#include "gwion.h"
#include "arg.h"
#include "pass.h"
+#include "compile.h"
#define GWIONRC ".gwionrc"
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);
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 <options>\n"
" -h : this help\n"
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;
}
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);
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;
}
}