Skip to content

Commit d15ed62

Browse files
committed
Fit to Plan 9's ANSI/POSIX compatibility layer
That haven't any commands: cut, expr and printf. And its sed(1)'s label is limited to maximum seven characters. Therefore I replaced some labels to drop a character. * close -> cl * continue -> cont (cnt is used for count) * line -> ln * hered -> hdoc * shell -> sh * string -> str Signed-off-by: lufia <[email protected]>
1 parent 22f8f3e commit d15ed62

File tree

3 files changed

+47
-40
lines changed

3 files changed

+47
-40
lines changed

GIT-VERSION-GEN

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ else
2626
VN="$DEF_VER"
2727
fi
2828

29-
VN=$(expr "$VN" : v*'\(.*\)')
29+
VN=${VN#v}
3030

3131
if test -r $GVF
3232
then

generate-cmdlist.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ die () {
66
}
77

88
command_list () {
9-
eval "grep -ve '^#' $exclude_programs" <"$1"
9+
eval "grep -v -e '^#' $exclude_programs" <"$1"
1010
}
1111

1212
get_categories () {
13-
tr ' ' '\n'|
13+
tr ' ' '\012'|
1414
grep -v '^$' |
1515
sort |
1616
uniq
1717
}
1818

1919
category_list () {
2020
command_list "$1" |
21-
cut -c 40- |
21+
awk '{ print substr($0, 40) }' |
2222
get_categories
2323
}
2424

2525
get_synopsis () {
2626
sed -n '
27-
/^NAME/,/'"$1"'/H
27+
/^NAME/,/'"$1"'/h
2828
${
2929
x
3030
s/.*'"$1"' - \(.*\)/N_("\1")/
@@ -60,16 +60,23 @@ define_category_names () {
6060
echo "};"
6161
}
6262

63+
if test -z "$(echo -n)"
64+
then
65+
alias print='echo -n'
66+
else
67+
alias print='printf %s'
68+
fi
69+
6370
print_command_list () {
6471
echo "static struct cmdname_help command_list[] = {"
6572

6673
command_list "$1" |
6774
while read cmd rest
6875
do
69-
printf " { \"$cmd\", $(get_synopsis $cmd), 0"
76+
print " { \"$cmd\", $(get_synopsis $cmd), 0"
7077
for cat in $(echo "$rest" | get_categories)
7178
do
72-
printf " | CAT_$cat"
79+
print " | CAT_$cat"
7380
done
7481
echo " },"
7582
done

t/chainlint.sed

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
/^[ ]*!*[ ]*(..*)[ ]*[0-9]*[<>|&]/boneline
118118

119119
# multi-line "(...\n...)"
120-
/^[ ]*(/bsubshell
120+
/^[ ]*(/bsubsh
121121

122122
# innocuous line -- print it and advance to next line
123123
b
@@ -130,11 +130,11 @@ b
130130
}
131131
b
132132

133-
:subshell
133+
:subsh
134134
# bare "(" line? -- stash for later printing
135135
/^[ ]*([ ]*$/ {
136136
h
137-
bnextline
137+
bnextln
138138
}
139139
# "(..." line -- split off and stash "(", then process "..." as its own line
140140
x
@@ -143,18 +143,18 @@ x
143143
s/(//
144144
bslurp
145145

146-
:nextline
146+
:nextln
147147
N
148148
s/.*\n//
149149

150150
:slurp
151151
# incomplete line "...\"
152152
/\\$/bicmplte
153153
# multi-line quoted string "...\n..."?
154-
/"/bdqstring
154+
/"/bdqstr
155155
# multi-line quoted string '...\n...'? (but not contraction in string "it's")
156156
/'/{
157-
/"[^'"]*'[^'"]*"/!bsqstring
157+
/"[^'"]*'[^'"]*"/!bsqstr
158158
}
159159
:folded
160160
# here-doc -- swallow it
@@ -163,8 +163,8 @@ s/.*\n//
163163
# before closing ")", "done", "elsif", "else", or "fi" will need to be
164164
# re-visited to drop "suspect" marking since final line of those constructs
165165
# legitimately lacks "&&", so "suspect" mark must be removed
166-
/^[ ]*#/bnextline
167-
/^[ ]*$/bnextline
166+
/^[ ]*#/bnextln
167+
/^[ ]*$/bnextln
168168
# in-line comment -- strip it (but not "#" in a string, Bash ${#...} array
169169
# length, or Perforce "//depot/path#42" revision in filespec)
170170
/[ ]#/{
@@ -175,22 +175,22 @@ s/.*\n//
175175
# multi-line "case ... esac"
176176
/^[ ]*case[ ]..*[ ]in/bcase
177177
# multi-line "for ... done" or "while ... done"
178-
/^[ ]*for[ ]..*[ ]in/bcontinue
179-
/^[ ]*while[ ]/bcontinue
180-
/^[ ]*do[ ]/bcontinue
181-
/^[ ]*do[ ]*$/bcontinue
182-
/;[ ]*do/bcontinue
178+
/^[ ]*for[ ]..*[ ]in/bcont
179+
/^[ ]*while[ ]/bcont
180+
/^[ ]*do[ ]/bcont
181+
/^[ ]*do[ ]*$/bcont
182+
/;[ ]*do/bcont
183183
/^[ ]*done[ ]*&&[ ]*$/bdone
184184
/^[ ]*done[ ]*$/bdone
185185
/^[ ]*done[ ]*[<>|]/bdone
186186
/^[ ]*done[ ]*)/bdone
187-
/||[ ]*exit[ ]/bcontinue
188-
/||[ ]*exit[ ]*$/bcontinue
187+
/||[ ]*exit[ ]/bcont
188+
/||[ ]*exit[ ]*$/bcont
189189
# multi-line "if...elsif...else...fi"
190-
/^[ ]*if[ ]/bcontinue
191-
/^[ ]*then[ ]/bcontinue
192-
/^[ ]*then[ ]*$/bcontinue
193-
/;[ ]*then/bcontinue
190+
/^[ ]*if[ ]/bcont
191+
/^[ ]*then[ ]/bcont
192+
/^[ ]*then[ ]*$/bcont
193+
/;[ ]*then/bcont
194194
/^[ ]*elif[ ]/belse
195195
/^[ ]*elif[ ]*$/belse
196196
/^[ ]*else[ ]/belse
@@ -234,10 +234,10 @@ s/.*\n//
234234
}
235235
}
236236
# line ends with pipe "...|" -- valid; not missing "&&"
237-
/|[ ]*$/bcontinue
237+
/|[ ]*$/bcont
238238
# missing end-of-line "&&" -- mark suspect
239239
/&&[ ]*$/!s/^/?!AMP?!/
240-
:continue
240+
:cont
241241
# retrieve and print previous line
242242
x
243243
n
@@ -250,29 +250,29 @@ s/\\\n//
250250
bslurp
251251

252252
# check for multi-line double-quoted string "...\n..." -- fold to one line
253-
:dqstring
253+
:dqstr
254254
# remove all quote pairs
255255
s/"\([^"]*\)"/@!\1@!/g
256256
# done if no dangling quote
257257
/"/!bdqdone
258258
# otherwise, slurp next line and try again
259259
N
260260
s/\n//
261-
bdqstring
261+
bdqstr
262262
:dqdone
263263
s/@!/"/g
264264
bfolded
265265

266266
# check for multi-line single-quoted string '...\n...' -- fold to one line
267-
:sqstring
267+
:sqstr
268268
# remove all quote pairs
269269
s/'\([^']*\)'/@!\1@!/g
270270
# done if no dangling quote
271271
/'/!bsqdone
272272
# otherwise, slurp next line and try again
273273
N
274274
s/\n//
275-
bsqstring
275+
bsqstr
276276
:sqdone
277277
s/@!/'/g
278278
bfolded
@@ -282,11 +282,11 @@ bfolded
282282
:heredoc
283283
s/^\(.*\)<<[ ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
284284
s/[ ]*<<//
285-
:heredsub
285+
:hdocsub
286286
N
287287
/^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{
288288
s/\n.*$//
289-
bheredsub
289+
bhdocsub
290290
}
291291
s/^<[^>]*>//
292292
s/\n.*$//
@@ -305,7 +305,7 @@ bcase
305305
x
306306
s/?!AMP?!//
307307
x
308-
bcontinue
308+
bcont
309309

310310
# found "done" closing for-loop or while-loop, or "fi" closing if-then -- drop
311311
# "suspect" from final contained line since that line legitimately lacks "&&"
@@ -321,22 +321,22 @@ bchkchn
321321
# found nested multi-line "(...\n...)" -- pass through untouched
322322
:nest
323323
x
324-
:nstslurp
324+
:nstslrp
325325
n
326326
# closing ")" on own line -- stop nested slurp
327-
/^[ ]*)/bnstclose
327+
/^[ ]*)/bnstcl
328328
# comment -- not closing ")" if in comment
329329
/^[ ]*#/bnstcnt
330330
# "$((...))" -- arithmetic expansion; not closing ")"
331331
/\$(([^)][^)]*))[^)]*$/bnstcnt
332332
# "$(...)" -- command substitution; not closing ")"
333333
/\$([^)][^)]*)[^)]*$/bnstcnt
334334
# closing "...)" -- stop nested slurp
335-
/)/bnstclose
335+
/)/bnstcl
336336
:nstcnt
337337
x
338-
bnstslurp
339-
:nstclose
338+
bnstslrp
339+
:nstcl
340340
s/^/>>/
341341
# is it "))" which closes nested and parent subshells?
342342
/)[ ]*)/bslurp

0 commit comments

Comments
 (0)