parent
6ca32e8d49
commit
4035b50128
38
src/sfxd.c
38
src/sfxd.c
|
@ -13,6 +13,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <wordexp.h>
|
||||
|
||||
#define KEY_LENGTH 256
|
||||
#define MAX_SOUNDS_PER_KEY 32
|
||||
|
@ -327,7 +328,23 @@ void execute_command(struct msg_target tgt, const char *command, const char *par
|
|||
send_txt(tgt, "ERR: argument required: PATH\n");
|
||||
return;
|
||||
}
|
||||
execute_file(tgt, params, 0);
|
||||
wordexp_t p;
|
||||
int retval = wordexp(params, &p, 0);
|
||||
#define _WORDEXP_ERROR(ERR_CODE) case ERR_CODE: send_txt(tgt, "ERR: wordexp: " #ERR_CODE); return;
|
||||
switch (retval) {
|
||||
case 0: break;
|
||||
_WORDEXP_ERROR(WRDE_BADCHAR);
|
||||
_WORDEXP_ERROR(WRDE_BADVAL);
|
||||
_WORDEXP_ERROR(WRDE_CMDSUB);
|
||||
_WORDEXP_ERROR(WRDE_NOSPACE);
|
||||
_WORDEXP_ERROR(WRDE_SYNTAX);
|
||||
default: send_txt(tgt, "ERR: wordexp: Unknown error: %d\n", retval); return;
|
||||
}
|
||||
#undef _WORDEXP_ERROR
|
||||
for (size_t i = 0; i < p.we_wordc; i++) {
|
||||
execute_file(tgt, p.we_wordv[i], 0);
|
||||
}
|
||||
wordfree(&p);
|
||||
} else if (0 == strcmp(command, "help")) {
|
||||
send_help(tgt);
|
||||
} else if (0 == strcmp(command, "meow")) {
|
||||
|
@ -425,7 +442,24 @@ bool execute_file(struct msg_target tgt, const char *path, int depth) {
|
|||
fclose(fp);
|
||||
return false;
|
||||
}
|
||||
execute_file(tgt, args, depth + 1);
|
||||
wordexp_t p;
|
||||
int retval = wordexp(args, &p, 0);
|
||||
#define _WORDEXP_ERROR(ERR_CODE) case ERR_CODE: send_txt(tgt, "ERR: wordexp: " #ERR_CODE); return false;
|
||||
switch (retval) {
|
||||
case 0: break;
|
||||
_WORDEXP_ERROR(WRDE_BADCHAR);
|
||||
_WORDEXP_ERROR(WRDE_BADVAL);
|
||||
_WORDEXP_ERROR(WRDE_CMDSUB);
|
||||
_WORDEXP_ERROR(WRDE_NOSPACE);
|
||||
_WORDEXP_ERROR(WRDE_SYNTAX);
|
||||
default: send_txt(tgt, "ERR: wordexp: Unknown error: %d\n", retval); return false;
|
||||
}
|
||||
#undef _WORDEXP_ERROR
|
||||
for (size_t i = 0; i < p.we_wordc; i++) {
|
||||
send_txt(tgt, "DBG: executing file %s\n", p.we_wordv[i]);
|
||||
execute_file(tgt, p.we_wordv[i], depth + 1);
|
||||
}
|
||||
wordfree(&p);
|
||||
} else {
|
||||
execute_command(tgt, cmd, args);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue