void assembler_run(const char *out_file) { compiler_descriptor_t c_descr; memset(&c_descr, 0, sizeof(compiler_descriptor_t)); FILE *of = fopen(out_file, "wb"); if (of == NULL) { printf("compiler error: error on opening output file ...\n"); return; } token_list_t *list = tokenizer_run(ASM_DESCR.MAIN_FILE); if (parser_run(list, &c_descr) == 1) { printf("compiler error: can't compile (parser error) ...\n"); return; } int compile_size = -1; if ((compile_size = fmt_compile(of, &c_descr, list)) != -1) { if (ferror(of) || fclose(of) == EOF) { printf("compiler error: error on closing output-file ...\n"); return; } printf("compiler success: written buffer into output-file ...\n"); printf("-----------------------------------------------------\n"); printf("output format: %s\n", ASM_DESCR.format); printf("output length: %u byte/s\n", compile_size); } }
static int preproc_rule_preprocess(token_t *tok, token_rule_t *rule) { if (tok->type == KEYWORD_INCLUDE_PREPROC) { int i; token_t *arg = tok_get_token(tok, 1); if (tok_strlen(arg) == 2) { sprintf(COMP_DESCR.err_msg, "illegal file name ..."); return 0; } char *f_name = (char*)malloc(tok_strlen(arg) - 1); for (i = arg->f_char + 1; i < arg->l_char - 1; i++) f_name[i - arg->f_char - 1] = tok->str->ptr[i]; f_name[i - arg->f_char - 1] = '\0'; char *f_buffer = f_load_file(f_name); if (f_buffer == NULL) { sprintf(COMP_DESCR.err_msg, "file not found [file: %s] ...", f_name); return 0; } f_header_t *file = f_parse_text(f_name, f_buffer); token_t *f_tokens = tokenizer_run(file); if (f_tokens == NULL) { printf("preprocessor warning: file '%s' is empty\n", f_name); return 1; } tok_insert_tokens(arg, f_tokens); } else if (tok->type == KEYWORD_ENTRY_PREPROC) { token_t *arg = tok_get_token(tok, 1); if (tok_strlen(arg) >= 64) { sprintf(COMP_DESCR.err_msg, "entry name too long (max. 63 chars)"); return 0; } tok_strcpy(COMP_DESCR.prg_entry, arg); printf("new entry: '%s'\n", COMP_DESCR.prg_entry); } else if (tok->type == KEYWORD_MODULE_PREPROC) { printf("preproc: module\n"); } return 1; }
/** * Load an AS-level topology in the Subramanian et al format. The * file format is as follows. Each line describes a directed * relationship between a two ASes: * <AS1-number> <AS2-number> <peering-type> * where peering type can be * 0 for a peer-to-peer relationship * 1 for a provider (AS1) to customer (AS2) relationship * A relationship among two ASes is described in one direction only. */ int rexford_parser(FILE * file, as_level_topo_t * topo, int * line_number) { char line[80]; asn_t asn1, asn2; unsigned int relation; int error= 0; net_link_delay_t delay; gds_tokenizer_t * tokenizer; const gds_tokens_t * tokens; as_level_domain_t * domain1, * domain2; peer_type_t peer_type; *line_number= 0; // Parse input file tokenizer= tokenizer_create(" \t", NULL, NULL); while ((!feof(file)) && (!error)) { if (fgets(line, sizeof(line), file) == NULL) break; (*line_number)++; // Skip comments starting with '#' if (line[0] == '#') continue; if (tokenizer_run(tokenizer, line) != TOKENIZER_SUCCESS) { error= ASLEVEL_ERROR_UNEXPECTED; break; } tokens= tokenizer_get_tokens(tokenizer); // Set default value for optional parameters delay= 0; // Get and check mandatory parameters if (tokens_get_num(tokens) < 3) { error= ASLEVEL_ERROR_NUM_PARAMS; break; } // Get and check ASNs if (str2asn(tokens_get_string_at(tokens, 0), &asn1) || str2asn(tokens_get_string_at(tokens, 1), &asn2)) { error= ASLEVEL_ERROR_INVALID_ASNUM; break; } // Get and check business relationship if ((tokens_get_uint_at(tokens, 2, &relation) != 0) || (_rexford_relation_to_peer_type(relation, &peer_type) != 0)) { error= ASLEVEL_ERROR_INVALID_RELATION; break; } // Get optional parameters if (tokens_get_num(tokens) > 3) { if (str2delay(tokens_get_string_at(tokens, 3), &delay)) { error= ASLEVEL_ERROR_INVALID_DELAY; break; } } // Limit number of parameters if (tokens_get_num(tokens) > 4) { STREAM_ERR(STREAM_LEVEL_SEVERE, "Error: too many arguments in topology, line %u\n", *line_number); error= ASLEVEL_ERROR_NUM_PARAMS; break; } // Add/get domain 1 if (!(domain1= aslevel_topo_get_as(topo, asn1)) && !(domain1= aslevel_topo_add_as(topo, asn1))) { error= ASLEVEL_ERROR_UNEXPECTED; break; } // Add/get domain 2 if (!(domain2= aslevel_topo_get_as(topo, asn2)) && !(domain2= aslevel_topo_add_as(topo, asn2))) { error= ASLEVEL_ERROR_UNEXPECTED; break; } // Add link in both directions error= aslevel_as_add_link(domain1, domain2, peer_type, NULL); if (error != ASLEVEL_SUCCESS) break; peer_type= aslevel_reverse_relation(peer_type); error= aslevel_as_add_link(domain2, domain1, peer_type, NULL); if (error != ASLEVEL_SUCCESS) break; } tokenizer_destroy(&tokenizer); return error; }