bool initialise_python() { if(python_script.empty()) return true; std::string content; if(!ail::read_file(python_script, content)) { error("Failed to load Python script \"" + python_script + "\""); return false; } if(prompt_mode) initialise_console(); content = ail::replace_string(content, "\r", ""); Py_Initialize(); initialise_module(); std::string script_directory; if(get_base_name(python_script, script_directory)) PyRun_SimpleString(("import sys\nsys.path.append('" + script_directory + "')\n").c_str()); if(PyRun_SimpleString(content.c_str()) != 0) return false; //PyRun_SimpleString(("execfile('" + ail::replace_string(python_script, "\\", "\\\\") + "')").c_str()); return true; }
void fz_warn_imp(fz_context *ctx, char *file, int line, const char *fmt, ...) { va_list ap; char buf[sizeof ctx->warn->message]; va_start(ap, fmt); vsnprintf(buf, sizeof buf, fmt, ap); va_end(ap); #ifdef USE_OUTPUT_DEBUG_STRING OutputDebugStringA(buf); OutputDebugStringA("\n"); #endif if (!strcmp(buf, ctx->warn->message)) { ctx->warn->count++; } else { fz_flush_warnings(ctx); fprintf(stderr, "- %s:%d: %s\n", get_base_name(file), line, buf); LOGE("warning: %s\n", buf); fz_strlcpy(ctx->warn->message, buf, sizeof ctx->warn->message); ctx->warn->count = 1; } }
char *find_material(struct aiMaterial *material) { struct aiString str; char shader[500], *p; char *name; int i; for (i = 0; i < nummats; i++) if (matlist[i].material == material) return matlist[i].shader; aiGetMaterialString(material, AI_MATKEY_NAME, &str); name = str.data; strcpy(shader, clean_material_name(name)); strcat(shader, "+"); if (!aiGetMaterialString(material, AI_MATKEY_TEXTURE_DIFFUSE(0), &str)) strcat(shader, get_base_name(str.data)); else strcat(shader, "unknown"); p = strrchr(shader, '.'); if (p) *p = 0; p = shader; while (*p) { *p = tolower(*p); p++; } matlist[nummats].name = name; matlist[nummats].material = material; matlist[nummats].shader = strdup(shader); return matlist[nummats++].shader; }
/*----------------------------------------------------------------------------*/ int main( int argc, char* argv[] ) { if (argc == 1) std::cerr << argv[0] << " image_file..." << std::endl; else for (int i=1; i!=argc; ++i) { std::ifstream f(argv[i], std::ios::binary); if (f) { try { claw::graphic::image img( f ); save( img, get_base_name(argv[i]) ); } catch(std::exception& e) { std::cerr << "Exception: " << e.what() << std::endl; } } else std::cerr << "can't open '" << argv[i] << "'" << std::endl; } return 0; }
void doodle_add_dir_images (gchar *dir, GtkWidget *box) { char base_name[255]; get_base_name (dir, base_name, 255); GtkWidget *expander = gtk_expander_new (base_name); GtkWidget *table = doodle_add_images (dir); gtk_container_add (GTK_CONTAINER (expander), table); gtk_expander_set_expanded (GTK_EXPANDER (expander), TRUE); gtk_container_add (GTK_CONTAINER (box), expander); }
/** intialize the config parser. * @param basedir - path to the config file name. If 0 the path * (base directory) of the main ser.cfg file will be used, else * basedir will be concatenated to the filename. It will be * used only if filename is not an absolute path. * @param filename - config filename (can include path elements). * @return 0 on error, !=0 on success. */ cfg_parser_t* cfg_parser_init(str* basedir, str* filename) { cfg_parser_t* st; char* pathname, *base, *abs_pathname; abs_pathname = NULL; pathname = filename->s; st = NULL; base = NULL; /* if basedir == 0 or != "" get_abs_pathname */ if (basedir == 0 || basedir->len != 0) { if ((abs_pathname = get_abs_pathname(basedir, filename)) == NULL) { ERR("cfg_parser: Error while converting %.*s to absolute" " pathname\n", STR_FMT(filename)); goto error; } pathname = abs_pathname; } if ((base = get_base_name(filename)) == NULL) goto error; if ((st = (cfg_parser_t*)pkg_malloc(sizeof(*st))) == NULL) { ERR("cfg_parser: No memory left\n"); goto error; } memset(st, '\0', sizeof(*st)); if ((st->f = fopen(pathname, "r")) == NULL) { ERR("cfg_parser: Unable to open file '%s'\n", pathname); goto error; } if (abs_pathname) pkg_free(abs_pathname); st->file = base; st->line = 1; st->col = 0; return st; error: if (st) { if (st->f) fclose(st->f); pkg_free(st); } if (base) pkg_free(base); if (abs_pathname) pkg_free(abs_pathname); return NULL; }
int sys_mkdir(const char *pathname) { int err; struct inode *dir = namei_parent(pathname); if (IS_ERR(dir)) return PTR_ERR(dir); err = -ENOSYS; if (dir->i_op && dir->i_op->mkdir) err = dir->i_op->mkdir(dir, get_base_name(pathname)); free_inode(dir); return err; }
char *build_image_name (char *dst, char *src) { char *base = get_base_name(src); while (*base) { if ((*base >= 'a' && *base <= 'z') || (*base >= 'A' && *base <= 'A') || (*base >= '0' && *base <= '9') || *base == '_') *dst++ = *base; else if (*base == '.') break; else *dst++ = '_'; base++; } *dst++ = '\0'; return dst; }
int main (int argc, char **argv) { unsigned char image_name[64]; unsigned char image[IMAGE_MAXLEN]; unsigned short image_start; unsigned int image_len; int i; argv[0] = get_base_name(argv[0]); if (argc != 2) { fprintf(stderr, "usage: %s filename\n", argv[0]); exit(1); } build_image_name(image_name, argv[1]); /* Load the s-record file */ image_len = srec_load(argv[1], image, IMAGE_MAXLEN, &image_start); /* Dump a .c file */ printf("/* Image file generated from %s by %s. */\n", argv[1], argv[0]); printf("/* See source for %s for license info. */\n", argv[1]); printf("\n"); printf("int %s_len = %d;\n", image_name, image_len); printf("unsigned char %s_image[] = {", image_name); for (i = 0; i < image_len; i++) { if (i % 16 == 0) printf("\n "); printf("%3d,", image[i]); } printf("\n"); printf("};\n"); printf("unsigned short %s_start = 0x%04x;\n", image_name, image_start); return 0; }
int gcc_modet::asm_output( bool act_as_bcc, const std::list<std::string> &preprocessed_source_files) { { bool have_files=false; for(goto_cc_cmdlinet::parsed_argvt::const_iterator it=cmdline.parsed_argv.begin(); it!=cmdline.parsed_argv.end(); it++) if(it->is_infile_name) have_files=true; if(!have_files) return EX_OK; } if(produce_hybrid_binary) { debug() << "Running " << native_tool_name << " to generate native asm output" << eom; int result=run_gcc(); if(result!=0) // native tool failed return result; } std::map<std::string, std::string> output_files; if(cmdline.isset('o')) { // GCC --combine supports more than one source file for(const auto &s : preprocessed_source_files) output_files.insert(std::make_pair(s, cmdline.get_value('o'))); } else { for(const std::string &s : preprocessed_source_files) output_files.insert( std::make_pair(s, get_base_name(s, true)+".s")); } if(output_files.empty() || (output_files.size()==1 && output_files.begin()->second=="/dev/null")) return EX_OK; debug() << "Appending preprocessed sources to generate hybrid asm output" << eom; for(const auto &so : output_files) { std::ifstream is(so.first); if(!is.is_open()) { error() << "Failed to open input source " << so.first << eom; return 1; } std::ofstream os(so.second, std::ios::app); if(!os.is_open()) { error() << "Failed to open output file " << so.second << eom; return 1; } const char comment=act_as_bcc ? ':' : '#'; os << comment << comment << " GOTO-CC" << '\n'; std::string line; while(std::getline(is, line)) { os << comment << comment << line << '\n'; } } return EX_OK; }
int gcc_modet::gcc_hybrid_binary() { { bool have_files=false; for(goto_cc_cmdlinet::parsed_argvt::const_iterator it=cmdline.parsed_argv.begin(); it!=cmdline.parsed_argv.end(); it++) if(it->is_infile_name) have_files=true; if(!have_files) return EX_OK; } std::list<std::string> output_files; if(cmdline.isset('c')) { if(cmdline.isset('o')) { // there should be only one input file output_files.push_back(cmdline.get_value('o')); } else { for(goto_cc_cmdlinet::parsed_argvt::const_iterator i_it=cmdline.parsed_argv.begin(); i_it!=cmdline.parsed_argv.end(); i_it++) if(i_it->is_infile_name && needs_preprocessing(i_it->arg)) output_files.push_back(get_base_name(i_it->arg, true)+".o"); } } else { // -c is not given if(cmdline.isset('o')) output_files.push_back(cmdline.get_value('o')); else output_files.push_back("a.out"); } if(output_files.empty() || (output_files.size()==1 && output_files.front()=="/dev/null")) return run_gcc(); debug() << "Running " << native_tool_name << " to generate hybrid binary" << eom; // save the goto-cc output files for(std::list<std::string>::const_iterator it=output_files.begin(); it!=output_files.end(); it++) { rename(it->c_str(), (*it+".goto-cc-saved").c_str()); } std::string objcopy_cmd; if(has_suffix(linker_name(cmdline, base_name), "-ld")) { objcopy_cmd=linker_name(cmdline, base_name); objcopy_cmd.erase(objcopy_cmd.size()-2); } else if(has_suffix(compiler_name(cmdline, base_name), "-gcc")) { objcopy_cmd=compiler_name(cmdline, base_name); objcopy_cmd.erase(objcopy_cmd.size()-3); } objcopy_cmd+="objcopy"; int result=run_gcc(); // merge output from gcc with goto-binaries // using objcopy, or do cleanup if an earlier call failed for(std::list<std::string>::const_iterator it=output_files.begin(); it!=output_files.end(); it++) { debug() << "merging " << *it << eom; std::string saved=*it+".goto-cc-saved"; #ifdef __linux__ if(result==0 && !cmdline.isset('c')) { // remove any existing goto-cc section std::vector<std::string> objcopy_argv; objcopy_argv.push_back(objcopy_cmd); objcopy_argv.push_back("--remove-section=goto-cc"); objcopy_argv.push_back(*it); result=run(objcopy_argv[0], objcopy_argv, "", ""); } if(result==0) { // now add goto-binary as goto-cc section std::vector<std::string> objcopy_argv; objcopy_argv.push_back(objcopy_cmd); objcopy_argv.push_back("--add-section"); objcopy_argv.push_back("goto-cc="+saved); objcopy_argv.push_back(*it); result=run(objcopy_argv[0], objcopy_argv, "", ""); } remove(saved.c_str()); #elif defined(__APPLE__) // Mac if(result==0) { std::vector<std::string> lipo_argv; // now add goto-binary as hppa7100LC section lipo_argv.push_back("lipo"); lipo_argv.push_back(*it); lipo_argv.push_back("-create"); lipo_argv.push_back("-arch"); lipo_argv.push_back("hppa7100LC"); lipo_argv.push_back(saved); lipo_argv.push_back("-output"); lipo_argv.push_back(*it); result=run(lipo_argv[0], lipo_argv, "", ""); } remove(saved.c_str()); #else error() << "binary merging not implemented for this platform" << eom; return 1; #endif } return result; }
/// does it. int gcc_modet::doit() { if(cmdline.isset('?') || cmdline.isset("help")) { help(); return EX_OK; } native_tool_name= act_as_ld ? linker_name(cmdline, base_name) : compiler_name(cmdline, base_name); unsigned int verbosity=1; bool act_as_bcc= base_name=="bcc" || base_name.find("goto-bcc")!=std::string::npos; if((cmdline.isset('v') && cmdline.have_infile_arg()) || (cmdline.isset("version") && !produce_hybrid_binary)) { // "-v" a) prints the version and b) increases verbosity. // Compilation continues, don't exit! if(act_as_ld) std::cout << "GNU ld version 2.16.91 20050610 (goto-cc " CBMC_VERSION << ")\n"; else if(act_as_bcc) std::cout << "bcc: version 0.16.17 (goto-cc " CBMC_VERSION ")\n"; else std::cout << "gcc version 3.4.4 (goto-cc " CBMC_VERSION ")\n"; } if(cmdline.isset("version")) { if(produce_hybrid_binary) return run_gcc(); std::cout << '\n' << "Copyright (C) 2006-2014 Daniel Kroening, Christoph Wintersteiger\n" << "CBMC version: " CBMC_VERSION << '\n' << "Architecture: " << config.this_architecture() << '\n' << "OS: " << config.this_operating_system() << '\n'; return EX_OK; // Exit! } if(cmdline.isset("dumpversion")) { if(produce_hybrid_binary) return run_gcc(); std::cout << "3.4.4\n"; return EX_OK; } if(cmdline.isset("Wall") || cmdline.isset("Wextra")) verbosity=2; if(cmdline.isset("verbosity")) verbosity=unsafe_string2unsigned(cmdline.get_value("verbosity")); gcc_message_handler.set_verbosity(verbosity); if(act_as_ld) { if(produce_hybrid_binary) debug() << "LD mode (hybrid)" << eom; else debug() << "LD mode" << eom; } else if(act_as_bcc) { if(produce_hybrid_binary) debug() << "BCC mode (hybrid)" << eom; else debug() << "BCC mode" << eom; } else { if(produce_hybrid_binary) debug() << "GCC mode (hybrid)" << eom; else debug() << "GCC mode" << eom; } // In gcc mode, we have just pass on to gcc to handle the following: // * if -M or -MM is given, we do dependencies only // * preprocessing (-E) // * no input files given if(act_as_ld) { } else if(cmdline.isset('M') || cmdline.isset("MM") || cmdline.isset('E') || !cmdline.have_infile_arg()) return run_gcc(); // exit! // get configuration config.set(cmdline); // Intel-specific // in GCC, m16 is 32-bit (!), as documented here: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59672 if(cmdline.isset("m16") || cmdline.isset("m32") || cmdline.isset("mx32")) { config.ansi_c.arch="i386"; config.ansi_c.set_arch_spec_i386(); } else if(cmdline.isset("m64")) { config.ansi_c.arch="x86_64"; config.ansi_c.set_arch_spec_x86_64(); } // ARM-specific if(cmdline.isset("mbig-endian") || cmdline.isset("mbig")) config.ansi_c.endianness=configt::ansi_ct::endiannesst::IS_BIG_ENDIAN; else if(cmdline.isset("little-endian") || cmdline.isset("mlittle")) config.ansi_c.endianness=configt::ansi_ct::endiannesst::IS_LITTLE_ENDIAN; if(cmdline.isset("mthumb") || cmdline.isset("mthumb-interwork")) config.ansi_c.set_arch_spec_arm("armhf"); // -mcpu sets both the arch and tune, but should only be used if // neither -march nor -mtune are passed on the command line. std::string target_cpu= cmdline.isset("march") ? cmdline.get_value("march") : cmdline.isset("mtune") ? cmdline.get_value("mtune") : cmdline.isset("mcpu") ? cmdline.get_value("mcpu") : ""; if(target_cpu!="") { // Work out what CPROVER architecture we should target. for(auto &pair : arch_map) for(auto &processor : pair.second) if(processor==target_cpu) { if(pair.first.find("mips")==std::string::npos) config.set_arch(pair.first); else { // Targeting a MIPS processor. MIPS is special; we also need // to know the endianness. -EB (big-endian) is the default. if(cmdline.isset("EL")) { if(pair.first=="mips32o") config.set_arch("mipsel"); else if(pair.first=="mips32n") config.set_arch("mipsn32el"); else config.set_arch("mips64el"); } else { if(pair.first=="mips32o") config.set_arch("mips"); else if(pair.first=="mips32n") config.set_arch("mipsn32"); else config.set_arch("mips64"); } } } } // -fshort-wchar makes wchar_t "short unsigned int" if(cmdline.isset("fshort-wchar")) { config.ansi_c.wchar_t_width=config.ansi_c.short_int_width; config.ansi_c.wchar_t_is_unsigned=true; } // -fsingle-precision-constant makes floating-point constants "float" // instead of double if(cmdline.isset("-fsingle-precision-constant")) config.ansi_c.single_precision_constant=true; // -fshort-double makes double the same as float if(cmdline.isset("fshort-double")) config.ansi_c.double_width=config.ansi_c.single_width; // determine actions to be undertaken compilet compiler(cmdline, gcc_message_handler, cmdline.isset("Werror") && cmdline.isset("Wextra") && !cmdline.isset("Wno-error")); if(act_as_ld) compiler.mode=compilet::LINK_LIBRARY; else if(cmdline.isset('S')) compiler.mode=compilet::ASSEMBLE_ONLY; else if(cmdline.isset('c')) compiler.mode=compilet::COMPILE_ONLY; else if(cmdline.isset('E')) { compiler.mode=compilet::PREPROCESS_ONLY; UNREACHABLE; } else if(cmdline.isset("shared") || cmdline.isset('r')) // really not well documented compiler.mode=compilet::COMPILE_LINK; else compiler.mode=compilet::COMPILE_LINK_EXECUTABLE; switch(compiler.mode) { case compilet::LINK_LIBRARY: debug() << "Linking a library only" << eom; break; case compilet::COMPILE_ONLY: debug() << "Compiling only" << eom; break; case compilet::ASSEMBLE_ONLY: debug() << "Assembling only" << eom; break; case compilet::PREPROCESS_ONLY: debug() << "Preprocessing only" << eom; break; case compilet::COMPILE_LINK: debug() << "Compiling and linking a library" << eom; break; case compilet::COMPILE_LINK_EXECUTABLE: debug() << "Compiling and linking an executable" << eom; break; } if(cmdline.isset("i386-win32") || cmdline.isset("winx64")) { // We may wish to reconsider the below. config.ansi_c.mode=configt::ansi_ct::flavourt::VISUAL_STUDIO; debug() << "Enabling Visual Studio syntax" << eom; } else if(config.this_operating_system()=="macos") config.ansi_c.mode=configt::ansi_ct::flavourt::APPLE; else config.ansi_c.mode=configt::ansi_ct::flavourt::GCC; if(compiler.mode==compilet::ASSEMBLE_ONLY) compiler.object_file_extension="s"; else compiler.object_file_extension="o"; if(cmdline.isset("std")) { std::string std_string=cmdline.get_value("std"); if(std_string=="gnu89" || std_string=="c89") config.ansi_c.set_c89(); if(std_string=="gnu99" || std_string=="c99" || std_string=="iso9899:1999" || std_string=="gnu9x" || std_string=="c9x" || std_string=="iso9899:199x") config.ansi_c.set_c99(); if(std_string=="gnu11" || std_string=="c11" || std_string=="gnu1x" || std_string=="c1x") config.ansi_c.set_c11(); if(std_string=="c++11" || std_string=="c++1x" || std_string=="gnu++11" || std_string=="gnu++1x" || std_string=="c++1y" || std_string=="gnu++1y") config.cpp.set_cpp11(); if(std_string=="gnu++14" || std_string=="c++14") config.cpp.set_cpp14(); } // gcc's default is 32 bits for wchar_t if(cmdline.isset("short-wchar")) config.ansi_c.wchar_t_width=16; // gcc's default is 64 bits for double if(cmdline.isset("short-double")) config.ansi_c.double_width=32; // gcc's default is signed chars on most architectures if(cmdline.isset("funsigned-char")) config.ansi_c.char_is_unsigned=true; if(cmdline.isset("fsigned-char")) config.ansi_c.char_is_unsigned=false; if(cmdline.isset('U')) config.ansi_c.undefines=cmdline.get_values('U'); if(cmdline.isset("undef")) config.ansi_c.preprocessor_options.push_back("-undef"); if(cmdline.isset("nostdinc")) config.ansi_c.preprocessor_options.push_back("-nostdinc"); if(cmdline.isset('L')) compiler.library_paths=cmdline.get_values('L'); // Don't add the system paths! if(cmdline.isset('l')) compiler.libraries=cmdline.get_values('l'); if(cmdline.isset("static")) compiler.libraries.push_back("c"); if(cmdline.isset("pthread")) compiler.libraries.push_back("pthread"); if(cmdline.isset('o')) { // given gcc -o file1 -o file2, // gcc will output to file2, not file1 compiler.output_file_object=cmdline.get_values('o').back(); compiler.output_file_executable=cmdline.get_values('o').back(); } else { compiler.output_file_object=""; compiler.output_file_executable="a.out"; } // We now iterate over any input files temp_dirt temp_dir("goto-cc-XXXXXX"); { std::string language; for(goto_cc_cmdlinet::parsed_argvt::iterator arg_it=cmdline.parsed_argv.begin(); arg_it!=cmdline.parsed_argv.end(); arg_it++) { if(arg_it->is_infile_name) { // do any preprocessing needed if(language=="cpp-output" || language=="c++-cpp-output") { compiler.add_input_file(arg_it->arg); } else if(language=="c" || language=="c++" || (language=="" && needs_preprocessing(arg_it->arg))) { std::string new_suffix; if(language=="c") new_suffix=".i"; else if(language=="c++") new_suffix=".ii"; else new_suffix=has_suffix(arg_it->arg, ".c")?".i":".ii"; std::string new_name= get_base_name(arg_it->arg, true)+new_suffix; std::string dest=temp_dir(new_name); int exit_code= preprocess(language, arg_it->arg, dest, act_as_bcc); if(exit_code!=0) { error() << "preprocessing has failed" << eom; return exit_code; } compiler.add_input_file(dest); } else compiler.add_input_file(arg_it->arg); } else if(arg_it->arg=="-x") { arg_it++; if(arg_it!=cmdline.parsed_argv.end()) { language=arg_it->arg; if(language=="none") language=""; } } else if(has_prefix(arg_it->arg, "-x")) { language=std::string(arg_it->arg, 2, std::string::npos); if(language=="none") language=""; } } } // Revert to gcc in case there is no source to compile // and no binary to link. if(compiler.source_files.empty() && compiler.object_files.empty()) return run_gcc(); // exit! if(compiler.mode==compilet::ASSEMBLE_ONLY) return asm_output(act_as_bcc, compiler.source_files); // do all the rest if(compiler.doit()) return 1; // GCC exit code for all kinds of errors // We can generate hybrid ELF and Mach-O binaries // containing both executable machine code and the goto-binary. if(produce_hybrid_binary && !act_as_bcc) return gcc_hybrid_binary(); return EX_OK; }
/// does it. int as_modet::doit() { if(cmdline.isset('?') || cmdline.isset("help")) { help(); return EX_OK; } unsigned int verbosity=1; bool act_as_as86= base_name=="as86" || base_name.find("goto-as86")!=std::string::npos; if((cmdline.isset('v') && act_as_as86) || cmdline.isset("version")) { if(act_as_as86) status() << "as86 version: 0.16.17 (goto-cc " CBMC_VERSION ")" << eom; else status() << "GNU assembler version 2.20.51.0.7 20100318" << " (goto-cc " CBMC_VERSION ")" << eom; status() << '\n' << "Copyright (C) 2006-2014 Daniel Kroening, Christoph Wintersteiger\n" << "CBMC version: " CBMC_VERSION << '\n' << "Architecture: " << config.this_architecture() << '\n' << "OS: " << config.this_operating_system() << eom; return EX_OK; // Exit! } if(cmdline.isset("w-") || cmdline.isset("warn")) verbosity=2; if(cmdline.isset("verbosity")) verbosity=unsafe_string2unsigned(cmdline.get_value("verbosity")); message_handler.set_verbosity(verbosity); if(act_as_as86) { if(produce_hybrid_binary) debug() << "AS86 mode (hybrid)" << eom; else debug() << "AS86 mode" << eom; } else { if(produce_hybrid_binary) debug() << "AS mode (hybrid)" << eom; else debug() << "AS mode" << eom; } // get configuration config.set(cmdline); // determine actions to be undertaken compilet compiler(cmdline, message_handler, cmdline.isset("fatal-warnings")); if(cmdline.isset('b')) // as86 only { compiler.mode=compilet::COMPILE_LINK_EXECUTABLE; debug() << "Compiling and linking an executable" << eom; } else { compiler.mode=compilet::COMPILE_LINK; debug() << "Compiling and linking a library" << eom; } config.ansi_c.mode=configt::ansi_ct::flavourt::GCC; compiler.object_file_extension="o"; if(cmdline.isset('o')) { compiler.output_file_object=cmdline.get_value('o'); compiler.output_file_executable=cmdline.get_value('o'); } else if(cmdline.isset('b')) // as86 only { compiler.output_file_object=cmdline.get_value('b'); compiler.output_file_executable=cmdline.get_value('b'); } else { compiler.output_file_object="a.out"; compiler.output_file_executable="a.out"; } // We now iterate over any input files temp_dirt temp_dir("goto-cc-XXXXXX"); for(goto_cc_cmdlinet::parsed_argvt::iterator arg_it=cmdline.parsed_argv.begin(); arg_it!=cmdline.parsed_argv.end(); arg_it++) { if(!arg_it->is_infile_name) continue; // extract the preprocessed source from the file std::string infile=arg_it->arg=="-"?cmdline.stdin_file:arg_it->arg; std::ifstream is(infile); if(!is.is_open()) { error() << "Failed to open input source " << infile << eom; return 1; } // there could be multiple source files in case GCC's --combine // was used unsigned outputs=0; std::string line; std::ofstream os; std::string dest; const std::string comment2=act_as_as86 ? "::" : "##"; // search for comment2 GOTO-CC // strip comment2 from all subsequent lines while(std::getline(is, line)) { if(line==comment2+" GOTO-CC") { if(outputs>0) { assert(!dest.empty()); compiler.add_input_file(dest); os.close(); } ++outputs; std::string new_name= get_base_name(infile, true)+"_"+ std::to_string(outputs)+".i"; dest=temp_dir(new_name); os.open(dest); if(!os.is_open()) { error() << "Failed to tmp output file " << dest << eom; return 1; } continue; } else if(outputs==0) continue; if(line.size()>2) os << line.substr(2) << '\n'; } if(outputs>0) { assert(!dest.empty()); compiler.add_input_file(dest); } else warning() << "No GOTO-CC section found in " << arg_it->arg << eom; } // Revert to as in case there is no source to compile if(compiler.source_files.empty()) return run_as(); // exit! // do all the rest if(compiler.doit()) return 1; // GCC exit code for all kinds of errors // We can generate hybrid ELF and Mach-O binaries // containing both executable machine code and the goto-binary. if(produce_hybrid_binary) return as_hybrid_binary(); return EX_OK; }
int main(int argc, char *argv[]) { if(argc < 1) { printf("usage: sdump src-directory\n"); } else { printf("Opening directory '%s'.\n", argv[1]); /* * Open our specified directory. */ DIR *dir = opendir(argv[1]); if(dir != NULL) { /* * Make this directory our CWD so our * output files will end up here. */ chdir(argv[1]); /* * Loop over a listing of the directory. */ struct dirent *ent = NULL; while((ent = readdir(dir)) != NULL) { /* * Calculate our necessary array length. */ size_t dn_length = strlen(argv[1]); size_t fn_length = strlen(argv[1]); size_t fp_length = dn_length + fn_length + 1; /* * Build the file full path for use with stat. * Make the array long enough to be null terminated. * Note that snprintf NULL terminates the data for us. */ char full_path[fp_length + 1]; snprintf(full_path, fp_length, "%s%s%s", argv[1], DIR_STR, ent->d_name); /* * Get the status of the file. */ struct stat file_stat; stat(full_path, &file_stat); /* * Check the mode member of the file status struct. * This tells us what type of file the file is. * Skip all directories in the current directory we are reading. */ if(!S_ISDIR(file_stat.st_mode)) { /* * The strtok call in get_shader_type * in-place substitues '.' with '\0' so * we should copy that string so we do not * modify the stat struct data. */ char tokenized_name[64]; snprintf(tokenized_name, 64, "%s", ent->d_name); unsigned int shader_type = get_shader_type(tokenized_name); /* * Ensure we only read shader files. */ if(shader_type != NOT_SHADER) { printf("Reading shader '%s'.\n", full_path); char base_name[64]; snprintf(base_name, 64, "%s", ent->d_name); get_base_name(base_name); if(base_name != NULL) { char file_name[64]; snprintf(file_name, 64, "%s%s.h", base_name, SHADER_NAMES_LOWER[shader_type]); /* * Write out our compiled shader to a header. */ FILE *header_fp = fopen(file_name, "wb"); if(header_fp != NULL) { char obj_name[64]; upper(base_name, obj_name); time_t raw_time; time(&raw_time); struct tm *tm_ptr = localtime(&raw_time); char time_str[64]; strftime(time_str, 64, "%c", tm_ptr); const char *const shader_type_name = SHADER_NAMES_UPPER[shader_type]; fprintf(header_fp, HEADER_FMT_TOP, obj_name, shader_type_name, obj_name, shader_type_name, time_str, obj_name, shader_type_name); dump_shader(full_path, header_fp); fprintf(header_fp, HEADER_FMT_BOT); fclose(header_fp); } free(base_name); } } } } } else { perror("Could not open directory"); } } return 0; }
void ansi_c_languaget::modules_provided(std::set<std::string> &modules) { modules.insert(get_base_name(parse_path, true)); }
int main(int argc, const char **argv) #endif { #ifdef _MSC_VER const char **argv=narrow_argv(argc, argv_wide); #endif if(argv==nullptr || argc<1) { std::cerr << "failed to determine base name\n"; return 1; } #ifdef _MSC_VER // we do 'to_lower_string' because of Windows std::string base_name= to_lower_string(get_base_name(argv[0], true)); #else std::string base_name=get_base_name(argv[0], false); #endif if(base_name=="goto-link" || base_name=="link" || base_name=="goto-cl" || base_name=="cl") { // this is the Visual Studio personality ms_cl_cmdlinet cmdline; cmdline.parse_env(); ms_cl_modet ms_cl_mode(cmdline, base_name); return ms_cl_mode.main(argc, argv); } else if(base_name=="goto-cw" || base_name=="goto-cw-link") { // this is the CodeWarrior personality, // but we use the gcc command line interface gcc_cmdlinet cmdline; cw_modet cw_mode(cmdline, base_name); return cw_mode.main(argc, argv); } else if(base_name=="goto-armcc" || base_name=="goto-armlink") { // this is the armcc personality armcc_cmdlinet cmdline; armcc_modet armcc_mode(cmdline, base_name); return armcc_mode.main(argc, argv); } // handle GCC names like x86_64-apple-darwin14-llvm-gcc-4.2 // via x86_64-apple-darwin14-llvm-goto-gcc-4.2 else if(base_name=="goto-clang" || base_name.find("goto-gcc")!=std::string::npos) { // this produces ELF/Mach-O "hybrid binaries", // with a GCC-style command-line interface, // but also disables CPROVER language extensions gcc_cmdlinet cmdline; gcc_modet gcc_mode(cmdline, base_name, true); return gcc_mode.main(argc, argv); } else if(base_name.find("goto-ld")!=std::string::npos) { // this simulates "ld" for linking ld_cmdlinet cmdline; gcc_modet gcc_mode(cmdline, base_name, true); return gcc_mode.main(argc, argv); } else if(base_name.find("goto-bcc")!=std::string::npos) { // this simulates Bruce's C Compiler bcc_cmdlinet cmdline; // bcc does not build ELF objects -- hybrid mode is used // with -S only gcc_modet gcc_mode(cmdline, base_name, true); return gcc_mode.main(argc, argv); } else if(base_name.find("goto-as86")!=std::string::npos) { // assembler used by Bruce's C Compiler as86_cmdlinet cmdline; // as86 does not build ELF objects, no hybrid binaries as_modet as_mode(cmdline, base_name, false); return as_mode.main(argc, argv); } else if(base_name.find("goto-as")!=std::string::npos) { // GNU assembler as_cmdlinet cmdline; as_modet as_mode(cmdline, base_name, true); return as_mode.main(argc, argv); } else { // the default personality is GCC-style gcc_cmdlinet cmdline; gcc_modet gcc_mode(cmdline, base_name, false); return gcc_mode.main(argc, argv); } }
bool ms_cl_modet::doit() { if(cmdline.isset('?') || cmdline.isset("help")) { help(); return false; } unsigned int verbosity=1; compilet compiler(cmdline); #if 0 bool act_as_ld= has_prefix(base_name, "link") || has_prefix(base_name, "goto-link"); #endif if(cmdline.isset("verbosity")) verbosity=unsafe_string2unsigned(cmdline.get_value("verbosity")); compiler.ui_message_handler.set_verbosity(verbosity); ui_message_handler.set_verbosity(verbosity); debug() << "Visual Studio mode" << eom; // get configuration config.set(cmdline); config.ansi_c.mode=configt::ansi_ct::flavourt::MODE_VISUAL_STUDIO_C_CPP; compiler.object_file_extension="obj"; // determine actions to be undertaken if(cmdline.isset('E') || cmdline.isset('P')) compiler.mode=compilet::PREPROCESS_ONLY; else if(cmdline.isset('c')) compiler.mode=compilet::COMPILE_ONLY; else compiler.mode=compilet::COMPILE_LINK_EXECUTABLE; compiler.echo_file_name=true; if(cmdline.isset("Fo")) { compiler.output_file_object=cmdline.get_value("Fo"); // this could be a directory if(is_directory(compiler.output_file_object)) { if(cmdline.args.size()>=1) compiler.output_file_object+=get_base_name(cmdline.args[0])+".obj"; } } if(cmdline.isset("Fe")) { compiler.output_file_executable=cmdline.get_value("Fe"); // this could be a directory if(is_directory(compiler.output_file_executable)) { if(cmdline.args.size()>=1) compiler.output_file_executable+=get_base_name(cmdline.args[0])+".exe"; } } else { // We need at least one argument. // CL uses the first file name it gets! if(cmdline.args.size()>=1) compiler.output_file_executable=get_base_name(cmdline.args[0])+".exe"; } if(cmdline.isset('J')) config.ansi_c.char_is_unsigned=true; if(verbosity>8) { std::list<std::string>::iterator it; std::cout << "Defines:\n"; for(it=config.ansi_c.defines.begin(); it!=config.ansi_c.defines.end(); it++) { std::cout << " " << (*it) << std::endl; } std::cout << "Undefines:\n"; for(it=config.ansi_c.undefines.begin(); it!=config.ansi_c.undefines.end(); it++) { std::cout << " " << (*it) << std::endl; } std::cout << "Preprocessor Options:\n"; for(it=config.ansi_c.preprocessor_options.begin(); it!=config.ansi_c.preprocessor_options.end(); it++) { std::cout << " " << (*it) << std::endl; } std::cout << "Include Paths:\n"; for(it=config.ansi_c.include_paths.begin(); it!=config.ansi_c.include_paths.end(); it++) { std::cout << " " << (*it) << std::endl; } std::cout << "Library Paths:\n"; for(it=compiler.library_paths.begin(); it!=compiler.library_paths.end(); it++) { std::cout << " " << (*it) << std::endl; } std::cout << "Output file (object): " << compiler.output_file_object << std::endl; std::cout << "Output file (executable): " << compiler.output_file_executable << std::endl; } // Parse input program, convert to goto program, write output return compiler.doit(); }
int read_macro(char *base_base, char *nom, int px, int py, int relatif, int mode_inclusion, int *selected_plane, struct hsearch_data *hash_table) { int i; int nbre_groupe_macro, nbre_gpes_inclus, nbre_liaison_macro; static char ligne[TAILLE_CHAINE]; char base_nom[SIZE_NO_NAME]; char base_nom_complet[SIZE_NO_NAME]; type_groupe *groupe_local, *debut_macro; type_liaison * liaison; FILE *f1; char macro_script_path[PATH_MAX]; int reverse; int mx, my; float zoom; int no_macro_used; int clipboard = 0; nbre_groupe_macro = 0; memcpy(base_nom, nom, (strlen(nom) + 1) * sizeof(char)); get_base_name(base_nom); if (strcmp(base_nom, "copy_buffer") == 0) { clipboard = 1; snprintf(macro_script_path, PATH_MAX, "%s", nom); } else { snprintf(macro_script_path, PATH_MAX, "%s/%s", sc->directory, nom); } f1 = fopen(macro_script_path, "r"); if (f1 == NULL) PRINT_WARNING("\n Error while opening the macro script file %s \n", macro_script_path); no_macro_used = sc->nbre_macro_lues; *selected_plane = (100 + sc->nbre_macro_lues * 7); if (1/*mode_inclusion==0*/) { while (plane_used(*selected_plane) == 1) { no_macro_used++; (*selected_plane) = (100 + no_macro_used * 7); } } if (clipboard) { memcpy(base_nom, "c", (strlen("c") + 1) * sizeof(char)); } if (base_base == NULL) sprintf(base_nom_complet, "%s[%d]", base_nom, no_macro_used); else memcpy(base_nom_complet, base_base, (strlen(base_base) + 1) * sizeof(char)); groupe_local = sc->fin_groupe; sc->first_comment_group = (type_noeud_comment *) read_line_with_comment(f1, sc->first_comment_group, ligne); sscanf(ligne, "nombre de groupes = %d\n", &nbre_groupe_macro); if (nbre_groupe_macro == 0) { printf("ATTENTION no group in this script: ABORT reading !!!\n"); return 0; /* aucun groupe inclus*/ } mx = my = 0; /* centre de gravite des groupes lus */ debut_macro = NULL; nbre_gpes_inclus = 0; for (i = 0; i < nbre_groupe_macro; i++) { groupe_local = (type_groupe *) creer_groupeb(groupe_local); if (sc->deb_groupe == NULL) sc->deb_groupe = groupe_local; /* c'est le 1er groupe lu */ sc->nbre_neurone += read_one_group_leto(f1, groupe_local, base_nom_complet, hash_table, NULL); if (debut_macro == NULL) debut_macro = groupe_local; sc->fin_groupe = groupe_local; /* gestion de la lecture d'un sous reseau, PB ICI ............. */ if (groupe_local->type == No_Sub_Network) { if (groupe_local->reverse > 0) reverse = 1; else reverse = -1; groupe_local->reverse = reverse * (100 + sc->nbre_macro_lues * 7); /* plan >100 pour tout bouger ensemble */ nbre_gpes_inclus = nbre_gpes_inclus + read_macro(groupe_local->no_name, groupe_local->nom, groupe_local->posx, groupe_local->posy, 1, 1, selected_plane, hash_table); } groupe_local->deja_active = mode_inclusion; /* c'est un groupe insere (a ne pas resauvegarder) */ mx = mx + groupe_local->posx; my = my + groupe_local->posy; if (relatif == 0) { groupe_local->posx = groupe_local->posx + 50; groupe_local->posy = groupe_local->posy + 50; } groupe_local->p_posx += 50; groupe_local->p_posy += 50; if (groupe_local->reverse > 0) reverse = 1; else reverse = -1; groupe_local->reverse = reverse * (*selected_plane); /* plan >100 pour tout bouger ensemble */ } /*sc->fin_groupe = groupe_local;*/ if (relatif == 1) { if (mode_inclusion == 1) zoom = 0.1; else zoom = 0.75; mx = mx / nbre_groupe_macro; my = my / nbre_groupe_macro; groupe_local = debut_macro; for (i = 0; i < nbre_groupe_macro; i++) /* tres laid PG !!! */ { groupe_local->posx = 2 + px + (int) (((float) (groupe_local->posx - mx)) * zoom); groupe_local->posy = 2 + py + (int) (((float) (groupe_local->posy - my)) * zoom); groupe_local = groupe_local->s; } } sc->first_comment_link = (type_noeud_comment *) read_line_with_comment(f1, sc->first_comment_link, ligne); sscanf(ligne, "nombre de liaisons = %d\n", &nbre_liaison_macro); liaison = sc->fin_liaison; for (i = sc->nbre_liaison; i < sc->nbre_liaison + nbre_liaison_macro; i++) { if (sc->deb_liaison == NULL) { liaison = sc->deb_liaison = sc->fin_liaison = (type_liaison *) creer_liaison(NULL); } else liaison = creer_liaison(liaison); read_one_link(f1, liaison, base_nom_complet, hash_table); liaison->deja_active = mode_inclusion; /* liaison->depart = liaison->depart + sc->nbre_groupe; *//* offset to change the connected groups (inutile maintenant)*/ /* liaison->arrivee = liaison->arrivee + sc->nbre_groupe; *//* c'est le nom compose qui evite le pb */ #ifndef AVEUGLE initialise_coudes_liaison(liaison); /*initialise les coudes de la liaison - par defaut on ne reprend pas le graphisme */ #endif } sc->fin_liaison = liaison; /* cette solution n'est valable que si le lien micro macro est toujours cree en premier: faux en ce moment ex: kohonen ce lien n'existe pas */ /* detruit_liaison(liaison1); *//* only a single link between micro and macro neuron */ sc->nbre_liaison = sc->nbre_liaison + nbre_liaison_macro; sc->nbre_groupe = nbre_groupe_macro + sc->nbre_groupe; fclose(f1); if (no_macro_used > sc->nbre_macro_lues) sc->nbre_macro_lues = no_macro_used + 1; else sc->nbre_macro_lues = sc->nbre_macro_lues + 1; /*#ifndef AVEUGLE if (sc->premiere_lecture == 0 && onglet_leto->window != NULL) regenerer_test(sc->onglet_leto); #endif*/ return (nbre_groupe_macro + nbre_gpes_inclus); }