-> DokkeNou! OPT OSVERSION=37, PREPROCESS MODULE 'tools/file', 'tools/ctype' DEF slist:PTR TO LONG,snum,scur=0,ofh=NIL,tabwidth=8, detailstemp[1000]:STRING,style PROC main() HANDLE DEF m=NIL,l,args:PTR TO LONG,rdargs=NIL,texf[100]:STRING,x args:=[0,0,0,0,0,0] IF (rdargs:=ReadArgs('TEXT/A,TEXFILE,TABWIDTH/K/N,STYLE,A4/S,A4COL/S',args,NIL))=NIL THEN Raise("ARGS") IF args[1] texf:=args[1] ELSE IF (x:=InStr(args[0],'.'))<1 THEN x:=ALL StrCopy(texf,args[0],x) StrAdd(texf,'.tex') ENDIF IF args[2] THEN tabwidth:=Long(args[2]) style:=IF args[3] THEN args[3] ELSE '' IF args[4] THEN style:='[a4din]' IF args[5] THEN style:='[a4din,twocolumn]' WriteF('DokkeNou! (c) 1994 Text2Tex conversion by Wouter\n' + 'converting "\s" to "\s"\n',args[0],texf) m,l:=readfile(args[0]) snum:=countstrings(m,l) slist:=stringsinfile(m,l,snum) IF (ofh:=Open(texf,NEWFILE))=NIL THEN Raise("OPEN") all() EXCEPT DO IF rdargs THEN FreeArgs(rdargs) IF m THEN freefile(m) IF ofh THEN Close(ofh) SELECT exception CASE "ARGS"; WriteF('Bad Args!\n') CASE "EOF"; WriteF('Done.\n') DEFAULT; WriteF('exception: "\s" (\h), info: "\s"\n', [exception,0],exception,IF exceptioninfo THEN exceptioninfo ELSE '') ENDSELECT ENDPROC PROC next(n) IS IF scur+n" ") AND (c<>"\t") PROC spaces(s) DEF n=0 LOOP IF s[]=" " n++ ELSEIF s[]="\t" n:=n+tabwidth ELSE RETURN n,s ENDIF s++ ENDLOOP ENDPROC PROC all() HANDLE DEF str[3]:ARRAY OF LONG,a=0,s,d REPEAT s:=GETCUR d,s:=spaces(s) IF s[] THEN str[a++]:=s getnext() UNTIL a=3 put('% generated by DokkeNou! (tm) text2tex formatting utility (c) Wouter 1994\n\n') put('\\documentstyle') put(style) put('{article}\n') put('\\title{') put(str[0]) put('}\n\\author{') put(str[1]) put('}\n\\date{') put(str[2]) put('}\n') put('\\begin{document}\\maketitle\n') process() EXCEPT DO putln('\\end{document}') ReThrow() ENDPROC PROC process(indent=0) DEF s,sn,sp,spn,numblank=0 s:=GETCUR LOOP s[-1]:=" " IF s[] IF numblank>1 THEN putln('\\vskip .0cm\\noindent ') numblank:=0 ELSE numblank++ ENDIF sp,s:=spaces(s) IF spic) OR isnotwhite(s[1]) BACK EXCEPT DO put('\\end{itemize}\n') ReThrow() ENDPROC PROC verbatim(s) HANDLE DEF d put('\\begin{verbatim}\n') REPEAT putln(s+1) d,s:=spaces(getnext()) UNTIL (s[]<>">") OR isnotwhite(s[1]) BACK EXCEPT DO put('\\end{verbatim}\n') ReThrow() ENDPROC PROC details(s) DEF r IF StrLen(s)>500 THEN RETURN 'TOO LONG' r:=detailstemp s,r:=dodet(s,r,0) r[]:=0 ENDPROC detailstemp PROC dorange(s,r,end,text,c) IF iswhite(s[-2]) AstrCopy(r,text) r:=r+StrLen(text) s,r:=dodet(s,r,end) r[]++:="}" ELSE r[]++:=c ENDIF ENDPROC s,r PROC dodet(s,r,stop) DEF c WHILE c:=s[]++ IF c=stop THEN RETURN s,r SELECT 128 OF c CASE "#","$","%","&","~","^","\\","{","}" ->,"|",">","<" r[]++:="\\" r[]++:=c CASE "[" s,r:=dorange(s,r,"]",'\\footnote{',c) -> footnotes CASE "_" IF isgraph(s[]) s,r:=dorange(s,r,"_",'{\\em ',c) -> emphasized ELSE r[]++:="\\" r[]++:=c ENDIF CASE "*" s,r:=dorange(s,r,"*",'{\\bf ',c) -> bold CASE "`" IF iswhite(s[-2]) -> inline verbatim AstrCopy(r,'\\verb|') r:=r+STRLEN WHILE ((c:=s[]++)<>"'") AND (c<>0) DO r[]++:=c IF c=0 THEN s-- r[]++:="|" ELSE r[]++:=c ENDIF DEFAULT -> normal chars r[]++:=c ENDSELECT ENDWHILE s-- ENDPROC s,r