Initial revision
[ssr] / StraySrc / Utilities / s / path_util
1 ;
2 ; path_util.s
3 ;
4 ; A path manipulation utility
5 ;
6 ; © 1994-1998 Straylight
7 ;
8
9 ;----- Licensing note -------------------------------------------------------
10 ;
11 ; This file is part of Straylight's core utilities (coreutils).
12 ;
13 ; Coreutils is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
16 ; any later version.
17 ;
18 ; Coreutils is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
22 ;
23 ; You should have received a copy of the GNU General Public License
24 ; along with Coreutils. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ;----- Standard header ------------------------------------------------------
28
29 GET libs:header
30 GET libs:swis
31
32 ;----- External dependencies ------------------------------------------------
33
34 GET sh.pathUtil
35
36 IMPORT version
37
38 ;----- Main code ------------------------------------------------------------
39
40 AREA |!!!Utility$$Header|,CODE,READONLY
41
42 ; --- Main program ---
43 ;
44 ; Arguments: [-add]|-remove[-path] <pathvar> [-dir] <element>
45 ;
46 ; Use: Adds an element to a path, or removes one.
47
48 main ROUT
49
50 STMFD R13!,{R14} ;Keep the return address safe
51 ADR R0,pu__commDef ;Point to command syntax def
52 MOV R2,R12 ;Point to a workspace buffer
53 MOV R3,#256 ;Size of my buffer thingy
54 SWI XOS_ReadArgs ;Try to understand the string
55 BVS %90main ;If it failed, return error
56
57 ; --- Make sure we got sensible arguments ---
58
59 LDMIA R12,{R10,R11} ;Load the two names
60
61 LDR R14,[R12,#8] ;Load the help flag value
62 CMP R14,#0 ;Is help specified?
63 BNE pu__help ;Yes -- give help then
64
65 LDR R14,[R12,#24] ;Load the fontinstall value
66 CMP R14,#0 ;Does he want to use it?
67 ADRNE R10,pu__fontPath ;Yes -- point to var name
68
69 CMP R11,#0 ;Is there no directory?
70 CMPNE R10,#0 ;Or no path variable?
71 BEQ pu__noDir ;None -- report an error
72
73 ; --- See if user wants GSTransing ---
74
75 MOV R0,R11 ;Point to the name string
76 LDR R14,[R12,#20] ;Load GSTrans flag out
77 CMP R14,#0 ;Does this want doing?
78 BEQ %20main ;No -- skip onwards then
79 ADD R1,R12,#512 ;Point to my GSTrans buffer
80 MOV R2,#256 ;Set the buffer size
81 ORR R2,R2,#&E0000000 ;Set *all* the GSTrans flags
82 SWI XOS_GSTrans ;Translate it nicely
83 ADD R0,R12,#512 ;Point to translated string
84
85 ; --- Do the main bit of processing ---
86
87 20main ADD R11,R12,#256 ;Point to a spare buffer
88 MOV R1,R0 ;Point to directory in R1
89 MOV R0,R10 ;Point to path var in R0
90 MOV R2,#2 ;Path variables are macros
91 LDR R14,[R12,#36] ;Load the create flag
92 CMP R14,#0 ;Do we create the variable?
93 ORRNE R2,R2,#&100 ;Yes -- set the bit then
94 LDR R14,[R12,#16] ;Load the remove flag
95 CMP R14,#0 ;Are we meant to remove it?
96 BLEQ path_addDir ;No -- then add it in
97 BLNE path_removeDir ;Yes -- remove it then
98 BVS %90main ;If it failed, report error
99 BCC %50main ;If nothing done, return
100
101 ; --- If we did fontPath things, update FontManager ---
102
103 LDR R14,[R12,#24] ;Load the fontinstall value
104 CMP R14,#0 ;Does he want to use it?
105 BEQ %50main ;No -- do nothing then
106
107 SWI XHourglass_On ;This could take some time
108 ADR R0,pu__finstall ;Point to command thingy
109 SWI XOS_CLI ;Try to update the font list
110 SWI XHourglass_Off ;And disable hourglass again
111
112 ; --- All done, all sweetness and light ---
113
114 50main LDMFD R13!,{PC}^ ;Return to caller nicely
115
116 pu__fontPath DCB "Font$Path",0
117 pu__finstall DCB "FontInstall",0
118
119 ; --- Someone threw a spanner in the works ---
120
121 90main LDMFD R13!,{R14} ;Restore the link register
122 ORRS PC,R14,#V_flag ;And return the error
123
124 ; --- The command definition table ---
125
126 pu__commDef DCB "path," ;Offset 0 p
127 DCB "dir," ;Offset 4 d
128
129 DCB "help/S," ;Offset 8 h
130 DCB "add/S," ;Offset 12 a
131 DCB "remove/S," ;Offset 16 r
132 DCB "GS=GSTrans/S," ;Offset 20 g
133 DCB "fInstall=fontPath/S," ;Offset 24 f
134 DCB "create/S," ;Offset 28 c
135 DCB 0
136
137 ; --- Our arguments weren't done right ---
138
139 pu__noDir ADR R0,pu__errNoDir ;Point to the error message
140 B %90main ;And report it as usual
141
142 pu__errNoDir DCD 1
143 DCB "Syntax: PathUtil [<options>] "
144 DCB "[-path] <pathvar> [-dir] <directory>",0
145
146 ; --- User wanted a helping hand ---
147
148 pu__help ADR R0,pu__helpText ;Point to the help text
149 MOV R1,#0 ;Don't use a dictionary
150 LDR R2,=version ;Point to version/cright
151 ADR R14,main ;Point to code base
152 ADD R2,R14,R2 ;And point to the help text
153 SWI XOS_PrettyPrint ;Print it on the screen
154 LDMFD R13!,{PC}^ ;And return to caller
155
156 pu__helpText DCB "PathUtil ",27,0,13
157 DCB 13
158 DCB "Syntax: PathUtil [<options>] "
159 DCB "[-path] <pathvar> [-dir] <directory>",13
160 DCB 13
161 DCB "By default, adds a path element to the given path "
162 DCB "variable. If the element is already included, "
163 DCB "PathUtil does nothing.",13
164 DCB 13
165 DCB "Options (which may be abbreviated) are as "
166 DCB "follows:",13
167 DCB 13
168 DCB "-help",9,9,"Display this help text",13
169 DCB "-add",9,9,"Add directory to path (default)",13
170 DCB "-remove",9,9,"Remove directory from path",13
171 DCB "-gsTrans",9,"Translate directory before adding",13
172 DCB "-fontPath",9,"Use Font$Path as path variable",13
173 DCB "-create",9,9,"Force creation of path variable",13
174 DCB 0
175
176 ;----- That's all, folks ----------------------------------------------------
177
178 END