From: fennecdjay Date: Sat, 7 Nov 2020 11:49:37 +0000 (+0100) Subject: :art: Update macro arguments system X-Git-Tag: nightly~1199 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=150ef2a1f0db29d929cc75a47151781ea47d9586;p=gwion.git :art: Update macro arguments system --- diff --git a/ast b/ast index 1811fe81..99c8a6ee 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 1811fe812817a12968c905c61165b146dc6a17e2 +Subproject commit 99c8a6ee64cb973c516a89c329bb953e3f13599a diff --git a/include/arg.h b/include/arg.h index 22b4bdf8..dfaf8587 100644 --- a/include/arg.h +++ b/include/arg.h @@ -9,9 +9,9 @@ typedef struct Arg_ { struct Vector_ config; struct SoundInfo_ *si; m_bool loop; - m_bool read_stdin; } Arg; ANN void arg_release(Arg*); ANN m_bool arg_parse(const Gwion, Arg*); +ANN void arg_compile(const Gwion, Arg*); #endif diff --git a/src/arg.c b/src/arg.c index be2c1e95..dd340388 100644 --- a/src/arg.c +++ b/src/arg.c @@ -6,6 +6,7 @@ #include "gwion.h" #include "arg.h" #include "pass.h" +#include "compile.h" #define GWIONRC ".gwionrc" @@ -30,6 +31,14 @@ ANN static m_str plug_dir(void) { return plug_dir; } +enum arg_type { + ARG_FILE, + ARG_STDIN, + ARG_DEFINE, + ARG_UNDEF, + ARG_INCLUDE +}; + ANN static void arg_init(Arg* arg) { map_init(&arg->mod); vector_init(&arg->add); @@ -47,6 +56,29 @@ ANN void arg_release(Arg* arg) { vector_release(&arg->config); } +ANN void arg_compile(const Gwion gwion, Arg *arg) { + const Vector v = &arg->add; + for(m_uint i = 0; i < vector_size(v); i++) { + switch(vector_at(v, i)) { + case ARG_FILE: + compile_filename(gwion, (m_str)VPTR(v, ++i)); + break; + case ARG_STDIN: + compile_file(gwion, "stdin", stdin); + break; + case ARG_DEFINE: + pparg_add(gwion->ppa, (m_str)VPTR(v, ++i)); + break; + case ARG_UNDEF: + pparg_rem(gwion->ppa, (m_str)VPTR(v, ++i)); + break; + case ARG_INCLUDE: + pparg_inc(gwion->ppa, (m_str)VPTR(v, ++i)); + break; + } + } +} + static const char usage[] = "usage: Gwion \n" " -h : this help\n" @@ -127,14 +159,32 @@ ANN m_bool _arg_parse(const Gwion gwion, Arg* arg) { arg_set_pass(gwion, tmp); break; case '\0': - arg->read_stdin = !arg->read_stdin; + vector_add(&arg->add, (vtype)ARG_STDIN); + break; + case 'D': + CHECK_OB((tmp = option_argument(ca))) + vector_add(&arg->add, (vtype)ARG_DEFINE); + vector_add(&arg->add, (vtype)tmp); + break; + case 'U': + CHECK_OB((tmp = option_argument(ca))) + vector_add(&arg->add, (vtype)ARG_UNDEF); + vector_add(&arg->add, (vtype)tmp); + break; + case 'I': + CHECK_OB((tmp = option_argument(ca))) + vector_add(&arg->add, (vtype)ARG_INCLUDE); + vector_add(&arg->add, (vtype)tmp); break; default: gw_err(_("invalid arguments")); return GW_ERROR; } } else +{ + vector_add(&arg->add, (vtype)ARG_FILE); vector_add(&arg->add, (vtype)ca->argv[ca->idx]); +} } return GW_OK; } diff --git a/src/gwion.c b/src/gwion.c index 9cce298c..80b01e72 100644 --- a/src/gwion.c +++ b/src/gwion.c @@ -27,11 +27,6 @@ ANN static inline m_bool gwion_engine(const Gwion gwion) { return type_engine_init(gwion) > 0; } -ANN static inline void gwion_compile(const Gwion gwion, const Vector v) { - for(m_uint i = 0; i < vector_size(v); i++) - compile_filename(gwion, (m_str)vector_at(v, i)); -} - ANN static void gwion_cleaner(const Gwion gwion) { const VM_Code code = new_vm_code(gwion->mp, NULL, 0, 1, "in code dtor"); gwion->vm->cleaner_shred = new_vm_shred(gwion->mp, code); @@ -67,9 +62,7 @@ ANN static m_bool gwion_ok(const Gwion gwion, Arg* arg) { plug_run(gwion, &arg->mod); if(gwion_engine(gwion)) { gwion_cleaner(gwion); - gwion_compile(gwion, &arg->add); - if(arg->read_stdin) - compile_file(gwion, "stdin", stdin); + (void)arg_compile(gwion, arg); return GW_OK; } }