66# https://github.com/Softmotions/autark
77
88META_VERSION=0.9.0
9- META_REVISION=170d75f
9+ META_REVISION=69a4678
1010cd " $( cd " $( dirname " $0 " ) " ; pwd -P) "
1111
1212prev_arg=" "
@@ -62,7 +62,7 @@ cat <<'a292effa503b' > ${AUTARK_HOME}/autark.c
6262#ifndef CONFIG_H
6363#define CONFIG_H
6464#define META_VERSION "0.9.0"
65- #define META_REVISION "170d75f "
65+ #define META_REVISION "69a4678 "
6666#endif
6767#define _AMALGAMATE_
6868#define _XOPEN_SOURCE 700
@@ -873,6 +873,7 @@ void node_product_add(struct node*, const char *prod, char pathbuf[PATH_MAX]);
873873void node_product_add_raw(struct node*, const char *prod);
874874void node_reset(struct node *n);
875875const char* node_value(struct node *n);
876+ #define NODE_VISIT_CHILD_SKIP INT_MAX
876877int node_visit(struct node *n, int lvl, void *ctx, int (*visitor)(struct node*, int, void*));
877878void node_module_setup(struct node *n, unsigned flags);
878879void node_init(struct node *n);
@@ -5681,9 +5682,11 @@ struct _call {
56815682 struct ulist nodes; ///< Nodes stack. struct node*
56825683 struct node *args[MACRO_MAX_ARGS_NUM];
56835684 int nn_idx;
5685+ int arg_idx;
56845686};
56855687static int _call_macro_visit(struct node *n, int lvl, void *d) {
56865688 struct _call *call = d;
5689+ int ret = 0;
56875690 if (call->mn == n /*skip macro itself */ || call->mn->child == n /* skip macro name */) {
56885691 return 0;
56895692 }
@@ -5692,15 +5695,23 @@ static int _call_macro_visit(struct node *n, int lvl, void *d) {
56925695 return 0;
56935696 }
56945697 // Macro arg
5695- if (n->value[0] == '&' && n->value[1] == '\0' && n->child && !n->child->next) {
5698+ if (n->value[0] == '&' && n->value[1] == '\0') {
5699+ int idx;
56965700 int rc = 0;
5697- int idx = utils_strtol(n->child->value, 10, &rc);
5698- if (rc || idx < 1 || idx >= MACRO_MAX_ARGS_NUM) {
5699- node_fatal(rc, n, "Invalid macro arg index: %d", idx);
5700- return 0;
5701+ if (n->child) {
5702+ idx = utils_strtol(n->child->value, 10, &rc);
5703+ if (rc || idx < 1 || idx >= MACRO_MAX_ARGS_NUM) {
5704+ node_fatal(rc, n, "Invalid macro arg index: %d", idx);
5705+ return 0;
5706+ }
5707+ //n->child = 0;
5708+ ret = INT_MAX;
5709+ idx--;
5710+ } else {
5711+ call->arg_idx++;
5712+ idx = call->arg_idx;
57015713 }
5702- n->child = 0; // Do not traverse arg index
5703- idx--;
5714+ call->arg_idx = idx;
57045715 n = call->args[idx];
57055716 if (!n) {
57065717 node_fatal(rc, call->n, "Call argument: %d for macro: %s is not set", (idx + 1), call->key);
@@ -5724,7 +5735,7 @@ static int _call_macro_visit(struct node *n, int lvl, void *d) {
57245735 c->next = nn;
57255736 }
57265737 ulist_push(&call->nodes, &nn);
5727- return 0 ;
5738+ return ret ;
57285739}
57295740static void _call_remove(struct node *n) {
57305741 struct node *prev = node_find_prev_sibling(n);
@@ -5748,6 +5759,7 @@ static void _call_init(struct node *n) {
57485759 }
57495760 struct _call *call = xcalloc(1, sizeof(*call));
57505761 call->nn_idx = -1;
5762+ call->arg_idx = -1;
57515763 call->key = key;
57525764 call->mn = mn;
57535765 call->n = n;
@@ -5767,10 +5779,7 @@ static void _call_init(struct node *n) {
57675779 }
57685780 ulist_push(&call->nodes, &n->parent);
57695781 _call_remove(n);
5770- int rc = node_visit(mn, 1, call, _call_macro_visit);
5771- if (rc) {
5772- node_fatal(rc, n, 0);
5773- }
5782+ node_visit(mn, 1, call, _call_macro_visit);
57745783 for (int i = call->nn_idx; i < n->ctx->nodes.num; ++i) {
57755784 struct node *nn = *(struct node**) ulist_get(&n->ctx->nodes, i);
57765785 node_bind(nn);
@@ -7530,13 +7539,15 @@ static void _finish(struct _yycontext *yy) {
75307539}
75317540static int _node_visit(struct node *n, int lvl, void *ctx, int (*visitor)(struct node*, int, void*)) {
75327541 int ret = visitor(n, lvl, ctx);
7533- if (ret) {
7542+ if (ret && ret != NODE_VISIT_CHILD_SKIP ) {
75347543 return ret;
75357544 }
7536- for (struct node *c = n->child; c; c = c->next) {
7537- ret = _node_visit(c, lvl + 1, ctx, visitor);
7538- if (ret) {
7539- return ret;
7545+ if (ret != NODE_VISIT_CHILD_SKIP) {
7546+ for (struct node *c = n->child; c; c = c->next) {
7547+ ret = _node_visit(c, lvl + 1, ctx, visitor);
7548+ if (ret) {
7549+ return ret;
7550+ }
75407551 }
75417552 }
75427553 return visitor(n, -lvl, ctx);
0 commit comments