62 else if (subop >
' ' && subop <=
'~')
69 else if (op >
' ' && op <=
'~')
90 if (ex->disc->inf !=
NULL) {
104 key = ex->disc->keyf(v,
type);
107 snprintf(buf,
sizeof(buf),
"%llx", (
unsigned long long)key.
integer);
133 char buf[2*
sizeof(key.
integer)+1];
148 key = ex->disc->keyf(v,
type);
151 snprintf(buf,
sizeof(buf),
"%llx", (
unsigned long long)key.
integer);
157 const size_t keyname_len = strlen(keyname);
159 memcpy(b->
name, keyname, keyname_len + 1);
212 exerror(
"printf: not enough arguments");
216 const long from =
node->type;
245 node->data.operand.left = 0;
269 fmt->
fmt.
size =
sizeof(double);
273 dp->
size =
sizeof(
long long);
294 dp->
flags &= ~SFFMT_LONG;
310 *
s = (
char)tolower(*
s);
312 *
s = (char)toupper(*
s);
334 if ((tm = *(
long long *)vp) == -1)
337 exerror(
"printf: no time format provided");
340 stm = localtime(&tm);
344 exerror(
"printf: out of memory");
387 v =
eval(ex, exnode->
data.print.descriptor, env);
396 memset(&fmt, 0,
sizeof(fmt));
400 x = exnode->
data.print.args;
412 }
while ((x = x->
next));
437 exerror(
"scanf: not enough arguments");
447 exerror(
"scanf: %s: floating variable address argument expected",
node->data.variable.symbol->name);
450 fmt->
fmt.
size =
sizeof(double);
451 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
452 memcpy(vp, &value,
sizeof(value));
459 exerror(
"scanf: %s: string variable address argument expected",
node->data.variable.symbol->name);
463 node->data.variable.symbol->value->data.constant.value.string = 0;
465 char *
s =
node->data.variable.symbol->value->data.constant.value.string;
468 memcpy(vp, &
s,
sizeof(
s));
469 node->data.variable.symbol->value->data.constant.value.string =
s;
474 exerror(
"scanf: %s: char variable address argument expected",
node->data.variable.symbol->name);
477 fmt->
fmt.
size =
sizeof(
long long);
478 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
479 memcpy(vp, &value,
sizeof(value));
485 exerror(
"scanf: %s: integer variable address argument expected",
node->data.variable.symbol->name);
488 dp->
size =
sizeof(
long long);
489 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
490 memcpy(vp, &value,
sizeof(value));
511 if (exnode->
data.scan.descriptor)
513 v =
eval(ex, exnode->
data.scan.descriptor, env);
514 if (exnode->
data.scan.descriptor->type ==
STRING)
526 memset(&fmt, 0,
sizeof(fmt));
530 u =
eval(ex, exnode->
data.scan.format, env);
536 exerror(
"scanf: failed to open temporary file");
558 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) {
588 for (
const char *p = l; *p !=
'\0'; ++p) {
589 if (strchr(p + 1, *p) ==
NULL) {
590 assert(i <
len &&
"incorrect preceding length computation");
595 for (
const char *p = r; *p !=
'\0'; ++p) {
596 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
597 assert(i <
len &&
"incorrect preceding length computation");
602 assert(i + 1 ==
len &&
"incorrect preceding length computation");
615 for (
const char *p = l; *p !=
'\0'; ++p) {
616 if (strchr(r, *p) !=
NULL && strchr(p + 1, *p) ==
NULL) {
626 for (
const char *p = l; *p !=
'\0'; ++p) {
627 if (strchr(r, *p) !=
NULL && strchr(p + 1, *p) ==
NULL) {
628 assert(i <
len &&
"incorrect preceding length computation");
633 assert(i + 1 ==
len &&
"incorrect preceding length computation");
646 for (
const char *p = l; *p !=
'\0'; ++p) {
647 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
651 for (
const char *p = r; *p !=
'\0'; ++p) {
652 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
662 for (
const char *p = l; *p !=
'\0'; ++p) {
663 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
664 assert(i <
len &&
"incorrect preceding length computation");
669 for (
const char *p = r; *p !=
'\0'; ++p) {
670 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
671 assert(i <
len &&
"incorrect preceding length computation");
676 assert(i + 1 ==
len &&
"incorrect preceding length computation");
689 for (
const char *p = l; *p !=
'\0'; ++p) {
690 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
700 for (
const char *p = l; *p !=
'\0'; ++p) {
701 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
702 assert(i <
len &&
"incorrect preceding length computation");
707 assert(i + 1 ==
len &&
"incorrect preceding length computation");
719 size_t len = strlen(l);
721 size_t len2 = strlen(r);
733 for (; l[i] !=
'\0' && r[i] !=
'\0'; ++i) {
734 assert(i <
len &&
"incorrect preceding length computation");
735 result[i] = l[i] == r[i] ? l[i] :
' ';
737 assert(i + 1 ==
len &&
"incorrect preceding length computation");
750 while ((c = *repl++)) {
755 const size_t offset =
sub[2 * idx];
789 Dt_t* arr = exnode->
data.split.array->local;
792 if (exnode->
data.split.seps)
799 sz = strspn (
str, seps);
805 for (
size_t i = 1; i < sz; i++) {
816 sz = strcspn (
str, seps);
837 Dt_t* arr = exnode->
data.split.array->local;
840 if (exnode->
data.split.seps)
847 sz = strspn (
str, seps);
852 sz = strcspn (
str, seps);
880 if (exnode->
data.string.repl)
896 if (p > pat && p[-1] ==
'\\') {
916 exwarn(
"pattern match of empty string - ill-specified pattern \"%s\"?", pat);
956 s =
eval(ex, exnode->
data.string.base, env);
957 const size_t len = strlen(
s.string);
958 i =
eval(ex, exnode->
data.string.pat, env);
960 exerror(
"illegal start index in substr(%s,%lld)",
s.string, i.
integer);
961 if (exnode->
data.string.repl) {
962 l =
eval(ex, exnode->
data.string.repl, env);
965 exerror(
"illegal length in substr(%s,%lld,%lld)",
971 if (exnode->
data.string.repl) {
986 if (ex->disc->convertf(tmp,
type, 0)) {
987 exerror(
"%s: cannot convert %s value to %s",
1000 if (ex->disc->stringof(ex, tmp, 0))
1001 exerror(
"%s: no string representation of %s value",
1028 if (!exnode || ex->loopcount)
1038 v =
eval(ex, x, env);
1040 ex->loopop = exnode->
op;
1048 r =
getdyn(ex, x, env, &assoc);
1101 if (exnode->subop ==
PRE)
1105 return getdyn(ex, exnode, env, &assoc);
1107 return exsplit(ex, exnode, env);
1111 return exsub(ex, exnode, env,
true);
1113 return exsub(ex, exnode, env,
false);
1121 seed = (long)time(0);
1128 v =
eval(ex, x, env);
1129 if (ex->disc->exitf)
1130 ex->disc->exitf(env, (
int)v.
integer);
1135 v =
eval(ex, x, env);
1147 r =
eval(ex, x, env);
1156 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1167 v =
eval(ex, x, env);
1184 if ((*t)->integer == v.
integer)
1207 if (ex->loopcount > 0)
1216 r =
eval(ex, a, env);
1217 if (ex->loopcount > 0)
1234 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1250 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1262 for (assoc =
dtlast(exnode->
data.generate.array->
1272 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE)) {
1284 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE)) {
1293 if (ex->disc->lengthf !=
NULL) {
1316 x = exnode->
data.call.args;
1322 args[n++] =
eval(ex, x->data.operand.left, env);
1326 x = x->data.operand.right;
1328 for (n = 0, a = exnode->
data.call.procedure->
value->data.procedure.args;
1332 exerror(
"too many actual args");
1334 exerror(
"not enough actual args");
1335 v =
exeval(ex, exnode->
data.call.procedure->
value->data.procedure.body, env);
1336 for (n = 0, a = exnode->
data.call.procedure->
value->data.procedure.args;
1343 x = x->data.operand.right)
1344 args[n++] =
eval(ex, x->data.operand.left, env);
1353 x = x->data.operand.right)
1354 args[n++] =
eval(ex, x->data.operand.left, env);
1381 ex->loopret =
eval(ex, x, env);
1382 ex->loopcount = 32767;
1383 ex->loopop = exnode->
op;
1390 FILE *buffer = tmpfile();
1391 if (buffer ==
NULL) {
1392 fprintf(stderr,
"out of memory\n");
1395 print(ex, exnode, env, buffer);
1396 const int64_t size =
gv_ftell(buffer);
1399 fprintf(stderr,
"failed to read back temporary file\n");
1404 if (fread(v.
string, (
size_t)size, 1, buffer) < 1) {
1405 fprintf(stderr,
"failed to read back temporary file\n");
1413 if (exnode->subop !=
'=')
1417 v =
getdyn(ex, x, env, &assoc);
1420 if (x->data.variable.index)
1421 v =
eval(ex, x->data.variable.index, env);
1424 if (x->data.variable.dyna) {
1426 locv =
getdyn(ex, x->data.variable.dyna, env, &assoc);
1427 x->data.variable.dyna->data.variable.dyna->data.constant.value = locv;
1429 v = ex->disc->getf(ex, x, x->data.variable.symbol,
1430 x->data.variable.reference, env, (
int)v.
integer,
1436 switch (exnode->subop)
1449 exerror(
"floating divide by 0");
1454 const double rounded = round(r.
floating);
1455 if (LLONG_MAX < (INT64_C(1) << 53) &&
1456 (rounded > (
double)LLONG_MAX || rounded < (
double)LLONG_MIN)) {
1457 exerror(
"floating modulus out of range");
1459 if ((
long long)rounded == 0)
1460 exerror(
"floating 0 modulus");
1490 switch (exnode->subop)
1503 exerror(
"integer divide by 0");
1533 switch (exnode->subop)
1562 getdyn(ex, x, env, &assoc);
1569 v =
eval(ex, x, env);
1576 return exnode ?
eval(ex, exnode, env) : v;
1578 v =
eval(ex, x, env);
1581 v =
eval(ex, x, env);
1584 v =
eval(ex, x, env);
1587 v =
eval(ex, x, env);
1589 r =
eval(ex, x, env);
1595 if (!ex->disc->binaryf(&tmp, exnode, &rtmp, 0))
1614 else if (ex->disc->convertf(&tmp,
STRING, 0)) {
1622 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1655 exerror(
"floating divide by 0");
1661 exerror(
"floating 0 modulus");
1707 xPrint(ex, exnode, v, &tmp);
1718 if (!ex->disc->binaryf(&tmp, exnode, rp, 0))
1765 else if (ex->disc->convertf(&tmp,
STRING, 0)) {
1778 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1811 exerror(
"integer divide by 0");
1856 if (ex->disc->convertf(&tmp,
FLOATING, 0))
1867 if (ex->disc->convertf(&tmp,
INTEGER, 0))
1882 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1931 char *op =
lexname(exnode->
op, exnode->subop);
1935 exerror(
"operator %s %s %s not implemented",
left, op,
1939 exerror(
"operator %s %s not implemented", op,
left);
1951 if (ex->loopcount > 0)
1954 if (ex->loopop ==
RETURN)
Agobj_t * copy(Agraph_t *g, Agobj_t *obj)
Dynamically expanding string buffers.
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)
void * gv_arena_alloc(arena_t *arena, size_t alignment, size_t size)
char * gv_arena_strdup(arena_t *arena, const char *s)
void gv_arena_free(arena_t *arena, void *ptr, size_t size)
Region-based memory allocator.
#define ARENA_NEW(arena, type)
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(arena_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 int64_t gv_ftell(FILE *stream)
ftell, accounting for platform limitations
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
bool binary
data.operand.{left,right} ok
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::@63 select
struct Exdata_u::@61 constant
struct Exdata_u::@62 operand
struct Exdata_u::@64 variable