Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: nvalias.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | id: @(#)nvalias.fth 1.3 98/04/08 | |
43 | purpose: Implements the nvalias persistent devalias feature | |
44 | copyright: Copyright 1992-1998 Sun Microsystems, Inc. All Rights Reserved | |
45 | ||
46 | \ "Permanent" devaliases | |
47 | ||
48 | unexported-words | |
49 | ||
50 | also hidden | |
51 | ||
52 | : next-field ( str -- rem-str first-str ) -leading bl left-parse-string ; | |
53 | ||
54 | \ True if the current line contains a devalias command with the | |
55 | \ same name as the one we're looking for. | |
56 | ||
57 | : this-alias? ( name-str -- name-str flag ) | |
58 | after next-field ( name-str rem-str first-field-str ) | |
59 | " devalias" $= if ( name-str rem-str ) | |
60 | next-field ( name-str rem-str' 2nd-field-str ) | |
61 | 5 pick 5 pick $= if ( name-str rem-str' ) | |
62 | 2drop true exit ( name-str true ) | |
63 | then ( name-str rem-str' ) | |
64 | then ( name-str rem-str ) | |
65 | 2drop false ( name-str false ) | |
66 | ; | |
67 | ||
68 | \ delete-old-alias leaves the cursor at the beginning of an empty line. | |
69 | \ If there was already an alias of the indicated name, it is deleted | |
70 | \ and the cursor is left on that line. Otherwise, a new line is | |
71 | \ created at the end of the file, and the cursor is left on that line. | |
72 | ||
73 | : delete-old-alias ( name-str -- ) | |
74 | buflen @ 0= if 2drop exit then | |
75 | begin | |
76 | this-alias? if ( name-str ) | |
77 | 2drop ( ) | |
78 | kill-to-end-of-line | |
79 | kill-to-end-of-line exit | |
80 | then ( name-str ) | |
81 | last-line? 0= while ( name-str ) | |
82 | next-line beginning-of-line ( name-str ) | |
83 | repeat ( name-str ) | |
84 | 2drop ( ) | |
85 | beginning-of-file | |
86 | ; | |
87 | ||
88 | : safe-insert ( adr len -- ) | |
89 | tuck (insert-characters) ( len actual ) | |
90 | dup forward-characters ( len actual ) | |
91 | <> if -1 throw then ( len ) | |
92 | ; | |
93 | : make-new-alias ( name-str path-str -- ) | |
94 | " devalias " safe-insert ( name-str path-str ) | |
95 | 2swap safe-insert ( path-str ) | |
96 | " " safe-insert ( path-str ) | |
97 | safe-insert ( ) | |
98 | split-line ( ) | |
99 | ; | |
100 | ||
101 | : get-field ( adr len -- rem-adr rem-len name-adr name-len ) | |
102 | next-field dup 0= abort" Usage: nvalias name path" | |
103 | ; | |
104 | ||
105 | : edit-nvramrc ( -- ) | |
106 | nvramrc-buffer if | |
107 | ." 'nvalias' and 'nvunalias' cannot be executed while 'nvedit' is in progress." cr | |
108 | ." Use 'nvstore' or 'nvquit' to finish editing nvramrc, then try again." cr | |
109 | abort | |
110 | then | |
111 | ||
112 | allocate-buffer | |
113 | nvbuf nvramrc-allocd 0 0 false start-edit | |
114 | ; | |
115 | ||
116 | previous | |
117 | exported-headers | |
118 | ||
119 | \ Creates a "devalias <name> <path>" command line in nvramrc, with name | |
120 | \ and path fields given by the two strings on the stack. If nvramrc already | |
121 | \ contains a devalias line with the same name, that entry is first deleted, | |
122 | \ and the new entry replaces it at the same location in nvramrc. Otherwise, | |
123 | \ the new entry is placed at the beginning of nvramrc. | |
124 | \ | |
125 | \ If there is insufficient space in nvramrc for the new devalias command, | |
126 | \ a message to that effect is displayed and $nvalias aborts without | |
127 | \ modifying nvramrc. | |
128 | \ | |
129 | \ If nvramrc was successfully modified, the new "devalias" command is | |
130 | \ executed immediately, creating a new memory-resident alias. | |
131 | \ | |
132 | \ If nvramrc is currently being edited (i.e. nvedit has been executed, | |
133 | \ but has not been completed with either nvstore or nvquit), $nvalias | |
134 | \ aborts with an error message before taking any other action. | |
135 | ||
136 | : $nvalias ( name-str path-str -- ) | |
137 | edit-nvramrc | |
138 | ||
139 | [ also hidden ] | |
140 | ||
141 | 2over delete-old-alias ( name-str path-str ) | |
142 | 2over 2over ['] make-new-alias catch if ( ? ) | |
143 | finish-edit drop | |
144 | deallocate-buffer | |
145 | true abort" Can't create new alias because nvramrc is full" | |
146 | then ( name-str path-str ) | |
147 | ||
148 | $devalias ( ) | |
149 | ||
150 | nvramrc-buffer finish-edit ( adr len ) to nvramrc | |
151 | true to use-nvramrc? | |
152 | ||
153 | [ previous ] | |
154 | deallocate-buffer | |
155 | ; | |
156 | ||
157 | \ nvalias is like $nvalias, except that the name and path arguments is taken | |
158 | \ from the command line following the nvalias command, instead of from | |
159 | \ the stack. | |
160 | ||
161 | : nvalias \ name path ( -- ) | |
162 | optional-arg$ get-field ( rem-str name-str ) | |
163 | 2swap get-field 2swap 2drop ( name-str path-str ) | |
164 | $nvalias | |
165 | ; | |
166 | ||
167 | \ If nvramrc contains a "devalias" command line with the same name | |
168 | \ as the string on the stack, $nvunalias deletes that line. Otherwise, | |
169 | \ nvramrc remains unchanged. | |
170 | \ | |
171 | \ $nvunalias aborts with an error message if nvramrc is currently being edited, | |
172 | \ i.e. nvedit has been executed, but has not been completed with either | |
173 | \ nvstore or nvquit. | |
174 | ||
175 | : $nvunalias ( name-str -- ) | |
176 | edit-nvramrc delete-old-alias | |
177 | ||
178 | [ also hidden ] | |
179 | nvramrc-buffer finish-edit to nvramrc | |
180 | [ previous ] | |
181 | ||
182 | deallocate-buffer | |
183 | ; | |
184 | ||
185 | \ nvunalias is like $nvalias, except that the name argument is taken | |
186 | \ from the command line following the nvunalias command, instead of from | |
187 | \ the stack. | |
188 | ||
189 | : nvunalias \ name ( -- ) | |
190 | optional-arg$ get-field ( rem-str name-str ) | |
191 | 2swap 2drop $nvunalias | |
192 | ; | |
193 | ||
194 | unexported-words | |
195 | ||
196 |