54 else if (subop >
' ' && subop <=
'~')
61 else if (op >
' ' && op <=
'~')
90 key = ex->disc->keyf(v,
type);
93 snprintf(buf,
sizeof(buf),
"%llx", (
unsigned long long)key.
integer);
120 char buf[2*
sizeof(key.
integer)+1];
136 key = ex->disc->keyf(v,
type);
139 snprintf(buf,
sizeof(buf),
"%llx", (
unsigned long long)key.
integer);
145 if (!(b = calloc(1,
sizeof(
Exassoc_t) + strlen(keyname))))
147 strcpy(b->
name, keyname);
200 exerror(
"printf: not enough arguments");
204 const long from =
node->type;
233 node->data.operand.left = 0;
241 exerror(
"printf: out of memory");
259 fmt->
fmt.
size =
sizeof(double);
263 dp->
size =
sizeof(
long long);
279 if (*(
char**)vp ==
NULL) {
280 exerror(
"printf: out of memory");
287 dp->
flags &= ~SFFMT_LONG;
303 *
s = (
char)tolower(*
s);
305 *
s = (char)toupper(*
s);
327 if ((tm = *(
long long *)vp) == -1)
330 exerror(
"printf: no time format provided");
333 stm = localtime(&tm);
337 exerror(
"printf: out of memory");
380 v =
eval(ex, exnode->
data.print.descriptor, env);
389 memset(&fmt, 0,
sizeof(fmt));
393 x = exnode->
data.print.args;
405 }
while ((x = x->
next));
430 exerror(
"scanf: not enough arguments");
440 exerror(
"scanf: %s: floating variable address argument expected",
node->data.variable.symbol->name);
443 fmt->
fmt.
size =
sizeof(double);
444 *(
void**)vp = &
node->data.variable.symbol->value->data.constant.value;
450 exerror(
"scanf: %s: string variable address argument expected",
node->data.variable.symbol->name);
454 node->data.variable.symbol->value->data.constant.value.string = 0;
456 char *
s =
node->data.variable.symbol->value->data.constant.value.string;
459 memset(
s, 0,
sizeof(
char) * (
size_t)fmt->
fmt.
size);
461 node->data.variable.symbol->value->data.constant.value.string =
s;
466 exerror(
"scanf: %s: char variable address argument expected",
node->data.variable.symbol->name);
469 fmt->
fmt.
size =
sizeof(
long long);
470 *((
void **) vp) = &
node->data.variable.symbol->value->data.constant.value;
475 exerror(
"scanf: %s: integer variable address argument expected",
node->data.variable.symbol->name);
478 dp->
size =
sizeof(
long long);
479 *(
void**)vp = &
node->data.variable.symbol->value->data.constant.value;
499 if (exnode->
data.scan.descriptor)
501 v =
eval(ex, exnode->
data.scan.descriptor, env);
502 if (exnode->
data.scan.descriptor->type ==
STRING)
514 memset(&fmt, 0,
sizeof(fmt));
518 u =
eval(ex, exnode->
data.scan.format, env);
524 exerror(
"scanf: failed to open temporary file");
546 size_t sz = strlen(l) + strlen(r) + 1;
551 snprintf(
s, sz,
"%s%s", l, r);
563 for (
const char *p = l; *p !=
'\0'; ++p) {
564 if (strchr(p + 1, *p) ==
NULL) {
568 for (
const char *p = r; *p !=
'\0'; ++p) {
569 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
576 if (result ==
NULL) {
582 for (
const char *p = l; *p !=
'\0'; ++p) {
583 if (strchr(p + 1, *p) ==
NULL) {
584 assert(i <
len &&
"incorrect preceding length computation");
589 for (
const char *p = r; *p !=
'\0'; ++p) {
590 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
591 assert(i <
len &&
"incorrect preceding length computation");
596 assert(i + 1 ==
len &&
"incorrect preceding length computation");
610 for (
const char *p = l; *p !=
'\0'; ++p) {
611 if (strchr(r, *p) !=
NULL && strchr(p + 1, *p) ==
NULL) {
618 if (result ==
NULL) {
624 for (
const char *p = l; *p !=
'\0'; ++p) {
625 if (strchr(r, *p) !=
NULL && strchr(p + 1, *p) ==
NULL) {
626 assert(i <
len &&
"incorrect preceding length computation");
631 assert(i + 1 ==
len &&
"incorrect preceding length computation");
645 for (
const char *p = l; *p !=
'\0'; ++p) {
646 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
650 for (
const char *p = r; *p !=
'\0'; ++p) {
651 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
658 if (result ==
NULL) {
664 for (
const char *p = l; *p !=
'\0'; ++p) {
665 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
666 assert(i <
len &&
"incorrect preceding length computation");
671 for (
const char *p = r; *p !=
'\0'; ++p) {
672 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
673 assert(i <
len &&
"incorrect preceding length computation");
678 assert(i + 1 ==
len &&
"incorrect preceding length computation");
692 for (
const char *p = l; *p !=
'\0'; ++p) {
693 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
700 if (result ==
NULL) {
706 for (
const char *p = l; *p !=
'\0'; ++p) {
707 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
708 assert(i <
len &&
"incorrect preceding length computation");
713 assert(i + 1 ==
len &&
"incorrect preceding length computation");
726 size_t len = strlen(l);
728 size_t len2 = strlen(r);
737 if (result ==
NULL) {
743 for (; l[i] !=
'\0' && r[i] !=
'\0'; ++i) {
744 assert(i <
len &&
"incorrect preceding length computation");
745 result[i] = l[i] == r[i] ? l[i] :
' ';
747 assert(i + 1 ==
len &&
"incorrect preceding length computation");
761 while ((c = *repl++)) {
786 exerror(
"out of space [assoc]");
803 Dt_t* arr = exnode->
data.split.array->local;
806 if (exnode->
data.split.seps)
813 sz = strspn (
str, seps);
819 for (
size_t i = 1; i < sz; i++) {
830 sz = strcspn (
str, seps);
856 Dt_t* arr = exnode->
data.split.array->local;
859 if (exnode->
data.split.seps)
866 sz = strspn (
str, seps);
871 sz = strcspn (
str, seps);
904 if (exnode->
data.string.repl)
920 if (p > pat && p[-1] ==
'\\') {
940 exwarn(
"pattern match of empty string - ill-specified pattern \"%s\"?", pat);
981 s =
eval(ex, exnode->
data.string.base, env);
982 len = strlen(
s.string);
983 i =
eval(ex, exnode->
data.string.pat, env);
985 exerror(
"illegal start index in substr(%s,%lld)",
s.string, i.
integer);
986 if (exnode->
data.string.repl) {
987 l =
eval(ex, exnode->
data.string.repl, env);
989 exerror(
"illegal length in substr(%s,%lld,%lld)",
995 if (exnode->
data.string.repl) {
1011 if (ex->disc->convertf(tmp,
type, 0)) {
1012 exerror(
"%s: cannot convert %s value to %s",
1025 if (ex->disc->stringof(ex, tmp, 0))
1026 exerror(
"%s: no string representation of %s value",
1053 if (!exnode || ex->loopcount)
1063 v =
eval(ex, x, env);
1065 ex->loopop = exnode->
op;
1073 r =
getdyn(ex, x, env, &assoc);
1131 if (exnode->subop ==
PRE)
1135 return getdyn(ex, exnode, env, &assoc);
1137 return exsplit(ex, exnode, env);
1141 return exsub(ex, exnode, env,
true);
1143 return exsub(ex, exnode, env,
false);
1151 seed = (long)time(0);
1158 v =
eval(ex, x, env);
1159 if (ex->disc->exitf)
1160 ex->disc->exitf(env, (
int)v.
integer);
1165 v =
eval(ex, x, env);
1177 r =
eval(ex, x, env);
1186 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1197 v =
eval(ex, x, env);
1214 if ((*t)->integer == v.
integer)
1237 if (ex->loopcount > 0)
1246 r =
eval(ex, a, env);
1247 if (ex->loopcount > 0)
1264 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1280 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1292 for (assoc =
dtlast(exnode->
data.generate.array->
1293 data.variable.symbol->local); assoc;
1302 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE)) {
1314 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE)) {
1337 x = exnode->
data.call.args;
1343 args[n++] =
eval(ex, x->data.operand.left, env);
1347 x = x->data.operand.right;
1349 for (n = 0, a = exnode->
data.call.procedure->
value->data.procedure.args;
1353 exerror(
"too many actual args");
1355 exerror(
"not enough actual args");
1356 v =
exeval(ex, exnode->
data.call.procedure->
value->data.procedure.body, env);
1357 for (n = 0, a = exnode->
data.call.procedure->
value->data.procedure.args;
1364 x = x->data.operand.right)
1365 args[n++] =
eval(ex, x->data.operand.left, env);
1374 x = x->data.operand.right)
1375 args[n++] =
eval(ex, x->data.operand.left, env);
1403 ex->loopret =
eval(ex, x, env);
1404 ex->loopcount = 32767;
1405 ex->loopop = exnode->
op;
1412 FILE *buffer = tmpfile();
1413 if (buffer ==
NULL) {
1414 fprintf(stderr,
"out of memory\n");
1417 print(ex, exnode, env, buffer);
1418 size_t size = (size_t)ftell(buffer);
1424 if (fread(v.
string, size, 1, buffer) < 1) {
1425 fprintf(stderr,
"failed to read back temporary file\n");
1435 if (exnode->subop !=
'=')
1439 v =
getdyn(ex, x, env, &assoc);
1442 if (x->data.variable.index)
1443 v =
eval(ex, x->data.variable.index, env);
1446 if (x->data.variable.dyna) {
1448 locv =
getdyn(ex, x->data.variable.dyna, env, &assoc);
1449 x->data.variable.dyna->data.variable.dyna->data.constant.value = locv;
1451 v = ex->disc->getf(ex, x, x->data.variable.symbol,
1452 x->data.variable.reference, env, (
int)v.
integer,
1458 switch (exnode->subop)
1471 exerror(
"floating divide by 0");
1477 exerror(
"floating 0 modulus");
1506 switch (exnode->subop)
1519 exerror(
"integer divide by 0");
1549 switch (exnode->subop)
1578 getdyn(ex, x, env, &assoc);
1585 v =
eval(ex, x, env);
1592 return exnode ?
eval(ex, exnode, env) : v;
1594 v =
eval(ex, x, env);
1597 v =
eval(ex, x, env);
1600 v =
eval(ex, x, env);
1603 v =
eval(ex, x, env);
1605 r =
eval(ex, x, env);
1611 if (!ex->disc->binaryf(&tmp, exnode, &rtmp, 0))
1630 else if (ex->disc->convertf(&tmp,
STRING, 0)) {
1638 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1671 exerror(
"floating divide by 0");
1677 exerror(
"floating 0 modulus");
1723 xPrint(ex, exnode, v, &tmp);
1734 if (!ex->disc->binaryf(&tmp, exnode, rp, 0))
1781 else if (ex->disc->convertf(&tmp,
STRING, 0)) {
1794 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1827 exerror(
"integer divide by 0");
1872 if (ex->disc->convertf(&tmp,
FLOATING, 0))
1883 if (ex->disc->convertf(&tmp,
INTEGER, 0))
1898 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1947 char *op =
lexname(exnode->
op, exnode->subop);
1951 exerror(
"operator %s %s %s not implemented",
left, op,
1955 exerror(
"operator %s %s not implemented", op,
left);
1970 switch (exnode->
type)
1985 v =
eval(ex, exnode, env);
1986 if (ex->loopcount > 0)
1989 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(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)
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::@88 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 variable
struct Exdata_u::@84 constant
struct Exdata_u::@85 operand
struct Exdata_u::@86 select
void vmfree(Vmalloc_t *vm, void *data)
void * vmalloc(Vmalloc_t *vm, size_t size)
char * vmstrdup(Vmalloc_t *, const char *)