diff options
author | Karl Berry <karl@freefriends.org> | 2021-01-02 16:31:31 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-01-02 16:31:31 +0000 |
commit | 6457cd3f6e21e23e21db6dafff021d17f5457567 (patch) | |
tree | 08f169333e47c5fc1c50e828cf3a0f50bdf9b508 /Build/source/utils/asymptote/runstring.in | |
parent | dc2504a4c02af0ec2fff00e6b833c6143a06b4cd (diff) |
asy 2.68 sources
git-svn-id: svn://tug.org/texlive/trunk@57291 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/utils/asymptote/runstring.in')
-rw-r--r-- | Build/source/utils/asymptote/runstring.in | 87 |
1 files changed, 45 insertions, 42 deletions
diff --git a/Build/source/utils/asymptote/runstring.in b/Build/source/utils/asymptote/runstring.in index a8b0e68bce1..415db53652b 100644 --- a/Build/source/utils/asymptote/runstring.in +++ b/Build/source/utils/asymptote/runstring.in @@ -35,16 +35,16 @@ static const string defaulttimeformat=string("%a %b %d %T %Z %Y"); #ifdef HAVE_STRFTIME static const size_t nTime=256; static char Time[nTime]; -#endif +#endif -void checkformat(const char *ptr, bool intformat) +void checkformat(const char *ptr, bool intformat) { while(*ptr != '\0') { if(*ptr != '%') /* While we have regular characters, print them. */ ptr++; else { /* We've got a format specifier. */ ptr++; - + while(*ptr && strchr ("-+ #0'I", *ptr)) /* Move past flags. */ ptr++; @@ -52,7 +52,7 @@ void checkformat(const char *ptr, bool intformat) ptr++; else while(isdigit(*ptr)) /* Handle explicit numeric value. */ ptr++; - + if(*ptr == '.') { ptr++; /* Go past the period. */ if(*ptr == '*') { @@ -63,7 +63,7 @@ void checkformat(const char *ptr, bool intformat) } while(*ptr && strchr ("hlL", *ptr)) ptr++; - + if(*ptr == '%') {++ptr; continue;} else if(*ptr != '\0') { if(intformat) { @@ -78,7 +78,7 @@ void checkformat(const char *ptr, bool intformat) break; default: ostringstream buf; - buf << "Invalid format '" << *ptr << "' for type " + buf << "Invalid format '" << *ptr << "' for type " << types::names[types::ty_Int]; error(buf); break; @@ -105,7 +105,7 @@ void checkformat(const char *ptr, bool intformat) } /* End of else statement */ } } - + // Autogenerated routines: @@ -157,7 +157,7 @@ string erase(string s, Int pos, Int n) { if ((size_t) pos < s.length()) return s.erase(pos,n); - return s; + return s; } string downcase(string s) @@ -181,33 +181,36 @@ string replace(string *S, stringarray2 *translate) array *a=read<array*>(translate,i); checkArray(a); } - const char *p=S->c_str(); + size_t pos=0; ostringstream buf; - while(*p) { + size_t Len=S->length(); + + while(pos < Len) { for(size_t i=0; i < size;) { array *a=read<array*>(translate,i); size_t size2=checkArray(a); - if(size2 != 2) + if(size2 != 2) error("translation table entry must be an array of length 2"); string* from=read<string*>(a,0); size_t len=from->length(); - if(strncmp(p,from->c_str(),len) != 0) {i++; continue;} + if(len == 0 || S->compare(pos,len,*from,0,len) != 0) {i++; continue;} buf << read<string>(a,1); - p += len; - if(*p == 0) return buf.str(); + pos += len; + if(pos == Len) return buf.str(); i=0; } - buf << *(p++); + buf << S->substr(pos,1); + ++pos; } return buf.str(); } -string format(string *format, Int x, string locale=emptystring) +string format(string *format, Int x, string locale=emptystring) { ostringstream out; const char *p0=format->c_str(); checkformat(p0,true); - + const char *p=p0; const char *start=NULL; while(*p != 0) { @@ -218,16 +221,16 @@ string format(string *format, Int x, string locale=emptystring) } out << *(p++); } - + if(!start) return out.str(); - - // Allow at most 1 argument + + // Allow at most 1 argument while(*p != 0) { if(*p == '*' || *p == '$') return out.str(); if(isupper(*p) || islower(*p)) {p++; break;} p++; } - + string f=format->substr(start-p0,p-start); const char *oldlocale=NULL; @@ -247,7 +250,7 @@ string format(string *format, Int x, string locale=emptystring) out << p; delete[] buf; - + if(oldlocale) { setlocale(LC_ALL,oldlocale); delete[] oldlocale; @@ -260,16 +263,16 @@ string format(string *format, bool forcemath=false, string separator, real x, string locale=emptystring) { if(*format == "%") return ""; // Temporary workaround for github Issue #29. - + bool tex=getSetting<string>("tex") != "none"; bool texify=forcemath; ostringstream out; - + const char *p0=format->c_str(); checkformat(p0,false); const char *phantom="\\phantom{+}"; - + const char *p=p0; const char *start=NULL; char prev=0; @@ -283,16 +286,16 @@ string format(string *format, bool forcemath=false, string separator, real x, } out << *(p++); } - + if(!start) return out.str(); - - // Allow at most 1 argument + + // Allow at most 1 argument while(*p != 0) { if(*p == '*' || *p == '$') return out.str(); if(isupper(*p) || islower(*p)) {p++; break;} p++; } - + const char *tail=p; string f=format->substr(start-p0,tail-start); @@ -311,14 +314,14 @@ string format(string *format, bool forcemath=false, string separator, real x, bool trailingzero=f.find("#") < string::npos; bool plus=f.find("+") < string::npos; bool space=f.find(" ") < string::npos; - + char *q=buf; // beginning of formatted number if(*q == ' ' && texify) { out << phantom; q++; } - + const char decimal=*(localeconv()->decimal_point); // Remove any spurious sign @@ -335,11 +338,11 @@ string format(string *format, bool forcemath=false, string separator, real x, if((plus || space) && texify) out << phantom; } } - + const char *r=p=q; bool dp=false; while(*r != 0 && (isspace(*r) || isdigit(*r) || *r == decimal \ - || *r == '+' || *r == '-')) { + || *r == '+' || *r == '-')) { if(*r == decimal) dp=true; r++; } @@ -351,12 +354,12 @@ string format(string *format, bool forcemath=false, string separator, real x, while(q <= r) out << *(q++); if(!trailingzero) q += n; } - + bool zero=(r == p && *r == '0') && !trailingzero; - + // Translate "E+/E-/e+/e-" exponential notation to TeX while(*q != 0) { - if(texify && (*q == 'E' || *q == 'e') && + if(texify && (*q == 'E' || *q == 'e') && (*(q+1) == '+' || *(q+1) == '-')) { if(!zero) out << separator << "10^{"; bool plus=(*(q+1) == '+'); @@ -371,17 +374,17 @@ string format(string *format, bool forcemath=false, string separator, real x, } out << *(q++); } - - while(*tail != 0) + + while(*tail != 0) out << *(tail++); - + delete[] buf; if(oldlocale) { setlocale(LC_ALL,oldlocale); delete[] oldlocale; } - + return out.str(); } @@ -424,7 +427,7 @@ string time(string format=defaulttimeformat) return Time; #else return format; -#endif +#endif } string time(Int seconds, string format=defaulttimeformat) @@ -449,5 +452,5 @@ Int seconds(string t=emptystring, string format=emptystring) return (Int) mktime(&tm); #else return -1; -#endif +#endif } |