void more_variables () { int indx; int old_count; bc_var **old_var; char **old_names; /* Save the old values. */ old_count = v_count; old_var = variables; old_names = v_names; /* Increment by a fixed amount and allocate. */ v_count += STORE_INCR; variables = (bc_var **) bc_malloc (v_count*sizeof(bc_var *)); v_names = (char **) bc_malloc (v_count*sizeof(char *)); /* Copy the old variables. */ for (indx = 3; indx < old_count; indx++) variables[indx] = old_var[indx]; /* Initialize the new elements. */ for (; indx < v_count; indx++) variables[indx] = NULL; /* Free the old elements. */ if (old_count != 0) { free (old_var); free (old_names); } }
void more_arrays () { int indx; int old_count; bc_var_array **old_ary; char **old_names; /* Save the old values. */ old_count = a_count; old_ary = arrays; old_names = a_names; /* Increment by a fixed amount and allocate. */ a_count += STORE_INCR; arrays = (bc_var_array **) bc_malloc (a_count*sizeof(bc_var_array *)); a_names = (char **) bc_malloc (a_count*sizeof(char *)); /* Copy the old arrays. */ for (indx = 1; indx < old_count; indx++) arrays[indx] = old_ary[indx]; /* Initialize the new elements. */ for (; indx < v_count; indx++) arrays[indx] = NULL; /* Free the old elements. */ if (old_count != 0) { free (old_ary); free (old_names); } }
static char * make_arg_str (arg_list *args, int len) { char *temp; char sval[30]; /* Recursive call. */ if (args != NULL) temp = make_arg_str (args->next, len+12); else { temp = bc_malloc (len); *temp = 0; return temp; } /* Add the current number to the end of the string. */ if (args->arg_is_var) if (len != 1) snprintf (sval, sizeof(sval), "*%d,", args->av_name); else snprintf (sval, sizeof(sval), "*%d", args->av_name); else if (len != 1) snprintf (sval, sizeof(sval), "%d,", args->av_name); else snprintf (sval, sizeof(sval), "%d", args->av_name); temp = strcat (temp, sval); return (temp); }
void more_functions (VOID) { int old_count; int indx1, indx2; bc_function *old_f; bc_function *f; char **old_names; /* Save old information. */ old_count = f_count; old_f = functions; old_names = f_names; /* Add a fixed amount and allocate new space. */ f_count += STORE_INCR; functions = (bc_function *) bc_malloc (f_count*sizeof (bc_function)); f_names = (char **) bc_malloc (f_count*sizeof (char *)); /* Copy old ones. */ for (indx1 = 0; indx1 < old_count; indx1++) { functions[indx1] = old_f[indx1]; f_names[indx1] = old_names[indx1]; } /* Initialize the new ones. */ for (; indx1 < f_count; indx1++) { f = &functions[indx1]; f->f_defined = FALSE; for (indx2 = 0; indx2 < BC_MAX_SEGS; indx2++) f->f_body [indx2] = NULL; f->f_code_size = 0; f->f_label = NULL; f->f_autos = NULL; f->f_params = NULL; } /* Free the old elements. */ if (old_count != 0) { free (old_f); free (old_names); } }
char * strcopyof (const char *str) { char *temp; temp = bc_malloc (strlen (str)+1); return (strcpy (temp,str)); }
/* genstr management to avoid buffer overflow. */ void set_genstr_size (int size) { if (size > genlen) { if (genstr != NULL) free(genstr); genstr = bc_malloc (size); genlen = size; } }
arg_list * nextarg (arg_list *args, int val, int is_var) { arg_list *temp; temp = bc_malloc (sizeof (arg_list)); temp->av_name = val; temp->arg_is_var = is_var; temp->next = args; return (temp); }
int bm_httpd_run(bm_ctx_t **ctx, bm_rule_exec_func_t rule_exec, bc_slist_t *outputs, bc_trie_t *args) { // this is here to avoid that the httpd starts running in the middle of the // first build, as the reloader and the httpd are started in parallel. // we run the task synchronously for the first time, and start the httpd // thread afterwards. bool wait_before_reloader = false; if (0 != rule_exec(*ctx, outputs, args)) { fprintf(stderr, "blogc-make: warning: failed to rebuild website. " "retrying in 5 seconds ...\n\n"); wait_before_reloader = true; } int err; pthread_attr_t attr; if (0 != (err = pthread_attr_init(&attr))) { fprintf(stderr, "blogc-make: error: failed to initialize httpd " "thread attributes: %s\n", strerror(err)); return 1; } // we run the thread detached, because we don't want to wait it to join // before exiting. the OS can clean it properly if (0 != (err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED))) { fprintf(stderr, "blogc-make: error: failed to mark httpd thread as " "detached: %s\n", strerror(err)); return 1; } bm_httpd_t *rv = bc_malloc(sizeof(bm_httpd_t)); rv->ctx = *ctx; rv->args = args; pthread_t thread; if (0 != (err = pthread_create(&thread, &attr, httpd_thread, rv))) { fprintf(stderr, "blogc-make: error: failed to create httpd " "thread: %s\n", strerror(err)); free(rv); return 1; } // run the reloader if (wait_before_reloader) { sleep(5); } return bm_reloader_run(ctx, rule_exec, outputs, args); }
char * call_str (arg_list *args) { arg_list *temp; int arg_count; int ix; if (arglist2 != NULL) free (arglist2); arglist2 = arglist1; /* Count the number of args and add the 0's and 1's. */ for (temp = args, arg_count = 0; temp != NULL; temp = temp->next) arg_count++; arglist1 = bc_malloc(arg_count+1); for (temp = args, ix=0; temp != NULL; temp = temp->next) arglist1[ix++] = ( temp->av_name ? '1' : '0'); arglist1[ix] = 0; return (arglist1); }
void *bc_realloc (void *buf, size_t size) { struct buffcontainernode_t *currnode; if (!buf) return bc_malloc (size); else { currnode = findNode (buf); if (currnode) { void *temp = realloc (currnode->data, size); if (temp) currnode->data = temp; else return NULL; } else return NULL; } return currnode->data; }
int lookup (char *name, int namekind) { id_rec *id; /* Warn about non-standard name. */ if (strlen(name) != 1) ct_warn ("multiple letter name - %s", name); /* Look for the id. */ id = find_id (name_tree, name); if (id == NULL) { /* We need to make a new item. */ id = bc_malloc (sizeof (id_rec)); id->id = strcopyof (name); id->a_name = 0; id->f_name = 0; id->v_name = 0; insert_id_rec (&name_tree, id); } /* Return the correct value. */ switch (namekind) { case ARRAY: /* ARRAY variable numbers are returned as negative numbers. */ if (id->a_name != 0) { free (name); return (-id->a_name); } id->a_name = next_array++; if (id->a_name < MAX_STORE) { if (id->a_name >= a_count) more_arrays (); a_names[id->a_name] = name; return (-id->a_name); } yyerror ("Too many array variables"); bc_exit (1); /*NOTREACHED*/ case FUNCT: case FUNCTDEF: if (id->f_name != 0) { free(name); /* Check to see if we are redefining a math lib function. */ if (use_math && namekind == FUNCTDEF && id->f_name <= 6) id->f_name = next_func++; return (id->f_name); } id->f_name = next_func++; if (id->f_name < MAX_STORE) { if (id->f_name >= f_count) more_functions (); f_names[id->f_name] = name; return (id->f_name); } yyerror ("Too many functions"); bc_exit (1); /*NOTREACHED*/ case SIMPLE: if (id->v_name != 0) { free(name); return (id->v_name); } id->v_name = next_var++; if (id->v_name <= MAX_STORE) { if (id->v_name >= v_count) more_variables (); v_names[id->v_name - 1] = name; return (id->v_name); } yyerror ("Too many variables"); bc_exit (1); /*NOTREACHED*/ } yyerror ("End of util.c/lookup() reached. Please report this bug."); bc_exit (1); /*NOTREACHED*/ }