58 else if (subop >
' ' && subop <=
'~')
65 else if (op >
' ' && op <=
'~')
86 if (ex->disc->inf !=
NULL) {
100 key = ex->disc->keyf(v,
type);
103 snprintf(buf,
sizeof(buf),
"%llx", (
unsigned long long)key.
integer);
129 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);
154 strcpy(b->
name, keyname);
207 exerror(
"printf: not enough arguments");
211 const long from =
node->type;
240 node->data.operand.left = 0;
264 fmt->
fmt.
size =
sizeof(double);
268 dp->
size =
sizeof(
long long);
289 dp->
flags &= ~SFFMT_LONG;
305 *
s = (
char)tolower(*
s);
307 *
s = (char)toupper(*
s);
329 if ((tm = *(
long long *)vp) == -1)
332 exerror(
"printf: no time format provided");
335 stm = localtime(&tm);
339 exerror(
"printf: out of memory");
382 v =
eval(ex, exnode->
data.print.descriptor, env);
391 memset(&fmt, 0,
sizeof(fmt));
395 x = exnode->
data.print.args;
407 }
while ((x = x->
next));
432 exerror(
"scanf: not enough arguments");
442 exerror(
"scanf: %s: floating variable address argument expected",
node->data.variable.symbol->name);
445 fmt->
fmt.
size =
sizeof(double);
446 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
447 memcpy(vp, &value,
sizeof(value));
454 exerror(
"scanf: %s: string variable address argument expected",
node->data.variable.symbol->name);
458 node->data.variable.symbol->value->data.constant.value.string = 0;
460 char *
s =
node->data.variable.symbol->value->data.constant.value.string;
463 memcpy(vp, &
s,
sizeof(
s));
464 node->data.variable.symbol->value->data.constant.value.string =
s;
469 exerror(
"scanf: %s: char variable address argument expected",
node->data.variable.symbol->name);
472 fmt->
fmt.
size =
sizeof(
long long);
473 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
474 memcpy(vp, &value,
sizeof(value));
480 exerror(
"scanf: %s: integer variable address argument expected",
node->data.variable.symbol->name);
483 dp->
size =
sizeof(
long long);
484 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
485 memcpy(vp, &value,
sizeof(value));
506 if (exnode->
data.scan.descriptor)
508 v =
eval(ex, exnode->
data.scan.descriptor, env);
509 if (exnode->
data.scan.descriptor->type ==
STRING)
521 memset(&fmt, 0,
sizeof(fmt));
525 u =
eval(ex, exnode->
data.scan.format, env);
531 exerror(
"scanf: failed to open temporary file");
553 size_t sz = strlen(l) + strlen(r) + 1;
555 snprintf(
s, sz,
"%s%s", l, r);
567 for (
const char *p = l; *p !=
'\0'; ++p) {
568 if (strchr(p + 1, *p) ==
NULL) {
572 for (
const char *p = r; *p !=
'\0'; ++p) {
573 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
583 for (
const char *p = l; *p !=
'\0'; ++p) {
584 if (strchr(p + 1, *p) ==
NULL) {
585 assert(i <
len &&
"incorrect preceding length computation");
590 for (
const char *p = r; *p !=
'\0'; ++p) {
591 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
592 assert(i <
len &&
"incorrect preceding length computation");
597 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) {
621 for (
const char *p = l; *p !=
'\0'; ++p) {
622 if (strchr(r, *p) !=
NULL && strchr(p + 1, *p) ==
NULL) {
623 assert(i <
len &&
"incorrect preceding length computation");
628 assert(i + 1 ==
len &&
"incorrect preceding length computation");
641 for (
const char *p = l; *p !=
'\0'; ++p) {
642 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
646 for (
const char *p = r; *p !=
'\0'; ++p) {
647 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
657 for (
const char *p = l; *p !=
'\0'; ++p) {
658 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
659 assert(i <
len &&
"incorrect preceding length computation");
664 for (
const char *p = r; *p !=
'\0'; ++p) {
665 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
666 assert(i <
len &&
"incorrect preceding length computation");
671 assert(i + 1 ==
len &&
"incorrect preceding length computation");
684 for (
const char *p = l; *p !=
'\0'; ++p) {
685 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
695 for (
const char *p = l; *p !=
'\0'; ++p) {
696 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
697 assert(i <
len &&
"incorrect preceding length computation");
702 assert(i + 1 ==
len &&
"incorrect preceding length computation");
714 size_t len = strlen(l);
716 size_t len2 = strlen(r);
728 for (; l[i] !=
'\0' && r[i] !=
'\0'; ++i) {
729 assert(i <
len &&
"incorrect preceding length computation");
730 result[i] = l[i] == r[i] ? l[i] :
' ';
732 assert(i + 1 ==
len &&
"incorrect preceding length computation");
745 while ((c = *repl++)) {
750 const size_t offset =
sub[2 * idx];
784 Dt_t* arr = exnode->
data.split.array->local;
787 if (exnode->
data.split.seps)
794 sz = strspn (
str, seps);
800 for (
size_t i = 1; i < sz; i++) {
811 sz = strcspn (
str, seps);
832 Dt_t* arr = exnode->
data.split.array->local;
835 if (exnode->
data.split.seps)
842 sz = strspn (
str, seps);
847 sz = strcspn (
str, seps);
875 if (exnode->
data.string.repl)
891 if (p > pat && p[-1] ==
'\\') {
911 exwarn(
"pattern match of empty string - ill-specified pattern \"%s\"?", pat);
952 s =
eval(ex, exnode->
data.string.base, env);
953 len = strlen(
s.string);
954 i =
eval(ex, exnode->
data.string.pat, env);
956 exerror(
"illegal start index in substr(%s,%lld)",
s.string, i.
integer);
957 if (exnode->
data.string.repl) {
958 l =
eval(ex, exnode->
data.string.repl, env);
960 exerror(
"illegal length in substr(%s,%lld,%lld)",
966 if (exnode->
data.string.repl) {
981 if (ex->disc->convertf(tmp,
type, 0)) {
982 exerror(
"%s: cannot convert %s value to %s",
995 if (ex->disc->stringof(ex, tmp, 0))
996 exerror(
"%s: no string representation of %s value",
1023 if (!exnode || ex->loopcount)
1033 v =
eval(ex, x, env);
1035 ex->loopop = exnode->
op;
1043 r =
getdyn(ex, x, env, &assoc);
1098 if (exnode->subop ==
PRE)
1102 return getdyn(ex, exnode, env, &assoc);
1104 return exsplit(ex, exnode, env);
1108 return exsub(ex, exnode, env,
true);
1110 return exsub(ex, exnode, env,
false);
1118 seed = (long)time(0);
1125 v =
eval(ex, x, env);
1126 if (ex->disc->exitf)
1127 ex->disc->exitf(env, (
int)v.
integer);
1132 v =
eval(ex, x, env);
1144 r =
eval(ex, x, env);
1153 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1164 v =
eval(ex, x, env);
1181 if ((*t)->integer == v.
integer)
1204 if (ex->loopcount > 0)
1213 r =
eval(ex, a, env);
1214 if (ex->loopcount > 0)
1231 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1247 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1259 for (assoc =
dtlast(exnode->
data.generate.array->
1260 data.variable.symbol->local); assoc;
1269 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE)) {
1281 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE)) {
1290 if (ex->disc->lengthf !=
NULL) {
1313 x = exnode->
data.call.args;
1319 args[n++] =
eval(ex, x->data.operand.left, env);
1323 x = x->data.operand.right;
1325 for (n = 0, a = exnode->
data.call.procedure->
value->data.procedure.args;
1329 exerror(
"too many actual args");
1331 exerror(
"not enough actual args");
1332 v =
exeval(ex, exnode->
data.call.procedure->
value->data.procedure.body, env);
1333 for (n = 0, a = exnode->
data.call.procedure->
value->data.procedure.args;
1340 x = x->data.operand.right)
1341 args[n++] =
eval(ex, x->data.operand.left, env);
1350 x = x->data.operand.right)
1351 args[n++] =
eval(ex, x->data.operand.left, env);
1378 ex->loopret =
eval(ex, x, env);
1379 ex->loopcount = 32767;
1380 ex->loopop = exnode->
op;
1387 FILE *buffer = tmpfile();
1388 if (buffer ==
NULL) {
1389 fprintf(stderr,
"out of memory\n");
1392 print(ex, exnode, env, buffer);
1393 const size_t size =
gv_ftell(buffer);
1396 if (fread(v.
string, size, 1, buffer) < 1) {
1397 fprintf(stderr,
"failed to read back temporary file\n");
1405 if (exnode->subop !=
'=')
1409 v =
getdyn(ex, x, env, &assoc);
1412 if (x->data.variable.index)
1413 v =
eval(ex, x->data.variable.index, env);
1416 if (x->data.variable.dyna) {
1418 locv =
getdyn(ex, x->data.variable.dyna, env, &assoc);
1419 x->data.variable.dyna->data.variable.dyna->data.constant.value = locv;
1421 v = ex->disc->getf(ex, x, x->data.variable.symbol,
1422 x->data.variable.reference, env, (
int)v.
integer,
1428 switch (exnode->subop)
1441 exerror(
"floating divide by 0");
1447 exerror(
"floating 0 modulus");
1476 switch (exnode->subop)
1489 exerror(
"integer divide by 0");
1519 switch (exnode->subop)
1548 getdyn(ex, x, env, &assoc);
1555 v =
eval(ex, x, env);
1562 return exnode ?
eval(ex, exnode, env) : v;
1564 v =
eval(ex, x, env);
1567 v =
eval(ex, x, env);
1570 v =
eval(ex, x, env);
1573 v =
eval(ex, x, env);
1575 r =
eval(ex, x, env);
1581 if (!ex->disc->binaryf(&tmp, exnode, &rtmp, 0))
1600 else if (ex->disc->convertf(&tmp,
STRING, 0)) {
1608 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1641 exerror(
"floating divide by 0");
1647 exerror(
"floating 0 modulus");
1693 xPrint(ex, exnode, v, &tmp);
1704 if (!ex->disc->binaryf(&tmp, exnode, rp, 0))
1751 else if (ex->disc->convertf(&tmp,
STRING, 0)) {
1764 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1797 exerror(
"integer divide by 0");
1842 if (ex->disc->convertf(&tmp,
FLOATING, 0))
1853 if (ex->disc->convertf(&tmp,
INTEGER, 0))
1868 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1917 char *op =
lexname(exnode->
op, exnode->subop);
1921 exerror(
"operator %s %s %s not implemented",
left, op,
1925 exerror(
"operator %s %s not implemented", op,
left);
1940 switch (exnode->
type)
1955 v =
eval(ex, exnode, env);
1956 if (ex->loopcount > 0)
1959 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)
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 size_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
union Exnode_s::@96 compiled
long long(* integer)(char **)
INTEGER|UNSIGNED return value.
char *(* string)(char **)
double(* floating)(char **)
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::@94 select
struct Exdata_u::@93 operand
struct Exdata_u::@95 variable
struct Exdata_u::@92 constant