diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f7e81e2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,7 @@ +root = true + +[*.{c,h,y}] +indent_size = 4 +indent_style = space +trim_trailing_whitespace = true +insert_final_newline = true \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..493ad9f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +*.c text diff=cpp whitespace=trailing-space,space-before-tab,tab-in-indent +*.h text diff=cpp whitespace=trailing-space,space-before-tab,tab-in-indent diff --git a/array.c b/array.c index dd49fb7..951ac60 100644 --- a/array.c +++ b/array.c @@ -35,8 +35,8 @@ int total_array_size; * It is cheaper to reuse it, than to use malloc() and allocate. */ struct vector null_vector = { - 0, /* size */ - 1 /* Ref count, which will ensure that it will never be deallocated */ + 0, /* size */ + 1 /* Ref count, which will ensure that it will never be deallocated */ }; /* @@ -49,20 +49,20 @@ allocate_array(long long nn) struct vector *p; if (nn < 0 || nn > MAX_ARRAY_SIZE) - error("Illegal array size.\n"); + error("Illegal array size.\n"); if (n == 0) { p = &null_vector; - INCREF(p->ref); - return p; + INCREF(p->ref); + return p; } num_arrays++; total_array_size += sizeof (struct vector) + sizeof (struct svalue) * - (n-1); + (n-1); p = ALLOC_VECTOR(n); p->ref = 1; p->size = n; for (i=0; iitem[i] = const0; + p->item[i] = const0; return p; } @@ -72,26 +72,26 @@ free_vector(struct vector *p) int i; if (!p->ref || --p->ref > 0) - return; + return; #if 0 if (p->ref < 0) { - debug_message("Array reference count < 0 in free_vector.\n"); - return; + debug_message("Array reference count < 0 in free_vector.\n"); + return; } #endif #if defined(DEBUG) if (p == &null_vector) { - p->ref = 1; - debug_message("Tried to free the zero-size shared vector.\n"); - return; + p->ref = 1; + debug_message("Tried to free the zero-size shared vector.\n"); + return; } #endif for (i = 0; i < p->size; i++) - free_svalue(&p->item[i]); + free_svalue(&p->item[i]); num_arrays--; total_array_size -= sizeof (struct vector) + sizeof (struct svalue) * - (p->size-1); + (p->size-1); free((char *)p); } @@ -102,17 +102,17 @@ multiply_array(struct vector *vec, long long factor) long long size = vec->size, newsize,j, offset; if (factor <= 0 || size == 0) { - return allocate_array(0); + return allocate_array(0); } if (factor > MAX_ARRAY_SIZE) - error("Illegal array size.\n"); + error("Illegal array size.\n"); newsize = size * factor; result = allocate_array(newsize); for (offset = 0; offset < newsize;) { - for (j = 0; j < size; j++, offset++) - assign_svalue_no_free(result->item + offset, vec->item + j); + for (j = 0; j < size; j++, offset++) + assign_svalue_no_free(result->item + offset, vec->item + j); } return result; } @@ -132,14 +132,14 @@ explode_string(char *str, char *delim) delim_len = strlen(str); struct vector *arr = allocate_array(delim_len); for (int num = 0; num < delim_len; num++) - { - arr->item[num].type = T_STRING; - arr->item[num].string_type = STRING_MSTRING; - arr->item[num].u.string = allocate_mstring(1); - arr->item[num].u.string[0] = str[num]; - arr->item[num].u.string[1] = '\0'; - } - return arr; + { + arr->item[num].type = T_STRING; + arr->item[num].string_type = STRING_MSTRING; + arr->item[num].u.string = allocate_mstring(1); + arr->item[num].u.string[0] = str[num]; + arr->item[num].u.string[1] = '\0'; + } + return arr; } if (!*str) /* Empty string */ @@ -185,7 +185,7 @@ explode_string(char *str, char *delim) #endif } - num++; + num++; struct vector *arr = allocate_array(num); @@ -233,14 +233,14 @@ implode_string(struct vector *arr, char *del) num = 0; for (i=0; i < arr->size; i++) { - if (arr->item[i].type == T_STRING) - { - size += strlen(arr->item[i].u.string); - num++; - } + if (arr->item[i].type == T_STRING) + { + size += strlen(arr->item[i].u.string); + num++; + } } if (num == 0) - return make_mstring(""); + return make_mstring(""); len = strlen(del); ret = allocate_mstring(size + (num-1) * len); @@ -249,17 +249,17 @@ implode_string(struct vector *arr, char *del) num = 0; for (i = 0; i < arr->size; i++) { - if (arr->item[i].type == T_STRING) - { - if (num > 0) - { - (void)strcpy(p, del); - p += len; - } - (void)strcpy(p, arr->item[i].u.string); - p += strlen(arr->item[i].u.string); - num++; - } + if (arr->item[i].type == T_STRING) + { + if (num > 0) + { + (void)strcpy(p, del); + p += len; + } + (void)strcpy(p, arr->item[i].u.string); + p += strlen(arr->item[i].u.string); + num++; + } } return ret; } @@ -271,12 +271,12 @@ users() struct vector *ret; if (!num_player) - return allocate_array(0); + return allocate_array(0); ret = allocate_array(num_player); for (i = 0; i < num_player; i++) { - ret->item[i].type = T_OBJECT; - add_ref(ret->item[i].u.ob = get_interactive_object(i),"users"); + ret->item[i].type = T_OBJECT; + add_ref(ret->item[i].u.ob = get_interactive_object(i),"users"); } return ret; } @@ -292,24 +292,24 @@ slice_array(struct vector *p, long long from, long long to) #ifdef NEGATIVE_SLICE_INDEX if (from < 0) - from = p->size + from; + from = p->size + from; #endif if (from < 0) - from = 0; + from = 0; if (from >= p->size) - return allocate_array(0); /* Slice starts above array */ + return allocate_array(0); /* Slice starts above array */ #ifdef NEGATIVE_SLICE_INDEX if (to < 0) - to = p->size + to; + to = p->size + to; #endif if (to >= p->size) - to = p->size - 1; + to = p->size - 1; if (to < from) - return allocate_array(0); + return allocate_array(0); d = allocate_array(to - from + 1); for (cnt = from; cnt <= to; cnt++) - assign_svalue_no_free (&d->item[cnt - from], &p->item[cnt]); + assign_svalue_no_free (&d->item[cnt - from], &p->item[cnt]); return d; } @@ -328,24 +328,24 @@ filter_arr(struct vector *p, struct closure *fun) int cnt,res; if (p->size<1) - return allocate_array(0); + return allocate_array(0); res = 0; flags = tmpalloc((size_t)p->size + 1); for (cnt = 0; cnt < p->size; cnt++) { - push_svalue(&p->item[cnt]); - (void)call_var(1, fun); - if (sp->type == T_NUMBER && sp->u.number) { - flags[cnt] = 1; - res++; - } else - flags[cnt] = 0; - pop_stack(); + push_svalue(&p->item[cnt]); + (void)call_var(1, fun); + if (sp->type == T_NUMBER && sp->u.number) { + flags[cnt] = 1; + res++; + } else + flags[cnt] = 0; + pop_stack(); } r = allocate_array(res); for (cnt = res = 0; res < r->size && cnt < p->size; cnt++) { - if (flags[cnt]) - assign_svalue_no_free(&r->item[res++], &p->item[cnt]); + if (flags[cnt]) + assign_svalue_no_free(&r->item[res++], &p->item[cnt]); } /* tmpfree(flags); */ return r; @@ -392,25 +392,25 @@ put_in(struct unique **ulist, struct svalue *marker, struct svalue *elem) cnt = 0; fixed = 0; while (llink) { - if ((!fixed) && (equal_svalue(marker, &(llink->mark)))) - { - for (tlink = llink; tlink->same; tlink = tlink->same) - (tlink->count)++; - (tlink->count)++; - slink = (struct unique *) tmpalloc(sizeof(struct unique)); - slink->count = 1; - assign_svalue_no_free(&slink->mark, marker); - slink->val = elem; - slink->same = 0; - slink->next = 0; - tlink->same = slink; - fixed = 1; /* We want the size of the list so do not break here */ - } - llink = llink->next; - cnt++; + if ((!fixed) && (equal_svalue(marker, &(llink->mark)))) + { + for (tlink = llink; tlink->same; tlink = tlink->same) + (tlink->count)++; + (tlink->count)++; + slink = (struct unique *) tmpalloc(sizeof(struct unique)); + slink->count = 1; + assign_svalue_no_free(&slink->mark, marker); + slink->val = elem; + slink->same = 0; + slink->next = 0; + tlink->same = slink; + fixed = 1; /* We want the size of the list so do not break here */ + } + llink = llink->next; + cnt++; } if (fixed) - return cnt; + return cnt; llink = (struct unique *) tmpalloc(sizeof(struct unique)); llink->count = 1; assign_svalue_no_free(&llink->mark, marker); @@ -431,49 +431,49 @@ make_unique(struct vector *arr, struct closure *fun, struct svalue *skipnum) int cnt, ant, cnt2; if (arr->size < 1) - return allocate_array(0); + return allocate_array(0); head = 0; ant = 0; INCREF(arr->ref); for(cnt = 0; cnt < arr->size; cnt++) { - if (arr->item[cnt].type == T_OBJECT) - { + if (arr->item[cnt].type == T_OBJECT) + { push_svalue(&arr->item[cnt]); (void)call_var(1, fun); - if ((!sp) || (sp->type != skipnum->type) || !equal_svalue(sp, skipnum)) - { - if (sp) - { - ant = put_in(&head, sp, &(arr->item[cnt])); - } - } + if ((!sp) || (sp->type != skipnum->type) || !equal_svalue(sp, skipnum)) + { + if (sp) + { + ant = put_in(&head, sp, &(arr->item[cnt])); + } + } pop_stack(); - } + } } DECREF(arr->ref); ret = allocate_array(ant); for (cnt = ant - 1; cnt >= 0; cnt--) /* Reverse to compensate put_in */ { - ret->item[cnt].type = T_POINTER; - ret->item[cnt].u.vec = res = allocate_array(head->count); - nxt2 = head; - head = head->next; - cnt2 = 0; - while (nxt2) - { - assign_svalue_no_free (&res->item[cnt2++], nxt2->val); - free_svalue(&nxt2->mark); - nxt = nxt2->same; -/* tmpfree((char *) nxt2); */ - nxt2 = nxt; - } - if (!head) - break; /* It shouldn't but, to avoid skydive just in case */ + ret->item[cnt].type = T_POINTER; + ret->item[cnt].u.vec = res = allocate_array(head->count); + nxt2 = head; + head = head->next; + cnt2 = 0; + while (nxt2) + { + assign_svalue_no_free (&res->item[cnt2++], nxt2->val); + free_svalue(&nxt2->mark); + nxt = nxt2->same; +/* tmpfree((char *) nxt2); */ + nxt2 = nxt; + } + if (!head) + break; /* It shouldn't but, to avoid skydive just in case */ } return ret; } @@ -495,13 +495,13 @@ add_array(struct vector *p, struct vector *r) res = 0; for (cnt = 0; cnt < p->size; cnt++) { - assign_svalue_no_free (&d->item[res],&p->item[cnt]); - res++; + assign_svalue_no_free (&d->item[res],&p->item[cnt]); + res++; } for (cnt = 0; cnt < r->size; cnt++) { - assign_svalue_no_free (&d->item[res],&r->item[cnt]); - res++; + assign_svalue_no_free (&d->item[res],&r->item[cnt]); + res++; } return d; } @@ -518,20 +518,20 @@ all_inventory(struct object *ob) cnt = 0; for (cur = ob->contains; cur; cur = cur->next_inv) - cnt++; + cnt++; if (!cnt) - return allocate_array(0); + return allocate_array(0); d = allocate_array(cnt); cur = ob->contains; for (res = 0; res < cnt; res++) { - d->item[res].type = T_OBJECT; - d->item[res].u.ob = cur; - add_ref(cur, "all_inventory"); - cur = cur->next_inv; + d->item[res].type = T_OBJECT; + d->item[res].u.ob = cur; + add_ref(cur, "all_inventory"); + cur = cur->next_inv; } return d; } @@ -549,10 +549,10 @@ map_array (struct vector *arr, struct closure *fun) r = allocate_array(arr->size); push_vector(r, 0); for (cnt = 0; cnt < arr->size; cnt++) { - push_svalue(&arr->item[cnt]); - (void)call_var(1, fun); - r->item[cnt] = *sp; /* Just copy it. Reference count is correct */ - sp--; /* since we loose a reference here. */ + push_svalue(&arr->item[cnt]); + (void)call_var(1, fun); + r->item[cnt] = *sp; /* Just copy it. Reference count is correct */ + sp--; /* since we loose a reference here. */ } sp--; return r; @@ -569,36 +569,36 @@ map_array (struct vector *arr, struct closure *fun) struct vector * deep_inventory(struct object *ob, int take_top) { - struct vector *dinv, *ainv, *sinv, *tinv; - int il; + struct vector *dinv, *ainv, *sinv, *tinv; + int il; ainv = all_inventory(ob); if (take_top) { - sinv = allocate_array(1); - sinv->item[0].type = T_OBJECT; - add_ref(ob,"deep_inventory"); - sinv->item[0].u.ob = ob; - dinv = add_array(sinv, ainv); - free_vector(sinv); - free_vector(ainv); - ainv = dinv; + sinv = allocate_array(1); + sinv->item[0].type = T_OBJECT; + add_ref(ob,"deep_inventory"); + sinv->item[0].u.ob = ob; + dinv = add_array(sinv, ainv); + free_vector(sinv); + free_vector(ainv); + ainv = dinv; } sinv = ainv; for (il = take_top ? 1 : 0 ; il < ainv->size ; il++) { - if (ainv->item[il].u.ob->contains) - { - dinv = deep_inventory(ainv->item[il].u.ob,0); - tinv = add_array(sinv, dinv); - if (sinv != ainv) - free_vector(sinv); - sinv = tinv; - free_vector(dinv); - } + if (ainv->item[il].u.ob->contains) + { + dinv = deep_inventory(ainv->item[il].u.ob,0); + tinv = add_array(sinv, dinv); + if (sinv != ainv) + free_vector(sinv); + sinv = tinv; + free_vector(dinv); + } } if (ainv != sinv) - free_vector(ainv); + free_vector(ainv); return sinv; } @@ -611,29 +611,29 @@ match_regexp(struct vector *v, char *pattern) struct vector *ret; if (v->size == 0) - return allocate_array(0); + return allocate_array(0); reg = regcomp(pattern, 0); if (reg == 0) - return 0; + return 0; res = (char *)alloca((size_t)v->size); for (num_match=i=0; i < v->size; i++) { - res[i] = 0; - if (v->item[i].type != T_STRING) - continue; - eval_cost++; - if (regexec(reg, v->item[i].u.string) == 0) - continue; - res[i] = 1; - num_match++; + res[i] = 0; + if (v->item[i].type != T_STRING) + continue; + eval_cost++; + if (regexec(reg, v->item[i].u.string) == 0) + continue; + res[i] = 1; + num_match++; } ret = allocate_array(num_match); for (num_match=i=0; i < v->size; i++) { - if (res[i] == 0) - continue; - assign_svalue_no_free(&ret->item[num_match], &v->item[i]); - num_match++; + if (res[i] == 0) + continue; + assign_svalue_no_free(&ret->item[num_match], &v->item[i]); + num_match++; } free((char *)reg); return ret; @@ -642,8 +642,8 @@ match_regexp(struct vector *v, char *pattern) /* An attempt at rewrite using mappings */ -#define SETARR_SUBTRACT 1 -#define SETARR_INTERSECT 2 +#define SETARR_SUBTRACT 1 +#define SETARR_INTERSECT 2 struct vector * set_manipulate_array(struct vector *arr1, struct vector *arr2, int op) @@ -656,15 +656,15 @@ set_manipulate_array(struct vector *arr1, struct vector *arr2, int op) if (arr1->size < 1 || arr2->size < 1) { - switch (op) - { - case SETARR_SUBTRACT: - INCREF(arr1->ref); - return arr1; + switch (op) + { + case SETARR_SUBTRACT: + INCREF(arr1->ref); + return arr1; case SETARR_INTERSECT: - return allocate_array(0); - } + return allocate_array(0); + } } m = make_mapping(arr2, 0); @@ -677,27 +677,27 @@ set_manipulate_array(struct vector *arr1, struct vector *arr2, int op) flags = alloca((size_t)arr1->size + 1); for (cnt = 0; cnt < arr1->size; cnt++) { - flags[cnt] = 0; - v = get_map_lvalue(m, &(arr1->item[cnt]), 0); - if (op == SETARR_INTERSECT && v != &const0) - { - flags[cnt] = 1; - res++; - } - else if (op == SETARR_SUBTRACT && v == &const0) - { - flags[cnt] = 1; - res++; - } + flags[cnt] = 0; + v = get_map_lvalue(m, &(arr1->item[cnt]), 0); + if (op == SETARR_INTERSECT && v != &const0) + { + flags[cnt] = 1; + res++; + } + else if (op == SETARR_SUBTRACT && v == &const0) + { + flags[cnt] = 1; + res++; + } } r = allocate_array(res); if (res) { - for (cnt = res = 0; cnt < arr1->size; cnt++) - { - if (flags[cnt]) - assign_svalue_no_free(&r->item[res++], &arr1->item[cnt]); - } + for (cnt = res = 0; cnt < arr1->size; cnt++) + { + if (flags[cnt]) + assign_svalue_no_free(&r->item[res++], &arr1->item[cnt]); + } } free_mapping(m); return r; @@ -725,29 +725,29 @@ union_array(struct vector *arr1, struct vector *arr2) if (arr1->size == 0) { - INCREF(arr2->ref); - return arr2; + INCREF(arr2->ref); + return arr2; } if (arr2->size == 0) { - INCREF(arr1->ref); - return arr1; + INCREF(arr1->ref); + return arr1; } mp = allocate_map(arr1->size); for (i = 0; i < arr1->size; i++) - assign_svalue(get_map_lvalue(mp, &arr1->item[i], 1), &const1); + assign_svalue(get_map_lvalue(mp, &arr1->item[i], 1), &const1); set = alloca((size_t)arr2->size); for (i = size = 0; i < arr2->size; i++) { - if (get_map_lvalue(mp, &arr2->item[i], 0) == &const0) - set[i] = 1, size++; - else - set[i] = 0; + if (get_map_lvalue(mp, &arr2->item[i], 0) == &const0) + set[i] = 1, size++; + else + set[i] = 0; } free_mapping(mp); @@ -755,13 +755,13 @@ union_array(struct vector *arr1, struct vector *arr2) arr3 = allocate_array(arr1->size + size); for (i = 0; i < arr1->size; i++) - assign_svalue_no_free(&arr3->item[i], &arr1->item[i]); + assign_svalue_no_free(&arr3->item[i], &arr1->item[i]); size = arr1->size; for (i = 0; i < arr2->size; i++) - if (set[i]) - assign_svalue_no_free(&arr3->item[size++], &arr2->item[i]); + if (set[i]) + assign_svalue_no_free(&arr3->item[size++], &arr2->item[i]); return arr3; } diff --git a/backend.c b/backend.c index 0df25d3..2f2df31 100644 --- a/backend.c +++ b/backend.c @@ -66,7 +66,7 @@ clear_state(void) current_interactive = 0; previous_ob = 0; current_prog = 0; - reset_machine(); /* Pop down the stack. */ + reset_machine(); /* Pop down the stack. */ } void @@ -82,8 +82,8 @@ logon(struct object *ob) current_object = ob; ret = apply("logon", ob, 0, 0); if (ret == 0) { - (void)add_message("prog %s:\n", ob->name); - fatal("Could not find logon on the player %s\n", ob->name); + (void)add_message("prog %s:\n", ob->name); + fatal("Could not find logon on the player %s\n", ob->name); } current_object = save; } @@ -162,7 +162,7 @@ init_tasks(void) { static void append_task(struct task *task) { if (!task) - return; + return; task->next = &task_head; task->prev = task_head.prev; task_head.prev->next = task; @@ -209,13 +209,13 @@ void remove_task(struct task*t) { if (!t) - return; + return; if (t->next && t->next != t) - num_tasks--; + num_tasks--; if (t->prev) - t->prev->next = t->next; + t->prev->next = t->next; if (t->next) - t->next->prev = t->prev; + t->next->prev = t->prev; t->prev = t->next = 0; } @@ -224,15 +224,15 @@ void reschedule_task(struct task *t) { if (!t) - return; + return; if (t->next == t) - return; /* It's the currently running task, it will be rescheduled - when it is finnished */ + return; /* It's the currently running task, it will be rescheduled + when it is finnished */ if (t->next == 0) { - t->prev = t->next = t; /* it's the currrently running task. Mark it - for rescheduling */ - return; + t->prev = t->next = t; /* it's the currrently running task. Mark it + for rescheduling */ + return; } /* Move the task to the tail */ remove_task(t); @@ -248,15 +248,15 @@ runtask(struct task *t) exception_frame.e_catch = 0; exception = &exception_frame; clear_state(); - tmpclean(); /* Free all temporary memory */ + tmpclean(); /* Free all temporary memory */ remove_destructed_objects(); /* marion - before ref checks! */ eval_cost = 0; if (setjmp(exception_frame.e_context) == 0) { - t->fkn(t->arg); + t->fkn(t->arg); } clear_state(); - tmpclean(); /* Free all temporary memory */ + tmpclean(); /* Free all temporary memory */ remove_destructed_objects(); /* marion - before ref checks! */ eval_cost = 0; } @@ -282,7 +282,7 @@ static void check_for_slow_shut_down(void) { if (!slow_shut_down_to_do || shutdown_task) - return; + return; shutdown_task = create_hiprio_task(slow_shut_down, 0); } @@ -303,41 +303,41 @@ mainloop(void) (void) signal(SIGFPE, sigfpe_handler); while (!game_is_being_shut_down) { - while (task_head.next == &task_head) { - set_current_time(); - deliver_signals(); - call_out(&tv); - if (task_head.next != &task_head) - tv.tv_sec = tv.tv_usec = 0; - nd_select(&tv); - check_for_slow_shut_down(); - } - set_current_time(); - current_task = task_head.next; - remove_task(current_task); - runtask(current_task); - task_start = current_time; - set_current_time(); - update_runq_av((num_tasks + 1.0) * (current_time - task_start)); - - /* process callouts and IO */ - deliver_signals(); - if (task_head.next != &task_head || - current_task->next == current_task) { - tv.tv_sec = tv.tv_usec = 0; - call_out(NULL); + while (task_head.next == &task_head) { + set_current_time(); + deliver_signals(); + call_out(&tv); + if (task_head.next != &task_head) + tv.tv_sec = tv.tv_usec = 0; + nd_select(&tv); + check_for_slow_shut_down(); + } + set_current_time(); + current_task = task_head.next; + remove_task(current_task); + runtask(current_task); + task_start = current_time; + set_current_time(); + update_runq_av((num_tasks + 1.0) * (current_time - task_start)); + + /* process callouts and IO */ + deliver_signals(); + if (task_head.next != &task_head || + current_task->next == current_task) { + tv.tv_sec = tv.tv_usec = 0; + call_out(NULL); } else - call_out(&tv); - if (task_head.next != &task_head || - current_task->next == current_task) - tv.tv_sec = tv.tv_usec = 0; - nd_select(&tv); - check_for_slow_shut_down(); - - if (current_task->next == current_task) - append_task(current_task); /* reschedule the task */ - else - free(current_task); + call_out(&tv); + if (task_head.next != &task_head || + current_task->next == current_task) + tv.tv_sec = tv.tv_usec = 0; + nd_select(&tv); + check_for_slow_shut_down(); + + if (current_task->next == current_task) + append_task(current_task); /* reschedule the task */ + else + free(current_task); } shutdowngame(); } @@ -363,49 +363,49 @@ preload_objects(int eflag) if (setjmp(exception_frame.e_context)) { - clear_state(); - (void)add_message("Error in start_boot() in master_ob.\n"); - exception = NULL; - return; + clear_state(); + (void)add_message("Error in start_boot() in master_ob.\n"); + exception = NULL; + return; } else { - exception_frame.e_exception = NULL; - exception_frame.e_catch = 0; - exception = &exception_frame; - push_number(eflag); - ret = apply_master_ob(M_START_BOOT, 1); + exception_frame.e_exception = NULL; + exception_frame.e_catch = 0; + exception = &exception_frame; + push_number(eflag); + ret = apply_master_ob(M_START_BOOT, 1); } if ((ret == 0) || (ret->type != T_POINTER)) - return; + return; else - prefiles = ret->u.vec; + prefiles = ret->u.vec; if ((prefiles == 0) || (prefiles->size < 1)) - return; + return; INCREF(prefiles->ref); /* Otherwise it will be freed next sapply */ ix = -1; if (setjmp(exception_frame.e_context)) { - clear_state(); - (void)add_message("Anomaly in the fabric of world space.\n"); + clear_state(); + (void)add_message("Anomaly in the fabric of world space.\n"); } while (++ix < prefiles->size) { set_current_time(); - if (s_flag) - reset_mudstatus(); - eval_cost = 0; - push_svalue(&(prefiles->item[ix])); - (void)apply_master_ob(M_PRELOAD_BOOT, 1); - if (s_flag) - print_mudstatus(prefiles->item[ix].u.string, eval_cost, - get_millitime(), get_processtime()); - tmpclean(); + if (s_flag) + reset_mudstatus(); + eval_cost = 0; + push_svalue(&(prefiles->item[ix])); + (void)apply_master_ob(M_PRELOAD_BOOT, 1); + if (s_flag) + print_mudstatus(prefiles->item[ix].u.string, eval_cost, + get_millitime(), get_processtime()); + tmpclean(); } free_vector(prefiles); exception = NULL; @@ -422,8 +422,8 @@ remove_destructed_objects(void) struct object *ob, *next; for (ob = obj_list_destruct; ob; ob = next) { - next = ob->next_all; - destruct2(ob); + next = ob->next_all; + destruct2(ob); } obj_list_destruct = 0; } @@ -439,18 +439,18 @@ write_file(char *file, char *str) file = check_valid_path(file, current_object, "write_file", 1); if (!file) - return 0; + return 0; f = fopen(file, "a"); if (f == 0) - error("Wrong permissions for opening file %s for append.\n", file); + error("Wrong permissions for opening file %s for append.\n", file); if (s_flag) - num_filewrite++; + num_filewrite++; if (fwrite(str, strlen(str), 1, f) != 1) { - (void)fclose(f); - return 0; + (void)fclose(f); + return 0; } if (fclose(f) == EOF) - return 0; + return 0; return 1; } @@ -568,38 +568,38 @@ read_bytes(char *file, int start, size_t len) int f; if(len > MAX_BYTE_TRANSFER) - return 0; + return 0; file = check_valid_path(file, current_object, "read_bytes", 0); if (!file) - return 0; + return 0; f = open(file, O_RDONLY); if (f < 0) - return 0; + return 0; #ifdef PURIFY (void)memset(&st, '\0', sizeof(st)); #endif if (fstat(f, &st) == -1) - fatal("Could not stat an open file.\n"); + fatal("Could not stat an open file.\n"); size = (int)st.st_size; if(start < 0) - start = size + start; + start = size + start; if (start >= size) { - (void)close(f); - return 0; + (void)close(f); + return 0; } if ((start+len) > size) - len = (size - start); + len = (size - start); if ((size = (int)lseek(f, (off_t)start, 0)) < 0) { - (void)close(f); - return 0; + (void)close(f); + return 0; } str = allocate_mstring(len); @@ -611,13 +611,13 @@ read_bytes(char *file, int start, size_t len) if (size <= 0) { free_mstring(str); - return 0; + return 0; } /* We want to allow all characters to pass untouched! for (il = 0; il < size; il++) - if (!isprint(str[il]) && !isspace(str[il])) - str[il] = ' '; + if (!isprint(str[il]) && !isspace(str[il])) + str[il] = ' '; */ /* @@ -639,38 +639,38 @@ write_bytes(char *file, int start, char *str) file = check_valid_path(file, current_object, "write_bytes", 1); if (!file) - return 0; + return 0; if (strlen(str) > MAX_BYTE_TRANSFER) - return 0; + return 0; f = open(file, O_WRONLY); if (f < 0) - return 0; + return 0; #ifdef PURIFY (void)memset(&st, '\0', sizeof(st)); #endif if (fstat(f, &st) == -1) - fatal("Could not stat an open file.\n"); + fatal("Could not stat an open file.\n"); size = (int)st.st_size; if(start < 0) - start = size + start; + start = size + start; if (start >= size) { - (void)close(f); - return 0; + (void)close(f); + return 0; } if ((start + strlen(str)) > size) { - (void)close(f); - return 0; + (void)close(f); + return 0; } if ((size = (int)lseek(f, (off_t)start, 0)) < 0) { - (void)close(f); - return 0; + (void)close(f); + return 0; } size = write(f, str, strlen(str)); @@ -678,7 +678,7 @@ write_bytes(char *file, int start, char *str) (void)close(f); if (size <= 0) { - return 0; + return 0; } return 1; @@ -692,22 +692,22 @@ file_size(char *file) file = check_valid_path(file, current_object, "file_size", 0); if (!file) - return -1; + return -1; if (file[0] == '/') - file++; + file++; if (!legal_path(file)) - return -1; + return -1; #ifdef PURIFY (void)memset(&st, '\0', sizeof(st)); #endif if (stat(file, &st) == -1) - return -1; + return -1; if (S_IFDIR & st.st_mode) - return -2; + return -2; return (int)st.st_size; } @@ -719,14 +719,14 @@ file_time(char *file) file = check_valid_path(file, current_object, "file_time", 0); if (!file) - return 0; + return 0; #ifdef PURIFY (void)memset(&st, '\0', sizeof(st)); #endif if (stat(file, &st) == -1) - return 0; + return 0; return (int)st.st_mtime; } @@ -745,13 +745,13 @@ update_av(av_t *av, double amount) av->avg1 = expl(-delta / 60.0l) * av->avg1 + - (1.0l - expl(-1.0l/60.0l)) * amount; + (1.0l - expl(-1.0l/60.0l)) * amount; av->avg5 = expl(-delta / 300.0l) * av->avg5 + - (1.0l - expl(-1.0l/300.0l)) * amount; + (1.0l - expl(-1.0l/300.0l)) * amount; av->avg15 = expl(-delta / 900.0l) * av->avg15 + - (1.0l - expl(-1.0l/900.0l)) * amount; + (1.0l - expl(-1.0l/900.0l)) * amount; } static av_t tcp_av = {0.0, 0.0, 0.0, 0.0}; @@ -812,18 +812,18 @@ query_load_av(void) update_av(&udp_av, 0); update_av(&tcp_av, 0); snprintf(buff, sizeof(buff) - 1, - "%.2f/%.2f/%.2f cmds/s, " - "%.2f/%.2f/%.2f comp lines/s, " - "%.2f/%.2f/%.2f alarms/s, " - "%.2f/%.2f/%.2f udp requests/s, " - "%.2f/%.2f/%.2f service requests/s, " - "%.2f/%.2f/%.2f runqueue length (current %ld)", - load_av.avg1, load_av.avg5, load_av.avg15, - compile_av.avg1, compile_av.avg5, compile_av.avg15, - alarm_av.avg1, alarm_av.avg5, alarm_av.avg15, - udp_av.avg1, udp_av.avg5, udp_av.avg15, - tcp_av.avg1, tcp_av.avg5, tcp_av.avg15, - runq_av.avg1, runq_av.avg5, runq_av.avg15, num_tasks + 1); + "%.2f/%.2f/%.2f cmds/s, " + "%.2f/%.2f/%.2f comp lines/s, " + "%.2f/%.2f/%.2f alarms/s, " + "%.2f/%.2f/%.2f udp requests/s, " + "%.2f/%.2f/%.2f service requests/s, " + "%.2f/%.2f/%.2f runqueue length (current %ld)", + load_av.avg1, load_av.avg5, load_av.avg15, + compile_av.avg1, compile_av.avg5, compile_av.avg15, + alarm_av.avg1, alarm_av.avg5, alarm_av.avg15, + udp_av.avg1, udp_av.avg5, udp_av.avg15, + tcp_av.avg1, tcp_av.avg5, tcp_av.avg15, + runq_av.avg1, runq_av.avg5, runq_av.avg15, num_tasks + 1); buff[sizeof(buff) - 1] = 0; return buff; } diff --git a/bibopmalloc.c b/bibopmalloc.c index 69cf9e7..fd731ab 100644 --- a/bibopmalloc.c +++ b/bibopmalloc.c @@ -65,16 +65,16 @@ #include "simulate.h" #endif -#define SMALL_SIZE 0x80 /* smaller than this is uses bibop */ -#define PAGE_SIZE 0x20000 /* 128k pages MUST!! be a power of 2 */ -#define SIZE_SLOP 0x80 /* don't split a free space if leftover is less than this */ -#define NFREE 20 /* number of headers for medium blocks */ +#define SMALL_SIZE 0x80 /* smaller than this is uses bibop */ +#define PAGE_SIZE 0x20000 /* 128k pages MUST!! be a power of 2 */ +#define SIZE_SLOP 0x80 /* don't split a free space if leftover is less than this */ +#define NFREE 20 /* number of headers for medium blocks */ typedef double aligntype; #define ALIGNMENT (sizeof(aligntype)) /* alignment requirement for this platform */ -typedef unsigned long mapword; /* should be the largest possible unsigned type */ +typedef unsigned long mapword; /* should be the largest possible unsigned type */ -#define BITS_PER_BYTE 8 /* bits per unit in sizeof */ +#define BITS_PER_BYTE 8 /* bits per unit in sizeof */ #define CEIL(x) (((x)+ALIGNMENT-1) & ~(ALIGNMENT-1)) #define PAGEMASK (~(PAGE_SIZE-1)) @@ -84,13 +84,13 @@ typedef unsigned long mapword; /* should be the largest possible unsigned type * #define BITS_PER_MAPWORD (sizeof(mapword) * BITS_PER_BYTE) struct bibop { - int objsize; /* Size of the objects (rounded) */ - int objfree; /* Number of free objects */ - int maxobjfree; /* Maximum objects that fit on the page */ - mapword *freemap; /* Bitmap for free objects */ - int nextfree; /* (Cached) index to look for free object */ - int maxfree; /* Max index into freemap */ - void *objs; /* Pointer to first object */ + int objsize; /* Size of the objects (rounded) */ + int objfree; /* Number of free objects */ + int maxobjfree; /* Maximum objects that fit on the page */ + mapword *freemap; /* Bitmap for free objects */ + int nextfree; /* (Cached) index to look for free object */ + int maxfree; /* Max index into freemap */ + void *objs; /* Pointer to first object */ }; #define BIBOPMAGIC 0x55AA5A01 static long long p_bibop, m_bibop, f_bibop; @@ -128,12 +128,12 @@ static long long p_big, m_big, f_big; static long long s_big; struct descr { - int magic; /* magic number for different page types */ - struct descr *dnext; /* next page in whatever list it happens to be in */ + int magic; /* magic number for different page types */ + struct descr *dnext; /* next page in whatever list it happens to be in */ union { - struct bibop bibop; - struct medium medium; - struct big big; + struct bibop bibop; + struct medium medium; + struct big big; } u; }; @@ -144,7 +144,7 @@ static struct descr *newbibop(unsigned int); static struct descr *firstpage; -typedef uintptr_t PTR; /* same size as a pointer */ +typedef uintptr_t PTR; /* same size as a pointer */ static struct descr *freepage = 0; static long long p_free; @@ -156,8 +156,8 @@ struct block { int busy; struct block *next; union { - aligntype data; - struct freeblk fb; + aligntype data; + struct freeblk fb; } u; }; #define DATA_TO_OBJ(p) ((struct block *)( (char *)p - (long)&((struct block *)0)->u.data )) @@ -184,37 +184,37 @@ insertfreepage(struct descr *p) #endif /* find position */ for(fp = &freepage; *fp && p > *fp; fp = &(*fp)->dnext) - ; + ; /* insert into chain */ p->dnext = *fp; *fp = p; /* check for adjecent following page */ if ((char *)p->dnext == (char *)p + p->u.big.npages * PAGE_SIZE) { - p->u.big.npages += p->dnext->u.big.npages; - p->dnext = p->dnext->dnext; + p->u.big.npages += p->dnext->u.big.npages; + p->dnext = p->dnext->dnext; #ifdef BIBOP_DEBUG (void)fprintf(stderr, ", join with next block"); #endif } /* check for adjecent preceding page */ if (fp != &freepage) { - struct descr *q; - q = (struct descr *)((char *)fp - OFFSET(struct descr, dnext)); - if ((char *)q->dnext == (char *)q + q->u.big.npages * PAGE_SIZE) { - q->u.big.npages += q->dnext->u.big.npages; - q->dnext = q->dnext->dnext; + struct descr *q; + q = (struct descr *)((char *)fp - OFFSET(struct descr, dnext)); + if ((char *)q->dnext == (char *)q + q->u.big.npages * PAGE_SIZE) { + q->u.big.npages += q->dnext->u.big.npages; + q->dnext = q->dnext->dnext; #ifdef BIBOP_DEBUG (void)fprintf(stderr, ", join with previous block"); #endif - } + } } #ifdef BIBOP_DEBUG { - struct descr *f; - (void)fprintf(stderr, "\nfree page list (nextpage=%lx):\n", nextpage); - for(f = freepage; f; f = f->dnext) { - (void)fprintf(stderr, " %lx (%lx) %d\n", f, (char *)f + f->u.big.npages * PAGE_SIZE, f->u.big.npages); - } + struct descr *f; + (void)fprintf(stderr, "\nfree page list (nextpage=%lx):\n", nextpage); + for(f = freepage; f; f = f->dnext) { + (void)fprintf(stderr, " %lx (%lx) %d\n", f, (char *)f + f->u.big.npages * PAGE_SIZE, f->u.big.npages); + } } #endif } @@ -230,68 +230,68 @@ pages(unsigned int n) #endif if (freepage) { - /* try to find something on the free list */ - /* use best fit, slower but better */ - struct descr **p, **last = 0, **best = 0, *b; - for(p = &freepage; *p; last = p, p = &(*p)->dnext) { - if ((*p)->u.big.npages == n) { - best = p; - break; - } else if ((*p)->u.big.npages > n) { - if (!best || (*p)->u.big.npages < (*best)->u.big.npages) - best = p; - } - } - if (!best) { - /* couldn't find anything, try extending last block */ - if ((char *)(*last) + (*last)->u.big.npages * PAGE_SIZE == nextpage) { - int k = n - (*last)->u.big.npages; - r = sbrk(k*PAGE_SIZE); - if (!r || (intptr_t)r == -1) { - (void)fprintf(stderr, "sbrk(%ld) failed %ld(0x%lx) with return value %p\n", - (long) k*PAGE_SIZE, (long)(nextpage - firstsbrk), - (unsigned long)(nextpage - firstsbrk), r); - return 0; - } - nextpage += k*PAGE_SIZE; - (*last)->u.big.npages += k; - best = last; - p_free += k; + /* try to find something on the free list */ + /* use best fit, slower but better */ + struct descr **p, **last = 0, **best = 0, *b; + for(p = &freepage; *p; last = p, p = &(*p)->dnext) { + if ((*p)->u.big.npages == n) { + best = p; + break; + } else if ((*p)->u.big.npages > n) { + if (!best || (*p)->u.big.npages < (*best)->u.big.npages) + best = p; + } + } + if (!best) { + /* couldn't find anything, try extending last block */ + if ((char *)(*last) + (*last)->u.big.npages * PAGE_SIZE == nextpage) { + int k = n - (*last)->u.big.npages; + r = sbrk(k*PAGE_SIZE); + if (!r || (intptr_t)r == -1) { + (void)fprintf(stderr, "sbrk(%ld) failed %ld(0x%lx) with return value %p\n", + (long) k*PAGE_SIZE, (long)(nextpage - firstsbrk), + (unsigned long)(nextpage - firstsbrk), r); + return 0; + } + nextpage += k*PAGE_SIZE; + (*last)->u.big.npages += k; + best = last; + p_free += k; #ifdef BIBOP_DEBUG - (void)fprintf(stderr, ", extending %d", k); + (void)fprintf(stderr, ", extending %d", k); #endif - } else - goto notfound; - } + } else + goto notfound; + } #ifdef BIBOP_DEBUG - (void)fprintf(stderr, ", from free list"); -#endif - /* best points at something usable */ - b = *best; - r = b; - if (b->u.big.npages > n) { - /* split the block */ - *best = (struct descr *)((char *)b + n * PAGE_SIZE); - (*best)->magic = b->magic; - (*best)->u.big.npages = b->u.big.npages - n; - (*best)->dnext = b->dnext; + (void)fprintf(stderr, ", from free list"); +#endif + /* best points at something usable */ + b = *best; + r = b; + if (b->u.big.npages > n) { + /* split the block */ + *best = (struct descr *)((char *)b + n * PAGE_SIZE); + (*best)->magic = b->magic; + (*best)->u.big.npages = b->u.big.npages - n; + (*best)->dnext = b->dnext; #ifdef BIBOP_DEBUG - (void)fprintf(stderr, ", split it %d %d", b->u.big.npages, n); + (void)fprintf(stderr, ", split it %d %d", b->u.big.npages, n); #endif - } else { - *best = b->dnext; /* remove block */ - } - p_free -= n; + } else { + *best = b->dnext; /* remove block */ + } + p_free -= n; #ifdef BIBOP_DEBUG { - struct descr *f; - (void)fprintf(stderr, "\nfree page list (nextpage=%lx):\n", nextpage); - for(f = freepage; f; f = f->dnext) { - (void)fprintf(stderr, " %lx (%lx) %d\n", f, (char *)f + f->u.big.npages * PAGE_SIZE, f->u.big.npages); - } + struct descr *f; + (void)fprintf(stderr, "\nfree page list (nextpage=%lx):\n", nextpage); + for(f = freepage; f; f = f->dnext) { + (void)fprintf(stderr, " %lx (%lx) %d\n", f, (char *)f + f->u.big.npages * PAGE_SIZE, f->u.big.npages); + } } #endif - return r; + return r; } notfound: @@ -301,13 +301,13 @@ pages(unsigned int n) r = sbrk(n*PAGE_SIZE); if (!r || (intptr_t)r == -1) { - (void)fprintf(stderr, "sbrk failed %ld with return value %p\n", (long)(nextpage - firstsbrk), r); - return 0; + (void)fprintf(stderr, "sbrk failed %ld with return value %p\n", (long)(nextpage - firstsbrk), r); + return 0; } if (!(nextpage - PAGE_SIZE <= (char *)r && (char *)r <= nextpage + PAGE_SIZE)) { - (void)fprintf(stderr, "bad sbrk %p %p\n", r, - nextpage); + (void)fprintf(stderr, "bad sbrk %p %p\n", r, + nextpage); } r = nextpage; nextpage += n*PAGE_SIZE; @@ -322,11 +322,11 @@ insfree(struct block *b, int how) int i; for(i = 0; i < NFREE && freehead[i].maxsize <= s; i++) - ; + ; #ifdef PARANOIA if (i == NFREE) { - (void)fprintf(stderr, "insfree %d\n", s); - abort(); + (void)fprintf(stderr, "insfree %d\n", s); + abort(); } #endif FINS(&b->u.fb, &freehead[i].h); @@ -370,39 +370,39 @@ bigmalloc(unsigned int size) int cursize, i; if (size > PAGE_SIZE - sizeof(struct descr) - ALIGNMENT - PTR_SIZE) { - /* really big! */ - unsigned int n = (size + sizeof(struct descr) + PAGE_SIZE - 1) / PAGE_SIZE; - struct descr *bigp = pages(n); - if (!bigp) - return 0; - p_big += n; - bigp->magic = BIGMAGIC; - bigp->u.big.npages = n; - m_big++; - s_big += size; - return (void *)&bigp->u.big.data; + /* really big! */ + unsigned int n = (size + sizeof(struct descr) + PAGE_SIZE - 1) / PAGE_SIZE; + struct descr *bigp = pages(n); + if (!bigp) + return 0; + p_big += n; + bigp->magic = BIGMAGIC; + bigp->u.big.npages = n; + m_big++; + s_big += size; + return (void *)&bigp->u.big.data; } - + /* find first block which is big enough */ for(i = 0; i < NFREE; i++) { - if (freehead[i].maxsize > size) { - struct freeblk *fp; - for(fp = freehead[i].h.fwd; fp != &freehead[i].h; fp = fp->fwd) { - cur = DATA_TO_OBJ(fp); - cursize = OBJSIZE(cur); - if (cursize >= size) { - p = (struct descr *)((PTR)cur & PAGEMASK); - goto found; - } - } - freehead[i].nskip++; - } + if (freehead[i].maxsize > size) { + struct freeblk *fp; + for(fp = freehead[i].h.fwd; fp != &freehead[i].h; fp = fp->fwd) { + cur = DATA_TO_OBJ(fp); + cursize = OBJSIZE(cur); + if (cursize >= size) { + p = (struct descr *)((PTR)cur & PAGEMASK); + goto found; + } + } + freehead[i].nskip++; + } } /* No page had a block that was big enough, get a new one. */ p = pages(1); if (!p) - return 0; + return 0; p_alloc++; init_allocpage(p); p->dnext = firstpage; @@ -412,44 +412,44 @@ bigmalloc(unsigned int size) found: #ifdef BIBOP_DEBUG if (cur->bmagic != BMAGIC) { - (void)fprintf(stderr, "bad magic 2\n"); - abort(); + (void)fprintf(stderr, "bad magic 2\n"); + abort(); } #endif - FDEL(&cur->u.fb); /* remove from free lists */ + FDEL(&cur->u.fb); /* remove from free lists */ #ifdef FREESTAT cur->u.fb.head->nalloc++; { - int i; - for(i = 0; i < NFREE && freehead[i].maxsize < size; i++) - ; + int i; + for(i = 0; i < NFREE && freehead[i].maxsize < size; i++) + ; #ifdef PARANOIA - if (i == NFREE) - abort(); + if (i == NFREE) + abort(); #endif - freehead[i].nreal++; - if (cur == (struct block *)&p->u.medium.data && cur->next->next == 0) - freehead[i].nwhy++; + freehead[i].nreal++; + if (cur == (struct block *)&p->u.medium.data && cur->next->next == 0) + freehead[i].nwhy++; } #endif if (size + SIZE_SLOP < cursize) { - /* we have to split the current block */ - next = (struct block *)((char *)cur + size + sizeof(struct block)); + /* we have to split the current block */ + next = (struct block *)((char *)cur + size + sizeof(struct block)); #ifdef BIBOP_DEBUG - next->bmagic = BMAGIC; + next->bmagic = BMAGIC; #endif - next->busy = 0; + next->busy = 0; #ifdef PARANOIA - if ((struct descr *)((PTR)cur->next & PAGEMASK) != p) - abort(); + if ((struct descr *)((PTR)cur->next & PAGEMASK) != p) + abort(); #endif - next->next = cur->next; - cur->next = next; + next->next = cur->next; + cur->next = next; #ifdef PARANOIA - if ((struct descr *)((PTR)cur->next & PAGEMASK) != p) - abort(); + if ((struct descr *)((PTR)cur->next & PAGEMASK) != p) + abort(); #endif - insfree(next, 1); /* insert second half */ + insfree(next, 1); /* insert second half */ } cur->busy = 1; m_alloc++; @@ -482,9 +482,9 @@ static void missaligned_free(void *ptr, void *should_be) { if (mstring_magic(should_be + mstring_header) == MSTRING_MAGIC) - fatal("freeing m-magic string: %s\n", (char *)should_be + mstring_header); + fatal("freeing m-magic string: %s\n", (char *)should_be + mstring_header); if (sstring_magic(should_be + sstring_header) == SSTRING_MAGIC) - fatal("freeing s-magic string: %s\n", (char *)should_be + sstring_header); + fatal("freeing s-magic string: %s\n", (char *)should_be + sstring_header); fatal("Freeing different pointer than malloced is %p should be %p.\n", ptr, should_be); } @@ -500,32 +500,32 @@ malloc(size_t size) size = CEIL(size); if (!initdone) - bibop_init(); + bibop_init(); if (size >= SMALL_SIZE) - return bigmalloc(size); + return bigmalloc(size); for(bp = bibops[size/ALIGNMENT - 1]; bp && bp->u.bibop.objfree == 0; bp = bp->dnext) - ; + ; if (!bp) { - /* Add a new page */ - bp = newbibop(size); - if (!bp) - return 0; - bp->dnext = bibops[size/ALIGNMENT - 1]; - bibops[size/ALIGNMENT - 1] = bp; + /* Add a new page */ + bp = newbibop(size); + if (!bp) + return 0; + bp->dnext = bibops[size/ALIGNMENT - 1]; + bibops[size/ALIGNMENT - 1] = bp; } /* locate word with free block */ for(i = bp->u.bibop.nextfree; ;) { - m = bp->u.bibop.freemap[i]; - if (m) - break; - if (++i >= bp->u.bibop.maxfree) - i = 0; + m = bp->u.bibop.freemap[i]; + if (m) + break; + if (++i >= bp->u.bibop.maxfree) + i = 0; #ifdef PARANOIA - if (i == bp->u.bibop.nextfree) { - /* Help! We've wrapped around without finding the promised free block! */ - (void)fprintf(stderr, "bmalloc wrapped around, size = %ld\n", (long)size); - abort(); - } + if (i == bp->u.bibop.nextfree) { + /* Help! We've wrapped around without finding the promised free block! */ + (void)fprintf(stderr, "bmalloc wrapped around, size = %ld\n", (long)size); + abort(); + } #endif } bp->u.bibop.nextfree = i; @@ -533,23 +533,23 @@ malloc(size_t size) #define ONES (~(mapword)0) j = 0; if ((m & (ONES >> (BITS_PER_MAPWORD/2))) == 0) - j += BITS_PER_MAPWORD/2, m >>= BITS_PER_MAPWORD/2; + j += BITS_PER_MAPWORD/2, m >>= BITS_PER_MAPWORD/2; else - m &= (ONES >> (BITS_PER_MAPWORD/2)); + m &= (ONES >> (BITS_PER_MAPWORD/2)); if ((m & (ONES >> (3*BITS_PER_MAPWORD/4))) == 0) - j += BITS_PER_MAPWORD/4, m >>= BITS_PER_MAPWORD/4; + j += BITS_PER_MAPWORD/4, m >>= BITS_PER_MAPWORD/4; else - m &= (ONES >> (3*BITS_PER_MAPWORD/4)); + m &= (ONES >> (3*BITS_PER_MAPWORD/4)); if ((m & (ONES >> (7*BITS_PER_MAPWORD/8))) == 0) - j += BITS_PER_MAPWORD/8, m >>= BITS_PER_MAPWORD/8; + j += BITS_PER_MAPWORD/8, m >>= BITS_PER_MAPWORD/8; else - m &= (ONES >> (7*BITS_PER_MAPWORD/8)); + m &= (ONES >> (7*BITS_PER_MAPWORD/8)); /* We're down to at most 8 bits now (if there are <= 64 bits in a word). Use a table to look up the last bit set. */ j += flsb[(int)m]; - bp->u.bibop.freemap[i] &= ~ ((mapword)1<u.bibop.objfree--; /* one less free */ + bp->u.bibop.freemap[i] &= ~ ((mapword)1<u.bibop.objfree--; /* one less free */ m_bibop++; s_bibop += size; return (void *) ((char *)bp->u.bibop.objs + (i * BITS_PER_MAPWORD + j) * size); @@ -563,7 +563,7 @@ calloc(size_t nmemb, size_t size) p = malloc(nmemb * size); if (p != NULL) - memset(p, '\0', nmemb * size); + memset(p, '\0', nmemb * size); return p; } @@ -576,118 +576,118 @@ free(void *ptr) int i, j; if (!ptr) - return; + return; if (!initdone) - return; + return; bp = (struct descr *)((PTR)ptr & PAGEMASK); if (bp->magic == BIGMAGIC) { - /* freeing really big block, stuff all pages on free list */ - int n = bp->u.big.npages; + /* freeing really big block, stuff all pages on free list */ + int n = bp->u.big.npages; #ifdef DEBUG if (ptr != &bp->u.big.data) missaligned_free(ptr, &bp->u.big.data); #endif - insertfreepage(bp); - f_big++; - p_big -= n; - p_free += n; + insertfreepage(bp); + f_big++; + p_big -= n; + p_free += n; } else if (bp->magic == ALLOCMAGIC) { - /* freeing part of a page */ - struct block *this, *cur, *next; + /* freeing part of a page */ + struct block *this, *cur, *next; - this = DATA_TO_OBJ(ptr); + this = DATA_TO_OBJ(ptr); #ifdef DEBUG if (ptr != &this->u.data) missaligned_free(ptr, &this->u.data); #endif #ifdef BIBOP_DEBUG - if (DATA_TO_OBJ(ptr)->bmagic != BMAGIC) { - (void)fprintf(stderr, "bad magic 3\n"); - abort(); - } + if (DATA_TO_OBJ(ptr)->bmagic != BMAGIC) { + (void)fprintf(stderr, "bad magic 3\n"); + abort(); + } #endif #ifdef PARANOIA - if (!this->busy) - abort(); -#endif - this->busy = 0; - insfree(this, 2); - /* coalescing is tedious since we don't have back pointers */ - for(cur = (struct block *)&bp->u.medium.data; cur->next; cur = cur->next) - if (cur == this || (cur->next == this && !cur->busy)) - break; + if (!this->busy) + abort(); +#endif + this->busy = 0; + insfree(this, 2); + /* coalescing is tedious since we don't have back pointers */ + for(cur = (struct block *)&bp->u.medium.data; cur->next; cur = cur->next) + if (cur == this || (cur->next == this && !cur->busy)) + break; #ifdef PARANOIA - if (!cur->next || cur->busy) - abort(); + if (!cur->next || cur->busy) + abort(); #endif - /* coalesce free blocks (max 3) */ - for(;;) { - next = cur->next; + /* coalesce free blocks (max 3) */ + for(;;) { + next = cur->next; #ifdef BIBOP_DEBUG - if (next->bmagic != BMAGIC) { - (void)fprintf(stderr, "bad magic 1\n"); - abort(); - } -#endif - if (!next->next || next->busy) - break; - cur->next = next->next; + if (next->bmagic != BMAGIC) { + (void)fprintf(stderr, "bad magic 1\n"); + abort(); + } +#endif + if (!next->next || next->busy) + break; + cur->next = next->next; #ifdef BIBOP_DEBUG - next->bmagic = 0; + next->bmagic = 0; #endif #ifdef PARANOIA - if ((struct descr *)((PTR)cur->next & PAGEMASK) != bp) - abort(); + if ((struct descr *)((PTR)cur->next & PAGEMASK) != bp) + abort(); #endif #ifdef FREESTAT - cur->u.fb.head->njoin1++; - next->u.fb.head->njoin2++; -#endif - FDEL(&cur->u.fb); - FDEL(&next->u.fb); - insfree(cur, 3); - } - - if (((struct block *)&bp->u.medium.data)->next->next == 0) { - /* The whole page is free now, move it to free list */ - struct descr **p; - struct block *blk = (struct block *)&bp->u.medium.data; - FDEL(&blk->u.fb); + cur->u.fb.head->njoin1++; + next->u.fb.head->njoin2++; +#endif + FDEL(&cur->u.fb); + FDEL(&next->u.fb); + insfree(cur, 3); + } + + if (((struct block *)&bp->u.medium.data)->next->next == 0) { + /* The whole page is free now, move it to free list */ + struct descr **p; + struct block *blk = (struct block *)&bp->u.medium.data; + FDEL(&blk->u.fb); #ifdef FREESTAT - blk->u.fb.head->ndrop++; -#endif - for(p = &firstpage; *p != bp; p = &(*p)->dnext) - ; - *p = (*p)->dnext; - bp->u.big.npages = 1; - insertfreepage(bp); - p_free++; - p_alloc--; - } - f_alloc++; + blk->u.fb.head->ndrop++; +#endif + for(p = &firstpage; *p != bp; p = &(*p)->dnext) + ; + *p = (*p)->dnext; + bp->u.big.npages = 1; + insertfreepage(bp); + p_free++; + p_alloc--; + } + f_alloc++; } else if (bp->magic == BIBOPMAGIC) { - offs = ((char *)ptr - (char *)bp->u.bibop.objs) / bp->u.bibop.objsize; /* block offset from first block */ - i = offs / BITS_PER_MAPWORD; - j = offs % BITS_PER_MAPWORD; + offs = ((char *)ptr - (char *)bp->u.bibop.objs) / bp->u.bibop.objsize; /* block offset from first block */ + i = offs / BITS_PER_MAPWORD; + j = offs % BITS_PER_MAPWORD; #ifdef DEBUG if (ptr != (char *)bp->u.bibop.objs + (offs * bp->u.bibop.objsize)) missaligned_free(ptr, (char *)bp->u.bibop.objs + (offs * bp->u.bibop.objsize)); #endif #ifdef PARANOIA - if (bp->u.bibop.freemap[i] & (mapword)1<u.bibop.freemap[i] & (mapword)1<u.bibop.freemap[i] |= (mapword)1<u.bibop.nextfree = i; /* we have a free block here */ - bp->u.bibop.objfree++; /* one more free */ - f_bibop++; + bp->u.bibop.freemap[i] |= (mapword)1<u.bibop.nextfree = i; /* we have a free block here */ + bp->u.bibop.objfree++; /* one more free */ + f_bibop++; } else { - /* Happens when freeing prematurely allocated objects. */ - (void)fprintf(stderr, "Warning, bad magic number in free %x (%p)\n", - bp->magic, ptr); + /* Happens when freeing prematurely allocated objects. */ + (void)fprintf(stderr, "Warning, bad magic number in free %x (%p)\n", + bp->magic, ptr); } } @@ -707,33 +707,33 @@ realloc(void *old, size_t size) void *new; if (!old) - return malloc(size); + return malloc(size); bp = (struct descr *)((PTR)old & PAGEMASK); switch (bp->magic) { case BIGMAGIC: - osize = bp->u.big.npages * PAGE_SIZE; - break; + osize = bp->u.big.npages * PAGE_SIZE; + break; case ALLOCMAGIC: - osize = OBJSIZE(DATA_TO_OBJ(old)); - break; + osize = OBJSIZE(DATA_TO_OBJ(old)); + break; case BIBOPMAGIC: - osize = bp->u.bibop.objsize; - break; + osize = bp->u.bibop.objsize; + break; default: - (void)fprintf(stderr, "Bad magic number in realloc %x\n", bp->magic); - osize = 0; - break; + (void)fprintf(stderr, "Bad magic number in realloc %x\n", bp->magic); + osize = 0; + break; } if (osize > size) - osize = size; + osize = size; else if (osize == size) - return old; + return old; /* Always assume the worst and allocate© */ new = malloc(size); if (!new) - return 0; + return 0; (void)memcpy(new, old, osize); @@ -753,13 +753,13 @@ unsigned int size; /* (void)fprintf(stderr, "newbibop %d\n", size);*/ bp = pages(1); if (!bp) - return 0; + return 0; p_bibop++; /* I'm to lazy to figure out the exact formula. Iterate at runtime instead. */ for(nmap = 0, nnmap = -1; nmap != nnmap;) { - nobj = (PAGE_SIZE - sizeof(struct descr) - nmap * sizeof(mapword) - 2 * ALIGNMENT) / size; - nnmap = nmap; - nmap = (nobj + BITS_PER_MAPWORD - 1) / BITS_PER_MAPWORD; + nobj = (PAGE_SIZE - sizeof(struct descr) - nmap * sizeof(mapword) - 2 * ALIGNMENT) / size; + nnmap = nmap; + nmap = (nobj + BITS_PER_MAPWORD - 1) / BITS_PER_MAPWORD; } bp->magic = BIBOPMAGIC; bp->u.bibop.objsize = size; @@ -773,12 +773,12 @@ unsigned int size; /* fill the freemap */ for(i = 0; i < nmap-1; i++) - bp->u.bibop.freemap[i] = (mapword)~0; + bp->u.bibop.freemap[i] = (mapword)~0; j = nobj % BITS_PER_MAPWORD; /* no of bits needed in last word, or 0 all are needed */ if (j) - bp->u.bibop.freemap[i] = ((mapword)~0) >> (BITS_PER_MAPWORD - j); + bp->u.bibop.freemap[i] = ((mapword)~0) >> (BITS_PER_MAPWORD - j); else - bp->u.bibop.freemap[i] = (mapword)~0; + bp->u.bibop.freemap[i] = (mapword)~0; return bp; } @@ -791,7 +791,7 @@ bibop_init() int i; if (initdone) - return; + return; initdone++; /* set up nextpage to point to space at a page boundary */ firstsbrk = nextpage = (char *)( ( (PTR)sbrk(PAGE_SIZE+1) & PAGEMASK) + PAGE_SIZE ); @@ -801,12 +801,12 @@ bibop_init() sfact = (double)maxs / mins; smult = exp(log(sfact) / NFREE); for(s = smult, i = 0; i < NFREE; i++, s *= smult) { - freehead[i].h.fwd = &freehead[i].h; - freehead[i].h.bwd = &freehead[i].h; - freehead[i].maxsize = (int) (mins * s + 0.5); - /*(void)fprintf(stderr, "bucket %d holds size <%d\n", i, freehead[i].maxsize);*/ + freehead[i].h.fwd = &freehead[i].h; + freehead[i].h.bwd = &freehead[i].h; + freehead[i].maxsize = (int) (mins * s + 0.5); + /*(void)fprintf(stderr, "bucket %d holds size <%d\n", i, freehead[i].maxsize);*/ #ifdef FREESTAT - freehead[i].h.head = &freehead[i]; + freehead[i].h.head = &freehead[i]; #endif } } @@ -822,21 +822,21 @@ dump_malloc_data() u_bibop = u_alloc = u_big = n_bibop = n_alloc = n_big = a_bibop = a_alloc = a_big = 0; for(i = 0; i < (SMALL_SIZE+ALIGNMENT-1)/ALIGNMENT; i++) { - for(p = bibops[i]; p; p = p->dnext) { - n = p->u.bibop.objfree * p->u.bibop.objsize; - n_bibop += n; - u_bibop += PAGE_SIZE - n; - a_bibop += p->u.bibop.objfree; - } + for(p = bibops[i]; p; p = p->dnext) { + n = p->u.bibop.objfree * p->u.bibop.objsize; + n_bibop += n; + u_bibop += PAGE_SIZE - n; + a_bibop += p->u.bibop.objfree; + } } for(p = firstpage; p; p = p->dnext) { - struct block *q; - for(q = (struct block *)&p->u.medium.data; q->next; q = q->next) { - if (q->busy) - u_alloc += OBJSIZE(q); - else - n_alloc += OBJSIZE(q), a_alloc++; - } + struct block *q; + for(q = (struct block *)&p->u.medium.data; q->next; q = q->next) { + if (q->busy) + u_alloc += OBJSIZE(q); + else + n_alloc += OBJSIZE(q), a_alloc++; + } } u_big = PAGE_SIZE * p_big; (void)sprintf(mbuf, "\ @@ -855,38 +855,38 @@ dump_malloc_data() \n\ sbrk requests: %lld %lld (a) \n\ ", - "", "small", "medium", "large", "total", - "used memory", u_bibop, u_alloc, u_big, u_bibop+u_alloc+u_big, - "free memory", n_bibop, n_alloc, n_big, n_bibop+n_alloc+n_big+p_free*PAGE_SIZE, + "", "small", "medium", "large", "total", + "used memory", u_bibop, u_alloc, u_big, u_bibop+u_alloc+u_big, + "free memory", n_bibop, n_alloc, n_big, n_bibop+n_alloc+n_big+p_free*PAGE_SIZE, " ", p_free*PAGE_SIZE, - "used blocks", m_bibop-f_bibop, m_alloc-f_alloc, m_big-f_big, m_bibop+m_alloc+m_big-(f_bibop+f_alloc+f_big), - "free blocks", a_bibop, a_alloc, a_big, a_bibop + a_alloc + a_big, - "allocated pages", p_bibop, p_alloc, p_big, p_bibop+p_alloc+p_big+p_free+1, + "used blocks", m_bibop-f_bibop, m_alloc-f_alloc, m_big-f_big, m_bibop+m_alloc+m_big-(f_bibop+f_alloc+f_big), + "free blocks", a_bibop, a_alloc, a_big, a_bibop + a_alloc + a_big, + "allocated pages", p_bibop, p_alloc, p_big, p_bibop+p_alloc+p_big+p_free+1, " ", p_free, (p_bibop+p_alloc+p_big+p_free+1)*PAGE_SIZE, (long long)PAGE_SIZE, - "# of malloc()", m_bibop, m_alloc, m_big, m_bibop+m_alloc+m_big, - "# of free()", f_bibop, f_alloc, f_big, f_bibop+f_alloc+f_big, - "total allocation", s_bibop, s_alloc, s_big, s_bibop+s_alloc+s_big, - p_bibop+p_alloc+p_big+p_free+1, (p_bibop+p_alloc+p_big+p_free+1)*PAGE_SIZE); + "# of malloc()", m_bibop, m_alloc, m_big, m_bibop+m_alloc+m_big, + "# of free()", f_bibop, f_alloc, f_big, f_bibop+f_alloc+f_big, + "total allocation", s_bibop, s_alloc, s_big, s_bibop+s_alloc+s_big, + p_bibop+p_alloc+p_big+p_free+1, (p_bibop+p_alloc+p_big+p_free+1)*PAGE_SIZE); #ifdef FREESTAT { - char xxxxx[2000]; - int k, tf; - (void)strcpy(xxxxx, "medium sizes:\n size unus split free join alloc join1 join2 drop real why skip\n"); - for(tf = 0, k = 0; k < NFREE; k++) { - struct freeblk *p; - int s; - for(s = 0, p = freehead[k].h.fwd; p != &freehead[k].h; p = p->fwd, s++) - ; - (void)sprintf(xxxxx+strlen(xxxxx), "%5d %4d %6d %6d %6d %6d %5d %5d %4d %5d %3d %5d\n", - freehead[k].maxsize, s, - freehead[k].nsplit, freehead[k].nfree, freehead[k].njoin, - freehead[k].nalloc, freehead[k].njoin1, freehead[k].njoin2, freehead[k].ndrop, - freehead[k].nreal, freehead[k].nwhy, freehead[k].nskip); - tf += s; - } - (void)sprintf(xxxxx+strlen(xxxxx), "tot=%d(%d)\n", tf, a_alloc); - (void)strcat(mbuf, xxxxx); + char xxxxx[2000]; + int k, tf; + (void)strcpy(xxxxx, "medium sizes:\n size unus split free join alloc join1 join2 drop real why skip\n"); + for(tf = 0, k = 0; k < NFREE; k++) { + struct freeblk *p; + int s; + for(s = 0, p = freehead[k].h.fwd; p != &freehead[k].h; p = p->fwd, s++) + ; + (void)sprintf(xxxxx+strlen(xxxxx), "%5d %4d %6d %6d %6d %6d %5d %5d %4d %5d %3d %5d\n", + freehead[k].maxsize, s, + freehead[k].nsplit, freehead[k].nfree, freehead[k].njoin, + freehead[k].nalloc, freehead[k].njoin1, freehead[k].njoin2, freehead[k].ndrop, + freehead[k].nreal, freehead[k].nwhy, freehead[k].nskip); + tf += s; + } + (void)sprintf(xxxxx+strlen(xxxxx), "tot=%d(%d)\n", tf, a_alloc); + (void)strcat(mbuf, xxxxx); } #endif return mbuf; diff --git a/call_out.c b/call_out.c index ee67868..94d06b9 100644 --- a/call_out.c +++ b/call_out.c @@ -62,13 +62,13 @@ remove_ob(struct object *ob) { if (ob->call_outs && !ob->callout_task) { - int slot = SLOT(ob->call_outs->when); - for (obp = &(call_outs[slot]); *obp && *obp != ob; - obp = &(*obp)->next_call_out) ; - if (!*obp) - return; /* It's not on the list */ - *obp = ob->next_call_out; - ob->next_call_out = 0; + int slot = SLOT(ob->call_outs->when); + for (obp = &(call_outs[slot]); *obp && *obp != ob; + obp = &(*obp)->next_call_out) ; + if (!*obp) + return; /* It's not on the list */ + *obp = ob->next_call_out; + ob->next_call_out = 0; } } static void @@ -76,7 +76,7 @@ add_ob(struct object *ob) { struct object **obp; if (ob->next_call_out) - abort(); + abort(); if (ob->call_outs && !ob->callout_task) { int slot = SLOT(ob->call_outs->when); @@ -105,13 +105,13 @@ call_out_swap_objects(struct object *ob1, struct object *ob2) ob1->callout_task = ob2->callout_task; ob1->num_callouts = ob2->num_callouts; if (ob1->callout_task) - ob1->callout_task->arg = ob1; + ob1->callout_task->arg = ob1; ob2->call_outs = co; ob2->callout_task = task; ob2->num_callouts = num_callouts; if (ob2->callout_task) - ob2->callout_task->arg = ob2; + ob2->callout_task->arg = ob2; add_ob(ob1); add_ob(ob2); @@ -123,20 +123,20 @@ insert_call_out(struct object *ob, struct call *cop) struct call **copp; if (!ob->call_outs || cop->when < ob->call_outs->when) { - remove_ob(ob); - cop->next = ob->call_outs; - ob->call_outs = cop; - if (!ob->callout_task) { - if (cop->when <= last) - ob->callout_task = create_task((void (*)(void *))run_call_out, ob); - else - add_ob(ob); - } - return; + remove_ob(ob); + cop->next = ob->call_outs; + ob->call_outs = cop; + if (!ob->callout_task) { + if (cop->when <= last) + ob->callout_task = create_task((void (*)(void *))run_call_out, ob); + else + add_ob(ob); + } + return; } /* Insert the callout */ for (copp = &ob->call_outs; *copp && cop->when >= (*copp)->when; - copp = &(*copp)->next) ; + copp = &(*copp)->next) ; cop->next = *copp; *copp = cop; @@ -148,7 +148,7 @@ free_call(struct call *cop) free_closure(cop->func); #ifdef THIS_PLAYER_IN_CALLOUT if (cop->command_giver) - free_object(cop->command_giver, "free_call"); + free_object(cop->command_giver, "free_call"); #endif free((char *)cop); num_call--; @@ -161,14 +161,14 @@ new_call_out(struct closure *fun, double delay, double reload) struct call *cop; if (delay < 0) - delay = 0; + delay = 0; if (reload < 0) - reload = -1; + reload = -1; if (current_object->num_callouts >= MAX_CALL_OUT) { - delete_all_calls(current_object); - error("too many alarms in object\n"); + delete_all_calls(current_object); + error("too many alarms in object\n"); } cop = (struct call *)xalloc(sizeof(struct call)); @@ -183,7 +183,7 @@ new_call_out(struct closure *fun, double delay, double reload) #ifdef THIS_PLAYER_IN_CALLOUT cop->command_giver = command_giver; if (command_giver) - INCREF(command_giver->ref); + INCREF(command_giver->ref); #endif current_object->num_callouts++; num_call++; @@ -198,20 +198,20 @@ delete_call(struct object *ob, long long call_ident) int remove_first = 0; if (ob->call_outs && ob->call_outs->id == call_ident) { - remove_first = 1; - remove_ob(ob); + remove_first = 1; + remove_ob(ob); } for(copp = &ob->call_outs; *copp && (*copp)->id != call_ident; - copp = &(*copp)->next) ; + copp = &(*copp)->next) ; if (!*copp) - return; + return; cop = *copp; *copp = (*copp)->next; free_call(cop); ob->num_callouts--; if (remove_first) { - add_ob(ob); + add_ob(ob); } } @@ -225,8 +225,8 @@ delete_all_calls(struct object *ob) ob->callout_task = NULL; for(cop = ob->call_outs; cop; cop = next) { - next = cop->next; - free_call(cop); + next = cop->next; + free_call(cop); } ob->call_outs = 0; ob->num_callouts = 0; @@ -248,9 +248,9 @@ get_call(struct object *ob, long long call_ident) struct call *cop; for(cop = ob->call_outs; cop && cop->id != call_ident; cop = cop->next) - ; + ; if (!cop) - return 0; + return 0; val = allocate_array(5); @@ -264,7 +264,7 @@ get_call(struct object *ob, long long call_ident) val->item[2].type = T_FLOAT; val->item[2].u.real = cop->when - alarm_time; if (val->item[2].u.real < 0.0) - val->item[2].u.real = 0.0; + val->item[2].u.real = 0.0; val->item[3].type = T_FLOAT; val->item[3].u.real = cop->reload; @@ -290,36 +290,36 @@ get_calls(struct object *ob) int i; for(i = 0, cop = ob->call_outs; cop; i++, cop = cop->next) - ; + ; ret = allocate_array(i); for(i = 0, cop = ob->call_outs; cop; i++, cop = cop->next) { - struct vector *val; - - val = allocate_array(5); - - val->item[0].type = T_NUMBER; - val->item[0].u.number = cop->id; - - val->item[1].type = T_STRING; - val->item[1].string_type = STRING_MSTRING; - val->item[1].u.string = make_mstring(getclosurename(cop->func)); - - val->item[2].type = T_FLOAT ; - val->item[2].u.real = cop->when - alarm_time; - if (val->item[2].u.real < 0.0) - val->item[2].u.real = 0.0; - - val->item[3].type = T_FLOAT; - val->item[3].u.real = cop->reload; - - val->item[4].type = T_POINTER; - val->item[4].u.vec = cop->func->funargs; - INCREF(cop->func->funargs->ref); - - ret->item[i].type = T_POINTER; - ret->item[i].u.vec = val; + struct vector *val; + + val = allocate_array(5); + + val->item[0].type = T_NUMBER; + val->item[0].u.number = cop->id; + + val->item[1].type = T_STRING; + val->item[1].string_type = STRING_MSTRING; + val->item[1].u.string = make_mstring(getclosurename(cop->func)); + + val->item[2].type = T_FLOAT ; + val->item[2].u.real = cop->when - alarm_time; + if (val->item[2].u.real < 0.0) + val->item[2].u.real = 0.0; + + val->item[3].type = T_FLOAT; + val->item[3].u.real = cop->reload; + + val->item[4].type = T_POINTER; + val->item[4].u.vec = cop->func->funargs; + INCREF(cop->func->funargs->ref); + + ret->item[i].type = T_POINTER; + ret->item[i].u.vec = val; } return ret; } @@ -327,7 +327,7 @@ get_calls(struct object *ob) long long current_call_out_id; struct object *current_call_out_object; -int inhibitcallouts = 0; /* Stop call-out processing. */ +int inhibitcallouts = 0; /* Stop call-out processing. */ /* * last_alarm is at which slot we last executed an alarm @@ -345,30 +345,30 @@ next_call_out(struct timeval *tvp) end = 0; slot = SLOT(last); do { - /* - * We found an alarm... - */ - if (call_outs[slot]) { - /* - * We found an alarm that was scheduled to run already - */ - if (call_outs[slot]->call_outs->when < last) { - tvp->tv_sec = 0; - tvp->tv_usec = 0; - return; - } - /* - * We found an alarm that is scheduled to run within the next - * 3 seconds - */ - else if (call_outs[slot]->call_outs->when - last < 3.0) { - double delay = call_outs[slot]->call_outs->when - last; - tvp->tv_sec = delay; - tvp->tv_usec = (delay - tvp->tv_sec) * 1e6 + 0.5; - return; - } - } - slot = (slot + 1) & (NUM_SLOTS - 1); + /* + * We found an alarm... + */ + if (call_outs[slot]) { + /* + * We found an alarm that was scheduled to run already + */ + if (call_outs[slot]->call_outs->when < last) { + tvp->tv_sec = 0; + tvp->tv_usec = 0; + return; + } + /* + * We found an alarm that is scheduled to run within the next + * 3 seconds + */ + else if (call_outs[slot]->call_outs->when - last < 3.0) { + double delay = call_outs[slot]->call_outs->when - last; + tvp->tv_sec = delay; + tvp->tv_usec = (delay - tvp->tv_sec) * 1e6 + 0.5; + return; + } + } + slot = (slot + 1) & (NUM_SLOTS - 1); } while (slot != end); /* Failed to find a call_out. Do extensive search */ tvp->tv_sec = 3; /* default to 3 seconds */ @@ -384,54 +384,54 @@ run_call_out(struct object *ob) struct closure *thefun; if (inhibitcallouts || !ob->call_outs || - ob->call_outs->when > alarm_time) { - ob->callout_task = 0; + ob->call_outs->when > alarm_time) { + ob->callout_task = 0; add_ob(ob); - return; + return; } /* Get one callout */ cop = ob->call_outs; ob->call_outs = cop->next; if (cop->reload >= 0) /* Reschedule the callout */ { - current_call_out_id = cop->id; - if (cop->reload < 1e-12) - cop->when = alarm_time; - else - cop->when = alarm_time - fmod(alarm_time - cop->when, cop->reload) + - cop->reload; - if (cop->when < alarm_time) - cop->when = alarm_time; - - for (copp = &ob->call_outs; - *copp && (*copp)->when < cop->when; - copp = &(*copp)->next) ; - cop->next = *copp; - *copp = cop; + current_call_out_id = cop->id; + if (cop->reload < 1e-12) + cop->when = alarm_time; + else + cop->when = alarm_time - fmod(alarm_time - cop->when, cop->reload) + + cop->reload; + if (cop->when < alarm_time) + cop->when = alarm_time; + + for (copp = &ob->call_outs; + *copp && (*copp)->when < cop->when; + copp = &(*copp)->next) ; + cop->next = *copp; + *copp = cop; } else - current_call_out_id = 0; + current_call_out_id = 0; /* do the call */ #ifdef THIS_PLAYER_IN_CALLOUT if (cop->command_giver && - cop->command_giver->flags & O_DESTRUCTED) + cop->command_giver->flags & O_DESTRUCTED) { - free_object(cop->command_giver, "call_out"); - cop->command_giver = 0; + free_object(cop->command_giver, "call_out"); + cop->command_giver = 0; } - - + + if (cop->command_giver && - cop->command_giver->flags & O_ENABLE_COMMANDS) - command_giver = cop->command_giver; + cop->command_giver->flags & O_ENABLE_COMMANDS) + command_giver = cop->command_giver; else if (ob->flags & O_ENABLE_COMMANDS) - command_giver = ob; + command_giver = ob; else #endif - command_giver = 0; + command_giver = 0; if (s_flag) - reset_mudstatus(); + reset_mudstatus(); eval_cost = 0; current_call_out_object = current_object = ob; @@ -440,52 +440,52 @@ run_call_out(struct object *ob) exception_frame.e_exception = exception; exception_frame.e_catch = 0; exception = &exception_frame; - + thefun = cop->func; INCREF(thefun->ref); /* keep a reference */ if (cop->reload < 0) { - free_call(cop); - ob->num_callouts--; + free_call(cop); + ob->num_callouts--; } if (thefun->funobj != ob) - previous_ob = ob; - + previous_ob = ob; + if (setjmp(exception_frame.e_context)) { - exception = exception_frame.e_exception; - clear_state(); - debug_message("Error in call out.\n"); - if (current_call_out_id) - { - /*access_program(ob->prog->inherit[inh].prog);*/ - debug_message("Call out %s turned off in %s.\n", getclosurename(thefun), - current_call_out_object->name); - delete_call(current_call_out_object, current_call_out_id); - } + exception = exception_frame.e_exception; + clear_state(); + debug_message("Error in call out.\n"); + if (current_call_out_id) + { + /*access_program(ob->prog->inherit[inh].prog);*/ + debug_message("Call out %s turned off in %s.\n", getclosurename(thefun), + current_call_out_object->name); + delete_call(current_call_out_object, current_call_out_id); + } } else { - update_alarm_av(); - (void)call_var(0, thefun); - exception = exception_frame.e_exception; - pop_stack(); - - if (s_flag) - { - strcpy(caodesc, "CAO:"); - strncat(caodesc, show_closure(thefun), - sizeof(caodesc) - 5); - print_mudstatus(caodesc, eval_cost, - get_millitime(), get_processtime()); - } + update_alarm_av(); + (void)call_var(0, thefun); + exception = exception_frame.e_exception; + pop_stack(); + + if (s_flag) + { + strcpy(caodesc, "CAO:"); + strncat(caodesc, show_closure(thefun), + sizeof(caodesc) - 5); + print_mudstatus(caodesc, eval_cost, + get_millitime(), get_processtime()); + } } free_closure(thefun); /* and kill the extra reference */ free_object(current_call_out_object, "call_out"); previous_ob = 0; /* Reschedule the object */ if (ob->call_outs && (ob->call_outs->when <= alarm_time || - ob->call_outs->when <= last)) { - reschedule_task(ob->callout_task); - return; + ob->call_outs->when <= last)) { + reschedule_task(ob->callout_task); + return; } ob->callout_task = 0; add_ob(ob); @@ -499,37 +499,37 @@ call_out(struct timeval *tvp) int end = 0; if (inhibitcallouts) { - if (tvp) { - tvp->tv_sec = 3; - tvp->tv_usec = 0; - } - return; + if (tvp) { + tvp->tv_sec = 3; + tvp->tv_usec = 0; + } + return; } while (!end) { - int slot, slot_end; - - if (last > alarm_time) - break; - last_end = last + 2.0; - if (last_end > alarm_time) { - last_end = alarm_time; /* last lap */ - end = 1; - } - slot = SLOT(last); - slot_end = (SLOT(last_end) + 1) & (NUM_SLOTS - 1); - for (; slot != slot_end; slot = ((slot + 1) & (NUM_SLOTS - 1))) - while(call_outs[slot] && - call_outs[slot]->call_outs->when <= last_end) - { - /* Extract the object and the callout */ - ob = call_outs[slot]; - call_outs[slot] = ob->next_call_out; - ob->next_call_out = 0; - ob->callout_task = create_task((void (*)(void *))run_call_out, ob); - } - last = last_end; + int slot, slot_end; + + if (last > alarm_time) + break; + last_end = last + 2.0; + if (last_end > alarm_time) { + last_end = alarm_time; /* last lap */ + end = 1; + } + slot = SLOT(last); + slot_end = (SLOT(last_end) + 1) & (NUM_SLOTS - 1); + for (; slot != slot_end; slot = ((slot + 1) & (NUM_SLOTS - 1))) + while(call_outs[slot] && + call_outs[slot]->call_outs->when <= last_end) + { + /* Extract the object and the callout */ + ob = call_outs[slot]; + call_outs[slot] = ob->next_call_out; + ob->next_call_out = 0; + ob->callout_task = create_task((void (*)(void *))run_call_out, ob); + } + last = last_end; } if (tvp) next_call_out(tvp); @@ -550,27 +550,27 @@ dump_callouts(FILE *f) count = 0; ob = obj_list; do { - for (c = ob->call_outs; c; c = c->next) - { + for (c = ob->call_outs; c; c = c->next) + { #ifdef THIS_PLAYER_IN_CALLOUT - if (!c->command_giver || - c->command_giver->flags & O_DESTRUCTED) - { - giver = "(void)"; - } else { - giver = c->command_giver->name; - } + if (!c->command_giver || + c->command_giver->flags & O_DESTRUCTED) + { + giver = "(void)"; + } else { + giver = c->command_giver->name; + } #endif - fprintf(f, + fprintf(f, "%s %s %9.6f %9.6f %s\n", ob->name, show_closure(c->func), c->when - alarm_time, c->reload, giver); - - count++; - } + + count++; + } } while ((ob = ob->next_all) != obj_list); return count; @@ -586,11 +586,11 @@ count_ref_from_call_outs() #ifdef THIS_PLAYER_IN_CALLOUT ob = obj_list; do { - for(cop = ob->call_outs; cop; cop = cop->next) - { - if (cop->command_giver) - cop->command_giver->extra_ref++; - } + for(cop = ob->call_outs; cop; cop = cop->next) + { + if (cop->command_giver) + cop->command_giver->extra_ref++; + } } while ((ob = ob->next_all) != obj_list); #endif diff --git a/clib/efun.c b/clib/efun.c index a44e096..475dff1 100644 --- a/clib/efun.c +++ b/clib/efun.c @@ -38,122 +38,122 @@ efun_sort(struct svalue *fp) if (fp[0].type == T_POINTER) { - start = p = 0; - end = fp[0].u.vec->size; - if (fp[1].type == T_FUNCTION) { - compare = fp[1].u.func; + start = p = 0; + end = fp[0].u.vec->size; + if (fp[1].type == T_FUNCTION) { + compare = fp[1].u.func; if (compare->funtype == FUN_EFUN) { error("sort_array with efun function"); } - while (p || (end - start) > 1) - { - if ((end - start) < 2) - { - start = ss[--p]; - end = es[p]; - } - else - { - h = A[((start + end) / 2)]; - for (c = l = start, r = end; c < r;) - { - push_svalue(&A[c]); - push_svalue(&h); - (void)call_var(2, compare); - i = ((sp->type == T_NUMBER) ? (sp->u.number) : 0); - pop_stack(); - if (i < 0) - { - t = A[l]; - A[l++] = A[c]; - A[c++] = t; - } - else if (i > 0) - { - t = A[--r]; - A[r] = A[c]; - A[c] = t; - } - else - c++; - } - if ((l - start) < (end - c)) - { /* Push the larger part, keep recursion to a minimum */ - ss[p] = c; - es[p++] = end; - end = l; - } - else - { - ss[p] = start; - es[p++] = l; - start = c; - } - } - } - } - else - { /* No compare function */ - while (p || (end - start) > 1) - { - if ((end - start) < 2) - { - start = ss[--p]; - end = es[p]; - } - else - { - h = A[((start + end) / 2)]; - for (c = l = start, r = end; c < r;) - { - switch ((A[c].type == h.type) ? A[c].type : 0) - { - case T_NUMBER: - i = (A[c].u.number - h.u.number); - break; - case T_FLOAT: - i = (((A[c].u.real - h.u.real) < 0) ? - -1 : - ((A[c].u.real - h.u.real) > 0) ? 1 : 0); - break; - case T_STRING: - i = (strcmp(A[c].u.string, h.u.string )); - break; - default: - i = (A[c].type - h.type); - } - if (i < 0) - { - t = A[l]; - A[l++] = A[c]; - A[c++] = t; - } - else if (i > 0) - { - t = A[--r]; - A[r] = A[c]; - A[c] = t; - } - else - c++; - } - if ((l - start) < (end - c)) - { /* Push the larger part, keep recursion to a minimum */ - ss[p] = c; - es[p++] = end; - end = l; - } - else - { - ss[p] = start; - es[p++] = l; - start = c; - } - } - } - } + while (p || (end - start) > 1) + { + if ((end - start) < 2) + { + start = ss[--p]; + end = es[p]; + } + else + { + h = A[((start + end) / 2)]; + for (c = l = start, r = end; c < r;) + { + push_svalue(&A[c]); + push_svalue(&h); + (void)call_var(2, compare); + i = ((sp->type == T_NUMBER) ? (sp->u.number) : 0); + pop_stack(); + if (i < 0) + { + t = A[l]; + A[l++] = A[c]; + A[c++] = t; + } + else if (i > 0) + { + t = A[--r]; + A[r] = A[c]; + A[c] = t; + } + else + c++; + } + if ((l - start) < (end - c)) + { /* Push the larger part, keep recursion to a minimum */ + ss[p] = c; + es[p++] = end; + end = l; + } + else + { + ss[p] = start; + es[p++] = l; + start = c; + } + } + } + } + else + { /* No compare function */ + while (p || (end - start) > 1) + { + if ((end - start) < 2) + { + start = ss[--p]; + end = es[p]; + } + else + { + h = A[((start + end) / 2)]; + for (c = l = start, r = end; c < r;) + { + switch ((A[c].type == h.type) ? A[c].type : 0) + { + case T_NUMBER: + i = (A[c].u.number - h.u.number); + break; + case T_FLOAT: + i = (((A[c].u.real - h.u.real) < 0) ? + -1 : + ((A[c].u.real - h.u.real) > 0) ? 1 : 0); + break; + case T_STRING: + i = (strcmp(A[c].u.string, h.u.string )); + break; + default: + i = (A[c].type - h.type); + } + if (i < 0) + { + t = A[l]; + A[l++] = A[c]; + A[c++] = t; + } + else if (i > 0) + { + t = A[--r]; + A[r] = A[c]; + A[c] = t; + } + else + c++; + } + if ((l - start) < (end - c)) + { /* Push the larger part, keep recursion to a minimum */ + ss[p] = c; + es[p++] = end; + end = l; + } + else + { + ss[p] = start; + es[p++] = l; + start = c; + } + } + } + } } push_svalue(fp); } @@ -171,23 +171,23 @@ efun_cat_file(struct svalue *fp) char *str; if (fp[0].type != T_STRING || fp[1].type != T_NUMBER - || fp[2].type != T_NUMBER) + || fp[2].type != T_NUMBER) { - push_number(0); - return; + push_number(0); + return; } str = read_file(fp[0].u.string, fp[1].u.number, fp[2].u.number); if (str) { - push_mstring(str); - if (command_giver) - (void)apply("catch_tell", command_giver, 1, 0); - else - (void)apply("catch_tell", current_interactive, 1, 0); - push_number(read_file_len); + push_mstring(str); + if (command_giver) + (void)apply("catch_tell", command_giver, 1, 0); + else + (void)apply("catch_tell", current_interactive, 1, 0); + push_number(read_file_len); } else - push_number(0); + push_number(0); } static func func_cat_file = @@ -208,63 +208,63 @@ efun_tell_room(struct svalue *fp) if (fp[3].type == T_OBJECT) tp = fp[3].u.ob; else if (command_giver && !(command_giver->flags & O_DESTRUCTED)) - tp = command_giver; + tp = command_giver; else - tp = 0; + tp = 0; if (fp[0].type == T_STRING) - room = find_object2(fp[0].u.string); + room = find_object2(fp[0].u.string); else if (fp[0].type == T_OBJECT) - room = fp[0].u.ob; + room = fp[0].u.ob; if (!room) return; switch (fp[2].type) { case T_OBJECT: - size = 1; - oblist = &fp[2]; - break; + size = 1; + oblist = &fp[2]; + break; case T_POINTER: - size = fp[2].u.vec->size; - oblist = fp[2].u.vec->item; - break; + size = fp[2].u.vec->size; + oblist = fp[2].u.vec->item; + break; default: - size = 0; - break; + size = 0; + break; } /* tell folx in room */ for(ob = room->contains; ob; ob = ob->next_inv) { - print = 1; - for (i = 0; i < size; i++) - if (oblist[i].u.ob == ob) - { - print = 0; - break; - } - /* before we push, check if it's a living */ - if ((ob->flags & O_ENABLE_COMMANDS) && print) - { - push_svalue(&fp[1]); - push_object(tp); - (void)apply("catch_msg", ob, 2, 0); - } + print = 1; + for (i = 0; i < size; i++) + if (oblist[i].u.ob == ob) + { + print = 0; + break; + } + /* before we push, check if it's a living */ + if ((ob->flags & O_ENABLE_COMMANDS) && print) + { + push_svalue(&fp[1]); + push_object(tp); + (void)apply("catch_msg", ob, 2, 0); + } } /* tell room */ print = 1; ob = room; for (i = 0; i < size; i++) - if (oblist[i].u.ob == ob) - { - print = 0; - break; - } + if (oblist[i].u.ob == ob) + { + print = 0; + break; + } if ((ob->flags & O_ENABLE_COMMANDS) && print) { - push_svalue(&fp[1]); - push_object(tp); - (void)apply("catch_msg", ob, 2, 0); + push_svalue(&fp[1]); + push_object(tp); + (void)apply("catch_msg", ob, 2, 0); } } @@ -282,9 +282,9 @@ efun_write(struct svalue *fp) if (!command_giver) { - if (fp[0].type == T_STRING) - (void)printf("%s", fp[0].u.string); - return; + if (fp[0].type == T_STRING) + (void)printf("%s", fp[0].u.string); + return; } push_svalue(fp); (void)apply("catch_tell", command_giver, 1, 0); @@ -308,9 +308,9 @@ efun_say(struct svalue *fp) push_number(0); if (command_giver && !(command_giver->flags & O_DESTRUCTED)) - tp = command_giver; + tp = command_giver; else - tp = previous_ob; + tp = previous_ob; if (tp == NULL) return; @@ -324,75 +324,75 @@ efun_say(struct svalue *fp) switch (fp[1].type) { case T_OBJECT: - size = 1; - oblist = &fp[1]; - break; + size = 1; + oblist = &fp[1]; + break; case T_POINTER: - size = fp[1].u.vec->size; - oblist = fp[1].u.vec->item; - break; + size = fp[1].u.vec->size; + oblist = fp[1].u.vec->item; + break; default: - if (tp) - { - size = 1; - oblist = &tp_svalue; - } - else size = 0; - break; + if (tp) + { + size = 1; + oblist = &tp_svalue; + } + else size = 0; + break; } /* tell folx in room */ if (tp && tp->super) { - for (ob = tp->super->contains; ob; ob = ob->next_inv) - { - print = 1; - for (i = 0; i < size; i++) - if (oblist[i].u.ob == ob) - print = 0; - /* before we push, check if it's a living */ - if ((ob->flags & O_ENABLE_COMMANDS) && print) - { - push_svalue(fp); - push_svalue(&tp_svalue); - (void)apply("catch_msg", ob, 2, 0); - } - } - - /* tell room */ - print = 1; ob = tp->super; - for (i = 0; i < size; i++) - if (oblist[i].u.ob == ob) - print = 0; - if ((ob->flags & O_ENABLE_COMMANDS) && print) - { - push_svalue(fp); - push_svalue(&tp_svalue); - (void)apply("catch_msg", ob, 2, 0); - } + for (ob = tp->super->contains; ob; ob = ob->next_inv) + { + print = 1; + for (i = 0; i < size; i++) + if (oblist[i].u.ob == ob) + print = 0; + /* before we push, check if it's a living */ + if ((ob->flags & O_ENABLE_COMMANDS) && print) + { + push_svalue(fp); + push_svalue(&tp_svalue); + (void)apply("catch_msg", ob, 2, 0); + } + } + + /* tell room */ + print = 1; ob = tp->super; + for (i = 0; i < size; i++) + if (oblist[i].u.ob == ob) + print = 0; + if ((ob->flags & O_ENABLE_COMMANDS) && print) + { + push_svalue(fp); + push_svalue(&tp_svalue); + (void)apply("catch_msg", ob, 2, 0); + } } /* tell folx in player */ for (ob = tp->contains; ob; ob = ob->next_inv) { - print = 1; - for (i = 0; i < size; i++) - if (oblist[i].u.ob == ob) - print = 0; - /* before we push, check if it's a living */ - if ((ob->flags & O_ENABLE_COMMANDS) && print) - { - push_svalue(fp); - push_svalue(&tp_svalue); - (void)apply("catch_msg", ob, 2, 0); - } + print = 1; + for (i = 0; i < size; i++) + if (oblist[i].u.ob == ob) + print = 0; + /* before we push, check if it's a living */ + if ((ob->flags & O_ENABLE_COMMANDS) && print) + { + push_svalue(fp); + push_svalue(&tp_svalue); + (void)apply("catch_msg", ob, 2, 0); + } } /* tell this_player */ print = 1; ob = tp; for (i = 0; i < size; i++) if (oblist[i].u.ob == ob) - print = 0; + print = 0; if (ob && (ob->flags & O_ENABLE_COMMANDS) && print) { push_svalue(fp); @@ -411,9 +411,9 @@ static void efun_atoi(struct svalue *fp) { if (fp->type == T_STRING) - push_number(atoi(fp->u.string)); + push_number(atoi(fp->u.string)); else - push_number(0); + push_number(0); } static func func_atoi = { diff --git a/clib/gl_language.c b/clib/gl_language.c index dd6aa8f..33fa151 100644 --- a/clib/gl_language.c +++ b/clib/gl_language.c @@ -30,7 +30,7 @@ global_article(struct svalue *fp) if (fp->type != T_STRING) { push_number(0); - return; + return; } size_t len = strlen(fp->u.string); @@ -245,8 +245,8 @@ global_plural_word(struct svalue *fp) if (fp->type != T_STRING) { - push_number(0); - return; + push_number(0); + return; } char *str = fp->u.string; @@ -261,7 +261,7 @@ global_plural_word(struct svalue *fp) if (sl < 3 || sl > 100) { push_svalue(fp); - return; + return; } char *tmp = alloca(sl + 10); @@ -275,37 +275,37 @@ global_plural_word(struct svalue *fp) case 's': case 'x': case 'h': - (void)strcat(tmp, "es"); - break; + (void)strcat(tmp, "es"); + break; case 'y': - if (penultimate == 'a' || penultimate == 'e' || penultimate == 'o') - (void)strcat(tmp, "s"); - else - { - tmp[sl - 1] = '\0'; - (void)strcat(tmp, "ies"); - } - break; + if (penultimate == 'a' || penultimate == 'e' || penultimate == 'o') + (void)strcat(tmp, "s"); + else + { + tmp[sl - 1] = '\0'; + (void)strcat(tmp, "ies"); + } + break; case 'e': - if (penultimate == 'f') - { - tmp[sl - 2] = '\0'; - (void)strcat(tmp, "ves"); - } - else - (void)strcat(tmp, "s"); - break; + if (penultimate == 'f') + { + tmp[sl - 2] = '\0'; + (void)strcat(tmp, "ves"); + } + else + (void)strcat(tmp, "s"); + break; case 'f': - if (penultimate == 'f') - { - tmp[sl - 2] = '\0'; - } - tmp[sl - 1] = '\0'; - (void)strcat(tmp, "ves"); - break; + if (penultimate == 'f') + { + tmp[sl - 2] = '\0'; + } + tmp[sl - 1] = '\0'; + (void)strcat(tmp, "ves"); + break; default: - (void)strcat(tmp, "s"); - break; + (void)strcat(tmp, "s"); + break; } push_string(tmp, STRING_MSTRING); return; diff --git a/clib/stdobject.c b/clib/stdobject.c index 4536450..987127f 100644 --- a/clib/stdobject.c +++ b/clib/stdobject.c @@ -41,54 +41,54 @@ object_check_call(struct svalue *fp) if (fp[0].type != T_STRING && fp[0].type != T_FUNCTION) { - push_svalue(&fp[0]); - return; + push_svalue(&fp[0]); + return; } assign_svalue(&VAR(obj_prev), &fp[1]); if (fp[0].type == T_FUNCTION) { - fun = fp[0].u.func; - (void)call_var(0, fun); - assign_svalue(&VAR(obj_prev), &const0); - return; + fun = fp[0].u.func; + (void)call_var(0, fun); + assign_svalue(&VAR(obj_prev), &const0); + return; } str = fp[0].u.string; if (str[0] == '@' && str[1] == '@') { - p = &str[2]; - p2 = &p[-1]; - while ((p2 = (char *) strchr(&p2[1], '@')) && - (p2[1] != '@')) - ; - if (!p2) - { - ret = process_value(p, 1); - } - else if (p2[2] == '\0') - { - size_t len = strlen(p); - p2 = (char *) alloca(len - 1); - (void)strncpy(p2, p, len - 2); - p2[len - 2] = '\0'; - ret = process_value(p2, 1); - } - else - retstr = process_string(str, 1); + p = &str[2]; + p2 = &p[-1]; + while ((p2 = (char *) strchr(&p2[1], '@')) && + (p2[1] != '@')) + ; + if (!p2) + { + ret = process_value(p, 1); + } + else if (p2[2] == '\0') + { + size_t len = strlen(p); + p2 = (char *) alloca(len - 1); + (void)strncpy(p2, p, len - 2); + p2[len - 2] = '\0'; + ret = process_value(p2, 1); + } + else + retstr = process_string(str, 1); } else retstr = process_string(str, 1); if (ret) { - push_svalue(ret); + push_svalue(ret); } else { if (retstr) - push_mstring(retstr); + push_mstring(retstr); else push_svalue(&fp[0]); } @@ -118,34 +118,34 @@ object_query_prop(struct svalue *fp) char *p, *p2, *str, *retstr = NULL; extern struct svalue *get_map_lvalue(struct mapping *, - struct svalue *, int ); + struct svalue *, int ); if (VAR(obj_props).type != T_MAPPING) { - push_number(0); - return; + push_number(0); + return; } val = get_map_lvalue(VAR(obj_props).u.map, fp, 0); if (val->type != T_STRING && val->type != T_FUNCTION) { - if (val->type == T_OBJECT && (val->u.ob->flags & O_DESTRUCTED)) - free_svalue(val); - push_svalue(val); - return; + if (val->type == T_OBJECT && (val->u.ob->flags & O_DESTRUCTED)) + free_svalue(val); + push_svalue(val); + return; } if (previous_ob != NULL) { - tmp.type = T_OBJECT; - tmp.u.ob = previous_ob; - assign_svalue(&VAR(obj_prev), &tmp); + tmp.type = T_OBJECT; + tmp.u.ob = previous_ob; + assign_svalue(&VAR(obj_prev), &tmp); } else - assign_svalue(&VAR(obj_prev), &const0); + assign_svalue(&VAR(obj_prev), &const0); if (val->type == T_FUNCTION) { - fun = val->u.func; + fun = val->u.func; if (!legal_closure(fun)) { @@ -153,45 +153,45 @@ object_query_prop(struct svalue *fp) return; } - (void)call_var(0, fun); - assign_svalue(&VAR(obj_prev), &const0); - return; + (void)call_var(0, fun); + assign_svalue(&VAR(obj_prev), &const0); + return; } str = val->u.string; if (str[0] == '@' && str[1] == '@') { - p = &str[2]; - p2 = &p[-1]; - while ((p2 = (char *) strchr(&p2[1], '@')) && - (p2[1] != '@')) - ; - if (!p2) - { - ret = process_value(p, 1); - } - else if (p2[2] == '\0') - { - size_t len = strlen(p); - p2 = (char *) tmpalloc(len - 1); - (void)strncpy(p2, p, len - 2); - p2[len - 2] = '\0'; - ret = process_value(p2, 1); - } - else - retstr = process_string(str, 1); + p = &str[2]; + p2 = &p[-1]; + while ((p2 = (char *) strchr(&p2[1], '@')) && + (p2[1] != '@')) + ; + if (!p2) + { + ret = process_value(p, 1); + } + else if (p2[2] == '\0') + { + size_t len = strlen(p); + p2 = (char *) tmpalloc(len - 1); + (void)strncpy(p2, p, len - 2); + p2[len - 2] = '\0'; + ret = process_value(p2, 1); + } + else + retstr = process_string(str, 1); } else retstr = process_string(str, 1); if (ret) { - push_svalue(ret); + push_svalue(ret); } else { if (retstr) - push_mstring(retstr); + push_mstring(retstr); else push_svalue(val); } @@ -210,7 +210,7 @@ static void object_add_prop(struct svalue *fp) { extern struct svalue *get_map_lvalue(struct mapping *, - struct svalue *, int ); + struct svalue *, int ); struct svalue *oval; if (VAR(obj_no_change).u.number || VAR(obj_props).type != T_MAPPING) diff --git a/comm.h b/comm.h index f59e645..10934c2 100644 --- a/comm.h +++ b/comm.h @@ -3,27 +3,27 @@ #include #include -#define MAX_WRITE_SOCKET_SIZE 8192 +#define MAX_WRITE_SOCKET_SIZE 8192 #include "config.h" struct interactive { void *tp; - struct object *ob; /* Points to the associated object */ - struct sentence *input_to; /* To be called with next input line ! */ + struct object *ob; /* Points to the associated object */ + struct sentence *input_to; /* To be called with next input line ! */ struct sockaddr_storage addr; char *host_name; socklen_t addrlen; char *prompt; - int closing; /* True when closing this socket. */ - int do_close; /* This is to be closed down. */ + int closing; /* True when closing this socket. */ + int do_close; /* This is to be closed down. */ struct interactive *snoop_on, *snoop_by; - int noecho; /* Don't echo lines */ - int last_time; /* Time of last command executed */ - char *default_err_message; /* This or What ? is printed when error */ - int trace_level; /* Debug flags. 0 means no debugging */ - char *trace_prefix; /* Trace only object which has this as name prefix */ - struct ed_buffer *ed_buffer; /* Local ed */ + int noecho; /* Don't echo lines */ + int last_time; /* Time of last command executed */ + char *default_err_message; /* This or What ? is printed when error */ + int trace_level; /* Debug flags. 0 means no debugging */ + char *trace_prefix; /* Trace only object which has this as name prefix */ + struct ed_buffer *ed_buffer; /* Local ed */ char *rname; int lport; int rport; @@ -44,4 +44,4 @@ void *new_player(void *, struct sockaddr_storage *, socklen_t, u_short); void mssp_request(struct interactive *ip); -void set_ip_number(struct object *ob, char *ip); \ No newline at end of file +void set_ip_number(struct object *ob, char *ip); diff --git a/comm1.c b/comm1.c index 9e766a2..3b3168f 100644 --- a/comm1.c +++ b/comm1.c @@ -81,19 +81,19 @@ shutdown_hname(void *hp) static void receive_hname(const char *addr, int lport, int rport, - const char *ip_name, const char *rname) + const char *ip_name, const char *rname) { int i; struct interactive *ip; if (addr == NULL || rname == NULL) - return; + return; for (i = 0; i < MAX_PLAYERS; i++) { - ip = all_players[i]; - if (ip == NULL) - continue; + ip = all_players[i]; + if (ip == NULL) + continue; const char *ip_number = query_ip_number(ip->ob); if (ip_number != NULL && !strcmp(addr, query_ip_number(ip->ob))) @@ -222,130 +222,130 @@ write_socket(char *cp, struct object *ob) if (ob == NULL || ob->flags & O_DESTRUCTED || (ip = ob->interactive) == NULL || ip->do_close) { - (void)fputs(cp, stderr); - (void)fflush(stderr); - return; + (void)fputs(cp, stderr); + (void)fflush(stderr); + return; } #ifdef SUPER_SNOOP if (ip->snoop_fd != -1) - (void)write(ip->snoop_fd, cp, strlen(cp)); + (void)write(ip->snoop_fd, cp, strlen(cp)); #endif if (ip->snoop_by != NULL) - add_message2(ip->snoop_by->ob, "%%%s", cp); + add_message2(ip->snoop_by->ob, "%%%s", cp); #ifdef WORD_WRAP if (ip->screen_width != 0) { - current_column = ip->current_column; - - bp = buf; - - for (;;) - { - if (*cp == '\0') - break; - - if (bp >= &buf[MAX_WRITE_SOCKET_SIZE]) - { - bp = &buf[MAX_WRITE_SOCKET_SIZE]; - overflow = 1; - break; - } - - if (*cp == '\n') - { - current_column = 0; - *bp++ = *cp++; - *bp = '\0'; - - telnet_overflow = telnet_output(ip->tp, (u_char *)buf); - bp = buf; - if (telnet_overflow) - break; - continue; - } - - if (*cp == '\t') - { - current_column &= ~7; - current_column += 8; - if (current_column >= ip->screen_width) - { - current_column = 0; - *bp++ = '\n'; - *bp = '\0'; - telnet_overflow = telnet_output(ip->tp, (u_char *)buf); - bp = buf; - if (telnet_overflow) - break; - - while (*cp == ' ' || *cp == '\t') - cp++; - } - else - { - *bp++ = *cp++; - } - continue; - } - - len = 1; - while (cp[len] > ' ' && cp[len - 1] != '-') - len++; - - if (current_column + len >= ip->screen_width) - { - if (current_column > ip->screen_width * 4 / 5) - { - current_column = 0; - *bp++ = '\n'; - *bp = '\0'; - telnet_overflow = telnet_output(ip->tp, (u_char *)buf); - bp = buf; - if (telnet_overflow) - break; - - while (*cp == ' ' || *cp == '\t') - cp++; - if (*cp == '\n') - cp++; - continue; - } - } - - if (bp + len > &buf[MAX_WRITE_SOCKET_SIZE]) - { - len = (&buf[MAX_WRITE_SOCKET_SIZE] - bp); - overflow = 1; - } - - current_column += len; - for (; len > 0; len--) - *bp++ = *cp++; - } - - ip->current_column = current_column; - - *bp = '\0'; - telnet_overflow |= telnet_output(ip->tp, (u_char *)buf); - - if (overflow && !telnet_overflow) - telnet_output(ip->tp, (u_char *)"*** Truncated! ***\n"); + current_column = ip->current_column; + + bp = buf; + + for (;;) + { + if (*cp == '\0') + break; + + if (bp >= &buf[MAX_WRITE_SOCKET_SIZE]) + { + bp = &buf[MAX_WRITE_SOCKET_SIZE]; + overflow = 1; + break; + } + + if (*cp == '\n') + { + current_column = 0; + *bp++ = *cp++; + *bp = '\0'; + + telnet_overflow = telnet_output(ip->tp, (u_char *)buf); + bp = buf; + if (telnet_overflow) + break; + continue; + } + + if (*cp == '\t') + { + current_column &= ~7; + current_column += 8; + if (current_column >= ip->screen_width) + { + current_column = 0; + *bp++ = '\n'; + *bp = '\0'; + telnet_overflow = telnet_output(ip->tp, (u_char *)buf); + bp = buf; + if (telnet_overflow) + break; + + while (*cp == ' ' || *cp == '\t') + cp++; + } + else + { + *bp++ = *cp++; + } + continue; + } + + len = 1; + while (cp[len] > ' ' && cp[len - 1] != '-') + len++; + + if (current_column + len >= ip->screen_width) + { + if (current_column > ip->screen_width * 4 / 5) + { + current_column = 0; + *bp++ = '\n'; + *bp = '\0'; + telnet_overflow = telnet_output(ip->tp, (u_char *)buf); + bp = buf; + if (telnet_overflow) + break; + + while (*cp == ' ' || *cp == '\t') + cp++; + if (*cp == '\n') + cp++; + continue; + } + } + + if (bp + len > &buf[MAX_WRITE_SOCKET_SIZE]) + { + len = (&buf[MAX_WRITE_SOCKET_SIZE] - bp); + overflow = 1; + } + + current_column += len; + for (; len > 0; len--) + *bp++ = *cp++; + } + + ip->current_column = current_column; + + *bp = '\0'; + telnet_overflow |= telnet_output(ip->tp, (u_char *)buf); + + if (overflow && !telnet_overflow) + telnet_output(ip->tp, (u_char *)"*** Truncated! ***\n"); } else #endif { - telnet_output(ip->tp, (u_char *)cp); - /* No test on overflow. Let the telnet buffer handle it. */ + telnet_output(ip->tp, (u_char *)cp); + /* No test on overflow. Let the telnet buffer handle it. */ } } #define MSR_SIZE 20 -int msecs_response[MSR_SIZE]; -int msr_point = -1; +int msecs_response[MSR_SIZE]; +int msr_point = -1; int get_msecs_response(int ix) @@ -364,76 +364,76 @@ remove_interactive(struct interactive *ip, int link_dead) int i; if (!ob || !(ob->interactive)) - return; + return; for (i = 0; i < MAX_PLAYERS; i++) { - if (all_players[i] != ob->interactive) - continue; - if (ob->interactive->closing) - fatal("Double call to remove_interactive()\n"); + if (all_players[i] != ob->interactive) + continue; + if (ob->interactive->closing) + fatal("Double call to remove_interactive()\n"); - command_giver = ob; + command_giver = ob; - if (ob->interactive->ed_buffer) - { - extern void save_ed_buffer(void); + if (ob->interactive->ed_buffer) + { + extern void save_ed_buffer(void); - /* This will call 'get_ed_buffer_save_file_name' in master_ob + /* This will call 'get_ed_buffer_save_file_name' in master_ob * If that fails(error in LPC) the closing IP will hang and - * on the next read a 'fatal read on closing socket will occur' - * unless we do this here before ip->closing = 1 - */ - (void)add_message("Saving editor buffer.\n"); - save_ed_buffer(); - } - if (ob->interactive == NULL) - return; - ob->interactive->closing = 1; - if (ob->interactive->snoop_by) - { - ob->interactive->snoop_by->snoop_on = 0; - ob->interactive->snoop_by = 0; - } - if (ob->interactive->snoop_on) - { - ob->interactive->snoop_on->snoop_by = 0; - ob->interactive->snoop_on = 0; - } - write_socket("Closing down.\n", ob); - telnet_detach(ob->interactive->tp); + * on the next read a 'fatal read on closing socket will occur' + * unless we do this here before ip->closing = 1 + */ + (void)add_message("Saving editor buffer.\n"); + save_ed_buffer(); + } + if (ob->interactive == NULL) + return; + ob->interactive->closing = 1; + if (ob->interactive->snoop_by) + { + ob->interactive->snoop_by->snoop_on = 0; + ob->interactive->snoop_by = 0; + } + if (ob->interactive->snoop_on) + { + ob->interactive->snoop_on->snoop_by = 0; + ob->interactive->snoop_on = 0; + } + write_socket("Closing down.\n", ob); + telnet_detach(ob->interactive->tp); #ifdef SUPER_SNOOP - if (ob->interactive->snoop_fd >= 0) { - (void)close(ob->interactive->snoop_fd); - ob->interactive->snoop_fd = -1; - } + if (ob->interactive->snoop_fd >= 0) { + (void)close(ob->interactive->snoop_fd); + ob->interactive->snoop_fd = -1; + } #endif - num_player--; - if (ob->interactive->input_to) - { - free_sentence(ob->interactive->input_to); - ob->interactive->input_to = 0; - } + num_player--; + if (ob->interactive->input_to) + { + free_sentence(ob->interactive->input_to); + ob->interactive->input_to = 0; + } if (ob->interactive->host_name) free(ob->interactive->host_name); - if (ob->interactive->rname) - free(ob->interactive->rname); + if (ob->interactive->rname) + free(ob->interactive->rname); - if (current_interactive == ob) - current_interactive = 0; + if (current_interactive == ob) + current_interactive = 0; - free((char *)ob->interactive); - ob->interactive = 0; - all_players[i] = 0; - free_object(ob, "remove_interactive"); + free((char *)ob->interactive); + ob->interactive = 0; + all_players[i] = 0; + free_object(ob, "remove_interactive"); - push_object(ob); - push_number(link_dead); - (void)apply_master_ob(M_REMOVE_INTERACTIVE,2); + push_object(ob); + push_number(link_dead); + (void)apply_master_ob(M_REMOVE_INTERACTIVE,2); - command_giver = save; - return; + command_giver = save; + return; } fatal("Could not find and remove player %s\n", ob->name); } @@ -451,8 +451,8 @@ set_interactive_address(struct interactive *ip, struct sockaddr_storage *addr, s } #ifndef NO_IP_DEMON - if (!no_ip_demon) - hname_sendreq(hname, query_ip_number(ip->ob), (u_short)ip->lport, atoi(query_port_number(ip->ob))); + if (!no_ip_demon) + hname_sendreq(hname, query_ip_number(ip->ob), (u_short)ip->lport, atoi(query_port_number(ip->ob))); #endif } @@ -467,16 +467,16 @@ int i; int n; if (i >= num_player) /* love them ASSERTS() :-) */ - fatal("Get interactive (%d) with only %d players!\n", i, num_player); + fatal("Get interactive (%d) with only %d players!\n", i, num_player); for (n = 0; n < MAX_PLAYERS; n++) - if (all_players[n]) - if (!(i--)) - return(all_players[n]->ob); + if (all_players[n]) + if (!(i--)) + return(all_players[n]->ob); fatal("Get interactive: player %d not found! (num_players = %d)\n", - i, num_player); - return 0; /* Just to satisfy some compiler warnings */ + i, num_player); + return 0; /* Just to satisfy some compiler warnings */ } void * @@ -499,73 +499,73 @@ new_player(void *tp, struct sockaddr_storage *addr, socklen_t len, u_short local inter = (struct interactive *)xalloc(sizeof (struct interactive)); memset(inter, 0, sizeof(struct interactive)); - master_ob->interactive = inter; + master_ob->interactive = inter; master_ob->interactive->default_err_message = 0; - master_ob->flags |= O_ONCE_INTERACTIVE; - /* This initialization is not pretty. */ - master_ob->interactive->rname = 0; - master_ob->interactive->ob = master_ob; - master_ob->interactive->input_to = 0; - master_ob->interactive->closing = 0; - master_ob->interactive->snoop_on = 0; - master_ob->interactive->snoop_by = 0; - master_ob->interactive->do_close = 0; - master_ob->interactive->noecho = 0; - master_ob->interactive->trace_level = 0; - master_ob->interactive->trace_prefix = 0; - master_ob->interactive->last_time = current_time; - master_ob->interactive->ed_buffer = 0; + master_ob->flags |= O_ONCE_INTERACTIVE; + /* This initialization is not pretty. */ + master_ob->interactive->rname = 0; + master_ob->interactive->ob = master_ob; + master_ob->interactive->input_to = 0; + master_ob->interactive->closing = 0; + master_ob->interactive->snoop_on = 0; + master_ob->interactive->snoop_by = 0; + master_ob->interactive->do_close = 0; + master_ob->interactive->noecho = 0; + master_ob->interactive->trace_level = 0; + master_ob->interactive->trace_prefix = 0; + master_ob->interactive->last_time = current_time; + master_ob->interactive->ed_buffer = 0; #ifdef SUPER_SNOOP - master_ob->interactive->snoop_fd = -1; + master_ob->interactive->snoop_fd = -1; #endif #ifdef WORD_WRAP - master_ob->interactive->current_column = 0; - master_ob->interactive->screen_width = 0; + master_ob->interactive->current_column = 0; + master_ob->interactive->screen_width = 0; #endif - all_players[i] = master_ob->interactive; - all_players[i]->tp = tp; - set_prompt(NULL); + all_players[i] = master_ob->interactive; + all_players[i]->tp = tp; + set_prompt(NULL); inter->lport = local_port; set_interactive_address(inter, addr, len); num_player++; - /* - * The player object has one extra reference. - * It is asserted that the master_ob is loaded. - */ - add_ref(master_ob, "new_player"); - ret = apply_master_ob(M_CONNECT, 0); - if (ret == 0 || ret->type != T_OBJECT || - current_interactive != master_ob) - { - if (master_ob->interactive) - remove_interactive(master_ob->interactive, 0); - current_interactive = 0; - return NULL; - } - /* - * There was an object returned from connect(). Use this as the - * player object. - */ - ob = ret->u.ob; - ob->interactive = master_ob->interactive; - ob->interactive->ob = ob; - ob->flags |= O_ONCE_INTERACTIVE; - master_ob->flags &= ~O_ONCE_INTERACTIVE; - master_ob->interactive = 0; - free_object(master_ob, "reconnect"); - add_ref(ob, "new_player"); - command_giver = ob; - current_interactive = ob; + /* + * The player object has one extra reference. + * It is asserted that the master_ob is loaded. + */ + add_ref(master_ob, "new_player"); + ret = apply_master_ob(M_CONNECT, 0); + if (ret == 0 || ret->type != T_OBJECT || + current_interactive != master_ob) + { + if (master_ob->interactive) + remove_interactive(master_ob->interactive, 0); + current_interactive = 0; + return NULL; + } + /* + * There was an object returned from connect(). Use this as the + * player object. + */ + ob = ret->u.ob; + ob->interactive = master_ob->interactive; + ob->interactive->ob = ob; + ob->flags |= O_ONCE_INTERACTIVE; + master_ob->flags &= ~O_ONCE_INTERACTIVE; + master_ob->interactive = 0; + free_object(master_ob, "reconnect"); + add_ref(ob, "new_player"); + command_giver = ob; + current_interactive = ob; #ifdef SUPER_SNOOP - check_supersnoop(ob); + check_supersnoop(ob); #endif - logon(ob); - current_interactive = 0; + logon(ob); + current_interactive = 0; - return all_players[i]; + return all_players[i]; } telnet_output(tp, (u_char *)"Lpmud is full. Come back later.\n"); return NULL; @@ -577,7 +577,7 @@ call_function_interactive(struct interactive *i, char *str) struct closure *func; if (!i->input_to) - return 0; + return 0; func = i->input_to->funct; /* * Special feature: input_to() has been called to setup @@ -585,10 +585,10 @@ call_function_interactive(struct interactive *i, char *str) */ if (!legal_closure(func)) { - /* Sorry, the object has selfdestructed ! */ + /* Sorry, the object has selfdestructed ! */ free_sentence(i->input_to); - i->input_to = 0; - return 0; + i->input_to = 0; + return 0; } INCREF(func->ref); @@ -610,14 +610,14 @@ set_call(struct object *ob, struct sentence *sent, int noecho) { struct object *save = command_giver; if (ob == 0 || sent == 0) - return 0; + return 0; if (ob->interactive == 0 || ob->interactive->input_to) - return 0; + return 0; ob->interactive->input_to = sent; ob->interactive->noecho = noecho; command_giver = ob; if (noecho) - telnet_enable_echo(ob->interactive->tp); + telnet_enable_echo(ob->interactive->tp); command_giver = save; return 1; } @@ -633,48 +633,48 @@ remove_all_players() if (setjmp(exception_frame.e_context)) { - clear_state(); - (void)add_message("Anomaly in the fabric of world space.\n"); - ret = NULL; + clear_state(); + (void)add_message("Anomaly in the fabric of world space.\n"); + ret = NULL; } else { - exception = &exception_frame; - eval_cost = 0; - ret = apply_master_ob(M_START_SHUTDOWN, 0); + exception = &exception_frame; + eval_cost = 0; + ret = apply_master_ob(M_START_SHUTDOWN, 0); } if (ret && ret->type == T_POINTER) { - volatile int i; - struct vector *unload_vec = ret->u.vec; - - INCREF(unload_vec->ref); - - for (i = 0; i < unload_vec->size; i++) - if (setjmp(exception_frame.e_context)) - { - clear_state(); - (void)add_message("Anomaly in the fabric of world space.\n"); - } - else - { - exception = &exception_frame; - push_svalue(&(unload_vec->item[i])); - eval_cost = 0; - (void)apply_master_ob(M_CLEANUP_SHUTDOWN, 1); - } - free_vector(unload_vec); + volatile int i; + struct vector *unload_vec = ret->u.vec; + + INCREF(unload_vec->ref); + + for (i = 0; i < unload_vec->size; i++) + if (setjmp(exception_frame.e_context)) + { + clear_state(); + (void)add_message("Anomaly in the fabric of world space.\n"); + } + else + { + exception = &exception_frame; + push_svalue(&(unload_vec->item[i])); + eval_cost = 0; + (void)apply_master_ob(M_CLEANUP_SHUTDOWN, 1); + } + free_vector(unload_vec); } if (setjmp(exception_frame.e_context)) { - clear_state(); - (void)add_message("Anomaly in the fabric of world space.\n"); + clear_state(); + (void)add_message("Anomaly in the fabric of world space.\n"); } else { - exception = &exception_frame; - eval_cost = 0; - ret = apply_master_ob(M_FINAL_SHUTDOWN, 0); + exception = &exception_frame; + eval_cost = 0; + ret = apply_master_ob(M_FINAL_SHUTDOWN, 0); } exception = NULL; } @@ -683,9 +683,9 @@ void set_prompt(char *str) { if (str) - command_giver->interactive->prompt = str; + command_giver->interactive->prompt = str; else - command_giver->interactive->prompt = "> "; + command_giver->interactive->prompt = "> "; } @@ -712,68 +712,68 @@ set_snoop(struct object *me, struct object *you) /* Stop if people managed to quit before we got this far */ if (me->flags & O_DESTRUCTED) - return 0; + return 0; if (you && (you->flags & O_DESTRUCTED)) - return 0; + return 0; /* Find the snooper & snopee */ for(i = 0 ; i < MAX_PLAYERS && (on == 0 || by == 0); i++) { - if (all_players[i] == 0) - continue; - if (all_players[i]->ob == me) - by = all_players[i]; - else if (all_players[i]->ob == you) - on = all_players[i]; + if (all_players[i] == 0) + continue; + if (all_players[i]->ob == me) + by = all_players[i]; + else if (all_players[i]->ob == you) + on = all_players[i]; } /* Check for permissions with valid_snoop in master */ if (current_object != master_ob) { - push_object(current_object); - push_object(me); - if (you == 0) - push_number(0); - else - push_object(you); - ret = apply_master_ob(M_VALID_SNOOP, 3); - - if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) - return 0; + push_object(current_object); + push_object(me); + if (you == 0) + push_number(0); + else + push_object(you); + ret = apply_master_ob(M_VALID_SNOOP, 3); + + if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) + return 0; } /* Stop snoop */ if (you == 0) { - if (by == 0) - error("Could not find snooper to stop snoop on.\n"); - if (by->snoop_on == 0) - return 1; - by->snoop_on->snoop_by = 0; - by->snoop_on = 0; - return 1; + if (by == 0) + error("Could not find snooper to stop snoop on.\n"); + if (by->snoop_on == 0) + return 1; + by->snoop_on->snoop_by = 0; + by->snoop_on = 0; + return 1; } /* Strange event, but possible, so test for it */ if (on == 0 || by == 0) - return 0; + return 0; /* Protect against snooping loops */ for (tmp = on; tmp; tmp = tmp->snoop_on) { - if (tmp == by) - return 0; + if (tmp == by) + return 0; } /* Terminate previous snoop, if any */ if (by->snoop_on) { - by->snoop_on->snoop_by = 0; - by->snoop_on = 0; + by->snoop_on->snoop_by = 0; + by->snoop_on = 0; } if (on->snoop_by) { - on->snoop_by->snoop_on = 0; - on->snoop_by = 0; + on->snoop_by->snoop_on = 0; + on->snoop_by = 0; } on->snoop_by = by; @@ -786,9 +786,9 @@ char * query_ip_name(struct object *ob) { if (ob == 0) - ob = command_giver; + ob = command_giver; if (!ob || ob->interactive == 0) - return 0; + return 0; if (ob->interactive->host_name) return ob->interactive->host_name; @@ -802,11 +802,11 @@ query_ip_number(struct object *ob) static char host[NI_MAXHOST]; if (ob == 0) { - ob = command_giver; + ob = command_giver; } if (!ob || ob->interactive == 0) - return NULL; + return NULL; if (getnameinfo((struct sockaddr * )&ob->interactive->addr, ob->interactive->addrlen, host, sizeof(host), NULL, 0, NI_NUMERICHOST) != 0) return NULL; @@ -825,7 +825,7 @@ set_ip_number(struct object *ob, char *ip) if (!ob || ob->interactive == 0) { error("Attempt to update ip number of non interactive\n"); - return; + return; } memset(&hints, 0, sizeof(hints)); @@ -880,7 +880,7 @@ query_host_name() static char name[64]; (void)gethostname(name, sizeof(name)); - name[sizeof(name) - 1] = '\0'; /* Just to make sure */ + name[sizeof(name) - 1] = '\0'; /* Just to make sure */ return name; } @@ -888,7 +888,7 @@ struct object * query_snoop(struct object *ob) { if (ob->interactive->snoop_by == 0) - return 0; + return 0; return ob->interactive->snoop_by->ob; } @@ -896,7 +896,7 @@ int query_idle(struct object *ob) { if (!ob->interactive) - error("query_idle() of non-interactive object.\n"); + error("query_idle() of non-interactive object.\n"); return current_time - ob->interactive->last_time; } @@ -907,33 +907,33 @@ notify_no_command() extern struct object *vbfc_object; if (!command_giver || !command_giver->interactive) - return; + return; p = command_giver->interactive->default_err_message; if (p) { - /* We want 'value by function call' */ - m = process_string(p, vbfc_object != 0); + /* We want 'value by function call' */ + m = process_string(p, vbfc_object != 0); if (m) { - (void)add_message("%s", m); + (void)add_message("%s", m); free_mstring(m); } else - (void)add_message("%s", p); - free_sstring(p); - command_giver->interactive->default_err_message = 0; + (void)add_message("%s", p); + free_sstring(p); + command_giver->interactive->default_err_message = 0; } else - (void)add_message("What?\n"); + (void)add_message("What?\n"); } void clear_notify() { if (!command_giver || !command_giver->interactive) - return; + return; if (command_giver->interactive->default_err_message) { - free_sstring(command_giver->interactive->default_err_message); - command_giver->interactive->default_err_message = 0; + free_sstring(command_giver->interactive->default_err_message); + command_giver->interactive->default_err_message = 0; } } @@ -941,18 +941,18 @@ void set_notify_fail_message(char *str, int pri) { if (!command_giver || !command_giver->interactive) - return; + return; if (command_giver->interactive->default_err_message && pri == 0) - return; + return; clear_notify(); if (command_giver->interactive->default_err_message) - free_sstring(command_giver->interactive->default_err_message); + free_sstring(command_giver->interactive->default_err_message); command_giver->interactive->default_err_message = make_sstring(str); } int replace_interactive(struct object *ob, struct object *obfrom, - /*IGN*/char *name) + /*IGN*/char *name) { struct svalue *v; @@ -961,42 +961,42 @@ replace_interactive(struct object *ob, struct object *obfrom, */ push_string(name, STRING_MSTRING); if (ob) - push_object(ob); + push_object(ob); else - push_number(0); + push_number(0); push_object(obfrom); v = apply_master_ob(M_VALID_EXEC, 3); if (v && (v->type != T_NUMBER || v->u.number == 0)) - return 0; + return 0; /* (void)fprintf(stderr,"DEBUG: %s,%s\n",ob->name,obfrom->name); */ if (ob && ob->interactive) - error("Bad argument1 to exec(), was an interactive\n"); + error("Bad argument1 to exec(), was an interactive\n"); if (!obfrom->interactive) - error("Bad argument2 to exec(), was not an interactive\n"); + error("Bad argument2 to exec(), was not an interactive\n"); if (ob) { #ifdef SUPER_SNOOP - if (obfrom->interactive->snoop_fd >= 0) { - (void)close(obfrom->interactive->snoop_fd); - obfrom->interactive->snoop_fd = -1; - } + if (obfrom->interactive->snoop_fd >= 0) { + (void)close(obfrom->interactive->snoop_fd); + obfrom->interactive->snoop_fd = -1; + } #endif - ob->interactive = obfrom->interactive; - ob->interactive->ob = ob; - ob->flags |= O_ONCE_INTERACTIVE; - add_ref(ob, "exec"); - free_object(obfrom, "exec"); - if (current_interactive == obfrom) - current_interactive = ob; - obfrom->interactive = 0; - obfrom->flags &= ~O_ONCE_INTERACTIVE; + ob->interactive = obfrom->interactive; + ob->interactive->ob = ob; + ob->flags |= O_ONCE_INTERACTIVE; + add_ref(ob, "exec"); + free_object(obfrom, "exec"); + if (current_interactive == obfrom) + current_interactive = ob; + obfrom->interactive = 0; + obfrom->flags &= ~O_ONCE_INTERACTIVE; #ifdef SUPER_SNOOP - check_supersnoop(ob); + check_supersnoop(ob); #endif } else - remove_interactive(obfrom->interactive, 0); + remove_interactive(obfrom->interactive, 0); if (obfrom == command_giver) command_giver = ob; return 1; @@ -1014,11 +1014,11 @@ update_ref_counts_for_players() for (i = 0; iob->extra_ref++; - if (all_players[i]->input_to) - all_players[i]->input_to->funct->funobj->extra_ref++; + if (all_players[i] == 0) + continue; + all_players[i]->ob->extra_ref++; + if (all_players[i]->input_to) + all_players[i]->input_to->funct->funobj->extra_ref++; } } #endif /* DEBUG */ @@ -1047,44 +1047,44 @@ interactive_input(struct interactive *ip, char *cp) if (ip->noecho) { - ip->noecho = 0; - telnet_disable_echo(ip->tp); + ip->noecho = 0; + telnet_disable_echo(ip->tp); } else { #ifdef SUPER_SNOOP - if (ip->snoop_fd != -1) - { - (void)write(ip->snoop_fd, cp, strlen(cp)); - (void)write(ip->snoop_fd, "\n", 1); - } + if (ip->snoop_fd != -1) + { + (void)write(ip->snoop_fd, cp, strlen(cp)); + (void)write(ip->snoop_fd, "\n", 1); + } #endif - if (ip->snoop_by != NULL) { - exception_frame.e_exception = exception; - exception_frame.e_catch = 0; - exception = &exception_frame; - - if (setjmp(exception_frame.e_context)) - { - reset_machine(); - if (!current_interactive) - return; - - command_giver = ip->ob; - current_object = NULL; - current_interactive = command_giver; - previous_ob = command_giver; - } - else - add_message2(ip->snoop_by->ob, "%% %s\n", cp); - exception = exception_frame.e_exception; - } + if (ip->snoop_by != NULL) { + exception_frame.e_exception = exception; + exception_frame.e_catch = 0; + exception = &exception_frame; + + if (setjmp(exception_frame.e_context)) + { + reset_machine(); + if (!current_interactive) + return; + + command_giver = ip->ob; + current_object = NULL; + current_interactive = command_giver; + previous_ob = command_giver; + } + else + add_message2(ip->snoop_by->ob, "%% %s\n", cp); + exception = exception_frame.e_exception; + } } if (!current_interactive) - return; + return; /* * Now we have a string from the player. This string can go to @@ -1109,12 +1109,12 @@ interactive_input(struct interactive *ip, char *cp) eval_cost = 0; #ifdef DEBUG if (!command_giver->interactive) - fatal("Non interactive player in main loop!\n"); + fatal("Non interactive player in main loop!\n"); #endif if (s_flag) { - reset_mudstatus(); + reset_mudstatus(); } exception_frame.e_exception = exception; @@ -1124,8 +1124,8 @@ interactive_input(struct interactive *ip, char *cp) if (setjmp(exception_frame.e_context)) { reset_machine(); - if (!current_interactive) - return; + if (!current_interactive) + return; command_giver = ip->ob; current_object = NULL; current_interactive = command_giver; @@ -1133,43 +1133,43 @@ interactive_input(struct interactive *ip, char *cp) } else { - if (cp[0] == '!' && command_giver->super) - (void)parse_command(cp + 1, command_giver); - else if (command_giver->interactive->ed_buffer) - ed_cmd(cp); - else if (!call_function_interactive(command_giver->interactive, cp)) - (void)parse_command(cp, command_giver); + if (cp[0] == '!' && command_giver->super) + (void)parse_command(cp + 1, command_giver); + else if (command_giver->interactive->ed_buffer) + ed_cmd(cp); + else if (!call_function_interactive(command_giver->interactive, cp)) + (void)parse_command(cp, command_giver); } exception = exception_frame.e_exception; if (current_interactive && ip->input_to == 0 && - !(ip->ob->flags & O_DESTRUCTED) && ip->prompt) + !(ip->ob->flags & O_DESTRUCTED) && ip->prompt) { - push_string(ip->prompt, STRING_MSTRING); - exception_frame.e_exception = exception; - exception_frame.e_catch = 0; - exception = &exception_frame; - - if (setjmp(exception_frame.e_context)) - { - reset_machine(); - if (!current_interactive) - return; - - command_giver = ip->ob; - current_object = NULL; - current_interactive = command_giver; - previous_ob = command_giver; - } - else - (void)apply("catch_tell", ip->ob, 1, 1); - exception = exception_frame.e_exception; + push_string(ip->prompt, STRING_MSTRING); + exception_frame.e_exception = exception; + exception_frame.e_catch = 0; + exception = &exception_frame; + + if (setjmp(exception_frame.e_context)) + { + reset_machine(); + if (!current_interactive) + return; + + command_giver = ip->ob; + current_object = NULL; + current_interactive = command_giver; + previous_ob = command_giver; + } + else + (void)apply("catch_tell", ip->ob, 1, 1); + exception = exception_frame.e_exception; } if (s_flag && current_interactive) { - print_mudstatus(current_interactive->name, eval_cost, get_millitime(), get_processtime()); + print_mudstatus(current_interactive->name, eval_cost, get_millitime(), get_processtime()); } current_interactive = 0; } diff --git a/config.h b/config.h index dbdc017..803c9d9 100644 --- a/config.h +++ b/config.h @@ -14,7 +14,7 @@ /* * Max size of a file allowed to be read by 'read_file()'. */ -#define READ_FILE_MAX_SIZE 500000 +#define READ_FILE_MAX_SIZE 500000 /* Version of the game in the form xx.xx.xx (leading zeroes) gc. * Two digits will be appended, that is the patch level. @@ -42,12 +42,12 @@ /* * Should the indent code in "ed" be enabled? */ -#define ED_INDENT +#define ED_INDENT /* * Should we warn if the same file is included multiple times? */ -#define WARN_INCLUDES +#define WARN_INCLUDES /* * What file, if any, to automatically include. @@ -77,7 +77,7 @@ /* * The maximum number of call outs per object */ -#define MAX_CALL_OUT 512 +#define MAX_CALL_OUT 512 /* * How to extract an unsigned char from a char *. @@ -91,18 +91,18 @@ * Define the maximum stack size of the stack machine. This stack will also * contain all local variables and arguments. */ -#define EVALUATOR_STACK_SIZE 0x2000 +#define EVALUATOR_STACK_SIZE 0x2000 /* * Define the maximum call depth for functions. */ -#define MAX_TRACE 0x400 +#define MAX_TRACE 0x400 /* * Define the size of the compiler stack. This defines how complex * expressions the compiler can parse. The value should be big enough. */ -#define COMPILER_STACK_SIZE 0x2000 +#define COMPILER_STACK_SIZE 0x2000 /* * With this option defined you can trace mudlib execution from within the @@ -143,22 +143,22 @@ * Maximum number of bits in a bit field. They are stored in printable * strings, 6 bits per byte. */ -#define MAX_BITS 49152 /* even 6 */ +#define MAX_BITS 49152 /* even 6 */ /* * There is a hash table for living objects, used by find_living(). */ -#define LIVING_HASH_SIZE 0x1000 +#define LIVING_HASH_SIZE 0x1000 /* * Define what port number the game is to use. */ -#define PORTNO 3011 +#define PORTNO 3011 /* * Max number of local variables in a function. */ -#define MAX_LOCAL 127 +#define MAX_LOCAL 127 /* * The hashing function used for pointers to shared strings. @@ -171,7 +171,7 @@ /* Maximum number of evaluated nodes/loop. * If this is exceeded, current function is halted. */ -#define MAX_COST 5000000 +#define MAX_COST 5000000 /* * EXTRA_COST @@ -180,23 +180,23 @@ * Note that in the event of recursive catch() calls, only * the top level catch() will get the extra limit applied. */ -#define EXTRA_COST 10000 +#define EXTRA_COST 10000 /* * Maximum length of inherit chain */ -#define MAX_INHERIT 42 +#define MAX_INHERIT 42 /* * Maximum number of nested includes */ -#define MAX_INCLUDE 30 +#define MAX_INCLUDE 30 /* * Where to swap out objects. This file is not used if NUM_RESET_TO_SWAP * is 0. */ -#define SWAP_FILE "LP_SWAP" +#define SWAP_FILE "LP_SWAP" /* * This is the maximum array size allowed for one single array. @@ -213,16 +213,16 @@ * * This is the absolute maximum, the mudlib will probably set a lower level. */ -#define MAX_PLAYERS 4000 +#define MAX_PLAYERS 4000 /* * Reserve an extra memory area from malloc(), to free when we run out * of memory to get some warning and tell master about our memory troubles. * If this value is 0, no area will be reserved. */ -#define RESERVED_SIZE (1 << 24) +#define RESERVED_SIZE (1 << 24) /* -#define RESERVED_SIZE (1 << 17) +#define RESERVED_SIZE (1 << 17) */ /* Define the size of the shared string hash table. This number should @@ -233,7 +233,7 @@ * need more, and you will still get good results with a smaller table. * THIS IS NOT IMPLEMENTED YET. */ -#define HTABLE_SIZE 262144 +#define HTABLE_SIZE 262144 /* * Object hash table size. @@ -241,13 +241,13 @@ * the number of objects in a game, as the distribution of accesses to * objects is somewhat more uniform than that of strings. */ -#define OTABLE_SIZE 262144 /* we have several thousand obs usually */ +#define OTABLE_SIZE 262144 /* we have several thousand obs usually */ /* * Define SYSV if you are running system V with a lower release level than * Sys V.4. */ -#undef SYSV +#undef SYSV /* * Define FCHMOD_MISSING only if your system doesn't have fchmod(). @@ -267,7 +267,7 @@ * specific port. If == -1 it will not be used unless the mud is started * with the -u### flag. Where ### is the portnumber for the udp port. * If undefined the -u flag will be ignored. - #define CATCH_UDP_PORT 2500 + #define CATCH_UDP_PORT 2500 */ #undef CATCH_UDP_PORT @@ -289,7 +289,7 @@ * with the -p### flag. Where ### is the portnumber for the service * port. If undefined the -p flag will be ignored. */ -#define SERVICE_PORT 3003 +#define SERVICE_PORT 3003 /* * ALLOWED_SERVICE diff --git a/debug.c b/debug.c index 57df8cb..2589448 100644 --- a/debug.c +++ b/debug.c @@ -9,7 +9,7 @@ #include #include #include -#include /* sys/types.h and netinet/in.h are here to enable include of comm.h below */ +#include /* sys/types.h and netinet/in.h are here to enable include of comm.h below */ #include /* #include Included in comm.h below */ #include @@ -24,11 +24,11 @@ #include "udpsvc.h" #include "call_out.h" -#ifdef RUSAGE /* Defined in config.h */ +#ifdef RUSAGE /* Defined in config.h */ #include extern int getrusage (int, struct rusage *); #ifndef RUSAGE_SELF -#define RUSAGE_SELF 0 +#define RUSAGE_SELF 0 #endif #endif @@ -61,62 +61,62 @@ int call_warnings; * The array below is the available subcommands to the debug() efun. * */ - /* Name Number Params */ -static char *debc[] = { "index", /* 0 */ - "malloc", /* 1 */ - "status", /* 2 */ - "status tables", /* 3 */ - "mudstatus", /* 4 on/off eval time */ - "functionlist", /* 5 object */ - "rusage", /* 6 */ - "top_ten_cpu", /* 7 */ - "object_cpu", /* 8 object */ - "swap", /* 9 object */ - "version", /* 10 */ - "wizlist", /* 11 wizname */ - "trace", /* 12 bitmask */ - "traceprefix", /* 13 pathstart */ - "call_out_info", /* 14 object */ - "inherit_list", /* 15 object */ - "load_average", /* 16 */ - "shutdown", /* 17 */ - "object_info", /* 18 num object */ - "opcdump", /* 19 */ - "send_udp", /* 20 host, port, msg */ - "mud_port", /* 21 */ - "udp_port", /* 22 */ - "set_wizard", /* 23 player */ - "ob_flags", /* 24 ob */ - "get_variables", /* 25 ob null/varname */ - "get_eval_cost", /* 26 */ + /* Name Number Params */ +static char *debc[] = { "index", /* 0 */ + "malloc", /* 1 */ + "status", /* 2 */ + "status tables", /* 3 */ + "mudstatus", /* 4 on/off eval time */ + "functionlist", /* 5 object */ + "rusage", /* 6 */ + "top_ten_cpu", /* 7 */ + "object_cpu", /* 8 object */ + "swap", /* 9 object */ + "version", /* 10 */ + "wizlist", /* 11 wizname */ + "trace", /* 12 bitmask */ + "traceprefix", /* 13 pathstart */ + "call_out_info", /* 14 object */ + "inherit_list", /* 15 object */ + "load_average", /* 16 */ + "shutdown", /* 17 */ + "object_info", /* 18 num object */ + "opcdump", /* 19 */ + "send_udp", /* 20 host, port, msg */ + "mud_port", /* 21 */ + "udp_port", /* 22 */ + "set_wizard", /* 23 player */ + "ob_flags", /* 24 ob */ + "get_variables", /* 25 ob null/varname */ + "get_eval_cost", /* 26 */ "debug malloc", /* 27 */ - "getprofile", /* 28 object */ - "get_avg_response", /* 29 */ - "destruct", /* 30 object */ - "destroy", /* 31 object */ - "update snoops", /* 32 */ - "call_warnings", /* 33 on/off */ - "dump_objects", /* 34 */ - "query_debug_ob", /* 35 object */ - "set_debug_ob", /* 36 object flags */ - "set_swap", /* 37 - ({min_mem, max_mem, min_time, max_time}) */ - "query_swap", /* 38 */ - "set_debug_prog", /* 39 object */ - "query_debug_prog", /* 40 object flags */ - "functions", /* 41 */ - "inhibitcallouts", /* 42 on/off */ - "warnobsolete", /* 43 on/off */ - "shared_strings", /* 44 */ + "getprofile", /* 28 object */ + "get_avg_response", /* 29 */ + "destruct", /* 30 object */ + "destroy", /* 31 object */ + "update snoops", /* 32 */ + "call_warnings", /* 33 on/off */ + "dump_objects", /* 34 */ + "query_debug_ob", /* 35 object */ + "set_debug_ob", /* 36 object flags */ + "set_swap", /* 37 + ({min_mem, max_mem, min_time, max_time}) */ + "query_swap", /* 38 */ + "set_debug_prog", /* 39 object */ + "query_debug_prog", /* 40 object flags */ + "functions", /* 41 */ + "inhibitcallouts", /* 42 on/off */ + "warnobsolete", /* 43 on/off */ + "shared_strings", /* 44 */ "dump_alarms", /* 45 */ "top_ten_cpu_avg", /* 46 */ "object_cpu_avg", /* 47 */ "getprofile_avg", /* 48 */ "profile_timebase", /* 49 */ - "trace_calls", /* 50 */ - "top_functions", /* 51 */ - 0 - }; + "trace_calls", /* 50 */ + "top_functions", /* 51 */ + 0 + }; extern struct vector *inherit_list (struct object *); #ifdef FUNCDEBUG @@ -141,99 +141,99 @@ debug_command(char *debcmd, int argc, struct svalue *argv) for (dbi = -1, dbnum = 0; debc[dbnum]; dbnum++) { - if (strcmp(debcmd, debc[dbnum]) == 0) - dbi = dbnum; + if (strcmp(debcmd, debc[dbnum]) == 0) + dbi = dbnum; } if (dbi < 0) { - retval.type = T_NUMBER; - retval.u.number = 0; - return &retval; + retval.type = T_NUMBER; + retval.u.number = 0; + return &retval; } switch (dbi) { case 0: /* index */ - retval.type = T_POINTER; - retval.u.vec = allocate_array(dbnum); - for (il = 0; il < dbnum; il++) - { - retval.u.vec->item[il].type = T_STRING; - retval.u.vec->item[il].string_type = STRING_CSTRING; - retval.u.vec->item[il].u.string = debc[il]; - } - return &retval; + retval.type = T_POINTER; + retval.u.vec = allocate_array(dbnum); + for (il = 0; il < dbnum; il++) + { + retval.u.vec->item[il].type = T_STRING; + retval.u.vec->item[il].string_type = STRING_CSTRING; + retval.u.vec->item[il].u.string = debc[il]; + } + return &retval; case 1: /* malloc */ - retval.type = T_STRING; - retval.string_type = STRING_SSTRING; + retval.type = T_STRING; + retval.string_type = STRING_SSTRING; char *data = dump_malloc_data(); - retval.u.string = make_sstring(data); + retval.u.string = make_sstring(data); free(data); - return &retval; + return &retval; case 2: /* status */ case 3: /* status tables */ - retval.type = T_STRING; - retval.string_type = STRING_MSTRING; - retval.u.string = (char *)get_gamedriver_info(debc[dbi]); - return &retval; + retval.type = T_STRING; + retval.string_type = STRING_MSTRING; + retval.u.string = (char *)get_gamedriver_info(debc[dbi]); + return &retval; case 4: /* mudstatus on/off eval_lim time_lim */ - if (argc < 3 || - argv[0].type != T_STRING || - argv[1].type != T_NUMBER || - argv[2].type != T_NUMBER) - break; - if (strcmp(argv[0].u.string, "on") == 0) - mudstatus_set(1, argv[1].u.number, argv[2].u.number); - else if (strcmp(argv[0].u.string, "off") == 0) - mudstatus_set(0, argv[1].u.number, argv[2].u.number); - else - break; - retval.type = T_NUMBER; - retval.u.number = 1; - return &retval; + if (argc < 3 || + argv[0].type != T_STRING || + argv[1].type != T_NUMBER || + argv[2].type != T_NUMBER) + break; + if (strcmp(argv[0].u.string, "on") == 0) + mudstatus_set(1, argv[1].u.number, argv[2].u.number); + else if (strcmp(argv[0].u.string, "off") == 0) + mudstatus_set(0, argv[1].u.number, argv[2].u.number); + else + break; + retval.type = T_NUMBER; + retval.u.number = 1; + return &retval; case 5: /* functionlist object */ - if (argc < 1 || argv[0].type != T_OBJECT) - break; - retval.type = T_POINTER; - retval.u.vec = allocate_array(argv[0].u.ob->prog->num_functions); - for (il = 0; il < (int)argv[0].u.ob->prog->num_functions; il++) - { - retval.u.vec->item[il].type = T_STRING; - retval.u.vec->item[il].string_type = STRING_SSTRING; - retval.u.vec->item[il].u.string = - reference_sstring(argv[0].u.ob->prog->functions[il].name); - } - return &retval; + if (argc < 1 || argv[0].type != T_OBJECT) + break; + retval.type = T_POINTER; + retval.u.vec = allocate_array(argv[0].u.ob->prog->num_functions); + for (il = 0; il < (int)argv[0].u.ob->prog->num_functions; il++) + { + retval.u.vec->item[il].type = T_STRING; + retval.u.vec->item[il].string_type = STRING_SSTRING; + retval.u.vec->item[il].u.string = + reference_sstring(argv[0].u.ob->prog->functions[il].name); + } + return &retval; case 6: /* rusage */ { #ifdef RUSAGE /* Only defined if we compile GD with RUSAGE */ - char buff[500]; - struct rusage rus; - long utime, stime; - long maxrss; - - if (getrusage(RUSAGE_SELF, &rus) < 0) - buff[0] = 0; - else { - utime = rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; - stime = rus.ru_stime.tv_sec * 1000 + rus.ru_stime.tv_usec / 1000; - maxrss = rus.ru_maxrss; - (void)sprintf(buff, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", - utime, stime, maxrss, rus.ru_ixrss, rus.ru_idrss, - rus.ru_isrss, rus.ru_minflt, rus.ru_majflt, rus.ru_nswap, - rus.ru_inblock, rus.ru_oublock, rus.ru_msgsnd, - rus.ru_msgrcv, rus.ru_nsignals, rus.ru_nvcsw, - rus.ru_nivcsw); - } - retval.type = T_STRING; - retval.string_type = STRING_MSTRING; - retval.u.string = make_mstring(buff); - return &retval; + char buff[500]; + struct rusage rus; + long utime, stime; + long maxrss; + + if (getrusage(RUSAGE_SELF, &rus) < 0) + buff[0] = 0; + else { + utime = rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000; + stime = rus.ru_stime.tv_sec * 1000 + rus.ru_stime.tv_usec / 1000; + maxrss = rus.ru_maxrss; + (void)sprintf(buff, "%ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", + utime, stime, maxrss, rus.ru_ixrss, rus.ru_idrss, + rus.ru_isrss, rus.ru_minflt, rus.ru_majflt, rus.ru_nswap, + rus.ru_inblock, rus.ru_oublock, rus.ru_msgsnd, + rus.ru_msgrcv, rus.ru_nsignals, rus.ru_nvcsw, + rus.ru_nivcsw); + } + retval.type = T_STRING; + retval.string_type = STRING_MSTRING; + retval.u.string = make_mstring(buff); + return &retval; #else - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Only valid if GD compiled with RUSAGE flag.\n"; - return &retval; + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "Only valid if GD compiled with RUSAGE flag.\n"; + return &retval; #endif } @@ -241,415 +241,415 @@ debug_command(char *debcmd, int argc, struct svalue *argv) case 7: /* top_ten_cpu */ { #define NUMBER_OF_TOP_TEN 100 - struct program *p[NUMBER_OF_TOP_TEN]; - struct vector *v; - struct program *prog; - int i, j; - for(i = 0; i < NUMBER_OF_TOP_TEN; i++) - p[i] = (struct program *)0L; - prog = prog_list; - do - { - for(i = NUMBER_OF_TOP_TEN-1; i >= 0; i--) - { - if ( p[i] && (prog->cpu <= p[i]->cpu)) - break; - } - - if (i < (NUMBER_OF_TOP_TEN - 1)) - for (j = 0; j <= i; j++) - if (strcmp(p[j]->name,prog->name) == 0) - { - i = NUMBER_OF_TOP_TEN-1; - break; - } - - if (i < (NUMBER_OF_TOP_TEN - 1)) - { - j = NUMBER_OF_TOP_TEN - 2; - while(j > i) - { - p[j + 1] = p[j]; - j--; - } - p[i + 1] = prog; - } - } while (prog_list != (prog = prog->next_all)); - v = make_cpu_array(NUMBER_OF_TOP_TEN, p); - if (v) - { - retval.type = T_POINTER; - retval.u.vec = v; - return &retval; - } - break; + struct program *p[NUMBER_OF_TOP_TEN]; + struct vector *v; + struct program *prog; + int i, j; + for(i = 0; i < NUMBER_OF_TOP_TEN; i++) + p[i] = (struct program *)0L; + prog = prog_list; + do + { + for(i = NUMBER_OF_TOP_TEN-1; i >= 0; i--) + { + if ( p[i] && (prog->cpu <= p[i]->cpu)) + break; + } + + if (i < (NUMBER_OF_TOP_TEN - 1)) + for (j = 0; j <= i; j++) + if (strcmp(p[j]->name,prog->name) == 0) + { + i = NUMBER_OF_TOP_TEN-1; + break; + } + + if (i < (NUMBER_OF_TOP_TEN - 1)) + { + j = NUMBER_OF_TOP_TEN - 2; + while(j > i) + { + p[j + 1] = p[j]; + j--; + } + p[i + 1] = prog; + } + } while (prog_list != (prog = prog->next_all)); + v = make_cpu_array(NUMBER_OF_TOP_TEN, p); + if (v) + { + retval.type = T_POINTER; + retval.u.vec = v; + return &retval; + } + break; #undef NUMBER_OF_TOP_TEN } #else case 7: - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Only valid if GD compiled with PROFILE_LPC flag.\n"; - return &retval; + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "Only valid if GD compiled with PROFILE_LPC flag.\n"; + return &retval; #endif case 8: /* object_cpu object */ { - long long c_num; + long long c_num; - if (argc && (argv[0].type == T_OBJECT)) - { + if (argc && (argv[0].type == T_OBJECT)) + { #if defined(PROFILE_LPC) - c_num = argv[0].u.ob->prog->cpu * 1e6; + c_num = argv[0].u.ob->prog->cpu * 1e6; #else - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Only valid if GD compiled with PROFILE_LPC flag.\n"; - return &retval; + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "Only valid if GD compiled with PROFILE_LPC flag.\n"; + return &retval; #endif - } - else - { + } + else + { #ifdef RUSAGE - struct rusage rus; - - if (getrusage(RUSAGE_SELF, &rus) < 0) - { - c_num = -1; - } - else - { - c_num = (long long)rus.ru_utime.tv_sec * 1000000 + - rus.ru_utime.tv_usec + - (long long)rus.ru_stime.tv_sec * 1000000 + - rus.ru_stime.tv_usec; - } + struct rusage rus; + + if (getrusage(RUSAGE_SELF, &rus) < 0) + { + c_num = -1; + } + else + { + c_num = (long long)rus.ru_utime.tv_sec * 1000000 + + rus.ru_utime.tv_usec + + (long long)rus.ru_stime.tv_sec * 1000000 + + rus.ru_stime.tv_usec; + } #else - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Only valid if GD compiled with RUSAGE flag.\n"; - return &retval; + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "Only valid if GD compiled with RUSAGE flag.\n"; + return &retval; #endif } - retval.type = T_NUMBER; - retval.u.number = c_num; - return &retval; + retval.type = T_NUMBER; + retval.u.number = c_num; + return &retval; } - case 9: /* swap, object */ + case 9: /* swap, object */ #if 0 /* can not swap while executing */ - if (argc && (argv[0].type == T_OBJECT)) - (void)swap(argv[0].u.ob); + if (argc && (argv[0].type == T_OBJECT)) + (void)swap(argv[0].u.ob); #endif - retval = const1; - return &retval; - case 10: /* version, */ + retval = const1; + return &retval; + case 10: /* version, */ { - char buff[64]; - (void)snprintf(buff, sizeof(buff), "%6.6s%02d %s %s", GAME_VERSION, PATCH_LEVEL, __DATE__, __TIME__); - retval.type = T_STRING; - retval.string_type = STRING_MSTRING; - retval.u.string = make_mstring(buff); - return &retval; + char buff[64]; + (void)snprintf(buff, sizeof(buff), "%6.6s%02d %s %s", GAME_VERSION, PATCH_LEVEL, __DATE__, __TIME__); + retval.type = T_STRING; + retval.string_type = STRING_MSTRING; + retval.u.string = make_mstring(buff); + return &retval; } - case 11: /* wizlist, wizname */ - /* - * Prints information, will be changed + case 11: /* wizlist, wizname */ + /* + * Prints information, will be changed */ - retval = const1; - return &retval; - case 12: /* trace, bitmask */ + retval = const1; + return &retval; + case 12: /* trace, bitmask */ { - int ot = -1; - extern struct object *current_interactive; - if (current_interactive && current_interactive->interactive) - { - if (argc && (argv[0].type == T_NUMBER)) - { - ot = current_interactive->interactive->trace_level; - current_interactive->interactive->trace_level = argv[0].u.number; - } - } - - retval.type = T_NUMBER; - retval.u.number = ot; - return &retval; + int ot = -1; + extern struct object *current_interactive; + if (current_interactive && current_interactive->interactive) + { + if (argc && (argv[0].type == T_NUMBER)) + { + ot = current_interactive->interactive->trace_level; + current_interactive->interactive->trace_level = argv[0].u.number; + } + } + + retval.type = T_NUMBER; + retval.u.number = ot; + return &retval; } - case 13: /* traceprefix, pathstart */ + case 13: /* traceprefix, pathstart */ { - char *old = 0; - - extern struct object *current_interactive; - if (current_interactive && current_interactive->interactive) - { - if (argc) - { - old = current_interactive->interactive->trace_prefix; - if (argv[0].type == T_STRING) - { - current_interactive->interactive->trace_prefix = - make_sstring(argv[0].u.string); - } - else - current_interactive->interactive->trace_prefix = 0; - } - } - - if (old) - { - retval.type = T_STRING; - retval.string_type = STRING_SSTRING; - retval.u.string = old; - } - else - retval = const0; - - return &retval; + char *old = 0; + + extern struct object *current_interactive; + if (current_interactive && current_interactive->interactive) + { + if (argc) + { + old = current_interactive->interactive->trace_prefix; + if (argv[0].type == T_STRING) + { + current_interactive->interactive->trace_prefix = + make_sstring(argv[0].u.string); + } + else + current_interactive->interactive->trace_prefix = 0; + } + } + + if (old) + { + retval.type = T_STRING; + retval.string_type = STRING_SSTRING; + retval.u.string = old; + } + else + retval = const0; + + return &retval; } - case 14: /* call_out_info, */ - { - extern struct vector *get_calls(struct object *); - if (argv[0].type != T_OBJECT) - break; - retval.type = T_POINTER; - retval.u.vec = get_calls(argv[0].u.ob); - return &retval; - } - case 15: /* inherit_list, object */ - if (argc && (argv[0].type == T_OBJECT)) - { - retval.type = T_POINTER; - retval.u.vec = inherit_list(argv[0].u.ob); - return &retval; - } - else - { - retval = const0; - return &retval; - } - case 16: /* load_average, */ - retval.type = T_STRING; - retval.string_type = STRING_MSTRING; - retval.u.string = make_mstring(query_load_av()); - return &retval; - - case 17: /* shutdown, */ - startshutdowngame(0); - retval = const1; - return &retval; - - case 18: /* "object_info", num object */ + case 14: /* call_out_info, */ + { + extern struct vector *get_calls(struct object *); + if (argv[0].type != T_OBJECT) + break; + retval.type = T_POINTER; + retval.u.vec = get_calls(argv[0].u.ob); + return &retval; + } + case 15: /* inherit_list, object */ + if (argc && (argv[0].type == T_OBJECT)) + { + retval.type = T_POINTER; + retval.u.vec = inherit_list(argv[0].u.ob); + return &retval; + } + else + { + retval = const0; + return &retval; + } + case 16: /* load_average, */ + retval.type = T_STRING; + retval.string_type = STRING_MSTRING; + retval.u.string = make_mstring(query_load_av()); + return &retval; + + case 17: /* shutdown, */ + startshutdowngame(0); + retval = const1; + return &retval; + + case 18: /* "object_info", num object */ { - struct object *ob; - char db_buff[1024], tdb[200]; - int i; - - if (argc < 2 || argv[0].type != T_NUMBER || argv[1].type != T_OBJECT) - break; - - if (argv[0].u.number == 0) - { - int flags; - struct object *obj2; - - if ( argv[1].type != T_OBJECT) - break; - ob = argv[1].u.ob; - flags = ob->flags; - (void)sprintf(db_buff,"O_ENABLE_COMMANDS : %s\nO_CLONE : %s\nO_DESTRUCTED : %s\nO_SWAPPED : %s\nO_ONCE_INTERACTIVE: %s\nO_CREATED : %s\n", - flags&O_ENABLE_COMMANDS ?"TRUE":"FALSE", - flags&O_CLONE ?"TRUE":"FALSE", - flags&O_DESTRUCTED ?"TRUE":"FALSE", - flags&O_SWAPPED ?"TRUE":"FALSE", - flags&O_ONCE_INTERACTIVE?"TRUE":"FALSE", - flags&O_CREATED ?"TRUE":"FALSE"); - - (void)sprintf(tdb,"time_of_ref : %d\n", ob->time_of_ref); - (void)strcat(db_buff, tdb); - (void)sprintf(tdb,"ref : %d\n", ob->ref); - (void)strcat(db_buff, tdb); + struct object *ob; + char db_buff[1024], tdb[200]; + int i; + + if (argc < 2 || argv[0].type != T_NUMBER || argv[1].type != T_OBJECT) + break; + + if (argv[0].u.number == 0) + { + int flags; + struct object *obj2; + + if ( argv[1].type != T_OBJECT) + break; + ob = argv[1].u.ob; + flags = ob->flags; + (void)sprintf(db_buff,"O_ENABLE_COMMANDS : %s\nO_CLONE : %s\nO_DESTRUCTED : %s\nO_SWAPPED : %s\nO_ONCE_INTERACTIVE: %s\nO_CREATED : %s\n", + flags&O_ENABLE_COMMANDS ?"TRUE":"FALSE", + flags&O_CLONE ?"TRUE":"FALSE", + flags&O_DESTRUCTED ?"TRUE":"FALSE", + flags&O_SWAPPED ?"TRUE":"FALSE", + flags&O_ONCE_INTERACTIVE?"TRUE":"FALSE", + flags&O_CREATED ?"TRUE":"FALSE"); + + (void)sprintf(tdb,"time_of_ref : %d\n", ob->time_of_ref); + (void)strcat(db_buff, tdb); + (void)sprintf(tdb,"ref : %d\n", ob->ref); + (void)strcat(db_buff, tdb); #ifdef DEBUG - (void)sprintf(tdb,"extra_ref : %d\n", ob->extra_ref); - (void)strcat(db_buff, tdb); + (void)sprintf(tdb,"extra_ref : %d\n", ob->extra_ref); + (void)strcat(db_buff, tdb); #endif - (void)snprintf(tdb, sizeof(tdb), "name : '%s'\n", ob->name); - (void)strcat(db_buff, tdb); - (void)snprintf(tdb, sizeof(tdb), "next_all : OBJ(%s)\n", - ob->next_all?ob->next_all->name: "NULL"); - (void)strcat(db_buff, tdb); - if (obj_list == ob) - { - (void)strcat(db_buff, "This object is the head of the object list.\n"); - } - - obj2 = obj_list; - i = 1; - do - if (obj2->next_all == ob) - { - (void)snprintf(tdb, sizeof(tdb), "Previous object in object list: OBJ(%s)\n", - obj2->name); - (void)strcat(db_buff, tdb); - (void)sprintf(tdb, "position in object list:%d\n",i); - (void)strcat(db_buff, tdb); - - } - while (obj_list != (obj2 = obj2->next_all)); - } + (void)snprintf(tdb, sizeof(tdb), "name : '%s'\n", ob->name); + (void)strcat(db_buff, tdb); + (void)snprintf(tdb, sizeof(tdb), "next_all : OBJ(%s)\n", + ob->next_all?ob->next_all->name: "NULL"); + (void)strcat(db_buff, tdb); + if (obj_list == ob) + { + (void)strcat(db_buff, "This object is the head of the object list.\n"); + } + + obj2 = obj_list; + i = 1; + do + if (obj2->next_all == ob) + { + (void)snprintf(tdb, sizeof(tdb), "Previous object in object list: OBJ(%s)\n", + obj2->name); + (void)strcat(db_buff, tdb); + (void)sprintf(tdb, "position in object list:%d\n",i); + (void)strcat(db_buff, tdb); + + } + while (obj_list != (obj2 = obj2->next_all)); + } else if (argv[0].u.number == 1) { - if (argv[1].type != T_OBJECT) - break; - ob = argv[1].u.ob; - - (void)sprintf(db_buff,"program ref's %d\n", ob->prog->ref); - (void)snprintf(tdb, sizeof(tdb), "Name %s\n", ob->prog->name); - (void)strcat(db_buff, tdb); - (void)sprintf(tdb,"program size %d\n", ob->prog->program_size); - (void)strcat(db_buff, tdb); - (void)sprintf(tdb, "num func's %u (%u) \n", ob->prog->num_functions - ,ob->prog->num_functions * (unsigned) sizeof(struct function)); - (void)strcat(db_buff, tdb); - (void)sprintf(tdb,"sizeof rodata %d\n", ob->prog->rodata_size); - (void)strcat(db_buff, tdb); - (void)sprintf(tdb,"num vars %u (%u)\n", ob->prog->num_variables - ,ob->prog->num_variables * (unsigned) sizeof(struct variable)); - (void)strcat(db_buff, tdb); - (void)sprintf(tdb,"num inherits %u (%u)\n", ob->prog->num_inherited - ,ob->prog->num_inherited * (unsigned) sizeof(struct inherit)); - (void)strcat(db_buff, tdb); - (void)sprintf(tdb,"total size %d\n", ob->prog->total_size); - (void)strcat(db_buff, tdb); - } + if (argv[1].type != T_OBJECT) + break; + ob = argv[1].u.ob; + + (void)sprintf(db_buff,"program ref's %d\n", ob->prog->ref); + (void)snprintf(tdb, sizeof(tdb), "Name %s\n", ob->prog->name); + (void)strcat(db_buff, tdb); + (void)sprintf(tdb,"program size %d\n", ob->prog->program_size); + (void)strcat(db_buff, tdb); + (void)sprintf(tdb, "num func's %u (%u) \n", ob->prog->num_functions + ,ob->prog->num_functions * (unsigned) sizeof(struct function)); + (void)strcat(db_buff, tdb); + (void)sprintf(tdb,"sizeof rodata %d\n", ob->prog->rodata_size); + (void)strcat(db_buff, tdb); + (void)sprintf(tdb,"num vars %u (%u)\n", ob->prog->num_variables + ,ob->prog->num_variables * (unsigned) sizeof(struct variable)); + (void)strcat(db_buff, tdb); + (void)sprintf(tdb,"num inherits %u (%u)\n", ob->prog->num_inherited + ,ob->prog->num_inherited * (unsigned) sizeof(struct inherit)); + (void)strcat(db_buff, tdb); + (void)sprintf(tdb,"total size %d\n", ob->prog->total_size); + (void)strcat(db_buff, tdb); + } else - { - (void)sprintf(db_buff, "Bad number argument to object_info: %lld\n", - argv[0].u.number); + { + (void)sprintf(db_buff, "Bad number argument to object_info: %lld\n", + argv[0].u.number); } - retval.type = T_STRING; - retval.string_type = STRING_MSTRING; - retval.u.string = make_mstring(db_buff); - return &retval; + retval.type = T_STRING; + retval.string_type = STRING_MSTRING; + retval.u.string = make_mstring(db_buff); + return &retval; } - case 19: /* opcdump, 19 */ + case 19: /* opcdump, 19 */ { #ifdef OPCPROF - opcdump(); - retval = const1; - return &retval; + opcdump(); + retval = const1; + return &retval; #else - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Only valid if GD compiled with OPCPROF flag.\n"; - return &retval; + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "Only valid if GD compiled with OPCPROF flag.\n"; + return &retval; #endif } - case 20: /* send_udp, 20 host, port, msg */ + case 20: /* send_udp, 20 host, port, msg */ { #ifdef CATCH_UDP_PORT - extern udpsvc_t *udpsvc; + extern udpsvc_t *udpsvc; #endif - if (argc < 3 || - argv[0].type != T_STRING || - argv[1].type != T_NUMBER || - argv[2].type != T_STRING) - break; + if (argc < 3 || + argv[0].type != T_STRING || + argv[1].type != T_NUMBER || + argv[2].type != T_STRING) + break; #ifdef CATCH_UDP_PORT - tmp = udpsvc_send(udpsvc, argv[0].u.string, argv[1].u.number, argv[2].u.string); - if (tmp) - retval = const1; - else + tmp = udpsvc_send(udpsvc, argv[0].u.string, argv[1].u.number, argv[2].u.string); + if (tmp) + retval = const1; + else #endif - retval = const0; - return &retval; + retval = const0; + return &retval; } - case 21: /* mud_port, 21 */ + case 21: /* mud_port, 21 */ { - extern int port_number; - retval.type = T_NUMBER; - retval.u.number = port_number; - return &retval; + extern int port_number; + retval.type = T_NUMBER; + retval.u.number = port_number; + return &retval; } - case 22: /* udp_port, 22 */ + case 22: /* udp_port, 22 */ { #ifdef CATCH_UDP_PORT - extern int udp_port; - retval.u.number = udp_port; + extern int udp_port; + retval.u.number = udp_port; #else - retval.u.number = -1; + retval.u.number = -1; #endif - retval.type = T_NUMBER; - return &retval; + retval.type = T_NUMBER; + return &retval; } - case 23: /* set_wizard, object */ - if (argc && (argv[0].type == T_OBJECT)) - { - retval = const1; - return &retval; - } - else - { - retval = const0; - return &retval; - } - case 24: /* ob_flags, 24 ob */ + case 23: /* set_wizard, object */ + if (argc && (argv[0].type == T_OBJECT)) + { + retval = const1; + return &retval; + } + else + { + retval = const0; + return &retval; + } + case 24: /* ob_flags, 24 ob */ { - if (argc && (argv[0].type == T_OBJECT)) - { - retval.type = T_NUMBER; - retval.u.number = argv[0].u.ob->flags; - return &retval; - } - retval = const0; - return &retval; + if (argc && (argv[0].type == T_OBJECT)) + { + retval.type = T_NUMBER; + retval.u.number = argv[0].u.ob->flags; + return &retval; + } + retval = const0; + return &retval; } case 25: /* get_variables, 25 object NULL/string */ { - struct svalue get_variables(struct object *); - struct svalue get_variable(struct object *, char *); - - switch (argc) - { - case 1: - if ( argv[0].type != T_OBJECT) - { - retval = const0; - return &retval; - } - retval = get_variables(argv[0].u.ob); - return &retval; - case 2: - if ( argv[0].type != T_OBJECT || argv[1].type != T_STRING) - { - retval = const0; - return &retval; - } - retval = get_variable(argv[0].u.ob, argv[1].u.string); - return &retval; - case 3: - if ( argv[0].type == T_OBJECT && argv[1].type == T_STRING) - { - retval = get_variable(argv[0].u.ob, argv[1].u.string); - return &retval; - } - if ( argv[0].type == T_OBJECT) - { - retval = get_variables(argv[0].u.ob); - return &retval; - } - retval = const0; - return &retval; - default: - retval = const0; - return &retval; - - } + struct svalue get_variables(struct object *); + struct svalue get_variable(struct object *, char *); + + switch (argc) + { + case 1: + if ( argv[0].type != T_OBJECT) + { + retval = const0; + return &retval; + } + retval = get_variables(argv[0].u.ob); + return &retval; + case 2: + if ( argv[0].type != T_OBJECT || argv[1].type != T_STRING) + { + retval = const0; + return &retval; + } + retval = get_variable(argv[0].u.ob, argv[1].u.string); + return &retval; + case 3: + if ( argv[0].type == T_OBJECT && argv[1].type == T_STRING) + { + retval = get_variable(argv[0].u.ob, argv[1].u.string); + return &retval; + } + if ( argv[0].type == T_OBJECT) + { + retval = get_variables(argv[0].u.ob); + return &retval; + } + retval = const0; + return &retval; + default: + retval = const0; + return &retval; + + } } - case 26: /* get_eval_cost, 26 */ + case 26: /* get_eval_cost, 26 */ { - extern int eval_cost; - retval.type = T_NUMBER; - retval.u.number = eval_cost; - return &retval; + extern int eval_cost; + retval.type = T_NUMBER; + retval.u.number = eval_cost; + return &retval; } case 27: /* debug malloc, 27 */ @@ -657,42 +657,42 @@ debug_command(char *debcmd, int argc, struct svalue *argv) retval = const1; return &retval; } - case 28: /* getprofile, 28 object */ + case 28: /* getprofile, 28 object */ { int format = 0; #ifndef PROFILE_LPC - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Only valid if GD compiled with PROFILE_LPC flag.\n"; - return &retval; + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "Only valid if GD compiled with PROFILE_LPC flag.\n"; + return &retval; #else - if (argc < 1 || argv[0].type != T_OBJECT) - break; + if (argc < 1 || argv[0].type != T_OBJECT) + break; if (argc >= 2 && argv[1].type == T_NUMBER) format = argv[1].u.number; if (format == 0) { - retval.type = T_POINTER; - retval.u.vec = allocate_array(argv[0].u.ob->prog->num_functions); - for (il = 0; il < (int)argv[0].u.ob->prog->num_functions; il++) - { - - (void)snprintf(buff, sizeof(buff), "%016lld:%020lld: %s", - (long long)argv[0].u.ob->prog->functions[il].num_calls, - (long long)(argv[0].u.ob->prog->functions[il].time_spent * 1e6), - argv[0].u.ob->prog->functions[il].name); - retval.u.vec->item[il].type = T_STRING; - retval.u.vec->item[il].string_type = STRING_MSTRING; - retval.u.vec->item[il].u.string = make_mstring(buff); - } + retval.type = T_POINTER; + retval.u.vec = allocate_array(argv[0].u.ob->prog->num_functions); + for (il = 0; il < (int)argv[0].u.ob->prog->num_functions; il++) + { + + (void)snprintf(buff, sizeof(buff), "%016lld:%020lld: %s", + (long long)argv[0].u.ob->prog->functions[il].num_calls, + (long long)(argv[0].u.ob->prog->functions[il].time_spent * 1e6), + argv[0].u.ob->prog->functions[il].name); + retval.u.vec->item[il].type = T_STRING; + retval.u.vec->item[il].string_type = STRING_MSTRING; + retval.u.vec->item[il].u.string = make_mstring(buff); + } } else if (format == 1) { retval.type = T_POINTER; retval.u.vec = allocate_array(argv[0].u.ob->prog->num_functions); double now = current_cpu(); struct program *prog = argv[0].u.ob->prog; - for (il = 0; il < (int)prog->num_functions; il++) - { + for (il = 0; il < (int)prog->num_functions; il++) + { struct function *func = prog->functions + il; - struct vector *res = allocate_array(7); + struct vector *res = allocate_array(7); update_func_profile(func, now, 0.0, 0.0, 0); res->item[0].type = T_STRING; res->item[0].string_type = STRING_MSTRING; @@ -715,194 +715,194 @@ debug_command(char *debcmd, int argc, struct svalue *argv) res->item[6].type = T_FLOAT; res->item[6].u.real = func->avg_calls; - retval.u.vec->item[il].type = T_POINTER; - retval.u.vec->item[il].u.vec = res; + retval.u.vec->item[il].type = T_POINTER; + retval.u.vec->item[il].u.vec = res; } } else { - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Unknown format.\n"; + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "Unknown format.\n"; } - return &retval; + return &retval; #endif } case 29: /* get_avg_response, 29 */ { - extern int get_msecs_response(int); - extern int msr_point; - int sum, num, tmp; - - if (msr_point >=0) - { - sum = 0; - num = 0; - for (il = 0; il < 100; il++) - { - if ((tmp = get_msecs_response(il)) >=0) - { - sum += tmp; - num++; - } - } - retval.type = T_NUMBER; - retval.u.number = (num > 0) ? sum / num : 0; - return &retval; - } - break; + extern int get_msecs_response(int); + extern int msr_point; + int sum, num, tmp; + + if (msr_point >=0) + { + sum = 0; + num = 0; + for (il = 0; il < 100; il++) + { + if ((tmp = get_msecs_response(il)) >=0) + { + sum += tmp; + num++; + } + } + retval.type = T_NUMBER; + retval.u.number = (num > 0) ? sum / num : 0; + return &retval; + } + break; } case 30: /* destruct, 30 */ case 31: /* destroy, 31 */ { - extern void destruct_object(struct object *); + extern void destruct_object(struct object *); - if (argc && argv[0].type == T_OBJECT && + if (argc && argv[0].type == T_OBJECT && !(argv[0].u.ob->flags & O_DESTRUCTED)) destruct_object(argv[0].u.ob); - break; + break; } case 32: /* update snoops, 31 */ #ifdef SUPER_SNOOP - update_snoop_file(); + update_snoop_file(); #else - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Only valid if GD compiled with SUPER_SNOOP flag.\n"; + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "Only valid if GD compiled with SUPER_SNOOP flag.\n"; #endif - break; + break; case 33: /* call_warnings, int 0 = off, 1 = on */ - if (argc && (argv[0].type == T_STRING)) - { - if (strcmp(argv[0].u.string, "on") == 0) - call_warnings++; - else - call_warnings = call_warnings > 0 ? call_warnings - 1 : 0; - retval.type = T_NUMBER; - retval.u.number = call_warnings; - return &retval; - } - else - { - retval.type = T_NUMBER; - retval.u.number = -1; - return &retval; - } + if (argc && (argv[0].type == T_STRING)) + { + if (strcmp(argv[0].u.string, "on") == 0) + call_warnings++; + else + call_warnings = call_warnings > 0 ? call_warnings - 1 : 0; + retval.type = T_NUMBER; + retval.u.number = call_warnings; + return &retval; + } + else + { + retval.type = T_NUMBER; + retval.u.number = -1; + return &retval; + } case 34: /* dump objects */ { - FILE *ufile; - struct object *ob; - - if ((ufile = fopen(OBJECT_DUMP_FILE, "w")) == NULL) - { - retval.type = T_NUMBER; - retval.u.number = -1; - return &retval; - } - - fputs("Array (size), Mapping (size), String (size), Objs, Ints, Floats, Inventory, Callouts, Environment, Name\n", ufile); - ob = obj_list; - do - { - mem_variables(ufile, ob); - } - while (obj_list != (ob = ob->next_all)); - (void)fclose(ufile); - break; + FILE *ufile; + struct object *ob; + + if ((ufile = fopen(OBJECT_DUMP_FILE, "w")) == NULL) + { + retval.type = T_NUMBER; + retval.u.number = -1; + return &retval; + } + + fputs("Array (size), Mapping (size), String (size), Objs, Ints, Floats, Inventory, Callouts, Environment, Name\n", ufile); + ob = obj_list; + do + { + mem_variables(ufile, ob); + } + while (obj_list != (ob = ob->next_all)); + (void)fclose(ufile); + break; } case 35: /* query_debug_ob */ - if (!argc || argv[0].type != T_OBJECT) - break; - retval.type = T_NUMBER; - retval.u.number = argv[0].u.ob->debug_flags; - return &retval; + if (!argc || argv[0].type != T_OBJECT) + break; + retval.type = T_NUMBER; + retval.u.number = argv[0].u.ob->debug_flags; + return &retval; case 36: /* set_debug_ob */ - if (!argc || argv[0].type != T_OBJECT || argv[1].type != T_NUMBER) - break; - retval.type = T_NUMBER; - retval.u.number = argv[0].u.ob->debug_flags; - argv[0].u.ob->debug_flags = argv[1].u.number; - return &retval; + if (!argc || argv[0].type != T_OBJECT || argv[1].type != T_NUMBER) + break; + retval.type = T_NUMBER; + retval.u.number = argv[0].u.ob->debug_flags; + argv[0].u.ob->debug_flags = argv[1].u.number; + return &retval; case 37: /* set_swap */ retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Obsolete function.\n"; - return &retval; + retval.string_type = STRING_CSTRING; + retval.u.string = "Obsolete function.\n"; + return &retval; case 38: /* query_swap */ - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Obsolete function.\n"; - return &retval; + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "Obsolete function.\n"; + return &retval; case 39: /* query_debug_prog */ - if (!argc || argv[0].type != T_OBJECT) - break; - retval.type = T_NUMBER; - retval.u.number = argv[0].u.ob->prog->debug_flags; - return &retval; + if (!argc || argv[0].type != T_OBJECT) + break; + retval.type = T_NUMBER; + retval.u.number = argv[0].u.ob->prog->debug_flags; + return &retval; case 40: /* set_debug_prog */ - if (argc < 2 || argv[0].type != T_OBJECT || argv[1].type != T_NUMBER) - break; - retval.type = T_NUMBER; - retval.u.number = argv[0].u.ob->prog->debug_flags; - argv[0].u.ob->prog->debug_flags = argv[1].u.number; - return &retval; + if (argc < 2 || argv[0].type != T_OBJECT || argv[1].type != T_NUMBER) + break; + retval.type = T_NUMBER; + retval.u.number = argv[0].u.ob->prog->debug_flags; + argv[0].u.ob->prog->debug_flags = argv[1].u.number; + return &retval; #ifdef FUNCDEBUG case 41: - dumpfuncs(); - retval = const0; - return &retval; + dumpfuncs(); + retval = const0; + return &retval; #endif case 42: /* inhibitcallouts */ - if (argc && (argv[0].type == T_STRING)) - { - extern int inhibitcallouts; - int old; - - old = inhibitcallouts; - if (strcmp(argv[0].u.string, "on") == 0) - inhibitcallouts = 1; - else - inhibitcallouts = 0; - retval.type = T_NUMBER; - retval.u.number = old; - return &retval; - } - else - { - retval.type = T_NUMBER; - retval.u.number = -1; - return &retval; - } + if (argc && (argv[0].type == T_STRING)) + { + extern int inhibitcallouts; + int old; + + old = inhibitcallouts; + if (strcmp(argv[0].u.string, "on") == 0) + inhibitcallouts = 1; + else + inhibitcallouts = 0; + retval.type = T_NUMBER; + retval.u.number = old; + return &retval; + } + else + { + retval.type = T_NUMBER; + retval.u.number = -1; + return &retval; + } case 43: /* inhibitcallouts */ - if (argc && (argv[0].type == T_STRING)) - { - extern int warnobsoleteflag; - int old; - - old = warnobsoleteflag; - if (strcmp(argv[0].u.string, "on") == 0) - warnobsoleteflag = 1; - else - warnobsoleteflag = 0; - retval.type = T_NUMBER; - retval.u.number = old; - return &retval; - } - else - { - retval.type = T_NUMBER; - retval.u.number = -1; - return &retval; - } + if (argc && (argv[0].type == T_STRING)) + { + extern int warnobsoleteflag; + int old; + + old = warnobsoleteflag; + if (strcmp(argv[0].u.string, "on") == 0) + warnobsoleteflag = 1; + else + warnobsoleteflag = 0; + retval.type = T_NUMBER; + retval.u.number = old; + return &retval; + } + else + { + retval.type = T_NUMBER; + retval.u.number = -1; + return &retval; + } case 44: /* shared_strings */ #ifdef DEBUG - dump_sstrings(); - retval = const0; + dump_sstrings(); + retval = const0; #else - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Only valid if GD compiled with DEBUG flag.\n"; + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "Only valid if GD compiled with DEBUG flag.\n"; #endif - return &retval; + return &retval; case 45: /* dump_alarms */ { int c; @@ -927,91 +927,91 @@ debug_command(char *debcmd, int argc, struct svalue *argv) case 46: /* top_ten_cpu */ { #define NUMBER_OF_TOP_TEN 100 - struct program *p[NUMBER_OF_TOP_TEN]; - struct program *prog; - struct vector *v; - int i, j; + struct program *p[NUMBER_OF_TOP_TEN]; + struct program *prog; + struct vector *v; + int i, j; double now = current_cpu(); - for(i = 0; i < NUMBER_OF_TOP_TEN; i++) - p[i] = (struct program *)0L; - prog = prog_list; - do - { + for(i = 0; i < NUMBER_OF_TOP_TEN; i++) + p[i] = (struct program *)0L; + prog = prog_list; + do + { update_prog_profile(prog, now, 0.0, 0.0); - for(i = NUMBER_OF_TOP_TEN-1; i >= 0; i--) - { - if ( p[i] && (prog->cpu_avg <= p[i]->cpu_avg)) - break; - } - - if (i < (NUMBER_OF_TOP_TEN - 1)) - for (j = 0; j <= i; j++) - if (strcmp(p[j]->name,prog->name) == 0) - { - i = NUMBER_OF_TOP_TEN-1; - break; - } - - if (i < (NUMBER_OF_TOP_TEN - 1)) - { - j = NUMBER_OF_TOP_TEN - 2; - while(j > i) - { - p[j + 1] = p[j]; - j--; - } - p[i + 1] = prog; - } - } while (prog_list != (prog = prog->next_all)); - v = make_cpu_array2(NUMBER_OF_TOP_TEN, p); - if (v) - { - retval.type = T_POINTER; - retval.u.vec = v; - return &retval; - } - break; + for(i = NUMBER_OF_TOP_TEN-1; i >= 0; i--) + { + if ( p[i] && (prog->cpu_avg <= p[i]->cpu_avg)) + break; + } + + if (i < (NUMBER_OF_TOP_TEN - 1)) + for (j = 0; j <= i; j++) + if (strcmp(p[j]->name,prog->name) == 0) + { + i = NUMBER_OF_TOP_TEN-1; + break; + } + + if (i < (NUMBER_OF_TOP_TEN - 1)) + { + j = NUMBER_OF_TOP_TEN - 2; + while(j > i) + { + p[j + 1] = p[j]; + j--; + } + p[i + 1] = prog; + } + } while (prog_list != (prog = prog->next_all)); + v = make_cpu_array2(NUMBER_OF_TOP_TEN, p); + if (v) + { + retval.type = T_POINTER; + retval.u.vec = v; + return &retval; + } + break; #undef NUMBER_OF_TOP_TEN } #else case 46: - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Only valid if GD compiled with PROFILE_LPC flag.\n"; - return &retval; + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "Only valid if GD compiled with PROFILE_LPC flag.\n"; + return &retval; #endif case 47: /* object_cpu_avg object */ { #if defined(PROFILE_LPC) - if (argc < 1 || (argv[0].type != T_OBJECT)) + if (argc < 1 || (argv[0].type != T_OBJECT)) break; update_prog_profile(argv[0].u.ob->prog, current_cpu(), 0.0, 0.0); - retval.type = T_FLOAT; - retval.u.number =argv[0].u.ob->prog->cpu_avg * 1e6; - return &retval; + retval.type = T_FLOAT; + retval.u.number =argv[0].u.ob->prog->cpu_avg * 1e6; + return &retval; #else retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Only valid if GD compiled with PROFILE_LPC flag.\n"; - return &retval; + retval.string_type = STRING_CSTRING; + retval.u.string = "Only valid if GD compiled with PROFILE_LPC flag.\n"; + return &retval; #endif } - case 48: /* getprofile_avg, 28 object */ + case 48: /* getprofile_avg, 28 object */ { #if defined(PROFILE_LPC) - if (argc < 1 || argv[0].type != T_OBJECT) - break; - retval.type = T_POINTER; - retval.u.vec = allocate_array(argv[0].u.ob->prog->num_functions); + if (argc < 1 || argv[0].type != T_OBJECT) + break; + retval.type = T_POINTER; + retval.u.vec = allocate_array(argv[0].u.ob->prog->num_functions); double now = current_cpu(); struct program *prog = argv[0].u.ob->prog; - for (il = 0; il < (int)prog->num_functions; il++) - { + for (il = 0; il < (int)prog->num_functions; il++) + { struct function *func = prog->functions + il; - struct vector *res = allocate_array(3); + struct vector *res = allocate_array(3); update_func_profile(func, now, 0.0, 0.0, 0); res->item[0].type = T_STRING; res->item[0].string_type = STRING_MSTRING; @@ -1023,15 +1023,15 @@ debug_command(char *debcmd, int argc, struct svalue *argv) res->item[2].type = T_FLOAT; res->item[2].u.real = func->avg_calls; - retval.u.vec->item[il].type = T_POINTER; - retval.u.vec->item[il].u.vec = res; - } - return &retval; + retval.u.vec->item[il].type = T_POINTER; + retval.u.vec->item[il].u.vec = res; + } + return &retval; #else - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "Only valid if GD compiled with PROFILE_LPC flag.\n"; - return &retval; + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "Only valid if GD compiled with PROFILE_LPC flag.\n"; + return &retval; #endif } case 49: /* profile_timebase */ @@ -1076,22 +1076,22 @@ debug_command(char *debcmd, int argc, struct svalue *argv) { #ifdef PROFILE_LPC - extern int trace_calls; - extern FILE *trace_calls_file; + extern int trace_calls; + extern FILE *trace_calls_file; if (argc < 1 || argv[0].type != T_NUMBER) - break; + break; - if (!trace_calls && argv[0].u.number) { - if ((trace_calls_file = fopen(TRACE_CALLS_FILE, "w")) == 0) + if (!trace_calls && argv[0].u.number) { + if ((trace_calls_file = fopen(TRACE_CALLS_FILE, "w")) == 0) break; setvbuf(trace_calls_file, 0, _IOFBF, 1<<20); /* Set a 1MB buffer */ - trace_calls = 1; - } else if (trace_calls && !argv[0].u.number) { - fclose(trace_calls_file); - trace_calls_file = 0; - trace_calls = 0; - } + trace_calls = 1; + } else if (trace_calls && !argv[0].u.number) { + fclose(trace_calls_file); + trace_calls_file = 0; + trace_calls = 0; + } retval = const1; return &retval; #else @@ -1105,118 +1105,118 @@ debug_command(char *debcmd, int argc, struct svalue *argv) { #if defined(PROFILE_LPC) - long long num_top, criteria, num_items = 0; + long long num_top, criteria, num_items = 0; double now = current_cpu(), crit_val; - struct program *prog; - struct { - struct program *prog; - double crit_val; - unsigned short func_index; - } *result; + struct program *prog; + struct { + struct program *prog; + double crit_val; + unsigned short func_index; + } *result; if (argc < 2 || - argv[0].type != T_NUMBER || - argv[1].type != T_NUMBER) - break; - num_top = argv[0].u.number; - criteria = argv[1].u.number; - if (num_top < 0 || num_top > 1000) { - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "The number of itmes must be >= 0 and <= 1000."; - break; - } - if (criteria < 0 || criteria > 9) { - retval.type = T_STRING; - retval.string_type = STRING_CSTRING; - retval.u.string = "The criteria must be >= 0 and <= 9."; - break; - } - if (num_top == 0) { - retval.type = T_POINTER; - retval.u.vec = allocate_array(0); - return &retval; - } - - result = xalloc(sizeof(*result) * (num_top + 1)); - memset(result, 0, sizeof(*result) * (num_top + 1)); - - prog = prog_list; - do - { + argv[0].type != T_NUMBER || + argv[1].type != T_NUMBER) + break; + num_top = argv[0].u.number; + criteria = argv[1].u.number; + if (num_top < 0 || num_top > 1000) { + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "The number of itmes must be >= 0 and <= 1000."; + break; + } + if (criteria < 0 || criteria > 9) { + retval.type = T_STRING; + retval.string_type = STRING_CSTRING; + retval.u.string = "The criteria must be >= 0 and <= 9."; + break; + } + if (num_top == 0) { + retval.type = T_POINTER; + retval.u.vec = allocate_array(0); + return &retval; + } + + result = xalloc(sizeof(*result) * (num_top + 1)); + memset(result, 0, sizeof(*result) * (num_top + 1)); + + prog = prog_list; + do + { update_prog_profile(prog, now, 0.0, 0.0); for (int i = 0; i < prog->num_functions; i++) { struct function *func = prog->functions + i; update_func_profile(func, now, 0.0, 0.0, 0); - crit_val = get_top_func_criteria(func, criteria); - - if (num_items == num_top && - result[num_items - 1].crit_val >= crit_val) - continue; - if (num_items == 0 || (num_items < num_top && - result[num_items - 1].crit_val >= crit_val)) { - result[num_items].prog = prog; - result[num_items].func_index = i; - result[num_items].crit_val = crit_val; - num_items++; - } else { - int insert = num_items; - while (insert > 0 && - result[insert - 1].crit_val < crit_val) - insert--; - memmove(&result[insert + 1], &result[insert], - sizeof(*result) * (num_items - insert)); - result[insert].prog = prog; - result[insert].func_index = i; - result[insert].crit_val = crit_val; - if (num_items < num_top) - num_items++; - } + crit_val = get_top_func_criteria(func, criteria); + + if (num_items == num_top && + result[num_items - 1].crit_val >= crit_val) + continue; + if (num_items == 0 || (num_items < num_top && + result[num_items - 1].crit_val >= crit_val)) { + result[num_items].prog = prog; + result[num_items].func_index = i; + result[num_items].crit_val = crit_val; + num_items++; + } else { + int insert = num_items; + while (insert > 0 && + result[insert - 1].crit_val < crit_val) + insert--; + memmove(&result[insert + 1], &result[insert], + sizeof(*result) * (num_items - insert)); + result[insert].prog = prog; + result[insert].func_index = i; + result[insert].crit_val = crit_val; + if (num_items < num_top) + num_items++; + } } - } while ((prog = prog->next_all) != prog_list); + } while ((prog = prog->next_all) != prog_list); - retval.type = T_POINTER; - retval.u.vec = allocate_array(num_items); - for (int i = 0; i < num_items; i++) { - struct vector *val = allocate_array(9); - prog = result[i].prog; - struct function *func = &prog->functions[result[i].func_index]; - crit_val = result[i].crit_val; + retval.type = T_POINTER; + retval.u.vec = allocate_array(num_items); + for (int i = 0; i < num_items; i++) { + struct vector *val = allocate_array(9); + prog = result[i].prog; + struct function *func = &prog->functions[result[i].func_index]; + crit_val = result[i].crit_val; - val->item[0].type = T_STRING; - val->item[0].string_type = STRING_MSTRING; - val->item[0].u.string = make_mstring(prog->name); + val->item[0].type = T_STRING; + val->item[0].string_type = STRING_MSTRING; + val->item[0].u.string = make_mstring(prog->name); - val->item[1].type = T_STRING; - val->item[1].string_type = STRING_SSTRING; - val->item[1].u.string = func->name; - reference_sstring(func->name); + val->item[1].type = T_STRING; + val->item[1].string_type = STRING_SSTRING; + val->item[1].u.string = func->name; + reference_sstring(func->name); - val->item[2].type = T_FLOAT; - val->item[2].u.real = crit_val; + val->item[2].type = T_FLOAT; + val->item[2].u.real = crit_val; - val->item[3].type = T_FLOAT; - val->item[3].u.real = func->time_spent; + val->item[3].type = T_FLOAT; + val->item[3].u.real = func->time_spent; - val->item[4].type = T_FLOAT; - val->item[4].u.real = func->avg_time; + val->item[4].type = T_FLOAT; + val->item[4].u.real = func->avg_time; - val->item[5].type = T_FLOAT; - val->item[5].u.real = func->tot_time_spent; + val->item[5].type = T_FLOAT; + val->item[5].u.real = func->tot_time_spent; - val->item[6].type = T_FLOAT; - val->item[6].u.real = func->avg_tot_time; + val->item[6].type = T_FLOAT; + val->item[6].u.real = func->avg_tot_time; - val->item[7].type = T_FLOAT; - val->item[7].u.real = func->num_calls; + val->item[7].type = T_FLOAT; + val->item[7].u.real = func->num_calls; - val->item[8].type = T_FLOAT; - val->item[8].u.real = func->avg_calls; + val->item[8].type = T_FLOAT; + val->item[8].u.real = func->avg_calls; - retval.u.vec->item[i].type = T_POINTER; - retval.u.vec->item[i].u.vec = val; - } - free(result); + retval.u.vec->item[i].type = T_POINTER; + retval.u.vec->item[i].u.vec = val; + } + free(result); return &retval; #else retval.type = T_STRING; @@ -1224,7 +1224,7 @@ debug_command(char *debcmd, int argc, struct svalue *argv) retval.u.string = "Only valid if GD compiled with PROFILE_LPC.\n"; return &retval; #endif - } + } } retval = const0; @@ -1236,28 +1236,28 @@ get_top_func_criteria(struct function *func, int criteria) { switch (criteria) { case 0: - return func->time_spent; + return func->time_spent; case 1: - return func->avg_time; + return func->avg_time; case 2: - return func->tot_time_spent; + return func->tot_time_spent; case 3: - return func->avg_tot_time; + return func->avg_tot_time; case 4: - return func->num_calls; + return func->num_calls; case 5: - return func->avg_calls; + return func->avg_calls; case 6: - return func->num_calls > 0 ? func->time_spent / func->num_calls : -MAXDOUBLE; + return func->num_calls > 0 ? func->time_spent / func->num_calls : -MAXDOUBLE; case 7: - return func->avg_calls > 1e-30 ? func->avg_time / func->avg_calls : -MAXDOUBLE; + return func->avg_calls > 1e-30 ? func->avg_time / func->avg_calls : -MAXDOUBLE; case 8: - return func->num_calls > 0 ? func->tot_time_spent / func->num_calls : -MAXDOUBLE; + return func->num_calls > 0 ? func->tot_time_spent / func->num_calls : -MAXDOUBLE; case 9: - return func->avg_calls > 1e-30 ? func->avg_tot_time / func->avg_calls : -MAXDOUBLE; + return func->avg_calls > 1e-30 ? func->avg_tot_time / func->avg_calls : -MAXDOUBLE; default: - return -MAXDOUBLE; + return -MAXDOUBLE; } } static struct vector * @@ -1268,18 +1268,18 @@ make_cpu_array(int i, struct program *prog[]) char buff[1024]; /* should REALLY be enough */ if (i <= 0) - return 0; + return 0; ret = allocate_array(i); for(num = 0; num < i; num++) { - (void)sprintf(buff, "%16lld:%s", - (long long)(prog ? prog[num]->cpu * 1e6: 0L), - prog ? prog[num]->name : ""); - free_svalue(&ret->item[num]); - ret->item[num].type = T_STRING; - ret->item[num].string_type = STRING_MSTRING; - ret->item[num].u.string = make_mstring(buff); + (void)sprintf(buff, "%16lld:%s", + (long long)(prog ? prog[num]->cpu * 1e6: 0L), + prog ? prog[num]->name : ""); + free_svalue(&ret->item[num]); + ret->item[num].type = T_STRING; + ret->item[num].string_type = STRING_MSTRING; + ret->item[num].u.string = make_mstring(buff); } return ret; } @@ -1291,18 +1291,18 @@ make_cpu_array2(int i, struct program *prog[]) char buff[1024]; /* should REALLY be enough */ if (i <= 0) - return 0; + return 0; ret = allocate_array(i); for(num = 0; num < i; num++) { - (void)sprintf(buff, "%22.18g:%s", - (double)(prog ? prog[num]->cpu_avg * 1e6: 0L), - prog ? prog[num]->name : ""); - free_svalue(&ret->item[num]); - ret->item[num].type = T_STRING; - ret->item[num].string_type = STRING_MSTRING; - ret->item[num].u.string = make_mstring(buff); + (void)sprintf(buff, "%22.18g:%s", + (double)(prog ? prog[num]->cpu_avg * 1e6: 0L), + prog ? prog[num]->name : ""); + free_svalue(&ret->item[num]); + ret->item[num].type = T_STRING; + ret->item[num].string_type = STRING_MSTRING; + ret->item[num].u.string = make_mstring(buff); } return ret; } @@ -1318,36 +1318,36 @@ get_variables(struct object *ob) int num_var; if (ob->flags & O_DESTRUCTED) - return const0; + return const0; if (!ob->variables) - return const0; + return const0; num_var = ob->prog->num_variables + ob->prog->inherit[ob->prog->num_inherited - 1] - .variable_index_offset; + .variable_index_offset; names = allocate_array(num_var); values = allocate_array(num_var); for (j = ob->prog->num_inherited - 1; j >= 0; j--) - if (!(ob->prog->inherit[j].type & TYPE_MOD_SECOND) && - ob->prog->inherit[j].prog->num_variables > 0) - { - for (i = 0; i < (int)ob->prog->inherit[j].prog->num_variables; i++) - { - if (num_var == 0) - error("Wrong number of variables in object.\n"); - names->item[--num_var].type = T_STRING; - names->item[num_var].string_type = STRING_SSTRING; - names->item[num_var].u.string = - reference_sstring(ob->prog->inherit[j].prog-> - variable_names[i].name); - assign_svalue_no_free(&values->item[num_var], - &ob->variables[ob->prog->inherit[j] - .variable_index_offset + i]); - } - } + if (!(ob->prog->inherit[j].type & TYPE_MOD_SECOND) && + ob->prog->inherit[j].prog->num_variables > 0) + { + for (i = 0; i < (int)ob->prog->inherit[j].prog->num_variables; i++) + { + if (num_var == 0) + error("Wrong number of variables in object.\n"); + names->item[--num_var].type = T_STRING; + names->item[num_var].string_type = STRING_SSTRING; + names->item[num_var].u.string = + reference_sstring(ob->prog->inherit[j].prog-> + variable_names[i].name); + assign_svalue_no_free(&values->item[num_var], + &ob->variables[ob->prog->inherit[j] + .variable_index_offset + i]); + } + } res.type = T_MAPPING; res.u.map = make_mapping(names, values); free_vector(names); @@ -1362,13 +1362,13 @@ get_variable(struct object *ob, char *var_name) struct svalue res = const0; if (ob->flags & O_DESTRUCTED) - return res; + return res; if (!ob->variables) - return const0; + return const0; if ((i = find_status(ob->prog, var_name,0)) != -1) - assign_svalue_no_free(&res, &ob->variables[i]); + assign_svalue_no_free(&res, &ob->variables[i]); return res; } @@ -1386,43 +1386,43 @@ mem_incr(struct svalue *var) switch(var->type) { case T_FUNCTION: - function_size += sizeof (struct closure); - num_func++; - if (var->u.func->funargs) - mem_array(var->u.func->funargs); - break; + function_size += sizeof (struct closure); + num_func++; + if (var->u.func->funargs) + mem_array(var->u.func->funargs); + break; case T_MAPPING: - mapping_elem += var->u.map->size; - num_map++; - mem_mapping(var->u.map); - break; + mapping_elem += var->u.map->size; + num_map++; + mem_mapping(var->u.map); + break; case T_POINTER: - array_elem += var->u.vec->size; - num_arr++; - mem_array(var->u.vec); - break; + array_elem += var->u.vec->size; + num_arr++; + mem_array(var->u.vec); + break; case T_STRING: - string_size += strlen(var->u.string); - num_string++; - break; + string_size += strlen(var->u.string); + num_string++; + break; case T_OBJECT: - /* Check for destructed objects while we'r at it :) */ - if (var->u.ob->flags & O_DESTRUCTED) - { - num_num++; - free_svalue(var); - break; - } - num_ob++; - break; + /* Check for destructed objects while we'r at it :) */ + if (var->u.ob->flags & O_DESTRUCTED) + { + num_num++; + free_svalue(var); + break; + } + num_ob++; + break; case T_FLOAT: - num_float++; - break; + num_float++; + break; case T_NUMBER: - num_num++; - break; + num_num++; + break; default: - ; + ; } } @@ -1434,31 +1434,31 @@ mem_mapping(struct mapping *m) int size; if (m->size < 0) - return; + return; size = m->size; m->size = -1; for (i = 0 ; i < size ; i++) { for(p = &m->pairs[i]; *p; ) { - /* Check for destructed objects while we'r at it :) */ - if ((*p)->arg.type == T_OBJECT && - ((*p)->arg.u.ob->flags & O_DESTRUCTED)) - { - struct apair *f; - - f = *p; - *p = f->next; - f->next = 0; - m->card -= free_apairs(f); - mapping_elem--; - } - else - { - mem_incr(&(*p)->arg); - mem_incr(&(*p)->val); - p = &(*p)->next; - } + /* Check for destructed objects while we'r at it :) */ + if ((*p)->arg.type == T_OBJECT && + ((*p)->arg.u.ob->flags & O_DESTRUCTED)) + { + struct apair *f; + + f = *p; + *p = f->next; + f->next = 0; + m->card -= free_apairs(f); + mapping_elem--; + } + else + { + mem_incr(&(*p)->arg); + mem_incr(&(*p)->val); + p = &(*p)->next; + } } } m->size = size; @@ -1471,11 +1471,11 @@ mem_array(struct vector *v) int size; if (v->size < 0) - return; + return; size = v->size; v->size = -1; for (i = 0; i < size; i++) - mem_incr(&v->item[i]); + mem_incr(&v->item[i]); v->size = size; } @@ -1500,18 +1500,18 @@ mem_variables(FILE *f, struct object *ob) num_var = ob->prog->num_variables + ob->prog->inherit[ob->prog->num_inherited - 1].variable_index_offset; if (!ob->variables) - num_var = 0; + num_var = 0; for (i = 0; i < num_var; i++) { - mem_incr(&ob->variables[i]); + mem_incr(&ob->variables[i]); } for (num_inv = 0, o = ob->contains; o; - num_inv++, o = o->next_inv) ; + num_inv++, o = o->next_inv) ; fprintf(f, "%6d %6d %6d %6d" - " %6d %6d %6d %6d %6d" - " %6d %6d %s %s\n", - num_arr, array_elem, num_map, mapping_elem, - num_string, string_size, num_ob, num_num, num_float, - num_inv, ob->num_callouts, ob->super ? ob->super->name : "(void)", ob->name); + " %6d %6d %6d %6d %6d" + " %6d %6d %s %s\n", + num_arr, array_elem, num_map, mapping_elem, + num_string, string_size, num_ob, num_num, num_float, + num_inv, ob->num_callouts, ob->super ? ob->super->name : "(void)", ob->name); } diff --git a/doc/function_references/for_each.c b/doc/function_references/for_each.c index 6d0782e..6879d5a 100644 --- a/doc/function_references/for_each.c +++ b/doc/function_references/for_each.c @@ -12,7 +12,7 @@ for_each(mixed elements, function mapfunc) arr=elements; if (mappingp(elements)) - elements = m_values(elements); + elements = m_values(elements); for (i=0;i #include @@ -65,47 +65,47 @@ int version = 6; /* used only in the "set" function, for i.d. */ /* define this if you don't like the ending dollar signs in ed, in n-mode */ #define NO_END_DOLLAR_SIGN /* - * #defines for non-printing ASCII characters + * #defines for non-printing ASCII characters */ -#define NUL 0x00 /* ^@ */ -#define EOS 0x00 /* end of string */ -#define SOH 0x01 /* ^A */ -#define STX 0x02 /* ^B */ -#define ETX 0x03 /* ^C */ -#define EOT 0x04 /* ^D */ -#define ENQ 0x05 /* ^E */ -#define ACK 0x06 /* ^F */ -#define BEL 0x07 /* ^G */ -#define BS 0x08 /* ^H */ -#define HT 0x09 /* ^I */ -#define LF 0x0a /* ^J */ -#define NL '\n' -#define VT 0x0b /* ^K */ -#define FF 0x0c /* ^L */ -#define CR 0x0d /* ^M */ -#define SO 0x0e /* ^N */ -#define SI 0x0f /* ^O */ -#define DLE 0x10 /* ^P */ -#define DC1 0x11 /* ^Q */ -#define DC2 0x12 /* ^R */ -#define DC3 0x13 /* ^S */ -#define DC4 0x14 /* ^T */ -#define NAK 0x15 /* ^U */ -#define SYN 0x16 /* ^V */ -#define ETB 0x17 /* ^W */ -#define CAN 0x18 /* ^X */ -#define EM 0x19 /* ^Y */ -#define SUB 0x1a /* ^Z */ -#define ESC 0x1b /* ^[ */ -#define FS 0x1c /* ^\ */ -#define GS 0x1d /* ^] */ -/*#define RS 0x1e ^^ */ -#define US 0x1f /* ^_ */ -#define SP 0x20 /* space */ -#define DEL 0x7f /* DEL*/ +#define NUL 0x00 /* ^@ */ +#define EOS 0x00 /* end of string */ +#define SOH 0x01 /* ^A */ +#define STX 0x02 /* ^B */ +#define ETX 0x03 /* ^C */ +#define EOT 0x04 /* ^D */ +#define ENQ 0x05 /* ^E */ +#define ACK 0x06 /* ^F */ +#define BEL 0x07 /* ^G */ +#define BS 0x08 /* ^H */ +#define HT 0x09 /* ^I */ +#define LF 0x0a /* ^J */ +#define NL '\n' +#define VT 0x0b /* ^K */ +#define FF 0x0c /* ^L */ +#define CR 0x0d /* ^M */ +#define SO 0x0e /* ^N */ +#define SI 0x0f /* ^O */ +#define DLE 0x10 /* ^P */ +#define DC1 0x11 /* ^Q */ +#define DC2 0x12 /* ^R */ +#define DC3 0x13 /* ^S */ +#define DC4 0x14 /* ^T */ +#define NAK 0x15 /* ^U */ +#define SYN 0x16 /* ^V */ +#define ETB 0x17 /* ^W */ +#define CAN 0x18 /* ^X */ +#define EM 0x19 /* ^Y */ +#define SUB 0x1a /* ^Z */ +#define ESC 0x1b /* ^[ */ +#define FS 0x1c /* ^\ */ +#define GS 0x1d /* ^] */ +/*#define RS 0x1e ^^ */ +#define US 0x1f /* ^_ */ +#define SP 0x20 /* space */ +#define DEL 0x7f /* DEL*/ #define ESCAPE '\\' -#define TAB '\t' /* added by Qixx for indentation */ +#define TAB '\t' /* added by Qixx for indentation */ #define LB '{' #define RB '}' #define LC '(' @@ -116,24 +116,24 @@ int version = 6; /* used only in the "set" function, for i.d. */ #define EOL '\0' -#define TRUE 1 -#define FALSE 0 -#define ERR -2 -#define FATAL (ERR-1) -#define CHANGED (ERR-2) -#define SET_FAIL (ERR-3) -#define SUB_FAIL (ERR-4) -#define MEM_FAIL (ERR-5) -#define UNSPEC_FAIL (ERR-6) +#define TRUE 1 +#define FALSE 0 +#define ERR -2 +#define FATAL (ERR-1) +#define CHANGED (ERR-2) +#define SET_FAIL (ERR-3) +#define SUB_FAIL (ERR-4) +#define MEM_FAIL (ERR-5) +#define UNSPEC_FAIL (ERR-6) -#define BUFFER_SIZE 2048 /* stream-buffer size: == 1 hd cluster */ +#define BUFFER_SIZE 2048 /* stream-buffer size: == 1 hd cluster */ -#define LINFREE 1 /* entry not in use */ -#define LGLOB 2 /* line marked global */ +#define LINFREE 1 /* entry not in use */ +#define LGLOB 2 /* line marked global */ -#define MAXLINE 512 /* max number of chars per line */ -#define MAXPAT 256 /* max number of chars per replacement pattern */ -#define MAXFNAME 256 /* max file name size */ +#define MAXLINE 512 /* max number of chars per line */ +#define MAXPAT 256 /* max number of chars per replacement pattern */ +#define MAXFNAME 256 /* max file name size */ /** Global variables **/ @@ -143,13 +143,13 @@ extern struct object *master_ob; int EdErr = 0; -struct line { - int l_stat; /* empty, mark */ - struct line *l_prev; - struct line *l_next; - char l_buff[1]; +struct line { + int l_stat; /* empty, mark */ + struct line *l_prev; + struct line *l_next; + char l_buff[1]; }; -typedef struct line LINE; +typedef struct line LINE; extern struct object *command_giver; void set_prompt (char *); @@ -177,103 +177,103 @@ static void count_blanks (int line); static void _count_blanks (char *str, int blanks); static void free_ed_buffer (void); -#define ED_BUFFER (command_giver->interactive->ed_buffer) - -#define P_DIAG (ED_BUFFER->diag) -#define P_TRUNCFLG (ED_BUFFER->truncflg) -#define P_NONASCII (ED_BUFFER->nonascii) -#define P_NULLCHAR (ED_BUFFER->nullchar) -#define P_TRUNCATED (ED_BUFFER->truncated) -#define P_FNAME (ED_BUFFER->fname) -#define P_FCHANGED (ED_BUFFER->fchanged) -#define P_NOFNAME (ED_BUFFER->nofname) -#define P_MARK (ED_BUFFER->mark) -#define P_OLDPAT (ED_BUFFER->oldpat) -#define P_LINE0 (ED_BUFFER->Line0) -#define P_CURLN (ED_BUFFER->CurLn) -#define P_CURPTR (ED_BUFFER->CurPtr) -#define P_LASTLN (ED_BUFFER->LastLn) -#define P_LINE1 (ED_BUFFER->Line1) -#define P_LINE2 (ED_BUFFER->Line2) -#define P_NLINES (ED_BUFFER->nlines) -#define P_SHIFTWIDTH (ED_BUFFER->shiftwidth) -#define P_FLAGS (ED_BUFFER->flags) -#define P_APPENDING (ED_BUFFER->appending) -#define P_MORE (ED_BUFFER->moring) -#define P_LEADBLANKS (ED_BUFFER->leading_blanks) +#define ED_BUFFER (command_giver->interactive->ed_buffer) + +#define P_DIAG (ED_BUFFER->diag) +#define P_TRUNCFLG (ED_BUFFER->truncflg) +#define P_NONASCII (ED_BUFFER->nonascii) +#define P_NULLCHAR (ED_BUFFER->nullchar) +#define P_TRUNCATED (ED_BUFFER->truncated) +#define P_FNAME (ED_BUFFER->fname) +#define P_FCHANGED (ED_BUFFER->fchanged) +#define P_NOFNAME (ED_BUFFER->nofname) +#define P_MARK (ED_BUFFER->mark) +#define P_OLDPAT (ED_BUFFER->oldpat) +#define P_LINE0 (ED_BUFFER->Line0) +#define P_CURLN (ED_BUFFER->CurLn) +#define P_CURPTR (ED_BUFFER->CurPtr) +#define P_LASTLN (ED_BUFFER->LastLn) +#define P_LINE1 (ED_BUFFER->Line1) +#define P_LINE2 (ED_BUFFER->Line2) +#define P_NLINES (ED_BUFFER->nlines) +#define P_SHIFTWIDTH (ED_BUFFER->shiftwidth) +#define P_FLAGS (ED_BUFFER->flags) +#define P_APPENDING (ED_BUFFER->appending) +#define P_MORE (ED_BUFFER->moring) +#define P_LEADBLANKS (ED_BUFFER->leading_blanks) #define P_CUR_AUTOIND (ED_BUFFER->cur_autoindent) /* shiftwidth is meant to be a 4-bit-value that can be packed into an int along with flags, therefore masks 0x1 ... 0x8 are reserved. */ -#define NFLG_MASK 0x0010 -#define P_NFLG ( P_FLAGS & NFLG_MASK ) -#define LFLG_MASK 0x0020 -#define P_LFLG ( P_FLAGS & LFLG_MASK ) -#define PFLG_MASK 0x0040 -#define P_PFLG ( P_FLAGS & PFLG_MASK ) -#define EIGHTBIT_MASK 0x0080 -#define P_EIGHTBIT ( P_FLAGS & EIGHTBIT_MASK ) -#define AUTOINDFLG_MASK 0x0100 -#define P_AUTOINDFLG ( P_FLAGS & AUTOINDFLG_MASK ) -#define EXCOMPAT_MASK 0x0200 -#define P_EXCOMPAT ( P_FLAGS & EXCOMPAT_MASK ) -#define TABINDENT_MASK 0x0400 -#define P_TABINDENT ( P_FLAGS & TABINDENT_MASK ) -#define SHIFTWIDTH_MASK 0x000f -#define ALL_FLAGS_MASK 0x07f0 - - -char inlin[MAXLINE]; -char *inptr; /* tty input buffer */ +#define NFLG_MASK 0x0010 +#define P_NFLG ( P_FLAGS & NFLG_MASK ) +#define LFLG_MASK 0x0020 +#define P_LFLG ( P_FLAGS & LFLG_MASK ) +#define PFLG_MASK 0x0040 +#define P_PFLG ( P_FLAGS & PFLG_MASK ) +#define EIGHTBIT_MASK 0x0080 +#define P_EIGHTBIT ( P_FLAGS & EIGHTBIT_MASK ) +#define AUTOINDFLG_MASK 0x0100 +#define P_AUTOINDFLG ( P_FLAGS & AUTOINDFLG_MASK ) +#define EXCOMPAT_MASK 0x0200 +#define P_EXCOMPAT ( P_FLAGS & EXCOMPAT_MASK ) +#define TABINDENT_MASK 0x0400 +#define P_TABINDENT ( P_FLAGS & TABINDENT_MASK ) +#define SHIFTWIDTH_MASK 0x000f +#define ALL_FLAGS_MASK 0x07f0 + + +char inlin[MAXLINE]; +char *inptr; /* tty input buffer */ struct ed_buffer { - int diag; /* diagnostic-output? flag */ - int truncflg; /* truncate long line flag */ - int nonascii; /* count of non-ascii chars read */ - int nullchar; /* count of null chars read */ - int truncated; /* count of lines truncated */ - char fname[MAXFNAME]; - int fchanged; /* file-changed? flag */ - int nofname; - int mark['z'-'a'+1]; - regexp *oldpat; - - LINE Line0; - int CurLn; - LINE *CurPtr; /* CurLn and CurPtr must be kept in step */ - int LastLn; - int Line1, Line2, nlines; - int flags; + int diag; /* diagnostic-output? flag */ + int truncflg; /* truncate long line flag */ + int nonascii; /* count of non-ascii chars read */ + int nullchar; /* count of null chars read */ + int truncated; /* count of lines truncated */ + char fname[MAXFNAME]; + int fchanged; /* file-changed? flag */ + int nofname; + int mark['z'-'a'+1]; + regexp *oldpat; + + LINE Line0; + int CurLn; + LINE *CurPtr; /* CurLn and CurPtr must be kept in step */ + int LastLn; + int Line1, Line2, nlines; + int flags; #if 0 - int eightbit; /* save eighth bit */ - int nflg; /* print line number flag */ - int lflg; /* print line in verbose mode */ - int pflg; /* print current line after each command */ + int eightbit; /* save eighth bit */ + int nflg; /* print line number flag */ + int lflg; /* print line in verbose mode */ + int pflg; /* print current line after each command */ #endif - int appending; + int appending; int moring; /* used for the wait line of help */ struct closure *exit_func; /* function to call on exit */ - int shiftwidth; - int leading_blanks; - int cur_autoindent; + int shiftwidth; + int leading_blanks; + int cur_autoindent; }; struct tbl { - char *t_str; - int t_and_mask; - int t_or_mask; + char *t_str; + int t_and_mask; + int t_or_mask; } *t, tbl[] = { - { "number", ~FALSE, NFLG_MASK, }, - { "nonumber", ~NFLG_MASK, FALSE, }, - { "list", ~FALSE, LFLG_MASK, }, - { "nolist", ~LFLG_MASK, FALSE, }, - { "print", ~FALSE, PFLG_MASK, }, - { "noprint", ~PFLG_MASK, FALSE, }, - { "eightbit", ~FALSE, EIGHTBIT_MASK, }, - { "noeightbit", ~EIGHTBIT_MASK, FALSE, }, - { "autoindent", ~FALSE, AUTOINDFLG_MASK, }, - { "noautoindent", ~AUTOINDFLG_MASK, FALSE, }, - { "excompatible", ~FALSE, EXCOMPAT_MASK, }, + { "number", ~FALSE, NFLG_MASK, }, + { "nonumber", ~NFLG_MASK, FALSE, }, + { "list", ~FALSE, LFLG_MASK, }, + { "nolist", ~LFLG_MASK, FALSE, }, + { "print", ~FALSE, PFLG_MASK, }, + { "noprint", ~PFLG_MASK, FALSE, }, + { "eightbit", ~FALSE, EIGHTBIT_MASK, }, + { "noeightbit", ~EIGHTBIT_MASK, FALSE, }, + { "autoindent", ~FALSE, AUTOINDFLG_MASK, }, + { "noautoindent", ~AUTOINDFLG_MASK, FALSE, }, + { "excompatible", ~FALSE, EXCOMPAT_MASK, }, { "noexcompatible",~EXCOMPAT_MASK,FALSE, }, - { "tabindent", ~FALSE, TABINDENT_MASK, }, + { "tabindent", ~FALSE, TABINDENT_MASK, }, { "notabindent",~TABINDENT_MASK, FALSE, }, { 0, 0, 0 }, }; @@ -281,37 +281,37 @@ struct tbl { /*-------------------------------------------------------------------------*/ -extern LINE *getptr(int); -extern void prntln(char *, int, int), error(char *, ...); -regexp *optpat(void); +extern LINE *getptr(int); +extern void prntln(char *, int, int), error(char *, ...); +regexp *optpat(void); /*________ Macros ________________________________________________________*/ #ifndef max -# define max(a,b) ((a) > (b) ? (a) : (b)) +# define max(a,b) ((a) > (b) ? (a) : (b)) #endif #ifndef min -# define min(a,b) ((a) < (b) ? (a) : (b)) +# define min(a,b) ((a) < (b) ? (a) : (b)) #endif -#define nextln(l) ((l)+1 > P_LASTLN ? 0 : (l)+1) -#define prevln(l) ((l)-1 < 0 ? P_LASTLN : (l)-1) +#define nextln(l) ((l)+1 > P_LASTLN ? 0 : (l)+1) +#define prevln(l) ((l)-1 < 0 ? P_LASTLN : (l)-1) -#define gettxtl(lin) ((lin)->l_buff) -#define gettxt(num) (gettxtl( getptr(num) )) +#define gettxtl(lin) ((lin)->l_buff) +#define gettxt(num) (gettxtl( getptr(num) )) -#define getnextptr(p) ((p)->l_next) -#define getprevptr(p) ((p)->l_prev) +#define getnextptr(p) ((p)->l_next) +#define getprevptr(p) ((p)->l_prev) -#define setCurLn( lin ) ( P_CURPTR = getptr( P_CURLN = (lin) ) ) -#define nextCurLn() ( P_CURLN = nextln(P_CURLN), P_CURPTR = getnextptr( P_CURPTR ) ) -#define prevCurLn() ( P_CURLN = prevln(P_CURLN), P_CURPTR = getprevptr( P_CURPTR ) ) +#define setCurLn( lin ) ( P_CURPTR = getptr( P_CURLN = (lin) ) ) +#define nextCurLn() ( P_CURLN = nextln(P_CURLN), P_CURPTR = getnextptr( P_CURPTR ) ) +#define prevCurLn() ( P_CURLN = prevln(P_CURLN), P_CURPTR = getprevptr( P_CURPTR ) ) -#define clrbuf() del(1, P_LASTLN) +#define clrbuf() del(1, P_LASTLN) -#define Skip_White_Space {while (*inptr==SP || *inptr==HT) inptr++;} +#define Skip_White_Space {while (*inptr==SP || *inptr==HT) inptr++;} #define relink(a, x, y, b) { (x)->l_prev = (a); (y)->l_next = (b); } @@ -319,7 +319,7 @@ regexp *optpat(void); /*________ functions ______________________________________________________*/ -/* append.c */ +/* append.c */ int @@ -395,15 +395,15 @@ _count_blanks(char *str, int blanks) P_LEADBLANKS = blanks < MAXLINE ? blanks : MAXLINE ; } -/* ckglob.c */ +/* ckglob.c */ int ckglob() { - regexp *glbpat; - char c, delim, *lin; - int num; - LINE *ptr; + regexp *glbpat; + char c, delim, *lin; + int num; + LINE *ptr; c = *inptr; @@ -426,7 +426,7 @@ ckglob() if (P_LINE1 <= num && num <= P_LINE2) { /* we might have got a NULL pointer if the - supplied pattern was invalid */ + supplied pattern was invalid */ if (glbpat) { lin = gettxtl(ptr); @@ -445,8 +445,8 @@ ckglob() /* deflt.c - * Set P_LINE1 & P_LINE2 (the command-range delimiters) if the file is - * empty; Test whether they have valid values. + * Set P_LINE1 & P_LINE2 (the command-range delimiters) if the file is + * empty; Test whether they have valid values. */ int @@ -461,7 +461,7 @@ deflt(int def1, int def2) } -/* del.c */ +/* del.c */ /* One of the calls to this function tests its return value for an error * condition. But del doesn't return any error value, and it isn't obvious @@ -473,7 +473,7 @@ deflt(int def1, int def2) int del(int from, int to) { - LINE *first, *last, *next, *tmp; + LINE *first, *last, *next, *tmp; if(from < 1) from = 1; @@ -504,7 +504,7 @@ dolst(int line1, int line2) return p; } -/* doprnt.c */ +/* doprnt.c */ int doprnt(int from, int to) @@ -564,12 +564,12 @@ void prntln(char *str, int vflg, int len) (void)add_message("%s\n", start); } -/* egets.c */ +/* egets.c */ int egets(char *str, int size, FILE *stream) { - int c = 0, count; + int c = 0, count; char *cp; for (count = 0, cp = str; size > count;) @@ -588,16 +588,16 @@ egets(char *str, int size, FILE *stream) return(++count); } else if (c == 0) - P_NULLCHAR++; /* count nulls */ + P_NULLCHAR++; /* count nulls */ else { if(c > 127) { - if(!P_EIGHTBIT) /* if not saving eighth bit */ - c = c & 127; /* strip eigth bit */ - P_NONASCII++; /* count it */ + if(!P_EIGHTBIT) /* if not saving eighth bit */ + c = c & 127; /* strip eigth bit */ + P_NONASCII++; /* count it */ } - *cp++ = c; /* not null, keep it */ + *cp++ = c; /* not null, keep it */ count++; } } @@ -617,11 +617,11 @@ egets(char *str, int size, FILE *stream) int doread(int lin, char *fname) { - FILE *fp; - int err; - unsigned long bytes; - unsigned int lines; - static char str[MAXLINE]; + FILE *fp; + int err; + unsigned long bytes; + unsigned int lines; + static char str[MAXLINE]; P_NONASCII = P_NULLCHAR = P_TRUNCATED = 0; @@ -664,12 +664,12 @@ doread(int lin, char *fname) int dowrite(int from, int to, char *fname, int apflg) { - FILE *fp; - int lin, err; - unsigned int lines; - unsigned long bytes; - char *str; - LINE *lptr; + FILE *fp; + int lin, err; + unsigned int lines; + unsigned long bytes; + char *str; + LINE *lptr; err = 0; lines = 0; @@ -687,7 +687,7 @@ dowrite(int from, int to, char *fname, int apflg) { str = lptr->l_buff; lines++; - bytes += strlen(str) + 1; /* str + '\n' */ + bytes += strlen(str) + 1; /* str + '\n' */ if(fputs(str, fp) == EOF) { (void)add_message("file write error\n"); @@ -703,12 +703,12 @@ dowrite(int from, int to, char *fname, int apflg) } /* dowrite */ -/* find.c */ +/* find.c */ int find(regexp *pat, int dir) { - int i, num; - LINE *lin; + int i, num; + LINE *lin; if (dir) nextCurLn(); @@ -732,14 +732,14 @@ int find(regexp *pat, int dir) } #if 0 -/* findg.c by Ted Gaunt for global searches.... much like 'grep' +/* findg.c by Ted Gaunt for global searches.... much like 'grep' especially useful when line numbering is turned on. */ int findg(regexp *pat, int dir) { - int i, num,count; - LINE *lin; + int i, num,count; + LINE *lin; count=0; num = P_CURLN; @@ -763,13 +763,13 @@ findg(regexp *pat, int dir) } #endif /* 0 */ -/* getfn.c */ +/* getfn.c */ char * getfn(int writeflg) { - static char file[MAXFNAME]; - char *cp; + static char file[MAXFNAME]; + char *cp; char *file2; struct svalue *ret; @@ -822,14 +822,14 @@ getfn(int writeflg) int getnum(int first) { - regexp *srchpat; - int num; - char c; + regexp *srchpat; + int num; + char c; Skip_White_Space; if(*inptr >= '0' && *inptr <= '9') - { /* line number */ + { /* line number */ for(num = 0; *inptr >= '0' && *inptr <= '9'; ++inptr) { num = (num * 10) + (*inptr - '0'); } @@ -854,7 +854,7 @@ getnum(int first) return(find(srchpat,c == '/'?1:0)); #if 0 - case '^': /* for grep-like searching */ + case '^': /* for grep-like searching */ case '&': srchpat = optpat(); if(*inptr == c) @@ -873,13 +873,13 @@ getnum(int first) return P_MARK[ *inptr++ - 'a' ]; default: - return ( first ? EOF : 1 ); /* unknown address */ + return ( first ? EOF : 1 ); /* unknown address */ } } /* getnum */ /* getone.c - * Parse a number (or arithmetic expression) off the command line. + * Parse a number (or arithmetic expression) off the command line. */ #define FIRST 1 #define NOTFIRST 0 @@ -887,7 +887,7 @@ getnum(int first) int getone() { - int c, i, num; + int c, i, num; if((num = getnum(FIRST)) >= 0) { @@ -895,7 +895,7 @@ getone() { Skip_White_Space; if(*inptr != '+' && *inptr != '-') - break; /* exit infinite loop */ + break; /* exit infinite loop */ c = *inptr++; if((i = getnum(NOTFIRST)) < 0) @@ -912,7 +912,7 @@ getone() int getlst() { - int num; + int num; P_LINE2 = 0; for(P_NLINES = 0; (num = getone()) >= 0;) @@ -936,19 +936,19 @@ getlst() } /* getlst */ -/* getptr.c */ +/* getptr.c */ LINE *getptr(num) - int num; + int num; { - LINE *ptr; - int j; + LINE *ptr; + int j; - if (2*num>P_LASTLN && num<=P_LASTLN) { /* high line numbers */ + if (2*num>P_LASTLN && num<=P_LASTLN) { /* high line numbers */ ptr = P_LINE0.l_prev; for (j = P_LASTLN; j>num; j--) ptr = ptr->l_prev; - } else { /* low line numbers */ + } else { /* low line numbers */ ptr = &P_LINE0; for(j = 0; j < num; j++) ptr = ptr->l_next; @@ -957,14 +957,14 @@ LINE *getptr(num) } -/* getrhs.c */ +/* getrhs.c */ int getrhs(char *sub) { char delim = *inptr++; char *outmax = sub + MAXPAT; - if( delim == NL || *inptr == NL) /* check for eol */ + if( delim == NL || *inptr == NL) /* check for eol */ return( ERR ); while( *inptr != delim && *inptr != NL ) { @@ -1037,7 +1037,7 @@ getrhs(char *sub) } *sub = '\0'; - inptr++; /* skip over delimter */ + inptr++; /* skip over delimter */ Skip_White_Space; if(*inptr == 'g') { @@ -1047,13 +1047,13 @@ getrhs(char *sub) return 0; } -/* ins.c */ +/* ins.c */ int ins(char *str) { - char *cp; - LINE *new, *nxt; - size_t len; + char *cp; + LINE *new, *nxt; + size_t len; do { @@ -1063,13 +1063,13 @@ int ins(char *str) /* cp now points to end of first or only line */ if((new = (LINE *) xalloc(sizeof(LINE) + len)) == NULL) - return( MEM_FAIL ); /* no memory */ + return( MEM_FAIL ); /* no memory */ new->l_stat=0; - (void)strncpy(new->l_buff, str, len); /* build new line */ + (void)strncpy(new->l_buff, str, len); /* build new line */ new->l_buff[len] = EOS; - nxt = getnextptr(P_CURPTR); /* get next line */ - relink(P_CURPTR, new, new, nxt); /* add to linked list */ + nxt = getnextptr(P_CURPTR); /* get next line */ + relink(P_CURPTR, new, new, nxt); /* add to linked list */ relink(new, nxt, P_CURPTR, new); P_LASTLN++; P_CURLN++; @@ -1081,7 +1081,7 @@ int ins(char *str) } -/* join.c */ +/* join.c */ int join(int first, int last) @@ -1131,15 +1131,15 @@ join(int first, int last) /* move.c - * Unlink the block of lines from P_LINE1 to P_LINE2, and relink them - * after line "num". + * Unlink the block of lines from P_LINE1 to P_LINE2, and relink them + * after line "num". */ int moveblock(int num) { - int range; - LINE *before, *first, *last, *after; + int range; + LINE *before, *first, *last, *after; if( P_LINE1 <= num && num <= P_LINE2 ) return( ERR ); @@ -1150,7 +1150,7 @@ moveblock(int num) after = getptr(nextln(P_LINE2)); relink(before, after, before, after); - P_LASTLN -= range; /* per ASTs posted patch 2/2/88 */ + P_LASTLN -= range; /* per ASTs posted patch 2/2/88 */ if (num > P_LINE1) num -= range; @@ -1158,7 +1158,7 @@ moveblock(int num) after = getptr(nextln(num)); relink(before, first, last, after); relink(last, after, before, first); - P_LASTLN += range; /* per ASTs posted patch 2/2/88 */ + P_LASTLN += range; /* per ASTs posted patch 2/2/88 */ setCurLn( num + range ); return 1; } @@ -1196,12 +1196,12 @@ transfer(int num) } -/* optpat.c */ +/* optpat.c */ regexp * optpat() { - char delim, str[MAXPAT], *cp; + char delim, str[MAXPAT], *cp; delim = *inptr++; if (delim == NL) @@ -1233,8 +1233,8 @@ regerror(char *s) int set() { - char word[16]; - int i; + char word[16]; + int i; if(*(++inptr) != 't') { if(*inptr != SP && *inptr != HT && *inptr != NL) @@ -1276,7 +1276,7 @@ set() { struct svalue *ret; push_object(command_giver); - /* push_object(command_giver, "ed: set()" ); */ + /* push_object(command_giver, "ed: set()" ); */ push_number( P_SHIFTWIDTH | P_FLAGS ); ret = apply_master_ob(M_SAVE_ED_SETUP,2); if ( ret && ret->type == T_NUMBER && ret->u.number > 0 ) @@ -1312,27 +1312,27 @@ set_ed_buf() } -/* subst.c */ +/* subst.c */ int subst(regexp *pat, char *sub, int gflg, int pflag) { - int nchngd = 0; - char *txtptr; - char *new, *old, buf[MAXLINE]; - int space; /* amylaar */ - int still_running = 1; - LINE *lastline = getptr( P_LINE2 ); + int nchngd = 0; + char *txtptr; + char *new, *old, buf[MAXLINE]; + int space; /* amylaar */ + int still_running = 1; + LINE *lastline = getptr( P_LINE2 ); if(P_LINE1 <= 0) return( SUB_FAIL ); - nchngd = 0; /* reset count of lines changed */ + nchngd = 0; /* reset count of lines changed */ for( setCurLn( prevln( P_LINE1 ) ); still_running; ) { nextCurLn(); new = buf; - space = MAXLINE; /* amylaar */ + space = MAXLINE; /* amylaar */ if ( P_CURPTR == lastline ) still_running = 0; if ( regexec( pat, txtptr = gettxtl( P_CURPTR ) ) ) @@ -1342,7 +1342,7 @@ subst(regexp *pat, char *sub, int gflg, int pflag) /* Copy leading text */ size_t diff = pat->startp[0] - txtptr; - if ( (space-=diff) < 0 ) /* amylaar */ + if ( (space-=diff) < 0 ) /* amylaar */ return SUB_FAIL; (void)strncpy( new, txtptr, diff ); new += diff; @@ -1445,26 +1445,26 @@ shift(char *text) } } -#define STACKSZ 1024 /* depth of indent stack */ +#define STACKSZ 1024 /* depth of indent stack */ /* * Token definitions in indent */ -#define SEMICOLON 0 -#define LBRACKET 1 -#define RBRACKET 2 -#define LOPERATOR 3 -#define ROPERATOR 4 -#define LHOOK 5 -#define LHOOK2 6 -#define RHOOK 7 -#define TOKEN 8 -#define ELSE 9 -#define IF 10 -#define FOR 11 -#define WHILE 12 -#define DO 13 -#define XEOT 14 +#define SEMICOLON 0 +#define LBRACKET 1 +#define RBRACKET 2 +#define LOPERATOR 3 +#define ROPERATOR 4 +#define LHOOK 5 +#define LHOOK2 6 +#define RHOOK 7 +#define TOKEN 8 +#define ELSE 9 +#define IF 10 +#define FOR 11 +#define WHILE 12 +#define DO 13 +#define XEOT 14 static struct pps_stack { char *stack, *stackbot; @@ -1472,10 +1472,10 @@ static struct pps_stack { struct pps_stack *last; } *pps; -static char *stack, *stackbot; /* token stack */ -static int *ind, *indbot; /* indent stack */ -static char quote; /* ' or " */ -static int in_ppcontrol, in_comment, after_keyword; /* status */ +static char *stack, *stackbot; /* token stack */ +static int *ind, *indbot; /* indent stack */ +static char quote; /* ' or " */ +static int in_ppcontrol, in_comment, after_keyword; /* status */ static void indent(char *buf) @@ -1508,7 +1508,7 @@ indent(char *buf) * process status vars */ if (quote != '\0') - shi = 0; /* in case a comment starts on this line */ + shi = 0; /* in case a comment starts on this line */ else if ((in_ppcontrol || *p == '#') && p[1] != '\'') { if (*p == '#') @@ -1616,7 +1616,7 @@ indent(char *buf) return; } else if (in_comment) - shift(text); /* use previous shi */ + shift(text); /* use previous shi */ else do_indent = TRUE; } @@ -1681,7 +1681,7 @@ indent(char *buf) { switch (*p++) { - case ' ': /* white space */ + case ' ': /* white space */ case '\t': continue; @@ -1703,12 +1703,12 @@ indent(char *buf) break; } /* FALLTHROUGH */ - case '"': /* start of string */ + case '"': /* start of string */ quote = p[-1]; continue; case '/': - if (*p == '*') /* start of comment */ + if (*p == '*') /* start of comment */ { in_comment = TRUE; if (do_indent) @@ -1747,7 +1747,7 @@ indent(char *buf) p++; continue; } - if (*p == '/') /* start of C++ style comment */ + if (*p == '/') /* start of C++ style comment */ p = strchr(p, '\0'); token = TOKEN; break; @@ -1770,7 +1770,7 @@ indent(char *buf) } if (*p == '{' || *p == '[') { - p++; /* ({ , ([ each are one token */ + p++; /* ({ , ([ each are one token */ token = LHOOK2; break; } @@ -1819,12 +1819,12 @@ indent(char *buf) while (isalnum(*p) || *p == '_'); *q = '\0'; - if (strcmp(ident, "if" ) == 0) token = IF; - else if (strcmp(ident, "else" ) == 0) token = ELSE; - else if (strcmp(ident, "for" ) == 0) token = FOR; - else if (strcmp(ident, "while") == 0) token = WHILE; - else if (strcmp(ident, "do" ) == 0) token = DO; - else /* not a keyword */ token = TOKEN; + if (strcmp(ident, "if" ) == 0) token = IF; + else if (strcmp(ident, "else" ) == 0) token = ELSE; + else if (strcmp(ident, "for" ) == 0) token = FOR; + else if (strcmp(ident, "while") == 0) token = WHILE; + else if (strcmp(ident, "do" ) == 0) token = DO; + else /* not a keyword */ token = TOKEN; } else { @@ -1848,7 +1848,7 @@ indent(char *buf) if (top == LOPERATOR && token == RHOOK) token = ROPERATOR; - if (f[top] <= g[token]) /* shift the token on the stack */ + if (f[top] <= g[token]) /* shift the token on the stack */ { register int i; @@ -1944,7 +1944,7 @@ indent(char *buf) } stack = isp; ind = ip; - after_keyword = (token >= IF); /* but not after ELSE */ + after_keyword = (token >= IF); /* but not after ELSE */ } } @@ -2001,19 +2001,19 @@ indent_code() #endif /* docmd.c - * Perform the command specified in the input buffer, as pointed to - * by inptr. Actually, this finds the command letter first. + * Perform the command specified in the input buffer, as pointed to + * by inptr. Actually, this finds the command letter first. */ int docmd(int glob) { - static char rhs[MAXPAT]; - regexp *subpat; - int c, err, line3; - int apflg, pflag, gflag; - int nchng; - char *fptr; + static char rhs[MAXPAT]; + regexp *subpat; + int c, err, line3; + int apflg, pflag, gflag; + int nchng; + char *fptr; pflag = FALSE; Skip_White_Space; @@ -2231,8 +2231,8 @@ docmd(int glob) if(P_NLINES > 1) return(ERR); - if(P_NLINES == 0) /* The original code tested */ - P_LINE2 = P_LASTLN; /* if(P_NLINES = 0) */ + if(P_NLINES == 0) /* The original code tested */ + P_LINE2 = P_LASTLN; /* if(P_NLINES = 0) */ /* which looks wrong. RAM */ if(*inptr != ' ' && *inptr != HT && *inptr != NL) @@ -2347,7 +2347,7 @@ docmd(int glob) return(ERR); break; } - break; + break; default: return(ERR); } @@ -2356,13 +2356,13 @@ docmd(int glob) } /* docmd */ -/* doglob.c */ +/* doglob.c */ int doglob() { - int lin, status; - char *cmd; - LINE *ptr; + int lin, status; + char *cmd; + LINE *ptr; cmd = inptr; @@ -2412,7 +2412,7 @@ void ed_start(char *file_arg, struct closure *exit_func) ED_BUFFER->truncflg = 1; ED_BUFFER->flags |= EIGHTBIT_MASK | TABINDENT_MASK; ED_BUFFER->shiftwidth = 4; - /* push_object(command_giver, "ed: ed_start()"); */ + /* push_object(command_giver, "ed: ed_start()"); */ push_object(command_giver); setup = apply_master_ob(M_RETRIEVE_ED_SETUP,1); if ( setup && setup->type == T_NUMBER && setup->u.number ) @@ -2420,7 +2420,7 @@ void ed_start(char *file_arg, struct closure *exit_func) ED_BUFFER->flags = setup->u.number & ALL_FLAGS_MASK; ED_BUFFER->shiftwidth = setup->u.number & SHIFTWIDTH_MASK; } - ED_BUFFER->CurPtr = &ED_BUFFER->Line0; + ED_BUFFER->CurPtr = &ED_BUFFER->Line0; ED_BUFFER->exit_func = exit_func; /* reference count has been incremented already */ set_ed_buf(); @@ -2436,7 +2436,7 @@ void ed_start(char *file_arg, struct closure *exit_func) if (!doread(0, file_arg)) setCurLn( 1 ); else - { /* May be a new file. Check with master for starting text. */ + { /* May be a new file. Check with master for starting text. */ push_object(command_giver); push_string(file_arg, STRING_MSTRING); if ((setup = apply_master_ob(M_GET_ED_EMPTY_FILE,2)) != NULL) @@ -2581,7 +2581,7 @@ ed_cmd(char *str) default: (void)add_message("Unrecognized or failed command.\n"); /* Unrecognized or failed command (this */ - /* is SOOOO much better than "?" */ + /* is SOOOO much better than "?" */ } } @@ -2599,7 +2599,7 @@ save_ed_buffer() if (*fname == '/') fname++; (void)dowrite(1, P_LASTLN, fname , 0); } - /* free_svalue(stmp, "save_ed_buffer"); */ + /* free_svalue(stmp, "save_ed_buffer"); */ free_svalue(stmp); } free_ed_buffer(); @@ -2755,9 +2755,9 @@ print_help(int arg) 'set save' will preserve the current settings for subsequent invocations of ed.\n\ Options:\n\ \n\ - number will print line numbers before printing or inserting a lines\n\ - list will print control characters in p(rint) and z command like in l(ist)\n\ - print will show current line after a single substitution\n\ + number will print line numbers before printing or inserting a lines\n\ + list will print control characters in p(rint) and z command like in l(ist)\n\ + print will show current line after a single substitution\n\ eightbit\n\ autoindent will preserve current indentation while entering text.\n\ use ^D or ^K to get back one step back to the right.\n\ diff --git a/efun/math.c b/efun/math.c index 6d830c9..5776592 100644 --- a/efun/math.c +++ b/efun/math.c @@ -29,7 +29,7 @@ void f_ftoi(int num_arg) { if (sp->u.real > (double)LLONG_MAX || sp->u.real < (double)LLONG_MIN) - error("Integer overflow.\n"); + error("Integer overflow.\n"); sp->type = T_NUMBER; sp->u.number = sp->u.real; } diff --git a/efun/math.h b/efun/math.h index ae8b516..3d5e5dd 100644 --- a/efun/math.h +++ b/efun/math.h @@ -26,4 +26,4 @@ void f_ftoa(int num_arg); void f_fact(int num_arg); void f_sqrt(int num_arg); -#endif \ No newline at end of file +#endif diff --git a/efun/string.c b/efun/string.c index 37c1983..e93fd86 100644 --- a/efun/string.c +++ b/efun/string.c @@ -11,10 +11,10 @@ f_upper_case(int num_arg) int i; if (sp->type == T_NUMBER) - return; + return; str = make_mstring(sp->u.string); for (i = strlen(str)-1; i>=0; i--) - str[i] = toupper(str[i]); + str[i] = toupper(str[i]); pop_stack(); push_mstring(str); } @@ -26,10 +26,10 @@ f_lower_case(int num_arg) int i; if (sp->type == T_NUMBER) - return; + return; str = make_mstring(sp->u.string); for (i = strlen(str)-1; i>=0; i--) - str[i] = tolower(str[i]); + str[i] = tolower(str[i]); pop_stack(); push_mstring(str); } @@ -57,14 +57,14 @@ f_capitalize(int num_arg) struct svalue *arg = sp - num_arg + 1; if (arg[0].type == T_NUMBER) - return; + return; if (islower(arg[0].u.string[0])) { - char *str; - str = make_mstring(arg[0].u.string); - str[0] = toupper(str[0]); - pop_stack(); - push_mstring(str); + char *str; + str = make_mstring(arg[0].u.string); + str[0] = toupper(str[0]); + pop_stack(); + push_mstring(str); } } @@ -74,9 +74,9 @@ f_strlen(int xxx) int i; if (sp->type == T_NUMBER) - i = 0; + i = 0; else - i = strlen(sp->u.string); + i = strlen(sp->u.string); pop_stack(); push_number(i); -} \ No newline at end of file +} diff --git a/efun/string.h b/efun/string.h index ff23daf..6b012c5 100644 --- a/efun/string.h +++ b/efun/string.h @@ -6,4 +6,4 @@ void f_lower_case(int num_arg); void f_readable_string(int num_arg); void f_capitalize(int num_arg); void f_strlen(int xxx); -#endif \ No newline at end of file +#endif diff --git a/exec.h b/exec.h index 3534451..4b724e6 100644 --- a/exec.h +++ b/exec.h @@ -57,8 +57,8 @@ struct cfun_desc struct function { #if defined(PROFILE_LPC) - unsigned long long num_calls; /* Number of times this function called */ - double time_spent; /* cpu spent inside this function */ + unsigned long long num_calls; /* Number of times this function called */ + double time_spent; /* cpu spent inside this function */ double tot_time_spent; /* cpu spent inside this function and those called by it */ double avg_time; double avg_tot_time; @@ -68,14 +68,14 @@ struct function { char *name; short hash_idx; - unsigned short type_flags; /* Return type of function. See below. */ - /* NAME_ . See above. */ + unsigned short type_flags; /* Return type of function. See below. */ + /* NAME_ . See above. */ offset_t offset; /* Address of function or inherit table index when inherited. */ - unsigned char num_local; /* Number of local variables */ - char num_arg; /* Number of arguments needed. + unsigned char num_local; /* Number of local variables */ + char num_arg; /* Number of arguments needed. * -1 arguments means function not defined - * in this object. Probably inherited */ + * in this object. Probably inherited */ char first_default; }; @@ -87,7 +87,7 @@ struct function_hash { struct variable { char *name; - unsigned short type; /* Type of variable. See below. TYPE_ */ + unsigned short type; /* Type of variable. See below. TYPE_ */ }; struct inherit { @@ -107,36 +107,36 @@ struct segment_desc int size_offset; struct section_desc { - int section; - int ptr_offset; - int num_offset; - int ent_size; + int section; + int ptr_offset; + int num_offset; + int ent_size; } *sections; }; extern struct segment_desc segm_desc[]; -#define A_HEADER 0 -#define A_PROGRAM 1 -#define A_FUNCTIONS 2 -#define A_RODATA 3 -#define A_VARIABLES 4 -#define A_LINENUMBERS 5 -#define A_INHERITS 6 -#define A_ARGUMENT_TYPES 7 -#define A_ARGUMENT_INDEX 8 -#define A_INCLUDES 9 +#define A_HEADER 0 +#define A_PROGRAM 1 +#define A_FUNCTIONS 2 +#define A_RODATA 3 +#define A_VARIABLES 4 +#define A_LINENUMBERS 5 +#define A_INHERITS 6 +#define A_ARGUMENT_TYPES 7 +#define A_ARGUMENT_INDEX 8 +#define A_INCLUDES 9 #define A_RELOC 10 -#define A_FUNC_HASH 11 -#define A_CFUN 12 -#define NUMPAREAS 13 +#define A_FUNC_HASH 11 +#define A_CFUN 12 +#define NUMPAREAS 13 #define A_CASE_NUMBERS (NUMPAREAS + 0) #define A_CASE_STRINGS (NUMPAREAS + 1) -#define A_CASE_LABELS (NUMPAREAS + 2) +#define A_CASE_LABELS (NUMPAREAS + 2) #define A_STRTAB (NUMPAREAS + 3) -#define A_LABELS (NUMPAREAS + 4) -#define A_JUMPS (NUMPAREAS + 5) -#define NUMAREAS (NUMPAREAS + 6) +#define A_LABELS (NUMPAREAS + 4) +#define A_JUMPS (NUMPAREAS + 5) +#define NUMAREAS (NUMPAREAS + 6) #define A_NUM NUMAREAS #define S_HDR 0 @@ -153,19 +153,19 @@ struct lineno { struct program { - char *program; /* The binary instructions */ - char *name; /* Name of file that defined prog */ + char *program; /* The binary instructions */ + char *name; /* Name of file that defined prog */ struct program *next_all, *prev_all; /* pointers in the list of all - programs. */ + programs. */ struct lineno *line_numbers; /* Line number information - This is not stored in memory - but swapped in when needed. - */ + This is not stored in memory + but swapped in when needed. + */ struct function *functions; struct function_hash *func_hash; - char *rodata; /* All strings uses by the program */ - struct variable *variable_names; /* All variables defined */ - struct inherit *inherit; /* List of inherited prgms */ + char *rodata; /* All strings uses by the program */ + struct variable *variable_names; /* All variables defined */ + struct inherit *inherit; /* List of inherited prgms */ struct cfun_desc *cfuns; /* * The types of function arguments are saved where 'argument_types' @@ -178,36 +178,36 @@ struct program { * that depends on the type length (16 bits) of 'type_start' (sorry !). */ unsigned short *argument_types; -#define INDEX_START_NONE 65535 +#define INDEX_START_NONE 65535 unsigned short *type_start; char *include_files; struct object *clones; #if defined(PROFILE_LPC) - double cpu; /* The amount of cpu taken up */ + double cpu; /* The amount of cpu taken up */ double cpu_avg; double last_avg_update; #endif - int ref; /* Reference count */ + int ref; /* Reference count */ int swap_num; long num_clones; unsigned int time_of_ref; #ifdef DEBUG - int extra_ref; /* Used to verify ref count */ + int extra_ref; /* Used to verify ref count */ #endif - offset_t total_size; /* Sum of all data in this struct */ + offset_t total_size; /* Sum of all data in this struct */ offset_t debug_size; offset_t exec_size; int load_time; /* Time of loding of the program */ - int id_number; /* used to associate information with - this prog block without needing to - increase the reference count */ - int swap_lineno_index; /* Index in swapfile for lineno info */ + int id_number; /* used to associate information with + this prog block without needing to + increase the reference count */ + int swap_lineno_index; /* Index in swapfile for lineno info */ int mod_time; /* (simulate.c) last time of modification of the */ - /* corrseponding file /lib_entry */ + /* corrseponding file /lib_entry */ unsigned short dtor_index; /* destructor */ unsigned short ctor_index; /* constructor */ @@ -218,7 +218,7 @@ struct program { */ /* SEC_EXE */ - offset_t program_size; /* size of this instruction code */ + offset_t program_size; /* size of this instruction code */ offset_t rodata_size; offset_t num_functions; offset_t num_variables; @@ -235,10 +235,10 @@ struct program { char flags; /* some useful flags */ -#define PRAGMA_NO_CLONE 1 -#define PRAGMA_NO_INHERIT 2 -#define PRAGMA_NO_SHADOW 4 -#define PRAGMA_RESIDENT 8 +#define PRAGMA_NO_CLONE 1 +#define PRAGMA_NO_INHERIT 2 +#define PRAGMA_NO_SHADOW 4 +#define PRAGMA_RESIDENT 8 }; extern struct program *current_prog; @@ -250,27 +250,27 @@ extern int inh_offset; * the run-time types, named T_ interpret.h. */ -#define TYPE_UNKNOWN 0 /* This type must be casted */ -#define TYPE_NUMBER 1 -#define TYPE_STRING 2 -#define TYPE_VOID 3 -#define TYPE_OBJECT 4 -#define TYPE_ANY 5 /* Will match any type */ -#define TYPE_MAPPING 6 +#define TYPE_UNKNOWN 0 /* This type must be casted */ +#define TYPE_NUMBER 1 +#define TYPE_STRING 2 +#define TYPE_VOID 3 +#define TYPE_OBJECT 4 +#define TYPE_ANY 5 /* Will match any type */ +#define TYPE_MAPPING 6 #define TYPE_FLOAT 7 -#define TYPE_FUNCTION 8 -#define TYPE_NONE 9 +#define TYPE_FUNCTION 8 +#define TYPE_NONE 9 -#define TYPE_LVALUE 0x10 /* or'ed in temporarily */ +#define TYPE_LVALUE 0x10 /* or'ed in temporarily */ /* * These are or'ed in on top of the basic type. */ -#define TYPE_MOD_STATIC 0x0100 /* Static function or variable */ -#define TYPE_MOD_NO_MASK 0x0200 /* The nomask => not redefineable */ -#define TYPE_MOD_POINTER 0x0400 /* Pointer to a basic type */ -#define TYPE_MOD_PRIVATE 0x0800 /* Can't be inherited */ -#define TYPE_MOD_PUBLIC 0x1000 /* Force inherit through private */ -#define TYPE_MOD_VARARGS 0x2000 /* Used for type checking */ +#define TYPE_MOD_STATIC 0x0100 /* Static function or variable */ +#define TYPE_MOD_NO_MASK 0x0200 /* The nomask => not redefineable */ +#define TYPE_MOD_POINTER 0x0400 /* Pointer to a basic type */ +#define TYPE_MOD_PRIVATE 0x0800 /* Can't be inherited */ +#define TYPE_MOD_PUBLIC 0x1000 /* Force inherit through private */ +#define TYPE_MOD_VARARGS 0x2000 /* Used for type checking */ #define TYPE_MOD_TRUE_VARARGS 0x4000 /* The new true varargs */ #define TYPE_MOD_SECOND 0x0080 /* Muliple inheritance (only valid for inherit) */ @@ -291,13 +291,13 @@ extern int inh_offset; #define NAME_PROTOTYPE 0x20 /* Defined by a prototype only */ #define NAME_ABSTRACT 0x40 /* Function is implemented in C */ -#define TYPE_MASK (~(TYPE_MOD_STATIC | TYPE_MOD_NO_MASK |\ - TYPE_MOD_PRIVATE | TYPE_MOD_PUBLIC |\ - TYPE_MOD_VARARGS | TYPE_MOD_TRUE_VARARGS |\ - NAME_ABSTRACT | NAME_STRICT_TYPES |\ - NAME_PROTOTYPE)) +#define TYPE_MASK (~(TYPE_MOD_STATIC | TYPE_MOD_NO_MASK |\ + TYPE_MOD_PRIVATE | TYPE_MOD_PUBLIC |\ + TYPE_MOD_VARARGS | TYPE_MOD_TRUE_VARARGS |\ + NAME_ABSTRACT | NAME_STRICT_TYPES |\ + NAME_PROTOTYPE)) #define TYPE_MOD_MASK (TYPE_MOD_STATIC | TYPE_MOD_NO_MASK |\ TYPE_MOD_PRIVATE | TYPE_MOD_PUBLIC |\ - TYPE_MOD_VARARGS | TYPE_MOD_TRUE_VARARGS) + TYPE_MOD_VARARGS | TYPE_MOD_TRUE_VARARGS) -#endif \ No newline at end of file +#endif diff --git a/func_spec.c b/func_spec.c index 9efe288..ab75fab 100644 --- a/func_spec.c +++ b/func_spec.c @@ -10,162 +10,162 @@ #include "config.h" -mixed abs(float|int); -float acos(float); -float acosh(float); -void add_action(string|function, string, void|int); -object *all_inventory(object default: F_THIS_OBJECT); -mixed *allocate(int); -float asin(float); -float asinh(float); -float atan(float); -float atan2(float, float); -float atanh(float); -string break_string(int|string, int, void|int|string); -mixed call_other(mapping|object|string|int|object *, string, ...); -mixed call_otherv(mapping|object|string|int|object *, string, mixed *); +mixed abs(float|int); +float acos(float); +float acosh(float); +void add_action(string|function, string, void|int); +object *all_inventory(object default: F_THIS_OBJECT); +mixed *allocate(int); +float asin(float); +float asinh(float); +float atan(float); +float atan2(float, float); +float atanh(float); +string break_string(int|string, int, void|int|string); +mixed call_other(mapping|object|string|int|object *, string, ...); +mixed call_otherv(mapping|object|string|int|object *, string, mixed *); mixed call_self(string, ...); mixed call_selfv(string, mixed *); string calling_function(int default: F_CONST0); object calling_object(int default: F_CONST0); string calling_program(int default: F_CONST0); -string capitalize(string|int); -string clear_bit(string, int); -object clone_object(string); -int command(string); +string capitalize(string|int); +string clear_bit(string, int); +object clone_object(string); +int command(string); mixed *commands(object|int default: F_THIS_OBJECT); -float cos(float); -float cosh(float); -string crypt(string, string|int, void|int); -string ctime(int default: F_TIME); -mixed debug(string, ...); -object *deep_inventory(int|object default: F_THIS_OBJECT); -void destruct(); -void disable_commands(); -void ed(void|string, void|string|function); -void enable_commands(void); -object environment(object default: F_THIS_OBJECT); -int exec(object|int, object); -float exp(float); -string *explode(string, string); -string extract(string, void|int, void|int); -float fact(float); -string file_name(object default: F_THIS_OBJECT); -int file_size(string); -int file_time(string); -mixed *filter(int|mapping|mixed *, string|function, void|object|string, void|mixed); -mixed find_living(string, void|int); -object find_object(string); -object find_player(string); +float cos(float); +float cosh(float); +string crypt(string, string|int, void|int); +string ctime(int default: F_TIME); +mixed debug(string, ...); +object *deep_inventory(int|object default: F_THIS_OBJECT); +void destruct(); +void disable_commands(); +void ed(void|string, void|string|function); +void enable_commands(void); +object environment(object default: F_THIS_OBJECT); +int exec(object|int, object); +float exp(float); +string *explode(string, string); +string extract(string, void|int, void|int); +float fact(float); +string file_name(object default: F_THIS_OBJECT); +int file_size(string); +int file_time(string); +mixed *filter(int|mapping|mixed *, string|function, void|object|string, void|mixed); +mixed find_living(string, void|int); +object find_object(string); +object find_player(string); int floatp(mixed); -string ftoa(float); -int ftoi(float); -string function_exists(string, object default: F_THIS_OBJECT); -string function_name(function); -object function_object(function); -int functionp(mixed); -float gettimeofday(); +string ftoa(float); +int ftoi(float); +string function_exists(string, object default: F_THIS_OBJECT); +string function_name(function); +object function_object(function); +int functionp(mixed); +float gettimeofday(); mixed *get_alarm(int); mixed *get_all_alarms(); -string *get_dir(string); -string implode(int|string *, string); -void input_to(string|function, ...); -int intp(mixed); -float itof(int); +string *get_dir(string); +string implode(int|string *, string); +void input_to(string|function, ...); +int intp(mixed); +float itof(int); int last_reference_time(); -int living(object|int); -float log(float); -string lower_case(int|string); -mapping m_delete(int|mapping, mixed); -void m_delkey(mapping, mixed); -mixed *m_indexes(int|mapping); +int living(object|int); +float log(float); +string lower_case(int|string); +mapping m_delete(int|mapping, mixed); +void m_delkey(mapping, mixed); +mixed *m_indexes(int|mapping); void m_restore_object(mapping); mapping m_save_object(); -int m_sizeof(int|mapping); -mixed *m_values(int|mapping); -mixed *map(int|mapping|mixed *, string|function, void|object|string, void|mixed); -int mappingp(mixed); -mixed match_path(mapping, string); -mixed max(int|string|float, ...); -int member_array(mixed, int|mixed *); -mixed min(int|string|float, ...); -int mkdir(string); +int m_sizeof(int|mapping); +mixed *m_values(int|mapping); +mixed *map(int|mapping|mixed *, string|function, void|object|string, void|mixed); +int mappingp(mixed); +mixed match_path(mapping, string); +mixed max(int|string|float, ...); +int member_array(mixed, int|mixed *); +mixed min(int|string|float, ...); +int mkdir(string); function mkfunction(string, object default: F_THIS_OBJECT); -mapping mkmapping(int|mixed *, int|mixed *); -void move_object(object|string); -int notify_fail(string, void|int); -float nrnd(void|float, void|float); +mapping mkmapping(int|mixed *, int|mixed *); +void move_object(object|string); +int notify_fail(string, void|int); +float nrnd(void|float, void|float); object *object_clones(object); -int object_time(object default: F_THIS_OBJECT); -int objectp(mixed); -void obsolete(string); +int object_time(object default: F_THIS_OBJECT); +int objectp(mixed); +void obsolete(string); function papplyv(function, mixed *); -int pointerp(mixed); -float pow(float, float); -object present(int|object|string, object *|object default: F_THIS_OBJECT); -object previous_object(int default: F_CONST0); -string process_string(string, int default: F_CONST0); -mixed process_value(string, int default: F_CONST0); -mixed query_auth(object); -string query_host_name(); -int query_idle(object); -int query_interactive(object|int); +int pointerp(mixed); +float pow(float, float); +object present(int|object|string, object *|object default: F_THIS_OBJECT); +object previous_object(int default: F_CONST0); +string process_string(string, int default: F_CONST0); +mixed process_value(string, int default: F_CONST0); +mixed query_auth(object); +string query_host_name(); +int query_idle(object); +int query_interactive(object|int); string query_ip_ident(object default: F_THIS_OBJECT); -string query_ip_name(void|object); -string query_ip_number(void|object); +string query_ip_name(void|object); +string query_ip_number(void|object); int query_remote_port(void|object); -string query_living_name(object); -object query_snoop(object); -string query_trigverb(); -string query_verb(); -int random(int, void|int); -string read_bytes(string, void|int, void|int); -string read_file(string, void|int, void|int); +string query_living_name(object); +object query_snoop(object); +string query_trigverb(); +string query_verb(); +int random(int, void|int); +string read_bytes(string, void|int, void|int); +string read_file(string, void|int, void|int); string readable_string(string); mixed reduce(function, mixed, void|mixed); -string *regexp(string *, string); +string *regexp(string *, string); void remove_alarm(int); -int rename(string, string); -mapping restore_map(string); -int restore_object(string); -int rm(string); -int rmdir(string); -float rnd(void|int); -void save_map(mapping, string); -void save_object(string); +int rename(string, string); +mapping restore_map(string); +int restore_object(string); +int rm(string); +int rmdir(string); +float rnd(void|int); +void save_map(mapping, string); +void save_object(string); int set_alarm(float, float, string|function, ...); int set_alarmv(float, float, string, mixed *); -void set_auth(object,mixed); -string set_bit(string, int); -void set_living_name(string); -void set_this_player(int|object default: F_THIS_OBJECT); -object shadow(object, int); -float sin(float); -float sinh(float); -int sizeof(int|mixed *); -object snoop(void|object, void|object); -string sprintf(string, ...); -float sqrt(float); +void set_auth(object,mixed); +string set_bit(string, int); +void set_living_name(string); +void set_this_player(int|object default: F_THIS_OBJECT); +object shadow(object, int); +float sin(float); +float sinh(float); +int sizeof(int|mixed *); +object snoop(void|object, void|object); +string sprintf(string, ...); +float sqrt(float); mixed str2val(string); -int stringp(mixed); -int strlen(int|string); -void tail(string); -float tan(float); -float tanh(float); -int test_bit(string, int); -object this_interactive(); -object this_object(); -object this_player(); -int time(); -int typeof(mixed); -mixed *unique_array(int|mixed *, string|function, void|mixed); -void update_actions(object default: F_THIS_OBJECT); -string upper_case(int|string); -object *users(); +int stringp(mixed); +int strlen(int|string); +void tail(string); +float tan(float); +float tanh(float); +int test_bit(string, int); +object this_interactive(); +object this_object(); +object this_player(); +int time(); +int typeof(mixed); +mixed *unique_array(int|mixed *, string|function, void|mixed); +void update_actions(object default: F_THIS_OBJECT); +string upper_case(int|string); +object *users(); string val2str(mixed); -int wildmatch(string, string|int); -int write_bytes(string, int, string); -int write_file(string, string); +int wildmatch(string, string|int); +int write_bytes(string, int, string); +int write_file(string, string); void write_socket(string|int); void write_socket_gmcp(string, mixed); string val2json(mixed); diff --git a/genfkntab.c b/genfkntab.c index 5c73788..b40b30a 100644 --- a/genfkntab.c +++ b/genfkntab.c @@ -13,12 +13,12 @@ main(int argc, char **argv) char *fname; FILE *header_file, *data_file; if (argc < 3) - exit(1); + exit(1); prefix = argv[1]; fname = argv[2]; for (j = 0; prefix[j]; j++) - prefix[j] = toupper(prefix[j]); + prefix[j] = toupper(prefix[j]); (void)sprintf(name, "%s.h", fname); header_file = fopen(name, "w"); @@ -28,33 +28,33 @@ main(int argc, char **argv) (void)fprintf(data_file, "static struct fkntab %s_fkntab[] =\n{\n", fname); for ((void)fgets(name, sizeof(name), stdin); - !feof(stdin); - (void)fgets(name, sizeof(name), stdin)) + !feof(stdin); + (void)fgets(name, sizeof(name), stdin)) { - if ((func_name = strchr(name, '\n')) != NULL) - *func_name = '\0'; - if (!*name || *name == '#') - continue; - func_name = name; - for (j = 0; name[j]; j++) - { - if (name[j] == '\t' || - name[j] == ' ') - { - name[j] = '\0'; - j++; - while (name[j] || name[j] == ' ' || name[j] == '\t') - j++; - if (name[j]) - func_name = &name[j]; - break; - } - } - - (void)fprintf(data_file, " {\"%s\", 0, 0},\n", func_name); - for (j = 0; name[j]; j++) - name[j] = toupper(name[j]); - (void)fprintf(header_file, "#define %s_%s %d\n", prefix, name, i++); + if ((func_name = strchr(name, '\n')) != NULL) + *func_name = '\0'; + if (!*name || *name == '#') + continue; + func_name = name; + for (j = 0; name[j]; j++) + { + if (name[j] == '\t' || + name[j] == ' ') + { + name[j] = '\0'; + j++; + while (name[j] || name[j] == ' ' || name[j] == '\t') + j++; + if (name[j]) + func_name = &name[j]; + break; + } + } + + (void)fprintf(data_file, " {\"%s\", 0, 0},\n", func_name); + for (j = 0; name[j]; j++) + name[j] = toupper(name[j]); + (void)fprintf(header_file, "#define %s_%s %d\n", prefix, name, i++); } (void)fputs(" {NULL, 0, 0}\n};\n", data_file); diff --git a/hname.c b/hname.c index aef53ec..2d03a4d 100644 --- a/hname.c +++ b/hname.c @@ -47,11 +47,11 @@ #include "backend.h" #ifndef INADDR_LOOPBACK -#define INADDR_LOOPBACK 0x7f000001 +#define INADDR_LOOPBACK 0x7f000001 #endif #ifndef INADDR_NONE -#define INADDR_NONE 0xffffffff +#define INADDR_NONE 0xffffffff #endif #ifndef EPROTO @@ -69,10 +69,10 @@ */ typedef struct { - u_char h_flags; - nqueue_t * h_rawq; - nqueue_t * h_canq; - nqueue_t * h_outq; + u_char h_flags; + nqueue_t * h_rawq; + nqueue_t * h_canq; + nqueue_t * h_outq; ndesc_t * h_nd; struct task *task; hname_callback_t callback; @@ -83,15 +83,15 @@ typedef struct { /* * Hostname Server Flags. */ -#define HF_CLOSE 0x01 -#define HF_ENABW 0x04 +#define HF_CLOSE 0x01 +#define HF_ENABW 0x04 #define HF_INPUT 0x08 /* * Queue Sizes. */ -#define HNAME_RAWQ_SIZE 128 -#define HNAME_CANQ_SIZE 128 -#define HNAME_OUTQ_SIZE 128 +#define HNAME_RAWQ_SIZE 128 +#define HNAME_CANQ_SIZE 128 +#define HNAME_OUTQ_SIZE 128 /* @@ -135,7 +135,7 @@ hname_input(hname_t *hp) char *addr, *rname, *ip_name, *cp, *end; if ((hp->h_flags & HF_INPUT) == 0) - return; + return; hp->h_flags &= ~HF_INPUT; cp = (char *)nq_rptr(hp->h_canq); @@ -176,45 +176,45 @@ hname_readbytes(hname_t *hp) if (!nq_full(hp->h_rawq)) { - cc = nq_recv(hp->h_rawq, nd_fd(hp->h_nd), NULL); - if (cc == -1) - { - switch (errno) - { - case EWOULDBLOCK: - case EINTR: - case EPROTO: - break; - - default: - hp->h_flags |= HF_CLOSE; - } - return; - } - if (cc == 0) - { - hp->h_flags |= HF_CLOSE; - return; - } + cc = nq_recv(hp->h_rawq, nd_fd(hp->h_nd), NULL); + if (cc == -1) + { + switch (errno) + { + case EWOULDBLOCK: + case EINTR: + case EPROTO: + break; + + default: + hp->h_flags |= HF_CLOSE; + } + return; + } + if (cc == 0) + { + hp->h_flags |= HF_CLOSE; + return; + } } for (;;) { - if (nq_empty(hp->h_rawq)) - { - nq_init(hp->h_rawq); - return; - } - c = nq_getc(hp->h_rawq); - if (c == '\n') { - break; - } - - if (!nq_full(hp->h_canq)) - nq_putc(hp->h_canq, c); + if (nq_empty(hp->h_rawq)) + { + nq_init(hp->h_rawq); + return; + } + c = nq_getc(hp->h_rawq); + if (c == '\n') { + break; + } + + if (!nq_full(hp->h_canq)) + nq_putc(hp->h_canq, c); } if (nq_full(hp->h_canq)) - nq_unputc(hp->h_canq); + nq_unputc(hp->h_canq); nq_putc(hp->h_canq, '\0'); hp->h_flags |= HF_INPUT; } @@ -228,7 +228,7 @@ hname_shutdown(hname_t *hp) nd_detach(hp->h_nd); hp->h_nd = 0; if (hp->shutdown_callback) - hp->shutdown_callback(hp); + hp->shutdown_callback(hp); hname_free(hp); } @@ -240,20 +240,20 @@ hname_readline(void *vp) if (hp->h_flags & HF_CLOSE) { - hname_shutdown(hp); - return; + hname_shutdown(hp); + return; } hname_input(hp); hname_readbytes(hp); if (hp->h_flags & HF_CLOSE) { - hname_shutdown(hp); - return; + hname_shutdown(hp); + return; } if (hp->h_flags & HF_INPUT) { - reschedule_task(hp->task); - nd_disable(hp->h_nd, ND_R); - return; + reschedule_task(hp->task); + nd_disable(hp->h_nd, ND_R); + return; } hp->task = NULL; nd_enable(hp->h_nd, ND_R); @@ -267,7 +267,7 @@ hname_disconnect(ndesc_t *nd, hname_t *hp) { hp->h_flags |= HF_CLOSE; if (!hp->task) - hp->task = create_task(hname_readline, hp); + hp->task = create_task(hname_readline, hp); } /* @@ -292,10 +292,10 @@ hname_write(ndesc_t *nd, hname_t *hp) nd_disable(nd, ND_W); return; } - } + } - if (!nq_empty(hp->h_outq)) - return; + if (!nq_empty(hp->h_outq)) + return; } nq_init(hp->h_outq); @@ -312,9 +312,9 @@ hname_read(ndesc_t *nd, hname_t *hp) { hname_readbytes(hp); if (hp->h_flags & (HF_INPUT | HF_CLOSE)) { - if (!hp->task) - hp->task = create_task(hname_readline, hp); - nd_disable(nd, ND_R); + if (!hp->task) + hp->task = create_task(hname_readline, hp); + nd_disable(nd, ND_R); } } @@ -330,31 +330,31 @@ hname_init(hname_callback_t callback, void (*shutdown_callback)(void *)) int sockets[2]; if(socketpair(AF_LOCAL, SOCK_STREAM, 0, sockets) == -1) - return NULL; + return NULL; pid = fork(); if (pid == -1) { - (void)close(sockets[0]); - (void)close(sockets[1]); - return NULL; + (void)close(sockets[0]); + (void)close(sockets[1]); + return NULL; } if (pid == 0) { - close(sockets[0]); - dup2(sockets[1], 0); - dup2(sockets[1], 1); + close(sockets[0]); + dup2(sockets[1], 0); + dup2(sockets[1], 1); - for (int i = 3; i < FD_SETSIZE; i++) - (void)close(i); + for (int i = 3; i < FD_SETSIZE; i++) + (void)close(i); snprintf(path, sizeof(path), "%s/hname", BINDIR); execl(path, "hname", NULL); fprintf(stderr, "exec of hname failed.\n"); - exit(1); + exit(1); } enable_nbio(sockets[0]); @@ -377,12 +377,12 @@ hname_sendreq(void *vp, const char *addr, u_short lport, u_short rport) hname_t *hp = vp; if (hp == NULL || hp->h_nd == NULL) - return; + return; snprintf(req, sizeof(req), "%s,%hu,%hu\n", addr, lport, rport); if (nq_avail(hp->h_outq) < strlen(req)) - return; + return; nq_puts(hp->h_outq, (u_char *)req); nd_enable(hp->h_nd, ND_W); diff --git a/hname.h b/hname.h index f6ef13f..4ffa6b2 100644 --- a/hname.h +++ b/hname.h @@ -30,7 +30,7 @@ */ typedef void (*hname_callback_t)(const char *addr, int lport, int rport, - const char *ip_name, const char *rname); + const char *ip_name, const char *rname); void *hname_init(hname_callback_t, void (*)(void *)); void hname_sendreq(void *, const char *addr, u_short lport, u_short rport); diff --git a/incralloc.h b/incralloc.h index d591a62..fcf0dd5 100644 --- a/incralloc.h +++ b/incralloc.h @@ -11,4 +11,4 @@ struct mem_block { int max_size; }; -#define START_BLOCK_SIZE 4096 +#define START_BLOCK_SIZE 4096 diff --git a/inline_eqs.h b/inline_eqs.h index 3703017..e322d25 100644 --- a/inline_eqs.h +++ b/inline_eqs.h @@ -5,36 +5,36 @@ static __inline__ int equal_svalue(const struct svalue *sval1, const struct svalue *sval2) { if (sval1->type == T_NUMBER && sval1->u.number == 0 && - sval2->type == T_OBJECT && sval2->u.ob->flags & O_DESTRUCTED) - return 1; + sval2->type == T_OBJECT && sval2->u.ob->flags & O_DESTRUCTED) + return 1; else if (sval2->type == T_NUMBER && sval2->u.number == 0 && - sval1->type == T_OBJECT && sval1->u.ob->flags & O_DESTRUCTED) - return 1; + sval1->type == T_OBJECT && sval1->u.ob->flags & O_DESTRUCTED) + return 1; else if (sval1->type == T_NUMBER && sval1->u.number == 0 && - sval2->type == T_FUNCTION && !legal_closure(sval2->u.func)) - return 1; + sval2->type == T_FUNCTION && !legal_closure(sval2->u.func)) + return 1; else if (sval2->type == T_NUMBER && sval2->u.number == 0 && - sval1->type == T_FUNCTION && !legal_closure(sval1->u.func)) - return 1; + sval1->type == T_FUNCTION && !legal_closure(sval1->u.func)) + return 1; else if (sval1->type != sval2->type) - return 0; + return 0; else switch (sval1->type) { - case T_NUMBER: - return sval1->u.number == sval2->u.number; - case T_POINTER: - return sval1->u.vec == sval2->u.vec; - case T_MAPPING: - return sval1->u.map == sval2->u.map; - case T_STRING: - return sval1->u.string == sval2->u.string || - strcmp(sval1->u.string, sval2->u.string) == 0; - case T_OBJECT: - return ((sval1->u.ob->flags & O_DESTRUCTED) && (sval2->u.ob->flags & O_DESTRUCTED)) || - sval1->u.ob == sval2->u.ob; - case T_FLOAT: - return sval1->u.real == sval2->u.real; - case T_FUNCTION: - return sval1->u.func == sval2->u.func; + case T_NUMBER: + return sval1->u.number == sval2->u.number; + case T_POINTER: + return sval1->u.vec == sval2->u.vec; + case T_MAPPING: + return sval1->u.map == sval2->u.map; + case T_STRING: + return sval1->u.string == sval2->u.string || + strcmp(sval1->u.string, sval2->u.string) == 0; + case T_OBJECT: + return ((sval1->u.ob->flags & O_DESTRUCTED) && (sval2->u.ob->flags & O_DESTRUCTED)) || + sval1->u.ob == sval2->u.ob; + case T_FLOAT: + return sval1->u.real == sval2->u.real; + case T_FUNCTION: + return sval1->u.func == sval2->u.func; } return 0; } diff --git a/inline_svalue.h b/inline_svalue.h index 29e6ac3..aa1e9e8 100644 --- a/inline_svalue.h +++ b/inline_svalue.h @@ -5,38 +5,38 @@ static __inline__ void free_svalue(struct svalue *v) { if (v->type & T_LVALUE) - return; + return; switch (v->type) { - case T_NUMBER: - case T_FLOAT: - break; - case T_STRING: - switch (v->string_type) { - case STRING_MSTRING: - free_mstring(v->u.string); - break; - case STRING_SSTRING: - free_sstring(v->u.string); - break; - case STRING_CSTRING: - break; - } - break; - case T_OBJECT: - free_object(v->u.ob, "free_svalue"); - break; - case T_POINTER: - free_vector(v->u.vec); - break; - case T_MAPPING: - free_mapping(v->u.map); - break; - case T_FUNCTION: - free_closure(v->u.func); - break; - default: - fatal("Invalid value of variable!\n"); - break; + case T_NUMBER: + case T_FLOAT: + break; + case T_STRING: + switch (v->string_type) { + case STRING_MSTRING: + free_mstring(v->u.string); + break; + case STRING_SSTRING: + free_sstring(v->u.string); + break; + case STRING_CSTRING: + break; + } + break; + case T_OBJECT: + free_object(v->u.ob, "free_svalue"); + break; + case T_POINTER: + free_vector(v->u.vec); + break; + case T_MAPPING: + free_mapping(v->u.map); + break; + case T_FUNCTION: + free_closure(v->u.func); + break; + default: + fatal("Invalid value of variable!\n"); + break; } *v = const0; /* marion - clear this value all away */ } diff --git a/instrs.h b/instrs.h index 27fb7bc..62fca85 100644 --- a/instrs.h +++ b/instrs.h @@ -5,7 +5,7 @@ */ struct instr { - short max_arg, min_arg; /* Can't use char to represent -1 */ + short max_arg, min_arg; /* Can't use char to represent -1 */ char type[2]; short Default; short ret_type; diff --git a/interface.c b/interface.c index 91a150c..885b503 100644 --- a/interface.c +++ b/interface.c @@ -24,10 +24,10 @@ get_C_fun_address(char *prog_name, char *name))(struct svalue *) { int i, j; for(i = 0; interface[i]; i++) - if (strcmp(interface[i]->program, prog_name) == 0) - for(j = 0; interface[i]->funcs[j]; j++) - if (strcmp(interface[i]->funcs[j]->name, name) == 0) - return interface[i]->funcs[j]->address; + if (strcmp(interface[i]->program, prog_name) == 0) + for(j = 0; interface[i]->funcs[j]; j++) + if (strcmp(interface[i]->funcs[j]->name, name) == 0) + return interface[i]->funcs[j]->address; return (void (*)(struct svalue *))0; } @@ -38,6 +38,6 @@ init_cfuns() int i,j; for(i = 0; interface[i]; i++) - for(j = 0; interface[i]->vars[j]; j++) - interface[i]->vars[j]->num = j; + for(j = 0; interface[i]->vars[j]; j++) + interface[i]->vars[j]->num = j; } diff --git a/interface.h b/interface.h index 167a53c..0ac31ac 100644 --- a/interface.h +++ b/interface.h @@ -3,10 +3,10 @@ #include "interpret.h" #define VAR(i) (current_object->variables[\ - current_object->prog->inherit[inh_offset +\ - current_prog->cfuns[(i).num].inh].\ - variable_index_offset +\ - current_prog->cfuns[(i).num].idx]) + current_object->prog->inherit[inh_offset +\ + current_prog->cfuns[(i).num].inh].\ + variable_index_offset +\ + current_prog->cfuns[(i).num].idx]) typedef struct var_info { diff --git a/interpret.c b/interpret.c index b51fa33..fecc4f4 100644 --- a/interpret.c +++ b/interpret.c @@ -5,7 +5,7 @@ #include #include #include -#include /* sys/types.h and netinet/in.h are here to enable include of comm.h below */ +#include /* sys/types.h and netinet/in.h are here to enable include of comm.h below */ #include /* #include Included in comm.h below */ #include @@ -116,7 +116,7 @@ static int tracedepth; (current_interactive && current_interactive->interactive && TRACETST(b) && \ (current_interactive->interactive->trace_prefix == 0 || \ (current_object && strpref(current_interactive->interactive->trace_prefix, \ - current_object->name))) ) + current_object->name))) ) /* * Inheritance: @@ -141,16 +141,16 @@ extern int current_line, eval_cost; * will return. That means that control_stack[0] will have almost no * interesting values, as it will terminate execution. */ -char *pc; /* Program pointer. */ -static struct svalue *fp; /* Pointer to first argument. */ -struct svalue *sp; /* Points to value of last push. */ -int inh_offset; /* Needed for inheritance */ +char *pc; /* Program pointer. */ +static struct svalue *fp; /* Pointer to first argument. */ +struct svalue *sp; /* Points to value of last push. */ +int inh_offset; /* Needed for inheritance */ struct svalue start_of_stack[EVALUATOR_STACK_SIZE]; -struct svalue catch_value; /* Used to throw an error to a catch */ +struct svalue catch_value; /* Used to throw an error to a catch */ static struct control_stack control_stack[MAX_TRACE]; -struct control_stack *csp; /* Points to last element pushed */ +struct control_stack *csp; /* Points to last element pushed */ #ifdef COUNT_CALLS /* Temporary */ static int num_call_self, num_call_down, num_call_other; @@ -158,12 +158,12 @@ static int num_call_self, num_call_down, num_call_other; /* These are set by search_for_function if it is successful * function_inherit_found == num_inherit if in top program - * function_prog_found == Implied by inherit_found + * function_prog_found == Implied by inherit_found */ -int function_inherit_found = -1; -struct program *function_prog_found = 0; -int function_index_found = -1; -unsigned short function_type_mod_found = 0; +int function_inherit_found = -1; +struct program *function_prog_found = 0; +int function_index_found = -1; +unsigned short function_type_mod_found = 0; /* * Information about assignments of values: @@ -190,7 +190,7 @@ static INLINE void probe_stack(int n) { if (sp + n >= &start_of_stack[EVALUATOR_STACK_SIZE]) - error("stack overflow\n"); + error("stack overflow\n"); } /* @@ -214,13 +214,13 @@ push_object(struct object *ob) extend_stack(); if (ob != NULL && !(ob->flags & O_DESTRUCTED)) { - sp->type = T_OBJECT; - sp->u.ob = ob; - add_ref(ob, "push_object"); + sp->type = T_OBJECT; + sp->u.ob = ob; + add_ref(ob, "push_object"); } else { - *sp = const0; + *sp = const0; } } @@ -250,7 +250,7 @@ push_function(struct closure *func, bool_t reference) sp->type = T_FUNCTION; sp->u.func = func; if (reference) - INCREF(func->ref); + INCREF(func->ref); } /* @@ -263,15 +263,15 @@ push_string(char *p, int type) sp->type = T_STRING; sp->string_type = type; switch(type) { - case STRING_MSTRING: - sp->u.string = make_mstring(p); - break; - case STRING_SSTRING: - sp->u.string = make_sstring(p); - break; - case STRING_CSTRING: - sp->u.string = p; - break; + case STRING_MSTRING: + sp->u.string = make_mstring(p); + break; + case STRING_SSTRING: + sp->u.string = make_sstring(p); + break; + case STRING_CSTRING: + sp->u.string = p; + break; } } @@ -284,24 +284,24 @@ find_value(int inh, int rnum) int num; if ((inh == 255 && rnum == 255)) { - error("Referencing undefined variable (inh == %d, var_num == %d, variables are %s).\n", - inh, rnum, current_object->variables?"defined":"undefined"); + error("Referencing undefined variable (inh == %d, var_num == %d, variables are %s).\n", + inh, rnum, current_object->variables?"defined":"undefined"); } if (inh == 255) - inh = 0; + inh = 0; else - inh -= current_prog->num_inherited - 1; + inh -= current_prog->num_inherited - 1; #ifdef DEBUG if (inh > 0) - fatal("Illegal variable access, %d(off %d). See trace above.\n", - inh, current_prog->num_inherited); + fatal("Illegal variable access, %d(off %d). See trace above.\n", + inh, current_prog->num_inherited); if (rnum > current_object->prog->inherit[inh_offset + inh].prog->num_variables - 1) - fatal("Illegal variable access, variable %d(off %d, in %d). See trace above.\n", - rnum, current_object->prog->inherit[inh_offset + inh].prog->num_variables, - inh_offset + inh); + fatal("Illegal variable access, variable %d(off %d, in %d). See trace above.\n", + rnum, current_object->prog->inherit[inh_offset + inh].prog->num_variables, + inh_offset + inh); #endif num = current_object->prog-> - inherit[inh_offset + inh].variable_index_offset + rnum; + inherit[inh_offset + inh].variable_index_offset + rnum; return ¤t_object->variables[num]; } @@ -315,38 +315,38 @@ void free_svalue(struct svalue *v) { if (v->type & T_LVALUE) - return; + return; switch (v->type) { - case T_NUMBER: - case T_FLOAT: - break; - case T_STRING: - switch (v->string_type) { - case STRING_MSTRING: - free_mstring(v->u.string); - break; - case STRING_SSTRING: - free_sstring(v->u.string); - break; - case STRING_CSTRING: - break; - } - break; - case T_OBJECT: - free_object(v->u.ob, "free_svalue"); - break; - case T_POINTER: - free_vector(v->u.vec); - break; - case T_MAPPING: - free_mapping(v->u.map); - break; - case T_FUNCTION: - free_closure(v->u.func); - break; - default: - fatal("Invalid value of variable!\n"); - break; + case T_NUMBER: + case T_FLOAT: + break; + case T_STRING: + switch (v->string_type) { + case STRING_MSTRING: + free_mstring(v->u.string); + break; + case STRING_SSTRING: + free_sstring(v->u.string); + break; + case STRING_CSTRING: + break; + } + break; + case T_OBJECT: + free_object(v->u.ob, "free_svalue"); + break; + case T_POINTER: + free_vector(v->u.vec); + break; + case T_MAPPING: + free_mapping(v->u.map); + break; + case T_FUNCTION: + free_closure(v->u.func); + break; + default: + fatal("Invalid value of variable!\n"); + break; } *v = const0; /* marion - clear this value all away */ } @@ -355,36 +355,36 @@ int equal_svalue(const struct svalue *sval1, const struct svalue *sval2) { if (sval1->type == T_NUMBER && sval1->u.number == 0 && - sval2->type == T_OBJECT && sval2->u.ob->flags & O_DESTRUCTED) - return 1; + sval2->type == T_OBJECT && sval2->u.ob->flags & O_DESTRUCTED) + return 1; else if (sval2->type == T_NUMBER && sval2->u.number == 0 && - sval1->type == T_OBJECT && sval1->u.ob->flags & O_DESTRUCTED) - return 1; + sval1->type == T_OBJECT && sval1->u.ob->flags & O_DESTRUCTED) + return 1; else if (sval2->type == T_NUMBER && sval2->u.number == 0 && - sval1->type == T_FUNCTION && !legal_closure(sval1->u.func)) - return 1; + sval1->type == T_FUNCTION && !legal_closure(sval1->u.func)) + return 1; else if (sval2->type == T_NUMBER && sval2->u.number == 0 && - sval1->type == T_FUNCTION && !legal_closure(sval1->u.func)) - return 1; + sval1->type == T_FUNCTION && !legal_closure(sval1->u.func)) + return 1; else if (sval1->type != sval2->type) - return 0; + return 0; else switch (sval1->type) { - case T_NUMBER: - return sval1->u.number == sval2->u.number; - case T_POINTER: - return sval1->u.vec == sval2->u.vec; - case T_MAPPING: - return sval1->u.map == sval2->u.map; - case T_STRING: - return sval1->u.string == sval2->u.string || - strcmp(sval1->u.string, sval2->u.string) == 0; - case T_OBJECT: - return ((sval1->u.ob->flags & O_DESTRUCTED) && (sval2->u.ob->flags & O_DESTRUCTED)) || - sval1->u.ob == sval2->u.ob; - case T_FLOAT: - return sval1->u.real == sval2->u.real; - case T_FUNCTION: - return sval1->u.func == sval2->u.func; + case T_NUMBER: + return sval1->u.number == sval2->u.number; + case T_POINTER: + return sval1->u.vec == sval2->u.vec; + case T_MAPPING: + return sval1->u.map == sval2->u.map; + case T_STRING: + return sval1->u.string == sval2->u.string || + strcmp(sval1->u.string, sval2->u.string) == 0; + case T_OBJECT: + return ((sval1->u.ob->flags & O_DESTRUCTED) && (sval2->u.ob->flags & O_DESTRUCTED)) || + sval1->u.ob == sval2->u.ob; + case T_FLOAT: + return sval1->u.real == sval2->u.real; + case T_FUNCTION: + return sval1->u.func == sval2->u.func; } return 0; } @@ -423,40 +423,40 @@ INLINE void assign_svalue_no_free(struct svalue *to, struct svalue *from) { if (to == from) - return; + return; #ifdef DEBUG if (from == 0) - fatal("Null pointer to assign_svalue().\n"); + fatal("Null pointer to assign_svalue().\n"); #endif *to = *from; switch(from->type) { case T_STRING: - switch(from->string_type) { - case STRING_MSTRING: - (void)reference_mstring(from->u.string); - break; - case STRING_SSTRING: - (void)reference_sstring(from->u.string); - break; + switch(from->string_type) { + case STRING_MSTRING: + (void)reference_mstring(from->u.string); + break; + case STRING_SSTRING: + (void)reference_sstring(from->u.string); + break; case STRING_CSTRING: - break; - default: - fatal("Bad string type %d\n", from->string_type); - } - break; + break; + default: + fatal("Bad string type %d\n", from->string_type); + } + break; case T_OBJECT: - add_ref(to->u.ob, "ass to var"); - break; + add_ref(to->u.ob, "ass to var"); + break; case T_POINTER: - INCREF(to->u.vec->ref); - break; + INCREF(to->u.vec->ref); + break; case T_MAPPING: - INCREF(to->u.map->ref); - break; + INCREF(to->u.map->ref); + break; case T_FUNCTION: - INCREF(to->u.func->ref); - break; + INCREF(to->u.func->ref); + break; } } @@ -464,7 +464,7 @@ INLINE void assign_svalue(struct svalue *dest, struct svalue *v) { if (dest == v) - return; + return; /* First deallocate the previous value. */ free_svalue(dest); @@ -493,7 +493,7 @@ void pop_stack() { #ifdef DEBUG if (sp < start_of_stack) - fatal("Stack underflow.\n"); + fatal("Stack underflow.\n"); #endif free_svalue(sp--); } @@ -505,72 +505,72 @@ INLINE static void push_indexed_lvalue(int needlval) { struct svalue *i, *vec, *item; - long long ind = 0; /* = 0 to make Wall quiet */ + long long ind = 0; /* = 0 to make Wall quiet */ long long org_ind = 0; i = sp; vec = sp - 1; if (vec->type != T_MAPPING) { - if (i->type != T_NUMBER) - error("Illegal index.\n"); + if (i->type != T_NUMBER) + error("Illegal index.\n"); org_ind = ind = i->u.number; } switch(vec->type) { case T_STRING: { - static struct svalue one_character; - /* marion says: this is a crude part of code */ - pop_stack(); - one_character.type = T_NUMBER; + static struct svalue one_character; + /* marion says: this is a crude part of code */ + pop_stack(); + one_character.type = T_NUMBER; if (ind < 0) ind = strlen(vec->u.string) + ind; - if (ind > strlen(vec->u.string) || ind < 0) - one_character.u.number = 0; - else - one_character.u.number = vec->u.string[ind]; - free_svalue(sp); - sp->type = T_LVALUE; - sp->u.lvalue = &one_character; - break;} + if (ind > strlen(vec->u.string) || ind < 0) + one_character.u.number = 0; + else + one_character.u.number = vec->u.string[ind]; + free_svalue(sp); + sp->type = T_LVALUE; + sp->u.lvalue = &one_character; + break;} case T_POINTER: - pop_stack(); + pop_stack(); if (ind < 0) ind = vec->u.vec->size + ind; - if (ind >= vec->u.vec->size || ind < 0) - error("Index out of bounds. Vector size: %d, index: %lld\n", + if (ind >= vec->u.vec->size || ind < 0) + error("Index out of bounds. Vector size: %d, index: %lld\n", vec->u.vec->size, org_ind); - item = &vec->u.vec->item[ind]; - if (vec->u.vec->ref == 1) { - static struct svalue quickfix = { T_NUMBER }; - /* marion says: but this is crude too */ - /* marion blushes. */ - assign_svalue (&quickfix, item); - item = &quickfix; - } - - free_svalue(sp); /* This will make 'vec' invalid to use */ - sp->type = T_LVALUE; - sp->u.lvalue = item; - break; + item = &vec->u.vec->item[ind]; + if (vec->u.vec->ref == 1) { + static struct svalue quickfix = { T_NUMBER }; + /* marion says: but this is crude too */ + /* marion blushes. */ + assign_svalue (&quickfix, item); + item = &quickfix; + } + + free_svalue(sp); /* This will make 'vec' invalid to use */ + sp->type = T_LVALUE; + sp->u.lvalue = item; + break; case T_MAPPING: - item = get_map_lvalue(vec->u.map, i, needlval); - pop_stack(); - if (vec->u.map->ref == 1) { - static struct svalue quickfix = { T_NUMBER }; - assign_svalue (&quickfix, item); - item = &quickfix; - } - free_svalue(sp); /* This will make 'vec' invalid to use */ - sp->type = T_LVALUE; - sp->u.lvalue = item; - break; + item = get_map_lvalue(vec->u.map, i, needlval); + pop_stack(); + if (vec->u.map->ref == 1) { + static struct svalue quickfix = { T_NUMBER }; + assign_svalue (&quickfix, item); + item = &quickfix; + } + free_svalue(sp); /* This will make 'vec' invalid to use */ + sp->type = T_LVALUE; + sp->u.lvalue = item; + break; default: - error("Indexing on illegal type.\n"); - break; + error("Indexing on illegal type.\n"); + break; } } @@ -587,10 +587,10 @@ void pop_n_elems(int n) { #ifdef DEBUG if (n < 0) - fatal("pop_n_elems: %d elements.\n", n); + fatal("pop_n_elems: %d elements.\n", n); #endif for (; n > 0; n--) - pop_stack(); + pop_stack(); } char * @@ -600,19 +600,19 @@ get_typename(int type) switch(type) { case T_NUMBER: - return "Integer"; + return "Integer"; case T_STRING: - return "String"; + return "String"; case T_POINTER: - return "Array"; + return "Array"; case T_OBJECT: - return "Object"; + return "Object"; case T_MAPPING: - return "Mapping"; + return "Mapping"; case T_FLOAT: - return "Float"; + return "Float"; case T_FUNCTION: - return "Function"; + return "Function"; } return "Unknown"; @@ -642,8 +642,8 @@ get_profile_timebase() { void set_profile_timebase(long double timebase) { if (timebase > 0.0) { - profile_timebase = timebase; - profile_exp_mtimebase = -expm1l(-1.0l / timebase); + profile_timebase = timebase; + profile_exp_mtimebase = -expm1l(-1.0l / timebase); } } @@ -691,7 +691,7 @@ save_control_context(struct control_stack *csp1) { #ifdef DEBUG if (current_prog && pc - current_prog->program >= current_prog->program_size) { - fatal("Invalid offset during context save\n"); + fatal("Invalid offset during context save\n"); } #endif csp1->ob = current_object; @@ -701,10 +701,10 @@ save_control_context(struct control_stack *csp1) csp1->prog = current_prog; csp1->extern_call = 0; if (current_prog) - csp1->pc = pc - current_prog->program; + csp1->pc = pc - current_prog->program; #ifdef DEBUG else - csp1->pc = 0xdeadbeef; + csp1->pc = 0xdeadbeef; #endif csp1->inh_offset = inh_offset; } @@ -713,22 +713,22 @@ void push_control_stack(struct object *ob, struct program *prog, struct function *funp) { if (csp >= &control_stack[MAX_TRACE-1]) - error("Too deep recursion.\n"); + error("Too deep recursion.\n"); csp++; save_control_context(csp); - csp->funp = funp; /* Only used for tracebacks */ + csp->funp = funp; /* Only used for tracebacks */ #if defined(PROFILE_LPC) { - double now = current_cpu(); + double now = current_cpu(); if (trace_calls) { if (csp == control_stack) - fprintf(trace_calls_file, "%.3f %.6f\n", + fprintf(trace_calls_file, "%.3f %.6f\n", (now - last_execution) * 1000.0, now); fprintf(trace_calls_file, "%*s%s %s %s()\n", - (int)(csp - control_stack) * 4, "", - ob->name, prog->name, funp ? funp->name : "???"); + (int)(csp - control_stack) * 4, "", + ob->name, prog->name, funp ? funp->name : "???"); } if (csp != control_stack) { csp[-1].frame_cpu += now - csp[-1].startcpu; @@ -763,26 +763,26 @@ pop_control_stack() { #ifdef DEBUG if (csp == control_stack - 1) - fatal("Popped out of the control stack\n"); + fatal("Popped out of the control stack\n"); #endif #if defined(PROFILE_LPC) { - double now = current_cpu(); - double delta = csp->frame_cpu + (now - csp->startcpu); - double tot_delta = now - csp->frame_start; - if (current_prog) - update_prog_profile(current_prog, now, delta, tot_delta); - if (csp->funp) - update_func_profile(csp->funp, now, delta, tot_delta, 1); - if (csp != control_stack) { - csp[-1].startcpu = now; - } else - last_execution = now; - if (trace_calls) { - fprintf(trace_calls_file, "%*s--- %.3f / %.3f\n", - (int)(csp - control_stack) * 4, "", - delta * 1000.0, - tot_delta * 1000.0); + double now = current_cpu(); + double delta = csp->frame_cpu + (now - csp->startcpu); + double tot_delta = now - csp->frame_start; + if (current_prog) + update_prog_profile(current_prog, now, delta, tot_delta); + if (csp->funp) + update_func_profile(csp->funp, now, delta, tot_delta, 1); + if (csp != control_stack) { + csp[-1].startcpu = now; + } else + last_execution = now; + if (trace_calls) { + fprintf(trace_calls_file, "%*s--- %.3f / %.3f\n", + (int)(csp - control_stack) * 4, "", + delta * 1000.0, + tot_delta * 1000.0); if (csp == control_stack) putc('\n', trace_calls_file); } @@ -802,7 +802,7 @@ push_vector(struct vector *v, bool_t reference) { extend_stack(); if (reference) - INCREF(v->ref); + INCREF(v->ref); sp->type = T_POINTER; sp->u.vec = v; } @@ -812,7 +812,7 @@ push_mapping(struct mapping *v, bool_t reference) { extend_stack(); if (reference) - INCREF(v->ref); + INCREF(v->ref); sp->type = T_MAPPING; sp->u.map = v; } @@ -838,14 +838,14 @@ do_trace_call(struct function *funp) do_trace("Call direct ", funp->name, " "); if (TRACETST(TRACE_ARGS)) { - int i; - char buff[1024]; + int i; + char buff[1024]; - (void)sprintf(buff, " with %d arguments: ", funp->num_arg); - write_socket(buff, command_giver); - for(i = 0; i < funp->num_arg; i++) - write_socket(string_print_formatted(0, "%O ", 1, &fp[i]), - command_giver); + (void)sprintf(buff, " with %d arguments: ", funp->num_arg); + write_socket(buff, command_giver); + for(i = 0; i < funp->num_arg; i++) + write_socket(string_print_formatted(0, "%O ", 1, &fp[i]), + command_giver); } write_socket("\n", command_giver); } @@ -884,11 +884,11 @@ setup_new_frame(struct function *funp) } else { - while(csp->num_local_variables > funp->num_arg) - { - pop_stack(); - csp->num_local_variables--; - } + while(csp->num_local_variables > funp->num_arg) + { + pop_stack(); + csp->num_local_variables--; + } } /* Correct number of arguments and local variables */ called_args = csp->num_local_variables; @@ -899,10 +899,10 @@ setup_new_frame(struct function *funp) } #ifdef DEBUG if (called_args > funp->num_arg) - fatal("Error in seting up call frame!\n"); + fatal("Error in seting up call frame!\n"); #endif if (called_args == funp->num_arg) { - npc = funp->offset + funp->num_arg * sizeof(offset_t); + npc = funp->offset + funp->num_arg * sizeof(offset_t); } else { @@ -913,7 +913,7 @@ setup_new_frame(struct function *funp) fp = sp - csp->num_local_variables + 1; #ifdef TRACE_CODE if (TRACEP(TRACE_CALL)) { - do_trace_call(funp); + do_trace_call(funp); } #endif return current_prog->program + npc; @@ -923,10 +923,10 @@ setup_new_frame(struct function *funp) * maintain a small and inefficient stack of error recovery context * data structures. * This routine is called in three different ways: - * push=-1 Pop the stack. - * push=1 push the stack. - * push=0 No error occured, so the pushed value does not have to be - * restored. The pushed value can simply be popped into the void. + * push=-1 Pop the stack. + * push=1 push the stack. + * push=0 No error occured, so the pushed value does not have to be + * restored. The pushed value can simply be popped into the void. * * The stack is implemented as a linked list of stack-objects, allocated * from the heap, and deallocated when popped. @@ -936,12 +936,12 @@ push_pop_error_context (int push) { static struct error_context_stack { - struct gdexception *exception; - struct control_stack *save_csp; - struct object *save_command_giver; - struct svalue *save_sp; - struct error_context_stack *next; - struct control_stack cstack; + struct gdexception *exception; + struct control_stack *save_csp; + struct object *save_command_giver; + struct svalue *save_sp; + struct error_context_stack *next; + struct control_stack cstack; } *ecsp = 0, *p; if (push == 1) { @@ -967,44 +967,44 @@ push_pop_error_context (int push) #ifdef DEBUG #if 0 if (csp != p->save_csp-1) - fatal("Catch: Lost track of csp\n"); + fatal("Catch: Lost track of csp\n"); #endif #endif ; - } else { - /* push == -1 ! - * They did a throw() or error. That means that the control - * stack must be restored manually here. - */ + } else { + /* push == -1 ! + * They did a throw() or error. That means that the control + * stack must be restored manually here. + */ #ifdef PROFILE_LPC - double now = current_cpu(); - struct program *prog = current_prog; - csp->frame_cpu += (now - csp->startcpu); - for (;csp != p->save_csp; (prog = csp->prog), csp--) { - double frame_tot_cpu = now - csp->frame_start; - if (prog) - update_prog_profile(prog, now, csp->frame_cpu, frame_tot_cpu); - if (csp->funp) - update_func_profile(csp->funp, now, csp->frame_cpu, frame_tot_cpu, 1); - if (trace_calls) { - fprintf(trace_calls_file, "%*s--- %.3f / %.3f\n", - (int)(csp - control_stack) * 4, "", - csp->frame_cpu * 1000.0, - frame_tot_cpu * 1000.0); - } - } - csp->startcpu = now; + double now = current_cpu(); + struct program *prog = current_prog; + csp->frame_cpu += (now - csp->startcpu); + for (;csp != p->save_csp; (prog = csp->prog), csp--) { + double frame_tot_cpu = now - csp->frame_start; + if (prog) + update_prog_profile(prog, now, csp->frame_cpu, frame_tot_cpu); + if (csp->funp) + update_func_profile(csp->funp, now, csp->frame_cpu, frame_tot_cpu, 1); + if (trace_calls) { + fprintf(trace_calls_file, "%*s--- %.3f / %.3f\n", + (int)(csp - control_stack) * 4, "", + csp->frame_cpu * 1000.0, + frame_tot_cpu * 1000.0); + } + } + csp->startcpu = now; #else - csp = p->save_csp; + csp = p->save_csp; #endif - pop_n_elems (sp - p->save_sp); - command_giver = p->save_command_giver; - } + pop_n_elems (sp - p->save_sp); + command_giver = p->save_command_giver; + } - exception = p->exception; - ecsp = p->next; - restore_control_context(&(p->cstack)); - free ((char *)p); + exception = p->exception; + ecsp = p->next; + restore_control_context(&(p->cstack)); + free ((char *)p); } } @@ -1023,41 +1023,41 @@ validate_shadowing(struct object *ob) if (current_object->shadowing) error("shadow: Already shadowing.\n"); if (current_object->shadowed) - error("shadow: Can't shadow when shadowed.\n"); + error("shadow: Can't shadow when shadowed.\n"); if (current_object->super) - error("The shadow must not reside inside another object.\n"); + error("The shadow must not reside inside another object.\n"); if (ob->shadowing || current_object == ob) - error("Can't shadow a shadow.\n"); + error("Can't shadow a shadow.\n"); /* Loop structure copied from search_for_function... *shrug* /Dark */ for (inh = ob->prog->num_inherited - 1; inh >= 0; inh--) { - struct program *progp = victim->inherit[inh].prog; - int fun; + struct program *progp = victim->inherit[inh].prog; + int fun; - if (progp->flags & PRAGMA_NO_SHADOW) - return 0; - for (fun = progp->num_functions - 1; fun >= 0; fun--) - { - /* Should static functions 'shadowing' nomask functions - * be allowed? They do not do any harm... - */ - if ((progp->functions[fun].type_flags & TYPE_MOD_NO_MASK) && - search_for_function(progp->functions[fun].name, shadow)) - error("Illegal to shadow 'nomask' function \"%s\".\n", - progp->functions[fun].name); - } + if (progp->flags & PRAGMA_NO_SHADOW) + return 0; + for (fun = progp->num_functions - 1; fun >= 0; fun--) + { + /* Should static functions 'shadowing' nomask functions + * be allowed? They do not do any harm... + */ + if ((progp->functions[fun].type_flags & TYPE_MOD_NO_MASK) && + search_for_function(progp->functions[fun].name, shadow)) + error("Illegal to shadow 'nomask' function \"%s\".\n", + progp->functions[fun].name); + } } if (current_object == master_ob) - return 1; + return 1; push_object(ob); ret = apply_master_ob(M_QUERY_ALLOW_SHADOW, 1); if (!(ob->flags & O_DESTRUCTED) && - ret && !(ret->type == T_NUMBER && ret->u.number == 0)) + ret && !(ret->type == T_NUMBER && ret->u.number == 0)) { - return 1; + return 1; } return 0; } @@ -1088,40 +1088,40 @@ check_for_destr(struct svalue *arg) switch (arg->type) { case T_FUNCTION: - v = arg->u.func->funargs; - goto arrtest; + v = arg->u.func->funargs; + goto arrtest; case T_POINTER: - v = arg->u.vec; + v = arg->u.vec; arrtest: - for (i = 0; i < v->size; i++) - { - if (v->item[i].type == T_OBJECT) - { - if (!(v->item[i].u.ob->flags & O_DESTRUCTED)) - continue; - } - else if (v->item[i].type == T_FUNCTION && legal_closure(v->item[i].u.func)) - continue; - else - continue; - assign_svalue(&v->item[i], &const0); - } - break; + for (i = 0; i < v->size; i++) + { + if (v->item[i].type == T_OBJECT) + { + if (!(v->item[i].u.ob->flags & O_DESTRUCTED)) + continue; + } + else if (v->item[i].type == T_FUNCTION && legal_closure(v->item[i].u.func)) + continue; + else + continue; + assign_svalue(&v->item[i], &const0); + } + break; case T_MAPPING: - m = arg->u.map; - /* Value parts that have been destructed are kept but set = 0. */ - for (i = 0 ; i < m->size ; i++) { - for (p = m->pairs[i]; p ; p = p->next) - { - if ((p->val.type == T_OBJECT && - (p->val.u.ob->flags & O_DESTRUCTED)) || - (p->val.type == T_FUNCTION && - !legal_closure(p->val.u.func))) - assign_svalue(&p->val, &const0); - } - } - /* Index parts that has been destructed is removed */ + m = arg->u.map; + /* Value parts that have been destructed are kept but set = 0. */ + for (i = 0 ; i < m->size ; i++) { + for (p = m->pairs[i]; p ; p = p->next) + { + if ((p->val.type == T_OBJECT && + (p->val.u.ob->flags & O_DESTRUCTED)) || + (p->val.type == T_FUNCTION && + !legal_closure(p->val.u.func))) + assign_svalue(&p->val, &const0); + } + } + /* Index parts that has been destructed is removed */ for (i = 0 ; i < m->size ; i++) { for (pp = &m->pairs[i]; *pp; ) @@ -1144,11 +1144,11 @@ check_for_destr(struct svalue *arg) } } } - break; + break; default: - error("Strange type to check_for_destr.\n"); - break; + error("Strange type to check_for_destr.\n"); + break; } } @@ -1229,23 +1229,23 @@ f_call_virt(int xxx) if (current_object->prog == current_prog) { - cache_hits++; + cache_hits++; #ifdef CACHE_STATS - call_first_saves += current_prog->num_inherited - fiix; + call_first_saves += current_prog->num_inherited - fiix; #endif - function_prog_found = current_object->prog-> - inherit[fiix].prog; - function_inherit_found = fiix; - function_index_found = fix; + function_prog_found = current_object->prog-> + inherit[fiix].prog; + function_inherit_found = fiix; + function_index_found = fix; } else { - func = current_prog->inherit[fiix].prog->functions[fix].name; - (void)s_f_f(func, current_object->prog); - if (function_type_mod_found & TYPE_MOD_PRIVATE && - inh_offset < function_inherit_found - - (int)function_prog_found->num_inherited + 1) - error("Attempted call of private function.\n"); + func = current_prog->inherit[fiix].prog->functions[fix].name; + (void)s_f_f(func, current_object->prog); + if (function_type_mod_found & TYPE_MOD_PRIVATE && + inh_offset < function_inherit_found - + (int)function_prog_found->num_inherited + 1) + error("Attempted call of private function.\n"); } funp = &(function_prog_found->functions[function_index_found]); @@ -1271,14 +1271,14 @@ f_call_self(int num_arg) arg = sp - num_arg + 1; if (search_for_function(arg->u.string, current_object->prog) == 0 || - ((function_type_mod_found & TYPE_MOD_PRIVATE) && - inh_offset < function_inherit_found - - (int)function_prog_found->num_inherited + 1)) + ((function_type_mod_found & TYPE_MOD_PRIVATE) && + inh_offset < function_inherit_found - + (int)function_prog_found->num_inherited + 1)) { - /* No such function */ - pop_n_elems(num_arg); - push_number(0); - return; + /* No such function */ + pop_n_elems(num_arg); + push_number(0); + return; } free_svalue(arg); @@ -1313,7 +1313,7 @@ f_call_selfv(int xxx) num_arg = argv->size + 1; for(i = 0; i < argv->size; i++) { - push_svalue(&argv->item[i]); + push_svalue(&argv->item[i]); } free_vector(argv); f_call_self(num_arg); @@ -1386,10 +1386,10 @@ f_call_simul(int xxx) func = current_prog->rodata + func_name_index; if (!simul_efun_ob || - current_prog == simul_efun_ob->prog || - !apply_low(func, simul_efun_ob, num_arg, 1)) + current_prog == simul_efun_ob->prog || + !apply_low(func, simul_efun_ob, num_arg, 1)) { - error ("Simulated efun %s not found", current_prog->rodata + func_name_index); + error ("Simulated efun %s not found", current_prog->rodata + func_name_index); } } @@ -1401,28 +1401,28 @@ f_previous_object(int num_arg) struct control_stack *cspi; if (sp->u.number > 0 || (sp->u.number == 0 && - (previous_ob == 0 || (previous_ob->flags & O_DESTRUCTED)))) + (previous_ob == 0 || (previous_ob->flags & O_DESTRUCTED)))) { - pop_stack(); - push_number(0); - return; + pop_stack(); + push_number(0); + return; } else if (sp->u.number == 0) { - pop_stack(); - push_object(previous_ob); - return; + pop_stack(); + push_object(previous_ob); + return; } n = sp->u.number; pop_stack(); for (cspi = csp; n && cspi > control_stack; cspi--) - if (cspi->ext_call) - n++; + if (cspi->ext_call) + n++; if (cspi == control_stack || cspi->ob == 0 || - (cspi->ob->flags & O_DESTRUCTED)) - push_number(0); + (cspi->ob->flags & O_DESTRUCTED)) + push_number(0); else - push_object(cspi->ob); + push_object(cspi->ob); } /* ARGSUSED */ @@ -1435,14 +1435,14 @@ f_calling_program(int num_arg) pop_stack(); if (n > 0 || -n > MAX_TRACE) { - push_number(0); - return; + push_number(0); + return; } cspi = csp + n; if (cspi <= control_stack || cspi->prog == 0) - push_number(0); + push_number(0); else - push_string(cspi->prog->name, STRING_MSTRING); + push_string(cspi->prog->name, STRING_MSTRING); } /* ARGSUSED */ @@ -1455,15 +1455,15 @@ f_calling_object(int num_arg) pop_stack(); if (n > 0 || -n > MAX_TRACE) { - push_number(0); - return; + push_number(0); + return; } cspi = csp + n; if (cspi <= control_stack || cspi->ob == 0 || - (cspi->ob->flags & O_DESTRUCTED)) - push_number(0); + (cspi->ob->flags & O_DESTRUCTED)) + push_number(0); else - push_object(cspi->ob); + push_object(cspi->ob); } /* ARGSUSED */ @@ -1476,16 +1476,16 @@ f_calling_function(int num_arg) pop_stack(); if (n > 0 || -n > MAX_TRACE) { - push_number(0); - return; + push_number(0); + return; } cspi = csp + n - 1; if (cspi < control_stack) - push_number(0); + push_number(0); else if (cspi->funp) - push_string(cspi->funp->name, STRING_MSTRING); + push_string(cspi->funp->name, STRING_MSTRING); else - push_string("", STRING_CSTRING); + push_string("", STRING_CSTRING); } /* ARGSUSED */ @@ -1704,42 +1704,42 @@ f_reduce(int argnum) if (argval[1].type == T_POINTER) { struct vector *arrval; - struct svalue retval; - register int arrlen, number; + struct svalue retval; + register int arrlen, number; - arrval = argval[1].u.vec; - arrlen = arrval->size; + arrval = argval[1].u.vec; + arrlen = arrval->size; - if (argnum == 3) + if (argnum == 3) { - push_svalue(&argval[2]); - number = -1; + push_svalue(&argval[2]); + number = -1; } - else if (arrlen) + else if (arrlen) { - push_svalue(&arrval->item[0]); - number = 0; + push_svalue(&arrval->item[0]); + number = 0; } - else + else { - push_svalue(&const0); - number = -1; + push_svalue(&const0); + number = -1; } - while (++number < arrlen) + while (++number < arrlen) { - push_svalue(&arrval->item[number]); - call_var(2, argval[0].u.func); + push_svalue(&arrval->item[number]); + call_var(2, argval[0].u.func); } - assign_svalue_no_free(&retval, sp); - pop_n_elems(argnum + 1); - *(++sp) = retval; + assign_svalue_no_free(&retval, sp); + pop_n_elems(argnum + 1); + *(++sp) = retval; } else { pop_n_elems(argnum); - push_svalue(&const0); + push_svalue(&const0); } } @@ -1752,9 +1752,9 @@ f_regexp(int num_arg) v = match_regexp((sp-1)->u.vec, sp->u.string); pop_n_elems(2); if (v == 0) - push_number(0); + push_number(0); else { - push_vector(v, FALSE); + push_vector(v, FALSE); } } @@ -1767,25 +1767,25 @@ f_shadow(int num_arg) ob = (sp-1)->u.ob; if (sp->u.number == 0) { - ob = ob->shadowed; - pop_n_elems(2); - push_object(ob); - return; + ob = ob->shadowed; + pop_n_elems(2); + push_object(ob); + return; } if (validate_shadowing(ob)) { - /* - * The shadow is entered first in the chain. - */ - while (ob->shadowed) - ob = ob->shadowed; - change_ref(current_object->shadowing, ob, "f_shadow-1"); - current_object->shadowing = ob; - change_ref(ob->shadowed, current_object, "f_shadow-2"); - ob->shadowed = current_object; - pop_n_elems(2); - push_object(ob); - return; + /* + * The shadow is entered first in the chain. + */ + while (ob->shadowed) + ob = ob->shadowed; + change_ref(current_object->shadowing, ob, "f_shadow-1"); + current_object->shadowing = ob; + change_ref(ob->shadowed, current_object, "f_shadow-2"); + ob->shadowed = current_object; + pop_n_elems(2); + push_object(ob); + return; } pop_n_elems(2); push_number(0); @@ -1814,10 +1814,10 @@ f_jump_when_zero(int num_arg) if (sp->u.number == 0) { - pc = current_prog->program + offset; + pc = current_prog->program + offset; } else - pc += sizeof(offset_t); + pc += sizeof(offset_t); pop_stack(); } @@ -1829,9 +1829,9 @@ f_skip_nz(int num_arg) pc += sizeof(offset_t); if (sp->type == T_NUMBER && sp->u.number == 0) - pop_stack(); + pop_stack(); else - pc = current_prog->program + offset; + pc = current_prog->program + offset; } /* ARGSUSED */ @@ -1849,9 +1849,9 @@ f_jump_when_non_zero(int num_arg) offset_t offset = read_address(pc); if (sp->u.number == 0) - pc += sizeof(offset_t); + pc += sizeof(offset_t); else - pc = current_prog->program + offset; + pc = current_prog->program + offset; pop_stack(); } @@ -1861,7 +1861,7 @@ f_indirect(int num_arg) { #ifdef DEBUG if (sp->type != T_LVALUE) - fatal("Bad type to F_INDIRECT\n"); + fatal("Bad type to F_INDIRECT\n"); #endif assign_svalue(sp, sp->u.lvalue); /* @@ -1870,10 +1870,10 @@ f_indirect(int num_arg) * be replaced by 0. */ if ((sp->type == T_OBJECT && (sp->u.ob->flags & O_DESTRUCTED)) || - (sp->type == T_FUNCTION && !legal_closure(sp->u.func))) + (sp->type == T_FUNCTION && !legal_closure(sp->u.func))) { - free_svalue(sp); - *sp = const0; + free_svalue(sp); + *sp = const0; } } @@ -1883,7 +1883,7 @@ f_identifier(int num_arg) { extend_stack(); assign_svalue_no_free(sp, find_value((int)EXTRACT_UCHAR(pc), - (int)EXTRACT_UCHAR(pc + 1))); + (int)EXTRACT_UCHAR(pc + 1))); pc += 2; /* * Fetch value of a variable. It is possible that it is a variable @@ -1891,8 +1891,8 @@ f_identifier(int num_arg) * be replaced by 0. */ if ((sp->type == T_OBJECT && (sp->u.ob->flags & O_DESTRUCTED)) || - (sp->type == T_FUNCTION && !legal_closure(sp->u.func))) - assign_svalue(sp, &const0); + (sp->type == T_FUNCTION && !legal_closure(sp->u.func))) + assign_svalue(sp, &const0); } /* ARGSUSED */ @@ -1924,11 +1924,11 @@ f_index(int num_arg) * be replaced by 0. */ if ((sp->type == T_OBJECT && (sp->u.ob->flags & O_DESTRUCTED)) || - (sp->type == T_FUNCTION && !legal_closure(sp->u.func))) + (sp->type == T_FUNCTION && !legal_closure(sp->u.func))) { - free_svalue(sp); - sp->type = T_NUMBER; - sp->u.number = 0; + free_svalue(sp); + sp->type = T_NUMBER; + sp->u.number = 0; } } @@ -1945,10 +1945,10 @@ f_local_name(int num_arg) * be replaced by 0. */ if ((sp->type == T_OBJECT && (sp->u.ob->flags & O_DESTRUCTED)) || - (sp->type == T_FUNCTION && !legal_closure(sp->u.func))) + (sp->type == T_FUNCTION && !legal_closure(sp->u.func))) { - free_svalue(sp); - *sp = const0; + free_svalue(sp); + *sp = const0; } } @@ -2016,7 +2016,7 @@ f_aggregate(int num_arg) pc += 2; v = allocate_array((int)num); for (i = 0; i < (int)num; i++) - assign_svalue_no_free(&v->item[i], sp + i - num + 1); + assign_svalue_no_free(&v->item[i], sp + i - num + 1); pop_n_elems((int)num); push_vector(v, FALSE); } @@ -2036,8 +2036,8 @@ f_m_aggregate(int num_arg) m = allocate_map((short)num); /* Ref count = 1 */ for (i = 0 ; i < (int)num ; i += 2) { - arg = sp + i - num; - assign_svalue(get_map_lvalue(m, arg + 1, 1), arg + 2); + arg = sp + i - num; + assign_svalue(get_map_lvalue(m, arg + 1, 1), arg + 2); } pop_n_elems((int)num); push_mapping(m, FALSE); @@ -2048,9 +2048,9 @@ static void f_tail(int num_arg) { if (tail(sp->u.string)) - assign_svalue(sp, &const1); + assign_svalue(sp, &const1); else - assign_svalue(sp, &const0); + assign_svalue(sp, &const0); } /* ARGSUSED */ @@ -2125,20 +2125,20 @@ f_read_file(int num_arg) long long start = 0, len = 0; if (num_arg > 1) - start = arg[1].u.number; + start = arg[1].u.number; if (num_arg == 3) - { - if (arg[2].type != T_NUMBER) - bad_arg(2, F_READ_FILE, &arg[2]); - len = arg[2].u.number; - } + { + if (arg[2].type != T_NUMBER) + bad_arg(2, F_READ_FILE, &arg[2]); + len = arg[2].u.number; + } str = read_file(arg[0].u.string, start, len); pop_n_elems(num_arg); if (str == 0) - push_number(0); + push_number(0); else { - push_mstring(str); + push_mstring(str); } } @@ -2151,21 +2151,21 @@ f_read_bytes(int num_arg) long long len = 0; if (num_arg > 1) - start = arg[1].u.number; + start = arg[1].u.number; if (num_arg == 3) { - if (arg[2].type != T_NUMBER) - bad_arg(2, F_READ_BYTES, &arg[2]); - len = arg[2].u.number; + if (arg[2].type != T_NUMBER) + bad_arg(2, F_READ_BYTES, &arg[2]); + len = arg[2].u.number; } str = read_bytes(arg[0].u.string, start, len); pop_n_elems(num_arg); if (str == 0) - push_number(0); + push_number(0); else { - push_mstring(str); + push_mstring(str); } } @@ -2174,10 +2174,10 @@ static void f_write_bytes(int num_arg) { if (sp->type != T_STRING) - bad_arg(3, F_WRITE_BYTES, sp); + bad_arg(3, F_WRITE_BYTES, sp); if (sp->u.string == NULL) - error("Attempt to write empty string.\n"); + error("Attempt to write empty string.\n"); int i = write_bytes((sp-2)->u.string, (sp-1)->u.number, sp->u.string); pop_n_elems(3); @@ -2217,16 +2217,16 @@ f_find_living(int num_arg) arg = sp - num_arg + 1; if (num_arg == 1 || arg[1].u.number == 0) - ob = find_living_object(arg[0].u.string); + ob = find_living_object(arg[0].u.string); else - obs = find_living_objects(arg[0].u.string); + obs = find_living_objects(arg[0].u.string); pop_n_elems(num_arg); if (ob) - push_object(ob); + push_object(ob); else if (obs) - push_vector(obs, FALSE); + push_vector(obs, FALSE); else - push_number(0); + push_number(0); } /* ARGSUSED */ @@ -2238,19 +2238,19 @@ f_find_player(int num_arg) int i; for (i=0 ; iliving_name && strcmp(ob->living_name, sp->u.string) == 0) { - pop_stack(); - push_object(ob); - return; - } + ob = get_interactive_object(i); + if (ob->living_name && strcmp(ob->living_name, sp->u.string) == 0) { + pop_stack(); + push_object(ob); + return; + } } ob = find_living_object(sp->u.string); pop_stack(); if (ob && (ob->flags & O_ONCE_INTERACTIVE)) - push_object(ob); + push_object(ob); else - push_number(0); + push_number(0); } /* ARGSUSED */ @@ -2400,10 +2400,10 @@ static void f_this_interactive(int num_arg) { if (current_interactive && - !(current_interactive->flags & O_DESTRUCTED)) - push_object(current_interactive); + !(current_interactive->flags & O_DESTRUCTED)) + push_object(current_interactive); else - push_number(0); + push_number(0); } /* ARGSUSED */ @@ -2411,9 +2411,9 @@ static void f_this_player(int num_arg) { if (command_giver && !(command_giver->flags & O_DESTRUCTED)) - push_object(command_giver); + push_object(command_giver); else - push_number(0); + push_number(0); } /* ARGSUSED */ @@ -2422,13 +2422,13 @@ f_set_this_player(int num_arg) { if (sp->type == T_NUMBER) { - if (sp->u.number != 0) - error("Bad argument 1 to set_this_player()\n"); - command_giver = 0; + if (sp->u.number != 0) + error("Bad argument 1 to set_this_player()\n"); + command_giver = 0; } else - if (sp->u.ob->flags & O_ENABLE_COMMANDS) - command_giver = sp->u.ob; + if (sp->u.ob->flags & O_ENABLE_COMMANDS) + command_giver = sp->u.ob; } /* ARGSUSED */ @@ -2437,13 +2437,13 @@ f_living(int num_arg) { if (sp->type == T_NUMBER) { - assign_svalue(sp, &const0); - return; + assign_svalue(sp, &const0); + return; } if (sp->u.ob->flags & O_ENABLE_COMMANDS) - assign_svalue(sp, &const1); + assign_svalue(sp, &const1); else - assign_svalue(sp, &const0); + assign_svalue(sp, &const0); } /* ARGSUSED */ @@ -2455,17 +2455,17 @@ f_set_auth(int num_arg) if (master_ob) { - push_object(current_object); - push_object(arg->u.ob); - push_svalue(arg + 1); - ret = apply_master_ob(M_VALID_SET_AUTH, 3); + push_object(current_object); + push_object(arg->u.ob); + push_svalue(arg + 1); + ret = apply_master_ob(M_VALID_SET_AUTH, 3); } if (!ret) { - pop_n_elems(2); - push_number(0); - return; + pop_n_elems(2); + push_number(0); + return; } assign_svalue(&arg->u.ob->auth, ret); free_svalue(ret); @@ -2485,17 +2485,17 @@ f_query_auth(int num_arg) switch (ob->auth.type) { case T_POINTER: - push_vector(allocate_array(ob->auth.u.vec->size), FALSE); - for (i = 0; i < ob->auth.u.vec->size; i++) - assign_svalue_no_free(&(sp->u.vec->item[i]), &(ob->auth.u.vec->item[i])); - break; + push_vector(allocate_array(ob->auth.u.vec->size), FALSE); + for (i = 0; i < ob->auth.u.vec->size; i++) + assign_svalue_no_free(&(sp->u.vec->item[i]), &(ob->auth.u.vec->item[i])); + break; case T_MAPPING: - push_mapping(copy_mapping(ob->auth.u.map), FALSE); - break; - /* I think functions are handled correctly be default. -- LA */ + push_mapping(copy_mapping(ob->auth.u.map), FALSE); + break; + /* I think functions are handled correctly be default. -- LA */ default: - push_svalue(&(ob->auth)); - break; + push_svalue(&(ob->auth)); + break; } } @@ -2508,9 +2508,9 @@ f_explode(int num_arg) v = explode_string((sp-1)->u.string, sp->u.string); pop_n_elems(2); if (v) { - push_vector(v, FALSE); + push_vector(v, FALSE); } else { - push_number(0); + push_number(0); } } @@ -2522,74 +2522,74 @@ f_filter(int num_arg) arg = sp - num_arg + 1; if (num_arg == 2 && arg[1].type == T_FUNCTION) { - ; + ; } else if (num_arg >= 3 && arg[1].type == T_STRING) { - struct closure *fun; - struct object *ob; - - if (arg[2].type == T_OBJECT) - ob = arg[2].u.ob; - else if (arg[2].type == T_STRING) - ob = find_object(arg[2].u.string); - else - ob = 0; - - if (!ob) - bad_arg(3, F_FILTER, &arg[2]); - - /* Fake a function */ - fun = alloc_objclosurestr(FUN_LFUNO, arg[1].u.string, ob, "f_filter", 0); - if (!fun) { - /* We have three choices here: - * 1 - return ({}) which is backwards compatible - * 2 - return 0 to indicate an error - * 3 - generate a runtime error - */ + struct closure *fun; + struct object *ob; + + if (arg[2].type == T_OBJECT) + ob = arg[2].u.ob; + else if (arg[2].type == T_STRING) + ob = find_object(arg[2].u.string); + else + ob = 0; + + if (!ob) + bad_arg(3, F_FILTER, &arg[2]); + + /* Fake a function */ + fun = alloc_objclosurestr(FUN_LFUNO, arg[1].u.string, ob, "f_filter", 0); + if (!fun) { + /* We have three choices here: + * 1 - return ({}) which is backwards compatible + * 2 - return 0 to indicate an error + * 3 - generate a runtime error + */ #if 0 - error("Function used in filter could not be found: %s\n", arg[1].u.string); + error("Function used in filter could not be found: %s\n", arg[1].u.string); #else - (void)printf("Function used in filter could not be found: %s\n", arg[1].u.string); - pop_n_elems(num_arg); - push_number(0); + (void)printf("Function used in filter could not be found: %s\n", arg[1].u.string); + pop_n_elems(num_arg); + push_number(0); #endif - return; - } - if (num_arg > 3) { - free_vector(fun->funargs); - fun->funargs = allocate_array(2); - fun->funargs->item[0] = constempty; - assign_svalue_no_free(&fun->funargs->item[1], &arg[3]); - } - free_svalue(&arg[1]); /* release old stack location */ - arg[1].type = T_FUNCTION; - arg[1].u.func = fun; /* and put in a new one */ - - WARNOBSOLETE(current_object, "string as function in filter"); + return; + } + if (num_arg > 3) { + free_vector(fun->funargs); + fun->funargs = allocate_array(2); + fun->funargs->item[0] = constempty; + assign_svalue_no_free(&fun->funargs->item[1], &arg[3]); + } + free_svalue(&arg[1]); /* release old stack location */ + arg[1].type = T_FUNCTION; + arg[1].u.func = fun; /* and put in a new one */ + + WARNOBSOLETE(current_object, "string as function in filter"); } else - error("Bad arguments to filter\n"); + error("Bad arguments to filter\n"); if (arg[0].type == T_POINTER) { - struct vector *res; - check_for_destr(&arg[0]); - res = filter_arr(arg[0].u.vec, arg[1].u.func); - pop_n_elems(num_arg); - if (res) { - push_vector(res, FALSE); - } else - push_number(0); + struct vector *res; + check_for_destr(&arg[0]); + res = filter_arr(arg[0].u.vec, arg[1].u.func); + pop_n_elems(num_arg); + if (res) { + push_vector(res, FALSE); + } else + push_number(0); } else if (arg[0].type == T_MAPPING) { - struct mapping *m; - check_for_destr(&arg[0]); - m = filter_map(arg[0].u.map, arg[1].u.func); - pop_n_elems(num_arg); - if (m) { - push_mapping(m, FALSE); - } else - push_number(0); + struct mapping *m; + check_for_destr(&arg[0]); + m = filter_map(arg[0].u.map, arg[1].u.func); + pop_n_elems(num_arg); + if (m) { + push_mapping(m, FALSE); + } else + push_number(0); } else { - /*bad_arg(1, F_FILTER, &arg[0]);*/ - pop_n_elems(num_arg); - push_number(0); + /*bad_arg(1, F_FILTER, &arg[0]);*/ + pop_n_elems(num_arg); + push_number(0); } } @@ -2602,22 +2602,22 @@ f_set_bit(int num_arg) int ind; if (sp->u.number > MAX_BITS) - error("set_bit: too big bit number: %lld\n", sp->u.number); + error("set_bit: too big bit number: %lld\n", sp->u.number); if (sp->u.number < 0) - error("set_bit: negative bit number: %lld\n", sp->u.number); + error("set_bit: negative bit number: %lld\n", sp->u.number); len = strlen((sp-1)->u.string); old_len = len; ind = sp->u.number/6; if (ind >= len) - len = ind + 1; + len = ind + 1; str = allocate_mstring(len); str[len] = '\0'; if (old_len) - (void)memcpy(str, (sp-1)->u.string, old_len); + (void)memcpy(str, (sp-1)->u.string, old_len); if (len > old_len) - (void)memset(str + old_len, ' ', len - old_len); + (void)memset(str + old_len, ' ', len - old_len); if (str[ind] > 0x3f + ' ' || str[ind] < ' ') - error("Illegal bit pattern in set_bit character %d\n", ind); + error("Illegal bit pattern in set_bit character %d\n", ind); str[ind] = ((str[ind] - ' ') | (1 << (sp->u.number % 6))) + ' '; pop_n_elems(2); push_mstring(str); @@ -2632,20 +2632,20 @@ f_clear_bit(int num_arg) int ind; if (sp->u.number > MAX_BITS) - error("clear_bit: too big bit number: %lld\n", sp->u.number); + error("clear_bit: too big bit number: %lld\n", sp->u.number); if (sp->u.number < 0) - error("clear_bit: negative bit number: %lld\n", sp->u.number); + error("clear_bit: negative bit number: %lld\n", sp->u.number); len = strlen((sp-1)->u.string); ind = sp->u.number/6; if (ind >= len) { - /* Return first argument unmodified ! */ - pop_stack(); - return; + /* Return first argument unmodified ! */ + pop_stack(); + return; } str = allocate_mstring(len); - (void)memcpy(str, (sp-1)->u.string, len+1); /* Including null byte */ + (void)memcpy(str, (sp-1)->u.string, len+1); /* Including null byte */ if (str[ind] > 0x3f + ' ' || str[ind] < ' ') - error("Illegal bit pattern in clear_bit character %d\n", ind); + error("Illegal bit pattern in clear_bit character %d\n", ind); str[ind] = ((str[ind] - ' ') & ~(1 << sp->u.number % 6)) + ' '; pop_n_elems(2); push_mstring(str); @@ -2658,22 +2658,22 @@ f_test_bit(int num_arg) int len; if (sp->u.number > MAX_BITS) - error("test_bit: too big bit number: %lld\n", sp->u.number); + error("test_bit: too big bit number: %lld\n", sp->u.number); if (sp->u.number < 0) - error("test_bit: negative bit number: %lld\n", sp->u.number); + error("test_bit: negative bit number: %lld\n", sp->u.number); len = strlen((sp-1)->u.string); if (sp->u.number/6 >= len) { - pop_n_elems(2); - push_number(0); - return; + pop_n_elems(2); + push_number(0); + return; } if (((sp-1)->u.string[sp->u.number/6] - ' ') & 1 << sp->u.number % 6) { - pop_n_elems(2); - push_number(1); + pop_n_elems(2); + push_number(1); } else { - pop_n_elems(2); - push_number(0); + pop_n_elems(2); + push_number(0); } } @@ -2710,7 +2710,7 @@ static void f_throw(int num_arg) { if (sp->type == T_NUMBER && sp->u.number == 0) - error("Illegal throw.\n"); + error("Illegal throw.\n"); assign_svalue(&catch_value, sp); pop_stack(); @@ -2726,8 +2726,8 @@ f_notify_fail(int num_arg) if (num_arg == 2) { - pri = sp->u.number; - pop_stack(); + pri = sp->u.number; + pop_stack(); } set_notify_fail_message(sp->u.string, pri); /* Return 0 */ @@ -2752,8 +2752,8 @@ f_query_interactive(int num_arg) { if (sp->type == T_NUMBER) { - assign_svalue(sp, &const0); - return; + assign_svalue(sp, &const0); + return; } assign_svalue(sp, sp->u.ob->interactive ? &const1 : &const0); } @@ -2766,16 +2766,16 @@ f_implode(int num_arg) if ((sp-1)->type == T_NUMBER) { - pop_stack(); - return; + pop_stack(); + return; } check_for_destr(sp-1); str = implode_string((sp-1)->u.vec, sp->u.string); pop_n_elems(2); if (str) { - push_mstring(str); + push_mstring(str); } else { - push_number(0); + push_number(0); } } @@ -2786,9 +2786,9 @@ f_query_snoop(int num_arg) struct object *ob; if (current_object == master_ob && sp->u.ob->interactive) - ob = query_snoop(sp->u.ob); + ob = query_snoop(sp->u.ob); else - ob = 0; + ob = 0; pop_stack(); push_object(ob); } @@ -2802,10 +2802,10 @@ f_query_remote_port(int num_arg) if (num_arg == 1) { - if (sp->type != T_OBJECT) - error("Bad optional argument to query_remote_port()\n"); - else - ob = sp->u.ob; + if (sp->type != T_OBJECT) + error("Bad optional argument to query_remote_port()\n"); + else + ob = sp->u.ob; } push_object(current_object); @@ -2814,10 +2814,10 @@ f_query_remote_port(int num_arg) ret = apply_master_ob(M_VALID_QUERY_IP_NUMBER_NAME, 2); if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) { - if (num_arg) - pop_stack(); - push_number(0); - return; + if (num_arg) + pop_stack(); + push_number(0); + return; } char *port_str = query_port_number(ob); @@ -2842,10 +2842,10 @@ f_query_ip_number_name(int name, int num_arg) if (num_arg == 1) { - if (sp->type != T_OBJECT) - error("Bad optional argument to query_ip_number() or query_ip_name\n"); - else - ob = sp->u.ob; + if (sp->type != T_OBJECT) + error("Bad optional argument to query_ip_number() or query_ip_name\n"); + else + ob = sp->u.ob; } push_number(name); @@ -2854,24 +2854,24 @@ f_query_ip_number_name(int name, int num_arg) ret = apply_master_ob(M_VALID_QUERY_IP_NUMBER_NAME, 3); if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) { - if (num_arg) - pop_stack(); - push_number(0); - return; + if (num_arg) + pop_stack(); + push_number(0); + return; } if (name) - tmp = query_ip_name(ob); + tmp = query_ip_name(ob); else - tmp = query_ip_number(ob); + tmp = query_ip_number(ob); if (num_arg) - pop_stack(); + pop_stack(); if (tmp == 0) - push_number(0); + push_number(0); else - push_string(tmp, STRING_MSTRING); + push_string(tmp, STRING_MSTRING); } static void @@ -2920,10 +2920,10 @@ f_query_ip_ident(int num_arg) push_object(ob); ret = apply_master_ob(M_VALID_QUERY_IP_IDENT, 2); if ((ret && (ret->type != T_NUMBER || ret->u.number == 0)) || - !ob->interactive || !ob->interactive->rname) - push_number(0); + !ob->interactive || !ob->interactive->rname) + push_number(0); else - push_string(ob->interactive->rname, STRING_MSTRING); + push_string(ob->interactive->rname, STRING_MSTRING); free_object(ob, "f_query_ip_ident"); } @@ -2936,9 +2936,9 @@ f_query_host_name(int num_arg) tmp = query_host_name(); if (tmp) - push_string(tmp, STRING_MSTRING); + push_string(tmp, STRING_MSTRING); else - push_number(0); + push_number(0); } /* ARGSUSED */ @@ -2950,9 +2950,9 @@ f_all_inventory(int num_arg) vec = all_inventory(sp->u.ob); pop_stack(); if (vec == 0) { - push_number(0); + push_number(0); } else { - push_vector(vec, FALSE); + push_vector(vec, FALSE); } } @@ -2963,9 +2963,9 @@ f_deep_inventory(int num_arg) struct vector *vec; if (sp->type == T_NUMBER) - vec = allocate_array(0); + vec = allocate_array(0); else - vec = deep_inventory(sp->u.ob, 0); + vec = deep_inventory(sp->u.ob, 0); free_svalue(sp); sp->type = T_POINTER; sp->u.vec = vec; @@ -2999,18 +2999,18 @@ f_object_clones(int num_arg) int num_clones; if (sp->type == T_NUMBER) - v = allocate_array(0); + v = allocate_array(0); else { - num_clones = sp->u.ob->prog->num_clones; - v = allocate_array(num_clones); - for (i = 0, ob = sp->u.ob->prog->clones; - i < num_clones; - i++, ob = ob->next_all) { - v->item[i].type = T_OBJECT; - v->item[i].u.ob = ob; - add_ref(ob, "object_clones"); - } + num_clones = sp->u.ob->prog->num_clones; + v = allocate_array(num_clones); + for (i = 0, ob = sp->u.ob->prog->clones; + i < num_clones; + i++, ob = ob->next_all) { + v->item[i].type = T_OBJECT; + v->item[i].u.ob = ob; + add_ref(ob, "object_clones"); + } } pop_stack(); push_vector(v, FALSE); @@ -3023,9 +3023,9 @@ f_commands(int num_arg) struct vector *vec; if (sp->type == T_NUMBER) - vec = allocate_array(0); + vec = allocate_array(0); else - vec = get_local_commands(sp->u.ob); + vec = get_local_commands(sp->u.ob); pop_stack(); push_vector(vec, FALSE); } @@ -3072,41 +3072,41 @@ f_max(int num_arg) case T_NUMBER: case T_STRING: case T_FLOAT: - break; + break; default: - bad_arg(1, F_MAX, arg0); - break; + bad_arg(1, F_MAX, arg0); + break; } for (i = 1; i < num_arg; i++) { - if (maxp->type != argn->type) - bad_arg(i + 1, F_MAX, arg0 + i); - - switch (arg0->type) - { - case T_NUMBER: - if (maxp->u.number < argn->u.number) - maxp = argn; - break; + if (maxp->type != argn->type) + bad_arg(i + 1, F_MAX, arg0 + i); - case T_STRING: - if (strcmp(maxp->u.string, argn->u.string) < 0) - maxp = argn; - break; - - case T_FLOAT: - if (maxp->u.real < argn->u.real) - maxp = argn; - break; - } + switch (arg0->type) + { + case T_NUMBER: + if (maxp->u.number < argn->u.number) + maxp = argn; + break; + + case T_STRING: + if (strcmp(maxp->u.string, argn->u.string) < 0) + maxp = argn; + break; + + case T_FLOAT: + if (maxp->u.real < argn->u.real) + maxp = argn; + break; + } - argn++; + argn++; } if (maxp != arg0) - assign_svalue(arg0, maxp); + assign_svalue(arg0, maxp); pop_n_elems(num_arg - 1); } @@ -3127,41 +3127,41 @@ f_min(int num_arg) case T_NUMBER: case T_STRING: case T_FLOAT: - break; + break; default: - bad_arg(1, F_MIN, arg0); - break; + bad_arg(1, F_MIN, arg0); + break; } for (i = 1; i < num_arg; i++) { - if (minp->type != argn->type) - bad_arg(i + 1, F_MIN, arg0 + i); - - switch (arg0->type) - { - case T_NUMBER: - if (minp->u.number > argn->u.number) - minp = argn; - break; + if (minp->type != argn->type) + bad_arg(i + 1, F_MIN, arg0 + i); - case T_STRING: - if (strcmp(minp->u.string, argn->u.string) > 0) - minp = argn; - break; - - case T_FLOAT: - if (minp->u.real > argn->u.real) - minp = argn; - break; - } + switch (arg0->type) + { + case T_NUMBER: + if (minp->u.number > argn->u.number) + minp = argn; + break; + + case T_STRING: + if (strcmp(minp->u.string, argn->u.string) > 0) + minp = argn; + break; + + case T_FLOAT: + if (minp->u.real > argn->u.real) + minp = argn; + break; + } - argn++; + argn++; } if (minp != arg0) - assign_svalue(arg0, minp); + assign_svalue(arg0, minp); pop_n_elems(num_arg - 1); } @@ -3173,62 +3173,62 @@ f_add(int num_arg) /*if (inadd==0) checkplus(p);*/ if ((sp-1)->type == T_STRING && sp->type == T_STRING) { - char *res; - int l = strlen((sp-1)->u.string); - res = allocate_mstring(l + strlen(sp->u.string)); - (void)strcpy(res, (sp-1)->u.string); - (void)strcpy(res+l, sp->u.string); - pop_n_elems(2); - push_mstring(res); + char *res; + int l = strlen((sp-1)->u.string); + res = allocate_mstring(l + strlen(sp->u.string)); + (void)strcpy(res, (sp-1)->u.string); + (void)strcpy(res+l, sp->u.string); + pop_n_elems(2); + push_mstring(res); } else if ((sp-1)->type == T_NUMBER && sp->type == T_STRING) { - char buff[60], *res; - (void)sprintf(buff, "%lld", (sp-1)->u.number); - res = allocate_mstring(strlen(sp->u.string) + strlen(buff)); - (void)strcpy(res, buff); - (void)strcat(res, sp->u.string); - pop_n_elems(2); - push_mstring(res); + char buff[60], *res; + (void)sprintf(buff, "%lld", (sp-1)->u.number); + res = allocate_mstring(strlen(sp->u.string) + strlen(buff)); + (void)strcpy(res, buff); + (void)strcat(res, sp->u.string); + pop_n_elems(2); + push_mstring(res); } else if (sp->type == T_NUMBER && (sp-1)->type == T_STRING) { - char buff[60]; - char *res; - (void)sprintf(buff, "%lld", sp->u.number); - res = allocate_mstring(strlen((sp-1)->u.string) + strlen(buff)); - (void)strcpy(res, (sp-1)->u.string); - (void)strcat(res, buff); - pop_n_elems(2); - push_mstring(res); + char buff[60]; + char *res; + (void)sprintf(buff, "%lld", sp->u.number); + res = allocate_mstring(strlen((sp-1)->u.string) + strlen(buff)); + (void)strcpy(res, (sp-1)->u.string); + (void)strcat(res, buff); + pop_n_elems(2); + push_mstring(res); } else if ((sp-1)->type == T_NUMBER && sp->type == T_NUMBER) { - (sp-1)->u.number += sp->u.number; - sp--; + (sp-1)->u.number += sp->u.number; + sp--; } else if ((sp-1)->type == T_FLOAT && sp->type == T_FLOAT) { - FLOATASGOP((sp-1)->u.real, += , sp->u.real); - sp--; + FLOATASGOP((sp-1)->u.real, += , sp->u.real); + sp--; } else if ((sp-1)->type == T_POINTER && sp->type == T_POINTER) { - struct vector *v; - check_for_destr(sp-1); - check_for_destr(sp); - v = add_array((sp-1)->u.vec,sp->u.vec); - pop_n_elems(2); - push_vector(v, FALSE); + struct vector *v; + check_for_destr(sp-1); + check_for_destr(sp); + v = add_array((sp-1)->u.vec,sp->u.vec); + pop_n_elems(2); + push_vector(v, FALSE); } else if ((sp-1)->type == T_MAPPING && sp->type == T_MAPPING) { - struct mapping *m; - check_for_destr(sp-1); - check_for_destr(sp); - m = add_mapping((sp-1)->u.map, sp->u.map); - pop_n_elems(2); - push_mapping(m, FALSE); + struct mapping *m; + check_for_destr(sp-1); + check_for_destr(sp); + m = add_mapping((sp-1)->u.map, sp->u.map); + pop_n_elems(2); + push_mapping(m, FALSE); } else { @@ -3243,32 +3243,32 @@ f_subtract(int num_arg) if ((sp-1)->type == T_POINTER && sp->type == T_POINTER) { - struct vector *v; + struct vector *v; - check_for_destr(sp-1); - check_for_destr(sp); + check_for_destr(sp-1); + check_for_destr(sp); - v = subtract_array((sp-1)->u.vec, sp->u.vec); + v = subtract_array((sp-1)->u.vec, sp->u.vec); - pop_stack(); - pop_stack(); + pop_stack(); + pop_stack(); - if (v == 0) - { - push_number(0); - } - else - { - push_vector(v, FALSE); - } + if (v == 0) + { + push_number(0); + } + else + { + push_vector(v, FALSE); + } - return; + return; } if ((sp-1)->type == T_FLOAT && sp->type == T_FLOAT) { - FLOATASGOP((sp-1)->u.real, -= , sp->u.real); - sp--; - return; + FLOATASGOP((sp-1)->u.real, -= , sp->u.real); + sp--; + return; } if ((sp-1)->type != T_NUMBER || sp->type != T_NUMBER) @@ -3283,24 +3283,24 @@ f_and(int num_arg) { if (sp->type == T_POINTER && (sp-1)->type == T_POINTER) { - struct vector *v; + struct vector *v; - v = intersect_array(sp->u.vec, (sp-1)->u.vec); + v = intersect_array(sp->u.vec, (sp-1)->u.vec); - pop_stack(); - pop_stack(); - if (v == 0) - { - push_number(0); - } - else - { - push_vector(v, FALSE); - } - return; + pop_stack(); + pop_stack(); + if (v == 0) + { + push_number(0); + } + else + { + push_vector(v, FALSE); + } + return; } if ((sp-1)->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_AND, sp - 1, sp); (sp-1)->u.number &= sp->u.number; sp--; @@ -3312,24 +3312,24 @@ f_or(int num_arg) { if (sp->type == T_POINTER && (sp-1)->type == T_POINTER) { - struct vector *v; + struct vector *v; - v = union_array((sp-1)->u.vec, sp->u.vec); + v = union_array((sp-1)->u.vec, sp->u.vec); - pop_stack(); - pop_stack(); + pop_stack(); + pop_stack(); - if (v == NULL) - push_number(0); - else - push_vector(v, FALSE); + if (v == NULL) + push_number(0); + else + push_vector(v, FALSE); - return; + return; } if ((sp-1)->type != T_NUMBER || - sp->type != T_NUMBER) - bad_arg_op(F_OR, sp-1, sp); + sp->type != T_NUMBER) + bad_arg_op(F_OR, sp-1, sp); (sp-1)->u.number |= sp->u.number; sp--; } @@ -3339,7 +3339,7 @@ static void f_xor(int num_arg) { if ((sp-1)->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_XOR, sp-1, sp); (sp-1)->u.number ^= sp->u.number; sp--; @@ -3350,7 +3350,7 @@ static void f_lsh(int num_arg) { if ((sp-1)->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_LSH, sp-1, sp); (sp-1)->u.number <<= sp->u.number; sp--; @@ -3363,7 +3363,7 @@ f_rsh(int num_arg) long long i; if ((sp-1)->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_RSH, sp-1, sp); i = (long long)((unsigned long long)(sp-1)->u.number >> sp->u.number); sp--; @@ -3376,46 +3376,46 @@ f_multiply(int num_arg) { if ((sp-1)->type == T_FLOAT && sp->type == T_FLOAT) { - FLOATASGOP((sp-1)->u.real, *= , sp->u.real); - sp--; - return; + FLOATASGOP((sp-1)->u.real, *= , sp->u.real); + sp--; + return; } if ((sp-1)->type == T_NUMBER) { - if (sp->type == T_NUMBER) { + if (sp->type == T_NUMBER) { (sp-1)->u.number *= sp->u.number; sp--; return; } else if (sp->type == T_STRING) { char *result = multiply_string(sp->u.string, (sp-1)->u.number); - pop_stack(); - pop_stack(); - push_string(result, STRING_MSTRING); - return; + pop_stack(); + pop_stack(); + push_string(result, STRING_MSTRING); + return; } else if (sp->type == T_POINTER) { - struct vector *result = multiply_array(sp->u.vec, - (sp-1)->u.number); - pop_stack(); - pop_stack(); - push_vector(result, 0); + struct vector *result = multiply_array(sp->u.vec, + (sp-1)->u.number); + pop_stack(); + pop_stack(); + push_vector(result, 0); return; } } else if ((sp-1)->type == T_POINTER && - sp->type == T_NUMBER) { - struct vector *result = multiply_array((sp-1)->u.vec, - sp->u.number); - pop_stack(); - pop_stack(); - push_vector(result, 0); + sp->type == T_NUMBER) { + struct vector *result = multiply_array((sp-1)->u.vec, + sp->u.number); + pop_stack(); + pop_stack(); + push_vector(result, 0); return; } else if ((sp-1)->type == T_STRING && - sp->type == T_NUMBER) { - char *result = multiply_string((sp-1)->u.string, sp->u.number); - pop_stack(); - pop_stack(); - push_string(result, STRING_MSTRING); - return; + sp->type == T_NUMBER) { + char *result = multiply_string((sp-1)->u.string, sp->u.number); + pop_stack(); + pop_stack(); + push_string(result, STRING_MSTRING); + return; } bad_arg_op(F_MULTIPLY, sp-1, sp); } @@ -3427,16 +3427,16 @@ f_divide(int num_arg) if ((sp-1)->type == T_FLOAT && sp->type == T_FLOAT) { if (sp->u.real == 0.0) - error("Division by zero\n"); - FLOATASGOP((sp-1)->u.real, /= , sp->u.real); - sp--; - return; + error("Division by zero\n"); + FLOATASGOP((sp-1)->u.real, /= , sp->u.real); + sp--; + return; } if ((sp-1)->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_DIVIDE, sp-1, sp); if (sp->u.number == 0) - error("Division by zero\n"); + error("Division by zero\n"); (sp-1)->u.number /= sp->u.number; sp--; } @@ -3451,13 +3451,13 @@ f_mod(int num_arg) if (sp->type == T_NUMBER) { if (sp->u.number == 0) - error("Modulus by zero.\n"); + error("Modulus by zero.\n"); (sp-1)->u.number %= sp->u.number; } else if (sp->type == T_FLOAT) { errno = 0; (sp-1)->u.real = fmod((sp-1)->u.real, sp->u.real); if (errno) - error("Modulus by zero.\n"); + error("Modulus by zero.\n"); } sp--; } @@ -3469,20 +3469,20 @@ f_gt(int num_arg) long long i; if ((sp-1)->type == T_STRING && sp->type == T_STRING) { - i = strcmp((sp-1)->u.string, sp->u.string) > 0; - pop_n_elems(2); - push_number(i); - return; + i = strcmp((sp-1)->u.string, sp->u.string) > 0; + pop_n_elems(2); + push_number(i); + return; } if ((sp-1)->type == T_FLOAT && sp->type == T_FLOAT) { - (sp-1)->u.number = (sp-1)->u.real > sp->u.real; - sp--; - sp->type = T_NUMBER; - return; + (sp-1)->u.number = (sp-1)->u.real > sp->u.real; + sp--; + sp->type = T_NUMBER; + return; } if ((sp-1)->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_GT, sp-1, sp); i = (sp-1)->u.number > sp->u.number; sp--; @@ -3496,20 +3496,20 @@ f_ge(int num_arg) long long i; if ((sp-1)->type == T_STRING && sp->type == T_STRING) { - i = strcmp((sp-1)->u.string, sp->u.string) >= 0; - pop_n_elems(2); - push_number(i); - return; + i = strcmp((sp-1)->u.string, sp->u.string) >= 0; + pop_n_elems(2); + push_number(i); + return; } if ((sp-1)->type == T_FLOAT && sp->type == T_FLOAT) { - (sp-1)->u.number = (sp-1)->u.real >= sp->u.real; - sp--; - sp->type = T_NUMBER; - return; + (sp-1)->u.number = (sp-1)->u.real >= sp->u.real; + sp--; + sp->type = T_NUMBER; + return; } if ((sp-1)->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_GE, sp-1, sp); i = (sp-1)->u.number >= sp->u.number; sp--; @@ -3523,20 +3523,20 @@ f_lt(int num_arg) long long i; if ((sp-1)->type == T_STRING && sp->type == T_STRING) { - i = strcmp((sp-1)->u.string, sp->u.string) < 0; - pop_n_elems(2); - push_number(i); - return; + i = strcmp((sp-1)->u.string, sp->u.string) < 0; + pop_n_elems(2); + push_number(i); + return; } if ((sp-1)->type == T_FLOAT && sp->type == T_FLOAT) { - (sp-1)->u.number = (sp-1)->u.real < sp->u.real; - sp--; - sp->type = T_NUMBER; - return; + (sp-1)->u.number = (sp-1)->u.real < sp->u.real; + sp--; + sp->type = T_NUMBER; + return; } if ((sp-1)->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_LT, sp-1, sp); i = (sp-1)->u.number < sp->u.number; sp--; @@ -3550,20 +3550,20 @@ f_le(int num_arg) long long i; if ((sp-1)->type == T_STRING && sp->type == T_STRING) { - i = strcmp((sp-1)->u.string, sp->u.string) <= 0; - pop_n_elems(2); - push_number(i); - return; + i = strcmp((sp-1)->u.string, sp->u.string) <= 0; + pop_n_elems(2); + push_number(i); + return; } if ((sp-1)->type == T_FLOAT && sp->type == T_FLOAT) { - (sp-1)->u.number = (sp-1)->u.real <= sp->u.real; - sp--; - sp->type = T_NUMBER; - return; + (sp-1)->u.number = (sp-1)->u.real <= sp->u.real; + sp--; + sp->type = T_NUMBER; + return; } if ((sp-1)->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_LE, sp-1, sp); i = (sp-1)->u.number <= sp->u.number; @@ -3598,11 +3598,11 @@ static void f_not(int num_arg) { if ((sp->type == T_NUMBER && sp->u.number == 0) || - (sp->type == T_FUNCTION && !legal_closure(sp->u.func)) || - (sp->type == T_OBJECT && (sp->u.ob->flags & O_DESTRUCTED))) - assign_svalue(sp, &const1); + (sp->type == T_FUNCTION && !legal_closure(sp->u.func)) || + (sp->type == T_OBJECT && (sp->u.ob->flags & O_DESTRUCTED))) + assign_svalue(sp, &const1); else - assign_svalue(sp, &const0); + assign_svalue(sp, &const0); } /* ARGSUSED */ @@ -3620,8 +3620,8 @@ f_negate(int num_arg) { if (sp->type == T_FLOAT) { - sp->u.real = - sp->u.real; - return; + sp->u.real = - sp->u.real; + return; } if (sp->type != T_NUMBER) bad_arg(1, F_NEGATE, sp); @@ -3633,7 +3633,7 @@ static void f_inc(int num_arg) { if (sp->type != T_LVALUE) - error("Non-lvalue argument to ++\n"); + error("Non-lvalue argument to ++\n"); if (sp->u.lvalue->type != T_NUMBER) bad_arg(1, F_INC, sp->u.lvalue); sp->u.lvalue->u.number++; @@ -3645,7 +3645,7 @@ static void f_dec(int num_arg) { if (sp->type != T_LVALUE) - error("Non-lvalue argument to --\n"); + error("Non-lvalue argument to --\n"); if (sp->u.lvalue->type != T_NUMBER) bad_arg(1, F_DEC, sp->u.lvalue); sp->u.lvalue->u.number--; @@ -3657,7 +3657,7 @@ static void f_post_inc(int num_arg) { if (sp->type != T_LVALUE) - error("Non-lvalue argument to ++\n"); + error("Non-lvalue argument to ++\n"); if (sp->u.lvalue->type != T_NUMBER) bad_arg(1, F_POST_INC, sp->u.lvalue); sp->u.lvalue->u.number++; @@ -3670,7 +3670,7 @@ static void f_post_dec(int num_arg) { if (sp->type != T_LVALUE) - error("Non-lvalue argument to --\n"); + error("Non-lvalue argument to --\n"); if (sp->u.lvalue->type != T_NUMBER) bad_arg(1, F_POST_DEC, sp->u.lvalue); sp->u.lvalue->u.number--; @@ -3690,115 +3690,115 @@ f_call_other(int num_arg) arg = sp - num_arg + 1; if (arg[0].type == T_NUMBER) { - if (arg[0].u.number != 0) - bad_arg(1, F_CALL_OTHER, arg); - pop_n_elems(num_arg); - push_number(0); - return; + if (arg[0].u.number != 0) + bad_arg(1, F_CALL_OTHER, arg); + pop_n_elems(num_arg); + push_number(0); + return; } if (arg[0].type == T_POINTER) { - struct vector *w, *v = allocate_array(num_arg - 2); - int i, j; - - for (i = 0; i < num_arg - 2; i++) - assign_svalue_no_free(&v->item[i], &arg[i + 2]); - pop_n_elems(num_arg - 2); - w = allocate_array(arg[0].u.vec->size); - for (i = 0; i < arg[0].u.vec->size; i++) - { - if (arg[0].u.vec->item[i].type != T_OBJECT && - arg[0].u.vec->item[i].type != T_STRING) - continue; - if (arg[0].u.vec->item[i].type == T_OBJECT) - ob = arg[0].u.vec->item[i].u.ob; - else - ob = find_object(arg[0].u.vec->item[i].u.string); - if (!ob || (ob->flags & O_DESTRUCTED)) - continue; - for (j = 0; j < v->size; j++) - push_svalue(&v->item[j]); + struct vector *w, *v = allocate_array(num_arg - 2); + int i, j; + + for (i = 0; i < num_arg - 2; i++) + assign_svalue_no_free(&v->item[i], &arg[i + 2]); + pop_n_elems(num_arg - 2); + w = allocate_array(arg[0].u.vec->size); + for (i = 0; i < arg[0].u.vec->size; i++) + { + if (arg[0].u.vec->item[i].type != T_OBJECT && + arg[0].u.vec->item[i].type != T_STRING) + continue; + if (arg[0].u.vec->item[i].type == T_OBJECT) + ob = arg[0].u.vec->item[i].u.ob; + else + ob = find_object(arg[0].u.vec->item[i].u.string); + if (!ob || (ob->flags & O_DESTRUCTED)) + continue; + for (j = 0; j < v->size; j++) + push_svalue(&v->item[j]); #ifdef TRACE_CODE - if (TRACEP(TRACE_CALL_OTHER)) - { - char buff[1024]; - (void)sprintf(buff,"%s->%s", ob->name,arg[1].u.string); - do_trace("Call other ", buff, "\n"); - } + if (TRACEP(TRACE_CALL_OTHER)) + { + char buff[1024]; + (void)sprintf(buff,"%s->%s", ob->name,arg[1].u.string); + do_trace("Call other ", buff, "\n"); + } #endif - if (apply_low(arg[1].u.string, ob, v->size, 1) == 0) - continue; /* function not found */ - w->item[i] = *sp--; - } + if (apply_low(arg[1].u.string, ob, v->size, 1) == 0) + continue; /* function not found */ + w->item[i] = *sp--; + } - pop_n_elems(2); - push_vector(w, FALSE); - free_vector(v); - return; + pop_n_elems(2); + push_vector(w, FALSE); + free_vector(v); + return; } if (arg[0].type == T_MAPPING) { - struct vector *w, *v = allocate_array(num_arg - 2); - struct vector *ix, *o; - int i, j; - - ix = map_domain(arg[0].u.map); - o = map_codomain(arg[0].u.map); - for (i = 0; i < num_arg - 2; i++) - assign_svalue_no_free(&v->item[i], &arg[i + 2]); - pop_n_elems(num_arg - 2); - w = allocate_array(o->size); - for (i = 0; i < o->size; i++) - { - if (o->item[i].type != T_OBJECT && - o->item[i].type != T_STRING) - continue; - if (o->item[i].type == T_OBJECT) - ob = o->item[i].u.ob; - else - ob = find_object(o->item[i].u.string); - if (!ob || (ob->flags & O_DESTRUCTED)) - continue; - for (j = 0; j < v->size; j++) - push_svalue(&v->item[j]); + struct vector *w, *v = allocate_array(num_arg - 2); + struct vector *ix, *o; + int i, j; + + ix = map_domain(arg[0].u.map); + o = map_codomain(arg[0].u.map); + for (i = 0; i < num_arg - 2; i++) + assign_svalue_no_free(&v->item[i], &arg[i + 2]); + pop_n_elems(num_arg - 2); + w = allocate_array(o->size); + for (i = 0; i < o->size; i++) + { + if (o->item[i].type != T_OBJECT && + o->item[i].type != T_STRING) + continue; + if (o->item[i].type == T_OBJECT) + ob = o->item[i].u.ob; + else + ob = find_object(o->item[i].u.string); + if (!ob || (ob->flags & O_DESTRUCTED)) + continue; + for (j = 0; j < v->size; j++) + push_svalue(&v->item[j]); #ifdef TRACE_CODE - if (TRACEP(TRACE_CALL_OTHER)) - { - char buff[1024]; - (void)sprintf(buff,"%s->%s", ob->name, arg[1].u.string); - do_trace("Call other ", buff, "\n"); - } + if (TRACEP(TRACE_CALL_OTHER)) + { + char buff[1024]; + (void)sprintf(buff,"%s->%s", ob->name, arg[1].u.string); + do_trace("Call other ", buff, "\n"); + } #endif - if (apply_low(arg[1].u.string, ob, v->size, 1) == 0) - continue; /* function not found */ - w->item[i] = *sp--; - } - - pop_n_elems(2); - push_mapping(make_mapping(ix,w), FALSE); - free_vector(o); - free_vector(ix); - free_vector(v); - free_vector(w); - return; + if (apply_low(arg[1].u.string, ob, v->size, 1) == 0) + continue; /* function not found */ + w->item[i] = *sp--; + } + + pop_n_elems(2); + push_mapping(make_mapping(ix,w), FALSE); + free_vector(o); + free_vector(ix); + free_vector(v); + free_vector(w); + return; } if (arg[0].type == T_OBJECT) - ob = arg[0].u.ob; + ob = arg[0].u.ob; else { - ob = find_object(arg[0].u.string); - if (ob == 0) - error("call_other() failed\n"); + ob = find_object(arg[0].u.string); + if (ob == 0) + error("call_other() failed\n"); } if (current_object->flags & O_DESTRUCTED) { - /* - * No external calls may be done when this object is - * destructed. - */ - pop_n_elems(num_arg); - push_number(0); - return; + /* + * No external calls may be done when this object is + * destructed. + */ + pop_n_elems(num_arg); + push_number(0); + return; } /* * Send the remaining arguments to the function. @@ -3806,27 +3806,27 @@ f_call_other(int num_arg) #ifdef TRACE_CODE if (TRACEP(TRACE_CALL_OTHER)) { - char buff[1024]; - (void)sprintf(buff,"%s->%s", ob->name, arg[1].u.string); - do_trace("Call other ", buff, "\n"); + char buff[1024]; + (void)sprintf(buff,"%s->%s", ob->name, arg[1].u.string); + do_trace("Call other ", buff, "\n"); } #endif if (apply_low(arg[1].u.string, ob, num_arg - 2, 1) == 0) { - /* Function not found */ - pop_n_elems(2); - push_number(0); - return; + /* Function not found */ + pop_n_elems(2); + push_number(0); + return; } /* * The result of the function call is on the stack. But, so * is the function name and object that was called. * These have to be removed. */ - svp = sp--; /* Copy the function call result */ - pop_n_elems(2); /* Remove old arguments to call_other */ - *++sp = *svp; /* Re-insert function result */ + svp = sp--; /* Copy the function call result */ + pop_n_elems(2); /* Remove old arguments to call_other */ + *++sp = *svp; /* Re-insert function result */ } /* ARGSUSED */ @@ -3842,7 +3842,7 @@ f_call_otherv(int xxx) num_arg = argv->size + 2; for(i = 0; i < argv->size; i++) { - push_svalue(&argv->item[i]); + push_svalue(&argv->item[i]); } free_vector(argv); f_call_other(num_arg); @@ -3856,12 +3856,12 @@ f_object_time(int num_arg) if (sp->type == T_OBJECT) { - i = sp->u.ob->created; - pop_stack(); - push_number(i); + i = sp->u.ob->created; + pop_stack(); + push_number(i); } else - assign_svalue(sp, &const0); + assign_svalue(sp, &const0); } /* ARGSUSED */ @@ -3924,12 +3924,12 @@ f_function_name(int num_arg) char *p; if (!legal_closure(sp->u.func)) - assign_svalue(sp, &const0); + assign_svalue(sp, &const0); else { - p = make_mstring(show_closure(sp->u.func)); - pop_stack(); - push_mstring(p); + p = make_mstring(show_closure(sp->u.func)); + pop_stack(); + push_mstring(p); } } @@ -3941,7 +3941,7 @@ f_functionp(int num_arg) ret = 0; if (sp->type == T_FUNCTION) - ret = legal_closure(sp->u.func); + ret = legal_closure(sp->u.func); assign_svalue(sp, ret ? &const1 : &const0); } @@ -3955,38 +3955,38 @@ f_extract(int num_arg) arg = sp - num_arg + 1; len = strlen(arg[0].u.string); if (num_arg == 1) - return; /* Simply return argument */ + return; /* Simply return argument */ from = arg[1].u.number; if (from < 0) - from = len + from; + from = len + from; if (from >= len) { - pop_n_elems(num_arg); - push_string("", STRING_CSTRING); - return; + pop_n_elems(num_arg); + push_string("", STRING_CSTRING); + return; } if (num_arg == 2) { - res = make_mstring(arg->u.string + from); - pop_n_elems(2); - push_mstring(res); - return; + res = make_mstring(arg->u.string + from); + pop_n_elems(2); + push_mstring(res); + return; } if (arg[2].type != T_NUMBER) - error("Bad third argument to extract()\n"); + error("Bad third argument to extract()\n"); to = arg[2].u.number; if (to < 0) - to = len + to; + to = len + to; if (to < from) { - pop_n_elems(3); - push_string("", STRING_CSTRING); - return; + pop_n_elems(3); + push_string("", STRING_CSTRING); + return; } if (to >= len) - to = len-1; + to = len-1; if (to == len-1) { - res = make_mstring(arg->u.string + from); - pop_n_elems(3); - push_mstring(res); - return; + res = make_mstring(arg->u.string + from); + pop_n_elems(3); + push_mstring(res); + return; } res = allocate_mstring((size_t)(to - from + 1)); (void)strncpy(res, arg[0].u.string + from, (size_t)(to - from + 1)); @@ -4004,51 +4004,51 @@ f_range(int num_arg) if (sp[0].type != T_NUMBER) bad_arg(3, F_RANGE, sp); if (sp[-2].type == T_POINTER) { - struct vector *v; - - v = slice_array(sp[-2].u.vec, sp[-1].u.number, sp[0].u.number); - pop_n_elems(3); - if (v) { - push_vector(v, FALSE); - } else { - push_number(0); - } + struct vector *v; + + v = slice_array(sp[-2].u.vec, sp[-1].u.number, sp[0].u.number); + pop_n_elems(3); + if (v) { + push_vector(v, FALSE); + } else { + push_number(0); + } } else if (sp[-2].type == T_STRING) { - int len, from, to; - char *res; - - len = strlen(sp[-2].u.string); - from = sp[-1].u.number; - if (from < 0) - from = len + from; - if (from < 0) - from = 0; - if (from >= len) { - pop_n_elems(3); - push_string("", STRING_CSTRING); - return; - } - to = sp[0].u.number; - if (to < 0) - to = len + to; - if (to < from) { - pop_n_elems(3); - push_string("", STRING_CSTRING); - return; - } - if (to >= len) - to = len - 1; - if (to == len - 1) { - res = make_mstring(sp[-2].u.string + from); - pop_n_elems(3); - push_mstring(res); - return; - } - res = allocate_mstring((size_t)(to - from + 1)); - (void)strncpy(res, sp[-2].u.string + from, (size_t)(to - from + 1)); - res[to - from + 1] = '\0'; - pop_n_elems(3); - push_mstring(res); + int len, from, to; + char *res; + + len = strlen(sp[-2].u.string); + from = sp[-1].u.number; + if (from < 0) + from = len + from; + if (from < 0) + from = 0; + if (from >= len) { + pop_n_elems(3); + push_string("", STRING_CSTRING); + return; + } + to = sp[0].u.number; + if (to < 0) + to = len + to; + if (to < from) { + pop_n_elems(3); + push_string("", STRING_CSTRING); + return; + } + if (to >= len) + to = len - 1; + if (to == len - 1) { + res = make_mstring(sp[-2].u.string + from); + pop_n_elems(3); + push_mstring(res); + return; + } + res = allocate_mstring((size_t)(to - from + 1)); + (void)strncpy(res, sp[-2].u.string + from, (size_t)(to - from + 1)); + res[to - from + 1] = '\0'; + pop_n_elems(3); + push_mstring(res); } else { @@ -4072,8 +4072,8 @@ static void f_query_trigverb(int num_arg) { if (trig_verb == 0) { - push_number(0); - return; + push_number(0); + return; } push_string(trig_verb, STRING_MSTRING); } @@ -4085,10 +4085,10 @@ f_exec(int num_arg) int i; if ((sp-1)->type == T_NUMBER) - i = replace_interactive(0, sp->u.ob, current_prog->name); + i = replace_interactive(0, sp->u.ob, current_prog->name); else - i = replace_interactive((sp-1)->u.ob, sp->u.ob, - current_prog->name); + i = replace_interactive((sp-1)->u.ob, sp->u.ob, + current_prog->name); pop_stack(); pop_stack(); push_number(i); @@ -4115,13 +4115,13 @@ f_users(int num_arg) if (current_object != master_ob) { - push_object(current_object); - ret = apply_master_ob(M_VALID_USERS, 1); - if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) - { - push_number(0); - return; - } + push_object(current_object); + ret = apply_master_ob(M_VALID_USERS, 1); + if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) + { + push_number(0); + return; + } } push_vector(users(), FALSE); } @@ -4136,51 +4136,51 @@ f_set_alarm(int num_arg) struct object *ob; if (num_arg == 3 && arg[2].type == T_FUNCTION) { - ; + ; } else if (num_arg >= 3 && arg[2].type == T_STRING) { - struct closure *fun; - - if (*(arg[2].u.string) == '.') { - pop_n_elems(num_arg); - push_number(0); - return; - } - - /* Fake a function */ - fun = alloc_objclosurestr(FUN_LFUNO, arg[2].u.string, current_object, "f_set_alarm", 0); - if (!fun) { - pop_n_elems(num_arg); - push_number(0); - return; - } - free_vector(fun->funargs); - fun->funargs = allocate_array(num_arg - 3); - (void)memcpy(&fun->funargs->item[0], &arg[3], (num_arg - 3) * sizeof(struct svalue)); - - sp = &arg[2]; - free_svalue(&arg[2]); /* release old stack location */ - arg[2].type = T_FUNCTION; - arg[2].u.func = fun; /* and put in a new one */ - - WARNOBSOLETE(current_object, "string as function in set_alarm"); - } else - bad_arg(3, F_SET_ALARM, arg + 2); + struct closure *fun; - f = arg[2].u.func; + if (*(arg[2].u.string) == '.') { + pop_n_elems(num_arg); + push_number(0); + return; + } + + /* Fake a function */ + fun = alloc_objclosurestr(FUN_LFUNO, arg[2].u.string, current_object, "f_set_alarm", 0); + if (!fun) { + pop_n_elems(num_arg); + push_number(0); + return; + } + free_vector(fun->funargs); + fun->funargs = allocate_array(num_arg - 3); + (void)memcpy(&fun->funargs->item[0], &arg[3], (num_arg - 3) * sizeof(struct svalue)); + + sp = &arg[2]; + free_svalue(&arg[2]); /* release old stack location */ + arg[2].type = T_FUNCTION; + arg[2].u.func = fun; /* and put in a new one */ + + WARNOBSOLETE(current_object, "string as function in set_alarm"); + } else + bad_arg(3, F_SET_ALARM, arg + 2); + + f = arg[2].u.func; ob = f->funobj; if (f->funtype == FUN_EFUN || !ob) - error("set_alarm can only be called with a local function."); + error("set_alarm can only be called with a local function."); if (!(ob->flags & O_DESTRUCTED)) { delay = 0.0; reload = -1.0; if (arg[0].u.real >= 0.0) - delay = arg[0].u.real; + delay = arg[0].u.real; if (arg[1].u.real > 0.0) - reload = arg[1].u.real; - ret = new_call_out(f, delay, reload); + reload = arg[1].u.real; + ret = new_call_out(f, delay, reload); } else - ret = 0; + ret = 0; pop_n_elems(3); push_number(ret); } @@ -4204,28 +4204,28 @@ f_set_alarmv(int xxx) if (*(arg[2].u.string) == '.') { - pop_n_elems(num_arg); - push_number(0); - return; + pop_n_elems(num_arg); + push_number(0); + return; } { - struct closure *fun; + struct closure *fun; - /* Fake a function */ - fun = alloc_objclosurestr(FUN_LFUNO, arg[2].u.string, current_object, "f_set_alarmv", 0); - if (!fun) { - pop_n_elems(num_arg); - push_number(0); - return; - } - free_vector(fun->funargs); - fun->funargs = arg[3].u.vec; - INCREF(fun->funargs->ref); + /* Fake a function */ + fun = alloc_objclosurestr(FUN_LFUNO, arg[2].u.string, current_object, "f_set_alarmv", 0); + if (!fun) { + pop_n_elems(num_arg); + push_number(0); + return; + } + free_vector(fun->funargs); + fun->funargs = arg[3].u.vec; + INCREF(fun->funargs->ref); - free_svalue(&arg[2]); /* release old stack location */ - arg[2].type = T_FUNCTION; - arg[2].u.func = fun; /* and put in a new one */ + free_svalue(&arg[2]); /* release old stack location */ + arg[2].type = T_FUNCTION; + arg[2].u.func = fun; /* and put in a new one */ } f = arg[2].u.func; @@ -4235,12 +4235,12 @@ f_set_alarmv(int xxx) delay = 0.0; reload = -1.0; if (arg[0].u.real >= 0.0) - delay = arg[0].u.real; + delay = arg[0].u.real; if (arg[1].u.real > 0.0) - reload = arg[1].u.real; - ret = new_call_out(f, delay, reload); + reload = arg[1].u.real; + ret = new_call_out(f, delay, reload); } else - ret = 0; + ret = 0; pop_n_elems(num_arg); push_number(ret); } @@ -4263,10 +4263,10 @@ f_get_all_alarms(int num_arg) ret = get_calls(current_object); if (ret) { - push_vector(ret, FALSE); + push_vector(ret, FALSE); } else - push_number(0); + push_number(0); } /* ARGSUSED */ @@ -4279,10 +4279,10 @@ f_get_alarm(int num_arg) pop_stack(); if (ret) { - push_vector(ret, FALSE); + push_vector(ret, FALSE); } else - push_number(0); + push_number(0); } @@ -4294,14 +4294,14 @@ f_set_screen_width(int num_arg) long long col; if (! current_object->interactive) - return; + return; col = sp->u.number; if (col < 0 || col == 1|| col > (1 << 30)) - error("Nonsensical screen width\n"); + error("Nonsensical screen width\n"); current_object->interactive->screen_width = col; if (current_object->interactive->current_column >= - col) - current_object->interactive->current_column = col - 1; + col) + current_object->interactive->current_column = col - 1; /* Return first argument */ } @@ -4314,7 +4314,7 @@ f_query_screen_width(int num_arg) i = -1; if (current_object->interactive) - i = current_object->interactive->screen_width; + i = current_object->interactive->screen_width; push_number(i); } #endif @@ -4331,12 +4331,12 @@ f_sprintf(int num_arg) */ s = string_print_formatted(1, (sp-num_arg+1)->u.string, - num_arg-1, sp-num_arg+2); + num_arg-1, sp-num_arg+2); pop_n_elems(num_arg); if (s == NULL) - push_number(0); + push_number(0); else - push_string(s, STRING_MSTRING); + push_string(s, STRING_MSTRING); } /* ARGSUSED */ @@ -4344,22 +4344,22 @@ static void f_member_array(int num_arg) { struct vector *v; - int i; + int i; if (sp->type == T_NUMBER) { - pop_n_elems(2); - push_number(-1); - return; + pop_n_elems(2); + push_number(-1); + return; } v = sp->u.vec; check_for_destr(sp); for (i=0; i < v->size; i++) { - if (equal_svalue(&v->item[i], sp - 1)) - break; + if (equal_svalue(&v->item[i], sp - 1)) + break; } if (i == v->size) - i = -1; /* Return -1 for failure */ + i = -1; /* Return -1 for failure */ pop_n_elems(2); push_number(i); } @@ -4371,17 +4371,17 @@ f_move_object(int num_arg) struct svalue *ret; if (sp->type == T_OBJECT) - ob = sp->u.ob; + ob = sp->u.ob; else - ob = find_object(sp->u.string); + ob = find_object(sp->u.string); push_object(current_object); push_object(ob); ret = apply_master_ob(M_VALID_MOVE, 2); if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) { - pop_n_elems(num_arg); /* Get rid of all arguments */ - push_number(0); - return; + pop_n_elems(num_arg); /* Get rid of all arguments */ + push_number(0); + return; } move_object(ob); } @@ -4403,17 +4403,17 @@ f_function_exists(int num_arg) str = function_exists((sp-1)->u.string, sp->u.ob); pop_n_elems(2); if (str) { - len = strlen(str); - res = strrchr(str, '.'); - if (res != NULL) - len = res - str; - res = allocate_mstring(len + 1); - res[0] = '/'; - (void)memcpy(&res[1], str, len); - res[len + 1] = '\0'; - push_mstring(res); + len = strlen(str); + res = strrchr(str, '.'); + if (res != NULL) + len = res - str; + res = allocate_mstring(len + 1); + res[0] = '/'; + (void)memcpy(&res[1], str, len); + res[len + 1] = '\0'; + push_mstring(res); } else { - push_number(0); + push_number(0); } } @@ -4428,27 +4428,27 @@ f_snoop(int num_arg) */ if (!command_giver) { - pop_n_elems(num_arg); - push_number(0); + pop_n_elems(num_arg); + push_number(0); } else { - ob = 0; /* Do not remove this, it is not 0 by default */ - switch (num_arg) { - case 1: - if (set_snoop(sp->u.ob, 0)) - ob = sp->u.ob; - break; - case 2: - if (set_snoop((sp-1)->u.ob, sp->u.ob)) - ob = sp->u.ob; - break; - default: - ob = 0; - break; - } - pop_n_elems(num_arg); - push_object(ob); + ob = 0; /* Do not remove this, it is not 0 by default */ + switch (num_arg) { + case 1: + if (set_snoop(sp->u.ob, 0)) + ob = sp->u.ob; + break; + case 2: + if (set_snoop((sp-1)->u.ob, sp->u.ob)) + ob = sp->u.ob; + break; + default: + ob = 0; + break; + } + pop_n_elems(num_arg); + push_object(ob); } } @@ -4459,29 +4459,29 @@ f_add_action(int num_arg) int flag; if (num_arg == 3) { - if (arg[2].type != T_NUMBER) - bad_arg(3, F_ADD_ACTION, arg + 2); + if (arg[2].type != T_NUMBER) + bad_arg(3, F_ADD_ACTION, arg + 2); } if (arg[0].type == T_FUNCTION) { - ; + ; } else if (arg[0].type == T_STRING) { - struct closure *fun; - - WARNOBSOLETE(current_object, "string function in add_action"); - - fun = alloc_objclosurestr(FUN_LFUNO, arg[0].u.string, current_object, "f_add_action", 1); - if (!fun) { - (void)fprintf(stderr, "add_action failed: %s(verb=%s) in %s\n", - arg[0].u.string, arg[1].u.string, current_object->name); - pop_n_elems(num_arg); - push_number(0); /* XXX error? */ - return; - } - free_svalue(&arg[0]); /* release old stack location */ - arg[0].type = T_FUNCTION; - arg[0].u.func = fun; /* and put in a new one */ + struct closure *fun; + + WARNOBSOLETE(current_object, "string function in add_action"); + + fun = alloc_objclosurestr(FUN_LFUNO, arg[0].u.string, current_object, "f_add_action", 1); + if (!fun) { + (void)fprintf(stderr, "add_action failed: %s(verb=%s) in %s\n", + arg[0].u.string, arg[1].u.string, current_object->name); + pop_n_elems(num_arg); + push_number(0); /* XXX error? */ + return; + } + free_svalue(&arg[0]); /* release old stack location */ + arg[0].type = T_FUNCTION; + arg[0].u.func = fun; /* and put in a new one */ } else - bad_arg(1, F_ADD_ACTION, arg); + bad_arg(1, F_ADD_ACTION, arg); flag = 0; if (num_arg > 2) { @@ -4491,7 +4491,7 @@ f_add_action(int num_arg) flag = 1; } add_action(arg[0].u.func, - num_arg > 1 ? &arg[1] : (struct svalue *)0, flag); + num_arg > 1 ? &arg[1] : (struct svalue *)0, flag); pop_n_elems(num_arg - 1); } @@ -4510,26 +4510,26 @@ static void f_ed(int num_arg) { if (num_arg == 0) { - push_number(0); + push_number(0); } else if (num_arg == 1) { - ed_start(sp->u.string, 0); + ed_start(sp->u.string, 0); } else if (num_arg == 2 && sp->type == T_FUNCTION) { - struct closure *f = sp->u.func; - INCREF(f->ref); - ed_start((sp-1)->u.string, f); - pop_stack(); /* remove function from stack */ + struct closure *f = sp->u.func; + INCREF(f->ref); + ed_start((sp-1)->u.string, f); + pop_stack(); /* remove function from stack */ } else if (num_arg == 2 && sp->type == T_STRING) { - struct closure *f = alloc_objclosurestr(FUN_LFUNO, sp->u.string, current_object, "f_ed", 1); - WARNOBSOLETE(current_object, "string function in ed"); - if (!f) { - pop_n_elems(num_arg); - push_number(0); - return; - } - ed_start((sp-1)->u.string, f); - pop_stack(); + struct closure *f = alloc_objclosurestr(FUN_LFUNO, sp->u.string, current_object, "f_ed", 1); + WARNOBSOLETE(current_object, "string function in ed"); + if (!f) { + pop_n_elems(num_arg); + push_number(0); + return; + } + ed_start((sp-1)->u.string, f); + pop_stack(); } else - error("Bad arg to ed()\n"); + error("Bad arg to ed()\n"); } static char * @@ -4560,12 +4560,12 @@ f_crypt(int num_arg) push_object(current_object); push_svalue(&arg[1]); - struct svalue *ret = apply_master_ob(M_VALID_CRYPT, 2); - if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) - { + struct svalue *ret = apply_master_ob(M_VALID_CRYPT, 2); + if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) + { error("Access to crypt() was denied"); - return; - } + return; + } if (num_arg > 2 && arg[2].type == T_NUMBER) generate_salt = sp->u.number; @@ -4714,7 +4714,7 @@ f_foreach(int num_arg) #define ISEMPTY(ob) (ob.type == T_FUNCTION && ob.u.func->funtype == FUN_EMPTY) static void -papply(int num_arg) /* num_arg does not include the function */ +papply(int num_arg) /* num_arg does not include the function */ { int nargs, i, j; struct closure *f, *oldf; @@ -4728,7 +4728,7 @@ papply(int num_arg) /* num_arg does not include the function */ oldf = (sp-num_arg)->u.func; #ifdef FUNCDEBUG if (oldf->magic != FUNMAGIC || oldf->ref == 0 || oldf->ref > 100) - fatal("Bad function argument to papply\n"); + fatal("Bad function argument to papply\n"); #endif f = alloc_closure(oldf->funtype); #ifdef DEBUG @@ -4745,31 +4745,31 @@ papply(int num_arg) /* num_arg does not include the function */ nargs = oldf->funargs->size; /* compute the size needed for the new vector */ for(i = j = 0; i < nargs; i++) { - if (ISEMPTY(oldf->funargs->item[i])) - j++; /* need an argument to fill the slot */ + if (ISEMPTY(oldf->funargs->item[i])) + j++; /* need an argument to fill the slot */ } newsize = nargs; if (j < num_arg) - newsize += num_arg-j; + newsize += num_arg-j; free_vector(f->funargs); f->funargs = items = allocate_array(newsize); /* march down and fill the slots */ for(j = i = 0; i < nargs; i++) { - if (ISEMPTY(oldf->funargs->item[i]) && j < num_arg) { - assign_svalue_no_free(&items->item[i], &args[j++]); - } else { - assign_svalue_no_free(&items->item[i], &oldf->funargs->item[i]); - } + if (ISEMPTY(oldf->funargs->item[i]) && j < num_arg) { + assign_svalue_no_free(&items->item[i], &args[j++]); + } else { + assign_svalue_no_free(&items->item[i], &oldf->funargs->item[i]); + } } /* now do the remaining slots */ for(; j < num_arg; j++) - assign_svalue(&items->item[i++], &args[j]); + assign_svalue(&items->item[i++], &args[j]); if (i != newsize) - fatal("papply\n"); + fatal("papply\n"); - pop_n_elems(num_arg+1); /* remove function and args */ + pop_n_elems(num_arg+1); /* remove function and args */ push_function(f, FALSE); } @@ -4794,16 +4794,16 @@ f_papplyv(int xxx) int i, size; if (arg[0].type != T_FUNCTION) - fatal("Non-function in f_papply_array\n"); + fatal("Non-function in f_papply_array\n"); if (arg[1].type != T_POINTER) - fatal("Non-array in f_papply_array\n"); + fatal("Non-array in f_papply_array\n"); v = arg[1].u.vec; - INCREF(v->ref); /* we pop it below */ - pop_n_elems(num_arg-1); /* remove all except function */ + INCREF(v->ref); /* we pop it below */ + pop_n_elems(num_arg-1); /* remove all except function */ size = v->size; for(i = 0; i < size; i++) - push_svalue(&v->item[i]); - free_vector(v); /* and free it now */ + push_svalue(&v->item[i]); + free_vector(v); /* and free it now */ papply(size); } @@ -4811,17 +4811,17 @@ char * getclosurename(struct closure *f) { if (f->funtype == FUN_EFUN) - return get_f_name(f->funno); + return get_f_name(f->funno); else if (f->funtype == FUN_COMPOSE) - return "@"; + return "@"; else if (f->funtype == FUN_EMPTY) - return "_"; + return "_"; else { - struct object *ob = f->funobj; + struct object *ob = f->funobj; - if (ob->flags & O_DESTRUCTED) - return "<>"; - return ob->prog->inherit[f->funinh].prog->functions[f->funno].name; + if (ob->flags & O_DESTRUCTED) + return "<>"; + return ob->prog->inherit[f->funinh].prog->functions[f->funno].name; } } @@ -4835,66 +4835,66 @@ write_closure(struct closure *f, char *buf, const char *end) if (f->funtype == FUN_EMPTY) { - if (buf < end) - *buf++ = '_'; - *buf = '\0'; - return buf; + if (buf < end) + *buf++ = '_'; + *buf = '\0'; + return buf; } name = getclosurename(f); if (f->funtype == FUN_COMPOSE) { - buf = write_closure(f->funargs->item[1].u.func, buf, end); - if (buf < end) - *buf++ = ' '; - if (buf < end) - *buf++ = '@'; - if (buf < end) - *buf++ = ' '; - buf = write_closure(f->funargs->item[0].u.func, buf, end); - *buf = '\0'; - return buf; + buf = write_closure(f->funargs->item[1].u.func, buf, end); + if (buf < end) + *buf++ = ' '; + if (buf < end) + *buf++ = '@'; + if (buf < end) + *buf++ = ' '; + buf = write_closure(f->funargs->item[0].u.func, buf, end); + *buf = '\0'; + return buf; } if (f->funargs && f->funargs->size && buf < end) - *buf++ = '&'; + *buf++ = '&'; if (f->funobj) { - if (buf + 3 < end) - { - (void)sprintf(buf, "\"/%.*s\"", (int)(end - buf), f->funobj->name); - buf += strlen(buf); - } - if (buf < end) - *buf++ = '-'; - if (buf < end) - *buf++ = '>'; - if (buf < end) - { - (void)sprintf(buf, "%.*s", (int)(end - buf), name); - buf += strlen(buf); - } + if (buf + 3 < end) + { + (void)sprintf(buf, "\"/%.*s\"", (int)(end - buf), f->funobj->name); + buf += strlen(buf); + } + if (buf < end) + *buf++ = '-'; + if (buf < end) + *buf++ = '>'; + if (buf < end) + { + (void)sprintf(buf, "%.*s", (int)(end - buf), name); + buf += strlen(buf); + } } else if (buf < end) { - (void)sprintf(buf, "%.*s", (int)(end - buf), name); - buf += strlen(buf); + (void)sprintf(buf, "%.*s", (int)(end - buf), name); + buf += strlen(buf); } if (f->funargs && f->funargs->size) { - if (buf < end) - *buf++ = '('; - for (i = 0; i < f->funargs->size; i++) - { - if (ISEMPTY(f->funargs->item[i]) && buf < end) - *buf++ = '_'; - else if (buf < end) - *buf++ = '?'; - if (i < f->funargs->size - 1 && buf < end) - *buf++ = ','; - if (buf >= end) - break; - } - if (buf < end) - *buf++ = ')'; + if (buf < end) + *buf++ = '('; + for (i = 0; i < f->funargs->size; i++) + { + if (ISEMPTY(f->funargs->item[i]) && buf < end) + *buf++ = '_'; + else if (buf < end) + *buf++ = '?'; + if (i < f->funargs->size - 1 && buf < end) + *buf++ = ','; + if (buf >= end) + break; + } + if (buf < end) + *buf++ = ')'; } *buf = '\0'; return buf; @@ -4919,11 +4919,11 @@ call_var(int num_arg, struct closure *f) struct svalue *insp = sp - num_arg; if (!f) - fatal("NULL closure in call_var\n"); + fatal("NULL closure in call_var\n"); #ifdef FUNCDEBUG if (f->magic != FUNMAGIC || f->ref == 0 || f->ref > 100) - fatal("Bad closure in call_var\n"); + fatal("Bad closure in call_var\n"); #endif efun = -1; ob = 0; @@ -4932,20 +4932,20 @@ call_var(int num_arg, struct closure *f) case FUN_LFUNO: case FUN_LFUN: case FUN_SFUN: - ob = f->funobj; - break; + ob = f->funobj; + break; case FUN_EFUN: - efun = f->funno; - break; + efun = f->funno; + break; case FUN_EMPTY: - error("Calling EMPTY closure\n"); - break; + error("Calling EMPTY closure\n"); + break; case FUN_COMPOSE: - return call_var(num_arg, f->funargs->item[0].u.func) && - call_var(1, f->funargs->item[1].u.func); + return call_var(num_arg, f->funargs->item[0].u.func) && + call_var(1, f->funargs->item[1].u.func); default: - fatal("bad type in call_var\n"); - break; + fatal("bad type in call_var\n"); + break; } #ifdef DEBUG #if 0 @@ -4953,63 +4953,63 @@ call_var(int num_arg, struct closure *f) #endif #endif if (!ob && efun == -1) { - error("ob=0 in call_var\n"); + error("ob=0 in call_var\n"); } if (ob && (ob->flags & O_DESTRUCTED)) { - error("Call to function in destructed object\n"); + error("Call to function in destructed object\n"); } narg = f->funargs->size; if (narg) { - struct svalue *arg; - int emptyargs; - - /* count the number of empty args */ - for(emptyargs = i = 0; i < narg; i++) - if (ISEMPTY(f->funargs->item[i])) - emptyargs++; - - if (emptyargs > num_arg) { - (void)fprintf(stderr, "bad call empty=%d, num=%d, f=%s\n", - emptyargs, num_arg, show_closure(f)); - error("Too few arguments supplied in function call\n"); - } - - probe_stack(narg); - - /* Need to shuffle the stack, move up all the arguments narg slots */ - /* to be safe. */ - for(i = 0; i < num_arg; i++) - sp[-i+narg] = sp[-i]; - sp -= num_arg; /* move sp temporarily */ - arg = (sp + 1) + narg; /* new postion of given args */ - - /* now we need to push the funargs, but only in the filled slots */ - for(i = 0; i < narg; i++) { - if (ISEMPTY(f->funargs->item[i])) { - *++sp = *arg++; /* copy from stack */ - } else { - push_svalue(&f->funargs->item[i]); - } - } - - /* The remaining stack arguments now need to be moved into - place. emptyargs have already been moved, go on until - num_arg. - */ - for(i = emptyargs; i < num_arg; i++) - *++sp = *arg++; - - num_arg += narg - emptyargs; + struct svalue *arg; + int emptyargs; + + /* count the number of empty args */ + for(emptyargs = i = 0; i < narg; i++) + if (ISEMPTY(f->funargs->item[i])) + emptyargs++; + + if (emptyargs > num_arg) { + (void)fprintf(stderr, "bad call empty=%d, num=%d, f=%s\n", + emptyargs, num_arg, show_closure(f)); + error("Too few arguments supplied in function call\n"); + } + + probe_stack(narg); + + /* Need to shuffle the stack, move up all the arguments narg slots */ + /* to be safe. */ + for(i = 0; i < num_arg; i++) + sp[-i+narg] = sp[-i]; + sp -= num_arg; /* move sp temporarily */ + arg = (sp + 1) + narg; /* new postion of given args */ + + /* now we need to push the funargs, but only in the filled slots */ + for(i = 0; i < narg; i++) { + if (ISEMPTY(f->funargs->item[i])) { + *++sp = *arg++; /* copy from stack */ + } else { + push_svalue(&f->funargs->item[i]); + } + } + + /* The remaining stack arguments now need to be moved into + place. emptyargs have already been moved, go on until + num_arg. + */ + for(i = emptyargs; i < num_arg; i++) + *++sp = *arg++; + + num_arg += narg - emptyargs; } if (ob) { - /* speed up call by only doing access_* when really needed */ - if (f->funno == 65535) - fatal("bad function index\n"); - call_function(ob, f->funinh, (unsigned int)f->funno, num_arg); + /* speed up call by only doing access_* when really needed */ + if (f->funno == 65535) + fatal("bad function index\n"); + call_function(ob, f->funinh, (unsigned int)f->funno, num_arg); } else { - /*(void)fprintf(stderr, "call efun %d %d\n", efun, num_arg);*/ - call_efun(efun, num_arg); + /*(void)fprintf(stderr, "call efun %d %d\n", efun, num_arg);*/ + call_efun(efun, num_arg); } if (sp-1 != insp) @@ -5029,15 +5029,15 @@ f_call_var(int xxx) pc++; if (sp->type != T_FUNCTION) - error("Bad function argument in function call.\n"); + error("Bad function argument in function call.\n"); f = sp->u.func; - sp--; /* pop function argument, but don't free it */ + sp--; /* pop function argument, but don't free it */ /*(void)printf("call_var in %d %s\n", num_arg, show_closure(f));*/ r = call_var(num_arg, f); /*(void)printf("call_var out %d %s\n", num_arg, show_closure(f));*/ - free_closure(f); /* hmm, what if we abort? f leaks. */ + free_closure(f); /* hmm, what if we abort? f leaks. */ if (!r) - error("Call of function failed\n"); + error("Call of function failed\n"); } #ifdef FUNCDEBUG @@ -5071,27 +5071,27 @@ legal_closure(struct closure *fun) { #ifdef FUNCDEBUG if (fun->magic != FUNMAGIC || fun->ref == 0 || fun->ref > 100) - fatal("Bad function in legal_closure\n"); + fatal("Bad function in legal_closure\n"); #endif #ifdef DEBUG switch (fun->funtype) { - case FUN_LFUN: - case FUN_SFUN: - case FUN_EFUN: - case FUN_LFUNO: - case FUN_COMPOSE: - break; - default: - fatal("Bad function type in legal_closure\n"); - /* NOTREACHED */ + case FUN_LFUN: + case FUN_SFUN: + case FUN_EFUN: + case FUN_LFUNO: + case FUN_COMPOSE: + break; + default: + fatal("Bad function type in legal_closure\n"); + /* NOTREACHED */ } #endif if (fun->funobj && (fun->funobj->flags & O_DESTRUCTED)) - return 0; + return 0; if (fun->funtype == FUN_COMPOSE) - return legal_closure(fun->funargs->item[0].u.func) && - legal_closure(fun->funargs->item[1].u.func); + return legal_closure(fun->funargs->item[0].u.func) && + legal_closure(fun->funargs->item[1].u.func); return 1; } @@ -5106,10 +5106,10 @@ clear_closure_cache() int i; for (i = 0; i < FUNCCACHE; i++) - if (funccache[i]) { - free_closure(funccache[i]); - funccache[i] = NULL; - } + if (funccache[i]) { + free_closure(funccache[i]); + funccache[i] = NULL; + } } #endif @@ -5123,39 +5123,39 @@ alloc_objclosure(int ftype, int inh, int no, struct object *ob, char *refstr, in fatal("Empty closure allocated"); if (usecache) { - /* Avoid repeated closure construction in some cases. - * Occurs a lot in add_action. - */ - int i; - for(i = 0; i < FUNCCACHE; i++) { - if (funccache[i] && - ftype == funccache[i]->funtype && - ob == funccache[i]->funobj && - no == funccache[i]->funno && - inh == funccache[i]->funinh) { - fun = funccache[i]; - INCREF(fun->ref); - return fun; - } - } + /* Avoid repeated closure construction in some cases. + * Occurs a lot in add_action. + */ + int i; + for(i = 0; i < FUNCCACHE; i++) { + if (funccache[i] && + ftype == funccache[i]->funtype && + ob == funccache[i]->funobj && + no == funccache[i]->funno && + inh == funccache[i]->funinh) { + fun = funccache[i]; + INCREF(fun->ref); + return fun; + } + } } fun = alloc_closure(ftype); /*(void)printf("alloc_objclosure=%lx %lx %s\n", fun, ob, refstr);*/ fun->funobj = ob; if (ob) - add_ref(fun->funobj, refstr); + add_ref(fun->funobj, refstr); fun->funno = no; fun->funinh = inh; /* Add function to cache */ if (funccache[next]) { - free_closure(funccache[next]); + free_closure(funccache[next]); } funccache[next] = fun; - INCREF(fun->ref); /* can be referenced from the cache now */ + INCREF(fun->ref); /* can be referenced from the cache now */ next = (next+1) % FUNCCACHE; return fun; @@ -5168,21 +5168,21 @@ alloc_objclosurestr(int ftype, char *funstr, struct object *ob, char *refstr, in /* look up function name in object */ if (!(ob->flags & O_DESTRUCTED) && - search_for_function(funstr, ob->prog)) { - /* maybe overly restrictive, but don't allow everything... */ - if ( (current_object != ob && - (function_type_mod_found & (TYPE_MOD_STATIC | TYPE_MOD_PRIVATE))) - || ((function_type_mod_found & TYPE_MOD_PRIVATE) && - /* mysterious test taken from old set_alarm */ - inh_offset < function_inherit_found - (int)function_prog_found->num_inherited + 1)) - return 0; - funno = function_index_found; - funinh = function_inherit_found; + search_for_function(funstr, ob->prog)) { + /* maybe overly restrictive, but don't allow everything... */ + if ( (current_object != ob && + (function_type_mod_found & (TYPE_MOD_STATIC | TYPE_MOD_PRIVATE))) + || ((function_type_mod_found & TYPE_MOD_PRIVATE) && + /* mysterious test taken from old set_alarm */ + inh_offset < function_inherit_found - (int)function_prog_found->num_inherited + 1)) + return 0; + funno = function_index_found; + funinh = function_inherit_found; } else { - return 0; + return 0; } if (ftype == FUN_LFUNO && ob == current_object) - ftype = FUN_LFUN; + ftype = FUN_LFUN; return alloc_objclosure(ftype, funinh, funno, ob, refstr, usecache); } @@ -5197,17 +5197,17 @@ f_mkfunction(int xxx) #if 1 if (arg[0].type != T_STRING || arg[1].type != T_OBJECT || num_arg < 2 || arg[1].u.ob == 0) - fatal("bad argument to mkfunction\n"); + fatal("bad argument to mkfunction\n"); #endif ob = arg[1].u.ob; f = alloc_objclosurestr(FUN_LFUNO, arg[0].u.string, ob, "f_mkfunction", 1); if (!f) { - pop_n_elems(num_arg); - push_number(0); - return; + pop_n_elems(num_arg); + push_number(0); + return; } if (ob == current_object) - f->funtype = FUN_LFUN; + f->funtype = FUN_LFUN; pop_n_elems(num_arg); push_function(f, FALSE); @@ -5226,84 +5226,84 @@ f_build_closure(int num_arg) pc++; if (ftype == FUN_EMPTY) { - probe_stack(1); - *++sp = constempty; - return; + probe_stack(1); + *++sp = constempty; + return; } switch(ftype) { case FUN_LFUN_NOMASK: fun_inh = EXTRACT_UCHAR(pc); - pc++; - ((char *)&funno)[0] = pc[0]; - ((char *)&funno)[1] = pc[1]; - pc += 2; - f = alloc_objclosure(FUN_LFUN, inh_offset + (fun_inh - (current_prog->num_inherited - 1)), funno, current_object, "f_build_closure", 1); - pop_stack(); + pc++; + ((char *)&funno)[0] = pc[0]; + ((char *)&funno)[1] = pc[1]; + pc += 2; + f = alloc_objclosure(FUN_LFUN, inh_offset + (fun_inh - (current_prog->num_inherited - 1)), funno, current_object, "f_build_closure", 1); + pop_stack(); break; case FUN_LFUN: - pc += 3; + pc += 3; - f = alloc_objclosurestr(ftype, sp->u.string, current_object, "f_build_closure", 1); - pop_stack(); - break; + f = alloc_objclosurestr(ftype, sp->u.string, current_object, "f_build_closure", 1); + pop_stack(); + break; case FUN_SFUN: - if (sp->type != T_STRING) - fatal("Not a string in f_build_sclosure\n"); - if (!simul_efun_ob) - error("No simul_efun object"); - f = alloc_objclosurestr(ftype, sp->u.string, simul_efun_ob, "f_build_closure", 1); - pop_stack(); - break; + if (sp->type != T_STRING) + fatal("Not a string in f_build_sclosure\n"); + if (!simul_efun_ob) + error("No simul_efun object"); + f = alloc_objclosurestr(ftype, sp->u.string, simul_efun_ob, "f_build_closure", 1); + pop_stack(); + break; case FUN_EFUN: - ((char *)&funno)[0] = pc[0]; - ((char *)&funno)[1] = pc[1]; - pc += 2; - f = alloc_objclosure(ftype, 0, funno, 0, "f_build_closure", 0); /* could cache */ - break; + ((char *)&funno)[0] = pc[0]; + ((char *)&funno)[1] = pc[1]; + pc += 2; + f = alloc_objclosure(ftype, 0, funno, 0, "f_build_closure", 0); /* could cache */ + break; case FUN_LFUNO: - if (sp->type != T_STRING) - fatal("Not a string in f_build_closure\n"); - if (sp[-1].type == T_OBJECT) { - obj = sp[-1].u.ob; - } else if (sp[-1].type == T_STRING) { - obj = find_object(sp[-1].u.string); - if (obj == 0) - error("Bad object in &\"ob\"->fun\n"); + if (sp->type != T_STRING) + fatal("Not a string in f_build_closure\n"); + if (sp[-1].type == T_OBJECT) { + obj = sp[-1].u.ob; + } else if (sp[-1].type == T_STRING) { + obj = find_object(sp[-1].u.string); + if (obj == 0) + error("Bad object in &\"ob\"->fun\n"); /* XXX Why? */ add_ref(obj, "build_closure string"); - } else { - obj = 0; - error("Bad object type in &ob->fun\n"); - } - - f = alloc_objclosurestr(ftype, sp->u.string, obj, "f_build_closure", 0); /* could cache */ - pop_stack(); - pop_stack(); - break; + } else { + obj = 0; + error("Bad object type in &ob->fun\n"); + } + + f = alloc_objclosurestr(ftype, sp->u.string, obj, "f_build_closure", 0); /* could cache */ + pop_stack(); + pop_stack(); + break; case FUN_COMPOSE: - if ((sp-1)->type != T_FUNCTION) - error("Bad argument 1 to '@'\n"); - if (sp->type != T_FUNCTION) - error("Bad argument 2 to '@'\n"); - f = alloc_closure(ftype); - free_vector(f->funargs); - f->funargs = allocate_array(2); - assign_svalue_no_free(&f->funargs->item[0], sp); - assign_svalue_no_free(&f->funargs->item[1], sp-1); - pop_stack(); - pop_stack(); - break; + if ((sp-1)->type != T_FUNCTION) + error("Bad argument 1 to '@'\n"); + if (sp->type != T_FUNCTION) + error("Bad argument 2 to '@'\n"); + f = alloc_closure(ftype); + free_vector(f->funargs); + f->funargs = allocate_array(2); + assign_svalue_no_free(&f->funargs->item[0], sp); + assign_svalue_no_free(&f->funargs->item[1], sp-1); + pop_stack(); + pop_stack(); + break; default: - fatal("Bad type in build_closure\n"); - f = 0; /* make -Wall quiet */ - break; + fatal("Bad type in build_closure\n"); + f = 0; /* make -Wall quiet */ + break; } if (f) { - push_function(f, FALSE); + push_function(f, FALSE); } else { - push_number(0); + push_number(0); } } @@ -5314,23 +5314,23 @@ free_closure(struct closure *f) return; if (!f->ref || --f->ref > 0) - return; + return; /*(void)printf("free_closure %lx %s\n", f, show_closure(f));*/ #ifdef FUNCDEBUG { - struct closure **p; - for(p = &allfuncs; *p && *p != f; p = &(*p)->next) - ; - if (!*p) - fatal("Closure pointer NULL\n"); - *p = (*p)->next; + struct closure **p; + for(p = &allfuncs; *p && *p != f; p = &(*p)->next) + ; + if (!*p) + fatal("Closure pointer NULL\n"); + *p = (*p)->next; } #endif free_vector(f->funargs); if (f->funobj) - free_object(f->funobj, "free_closure"); + free_object(f->funobj, "free_closure"); num_closures--; total_closure_size -= sizeof(struct closure); free((char *)f); @@ -5344,12 +5344,12 @@ dumpfuncs() (void)fprintf(stderr, "\nFunction dump:\n"); for(f = allfuncs; f; f = f->next) { - if (f->funobj && (f->funobj->flags & O_DESTRUCTED)) - (void)fprintf(stderr, "***DEST "); - (void)fprintf(stderr, "%lx: ref=%d %s", (long)f, f->ref, show_closure(f)); - if (f->from != f->funobj) - (void)fprintf(stderr, " from %s", f->from->name); - (void)fprintf(stderr, "\n"); + if (f->funobj && (f->funobj->flags & O_DESTRUCTED)) + (void)fprintf(stderr, "***DEST "); + (void)fprintf(stderr, "%lx: ref=%d %s", (long)f, f->ref, show_closure(f)); + if (f->from != f->funobj) + (void)fprintf(stderr, " from %s", f->from->name); + (void)fprintf(stderr, "\n"); } } #endif @@ -5373,10 +5373,10 @@ static long long cmp_values(searchval_t val, long long cmp, int as_str) { if (as_str) { - return strcmp(val.str, current_prog->rodata + cmp); + return strcmp(val.str, current_prog->rodata + cmp); } else - return (long long)(val.i - cmp); + return (long long)(val.i - cmp); } /* ARGSUSED */ @@ -5412,69 +5412,69 @@ f_switch(int num_arg) if (is_str) { - /* This table has 0 as case label as first entry in the table */ + /* This table has 0 as case label as first entry in the table */ - if (sp->type == T_NUMBER && !sp->u.number) - { - pc = current_prog->program + read_address(current_prog->program + tab_start + E_OFFSET); - pop_stack(); - return; - } - if (sp->type != T_STRING) - bad_arg(1, F_SWITCH, sp); - search_val.str = sp->u.string; - tab_head++; + if (sp->type == T_NUMBER && !sp->u.number) + { + pc = current_prog->program + read_address(current_prog->program + tab_start + E_OFFSET); + pop_stack(); + return; + } + if (sp->type != T_STRING) + bad_arg(1, F_SWITCH, sp); + search_val.str = sp->u.string; + tab_head++; } else if (sp->type == T_NUMBER) - search_val.i = sp->u.number; + search_val.i = sp->u.number; else - bad_arg(1, F_SWITCH, sp); + bad_arg(1, F_SWITCH, sp); while (tab_head <= tab_tail) { - tab_mid = (tab_head + tab_tail) / 2; + tab_mid = (tab_head + tab_tail) / 2; - if (read_address(current_prog->program + tab_start + tab_mid * ENTRY_SIZE + E_OFFSET) == RANGE_OFFSET || - (tab_mid != tab_head && - read_address(current_prog->program + tab_start + tab_mid * ENTRY_SIZE + E_OFFSET - ENTRY_SIZE) == RANGE_OFFSET && - (tab_mid--, 1))) - { - /* It is a range entry */ - long long lo_value, hi_value; + if (read_address(current_prog->program + tab_start + tab_mid * ENTRY_SIZE + E_OFFSET) == RANGE_OFFSET || + (tab_mid != tab_head && + read_address(current_prog->program + tab_start + tab_mid * ENTRY_SIZE + E_OFFSET - ENTRY_SIZE) == RANGE_OFFSET && + (tab_mid--, 1))) + { + /* It is a range entry */ + long long lo_value, hi_value; - lo_value = read_long_long(current_prog->program + tab_start + tab_mid * ENTRY_SIZE + E_VALUE); - hi_value = read_long_long(current_prog->program + tab_start + tab_mid * ENTRY_SIZE + E_VALUE + ENTRY_SIZE); + lo_value = read_long_long(current_prog->program + tab_start + tab_mid * ENTRY_SIZE + E_VALUE); + hi_value = read_long_long(current_prog->program + tab_start + tab_mid * ENTRY_SIZE + E_VALUE + ENTRY_SIZE); if (cmp_values(search_val, lo_value, is_str) < 0) tab_tail = tab_mid - 1; else if (cmp_values(search_val, hi_value, is_str) > 0) tab_head = tab_mid + 2; else - { - pc = current_prog->program + read_address(current_prog->program + tab_start + tab_mid * ENTRY_SIZE + E_OFFSET + ENTRY_SIZE); - pop_stack(); - return; - } - } - else - { - /* It is an ordinary entry */ - long value; - int cmp; - - value = read_long_long(current_prog->program + tab_start + - tab_mid * ENTRY_SIZE + E_VALUE); - if ((cmp = cmp_values(search_val, value, is_str)) == 0) - { - pc = current_prog->program + read_address(current_prog->program + tab_start + tab_mid * ENTRY_SIZE + E_OFFSET); - pop_stack(); - return; - } - else if (cmp < 0) - tab_tail = tab_mid - 1; - else - tab_head = tab_mid + 1; - } + { + pc = current_prog->program + read_address(current_prog->program + tab_start + tab_mid * ENTRY_SIZE + E_OFFSET + ENTRY_SIZE); + pop_stack(); + return; + } + } + else + { + /* It is an ordinary entry */ + long value; + int cmp; + + value = read_long_long(current_prog->program + tab_start + + tab_mid * ENTRY_SIZE + E_VALUE); + if ((cmp = cmp_values(search_val, value, is_str)) == 0) + { + pc = current_prog->program + read_address(current_prog->program + tab_start + tab_mid * ENTRY_SIZE + E_OFFSET); + pop_stack(); + return; + } + else if (cmp < 0) + tab_tail = tab_mid - 1; + else + tab_head = tab_mid + 1; + } } /* No match, use default */ pc = current_prog->program + read_address(pc + DEFAULT_OFF); @@ -5503,11 +5503,11 @@ f_mkmapping(int num_arg) struct mapping *mm = 0; if ((sp-1)->type == T_POINTER && sp->type == T_POINTER) - mm = make_mapping((sp-1)->u.vec, sp->u.vec); + mm = make_mapping((sp-1)->u.vec, sp->u.vec); else if ((sp-1)->type == T_NUMBER && sp->type == T_POINTER) - mm = make_mapping(NULL, sp->u.vec); + mm = make_mapping(NULL, sp->u.vec); else if ((sp-1)->type == T_POINTER && sp->type == T_NUMBER) - mm = make_mapping((sp-1)->u.vec, NULL); + mm = make_mapping((sp-1)->u.vec, NULL); else if ((sp-1)->type == T_NUMBER && sp->type == T_NUMBER) { bad_arg_op(F_MKMAPPING, sp - 1, sp); @@ -5524,9 +5524,9 @@ f_m_sizeof(int num_arg) int i; if (sp->type == T_MAPPING) - i = card_mapping(sp->u.map); + i = card_mapping(sp->u.map); else - i = 0; + i = 0; pop_stack(); push_number(i); } @@ -5539,14 +5539,14 @@ f_m_indexes(int num_arg) if (sp->type == T_MAPPING) { - v = map_domain(sp->u.map); - pop_stack(); - push_vector(v, FALSE); + v = map_domain(sp->u.map); + pop_stack(); + push_vector(v, FALSE); } else { - pop_stack(); - push_number(0); + pop_stack(); + push_number(0); } } @@ -5558,14 +5558,14 @@ f_m_values(int num_arg) if (sp->type == T_MAPPING) { - v = map_codomain(sp->u.map); - pop_stack(); - push_vector(v, FALSE); + v = map_codomain(sp->u.map); + pop_stack(); + push_vector(v, FALSE); } else { - pop_stack(); - push_number(0); + pop_stack(); + push_number(0); } } @@ -5577,14 +5577,14 @@ f_m_delete(int num_arg) if ((sp-1)->type == T_MAPPING) { - m = remove_mapping((sp-1)->u.map, sp); - pop_n_elems(2); - push_mapping(m, FALSE); + m = remove_mapping((sp-1)->u.map, sp); + pop_n_elems(2); + push_mapping(m, FALSE); } else { - pop_n_elems(2); - push_number(0); + pop_n_elems(2); + push_number(0); } } @@ -5595,9 +5595,9 @@ f_sizeof(int num_arg) int i; if (sp->type == T_NUMBER) - i = 0; + i = 0; else - i = sp->u.vec->size; + i = sp->u.vec->size; pop_stack(); push_number(i); } @@ -5613,8 +5613,8 @@ f_process_string(int num_arg) pop_stack(); if (str) { - pop_stack(); - push_mstring(str); + pop_stack(); + push_mstring(str); } } @@ -5630,10 +5630,10 @@ f_process_value(int num_arg) pop_stack(); if (ret) { - push_svalue(ret); + push_svalue(ret); } else - push_number(0); + push_number(0); } /* ARGSUSED */ @@ -5655,9 +5655,9 @@ f_get_dir(int num_arg) pop_stack(); if (v) { - push_vector(v, FALSE); + push_vector(v, FALSE); } else - push_number(0); + push_number(0); } /* ARGSUSED */ @@ -5680,9 +5680,9 @@ f_mkdir(int num_arg) path = check_valid_path(sp->u.string, current_object, "mkdir", 1); /* pop_stack(); see comment above... */ if (path == 0 || mkdir(path, 0774) == -1) - assign_svalue(sp, &const0); + assign_svalue(sp, &const0); else - assign_svalue(sp, &const1); + assign_svalue(sp, &const1); } /* ARGSUSED */ @@ -5694,9 +5694,9 @@ f_rmdir(int num_arg) path = check_valid_path(sp->u.string, current_object, "rmdir", 1); /* pop_stack(); rw - what the heck ??? */ if (path == 0 || rmdir(path) == -1) - assign_svalue(sp, &const0); + assign_svalue(sp, &const0); else - assign_svalue(sp, &const1); + assign_svalue(sp, &const1); } static void @@ -5708,39 +5708,39 @@ f_input_to(int num_arg) int flag = 1; if (arg[0].type == T_FUNCTION) { - if (num_arg > 2) - error("Bad # of args to input_to()\n"); + if (num_arg > 2) + error("Bad # of args to input_to()\n"); } else if (arg[0].type == T_STRING) { - struct closure *fun; - int i, size; - - fun = alloc_objclosurestr(FUN_LFUNO, arg[0].u.string, current_object, "f_input_to", 0); - if (!fun) { - pop_n_elems(num_arg); - push_number(0); - return; - } - - size = num_arg > 2 ? num_arg - 2 : 0; - if (size > 0) { - v = allocate_array(size+1); - v->item[0] = constempty; /* slot for the input_to string */ - for (i = 2; i < num_arg; i++) - assign_svalue_no_free(&v->item[i - 1], &arg[i]); - free_vector(fun->funargs); - fun->funargs = v; - } - - free_svalue(&arg[0]); /* release old stack location */ - arg[0].type = T_FUNCTION; - arg[0].u.func = fun; /* and put in a new one */ - - WARNOBSOLETE(current_object, "string as function in input_to"); + struct closure *fun; + int i, size; + + fun = alloc_objclosurestr(FUN_LFUNO, arg[0].u.string, current_object, "f_input_to", 0); + if (!fun) { + pop_n_elems(num_arg); + push_number(0); + return; + } + + size = num_arg > 2 ? num_arg - 2 : 0; + if (size > 0) { + v = allocate_array(size+1); + v->item[0] = constempty; /* slot for the input_to string */ + for (i = 2; i < num_arg; i++) + assign_svalue_no_free(&v->item[i - 1], &arg[i]); + free_vector(fun->funargs); + fun->funargs = v; + } + + free_svalue(&arg[0]); /* release old stack location */ + arg[0].type = T_FUNCTION; + arg[0].u.func = fun; /* and put in a new one */ + + WARNOBSOLETE(current_object, "string as function in input_to"); } else bad_arg(1, F_INPUT_TO, arg); if (num_arg == 1 || (arg[1].type == T_NUMBER && arg[1].u.number == 0)) - flag = 0; + flag = 0; r = input_to(arg[0].u.func, flag); pop_n_elems(num_arg); push_number(r); @@ -5778,24 +5778,24 @@ static void f_parse_command(int num_arg) { struct svalue *arg; - int i; + int i; num_arg = EXTRACT_UCHAR(pc); pc++; arg = sp - num_arg + 1; if (arg[0].type != T_STRING) - bad_arg(1, F_PARSE_COMMAND, &arg[0]); + bad_arg(1, F_PARSE_COMMAND, &arg[0]); if (arg[1].type != T_OBJECT && arg[1].type != T_POINTER) - bad_arg(2, F_PARSE_COMMAND, &arg[1]); + bad_arg(2, F_PARSE_COMMAND, &arg[1]); if (arg[2].type != T_STRING) - bad_arg(3, F_PARSE_COMMAND, &arg[2]); + bad_arg(3, F_PARSE_COMMAND, &arg[2]); if (arg[1].type == T_POINTER) - check_for_destr(&arg[1]); + check_for_destr(&arg[1]); i = parse(arg[0].u.string, &arg[1], arg[2].u.string, &arg[3], - num_arg-3); - pop_n_elems(num_arg); /* Get rid of all arguments */ - push_number(i); /* Push the result value */ + num_arg-3); + pop_n_elems(num_arg); /* Get rid of all arguments */ + push_number(i); /* Push the result value */ } static void @@ -5807,24 +5807,24 @@ f_debug(int num_arg) arg = sp - num_arg + 1; if (current_object != master_ob) { - push_object(current_object); - for (i = 0; i < num_arg; i++) - push_svalue(&arg[i]); - ret = apply_master_ob(M_VALID_DEBUG, num_arg + 1); - if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) - { - pop_n_elems(num_arg); /* Get rid of all arguments */ - push_number(0); - return; - } + push_object(current_object); + for (i = 0; i < num_arg; i++) + push_svalue(&arg[i]); + ret = apply_master_ob(M_VALID_DEBUG, num_arg + 1); + if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) + { + pop_n_elems(num_arg); /* Get rid of all arguments */ + push_number(0); + return; + } } arg = sp - num_arg + 1; if (arg[0].type != T_STRING) - bad_arg(1, F_DEBUG, &arg[0]); + bad_arg(1, F_DEBUG, &arg[0]); ret = debug_command(arg[0].u.string, - num_arg-1, sp-num_arg+2); - pop_n_elems(num_arg - 1); /* Get rid of all arguments */ + num_arg-1, sp-num_arg+2); + pop_n_elems(num_arg - 1); /* Get rid of all arguments */ assign_svalue(sp, ret); free_svalue(ret); } @@ -5866,11 +5866,11 @@ f_present(int num_arg) struct object *ob; if ((sp-1)->type == T_NUMBER) { - if ((sp-1)->u.number != 0) - bad_arg(1, F_PRESENT, sp - 1); - ob = 0; + if ((sp-1)->u.number != 0) + bad_arg(1, F_PRESENT, sp - 1); + ob = 0; } else - ob = object_present((sp-1), sp); + ob = object_present((sp-1), sp); pop_stack(); pop_stack(); push_object(ob); @@ -5907,7 +5907,7 @@ f_assign(int num_arg) { #ifdef DEBUG if (sp[-1].type != T_LVALUE) - fatal("Bad argument to F_ASSIGN\n"); + fatal("Bad argument to F_ASSIGN\n"); #endif assign_svalue((sp-1)->u.lvalue, sp); sp--; @@ -5927,7 +5927,7 @@ f_ctime(int num_arg) char *nl = strchr(time, '\n'); if (nl) - *nl = '\0'; + *nl = '\0'; pop_stack(); push_string(time, STRING_MSTRING); @@ -5947,87 +5947,87 @@ f_add_eq(int num_arg) argp = sp[-1].u.lvalue; switch(argp->type) { - case T_STRING: - if (sp->type == T_STRING) - { - int l = strlen(argp->u.string); - new_str = allocate_mstring(l + strlen(sp->u.string)); - (void)strcpy(new_str, argp->u.string); - (void)strcpy(new_str+l, sp->u.string); - pop_n_elems(2); - push_mstring(new_str); - } - else if (sp->type == T_NUMBER) - { - char buff[20]; - (void)sprintf(buff, "%lld", sp->u.number); - new_str = allocate_mstring(strlen(argp->u.string) + strlen(buff)); - (void)strcpy(new_str, argp->u.string); - (void)strcat(new_str, buff); - pop_n_elems(2); - push_mstring(new_str); - } - else - { - bad_arg_op(F_ADD_EQ, argp, sp); - } - break; - case T_NUMBER: - if (sp->type == T_NUMBER) - { - i = argp->u.number + sp->u.number; - pop_n_elems(2); - push_number(i); - } - else - { - bad_arg_op(F_ADD_EQ, argp, sp); - } - break; - case T_FLOAT: - if (sp->type == T_FLOAT) - { - fl = argp->u.real + sp->u.real; - pop_n_elems(2); - push_float(fl); - } - else - { - bad_arg_op(F_ADD_EQ, argp, sp); - } - break; - case T_MAPPING: - if (sp->type != T_MAPPING) { - bad_arg_op(F_ADD_EQ, argp, sp); - } - else { - struct mapping *m; - - check_for_destr(argp); - check_for_destr(sp); - addto_mapping(argp->u.map, sp->u.map); - m = argp->u.map; - INCREF(m->ref); - pop_n_elems(2); - push_mapping(m, FALSE); - } - break; - case T_POINTER: - if (sp->type != T_POINTER) { - bad_arg_op(F_ADD_EQ, argp, sp); - } - else { - struct vector *v; - - check_for_destr(argp); - check_for_destr(sp); - v = add_array(argp->u.vec, sp->u.vec); - pop_n_elems(2); - push_vector(v, FALSE); - } - break; - default: - bad_arg_op(F_ADD_EQ, argp, sp); + case T_STRING: + if (sp->type == T_STRING) + { + int l = strlen(argp->u.string); + new_str = allocate_mstring(l + strlen(sp->u.string)); + (void)strcpy(new_str, argp->u.string); + (void)strcpy(new_str+l, sp->u.string); + pop_n_elems(2); + push_mstring(new_str); + } + else if (sp->type == T_NUMBER) + { + char buff[20]; + (void)sprintf(buff, "%lld", sp->u.number); + new_str = allocate_mstring(strlen(argp->u.string) + strlen(buff)); + (void)strcpy(new_str, argp->u.string); + (void)strcat(new_str, buff); + pop_n_elems(2); + push_mstring(new_str); + } + else + { + bad_arg_op(F_ADD_EQ, argp, sp); + } + break; + case T_NUMBER: + if (sp->type == T_NUMBER) + { + i = argp->u.number + sp->u.number; + pop_n_elems(2); + push_number(i); + } + else + { + bad_arg_op(F_ADD_EQ, argp, sp); + } + break; + case T_FLOAT: + if (sp->type == T_FLOAT) + { + fl = argp->u.real + sp->u.real; + pop_n_elems(2); + push_float(fl); + } + else + { + bad_arg_op(F_ADD_EQ, argp, sp); + } + break; + case T_MAPPING: + if (sp->type != T_MAPPING) { + bad_arg_op(F_ADD_EQ, argp, sp); + } + else { + struct mapping *m; + + check_for_destr(argp); + check_for_destr(sp); + addto_mapping(argp->u.map, sp->u.map); + m = argp->u.map; + INCREF(m->ref); + pop_n_elems(2); + push_mapping(m, FALSE); + } + break; + case T_POINTER: + if (sp->type != T_POINTER) { + bad_arg_op(F_ADD_EQ, argp, sp); + } + else { + struct vector *v; + + check_for_destr(argp); + check_for_destr(sp); + v = add_array(argp->u.vec, sp->u.vec); + pop_n_elems(2); + push_vector(v, FALSE); + } + break; + default: + bad_arg_op(F_ADD_EQ, argp, sp); } assign_svalue(argp, sp); } @@ -6042,47 +6042,47 @@ f_sub_eq(int num_arg) error("Non-lvalue argument to -="); argp = sp[-1].u.lvalue; switch (argp->type) { - case T_NUMBER: - if (sp->type != T_NUMBER) - bad_arg_op(F_SUB_EQ, argp, sp); - argp->u.number -= sp->u.number; - sp--; - break; - case T_FLOAT: - if (sp->type != T_FLOAT) - bad_arg_op(F_SUB_EQ, argp, sp); - FLOATASGOP(argp->u.real, -= , sp->u.real); - sp--; - break; - case T_POINTER: - { - struct vector *v; - - if (sp->type != T_POINTER) - bad_arg_op(F_SUB_EQ, argp, sp); - - check_for_destr(argp); - check_for_destr(sp); - - v = subtract_array(argp->u.vec, sp->u.vec); - - pop_stack(); - pop_stack(); - - if (v == 0) - { - push_number(0); - } - else - { - push_vector(v, FALSE); - } - - assign_svalue(argp, sp); - break; - } - default: - bad_arg_op(F_SUB_EQ, argp, sp); + case T_NUMBER: + if (sp->type != T_NUMBER) + bad_arg_op(F_SUB_EQ, argp, sp); + argp->u.number -= sp->u.number; + sp--; + break; + case T_FLOAT: + if (sp->type != T_FLOAT) + bad_arg_op(F_SUB_EQ, argp, sp); + FLOATASGOP(argp->u.real, -= , sp->u.real); + sp--; + break; + case T_POINTER: + { + struct vector *v; + + if (sp->type != T_POINTER) + bad_arg_op(F_SUB_EQ, argp, sp); + + check_for_destr(argp); + check_for_destr(sp); + + v = subtract_array(argp->u.vec, sp->u.vec); + + pop_stack(); + pop_stack(); + + if (v == 0) + { + push_number(0); + } + else + { + push_vector(v, FALSE); + } + + assign_svalue(argp, sp); + break; + } + default: + bad_arg_op(F_SUB_EQ, argp, sp); } assign_svalue(sp, argp); } @@ -6100,54 +6100,54 @@ f_mult_eq(int num_arg) argp = sp[-1].u.lvalue; if (argp->type == T_FLOAT && sp->type == T_FLOAT) { - fl = argp->u.real * sp->u.real; - pop_n_elems(2); - push_float(fl); - assign_svalue(argp, sp); + fl = argp->u.real * sp->u.real; + pop_n_elems(2); + push_float(fl); + assign_svalue(argp, sp); return; } if (argp->type == T_NUMBER) { - if (sp->type == T_NUMBER) { - i = argp->u.number * sp->u.number; - pop_n_elems(2); - push_number(i); - assign_svalue(argp, sp); - return; - } + if (sp->type == T_NUMBER) { + i = argp->u.number * sp->u.number; + pop_n_elems(2); + push_number(i); + assign_svalue(argp, sp); + return; + } else if (sp->type == T_STRING) { char *result = multiply_string(sp->u.string, argp->u.number); - pop_stack(); - pop_stack(); - push_string(result, STRING_MSTRING); - assign_svalue(argp, sp); - return; + pop_stack(); + pop_stack(); + push_string(result, STRING_MSTRING); + assign_svalue(argp, sp); + return; } else if (sp->type == T_POINTER) { - struct vector *result = multiply_array(sp->u.vec, - argp->u.number); - pop_stack(); - pop_stack(); - push_vector(result, 0); - assign_svalue(argp, sp); + struct vector *result = multiply_array(sp->u.vec, + argp->u.number); + pop_stack(); + pop_stack(); + push_vector(result, 0); + assign_svalue(argp, sp); return; } } else if (argp->type == T_POINTER && - sp->type == T_NUMBER) { - struct vector *result = multiply_array(argp->u.vec, - sp->u.number); - pop_stack(); - pop_stack(); - push_vector(result, 0); - assign_svalue(argp, sp); + sp->type == T_NUMBER) { + struct vector *result = multiply_array(argp->u.vec, + sp->u.number); + pop_stack(); + pop_stack(); + push_vector(result, 0); + assign_svalue(argp, sp); return; } else if (argp->type == T_STRING && - sp->type == T_NUMBER) { - char *result = multiply_string(argp->u.string, sp->u.number); - pop_stack(); - pop_stack(); - push_string(result, STRING_MSTRING); - assign_svalue(argp, sp); - return; + sp->type == T_NUMBER) { + char *result = multiply_string(argp->u.string, sp->u.number); + pop_stack(); + pop_stack(); + push_string(result, STRING_MSTRING); + assign_svalue(argp, sp); + return; } bad_arg_op(F_MULT_EQ, argp, sp); } @@ -6164,40 +6164,40 @@ f_and_eq(int num_arg) argp = sp[-1].u.lvalue; switch (argp->type) { - case T_NUMBER: - if (sp->type != T_NUMBER) - bad_arg_op(F_AND_EQ, argp, sp); - i = argp->u.number & sp->u.number; - pop_n_elems(2); - push_number(i); - assign_svalue(argp, sp); - break; - case T_POINTER: - { - struct vector *v; + case T_NUMBER: + if (sp->type != T_NUMBER) + bad_arg_op(F_AND_EQ, argp, sp); + i = argp->u.number & sp->u.number; + pop_n_elems(2); + push_number(i); + assign_svalue(argp, sp); + break; + case T_POINTER: + { + struct vector *v; - if (sp->type != T_POINTER) - bad_arg_op(F_AND_EQ, argp, sp); + if (sp->type != T_POINTER) + bad_arg_op(F_AND_EQ, argp, sp); - v = intersect_array(argp->u.vec, sp->u.vec); + v = intersect_array(argp->u.vec, sp->u.vec); - pop_stack(); - pop_stack(); + pop_stack(); + pop_stack(); - if (v == 0) - { - push_number(0); - } - else - { - push_vector(v, FALSE); - } + if (v == 0) + { + push_number(0); + } + else + { + push_vector(v, FALSE); + } - assign_svalue(argp, sp); - break; - } - default: - bad_arg_op(F_AND_EQ, argp, sp); + assign_svalue(argp, sp); + break; + } + default: + bad_arg_op(F_AND_EQ, argp, sp); } } @@ -6213,22 +6213,22 @@ f_or_eq(int num_arg) argp = sp[-1].u.lvalue; if (sp->type == T_POINTER && argp->type == T_POINTER) { - struct vector *v; + struct vector *v; - v = union_array(argp->u.vec, sp->u.vec); + v = union_array(argp->u.vec, sp->u.vec); - pop_stack(); - pop_stack(); + pop_stack(); + pop_stack(); - if (v == NULL) - push_number(0); - else - push_vector(v, FALSE); - assign_svalue(argp,sp); - return; + if (v == NULL) + push_number(0); + else + push_vector(v, FALSE); + assign_svalue(argp,sp); + return; } if (argp->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_OR_EQ, argp, sp); i = argp->u.number | sp->u.number; pop_n_elems(2); @@ -6247,7 +6247,7 @@ f_xor_eq(int num_arg) error("Non-lvalue argument to ^="); argp = sp[-1].u.lvalue; if (argp->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_XOR_EQ, argp, sp); i = argp->u.number ^ sp->u.number; pop_n_elems(2); @@ -6266,7 +6266,7 @@ f_lsh_eq(int num_arg) error("Non-lvalue argument to <<="); argp = sp[-1].u.lvalue; if (argp->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_LSH_EQ, argp, sp); i = argp->u.number << sp->u.number; pop_n_elems(2); @@ -6285,7 +6285,7 @@ f_rsh_eq(int num_arg) error("Non-lvalue argument to >>="); argp = sp[-1].u.lvalue; if (argp->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_RSH_EQ, argp, sp); i = (int)((unsigned)argp->u.number >> sp->u.number); pop_n_elems(2); @@ -6315,19 +6315,19 @@ f_div_eq(int num_arg) argp = sp[-1].u.lvalue; if (argp->type == T_FLOAT && sp->type == T_FLOAT) { - if (sp->u.real == 0.0) - error("Division by 0\n"); + if (sp->u.real == 0.0) + error("Division by 0\n"); fl = argp->u.real / sp->u.real; - pop_n_elems(2); - push_float(fl); - assign_svalue(argp, sp); + pop_n_elems(2); + push_float(fl); + assign_svalue(argp, sp); return; } if (argp->type != T_NUMBER || - sp->type != T_NUMBER) + sp->type != T_NUMBER) bad_arg_op(F_DIV_EQ, argp, sp); if (sp->u.number == 0) - error("Division by 0\n"); + error("Division by 0\n"); i = argp->u.number / sp->u.number; pop_n_elems(2); push_number(i); @@ -6350,7 +6350,7 @@ f_mod_eq(int num_arg) if (sp->type == T_NUMBER) { long long i; if (sp->u.number == 0) - error("Modulus by zero.\n"); + error("Modulus by zero.\n"); i = argp->u.number = argp->u.number % sp->u.number; pop_n_elems(2); push_number(i); @@ -6359,7 +6359,7 @@ f_mod_eq(int num_arg) errno = 0; d = argp->u.real = fmod(argp->u.real, sp->u.real); if (errno) - error("Modulus by zero.\n"); + error("Modulus by zero.\n"); pop_n_elems(2); push_float(d); } @@ -6397,9 +6397,9 @@ f_unique_array(int num_arg) if ((sp - (num_arg - 1))->type == T_NUMBER) { - pop_n_elems(num_arg); - push_number(0); - return; + pop_n_elems(num_arg); + push_number(0); + return; } arg = sp - num_arg + 1; @@ -6407,7 +6407,7 @@ f_unique_array(int num_arg) if (arg[1].type == T_STRING) { /* create a function, &call_other(, "function name") */ - fun = alloc_objclosure(FUN_EFUN, 0, F_CALL_OTHER, 0, "f_unique_array", 0); + fun = alloc_objclosure(FUN_EFUN, 0, F_CALL_OTHER, 0, "f_unique_array", 0); free_vector(fun->funargs); fun->funargs = allocate_array(2); @@ -6421,14 +6421,14 @@ f_unique_array(int num_arg) if (num_arg < 3) { - check_for_destr(arg); - res = make_unique((arg)->u.vec, fun, &const0); + check_for_destr(arg); + res = make_unique((arg)->u.vec, fun, &const0); } else { - check_for_destr(arg); - res = make_unique((arg)->u.vec, fun, sp); - pop_stack (); + check_for_destr(arg); + res = make_unique((arg)->u.vec, fun, sp); + pop_stack (); } @@ -6441,11 +6441,11 @@ f_unique_array(int num_arg) if (res) { - push_vector(res, FALSE); + push_vector(res, FALSE); } else { - push_number (0); + push_number (0); } } @@ -6471,72 +6471,72 @@ f_map(int num_arg) arg = sp - num_arg + 1; if (num_arg == 2 && arg[1].type == T_FUNCTION) { - ; + ; } else if (num_arg >= 3 && arg[1].type == T_STRING) { - struct closure *fun; - - if (arg[2].type == T_OBJECT) - ob = arg[2].u.ob; - else if (arg[2].type == T_STRING) - ob = find_object(arg[2].u.string); - else - ob = 0; - - if (!ob) - bad_arg(3, F_MAP, &arg[2]); - - /* Fake a function */ - fun = alloc_objclosurestr(FUN_LFUNO, arg[1].u.string, ob, "f_map", 0); - if (!fun) { - /* We have three choices here: - * 1 - return ({}) which is backwards compatible - * 2 - return 0 to indicate an error - * 3 - generate a runtime error - */ + struct closure *fun; + + if (arg[2].type == T_OBJECT) + ob = arg[2].u.ob; + else if (arg[2].type == T_STRING) + ob = find_object(arg[2].u.string); + else + ob = 0; + + if (!ob) + bad_arg(3, F_MAP, &arg[2]); + + /* Fake a function */ + fun = alloc_objclosurestr(FUN_LFUNO, arg[1].u.string, ob, "f_map", 0); + if (!fun) { + /* We have three choices here: + * 1 - return ({}) which is backwards compatible + * 2 - return 0 to indicate an error + * 3 - generate a runtime error + */ #if 0 - error("Function used in map could not be found: %s\n", arg[1].u.string); + error("Function used in map could not be found: %s\n", arg[1].u.string); #else - (void)printf("Function used in map could not be found: %s\n", arg[1].u.string); - pop_n_elems(num_arg); - push_number(0); + (void)printf("Function used in map could not be found: %s\n", arg[1].u.string); + pop_n_elems(num_arg); + push_number(0); #endif - return; - } - if (num_arg > 3) { - free_vector(fun->funargs); - fun->funargs = allocate_array(2); - fun->funargs->item[0] = constempty; - assign_svalue_no_free(&fun->funargs->item[1], &arg[3]); - } - free_svalue(&arg[1]); /* release old stack location */ - arg[1].type = T_FUNCTION; - arg[1].u.func = fun; /* and put in a new one */ - - WARNOBSOLETE(current_object, "string as function in map"); + return; + } + if (num_arg > 3) { + free_vector(fun->funargs); + fun->funargs = allocate_array(2); + fun->funargs->item[0] = constempty; + assign_svalue_no_free(&fun->funargs->item[1], &arg[3]); + } + free_svalue(&arg[1]); /* release old stack location */ + arg[1].type = T_FUNCTION; + arg[1].u.func = fun; /* and put in a new one */ + + WARNOBSOLETE(current_object, "string as function in map"); } else - error("Bad arguments to map\n"); + error("Bad arguments to map\n"); if (arg[0].type == T_POINTER) { - check_for_destr(&arg[0]); - res = map_array(arg[0].u.vec, arg[1].u.func); - pop_n_elems(num_arg); - if (res) { - push_vector(res, FALSE); - } else - push_number(0); + check_for_destr(&arg[0]); + res = map_array(arg[0].u.vec, arg[1].u.func); + pop_n_elems(num_arg); + if (res) { + push_vector(res, FALSE); + } else + push_number(0); } else if (arg[0].type == T_MAPPING) { - check_for_destr(&arg[0]); - m = map_map(arg[0].u.map, arg[1].u.func); - pop_n_elems(num_arg); - if (m) { - push_mapping(m, FALSE); - } else - push_number(0); + check_for_destr(&arg[0]); + m = map_map(arg[0].u.map, arg[1].u.func); + pop_n_elems(num_arg); + if (m) { + push_mapping(m, FALSE); + } else + push_number(0); } else { - /*bad_arg(1, F_MAP, &arg[0]);*/ - pop_n_elems(num_arg); - push_number(0); + /*bad_arg(1, F_MAP, &arg[0]);*/ + pop_n_elems(num_arg); + push_number(0); } } @@ -6558,23 +6558,23 @@ f_match_path(int num_arg) if (*scp != '\0') { - for (;;) - { - while (*scp != '\0' && *scp != '/') - *dcp++ = *scp++; - while (*scp == '/') - scp++; - if (dcp == string.u.string) - *dcp++ = '/'; - *dcp = '\0'; - svp2 = get_map_lvalue(sp[-1].u.map, &string, 0); - if (svp2 != &const0) - svp1 = svp2; - if (*scp == '\0') - break; - if (dcp[-1] != '/') - *dcp++ = '/'; - } + for (;;) + { + while (*scp != '\0' && *scp != '/') + *dcp++ = *scp++; + while (*scp == '/') + scp++; + if (dcp == string.u.string) + *dcp++ = '/'; + *dcp = '\0'; + svp2 = get_map_lvalue(sp[-1].u.map, &string, 0); + if (svp2 != &const0) + svp1 = svp2; + if (*scp == '\0') + break; + if (dcp[-1] != '/') + *dcp++ = '/'; + } } free(string.u.string); @@ -6607,9 +6607,9 @@ eval_instruction(char *p) if (instruction == F_EXT - EFUN_FIRST) { - ((char *)&ext_instr)[0] = pc[1]; - ((char *)&ext_instr)[1] = pc[2]; - instruction = ext_instr; + ((char *)&ext_instr)[0] = pc[1]; + ((char *)&ext_instr)[1] = pc[2]; + instruction = ext_instr; } #ifdef TRACE_CODE @@ -6617,7 +6617,7 @@ eval_instruction(char *p) previous_pc[last] = pc - current_prog->program; reference_prog(current_prog, "trace code"); if (previous_prog[last]) - free_prog(previous_prog[last]); + free_prog(previous_prog[last]); previous_prog[last] = current_prog; stack_size[last] = sp - fp - csp->num_local_variables; curtracedepth[last] = tracedepth; @@ -6625,17 +6625,17 @@ eval_instruction(char *p) #endif if (i == F_EXT - EFUN_FIRST) - pc += 2; + pc += 2; pc++; eval_cost++; if (!unlimited && eval_cost > MAX_COST) { - char *line; - line = get_srccode_position(pc - current_prog->program, current_prog); - (void)printf("eval_cost too big %d (%s)\n", eval_cost, line); + char *line; + line = get_srccode_position(pc - current_prog->program, current_prog); + (void)printf("eval_cost too big %d (%s)\n", eval_cost, line); eval_cost = 0; - error("Too long evaluation. Execution aborted.\n"); + error("Too long evaluation. Execution aborted.\n"); } /* * Execute current instruction. Note that all functions callable @@ -6644,56 +6644,56 @@ eval_instruction(char *p) */ { #ifdef DEBUG - int xnum_arg; + int xnum_arg; #endif - if (instrs[instruction].min_arg != instrs[instruction].max_arg) - { - num_arg = EXTRACT_UCHAR(pc); + if (instrs[instruction].min_arg != instrs[instruction].max_arg) + { + num_arg = EXTRACT_UCHAR(pc); #ifdef DEBUG - xnum_arg = num_arg; + xnum_arg = num_arg; #endif - pc++; - } - else - { + pc++; + } + else + { #ifdef DEBUG - xnum_arg = -1; + xnum_arg = -1; #endif - num_arg = instrs[instruction].min_arg; - } - if (num_arg > 0) - { - int type1 = (sp-num_arg+1)->type, type2 = (sp-num_arg+2)->type; - if (instrs[instruction].type[0] != 0 && - (instrs[instruction].type[0] & type1) == 0) - { - bad_arg(1, instruction + EFUN_FIRST, sp-num_arg+1); - } - if (num_arg > 1) - { - if (instrs[instruction].type[1] != 0 && - (instrs[instruction].type[1] & type2) == 0) - { - bad_arg(2, instruction + EFUN_FIRST, sp-num_arg+2); - } - } - } - /* + num_arg = instrs[instruction].min_arg; + } + if (num_arg > 0) + { + int type1 = (sp-num_arg+1)->type, type2 = (sp-num_arg+2)->type; + if (instrs[instruction].type[0] != 0 && + (instrs[instruction].type[0] & type1) == 0) + { + bad_arg(1, instruction + EFUN_FIRST, sp-num_arg+1); + } + if (num_arg > 1) + { + if (instrs[instruction].type[1] != 0 && + (instrs[instruction].type[1] & type2) == 0) + { + bad_arg(2, instruction + EFUN_FIRST, sp-num_arg+2); + } + } + } + /* * Safety measure. It is supposed that the evaluator knows - * the number of arguments. - */ + * the number of arguments. + */ #ifdef DEBUG - if (xnum_arg != -1 && instruction + EFUN_FIRST != F_CALL_SELF) { - expected_stack = sp - num_arg + 1; - } else { - expected_stack = 0; - } + if (xnum_arg != -1 && instruction + EFUN_FIRST != F_CALL_SELF) { + expected_stack = sp - num_arg + 1; + } else { + expected_stack = 0; + } #endif } instruction += EFUN_FIRST; #ifdef OPCPROF if (instruction >= 0 && instruction < MAXOPC) - opcount[instruction]++; + opcount[instruction]++; #endif /* * Execute the instructions. The number of arguments are correct, @@ -6701,230 +6701,230 @@ eval_instruction(char *p) */ #ifdef TRACE_CODE if (TRACEP(TRACE_EXEC)) { - do_trace("Exec ", get_f_name(instruction), "\n"); + do_trace("Exec ", get_f_name(instruction), "\n"); } #endif switch(instruction) { default: #ifdef DEBUG - if (instruction >= EFUN_FIRST && instruction <= EFUN_LAST) + if (instruction >= EFUN_FIRST && instruction <= EFUN_LAST) #endif - efun_table[instruction - EFUN_FIRST](num_arg); + efun_table[instruction - EFUN_FIRST](num_arg); #ifdef DEBUG - else - fatal("Undefined instruction %s (%d)\n", get_f_name(instruction), - instruction); + else + fatal("Undefined instruction %s (%d)\n", get_f_name(instruction), + instruction); #endif - break; + break; case F_RETURN: - { - int do_return = csp->extern_call; + { + int do_return = csp->extern_call; - if (sp > fp) { - struct svalue *sv; + if (sp > fp) { + struct svalue *sv; - sv = sp--; - /* - * Deallocate frame and return. - */ + sv = sp--; + /* + * Deallocate frame and return. + */ while (sp >= fp) - pop_stack(); + pop_stack(); - *++sp = *sv; /* This way, the same ref counts are maintained */ - } + *++sp = *sv; /* This way, the same ref counts are maintained */ + } #ifdef DEBUG - if (sp != fp) { - fatal("Bad stack at F_RETURN\n"); /* marion */ - } + if (sp != fp) { + fatal("Bad stack at F_RETURN\n"); /* marion */ + } #endif - pop_control_stack(); - tracedepth--; + pop_control_stack(); + tracedepth--; #ifdef TRACE_CODE - if (TRACEP(TRACE_RETURN)) { - do_trace("Return", "", ""); - if (TRACETST(TRACE_ARGS)) { - write_socket(string_print_formatted(0, " with value: %O", 1, sp), - command_giver); - } - write_socket("\n", command_giver); - } + if (TRACEP(TRACE_RETURN)) { + do_trace("Return", "", ""); + if (TRACETST(TRACE_ARGS)) { + write_socket(string_print_formatted(0, " with value: %O", 1, sp), + command_giver); + } + write_socket("\n", command_giver); + } #endif - if (do_return) { /* The control stack was popped just before */ - return; - } + if (do_return) { /* The control stack was popped just before */ + return; + } - } + } - break; + break; case F_TRY: { - struct gdexception exception_frame; - char *new_pc; + struct gdexception exception_frame; + char *new_pc; #ifdef DEBUG - struct svalue *stack; - int args, ins; + struct svalue *stack; + int args, ins; #endif - push_pop_error_context (1); - catch_level++; + push_pop_error_context (1); + catch_level++; - pc += 1 + sizeof(offset_t); + pc += 1 + sizeof(offset_t); #ifdef DEBUG - stack = expected_stack; - ins = instruction; - args = num_arg; + stack = expected_stack; + ins = instruction; + args = num_arg; #endif - /* signal catch OK - print no err msg */ - if (setjmp(exception_frame.e_context)) - { - /* - * They did a throw() or error. That means that the control - * stack must be restored manually here. - * Restore the value of expected_stack also. It is always 0 - * for catch(). - */ - unsigned int varnum; + /* signal catch OK - print no err msg */ + if (setjmp(exception_frame.e_context)) + { + /* + * They did a throw() or error. That means that the control + * stack must be restored manually here. + * Restore the value of expected_stack also. It is always 0 + * for catch(). + */ + unsigned int varnum; #ifdef DEBUG - num_arg = args; - instruction = ins; - expected_stack = 0; + num_arg = args; + instruction = ins; + expected_stack = 0; #endif - push_pop_error_context (-1); - catch_level--; - new_pc = current_prog->program + read_address(pc); - pc += sizeof(offset_t); - varnum = EXTRACT_UCHAR(pc); - assign_svalue(fp + varnum, &catch_value); - pc = new_pc; - /* If it was eval_cost too big when cant really catch it */ - if (eval_cost == 0) { - eval_cost = MAX_COST; - if (catch_level == 0) - eval_cost -= EXTRA_COST; - } - } else { + push_pop_error_context (-1); + catch_level--; + new_pc = current_prog->program + read_address(pc); + pc += sizeof(offset_t); + varnum = EXTRACT_UCHAR(pc); + assign_svalue(fp + varnum, &catch_value); + pc = new_pc; + /* If it was eval_cost too big when cant really catch it */ + if (eval_cost == 0) { + eval_cost = MAX_COST; + if (catch_level == 0) + eval_cost -= EXTRA_COST; + } + } else { #ifdef DEBUG - num_arg = args; - instruction = ins; - expected_stack = stack; + num_arg = args; + instruction = ins; + expected_stack = stack; #endif - exception_frame.e_exception = exception; - exception_frame.e_catch = 1; - exception = &exception_frame; - - eval_instruction(pc); - } - - /* next error will return 1 by default */ - assign_svalue(&catch_value, &const1); - break; - case F_END_TRY: - new_pc = pc; - push_pop_error_context(0); - catch_level--; - pc = new_pc; - return; - } + exception_frame.e_exception = exception; + exception_frame.e_catch = 1; + exception = &exception_frame; + + eval_instruction(pc); + } + + /* next error will return 1 by default */ + assign_svalue(&catch_value, &const1); + break; + case F_END_TRY: + new_pc = pc; + push_pop_error_context(0); + catch_level--; + pc = new_pc; + return; + } case F_CATCH: - /* - * Catch/Throw - catch errors in system or other peoples routines. - */ - { - struct gdexception exception_frame; + /* + * Catch/Throw - catch errors in system or other peoples routines. + */ + { + struct gdexception exception_frame; #ifdef DEBUG - struct svalue *stack; - int args, ins; + struct svalue *stack; + int args, ins; #endif - char *old_pc; + char *old_pc; - /* - * Compute address of next instruction after the CATCH statement. - */ + /* + * Compute address of next instruction after the CATCH statement. + */ offset_t new_pc_offset = read_address(pc); - pc += sizeof(offset_t); - /* - * Save some global variables that must be restored separately - * after a longjmp. The stack will have to be manually popped all - * the way. - */ - old_pc = pc; - pc = current_prog->program + new_pc_offset; /* save with pc == where to continue */ - push_pop_error_context (1); - catch_level++; - pc = old_pc; - /* - * We save and restore expected_stack, instruction and num_arg - * here to work around problems with some implementations of - * setjmp/longjmp - */ + pc += sizeof(offset_t); + /* + * Save some global variables that must be restored separately + * after a longjmp. The stack will have to be manually popped all + * the way. + */ + old_pc = pc; + pc = current_prog->program + new_pc_offset; /* save with pc == where to continue */ + push_pop_error_context (1); + catch_level++; + pc = old_pc; + /* + * We save and restore expected_stack, instruction and num_arg + * here to work around problems with some implementations of + * setjmp/longjmp + */ #ifdef DEBUG - stack = expected_stack; - ins = instruction; - args = num_arg; + stack = expected_stack; + ins = instruction; + args = num_arg; #endif - /* signal catch OK - print no err msg */ - if (setjmp(exception_frame.e_context)) - { - /* - * They did a throw() or error. That means that the control - * stack must be restored manually here. - * Restore the value of expected_stack also. It is always 0 - * for catch(). - */ + /* signal catch OK - print no err msg */ + if (setjmp(exception_frame.e_context)) + { + /* + * They did a throw() or error. That means that the control + * stack must be restored manually here. + * Restore the value of expected_stack also. It is always 0 + * for catch(). + */ #ifdef DEBUG - num_arg = args; - instruction = ins; - expected_stack = 0; + num_arg = args; + instruction = ins; + expected_stack = 0; #endif - push_pop_error_context (-1); - catch_level--; - push_svalue(&catch_value); - - /* If it was eval_cost too big when cant really catch it */ - if (eval_cost == 0) { - eval_cost = MAX_COST; - if (catch_level == 0) - eval_cost -= EXTRA_COST; - } - } else { + push_pop_error_context (-1); + catch_level--; + push_svalue(&catch_value); + + /* If it was eval_cost too big when cant really catch it */ + if (eval_cost == 0) { + eval_cost = MAX_COST; + if (catch_level == 0) + eval_cost -= EXTRA_COST; + } + } else { #ifdef DEBUG - num_arg = args; - instruction = ins; - expected_stack = stack; + num_arg = args; + instruction = ins; + expected_stack = stack; #endif - exception_frame.e_exception = exception; - exception_frame.e_catch = 1; - exception = &exception_frame; - - eval_instruction(pc); - } - - /* next error will return 1 by default */ - assign_svalue(&catch_value, &const1); - break; - case F_END_CATCH: - push_pop_error_context(0); - catch_level--; - push_svalue(&const0); - return; - } + exception_frame.e_exception = exception; + exception_frame.e_catch = 1; + exception = &exception_frame; + + eval_instruction(pc); + } + + /* next error will return 1 by default */ + assign_svalue(&catch_value, &const1); + break; + case F_END_CATCH: + push_pop_error_context(0); + catch_level--; + push_svalue(&const0); + return; + } } #ifdef DEBUG - if ((expected_stack && expected_stack != sp) || sp < fp + csp->num_local_variables - 1) + if ((expected_stack && expected_stack != sp) || sp < fp + csp->num_local_variables - 1) { fatal("Bad stack after evaluation. Was %ld, expected %ld, frame ends at %ld. Instruction %d, num arg %d\n", - sp - start_of_stack, - expected_stack - start_of_stack, - (fp - start_of_stack) + csp->num_local_variables - 1, - instruction, num_arg); + sp - start_of_stack, + expected_stack - start_of_stack, + (fp - start_of_stack) + csp->num_local_variables - 1, + instruction, num_arg); } #endif /* DEBUG */ goto again; @@ -6932,10 +6932,10 @@ eval_instruction(char *p) #ifdef GLOBAL_CACHE struct fcache1 { - int tp; - char *fn; - int ff_inh; - int ff_ix; + int tp; + char *fn; + int ff_inh; + int ff_ix; }; #endif @@ -6954,7 +6954,7 @@ s_f_f(char *name, struct program *prog) #endif if (!name) - return 0; + return 0; #ifdef GLOBAL_CACHE @@ -6965,40 +6965,40 @@ s_f_f(char *name, struct program *prog) globcache_tries++; global_hash_val = (int)(((unsigned long)prog / sizeof(void *)) ^ - ((unsigned long)prog >> 16) ^ - ((unsigned long)name / sizeof(void *)) ^ - ((unsigned long)name >> 16)) & (GLOBAL_CACHE - 1); + ((unsigned long)prog >> 16) ^ + ((unsigned long)name / sizeof(void *)) ^ + ((unsigned long)name >> 16)) & (GLOBAL_CACHE - 1); if (fc[global_hash_val].tp == prog->id_number && - fc[global_hash_val].fn == name) + fc[global_hash_val].fn == name) { - globcache_hits++; + globcache_hits++; #ifdef CACHE_STATS - global_first_saves += prog->num_inherited - fc[global_hash_val].ff_inh; + global_first_saves += prog->num_inherited - fc[global_hash_val].ff_inh; #endif - function_inherit_found = fc[global_hash_val].ff_inh; - function_index_found = fc[global_hash_val].ff_ix; - if (function_inherit_found != -1) - { - int type_mod1 = prog->inherit[function_inherit_found].type; - - function_prog_found = prog->inherit[function_inherit_found].prog; - function_type_mod_found = function_prog_found-> - functions[function_index_found].type_flags & TYPE_MOD_MASK ; - - /* Correct function_type_mod_found */ - if (function_type_mod_found & TYPE_MOD_PRIVATE) - type_mod1 &= ~TYPE_MOD_PUBLIC; - if (function_type_mod_found & TYPE_MOD_PUBLIC) - type_mod1 &= ~TYPE_MOD_PRIVATE; - function_type_mod_found |= type_mod1; - return 1; - } - else - { - function_prog_found = 0; - return 0; - } + function_inherit_found = fc[global_hash_val].ff_inh; + function_index_found = fc[global_hash_val].ff_ix; + if (function_inherit_found != -1) + { + int type_mod1 = prog->inherit[function_inherit_found].type; + + function_prog_found = prog->inherit[function_inherit_found].prog; + function_type_mod_found = function_prog_found-> + functions[function_index_found].type_flags & TYPE_MOD_MASK ; + + /* Correct function_type_mod_found */ + if (function_type_mod_found & TYPE_MOD_PRIVATE) + type_mod1 &= ~TYPE_MOD_PUBLIC; + if (function_type_mod_found & TYPE_MOD_PUBLIC) + type_mod1 &= ~TYPE_MOD_PRIVATE; + function_type_mod_found |= type_mod1; + return 1; + } + else + { + function_prog_found = 0; + return 0; + } } fc[global_hash_val].tp = prog->id_number; @@ -7014,35 +7014,35 @@ s_f_f(char *name, struct program *prog) for (;;) { - /* Beware of empty function lists */ + /* Beware of empty function lists */ #ifdef CACHE_STATS - searches_done++; + searches_done++; #endif - if (cprog->num_functions) - { - /* hash - */ - probe = PTR_HASH(name, cprog->num_functions); - /* Select the right one from the chain - */ - while (name != cprog->func_hash[probe].name && probe >= 0) - probe = cprog->func_hash[probe].next_hashed_function; - - if (probe >= 0) - { - probe = cprog->func_hash[probe].func_index; - break; - } - } - if (--i < 0) - return 0; + if (cprog->num_functions) + { + /* hash + */ + probe = PTR_HASH(name, cprog->num_functions); + /* Select the right one from the chain + */ + while (name != cprog->func_hash[probe].name && probe >= 0) + probe = cprog->func_hash[probe].next_hashed_function; + + if (probe >= 0) + { + probe = cprog->func_hash[probe].func_index; + break; + } + } + if (--i < 0) + return 0; - cprog = prog->inherit[i].prog; + cprog = prog->inherit[i].prog; } /* Found. Undefined prototypes cannot occur in compiled programs - */ + */ #ifdef CACHE_STATS searches_needed -= i; #endif @@ -7050,25 +7050,25 @@ s_f_f(char *name, struct program *prog) #ifdef GLOBAL_CACHE fc[global_hash_val].ff_inh = #endif - function_inherit_found = i; + function_inherit_found = i; function_prog_found = prog->inherit[i].prog; #ifdef GLOBAL_CACHE fc[global_hash_val].ff_ix = #endif - function_index_found = probe; + function_index_found = probe; function_type_mod_found = - prog->inherit[i].prog->functions[probe].type_flags & - TYPE_MOD_MASK ; + prog->inherit[i].prog->functions[probe].type_flags & + TYPE_MOD_MASK ; /* Correct function_type_mod_found */ type_mod = prog->inherit[i].type; if (function_type_mod_found & TYPE_MOD_PRIVATE) - type_mod &= ~TYPE_MOD_PUBLIC; + type_mod &= ~TYPE_MOD_PUBLIC; if (function_type_mod_found & TYPE_MOD_PUBLIC) - type_mod &= ~TYPE_MOD_PRIVATE; + type_mod &= ~TYPE_MOD_PRIVATE; function_type_mod_found |= type_mod; return 1; } @@ -7135,14 +7135,14 @@ apply_low(char *fun, struct object *ob, int num_arg, int external) debug_apply_fun[sizeof debug_apply_fun - 1] = '\0'; #endif if (*fun == '.') - goto failure; + goto failure; /* * If there is a chain of objects shadowing, start with the first * of these. */ while (ob->shadowed && ob->shadowed != current_object) - ob = ob->shadowed; + ob = ob->shadowed; sfun = find_sstring(fun); @@ -7151,41 +7151,41 @@ apply_low(char *fun, struct object *ob, int num_arg, int external) #ifdef DEBUG if (ob->flags & O_DESTRUCTED) - fatal("apply() on destructed object\n"); + fatal("apply() on destructed object\n"); #endif if (!(ob->flags & O_CREATED)) - create_object(ob); + create_object(ob); if (ob->flags & O_DESTRUCTED) - goto failure; + goto failure; if (s_f_f(sfun, progp)) { - /* Static or private functions may not be called from outside. */ - if (((ob != current_object || external) && - function_type_mod_found & (TYPE_MOD_STATIC | TYPE_MOD_PRIVATE)) || - (function_type_mod_found & TYPE_MOD_PRIVATE && - function_prog_found != ob->prog)) - ; /* Do nothing */ - else + /* Static or private functions may not be called from outside. */ + if (((ob != current_object || external) && + function_type_mod_found & (TYPE_MOD_STATIC | TYPE_MOD_PRIVATE)) || + (function_type_mod_found & TYPE_MOD_PRIVATE && + function_prog_found != ob->prog)) + ; /* Do nothing */ + else { - call_function(ob, function_inherit_found, - (unsigned int)function_index_found, num_arg); + call_function(ob, function_inherit_found, + (unsigned int)function_index_found, num_arg); - return 1; + return 1; - } + } } /* Not found */ if (ob->shadowing) { - /* - * This is an object shadowing another. The function was not found, - * but can maybe be found in the object we are shadowing. - */ - ob = ob->shadowing; - goto retry_for_shadow; + /* + * This is an object shadowing another. The function was not found, + * but can maybe be found in the object we are shadowing. + */ + ob = ob->shadowing; + goto retry_for_shadow; } failure: /* Failure. Deallocate stack. */ @@ -7214,17 +7214,17 @@ sapply(char *fun, struct object *ob, int num_arg, int ext) #ifdef DEALLOCATE_MEMORY_AT_SHUTDOWN if (fun == NULL) { - free_svalue(&ret_value); - return NULL; + free_svalue(&ret_value); + return NULL; } #endif #ifdef TRACE_CODE if (TRACEP(TRACE_APPLY)) { - char buff[1024]; - (void)sprintf(buff,"%s->%s", ob->name, fun); - do_trace("Apply", "", "\n"); + char buff[1024]; + (void)sprintf(buff,"%s->%s", ob->name, fun); + do_trace("Apply", "", "\n"); } #endif @@ -7233,16 +7233,16 @@ sapply(char *fun, struct object *ob, int num_arg, int ext) #endif if (!ob || (ob->flags & O_DESTRUCTED)) { pop_n_elems(num_arg); - return 0; + return 0; } if (apply_low(fun, ob, num_arg, ext) == 0) - return 0; + return 0; assign_svalue(&ret_value, sp); pop_stack(); #ifdef DEBUG if (expected_sp != sp) - fatal("Corrupt stack pointer.\n"); + fatal("Corrupt stack pointer.\n"); #endif return &ret_value; } @@ -7265,14 +7265,14 @@ function_exists(char *fun, struct object *ob) { #ifdef DEBUG if (ob->flags & O_DESTRUCTED) - fatal("function_exists() on destructed object\n"); + fatal("function_exists() on destructed object\n"); #endif if (*fun == '.') - return 0; + return 0; if ( search_for_function (fun, ob->prog) - && (!(function_type_mod_found & (TYPE_MOD_STATIC|TYPE_MOD_PRIVATE)) - || current_object == ob) ) - return function_prog_found->name; + && (!(function_type_mod_found & (TYPE_MOD_STATIC|TYPE_MOD_PRIVATE)) + || current_object == ob) ) + return function_prog_found->name; /* Not found */ return 0; } @@ -7291,18 +7291,18 @@ call_function(struct object *ob, int inh_index, unsigned int fun, int num_arg) struct program *progp; if (inh_index < 0 || /*fun < 0 ||*/ inh_index >= (int)ob->prog->num_inherited || - fun >= ob->prog->inherit[inh_index].prog->num_functions) + fun >= ob->prog->inherit[inh_index].prog->num_functions) { - /* invalid function */ - pop_n_elems(num_arg); - push_number(0); - return; + /* invalid function */ + pop_n_elems(num_arg); + push_number(0); + return; } progp = ob->prog->inherit[inh_index].prog; funp = &progp->functions[fun]; if (funp->type_flags & NAME_PROTOTYPE) /* Cannot happen. */ - return; + return; push_control_stack(ob, progp, funp); csp->ext_call = 1; @@ -7313,7 +7313,7 @@ call_function(struct object *ob, int inh_index, unsigned int fun, int num_arg) current_object = ob; #ifdef DEBUG if (current_object->prog->inherit[inh_offset].prog != current_prog) - fatal("Corrupt inherit offset!\n"); + fatal("Corrupt inherit offset!\n"); #endif cp = setup_new_frame(funp); csp->extern_call = 1; @@ -7326,7 +7326,7 @@ call_function(struct object *ob, int inh_index, unsigned int fun, int num_arg) */ char * inner_get_srccode_position(int code, struct lineno *lineno, int lineno_count, - char *inc_files, char *name) + char *inc_files, char *name) { static char buff[200]; struct lineno *lo = lineno, *hi = lineno + lineno_count - 1; @@ -7389,17 +7389,17 @@ get_srccode_position(int offset, struct program *progp) char *ret; if (progp == 0) - return ""; + return ""; #ifdef DEBUG if (offset > progp->program_size) - fatal("Illegal offset %d in object %s\n", offset, progp->name); + fatal("Illegal offset %d in object %s\n", offset, progp->name); #endif ret = inner_get_srccode_position(offset, progp->line_numbers, - progp->sizeof_line_numbers, - progp->include_files, - progp->name); + progp->sizeof_line_numbers, + progp->include_files, + progp->name); return ret; } @@ -7419,34 +7419,34 @@ dump_trace(int how) char *line; if (current_prog == 0) - return 0; + return 0; if (csp < &control_stack[0]) { - (void) printf("No trace.\n"); - debug_message("No trace.\n"); - return 0; + (void) printf("No trace.\n"); + debug_message("No trace.\n"); + return 0; } #if defined(DEBUG) && defined(TRACE_CODE) if (how) - (void) last_instructions(); + (void) last_instructions(); #endif for (p = &control_stack[0]; p < csp; p++) { #define FORM "%-15s in /%s\n /%s\n %s\n" - line = get_srccode_position((int)p[1].pc, p[1].prog); - debug_message(FORM, - p[0].funp ? p[0].funp->name : "CATCH", - p[1].prog->name, p[1].ob->name, - line); - if (p->funp && strcmp(p->funp->name, "heart_beat") == 0) - ret = p->ob?p->ob->name:0; /*crash unliked gc*/ + line = get_srccode_position((int)p[1].pc, p[1].prog); + debug_message(FORM, + p[0].funp ? p[0].funp->name : "CATCH", + p[1].prog->name, p[1].ob->name, + line); + if (p->funp && strcmp(p->funp->name, "heart_beat") == 0) + ret = p->ob?p->ob->name:0; /*crash unliked gc*/ } line = get_srccode_position(pc - current_prog->program, - current_prog); + current_prog); debug_message(FORM, - p[0].funp ? p[0].funp->name : "CATCH", - current_prog->name, current_object->name, - line); + p[0].funp ? p[0].funp->name : "CATCH", + current_prog->name, current_object->name, + line); return ret; } @@ -7456,7 +7456,7 @@ get_srccode_position_if_any() char *ret = ""; if (current_prog) - ret = (char *)get_srccode_position(pc - current_prog->program, current_prog); + ret = (char *)get_srccode_position(pc - current_prog->program, current_prog); return ret; } @@ -7466,20 +7466,20 @@ find_percent(char *str) { for (;;) { - str = strchr(str, '%'); - if (str == 0) - return 0; - if (str[1] != '%') - return str; - str++; + str = strchr(str, '%'); + if (str == 0) + return 0; + if (str[1] != '%') + return str; + str++; } } static int inter_sscanf(int num_arg) { - char *fmt; /* Format description */ - char *in_string; /* The string to be parsed. */ + char *fmt; /* Format description */ + char *in_string; /* The string to be parsed. */ int number_of_matches; char *cp; struct svalue *arg = sp - num_arg + 1; @@ -7488,23 +7488,23 @@ inter_sscanf(int num_arg) * First get the string to be parsed. */ if (arg[0].type != T_STRING) - bad_arg(1, F_SSCANF, &arg[0]); + bad_arg(1, F_SSCANF, &arg[0]); in_string = arg[0].u.string; if (in_string == 0) - return 0; + return 0; /* * Now get the format description. */ if (arg[1].type != T_STRING) - bad_arg(2, F_SSCANF, &arg[1]); + bad_arg(2, F_SSCANF, &arg[1]); fmt = arg[1].u.string; /* * First, skip and match leading text. */ for (cp = find_percent(fmt); fmt != cp; fmt++, in_string++) { - if (in_string[0] == '\0' || fmt[0] != in_string[0]) - return 0; + if (in_string[0] == '\0' || fmt[0] != in_string[0]) + return 0; } /* * Loop for every % or substring in the format. Update num_arg and the @@ -7513,145 +7513,145 @@ inter_sscanf(int num_arg) num_arg -= 2; arg += 2; for (number_of_matches = 0; num_arg > 0; - /* LINTED: expression has null effect */ - number_of_matches++, num_arg--, arg++) - { - int i, type, base = 0; - - if (fmt[0] == '\0') - { - /* - * We have reached end of the format string. - * If there are any chars left in the in_string, - * then we put them in the last variable (if any). - */ - if (in_string[0]) - { - free_svalue(arg->u.lvalue); - arg->u.lvalue->type = T_STRING; - arg->u.lvalue->u.string = make_mstring(in_string); - arg->u.lvalue->string_type = STRING_MSTRING; - number_of_matches++; - } - break; - } + /* LINTED: expression has null effect */ + number_of_matches++, num_arg--, arg++) + { + int i, type, base = 0; + + if (fmt[0] == '\0') + { + /* + * We have reached end of the format string. + * If there are any chars left in the in_string, + * then we put them in the last variable (if any). + */ + if (in_string[0]) + { + free_svalue(arg->u.lvalue); + arg->u.lvalue->type = T_STRING; + arg->u.lvalue->u.string = make_mstring(in_string); + arg->u.lvalue->string_type = STRING_MSTRING; + number_of_matches++; + } + break; + } #ifdef DEBUG - if (fmt[0] != '%') - fatal("Should be a %% now !\n"); + if (fmt[0] != '%') + fatal("Should be a %% now !\n"); #endif - type = T_STRING; - if (fmt[1] == 'd') { - type = T_NUMBER; base = 10;} - else if (fmt[1] == 'x') { - type = T_NUMBER; base = 0x10;} - else if (fmt[1] == 'o') { - type = T_NUMBER; base = 010;} - else if (fmt[1] == 'i') { - type = T_NUMBER; base = 0;} - else if (fmt[1] == 'f') - type = T_FLOAT; - else if (fmt[1] != 's') - error("Bad type : '%%%c' in sscanf fmt string.\n", fmt[1]); - fmt += 2; - /* - * Parsing a number is the easy case. Just use strtol() to - * find the end of the number. - */ - if (type == T_NUMBER) - { - char *tmp = in_string; - long long tmp_num; - - tmp_num = (long long) strtoll(in_string, &in_string, base); - if(tmp == in_string) - { - /* No match */ - break; - } - free_svalue(arg->u.lvalue); - arg->u.lvalue->type = T_NUMBER; - arg->u.lvalue->u.number = tmp_num; - while(fmt[0] && fmt[0] == in_string[0]) - fmt++, in_string++; - if (fmt[0] != '%') - { - number_of_matches++; - break; - } - continue; - } - if (type == T_FLOAT) - { - char *tmp = in_string; - double tmp_num; - - tmp_num = strtod(in_string, &in_string); - if(tmp == in_string) - { - /* No match */ - break; - } - free_svalue(arg->u.lvalue); - arg->u.lvalue->type = T_FLOAT; - arg->u.lvalue->u.real = tmp_num; - while(fmt[0] && fmt[0] == in_string[0]) - fmt++, in_string++; - if (fmt[0] != '%') - { - number_of_matches++; - break; - } - continue; - } - /* - * Now we have the string case. - */ - cp = find_percent(fmt); - if (cp == fmt) - error("Illegal to have 2 adjacent %%s in fmt string in sscanf.\n"); - if (cp == 0) - cp = fmt + strlen(fmt); - /* - * First case: There was no extra characters to match. - * Then this is the last match. - */ - if (cp == fmt) - { - free_svalue(arg->u.lvalue); - - arg->u.lvalue->type = T_STRING; - arg->u.lvalue->u.string = make_mstring(in_string); - arg->u.lvalue->string_type = STRING_MSTRING; - number_of_matches++; - break; - } - for (i = 0; in_string[i]; i++) - { - if (strncmp(in_string+i, fmt, (size_t)(cp - fmt)) == 0) - { - char *match; - /* - * Found a match ! - */ - match = allocate_mstring((size_t)i); - (void) strncpy(match, in_string, (size_t)i); - in_string += i + cp - fmt; - match[i] = '\0'; - free_svalue(arg->u.lvalue); - arg->u.lvalue->type = T_STRING; - arg->u.lvalue->string_type = STRING_MSTRING; - arg->u.lvalue->u.string = match; - fmt = cp; /* Advance fmt to next % */ - break; - } - } - if (fmt == cp) /* If match, then do continue. */ - continue; - /* - * No match was found. Then we stop here, and return - * the result so far ! - */ - break; + type = T_STRING; + if (fmt[1] == 'd') { + type = T_NUMBER; base = 10;} + else if (fmt[1] == 'x') { + type = T_NUMBER; base = 0x10;} + else if (fmt[1] == 'o') { + type = T_NUMBER; base = 010;} + else if (fmt[1] == 'i') { + type = T_NUMBER; base = 0;} + else if (fmt[1] == 'f') + type = T_FLOAT; + else if (fmt[1] != 's') + error("Bad type : '%%%c' in sscanf fmt string.\n", fmt[1]); + fmt += 2; + /* + * Parsing a number is the easy case. Just use strtol() to + * find the end of the number. + */ + if (type == T_NUMBER) + { + char *tmp = in_string; + long long tmp_num; + + tmp_num = (long long) strtoll(in_string, &in_string, base); + if(tmp == in_string) + { + /* No match */ + break; + } + free_svalue(arg->u.lvalue); + arg->u.lvalue->type = T_NUMBER; + arg->u.lvalue->u.number = tmp_num; + while(fmt[0] && fmt[0] == in_string[0]) + fmt++, in_string++; + if (fmt[0] != '%') + { + number_of_matches++; + break; + } + continue; + } + if (type == T_FLOAT) + { + char *tmp = in_string; + double tmp_num; + + tmp_num = strtod(in_string, &in_string); + if(tmp == in_string) + { + /* No match */ + break; + } + free_svalue(arg->u.lvalue); + arg->u.lvalue->type = T_FLOAT; + arg->u.lvalue->u.real = tmp_num; + while(fmt[0] && fmt[0] == in_string[0]) + fmt++, in_string++; + if (fmt[0] != '%') + { + number_of_matches++; + break; + } + continue; + } + /* + * Now we have the string case. + */ + cp = find_percent(fmt); + if (cp == fmt) + error("Illegal to have 2 adjacent %%s in fmt string in sscanf.\n"); + if (cp == 0) + cp = fmt + strlen(fmt); + /* + * First case: There was no extra characters to match. + * Then this is the last match. + */ + if (cp == fmt) + { + free_svalue(arg->u.lvalue); + + arg->u.lvalue->type = T_STRING; + arg->u.lvalue->u.string = make_mstring(in_string); + arg->u.lvalue->string_type = STRING_MSTRING; + number_of_matches++; + break; + } + for (i = 0; in_string[i]; i++) + { + if (strncmp(in_string+i, fmt, (size_t)(cp - fmt)) == 0) + { + char *match; + /* + * Found a match ! + */ + match = allocate_mstring((size_t)i); + (void) strncpy(match, in_string, (size_t)i); + in_string += i + cp - fmt; + match[i] = '\0'; + free_svalue(arg->u.lvalue); + arg->u.lvalue->type = T_STRING; + arg->u.lvalue->string_type = STRING_MSTRING; + arg->u.lvalue->u.string = match; + fmt = cp; /* Advance fmt to next % */ + break; + } + } + if (fmt == cp) /* If match, then do continue. */ + continue; + /* + * No match was found. Then we stop here, and return + * the result so far ! + */ + break; } return number_of_matches; } @@ -7664,9 +7664,9 @@ opcdump(void) int i; for(i = 0; i < MAXOPC; i++) - if (opcount[i]) - (void)fprintf(stderr, "%-20s %12d: %12d\n", get_f_name(i), i, - opcount[i]); + if (opcount[i]) + (void)fprintf(stderr, "%-20s %12d: %12d\n", get_f_name(i), i, + opcount[i]); } #endif @@ -7684,27 +7684,27 @@ reset_machine() { #if defined(PROFILE_LPC) if (csp != control_stack - 1) { - double now = current_cpu(); - struct program *prog = current_prog; - last_execution = now; - csp->frame_cpu += (now - csp->startcpu); - for (; csp != control_stack - 1; (prog = csp->prog), csp--) - { - double tot_delta = now - csp->frame_start; - if (prog) - update_prog_profile(prog, now, csp->frame_cpu, tot_delta); - if (csp->funp) { - update_func_profile(csp->funp, now, csp->frame_cpu, tot_delta, 1); - } - if (trace_calls) { - fprintf(trace_calls_file, "%*s--- %.3f / %.3f\n", - (int)(csp - control_stack) * 4, "", - csp->frame_cpu * 1000.0, - tot_delta * 1000.0); - } - } - if (trace_calls) - putc('\n', trace_calls_file); + double now = current_cpu(); + struct program *prog = current_prog; + last_execution = now; + csp->frame_cpu += (now - csp->startcpu); + for (; csp != control_stack - 1; (prog = csp->prog), csp--) + { + double tot_delta = now - csp->frame_start; + if (prog) + update_prog_profile(prog, now, csp->frame_cpu, tot_delta); + if (csp->funp) { + update_func_profile(csp->funp, now, csp->frame_cpu, tot_delta, 1); + } + if (trace_calls) { + fprintf(trace_calls_file, "%*s--- %.3f / %.3f\n", + (int)(csp - control_stack) * 4, "", + csp->frame_cpu * 1000.0, + tot_delta * 1000.0); + } + } + if (trace_calls) + putc('\n', trace_calls_file); } #else csp = control_stack - 1; @@ -7721,33 +7721,33 @@ get_arg(unsigned long a, unsigned long b) from = previous_prog[a]->program + previous_pc[a]; if (EXTRACT_UCHAR(from) + EFUN_FIRST == F_EXT) - from++; + from++; to = previous_prog[b]->program + previous_pc[b]; if (to - from < 2) - return ""; + return ""; if (to - from == 2) { - (void)sprintf(buff, "%d", from[1]); - return buff; + (void)sprintf(buff, "%d", from[1]); + return buff; } if (to - from == 3) { - short arg; - ((char *)&arg)[0] = from[1]; - ((char *)&arg)[1] = from[2]; - (void)sprintf(buff, "%d", arg); - return buff; + short arg; + ((char *)&arg)[0] = from[1]; + ((char *)&arg)[1] = from[2]; + (void)sprintf(buff, "%d", arg); + return buff; } if (to - from == 5) { - int arg; - ((char *) &arg)[0] = from[1]; - ((char *) &arg)[1] = from[2]; - ((char *) &arg)[2] = from[3]; - ((char *) &arg)[3] = from[4]; - (void)sprintf(buff, "%d", arg); - return buff; + int arg; + ((char *) &arg)[0] = from[1]; + ((char *) &arg)[1] = from[2]; + ((char *) &arg)[2] = from[3]; + ((char *) &arg)[3] = from[4]; + (void)sprintf(buff, "%d", arg); + return buff; } return ""; } @@ -7759,17 +7759,17 @@ last_instructions() i = last; do { - if (previous_prog[i]) - (void)printf("%6d: %3d%*s %8s %-25s (%d) %s\n", - (unsigned long)previous_pc[i], - previous_instruction[i], - curtracedepth[i],"", - get_arg(i, (i+1) % TRACE_SIZE), - get_f_name(previous_instruction[i]), - stack_size[i] + 1, - get_srccode_position(previous_pc[i], previous_prog[i]) - ); - i = (i + 1) % TRACE_SIZE; + if (previous_prog[i]) + (void)printf("%6d: %3d%*s %8s %-25s (%d) %s\n", + (unsigned long)previous_pc[i], + previous_instruction[i], + curtracedepth[i],"", + get_arg(i, (i+1) % TRACE_SIZE), + get_f_name(previous_instruction[i]), + stack_size[i] + 1, + get_srccode_position(previous_pc[i], previous_prog[i]) + ); + i = (i + 1) % TRACE_SIZE; } while (i != last); return last; } @@ -7785,13 +7785,13 @@ count_inherits(struct program *progp, struct program *search_prog) /* Clones will not add to the ref count of inherited progs */ if (progp->extra_ref != 1) - return; + return; for (i = 0; i < progp->num_inherited; i++) { - progp->inherit[i].prog->extra_ref++; - if (progp->inherit[i].prog == search_prog) - (void)printf("Found prog, inherited by %s\n", progp->name); - count_inherits(progp->inherit[i].prog, search_prog); + progp->inherit[i].prog->extra_ref++; + if (progp->inherit[i].prog == search_prog) + (void)printf("Found prog, inherited by %s\n", progp->name); + count_inherits(progp->inherit[i].prog, search_prog); } } @@ -7802,16 +7802,16 @@ count_ref_in_vector(struct svalue *svp, int num) for (p = svp; p < svp + num; p++) { - switch(p->type) - { - case T_OBJECT: - p->u.ob->extra_ref++; - continue; - case T_POINTER: - count_ref_in_vector(&p->u.vec->item[0], p->u.vec->size); - p->u.vec->extra_ref++; - continue; - } + switch(p->type) + { + case T_OBJECT: + p->u.ob->extra_ref++; + continue; + case T_POINTER: + count_ref_in_vector(&p->u.vec->item[0], p->u.vec->size); + p->u.vec->extra_ref++; + continue; + } } } @@ -7825,13 +7825,13 @@ clear_vector_refs(struct svalue *svp, int num) for (p = svp; p < svp + num; p++) { - switch(p->type) - { - case T_POINTER: - clear_vector_refs(&p->u.vec->item[0], p->u.vec->size); - p->u.vec->extra_ref = 0; - continue; - } + switch(p->type) + { + case T_POINTER: + clear_vector_refs(&p->u.vec->item[0], p->u.vec->size); + p->u.vec->extra_ref = 0; + continue; + } } } @@ -7852,13 +7852,13 @@ check_a_lot_ref_counts(struct program *search_prog) ob = obj_list; do { - ob->extra_ref = 0; - ob->prog->extra_ref = 0; + ob->extra_ref = 0; + ob->prog->extra_ref = 0; - clear_vector_refs(ob->variables, ob->prog->num_variables + - ob->prog->inherit[ob->prog->num_inherited - 1] - .variable_index_offset); - ob = ob->next_all; + clear_vector_refs(ob->variables, ob->prog->num_variables + + ob->prog->inherit[ob->prog->num_inherited - 1] + .variable_index_offset); + ob = ob->next_all; } while (ob != obj_list); clear_vector_refs(start_of_stack, sp - start_of_stack + 1); @@ -7872,16 +7872,16 @@ check_a_lot_ref_counts(struct program *search_prog) */ for (ob = obj_list; ob; ob = ob->next_all) { - ob->extra_ref++; - count_ref_in_vector(ob->variables, ob->prog->num_variables + - ob->prog->inherit[ob->prog->num_inherited - 1] - .variable_index_offset); - ob->prog->extra_ref++; - if (ob->prog == search_prog) - (void)printf("Found program for object %s\n", ob->name); - /* Clones will not add to the ref count of inherited progs */ - if (ob->prog->extra_ref == 1) - count_inherits(ob->prog, search_prog); + ob->extra_ref++; + count_ref_in_vector(ob->variables, ob->prog->num_variables + + ob->prog->inherit[ob->prog->num_inherited - 1] + .variable_index_offset); + ob->prog->extra_ref++; + if (ob->prog == search_prog) + (void)printf("Found program for object %s\n", ob->name); + /* Clones will not add to the ref count of inherited progs */ + if (ob->prog->extra_ref == 1) + count_inherits(ob->prog, search_prog); } /* @@ -7891,25 +7891,25 @@ check_a_lot_ref_counts(struct program *search_prog) update_ref_counts_for_players(); count_ref_from_call_outs(); if (master_ob) - master_ob->extra_ref++; + master_ob->extra_ref++; if (search_prog) - return; + return; /* * Pass 3: Check the ref counts. */ for (ob = obj_list; ob; ob = ob->next_all) { - if (ob->ref != ob->extra_ref) - fatal("Bad ref count in object %s, %d - %d\n", ob->name, - ob->ref, ob->extra_ref); - if (ob->prog->ref != ob->prog->extra_ref) - { - check_a_lot_ref_counts(ob->prog); - fatal("Bad ref count in prog %s, %d - %d\n", ob->prog->name, - ob->prog->ref, ob->prog->extra_ref); - } + if (ob->ref != ob->extra_ref) + fatal("Bad ref count in object %s, %d - %d\n", ob->name, + ob->ref, ob->extra_ref); + if (ob->prog->ref != ob->prog->extra_ref) + { + check_a_lot_ref_counts(ob->prog); + fatal("Bad ref count in prog %s, %d - %d\n", ob->prog->name, + ob->prog->ref, ob->prog->extra_ref); + } } } @@ -7927,8 +7927,8 @@ do_trace(char *msg, char *fname, char *post) (void)sprintf(buf, "*** %d %*s %s %s %s", tracedepth, tracedepth, "", msg, objname, fname); p = buf + strlen(buf); if (TRACETST(TRACE_TOS)) { - (void)strcpy(p, string_print_formatted(0, " *sp=%O", 1, sp)); - p += strlen(p); + (void)strcpy(p, string_print_formatted(0, " *sp=%O", 1, sp)); + p += strlen(p); } (void)strcpy(p, post); write_socket(buf, command_giver); @@ -7947,16 +7947,16 @@ resolve_master_fkntab() for (tab = master_fkntab; tab->name; tab++) { - if (search_for_function(tab->name, prog)) - { - tab->inherit_index = function_inherit_found; - tab->function_index = function_index_found; - } - else - { - tab->inherit_index = (unsigned short)-1; - tab->function_index = (unsigned short)-1; - } + if (search_for_function(tab->name, prog)) + { + tab->inherit_index = function_inherit_found; + tab->function_index = function_index_found; + } + else + { + tab->inherit_index = (unsigned short)-1; + tab->function_index = (unsigned short)-1; + } } } @@ -7967,15 +7967,15 @@ apply_master_ob(int fun, int num_arg) static struct svalue retval = { T_NUMBER }; if (s_flag) - num_mcall++; + num_mcall++; if (!master_ob || (master_fkntab[fun].inherit_index == (unsigned short)-1 && - master_fkntab[fun].function_index == (unsigned short)-1)) + master_fkntab[fun].function_index == (unsigned short)-1)) { - pop_n_elems(num_arg); - return 0; /* No such function */ + pop_n_elems(num_arg); + return 0; /* No such function */ } call_function(master_ob, master_fkntab[fun].inherit_index, - (unsigned int)master_fkntab[fun].function_index, num_arg); + (unsigned int)master_fkntab[fun].function_index, num_arg); assign_svalue(&retval, sp); pop_stack(); @@ -7995,13 +7995,13 @@ remove_object_from_stack(struct object *ob) for (svp = start_of_stack; svp <= sp; svp++) { - if (svp->type != T_OBJECT) - continue; - if (svp->u.ob != ob) - continue; - free_object(svp->u.ob, "remove_object_from_stack"); - svp->type = T_NUMBER; - svp->u.number = 0; + if (svp->type != T_OBJECT) + continue; + if (svp->u.ob != ob) + continue; + free_object(svp->u.ob, "remove_object_from_stack"); + svp->type = T_NUMBER; + svp->u.number = 0; } } void @@ -8010,26 +8010,26 @@ stack_swap_objects(struct object *ob1, struct object *ob2) struct control_stack *cspi; if (current_object == ob1) - current_object = ob2; + current_object = ob2; else if (current_object == ob2) - current_object = ob1; + current_object = ob1; if (previous_ob == ob1) - previous_ob = ob2; + previous_ob = ob2; else if (previous_ob == ob2) - previous_ob = ob1; + previous_ob = ob1; for (cspi = csp; cspi >= control_stack; cspi--) { - if (cspi->ob == ob1) - cspi->ob = ob2; - else if (cspi->ob == ob2) - cspi->ob = ob1; + if (cspi->ob == ob1) + cspi->ob = ob2; + else if (cspi->ob == ob2) + cspi->ob = ob1; - if (cspi->prev_ob == ob1) - cspi->prev_ob = ob2; - else if (cspi->prev_ob == ob2) - cspi->prev_ob = ob1; + if (cspi->prev_ob == ob1) + cspi->prev_ob = ob2; + else if (cspi->prev_ob == ob2) + cspi->prev_ob = ob1; } /* FIXME: Process error-stack and data-stack as well. */ } @@ -8039,8 +8039,8 @@ static int strpref(char *p, char *s) { while (*p) - if (*p++ != *s++) - return 0; + if (*p++ != *s++) + return 0; return 1; } #endif @@ -8049,34 +8049,34 @@ static void call_efun(int instruction, int numa) { if (instruction < EFUN_FIRST || instruction > EFUN_LAST) - fatal("Undefined instruction %s (%d)\n", get_f_name(instruction), - instruction); + fatal("Undefined instruction %s (%d)\n", get_f_name(instruction), + instruction); instruction -= EFUN_FIRST; if (instrs[instruction].min_arg != instrs[instruction].max_arg) { - if (instrs[instruction].min_arg != -1 && - instrs[instruction].min_arg > numa) - error("Too few arguments to efun.\n"); - if (instrs[instruction].max_arg != -1 && - instrs[instruction].max_arg < numa) - error("Too many arguments to efun.\n"); + if (instrs[instruction].min_arg != -1 && + instrs[instruction].min_arg > numa) + error("Too few arguments to efun.\n"); + if (instrs[instruction].max_arg != -1 && + instrs[instruction].max_arg < numa) + error("Too many arguments to efun.\n"); } else { - if (numa != instrs[instruction].min_arg) { - (void)fprintf(stderr, "call_efun %d numa=%d min_arg=%d\n", - instruction, numa, instrs[instruction].min_arg); - error("Bad number of arguments to efun.\n"); - } + if (numa != instrs[instruction].min_arg) { + (void)fprintf(stderr, "call_efun %d numa=%d min_arg=%d\n", + instruction, numa, instrs[instruction].min_arg); + error("Bad number of arguments to efun.\n"); + } } if (numa > 0) { - int type1 = (sp-numa+1)->type, type2 = (sp-numa+2)->type; - if (instrs[instruction].type[0] != 0 && - (instrs[instruction].type[0] & type1) == 0) { - bad_arg(1, instruction + EFUN_FIRST, sp-numa+1); - } - if (numa > 1) { - if (instrs[instruction].type[1] != 0 && - (instrs[instruction].type[1] & type2) == 0) - bad_arg(2, instruction + EFUN_FIRST, sp-numa+2); - } + int type1 = (sp-numa+1)->type, type2 = (sp-numa+2)->type; + if (instrs[instruction].type[0] != 0 && + (instrs[instruction].type[0] & type1) == 0) { + bad_arg(1, instruction + EFUN_FIRST, sp-numa+1); + } + if (numa > 1) { + if (instrs[instruction].type[1] != 0 && + (instrs[instruction].type[1] & type2) == 0) + bad_arg(2, instruction + EFUN_FIRST, sp-numa+2); + } } efun_table[instruction](numa); } diff --git a/interpret.h b/interpret.h index 9b91eb4..98f1539 100644 --- a/interpret.h +++ b/interpret.h @@ -11,10 +11,10 @@ #define push_svalue(val) \ { \ - if (sp + 1 >= &start_of_stack[EVALUATOR_STACK_SIZE]) \ - error("Stack overflow\n"); \ - sp++; \ - assign_svalue_no_free(sp, val); \ + if (sp + 1 >= &start_of_stack[EVALUATOR_STACK_SIZE]) \ + error("Stack overflow\n"); \ + sp++; \ + assign_svalue_no_free(sp, val); \ } union u { @@ -42,19 +42,19 @@ struct svalue { extern struct svalue *sp; extern struct svalue start_of_stack[]; -#define T_INVALID 0x0 -#define T_LVALUE 0x1 -#define T_NUMBER 0x2 -#define T_STRING 0x4 -#define T_POINTER 0x8 -#define T_OBJECT 0x10 -#define T_MAPPING 0x20 +#define T_INVALID 0x0 +#define T_LVALUE 0x1 +#define T_NUMBER 0x2 +#define T_STRING 0x4 +#define T_POINTER 0x8 +#define T_OBJECT 0x10 +#define T_MAPPING 0x20 #define T_FLOAT 0x40 -#define T_FUNCTION 0x80 +#define T_FUNCTION 0x80 -#define STRING_MSTRING 0 /* Allocated by malloc() */ -#define STRING_SSTRING 1 /* Allocated by the shared string library */ -#define STRING_CSTRING 2 /* Do not has to be freed at all */ +#define STRING_MSTRING 0 /* Allocated by malloc() */ +#define STRING_SSTRING 1 /* Allocated by the shared string library */ +#define STRING_CSTRING 2 /* Do not has to be freed at all */ struct vector { unsigned int size; @@ -67,7 +67,7 @@ struct vector { #define ALLOC_VECTOR(nelem) \ (struct vector *)xalloc(sizeof (struct vector) + \ - sizeof(struct svalue) * (nelem - 1)) + sizeof(struct svalue) * (nelem - 1)) /* * Function stuff. @@ -85,12 +85,12 @@ struct closure { #define FUN_SFUN 2 #define FUN_EFUN 3 #define FUN_LFUNO 4 -#define FUN_COMPOSE 5 /* used for compositions */ -#define FUN_EMPTY 6 /* used for empty argument slots */ +#define FUN_COMPOSE 5 /* used for compositions */ +#define FUN_EMPTY 6 /* used for empty argument slots */ #define FUN_LFUN_NOMASK 7 /* used for nomask functions */ unsigned short funno, funinh; /* function no, and inherit no. used in call */ - struct object *funobj; /* object where function is, or 0 */ - struct vector *funargs; /* function arguments, or 0 */ + struct object *funobj; /* object where function is, or 0 */ + struct vector *funargs; /* function arguments, or 0 */ /* "empty" argument slots in the argument array contain function nodes with the FUN_EMPTY tag */ }; @@ -102,15 +102,15 @@ struct closure { * The pointer, csp, will point to the values that will be used at return. */ struct control_stack { - struct object *ob; /* Current object */ - struct object *prev_ob; /* Save previous object */ - struct program *prog; /* Current program */ - int num_local_variables; /* Local + arguments */ + struct object *ob; /* Current object */ + struct object *prev_ob; /* Save previous object */ + struct program *prog; /* Current program */ + int num_local_variables; /* Local + arguments */ offset_t pc; offset_t pc_save; struct svalue *fp; - int extern_call; /* Flag if evaluator should return */ - struct function *funp; /* Only used for tracebacks */ + int extern_call; /* Flag if evaluator should return */ + struct function *funp; /* Only used for tracebacks */ int inh_offset; char ext_call; #if defined(PROFILE_LPC) @@ -130,21 +130,21 @@ struct control_stack { */ struct gdexception { struct gdexception *e_exception; - int e_catch; - jmp_buf e_context; + int e_catch; + jmp_buf e_context; }; /* * Boolean Type */ -typedef int bool_t; +typedef int bool_t; #ifndef FALSE -#define FALSE 0 +#define FALSE 0 #endif #ifndef TRUE -#define TRUE 1 +#define TRUE 1 #endif extern struct gdexception *exception; @@ -158,7 +158,7 @@ extern int function_index_found; extern struct program *function_prog_found; extern unsigned short function_type_mod_found; extern int function_inherit_found; -extern struct control_stack *csp; /* Points to last element pushed */ +extern struct control_stack *csp; /* Points to last element pushed */ #define INCREF(x) if (x) x++ #define DECREF(x) if (x) x-- diff --git a/json.h b/json.h index 7f54a5b..d4e4bc4 100644 --- a/json.h +++ b/json.h @@ -1,2 +1,2 @@ char * val2json(struct svalue *sp); -struct svalue *json2val(const char *cp); \ No newline at end of file +struct svalue *json2val(const char *cp); diff --git a/lex.c b/lex.c index 031d17a..1519263 100644 --- a/lex.c +++ b/lex.c @@ -132,54 +132,54 @@ calculate_include_path(char *name, char *dest) if ( (current = strrchr(dest, '/')) == NULL) /* strip filename */ { - /* current_file is in the root directory */ - current = dest; + /* current_file is in the root directory */ + current = dest; } *current = '\0'; while (*name == '/') { - name++; - current = dest; - *current = '\0'; /* absolute path */ + name++; + current = dest; + *current = '\0'; /* absolute path */ } while (*name) { - if (strncmp(name, "../", 3) == 0) - { - if (*dest == '\0') /* including from above mudlib is NOT allowed */ - break; - - /* Remove previous path element */ - while (current > dest) - { - *current-- = '\0'; - if (*current == '/') - break; - } - if (current == dest) - { - *current = '\0'; - } - - name += 3; /* skip "../" */ - } - else if (strncmp(name, "./", 2) == 0) - { - name += 2; - } - else - { /* append first component to dest */ - if (*dest) - *current++ = '/'; /* only if dest is not empty !! */ - while (*name != '\0' && *name != '/') - *current++ = *name++; - if (*name == '/') - name++; - else - *current = '\0'; /* Last element */ - } + if (strncmp(name, "../", 3) == 0) + { + if (*dest == '\0') /* including from above mudlib is NOT allowed */ + break; + + /* Remove previous path element */ + while (current > dest) + { + *current-- = '\0'; + if (*current == '/') + break; + } + if (current == dest) + { + *current = '\0'; + } + + name += 3; /* skip "../" */ + } + else if (strncmp(name, "./", 2) == 0) + { + name += 2; + } + else + { /* append first component to dest */ + if (*dest) + *current++ = '/'; /* only if dest is not empty !! */ + while (*name != '\0' && *name != '/') + *current++ = *name++; + if (*name == '/') + name++; + else + *current = '\0'; /* Last element */ + } } } @@ -219,7 +219,7 @@ gobble(int c) int d; d = mygetc(); if (c == d) - return 1; + return 1; *--outp = d; nbuf++; return 0; @@ -322,16 +322,16 @@ handle_cond(int c) /*(void)fprintf(stderr, "cond %d\n", c);*/ if (c || skip_to("else", "endif")) { - p = (struct ifstate *)xalloc(sizeof(struct ifstate)); - p->next = iftop; - iftop = p; - p->state = c ? EXPECT_ELSE : EXPECT_ENDIF; + p = (struct ifstate *)xalloc(sizeof(struct ifstate)); + p->next = iftop; + iftop = p; + p->state = c ? EXPECT_ELSE : EXPECT_ENDIF; } if (!c) { - store_line_number_info(current_incfile, current_line); - current_line++; - total_lines++; + store_line_number_info(current_incfile, current_line); + current_line++; + total_lines++; } } @@ -346,9 +346,9 @@ check_valid_compile_path(char *path, char *file_name, char *calling_function) while (*p) { - if (p[0] == '.' && p[1] == '.') - return NULL; - p++; + if (p[0] == '.' && p[1] == '.') + return NULL; + p++; } #if 0 push_string(path, STRING_MSTRING); @@ -356,7 +356,7 @@ check_valid_compile_path(char *path, char *file_name, char *calling_function) push_string(calling_function, STRING_MSTRING); ret = apply_master_ob(M_VALID_COMPILE_PATH, 3); if (ret) - path = tmpstring_copy(ret->u.string); + path = tmpstring_copy(ret->u.string); #endif return path; } @@ -376,23 +376,23 @@ inc_try(char *buf) new_name = check_valid_compile_path(buf, current_loaded_file, "include"); if (!new_name) { - lexerror("Invalid include."); - return NULL; + lexerror("Invalid include."); + return NULL; } if (new_name && (f = fopen(new_name, "r")) != NULL) { #ifdef WARN_INCLUDES - for (inc = inctop ; inc ; inc = inc->next) - if (strcmp(inc->file, new_name) == 0) - { - (void)snprintf(errbuf, sizeof(errbuf), "File /%s already included,", buf); - lexwarning(errbuf); - } + for (inc = inctop ; inc ; inc = inc->next) + if (strcmp(inc->file, new_name) == 0) + { + (void)snprintf(errbuf, sizeof(errbuf), "File /%s already included,", buf); + lexwarning(errbuf); + } #endif - if (s_flag) - num_fileread++; - remember_include(new_name); - return f; + if (s_flag) + num_fileread++; + remember_include(new_name); + return f; } return NULL; } @@ -406,21 +406,21 @@ inc_open(char *buf, size_t len, char *name) if (incdepth >= MAX_INCLUDE) { - lexerror("To deep recursion of includes."); - return NULL; + lexerror("To deep recursion of includes."); + return NULL; } (void)strcpy(buf, current_file); calculate_include_path(name, buf); if ((f = inc_try(buf)) != NULL) - return f; + return f; /* * Search all include dirs specified. */ for (i = 0; i < inc_list_size; i++) { (void)snprintf(buf, len, "%s%s", inc_list[i], name); - if ((f = inc_try(buf)) != NULL) - return f; + if ((f = inc_try(buf)) != NULL) + return f; } return NULL; } @@ -436,43 +436,43 @@ handle_include(char *name, int ignore_errors) if (*name != '"' && *name != '<') { - struct defn *d; - if ((d = lookup_define(name)) && d->nargs == -1) - { - char *q; - q = d->exps; - while (isspace(*q)) - q++; - return handle_include(q, ignore_errors); - } - else - { + struct defn *d; + if ((d = lookup_define(name)) && d->nargs == -1) + { + char *q; + q = d->exps; + while (isspace(*q)) + q++; + return handle_include(q, ignore_errors); + } + else + { if (!ignore_errors) - lexerror("Missing leading \" or < in #include"); + lexerror("Missing leading \" or < in #include"); return 0; - } + } } delim = *name++ == '"' ? '"' : '>'; for (p = name; *p && *p != delim; p++) - ; + ; if (!*p) { if (!ignore_errors) - lexerror("Missing trailing \" or > in #include"); - return 0; + lexerror("Missing trailing \" or > in #include"); + return 0; } if (strlen(name) > sizeof(buf) - 100) { if (!ignore_errors) - lexerror("Include name too long."); - return 0; + lexerror("Include name too long."); + return 0; } *p = 0; if ((f = inc_open(buf, sizeof(buf), name)) == NULL) { if (!ignore_errors) { - lexerror("Cannot #include %s\n", name); + lexerror("Cannot #include %s\n", name); } return 0; @@ -521,9 +521,9 @@ handle_exception(int action, char *message) (void)strcpy(buf, "\""); if (strlen(message) < 2) - (void)strcat(buf, "Unspecified condition"); + (void)strcat(buf, "Unspecified condition"); else - (void)strcat(buf, message); + (void)strcat(buf, message); (void)strcat(buf, "\""); push_number(action); @@ -533,7 +533,7 @@ handle_exception(int action, char *message) (void)apply_master_ob(M_PARSE_EXCEPTION, 4); if (action == ERROR) - lexerror("Parse aborted on #error statement,"); + lexerror("Parse aborted on #error statement,"); } static void @@ -543,31 +543,31 @@ skip_comment(void) for (;;) { - while ((c = mygetc()) != '*') - { - if (c == EOF) - { - lexerror("End of file in a comment"); - return; - } - if (c == '\n') - { - nexpands=0; - store_line_number_info(current_incfile, current_line); - current_line++; - } - } - do - { - if ((c = mygetc()) == '/') - return; - if (c == '\n') - { - nexpands=0; - store_line_number_info(current_incfile, current_line); - current_line++; - } - } while (c == '*'); + while ((c = mygetc()) != '*') + { + if (c == EOF) + { + lexerror("End of file in a comment"); + return; + } + if (c == '\n') + { + nexpands=0; + store_line_number_info(current_incfile, current_line); + current_line++; + } + } + do + { + if ((c = mygetc()) == '/') + return; + if (c == '\n') + { + nexpands=0; + store_line_number_info(current_incfile, current_line); + current_line++; + } + } while (c == '*'); } } @@ -577,10 +577,10 @@ skip_comment2(void) int c; while ((c = mygetc()) != '\n' && c != EOF) - ; + ; if (c == EOF) { - lexerror("End of file in a // comment"); - return; + lexerror("End of file in a // comment"); + return; } nexpands=0; store_line_number_info(current_incfile, current_line); @@ -595,13 +595,13 @@ deltrail(char *ap) char *p = ap; if (!*p) { - lexerror("Illegal # command"); + lexerror("Illegal # command"); } else { - while (*p && !isspace(*p)) - p++; - *p = 0; + while (*p && !isspace(*p)) + p++; + *p = 0; } } @@ -617,19 +617,19 @@ static void handle_pragma(char *str) { if (strcmp(str, "strict_types") == 0) - pragma_strict_types = 1; + pragma_strict_types = 1; else if (strcmp(str, "save_binary") == 0) - ; + ; else if (strcmp(str, "no_clone") == 0) - pragma_no_clone = 1; + pragma_no_clone = 1; else if (strcmp(str, "no_inherit") == 0) - pragma_no_inherit = 1; + pragma_no_inherit = 1; else if (strcmp(str, "no_shadow") == 0) - pragma_no_shadow = 1; + pragma_no_shadow = 1; else if (strcmp(str, "resident") == 0) - pragma_resident = 1; + pragma_resident = 1; else - handle_exception(WARNING, "Unknown pragma"); + handle_exception(WARNING, "Unknown pragma"); } static struct keyword { @@ -656,7 +656,7 @@ static struct keyword reswords[] = { { "else", F_ELSE, }, { "float", F_FLOAT, }, { "for", F_FOR, }, -{ "foreach", F_FOREACH, }, +{ "foreach", F_FOREACH, }, { "function", F_FUNCTION, }, { "if", F_IF, }, { "inherit", F_INHERIT, }, @@ -675,7 +675,7 @@ static struct keyword reswords[] = { { "status", F_STATUS, }, { "string", F_STRING_DECL, }, { "switch", F_SWITCH, }, -{ "throw", F_THROW }, +{ "throw", F_THROW }, { "try", F_TRY, }, { "varargs", F_VARARGS, }, { "void", F_VOID, }, @@ -692,16 +692,16 @@ lookupword(char *s, struct keyword *words, int h) l = 0; for (;;) { - i = (l + h) / 2; - r = strcmp(s, words[i].word); - if (r == 0) - return words[i].token; - else if (l == i) - return -1; - else if (r < 0) - h = i; - else - l = i; + i = (l + h) / 2; + r = strcmp(s, words[i].word); + if (r == 0) + return words[i].token; + else if (l == i) + return -1; + else if (r < 0) + h = i; + else + l = i; } } @@ -720,425 +720,425 @@ yylex1(void) for (;;) { - if (lex_fatal) - { - return -1; - } - switch(c = mygetc()) - { - case EOF: - if (inctop) - { - struct incstate *p; - p = inctop; - (void)fclose(yyin); - /*(void)fprintf(stderr, "popping to %s\n", p->file);*/ - free(current_file); - nexpands = 0; - current_file = p->file; - current_line = p->line + 1; - current_incfile = p->incfnum; - pragma_strict_types = p->pragma_strict_types; - yyin = p->yyin; - slast = p->slast; - lastchar = p->lastchar; - inctop = p->next; - - if (p->nbuf) - { - nbuf = p->nbuf; - outp = defbuf + DEFMAX - nbuf; - memcpy(outp, p->outp, nbuf); - free((char *)p->outp); - } - else - { - nbuf = 0; - outp = defbuf + DEFMAX; - } - - store_line_number_info(current_incfile, current_line); - incdepth--; - - free((char *)p); - break; - } - if (iftop) - { - struct ifstate *p = iftop; - lexerror(p->state == EXPECT_ENDIF ? "Missing #endif" : "Missing #else"); - while (iftop) - { - p = iftop; - iftop = p->next; - free((char *)p); - } - } - return -1; - case '\n': - { - nexpands=0; - store_line_number_info(current_incfile, current_line); - current_line++; - total_lines++; - } + if (lex_fatal) + { + return -1; + } + switch(c = mygetc()) + { + case EOF: + if (inctop) + { + struct incstate *p; + p = inctop; + (void)fclose(yyin); + /*(void)fprintf(stderr, "popping to %s\n", p->file);*/ + free(current_file); + nexpands = 0; + current_file = p->file; + current_line = p->line + 1; + current_incfile = p->incfnum; + pragma_strict_types = p->pragma_strict_types; + yyin = p->yyin; + slast = p->slast; + lastchar = p->lastchar; + inctop = p->next; + + if (p->nbuf) + { + nbuf = p->nbuf; + outp = defbuf + DEFMAX - nbuf; + memcpy(outp, p->outp, nbuf); + free((char *)p->outp); + } + else + { + nbuf = 0; + outp = defbuf + DEFMAX; + } + + store_line_number_info(current_incfile, current_line); + incdepth--; + + free((char *)p); + break; + } + if (iftop) + { + struct ifstate *p = iftop; + lexerror(p->state == EXPECT_ENDIF ? "Missing #endif" : "Missing #else"); + while (iftop) + { + p = iftop; + iftop = p->next; + free((char *)p); + } + } + return -1; + case '\n': + { + nexpands=0; + store_line_number_info(current_incfile, current_line); + current_line++; + total_lines++; + } /* FALLTHROUGH */ - case ' ': - case '\t': - case '\f': - case '\v': - break; - case '+': - TRY('+', F_INC); - TRY('=', F_ADD_EQ); - return c; - case '-': - TRY('>', F_ARROW); - TRY('-', F_DEC); - TRY('=', F_SUB_EQ); - return c; - case '&': - TRY('&', F_LAND); - TRY('=', F_AND_EQ); - return c; - case '|': - TRY('|', F_LOR); - TRY('=', F_OR_EQ); - return c; - case '^': - TRY('=', F_XOR_EQ); - return c; - case '<': - if (gobble('<')) { - TRY('=', F_LSH_EQ); - return F_LSH; - } - TRY('=', F_LE); - return c; - case '>': - if (gobble('>')) - { - TRY('=', F_RSH_EQ); - return F_RSH; - } - TRY('=', F_GE); - return c; - case '*': - TRY('=', F_MULT_EQ); - return c; - case '%': - TRY('=', F_MOD_EQ); - return F_MOD; - case '/': - if (gobble('*')) - { - skip_comment(); - break; - } - else if (gobble('/')) - { - skip_comment2(); - break; - } - TRY('=', F_DIV_EQ); - return c; - case '=': - TRY('=', F_EQ); - return c; - case ';': - case '(': - case ')': - case ',': - case '{': - case '}': - case '~': - case '[': - case ']': - case '?': - case '@': - return c; - case '!': - TRY('=', F_NE); - return F_NOT; - case ':': - TRY(':', F_COLON_COLON); - return ':'; - case '.': - if (gobble('.')) - { - if (gobble('.')) - return F_VARARG; - else - return F_RANGE; - } - return c; - case '#': - if (lastchar == '\n') - { - char *ssp = 0; - int quote; - - yyp = yytext; - do - { - c = mygetc(); - } while (isspace(c)); - - for (quote = 0;;) - { - if (c == '"') - quote ^= 1; - - /*gc - handle comments cpp-like! 1.6.91 @@@*/ - while (!quote && c == '/') - { - if (gobble('*')) - { - skip_comment(); - c = mygetc(); - } - else - break; - } - - if (!ssp && isspace(c)) - ssp = yyp; - if (c == '\n' || c == EOF) - break; - SAVEC; - c = mygetc(); - } - if (ssp) - { - *ssp++ = 0; - while (isspace(*ssp)) - ssp++; - } - else - { - ssp = yyp; - } - *yyp = 0; - if (strcmp("define", yytext) == 0) - { - handle_define(ssp); - } - else if (strcmp("if", yytext) == 0) - { + case ' ': + case '\t': + case '\f': + case '\v': + break; + case '+': + TRY('+', F_INC); + TRY('=', F_ADD_EQ); + return c; + case '-': + TRY('>', F_ARROW); + TRY('-', F_DEC); + TRY('=', F_SUB_EQ); + return c; + case '&': + TRY('&', F_LAND); + TRY('=', F_AND_EQ); + return c; + case '|': + TRY('|', F_LOR); + TRY('=', F_OR_EQ); + return c; + case '^': + TRY('=', F_XOR_EQ); + return c; + case '<': + if (gobble('<')) { + TRY('=', F_LSH_EQ); + return F_LSH; + } + TRY('=', F_LE); + return c; + case '>': + if (gobble('>')) + { + TRY('=', F_RSH_EQ); + return F_RSH; + } + TRY('=', F_GE); + return c; + case '*': + TRY('=', F_MULT_EQ); + return c; + case '%': + TRY('=', F_MOD_EQ); + return F_MOD; + case '/': + if (gobble('*')) + { + skip_comment(); + break; + } + else if (gobble('/')) + { + skip_comment2(); + break; + } + TRY('=', F_DIV_EQ); + return c; + case '=': + TRY('=', F_EQ); + return c; + case ';': + case '(': + case ')': + case ',': + case '{': + case '}': + case '~': + case '[': + case ']': + case '?': + case '@': + return c; + case '!': + TRY('=', F_NE); + return F_NOT; + case ':': + TRY(':', F_COLON_COLON); + return ':'; + case '.': + if (gobble('.')) + { + if (gobble('.')) + return F_VARARG; + else + return F_RANGE; + } + return c; + case '#': + if (lastchar == '\n') + { + char *ssp = 0; + int quote; + + yyp = yytext; + do + { + c = mygetc(); + } while (isspace(c)); + + for (quote = 0;;) + { + if (c == '"') + quote ^= 1; + + /*gc - handle comments cpp-like! 1.6.91 @@@*/ + while (!quote && c == '/') + { + if (gobble('*')) + { + skip_comment(); + c = mygetc(); + } + else + break; + } + + if (!ssp && isspace(c)) + ssp = yyp; + if (c == '\n' || c == EOF) + break; + SAVEC; + c = mygetc(); + } + if (ssp) + { + *ssp++ = 0; + while (isspace(*ssp)) + ssp++; + } + else + { + ssp = yyp; + } + *yyp = 0; + if (strcmp("define", yytext) == 0) + { + handle_define(ssp); + } + else if (strcmp("if", yytext) == 0) + { #if 0 - short int nega=0; /*@@@ allow #if !VAR gc 1.6.91*/ - if (*ssp=='!'){ ssp++; nega=1;} - if (isdigit(*ssp)) - { - char *p; - long l; - l = strtol(ssp, &p, 10); - while (isspace(*p)) - p++; - if (*p) - lexerror("Condition too complex in #if"); - else - handle_cond(nega ? !(int)l : (int)l); - } - else if (isalunum(*ssp)) - { - char *p = ssp; - while (isalunum(*p)) - p++; - if (*p) - { - *p++ = 0; - while (isspace(*p)) - p++; - } - if (*p) - lexerror("Condition too complex in #if"); - else - { - struct defn *d; - d = lookup_define(ssp); - if (d) - { - handle_cond(nega ? !atoi(d->exps) : atoi(d->exps));/* a hack! */ - } - else - { - handle_cond(nega?1:0); /* cpp-like gc*/ - } - } - } - else - lexerror("Condition too complex in #if"); + short int nega=0; /*@@@ allow #if !VAR gc 1.6.91*/ + if (*ssp=='!'){ ssp++; nega=1;} + if (isdigit(*ssp)) + { + char *p; + long l; + l = strtol(ssp, &p, 10); + while (isspace(*p)) + p++; + if (*p) + lexerror("Condition too complex in #if"); + else + handle_cond(nega ? !(int)l : (int)l); + } + else if (isalunum(*ssp)) + { + char *p = ssp; + while (isalunum(*p)) + p++; + if (*p) + { + *p++ = 0; + while (isspace(*p)) + p++; + } + if (*p) + lexerror("Condition too complex in #if"); + else + { + struct defn *d; + d = lookup_define(ssp); + if (d) + { + handle_cond(nega ? !atoi(d->exps) : atoi(d->exps));/* a hack! */ + } + else + { + handle_cond(nega?1:0); /* cpp-like gc*/ + } + } + } + else + lexerror("Condition too complex in #if"); #else - int cond; - - myungetc(0); - add_input(ssp); - cond = cond_get_exp(0); - if (mygetc()) - { - lexerror("Condition too complex in #if"); - while (mygetc()) - ; - } - else - handle_cond(cond); + int cond; + + myungetc(0); + add_input(ssp); + cond = cond_get_exp(0); + if (mygetc()) + { + lexerror("Condition too complex in #if"); + while (mygetc()) + ; + } + else + handle_cond(cond); #endif - } - else if (strcmp("ifdef", yytext) == 0) - { - deltrail(ssp); - handle_cond(lookup_define(ssp) != 0); - } - else if (strcmp("ifndef", yytext) == 0) - { - deltrail(ssp); - handle_cond(lookup_define(ssp) == 0); - } - else if (strcmp("else", yytext) == 0) - { - if (iftop && iftop->state == EXPECT_ELSE) - { - struct ifstate *p = iftop; - - /*(void)fprintf(stderr, "found else\n");*/ - iftop = p->next; - free((char *)p); - (void)skip_to("endif", (char *)0); - store_line_number_info(current_incfile, current_line); - current_line++; - total_lines++; - } - else - { - lexerror("Unexpected #else"); - } - } - else if (strcmp("endif", yytext) == 0) - { - if (iftop && (iftop->state == EXPECT_ENDIF || - iftop->state == EXPECT_ELSE)) - { - struct ifstate *p = iftop; - - /*(void)fprintf(stderr, "found endif\n");*/ - iftop = p->next; - free((char *)p); - } - else - { - lexerror("Unexpected #endif"); - } - } - else if (strcmp("undef", yytext) == 0) - { - struct defn *d; - - deltrail(ssp); - if ((d = lookup_define(ssp)) != NULL ) - d->undef++; - } - else if (strcmp("echo", yytext) == 0) - { - (void)fprintf(stderr, "%s\n", ssp); - } - else if (strcmp("include", yytext) == 0) - { - /*(void)fprintf(stderr, "including %s\n", ssp); */ - handle_include(ssp, 0); - } - else if (strcmp("pragma", yytext) == 0) - { - deltrail(ssp); - handle_pragma(ssp); - } - else if (strcmp("error", yytext) == 0) - { - handle_exception(ERROR, ssp); - } - else if (strcmp("warning", yytext) == 0) - { - handle_exception(WARNING, ssp); - } - else - { - lexerror("Unrecognised # directive"); - } - myungetc('\n'); - break; - } - else - goto badlex; - case '\'': - yylval.number = mygetc(); - if (yylval.number == '\\') - { - int tmp = mygetc(); - switch (tmp) - { - case 'n': yylval.number = '\n'; break; - case 't': yylval.number = '\t'; break; - case 'b': yylval.number = '\b'; break; - case 'a': yylval.number = '\a'; break; - case 'v': yylval.number = '\v'; break; - case '\'': - case '\\': - case '"': - yylval.number = tmp; break; - default: - lexwarning("Bad character escape sequence"); - yylval.number = tmp; - break; - } - } - if (!gobble('\'')) - lexerror("Illegal character constant"); - return F_NUMBER; - case '"': - yyp = yytext; - *yyp++ = c; - for (;;) - { - c = mygetc(); - if (c == EOF) - { - lexerror("End of file in string"); - return string("\"\""); - } - else if (c == '\n') - { - lexerror("Newline in string"); - return string("\"\""); - } - SAVEC; - if (c == '"') - break; - if (c == '\\') - { - c = mygetc(); - if ( c == '\n' ) - { - yyp--; - store_line_number_info(current_incfile, current_line); - current_line++; - total_lines++; - } - else if ( c == EOF ) - { - /* some operating systems give EOF only once */ - myungetc(c); - } - else - *yyp++ = c; - } - } - *yyp = 0; - return string(yytext); - - case '0': - c = mygetc(); - if ( c == 'X' || c == 'x' || c == 'o') - { + } + else if (strcmp("ifdef", yytext) == 0) + { + deltrail(ssp); + handle_cond(lookup_define(ssp) != 0); + } + else if (strcmp("ifndef", yytext) == 0) + { + deltrail(ssp); + handle_cond(lookup_define(ssp) == 0); + } + else if (strcmp("else", yytext) == 0) + { + if (iftop && iftop->state == EXPECT_ELSE) + { + struct ifstate *p = iftop; + + /*(void)fprintf(stderr, "found else\n");*/ + iftop = p->next; + free((char *)p); + (void)skip_to("endif", (char *)0); + store_line_number_info(current_incfile, current_line); + current_line++; + total_lines++; + } + else + { + lexerror("Unexpected #else"); + } + } + else if (strcmp("endif", yytext) == 0) + { + if (iftop && (iftop->state == EXPECT_ENDIF || + iftop->state == EXPECT_ELSE)) + { + struct ifstate *p = iftop; + + /*(void)fprintf(stderr, "found endif\n");*/ + iftop = p->next; + free((char *)p); + } + else + { + lexerror("Unexpected #endif"); + } + } + else if (strcmp("undef", yytext) == 0) + { + struct defn *d; + + deltrail(ssp); + if ((d = lookup_define(ssp)) != NULL ) + d->undef++; + } + else if (strcmp("echo", yytext) == 0) + { + (void)fprintf(stderr, "%s\n", ssp); + } + else if (strcmp("include", yytext) == 0) + { + /*(void)fprintf(stderr, "including %s\n", ssp); */ + handle_include(ssp, 0); + } + else if (strcmp("pragma", yytext) == 0) + { + deltrail(ssp); + handle_pragma(ssp); + } + else if (strcmp("error", yytext) == 0) + { + handle_exception(ERROR, ssp); + } + else if (strcmp("warning", yytext) == 0) + { + handle_exception(WARNING, ssp); + } + else + { + lexerror("Unrecognised # directive"); + } + myungetc('\n'); + break; + } + else + goto badlex; + case '\'': + yylval.number = mygetc(); + if (yylval.number == '\\') + { + int tmp = mygetc(); + switch (tmp) + { + case 'n': yylval.number = '\n'; break; + case 't': yylval.number = '\t'; break; + case 'b': yylval.number = '\b'; break; + case 'a': yylval.number = '\a'; break; + case 'v': yylval.number = '\v'; break; + case '\'': + case '\\': + case '"': + yylval.number = tmp; break; + default: + lexwarning("Bad character escape sequence"); + yylval.number = tmp; + break; + } + } + if (!gobble('\'')) + lexerror("Illegal character constant"); + return F_NUMBER; + case '"': + yyp = yytext; + *yyp++ = c; + for (;;) + { + c = mygetc(); + if (c == EOF) + { + lexerror("End of file in string"); + return string("\"\""); + } + else if (c == '\n') + { + lexerror("Newline in string"); + return string("\"\""); + } + SAVEC; + if (c == '"') + break; + if (c == '\\') + { + c = mygetc(); + if ( c == '\n' ) + { + yyp--; + store_line_number_info(current_incfile, current_line); + current_line++; + total_lines++; + } + else if ( c == EOF ) + { + /* some operating systems give EOF only once */ + myungetc(c); + } + else + *yyp++ = c; + } + } + *yyp = 0; + return string(yytext); + + case '0': + c = mygetc(); + if ( c == 'X' || c == 'x' || c == 'o') + { char *endptr; long long value; int base = 16; @@ -1146,16 +1146,16 @@ yylex1(void) base = 8; - yyp = yytext; + yyp = yytext; - for (;;) - { - c = mygetc(); - if (!isxdigit(c)) - break; + for (;;) + { + c = mygetc(); + if (!isxdigit(c)) + break; SAVEC; - } - myungetc(c); + } + myungetc(c); *yyp = '\0'; value = strtoll(yytext, &endptr, base); @@ -1166,79 +1166,79 @@ yylex1(void) } return number(value); - } - myungetc(c); - c = '0'; - /* FALLTHROUGH */ - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - yyp = yytext; - *yyp++ = c; - for (;;) - { - c = mygetc(); - if (!isdigit(c)) - break; - SAVEC; - } - if (c == '.') - { - if (isdigit(c1 = mygetc())) - { - SAVEC; - c = c1; - SAVEC; - for (c = mygetc(); isdigit(c); c = mygetc()) - SAVEC; - if (c == 'e' || c == 'E') - { - c1 = mygetc(); - if (c1 == '-' || c1 == '+') - { - c2 = mygetc(); - if (isdigit(c2)) - { - SAVEC; - c = c1; - SAVEC; - c = c2; - SAVEC; - for (c = mygetc(); isdigit(c); c = mygetc()) - SAVEC; - } - else - { - myungetc(c2); - myungetc(c1); - } - } - else if (isdigit(c1)) - { - SAVEC; - c = c1; - SAVEC; - for (c = mygetc(); isdigit(c); c = mygetc()) - SAVEC; - } - else - myungetc(c1); - } - myungetc(c); - *yyp = 0; - return real(strtod(yytext, NULL)); - } - myungetc(c1); - } - myungetc(c); - *yyp = 0; - if (*yytext == '0') + } + myungetc(c); + c = '0'; + /* FALLTHROUGH */ + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + yyp = yytext; + *yyp++ = c; + for (;;) + { + c = mygetc(); + if (!isdigit(c)) + break; + SAVEC; + } + if (c == '.') + { + if (isdigit(c1 = mygetc())) + { + SAVEC; + c = c1; + SAVEC; + for (c = mygetc(); isdigit(c); c = mygetc()) + SAVEC; + if (c == 'e' || c == 'E') + { + c1 = mygetc(); + if (c1 == '-' || c1 == '+') + { + c2 = mygetc(); + if (isdigit(c2)) + { + SAVEC; + c = c1; + SAVEC; + c = c2; + SAVEC; + for (c = mygetc(); isdigit(c); c = mygetc()) + SAVEC; + } + else + { + myungetc(c2); + myungetc(c1); + } + } + else if (isdigit(c1)) + { + SAVEC; + c = c1; + SAVEC; + for (c = mygetc(); isdigit(c); c = mygetc()) + SAVEC; + } + else + myungetc(c1); + } + myungetc(c); + *yyp = 0; + return real(strtod(yytext, NULL)); + } + myungetc(c1); + } + myungetc(c); + *yyp = 0; + if (*yytext == '0') { /* OCTALS */ char *endptr; @@ -1252,43 +1252,43 @@ yylex1(void) if (value != 0) lexwarning("Obsolete octal format used. Use 0o111 syntax"); - return number(value); + return number(value); + } + return number(atoll(yytext)); + default: + if (isalpha(c) || c == '_') { + int r; + + yyp = yytext; + *yyp++ = c; + for (;;) + { + c = mygetc(); + if (!isalunum(c)) + break; + SAVEC; + } + *yyp = 0; + + myungetc(c); + if (!expand_define()) + { + r = lookup_resword(yytext); + if (r >= 0) + { + return r; + } + else + return ident(yytext); + } + break; } - return number(atoll(yytext)); - default: - if (isalpha(c) || c == '_') { - int r; - - yyp = yytext; - *yyp++ = c; - for (;;) - { - c = mygetc(); - if (!isalunum(c)) - break; - SAVEC; - } - *yyp = 0; - - myungetc(c); - if (!expand_define()) - { - r = lookup_resword(yytext); - if (r >= 0) - { - return r; - } - else - return ident(yytext); - } - break; - } - goto badlex; - } + goto badlex; + } } badlex: { - lexerror("Illegal character (hex %02x) '%c'", c, c); + lexerror("Illegal character (hex %02x) '%c'", c, c); return ' '; } } @@ -1300,16 +1300,16 @@ yylex(void) if (keep1.token != -47) { - /* - * something in keep buffer. shift it out. - */ - r = keep1.token; - current_line = keep1.line; - yylval = keep1.lval; - keep1 = keep2; - keep2 = keep3; - keep3.token = -47; - return r; + /* + * something in keep buffer. shift it out. + */ + r = keep1.token; + current_line = keep1.line; + yylval = keep1.lval; + keep1 = keep2; + keep2 = keep3; + keep3.token = -47; + return r; } yytext[0] = 0; /* @@ -1317,68 +1317,68 @@ yylex(void) */ if ((r = yylex1()) == F_STRING) { - keep4.lval = yylval; - keep4.line = current_line; - yytext[0] = 0; - r = yylex1(); - for (;;) - { - keep1.line = current_line; - keep1.lval = yylval; - if (r != '+') - { - /* - * 1:string 2:non-'+' - * save 2, return 1 - */ - keep1.token = r; - yylval = keep4.lval; - current_line = keep4.line; - return F_STRING; - } - yytext[0] = 0; - r = yylex1(); - keep2.line = current_line; - keep2.lval = yylval; - if (r != F_STRING) - { - /* - * 1:string 2:'+' 3:non-string - * save 2 and 3, return 1 - */ - keep1.token = '+'; - keep2.token = r; - current_line = keep4.line; - yylval = keep4.lval; - return F_STRING; - } - yytext[0] = 0; - r = yylex1(); - keep3.line = current_line; - keep3.lval = yylval; - if (r == '[' || r == F_ARROW) - { - /* - * 1:string 2:'+' 3:string 4:[-> - * save 2, 3, 4, return 1 - */ - keep1.token = '+'; - keep2.token = F_STRING; - keep3.token = r; - current_line = keep4.line; - yylval = keep4.lval; - return F_STRING; - } - /* - * concatenate string constants - */ - keep3.lval.string = pool_alloc(&lex_allocations, strlen(keep4.lval.string) + - strlen(keep2.lval.string) + 1); - (void)strcpy(keep3.lval.string, keep4.lval.string); - (void)strcat(keep3.lval.string, keep2.lval.string); - keep4.line = keep2.line; - keep4.lval.string = keep3.lval.string; - } + keep4.lval = yylval; + keep4.line = current_line; + yytext[0] = 0; + r = yylex1(); + for (;;) + { + keep1.line = current_line; + keep1.lval = yylval; + if (r != '+') + { + /* + * 1:string 2:non-'+' + * save 2, return 1 + */ + keep1.token = r; + yylval = keep4.lval; + current_line = keep4.line; + return F_STRING; + } + yytext[0] = 0; + r = yylex1(); + keep2.line = current_line; + keep2.lval = yylval; + if (r != F_STRING) + { + /* + * 1:string 2:'+' 3:non-string + * save 2 and 3, return 1 + */ + keep1.token = '+'; + keep2.token = r; + current_line = keep4.line; + yylval = keep4.lval; + return F_STRING; + } + yytext[0] = 0; + r = yylex1(); + keep3.line = current_line; + keep3.lval = yylval; + if (r == '[' || r == F_ARROW) + { + /* + * 1:string 2:'+' 3:string 4:[-> + * save 2, 3, 4, return 1 + */ + keep1.token = '+'; + keep2.token = F_STRING; + keep3.token = r; + current_line = keep4.line; + yylval = keep4.lval; + return F_STRING; + } + /* + * concatenate string constants + */ + keep3.lval.string = pool_alloc(&lex_allocations, strlen(keep4.lval.string) + + strlen(keep2.lval.string) + 1); + (void)strcpy(keep3.lval.string, keep4.lval.string); + (void)strcat(keep3.lval.string, keep2.lval.string); + keep4.line = keep2.line; + keep4.lval.string = keep3.lval.string; + } } /* (void)fprintf(stderr, "lex=%d(%s) ", r, yytext);*/ return r; @@ -1400,36 +1400,36 @@ string(const char *str) { if (!*str) { - str = "\"\""; + str = "\"\""; } char *p = pool_alloc(&lex_allocations, strlen(str) + 1); yylval.string = p; for (str++; str[0] && str[1] ; str++, p++) { - /* Copy the similar one to here /JH */ - if (str[0] == '\\') { - if (str[1] == 'n') { - *p = '\n'; - } else if (str[1] == 't') { - *p = '\t'; - } else if (str[1] == 'r') { - *p = '\r'; - } else if (str[1] == 'b') { - *p = '\b'; - } else if (str[1] == 'a') { - *p = '\a'; - } else if (str[1] == 'v') { - *p = '\v'; - } else if (str[1] == '"' || str[1] == '\\' || str[1] == '\'') { - *p = str[1]; - } else { - lexwarning("Bad string escape sequence."); - *p = str[1]; - } - str++; - } else - *p = *str; + /* Copy the similar one to here /JH */ + if (str[0] == '\\') { + if (str[1] == 'n') { + *p = '\n'; + } else if (str[1] == 't') { + *p = '\t'; + } else if (str[1] == 'r') { + *p = '\r'; + } else if (str[1] == 'b') { + *p = '\b'; + } else if (str[1] == 'a') { + *p = '\a'; + } else if (str[1] == 'v') { + *p = '\v'; + } else if (str[1] == '"' || str[1] == '\\' || str[1] == '\'') { + *p = str[1]; + } else { + lexwarning("Bad string escape sequence."); + *p = str[1]; + } + str++; + } else + *p = *str; } *p = '\0'; return F_STRING; @@ -1454,28 +1454,28 @@ end_new_file(void) { while (inctop) { - struct incstate *p; - p = inctop; - (void)fclose(yyin); - free(current_file); - current_file = p->file; - yyin = p->yyin; - inctop = p->next; - - if (p->outp != NULL) - { - free((char *)p->outp); - } - - free((char *)p); + struct incstate *p; + p = inctop; + (void)fclose(yyin); + free(current_file); + current_file = p->file; + yyin = p->yyin; + inctop = p->next; + + if (p->outp != NULL) + { + free((char *)p->outp); + } + + free((char *)p); } while (iftop) { - struct ifstate *p; + struct ifstate *p; - p = iftop; - iftop = p->next; - free((char *)p); + p = iftop; + iftop = p->next; + free((char *)p); } free_defines(); pool_free(&lex_allocations); @@ -1517,16 +1517,16 @@ start_new_file(FILE *f) for (tmpf = lpc_predefs; tmpf; tmpf = tmpf->next) { - char namebuf[NSIZE]; - char mtext[MLEN]; - - *mtext='\0'; - (void)sscanf(tmpf->flag, "%[^=]=%[ -~=]", namebuf, mtext); - if (strlen(namebuf) >= NSIZE) - fatal("NSIZE exceeded\n"); - if (strlen(mtext) >= MLEN) - fatal("MLEN exceeded\n"); - add_define(namebuf,-1,mtext); + char namebuf[NSIZE]; + char mtext[MLEN]; + + *mtext='\0'; + (void)sscanf(tmpf->flag, "%[^=]=%[ -~=]", namebuf, mtext); + if (strlen(namebuf) >= NSIZE) + fatal("NSIZE exceeded\n"); + if (strlen(mtext) >= MLEN) + fatal("MLEN exceeded\n"); + add_define(namebuf,-1,mtext); } keep1.token = keep2.token = keep3.token = -47; yyin = f; @@ -1597,17 +1597,17 @@ init_num_args(void) for (i = 0; i NELEM(instrs)) - fatal("Token %s has illegal value %d.\n", predefs[i].word, n); - instrs[n].min_arg = predefs[i].min_args; - instrs[n].max_arg = predefs[i].max_args; - instrs[n].name = predefs[i].word; - instrs[n].type[0] = predefs[i].arg_type1; - instrs[n].type[1] = predefs[i].arg_type2; - instrs[n].Default = predefs[i].Default; - instrs[n].ret_type = predefs[i].ret_type; - instrs[n].arg_index = predefs[i].arg_index; + n = predefs[i].token - EFUN_FIRST; + if (n < 0 || n > NELEM(instrs)) + fatal("Token %s has illegal value %d.\n", predefs[i].word, n); + instrs[n].min_arg = predefs[i].min_args; + instrs[n].max_arg = predefs[i].max_args; + instrs[n].name = predefs[i].word; + instrs[n].type[0] = predefs[i].arg_type1; + instrs[n].type[1] = predefs[i].arg_type2; + instrs[n].Default = predefs[i].Default; + instrs[n].ret_type = predefs[i].ret_type; + instrs[n].arg_index = predefs[i].arg_index; } add_instr_opname("+", F_ADD, TYPE_ANY, T_ANY, T_ANY); add_instr_opname("-", F_SUBTRACT, TYPE_ANY, T_ANY, T_ANY); @@ -1689,12 +1689,12 @@ char * get_f_name(int n) { if (instrs[n-EFUN_FIRST].name) - return instrs[n-EFUN_FIRST].name; + return instrs[n-EFUN_FIRST].name; else { - static char buf[30]; - (void)snprintf(buf, sizeof(buf), "", n); - return buf; + static char buf[30]; + (void)snprintf(buf, sizeof(buf), "", n); + return buf; } } @@ -1728,15 +1728,15 @@ cmygetc(void) for (;;) { - c = mygetc(); - if (c == '/') - { - if (gobble('*')) - skip_comment(); - else - return c; - } else - return c; + c = mygetc(); + if (c == '/') + { + if (gobble('*')) + skip_comment(); + else + return c; + } else + return c; } } @@ -1749,14 +1749,14 @@ refill(void) p = yytext; do { - c = cmygetc(); - if (p < yytext+MAXLINE-5) - *p++ = c; - else - { - lexerror("Line too long"); - break; - } + c = cmygetc(); + if (p < yytext+MAXLINE-5) + *p++ = c; + else + { + lexerror("Line too long"); + break; + } } while (c != '\n' && c != EOF); p[-1] = ' '; *p = 0; @@ -1779,113 +1779,113 @@ handle_define(char *yyt) GETALPHA(p, q, namebuf+NSIZE-1); if (*p == '(') { /* if "function macro" */ - int arg; - int inid; - char *ids = 0; - p++; /* skip '(' */ - SKIPWHITE; - if (*p == ')') - { - arg = 0; - } - else - { - for (arg = 0; arg < NARGS; ) - { - q = args[arg]; - GETALPHA(p, q, args[arg] + NSIZE - 1); - arg++; - SKIPWHITE; - if (*p == ')') - break; - if (*p++ != ',') - { - lexerror("Missing ',' in #define parameter list"); - return; - } - SKIPWHITE; - } - if (arg == NARGS) - { - lexerror("Too many macro arguments"); - return; - } - } - p++; /* skip ')' */ - for (inid = 0, q = mtext; *p; ) - { - if (isalunum(*p)) - { - if (!inid) - { - inid++; - ids = p; - } - } - else - { - if (inid) - { - size_t l, idlen = p - ids; - int n; - - for (n = 0; n < arg; n++) - { - l = strlen(args[n]); - if (l == idlen && strncmp(args[n], ids, l) == 0) - { - q -= idlen; - *q++ = MARKS; - *q++ = n+MARKS+1; - break; - } - } - inid = 0; - } - } - *q = *p; - if (*p++ == MARKS) - *++q = MARKS; - if (q < mtext + MLEN - 2) - q++; - else - { - lexerror("Macro text too long"); - return; - } - if (!*p && strlen(yytext) >= 2 && p[-2] == '\\') - { - q -= 2; - refill(); - p = yytext; - } - } - - *--q = 0; - add_define(namebuf, arg, mtext); + int arg; + int inid; + char *ids = 0; + p++; /* skip '(' */ + SKIPWHITE; + if (*p == ')') + { + arg = 0; + } + else + { + for (arg = 0; arg < NARGS; ) + { + q = args[arg]; + GETALPHA(p, q, args[arg] + NSIZE - 1); + arg++; + SKIPWHITE; + if (*p == ')') + break; + if (*p++ != ',') + { + lexerror("Missing ',' in #define parameter list"); + return; + } + SKIPWHITE; + } + if (arg == NARGS) + { + lexerror("Too many macro arguments"); + return; + } + } + p++; /* skip ')' */ + for (inid = 0, q = mtext; *p; ) + { + if (isalunum(*p)) + { + if (!inid) + { + inid++; + ids = p; + } + } + else + { + if (inid) + { + size_t l, idlen = p - ids; + int n; + + for (n = 0; n < arg; n++) + { + l = strlen(args[n]); + if (l == idlen && strncmp(args[n], ids, l) == 0) + { + q -= idlen; + *q++ = MARKS; + *q++ = n+MARKS+1; + break; + } + } + inid = 0; + } + } + *q = *p; + if (*p++ == MARKS) + *++q = MARKS; + if (q < mtext + MLEN - 2) + q++; + else + { + lexerror("Macro text too long"); + return; + } + if (!*p && strlen(yytext) >= 2 && p[-2] == '\\') + { + q -= 2; + refill(); + p = yytext; + } + } + + *--q = 0; + add_define(namebuf, arg, mtext); } else { - for (q = mtext; *p; ) - { - *q = *p++; - if (q < mtext + MLEN - 2) - q++; - else - { - lexerror("Macro text too long"); - return; - } - if (!*p && strlen(yytext) >= 2 && p[-2] == '\\') - { - q -= 2; - refill(); - p = yytext; - } - } - - *--q = 0; - add_define(namebuf, -1, mtext); + for (q = mtext; *p; ) + { + *q = *p++; + if (q < mtext + MLEN - 2) + q++; + else + { + lexerror("Macro text too long"); + return; + } + if (!*p && strlen(yytext) >= 2 && p[-2] == '\\') + { + q -= 2; + refill(); + p = yytext; + } + } + + *--q = 0; + add_define(namebuf, -1, mtext); } return; } @@ -1904,8 +1904,8 @@ add_input(char *p) if (nbuf+l >= DEFMAX-10) { - lexerror("Macro expansion buffer overflow"); - return; + lexerror("Macro expansion buffer overflow"); + return; } outp -= l; nbuf += l; @@ -1936,11 +1936,11 @@ add_define(char *name, int nargs, char *exps) if ((p = lookup_define(name)) != NULL) { - if (nargs != p->nargs || strcmp(exps, p->exps) != 0) - { - lexerror("Redefinition of #define %s", name); - } - return; + if (nargs != p->nargs || strcmp(exps, p->exps) != 0) + { + lexerror("Redefinition of #define %s", name); + } + return; } p = (struct defn *)xalloc(sizeof(struct defn)); p->name = xalloc(strlen(name)+1); @@ -1963,14 +1963,14 @@ free_defines(void) for (i = 0; i < DEFHASH; i++) { - for (p = defns[i]; p; p = q) - { - q = p->next; - free(p->name); - free(p->exps); - free((char *)p); - } - defns[i] = 0; + for (p = defns[i]; p; p = q) + { + q = p->next; + free(p->name); + free(p->exps); + free((char *)p); + } + defns[i] = 0; } nexpands = 0; } @@ -1983,8 +1983,8 @@ lookup_define(char *s) h = defhash(s); for (p = defns[h]; p; p = p->next) - if (!p->undef && strcmp(s, p->name) == 0) - return p; + if (!p->undef && strcmp(s, p->name) == 0) + return p; return 0; } @@ -2006,147 +2006,147 @@ expand_define(void) if (nexpands++ > EXPANDMAX) { - lexerror("Too many macro expansions"); - return 0; + lexerror("Too many macro expansions"); + return 0; } p = lookup_define(yytext); if (!p) { - return 0; + return 0; } if (p->nargs == -1) { - add_input(p->exps); + add_input(p->exps); } else { - int c, parcnt = 0, dquote = 0, squote = 0; - int n; - SKIPW; - if (c != '(') - { - lexerror("Missing '(' in macro call"); - return 0; - } - SKIPW; - if (c == ')') - n = 0; - else - { - q = expbuf; - args[0] = q; - for (n = 0; n < NARGS; ) - { - switch(c) - { - case '"': - if (!squote) - dquote ^= 1; - break; - case '\'': - if (!dquote) - squote ^= 1; - break; - case '(': - if (!squote && !dquote) - parcnt++; - break; - case ')': - if (!squote && !dquote) - parcnt--; - break; - case '\\': - if (squote || dquote) - { - *q++ = c; - c = mygetc();} - break; - case '\n': - if (squote || dquote) - { - lexerror("Newline in string"); - return 0; - } - break; - } - if (c == ',' && !parcnt && !dquote && !squote) - { - *q++ = 0; - args[++n] = q; - } - else if (parcnt < 0) - { - *q++ = 0; - n++; - break; - } - else - { - if (c == EOF) - { - lexerror("Unexpected end of file"); - return 0; - } - if (q >= expbuf + DEFMAX - 5) - { - lexerror("Macro argument overflow"); - return 0; - } - else - { - *q++ = c; - } - } - if (!squote && ! dquote) - c = cmygetc(); - else - c = mygetc(); - } - if (n == NARGS) - { - lexerror("Maximum macro argument count exceeded"); - return 0; - } - } - if (n != p->nargs) - { - lexerror("Wrong number of macro arguments"); - return 0; - } - /* Do expansion */ - b = buf; - e = p->exps; - while (*e) - { - if (*e == MARKS) - { - if (*++e == MARKS) - *b++ = *e++; - else - { - for (q = args[*e++ - MARKS - 1]; *q; ) - { - *b++ = *q++; - if (b >= buf+DEFMAX) - { - lexerror("Macro expansion overflow"); - return 0; - } - } - } - } - else - { - *b++ = *e++; - if (b >= buf+DEFMAX) - { - lexerror("Macro expansion overflow"); - return 0; - } - } - } - *b++ = 0; - add_input(buf); + int c, parcnt = 0, dquote = 0, squote = 0; + int n; + SKIPW; + if (c != '(') + { + lexerror("Missing '(' in macro call"); + return 0; + } + SKIPW; + if (c == ')') + n = 0; + else + { + q = expbuf; + args[0] = q; + for (n = 0; n < NARGS; ) + { + switch(c) + { + case '"': + if (!squote) + dquote ^= 1; + break; + case '\'': + if (!dquote) + squote ^= 1; + break; + case '(': + if (!squote && !dquote) + parcnt++; + break; + case ')': + if (!squote && !dquote) + parcnt--; + break; + case '\\': + if (squote || dquote) + { + *q++ = c; + c = mygetc();} + break; + case '\n': + if (squote || dquote) + { + lexerror("Newline in string"); + return 0; + } + break; + } + if (c == ',' && !parcnt && !dquote && !squote) + { + *q++ = 0; + args[++n] = q; + } + else if (parcnt < 0) + { + *q++ = 0; + n++; + break; + } + else + { + if (c == EOF) + { + lexerror("Unexpected end of file"); + return 0; + } + if (q >= expbuf + DEFMAX - 5) + { + lexerror("Macro argument overflow"); + return 0; + } + else + { + *q++ = c; + } + } + if (!squote && ! dquote) + c = cmygetc(); + else + c = mygetc(); + } + if (n == NARGS) + { + lexerror("Maximum macro argument count exceeded"); + return 0; + } + } + if (n != p->nargs) + { + lexerror("Wrong number of macro arguments"); + return 0; + } + /* Do expansion */ + b = buf; + e = p->exps; + while (*e) + { + if (*e == MARKS) + { + if (*++e == MARKS) + *b++ = *e++; + else + { + for (q = args[*e++ - MARKS - 1]; *q; ) + { + *b++ = *q++; + if (b >= buf+DEFMAX) + { + lexerror("Macro expansion overflow"); + return 0; + } + } + } + } + else + { + *b++ = *e++; + if (b >= buf+DEFMAX) + { + lexerror("Macro expansion overflow"); + return 0; + } + } + } + *b++ = 0; + add_input(buf); } return 1; } @@ -2162,61 +2162,61 @@ exgetc(void) c = mygetc(); while (isalpha(c) || c == '_') { - yyp = yytext; - do - { - SAVEC; - c = mygetc(); - } while (isalunum(c)); - myungetc(c); - *yyp = '\0'; - if (strcmp(yytext, "defined") == 0) - { - /* handle the defined "function" in #if */ - do - c = mygetc(); - while (isspace(c)); - - if (c != '(') - { - lexerror("Missing ( in defined"); - continue; - } - do - c = mygetc(); - while (isspace(c)); - - yyp = yytext; - while (isalunum(c)) - { - SAVEC; - c = mygetc(); - } - *yyp = '\0'; - while (isspace(c)) - c = mygetc(); - if (c != ')') - { - lexerror("Missing ) in defined"); - continue; - } - - /* Skip whitespace */ - do - c = mygetc(); - while (isspace(c)); - myungetc(c); - - if (lookup_define(yytext)) - add_input(" 1 "); - else - add_input(" 0 "); - } - else - { - if (!expand_define()) add_input(" 0 "); - } - c = mygetc(); + yyp = yytext; + do + { + SAVEC; + c = mygetc(); + } while (isalunum(c)); + myungetc(c); + *yyp = '\0'; + if (strcmp(yytext, "defined") == 0) + { + /* handle the defined "function" in #if */ + do + c = mygetc(); + while (isspace(c)); + + if (c != '(') + { + lexerror("Missing ( in defined"); + continue; + } + do + c = mygetc(); + while (isspace(c)); + + yyp = yytext; + while (isalunum(c)) + { + SAVEC; + c = mygetc(); + } + *yyp = '\0'; + while (isspace(c)) + c = mygetc(); + if (c != ')') + { + lexerror("Missing ) in defined"); + continue; + } + + /* Skip whitespace */ + do + c = mygetc(); + while (isspace(c)); + myungetc(c); + + if (lookup_define(yytext)) + add_input(" 1 "); + else + add_input(" 0 "); + } + else + { + if (!expand_define()) add_input(" 0 "); + } + c = mygetc(); } return c; } @@ -2264,174 +2264,174 @@ cond_get_exp(int priority) int value, value2, x; do - c = exgetc(); + c = exgetc(); while (isspace(c)); if (c == '(') { - value = cond_get_exp(0); - do - c = exgetc(); - while (isspace(c)); - if (c != ')') - { - lexerror("bracket not paired in #if"); - if (!c) - myungetc('\0'); - } + value = cond_get_exp(0); + do + c = exgetc(); + while (isspace(c)); + if (c != ')') + { + lexerror("bracket not paired in #if"); + if (!c) + myungetc('\0'); + } } else if (ispunct(c)) { - x = (_optab-' ')[c]; - if (!x) - { - lexerror("illegal character in #if"); - return 0; - } - value = cond_get_exp(12); - switch ( optab2[x-1] ) - { - case BNOT : value = ~value; break; - case LNOT : value = !value; break; - case UMINUS: value = -value; break; - case UPLUS : /* value = value; */ break; - default : - lexerror("illegal unary operator in #if"); - return 0; - } + x = (_optab-' ')[c]; + if (!x) + { + lexerror("illegal character in #if"); + return 0; + } + value = cond_get_exp(12); + switch ( optab2[x-1] ) + { + case BNOT : value = ~value; break; + case LNOT : value = !value; break; + case UMINUS: value = -value; break; + case UPLUS : /* value = value; */ break; + default : + lexerror("illegal unary operator in #if"); + return 0; + } } else { - int base; - - if (!isdigit(c)) - { - if (!c) - { - lexerror("missing expression in #if"); - myungetc('\0'); - } - else - lexerror("illegal character in #if"); - return 0; - } - value = 0; - if (c!='0') - base = 10; - else - { - c = mygetc(); - if ( c == 'x' || c == 'X' ) - { - base = 16; - c = mygetc(); - } - else - base=8; - } - for (;;) - { - if ( isdigit(c) ) - x = -'0'; - else if (isupper(c)) - x = -'A' + 10; - else if (islower(c)) - x = -'a' + 10; - else - break; - x += c; - if (x > base) - break; - value = value*base + x; - c = mygetc(); - } - myungetc(c); + int base; + + if (!isdigit(c)) + { + if (!c) + { + lexerror("missing expression in #if"); + myungetc('\0'); + } + else + lexerror("illegal character in #if"); + return 0; + } + value = 0; + if (c!='0') + base = 10; + else + { + c = mygetc(); + if ( c == 'x' || c == 'X' ) + { + base = 16; + c = mygetc(); + } + else + base=8; + } + for (;;) + { + if ( isdigit(c) ) + x = -'0'; + else if (isupper(c)) + x = -'A' + 10; + else if (islower(c)) + x = -'a' + 10; + else + break; + x += c; + if (x > base) + break; + value = value*base + x; + c = mygetc(); + } + myungetc(c); } for (;;) { - do - c = exgetc(); - while (isspace(c)); - - if (!ispunct(c)) - break; - x = (_optab-' ')[c]; - if (!x) - break; - value2 = mygetc(); - for (;;x += 3) - { - if (!optab2[x]) - { - myungetc(value2); - if (!optab2[x + 1]) - { - lexerror("illegal operator use in #if"); - return 0; - } - break; - } - if (value2 == optab2[x]) - break; - } - if (priority >= optab2[x + 2]) - { - if (optab2[x]) - myungetc(value2); - break; - } - value2 = cond_get_exp(optab2[x + 2]); - switch ( optab2[x + 1] ) - { - case MULT : value *= value2; break; - case BPLUS : value += value2; break; - case BMINUS : value -= value2; break; - case LSHIFT : value <<= value2; break; - case RSHIFT : value = (unsigned)value >> value2; break; - case LESS : value = value < value2; break; - case LEQ : value = value <= value2; break; - case GREAT : value = value > value2; break; - case GEQ : value = value >= value2; break; - case EQ : value = value == value2; break; - case NEQ : value = value != value2; break; - case BAND : value &= value2; break; - case XOR : value ^= value2; break; - case BOR : value |= value2; break; - case LAND : value = value && value2; break; - case LOR : value = value || value2; break; - case MOD: + do + c = exgetc(); + while (isspace(c)); + + if (!ispunct(c)) + break; + x = (_optab-' ')[c]; + if (!x) + break; + value2 = mygetc(); + for (;;x += 3) + { + if (!optab2[x]) + { + myungetc(value2); + if (!optab2[x + 1]) + { + lexerror("illegal operator use in #if"); + return 0; + } + break; + } + if (value2 == optab2[x]) + break; + } + if (priority >= optab2[x + 2]) + { + if (optab2[x]) + myungetc(value2); + break; + } + value2 = cond_get_exp(optab2[x + 2]); + switch ( optab2[x + 1] ) + { + case MULT : value *= value2; break; + case BPLUS : value += value2; break; + case BMINUS : value -= value2; break; + case LSHIFT : value <<= value2; break; + case RSHIFT : value = (unsigned)value >> value2; break; + case LESS : value = value < value2; break; + case LEQ : value = value <= value2; break; + case GREAT : value = value > value2; break; + case GEQ : value = value >= value2; break; + case EQ : value = value == value2; break; + case NEQ : value = value != value2; break; + case BAND : value &= value2; break; + case XOR : value ^= value2; break; + case BOR : value |= value2; break; + case LAND : value = value && value2; break; + case LOR : value = value || value2; break; + case MOD: if (!value2) { lexerror("Modulo by zero in #if"); return 0; } value %= value2; break; - case DIV: + case DIV: if (!value2) { lexerror("Division by zero in #if"); return 0; } value /= value2; break; - case QMARK : - do - c = exgetc(); - while (isspace(c)); + case QMARK : + do + c = exgetc(); + while (isspace(c)); if (c != ':') - { - lexerror("'?' without ':' in #if"); - myungetc(c); - return 0; - } - if (value) - { - (void)cond_get_exp(1); - value = value2; - } - else - value = cond_get_exp(1); - break; - } + { + lexerror("'?' without ':' in #if"); + myungetc(c); + return 0; + } + if (value) + { + (void)cond_get_exp(1); + value = value2; + } + else + value = cond_get_exp(1); + break; + } } myungetc(c); return value; @@ -2445,9 +2445,9 @@ free_inc_list(void) int i; for (i = 0; i < inc_list_size; i++) - free(inc_list[i]); + free(inc_list[i]); if (inc_list) - free(inc_list); + free(inc_list); } @@ -2464,74 +2464,74 @@ set_inc_list(struct svalue *sv) free_inc_list(); if (sv == 0) { - inc_list_size = 0; - inc_list = NULL; - return; + inc_list_size = 0; + inc_list = NULL; + return; } if (sv->type != T_POINTER) { - (void)fprintf(stderr, "'define_include_dirs' in master.c did not return an array.\n"); - exit(1); - inc_list_size = 0; - inc_list = NULL; - return; + (void)fprintf(stderr, "'define_include_dirs' in master.c did not return an array.\n"); + exit(1); + inc_list_size = 0; + inc_list = NULL; + return; } v = sv->u.vec; if (v->size == 0) { - (void)fprintf(stderr, "'define_include_dirs' returned an empty array\n"); - inc_list_size = 0; - inc_list = NULL; - return; + (void)fprintf(stderr, "'define_include_dirs' returned an empty array\n"); + inc_list_size = 0; + inc_list = NULL; + return; } tmp_inc_list = (char **) xalloc(v->size * sizeof (char *)); inc_list_size = 0; for (i = 0; i < v->size; i++) { - if (v->item[i].type != T_STRING) - { - (void)fprintf(stderr, "Illegal value returned from 'define_include_dirs' in master.c\n"); - continue; - } - p = v->item[i].u.string; - if (*p == '/') - p++; - /* - * Even make sure that the game administrator has not made an error. - */ - if (!legal_path(p)) - { - (void)fprintf(stderr, "'define_include_dirs' must give paths without any '..'\n"); - continue; - } - if ((end = strstr(p, "%s"))) { - if (end != p + strlen(p) - 2) { - (void)fprintf(stderr, "'define_include_dirs' may only contain %%s last."); - continue; - } - } - else - end = p + strlen(p); - if (end != p && end[-1] != '/') { - tmp_inc_list[inc_list_size] = xalloc(end - p + 2); - strncpy(tmp_inc_list[inc_list_size], p, end - p); - tmp_inc_list[inc_list_size][end - p] = '/'; - tmp_inc_list[inc_list_size][end - p + 1] = '\0'; - } else { - tmp_inc_list[inc_list_size] = xalloc(end - p + 1); - strncpy(tmp_inc_list[inc_list_size], p, end - p); - tmp_inc_list[inc_list_size][end - p] = '\0'; - } - inc_list_size++; + if (v->item[i].type != T_STRING) + { + (void)fprintf(stderr, "Illegal value returned from 'define_include_dirs' in master.c\n"); + continue; + } + p = v->item[i].u.string; + if (*p == '/') + p++; + /* + * Even make sure that the game administrator has not made an error. + */ + if (!legal_path(p)) + { + (void)fprintf(stderr, "'define_include_dirs' must give paths without any '..'\n"); + continue; + } + if ((end = strstr(p, "%s"))) { + if (end != p + strlen(p) - 2) { + (void)fprintf(stderr, "'define_include_dirs' may only contain %%s last."); + continue; + } + } + else + end = p + strlen(p); + if (end != p && end[-1] != '/') { + tmp_inc_list[inc_list_size] = xalloc(end - p + 2); + strncpy(tmp_inc_list[inc_list_size], p, end - p); + tmp_inc_list[inc_list_size][end - p] = '/'; + tmp_inc_list[inc_list_size][end - p + 1] = '\0'; + } else { + tmp_inc_list[inc_list_size] = xalloc(end - p + 1); + strncpy(tmp_inc_list[inc_list_size], p, end - p); + tmp_inc_list[inc_list_size][end - p] = '\0'; + } + inc_list_size++; } if (inc_list_size == 0) { - inc_list = NULL; - free(tmp_inc_list); + inc_list = NULL; + free(tmp_inc_list); } else if (inc_list_size != v->size) { - inc_list = (char **) xalloc(inc_list_size * sizeof (char *)); - for (i = 0; i < inc_list_size; i++) - inc_list[i] = tmp_inc_list[i]; - free(tmp_inc_list); + inc_list = (char **) xalloc(inc_list_size * sizeof (char *)); + for (i = 0; i < inc_list_size; i++) + inc_list[i] = tmp_inc_list[i]; + free(tmp_inc_list); } else - inc_list = tmp_inc_list; + inc_list = tmp_inc_list; } diff --git a/lint.h b/lint.h index 070b6c8..e5f1806 100644 --- a/lint.h +++ b/lint.h @@ -19,22 +19,22 @@ /* * Some structure forward declarations are needed. */ -#define DEBUG_CHK_REF 1 -#define DEBUG_RESET 2 -#define DEBUG_CLEAN_UP 4 -#define DEBUG_SWAP 8 -#define DEBUG_OUTPUT 16 -#define DEBUG_CONNECT 32 -#define DEBUG_TELNET 64 -#define DEBUG_RESTORE 128 -#define DEBUG_OB_REF 256 -#define DEBUG_PROG_REF 512 -#define DEBUG_LOAD 1024 -#define DEBUG_DESTRUCT 2048 -#define DEBUG_LIVING 4096 -#define DEBUG_COMMAND 8192 +#define DEBUG_CHK_REF 1 +#define DEBUG_RESET 2 +#define DEBUG_CLEAN_UP 4 +#define DEBUG_SWAP 8 +#define DEBUG_OUTPUT 16 +#define DEBUG_CONNECT 32 +#define DEBUG_TELNET 64 +#define DEBUG_RESTORE 128 +#define DEBUG_OB_REF 256 +#define DEBUG_PROG_REF 512 +#define DEBUG_LOAD 1024 +#define DEBUG_DESTRUCT 2048 +#define DEBUG_LIVING 4096 +#define DEBUG_COMMAND 8192 #define DEBUG_ADD_ACTION 16384 -#define DEBUG_SENTENCE 32768 +#define DEBUG_SENTENCE 32768 #define DEBUG_BREAK_POINT 65536 /* Calculation of average */ diff --git a/main.c b/main.c index 1f6ac03..9b874d8 100644 --- a/main.c +++ b/main.c @@ -29,9 +29,9 @@ extern int current_line; -int d_flag = 0; /* Run with debug */ -int t_flag = 0; /* Disable heart beat and reset */ -int e_flag = 0; /* Load empty, without castles. */ +int d_flag = 0; /* Run with debug */ +int t_flag = 0; /* Disable heart beat and reset */ +int e_flag = 0; /* Load empty, without castles. */ int s_flag = 0; /* Make statistics and dump to /MUDstatistics */ int no_ip_demon = 0; int unlimited = 0; /* Run without eval cost limits */ @@ -57,7 +57,7 @@ int udp_port = CATCH_UDP_PORT; #ifdef SERVICE_PORT int service_port = SERVICE_PORT; #endif -char *reserved_area; /* reserved for malloc() */ +char *reserved_area; /* reserved for malloc() */ struct svalue const0, const1, constempty; struct closure funcempty; @@ -232,61 +232,61 @@ main(int argc, char **argv) } else { - exception_frame.e_exception = NULL; - exception_frame.e_catch = 0; - exception = &exception_frame; - auto_ob = 0; - master_ob = 0; - - if ((auto_ob = load_object("secure/auto", 1, 0, 0)) != NULL) - { - add_ref(auto_ob, "main"); - auto_ob->prog->flags |= PRAGMA_RESIDENT; - } - - get_simul_efun(); - master_ob = load_object("secure/master", 1, 0, 0); - if (master_ob) - { - /* - * Make sure master_ob is never made a dangling pointer. - * Look at apply_master_ob() for more details. - */ - add_ref(master_ob, "main"); - master_ob->prog->flags |= PRAGMA_RESIDENT; + exception_frame.e_exception = NULL; + exception_frame.e_catch = 0; + exception = &exception_frame; + auto_ob = 0; + master_ob = 0; + + if ((auto_ob = load_object("secure/auto", 1, 0, 0)) != NULL) + { + add_ref(auto_ob, "main"); + auto_ob->prog->flags |= PRAGMA_RESIDENT; + } + + get_simul_efun(); + master_ob = load_object("secure/master", 1, 0, 0); + if (master_ob) + { + /* + * Make sure master_ob is never made a dangling pointer. + * Look at apply_master_ob() for more details. + */ + add_ref(master_ob, "main"); + master_ob->prog->flags |= PRAGMA_RESIDENT; resolve_master_fkntab(); - create_object(master_ob); + create_object(master_ob); load_parse_information(); - clear_state(); - } + clear_state(); + } } exception = NULL; if (auto_ob == 0) { - (void)fprintf(stderr, "The file secure/auto must be loadable.\n"); - exit(1); + (void)fprintf(stderr, "The file secure/auto must be loadable.\n"); + exit(1); } if (master_ob == 0) { - (void)fprintf(stderr, "The file secure/master must be loadable.\n"); - exit(1); + (void)fprintf(stderr, "The file secure/master must be loadable.\n"); + exit(1); } set_inc_list(apply_master_ob(M_DEFINE_INCLUDE_DIRS, 0)); { - struct svalue* ret1; + struct svalue* ret1; - ret1 = apply_master_ob(M_PREDEF_DEFINES, 0); - if (ret1 && ret1->type == T_POINTER) - { - int ii; + ret1 = apply_master_ob(M_PREDEF_DEFINES, 0); + if (ret1 && ret1->type == T_POINTER) + { + int ii; - for (ii = 0; ii < ret1->u.vec->size; ii++) - if (ret1->u.vec->item[ii].type == T_STRING) - { + for (ii = 0; ii < ret1->u.vec->size; ii++) + if (ret1->u.vec->item[ii].type == T_STRING) + { add_pre_define(ret1->u.vec->item[ii].u.string); - } - } + } + } } if (flag != NULL) @@ -309,28 +309,28 @@ main(int argc, char **argv) if (ret && ret->type == T_STRING) { - struct lpc_predef_s *tmp; - - tmp = (struct lpc_predef_s *) - xalloc(sizeof(struct lpc_predef_s)); - if (!tmp) - fatal("xalloc failed\n"); - tmp->flag = string_copy(ret->u.string); - tmp->next = lpc_predefs; - lpc_predefs = tmp; + struct lpc_predef_s *tmp; + + tmp = (struct lpc_predef_s *) + xalloc(sizeof(struct lpc_predef_s)); + if (!tmp) + fatal("xalloc failed\n"); + tmp->flag = string_copy(ret->u.string); + tmp->next = lpc_predefs; + lpc_predefs = tmp; } ret = apply_master_ob(M_GET_VBFC_OBJECT, 0); if (ret && ret->type == T_OBJECT) { - vbfc_object = ret->u.ob; - INCREF(vbfc_object->ref); + vbfc_object = ret->u.ob; + INCREF(vbfc_object->ref); } else - vbfc_object = 0; + vbfc_object = 0; if (game_is_being_shut_down) - exit(1); + exit(1); init_call_out(); preload_objects(e_flag); @@ -364,15 +364,15 @@ debug_message(char *fmt, ...) char name[100]; if (fp == NULL) { - (void)gethostname(name,sizeof name); - if ((f = strchr(name, '.')) != NULL) - *f = '\0'; - snprintf(deb, sizeof(deb), "%s.debug.log", name); - fp = fopen(deb, "w"); - if (fp == NULL) { - perror(deb); - abort(); - } + (void)gethostname(name,sizeof name); + if ((f = strchr(name, '.')) != NULL) + *f = '\0'; + snprintf(deb, sizeof(deb), "%s.debug.log", name); + fp = fopen(deb, "w"); + if (fp == NULL) { + perror(deb); + abort(); + } } va_start(argp, fmt); @@ -386,30 +386,30 @@ debug_message_svalue(struct svalue *v) { if (v == 0) { - debug_message(""); - return; + debug_message(""); + return; } switch(v->type) { case T_NUMBER: - debug_message("%lld", v->u.number); - return; + debug_message("%lld", v->u.number); + return; case T_FLOAT: - debug_message("%.18g", v->u.real); - return; + debug_message("%.18g", v->u.real); + return; case T_STRING: - debug_message("\"%s\"", v->u.string); - return; + debug_message("\"%s\"", v->u.string); + return; case T_OBJECT: - debug_message("OBJ(%s)", v->u.ob->name); - return; + debug_message("OBJ(%s)", v->u.ob->name); + return; case T_LVALUE: - debug_message("Pointer to "); - debug_message_svalue(v->u.lvalue); - return; + debug_message("Pointer to "); + debug_message_svalue(v->u.lvalue); + return; default: - debug_message("\n"); - return; + debug_message("\n"); + return; } } diff --git a/make_func.y b/make_func.y index 05960e1..c161231 100644 --- a/make_func.y +++ b/make_func.y @@ -6,14 +6,14 @@ #include #include "config.h" -#define FUNC_SPEC "func_spec.i" -#define FUNC_TOKENS "efun_tokens.y" +#define FUNC_SPEC "func_spec.i" +#define FUNC_TOKENS "efun_tokens.y" #define PRE_LANG "prelang.y" #define POST_LANG "postlang.y" #define THE_LANG "lang.y" -#define NELEMS(arr) (sizeof arr / sizeof arr[0]) +#define NELEMS(arr) (sizeof arr / sizeof arr[0]) -#define MAX_FUNC 2048 /* If we need more than this we're in trouble! */ +#define MAX_FUNC 2048 /* If we need more than this we're in trouble! */ int num_buff; /* For quick sort purposes : */ char *key[MAX_FUNC], *buf[MAX_FUNC], has_token[MAX_FUNC]; @@ -81,90 +81,90 @@ optional_default: DEFAULT ':' ID { $$ = $3; } | /* empty */ { $$="0"; } ; func: type ID optional_ID '(' arg_list optional_default ')' ';' { - char buff[500]; - char f_name[500]; - int i; - if (min_arg == -1) - min_arg = $5; - if ($3[0] == '\0') { - int len; - if (strlen($2) + 1 + 2 > sizeof f_name) - fatal("A local buffer was too small!(1)\n"); - (void)sprintf(f_name, "F_%s", $2); - len = strlen(f_name); - for (i=0; i < len; i++) { - if (islower(f_name[i])) - f_name[i] = toupper(f_name[i]); - } - has_token[num_buff]=1; - } else { - if (strlen($3) + 1 > sizeof f_name) - fatal("A local buffer was too small(2)!\n"); - (void)strcpy(f_name, $3); - has_token[num_buff]=0; - } - for(i=0; i < last_current_type; i++) { - int j; - for (j = 0; j+i sizeof f_name) + fatal("A local buffer was too small!(1)\n"); + (void)sprintf(f_name, "F_%s", $2); + len = strlen(f_name); + for (i=0; i < len; i++) { + if (islower(f_name[i])) + f_name[i] = toupper(f_name[i]); + } + has_token[num_buff]=1; + } else { + if (strlen($3) + 1 > sizeof f_name) + fatal("A local buffer was too small(2)!\n"); + (void)strcpy(f_name, $3); + has_token[num_buff]=0; + } + for(i=0; i < last_current_type; i++) { + int j; + for (j = 0; j+i sizeof buff) - fatal("Local buffer overwritten !\n"); + fatal("Local buffer overwritten !\n"); key[num_buff] = (char *) malloc(strlen($2) + 1); - (void)strcpy(key[num_buff], $2); - buf[num_buff] = (char *) malloc(strlen(buff) + 1); - (void)strcpy(buf[num_buff], buff); + (void)strcpy(key[num_buff], $2); + buf[num_buff] = (char *) malloc(strlen(buff) + 1); + (void)strcpy(buf[num_buff], buff); num_buff++; - min_arg = -1; - limit_max = 0; - curr_arg_type_size = 0; + min_arg = -1; + limit_max = 0; + curr_arg_type_size = 0; } ; type: basic | basic '*' { $$ = $1 | 0x10000; }; basic: VOID | INT | STRING | MIXED | UNKNOWN | OBJECT | MAPPING | FLOAT | FUNCTION ; -arg_list: /* empty */ { $$ = 0; } - | typel2 { $$ = 1; if ($1) min_arg = 0; } - | arg_list ',' typel2 { $$ = $1 + 1; if ($3) min_arg = $$ - 1; } ; +arg_list: /* empty */ { $$ = 0; } + | typel2 { $$ = 1; if ($1) min_arg = 0; } + | arg_list ',' typel2 { $$ = $1 + 1; if ($3) min_arg = $$ - 1; } ; typel2: typel { - $$ = $1; - curr_arg_types[curr_arg_type_size++] = 0; - if (curr_arg_type_size == NELEMS(curr_arg_types)) - yyerror("Too many arguments"); + $$ = $1; + curr_arg_types[curr_arg_type_size++] = 0; + if (curr_arg_type_size == NELEMS(curr_arg_types)) + yyerror("Too many arguments"); } ; arg_type: type { - if ($1 != VOID) { - curr_arg_types[curr_arg_type_size++] = $1; - if (curr_arg_type_size == NELEMS(curr_arg_types)) - yyerror("Too many arguments"); - } - $$ = $1; + if ($1 != VOID) { + curr_arg_types[curr_arg_type_size++] = $1; + if (curr_arg_type_size == NELEMS(curr_arg_types)) + yyerror("Too many arguments"); + } + $$ = $1; } ; -typel: arg_type { $$ = ($1 == VOID && min_arg == -1); } - | typel '|' arg_type { $$ = (min_arg == -1 && ($1 || $3 == VOID));} - | '.' '.' '.' { $$ = min_arg == -1 ; limit_max = 1; } ; +typel: arg_type { $$ = ($1 == VOID && min_arg == -1); } + | typel '|' arg_type { $$ = (min_arg == -1 && ($1 || $3 == VOID));} + | '.' '.' '.' { $$ = min_arg == -1 ; limit_max = 1; } ; %% @@ -196,8 +196,8 @@ main(int argc, char **argv) if ((f = fopen(FUNC_SPEC, "r")) == NULL) { - perror(FUNC_SPEC); - exit(1); + perror(FUNC_SPEC); + exit(1); } (void)yyparse(); /* Now sort the main_list */ @@ -206,14 +206,14 @@ main(int argc, char **argv) { int j; for (j = 0; j < i; j++) - if (strcmp(key[i], key[j]) < 0) - { - char *tmp; - int tmpi; - tmp = key[i]; key[i] = key[j]; key[j] = tmp; - tmp = buf[i]; buf[i] = buf[j]; buf[j] = tmp; - tmpi = has_token[i]; - has_token[i] = has_token[j]; has_token[j] = tmpi; + if (strcmp(key[i], key[j]) < 0) + { + char *tmp; + int tmpi; + tmp = key[i]; key[i] = key[j]; key[j] = tmp; + tmp = buf[i]; buf[i] = buf[j]; buf[j] = tmp; + tmpi = has_token[i]; + has_token[i] = has_token[j]; has_token[j] = tmpi; } } @@ -224,10 +224,10 @@ main(int argc, char **argv) (void)printf("\n};\nint efun_arg_types[] = {\n"); for (i = 0; i < last_current_type; i++) { - if (arg_types[i] == 0) - (void)printf("0,\n"); - else - (void)printf("%s,", ctype(arg_types[i])); + if (arg_types[i] == 0) + (void)printf("0,\n"); + else + (void)printf("%s,", ctype(arg_types[i])); } (void)printf("};\n"); (void)fclose(f); @@ -254,22 +254,22 @@ main(int argc, char **argv) (void)fclose(fpr); for (i = 0; i < num_buff; i++) { - if (has_token[i]) - { - char *str; /* It's okay to mung key[*] now */ - for (str = key[i]; *str; str++) - if (islower(*str)) *str = toupper(*str); - (void)sprintf(buffer, "%%token F_%s\n", key[i]); - (void)fwrite(buffer, sizeof(buffer[0]), strlen(buffer), fpw); - } + if (has_token[i]) + { + char *str; /* It's okay to mung key[*] now */ + for (str = key[i]; *str; str++) + if (islower(*str)) *str = toupper(*str); + (void)sprintf(buffer, "%%token F_%s\n", key[i]); + (void)fwrite(buffer, sizeof(buffer[0]), strlen(buffer), fpw); + } } if ((fpr = fopen(POST_LANG, "r")) < 0) { - perror(POST_LANG); - exit(1); + perror(POST_LANG); + exit(1); } while ( (i = fread(buffer, sizeof(buffer[0]), BUFSIZ, fpr)) > 0) - (void)fwrite(buffer, sizeof(buffer[0]), i, fpw); + (void)fwrite(buffer, sizeof(buffer[0]), i, fpw); (void)fclose(fpr); (void)fclose(fpw); return 0; @@ -291,14 +291,14 @@ oper() c = getc(f); for (len=0; c != EOF && c != '('; c = getc(f)) { - buff[len++] = c; - if (len + 1 >= sizeof buff) - fatal("Local buffer in oper() too small!\n"); - if (len == sizeof buff - 1) - { - yyerror("Too long indentifier"); - break; - } + buff[len++] = c; + if (len + 1 >= sizeof buff) + fatal("Local buffer in oper() too small!\n"); + if (len == sizeof buff - 1) + { + yyerror("Too long indentifier"); + break; + } } (void)ungetc(c, f); buff[len] = '\0'; @@ -315,27 +315,27 @@ ident(int c) for (len=0; isalnum(c) || c == '_'; c = getc(f)) { - buff[len++] = c; - if (len + 1 >= sizeof buff) - fatal("Local buffer in ident() too small!\n"); - if (len == sizeof buff - 1) - { - yyerror("Too long indentifier"); - break; - } + buff[len++] = c; + if (len + 1 >= sizeof buff) + fatal("Local buffer in ident() too small!\n"); + if (len == sizeof buff - 1) + { + yyerror("Too long indentifier"); + break; + } } (void)ungetc(c, f); buff[len] = '\0'; for (i = 0; i < NELEMS(types); i++) { - if (strcmp(buff, types[i].name) == 0) - { - yylval.number = types[i].num; - return types[i].num; - } + if (strcmp(buff, types[i].name) == 0) + { + yylval.number = types[i].num; + return types[i].num; + } } if (strcmp(buff, "default") == 0) - return DEFAULT; + return DEFAULT; yylval.string = (char *) malloc(strlen(buff)+1); (void)strcpy(yylval.string, buff); return ID; @@ -347,34 +347,34 @@ yylex1() register int c; for(;;) { - switch(c = getc(f)) { - case ' ': - case '\t': - continue; - case '#': - { - int line; - char file[2048]; /* does any operating system support - longer pathnames? */ - if ( fscanf(f,"%d \"%s\"",&line,file ) == 2 ) - current_line = line; - while(c != '\n' && c != EOF) - c = getc(f); - current_line++; - continue; - } - case '\n': - current_line++; - continue; - case EOF: - return -1; - case '\\': - return oper(); - default: - if (isalpha(c)) - return ident(c); - return c; - } + switch(c = getc(f)) { + case ' ': + case '\t': + continue; + case '#': + { + int line; + char file[2048]; /* does any operating system support + longer pathnames? */ + if ( fscanf(f,"%d \"%s\"",&line,file ) == 2 ) + current_line = line; + while(c != '\n' && c != EOF) + c = getc(f); + current_line++; + continue; + } + case '\n': + current_line++; + continue; + case EOF: + return -1; + case '\\': + return oper(); + default: + if (isalpha(c)) + return ident(c); + return c; + } } } @@ -387,24 +387,24 @@ yylex() char *etype1(int n) { if (n & 0x10000) - return "T_POINTER"; + return "T_POINTER"; switch(n) { case INT: - return "T_NUMBER"; + return "T_NUMBER"; case OBJECT: - return "T_OBJECT"; + return "T_OBJECT"; case STRING: - return "T_STRING"; + return "T_STRING"; case MAPPING: - return "T_MAPPING"; + return "T_MAPPING"; case FUNCTION: - return "T_FUNCTION"; + return "T_FUNCTION"; case FLOAT: - return "T_FLOAT"; + return "T_FLOAT"; case MIXED: - return "0"; /* 0 means any type */ + return "0"; /* 0 means any type */ default: - yyerror("Illegal type for argument"); + yyerror("Illegal type for argument"); } return "What ?"; } @@ -417,43 +417,43 @@ etype(int n) char *buff = (char *) malloc(local_size); for (i=0; i < curr_arg_type_size; i++) { - if (n == 0) - break; - if (curr_arg_types[i] == 0) - n--; + if (n == 0) + break; + if (curr_arg_types[i] == 0) + n--; } if (i == curr_arg_type_size) - return "0"; + return "0"; buff[0] = '\0'; for(; curr_arg_types[i] != 0; i++) { - char *p; - if (curr_arg_types[i] == VOID) - continue; - if (buff[0] != '\0') - (void)strcat(buff, "|"); - p = etype1(curr_arg_types[i]); - /* - * The number 2 below is to include the zero-byte and the next - * '|' (which may not come). - */ - if (strlen(p) + strlen(buff) + 2 > local_size) { - (void)fprintf(stderr, "Buffer overflow!\n"); - exit(1); - } - (void)strcat(buff, etype1(curr_arg_types[i])); + char *p; + if (curr_arg_types[i] == VOID) + continue; + if (buff[0] != '\0') + (void)strcat(buff, "|"); + p = etype1(curr_arg_types[i]); + /* + * The number 2 below is to include the zero-byte and the next + * '|' (which may not come). + */ + if (strlen(p) + strlen(buff) + 2 > local_size) { + (void)fprintf(stderr, "Buffer overflow!\n"); + exit(1); + } + (void)strcat(buff, etype1(curr_arg_types[i])); } return buff; } char *ctype(int n) { - static char buff[100]; /* 100 is such a comfortable size :-) */ + static char buff[100]; /* 100 is such a comfortable size :-) */ char *p = ""; if (n & 0x10000) - (void)strcpy(buff, "TYPE_MOD_POINTER|"); + (void)strcpy(buff, "TYPE_MOD_POINTER|"); else - buff[0] = '\0'; + buff[0] = '\0'; n &= ~0x10000; switch(n) { case VOID: p = "TYPE_VOID"; break; @@ -469,6 +469,6 @@ char *ctype(int n) } (void)strcat(buff, p); if (strlen(buff) + 1 > sizeof buff) - fatal("Local buffer overwritten in ctype()\n"); + fatal("Local buffer overwritten in ctype()\n"); return buff; } diff --git a/make_table.c b/make_table.c index 7aba9af..2f03810 100644 --- a/make_table.c +++ b/make_table.c @@ -12,19 +12,19 @@ main(int argc, char *argv[]) int first=0x7fffffff, last=0, n; if (argc != 3) { - (void)fprintf(stderr, "Usage: make_table input.h output.h\n"); - exit(1); - /* NOTREACHED */ + (void)fprintf(stderr, "Usage: make_table input.h output.h\n"); + exit(1); + /* NOTREACHED */ } if ((in = fopen(argv[1], "r")) == NULL) { - perror("fopen"); - exit(1); - /* NOTREACHED */ + perror("fopen"); + exit(1); + /* NOTREACHED */ } if ((out = fopen(argv[2], "w")) == NULL) { - perror("fopen"); - exit(1); - /* NOTREACHED */ + perror("fopen"); + exit(1); + /* NOTREACHED */ } (void)fprintf(out, "/*\n"); (void)fprintf(out, " * This file is automatically generated; do not edit.\n"); @@ -32,24 +32,24 @@ main(int argc, char *argv[]) (void)fprintf(out, "#ifdef EFUN_TABLE\n"); (void)fprintf(out, "static void (*efun_table[])(int) = {\n"); while (fgets(buffer, sizeof(buffer), in)) { - if (buffer[0] != '#') - continue; - p = strtok(buffer+1, " \t\n"); - if (strcmp(p, "define")) - continue; - if ((p = strtok(NULL, " \t\n")) == NULL) - continue; - if (p[0] != 'F' || p[1] != '_') - continue; - lower(p); - (void)fprintf(out, "\t%s,\n", p); - if ((p = strtok(NULL, " \t\n")) == NULL) - continue; - n = atoi(p); - if (n < first) - first = n; - if (n > last) - last = n; + if (buffer[0] != '#') + continue; + p = strtok(buffer+1, " \t\n"); + if (strcmp(p, "define")) + continue; + if ((p = strtok(NULL, " \t\n")) == NULL) + continue; + if (p[0] != 'F' || p[1] != '_') + continue; + lower(p); + (void)fprintf(out, "\t%s,\n", p); + if ((p = strtok(NULL, " \t\n")) == NULL) + continue; + n = atoi(p); + if (n < first) + first = n; + if (n > last) + last = n; } (void)fprintf(out, "};\n"); (void)fprintf(out, "#else /* EFUN_TABLE */\n"); @@ -66,7 +66,7 @@ lower(char *string) { while (*string) { if (isupper(*string)) - *string = tolower(*string); - string++; + *string = tolower(*string); + string++; } } diff --git a/mapping.c b/mapping.c index 1c4311c..afc4dce 100644 --- a/mapping.c +++ b/mapping.c @@ -3,7 +3,7 @@ #include #include #include -#include /* sys/types.h and netinet/in.h are here to enable include of comm.h below */ +#include /* sys/types.h and netinet/in.h are here to enable include of comm.h below */ #include /* #include Included in comm.h below */ #include @@ -38,12 +38,12 @@ free_apairs(struct apair *p) int pairs = 0; for (;p;p = next) { - free_svalue(&p->arg); - free_svalue(&p->val); - next = p->next; - free((char *)p); - total_mapping_size -= sizeof(struct apair); - pairs++; + free_svalue(&p->arg); + free_svalue(&p->val); + next = p->next; + free((char *)p); + total_mapping_size -= sizeof(struct apair); + pairs++; } return pairs; } @@ -54,12 +54,12 @@ free_mapping(struct mapping *m) unsigned int i; if (!m->ref || --m->ref > 0) - return; + return; for (i = 0; i < m->size; i++) - m->card -= free_apairs(m->pairs[i]); + m->card -= free_apairs(m->pairs[i]); num_mappings--; total_mapping_size -= (sizeof(struct apair *) * m->size + - sizeof(struct mapping)); + sizeof(struct mapping)); free((char *)m->pairs); free((char *)m); } @@ -72,7 +72,7 @@ allocate_map(unsigned int msize) unsigned int size; for(size = 1, u = (msize*100)/FILL_FACTOR; u && size < MAX_MAPPING_SIZE; size <<= 1, u >>= 1) - ; + ; num_mappings++; m = (struct mapping *) xalloc(sizeof(struct mapping)); @@ -137,8 +137,8 @@ get_map_lvalue(struct mapping *m, struct svalue *k, int c) h = hash % m->size; for (p = m->pairs[h]; p; p = p->next) { - if (p->hashval == hash && equal_svalue(k, &p->arg)) - break; + if (p->hashval == hash && equal_svalue(k, &p->arg)) + break; } if (!p) { if (c) { @@ -148,14 +148,14 @@ get_map_lvalue(struct mapping *m, struct svalue *k, int c) } m->pairs[h] = p = newpair(m->pairs[h], k, &const0, hash); - if (++m->card > m->mcard) { - /* We need to extend the hash table */ - rehash_map(m); - } - } else { - /* Return address of a dummy location, with 0. */ - return &const0; - } + if (++m->card > m->mcard) { + /* We need to extend the hash table */ + rehash_map(m); + } + } else { + /* Return address of a dummy location, with 0. */ + return &const0; + } } return &p->val; } @@ -171,8 +171,8 @@ struct mapping *m; cnt = m->card; d = allocate_array(cnt); for (k = 0, i = 0; i < m->size; i++) - for(p = m->pairs[i]; p; p = p->next) - assign_svalue_no_free (&d->item[k++], &p->arg); + for(p = m->pairs[i]; p; p = p->next) + assign_svalue_no_free (&d->item[k++], &p->arg); return d; } @@ -186,8 +186,8 @@ map_codomain(struct mapping *m) cnt = m->card; d = allocate_array(cnt); for (k = 0, i = 0; i < m->size; i++) - for(p = m->pairs[i]; p; p = p->next) - assign_svalue_no_free(&d->item[k++], &p->val); + for(p = m->pairs[i]; p; p = p->next) + assign_svalue_no_free(&d->item[k++], &p->val); return d; } @@ -204,29 +204,29 @@ make_mapping(struct vector *ind, struct vector *val) #endif if (ind != NULL && val != NULL) { - max = ind->size < val->size ? ind->size : val->size; - m = allocate_map(max); - for (i = 0 ; i < max ; i++) - { - assign_svalue(get_map_lvalue(m, &ind->item[i], 1), - &val->item[i]); - } + max = ind->size < val->size ? ind->size : val->size; + m = allocate_map(max); + for (i = 0 ; i < max ; i++) + { + assign_svalue(get_map_lvalue(m, &ind->item[i], 1), + &val->item[i]); + } } else if (ind != NULL && val == NULL) { - m = allocate_map(ind->size); - for (i = 0 ; i < ind->size ; i++) - { - tmp.u.number = i; - assign_svalue(get_map_lvalue(m, &ind->item[i], 1), &tmp); - } + m = allocate_map(ind->size); + for (i = 0 ; i < ind->size ; i++) + { + tmp.u.number = i; + assign_svalue(get_map_lvalue(m, &ind->item[i], 1), &tmp); + } } else if (ind == NULL && val != NULL) { - m = allocate_map(val->size); - for (i = 0 ; i < val->size ; i++) - { - tmp.u.number = i; - assign_svalue_no_free(get_map_lvalue(m, &tmp, 1), &val->item[i]); - } + m = allocate_map(val->size); + for (i = 0 ; i < val->size ; i++) + { + tmp.u.number = i; + assign_svalue_no_free(get_map_lvalue(m, &tmp, 1), &val->item[i]); + } } else { - m = allocate_map(0); + m = allocate_map(0); } return m; @@ -243,13 +243,13 @@ add_mapping(struct mapping *m1, struct mapping *m2) for (i = 0 ; i < m1->size ; i++) { - for (p = m1->pairs[i]; p ; p = p->next) - assign_svalue(get_map_lvalue(retm, &p->arg, 1), &p->val); + for (p = m1->pairs[i]; p ; p = p->next) + assign_svalue(get_map_lvalue(retm, &p->arg, 1), &p->val); } for (i = 0 ; i < m2->size ; i++) { - for (p = m2->pairs[i]; p ; p = p->next) - assign_svalue(get_map_lvalue(retm, &p->arg, 1), &p->val); + for (p = m2->pairs[i]; p ; p = p->next) + assign_svalue(get_map_lvalue(retm, &p->arg, 1), &p->val); } return retm; } @@ -262,8 +262,8 @@ addto_mapping(struct mapping *m1, struct mapping *m2) for (i = 0 ; i < m2->size ; i++) { - for (p = m2->pairs[i]; p ; p = p->next) - assign_svalue(get_map_lvalue(m1, &p->arg, 1), &p->val); + for (p = m2->pairs[i]; p ; p = p->next) + assign_svalue(get_map_lvalue(m1, &p->arg, 1), &p->val); } } @@ -277,12 +277,12 @@ remove_from_mapping(struct mapping *m, struct svalue *val) for (p = &m->pairs[h]; *p; p = &(*p)->next) if (equal_svalue(val, &(*p)->arg)) { - struct apair *del = *p; - *p = del->next; - del->next = NULL; - m->card--; - free_apairs(del); - return; + struct apair *del = *p; + *p = del->next; + del->next = NULL; + m->card--; + free_apairs(del); + return; } return; @@ -300,16 +300,16 @@ remove_mapping(struct mapping *m, struct svalue *val) for (i = 0 ; i < m->size ; i++) { - for (p = m->pairs[i] ; p ; p = p->next) - { - if (h == i) - { - if (!equal_svalue(val, &p->arg)) - assign_svalue(get_map_lvalue(retm, &p->arg, 1), &p->val); - } - else - assign_svalue(get_map_lvalue(retm, &p->arg, 1), &p->val); - } + for (p = m->pairs[i] ; p ; p = p->next) + { + if (h == i) + { + if (!equal_svalue(val, &p->arg)) + assign_svalue(get_map_lvalue(retm, &p->arg, 1), &p->val); + } + else + assign_svalue(get_map_lvalue(retm, &p->arg, 1), &p->val); + } } return retm; } @@ -323,20 +323,20 @@ rehash_map(struct mapping *map) nsize = map->size * 2; if (nsize > MAX_MAPPING_SIZE) { - error("Too large mapping.\n"); - return; + error("Too large mapping.\n"); + return; } pairs = (struct apair **)xalloc(sizeof(struct apair *) * nsize); (void)memset(pairs, 0, sizeof(struct apair *) * nsize); for (i = 0 ; i < map->size ; i++) { - for (ptr = map->pairs[i]; ptr; ptr = next) { - hval = ptr->hashval & (nsize-1); - next = ptr->next; - ptr->next = pairs[hval]; - pairs[hval] = ptr; - } + for (ptr = map->pairs[i]; ptr; ptr = next) { + hval = ptr->hashval & (nsize-1); + next = ptr->next; + ptr->next = pairs[hval]; + pairs[hval] = ptr; + } } free((char *)map->pairs); @@ -364,8 +364,8 @@ copy_mapping(struct mapping *m) cm->card = m->card; cm->mcard = m->mcard; for (i = 0; i < m->size; i++) - for(pair = m->pairs[i]; pair; pair = pair->next) - cm->pairs[i] = newpair(cm->pairs[i], &pair->arg, &pair->val, pair->hashval); + for(pair = m->pairs[i]; pair; pair = pair->next) + cm->pairs[i] = newpair(cm->pairs[i], &pair->arg, &pair->val, pair->hashval); return cm; } @@ -381,15 +381,15 @@ map_map(struct mapping *map, struct closure *fun) struct apair *p; unsigned int i; - r = copy_mapping(map); /* copy entire mapping */ + r = copy_mapping(map); /* copy entire mapping */ push_mapping(r, 0); for (i = 0 ; i < r->size ; i++) { - for(p = r->pairs[i]; p; p = p->next) { - push_svalue(&p->val); - (void)call_var(1, fun); - assign_svalue(&p->val, sp); /* replace old value */ - pop_stack(); /* and pop it */ - } + for(p = r->pairs[i]; p; p = p->next) { + push_svalue(&p->val); + (void)call_var(1, fun); + assign_svalue(&p->val, sp); /* replace old value */ + pop_stack(); /* and pop it */ + } } sp--; return r; @@ -411,23 +411,23 @@ filter_map(struct mapping *map, struct closure *fun) r = copy_mapping(map); for (i = 0; i < r->size; i++) { - for(p = &r->pairs[i]; *p;) { - push_svalue(&(*p)->val); - (void)call_var(1, fun); - if (sp->type == T_NUMBER && sp->u.number == 0) { - /* remove it from the list */ - struct apair *ap = *p; - *p = (*p)->next; /* remove element, but don't move p */ - free_svalue(&ap->arg); - free_svalue(&ap->val); - free(ap); - total_mapping_size -= sizeof(struct apair); - r->card--; - } else { - p = &(*p)->next; /* step to next */ - } - pop_stack(); - } + for(p = &r->pairs[i]; *p;) { + push_svalue(&(*p)->val); + (void)call_var(1, fun); + if (sp->type == T_NUMBER && sp->u.number == 0) { + /* remove it from the list */ + struct apair *ap = *p; + *p = (*p)->next; /* remove element, but don't move p */ + free_svalue(&ap->arg); + free_svalue(&ap->val); + free(ap); + total_mapping_size -= sizeof(struct apair); + r->card--; + } else { + p = &(*p)->next; /* step to next */ + } + pop_stack(); + } } return r; } diff --git a/mapping.h b/mapping.h index 83058c1..72e38b1 100644 --- a/mapping.h +++ b/mapping.h @@ -1,17 +1,17 @@ struct apair { - struct apair *next; /* next pair in hashed at this value */ - struct svalue arg, val; /* index and value for this element */ - unsigned int hashval; /* cached hash value */ + struct apair *next; /* next pair in hashed at this value */ + struct svalue arg, val; /* index and value for this element */ + unsigned int hashval; /* cached hash value */ }; struct mapping { - unsigned int size; /* current size (no of pairs entries) */ - unsigned int ref; /* reference count */ - unsigned int card; /* number of elements in the mapping */ - unsigned int mcard; /* extend when card exceeds this value */ - struct apair **pairs; /* array of lists of elements */ + unsigned int size; /* current size (no of pairs entries) */ + unsigned int ref; /* reference count */ + unsigned int card; /* number of elements in the mapping */ + unsigned int mcard; /* extend when card exceeds this value */ + struct apair **pairs; /* array of lists of elements */ }; void free_mapping (struct mapping *); diff --git a/mstring.c b/mstring.c index 9b1b849..357145c 100644 --- a/mstring.c +++ b/mstring.c @@ -67,7 +67,7 @@ allocate_mstring(size_t len) { char *cp; if (len < 0 || len > MAX_STRING_SIZE) - error("Illegal string size.\n"); + error("Illegal string size.\n"); cp = (char *)xalloc(mstring_header + len + 1) + mstring_header; #ifdef DEBUG @@ -100,11 +100,11 @@ reference_mstring(char *cp) { #ifdef DEBUG if (mstring_magic(cp) != MSTRING_MAGIC) - fatal("Bad m-magic: %lx %x\n", mstring_magic(cp), MSTRING_MAGIC); + fatal("Bad m-magic: %lx %x\n", mstring_magic(cp), MSTRING_MAGIC); #endif if (mstring_count(cp) != 0) - mstring_count(cp)++; + mstring_count(cp)++; allocd_strings_malloced++; allocd_bytes_malloced += mstring_header + mstring_len(cp) + 1; @@ -117,22 +117,22 @@ free_mstring(char *cp) { #ifdef DEBUG if (mstring_magic(cp) != MSTRING_MAGIC) - fatal("Bad m-magic: %lx %x\n", mstring_magic(cp), MSTRING_MAGIC); + fatal("Bad m-magic: %lx %x\n", mstring_magic(cp), MSTRING_MAGIC); #endif if (mstring_count(cp) != 0) { - allocd_strings_malloced--; - allocd_bytes_malloced -= mstring_header + mstring_len(cp) + 1; - if (--mstring_count(cp) == 0) - { + allocd_strings_malloced--; + allocd_bytes_malloced -= mstring_header + mstring_len(cp) + 1; + if (--mstring_count(cp) == 0) + { #ifdef DEBUG - mstring_magic(cp) = 0; + mstring_magic(cp) = 0; #endif - num_distinct_strings_malloced--; - bytes_distinct_strings_malloced -= mstring_len(cp) + 1; - overhead_bytes_malloced -= mstring_header; - free(cp - mstring_header); - } + num_distinct_strings_malloced--; + bytes_distinct_strings_malloced -= mstring_len(cp) + 1; + overhead_bytes_malloced -= mstring_header; + free(cp - mstring_header); + } } } @@ -141,11 +141,11 @@ reference_sstring(char *cp) { #ifdef DEBUG if (sstring_magic(cp) != SSTRING_MAGIC) - fatal("Bad s-magic: %lx %x\n", sstring_magic(cp), SSTRING_MAGIC); + fatal("Bad s-magic: %lx %x\n", sstring_magic(cp), SSTRING_MAGIC); #endif if (sstring_count(cp) != 0) - sstring_count(cp)++; + sstring_count(cp)++; allocd_strings_shared++; allocd_bytes_shared += sstring_header + sstring_len(cp) + 1; @@ -164,25 +164,25 @@ find_sstring(char *cp) num_str_searches++; while (xp != NULL) { - search_len++; + search_len++; #ifdef DEBUG - if (sstring_magic(xp) != SSTRING_MAGIC) - fatal("Bad s-magic: %lx %x\n", sstring_magic(xp), SSTRING_MAGIC); + if (sstring_magic(xp) != SSTRING_MAGIC) + fatal("Bad s-magic: %lx %x\n", sstring_magic(xp), SSTRING_MAGIC); #endif - if (xp == cp || (*xp == *cp && strcmp(xp, cp) == 0)) - { - if (sstring_prev(xp) != NULL) { - sstring_next(sstring_prev(xp)) = sstring_next(xp); - if (sstring_next(xp) != NULL) - sstring_prev(sstring_next(xp)) = sstring_prev(xp); - sstring_prev(xp) = NULL; - sstring_next(xp) = sstring_table[hash]; - sstring_prev(sstring_table[hash]) = xp; - sstring_table[hash] = xp; - } - return xp; - } - xp = sstring_next(xp); + if (xp == cp || (*xp == *cp && strcmp(xp, cp) == 0)) + { + if (sstring_prev(xp) != NULL) { + sstring_next(sstring_prev(xp)) = sstring_next(xp); + if (sstring_next(xp) != NULL) + sstring_prev(sstring_next(xp)) = sstring_prev(xp); + sstring_prev(xp) = NULL; + sstring_next(xp) = sstring_table[hash]; + sstring_prev(sstring_table[hash]) = xp; + sstring_table[hash] = xp; + } + return xp; + } + xp = sstring_next(xp); } return NULL; @@ -200,29 +200,29 @@ make_sstring(const char *cp) num_str_searches++; while (xp != NULL) { - search_len++; + search_len++; #ifdef DEBUG - if (sstring_magic(xp) != SSTRING_MAGIC) - fatal("Bad s-magic: %lx %x\n", sstring_magic(xp), SSTRING_MAGIC); + if (sstring_magic(xp) != SSTRING_MAGIC) + fatal("Bad s-magic: %lx %x\n", sstring_magic(xp), SSTRING_MAGIC); #endif - if (xp == cp || (*xp == *cp && strcmp(xp, cp) == 0)) - { - if (sstring_prev(xp) != NULL) { - sstring_next(sstring_prev(xp)) = sstring_next(xp); - if (sstring_next(xp) != NULL) - sstring_prev(sstring_next(xp)) = sstring_prev(xp); - sstring_prev(xp) = NULL; - sstring_next(xp) = sstring_table[hash]; - sstring_prev(sstring_table[hash]) = xp; - sstring_table[hash] = xp; - } - return reference_sstring(xp); - } - xp = sstring_next(xp); + if (xp == cp || (*xp == *cp && strcmp(xp, cp) == 0)) + { + if (sstring_prev(xp) != NULL) { + sstring_next(sstring_prev(xp)) = sstring_next(xp); + if (sstring_next(xp) != NULL) + sstring_prev(sstring_next(xp)) = sstring_prev(xp); + sstring_prev(xp) = NULL; + sstring_next(xp) = sstring_table[hash]; + sstring_prev(sstring_table[hash]) = xp; + sstring_table[hash] = xp; + } + return reference_sstring(xp); + } + xp = sstring_next(xp); } len = strlen(cp); if (len < 0 || len > MAX_STRING_SIZE) - error("Illegal string size.\n"); + error("Illegal string size.\n"); xp = (char *)xalloc(sstring_header + len + 1) + sstring_header; #ifdef DEBUG @@ -231,7 +231,7 @@ make_sstring(const char *cp) sstring_prev(xp) = NULL; sstring_next(xp) = sstring_table[hash]; if (sstring_next(xp) != NULL) - sstring_prev(sstring_next(xp)) = xp; + sstring_prev(sstring_next(xp)) = xp; sstring_hash(xp) = hash; sstring_count(xp) = 1; sstring_len(xp) = len; @@ -251,29 +251,29 @@ free_sstring(char *cp) { #ifdef DEBUG if (sstring_magic(cp) != SSTRING_MAGIC) - fatal("Bad s-magic: %lx %x\n", sstring_magic(cp), SSTRING_MAGIC); + fatal("Bad s-magic: %lx %x\n", sstring_magic(cp), SSTRING_MAGIC); #endif if (sstring_count(cp) != 0) { - allocd_strings_shared--; - allocd_bytes_shared -= sstring_header + sstring_len(cp) + 1; - - if (--sstring_count(cp) == 0) - { - if (sstring_prev(cp) != NULL) - sstring_next(sstring_prev(cp)) = sstring_next(cp); - else - sstring_table[sstring_hash(cp)] = sstring_next(cp); - if (sstring_next(cp) != NULL) - sstring_prev(sstring_next(cp)) = sstring_prev(cp); + allocd_strings_shared--; + allocd_bytes_shared -= sstring_header + sstring_len(cp) + 1; + + if (--sstring_count(cp) == 0) + { + if (sstring_prev(cp) != NULL) + sstring_next(sstring_prev(cp)) = sstring_next(cp); + else + sstring_table[sstring_hash(cp)] = sstring_next(cp); + if (sstring_next(cp) != NULL) + sstring_prev(sstring_next(cp)) = sstring_prev(cp); #ifdef DEBUG - sstring_magic(cp) = 0; + sstring_magic(cp) = 0; #endif - num_distinct_strings_shared--; - bytes_distinct_strings_shared -= sstring_len(cp) + 1; - overhead_bytes_shared -= sstring_header; - free(cp - sstring_header); - } + num_distinct_strings_shared--; + bytes_distinct_strings_shared -= sstring_len(cp) + 1; + overhead_bytes_shared -= sstring_header; + free(cp - sstring_header); + } } } @@ -284,16 +284,16 @@ multiply_string(char *str, long long factor) long long size, newsize, offset; if (factor <= 0 || (size = strlen(str)) == 0) { - return make_mstring(""); + return make_mstring(""); } if (factor > MAX_STRING_SIZE) - error("Illegal string size.\n"); + error("Illegal string size.\n"); newsize = size * factor; result = allocate_mstring(newsize); for (offset = 0; offset < newsize; offset += size) { - strcpy(result + offset, str); + strcpy(result + offset, str); } return result; } @@ -315,21 +315,21 @@ add_string_status(char *debinf) */ for (i = 0; i < HTABLE_SIZE; i++) { - n = 0; - for (cp = sstring_table[i]; cp != NULL; cp = sstring_next(cp)) - n++; - if (min > n) - min = n; - if (max < n) - max = n; - sum1 += n; - sum2 += n * n; + n = 0; + for (cp = sstring_table[i]; cp != NULL; cp = sstring_next(cp)) + n++; + if (min > n) + min = n; + if (max < n) + max = n; + sum1 += n; + sum2 += n * n; } if (sum1 == 0) { - min = 0; - max = 0; + min = 0; + max = 0; } /* @@ -341,49 +341,49 @@ add_string_status(char *debinf) * Compute the standard deviation. */ stddev = sqrt(((double)sum2 - - (((double)sum1 * (double)sum1) / HTABLE_SIZE)) / HTABLE_SIZE); + (((double)sum1 * (double)sum1) / HTABLE_SIZE)) / HTABLE_SIZE); (void)strcat(debinf, "\nShared string hash table:\n"); (void)strcat(debinf, "------------------------- Strings Bytes\n"); (void)sprintf(debinf + strlen(debinf), "Total asked for\t\t%12d %12ld\n", - allocd_strings_shared, allocd_bytes_shared); + allocd_strings_shared, allocd_bytes_shared); (void)sprintf(debinf + strlen(debinf), "Actually used\t\t%12d %12ld\n", - num_distinct_strings_shared, - bytes_distinct_strings_shared + overhead_bytes_shared); + num_distinct_strings_shared, + bytes_distinct_strings_shared + overhead_bytes_shared); (void)sprintf(debinf + strlen(debinf), - "Space actually required/total string bytes %6.2f%%\n", - (bytes_distinct_strings_shared + overhead_bytes_shared)*100.0 / - (double)allocd_bytes_shared); + "Space actually required/total string bytes %6.2f%%\n", + (bytes_distinct_strings_shared + overhead_bytes_shared)*100.0 / + (double)allocd_bytes_shared); (void)sprintf(debinf + strlen(debinf), - "Searches : %12lld Average search: %7.3f\n", - num_str_searches, - (double)search_len / (double)num_str_searches); + "Searches : %12lld Average search: %7.3f\n", + num_str_searches, + (double)search_len / (double)num_str_searches); (void)sprintf(debinf + strlen(debinf), - "Hash size : %12d\n", HTABLE_SIZE); + "Hash size : %12d\n", HTABLE_SIZE); (void)sprintf(debinf + strlen(debinf), - "Minimum depth: %12d Average depth : %7.3f\n", - min, mean); + "Minimum depth: %12d Average depth : %7.3f\n", + min, mean); (void)sprintf(debinf + strlen(debinf), - "Maximum depth: %12d Std. deviation: %7.3f\n", - max, stddev); + "Maximum depth: %12d Std. deviation: %7.3f\n", + max, stddev); (void)strcat(debinf, "\nMalloced string table:\n"); (void)strcat(debinf, "----------------------\t Strings Bytes\n"); (void)sprintf(debinf + strlen(debinf), "Total asked for\t\t%12d %12ld\n", - allocd_strings_malloced, allocd_bytes_malloced); + allocd_strings_malloced, allocd_bytes_malloced); (void)sprintf(debinf + strlen(debinf), "Actually used\t\t%12d %12ld\n", - num_distinct_strings_malloced, - bytes_distinct_strings_malloced + overhead_bytes_malloced); + num_distinct_strings_malloced, + bytes_distinct_strings_malloced + overhead_bytes_malloced); (void)sprintf(debinf + strlen(debinf), - "Space actually required/total string bytes %6.2f%%\n", - (bytes_distinct_strings_malloced + overhead_bytes_malloced)*100.0 / - (double)allocd_bytes_malloced); + "Space actually required/total string bytes %6.2f%%\n", + (bytes_distinct_strings_malloced + overhead_bytes_malloced)*100.0 / + (double)allocd_bytes_malloced); } #ifdef DEBUG @@ -396,17 +396,17 @@ dump_sstrings(void) int i; if ((fp = fopen("SSTRING_DUMP", "w")) == NULL) - return; + return; for (i = 0; i < HTABLE_SIZE; i++) { - str = sstring_table[i]; - while (str) { - if (sstring_magic(str) != SSTRING_MAGIC) - fatal("Bad s-magic: %lx %x\n", sstring_magic(str), SSTRING_MAGIC); - len = sstring_len(str); - (void)fwrite(&len, sizeof(len), 1, fp); - (void)fwrite(str, sizeof(char), strlen(str) + 1, fp); - str = sstring_next(str); - } + str = sstring_table[i]; + while (str) { + if (sstring_magic(str) != SSTRING_MAGIC) + fatal("Bad s-magic: %lx %x\n", sstring_magic(str), SSTRING_MAGIC); + len = sstring_len(str); + (void)fwrite(&len, sizeof(len), 1, fp); + (void)fwrite(str, sizeof(char), strlen(str) + 1, fp); + str = sstring_next(str); + } } (void)fclose(fp); } @@ -419,6 +419,6 @@ remove_string_hash() int i; for (i = 0 ; i < HTABLE_SIZE ; i++) - sstring_table[i] = NULL; + sstring_table[i] = NULL; } #endif /* DEALLOCATE_MEMORY_AT_SHUTDOWN */ diff --git a/mstring.h b/mstring.h index 9a2c2b0..f879493 100644 --- a/mstring.h +++ b/mstring.h @@ -35,29 +35,29 @@ struct mstring_hdr { #ifdef DEBUG - uint64_t magic; + uint64_t magic; #endif - uint32_t length; - uint16_t count; + uint32_t length; + uint16_t count; }; -#define mstring_header \ - sizeof (struct mstring_hdr) +#define mstring_header \ + sizeof (struct mstring_hdr) #ifdef DEBUG -#define MSTRING_MAGIC 0x12311943 +#define MSTRING_MAGIC 0x12311943 -#define mstring_magic(cp) \ - (((struct mstring_hdr *)((char *)(cp) - mstring_header))->magic) +#define mstring_magic(cp) \ + (((struct mstring_hdr *)((char *)(cp) - mstring_header))->magic) #endif -#define mstring_len(cp) \ - (((struct mstring_hdr *)((char *)(cp) - mstring_header))->length) +#define mstring_len(cp) \ + (((struct mstring_hdr *)((char *)(cp) - mstring_header))->length) -#define mstring_count(cp) \ - (((struct mstring_hdr *)((char *)(cp) - mstring_header))->count) +#define mstring_count(cp) \ + (((struct mstring_hdr *)((char *)(cp) - mstring_header))->count) char *allocate_mstring(size_t); char *make_mstring(const char *); @@ -66,48 +66,48 @@ void free_mstring(char *); struct sstring_hdr { #ifdef DEBUG - uint64_t magic; + uint64_t magic; #endif - char *prev; - char *next; - uint32_t length; - uint16_t count; - uint32_t hash; + char *prev; + char *next; + uint32_t length; + uint16_t count; + uint32_t hash; }; -#define sstring_header \ - sizeof (struct sstring_hdr) +#define sstring_header \ + sizeof (struct sstring_hdr) #ifdef DEBUG -#define SSTRING_MAGIC 0x04301963 +#define SSTRING_MAGIC 0x04301963 -#define sstring_magic(cp) \ - (((struct sstring_hdr *)((char *)(cp) - sstring_header))->magic) +#define sstring_magic(cp) \ + (((struct sstring_hdr *)((char *)(cp) - sstring_header))->magic) #endif -#define sstring_prev(cp) \ - (((struct sstring_hdr *)((char *)(cp) - sstring_header))->prev) +#define sstring_prev(cp) \ + (((struct sstring_hdr *)((char *)(cp) - sstring_header))->prev) -#define sstring_next(cp) \ - (((struct sstring_hdr *)((char *)(cp) - sstring_header))->next) +#define sstring_next(cp) \ + (((struct sstring_hdr *)((char *)(cp) - sstring_header))->next) -#define sstring_len(cp) \ - (((struct sstring_hdr *)((char *)(cp) - sstring_header))->length) +#define sstring_len(cp) \ + (((struct sstring_hdr *)((char *)(cp) - sstring_header))->length) -#define sstring_count(cp) \ - (((struct sstring_hdr *)((char *)(cp) - sstring_header))->count) +#define sstring_count(cp) \ + (((struct sstring_hdr *)((char *)(cp) - sstring_header))->count) -#define sstring_hash(cp) \ - (((struct sstring_hdr *)((char *)(cp) - sstring_header))->hash) +#define sstring_hash(cp) \ + (((struct sstring_hdr *)((char *)(cp) - sstring_header))->hash) char *reference_sstring(char *); char *make_sstring(const char *); void free_sstring(char *); char *find_sstring(char *); -#define HASH_SSTRING(cp) (hash_string(cp) % HTABLE_SIZE) +#define HASH_SSTRING(cp) (hash_string(cp) % HTABLE_SIZE) #ifdef DEBUG void dump_sstrings(void); diff --git a/mudstat.c b/mudstat.c index fade1cc..a96ba62 100644 --- a/mudstat.c +++ b/mudstat.c @@ -16,27 +16,27 @@ #define MUDSTAT #include "mudstat.h" -#ifdef RUSAGE /* Defined in config.h */ +#ifdef RUSAGE /* Defined in config.h */ #include #endif -int num_move, /* Number of move_object() */ - num_mcall, /* Number of calls to master ob */ - num_fileread, /* Number of file reads */ - num_filewrite, /* Number of file writes */ - num_compile; /* Number of compiles */ +int num_move, /* Number of move_object() */ + num_mcall, /* Number of calls to master ob */ + num_fileread, /* Number of file reads */ + num_filewrite, /* Number of file writes */ + num_compile; /* Number of compiles */ -static long mch_t1; +static long mch_t1; static struct tms tms1; -static int num_pr = 0, - ms_eval_lim, /* Low limit for logging eval cost */ - ms_time_lim, /* Low limit for logging eval time */ - ms_active = 0; /* True if logging active */ +static int num_pr = 0, + ms_eval_lim, /* Low limit for logging eval cost */ + ms_time_lim, /* Low limit for logging eval time */ + ms_active = 0; /* True if logging active */ static void mark_millitime(void); extern int s_flag; - + /* * Set active / inactive and parameters */ @@ -50,22 +50,22 @@ mudstatus_set(int active, int eval_lim, int time_lim) if (active) { - s_flag = 1; - if ((mstat = fopen(MUDSTAT_FILE, "a")) != NULL) - { - (void)fprintf(mstat,"\n%-35s (%5.2f) %8d\n", - "------ ON, Limits:", tifl, eval_lim); - (void)fclose(mstat); - } + s_flag = 1; + if ((mstat = fopen(MUDSTAT_FILE, "a")) != NULL) + { + (void)fprintf(mstat,"\n%-35s (%5.2f) %8d\n", + "------ ON, Limits:", tifl, eval_lim); + (void)fclose(mstat); + } } else { - if (s_flag && ((mstat = fopen(MUDSTAT_FILE,"a")) != NULL)) - { - (void)fprintf(mstat,"\n%-35s\n", "------ OFF"); - (void)fclose(mstat); - } - s_flag = 0; + if (s_flag && ((mstat = fopen(MUDSTAT_FILE,"a")) != NULL)) + { + (void)fprintf(mstat,"\n%-35s\n", "------ OFF"); + (void)fclose(mstat); + } + s_flag = 0; } ms_eval_lim = ((eval_lim >= 0) ? eval_lim : MUDSTAT_LOGEVAL); ms_time_lim = ((time_lim >= 0) ? time_lim : MUDSTAT_LOGTIME); @@ -81,10 +81,10 @@ mark_millitime() static struct rusage rus; if (getrusage(RUSAGE_SELF, &rus) >= 0) { - /* Time in millisecs - */ - mch_t1 = rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000 + - rus.ru_stime.tv_sec * 1000 + rus.ru_stime.tv_usec / 1000; + /* Time in millisecs + */ + mch_t1 = rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000 + + rus.ru_stime.tv_sec * 1000 + rus.ru_stime.tv_usec / 1000; } #endif @@ -102,7 +102,7 @@ get_millitime() (void)times(&tms2); mtime = (tms2.tms_utime - tms1.tms_utime + - tms2.tms_stime - tms1.tms_stime) / 60.0; + tms2.tms_stime - tms1.tms_stime) / 60.0; return (int)(mtime * 100.0); } @@ -119,12 +119,12 @@ get_processtime() if (getrusage(RUSAGE_SELF, &rus) >= 0) { - /* Time in millisecs - */ - mch_t2 = rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000 + - rus.ru_stime.tv_sec * 1000 + rus.ru_stime.tv_usec / 1000; + /* Time in millisecs + */ + mch_t2 = rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000 + + rus.ru_stime.tv_sec * 1000 + rus.ru_stime.tv_usec / 1000; } else - return 0; + return 0; return (int)(mch_t2 - mch_t1); } #else @@ -149,30 +149,30 @@ print_mudstatus(char *activity, int eval, int timem, int tiproc) float tifl, tifl2; if (!ms_active) - return; + return; if (timem < ms_time_lim && eval < ms_eval_lim) - return; + return; tifl = timem / 100.0; tifl2 = tiproc / 1000.0; if ((mstat = fopen(MUDSTAT_FILE,"a")) != NULL) { - if (!num_pr) - (void)fprintf(mstat,"\n%-35s (%11s) %8s %3s %3s %3s %3s %3s\n", - "Activity", "time:cpu", "evalcost", "cp", "mc", - "rd", "wr", "mv"); - num_pr = (num_pr + 1) % 10; - if (strlen(activity) < 35U) - (void)fprintf(mstat,"%-35s (%5.2f:%5.2f) %8d %3d %3d %3d %3d %3d\n", - activity, tifl, tifl2, eval, num_compile, num_mcall, - num_fileread, num_filewrite, num_move); - else - (void)fprintf(mstat,"%s\n%-35s (%5.2f:%5.2f) %8d %3d %3d %3d %3d %3d\n", - activity, "", tifl, tifl2, eval, num_compile, num_mcall, - num_fileread, num_filewrite, num_move); - - (void)fclose(mstat); + if (!num_pr) + (void)fprintf(mstat,"\n%-35s (%11s) %8s %3s %3s %3s %3s %3s\n", + "Activity", "time:cpu", "evalcost", "cp", "mc", + "rd", "wr", "mv"); + num_pr = (num_pr + 1) % 10; + if (strlen(activity) < 35U) + (void)fprintf(mstat,"%-35s (%5.2f:%5.2f) %8d %3d %3d %3d %3d %3d\n", + activity, tifl, tifl2, eval, num_compile, num_mcall, + num_fileread, num_filewrite, num_move); + else + (void)fprintf(mstat,"%s\n%-35s (%5.2f:%5.2f) %8d %3d %3d %3d %3d %3d\n", + activity, "", tifl, tifl2, eval, num_compile, num_mcall, + num_fileread, num_filewrite, num_move); + + (void)fclose(mstat); } } diff --git a/mudstat.h b/mudstat.h index 15d5c02..a91589f 100644 --- a/mudstat.h +++ b/mudstat.h @@ -2,15 +2,15 @@ * These are some statistics variables that are used if we run -S mode */ -extern int num_move, /* Number of move_object() */ - num_mcall, /* Number of calls to master ob */ - num_fileread, /* Number of file reads */ - num_filewrite, /* Number of file writes */ - num_compile; /* Number of compiles */ +extern int num_move, /* Number of move_object() */ + num_mcall, /* Number of calls to master ob */ + num_fileread, /* Number of file reads */ + num_filewrite, /* Number of file writes */ + num_compile; /* Number of compiles */ -#define MUDSTAT_FILE "MUDstatistics" -#define MUDSTAT_LOGTIME 50 -#define MUDSTAT_LOGEVAL 25000 +#define MUDSTAT_FILE "MUDstatistics" +#define MUDSTAT_LOGTIME 50 +#define MUDSTAT_LOGEVAL 25000 /* * Prototypes diff --git a/ndesc.c b/ndesc.c index cc4e2ab..dd66aab 100644 --- a/ndesc.c +++ b/ndesc.c @@ -87,9 +87,9 @@ nd_append(ndesc_t *nd) { nd->nd_next = NULL; if ((nd->nd_prev = nd_tail) != NULL) - nd->nd_prev->nd_next = nd; + nd->nd_prev->nd_next = nd; else - nd_head = nd; + nd_head = nd; nd_tail = nd; } @@ -101,14 +101,14 @@ static void nd_remove(ndesc_t *nd) { if (nd->nd_next != NULL) - nd->nd_next->nd_prev = nd->nd_prev; + nd->nd_next->nd_prev = nd->nd_prev; else - nd_tail = nd->nd_prev; + nd_tail = nd->nd_prev; if (nd->nd_prev != NULL) - nd->nd_prev->nd_next = nd->nd_next; + nd->nd_prev->nd_next = nd->nd_next; else - nd_head = nd->nd_next; + nd_head = nd->nd_next; } /* @@ -281,7 +281,7 @@ nd_shutdown(void) { next = nd->nd_next; - if (nd->nd_sfunc != NULL) - (*nd->nd_sfunc)(nd, nd->nd_vp); + if (nd->nd_sfunc != NULL) + (*nd->nd_sfunc)(nd, nd->nd_vp); } } diff --git a/ndesc.h b/ndesc.h index a3eb166..844de3f 100644 --- a/ndesc.h +++ b/ndesc.h @@ -32,7 +32,7 @@ #define _NDESC_H typedef struct ndesc { int nd_fd; - int nd_mask; + int nd_mask; int nd_poll; void (*nd_rfunc)(struct ndesc *, void *); void (*nd_wfunc)(struct ndesc *, void *); @@ -43,10 +43,10 @@ typedef struct ndesc { struct ndesc * nd_prev; } ndesc_t; -#define ND_R 0x01 -#define ND_W 0x02 -#define ND_X 0x04 -#define ND_MASK 0x07 +#define ND_R 0x01 +#define ND_W 0x02 +#define ND_X 0x04 +#define ND_MASK 0x07 struct timeval; diff --git a/net.c b/net.c index 6d86418..f545f3b 100644 --- a/net.c +++ b/net.c @@ -46,7 +46,7 @@ #include "nqueue.h" #ifndef IPTOS_LOWDELAY -#define IPTOS_LOWDELAY 0x10 +#define IPTOS_LOWDELAY 0x10 #endif /* @@ -69,7 +69,7 @@ enable_keepalive(int s) int keepalive = 1; if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *)&keepalive, sizeof (keepalive)) == -1) - fatal("enable_keepalive: setsockopt() errno = %d.\n", errno); + fatal("enable_keepalive: setsockopt() errno = %d.\n", errno); } /* @@ -81,7 +81,7 @@ enable_reuseaddr(int s) int reuse = 1; if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof (reuse)) == -1) - fatal("enable_reuseaddr: setsockopt() errno = %d.\n", errno); + fatal("enable_reuseaddr: setsockopt() errno = %d.\n", errno); } /* @@ -93,7 +93,7 @@ enable_oobinline(int s) int oobinline = 1; if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&oobinline, sizeof (oobinline)) == -1) - fatal("enable_oobinline: setsockopt() errno = %d.\n", errno); + fatal("enable_oobinline: setsockopt() errno = %d.\n", errno); } /* @@ -124,7 +124,7 @@ enable_lowdelay(int s) // should not crash the mud so regularly. Outcommented until a proper fix // can be installed. Mercade. // if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *)&tos, sizeof (tos)) == -1) -// fatal("enable_lowdelay: setsockopt() errno = %d.\n", errno); +// fatal("enable_lowdelay: setsockopt() errno = %d.\n", errno); #endif } @@ -149,8 +149,8 @@ at_mark(int fd) if (ioctl(fd, SIOCATMARK, &atmark) != -1) { - if (atmark) - return 1; + if (atmark) + return 1; } return 0; diff --git a/nqueue.c b/nqueue.c index 26acf22..064d2d9 100644 --- a/nqueue.c +++ b/nqueue.c @@ -205,21 +205,21 @@ nq_puts(nqueue_t *nq, u_char *cp) while (len > 0) { - if (nq->nq_rptr > nq->nq_wptr) - size = nq->nq_rptr - nq->nq_wptr; - else - size = nq->nq_size - nq->nq_wptr; + if (nq->nq_rptr > nq->nq_wptr) + size = nq->nq_rptr - nq->nq_wptr; + else + size = nq->nq_size - nq->nq_wptr; - if (size > len) - size = len; + if (size > len) + size = len; - memcpy(nq_wptr(nq), cp, size); + memcpy(nq_wptr(nq), cp, size); - nq->nq_len += size, nq->nq_wptr += size; - if (nq->nq_wptr == nq->nq_size) - nq->nq_wptr = 0; + nq->nq_len += size, nq->nq_wptr += size; + if (nq->nq_wptr == nq->nq_size) + nq->nq_wptr = 0; - cp += size, len -= size; + cp += size, len -= size; } } @@ -247,20 +247,20 @@ nq_recv(nqueue_t *nq, int fd, u_int *uip) int len, cc; if (nq->nq_rptr > nq->nq_wptr) - len = nq->nq_rptr - nq->nq_wptr; + len = nq->nq_rptr - nq->nq_wptr; else - len = nq->nq_size - nq->nq_wptr; + len = nq->nq_size - nq->nq_wptr; cc = recv(fd, nq_wptr(nq), len, 0); if (cc > 0) { - nq->nq_len += cc, nq->nq_wptr += cc; - if (nq->nq_wptr == nq->nq_size) - nq->nq_wptr = 0; + nq->nq_len += cc, nq->nq_wptr += cc; + if (nq->nq_wptr == nq->nq_size) + nq->nq_wptr = 0; - if (uip != NULL) - *uip += cc; + if (uip != NULL) + *uip += cc; } return cc; @@ -276,25 +276,25 @@ nq_send(nqueue_t *nq, int fd, u_int *uip) while (nq->nq_len > 0) { - len = nq->nq_size - nq->nq_rptr; + len = nq->nq_size - nq->nq_rptr; - if (len > nq->nq_len) - len = nq->nq_len; + if (len > nq->nq_len) + len = nq->nq_len; - cc = send(fd, nq_rptr(nq), len, 0); + cc = send(fd, nq_rptr(nq), len, 0); - if (cc > 0) - { - nq->nq_len -= cc, nq->nq_rptr += cc; - if (nq->nq_rptr == nq->nq_size) - nq->nq_rptr = 0; + if (cc > 0) + { + nq->nq_len -= cc, nq->nq_rptr += cc; + if (nq->nq_rptr == nq->nq_size) + nq->nq_rptr = 0; - if (uip != NULL) - *uip += cc; - } + if (uip != NULL) + *uip += cc; + } - if (cc != len) - break; + if (cc != len) + break; } return cc; diff --git a/nqueue.h b/nqueue.h index 2c21e90..7a3ffb3 100644 --- a/nqueue.h +++ b/nqueue.h @@ -32,10 +32,10 @@ #define _NQUEUE_H typedef struct { - u_short nq_size; - u_short nq_len; - u_short nq_rptr; - u_short nq_wptr; + u_short nq_size; + u_short nq_len; + u_short nq_rptr; + u_short nq_wptr; } nqueue_t; void nq_init(nqueue_t *); diff --git a/object.c b/object.c index 5d733ef..ac4278f 100644 --- a/object.c +++ b/object.c @@ -55,20 +55,20 @@ add_strbuf(struct savebuf *sbuf, char *str) size_t len = strlen(str); if (sbuf->f) { - fwrite(str, len, 1, sbuf->f); - return; + fwrite(str, len, 1, sbuf->f); + return; } if (sbuf->size + len + 1 > sbuf->max_size) { - char *nbuf; - size_t nsize; - nsize = ((len + sbuf->size) / STRBUFSIZE + 1) * STRBUFSIZE; - nbuf = xalloc(nsize); - (void)memcpy(nbuf, sbuf->buf, sbuf->size); - sbuf->max_size = nsize; - free(sbuf->buf); - sbuf->buf = nbuf; + char *nbuf; + size_t nsize; + nsize = ((len + sbuf->size) / STRBUFSIZE + 1) * STRBUFSIZE; + nbuf = xalloc(nsize); + (void)memcpy(nbuf, sbuf->buf, sbuf->size); + sbuf->max_size = nsize; + free(sbuf->buf); + sbuf->buf = nbuf; } (void)strcpy(&(sbuf->buf[sbuf->size]), str); sbuf->size += len; @@ -88,23 +88,23 @@ save_string(struct savebuf *f, char *s) add_strbuf(f, "\""); while (*s) { - switch (*s) - { - case '"': - add_strbuf(f, "\\\""); - break; - case '\\': - add_strbuf(f, "\\\\"); - break; - case '\n': - add_strbuf(f, "\\n"); - break; - default: - buf[0] = *s; - add_strbuf(f, buf); - break; - } - s++; + switch (*s) + { + case '"': + add_strbuf(f, "\\\""); + break; + case '\\': + add_strbuf(f, "\\\\"); + break; + case '\n': + add_strbuf(f, "\\n"); + break; + default: + buf[0] = *s; + add_strbuf(f, buf); + break; + } + s++; } add_strbuf(f, "\""); @@ -121,8 +121,8 @@ save_array(struct savebuf *f, struct vector *v) add_strbuf(f, "({"); for (i = 0; i < v->size; i++) { - save_one(f, &v->item[i]); - add_strbuf(f,","); + save_one(f, &v->item[i]); + add_strbuf(f,","); } add_strbuf(f,"})"); } @@ -136,13 +136,13 @@ save_mapping(struct savebuf *f, struct mapping *m) add_strbuf(f, "(["); for (i = 0; i < m->size; i++) { - for(p = m->pairs[i]; p; p = p->next) - { - save_one(f, &p->arg); - add_strbuf(f,":"); - save_one(f, &p->val); - add_strbuf(f,","); - } + for(p = m->pairs[i]; p; p = p->next) + { + save_one(f, &p->arg); + add_strbuf(f,":"); + save_one(f, &p->val); + add_strbuf(f,","); + } } add_strbuf(f,"])"); } @@ -162,36 +162,36 @@ save_one(struct savebuf *f, struct svalue *v) switch(v->type) { case T_FLOAT: - (void)sprintf(buf,"#%a#", v->u.real); - add_strbuf(f, buf); - break; + (void)sprintf(buf,"#%a#", v->u.real); + add_strbuf(f, buf); + break; case T_NUMBER: - (void)sprintf(buf, "%lld", v->u.number); - add_strbuf(f, buf); - break; + (void)sprintf(buf, "%lld", v->u.number); + add_strbuf(f, buf); + break; case T_STRING: - save_string(f, v->u.string); - break; + save_string(f, v->u.string); + break; case T_POINTER: - save_array(f, v->u.vec); - break; + save_array(f, v->u.vec); + break; case T_MAPPING: - save_mapping(f, v->u.map); - break; + save_mapping(f, v->u.map); + break; case T_OBJECT: - (void)sprintf(buf, "$%d@", v->u.ob->created); - add_strbuf(f, buf); - add_strbuf(f, v->u.ob->name); - add_strbuf(f, "$"); + (void)sprintf(buf, "$%d@", v->u.ob->created); + add_strbuf(f, buf); + add_strbuf(f, v->u.ob->name); + add_strbuf(f, "$"); break; #if 0 case T_FUNCTION: - add_strbuf(f, "&FUNCTION&"); /* XXX function */ - break; + add_strbuf(f, "&FUNCTION&"); /* XXX function */ + break; #endif default: - add_strbuf(f, "0"); - break; + add_strbuf(f, "0"); + break; } depth--; @@ -213,11 +213,11 @@ void save_object(struct object *ob, char *file) /* struct svalue *v; */ if (ob->flags & O_DESTRUCTED) - return; + return; file = check_valid_path(file, ob, "save_object", 1); if (file == 0) - error("Illegal use of save_object()\n"); + error("Illegal use of save_object()\n"); len = strlen(file); name = tmpalloc(len + 2 + 1); @@ -231,9 +231,9 @@ void save_object(struct object *ob, char *file) (void)sprintf(tmp_name, "%s.tmp", name); f = fopen(tmp_name, "w"); if (s_flag) - num_filewrite++; + num_filewrite++; if (f == 0) { - error("Could not open %s for a save.\n", tmp_name); + error("Could not open %s for a save.\n", tmp_name); } failed = 0; @@ -244,41 +244,41 @@ void save_object(struct object *ob, char *file) for (j = 0; j < (int)ob->prog->num_inherited; j++) { - struct program *prog = ob->prog->inherit[j].prog; - if (ob->prog->inherit[j].type & TYPE_MOD_SECOND || - prog->num_variables == 0) - continue; - for (i = 0; i < (int)prog->num_variables; i++) { - struct svalue *v = - &ob->variables[i + ob->prog->inherit[j].variable_index_offset]; - - if (ob->prog->inherit[j].prog->variable_names[i].type & TYPE_MOD_STATIC) - continue; - if (v->type == T_NUMBER || v->type == T_STRING || v->type == T_POINTER - || v->type == T_MAPPING || v->type == T_OBJECT || v->type == T_FLOAT) { /* XXX function */ - add_strbuf(&sbuf, ob->prog->inherit[j].prog->variable_names[i].name); - add_strbuf(&sbuf, " "); - save_one(&sbuf, v); - add_strbuf(&sbuf, "\n"); - } - } + struct program *prog = ob->prog->inherit[j].prog; + if (ob->prog->inherit[j].type & TYPE_MOD_SECOND || + prog->num_variables == 0) + continue; + for (i = 0; i < (int)prog->num_variables; i++) { + struct svalue *v = + &ob->variables[i + ob->prog->inherit[j].variable_index_offset]; + + if (ob->prog->inherit[j].prog->variable_names[i].type & TYPE_MOD_STATIC) + continue; + if (v->type == T_NUMBER || v->type == T_STRING || v->type == T_POINTER + || v->type == T_MAPPING || v->type == T_OBJECT || v->type == T_FLOAT) { /* XXX function */ + add_strbuf(&sbuf, ob->prog->inherit[j].prog->variable_names[i].name); + add_strbuf(&sbuf, " "); + save_one(&sbuf, v); + add_strbuf(&sbuf, "\n"); + } + } } fwrite(sbuf.buf, sbuf.size, 1, f); free(sbuf.buf); if (fclose(f) == EOF) - failed = 1; + failed = 1; if (failed) { - (void)unlink(tmp_name); - error("Failed to save to file. Disk could be full.\n"); + (void)unlink(tmp_name); + error("Failed to save to file. Disk could be full.\n"); } if (rename(tmp_name, name) == -1) { - (void)unlink(tmp_name); - perror(name); - (void)printf("Failed to link %s to %s\n", tmp_name, name); - error("Failed to save object !\n"); + (void)unlink(tmp_name); + perror(name); + (void)printf("Failed to link %s to %s\n", tmp_name, name); + error("Failed to save object !\n"); } } @@ -293,32 +293,32 @@ m_save_object(struct object *ob) struct svalue s = const0; if (ob->flags & O_DESTRUCTED) - return allocate_map(0); /* XXX is this right /LA */ + return allocate_map(0); /* XXX is this right /LA */ ret = allocate_map((short)(ob->prog->num_variables + - ob->prog->inherit[ob->prog->num_inherited - 1]. - variable_index_offset)); + ob->prog->inherit[ob->prog->num_inherited - 1]. + variable_index_offset)); for (j = 0; j < (int)ob->prog->num_inherited; j++) { - struct program *prog = ob->prog->inherit[j].prog; - if (ob->prog->inherit[j].type & TYPE_MOD_SECOND || - prog->num_variables == 0) - continue; - for (i = 0; i < (int)prog->num_variables; i++) - { - struct svalue *v = - &ob->variables[i + ob->prog->inherit[j]. - variable_index_offset]; - - if (prog->variable_names[i].type & TYPE_MOD_STATIC) - continue; - free_svalue(&s); - s.type = T_STRING; - s.string_type = STRING_SSTRING; - s.u.string = make_sstring(prog->variable_names[i].name); - assign_svalue(get_map_lvalue(ret, &s, 1), v); - } + struct program *prog = ob->prog->inherit[j].prog; + if (ob->prog->inherit[j].type & TYPE_MOD_SECOND || + prog->num_variables == 0) + continue; + for (i = 0; i < (int)prog->num_variables; i++) + { + struct svalue *v = + &ob->variables[i + ob->prog->inherit[j]. + variable_index_offset]; + + if (prog->variable_names[i].type & TYPE_MOD_STATIC) + continue; + free_svalue(&s); + s.type = T_STRING; + s.string_type = STRING_SSTRING; + s.u.string = make_sstring(prog->variable_names[i].name); + assign_svalue(get_map_lvalue(ret, &s, 1), v); + } } free_svalue(&s); @@ -340,16 +340,16 @@ save_map(struct object *ob, struct mapping *map, char *file) file = check_valid_path(file, ob, "save_map", 1); if (file == 0) - error("Illegal use of save_map()\n"); + error("Illegal use of save_map()\n"); for (j = 0; j < map->size; j++) { - for (i = map->pairs[j]; i; i = i->next) { - if (i->arg.type != T_STRING) - error("Non-string index in mapping\n"); - if (strpbrk(i->arg.u.string, " \n\r\t\f\v\b") != NULL) - error("Mapping index cannot have whitespace\n"); - } + for (i = map->pairs[j]; i; i = i->next) { + if (i->arg.type != T_STRING) + error("Non-string index in mapping\n"); + if (strpbrk(i->arg.u.string, " \n\r\t\f\v\b") != NULL) + error("Mapping index cannot have whitespace\n"); + } } len = strlen(file); @@ -364,9 +364,9 @@ save_map(struct object *ob, struct mapping *map, char *file) (void)sprintf(tmp_name, "%s.tmp", name); f = fopen(tmp_name, "w"); if (s_flag) - num_filewrite++; + num_filewrite++; if (f == 0) { - error("Could not open %s for a save.\n", tmp_name); + error("Could not open %s for a save.\n", tmp_name); } failed = 0; @@ -377,36 +377,36 @@ save_map(struct object *ob, struct mapping *map, char *file) for (j = 0; j < map->size; j++) { - for (i = map->pairs[j]; i; i = i->next) { - struct svalue *v = - &i->val; - - if (i->arg.type != T_STRING) - continue; - if (v->type == T_NUMBER || v->type == T_STRING || v->type == T_POINTER - || v->type == T_MAPPING || v->type == T_OBJECT || v->type == T_FLOAT) { /* XXX function */ - add_strbuf(&sbuf, i->arg.u.string); - add_strbuf(&sbuf, " "); - save_one(&sbuf, v); - add_strbuf(&sbuf, "\n"); - } - } + for (i = map->pairs[j]; i; i = i->next) { + struct svalue *v = + &i->val; + + if (i->arg.type != T_STRING) + continue; + if (v->type == T_NUMBER || v->type == T_STRING || v->type == T_POINTER + || v->type == T_MAPPING || v->type == T_OBJECT || v->type == T_FLOAT) { /* XXX function */ + add_strbuf(&sbuf, i->arg.u.string); + add_strbuf(&sbuf, " "); + save_one(&sbuf, v); + add_strbuf(&sbuf, "\n"); + } + } } fwrite(sbuf.buf, sbuf.size, 1, f); free(sbuf.buf); if (fclose(f) == EOF) - failed = 1; + failed = 1; if (failed) { - (void)unlink(tmp_name); - error("Failed to save to file. Disk could be full.\n"); + (void)unlink(tmp_name); + error("Failed to save to file. Disk could be full.\n"); } if (rename(tmp_name, name) == -1) { - (void)unlink(tmp_name); - perror(name); - (void)printf("Failed to link %s to %s\n", tmp_name, name); - error("Failed to save mapping !\n"); + (void)unlink(tmp_name); + perror(name); + (void)printf("Failed to link %s to %s\n", tmp_name, name); + error("Failed to save mapping !\n"); } } @@ -438,46 +438,46 @@ restore_array(char **str) tmp = (struct svalue *)xalloc(nmax * sizeof(struct svalue)); for(k = 0; k < nmax; k++) - tmp[k] = const0; + tmp[k] = const0; i = 0; for(;;) { - if (**str == '}') - { - if (*++*str == ')') - { - struct vector *v; - - ++*str; - v = allocate_array(i); - (void)memcpy((char *)&v->item[0], (char *)tmp, sizeof(struct svalue) * i); - free(tmp); - return v; - } - else - break; - } - else - { - if (i >= nmax) - { - struct svalue *ntmp = (struct svalue *)xalloc(nmax * 2 * sizeof(struct svalue)); - (void)memcpy((char *)ntmp, (char *)tmp, sizeof(struct svalue) * nmax); - free(tmp); - tmp = ntmp; - nmax *= 2; - for(k = i; k < nmax; k++) - tmp[k] = const0; - } - if (!restore_one(&tmp[i++], str)) - break; - if (*(*str)++ != ',') - break; - } - } - for (i--; i >= 0; i--) - free_svalue(&(tmp[i])); - free(tmp); + if (**str == '}') + { + if (*++*str == ')') + { + struct vector *v; + + ++*str; + v = allocate_array(i); + (void)memcpy((char *)&v->item[0], (char *)tmp, sizeof(struct svalue) * i); + free(tmp); + return v; + } + else + break; + } + else + { + if (i >= nmax) + { + struct svalue *ntmp = (struct svalue *)xalloc(nmax * 2 * sizeof(struct svalue)); + (void)memcpy((char *)ntmp, (char *)tmp, sizeof(struct svalue) * nmax); + free(tmp); + tmp = ntmp; + nmax *= 2; + for(k = i; k < nmax; k++) + tmp[k] = const0; + } + if (!restore_one(&tmp[i++], str)) + break; + if (*(*str)++ != ',') + break; + } + } + for (i--; i >= 0; i--) + free_svalue(&(tmp[i])); + free(tmp); return 0; } @@ -489,34 +489,34 @@ restore_mapping(char **str) m = allocate_map(0); for(;;) { - if (**str == ']') - { - if (*++*str == ')') - { - ++*str; - return m; - } - else - break; - } - else - { - struct svalue arg, *val; - arg = const0; - if (!restore_one(&arg, str)) - break; - if (*(*str)++ != ':') - { - free_svalue(&arg); - break; - } - val = get_map_lvalue(m, &arg, 1); - free_svalue(&arg); - - if (!restore_one(val, str) || - *(*str)++ != ',') - break; - } + if (**str == ']') + { + if (*++*str == ')') + { + ++*str; + return m; + } + else + break; + } + else + { + struct svalue arg, *val; + arg = const0; + if (!restore_one(&arg, str)) + break; + if (*(*str)++ != ':') + { + free_svalue(&arg); + break; + } + val = get_map_lvalue(m, &arg, 1); + free_svalue(&arg); + + if (!restore_one(val, str) || + *(*str)++ != ',') + break; + } } free_mapping(m); return 0; @@ -531,45 +531,45 @@ restore_one(struct svalue *v, char **msp) s = *msp; switch(*s) { case '(': - switch(*++s) - { - case '[': - { - struct mapping *map; - s++; - map = restore_mapping(&s); - if (!map) { - return 0; - } - free_svalue(v); - v->type = T_MAPPING; - v->u.map = map; - } - break; - - case '{': - { - struct vector *vec; - s++; - vec = restore_array(&s); - if (!vec) { - return 0; - } - free_svalue(v); - v->type = T_POINTER; - v->u.vec = vec; - } - break; - - default: - return 0; - } - break; + switch(*++s) + { + case '[': + { + struct mapping *map; + s++; + map = restore_mapping(&s); + if (!map) { + return 0; + } + free_svalue(v); + v->type = T_MAPPING; + v->u.map = map; + } + break; + + case '{': + { + struct vector *vec; + s++; + vec = restore_array(&s); + if (!vec) { + return 0; + } + free_svalue(v); + v->type = T_POINTER; + v->u.vec = vec; + } + break; + + default: + return 0; + } + break; case '"': - for (p = s + 1, q = s; *p && *p != '"'; p++) - { - if (*p == '\\') { - switch (*++p) { + for (p = s + 1, q = s; *p && *p != '"'; p++) + { + if (*p == '\\') { + switch (*++p) { case '\0': /* string can't end with \ */ return 0; @@ -580,38 +580,38 @@ restore_one(struct svalue *v, char **msp) default: *q++ = *p; break; - } - } else { - /* Have to be able to restore old format... */ - if (*p == '\r') - *q++ = '\n'; - else - *q++ = *p; - } - } - *q = 0; - if (*p != '"') + } + } else { + /* Have to be able to restore old format... */ + if (*p == '\r') + *q++ = '\n'; + else + *q++ = *p; + } + } + *q = 0; + if (*p != '"') return 0; - free_svalue(v); - v->type = T_STRING; - v->string_type = STRING_SSTRING; - v->u.string = make_sstring(s); - s = p+1; - break; + free_svalue(v); + v->type = T_STRING; + v->string_type = STRING_SSTRING; + v->u.string = make_sstring(s); + s = p+1; + break; case '$': { - int ct; + int ct; struct object *ob; char name[1024]; char *b = strchr(s + 1,'$'); - *name = '\0'; + *name = '\0'; if (b == NULL) return 0; if (sscanf(s,"$%d@%[^$ \n\t]$",&ct,name) != 2) return 0; ob = find_object2(name); - free_svalue(v); + free_svalue(v); if (ob && ob->created == ct) { v->type = T_OBJECT; @@ -627,27 +627,27 @@ restore_one(struct svalue *v, char **msp) } break; case '#': - { - double f; - char *b = strchr(s + 1, '#'); - if (b == NULL) - return 0; + { + double f; + char *b = strchr(s + 1, '#'); + if (b == NULL) + return 0; f = strtod(s + 1, NULL); - free_svalue(v); - v->type = T_FLOAT; - v->u.real = f; - s = b + 1; - } - break; + free_svalue(v); + v->type = T_FLOAT; + v->u.real = f; + s = b + 1; + } + break; default: - if (!isdigit(*s) && *s != '-') - return 0; - free_svalue(v); - v->type = T_NUMBER; - v->u.number = atoll(s); - while(isdigit(*s) || *s == '-') - s++; - break; + if (!isdigit(*s) && *s != '-') + return 0; + free_svalue(v); + v->type = T_NUMBER; + v->u.number = atoll(s); + while(isdigit(*s) || *s == '-') + s++; + break; } *msp = s; return 1; @@ -664,64 +664,64 @@ restore_object(struct object *ob, char *file) int p; if (current_object != ob) - fatal("Bad argument to restore_object()\n"); + fatal("Bad argument to restore_object()\n"); if (ob->flags & O_DESTRUCTED) - return 0; + return 0; file = check_valid_path(file, ob, "restore_object", 0); if (file == 0) - error("Illegal use of restore_object()\n"); + error("Illegal use of restore_object()\n"); len = strlen(file); name = tmpalloc(len + 3); (void)strcpy(name, file); if (name[len-2] == '.' && name[len-1] == 'c') - name[len-1] = 'o'; + name[len-1] = 'o'; else - (void)strcat(name, ".o"); + (void)strcat(name, ".o"); f = fopen(name, "r"); if (s_flag) - num_fileread++; + num_fileread++; if (!f || fstat(fileno(f), &st) == -1) { - if (f) - (void)fclose(f); - return 0; + if (f) + (void)fclose(f); + return 0; } if (st.st_size == 0) { - (void)fclose(f); - return 0; + (void)fclose(f); + return 0; } buff = xalloc((size_t)st.st_size + 1); current_object = ob; for (;;) { - struct svalue *v; - - if (fgets(buff, (int)st.st_size + 1, f) == 0) - break; - /* Remember that we have a newline at end of buff ! */ - space = strchr(buff, ' '); - if (space == 0 || space - buff >= sizeof (var)) { - (void)fclose(f); - free(buff); - error("Illegal format when restoring %s.\n", file); - } - (void)strncpy(var, buff, (size_t)(space - buff)); - var[space - buff] = '\0'; - p = find_status(ob->prog, var, TYPE_MOD_STATIC); - if (p == -1) - continue; - v = &ob->variables[p]; - space++; - if (!restore_one(v, &space)) { - (void)fclose(f); - free(buff); - error("Illegal format when restoring %s from %s.\n", var, file); - } + struct svalue *v; + + if (fgets(buff, (int)st.st_size + 1, f) == 0) + break; + /* Remember that we have a newline at end of buff ! */ + space = strchr(buff, ' '); + if (space == 0 || space - buff >= sizeof (var)) { + (void)fclose(f); + free(buff); + error("Illegal format when restoring %s.\n", file); + } + (void)strncpy(var, buff, (size_t)(space - buff)); + var[space - buff] = '\0'; + p = find_status(ob->prog, var, TYPE_MOD_STATIC); + if (p == -1) + continue; + v = &ob->variables[p]; + space++; + if (!restore_one(v, &space)) { + (void)fclose(f); + free(buff); + error("Illegal format when restoring %s from %s.\n", var, file); + } } current_object = save; if (d_flag & DEBUG_RESTORE) - debug_message("Object %s restored from %s.\n", ob->name, file); + debug_message("Object %s restored from %s.\n", ob->name, file); free(buff); (void)fclose(f); return 1; @@ -734,21 +734,21 @@ m_restore_object(struct object *ob, struct mapping *map) struct apair *j; if (ob->flags & O_DESTRUCTED) - return 0; + return 0; for (i = 0; i < map->size; i++) { - for (j = map->pairs[i]; j ; j = j->next) - { - if (j->arg.type != T_STRING) - continue; + for (j = map->pairs[i]; j ; j = j->next) + { + if (j->arg.type != T_STRING) + continue; - if ((p = find_status(ob->prog, j->arg.u.string, TYPE_MOD_STATIC)) - == -1) - continue; + if ((p = find_status(ob->prog, j->arg.u.string, TYPE_MOD_STATIC)) + == -1) + continue; - assign_svalue(&ob->variables[p], &j->val); - } + assign_svalue(&ob->variables[p], &j->val); + } } return 1; @@ -764,60 +764,60 @@ restore_map(struct object *ob, struct mapping *map, char *file) struct stat st; if (current_object != ob) - fatal("Bad argument to restore_map()\n"); + fatal("Bad argument to restore_map()\n"); if (ob->flags & O_DESTRUCTED) - return; + return; file = check_valid_path(file, ob, "restore_map", 0); if (file == 0) - error("Illegal use of restore_map()\n"); + error("Illegal use of restore_map()\n"); len = strlen(file); name = tmpalloc(len + 2 + 1); (void)strcpy(name, file); if (name[len-2] == '.' && name[len-1] == 'c') - name[len-1] = 'o'; + name[len-1] = 'o'; else - (void)strcat(name, ".o"); + (void)strcat(name, ".o"); f = fopen(name, "r"); if (s_flag) - num_fileread++; + num_fileread++; if (!f || fstat(fileno(f), &st) == -1) { - if (f) - (void)fclose(f); - return; + if (f) + (void)fclose(f); + return; } if (st.st_size == 0) { - (void)fclose(f); - return; + (void)fclose(f); + return; } buff = xalloc((size_t)st.st_size + 1); for (;;) { - struct svalue v; - - v.type = T_STRING; - v.string_type = STRING_SSTRING; - - if (fgets(buff, (int)st.st_size + 1, f) == 0) - break; - /* Remember that we have a newline at end of buff ! */ - space = strchr(buff, ' '); - if (space == 0) { - (void)fclose(f); - free(buff); - error("Illegal format when restoring %s.\n", file); - } - *space++ = '\0'; - v.u.string = make_sstring(buff); - - if (!restore_one(get_map_lvalue(map,&v,1), &space)) { - (void)fclose(f); - free(buff); - free_svalue(&v); - error("Illegal format when restoring %s.\n", file); - } - free_svalue(&v); + struct svalue v; + + v.type = T_STRING; + v.string_type = STRING_SSTRING; + + if (fgets(buff, (int)st.st_size + 1, f) == 0) + break; + /* Remember that we have a newline at end of buff ! */ + space = strchr(buff, ' '); + if (space == 0) { + (void)fclose(f); + free(buff); + error("Illegal format when restoring %s.\n", file); + } + *space++ = '\0'; + v.u.string = make_sstring(buff); + + if (!restore_one(get_map_lvalue(map,&v,1), &space)) { + (void)fclose(f); + free(buff); + free_svalue(&v); + error("Illegal format when restoring %s.\n", file); + } + free_svalue(&v); } current_object = save; free(buff); @@ -828,27 +828,27 @@ void free_object(struct object *ob, char *from) { if (d_flag & DEBUG_OB_REF) - (void)printf("Subtr ref to ob %s: %d (%s)\n", ob->name, - ob->ref, from); + (void)printf("Subtr ref to ob %s: %d (%s)\n", ob->name, + ob->ref, from); if (!ob->ref || --ob->ref > 0) - return; + return; if (!(ob->flags & O_DESTRUCTED)) { - /* This is fatal, and should never happen. */ - fatal("FATAL: Object %p %s ref count 0, but not destructed (from %s).\n", - ob, ob->name, from); + /* This is fatal, and should never happen. */ + fatal("FATAL: Object %p %s ref count 0, but not destructed (from %s).\n", + ob, ob->name, from); } if (ob->interactive) - fatal("Tried to free an interactive object.\n"); + fatal("Tried to free an interactive object.\n"); /* * If the program is freed, then we can also free the variable * declarations. */ if (ob->name) { - if (lookup_object_hash(ob->name) == ob) - fatal("Freeing object %s but name still in name table\n", ob->name); - free(ob->name); - ob->name = 0; + if (lookup_object_hash(ob->name) == ob) + fatal("Freeing object %s but name still in name table\n", ob->name); + free(ob->name); + ob->name = 0; } tot_alloc_object--; tot_alloc_dest_object--; @@ -862,8 +862,8 @@ add_ref(struct object *ob, char *from) { INCREF(ob->ref); if (d_flag & DEBUG_OB_REF) - (void)printf("Add reference to object %s: %d (%s)\n", ob->name, - ob->ref, from); + (void)printf("Add reference to object %s: %d (%s)\n", ob->name, + ob->ref, from); } /* @@ -920,26 +920,26 @@ remove_all_objects() exception_frame.e_catch = 0; for (;;) { - ob = obj_list; - n = 0; - while (ob == master_ob || - ob == vbfc_object || - ob == auto_ob || - ob == simul_efun_ob) { - ob = ob->next_all; - if (n++ > 3) - break; - } - if (n > 3 || ob == 0) - break; - if (setjmp(exception_frame.e_context)) - clear_state(); - else { - exception = &exception_frame; - ob->prog->flags &= ~PRAGMA_RESIDENT; - destruct_object(ob); - exception = NULL; - } + ob = obj_list; + n = 0; + while (ob == master_ob || + ob == vbfc_object || + ob == auto_ob || + ob == simul_efun_ob) { + ob = ob->next_all; + if (n++ > 3) + break; + } + if (n > 3 || ob == 0) + break; + if (setjmp(exception_frame.e_context)) + clear_state(); + else { + exception = &exception_frame; + ob->prog->flags &= ~PRAGMA_RESIDENT; + destruct_object(ob); + exception = NULL; + } } /* * In case we have objects referenced through @@ -984,19 +984,19 @@ check_ob_ref(struct object *ob, char *from) int i; for (o = obj_list, i=0; o; o = o->next_all) { - if (o->inherit == ob) - i++; + if (o->inherit == ob) + i++; } if (i+1 > ob->ref) { - fatal("FATAL too many references to inherited object %s (%d) from %s.\n", - ob->name, ob->ref, from); - if (current_object) - (void)fprintf(stderr, "current_object: %s\n", current_object->name); - for (o = obj_list; o; o = o->next_all) { - if (o->inherit != ob) - continue; - (void)fprintf(stderr, " %s\n", ob->name); - } + fatal("FATAL too many references to inherited object %s (%d) from %s.\n", + ob->name, ob->ref, from); + if (current_object) + (void)fprintf(stderr, "current_object: %s\n", current_object->name); + for (o = obj_list; o; o = o->next_all) { + if (o->inherit != ob) + continue; + (void)fprintf(stderr, " %s\n", ob->name); + } } } #endif /* 0 */ @@ -1016,17 +1016,17 @@ find_living_object(char *str) num_searches++; hl = &hashed_living[LivHash(str)]; for (obp = hl; *obp; obp = &(*obp)->next_hashed_living) { - search_length++; - if (!((*obp)->flags & O_ENABLE_COMMANDS)) - continue; - if (strcmp((*obp)->living_name, str) == 0) - break; + search_length++; + if (!((*obp)->flags & O_ENABLE_COMMANDS)) + continue; + if (strcmp((*obp)->living_name, str) == 0) + break; } if (*obp == 0) - return 0; + return 0; /* Move the found ob first. */ if (obp == hl) - return *obp; + return *obp; tmp = *obp; *obp = tmp->next_hashed_living; tmp->next_hashed_living = *hl; @@ -1045,26 +1045,26 @@ find_living_objects(char *str) num_searches++; hl = &hashed_living[LivHash(str)]; for (count = 0, obp = hl; *obp; obp = &(*obp)->next_hashed_living) { - search_length++; - if (!((*obp)->flags & O_ENABLE_COMMANDS)) - continue; - if (strcmp((*obp)->living_name, str) == 0) - count++; + search_length++; + if (!((*obp)->flags & O_ENABLE_COMMANDS)) + continue; + if (strcmp((*obp)->living_name, str) == 0) + count++; } ret = allocate_array(count); for (count = 0, obp = hl; *obp; obp = &(*obp)->next_hashed_living) { - search_length++; - if (!((*obp)->flags & O_ENABLE_COMMANDS)) - continue; - if (strcmp((*obp)->living_name, str) == 0) - { - ret->item[count].type = T_OBJECT; - ret->item[count++].u.ob = *obp; - add_ref(*obp, "find_living_objects"); - } + search_length++; + if (!((*obp)->flags & O_ENABLE_COMMANDS)) + continue; + if (strcmp((*obp)->living_name, str) == 0) + { + ret->item[count].type = T_OBJECT; + ret->item[count++].u.ob = *obp; + add_ref(*obp, "find_living_objects"); + } } return ret; @@ -1076,18 +1076,18 @@ set_living_name(struct object *ob, char *str) struct object **hl; if (ob->flags & O_DESTRUCTED) - return; + return; if (ob->living_name) { - remove_living_name(ob); + remove_living_name(ob); #ifdef SUPER_SNOOP - if (ob->interactive && ob->interactive->snoop_fd >= 0) { - (void) close(ob->interactive->snoop_fd); - ob->interactive->snoop_fd = -1; - } + if (ob->interactive && ob->interactive->snoop_fd >= 0) { + (void) close(ob->interactive->snoop_fd); + ob->interactive->snoop_fd = -1; + } #endif } if (!*str) - return; + return; num_living_names++; hl = &hashed_living[LivHash(str)]; ob->next_hashed_living = *hl; @@ -1106,16 +1106,16 @@ remove_living_name(struct object *ob) num_living_names--; if (!ob->living_name) - fatal("remove_living_name: no living name set.\n"); + fatal("remove_living_name: no living name set.\n"); hl = &hashed_living[LivHash(ob->living_name)]; while(*hl) { - if (*hl == ob) - break; - hl = &(*hl)->next_hashed_living; + if (*hl == ob) + break; + hl = &(*hl)->next_hashed_living; } if (*hl == 0) - fatal("remove_living_name: Object named %s no in hash list.\n", - ob->living_name); + fatal("remove_living_name: Object named %s no in hash list.\n", + ob->living_name); *hl = ob->next_hashed_living; free_sstring(ob->living_name); ob->next_hashed_living = 0; @@ -1128,7 +1128,7 @@ stat_living_objects() static char tmp[400]; (void)sprintf(tmp,"Hash table of living objects:\n-----------------------------\n%d living named objects, average search length: %4.2f\n", - num_living_names, (double)search_length / num_searches); + num_living_names, (double)search_length / num_searches); return tmp; } @@ -1137,8 +1137,8 @@ reference_prog (struct program *progp, char *from) { INCREF(progp->ref); if (d_flag & DEBUG_PROG_REF) - (void)printf("reference_prog: %s ref %d (%s)\n", - progp->name, progp->ref, from); + (void)printf("reference_prog: %s ref %d (%s)\n", + progp->name, progp->ref, from); } struct program *prog_list; @@ -1148,14 +1148,14 @@ void register_program(struct program *prog) { if (prog_list) { - prog->next_all = prog_list; - prog->prev_all = prog_list->prev_all; - prog_list->prev_all->next_all = prog; - prog_list->prev_all = prog; - prog_list = prog; + prog->next_all = prog_list; + prog->prev_all = prog_list->prev_all; + prog_list->prev_all->next_all = prog; + prog_list->prev_all = prog; + prog_list = prog; } else - prog_list = prog->next_all = prog->prev_all = prog; + prog_list = prog->next_all = prog->prev_all = prog; } /* @@ -1172,19 +1172,19 @@ free_prog(struct program *progp) int i; if (d_flag & DEBUG_PROG_REF) - (void)printf("free_prog: %s\n", progp->name); + (void)printf("free_prog: %s\n", progp->name); if (!progp->ref || --progp->ref > 0) - return; + return; if (progp->ref < 0) - fatal("Negative ref count for prog ref.\n"); + fatal("Negative ref count for prog ref.\n"); if (progp == prog_list) - prog_list = progp->next_all; + prog_list = progp->next_all; progp->prev_all->next_all = progp->next_all; progp->next_all->prev_all = progp->prev_all; if (progp->next_all == progp) - prog_list = 0; + prog_list = 0; total_program_size -= progp->exec_size; @@ -1193,24 +1193,24 @@ free_prog(struct program *progp) /* Free all function names. */ for (i=0; i < progp->num_functions; i++) - if (progp->functions[i].name) - free_sstring(progp->functions[i].name); + if (progp->functions[i].name) + free_sstring(progp->functions[i].name); /* Free all variable names */ for (i=0; i < progp->num_variables; i++) - free_sstring(progp->variable_names[i].name); + free_sstring(progp->variable_names[i].name); /* Free all inherited objects */ for (i=0; i < progp->num_inherited - 1; i++) { - free_prog(progp->inherit[i].prog); - free_sstring(progp->inherit[i].name); + free_prog(progp->inherit[i].prog); + free_sstring(progp->inherit[i].name); } free_sstring(progp->inherit[i].name); free(progp->name); free((char *)progp->program); if (progp->line_numbers != 0) - free((char *)progp->line_numbers); + free((char *)progp->line_numbers); free((char *)progp); } @@ -1221,25 +1221,25 @@ create_object(struct object *ob) if (!(ob->flags & O_CREATED)) { - ob->flags |= O_CREATED; - ob->created = current_time; - for (i = 0; i < (int)ob->prog->num_inherited; i++) - if (!(ob->prog->inherit[i].type & TYPE_MOD_SECOND)) - { - if (ob->prog->inherit[i].prog->ctor_index != - (unsigned short) -1) - { - call_function(ob, i, - (unsigned int)ob->prog->inherit[i].prog->ctor_index, 0); - pop_stack(); - } - } - if (search_for_function("create", ob->prog)) - { - call_function(ob, function_inherit_found, - (unsigned int)function_index_found, 0); - pop_stack(); - } + ob->flags |= O_CREATED; + ob->created = current_time; + for (i = 0; i < (int)ob->prog->num_inherited; i++) + if (!(ob->prog->inherit[i].type & TYPE_MOD_SECOND)) + { + if (ob->prog->inherit[i].prog->ctor_index != + (unsigned short) -1) + { + call_function(ob, i, + (unsigned int)ob->prog->inherit[i].prog->ctor_index, 0); + pop_stack(); + } + } + if (search_for_function("create", ob->prog)) + { + call_function(ob, function_inherit_found, + (unsigned int)function_index_found, 0); + pop_stack(); + } } } void @@ -1251,33 +1251,33 @@ recreate_object(struct object *ob, struct object *old_ob) if (!(ob->flags & O_CREATED)) { need_create = 1; - ob->flags |= O_CREATED; - if (!ob->created) - ob->created = current_time; - for (i = 0; i < (int)ob->prog->num_inherited; i++) - if (!(ob->prog->inherit[i].type & TYPE_MOD_SECOND)) - { - if (ob->prog->inherit[i].prog->ctor_index != - (unsigned short) -1) - { - call_function(ob, i, - (unsigned int)ob->prog->inherit[i].prog->ctor_index, 0); - pop_stack(); - } - } + ob->flags |= O_CREATED; + if (!ob->created) + ob->created = current_time; + for (i = 0; i < (int)ob->prog->num_inherited; i++) + if (!(ob->prog->inherit[i].type & TYPE_MOD_SECOND)) + { + if (ob->prog->inherit[i].prog->ctor_index != + (unsigned short) -1) + { + call_function(ob, i, + (unsigned int)ob->prog->inherit[i].prog->ctor_index, 0); + pop_stack(); + } + } } if (search_for_function("recreate", ob->prog)) { - push_object(old_ob); - call_function(ob, function_inherit_found, - (unsigned int)function_index_found, 1); - pop_stack(); + push_object(old_ob); + call_function(ob, function_inherit_found, + (unsigned int)function_index_found, 1); + pop_stack(); } else if (need_create && search_for_function("create", ob->prog)) { call_function(ob, function_inherit_found, - (unsigned int)function_index_found, 0); - pop_stack(); + (unsigned int)function_index_found, 0); + pop_stack(); } } @@ -1295,9 +1295,9 @@ inherit_list(struct object *ob) for (inh = 0; inh < (int)ob->prog->num_inherited; inh++ ) { - ret->item[inh].type = T_STRING; - ret->item[inh].string_type = STRING_MSTRING; - ret->item[inh].u.string = add_slash(ob->prog->inherit[inh].prog->name); + ret->item[inh].type = T_STRING; + ret->item[inh].string_type = STRING_MSTRING; + ret->item[inh].u.string = add_slash(ob->prog->inherit[inh].prog->name); } return ret; } @@ -1318,6 +1318,6 @@ warnobsolete(struct object *ob, char *msg) ob->flags |= O_OBSOLETE_WARNING; if (!warnobsoleteflag) - return; + return; (void)fprintf(stderr, "OBSOLETE: %s: %s\n", ob->name, msg); } diff --git a/object.h b/object.h index bf85982..0c302a2 100644 --- a/object.h +++ b/object.h @@ -6,7 +6,7 @@ * 0: There is an error in the reset() in this object. Never call it again. * 1: Normal state. * 2 or higher: This is an interactive player, that has not given any commands - * for a number of reset periods. + * for a number of reset periods. */ #include "config.h" #include "interpret.h" @@ -14,25 +14,25 @@ #ifndef _OBJECT_H #define _OBJECT_H -#define O_CREATED 0x02 /* Has 'create()' been called */ -#define O_ENABLE_COMMANDS 0x04 /* Can it execute commands ? */ -#define O_CLONE 0x08 /* Is it cloned from a master copy ? */ -#define O_DESTRUCTED 0x10 /* Is it destructed ? */ -#define O_SWAPPED 0x20 /* Is it swapped to file */ -#define O_ONCE_INTERACTIVE 0x40 /* Has it ever been interactive ? */ -#define O_OBSOLETE_WARNING 0x80 /* Object has already generated a warning */ -#define O_ADDED_COMMAND 0x100 /* Has it created a sentence? */ +#define O_CREATED 0x02 /* Has 'create()' been called */ +#define O_ENABLE_COMMANDS 0x04 /* Can it execute commands ? */ +#define O_CLONE 0x08 /* Is it cloned from a master copy ? */ +#define O_DESTRUCTED 0x10 /* Is it destructed ? */ +#define O_SWAPPED 0x20 /* Is it swapped to file */ +#define O_ONCE_INTERACTIVE 0x40 /* Has it ever been interactive ? */ +#define O_OBSOLETE_WARNING 0x80 /* Object has already generated a warning */ +#define O_ADDED_COMMAND 0x100 /* Has it created a sentence? */ struct call; struct object { - unsigned short flags; /* Bits or'ed together from above */ + unsigned short flags; /* Bits or'ed together from above */ unsigned short debug_flags; - int created; /* Time of creation of this object */ - int time_of_ref; /* Time when last referenced. Used by swap */ - unsigned int ref; /* Reference count. */ + int created; /* Time of creation of this object */ + int time_of_ref; /* Time when last referenced. Used by swap */ + unsigned int ref; /* Reference count. */ #ifdef DEBUG - int extra_ref; /* Used to check ref count. */ + int extra_ref; /* Used to check ref count. */ #endif struct program *prog; char *name; @@ -42,19 +42,19 @@ struct object { struct object *next_call_out; struct object *next_all, *prev_all, *next_inv, *next_hash; struct object *contains; - struct object *super; /* Which object surround us ? */ - struct object *shadowing; /* Is this object shadowing ? */ - struct object *shadowed; /* Is this object shadowed ? */ - struct interactive *interactive; /* Data about an interactive player */ + struct object *super; /* Which object surround us ? */ + struct object *shadowing; /* Is this object shadowing ? */ + struct object *shadowed; /* Is this object shadowed ? */ + struct interactive *interactive; /* Data about an interactive player */ struct sentence *sent; struct object *next_hashed_living; - char *living_name; /* Name of living object if in hash */ - struct svalue *variables; /* All variables to this program */ + char *living_name; /* Name of living object if in hash */ + struct svalue *variables; /* All variables to this program */ struct svalue auth; /* The protected auth variable */ }; -#define WARNOBSOLETE(ob, msg) if (((ob)->flags & O_OBSOLETE_WARNING) == 0) \ - warnobsolete(ob, msg) +#define WARNOBSOLETE(ob, msg) if (((ob)->flags & O_OBSOLETE_WARNING) == 0) \ + warnobsolete(ob, msg) void warnobsolete(struct object *ob, char *msg); @@ -88,4 +88,4 @@ int restore_one(struct svalue *, char **); void restore_map(struct object *, struct mapping *, char *); void create_object(struct object *); void recreate_object(struct object *, struct object *); -#endif \ No newline at end of file +#endif diff --git a/otable.c b/otable.c index 40018cc..0204d0e 100644 --- a/otable.c +++ b/otable.c @@ -49,19 +49,19 @@ find_obj_n(char *s) while (curr) { - obj_probes++; - if (strcmp(curr->name, s) == 0) { /* found it */ - if (prev) - { /* not at head of list */ - prev->next_hash = curr->next_hash; - curr->next_hash = obj_table[h]; - obj_table[h] = curr; - } - objs_found++; - return(curr); /* pointer to object */ - } - prev = curr; - curr = curr->next_hash; + obj_probes++; + if (strcmp(curr->name, s) == 0) { /* found it */ + if (prev) + { /* not at head of list */ + prev->next_hash = curr->next_hash; + curr->next_hash = obj_table[h]; + obj_table[h] = curr; + } + objs_found++; + return(curr); /* pointer to object */ + } + prev = curr; + curr = curr->next_hash; } return(0); /* not found */ @@ -81,40 +81,40 @@ enter_object_hash(struct object *ob) /* Add to object list */ if (ob->flags & O_CLONE && ob->prog->clones) { - sibling = ob->prog->clones; - ob->next_all = sibling; - ob->prev_all = sibling->prev_all; - sibling->prev_all->next_all = ob; - sibling->prev_all = ob; - if (sibling == obj_list) - obj_list = ob; + sibling = ob->prog->clones; + ob->next_all = sibling; + ob->prev_all = sibling->prev_all; + sibling->prev_all->next_all = ob; + sibling->prev_all = ob; + if (sibling == obj_list) + obj_list = ob; } else if (obj_list) { - ob->next_all = obj_list; - ob->prev_all = obj_list->prev_all; - obj_list->prev_all->next_all = ob; - obj_list->prev_all = ob; - obj_list = ob; + ob->next_all = obj_list; + ob->prev_all = obj_list->prev_all; + obj_list->prev_all->next_all = ob; + obj_list->prev_all = ob; + obj_list = ob; } else - obj_list = ob->next_all = ob->prev_all = ob; + obj_list = ob->next_all = ob->prev_all = ob; if (ob->flags & O_CLONE) { - ob->prog->clones = ob; - ob->prog->num_clones++; + ob->prog->clones = ob; + ob->prog->num_clones++; } s = find_obj_n(ob->name); if (s) { - if (s != ob) - fatal("Duplicate object \"%s\" in object hash table\n", - ob->name); - else - fatal("Entering object \"%s\" twice in object table\n", - ob->name); + if (s != ob) + fatal("Duplicate object \"%s\" in object hash table\n", + ob->name); + else + fatal("Entering object \"%s\" twice in object table\n", + ob->name); } if (ob->next_hash) - fatal("Object \"%s\" not found in object table but next link not null\n", - ob->name); + fatal("Object \"%s\" not found in object table but next link not null\n", + ob->name); ob->next_hash = obj_table[h]; obj_table[h] = ob; objs_in_table++; @@ -134,27 +134,27 @@ remove_object_hash(struct object *ob) s = find_obj_n(ob->name); if (s != ob) - fatal("Remove object \"%s\": found a different object!\n", - ob->name); + fatal("Remove object \"%s\": found a different object!\n", + ob->name); obj_table[h] = ob->next_hash; ob->next_hash = 0; objs_in_table--; if (ob->flags & O_CLONE) - ob->prog->num_clones--; + ob->prog->num_clones--; if (ob->prog->clones == ob) { - if (ob->next_all->prog == ob->prog && - ob->next_all->flags & O_CLONE && - ob->next_all != ob) - ob->prog->clones = ob->next_all; - else - ob->prog->clones = NULL; + if (ob->next_all->prog == ob->prog && + ob->next_all->flags & O_CLONE && + ob->next_all != ob) + ob->prog->clones = ob->next_all; + else + ob->prog->clones = NULL; } if (ob->next_all == ob) - obj_list = NULL; + obj_list = NULL; else if (ob == obj_list) - obj_list = ob->next_all; + obj_list = ob->next_all; ob->prev_all->next_all = ob->next_all; ob->next_all->prev_all = ob->prev_all; @@ -172,10 +172,10 @@ static int user_obj_lookups = 0, user_obj_found = 0; struct object * lookup_object_hash(char *s) { - struct object * ob = find_obj_n(s); - user_obj_lookups++; - if (ob) user_obj_found++; - return(ob); + struct object * ob = find_obj_n(s); + user_obj_lookups++; + if (ob) user_obj_found++; + return(ob); } /* @@ -188,11 +188,11 @@ add_otable_status(char *debinf) (void)strcat(debinf, "\nObject name hash table status:\n"); (void)strcat(debinf, "------------------------------\n"); (void)sprintf(debinf + strlen(debinf), "Average hash chain length %.2f\n", - (double)objs_in_table / OTABLE_SIZE); + (double)objs_in_table / OTABLE_SIZE); (void)sprintf(debinf + strlen(debinf), "Searches/average search length %lld (%.2f)\n", - obj_searches, (double)obj_probes / (double)obj_searches); + obj_searches, (double)obj_probes / (double)obj_searches); (void)sprintf(debinf + strlen(debinf), "External lookups succeeded (succeed) %d (%d)\n", - user_obj_lookups, user_obj_found); + user_obj_lookups, user_obj_found); } #ifdef DEALLOCATE_MEMORY_AT_SHUTDOWN @@ -202,6 +202,6 @@ clear_otable() int i; for (i = 0; i < OTABLE_SIZE; i++) - obj_table[i] = NULL; + obj_table[i] = NULL; } #endif diff --git a/parse.c b/parse.c index 1431bbe..86c4ac8 100644 --- a/parse.c +++ b/parse.c @@ -32,7 +32,7 @@ extern int d_flag; /* for debugging purposes */ extern struct object *previous_ob; struct object *vbfc_object; -#ifndef tolower /* On some systems this is a function */ +#ifndef tolower /* On some systems this is a function */ extern int tolower (int); #endif @@ -132,25 +132,25 @@ extern int tolower (int); * The numberwords below should be replaced for the new language * static char *ord1[] = {"", "first", "second", "third", "fourth", "fifth", - "sixth", "seventh", "eighth", "ninth", "tenth", - "eleventh", "twelfth", "thirteenth", "fourteenth", - "fifteenth", "sixteenth", "seventeenth", - "eighteenth","nineteenth"}; + "sixth", "seventh", "eighth", "ninth", "tenth", + "eleventh", "twelfth", "thirteenth", "fourteenth", + "fifteenth", "sixteenth", "seventeenth", + "eighteenth","nineteenth"}; static char *ord10[] = {"", "", "twenty","thirty","forty","fifty","sixty", - "seventy", "eighty","ninety"}; + "seventy", "eighty","ninety"}; static char *sord10[] = {"", "", "twentieth", "thirtieth", "fortieth", - "fiftieth", "sixtieth","seventieth", "eightieth", - "ninetieth"}; + "fiftieth", "sixtieth","seventieth", "eightieth", + "ninetieth"}; static char *num1[] = {"", "one","two","three","four","five","six", - "seven","eight","nine","ten", - "eleven","twelve","thirteen","fourteen","fifteen", - "sixteen", "seventeen","eighteen","nineteen"}; + "seven","eight","nine","ten", + "eleven","twelve","thirteen","fourteen","fifteen", + "sixteen", "seventeen","eighteen","nineteen"}; static char *num10[] = {"", "", "twenty","thirty","forty","fifty","sixty", - "seventy", "eighty","ninety"}; + "seventy", "eighty","ninety"}; #include "parse_english.c" * This parse.c file * @@ -164,49 +164,49 @@ extern int tolower (int); int parse_command(string, object/object*, string, destargs...) - Returns 1 if pattern matches - - string Given command - - object* if arr - object array holding the accessible objects - if ob - object from which to recurse and create - the list of accessible objects, normally - ob = environment(this_player()) - string Parsepattern as list of words and formats: - Example string = " 'get' / 'take' %i " - Syntax: - 'word' obligatory text - [word] optional text - / Alternative marker - %o Single item, object - %l Living objects - %s Any text - %w Any word - %p One of a list (prepositions) - %i Any items - %d Number 0- or tx(0-99) - - destargs This is the list of result variables as in sscanf - One variable is needed for each %_ - The return types of different %_ is: - %o Returns an object - %s Returns a string of words - %w Returns a string of one word - %p Can on entry hold a list of word in array - or an empty variable - Returns: - if empty variable: a string - if array: array[0]=matched word - %i Returns a special array on the form: - [0] = (int) +(wanted) -(order) 0(all) - [1..n] (object) Objectpointers - %l Returns a special array on the form: - [0] = (int) +(wanted) -(order) 0(all) - [1..n] (object) Objectpointers - These are only living objects. - %d Returns a number + Returns 1 if pattern matches + + string Given command + + object* if arr + object array holding the accessible objects + if ob + object from which to recurse and create + the list of accessible objects, normally + ob = environment(this_player()) + string Parsepattern as list of words and formats: + Example string = " 'get' / 'take' %i " + Syntax: + 'word' obligatory text + [word] optional text + / Alternative marker + %o Single item, object + %l Living objects + %s Any text + %w Any word + %p One of a list (prepositions) + %i Any items + %d Number 0- or tx(0-99) + + destargs This is the list of result variables as in sscanf + One variable is needed for each %_ + The return types of different %_ is: + %o Returns an object + %s Returns a string of words + %w Returns a string of one word + %p Can on entry hold a list of word in array + or an empty variable + Returns: + if empty variable: a string + if array: array[0]=matched word + %i Returns a special array on the form: + [0] = (int) +(wanted) -(order) 0(all) + [1..n] (object) Objectpointers + %l Returns a special array on the form: + [0] = (int) +(wanted) -(order) 0(all) + [1..n] (object) Objectpointers + These are only living objects. + %d Returns a number The only types of % that uses all the loaded information from the objects are %i and %l. These are in fact identical except that %l filters out @@ -290,15 +290,15 @@ int parse_command(string, object/object*, string, destargs...) The main 'parse' routine stores these on call, making the entire parse_command() reentrant. */ -static struct vector *gId_list = 0; -static struct vector *gPluid_list = 0; -static struct vector *gAdjid_list = 0; +static struct vector *gId_list = 0; +static struct vector *gPluid_list = 0; +static struct vector *gAdjid_list = 0; -static struct vector *gId_list_d = 0; /* From master */ -static struct vector *gPluid_list_d = 0; /* From master */ -static struct vector *gAdjid_list_d = 0; /* From master */ -static struct vector *gPrepos_list = 0; /* From master */ -static char *gAllword = 0; /* From master */ +static struct vector *gId_list_d = 0; /* From master */ +static struct vector *gPluid_list_d = 0; /* From master */ +static struct vector *gAdjid_list_d = 0; /* From master */ +static struct vector *gPrepos_list = 0; /* From master */ +static char *gAllword = 0; /* From master */ /* * Master has been (re)loaded; fetch params needed for parsing @@ -315,55 +315,55 @@ load_parse_information() pval = apply_master_ob(M_QGET_ID, 0); if (pval && pval->type == T_POINTER) { - gId_list_d = pval->u.vec; - INCREF(pval->u.vec->ref); /* Otherwise next sapply will free it */ + gId_list_d = pval->u.vec; + INCREF(pval->u.vec->ref); /* Otherwise next sapply will free it */ } else - gId_list_d = 0; + gId_list_d = 0; pval = apply_master_ob(M_QGET_PLURID,0); if (pval && pval->type == T_POINTER) { - gPluid_list_d = pval->u.vec; - INCREF(pval->u.vec->ref); /* Otherwise next sapply will free it */ + gPluid_list_d = pval->u.vec; + INCREF(pval->u.vec->ref); /* Otherwise next sapply will free it */ } else - gPluid_list_d = 0; + gPluid_list_d = 0; pval = apply_master_ob(M_QGET_ADJID, 0); if (pval && pval->type == T_POINTER) { - gAdjid_list_d = pval->u.vec; - INCREF(pval->u.vec->ref); /* Otherwise next sapply will free it */ + gAdjid_list_d = pval->u.vec; + INCREF(pval->u.vec->ref); /* Otherwise next sapply will free it */ } else - gAdjid_list_d = 0; + gAdjid_list_d = 0; pval = apply_master_ob(M_QGET_PREPOS,0); if (pval && pval->type == T_POINTER) { - gPrepos_list = pval->u.vec; - INCREF(pval->u.vec->ref); /* Otherwise next sapply will free it */ + gPrepos_list = pval->u.vec; + INCREF(pval->u.vec->ref); /* Otherwise next sapply will free it */ } else - gPrepos_list = 0; + gPrepos_list = 0; pval = apply_master_ob(M_QGET_ALLWORD,0); if (pval && pval->type == T_STRING) - gAllword = string_copy(pval->u.string); + gAllword = string_copy(pval->u.string); else - gAllword = 0; + gAllword = 0; } /* - * Function name: load_lpc_info - * Description: Loads relevant information from a given object. - * This is the ids, plural ids and adjectiv ids. This - * is the only calls to LPC objects other than the + * Function name: load_lpc_info + * Description: Loads relevant information from a given object. + * This is the ids, plural ids and adjectiv ids. This + * is the only calls to LPC objects other than the * master object that occur within the efun * parse_command(). - * Arguments: ix: Index in the array - * ob: The object to call for information. + * Arguments: ix: Index in the array + * ob: The object to call for information. */ void load_lpc_info(int ix, struct object *ob) @@ -375,71 +375,71 @@ load_lpc_info(int ix, struct object *ob) char *parse_to_plural(char *); if (!ob) - return; + return; if (gPluid_list && - gPluid_list->size > ix && - gPluid_list->item[ix].type == T_NUMBER && - gPluid_list->item[ix].u.number == 0) + gPluid_list->size > ix && + gPluid_list->item[ix].type == T_NUMBER && + gPluid_list->item[ix].u.number == 0) { - ret = apply(QGET_PLURID, ob, 0, 1); - if (ret && ret->type == T_POINTER) - assign_svalue_no_free(&gPluid_list->item[ix], ret); - else - { - make_plural = 1; - gPluid_list->item[ix].u.number = 1; - } + ret = apply(QGET_PLURID, ob, 0, 1); + if (ret && ret->type == T_POINTER) + assign_svalue_no_free(&gPluid_list->item[ix], ret); + else + { + make_plural = 1; + gPluid_list->item[ix].u.number = 1; + } } if (gId_list && - gId_list->size > ix && - gId_list->item[ix].type == T_NUMBER && - gId_list->item[ix].u.number == 0) + gId_list->size > ix && + gId_list->item[ix].type == T_NUMBER && + gId_list->item[ix].u.number == 0) { - ret = apply(QGET_ID, ob, 0, 1); - if (ret && ret->type == T_POINTER) - { - assign_svalue_no_free(&gId_list->item[ix], ret); - if (make_plural) - { - tmp = allocate_array(ret->u.vec->size); - sing = ret->u.vec; - - sval.type = T_STRING; - sval.string_type = STRING_MSTRING; - for (il = 0; il < tmp->size; il++) - { - if (sing->item[il].type == T_STRING) - { - str = parse_to_plural(sing->item[il].u.string); - sval.u.string = str; - assign_svalue_no_free(&tmp->item[il],&sval); - free_mstring(sval.u.string); - } - } - sval.type = T_POINTER; - sval.u.vec = tmp; - assign_svalue_no_free(&gPluid_list->item[ix], &sval); - free_svalue(&sval); - } - } - else - { - gId_list->item[ix].u.number = 1; - } + ret = apply(QGET_ID, ob, 0, 1); + if (ret && ret->type == T_POINTER) + { + assign_svalue_no_free(&gId_list->item[ix], ret); + if (make_plural) + { + tmp = allocate_array(ret->u.vec->size); + sing = ret->u.vec; + + sval.type = T_STRING; + sval.string_type = STRING_MSTRING; + for (il = 0; il < tmp->size; il++) + { + if (sing->item[il].type == T_STRING) + { + str = parse_to_plural(sing->item[il].u.string); + sval.u.string = str; + assign_svalue_no_free(&tmp->item[il],&sval); + free_mstring(sval.u.string); + } + } + sval.type = T_POINTER; + sval.u.vec = tmp; + assign_svalue_no_free(&gPluid_list->item[ix], &sval); + free_svalue(&sval); + } + } + else + { + gId_list->item[ix].u.number = 1; + } } if (gAdjid_list && - gAdjid_list->size > ix && - gAdjid_list->item[ix].type == T_NUMBER && - gAdjid_list->item[ix].u.number == 0) + gAdjid_list->size > ix && + gAdjid_list->item[ix].type == T_NUMBER && + gAdjid_list->item[ix].u.number == 0) { - ret = apply(QGET_ADJID, ob, 0, 1); - if (ret && ret->type == T_POINTER) - assign_svalue_no_free(&gAdjid_list->item[ix], ret); - else - gAdjid_list->item[ix].u.number = 1; + ret = apply(QGET_ADJID, ob, 0, 1); + if (ret && ret->type == T_POINTER) + assign_svalue_no_free(&gAdjid_list->item[ix], ret); + else + gAdjid_list->item[ix].u.number = 1; } } @@ -447,19 +447,19 @@ void free_parse_information() { if (gId_list_d) - free_vector(gId_list_d); + free_vector(gId_list_d); gId_list_d = 0; if (gPluid_list_d) - free_vector(gPluid_list_d); + free_vector(gPluid_list_d); gPluid_list_d = 0; if (gAdjid_list_d) - free_vector(gAdjid_list_d); + free_vector(gAdjid_list_d); gAdjid_list_d = 0; if (gPrepos_list) - free_vector(gPrepos_list); + free_vector(gPrepos_list); gPrepos_list = 0; if (gAllword) - free(gAllword); + free(gAllword); gAllword = 0; } @@ -467,47 +467,47 @@ free_parse_information() */ /* - * Function name: parse - * Description: The main function for the efun: parse_command() - * It parses a given command using a given pattern and - * a set of objects (see args below). For details - * see LPC documentation of the efun. - * Arguments: cmd: The command to parse - * ob_or_array: A list of objects or one object from - * which to make a list of objects by - * using the objects deep_inventory - * pattern: The given parse pattern somewhat like sscanf - * but with different %-codes, see efun docs. - * stack_args: Pointer to destination arguments. - * num_arg: Number of destination arguments. - * Returns: True if command matched pattern. + * Function name: parse + * Description: The main function for the efun: parse_command() + * It parses a given command using a given pattern and + * a set of objects (see args below). For details + * see LPC documentation of the efun. + * Arguments: cmd: The command to parse + * ob_or_array: A list of objects or one object from + * which to make a list of objects by + * using the objects deep_inventory + * pattern: The given parse pattern somewhat like sscanf + * but with different %-codes, see efun docs. + * stack_args: Pointer to destination arguments. + * num_arg: Number of destination arguments. + * Returns: True if command matched pattern. */ int parse (char *cmd, struct svalue *ob_or_array, char *pattern, struct svalue *stack_args, int num_arg) /* - char *cmd; Command to parse - struct svalue *ob_or_array; Object or array of objects - char *pattern; Special parsing pattern - struct svalue *stack_args; Pointer to lvalue args on stack - int num_arg; Number of args on stack + char *cmd; Command to parse + struct svalue *ob_or_array; Object or array of objects + char *pattern; Special parsing pattern + struct svalue *stack_args; Pointer to lvalue args on stack + int num_arg; Number of args on stack */ { - struct vector *obvec, *patvec, *wvec; - struct vector *old_id, *old_plid, *old_adjid; - int pix, cix, six, fail, fword, ocix, fpix; - struct svalue *pval; - void check_for_destr(struct svalue *); /* In interpret.c */ - struct svalue *sub_parse(struct vector *, struct vector *, int *, struct vector *, int *, int *, struct svalue *); - struct svalue *slice_words(struct vector *, int, int), tmp; - void stack_put(struct svalue *, struct svalue *, int, int); - struct vector *deep_inventory(struct object *, int); + struct vector *obvec, *patvec, *wvec; + struct vector *old_id, *old_plid, *old_adjid; + int pix, cix, six, fail, fword, ocix, fpix; + struct svalue *pval; + void check_for_destr(struct svalue *); /* In interpret.c */ + struct svalue *sub_parse(struct vector *, struct vector *, int *, struct vector *, int *, int *, struct svalue *); + struct svalue *slice_words(struct vector *, int, int), tmp; + void stack_put(struct svalue *, struct svalue *, int, int); + struct vector *deep_inventory(struct object *, int); /* * Pattern and commands can not be empty */ if (*cmd == '\0' || *pattern == '\0') - return 0; + return 0; wvec = explode_string(cmd," "); /* Array of words in command */ patvec = explode_string(pattern," "); /* Array of pattern elements */ @@ -516,21 +516,21 @@ parse (char *cmd, struct svalue *ob_or_array, char *pattern, * Explode can return '0'. */ if (!wvec) - wvec = allocate_array(0); + wvec = allocate_array(0); if (!patvec) - patvec = allocate_array(0); + patvec = allocate_array(0); - INCREF(wvec->ref); /* Do not lose these arrays */ + INCREF(wvec->ref); /* Do not lose these arrays */ INCREF(patvec->ref); if (ob_or_array->type == T_POINTER) - obvec = ob_or_array->u.vec; + obvec = ob_or_array->u.vec; else if (ob_or_array->type == T_OBJECT) - obvec = deep_inventory(ob_or_array->u.ob, 1); /* 1 == ob + deepinv */ + obvec = deep_inventory(ob_or_array->u.ob, 1); /* 1 == ob + deepinv */ else { - obvec = 0; - error("Bad second argument to parse_command()\n"); + obvec = 0; + error("Bad second argument to parse_command()\n"); } tmp.type = T_POINTER; @@ -554,7 +554,7 @@ parse (char *cmd, struct svalue *ob_or_array, char *pattern, pix = 0; #ifndef OLD_EXPLODE while (pix < patvec->size && !*(patvec->item[pix].u.string)) - pix++; + pix++; #endif six = 0; @@ -562,113 +562,113 @@ parse (char *cmd, struct svalue *ob_or_array, char *pattern, fail = 0; for (; pix < patvec->size; pix++) { - pval = 0; /* The 'fill-in' value */ - fail = 0; /* 1 if match failed */ + pval = 0; /* The 'fill-in' value */ + fail = 0; /* 1 if match failed */ - if (EQ(patvec->item[pix].u.string, "%s")) - { - /* We are at end of pattern, scrap up the remaining - words and put them in the fill-in value. + if (EQ(patvec->item[pix].u.string, "%s")) + { + /* We are at end of pattern, scrap up the remaining + words and put them in the fill-in value. */ - if (pix == (patvec->size-1)) - { - pval = slice_words(wvec, cix, wvec->size - 1); - cix = wvec->size; - stack_put(pval, stack_args, six++, num_arg); - } - else - /* - There is something after %s, try to parse with the + if (pix == (patvec->size-1)) + { + pval = slice_words(wvec, cix, wvec->size - 1); + cix = wvec->size; + stack_put(pval, stack_args, six++, num_arg); + } + else + /* + There is something after %s, try to parse with the next pattern. Begin with the current word and step - one word for each fail, until match or end of words. + one word for each fail, until match or end of words. */ - { - ocix = fword = cix; /* Current word */ - fpix = ++pix; /* pix == next pattern */ - do - { - fail = 0; - /* - Parse the following pattern, fill-in values: - stack_args[six] = result of %s - stack_args[six + 1] = result of following pattern, - if it is a fill-in pattern - */ - pval = sub_parse(obvec, patvec, &pix, wvec, &cix, &fail, - ((six + 1) < num_arg) ? - stack_args[six + 1].u.lvalue - : 0); - if (fail) - { - cix = ++ocix; - pix = fpix; - } - } while ((fail) && (cix < wvec->size)); - - /* - We found something matching the pattern after %s. - First - stack_args[six + 1] = result of match - Then - stack_args[six] = the skipped words before match - */ - if (!fail) - { - /* A match with a value fill in param */ - if (pval) - { - stack_put(pval, stack_args, six + 1, num_arg); - pval = slice_words(wvec, fword, ocix - 1); - stack_put(pval, stack_args, six, num_arg); - six += 2; - } - else - { - /* A match with a non value ie 'word' */ - pval = slice_words(wvec, fword, ocix - 1); - stack_put(pval, stack_args, six++, num_arg); - } - pval = 0; - } - } - } - - else if (!EQ(patvec->item[pix].u.string,"/")) - { - /* The pattern was not %s, parse the pattern if - * it is not '/', a '/' here is skipped. - * If match, put in fill-in value. + { + ocix = fword = cix; /* Current word */ + fpix = ++pix; /* pix == next pattern */ + do + { + fail = 0; + /* + Parse the following pattern, fill-in values: + stack_args[six] = result of %s + stack_args[six + 1] = result of following pattern, + if it is a fill-in pattern + */ + pval = sub_parse(obvec, patvec, &pix, wvec, &cix, &fail, + ((six + 1) < num_arg) ? + stack_args[six + 1].u.lvalue + : 0); + if (fail) + { + cix = ++ocix; + pix = fpix; + } + } while ((fail) && (cix < wvec->size)); + + /* + We found something matching the pattern after %s. + First + stack_args[six + 1] = result of match + Then + stack_args[six] = the skipped words before match + */ + if (!fail) + { + /* A match with a value fill in param */ + if (pval) + { + stack_put(pval, stack_args, six + 1, num_arg); + pval = slice_words(wvec, fword, ocix - 1); + stack_put(pval, stack_args, six, num_arg); + six += 2; + } + else + { + /* A match with a non value ie 'word' */ + pval = slice_words(wvec, fword, ocix - 1); + stack_put(pval, stack_args, six++, num_arg); + } + pval = 0; + } + } + } + + else if (!EQ(patvec->item[pix].u.string,"/")) + { + /* The pattern was not %s, parse the pattern if + * it is not '/', a '/' here is skipped. + * If match, put in fill-in value. */ - pval = sub_parse(obvec, patvec, &pix, wvec, &cix, &fail, - (six < num_arg) ? stack_args[six].u.lvalue : 0); - if (!fail && pval) - stack_put(pval, stack_args, six++, num_arg); - } + pval = sub_parse(obvec, patvec, &pix, wvec, &cix, &fail, + (six < num_arg) ? stack_args[six].u.lvalue : 0); + if (!fail && pval) + stack_put(pval, stack_args, six++, num_arg); + } - /* Terminate parsing if no match + /* Terminate parsing if no match */ - if (fail) - break; + if (fail) + break; } /* Also fail when there are words left to parse and pattern exhausted */ if (cix < wvec->size) - fail = 1; + fail = 1; /* Delete and free the id arrays */ if (gId_list) { - free_vector(gId_list); + free_vector(gId_list); } if (gPluid_list) { - free_vector(gPluid_list); + free_vector(gPluid_list); } if (gAdjid_list) { - free_vector(gAdjid_list); + free_vector(gAdjid_list); } gId_list = old_id; @@ -686,136 +686,136 @@ parse (char *cmd, struct svalue *ob_or_array, char *pattern, */ if (ob_or_array->type == T_OBJECT) { - free_vector(obvec); + free_vector(obvec); } return !fail; } /* - * Function name: stack_put - * Description: Puts an svalue on the stack. - * Arguments: pval: Value to put - * sp: Stackpointer - * pos: Position on stack to put value - * max: The number of args on the stack + * Function name: stack_put + * Description: Puts an svalue on the stack. + * Arguments: pval: Value to put + * sp: Stackpointer + * pos: Position on stack to put value + * max: The number of args on the stack */ void -stack_put(struct svalue *pval, struct svalue *msp, int pos, int max) +stack_put(struct svalue *pval, struct svalue *msp, int pos, int max) { if (pos >= max) - return; + return; if ((pval) && (msp[pos].type == T_LVALUE)) - assign_svalue(msp[pos].u.lvalue, pval); + assign_svalue(msp[pos].u.lvalue, pval); } /* - * Function name: slice_words - * Description: Gives an imploded string of words from an array - * Arguments: wvec: array of words - * from: First word to use - * to: Last word to use - * Returns: A pointer to a static svalue now containing string. + * Function name: slice_words + * Description: Gives an imploded string of words from an array + * Arguments: wvec: array of words + * from: First word to use + * to: Last word to use + * Returns: A pointer to a static svalue now containing string. */ struct svalue * slice_words(struct vector *wvec, int from, int to) { - struct vector *slice; - char *tx; + struct vector *slice; + char *tx; static struct svalue stmp = { T_NUMBER }; tx = 0; if (from <= to) { - slice = slice_array(wvec, from, to); + slice = slice_array(wvec, from, to); - if (slice->size) - tx = implode_string(slice, " "); - free_vector(slice); + if (slice->size) + tx = implode_string(slice, " "); + free_vector(slice); } free_svalue(&stmp); /* May be allocated! */ if (tx) { - stmp.type = T_STRING; - stmp.string_type = STRING_MSTRING; - stmp.u.string = tx; + stmp.type = T_STRING; + stmp.string_type = STRING_MSTRING; + stmp.u.string = tx; } else { - stmp.type = T_STRING; - stmp.string_type = STRING_CSTRING; - stmp.u.string = ""; + stmp.type = T_STRING; + stmp.string_type = STRING_CSTRING; + stmp.u.string = ""; } return &stmp; } /* - * Function name: sub_parse - * Description: Parses a vector of words against a pattern. Gives - * result as an svalue. Sets fail if parsing fails and - * updates pointers in pattern and word vectors. It - * handles alternate patterns but not "%s" + * Function name: sub_parse + * Description: Parses a vector of words against a pattern. Gives + * result as an svalue. Sets fail if parsing fails and + * updates pointers in pattern and word vectors. It + * handles alternate patterns but not "%s" */ struct svalue * sub_parse(struct vector *obvec, struct vector *patvec, int *pix_in, - struct vector *wvec, int *cix_in, int *fail, struct svalue *msp) + struct vector *wvec, int *cix_in, int *fail, struct svalue *msp) { - int cix, pix, subfail; - struct svalue *pval; - struct svalue *one_parse(struct vector *, char *, struct vector *, - int *, int *, struct svalue *); + int cix, pix, subfail; + struct svalue *pval; + struct svalue *one_parse(struct vector *, char *, struct vector *, + int *, int *, struct svalue *); cix = *cix_in; pix = *pix_in; subfail = 0; pval = one_parse(obvec, patvec->item[pix].u.string, - wvec, &cix, &subfail, msp); + wvec, &cix, &subfail, msp); while (subfail) { - pix++; - cix = *cix_in; - - /* - Find the next alternative pattern, consecutive '/' are skipped - */ - while ((pix < patvec->size) && (EQ(patvec->item[pix].u.string, "/"))) - { - subfail = 0; - pix++; - } - - if (!subfail && (pix < patvec->size)) - { - pval = one_parse(obvec, patvec->item[pix].u.string, wvec, &cix, - &subfail, msp); - } - else if (subfail == 2) /* failed optional */ - { - subfail = 0; - pix = pix-1; - } - else - { - *fail = 1; *pix_in = pix-1; - return 0; - } + pix++; + cix = *cix_in; + + /* + Find the next alternative pattern, consecutive '/' are skipped + */ + while ((pix < patvec->size) && (EQ(patvec->item[pix].u.string, "/"))) + { + subfail = 0; + pix++; + } + + if (!subfail && (pix < patvec->size)) + { + pval = one_parse(obvec, patvec->item[pix].u.string, wvec, &cix, + &subfail, msp); + } + else if (subfail == 2) /* failed optional */ + { + subfail = 0; + pix = pix-1; + } + else + { + *fail = 1; *pix_in = pix-1; + return 0; + } } /* If there are alternatives left after the matching pattern, skip them */ if ((pix + 1 < patvec->size) && (EQ(patvec->item[pix + 1].u.string, "/"))) { - while ((pix + 1 size) && - (EQ(patvec->item[pix + 1].u.string, "/"))) - { - pix += 2; - } - if (pix>=patvec->size) - pix = patvec->size-1; + while ((pix + 1 size) && + (EQ(patvec->item[pix + 1].u.string, "/"))) + { + pix += 2; + } + if (pix>=patvec->size) + pix = patvec->size-1; } *cix_in = cix; @@ -826,115 +826,115 @@ sub_parse(struct vector *obvec, struct vector *patvec, int *pix_in, /* - * Function name: one_parse - * Description: Checks one parse pattern to see if match. Consumes - * needed number of words from wvec. - * Arguments: obvec: Vector of objects relevant to parse - * pat: The pattern to match against. - * wvec: Vector of words in the command to parse - * cix_in: Current word in commandword vector - * fail: Fail flag if parse did not match - * prep_param: Only used on %p (see prepos_parse) - * Returns: svalue holding result of parse. + * Function name: one_parse + * Description: Checks one parse pattern to see if match. Consumes + * needed number of words from wvec. + * Arguments: obvec: Vector of objects relevant to parse + * pat: The pattern to match against. + * wvec: Vector of words in the command to parse + * cix_in: Current word in commandword vector + * fail: Fail flag if parse did not match + * prep_param: Only used on %p (see prepos_parse) + * Returns: svalue holding result of parse. */ struct svalue * one_parse(struct vector *obvec, char *pat, struct vector *wvec, int *cix_in, - int *fail, struct svalue *prep_param) + int *fail, struct svalue *prep_param) { - struct svalue *pval; + struct svalue *pval; static struct svalue stmp = { T_NUMBER }; - char *str1, *str2; - struct svalue *item_parse(struct vector *, struct vector *, int *, int *); - struct svalue *living_parse(struct vector *, struct vector *, int *, int *); - struct svalue *single_parse(struct vector *, struct vector *, int *, int *); - struct svalue *prepos_parse(struct vector *, int *, int *, struct svalue *); - struct svalue *number_parse(struct vector *, int *, int *); + char *str1, *str2; + struct svalue *item_parse(struct vector *, struct vector *, int *, int *); + struct svalue *living_parse(struct vector *, struct vector *, int *, int *); + struct svalue *single_parse(struct vector *, struct vector *, int *, int *); + struct svalue *prepos_parse(struct vector *, int *, int *, struct svalue *); + struct svalue *number_parse(struct vector *, int *, int *); /* - Fail if we have a pattern left but no words to parse + Fail if we have a pattern left but no words to parse */ if (*cix_in >= wvec->size) { - if (pat[0] == '[') - *fail = 0; - else - *fail = 1; - return 0; + if (pat[0] == '[') + *fail = 0; + else + *fail = 1; + return 0; } pval = 0; switch (pat[0]) { - case '%': - switch (pat[1]) { - case 'i': - pval = item_parse(obvec, wvec, cix_in, fail); - break; - - case 'l': - pval = living_parse(obvec, wvec, cix_in, fail); - break; - - case 's': - *fail = 0; /* This is double %s in pattern, skip it */ - break; - - case 'w': - free_svalue(&stmp); - stmp.type = T_STRING; - stmp.string_type = STRING_SSTRING; - stmp.u.string = make_sstring(wvec->item[*cix_in].u.string); - pval = &stmp; - (*cix_in)++; - *fail = 0; - break; - - case 'o': - pval = single_parse(obvec, wvec, cix_in, fail); - break; - - case 'p': - pval = prepos_parse(wvec, cix_in, fail, prep_param); - break; - - case 'd': - pval = number_parse(wvec, cix_in, fail); - break; - default: - warning("Invalid pattern in parse_command: %s\n", pat); - break; - } - break; - - case '\'': - str1 = &pat[1]; str2 = wvec->item[*cix_in].u.string; - if ((strncmp(str1, str2, strlen(str1) - 1) == 0) && - (strlen(str1) == strlen(str2) + 1)) - { - *fail = 0; - (*cix_in)++; - } - else - *fail = 1; - break; - - case '[': - str1 = &pat[1]; str2 = wvec->item[*cix_in].u.string; - if ((strncmp(str1, str2, strlen(str1) - 1) == 0) && - (strlen(str1) == strlen(str2) + 1)) - { - (*cix_in)++; - *fail = 0; - } - else - { - *fail = 2; - } - break; - - default: - warning("%s: Invalid pattern in parse_command: %s\n", current_object->name, pat); - *fail = 0; /* Skip invalid patterns */ + case '%': + switch (pat[1]) { + case 'i': + pval = item_parse(obvec, wvec, cix_in, fail); + break; + + case 'l': + pval = living_parse(obvec, wvec, cix_in, fail); + break; + + case 's': + *fail = 0; /* This is double %s in pattern, skip it */ + break; + + case 'w': + free_svalue(&stmp); + stmp.type = T_STRING; + stmp.string_type = STRING_SSTRING; + stmp.u.string = make_sstring(wvec->item[*cix_in].u.string); + pval = &stmp; + (*cix_in)++; + *fail = 0; + break; + + case 'o': + pval = single_parse(obvec, wvec, cix_in, fail); + break; + + case 'p': + pval = prepos_parse(wvec, cix_in, fail, prep_param); + break; + + case 'd': + pval = number_parse(wvec, cix_in, fail); + break; + default: + warning("Invalid pattern in parse_command: %s\n", pat); + break; + } + break; + + case '\'': + str1 = &pat[1]; str2 = wvec->item[*cix_in].u.string; + if ((strncmp(str1, str2, strlen(str1) - 1) == 0) && + (strlen(str1) == strlen(str2) + 1)) + { + *fail = 0; + (*cix_in)++; + } + else + *fail = 1; + break; + + case '[': + str1 = &pat[1]; str2 = wvec->item[*cix_in].u.string; + if ((strncmp(str1, str2, strlen(str1) - 1) == 0) && + (strlen(str1) == strlen(str2) + 1)) + { + (*cix_in)++; + *fail = 0; + } + else + { + *fail = 2; + } + break; + + default: + warning("%s: Invalid pattern in parse_command: %s\n", current_object->name, pat); + *fail = 0; /* Skip invalid patterns */ } return pval; } @@ -973,39 +973,39 @@ number_parse(struct vector *wvec, int *cix_in, int *fail) #ifndef PARSE_FOREIGN static char *ord1[] = {"", "first", "second", "third", "fourth", "fifth", - "sixth", "seventh", "eighth", "ninth", "tenth", - "eleventh", "twelfth", "thirteenth", "fourteenth", - "fifteenth", "sixteenth", "seventeenth", - "eighteenth","nineteenth"}; + "sixth", "seventh", "eighth", "ninth", "tenth", + "eleventh", "twelfth", "thirteenth", "fourteenth", + "fifteenth", "sixteenth", "seventeenth", + "eighteenth","nineteenth"}; static char *ord10[] = {"", "", "twenty","thirty","forty","fifty","sixty", - "seventy", "eighty","ninety"}; + "seventy", "eighty","ninety"}; static char *sord10[] = {"", "", "twentieth", "thirtieth", "fortieth", - "fiftieth", "sixtieth","seventieth", "eightieth", - "ninetieth"}; + "fiftieth", "sixtieth","seventieth", "eightieth", + "ninetieth"}; static char *num1[] = {"", "one","two","three","four","five","six", - "seven","eight","nine","ten", - "eleven","twelve","thirteen","fourteen","fifteen", - "sixteen", "seventeen","eighteen","nineteen"}; + "seven","eight","nine","ten", + "eleven","twelve","thirteen","fourteen","fifteen", + "sixteen", "seventeen","eighteen","nineteen"}; static char *num10[] = {"", "", "twenty","thirty","forty","fifty","sixty", - "seventy", "eighty","ninety"}; + "seventy", "eighty","ninety"}; #endif /* - * Function name: number_parse - * Description: Tries to interpret the word in wvec as a numeral - * descriptor and returns the result on the form: - * ret.type == T_NUMBER - * num == 0, 'zero', '0', gAllword - * num > 0, one, two, three etc or numbers given - * num < 0, first, second,third etc given - * Arguments: wvec: Vector of words in the command to parse - * cix_in: Current word in commandword vector - * fail: Fail flag if parse did not match - * Returns: svalue holding result of parse. + * Function name: number_parse + * Description: Tries to interpret the word in wvec as a numeral + * descriptor and returns the result on the form: + * ret.type == T_NUMBER + * num == 0, 'zero', '0', gAllword + * num > 0, one, two, three etc or numbers given + * num < 0, first, second,third etc given + * Arguments: wvec: Vector of words in the command to parse + * cix_in: Current word in commandword vector + * fail: Fail flag if parse did not match + * Returns: svalue holding result of parse. */ struct svalue * item_number_parse(struct vector *wvec, int *cix_in, int *fail) @@ -1013,7 +1013,7 @@ item_number_parse(struct vector *wvec, int *cix_in, int *fail) int cix, ten, ones; long long num; char buf[100]; - static struct svalue stmp; /* No need to free, only numbers */ + static struct svalue stmp; /* No need to free, only numbers */ cix = *cix_in; *fail = 0; @@ -1022,15 +1022,15 @@ item_number_parse(struct vector *wvec, int *cix_in, int *fail) if (matches == 1) { - if (num > 0) - { - (*cix_in)++; - stmp.type = T_NUMBER; - stmp.u.number = num; - return &stmp; - } - *fail = 1; - return 0; /* Only positive numbers */ + if (num > 0) + { + (*cix_in)++; + stmp.type = T_NUMBER; + stmp.u.number = num; + return &stmp; + } + *fail = 1; + return 0; /* Only positive numbers */ } if (matches == 2) @@ -1061,39 +1061,39 @@ item_number_parse(struct vector *wvec, int *cix_in, int *fail) if (gAllword && (strcmp(wvec->item[cix].u.string, gAllword) == 0)) { - (*cix_in)++; - stmp.type = T_NUMBER; - stmp.u.number = 0; - return &stmp; + (*cix_in)++; + stmp.type = T_NUMBER; + stmp.u.number = 0; + return &stmp; } for (ten = 0; ten < 10; ten++) - for(ones = 0; ones < 10; ones++) - { - (void)sprintf(buf,"%s%s", num10[ten], - (ten > 1) ? num1[ones] : num1[ten * 10 + ones]); - if (EQ(buf, wvec->item[cix].u.string)) - { - (*cix_in)++; - stmp.type = T_NUMBER; - stmp.u.number = ten * 10 + ones; - return &stmp; - } - } + for(ones = 0; ones < 10; ones++) + { + (void)sprintf(buf,"%s%s", num10[ten], + (ten > 1) ? num1[ones] : num1[ten * 10 + ones]); + if (EQ(buf, wvec->item[cix].u.string)) + { + (*cix_in)++; + stmp.type = T_NUMBER; + stmp.u.number = ten * 10 + ones; + return &stmp; + } + } for (ten = 0; ten < 10; ten++) - for(ones = 0; ones < 10; ones++) - { - (void)sprintf(buf,"%s%s", (ones) ? ord10[ten] : sord10[ten], - (ten > 1) ? ord1[ones] : ord1[ten * 10 + ones]); - if (EQ(buf, wvec->item[cix].u.string)) - { - (*cix_in)++; - stmp.type = T_NUMBER; - stmp.u.number = -(ten * 10 + ones); - return &stmp; - } - } + for(ones = 0; ones < 10; ones++) + { + (void)sprintf(buf,"%s%s", (ones) ? ord10[ten] : sord10[ten], + (ten > 1) ? ord1[ones] : ord1[ten * 10 + ones]); + if (EQ(buf, wvec->item[cix].u.string)) + { + (*cix_in)++; + stmp.type = T_NUMBER; + stmp.u.number = -(ten * 10 + ones); + return &stmp; + } + } *fail = 1; return 0; @@ -1101,91 +1101,91 @@ item_number_parse(struct vector *wvec, int *cix_in, int *fail) /* - * Function name: item_parse - * Description: Tries to match as many objects in obvec as possible - * onto the description given in commandvector wvec. - * Also finds numeral description if one exist and returns - * that as first element in array: - * ret[0].type == T_NUMBER - * num == 0, 'all' or 'general plural given' - * num > 0, one, two, three etc given - * num < 0, first, second,third etc given - * ret[1-n] == Selected objectpointers from obvec - * Arguments: obvec: Vector of objects relevant to parse - * wvec: Vector of words in the command to parse - * cix_in: Current word in commandword vector - * fail: Fail flag if parse did not match - * Returns: svalue holding result of parse. + * Function name: item_parse + * Description: Tries to match as many objects in obvec as possible + * onto the description given in commandvector wvec. + * Also finds numeral description if one exist and returns + * that as first element in array: + * ret[0].type == T_NUMBER + * num == 0, 'all' or 'general plural given' + * num > 0, one, two, three etc given + * num < 0, first, second,third etc given + * ret[1-n] == Selected objectpointers from obvec + * Arguments: obvec: Vector of objects relevant to parse + * wvec: Vector of words in the command to parse + * cix_in: Current word in commandword vector + * fail: Fail flag if parse did not match + * Returns: svalue holding result of parse. */ struct svalue * item_parse(struct vector *obvec, struct vector *wvec, int *cix_in, int *fail) { - struct vector *tmp, *ret; - struct svalue *pval; + struct vector *tmp, *ret; + struct svalue *pval; static struct svalue stmp = { T_NUMBER }; - int cix, tix, obix, plur_flag, max_cix, match_all; - int match_object(int, struct vector *, int *, int *); + int cix, tix, obix, plur_flag, max_cix, match_all; + int match_object(int, struct vector *, int *, int *); tmp = allocate_array(obvec->size + 1); if ((pval = item_number_parse(wvec, cix_in, fail)) != NULL ) - assign_svalue_no_free(&tmp->item[0],pval); + assign_svalue_no_free(&tmp->item[0],pval); if ((pval) && (pval->u.number>1)) { - plur_flag = 1; - match_all = 0; + plur_flag = 1; + match_all = 0; } else if ((pval) && (pval->u.number == 0)) { - plur_flag = 1; - match_all = 1; + plur_flag = 1; + match_all = 1; } else { - plur_flag = 0; - match_all = 0; + plur_flag = 0; + match_all = 0; } max_cix = *cix_in; tix = 1; for (obix = 0; obix < obvec->size; obix++) { - *fail = 0; cix = *cix_in; - if (obvec->item[obix].type != T_OBJECT) - continue; - if (cix == wvec->size && match_all) - { - assign_svalue_no_free(&tmp->item[tix++], &obvec->item[obix]); - continue; - } - load_lpc_info(obix, obvec->item[obix].u.ob); - - if (match_object(obix, wvec, &cix, &plur_flag)) - { - assign_svalue_no_free(&tmp->item[tix++], &obvec->item[obix]); - max_cix = (max_cixitem[obix].type != T_OBJECT) + continue; + if (cix == wvec->size && match_all) + { + assign_svalue_no_free(&tmp->item[tix++], &obvec->item[obix]); + continue; + } + load_lpc_info(obix, obvec->item[obix].u.ob); + + if (match_object(obix, wvec, &cix, &plur_flag)) + { + assign_svalue_no_free(&tmp->item[tix++], &obvec->item[obix]); + max_cix = (max_cixsize) - *cix_in = max_cix + 1; - ret = slice_array(tmp, 0, tix - 1); - if (!pval) - { - ret->item[0].type = T_NUMBER; - ret->item[0].u.number = plur_flag ? 0 : 1; - } - free_vector(tmp); + if (*cix_in < wvec->size) + *cix_in = max_cix + 1; + ret = slice_array(tmp, 0, tix - 1); + if (!pval) + { + ret->item[0].type = T_NUMBER; + ret->item[0].u.number = plur_flag ? 0 : 1; + } + free_vector(tmp); } /* stmp is static, and may contain old info that must be freed @@ -1197,52 +1197,52 @@ item_parse(struct vector *obvec, struct vector *wvec, int *cix_in, int *fail) } /* - * Function name: living_parse - * Description: Tries to match as many living objects in obvec as - * possible onto the description given in the command- - * vector wvec. - * Also finds numeral description if one exist and returns - * that as first element in array: - * ret[0].type == T_NUMBER - * num == 0, 'all' or 'general plural given' - * num > 0, one, two, three etc given - * num < 0, first, second,third etc given - * ret[1-n] == Selected objectpointers from obvec - * If not found in obvec a find_player and - * lastly a find_living is done. These will return an - * objecttype svalue. - * Arguments: obvec: Vector of objects relevant to parse - * wvec: Vector of words in the command to parse - * cix_in: Current word in commandword vector - * fail: Fail flag if parse did not match - * Returns: svalue holding result of parse. + * Function name: living_parse + * Description: Tries to match as many living objects in obvec as + * possible onto the description given in the command- + * vector wvec. + * Also finds numeral description if one exist and returns + * that as first element in array: + * ret[0].type == T_NUMBER + * num == 0, 'all' or 'general plural given' + * num > 0, one, two, three etc given + * num < 0, first, second,third etc given + * ret[1-n] == Selected objectpointers from obvec + * If not found in obvec a find_player and + * lastly a find_living is done. These will return an + * objecttype svalue. + * Arguments: obvec: Vector of objects relevant to parse + * wvec: Vector of words in the command to parse + * cix_in: Current word in commandword vector + * fail: Fail flag if parse did not match + * Returns: svalue holding result of parse. */ struct svalue * living_parse(struct vector *obvec, struct vector *wvec, int *cix_in, int *fail) { - struct vector *live; - struct svalue *pval; + struct vector *live; + struct svalue *pval; static struct svalue stmp = { T_NUMBER }; - struct object *ob; - int obix, tix; + struct object *ob; + int obix, tix; live = allocate_array(obvec->size); tix = 0; *fail = 0; for (obix = 0; obix < obvec->size; obix++) - if (obvec->item[obix].type == T_OBJECT && - obvec->item[obix].u.ob->flags & O_ENABLE_COMMANDS) - assign_svalue_no_free(&live->item[tix++], &obvec->item[obix]); + if (obvec->item[obix].type == T_OBJECT && + obvec->item[obix].u.ob->flags & O_ENABLE_COMMANDS) + assign_svalue_no_free(&live->item[tix++], &obvec->item[obix]); if (tix) { - pval = item_parse(live, wvec, cix_in, fail); - if (pval) - { - free_vector(live); - return pval; - } + pval = item_parse(live, wvec, cix_in, fail); + if (pval) + { + free_vector(live); + return pval; + } } free_vector(live); @@ -1251,46 +1251,46 @@ living_parse(struct vector *obvec, struct vector *wvec, int *cix_in, int *fail) ob = find_living_object(wvec->item[*cix_in].u.string); if (ob) { - free_svalue(&stmp); /* Might be allocated */ - stmp.type = T_OBJECT; - stmp.u.ob = ob; - add_ref(ob, "living_parse"); - (*cix_in)++; - return &stmp; + free_svalue(&stmp); /* Might be allocated */ + stmp.type = T_OBJECT; + stmp.u.ob = ob; + add_ref(ob, "living_parse"); + (*cix_in)++; + return &stmp; } *fail = 1; return 0; } /* - * Function name: single_parse - * Description: Finds the first object in obvec fitting the description - * in commandvector wvec. Gives this as an objectpointer. - * Arguments: obvec: Vector of objects relevant to parse - * wvec: Vector of words in the command to parse - * cix_in: Current word in commandword vector - * fail: Fail flag if parse did not match - * Returns: svalue holding result of parse. + * Function name: single_parse + * Description: Finds the first object in obvec fitting the description + * in commandvector wvec. Gives this as an objectpointer. + * Arguments: obvec: Vector of objects relevant to parse + * wvec: Vector of words in the command to parse + * cix_in: Current word in commandword vector + * fail: Fail flag if parse did not match + * Returns: svalue holding result of parse. */ struct svalue * single_parse(struct vector *obvec, struct vector *wvec, int *cix_in, int *fail) { - int cix, obix, plur_flag; - int match_object(int, struct vector *, int *, int *); + int cix, obix, plur_flag; + int match_object(int, struct vector *, int *, int *); for (obix = 0; obix < obvec->size; obix++) { - if (obvec->item[obix].type != T_OBJECT) - continue; - *fail = 0; - cix = *cix_in; - load_lpc_info(obix, obvec->item[obix].u.ob); - plur_flag = 0; - if (match_object(obix, wvec, &cix, &plur_flag)) - { - *cix_in = cix + 1; - return &obvec->item[obix]; - } + if (obvec->item[obix].type != T_OBJECT) + continue; + *fail = 0; + cix = *cix_in; + load_lpc_info(obix, obvec->item[obix].u.ob); + plur_flag = 0; + if (match_object(obix, wvec, &cix, &plur_flag)) + { + *cix_in = cix + 1; + return &obvec->item[obix]; + } } *fail = 1; return 0; @@ -1298,91 +1298,91 @@ single_parse(struct vector *obvec, struct vector *wvec, int *cix_in, int *fail) /* - * Function name: prepos_parse - * Description: This is a general sentencelist matcher with some hard- - * coded prepositions as the default list. The list is - * sent as a parameter which will be replaced in the - * destination values. If no list is given the return - * value on match with the hardcoded prepositions will be - * string. If a list is given, the list will be returned - * with the matched sentence swapped to the first element. - * Arguments: wvec: Vector of words in the command to parse - * cix_in: Current word in commandword vector - * fail: Fail flag if parse did not match - * prepos: Pointer to svalue holding prepos parameter. - * Returns: svalue holding result of parse. + * Function name: prepos_parse + * Description: This is a general sentencelist matcher with some hard- + * coded prepositions as the default list. The list is + * sent as a parameter which will be replaced in the + * destination values. If no list is given the return + * value on match with the hardcoded prepositions will be + * string. If a list is given, the list will be returned + * with the matched sentence swapped to the first element. + * Arguments: wvec: Vector of words in the command to parse + * cix_in: Current word in commandword vector + * fail: Fail flag if parse did not match + * prepos: Pointer to svalue holding prepos parameter. + * Returns: svalue holding result of parse. */ struct svalue * prepos_parse(struct vector *wvec, int *cix_in, int *fail, - struct svalue *prepos) + struct svalue *prepos) { - struct vector *pvec, *tvec; + struct vector *pvec, *tvec; static struct svalue stmp = { T_NUMBER }; char *tmp; int pix, tix; if ((!prepos) || (prepos->type != T_POINTER)) { - pvec = gPrepos_list; + pvec = gPrepos_list; } else { - pvec = prepos->u.vec; + pvec = prepos->u.vec; } for (pix = 0; pix < pvec->size; pix++) { - if (pvec->item[pix].type != T_STRING) - continue; - - tmp = pvec->item[pix].u.string; - if (strchr(tmp,' ') == NULL) - { - if (EQ(tmp, wvec->item[*cix_in].u.string)) - { - (*cix_in)++; - break; - } - } - else - { - tvec = explode_string(tmp, " "); - for (tix = 0; tix < tvec->size; tix++) - { - if ((*cix_in+tix >= wvec->size) || - (!EQ(wvec->item[*cix_in+tix].u.string, tvec->item[tix].u.string))) - break; - } - if ( (tix = (tix == tvec->size) ? 1 : 0) != 0 ) - (*cix_in) += tvec->size; - free_vector(tvec); - if (tix) - break; - } + if (pvec->item[pix].type != T_STRING) + continue; + + tmp = pvec->item[pix].u.string; + if (strchr(tmp,' ') == NULL) + { + if (EQ(tmp, wvec->item[*cix_in].u.string)) + { + (*cix_in)++; + break; + } + } + else + { + tvec = explode_string(tmp, " "); + for (tix = 0; tix < tvec->size; tix++) + { + if ((*cix_in+tix >= wvec->size) || + (!EQ(wvec->item[*cix_in+tix].u.string, tvec->item[tix].u.string))) + break; + } + if ( (tix = (tix == tvec->size) ? 1 : 0) != 0 ) + (*cix_in) += tvec->size; + free_vector(tvec); + if (tix) + break; + } } free_svalue(&stmp); if (pix == pvec->size) { - stmp.type = T_NUMBER; - stmp.u.number = 0; - *fail = 1; + stmp.type = T_NUMBER; + stmp.u.number = 0; + *fail = 1; } else if (pvec != gPrepos_list) { - stmp = pvec->item[0]; - pvec->item[0] = pvec->item[pix]; - pvec->item[pix] = stmp; - *fail = 0; - assign_svalue_no_free(&stmp, prepos); + stmp = pvec->item[0]; + pvec->item[0] = pvec->item[pix]; + pvec->item[pix] = stmp; + *fail = 0; + assign_svalue_no_free(&stmp, prepos); } else { - stmp.type = T_STRING; - stmp.string_type = STRING_MSTRING; - stmp.u.string = make_mstring(pvec->item[pix].u.string); - *fail = 0; + stmp.type = T_STRING; + stmp.string_type = STRING_MSTRING; + stmp.u.string = make_mstring(pvec->item[pix].u.string); + *fail = 0; } return &stmp; @@ -1390,97 +1390,97 @@ prepos_parse(struct vector *wvec, int *cix_in, int *fail, } /* - * Function name: match_object - * Description: Tests if a given object matches the description as - * given in the commandvector wvec. - * Arguments: obix: Index in id arrays for this object. - * wvec: Vector of words in the command to parse - * cix_in: Current word in commandword vector - * plur: This arg gets set if the noun was on pluralform - * Returns: True if object matches. + * Function name: match_object + * Description: Tests if a given object matches the description as + * given in the commandvector wvec. + * Arguments: obix: Index in id arrays for this object. + * wvec: Vector of words in the command to parse + * cix_in: Current word in commandword vector + * plur: This arg gets set if the noun was on pluralform + * Returns: True if object matches. */ int match_object(int obix, struct vector *wvec, int *cix_in, int *plur) { - struct vector *ids; - int il, pos, cplur, old_cix; - char *str; - int find_string(char *, struct vector *, int *); - int check_adjectiv(int, struct vector *, int, int); + struct vector *ids; + int il, pos, cplur, old_cix; + char *str; + int find_string(char *, struct vector *, int *); + int check_adjectiv(int, struct vector *, int, int); for (cplur = (*plur * 2); cplur < 4; cplur++) { - switch (cplur) - { - case 0: - if (!gId_list_d) - continue; - ids = gId_list_d; - break; - - case 1: - if (!gId_list || - gId_list->size <= obix || - gId_list->item[obix].type != T_POINTER) - continue; - ids = gId_list->item[obix].u.vec; - break; - - case 2: - if (!gPluid_list_d) - continue; - ids = gPluid_list_d; - break; - - case 3: - if (!gPluid_list || - gPluid_list->size <= obix || - gPluid_list->item[obix].type != T_POINTER) - continue; - ids = gPluid_list->item[obix].u.vec; - break; - - default: + switch (cplur) + { + case 0: + if (!gId_list_d) + continue; + ids = gId_list_d; + break; + + case 1: + if (!gId_list || + gId_list->size <= obix || + gId_list->item[obix].type != T_POINTER) + continue; + ids = gId_list->item[obix].u.vec; + break; + + case 2: + if (!gPluid_list_d) + continue; + ids = gPluid_list_d; + break; + + case 3: + if (!gPluid_list || + gPluid_list->size <= obix || + gPluid_list->item[obix].type != T_POINTER) + continue; + ids = gPluid_list->item[obix].u.vec; + break; + + default: return 0; - } - - for (il = 0; il < ids->size; il++) - { - if (ids->item[il].type == T_STRING) - { - str = ids->item[il].u.string; /* A given id of the object */ - old_cix = *cix_in; - if ((pos = find_string(str, wvec, cix_in)) >= 0) - { - if (pos == old_cix) - { - if (cplur > 1) - *plur = 1; - return 1; - } - else if (check_adjectiv(obix, wvec, old_cix, pos-1)) - { - if (cplur > 1) - *plur = 1; - return 1; - } - } - *cix_in = old_cix; - } - } + } + + for (il = 0; il < ids->size; il++) + { + if (ids->item[il].type == T_STRING) + { + str = ids->item[il].u.string; /* A given id of the object */ + old_cix = *cix_in; + if ((pos = find_string(str, wvec, cix_in)) >= 0) + { + if (pos == old_cix) + { + if (cplur > 1) + *plur = 1; + return 1; + } + else if (check_adjectiv(obix, wvec, old_cix, pos-1)) + { + if (cplur > 1) + *plur = 1; + return 1; + } + } + *cix_in = old_cix; + } + } } return 0; } /* - * Function name: find_string - * Description: Finds out if a given string exist within an - * array of words. - * Arguments: str: String of some words - * wvec: Array of words - * cix_in: Startpos in word array - * Returns: Pos in array if string found or -1 + * Function name: find_string + * Description: Finds out if a given string exist within an + * array of words. + * Arguments: str: String of some words + * wvec: Array of words + * cix_in: Startpos in word array + * Returns: Pos in array if string found or -1 */ int find_string(char *str, struct vector *wvec, int *cix_in) @@ -1491,67 +1491,67 @@ find_string(char *str, struct vector *wvec, int *cix_in) #ifndef OLD_EXPLODE while (*cix_in < wvec->size && !*(wvec->item[*cix_in].u.string)) - (*cix_in)++; + (*cix_in)++; #endif for (; *cix_in < wvec->size; (*cix_in)++) { - p1 = wvec->item[*cix_in].u.string; - if (p1[0] != str[0]) - continue; + p1 = wvec->item[*cix_in].u.string; + if (p1[0] != str[0]) + continue; - if (strcmp(p1, str) == 0) /* str was one word and we found it */ - return *cix_in; + if (strcmp(p1, str) == 0) /* str was one word and we found it */ + return *cix_in; - if (strchr(str,' ') == NULL) - continue; + if (strchr(str,' ') == NULL) + continue; - /* If str was multi word we need to make som special checks + /* If str was multi word we need to make som special checks */ - if (*cix_in == (wvec->size -1)) - continue; + if (*cix_in == (wvec->size -1)) + continue; - split = explode_string(str," "); + split = explode_string(str," "); - /* - wvec->size - *cix_in == 2: One extra word - 3: Two extra words + /* + wvec->size - *cix_in == 2: One extra word + 3: Two extra words */ - if (!split || (split->size > (wvec->size - *cix_in))) - { - if (split) - free_vector(split); - continue; - } - - fpos = *cix_in; - for (; (*cix_in-fpos) < split->size; (*cix_in)++) - { - if (strcmp(split->item[*cix_in-fpos].u.string, - wvec->item[*cix_in].u.string)) - break; - } - if ((*cix_in - fpos) == split->size) { - free_vector(split); - return fpos; - } - free_vector(split); - - *cix_in = fpos; + if (!split || (split->size > (wvec->size - *cix_in))) + { + if (split) + free_vector(split); + continue; + } + + fpos = *cix_in; + for (; (*cix_in-fpos) < split->size; (*cix_in)++) + { + if (strcmp(split->item[*cix_in-fpos].u.string, + wvec->item[*cix_in].u.string)) + break; + } + if ((*cix_in - fpos) == split->size) { + free_vector(split); + return fpos; + } + free_vector(split); + + *cix_in = fpos; } return -1; } /* - * Function name: check_adjectiv - * Description: Checks a word to see if it fits as adjectiv of an - * object. - * Arguments: obix: The index in the global id arrays - * wvec: The command words - * from: #1 cmdword to test - * to: last cmdword to test - * Returns: True if a match is made. + * Function name: check_adjectiv + * Description: Checks a word to see if it fits as adjectiv of an + * object. + * Arguments: obix: The index in the global id arrays + * wvec: The command words + * from: #1 cmdword to test + * to: last cmdword to test + * Returns: True if a match is made. */ int check_adjectiv(int obix, struct vector *wvec, int from, int to) @@ -1563,29 +1563,29 @@ check_adjectiv(int obix, struct vector *wvec, int from, int to) int member_string(char *, struct vector *); if (gAdjid_list->item[obix].type == T_POINTER) - ids = gAdjid_list->item[obix].u.vec; + ids = gAdjid_list->item[obix].u.vec; else - ids = 0; + ids = 0; sum = 0; fail = 0; for (il = from; il<= to; il++) { - sum += strlen(wvec->item[il].u.string) + 1; - if ((member_string(wvec->item[il].u.string, ids) < 0) && - (member_string(wvec->item[il].u.string, gAdjid_list_d) < 0)) - { - fail = 1; - } + sum += strlen(wvec->item[il].u.string) + 1; + if ((member_string(wvec->item[il].u.string, ids) < 0) && + (member_string(wvec->item[il].u.string, gAdjid_list_d) < 0)) + { + fail = 1; + } } /* Simple case: all adjs were single word */ if (!fail) - return 1; + return 1; if (from == to) - return 0; + return 0; adstr = alloca(sum); @@ -1608,40 +1608,40 @@ check_adjectiv(int obix, struct vector *wvec, int from, int to) for (il = from; il <= to;) /* adj1 .. adjN */ #endif { - for (back = to; back >= il; back--) /* back from adjN to adj[il] */ - { - /* + for (back = to; back >= il; back--) /* back from adjN to adj[il] */ + { + /* * Create teststring with "adj[il] .. adj[back]" */ - (void)strcpy(adstr, ""); - for (sum = il; sum <= back; sum++) /* test "adj[il] .. adj[back] */ - { - if (sum > il) - (void)strcat(adstr, " "); - (void)strcat(adstr, wvec->item[sum].u.string); - } - if ((member_string(adstr, ids) < 0) && - (member_string(adstr, gAdjid_list_d) < 0)) - continue; + (void)strcpy(adstr, ""); + for (sum = il; sum <= back; sum++) /* test "adj[il] .. adj[back] */ + { + if (sum > il) + (void)strcat(adstr, " "); + (void)strcat(adstr, wvec->item[sum].u.string); + } + if ((member_string(adstr, ids) < 0) && + (member_string(adstr, gAdjid_list_d) < 0)) + continue; else - { + { back = 0; - break; - } - } + break; + } + } if (back) - return 0; /* adj[il] does not match at all => no match */ + return 0; /* adj[il] does not match at all => no match */ } return 1; } /* - * Function name: member_string - * Description: Checks if a string is a member of an array. - * Arguments: str: The string to search for - * svec: vector of strings - * Returns: Pos if found else -1. + * Function name: member_string + * Description: Checks if a string is a member of an array. + * Arguments: str: The string to search for + * svec: vector of strings + * Returns: Pos if found else -1. */ int member_string(char *str, struct vector *svec) @@ -1649,70 +1649,70 @@ member_string(char *str, struct vector *svec) int il; if (!svec) - return -1; + return -1; for (il = 0; il < svec->size; il++) { - if (svec->item[il].type != T_STRING) - continue; + if (svec->item[il].type != T_STRING) + continue; - if (strcmp(svec->item[il].u.string, str) == 0) - return il; + if (strcmp(svec->item[il].u.string, str) == 0) + return il; } return -1; } #ifndef PARSE_FOREIGN /* - * Function name: parse_to_plural - * Description: Change a sentence in singular form to a sentence - * in pluralform. - * Arguments: str: The sentence to change - * Returns: Sentence in plural form. + * Function name: parse_to_plural + * Description: Change a sentence in singular form to a sentence + * in pluralform. + * Arguments: str: The sentence to change + * Returns: Sentence in plural form. */ char * parse_to_plural(char *str) { - struct vector *words; - struct svalue stmp; + struct vector *words; + struct svalue stmp; char *spl; int il, changed; - char *parse_one_plural(char *); + char *parse_one_plural(char *); if (!(strchr(str,' '))) - return make_mstring(parse_one_plural(str)); + return make_mstring(parse_one_plural(str)); words = explode_string(str, " "); #ifdef OLD_EXPLODE il = 1; #else for (il = 0 ; il < words->size ; il++) - if (*(words->item[il].u.string)) - break; + if (*(words->item[il].u.string)) + break; il++; #endif for (changed = 0; il < words->size; il++) { - if ((EQ(words->item[il].u.string, "of")) || - (il + 1 == words->size)) - { - spl = parse_one_plural(words->item[il - 1].u.string); - if (spl != words->item[il - 1].u.string) - { - stmp.type = T_STRING; - stmp.string_type = STRING_MSTRING; - stmp.u.string = make_mstring(spl); - assign_svalue(&words->item[il - 1], &stmp); - changed = 1; - free_svalue(&stmp); - } - } + if ((EQ(words->item[il].u.string, "of")) || + (il + 1 == words->size)) + { + spl = parse_one_plural(words->item[il - 1].u.string); + if (spl != words->item[il - 1].u.string) + { + stmp.type = T_STRING; + stmp.string_type = STRING_MSTRING; + stmp.u.string = make_mstring(spl); + assign_svalue(&words->item[il - 1], &stmp); + changed = 1; + free_svalue(&stmp); + } + } } if (!changed) { - free_vector(words); - return make_mstring(str); + free_vector(words); + return make_mstring(str); } str = implode_string(words, " "); free_vector(words); @@ -1721,22 +1721,22 @@ parse_to_plural(char *str) /* - * Function name: parse_one_plural - * Description: Change a noun in singularform to a noun - * in pluralform. - * Arguments: str: The sentence to change - * Returns: Word in plural form. + * Function name: parse_one_plural + * Description: Change a noun in singularform to a noun + * in pluralform. + * Arguments: str: The sentence to change + * Returns: Word in plural form. */ char * parse_one_plural(char *str) { - char ch, ch2, ch3; - int sl; - static char pbuf[100]; /* Words > 100 letters? In Wales maybe... */ + char ch, ch2, ch3; + int sl; + static char pbuf[100]; /* Words > 100 letters? In Wales maybe... */ sl = strlen(str) - 1; if ((sl < 2) || (sl > 90)) - return str; + return str; ch = str[sl]; ch2 = str[sl - 1]; @@ -1746,29 +1746,29 @@ parse_one_plural(char *str) switch (ch) { case 'h': - if (ch2 == 's' || ch2 == 'c') - return strcat(pbuf, "hes"); - /* FALLTHROUGH */ + if (ch2 == 's' || ch2 == 'c') + return strcat(pbuf, "hes"); + /* FALLTHROUGH */ case 'f': - return strcat(pbuf, "ves"); + return strcat(pbuf, "ves"); case 's': - return strcat(pbuf, "ses"); + return strcat(pbuf, "ses"); case 'x': - if (EQ(str,"ox")) - return "oxen"; - else - return strcat(pbuf, "xes"); + if (EQ(str,"ox")) + return "oxen"; + else + return strcat(pbuf, "xes"); case 'y': - if ((ch2 != 'a' && ch2 != 'e' && ch2 != 'i' && ch2 != 'o' && - ch2 != 'u') || (ch2 == 'u' && ch3 == 'q')) - return strcat(pbuf, "ies"); - /* FALLTHROUGH */ + if ((ch2 != 'a' && ch2 != 'e' && ch2 != 'i' && ch2 != 'o' && + ch2 != 'u') || (ch2 == 'u' && ch3 == 'q')) + return strcat(pbuf, "ies"); + /* FALLTHROUGH */ case 'e': - if (ch2 == 'f') - { - pbuf[sl - 1] = 0; - return strcat(pbuf, "ves"); - } + if (ch2 == 'f') + { + pbuf[sl - 1] = 0; + return strcat(pbuf, "ves"); + } } if (EQ(str,"corpse")) return "corpses"; @@ -1797,12 +1797,12 @@ parse_one_plural(char *str) /* process_string * * Description: Checks a string for the below occurences and replaces: - * Fixes a call to a named function if the value is on the + * Fixes a call to a named function if the value is on the * form: '@@function[:filename][|arg|arg]@@' Filename is * optional. - * Note that process_string does not recurse over returned - * replacement values. If a function returns another function - * description, that description will not be replaced. + * Note that process_string does not recurse over returned + * replacement values. If a function returns another function + * description, that description will not be replaced. * Example (added after reading TMI docs :-) * "You are chased by @@query_name:/obj/monster#123@@ eastward." * is replaced by: @@ -1811,8 +1811,8 @@ parse_one_plural(char *str) * * Note that both object and arguments are optional. * Arguments: str: A string containing text and function descriptions as - * as described above. - * Returns: String containing the result of all replacements. + * as described above. + * Returns: String containing the result of all replacements. */ char * process_string(char *str, int other_ob) @@ -1824,7 +1824,7 @@ process_string(char *str, int other_ob) char *process_part(char *, int); if (str == NULL || strstr(str,"@@") == NULL) - return 0; + return 0; /* This means we are called from notify_ in comm1 We must temporary set eff_user to backbone uid for @@ -1832,7 +1832,7 @@ process_string(char *str, int other_ob) */ if (!current_object) { - current_object = command_giver; + current_object = command_giver; } vec = explode_string(str, "@@"); @@ -1851,33 +1851,33 @@ process_string(char *str, int other_ob) */ for (changed = 0, il = pr_start; il < vec->size; il += 2) { - p2 = process_part(vec->item[il].u.string, other_ob); - - if (p2 == vec->item[il].u.string) /* VBFC not resolved */ - { - /* Put back the leading and trailing '@@'. - If some other VBFC resolves, this is needed. - */ - p3 = xalloc(5 + strlen(p2)); - (void)strcpy(p3, "@@"); - (void)strcat(p3, p2); - (void)strcat(p3, "@@"); - p2 = p3; - } - else - changed = 1; - - free_svalue(&vec->item[il]); - vec->item[il].type = T_STRING; - vec->item[il].string_type = STRING_MSTRING; - vec->item[il].u.string = make_mstring(p2); - free(p2); + p2 = process_part(vec->item[il].u.string, other_ob); + + if (p2 == vec->item[il].u.string) /* VBFC not resolved */ + { + /* Put back the leading and trailing '@@'. + If some other VBFC resolves, this is needed. + */ + p3 = xalloc(5 + strlen(p2)); + (void)strcpy(p3, "@@"); + (void)strcat(p3, p2); + (void)strcat(p3, "@@"); + p2 = p3; + } + else + changed = 1; + + free_svalue(&vec->item[il]); + vec->item[il].type = T_STRING; + vec->item[il].string_type = STRING_MSTRING; + vec->item[il].u.string = make_mstring(p2); + free(p2); } if (changed) - buf = implode_string(vec, ""); + buf = implode_string(vec, ""); else - buf = 0; + buf = 0; free_vector(vec); @@ -1900,14 +1900,14 @@ process_part(char *str, int other_ob) struct svalue *process_value(char *, int); if (!(*str) || (str[0] < 'A') || (str[0] > 'z')) - return str; + return str; ret = process_value(str, other_ob); if ((ret) && (ret->type == T_STRING)) - return string_copy(ret->u.string); + return string_copy(ret->u.string); else - return str; + return str; } /* @@ -1926,7 +1926,7 @@ process_value(char *str, int other_ob) struct object *ob; if (!(*str) || (str[0] < 'A') || (str[0] > 'z')) - return &const0; + return &const0; func = (char *) tmpalloc(strlen(str) + 1); (void)strcpy(func, str); @@ -1937,47 +1937,47 @@ process_value(char *str, int other_ob) /* Find the objectpointer */ if (!obj) - ob = current_object; + ob = current_object; else - ob = find_object2(obj); + ob = find_object2(obj); if (!ob) { - return &const0; + return &const0; } /* Push all arguments as strings to the stack */ for (numargs = 0; arg; arg = narg) { - narg = strchr(arg,'|'); - if (narg) - *narg = 0; - push_string(arg, STRING_MSTRING); - numargs++; - if (narg) - { - *narg = '|'; - narg++; - } + narg = strchr(arg,'|'); + if (narg) + *narg = 0; + push_string(arg, STRING_MSTRING); + numargs++; + if (narg) + { + *narg = '|'; + narg++; + } } if (ob->flags & O_DESTRUCTED) - error("object used by process_string/process_value destructed\n"); + error("object used by process_string/process_value destructed\n"); if (other_ob) { - extern char *pc; - - if (!vbfc_object) - error("No vbfc object.\n"); - push_control_stack(vbfc_object, vbfc_object->prog, 0); - current_prog = vbfc_object->prog; - pc = vbfc_object->prog->program; /* XXX */ - inh_offset = current_prog->num_inherited; - previous_ob = current_object; - current_object = vbfc_object; - csp->ext_call = 1; + extern char *pc; + + if (!vbfc_object) + error("No vbfc object.\n"); + push_control_stack(vbfc_object, vbfc_object->prog, 0); + current_prog = vbfc_object->prog; + pc = vbfc_object->prog->program; /* XXX */ + inh_offset = current_prog->num_inherited; + previous_ob = current_object; + current_object = vbfc_object; + csp->ext_call = 1; } @@ -1987,62 +1987,62 @@ process_value(char *str, int other_ob) ret = apply(func, ob, numargs, 1); if (other_ob) - pop_control_stack(); + pop_control_stack(); if (!ret) - return &const0; + return &const0; else - return ret; + return ret; } /* * Function name: break_string * Description: Breaks a continous string without newlines into a string - * with newlines inserted at regular intervalls replacing spaces - * Each newline separated string can be indented with a given - * number of spaces. + * with newlines inserted at regular intervalls replacing spaces + * Each newline separated string can be indented with a given + * number of spaces. * Arguments: str: Original message - * width: The total maximum width of each line. - * indent: (optional) How many spaces to indent with or + * width: The total maximum width of each line. + * indent: (optional) How many spaces to indent with or * indent string. (Max 1000 in indent) * Returns: A string with newline separated strings */ char * break_string(char *str, int width, struct svalue *indent) { - char *fstr, *istr; - struct vector *lines; + char *fstr, *istr; + struct vector *lines; long long l; int il, nchar, space, indlen; if (!indent) - istr = 0; + istr = 0; else if (indent->type == T_NUMBER && indent->u.number >= 0 && indent->u.number < 1000) { - l = indent->u.number; - istr = xalloc((size_t)l + 1); - for (il = 0; il < l; il++) - istr[il] = ' '; - istr[il] = 0; + l = indent->u.number; + istr = xalloc((size_t)l + 1); + for (il = 0; il < l; il++) + istr[il] = ' '; + istr[il] = 0; } else if (indent->type == T_STRING) - istr = string_copy(indent->u.string); + istr = string_copy(indent->u.string); else - return 0; + return 0; if (width < 1) - width = 1; + width = 1; if (istr) { - indlen = strlen(istr); - if (width <= indlen) - width = indlen + 1; + indlen = strlen(istr); + if (width <= indlen) + width = indlen + 1; } else - indlen = 0; + indlen = 0; l = strlen(str); if (l == 0) { @@ -2058,17 +2058,17 @@ break_string(char *str, int width, struct svalue *indent) fstr = str; for (il = 0; il < l; il++) { - if (fstr[il] == ' ') - space = il; + if (fstr[il] == ' ') + space = il; - if ((il - nchar) >= (width - indlen) && space >= 0) - { + if ((il - nchar) >= (width - indlen) && space >= 0) + { if (fstr == str) fstr = make_mstring(str); - fstr[space] = '\n'; - nchar = space + 1; - space = -1; - } + fstr[space] = '\n'; + nchar = space + 1; + space = -1; + } } /* @@ -2076,11 +2076,11 @@ break_string(char *str, int width, struct svalue *indent) */ if (!indlen) { - if (istr) - free(istr); + if (istr) + free(istr); if (fstr == str) return 0; - return fstr; + return fstr; } /* @@ -2097,7 +2097,7 @@ break_string(char *str, int width, struct svalue *indent) */ for (nchar = 0, il = 0; il < lines->size; il++) { - nchar += indlen + strlen(lines->item[il].u.string) + 1; + nchar += indlen + strlen(lines->item[il].u.string) + 1; } fstr = allocate_mstring((size_t)nchar); @@ -2105,16 +2105,16 @@ break_string(char *str, int width, struct svalue *indent) for (il = 0; il < lines->size - 1; il++) { - (void)strcat(fstr, istr); - (void)strcat(fstr, lines->item[il].u.string); - (void)strcat(fstr, "\n"); + (void)strcat(fstr, istr); + (void)strcat(fstr, lines->item[il].u.string); + (void)strcat(fstr, "\n"); } if (lines->size > 0) { - (void)strcat(fstr, istr); - (void)strcat(fstr, lines->item[il].u.string); + (void)strcat(fstr, istr); + (void)strcat(fstr, lines->item[il].u.string); } if (space) - (void)strcat(fstr, "\n"); + (void)strcat(fstr, "\n"); free(istr); free_vector(lines); diff --git a/postlang.y b/postlang.y index efa27be..66f8b2d 100644 --- a/postlang.y +++ b/postlang.y @@ -17,13 +17,13 @@ %union { - long long number; - double real; - unsigned int address; /* Address of an instruction */ - char *string; - short type; - struct { long long key; char block; } case_label; - struct function *funp; + long long number; + double real; + unsigned int address; /* Address of an instruction */ + char *string; + short type; + struct { long long key; char block; } case_label; + struct function *funp; } %type assign F_NUMBER constant F_LOCAL_NAME expr_list funop %type oexpr_list oexpr_list1 @@ -68,35 +68,35 @@ possible_semi_colon: /* empty */ | ';' { yyerror("Extra ';'. Ignored."); }; inheritance: type_modifier_list F_INHERIT string_constant opt_inherit_name ';' - { - struct object *ob; + { + struct object *ob; if (mem_block[A_VARIABLES].current_size || - mem_block[A_FUNCTIONS].current_size) + mem_block[A_FUNCTIONS].current_size) yyerror("Inherit after other definitions\n"); - ob = find_object2($3); - if (ob == 0) { - if (inherit_file) - free(inherit_file); - inherit_file = string_copy($3); - /* Return back to load_object() */ - YYACCEPT; - } + ob = find_object2($3); + if (ob == 0) { + if (inherit_file) + free(inherit_file); + inherit_file = string_copy($3); + /* Return back to load_object() */ + YYACCEPT; + } if (ob->prog->flags & PRAGMA_NO_INHERIT) { yyerror("Inheriting bad object.\n"); } - if (!check_inherits(ob->prog)) + if (!check_inherits(ob->prog)) { - if (inherit_file) - free(inherit_file); - inherit_file = string_copy($3); - /* Return back to load_object() */ - YYACCEPT; + if (inherit_file) + free(inherit_file); + inherit_file = string_copy($3); + /* Return back to load_object() */ + YYACCEPT; } - copy_inherits(ob->prog, $1, $4); - }; + copy_inherits(ob->prog, $1, $4); + }; opt_inherit_name: /* empty */ { @@ -123,304 +123,304 @@ opt_inherit_name: /* empty */ } ; number: F_NUMBER - { - if ( $1 == 0 ) { - ins_f_byte(F_CONST0); $$ = TYPE_ANY; - } else if ( $1 == 1 ) { - ins_f_byte(F_CONST1); $$ = TYPE_NUMBER; - } else { - ins_f_byte(F_NUMBER); ins_mem(&$1, sizeof($1)); $$ = TYPE_NUMBER; - } - } ; + { + if ( $1 == 0 ) { + ins_f_byte(F_CONST0); $$ = TYPE_ANY; + } else if ( $1 == 1 ) { + ins_f_byte(F_CONST1); $$ = TYPE_NUMBER; + } else { + ins_f_byte(F_NUMBER); ins_mem(&$1, sizeof($1)); $$ = TYPE_NUMBER; + } + } ; optional_star: /* empty */ { $$ = 0; } | '*' { $$ = TYPE_MOD_POINTER; } ; block_or_semi: block { $$ = 0; } | ';' { $$ = ';'; } | '=' string_con1 ';' { $$ = $2; } - | '=' F_NUMBER ';' + | '=' F_NUMBER ';' { - if ($2 != 0) - { - yyerror("Syntax error"); - } - $$ = 1; - } ; + if ($2 != 0) + { + yyerror("Syntax error"); + } + $$ = 1; + } ; def: type optional_star fun_identifier - { - /* Save start of function. */ - clear_init_arg_stack(); - deref_index = 0; - push_address(); - try_level = break_try_level = continue_try_level = 0; - true_varargs = 0; - first_default_arg = current_arg = 0; - is_ctor = is_dtor = 0; - - return_label = make_label(); - if ($3 == CTOR_FUNC) - { - $3 = tmpstring_copy(".CTOR"); - is_ctor = 1; - } - else if ($3 == DTOR_FUNC) - { - $3 = tmpstring_copy(".DTOR"); - is_dtor = 1; - } - - if (is_ctor | is_dtor) - { - if ($1 | $2) - { - yyerror("Constructors and destructors don't have a type"); - $1 = $2 = 0; - } - if (pragma_strict_types) - { - $1 = exact_types = TYPE_VOID; - } - else - exact_types = 0; - } - else if ($1 & TYPE_MASK) - { - exact_types = $1 | $2; - } - else - { - if (pragma_strict_types) - yyerror("\"#pragma strict_types\" requires type of function"); - exact_types = 0; - } - } - fun_args - { - /* - * Define a prototype. If it is a real function, then the - * prototype will be replaced below. - */ - if ($5 && is_ctor | is_dtor) - { - yyerror("Constructors and destructors don't take arguments"); - } - - ins_f_byte(F_JUMP); - push_address(); - ins_address(0); - - { - offset_t i = pop_address(); - push_address(); - dump_init_arg_table($5); - upd_address(i, mem_block[A_PROGRAM].current_size); - define_new_function($3, (char)$5, 0, 0, - NAME_PROTOTYPE | $1 | $2 | true_varargs, - (char)first_default_arg); - } - } + { + /* Save start of function. */ + clear_init_arg_stack(); + deref_index = 0; + push_address(); + try_level = break_try_level = continue_try_level = 0; + true_varargs = 0; + first_default_arg = current_arg = 0; + is_ctor = is_dtor = 0; + + return_label = make_label(); + if ($3 == CTOR_FUNC) + { + $3 = tmpstring_copy(".CTOR"); + is_ctor = 1; + } + else if ($3 == DTOR_FUNC) + { + $3 = tmpstring_copy(".DTOR"); + is_dtor = 1; + } + + if (is_ctor | is_dtor) + { + if ($1 | $2) + { + yyerror("Constructors and destructors don't have a type"); + $1 = $2 = 0; + } + if (pragma_strict_types) + { + $1 = exact_types = TYPE_VOID; + } + else + exact_types = 0; + } + else if ($1 & TYPE_MASK) + { + exact_types = $1 | $2; + } + else + { + if (pragma_strict_types) + yyerror("\"#pragma strict_types\" requires type of function"); + exact_types = 0; + } + } + fun_args + { + /* + * Define a prototype. If it is a real function, then the + * prototype will be replaced below. + */ + if ($5 && is_ctor | is_dtor) + { + yyerror("Constructors and destructors don't take arguments"); + } + + ins_f_byte(F_JUMP); + push_address(); + ins_address(0); + + { + offset_t i = pop_address(); + push_address(); + dump_init_arg_table($5); + upd_address(i, mem_block[A_PROGRAM].current_size); + define_new_function($3, (char)$5, 0, 0, + NAME_PROTOTYPE | $1 | $2 | true_varargs, + (char)first_default_arg); + } + } block_or_semi - { - - /* Either a prototype or a block */ - if ($7 == ';') /* its only a prototype */ - { - (void)pop_address(); /* Not used here */ - mem_block[A_PROGRAM].current_size = - pop_address(); - } - else if ($7 == 0) - { - define_new_function($3, (char)$5, - (unsigned char)(max_number_of_locals - $5), - pop_address(), $1 | $2 | true_varargs, - (char)first_default_arg); - ins_f_byte(F_CONST0); - set_label(return_label, mem_block[A_PROGRAM].current_size); - ins_f_byte(F_RETURN); - (void)pop_address(); /* Not used here */ - } - else if ($7 == 1) - { - if (is_ctor | is_dtor) - yyerror("Constructors and destructors can't be abstract"); - define_new_function($3, (char)$5, 0, 0, - NAME_ABSTRACT | $1 | $2 | true_varargs, - (char)first_default_arg); - yyerror("Abstract functions aren't implemented yet"); - } - else + { + + /* Either a prototype or a block */ + if ($7 == ';') /* its only a prototype */ + { + (void)pop_address(); /* Not used here */ + mem_block[A_PROGRAM].current_size = + pop_address(); + } + else if ($7 == 0) + { + define_new_function($3, (char)$5, + (unsigned char)(max_number_of_locals - $5), + pop_address(), $1 | $2 | true_varargs, + (char)first_default_arg); + ins_f_byte(F_CONST0); + set_label(return_label, mem_block[A_PROGRAM].current_size); + ins_f_byte(F_RETURN); + (void)pop_address(); /* Not used here */ + } + else if ($7 == 1) + { + if (is_ctor | is_dtor) + yyerror("Constructors and destructors can't be abstract"); + define_new_function($3, (char)$5, 0, 0, + NAME_ABSTRACT | $1 | $2 | true_varargs, + (char)first_default_arg); + yyerror("Abstract functions aren't implemented yet"); + } + else { - extern void (* get_C_fun_address(char *, char *))(struct svalue *); - void (*funca)(struct svalue *); - - define_new_function($3, (char)$5, - (unsigned char)(max_number_of_locals - $5), - pop_address(), $1 | $2 | true_varargs, - (char)first_default_arg); - ins_f_byte(F_CALL_C); - funca = get_C_fun_address(current_file, $7); - if (!funca) + extern void (* get_C_fun_address(char *, char *))(struct svalue *); + void (*funca)(struct svalue *); + + define_new_function($3, (char)$5, + (unsigned char)(max_number_of_locals - $5), + pop_address(), $1 | $2 | true_varargs, + (char)first_default_arg); + ins_f_byte(F_CALL_C); + funca = get_C_fun_address(current_file, $7); + if (!funca) { - char buf[256]; - - (void)snprintf(buf, sizeof(buf), "Undefined interface %s() = \"%s\".\n", - $3, $7); - yyerror(buf); - } - ins_mem(&funca, sizeof(funca)); - ins_f_byte(F_RETURN); - (void)pop_address(); /* Not used here */ - } - free_all_local_names(); - is_ctor = is_dtor = 0; - } + char buf[256]; + + (void)snprintf(buf, sizeof(buf), "Undefined interface %s() = \"%s\".\n", + $3, $7); + yyerror(buf); + } + ins_mem(&funca, sizeof(funca)); + ins_f_byte(F_RETURN); + (void)pop_address(); /* Not used here */ + } + free_all_local_names(); + is_ctor = is_dtor = 0; + } | type name_list ';' { if ($1 == 0) yyerror("Missing type"); } | inheritance ; new_arg_name: type optional_star F_IDENTIFIER - { - if (exact_types && $1 == 0) { - yyerror("Missing type for argument"); - (void)add_local_name($3, TYPE_ANY); /* Supress more errors */ - } else { - (void)add_local_name($3, $1 | $2); - } - if (first_default_arg != current_arg) - yyerror("non default argument defined after default one"); - else - first_default_arg++; - push_init_arg_address(mem_block[A_PROGRAM].current_size); - } + { + if (exact_types && $1 == 0) { + yyerror("Missing type for argument"); + (void)add_local_name($3, TYPE_ANY); /* Supress more errors */ + } else { + (void)add_local_name($3, $1 | $2); + } + if (first_default_arg != current_arg) + yyerror("non default argument defined after default one"); + else + first_default_arg++; + push_init_arg_address(mem_block[A_PROGRAM].current_size); + } | type optional_star F_IDENTIFIER { int var_num; - if (exact_types && $1 == 0) { - yyerror("Missing type for argument"); - var_num = add_local_name($3, TYPE_ANY); /* Supress more errors */ - } else { - var_num = add_local_name($3, $1 | $2); - } - push_init_arg_address(mem_block[A_PROGRAM].current_size); - ins_f_byte(F_PUSH_LOCAL_VARIABLE_LVALUE); - ins_byte((char)var_num); - } + if (exact_types && $1 == 0) { + yyerror("Missing type for argument"); + var_num = add_local_name($3, TYPE_ANY); /* Supress more errors */ + } else { + var_num = add_local_name($3, $1 | $2); + } + push_init_arg_address(mem_block[A_PROGRAM].current_size); + ins_f_byte(F_PUSH_LOCAL_VARIABLE_LVALUE); + ins_byte((char)var_num); + } '=' expr0 { - if (!compatible_types((($1 ? $1 : TYPE_ANY) | $2) & TYPE_MASK, $6)){ - char buff[100]; + if (!compatible_types((($1 ? $1 : TYPE_ANY) | $2) & TYPE_MASK, $6)){ + char buff[100]; - (void)snprintf(buff, sizeof(buff), "Type mismatch %s when initializing %s", - get_two_types($1 | $2, $6), $3); - yyerror(buff); - } - ins_f_byte(F_ASSIGN); - ins_f_byte(F_POP_VALUE); - } + (void)snprintf(buff, sizeof(buff), "Type mismatch %s when initializing %s", + get_two_types($1 | $2, $6), $3); + yyerror(buff); + } + ins_f_byte(F_ASSIGN); + ins_f_byte(F_POP_VALUE); + } -fun_args: '(' /* empty */ ')' { $$ = 0; } - | '(' argument ')' { $$ = $2; } - | '(' F_VOID ')' { $$ = 0; }; +fun_args: '(' /* empty */ ')' { $$ = 0; } + | '(' argument ')' { $$ = $2; } + | '(' F_VOID ')' { $$ = 0; }; argument: argument_list - | argument_list ',' F_VARARG - { + | argument_list ',' F_VARARG + { int var_num = add_local_name(tmpstring_copy("argv"), TYPE_ANY | TYPE_MOD_POINTER); - $$ = $1 + 1; + $$ = $1 + 1; true_varargs = TYPE_MOD_TRUE_VARARGS; - push_init_arg_address(mem_block[A_PROGRAM].current_size); - ins_f_byte(F_PUSH_LOCAL_VARIABLE_LVALUE); - ins_byte((char)var_num); - ins_f_byte(F_AGGREGATE); - ins_short(0); - ins_f_byte(F_ASSIGN); - ins_f_byte(F_POP_VALUE); - current_arg++; - } - | F_VARARG - { + push_init_arg_address(mem_block[A_PROGRAM].current_size); + ins_f_byte(F_PUSH_LOCAL_VARIABLE_LVALUE); + ins_byte((char)var_num); + ins_f_byte(F_AGGREGATE); + ins_short(0); + ins_f_byte(F_ASSIGN); + ins_f_byte(F_POP_VALUE); + current_arg++; + } + | F_VARARG + { int var_num = add_local_name(tmpstring_copy("argv"), TYPE_ANY | TYPE_MOD_POINTER); - $$ = 1; + $$ = 1; true_varargs = TYPE_MOD_TRUE_VARARGS; - push_init_arg_address(mem_block[A_PROGRAM].current_size); - ins_f_byte(F_PUSH_LOCAL_VARIABLE_LVALUE); - ins_byte((char)var_num); - ins_f_byte(F_AGGREGATE); - ins_short(0); - ins_f_byte(F_ASSIGN); - ins_f_byte(F_POP_VALUE); - current_arg++; - }; + push_init_arg_address(mem_block[A_PROGRAM].current_size); + ins_f_byte(F_PUSH_LOCAL_VARIABLE_LVALUE); + ins_byte((char)var_num); + ins_f_byte(F_AGGREGATE); + ins_short(0); + ins_f_byte(F_ASSIGN); + ins_f_byte(F_POP_VALUE); + current_arg++; + }; argument_list: new_arg_name { $$ = 1; current_arg++; } - | argument_list ',' new_arg_name { $$ = $1 + 1; current_arg++; } ; + | argument_list ',' new_arg_name { $$ = $1 + 1; current_arg++; } ; type_modifier: F_NO_MASK { $$ = TYPE_MOD_NO_MASK; } - | F_STATIC { $$ = TYPE_MOD_STATIC; } - | F_PRIVATE { $$ = TYPE_MOD_PRIVATE; } - | F_PUBLIC { $$ = TYPE_MOD_PUBLIC; } - | F_VARARGS { $$ = TYPE_MOD_VARARGS; } ; + | F_STATIC { $$ = TYPE_MOD_STATIC; } + | F_PRIVATE { $$ = TYPE_MOD_PRIVATE; } + | F_PUBLIC { $$ = TYPE_MOD_PUBLIC; } + | F_VARARGS { $$ = TYPE_MOD_VARARGS; } ; type_modifier_list: /* empty */ { $$ = 0; } - | type_modifier type_modifier_list { $$ = $1 | $2; } ; + | type_modifier type_modifier_list { $$ = $1 | $2; } ; type: type_modifier_list opt_basic_type { $$ = $1 | $2; current_type = $$; } ; cast: '(' basic_type optional_star ')' - { - $$ = $2 | $3; - } ; + { + $$ = $2 | $3; + } ; opt_basic_type: basic_type | /* empty */ { $$ = TYPE_UNKNOWN; } ; basic_type: F_STATUS { $$ = TYPE_NUMBER; current_type = $$; } - | F_INT { $$ = TYPE_NUMBER; current_type = $$; } - | F_STRING_DECL { $$ = TYPE_STRING; current_type = $$; } - | F_OBJECT { $$ = TYPE_OBJECT; current_type = $$; } - | F_VOID {$$ = TYPE_VOID; current_type = $$; } - | F_MIXED { $$ = TYPE_ANY; current_type = $$; } - | F_MAPPING { $$ = TYPE_MAPPING; current_type = $$; } + | F_INT { $$ = TYPE_NUMBER; current_type = $$; } + | F_STRING_DECL { $$ = TYPE_STRING; current_type = $$; } + | F_OBJECT { $$ = TYPE_OBJECT; current_type = $$; } + | F_VOID {$$ = TYPE_VOID; current_type = $$; } + | F_MIXED { $$ = TYPE_ANY; current_type = $$; } + | F_MAPPING { $$ = TYPE_MAPPING; current_type = $$; } | F_FLOAT { $$ = TYPE_FLOAT; current_type = $$; } | F_FUNCTION { $$ = TYPE_FUNCTION; current_type = $$; }; name_list: new_name - | new_name ',' name_list; + | new_name ',' name_list; new_name: optional_star F_IDENTIFIER - { - define_variable($2, current_type | $1); - } + { + define_variable($2, current_type | $1); + } | optional_star F_IDENTIFIER - { - define_variable($2, current_type | $1); - transfer_init_control(); - ins_f_byte(F_PUSH_IDENTIFIER_LVALUE); - ins_byte((char)variable_inherit_found); - ins_byte((char)variable_index_found); - } - '=' expr0 - { - if (pragma_strict_types && - !compatible_types((current_type | $1) & TYPE_MASK, $5)){ - char buff[100]; - - (void)snprintf(buff, sizeof(buff), "Type mismatch %s when initializing %s", - get_two_types(current_type | $1, $5), $2); - yyerror(buff); - } - ins_f_byte(F_ASSIGN); - ins_f_byte(F_POP_VALUE); - add_new_init_jump(); - } ; + { + define_variable($2, current_type | $1); + transfer_init_control(); + ins_f_byte(F_PUSH_IDENTIFIER_LVALUE); + ins_byte((char)variable_inherit_found); + ins_byte((char)variable_index_found); + } + '=' expr0 + { + if (pragma_strict_types && + !compatible_types((current_type | $1) & TYPE_MASK, $5)){ + char buff[100]; + + (void)snprintf(buff, sizeof(buff), "Type mismatch %s when initializing %s", + get_two_types(current_type | $1, $5), $2); + yyerror(buff); + } + ins_f_byte(F_ASSIGN); + ins_f_byte(F_POP_VALUE); + add_new_init_jump(); + } ; block: '{' { - start_block(); + start_block(); } statements '}' { - end_block(); + end_block(); }; local_declaration: basic_type local_name_list ';' { ;} ; @@ -445,9 +445,9 @@ new_local_name: new_local_name2 char buff[100]; (void)snprintf(buff, sizeof(buff), - "Type mismatch %s when initializing %s", - get_two_types(type_of_locals[$1], $4), - local_names[$1]); + "Type mismatch %s when initializing %s", + get_two_types(type_of_locals[$1], $4), + local_names[$1]); yyerror(buff); } ins_f_byte(F_ASSIGN); @@ -456,145 +456,145 @@ new_local_name: new_local_name2 local_name_list: new_local_name - | new_local_name ',' local_name_list ; + | new_local_name ',' local_name_list ; statements: /* empty */ - | statement statements - | error ';' ; + | statement statements + | error ';' ; statement: comma_expr ';' - { - ins_f_byte(F_POP_VALUE); - /* if (exact_types && !TYPE($1,TYPE_VOID)) - yyerror("Value thrown away"); */ - } - | cond | try | while | do | for | switch | case | default | return ';' - | foreach | foreach_m | block | local_declaration - | /* empty */ ';' - | F_BREAK ';' /* This code is a jump to a jump */ - { - if (current_break_address == 0) - yyerror("break statement outside loop"); - for (int i = try_level; i > break_try_level; i--) - ins_f_byte(F_END_TRY); - ins_f_byte(F_JUMP); - add_jump(); - ins_label(current_break_address); - } - | F_CONTINUE ';' /* This code is a jump to a jump */ - { - if (current_continue_address == 0) - yyerror("continue statement outside loop"); - for (int i = try_level; i > continue_try_level; i--) - ins_f_byte(F_END_TRY); - ins_f_byte(F_JUMP); - add_jump(); - ins_label(current_continue_address); - } + { + ins_f_byte(F_POP_VALUE); + /* if (exact_types && !TYPE($1,TYPE_VOID)) + yyerror("Value thrown away"); */ + } + | cond | try | while | do | for | switch | case | default | return ';' + | foreach | foreach_m | block | local_declaration + | /* empty */ ';' + | F_BREAK ';' /* This code is a jump to a jump */ + { + if (current_break_address == 0) + yyerror("break statement outside loop"); + for (int i = try_level; i > break_try_level; i--) + ins_f_byte(F_END_TRY); + ins_f_byte(F_JUMP); + add_jump(); + ins_label(current_break_address); + } + | F_CONTINUE ';' /* This code is a jump to a jump */ + { + if (current_continue_address == 0) + yyerror("continue statement outside loop"); + for (int i = try_level; i > continue_try_level; i--) + ins_f_byte(F_END_TRY); + ins_f_byte(F_JUMP); + add_jump(); + ins_label(current_continue_address); + } ; try: F_TRY { - ins_f_byte(F_TRY); - push_address(); - ins_address(0); - ins_byte(0); - try_level++; - } statement F_CATCH {start_block();} '(' basic_type new_local_name2 ')' - { - short try_start = pop_address(); - try_level--; - ins_f_byte(F_END_TRY); - ins_f_byte(F_JUMP); - push_address(); - ins_address(0); - upd_address(try_start, mem_block[A_PROGRAM].current_size); - upd_byte(try_start + 4, $8); - } statement - { - end_block(); - upd_address(pop_address(), mem_block[A_PROGRAM].current_size); - }; + ins_f_byte(F_TRY); + push_address(); + ins_address(0); + ins_byte(0); + try_level++; + } statement F_CATCH {start_block();} '(' basic_type new_local_name2 ')' + { + short try_start = pop_address(); + try_level--; + ins_f_byte(F_END_TRY); + ins_f_byte(F_JUMP); + push_address(); + ins_address(0); + upd_address(try_start, mem_block[A_PROGRAM].current_size); + upd_byte(try_start + 4, $8); + } statement + { + end_block(); + upd_address(pop_address(), mem_block[A_PROGRAM].current_size); + }; while: { push_explicit(current_continue_address); - push_explicit(continue_try_level); - push_explicit(current_break_address); - push_explicit(break_try_level); - current_continue_address = make_label(); - current_break_address = make_label(); - continue_try_level = break_try_level = try_level; - set_label(current_continue_address, mem_block[A_PROGRAM].current_size); - } F_WHILE '(' comma_expr ')' - { - ins_f_byte(F_JUMP_WHEN_ZERO); - add_jump(); - ins_label(current_break_address); - } + push_explicit(continue_try_level); + push_explicit(current_break_address); + push_explicit(break_try_level); + current_continue_address = make_label(); + current_break_address = make_label(); + continue_try_level = break_try_level = try_level; + set_label(current_continue_address, mem_block[A_PROGRAM].current_size); + } F_WHILE '(' comma_expr ')' + { + ins_f_byte(F_JUMP_WHEN_ZERO); + add_jump(); + ins_label(current_break_address); + } statement - { - ins_f_byte(F_JUMP); - add_jump(); - ins_label(current_continue_address); - set_label(current_break_address, mem_block[A_PROGRAM].current_size); - break_try_level = pop_address(); - current_break_address = pop_address(); - continue_try_level = pop_address(); - current_continue_address = pop_address(); + { + ins_f_byte(F_JUMP); + add_jump(); + ins_label(current_continue_address); + set_label(current_break_address, mem_block[A_PROGRAM].current_size); + break_try_level = pop_address(); + current_break_address = pop_address(); + continue_try_level = pop_address(); + current_continue_address = pop_address(); }; do: { push_explicit(current_continue_address); - push_explicit(continue_try_level); - push_explicit(current_break_address); - push_explicit(break_try_level); - current_continue_address = make_label(); - current_break_address = make_label(); - continue_try_level = break_try_level = try_level; + push_explicit(continue_try_level); + push_explicit(current_break_address); + push_explicit(break_try_level); + current_continue_address = make_label(); + current_break_address = make_label(); + continue_try_level = break_try_level = try_level; push_address(); } F_DO statement { - set_label(current_continue_address, mem_block[A_PROGRAM].current_size); + set_label(current_continue_address, mem_block[A_PROGRAM].current_size); } F_WHILE '(' comma_expr ')' ';' { - ins_f_byte(F_JUMP_WHEN_NON_ZERO); - add_jump(); - ins_address(pop_address()); - set_label(current_break_address, mem_block[A_PROGRAM].current_size); - break_try_level = pop_address(); - current_break_address = pop_address(); - continue_try_level = pop_address(); - current_continue_address = pop_address(); + ins_f_byte(F_JUMP_WHEN_NON_ZERO); + add_jump(); + ins_address(pop_address()); + set_label(current_break_address, mem_block[A_PROGRAM].current_size); + break_try_level = pop_address(); + current_break_address = pop_address(); + continue_try_level = pop_address(); + current_continue_address = pop_address(); }; start_block: { start_block();} ; -foreach_var: basic_type new_local_name2 { +foreach_var: basic_type new_local_name2 { ins_f_byte(F_PUSH_LOCAL_VARIABLE_LVALUE); ins_byte((char)$2); - } ; + } ; foreach_m: F_FOREACH start_block '(' foreach_var ',' foreach_var ':' comma_expr ')' { ins_f_byte(F_DUP); ins_f_byte(F_M_INDEXES); - ins_f_byte(F_CONST0); + ins_f_byte(F_CONST0); push_explicit(current_continue_address); - push_explicit(continue_try_level); - push_explicit(current_break_address); - push_explicit(break_try_level); - current_continue_address = make_label(); - current_break_address = make_label(); - continue_try_level = break_try_level = try_level; - set_label(current_continue_address, get_address()); - ins_f_byte(F_FOREACH_M); + push_explicit(continue_try_level); + push_explicit(current_break_address); + push_explicit(break_try_level); + current_continue_address = make_label(); + current_break_address = make_label(); + continue_try_level = break_try_level = try_level; + set_label(current_continue_address, get_address()); + ins_f_byte(F_FOREACH_M); add_jump(); - ins_label(current_break_address); - } - statement - { + ins_label(current_break_address); + } + statement + { ins_f_byte(F_JUMP); add_jump(); ins_label(current_continue_address); @@ -605,28 +605,28 @@ foreach_m: F_FOREACH start_block '(' foreach_var ',' foreach_var ':' comma_expr ins_f_byte(F_POP_VALUE); ins_f_byte(F_POP_VALUE); end_block(); - break_try_level = pop_address(); + break_try_level = pop_address(); current_break_address = pop_address(); - continue_try_level = pop_address(); + continue_try_level = pop_address(); current_continue_address = pop_address(); - }; + }; foreach: F_FOREACH start_block '(' foreach_var ':' comma_expr ')' { - ins_f_byte(F_CONST0); + ins_f_byte(F_CONST0); push_explicit(current_continue_address); - push_explicit(continue_try_level); - push_explicit(current_break_address); - push_explicit(break_try_level); - current_continue_address = make_label(); - current_break_address = make_label(); - continue_try_level = break_try_level = try_level; - set_label(current_continue_address, get_address()); - ins_f_byte(F_FOREACH); + push_explicit(continue_try_level); + push_explicit(current_break_address); + push_explicit(break_try_level); + current_continue_address = make_label(); + current_break_address = make_label(); + continue_try_level = break_try_level = try_level; + set_label(current_continue_address, get_address()); + ins_f_byte(F_FOREACH); add_jump(); - ins_label(current_break_address); - } - statement - { + ins_label(current_break_address); + } + statement + { ins_f_byte(F_JUMP); add_jump(); ins_label(current_continue_address); @@ -635,40 +635,40 @@ foreach: F_FOREACH start_block '(' foreach_var ':' comma_expr ')' { ins_f_byte(F_POP_VALUE); ins_f_byte(F_POP_VALUE); end_block(); - break_try_level = pop_address(); + break_try_level = pop_address(); current_break_address = pop_address(); - continue_try_level = pop_address(); + continue_try_level = pop_address(); current_continue_address = pop_address(); - }; + }; for_init_expr: for_expr - | basic_type local_name_list {;}; + | basic_type local_name_list {;}; -for: F_FOR '(' start_block { +for: F_FOR '(' start_block { push_explicit(current_continue_address); push_explicit(continue_try_level); push_explicit(current_break_address); push_explicit(break_try_level); continue_try_level = break_try_level = try_level; } for_init_expr ';' { - push_address(); - } + push_address(); + } for_guard ';' { - push_address(); - ins_address(0); - current_continue_address = make_label(); - current_break_address = make_label(); - ins_f_byte(F_JUMP); - add_jump(); - ins_label(current_break_address); - set_label(current_continue_address, mem_block[A_PROGRAM].current_size); - } + push_address(); + ins_address(0); + current_continue_address = make_label(); + current_break_address = make_label(); + ins_f_byte(F_JUMP); + add_jump(); + ins_label(current_break_address); + set_label(current_continue_address, mem_block[A_PROGRAM].current_size); + } for_expr ')' { - upd_address(pop_address(), mem_block[A_PROGRAM].current_size + 1 + sizeof(offset_t)); - ins_f_byte(F_JUMP); - add_jump(); - ins_address(pop_address()); - } + upd_address(pop_address(), mem_block[A_PROGRAM].current_size + 1 + sizeof(offset_t)); + ins_f_byte(F_JUMP); + add_jump(); + ins_address(pop_address()); + } statement { ins_f_byte(F_JUMP); @@ -683,15 +683,15 @@ for: F_FOR '(' start_block { }; for_guard: /* EMPTY */ - { - ins_f_byte(F_JUMP); - add_jump(); - } + { + ins_f_byte(F_JUMP); + add_jump(); + } | comma_expr - { - ins_f_byte(F_JUMP_WHEN_NON_ZERO); - add_jump(); - } + { + ins_f_byte(F_JUMP_WHEN_NON_ZERO); + add_jump(); + } ; for_expr: /* EMPTY */ @@ -699,170 +699,170 @@ for_expr: /* EMPTY */ switch: F_SWITCH '(' comma_expr ')' { - /* initialize switch */ - push_explicit(current_case_number_heap); - push_explicit(current_case_string_heap); - push_explicit(zero_case_label); - push_explicit(current_break_address); - push_explicit(break_try_level); - break_try_level = try_level; - push_explicit(current_case_address); - - ins_f_byte(F_SWITCH); - current_case_address = mem_block[A_PROGRAM].current_size; - ins_byte((char)0xff); /* kind of table */ - current_case_number_heap = mem_block[A_CASE_NUMBERS].current_size; - current_case_string_heap = mem_block[A_CASE_STRINGS].current_size; - zero_case_label = NO_STRING_CASE_LABELS; - ins_address(0); /* address of table */ - ins_address(0); /* break address to push, table is entered before */ - ins_address(0); /* default address */ - - current_break_address = make_label(); + /* initialize switch */ + push_explicit(current_case_number_heap); + push_explicit(current_case_string_heap); + push_explicit(zero_case_label); + push_explicit(current_break_address); + push_explicit(break_try_level); + break_try_level = try_level; + push_explicit(current_case_address); + + ins_f_byte(F_SWITCH); + current_case_address = mem_block[A_PROGRAM].current_size; + ins_byte((char)0xff); /* kind of table */ + current_case_number_heap = mem_block[A_CASE_NUMBERS].current_size; + current_case_string_heap = mem_block[A_CASE_STRINGS].current_size; + zero_case_label = NO_STRING_CASE_LABELS; + ins_address(0); /* address of table */ + ins_address(0); /* break address to push, table is entered before */ + ins_address(0); /* default address */ + + current_break_address = make_label(); } statement { - int block_index; - int current_case_heap; - offset_t default_addr; - - /* Wrap up switch */ - /* It is not unusual that the last case/default has no break - */ - /* Default address */ - if (!(default_addr = read_address(current_case_address + 1 + (sizeof(offset_t) * 2)))) - { - upd_address(current_case_address + 1 + (sizeof(offset_t) * 2), /* no default given -> */ - mem_block[A_PROGRAM].current_size); /* create one */ - default_addr = mem_block[A_PROGRAM].current_size; - } - - ins_f_byte(F_JUMP); - add_jump(); - ins_label(current_break_address); - - /* Table address */ - upd_address(current_case_address + 1, mem_block[A_PROGRAM].current_size); - - /* What type of table? */ - if (zero_case_label & (NO_STRING_CASE_LABELS|SOME_NUMERIC_CASE_LABELS)) - { - block_index = A_CASE_NUMBERS; - current_case_heap = current_case_number_heap; - mem_block[A_PROGRAM].block[current_case_address] = 0; - } - else - { - block_index = A_CASE_STRINGS; - current_case_heap = current_case_string_heap; - mem_block[A_PROGRAM].block[current_case_address] = 1; - if (zero_case_label & 0xffff) - { - ins_long_long(0); /* not used */ - ins_address(zero_case_label); /* the address */ - } - else - { - ins_long_long(0); /* not used */ - ins_address(default_addr); /* the address */ - } - } - - /* Dump the table */ - { - struct case_heap_entry *ent, *end; - - ent = (struct case_heap_entry *) - (mem_block[block_index].block + current_case_heap); - end = (struct case_heap_entry *) - (mem_block[block_index].block + - mem_block[block_index].current_size); - for (; ent < end; ent++) - { - ins_long_long(ent->key); - ins_address(ent->addr); - } - } - - /* Break address */ - upd_address(current_case_address + 1 + sizeof(offset_t), mem_block[A_PROGRAM].current_size); - set_label(current_break_address, mem_block[A_PROGRAM].current_size); - - mem_block[A_CASE_NUMBERS].current_size = current_case_number_heap; - mem_block[A_CASE_STRINGS].current_size = current_case_string_heap; - current_case_address = pop_address(); - break_try_level = pop_address(); - current_break_address = pop_address(); - zero_case_label = pop_address(); - current_case_string_heap = pop_address(); - current_case_number_heap = pop_address(); + int block_index; + int current_case_heap; + offset_t default_addr; + + /* Wrap up switch */ + /* It is not unusual that the last case/default has no break + */ + /* Default address */ + if (!(default_addr = read_address(current_case_address + 1 + (sizeof(offset_t) * 2)))) + { + upd_address(current_case_address + 1 + (sizeof(offset_t) * 2), /* no default given -> */ + mem_block[A_PROGRAM].current_size); /* create one */ + default_addr = mem_block[A_PROGRAM].current_size; + } + + ins_f_byte(F_JUMP); + add_jump(); + ins_label(current_break_address); + + /* Table address */ + upd_address(current_case_address + 1, mem_block[A_PROGRAM].current_size); + + /* What type of table? */ + if (zero_case_label & (NO_STRING_CASE_LABELS|SOME_NUMERIC_CASE_LABELS)) + { + block_index = A_CASE_NUMBERS; + current_case_heap = current_case_number_heap; + mem_block[A_PROGRAM].block[current_case_address] = 0; + } + else + { + block_index = A_CASE_STRINGS; + current_case_heap = current_case_string_heap; + mem_block[A_PROGRAM].block[current_case_address] = 1; + if (zero_case_label & 0xffff) + { + ins_long_long(0); /* not used */ + ins_address(zero_case_label); /* the address */ + } + else + { + ins_long_long(0); /* not used */ + ins_address(default_addr); /* the address */ + } + } + + /* Dump the table */ + { + struct case_heap_entry *ent, *end; + + ent = (struct case_heap_entry *) + (mem_block[block_index].block + current_case_heap); + end = (struct case_heap_entry *) + (mem_block[block_index].block + + mem_block[block_index].current_size); + for (; ent < end; ent++) + { + ins_long_long(ent->key); + ins_address(ent->addr); + } + } + + /* Break address */ + upd_address(current_case_address + 1 + sizeof(offset_t), mem_block[A_PROGRAM].current_size); + set_label(current_break_address, mem_block[A_PROGRAM].current_size); + + mem_block[A_CASE_NUMBERS].current_size = current_case_number_heap; + mem_block[A_CASE_STRINGS].current_size = current_case_string_heap; + current_case_address = pop_address(); + break_try_level = pop_address(); + current_break_address = pop_address(); + zero_case_label = pop_address(); + current_case_string_heap = pop_address(); + current_case_number_heap = pop_address(); }; case: F_CASE case_label ':' { - /* Register label */ - struct case_heap_entry temp; - - if ( !current_case_address ) - { - yyerror("Case outside switch"); - break; - } - temp.key = $2.key; - temp.addr = mem_block[A_PROGRAM].current_size; - temp.line = current_line; - add_to_case_heap($2.block,&temp, NULL); + /* Register label */ + struct case_heap_entry temp; + + if ( !current_case_address ) + { + yyerror("Case outside switch"); + break; + } + temp.key = $2.key; + temp.addr = mem_block[A_PROGRAM].current_size; + temp.line = current_line; + add_to_case_heap($2.block,&temp, NULL); } | F_CASE case_label F_RANGE case_label ':' { - /* Register range label */ - struct case_heap_entry temp1, temp2; - - if ( !current_case_address) - { - yyerror("Case outside switch"); - break; - } - - if ($2.block != $4.block) - yyerror("Incompatible types in case label range bounds"); - else - { - temp1.key = $2.key; - temp1.addr = OFFSET_MAX; - temp1.line = current_line; - temp2.key = $4.key; - temp2.addr = mem_block[A_PROGRAM].current_size; - temp2.line = current_line; - add_to_case_heap($2.block, &temp1, &temp2); - } + /* Register range label */ + struct case_heap_entry temp1, temp2; + + if ( !current_case_address) + { + yyerror("Case outside switch"); + break; + } + + if ($2.block != $4.block) + yyerror("Incompatible types in case label range bounds"); + else + { + temp1.key = $2.key; + temp1.addr = OFFSET_MAX; + temp1.line = current_line; + temp2.key = $4.key; + temp2.addr = mem_block[A_PROGRAM].current_size; + temp2.line = current_line; + add_to_case_heap($2.block, &temp1, &temp2); + } }; case_label: constant { - if ( !(zero_case_label & NO_STRING_CASE_LABELS) ) - yyerror("Mixed case label list not allowed"); - if ( ($$.key = $1) != 0 ) - zero_case_label |= SOME_NUMERIC_CASE_LABELS; - else - zero_case_label |= mem_block[A_PROGRAM].current_size; - $$.block = A_CASE_NUMBERS; - } + if ( !(zero_case_label & NO_STRING_CASE_LABELS) ) + yyerror("Mixed case label list not allowed"); + if ( ($$.key = $1) != 0 ) + zero_case_label |= SOME_NUMERIC_CASE_LABELS; + else + zero_case_label |= mem_block[A_PROGRAM].current_size; + $$.block = A_CASE_NUMBERS; + } | string_constant { - if ( zero_case_label & SOME_NUMERIC_CASE_LABELS ) - yyerror("Mixed case label list not allowed"); - zero_case_label &= ~NO_STRING_CASE_LABELS; + if ( zero_case_label & SOME_NUMERIC_CASE_LABELS ) + yyerror("Mixed case label list not allowed"); + zero_case_label &= ~NO_STRING_CASE_LABELS; $$.key = (unsigned short)store_prog_string($1); - $$.block = A_CASE_STRINGS; + $$.block = A_CASE_STRINGS; }; constant: const1 - | constant '|' const1 { $$ = $1 | $3; } ; + | constant '|' const1 { $$ = $1 | $3; } ; const1: const2 | const1 '^' const2 { $$ = $1 ^ $3; } ; @@ -903,14 +903,14 @@ const9: F_NUMBER default: F_DEFAULT ':' { - if (!current_case_address) - { - yyerror("Default outside switch"); - break; - } - if (read_address(current_case_address + 1 + sizeof(offset_t) * 2)) - yyerror("Duplicate default"); - upd_address(current_case_address + 1 + sizeof(offset_t) * 2, mem_block[A_PROGRAM].current_size); + if (!current_case_address) + { + yyerror("Default outside switch"); + break; + } + if (read_address(current_case_address + 1 + sizeof(offset_t) * 2)) + yyerror("Duplicate default"); + upd_address(current_case_address + 1 + sizeof(offset_t) * 2, mem_block[A_PROGRAM].current_size); } ; @@ -919,24 +919,24 @@ comma_expr: c_expr c_expr: expr0 { $$ = $1; } | c_expr { ins_f_byte(F_POP_VALUE); } - ',' expr0 - { $$ = $4; } ; + ',' expr0 + { $$ = $4; } ; expr0: expr01 | lvalue assign expr0 - { - deref_index--; - if (!($1 & TYPE_LVALUE)) - yyerror("Illegal LHS"); - $1 &= ~TYPE_LVALUE; - if (exact_types && !compatible_types($1, $3) && - !($1 == TYPE_STRING && $3 == TYPE_NUMBER && $2 == F_ADD_EQ) && - !(($1 == TYPE_STRING || ($1 & TYPE_MOD_POINTER)) && - $3 == TYPE_NUMBER && $2 == F_MULT_EQ)) - type_error("Bad assignment. Rhs", $3); - ins_f_byte((unsigned)$2); - $$ = $3; - } + { + deref_index--; + if (!($1 & TYPE_LVALUE)) + yyerror("Illegal LHS"); + $1 &= ~TYPE_LVALUE; + if (exact_types && !compatible_types($1, $3) && + !($1 == TYPE_STRING && $3 == TYPE_NUMBER && $2 == F_ADD_EQ) && + !(($1 == TYPE_STRING || ($1 & TYPE_MOD_POINTER)) && + $3 == TYPE_NUMBER && $2 == F_MULT_EQ)) + type_error("Bad assignment. Rhs", $3); + ins_f_byte((unsigned)$2); + $$ = $3; + } | error assign expr01 { yyerror("Illegal LHS"); $$ = TYPE_ANY; }; opt_expr01: { $$ = TYPE_NONE;} @@ -944,48 +944,48 @@ opt_expr01: { $$ = TYPE_NONE;} expr01: expr1 { $$ = $1; } | expr1 '?' - { - push_address(); - ins_f_byte(F_JUMP_WHEN_ZERO); - add_jump(); - push_address(); - ins_address(0); - } - opt_expr01 - { - int i; - i = pop_address(); - if ($4 != TYPE_NONE) - { - (void)pop_address(); - ins_f_byte(F_JUMP); - add_jump(); - push_address(); - ins_address(0); - upd_address(i, mem_block[A_PROGRAM].current_size); - } - else - { - mem_block[A_PROGRAM].current_size = pop_address(); - ins_f_byte(F_SKIP_NZ); - push_address(); - ins_address(0); - $4 = $1; - } - } + { + push_address(); + ins_f_byte(F_JUMP_WHEN_ZERO); + add_jump(); + push_address(); + ins_address(0); + } + opt_expr01 + { + int i; + i = pop_address(); + if ($4 != TYPE_NONE) + { + (void)pop_address(); + ins_f_byte(F_JUMP); + add_jump(); + push_address(); + ins_address(0); + upd_address(i, mem_block[A_PROGRAM].current_size); + } + else + { + mem_block[A_PROGRAM].current_size = pop_address(); + ins_f_byte(F_SKIP_NZ); + push_address(); + ins_address(0); + $4 = $1; + } + } ':' expr01 - { - upd_address(pop_address(), mem_block[A_PROGRAM].current_size); - if (exact_types && !compatible_types($4, $7)) { - type_error("Different types in ?: expr", $4); - type_error(" and ", $7); - } - if ($4 == TYPE_ANY) $$ = $7; - else if ($7 == TYPE_ANY) $$ = $4; - else if (TYPE($4, TYPE_MOD_POINTER|TYPE_ANY)) $$ = $7; - else if (TYPE($7, TYPE_MOD_POINTER|TYPE_ANY)) $$ = $4; - else $$ = $4; - }; + { + upd_address(pop_address(), mem_block[A_PROGRAM].current_size); + if (exact_types && !compatible_types($4, $7)) { + type_error("Different types in ?: expr", $4); + type_error(" and ", $7); + } + if ($4 == TYPE_ANY) $$ = $7; + else if ($7 == TYPE_ANY) $$ = $4; + else if (TYPE($4, TYPE_MOD_POINTER|TYPE_ANY)) $$ = $7; + else if (TYPE($7, TYPE_MOD_POINTER|TYPE_ANY)) $$ = $4; + else $$ = $4; + }; assign: '=' { $$ = F_ASSIGN; } | F_AND_EQ { $$ = F_AND_EQ; } @@ -1000,583 +1000,583 @@ assign: '=' { $$ = F_ASSIGN; } | F_DIV_EQ { $$ = F_DIV_EQ; }; return: F_RETURN - { - if (exact_types && !TYPE(exact_types, TYPE_VOID)) - type_error("Must return a value for a function declared", - exact_types); - ins_f_byte(F_CONST0); - for (int i = try_level;i > 0; i--) - ins_f_byte(F_END_TRY); - ins_f_byte(F_JUMP); - add_jump(); - ins_label(return_label); - } + { + if (exact_types && !TYPE(exact_types, TYPE_VOID)) + type_error("Must return a value for a function declared", + exact_types); + ins_f_byte(F_CONST0); + for (int i = try_level;i > 0; i--) + ins_f_byte(F_END_TRY); + ins_f_byte(F_JUMP); + add_jump(); + ins_label(return_label); + } | F_RETURN comma_expr - { - if (exact_types && !TYPE($2, exact_types & TYPE_MASK)) - type_error("Return type not matching", exact_types); - for (int i = try_level; i > 0; i--) - ins_f_byte(F_END_TRY); - ins_f_byte(F_JUMP); - add_jump(); - ins_label(return_label); - }; - -expr_list: /* empty */ { $$ = 0; } - | expr_list2 { $$ = $1; } - | expr_list2 ',' { $$ = $1; } ; /* Allow a terminating comma */ - -expr_list2: expr0 { $$ = 1; add_arg_type($1); } - | expr_list2 ',' expr0 { $$ = $1 + 1; add_arg_type($3); } ; - -m_expr_list: /* empty */ { $$ = 0; } - | m_expr_list2 { $$ = $1; } - | m_expr_list2 ',' { $$ = $1; } ; /* Allow a terminating comma */ - -m_expr_list2: expr0 ':' expr1 { $$ = 2; add_arg_type($1); add_arg_type($3); } + { + if (exact_types && !TYPE($2, exact_types & TYPE_MASK)) + type_error("Return type not matching", exact_types); + for (int i = try_level; i > 0; i--) + ins_f_byte(F_END_TRY); + ins_f_byte(F_JUMP); + add_jump(); + ins_label(return_label); + }; + +expr_list: /* empty */ { $$ = 0; } + | expr_list2 { $$ = $1; } + | expr_list2 ',' { $$ = $1; } ; /* Allow a terminating comma */ + +expr_list2: expr0 { $$ = 1; add_arg_type($1); } + | expr_list2 ',' expr0 { $$ = $1 + 1; add_arg_type($3); } ; + +m_expr_list: /* empty */ { $$ = 0; } + | m_expr_list2 { $$ = $1; } + | m_expr_list2 ',' { $$ = $1; } ; /* Allow a terminating comma */ + +m_expr_list2: expr0 ':' expr1 { $$ = 2; add_arg_type($1); add_arg_type($3); } | m_expr_list2 ',' expr0 ':' expr1 { $$ = $1 + 2; add_arg_type($3); add_arg_type($5); }; expr1: expr2 { $$ = $1; } | expr2 F_LOR - { - ins_f_byte(F_DUP); - ins_f_byte(F_JUMP_WHEN_NON_ZERO); - add_jump(); - push_address(); - ins_address(0); - ins_f_byte(F_POP_VALUE); - } + { + ins_f_byte(F_DUP); + ins_f_byte(F_JUMP_WHEN_NON_ZERO); + add_jump(); + push_address(); + ins_address(0); + ins_f_byte(F_POP_VALUE); + } expr1 - { - upd_address(pop_address(), mem_block[A_PROGRAM].current_size); - if ($1 == $4) - $$ = $1; - else - $$ = TYPE_ANY; /* Return type can't be known */ - }; + { + upd_address(pop_address(), mem_block[A_PROGRAM].current_size); + if ($1 == $4) + $$ = $1; + else + $$ = TYPE_ANY; /* Return type can't be known */ + }; expr2: expr211 { $$ = $1; } | expr211 F_LAND - { - ins_f_byte(F_DUP); - ins_f_byte(F_JUMP_WHEN_ZERO); - add_jump(); - push_address(); - ins_address(0); - ins_f_byte(F_POP_VALUE); - } + { + ins_f_byte(F_DUP); + ins_f_byte(F_JUMP_WHEN_ZERO); + add_jump(); + push_address(); + ins_address(0); + ins_f_byte(F_POP_VALUE); + } expr2 - { - upd_address(pop_address(), mem_block[A_PROGRAM].current_size); - if ($1 == $4) - $$ = $1; - else - $$ = TYPE_ANY; /* Return type can't be known */ - } ; + { + upd_address(pop_address(), mem_block[A_PROGRAM].current_size); + if ($1 == $4) + $$ = $1; + else + $$ = TYPE_ANY; /* Return type can't be known */ + } ; expr211: expr212 | expr211 '|' expr212 { - int t1 = $1 & TYPE_MASK, t3 = $3 & TYPE_MASK; - if (($1 & TYPE_MOD_POINTER && $3 & TYPE_MOD_POINTER) && - (t1 == t3)) - $$ = $1; - else if (((t1 == TYPE_ANY) && $3 & TYPE_MOD_POINTER) || - ($1 & TYPE_MOD_POINTER && (t3 == TYPE_ANY))) - $$ = TYPE_MOD_POINTER | TYPE_ANY; - else if ((t1 == TYPE_ANY) && (t3 == TYPE_ANY)) - $$ = TYPE_ANY; - else - { - if (exact_types && !TYPE($1,TYPE_NUMBER)) - type_error("Bad argument 1 to |", $1); - if (exact_types && !TYPE($3,TYPE_NUMBER)) - type_error("Bad argument 2 to |", $3); - $$ = TYPE_NUMBER; - } - ins_f_byte(F_OR); - }; + int t1 = $1 & TYPE_MASK, t3 = $3 & TYPE_MASK; + if (($1 & TYPE_MOD_POINTER && $3 & TYPE_MOD_POINTER) && + (t1 == t3)) + $$ = $1; + else if (((t1 == TYPE_ANY) && $3 & TYPE_MOD_POINTER) || + ($1 & TYPE_MOD_POINTER && (t3 == TYPE_ANY))) + $$ = TYPE_MOD_POINTER | TYPE_ANY; + else if ((t1 == TYPE_ANY) && (t3 == TYPE_ANY)) + $$ = TYPE_ANY; + else + { + if (exact_types && !TYPE($1,TYPE_NUMBER)) + type_error("Bad argument 1 to |", $1); + if (exact_types && !TYPE($3,TYPE_NUMBER)) + type_error("Bad argument 2 to |", $3); + $$ = TYPE_NUMBER; + } + ins_f_byte(F_OR); + }; expr212: expr213 | expr212 '^' expr213 - { - if (exact_types && !TYPE($1,TYPE_NUMBER)) - type_error("Bad argument 1 to ^", $1); - if (exact_types && !TYPE($3,TYPE_NUMBER)) - type_error("Bad argument 2 to ^", $3); - $$ = TYPE_NUMBER; - ins_f_byte(F_XOR); - }; + { + if (exact_types && !TYPE($1,TYPE_NUMBER)) + type_error("Bad argument 1 to ^", $1); + if (exact_types && !TYPE($3,TYPE_NUMBER)) + type_error("Bad argument 2 to ^", $3); + $$ = TYPE_NUMBER; + ins_f_byte(F_XOR); + }; expr213: expr22 | expr213 '&' expr22 - { - int t1 = $1 & TYPE_MASK, t3 = $3 & TYPE_MASK; - if (($1 & TYPE_MOD_POINTER && $3 & TYPE_MOD_POINTER) && - (t1 == t3)) - $$ = $1; - else if (((t1 == TYPE_ANY) && $3 & TYPE_MOD_POINTER) || - ($1 & TYPE_MOD_POINTER && (t3 == TYPE_ANY))) - $$ = TYPE_MOD_POINTER | TYPE_ANY; - else if ((t1 == TYPE_ANY) && (t3 == TYPE_ANY)) - $$ = TYPE_ANY; - else - { - if (exact_types && !TYPE($1,TYPE_NUMBER)) - type_error("Bad argument 1 to &", $1); - if (exact_types && !TYPE($3,TYPE_NUMBER)) - type_error("Bad argument 2 to &", $3); - $$ = TYPE_NUMBER; - } - ins_f_byte(F_AND); - }; + { + int t1 = $1 & TYPE_MASK, t3 = $3 & TYPE_MASK; + if (($1 & TYPE_MOD_POINTER && $3 & TYPE_MOD_POINTER) && + (t1 == t3)) + $$ = $1; + else if (((t1 == TYPE_ANY) && $3 & TYPE_MOD_POINTER) || + ($1 & TYPE_MOD_POINTER && (t3 == TYPE_ANY))) + $$ = TYPE_MOD_POINTER | TYPE_ANY; + else if ((t1 == TYPE_ANY) && (t3 == TYPE_ANY)) + $$ = TYPE_ANY; + else + { + if (exact_types && !TYPE($1,TYPE_NUMBER)) + type_error("Bad argument 1 to &", $1); + if (exact_types && !TYPE($3,TYPE_NUMBER)) + type_error("Bad argument 2 to &", $3); + $$ = TYPE_NUMBER; + } + ins_f_byte(F_AND); + }; expr22: expr23 | expr24 F_EQ expr24 - { - int t1 = $1 & TYPE_MASK, t2 = $3 & TYPE_MASK; - if (exact_types && t1 != t2 && t1 != TYPE_ANY && t2 != TYPE_ANY) { - type_error("== always false because of different types", $1); - type_error(" compared to", $3); - } - ins_f_byte(F_EQ); - $$ = TYPE_NUMBER; - } + { + int t1 = $1 & TYPE_MASK, t2 = $3 & TYPE_MASK; + if (exact_types && t1 != t2 && t1 != TYPE_ANY && t2 != TYPE_ANY) { + type_error("== always false because of different types", $1); + type_error(" compared to", $3); + } + ins_f_byte(F_EQ); + $$ = TYPE_NUMBER; + } | expr24 F_NE expr24 - { - int t1 = $1 & TYPE_MASK, t2 = $3 & TYPE_MASK; - if (exact_types && t1 != t2 && t1 != TYPE_ANY && t2 != TYPE_ANY) { - type_error("!= always true because of different types", $1); - type_error(" compared to", $3); - } - ins_f_byte(F_NE); - $$ = TYPE_NUMBER; - }; + { + int t1 = $1 & TYPE_MASK, t2 = $3 & TYPE_MASK; + if (exact_types && t1 != t2 && t1 != TYPE_ANY && t2 != TYPE_ANY) { + type_error("!= always true because of different types", $1); + type_error(" compared to", $3); + } + ins_f_byte(F_NE); + $$ = TYPE_NUMBER; + }; expr23: expr24 | expr24 '>' expr24 - { $$ = TYPE_NUMBER; ins_f_byte(F_GT); } + { $$ = TYPE_NUMBER; ins_f_byte(F_GT); } | expr24 F_GE expr24 - { $$ = TYPE_NUMBER; ins_f_byte(F_GE); } + { $$ = TYPE_NUMBER; ins_f_byte(F_GE); } | expr24 '<' expr24 - { $$ = TYPE_NUMBER; ins_f_byte(F_LT); } + { $$ = TYPE_NUMBER; ins_f_byte(F_LT); } | expr24 F_LE expr24 - { $$ = TYPE_NUMBER; ins_f_byte(F_LE); }; + { $$ = TYPE_NUMBER; ins_f_byte(F_LE); }; expr24: expr25 | expr24 F_LSH expr25 - { - ins_f_byte(F_LSH); - $$ = TYPE_NUMBER; - if (exact_types && !TYPE($1, TYPE_NUMBER)) - type_error("Bad argument number 1 to '<<'", $1); - if (exact_types && !TYPE($3, TYPE_NUMBER)) - type_error("Bad argument number 2 to '<<'", $3); - } + { + ins_f_byte(F_LSH); + $$ = TYPE_NUMBER; + if (exact_types && !TYPE($1, TYPE_NUMBER)) + type_error("Bad argument number 1 to '<<'", $1); + if (exact_types && !TYPE($3, TYPE_NUMBER)) + type_error("Bad argument number 2 to '<<'", $3); + } | expr24 F_RSH expr25 - { - ins_f_byte(F_RSH); - $$ = TYPE_NUMBER; - if (exact_types && !TYPE($1, TYPE_NUMBER)) - type_error("Bad argument number 1 to '>>'", $1); - if (exact_types && !TYPE($3, TYPE_NUMBER)) - type_error("Bad argument number 2 to '>>'", $3); - }; + { + ins_f_byte(F_RSH); + $$ = TYPE_NUMBER; + if (exact_types && !TYPE($1, TYPE_NUMBER)) + type_error("Bad argument number 1 to '>>'", $1); + if (exact_types && !TYPE($3, TYPE_NUMBER)) + type_error("Bad argument number 2 to '>>'", $3); + }; expr25: expr27 - | expr25 '+' expr27 /* Type checks of this case is complicated */ - { ins_f_byte(F_ADD); $$ = TYPE_ANY; } + | expr25 '+' expr27 /* Type checks of this case is complicated */ + { ins_f_byte(F_ADD); $$ = TYPE_ANY; } | expr25 '-' expr27 - { - int bad_arg = 0; + { + int bad_arg = 0; - if (exact_types) { - if (!(TYPE($1, TYPE_NUMBER) || TYPE($1, TYPE_FLOAT)) && - !($1 & TYPE_MOD_POINTER) ) { + if (exact_types) { + if (!(TYPE($1, TYPE_NUMBER) || TYPE($1, TYPE_FLOAT)) && + !($1 & TYPE_MOD_POINTER) ) { type_error("Bad argument number 1 to '-'", $1); - bad_arg++; - } - if (!TYPE($3, $1) && !($3 & TYPE_MOD_POINTER) ) { + bad_arg++; + } + if (!TYPE($3, $1) && !($3 & TYPE_MOD_POINTER) ) { type_error("Bad argument number 2 to '-'", $3); - bad_arg++; - } - } - $$ = TYPE_ANY; - if (($1 & TYPE_MOD_POINTER) || ($3 & TYPE_MOD_POINTER)) - $$ = TYPE_MOD_POINTER | TYPE_ANY; - if (!($1 & TYPE_MOD_POINTER) || !($3 & TYPE_MOD_POINTER)) { - if (exact_types && $$ != TYPE_ANY && !bad_arg) - yyerror("Arguments to '-' don't match"); - $$ = ($1 & TYPE_MOD_POINTER)?$3:$1; - } - ins_f_byte(F_SUBTRACT); - } - ; + bad_arg++; + } + } + $$ = TYPE_ANY; + if (($1 & TYPE_MOD_POINTER) || ($3 & TYPE_MOD_POINTER)) + $$ = TYPE_MOD_POINTER | TYPE_ANY; + if (!($1 & TYPE_MOD_POINTER) || !($3 & TYPE_MOD_POINTER)) { + if (exact_types && $$ != TYPE_ANY && !bad_arg) + yyerror("Arguments to '-' don't match"); + $$ = ($1 & TYPE_MOD_POINTER)?$3:$1; + } + ins_f_byte(F_SUBTRACT); + } + ; expr27: expr28 | expr27 '*' expr3 - { + { if (exact_types && - !(TYPE($1, TYPE_NUMBER) || TYPE($1, TYPE_FLOAT) || - TYPE($1, TYPE_STRING) || TYPE($1, TYPE_ANY | TYPE_MOD_POINTER))) - type_error("Bad argument number 1 to '*'", $1); - if (exact_types && !TYPE($1, $3) && - !(TYPE($1, TYPE_STRING) && TYPE($3, TYPE_NUMBER)) && - !(TYPE($3, TYPE_STRING) && TYPE($1, TYPE_NUMBER)) && - !(TYPE($1, TYPE_ANY | TYPE_MOD_POINTER) && TYPE($3, TYPE_NUMBER)) && - !(TYPE($3, TYPE_ANY | TYPE_MOD_POINTER) && TYPE($1, TYPE_NUMBER))) - type_error("Bad argument number 2 to '*'", $3); - - ins_f_byte(F_MULTIPLY); + !(TYPE($1, TYPE_NUMBER) || TYPE($1, TYPE_FLOAT) || + TYPE($1, TYPE_STRING) || TYPE($1, TYPE_ANY | TYPE_MOD_POINTER))) + type_error("Bad argument number 1 to '*'", $1); + if (exact_types && !TYPE($1, $3) && + !(TYPE($1, TYPE_STRING) && TYPE($3, TYPE_NUMBER)) && + !(TYPE($3, TYPE_STRING) && TYPE($1, TYPE_NUMBER)) && + !(TYPE($1, TYPE_ANY | TYPE_MOD_POINTER) && TYPE($3, TYPE_NUMBER)) && + !(TYPE($3, TYPE_ANY | TYPE_MOD_POINTER) && TYPE($1, TYPE_NUMBER))) + type_error("Bad argument number 2 to '*'", $3); + + ins_f_byte(F_MULTIPLY); if (TYPE($3, TYPE_STRING) || - TYPE($3, TYPE_ANY | TYPE_MOD_POINTER)) - $$ = $3; + TYPE($3, TYPE_ANY | TYPE_MOD_POINTER)) + $$ = $3; else $$ = $1; - } + } | expr27 F_MOD expr3 - { - if (exact_types && !TYPE($1, TYPE_NUMBER)) - type_error("Bad argument number 1 to '%'", $1); - if (exact_types && !TYPE($3, TYPE_NUMBER)) - type_error("Bad argument number 2 to '%'", $3); - ins_f_byte(F_MOD); - $$ = TYPE_NUMBER; - } + { + if (exact_types && !TYPE($1, TYPE_NUMBER)) + type_error("Bad argument number 1 to '%'", $1); + if (exact_types && !TYPE($3, TYPE_NUMBER)) + type_error("Bad argument number 2 to '%'", $3); + ins_f_byte(F_MOD); + $$ = TYPE_NUMBER; + } | expr27 '/' expr3 - { - if (exact_types && !(TYPE($1, TYPE_NUMBER) || TYPE($1, TYPE_FLOAT))) - type_error("Bad argument number 1 to '/'", $1); - if (exact_types && !TYPE($3, $1)) - type_error("Bad argument number 2 to '/'", $3); - ins_f_byte(F_DIVIDE); - $$ = $1; - } + { + if (exact_types && !(TYPE($1, TYPE_NUMBER) || TYPE($1, TYPE_FLOAT))) + type_error("Bad argument number 1 to '/'", $1); + if (exact_types && !TYPE($3, $1)) + type_error("Bad argument number 2 to '/'", $3); + ins_f_byte(F_DIVIDE); + $$ = $1; + } | expr27 '@' expr3 - { - if (exact_types && !TYPE($1, TYPE_FUNCTION)) - type_error("Bad argument number 1 to '@'", $1); - if (exact_types && !TYPE($3, TYPE_FUNCTION)) - type_error("Bad argument number 2 to '@'", $3); - ins_f_byte(F_BUILD_CLOSURE); - ins_byte(FUN_COMPOSE); - $$ = TYPE_FUNCTION; - } - ; + { + if (exact_types && !TYPE($1, TYPE_FUNCTION)) + type_error("Bad argument number 1 to '@'", $1); + if (exact_types && !TYPE($3, TYPE_FUNCTION)) + type_error("Bad argument number 2 to '@'", $3); + ins_f_byte(F_BUILD_CLOSURE); + ins_byte(FUN_COMPOSE); + $$ = TYPE_FUNCTION; + } + ; expr28: expr3 - | cast expr3 - { - $$ = $1; - if (exact_types && $2 != TYPE_ANY && $2 != TYPE_UNKNOWN && - $1 != TYPE_VOID) - type_error("Casts are only legal for type mixed, or when unknown", $2); - } ; + | cast expr3 + { + $$ = $1; + if (exact_types && $2 != TYPE_ANY && $2 != TYPE_UNKNOWN && + $1 != TYPE_VOID) + type_error("Casts are only legal for type mixed, or when unknown", $2); + } ; expr3: expr31 | F_INC lvalue { - deref_index--; - ins_f_byte(F_INC); - if (exact_types && !TYPE($2, TYPE_NUMBER)) - type_error("Bad argument to ++", $2); - $$ = TYPE_NUMBER; - } + deref_index--; + ins_f_byte(F_INC); + if (exact_types && !TYPE($2, TYPE_NUMBER)) + type_error("Bad argument to ++", $2); + $$ = TYPE_NUMBER; + } | F_DEC lvalue { - deref_index--; - ins_f_byte(F_DEC); - if (exact_types && !TYPE($2, TYPE_NUMBER)) - type_error("Bad argument to --", $2); - $$ = TYPE_NUMBER; - } + deref_index--; + ins_f_byte(F_DEC); + if (exact_types && !TYPE($2, TYPE_NUMBER)) + type_error("Bad argument to --", $2); + $$ = TYPE_NUMBER; + } | F_NOT expr3 - { - ins_f_byte(F_NOT); /* Any type is valid here. */ - $$ = TYPE_NUMBER; - } + { + ins_f_byte(F_NOT); /* Any type is valid here. */ + $$ = TYPE_NUMBER; + } | '~' expr3 - { - ins_f_byte(F_COMPL); - if (exact_types && !TYPE($2, TYPE_NUMBER)) - type_error("Bad argument to ~", $2); - $$ = TYPE_NUMBER; - } + { + ins_f_byte(F_COMPL); + if (exact_types && !TYPE($2, TYPE_NUMBER)) + type_error("Bad argument to ~", $2); + $$ = TYPE_NUMBER; + } | '-' expr3 - { - ins_f_byte(F_NEGATE); - if (exact_types && !(TYPE($2, TYPE_NUMBER) || TYPE($2, TYPE_FLOAT))) - type_error("Bad argument to unary '-'", $2); - $$ = $2; - } + { + ins_f_byte(F_NEGATE); + if (exact_types && !(TYPE($2, TYPE_NUMBER) || TYPE($2, TYPE_FLOAT))) + type_error("Bad argument to unary '-'", $2); + $$ = $2; + } | '&' funexpr '(' oexpr_list ')' - { - if ($4) { - pop_arg_stack($4); - ins_f_byte(F_PAPPLY); - ins_byte((char)$4); - } - if (exact_types && !TYPE($2, TYPE_FUNCTION)) - type_error("Bad argument to unary '&'", $2); - $$ = TYPE_FUNCTION; - } + { + if ($4) { + pop_arg_stack($4); + ins_f_byte(F_PAPPLY); + ins_byte((char)$4); + } + if (exact_types && !TYPE($2, TYPE_FUNCTION)) + type_error("Bad argument to unary '&'", $2); + $$ = TYPE_FUNCTION; + } | '&' F_ARROW F_IDENTIFIER - { - /* emulate &call_other(,id) */ + { + /* emulate &call_other(,id) */ - ins_f_byte(F_BUILD_CLOSURE); - ins_byte(FUN_EFUN); - ins_short(F_CALL_OTHER); /* call_other */ + ins_f_byte(F_BUILD_CLOSURE); + ins_byte(FUN_EFUN); + ins_short(F_CALL_OTHER); /* call_other */ - ins_f_byte(F_BUILD_CLOSURE); - ins_byte(FUN_EMPTY); /* empty arg */ + ins_f_byte(F_BUILD_CLOSURE); + ins_byte(FUN_EMPTY); /* empty arg */ - ins_f_byte(F_STRING); - ins_short(store_prog_string($3)); /* the string for the id */ + ins_f_byte(F_STRING); + ins_short(store_prog_string($3)); /* the string for the id */ - } '(' oexpr_list ')' - { - pop_arg_stack($6); - ins_f_byte(F_PAPPLY); - ins_byte((char)(2 + $6)); /* two args above & the oexpr_list */ + } '(' oexpr_list ')' + { + pop_arg_stack($6); + ins_f_byte(F_PAPPLY); + ins_byte((char)(2 + $6)); /* two args above & the oexpr_list */ - $$ = TYPE_FUNCTION; - } + $$ = TYPE_FUNCTION; + } ; funexpr: - funident { $$ = $1; } - | string_or_id F_ARROW F_IDENTIFIER - { - ins_f_byte(F_STRING); - ins_short(store_prog_string($3)); - ins_f_byte(F_BUILD_CLOSURE); - ins_byte(FUN_LFUNO); - $$ = TYPE_FUNCTION; - } - ; + funident { $$ = $1; } + | string_or_id F_ARROW F_IDENTIFIER + { + ins_f_byte(F_STRING); + ins_short(store_prog_string($3)); + ins_f_byte(F_BUILD_CLOSURE); + ins_byte(FUN_LFUNO); + $$ = TYPE_FUNCTION; + } + ; /* I hate it! LA */ string_or_id: - string - { - $$ = $1; - } - | identifier - { + string + { + $$ = $1; + } + | identifier + { int var_num = lookup_local_name($1); if (var_num != -1) { - ins_f_byte(F_LOCAL_NAME); - ins_byte((char)var_num); + ins_f_byte(F_LOCAL_NAME); + ins_byte((char)var_num); } else { - int i = verify_declared($1); - - if (i == -1) { - char buff[100]; - - (void)snprintf(buff, sizeof(buff), "Variable %s not declared!", $1); - yyerror(buff); - } else { - ins_f_byte(F_IDENTIFIER); - ins_byte((char)variable_inherit_found); - ins_byte((char)variable_index_found); - } + int i = verify_declared($1); + + if (i == -1) { + char buff[100]; + + (void)snprintf(buff, sizeof(buff), "Variable %s not declared!", $1); + yyerror(buff); + } else { + ins_f_byte(F_IDENTIFIER); + ins_byte((char)variable_inherit_found); + ins_byte((char)variable_index_found); + } } - } - | '(' comma_expr ')' - ; + } + | '(' comma_expr ')' + ; -oexpr_list: /* empty */ { $$ = 0; } - | expr0 { add_arg_type($1); $$ = 1; } - | oexpr_list1 { $$ = $1; }; +oexpr_list: /* empty */ { $$ = 0; } + | expr0 { add_arg_type($1); $$ = 1; } + | oexpr_list1 { $$ = $1; }; -oexpr_list1: oexpr0 ',' oexpr0 { $$ = 2; } - | oexpr0 ',' oexpr_list1 { $$ = $3 + 1; } ; +oexpr_list1: oexpr0 ',' oexpr0 { $$ = 2; } + | oexpr0 ',' oexpr_list1 { $$ = $3 + 1; } ; -oexpr0: expr0 { add_arg_type($1); } - | /*empty */ { - ins_f_byte(F_BUILD_CLOSURE); - ins_byte(FUN_EMPTY); - add_arg_type(TYPE_ANY); - } - ; +oexpr0: expr0 { add_arg_type($1); } + | /*empty */ { + ins_f_byte(F_BUILD_CLOSURE); + ins_byte(FUN_EMPTY); + add_arg_type(TYPE_ANY); + } + ; funident: F_IDENTIFIER - { + { int var_num = lookup_local_name($1); if (var_num != -1) { - ins_f_byte(F_LOCAL_NAME); - ins_byte((char)var_num); + ins_f_byte(F_LOCAL_NAME); + ins_byte((char)var_num); $$ = type_of_locals[var_num]; } else { - int i = verify_declared($1); - - if (i == -1) { - if (handle_function_id($1)) { - $$ = TYPE_FUNCTION; - } else { - char buff[100]; - - (void)snprintf(buff, sizeof(buff), "Variable %s not declared!", $1); - yyerror(buff); - $$ = TYPE_ANY; - } - } else { - ins_f_byte(F_IDENTIFIER); - ins_byte((char)variable_inherit_found); - ins_byte((char)variable_index_found); - $$ = i & TYPE_MASK; - } + int i = verify_declared($1); + + if (i == -1) { + if (handle_function_id($1)) { + $$ = TYPE_FUNCTION; + } else { + char buff[100]; + + (void)snprintf(buff, sizeof(buff), "Variable %s not declared!", $1); + yyerror(buff); + $$ = TYPE_ANY; + } + } else { + ins_f_byte(F_IDENTIFIER); + ins_byte((char)variable_inherit_found); + ins_byte((char)variable_index_found); + $$ = i & TYPE_MASK; + } } } - | funoperator - { - $$ = TYPE_FUNCTION; - }; + | funoperator + { + $$ = TYPE_FUNCTION; + }; funoperator: - F_OPERATOR '(' funop ')' - { - ins_f_byte(F_BUILD_CLOSURE); /* and build the function closure */ - ins_byte(FUN_EFUN); - ins_short((short)$3); - }; - -funop: '+' { $$ = F_ADD; } | - '-' { $$ = F_SUBTRACT; } | - '*' { $$ = F_MULTIPLY; } | - '/' { $$ = F_DIVIDE; } | - F_MOD { $$ = F_MOD; } | - '>' { $$ = F_GT; } | - '<' { $$ = F_LT; } | - F_GE { $$ = F_GE; } | - F_LE { $$ = F_LE; } | - F_EQ { $$ = F_EQ; } | - F_NE { $$ = F_NE; } | - '&' { $$ = F_AND; } | - '^' { $$ = F_XOR; } | - '|' { $$ = F_OR; } | - F_LSH { $$ = F_LSH; } | - F_RSH { $$ = F_RSH; } | - '[' ']' { $$ = F_INDEX; } | - F_NOT { $$ = F_NOT; } | - '~' { $$ = F_COMPL; }; + F_OPERATOR '(' funop ')' + { + ins_f_byte(F_BUILD_CLOSURE); /* and build the function closure */ + ins_byte(FUN_EFUN); + ins_short((short)$3); + }; + +funop: '+' { $$ = F_ADD; } | + '-' { $$ = F_SUBTRACT; } | + '*' { $$ = F_MULTIPLY; } | + '/' { $$ = F_DIVIDE; } | + F_MOD { $$ = F_MOD; } | + '>' { $$ = F_GT; } | + '<' { $$ = F_LT; } | + F_GE { $$ = F_GE; } | + F_LE { $$ = F_LE; } | + F_EQ { $$ = F_EQ; } | + F_NE { $$ = F_NE; } | + '&' { $$ = F_AND; } | + '^' { $$ = F_XOR; } | + '|' { $$ = F_OR; } | + F_LSH { $$ = F_LSH; } | + F_RSH { $$ = F_RSH; } | + '[' ']' { $$ = F_INDEX; } | + F_NOT { $$ = F_NOT; } | + '~' { $$ = F_COMPL; }; /*aexpr: rvalue | '(' comma_expr ')' { $$ = $2; };*/ expr31: expr4 | lvalue F_INC { - deref_index--; - ins_f_byte(F_POST_INC); - if (exact_types && !TYPE($1, TYPE_NUMBER)) - type_error("Bad argument to ++", $1); - $$ = TYPE_NUMBER; - } + deref_index--; + ins_f_byte(F_POST_INC); + if (exact_types && !TYPE($1, TYPE_NUMBER)) + type_error("Bad argument to ++", $1); + $$ = TYPE_NUMBER; + } | lvalue F_DEC { - deref_index--; - ins_f_byte(F_POST_DEC); - if (exact_types && !TYPE($1, TYPE_NUMBER)) - type_error("Bad argument to --", $1); - $$ = TYPE_NUMBER; - }; + deref_index--; + ins_f_byte(F_POST_DEC); + if (exact_types && !TYPE($1, TYPE_NUMBER)) + type_error("Bad argument to --", $1); + $$ = TYPE_NUMBER; + }; rvalue: lvalue - { - int i, lastl; - /* This is yucky! But the way the parser is structured - * together with YACC forces it. - */ - if (deref_index <= 0) - fatal("deref_index\n"); - lastl = deref_stack[--deref_index]; - if (lastl != -1) { - switch(mem_block[A_PROGRAM].block[lastl]) { - case F_PUSH_IDENTIFIER_LVALUE-EFUN_FIRST: - i = F_IDENTIFIER-EFUN_FIRST; break; - case F_PUSH_LOCAL_VARIABLE_LVALUE-EFUN_FIRST: - i = F_LOCAL_NAME-EFUN_FIRST; break; - case F_PUSH_INDEXED_LVALUE-EFUN_FIRST: - i = F_INDEX-EFUN_FIRST; break; - default:i = -1; break; - } - if (i == -1) fatal("Should be a push at this point!\n"); - mem_block[A_PROGRAM].block[lastl] = i; - } - $$ = $1 & ~TYPE_LVALUE; - }; + { + int i, lastl; + /* This is yucky! But the way the parser is structured + * together with YACC forces it. + */ + if (deref_index <= 0) + fatal("deref_index\n"); + lastl = deref_stack[--deref_index]; + if (lastl != -1) { + switch(mem_block[A_PROGRAM].block[lastl]) { + case F_PUSH_IDENTIFIER_LVALUE-EFUN_FIRST: + i = F_IDENTIFIER-EFUN_FIRST; break; + case F_PUSH_LOCAL_VARIABLE_LVALUE-EFUN_FIRST: + i = F_LOCAL_NAME-EFUN_FIRST; break; + case F_PUSH_INDEXED_LVALUE-EFUN_FIRST: + i = F_INDEX-EFUN_FIRST; break; + default:i = -1; break; + } + if (i == -1) fatal("Should be a push at this point!\n"); + mem_block[A_PROGRAM].block[lastl] = i; + } + $$ = $1 & ~TYPE_LVALUE; + }; expr4: rvalue - | funoperator - { - $$ = TYPE_FUNCTION; - } - | expr4 '[' comma_expr F_RANGE comma_expr ']' - { - ins_f_byte(F_RANGE); - if (exact_types && !($1 & TYPE_MAPPING)) - { - if (($1 & TYPE_MOD_POINTER) == 0 && !TYPE($1, TYPE_STRING)) - type_error("Bad type to indexed value", $1); - if (!TYPE($3, TYPE_NUMBER)) - type_error("Bad type of index", $3); - if (!TYPE($5, TYPE_NUMBER)) - type_error("Bad type of index", $5); - } - if ($1 == TYPE_ANY) - $$ = TYPE_ANY; - else if (TYPE($1, TYPE_STRING)) - $$ = TYPE_STRING; - else if ($1 & TYPE_MOD_POINTER) - $$ = $1; - else if (exact_types) - type_error("Bad type of argument used for range", $1); - } - | expr4 '[' F_RANGE { ins_f_byte(F_CONST0); } comma_expr ']' - { - ins_f_byte(F_RANGE); - if (exact_types && !($1 & TYPE_MAPPING)) - { - if (($1 & TYPE_MOD_POINTER) == 0 && !TYPE($1, TYPE_STRING)) - type_error("Bad type to indexed value", $1); - if (!TYPE($5, TYPE_NUMBER)) - type_error("Bad type of index", $5); - } - if ($1 == TYPE_ANY) - $$ = TYPE_ANY; - else if (TYPE($1, TYPE_STRING)) - $$ = TYPE_STRING; - else if ($1 & TYPE_MOD_POINTER) - $$ = $1; - else if (exact_types) - type_error("Bad type of argument used for range", $1); - } - | expr4 '[' comma_expr F_RANGE ']' - { + | funoperator + { + $$ = TYPE_FUNCTION; + } + | expr4 '[' comma_expr F_RANGE comma_expr ']' + { + ins_f_byte(F_RANGE); + if (exact_types && !($1 & TYPE_MAPPING)) + { + if (($1 & TYPE_MOD_POINTER) == 0 && !TYPE($1, TYPE_STRING)) + type_error("Bad type to indexed value", $1); + if (!TYPE($3, TYPE_NUMBER)) + type_error("Bad type of index", $3); + if (!TYPE($5, TYPE_NUMBER)) + type_error("Bad type of index", $5); + } + if ($1 == TYPE_ANY) + $$ = TYPE_ANY; + else if (TYPE($1, TYPE_STRING)) + $$ = TYPE_STRING; + else if ($1 & TYPE_MOD_POINTER) + $$ = $1; + else if (exact_types) + type_error("Bad type of argument used for range", $1); + } + | expr4 '[' F_RANGE { ins_f_byte(F_CONST0); } comma_expr ']' + { + ins_f_byte(F_RANGE); + if (exact_types && !($1 & TYPE_MAPPING)) + { + if (($1 & TYPE_MOD_POINTER) == 0 && !TYPE($1, TYPE_STRING)) + type_error("Bad type to indexed value", $1); + if (!TYPE($5, TYPE_NUMBER)) + type_error("Bad type of index", $5); + } + if ($1 == TYPE_ANY) + $$ = TYPE_ANY; + else if (TYPE($1, TYPE_STRING)) + $$ = TYPE_STRING; + else if ($1 & TYPE_MOD_POINTER) + $$ = $1; + else if (exact_types) + type_error("Bad type of argument used for range", $1); + } + | expr4 '[' comma_expr F_RANGE ']' + { static long long maxint = ~(unsigned long long)0 >> 1; - ins_f_byte(F_NUMBER); - ins_mem(&maxint, sizeof(maxint)); /* MAXINT */ - - ins_f_byte(F_RANGE); - if (exact_types && !($1 & TYPE_MAPPING)) - { - if (($1 & TYPE_MOD_POINTER) == 0 && !TYPE($1, TYPE_STRING)) - type_error("Bad type to indexed value", $1); - if (!TYPE($3, TYPE_NUMBER)) - type_error("Bad type of index", $3); - } - if ($1 == TYPE_ANY) - $$ = TYPE_ANY; - else if (TYPE($1, TYPE_STRING)) - $$ = TYPE_STRING; - else if ($1 & TYPE_MOD_POINTER) - $$ = $1; - else if (exact_types) - type_error("Bad type of argument used for range", $1); - } + ins_f_byte(F_NUMBER); + ins_mem(&maxint, sizeof(maxint)); /* MAXINT */ + + ins_f_byte(F_RANGE); + if (exact_types && !($1 & TYPE_MAPPING)) + { + if (($1 & TYPE_MOD_POINTER) == 0 && !TYPE($1, TYPE_STRING)) + type_error("Bad type to indexed value", $1); + if (!TYPE($3, TYPE_NUMBER)) + type_error("Bad type of index", $3); + } + if ($1 == TYPE_ANY) + $$ = TYPE_ANY; + else if (TYPE($1, TYPE_STRING)) + $$ = TYPE_STRING; + else if ($1 & TYPE_MOD_POINTER) + $$ = $1; + else if (exact_types) + type_error("Bad type of argument used for range", $1); + } | string | number | real | '(' comma_expr ')' { $$ = $2; } @@ -1585,84 +1585,84 @@ expr4: rvalue | parse_command { $$ = TYPE_NUMBER; } | '(' '{' expr_list '}' ')' { - pop_arg_stack($3); /* We don't care about these types */ - ins_f_byte(F_AGGREGATE); - ins_short((short)$3); - $$ = TYPE_MOD_POINTER | TYPE_ANY; + pop_arg_stack($3); /* We don't care about these types */ + ins_f_byte(F_AGGREGATE); + ins_short((short)$3); + $$ = TYPE_MOD_POINTER | TYPE_ANY; } | '(' '[' m_expr_list ']' ')' { - pop_arg_stack($3); - ins_f_byte(F_M_AGGREGATE); - ins_short((short)$3); - $$ = TYPE_MAPPING; + pop_arg_stack($3); + ins_f_byte(F_M_AGGREGATE); + ins_short((short)$3); + $$ = TYPE_MAPPING; } - /* Function calls */ + /* Function calls */ /* ident, not name. Calls to :: functions are not allowed anyway /Dark */ | call_other_start { - ins_f_byte(F_BUILD_CLOSURE); - ins_byte(FUN_LFUNO); - $$ = TYPE_FUNCTION; - } + ins_f_byte(F_BUILD_CLOSURE); + ins_byte(FUN_LFUNO); + $$ = TYPE_FUNCTION; + } | expr4 '(' expr_list ')' - { + { if ($1 != TYPE_FUNCTION && $1 != TYPE_ANY) - type_error("Call of non-function", $1); - ins_f_byte(F_CALL_VAR); - ins_byte((char)$3); - pop_arg_stack($3); + type_error("Call of non-function", $1); + ins_f_byte(F_CALL_VAR); + ins_byte((char)$3); + pop_arg_stack($3); #if MUSTCASTFUN - $$ = TYPE_UNKNOWN; + $$ = TYPE_UNKNOWN; #else - $$ = TYPE_ANY; + $$ = TYPE_ANY; #endif - } + } | call_other_start '(' expr_list ')' { - ins_f_byte(F_CALL_OTHER); - ins_byte((char)($3 + 2)); - pop_arg_stack($3); /* No good need of these arguments */ - $$ = TYPE_ANY; /* TYPE_UNKNOWN forces casts */ - } + ins_f_byte(F_CALL_OTHER); + ins_byte((char)($3 + 2)); + pop_arg_stack($3); /* No good need of these arguments */ + $$ = TYPE_ANY; /* TYPE_UNKNOWN forces casts */ + } | identifier '(' expr_list ')' /* special case */ { int var_num = lookup_local_name($1); if (var_num != -1) { - int t; - ins_f_byte(F_LOCAL_NAME); - ins_byte((char)var_num); - t = type_of_locals[var_num]; + int t; + ins_f_byte(F_LOCAL_NAME); + ins_byte((char)var_num); + t = type_of_locals[var_num]; if (t != TYPE_FUNCTION && t != TYPE_ANY) - type_error("Call of non-function", t); - ins_f_byte(F_CALL_VAR); - ins_byte((char)$3); - pop_arg_stack($3); /* Argument types not needed more */ + type_error("Call of non-function", t); + ins_f_byte(F_CALL_VAR); + ins_byte((char)$3); + pop_arg_stack($3); /* Argument types not needed more */ #if MUSTCASTFUN - $$ = TYPE_UNKNOWN; + $$ = TYPE_UNKNOWN; #else - $$ = TYPE_ANY; + $$ = TYPE_ANY; #endif } else { /* Note that this code could be made a lot cleaner if some * support functions were added. (efun_call() is a good one) - */ - int inherited_override = strchr($1, ':') != NULL; - int efun_override = inherited_override && strncmp($1,"efun::", 6) == 0; - int is_sfun = 0; - int f = -1; - - $$ = TYPE_ANY; /* in case anything goes wrong we need a default type. /LA */ - if (inherited_override && !efun_override) - { - struct function *funp; + */ + int inherited_override = strchr($1, ':') != NULL; + int efun_override = inherited_override && strncmp($1,"efun::", 6) == 0; + int is_sfun = 0; + int f = -1; + + $$ = TYPE_ANY; /* in case anything goes wrong we need a default type. /LA */ + if (inherited_override && !efun_override) + { + struct function *funp; /* Find the right function to call * This assumes max 255 inherited programs * and 32767 functions in one program. */ - if (defined_function($1)) - { + if (defined_function($1)) + { if (function_prog_found) { funp = &(function_prog_found->functions[function_index_found]); @@ -1670,277 +1670,277 @@ expr4: rvalue funp = FUNCTION(function_index_found); } - $$ = funp->type_flags & TYPE_MASK; - ins_f_byte(F_CALL_NON_VIRT); - ins_byte ((char)function_inherit_found); + $$ = funp->type_flags & TYPE_MASK; + ins_f_byte(F_CALL_NON_VIRT); + ins_byte ((char)function_inherit_found); ins_short ((short)function_index_found); - ins_byte((char)$3); /* Number of arguments */ - } - else - { - char buff[100]; - - (void)snprintf(buff, sizeof(buff), "Function %s undefined", $1); - yyerror(buff); + ins_byte((char)$3); /* Number of arguments */ + } + else + { + char buff[100]; + + (void)snprintf(buff, sizeof(buff), "Function %s undefined", $1); + yyerror(buff); } } /* All simul_efuns are considered defined. - */ - else if (!efun_override && + */ + else if (!efun_override && (defined_function ($1) || ((is_sfun = 1) && is_simul_efun ($1))) ) - { - struct function *funp; - unsigned short *arg_indices; - unsigned short *arg_types; - - if (function_prog_found) - { - funp = &(function_prog_found-> - functions[function_index_found]); - arg_indices = function_prog_found->type_start; - arg_types = function_prog_found->argument_types; - } - else - { - funp = FUNCTION(function_index_found); - - /* Beware... these are pointers to volatile structures - */ - arg_indices = (unsigned short *) mem_block[A_ARGUMENT_INDEX].block; - arg_types = (unsigned short *) mem_block[A_ARGUMENT_TYPES].block; - /* Assumption: exact_types implies correct - values for arg_types - */ - } - - /* Private functions in inherited programs may not be called. - */ - if (function_prog_found && - function_type_mod_found & TYPE_MOD_PRIVATE) - { - char buff[100]; - - (void)snprintf(buff, sizeof(buff), "Function %s marked 'private'", - funp->name); - yyerror (buff); - } - $$ = funp->type_flags & TYPE_MASK; + { + struct function *funp; + unsigned short *arg_indices; + unsigned short *arg_types; + + if (function_prog_found) + { + funp = &(function_prog_found-> + functions[function_index_found]); + arg_indices = function_prog_found->type_start; + arg_types = function_prog_found->argument_types; + } + else + { + funp = FUNCTION(function_index_found); + + /* Beware... these are pointers to volatile structures + */ + arg_indices = (unsigned short *) mem_block[A_ARGUMENT_INDEX].block; + arg_types = (unsigned short *) mem_block[A_ARGUMENT_TYPES].block; + /* Assumption: exact_types implies correct + values for arg_types + */ + } + + /* Private functions in inherited programs may not be called. + */ + if (function_prog_found && + function_type_mod_found & TYPE_MOD_PRIVATE) + { + char buff[100]; + + (void)snprintf(buff, sizeof(buff), "Function %s marked 'private'", + funp->name); + yyerror (buff); + } + $$ = funp->type_flags & TYPE_MASK; if (is_sfun) - { + { ins_f_byte(F_CALL_SIMUL); - store_reloc_data(R_CALL, mem_block[A_PROGRAM].current_size, $1,0,0); - } + store_reloc_data(R_CALL, mem_block[A_PROGRAM].current_size, $1,0,0); + } else if (function_type_mod_found & (TYPE_MOD_NO_MASK|TYPE_MOD_PRIVATE)) - { + { ins_f_byte(F_CALL_NON_VIRT); - } + } else - { - ins_f_byte (F_CALL_VIRT); - if (function_prog_found) - store_reloc_data(R_CALL, mem_block[A_PROGRAM].current_size, $1,0,0); - } - ins_byte ((char)function_inherit_found); + { + ins_f_byte (F_CALL_VIRT); + if (function_prog_found) + store_reloc_data(R_CALL, mem_block[A_PROGRAM].current_size, $1,0,0); + } + ins_byte ((char)function_inherit_found); ins_short ((short)function_index_found); /* Insert function name into string list and code its index - */ - ins_byte ((char)$3); - - /* - * Check number of arguments. - */ - if ((funp->type_flags & NAME_STRICT_TYPES) && exact_types && - funp->num_arg != $3 && - - /* An old varargs function */ - !((funp->type_flags & TYPE_MOD_VARARGS) && - $3 < funp->num_arg) && - - /* A true varargs function? */ - !((funp->type_flags & TYPE_MOD_TRUE_VARARGS) && - $3 + 1 >= funp->num_arg) && - - /* A function with default values for arguments? */ - !($3 < funp->num_arg && funp->first_default <= $3)) - { - char buff[100]; - - (void)snprintf(buff, sizeof(buff), "Wrong number of arguments to %s", $1); - yyerror(buff); - } - - /* - * Check the argument types. - */ - if (funp->type_flags & NAME_STRICT_TYPES && - exact_types && arg_indices && - arg_indices[function_index_found] != INDEX_START_NONE) - { - int i, first; - int num_check = funp->num_arg; - - if (funp->type_flags & TYPE_MOD_TRUE_VARARGS) - num_check--; - - first = arg_indices[function_index_found]; - for (i=0; i < num_check && i < $3; i++) - { - int tmp = get_argument_type(i, $3); - if (!TYPE(tmp, arg_types[first + i])) - { - char buff[100]; - - (void)snprintf(buff, sizeof(buff), - "Bad type for argument %d %s", i+1, - get_two_types(arg_types[first+i], tmp)); - yyerror(buff); - } - } - } - } - - else if (efun_override || (f = lookup_predef($1)) != -1) - { - int min, max, def, *argp; - extern int efun_arg_types[]; - - if (efun_override) - f = lookup_predef($1+6); - - if (f == -1) /* Only possible for efun_override */ - { - char buff[100]; - - (void)snprintf(buff, sizeof(buff), "Unknown efun: %s", $1+6); - yyerror(buff); - } - else - { - min = instrs[f-EFUN_FIRST].min_arg; - max = instrs[f-EFUN_FIRST].max_arg; - def = instrs[f-EFUN_FIRST].Default; - $$ = instrs[f-EFUN_FIRST].ret_type; - argp = &efun_arg_types[instrs[f-EFUN_FIRST].arg_index]; - if (def && $3 == min-1) - { - ins_f_byte((unsigned)def); - max--; - min--; - } - else if ($3 < min) - { - char bff[100]; - - (void)snprintf(bff, sizeof(bff), "Too few arguments to %s", - instrs[f-EFUN_FIRST].name); - yyerror(bff); - } - else if ($3 > max && max != -1) - { - char bff[100]; - - (void)snprintf(bff, sizeof(bff), "Too many arguments to %s", - instrs[f - EFUN_FIRST].name); - yyerror(bff); - } - else if (max != -1 && exact_types) - { - /* - * Now check all types of the arguments to efuns. - */ - int i, argn; - char buff[100]; - for (argn=0; argn < $3; argn++) - { - int tmp = get_argument_type(argn, $3); - for(i=0; !TYPE(argp[i], tmp) && argp[i] != 0; i++) - ; - if (argp[i] == 0) - { - (void)snprintf(buff, sizeof(buff), - "Bad argument %d type to efun %s()", - argn+1, instrs[f-EFUN_FIRST].name); - yyerror(buff); - } - while(argp[i] != 0) - i++; - argp += i + 1; - } - } - ins_f_byte((unsigned)f); - - /* Only store number of arguments for instructions - * that allowed a variable number. - */ - if (max != min) - ins_byte((char)$3); /* Number of actual arguments */ - } - } - else - { - int i; - i = verify_declared($1); - if (i != -1 && (i & TYPE_MASK) == TYPE_FUNCTION) { - ins_f_byte(F_IDENTIFIER); - ins_byte((char)variable_inherit_found); - ins_byte((char)variable_index_found); - ins_f_byte(F_CALL_VAR); - ins_byte((char)$3); + */ + ins_byte ((char)$3); + + /* + * Check number of arguments. + */ + if ((funp->type_flags & NAME_STRICT_TYPES) && exact_types && + funp->num_arg != $3 && + + /* An old varargs function */ + !((funp->type_flags & TYPE_MOD_VARARGS) && + $3 < funp->num_arg) && + + /* A true varargs function? */ + !((funp->type_flags & TYPE_MOD_TRUE_VARARGS) && + $3 + 1 >= funp->num_arg) && + + /* A function with default values for arguments? */ + !($3 < funp->num_arg && funp->first_default <= $3)) + { + char buff[100]; + + (void)snprintf(buff, sizeof(buff), "Wrong number of arguments to %s", $1); + yyerror(buff); + } + + /* + * Check the argument types. + */ + if (funp->type_flags & NAME_STRICT_TYPES && + exact_types && arg_indices && + arg_indices[function_index_found] != INDEX_START_NONE) + { + int i, first; + int num_check = funp->num_arg; + + if (funp->type_flags & TYPE_MOD_TRUE_VARARGS) + num_check--; + + first = arg_indices[function_index_found]; + for (i=0; i < num_check && i < $3; i++) + { + int tmp = get_argument_type(i, $3); + if (!TYPE(tmp, arg_types[first + i])) + { + char buff[100]; + + (void)snprintf(buff, sizeof(buff), + "Bad type for argument %d %s", i+1, + get_two_types(arg_types[first+i], tmp)); + yyerror(buff); + } + } + } + } + + else if (efun_override || (f = lookup_predef($1)) != -1) + { + int min, max, def, *argp; + extern int efun_arg_types[]; + + if (efun_override) + f = lookup_predef($1+6); + + if (f == -1) /* Only possible for efun_override */ + { + char buff[100]; + + (void)snprintf(buff, sizeof(buff), "Unknown efun: %s", $1+6); + yyerror(buff); + } + else + { + min = instrs[f-EFUN_FIRST].min_arg; + max = instrs[f-EFUN_FIRST].max_arg; + def = instrs[f-EFUN_FIRST].Default; + $$ = instrs[f-EFUN_FIRST].ret_type; + argp = &efun_arg_types[instrs[f-EFUN_FIRST].arg_index]; + if (def && $3 == min-1) + { + ins_f_byte((unsigned)def); + max--; + min--; + } + else if ($3 < min) + { + char bff[100]; + + (void)snprintf(bff, sizeof(bff), "Too few arguments to %s", + instrs[f-EFUN_FIRST].name); + yyerror(bff); + } + else if ($3 > max && max != -1) + { + char bff[100]; + + (void)snprintf(bff, sizeof(bff), "Too many arguments to %s", + instrs[f - EFUN_FIRST].name); + yyerror(bff); + } + else if (max != -1 && exact_types) + { + /* + * Now check all types of the arguments to efuns. + */ + int i, argn; + char buff[100]; + for (argn=0; argn < $3; argn++) + { + int tmp = get_argument_type(argn, $3); + for(i=0; !TYPE(argp[i], tmp) && argp[i] != 0; i++) + ; + if (argp[i] == 0) + { + (void)snprintf(buff, sizeof(buff), + "Bad argument %d type to efun %s()", + argn+1, instrs[f-EFUN_FIRST].name); + yyerror(buff); + } + while(argp[i] != 0) + i++; + argp += i + 1; + } + } + ins_f_byte((unsigned)f); + + /* Only store number of arguments for instructions + * that allowed a variable number. + */ + if (max != min) + ins_byte((char)$3); /* Number of actual arguments */ + } + } + else + { + int i; + i = verify_declared($1); + if (i != -1 && (i & TYPE_MASK) == TYPE_FUNCTION) { + ins_f_byte(F_IDENTIFIER); + ins_byte((char)variable_inherit_found); + ins_byte((char)variable_index_found); + ins_f_byte(F_CALL_VAR); + ins_byte((char)$3); #if MUSTCASTFUN - $$ = TYPE_UNKNOWN; + $$ = TYPE_UNKNOWN; #else - $$ = TYPE_ANY; + $$ = TYPE_ANY; #endif - } else { - - if (exact_types) { - char buff[200]; - - (void)snprintf(buff, sizeof(buff), "Undefined function: %s", $1); - yyerror (buff); - } - - /* Function not found - */ - ins_f_byte(F_CALL_VIRT); - store_reloc_data(R_CALL, mem_block[A_PROGRAM].current_size, $1, 0, 0); - ins_byte((char)0xFF); - ins_short (-1); - ins_byte((char)$3); /* Number of arguments */ - $$ = TYPE_ANY; /* just a guess */ - } - } - pop_arg_stack($3); /* Argument types not needed more */ + } else { + + if (exact_types) { + char buff[200]; + + (void)snprintf(buff, sizeof(buff), "Undefined function: %s", $1); + yyerror (buff); + } + + /* Function not found + */ + ins_f_byte(F_CALL_VIRT); + store_reloc_data(R_CALL, mem_block[A_PROGRAM].current_size, $1, 0, 0); + ins_byte((char)0xFF); + ins_short (-1); + ins_byte((char)$3); /* Number of arguments */ + $$ = TYPE_ANY; /* just a guess */ + } } - }; + pop_arg_stack($3); /* Argument types not needed more */ + } + }; call_other_start: expr4 F_ARROW F_IDENTIFIER - { - ins_f_byte(F_STRING); - ins_short(store_prog_string($3)); - } ; + { + ins_f_byte(F_STRING); + ins_short(store_prog_string($3)); + } ; catch: F_CATCH { ins_f_byte(F_CATCH); push_address(); ins_address(0);} '(' comma_expr ')' - { - ins_f_byte(F_POP_VALUE); - ins_f_byte(F_END_CATCH); - upd_address(pop_address(), mem_block[A_PROGRAM].current_size); - }; + { + ins_f_byte(F_POP_VALUE); + ins_f_byte(F_END_CATCH); + upd_address(pop_address(), mem_block[A_PROGRAM].current_size); + }; sscanf: F_SSCANF '(' expr0 ',' expr0 lvalue_list ')' - { - ins_f_byte(F_SSCANF); ins_byte((char)($6 + 2)); - }; + { + ins_f_byte(F_SSCANF); ins_byte((char)($6 + 2)); + }; parse_command: F_PARSE_COMMAND '(' expr0 ',' expr0 ',' expr0 lvalue_list ')' - { - ins_f_byte(F_PARSE_COMMAND); ins_byte((char)($8 + 3)); - }; + { + ins_f_byte(F_PARSE_COMMAND); ins_byte((char)($8 + 3)); + }; lvalue_list: /* empty */ { $$ = 0; } - | ',' lvaluec lvalue_list { $$ = 1 + $3; } ; + | ',' lvaluec lvalue_list { $$ = 1 + $3; } ; lvaluec: lvalue { if (!($1 & TYPE_LVALUE)) yyerror("Illegal lvalue"); $$ = $1 & TYPE_LVALUE; deref_index--; }; identifier: identifier2 @@ -1960,78 +1960,78 @@ fun_identifier: F_IDENTIFIER | F_RSH { $$ = CTOR_FUNC;}; lvalue: identifier - { + { int var_num = lookup_local_name($1); if (var_num != -1) { - deref_stack[deref_index++] = mem_block[A_PROGRAM].current_size; - if (deref_index >= DEREFSIZE) - fatal("deref_index overflow\n"); - ins_f_byte(F_PUSH_LOCAL_VARIABLE_LVALUE); - ins_byte((char)var_num); + deref_stack[deref_index++] = mem_block[A_PROGRAM].current_size; + if (deref_index >= DEREFSIZE) + fatal("deref_index overflow\n"); + ins_f_byte(F_PUSH_LOCAL_VARIABLE_LVALUE); + ins_byte((char)var_num); $$ = type_of_locals[var_num] | TYPE_LVALUE; } else { - int i = verify_declared($1); - - if (i == -1) { - deref_stack[deref_index++] = -1; - if (deref_index >= DEREFSIZE) - fatal("deref_index overflow\n"); - if (handle_function_id($1)) { - $$ = TYPE_FUNCTION; - } else { - char buff[100]; - - (void)snprintf(buff, sizeof(buff), "Variable %s not declared!", $1); - yyerror(buff); - $$ = TYPE_ANY; - } - } else { - deref_stack[deref_index++] = mem_block[A_PROGRAM].current_size; - if (deref_index >= DEREFSIZE) - fatal("deref_index overflow\n"); - ins_f_byte(F_PUSH_IDENTIFIER_LVALUE); - ins_byte((char)variable_inherit_found); - ins_byte((char)variable_index_found); - $$ = (i & TYPE_MASK) | TYPE_LVALUE; - } + int i = verify_declared($1); + + if (i == -1) { + deref_stack[deref_index++] = -1; + if (deref_index >= DEREFSIZE) + fatal("deref_index overflow\n"); + if (handle_function_id($1)) { + $$ = TYPE_FUNCTION; + } else { + char buff[100]; + + (void)snprintf(buff, sizeof(buff), "Variable %s not declared!", $1); + yyerror(buff); + $$ = TYPE_ANY; + } + } else { + deref_stack[deref_index++] = mem_block[A_PROGRAM].current_size; + if (deref_index >= DEREFSIZE) + fatal("deref_index overflow\n"); + ins_f_byte(F_PUSH_IDENTIFIER_LVALUE); + ins_byte((char)variable_inherit_found); + ins_byte((char)variable_index_found); + $$ = (i & TYPE_MASK) | TYPE_LVALUE; + } } - } - | expr4 '[' comma_expr ']' - { - deref_stack[deref_index++] = mem_block[A_PROGRAM].current_size; - if (deref_index >= DEREFSIZE) - fatal("deref_index overflow\n"); - ins_f_byte(F_PUSH_INDEXED_LVALUE); - if (exact_types && !($1 & TYPE_MAPPING)) { - if (($1 & TYPE_MOD_POINTER) == 0 && !TYPE($1, TYPE_STRING)) - type_error("Bad type to indexed value", $1); - if (!TYPE($3, TYPE_NUMBER)) - type_error("Bad type of index", $3); - } - if ($1 == TYPE_ANY) - $$ = TYPE_ANY; - else if (TYPE($1, TYPE_STRING)) - $$ = TYPE_NUMBER; - else if ($1 == TYPE_MAPPING) - $$ = TYPE_ANY; - else - $$ = $1 & TYPE_MASK & ~TYPE_MOD_POINTER; - $$ |= TYPE_LVALUE; - }; + } + | expr4 '[' comma_expr ']' + { + deref_stack[deref_index++] = mem_block[A_PROGRAM].current_size; + if (deref_index >= DEREFSIZE) + fatal("deref_index overflow\n"); + ins_f_byte(F_PUSH_INDEXED_LVALUE); + if (exact_types && !($1 & TYPE_MAPPING)) { + if (($1 & TYPE_MOD_POINTER) == 0 && !TYPE($1, TYPE_STRING)) + type_error("Bad type to indexed value", $1); + if (!TYPE($3, TYPE_NUMBER)) + type_error("Bad type of index", $3); + } + if ($1 == TYPE_ANY) + $$ = TYPE_ANY; + else if (TYPE($1, TYPE_STRING)) + $$ = TYPE_NUMBER; + else if ($1 == TYPE_MAPPING) + $$ = TYPE_ANY; + else + $$ = $1 & TYPE_MASK & ~TYPE_MOD_POINTER; + $$ |= TYPE_LVALUE; + }; real: F_FLOATC - { - ins_f_byte(F_FLOATC); - ins_mem(&$1, sizeof($1)); - $$ = TYPE_FLOAT; - }; + { + ins_f_byte(F_FLOATC); + ins_mem(&$1, sizeof($1)); + $$ = TYPE_FLOAT; + }; string: F_STRING - { - ins_f_byte(F_STRING); - ins_short(store_prog_string($1)); - $$ = TYPE_STRING; - }; + { + ins_f_byte(F_STRING); + ins_short(store_prog_string($1)); + $$ = TYPE_STRING; + }; string_constant: string_con1 { @@ -2039,38 +2039,38 @@ string_constant: string_con1 }; string_con1: F_STRING - | string_con1 '+' F_STRING - { - $$ = tmpalloc( strlen($1) + strlen($3) + 1 ); - (void)strcpy($$, $1); - (void)strcat($$, $3); - } - | '(' string_con1 ')' - { - $$ = $2; - }; + | string_con1 '+' F_STRING + { + $$ = tmpalloc( strlen($1) + strlen($3) + 1 ); + (void)strcpy($$, $1); + (void)strcat($$, $3); + } + | '(' string_con1 ')' + { + $$ = $2; + }; cond: condStart statement - { - int i; - i = pop_address(); - ins_f_byte(F_JUMP); - add_jump(); - push_address(); - ins_address(0); - upd_address(i, mem_block[A_PROGRAM].current_size); - } + { + int i; + i = pop_address(); + ins_f_byte(F_JUMP); + add_jump(); + push_address(); + ins_address(0); + upd_address(i, mem_block[A_PROGRAM].current_size); + } optional_else_part - { upd_address(pop_address(), mem_block[A_PROGRAM].current_size); } ; + { upd_address(pop_address(), mem_block[A_PROGRAM].current_size); } ; condStart: F_IF '(' comma_expr ')' - { - ins_f_byte(F_JUMP_WHEN_ZERO); - add_jump(); - push_address(); - ins_address(0); - } ; + { + ins_f_byte(F_JUMP_WHEN_ZERO); + add_jump(); + push_address(); + ins_address(0); + } ; optional_else_part: /* empty */ | F_ELSE statement ; @@ -2082,11 +2082,11 @@ int link_errors; static void ins_f_byte(unsigned int b) { if (b - EFUN_FIRST < 256) - ins_byte((char)(b - EFUN_FIRST)); + ins_byte((char)(b - EFUN_FIRST)); else { - ins_byte((char)(F_EXT - EFUN_FIRST)); - ins_short((short)(b - EFUN_FIRST)); + ins_byte((char)(F_EXT - EFUN_FIRST)); + ins_short((short)(b - EFUN_FIRST)); } } @@ -2096,7 +2096,7 @@ yyerror(char *str) extern int num_parse_error; if (num_parse_error > 5) - return; + return; fprintf(stderr, "/%s: %s line %d\n", current_file, str, current_line); fflush(stderr); @@ -2123,60 +2123,60 @@ check_declared(char *str) if(!(real_name = (find_sstring((real_name == (char *)1) ? str : real_name)))) return -1; if (sub_name == (char *)2) - for (offset = 0; offset < mem_block[A_VARIABLES].current_size; - offset += sizeof (struct variable)) - { - vp = (struct variable *)&mem_block[A_VARIABLES].block[offset]; - /* Only index, prog, and type will be defined. */ - if (real_name == vp->name) - { - variable_type_mod_found = vp->type; - variable_index_found = offset / sizeof (struct variable); - variable_inherit_found = 255; - return variable_index_found; - } - } + for (offset = 0; offset < mem_block[A_VARIABLES].current_size; + offset += sizeof (struct variable)) + { + vp = (struct variable *)&mem_block[A_VARIABLES].block[offset]; + /* Only index, prog, and type will be defined. */ + if (real_name == vp->name) + { + variable_type_mod_found = vp->type; + variable_index_found = offset / sizeof (struct variable); + variable_inherit_found = 255; + return variable_index_found; + } + } else - if (sub_name - str > 2) - { - super_name = xalloc((size_t)(sub_name - str - 1)); - (void)memcpy(super_name, str, (size_t)(sub_name - str - 2)); - super_name[sub_name - str - 2] = 0; - if (strcmp(super_name, "this") == 0) - return check_declared(sub_name); - } - else - str = sub_name; + if (sub_name - str > 2) + { + super_name = xalloc((size_t)(sub_name - str - 1)); + (void)memcpy(super_name, str, (size_t)(sub_name - str - 2)); + super_name[sub_name - str - 2] = 0; + if (strcmp(super_name, "this") == 0) + return check_declared(sub_name); + } + else + str = sub_name; /* Look for the variable in the inherited programs - */ + */ for (inh = mem_block[A_INHERITS].current_size / sizeof (struct inherit) - 1; inh >= 0; inh -= ((struct inherit *)mem_block[A_INHERITS].block)[inh].prog-> - num_inherited) + num_inherited) { - if (super_name && - strcmp(super_name, ((struct inherit *)mem_block[A_INHERITS].block)[inh].name) == 0) - search = sub_name; - else - search = str; + if (super_name && + strcmp(super_name, ((struct inherit *)mem_block[A_INHERITS].block)[inh].name) == 0) + search = sub_name; + else + search = str; if (find_status (((struct inherit *)mem_block[A_INHERITS].block)[inh].prog, - search, TYPE_MOD_PRIVATE) != -1) - { - /* Adjust for inherit-type */ - int type = ((struct inherit *)mem_block[A_INHERITS].block)[inh].type; - - if (variable_type_mod_found & TYPE_MOD_PRIVATE) - type &= ~TYPE_MOD_PUBLIC; - if (variable_type_mod_found & TYPE_MOD_PUBLIC) - type &= ~TYPE_MOD_PRIVATE; + search, TYPE_MOD_PRIVATE) != -1) + { + /* Adjust for inherit-type */ + int type = ((struct inherit *)mem_block[A_INHERITS].block)[inh].type; + + if (variable_type_mod_found & TYPE_MOD_PRIVATE) + type &= ~TYPE_MOD_PUBLIC; + if (variable_type_mod_found & TYPE_MOD_PUBLIC) + type &= ~TYPE_MOD_PRIVATE; variable_type_mod_found |= type & TYPE_MOD_MASK; - variable_inherit_found += inh - - (((struct inherit *)mem_block[A_INHERITS].block)[inh].prog-> - num_inherited - 1); - return 1; - } + variable_inherit_found += inh - + (((struct inherit *)mem_block[A_INHERITS].block)[inh].prog-> + num_inherited - 1); + return 1; + } } return -1; } @@ -2187,40 +2187,40 @@ handle_function_id(char *str) short i; if (defined_function(str)) { - ins_f_byte(F_STRING); /* XXX */ - ins_short(store_prog_string(str)); /* XXX */ - ins_f_byte(F_BUILD_CLOSURE); /* and build the function closure */ - if (function_type_mod_found & (TYPE_MOD_NO_MASK|TYPE_MOD_PRIVATE)) { - if (function_prog_found && function_prog_found-> - functions[function_index_found].type_flags & TYPE_MOD_PRIVATE) - { - char buff[100]; - (void)snprintf(buff, sizeof(buff), "Function %s marked 'private'", - str); - yyerror (buff); - } - ins_byte(FUN_LFUN_NOMASK); - ins_byte((char)function_inherit_found); - ins_short((short)function_index_found); - } else { - ins_byte(FUN_LFUN); - ins_byte((char)function_inherit_found); - ins_short((short)function_index_found); - } - return 1; + ins_f_byte(F_STRING); /* XXX */ + ins_short(store_prog_string(str)); /* XXX */ + ins_f_byte(F_BUILD_CLOSURE); /* and build the function closure */ + if (function_type_mod_found & (TYPE_MOD_NO_MASK|TYPE_MOD_PRIVATE)) { + if (function_prog_found && function_prog_found-> + functions[function_index_found].type_flags & TYPE_MOD_PRIVATE) + { + char buff[100]; + (void)snprintf(buff, sizeof(buff), "Function %s marked 'private'", + str); + yyerror (buff); + } + ins_byte(FUN_LFUN_NOMASK); + ins_byte((char)function_inherit_found); + ins_short((short)function_index_found); + } else { + ins_byte(FUN_LFUN); + ins_byte((char)function_inherit_found); + ins_short((short)function_index_found); + } + return 1; } else if (is_simul_efun(str)) { - ins_f_byte(F_STRING); - ins_short(store_prog_string(str)); - ins_f_byte(F_BUILD_CLOSURE); /* and build the function closure */ - ins_byte(FUN_SFUN); - return 1; + ins_f_byte(F_STRING); + ins_short(store_prog_string(str)); + ins_f_byte(F_BUILD_CLOSURE); /* and build the function closure */ + ins_byte(FUN_SFUN); + return 1; } else if ((i = lookup_predef(str)) != -1) { - ins_f_byte(F_BUILD_CLOSURE); /* and build the function closure */ - ins_byte(FUN_EFUN); - ins_short(i); - return 1; + ins_f_byte(F_BUILD_CLOSURE); /* and build the function closure */ + ins_byte(FUN_EFUN); + ins_short(i); + return 1; } else { - return 0; + return 0; } } @@ -2232,14 +2232,14 @@ verify_declared(char *str) r = check_declared(str); if (r == -1) { - return -1; + return -1; } if (variable_inherit_found == 255) - return ((struct variable *)mem_block[A_VARIABLES].block)[variable_index_found]. - type; + return ((struct variable *)mem_block[A_VARIABLES].block)[variable_index_found]. + type; else - return ((struct inherit *)mem_block[A_INHERITS].block)[variable_inherit_found]. - prog->variable_names[variable_index_found].type; + return ((struct inherit *)mem_block[A_INHERITS].block)[variable_inherit_found]. + prog->variable_names[variable_index_found].type; } void @@ -2292,11 +2292,11 @@ add_local_name(char *str, int type) } if (current_number_of_locals == MAX_LOCAL) - yyerror("Too many local variables"); + yyerror("Too many local variables"); else { - type_of_locals[current_number_of_locals] = type; - local_blockdepth[current_number_of_locals] = block_depth; - local_names[current_number_of_locals++] = str; + type_of_locals[current_number_of_locals] = type; + local_blockdepth[current_number_of_locals] = block_depth; + local_names[current_number_of_locals++] = str; } if (current_number_of_locals > max_number_of_locals) max_number_of_locals = current_number_of_locals; @@ -2310,8 +2310,8 @@ find_inherit(struct program *prog1, struct program *prog2) int i; for (i = 0; i < (int)prog1->num_inherited; i++) - if (prog1->inherit[i].prog == prog2) - return i; + if (prog1->inherit[i].prog == prog2) + return i; return -1; } @@ -2325,55 +2325,55 @@ copy_inherits(struct program *from, int type, char *name) if (!has_inherited) { - free_sstring(((struct inherit *)mem_block[A_INHERITS].block)->name); - mem_block[A_INHERITS].current_size = 0; - has_inherited = 1; + free_sstring(((struct inherit *)mem_block[A_INHERITS].block)->name); + mem_block[A_INHERITS].current_size = 0; + has_inherited = 1; } for(i = 0; i < (int)from->num_variables; i++) - if ((type | from->variable_names[i].type) & TYPE_MOD_NO_MASK && - check_declared(from->variable_names[i].name) != -1 && - (variable_inherit_found == 255 || ((struct inherit *) - (mem_block[A_INHERITS].block))[variable_inherit_found].prog != from)) - { - (void)snprintf(buf, sizeof(buf), - "Redefinition of no_mask variable %s in program %s.\n", - from->variable_names[i].name, - from->name); + if ((type | from->variable_names[i].type) & TYPE_MOD_NO_MASK && + check_declared(from->variable_names[i].name) != -1 && + (variable_inherit_found == 255 || ((struct inherit *) + (mem_block[A_INHERITS].block))[variable_inherit_found].prog != from)) + { + (void)snprintf(buf, sizeof(buf), + "Redefinition of no_mask variable %s in program %s.\n", + from->variable_names[i].name, + from->name); yyerror(buf); - } + } for (i = 0; i < (int) from->num_functions; i++) - if ((type | from->functions[i].type_flags) & TYPE_MOD_NO_MASK && - defined_function(from->functions[i].name) && - function_prog_found != from) - { - (void)snprintf(buf, sizeof(buf), - "Redefinition of no_mask function %s in program %s.\n", - from->functions[i].name, - from->name); - yyerror(buf); - } + if ((type | from->functions[i].type_flags) & TYPE_MOD_NO_MASK && + defined_function(from->functions[i].name) && + function_prog_found != from) + { + (void)snprintf(buf, sizeof(buf), + "Redefinition of no_mask function %s in program %s.\n", + from->functions[i].name, + from->name); + yyerror(buf); + } for (i = from->num_inherited - 2; i >= 0; - i -= from->inherit[i].prog->num_inherited) - j[k++] = i; + i -= from->inherit[i].prog->num_inherited) + j[k++] = i; while (k) { - /* Correct the type */ - int new_type = type; - int old_type; + /* Correct the type */ + int new_type = type; + int old_type; - i = j[--k]; - old_type = from->inherit[i].type; + i = j[--k]; + old_type = from->inherit[i].type; - if (old_type & TYPE_MOD_PRIVATE) - new_type &= ~TYPE_MOD_PUBLIC; - if (old_type & TYPE_MOD_PUBLIC) - new_type &= ~TYPE_MOD_PRIVATE; + if (old_type & TYPE_MOD_PRIVATE) + new_type &= ~TYPE_MOD_PUBLIC; + if (old_type & TYPE_MOD_PUBLIC) + new_type &= ~TYPE_MOD_PRIVATE; - copy_inherits(from->inherit[i].prog, - old_type | new_type, - from->inherit[i].name); + copy_inherits(from->inherit[i].prog, + old_type | new_type, + from->inherit[i].name); } inh = from->inherit[from->num_inherited - 1]; /* Make a copy */ @@ -2397,20 +2397,20 @@ check_inherits(struct program *from) ob = find_object2(ob_name); if (!ob || ob->prog != from) - return 0; + return 0; for (i = from->num_inherited - 2; i >= 0; - i -= from->inherit[i].prog->num_inherited) - if (!check_inherits(from->inherit[i].prog)) - update = 1; + i -= from->inherit[i].prog->num_inherited) + if (!check_inherits(from->inherit[i].prog)) + update = 1; if (update) { - if (ob) { - ob->prog->flags &= ~PRAGMA_RESIDENT; - destruct_object(ob); - } - return 0; + if (ob) { + ob->prog->flags &= ~PRAGMA_RESIDENT; + destruct_object(ob); + } + return 0; } return 1; } @@ -2505,10 +2505,10 @@ store_line_number_info(int file, int line) unsigned int code = mem_block[A_PROGRAM].current_size; struct lineno *last_lineno = (struct lineno *)(mem_block[A_LINENUMBERS].block + - mem_block[A_LINENUMBERS].current_size) - 1; + mem_block[A_LINENUMBERS].current_size) - 1; if (mem_block[A_LINENUMBERS].current_size && - last_lineno->code == code) { + last_lineno->code == code) { last_lineno->file = file; last_lineno->lineno = line; return; @@ -2536,32 +2536,32 @@ get_type_name(int type) { static char buff[100]; static char *type_name[] = { "unknown", "int", "string", - "void", "object", "mixed", "mapping", - "float", "function" }; + "void", "object", "mixed", "mapping", + "float", "function" }; int pointer = 0; buff[0] = 0; if (type & TYPE_MOD_STATIC) - (void)strcat(buff, "static "); + (void)strcat(buff, "static "); if (type & TYPE_MOD_NO_MASK) - (void)strcat(buff, "nomask "); + (void)strcat(buff, "nomask "); if (type & TYPE_MOD_PRIVATE) - (void)strcat(buff, "private "); + (void)strcat(buff, "private "); if (type & TYPE_MOD_PUBLIC) - (void)strcat(buff, "public "); + (void)strcat(buff, "public "); if (type & TYPE_MOD_VARARGS) - (void)strcat(buff, "varargs "); + (void)strcat(buff, "varargs "); type &= TYPE_MASK; if (type & TYPE_MOD_POINTER) { - pointer = 1; - type &= ~TYPE_MOD_POINTER; + pointer = 1; + type &= ~TYPE_MOD_POINTER; } if (type >= sizeof type_name / sizeof type_name[0]) - fatal("Bad type\n"); + fatal("Bad type\n"); (void)strcat(buff, type_name[type]); (void)strcat(buff," "); if (pointer) - (void)strcat(buff, "* "); + (void)strcat(buff, "* "); return buff; } @@ -2573,15 +2573,15 @@ type_error(char *str, int type) p = get_type_name(type); if (strlen(str) + strlen(p) + 5 >= sizeof buff) { - yyerror(str); + yyerror(str); } else { - (void)strcpy(buff, str); - (void)strcat(buff, ": \""); - (void)strcat(buff, p); - (void)strcat(buff, "\""); - yyerror(buff); + (void)strcpy(buff, str); + (void)strcat(buff, ": \""); + (void)strcat(buff, p); + (void)strcat(buff, "\""); + yyerror(buff); } } @@ -2591,15 +2591,15 @@ remove_undefined_prototypes (int num_functions, struct function *functions) int i; for (i = 0; i < num_functions;i++) { - if (functions[i].type_flags & NAME_PROTOTYPE) - { - char buff[500]; - - (void)snprintf(buff, sizeof(buff), - "Function %s declared but never defined", - functions[i].name); - yyerror(buff); - } + if (functions[i].type_flags & NAME_PROTOTYPE) + { + char buff[500]; + + (void)snprintf(buff, sizeof(buff), + "Function %s declared but never defined", + functions[i].name); + yyerror(buff); + } } return num_functions; } @@ -2654,7 +2654,7 @@ remember_include(char *buf) int current_id_number = 1; #define H_OFFSET(arg) (((char *)&(((struct program *)0)->arg)) -\ - ((char *)((struct program *)0))) + ((char *)((struct program *)0))) static struct section_desc sec_hdr[] = { @@ -2706,37 +2706,37 @@ load_segments(struct segment_desc *seg, struct mem_block *mem_block1) for ( ; seg->sections != NULL; seg++) { - size = 0; - for (sect = seg->sections; sect->section != -1; sect++) { - size += align(mem_block1[sect->section].current_size); - } - - if (size) - block = xalloc((size_t)size); - else - block = xalloc(1); - - if (!hdr) - hdr = block; - - if (seg->ptr_offset != -1) - *(char **)(hdr + seg->ptr_offset) = block; - - for (sect = seg->sections; sect->section != -1; sect++) - { - size_t section_size = mem_block1[sect->section].current_size; - memcpy(block, mem_block1[sect->section].block, section_size); - - if (sect->ptr_offset != -1) - *(char **)(hdr + sect->ptr_offset) = block; - if (sect->num_offset != -1) - *(offset_t *)(hdr + sect->num_offset) = section_size / sect->ent_size; - - block += align(mem_block1[sect->section].current_size); - } - if (seg->size_offset != -1) { - *(offset_t *)(hdr + seg->size_offset) = size; - } + size = 0; + for (sect = seg->sections; sect->section != -1; sect++) { + size += align(mem_block1[sect->section].current_size); + } + + if (size) + block = xalloc((size_t)size); + else + block = xalloc(1); + + if (!hdr) + hdr = block; + + if (seg->ptr_offset != -1) + *(char **)(hdr + seg->ptr_offset) = block; + + for (sect = seg->sections; sect->section != -1; sect++) + { + size_t section_size = mem_block1[sect->section].current_size; + memcpy(block, mem_block1[sect->section].block, section_size); + + if (sect->ptr_offset != -1) + *(char **)(hdr + sect->ptr_offset) = block; + if (sect->num_offset != -1) + *(offset_t *)(hdr + sect->num_offset) = section_size / sect->ent_size; + + block += align(mem_block1[sect->section].current_size); + } + if (seg->size_offset != -1) { + *(offset_t *)(hdr + seg->size_offset) = size; + } } return hdr; } @@ -2754,29 +2754,29 @@ process_reloc(struct reloc *reloc, int num_relocs, int num_inherited) for (i = 0; i < num_relocs; i++, reloc++) { - if (reloc->address >= psize) - fatal("Corrupt relocation address.\n"); - - name = reloc->name; - switch (reloc->type) - { - int call_efun; - case R_CALL: - call_efun = 0; - if (!defined_function(name) || - ((function_type_mod_found & TYPE_MOD_PRIVATE) && - function_inherit_found != num_inherited)) - { - if (is_simul_efun(name)) - { - call_efun = F_CALL_SIMUL; - function_index_found = store_prog_string(name); - function_inherit_found = 0; - } - else - { - link_errors++; - (void)fprintf(stderr,"%s Function %s doesn't exist.\n", + if (reloc->address >= psize) + fatal("Corrupt relocation address.\n"); + + name = reloc->name; + switch (reloc->type) + { + int call_efun; + case R_CALL: + call_efun = 0; + if (!defined_function(name) || + ((function_type_mod_found & TYPE_MOD_PRIVATE) && + function_inherit_found != num_inherited)) + { + if (is_simul_efun(name)) + { + call_efun = F_CALL_SIMUL; + function_index_found = store_prog_string(name); + function_inherit_found = 0; + } + else + { + link_errors++; + (void)fprintf(stderr,"%s Function %s doesn't exist.\n", inner_get_srccode_position(reloc->address, (struct lineno *)mem_block[A_LINENUMBERS].block, mem_block[A_LINENUMBERS].current_size / @@ -2784,25 +2784,25 @@ process_reloc(struct reloc *reloc, int num_relocs, int num_inherited) mem_block[A_INCLUDES].block, current_file), name); - (void)fflush(stderr); - break; - } - } - else if (strchr(name,':') || function_type_mod_found & (TYPE_MOD_NO_MASK|TYPE_MOD_PRIVATE)) - call_efun = F_CALL_NON_VIRT; - else - call_efun = F_CALL_VIRT; - - fix = function_index_found; - mem_block[A_PROGRAM].block[reloc->address - 1] = call_efun - EFUN_FIRST; - mem_block[A_PROGRAM].block[reloc->address] = function_inherit_found; - mem_block[A_PROGRAM].block[reloc->address + 1] = ((char *)&fix)[0]; - mem_block[A_PROGRAM].block[reloc->address + 2] = ((char *)&fix)[1]; - break; - - default: - fatal("Unsupported reloc data.\n"); - } + (void)fflush(stderr); + break; + } + } + else if (strchr(name,':') || function_type_mod_found & (TYPE_MOD_NO_MASK|TYPE_MOD_PRIVATE)) + call_efun = F_CALL_NON_VIRT; + else + call_efun = F_CALL_VIRT; + + fix = function_index_found; + mem_block[A_PROGRAM].block[reloc->address - 1] = call_efun - EFUN_FIRST; + mem_block[A_PROGRAM].block[reloc->address] = function_inherit_found; + mem_block[A_PROGRAM].block[reloc->address + 1] = ((char *)&fix)[0]; + mem_block[A_PROGRAM].block[reloc->address + 2] = ((char *)&fix)[1]; + break; + + default: + fatal("Unsupported reloc data.\n"); + } } } @@ -2813,31 +2813,31 @@ link_C_functions(char *name) struct cfun_desc cfun; int num_inherited; num_inherited = - mem_block[A_INHERITS].current_size / - sizeof(struct inherit); + mem_block[A_INHERITS].current_size / + sizeof(struct inherit); for(i = 0; interface[i]; i++) - if (strcmp(interface[i]->program, name) == 0) - for(j = 0; interface[i]->vars[j]; j++) - { - if (check_declared(interface[i]->vars[j]->name) - == -1) - { - char buf[100]; - - (void)snprintf(buf, sizeof(buf), - "Variable %s (referenced from cfun) not defined.\n", - interface[i]->vars[j]->name); - current_line = -1; - yyerror(buf); - } - - if (variable_inherit_found == 255) - variable_inherit_found = num_inherited; - cfun.idx = variable_index_found; - cfun.inh = variable_inherit_found - num_inherited; - add_to_mem_block(A_CFUN, (char *)&cfun, sizeof(cfun)); - } + if (strcmp(interface[i]->program, name) == 0) + for(j = 0; interface[i]->vars[j]; j++) + { + if (check_declared(interface[i]->vars[j]->name) + == -1) + { + char buf[100]; + + (void)snprintf(buf, sizeof(buf), + "Variable %s (referenced from cfun) not defined.\n", + interface[i]->vars[j]->name); + current_line = -1; + yyerror(buf); + } + + if (variable_inherit_found == 255) + variable_inherit_found = num_inherited; + cfun.idx = variable_index_found; + cfun.inh = variable_inherit_found - num_inherited; + add_to_mem_block(A_CFUN, (char *)&cfun, sizeof(cfun)); + } } /* @@ -2865,58 +2865,58 @@ optimize_jumps(void) */ for (i = 0; i < jumps; i++) { - /* - * Read the target PC from the program section. - */ - offset2 = read_address(*ip); - - /* - * Short-circuit all unconditional jumps. - */ - for (;;) - { - /* - * Get the target PC of the jump. - */ - offset1 = offset2; - - /* - * Get the opcode. - */ - opcode = (unsigned char)read_byte(offset2++); - if (opcode == F_EXT - EFUN_FIRST) - { - opcode = read_short(offset2); - offset2 += 2; - } - - /* - * If the target is not an unconditional jump, then proceed to - * the next jump table entry. - */ - if (opcode != F_JUMP - EFUN_FIRST) - break; - - /* - * Get the target PC of the unconditional jump. - */ - offset2 = read_address(offset2); - - /* - * If the target PC of the jump is the same as the target PC of - * the unconditional jump, then the jump is self-referential and - * not interesting. - */ - if (offset2 == offset1) - break; - - /* - * Short-circuit the unconditional jump. - */ - upd_address(*ip, offset2); - } - - ip++; + /* + * Read the target PC from the program section. + */ + offset2 = read_address(*ip); + + /* + * Short-circuit all unconditional jumps. + */ + for (;;) + { + /* + * Get the target PC of the jump. + */ + offset1 = offset2; + + /* + * Get the opcode. + */ + opcode = (unsigned char)read_byte(offset2++); + if (opcode == F_EXT - EFUN_FIRST) + { + opcode = read_short(offset2); + offset2 += 2; + } + + /* + * If the target is not an unconditional jump, then proceed to + * the next jump table entry. + */ + if (opcode != F_JUMP - EFUN_FIRST) + break; + + /* + * Get the target PC of the unconditional jump. + */ + offset2 = read_address(offset2); + + /* + * If the target PC of the jump is the same as the target PC of + * the unconditional jump, then the jump is self-referential and + * not interesting. + */ + if (offset2 == offset1) + break; + + /* + * Short-circuit the unconditional jump. + */ + upd_address(*ip, offset2); + } + + ip++; } } @@ -2943,15 +2943,15 @@ epilog() #ifdef DEBUG if (num_parse_error == 0 && type_of_arguments.current_size != 0) - fatal("Failed to deallocate argument type stack\n"); + fatal("Failed to deallocate argument type stack\n"); #endif #ifdef DEALLOCATE_MEMORY_AT_SHUTDOWN if (type_of_arguments.block != NULL) { - type_of_arguments.max_size = 0; - type_of_arguments.current_size = 0; - free(type_of_arguments.block); - type_of_arguments.block = NULL; + type_of_arguments.max_size = 0; + type_of_arguments.current_size = 0; + free(type_of_arguments.block); + type_of_arguments.block = NULL; } #endif /* @@ -2963,27 +2963,27 @@ epilog() if (first_last_initializer_end != last_initializer_end) { - if (has_ctor != -1) - { - struct function *funp1; - - funp1 = &((struct function *)mem_block[A_FUNCTIONS].block)[has_ctor]; - upd_address(last_initializer_end, funp1->offset); - funp1->offset = 0; - } - else - { - has_ctor = mem_block[A_FUNCTIONS].current_size / - sizeof(struct function); - define_new_function(".CTOR", 0, 0, 0, - TYPE_MOD_PRIVATE | TYPE_VOID, 0); - /* - * Change the last jump after the last initializer into a - * return(1) statement. - */ - mem_block[A_PROGRAM].block[last_initializer_end -1] = F_CONST1 - EFUN_FIRST; - mem_block[A_PROGRAM].block[last_initializer_end] = F_RETURN - EFUN_FIRST; - } + if (has_ctor != -1) + { + struct function *funp1; + + funp1 = &((struct function *)mem_block[A_FUNCTIONS].block)[has_ctor]; + upd_address(last_initializer_end, funp1->offset); + funp1->offset = 0; + } + else + { + has_ctor = mem_block[A_FUNCTIONS].current_size / + sizeof(struct function); + define_new_function(".CTOR", 0, 0, 0, + TYPE_MOD_PRIVATE | TYPE_VOID, 0); + /* + * Change the last jump after the last initializer into a + * return(1) statement. + */ + mem_block[A_PROGRAM].block[last_initializer_end -1] = F_CONST1 - EFUN_FIRST; + mem_block[A_PROGRAM].block[last_initializer_end] = F_RETURN - EFUN_FIRST; + } } functions_left = remove_undefined_prototypes ( @@ -2996,23 +2996,23 @@ epilog() if (!(num_parse_error || inherit_file)) { - optimize_jumps(); + optimize_jumps(); - link_C_functions(current_file); + link_C_functions(current_file); - link_errors = 0; - process_reloc((struct reloc *)mem_block[A_RELOC].block, - (int)(mem_block[A_RELOC].current_size / sizeof(struct reloc)), - (int)(mem_block[A_INHERITS].current_size / sizeof(struct inherit))); - num_parse_error += link_errors; + link_errors = 0; + process_reloc((struct reloc *)mem_block[A_RELOC].block, + (int)(mem_block[A_RELOC].current_size / sizeof(struct reloc)), + (int)(mem_block[A_INHERITS].current_size / sizeof(struct inherit))); + num_parse_error += link_errors; } { - int c; + int c; - for (c = 0; - c < mem_block[A_RELOC].current_size / sizeof(struct reloc); - c++) - free(((struct reloc *)mem_block[A_RELOC].block)[c].name); + for (c = 0; + c < mem_block[A_RELOC].current_size / sizeof(struct reloc); + c++) + free(((struct reloc *)mem_block[A_RELOC].block)[c].name); } inherit_self.type = 0; @@ -3023,21 +3023,21 @@ epilog() add_to_mem_block(A_HEADER, (char *)&NULL_program, sizeof(NULL_program)); { - int num_func = - mem_block[A_FUNCTIONS].current_size / sizeof(struct function); - - mem_block[A_FUNC_HASH].current_size = num_func * - sizeof(struct function_hash); - if (num_func) - { - mem_block[A_FUNC_HASH].block = - realloc(mem_block[A_FUNC_HASH].block, num_func * - sizeof(struct function_hash)); - mem_block[A_FUNC_HASH].max_size = - mem_block[A_FUNC_HASH].current_size; - } - hash_func(num_func, (struct function *)mem_block[A_FUNCTIONS].block, - (struct function_hash *)mem_block[A_FUNC_HASH].block); + int num_func = + mem_block[A_FUNCTIONS].current_size / sizeof(struct function); + + mem_block[A_FUNC_HASH].current_size = num_func * + sizeof(struct function_hash); + if (num_func) + { + mem_block[A_FUNC_HASH].block = + realloc(mem_block[A_FUNC_HASH].block, num_func * + sizeof(struct function_hash)); + mem_block[A_FUNC_HASH].max_size = + mem_block[A_FUNC_HASH].current_size; + } + hash_func(num_func, (struct function *)mem_block[A_FUNCTIONS].block, + (struct function_hash *)mem_block[A_FUNC_HASH].block); } end_lineno_info(); @@ -3057,46 +3057,46 @@ epilog() #endif prog->swap_lineno_index = 0; prog->flags = (pragma_no_inherit ? PRAGMA_NO_INHERIT : 0) | - (pragma_no_clone ? PRAGMA_NO_CLONE : 0) | - (pragma_no_shadow ? PRAGMA_NO_SHADOW : 0) | + (pragma_no_clone ? PRAGMA_NO_CLONE : 0) | + (pragma_no_shadow ? PRAGMA_NO_SHADOW : 0) | (pragma_resident ? PRAGMA_RESIDENT : 0); prog->inherit[prog->num_inherited - 1].prog = prog; for (i = ix = 0; i < (int)prog->num_inherited; i++) { - int inh = find_inherit(prog, prog->inherit[i].prog); - if (inh == i) - { - prog->inherit[i].variable_index_offset = ix; - ix += prog->inherit[i].prog->num_variables; - prog->inherit[i].type &= ~TYPE_MOD_SECOND; - } - else - { - prog->inherit[i].variable_index_offset = - prog->inherit[inh].variable_index_offset; - prog->inherit[i].type |= TYPE_MOD_SECOND; - } + int inh = find_inherit(prog, prog->inherit[i].prog); + if (inh == i) + { + prog->inherit[i].variable_index_offset = ix; + ix += prog->inherit[i].prog->num_variables; + prog->inherit[i].type &= ~TYPE_MOD_SECOND; + } + else + { + prog->inherit[i].variable_index_offset = + prog->inherit[inh].variable_index_offset; + prog->inherit[i].type |= TYPE_MOD_SECOND; + } } /* don't forget the following: * prog->sizeof_argument_types = - * mem_block[A_ARGUMENT_TYPES??].current_size); + * mem_block[A_ARGUMENT_TYPES??].current_size); * if you have fixed it one day .... ok ? :-=) * remember to remove the above change to total_size !!!!!!!! */ prog->sizeof_argument_types=0; /* NOTE: Don't forget to hash the argument types along with the functions */ - prog->argument_types = 0; /* For now. Will be fixed someday */ + prog->argument_types = 0; /* For now. Will be fixed someday */ prog->type_start = 0; for (i = 0; i < (int)prog->num_inherited - 1; i++) { - reference_prog (prog->inherit[i].prog, "inheritance"); + reference_prog (prog->inherit[i].prog, "inheritance"); } prog->load_time = current_time; @@ -3104,9 +3104,9 @@ epilog() register_program(prog); /* marion - Do referencing here - avoid multiple referencing when an object - inherits more than one object and one of the inherited is already - loaded and not the last inherited + Do referencing here - avoid multiple referencing when an object + inherits more than one object and one of the inherited is already + loaded and not the last inherited */ total_program_size += prog->exec_size; total_prog_block_size += prog->total_size; @@ -3133,25 +3133,25 @@ prolog() char auto_include[] = AUTO_INCLUDE; #endif if (type_of_arguments.block == 0) { - type_of_arguments.max_size = 100; - type_of_arguments.block = xalloc((size_t)type_of_arguments.max_size); + type_of_arguments.max_size = 100; + type_of_arguments.block = xalloc((size_t)type_of_arguments.max_size); } type_of_arguments.current_size = 0; - prog = 0; /* 0 means fail to load. */ - comp_stackp = 0; /* Local temp stack used by compiler */ + prog = 0; /* 0 means fail to load. */ + comp_stackp = 0; /* Local temp stack used by compiler */ current_continue_address = 0; current_break_address = 0; current_case_address = 0; num_parse_error = 0; try_level = break_try_level = continue_try_level = 0; - free_all_local_names(); /* In case of earlier error */ + free_all_local_names(); /* In case of earlier error */ /* Initialize memory blocks where the result of the compilation * will be stored. */ for (i=0; i < NUMAREAS; i++) { - mem_block[i].block = xalloc(START_BLOCK_SIZE); - mem_block[i].current_size = 0; - mem_block[i].max_size = START_BLOCK_SIZE; + mem_block[i].block = xalloc(START_BLOCK_SIZE); + mem_block[i].current_size = 0; + mem_block[i].max_size = START_BLOCK_SIZE; } init_lineno_info(); add_new_init_jump(); @@ -3159,8 +3159,8 @@ prolog() has_inherited = 1; if (auto_ob && strcmp(current_file, auto_ob->prog->name)) { - copy_inherits(auto_ob->prog, 0, "auto"); - has_inherited = 0; + copy_inherits(auto_ob->prog, 0, "auto"); + has_inherited = 0; } #ifdef AUTO_INCLUDE current_line = 0; @@ -3193,44 +3193,44 @@ search_for_ext_function(char *name, struct program *prog1) ix = strchr(name, ':'); if (ix == NULL) { - /* its a simple name so search for it the normal way */ - return search_for_function(name, prog1); + /* its a simple name so search for it the normal way */ + return search_for_function(name, prog1); } if (ix - name == 4 && strncmp(name, "this", 4) == 0) - return search_for_ext_function(ix + 2, prog1); + return search_for_ext_function(ix + 2, prog1); for (i = prog1->num_inherited - 2; i >= 0; i--) { - if (ix == name || (strlen(prog1->inherit[i].name) == ix - name && - strncmp(prog1->inherit[i].name, name, (size_t)(ix - name)) == 0)) - { - res = search_for_ext_function(ix + 2, prog1->inherit[i].prog); - if (res) - { - int type_mod; - - /* adjust values and return */ - function_inherit_found += i - - (prog1->inherit[i].prog->num_inherited - 1); - type_mod = prog1->inherit[function_inherit_found].type; - - /* Correct function_type_mod_found */ - if (function_type_mod_found & TYPE_MOD_PRIVATE) - type_mod &= ~TYPE_MOD_PUBLIC; - if (function_type_mod_found & TYPE_MOD_PUBLIC) - type_mod &= ~TYPE_MOD_PRIVATE; - function_type_mod_found |= type_mod; - - return res; - } - else - { - /* skip program and continue */ - i -= prog1->inherit[i].prog->num_inherited - 1; - } - - } + if (ix == name || (strlen(prog1->inherit[i].name) == ix - name && + strncmp(prog1->inherit[i].name, name, (size_t)(ix - name)) == 0)) + { + res = search_for_ext_function(ix + 2, prog1->inherit[i].prog); + if (res) + { + int type_mod; + + /* adjust values and return */ + function_inherit_found += i - + (prog1->inherit[i].prog->num_inherited - 1); + type_mod = prog1->inherit[function_inherit_found].type; + + /* Correct function_type_mod_found */ + if (function_type_mod_found & TYPE_MOD_PRIVATE) + type_mod &= ~TYPE_MOD_PUBLIC; + if (function_type_mod_found & TYPE_MOD_PUBLIC) + type_mod &= ~TYPE_MOD_PRIVATE; + function_type_mod_found |= type_mod; + + return res; + } + else + { + /* skip program and continue */ + i -= prog1->inherit[i].prog->num_inherited - 1; + } + + } } return 0; diff --git a/prelang.y b/prelang.y index 7dc2f0a..98f764d 100644 --- a/prelang.y +++ b/prelang.y @@ -40,10 +40,10 @@ #endif #define malloc xalloc -#define YYMAXDEPTH 600 +#define YYMAXDEPTH 600 -#define BREAK_ON_STACK 0x40000 -#define BREAK_FROM_CASE 0x80000 +#define BREAK_ON_STACK 0x40000 +#define BREAK_FROM_CASE 0x80000 /* make shure that this struct has a size that is a power of two */ struct case_heap_entry { long long key; offset_t addr; short line; }; @@ -58,13 +58,13 @@ static int has_inherited; */ #define BASIC_TYPE(e,t) ((e) == TYPE_ANY ||\ - (e) == (t) ||\ - (t) == TYPE_ANY) + (e) == (t) ||\ + (t) == TYPE_ANY) #define TYPE(e,t) (BASIC_TYPE((e) & TYPE_MASK, (t) & TYPE_MASK) ||\ - (((e) & TYPE_MOD_POINTER) && ((t) & TYPE_MOD_POINTER) &&\ - BASIC_TYPE((e) & (TYPE_MASK & ~TYPE_MOD_POINTER),\ - (t) & (TYPE_MASK & ~TYPE_MOD_POINTER)))) + (((e) & TYPE_MOD_POINTER) && ((t) & TYPE_MOD_POINTER) &&\ + BASIC_TYPE((e) & (TYPE_MASK & ~TYPE_MOD_POINTER),\ + (t) & (TYPE_MASK & ~TYPE_MOD_POINTER)))) #define FUNCTION(n) ((struct function *)mem_block[A_FUNCTIONS].block + (n)) #define VARIABLE(n) ((struct variable *)mem_block[A_VARIABLES].block + (n)) @@ -77,8 +77,8 @@ static int has_inherited; * checked and required. */ static int exact_types; -extern int pragma_strict_types; /* Maintained by lex.c */ -extern int pragma_save_binary; /* Save this in the binary shadow dir */ +extern int pragma_strict_types; /* Maintained by lex.c */ +extern int pragma_save_binary; /* Save this in the binary shadow dir */ extern int pragma_no_inherit; extern int pragma_no_shadow; extern int pragma_no_clone; @@ -181,7 +181,7 @@ static int max_number_of_locals = 0; */ struct mem_block type_of_arguments; -struct program *prog; /* Is returned to the caller of yyparse */ +struct program *prog; /* Is returned to the caller of yyparse */ /* * Compare two types, and return true if they are compatible. @@ -190,18 +190,18 @@ static int compatible_types(int t1, int t2) { if (t1 == TYPE_UNKNOWN || t2 == TYPE_UNKNOWN) - return 0; + return 0; if (t1 == t2) - return 1; + return 1; if ((t1|TYPE_MOD_NO_MASK|TYPE_MOD_STATIC|TYPE_MOD_PRIVATE|TYPE_MOD_PUBLIC) - == (t2|TYPE_MOD_NO_MASK|TYPE_MOD_STATIC|TYPE_MOD_PRIVATE|TYPE_MOD_PUBLIC)) - return 1; + == (t2|TYPE_MOD_NO_MASK|TYPE_MOD_STATIC|TYPE_MOD_PRIVATE|TYPE_MOD_PUBLIC)) + return 1; if (t1 == TYPE_ANY || t2 == TYPE_ANY) - return 1; + return 1; if ((t1 & TYPE_MOD_POINTER) && (t2 & TYPE_MOD_POINTER)) { - if ((t1 & TYPE_MASK) == (TYPE_ANY|TYPE_MOD_POINTER) || - (t2 & TYPE_MASK) == (TYPE_ANY|TYPE_MOD_POINTER)) - return 1; + if ((t1 & TYPE_MASK) == (TYPE_ANY|TYPE_MOD_POINTER) || + (t2 & TYPE_MASK) == (TYPE_ANY|TYPE_MOD_POINTER)) + return 1; } if (t1 == TYPE_MAPPING) return 1; @@ -217,8 +217,8 @@ add_arg_type(unsigned short type) { struct mem_block *mbp = &type_of_arguments; while (mbp->current_size + sizeof type > mbp->max_size) { - mbp->max_size <<= 1; - mbp->block = realloc(mbp->block, (size_t)mbp->max_size); + mbp->max_size <<= 1; + mbp->block = realloc(mbp->block, (size_t)mbp->max_size); } (void)memcpy(mbp->block + mbp->current_size, &type, sizeof type); mbp->current_size += sizeof type; @@ -240,7 +240,7 @@ static unsigned short* get_argument_ptr(int n) { return &((unsigned short *) - (type_of_arguments.block + type_of_arguments.current_size))[-n]; + (type_of_arguments.block + type_of_arguments.current_size))[-n]; } /* * Get type of argument number 'arg', where there are @@ -378,62 +378,62 @@ defined_function(char *s) return 0; } if (sub_name == (char *)2) - for (offset = 0; offset < mem_block[A_FUNCTIONS].current_size; - offset += sizeof (struct function)) - { - funp = (struct function *)&mem_block[A_FUNCTIONS].block[offset]; - /* Only index, prog, and type will be defined. */ - if (real_name == funp->name) - { - function_index_found = offset / sizeof (struct function); - function_prog_found = 0; - function_type_mod_found = funp->type_flags & TYPE_MOD_MASK; - function_inherit_found = mem_block[A_INHERITS].current_size / sizeof(struct inherit); - return 1; - } - } + for (offset = 0; offset < mem_block[A_FUNCTIONS].current_size; + offset += sizeof (struct function)) + { + funp = (struct function *)&mem_block[A_FUNCTIONS].block[offset]; + /* Only index, prog, and type will be defined. */ + if (real_name == funp->name) + { + function_index_found = offset / sizeof (struct function); + function_prog_found = 0; + function_type_mod_found = funp->type_flags & TYPE_MOD_MASK; + function_inherit_found = mem_block[A_INHERITS].current_size / sizeof(struct inherit); + return 1; + } + } else - if (sub_name - s > 2) - { - super_name = alloca((size_t)(sub_name - s - 1)); - (void)memcpy(super_name, s, (size_t)(sub_name - s - 2)); - super_name[sub_name - s - 2] = 0; - if (strcmp(super_name, "this") == 0) - return defined_function(sub_name); - } - else - s = sub_name; + if (sub_name - s > 2) + { + super_name = alloca((size_t)(sub_name - s - 1)); + (void)memcpy(super_name, s, (size_t)(sub_name - s - 2)); + super_name[sub_name - s - 2] = 0; + if (strcmp(super_name, "this") == 0) + return defined_function(sub_name); + } + else + s = sub_name; /* Look for the function in the inherited programs - */ + */ for (inh = mem_block[A_INHERITS].current_size / sizeof (struct inherit) - 1; inh >= 0; inh -= ((struct inherit *)(mem_block[A_INHERITS].block))[inh].prog-> - num_inherited) + num_inherited) { - if (super_name && - strcmp(super_name, ((struct inherit *)(mem_block[A_INHERITS].block))[inh].name) == 0) - search = sub_name; - else - search = s; + if (super_name && + strcmp(super_name, ((struct inherit *)(mem_block[A_INHERITS].block))[inh].name) == 0) + search = sub_name; + else + search = s; if (search_for_ext_function (search, - ((struct inherit *)(mem_block[A_INHERITS].block))[inh].prog)) - { - /* Adjust for inherit-type */ - int type = ((struct inherit *)mem_block[A_INHERITS].block)[inh].type; - - if (function_type_mod_found & TYPE_MOD_PRIVATE) - type &= ~TYPE_MOD_PUBLIC; - if (function_type_mod_found & TYPE_MOD_PUBLIC) - type &= ~TYPE_MOD_PRIVATE; + ((struct inherit *)(mem_block[A_INHERITS].block))[inh].prog)) + { + /* Adjust for inherit-type */ + int type = ((struct inherit *)mem_block[A_INHERITS].block)[inh].type; + + if (function_type_mod_found & TYPE_MOD_PRIVATE) + type &= ~TYPE_MOD_PUBLIC; + if (function_type_mod_found & TYPE_MOD_PUBLIC) + type &= ~TYPE_MOD_PRIVATE; function_type_mod_found |= type & TYPE_MOD_MASK; - function_inherit_found += inh - - (((struct inherit *)(mem_block[A_INHERITS].block))[inh].prog-> - num_inherited - 1); + function_inherit_found += inh - + (((struct inherit *)(mem_block[A_INHERITS].block))[inh].prog-> + num_inherited - 1); - return 1; - } + return 1; + } } return 0; } @@ -449,9 +449,9 @@ static INLINE void push_address() { if (comp_stackp >= COMPILER_STACK_SIZE) { - yyerror("Compiler stack overflow"); - comp_stackp++; - return; + yyerror("Compiler stack overflow"); + comp_stackp++; + return; } comp_stack[comp_stackp++] = mem_block[A_PROGRAM].current_size; } @@ -466,9 +466,9 @@ static INLINE void push_explicit(offset_t address) { if (comp_stackp >= COMPILER_STACK_SIZE) { - yyerror("Compiler stack overflow"); - comp_stackp++; - return; + yyerror("Compiler stack overflow"); + comp_stackp++; + return; } comp_stack[comp_stackp++] = address; } @@ -477,10 +477,10 @@ static INLINE offset_t pop_address() { if (comp_stackp == 0) - fatal("Compiler stack underflow.\n"); + fatal("Compiler stack underflow.\n"); if (comp_stackp > COMPILER_STACK_SIZE) { - --comp_stackp; - return 0; + --comp_stackp; + return 0; } offset_t ret = comp_stack[--comp_stackp]; return ret; @@ -508,86 +508,86 @@ define_new_function(char *name, char num_arg, unsigned char num_local, offset_t * If it was defined in the current program, use that definition. */ /* Point to the function definition found - */ + */ if (function_prog_found) - { - funp = &function_prog_found->functions[function_index_found]; - } - else - funp = FUNCTION(function_index_found); - - /* If it was declared in the current program, and not a prototype, - * it is a double definition. - */ - if (!(funp->type_flags & NAME_PROTOTYPE) && - !function_prog_found) - { - char buff[500]; - - (void)snprintf(buff, sizeof(buff), "Redeclaration of function %s", name); - yyerror (buff); - return; - } - - /* If neither the new nor the old definition is a prototype, - * it must be a redefinition of an inherited function. - * Check for nomask. - */ - if ((funp->type_flags & TYPE_MOD_NO_MASK) && - !(funp->type_flags & NAME_PROTOTYPE)) - { - char buff[500]; - - (void)snprintf(buff, sizeof(buff), "Illegal to redefine nomask function %s", name); - yyerror (buff); - return; - } - - /* Check types - */ - if (exact_types && - ((funp->type_flags & TYPE_MASK) != TYPE_UNKNOWN)) - { - if (funp->num_arg != num_arg && - !(funp->type_flags & TYPE_MOD_VARARGS)) - { - yyerror("Incorrect number of arguments"); - return; - } + { + funp = &function_prog_found->functions[function_index_found]; + } + else + funp = FUNCTION(function_index_found); + + /* If it was declared in the current program, and not a prototype, + * it is a double definition. + */ + if (!(funp->type_flags & NAME_PROTOTYPE) && + !function_prog_found) + { + char buff[500]; + + (void)snprintf(buff, sizeof(buff), "Redeclaration of function %s", name); + yyerror (buff); + return; + } + + /* If neither the new nor the old definition is a prototype, + * it must be a redefinition of an inherited function. + * Check for nomask. + */ + if ((funp->type_flags & TYPE_MOD_NO_MASK) && + !(funp->type_flags & NAME_PROTOTYPE)) + { + char buff[500]; + + (void)snprintf(buff, sizeof(buff), "Illegal to redefine nomask function %s", name); + yyerror (buff); + return; + } + + /* Check types + */ + if (exact_types && + ((funp->type_flags & TYPE_MASK) != TYPE_UNKNOWN)) + { + if (funp->num_arg != num_arg && + !(funp->type_flags & TYPE_MOD_VARARGS)) + { + yyerror("Incorrect number of arguments"); + return; + } /* * This is just a nuisance! /JnA - else if (!(funp->type_flags & NAME_STRICT_TYPES)) - { - yyerror("Function called not compiled with type testing"); - return; - } + else if (!(funp->type_flags & NAME_STRICT_TYPES)) + { + yyerror("Function called not compiled with type testing"); + return; + } */ #if 0 else - { - int i; - /* Now check argument types - */ - for (i=0; i < num_arg; i++) - { - } - } + { + int i; + /* Now check argument types + */ + for (i=0; i < num_arg; i++) + { + } + } #endif - } - /* If it is a prototype for a function that has already been defined, - * we don't need it. - */ - if ((type_flags & NAME_PROTOTYPE) && !function_prog_found) - return; - - /* If the function was defined in an inherited program, we need to - * make a new definition here. - */ - if (function_prog_found) { - funp = &fun; - } + } + /* If it is a prototype for a function that has already been defined, + * we don't need it. + */ + if ((type_flags & NAME_PROTOTYPE) && !function_prog_found) + return; + + /* If the function was defined in an inherited program, we need to + * make a new definition here. + */ + if (function_prog_found) { + funp = &fun; + } } else { /* Function was not defined before, we need a new definition */ funp = &fun; @@ -612,33 +612,33 @@ define_new_function(char *name, char num_arg, unsigned char num_local, offset_t funp->type_flags |= NAME_STRICT_TYPES; if (!exact_types || num_arg == 0) { - argument_start_index = INDEX_START_NONE; + argument_start_index = INDEX_START_NONE; } else { - int i; - /* - * Save the start of argument types. - */ - argument_start_index = - mem_block[A_ARGUMENT_TYPES].current_size / - sizeof (unsigned short); - for (i=0; i < num_arg; i++) - add_to_mem_block(A_ARGUMENT_TYPES, (char *)&type_of_locals[i], - sizeof type_of_locals[i]); + int i; + /* + * Save the start of argument types. + */ + argument_start_index = + mem_block[A_ARGUMENT_TYPES].current_size / + sizeof (unsigned short); + for (i=0; i < num_arg; i++) + add_to_mem_block(A_ARGUMENT_TYPES, (char *)&type_of_locals[i], + sizeof type_of_locals[i]); } if (funp == &fun) { - funp->name = make_sstring(name); + funp->name = make_sstring(name); add_to_mem_block (A_FUNCTIONS, (char *)&fun, sizeof fun); - add_to_mem_block(A_ARGUMENT_INDEX, (char *)&argument_start_index, + add_to_mem_block(A_ARGUMENT_INDEX, (char *)&argument_start_index, sizeof argument_start_index); } else { - (void)memcpy(&mem_block[A_ARGUMENT_INDEX]. - block[function_index_found * sizeof(argument_start_index)], - (char *)&argument_start_index, sizeof(argument_start_index)); + (void)memcpy(&mem_block[A_ARGUMENT_INDEX]. + block[function_index_found * sizeof(argument_start_index)], + (char *)&argument_start_index, sizeof(argument_start_index)); } return; } @@ -648,7 +648,7 @@ is_simul_efun (char *name) { if (simul_efun_ob != 0 && search_for_function (name, simul_efun_ob->prog) && - !(function_type_mod_found & (TYPE_MOD_PRIVATE | TYPE_MOD_STATIC))) + !(function_type_mod_found & (TYPE_MOD_PRIVATE | TYPE_MOD_STATIC))) return 1; return 0; } @@ -662,9 +662,9 @@ define_variable(char *name, int type) n = check_declared(name); if (n != -1 && (n & TYPE_MOD_NO_MASK)) { - char *p = (char *)alloca(80 + strlen(name)); - (void)sprintf(p, "Illegal to redefine 'nomask' variable \"%s\"", name); - yyerror(p); + char *p = (char *)alloca(80 + strlen(name)); + (void)sprintf(p, "Illegal to redefine 'nomask' variable \"%s\"", name); + yyerror(p); } dummy.name = make_sstring(name); @@ -682,18 +682,18 @@ store_prog_string(char *str) for (i = mem_block[A_STRTAB].current_size - sizeof(short); i >= 0; i -= sizeof(short)) { - char *str2; - unsigned short offset; - ((char *)&offset)[0] = mem_block[A_STRTAB].block[i]; - ((char *)&offset)[1] = mem_block[A_STRTAB].block[i + 1]; - str2 = mem_block[A_RODATA].block + offset; - if (strcmp(str, str2) == 0) - return offset; + char *str2; + unsigned short offset; + ((char *)&offset)[0] = mem_block[A_STRTAB].block[i]; + ((char *)&offset)[1] = mem_block[A_STRTAB].block[i + 1]; + str2 = mem_block[A_RODATA].block + offset; + if (strcmp(str, str2) == 0) + return offset; } if (mem_block[A_RODATA].current_size >= 0x10000) { - yyerror("Too large rodata segment!\n"); - mem_block[A_RODATA].current_size = 0; + yyerror("Too large rodata segment!\n"); + mem_block[A_RODATA].current_size = 0; } addr = mem_block[A_RODATA].current_size; @@ -729,11 +729,11 @@ ins_label(offset_t lbl) offset_t here = mem_block[A_PROGRAM].current_size; l = &((struct label *)mem_block[A_LABELS].block)[lbl]; if (l->address != EMPTY_LABEL) - ins_address(l->address); + ins_address(l->address); else { - ins_address(l->link); - l->link = here; + ins_address(l->link); + l->link = here; } } @@ -748,8 +748,8 @@ set_label(offset_t lbl, offset_t addr) for (link1 = l->link; link1 != EMPTY_LABEL; link1 = next) { - next = read_address(link1); - upd_address(link1, addr); + next = read_address(link1); + upd_address(link1, addr); } l->link = EMPTY_LABEL; @@ -757,13 +757,13 @@ set_label(offset_t lbl, offset_t addr) static INLINE long long cmp_case_keys(struct case_heap_entry *entry1, - struct case_heap_entry *entry2, int is_str) + struct case_heap_entry *entry2, int is_str) { if (is_str) - return strcmp(mem_block[A_RODATA].block + (unsigned short)entry1->key, - mem_block[A_RODATA].block + (unsigned short)entry2->key); + return strcmp(mem_block[A_RODATA].block + (unsigned short)entry1->key, + mem_block[A_RODATA].block + (unsigned short)entry2->key); else - return entry1->key - entry2->key; + return entry1->key - entry2->key; } void @@ -781,67 +781,67 @@ add_to_case_heap(int block_index, struct case_heap_entry *entry, struct case_hea } else { - current_heap = current_case_string_heap; + current_heap = current_case_string_heap; is_str = 1; } if (entry2 && cmp_case_keys(entry, entry2, is_str) > 0) - return; + return; heap_top = (struct case_heap_entry *)(mem_block[block_index].block + mem_block[block_index].current_size); heap_entry = (struct case_heap_entry *)(mem_block[block_index].block + current_heap); for (; heap_entry < heap_top; heap_entry++) { - if (cmp_case_keys(heap_entry, entry, is_str) > 0) - break; + if (cmp_case_keys(heap_entry, entry, is_str) > 0) + break; - if (heap_entry->addr == OFFSET_MAX) - { + if (heap_entry->addr == OFFSET_MAX) + { /* Range entry, compare next also */ - if (cmp_case_keys(++heap_entry, entry, is_str) >= 0) - { - /* Duplicate case label! */ - char buff[100]; - - (void)sprintf(buff, "Duplicate case label (line %d)", - heap_entry->line); - yyerror(buff); - break; - } - } + if (cmp_case_keys(++heap_entry, entry, is_str) >= 0) + { + /* Duplicate case label! */ + char buff[100]; + + (void)sprintf(buff, "Duplicate case label (line %d)", + heap_entry->line); + yyerror(buff); + break; + } + } } if (heap_entry < heap_top && - (!cmp_case_keys(heap_entry, entry, is_str) || - (entry2 && (cmp_case_keys(entry2, heap_entry, is_str) >= 0)))) + (!cmp_case_keys(heap_entry, entry, is_str) || + (entry2 && (cmp_case_keys(entry2, heap_entry, is_str) >= 0)))) { - /* Duplicate case label! */ - char buff[100]; + /* Duplicate case label! */ + char buff[100]; - (void)sprintf(buff, "Duplicate case label (line %d)", - heap_entry->line); - yyerror(buff); + (void)sprintf(buff, "Duplicate case label (line %d)", + heap_entry->line); + yyerror(buff); } to = ((char *)(heap_entry + 1 + (entry2 != NULL))) - - mem_block[block_index].block; + mem_block[block_index].block; from = ((char *)heap_entry) - mem_block[block_index].block; size = (heap_top - heap_entry) * sizeof(*entry); add_to_mem_block(block_index, (char *)entry, sizeof(*entry)); if (entry2) - add_to_mem_block(block_index, (char *)entry2, sizeof(*entry2)); + add_to_mem_block(block_index, (char *)entry2, sizeof(*entry2)); if (heap_entry != heap_top) { - (void)memmove(mem_block[block_index].block + to, - mem_block[block_index].block + from, (size_t)size); - (void)memcpy(mem_block[block_index].block + from, entry, sizeof(*entry)); - if (entry2) - (void)memcpy(mem_block[block_index].block + from + sizeof(*entry), - entry2, sizeof(*entry)); + (void)memmove(mem_block[block_index].block + to, + mem_block[block_index].block + from, (size_t)size); + (void)memcpy(mem_block[block_index].block + from, entry, sizeof(*entry)); + if (entry2) + (void)memcpy(mem_block[block_index].block + from + sizeof(*entry), + entry2, sizeof(*entry)); } } @@ -853,7 +853,7 @@ static void transfer_init_control() { if (mem_block[A_PROGRAM].current_size - 2 == last_initializer_end) { - mem_block[A_PROGRAM].current_size -= 3; + mem_block[A_PROGRAM].current_size -= 3; } else { @@ -861,7 +861,7 @@ transfer_init_control() * Change the address of the last jump after the last * initializer to this point. */ - upd_address(last_initializer_end, mem_block[A_PROGRAM].current_size); + upd_address(last_initializer_end, mem_block[A_PROGRAM].current_size); } } diff --git a/regexp.c b/regexp.c index e558902..8b07ab7 100644 --- a/regexp.c +++ b/regexp.c @@ -4,45 +4,45 @@ * * DESCRIPTION * - * Underneath the reformatting and comment blocks which were added to - * make it consistent with the rest of the code, you will find a - * modified version of Henry Specer's regular expression library. - * Henry's functions were modified to provide the minimal regular - * expression matching, as required by P1003. Henry's code was - * copyrighted, and copy of the copyright message and restrictions - * are provided, verbatim, below: + * Underneath the reformatting and comment blocks which were added to + * make it consistent with the rest of the code, you will find a + * modified version of Henry Specer's regular expression library. + * Henry's functions were modified to provide the minimal regular + * expression matching, as required by P1003. Henry's code was + * copyrighted, and copy of the copyright message and restrictions + * are provided, verbatim, below: * - * Copyright (c) 1986 by University of Toronto. - * Written by Henry Spencer. Not derived from licensed software. + * Copyright (c) 1986 by University of Toronto. + * Written by Henry Spencer. Not derived from licensed software. * - * Permission is granted to anyone to use this software for any - * purpose on any computer system, and to redistribute it freely, - * subject to the following restrictions: + * Permission is granted to anyone to use this software for any + * purpose on any computer system, and to redistribute it freely, + * subject to the following restrictions: * - * 1. The author is not responsible for the consequences of use of + * 1. The author is not responsible for the consequences of use of * this software, no matter how awful, even if they arise - * from defects in it. + * from defects in it. * - * 2. The origin of this software must not be misrepresented, either - * by explicit claim or by omission. + * 2. The origin of this software must not be misrepresented, either + * by explicit claim or by omission. * - * 3. Altered versions must be plainly marked as such, and must not - * be misrepresented as being the original software. + * 3. Altered versions must be plainly marked as such, and must not + * be misrepresented as being the original software. * * * This version modified by Ian Phillipps to return pointer to terminating * NUL on substitution string. [ Temp mail address ex-igp@camcon.co.uk ] * - * Altered by amylaar to support excompatible option and the + * Altered by amylaar to support excompatible option and the * operators \< and >\ . ( 7.Sep. 1991 ) * * regsub altered by amylaar to take an additional parameter specifying * maximum number of bytes that can be written to the memory region * pointed to by dest * - * Beware that some of this code is subtly aware of the way operator - * precedence is structured in regular expressions. Serious changes in - * regular-expression syntax might require a total rethink. + * Beware that some of this code is subtly aware of the way operator + * precedence is structured in regular expressions. Serious changes in + * regular-expression syntax might require a total rethink. * * AUTHORS * @@ -67,10 +67,10 @@ * compile to execute that permits the execute phase to run lots faster on * simple cases. They are: * - * regstart char that must begin a match; '\0' if none obvious - * reganch is the match anchored (at beginning-of-line only)? - * regmust string (pointer into program) that match must include, or NULL - * regmlen length of regmust string + * regstart char that must begin a match; '\0' if none obvious + * reganch is the match anchored (at beginning-of-line only)? + * regmust string (pointer into program) that match must include, or NULL + * regmlen length of regmust string * * Regstart and reganch permit very fast decisions on suitable starting points * for a match, cutting down the work a lot. Regmust permits fast rejection @@ -98,48 +98,48 @@ * to the thing following the set of BRANCHes.) The opcodes are: */ -/* definition number opnd? meaning */ -#define END 0 /* no End of program. */ -#define BOL 1 /* no Match "" at beginning of line. */ -#define EOL 2 /* no Match "" at end of line. */ -#define ANY 3 /* no Match any one character. */ -#define ANYOF 4 /* str Match any character in this string. */ -#define ANYBUT 5 /* str Match any character not in this - * string. */ -#define BRANCH 6 /* node Match this alternative, or the - * nxt... */ -#define BACK 7 /* no Match "", "nxt" ptr points backward. */ -#define EXACTLY 8 /* str Match this string. */ -#define NOTHING 9 /* no Match empty string. */ -#define STAR 10 /* node Match this (simple) thing 0 or more - * times. */ -#define WORDSTART 11 /* node matching a start of a word */ -#define WORDEND 12 /* node matching an end of a word */ -#define OPEN 20 /* no Mark this point in input as start of - * #n. */ +/* definition number opnd? meaning */ +#define END 0 /* no End of program. */ +#define BOL 1 /* no Match "" at beginning of line. */ +#define EOL 2 /* no Match "" at end of line. */ +#define ANY 3 /* no Match any one character. */ +#define ANYOF 4 /* str Match any character in this string. */ +#define ANYBUT 5 /* str Match any character not in this + * string. */ +#define BRANCH 6 /* node Match this alternative, or the + * nxt... */ +#define BACK 7 /* no Match "", "nxt" ptr points backward. */ +#define EXACTLY 8 /* str Match this string. */ +#define NOTHING 9 /* no Match empty string. */ +#define STAR 10 /* node Match this (simple) thing 0 or more + * times. */ +#define WORDSTART 11 /* node matching a start of a word */ +#define WORDEND 12 /* node matching an end of a word */ +#define OPEN 20 /* no Mark this point in input as start of + * #n. */ /* OPEN+1 is number 1, etc. */ -#define CLOSE 30 /* no Analogous to OPEN. */ +#define CLOSE 30 /* no Analogous to OPEN. */ /* * Opcode notes: * - * BRANCH The set of branches constituting a single choice are hooked - * together with their "nxt" pointers, since precedence prevents - * anything being concatenated to any individual branch. The - * "nxt" pointer of the last BRANCH in a choice points to the - * thing following the whole choice. This is also where the - * final "nxt" pointer of each individual branch points; each - * branch starts with the operand node of a BRANCH node. + * BRANCH The set of branches constituting a single choice are hooked + * together with their "nxt" pointers, since precedence prevents + * anything being concatenated to any individual branch. The + * "nxt" pointer of the last BRANCH in a choice points to the + * thing following the whole choice. This is also where the + * final "nxt" pointer of each individual branch points; each + * branch starts with the operand node of a BRANCH node. * - * BACK Normal "nxt" pointers all implicitly point forward; BACK - * exists to make loop structures possible. + * BACK Normal "nxt" pointers all implicitly point forward; BACK + * exists to make loop structures possible. * - * STAR complex '*', are implemented as circular BRANCH structures - * using BACK. Simple cases (one character per match) are - * implemented with STAR for speed and to minimize recursive - * plunges. + * STAR complex '*', are implemented as circular BRANCH structures + * using BACK. Simple cases (one character per match) are + * implemented with STAR for speed and to minimize recursive + * plunges. * - * OPEN,CLOSE ...are numbered at compile time. + * OPEN,CLOSE ...are numbered at compile time. */ /* @@ -152,59 +152,59 @@ * Using two bytes for the "nxt" pointer is vast overkill for most things, * but allows patterns to get big without disasters. */ -#define OP(p) (*(p)) -#define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377)) -#define OPERAND(p) ((p) + 3) +#define OP(p) (*(p)) +#define NEXT(p) (((*((p)+1)&0377)<<8) + (*((p)+2)&0377)) +#define OPERAND(p) ((p) + 3) /* * Utility definitions. */ #define SPECIAL 0x100 -#define LBRAC ('('|SPECIAL) -#define RBRAC (')'|SPECIAL) -#define ASTERIX ('*'|SPECIAL) -#define OR_OP ('|'|SPECIAL) -#define DOLLAR ('$'|SPECIAL) -#define DOT ('.'|SPECIAL) -#define CARET ('^'|SPECIAL) +#define LBRAC ('('|SPECIAL) +#define RBRAC (')'|SPECIAL) +#define ASTERIX ('*'|SPECIAL) +#define OR_OP ('|'|SPECIAL) +#define DOLLAR ('$'|SPECIAL) +#define DOT ('.'|SPECIAL) +#define CARET ('^'|SPECIAL) #define LSQBRAC ('['|SPECIAL) #define RSQBRAC (']'|SPECIAL) #define LSHBRAC ('<'|SPECIAL) #define RSHBRAC ('>'|SPECIAL) -#define FAIL(m) { regerror(m); return(NULL); } -#define ISMULT(c) ((c) == ASTERIX) -#define META "^$.[()|*\\" +#define FAIL(m) { regerror(m); return(NULL); } +#define ISMULT(c) ((c) == ASTERIX) +#define META "^$.[()|*\\" #ifndef CHARBITS -#define CHARBITS 0xff -#define UCHARAT(p) ((int)*(unsigned char *)(p)) +#define CHARBITS 0xff +#define UCHARAT(p) ((int)*(unsigned char *)(p)) #else -#define UCHARAT(p) ((int)*(p)&CHARBITS) +#define UCHARAT(p) ((int)*(p)&CHARBITS) #endif #define ISWORDPART(c) ( isalnum(c) || (c) == '_' ) /* * Flags to be passed up and down. */ -#define HASWIDTH 01 /* Known never to match null string. */ -#define SIMPLE 02 /* Simple enough to be STAR operand. */ -#define SPSTART 04 /* Starts with * */ -#define WORST 0 /* Worst case. */ +#define HASWIDTH 01 /* Known never to match null string. */ +#define SIMPLE 02 /* Simple enough to be STAR operand. */ +#define SPSTART 04 /* Starts with * */ +#define WORST 0 /* Worst case. */ /* * Global work variables for regcomp(). */ -static short *regparse; /* Input-scan pointer. */ -static int regnpar; /* () count. */ +static short *regparse; /* Input-scan pointer. */ +static int regnpar; /* () count. */ static char regdummy; -static char *regcode; /* Code-emit pointer; ®dummy = don't. */ -static long regsize; /* Code size. */ +static char *regcode; /* Code-emit pointer; ®dummy = don't. */ +static long regsize; /* Code size. */ /* * Forward declarations for regcomp()'s friends. */ #ifndef STATIC -#define STATIC static +#define STATIC static #endif STATIC char *reg(int, int *); STATIC char *regbranch(int *); @@ -235,7 +235,7 @@ STATIC void regoptail(char *, char *); regexp * regcomp(char *rexp, int excompat) /* -int excompat; \( \) operators like in unix ex +int excompat; \( \) operators like in unix ex */ { register regexp *r; @@ -243,50 +243,50 @@ int excompat; \( \) operators like in unix ex register char *longest; register int len; int flags; - short *exp2,*dest,c; + short *exp2,*dest,c; if (rexp == (char *)NULL) - FAIL("NULL argument"); + FAIL("NULL argument"); exp2=(short*)xalloc( (strlen(rexp)+1) * (sizeof(short[8])/sizeof(char[8])) ); for ( scan=rexp,dest=exp2; (c= *scan++); ) { - switch (c) { - case '(': - case ')': - *dest++ = excompat ? c : c | SPECIAL; - break; - case '.': - case '*': - case '|': - case '$': - case '^': - case '[': - case ']': - *dest++ = c | SPECIAL; - break; - case '\\': - switch ( c = *scan++ ) { - case '(': - case ')': - *dest++ = excompat ? c | SPECIAL : c; - break; - case '<': - case '>': - *dest++ = c | SPECIAL; - break; - case '{': - case '}': - FAIL("sorry, unimplemented operator"); - case 'b': *dest++ = '\b'; break; - case 't': *dest++ = '\t'; break; - case 'r': *dest++ = '\r'; break; - default: - *dest++ = c; - } - break; - default: - *dest++ = c; - } + switch (c) { + case '(': + case ')': + *dest++ = excompat ? c : c | SPECIAL; + break; + case '.': + case '*': + case '|': + case '$': + case '^': + case '[': + case ']': + *dest++ = c | SPECIAL; + break; + case '\\': + switch ( c = *scan++ ) { + case '(': + case ')': + *dest++ = excompat ? c | SPECIAL : c; + break; + case '<': + case '>': + *dest++ = c | SPECIAL; + break; + case '{': + case '}': + FAIL("sorry, unimplemented operator"); + case 'b': *dest++ = '\b'; break; + case 't': *dest++ = '\t'; break; + case 'r': *dest++ = '\r'; break; + default: + *dest++ = c; + } + break; + default: + *dest++ = c; + } } *dest=0; /* First pass: determine size, legality. */ @@ -296,16 +296,16 @@ int excompat; \( \) operators like in unix ex regcode = ®dummy; regc((char)MAGIC); if (reg(0, &flags) == (char *)NULL) - return ((regexp *)NULL); + return ((regexp *)NULL); /* Small enough for pointer-storage convention? */ - if (regsize >= 32767L) /* Probably could be 65535L. */ - FAIL("regexp too big"); + if (regsize >= 32767L) /* Probably could be 65535L. */ + FAIL("regexp too big"); /* Allocate space. */ r = (regexp *) xalloc(sizeof(regexp) + (unsigned) regsize); if (r == (regexp *) NULL) - FAIL("out of space"); + FAIL("out of space"); /* Second pass: emit code. */ regparse = exp2; @@ -313,42 +313,42 @@ int excompat; \( \) operators like in unix ex regcode = r->program; regc((char)MAGIC); if (reg(0, &flags) == NULL) - return ((regexp *) NULL); + return ((regexp *) NULL); /* Dig out information for optimizations. */ - r->regstart = '\0'; /* Worst-case defaults. */ + r->regstart = '\0'; /* Worst-case defaults. */ r->reganch = 0; r->regmust = NULL; r->regmlen = 0; - scan = r->program + 1; /* First BRANCH. */ - if (OP(regnext(scan)) == END) { /* Only one top-level choice. */ - scan = OPERAND(scan); - - /* Starting-point info. */ - if (OP(scan) == EXACTLY) - r->regstart = *OPERAND(scan); - else if (OP(scan) == BOL) - r->reganch++; - - /* - * If there's something expensive in the r.e., find the longest - * literal string that must appear and make it the regmust. Resolve - * ties in favor of later strings, since the regstart check works - * with the beginning of the r.e. and avoiding duplication - * strengthens checking. Not a strong reason, but sufficient in the - * absence of others. - */ - if (flags & SPSTART) { - longest = NULL; - len = 0; - for (; scan != NULL; scan = regnext(scan)) - if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) { - longest = OPERAND(scan); - len = strlen(OPERAND(scan)); - } - r->regmust = longest; - r->regmlen = len; - } + scan = r->program + 1; /* First BRANCH. */ + if (OP(regnext(scan)) == END) { /* Only one top-level choice. */ + scan = OPERAND(scan); + + /* Starting-point info. */ + if (OP(scan) == EXACTLY) + r->regstart = *OPERAND(scan); + else if (OP(scan) == BOL) + r->reganch++; + + /* + * If there's something expensive in the r.e., find the longest + * literal string that must appear and make it the regmust. Resolve + * ties in favor of later strings, since the regstart check works + * with the beginning of the r.e. and avoiding duplication + * strengthens checking. Not a strong reason, but sufficient in the + * absence of others. + */ + if (flags & SPSTART) { + longest = NULL; + len = 0; + for (; scan != NULL; scan = regnext(scan)) + if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) { + longest = OPERAND(scan); + len = strlen(OPERAND(scan)); + } + r->regmust = longest; + r->regmlen = len; + } } free((char*)exp2); return (r); @@ -372,38 +372,38 @@ reg(int paren, int *flagp) register int parno = 0; int flags; - *flagp = HASWIDTH; /* Tentatively. */ + *flagp = HASWIDTH; /* Tentatively. */ /* Make an OPEN node, if parenthesized. */ if (paren) { - if (regnpar >= NSUBEXP) - FAIL("too many ()"); - parno = regnpar; - regnpar++; - ret = regnode((char)(OPEN + parno)); + if (regnpar >= NSUBEXP) + FAIL("too many ()"); + parno = regnpar; + regnpar++; + ret = regnode((char)(OPEN + parno)); } else - ret = (char *)NULL; + ret = (char *)NULL; /* Pick up the branches, linking them together. */ br = regbranch(&flags); if (br == (char *)NULL) - return ((char *)NULL); + return ((char *)NULL); if (ret != (char *)NULL) - regtail(ret, br); /* OPEN -> first. */ + regtail(ret, br); /* OPEN -> first. */ else - ret = br; + ret = br; if (!(flags & HASWIDTH)) - *flagp &= ~HASWIDTH; + *flagp &= ~HASWIDTH; *flagp |= flags & SPSTART; while (*regparse == OR_OP) { - regparse++; - br = regbranch(&flags); - if (br == (char *)NULL) - return ((char *)NULL); - regtail(ret, br); /* BRANCH -> BRANCH. */ - if (!(flags & HASWIDTH)) - *flagp &= ~HASWIDTH; - *flagp |= flags & SPSTART; + regparse++; + br = regbranch(&flags); + if (br == (char *)NULL) + return ((char *)NULL); + regtail(ret, br); /* BRANCH -> BRANCH. */ + if (!(flags & HASWIDTH)) + *flagp &= ~HASWIDTH; + *flagp |= flags & SPSTART; } /* Make a closing node, and hook it on the end. */ @@ -412,17 +412,17 @@ reg(int paren, int *flagp) /* Hook the tails of the branches to the closing node. */ for (br = ret; br != (char *)NULL; br = regnext(br)) - regoptail(br, ender); + regoptail(br, ender); /* Check for proper termination. */ if (paren && *regparse++ != RBRAC) { - FAIL("unmatched ()"); + FAIL("unmatched ()"); } else if (!paren && *regparse != '\0') { - if (*regparse == RBRAC) { - FAIL("unmatched ()"); - } else - FAIL("junk on end");/* "Can't happen". */ - /* NOTREACHED */ + if (*regparse == RBRAC) { + FAIL("unmatched ()"); + } else + FAIL("junk on end");/* "Can't happen". */ + /* NOTREACHED */ } return (ret); } @@ -440,23 +440,23 @@ regbranch(int *flagp) register char *latest; int flags; - *flagp = WORST; /* Tentatively. */ + *flagp = WORST; /* Tentatively. */ ret = regnode(BRANCH); chain = (char *)NULL; while (*regparse != '\0' && *regparse != OR_OP && *regparse != RBRAC) { - latest = regpiece(&flags); - if (latest == (char *)NULL) - return ((char *)NULL); - *flagp |= flags & HASWIDTH; - if (chain == (char *)NULL) /* First piece. */ - *flagp |= flags & SPSTART; - else - regtail(chain, latest); - chain = latest; + latest = regpiece(&flags); + if (latest == (char *)NULL) + return ((char *)NULL); + *flagp |= flags & HASWIDTH; + if (chain == (char *)NULL) /* First piece. */ + *flagp |= flags & SPSTART; + else + regtail(chain, latest); + chain = latest; } - if (chain == (char *)NULL) /* Loop ran zero times. */ - (void)regnode(NOTHING); + if (chain == (char *)NULL) /* Loop ran zero times. */ + (void)regnode(NOTHING); return (ret); } @@ -479,30 +479,30 @@ regpiece(int *flagp) ret = regatom(&flags); if (ret == (char *)NULL) - return ((char *)NULL); + return ((char *)NULL); op = *regparse; if (!ISMULT(op)) { - *flagp = flags; - return (ret); + *flagp = flags; + return (ret); } if (!(flags & HASWIDTH)) - FAIL("* operand could be empty"); + FAIL("* operand could be empty"); *flagp = (WORST | SPSTART); if (op == ASTERIX && (flags & SIMPLE)) - reginsert(STAR, ret); + reginsert(STAR, ret); else if (op == ASTERIX) { - /* Emit x* as (x&|), where & means "self". */ - reginsert(BRANCH, ret); /* Either x */ - regoptail(ret, regnode(BACK)); /* and loop */ - regoptail(ret, ret); /* back */ - regtail(ret, regnode(BRANCH)); /* or */ - regtail(ret, regnode(NOTHING)); /* null. */ + /* Emit x* as (x&|), where & means "self". */ + reginsert(BRANCH, ret); /* Either x */ + regoptail(ret, regnode(BACK)); /* and loop */ + regoptail(ret, ret); /* back */ + regtail(ret, regnode(BRANCH)); /* or */ + regtail(ret, regnode(NOTHING)); /* null. */ } regparse++; if (ISMULT(*regparse)) - FAIL("nested *"); + FAIL("nested *"); return (ret); } @@ -520,97 +520,97 @@ regatom(int *flagp) register char *ret; int flags; - *flagp = WORST; /* Tentatively. */ + *flagp = WORST; /* Tentatively. */ switch (*regparse++) { case CARET: - ret = regnode(BOL); - break; + ret = regnode(BOL); + break; case DOLLAR: - ret = regnode(EOL); - break; + ret = regnode(EOL); + break; case DOT: - ret = regnode(ANY); - *flagp |= HASWIDTH | SIMPLE; - break; + ret = regnode(ANY); + *flagp |= HASWIDTH | SIMPLE; + break; case LSHBRAC: - ret = regnode(WORDSTART); - break; + ret = regnode(WORDSTART); + break; case RSHBRAC: - ret = regnode(WORDEND); - break; + ret = regnode(WORDEND); + break; case LSQBRAC:{ - register int class; - register int classend; - - if (*regparse == CARET) { /* Complement of range. */ - ret = regnode(ANYBUT); - regparse++; - } else - ret = regnode(ANYOF); - if (*regparse == RSQBRAC || *regparse == '-') - regc((char)*regparse++); - while (*regparse != '\0' && *regparse != RSQBRAC) { - if (*regparse == '-') { - regparse++; - if (*regparse == RSQBRAC || *regparse == '\0') - regc('-'); - else { - class = (CHARBITS & *(regparse - 2)) + 1; - classend = (CHARBITS & *(regparse)); - if (class > classend + 1) - FAIL("invalid [] range"); - for (; class <= classend; class++) - regc((char)class); - regparse++; - } - } else - regc((char)*regparse++); - } - regc('\0'); - if (*regparse != RSQBRAC) - FAIL("unmatched []"); - regparse++; - *flagp |= HASWIDTH | SIMPLE; - } - break; + register int class; + register int classend; + + if (*regparse == CARET) { /* Complement of range. */ + ret = regnode(ANYBUT); + regparse++; + } else + ret = regnode(ANYOF); + if (*regparse == RSQBRAC || *regparse == '-') + regc((char)*regparse++); + while (*regparse != '\0' && *regparse != RSQBRAC) { + if (*regparse == '-') { + regparse++; + if (*regparse == RSQBRAC || *regparse == '\0') + regc('-'); + else { + class = (CHARBITS & *(regparse - 2)) + 1; + classend = (CHARBITS & *(regparse)); + if (class > classend + 1) + FAIL("invalid [] range"); + for (; class <= classend; class++) + regc((char)class); + regparse++; + } + } else + regc((char)*regparse++); + } + regc('\0'); + if (*regparse != RSQBRAC) + FAIL("unmatched []"); + regparse++; + *flagp |= HASWIDTH | SIMPLE; + } + break; case LBRAC: - ret = reg(1, &flags); - if (ret == (char *)NULL) - return ((char *)NULL); - *flagp |= flags & (HASWIDTH | SPSTART); - break; + ret = reg(1, &flags); + if (ret == (char *)NULL) + return ((char *)NULL); + *flagp |= flags & (HASWIDTH | SPSTART); + break; case '\0': case OR_OP: case RBRAC: - FAIL("internal urp"); /* Supposed to be caught earlier. */ + FAIL("internal urp"); /* Supposed to be caught earlier. */ case ASTERIX: - FAIL("* follows nothing"); + FAIL("* follows nothing"); default:{ - register int len; - register short ender; - - regparse--; - for (len=0; regparse[len] && - !(regparse[len]&SPECIAL) && regparse[len] != RSQBRAC; len++) ; - if (len <= 0) - { - FAIL("internal disaster"); - } - ender = *(regparse + len); - if (len > 1 && ISMULT(ender)) - len--; /* Back off clear of * operand. */ - *flagp |= HASWIDTH; - if (len == 1) - *flagp |= SIMPLE; - ret = regnode(EXACTLY); - while (len > 0) { - regc((char)*regparse++); - len--; - } - regc('\0'); - } - break; + register int len; + register short ender; + + regparse--; + for (len=0; regparse[len] && + !(regparse[len]&SPECIAL) && regparse[len] != RSQBRAC; len++) ; + if (len <= 0) + { + FAIL("internal disaster"); + } + ender = *(regparse + len); + if (len > 1 && ISMULT(ender)) + len--; /* Back off clear of * operand. */ + *flagp |= HASWIDTH; + if (len == 1) + *flagp |= SIMPLE; + ret = regnode(EXACTLY); + while (len > 0) { + regc((char)*regparse++); + len--; + } + regc('\0'); + } + break; } return (ret); @@ -627,12 +627,12 @@ regnode(char op) ret = regcode; if (ret == ®dummy) { - regsize += 3; - return (ret); + regsize += 3; + return (ret); } ptr = ret; *ptr++ = op; - *ptr++ = '\0'; /* Null "nxt" pointer. */ + *ptr++ = '\0'; /* Null "nxt" pointer. */ *ptr++ = '\0'; regcode = ptr; @@ -646,9 +646,9 @@ static INLINE void regc(char b) { if (regcode != ®dummy) - *regcode++ = b; + *regcode++ = b; else - regsize++; + regsize++; } /* @@ -664,16 +664,16 @@ reginsert(char op, char *opnd) register char *place; if (regcode == ®dummy) { - regsize += 3; - return; + regsize += 3; + return; } src = regcode; regcode += 3; dst = regcode; while (src > opnd) - *--dst = *--src; + *--dst = *--src; - place = opnd; /* Op node, where operand used to be. */ + place = opnd; /* Op node, where operand used to be. */ *place++ = op; *place++ = '\0'; *place++ = '\0'; @@ -689,21 +689,21 @@ static void regtail(char *p, char *val) register int offset; if (p == ®dummy) - return; + return; /* Find last node. */ scan = p; for (;;) { - temp = regnext(scan); - if (temp == (char *)NULL) - break; - scan = temp; + temp = regnext(scan); + if (temp == (char *)NULL) + break; + scan = temp; } if (OP(scan) == BACK) - offset = scan - val; + offset = scan - val; else - offset = val - scan; + offset = val - scan; *(scan + 1) = ((unsigned)offset >> 8) & 0377; *(scan + 2) = offset & 0377; } @@ -716,7 +716,7 @@ regoptail(char *p, char *val) { /* "Operandless" and "op != BRANCH" are synonymous in practice. */ if (p == (char *)NULL || p == ®dummy || OP(p) != BRANCH) - return; + return; regtail(OPERAND(p), val); } @@ -727,17 +727,17 @@ regoptail(char *p, char *val) /* * Global work variables for regexec(). */ -static char *reginput; /* String-input pointer. */ -static char *regbol; /* Beginning of input, for ^ check. */ -static char **regstartp; /* Pointer to startp array. */ -static char **regendp; /* Ditto for endp. */ +static char *reginput; /* String-input pointer. */ +static char *regbol; /* Beginning of input, for ^ check. */ +static char **regstartp; /* Pointer to startp array. */ +static char **regendp; /* Ditto for endp. */ /* * Forwards. */ STATIC int regtry(regexp *, char *); STATIC int regmatch(char *); -STATIC int regrepeat(char *); +STATIC int regrepeat(char *); #ifdef DEBUG int regnarrate = 0; @@ -754,47 +754,47 @@ regexec(register regexp *prog, register char *string) /* Be paranoid... */ if (prog == (regexp *)NULL || string == (char *)NULL) { - regerror("NULL parameter"); - return (0); + regerror("NULL parameter"); + return (0); } /* Check validity of program. */ if (UCHARAT(prog->program) != MAGIC) { - regerror("corrupted program"); - return (0); + regerror("corrupted program"); + return (0); } /* If there is a "must appear" string, look for it. */ if (prog->regmust != (char *)NULL) { - s = string; - while ((s = strchr(s, prog->regmust[0])) != (char *)NULL) { - if (strncmp(s, prog->regmust, (size_t)prog->regmlen) == 0) - break; /* Found it. */ - s++; - } - if (s == (char *)NULL) /* Not present. */ - return (0); + s = string; + while ((s = strchr(s, prog->regmust[0])) != (char *)NULL) { + if (strncmp(s, prog->regmust, (size_t)prog->regmlen) == 0) + break; /* Found it. */ + s++; + } + if (s == (char *)NULL) /* Not present. */ + return (0); } /* Mark beginning of line for ^ . */ regbol = string; /* Simplest case: anchored match need be tried only once. */ if (prog->reganch) - return (regtry(prog, string)); + return (regtry(prog, string)); /* Messy cases: unanchored match. */ s = string; if (prog->regstart != '\0') - /* We know what char it must start with. */ - while ((s = strchr(s, prog->regstart)) != (char *)NULL) { - if (regtry(prog, s)) - return (1); - s++; - } + /* We know what char it must start with. */ + while ((s = strchr(s, prog->regstart)) != (char *)NULL) { + if (regtry(prog, s)) + return (1); + s++; + } else - /* We don't -- general case. */ - do { - if (regtry(prog, s)) - return (1); - } while (*s++ != '\0'); + /* We don't -- general case. */ + do { + if (regtry(prog, s)) + return (1); + } while (*s++ != '\0'); /* Failure. */ return (0); @@ -817,15 +817,15 @@ regtry(regexp *prog, char *string) sprog = prog->startp; eprog = prog->endp; for (i = NSUBEXP; i > 0; i--) { - *sprog++ = (char *)NULL; - *eprog++ = (char *)NULL; + *sprog++ = (char *)NULL; + *eprog++ = (char *)NULL; } if (regmatch(prog->program + 1)) { - prog->startp[0] = string; - prog->endp[0] = reginput; - return (1); + prog->startp[0] = string; + prog->endp[0] = reginput; + return (1); } else - return (0); + return (0); } /* @@ -842,184 +842,184 @@ regtry(regexp *prog, char *string) static int regmatch(char *prog) { - register char *scan; /* Current node. */ - char *nxt; /* nxt node. */ + register char *scan; /* Current node. */ + char *nxt; /* nxt node. */ scan = prog; #ifdef DEBUG if (scan != (char *)NULL && regnarrate) - (void)fprintf(stderr, "%s(\n", regprop(scan)); + (void)fprintf(stderr, "%s(\n", regprop(scan)); #endif while (scan != (char *)NULL) { #ifdef DEBUG - if (regnarrate) - (void)fprintf(stderr, "%s...\n", regprop(scan)); + if (regnarrate) + (void)fprintf(stderr, "%s...\n", regprop(scan)); #endif - nxt = regnext(scan); - - switch (OP(scan)) { - case BOL: - if (reginput != regbol) - return (0); - break; - case EOL: - if (*reginput != '\0') - return (0); - break; - case ANY: - if (*reginput == '\0') - return (0); - reginput++; - break; - case WORDSTART: - if (reginput == regbol) - break; - if (*reginput == '\0' || - ISWORDPART( *(reginput-1) ) || !ISWORDPART( *reginput ) ) - return (0); - break; - case WORDEND: - if (*reginput == '\0') - break; - if ( reginput == regbol || - !ISWORDPART( *(reginput-1) ) || ISWORDPART( *reginput ) ) - return (0); - break; - case EXACTLY:{ - register size_t len; - register char *opnd; - - opnd = OPERAND(scan); - /* Inline the first character, for speed. */ - if (*opnd != *reginput) - return (0); - len = strlen(opnd); - if (len > 1 && strncmp(opnd, reginput, len) != 0) - return (0); - reginput += len; - } - break; - case ANYOF: - if (*reginput == '\0' || - strchr(OPERAND(scan), *reginput) == (char *)NULL) - return (0); - reginput++; - break; - case ANYBUT: - if (*reginput == '\0' || - strchr(OPERAND(scan), *reginput) != (char *)NULL) - return (0); - reginput++; - break; - case NOTHING: - break; - case BACK: - break; - case OPEN + 1: - case OPEN + 2: - case OPEN + 3: - case OPEN + 4: - case OPEN + 5: - case OPEN + 6: - case OPEN + 7: - case OPEN + 8: - case OPEN + 9:{ - register int no; - register char *save; - - no = OP(scan) - OPEN; - save = reginput; - - if (regmatch(nxt)) { - /* - * Don't set startp if some later invocation of the same - * parentheses already has. - */ - if (regstartp[no] == (char *)NULL) - regstartp[no] = save; - return (1); - } else - return (0); - } - case CLOSE + 1: - case CLOSE + 2: - case CLOSE + 3: - case CLOSE + 4: - case CLOSE + 5: - case CLOSE + 6: - case CLOSE + 7: - case CLOSE + 8: - case CLOSE + 9:{ - register int no; - register char *save; - - no = OP(scan) - CLOSE; - save = reginput; - - if (regmatch(nxt)) { - /* - * Don't set endp if some later invocation of the same - * parentheses already has. - */ - if (regendp[no] == (char *)NULL) - regendp[no] = save; - return (1); - } else - return (0); - } - case BRANCH:{ - register char *save; - - if (OP(nxt) != BRANCH) /* No choice. */ - nxt = OPERAND(scan); /* Avoid recursion. */ - else { - do { - save = reginput; - if (regmatch(OPERAND(scan))) - return (1); - reginput = save; - scan = regnext(scan); - } while (scan != (char *)NULL && OP(scan) == BRANCH); - return (0); - /* NOTREACHED */ - } - } - break; - case STAR:{ - register char nextch; - register int no; - register char *save; - register int minimum; - - /* - * Lookahead to avoid useless match attempts when we know - * what character comes next. - */ - nextch = '\0'; - if (OP(nxt) == EXACTLY) - nextch = *OPERAND(nxt); - minimum = (OP(scan) == STAR) ? 0 : 1; - save = reginput; - no = regrepeat(OPERAND(scan)); - while (no >= minimum) { - /* If it could work, try it. */ - if (nextch == '\0' || *reginput == nextch) - if (regmatch(nxt)) - return (1); - /* Couldn't or didn't -- back up. */ - no--; - reginput = save + no; - } - return (0); - } - case END: - return (1); /* Success! */ - default: - regerror("memory corruption"); - return (0); - } - - scan = nxt; + nxt = regnext(scan); + + switch (OP(scan)) { + case BOL: + if (reginput != regbol) + return (0); + break; + case EOL: + if (*reginput != '\0') + return (0); + break; + case ANY: + if (*reginput == '\0') + return (0); + reginput++; + break; + case WORDSTART: + if (reginput == regbol) + break; + if (*reginput == '\0' || + ISWORDPART( *(reginput-1) ) || !ISWORDPART( *reginput ) ) + return (0); + break; + case WORDEND: + if (*reginput == '\0') + break; + if ( reginput == regbol || + !ISWORDPART( *(reginput-1) ) || ISWORDPART( *reginput ) ) + return (0); + break; + case EXACTLY:{ + register size_t len; + register char *opnd; + + opnd = OPERAND(scan); + /* Inline the first character, for speed. */ + if (*opnd != *reginput) + return (0); + len = strlen(opnd); + if (len > 1 && strncmp(opnd, reginput, len) != 0) + return (0); + reginput += len; + } + break; + case ANYOF: + if (*reginput == '\0' || + strchr(OPERAND(scan), *reginput) == (char *)NULL) + return (0); + reginput++; + break; + case ANYBUT: + if (*reginput == '\0' || + strchr(OPERAND(scan), *reginput) != (char *)NULL) + return (0); + reginput++; + break; + case NOTHING: + break; + case BACK: + break; + case OPEN + 1: + case OPEN + 2: + case OPEN + 3: + case OPEN + 4: + case OPEN + 5: + case OPEN + 6: + case OPEN + 7: + case OPEN + 8: + case OPEN + 9:{ + register int no; + register char *save; + + no = OP(scan) - OPEN; + save = reginput; + + if (regmatch(nxt)) { + /* + * Don't set startp if some later invocation of the same + * parentheses already has. + */ + if (regstartp[no] == (char *)NULL) + regstartp[no] = save; + return (1); + } else + return (0); + } + case CLOSE + 1: + case CLOSE + 2: + case CLOSE + 3: + case CLOSE + 4: + case CLOSE + 5: + case CLOSE + 6: + case CLOSE + 7: + case CLOSE + 8: + case CLOSE + 9:{ + register int no; + register char *save; + + no = OP(scan) - CLOSE; + save = reginput; + + if (regmatch(nxt)) { + /* + * Don't set endp if some later invocation of the same + * parentheses already has. + */ + if (regendp[no] == (char *)NULL) + regendp[no] = save; + return (1); + } else + return (0); + } + case BRANCH:{ + register char *save; + + if (OP(nxt) != BRANCH) /* No choice. */ + nxt = OPERAND(scan); /* Avoid recursion. */ + else { + do { + save = reginput; + if (regmatch(OPERAND(scan))) + return (1); + reginput = save; + scan = regnext(scan); + } while (scan != (char *)NULL && OP(scan) == BRANCH); + return (0); + /* NOTREACHED */ + } + } + break; + case STAR:{ + register char nextch; + register int no; + register char *save; + register int minimum; + + /* + * Lookahead to avoid useless match attempts when we know + * what character comes next. + */ + nextch = '\0'; + if (OP(nxt) == EXACTLY) + nextch = *OPERAND(nxt); + minimum = (OP(scan) == STAR) ? 0 : 1; + save = reginput; + no = regrepeat(OPERAND(scan)); + while (no >= minimum) { + /* If it could work, try it. */ + if (nextch == '\0' || *reginput == nextch) + if (regmatch(nxt)) + return (1); + /* Couldn't or didn't -- back up. */ + no--; + reginput = save + no; + } + return (0); + } + case END: + return (1); /* Success! */ + default: + regerror("memory corruption"); + return (0); + } + + scan = nxt; } /* @@ -1044,31 +1044,31 @@ regrepeat(char *p) opnd = OPERAND(p); switch (OP(p)) { case ANY: - count = strlen(scan); - scan += count; - break; + count = strlen(scan); + scan += count; + break; case EXACTLY: - while (*opnd == *scan) { - count++; - scan++; - } - break; + while (*opnd == *scan) { + count++; + scan++; + } + break; case ANYOF: - while (*scan != '\0' && strchr(opnd, *scan) != (char *)NULL) { - count++; - scan++; - } - break; + while (*scan != '\0' && strchr(opnd, *scan) != (char *)NULL) { + count++; + scan++; + } + break; case ANYBUT: - while (*scan != '\0' && strchr(opnd, *scan) == (char *)NULL) { - count++; - scan++; - } - break; - default: /* Oh dear. Called inappropriately. */ - regerror("internal foulup"); - count = 0; /* Best compromise. */ - break; + while (*scan != '\0' && strchr(opnd, *scan) == (char *)NULL) { + count++; + scan++; + } + break; + default: /* Oh dear. Called inappropriately. */ + regerror("internal foulup"); + count = 0; /* Best compromise. */ + break; } reginput = scan; @@ -1085,16 +1085,16 @@ regnext(register char *p) register int offset; if (p == ®dummy) - return ((char *)NULL); + return ((char *)NULL); offset = NEXT(p); if (offset == 0) - return ((char *)NULL); + return ((char *)NULL); if (OP(p) == BACK) - return (p - offset); + return (p - offset); else - return (p + offset); + return (p + offset); } #ifdef DEBUG @@ -1114,35 +1114,35 @@ static char switch (OP(op)) { case BOL: - p = "BOL"; - break; + p = "BOL"; + break; case EOL: - p = "EOL"; - break; + p = "EOL"; + break; case ANY: - p = "ANY"; - break; + p = "ANY"; + break; case ANYOF: - p = "ANYOF"; - break; + p = "ANYOF"; + break; case ANYBUT: - p = "ANYBUT"; - break; + p = "ANYBUT"; + break; case BRANCH: - p = "BRANCH"; - break; + p = "BRANCH"; + break; case EXACTLY: - p = "EXACTLY"; - break; + p = "EXACTLY"; + break; case NOTHING: - p = "NOTHING"; - break; + p = "NOTHING"; + break; case BACK: - p = "BACK"; - break; + p = "BACK"; + break; case END: - p = "END"; - break; + p = "END"; + break; case OPEN + 1: case OPEN + 2: case OPEN + 3: @@ -1152,9 +1152,9 @@ static char case OPEN + 7: case OPEN + 8: case OPEN + 9: - (void)sprintf(buf + strlen(buf), "OPEN%d", OP(op) - OPEN); - p = (char *)NULL; - break; + (void)sprintf(buf + strlen(buf), "OPEN%d", OP(op) - OPEN); + p = (char *)NULL; + break; case CLOSE + 1: case CLOSE + 2: case CLOSE + 3: @@ -1164,19 +1164,19 @@ static char case CLOSE + 7: case CLOSE + 8: case CLOSE + 9: - (void)sprintf(buf + strlen(buf), "CLOSE%d", OP(op) - CLOSE); - p = (char *)NULL; - break; + (void)sprintf(buf + strlen(buf), "CLOSE%d", OP(op) - CLOSE); + p = (char *)NULL; + break; case STAR: - p = "STAR"; - break; + p = "STAR"; + break; default: - regerror("corrupted opcode"); - p = (char *)NULL; - break; + regerror("corrupted opcode"); + p = (char *)NULL; + break; } if (p != (char *)NULL) - (void)strcat(buf, p); + (void)strcat(buf, p); return (buf); } #endif @@ -1194,57 +1194,57 @@ regsub(regexp *prog, char *source, char *dest, int n) register size_t len; if (prog == (regexp *)NULL || - source == (char *)NULL || dest == (char *)NULL) { - regerror("NULL parm to regsub"); - return NULL; + source == (char *)NULL || dest == (char *)NULL) { + regerror("NULL parm to regsub"); + return NULL; } if (UCHARAT(prog->program) != MAGIC) { - regerror("damaged regexp fed to regsub"); - return NULL; + regerror("damaged regexp fed to regsub"); + return NULL; } src = source; dst = dest; while ((c = *src++) != '\0') { - if (c == '&') - no = 0; - else if (c == '\\' && '0' <= *src && *src <= '9') - no = *src++ - '0'; - else - no = -1; - - if (no < 0) { /* Ordinary character. */ - if (c == '\\' && (*src == '\\' || *src == '&')) - c = *src++; - if (--n < 0) { /* amylaar */ - regerror("line too long"); - return NULL; - } - *dst++ = c; - } else if (prog->startp[no] != (char *)NULL && - prog->endp[no] != (char *)NULL) { - len = prog->endp[no] - prog->startp[no]; - if ( (n-=len) < 0 ) { /* amylaar */ - regerror("line too long"); - return NULL; - } - (void)strncpy(dst, prog->startp[no], len); - dst += len; - if (len != 0 && *(dst - 1) == '\0') { /* strncpy hit NUL. */ - regerror("damaged match string"); - return NULL; - } - } + if (c == '&') + no = 0; + else if (c == '\\' && '0' <= *src && *src <= '9') + no = *src++ - '0'; + else + no = -1; + + if (no < 0) { /* Ordinary character. */ + if (c == '\\' && (*src == '\\' || *src == '&')) + c = *src++; + if (--n < 0) { /* amylaar */ + regerror("line too long"); + return NULL; + } + *dst++ = c; + } else if (prog->startp[no] != (char *)NULL && + prog->endp[no] != (char *)NULL) { + len = prog->endp[no] - prog->startp[no]; + if ( (n-=len) < 0 ) { /* amylaar */ + regerror("line too long"); + return NULL; + } + (void)strncpy(dst, prog->startp[no], len); + dst += len; + if (len != 0 && *(dst - 1) == '\0') { /* strncpy hit NUL. */ + regerror("damaged match string"); + return NULL; + } + } } - if (--n < 0) { /* amylaar */ - regerror("line too long"); - return NULL; + if (--n < 0) { /* amylaar */ + regerror("line too long"); + return NULL; } *dst = '\0'; return dst; } -#if 0 /* Use the local regerror() in ed.c */ +#if 0 /* Use the local regerror() in ed.c */ void regerror(char *s) { diff --git a/regexp.h b/regexp.h index 6a89855..ff69b05 100644 --- a/regexp.h +++ b/regexp.h @@ -8,13 +8,13 @@ #define NSUBEXP 10 typedef struct regexp { - char *startp[NSUBEXP]; - char *endp[NSUBEXP]; - char regstart; /* Internal use only. */ - char reganch; /* Internal use only. */ - char *regmust; /* Internal use only. */ - int regmlen; /* Internal use only. */ - char program[1]; /* Unwarranted chumminess with compiler. */ + char *startp[NSUBEXP]; + char *endp[NSUBEXP]; + char regstart; /* Internal use only. */ + char reganch; /* Internal use only. */ + char *regmust; /* Internal use only. */ + int regmlen; /* Internal use only. */ + char program[1]; /* Unwarranted chumminess with compiler. */ } regexp; @@ -22,7 +22,7 @@ typedef struct regexp { * The first byte of the regexp internal "program" is actually this magic * number; the start node begins in the second byte. */ -#define MAGIC 0234 +#define MAGIC 0234 extern regexp *regcomp(char *, int); extern int regexec(regexp *, char *); diff --git a/regress/secure/auto.c b/regress/secure/auto.c index e5ec9bf..1c2e7b1 100644 --- a/regress/secure/auto.c +++ b/regress/secure/auto.c @@ -16,20 +16,20 @@ static string type_name(mixed etwas) { if (intp(etwas)) - return "int"; + return "int"; else if (floatp(etwas)) - return "float"; + return "float"; else if (stringp(etwas)) - return "string"; + return "string"; else if (objectp(etwas)) - return "object"; + return "object"; else if (pointerp(etwas)) - return "array"; + return "array"; else if (mappingp(etwas)) - return "mapping"; + return "mapping"; #ifdef _FUNCTION else if (functionp(etwas)) - return "function"; + return "function"; #endif return "!UNKNOWN!"; } @@ -44,29 +44,29 @@ dump_array(mixed a, string tab) { int n, m; - mixed ix, val; + mixed ix, val; if (!tab) - tab = ""; + tab = ""; if (!pointerp(a) && !mappingp(a)) { - dump_elem(a, tab); - return; + dump_elem(a, tab); + return; } else if (pointerp(a)) { - write("(Array)\n"); - m = sizeof(a); - n = 0; - while (n < m) - { - write(tab + "[" + n + "] ="); - dump_elem(a[n], tab); - n += 1; - } + write("(Array)\n"); + m = sizeof(a); + n = 0; + while (n < m) + { + write(tab + "[" + n + "] ="); + dump_elem(a[n], tab); + n += 1; + } } else /* Mappingp */ - dump_mapping(a, tab); + dump_mapping(a, tab); } /* @@ -82,68 +82,68 @@ dump_mapping(mapping m, string tab) string dval, val; if (!tab) - tab = ""; + tab = ""; d = m_indexes(m); s = sizeof(d); write("(Mapping) ([\n"); for(i = 0; i < s; i++) { - if (intp(d[i])) - dval = "(int)" + d[i]; + if (intp(d[i])) + dval = "(int)" + d[i]; - if (floatp(d[i])) - dval = "(float)" + ftoa(d[i]); + if (floatp(d[i])) + dval = "(float)" + ftoa(d[i]); - if (stringp(d[i])) - dval = "\"" + d[i] + "\""; + if (stringp(d[i])) + dval = "\"" + d[i] + "\""; - if (objectp(d[i])) - dval = file_name(d[i]); + if (objectp(d[i])) + dval = file_name(d[i]); - if (pointerp(d[i])) - dval = "(array:" + sizeof(d[i]) + ")"; + if (pointerp(d[i])) + dval = "(array:" + sizeof(d[i]) + ")"; - if (mappingp(d[i])) - dval = "(mapping:" + m_sizeof(d[i]) + ")"; + if (mappingp(d[i])) + dval = "(mapping:" + m_sizeof(d[i]) + ")"; #ifdef _FUNCTION - if (functionp(d[i])) - dval = sprintf("%O", d[i]); + if (functionp(d[i])) + dval = sprintf("%O", d[i]); - if (functionp(m[d[i]])) - val = sprintf("%O", m[d[i]]); + if (functionp(m[d[i]])) + val = sprintf("%O", m[d[i]]); #endif - - if (intp(m[d[i]])) - val = "(int)" + m[d[i]]; + + if (intp(m[d[i]])) + val = "(int)" + m[d[i]]; - if (floatp(m[d[i]])) - val = "(float)" + ftoa(m[d[i]]); + if (floatp(m[d[i]])) + val = "(float)" + ftoa(m[d[i]]); - if (stringp(m[d[i]])) - val = "\"" + m[d[i]] + "\""; + if (stringp(m[d[i]])) + val = "\"" + m[d[i]] + "\""; - if (objectp(m[d[i]])) - val = file_name(m[d[i]]); + if (objectp(m[d[i]])) + val = file_name(m[d[i]]); - if (pointerp(m[d[i]])) - val = "(array:" + sizeof(m[d[i]]) + ")"; + if (pointerp(m[d[i]])) + val = "(array:" + sizeof(m[d[i]]) + ")"; - if (mappingp(m[d[i]])) - val = "(mapping:" + m_sizeof(m[d[i]]) + ")"; + if (mappingp(m[d[i]])) + val = "(mapping:" + m_sizeof(m[d[i]]) + ")"; - write(tab + dval + ":" + val + "\n"); + write(tab + dval + ":" + val + "\n"); - if (pointerp(d[i])) - dump_array(d[i]); + if (pointerp(d[i])) + dump_array(d[i]); - if (pointerp(m[d[i]])) - dump_array(m[d[i]]); + if (pointerp(m[d[i]])) + dump_array(m[d[i]]); - if (mappingp(d[i])) - dump_mapping(d[i], tab + " "); + if (mappingp(d[i])) + dump_mapping(d[i], tab + " "); - if (mappingp(m[d[i]])) - dump_mapping(m[d[i]], tab + " "); + if (mappingp(m[d[i]])) + dump_mapping(m[d[i]], tab + " "); } write("])\n"); } @@ -153,21 +153,21 @@ dump_elem(mixed sak, string tab) { if (pointerp(sak)) { - dump_array(sak, tab + " "); + dump_array(sak, tab + " "); } else if (mappingp(sak)) { - dump_mapping(sak, tab + " "); + dump_mapping(sak, tab + " "); } else { - write("(" + type_name(sak) + ") "); - if (objectp(sak)) - write(file_name(sak)); - else if (floatp(sak)) - write(ftoa(sak)); - else - write(sprintf("%O",sak)); + write("(" + type_name(sak) + ") "); + if (objectp(sak)) + write(file_name(sak)); + else if (floatp(sak)) + write(ftoa(sak)); + else + write(sprintf("%O",sak)); } write("\n"); } @@ -250,16 +250,16 @@ int mkcompare_util(function f, mixed x, mixed y) { if (f(x,y)) - return -1; + return -1; if (f(y,x)) - return 1; + return 1; return 0; } /* * Function name: mkcompare * Description: takes a normal comparison function, like < and - * returns a function suitable for sort_array + * returns a function suitable for sort_array * Arguments: f: the function * Returns: another function */ diff --git a/regress/secure/simul_efun.c b/regress/secure/simul_efun.c index 0b456b8..1205286 100644 --- a/regress/secure/simul_efun.c +++ b/regress/secure/simul_efun.c @@ -9,9 +9,9 @@ varargs nomask mixed sort_array(mixed arr, mixed lfunc, object obj) { if (stringp(lfunc)) { - if (!obj) - obj = previous_object(); - lfunc = mkfunction(lfunc, obj); + if (!obj) + obj = previous_object(); + lfunc = mkfunction(lfunc, obj); } return sort(arr, lfunc); } diff --git a/regress/tests/test-001.c b/regress/tests/test-001.c index 3d6d50d..5396c0f 100644 --- a/regress/tests/test-001.c +++ b/regress/tests/test-001.c @@ -4,7 +4,7 @@ public int crashme(int num, int a, int b, int c, int d, int e, int f, int g, int h, int i) { if (num == 1) - return this_object()->crashme(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); + return this_object()->crashme(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); return 0; } diff --git a/regress/tests/test-002.c b/regress/tests/test-002.c index f964484..3b998c2 100644 --- a/regress/tests/test-002.c +++ b/regress/tests/test-002.c @@ -4,7 +4,7 @@ public int crashme(int num, int a, int b, int c, int d, int e, int f, int g, int h, int i) { if (num == 1) - return crashme(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); + return crashme(1, 1, 1, 1, 1, 1, 1, 1, 1, 1); return 0; } diff --git a/regress/tests/test-008.c b/regress/tests/test-008.c index 27a522f..6f2adff 100644 --- a/regress/tests/test-008.c +++ b/regress/tests/test-008.c @@ -4,5 +4,5 @@ void create() { if ((sprintf("%-4s", "x") + "x") != "x x") - throw("sprintf botch\n"); + throw("sprintf botch\n"); } diff --git a/regress/tests/test-009.c b/regress/tests/test-009.c index 827f5b4..64e6f6c 100644 --- a/regress/tests/test-009.c +++ b/regress/tests/test-009.c @@ -4,72 +4,72 @@ void create() { sprintf("%O", ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object(), - ({ "a", "b", 1, 2, this_object(), previous_object() - }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) - }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) - }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) - }) }) }) }) }) }) }) })); + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object(), + ({ "a", "b", 1, 2, this_object(), previous_object() + }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) + }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) + }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) }) + }) }) }) }) }) }) }) })); } diff --git a/regress/tests/test-010.c b/regress/tests/test-010.c index 0532a0a..14676e9 100644 --- a/regress/tests/test-010.c +++ b/regress/tests/test-010.c @@ -12,5 +12,5 @@ create() b[0] = b; if (a == b) - throw("Bad array handling\n"); + throw("Bad array handling\n"); } diff --git a/regress/tests/test-011.c b/regress/tests/test-011.c index 95fd14b..30ea016 100644 --- a/regress/tests/test-011.c +++ b/regress/tests/test-011.c @@ -11,8 +11,8 @@ create() int i; for (i = 0; i < 1024 ; i++) - if (set_alarm(120.0, 0.0, nothing) == 0) - break; + if (set_alarm(120.0, 0.0, nothing) == 0) + break; if (i == 1024) - throw("Driver compiled without per-object alarm limit\n"); + throw("Driver compiled without per-object alarm limit\n"); } diff --git a/regress/tests/test-013.c b/regress/tests/test-013.c index e1ada3e..e0ab219 100644 --- a/regress/tests/test-013.c +++ b/regress/tests/test-013.c @@ -6,7 +6,7 @@ create() int i, j, k; for (i = 0; i < 100000; i++) - for (j = 0; j < 100000; j++) - for (k = 0; k < 100000; k++) - ; + for (j = 0; j < 100000; j++) + for (k = 0; k < 100000; k++) + ; } diff --git a/regress/tests/test-015.c b/regress/tests/test-015.c index b247b58..63562f1 100644 --- a/regress/tests/test-015.c +++ b/regress/tests/test-015.c @@ -4,15 +4,15 @@ void create() { if (min(1, 2) != 1) - throw("min() does not work!\n"); + throw("min() does not work!\n"); if (min("a", "b") != "a") - throw("min() does not work!\n"); + throw("min() does not work!\n"); if (min(1.0, 2.0) > 1.1) - throw("min() does not work!\n"); + throw("min() does not work!\n"); if (max(1, 2) != 2) - throw("max() does not work!\n"); + throw("max() does not work!\n"); if (max("a", "b") != "b") - throw("max() does not work!\n"); + throw("max() does not work!\n"); if (max(1.0, 2.0) < 1.9) - throw("max() does not work!\n"); + throw("max() does not work!\n"); } diff --git a/regress/tests/test-016.c b/regress/tests/test-016.c index 9dcb3a5..7f99671 100644 --- a/regress/tests/test-016.c +++ b/regress/tests/test-016.c @@ -7,5 +7,5 @@ create() funp = this_object; if (!functionp(funp)) - throw("Bad functionp()\n"); + throw("Bad functionp()\n"); } diff --git a/regress/tests/test-017.c b/regress/tests/test-017.c index f7d0a27..340cc65 100644 --- a/regress/tests/test-017.c +++ b/regress/tests/test-017.c @@ -23,64 +23,64 @@ create() f5 = &ob->func() @ &func(); if (!functionp(f1)) - throw("parent functionp(&ob->func()) broken\n"); + throw("parent functionp(&ob->func()) broken\n"); if (!functionp(f2)) - throw("parent functionp(&ob->func(f1)) broken\n"); + throw("parent functionp(&ob->func(f1)) broken\n"); if (!functionp(f3)) - throw("parent functionp(mkfunction(\"func\", ob)) broken\n"); + throw("parent functionp(mkfunction(\"func\", ob)) broken\n"); if (!functionp(f4)) - throw("parent functionp(&func @ &ob->func()) broken\n"); + throw("parent functionp(&func @ &ob->func()) broken\n"); if (!functionp(f5)) - throw("parent functionp(&ob->func() @ &func()) broken\n"); + throw("parent functionp(&ob->func() @ &func()) broken\n"); if (!functionp(g1)) - throw("child functionp(&ob->func()) broken\n"); + throw("child functionp(&ob->func()) broken\n"); if (!functionp(g2)) - throw("child functionp(&ob->func(&func())) broken\n"); + throw("child functionp(&ob->func(&func())) broken\n"); if (!functionp(g3)) - throw("child functionp(mkfunction(\"func\", ob)) broken\n"); + throw("child functionp(mkfunction(\"func\", ob)) broken\n"); if (!functionp(g4)) - throw("child functionp(&func()) broken\n"); + throw("child functionp(&func()) broken\n"); if (!functionp(g5)) - throw("child functionp(&func(&func())) broken\n"); + throw("child functionp(&func(&func())) broken\n"); if (!functionp(g6)) - throw("child functionp(&file_name(this_object())) broken\n"); + throw("child functionp(&file_name(this_object())) broken\n"); if (!functionp(g7)) - throw("child functionp(&sin(10.0)) broken\n"); + throw("child functionp(&sin(10.0)) broken\n"); if (g6() != "/tests/functions#1") - throw("child &file_name(this_object()) evaluates wrong\n"); + throw("child &file_name(this_object()) evaluates wrong\n"); ob->remove_object(); if (functionp(f1)) - throw("parent functionp(&ob->func()) did not detect destructed object\n"); + throw("parent functionp(&ob->func()) did not detect destructed object\n"); if (functionp(f2)) - throw("parent functionp(&ob->func(f1)) did not detect destructed object\n"); + throw("parent functionp(&ob->func(f1)) did not detect destructed object\n"); if (functionp(f3)) - throw("parent functionp(mkfunction(\"func\", ob)) did not detect destructed object\n"); + throw("parent functionp(mkfunction(\"func\", ob)) did not detect destructed object\n"); if (functionp(f4)) - throw("parent functionp(&func() @ &ob->func()) did not detect destructed object\n"); + throw("parent functionp(&func() @ &ob->func()) did not detect destructed object\n"); if (functionp(f5)) - throw("parent functionp(&ob->func() @ &func()) did not detect destructed object\n"); + throw("parent functionp(&ob->func() @ &func()) did not detect destructed object\n"); if (functionp(g1)) - throw("child functionp(&ob->func()) did not detect destructed object\n"); + throw("child functionp(&ob->func()) did not detect destructed object\n"); if (functionp(g2)) - throw("child functionp(&ob->func(&func())) did not detect destructed object\n"); + throw("child functionp(&ob->func(&func())) did not detect destructed object\n"); if (functionp(g3)) - throw("child functionp(mkfunction(\"func\", ob)) did not detect destructed object\n"); + throw("child functionp(mkfunction(\"func\", ob)) did not detect destructed object\n"); if (functionp(g4)) - throw("child functionp(&func()) did not detect destructed object\n"); + throw("child functionp(&func()) did not detect destructed object\n"); if (functionp(g5)) - throw("child functionp(&func(&func())) did not detect destructed object\n"); + throw("child functionp(&func(&func())) did not detect destructed object\n"); if (!functionp(g6)) - throw("child functionp(&file_name(this_object())) was affected by destructed object\n"); + throw("child functionp(&file_name(this_object())) was affected by destructed object\n"); if (!functionp(g7)) - throw("child functionp(&sin(10.0)) was affected by destructed object\n"); + throw("child functionp(&sin(10.0)) was affected by destructed object\n"); } void set_funcs(function f1, function f2, function f3, function f4, - function f5, function f6, function f7) + function f5, function f6, function f7) { g1 = f1; g2 = f2; diff --git a/regress/tests/test-020.c b/regress/tests/test-020.c index 1d2db70..2c87a88 100644 --- a/regress/tests/test-020.c +++ b/regress/tests/test-020.c @@ -12,5 +12,5 @@ void create() { this_object()->test(); - test(); // Only this call crashes + test(); // Only this call crashes } diff --git a/regress/tests/test-021.c b/regress/tests/test-021.c index c194269..9f47123 100644 --- a/regress/tests/test-021.c +++ b/regress/tests/test-021.c @@ -4,7 +4,7 @@ int function_one(int arg) { if (arg != 0x1234) - throw("Bad argument!\n"); + throw("Bad argument!\n"); return 0x5678; } @@ -12,7 +12,7 @@ static int function_two(int arg) { if (arg != 0x1234) - throw("Bad argument!\n"); + throw("Bad argument!\n"); return 0x5678; } @@ -20,7 +20,7 @@ private int function_three(int arg) { if (arg != 0x1234) - throw("Bad argument!\n"); + throw("Bad argument!\n"); return 0x5678; } @@ -28,15 +28,15 @@ void create() { if (call_self("function_one", 0x1234) != 0x5678) - throw("Bad return value from call_self(\"function_one\", 0x1234)\n"); + throw("Bad return value from call_self(\"function_one\", 0x1234)\n"); if (call_self("function_two", 0x1234) != 0x5678) - throw("Bad return value from call_self(\"function_two\", 0x1234)\n"); + throw("Bad return value from call_self(\"function_two\", 0x1234)\n"); if (call_self("function_three", 0x1234) != 0x5678) - throw("Bad return value from call_self(\"function_three\", 0x1234)\n"); + throw("Bad return value from call_self(\"function_three\", 0x1234)\n"); if (call_selfv("function_one", ({ 0x1234 }) ) != 0x5678) - throw("Bad return value from call_selfv(\"function_one\", ({ 0x1234 }) )\n"); + throw("Bad return value from call_selfv(\"function_one\", ({ 0x1234 }) )\n"); if (call_selfv("function_two", ({ 0x1234 }) ) != 0x5678) - throw("Bad return value from call_selfv(\"function_two\", ({ 0x1234 }) )\n"); + throw("Bad return value from call_selfv(\"function_two\", ({ 0x1234 }) )\n"); if (call_selfv("function_three", ({ 0x1234 }) ) != 0x5678) - throw("Bad return value from call_selfv(\"function_three\", ({ 0x1234 }) )\n"); + throw("Bad return value from call_selfv(\"function_three\", ({ 0x1234 }) )\n"); } diff --git a/regress/tests/test-022.c b/regress/tests/test-022.c index e6dac4b..03a4fbc 100644 --- a/regress/tests/test-022.c +++ b/regress/tests/test-022.c @@ -8,7 +8,7 @@ create() a = 1 ?: 2; b = 0 ? 1 : 2; if (a != 1) - throw("Bad result from :? operation\n"); + throw("Bad result from :? operation\n"); if (b != 2) - throw("Bad result from :? operation\n"); + throw("Bad result from :? operation\n"); } diff --git a/regress/tests/test-024.c b/regress/tests/test-024.c index 3570107..7828bcc 100644 --- a/regress/tests/test-024.c +++ b/regress/tests/test-024.c @@ -7,5 +7,5 @@ create() parse_command("0", ({ this_object() }), "%i", obs); if (sizeof(obs)) - throw("parse_command botch\n"); + throw("parse_command botch\n"); } diff --git a/regress/tests/test-025.c b/regress/tests/test-025.c index 11d4d32..809a019 100644 --- a/regress/tests/test-025.c +++ b/regress/tests/test-025.c @@ -4,6 +4,6 @@ void create() { if (break_string("ab cd ef gh ij kl mn op qr", 8) != - "ab cd ef\ngh ij kl\nmn op qr") - throw("break_string inconsistant\n"); + "ab cd ef\ngh ij kl\nmn op qr") + throw("break_string inconsistant\n"); } diff --git a/sent.h b/sent.h index 73819f3..a835119 100644 --- a/sent.h +++ b/sent.h @@ -8,8 +8,8 @@ struct sentence { unsigned short short_verb; }; -#define V_SHORT 0x1 /* Only leading characters count */ -#define V_NO_SPACE 0x2 /* A space is not required */ +#define V_SHORT 0x1 /* Only leading characters count */ +#define V_NO_SPACE 0x2 /* A space is not required */ struct sentence *alloc_sentence(void); diff --git a/signals.c b/signals.c index 9d2e529..465ffd8 100644 --- a/signals.c +++ b/signals.c @@ -46,7 +46,7 @@ sig_handler(int sig) } for (i = 0; disp[i].sig && disp[i].sig != sig; i++) - ; + ; pending_signals |= 1 << i; } @@ -65,7 +65,7 @@ init_signals() act.sa_mask = sigs_to_block; act.sa_flags = SA_RESTART; for (i = 0; disp[i].sig; i++) - (void)sigaction(disp[i].sig, &act, NULL); + (void)sigaction(disp[i].sig, &act, NULL); } static struct task *signal_task; @@ -77,7 +77,7 @@ send_signals(void *x) sigprocmask(SIG_BLOCK, &sigs_to_block, NULL); for (i = 0; i < MAX_SIGNALS; i++) - if (pending_signals & (1 << i)) + if (pending_signals & (1 << i)) break; pending_signals &= ~(1 << i); diff --git a/simul_efun.c b/simul_efun.c index e49831e..ed834ff 100644 --- a/simul_efun.c +++ b/simul_efun.c @@ -38,13 +38,13 @@ get_simul_efun() f = fopen(SIMULFILE, "r"); if (f == 0) { - (void)fprintf(stderr, SIMULFILE " not found.\n"); - exit(1); + (void)fprintf(stderr, SIMULFILE " not found.\n"); + exit(1); } #if 1 init_smart_log(); start_new_file(f); - current_file = string_copy(SIMULFILE); /* This one is freed below */ + current_file = string_copy(SIMULFILE); /* This one is freed below */ current_loaded_file = SIMULFILE; compile_file(); end_new_file(); @@ -56,17 +56,17 @@ get_simul_efun() dump_smart_log(); if (inherit_file || num_parse_error > 0 || prog == 0) { - (void)fprintf(stderr, "Error in " SIMULFILE ".\n"); - return; + (void)fprintf(stderr, "Error in " SIMULFILE ".\n"); + return; } (void)fprintf(stderr,"%s loaded: %d functions\n", SIMULFILE, - prog->num_functions); + prog->num_functions); if (prog->num_functions == 0) - return; + return; /* - We make an object so that it can be updated. + We make an object so that it can be updated. */ ob = get_empty_object(); ob->name = string_copy("secure/simul_efun"); @@ -75,20 +75,20 @@ get_simul_efun() simul_efun_ob = ob; add_ref(ob, "simul_efun"); - enter_object_hash(ob); /* add name to fast object lookup table */ + enter_object_hash(ob); /* add name to fast object lookup table */ { - int num_var, i; - extern int tot_alloc_variable_size; + int num_var, i; + extern int tot_alloc_variable_size; - num_var = ob->prog->num_variables + ob->prog->inherit[ob->prog->num_inherited - 1].variable_index_offset; + num_var = ob->prog->num_variables + ob->prog->inherit[ob->prog->num_inherited - 1].variable_index_offset; - if (ob->variables) - fatal("Object already initialized!\n"); - - ob->variables = (struct svalue *)xalloc(num_var * sizeof(struct svalue)); - tot_alloc_variable_size += num_var * sizeof(struct svalue); - for (i = 0; i < num_var; i++) - ob->variables[i] = const0; + if (ob->variables) + fatal("Object already initialized!\n"); + + ob->variables = (struct svalue *)xalloc(num_var * sizeof(struct svalue)); + tot_alloc_variable_size += num_var * sizeof(struct svalue); + for (i = 0; i < num_var; i++) + ob->variables[i] = const0; } current_object = 0; #else diff --git a/simulate.c b/simulate.c index f5b2e19..22e4ba5 100644 --- a/simulate.c +++ b/simulate.c @@ -103,52 +103,52 @@ find_status(struct program *prog, char *str, int not_type) return -1; if (sub_name == (char *)2) { - for (i = 0; i < (int)prog->num_variables; i++) - { - if (prog->variable_names[i].name == real_name && - !(prog->variable_names[i].type & not_type)) - { - variable_index_found = i; - variable_inherit_found = prog->num_inherited - 1; - variable_type_mod_found = prog->variable_names[i].type; - return prog->inherit[variable_inherit_found].variable_index_offset + i; - } - } + for (i = 0; i < (int)prog->num_variables; i++) + { + if (prog->variable_names[i].name == real_name && + !(prog->variable_names[i].type & not_type)) + { + variable_index_found = i; + variable_inherit_found = prog->num_inherited - 1; + variable_type_mod_found = prog->variable_names[i].type; + return prog->inherit[variable_inherit_found].variable_index_offset + i; + } + } } else if (sub_name - str > 2) { - super_name = xalloc((size_t)(sub_name - str - 1)); - (void)memcpy(super_name, str, (size_t)(sub_name - str - 2)); - super_name[sub_name - str - 2] = 0; - if (strcmp(super_name, "this") == 0) - return find_status(prog, sub_name, not_type); + super_name = xalloc((size_t)(sub_name - str - 1)); + (void)memcpy(super_name, str, (size_t)(sub_name - str - 2)); + super_name[sub_name - str - 2] = 0; + if (strcmp(super_name, "this") == 0) + return find_status(prog, sub_name, not_type); } else - str = sub_name; + str = sub_name; for(j = prog->num_inherited - 2; j >= 0 ;j -= prog->inherit[j].prog->num_inherited) { - if (super_name && - strcmp(super_name, prog->inherit[j].name) == 0) - search = sub_name; - else - search = str; - if (find_status(prog->inherit[j].prog, search, not_type) != -1) - { - int type1 = prog->inherit[j].type; - if (variable_type_mod_found & TYPE_MOD_PUBLIC) - type1 &= ~TYPE_MOD_PRIVATE; - if (variable_type_mod_found & TYPE_MOD_PRIVATE) - type1 &= ~TYPE_MOD_PUBLIC; - variable_type_mod_found |= type1 & TYPE_MOD_MASK; - if (variable_type_mod_found & not_type) - continue; - - variable_inherit_found += j - - (prog->inherit[j].prog->num_inherited - 1); - return prog->inherit[variable_inherit_found].variable_index_offset + - variable_index_found; - } + if (super_name && + strcmp(super_name, prog->inherit[j].name) == 0) + search = sub_name; + else + search = str; + if (find_status(prog->inherit[j].prog, search, not_type) != -1) + { + int type1 = prog->inherit[j].type; + if (variable_type_mod_found & TYPE_MOD_PUBLIC) + type1 &= ~TYPE_MOD_PRIVATE; + if (variable_type_mod_found & TYPE_MOD_PRIVATE) + type1 &= ~TYPE_MOD_PUBLIC; + variable_type_mod_found |= type1 & TYPE_MOD_MASK; + if (variable_type_mod_found & not_type) + continue; + + variable_inherit_found += j - + (prog->inherit[j].prog->num_inherited - 1); + return prog->inherit[variable_inherit_found].variable_index_offset + + variable_index_found; + } } return -1; } @@ -213,28 +213,28 @@ load_object(char *lname, int dont_reset, struct object *old_ob, int depth) /* Truncate possible .c in the object name. */ /* Remove leading '/' if any. */ while(lname[0] == '/') - lname++; + lname++; (void)strncpy(name, lname, sizeof(name) - 1); name[sizeof name - 1] = '\0'; name_length = strlen(name); if (name_length > sizeof name - 4) - name_length = sizeof name - 4; + name_length = sizeof name - 4; name[name_length] = '\0'; while (name_length >= 2 && name[name_length-2] == '.' && name[name_length-1] == 'c') { - name[name_length-2] = '\0'; - name_length -= 2; + name[name_length-2] = '\0'; + name_length -= 2; } if (old_ob) { - struct object *invalid_ob; + struct object *invalid_ob; - (void)strcpy(new_ob_name, name); - (void)strcat(new_ob_name, "#0"); - if ( (invalid_ob = find_object2(new_ob_name)) != NULL ) - { - invalid_ob->prog->flags &= ~PRAGMA_RESIDENT; - destruct_object(invalid_ob); - } + (void)strcpy(new_ob_name, name); + (void)strcat(new_ob_name, "#0"); + if ( (invalid_ob = find_object2(new_ob_name)) != NULL ) + { + invalid_ob->prog->flags &= ~PRAGMA_RESIDENT; + destruct_object(invalid_ob); + } } /* @@ -246,54 +246,54 @@ load_object(char *lname, int dont_reset, struct object *old_ob, int depth) if (depth > MAX_INHERIT) { - (void)fprintf(stderr, "Inherit chain too long for %s\n", real_name); - error("Inherit chain too long: %s\n", real_name); - /* NOTREACHED */ + (void)fprintf(stderr, "Inherit chain too long for %s\n", real_name); + error("Inherit chain too long: %s\n", real_name); + /* NOTREACHED */ } if (stat(real_name, &c_st) == -1) { - (void)fprintf(stderr, "File not found: /%s\n", real_name); - error("File not found: /%s\n", real_name); - /* NOTREACHED */ + (void)fprintf(stderr, "File not found: /%s\n", real_name); + error("File not found: /%s\n", real_name); + /* NOTREACHED */ } /* * Check if it is a legal name. */ if (!legal_path(real_name)) { - (void)fprintf(stderr, "Illegal pathname: %s\n", real_name); - error("Illegal path name: %s\n", real_name); - /* NOTREACHED */ + (void)fprintf(stderr, "Illegal pathname: %s\n", real_name); + error("Illegal path name: %s\n", real_name); + /* NOTREACHED */ } if (comp_flag) - (void)fprintf(stderr, " compiling %s ...", real_name); + (void)fprintf(stderr, " compiling %s ...", real_name); f = fopen(real_name, "r"); if (s_flag) { - num_fileread++; - num_compile++; + num_fileread++; + num_compile++; } if (f == 0) { - perror(real_name); - error("Could not read the file: %s\n", real_name); - /* NOTREACHED */ + perror(real_name); + error("Could not read the file: %s\n", real_name); + /* NOTREACHED */ } init_smart_log(); start_new_file(f); - current_file = string_copy(real_name); /* This one is freed below */ + current_file = string_copy(real_name); /* This one is freed below */ current_loaded_file = real_name; compile_file(); end_new_file(); current_loaded_file = 0; if (comp_flag) { - if (inherit_file == 0) - (void)fprintf(stderr, " done\n"); - else - (void)fprintf(stderr, " suspended, compiling inherited file(s)\n"); + if (inherit_file == 0) + (void)fprintf(stderr, " done\n"); + else + (void)fprintf(stderr, " suspended, compiling inherited file(s)\n"); } update_compile_av(total_lines); total_lines = 0; @@ -305,15 +305,15 @@ load_object(char *lname, int dont_reset, struct object *old_ob, int depth) /* Sorry, can not handle objects without programs yet. */ if (inherit_file == 0 && (num_parse_error > 0 || prog == 0)) { - if (prog) - free_prog(prog); - if (num_parse_error == 0 && prog == 0) { - error("No program in object !\n"); - /* NOTREACHED */ - } - if (!old_ob) - error("Error in loading object\n"); - return 0; + if (prog) + free_prog(prog); + if (num_parse_error == 0 && prog == 0) { + error("No program in object !\n"); + /* NOTREACHED */ + } + if (!old_ob) + error("Error in loading object\n"); + return 0; } /* @@ -327,113 +327,113 @@ load_object(char *lname, int dont_reset, struct object *old_ob, int depth) /* Ensure inherit_file memory will be freed */ pool_track(&compilation_pool, inherit_file); - char *tmp = inherit_file; + char *tmp = inherit_file; - if (prog) - { - free_prog(prog); - prog = 0; - } + if (prog) { - char *t1 = tmp, *t2 = tmp + strlen(tmp); - while (*t1=='/') - t1++; - if (t2-t1 > 1) - if (*(--t2)=='c') - if (*(--t2)=='.') - *t2='\000'; - - if (strcmp(t1, name) == 0) - { - inherit_file = NULL; - error("Illegal to inherit self.\n"); - /* NOTREACHED */ - } - } - - /* Extreme ugliness begins. inherit_file must be 0 when we call - load_object, but tmp is used as a parameter, so we can not free - the string until after the call - */ - inherit_file = NULL; - load_object(tmp, 1, 0, depth + 1); - /* Extreme ugliness ends */ - - ob = load_object(name, dont_reset, old_ob, depth); - return ob; + free_prog(prog); + prog = 0; + } + { + char *t1 = tmp, *t2 = tmp + strlen(tmp); + while (*t1=='/') + t1++; + if (t2-t1 > 1) + if (*(--t2)=='c') + if (*(--t2)=='.') + *t2='\000'; + + if (strcmp(t1, name) == 0) + { + inherit_file = NULL; + error("Illegal to inherit self.\n"); + /* NOTREACHED */ + } + } + + /* Extreme ugliness begins. inherit_file must be 0 when we call + load_object, but tmp is used as a parameter, so we can not free + the string until after the call + */ + inherit_file = NULL; + load_object(tmp, 1, 0, depth + 1); + /* Extreme ugliness ends */ + + ob = load_object(name, dont_reset, old_ob, depth); + return ob; } ob = get_empty_object(); if (!old_ob) - ob->name = string_copy(name); /* Shared string is no good here */ + ob->name = string_copy(name); /* Shared string is no good here */ else { - ob->name = xalloc(strlen(name) + 3); - (void)strcpy(ob->name, name); - (void)strcat(ob->name, "#0"); + ob->name = xalloc(strlen(name) + 3); + (void)strcpy(ob->name, name); + (void)strcat(ob->name, "#0"); } ob->prog = prog; /* - add name to fast object lookup table + add name to fast object lookup table */ enter_object_hash(ob); { - int num_var, i; - extern int tot_alloc_variable_size; + int num_var, i; + extern int tot_alloc_variable_size; - num_var = ob->prog->num_variables + - ob->prog->inherit[ob->prog->num_inherited - 1] - .variable_index_offset; - if (ob->variables) - fatal("Object already initialized!\n"); + num_var = ob->prog->num_variables + + ob->prog->inherit[ob->prog->num_inherited - 1] + .variable_index_offset; + if (ob->variables) + fatal("Object already initialized!\n"); - ob->variables = (struct svalue *) xalloc(num_var * sizeof(struct svalue)); - tot_alloc_variable_size += num_var * sizeof(struct svalue); - for (i = 0; i < num_var; i++) - ob->variables[i] = const0; + ob->variables = (struct svalue *) xalloc(num_var * sizeof(struct svalue)); + tot_alloc_variable_size += num_var * sizeof(struct svalue); + for (i = 0; i < num_var; i++) + ob->variables[i] = const0; } /* - We ought to add a flag here marking the object as unfinished - so it can be removed if the following code causes an LPC error + We ought to add a flag here marking the object as unfinished + so it can be removed if the following code causes an LPC error */ if (master_ob) { - int save_resident; + int save_resident; - push_object(current_object); - push_object(ob); - save_resident = ob->prog->flags & PRAGMA_RESIDENT; - ob->prog->flags &= ~PRAGMA_RESIDENT; + push_object(current_object); + push_object(ob); + save_resident = ob->prog->flags & PRAGMA_RESIDENT; + ob->prog->flags &= ~PRAGMA_RESIDENT; - apply_master_ob(M_LOADED_OBJECT, 2); + apply_master_ob(M_LOADED_OBJECT, 2); - if ((ob->flags & O_DESTRUCTED) == 0) - ob->prog->flags |= save_resident; + if ((ob->flags & O_DESTRUCTED) == 0) + ob->prog->flags |= save_resident; } if (!(ob->flags & (O_CREATED | O_DESTRUCTED)) && !dont_reset) - create_object(ob); + create_object(ob); if (ob->flags & O_DESTRUCTED) - return 0; + return 0; command_giver = save_command_giver; if (d_flag & DEBUG_LOAD && ob) - debug_message("--%s loaded\n", ob->name); + debug_message("--%s loaded\n", ob->name); if (master_ob && (ob->prog->flags & PRAGMA_RESIDENT)) { - struct svalue *ret; - push_object(ob); - ret = apply_master_ob(M_VALID_RESIDENT, 1); - if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) - ob->prog->flags &= ~PRAGMA_RESIDENT; + struct svalue *ret; + push_object(ob); + ret = apply_master_ob(M_VALID_RESIDENT, 1); + if (ret && (ret->type != T_NUMBER || ret->u.number == 0)) + ob->prog->flags &= ~PRAGMA_RESIDENT; } if (!depth) { - pool_free(&compilation_pool); + pool_free(&compilation_pool); } return ob; @@ -463,8 +463,8 @@ clone_object(char *str1) ob = find_object_no_create(str1); if (ob == 0 || ob->super || (ob->flags & O_CLONE) || ob->prog->flags & PRAGMA_NO_CLONE) { - error("Cloning a bad object! (No Master, Master in environment or Master is clone)\n"); - /* NOTREACHED */ + error("Cloning a bad object! (No Master, Master in environment or Master is clone)\n"); + /* NOTREACHED */ } /* We do not want the heart beat to be running for unused copied objects */ @@ -475,42 +475,42 @@ clone_object(char *str1) new_ob->flags |= O_CLONE; new_ob->prog = ob->prog; reference_prog (ob->prog, "clone_object"); - enter_object_hash(new_ob); /* Add name to fast object lookup table */ + enter_object_hash(new_ob); /* Add name to fast object lookup table */ if (!current_object) - fatal("clone_object() from no current_object !\n"); + fatal("clone_object() from no current_object !\n"); { - int num_var, i; - extern int tot_alloc_variable_size; + int num_var, i; + extern int tot_alloc_variable_size; - num_var = new_ob->prog->num_variables + - new_ob->prog->inherit[ob->prog->num_inherited - 1] - .variable_index_offset; - if (new_ob->variables) - fatal("Object already initialized!\n"); + num_var = new_ob->prog->num_variables + + new_ob->prog->inherit[ob->prog->num_inherited - 1] + .variable_index_offset; + if (new_ob->variables) + fatal("Object already initialized!\n"); - new_ob->variables = (struct svalue *) - xalloc(num_var * sizeof(struct svalue)); - tot_alloc_variable_size += num_var * sizeof(struct svalue); - for (i = 0; i < num_var; i++) - new_ob->variables[i] = const0; + new_ob->variables = (struct svalue *) + xalloc(num_var * sizeof(struct svalue)); + tot_alloc_variable_size += num_var * sizeof(struct svalue); + for (i = 0; i < num_var; i++) + new_ob->variables[i] = const0; } if (master_ob) { - push_object(current_object); - push_object(new_ob); - apply_master_ob(M_CLONED_OBJECT, 2); + push_object(current_object); + push_object(new_ob); + apply_master_ob(M_CLONED_OBJECT, 2); - if (new_ob->flags & O_DESTRUCTED) - return 0; + if (new_ob->flags & O_DESTRUCTED) + return 0; } if (!(ob->flags & O_CREATED)) - create_object(new_ob); + create_object(new_ob); command_giver = save_command_giver; /* Never know what can happen ! :-( */ if (new_ob->flags & O_DESTRUCTED) - return 0; + return 0; return new_ob; } @@ -520,14 +520,14 @@ environment(struct svalue *arg) struct object *ob = current_object; if (arg && arg->type == T_OBJECT) - ob = arg->u.ob; + ob = arg->u.ob; else if (arg && arg->type == T_STRING) - ob = find_object2(arg->u.string); + ob = find_object2(arg->u.string); if (ob == 0 || ob->super == 0 || (ob->flags & O_DESTRUCTED)) - return 0; + return 0; if (ob->flags & O_DESTRUCTED) { - error("environment() off destructed object.\n"); - /* NOTREACHED */ + error("environment() off destructed object.\n"); + /* NOTREACHED */ } return ob->super; } @@ -549,19 +549,19 @@ command_for_object(char *str, struct object *ob) int save_eval_cost = eval_cost - 1000; if (strlen(str) > sizeof(buff) - 1) { - error("Too long command.\n"); - /* NOTREACHED */ + error("Too long command.\n"); + /* NOTREACHED */ } if (ob == 0) - ob = current_object; + ob = current_object; else if (ob->flags & O_DESTRUCTED) - return 0; + return 0; (void)strncpy(buff, str, sizeof buff); buff[sizeof buff - 1] = '\0'; if (parse_command(buff, ob)) - return eval_cost - save_eval_cost; + return eval_cost - save_eval_cost; else - return 0; + return 0; } /* @@ -575,49 +575,49 @@ object_present(struct svalue *v, struct svalue *where) struct object *ret; if (v->type == T_OBJECT) - if (v->u.ob->flags & O_DESTRUCTED) - return 0; + if (v->u.ob->flags & O_DESTRUCTED) + return 0; switch (where->type) { case T_OBJECT: - if (where->u.ob->flags & O_DESTRUCTED) - break; - - if (v->type == T_OBJECT) - { - if (v->u.ob->super == where->u.ob) - return v->u.ob; - else - break; - } - else - return object_present2(v->u.string, where->u.ob->contains); + if (where->u.ob->flags & O_DESTRUCTED) + break; + + if (v->type == T_OBJECT) + { + if (v->u.ob->super == where->u.ob) + return v->u.ob; + else + break; + } + else + return object_present2(v->u.string, where->u.ob->contains); case T_POINTER: - if (v->type == T_OBJECT) - { - for (i = 0 ; i < where->u.vec->size ; i++) - { - if (where->u.vec->item[i].type != T_OBJECT) - continue; - if (v->u.ob->super == where->u.vec->item[i].u.ob) - return v->u.ob; - } - } - else - { - for (i = 0 ; i < where->u.vec->size ; i++) - { - if (where->u.vec->item[i].type != T_OBJECT) - continue; - if ((ret = object_present2(v->u.string, where->u.vec->item[i].u.ob->contains)) != NULL) - return ret; - } - } - break; + if (v->type == T_OBJECT) + { + for (i = 0 ; i < where->u.vec->size ; i++) + { + if (where->u.vec->item[i].type != T_OBJECT) + continue; + if (v->u.ob->super == where->u.vec->item[i].u.ob) + return v->u.ob; + } + } + else + { + for (i = 0 ; i < where->u.vec->size ; i++) + { + if (where->u.vec->item[i].type != T_OBJECT) + continue; + if ((ret = object_present2(v->u.string, where->u.vec->item[i].u.ob->contains)) != NULL) + return ret; + } + } + break; default: - error("Strange type %d in object_present.\n", where->type); - /* NOTREACHED */ + error("Strange type %d in object_present.\n", where->type); + /* NOTREACHED */ } return 0; } @@ -635,30 +635,30 @@ object_present2(char *str, struct object *ob) p = item + length - 1; if (*p >= '0' && *p <= '9') { - while(p > item && *p >= '0' && *p <= '9') - p--; - if (p > item && *p == ' ') - { - count = atoi(p+1) - 1; - *p = '\0'; - length = p - item; /* This is never used again ! */ - } + while(p > item && *p >= '0' && *p <= '9') + p--; + if (p > item && *p == ' ') + { + count = atoi(p+1) - 1; + *p = '\0'; + length = p - item; /* This is never used again ! */ + } } for (; ob; ob = ob->next_inv) { - push_string(item, STRING_MSTRING); - ret = apply("id", ob, 1, 1); - if (ob->flags & O_DESTRUCTED) - { - free(item); - return 0; - } - if (ret == 0 || (ret->type == T_NUMBER && ret->u.number == 0)) - continue; - if (count-- > 0) - continue; - free(item); - return ob; + push_string(item, STRING_MSTRING); + ret = apply("id", ob, 1, 1); + if (ob->flags & O_DESTRUCTED) + { + free(item); + return 0; + } + if (ret == 0 || (ret->type == T_NUMBER && ret->u.number == 0)) + continue; + if (count-- > 0) + continue; + free(item); + return ob; } free(item); return 0; @@ -680,40 +680,40 @@ destruct_object(struct object *ob) int si, i; if (ob == NULL || (ob->flags & O_DESTRUCTED)) - return; + return; /* * If we are to destruct the master ob or the simul_efun ob * it must be reloadable. */ if ( (!(ob->flags & O_CLONE) && (ob->prog->flags & PRAGMA_RESIDENT)) || - ob == auto_ob || ob == master_ob || ob == simul_efun_ob) - { - struct object *new_ob; - new_ob = load_object(ob->name, 1, ob, 0); - if (!new_ob) { - error("Can not compile the new %s, aborting destruction of the old.\n", ob->prog->name); - /* NOTREACHED */ - } - - /* Make sure that the master object and the simul_efun object - * stays loaded */ - if (ob == master_ob || ob == auto_ob || - ob == simul_efun_ob) - ob->prog->flags |= PRAGMA_RESIDENT; - - swap_objects(ob, new_ob); - if (ob == master_ob) - { + ob == auto_ob || ob == master_ob || ob == simul_efun_ob) + { + struct object *new_ob; + new_ob = load_object(ob->name, 1, ob, 0); + if (!new_ob) { + error("Can not compile the new %s, aborting destruction of the old.\n", ob->prog->name); + /* NOTREACHED */ + } + + /* Make sure that the master object and the simul_efun object + * stays loaded */ + if (ob == master_ob || ob == auto_ob || + ob == simul_efun_ob) + ob->prog->flags |= PRAGMA_RESIDENT; + + swap_objects(ob, new_ob); + if (ob == master_ob) + { resolve_master_fkntab(); - } + } /* Keep a reference that will be freed in the event of an exception */ push_object(new_ob); push_object(ob); - if (new_ob && new_ob->flags & O_CREATED) - recreate_object(ob, new_ob); + if (new_ob && new_ob->flags & O_CREATED) + recreate_object(ob, new_ob); if (ob == master_ob) { load_parse_information(); } @@ -723,8 +723,8 @@ destruct_object(struct object *ob) return; } pop_stack(); /* new_ob */ - ob = new_ob; - ob->prog->flags &= ~PRAGMA_RESIDENT; + ob = new_ob; + ob->prog->flags &= ~PRAGMA_RESIDENT; } @@ -737,86 +737,86 @@ destruct_object(struct object *ob) */ if (ob->shadowed && !ob->shadowing) { - struct svalue svp; - struct object *ob2; - - svp.type = T_OBJECT; - for (ob2 = ob->shadowed; ob2; ) - { - svp.u.ob = ob2; - ob2 = ob2->shadowed; - if (svp.u.ob->shadowed) { - free_object(svp.u.ob->shadowed, "destruct_object-5"); - svp.u.ob->shadowed = 0; - } - if (svp.u.ob->shadowing) { - free_object(svp.u.ob->shadowing, "destruct_object-6"); - svp.u.ob->shadowing = 0; - } - destruct_object(ob2); - if (ob->flags & O_DESTRUCTED) return; - } + struct svalue svp; + struct object *ob2; + + svp.type = T_OBJECT; + for (ob2 = ob->shadowed; ob2; ) + { + svp.u.ob = ob2; + ob2 = ob2->shadowed; + if (svp.u.ob->shadowed) { + free_object(svp.u.ob->shadowed, "destruct_object-5"); + svp.u.ob->shadowed = 0; + } + if (svp.u.ob->shadowing) { + free_object(svp.u.ob->shadowing, "destruct_object-6"); + svp.u.ob->shadowing = 0; + } + destruct_object(ob2); + if (ob->flags & O_DESTRUCTED) return; + } } /* * The chain of shadows is a double linked list. Take care to update * it correctly. */ if (ob->shadowing) { - change_ref(ob->shadowing->shadowed, ob->shadowed, "destruct_object-1"); - ob->shadowing->shadowed = ob->shadowed; + change_ref(ob->shadowing->shadowed, ob->shadowed, "destruct_object-1"); + ob->shadowing->shadowed = ob->shadowed; } if (ob->shadowed) { - change_ref(ob->shadowed->shadowing, ob->shadowing, "destruct_object-2"); - ob->shadowed->shadowing = ob->shadowing; + change_ref(ob->shadowed->shadowing, ob->shadowing, "destruct_object-2"); + ob->shadowed->shadowing = ob->shadowing; } if (ob->shadowing) { free_object(ob->shadowing, "destruct_object-3"); - ob->shadowing = 0; + ob->shadowing = 0; } if (ob->shadowed) { free_object(ob->shadowed, "destruct_object-4"); - ob->shadowed = 0; + ob->shadowed = 0; } if (d_flag & DEBUG_DESTRUCT) - debug_message("Destruct object %s (ref %d)\n", ob->name, ob->ref); + debug_message("Destruct object %s (ref %d)\n", ob->name, ob->ref); /* * There is nowhere to move the objects. */ { - struct svalue svp; - svp.type = T_OBJECT; - while(ob->contains) - { - svp.u.ob = ob->contains; - push_object(ob->contains); - /* An error here will not leave destruct() in an inconsistent - * stage. - */ - (void)apply_master_ob(M_DESTRUCT_ENVIRONMENT_OF,1); - if (ob->flags & O_DESTRUCTED) return; - if (svp.u.ob == ob->contains) - destruct_object(ob->contains); - if (ob->flags & O_DESTRUCTED) return; - } + struct svalue svp; + svp.type = T_OBJECT; + while(ob->contains) + { + svp.u.ob = ob->contains; + push_object(ob->contains); + /* An error here will not leave destruct() in an inconsistent + * stage. + */ + (void)apply_master_ob(M_DESTRUCT_ENVIRONMENT_OF,1); + if (ob->flags & O_DESTRUCTED) return; + if (svp.u.ob == ob->contains) + destruct_object(ob->contains); + if (ob->flags & O_DESTRUCTED) return; + } } if (ob->interactive) { - struct object *save=command_giver; + struct object *save=command_giver; - command_giver=ob; - if (ob->interactive->ed_buffer) - { - extern void save_ed_buffer(void); + command_giver=ob; + if (ob->interactive->ed_buffer) + { + extern void save_ed_buffer(void); - save_ed_buffer(); - } - command_giver=save; - remove_interactive(ob->interactive, 0); - if (ob->flags & O_DESTRUCTED) return; + save_ed_buffer(); + } + command_giver=save; + remove_interactive(ob->interactive, 0); + if (ob->flags & O_DESTRUCTED) return; } /* @@ -824,17 +824,17 @@ destruct_object(struct object *ob) * Remove all sentences defined by this object from all objects here. */ if (ob->super) { - if (ob->super->flags & O_ENABLE_COMMANDS) - remove_sent(ob, ob->super); - for (pp = &ob->super->contains; *pp; ) - { - if ((*pp)->flags & O_ENABLE_COMMANDS) - remove_sent(ob, *pp); - if (*pp != ob) - pp = &(*pp)->next_inv; - else - *pp = (*pp)->next_inv; - } + if (ob->super->flags & O_ENABLE_COMMANDS) + remove_sent(ob, ob->super); + for (pp = &ob->super->contains; *pp; ) + { + if ((*pp)->flags & O_ENABLE_COMMANDS) + remove_sent(ob, *pp); + if (*pp != ob) + pp = &(*pp)->next_inv; + else + *pp = (*pp)->next_inv; + } } exception_frame.e_exception = NULL; @@ -843,43 +843,43 @@ destruct_object(struct object *ob) /* Call destructors */ if (ob->flags & O_CREATED) { - for (i = ob->prog->num_inherited - 1; i >= 0; i--) - if (!(ob->prog->inherit[i].type & TYPE_MOD_SECOND) && - ob->prog->inherit[i].prog->dtor_index != - (unsigned short) -1) - { - push_pop_error_context(1); - - /* - * The following assignments between i & si and - * ob & sob might seem unneccecary, but some - * compilers requires this to ensure correct - * operation with setjmp/longjmp. - */ - si = i; - sob = ob; - if (setjmp(exception_frame.e_context)) - { - i = si; - ob = sob; - push_pop_error_context(-1); - exception = exception_frame.e_exception; - } - else - { - i = si; - ob = sob; - exception_frame.e_exception = exception; - exception = &exception_frame; - call_function(ob, i, - (unsigned int)ob->prog->inherit[i].prog->dtor_index, 0); - push_pop_error_context(-1); - exception = exception_frame.e_exception; - - if (ob->flags & O_DESTRUCTED) - return; - } - } + for (i = ob->prog->num_inherited - 1; i >= 0; i--) + if (!(ob->prog->inherit[i].type & TYPE_MOD_SECOND) && + ob->prog->inherit[i].prog->dtor_index != + (unsigned short) -1) + { + push_pop_error_context(1); + + /* + * The following assignments between i & si and + * ob & sob might seem unneccecary, but some + * compilers requires this to ensure correct + * operation with setjmp/longjmp. + */ + si = i; + sob = ob; + if (setjmp(exception_frame.e_context)) + { + i = si; + ob = sob; + push_pop_error_context(-1); + exception = exception_frame.e_exception; + } + else + { + i = si; + ob = sob; + exception_frame.e_exception = exception; + exception = &exception_frame; + call_function(ob, i, + (unsigned int)ob->prog->inherit[i].prog->dtor_index, 0); + push_pop_error_context(-1); + exception = exception_frame.e_exception; + + if (ob->flags & O_DESTRUCTED) + return; + } + } } remove_object_from_stack(ob); @@ -894,7 +894,7 @@ destruct_object(struct object *ob) remove_task(ob->callout_task); delete_all_calls(ob); if (ob->living_name) - remove_living_name(ob); + remove_living_name(ob); ob->super = 0; ob->next_inv = 0; ob->contains = 0; @@ -907,14 +907,14 @@ destruct_object(struct object *ob) tot_alloc_dest_object++; if (ob == vbfc_object) { - free_object(vbfc_object, "destruct_object"); - vbfc_object = 0; - ret = apply_master_ob(M_GET_VBFC_OBJECT, 0); - if (ret && ret->type == T_OBJECT) - { - vbfc_object = ret->u.ob; - INCREF(vbfc_object->ref); - } + free_object(vbfc_object, "destruct_object"); + vbfc_object = 0; + ret = apply_master_ob(M_GET_VBFC_OBJECT, 0); + if (ret && ret->type == T_OBJECT) + { + vbfc_object = ret->u.ob; + INCREF(vbfc_object->ref); + } } } /* @@ -928,10 +928,10 @@ destruct2(struct object *ob) extern int tot_alloc_variable_size; if (d_flag & DEBUG_DESTRUCT) - debug_message("Destruct-2 object %s (ref %d)\n", ob->name, ob->ref); + debug_message("Destruct-2 object %s (ref %d)\n", ob->name, ob->ref); if (ob->interactive) - remove_interactive(ob->interactive, 0); + remove_interactive(ob->interactive, 0); /* * We must deallocate variables here, not in 'free_object()'. @@ -943,22 +943,22 @@ destruct2(struct object *ob) * execute, change string and object variables into the number 0. */ { - /* - * Deallocate variables in this object. - */ - int i; - num_var = ob->prog->num_variables + - ob->prog->inherit[ob->prog->num_inherited - 1]. - variable_index_offset; - - for (i = 0; i < num_var; i++) { - free_svalue(&ob->variables[i]); - ob->variables[i].type = T_NUMBER; - ob->variables[i].u.number = 0; - } - free((char *)(ob->variables)); - ob->variables = NULL; - tot_alloc_variable_size -= num_var * sizeof(struct svalue); + /* + * Deallocate variables in this object. + */ + int i; + num_var = ob->prog->num_variables + + ob->prog->inherit[ob->prog->num_inherited - 1]. + variable_index_offset; + + for (i = 0; i < num_var; i++) { + free_svalue(&ob->variables[i]); + ob->variables[i].type = T_NUMBER; + ob->variables[i].u.number = 0; + } + free((char *)(ob->variables)); + ob->variables = NULL; + tot_alloc_variable_size -= num_var * sizeof(struct svalue); } free_svalue(&ob->auth); @@ -967,10 +967,10 @@ destruct2(struct object *ob) for (s = ob->sent; s;) { - struct sentence *next; - next = s->next; - free_sentence(s); - s = next; + struct sentence *next; + next = s->next; + free_sentence(s); + s = next; } delete_all_calls(ob); free_object(ob, "destruct_object"); @@ -987,22 +987,22 @@ void enable_commands(int num) { if (current_object->flags & O_DESTRUCTED) - return; + return; if (d_flag & DEBUG_LIVING) { - debug_message("Enable commands %s (ref %d)\n", - current_object->name, current_object->ref); + debug_message("Enable commands %s (ref %d)\n", + current_object->name, current_object->ref); } if (num) { - current_object->flags |= O_ENABLE_COMMANDS; - command_giver = current_object; + current_object->flags |= O_ENABLE_COMMANDS; + command_giver = current_object; } else { - current_object->flags &= ~O_ENABLE_COMMANDS; - if (command_giver == current_object) - command_giver = 0; + current_object->flags &= ~O_ENABLE_COMMANDS; + if (command_giver == current_object) + command_giver = 0; } } @@ -1016,16 +1016,16 @@ input_to(struct closure *fun, int flag) struct sentence *s; if (!command_giver || command_giver->flags & O_DESTRUCTED) - return 0; + return 0; s = alloc_sentence(); if (set_call(command_giver, s, flag)) { - s->funct = fun; - INCREF(fun->ref); - return 1; + s->funct = fun; + INCREF(fun->ref); + return 1; } else { - free_sentence(s); - return 0; + free_sentence(s); + return 0; } } @@ -1038,7 +1038,7 @@ int pstrcmp(const void *p1, const void *p2) { return strcmp(((const struct svalue *) p1)->u.string, - ((const struct svalue *) p2)->u.string); + ((const struct svalue *) p2)->u.string); } /* @@ -1071,12 +1071,12 @@ get_dir(char *path) char *regexp = 0; if (!path) - return 0; + return 0; path = check_valid_path(path, current_object, "get_dir", 0); if (path == 0) - return 0; + return 0; /* * We need to modify the returned path, and thus to make a @@ -1085,65 +1085,65 @@ get_dir(char *path) */ temppath = (char *) tmpalloc(strlen(path) + 2); if (strlen(path)<2) { - temppath[0] = path[0] ? path[0] : '.'; - temppath[1] = '\000'; - p = temppath; + temppath[0] = path[0] ? path[0] : '.'; + temppath[1] = '\000'; + p = temppath; } else { - (void)strcpy(temppath, path); - /* - * If path ends with '/' or "/." remove it - */ - if ((p = strrchr(temppath, '/')) == 0) - p = temppath; - if ((p[0] == '/' && p[1] == '.' && p[2] == '\0') || - (p[0] == '/' && p[1] == '\0')) - *p = '\0'; + (void)strcpy(temppath, path); + /* + * If path ends with '/' or "/." remove it + */ + if ((p = strrchr(temppath, '/')) == 0) + p = temppath; + if ((p[0] == '/' && p[1] == '.' && p[2] == '\0') || + (p[0] == '/' && p[1] == '\0')) + *p = '\0'; } if (stat(temppath, &st) < 0) { - if (*p == '\0') - return 0; - regexp = (char *)tmpalloc(strlen(p)+2); - if (p != temppath) - { - (void)strcpy(regexp, p + 1); - *p = '\0'; - } - else - { - (void)strcpy(regexp, p); - (void)strcpy(temppath, "."); - } - do_match = 1; + if (*p == '\0') + return 0; + regexp = (char *)tmpalloc(strlen(p)+2); + if (p != temppath) + { + (void)strcpy(regexp, p + 1); + *p = '\0'; + } + else + { + (void)strcpy(regexp, p); + (void)strcpy(temppath, "."); + } + do_match = 1; } else if (*p != '\0' && strcmp(temppath, ".")) { - if (*p == '/' && *(p + 1) != '\0') - p++; - v = allocate_array(1); - v->item[0].type = T_STRING; - v->item[0].string_type = STRING_MSTRING; - v->item[0].u.string = make_mstring(p); - return v; + if (*p == '/' && *(p + 1) != '\0') + p++; + v = allocate_array(1); + v->item[0].type = T_STRING; + v->item[0].string_type = STRING_MSTRING; + v->item[0].u.string = make_mstring(p); + return v; } if ((dirp = opendir(temppath)) == 0) - return 0; + return 0; /* * Count files */ for (de = readdir(dirp); de; de = readdir(dirp)) { - if (!do_match && (strcmp(de->d_name, ".") == 0 || - strcmp(de->d_name, "..") == 0)) - continue; - if (do_match && !match_string(regexp, de->d_name)) - continue; - count++; - if (count >= MAX_ARRAY_SIZE) - break; + if (!do_match && (strcmp(de->d_name, ".") == 0 || + strcmp(de->d_name, "..") == 0)) + continue; + if (do_match && !match_string(regexp, de->d_name)) + continue; + count++; + if (count >= MAX_ARRAY_SIZE) + break; } /* * Make array and put files on it. @@ -1151,24 +1151,24 @@ get_dir(char *path) v = allocate_array((int)count); if (count == 0) { - /* This is the easy case */ - (void)closedir(dirp); - return v; + /* This is the easy case */ + (void)closedir(dirp); + return v; } rewinddir(dirp); for(i = 0, de = readdir(dirp); i < count; de = readdir(dirp)) { namelen = strlen(de->d_name); - if (!do_match && (strcmp(de->d_name, ".") == 0 || - strcmp(de->d_name, "..") == 0)) - continue; - if (do_match && !match_string(regexp, de->d_name)) - continue; - de->d_name[namelen] = '\0'; - v->item[i].type = T_STRING; - v->item[i].string_type = STRING_MSTRING; - v->item[i].u.string = make_mstring(de->d_name); - i++; + if (!do_match && (strcmp(de->d_name, ".") == 0 || + strcmp(de->d_name, "..") == 0)) + continue; + if (do_match && !match_string(regexp, de->d_name)) + continue; + de->d_name[namelen] = '\0'; + v->item[i].type = T_STRING; + v->item[i].string_type = STRING_MSTRING; + v->item[i].u.string = make_mstring(de->d_name); + i++; } (void)closedir(dirp); /* Sort the names. */ @@ -1190,22 +1190,22 @@ tail(char *path) return 0; f = fopen(path, "r"); if (s_flag) - num_fileread++; + num_fileread++; if (f == 0) - return 0; + return 0; if (fstat(fileno(f), &st) == -1) - fatal("Could not stat an open file.\n"); + fatal("Could not stat an open file.\n"); offset = st.st_size - 54 * 20; if (offset < 0) - offset = 0; + offset = 0; if (fseek(f, (long) offset, 0) == -1) - fatal("Could not seek.\n"); + fatal("Could not seek.\n"); /* Throw away the first incomplete line. */ if (offset > 0) - (void) fgets(buff, sizeof buff, f); + (void) fgets(buff, sizeof buff, f); while(fgets(buff, sizeof buff, f)) - (void)add_message("%s", buff); + (void)add_message("%s", buff); (void)fclose(f); return 1; } @@ -1235,13 +1235,13 @@ find_object(char *str) /* Remove leading '/' if any. */ while(str[0] == '/') - str++; + str++; ob = find_object2(str); if (ob) - return ob; + return ob; ob = load_object(str, 0, 0, 0); - if (!ob || (ob->flags & O_DESTRUCTED)) /* *sigh* */ - return 0; + if (!ob || (ob->flags & O_DESTRUCTED)) /* *sigh* */ + return 0; return ob; } @@ -1253,13 +1253,13 @@ struct object *find_object_no_create(str) /* Remove leading '/' if any. */ while(str[0] == '/') - str++; + str++; ob = find_object2(str); if (ob) - return ob; + return ob; ob = load_object(str, 1, 0, 0); - if (!ob || (ob->flags & O_DESTRUCTED)) /* *sigh* */ - return 0; + if (!ob || (ob->flags & O_DESTRUCTED)) /* *sigh* */ + return 0; return ob; } @@ -1271,7 +1271,7 @@ find_object2(char *str) /* Remove leading '/' if any. */ while(str[0] == '/') - str++; + str++; /* Truncate possible .c in the object name. */ size_t length = strlen(str); size_t tail = length; @@ -1282,14 +1282,14 @@ find_object2(char *str) if (tail != length) { - char *p = (char *)tmpalloc(tail + 1); - strncpy(p, str, tail + 1); - p[tail] = '\0'; - str = p; + char *p = (char *)tmpalloc(tail + 1); + strncpy(p, str, tail + 1); + p[tail] = '\0'; + str = p; } if ((ob = lookup_object_hash(str)) != NULL) { - return ob; + return ob; } return 0; } @@ -1302,22 +1302,22 @@ apply_command(char *com) struct value *ret; if (command_giver == 0) { - error("command_giver == 0 !\n"); - /* NOTREACHED */ + error("command_giver == 0 !\n"); + /* NOTREACHED */ } ret = apply(com, command_giver->super, 0, 1); if (ret != 0) { - (void)add_message("Result:"); - if (ret->type == T_STRING) - (void)add_message("%s\n", ret->u.string); - if (ret->type == T_NUMBER) - (void)add_message("%lld\n", ret->u.number); - if (ret->type == T_FLOAT) - (void)add_message("%.18Lg\n", ret->u.real); + (void)add_message("Result:"); + if (ret->type == T_STRING) + (void)add_message("%s\n", ret->u.string); + if (ret->type == T_NUMBER) + (void)add_message("%lld\n", ret->u.number); + if (ret->type == T_FLOAT) + (void)add_message("%.18Lg\n", ret->u.real); } else - (void)add_message("Error apply_command: function %s not found.\n", com); + (void)add_message("Error apply_command: function %s not found.\n", com); } #endif /* 0 */ @@ -1328,10 +1328,10 @@ apply_command(char *com) * * NOTE! * It removes ALL actions defined by itself, including those added - * to itself. As actions added to onself is normally not done in init() - * this will have to be taken care of specifically. This should be of - * little problem as living objects seldom export actions and would - * therefore have little use of this efun. + * to itself. As actions added to onself is normally not done in init() + * this will have to be taken care of specifically. This should be of + * little problem as living objects seldom export actions and would + * therefore have little use of this efun. */ void update_actions(struct object *aob) @@ -1346,14 +1346,14 @@ update_actions(struct object *aob) */ if (item->super) { - if (item->super->flags & O_ENABLE_COMMANDS) - remove_sent(item, item->super); + if (item->super->flags & O_ENABLE_COMMANDS) + remove_sent(item, item->super); - for (pp = item->super->contains; pp; pp = pp->next_inv) - { - if (pp != item && (pp->flags & O_ENABLE_COMMANDS)) - remove_sent(item, pp); - } + for (pp = item->super->contains; pp; pp = pp->next_inv) + { + if (pp != item && (pp->flags & O_ENABLE_COMMANDS)) + remove_sent(item, pp); + } } /* @@ -1361,8 +1361,8 @@ update_actions(struct object *aob) */ for (pp = item->contains; pp; pp = pp->next_inv) { - if (pp->flags & O_ENABLE_COMMANDS) - remove_sent(item, pp); + if (pp->flags & O_ENABLE_COMMANDS) + remove_sent(item, pp); } /* @@ -1381,51 +1381,51 @@ update_actions(struct object *aob) */ if (item->super) { - if (item->super->flags & O_ENABLE_COMMANDS) - { - command_giver = item->super; + if (item->super->flags & O_ENABLE_COMMANDS) + { + command_giver = item->super; #ifdef USE_ENCOUNTER_NOT_INIT - push_object(item); - ret = apply("encounter", item->super, 1, 1); - if (!ret) - (void)apply("init", item, 0, 1); + push_object(item); + ret = apply("encounter", item->super, 1, 1); + if (!ret) + (void)apply("init", item, 0, 1); #else - (void)apply("init", item, 0, 1); + (void)apply("init", item, 0, 1); #endif - if (ob != item->super || - (item->flags & O_DESTRUCTED) || - (ob->flags & O_DESTRUCTED)) - { - command_giver = save_cmd; /* marion */ - return; - } - } - - for (pp = item->super->contains; pp;) - { - next_ob = pp->next_inv; - if (pp != item && (pp->flags & O_ENABLE_COMMANDS)) - { - command_giver = pp; + if (ob != item->super || + (item->flags & O_DESTRUCTED) || + (ob->flags & O_DESTRUCTED)) + { + command_giver = save_cmd; /* marion */ + return; + } + } + + for (pp = item->super->contains; pp;) + { + next_ob = pp->next_inv; + if (pp != item && (pp->flags & O_ENABLE_COMMANDS)) + { + command_giver = pp; #ifdef USE_ENCOUNTER_NOT_INIT - push_object(item); - ret = apply("encounter", pp, 1, 1); - if (!ret) - (void)apply("init", item, 0, 1); + push_object(item); + ret = apply("encounter", pp, 1, 1); + if (!ret) + (void)apply("init", item, 0, 1); #else - (void)apply("init", item, 0, 1); + (void)apply("init", item, 0, 1); #endif - if (ob != item->super || - (item->flags & O_DESTRUCTED) || - (ob->flags & O_DESTRUCTED) || - (next_ob->flags & O_DESTRUCTED)) - { - command_giver = save_cmd; /* marion */ - return; - } - } - pp = next_ob; - } + if (ob != item->super || + (item->flags & O_DESTRUCTED) || + (ob->flags & O_DESTRUCTED) || + (next_ob->flags & O_DESTRUCTED)) + { + command_giver = save_cmd; /* marion */ + return; + } + } + pp = next_ob; + } } /* @@ -1433,29 +1433,29 @@ update_actions(struct object *aob) */ for (pp = item->contains; pp;) { - next_ob = pp->next_inv; - if (pp->flags & O_ENABLE_COMMANDS) - { - command_giver = pp; + next_ob = pp->next_inv; + if (pp->flags & O_ENABLE_COMMANDS) + { + command_giver = pp; #ifdef USE_ENCOUNTER_NOT_INIT - push_object(item); - ret = apply("encounter", pp, 1, 1); - if (!ret) - (void)apply("init", item, 0, 1); + push_object(item); + ret = apply("encounter", pp, 1, 1); + if (!ret) + (void)apply("init", item, 0, 1); #else - (void)apply("init", item, 0, 1); + (void)apply("init", item, 0, 1); #endif - if (ob != item->super || - (item->flags & O_DESTRUCTED) || - (ob->flags & O_DESTRUCTED) || - (next_ob->flags & O_DESTRUCTED)) - - { - command_giver = save_cmd; /* marion */ - return; - } - } - pp = next_ob; + if (ob != item->super || + (item->flags & O_DESTRUCTED) || + (ob->flags & O_DESTRUCTED) || + (next_ob->flags & O_DESTRUCTED)) + + { + command_giver = save_cmd; /* marion */ + return; + } + } + pp = next_ob; } } @@ -1474,17 +1474,17 @@ move_object(struct object *dest) struct svalue *ret; if (item == NULL || dest == NULL || item->flags & O_DESTRUCTED) - return; + return; /* Recursive moves are not allowed. */ for (ob = dest; ob; ob = ob->super) - if (ob == item) { - error("Can't move object inside itself.\n"); - /* NOTREACHED */ - } + if (ob == item) { + error("Can't move object inside itself.\n"); + /* NOTREACHED */ + } if (item->shadowing) { - error("Can't move an object that is shadowing.\n"); - /* NOTREACHED */ + error("Can't move an object that is shadowing.\n"); + /* NOTREACHED */ } /* @@ -1492,38 +1492,38 @@ move_object(struct object *dest) * objects can not be moved into each other. */ if (s_flag) - num_move++; + num_move++; if (item->super) { - int okey = 0; - - if (item->flags & O_ENABLE_COMMANDS) - remove_sent(item->super, item); - - if (item->super->flags & O_ENABLE_COMMANDS) - remove_sent(item, item->super); - - for (pp = &item->super->contains; *pp;) - { - if (*pp != item) - { - if ((*pp)->flags & O_ENABLE_COMMANDS) - remove_sent(item, *pp); - if (item->flags & O_ENABLE_COMMANDS) - remove_sent(*pp, item); - pp = &(*pp)->next_inv; - continue; - } - *pp = item->next_inv; - okey = 1; - } - if (!okey) + int okey = 0; + + if (item->flags & O_ENABLE_COMMANDS) + remove_sent(item->super, item); + + if (item->super->flags & O_ENABLE_COMMANDS) + remove_sent(item, item->super); + + for (pp = &item->super->contains; *pp;) + { + if (*pp != item) + { + if ((*pp)->flags & O_ENABLE_COMMANDS) + remove_sent(item, *pp); + if (item->flags & O_ENABLE_COMMANDS) + remove_sent(*pp, item); + pp = &(*pp)->next_inv; + continue; + } + *pp = item->next_inv; + okey = 1; + } + if (!okey) #if 0 - fatal("Failed to find object %s in super list of %s.\n", - item->name, item->super->name); + fatal("Failed to find object %s in super list of %s.\n", + item->name, item->super->name); #else - fatal("Failed to find object in super list\n"); + fatal("Failed to find object in super list\n"); #endif } item->next_inv = dest->contains; @@ -1539,20 +1539,20 @@ move_object(struct object *dest) */ if (item->flags & O_ENABLE_COMMANDS) { - command_giver = item; + command_giver = item; #ifdef USE_ENCOUNTER_NOT_INIT - push_object(dest); - ret = apply("encounter", item, 1, 1); - if (!ret) - (void)apply("init", dest, 0, 1); + push_object(dest); + ret = apply("encounter", item, 1, 1); + if (!ret) + (void)apply("init", dest, 0, 1); #else - (void)apply("init", dest, 0, 1); + (void)apply("init", dest, 0, 1); #endif - if ((dest->flags & O_DESTRUCTED) || item->super != dest) - { - command_giver = save_cmd; /* marion */ - return; - } + if ((dest->flags & O_DESTRUCTED) || item->super != dest) + { + command_giver = save_cmd; /* marion */ + return; + } } /* * Run init of the item once for every present player, and @@ -1560,66 +1560,66 @@ move_object(struct object *dest) */ for (ob = dest->contains; ob; ob=next_ob) { - next_ob = ob->next_inv; - if (ob == item) - continue; - if (ob->flags & O_DESTRUCTED) { - error("An object was destructed at call of init()\n"); - /*NOTREACHED */ - } - if (ob->flags & O_ENABLE_COMMANDS) - { - command_giver = ob; + next_ob = ob->next_inv; + if (ob == item) + continue; + if (ob->flags & O_DESTRUCTED) { + error("An object was destructed at call of init()\n"); + /*NOTREACHED */ + } + if (ob->flags & O_ENABLE_COMMANDS) + { + command_giver = ob; #ifdef USE_ENCOUNTER_NOT_INIT - push_object(item); - ret = apply("encounter", ob, 1, 1); - if (!ret) - (void)apply("init", item, 0, 1); + push_object(item); + ret = apply("encounter", ob, 1, 1); + if (!ret) + (void)apply("init", item, 0, 1); #else - (void)apply("init", item, 0, 1); + (void)apply("init", item, 0, 1); #endif - if (dest != item->super) - { - command_giver = save_cmd; - return; - } - } - if (item->flags & O_DESTRUCTED) { /* marion */ - error("The object to be moved was destructed at call of init()\n"); - /* NOTREACHED */ - } - if (item->flags & O_ENABLE_COMMANDS) - { - command_giver = item; + if (dest != item->super) + { + command_giver = save_cmd; + return; + } + } + if (item->flags & O_DESTRUCTED) { /* marion */ + error("The object to be moved was destructed at call of init()\n"); + /* NOTREACHED */ + } + if (item->flags & O_ENABLE_COMMANDS) + { + command_giver = item; #ifdef USE_ENCOUNTER_NOT_INIT - push_object(ob); - ret = apply("encounter", item, 1, 1); - if (!ret) - (void)apply("init", ob, 0, 1); + push_object(ob); + ret = apply("encounter", item, 1, 1); + if (!ret) + (void)apply("init", ob, 0, 1); #else - (void) apply("init", ob, 0, 1); + (void) apply("init", ob, 0, 1); #endif - if (dest != item->super) - { - command_giver = save_cmd; - return; - } - } + if (dest != item->super) + { + command_giver = save_cmd; + return; + } + } } if (dest->flags & O_DESTRUCTED) { /* marion */ - error("The destination to move to was destructed at call of init()\n"); - /* NOTREACHED */ + error("The destination to move to was destructed at call of init()\n"); + /* NOTREACHED */ } if (dest->flags & O_ENABLE_COMMANDS) { - command_giver = dest; + command_giver = dest; #ifdef USE_ENCOUNTER_NOT_INIT - push_object(item); - ret = apply("encounter", dest, 1, 1); - if (!ret) - (void)apply("init", item, 0, 1); + push_object(item); + ret = apply("encounter", dest, 1, 1); + if (!ret) + (void)apply("init", item, 0, 1); #else - (void)apply("init", item, 0, 1); + (void)apply("init", item, 0, 1); #endif } command_giver = save_cmd; @@ -1646,7 +1646,7 @@ alloc_sentence() p->prev_all = NULL; p->next_all = sent_free; if (sent_free != NULL) - sent_free->prev_all = p; + sent_free->prev_all = p; sent_free = p; #endif @@ -1660,10 +1660,10 @@ free_all_sent() struct sentence *p; for (; sent_free ; sent_free = p) { - p = sent_free->next_all; - free(sent_free); - tot_current_alloc_sentence--; - tot_alloc_sentence--; + p = sent_free->next_all; + free(sent_free); + tot_current_alloc_sentence--; + tot_alloc_sentence--; } } #endif @@ -1916,23 +1916,23 @@ add_action(struct closure *func, struct svalue *cmd, int flag) struct object *ob; if (current_object->flags & O_DESTRUCTED) - return; + return; ob = current_object; if (command_giver == 0 || (command_giver->flags & O_DESTRUCTED)) - return; + return; if (ob != command_giver && ob->super != command_giver && - ob->super != command_giver->super && ob != command_giver->super) { - error("add_action from object that was not present.\n"); - /* NOTREACHED */ + ob->super != command_giver->super && ob != command_giver->super) { + error("add_action from object that was not present.\n"); + /* NOTREACHED */ } if (!legal_closure(func)) { - error("add_action to function in destructed object.\n"); - /* NOTREACHED */ + error("add_action to function in destructed object.\n"); + /* NOTREACHED */ } #ifdef DEBUG if (d_flag & DEBUG_ADD_ACTION) - debug_message("--Add action %s\n", getclosurename(func)); + debug_message("--Add action %s\n", getclosurename(func)); #endif if (func->funobj) func->funobj->flags |= O_ADDED_COMMAND; @@ -1943,9 +1943,9 @@ add_action(struct closure *func, struct svalue *cmd, int flag) p->next = command_giver->sent; p->short_verb = flag; if (cmd) - p->verb = make_sstring(cmd->u.string); + p->verb = make_sstring(cmd->u.string); else - p->verb = 0; + p->verb = 0; command_giver->sent = p; } @@ -1968,16 +1968,16 @@ remove_sent(struct object *ob, struct object *player) for (s= &player->sent; *s;) { - struct sentence *tmp; - if ((*s)->funct->funobj == ob) { - if (d_flag & DEBUG_SENTENCE) - debug_message("--Unlinking sentence %s\n", getclosurename((*s)->funct)); - tmp = *s; - *s = tmp->next; - free_sentence(tmp); + struct sentence *tmp; + if ((*s)->funct->funobj == ob) { + if (d_flag & DEBUG_SENTENCE) + debug_message("--Unlinking sentence %s\n", getclosurename((*s)->funct)); + tmp = *s; + *s = tmp->next; + free_sentence(tmp); found = 1; - } else - s = &((*s)->next); + } else + s = &((*s)->next); } if (!found) { @@ -1999,8 +1999,8 @@ get_gamedriver_info(char *str) int res, verbose = 0; extern char *reserved_area; extern int tot_alloc_object, tot_alloc_object_size, - num_arrays, total_array_size, num_mappings, - total_mapping_size; + num_arrays, total_array_size, num_mappings, + total_mapping_size; extern int num_distinct_strings_shared, num_distinct_strings_malloced; extern long bytes_distinct_strings_shared, bytes_distinct_strings_malloced; extern long overhead_bytes_shared, overhead_bytes_malloced; @@ -2015,156 +2015,156 @@ get_gamedriver_info(char *str) if (strcmp(str, "status") == 0 || strcmp(str, "status tables") == 0) { - if (strcmp(str, "status tables") == 0) - verbose = 1; - if (reserved_area) - res = RESERVED_SIZE; - else - res = 0; - if (!verbose) - { - (void)sprintf(tmp,"Sentences:\t\t%12d %12d\n", tot_alloc_sentence, - tot_alloc_sentence * (int) sizeof (struct sentence)); - (void)strcat(debinf, tmp); - - (void)sprintf(tmp,"Objects:\t\t%12d %12d (%d dest, %d rmd)\n", - tot_alloc_object, tot_alloc_object_size, - tot_alloc_dest_object, tot_removed_object); - (void)strcat(debinf, tmp); - - (void)sprintf(tmp,"Variables:\t\t\t %12d\n", - tot_alloc_variable_size); - (void)strcat(debinf, tmp); - - (void)sprintf(tmp,"Arrays:\t\t\t%12d %12d\n", - num_arrays, total_array_size); - (void)strcat(debinf, tmp); - - (void)sprintf(tmp,"Call_outs:\t\t%12lld %12lld\n", num_call, - call_out_size); - (void)strcat(debinf, tmp); - - (void)sprintf(tmp,"Mappings:\t\t%12d %12d\n", - num_mappings, total_mapping_size); - (void)strcat(debinf, tmp); - - (void)sprintf(tmp,"Functions:\t\t%12d %12d\n", - num_closures, total_closure_size); - (void)strcat(debinf, tmp); - - (void)sprintf(tmp,"Strings:\t\t%12d %12ld (%ld overhead)\n", - num_distinct_strings_shared + num_distinct_strings_malloced, - bytes_distinct_strings_shared + bytes_distinct_strings_malloced, - overhead_bytes_shared + overhead_bytes_malloced); - (void)strcat(debinf, tmp); - - (void)sprintf(tmp,"Prog blocks:\t\t%12d %12d\n", - total_num_prog_blocks, total_prog_block_size); - (void)strcat(debinf, tmp); - - (void)sprintf(tmp,"Programs:\t\t\t %12d\n", total_program_size); - (void)strcat(debinf, tmp); - - (void)sprintf(tmp,"Memory reserved:\t\t %12d\n", res); - (void)strcat(debinf, tmp); - - } - if (verbose) - { + if (strcmp(str, "status tables") == 0) + verbose = 1; + if (reserved_area) + res = RESERVED_SIZE; + else + res = 0; + if (!verbose) + { + (void)sprintf(tmp,"Sentences:\t\t%12d %12d\n", tot_alloc_sentence, + tot_alloc_sentence * (int) sizeof (struct sentence)); + (void)strcat(debinf, tmp); + + (void)sprintf(tmp,"Objects:\t\t%12d %12d (%d dest, %d rmd)\n", + tot_alloc_object, tot_alloc_object_size, + tot_alloc_dest_object, tot_removed_object); + (void)strcat(debinf, tmp); + + (void)sprintf(tmp,"Variables:\t\t\t %12d\n", + tot_alloc_variable_size); + (void)strcat(debinf, tmp); + + (void)sprintf(tmp,"Arrays:\t\t\t%12d %12d\n", + num_arrays, total_array_size); + (void)strcat(debinf, tmp); + + (void)sprintf(tmp,"Call_outs:\t\t%12lld %12lld\n", num_call, + call_out_size); + (void)strcat(debinf, tmp); + + (void)sprintf(tmp,"Mappings:\t\t%12d %12d\n", + num_mappings, total_mapping_size); + (void)strcat(debinf, tmp); + + (void)sprintf(tmp,"Functions:\t\t%12d %12d\n", + num_closures, total_closure_size); + (void)strcat(debinf, tmp); + + (void)sprintf(tmp,"Strings:\t\t%12d %12ld (%ld overhead)\n", + num_distinct_strings_shared + num_distinct_strings_malloced, + bytes_distinct_strings_shared + bytes_distinct_strings_malloced, + overhead_bytes_shared + overhead_bytes_malloced); + (void)strcat(debinf, tmp); + + (void)sprintf(tmp,"Prog blocks:\t\t%12d %12d\n", + total_num_prog_blocks, total_prog_block_size); + (void)strcat(debinf, tmp); + + (void)sprintf(tmp,"Programs:\t\t\t %12d\n", total_program_size); + (void)strcat(debinf, tmp); + + (void)sprintf(tmp,"Memory reserved:\t\t %12d\n", res); + (void)strcat(debinf, tmp); + + } + if (verbose) + { #ifdef CACHE_STATS - extern long long call_cache_saves; - extern long long global_cache_saves; - extern long long searches_needed; - extern long long searches_done; - extern long long global_first_saves; - extern long long call_first_saves; + extern long long call_cache_saves; + extern long long global_cache_saves; + extern long long searches_needed; + extern long long searches_done; + extern long long global_first_saves; + extern long long call_first_saves; #endif - if (globcache_tries < 1) - globcache_tries = 1; - (void)strcat(debinf, stat_living_objects()); - (void)strcat(debinf, "\nFunction calls:\n--------------------------\n"); - proc = 100.0 * (((double)cache_hits * 1.0) / cache_tries); - (void)sprintf(tmp,"Call cache, Tries: %10lld Hits: %10lld Miss: %10Ld Rate: %3.2f%%\n", - cache_tries, cache_hits, - cache_tries - cache_hits, proc); - (void)strcat(debinf, tmp); + if (globcache_tries < 1) + globcache_tries = 1; + (void)strcat(debinf, stat_living_objects()); + (void)strcat(debinf, "\nFunction calls:\n--------------------------\n"); + proc = 100.0 * (((double)cache_hits * 1.0) / cache_tries); + (void)sprintf(tmp,"Call cache, Tries: %10lld Hits: %10lld Miss: %10Ld Rate: %3.2f%%\n", + cache_tries, cache_hits, + cache_tries - cache_hits, proc); + (void)strcat(debinf, tmp); #ifdef CACHE_STATS - (void)sprintf(tmp, "searches saved %10lld %3.2f%%\n", - call_first_saves, - (double)(100.0 * (((double)call_first_saves * 1.0) / - (searches_needed + - global_first_saves - + call_first_saves)))); - (void)strcat(debinf, tmp); + (void)sprintf(tmp, "searches saved %10lld %3.2f%%\n", + call_first_saves, + (double)(100.0 * (((double)call_first_saves * 1.0) / + (searches_needed + + global_first_saves + + call_first_saves)))); + (void)strcat(debinf, tmp); #endif #ifdef GLOBAL_CACHE - proc = 100.0 * (((double)globcache_hits * 1.0) / globcache_tries); - (void)sprintf(tmp,"Global cache, Tries: %10lld Hits: %10lld Miss: %10lld Rate: %3.2f%%\n", - globcache_tries, globcache_hits, - globcache_tries -globcache_hits, proc); - (void)strcat(debinf, tmp); + proc = 100.0 * (((double)globcache_hits * 1.0) / globcache_tries); + (void)sprintf(tmp,"Global cache, Tries: %10lld Hits: %10lld Miss: %10lld Rate: %3.2f%%\n", + globcache_tries, globcache_hits, + globcache_tries -globcache_hits, proc); + (void)strcat(debinf, tmp); #ifdef CACHE_STATS - (void)sprintf(tmp, "searches saved %10lld %3.2f%%\n", - global_first_saves, - (double)(100.0 * (((double)global_first_saves * 1.0) / - (searches_needed + - global_first_saves - + call_first_saves)))); - (void)strcat(debinf, tmp); + (void)sprintf(tmp, "searches saved %10lld %3.2f%%\n", + global_first_saves, + (double)(100.0 * (((double)global_first_saves * 1.0) / + (searches_needed + + global_first_saves + + call_first_saves)))); + (void)strcat(debinf, tmp); #endif #endif #ifdef CACHE_STATS - (void)strcat(debinf, "Secondary hits:\n"); - (void)sprintf(tmp,"searches needed : %10lld\n", searches_needed); - (void)strcat(debinf, tmp); - (void)sprintf(tmp,"call cache saves : %10lld %3.2f%%\n", - call_cache_saves, (double)(100.0 * (((double)call_cache_saves * 1.0) / - searches_needed))); - (void)strcat(debinf, tmp); - (void)sprintf(tmp,"global cache saves : %10lld %3.2f%%\n", - global_cache_saves, - (double)(100.0 * (((double)global_cache_saves * 1.0) / - searches_needed))); - (void)strcat(debinf, tmp); - (void)sprintf(tmp,"searches done : %10lld\n", searches_done); - (void)strcat(debinf, tmp); - (void)sprintf(tmp,"Total needed : %10lld %3.2f%% done\n", - searches_needed + global_first_saves + call_first_saves, - (double)(100.0 * (((double)searches_done * 1.0) / - (searches_needed + - global_first_saves - + call_first_saves)))); - (void)strcat(debinf, tmp); + (void)strcat(debinf, "Secondary hits:\n"); + (void)sprintf(tmp,"searches needed : %10lld\n", searches_needed); + (void)strcat(debinf, tmp); + (void)sprintf(tmp,"call cache saves : %10lld %3.2f%%\n", + call_cache_saves, (double)(100.0 * (((double)call_cache_saves * 1.0) / + searches_needed))); + (void)strcat(debinf, tmp); + (void)sprintf(tmp,"global cache saves : %10lld %3.2f%%\n", + global_cache_saves, + (double)(100.0 * (((double)global_cache_saves * 1.0) / + searches_needed))); + (void)strcat(debinf, tmp); + (void)sprintf(tmp,"searches done : %10lld\n", searches_done); + (void)strcat(debinf, tmp); + (void)sprintf(tmp,"Total needed : %10lld %3.2f%% done\n", + searches_needed + global_first_saves + call_first_saves, + (double)(100.0 * (((double)searches_done * 1.0) / + (searches_needed + + global_first_saves + + call_first_saves)))); + (void)strcat(debinf, tmp); #endif - add_string_status(debinf); + add_string_status(debinf); - add_otable_status(debinf); + add_otable_status(debinf); - (void)strcat(debinf, "\nReferences:\n--------------------------------\n"); - (void)sprintf(tmp, "Null vector: %d\n", null_vector.ref); - (void)strcat(debinf, tmp); + (void)strcat(debinf, "\nReferences:\n--------------------------------\n"); + (void)sprintf(tmp, "Null vector: %d\n", null_vector.ref); + (void)strcat(debinf, tmp); } - tot = total_prog_block_size + - total_program_size + - tot_alloc_sentence * sizeof(struct sentence) + - total_array_size + + tot = total_prog_block_size + + total_program_size + + tot_alloc_sentence * sizeof(struct sentence) + + total_array_size + tot_alloc_variable_size + - call_out_size + - total_mapping_size + - bytes_distinct_strings_shared + overhead_bytes_shared + - bytes_distinct_strings_malloced + overhead_bytes_malloced + - tot_alloc_object_size + res; - - if (!verbose) - { - (void)strcat(debinf, "\t\t\t\t\t --------\n"); - (void)sprintf(tmp,"Total:\t\t\t\t\t %8ld\n", tot); - (void)strcat(debinf, tmp); - } + call_out_size + + total_mapping_size + + bytes_distinct_strings_shared + overhead_bytes_shared + + bytes_distinct_strings_malloced + overhead_bytes_malloced + + tot_alloc_object_size + res; + + if (!verbose) + { + (void)strcat(debinf, "\t\t\t\t\t --------\n"); + (void)sprintf(tmp,"Total:\t\t\t\t\t %8ld\n", tot); + (void)strcat(debinf, tmp); + } } return make_mstring(debinf); } @@ -2178,32 +2178,32 @@ get_local_commands(struct object *ob) int num; for (num = 0, s = ob->sent; s; s = s->next) - num++; + num++; ret2 = allocate_array(num); /* XXX */ for (num = 0, s = ob->sent; s; s = s->next, num++) { - ret2->item[num].type = T_POINTER; - ret2->item[num].u.vec = ret = allocate_array(4); + ret2->item[num].type = T_POINTER; + ret2->item[num].u.vec = ret = allocate_array(4); - ret->item[0].type = T_STRING; - ret->item[0].string_type = STRING_SSTRING; - ret->item[0].u.string = reference_sstring(s->verb); + ret->item[0].type = T_STRING; + ret->item[0].string_type = STRING_SSTRING; + ret->item[0].u.string = reference_sstring(s->verb); - ret->item[1].type = T_NUMBER; - ret->item[1].u.number = s->short_verb; + ret->item[1].type = T_NUMBER; + ret->item[1].u.number = s->short_verb; - if (s->funct->funobj) { - ret->item[2].type = T_OBJECT; - ret->item[2].u.ob = s->funct->funobj; - add_ref(ret->item[2].u.ob,"get_local_commands"); - } + if (s->funct->funobj) { + ret->item[2].type = T_OBJECT; + ret->item[2].u.ob = s->funct->funobj; + add_ref(ret->item[2].u.ob,"get_local_commands"); + } - ret->item[3].type = T_STRING; - ret->item[3].string_type = STRING_MSTRING; - ret->item[3].u.string = make_mstring(getclosurename(s->funct)); + ret->item[3].type = T_STRING; + ret->item[3].string_type = STRING_MSTRING; + ret->item[3].u.string = make_mstring(getclosurename(s->funct)); } return ret2; } @@ -2231,7 +2231,7 @@ fatal(char *fmt, ...) static int in_fatal = 0; /* Prevent double fatal. */ if (in_fatal) - abort(); + abort(); in_fatal = 1; va_start(argp, fmt); @@ -2240,7 +2240,7 @@ fatal(char *fmt, ...) fflush(stderr); if (current_object) - fprintf(stderr, "Current object was %s\n", current_object->name); + fprintf(stderr, "Current object was %s\n", current_object->name); va_start(argp, fmt); vsprintf(buf, fmt, argp); @@ -2249,7 +2249,7 @@ fatal(char *fmt, ...) debug_message("%s", buf); if (current_object) - debug_message("Current object was %s\n", current_object->name); + debug_message("Current object was %s\n", current_object->name); debug_message("Dump of variables:\n"); dump_trace(1); abort(); @@ -2278,13 +2278,13 @@ throw_error() if (exception && exception->e_catch) { - longjmp(exception->e_context, 1); - fatal("Throw_error failed!\n"); + longjmp(exception->e_context, 1); + fatal("Throw_error failed!\n"); } if (catch_value.type == T_STRING) - error("%s", catch_value.u.string); + error("%s", catch_value.u.string); else - error("Throw with no catch.\n"); + error("Throw with no catch.\n"); /* NOTREACHED */ } @@ -2303,81 +2303,81 @@ error(char *fmt, ...) vsnprintf(emsg_buf + 1, sizeof(emsg_buf) - 1, fmt, argp); va_end(argp); - emsg_buf[0] = '*'; /* all system errors get a * at the start */ + emsg_buf[0] = '*'; /* all system errors get a * at the start */ if (exception != NULL && exception->e_catch) { /* user catches this error */ - free_svalue(&catch_value); - catch_value.type = T_STRING; - catch_value.string_type = STRING_MSTRING; /* Always reallocate */ - catch_value.u.string = make_mstring(emsg_buf); - longjmp(exception->e_context, 1); - fatal("Catch() longjump failed\n"); + free_svalue(&catch_value); + catch_value.type = T_STRING; + catch_value.string_type = STRING_MSTRING; /* Always reallocate */ + catch_value.u.string = make_mstring(emsg_buf); + longjmp(exception->e_context, 1); + fatal("Catch() longjump failed\n"); } if (num_error == 0) { time_t now = time(NULL); - num_error = 1; - debug_message("%s%s", ctime(&now), emsg_buf+1); - - object_name = dump_trace(0); - (void)fflush(stdout); - if (object_name) { - struct object *ob; - ob = find_object2(object_name); - if (!ob) { - debug_message("error when executing program in destroyed object %s\n", - object_name); - } - } - /* - * The stack must be brought in a usable state. After the - * call to reset_machine(), all arguments to error() are invalid, - * and may not be used any more. The reason is that some strings - * may have been on the stack machine stack, and has been deallocated. - */ - reset_machine (); - push_string(emsg_buf, STRING_MSTRING); - if (current_object) - { - push_object(current_object); - - if (current_prog) - push_string(current_prog->name, STRING_MSTRING); - else - push_string("", STRING_CSTRING); - - push_string(get_srccode_position_if_any(), STRING_MSTRING); - } - else - { - push_number(0); - push_string("", STRING_CSTRING); - push_string("", STRING_CSTRING); - } - - exception_frame.e_exception = exception; - exception_frame.e_catch = 1; - if (setjmp(exception_frame.e_context)) - { - debug_message("Error while calling runtime_error()\n"); - reset_machine(); - } - else - { - exception = &exception_frame; - (void)apply_master_ob(M_RUNTIME_ERROR, 4); - } - num_error = 0; - exception = exception_frame.e_exception; + num_error = 1; + debug_message("%s%s", ctime(&now), emsg_buf+1); + + object_name = dump_trace(0); + (void)fflush(stdout); + if (object_name) { + struct object *ob; + ob = find_object2(object_name); + if (!ob) { + debug_message("error when executing program in destroyed object %s\n", + object_name); + } + } + /* + * The stack must be brought in a usable state. After the + * call to reset_machine(), all arguments to error() are invalid, + * and may not be used any more. The reason is that some strings + * may have been on the stack machine stack, and has been deallocated. + */ + reset_machine (); + push_string(emsg_buf, STRING_MSTRING); + if (current_object) + { + push_object(current_object); + + if (current_prog) + push_string(current_prog->name, STRING_MSTRING); + else + push_string("", STRING_CSTRING); + + push_string(get_srccode_position_if_any(), STRING_MSTRING); + } + else + { + push_number(0); + push_string("", STRING_CSTRING); + push_string("", STRING_CSTRING); + } + + exception_frame.e_exception = exception; + exception_frame.e_catch = 1; + if (setjmp(exception_frame.e_context)) + { + debug_message("Error while calling runtime_error()\n"); + reset_machine(); + } + else + { + exception = &exception_frame; + (void)apply_master_ob(M_RUNTIME_ERROR, 4); + } + num_error = 0; + exception = exception_frame.e_exception; } else { - debug_message("Too many simultaneous errors.\n"); + debug_message("Too many simultaneous errors.\n"); } if (exception != NULL) - longjmp(exception->e_context, 1); + longjmp(exception->e_context, 1); abort(); /* NOTREACHED */ } @@ -2391,13 +2391,13 @@ legal_path(char *path) char *p; if (path == NULL || strchr(path, ' ')) - return 0; + return 0; if (path[0] == '/') return 0; for(p = strchr(path, '.'); p; p = strchr(p+1, '.')) { - if (p[1] == '.') - return 0; + if (p[1] == '.') + return 0; } return 1; } @@ -2419,11 +2419,11 @@ init_smart_log() while (smart_log_msg) { - prev = smart_log_msg; - smart_log_msg = smart_log_msg->next; - free_mstring(prev->file); - free_mstring(prev->msg); - free((char *)prev); + prev = smart_log_msg; + smart_log_msg = smart_log_msg->next; + free_mstring(prev->file); + free_mstring(prev->msg); + free((char *)prev); } } @@ -2434,18 +2434,18 @@ dump_smart_log() if (!master_ob) { - init_smart_log(); - return; + init_smart_log(); + return; } while (smart_log_msg) { - prev = smart_log_msg; - smart_log_msg = smart_log_msg->next; - push_mstring(prev->file); - push_mstring(prev->msg); - free((char *)prev); - (void)apply_master_ob(M_LOG_ERROR, 2); + prev = smart_log_msg; + smart_log_msg = smart_log_msg->next; + push_mstring(prev->file); + push_mstring(prev->msg); + free((char *)prev); + (void)apply_master_ob(M_LOG_ERROR, 2); } } @@ -2457,11 +2457,11 @@ smart_log(char *error_file, int line, char *what) for (last = &smart_log_msg; *last; last = &(*last)->next) if (error_file == 0) - return; + return; if (strlen(what) + strlen(error_file) > sizeof buff - 100) - what = "...[too long error message]..."; + what = "...[too long error message]..."; if (strlen(what) + strlen(error_file) > sizeof buff - 100) - error_file = "...[too long filename]..."; + error_file = "...[too long filename]..."; (void)snprintf(buff, sizeof(buff), "/%s line %d:%s\n", error_file, line, what); *last = (struct error_msg *)xalloc(sizeof(struct error_msg)); (*last)->next = NULL; @@ -2490,17 +2490,17 @@ check_valid_path(char *path, struct object *ob, push_object(ob); push_string(call_fun, STRING_MSTRING); if (writeflg) - v = apply_master_ob(M_VALID_WRITE, 3); + v = apply_master_ob(M_VALID_WRITE, 3); else - v = apply_master_ob(M_VALID_READ, 3); + v = apply_master_ob(M_VALID_READ, 3); if (v && (v->type != T_NUMBER || v->u.number == 0)) - return 0; + return 0; if (path[0] == '/') - path++; + path++; if (path[0] == '\0') - path = "."; + path = "."; if (legal_path(path)) - return path; + return path; return 0; } @@ -2534,16 +2534,16 @@ shutdowngame() ipc_remove(); #ifdef DEALLOCATE_MEMORY_AT_SHUTDOWN if (reserved_area) { - free(reserved_area); - reserved_area = NULL; + free(reserved_area); + reserved_area = NULL; } free_parse_information(); remove_all_objects(); while ((lp = lpc_predefs) != NULL) { - lpc_predefs = lpc_predefs->next; - if (lp->flag) - free(lp->flag); - free(lp); + lpc_predefs = lpc_predefs->next; + if (lp->flag) + free(lp->flag); + free(lp); } free_inc_list(); remove_destructed_objects(); @@ -2573,37 +2573,37 @@ match_string(char *match, char *str) again: if (*str == '\0' && *match == '\0') - return 1; + return 1; switch(*match) { case '?': - if (*str == '\0') - return 0; - str++; - match++; - goto again; + if (*str == '\0') + return 0; + str++; + match++; + goto again; case '*': - match++; - if (*match == '\0') - return 1; - for (i=0; str[i] != '\0'; i++) - if (match_string(match, str+i)) - return 1; - return 0; + match++; + if (*match == '\0') + return 1; + for (i=0; str[i] != '\0'; i++) + if (match_string(match, str+i)) + return 1; + return 0; case '\0': - return 0; + return 0; case '\\': - match++; - if (*match == '\0') - return 0; - /* FALLTHROUGH */ + match++; + if (*match == '\0') + return 0; + /* FALLTHROUGH */ default: - if (*match == *str) { - match++; - str++; - goto again; - } - return 0; + if (*match == *str) { + match++; + str++; + goto again; + } + return 0; } } @@ -2613,11 +2613,11 @@ match_string(char *match, char *str) * See the GNU General Public License for more details. */ #ifndef S_ISDIR -#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) +#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) #endif #ifndef S_ISREG -#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) +#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) #endif int @@ -2635,7 +2635,7 @@ strip_trailing_slashes(char *path) last = strlen (path) - 1; while (last > 0 && path[last] == '/') - path[last--] = '\0'; + path[last--] = '\0'; } struct stat to_stats, from_stats; @@ -2644,90 +2644,90 @@ int copy (char *from, char *to) { char buf[1024 * 8]; - int len; /* Number of bytes read into buf. */ + int len; /* Number of bytes read into buf. */ int ifd; int ofd; if (!S_ISREG (from_stats.st_mode)) { error("cannot move `%s' across filesystems: Not a regular file\n", from); - /* NOTREACHED */ + /* NOTREACHED */ } if (unlink (to) && errno != ENOENT) { - error("cannot remove `%s'\n", to); - /* NOTREACHED */ + error("cannot remove `%s'\n", to); + /* NOTREACHED */ } ifd = open (from, O_RDONLY, 0); if (ifd < 0) { - error ("%s: open failed\n", from); - /* NOTREACHED */ + error ("%s: open failed\n", from); + /* NOTREACHED */ } ofd = open (to, O_WRONLY | O_CREAT | O_TRUNC, 0600); if (ofd < 0) { - error ("%s: open failed\n", to); - (void)close (ifd); - return 1; + error ("%s: open failed\n", to); + (void)close (ifd); + return 1; } if (fchmod (ofd, (mode_t)(from_stats.st_mode & 0777))) { - error ("%s: fchmod failed\n", to); - (void)close (ifd); - (void)close (ofd); - (void)unlink (to); - return 1; + error ("%s: fchmod failed\n", to); + (void)close (ifd); + (void)close (ofd); + (void)unlink (to); + return 1; } while ((len = read (ifd, buf, sizeof (buf))) > 0) { - int wrote = 0; - char *bp = buf; - - do - { - wrote = write (ofd, bp, (size_t)len); - if (wrote < 0) - { - error ("%s: write failed\n", to); - (void)close (ifd); - (void)close (ofd); - (void)unlink (to); - return 1; - } - bp += wrote; - len -= wrote; - } while (len > 0); + int wrote = 0; + char *bp = buf; + + do + { + wrote = write (ofd, bp, (size_t)len); + if (wrote < 0) + { + error ("%s: write failed\n", to); + (void)close (ifd); + (void)close (ofd); + (void)unlink (to); + return 1; + } + bp += wrote; + len -= wrote; + } while (len > 0); } if (len < 0) { - error ("%s: read failed\n", from); - (void)close (ifd); - (void)close (ofd); - (void)unlink (to); - return 1; + error ("%s: read failed\n", from); + (void)close (ifd); + (void)close (ofd); + (void)unlink (to); + return 1; } if (close (ifd) < 0) { - error ("%s: close failed", from); - (void)close (ofd); - return 1; + error ("%s: close failed", from); + (void)close (ofd); + return 1; } if (close (ofd) < 0) { - error ("%s: close failed", to); - return 1; + error ("%s: close failed", to); + return 1; } #ifdef FCHMOD_MISSING if (chmod (to, from_stats.st_mode & 0777)) { - error ("%s: chmod failed\n", to); - return 1; + error ("%s: chmod failed\n", to); + return 1; } #endif @@ -2743,51 +2743,51 @@ do_move (char *from, char *to) { if (lstat (from, &from_stats) != 0) { - error ("%s: lstat failed\n", from); - return 0; + error ("%s: lstat failed\n", from); + return 0; } if (lstat (to, &to_stats) == 0) { - if (from_stats.st_dev == to_stats.st_dev - && from_stats.st_ino == to_stats.st_ino) - { - error ("`%s' and `%s' are the same file", from, to); - return 0; - } + if (from_stats.st_dev == to_stats.st_dev + && from_stats.st_ino == to_stats.st_ino) + { + error ("`%s' and `%s' are the same file", from, to); + return 0; + } - if (S_ISDIR (to_stats.st_mode)) - { - error ("%s: cannot overwrite directory", to); - return 0; - } + if (S_ISDIR (to_stats.st_mode)) + { + error ("%s: cannot overwrite directory", to); + return 0; + } } else if (errno != ENOENT) { - error ("%s: unknown error\n", to); - return 0; + error ("%s: unknown error\n", to); + return 0; } if (rename (from, to) == 0) { - return 1; + return 1; } if (errno != EXDEV) { - error ("cannot move `%s' to `%s'", from, to); - return 0; + error ("cannot move `%s' to `%s'", from, to); + return 0; } /* rename failed on cross-filesystem link. Copy the file instead. */ if (copy (from, to)) - return 0; + return 0; if (unlink (from)) { - error ("cannot remove `%s'", from); - return 0; + error ("cannot remove `%s'", from); + return 0; } return 1; @@ -2816,32 +2816,32 @@ do_rename(char * fr, char *t) from = check_valid_path(fr, current_object, "do_rename_from", 1); if(!from) - return 0; + return 0; to = check_valid_path(t, current_object, "do_rename_to", 1); if(!to) - return 0; + return 0; if(*to == '\0' && strcmp(t, "/") == 0) { - to = (char *)tmpalloc(3); - (void)strcpy(to, "./"); + to = (char *)tmpalloc(3); + (void)strcpy(to, "./"); } strip_trailing_slashes (from); if (isdir (to)) { - /* Target is a directory; build full target filename. */ - char *cp; - char *newto; + /* Target is a directory; build full target filename. */ + char *cp; + char *newto; - cp = strrchr (from, '/'); - if (cp) - cp++; - else - cp = from; + cp = strrchr (from, '/'); + if (cp) + cp++; + else + cp = from; - newto = (char *) tmpalloc (strlen (to) + 1 + strlen (cp) + 1); - (void)sprintf (newto, "%s/%s", to, cp); - return do_move (from, newto); + newto = (char *) tmpalloc (strlen (to) + 1 + strlen (cp) + 1); + (void)sprintf (newto, "%s/%s", to, cp); + return do_move (from, newto); } else - return do_move (from, to); + return do_move (from, to); } diff --git a/simulate.h b/simulate.h index bca6c36..ac1251b 100644 --- a/simulate.h +++ b/simulate.h @@ -8,4 +8,4 @@ char *get_gamedriver_info(char *str); void fatal(char *fmt, ...) __attribute__((format(printf, 1, 2))) __attribute__ ((noreturn)); void warning(char *fmt, ...) __attribute__((format(printf, 1, 2))); void error(char *fmt, ...) __attribute__((format(printf, 1, 2))) __attribute__ ((noreturn)); -#endif \ No newline at end of file +#endif diff --git a/siphash.c b/siphash.c index 7943218..7a7ea0a 100644 --- a/siphash.c +++ b/siphash.c @@ -4,67 +4,67 @@ static uint64_t INLINE U8TO64_LE(const unsigned char *p) { - return *(const uint64_t *)p; + return *(const uint64_t *)p; } /* static void INLINE U64TO8_LE(unsigned char *p, const uint64_t v) { - *(uint64_t *)p = v; + *(uint64_t *)p = v; } */ uint64_t siphash(const unsigned char key[16], const unsigned char *m, size_t len) { - uint64_t v0, v1, v2, v3; - uint64_t mi, k0, k1; - uint64_t last7; - size_t i, blocks; + uint64_t v0, v1, v2, v3; + uint64_t mi, k0, k1; + uint64_t last7; + size_t i, blocks; - k0 = U8TO64_LE(key + 0); - k1 = U8TO64_LE(key + 8); - v0 = k0 ^ 0x736f6d6570736575ull; - v1 = k1 ^ 0x646f72616e646f6dull; - v2 = k0 ^ 0x6c7967656e657261ull; - v3 = k1 ^ 0x7465646279746573ull; + k0 = U8TO64_LE(key + 0); + k1 = U8TO64_LE(key + 8); + v0 = k0 ^ 0x736f6d6570736575ull; + v1 = k1 ^ 0x646f72616e646f6dull; + v2 = k0 ^ 0x6c7967656e657261ull; + v3 = k1 ^ 0x7465646279746573ull; - last7 = (uint64_t)(len & 0xff) << 56; + last7 = (uint64_t)(len & 0xff) << 56; #define sipcompress() \ - v0 += v1; v2 += v3; \ - v1 = ROTL64(v1,13); v3 = ROTL64(v3,16); \ - v1 ^= v0; v3 ^= v2; \ - v0 = ROTL64(v0,32); \ - v2 += v1; v0 += v3; \ - v1 = ROTL64(v1,17); v3 = ROTL64(v3,21); \ - v1 ^= v2; v3 ^= v0; \ - v2 = ROTL64(v2,32); + v0 += v1; v2 += v3; \ + v1 = ROTL64(v1,13); v3 = ROTL64(v3,16); \ + v1 ^= v0; v3 ^= v2; \ + v0 = ROTL64(v0,32); \ + v2 += v1; v0 += v3; \ + v1 = ROTL64(v1,17); v3 = ROTL64(v3,21); \ + v1 ^= v2; v3 ^= v0; \ + v2 = ROTL64(v2,32); - for (i = 0, blocks = (len & ~7); i < blocks; i += 8) { - mi = U8TO64_LE(m + i); - v3 ^= mi; - sipcompress() - v0 ^= mi; - } + for (i = 0, blocks = (len & ~7); i < blocks; i += 8) { + mi = U8TO64_LE(m + i); + v3 ^= mi; + sipcompress() + v0 ^= mi; + } - switch (len - blocks) { - case 7: last7 |= (uint64_t)m[i + 6] << 48; - case 6: last7 |= (uint64_t)m[i + 5] << 40; - case 5: last7 |= (uint64_t)m[i + 4] << 32; - case 4: last7 |= (uint64_t)m[i + 3] << 24; - case 3: last7 |= (uint64_t)m[i + 2] << 16; - case 2: last7 |= (uint64_t)m[i + 1] << 8; - case 1: last7 |= (uint64_t)m[i + 0] ; - case 0: - default:; - }; - v3 ^= last7; - sipcompress() - v0 ^= last7; - v2 ^= 0xff; - sipcompress() - sipcompress() - sipcompress() - return v0 ^ v1 ^ v2 ^ v3; + switch (len - blocks) { + case 7: last7 |= (uint64_t)m[i + 6] << 48; + case 6: last7 |= (uint64_t)m[i + 5] << 40; + case 5: last7 |= (uint64_t)m[i + 4] << 32; + case 4: last7 |= (uint64_t)m[i + 3] << 24; + case 3: last7 |= (uint64_t)m[i + 2] << 16; + case 2: last7 |= (uint64_t)m[i + 1] << 8; + case 1: last7 |= (uint64_t)m[i + 0] ; + case 0: + default:; + }; + v3 ^= last7; + sipcompress() + v0 ^= last7; + v2 ^= 0xff; + sipcompress() + sipcompress() + sipcompress() + return v0 ^ v1 ^ v2 ^ v3; } diff --git a/siphash.h b/siphash.h index c9aa333..29c222e 100644 --- a/siphash.h +++ b/siphash.h @@ -1,22 +1,22 @@ -#ifndef SIPHASH_H -#define SIPHASH_H - -#if defined(_MSC_VER) - typedef unsigned __int64 uint64_t; -#else - #include - #include -#endif - -#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ -extern "C" { -#endif - -uint64_t siphash(const unsigned char key[16], const unsigned char *m, size_t len); - -#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */ -} -#endif - - -#endif // SIPHASH_H +#ifndef SIPHASH_H +#define SIPHASH_H + +#if defined(_MSC_VER) + typedef unsigned __int64 uint64_t; +#else + #include + #include +#endif + +#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ +extern "C" { +#endif + +uint64_t siphash(const unsigned char key[16], const unsigned char *m, size_t len); + +#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */ +} +#endif + + +#endif // SIPHASH_H diff --git a/siphash_impl.h b/siphash_impl.h index c134060..41624d2 100644 --- a/siphash_impl.h +++ b/siphash_impl.h @@ -1,50 +1,50 @@ -#ifndef SIPHASH_IMPL_H -#define SIPHASH_IMPL_H - -#include "siphash.h" - -#if defined(_MSC_VER) - #include - - #define INLINE __forceinline - #define NOINLINE __declspec(noinline) - #define ROTL64(a,b) _rotl64(a,b) - #define MM16 __declspec(align(16)) - - typedef unsigned int uint32_t; - - #if (_MSC_VER >= 1500) - #define __SSSE3__ - #endif - #if (_MSC_VER > 1200) || defined(_mm_free) - #define __SSE2__ - #endif -#else - #define INLINE inline __attribute__((always_inline)) - #define NOINLINE __attribute__((noinline)) - #define ROTL64(a,b) (((a)<<(b))|((a)>>(64-b))) - #define MM16 __attribute__((aligned(16))) -#endif - -#if defined(__SSE2__) - #include - typedef __m128i xmmi; - typedef __m64 qmm; - - typedef union packedelem64_t { - uint64_t u[2]; - xmmi v; - } packedelem64; - - typedef union packedelem8_t { - unsigned char u[16]; - xmmi v; - } packedelem8; -#endif - -#if defined(__SSSE3__) - #include -#endif - -#endif // SIPHASH_IMPL_H - +#ifndef SIPHASH_IMPL_H +#define SIPHASH_IMPL_H + +#include "siphash.h" + +#if defined(_MSC_VER) + #include + + #define INLINE __forceinline + #define NOINLINE __declspec(noinline) + #define ROTL64(a,b) _rotl64(a,b) + #define MM16 __declspec(align(16)) + + typedef unsigned int uint32_t; + + #if (_MSC_VER >= 1500) + #define __SSSE3__ + #endif + #if (_MSC_VER > 1200) || defined(_mm_free) + #define __SSE2__ + #endif +#else + #define INLINE inline __attribute__((always_inline)) + #define NOINLINE __attribute__((noinline)) + #define ROTL64(a,b) (((a)<<(b))|((a)>>(64-b))) + #define MM16 __attribute__((aligned(16))) +#endif + +#if defined(__SSE2__) + #include + typedef __m128i xmmi; + typedef __m64 qmm; + + typedef union packedelem64_t { + uint64_t u[2]; + xmmi v; + } packedelem64; + + typedef union packedelem8_t { + unsigned char u[16]; + xmmi v; + } packedelem8; +#endif + +#if defined(__SSSE3__) + #include +#endif + +#endif // SIPHASH_IMPL_H + diff --git a/sprintf.c b/sprintf.c index cc04ee0..2c58535 100644 --- a/sprintf.c +++ b/sprintf.c @@ -82,27 +82,27 @@ typedef unsigned int format_info; /* * Format of format_info: * 00000000 0000xxxx : argument type: - * 0000 : type not found yet; - * 0001 : error type not found; - * 0010 : percent sign, null argument; - * 0011 : LPC datatype; - * 0100 : string; - * 0101 : float, engineering; - * 0110 : float, decimal; - * 0111 : float, shortest; - * 1000 : integer; - * 1001 : char; - * 1010 : octal; - * 1011 : hex; - * 1100 : HEX; + * 0000 : type not found yet; + * 0001 : error type not found; + * 0010 : percent sign, null argument; + * 0011 : LPC datatype; + * 0100 : string; + * 0101 : float, engineering; + * 0110 : float, decimal; + * 0111 : float, shortest; + * 1000 : integer; + * 1001 : char; + * 1010 : octal; + * 1011 : hex; + * 1100 : HEX; * 00000000 00xx0000 : justification: - * 00 : right; - * 01 : centre; - * 10 : left; + * 00 : right; + * 01 : centre; + * 10 : left; * 00000000 xx000000 : positive pad char: - * 00 : none; - * 01 : ' '; - * 10 : '+'; + * 00 : none; + * 01 : ' '; + * 10 : '+'; * 0000000x 00000000 : array mode? * 000000x0 00000000 : column mode? * 00000x00 00000000 : table mode? @@ -113,7 +113,7 @@ typedef unsigned int format_info; #define INFO_T_NULL 0x2 #define INFO_T_LPC 0x3 #define INFO_T_STRING 0x4 -#define INFO_T_FLOAT_E 0x05 +#define INFO_T_FLOAT_E 0x05 #define INFO_T_FLOAT_F 0x06 #define INFO_T_FLOAT_G 0x07 #define INFO_T_INT 0x8 @@ -133,23 +133,23 @@ typedef unsigned int format_info; #define INFO_ARRAY 0x100 #define INFO_COLS 0x200 #define INFO_TABLE 0x400 -#define INFO_COMMA 0x800 +#define INFO_COMMA 0x800 #define BUFF_SIZE 65535 #define ERROR(x) longjmp(error_jmp, x) -#define ERR_BUFF_OVERFLOW 0x1 /* buffer overflowed */ -#define ERR_TO_FEW_ARGS 0x2 /* more arguments spec'ed than passed */ -#define ERR_INVALID_STAR 0x3 /* invalid arg to * */ -#define ERR_PREC_EXPECTED 0x4 /* expected precision not found */ -#define ERR_INVALID_FORMAT_STR 0x5 /* error in format string */ -#define ERR_INCORRECT_ARG_S 0x6 /* invalid arg to %s */ -#define ERR_CST_REQUIRES_FS 0x7 /* field size not given for c/t */ -#define ERR_BAD_INT_TYPE 0x8 /* bad integer type... */ -#define ERR_UNDEFINED_TYPE 0x9 /* undefined type found */ -#define ERR_QUOTE_EXPECTED 0xA /* expected ' not found */ -#define ERR_UNEXPECTED_EOS 0xB /* fs terminated unexpectedly */ -#define ERR_NULL_PS 0xC /* pad string is null */ +#define ERR_BUFF_OVERFLOW 0x1 /* buffer overflowed */ +#define ERR_TO_FEW_ARGS 0x2 /* more arguments spec'ed than passed */ +#define ERR_INVALID_STAR 0x3 /* invalid arg to * */ +#define ERR_PREC_EXPECTED 0x4 /* expected precision not found */ +#define ERR_INVALID_FORMAT_STR 0x5 /* error in format string */ +#define ERR_INCORRECT_ARG_S 0x6 /* invalid arg to %s */ +#define ERR_CST_REQUIRES_FS 0x7 /* field size not given for c/t */ +#define ERR_BAD_INT_TYPE 0x8 /* bad integer type... */ +#define ERR_UNDEFINED_TYPE 0x9 /* undefined type found */ +#define ERR_QUOTE_EXPECTED 0xA /* expected ' not found */ +#define ERR_UNEXPECTED_EOS 0xB /* fs terminated unexpectedly */ +#define ERR_NULL_PS 0xC /* pad string is null */ #define ERR_BAD_FLOAT_TYPE 0xD /* Bad float type... */ #define ADD_CHAR(x) {\ @@ -186,26 +186,26 @@ typedef struct ColumnSlashTable { union CSTData { - char *col; /* column text position */ - char **tab; /* table data */ - } d; /* d == data */ - unsigned short int nocols; /* number of columns in table *sigh* */ + char *col; /* column text position */ + char **tab; /* table data */ + } d; /* d == data */ + unsigned short int nocols; /* number of columns in table *sigh* */ char *pad; - unsigned int start; /* starting cursor position */ - unsigned int size; /* column/table width */ - int prec; /* precision */ - format_info info; /* formatting data */ + unsigned int start; /* starting cursor position */ + unsigned int size; /* column/table width */ + int prec; /* precision */ + format_info info; /* formatting data */ struct ColumnSlashTable *next; -} cst; /* Columns Slash Tables */ +} cst; /* Columns Slash Tables */ -static char buff[BUFF_SIZE]; /* buffer for returned string */ -static unsigned int bpos; /* position in buff */ -static unsigned int curpos; /* cursor position */ -static jmp_buf error_jmp; /* for error longjmp()s */ -static struct svalue *clean; /* Temporary storage */ -static savechars *saves; /* chars to restore */ -static int call_master_ob; /* should the master object be called for the - * name of an object? */ +static char buff[BUFF_SIZE]; /* buffer for returned string */ +static unsigned int bpos; /* position in buff */ +static unsigned int curpos; /* cursor position */ +static jmp_buf error_jmp; /* for error longjmp()s */ +static struct svalue *clean; /* Temporary storage */ +static savechars *saves; /* chars to restore */ +static int call_master_ob; /* should the master object be called for the + * name of an object? */ /* * Probably should make this a #define... */ @@ -217,13 +217,13 @@ stradd(char **dst, size_t *size, char *add) if ((i = (strlen(*dst) + strlen(add))) >= *size) { - *size += i + 1; - if (*size >= BUFF_SIZE) - ERROR(ERR_BUFF_OVERFLOW); - tmp = allocate_mstring((size_t)*size); - (void)strcpy(tmp, *dst); - free_mstring(*dst); - *dst = tmp; + *size += i + 1; + if (*size >= BUFF_SIZE) + ERROR(ERR_BUFF_OVERFLOW); + tmp = allocate_mstring((size_t)*size); + (void)strcpy(tmp, *dst); + free_mstring(*dst); + *dst = tmp; } (void)strcat(*dst, add); } /* end of stradd() */ @@ -239,26 +239,26 @@ numadd(char **dst, size_t *size, long long snum) if (snum < 0) { unum = -snum; - nve = 1; + nve = 1; } for (i = 10, j = 0; unum >= i && j < 18; i *= 10, j++) /* LA XXX */ - ; + ; i = strlen(*dst) + nve; if ((i + j) >= *size) { - *size += i + j + 1; - tmp = allocate_mstring((size_t)*size); - if (*size >= BUFF_SIZE) - ERROR(ERR_BUFF_OVERFLOW); - (void)strcpy(tmp, *dst); - free_mstring(*dst); - *dst = tmp; + *size += i + j + 1; + tmp = allocate_mstring((size_t)*size); + if (*size >= BUFF_SIZE) + ERROR(ERR_BUFF_OVERFLOW); + (void)strcpy(tmp, *dst); + free_mstring(*dst); + *dst = tmp; } if (nve) - (*dst)[i - 1] = '-'; + (*dst)[i - 1] = '-'; (*dst)[i + j + 1] = '\0'; for ( ; j >= 0; j--, unum /= 10) - (*dst)[i + j] = (unum % 10) + '0'; + (*dst)[i + j] = (unum % 10) + '0'; } /* end of num_add() */ /* @@ -274,16 +274,16 @@ add_indent(char **dst, size_t *size, int indent) i = strlen(*dst); if ((i + indent) >= *size) { - *size += i + indent + 1; - if (*size >= BUFF_SIZE) - ERROR(ERR_BUFF_OVERFLOW); - tmp = allocate_mstring(*size); - (void)strcpy(tmp, *dst); - free_mstring(*dst); - *dst = tmp; + *size += i + indent + 1; + if (*size >= BUFF_SIZE) + ERROR(ERR_BUFF_OVERFLOW); + tmp = allocate_mstring(*size); + (void)strcpy(tmp, *dst); + free_mstring(*dst); + *dst = tmp; } for ( ; indent; indent--) - (*dst)[i++] = ' '; + (*dst)[i++] = ' '; (*dst)[i] = '\0'; } @@ -294,117 +294,117 @@ add_indent(char **dst, size_t *size, int indent) */ static void svalue_to_string(struct svalue *obj, char **str, size_t size, int indent, - int trailing) + int trailing) { int i; if (indent >= 0) - add_indent(str, &size, indent); + add_indent(str, &size, indent); else - indent = -indent; + indent = -indent; switch (obj->type) { case T_INVALID: - stradd(str,&size,"T_INVALID"); - break; + stradd(str,&size,"T_INVALID"); + break; case T_LVALUE: - stradd(str, &size, "lvalue: "); - svalue_to_string(obj->u.lvalue, str, size, - indent - 2, trailing); - break; + stradd(str, &size, "lvalue: "); + svalue_to_string(obj->u.lvalue, str, size, - indent - 2, trailing); + break; case T_NUMBER: - numadd(str, &size, obj->u.number); - break; + numadd(str, &size, obj->u.number); + break; case T_FLOAT: - { - char buffer[1024]; - (void)sprintf(buffer,"%.18g",obj->u.real); - stradd(str,&size,buffer); - } - break; + { + char buffer[1024]; + (void)sprintf(buffer,"%.18g",obj->u.real); + stradd(str,&size,buffer); + } + break; case T_STRING: - stradd(str, &size, "\""); - stradd(str, &size, obj->u.string); - stradd(str, &size, "\""); - break; + stradd(str, &size, "\""); + stradd(str, &size, obj->u.string); + stradd(str, &size, "\""); + break; case T_POINTER: - if (!(obj->u.vec->size)) - { - stradd(str, &size, "({ })"); - } - else - { - stradd(str, &size, "({ /* sizeof() == "); - numadd(str, &size, obj->u.vec->size); - stradd(str, &size, " */\n"); - for (i = 0; i < (obj->u.vec->size) - 1; i++) - svalue_to_string(&(obj->u.vec->item[i]), str, size, - indent + 2 , 1); - svalue_to_string(&(obj->u.vec->item[i]), str, size, indent + 2, 0); - stradd(str, &size, " })"); - } - break; + if (!(obj->u.vec->size)) + { + stradd(str, &size, "({ })"); + } + else + { + stradd(str, &size, "({ /* sizeof() == "); + numadd(str, &size, obj->u.vec->size); + stradd(str, &size, " */\n"); + for (i = 0; i < (obj->u.vec->size) - 1; i++) + svalue_to_string(&(obj->u.vec->item[i]), str, size, + indent + 2 , 1); + svalue_to_string(&(obj->u.vec->item[i]), str, size, indent + 2, 0); + stradd(str, &size, " })"); + } + break; case T_OBJECT: - if (obj->u.ob->flags & O_DESTRUCTED) - numadd(str, &size, 0); - else - { - struct svalue *temp; + if (obj->u.ob->flags & O_DESTRUCTED) + numadd(str, &size, 0); + else + { + struct svalue *temp; - stradd(str, &size, obj->u.ob->name); - if (call_master_ob) - { - push_object(obj->u.ob); - temp = apply_master_ob(M_OBJECT_NAME, 1); - if (temp && (temp->type == T_STRING)) - { - stradd(str, &size, " (\""); - stradd(str, &size, temp->u.string); - stradd(str, &size, "\")"); - } - } - } - break; + stradd(str, &size, obj->u.ob->name); + if (call_master_ob) + { + push_object(obj->u.ob); + temp = apply_master_ob(M_OBJECT_NAME, 1); + if (temp && (temp->type == T_STRING)) + { + stradd(str, &size, " (\""); + stradd(str, &size, temp->u.string); + stradd(str, &size, "\")"); + } + } + } + break; case T_MAPPING: - if (!(obj->u.map->card)) - { - stradd(str, &size, "([ ])"); - } - else - { - struct apair *pair = 0; - int j; - stradd(str, &size, "([ /* sizeof() == "); - numadd(str, &size, obj->u.map->card); - stradd(str, &size, " */\n"); - for (j = obj->u.map->size - 1; obj->u.map->pairs[j] == 0 && j >= 0; j--); - for (i = 0; i <= j; i++) - { - for (pair = obj->u.map->pairs[i]; - (i != j) ? pair : pair->next; pair = pair->next) - { - svalue_to_string(&(pair->arg), str, size, indent + 2, 0); - stradd(str, &size, " : "); - svalue_to_string(&(pair->val), str, size, -indent - 2, 1); - } - } - if (pair) - { - svalue_to_string(&(pair->arg), str, size, indent + 2, 0); - stradd(str, &size, " : "); - svalue_to_string(&(pair->val), str, size, -indent - 2, 0); - } - stradd(str, &size, " ])"); - } - break; + if (!(obj->u.map->card)) + { + stradd(str, &size, "([ ])"); + } + else + { + struct apair *pair = 0; + int j; + stradd(str, &size, "([ /* sizeof() == "); + numadd(str, &size, obj->u.map->card); + stradd(str, &size, " */\n"); + for (j = obj->u.map->size - 1; obj->u.map->pairs[j] == 0 && j >= 0; j--); + for (i = 0; i <= j; i++) + { + for (pair = obj->u.map->pairs[i]; + (i != j) ? pair : pair->next; pair = pair->next) + { + svalue_to_string(&(pair->arg), str, size, indent + 2, 0); + stradd(str, &size, " : "); + svalue_to_string(&(pair->val), str, size, -indent - 2, 1); + } + } + if (pair) + { + svalue_to_string(&(pair->arg), str, size, indent + 2, 0); + stradd(str, &size, " : "); + svalue_to_string(&(pair->val), str, size, -indent - 2, 0); + } + stradd(str, &size, " ])"); + } + break; case T_FUNCTION: - stradd(str, &size, "<u.func)); - stradd(str, &size, ">>"); - break; + stradd(str, &size, "<u.func)); + stradd(str, &size, ">>"); + break; default: - stradd(str, &size, "!ERROR: GARBAGE SVALUE!"); + stradd(str, &size, "!ERROR: GARBAGE SVALUE!"); } /* end of switch (obj->type) */ if (trailing) stradd(str, &size, ",\n"); } /* end of svalue_to_string() */ @@ -425,68 +425,68 @@ add_justified(char *str, char *pad, unsigned int fs, format_info finfo, short tr switch(finfo & INFO_J) { case INFO_J_LEFT: - for (i = 0; i < len; i++) - ADD_CHAR(str[i]); - fs -= len; - len = strlen(pad); - if (trailing) - for (i = 0; fs > 0; i++, fs--) - { - if (pad[i%len] == '\\') - i++; - ADD_CHAR(pad[i % len]); - } - break; + for (i = 0; i < len; i++) + ADD_CHAR(str[i]); + fs -= len; + len = strlen(pad); + if (trailing) + for (i = 0; fs > 0; i++, fs--) + { + if (pad[i%len] == '\\') + i++; + ADD_CHAR(pad[i % len]); + } + break; case INFO_J_CENTRE: { - int j, l; - - l = strlen(pad); - j = (fs - len) / 2 + (fs - len) % 2; - for (i = 0; i < j; i++) - { - if (l && pad[i % l] == '\\') - { - i++; - j++; - } - ADD_CHAR(pad[i % l]); - } - for (i = 0; i < len; i++) - ADD_CHAR(str[i]); - j = (fs - len) / 2; - if (trailing) - for (i = 0; i < j; i++) - { - if (pad[i % l] == '\\') - { - i++; - j++; - } - ADD_CHAR(pad[i % l]); - } - break; + int j, l; + + l = strlen(pad); + j = (fs - len) / 2 + (fs - len) % 2; + for (i = 0; i < j; i++) + { + if (l && pad[i % l] == '\\') + { + i++; + j++; + } + ADD_CHAR(pad[i % l]); + } + for (i = 0; i < len; i++) + ADD_CHAR(str[i]); + j = (fs - len) / 2; + if (trailing) + for (i = 0; i < j; i++) + { + if (pad[i % l] == '\\') + { + i++; + j++; + } + ADD_CHAR(pad[i % l]); + } + break; } default: { /* std (s)printf defaults to right justification */ - int l; - + int l; + if (fs > len) fs -= len; else fs = 0; - l = strlen(pad); - for (i = 0; i < fs; i++) - { - if (pad[i % l] == '\\') - { - i++; - fs++; - } - ADD_CHAR(pad[i % l]); - } - for (i = 0; i < len; i++) - ADD_CHAR(str[i]); + l = strlen(pad); + for (i = 0; i < fs; i++) + { + if (pad[i % l] == '\\') + { + i++; + fs++; + } + ADD_CHAR(pad[i % l]); + } + for (i = 0; i < len; i++) + ADD_CHAR(str[i]); } } } /* end of add_justified() */ @@ -504,27 +504,27 @@ add_column(cst **column, short int trailing) unsigned int save; for (done = 0; - (done < (*column)->prec) && - ((*column)->d.col)[done] && - (((*column)->d.col)[done] != '\n'); - done++) - ; + (done < (*column)->prec) && + ((*column)->d.col)[done] && + (((*column)->d.col)[done] != '\n'); + done++) + ; if (((*column)->d.col)[done] && (((*column)->d.col)[done] != '\n')) { - save = done; - for ( ; done && (((*column)->d.col)[done] != ' '); done--) - ; - /* - * handle larger than column size words... - */ - if (!done) - done = save; + save = done; + for ( ; done && (((*column)->d.col)[done] != ' '); done--) + ; + /* + * handle larger than column size words... + */ + if (!done) + done = save; } save = ((*column)->d.col)[done]; ((*column)->d.col)[done] = '\0'; add_justified(((*column)->d.col), (*column)->pad, (*column)->size, - (*column)->info, - (trailing || ((*column)->next))); + (*column)->info, + (trailing || ((*column)->next))); ((*column)->d.col)[done] = save; ((*column)->d.col) += done; /* incremented below ... */ /* @@ -533,17 +533,17 @@ add_column(cst **column, short int trailing) */ if (!(*((*column)->d.col)) || !(*(++((*column)->d.col)))) { - cst *temp; - int ret; - - if (*(((*column)->d.col) - 1) == '\n') - ret = 2; - else - ret = 1; - temp = (*column)->next; - free((char *)(*column)); - (*column) = temp; - return ret; + cst *temp; + int ret; + + if (*(((*column)->d.col) - 1) == '\n') + ret = 2; + else + ret = 1; + temp = (*column)->next; + free((char *)(*column)); + (*column) = temp; + return ret; } return 0; } /* end of add_column() */ @@ -562,32 +562,32 @@ add_table(cst **table, short int trailing) for (i = 0; i < TAB->nocols && (TAB->d.tab[i]); i++) { - for (done = 0; ((TAB->d.tab[i])[done]) && - ((TAB->d.tab[i])[done] != '\n'); done++) - ; - save = (TAB->d.tab[i])[done]; - (TAB->d.tab[i])[done] = '\0'; - add_justified((TAB->d.tab[i]), TAB->pad, TAB->size, TAB->info, - (trailing || (i < TAB->nocols-1) || (TAB->next))); - (TAB->d.tab[i])[done] = save; - (TAB->d.tab[i]) += done; /* incremented next line ... */ - if (!(*(TAB->d.tab[i])) || !(*(++(TAB->d.tab[i])))) - (TAB->d.tab[i]) = 0; + for (done = 0; ((TAB->d.tab[i])[done]) && + ((TAB->d.tab[i])[done] != '\n'); done++) + ; + save = (TAB->d.tab[i])[done]; + (TAB->d.tab[i])[done] = '\0'; + add_justified((TAB->d.tab[i]), TAB->pad, TAB->size, TAB->info, + (trailing || (i < TAB->nocols-1) || (TAB->next))); + (TAB->d.tab[i])[done] = save; + (TAB->d.tab[i]) += done; /* incremented next line ... */ + if (!(*(TAB->d.tab[i])) || !(*(++(TAB->d.tab[i])))) + (TAB->d.tab[i]) = 0; } if (trailing && i < TAB->nocols) - for ( ; i < TAB->nocols; i++) - for (done = 0; done < TAB->size; done++) - ADD_CHAR(' '); + for ( ; i < TAB->nocols; i++) + for (done = 0; done < TAB->size; done++) + ADD_CHAR(' '); if (!TAB->d.tab[0]) { - cst *temp; - - temp = TAB->next; - if (TAB->d.tab) - free((char *) TAB->d.tab); - free((char *) TAB); - TAB = temp; - return 1; + cst *temp; + + temp = TAB->next; + if (TAB->d.tab) + free((char *) TAB->d.tab); + free((char *) TAB); + TAB = temp; + return 1; } return 0; } /* end of add_table() */ @@ -600,34 +600,34 @@ add_commas(char *strp) for (;;) { - if (*strp == '\0') - return; - if (isxdigit(*strp)) - break; - strp++; + if (*strp == '\0') + return; + if (isxdigit(*strp)) + break; + strp++; } for (n = 0; isxdigit(*strp); n++) - strp++; + strp++; c = (n - 1) / 3; if (c > 0) { - dp = strp + c; + dp = strp + c; - *dp = '\0'; + *dp = '\0'; - for (i = 0; i < n; i++) - { - *--dp = *--strp; - if (i % 3 == 2 && c != 0) - { - *--dp = ','; - if (--c == 0) - break; - } - } + for (i = 0; i < n; i++) + { + *--dp = *--strp; + if (i % 3 == 2 && c != 0) + { + *--dp = ','; + if (--c == 0) + break; + } + } } } @@ -642,15 +642,15 @@ char * string_print_formatted(int call_master, char *format_input, int argc, struct svalue *argv) { format_info finfo; - cst *csts; /* list of columns/tables to be done */ - struct svalue *carg; /* current arg */ - volatile unsigned int nelemno; /* next offset into array */ - unsigned int fpos; /* position in format_str */ - unsigned int arg; /* current arg number */ - unsigned int fs; /* field size */ - int prec; /* precision */ + cst *csts; /* list of columns/tables to be done */ + struct svalue *carg; /* current arg */ + volatile unsigned int nelemno; /* next offset into array */ + unsigned int fpos; /* position in format_str */ + unsigned int arg; /* current arg number */ + unsigned int fs; /* field size */ + int prec; /* precision */ unsigned int i; - char *pad; /* fs pad string */ + char *pad; /* fs pad string */ format_info format; char *format_str = string_copy(format_input); struct allocation_pool pool = EMPTY_ALLOCATION_POOL; @@ -658,87 +658,87 @@ string_print_formatted(int call_master, char *format_input, int argc, struct sva nelemno = 0; call_master_ob = call_master; if ((i = setjmp(error_jmp)) != 0) { /* error handling */ - char *err = NULL; + char *err = NULL; - if (clean) - { - free_svalue(clean); - free(clean); - clean = NULL; - } - while (saves) - { - savechars *tmp; + if (clean) + { + free_svalue(clean); + free(clean); + clean = NULL; + } + while (saves) + { + savechars *tmp; - *saves->where = saves->what; - tmp = saves; - saves = saves->next; - free(tmp); - } + *saves->where = saves->what; + tmp = saves; + saves = saves->next; + free(tmp); + } free(format_str); pool_free(&pool); - switch(i) - { - case ERR_BUFF_OVERFLOW: - err = "BUFF_SIZE overflowed..."; - break; - case ERR_TO_FEW_ARGS: - err = "More arguments specified than passed."; - break; - case ERR_INVALID_STAR: - err = "Incorrect argument type to *."; - break; - case ERR_PREC_EXPECTED: - err = "Expected precision not found."; - break; - case ERR_INVALID_FORMAT_STR: - err = "Error in format string."; - break; - case ERR_INCORRECT_ARG_S: - err = "Incorrect argument to type %s"; - break; - case ERR_CST_REQUIRES_FS: - err = "Column/table mode requires a field size."; - break; - case ERR_BAD_INT_TYPE: - err = "!feature - bad integer type!"; - break; - case ERR_UNDEFINED_TYPE: - err = "!feature - undefined type!"; - break; - case ERR_QUOTE_EXPECTED: - err = "Quote expected in format string."; - break; - case ERR_UNEXPECTED_EOS: - err = "Unexpected end of format string."; - break; - case ERR_NULL_PS: - err = "Null pad string specified."; - break; + switch(i) + { + case ERR_BUFF_OVERFLOW: + err = "BUFF_SIZE overflowed..."; + break; + case ERR_TO_FEW_ARGS: + err = "More arguments specified than passed."; + break; + case ERR_INVALID_STAR: + err = "Incorrect argument type to *."; + break; + case ERR_PREC_EXPECTED: + err = "Expected precision not found."; + break; + case ERR_INVALID_FORMAT_STR: + err = "Error in format string."; + break; + case ERR_INCORRECT_ARG_S: + err = "Incorrect argument to type %s"; + break; + case ERR_CST_REQUIRES_FS: + err = "Column/table mode requires a field size."; + break; + case ERR_BAD_INT_TYPE: + err = "!feature - bad integer type!"; + break; + case ERR_UNDEFINED_TYPE: + err = "!feature - undefined type!"; + break; + case ERR_QUOTE_EXPECTED: + err = "Quote expected in format string."; + break; + case ERR_UNEXPECTED_EOS: + err = "Unexpected end of format string."; + break; + case ERR_NULL_PS: + err = "Null pad string specified."; + break; case ERR_BAD_FLOAT_TYPE: err = "!feature - bad float type!"; break; - default: + default: #ifdef RETURN_ERROR_MESSAGES - (void)sprintf(buff, - "ERROR: (s)printf(): !feature - undefined error 0x%X !\n", i); - (void)fprintf(stderr, "%s:%s: %s", current_object->name, - get_srccode_position_if_any(), buff); - return buff; + (void)sprintf(buff, + "ERROR: (s)printf(): !feature - undefined error 0x%X !\n", i); + (void)fprintf(stderr, "%s:%s: %s", current_object->name, + get_srccode_position_if_any(), buff); + return buff; #else - error("ERROR: (s)printf(): !feature - undefined error 0x%X !\n", i); + error("ERROR: (s)printf(): !feature - undefined error 0x%X !\n", i); #endif /* RETURN_ERROR_MESSAGES */ - } + } #ifdef RETURN_ERROR_MESSAGES - (void)sprintf(buff, "ERROR: (s)printf(): %s\n", err); - (void)fprintf(stderr, "%s:%s: %s", current_object->name, - get_srccode_position_if_any(), buff); - return buff; + (void)sprintf(buff, "ERROR: (s)printf(): %s\n", err); + (void)fprintf(stderr, "%s:%s: %s", current_object->name, + get_srccode_position_if_any(), buff); + return buff; #else - error("ERROR: (s)printf(): %s\n", err); + error("ERROR: (s)printf(): %s\n", err); #endif /* RETURN_ERROR_MESSAGES */ } arg = (unsigned)-1; @@ -747,517 +747,517 @@ string_print_formatted(int call_master, char *format_input, int argc, struct sva csts = 0; for (fpos = 0 ;; fpos++) { - if ((format_str[fpos] == '\n') || (!format_str[fpos])) - { - int column_stat = 0; - - if (!csts) - { - if (!format_str[fpos]) - break; - ADD_CHAR('\n'); - curpos = 0; - continue; - } - ADD_CHAR('\n'); - curpos = 0; - while (csts) - { - cst **temp; - - temp = &csts; - while (*temp) - { - if ((*temp)->info & INFO_COLS) - { - if (*((*temp)->d.col-1) != '\n') - while (*((*temp)->d.col) == ' ') - (*temp)->d.col++; - for (i = curpos; i < (*temp)->start; i++) - ADD_CHAR(' '); - column_stat = add_column(temp, 0); - if (!column_stat) - temp = &((*temp)->next); - } - else - { - for (i = curpos; i < (*temp)->start; i++) - ADD_CHAR(' '); - if (!add_table(temp, 0)) - temp = &((*temp)->next); - } - } /* of while (*temp) */ - if (csts || format_str[fpos] == '\n') - ADD_CHAR('\n'); - curpos = 0; - } /* of while (csts) */ - if (column_stat == 2) - ADD_CHAR('\n'); - if (!format_str[fpos]) - break; - continue; - } - if (format_str[fpos] == '%') - { - if (format_str[fpos+1] == '%') - { - ADD_CHAR('%'); - fpos++; - continue; - } - GET_NEXT_ARG; - fs = 0; - prec = 0; - pad = " "; - finfo = 0; - for (fpos++; !(finfo & INFO_T); fpos++) - { - if (!format_str[fpos]) - { - finfo |= INFO_T_ERROR; - break; - } - if (((format_str[fpos] >= '0') && (format_str[fpos] <= '9')) - || (format_str[fpos] == '*')) - { - if (prec == -1) { /* then looking for prec */ - if (format_str[fpos] == '*') - { - if (carg->type != T_NUMBER) - ERROR(ERR_INVALID_STAR); - prec = carg->u.number; - GET_NEXT_ARG; - continue; - } - prec = format_str[fpos] - '0'; - for (fpos++; - (format_str[fpos] >= '0') && - (format_str[fpos] <= '9'); fpos++) - { - prec = prec*10 + format_str[fpos] - '0'; - } - } - else - { /* then is fs (and maybe prec) */ - if ((format_str[fpos] == '0') && - (((format_str[fpos+1] >= '1') && - (format_str[fpos+1] <= '9')) || - (format_str[fpos+1] == '*'))) - pad = "0"; - else - { - if (format_str[fpos] == '*') - { - if (carg->type != T_NUMBER) - ERROR(ERR_INVALID_STAR); - fs = carg->u.number; - if (prec == -2) - prec = fs; /* colon */ - GET_NEXT_ARG; - continue; - } - fs = format_str[fpos] - '0'; - } - for (fpos++; - (format_str[fpos]>='0') && - (format_str[fpos]<='9'); fpos++) - { - fs = fs*10 + format_str[fpos] - '0'; - } - if (prec == -2) - { /* colon */ - prec = fs; - } - } - fpos--; /* bout to get incremented */ - continue; - } - switch (format_str[fpos]) - { - case ' ': - finfo |= INFO_PP_SPACE; - break; - case '+': finfo |= INFO_PP_PLUS; break; - case '-': finfo |= INFO_J_LEFT; break; - case '|': finfo |= INFO_J_CENTRE; break; - case '@': finfo |= INFO_ARRAY; break; - case '=': finfo |= INFO_COLS; break; - case '#': finfo |= INFO_TABLE; break; - case ',': finfo |= INFO_COMMA; break; - case '.': prec = -1; break; - case ':': prec = -2; break; - case '%': finfo |= INFO_T_NULL; break; /* never reached */ - case 'O': finfo |= INFO_T_LPC; break; - case 's': finfo |= INFO_T_STRING; break; - case 'd': finfo |= INFO_T_INT; break; - case 'i': finfo |= INFO_T_INT; break; - case 'c': finfo |= INFO_T_CHAR; break; - case 'o': finfo |= INFO_T_OCT; break; - case 'x': finfo |= INFO_T_HEX; break; - case 'X': finfo |= INFO_T_C_HEX; break; - case 'e': finfo |= INFO_T_FLOAT_E; break; - case 'f': finfo |= INFO_T_FLOAT_F; break; - case 'g': finfo |= INFO_T_FLOAT_G; break; - case '\'': - pad = &(format_str[++fpos]); - for (;;) - { - if (!format_str[fpos]) - ERROR(ERR_UNEXPECTED_EOS); - if (format_str[fpos] == '\\') - { - fpos += 2; - continue; - } - if (format_str[fpos] == '\'') - { - if (format_str+fpos == pad) - ERROR(ERR_NULL_PS); - SAVE_CHAR(format_str + fpos); - format_str[fpos] = '\0'; - break; - } - fpos++; - } - break; - default: finfo |= INFO_T_ERROR; - } - } /* end of for () */ - if (prec < 0) - ERROR(ERR_PREC_EXPECTED); - /* - * now handle the different arg types... - */ - if (finfo & INFO_ARRAY) - { - if (carg->type != T_POINTER || carg->u.vec->size == 0) - { - fpos--; /* About to get incremented */ - continue; - } - carg = (argv + arg)->u.vec->item; - nelemno = 1; /* next element number */ - } - for (;;) - { - if ((finfo & INFO_T) == INFO_T_LPC) - { - clean = (struct svalue *)xalloc(sizeof(struct svalue)); - clean->type = T_STRING; - clean->string_type = STRING_MSTRING; - clean->u.string = allocate_mstring(512); - clean->u.string[0] = '\0'; - svalue_to_string(carg, &(clean->u.string), 512, 0, 0); - carg = clean; - - finfo ^= INFO_T_LPC; - finfo |= INFO_T_STRING; - } - if ((finfo & INFO_T) == INFO_T_ERROR) - { - ERROR(ERR_INVALID_FORMAT_STR); - } - else if ((finfo & INFO_T) == INFO_T_NULL) - { - /* never reached... */ - (void)fprintf(stderr, "%s: (s)printf: INFO_T_NULL.... found.\n", - current_object->name); - ADD_CHAR('%'); - } else if ((finfo & INFO_T) == INFO_T_STRING) - { - size_t slen; - - if (carg->type != T_STRING) - ERROR(ERR_INCORRECT_ARG_S); + if ((format_str[fpos] == '\n') || (!format_str[fpos])) + { + int column_stat = 0; + + if (!csts) + { + if (!format_str[fpos]) + break; + ADD_CHAR('\n'); + curpos = 0; + continue; + } + ADD_CHAR('\n'); + curpos = 0; + while (csts) + { + cst **temp; + + temp = &csts; + while (*temp) + { + if ((*temp)->info & INFO_COLS) + { + if (*((*temp)->d.col-1) != '\n') + while (*((*temp)->d.col) == ' ') + (*temp)->d.col++; + for (i = curpos; i < (*temp)->start; i++) + ADD_CHAR(' '); + column_stat = add_column(temp, 0); + if (!column_stat) + temp = &((*temp)->next); + } + else + { + for (i = curpos; i < (*temp)->start; i++) + ADD_CHAR(' '); + if (!add_table(temp, 0)) + temp = &((*temp)->next); + } + } /* of while (*temp) */ + if (csts || format_str[fpos] == '\n') + ADD_CHAR('\n'); + curpos = 0; + } /* of while (csts) */ + if (column_stat == 2) + ADD_CHAR('\n'); + if (!format_str[fpos]) + break; + continue; + } + if (format_str[fpos] == '%') + { + if (format_str[fpos+1] == '%') + { + ADD_CHAR('%'); + fpos++; + continue; + } + GET_NEXT_ARG; + fs = 0; + prec = 0; + pad = " "; + finfo = 0; + for (fpos++; !(finfo & INFO_T); fpos++) + { + if (!format_str[fpos]) + { + finfo |= INFO_T_ERROR; + break; + } + if (((format_str[fpos] >= '0') && (format_str[fpos] <= '9')) + || (format_str[fpos] == '*')) + { + if (prec == -1) { /* then looking for prec */ + if (format_str[fpos] == '*') + { + if (carg->type != T_NUMBER) + ERROR(ERR_INVALID_STAR); + prec = carg->u.number; + GET_NEXT_ARG; + continue; + } + prec = format_str[fpos] - '0'; + for (fpos++; + (format_str[fpos] >= '0') && + (format_str[fpos] <= '9'); fpos++) + { + prec = prec*10 + format_str[fpos] - '0'; + } + } + else + { /* then is fs (and maybe prec) */ + if ((format_str[fpos] == '0') && + (((format_str[fpos+1] >= '1') && + (format_str[fpos+1] <= '9')) || + (format_str[fpos+1] == '*'))) + pad = "0"; + else + { + if (format_str[fpos] == '*') + { + if (carg->type != T_NUMBER) + ERROR(ERR_INVALID_STAR); + fs = carg->u.number; + if (prec == -2) + prec = fs; /* colon */ + GET_NEXT_ARG; + continue; + } + fs = format_str[fpos] - '0'; + } + for (fpos++; + (format_str[fpos]>='0') && + (format_str[fpos]<='9'); fpos++) + { + fs = fs*10 + format_str[fpos] - '0'; + } + if (prec == -2) + { /* colon */ + prec = fs; + } + } + fpos--; /* bout to get incremented */ + continue; + } + switch (format_str[fpos]) + { + case ' ': + finfo |= INFO_PP_SPACE; + break; + case '+': finfo |= INFO_PP_PLUS; break; + case '-': finfo |= INFO_J_LEFT; break; + case '|': finfo |= INFO_J_CENTRE; break; + case '@': finfo |= INFO_ARRAY; break; + case '=': finfo |= INFO_COLS; break; + case '#': finfo |= INFO_TABLE; break; + case ',': finfo |= INFO_COMMA; break; + case '.': prec = -1; break; + case ':': prec = -2; break; + case '%': finfo |= INFO_T_NULL; break; /* never reached */ + case 'O': finfo |= INFO_T_LPC; break; + case 's': finfo |= INFO_T_STRING; break; + case 'd': finfo |= INFO_T_INT; break; + case 'i': finfo |= INFO_T_INT; break; + case 'c': finfo |= INFO_T_CHAR; break; + case 'o': finfo |= INFO_T_OCT; break; + case 'x': finfo |= INFO_T_HEX; break; + case 'X': finfo |= INFO_T_C_HEX; break; + case 'e': finfo |= INFO_T_FLOAT_E; break; + case 'f': finfo |= INFO_T_FLOAT_F; break; + case 'g': finfo |= INFO_T_FLOAT_G; break; + case '\'': + pad = &(format_str[++fpos]); + for (;;) + { + if (!format_str[fpos]) + ERROR(ERR_UNEXPECTED_EOS); + if (format_str[fpos] == '\\') + { + fpos += 2; + continue; + } + if (format_str[fpos] == '\'') + { + if (format_str+fpos == pad) + ERROR(ERR_NULL_PS); + SAVE_CHAR(format_str + fpos); + format_str[fpos] = '\0'; + break; + } + fpos++; + } + break; + default: finfo |= INFO_T_ERROR; + } + } /* end of for () */ + if (prec < 0) + ERROR(ERR_PREC_EXPECTED); + /* + * now handle the different arg types... + */ + if (finfo & INFO_ARRAY) + { + if (carg->type != T_POINTER || carg->u.vec->size == 0) + { + fpos--; /* About to get incremented */ + continue; + } + carg = (argv + arg)->u.vec->item; + nelemno = 1; /* next element number */ + } + for (;;) + { + if ((finfo & INFO_T) == INFO_T_LPC) + { + clean = (struct svalue *)xalloc(sizeof(struct svalue)); + clean->type = T_STRING; + clean->string_type = STRING_MSTRING; + clean->u.string = allocate_mstring(512); + clean->u.string[0] = '\0'; + svalue_to_string(carg, &(clean->u.string), 512, 0, 0); + carg = clean; + + finfo ^= INFO_T_LPC; + finfo |= INFO_T_STRING; + } + if ((finfo & INFO_T) == INFO_T_ERROR) + { + ERROR(ERR_INVALID_FORMAT_STR); + } + else if ((finfo & INFO_T) == INFO_T_NULL) + { + /* never reached... */ + (void)fprintf(stderr, "%s: (s)printf: INFO_T_NULL.... found.\n", + current_object->name); + ADD_CHAR('%'); + } else if ((finfo & INFO_T) == INFO_T_STRING) + { + size_t slen; + + if (carg->type != T_STRING) + ERROR(ERR_INCORRECT_ARG_S); - slen = strlen(carg->u.string); + slen = strlen(carg->u.string); char *input_copy = pool_alloc(&pool, slen + 1); strncpy(input_copy, carg->u.string, slen + 1); - if ((finfo & INFO_COLS) || (finfo & INFO_TABLE)) - { - cst **temp; - - if (!fs) - ERROR(ERR_CST_REQUIRES_FS); - - temp = &csts; - while (*temp) - temp = &((*temp)->next); - if (finfo & INFO_COLS) - { - *temp = (cst *)xalloc(sizeof(cst)); - (*temp)->next = 0; + if ((finfo & INFO_COLS) || (finfo & INFO_TABLE)) + { + cst **temp; + + if (!fs) + ERROR(ERR_CST_REQUIRES_FS); + + temp = &csts; + while (*temp) + temp = &((*temp)->next); + if (finfo & INFO_COLS) + { + *temp = (cst *)xalloc(sizeof(cst)); + (*temp)->next = 0; (*temp)->d.col = input_copy; - (*temp)->pad = pad; - (*temp)->size = fs; - (*temp)->prec = (prec) ? prec : fs; - (*temp)->info = finfo; - (*temp)->start = curpos; + (*temp)->pad = pad; + (*temp)->size = fs; + (*temp)->prec = (prec) ? prec : fs; + (*temp)->info = finfo; + (*temp)->start = curpos; if ((add_column(temp, (((format_str[fpos] != '\n') && (format_str[fpos] != '\0')) || ((finfo & INFO_ARRAY) && (nelemno < (argv+arg)->u.vec->size)))) == 2) && !format_str[fpos]) - { - ADD_CHAR('\n'); - } - } - else - { /* (finfo & INFO_TABLE) */ - unsigned int n, len, max; - - (*temp) = (cst *)xalloc(sizeof(cst)); - (*temp)->pad = pad; - (*temp)->info = finfo; - (*temp)->start = curpos; - (*temp)->next = 0; - max = len = 0; - n = 1; - for (i = 0; input_copy[i]; i++) - { - if (input_copy[i] == '\n') - { - if (len > max) - max = len; - len = 0; - if (input_copy[i + 1]) - n++; - continue; - } - len++; - } - if (prec) - { - (*temp)->size = fs/prec; - } - else - { - if (len > max) - max = len; /* the null terminated word */ - prec = fs/(max+2); /* at least two separating spaces */ - if (!prec) - prec = 1; - (*temp)->size = fs / prec; - } - len = n / prec; /* length of average column */ - if (n < prec) - prec = n; - if (len * prec < n) - len++; - if (len > 1 && n % prec) - prec -= (prec - n % prec) / len; - (*temp)->d.tab = (char **)xalloc(prec*sizeof(char *)); - (*temp)->nocols = prec; /* heavy sigh */ - (*temp)->d.tab[0] = input_copy; - if (prec == 1) - goto add_table_now; - i = 1; /* the next column number */ - n = 0; /* the current "word" number in this column */ - for (fs = 0; input_copy[fs]; fs++) - { /* throwing away fs... */ - if (input_copy[fs] == '\n') - { - if (++n >= len) - { - input_copy[fs] = '\0'; - (*temp)->d.tab[i++] = input_copy + fs + 1; - if (i >= prec) - goto add_table_now; - n = 0; - } - } - } - add_table_now: - (void)add_table(temp, (((format_str[fpos] != '\n') && - (format_str[fpos] != '\0')) || - ((finfo & INFO_ARRAY) && - (nelemno < (argv + arg)->u.vec->size)))); - } - } - else - { /* not column or table */ - if (prec && prec < slen) - { - input_copy[prec] = '\0'; - slen = prec; - } - if (fs && fs > slen) { + { + ADD_CHAR('\n'); + } + } + else + { /* (finfo & INFO_TABLE) */ + unsigned int n, len, max; + + (*temp) = (cst *)xalloc(sizeof(cst)); + (*temp)->pad = pad; + (*temp)->info = finfo; + (*temp)->start = curpos; + (*temp)->next = 0; + max = len = 0; + n = 1; + for (i = 0; input_copy[i]; i++) + { + if (input_copy[i] == '\n') + { + if (len > max) + max = len; + len = 0; + if (input_copy[i + 1]) + n++; + continue; + } + len++; + } + if (prec) + { + (*temp)->size = fs/prec; + } + else + { + if (len > max) + max = len; /* the null terminated word */ + prec = fs/(max+2); /* at least two separating spaces */ + if (!prec) + prec = 1; + (*temp)->size = fs / prec; + } + len = n / prec; /* length of average column */ + if (n < prec) + prec = n; + if (len * prec < n) + len++; + if (len > 1 && n % prec) + prec -= (prec - n % prec) / len; + (*temp)->d.tab = (char **)xalloc(prec*sizeof(char *)); + (*temp)->nocols = prec; /* heavy sigh */ + (*temp)->d.tab[0] = input_copy; + if (prec == 1) + goto add_table_now; + i = 1; /* the next column number */ + n = 0; /* the current "word" number in this column */ + for (fs = 0; input_copy[fs]; fs++) + { /* throwing away fs... */ + if (input_copy[fs] == '\n') + { + if (++n >= len) + { + input_copy[fs] = '\0'; + (*temp)->d.tab[i++] = input_copy + fs + 1; + if (i >= prec) + goto add_table_now; + n = 0; + } + } + } + add_table_now: + (void)add_table(temp, (((format_str[fpos] != '\n') && + (format_str[fpos] != '\0')) || + ((finfo & INFO_ARRAY) && + (nelemno < (argv + arg)->u.vec->size)))); + } + } + else + { /* not column or table */ + if (prec && prec < slen) + { + input_copy[prec] = '\0'; + slen = prec; + } + if (fs && fs > slen) { add_justified(input_copy, pad, fs, finfo, ( ((format_str[fpos] != '\n') && (format_str[fpos] != '\0')) - || ((finfo & INFO_ARRAY) && (nelemno < (argv + arg)->u.vec->size)) + || ((finfo & INFO_ARRAY) && (nelemno < (argv + arg)->u.vec->size)) ) || (slen > 0 && (input_copy[slen - 1] != '\n'))); - } - else - { - for (i = 0; i < slen; i++) - ADD_CHAR(input_copy[i]); - } - } - } else if (finfo & INFO_T_INT) { /* one of the integer types */ - char temp[100]; - - if (carg->type != T_NUMBER) - { /* sigh... */ + } + else + { + for (i = 0; i < slen; i++) + ADD_CHAR(input_copy[i]); + } + } + } else if (finfo & INFO_T_INT) { /* one of the integer types */ + char temp[100]; + + if (carg->type != T_NUMBER) + { /* sigh... */ #ifdef RETURN_ERROR_MESSAGES - (void)sprintf(buff, - "ERROR: (s)printf(): incorrect argument type to %%d.\n"); - (void)fprintf(stderr, "%s:%s: %s", current_object->name, - get_srccode_position_if_any(), buff); - return buff; + (void)sprintf(buff, + "ERROR: (s)printf(): incorrect argument type to %%d.\n"); + (void)fprintf(stderr, "%s:%s: %s", current_object->name, + get_srccode_position_if_any(), buff); + return buff; #else - error("ERROR: (s)printf(): incorrect argument type to %%d.\n"); + error("ERROR: (s)printf(): incorrect argument type to %%d.\n"); #endif /* RETURN_ERROR_MESSAGES */ - } - format = finfo & INFO_T; - if (format == INFO_T_INT) - switch (finfo & INFO_PP) - { - case INFO_PP_SPACE: - sprintf(temp, "% lld", carg->u.number); - break; - case INFO_PP_PLUS: - sprintf(temp, "%+lld", carg->u.number); - break; - default: - sprintf(temp, "%lld", carg->u.number); - } - else if (format == INFO_T_CHAR) - sprintf(temp, "%c", (int)carg->u.number); - else if (format == INFO_T_OCT) - sprintf(temp, "%llo", carg->u.number); - else if (format == INFO_T_HEX) - sprintf(temp, "%llx", carg->u.number); - else if (format == INFO_T_C_HEX) - sprintf(temp, "%llX", carg->u.number); - else { - ERROR(ERR_BAD_INT_TYPE); - } - if (finfo & INFO_COMMA) - add_commas(temp); - { - int tmpl = strlen(temp); + } + format = finfo & INFO_T; + if (format == INFO_T_INT) + switch (finfo & INFO_PP) + { + case INFO_PP_SPACE: + sprintf(temp, "% lld", carg->u.number); + break; + case INFO_PP_PLUS: + sprintf(temp, "%+lld", carg->u.number); + break; + default: + sprintf(temp, "%lld", carg->u.number); + } + else if (format == INFO_T_CHAR) + sprintf(temp, "%c", (int)carg->u.number); + else if (format == INFO_T_OCT) + sprintf(temp, "%llo", carg->u.number); + else if (format == INFO_T_HEX) + sprintf(temp, "%llx", carg->u.number); + else if (format == INFO_T_C_HEX) + sprintf(temp, "%llX", carg->u.number); + else { + ERROR(ERR_BAD_INT_TYPE); + } + if (finfo & INFO_COMMA) + add_commas(temp); + { + int tmpl = strlen(temp); - if (prec && tmpl > prec) { - temp[prec] = '\0'; /* well.... */ + if (prec && tmpl > prec) { + temp[prec] = '\0'; /* well.... */ tmpl = prec; } - if (tmpl < fs) - add_justified(temp, pad, fs, finfo, - (((format_str[fpos] != '\n') && - (format_str[fpos] != '\0')) || - ((finfo & INFO_ARRAY) && - (nelemno < (argv+arg)->u.vec->size)))); - else - for (i = 0; i < tmpl; i++) - ADD_CHAR(temp[i]); - } - } - else if ((i=finfo&INFO_T) == INFO_T_FLOAT_E || - i == INFO_T_FLOAT_F || i == INFO_T_FLOAT_G) - { - char temp[100]; + if (tmpl < fs) + add_justified(temp, pad, fs, finfo, + (((format_str[fpos] != '\n') && + (format_str[fpos] != '\0')) || + ((finfo & INFO_ARRAY) && + (nelemno < (argv+arg)->u.vec->size)))); + else + for (i = 0; i < tmpl; i++) + ADD_CHAR(temp[i]); + } + } + else if ((i=finfo&INFO_T) == INFO_T_FLOAT_E || + i == INFO_T_FLOAT_F || i == INFO_T_FLOAT_G) + { + char temp[100]; - if (carg->type != T_FLOAT) - { /* sigh... */ + if (carg->type != T_FLOAT) + { /* sigh... */ #ifdef RETURN_ERROR_MESSAGES - (void)sprintf(buff, - "ERROR: (s)printf(): incorrect argument type to %%f.\n"); - (void)fprintf(stderr, "%s:%s: %s", current_object->name, - get_srccode_position_if_any(), buff); - return buff; + (void)sprintf(buff, + "ERROR: (s)printf(): incorrect argument type to %%f.\n"); + (void)fprintf(stderr, "%s:%s: %s", current_object->name, + get_srccode_position_if_any(), buff); + return buff; #else - error("ERROR: (s)printf(): incorrect argument type to %%f.\n"); + error("ERROR: (s)printf(): incorrect argument type to %%f.\n"); #endif /* RETURN_ERROR_MESSAGES */ - } + } - if (prec <= 0) - prec = 6; - format = finfo & INFO_T; - if (format == INFO_T_FLOAT_E) - switch (finfo & INFO_PP) { - case INFO_PP_SPACE: - (void)sprintf(temp,"% .*e",prec, carg->u.real); - break; - case INFO_PP_PLUS: - (void)sprintf(temp,"%+.*e",prec, carg->u.real); - break; - default: - (void)sprintf(temp,"%.*e",prec, carg->u.real); - break; - } - else if (format == INFO_T_FLOAT_F) - switch (finfo & INFO_PP) { - case INFO_PP_SPACE: - (void)sprintf(temp,"% .*f",prec, carg->u.real); - break; - case INFO_PP_PLUS: - (void)sprintf(temp,"%+.*f",prec, carg->u.real); - break; - default: - (void)sprintf(temp,"%.*f",prec, carg->u.real); - break; - } - else if (format == INFO_T_FLOAT_G) - switch (finfo & INFO_PP) { - case INFO_PP_SPACE: - (void)sprintf(temp,"% .*g",prec, carg->u.real); - break; - case INFO_PP_PLUS: - (void)sprintf(temp,"%+.*g",prec, carg->u.real); - break; - default: - (void)sprintf(temp,"%.*g",prec, carg->u.real); - break; - } - else { - ERROR(ERR_BAD_FLOAT_TYPE); - } - { - int tmpl = strlen(temp); - - if (tmpl < fs) - add_justified(temp, pad, fs, finfo, - (((format_str[fpos] != '\n') && - (format_str[fpos] != '\0')) || - ((finfo & INFO_ARRAY) && - (nelemno < (argv+arg)->u.vec->size)))); - else - for (i = 0; i < tmpl; i++) - ADD_CHAR(temp[i]); - } - } - else /* type not found */ - ERROR(ERR_UNDEFINED_TYPE); + if (prec <= 0) + prec = 6; + format = finfo & INFO_T; + if (format == INFO_T_FLOAT_E) + switch (finfo & INFO_PP) { + case INFO_PP_SPACE: + (void)sprintf(temp,"% .*e",prec, carg->u.real); + break; + case INFO_PP_PLUS: + (void)sprintf(temp,"%+.*e",prec, carg->u.real); + break; + default: + (void)sprintf(temp,"%.*e",prec, carg->u.real); + break; + } + else if (format == INFO_T_FLOAT_F) + switch (finfo & INFO_PP) { + case INFO_PP_SPACE: + (void)sprintf(temp,"% .*f",prec, carg->u.real); + break; + case INFO_PP_PLUS: + (void)sprintf(temp,"%+.*f",prec, carg->u.real); + break; + default: + (void)sprintf(temp,"%.*f",prec, carg->u.real); + break; + } + else if (format == INFO_T_FLOAT_G) + switch (finfo & INFO_PP) { + case INFO_PP_SPACE: + (void)sprintf(temp,"% .*g",prec, carg->u.real); + break; + case INFO_PP_PLUS: + (void)sprintf(temp,"%+.*g",prec, carg->u.real); + break; + default: + (void)sprintf(temp,"%.*g",prec, carg->u.real); + break; + } + else { + ERROR(ERR_BAD_FLOAT_TYPE); + } + { + int tmpl = strlen(temp); + + if (tmpl < fs) + add_justified(temp, pad, fs, finfo, + (((format_str[fpos] != '\n') && + (format_str[fpos] != '\0')) || + ((finfo & INFO_ARRAY) && + (nelemno < (argv+arg)->u.vec->size)))); + else + for (i = 0; i < tmpl; i++) + ADD_CHAR(temp[i]); + } + } + else /* type not found */ + ERROR(ERR_UNDEFINED_TYPE); - if (clean) - { - free_svalue(clean); - free(clean); - clean = 0; - } - if (!(finfo & INFO_ARRAY)) - break; - if (nelemno >= (argv+arg)->u.vec->size) - break; - carg = (argv + arg)->u.vec->item + nelemno++; - } /* end of while (1) */ - fpos--; /* bout to get incremented */ - continue; - } - ADD_CHAR(format_str[fpos]); + if (clean) + { + free_svalue(clean); + free(clean); + clean = 0; + } + if (!(finfo & INFO_ARRAY)) + break; + if (nelemno >= (argv+arg)->u.vec->size) + break; + carg = (argv + arg)->u.vec->item + nelemno++; + } /* end of while (1) */ + fpos--; /* bout to get incremented */ + continue; + } + ADD_CHAR(format_str[fpos]); } /* end of for (fpos = 0; 1; fpos++) */ ADD_CHAR('\0'); while (saves) { - savechars *tmp; - *(saves->where) = saves->what; - tmp = saves; - saves = saves->next; - free((char *)tmp); + savechars *tmp; + *(saves->where) = saves->what; + tmp = saves; + saves = saves->next; + free((char *)tmp); } pool_free(&pool); diff --git a/super_snoop.c b/super_snoop.c index fcd4ef8..0994bdf 100644 --- a/super_snoop.c +++ b/super_snoop.c @@ -41,22 +41,22 @@ update_snoop_file() int i, j; for (i = 0; num_super_snooped && i < MAX_PLAYERS; i++) - if (all_players[i] && all_players[i]->snoop_fd >= 0) { - (void)close(all_players[i]->snoop_fd); - all_players[i]->snoop_fd = -1; - num_super_snooped--; - } + if (all_players[i] && all_players[i]->snoop_fd >= 0) { + (void)close(all_players[i]->snoop_fd); + all_players[i]->snoop_fd = -1; + num_super_snooped--; + } read_snoop_file(); for (i = 0; i < MAX_PLAYERS; i++) - for (j = 0; j < num_super_snooped; j++) - if (all_players[i] && all_players[i]->ob && - all_players[i]->ob->living_name && - strcmp(all_players[i]->ob->living_name, super_snooped[j]) == 0) { - all_players[i]->snoop_fd = open(super_snoopfile[j], - O_WRONLY | O_APPEND | O_CREAT, - 0600); - break; - } + for (j = 0; j < num_super_snooped; j++) + if (all_players[i] && all_players[i]->ob && + all_players[i]->ob->living_name && + strcmp(all_players[i]->ob->living_name, super_snooped[j]) == 0) { + all_players[i]->snoop_fd = open(super_snoopfile[j], + O_WRONLY | O_APPEND | O_CREAT, + 0600); + break; + } } void @@ -65,20 +65,20 @@ check_supersnoop(struct object *ob) int i; if (!ob || !ob->interactive) - return; + return; if (ob->interactive->snoop_fd >= 0) { - (void)close(ob->interactive->snoop_fd); - ob->interactive->snoop_fd = -1; + (void)close(ob->interactive->snoop_fd); + ob->interactive->snoop_fd = -1; } if (!ob->living_name || !*ob->living_name) - return; + return; for (i = 0; i < num_super_snooped; i++) { - if (strcmp(ob->living_name, super_snooped[i]) == 0) { - ob->interactive->snoop_fd = open(super_snoopfile[i], O_WRONLY | O_APPEND | O_CREAT, 0600); - break; - } + if (strcmp(ob->living_name, super_snooped[i]) == 0) { + ob->interactive->snoop_fd = open(super_snoopfile[i], O_WRONLY | O_APPEND | O_CREAT, 0600); + break; + } } } #endif diff --git a/tcpsvc.c b/tcpsvc.c index 9307ef4..942d9d3 100644 --- a/tcpsvc.c +++ b/tcpsvc.c @@ -51,7 +51,7 @@ #include "tcpsvc.h" #ifndef EPROTO -#define EPROTO EPROTOTYPE +#define EPROTO EPROTOTYPE #endif #ifdef SERVICE_PORT @@ -64,9 +64,9 @@ * TCP Service Control Block. */ typedef struct { - u_char ts_flags; - nqueue_t * ts_canq; - nqueue_t * ts_rawq; + u_char ts_flags; + nqueue_t * ts_canq; + nqueue_t * ts_rawq; ndesc_t * ts_nd; struct task *task; } tcpsvc_t; @@ -74,18 +74,18 @@ typedef struct { /* * TCP Service Flags. */ -#define TF_CLOSE 0x01 +#define TF_CLOSE 0x01 /* * Queue Sizes. */ -#define TCPSVC_RAWQ_SIZE 32768 -#define TCPSVC_CANQ_SIZE 32768 +#define TCPSVC_RAWQ_SIZE 32768 +#define TCPSVC_CANQ_SIZE 32768 /* * Maximum # of concurrent TCP Service. */ -#define TCPSVC_MAX 32 +#define TCPSVC_MAX 32 // static ndesc_t *tcpsvc_nd = NULL; static int tcpsvc_count = 0; @@ -142,7 +142,7 @@ static void tcpsvc_shutdown(ndesc_t *nd, tcpsvc_t *tsp) { if (tsp) - tsp->ts_flags |= TF_CLOSE; + tsp->ts_flags |= TF_CLOSE; } static void @@ -161,17 +161,17 @@ tcpsvc_process(void *vp) nd_detach(tsp->ts_nd); tcpsvc_free(tsp); tcpsvc_count--; - return; + return; } update_tcp_av(); if (nq_full(tsp->ts_canq)) { - nq_init(tsp->ts_canq); - nq_puts(tsp->ts_canq, (u_char *)"ERROR Service request too long.\n"); - tcpsvc_disconnect(tsp->ts_nd, tsp); - return; + nq_init(tsp->ts_canq); + nq_puts(tsp->ts_canq, (u_char *)"ERROR Service request too long.\n"); + tcpsvc_disconnect(tsp->ts_nd, tsp); + return; } @@ -182,12 +182,12 @@ tcpsvc_process(void *vp) if (setjmp(exception_frame.e_context) == 0) { - push_string((char *)nq_rptr(tsp->ts_canq), STRING_MSTRING); - svp = apply_master_ob(M_INCOMING_SERVICE, 1); + push_string((char *)nq_rptr(tsp->ts_canq), STRING_MSTRING); + svp = apply_master_ob(M_INCOMING_SERVICE, 1); } else { - svp = NULL; + svp = NULL; } exception = exception->e_exception; @@ -196,16 +196,16 @@ tcpsvc_process(void *vp) if (svp == NULL || svp->type != T_STRING) { - nq_puts(tsp->ts_canq, (u_char *)"ERROR Service calls not supported.\n"); - tcpsvc_disconnect(tsp->ts_nd, tsp); - return; + nq_puts(tsp->ts_canq, (u_char *)"ERROR Service calls not supported.\n"); + tcpsvc_disconnect(tsp->ts_nd, tsp); + return; } if (strlen(svp->u.string) > nq_size(tsp->ts_canq)) { - nq_puts(tsp->ts_canq, (u_char *)"ERROR Service response too long.\n"); - tcpsvc_disconnect(tsp->ts_nd, tsp); - return; + nq_puts(tsp->ts_canq, (u_char *)"ERROR Service response too long.\n"); + tcpsvc_disconnect(tsp->ts_nd, tsp); + return; } nq_puts(tsp->ts_canq, (u_char *)svp->u.string); @@ -222,49 +222,49 @@ tcpsvc_read(ndesc_t *nd, tcpsvc_t *tsp) if (!nq_full(tsp->ts_rawq)) { - cc = nq_recv(tsp->ts_rawq, nd_fd(nd), NULL); - if (cc == -1) - { - switch (errno) - { - case EWOULDBLOCK: - case EINTR: - case EPROTO: - break; - - default: - tcpsvc_disconnect(nd, tsp); + cc = nq_recv(tsp->ts_rawq, nd_fd(nd), NULL); + if (cc == -1) + { + switch (errno) + { + case EWOULDBLOCK: + case EINTR: + case EPROTO: + break; + + default: + tcpsvc_disconnect(nd, tsp); nd_disable(nd, ND_W); - tsp->task = create_task(tcpsvc_process, tsp); - return; - } - } - - if (cc == 0) - { - tcpsvc_disconnect(nd, tsp); + tsp->task = create_task(tcpsvc_process, tsp); + return; + } + } + + if (cc == 0) + { + tcpsvc_disconnect(nd, tsp); nd_disable(nd, ND_W); - tsp->task = create_task(tcpsvc_process, tsp); - return; - } + tsp->task = create_task(tcpsvc_process, tsp); + return; + } } for (;;) { - if (nq_empty(tsp->ts_rawq)) - { - nq_init(tsp->ts_rawq); - return; - } - c = nq_getc(tsp->ts_rawq); - if (c == '\n') - break; - if (!nq_full(tsp->ts_canq)) - nq_putc(tsp->ts_canq, c); + if (nq_empty(tsp->ts_rawq)) + { + nq_init(tsp->ts_rawq); + return; + } + c = nq_getc(tsp->ts_rawq); + if (c == '\n') + break; + if (!nq_full(tsp->ts_canq)) + nq_putc(tsp->ts_canq, c); } nd_disable(tsp->ts_nd, ND_R); if (!nq_full(tsp->ts_canq)) - nq_putc(tsp->ts_canq, '\0'); + nq_putc(tsp->ts_canq, '\0'); tsp->task = create_task(tcpsvc_process, tsp); } @@ -276,25 +276,25 @@ tcpsvc_write(ndesc_t *nd, tcpsvc_t *tsp) { if (!nq_empty(tsp->ts_canq)) { - if (nq_send(tsp->ts_canq, nd_fd(nd), NULL) == -1) - { - switch (errno) - { - case EWOULDBLOCK: - case EINTR: - case EPROTO: - break; - - default: + if (nq_send(tsp->ts_canq, nd_fd(nd), NULL) == -1) + { + switch (errno) + { + case EWOULDBLOCK: + case EINTR: + case EPROTO: + break; + + default: tcpsvc_disconnect(nd, tsp); nd_disable(nd, ND_W); - tsp->task = create_task(tcpsvc_process, tsp); - return; - } - } + tsp->task = create_task(tcpsvc_process, tsp); + return; + } + } - if (!nq_empty(tsp->ts_canq)) - return; + if (!nq_empty(tsp->ts_canq)) + return; } nq_init(tsp->ts_canq); @@ -303,8 +303,8 @@ tcpsvc_write(ndesc_t *nd, tcpsvc_t *tsp) if (tsp->ts_flags & TF_CLOSE) { - tsp->task = create_task(tcpsvc_process, tsp); - return; + tsp->task = create_task(tcpsvc_process, tsp); + return; } nd_enable(nd, ND_R); } @@ -331,15 +331,15 @@ tcpsvc_accept(void *vp) s = accept(nd_fd(nd), (struct sockaddr *)&addr, &addrlen); if (s == -1) { - switch (errno) - { - default: - fatal("svc_server: accept() errno = %d.\n", errno); - case EWOULDBLOCK: - case EINTR: - case EPROTO: - return; - } + switch (errno) + { + default: + fatal("svc_server: accept() errno = %d.\n", errno); + case EWOULDBLOCK: + case EINTR: + case EPROTO: + return; + } } getnameinfo((struct sockaddr *)&addr, addrlen, host, sizeof(host), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV); @@ -375,10 +375,10 @@ tcpsvc_accept(void *vp) if (++tcpsvc_count > TCPSVC_MAX) { - nq_puts(tsp->ts_canq, (u_char *)"ERROR Too many services in use.\n"); - nd_enable(tsp->ts_nd, ND_W); - tcpsvc_disconnect(tsp->ts_nd, tsp); - return; + nq_puts(tsp->ts_canq, (u_char *)"ERROR Too many services in use.\n"); + nd_enable(tsp->ts_nd, ND_W); + tcpsvc_disconnect(tsp->ts_nd, tsp); + return; } nd_enable(tsp->ts_nd, ND_R); } @@ -403,7 +403,7 @@ tcpsvc_init(u_short port_nr) ndesc_t *nd; if (service_port < 0) - return; + return; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; diff --git a/telnet.c b/telnet.c index a79aa27..ff540ee 100644 --- a/telnet.c +++ b/telnet.c @@ -54,7 +54,7 @@ #include "backend.h" #ifndef EPROTO -#define EPROTO EPROTOTYPE +#define EPROTO EPROTOTYPE #endif /* @@ -64,16 +64,16 @@ /* * Queue Sizes. */ -#define TELNET_CANQ_SIZE (1024 * 8) -#define TELNET_RAWQ_SIZE (1024 * 4) -#define TELNET_OPTQ_SIZE (1024) -#define TELNET_OUTQ_SIZE (32*1024) +#define TELNET_CANQ_SIZE (1024 * 8) +#define TELNET_RAWQ_SIZE (1024 * 4) +#define TELNET_OPTQ_SIZE (1024) +#define TELNET_OUTQ_SIZE (32*1024) /* * Output Queue Flow Control Parameters. */ -#define TELNET_OUTQ_LOWAT (TELNET_OUTQ_SIZE/2) -#define TELNET_OUTQ_HIWAT (TELNET_OUTQ_SIZE - 256) +#define TELNET_OUTQ_LOWAT (TELNET_OUTQ_SIZE/2) +#define TELNET_OUTQ_HIWAT (TELNET_OUTQ_SIZE - 256) /* * The following parameter specifies the minimum number of bytes that must @@ -82,7 +82,7 @@ * TELNET command. N.B. Do not change this unless you know what you * are doing! */ -#define TELNET_OUTQ_REQUIRED 12 +#define TELNET_OUTQ_REQUIRED 12 /* * The folowing parameters are used to set the kernel socket buffer @@ -90,18 +90,18 @@ * and receive buffers to 4k. It makes more sense to increase the * send size and reduce the receive size for a MUD. */ -#define TELNET_RCVBUF_SIZE 2048 -#define TELNET_SNDBUF_SIZE TELNET_OUTQ_SIZE +#define TELNET_RCVBUF_SIZE 2048 +#define TELNET_SNDBUF_SIZE TELNET_OUTQ_SIZE /* * ASCII Definitions. */ -#define NUL 0 -#define BEL 7 -#define BS 8 -#define LF 10 -#define CR 13 -#define DEL 127 +#define NUL 0 +#define BEL 7 +#define BS 8 +#define LF 10 +#define CR 13 +#define DEL 127 #define TRUNCATED "*** Truncated. ***\r\n" diff --git a/telnet.h b/telnet.h index 1996aa2..b0247eb 100644 --- a/telnet.h +++ b/telnet.h @@ -33,32 +33,32 @@ * Telnet Option Block. */ typedef struct { - u_char o_us; - u_char o_usq; - u_char o_him; - u_char o_himq; + u_char o_us; + u_char o_usq; + u_char o_him; + u_char o_himq; } opt_t; /* * Option States. */ -#define OS_NO 0 -#define OS_YES 1 -#define OS_WANTNO 2 -#define OS_WANTYES 3 +#define OS_NO 0 +#define OS_YES 1 +#define OS_WANTNO 2 +#define OS_WANTYES 3 /* * Option Queue States. */ -#define OQ_EMPTY 0 -#define OQ_OPPOSITE 2 +#define OQ_EMPTY 0 +#define OQ_OPPOSITE 2 /* * Options. */ -#define OP_ECHO 0 -#define OP_SGA 1 -#define OP_CDM 2 +#define OP_ECHO 0 +#define OP_SGA 1 +#define OP_CDM 2 #define OP_GMCP 3 #define OP_MSSP 4 #define OP_CHARSET 5 @@ -68,56 +68,56 @@ typedef struct { * Telnet Control Block. */ typedef struct { - u_short t_flags; - u_char t_state; - u_char t_opt; - opt_t t_optb[OP_SIZE]; - ndesc_t * t_nd; - nqueue_t * t_rawq; - nqueue_t * t_canq; nqueue_t * t_optq; - nqueue_t * t_outq; - void * t_ip; - u_int t_rblen; - u_int t_sblen; + u_short t_flags; + u_char t_state; + u_char t_opt; + opt_t t_optb[OP_SIZE]; + ndesc_t * t_nd; + nqueue_t * t_rawq; + nqueue_t * t_canq; nqueue_t * t_optq; + nqueue_t * t_outq; + void * t_ip; + u_int t_rblen; + u_int t_sblen; struct task *task; } telnet_t; /* * Telnet Flags. */ -#define TF_ATTACH 0x0001 +#define TF_ATTACH 0x0001 #define TF_INPUT 0x0002 #define TF_DISCONNECT 0x0004 -#define TF_OVFLCANQ 0x0010 -#define TF_OVFLOPTQ 0x0020 -#define TF_OVFLOUTQ 0x0040 -#define TF_SYNCH 0x0080 -#define TF_URGENT 0x0100 -#define TF_GA 0x0200 -#define TF_ECHO 0x1000 -#define TF_SGA 0x2000 +#define TF_OVFLCANQ 0x0010 +#define TF_OVFLOPTQ 0x0020 +#define TF_OVFLOUTQ 0x0040 +#define TF_SYNCH 0x0080 +#define TF_URGENT 0x0100 +#define TF_GA 0x0200 +#define TF_ECHO 0x1000 +#define TF_SGA 0x2000 #define TF_GMCP 0x4000 /* * Telnet Input States. */ -#define TS_DATA 0 -#define TS_CR 1 -#define TS_IAC 2 -#define TS_IAC_SB 3 -#define TS_IAC_SB_DATA 4 -#define TS_IAC_SB_IAC 5 -#define TS_IAC_WILL 6 -#define TS_IAC_WONT 7 -#define TS_IAC_DO 8 -#define TS_IAC_DONT 9 +#define TS_DATA 0 +#define TS_CR 1 +#define TS_IAC 2 +#define TS_IAC_SB 3 +#define TS_IAC_SB_DATA 4 +#define TS_IAC_SB_IAC 5 +#define TS_IAC_WILL 6 +#define TS_IAC_WONT 7 +#define TS_IAC_DO 8 +#define TS_IAC_DONT 9 #define TELOPT_CHARSET 42 #define TELOPT_MSSP 70 #define TELOPT_GMCP 201 -#define TELOPT_CDM 205 +#define TELOPT_CDM 205 /* * MSSP Data Block diff --git a/udpsvc.c b/udpsvc.c index bf5e729..079174f 100644 --- a/udpsvc.c +++ b/udpsvc.c @@ -49,7 +49,7 @@ #ifdef CATCH_UDP_PORT #ifndef INADDR_NONE -#define INADDR_NONE 0xffffffff +#define INADDR_NONE 0xffffffff #endif /* @@ -59,7 +59,7 @@ /* * Maximum UDP Datagram Size. */ -#define UDPSVC_RAWQ_SIZE 1024 +#define UDPSVC_RAWQ_SIZE 1024 /* * Send a UDP datagram. @@ -71,7 +71,7 @@ udpsvc_send(udpsvc_t *svc, char *dest, int port, char *cp) int cc; if (udpsvc_nd == NULL || port < 0) - return 0; + return 0; memset(&addr, 0, sizeof (addr)); addr.sin_family = AF_INET; @@ -81,19 +81,19 @@ udpsvc_send(udpsvc_t *svc, char *dest, int port, char *cp) if (addr.sin_addr.s_addr == INADDR_NONE) { #ifdef UDP_SEND_HOSTNAME - struct hostent *hp; + struct hostent *hp; - hp = gethostbyname(addr); - if (hp == NULL) - return 0; - memcpy(&addr.sin_addr, hp->h_addr, hp->h_length); + hp = gethostbyname(addr); + if (hp == NULL) + return 0; + memcpy(&addr.sin_addr, hp->h_addr, hp->h_length); #else - return 0; + return 0; #endif } cc = sendto(nd_fd(svc->nd), cp, strlen(cp), 0, - (struct sockaddr *)&addr, sizeof (addr)); + (struct sockaddr *)&addr, sizeof (addr)); return cc != -1; } @@ -106,10 +106,10 @@ read_datagram(udpsvc_t *svc) /* Get another datagram */ cc = recvfrom(nd_fd(svc->nd), nq_wptr(svc->nq), nq_size(svc->nq) - 1, 0, - (struct sockaddr *)&addr, &addrlen); + (struct sockaddr *)&addr, &addrlen); if (cc == -1) { - return 0; + return 0; } nq_wptr(svc->nq)[cc] = '\0'; @@ -134,17 +134,17 @@ udpsvc_process(udpsvc_t *svc) if (setjmp(exception_frame.e_context) == 0) { - push_string(inet_ntoa(addr.sin_addr), STRING_MSTRING); - push_string((char *)nq_rptr(svc->nq), STRING_MSTRING); - (void)apply_master_ob(M_INCOMING_UDP, 2); + push_string(inet_ntoa(addr.sin_addr), STRING_MSTRING); + push_string((char *)nq_rptr(svc->nq), STRING_MSTRING); + (void)apply_master_ob(M_INCOMING_UDP, 2); } exception = exception->e_exception; addrlen = sizeof (addr); if (!read_datagram(svc)) { - nd_enable(svc->nd, ND_R); - svc->task = 0; - return; + nd_enable(svc->nd, ND_R); + svc->task = 0; + return; } reschedule_task(svc->task); } @@ -160,8 +160,8 @@ udpsvc_read(ndesc_t *nd, udpsvc_t *svc) struct gdexception exception_frame; if (read_datagram(svc)) { - nd_disable(udpsvc_nd, ND_R); - svc->task = create_task(udpsvc_process); + nd_disable(udpsvc_nd, ND_R); + svc->task = create_task(udpsvc_process); } } @@ -189,7 +189,7 @@ udpsvc_init(int port) s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (s == -1) - fatal("udp_init: socket() error = %d.\n", errno); + fatal("udp_init: socket() error = %d.\n", errno); enable_reuseaddr(s); @@ -200,17 +200,17 @@ udpsvc_init(int port) if (bind(s, (struct sockaddr *)&addr, sizeof (addr)) == -1) { - if (errno == EADDRINUSE) - { - (void)fprintf(stderr, "UDP Socket already bound!\n"); - debug_message("UDP Socket already bound!\n"); - (void)close(s); - return 0; - } - else - { - fatal("udp_init: bind() error = %d.\n", errno); - } + if (errno == EADDRINUSE) + { + (void)fprintf(stderr, "UDP Socket already bound!\n"); + debug_message("UDP Socket already bound!\n"); + (void)close(s); + return 0; + } + else + { + fatal("udp_init: bind() error = %d.\n", errno); + } } enable_nbio(s); diff --git a/wildmat.c b/wildmat.c index 90440f0..f0ba695 100644 --- a/wildmat.c +++ b/wildmat.c @@ -11,9 +11,9 @@ ** ** Special thanks to Lars Mathiesen for the ABORT code. ** This can greatly speed up failing wildcard patterns. For example: -** pattern: -*-*-*-*-*-*-12-*-*-*-m-*-*-* -** text 1: -adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1 -** text 2: -adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1 +** pattern: -*-*-*-*-*-*-12-*-*-*-m-*-*-* +** text 1: -adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1 +** text 2: -adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1 ** Text 1 matches with 51 calls, while text 2 fails with 54 calls. Without ** the ABORT code, it takes 22310 calls to fail. Ugh. The following ** explanation is from Lars: @@ -38,13 +38,13 @@ int wildmat(char *, char *); static int DoMatch(char *, char *); -#define TRUE 1 -#define FALSE 0 -#define ABORT -1 +#define TRUE 1 +#define FALSE 0 +#define ABORT -1 /* What character marks an inverted character class? */ -#define NEGATE_CLASS '^' +#define NEGATE_CLASS '^' /* Is "*" a common pattern? */ #define OPTIMIZE_JUST_STAR /* Do tar(1) matching rules, which ignore a trailing slash? */ @@ -56,63 +56,63 @@ static int DoMatch(char *, char *); */ static int DoMatch(text, p) - register char *text; - register char *p; + register char *text; + register char *p; { - register int last; - register int matched; - register int reverse; + register int last; + register int matched; + register int reverse; for ( ; *p; text++, p++) { - if (*text == '\0' && *p != '*') - return ABORT; - switch (*p) { - case '\\': - /* Literal match with following character. */ - p++; - /* FALLTHROUGH */ - default: - if (*text != *p) - return FALSE; - continue; - case '?': - /* Match anything. */ - continue; - case '*': - while (*++p == '*') - /* Consecutive stars act just like one. */ - continue; - if (*p == '\0') - /* Trailing star matches everything. */ - return TRUE; - while (*text) - if ((matched = DoMatch(text++, p)) != FALSE) - return matched; - return ABORT; - case '[': - reverse = p[1] == NEGATE_CLASS ? TRUE : FALSE; - if (reverse) - /* Inverted character class. */ - p++; - matched = FALSE; - if (p[1] == ']' || p[1] == '-') - if (*++p == *text) - matched = TRUE; - for (last = *p; *++p && *p != ']'; last = *p) - /* This next line requires a good C compiler. */ - if (*p == '-' && p[1] != ']' - ? *text <= *++p && *text >= last : *text == *p) - matched = TRUE; - if (matched == reverse) - return FALSE; - continue; - } + if (*text == '\0' && *p != '*') + return ABORT; + switch (*p) { + case '\\': + /* Literal match with following character. */ + p++; + /* FALLTHROUGH */ + default: + if (*text != *p) + return FALSE; + continue; + case '?': + /* Match anything. */ + continue; + case '*': + while (*++p == '*') + /* Consecutive stars act just like one. */ + continue; + if (*p == '\0') + /* Trailing star matches everything. */ + return TRUE; + while (*text) + if ((matched = DoMatch(text++, p)) != FALSE) + return matched; + return ABORT; + case '[': + reverse = p[1] == NEGATE_CLASS ? TRUE : FALSE; + if (reverse) + /* Inverted character class. */ + p++; + matched = FALSE; + if (p[1] == ']' || p[1] == '-') + if (*++p == *text) + matched = TRUE; + for (last = *p; *++p && *p != ']'; last = *p) + /* This next line requires a good C compiler. */ + if (*p == '-' && p[1] != ']' + ? *text <= *++p && *text >= last : *text == *p) + matched = TRUE; + if (matched == reverse) + return FALSE; + continue; + } } -#ifdef MATCH_TAR_PATTERN +#ifdef MATCH_TAR_PATTERN if (*text == '/') - return TRUE; -#endif /* MATCH_TAR_ATTERN */ + return TRUE; +#endif /* MATCH_TAR_ATTERN */ return *text == '\0'; } @@ -122,53 +122,53 @@ DoMatch(text, p) */ int wildmat(text, p) - char *text; - char *p; + char *text; + char *p; { -#ifdef OPTIMIZE_JUST_STAR +#ifdef OPTIMIZE_JUST_STAR if (p[0] == '*' && p[1] == '\0') - return TRUE; -#endif /* OPTIMIZE_JUST_STAR */ + return TRUE; +#endif /* OPTIMIZE_JUST_STAR */ return DoMatch(text, p) == TRUE; } -#if defined(TEST) +#if defined(TEST) #include /* Yes, we use gets not fgets. Sue me. */ -extern char *gets(); +extern char *gets(); int main() { - char p[80]; - char text[80]; + char p[80]; + char text[80]; (void)printf("Wildmat tester. Enter pattern, then strings to test.\n"); (void)printf("A blank line gets prompts for a new pattern; a blank pattern\n"); (void)printf("exits the program.\n"); for ( ; ; ) { - (void)printf("\nEnter pattern: "); - (void)fflush(stdout); - if (gets(p) == NULL || p[0] == '\0') - break; - for ( ; ; ) { - (void)printf("Enter text: "); - (void)fflush(stdout); - if (gets(text) == NULL) - exit(0); - if (text[0] == '\0') - /* Blank line; go back and get a new pattern. */ - break; - (void)printf(" %s\n", wildmat(text, p) ? "YES" : "NO"); - } + (void)printf("\nEnter pattern: "); + (void)fflush(stdout); + if (gets(p) == NULL || p[0] == '\0') + break; + for ( ; ; ) { + (void)printf("Enter text: "); + (void)fflush(stdout); + if (gets(text) == NULL) + exit(0); + if (text[0] == '\0') + /* Blank line; go back and get a new pattern. */ + break; + (void)printf(" %s\n", wildmat(text, p) ? "YES" : "NO"); + } } exit(0); /* NOTREACHED */ } -#endif /* defined(TEST) */ +#endif /* defined(TEST) */