Commit dadfd3ba authored by Hanspeter Portner's avatar Hanspeter Portner

outsource _parse_env to private_ui.h.

parent b1948da0
......@@ -20,6 +20,7 @@
#include <unistd.h>
#include <stdbool.h>
#include <errno.h>
#if !defined(_WIN32)
# include <sys/wait.h>
#else
......@@ -40,6 +41,48 @@ struct _spawn_t {
LV2_Log_Logger *logger;
};
static inline char **
_spawn_parse_env(char *env, char *path)
{
unsigned n = 0;
char **args = malloc((n+1) * sizeof(char *));
char **oldargs = NULL;
if(!args)
goto fail;
args[n] = NULL;
char *pch = strtok(env," \t");
while(pch)
{
args[n++] = pch;
oldargs = args;
args = realloc(args, (n+1) * sizeof(char *));
if(!args)
goto fail;
oldargs = NULL;
args[n] = NULL;
pch = strtok(NULL, " \t");
}
args[n++] = path;
oldargs = args;
args = realloc(args, (n+1) * sizeof(char *));
if(!args)
goto fail;
oldargs = NULL;
args[n] = NULL;
return args;
fail:
if(oldargs)
free(oldargs);
if(args)
free(args);
return 0;
}
#if defined(_WIN32)
static inline int
_spawn_spawn(spawn_t *spawn, char **args)
......
......@@ -19,9 +19,11 @@
#include <unistd.h>
#include <inttypes.h>
#include <uv.h>
#include <moony.h>
#include <private_ui.h>
#include <uv.h>
#include <lv2_external_ui.h> // kxstudio external-ui extension
typedef struct _UI UI;
......@@ -259,48 +261,6 @@ _on_fs_poll(uv_fs_poll_t *pol, int status, const uv_stat_t* prev, const uv_stat_
}
#endif
static inline char **
_parse_env(char *env, char *path)
{
unsigned n = 0;
char **args = malloc((n+1) * sizeof(char *));
char **oldargs = NULL;
if(!args)
goto fail;
args[n] = NULL;
char *pch = strtok(env," \t");
while(pch)
{
args[n++] = pch;
oldargs = args;
args = realloc(args, (n+1) * sizeof(char *));
if(!args)
goto fail;
oldargs = NULL;
args[n] = NULL;
pch = strtok(NULL, " \t");
}
args[n++] = path;
oldargs = args;
args = realloc(args, (n+1) * sizeof(char *));
if(!args)
goto fail;
oldargs = NULL;
args[n] = NULL;
return args;
fail:
if(oldargs)
free(oldargs);
if(args)
free(args);
return 0;
}
static inline void
_show(UI *ui)
{
......@@ -320,7 +280,7 @@ _show(UI *ui)
if(!moony_editor)
moony_editor = command;
char *dup = strdup(moony_editor);
char **args = dup ? _parse_env(dup, ui->path) : NULL;
char **args = dup ? _spawn_parse_env(dup, ui->path) : NULL;
ui->opts.exit_cb = _on_exit;
ui->opts.file = args ? args[0] : NULL;
......
......@@ -19,7 +19,6 @@
#include <stdlib.h>
#include <stddef.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <string.h>
......@@ -929,48 +928,6 @@ _moony_cb(ui_t *ui, const char *json)
}
}
static inline char **
_parse_env(char *env, char *path)
{
unsigned n = 0;
char **args = malloc((n+1) * sizeof(char *));
char **oldargs = NULL;
if(!args)
goto fail;
args[n] = NULL;
char *pch = strtok(env," \t");
while(pch)
{
args[n++] = pch;
oldargs = args;
args = realloc(args, (n+1) * sizeof(char *));
if(!args)
goto fail;
oldargs = NULL;
args[n] = NULL;
pch = strtok(NULL, " \t");
}
args[n++] = path;
oldargs = args;
args = realloc(args, (n+1) * sizeof(char *));
if(!args)
goto fail;
oldargs = NULL;
args[n] = NULL;
return args;
fail:
if(oldargs)
free(oldargs);
if(args)
free(args);
return 0;
}
// Show Interface
static inline int
_show_cb(LV2UI_Handle instance)
......@@ -995,7 +952,7 @@ _show_cb(LV2UI_Handle instance)
if(!moony_browser)
moony_browser = command;
char *dup = strdup(moony_browser);
char **args = dup ? _parse_env(dup, ui->url) : NULL;
char **args = dup ? _spawn_parse_env(dup, ui->url) : NULL;
const int status = _spawn_spawn(&ui->spawn, args);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment