60 else if (subop >
' ' && subop <=
'~')
67 else if (op >
' ' && op <=
'~')
88 if (ex->disc->inf !=
NULL) {
102 key = ex->disc->keyf(v,
type);
105 snprintf(buf,
sizeof(buf),
"%llx", (
unsigned long long)key.
integer);
131 char buf[2*
sizeof(key.
integer)+1];
146 key = ex->disc->keyf(v,
type);
149 snprintf(buf,
sizeof(buf),
"%llx", (
unsigned long long)key.
integer);
155 const size_t keyname_len = strlen(keyname);
157 memcpy(b->
name, keyname, keyname_len + 1);
210 exerror(
"printf: not enough arguments");
214 const long from =
node->type;
243 node->data.operand.left = 0;
267 fmt->
fmt.
size =
sizeof(double);
271 dp->
size =
sizeof(
long long);
292 dp->
flags &= ~SFFMT_LONG;
308 *
s = (
char)tolower(*
s);
310 *
s = (char)toupper(*
s);
332 if ((tm = *(
long long *)vp) == -1)
335 exerror(
"printf: no time format provided");
338 stm = localtime(&tm);
342 exerror(
"printf: out of memory");
385 v =
eval(ex, exnode->
data.print.descriptor, env);
394 memset(&fmt, 0,
sizeof(fmt));
398 x = exnode->
data.print.args;
410 }
while ((x = x->
next));
435 exerror(
"scanf: not enough arguments");
445 exerror(
"scanf: %s: floating variable address argument expected",
node->data.variable.symbol->name);
448 fmt->
fmt.
size =
sizeof(double);
449 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
450 memcpy(vp, &value,
sizeof(value));
457 exerror(
"scanf: %s: string variable address argument expected",
node->data.variable.symbol->name);
461 node->data.variable.symbol->value->data.constant.value.string = 0;
463 char *
s =
node->data.variable.symbol->value->data.constant.value.string;
466 memcpy(vp, &
s,
sizeof(
s));
467 node->data.variable.symbol->value->data.constant.value.string =
s;
472 exerror(
"scanf: %s: char variable address argument expected",
node->data.variable.symbol->name);
475 fmt->
fmt.
size =
sizeof(
long long);
476 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
477 memcpy(vp, &value,
sizeof(value));
483 exerror(
"scanf: %s: integer variable address argument expected",
node->data.variable.symbol->name);
486 dp->
size =
sizeof(
long long);
487 const void *
const value = &
node->data.variable.symbol->value->data.constant.value;
488 memcpy(vp, &value,
sizeof(value));
509 if (exnode->
data.scan.descriptor)
511 v =
eval(ex, exnode->
data.scan.descriptor, env);
512 if (exnode->
data.scan.descriptor->type ==
STRING)
524 memset(&fmt, 0,
sizeof(fmt));
528 u =
eval(ex, exnode->
data.scan.format, env);
534 exerror(
"scanf: failed to open temporary file");
556 size_t sz = strlen(l) + strlen(r) + 1;
558 snprintf(
s, sz,
"%s%s", l, r);
570 for (
const char *p = l; *p !=
'\0'; ++p) {
571 if (strchr(p + 1, *p) ==
NULL) {
575 for (
const char *p = r; *p !=
'\0'; ++p) {
576 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
586 for (
const char *p = l; *p !=
'\0'; ++p) {
587 if (strchr(p + 1, *p) ==
NULL) {
588 assert(i <
len &&
"incorrect preceding length computation");
593 for (
const char *p = r; *p !=
'\0'; ++p) {
594 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
595 assert(i <
len &&
"incorrect preceding length computation");
600 assert(i + 1 ==
len &&
"incorrect preceding length computation");
613 for (
const char *p = l; *p !=
'\0'; ++p) {
614 if (strchr(r, *p) !=
NULL && strchr(p + 1, *p) ==
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");
644 for (
const char *p = l; *p !=
'\0'; ++p) {
645 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
649 for (
const char *p = r; *p !=
'\0'; ++p) {
650 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
660 for (
const char *p = l; *p !=
'\0'; ++p) {
661 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
662 assert(i <
len &&
"incorrect preceding length computation");
667 for (
const char *p = r; *p !=
'\0'; ++p) {
668 if (strchr(l, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
669 assert(i <
len &&
"incorrect preceding length computation");
674 assert(i + 1 ==
len &&
"incorrect preceding length computation");
687 for (
const char *p = l; *p !=
'\0'; ++p) {
688 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
698 for (
const char *p = l; *p !=
'\0'; ++p) {
699 if (strchr(r, *p) ==
NULL && strchr(p + 1, *p) ==
NULL) {
700 assert(i <
len &&
"incorrect preceding length computation");
705 assert(i + 1 ==
len &&
"incorrect preceding length computation");
717 size_t len = strlen(l);
719 size_t len2 = strlen(r);
731 for (; l[i] !=
'\0' && r[i] !=
'\0'; ++i) {
732 assert(i <
len &&
"incorrect preceding length computation");
733 result[i] = l[i] == r[i] ? l[i] :
' ';
735 assert(i + 1 ==
len &&
"incorrect preceding length computation");
748 while ((c = *repl++)) {
753 const size_t offset =
sub[2 * idx];
787 Dt_t* arr = exnode->
data.split.array->local;
790 if (exnode->
data.split.seps)
797 sz = strspn (
str, seps);
803 for (
size_t i = 1; i < sz; i++) {
814 sz = strcspn (
str, seps);
835 Dt_t* arr = exnode->
data.split.array->local;
838 if (exnode->
data.split.seps)
845 sz = strspn (
str, seps);
850 sz = strcspn (
str, seps);
878 if (exnode->
data.string.repl)
894 if (p > pat && p[-1] ==
'\\') {
914 exwarn(
"pattern match of empty string - ill-specified pattern \"%s\"?", pat);
954 s =
eval(ex, exnode->
data.string.base, env);
955 const size_t len = strlen(
s.string);
956 i =
eval(ex, exnode->
data.string.pat, env);
958 exerror(
"illegal start index in substr(%s,%lld)",
s.string, i.
integer);
959 if (exnode->
data.string.repl) {
960 l =
eval(ex, exnode->
data.string.repl, env);
963 exerror(
"illegal length in substr(%s,%lld,%lld)",
969 if (exnode->
data.string.repl) {
984 if (ex->disc->convertf(tmp,
type, 0)) {
985 exerror(
"%s: cannot convert %s value to %s",
998 if (ex->disc->stringof(ex, tmp, 0))
999 exerror(
"%s: no string representation of %s value",
1026 if (!exnode || ex->loopcount)
1036 v =
eval(ex, x, env);
1038 ex->loopop = exnode->
op;
1046 r =
getdyn(ex, x, env, &assoc);
1099 if (exnode->subop ==
PRE)
1103 return getdyn(ex, exnode, env, &assoc);
1105 return exsplit(ex, exnode, env);
1109 return exsub(ex, exnode, env,
true);
1111 return exsub(ex, exnode, env,
false);
1119 seed = (long)time(0);
1126 v =
eval(ex, x, env);
1127 if (ex->disc->exitf)
1128 ex->disc->exitf(env, (
int)v.
integer);
1133 v =
eval(ex, x, env);
1145 r =
eval(ex, x, env);
1154 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1165 v =
eval(ex, x, env);
1182 if ((*t)->integer == v.
integer)
1205 if (ex->loopcount > 0)
1214 r =
eval(ex, a, env);
1215 if (ex->loopcount > 0)
1232 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1248 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE))
1260 for (assoc =
dtlast(exnode->
data.generate.array->
1270 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE)) {
1282 if (ex->loopcount > 0 && (--ex->loopcount > 0 || ex->loopop !=
CONTINUE)) {
1291 if (ex->disc->lengthf !=
NULL) {
1314 x = exnode->
data.call.args;
1320 args[n++] =
eval(ex, x->data.operand.left, env);
1324 x = x->data.operand.right;
1326 for (n = 0, a = exnode->
data.call.procedure->
value->data.procedure.args;
1330 exerror(
"too many actual args");
1332 exerror(
"not enough actual args");
1333 v =
exeval(ex, exnode->
data.call.procedure->
value->data.procedure.body, env);
1334 for (n = 0, a = exnode->
data.call.procedure->
value->data.procedure.args;
1341 x = x->data.operand.right)
1342 args[n++] =
eval(ex, x->data.operand.left, env);
1351 x = x->data.operand.right)
1352 args[n++] =
eval(ex, x->data.operand.left, env);
1379 ex->loopret =
eval(ex, x, env);
1380 ex->loopcount = 32767;
1381 ex->loopop = exnode->
op;
1388 FILE *buffer = tmpfile();
1389 if (buffer ==
NULL) {
1390 fprintf(stderr,
"out of memory\n");
1393 print(ex, exnode, env, buffer);
1394 const size_t size =
gv_ftell(buffer);
1397 if (fread(v.
string, size, 1, buffer) < 1) {
1398 fprintf(stderr,
"failed to read back temporary file\n");
1406 if (exnode->subop !=
'=')
1410 v =
getdyn(ex, x, env, &assoc);
1413 if (x->data.variable.index)
1414 v =
eval(ex, x->data.variable.index, env);
1417 if (x->data.variable.dyna) {
1419 locv =
getdyn(ex, x->data.variable.dyna, env, &assoc);
1420 x->data.variable.dyna->data.variable.dyna->data.constant.value = locv;
1422 v = ex->disc->getf(ex, x, x->data.variable.symbol,
1423 x->data.variable.reference, env, (
int)v.
integer,
1429 switch (exnode->subop)
1442 exerror(
"floating divide by 0");
1448 exerror(
"floating 0 modulus");
1477 switch (exnode->subop)
1490 exerror(
"integer divide by 0");
1520 switch (exnode->subop)
1549 getdyn(ex, x, env, &assoc);
1556 v =
eval(ex, x, env);
1563 return exnode ?
eval(ex, exnode, env) : v;
1565 v =
eval(ex, x, env);
1568 v =
eval(ex, x, env);
1571 v =
eval(ex, x, env);
1574 v =
eval(ex, x, env);
1576 r =
eval(ex, x, env);
1582 if (!ex->disc->binaryf(&tmp, exnode, &rtmp, 0))
1601 else if (ex->disc->convertf(&tmp,
STRING, 0)) {
1609 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1642 exerror(
"floating divide by 0");
1648 exerror(
"floating 0 modulus");
1694 xPrint(ex, exnode, v, &tmp);
1705 if (!ex->disc->binaryf(&tmp, exnode, rp, 0))
1752 else if (ex->disc->convertf(&tmp,
STRING, 0)) {
1765 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1798 exerror(
"integer divide by 0");
1843 if (ex->disc->convertf(&tmp,
FLOATING, 0))
1854 if (ex->disc->convertf(&tmp,
INTEGER, 0))
1869 if (ex->disc->convertf(&tmp, exnode->
type, 0))
1918 char *op =
lexname(exnode->
op, exnode->subop);
1922 exerror(
"operator %s %s %s not implemented",
left, op,
1926 exerror(
"operator %s %s not implemented", op,
left);
1941 switch (exnode->
type)
1956 v =
eval(ex, exnode, env);
1957 if (ex->loopcount > 0)
1960 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 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::@65 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::@63 select
struct Exdata_u::@61 constant
struct Exdata_u::@62 operand
struct Exdata_u::@64 variable