Skip to content

Commit

Permalink
Fix meta args cascade arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas RODRIGUEZ <lucas.rodriguez@outscale.com>
  • Loading branch information
ryohkhn authored and outscale-mgo committed Jun 11, 2024
1 parent 75217f0 commit be6f3d6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
30 changes: 3 additions & 27 deletions cognac_gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ EOF
incr = 1;
aa = eq_ptr + 1;
} else {
CHK_BAD_RET(!aa || aa[0] == '-', "cascade need an argument\n");
CHK_BAD_RET(!aa, "cascade need an argument\n");
META_ARGS()
}
STRY(cascade_parser(cascade_struct, next_a, aa, pa));
i += incr;
Expand All @@ -355,32 +356,7 @@ EOF
(void)str;
if (aa && aa[0] == '-' && aa[1] == '-' && aa[2] != '-') {
if (!strcmp(aa, "--file")) {
TRY(i + 3 >= ac, "file name require");
++incr;
aa = read_file(files_cnt, av[i + 3], 0);
STRY(!aa);
} else if (!strcmp(aa, "--jsonstr-file")) {
TRY(i + 3 >= ac, "file name require");
++incr;
aa = read_file(files_cnt, av[i + 3], 1);
STRY(!aa);
} else if (!strcmp(aa, "--var")) {
TRY(i + 3 >= ac, "var name require");
int var_found = 0;
for (int j = 0; j < nb_cli_vars; ++j) {
if (!strcmp(cli_vars[j].name, av[i + 3])) {
var_found = 1;
aa = cli_vars[j].val;
}
}
TRY(!var_found, "--var could not find osc variable '%s'", av[i + 3]);
++incr;
STRY(!aa);
} else {
aa = 0;
incr = 1;
}
META_ARGS();
}
EOF

Expand Down
27 changes: 27 additions & 0 deletions main_tpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,33 @@
if (f) {fprintf(stderr, args); return -1;} \
} while(0)

#define META_ARGS() \
if (!strcmp(aa, "--file")) { \
TRY(i + 3 >= ac, "file name require"); \
++incr; \
aa = read_file(files_cnt, av[i + 3], 0); \
STRY(!aa); \
} else if (!strcmp(aa, "--jsonstr-file")) { \
TRY(i + 3 >= ac, "file name require"); \
++incr; \
aa = read_file(files_cnt, av[i + 3], 1); \
STRY(!aa); \
} else if (!strcmp(aa, "--var")) { \
TRY(i + 3 >= ac, "var name require"); \
int var_found = 0; \
for (int j = 0; j < nb_cli_vars; ++j) { \
if (!strcmp(cli_vars[j].name, av[i + 3])) { \
var_found = 1; \
aa = cli_vars[j].val; \
} \
} \
TRY(!var_found, "--var could not find osc variable '%s'", av[i + 3]); \
++incr; \
STRY(!aa); \
} else { \
aa = 0; \
incr = 1; \
}

#define VAR_NAME_SIZE 128
#define VAR_VAL_SIZE 512
Expand Down

0 comments on commit be6f3d6

Please sign in to comment.