#include "defs.h" #define TESTFILE "/players/"+this_player()->query_real_name()+"/_test.c" int show,dontkill; mixed arg; main(str) { object ob; string file; int error; SECURE show=0; dontkill=0; arg=0; if(!str) return usage(); str=parse_args(str); if(!str) WRITE1("Aborted.\n"); if(show) WRITE1(before()+str+after()); file=TESTFILE; if(file_size(file)>0 && dontkill) WRITE1("Aborted. "+file+" already exists. (remove first)\n"); write_file(file,before()+str+after()); if((ob=find_object(file))) destruct(ob); /* update */ error=catch(file->main(arg)); if(error) write("Error occured: "+error+"\n"); rm(file); return 1; } parse_args(str) { string pre,rest,flags; if(sscanf(str,"%sABORT%s",pre,rest)==2) return 0; if(sscanf(str,"-%s %s",flags,rest)==2) { str=rest; if(sscanf(flags,"%ss%s",pre,rest)==2) show=1; if(sscanf(flags,"%sd%s",pre,rest)==2) dontkill=1; if(sscanf(flags,"%sa",pre)==1) if((sscanf(str,"\"%s\" %s",arg,str)!=2) && (sscanf(str,"%s %s",arg,str)!=2)) { usage(); return 0; } } return str; } usage() { write("Usage: lpc [-flags] "); write("[Allow testing of one line of LPC code]\n\n"); write("lpc tests a line of code inside the function main()\n"); write("file: "+TESTFILE+" (will be removed)\n"); write("flags: s: just write file\n"); write(" d: don't overwrite file if it exists\n"); write(" a : use arg to call main() (must be last flag)\n"); write("\nThese macros may be used: \n"+defines()+"\n"); write("These variables are set for you: \n"+vars()+"\n"); write("Also, if \"ABORT\" is found in the line, lpc will be aborted.\n"); write("\nEx: lpc a=users();for(i=0;i