token_actions() { register int i; register int j; register int k; actrow = NEW2(ntokens, short); k = action_row(0); fprintf(ftable, "\nstatic const short yydefact[] = {%6d", k); save_row(0); j = 10; for (i = 1; i < nstates; i++) { putc(',', ftable); if (j >= 10) { putc('\n', ftable); j = 1; } else { j++; } k = action_row(i); fprintf(ftable, "%6d", k); save_row(i); } fprintf(ftable, "\n};\n"); FREE(actrow); }
void accumulate_bins() { mxtype bins[MAX_BIN+1]; mxtype s; int b; /* bin number */ int i; /* character number in line */ int have_number; /* whether we are building a number */ #ifdef DEBUG #define SHOW_S printf("%d ",s); #else #define SHOW_S #endif #define ACCUMULATE do { \ SHOW_S have_number = 0; \ bins[b++] = s; \ total_counts += s; \ nnz += (s!=0); \ } while (0) for (b=0; b < MAX_BIN+1; b++) bins[b] = 0.; next_line(line,MAX_LINE); have_number = 0; s=0; b = i = 0; while (1) { const char c = line[i]; // printf("<s=%d c='%c'>",s,c); if (isdigit(c)) { if (have_number) { s = s*10 + c - '0'; } else { have_number = 1; s = c - '0'; } // printf("<digit %c s=%d>",c,s); i++; } else if (c==',' || c==';') { assert(have_number == 1); ACCUMULATE; if (c == ';') { save_row(bins, b); while (b>0) bins[--b] = 0; } i++; } else if (c=='\n' || c=='\r') { next_line(line,MAX_LINE); if (have_number) { /* End of frame if line ends in a number without punctuation */ ACCUMULATE; save_row(bins, b); return; } if (gzeof(infile)) return; i = 0; } else if (c == '\0') { /* Maybe line was too long or maybe we are at the end of the file */ next_line(line,MAX_LINE); if (gzeof(infile)) { /* If at the end of the file, finish off current frame */ if (have_number) { ACCUMULATE; save_row(bins,b); } return; } i = 0; } else if (isspace(c)) { /* If at a space between numbers ... must in be a new point */ /* Note that we don't save it, since the end of */ /* the matrix was already saved by the '\n'. The only */ /* way we can get here is if we have an empty frame. */ i++; if (have_number) { #ifdef DEBUG printf("empty frame triggered by consecutive numbers with no separator\n"); #endif return; } } else { /* Some kind of floating point character ... must be a new point */ #ifdef DEBUG printf("empty frame triggered by character which is not digit, space or separator\n"); #endif return; } } }