/* Wp2Rtf, main program, copyright Branko Collin 1997. Use this program for educational purposes only, do not spread a compiled version! */ /* Below comments are in Dutch. They describe the program history. I will translate them as soon as I have got the time. Let me know if you're at all interested! Wat gedaan is: -Een GUI geimplementeerd -De Quit-button geimplementeerd -De About-button geimplementeerd -De invoer- en uitvoer-buttons implementeren -De convert-button implementeren: -een tokeniser implementeren -een compiler implementeren -requestfile() een eventueel bestaande lade en/of bestandsnaam meegeven. Verholpen bugs: -De bug verwijderen die er voor zorgt dat requestfile() geen lade teruggeeft. Wat gedaan moet worden: -De bug verwijderen die er voor zorgt dat Word de laatste regels van de Guust.w42 conversie niet begrijpt. -de outfunctie laten controleren op bestaande bestanden en vragen of de user een bestaand bestand wil overschrijven. -Controles op alles wat los en vast zit implementeren -Functionaliteitstesten ontwerpen -Functionaliteitstesten uitvoeren (v.0.2) -Een plan opstellen om de source te stroomlijnen -Source stroomlijnen (v.0.3) -Alfatesten -Betatesten -Public release (v.1.0) */ /* WP2RTF (c) 1996 Branko Collin first version: 24-12-1996 v.0.1 latest version: 31-12-1996 v.0.1 This program will try to convert WP4.2 for DOS documents to RTF documents. Some of its features or lack of features are: -No complete implementation -WP side undocumented -Input is read as a whole, output is buffered -GUI-driven */ MODULE 'tools/easygui', 'Asl', 'libraries/Asl', 'tools/exceptions', 'workbench/startup', '*convert' ENUM EG_INREQ=1, EG_INSTR, EG_OUTREQ, EG_OUTSTR, EG_CONVERT, EG_ABOUT, EG_QUIT=0 ENUM ERR_NONE, ERR_ASL, ERR_KICK, ERR_LIB, ERR_SCRN, ERR_WIN RAISE ERR_ASL IF AllocAslRequest()=NIL, ERR_LIB IF OpenLibrary()=NIL CONST MC=256 DEF infile,outfile,gh=NIL:PTR TO guihandle DEF ingad,outgad DEF outpath, inpath PROC main() HANDLE DEF res=-1 infile:=String(MC) outfile:=String(MC) inpath:=String(MC) outpath:=String(MC) parseargs() aslbase:=OpenLibrary('asl.library',37) gh:=guiinit('WP to RTF converter by Branko Collin', [ROWS, [COLS, [BEVEL,[BUTTON,{inreq},'In']], ingad:=[STR,{instr},NIL,infile,MC,20] ], [COLS, [BEVEL,[BUTTON,{outreq},'Out']], outgad:=[STR,{outstr},NIL,outfile,MC,20] ], [BUTTON,{convertmain},'Convert'], [BUTTON,{about},'About'], [BUTTON,EG_QUIT,'Quit'] ] ) IF CtrlC() THEN CleanUp(0) WHILE res<0 Wait(gh.sig) res:=guimessage(gh) ENDWHILE EXCEPT DO CloseLibrary(aslbase) cleangui(gh) ReThrow() ENDPROC PROC inreq() HANDLE DEF req:PTR TO filerequester IF (req:=requestfile('Select a WP file.','#?.w(p|41|42)',inpath)) StrCopy(infile,req.drawer) StrCopy(inpath,req.drawer) AddPart(infile,req.file,MC) setstr(gh,ingad,infile) ENDIF EXCEPT DO report_exception() ENDPROC PROC instr() HANDLE setstr(gh,ingad,infile) EXCEPT DO report_exception() ENDPROC PROC outreq() HANDLE DEF req:PTR TO filerequester IF (req:=requestfile('Enter the name of the RTF file','#?.rtf',outpath)) StrCopy(outfile,req.drawer) StrCopy(outpath,req.drawer) AddPart(outfile,req.file,MC) setstr(gh,outgad,outfile) ENDIF EXCEPT DO report_exception() ENDPROC PROC outstr() HANDLE setstr(gh,outgad,outfile) EXCEPT DO report_exception() ENDPROC PROC convertmain() HANDLE DEF dummy, check, subcheck1, subcheck2 subcheck1:=namecheck(infile) subcheck2:=namecheck(outfile) check:=(subcheck1=TRUE) AND (subcheck2=TRUE) IF check=TRUE WriteF('Converting...\n') convert(infile,outfile) WriteF('Done!\n') ELSEIF subcheck1=FALSE IF subcheck2=FALSE dummy:=easygui('Convert', [BUTTON,0,'Enter valid in- and outputfiles'] ) ELSE dummy:=easygui('Convert', [BUTTON,0,'Enter a valid inputfile'] ) ENDIF ELSE dummy:=easygui('Convert', [BUTTON,0,'Enter a valid outputfile'] ) ENDIF EXCEPT DO report_exception() ENDPROC PROC namecheck(name) HANDLE DEF result=TRUE,length,char length:=EstrLen(name) IF length=0 result:=FALSE ELSE char:=String(1) RightStr(char,name,1) WriteF('tested character: \s (value: \d)\n',char,char[0]) IF StrCmp(char,':') THEN result:=FALSE IF StrCmp(char,'/') THEN result:=FALSE ENDIF EXCEPT DO report_exception() ENDPROC result PROC about() HANDLE DEF dummy dummy:=easygui('About...', [ROWS, [BEVEL, [ROWS, [TEXT,'WP2RTF v.0.1.',NIL,FALSE,1], [TEXT,'copyright 1996 by Branko Collin',NIL,FALSE,1], [TEXT,' ',NIL,FALSE,1], [TEXT,'WP2RTF tries to convert WordPerfect 4.2',NIL,FALSE,16], [TEXT,'for Dos documents to the RTF-format.',NIL,FALSE,1], [TEXT,'Enter the name of the WP-document in ',NIL,FALSE,1], [TEXT,'the \qIN\q field or press the \qIN\q',NIL,FALSE,1], [TEXT,'button. Enter a name for the RTF file',NIL,FALSE,1], [TEXT,'in a similar manner in the \qOUT\q field.',NIL,FALSE,1], [TEXT,'Press \qconvert\q to start the conversion',NIL,FALSE,1], [TEXT,'process.',NIL,FALSE,1], [TEXT,'See the accompagnying document for more',NIL,FALSE,1], [TEXT,'details.',NIL,FALSE,1] ] ], [BUTTON,0,'OK'] ]) EXCEPT DO report_exception() ENDPROC PROC requestfile(title,pattern,path) HANDLE DEF fr=NIL:PTR TO filerequester aslbase:=OpenLibrary('asl.library',37) fr:=AllocAslRequest(ASL_FILEREQUEST, [ASL_HAIL, title, -> Initial pattern string for pattern matching ASL_PATTERN, pattern, -> Initial directory ASL_DIR, path, -> Enable multiselection and pattern match gadget ASL_FUNCFLAGS, FILF_PATGAD, NIL]) -> Put up file requester IF AslRequest(fr, 0) WriteF('PATH=\s FILE=\s\n', fr.drawer, fr.file) ENDIF EXCEPT DO IF fr THEN FreeAslRequest(fr) IF aslbase THEN CloseLibrary(aslbase) SELECT exception CASE ERR_ASL; WriteF('Error: Could not allocate ASL request\n') CASE ERR_LIB; WriteF('Error: Could not open ASL library\n') ENDSELECT ENDPROC fr PROC parseargs() DEF split1,split2, wb:PTR TO wbstartup, args:PTR TO wbarg IF wbmessage=NIL split1:=InStr(arg,' ') IF split1<0 StrCopy(infile,arg) ELSE MidStr(infile,arg,0,split1) split1++ split2:=InStr(arg,' ',split1) IF split2>0 MidStr(outfile,arg,split1,split2-split1) ELSE MidStr(outfile,arg,split1) ENDIF ENDIF ELSE wb:=wbmessage args:=wb.arglist IF wb.numargs>1 StrCopy(infile,args[1].name) ENDIF ENDIF ENDPROC ->End of file