REM Module load error handler. REM Run by !Run. Usage is as follows... REM To check RISC-OS 3 or better... REM RMEnsure UtilityModule 3.00 Run .Error REM To change the dialog box title use. : -a"". REM The message is set using switch. : -m"" REM .Error Points to this file. Normal conditions for REM use of SYS"Wimp_ReportError" apply to this. program$="Error Handler":q$=CHR$(34) msg$="v1.01 Syntax : -a"+q$+""+q$+" -m"+q$+""+q$ REM ***** LibCLI Embedded portion. ***** REM Grab our CLI and process it. i%=0 :REM Init our counter. SYS "OS_GetEnv" TO c$ :REM Grab CLI. c$=FNcli_getswitch(c$) :REM Strip out our filespec. REPEAT :REM ** Process command line. switch$=FNcli_extract(c$) :REM Extract a switch. opt$=LEFT$(switch$,2) :REM Get first 2 chars. REM Check against known switches and set program values. CASE opt$ OF WHEN "-a","-A":program$=FNcli_grabquoted(switch$) WHEN "-m","-M":msg$=FNcli_grabquoted(switch$) ENDCASE REM Increment counter. If this is still zero when c$="" then we REM haven't been given any switches. i%+=1 UNTIL c$="" :REM Wash... Rinse... Repeat... REM ***** End of LibCLI Embedded portion. ***** DIM Block 256:Block!0=1234:$(Block+4)=msg$+CHR$0 SYS "Wimp_ReportError",Block,17,program$ END REM Return just the "switch-line." REM c$ : Command line to parse... REM t$ : Temporary store for output... REM i% : Loop counter... REM p% : Position of the first switch in the string... REM q% : If q%=2 then we return the rest of the line... REM Always ignore the first instance (BASIC -quit ) DEFFNcli_getswitch(c$) LOCAL i%,p%,q%,t$ i%=0:p%=0:q%=0 FOR i%=1 TO LEN(c$) IF ASC(MID$(c$,i%,1))=34 THEN q%+=1 IF q%=2 THEN p%=i% ENDIF NEXT i% t$=RIGHT$(c$,LEN(c$)-p%) IF LEFT$(t$,1)=" " THEN =RIGHT$(t$,LEN(t$)-1) =t$ REM Extract a parameter from the command line... REM c$ : Command line to parse... REM out$ : Extracted parameter... REM s% : Position in the string of the first switch... REM ns% : Position in the string of the next switch... REM We subtract s% from ns% to get the length of the parameter to REM return. This starts at position s%. Finally we remove the REM parameter we've just found from the command line. DEFFNcli_extract(RETURN c$) LOCAL t$,s%,ns%,out$ s%=INSTR(c$,"-"):ns%=INSTR(c$,"-",s%+1) out$=MID$(c$,s%,ns%-s%):c$=RIGHT$(c$,LEN(c$)-(ns%-1)) IF c$=out$ THEN c$="" :REM We've just extracted the last one... IF RIGHT$(out$,1)=CHR$(32) THEN =LEFT$(out$,LEN(out$)-1) =out$ REM Extract a quoted string from a parameter. REM p$ : Parameter to parse... REM t$ : Temporary store for string... REM oq% : Position in the string of the first (open) quote. REM cq% : Position in the string of the second (close) quote. REM l% : Length of the string inside the quotes. REM This allows us to use "-" characters in filenames by enclosing REM filespecs in quotes and ignoring "-" that appear in quotes. DEFFNcli_grabquoted(p$) LOCAL t$,oq%,cq%,l% oq%=INSTR(p$,CHR$(34)):l%=0 IF oq%<>0 THEN cq%=INSTR(p$,CHR$(34),oq%+1) IF cq%<>0 THEN l%=(cq%-oq%)-1 ENDIF IF l%=0 THEN ="" =MID$(p$,oq%+1,l%)