// this is the good note.c // 10/24/02: // Alright, finally found out how to work save_object() :-D , now all // that needs to be done is add non-numeric support for filenames :-\ // 10/16/02: // just trying to figure out how the hell to use save_object() and // have it save STRING TITLE and STRING DATA // -johndoe #include inherit DAEMON ; #define SYNTAX " Usage: note [1/2/3] \n Save: 1 [title, data -saveas filename] \n View: 2 [path extention] \n Restore: 3 [path filename]\n" #define EXAMPLE " Example Usage:\n note 1 Hello!, This is just a note -saveas hello!\n note 2\n note 3 hello!\n\n" int disp(string title, string data); int save(string file); int save(string str); int view(); int restore(string str); mapping globals = ([]); //Gtitle,Gdata,Gfile,Gauthor, Gtime; int cmd_note(string str, int option) { notify_fail("\n\t\t=====Syntax=====\n"+ SYNTAX + "\n" + EXAMPLE ); if(str == ""||!str) return 0; sscanf(str,"%d",option); switch(option) { case 1:save(str); ; break; case 2:view(); ; break; case 3:restore(str); ; break; case 0:write(EXAMPLE); break; default:write( "\n\t\t=====Syntax=====\n"+ SYNTAX +"\n"+EXAMPLE ); break; } return 1; } int save(string str, string title, string data, string file, string fp) { string d,m,str2; int dd,hh,mm,ss,yyyy; str2=ctime(time()); sscanf(str2,"%s %s %d %d:%d:%d %d", d,m,dd,hh,mm,ss,yyyy); sscanf(str,"1 %s, %s -saveas %s",title,data,file); if(!title||!data){write( SYNTAX );return 0;} if(!file||file=="")file="note"; fp="/tmp/note/"+file; write("Data saved to:"+fp+".o\n"); globals["Gtitle"] = title; globals["Gdata"] = data; globals["Gfile"] = fp+".o"; globals["Gauthor"] = this_player()->query("name"); globals["Gtime"] = m+" "+dd+","+yyyy+" ["+hh+":"+mm+"]"; disp(title,data); save_object(fp); return 1; } int view(string path,string ext, string name, string type, string pat, string *gdir, int i, int x, int p,int t, string a, string fp) { p = 0; path="/tmp/note/"; ext=".o"; gdir = get_dir(path); write("\nList of saved notes:\n\n"); write(" Name Author Date \n"); write(" -----------------------------------------------\n"); for(i=0,x=sizeof(gdir);i=6) write(" "+name+"\t"+a+"\t\t"+t+"\n"); if(sizeof(a)<6) write(" "+name+"\t"+a+"\t"+t+"\n"); } } write("\n"); return 1; } int restore(string str, string path, string file, string fp, string title, string data) { sscanf(str,"3 %s",file); if(!file||file==""){write( SYNTAX );return 0;} if(!path||path=="")path="/tmp/note/"; fp=path+file; write("Loading "+fp+"\n"); restore_object(fp); title = globals["Gtitle"]; data = globals["Gdata"]; disp(title,data); return 1; } int disp(string title, string data) { notify_fail( SYNTAX ); if(!title && !data || title=="" && data==""){return 0;} for(int a=0;a<70;a++)write("-"); write("\nTitle: "+globals["Gtitle"]+""); write("\nAuthor: "+globals["Gauthor"]+""); write("\nDate: "+globals["Gtime"]+"\n"); for(int b=0;b<70;b++)write("-"); write("\n\t\t\t\tMESSAGE\n"); for(int d=0;d<70;d++)write("-"); write("\n"+globals["Gdata"]+"\n\n"); } int help() { write("\n It is a notepad which is under construction...\n") ; write(SYNTAX); write(EXAMPLE); return 1; }