Commit e088bfc3 authored by rswindell's avatar rswindell
Browse files

Bug-fix: exec_bin() can now accept an entire module "command-line"

(including arguments) - this allows .js modules executed with "*modname args"
(as opposed to "?modname args") to get the passed arguments (e.g. argv[0]).
Reported by Ash-Fox in regards to telgate.js.
parent 14dd3383
......@@ -653,23 +653,37 @@ long sbbs_t::js_execfile(const char *cmd)
}
#endif
long sbbs_t::exec_bin(char *mod, csi_t *csi)
/* Important change as of Nov-16-2006, 'cmdline' may contain args */
long sbbs_t::exec_bin(const char *cmdline, csi_t *csi)
{
char str[MAX_PATH+1];
char mod[MAX_PATH+1];
char modname[MAX_PATH+1];
char* p;
int file;
csi_t bin;
SAFECOPY(mod,cmdline);
p=mod;
FIND_CHAR(p,' ');
if(*p) {
*p=0; /* terminate 'mod' */
p++; /* skip space */
SKIP_CHAR(p,' '); /* skip more spaces */
}
strcpy(main_csi.str, p);
#ifdef JAVASCRIPT
if((p=getfext(mod))!=NULL && stricmp(p,".js")==0)
return(js_execfile(cmdline));
if(cfg.mods_dir[0]) {
sprintf(str,"%s%s.js",cfg.mods_dir,mod);
if(fexistcase(str))
return(js_execfile(str));
return(js_execfile(cmdline));
}
sprintf(str,"%s%s.js",cfg.exec_dir,mod);
if(fexistcase(str))
return(js_execfile(str));
return(js_execfile(cmdline));
#endif
memcpy(&bin,csi,sizeof(csi_t));
......
......@@ -382,7 +382,7 @@ public:
int exec_net(csi_t *csi);
int exec_msg(csi_t *csi);
int exec_file(csi_t *csi);
long exec_bin(char *mod, csi_t *csi);
long exec_bin(const char *mod, csi_t *csi);
void clearvars(csi_t *bin);
void freevars(csi_t *bin);
char** getstrvar(csi_t *bin, long name);
......
......@@ -280,16 +280,8 @@ static bool native_executable(scfg_t* cfg, const char* cmdline, long mode)
}
#define XTRN_LOADABLE_MODULE \
if(cmdline[0]=='*') { /* Baja module or JavaScript */ \
SAFECOPY(str,cmdline+1); \
p=strchr(str,' '); \
if(p) { \
strcpy(main_csi.str,p+1); \
*p=0; \
} else \
main_csi.str[0]=0; \
return(exec_bin(str,&main_csi)); \
}
if(cmdline[0]=='*') /* Baja module or JavaScript */ \
return(exec_bin(cmdline+1,&main_csi))
#ifdef JAVASCRIPT
#define XTRN_LOADABLE_JS_MODULE \
if(cmdline[0]=='?') /* JavaScript */ \
......@@ -361,7 +353,6 @@ static void add_env_var(str_list_t* list, const char* var, const char* val)
int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
{
char str[MAX_PATH+1];
char* p;
char* env_block=NULL;
char* env_strings;
const char* p_startup_dir;
......
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