int main(int argc, char *argv[]) { // reads 4000 characters of brainfuck char brainfuck[4000]; FILE *in = fopen(argv[1], "r"); FILE *out = fopen(argv[2], "w"); // read from "in" file into brainfuck array fread(brainfuck, 4000, 1, in); fclose(in); if (!check_syntax(brainfuck)) { return -1; } // create assembly file make_template_top(out, argv[1]); compile(brainfuck, out); make_template_bottom(out); fclose(out); // if a third object argument is specified, compile the .o file if (argv[3]) { char command[80]; sprintf (command, "gcc %s -o %s", argv[2], argv[3]); system (command); } }
Options::Options(const char * name, const char * const optv[]) : cmdname(name), optvec(optv), explicit_end(0), optctrls(DEFAULT), nextchar(NULLSTR), listopt(NULLSTR) { const char * basename = ::strrchr(cmdname, DIR_SEP_CHAR); if (basename) cmdname = basename + 1; check_syntax(); }
int mem() { address start_address; address stop_address; long i; int cur_syn; static struct syntax_def syntax[]={ {{"MEM","ROM","AT","?ADDRESS RANGE",NULL},0}, {{"MEM","R+","?ADDRESS RANGE",NULL}, 1}, {{"MEM","RAM","AT","?ADDRESS RANGE",NULL},2}, {{"MEM","R-","?ADDRESS RANGE",NULL}, 3}, {{"MEM","NOT","AT","?ADDRESS RANGE",NULL},4}, {{"MEM","-","?ADDRESS RANGE",NULL}, 5}, {{"MEM","AT","?ADDRESS RANGE",NULL}, 6}, {{"MEM","+","?ADDRESS RANGE",NULL}, 7}, {{NULL}, -1} }; switch (cur_syn = check_syntax(parts, n_parts, syntax)) { case 0: case 1: if (get_address_range(&start_address, &stop_address, cur_syn==0 ? 3 : 2)) { for (i=start_address; i<=stop_address; i++) MemSetAttr(MEM_ROM,i); } break; case 2: case 3: if (get_address_range(&start_address, &stop_address, cur_syn==2 ? 3 : 2)) { for (i=start_address; i<=stop_address; i++) MemClearAttr(MEM_ROM,i); } break; case 4: case 5: if (get_address_range(&start_address, &stop_address, cur_syn==4 ? 3 : 2)) { for (i=start_address; i<=stop_address; i++) MemSetAttr(MEM_NOTEXIST,i); } break; case 6: case 7: if (get_address_range(&start_address, &stop_address, 2)) { for (i=start_address; i<=stop_address; i++) MemClearAttr(MEM_NOTEXIST,i); } break; } return (ERROR); }
int add_local(t_info *info, char *str) { char **new_local; if ((new_local = cpy_old_local(info)) == NULL) return (EXIT_FAILURE); if ((check_syntax(info, str, new_local)) == EXIT_FAILURE) return (EXIT_FAILURE); return (EXIT_SUCCESS); }
int regis() { int ret_code=NO_ERROR; int i; static struct syntax_def syntax[]={ {{"REGISTER",NULL}, 0}, {{NULL}, -1} }; static char *message[]={ " REGISTRATION INFORMATION", "", "To get the most out of Z80SIM, you should obtain a registered copy of", "the program. Registration provides the following benifits:", "", " 1) Newest version of the program.", " 2) Full documentation. This includes:", " a) Introductory and advanced tutorial.", " b) Complete reference manual.", " c) Expanded on-line help file.", " d) Technical documentation.", " 3) Complete source code (in ANSI C). This features:", " a) Well modularized, well documented code.", " b) High portability.", " c) Right to make modifications for personal use.", " 4) Notification of updates.", " 5) Five dollar commision for all registrations spawned by your", " copy.", "", "[INCLUDE DISCLAIMER!!]", "", "To register send $50.00 to:", "", " Peter Chapin", " P.O. Box 317", " Randolph Center, VT 05061", "", "Please be sure to include the registration number of the copy you", "are now reviewing. This allows the registered owner of this copy to", "receive his/her commision.", NULL }; if (check_syntax(parts, n_parts, syntax) == 0) { StartPrnt(); for (i=0; message[i] != NULL; i++) Prnt(message[i]); StopPrnt(); } else ret_code = ERROR; return (ret_code); }
int quit() { char *response; int ret_value=YES; static struct syntax_def syntax[]={ {{"QUIT",NULL}, 0}, {{NULL}, -1} }; if (check_syntax(parts, n_parts, syntax)==0) { response = PrntMessage(DISP_WARNING,"Are you sure? [y]/n"); if (strlen(response)==1 && response[0]=='N') ret_value = NO; } else ret_value = NO; return (ret_value); }
int viewm() { int ret_code=NO_ERROR; address new_start_address; static struct syntax_def syntax[]={ {{"VIEWM","?ADDRESS",NULL}, 0}, {{NULL}, -1} }; if (check_syntax(parts, n_parts, syntax)==0) { if (get_address(parts[1],&new_start_address)) SetMemStart(new_start_address); else ret_code = ERROR; } else ret_code = ERROR; return (ret_code); }
int main(int argc, char **argv) { ref_vector X, Xi; exome ex; check_syntax(argc, 4, "preprocess ref_file output_dir nucleotides"); timevars(); init_replace_table(argv[3]); encode_reference(&X, &ex, true, argv[1]); save_ref_vector(&X, argv[2], "X"); save_exome_file(&ex, true, argv[2]); tic("Calc. Backward Burrows-Wheeler Transform -> Sadakane direct SAIS"); direct_bwt(X.vector, X.n, argv[2], "backward", false); toc(); tic("Calc. Backward Suffix Array -> CSALIB DNA"); csa_new_from_bwt_gnu_bwt_wrapper(argv[2], "backward"); toc(); read_ref_vector(&Xi, argv[2], "X"); revstring(Xi.vector, Xi.n); save_ref_vector(&Xi, argv[2], "Xi"); tic("Calc. Forward Burrows-Wheeler Transform -> Sadakane direct SAIS"); direct_bwt(Xi.vector, Xi.n, argv[2], "forward", false); toc(); tic("Calc. Forward Suffix Array -> CSALIB DNA"); csa_new_from_bwt_gnu_bwt_wrapper(argv[2], "forward"); toc(); return 0; }
static int make_toks(const char *source, int *my_token) { int old_tok = STARTTOK, tok_in = 0; int index = 0, nparen = 0, lastindex = 0; while (source[index] != '\0') { int token = find_tok(&my_symb, source + index); lastindex = index; if (token != my_symb.len) index += my_symb.elems[token].len; if ((token == MINUS) && ((old_tok == STARTTOK) || (old_tok == COMMA) || (old_tok == LPAREN))) token = NEGATE; else if (token == LPAREN) ++nparen; else if (token == RPAREN) --nparen; if (token == my_symb.len) { char num[40]; double value; /* WARNING -- ASSUMES 32 bit int and 64 bit double */ union { struct { int int1; int int2; } pieces; struct { double z; } num; } encoder; if (do_num(source, num, &value, &index)) { plintf("illegal expression: %s\n", num); show_where(source, index); return (1); } /* new code 3/95 */ encoder.num.z = value; my_token[tok_in++] = NUMTOK; my_token[tok_in++] = encoder.pieces.int1; my_token[tok_in++] = encoder.pieces.int2; if (check_syntax(old_tok, NUMTOK) == 1) { plintf("Illegal syntax \n"); show_where(source, lastindex); return (1); } old_tok = NUMTOK; } else { my_token[tok_in++] = token; if (check_syntax(old_tok, token) == 1) { plintf("Illegal syntax (Ref:%d %d) \n", old_tok, token); show_where(source, lastindex); tokeninfo(old_tok); tokeninfo(token); return (1); } old_tok = token; } } my_token[tok_in++] = ENDTOK; if (check_syntax(old_tok, ENDTOK) == 1) { plintf("Premature end of expression \n"); show_where(source, lastindex); return (1); } if (nparen != 0) { plintf("parentheses don't match\n"); return (1); } return (0); }
int main(int argc, char **argv) { ref_vector X, B, Bi; vector C, C1; comp_vector S, Si, Scomp, Scompi; comp_vector R, Ri, Rcomp, Rcompi; comp_matrix O, Oi; int s_ratio; exome ex; check_syntax(argc, 5, "preprocess_debug ref_file output_dir s_ratio nucleotides"); timevars(); init_replace_table(argv[4]); s_ratio = atoi(argv[3]); encode_reference(&X, &ex, true, argv[1]); save_exome_file(&ex, argv[2]); tic("Calculating BWT"); calculateBWTdebug(&B, &S, &X, 0); toc(); save_ref_vector(&X, argv[2], "X"); print_vector(S.vector, S.n); print_vector(B.vector, B.n); tic("Calculating prefix-trie matrices C and O"); calculate_C(&C, &C1, &B); calculate_O(&O, &B); toc(); print_vector(C.vector, C.n); print_vector(C1.vector, C1.n); print_comp_matrix(O); save_ref_vector(&B, argv[2], "B"); free(B.vector); save_vector(&C, argv[2], "C"); free(C.vector); save_vector(&C1, argv[2], "C1"); free(C1.vector); save_comp_matrix(&O, argv[2], "O"); free_comp_matrix(NULL, &O); tic("Calculating R"); calculate_R(&R, &S); toc(); print_vector(R.vector, R.n); tic("Calculating Scomp Rcomp"); compress_SR(&S, &Scomp, s_ratio); print_vector(Scomp.vector, Scomp.n); compress_SR(&R, &Rcomp, s_ratio); print_vector(Rcomp.vector, Rcomp.n); toc(); save_comp_vector(&S, argv[2], "S"); free(S.vector); save_comp_vector(&R, argv[2], "R"); free(R.vector); save_comp_vector(&Scomp, argv[2], "Scomp"); free(Scomp.vector); save_comp_vector(&Rcomp, argv[2], "Rcomp"); free(Rcomp.vector); tic("Calculating BWT of reverse reference"); calculateBWTdebug(&Bi, &Si, &X, 1); toc(); save_ref_vector(&X, argv[2], "Xi"); print_vector(Bi.vector, Bi.n); print_vector(Si.vector, Si.n); tic("Calculating inverted prefix-trie matrix Oi"); calculate_O(&Oi, &Bi); toc(); free(X.vector); print_comp_matrix(Oi); save_ref_vector(&Bi, argv[2], "Bi"); free(Bi.vector); save_comp_matrix(&Oi, argv[2], "Oi"); free_comp_matrix(NULL, &Oi); tic("Calculating Ri"); calculate_R(&Ri, &Si); toc(); print_vector(Ri.vector, Ri.n); tic("Calculating Scompi Rcompi"); compress_SR(&Si, &Scompi, s_ratio); print_vector(Scompi.vector, Scompi.n); compress_SR(&Ri, &Rcompi, s_ratio); print_vector(Rcompi.vector, Rcompi.n); toc(); save_comp_vector(&Si, argv[2], "Si"); free(Si.vector); save_comp_vector(&Ri, argv[2], "Ri"); free(Ri.vector); save_comp_vector(&Scompi, argv[2], "Scompi"); free(Scompi.vector); save_comp_vector(&Rcompi, argv[2], "Rcompi"); free(Rcompi.vector); return 0; }
int main(int argc, char **argv) { bwt_index backward, forward; char *Worig; ref_vector W; results_list rl_prev, rl_next, rl_prev_i, rl_next_i, rl_final; uintmax_t read_index=0; uintmax_t RESULTS, FRAGSIZE; exome ex; FILE *queries_file, *output_file; check_syntax(argc, 7, "exact_search search_file input_dir output_file results_buffer frag_size nucleotides"); timevars(); init_replace_table(argv[6]); queries_file = fopen(argv[1], "r"); check_file_open(queries_file, argv[1]); output_file = fopen(argv[3], "w"); check_file_open(output_file, argv[3]); RESULTS = atoi(argv[4]); FRAGSIZE = atoi(argv[5]); if (FRAGSIZE <= 0) { fprintf(stderr, "Fragsize must be greater than 0\n"); exit(1); } tic("Loading FM-Index"); load_bwt_index(NULL, &backward, argv[2], 1, true); load_bwt_index(NULL, &forward, argv[2], 0, true); toc(); tic("Preparing search space"); load_exome_file(&ex, argv[2]); new_results_list(&rl_prev, RESULTS); new_results_list(&rl_prev_i, RESULTS); new_results_list(&rl_next, RESULTS); new_results_list(&rl_next_i, RESULTS); new_results_list(&rl_final, RESULTS); Worig = (char *) malloc( MAXLINE * sizeof(char) ); check_malloc(Worig, "main"); W.vector = (uint8_t *) malloc( MAXLINE * sizeof(uint8_t) ); check_malloc(W.vector, "main"); toc(); intmax_t *k = (intmax_t*)malloc(RESULTS * sizeof(intmax_t)); intmax_t *l = (intmax_t*)malloc(RESULTS * sizeof(intmax_t)); uintmax_t nW_aux; tic("Sequence mapping"); while(nextFASTAToken(queries_file, Worig, W.vector, &nW_aux)) { if (!W.vector) { printf ("Error de lectura de la cadena a buscar\n"); return -1; } W.n = nW_aux; rl_prev.read_index = read_index; rl_prev_i.read_index = read_index; rl_next.read_index = read_index; rl_next_i.read_index = read_index; rl_final.read_index = read_index; BWSearchCPU(W.vector, W.n, &backward, &forward, &rl_prev, &rl_next, &rl_prev_i, &rl_next_i, &rl_final, FRAGSIZE, 1); write_results(&rl_final, k, l, &ex, &backward, &forward, Worig, nW_aux, 2, output_file); rl_final.num_results=0; read_index++; } toc(); printf("Memory frees\n"); free(W.vector); free(Worig); free(k); free(l); free_bwt_index(NULL, &backward); free_bwt_index(NULL, &forward); free(rl_prev.list); free(rl_next.list); free(rl_prev_i.list); free(rl_next_i.list); free(rl_final.list); fclose(queries_file); fclose(output_file); return 0; }
int main( int argc, char *argv[] ) { if( argc != 2 ) { fprintf( stderr, "Error: No input file specified !\n" ); return E_OTHER; } E_ERROR_TYPE ret_val; char *handle_subor; /**< abstrakcia zdrojoveho suboru */ unsigned file_size; /**< velkost suboru */ ret_val = mmap_file( argv[1], &handle_subor, &file_size ); if ( ret_val != E_OK ) return E_INTERPRET_ERROR; char *subor = handle_subor; if ( check_file_header( &subor ) != E_OK ) // kontrola '<?php' na zaciatku suboru { fprintf( stderr, "Error on line 1: Missing '<?php' inserted. \n" ); free(handle_subor); return E_SYNTAX; } scanner_init( subor, file_size - 5); // scanner dostava subor o 5 znakov mensi koli '<?php' if ( ( ret_val = GeneratorInit( ) ) != E_OK ) { GeneratorErrorCleanup( ); free( handle_subor ); return ret_val; } if ( ( ret_val = check_syntax() ) != E_OK ) { GeneratorErrorCleanup( ); free( handle_subor ); return ret_val; } struct InstructionTapeBuffer *ptr; if ( ( ret_val = GeneratorPrepareTape( &ptr ) ) != E_OK ) { GeneratorErrorCleanup( ); free( handle_subor ); return ret_val; } /* Vsetko je pripravene na beh */ if ( ( ret_val = InterpretCode( ptr->array[0] ) ) != E_OK ) RuntimeErrorCleanup(); /** * Páni, vďaka za projekt !! * Tu máte niečo na zabavenie * http://www.youtube.com/watch?v=6m2THtTuBIo */ GeneratorDeleteTapes(ptr); free( handle_subor ); return ret_val; }
int ged_comb_std(struct ged *gedp, int argc, const char *argv[]) { char *comb_name; int ch; int region_flag = -1; struct directory *dp = RT_DIR_NULL; struct rt_db_internal intern; struct rt_comb_internal *comb = NULL; struct tokens tok_hd; short last_tok; int i; union tree *final_tree; static const char *usage = "[-cr] comb_name <boolean_expr>"; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_READ_ONLY(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); /* initialize result */ bu_vls_trunc(gedp->ged_result_str, 0); /* must be wanting help */ if (argc == 1) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_HELP; } if (argc < 3) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_ERROR; } /* Parse options */ bu_optind = 1; /* re-init bu_getopt() */ while ((ch = bu_getopt(argc, (char * const *)argv, "cgr?")) != -1) { switch (ch) { case 'c': case 'g': region_flag = 0; break; case 'r': region_flag = 1; break; /* XXX How about -p and -v for FASTGEN? */ case '?': default: bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_OK; } } argc -= (bu_optind + 1); argv += bu_optind; comb_name = (char *)*argv++; if (argc == -1) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_OK; } if ((region_flag != -1) && (argc == 0)) { /* * Set/Reset the REGION flag of an existing combination */ GED_DB_LOOKUP(gedp, dp, comb_name, LOOKUP_NOISY, GED_ERROR & GED_QUIET); if (!(dp->d_flags & RT_DIR_COMB)) { bu_vls_printf(gedp->ged_result_str, "%s is not a combination\n", comb_name); return GED_ERROR; } GED_DB_GET_INTERNAL(gedp, &intern, dp, (fastf_t *)NULL, &rt_uniresource, GED_ERROR); comb = (struct rt_comb_internal *)intern.idb_ptr; RT_CK_COMB(comb); if (region_flag) { if (!comb->region_flag) { /* assign values from the defaults */ comb->region_id = gedp->ged_wdbp->wdb_item_default++; comb->aircode = gedp->ged_wdbp->wdb_air_default; comb->GIFTmater = gedp->ged_wdbp->wdb_mat_default; comb->los = gedp->ged_wdbp->wdb_los_default; } comb->region_flag = 1; } else comb->region_flag = 0; GED_DB_PUT_INTERNAL(gedp, dp, &intern, &rt_uniresource, GED_ERROR); return GED_OK; } /* * At this point, we know we have a Boolean expression. * If the combination already existed and region_flag is -1, * then leave its region_flag alone. * If the combination didn't exist yet, * then pretend region_flag was 0. * Otherwise, make sure to set its c_flags according to region_flag. */ GED_CHECK_EXISTS(gedp, comb_name, LOOKUP_QUIET, GED_ERROR); dp = RT_DIR_NULL; /* parse Boolean expression */ BU_LIST_INIT(&tok_hd.l); tok_hd.type = TOK_NULL; last_tok = TOK_LPAREN; for (i = 0; i < argc; i++) { char *ptr; ptr = (char *)argv[i]; while (*ptr) { while (*ptr == '(' || *ptr == ')') { switch (*ptr) { case '(': append_lparen(&tok_hd.l); last_tok = TOK_LPAREN; break; case ')': append_rparen(&tok_hd.l); last_tok = TOK_RPAREN; break; } ptr++; } if (*ptr == '\0') continue; if (last_tok == TOK_RPAREN) { /* next token MUST be an operator */ if (add_operator(gedp, &tok_hd.l, *ptr, &last_tok) == GED_ERROR) { free_tokens(&tok_hd.l); return GED_ERROR; } ptr++; } else if (last_tok == TOK_LPAREN) { /* next token MUST be an operand */ int name_len; name_len = add_operand(gedp, &tok_hd.l, ptr); if (name_len < 1) { free_tokens(&tok_hd.l); return GED_ERROR; } last_tok = TOK_TREE; ptr += name_len; } else if (last_tok == TOK_TREE) { /* must be an operator */ if (add_operator(gedp, &tok_hd.l, *ptr, &last_tok) == GED_ERROR) { free_tokens(&tok_hd.l); return GED_ERROR; } ptr++; } else if (last_tok == TOK_UNION || last_tok == TOK_INTER || last_tok == TOK_SUBTR) { /* must be an operand */ int name_len; name_len = add_operand(gedp, &tok_hd.l, ptr); if (name_len < 1) { free_tokens(&tok_hd.l); return GED_ERROR; } last_tok = TOK_TREE; ptr += name_len; } } } if (check_syntax(gedp, &tok_hd.l, comb_name, dp)) { free_tokens(&tok_hd.l); return GED_ERROR; } final_tree = eval_bool(&tok_hd.l); { int flags; flags = RT_DIR_COMB; BU_ALLOC(comb, struct rt_comb_internal); RT_COMB_INTERNAL_INIT(comb); comb->tree = final_tree; comb->region_id = -1; if (region_flag == (-1)) comb->region_flag = 0; else comb->region_flag = region_flag; if (comb->region_flag) { comb->region_flag = 1; comb->region_id = gedp->ged_wdbp->wdb_item_default++; comb->aircode = gedp->ged_wdbp->wdb_air_default; comb->los = gedp->ged_wdbp->wdb_los_default; comb->GIFTmater = gedp->ged_wdbp->wdb_mat_default; bu_vls_printf(gedp->ged_result_str, "Creating region with attrs: region_id=%d, ", comb->region_id); if (comb->aircode) bu_vls_printf(gedp->ged_result_str, "air=%d, ", comb->aircode); bu_vls_printf(gedp->ged_result_str, "los=%d, material_id=%d\n", comb->los, comb->GIFTmater); flags |= RT_DIR_REGION; } RT_DB_INTERNAL_INIT(&intern); intern.idb_major_type = DB5_MAJORTYPE_BRLCAD; intern.idb_type = ID_COMBINATION; intern.idb_meth = &OBJ[ID_COMBINATION]; intern.idb_ptr = (void *)comb; GED_DB_DIRADD(gedp, dp, comb_name, RT_DIR_PHONY_ADDR, 0, flags, (void *)&intern.idb_type, GED_ERROR); GED_DB_PUT_INTERNAL(gedp, dp, &intern, &rt_uniresource, GED_ERROR); } return GED_OK; }
int make_cal(char *message) { char line[BUFSIZ]; int i, j = 0; int stack[BUFSIZ]; int top = 0; printf("tinybc_extra: "); fgets(line, BUFSIZ, stdin); printf("line:%s", line); if (check_syntax(line)) { for (i = 0; i < strlen(line); i++) { if (line[i] == '{') { line[i] = '('; } if (line[i] == '}') { line[i] = ')'; } if (line[i] == '[') { line[i] = '('; } if(line[i] == ']') { line[i] = ')'; } if (line[i] == '(') { message[j++] = ' '; stack[++top] = line[i]; } else if (line[i] == ')') { message[j++] = ' '; while(stack[top] != '(') { message[j++] = stack[top--]; /* need change */ } top--; /* why? */ } else if(line[i] == '+' || line[i] == '-') { message[j++] = ' '; while (top != 0 && stack[top] != '(') { message[j++] = stack[top--]; message[j++] = ' '; } stack[++top] = line[i]; } else if(line[i] == '*' || line[i] == '/') { message[j++] = ' '; while (stack[top] == '*' || stack[top] == '/') { message[j++] = stack[top--]; message[j++] = ' '; } top++; stack[top] = line[i]; } else { if(isdigit(line[i])) { message[j++] = line[i]; /* need to care for int */ } } } while (top != 0) { message[j++] = stack[top--]; } } message[j] = '\0'; printf("in_make_cal message: %s", message); return 0; }