void cf_init(void) { if (cf_filename == NULL) { cf_filename = defs_mopherd_conf; } //char buffer[4096]; cf_config = vtable_create("config", VF_KEEPNAME); if (cf_config == NULL) { log_die(EX_CONFIG, "cf_init: vtable_create failed"); } //var_dump(cf_config, buffer, sizeof(buffer)); //printf(buffer); cf_load_defaults(); cf_load_file(cf_filename); cf_load_functions(); cf_load_symbols(); return; }
void cf_set_keylist(var_t *table, ll_t *keys, var_t *v) { char *key; var_t *sub; if (table == NULL) { table = cf_config; } /* * Last key queued belongs to var_t *v itself. */ key = LL_DEQUEUE(keys); if(keys->ll_size == 0) { /* * keys is created in cf_yacc.y and no longer needed. */ ll_delete(keys, NULL); if(v->v_name == NULL) { v->v_name = key; } if(vtable_set(table, v) == -1) { log_die(EX_CONFIG, "cf_set: vtable_set failed"); } return; } if((sub = vtable_lookup(table, key))) { cf_set_keylist(sub, keys, v); /* * key is strdupd in cf_yacc.y and no longer needed. */ free(key); return; } if ((sub = vtable_create(key, 0)) == NULL) { log_die(EX_CONFIG, "cf_setr: vtable_create failed"); } if(vtable_set(table, sub) == -1) { log_die(EX_CONFIG, "cf_set: vtable_set failed"); } cf_set_keylist(sub, keys, v); return; }
int main(int argc, char **argv) { int res = 0; void *root=NULL; int root_type=0; res = parse(argv[1], &root, &root_type); if(res == 0) { printf("Hex Parsing successful.\n"); } else if(res == 1) { printf("Hex Parse error!!!\n"); exit(EXIT_FAILURE); } else if(res == 2) { printf("Hex insufficient memory for parsing!\n"); exit(EXIT_FAILURE); } HEX_ASSERT(root); HEX_ASSERT(root_type); /* semantics analysis... */ RETURN_VAL_IF_NE(root_type, HEX_PARSE_TREE_ROOT_TYPE_STMT_GROUP, 0); Vtable vtable = vtable_create(); StmtGroup stmt_group = (StmtGroup)root; hex_scope_type_t scope_type = HEX_VAR_SCOPE_TYPE_LOCAL; unsigned int indent_level = 1; HEX_ASSERT(vtable); HEX_ASSERT(stmt_group); hex_semantics_check_stmt_group(vtable, stmt_group, scope_type, indent_level); return 0; }