summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/runstring.cc
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-01-02 16:31:31 +0000
committerKarl Berry <karl@freefriends.org>2021-01-02 16:31:31 +0000
commit6457cd3f6e21e23e21db6dafff021d17f5457567 (patch)
tree08f169333e47c5fc1c50e828cf3a0f50bdf9b508 /Build/source/utils/asymptote/runstring.cc
parentdc2504a4c02af0ec2fff00e6b833c6143a06b4cd (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.cc')
-rw-r--r--Build/source/utils/asymptote/runstring.cc175
1 files changed, 89 insertions, 86 deletions
diff --git a/Build/source/utils/asymptote/runstring.cc b/Build/source/utils/asymptote/runstring.cc
index 89c151026a7..98f10e08f2d 100644
--- a/Build/source/utils/asymptote/runstring.cc
+++ b/Build/source/utils/asymptote/runstring.cc
@@ -90,16 +90,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++;
@@ -107,7 +107,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 == '*') {
@@ -118,7 +118,7 @@ void checkformat(const char *ptr, bool intformat)
}
while(*ptr && strchr ("hlL", *ptr))
ptr++;
-
+
if(*ptr == '%') {++ptr; continue;}
else if(*ptr != '\0') {
if(intformat) {
@@ -133,7 +133,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;
@@ -160,7 +160,7 @@ void checkformat(const char *ptr, bool intformat)
} /* End of else statement */
}
}
-
+
// Autogenerated routines:
@@ -257,7 +257,7 @@ void gen_runstring7(stack *Stack)
#line 157 "runstring.in"
if ((size_t) pos < s.length())
{Stack->push<string>(s.erase(pos,n)); return;}
- {Stack->push<string>(s); return;}
+ {Stack->push<string>(s); return;}
}
#line 163 "runstring.in"
@@ -294,39 +294,42 @@ void gen_runstring10(stack *Stack)
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) {Stack->push<string>(buf.str()); return;}
+ pos += len;
+ if(pos == Len) {Stack->push<string>(buf.str()); return;}
i=0;
}
- buf << *(p++);
+ buf << S->substr(pos,1);
+ ++pos;
}
{Stack->push<string>(buf.str()); return;}
}
-#line 205 "runstring.in"
+#line 208 "runstring.in"
// string format(string *format, Int x, string locale=emptystring);
void gen_runstring11(stack *Stack)
{
string locale=vm::pop<string>(Stack,emptystring);
Int x=vm::pop<Int>(Stack);
string * format=vm::pop<string *>(Stack);
-#line 206 "runstring.in"
+#line 209 "runstring.in"
ostringstream out;
const char *p0=format->c_str();
checkformat(p0,true);
-
+
const char *p=p0;
const char *start=NULL;
while(*p != 0) {
@@ -337,16 +340,16 @@ void gen_runstring11(stack *Stack)
}
out << *(p++);
}
-
+
if(!start) {Stack->push<string>(out.str()); return;}
-
- // Allow at most 1 argument
+
+ // Allow at most 1 argument
while(*p != 0) {
if(*p == '*' || *p == '$') {Stack->push<string>(out.str()); return;}
if(isupper(*p) || islower(*p)) {p++; break;}
p++;
}
-
+
string f=format->substr(start-p0,p-start);
const char *oldlocale=NULL;
@@ -366,7 +369,7 @@ void gen_runstring11(stack *Stack)
out << p;
delete[] buf;
-
+
if(oldlocale) {
setlocale(LC_ALL,oldlocale);
delete[] oldlocale;
@@ -375,7 +378,7 @@ void gen_runstring11(stack *Stack)
{Stack->push<string>(out.str()); return;}
}
-#line 259 "runstring.in"
+#line 262 "runstring.in"
// string format(string *format, bool forcemath=false, string separator, real x, string locale=emptystring);
void gen_runstring12(stack *Stack)
{
@@ -384,18 +387,18 @@ void gen_runstring12(stack *Stack)
string separator=vm::pop<string>(Stack);
bool forcemath=vm::pop<bool>(Stack,false);
string * format=vm::pop<string *>(Stack);
-#line 261 "runstring.in"
+#line 264 "runstring.in"
if(*format == "%") {Stack->push<string>(""); 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;
@@ -409,16 +412,16 @@ void gen_runstring12(stack *Stack)
}
out << *(p++);
}
-
+
if(!start) {Stack->push<string>(out.str()); return;}
-
- // Allow at most 1 argument
+
+ // Allow at most 1 argument
while(*p != 0) {
if(*p == '*' || *p == '$') {Stack->push<string>(out.str()); return;}
if(isupper(*p) || islower(*p)) {p++; break;}
p++;
}
-
+
const char *tail=p;
string f=format->substr(start-p0,tail-start);
@@ -437,14 +440,14 @@ void gen_runstring12(stack *Stack)
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
@@ -461,11 +464,11 @@ void gen_runstring12(stack *Stack)
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++;
}
@@ -477,12 +480,12 @@ void gen_runstring12(stack *Stack)
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) == '+');
@@ -497,26 +500,26 @@ void gen_runstring12(stack *Stack)
}
out << *(q++);
}
-
- while(*tail != 0)
+
+ while(*tail != 0)
out << *(tail++);
-
+
delete[] buf;
if(oldlocale) {
setlocale(LC_ALL,oldlocale);
delete[] oldlocale;
}
-
+
{Stack->push<string>(out.str()); return;}
}
-#line 388 "runstring.in"
+#line 391 "runstring.in"
// Int hex(string s);
void gen_runstring13(stack *Stack)
{
string s=vm::pop<string>(Stack);
-#line 389 "runstring.in"
+#line 392 "runstring.in"
istringstream is(s);
is.setf(std::ios::hex,std::ios::basefield);
Int value;
@@ -526,61 +529,61 @@ void gen_runstring13(stack *Stack)
error(buf);
}
-#line 399 "runstring.in"
+#line 402 "runstring.in"
// Int ascii(string s);
void gen_runstring14(stack *Stack)
{
string s=vm::pop<string>(Stack);
-#line 400 "runstring.in"
+#line 403 "runstring.in"
{Stack->push<Int>(s.empty() ? -1 : (unsigned char) s[0]); return;}
}
-#line 404 "runstring.in"
+#line 407 "runstring.in"
// string string(Int x);
void gen_runstring15(stack *Stack)
{
Int x=vm::pop<Int>(Stack);
-#line 405 "runstring.in"
+#line 408 "runstring.in"
ostringstream buf;
buf << x;
{Stack->push<string>(buf.str()); return;}
}
-#line 411 "runstring.in"
+#line 414 "runstring.in"
// string string(real x, Int digits=DBL_DIG);
void gen_runstring16(stack *Stack)
{
Int digits=vm::pop<Int>(Stack,DBL_DIG);
real x=vm::pop<real>(Stack);
-#line 412 "runstring.in"
+#line 415 "runstring.in"
ostringstream buf;
buf.precision(digits);
buf << x;
{Stack->push<string>(buf.str()); return;}
}
-#line 419 "runstring.in"
+#line 422 "runstring.in"
// string time(string format=defaulttimeformat);
void gen_runstring17(stack *Stack)
{
string format=vm::pop<string>(Stack,defaulttimeformat);
-#line 420 "runstring.in"
+#line 423 "runstring.in"
#ifdef HAVE_STRFTIME
const time_t bintime=time(NULL);
if(!strftime(Time,nTime,format.c_str(),localtime(&bintime))) {Stack->push<string>(""); return;}
{Stack->push<string>(Time); return;}
#else
{Stack->push<string>(format); return;}
-#endif
+#endif
}
-#line 430 "runstring.in"
+#line 433 "runstring.in"
// string time(Int seconds, string format=defaulttimeformat);
void gen_runstring18(stack *Stack)
{
string format=vm::pop<string>(Stack,defaulttimeformat);
Int seconds=vm::pop<Int>(Stack);
-#line 431 "runstring.in"
+#line 434 "runstring.in"
#ifdef HAVE_STRFTIME
const time_t bintime=seconds;
if(!strftime(Time,nTime,format.c_str(),localtime(&bintime))) {Stack->push<string>(""); return;}
@@ -592,13 +595,13 @@ void gen_runstring18(stack *Stack)
#endif
}
-#line 443 "runstring.in"
+#line 446 "runstring.in"
// Int seconds(string t=emptystring, string format=emptystring);
void gen_runstring19(stack *Stack)
{
string format=vm::pop<string>(Stack,emptystring);
string t=vm::pop<string>(Stack,emptystring);
-#line 444 "runstring.in"
+#line 447 "runstring.in"
#if defined(HAVE_STRPTIME)
const time_t bintime=time(NULL);
tm tm=*localtime(&bintime);
@@ -606,7 +609,7 @@ void gen_runstring19(stack *Stack)
{Stack->push<Int>((Int) mktime(&tm)); return;}
#else
{Stack->push<Int>(-1); return;}
-#endif
+#endif
}
} // namespace run
@@ -620,41 +623,41 @@ void gen_runstring_venv(venv &ve)
#line 119 "runstring.in"
addFunc(ve, run::gen_runstring1, primInt(), SYM(length), formal(primString(), SYM(s), false, false));
#line 124 "runstring.in"
- addFunc(ve, run::gen_runstring2, primInt(), SYM(find), formal(primString(), SYM(s), false, false), formal(primString() , SYM(t), false, false), formal(primInt(), SYM(pos), true, false));
+ addFunc(ve, run::gen_runstring2, primInt(), SYM(find), formal(primString(), SYM(s), false, false), formal(primString(), SYM(t), false, false), formal(primInt(), SYM(pos), true, false));
#line 130 "runstring.in"
- addFunc(ve, run::gen_runstring3, primInt(), SYM(rfind), formal(primString(), SYM(s), false, false), formal(primString() , SYM(t), false, false), formal(primInt(), SYM(pos), true, false));
+ addFunc(ve, run::gen_runstring3, primInt(), SYM(rfind), formal(primString(), SYM(s), false, false), formal(primString(), SYM(t), false, false), formal(primInt(), SYM(pos), true, false));
#line 136 "runstring.in"
- addFunc(ve, run::gen_runstring4, primString() , SYM(reverse), formal(primString() , SYM(s), false, false));
+ addFunc(ve, run::gen_runstring4, primString(), SYM(reverse), formal(primString(), SYM(s), false, false));
#line 142 "runstring.in"
- addFunc(ve, run::gen_runstring5, primString() , SYM(insert), formal(primString() , SYM(s), false, false), formal(primInt(), SYM(pos), false, false), formal(primString() , SYM(t), false, false));
+ addFunc(ve, run::gen_runstring5, primString(), SYM(insert), formal(primString(), SYM(s), false, false), formal(primInt(), SYM(pos), false, false), formal(primString(), SYM(t), false, false));
#line 149 "runstring.in"
- addFunc(ve, run::gen_runstring6, primString() , SYM(substr), formal(primString(), SYM(s), false, false), formal(primInt(), SYM(pos), false, false), formal(primInt(), SYM(n), true, false));
+ addFunc(ve, run::gen_runstring6, primString(), SYM(substr), formal(primString(), SYM(s), false, false), formal(primInt(), SYM(pos), false, false), formal(primInt(), SYM(n), true, false));
#line 156 "runstring.in"
- addFunc(ve, run::gen_runstring7, primString() , SYM(erase), formal(primString() , SYM(s), false, false), formal(primInt(), SYM(pos), false, false), formal(primInt(), SYM(n), false, false));
+ addFunc(ve, run::gen_runstring7, primString(), SYM(erase), formal(primString(), SYM(s), false, false), formal(primInt(), SYM(pos), false, false), formal(primInt(), SYM(n), false, false));
#line 163 "runstring.in"
- addFunc(ve, run::gen_runstring8, primString() , SYM(downcase), formal(primString() , SYM(s), false, false));
+ addFunc(ve, run::gen_runstring8, primString(), SYM(downcase), formal(primString(), SYM(s), false, false));
#line 169 "runstring.in"
- addFunc(ve, run::gen_runstring9, primString() , SYM(upcase), formal(primString() , SYM(s), false, false));
+ addFunc(ve, run::gen_runstring9, primString(), SYM(upcase), formal(primString(), SYM(s), false, false));
#line 175 "runstring.in"
- addFunc(ve, run::gen_runstring10, primString() , SYM(replace), formal(primString(), SYM(s), false, false), formal(stringArray2(), SYM(translate), false, false));
-#line 205 "runstring.in"
- addFunc(ve, run::gen_runstring11, primString() , SYM(format), formal(primString(), SYM(format), false, false), formal(primInt(), SYM(x), false, false), formal(primString() , SYM(locale), true, false));
-#line 259 "runstring.in"
- addFunc(ve, run::gen_runstring12, primString() , SYM(format), formal(primString(), SYM(format), false, false), formal(primBoolean(), SYM(forcemath), true, false), formal(primString() , SYM(separator), false, false), formal(primReal(), SYM(x), false, false), formal(primString() , SYM(locale), true, false));
-#line 388 "runstring.in"
- addFunc(ve, run::gen_runstring13, primInt(), SYM(hex), formal(primString() , SYM(s), false, false));
-#line 399 "runstring.in"
- addFunc(ve, run::gen_runstring14, primInt(), SYM(ascii), formal(primString() , SYM(s), false, false));
-#line 404 "runstring.in"
- addFunc(ve, run::gen_runstring15, primString() , SYM(string), formal(primInt(), SYM(x), false, false));
-#line 411 "runstring.in"
- addFunc(ve, run::gen_runstring16, primString() , SYM(string), formal(primReal(), SYM(x), false, false), formal(primInt(), SYM(digits), true, false));
-#line 419 "runstring.in"
- addFunc(ve, run::gen_runstring17, primString() , SYM(time), formal(primString() , SYM(format), true, false));
-#line 430 "runstring.in"
- addFunc(ve, run::gen_runstring18, primString() , SYM(time), formal(primInt(), SYM(seconds), false, false), formal(primString() , SYM(format), true, false));
-#line 443 "runstring.in"
- addFunc(ve, run::gen_runstring19, primInt(), SYM(seconds), formal(primString() , SYM(t), true, false), formal(primString() , SYM(format), true, false));
+ addFunc(ve, run::gen_runstring10, primString(), SYM(replace), formal(primString(), SYM(s), false, false), formal(stringArray2(), SYM(translate), false, false));
+#line 208 "runstring.in"
+ addFunc(ve, run::gen_runstring11, primString(), SYM(format), formal(primString(), SYM(format), false, false), formal(primInt(), SYM(x), false, false), formal(primString(), SYM(locale), true, false));
+#line 262 "runstring.in"
+ addFunc(ve, run::gen_runstring12, primString(), SYM(format), formal(primString(), SYM(format), false, false), formal(primBoolean(), SYM(forcemath), true, false), formal(primString(), SYM(separator), false, false), formal(primReal(), SYM(x), false, false), formal(primString(), SYM(locale), true, false));
+#line 391 "runstring.in"
+ addFunc(ve, run::gen_runstring13, primInt(), SYM(hex), formal(primString(), SYM(s), false, false));
+#line 402 "runstring.in"
+ addFunc(ve, run::gen_runstring14, primInt(), SYM(ascii), formal(primString(), SYM(s), false, false));
+#line 407 "runstring.in"
+ addFunc(ve, run::gen_runstring15, primString(), SYM(string), formal(primInt(), SYM(x), false, false));
+#line 414 "runstring.in"
+ addFunc(ve, run::gen_runstring16, primString(), SYM(string), formal(primReal(), SYM(x), false, false), formal(primInt(), SYM(digits), true, false));
+#line 422 "runstring.in"
+ addFunc(ve, run::gen_runstring17, primString(), SYM(time), formal(primString(), SYM(format), true, false));
+#line 433 "runstring.in"
+ addFunc(ve, run::gen_runstring18, primString(), SYM(time), formal(primInt(), SYM(seconds), false, false), formal(primString(), SYM(format), true, false));
+#line 446 "runstring.in"
+ addFunc(ve, run::gen_runstring19, primInt(), SYM(seconds), formal(primString(), SYM(t), true, false), formal(primString(), SYM(format), true, false));
}
} // namespace trans