int main(int argc, char** argv) { int opt = 0; if (check_argv(argc, argv, &opt)) // if there is unappropriate argument we return 1 return 1; if (argc == 1) // if wc receive no arguments { read_and_print_info(); printf("\n"); } int i; for (i = 1; i < argc; i++) // for every argument { if (argv[i][0] != '-') { print_wc(get_lines_c(argv[i]), get_words_c(argv[i]), get_bytes_c(argv[i]), opt); printf("\t%s\n", argv[i]); } else if (strlen(argv[i]) == 1) // is - { read_and_print_info(); printf("\t%s\n", argv[i]); } } return 0; }
static void check_args(struct mdoc *m, struct mdoc_node *n) { int i; if (NULL == n->args) return; assert(n->args->argc); for (i = 0; i < (int)n->args->argc; i++) check_argv(m, n, &n->args->argv[i]); }
int main(int argc, char const* const argv[]) { check_argv(argc, argv); std::string mode(argv[1]); if(mode == "encode") { return encode_to_file(create_test_m09(), "test09.c2ml.data"); } else if(mode == "decode") { M09 m09; validate_decode(m09, "test09.ml2c.data"); } else { std::cerr << "Invalid second argument: " << argv[1] << std::endl; return 1; } }
int main(int argc, char **argv) { t_env *env; if (argc > 1 && argc <= 3) { env = (t_env *)malloc(sizeof(t_env)); if (ft_strcmp(argv[1], "/dev/random") == 0) return (0); read_that_file(argv[1], env); if (init_struct(env) == 0 || env->map == NULL ) { ft_putstr("d1\n"); return (0); } if (argc == 3) check_argv(argv[2], env); mlx_key_hook(env->win, ft_key_hook, env); mlx_expose_hook(env->win, expose_hook, env); mlx_do_sync(env->mlx); mlx_loop(env->mlx); } return (0); }
/* * This main function is quite high density, it's functions are: * 1) Configure the FE with the BE capabilities. * 2) Despatch arguments to FE and BE argument checkers. * 3) Open and read the BF file. * 4) Decode the BF into calls of the outrun() function. * 5) Run length encode calls to the outrun() function. * 6) Ensure that '[', ']' commands balance. * 7) Allow the '#' command only if enabled. * 8) If enabled; decode input RLE (a number prefix on the "+-<>" commands) * 9) If enabled; decode input quoted strings as BF print sequences. * 10) If enabled; convert the '=' command into '[-]'. */ int main(int argc, char ** argv) { int ar, mm=0; char * pgm = argv[0]; char ** filelist = 0; int filecount = 0; filelist = calloc(argc, sizeof*filelist); for(ar=1;ar<argc;ar++) { if (argv[ar][0] != '-' || argv[ar][1] == '\0' || mm) { filelist[filecount++] = argv[ar]; } else if (strcmp(argv[ar], "-h") == 0) { fprintf(stderr, "%s: [options] [File]\n", pgm); fprintf(stderr, "%s\n", "\t" "-h This message"); if (!be_interface.bytesonly) fprintf(stderr, "%s\n", "\t" "-b Force byte cells" ); if (be_interface.hasdebug) fprintf(stderr, "%s\n", "\t" "-# Turn on trace code." ); fprintf(stderr, "%s%d%s\n", "\t" "-R Decode rle on '+-<>', quoted strings and '='." "\n\t" "-m Disable optimisation (including dead loop removal)" "\n\t" "-p Optimise as part of a BF program" "\n\t" "-O Enable optimisation" "\n\t" "-M<num> Set length of tape, default is ", TAPELEN, "" ); if (check_arg("-M")) printf("\t-M Set the tape to dynamic\n"); check_arg(argv[ar]); exit(0); } else if (check_argv(argv[ar])) { ; } else if (strcmp(argv[ar], "--") == 0) { mm = 1; } else { char * ap = argv[ar]+1; static char buf[4] = "-X"; while(*ap) { buf[1] = *ap; if (!check_argv(buf)) break; ap++; } if (*ap) { fprintf(stderr, "Unknown option '%s'; try -h for option list\n", argv[ar]); exit(1); } } } check_arg("+init"); /* Callout to BE for soft init. */ /* Defaults if not told */ if (!opt_optim && be_interface.disable_fe_optim) opt_optim = disable_init_optim = 1; if (!opt_optim) opt_optim = enable_optim = 1; tapeinit = (!be_interface.disable_be_optim && !backend_only)?BOFF:0; if (be_interface.bytesonly) bytecell = 1; if (filecount == 0) filelist[filecount++] = "-"; if (backend_only) pipe_to_be(filelist, filecount); else load_and_run(filelist, filecount); return 0; }
int main(int argc, char ** argv) { char * pgm = argv[0]; int ch, lastch=']', c=0, m, b=0, lc=0, ar, cf=0; FILE * ifd; char ** filelist = 0; int filecount = 0; filelist = calloc(argc, sizeof*filelist); for(ar=1;ar<argc;ar++) { if (argv[ar][0] != '-' || argv[ar][1] == '\0') { filelist[filecount++] = argv[ar]; } else if (strcmp(argv[ar], "-h") == 0) { fprintf(stderr, "%s: [options] [File]\n", pgm); fprintf(stderr, "%s%d%s\n", "\t" "-h This message" "\n\t" "-i Use int cells" "\n\t" "-M<num> Set length of tape, default is ", TAPELEN, ""); exit(0); } else if (check_argv(argv[ar])) { ; } else if (strcmp(argv[ar], "--") == 0) { ; break; } else if (argv[ar][0] == '-') { char * ap = argv[ar]+1; static char buf[4] = "-X"; while(*ap) { buf[1] = *ap; if (!check_argv(buf)) break; ap++; } if (*ap) { fprintf(stderr, "Unknown option '%s'; try -h for option list\n", argv[ar]); exit(1); } } else filelist[filecount++] = argv[ar]; } if (filecount == 0) filelist[filecount++] = "-"; /* Now we do it ... */ outrun('!', 0); for(ar=0; ar<filecount; ar++) { if (strcmp(filelist[ar], "-") == 0) { ifd = stdin; current_file = "stdin"; } else if((ifd = fopen(filelist[ar],"r")) == 0) { perror(filelist[ar]); exit(1); } else current_file = filelist[ar]; while((ch = getc(ifd)) != EOF && (ifd!=stdin || ch != '!' || lc || b || (c==0 && cf==0))) { if (ch == ' ' || ch == '\t') continue; /* These chars are RLE */ m = (ch == '>' || ch == '<' || ch == '+' || ch == '-'); /* These ones are not */ if(!m && ch != '[' && ch != ']' && ch != '.' && ch != ',' && (ch != '#' || !enable_debug)) continue; /* Check for loop comments; ie: ][ comment ] */ if (lc || (ch=='[' && lastch==']')) { lc += (ch=='[') - (ch==']'); continue; } if (lc) continue; cf=1; /* Do the RLE */ if (m && ch == lastch) { c++; continue; } /* Post the RLE token onward */ if (c) outrun(lastch, c); if (!m) { /* Non RLE tokens here */ if (!b && ch == ']') continue; /* Ignore too many ']' */ b += (ch=='[') - (ch==']'); if (lastch == '[' && ch == ']') outrun('X', 1); outrun(ch, 1); c = 0; } else c = 1; lastch = ch; } if (ifd != stdin) fclose(ifd); } if(c) outrun(lastch, c); while(b>0){ outrun(']', 1); b--;} /* Not enough ']', add some. */ setbuf(stdout, 0); outrun('~', 0); return 0; }