   10REM > $.release.!DVIl3p.!Wimpman
   20ExecComm$="Run        "
   30OptComm$= "Set options"
   40Command$="dvil3p -b ": Task$="DVI -> LN3": Menu$="DVIl3p command line": Icon$="S!dvil3p":IconName$="DVIl3p"
   50Last$=""
   60REM For A310, try:
   70REM Command$="commontex \pageno=1\relax\input ":REM Task$="TeX man":REM Menu$="TeX command line":REM Icon$="S!tex":REM IconName$="TeX310"
   80SYS "OS_GetEnv" TO params$
   90DIM buffers% 255,validbuffer% 32,q% 255,taskid% 4,menu% 255,icons%(9),textbuffer% 640,commbuffer% 640
  100END=END+&1000
  110icons%()=-1
  120nicons%=0
  130$validbuffer%=Icon$
  140
  150$taskid%="TASK"
  160SYS "Wimp_Initialise",200,!taskid%,Task$ TO ,ourhandle%:REM Title for task manager display
  170ON ERROR PROCerrorbox
  180p%=INSTR( params$," -quit ")
  190IF p% THEN
  200params$=MID$( params$,p%+LEN" -quit ")
  210WHILE ASC(params$)=32 params$=MID$( params$,2):ENDWHILE
  220IF ASC(params$)=ASC"""" THEN
  230params$=MID$( params$,INSTR( params$,"""",2)+1)
  240ELSE
  250params$=MID$( params$,INSTR( params$," ")+1)
  260ENDIF
  270WHILE params$<>"" AND nicons%<>10
  280WHILE ASC(params$)=32 params$=MID$( params$,2):ENDWHILE
  290IF params$<>"" THEN
  300IF ASC(params$)=ASC"""" THEN
  310p%=INSTR( params$,"""",2)
  320com$=MID$( params$,2,p%-2)
  330params$=MID$( params$,p%+1)
  340ELSE
  350p%=INSTR( params$+" "," ")
  360com$=LEFT$( params$,p%-1)
  370params$=MID$( params$,p%+1)
  380ENDIF
  390PROCnewicon(q%,com$)
  400ENDIF
  410ENDWHILE
  420ELSE
  430PROCnewicon(q%,Command$):REM This is what you get if you BASIC <this file>
  440ENDIF
  450
  460IF nicons%=0 PROCnewicon(q%,Command$):REM Start-up title
  470
  480REPEAT
  490SYS "Wimp_Poll",NOT((3<<17)OR(1<<9)OR(1<<8)OR(1<<6)),q% TO reason%
  500CASE reason% OF
  510WHEN 6:PROCmousebutton(q%)
  520WHEN 9:PROCmenuselect(q%)
  530WHEN 17,18:PROCmessage(q%)
  540ENDCASE
  550UNTIL 0
  560
  570DEF PROCmessage(q%)
  580CASE q%!16 OF
  590WHEN 0:PROCend
  600WHEN 3:PROCtask
  610ENDCASE
  620ENDPROC
  630
  640DEF PROCtask
  650LOCAL p%,got%
  660IF q%!20=-2 THEN
  670got%=-1
  680WHILE p%<10 AND got%=-1
  690IF icons%(p%)=q%!24 got%=p%
  700p%+=1
  710ENDWHILE
  720IF got%<>-1 THEN
  730PROCrunmoria(FNgetstr(q%+44),got%)
  740ENDIF
  750ENDIF
  760ENDPROC
  770DEF PROCrunmoria(Param$,got%)
  780LOCAL S
  790DIM S LEN(Param$)+1
  800Last$=Param$
  810$S=Param$
  820I=LEN($S)
  830I=I-1:IF S?I <> ASC(".") GOTO 830
  840S?I=13
  860REM  Param$=FNfilename(Param$)
  870SYS "OS_SubstituteArgs",Param$,buffers%,255,$(commbuffer%)+" ",LEN$(commbuffer%)+1
  880SYS "Wimp_SlotSize",-1,-1 TO r0,r1,r2
  890SYS "Wimp_SlotSize",-1,r2: REM Make biggest free lump possible
  900SYS "XWimp_StartTask",buffers%
  910SYS "XWimp_SlotSize",-1,r1: REM Put back how it was if possible
  920OSCLI("Settype "+Param$+".dvi-l3p FF4")
  930ENDPROC
  940
  950
  960DEF PROCnewicon(q%,a$)
  970LOCAL n%
  980IF a$="" a$="Cloned":REM This one never called I suspect...
  990WHILE icons%(n%)<>-1 n%+=1:ENDWHILE
 1000$(textbuffer%)=FNmassage(a$):REM This is what is in the initial type-in window
 1010$(commbuffer%)=a$:REM was massaged here... now done below
 1020q%!0=-1
 1030q%!4=0
 1040q%!8=-16
 1050q%!12=128
 1060q%!16=88
 1070q%!20=(1 << 28)OR(7 << 24)OR(3 << 12)OR(1 << 8)OR(1 << 5)OR(1 << 3)OR(3)
 1080q%!24=textbuffer%:REM If use textbuffer here, don't get 1st correct occurance of name after typing it in.
 1090REMBUG swapped buffs in 950, massaged 870
 1100q%!28=validbuffer%
 1110q%!32=64
 1120SYS "Wimp_CreateIcon",,q% TO icons%(n%)
 1130REM$(commbuffer%)=FNmassage(a$):REM This is what is on the initial CLI Icon
 1140q%!24=commbuffer%:REM TESTING BUG: changed from comm->text
 1150nicons%+=1
 1160ENDPROC
 1170
 1180DEF FNgetstr(a%)
 1190LOCAL a$
 1200WHILE ?a% a$+=CHR$?a%:a%+=1:ENDWHILE
 1210=a$
 1220
 1230DEF PROCerrorbox
 1240SYS "Wimp_DragBox",,-1
 1250!buffers%=ERR:$(buffers%+4)=REPORT$+" at line "+STR$ERL+CHR$ 0
 1260SYS "Wimp_ReportError",buffers%,1,Task$
 1270PROCend
 1280ENDPROC
 1290
 1300DEF PROCmakemenu
 1310$menu%=Menu$:REM Title at top of menu when called up
 1320menu%?12=7
 1330menu%?13=2
 1340menu%?14=7
 1350menu%?15=0
 1360menu%!16=188
 1370menu%!20=40
 1380menu%!24=0
 1390m%=menu%+28
 1400m%!0=0
 1410m%!4=-1
 1420m%!8=(7<<24)OR(-(nicons%=10)<<22)OR(1)
 1430$(m%+12)=ExecComm$
 1440m%+=24
 1450m%!0=0
 1460m%!4=m%+48
 1470m%!8=(7<<24)OR(1)
 1480$(m%+12)=OptComm$
 1490m%+=24
 1500m%!0=&80
 1510m%!4=-1
 1520m%!8=(7<<24)OR(1)
 1530$(m%+12)="Quit       "
 1540m%+=24
 1550$m%="Command"
 1560m%?12=7
 1570m%?13=2
 1580m%?14=7
 1590m%?15=0
 1600m%!16=160
 1610m%!20=40
 1620m%!24=0
 1630m%+=28
 1640m%!0=&84
 1650m%!4=-1
 1660m%!8=(7<<24)OR(1<<8)OR(1)
 1670m%!12=buffers%
 1680m%!16=-1
 1690m%!20=64
 1700$buffers%=$(commbuffer%):REM BUG use which? <tested other one>
 1710ENDPROC
 1720
 1730DEF PROCmousebutton(q%)
 1740LOCAL p%,got%
 1750got%=-1
 1760IF q%!12=-2 THEN
 1770WHILE p%<10 AND got%=-1
 1780IF icons%(p%)=q%!16 got%=p%
 1790p%+=1
 1800ENDWHILE
 1810IF got%<>-1 THEN
 1820CASE q%!8 OF
 1830WHEN 2:menuicon%=got%
 1840PROCmakemenu
 1850SYS "Wimp_CreateMenu",,menu%,(q%!0)-64,216
 1860WHEN 1,4: PROCrunmoria(Last$,got%)
 1870ENDCASE
 1880ENDIF
 1890ENDIF
 1900ENDPROC
 1910
 1920DEF FNmassage(Name$):=IconName$
 1930LOCAL S         :REM Where does name get changed?
 1940DIM S LEN(Name$)+1
 1950$S=Name$
 1960LOCAL I:I=S
 1970WHILE ((?I <> 32) AND (?I <> 13)):  I=I+1:  ENDWHILE
 1980?I=13:=$S
 1990
 2000DEF PROCmenuselect(q%)
 2010CASE q%!0 OF
 2020WHEN 0:PROCrunmoria(Last$,1): REM Assume 1st copy of icon??? BUG 1 or 0?
 2030WHEN 1:$(textbuffer%)=$(buffers%):REM This is what is put up in the type-in window
 2040$(textbuffer%)=FNmassage($(buffers%)):REM This is what is put up after changing the command, but after execution the display shows the actual command :(
 2050REM BUG THE ABOVE LOOKS DAFT!!!   (when it was comm...)
 2060q%!0=-2:q%!4=icons%(menuicon%):q%!8=0:q%!12=0:SYS "Wimp_SetIconState",,q%
 2070$(commbuffer%)=$(buffers%):REM This is the string that actually gets executed!
 2080$(textbuffer%)=FNmassage($(buffers%))
 2090REM THE LINE ABOVE SETS COMMAND FROM TYPE-IN STRING - WHAT ABOUT MASSAGE BU
 2100PROCremenu
 2110WHEN 2:q%!0=-2:q%!4=icons%(menuicon%):SYS "Wimp_DeleteIcon",,q%
 2120icons%(menuicon%)=-1
 2130nicons%-=1
 2140IF nicons%=0 PROCend
 2150ENDCASE
 2160ENDPROC
 2170
 2180DEF PROCremenu
 2190SYS "Wimp_GetPointerInfo",,q%
 2200IF q%!8=1 PROCmakemenu:SYS "Wimp_CreateMenu",,menu%,q%!0,q%!4
 2210ENDPROC
 2220
 2230DEF PROCend
 2240SYS"Wimp_CloseDown",ourhandle%,!taskid%:END
 2250ENDPROC
 2260
 2270DEF FNfilename(F$)
 2280LOCAL F
 2290DIM F LEN(F$)+1
 2300$F=F$
 2310LOCAL S:S=F
 2320WHILE (?S <> 13): S=S+1: ENDWHILE
 2330WHILE (?S <> ASC(".")): S=S-1: ENDWHILE
 2340S=S+1
 2350=$S
