bool gs_PDF_EmbedAllFonts (url image, url pdf) { if (DEBUG_CONVERT) debug_convert << "gs_PDF_EmbedAllFonts" << LF; if (!exists (image)) return false; array<string> cmd; cmd << gs_executable (); cmd << string ("-dNOPAUSE"); cmd << string ("-dBATCH"); cmd << string ("-dQUIET"); cmd << string ("-dSAFER"); cmd << string ("-sDEVICE=pdfwrite"); cmd << string ("-dPDFSETTINGS=/prepress"); cmd << string ("-dEmbedAllFonts=true"); cmd << string ("-dCompatibilityLevel=") * pdf_version (); cmd << string ("-sOutputFile=") * concretize (pdf); cmd << concretize (image); // cout << cmd << LF; array<int> out; out << 1; out << 2; array<string> ret= evaluate_system (cmd, array<int> (), array<string> (), out); // cout << "ret= " << ret << LF; if (ret [0] != "0" || ret[2] != "") { convert_warning << "cannot embed all fonts for file " << image << LF; convert_warning << ret[1] << LF; convert_warning << ret[2] << LF; return false; } return true; }
bool is_up_to_date (url dir) { string name_dir= concretize (dir); if (cache_valid->contains (name_dir)) return cache_valid [name_dir]; int l= last_modified (dir, false); if (is_cached ("validate_cache.scm", name_dir)) { int r= as_int (cache_get ("validate_cache.scm", name_dir) -> label); if (l == r) { cache_valid (name_dir)= true; return true; } //cout << name_dir << " no longer up to date " << r << " -> " << l << "\n"; } //else cout << name_dir << " not up to date " << l << "\n"; cache_set ("validate_cache.scm", name_dir, as_string (l)); cache_valid (name_dir)= false; // FIXME: we should explicitly remove all data concerning files in 'dir' // from the various caches. Indeed, at a next run of TeXmacs, the directory // will be regarded as up to date, but the other caches may still contain // outdated data. Careful: invalidating the cache lines should not // give rise to a performance penaly (e.g. go through all entries of // 'cache_data', or reloading unchanged files many times). // See also 'declare_out_of_date'. return false; }
void declare_out_of_date (url dir) { //cout << "out of date: " << dir << "\n"; string name_dir= concretize (dir); int l= last_modified (dir, false); cache_set ("validate_cache.scm", name_dir, as_string (l)); cache_valid (name_dir)= false; // FIXME: see 'FIXME' in 'is_up_to_date'. }
string concretize (url u) { // This routine transforms a resolved url into a system file name. // In the case of distant files from the web, a local copy is created. if (is_rooted (u, "default") || is_rooted (u, "file") || is_rooted (u, "blank")) return as_string (reroot (u, "default")); if (is_rooted_web (u)) return concretize (get_from_web (u)); if (is_rooted_tmfs (u)) return concretize (get_from_server (u)); if (is_ramdisc (u)) return concretize (get_from_ramdisc (u)); if (is_here (u)) return as_string (url_pwd ()); if (is_parent (u)) return as_string (url_pwd () * url_parent ()); if (is_wildcard (u, 1)) return u->t[1]->label; std_warning << "Couldn't concretize " << u->t << LF; // failed_error << "u= " << u << LF; // FAILED ("url has no root"); return "xxx"; }
string materialize (url u, string filter) { // Combines resolve and concretize url r= resolve (u, filter); if (!(is_rooted (r) || is_here (r) || is_parent (r))) { failed_error << "u= " << u << LF; FAILED ("url could not be resolved"); } return concretize (r); }
int unix_system (string cmd, string& result) { url temp= url_temp (); string temp_s= escape_sh (concretize (temp)); c_string _cmd (cmd * " > " * temp_s * " 2>&1"); int ret= system (_cmd); bool flag= load_string (temp, result, false); remove (temp); if (flag) result= ""; return ret; }
static void init_deprecated () { #ifndef OS_WIN32 // Check for Macaulay 2 if (get_env ("M2HOME") == "") if (exists_in_path ("M2")) { string where= concretize (resolve_in_path ("M2")); string s = var_eval_system ("grep 'M2HOME=' " * where); string dir = s (search_forwards ("=", s) + 1, N(s)); if (dir != "") set_env ("M2HOME", dir); } #endif }
void cache_initialize () { texmacs_path= url_system ("$TEXMACS_PATH"); if (get_env ("TEXMACS_HOME_PATH") == "") texmacs_home_path= url_system ("$HOME/.TeXmacs"); else texmacs_home_path= url_system ("$TEXMACS_HOME_PATH"); if (get_env ("TEXMACS_DOC_PATH") == "") texmacs_doc_path= url_system ("$TEXMACS_PATH/doc"); else texmacs_doc_path= url_system ("$TEXMACS_DOC_PATH"); texmacs_path_string = concretize (texmacs_path); texmacs_home_path_string = concretize (texmacs_home_path); texmacs_doc_path_string = concretize (texmacs_doc_path); texmacs_font_path_string = concretize (texmacs_home_path * "fonts/"); cache_refresh (); if (is_recursively_up_to_date (texmacs_path * "fonts/type1") && is_recursively_up_to_date (texmacs_path * "fonts/truetype") && is_recursively_up_to_date (texmacs_home_path * "fonts/type1") && is_recursively_up_to_date (texmacs_home_path * "fonts/truetype")); else remove (texmacs_home_path * "fonts/error" * url_wildcard ("*")); }
string gs_embedded () { string cmd; // no need to resolve each time url tmp= url_system (get_env ("TEXMACS_PATH")); url gs= tmp * url_system (GS_EXE); if (exists (gs)) { cmd= concretize (gs); } else { cmd= gs_system (); } return cmd; }
url get_from_web (url name) { if (!is_rooted_web (name)) return url_none (); url res= get_cache (name); if (!is_none (res)) return res; #ifdef OS_WIN32 string urlString = as_string (name); url tmp = url_temp(); if (starts (urlString, "www.")) urlString = "http://" * urlString; else if (starts (urlString, "ftp.")) urlString = "ftp://" * urlString; else if (starts (urlString, "ftp://")) urlPath = NULL; else if (starts (urlString, "http://")) urlPath = NULL; else urlString = "http://" * urlString; urlString= web_encode (urlString); c_string urlPath (urlString); c_string tempFilePath (as_string (tmp)); if(!URL_Get(urlPath, tempFilePath)) return url_none(); else return set_cache (name, tmp); #else string test= var_eval_system ("which wget"); if (!ends (test, "wget")) return url_none (); url tmp= url_temp (); string tmp_s= escape_sh (concretize (tmp)); string cmd= "wget --header='User-Agent: TeXmacs-" TEXMACS_VERSION "' -q"; cmd << " -O " << tmp_s << " " << escape_sh (web_encode (as_string (name))); // cout << cmd << "\n"; system (cmd); // cout << "got " << name << " as " << tmp << "\n"; if (var_eval_system ("cat " * tmp_s * " 2> /dev/null") == "") { remove (tmp); return url_none (); } else return set_cache (name, tmp); #endif }
bool gs_check (url doc) { if (!exists (gs_executable ()) && !exists_in_path (gs_executable ())) return true; array<string> cmd; cmd << gs_executable (); cmd << string ("-dNOPAUSE"); cmd << string ("-dBATCH"); cmd << string ("-dDEBUG"); cmd << string ("-sDEVICE=nullpage"); cmd << concretize (doc); array<int> out; out << 1; out << 2; //cout << "cmd= " << cmd << LF; array<string> ret= evaluate_system (cmd, array<int> (), array<string> (), out); //cout << "ret= " << ret << LF; if (ret [0] != "0" || ret[2] != "") { //convert_error << ret[1] << LF; convert_error << "for file " << doc << LF; convert_error << ret[2] << LF; return false; } return true; }
tree bibtex_run (string bib, string style, url bib_file, tree bib_t) { int i; string bib_s= "\\bibstyle{" * style * "}\n"; for (i=0; i<arity(bib_t); i++) bib_s << "\\citation{" << as_string (bib_t[i]) << "}\n"; string dir= concretize (head (bib_file)); string bib_name= as_string (tail (bib_file)); if ((N(bib_name) >= 4) && (bib_name (N(bib_name)-4, N(bib_name)) == ".bib")) bib_name= bib_name (0, N(bib_name)- 4); bib_s << "\\bibdata{" << bib_name << "}\n"; save_string ("$TEXMACS_HOME_PATH/system/bib/temp.aux", bib_s); #ifdef OS_WIN32 char *directory = as_charp (dir); RunBibtex(directory, "$TEXMACS_HOME_PATH/system/bib", "temp"); tm_delete_array (directory); #else string cmdln= "cd $TEXMACS_HOME_PATH/system/bib; "; cmdln << "BIBINPUTS=" << dir << ":$BIBINPUTS " << "BSTINPUTS=" << dir << ":$BSTINPUTS " << bibtex_command << " temp"; if (DEBUG_AUTO) cout << "TeXmacs] BibTeX command: " << cmdln << "\n"; system (cmdln); #endif return bibtex_load_bbl (bib, "$TEXMACS_HOME_PATH/system/bib/temp.bbl"); /* string result; if (load_string ("$TEXMACS_HOME_PATH/system/bib/temp.bbl", result, false)) return "Error: bibtex failed to create bibliography"; int count=1; tree t= generic_to_tree (result, "latex-snippet"); t= search_bib (t); if (t == "") return ""; tree largest= t[0]; t= t[1]; tree u (DOCUMENT); for (i=0; i<arity(t); i++) { if (is_concat (t[i]) && (is_compound (t[i][0], "bibitem") || is_compound (t[i][0], "bibitem*"))) { tree item= t[i][0]; if (is_compound (item, "bibitem")) item= compound ("bibitem*", as_string (count++), item[0]); t[i][0]= item; tree v (CONCAT, compound ("bibitem*", item[0])); if (is_atomic (item[1])) v << tree (LABEL, bib * "-" * item[1]->label); if (N(t[i])>1) { v << remove_start_space (t[i][1]); v << A (t[i] (2, N(t[i]))); } u << v; } } if (N(u) == 0) u= tree (DOCUMENT, ""); return compound ("bib-list", largest, u); */ }
/** Handle s2e_op instruction. Instructions: 0f 3f XX XX XX XX XX XX XX XX XX: opcode */ void BaseInstructions::handleBuiltInOps(S2EExecutionState* state, uint64_t opcode) { switch((opcode>>8) & 0xFF) { case 0: { /* s2e_check */ uint32_t v = 1; state->writeCpuRegisterConcrete(CPU_OFFSET(regs[R_EAX]), &v, 4); } break; case 1: state->enableSymbolicExecution(); break; case 2: state->disableSymbolicExecution(); break; case 3: { /* s2e_make_symbolic */ makeSymbolic(state, false); break; } case 4: { /* s2e_is_symbolic */ isSymbolic(state); break; } case 5: { /* s2e_get_path_id */ state->writeCpuRegister(offsetof(CPUX86State, regs[R_EAX]), klee::ConstantExpr::create(state->getID(), klee::Expr::Int32)); break; } case 6: { /* s2e_kill_state */ killState(state); break; } case 7: { /* s2e_print_expression */ printExpression(state); break; } case 8: { //Print memory contents printMemory(state); break; } case 9: state->enableForking(); break; case 10: state->disableForking(); break; case 0x10: { /* s2e_print_message */ printMessage(state, opcode >> 16); break; } case 0x11: { /* s2e_make_concolic */ makeSymbolic(state, true); break; } case 0x20: /* concretize */ concretize(state, true); break; case 0x21: { /* replace an expression by one concrete example */ concretize(state, false); break; } case 0x30: { /* Get number of active states */ uint32_t count = s2e()->getExecutor()->getStatesCount(); state->writeCpuRegisterConcrete(CPU_OFFSET(regs[R_EAX]), &count, sizeof(uint32_t)); break; } case 0x31: { /* Get number of active S2E instances */ uint32_t count = s2e()->getCurrentProcessCount(); state->writeCpuRegisterConcrete(CPU_OFFSET(regs[R_EAX]), &count, sizeof(uint32_t)); break; } case 0x32: { /* Sleep for a given number of seconds */ sleep(state); break; } case 0x50: { /* disable/enable timer interrupt */ uint64_t disabled = opcode >> 16; if(disabled) s2e()->getMessagesStream(state) << "Disabling timer interrupt\n"; else s2e()->getMessagesStream(state) << "Enabling timer interrupt\n"; state->writeCpuState(CPU_OFFSET(timer_interrupt_disabled), disabled, 8); break; } case 0x51: { /* disable/enable all apic interrupts */ uint64_t disabled = opcode >> 16; if(disabled) s2e()->getMessagesStream(state) << "Disabling all apic interrupt\n"; else s2e()->getMessagesStream(state) << "Enabling all apic interrupt\n"; state->writeCpuState(CPU_OFFSET(all_apic_interrupts_disabled), disabled, 8); break; } case 0x52: { /* Gets the current S2E memory object size (in power of 2) */ uint32_t size = S2E_RAM_OBJECT_BITS; state->writeCpuRegisterConcrete(CPU_OFFSET(regs[R_EAX]), &size, 4); break; } case 0x70: /* merge point */ state->jumpToSymbolicCpp(); s2e()->getExecutor()->queueStateForMerge(state); break; default: s2e()->getWarningsStream(state) << "BaseInstructions: Invalid built-in opcode " << hexval(opcode) << '\n'; break; } }
inline string eval_system (string which, url u1, url u2) { return eval_system (which * " " * escape_sh (concretize (u1)) * " " * escape_sh (concretize (u2))); }
inline string sys_concretize (url u1) { return escape_sh (concretize (u1)); }
tree sql_exec (url db_name, string cmd) { if (!sqlite3_initialized) tm_sqlite3_initialize (); if (sqlite3_error) { cout << "TeXmacs] ERROR: SQLite support not properly configured.\n"; return tree (TUPLE); } string name= concretize (db_name); if (!sqlite3_connections->contains (name)) { c_string _name (name); sqlite3* db= NULL; //cout << "Opening " << _name << "\n"; int status= SQLITE3_open (_name, &db); if (status == SQLITE_OK) sqlite3_connections (name) = (void*) db; } if (!sqlite3_connections->contains (name)) { cout << "TeXmacs] SQL error: database " << name << " could not be opened\n"; return tree (TUPLE); } tree ret (TUPLE); sqlite3* db= (sqlite3*) sqlite3_connections [name]; c_string _cmd (sql_escape (cmd)); char** tab; int rows, cols; char* err; //cout << "Executing " << _cmd << "\n"; int status= SQLITE3_get_table (db, _cmd, &tab, &rows, &cols, &err); int attempt= 0; while (status != SQLITE_OK && string (err) == string ("database is locked") && attempt < 100) { usleep (100000); attempt++; status= SQLITE3_get_table (db, _cmd, &tab, &rows, &cols, &err); } if (status != SQLITE_OK) { // TODO: improve error handling cout << "TeXmacs] SQL error\n"; if (err != NULL) cout << "TeXmacs] " << err << "\n"; } for (int r=0; r<=rows; r++) { tree row (TUPLE); //cout << " Row " << r << LF; for (int c=0; c<cols; c++) { int i= r*cols + c; if (tab[i] == NULL) row << tree (TUPLE); else { row << tree (scm_quote (sql_unescape (tab[i]))); //cout << " Column " << c << ": " << tab[i] << LF; } } ret << row; } SQLITE3_free_table (tab); //cout << "Return " << ret << "\n"; return ret; }