status_t rdef_compile(const char *outputFile) { clear_error(); if (outputFile == NULL || outputFile[0] == '\0') { rdef_err = B_BAD_VALUE; return rdef_err; } rsrc_file = outputFile; rdef_err = open_output_file(); if (rdef_err != B_OK) return rdef_err; for (ptr_iter_t i = input_files.begin(); (i != input_files.end()) && (rdef_err == B_OK); ++i) { char *path = (char *)*i; AddIncludeDir add(path); compile_file(path); } close_output_file(); return rdef_err; }
ZEND_API zend_op_array *dtrace_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC) { zend_op_array *res; DTRACE_COMPILE_FILE_ENTRY(file_handle->opened_path, (char *)file_handle->filename); res = compile_file(file_handle, type TSRMLS_CC); DTRACE_COMPILE_FILE_RETURN(file_handle->opened_path, (char *)file_handle->filename); return res; }
PhpFile *FileRepository::parseFile(const std::string &name, const FileInfo &fileInfo) { MD5 md5 = MD5(fileInfo.m_unitMd5.c_str()); VM::Unit* unit = compile_file(fileInfo.m_inputString->data(), fileInfo.m_inputString->size(), md5, name.c_str()); PhpFile *p = new PhpFile(name, fileInfo.m_srcRoot, fileInfo.m_relPath, fileInfo.m_md5, unit); return p; }
CachedUnit createUnitFromString(const char* path, const String& contents) { auto const md5 = MD5 { mangleUnitMd5(string_md5(contents.data(), contents.size())).c_str() }; // Try the repo; if it's not already there, invoke the compiler. if (auto const unit = Repo::get().loadUnit(path, md5)) { return CachedUnit { unit, RDS::allocBit() }; } auto const unit = compile_file(contents.data(), contents.size(), md5, path); return CachedUnit { unit, RDS::allocBit() }; }
int main(int argc,char** argv) { //testvas(); gArgc = argc; gArgv = argv; if(argc > 1) f = (frameKernel_t)compile_file(argv[1]); else f = (frameKernel_t)compile_str(); ProcessVideo(); release_function((void*&)f); if(gVideoIn) free(gVideoIn); if(gVideoOut) free(gVideoOut); }
RepoWrapper::RepoWrapper(const char* repoSchema, const std::string& configFile) { if (setenv("HHVM_RUNTIME_REPO_SCHEMA", repoSchema, 1 /* overwrite */)) { fprintf(stderr, "Could not set repo schema"); exit(EXIT_FAILURE); } printf("# Config file: %s\n", configFile.c_str()); printf("# Repo schema: %s\n", repoSchemaId().begin()); register_process_init(); initialize_repo(); hphp_thread_init(); g_context.getCheck(); IniSetting::Map ini = IniSetting::Map::object; Hdf config; if (!configFile.empty()) { Config::ParseConfigFile(configFile, ini, config); // Disable logging to suppress harmless errors about setrlimit. config["Log"]["Level"] = "None"; } RuntimeOption::Load(ini, config); RuntimeOption::RepoCommit = false; compile_file(nullptr, 0, MD5(), nullptr); repo = &Repo::get(); RuntimeOption::AlwaysUseRelativePath = false; RuntimeOption::SafeFileAccess = false; RuntimeOption::EvalAllowHhas = true; Option::WholeProgram = false; LitstrTable::init(); LitstrTable::get().setWriting(); RuntimeOption::RepoAuthoritative = true; repo->loadGlobalData(true /* allowFailure */); std::string hhasLib; auto const phpLib = get_systemlib(&hhasLib); always_assert(!hhasLib.empty() && !phpLib.empty()); auto phpUnit = compile_string(phpLib.c_str(), phpLib.size(), "systemlib.php"); addUnit(phpUnit); auto hhasUnit = compile_string(hhasLib.c_str(), hhasLib.size(), "systemlib.hhas"); addUnit(hhasUnit); SystemLib::s_inited = true; LitstrTable::get().setReading(); }
int main(int argc, char *argv[]) { if (argc >= 2) { argv++; while (*argv) compile_file(*(argv++)); } else { my_putstr("Usage: "); my_putstr(argv[0]); my_putstr(" file_name[.s] ....\n"); } return (0); }
int main(int argc, char **argv) { int i; MEMORY_init(); COMMON_init(); TRY { get_arguments(argc, argv); COMPILE_init(); // Remove information files if we are compiling everything if (main_compile_all) { if (main_verbose) puts("Removing .info and .list files"); FILE_chdir(FILE_get_dir(COMP_project)); FILE_unlink(".info"); FILE_unlink(".list"); } init_files(FILE_get_dir(COMP_project)); for (i = 0; i < ARRAY_count(_files); i++) compile_file(_files[i]); exit_files(); COMPILE_exit(); puts("OK"); } CATCH { fflush(NULL); COMPILE_print(MSG_ERROR, -1, NULL); ERROR_print(); exit(1); } END_TRY return 0; }
void compile_file_wrapper( const char* path ) { try { if (compile_file( path )) ++summary.CompiledScripts; else ++summary.UpToDateScripts; } catch( std::exception& ) { ++summary.CompiledScripts; ++summary.ScriptsWithCompileErrors; if (!keep_building) throw; } }
int main(int argc, char** argv) { args = 0; unsigned int i = 1; char outputfn[128]; char inputfn[128]; char soloarg[128]; memset(outputfn, 0, 128); memset(inputfn, 0, 128); memset(soloarg, 0, 128); for (; i < argc; i++) { if (!strncmp(argv[i], "-noopt", 6)) { args |= MASK_NOOPT; } else if (!strncmp(argv[i], "-c", 2)) { args |= MASK_COMPILE; memcpy(inputfn, argv[++i], 128); } else if (!strncmp(argv[i], "-r", 2)) { args |= MASK_RUN; memcpy(inputfn, argv[++i], 128); } else if (!strncmp(argv[i], "-o", 2)) { args |= MASK_OUTPUT; memcpy(outputfn, argv[++i], 128); } else if (!strncmp(argv[i], "-d", 2)) { args |= MASK_DUMP; } else { memcpy(soloarg, argv[i], 128); } } if (args & MASK_COMPILE) { compile_file(inputfn, (args & MASK_OUTPUT) ? outputfn : "a.spyb"); } else if (args & MASK_RUN) { run_file(inputfn); } else { do_file(soloarg); } return 0; }
CachedUnit createUnitFromString(const char* path, const String& contents, Unit** releaseUnit, OptLog& ent, const Native::FuncTable& nativeFuncs, const RepoOptions& options, FileLoadFlags& flags) { auto const sha1 = SHA1{mangleUnitSha1(string_sha1(contents.slice()), options)}; // Try the repo; if it's not already there, invoke the compiler. if (auto unit = Repo::get().loadUnit(path, sha1, nativeFuncs)) { flags = FileLoadFlags::kHitDisk; return CachedUnit { unit.release(), rds::allocBit() }; } LogTimer compileTimer("compile_ms", ent); rqtrace::EventGuard trace{"COMPILE_UNIT"}; trace.annotate("file_size", folly::to<std::string>(contents.size())); flags = FileLoadFlags::kCompiled; auto const unit = compile_file(contents.data(), contents.size(), sha1, path, nativeFuncs, options, releaseUnit); return CachedUnit { unit, rds::allocBit() }; }
void parallel_compile(vector<string> &files) { unsigned compiled_scripts=0; unsigned uptodate_scripts=0; unsigned error_scripts=0; bool omp_keep_building=true; #pragma omp parallel for reduction(+ : compiled_scripts, uptodate_scripts, error_scripts) shared(omp_keep_building) schedule(dynamic) for (int i=0;i<(int)files.size();++i) { #pragma omp flush(omp_keep_building) if (omp_keep_building) { try { if (compile_file( files[i].c_str() )) ++compiled_scripts; else ++uptodate_scripts; } catch( std::exception& ) { ++compiled_scripts; ++error_scripts; if (!keep_building) { #pragma omp critical(building_break) omp_keep_building=false; } } } } summary.CompiledScripts = compiled_scripts; summary.UpToDateScripts = uptodate_scripts; summary.ScriptsWithCompileErrors = error_scripts; }
void recurse_compile_inc( string basedir, vector<string>* files ) { for( DirList dl( basedir.c_str() ); !dl.at_end(); dl.next() ) { string name = dl.name(), ext; if (name[0] == '.') continue; string::size_type pos = name.rfind("."); if (pos != string::npos) ext = name.substr(pos); if (pos != string::npos && !ext.compare(".inc")) { if (files==NULL) compile_file( (basedir + name).c_str() ); else files->push_back( (basedir + name)); } else { recurse_compile( basedir + name + "/", files ); } } }
int blue_main(int argc, char **argv){ int arg_index; int mode=0; char * filename = NULL; char * output_filename = NULL; /* Not enough arguments */ if (argc < 2 ) usage(); Global = malloc(sizeof(struct Global)); if ( ! Global){ printf("Out of Memory\n"); exit(1); } Global->dbg_status = 0; /* handle arguments to blue */ for (arg_index=1; arg_index<argc ; arg_index++){ if (argv[arg_index][0] == '-'){ /* disassemble and quit*/ if ( strcmp(argv[arg_index], "-d")==0 ) mode = 1; else if ( strcmp(argv[arg_index], "-c")==0 ) mode = 2; else if ( strcmp(argv[arg_index], "-g")==0 ) Global->dbg_status = 1; else if ( strcmp(argv[arg_index], "-o")==0 ){ arg_index++; output_filename = argv[arg_index]; } else if ( strcmp(argv[arg_index], "-s")==0 ){ mode = 3 ; } else if ( strcmp(argv[arg_index], "-a")==0 ){ mode = 4 ; } if (argc <3) return 0; }else{ filename = argv[arg_index]; break; } } /* Initialization routines */ global_init(); link_setThreadState(0); // turn multi-threading off until needed if (mode==1){ /* DISASSEMBLE */ Link module = create_module_filename(filename); string_t code = disassemble(module->value.module->bytecode); string_fprint(code , stdout); exit(0); } else if (mode == 2){ /* COMPILE */ Link module = create_module_filename(filename); module_save( module, output_filename ? output_filename : "blue.blx"); exit(0); }else if (mode == 3){ /* COMPILE TO ASSEMBLY CODE */ char * acode = compile_file( filename); if ( memcmp( acode, "ERR:",4) ==0 ){ printf( acode+4); exit(0); } if (output_filename){ FILE * fp = fopen( output_filename,"wb"); fprintf(fp,acode); fclose(fp); }else{ printf(acode); } free(acode); exit(0); }else if (mode == 4){ /* ASSEMBLE THS ASSEMBLY CODE TO BYTECODE */ char * acode = file_load(filename); if ( memcmp( acode, "ERR:",4) ==0 ){ printf( acode+4); exit(0); } Bytes bytes = assemble( acode ); if (output_filename){ bytes_save(bytes, output_filename); }else{ bytes_save(bytes, "out.blx"); } free(acode); exit(0); } /* Add arguments from call to this application */ Link Arg = array_new(argc-arg_index); Link * Argv = array_getArray(Arg); Link a = NULL; int c = 0; for(c=0; c <argc-arg_index; c++){ a = create_string_str( string_new((argv+arg_index)[c]) ); Argv[c] =a; } /* creates and runs the module */ Link main_ret = module_new(filename, Arg); link_free(Arg); if (main_ret){ showBacktrace(main_ret); link_free(main_ret); } fflush(stdout); fflush(stderr); exit(0); return 0; }
void recurse_compile( string basedir, vector<string>* files ) { long s_compiled, s_uptodate, s_errors; clock_t start, finish; if ( !IsDirectory( basedir.c_str() ) ) return; s_compiled = s_uptodate = s_errors = 0; start = clock(); for( DirList dl( basedir.c_str() ); !dl.at_end(); dl.next() ) { string name = dl.name(), ext; if (name[0] == '.') continue; string::size_type pos = name.rfind("."); if (pos != string::npos) ext = name.substr(pos); try { if ( pos != string::npos && (!ext.compare(".src") || !ext.compare(".hsr") || (compilercfg.CompileAspPages && !ext.compare(".asp"))) ) { s_compiled++; if (files==NULL) { if (compile_file( (basedir + name).c_str() )) { ++summary.CompiledScripts; } else { ++s_uptodate; ++summary.UpToDateScripts; } } else files->push_back((basedir + name)); } else { recurse_compile( basedir + name + "/", files ); } } catch( std::exception& ) { ++summary.CompiledScripts; ++summary.ScriptsWithCompileErrors; if (!keep_building) throw; s_errors++; } } if (files==NULL) return; finish = clock(); if ( (!quiet || timing_quiet_override) && show_timing_details && s_compiled > 0 && files==NULL) { cout << "Compiled " << s_compiled << " script" << (s_compiled==1?"":"s") << " in " << basedir << " in " << (long)((finish-start)/CLOCKS_PER_SEC) << " second(s)" << endl; if ( s_uptodate > 0 ) cout << " " << s_uptodate << " script" << (s_uptodate==1?" was":"s were") << " already up-to-date." << endl; if ( s_errors > 0 ) cout << " " << s_errors << " script" << (s_errors==1?"":"s") << " had errors." << endl; } }
static int compile_fs () { int err; int fd = -1; while (1) { int fd = open ("romfs.bin", O_WRONLY | O_CREAT | O_TRUNC); if (fd < 0) { err = errno; break; } /* Write super block first */ super_disk_t super; memset (&super, 0xFF, sizeof (super_disk_t)); strcpy (super.magic, SUPER_MAGIC); super.ssize = sizeof (super_disk_t); super.isize = sizeof (inode_disk_t); super.icount = _inodes.count; int count = write (fd, &super, sizeof (super_disk_t)); if (count != sizeof (super_disk_t)) { err = errno; break; } /* Skip the table of inodes */ off_t offset = _inodes.count * sizeof (inode_disk_t); offset = lseek (fd, offset, SEEK_CUR); if (offset < 0) { err = errno; break; } /* Compile the inodes, directories and files */ inode_build_t * inode_build = (inode_build_t *) _inodes.node.next; while (inode_build != (inode_build_t *) &_inodes.node) { inode_build->offset = offset; if (inode_build->flags & INODE_DIR) { printf ("Dir: %s\n", inode_build->path); err = compile_dir (fd, inode_build); } else if (inode_build->flags & INODE_FILE) { printf ("File: %s\n", inode_build->path); err = compile_file (fd, inode_build); } if (err) break; offset += inode_build->size; inode_build = (inode_build_t *) inode_build->node.next; } /* Now write table of inodes */ offset = sizeof (super_disk_t); offset = lseek (fd, offset, SEEK_SET); if (offset < 0) { err = errno; break; } inode_build = (inode_build_t *) _inodes.node.next; while (inode_build != (inode_build_t *) &_inodes.node) { inode_disk_t inode_disk; memset (&inode_disk, 0xFF, sizeof (inode_disk_t)); inode_disk.flags = inode_build->flags; inode_disk.offset = inode_build->offset; inode_disk.size = inode_build->size; int count = write (fd, &inode_disk, sizeof (inode_disk_t)); if (count != sizeof (inode_disk_t)) { err = errno; break; } inode_build = (inode_build_t *) inode_build->node.next; } break; } if (fd >= 0) close (fd); return err; }
static void do_file(const char* inputfn) { const char* temp = ".tmp_spyre_bytecode.spyb"; compile_file(inputfn, temp); run_file(temp); remove(temp); }
int main(int argc, char** argv) { char *outfile = 0; int from_stdin = 0; struct sass_options options; options.output_style = SASS_STYLE_NESTED; options.source_comments = 0; options.image_path = "images"; options.include_paths = ""; int c, i; int long_index = 0; static struct option long_options[] = { { "stdin", no_argument, 0, 's' }, { "load-path", required_argument, 0, 'I' }, { "style", required_argument, 0, 't' }, { "line-numbers", no_argument, 0, 'l' }, { "line-comments", no_argument, 0, 'l' }, { "sourcemap", no_argument, 0, 'm' }, { "help", no_argument, 0, 'h' } }; while ((c = getopt_long(argc, argv, "hslmt:I:", long_options, &long_index)) != -1) { switch (c) { case 's': from_stdin = 1; break; case 'I': options.include_paths = optarg; break; case 't': for(i = 0; i < NUM_STYLE_OPTION_STRINGS; ++i) { if(strcmp(optarg, style_option_strings[i].style_string) == 0) { options.output_style = style_option_strings[i].output_style; break; } } if(i == NUM_STYLE_OPTION_STRINGS) { fprintf(stderr, "Invalid argument for -t flag: '%s'. Allowed arguments are:", optarg); for(i = 0; i < NUM_STYLE_OPTION_STRINGS; ++i) { fprintf(stderr, " %s", style_option_strings[i].style_string); } fprintf(stderr, "\n"); invalid_usage(argv[0]); } break; case 'l': options.source_comments = SASS_SOURCE_COMMENTS_DEFAULT; break; case 'm': options.source_comments = SASS_SOURCE_COMMENTS_MAP; break; case 'h': print_usage(argv[0]); return 0; case '?': /* Unrecognized flag or missing an expected value */ /* getopt should produce it's own error message for this case */ invalid_usage(argv[0]); default: fprintf(stderr, "Unknown error while processing arguments\n"); return 2; } } if(optind < argc - 2) { fprintf(stderr, "Error: Too many arguments.\n"); invalid_usage(argv[0]); } if(optind < argc && strcmp(argv[optind], "-") != 0 && !from_stdin) { if (optind + 1 < argc) { outfile = argv[optind + 1]; } return compile_file(options, argv[optind], outfile); } else { if (optind < argc) { outfile = argv[optind]; } return compile_stdin(options, outfile); } }
bool Compiler::compile_file(const char* filepath) { printf("Compiler::compile_file [%s]\n", filepath); // Compiler only accept absolute file path, for debug reason it's more relevant to know the absolute path than the relative one if (!g_is_absolute_path(filepath)) { fprintf(stderr, "Compiler::compile_file error: filepath must be a absolute path\n"); return false; } // [Windows] "rb" is need to avoid some translation/encoding platform dependant stuff // \r\n are handled in the lexer FILE* src_file = fopen(filepath, "rb"); if (!src_file) { fprintf(stderr, "Compiler::compileFile can't open '%s'\n", filepath); return false; } fseek(src_file, 0, SEEK_END); long fsize = ftell(src_file); fseek(src_file, 0, SEEK_SET); if (!fsize) { fclose(src_file); fprintf(stdout, "Warning: Compiler::compileFile empty file '%s'\n", filepath); return true; } char *content = (char*)malloc(fsize + 1); fread(content, fsize, 1, src_file); fclose(src_file); content[fsize] = 0; if (!content) { fprintf(stderr, "Compiler::compileFile can't read file content'%s'\n", filepath); return false; } { // use a non null terminated string const utf8_string& str_with_len = manager.register_path_in_pool(filepath); std::cout << str_with_len << std::endl; // @TODO check if already parsed and remove/replace std::string const std::string s(filepath); //auto found = ctx.compiledFilePaths.find(s); //if (found != ctx.compiledFilePaths.end()) { // printf("Compiler log, file has already been '%s' compiled!", filepath); // return true; //} // Initialize parser Parser parser_(manager, content, std::strlen(content), str_with_len); TopLevel* top_level = 0; top_level = parser_.parse_top_level(); // Parse top level if (!top_level) { return false; } else { top_level->set_path(&str_with_len); manager.register_parsed_file(&str_with_len); } // register file as compiled //ctx.compiledFilePaths.insert(std::string(filepath)); //ctx.topLevels.push_back(&top_level); if (!top_level->import_items.empty()) { // @TODO use a names const expr value char fullpath[4096]; for (DirectiveImport* import: top_level->import_items) { if (!compile_file(fullpath)) { fprintf(stderr, "Compiler Error : Can't compile import file:'%.*s'!\n", import->absolute_path.size(), import->absolute_path.data()); return false; } } } } free(content); return true; } // compile_file
/* Entry point of cc1/c++. Decode command args, then call compile_file. Exit code is 35 if can't open files, 34 if fatal error, 33 if had nonfatal errors, else success. */ int main(int argc, char **argv) { register int i; dd_list files, preludes; dd_list_pos cur; int version_flag = 0; char *p; char *config_file = NULL; #ifdef TIMER_USERTIME reset_timer(&total_time); #endif start_timer(&total_time); region_init(); parse_region = newregion(); in_prelude = FALSE; num_hotspots = 0; parsed_files = dd_new_list(parse_region); copy_argc = 0; copy_argv = xmalloc((argc + 1) * sizeof(*copy_argv)); files = dd_new_list(parse_region); preludes = dd_new_list(parse_region); p = argv[0] + strlen (argv[0]); while (p != argv[0] && p[-1] != '/' #ifdef DIR_SEPARATOR && p[-1] != DIR_SEPARATOR #endif ) --p; progname = p; #ifdef SIGPIPE signal (SIGPIPE, pipe_closed); #endif copy_argv[0] = argv[0]; copy_argc = 1; for (i = 1; i < argc; i++) { int j; bool copy_arg = TRUE; /* If this is a language-specific option, decode it in a language-specific way. */ for (j = 0; lang_options[j] != 0; j++) if (!strncmp (argv[i], lang_options[j], strlen (lang_options[j]))) break; if (lang_options[j] != 0) /* If the option is valid for *some* language, treat it as valid even if this language doesn't understand it. */ c_decode_option(argv[i]); else if (argv[i][0] == '-' && argv[i][1] != 0) { register char *str = argv[i] + 1; if (str[0] == 'Y') str++; if (!strcmp (str, "dumpbase")) copy_argv[copy_argc++] = argv[i++]; else if (str[0] == 'f') { register char *p = &str[1]; int found = 0; /* Some kind of -f option. P's value is the option sans `-f'. Search for it in the table of options. */ for (j = 0; !found && j < sizeof (f_options) / sizeof (f_options[0]); j++) { if (!strcmp (p, f_options[j].string)) { *f_options[j].variable = f_options[j].on_value; /* A goto here would be cleaner, but breaks the vax pcc. */ found = 1; } if (p[0] == 'n' && p[1] == 'o' && p[2] == '-' && ! strcmp (p+3, f_options[j].string)) { *f_options[j].variable = ! f_options[j].on_value; found = 1; } } } else if (!strcmp (str, "pedantic")) pedantic = 1; else if (!strcmp (str, "pedantic-errors")) flag_pedantic_errors = pedantic = 1; else if (!strcmp (str, "quiet")) quiet_flag = 1; else if (!strcmp (str, "version")) version_flag = 1; else if (!strcmp (str, "w")) inhibit_warnings = 1; else if (!strcmp (str, "W")) { extra_warnings = 1; /* We save the value of warn_uninitialized, since if they put -Wuninitialized on the command line, we need to generate a warning about not using it without also specifying -O. */ if (warn_uninitialized != 1) warn_uninitialized = 2; } else if (str[0] == 'W') { register char *p = &str[1]; int found = 0; /* Some kind of -W option. P's value is the option sans `-W'. Search for it in the table of options. */ for (j = 0; !found && j < sizeof (W_options) / sizeof (W_options[0]); j++) { if (!strcmp (p, W_options[j].string)) { *W_options[j].variable = W_options[j].on_value; /* A goto here would be cleaner, but breaks the vax pcc. */ found = 1; } if (p[0] == 'n' && p[1] == 'o' && p[2] == '-' && ! strcmp (p+3, W_options[j].string)) { *W_options[j].variable = ! W_options[j].on_value; found = 1; } } if (found) ; else if (!strncmp (p, "id-clash-", 9)) { char *endp = p + 9; while (*endp) { if (*endp >= '0' && *endp <= '9') endp++; else { error ("Invalid option `%s'", argv[i]); goto id_clash_lose; } } warn_id_clash = 1; id_clash_len = atoi (str + 10); id_clash_lose: ; } else if (!strncmp (p, "larger-than-", 12)) { char *endp = p + 12; while (*endp) { if (*endp >= '0' && *endp <= '9') endp++; else { error ("Invalid option `%s'", argv[i]); goto larger_than_lose; } } warn_larger_than = 1; larger_than_size = atoi (str + 13); larger_than_lose: ; } } else if (!strcmp (str, "o")) copy_argv[copy_argc++] = argv[i++]; else if (str[0] == 'G') { if (str[1] == '\0') copy_argv[copy_argc++] = argv[i++]; } else if (!strncmp (str, "aux-info", 8)) { if (str[8] == '\0') copy_argv[copy_argc++] = argv[i++]; } else if (!strcmp(str, "config")) { if (i < argc - 1) { i++; config_file = strdup(argv[i]); } else error ("Missing -config file"); } else if (!strcmp(str, "prelude")) { if (i < argc - 1) { i++; dd_add_last(parse_region, preludes, rstrdup(parse_region, argv[i])); } else error("Missing -prelude file"); } else if (!strcmp(str, "hotspots")) { if (i < argc - 1) { i++; num_hotspots = atoi(argv[i]); if (num_hotspots < 0) error("Negative value for -hotspots count"); } else error("Missing -hotspots count"); } else if (!strcmp( str, "program-files")) { if (i < argc - 1) { i++; add_program_files(argv[i], files); } else error("Missing -program-files file"); } } else if (argv[i][0] == '+') ; else { /* Allow wildcards, because PAM won't expand files */ glob_t globbuf; char **cur; if (glob(argv[i], 0, NULL, &globbuf)) { /* glob returned non-zero error status; abort */ fprintf(stderr, "%s: file not found\n", argv[i]); exit(FATAL_EXIT_CODE); } else for (cur = globbuf.gl_pathv; *cur; cur++) { /* Assume anything called prelude.i is a prelude file */ if ( strlen(*cur) >= 9 && !strncmp("prelude.i", *cur + strlen(*cur) - 9, 9)) dd_add_last(parse_region, preludes, rstrdup(parse_region, *cur)); else dd_add_last(parse_region, files, rstrdup(parse_region, *cur)); } copy_arg = FALSE; } if (copy_arg) copy_argv[copy_argc++] = argv[i]; } copy_argv[copy_argc] = NULL; if (flag_casts_preserve && flag_flow_sensitive) { fprintf(stderr, "-fcasts-preserve currently not allowed with " "-fflow_sensitive"); exit(FATAL_EXIT_CODE); } /* Now analyze *all* of the files. First, initialize all appropriate data structures. */ init_types(); cval_init(); init_effects(); init_qtype(); init_quals(); init_qerror(); init_store(); if (config_file) load_config_file_quals(config_file); /* Add const so that we can do -fconst-subtyping no matter what */ if (!const_qual) { begin_po_qual(); const_qual = add_qual("const"); add_level_qual(const_qual, level_ref); set_po_nonprop(); end_po_qual(); } /* Add volatile so we can handle noreturn functions */ if (!volatile_qual) { begin_po_qual(); volatile_qual = add_qual("volatile"); add_level_qual(volatile_qual, level_ref); add_sign_qual(volatile_qual, sign_eq); set_po_nonprop(); end_po_qual(); } /* Add noreturn, for non-returning functions */ if (!noreturn_qual) { begin_po_qual(); noreturn_qual = add_qual("noreturn"); add_level_qual(noreturn_qual, level_value); add_sign_qual(noreturn_qual, sign_eq); set_po_nonprop(); end_po_qual(); } end_define_pos(); /* Allow cqual to run with no qualifiers */ init_pam(); init_analyze(); found_fs_qual = FALSE; /* Force reset, since init_analyze may look up some quals */ /* Now analyze the prelude files */ in_prelude = TRUE; dd_scan(cur, preludes) { char *file; file = DD_GET(char *, cur); fprintf(stderr, "Analyzing prelude %s\n", file); compile_file(file); }
int main(int argc, char** argv) { char *outfile = 0; int from_stdin = 0; bool generate_source_map = false; struct Sass_Options* options = sass_make_options(); sass_option_set_output_style(options, SASS_STYLE_NESTED); sass_option_set_image_path(options, "images"); char *include_paths = NULL; sass_option_set_precision(options, 5); int c, i; int long_index = 0; static struct option long_options[] = { { "stdin", no_argument, 0, 's' }, { "load-path", required_argument, 0, 'I' }, { "style", required_argument, 0, 't' }, { "line-numbers", no_argument, 0, 'l' }, { "line-comments", no_argument, 0, 'l' }, { "sourcemap", no_argument, 0, 'm' }, { "omit-map-comment", no_argument, 0, 'M' }, { "precision", required_argument, 0, 'p' }, { "version", no_argument, 0, 'v' }, { "help", no_argument, 0, 'h' } }; while ((c = getopt_long(argc, argv, "vhslmMt:I:", long_options, &long_index)) != -1) { switch (c) { case 's': from_stdin = 1; break; case 'I': if (!include_paths) { include_paths = strdup(optarg); } else { char *old_paths = include_paths; include_paths = malloc(strlen(old_paths) + 1 + strlen(optarg) + 1); sprintf(include_paths, "%s%c%s", old_paths, PATH_SEP, optarg); free(old_paths); } break; case 't': for(i = 0; i < NUM_STYLE_OPTION_STRINGS; ++i) { if(strcmp(optarg, style_option_strings[i].style_string) == 0) { sass_option_set_output_style(options, style_option_strings[i].output_style); break; } } if(i == NUM_STYLE_OPTION_STRINGS) { fprintf(stderr, "Invalid argument for -t flag: '%s'. Allowed arguments are:", optarg); for(i = 0; i < NUM_STYLE_OPTION_STRINGS; ++i) { fprintf(stderr, " %s", style_option_strings[i].style_string); } fprintf(stderr, "\n"); invalid_usage(argv[0]); } break; case 'l': sass_option_set_source_comments(options, true); break; case 'm': generate_source_map = true; break; case 'M': sass_option_set_omit_source_map_url(options, true); break; case 'p': sass_option_set_precision(options, atoi(optarg)); // TODO: make this more robust if (sass_option_get_precision(options) < 0) sass_option_set_precision(options, 5); break; case 'v': print_version(argv[0]); return 0; case 'h': print_usage(argv[0]); return 0; case '?': /* Unrecognized flag or missing an expected value */ /* getopt should produce it's own error message for this case */ invalid_usage(argv[0]); default: fprintf(stderr, "Unknown error while processing arguments\n"); return 2; } } sass_option_set_include_path(options, include_paths ? include_paths : ""); if(optind < argc - 2) { fprintf(stderr, "Error: Too many arguments.\n"); invalid_usage(argv[0]); } int result; if(optind < argc && strcmp(argv[optind], "-") != 0 && !from_stdin) { if (optind + 1 < argc) { outfile = argv[optind + 1]; } if (generate_source_map && outfile) { const char* extension = ".map"; char* source_map_file = calloc(strlen(outfile) + strlen(extension) + 1, sizeof(char)); strcpy(source_map_file, outfile); strcat(source_map_file, extension); sass_option_set_source_map_file(options, source_map_file); } result = compile_file(options, argv[optind], outfile); } else { if (optind < argc) { outfile = argv[optind]; } result = compile_stdin(options, outfile); } free(include_paths); return result; }
int main(int argc, char** argv) { #ifdef _MSC_VER _set_error_mode(_OUT_TO_STDERR); _set_abort_behavior( 0, _WRITE_ABORT_MSG); #endif #ifdef _WIN32 get_argv_utf8(&argc, &argv); #endif char *outfile = 0; int from_stdin = 0; bool generate_source_map = false; struct Sass_Options* options = sass_make_options(); sass_option_set_output_style(options, SASS_STYLE_NESTED); sass_option_set_precision(options, 5); int c; size_t i; int long_index = 0; static struct option long_options[] = { { "stdin", no_argument, 0, 's' }, { "load-path", required_argument, 0, 'I' }, { "plugin-path", required_argument, 0, 'P' }, { "style", required_argument, 0, 't' }, { "line-numbers", no_argument, 0, 'l' }, { "line-comments", no_argument, 0, 'l' }, { "sourcemap", no_argument, 0, 'm' }, { "omit-map-comment", no_argument, 0, 'M' }, { "precision", required_argument, 0, 'p' }, { "version", no_argument, 0, 'v' }, { "help", no_argument, 0, 'h' }, { NULL, 0, NULL, 0} }; while ((c = getopt_long(argc, argv, "vhslmMp:t:I:P:", long_options, &long_index)) != -1) { switch (c) { case 's': from_stdin = 1; break; case 'I': sass_option_push_include_path(options, strdup(optarg)); break; case 'P': sass_option_push_plugin_path(options, strdup(optarg)); break; case 't': for(i = 0; i < NUM_STYLE_OPTION_STRINGS; ++i) { if(strcmp(optarg, style_option_strings[i].style_string) == 0) { sass_option_set_output_style(options, style_option_strings[i].output_style); break; } } if(i == NUM_STYLE_OPTION_STRINGS) { fprintf(stderr, "Invalid argument for -t flag: '%s'. Allowed arguments are:", optarg); for(i = 0; i < NUM_STYLE_OPTION_STRINGS; ++i) { fprintf(stderr, " %s", style_option_strings[i].style_string); } fprintf(stderr, "\n"); invalid_usage(argv[0]); } break; case 'l': sass_option_set_source_comments(options, true); break; case 'm': generate_source_map = true; break; case 'M': sass_option_set_omit_source_map_url(options, true); break; case 'p': sass_option_set_precision(options, atoi(optarg)); // TODO: make this more robust if (sass_option_get_precision(options) < 0) sass_option_set_precision(options, 5); break; case 'v': print_version(); return 0; case 'h': print_usage(argv[0]); return 0; case '?': /* Unrecognized flag or missing an expected value */ /* getopt should produce it's own error message for this case */ invalid_usage(argv[0]); default: fprintf(stderr, "Unknown error while processing arguments\n"); return 2; } } if(optind < argc - 2) { fprintf(stderr, "Error: Too many arguments.\n"); invalid_usage(argv[0]); } int result; if(optind < argc && strcmp(argv[optind], "-") != 0 && !from_stdin) { if (optind + 1 < argc) { outfile = argv[optind + 1]; } if (generate_source_map && outfile) { const char* extension = ".map"; char* source_map_file = calloc(strlen(outfile) + strlen(extension) + 1, sizeof(char)); strcpy(source_map_file, outfile); strcat(source_map_file, extension); sass_option_set_source_map_file(options, source_map_file); } result = compile_file(options, argv[optind], outfile); } else { if (optind < argc) { outfile = argv[optind]; } result = compile_stdin(options, outfile); } return result; }