/* Read an s-expression from a FILE and buffer lines in a linked-list */ char *read_sexp(FILE *in) { struct list_t *head = NULL; int parens = 0; int quote = 0; char *buf = malloc(sizeof(*buf) * MAX_LINE); if(buf == NULL) return NULL; buf[0] = '\0'; /* while there are valid lines and while the parens are not matched */ char *str; while((str = fgets(buf, MAX_LINE, in)) != NULL) { quote = strip_comments(buf, quote); if(buf[0] == '\n' || buf[0] == '\0') /* skip totally blank lines */ continue; /* break if we've read a matched s-expression */ if((parens += count_parens(buf, MAX_LINE)) == 0) break; head = list_push(buf, head); buf = malloc(sizeof(*buf) * MAX_LINE); if(buf == NULL) { list_for_each(head, &list_free_node); return NULL; } } if(str == NULL) { list_for_each(head, &list_free_node); free(buf); return NULL; } quote = strip_comments(buf, quote); head = list_push(buf, head); head = list_reverse(head); size_t len = 0; struct list_t *n; for(n = head; n != NULL; n = n->next) len += strlen((char *) n->data); char *concat = malloc(sizeof(*concat) * (len+1)); char *i = concat; for(n = head; n != NULL; n = n->next) { len = strlen(n->data); strncpy(i, (char*)n->data, len); i += len; } *i = '\0'; list_for_each(head, &list_free_node); return concat; }
int convert_intl(char *in_filename, char *out_filename) { struct stat statbuf; FILE *infile, *outfile; if (stat(in_filename, &statbuf) < 0) { printf("cannot stat %s\n",in_filename); return 0; } if (statbuf.st_size==0) { printf("file %s is 0 bytes\n",in_filename); return 0; } infile=fopen(in_filename,"rb"); if (infile==NULL) { printf("cannot open %s for reading\n",in_filename); return 0; } outfile=fopen(out_filename,"wb"); if (outfile==NULL) { printf("cannot open %s for writing\n",out_filename); fclose(infile); return 0; } while (!feof(infile)) { getline_simple(infile); if (!feof(infile)) { if (!strncmp(line_buffer,"/* en */",8)) { strip_comments(line_buffer); replace_string(line_buffer,outfile); } else { strip_comments(line_buffer); fprintf(outfile,"%s",line_buffer); } } } fclose(infile); fclose(outfile); return 1; }
bool read_config(FILE *file, bool is_active) { struct sway_config *temp_config = malloc(sizeof(struct sway_config)); config_defaults(temp_config); if (is_active) { sway_log(L_DEBUG, "Performing configuration file reload"); temp_config->reloading = true; temp_config->active = true; } bool success = true; int temp_depth = 0; // Temporary: skip all config sections with depth while (!feof(file)) { int _; char *line = read_line(file); line = strip_whitespace(line, &_); line = strip_comments(line); if (!line[0]) { goto _continue; } if (temp_depth && line[0] == '}') { temp_depth--; goto _continue; } // Any command which would require wlc to be initialized // should be queued for later execution list_t *args = split_string(line, " "); if (!is_active && ( strcmp("exec", args->items[0]) == 0 || strcmp("exec_always", args->items[0]) == 0 )) { sway_log(L_DEBUG, "Deferring command %s", line); char *cmd = malloc(strlen(line) + 1); strcpy(cmd, line); list_add(temp_config->cmd_queue, cmd); } else if (!temp_depth && !handle_command(temp_config, line)) { sway_log(L_DEBUG, "Config load failed for line %s", line); success = false; temp_config->failed = true; } list_free(args); _continue: if (line && line[strlen(line) - 1] == '{') { temp_depth++; } free(line); } if (is_active) { temp_config->reloading = false; container_map(&root_container, reset_gaps, NULL); arrange_windows(&root_container, -1, -1); } config = temp_config; return success; }
void got_dir (str *out, vec<str> s, str loc, bool *errp) { strip_comments (&s); if (s.size () != 2) { warn << loc << ": usage: " << s[0] << " <path>\n"; *errp = true; return; } str res = s[1]; if (res.len() > 1 && res[0] == '$') { str env_val = getenv(res.cstr() + 1); if (!env_val) { warn << loc << ": directory env variable not set (" << res << ")\n"; *errp = true; return; } res = env_val; } if (!is_safe(res)) { warn << loc << ": directory (" << res << ") contains unsafe substrings\n"; *errp = true; return; } *out = dir_standardize(res); }
void bf_run(BF_Code code, BF_Options options) { int* data = calloc(options.data_length, sizeof(int)); CHECK_OOM(data); int* skips = calloc(options.data_length, sizeof(int)); CHECK_OOM(skips); BF_Code* code_copy = malloc(sizeof(BF_Code)); CHECK_OOM(code_copy); BF_State* state = malloc(sizeof(BF_State)); CHECK_OOM(state); memcpy(code_copy, &code, sizeof(BF_Code)); *state = (BF_State){0, options.data_length, data, skips}; strip_comments(code_copy); bf_run_code(code_copy, state, options.debug); free(state->data); free(state->skips); free(state); free(code_copy->data); free(code_copy); }
static int parse_variable(git_config_parser *reader, char **var_name, char **var_value) { const char *value_start = NULL; char *line; int quote_count; bool multiline; git_parse_advance_ws(&reader->ctx); line = git__strndup(reader->ctx.line, reader->ctx.line_len); if (line == NULL) return -1; quote_count = strip_comments(line, 0); /* If there is no value, boolean true is assumed */ *var_value = NULL; if (parse_name(var_name, &value_start, reader, line) < 0) goto on_error; /* * Now, let's try to parse the value */ if (value_start != NULL) { while (git__isspace(value_start[0])) value_start++; if (unescape_line(var_value, &multiline, value_start, 0) < 0) goto on_error; if (multiline) { git_buf multi_value = GIT_BUF_INIT; git_buf_attach(&multi_value, *var_value, 0); if (parse_multiline_variable(reader, &multi_value, quote_count) < 0 || git_buf_oom(&multi_value)) { git_buf_free(&multi_value); goto on_error; } *var_value = git_buf_detach(&multi_value); } } git__free(line); return 0; on_error: git__free(*var_name); git__free(line); return -1; }
static int parse_multiline_variable(git_config_parser *reader, git_buf *value, int in_quotes) { char *line = NULL, *proc_line = NULL; int quote_count; bool multiline; /* Check that the next line exists */ git_parse_advance_line(&reader->ctx); line = git__strndup(reader->ctx.line, reader->ctx.line_len); if (line == NULL) return -1; /* We've reached the end of the file, there is no continuation. * (this is not an error). */ if (line[0] == '\0') { git__free(line); return 0; } quote_count = strip_comments(line, !!in_quotes); /* If it was just a comment, pretend it didn't exist */ if (line[0] == '\0') { git__free(line); return parse_multiline_variable(reader, value, quote_count); /* TODO: unbounded recursion. This **could** be exploitable */ } if (unescape_line(&proc_line, &multiline, line, in_quotes) < 0) { git__free(line); return -1; } /* add this line to the multiline var */ git_buf_puts(value, proc_line); git__free(line); git__free(proc_line); /* * If we need to continue reading the next line, let's just * keep putting stuff in the buffer */ if (multiline) return parse_multiline_variable(reader, value, quote_count); return 0; }
static void convert_files(m00data_t* data) { debug_print("Starting file conversion\n"); char line[256]; unsigned long line_a = 0, line_c = 0; /* line_a: count of all lines; line_c: converted lines */ int g = 0, x = 0, z = 0; char output_line[256]; /* String that contains the converted output */ debug_print("Beginning to read/write the files\n"); while(fgets(line, 255, data->in_file) != NULL) { line_a++; /* Increase line count */ char* stripped = strip_spaces(strip_comments(line)); if(is_blank(stripped) || !parse_line(stripped, &g, &x, &z)) continue; /* Skip unuseful lines */ line_c++; if(sprintf(output_line, " %02d %02d % 05d % 05d\n", (int)line_c+2, g, x, z) < 0) { fprintf(stderr, "m00conv: an unknown error occurred while writing the file\n"); terminate(1); } fputs(output_line, data->out_file); debug_print("L%lu A%lu (-%lu): '%s'\n" "\tg=%d x=%d z=%d\n" "\t=%s", line_a, line_c, line_a-line_c, line, g, x, z, output_line); } /* 'end of instructions' line */ if(sprintf(output_line, " %02dM30\n", (int)line_c+3) < 0) { fprintf(stderr, "m00conv: an unknown error occurred while writing the file\n"); terminate(1); } fputs(output_line, data->out_file); debug_print("Finished reading/writing the files\n"); }
QString CMySQLQuery::query_type(const QString &q) { #ifdef DEBUG qDebug("static CMySQLQuery::query_type(const QString &)"); #endif if (q.isEmpty()) return QString::null; QString qry = strip_comments(q).simplifyWhiteSpace(); if (qry.isEmpty()) return QString::null; int p = qry.find(" "); return p != -1 ? qry.left(p).lower() : QString::null; }
struct sway_config *read_config(FILE *file) { struct sway_config *config = malloc(sizeof(struct sway_config)); config_defaults(config); bool success = true; int temp_depth = 0; // Temporary: skip all config sections with depth while (!feof(file)) { int _; char *line = read_line(file); line = strip_whitespace(line, &_); line = strip_comments(line); if (!line[0]) { goto _continue; } if (temp_depth && line[0] == '}') { temp_depth--; goto _continue; } if (!temp_depth && handle_command(config, line) != 0) { success = false; } _continue: if (line && line[strlen(line) - 1] == '{') { temp_depth++; } free(line); } if (!success) { exit(1); } return config; }
/* * FUNCTION qsub(char *qtag, int flags) * * based on the settings of flags, and the template file $QDIR/qtag.sql * make the following substitutions to turn a query template into EQT * * String Converted to Based on * ====== ============ =========== * first line database <db_name>; -n from command line * second line set explain on; -x from command line * :<number> parameter <number> * :k set number * :o output to outpath/qnum.snum * -o from command line, SET_OUTPUT * :s stream number * :b BEGIN WORK; -a from command line, START_TRAN * :e COMMIT WORK; -a from command line, END_TRAN * :q query number * :n<number> sets rowcount to be returned */ void qsub(char *qtag, int flags) { static char *line = NULL, *qpath = NULL; FILE *qfp; char *cptr, *mark, *qroot = NULL; qnum = atoi(qtag); if (line == NULL) { line = malloc(BUFSIZ); qpath = malloc(BUFSIZ); MALLOC_CHECK(line); MALLOC_CHECK(qpath); } qroot = env_config(QDIR_TAG, QDIR_DFLT); sprintf(qpath, "%s%c%s.sql", qroot, PATH_SEP, qtag); qfp = fopen(qpath, "r"); OPEN_CHECK(qfp, qpath); rowcnt = rowcnt_dflt[qnum]; varsub(qnum, 0, flags); /* set the variables */ if (flags & DFLT_NUM) fprintf(ofp, SET_ROWCOUNT, rowcnt); while (fgets(line, BUFSIZ, qfp) != NULL) { if (!(flags & COMMENT)) strip_comments(line); mark = line; while ((cptr = strchr(mark, VTAG)) != NULL) { *cptr = '\0'; cptr++; fprintf(ofp,"%s", mark); switch(*cptr) { case 'b': case 'B': if (!(flags & ANSI)) fprintf(ofp,"%s\n", START_TRAN); cptr++; break; case 'c': case 'C': if (flags & DBASE) fprintf(ofp, SET_DBASE, db_name); cptr++; break; case 'e': case 'E': if (!(flags & ANSI)) fprintf(ofp,"%s\n", END_TRAN); cptr++; break; case 'n': case 'N': if (!(flags & DFLT_NUM)) { rowcnt=atoi(++cptr); while (isdigit(*cptr) || *cptr == ' ') cptr++; fprintf(ofp, SET_ROWCOUNT, rowcnt); } continue; case 'o': case 'O': if (flags & OUTPUT) fprintf(ofp,"%s '%s/%s.%d'", SET_OUTPUT, osuff, qtag, (snum < 0)?0:snum); cptr++; break; case 'q': case 'Q': fprintf(ofp,"%s", qtag); cptr++; break; case 's': case 'S': fprintf(ofp,"%d", (snum < 0)?0:snum); cptr++; break; case 'X': case 'x': if (flags & EXPLAIN) fprintf(ofp, "%s\n", GEN_QUERY_PLAN); cptr++; break; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': varsub(qnum, atoi(cptr), flags & DFLT); while (isdigit(*++cptr)); break; default: fprintf(stderr, "-- unknown flag '%c%c' ignored\n", VTAG, *cptr); cptr++; break; } mark=cptr; } fprintf(ofp,"%s", mark); } fclose(qfp); fflush(stdout); return; }
int main() { strip_comments(); return 0; }
int main(int argc, char **argv) { FILE *in, *out; char *out_file; const char *tmp; if (argc != 2) { fprintf(stderr, "usage: %s rebase-file\n", argv[0]); return EXIT_FAILURE; } in = fopen(argv[1], "r"); if (in == NULL) { perror("failed to open file"); return EXIT_FAILURE; } // open a temporary file for making a new rebase input tmp = getenv("TMPDIR"); if (tmp == NULL) tmp = "/tmp"; if (asprintf(&out_file, "%s/tmp.XXXXXX", tmp) < 0) { fprintf(stderr, "failed to create temporary path\n"); fclose(in); return EXIT_FAILURE; } { int out_fd = mkstemp(out_file); if (out_fd < 0) { perror("failed to open temporary file"); free(out_file); fclose(in); return EXIT_FAILURE; } out = fdopen(out_fd, "w"); assert(out != NULL); } { int ret = insert_diffs(in, out); fclose(out); fclose(in); if (ret != 0) { fprintf(stderr, "failed to insert diffs: %s\n", strerror(-ret)); unlink(out_file); free(out_file); return EXIT_FAILURE; } } // Overwrite the original input file with our modified version { int ret = move(out_file, argv[1]); if (ret < 0) unlink(out_file); free(out_file); if (ret < 0) { fprintf(stderr, "failed to overwrite original input\n"); return EXIT_FAILURE; } } // Now open Vim with the new file with all folds collapsed { char *command; if (asprintf(&command, "vim '+set foldmethod=marker' '+set foldlevel=0' '%s'", argv[1]) < 0) { fprintf(stderr, "failed to construct Vim command\n"); return EXIT_FAILURE; } int ret = system(command); free(command); if (ret == -1) { fprintf(stderr, "executing Vim failed\n"); return EXIT_FAILURE; } if (WEXITSTATUS(ret) != EXIT_SUCCESS) return WEXITSTATUS(ret); } /* Now strip the comment lines. This is not strictly necessary, but Git's interactive rebase * script seems incredibly slow to pass over long stretches of comment lines. */ in = fopen(argv[1], "r"); if (in == NULL) { perror("failed to open file"); return EXIT_FAILURE; } if (asprintf(&out_file, "%s/tmp.XXXXXX", tmp) < 0) { fprintf(stderr, "failed to create temporary path\n"); fclose(in); return EXIT_FAILURE; } { int out_fd = mkstemp(out_file); if (out_fd < 0) { perror("failed to open temporary file"); free(out_file); fclose(in); return EXIT_FAILURE; } out = fdopen(out_fd, "w"); assert(out != NULL); } { int ret = strip_comments(in, out); fclose(out); fclose(in); if (ret != 0) { fprintf(stderr, "failed to strip comments: %s\n", strerror(-ret)); unlink(out_file); free(out_file); return EXIT_FAILURE; } } { int ret = move(out_file, argv[1]); if (ret < 0) unlink(out_file); free(out_file); if (ret < 0) { fprintf(stderr, "failed to overwrite original input\n"); return EXIT_FAILURE; } } return EXIT_SUCCESS; }
int main(int argc, char* argv[]) { UCHAR seed[256]; UCHAR line[MAX_LINE+1]; UCHAR plain_text[MAX_TEXT+1]; UCHAR cipher_text[MAX_TEXT+1]; UCHAR comment[MAX_LINE+1]; UCHAR xored_text[MAX_TEXT+1]; int i, num; ULONG sweep, done = 0, iter; rc4_key key; FILE *fp; char** args = argv; int acount = argc; double time_taken; USHORT plain_text_len, cipher_text_len, text_len; USHORT cmd_line_project_id, file_check_sum = 0; USHORT completed_check_sum = 0; USHORT comment_len = 0; USHORT segments, start_segment; UCHAR* tag; UCHAR* value; int done_plain_text = 0; int done_cipher_text = 0; #if !defined(_MSDOS) && !defined(__OS2__) struct timeval tv_start,tv_end; #endif double keys_sec, run_time, start_time; int first = 1; #ifdef __OS2__ APIRET rc; #endif big_endian = ((char*)&test_endian)[0]; prog = argv[0]; #ifdef __OS2__ /* set priority class to IDLETIME */ rc = DosSetPriority(PRTYS_PROCESS, PRTYC_IDLETIME, 0, 0); if (rc != 0) { fprintf(stderr, "%s: unable to set priority, rc = %ld\n", prog, rc); exit(1); } #endif /* __OS2__ */ if (argc < 2) { usage(); exit(1); } if (args[1][0]=='-') { switch(args[1][1]) { case 'q': verbose = 0; break; case '\0': /* stdin = '-' */ acount++; args--; /* doesn't count as a flag */ break; default: fprintf(stderr,"invalid flag %s\n",args[1]); usage(); exit(1); } args++; acount--; } if (acount < 5) { usage(); exit(1); } if (!strcmp(args[1],"-")) { fp = stdin; } else { fp = fopen(args[1],"rb"); if (!fp) { fprintf(stderr,"error cannot open config file %s\n",args[1]); exit(2); } } num = sscanf(args[2],"%hx",&cmd_line_project_id); if (num < 1) { fprintf(stderr,"error: project-id should be a hexadecimal number\n\n"); usage(); exit(1); } if (strlen(args[3]) > 4) { fprintf(stderr,"error: start-key should be a 4 digit hexadecimal number\n\n"); usage(); exit(1); } i = byte_pack(seed, (UCHAR*) args[3], 2); if (i != 2) { fprintf(stderr,"error: start-key should be a 4 digit hexadecimal number\n\n"); usage(); exit(1); } seed[2] = seed[3] = seed[4] = 0; start_segment = (USHORT)seed[0]*256 + (USHORT)seed[1]; num = sscanf(args[4],"%hu",&segments); if (num < 1) { fprintf(stderr,"error: segments should be a decimal number\n\n"); usage(); exit(1); } sweep = (ULONG)segments << 8; while (!feof(fp)) { line[0] = '\0'; fgets(line, MAX_LINE, fp); strip_crlf(line); strip_comments(line); file_check_sum = checksum(file_check_sum, line); parse_line(line,&tag,&value); if (!tag || !*tag) { continue; } if (!strcasecmp(tag,"PLAIN-TEXT")) { if (done_plain_text) { fprintf(stderr, "config file error: should only have one PLAIN-TEXT field\n"); exit(2); } if (strlen(value) & 0x1 != 0) { fprintf(stderr, "config file error: PLAIN-TEXT field must be an even number of hex digits\n"); exit(2); } plain_text_len = byte_pack(plain_text, value, MAX_TEXT); if (plain_text_len == 0) { fprintf(stderr, "config file error: PLAIN-TEXT field must be hex digits\n"); exit(2); } done_plain_text = 1; } else if (!strcasecmp(tag,"CIPHER-TEXT")) { if (done_cipher_text) { fprintf(stderr, "config file error: should only have one CIPHER-TEXT field\n"); exit(2); } if (strlen(value) & 0x1 != 0) { fprintf(stderr, "config file error: CIPHER-TEXT field must be an even number of hex digits\n"); exit(2); } cipher_text_len = byte_pack(cipher_text, value, MAX_TEXT); if (cipher_text_len == 0) { fprintf(stderr, "config file error: CIPHER-TEXT field must be hex digits\n"); exit(2); } done_cipher_text = 1; } else if (!strcasecmp(tag,"COMMENT")) { char *rest = strtok(0, "\n"); /* ie to the end of string as there */ if (comment_len != 0) /* won't be a \n due to strip_crlf */ { fprintf(stderr, "config file error: should only have one COMMENT field\n"); exit(2); } strncpy(comment, value, MAX_LINE); if (rest) { comment_len = strlen(comment); strncat(comment," ", MAX_LINE - comment_len); comment_len++; strncat(comment, rest, MAX_LINE - comment_len); comment[MAX_LINE] = '\0'; } comment_len = strlen(comment); } else { fprintf(stderr,"config file error: unknown tag: %s\n",tag); exit(2); } } if (!done_plain_text) { fprintf(stderr,"config file error: no PLAIN-TEXT field\n"); exit(2); } if (!done_cipher_text) { fprintf(stderr,"config file error: no CIPHER-TEXT field\n"); exit(2); } if (plain_text_len != cipher_text_len) { fprintf(stderr,"config file warning: PLAIN-TEXT and CIPHER-TEXT are not the same length\n"); } text_len = plain_text_len < cipher_text_len ? plain_text_len : cipher_text_len; if (cmd_line_project_id != file_check_sum) { fprintf(stderr,"error: you have the wrong config file for project %04x (%04x)\n", cmd_line_project_id, file_check_sum); exit(1); } completed_check_sum = (( (ULONG)file_check_sum + (ULONG)start_segment + (ULONG)segments ) & 0xFFFFL); if (verbose) { fprintf(stderr,"PROJECT-ID\t%04x\n",file_check_sum); if (comment_len) fprintf(stderr,"COMMENT \t%s\n",comment); fprintf(stderr,"START-KEY\t%s\n",print_hex(seed,KEY_SIZE)); fprintf(stderr,"SEGMENTS\t%u (16M keys/segment)\n",segments); fprintf(stderr,"PLAIN-TEXT\t%s\n",print_hex(plain_text,text_len)); fprintf(stderr,"CIPHER-TEXT\t%s\n",print_hex(cipher_text,text_len)); fprintf(stderr,"TEXT-SIZE\t%d\n",text_len); fprintf(stderr,"256k keys per '.' printed, 1 segment per line, a segment = 16M keys\n"); fprintf(stderr,"LINES-TO-DO\t%d\n",segments); } /* pre-compute plain_text XOR cipher_text */ for (i=0; i<text_len; i++) { xored_text[i] = plain_text[i] ^ cipher_text[i]; } for (done=0; done<sweep; done++) { if (verbose) { if (first) { #if defined(_MSDOS) || defined(__OS2__) start_time = (double) clock()/CLOCKS_PER_SEC; #else gettimeofday(&tv_start,0); #endif } } for (iter=0; iter < 65536; iter++) { prepare_key(seed,KEY_SIZE,&key); if (rc4_eq(xored_text, text_len, &key)) { if (verbose) { fprintf(stderr,"\nFOUND-IT\t%s\n", print_hex(seed,KEY_SIZE)); instructions(); } printf("%04x %04x %04x %u %s\n",file_check_sum,completed_check_sum, start_segment,segments,print_hex(seed,KEY_SIZE)); exit(0); } inc_key(seed); } if (verbose) { if (first) { #if defined(_MSDOS) || defined(__OS2__) time_taken = ((double) clock()/CLOCKS_PER_SEC) - start_time; #else gettimeofday(&tv_end,0); time_taken = (double)(tv_end.tv_sec - tv_start.tv_sec); time_taken += ((double)(tv_end.tv_usec - tv_start.tv_usec)/1000000.0); #endif keys_sec = 65536.0 / time_taken; fprintf(stderr,"KEYS-PER-SEC\t%0.1lf keys/sec\n",keys_sec); fprintf(stderr,"EXPECTED-RUNNING-TIME\t"); run_time = sweep * time_taken; if (run_time < 60) { fprintf(stderr,"%0.1lf secs\n",run_time); } else if (run_time < 3600) { fprintf(stderr,"%0.1lf mins\n",run_time / 60); } else { fprintf(stderr,"%0.1lf hours\n",run_time / 3600); if (run_time > 180000) { fprintf(stderr,"in days: %0.1lf days\n",run_time / 86400); } } first = 0; } if ((done & 255L) == 0) { if (done > 0) fprintf(stderr,"]\n"); fprintf(stderr,"%sxxxxxx:[",print_hex(seed,2)); } if ((done & 3L) == 0) { fputc('.',stderr); } #ifdef __OS2__ fflush(stderr); /* needed to prevent buffering of stderr */ #endif } } if (verbose) { fprintf(stderr,"]\n"); instructions(); } printf("%04x %04x %04x %u no\n",file_check_sum,completed_check_sum, start_segment,segments); return 0; }
/* begin main function */ int main(int argc, char *argv[]) { int SUPER_CNT_PREVIOUS; /* locate this here for memory leak prevention */ char env[READLINELEN + 1], *endptr; /* file variables */ /* buffers */ int pinheadcount = 0, maxblksizeallowed; char pinhead[PINSIZE][NUMPINS]; char vector[READLINELEN + 1], nv1[MAX_SCAN_LEN +1], nv2[MAX_SCAN_LEN +1]; char *ptr, *ptr2, *ptr3, *ptrCR, *ptrCRN, phold; char tempstr[READLINELEN + 1], CYCLETBL[READLINELEN + 1]; char outfile1[READLINELEN + 1], pattern[READLINELEN + 1], *patnameptr; int i, j, incomment; long gunzip = 0, GIVE_CYCLETBL_WARNING = 0; char hexdebug1[MXFIELD], hexdebug2[MXFIELD], hexdebug3[MXFIELD]; int begin_loc, repeat_loc, match_loc, shutdown_loc, end_loc, CFV, CFS, CFRF, loopnest; int vs, ve, flag_match, flag_scan, flag_repeatforever, max_rpt_depth, vc; int inshutdown, first_match_line, begin_before_set, first_set, muxcnt; int printfields = 0; /* command line stuff */ struct stat statbuf; off_t filesize; int ret, pos, posO, conv_vect; int SUPER_CNT; int begin_pending_index[8], last_repeat[8], max_repeat_block, repeat_calc, last_was_repeat; struct LOOP_LINES *SUPER; char *ptrSTART, *ptrNEXT, *ptrBO; char *patbuf; char linebuf[LINE_BUFF + 1]; /* 20 is for MDI */ char linebuforig[LINE_BUFF + 1]; /* 20 is for MDI */ strcpy(progstr, __FILE__); strcpy(datestr, __DATE__); strcpy(timestr, __TIME__); strcpy(compilestr, argv[0]); if (getenv("DEBUG_FIELDS") != NULL) printfields = 1; if (getenv("DEBUG_PROC") == NULL) debug = 0; else { strcpy(env, getenv("DEBUG_PROC")); debug = strtol(env, &endptr, 0); fprintf(stderr, "Turning on DEBUG!\n"); printfields = 1; } fprintf(stderr, "\n\n\nThis code is supplied under the LTX-Credence Shareware License.\n"); fprintf(stderr, "Please see the LSLV1.2 file in the document directory for a full text.\n\n\n"); fprintf(stderr, "Environment variables:DEBUG_PROC,DEBUG_FIELDS\n"); if (NULL == (fperrors = fopen(TRANSLATION_ERRORS, "a"))) { fprintf(stderr, "\nFATAL_ERROR:%s:Could not open %s for output\n", compilestr, TRANSLATION_ERRORS); exit(1); } if (NULL == (fpstatus = fopen(TRANSLATION_STATUS, "a"))) { /* replaces the fpstatus messages */ fprintf(stderr, "\nFATAL_ERROR:%s:Could not open %s for append output[%s,%d,%s]\n", compilestr, TRANSLATION_STATUS, __FILE__, __LINE__, __FUNCTION__); exit(1); } if (argc >= 4 && isdigit(argv[3][0])) { fprintf(stderr, "FYI:Modifying max loop count threshold for DPM to CPM conversion from %ld to %ld\n", MAX_LOOP_SIZE, atol(argv[3])); fprintf(fperrors, "FYI:Modifying max loop count threshold for DPM to CPM conversion from %ld to %ld\n", MAX_LOOP_SIZE, atol(argv[3])); MAX_LOOP_SIZE = atol(argv[3]); } if (strstr(argv[0], "FORCE_DPM") != NULL) { fprintf(stderr, "Forcing DPM pattern\n"); FORCEDPM = 1; } /* force CPM with PRE_PROC_CPM */ if (argc >= 3) strcpy(CYCLETBL, (char *) argv[2]); else { fprintf(stderr, "No Cycletbl_mod%s file given. This is now an error!,exiting\n", MODVER); fprintf(stderr, "Syntax:%s pattern.vpl.Z [cycletbl_mod%s] [debug_level]\n", argv[0], MODVER); fprintf(stderr, "If the third parameter starts with a number it will be assumed to be the debug level\n"); fprintf(fperrors, "FATAL_ERROR:%s:No file given [%s,%d,%s]\n", compilestr, __FILE__, __LINE__, __FUNCTION__); exit(1); } if (argc >= 3 && 0 == strstr(CYCLETBL, MODVER)) { fprintf(fperrors, "This version requires a %s version %s file\n", MODVER, GCT_GEN_MODVER); fprintf(stderr, "This version requires a %s version %s file\n", MODVER, GCT_GEN_MODVER); fprintf(stderr, "Aborting....[%s,%d,%s]\n", __FILE__, __LINE__, __FUNCTION__); exit(2); } if (argc >= 2) strcpy(infile_orig, (char *) argv[1]); else { fprintf(stderr, "No file given\n"); fprintf(stderr, "Syntax:%s pattern.vpl.Z [cycletbl_mod%s] [debug_level]\n", argv[0], MODVER); fprintf(stderr, "If the second parameter starts with a number it will be assumed to be the debug level\n"); fprintf(fperrors, "FATAL_ERROR:%s:No file given [%s,%d,%s]\n", compilestr, __FILE__, __LINE__, __FUNCTION__); exit(1); } if (isdigit(CYCLETBL[0])) { debug = atoi(CYCLETBL); CYCLETBL[0] = '\0'; GIVE_CYCLETBL_WARNING = 1; fprintf(stderr, "USING SECOND PARAMETER AS DEBUG LEVEL!!!!\n"); } //fprintf(fpstatus,"GOT2 cycl[%s]\n",CYCLETBL); if (CYCLETBL[0] != '\0') { // fprintf(fpstatus,"GOT3 cycl[%s]\n",CYCLETBL); if (NULL != (fp_cycmod3 = fopen(CYCLETBL, "r"))) { hexproc[0] = hexfield[0] = muxpin[0] = '\0'; /* in case we don't find one! */ // fprintf(fpstatus,"GOT4 cycl[%s]\n",CYCLETBL); while (fgets(vector, READLINELEN - 1, fp_cycmod3) != NULL) { if (vector[0] == 'H') { ptr = strchr(vector, '['); strcpy(hexproc, ptr + 1); } /* get past H[ */ if (vector[0] == 'F') { ptr = strchr(vector, '['); strcpy(hexfield, ptr + 1); } /* get past F[ */ if (vector[0] == 'M') { ptr = strchr(vector, '['); strcpy(muxpin, ptr + 1); } /* get past M[ */ if (vector[0] == '/') { strcpy(pinhead[pinheadcount], vector); pinheadcount++; } /* pinheader info */ } fclose(fp_cycmod3); } if (hexproc[0] == '\0' || hexfield[0] == '\0' || muxpin[0] == '\0' || pinhead[0] == '\0') { fprintf(stderr,"A mod8 file should contain HEXPROC, FIELDS, MUXSECONDARYPINS, and //pinheader entries\n"); fprintf(stderr," at least one of those is missing, Please generate a valid .mod8 file...\n"); exit(1); } ptr = strchr(hexfield, ']'); if (ptr == NULL) {fprintf(stderr,"OOPS no terminating ']' in modfile for [%s]\n",hexfield);exit(1);} *ptr = '\0'; fhlen = strlen(hexfield); if (fhlen > 0) { // fprintf(stdout,"HF1[%s]\n",hexfield); for (i = (fhlen - 1); i >= 0; i--) { if (hexfield[i] == '.') fhlen--; else break; } hexfield[fhlen] = '\0'; /* remove trailing ']' and any dummy pins */ hexproc[fhlen] = '\0'; /* remove trailing ']' and any dummy pins */ muxpin[fhlen] = '\0'; /* remove trailing ']' and any dummy pins */ // fprintf(stdout,"HF2[%s]\n",hexfield); fieldcount[0] = 0; fieldstart[0] = fields = muxcnt = 0; for (i = 0; i <= fhlen; i++) { // fputc(hexproc[i],fpstatus); if (hexfield[i] == '.') { fprintf(stderr, "Non-patpin \'.\'\n"); continue; } if (hexfield[i] == fields + 'A') { fieldcount[fields]++; fieldtype[fields] = hexproc[i]; } else { fields++; fieldstart[fields] = i + muxcnt; fieldcount[fields] = 1; fieldtype[fields] = hexproc[i]; } if (muxpin[i] == 'M') { fieldcount[fields]++; muxcnt++; } } /* end for length */ } /* end if fhlen>0 */ for (j = 0, i = 0; i < fields; i++) { if (fieldtype[i] == 'H') { phd_st[i] = j; phd_sp[i] = j + (int) ((fieldcount[i] + 3) / 4) - 1; /* allow for hex+comma, +3 is for round up... */ j = cmma[i] = phd_sp[i] + 1; j++; } else { /* binary */ phd_st[i] = j; phd_sp[i] = j + fieldcount[i] - 1; /* allow for comma */ j = cmma[i] = phd_sp[i] + 1; j++; } // fprintf(fpstatus,"ft[%c],fs[%d],fc[%d]st[%d]sp[%d]cm[%d]\n", // fieldtype[i],fieldstart[i],fieldcount[i], // phd_st[i],phd_sp[i],cmma[i]); } } /* end if CYCLETBL */ for (i = 0; i < strlen(hexproc); i++) { hexdebug3[i] = ','; hexdebug1[i] = '.'; } hexdebug3[i] = hexdebug1[i] = '\0'; strcpy(hexdebug2, hexdebug3); for (i = 0; i < fields; i++) { hexdebug1[fieldstart[i]] = '^'; hexdebug2[phd_st[i]] = 'S'; hexdebug2[phd_sp[i]] = 'E'; for (j = phd_st[i]; j <= phd_sp[i]; j++) hexdebug3[j] = 'A' + i; } if (printfields) { fprintf(fpstatus, "\nX_X FT:FILE[%s]\n", infile_orig); fprintf(fpstatus, "\nX_X FT:"); for (i = 0; i < fields; i++) fprintf(fpstatus, "__%c,", fieldtype[i]); fprintf(fpstatus, "\nX_X FC:"); for (i = 0; i < fields; i++) fprintf(fpstatus, "%03d,", fieldcount[i]); fprintf(fpstatus, "\nX_X FS:"); for (i = 0; i < fields; i++) fprintf(fpstatus, "%03d,", fieldstart[i]); fprintf(fpstatus, "\nX_XPHDST:"); for (i = 0; i < fields; i++) fprintf(fpstatus, "%03d,", phd_st[i]); fprintf(fpstatus, "\nX_XPHDSP:"); for (i = 0; i < fields; i++) fprintf(fpstatus, "%03d,", phd_sp[i]); fprintf(fpstatus, "\nX_X CMMA:"); for (i = 0; i < fields; i++) fprintf(fpstatus, "%03d,", cmma[i]); fprintf(fpstatus, "\nX_Xcount:"); for (i = 0; i < strlen(hexproc); i++) fputc('0' + i - 10 * (int) (i / 10), fpstatus); fputc('\n', fpstatus); fprintf(fpstatus, "X_XHXPRC:"); fprintf(fpstatus, "%s\n", hexproc); fprintf(fpstatus, "X_XHXFLD:"); fprintf(fpstatus, "%s\n", hexfield); fprintf(fpstatus, "X_XHX_ST:"); fprintf(fpstatus, "%s\n", hexdebug1); fprintf(fpstatus, "X_XST_SP:"); fprintf(fpstatus, "%s\n", hexdebug2); fprintf(fpstatus, "X_XSIMFD:"); fprintf(fpstatus, "%s\n", hexdebug3); } strcpy(infile_base, infile_orig); /* The following few lines check that the file actually exists before uncompressing it */ if (NULL == (fpin1 = fopen(infile_orig, "r"))) { fprintf(stderr, "\nFATAL_ERROR:Compressed input file [%s] not found. can't gunzip...exiting[%s,%d,%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "\nFATAL_ERROR:%s:Compressed input file [%s] not found.[%s,%d,%s]\n", compilestr, infile_orig, __FILE__, __LINE__, __FUNCTION__); exit(1); } fclose(fpin1); /* Only close it if we found that the compressed file exists */ ptr2 = strrchr(infile_base, '/'); /* get the last '/' */ if (ptr2 != NULL) { strcpy(infile_base, ptr2); } ptr = strrchr(infile_base, '.'); /* get the last '.' */ if (ptr != NULL) { if (*(ptr + 1) == 'g' && *(ptr + 2) == 'z' && *(ptr + 3) == '\0') gunzip = 1; if (*(ptr + 1) == 'Z' && *(ptr + 2) == '\0') gunzip = 1; if (gunzip == 1) { *ptr = '\0'; ptr3 = strrchr(infile_base, '.'); /* get the last '.' i.e. .vpl */ if (ptr3 != NULL) *ptr3 = '\0'; sprintf(tempgunzipname, "%s.tmpgunzip", infile_base); sprintf(pattern, infile_base); sprintf(tempstr, "gunzip -c %s >%s", infile_orig, tempgunzipname); fprintf(fpstatus, "[%s]\n", tempstr); i = system(tempstr); /* unzip to temporary file */ /* before opening figure out the size */ ret = stat(tempgunzipname, &statbuf); if (NULL == (fpin1 = fopen(tempgunzipname, "r"))) { fprintf(stderr, "\nFATAL_ERROR:Uncompressed input file [%s] not found.[%s,%d,%s]\n", tempgunzipname, __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "\nFATAL_ERROR:%s:Uncompressed input file [%s] not found.[%s,%d,%s]\n", compilestr, tempgunzipname, __FILE__, __LINE__, __FUNCTION__); exit(1); } } else { /* no uncompress needed */ *ptr = '\0'; sprintf(pattern, infile_base); /* before opening figure out the size */ ret = stat(infile_orig, &statbuf); strcpy(tempgunzipname, infile_orig); /* copy this so the remove is easier */ if (NULL == (fpin1 = fopen(infile_orig, "r"))) { fprintf(stderr, "\nFATAL_ERROR:Input file [%s] not found.[%s,%d,%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "\nFATAL_ERROR:%s:Input file [%s] not found.[%s,%d,%s]\n", compilestr, infile_orig, __FILE__, __LINE__, __FUNCTION__); exit(1); } } } else { fprintf(stderr, "There is no .vpl extension[%s]\n,exiting[%s,%d,%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "There is no .vpl extension[%s]\n,exiting[%s,%d,%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); exit(1); } fprintf(stdout, "%s:input file1 <%s> ok\n", compilestr, (gunzip == 1) ? infile_base : infile_orig); sprintf(outfile1, "%s.proc", pattern); if (NULL == (fpout1 = fopen(outfile1, "w"))) { fprintf(stderr, "\nFATAL_ERROR:Could not create output file [%s][%s,%d,%s]\n", outfile1, __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "\nFATAL_ERROR:%s:Could not create output file [%s][%s,%d,%s]\n", compilestr, outfile1, __FILE__, __LINE__, __FUNCTION__); exit(1); } patnameptr = pattern; fprintf(stderr, "\n%s:<%s>\n", compilestr, patnameptr); for (i = 0; i < pinheadcount; i++) fprintf(fpout1, "%s", pinhead[i]); /* from above... */ if (ret == 0) filesize = statbuf.st_size; else { fprintf(stderr, "Can't determine filesize for [%s][%s,%d,%s]\n", pattern, __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "Can't determine filesize for [%s][%s,%d,%s]\n", pattern, __FILE__, __LINE__, __FUNCTION__); exit(1); } SUPER = calloc(MAXPATLINES, sizeof(struct LOOP_LINES)); if (SUPER == NULL) { fprintf(stderr, "Could not allocate memory for %d LINES of size %d, exiting[%s,%d,%s]\n", MAXPATLINES, sizeof(struct LOOP_LINES), __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "Could not allocate memory for %d LINES of size %d, exiting[%s,%d,%s]\n", MAXPATLINES, sizeof(struct LOOP_LINES), __FILE__, __LINE__, __FUNCTION__); exit(1); } fprintf(fpstatus, "succesfully allocated memory for %d LINES of size %d\n", MAXPATLINES, sizeof(struct LOOP_LINES)); SCANV = calloc(MAXSCAN, sizeof(struct SCAN_VECTORS)); if (SCANV == NULL) { fprintf(stderr, "Could not allocate memory for %d SCAN LINES of size %d, exiting[%s,%d,%s]\n", MAXSCAN, sizeof(struct SCAN_VECTORS), __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "Could not allocate memory for %d SCAN LINES of size %d, exiting[%s,%d,%s]\n", MAXSCAN, sizeof(struct SCAN_VECTORS), __FILE__, __LINE__, __FUNCTION__); exit(1); } fprintf(fpstatus, "succesfully allocated memory for %d SCAN LINES of size %d\n", MAXSCAN, sizeof(struct SCAN_VECTORS)); patbuf = malloc((size_t) (filesize + 1)); if (patbuf == NULL) { fprintf(stderr, "Could not allocate memory for [%s] file in memory[%s,%d,%s]\n", pattern, __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "Could not allocate memory for [%s] file in memory[%s,%d,%s]\n", pattern, __FILE__, __LINE__, __FUNCTION__); exit(1); } fprintf(fpstatus, "allocated [%ld] bytes for patbuf\n", filesize + 1); fread(patbuf, (size_t) filesize, 1, fpin1); fclose(fpin1); patbuf[filesize] = '\0'; /* just to make sure */ ptrSTART = patbuf; vc = pos = SUPER_CNT_PREVIOUS = SUPER_CNT = incomment = 0; flag_scan = flag_match = flag_repeatforever = 0; loopnest = max_rpt_depth = max_repeat_block = last_was_repeat = inshutdown = 0; repeat_calc = 1; begin_before_set = first_set = 0; while (pos < filesize) { if (SUPER_CNT > MAXPATLINES) { fprintf(stderr, "Error!!!![%s]Memory leak!!!!new count[%d], previous count[%d]\n", pattern, SUPER_CNT, SUPER_CNT_PREVIOUS); fprintf(fperrors, "Error!!!![%s]Memory leak!!!!new count[%d], previous count[%d]\n", pattern, SUPER_CNT, SUPER_CNT_PREVIOUS); if (SUPER[SUPER_CNT].VectorType == VT_VECTOR) { fprintf(stderr, "Near Vector: %s {%s}\n", SUPER[SUPER_CNT_PREVIOUS].vector, SUPER[SUPER_CNT_PREVIOUS].comment); fprintf(stderr, "Near Vector: %s {%s}\n", SUPER[SUPER_CNT_PREVIOUS].vector, SUPER[SUPER_CNT_PREVIOUS].comment); } else { fprintf(stderr, "Near Comment:{%s}\n", SUPER[SUPER_CNT_PREVIOUS].comment); fprintf(stderr, "Near Comment:{%s}\n", SUPER[SUPER_CNT_PREVIOUS].comment); } exit(1); } SUPER_CNT_PREVIOUS = SUPER_CNT; SUPER[SUPER_CNT].begin = SUPER[SUPER_CNT].end = 0; SUPER[SUPER_CNT].matchcnt = SUPER[SUPER_CNT].inmatch = 0; SUPER[SUPER_CNT].shutdownvect = SUPER[SUPER_CNT].repeatcnt = SUPER[SUPER_CNT].repeatforever = 0; SUPER[SUPER_CNT].dummy = 1; /* initial to dummy. if its real, set it to zero */ SUPER[SUPER_CNT].vc = vc; /* this is the vector count at ANY line, previously it was -1 on each "non-vector" */ ptrNEXT = strchr(ptrSTART, '\n'); /* find end of line */ *ptrNEXT = '\0'; strncpy(linebuf, ptrSTART, LINE_BUFF - 1); linebuf[LINE_BUFF] = '\0'; strncpy(linebuforig, linebuf, LINE_BUFF - 1); if (strlen(linebuf) >= LINE_BUFF) { /* FIXME: APS this is bad as we may loose the comment close */ fprintf(fperrors, "input line from [%s] too long: [%s]\n", infile_orig, ptrSTART); fprintf(fperrors, "input line from [%s] truncated to[%s]\n", infile_orig, linebuf); fflush(fperrors); fprintf(stderr, "input line from [%s] too long:[%s]\n", infile_orig, ptrSTART); } posO = pos; pos += strlen(ptrSTART) + 1; /* next read in the right location, for the '\0' */ *ptrNEXT = '\n'; readlinenum++; if (linebuf[0] == '\0') { ptrSTART = ptrNEXT + 1; continue; } /* nothing to do */ /*---*/ strip_comments(linebuf, SUPER[SUPER_CNT].comment, &incomment); if (incomment != 0) { ptrSTART = ptrNEXT + 1; continue; } /* don't do anything else if its nested */ /*---*/ check_for_match(linebuf, &match_loc, &SUPER[SUPER_CNT].matchcnt); /* official syntax is "match repeat nnn" but can just have "match nnn", so check both */ if (match_loc != NO_MATCH) { /* match can have the begin on the same line so be careful */ SUPER[SUPER_CNT].dummy = 0; flag_match = 1; first_match_line = SUPER_CNT; last_was_repeat = 0; } /*---*/ CFRF = check_for_repeat(linebuf, &repeat_loc, &SUPER[SUPER_CNT].repeatcnt, loopnest); if (CFRF == RET_FOREVER) { flag_repeatforever = 1; fprintf(stdout,"SETTING REPEAT FOREVER********************************\n"); SUPER[SUPER_CNT].repeatforever = 1; SUPER[SUPER_CNT].dummy = 0; } if (SUPER[SUPER_CNT].repeatcnt == 1) { fprintf(stderr, "Repeat of 1 in [%s],ignoring\n", infile_orig); fprintf(fperrors, "Repeat of 1 in [%s],ignoring\n", infile_orig); SUPER[SUPER_CNT].repeatcnt = 0; } else if (SUPER[SUPER_CNT].repeatcnt > 1) { SUPER[SUPER_CNT].dummy = 0; if (loopnest < 1) { /* we get one begin automatically for the pattern begin->end */ fprintf(fperrors, "loop-nest problem, should be greater than zero[%s]approxline[%ld]cnt[%d]\n[%s]\n", infile_orig, readlinenum, loopnest, linebuforig); fprintf(stderr, "loop-nest problem, should be greater than zero[%s]approxline[%ld]cnt[%d]\n", infile_orig, readlinenum, loopnest); exit(1); } else { last_was_repeat = 1; last_repeat[loopnest] = SUPER[SUPER_CNT].repeatcnt; } } /*---*/ check_for_begin(linebuf, &begin_loc, &loopnest); /* this can/will increment loopnest */ if (begin_loc != -1) { if (begin_before_set == 0) begin_before_set = 1; SUPER[SUPER_CNT].dummy = 0; if (inshutdown > 0) inshutdown++; SUPER[SUPER_CNT].shutdownvect = inshutdown; begin_pending_index[loopnest] = SUPER_CNT; SUPER[SUPER_CNT].begin = 1; if (last_was_repeat == 1) { if (loopnest > 0) { repeat_calc *= last_repeat[loopnest - 1]; /* need to be one up */ if (repeat_calc > max_repeat_block) max_repeat_block = repeat_calc; } SUPER[SUPER_CNT].beginpointtoend = 0; } } else SUPER[SUPER_CNT].begin = 0; /*---*/ /*---*/ check_for_end(linebuf, &end_loc, loopnest); if (end_loc != -1) { SUPER[SUPER_CNT].end = 1; SUPER[SUPER_CNT].dummy = 0; if (inshutdown > 0) inshutdown--; SUPER[SUPER_CNT].shutdownvect = inshutdown; if (inshutdown == 1) inshutdown = 0; SUPER[begin_pending_index[loopnest]].beginpointtoend = SUPER_CNT; SUPER[SUPER_CNT].endpointtobegin = begin_pending_index[loopnest]; if (last_was_repeat) { if (loopnest > 0) { if (last_repeat[loopnest - 1] != 0) repeat_calc /= last_repeat[loopnest - 1]; /* need to be one up */ } } loopnest--; if (loopnest < 0) { fprintf(fperrors, "FATAL:Found extra 'end;', error in [%s],exiting\n", infile_orig); exit(1); } } if (loopnest > max_rpt_depth) max_rpt_depth = loopnest; SUPER[SUPER_CNT].level = loopnest; /*---*/ check_for_shutdown(linebuf, &shutdown_loc); if (shutdown_loc != -1) { SUPER[SUPER_CNT].dummy = 0; last_was_repeat = 0; SUPER[SUPER_CNT].shutdownvect = inshutdown = 1; } /*---*/ check_for_align_until(linebuf); /* these do nothing useful other than flag */ check_for_subroutine(linebuf); /*---*/ SUPER[SUPER_CNT].VectorType = VT_NONE; SCAN = check_for_scan(linebuf); if (SCAN) { flag_scan = 1; // fclose(fpout1); // sprintf(linebuf,"%s.proc",infile_base); // remove(linebuf); /* if we have comments then wipe them and reacquire line */ ptrNEXT = strchr(ptrSTART, ';'); /* find end of line */ *ptrNEXT = '\0'; /* reacquire line, these are special because they can be long lines... */ if (strstr(ptrSTART, "ScanIn") != NULL || strstr(ptrSTART, "ScanOut") != NULL) { /* or ScanSetCoupled contains ScanInOrder ScanOutOrder */ *ptrNEXT = ';'; if ((ptrBO = strchr(ptrSTART, '{')) != NULL) { /* this kills the comment in the source data!,BAD */ while (*ptrBO != '}') *ptrBO++ = ' '; *ptrBO = ' '; } ptrNEXT = strchr(ptrSTART, ';'); /* find end of line, now with {} removed */ phold = *(ptrNEXT + 1); *(ptrNEXT + 1) = '\0'; strncpy(SCANV[SCANCNT].vector, ptrSTART, MAX_SCAN_LEN - 1); if (strstr(SCANV[SCANCNT].vector,"ScanSet") != NULL) { strncpy(nv1,SCANV[SCANCNT].vector, MAX_SCAN_LEN); ptr = strchr(nv1, '['); ptr2 = strchr(nv1, ']'); phold = *(ptr2 + 1); *(ptr2 + 1) = '\0'; // fprintf(stdout,"NV1=[%s]\n",nv1); expand_vector(nv2, nv1, ptr, __LINE__, __FILE__); // fprintf(stdout,"NV2=[%s]\n",nv2); *(ptr2 + 1) = phold; // *(nv2 + strlen(nv2) - 1) = '\0'; /* back over "];" */ ptr3=strrchr(nv2,']'); *ptr3='\0';/* find ']' and replace it NOW!!! */ strncat(nv2, ptr2, MAX_SCAN_LEN); // fprintf(stdout,"NV[%s]\nOV[%s]\n",nv2, nv1); strcpy(SCANV[SCANCNT].vector,nv2); // fprintf(stdout,"POST[%s]\n",nv2); } posO += strlen(ptrSTART) + 1; /* next read in the right location, for the '\0' */ pos = posO; *(ptrNEXT + 1) = phold; ptrCR = SCANV[SCANCNT].vector; while (NULL != (ptrCRN = strchr(ptrCR, '\n'))) { *ptrCRN = ' '; ptrCR = ptrCRN; } SUPER[SUPER_CNT].VectorType = VT_SCAN; // fprintf(stdout,"[%d][%s]\n",SCANCNT,SCANV[SCANCNT].vector); SUPER[SUPER_CNT].scannum = SCANCNT++; if (SCANCNT > MAXSCAN) { fprintf(stderr, "Too many scanin/out statements[%d][%s,%d,%s]\n", SCANCNT, __FILE__, __LINE__, __FUNCTION__); exit(1); } SUPER_CNT++; if (SUPER_CNT > MAXPATLINES) { fprintf(stderr, "FATAL_S[%s]Source file has too many lines.Max[%d].\n", infile_orig, MAXPATLINES); fprintf(stderr, "FATAL_S[%s]You should split this into two or more sub-patterns. Exiting...[%s,%d,%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "FATAL_S[%s]Source file has too many lines.Max[%d]\n", infile_orig, MAXPATLINES); fprintf(fperrors, "FATAL_S[%s]You should split this into two or more sub-patterns. Exiting...[%s,%d,%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); fclose(fperrors); if (gunzip) remove(tempgunzipname); fclose(fpout1); remove(outfile1); exit(1); } } else { *ptrNEXT = ';'; SUPER[SUPER_CNT].VectorType = VT_SCANCONTROL; strncpy(SUPER[SUPER_CNT].vector, linebuf, LINE_BUFF - 1); SUPER_CNT++; if (SUPER_CNT > MAXPATLINES) { fprintf(stderr, "FATAL_S[%s]Source file has too many lines.Max[%d].\n", infile_orig, MAXPATLINES); fprintf(stderr, "FATAL_S[%s]You should split this into two or more sub-patterns. Exiting...[%s,%d,%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "FATAL_S[%s]Source file has too many lines.Max[%d]\n", infile_orig, MAXPATLINES); fprintf(fperrors, "FATAL_S[%s]You should split this into two or more sub-patterns. Exiting...[%s,%d,%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); fclose(fperrors); if (gunzip) remove(tempgunzipname); fclose(fpout1); remove(outfile1); exit(1); } } } /*---*/ /* returns location of ';' */ CFS = check_for_SET(linebuf, SUPER[SUPER_CNT].vector, &vs, &ve); CFV = 0; if (CFS != 0) { if (begin_before_set == 0 && first_set == 0) { /* we hit the first set and there has been no begin yet */ strcpy(SUPER[SUPER_CNT + 1].vector, SUPER[SUPER_CNT].vector); /* push set down one */ SUPER[SUPER_CNT].dummy = 0; loopnest++; /* this is done in the check_for_begin function! */ begin_pending_index[loopnest] = SUPER_CNT; SUPER[SUPER_CNT].begin = 1; first_set = begin_before_set = 1; /* flag that we put one in */ SUPER_CNT++; if (SUPER_CNT > MAXPATLINES) { fprintf(stderr, "FATAL_S[%s]Source file has too many lines.Max[%d]\n", infile_orig, MAXPATLINES); fprintf(stderr, "FATAL_S[%s]You should split this into two or more sub-patterns. Exiting...[%s,%d,%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "FATAL_S[%s]Source file has too many lines.Max[%d]\n", infile_orig, MAXPATLINES); fprintf(fperrors, "FATAL_S[%s]You should split this into two or more sub-patterns. Exiting...[%s,%d,%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); fclose(fperrors); if (gunzip) remove(tempgunzipname); fclose(fpout1); remove(outfile1); exit(1); } fprintf(stdout,"normal VTSET[%d][%s]\n",SUPER_CNT, SUPER[SUPER_CNT].vector); } else { fprintf(stdout,"internal VTSET[%d][%s]\n",SUPER_CNT, SUPER[SUPER_CNT].vector); } SUPER[SUPER_CNT].VectorType = VT_SET; SUPER[SUPER_CNT].dummy = 0; SUPER[SUPER_CNT].label[0] = '\0'; } /*---*/ else { /* can't be vector if already SET */ CFV = check_for_vector(linebuf, SUPER[SUPER_CNT].vector, &vs, &ve, SUPER[SUPER_CNT].label); } if (CFV) { SUPER[SUPER_CNT].dummy = 0; vc++; SUPER[SUPER_CNT].VectorType = VT_VECTOR; SUPER[SUPER_CNT].shutdownvect = inshutdown; if (inshutdown == 1) inshutdown = 0; /* ==1 no begin-end loop, single vector, die */ } if (CFV < repeat_loc) SUPER[SUPER_CNT].vectisbefore = 1; else if (CFV < match_loc) SUPER[SUPER_CNT].vectisbefore = 1; else SUPER[SUPER_CNT].vectisbefore = 0; /*---*/ SUPER_CNT++; if (SUPER_CNT > MAXPATLINES) { fprintf(stderr, "FATAL_S[%s]Source file has too many lines.Max[%d].\n", infile_orig, MAXPATLINES); fprintf(stderr, "FATAL_S[%s]You should split this into two or more sub-patterns. Exiting...[%s,%d,%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); fprintf(fperrors, "FATAL_S[%s]Source file has too many lines.Max[%d]\n", infile_orig, MAXPATLINES); fprintf(fperrors, "FATAL_S[%s]You should split this into two or more sub-patterns. Exiting...[%s,%d,%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); fclose(fperrors); if (gunzip) remove(tempgunzipname); fclose(fpout1); remove(outfile1); exit(1); } ptrSTART = ptrNEXT + 1; } /* write out a summary of the pattern */ for (i = 0; i < SUPER_CNT; i++) if (SUPER[i].begin == 1) break; if (i != SUPER_CNT) fprintf(fpstatus, "FileStat:First begin at %6d in [%s]\n", i, infile_orig); else fprintf(fpstatus, "FileStat:*Error no begin found* in [%s]\n", infile_orig); fprintf(fpstatus, "FileStat:Got %6d lines from [%s]\n", SUPER_CNT, infile_orig); fprintf(fpstatus, "FileStat:vectors %6d in [%s]\n", vc, infile_orig); fprintf(fpstatus, "FileStat:Max loop depth %2d in [%s]\n", max_rpt_depth, infile_orig); fprintf(fpstatus, "FileStat:Max RPT depth count %2d in [%s]\n", max_repeat_block, infile_orig); fprintf(fpstatus, "FileStat:Match? %3s in [%s]\n", (flag_match == 0) ? "NO" : "YES", infile_orig); fprintf(fpstatus, "FileStat:Scan? %3s in [%s]\n", (flag_scan == 0) ? "NO" : "YES", infile_orig); fprintf(fpstatus, "FileStat:Repeat forever? %3s in [%s]\n", (flag_repeatforever == 0) ? "NO" : "YES", infile_orig); /* check for bad stuff */ if (vc == 0) { fprintf(fperrors, "Fatal:Got no vectors from this pattern[%s]\n", infile_orig); if (incomment) fprintf(fperrors, "Fatal:Ended inside multiline comment!!!!\n"); } /***************************************/ /* begin main loop */ /***************************************/ fprintf(fpout1, "{-FLAG-preprocessed with %s REV:%2.1f:%s by Anthony Sully compile_date:%s@%s}\n", compilestr, REV, progstr, __DATE__, __TIME__); maxblksizeallowed = (int) (1000000.0) / ((float) fhlen / 50.0); if (max_repeat_block > maxblksizeallowed) { fprintf(fpstatus, "Max loop size allowed is [%d] based on pin width of [%d]\n", maxblksizeallowed, fhlen); fprintf(fpstatus, "This was exceeded [%d], so translating as CPM\n", max_repeat_block); fprintf(stdout, "Max loop size allowed is [%d] based on pin width of [%d]\n", maxblksizeallowed, fhlen); fprintf(stdout, "This was exceeded [%d], so translating as CPM\n", max_repeat_block); } fprintf(fpstatus, "Max loop size allowed is [%d] based on pin width of [%d]\n", maxblksizeallowed, fhlen); if (flag_scan && !(flag_match || flag_repeatforever || max_repeat_block > maxblksizeallowed)) { /* output as pure SCAN pattern */ conv_vect = output_scan(outfile1, CYCLETBL, &SUPER_CNT, SUPER); free(patbuf); /* rest are free'd in output_scan before calling VCS */ if (gunzip) { /* !!!ONLY!!! remove this if gunzipping because otherwise the original filename is copied in!!! */ if (0 != remove(tempgunzipname)) perror("Can't remove ungzipped file"); } exit(RET_GOOD); } else if (flag_scan) { /* means cpm calling dpm scan.... */ /* output as pure SCAN pattern */ conv_vect = output_scan_cpm(outfile1, CYCLETBL, &SUPER_CNT, SUPER); free(patbuf); /* rest are free'd in output_scan before calling VCS */ if (gunzip) { /* !!!ONLY!!! remove this if gunzipping because otherwise the original filename is copied in!!! */ if (0 != remove(tempgunzipname)) perror("Can't remove ungzipped file"); } exit(RET_GOOD); } else if (flag_match || flag_repeatforever || max_repeat_block > maxblksizeallowed) { /* output as CPM calling DPM pattern */ if (strstr(compilestr, "PRE_PROC_CPM") == NULL) { if (max_repeat_block > maxblksizeallowed) { fprintf(stdout, "CPM->%s\n", compilestr); conv_vect = output_cpm_dpm(&SUPER_CNT, SUPER, 1); } else { fprintf(stdout, "DPM->%s\n", compilestr); conv_vect = output_cpm_dpm(&SUPER_CNT, SUPER, 0); } } else { fprintf(stdout, "CPM_FORCED:%s\n", compilestr); conv_vect = output_cpm_dpm(&SUPER_CNT, SUPER, 1); } } else { /* its just DPM */ /* but we can still force CPM with this: */ if (strstr(compilestr, "PRE_PROC_CPM") != NULL) { fprintf(stdout, "CPM_FORCED(DPM):%s\n", compilestr); conv_vect = output_cpm_dpm(&SUPER_CNT, SUPER, 1); } else { fprintf(stdout, "DPM->%s\n", compilestr); conv_vect = output_dpm(&SUPER_CNT, SUPER); chksumout(fpout1, "(*", "*)"); fclose(fpout1); } } //fclose(fpout1);/* closed by output functions */ /* before calling figure out the size */ ret = stat(outfile1, &statbuf); if (statbuf.st_size >= MAXFILESIZE) { fprintf(stderr, "file[%s] is too big(2GB). Need to retranslate as CPM\n", outfile1); fprintf(fperrors, "file[%s] is too big(2GB). Need to retranslate as CPM\n", outfile1); remove(outfile1); /* we can free here because this is a termination point! */ free(SUPER); free(SCANV); free(patbuf); /* We can get by with just this statement because if its not compressed we copy infile_orig into */ /* tempgunzipname */ sprintf(tempstr, "%s %s %s", PRE_PROC_CPM, tempgunzipname, CYCLETBL); fprintf(fperrors, "[%s]\n", tempstr); system(tempstr); if (gunzip) { /* !!!ONLY!!! remove this if gunzipping because otherwise the original filename is copied in!!! */ if (0 != remove(tempgunzipname)) perror("Can't remove ungzipped file"); } fprintf(fpstatus, "BACK from %s\n", PRE_PROC_CPM); fclose(fpstatus); fclose(fperrors); exit(RET_GOOD); /* exit, done! */ } if (gunzip) { /* !!!ONLY!!! remove this if gunzipping because otherwise the original filename is copied in!!! */ if (0 != remove(tempgunzipname)) perror("Can't remove ungzipped file"); } if (RESULT_BAD == 1 && debug == 0) { fprintf(fperrors, "Preprocessing of [%s] had errors, so vector data may be WRONG!,source[%s][%d][%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); fprintf(stderr, "Preprocessing of [%s] had errors, so vector data may be WRONG!,source[%s][%d][%s]\n", infile_orig, __FILE__, __LINE__, __FUNCTION__); } /* be careful, these were free'd above, and in the scan routine */ free(SUPER); free(SCANV); free(patbuf); fprintf(stdout, "TOTAL BEGINS[%d], TOTAL ENDS[%d], TOTAL REPEATS[%d], MAXLOOPDEPTH[%d]\n", BEGINCNT, ENDCNT, REPEATCNT, MAXLOOPDEPTH); if (!flag_scan) { /* output_scan deals with calling VCS */ fprintf(fpstatus, "FYI:%s:AUTO LAUNCHING vector_convert_polaris on pattern[%s]\n", compilestr, outfile1); fprintf(stderr, "FYI:AUTO LAUNCHING vector_convert_polaris on pattern[%s]\n", outfile1); /* before calling figure out the size */ sprintf(tempstr, "%s %s %s", VECTOR_CONVERT_POLARIS, outfile1, CYCLETBL); system(tempstr); /* call VCP */ fprintf(fpstatus, "Back from VCP\n"); fclose(fpstatus); fclose(fperrors); return (RET_GOOD); } return (RET_GOOD); } /* end of main program */
bool read_config(FILE *file, bool is_active) { struct sway_config *old_config = config; config = malloc(sizeof(struct sway_config)); config_defaults(config); config->reading = true; if (is_active) { sway_log(L_DEBUG, "Performing configuration file reload"); config->reloading = true; config->active = true; } bool success = true; enum cmd_status block = CMD_BLOCK_END; int line_number = 0; char *line; while (!feof(file)) { line = read_line(file); line_number++; line = strip_comments(line); struct cmd_results *res = config_command(line); switch(res->status) { case CMD_FAILURE: case CMD_INVALID: sway_log(L_ERROR, "Error on line %i '%s': %s", line_number, line, res->error); success = false; break; case CMD_DEFER: sway_log(L_DEBUG, "Defferring command `%s'", line); list_add(config->cmd_queue, strdup(line)); break; case CMD_BLOCK_MODE: if (block == CMD_BLOCK_END) { block = CMD_BLOCK_MODE; } else { sway_log(L_ERROR, "Invalid block '%s'", line); } break; case CMD_BLOCK_END: switch(block) { case CMD_BLOCK_MODE: sway_log(L_DEBUG, "End of mode block"); config->current_mode = config->modes->items[0]; break; case CMD_BLOCK_END: sway_log(L_ERROR, "Unmatched }"); break; default:; } default:; } free(line); free(res); } if (is_active) { config->reloading = false; arrange_windows(&root_container, -1, -1); } if (old_config) { free_config(old_config); } config->reading = false; return success; }