Node
struct Node *nnext;
struct Node *narg[1]; /* variable: actual size set by calling malloc */
#define NIL ((Node *) 0)
extern Node *winner;
extern Node *nullnode;
Node *np;
winner = (Node *)stat3(PROGRAM, beginloc, $1, endloc); }
| ppattern MATCHOP reg_expr { $$ = op3($2, NIL, $1, (Node*)makedfa($3, 0)); free($3); }
$$ = op3($2, NIL, $1, (Node*)makedfa(strnode($3), 0));
$$ = op3($2, (Node *)1, $1, $3); }
| pattern MATCHOP reg_expr { $$ = op3($2, NIL, $1, (Node*)makedfa($3, 0)); free($3); }
$$ = op3($2, NIL, $1, (Node*)makedfa(strnode($3), 0));
$$ = op3($2, (Node *)1, $1, $3); }
else $$ = op3(GETLINE, (Node*)0, itonp($2), $1); }
{ $$ = op3(MATCH, NIL, rectonode(), (Node*)makedfa($1, 0)); free($1); }
void checkdup(Node *list, Cell *item);
Node *beginloc = 0;
Node *endloc = 0;
{ $$ = op5(GENSUB, NIL, (Node*)makedfa($3, 1), $5, $7, rectonode()); }
$$ = op5(GENSUB, NIL, (Node *)makedfa(strnode($3), 1), $5, $7, rectonode());
$$ = op5(GENSUB, (Node *)1, $3, $5, $7, rectonode());
Node *arglist = 0; /* list of args for current function */
{ $$ = op5(GENSUB, NIL, (Node*)makedfa($3, 1), $5, $7, $9); }
$$ = op5(GENSUB, NIL, (Node *)makedfa(strnode($3),1), $5,$7,$9);
$$ = op5(GENSUB, (Node *)1, $3, $5, $7, $9);
$$ = op2(INDEX, $3, (Node*)$5); }
{ $$ = op3(MATCHFCN, NIL, $3, (Node*)makedfa($5, 1)); free($5); }
$$ = op3(MATCHFCN, NIL, $3, (Node*)makedfa(strnode($5), 1));
$$ = op3(MATCHFCN, (Node *)1, $3, $5); }
{ $$ = op4(SPLIT, $3, makearr($5), $7, (Node*)STRING); }
{ $$ = op4(SPLIT, $3, makearr($5), (Node*)makedfa($7, 1), (Node *)REGEXPR); free($7); }
{ $$ = op4(SPLIT, $3, makearr($5), NIL, (Node*)STRING); } /* default */
{ $$ = op4($1, NIL, (Node*)makedfa($3, 1), $5, rectonode()); free($3); }
Node *p;
$$ = op4($1, NIL, (Node*)makedfa(strnode($3), 1), $5, rectonode());
$$ = op4($1, (Node *)1, $3, $5, rectonode()); }
{ $$ = op4($1, NIL, (Node*)makedfa($3, 1), $5, $7); free($3); }
$$ = op4($1, NIL, (Node*)makedfa(strnode($3), 1), $5, $7);
$$ = op4($1, (Node *)1, $3, $5, $7); }
| VARNF { $$ = op1(VARNF, (Node *) $1); }
int constnode(Node *p)
char *strnode(Node *p)
Node *notnull(Node *n)
void checkdup(Node *vl, Cell *cp) /* check if name already in list */
np = op2(CCL, NIL, (Node*) cclenter((const char *) rlxstr));
np = op2(NCCL, NIL, (Node *) cclenter((const char *) rlxstr));
return unary(op2(CCL, NIL, (Node *) cclenter("")));
Node *concat(Node *np)
return (concat(op2(CAT, op2(CCL, NIL, (Node *) cclenter("")),
Node *alt(Node *np)
Node *unary(Node *np)
Node *p, *p1;
void penter(Node *p) /* set up parent pointers and leaf indices */
void freetr(Node *p) /* free parse tree */
void cfoll(fa *f, Node *v) /* enter follow set of each leaf of vertex v into lfollow[leaf] */
int first(Node *p) /* collects initially active leaves of p into setvec */
void follow(Node *v) /* collects leaves that can follow v into setvec */
Node *p;
Node *reparse(const char *p) /* parses regular expression pointed to by p */
Node *np;
Node *regexp(void) /* top-level parse of reg expr */
Node *primary(void)
Node *np;
extern Node *curnode;
extern Node *curnode;
Node *stat1(int a, Node *b)
Node *x;
Node *stat2(int a, Node *b, Node *c)
Node *x;
Node *stat3(int a, Node *b, Node *c, Node *d)
Node *x;
Node *stat4(int a, Node *b, Node *c, Node *d, Node *e)
Node *x;
Node *op1(int a, Node *b)
Node *x;
Node *op2(int a, Node *b, Node *c)
Node *x;
Node *op3(int a, Node *b, Node *c, Node *d)
Node *x;
Node *op4(int a, Node *b, Node *c, Node *d, Node *e)
Node *x;
Node *op5(int a, Node *b, Node *c, Node *d, Node *e, Node *f)
Node *x;
Node *celltonode(Cell *a, int b)
Node *x;
x = node1(0, (Node *) a);
Node *rectonode(void) /* make $0 into a Node */
Node *makearr(Node *p)
Node *pa2stat(Node *a, Node *b, Node *c) /* pat, pat {...} */
Node *x;
Node *linkum(Node *a, Node *b)
Node *c;
void defn(Cell *v, Node *vl, Node *st) /* turn on FCN bit in definition, */
Node *p;
extern Node *arglist;
Node *p = arglist;
Node *itonp(int i) /* and vice versa */
return (Node *) (long) i;
Node *nodealloc(size_t n)
Node *x;
x = (Node *) malloc(sizeof(*x) + (n-1) * sizeof(x));
Node *exptostat(Node *a)
Node *node1(int a, Node *b)
Node *x;
Node *node2(int a, Node *b, Node *c)
Node *x;
Node *node3(int a, Node *b, Node *c, Node *d)
Node *x;
Node *node4(int a, Node *b, Node *c, Node *d, Node *e)
Node *x;
Node *node5(int a, Node *b, Node *c, Node *d, Node *e, Node *f)
Node *x;
extern void run(Node *);
extern Cell *execute(Node *);
extern Cell *program(Node **, int);
extern Cell *call(Node **, int);
extern Cell *arg(Node **, int);
extern Cell *jump(Node **, int);
extern Cell *awkgetline(Node **, int);
extern Cell *getnf(Node **, int);
extern Cell *array(Node **, int);
extern Cell *awkdelete(Node **, int);
extern Cell *intest(Node **, int);
extern Cell *matchop(Node **, int);
extern Cell *boolop(Node **, int);
extern Cell *relop(Node **, int);
extern Cell *indirect(Node **, int);
extern Cell *substr(Node **, int);
extern Cell *sindex(Node **, int);
extern int format(char **, int *, const char *, Node *);
extern Cell *awksprintf(Node **, int);
extern Cell *awkprintf(Node **, int);
extern Cell *arith(Node **, int);
extern Cell *incrdecr(Node **, int);
extern Cell *assign(Node **, int);
extern Cell *cat(Node **, int);
extern Cell *pastat(Node **, int);
extern Cell *dopa2(Node **, int);
extern Cell *split(Node **, int);
extern Cell *condexpr(Node **, int);
extern Cell *ifstat(Node **, int);
extern Cell *whilestat(Node **, int);
extern Cell *dostat(Node **, int);
extern Cell *forstat(Node **, int);
extern Cell *instat(Node **, int);
extern Cell *bltin(Node **, int);
extern Cell *printstat(Node **, int);
extern Cell *nullproc(Node **, int);
extern FILE *redirect(int, Node *);
extern Cell *closefile(Node **, int);
extern Cell *dosub(Node **, int);
extern Cell *gensub(Node **, int);
extern int constnode(Node *);
extern char *strnode(Node *);
extern Node *notnull(Node *);
extern void penter(Node *);
extern void freetr(Node *);
extern void cfoll(fa *, Node *);
extern int first(Node *);
extern void follow(Node *);
extern Node *reparse(const char *);
extern Node *regexp(void);
extern Node *primary(void);
extern Node *concat(Node *);
extern Node *alt(Node *);
extern Node *unary(Node *);
extern Node *nodealloc(size_t);
extern Node *exptostat(Node *);
extern Node *node1(int, Node *);
extern Node *node2(int, Node *, Node *);
extern Node *node3(int, Node *, Node *, Node *);
extern Node *node4(int, Node *, Node *, Node *, Node *);
extern Node *node5(int, Node *, Node *, Node *, Node *, Node *);
extern Node *stat3(int, Node *, Node *, Node *);
extern Node *op2(int, Node *, Node *);
extern Node *op1(int, Node *);
extern Node *stat1(int, Node *);
extern Node *op3(int, Node *, Node *, Node *);
extern Node *op4(int, Node *, Node *, Node *, Node *);
extern Node *op5(int, Node *, Node *, Node *, Node *, Node *);
extern Node *stat2(int, Node *, Node *);
extern Node *stat4(int, Node *, Node *, Node *, Node *);
extern Node *celltonode(Cell *, int);
extern Node *rectonode(void);
extern Node *makearr(Node *);
extern Node *pa2stat(Node *, Node *, Node *);
extern Node *linkum(Node *, Node *);
extern void defn(Cell *, Node *, Node *);
extern Cell *(*proctab[])(Node **, int);
extern Node *itonp(int);
Node *curnode = NULL; /* the node being executed, for debugging */
Cell *sindex(Node **a, int nnn) /* index(a[0], a[1]) */
int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like conversions */
Cell *awksprintf(Node **a, int n) /* sprintf(a[0]) */
void run(Node *a) /* execution of parse tree starts here */
Node *y;
Cell *awkprintf(Node **a, int n) /* printf */
Node *y;
Cell *arith(Node **a, int n) /* a[0] + a[1], etc. also -a[0] */
Cell *execute(Node *u) /* execute a node of the parse tree */
Cell *(*proc)(Node **, int);
Node *a;
Cell *incrdecr(Node **a, int n) /* a[0]++, etc. */
Cell *assign(Node **a, int n) /* a[0] = a[1], a[0] += a[1], etc. */
Cell *cat(Node **a, int q) /* a[0] cat a[1] */
Cell *pastat(Node **a, int n) /* a[0] { a[1] } */
Cell *dopa2(Node **a, int n) /* a[0], a[1] { a[2] } */
Cell *split(Node **a, int nnn) /* split(a[0], a[1], a[2]); a[3] is type */
Cell *program(Node **a, int n) /* execute an awk program */
Cell *condexpr(Node **a, int n) /* a[0] ? a[1] : a[2] */
Cell *ifstat(Node **a, int n) /* if (a[0]) a[1]; else a[2] */
Cell *whilestat(Node **a, int n) /* while (a[0]) a[1] */
Cell *dostat(Node **a, int n) /* do a[0]; while(a[1]) */
Cell *forstat(Node **a, int n) /* for (a[0]; a[1]; a[2]) a[3] */
Cell *instat(Node **a, int n) /* for (a[0] in a[1]) a[2] */
Cell *bltin(Node **a, int n) /* builtin functions. a[0] is type, a[1] is arg list */
Node *nextarg;
Cell *printstat(Node **a, int n) /* print a[0] */
Node *x;
Cell *call(Node **a, int n) /* function call. very kludgy and fragile */
Cell *nullproc(Node **a, int n)
FILE *redirect(int a, Node *b) /* set up all i/o redirections */
Node *x;
Cell *closefile(Node **a, int n)
Cell *dosub(Node **a, int subop) /* sub and gsub */
Cell *gensub(Node **a, int nnn) /* global selective substitute */
y = execute((Node *)(fcn->sval)); /* execute body */
Cell *arg(Node **a, int n) /* nth argument of a function */
Cell *jump(Node **a, int n) /* break, continue, next, nextfile, return */
Cell *awkgetline(Node **a, int n) /* get next line from specific input */
Cell *getnf(Node **a, int n) /* get NF */
makearraystring(Node *p, const char *func)
Cell *array(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */
Cell *awkdelete(Node **a, int n) /* a[0] is symtab, a[1] is list of subscripts */
Cell *intest(Node **a, int n) /* a[0] is index (list), a[1] is symtab */
Cell *matchop(Node **a, int n) /* ~ and match() */
Node *winner = NULL; /* root of parse tree */
Cell *boolop(Node **a, int n) /* a[0] || a[1], a[0] && a[1], !a[0] */
Cell *relop(Node **a, int n) /* a[0 < a[1], etc. */
Cell *indirect(Node **a, int n) /* $( a[0] ) */
Cell *substr(Node **a, int nnn) /* substr(a[0], a[1], a[2]) */
Node *nullnode; /* zero&null, converted into a node for comparisons */
void graph_edges(Node *node);
void elide_aliases(Node *node);
Node *find_node(u_int32_t addr, Node **ptr)
Node *n = *ptr;
*ptr = n = malloc(sizeof(Node));
Interface *find_interface(u_int32_t addr, Node *node)
Neighbor *find_neighbor(u_int32_t addr, Node *node)
Node *node = find_node(src, &routers);
Node *ifc_node;
Node *tmp = ifc_node->u.alias;
Node *n_node;
Node *node = find_node(src, &routers);
Node *ifc_node;
Node *tmp = ifc_node->u.alias;
Node *n_node;
int retry_requests(Node *node)
void print_map(Node *node)
void graph_edges(Node *node)
Node *nb_node = find_node(nb->addr, &routers);
void elide_aliases(Node *node)
Node *nb_node = find_node(nb->addr, &routers);
Node *routers = 0;
Node *n = find_node(target_addr, &routers);
Node * find_node(u_int32_t addr, Node **ptr);
Interface * find_interface(u_int32_t addr, Node *node);
Neighbor * find_neighbor(u_int32_t addr, Node *node);
int retry_requests(Node *node);
void print_map(Node *node);