| 1 | REM |
| 2 | REM SapphStub |
| 3 | REM |
| 4 | REM Build Sapphire extension stub entries |
| 5 | REM |
| 6 | REM © 1994-1998 Straylight |
| 7 | REM |
| 8 | |
| 9 | REM ----- Licensing note ---------------------------------------------------- |
| 10 | REM |
| 11 | REM This file is part of Straylight's core utilities (coreutils) |
| 12 | REM |
| 13 | REM Coreutils is free software; you can redistribute it and/or modify |
| 14 | REM it under the terms of the GNU General Public License as published by |
| 15 | REM the Free Software Foundation; either version 2, or (at your option) |
| 16 | REM any later version |
| 17 | REM |
| 18 | REM Coreutils is distributed in the hope that it will be useful, |
| 19 | REM but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | REM GNU General Public License for more details. |
| 22 | REM |
| 23 | REM You should have received a copy of the GNU General Public License |
| 24 | REM along with Coreutils. If not, write to the Free Software Foundation, |
| 25 | REM 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 26 | |
| 27 | REM --- Parse arguments --- |
| 28 | |
| 29 | ON ERROR ERROR EXT 0,REPORT$+"["+STR$(ERL)+"]" |
| 30 | PROCinit |
| 31 | PROCparse(FNreadCommandLine) |
| 32 | END |
| 33 | |
| 34 | DEF PROCinit |
| 35 | DIM q% 256 |
| 36 | LIBRARY "libs:bas" |
| 37 | PROCbas_init |
| 38 | ENDPROC |
| 39 | |
| 40 | REM --- Read a command line --- |
| 41 | |
| 42 | DEF FNreadCommandLine |
| 43 | LOCAL comm$ |
| 44 | SYS "OS_GetEnv" TO comm$ |
| 45 | IF INSTR(comm$,"-quit")=0 THEN ERROR 1,"SapphStub must be started using *Run" |
| 46 | comm$=MID$(comm$,INSTR(comm$,"""")+1) |
| 47 | comm$=MID$(comm$,INSTR(comm$," ")+1) |
| 48 | comm$=LEFT$(comm$,INSTR(comm$,"""")-1) |
| 49 | =comm$ |
| 50 | |
| 51 | REM --- Remove a word from a command line --- |
| 52 | |
| 53 | DEF FNword(RETURN line$) |
| 54 | LOCAL word$ |
| 55 | IF INSTR(line$," ") THEN |
| 56 | word$=LEFT$(line$,INSTR(line$," ")-1) |
| 57 | line$=MID$(line$,INSTR(line$," ")+1) |
| 58 | ELSE |
| 59 | word$=line$ |
| 60 | line$="" |
| 61 | ENDIF |
| 62 | =word$ |
| 63 | |
| 64 | REM --- Convert a string to upper case --- |
| 65 | |
| 66 | DEF FNupper(line$) |
| 67 | LOCAL i% |
| 68 | $q%=line$ |
| 69 | FOR i%=0 TO LEN(line$)-1 |
| 70 | IF q%?i%>=97 AND q%?i%<=122 THEN q%?i%-=32 |
| 71 | NEXT |
| 72 | =$q% |
| 73 | |
| 74 | REM --- Do the command line parsing --- |
| 75 | |
| 76 | DEF PROCparse(line$) |
| 77 | LOCAL libfn$,stub$,lib$,off%,helped%,word$ |
| 78 | REPEAT |
| 79 | word$=FNword(line$) |
| 80 | CASE FNupper(word$) OF |
| 81 | WHEN "-HELP" |
| 82 | PROCshowHelp |
| 83 | helped%=TRUE |
| 84 | WHEN "-LIBFN" |
| 85 | libfn$=FNword(line$) |
| 86 | WHEN "-LIB" |
| 87 | lib$=FNword(line$) |
| 88 | WHEN "-STUB" |
| 89 | stub$=FNword(line$) |
| 90 | WHEN "-OFFSET" |
| 91 | off%=VAL(FNword(line$)) |
| 92 | OTHERWISE |
| 93 | CASE TRUE OF |
| 94 | WHEN lib$="" |
| 95 | lib$=word$ |
| 96 | WHEN stub$="" |
| 97 | stub$=word$ |
| 98 | WHEN libfn$="" |
| 99 | libfn$=word$ |
| 100 | WHEN off%=0 |
| 101 | off%=VAL(word$) |
| 102 | ENDCASE |
| 103 | ENDCASE |
| 104 | UNTIL line$="" |
| 105 | IF helped% THEN END |
| 106 | IF libfn$="" OR lib$="" OR stub$="" THEN ERROR 0,"Bad arguments" |
| 107 | PROCbuild(lib$,stub$,libfn$,off%) |
| 108 | ENDPROC |
| 109 | |
| 110 | DEF PROCbuild(lib$,stub$,libfn$,off%) |
| 111 | |
| 112 | REM --- Build library section --- |
| 113 | |
| 114 | zero=0 |
| 115 | |
| 116 | PROCbas_aofInit(&1000) |
| 117 | FOR o=4 TO 6 STEP 2 |
| 118 | [ opt o |
| 119 | FNpass |
| 120 | |
| 121 | FNimportAs("Sapphire$$LibData$$Base","sapph_base") |
| 122 | FNimportAs("Sapphire$$LibData$$Limit","sapph_limit") |
| 123 | |
| 124 | FNarea("!Stub$$Code","CODE,READONLY") |
| 125 | |
| 126 | FNexportAs("stubfn",libfn$) |
| 127 | .stubfn |
| 128 | adr r0,stubBlock |
| 129 | ldmia r0,{r0-2} |
| 130 | movs pc,r14 |
| 131 | |
| 132 | .stubBlock |
| 133 | dcd sapph_base |
| 134 | dcd sapph_limit |
| 135 | dcd off% |
| 136 | |
| 137 | FNexportAs("zero","sapphire_init") |
| 138 | FNexportAs("zero","sapphire_libInit") |
| 139 | FNexportAs("zero","sapphire_disable") |
| 140 | ] |
| 141 | offDiff%=off%-4 |
| 142 | [ opt o |
| 143 | FNexportAs("offDiff%","__sph_workoff") |
| 144 | ] |
| 145 | NEXT |
| 146 | PROCbas_aofSaveAs(lib$) |
| 147 | |
| 148 | REM --- Build stub section --- |
| 149 | |
| 150 | PROCbas_aofInit(0) |
| 151 | FOR o=4 TO 6 STEP 2 |
| 152 | [ opt o |
| 153 | FNpass |
| 154 | |
| 155 | FNimportAs(libfn$,"stubfn") |
| 156 | |
| 157 | FNarea("Sapphire$$ExtTable","CODE,READONLY") |
| 158 | |
| 159 | dcd stubfn |
| 160 | ] |
| 161 | NEXT |
| 162 | PROCbas_aofSaveAs(stub$) |
| 163 | |
| 164 | ENDPROC |