free_vector(gwion->mp, v);
}
-ANN static inline m_str _get_arg(Arg* arg, int *i) {
- const char key = arg->argv[*i][1];
- const m_str str = (arg->argv[*i][2] == '\0' ? arg->argv[++(*i)] : arg->argv[*i] + 2);
- if(!str)
- gw_err(_("option '-%c' needs arguments\n"), key);
- return str;
-}
-
ANN m_bool _arg_parse(const Gwion gwion, Arg* arg) {
- for(int i = 1; i < arg->argc; ++i) {
- if(arg->argv[i][0] == '-') {
+ struct CArg *ca = &arg->arg;
+ for(ca->idx = 1; ca->idx < ca->argc; ++ca->idx) {
+ if(ca->argv[ca->idx][0] == '-') {
m_str tmp;
- switch(arg->argv[i][1]) {
+ switch(ca->argv[ca->idx][1]) {
case 'h':
gw_err(usage);
break;
case 'c':
- CHECK_OB((tmp = _get_arg(arg, &i)))
+ CHECK_OB((tmp = option_argument(ca)))
config_parse(gwion, arg, tmp);
break;
case 'p':
- CHECK_OB((tmp = _get_arg(arg, &i)))
+ CHECK_OB((tmp = option_argument(ca)))
vector_add(&arg->lib, (vtype)tmp);
break;
case 'm':
- CHECK_OB((tmp = _get_arg(arg, &i)))
+ CHECK_OB((tmp = option_argument(ca)))
vector_add(&arg->mod, (vtype)tmp);
break;
case 'l':
- CHECK_OB((tmp = _get_arg(arg, &i)))
+ CHECK_OB((tmp = option_argument(ca)))
arg->loop = (m_bool)ARG2INT(tmp) > 0 ? 1 : -1;
break;
case 'i':
- CHECK_OB((tmp = _get_arg(arg, &i)))
+ CHECK_OB((tmp = option_argument(ca)))
arg->si->in = (uint8_t)ARG2INT(tmp);
break;
case 'o':
- CHECK_OB((tmp = _get_arg(arg, &i)))
+ CHECK_OB((tmp = option_argument(ca)))
arg->si->out = (uint8_t)ARG2INT(tmp);
break;
case 's':
- CHECK_OB((tmp = _get_arg(arg, &i)))
+ CHECK_OB((tmp = option_argument(ca)))
arg->si->sr = (uint32_t)ARG2INT(tmp);
break;
case 'd':
- CHECK_OB((tmp = _get_arg(arg, &i)))
+ CHECK_OB((tmp = option_argument(ca)))
arg->si->arg = tmp;
break;
case 'g':
- CHECK_OB((tmp = _get_arg(arg, &i)))
+ CHECK_OB((tmp = option_argument(ca)))
arg_set_pass(gwion, tmp);
break;
default:
return GW_ERROR;
}
} else
- vector_add(&arg->add, (vtype)arg->argv[i]);
+ vector_add(&arg->add, (vtype)ca->argv[ca->idx]);
}
return GW_OK;
}
const m_bool arg = (str[sz-1] == '\n');
vector_add(v, (vtype)strndup(str, arg ? sz - 1 : sz));
}
- free(d);
- free(c);
+ xfree(d);
+ xfree(c);
}
ANN static Vector get_config(const m_str name) {
ANN static void config_parse(const Gwion gwion, Arg* arg, const m_str name) {
const Vector v = get_config(name);
if(v) {
- int argc = arg->argc;
- char** argv = arg->argv;
- arg->argc = vector_size(v);
- arg->argv = (m_str*)(v->ptr + OFFSET);
+ struct CArg ca = arg->arg;
+ arg->arg.argc = vector_size(v);
+ arg->arg.argv = (m_str*)(v->ptr + OFFSET);
_arg_parse(gwion, arg);
- arg->argc = argc;
- arg->argv = argv;
+ arg->arg = ca;
vector_add(&arg->config, (vtype)v);
}
}
}
ANN static void gwion_cleaner(const Gwion gwion) {
+ if(!gwion->type[et_shred])
+ return;
const VM_Code code = new_vm_code(gwion->mp, NULL, 0, ae_flag_builtin, "in code dtor");
gwion->vm->cleaner_shred = new_vm_shred(gwion->mp, code);
vm_add_shred(gwion->vm, gwion->vm->cleaner_shred);
gwion_cleaner(gwion);
gwion_end_child(gwion);
free_env(gwion->env);
- free_vm_shred(gwion->vm->cleaner_shred);
+ if(gwion->vm->cleaner_shred)
+ free_vm_shred(gwion->vm->cleaner_shred);
free_emitter(gwion->mp, gwion->emit);
free_vm(gwion->vm);
pparg_end(gwion->ppa);
mp_free(gwion->mp, PlugInfo, p);
}
-struct ArgSplitter {
- m_str str;
- Vector v;
- MemPool mp;
-};
-
-ANN static void _split_args(struct ArgSplitter *as) {
- const size_t sz = strlen(as->str);
- char buf[sz + 1], prev = '\0';
- m_uint i = 0, j = 0;
- char c;
- while((c = as->str[i]) != '\0') {
- const m_bool skip = prev == '\\';
- const m_bool comma = c == ',';
- if(comma) {
- if(!skip)
- break;
- --j;
- }
- buf[j++] = (prev = c);
- ++i;
- }
- buf[i] = '\0';
- vector_add(as->v, (vtype)mstrdup(as->mp, buf));
- if(i == sz)
- return;
- as->str += i + 1;
- _split_args(as);
-}
-
-ANN Vector split_args(MemPool p, const m_str str) {
- struct ArgSplitter as = { .str=str, .v=new_vector(p), .mp=p };
- _split_args(&as);
- return as.v;
-}
-
-
ANN static Vector get_arg(MemPool p, const m_str name, const Vector v) {
const size_t len = strlen(name);
for(m_uint i = vector_size(v) + 1; --i;) {