/*======================================+ * llrpt_newfile -- Switch output to new file * usage: newfile(STRING, BOOL) -> VOID *=====================================*/ PVALUE llrpt_newfile (PNODE node, SYMTAB stab, BOOLEAN *eflg) { PNODE argvar = builtin_args(node); BOOLEAN aflag=FALSE; STRING name=0; PVALUE val = eval_and_coerce(PSTRING, argvar, stab, eflg); if (*eflg) { prog_var_error(node, stab, argvar, val, nonstrx, "newfile", "1"); delete_pvalue_ptr(&val); return NULL; } name = pvalue_to_string(val); if (!name || !name[0]) { *eflg = TRUE; prog_var_error(node, stab, argvar, val, "1st arg to newfile must be a nonempty string."); delete_pvalue_ptr(&val); return NULL; } strupdate(&outfilename, name); delete_pvalue_ptr(&val); val = eval_and_coerce(PBOOL, argvar=inext(argvar), stab, eflg); if (*eflg) { prog_var_error(node, stab, argvar, val, nonboox, "newfile", "2"); delete_pvalue_ptr(&val); return NULL; } aflag = pvalue_to_bool(val); delete_pvalue_ptr(&val); if (!set_output_file(outfilename, aflag)) { *eflg = TRUE; prog_var_error(node, stab, argvar, NULL, "Failed to open output file: %s", outfilename); } return NULL; }
int main(int argc, char **argv) { int exit_status; MR_progname = argv[0]; parse_options(argc, argv); set_output_file(output_file_name); switch (output_task) { case TASK_OUTPUT_LIB_INIT: /* Output a .init file */ exit_status = output_lib_init_file(); break; case TASK_OUTPUT_INIT_PROG: /* Output a _init.erl file. */ exit_status = output_init_program(); break; default: fprintf(stderr, "%s: unknown task\n", MR_progname); exit(EXIT_FAILURE); } return exit_status; }
FILE* openCommandPipe(char* pipeName) { FILE* fp = fopen(pipeName, "w"); if (fp != NULL) set_output_file(fp); return fp; }
/*======================================+ * start_output_file -- Start outputing to specified file * (Closes any previously open output file) * Calls msg_error & returns FALSE, if problem *=====================================*/ BOOLEAN start_output_file (STRING outfname) { BOOLEAN append=FALSE; if (set_output_file(outfname, append)) { strupdate(&outfilename, outfname); return TRUE; } else { return FALSE; } }
void packet_dump( const std::string& lib = "/phenix/u/beaumim/VernierAnalysis/prdf_analysis/prdf_tools/full_prdf_scalers/scaler_dump/librun_scalers.so", const std::string& PRDF_name = "/gpfs02/phenix/spin3/beaumim/Run12VernierPRDF/files/VSCANDATA_P00-0000364636-0005.PRDFF", const std::string& out_file_name = "testout.txt" ) { gSystem->Load(lib.c_str()); set_output_file(out_file_name); pfileopen(PRDF_name.c_str()); prun(0); finish(); std::cout << "Job done!" << std::endl; }
int main(int argc, char **argv) { int exit_status; MR_progname = argv[0]; parse_options(argc, argv); #ifdef CHECK_GET_LINE check_fp = fopen(".check_get_line", "w"); /* If the open fails, we won't write to the file */ #endif set_output_file(output_file_name); switch (output_task) { case TASK_OUTPUT_LIB_INIT: /* Output a .init file */ exit_status = output_lib_init_file(); break; case TASK_OUTPUT_STANDALONE_INIT: case TASK_OUTPUT_INIT_PROG: /* ** Output a _init.c file or a standalone initialisation ** interface. */ exit_status = output_init_program(); break; default: fprintf(stderr, "mkinit: unknown task\n"); exit(EXIT_FAILURE); } return exit_status; }
int main(int argc, char **argv) { int i, r; struct format *f; const char *input = NULL, *output = NULL; FILE *out; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "--format")) { if (i + 1 == argc) usage(); f = lookup_format(argv[i + 1]); if (!f) { fprintf(stderr, "unkown format\n"); usage(); } i++; } else if (!strcmp(argv[i], "--debug")) { yydebug = 1; } else if (!strcmp(argv[i], "-o")) { if (i + 1 == argc) usage(); output = argv[i + 1]; i++; } else { if (input) { fprintf(stderr, "multiple input files specified.\n"); usage(); } input = argv[i]; } } if (!input) { fprintf(stderr, "no input file specified\n"); usage(); } if (!f) { fprintf(stderr, "no format specified\n"); usage(); } init(); yyin = fopen(input, "r"); if (!yyin) { fprintf(stderr, "Couldn't open '%s'\n", input); exit(1); } if (!output) set_output_file(stdout); else { out = fopen(output, "w"); if (!out) { fprintf(stderr, "unable to open '%s'", output); exit(1); } set_output_file(out); } r = yyparse(); f->fn(get_result()); fclose(yyin); if (output) fclose(out); fin(); return r; }
static error_t parse_arg( int key, char * arg, struct argp_state *state ) { struct opdis_options * opts = state->input; switch ( key ) { case 'c': if (! add_job( opts->jobs, job_cflow, arg ) ) { argp_error( state, "Invalid argument for -c" ); } break; case 'l': if (! add_job( opts->jobs, job_linear, arg ) ) { argp_error( state, "Invalid argument for -l" ); } break; case 'a': if (! set_arch( opts, arg ) ) { argp_error( state, "Invalid argument for -s" ); } break; case 's': if (! set_syntax( opts, arg ) ) { argp_error( state, "Invalid argument for -s" ); } break; case 'f': if (! set_format( opts, arg ) ) { argp_error( state, "Invalid argument for -f" ); } break; case 'o': if (! set_output_file( opts, arg ) ) { argp_error( state, "Invalid argument for -o" ); } break; case 'b': if (! tgt_list_add( opts->targets, tgt_bytes, arg ) ) { argp_error( state, "Invalid argument for -b" ); } break; case 'm': if (! add_map( opts->map, arg ) ) { argp_error( state, "Invalid argument for -m" ); } break; case 'O': opts->disasm_opts = arg; break; case 'B': if (! set_bfd_target( opts, arg ) ) { argp_error( state, "Invalid argument for -B" ); } break; case 'E': add_bfd_job( opts, job_bfd_entry, NULL ); break; case 'N': if (! add_bfd_job( opts, job_bfd_symbol, arg ) ) { argp_error( state, "Invalid argument for -N" ); } break; case 'S': if (! add_bfd_job( opts, job_bfd_section, arg ) ) { argp_error( state, "Invalid argument for -N" ); } break; case 'q': opts->quiet = 1; break; case 1: opts->list_arch = 1; break; case 2: opts->list_disasm_opt = 1; break; case 3: opts->list_syntax = 1; break; case 4: opts->list_format = 1; break; case 5: opts->dry_run = 1; break; case ARGP_KEY_ARG: tgt_list_add( opts->targets, tgt_file, arg ); break; default: return ARGP_ERR_UNKNOWN; } return 0; }
int quence(char *src, char *output) { output_thingy *out; int sz_theory; int sz_actual; int success; int err; /* Parse the input file */ // if (src[0] = 0) // yyin = stdin; // else // yyin = fopen(src, "r"); err = start_preprocessor(preprocessor, src, &yyin); switch (err) { case 0 : break; case 1 : eprintf("Preprocessor executable \"%s\" not found.\n", preprocessor); break; case 2 : eprintf("Could not open input file \"%s\" for reading.\n", src); break; case 3 : eprintf("Preprocessor \"%s\" returned error on file \"%s\".\n", preprocessor, src); break; default : eprintf("Unknown preprocessor error (%d).\n", err); } if (err) return 1; asm_source_file = cpstring(src); asm_base_file = cpstring(src); asm_linenum = 1; success = (yyparse() == 0); /* Close input file, and delete temporary file if used */ if (fileno(yyin) != STDIN_FILENO) { fclose(yyin); if (preprocessor != NULL) unlink(CPP_TEMP_FILE); } if (! success) return 1; /* Check for unresolvable label refs */ if (resolve_all_label_refs(parsed_text) != 0) { eprintf("Unresolved labels (and number of occurences):\n"); print_table(0, unresolved_labels); eprintf("\n"); return 2; } /* Print parsed text */ d_printf(2, "Input file %s parsed as follows:\n", src); print_text(2, parsed_text); d_printf(2, "\n"); /* output assembled data */ out = new_output(src); if (output) set_output_file(out, output); sz_theory = encoded_text_size(parsed_text); sz_actual = compile_text(out, parsed_text); if (sz_theory == sz_actual) { output_data(out); eprintf("Syntax OK: %d bytes written.\n", sz_actual); } else { if (! safe_write) { output_data(out); eprintf("Internal compile error: %d of %d bytes written.\n", sz_actual, sz_theory); } else { eprintf("Internal compile error: %d of %d bytes generated (0 written).\n", sz_actual, sz_theory); } return 3; } return 0; }
int main(int argc, char **argv) { #define FIND_LONG_OPTION(ARRAY) \ { \ for(i = 0; i < sizeof (ARRAY) / sizeof(struct option); i++) { \ struct option *o = (ARRAY) + i; \ if(o->arg < 2) { \ if(strcmp(arg, o->opt) == 0) { \ const char *a = o->arg ? *++v : argv[0]; \ if(o->arg && !a) { \ fprintf(stderr, "%s: option '%s' need an argument\n", argv[0], *v); \ return 1; \ } \ if(o->act) o->act(a); \ goto first_loop; \ } \ } else { \ size_t len = strlen(o->opt); \ if(strncmp(arg, o->opt, len) == 0) { \ if(arg[len] && arg[len] != '=') continue; \ if(!arg[len] || !arg[len + 1]) { \ fprintf(stderr, "%s: option '%s' need an argument\n", argv[0], *v); \ return 1; \ } \ const char *a = arg + len + 1; \ if(o->act) o->act(a); \ goto first_loop; \ } \ } \ } \ } #define UNRECOGNIZED_OPTION(O) \ do { \ fprintf(stderr, "%s: error: unrecognized option '%s'\n", \ argv[0], (O)); \ return 1; \ } while(0) int verbose = 0; int no_link = 0; int preprocess_only = -1; int no_warning = -1; int end_of_options = 0; const char *output_file = NULL; char **v = argv; init_argv(); const char *vs_path = getenv("VS_PATH"); if(!vs_path) vs_path = getenv("VSINSTALLDIR"); if(!getenv("INCLUDE")) { if(vs_path) { size_t len = strlen(vs_path); if(vs_path[len - 1] == '/' || vs_path[len - 1] == '\\') len--; char buffer[len + 12 + len + 24 + 1]; memcpy(buffer, vs_path, len); memcpy(buffer + len, "/VC/include;", 12); memcpy(buffer + len + 12, vs_path, len); strcpy(buffer + len + 12 + len, "/VC/PlatformSDK/include;"); setenv("INCLUDE", buffer, 0); } else { no_warning = find_argv(argv, "-w"); if(!no_warning) fprintf(stderr, "%s: warning: no system include path set\n", argv[0]); } } if(!getenv("LIB")) { if(vs_path) { size_t len = strlen(vs_path); if(vs_path[len - 1] == '/' || vs_path[len - 1] == '\\') len--; char buffer[len + 8 + len + 20 + 1]; memcpy(buffer, vs_path, len); memcpy(buffer + len, "/VC/lib;", 8); memcpy(buffer + len + 12, vs_path, len); strcpy(buffer + len + 12 + len, "/VC/PlatformSDK/lib;"); setenv("LIB", buffer, 0); } else { if(no_warning == -1) no_warning = find_argv(argv, "-w"); if(!no_warning) fprintf(stderr, "%s: warning: no system library path set\n", argv[0]); } } first_loop: while(*++v) { if(!end_of_options && **v == '-') { int i; if((*v)[1] == '-') { const char *arg = *v + 2; if(!*arg) { end_of_options = 1; continue; } FIND_LONG_OPTION(double_dash_long_options); if(strcmp(arg, "verbose") == 0) { verbose = 1; } else UNRECOGNIZED_OPTION(*v); } else { const char *arg = *v + 1; FIND_LONG_OPTION(singal_dash_long_options); switch(*arg) { case 0: goto not_an_option; case 'c': if(arg[1]) UNRECOGNIZED_OPTION(*v); add_to_argv("-c"); no_link = 1; break; case 'D': if(arg[1]) add_to_argv(*v); else { const char *d = *++v; if(!d) { fprintf(stderr, "%s: error: macro name missing after '-D'\n", argv[0]); return 1; } define(d); } break; case 'E': if(arg[1]) UNRECOGNIZED_OPTION(*v); add_to_argv("-E"); preprocess_only = 1; break; case 'f': if(arg[1]) set_feature(arg + 1); else { const char *feature = *++v; if(!feature) { fprintf(stderr, "%s: error: option '-f' need an argument\n", argv[0]); return -1; } set_feature(feature); } break; case 'g': // -g[coff][<level>] (level: 0~3) if(arg[1]) { const char *level = arg + 1; if(strncmp(level, "coff", 4) == 0) level += 4; if(*level && *level != '-') { int i = 0; do { if(!isdigit(level[i])) { fprintf(stderr, "%s: error: unrecognized debug output level \"%s\"\n", argv[0], level); return 1; } } while(level[++i]); /* if(i > 1 || *level > '3') { fprintf(stderr, "%s: error: debug output level %s is too high\n", argv[0], level); return 1; } if(*level == '0') break; */ int l = atoi(level); if(!l) break; if(l > 3) { fprintf(stderr, "%s: error: debug output level %s is too high\n", argv[0], level); return 1; } } } add_to_argv("-Zi"); break; case 'I': if(no_warning == -1) no_warning = find_argv(argv, "-w"); //if(arg[1]) add_to_argv(*v); if(arg[1]) add_include_path(arg + 1, no_warning); else { const char *path = *++v; if(!path) { fprintf(stderr, "%s: error: option '-I' need an argument\n", argv[0]); return 1; } add_include_path(path, no_warning); } break; case 'L': if(no_warning == -1) no_warning = find_argv(argv, "-w"); if(arg[1]) add_library_path(arg + 1, no_warning); else { const char *path = *++v; if(!path) { fprintf(stderr, "%s: error: option '-L' need an argument\n", argv[0]); return 1; } add_library_path(path, no_warning); } break; case 'l': if(arg[1]) add_library(arg + 1); else { const char *path = *++v; if(!path) { fprintf(stderr, "%s: error: option '-l' need an argument\n", argv[0]); return 1; } add_library(path); } break; case 'M': if(arg[1]) UNRECOGNIZED_OPTION(*v); add_to_argv("-showIncludes"); break; case 'm': if(arg[1]) set_machine(arg + 1); else { const char *machine = *++v; if(!machine) { fprintf(stderr, "%s: argument to `-m' is missing\n", argv[0]); return 1; } set_machine(machine); } break; case 'O': if(arg[1]) { const char *o = arg + 1; if(strcmp(o, "0") == 0) add_to_argv("-Od"); else if(strcmp(o, "1") == 0) add_to_argv("-O2"); else if(strcmp(o, "3") == 0) add_to_argv("-Ox"); else if(strcmp(o, "s") == 0) add_to_argv("-O1"); else if(strcmp(o, "fast") == 0) add_to_argv("-O2"); else add_to_argv(*v); } else add_to_argv("-O2"); break; case 'o': if(arg[1]) output_file = arg + 1; else { output_file = *++v; if(!output_file) { fprintf(stderr, "%s: error: option '-o' need an argument\n", argv[0]); return 1; } } break; case 'P': if(preprocess_only == -1) preprocess_only = find_argv(argv, "-E"); if(preprocess_only) add_to_argv("-EP"); break; case 's': if(arg[1]) UNRECOGNIZED_OPTION(*v); break; case 'U': if(arg[1]) add_to_argv(*v); else { const char *u = *++v; if(!u) { fprintf(stderr, "%s: error: macro name missing after '-U'\n", argv[0]); return 1; } undefine(u); } break; case 'v': if(arg[1]) UNRECOGNIZED_OPTION(*v); verbose = 1; break; case 'W': if(!arg[1]) { if(no_warning == -1) no_warning = find_argv(argv, "-w"); if(!no_warning) { fprintf(stderr, "%s: warning: option '-W' is deprecated; use '-Wextra' instead\n", argv[0]); } add_to_argv("-Wall"); break; } if(strncmp(arg, "Wa,", 3) == 0 || strncmp(arg, "Wp,", 3) == 0 || strncmp(arg, "Wl,", 3) == 0) { (*v)[3] = 0; // XXX fprintf(stderr, "%s: warning: option '%s' is not supported\n", argv[0], *v); break; } if(set_warning(arg + 1)) break; add_to_argv(*v); break; case 'w': if(arg[1]) UNRECOGNIZED_OPTION(*v); add_to_argv("-w"); no_warning = 1; break; case 'x': if(arg[1]) set_language(arg + 1); else { const char *lang = *++v; if(!lang) { fprintf(stderr, "%s: error: missing argument to ‘-x’", argv[0]); return 4; } set_language(lang); } break; default: fprintf(stderr, "%s: error: unrecognized option '%s'\n", argv[0], *v); return 1; } } } else { not_an_option: #if defined __INTERIX && !defined _NO_CONV_PATH if(**v == '/') { char buffer[PATH_MAX + 1]; if(unixpath2win(*v, 0, buffer, sizeof buffer) == 0) { add_input_file(buffer); } else { if(no_warning == -1) no_warning = find_argv(argv, "-w"); if(!no_warning) { fprintf(stderr, "%s: warning: cannot convert '%s' to Windows path name, %s\n", argv[0], *v, strerror(errno)); } add_input_file(*v); } } else #endif add_input_file(*v); } } setvbuf(stdout, NULL, _IOLBF, 0); if(preprocess_only == -1) preprocess_only = 0; if(no_warning == -1) no_warning = 0; if(last_language && last_language_unused && !no_warning) { fprintf(stderr, "%s: warning: '-x %s' after last input file has no effect\n", argv[0], last_language); } if(!first_input_file) { if(verbose) { if(!no_link) add_to_argv("-c"); start_cl(); return 0; } fprintf(stderr, "%s: no input files\n", argv[0]); return 1; } if(multiple_input_files && (preprocess_only || no_link)) { if(output_file) { fprintf(stderr, "%s: error: cannot specify -o with -c or -E with multiple files\n", argv[0]); return 4; } else if(no_link) { fprintf(stderr, "%s: error: '-c' with multiple files is currently not supported\n", argv[0]); return -1; } } if(!output_file && !preprocess_only) { if(no_link) { size_t len = strlen(first_input_file); int n = get_last_dot(first_input_file, len); if(n >= 0) len = n; char *p = malloc(len + 3); if(!p) { perror(argv[0]); return 1; } memcpy(p, first_input_file, len); strcpy(p + len, ".o"); output_file = p; } else output_file = DEFAULT_OUTPUT_FILENAME; } if(!verbose) add_to_argv("-nologo"); if(preprocess_only) { if(output_file) target.name = output_file; target.type = PREPROCESSED_SOURCE; } else set_output_file(output_file, no_link, no_warning); //if(no_static_link) add_to_argv("-MD"); add_to_argv(no_static_link ? "-MD" : "-MT"); add_libraries_to_argv(); if(verbose) print_argv(); return start_cl(); }