home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 3
/
goldfish_volume_3.bin
/
files
/
dev
/
e
/
amigae
/
src
/
various
/
dokkenou
/
dokkenou.e
(
.txt
)
< prev
next >
Wrap
LaTeX Document
|
1992-09-02
|
5KB
|
198 lines
-> 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<snum THEN slist[scur+n] ELSE ''
PROC getnext() IS scur++ BUT IF scur<snum THEN slist[scur] ELSE Raise("EOF")
#define GETCUR slist[scur]
#define SKIP scur++
#define BACK scur--
PROC put(s) IS Fputs(ofh,s)
PROC putln(s) IS Fputs(ofh,s) BUT FputC(ofh,"\n")
PROC iswhite(c) IS (c=" ") OR (c="\t")
PROC isnotwhite(c) IS (c<>" ") 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 sp<indent THEN RETURN
spn,sn:=spaces(next(1))
IF StrCmp(sn,'====',STRLEN)
put('\\section{'); put(details(s)); put('}\n')
SKIP
ELSEIF StrCmp(sn,'----',STRLEN)
put('\\subsection{'); put(details(s)); put('}\n')
SKIP
ELSEIF StrCmp(sn,'****',STRLEN)
put('\\subsubsection{'); put(details(s)); put('}\n')
SKIP
ELSEIF (s[]=">") AND iswhite(s[1])
verbatim(s)
ELSEIF ((s[]="*") OR (s[]="-")) AND iswhite(s[1])
itemize(s,s[],sp)
ELSE
putln(details(s))
ENDIF
s:=getnext()
ENDLOOP
ENDPROC
PROC itemize(s,ic,ind) HANDLE
DEF d
put('\\begin{itemize}\n')
REPEAT
put('\\item ')
putln(details(s+2))
SKIP
process(ind+2)
d,s:=spaces(GETCUR)
UNTIL (s[]<>ic) 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