From e355922861e2bc91176c058d563d477444c2dfd9 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Wed, 15 Jul 2009 00:14:18 +0000 Subject: asymptote 1.81 source/w32 update git-svn-id: svn://tug.org/texlive/trunk@14262 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/utils/asymptote/util.cc | 101 ++++++++++++++++------------------- 1 file changed, 47 insertions(+), 54 deletions(-) (limited to 'Build/source/utils/asymptote/util.cc') diff --git a/Build/source/utils/asymptote/util.cc b/Build/source/utils/asymptote/util.cc index ecf6bd272d6..33fb56ad104 100644 --- a/Build/source/utils/asymptote/util.cc +++ b/Build/source/utils/asymptote/util.cc @@ -91,11 +91,6 @@ string stripFile(string name) return dir ? name : ""; } -string stripTeXFile(string name) -{ - return getSetting("tex") == "context" ? "" : stripFile(name); -} - string stripExt(string name, const string& ext) { string suffix="."+ext; @@ -167,49 +162,39 @@ string auxname(string filename, string suffix) return buildname(filename,suffix,"_"); } -char **args(const char *command, bool quiet) +void push_split(mem::vector& a, const string& S) { - if(command == NULL) return NULL; - - size_t n=0; - char **argv=NULL; - for(int pass=0; pass < 2; ++pass) { - if(pass) argv=new char*[n+1]; - ostringstream buf; - const char *p=command; - bool empty=true; - bool quote=false; - n=0; - char c; - while((c=*(p++))) { - if(!quote && c == ' ') { - if(!empty) { - if(pass) { - argv[n]=StrdupNoGC(buf.str()); - buf.str(""); - } - empty=true; - n++; - } - } else { - empty=false; - if(c == '\'') quote=!quote; - else if(pass) buf << c; + const char *p=S.c_str(); + string s; + char c; + while((c=*(p++))) { + if(c == ' ') { + if(s.size() > 0) { + a.push_back(s); + s.clear(); } - } - if(!empty) { - if(pass) argv[n]=StrdupNoGC(buf.str()); - n++; - } + } else s += c; } + if(s.size() > 0) + a.push_back(s); +} + +char **args(const mem::vector& s, bool quiet) +{ + size_t count=s.size(); + + char **argv=NULL; + argv=new char*[count+1]; + for(size_t i=0; i < count; ++i) + argv[i]=StrdupNoGC(s[i]); if(!quiet && settings::verbose > 1) { cerr << argv[0]; - for(size_t m=1; m < n; ++m) cerr << " " << argv[m]; + for(size_t i=1; i < count; ++i) cerr << " " << argv[i]; cerr << endl; } - argv[n]=NULL; + argv[count]=NULL; return argv; } @@ -235,14 +220,11 @@ void execError(const char *command, const char *hint, const char *application) } // quiet: 0=none; 1=suppress stdout; 2=suppress stdout+stderr. - -int System(const char *command, int quiet, bool wait, +int System(const mem::vector &command, int quiet, bool wait, const char *hint, const char *application, int *ppid) { int status; - if(!command) return 1; - cout.flush(); // Flush stdout to avoid duplicate output. char **argv=args(command); @@ -276,7 +258,8 @@ int System(const char *command, int quiet, bool wait, if(errno != EINTR) { if(quiet < 2) { ostringstream msg; - msg << "Command failed: " << command; + msg << "Command failed: "; + for(size_t i=0; i < command.size(); ++i) msg << command[i]; camp::reportError(msg); } } @@ -294,7 +277,8 @@ int System(const char *command, int quiet, bool wait, } else { if(quiet < 2) { ostringstream msg; - msg << "Command exited abnormally: " << command; + msg << "Command exited abnormally: "; + for(size_t i=0; i < command.size(); ++i) msg << command[i]; camp::reportError(msg); } } @@ -302,12 +286,6 @@ int System(const char *command, int quiet, bool wait, } } -int System(const ostringstream& command, int quiet, bool wait, - const char *hint, const char *application, int *pid) -{ - return System(command.str().c_str(),quiet,wait,hint,application,pid); -} - string stripblanklines(const string& s) { string S=string(s); @@ -361,6 +339,18 @@ const char *setPath(const char *s, bool quiet) return p; } +void push_command(mem::vector& a, const string& s) +{ + a.push_back(s); +#ifdef __CYGWIN__ + if(s == "cmd") { + a.push_back("/c"); + a.push_back("start"); + a.push_back("\"\""); + } +#endif +} + void popupHelp() { // If the popped-up help is already running, pid stores the pid of the viewer. static int pid=0; @@ -371,9 +361,12 @@ void popupHelp() { // If the help viewer isn't running (or its last run has termined), launch the // viewer again. if (pid==0 || (waitpid(pid, &status, WNOHANG) == pid)) { - ostringstream cmd; - cmd << "'" << getSetting("pdfviewer") << "' '" - << docdir << dirsep << "asymptote.pdf'"; + mem::vector cmd; + push_command(cmd,getSetting("pdfviewer")); + string viewerOptions=getSetting("pdfviewerOptions"); + if(!viewerOptions.empty()) + cmd.push_back(viewerOptions); + cmd.push_back(docdir+dirsep+"asymptote.pdf"); status=System(cmd,0,false,"pdfviewer","your PDF viewer",&pid); } } -- cgit v1.2.3