#include "soundinfo.h"
#define GWIONRC ".gwionrc"
-ANN static inline void config_end(MemPool p, const Vector config) {
+/* use before MemPool allocation */
+ANN static inline void config_end(const Vector config) {
for(m_uint i = 0; i < vector_size(config); ++i) {
const Vector v = (Vector)vector_at(config, i);
- free_mstr(p, (m_str)vector_front(v));
- free_vector(p, v);
+ for(m_uint i = 1; i < vector_size(v); ++i)
+ xfree((m_str)vector_at(v, i));
+ vector_release(v);
+ xfree(v);
}
}
-ANN static m_str plug_dir(MemPool p) {
+ANN static m_str plug_dir(void) {
const m_str home = getenv("HOME");
const size_t sz = strlen(home);
const m_str pdir = "/.gwplug";
- m_str plug_dir = (m_str)_mp_malloc(p, sz + strlen(pdir) + 1);
+ m_str plug_dir = (m_str)xmalloc(sz + strlen(pdir) + 1);
strcpy(plug_dir, home);
strcpy(plug_dir + sz, pdir);
return plug_dir;
}
-ANN static void arg_init(MemPool p, Arg* arg) {
+ANN static void arg_init(Arg* arg) {
vector_init(&arg->add);
vector_init(&arg->lib);
vector_init(&arg->mod);
vector_init(&arg->config);
- vector_add(&arg->lib, (vtype)plug_dir(p));
+// vector_add(&arg->lib, (vtype)GWPLUG_DIR);
+ vector_add(&arg->lib, (vtype)plug_dir());
}
-ANN void arg_release(MemPool p, Arg* arg) {
+ANN void arg_release(Arg* arg) {
vector_release(&arg->add);
- free_mstr(p, (m_str)vector_front(&arg->lib));
+ xfree((m_str)vector_front(&arg->lib));
vector_release(&arg->lib);
vector_release(&arg->mod);
- config_end(p, &arg->config);
+ config_end(&arg->config);
vector_release(&arg->config);
}
" -z <number> : set memoization limit\n"
" -m <mod:args> : load module (and arguments)\n";
-ANN static void config_parse(MemPool p, Arg* arg, const m_str name);
+ANN static void config_parse(Arg* arg, const m_str name);
#define CASE(a,b) case a: (b) ; break;
#define get_arg(a) (a[i][2] == '\0' ? arg->argv[++i] : a[i] + 2)
#define ARG2INT(a) strtol(get_arg(a), NULL, 10)
-ANN void _arg_parse(MemPool p, Arg* arg) {
+ANN void _arg_parse(Arg* arg) {
for(int i = 1; i < arg->argc; ++i) {
if(arg->argv[i][0] == '-') {
switch(arg->argv[i][1]) {
CASE('h', gw_err(usage))
CASE('k', gw_err("CFLAGS: %s\nLDFLAGS: %s\n", CFLAGS, LDFLAGS))
- CASE('c', config_parse(p, arg, get_arg(arg->argv)))
+ CASE('c', config_parse(arg, get_arg(arg->argv)))
CASE('p', vector_add(&arg->lib, (vtype)get_arg(arg->argv)))
CASE('m', vector_add(&arg->mod, (vtype)get_arg(arg->argv)))
CASE('l', arg->loop = (m_bool)ARG2INT(arg->argv) > 0 ? 1 : -1)
}
}
-ANN static void split_line(MemPool p, const m_str line, const Vector v) {
- m_str d = mstrdup(p, line);
+ANN static void split_line(const m_str line, const Vector v) {
+ m_str d = strdup(line), c = d;
while(d) {
const m_str str = strsep(&d, " ");
const size_t sz = strlen(str);
- if(str[sz-1] == '\n')
- str[sz-1] = '\0';
- vector_add(v, (vtype)str);
+ const m_bool arg = (str[sz-1] == '\n');
+ vector_add(v, (vtype)strndup(str, arg ? sz - 1 : sz));
}
+ free(d);
+ free(c);
}
-ANN static Vector get_config(MemPool p, const m_str name) {
+ANN static Vector get_config(const m_str name) {
char *line = NULL;
size_t len = 0;
ssize_t nread;
FILE *f = fopen(name, "r");
CHECK_OO(f)
- const Vector v = new_vector(p);
+ const Vector v = (Vector)xmalloc(sizeof(struct Vector_));
+ vector_init(v);
vector_add(v, (vtype)name);
while((nread = getline(&line, &len, f)) != -1) {
if(line[0] != '#')
- split_line(p, line, v);
+ split_line(line, v);
}
free(line);
fclose(f);
return v;
}
-ANN static void config_parse(MemPool p, Arg* arg, const m_str name) {
- const Vector v = get_config(p, name);
+ANN static void config_parse(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);
- _arg_parse(p, arg);
+ _arg_parse(arg);
arg->argc = argc;
arg->argv = argv;
vector_add(&arg->config, (vtype)v);
}
}
-ANN static void config_default(MemPool p, Arg* arg) {
+ANN static void config_default(Arg* arg) {
char* home = getenv("HOME");
char c[strlen(home) + strlen(GWIONRC) + 2];
sprintf(c, "%s/%s", home, GWIONRC);
- config_parse(p, arg, c);
+ config_parse(arg, c);
}
-ANN void arg_parse(MemPool p, Arg* a) {
- arg_init(p, a);
- config_default(p, a);
- _arg_parse(p, a);
+ANN void arg_parse(Arg* a) {
+ arg_init(a);
+ config_default(a);
+ _arg_parse(a);
}
return gwion->vm;
}
-
-ANN m_bool start(const Gwion gwion, Arg* arg) {
- if(gwion_audio(gwion) > 0 && gwion_engine(gwion)) {
- gwion_compile(gwion, &arg->add);
- plug_run(gwion, &arg->mod);
- return GW_OK;
- }
- return GW_ERROR;
-}
-
ANN m_bool gwion_ini(const Gwion gwion, Arg* arg) {
gwion->mp = mempool_ini((sizeof(VM_Shred) + SIZEOF_REG + SIZEOF_MEM) / SZ_INT);
gwion->st = new_symbol_table(gwion->mp, 65347);
gwion->env->gwion = gwion;
gwion->vm->bbq->si = new_soundinfo(gwion->mp);
arg->si = gwion->vm->bbq->si;
- arg_parse(gwion->mp, arg);
+ arg_parse(arg);
gwion->emit->memoize = arg->memoize;
gwion->plug = new_plug(gwion->mp, &arg->lib);
gwion->data = new_gwiondata(gwion->mp);
shreduler_set_loop(gwion->vm->shreduler, arg->loop);
- const m_bool ret = start(gwion, arg);
- arg_release(gwion->mp, arg);
- return ret;
+ if(gwion_audio(gwion) > 0 && gwion_engine(gwion)) {
+ gwion_compile(gwion, &arg->add);
+ plug_run(gwion, &arg->mod);
+ return GW_OK;
+ }
+ return GW_ERROR;
}
ANN void gwion_run(const Gwion gwion) {