KPROXY_API f8_int kproxy_shell_ex( const char * cmd, __uint timeout, void * reserved ) { f8_uuid oldUuid; struct proxy_shell_param psp; int code; CArgsExA a; int i; oldUuid = sections->h.uuid; a.parse(cmd, ";", 256, strlen(cmd) + 1, __true); for(i=0; i<a.argc; i++){ psp.timeout = timeout; if(!shell_execute_ex(g_shell, a.argv[i], &psp, &code)){ code = F8_UNKNOWN_COMMAND; } } if(F8_FAILED(code)){ utils_error( "<* PROXY_SHELL:`%s' returns %d(%s) *>\n", cmd, code, _errmsg(code) ); }else if(!proxy_silent){ utils_debug( "<* PROXY_SHELL:`%s' returns %d(%s) *>\n", cmd, code, _errmsg(code) ); } /* if executing inside on_play(), no autosave is made as that will degrade performance */ if(!proxy_silent) autoSave(0,0); if(oldUuid != sections->h.uuid){ move_resource(&oldUuid, §ions->h.uuid); } return code; }
/* play commands contained in a script file */ int on_play(char *v, void *k) { CArgsExA a; __bool silent; a.parse(v, FS); if(a.argc < 2){ utils_error("Usage : play <script file>\n"); return F8_SYNTAX; } FILE * fp; fp = fopen(a.argv[1], "rt"); if(!fp){ utils_error("%s - cannot open.\n", a.argv[1]); return F8_FILE_NOT_FOUND; } char buf[2048]; silent = proxy_silent; proxy_silent = __true; while(fgets(buf, sizeof(buf), fp), !feof(fp)){ // buf trimming if(*buf == 0){ continue; } if(*buf == '\r' || *buf=='\n' || *buf=='#'){ continue; } char *p = buf + strlen(buf) - 1; if(*p == '\r' || *p == '\n'){ *p = 0; } kproxy_shell(buf); } fclose(fp); proxy_silent = silent; return F8_SUCCESS; }