55 else if (subop >
' ' && subop <=
'~')
62 else if (op >
' ' && op <=
'~')
91 key = ex->disc->keyf(v,
type);
94 snprintf(buf,
sizeof(buf),
"%llx", (
unsigned long long)key.
integer);
121 char buf[2*
sizeof(key.
integer)+1];
138 key = ex->disc->keyf(v,
type);
141 snprintf(buf,
sizeof(buf),
"%llx", (
unsigned long long)key.
integer);
150 strcpy(b->
name, keyname);
203 exerror(
"printf: not enough arguments");
207 const long from =
node->type;
236 node->data.operand.left = 0;
244 exerror(
"printf: out of memory");
262 fmt->
fmt.
size =
sizeof(double);
266 dp->
size =
sizeof(
long long);
282 if (*(
char**)vp ==
NULL) {
283 exerror(
"printf: out of memory");
290 dp->
flags &= ~SFFMT_LONG;
306 *
s = (
char)tolower(*
s);
308 *
s = (char)toupper(*
s);
330 if ((tm = *(
long long *)vp) == -1)
333 exerror(
"printf: no time format provided");
336 stm = localtime(&tm);
340 exerror(
"printf: out of memory");
383 v =
eval(ex, exnode->
data.print.descriptor, env);
392 memset(&fmt, 0,
sizeof(fmt));
396 x = exnode->
data.print.args;
408 }
while ((x = x->
next));
433 exerror(
"scanf: not enough arguments");
443 exerror(
"scanf: %s: floating variable address argument expected",
node->data.variable.symbol->name);
446 fmt->
fmt.
size =
sizeof(double);
447 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
448 memcpy(vp, &value,
sizeof(value));
455 exerror(
"scanf: %s: string variable address argument expected",
node->data.variable.symbol->name);
459 node->data.variable.symbol->value->data.constant.value.string = 0;
461 char *
s =
node->data.variable.symbol->value->data.constant.value.string;
464 memset(
s, 0,
sizeof(
char) * (
size_t)fmt->
fmt.
size);
465 memcpy(vp, &
s,
sizeof(
s));
466 node->data.variable.symbol->value->data.constant.value.string =
s;
471 exerror(
"scanf: %s: char variable address argument expected",
node->data.variable.symbol->name);
474 fmt->
fmt.
size =
sizeof(
long long);
475 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
476 memcpy(vp, &value,
sizeof(value));
482 exerror(
"scanf: %s: integer variable address argument expected",
node->data.variable.symbol->name);
485 dp->
size =
sizeof(
long long);
486 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
487 memcpy(vp, &value,
sizeof(value));
508 if (exnode->
data.scan.descriptor)
510 v =
eval(ex, exnode->
data.scan.descriptor, env);
511 if (exnode->
data.scan.descriptor->type ==
STRING)
523 memset(&fmt, 0,
sizeof(fmt));
527 u =
eval(ex, exnode->
data.scan.format, env);
533 exerror(
"scanf: failed to open temporary file");
555 size_t sz = strlen(l) + strlen(r) + 1;
560 snprintf(
s, sz,
"%s%s", l, r);
572 for (
const char *p = l; *p !=
'\0'; ++p) {
573 if (strchr(p + 1, *p) ==
NULL) {
577 for (
const char *p = r; *p !=
'\0'; ++p) {
578 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
585 if (result ==
NULL) {
591 for (
const char *p = l; *p !=
'\0'; ++p) {
592 if (strchr(p + 1, *p) ==
NULL) {
593 assert(i <
len &&
"incorrect preceding length computation");
598 for (
const char *p = r; *p !=
'\0'; ++p) {
599 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
600 assert(i <
len &&
"incorrect preceding length computation");
605 assert(i + 1 ==
len &&
"incorrect preceding length computation");
619 for (
const char *p = l; *p !=
'\0'; ++p) {
620 if (strchr(r, *p) !=
NULL && strchr(p + 1, *p) ==
NULL) {
627 if (result ==
NULL) {
633 for (
const char *p = l; *p !=
'\0'; ++p) {
634 if (strchr(r, *p) !=
NULL && strchr(p + 1, *p) ==
NULL) {
635 assert(i <
len &&
"incorrect preceding length computation");
640 assert(i + 1 ==
len &&
"incorrect preceding length computation");
654 for (
const char *p = l; *p !=
'\0'; ++p) {
655 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
659 for (
const char *p = r; *p !=
'\0'; ++p) {
660 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
667 if (result ==
NULL) {
673 for (
const char *p = l; *p !=
'\0'; ++p) {
674 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
675 assert(i <
len &&
"incorrect preceding length computation");
680 for (
const char *p = r; *p !=
'\0'; ++p) {
681 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
682 assert(i <
len &&
"incorrect preceding length computation");
687 assert(i + 1 ==
len &&
"incorrect preceding length computation");
701 for (
const char *p = l; *p !=
'\0'; ++p) {
702 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
709 if (result ==
NULL) {
715 for (
const char *p = l; *p !=
'\0'; ++p) {
716 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
717 assert(i <
len &&
"incorrect preceding length computation");
722 assert(i + 1 ==
len &&
"incorrect preceding length computation");
735 size_t len = strlen(l);
737 size_t len2 = strlen(r);
746 if (result ==
NULL) {
752 for (; l[i] !=
'\0' && r[i] !=
'\0'; ++i) {
753 assert(i <
len &&
"incorrect preceding length computation");
754 result[i] = l[i] == r[i] ? l[i] :
' ';
756 assert(i + 1 ==
len &&
"incorrect preceding length computation");
770 while ((c = *repl++)) {
793 exerror(
"out of space [assoc]");
811 Dt_t* arr = exnode->
data.split.array->local;
814 if (exnode->
data.split.seps)
821 sz = strspn (
str, seps);
827 for (
size_t i = 1; i < sz; i++) {
838 sz = strcspn (
str, seps);
864 Dt_t* arr = exnode->
data.split.array->local;
867 if (exnode->
data.split.seps)
874 sz = strspn (
str, seps);
879 sz = strcspn (
str, seps);
912 if (exnode->
data.string.repl)
928 if (p > pat && p[-1] ==
'\\') {
948 exwarn(
"pattern match of empty string - ill-specified pattern \"%s\"?", pat);
989 s =
eval(ex, exnode->
data.string.base, env);
990 len = strlen(
s.string);
991 i =
eval(ex, exnode->
data.string.pat, env);
993 exerror(
"illegal start index in substr(%s,%lld)",
s.string, i.
integer);
994 if (exnode->
data.string.repl) {
995 l =
eval(ex, exnode->
data.string.repl, env);
997 exerror(
"illegal length in substr(%s,%lld,%lld)",
1003 if (exnode->
data.string.repl) {
1019 if (ex->disc->convertf(tmp,
type, 0)) {
1020 exerror(
"%s: cannot convert %s value to %s",
1033 if (ex->disc->stringof(ex, tmp, 0))
1034 exerror(
"%s: no string representation of %s value",
1061 if (!exnode || ex->loopcount)
1071 v =
eval(ex, x, env);
1073 ex->loopop = exnode->
op;
1081 r =
getdyn(ex, x, env, &assoc);
1139 if (exnode->subop ==
PRE)
1143 return getdyn(ex, exnode, env, &assoc);
1145 return exsplit(ex, exnode, env);
1149 return exsub(ex, exnode, env,
true);
1151 return exsub(ex, exnode, env,
false);
1159 seed = (long)time(0);
1166 v =
eval(ex, x, env);
1167 if (ex->disc->exitf)
1168 ex->disc->exitf(env, (
int)v.
integer);
1173 v =
eval(ex, x, env);
1185 r =
eval(ex, x, env);
1194 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1205 v =
eval(ex, x, env);
1222 if ((*t)->integer == v.
integer)
1245 if (ex->loopcount > 0)
1254 r =
eval(ex, a, env);
1255 if (ex->loopcount > 0)
1272 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1288 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1300 for (assoc =
dtlast(exnode->
data.generate.array->
1301 data.variable.symbol->local); assoc;
1310 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE)) {
1322 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE)) {
1345 x = exnode->
data.call.args;
1351 args[n++] =
eval(ex, x->data.operand.left, env);
1355 x = x->data.operand.right;
1357 for (n = 0, a = exnode->
data.call.procedure->
value->data.procedure.args;
1361 exerror(
"too many actual args");
1363 exerror(
"not enough actual args");
1364 v =
exeval(ex, exnode->
data.call.procedure->
value->data.procedure.body, env);
1365 for (n = 0, a = exnode->
data.call.procedure->
value->data.procedure.args;
1372 x = x->data.operand.right)
1373 args[n++] =
eval(ex, x->data.operand.left, env);
1382 x = x->data.operand.right)
1383 args[n++] =
eval(ex, x->data.operand.left, env);
1410 ex->loopret =
eval(ex, x, env);
1411 ex->loopcount = 32767;
1412 ex->loopop = exnode->
op;
1419 FILE *buffer = tmpfile();
1420 if (buffer ==
NULL) {
1421 fprintf(stderr,
"out of memory\n");
1424 print(ex, exnode, env, buffer);
1425 const size_t size =
gv_ftell(buffer);
1431 if (fread(v.
string, size, 1, buffer) < 1) {
1432 fprintf(stderr,
"failed to read back temporary file\n");
1442 if (exnode->subop !=
'=')
1446 v =
getdyn(ex, x, env, &assoc);
1449 if (x->data.variable.index)
1450 v =
eval(ex, x->data.variable.index, env);
1453 if (x->data.variable.dyna) {
1455 locv =
getdyn(ex, x->data.variable.dyna, env, &assoc);
1456 x->data.variable.dyna->data.variable.dyna->data.constant.value = locv;
1458 v = ex->disc->getf(ex, x, x->data.variable.symbol,
1459 x->data.variable.reference, env, (
int)v.
integer,
1465 switch (exnode->subop)
1478 exerror(
"floating divide by 0");
1484 exerror(
"floating 0 modulus");
1513 switch (exnode->subop)
1526 exerror(
"integer divide by 0");
1556 switch (exnode->subop)
1585 getdyn(ex, x, env, &assoc);
1592 v =
eval(ex, x, env);
1599 return exnode ?
eval(ex, exnode, env) : v;
1601 v =
eval(ex, x, env);
1604 v =
eval(ex, x, env);
1607 v =
eval(ex, x, env);
1610 v =
eval(ex, x, env);
1612 r =
eval(ex, x, env);
1618 if (!ex->disc->binaryf(&tmp, exnode, &rtmp, 0))
1637 else if (ex->disc->convertf(&tmp,
STRING, 0)) {
1645 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1678 exerror(
"floating divide by 0");
1684 exerror(
"floating 0 modulus");
1730 xPrint(ex, exnode, v, &tmp);
1741 if (!ex->disc->binaryf(&tmp, exnode, rp, 0))
1788 else if (ex->disc->convertf(&tmp,
STRING, 0)) {
1801 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1834 exerror(
"integer divide by 0");
1879 if (ex->disc->convertf(&tmp,
FLOATING, 0))
1890 if (ex->disc->convertf(&tmp,
INTEGER, 0))
1905 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1954 char *op =
lexname(exnode->
op, exnode->subop);
1958 exerror(
"operator %s %s %s not implemented",
left, op,
1962 exerror(
"operator %s %s not implemented", op,
left);
1977 switch (exnode->
type)
1992 v =
eval(ex, exnode, env);
1993 if (ex->loopcount > 0)
1996 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 *)