/* indentation level n. */
void CORD_dump_inner(CORD x, unsigned n)
{
- register size_t i;
+ size_t i;
for (i = 0; i < (size_t)n; i++) {
fputs(" ", stdout);
if (x[i] != '\0') fputs("...", stdout);
putchar('\n');
} else if (IS_CONCATENATION(x)) {
- register struct Concatenation * conc =
- &(((CordRep *)x) -> concatenation);
+ struct Concatenation * conc = &(((CordRep *)x) -> concatenation);
+
printf("Concatenation: %p (len: %d, depth: %d)\n",
(void *)x, (int)(conc -> len), (int)(conc -> depth));
CORD_dump_inner(conc -> left, n+1);
CORD_dump_inner(conc -> right, n+1);
- } else /* function */{
- register struct Function * func =
- &(((CordRep *)x) -> function);
+ } else /* function */ {
+ struct Function * func = &(((CordRep *)x) -> function);
+
if (IS_SUBSTR(x)) printf("(Substring) ");
printf("Function: %p (len: %d): ", (void *)x, (int)(func -> len));
for (i = 0; i < 20 && i < func -> len; i++) {
CORD CORD_cat_char_star(CORD x, const char * y, size_t leny)
{
- register size_t result_len;
- register size_t lenx;
- register int depth;
+ size_t result_len;
+ size_t lenx;
+ int depth;
if (x == CORD_EMPTY) return(y);
if (leny == 0) return(x);
depth = 1;
}
} else {
- register CORD right;
- register CORD left;
- register char * new_right;
+ CORD right;
+ CORD left;
+ char * new_right;
lenx = LEN(x);
}
{
/* The general case; lenx, result_len is known: */
- register struct Concatenation * result;
+ struct Concatenation * result = GC_NEW(struct Concatenation);
- result = GC_NEW(struct Concatenation);
- if (result == 0) OUT_OF_MEMORY;
+ if (NULL == result) OUT_OF_MEMORY;
result->header = CONCAT_HDR;
result->depth = (char)depth;
if (lenx <= MAX_LEFT_LEN)
CORD CORD_cat(CORD x, CORD y)
{
- register size_t result_len;
- register int depth;
- register size_t lenx;
+ size_t result_len;
+ int depth;
+ size_t lenx;
if (x == CORD_EMPTY) return(y);
if (y == CORD_EMPTY) return(x);
lenx = strlen(x);
depth = DEPTH(y) + 1;
} else {
- register int depthy = DEPTH(y);
+ int depthy = DEPTH(y);
lenx = LEN(x);
depth = DEPTH(x) + 1;
}
result_len = lenx + LEN(y);
{
- register struct Concatenation * result;
+ struct Concatenation * result = GC_NEW(struct Concatenation);
- result = GC_NEW(struct Concatenation);
- if (result == 0) OUT_OF_MEMORY;
+ if (NULL == result) OUT_OF_MEMORY;
result->header = CONCAT_HDR;
result->depth = (char)depth;
if (lenx <= MAX_LEFT_LEN)
{
if (len == 0) return(0);
if (len <= SHORT_LIMIT) {
- register char * result;
- register size_t i;
+ char * result;
+ size_t i;
char buf[SHORT_LIMIT+1];
for (i = 0; i < len; i++) {
}
gen_case:
{
- register struct Function * result;
+ struct Function * result = GC_NEW(struct Function);
- result = GC_NEW(struct Function);
- if (result == 0) OUT_OF_MEMORY;
+ if (NULL == result) OUT_OF_MEMORY;
result->header = FN_HDR;
/* depth is already 0 */
result->len = (word)len;
char CORD_index_access_fn(size_t i, void * client_data)
{
- register struct substr_args *descr = (struct substr_args *)client_data;
+ struct substr_args *descr = (struct substr_args *)client_data;
return(((char *)(descr->sa_cord))[i + descr->sa_index]);
}
char CORD_apply_access_fn(size_t i, void * client_data)
{
- register struct substr_args *descr = (struct substr_args *)client_data;
- register struct Function * fn_cord = &(descr->sa_cord->function);
+ struct substr_args *descr = (struct substr_args *)client_data;
+ struct Function * fn_cord = &(descr->sa_cord->function);
return((*(fn_cord->fn))(i + descr->sa_index, fn_cord->client_data));
}
/* Assumes i >= 0 and i + n < length(x). */
CORD CORD_substr_closure(CORD x, size_t i, size_t n, CORD_fn f)
{
- register struct substr_args * sa = GC_NEW(struct substr_args);
+ struct substr_args * sa = GC_NEW(struct substr_args);
CordRep * result;
if (sa == 0) OUT_OF_MEMORY;
return(result);
}
} else if (IS_CONCATENATION(x)) {
- register struct Concatenation * conc
- = &(((CordRep *)x) -> concatenation);
- register size_t left_len;
- register size_t right_len;
+ struct Concatenation * conc = &(((CordRep *)x) -> concatenation);
+ size_t left_len = LEFT_LEN(conc);
+ size_t right_len = conc -> len - left_len;
- left_len = LEFT_LEN(conc);
- right_len = conc -> len - left_len;
if (i >= left_len) {
if (n == right_len) return(conc -> right);
return(CORD_substr_checked(conc -> right, i - left_len, n));
return(CORD_substr_checked(conc -> left, i, n));
} else {
/* Need at least one character from each side. */
- register CORD left_part;
- register CORD right_part;
- register size_t left_part_len = left_len - i;
+ CORD left_part;
+ CORD right_part;
+ size_t left_part_len = left_len - i;
if (i == 0) {
left_part = conc -> left;
if (n > SUBSTR_LIMIT) {
if (IS_SUBSTR(x)) {
/* Avoid nesting substring nodes. */
- register struct Function * f = &(((CordRep *)x) -> function);
- register struct substr_args *descr =
+ struct Function * f = &(((CordRep *)x) -> function);
+ struct substr_args *descr =
(struct substr_args *)(f -> client_data);
return(CORD_substr_closure((CORD)descr->sa_cord,
}
} else {
char * result;
- register struct Function * f = &(((CordRep *)x) -> function);
+ struct Function * f = &(((CordRep *)x) -> function);
char buf[SUBSTR_LIMIT+1];
- register char * p = buf;
- register size_t j;
- register size_t lim = i + n;
+ char * p = buf;
+ size_t j;
+ size_t lim = i + n;
for (j = i; j < lim; j++) {
char c = (*(f -> fn))(j, f -> client_data);
CORD CORD_substr(CORD x, size_t i, size_t n)
{
- register size_t len = CORD_len(x);
+ size_t len = CORD_len(x);
if (i >= len || n == 0) return(0);
if (i + n > len) n = len - i;
{
if (x == 0) return(0);
if (CORD_IS_STRING(x)) {
- register const char *p = x+i;
+ const char *p = x+i;
if (*p == '\0') ABORT("2nd arg to CORD_iter5 too big");
if (f2 != CORD_NO_FN) {
return(0);
}
} else if (IS_CONCATENATION(x)) {
- register struct Concatenation * conc
- = &(((CordRep *)x) -> concatenation);
-
+ struct Concatenation * conc = &(((CordRep *)x) -> concatenation);
if (i > 0) {
- register size_t left_len = LEFT_LEN(conc);
+ size_t left_len = LEFT_LEN(conc);
if (i >= left_len) {
return(CORD_iter5(conc -> right, i - left_len, f1, f2,
}
return(CORD_iter5(conc -> right, 0, f1, f2, client_data));
} else /* function */ {
- register struct Function * f = &(((CordRep *)x) -> function);
- register size_t j;
- register size_t lim = f -> len;
+ struct Function * f = &(((CordRep *)x) -> function);
+ size_t j;
+ size_t lim = f -> len;
for (j = i; j < lim; j++) {
if ((*f1)((*(f -> fn))(j, f -> client_data), client_data)) {
{
if (x == 0) return(0);
if (CORD_IS_STRING(x)) {
- register const char *p = x + i;
+ const char *p = x + i;
for(;;) {
char c = *p;
}
return(0);
} else if (IS_CONCATENATION(x)) {
- register struct Concatenation * conc
- = &(((CordRep *)x) -> concatenation);
- register CORD left_part = conc -> left;
- register size_t left_len;
+ struct Concatenation * conc = &(((CordRep *)x) -> concatenation);
+ CORD left_part = conc -> left;
+ size_t left_len = LEFT_LEN(conc);
- left_len = LEFT_LEN(conc);
if (i >= left_len) {
if (CORD_riter4(conc -> right, i - left_len, f1, client_data)) {
return(1);
return(CORD_riter4(left_part, i, f1, client_data));
}
} else /* function */ {
- register struct Function * f = &(((CordRep *)x) -> function);
- register size_t j;
+ struct Function * f = &(((CordRep *)x) -> function);
+ size_t j;
for (j = i; ; j--) {
if ((*f1)((*(f -> fn))(j, f -> client_data), client_data)) {
void CORD_init_min_len(void)
{
- register int i;
+ int i;
size_t last, previous;
min_len[0] = previous = 1;
void CORD_init_forest(ForestElement * forest, size_t max_len)
{
- register int i;
+ int i;
for (i = 0; i < MAX_DEPTH; i++) {
forest[i].c = 0;
/* This node should not be counted in the statement of the invariants. */
void CORD_add_forest(ForestElement * forest, CORD x, size_t len)
{
- register int i = 0;
- register CORD sum = CORD_EMPTY;
- register size_t sum_len = 0;
+ int i = 0;
+ CORD sum = CORD_EMPTY;
+ size_t sum_len = 0;
while (len > min_len[i + 1]) {
if (forest[i].c != 0) {
CORD CORD_concat_forest(ForestElement * forest, size_t expected_len)
{
- register int i = 0;
+ int i = 0;
CORD sum = 0;
size_t sum_len = 0;
/* of the final tree. */
void CORD_balance_insert(CORD x, size_t len, ForestElement * forest)
{
- register int depth;
+ int depth;
if (CORD_IS_STRING(x)) {
CORD_add_forest(forest, x, len);
} else if (IS_CONCATENATION(x)
&& ((depth = DEPTH(x)) >= MAX_DEPTH
|| len < min_len[depth])) {
- register struct Concatenation * conc
- = &(((CordRep *)x) -> concatenation);
+ struct Concatenation * conc = &(((CordRep *)x) -> concatenation);
size_t left_len = LEFT_LEN(conc);
CORD_balance_insert(conc -> left, left_len, forest);
CORD CORD_balance(CORD x)
{
Forest forest;
- register size_t len;
+ size_t len;
if (x == 0) return(0);
if (CORD_IS_STRING(x)) return(x);
/* P contains a prefix of the path to cur_pos. Extend it to a full */
/* path and set up leaf info. */
/* Return 0 if past the end of cord, 1 o.w. */
-void CORD__extend_path(register CORD_pos p)
+void CORD__extend_path(CORD_pos p)
{
- register struct CORD_pe * current_pe = &(p[0].path[p[0].path_len]);
- register CORD top = current_pe -> pe_cord;
- register size_t pos = p[0].cur_pos;
- register size_t top_pos = current_pe -> pe_start_pos;
- register size_t top_len = GEN_LEN(top);
+ struct CORD_pe * current_pe = &(p[0].path[p[0].path_len]);
+ CORD top = current_pe -> pe_cord;
+ size_t pos = p[0].cur_pos;
+ size_t top_pos = current_pe -> pe_start_pos;
+ size_t top_len = GEN_LEN(top);
/* Fill in the rest of the path. */
while(!CORD_IS_STRING(top) && IS_CONCATENATION(top)) {
- register struct Concatenation * conc =
- &(((CordRep *)top) -> concatenation);
- register size_t left_len;
+ struct Concatenation * conc = &(((CordRep *)top) -> concatenation);
+ size_t left_len;
left_len = LEFT_LEN(conc);
current_pe++;
if (pos >= top_pos + top_len) p[0].path_len = CORD_POS_INVALID;
}
-char CORD__pos_fetch(register CORD_pos p)
+char CORD__pos_fetch(CORD_pos p)
{
/* Leaf is a function node */
struct CORD_pe * pe = &((p)[0].path[(p)[0].path_len]);
CORD leaf = pe -> pe_cord;
- register struct Function * f = &(((CordRep *)leaf) -> function);
+ struct Function * f = &(((CordRep *)leaf) -> function);
if (!IS_FUNCTION(leaf)) ABORT("CORD_pos_fetch: bad leaf");
return ((*(f -> fn))(p[0].cur_pos - pe -> pe_start_pos, f -> client_data));
}
-void CORD__next(register CORD_pos p)
+void CORD__next(CORD_pos p)
{
- register size_t cur_pos = p[0].cur_pos + 1;
- register struct CORD_pe * current_pe = &((p)[0].path[(p)[0].path_len]);
- register CORD leaf = current_pe -> pe_cord;
+ size_t cur_pos = p[0].cur_pos + 1;
+ struct CORD_pe * current_pe = &((p)[0].path[(p)[0].path_len]);
+ CORD leaf = current_pe -> pe_cord;
/* Leaf is not a string or we're at end of leaf */
p[0].cur_pos = cur_pos;
if (!CORD_IS_STRING(leaf)) {
/* Function leaf */
- register struct Function * f = &(((CordRep *)leaf) -> function);
- register size_t start_pos = current_pe -> pe_start_pos;
- register size_t end_pos = start_pos + f -> len;
+ struct Function * f = &(((CordRep *)leaf) -> function);
+ size_t start_pos = current_pe -> pe_start_pos;
+ size_t end_pos = start_pos + f -> len;
if (cur_pos < end_pos) {
/* Fill cache and return. */
- register size_t i;
- register size_t limit = cur_pos + FUNCTION_BUF_SZ;
- register CORD_fn fn = f -> fn;
- register void * client_data = f -> client_data;
+ size_t i;
+ size_t limit = cur_pos + FUNCTION_BUF_SZ;
+ CORD_fn fn = f -> fn;
+ void * client_data = f -> client_data;
if (limit > end_pos) {
limit = end_pos;
CORD__extend_path(p);
}
-void CORD__prev(register CORD_pos p)
+void CORD__prev(CORD_pos p)
{
- register struct CORD_pe * pe = &(p[0].path[p[0].path_len]);
+ struct CORD_pe * pe = &(p[0].path[p[0].path_len]);
if (p[0].cur_pos == 0) {
p[0].path_len = CORD_POS_INVALID;
/* Pop the stack until we find two concatenation nodes with the */
/* different start position: this implies we were in right part. */
{
- register struct CORD_pe * current_pe = &((p)[0].path[(p)[0].path_len]);
+ struct CORD_pe * current_pe = &((p)[0].path[(p)[0].path_len]);
while (p[0].path_len > 0
&& current_pe[0].pe_start_pos == current_pe[-1].pe_start_pos) {
#undef CORD_pos_to_cord
#undef CORD_pos_valid
-char CORD_pos_fetch(register CORD_pos p)
+char CORD_pos_fetch(CORD_pos p)
{
if (p[0].cur_end != 0) {
return(p[0].cur_leaf[p[0].cur_pos - p[0].cur_start]);
CORD CORD_cat_char(CORD x, char c)
{
- register char * string;
+ char * string;
if (c == '\0') return(CORD_cat(x, CORD_nul(1)));
string = (char *)GC_MALLOC_ATOMIC(2);
CORD CORD_catn(int nargs, ...)
{
- register CORD result = CORD_EMPTY;
+ CORD result = CORD_EMPTY;
va_list args;
- register int i;
+ int i;
va_start(args, nargs);
for (i = 0; i < nargs; i++) {
- register CORD next = va_arg(args, CORD);
+ CORD next = va_arg(args, CORD);
result = CORD_cat(result, next);
}
va_end(args);
int CORD_fill_proc(char c, void * client_data)
{
- register CORD_fill_data * d = (CORD_fill_data *)client_data;
- register size_t count = d -> count;
+ CORD_fill_data * d = (CORD_fill_data *)client_data;
+ size_t count = d -> count;
(d -> buf)[count] = c;
d -> count = ++count;
int CORD_batched_fill_proc(const char * s, void * client_data)
{
- register CORD_fill_data * d = (CORD_fill_data *)client_data;
- register size_t count = d -> count;
- register size_t max = d -> len;
- register char * buf = d -> buf;
- register const char * t = s;
+ CORD_fill_data * d = (CORD_fill_data *)client_data;
+ size_t count = d -> count;
+ size_t max = d -> len;
+ char * buf = d -> buf;
+ const char * t = s;
while((buf[count] = *t++) != '\0') {
count++;
avail = CORD_pos_chars_left(xpos);
if (avail == 0
|| (yavail = CORD_pos_chars_left(ypos)) == 0) {
- register char xcurrent = CORD_pos_fetch(xpos);
- register char ycurrent = CORD_pos_fetch(ypos);
+ char xcurrent = CORD_pos_fetch(xpos);
+ char ycurrent = CORD_pos_fetch(ypos);
if (xcurrent != ycurrent) return(xcurrent - ycurrent);
CORD_next(xpos);
CORD_next(ypos);
} else {
/* process as many characters as we can */
- register int result;
+ int result;
if (avail > yavail) avail = yavail;
result = strncmp(CORD_pos_cur_char_addr(xpos),
{
CORD_pos xpos;
CORD_pos ypos;
- register size_t count;
+ size_t count;
CORD_set_pos(xpos, x, x_start);
CORD_set_pos(ypos, y, y_start);
}
if ((avail = CORD_pos_chars_left(xpos)) <= 0
|| (yavail = CORD_pos_chars_left(ypos)) <= 0) {
- register char xcurrent = CORD_pos_fetch(xpos);
- register char ycurrent = CORD_pos_fetch(ypos);
+ char xcurrent = CORD_pos_fetch(xpos);
+ char ycurrent = CORD_pos_fetch(ypos);
+
if (xcurrent != ycurrent) return(xcurrent - ycurrent);
CORD_next(xpos);
CORD_next(ypos);
count++;
} else {
/* process as many characters as we can */
- register int result;
+ int result;
if (avail > yavail) avail = yavail;
count += avail;
char * CORD_to_char_star(CORD x)
{
- register size_t len = CORD_len(x);
+ size_t len = CORD_len(x);
char * result = (char *)GC_MALLOC_ATOMIC(len + 1);
if (result == 0) OUT_OF_MEMORY;
int CORD_put_proc(char c, void * client_data)
{
- register FILE * f = (FILE *)client_data;
+ FILE * f = (FILE *)client_data;
return(putc(c, f) == EOF);
}
int CORD_batched_put_proc(const char * s, void * client_data)
{
- register FILE * f = (FILE *)client_data;
+ FILE * f = (FILE *)client_data;
return(fputs(s, f) == EOF);
}
int CORD_chr_proc(char c, void * client_data)
{
- register chr_data * d = (chr_data *)client_data;
+ chr_data * d = (chr_data *)client_data;
if (c == d -> target) return(1);
(d -> pos) ++;
int CORD_rchr_proc(char c, void * client_data)
{
- register chr_data * d = (chr_data *)client_data;
+ chr_data * d = (chr_data *)client_data;
if (c == d -> target) return(1);
(d -> pos) --;
int CORD_batched_chr_proc(const char *s, void * client_data)
{
- register chr_data * d = (chr_data *)client_data;
+ chr_data * d = (chr_data *)client_data;
const char * occ = strchr(s, d -> target);
if (NULL == occ) {
CORD_pos xpos;
size_t xlen = CORD_len(x);
size_t slen;
- register size_t start_len;
+ size_t start_len;
const char * s_start;
unsigned long s_buf = 0; /* The first few characters of s */
unsigned long x_buf = 0; /* Start of candidate substring. */
/* Initialized only to make compilers */
/* happy. */
unsigned long mask = 0;
- register size_t i;
- register size_t match_pos;
+ size_t i;
+ size_t match_pos;
if (s == CORD_EMPTY) return(start);
if (CORD_IS_STRING(s)) {
void CORD_ec_flush_buf(CORD_ec x)
{
- register size_t len = x[0].ec_bufptr - x[0].ec_buf;
+ size_t len = x[0].ec_bufptr - x[0].ec_buf;
char * s;
if (len == 0) return;
/* Append the right number of NULs */
/* Note that any string of NULs is represented in 4 words, */
/* independent of its length. */
- register size_t count = 1;
+ size_t count = 1;
CORD_ec_flush_buf(ecord);
while ((c = getc(f)) == 0) count++;
/* Executed with allocation lock. */
static char refill_cache(refill_data * client_data)
{
- register lf_state * state = client_data -> state;
- register size_t file_pos = client_data -> file_pos;
+ lf_state * state = client_data -> state;
+ size_t file_pos = client_data -> file_pos;
FILE *f = state -> lf_file;
size_t line_start = LINE_START(file_pos);
size_t line_no = DIV_LINE_SZ(MOD_CACHE_SZ(file_pos));
char CORD_lf_func(size_t i, void * client_data)
{
- register lf_state * state = (lf_state *)client_data;
- register cache_line * volatile * cl_addr =
- &(state -> lf_cache[DIV_LINE_SZ(MOD_CACHE_SZ(i))]);
- register cache_line * cl = (cache_line *)ATOMIC_READ(cl_addr);
+ lf_state * state = (lf_state *)client_data;
+ cache_line * volatile * cl_addr =
+ &(state -> lf_cache[DIV_LINE_SZ(MOD_CACHE_SZ(i))]);
+ cache_line * cl = (cache_line *)ATOMIC_READ(cl_addr);
if (cl == 0 || cl -> tag != DIV_LINE_SZ(i)) {
/* Cache miss */
CORD CORD_from_file_lazy_inner(FILE * f, size_t len)
{
- register lf_state * state = GC_NEW(lf_state);
- register int i;
+ lf_state * state = GC_NEW(lf_state);
+ int i;
if (state == 0) OUT_OF_MEMORY;
if (len != 0) {
CORD CORD_from_file_lazy(FILE * f)
{
- register long len;
+ long len;
if (fseek(f, 0l, SEEK_END) != 0
|| (len = ftell(f)) < 0
CORD CORD_from_file(FILE * f)
{
- register long len;
+ long len;
if (fseek(f, 0l, SEEK_END) != 0
|| (len = ftell(f)) < 0