void main() { int c; while((c = getchar()) != EOF) { if(c == '/') { int next; next = getchar(); if(next == EOF) { return; } if(next == '/' || next == '*') { ungetc(next,stdin); rm_comment(); } else putchar(c); } else if(c == '\"') { ed_quota(c); } else putchar(c); } }
int config_parse(const char *file, struct config *c) { char *buf, real_buf[BUF_LEN], arg[BUF_LEN]; FILE *fp = fopen(file, "r"); int gotargs = 0; if (fp == NULL) return 1; // defaults c->retries = BLIP_L2_RETRIES; while (fgets(real_buf, BUF_LEN, fp) != NULL) { buf = real_buf; rm_comment(buf); upd_start(&buf); if (sscanf(buf, "addr %s\n", arg) > 0) { inet_pton6(arg, &c->router_addr); gotargs ++; } else if (sscanf(buf, "proxy %s\n", c->proxy_dev) > 0) { gotargs ++; } else if (sscanf(buf, "channel %i\n", &c->channel) > 0) { if (c->channel < 11 || c->channel > 26) { fatal("Invalid channel specified in '%s'\n", file); exit(1); } gotargs ++; } else if (sscanf(buf, "log %s\n", arg) > 0) { int i; for (i = 0; i < 5; i++) { if (strncmp(log_names[i], arg, strlen(log_names[i])) == 0) { info("Read log level: %s\n", arg); log_setlevel(i); break; } } } else if (sscanf(buf, "retry %i\n", &c->retries) > 0) { if (c->retries <= 0 || c->retries > 25) { warn("retry value set to %i: outside of the recommended range (0,25]\n", c->retries); } } else if (*buf != '\0') { // anything else indicates that there's invalid input. return 1; } } fclose(fp); if (gotargs != 3) return 1; info("Read config from '%s'\r\n", file); if (strncmp(c->proxy_dev, "lo", 3) != 0) { info("Proxying neighbor advertisements to %s\r\n", c->proxy_dev); } info("Using channel %i\r\n", c->channel); info("Retries: %i\r\n", c->retries); lastconfig = c; return 0; }
int decode(char *srcpath){ char input[ROM_SIZE][MAX_CHAR]; ltable table; uint romindex = 0; ifstream fasm(srcpath); // 必要な行だけを抜き取り、labelをtableに入れる while( fasm.getline(input[romindex],MAX_CHAR) ){ if(input[romindex] == NULL || input[romindex][0] == 0){ continue; } rm_comment(input[romindex], "#;"); if(input[romindex] == NULL || input[romindex][0] == 0){ continue; } if(input[romindex][0] == '\t' && input[romindex][1] != 0){ if('a' <= input[romindex][1] && input[romindex][1] <= 'z') romindex++; // 今読んだ入力を保持して、次の入力を読みに行く else continue; } else { char *label = strtok(input[romindex], ":"); table.set_label(romindex,label); } } for(uint i=0;i < romindex;i++){ put_rom(input[i], table, rom[i], i); } // for(uint i=0;i < romindex; i++){ // cout << '[' << (int)i << ']'; // rom[i].show(); // } char string[50]; sprintf(string, "<デコード終了> 発行命令数:%d\n\n",romindex); cerr << string; return 0; }