/** * eo_prep * ``````` * Validate and prepare the command line arguments for execution. * * @argc : number of arguments * @argv : vector of arguments * Return: nothing. */ void eo_prep(int argc, char *argv[]) { struct routine_t *r; static int tree[30]; int i; if (isarg(1, "stat")) print_config(); else if (isarg(1, "init")) eo_init(); else if (isarg(1, "kleene")) { if ((kleene(argv[2], argv[3]))) printf("match\n"); else printf("no match\n"); } else { /* If there is only one argument, assume the CWD. */ /*r = (argc==2) ? parse(scwd(), argv[1]) */ /*: parse(argv[1], argv[2]);*/ if (argc == 2) build_tree(tree, argv[1]); else build_tree(tree, argv[2]); for (i=0; tree[i] != END; i++) { printf("%s (%d)\n", op_name[tree[i]], tree[i]); } return; eo_process(r); } return; }
int word(char *w) { Keyword *kp; int c, n; n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0])); /* BUG: this ought to be inside the if; in theory could fault (daniel barrett) */ kp = keywords + n; if (n != -1) { /* found in table */ yylval.i = kp->sub; switch (kp->type) { /* special handling */ case BLTIN: if (kp->sub == FSYSTEM && safe) SYNTAX( "system is unsafe" ); RET(kp->type); case FUNC: if (infunc) SYNTAX( "illegal nested function" ); RET(kp->type); case RETURN: if (!infunc) SYNTAX( "return not in function" ); RET(kp->type); case VARNF: yylval.cp = setsymtab("NF", "", 0.0, NUM, symtab); RET(VARNF); default: RET(kp->type); } } c = peek(); /* look for '(' */ if (c != '(' && infunc && (n=isarg(w)) >= 0) { yylval.i = n; RET(ARG); } else { yylval.cp = setsymtab(w, "", 0.0, STR|NUM|DONTFREE, symtab); if (c == '(') { RET(CALL); } else { RET(VAR); } } }
int word(char *w) { Keyword *kp; int c, n; n = binsearch(w, keywords, sizeof(keywords)/sizeof(keywords[0])); kp = keywords + n; if (n != -1) { /* found in table */ yylval.i = kp->sub; switch (kp->type) { /* special handling */ case FSYSTEM: if (safe) ERROR "system is unsafe" SYNTAX; RET(kp->type); case FUNC: if (infunc) ERROR "illegal nested function" SYNTAX; RET(kp->type); case RETURN: if (!infunc) ERROR "return not in function" SYNTAX; RET(kp->type); case VARNF: yylval.cp = setsymtab("NF", "", 0.0, NUM, symtab); RET(VARNF); default: RET(kp->type); } } c = peek(); /* look for '(' */ if (c != '(' && infunc && (n=isarg(w)) >= 0) { yylval.i = n; RET(ARG); } else { yylval.cp = setsymtab(w, "", 0.0, STR|NUM|DONTFREE, symtab); if (c == '(') { RET(CALL); } else { RET(VAR); } } }
void defn(Cell *v, Node *vl, Node *st) /* turn on FCN bit in definition, */ { /* body of function, arglist */ Node *p; int n; if (isarr(v)) { SYNTAX( "`%s' is an array name and a function name", v->nval ); return; } if (isarg(v->nval) != -1) { SYNTAX( "`%s' is both function name and argument name", v->nval ); return; } v->tval = FCN; v->sval = (char *) st; n = 0; /* count arguments */ for (p = vl; p; p = p->nnext) n++; v->fval = n; dprintf( ("defining func %s (%d args)\n", v->nval, n) ); }
int yylex(void) { int c; static char *buf = 0; static int bufsize = 500; if (buf == 0 && (buf = (char *) malloc(bufsize)) == NULL) FATAL( "out of space in yylex" ); if (sc) { sc = 0; RET('}'); } if (reg) { reg = 0; return regexpr(); } /* printf("top\n"); */ for (;;) { c = gettok(&buf, &bufsize); /* printf("gettok [%s]\n", buf); */ if (c == 0) return 0; if (isalpha(c) || c == '_') return word(buf); if (isdigit(c)) { yylval.cp = setsymtab(buf, tostring(buf), atof(buf), CON|NUM, symtab); /* should this also have STR set? */ RET(NUMBER); } yylval.i = c; switch (c) { case '\n': /* {EOL} */ RET(NL); case '\r': /* assume \n is coming */ case ' ': /* {WS}+ */ case '\t': break; case '#': /* #.* strip comments */ while ((c = input()) != '\n' && c != 0) ; unput(c); break; case ';': RET(';'); case '\\': if (peek() == '\n') { input(); } else if (peek() == '\r') { input(); input(); /* \n */ lineno++; } else { RET(c); } break; case '&': if (peek() == '&') { input(); RET(AND); } else RET('&'); case '|': if (peek() == '|') { input(); RET(BOR); } else RET('|'); case '!': if (peek() == '=') { input(); yylval.i = NE; RET(NE); } else if (peek() == '~') { input(); yylval.i = NOTMATCH; RET(MATCHOP); } else RET(NOT); case '~': yylval.i = MATCH; RET(MATCHOP); case '<': if (peek() == '=') { input(); yylval.i = LE; RET(LE); } else { yylval.i = LT; RET(LT); } case '=': if (peek() == '=') { input(); yylval.i = EQ; RET(EQ); } else { yylval.i = ASSIGN; RET(ASGNOP); } case '>': if (peek() == '=') { input(); yylval.i = GE; RET(GE); } else if (peek() == '>') { input(); yylval.i = APPEND; RET(APPEND); } else { yylval.i = GT; RET(GT); } case '+': if (peek() == '+') { input(); yylval.i = INCR; RET(INCR); } else if (peek() == '=') { input(); yylval.i = ADDEQ; RET(ASGNOP); } else RET('+'); case '-': if (peek() == '-') { input(); yylval.i = DECR; RET(DECR); } else if (peek() == '=') { input(); yylval.i = SUBEQ; RET(ASGNOP); } else RET('-'); case '*': if (peek() == '=') { /* *= */ input(); yylval.i = MULTEQ; RET(ASGNOP); } else if (peek() == '*') { /* ** or **= */ input(); /* eat 2nd * */ if (peek() == '=') { input(); yylval.i = POWEQ; RET(ASGNOP); } else { RET(POWER); } } else RET('*'); case '/': RET('/'); case '%': if (peek() == '=') { input(); yylval.i = MODEQ; RET(ASGNOP); } else RET('%'); case '^': if (peek() == '=') { input(); yylval.i = POWEQ; RET(ASGNOP); } else RET(POWER); case '$': /* BUG: awkward, if not wrong */ c = gettok(&buf, &bufsize); if (isalpha(c)) { if (strcmp(buf, "NF") == 0) { /* very special */ unputstr("(NF)"); RET(INDIRECT); } c = peek(); if (c == '(' || c == '[' || (infunc && isarg(buf) >= 0)) { unputstr(buf); RET(INDIRECT); } yylval.cp = setsymtab(buf, "", 0.0, STR|NUM, symtab); RET(IVAR); } else if (c == 0) { /* */ SYNTAX( "unexpected end of input after $" ); RET(';'); } else { unputstr(buf); RET(INDIRECT); } case '}': if (--bracecnt < 0) SYNTAX( "extra }" ); sc = 1; RET(';'); case ']': if (--brackcnt < 0) SYNTAX( "extra ]" ); RET(']'); case ')': if (--parencnt < 0) SYNTAX( "extra )" ); RET(')'); case '{': bracecnt++; RET('{'); case '[': brackcnt++; RET('['); case '(': parencnt++; RET('('); case '"': return string(); /* BUG: should be like tran.c ? */ default: RET(c); } } }
int main(int argc, char **argv){ if( argc<6){ if(argc>1) fprintf(stderr,"Error, not enough arguments\n"); usage(); exit(1); } // read arguments color_image_t *im1 = color_image_load(argv[1]); color_image_t *im2 = color_image_load(argv[2]); float_image edges = read_edges(argv[3], im1->width, im1->height); float_image matches = read_matches(argv[4]); const char *outputfile = argv[5]; // prepare variables epic_params_t epic_params; epic_params_default(&epic_params); variational_params_t flow_params; variational_params_default(&flow_params); image_t *wx = image_new(im1->width, im1->height), *wy = image_new(im1->width, im1->height); // read optional arguments #define isarg(key) !strcmp(a,key) int current_arg = 6; while(current_arg < argc ){ const char* a = argv[current_arg++]; if( isarg("-h") || isarg("-help") ) usage(); else if( isarg("-nw") ) strcpy(epic_params.method, "NW"); else if( isarg("-p") || isarg("-prefnn") ) epic_params.pref_nn = atoi(argv[current_arg++]); else if( isarg("-n") || isarg("-nn") ) epic_params.nn = atoi(argv[current_arg++]); else if( isarg("-k") ) epic_params.coef_kernel = atof(argv[current_arg++]); else if( isarg("-i") || isarg("-iter") ) flow_params.niter_outer = atoi(argv[current_arg++]); else if( isarg("-a") || isarg("-alpha") ) flow_params.alpha= atof(argv[current_arg++]); else if( isarg("-g") || isarg("-gamma") ) flow_params.gamma= atof(argv[current_arg++]); else if( isarg("-d") || isarg("-delta") ) flow_params.delta= atof(argv[current_arg++]); else if( isarg("-s") || isarg("-sigma") ) flow_params.sigma= atof(argv[current_arg++]); else if( isarg("-sintel") ){ epic_params.pref_nn= 25; epic_params.nn= 160; epic_params.coef_kernel = 1.1f; flow_params.niter_outer = 5; flow_params.alpha = 1.0f; flow_params.gamma = 0.72f; flow_params.delta = 0.0f; flow_params.sigma = 1.1f; } else if( isarg("-kitti") ){ epic_params.pref_nn= 25; epic_params.nn= 160; epic_params.coef_kernel = 1.1f; flow_params.niter_outer = 2; flow_params.alpha = 1.0f; flow_params.gamma = 0.77f; flow_params.delta = 0.0f; flow_params.sigma = 1.7f; } else if( isarg("-middlebury") ){ epic_params.pref_nn= 15; epic_params.nn= 65; epic_params.coef_kernel = 0.2f; flow_params.niter_outer = 25; flow_params.alpha = 1.0f; flow_params.gamma = 0.72f; flow_params.delta = 0.0f; flow_params.sigma = 1.1f; } else{ fprintf(stderr, "unknown argument %s", a); usage(); exit(1); } } // compute interpolation and energy minimization color_image_t *imlab = rgb_to_lab(im1); epic(wx, wy, imlab, &matches, &edges, &epic_params, 1); // energy minimization variational(wx, wy, im1, im2, &flow_params); // write output file and free memory writeFlowFile(outputfile, wx, wy); color_image_delete(im1); color_image_delete(imlab); color_image_delete(im2); free(matches.pixels); free(edges.pixels); image_delete(wx); image_delete(wy); return 0; }
int main(int argc, char **argv) { int n; int stoparg = 0; char *fname1 = NULL, *fname2 = NULL; FILE *fpin = stdin, *fpout = stdout; char *s; /* Some CP/M and DOS compilers don't support argv[0] */ if (argv[0][0]) cnv_progname = argv[0]; /* Argument parsing */ for (n = 1; n < argc; n++) if (isarg(argv[n]) && !stoparg) { if (!strcmp(argv[n], "--")) { stoparg = 1; continue; } /* Check for likely help commands */ if (!stricmp(argv[n], "--help")) help(); if (!stricmp(argv[n]+1, "h" )) help(); #ifdef __MSDOS__ if (!stricmp(argv[n]+1, "?" )) help(); #endif #ifdef CPM if (!stricmp(argv[n]+1, "?" )) help(); if (!stricmp(argv[n], "//" )) help(); if (!stricmp(argv[n], "[help]")) help(); if (!stricmp(argv[n], "[h]" )) help(); #endif /* OK, it isn't a help command. */ if (argv[n][0] == '-' && argv[n][1] == '-') { handle_option(1, argv[n]+2); continue; } /* CP/M-style [VARIABLE=VALUE,VARIABLE=VALUE] options */ #ifdef CPM if (argv[n][0] == '[') { char *s; do { s = handle_option(1, argv[n]+2); } while ( s && (*s) && (*s != ']')); continue; } #endif /* Short option */ handle_option(0, argv[n]+1); } else { if (!fname1) fname1 = argv[n]; else if (!fname2) fname2 = argv[n]; else { fprintf(stderr, "%s: This program takes two filenames, so '%s' is ignored.\n", cnv_progname, argv[n]); } } /* Options parsed */ if (fname1) { fpin = fopen(fname1, "rb"); if (!fpin) { perror(fname1); exit(1); } } else fname1 = "<stdin>"; if (fname2) { fpout = fopen(fname2, "w+b"); if (!fpout) { fclose(fpin); perror(fname2); exit(1); } } else fname2 = "<stdout>"; s = cnv_execute(fpin, fpout); if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (!s) return 0; if (fpout != stdout) remove(fname2); fprintf(stderr, "%s: %s\n", cnv_progname, s); return 1; }
lex() { int c, d; char *s; if (regexflg) return sym = scanreg(); next: while ((c = Getc()) == ' ' || c == '\t') ; while (c == '#') for (c = Getc(); c != '\n'; c = Getc()) ; switch (c) { case '\\': if ((c = Getc()) == '\n') { lineno++; goto next; } break; case '\n': lineno++; break; } switch (c) { case EOF: return sym = 0; case '+': return sym = follow2('=', '+', ADDEQ, INC, ADD); case '-': return sym = follow2('=', '-', SUBEQ, DEC, SUB); case '*': return sym = follow('=', MULTEQ, MULT); case '/': return sym = follow('=', DIVEQ, DIV); case '%': return sym = follow('=', MODEQ, MOD); case '^': return sym = follow('=', POWEQ, POWER); case '=': return sym = follow('=', EQ, ASSIGN); case '!': return sym = follow2('=', '~', NE, NOMATCH, NOT); case '&': return sym = follow('&', AND, BINAND); case '|': sym = follow('|', OR, BINOR); if (printflg && sym == BINOR) sym = R_POUT; return sym; case '<': sym = follow2('=', '<', LE, SHIFTL, LT); if (getlineflg && sym == LT) sym = R_IN; return sym; case '>': sym = follow2('=', '>', GE, SHIFTR, GT); if (printflg) { switch (sym) { case GT: sym = R_OUT; break; case SHIFTR: sym = R_APD; break; } } return sym; case '~': return sym = MATCH; break; case ';': case '\n': return sym = EOL; } if (isalpha(c) || c == '_') { for (s = text; isalnum(c) || c == '_'; ) { *s++ = c; c = Getc(); } Ungetc(c); *s = '\0'; if ((d = iskeywd(text)) == 0 && (d = isbuiltin(text, &sym1)) == 0) { if (c == '(') return sym = CALL; else if (funflg) { if ((sym1 = isarg(text)) != -1) return sym = ARG; } } return sym = d ? d : IDENT; } else if (c == '.' || (isdigit(c))) { Ungetc(c); return sym = scannum(text); /* NUMBER */ } else if (c == '"') return sym = scanstr(text); /* STRING */ return sym = c; }