static void rules_read (s_rules *rr, const char *path) { FILE *fp; char line[2048]; syslog(LOG_DEBUG, "READ %s", path); fp = fopen(path, "r"); if (!fp) { syslog(LOG_ERR, "rules_read: %s: %s", path, strerror(errno)); err(3, "rules_read: %s", path); } while (fgets(line, sizeof(line) - 4, fp)) { s_rule r; syslog(LOG_DEBUG, "LINE %s", line); rule_init(&r); rule_read(&r, line); if (r.count >= 2) { log_rule("RULE", &r); rules_add(rr, &r); } else if (r.count == 1) syslog(LOG_WARNING, "invalid rule: %s", line); } if (ferror(fp)) { syslog(LOG_ERR, "rules_read: %s: %s", path, strerror(errno)); fclose(fp); err(3, "rules_read: %s", path); } fclose(fp); }
Wht * node_init(size_t n, char *name) { Wht *W; size_t i; W = (Wht *) i_malloc(sizeof(Wht)); W->N = (1 << n); W->n = n; W->apply = null_apply; W->error_msg = NULL; W->left = W->N; W->right = 1; W->parent = NULL; W->children = NULL; W->to_string = NULL; W->rule = rule_init(name); for (i = 0; i < MAX_ATTRIBUTES; i++) W->attr[i] = UNSET_ATTRIBUTE; for (i = 0; i < MAX_ATTRIBUTES; i++) { W->provides[i] = false; W->requires[i] = false; } return W; }
GSList * rule_get_available_rules (void) { if (!ruleFunctions) rule_init (); return ruleFunctions; }
void new_target(char * target){ rule_struct * myRule= calloc(1,sizeof(rule_struct)); myRule->rule= malloc(sizeof(rule_t)); myRule->ready= 0; rule_init(myRule->rule); myRule->rule->target= strdup(target); queue_enqueue(&rulesQueue, myRule); queue_enqueue(&allRules, myRule); }
void parsed_new_target ( char *target ) /**PART2**/ { rule_t * q1 = malloc(sizeof(rule_t)); rule_init(q1); q1->target = malloc( sizeof(char)* (strlen(target) + 1) ); strcpy(q1->target, target); queue_enqueue(&q,q1); remain_size++; }
/* creates a target and adds to queue. * * @param - string name of target * @return - nothing? function type still requires the void pointer */ void* parsed_new_target(char *target) { rule_t *temp=malloc(sizeof(rule_t)); rule_init(temp); temp->target=target; queue_enqueue(rules, temp); queue_enqueue(rulesDup, temp); return NULL; }
void parsed_new_targer(char *target) { char *temp = malloc(strlen(target)+1); strcpy(temp, target); rule_t *rule = malloc(sizeof(rule_t)); rule_init(rule); rule->target = temp; queue_enqueue(all_rules, rule); queue_enqueue(all_targets, temp); }
int main(int argc, const char ** argv) { int res = 1; config_t config; rule_info_t rule; DEHT * deht = NULL; if (argc != 2) { fprintf(stderr, "Usage: %s <prefix>\n", argv[0]); goto cleanup0; } if (config_load(&config, argv[1]) != INI_STATUS_OK) { /* error message printed by config_load */ goto cleanup0; } if (rule_init(&rule, config.rule_pattern, config.lexicon_file) != RULE_STATUS_OK) { /* error message printed by rule_init */ goto cleanup1; } deht = create_empty_DEHT(config.prefix, my_hash_func, my_valid_func, config.num_of_buckets, config.bucket_size, 8, config.hash_name); if (deht == NULL) { /* error message printed by create_empty_DEHT */ goto cleanup2; } if (rainbow_generate_seed_table(&config) != RAINBOW_STATUS_OK) { /* error message printed by rainbow_generate_seed_table */ goto cleanup3; } res = generate_all_chains(&config, &rule, deht); cleanup3: close_DEHT_files(deht); cleanup2: rule_finalize(&rule); cleanup1: config_finalize(&config); cleanup0: return res; }
int main(int argc, char **argv) { int ch; const char *conffile; conffile = CONFFILE; while ((ch = getopt(argc, argv, "f:v")) != -1) { switch (ch) { case 'f': conffile = optarg; break; case 'v': verbose++; break; default: usage(); /* NOTREACHED */ } } bzero(&config, sizeof(config)); config.print.feedlines = -1; config.print.cchide_customer = 1; config.print.ccsig_customer = 1; bzero(&header, sizeof(header)); if (parse_config(conffile)) exit(1); /* set database files */ if (config.database.custdb == NULL) if ((config.database.custdb = strdup(config.database.alldb ? config.database.alldb : CUSTDBFILE)) == NULL) err(1, "cannot set customer database file"); if (config.database.menudb == NULL) if ((config.database.menudb = strdup(config.database.alldb ? config.database.alldb : MENUDBFILE)) == NULL) err(1, "cannot set menu database file"); if (config.database.orderdb == NULL) if ((config.database.orderdb = strdup(config.database.alldb ? config.database.alldb : ORDERDBFILE)) == NULL) err(1, "cannot set order database file"); if (config.print.feedlines < 0) config.print.feedlines = PRINT_FEED_LINES; if (licence_init() == -1) errx(1, "cannot proceed without licence"); event_init(); module_init(); rule_init(); input_init(); print_init(); form_init(); display_init(); status_init(); menu_init(); customer_init(); special_init(); payment_init(); window_init(); order_init(); display_refresh(); signal(SIGPIPE, SIG_IGN); if (event_dispatch() == -1) err(1, "terminated abnormally"); if (exitcode != 0 && exitmsg == NULL) exitmsg = strdup(status.status); order_exit(); window_exit(); payment_exit(); special_exit(); customer_exit(); menu_exit(); status_exit(); display_exit(); form_exit(); print_exit(); input_exit(); rule_exit(); module_exit(); if (exitcode && exitmsg != NULL) errx(exitcode, "%s", exitmsg); else fprintf(stdout, "exiting normally\n"); exit(0); }
static void cmd_init (s_symtable *cmd, t_sym id, const char *arg) { rule_init(cmd); rule_add(cmd, id); rule_read(cmd, arg); }
/** * Parses makeFileName based on GNU 'make' utility. * * @param makeFileName Path to valid makefile. * @param run_targets Null-terminated list of targets as listed on command-line. * @param parsed_new_target Function pointer to callback function for new target. * @param parsed_new_dependency Function pointer to callback function for new dependency. * @param parsed_new_command Function pointer to callback function for new command. * @return Void. */ void parser_parse_makefile ( const char *makeFileName, char **run_targets, void (*parsed_new_target)(char *target), void (*parsed_new_dependency)(char *target, char *dependency), void (*parsed_new_command)(char *target, char *command) ) { boolean run_targetsMalloced = False; FILE *f = fopen(makeFileName, "r"); assert(f != NULL); queue_t *rules = malloc(sizeof(queue_t)); queue_init(rules); queue_t curRules; queue_init(&curRules); char *lineBuf = NULL; size_t bytes; size_t len; while((len = getline(&lineBuf, &bytes, f)) != -1){ if(len && lineBuf[len-1] == '\n'){ lineBuf[--len] = '\0'; if(len && lineBuf[len-1] == '\r') lineBuf[--len] = '\0'; } if(isalnum(lineBuf[0])){ char *depLine = strstr(lineBuf, ":"); assert(depLine != NULL); depLine[0] = '\0'; depLine = depLine + 1; //insert prev Rule to queue int ruleIdx; for(ruleIdx=0; ruleIdx < queue_size(&curRules); ruleIdx++){ queue_enqueue(rules, queue_at(&curRules,ruleIdx)); } queue_destroy(&curRules); queue_init(&curRules); char **targets = parse_line(lineBuf); int tarIdx; for(tarIdx=0; targets[tarIdx] != NULL; tarIdx++){ rule_t *newRule = malloc(sizeof(rule_t)); rule_init(newRule); char *target = strdup(targets[tarIdx]); newRule->target = target; queue_enqueue(&curRules, newRule); } if(run_targets == NULL || run_targets[0] == NULL){ run_targetsMalloced = True; run_targets = calloc(sizeof(char *), tarIdx + 1); int rtIdx; for(rtIdx=0; rtIdx < tarIdx; rtIdx++) run_targets[rtIdx] = strdup(targets[rtIdx]); } free(targets); char **deps = parse_line(depLine); int depIdx; for(depIdx=0; deps[depIdx] != NULL; depIdx++){ int ruleIdx; for(ruleIdx=0; ruleIdx < queue_size(&curRules); ruleIdx++){ rule_t *curRule = queue_at(&curRules, ruleIdx); char *dep = strdup(deps[depIdx]); queue_enqueue(curRule->deps, dep); } } free(deps); } else if(lineBuf[0] == '\t') { assert(queue_size(&curRules) != 0); //command without target int idx; for(idx=0; idx < queue_size(&curRules); idx++){ rule_t *curRule = queue_at(&curRules, idx); char *command = strdup(lineBuf + 1); queue_enqueue(curRule->commands, command); } }else { ;//ignore line } } int ruleIdx; for(ruleIdx=0; ruleIdx < queue_size(&curRules); ruleIdx++){ queue_enqueue(rules, queue_at(&curRules, ruleIdx)); } queue_destroy(&curRules); //No longer need curRules filterOnTargets(&rules, run_targets); //send callbacks notifyRules(rules, parsed_new_target, parsed_new_dependency, parsed_new_command); //cleanup queue_iterate(rules, rule_free_adapter, 0); queue_destroy(rules); if(run_targetsMalloced){ int tarIdx; for(tarIdx=0; run_targets[tarIdx] != NULL; tarIdx++) free(run_targets[tarIdx]); free(run_targets); } free(lineBuf); free(rules); fclose(f); }