55 else if (subop >
' ' && subop <=
'~')
62 else if (op >
' ' && op <=
'~')
83 if (ex->disc->inf !=
NULL) {
97 key = ex->disc->keyf(v,
type);
100 snprintf(buf,
sizeof(buf),
"%llx", (
unsigned long long)key.
integer);
127 char buf[2*
sizeof(key.
integer)+1];
144 key = ex->disc->keyf(v,
type);
147 snprintf(buf,
sizeof(buf),
"%llx", (
unsigned long long)key.
integer);
156 strcpy(b->
name, keyname);
209 exerror(
"printf: not enough arguments");
213 const long from =
node->type;
242 node->data.operand.left = 0;
250 exerror(
"printf: out of memory");
268 fmt->
fmt.
size =
sizeof(double);
272 dp->
size =
sizeof(
long long);
288 if (*(
char**)vp ==
NULL) {
289 exerror(
"printf: out of memory");
296 dp->
flags &= ~SFFMT_LONG;
312 *
s = (
char)tolower(*
s);
314 *
s = (char)toupper(*
s);
336 if ((tm = *(
long long *)vp) == -1)
339 exerror(
"printf: no time format provided");
342 stm = localtime(&tm);
346 exerror(
"printf: out of memory");
389 v =
eval(ex, exnode->
data.print.descriptor, env);
398 memset(&fmt, 0,
sizeof(fmt));
402 x = exnode->
data.print.args;
414 }
while ((x = x->
next));
439 exerror(
"scanf: not enough arguments");
449 exerror(
"scanf: %s: floating variable address argument expected",
node->data.variable.symbol->name);
452 fmt->
fmt.
size =
sizeof(double);
453 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
454 memcpy(vp, &value,
sizeof(value));
461 exerror(
"scanf: %s: string variable address argument expected",
node->data.variable.symbol->name);
465 node->data.variable.symbol->value->data.constant.value.string = 0;
467 char *
s =
node->data.variable.symbol->value->data.constant.value.string;
470 memset(
s, 0,
sizeof(
char) * (
size_t)fmt->
fmt.
size);
471 memcpy(vp, &
s,
sizeof(
s));
472 node->data.variable.symbol->value->data.constant.value.string =
s;
477 exerror(
"scanf: %s: char variable address argument expected",
node->data.variable.symbol->name);
480 fmt->
fmt.
size =
sizeof(
long long);
481 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
482 memcpy(vp, &value,
sizeof(value));
488 exerror(
"scanf: %s: integer variable address argument expected",
node->data.variable.symbol->name);
491 dp->
size =
sizeof(
long long);
492 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
493 memcpy(vp, &value,
sizeof(value));
514 if (exnode->
data.scan.descriptor)
516 v =
eval(ex, exnode->
data.scan.descriptor, env);
517 if (exnode->
data.scan.descriptor->type ==
STRING)
529 memset(&fmt, 0,
sizeof(fmt));
533 u =
eval(ex, exnode->
data.scan.format, env);
539 exerror(
"scanf: failed to open temporary file");
561 size_t sz = strlen(l) + strlen(r) + 1;
566 snprintf(
s, sz,
"%s%s", l, r);
578 for (
const char *p = l; *p !=
'\0'; ++p) {
579 if (strchr(p + 1, *p) ==
NULL) {
583 for (
const char *p = r; *p !=
'\0'; ++p) {
584 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
591 if (result ==
NULL) {
597 for (
const char *p = l; *p !=
'\0'; ++p) {
598 if (strchr(p + 1, *p) ==
NULL) {
599 assert(i <
len &&
"incorrect preceding length computation");
604 for (
const char *p = r; *p !=
'\0'; ++p) {
605 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
606 assert(i <
len &&
"incorrect preceding length computation");
611 assert(i + 1 ==
len &&
"incorrect preceding length computation");
625 for (
const char *p = l; *p !=
'\0'; ++p) {
626 if (strchr(r, *p) !=
NULL && strchr(p + 1, *p) ==
NULL) {
633 if (result ==
NULL) {
639 for (
const char *p = l; *p !=
'\0'; ++p) {
640 if (strchr(r, *p) !=
NULL && strchr(p + 1, *p) ==
NULL) {
641 assert(i <
len &&
"incorrect preceding length computation");
646 assert(i + 1 ==
len &&
"incorrect preceding length computation");
660 for (
const char *p = l; *p !=
'\0'; ++p) {
661 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
665 for (
const char *p = r; *p !=
'\0'; ++p) {
666 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
673 if (result ==
NULL) {
679 for (
const char *p = l; *p !=
'\0'; ++p) {
680 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
681 assert(i <
len &&
"incorrect preceding length computation");
686 for (
const char *p = r; *p !=
'\0'; ++p) {
687 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
688 assert(i <
len &&
"incorrect preceding length computation");
693 assert(i + 1 ==
len &&
"incorrect preceding length computation");
707 for (
const char *p = l; *p !=
'\0'; ++p) {
708 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
715 if (result ==
NULL) {
721 for (
const char *p = l; *p !=
'\0'; ++p) {
722 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
723 assert(i <
len &&
"incorrect preceding length computation");
728 assert(i + 1 ==
len &&
"incorrect preceding length computation");
741 size_t len = strlen(l);
743 size_t len2 = strlen(r);
752 if (result ==
NULL) {
758 for (; l[i] !=
'\0' && r[i] !=
'\0'; ++i) {
759 assert(i <
len &&
"incorrect preceding length computation");
760 result[i] = l[i] == r[i] ? l[i] :
' ';
762 assert(i + 1 ==
len &&
"incorrect preceding length computation");
776 while ((c = *repl++)) {
799 exerror(
"out of space [assoc]");
817 Dt_t* arr = exnode->
data.split.array->local;
820 if (exnode->
data.split.seps)
827 sz = strspn (
str, seps);
833 for (
size_t i = 1; i < sz; i++) {
844 sz = strcspn (
str, seps);
870 Dt_t* arr = exnode->
data.split.array->local;
873 if (exnode->
data.split.seps)
880 sz = strspn (
str, seps);
885 sz = strcspn (
str, seps);
918 if (exnode->
data.string.repl)
934 if (p > pat && p[-1] ==
'\\') {
954 exwarn(
"pattern match of empty string - ill-specified pattern \"%s\"?", pat);
995 s =
eval(ex, exnode->
data.string.base, env);
996 len = strlen(
s.string);
997 i =
eval(ex, exnode->
data.string.pat, env);
999 exerror(
"illegal start index in substr(%s,%lld)",
s.string, i.
integer);
1000 if (exnode->
data.string.repl) {
1001 l =
eval(ex, exnode->
data.string.repl, env);
1003 exerror(
"illegal length in substr(%s,%lld,%lld)",
1009 if (exnode->
data.string.repl) {
1025 if (ex->disc->convertf(tmp,
type, 0)) {
1026 exerror(
"%s: cannot convert %s value to %s",
1039 if (ex->disc->stringof(ex, tmp, 0))
1040 exerror(
"%s: no string representation of %s value",
1067 if (!exnode || ex->loopcount)
1077 v =
eval(ex, x, env);
1079 ex->loopop = exnode->
op;
1087 r =
getdyn(ex, x, env, &assoc);
1145 if (exnode->subop ==
PRE)
1149 return getdyn(ex, exnode, env, &assoc);
1151 return exsplit(ex, exnode, env);
1155 return exsub(ex, exnode, env,
true);
1157 return exsub(ex, exnode, env,
false);
1165 seed = (long)time(0);
1172 v =
eval(ex, x, env);
1173 if (ex->disc->exitf)
1174 ex->disc->exitf(env, (
int)v.
integer);
1179 v =
eval(ex, x, env);
1191 r =
eval(ex, x, env);
1200 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1211 v =
eval(ex, x, env);
1228 if ((*t)->integer == v.
integer)
1251 if (ex->loopcount > 0)
1260 r =
eval(ex, a, env);
1261 if (ex->loopcount > 0)
1278 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1294 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1306 for (assoc =
dtlast(exnode->
data.generate.array->
1307 data.variable.symbol->local); assoc;
1316 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE)) {
1328 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE)) {
1337 if (ex->disc->lengthf !=
NULL) {
1360 x = exnode->
data.call.args;
1366 args[n++] =
eval(ex, x->data.operand.left, env);
1370 x = x->data.operand.right;
1372 for (n = 0, a = exnode->
data.call.procedure->
value->data.procedure.args;
1376 exerror(
"too many actual args");
1378 exerror(
"not enough actual args");
1379 v =
exeval(ex, exnode->
data.call.procedure->
value->data.procedure.body, env);
1380 for (n = 0, a = exnode->
data.call.procedure->
value->data.procedure.args;
1387 x = x->data.operand.right)
1388 args[n++] =
eval(ex, x->data.operand.left, env);
1397 x = x->data.operand.right)
1398 args[n++] =
eval(ex, x->data.operand.left, env);
1425 ex->loopret =
eval(ex, x, env);
1426 ex->loopcount = 32767;
1427 ex->loopop = exnode->
op;
1434 FILE *buffer = tmpfile();
1435 if (buffer ==
NULL) {
1436 fprintf(stderr,
"out of memory\n");
1439 print(ex, exnode, env, buffer);
1440 const size_t size =
gv_ftell(buffer);
1446 if (fread(v.
string, size, 1, buffer) < 1) {
1447 fprintf(stderr,
"failed to read back temporary file\n");
1457 if (exnode->subop !=
'=')
1461 v =
getdyn(ex, x, env, &assoc);
1464 if (x->data.variable.index)
1465 v =
eval(ex, x->data.variable.index, env);
1468 if (x->data.variable.dyna) {
1470 locv =
getdyn(ex, x->data.variable.dyna, env, &assoc);
1471 x->data.variable.dyna->data.variable.dyna->data.constant.value = locv;
1473 v = ex->disc->getf(ex, x, x->data.variable.symbol,
1474 x->data.variable.reference, env, (
int)v.
integer,
1480 switch (exnode->subop)
1493 exerror(
"floating divide by 0");
1499 exerror(
"floating 0 modulus");
1528 switch (exnode->subop)
1541 exerror(
"integer divide by 0");
1571 switch (exnode->subop)
1600 getdyn(ex, x, env, &assoc);
1607 v =
eval(ex, x, env);
1614 return exnode ?
eval(ex, exnode, env) : v;
1616 v =
eval(ex, x, env);
1619 v =
eval(ex, x, env);
1622 v =
eval(ex, x, env);
1625 v =
eval(ex, x, env);
1627 r =
eval(ex, x, env);
1633 if (!ex->disc->binaryf(&tmp, exnode, &rtmp, 0))
1652 else if (ex->disc->convertf(&tmp,
STRING, 0)) {
1660 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1693 exerror(
"floating divide by 0");
1699 exerror(
"floating 0 modulus");
1745 xPrint(ex, exnode, v, &tmp);
1756 if (!ex->disc->binaryf(&tmp, exnode, rp, 0))
1803 else if (ex->disc->convertf(&tmp,
STRING, 0)) {
1816 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1849 exerror(
"integer divide by 0");
1894 if (ex->disc->convertf(&tmp,
FLOATING, 0))
1905 if (ex->disc->convertf(&tmp,
INTEGER, 0))
1920 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1969 char *op =
lexname(exnode->
op, exnode->subop);
1973 exerror(
"operator %s %s %s not implemented",
left, op,
1977 exerror(
"operator %s %s not implemented", op,
left);
1992 switch (exnode->
type)
2007 v =
eval(ex, exnode, env);
2008 if (ex->loopcount > 0)
2011 if (ex->loopop ==
RETURN)
Agobj_t * copy(Agraph_t *g, Agobj_t *obj)
static void agxbfree(agxbuf *xb)
free any malloced resources
static size_t agxbput_n(agxbuf *xb, const char *s, size_t ssz)
append string s of length ssz into xb
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
static WUR char * agxbuse(agxbuf *xb)
static int agxbputc(agxbuf *xb, char c)
add character to buffer
static char * agxbdisown(agxbuf *xb)
Memory allocation wrappers that exit on failure.
static char * gv_strdup(const char *original)
char * fmtquote(const char *, const char *, const char *)
quote string as with qb...qe
int strmatch(char *, char *)
int strgrpmatch(char *, char *, size_t *, int, int)
CDT_API int dtsize(Dt_t *)
void exwarn(const char *format,...)
void exerror(const char *format,...)
static int prints(Expr_t *ex, Exnode_t *exnode, void *env, FILE *sp)
static int scformat(void *vp, Sffmt_t *dp)
static Extype_t getdyn(Expr_t *ex, Exnode_t *exnode, void *env, Exassoc_t **assoc)
static void xConvert(Expr_t *ex, Exnode_t *exnode, long type, Extype_t v, Exnode_t *tmp)
static char * str_add(Expr_t *ex, char *l, char *r)
static Extype_t exsub(Expr_t *ex, Exnode_t *exnode, void *env, bool global)
static char * str_xor(Expr_t *ex, const char *l, const char *r)
char * exstring(Expr_t *ex, char *s)
static char * str_and(Expr_t *ex, const char *l, const char *r)
static Extype_t eval(Expr_t *, Exnode_t *, void *)
Extype_t exeval(Expr_t *ex, Exnode_t *exnode, void *env)
static char * str_mpy(Expr_t *ex, const char *l, const char *r)
static Extype_t exsplit(Expr_t *ex, Exnode_t *exnode, void *env)
static void xPrint(Expr_t *ex, Exnode_t *exnode, Extype_t v, Exnode_t *tmp)
static void addItem(Expr_t *ex, Dt_t *arr, Extype_t v, char *tok)
static int prformat(void *vp, Sffmt_t *dp)
static Extype_t exsubstr(Expr_t *ex, Exnode_t *exnode, void *env)
static void replace(agxbuf *s, char *base, char *repl, int ng, size_t *sub)
static char * str_mod(Expr_t *ex, const char *l, const char *r)
static char * lexname(long op, int subop)
static int evaldyn(Expr_t *ex, Exnode_t *exnode, void *env, int delete)
static int scan(Expr_t *ex, Exnode_t *exnode, void *env, FILE *sp)
static int print(Expr_t *ex, Exnode_t *exnode, void *env, FILE *sp)
static char * str_ior(Expr_t *ex, const char *l, const char *r)
static Extype_t extokens(Expr_t *ex, Exnode_t *exnode, void *env)
void * exstralloc(Expr_t *ex, size_t sz)
static NORETURN void graphviz_exit(int status)
const char * exop(size_t id)
Exnode_t * excast(Expr_t *, Exnode_t *, long, Exnode_t *, int)
static char * exprintf(Vmalloc_t *vm, const char *fmt,...)
char * extypename(Expr_t *p, long)
Extype_t exzero(long int)
static double len(glCompPoint p)
replacements for ctype.h functions
static void gv_tolower_str(char *s)
static bool gv_islower(int c)
static bool gv_isupper(int c)
static bool gv_isalnum(int c)
static void gv_toupper_str(char *s)
static bool gv_isdigit(int c)
static bool gv_isalpha(int c)
static size_t gv_ftell(FILE *stream)
ftell, accounting for platform limitations
swig_ptr_object_handlers offset
GVIO_API const char * format
textitem scanner parser str
static Ppoint_t add(Ppoint_t, Ppoint_t)
int sfprint(FILE *, Sffmt_t *format)
int sfvscanf(FILE *, Sffmt_t *format)
void * local
user defined local stuff
long long(* integer)(char **)
INTEGER|UNSIGNED return value.
char *(* string)(char **)
double(* floating)(char **)
bool binary
data.operand.{left,right} ok
union Exnode_s::@89 compiled
struct Exnode_s * param[3]
a non-owning string reference
const char * data
start of the pointed to string
size_t size
extent of the string in bytes
Non-owning string references.
static bool strview_str_eq(strview_t a, const char *b)
compare a string reference to a string for equality
static tok_t tok(const char *input, const char *separators)
begin tokenization of a new string
struct Exdata_u::@87 select
struct Exdata_u::@88 variable
struct Exdata_u::@86 operand
struct Exdata_u::@85 constant
void vmfree(Vmalloc_t *vm, void *data)
void * vmalloc(Vmalloc_t *vm, size_t size)
char * vmstrdup(Vmalloc_t *, const char *)