int main() { FILE *prodf, *custf, *ordf; char c, n; int numcond, check; int i, offset[50], j; int *condition, *relation, *condoffset; char **var; prodf = fopen("product.data", "r"); custf = fopen("customer.data", "r"); ordf = fopen("orders.data", "r"); //You have a choice with product.data customer.data and orders.data //Performing the input operation i = 0; while(1) { scanf("%d", &offset[i]); if(offset[i++] == -1) break; } scanf("%d", &numcond); condition = (int *)calloc(sizeof(int *), numcond); relation = (int *)calloc(sizeof(int *), numcond - 1); condoffset = (int *)calloc(sizeof(int *), numcond); var = (char **)calloc(sizeof(char **), numcond); for(i=0;i<numcond;i++) { var[i] = (char *)calloc(sizeof(char *), 30); scanf("%d", &condition[i]); if(condition[i] == 0) continue; scanf("%d", &condoffset[i]); scanf("%s", var[i]); printf("var entered = %s\n", var[i]); if(i > 0) { scanf("%d", &relation[i - 1]); } } //End of taking input n = getlineno(ordf); show(ordf, offset, 40, n, condition, relation, var, condoffset, numcond); return 0; }
static Token *gettoken0() { int ch; Token *t = &tok; clear_lexeme(); ch = nextch(); if (ch == EOF) return (Token*)0; switch (codeof(ch)) { case '+': case '-': case '*': case'/': case '%': case '=': t = op(ch); break; case 'Z': t = id(ch); break; case '0': case '9': t = lit(ch); break; case '@': printf("[line %d, pos %d]", getlineno(), getlinepos()); t->sym = ' '; break; default: t->sym = ch; break; } return t; }
/* this adds the config of a tagline to execution plan * HINT: order of calling arguments from stacks is IMPORTANT! */ void rule_addtag_config() { #ifdef DEBUG printf( "try to match tagline at line %i\n", getlineno()); #endif char fname[MAXSTRLEN]; int i; for (i= 0; i<MAXSTRLEN; i++) { fname[i]='\0'; } funcp f = NULL; f=malloc( sizeof( struct funcu ) ); if (NULL == f) { fprintf (stderr, "could not alloc mem for f\n"); exit(EXIT_FAILURE); }; tag_t tag = parser_state.tag; f->tag=tag; /* HINT: order of evaluating last val and last req is IMPORTANT! */ switch ( parser_state.val ) { case range: { unsigned int r = i_pop(); unsigned int l = i_pop(); snprintf(fname, MAXSTRLEN-1, "tst_tag%u_%i_%s_%u_%u", parser_state.tag, parser_state.req, "range", l, r); _helper_add_fsp_tifp_tag_uint_uint(f, &check_tag_has_value_in_range, fname, tag, l, r); break; } case logical_or: { int count_of_values = parser_state.valuelist; snprintf(fname, MAXSTRLEN-1, "tst_tag%u_%i_%s_%i", parser_state.tag, parser_state.req, "logical_or", count_of_values); unsigned int * rp = NULL; rp = malloc ( count_of_values * sizeof( int ) ); if (NULL == rp) { fprintf (stderr, "could not alloc mem for rp\n"); exit(EXIT_FAILURE); }; int i; unsigned int * rnp=rp; for (i=0; i<count_of_values; i++) { *(rnp) = i_pop(); rnp++; } _helper_add_fsp_tifp_tag_uint_uintp(f, &check_tag_has_some_of_these_values, fname, tag, count_of_values, rp); break; } case only: { int count_of_values = parser_state.valuelist; if (1 == count_of_values) { unsigned int v = i_pop(); snprintf(fname, MAXSTRLEN-1, "tst_tag%u_%i_%s_%u", parser_state.tag, parser_state.req, "only", v); _helper_add_fsp_tifp_tag_uint(f, &check_tag_has_value, fname, tag, v); } else { /* valuelist, pE. BitsPerSample */ snprintf(fname, MAXSTRLEN-1, "tst_tag%u_%i_%s_%i", parser_state.tag, parser_state.req, "onlym", count_of_values); unsigned int * rp = NULL; rp = malloc ( count_of_values * sizeof( int ) ); if (NULL == rp) { fprintf (stderr, "could not alloc mem for rp\n"); exit(EXIT_FAILURE); }; int i; unsigned int * rnp=rp; rnp+=(count_of_values-1); for (i=0; i<count_of_values; i++) { *(rnp) = i_pop(); rnp--; } _helper_add_fsp_tifp_tag_uint_uintp(f, &check_tag_has_valuelist, fname, tag, count_of_values, rp); } break; } case any: { snprintf(fname, MAXSTRLEN-1, "tst_tag%u_%i_%s", parser_state.tag, parser_state.req, "any"); _helper_add_fsp_tifp_tag(f, &check_tag, fname, tag); break; } case regex: { snprintf(fname, MAXSTRLEN-1, "tst_tag%u_%i_%s_%s", parser_state.tag, parser_state.req, "regex", parser_state.regex_string); _helper_add_fsp_tifp_tag_charp(f, &check_tag_has_value_matching_regex, fname, tag, parser_state.regex_string); break; } default: printf("unknown parserstate.val, should not occure\n"); exit(EXIT_FAILURE); } /* set predicate if and only if lastreq = depends */ /* HINT: order of evaluating last val and last req is IMPORTANT! */ /* HINT: order of calling arguments from stacks is IMPORTANT! */ switch ( parser_state.req ) { case ifdepends: { funcp predicate = NULL; predicate=malloc( sizeof( struct funcu ) ); if (NULL == predicate) { fprintf (stderr, "could not alloc mem for pred\n"); exit(EXIT_FAILURE); }; predicate->pred=NULL; if (parser_state.any_reference == 0) { unsigned int valreference = i_pop(); tag_t tagreference = i_pop(); #ifdef DEBUG printf("ifdepends %u references to %u.%u\n", tag, tagreference, valreference); #endif _helper_add_fsp_tifp_tag_uint(predicate, &check_tag_has_value_quiet, "predicate", tagreference, valreference); } else { /* point to any reference */ tag_t tagreference = i_pop(); #ifdef DEBUG printf("ifdepends %u references to %u.any\n", tag, tagreference); #endif _helper_add_fsp_tifp_tag(predicate, &check_tag_quiet, "predicate", tagreference); } f->pred=predicate; break; } case mandatory: { f->pred = NULL; break; } case optional: { funcp predicate = NULL; predicate=malloc( sizeof( struct funcu ) ); if (NULL == predicate) { fprintf (stderr, "could not alloc mem for pred\n"); exit(EXIT_FAILURE); }; predicate->pred=NULL; _helper_add_fsp_tifp_tag(predicate, &check_tag_quiet, "predicate", tag); f->pred=predicate; break; } case optdepends: { funcp predicate = NULL; predicate=malloc( sizeof( struct funcu ) ); if (NULL == predicate) { fprintf (stderr, "could not alloc mem for pred\n"); exit(EXIT_FAILURE); }; predicate->pred=NULL; /* set predicate of predicate to check_tag */ funcp predicatepredicate = NULL; predicatepredicate=malloc( sizeof( struct funcu ) ); if (NULL == predicatepredicate) { fprintf (stderr, "could not alloc mem for pred\n"); exit(EXIT_FAILURE); }; predicatepredicate->pred=NULL; _helper_add_fsp_tifp_tag(predicatepredicate, &check_tag_quiet, "predicatepredicate", tag); /* set rest of predicate */ predicate->pred = predicatepredicate; if (parser_state.any_reference == 0) { unsigned int valreference = i_pop(); tag_t tagreference = i_pop(); #ifdef DEBUG printf("optdepends %u references to %u.%u\n", tag, tagreference, valreference); #endif _helper_add_fsp_tifp_tag_uint(predicate, &check_tag_has_value_quiet, "predicate", tagreference, valreference); } else { /* point to any reference */ tag_t tagreference = i_pop(); #ifdef DEBUG printf("optdepends %u references to %u.any\n", tag, tagreference); #endif _helper_add_fsp_tifp_tag(predicate, &check_tag_quiet, "predicate", tagreference); } f->pred=predicate; break; } default: printf("unknown parserstate.req, should not occure\n"); exit(EXIT_FAILURE); } #ifdef DEBUG printf("fname='%s'\n", fname); #endif append_function_to_plan(f, fname); reset_valuelist(); parser_state.any_reference = 0; }
int vedit(const char *filename, const char *saveheader, char *bname) { int ch, foo; int lastcharindent = -1; BOOL firstkey = TRUE; char bakfile[PATHLEN]; int old_rows = t_lines, old_columns = t_columns; sethomefile(bakfile, curuser.userid, UFNAME_EDIT); if ((saveheader || uinfo.mode == EDITPLAN || uinfo.mode == EDITBMWEL) && isfile(bakfile) /* lthuang */ #ifdef GUEST && strcmp(curuser.userid, GUEST) #endif ) { clear(); outs(_msg_edit_8); if (getkey() != '2') mycp(bakfile, filename); } if (!isfile(filename)) unlink(bakfile); if (saveheader) do_article_sig(filename); read_file(filename); top_of_win = firstline; currline = firstline; curr_window_line = 0; currpnt = 0; ansi_mode = FALSE; clear(); display_buffer(); move(curr_window_line, currpnt); while ((ch = getkey()) != EOF) { if (firstkey) { firstkey = FALSE; show_help_msg(); } if (talkrequest) /* lthuang */ { backup_file(bakfile); talkreply(); pressreturn(); ch = CTRL('G'); /* redraw screen */ } else if (msqrequest) /* lthuang */ { msqrequest = FALSE; msq_reply(); #if 0 ch = CTRL('G'); #endif } if (old_rows != t_lines || old_columns != t_columns) { static const char *msg_resized = "[1;34;47m螢幕大小已改變, 按(Ctrl-G)回到頁首![m"; old_rows = t_lines; old_columns = t_columns; top_of_win = firstline; currline = top_of_win; curr_window_line = 0; currpnt = 0; shift = 0; redraw_everything = TRUE; move(t_lines / 2, (t_columns - strlen(msg_resized)) / 2); outs(msg_resized); while (getkey() != CTRL('G')); } else if (ch < 0x100 && isprint2(ch)) { insert_char(ch); lastcharindent = -1; } else switch (ch) { case KEY_UP: if (lastcharindent == -1) lastcharindent = currpnt; if (!currline->prev) { bell(); break; } curr_window_line--; currline = currline->prev; currpnt = (currline->len > lastcharindent) ? lastcharindent : currline->len; break; case KEY_DOWN: if (lastcharindent == -1) lastcharindent = currpnt; if (!currline->next) { bell(); break; } curr_window_line++; currline = currline->next; currpnt = (currline->len > lastcharindent) ? lastcharindent : currline->len; break; default: lastcharindent = -1; switch (ch) { case CTRL('T'): top_of_win = back_line(lastline, b_lines - 2); currline = lastline; curr_window_line = getlineno(); currpnt = 0; redraw_everything = TRUE; break; case CTRL('S'): top_of_win = firstline; currline = top_of_win; curr_window_line = 0; currpnt = 0; redraw_everything = TRUE; break; case '\t': do { insert_char(' '); } while (currpnt & 0x7); break; case CTRL('U'): case CTRL('V'): insert_char(0x1b); break; case CTRL('C'): insert_char(0x1b); insert_char('['); insert_char('m'); break; case KEY_RIGHT: case CTRL('F'): if (currline->len == currpnt) { if (!currline->next) bell(); else { currpnt = 0; curr_window_line++; currline = currline->next; } } else currpnt++; break; case KEY_LEFT: case CTRL('B'): if (currpnt == 0) { if (!currline->prev) bell(); else { currline = currline->prev; currpnt = currline->len; curr_window_line--; } } else currpnt--; break; case CTRL('G'): clear(); redraw_everything = TRUE; break; case CTRL('Z'): vedit_help(); break; case KEY_PGUP: case CTRL('P'): top_of_win = back_line(top_of_win, b_lines - 2); currline = top_of_win; currpnt = 0; curr_window_line = 0; redraw_everything = TRUE; break; case KEY_PGDN: case CTRL('N'): top_of_win = forward_line(top_of_win, b_lines - 2); currline = top_of_win; currpnt = 0; curr_window_line = 0; redraw_everything = TRUE; break; case KEY_HOME: case CTRL('A'): currpnt = 0; break; case KEY_END: case CTRL('E'): currpnt = currline->len; break; case CTRL('R'): #if 0 backup_file(bakfile); #endif msq_reply(); #if 0 redraw_everything = TRUE; /* lthuang */ #endif break; case CTRL('Q'): ansi_mode = TRUE; display_buffer(); pressreturn(); ansi_mode = FALSE; display_buffer(); break; case CTRL('X'): case CTRL('W'): backup_file(bakfile); clear(); foo = write_file(filename, saveheader, bname); if (foo == BACKUP_EDITING) return foo; else if (foo != KEEP_EDITING) { unlink(bakfile); return foo; } redraw_everything = TRUE; /* lthuang */ break; case '\r': case '\n': split(currline, currpnt); /* lthuang: reduce the times of backup */ if (total_num_of_line % 7 == 0) backup_file(bakfile); break; case '\177': case CTRL('H'): if (currpnt == 0) { if (!currline->prev) { bell(); break; } curr_window_line--; currline = currline->prev; currpnt = currline->len; if (*killsp(currline->next->data) == '\0') { delete_line(currline->next); redraw_everything = TRUE; } else { join_currline(); } if (curr_window_line == -1) { curr_window_line = 0; top_of_win = currline; rscroll(); } break; } currpnt--; delete_char(); break; case CTRL('D'): if (currline->len == currpnt) join_currline(); else delete_char(); break; case CTRL('Y'): currpnt = 0; currline->len = 0; delete_currline(); break; case CTRL('K'): if (currline->len == 0) delete_currline(); else if (currline->len == currpnt) join_currline(); else { currline->len = currpnt; currline->data[currpnt] = '\0'; } break; default: break; } break; } if (curr_window_line == -1) { curr_window_line = 0; if (!top_of_win->prev) { indigestion(6); bell(); } else { top_of_win = top_of_win->prev; rscroll(); } } if (curr_window_line == t_lines - 1) { curr_window_line = t_lines - 2; if (!top_of_win->next) { indigestion(7); bell(); } else { top_of_win = top_of_win->next; scroll(); } } /* lthuang: 99/07 */ if (currpnt - shift >= t_columns - 1) { shift = (currpnt / (t_columns - 1)) * (t_columns - 1) - 1; redraw_everything = TRUE; } else if (currpnt - shift < 0) { shift = 0; redraw_everything = TRUE; } if (redraw_everything) { display_buffer(); redraw_everything = FALSE; } else { move(curr_window_line, 0); clrtoeol(); /* lthuang */ vedit_outs(currline->data); } move(curr_window_line, currpnt - shift); /* lthuang: 99/07 */ } if (uinfo.mode == POSTING || uinfo.mode == SMAIL) unlink(filename); return ABORT_EDITING; }