@cratis/pi 7.170.8 → 7.170.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -759,6 +759,11 @@ function base(word) { sub(/^.*\//, "", word); return word }
|
|
|
759
759
|
function member(list, word) { return index(" " list " ", " " word " ") > 0 }
|
|
760
760
|
function destructive(word) { return member("rm rmdir unlink shred mv", base(word)) }
|
|
761
761
|
function shell(word) { return member("sh bash dash zsh ksh ash", base(word)) }
|
|
762
|
+
# Command-head recognition is shared by dispatch and directory tracking. time retains
|
|
763
|
+
# its option-aware wrapper handling below; grouping delimiters also split segments.
|
|
764
|
+
function command_prefix(word) {
|
|
765
|
+
return word ~ /^[A-Za-z_][A-Za-z0-9_]*=/ || member("then do else elif ! if while until { ( coproc", word)
|
|
766
|
+
}
|
|
762
767
|
# Only these established execution prefixes expose another command position.
|
|
763
768
|
function wrapper(word) {
|
|
764
769
|
return member("sudo doas env command builtin exec nohup nice ionice timeout time stdbuf xargs setsid chroot nsenter busybox", base(word))
|
|
@@ -809,30 +814,77 @@ function arithmetic_prefix(text, i, quoted) {
|
|
|
809
814
|
if (!quoted && substr(text, i, 2) == "((") return i + 2
|
|
810
815
|
return 0
|
|
811
816
|
}
|
|
812
|
-
#
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
else if (!quoted && word ~ /^~/) return "!"
|
|
821
|
-
if (word ~ /[$`]/) {
|
|
822
|
-
# A variable prefix with a literal suffix is not evidence of a root operand.
|
|
823
|
-
rest = word
|
|
824
|
-
if (rest ~ /^\$\{[A-Za-z_][A-Za-z0-9_]*\}\//) sub(/^\$\{[A-Za-z_][A-Za-z0-9_]*\}\//, "", rest)
|
|
825
|
-
else if (rest ~ /^\$[A-Za-z_][A-Za-z0-9_]*\//) sub(/^\$[A-Za-z_][A-Za-z0-9_]*\//, "", rest)
|
|
826
|
-
else return "!"
|
|
827
|
-
if (rest == "" || rest ~ /[$`]/) return "!"
|
|
828
|
-
word = rest
|
|
817
|
+
# Exceptions need a whole-tool simple command, not a guess about earlier mutations.
|
|
818
|
+
# Quoted parentheses and parameter braces remain word data in the lexer.
|
|
819
|
+
function simple_command(text, d, n, i, head) {
|
|
820
|
+
head = base(W[d, 1])
|
|
821
|
+
if (!destructive(head) && head != "git" && head != "find") return 0
|
|
822
|
+
if (text ~ /`|\$\(/) return 0
|
|
823
|
+
for (i = 1; i <= n; i++) {
|
|
824
|
+
if (BC[d, i] || (K[d, i] != "word" && K[d, i] !~ /^(>|>>|>&|&>|&>>|<|<&)$/)) return 0
|
|
829
825
|
}
|
|
826
|
+
return 1
|
|
827
|
+
}
|
|
828
|
+
function unquoted_expansion(raw, i, c, quote) {
|
|
829
|
+
for (i = 1; i <= length(raw); i++) {
|
|
830
|
+
c = substr(raw, i, 1)
|
|
831
|
+
if (c == "\\" && quote != "\047") { i++; continue }
|
|
832
|
+
if (quote != "") { if (c == quote) quote = ""; continue }
|
|
833
|
+
if (c == "\047" || c == "\"") { quote = c; continue }
|
|
834
|
+
if (c == "*" || c == "?" || c == "[" || c == "$" || c == "`") return 1
|
|
835
|
+
}
|
|
836
|
+
return 0
|
|
837
|
+
}
|
|
838
|
+
# Raw-source proof excludes splitting and mixed unquoted globs. A value of 2
|
|
839
|
+
# marks quoted predicate data, not an eligible environment path prefix.
|
|
840
|
+
function quoted_prefix(raw) {
|
|
841
|
+
if (raw ~ /^~/) return !unquoted_expansion(raw)
|
|
842
|
+
if (raw ~ /^"\$(\{(PWD|HOME|TMPDIR)\}|PWD|HOME|TMPDIR)(\/|")/ && !unquoted_expansion(raw)) return 1
|
|
843
|
+
return (raw ~ /^"[^"]*"$/ || raw ~ /^\047[^\047]*\047$/) ? 2 : 0
|
|
844
|
+
}
|
|
845
|
+
# Only raw, unquoted ~+ with a literal suffix can establish the initial cwd.
|
|
846
|
+
function literal_current_directory(raw, word) {
|
|
847
|
+
return raw == word && word ~ /^~\+(\/|$)/ && substr(word, 3) !~ /[$`~*?\[{}]/
|
|
848
|
+
}
|
|
849
|
+
# A destructive expansion exception must name only real descendant components.
|
|
850
|
+
function descendant_suffix(suffix, parts, count, i) {
|
|
851
|
+
if (suffix !~ /^\// || suffix ~ /[$`*?\[{}~]/ || index(suffix, "]") || index(suffix, "\\")) return 0
|
|
852
|
+
gsub(/\/+/, "/", suffix)
|
|
853
|
+
sub(/\/$/, "", suffix)
|
|
854
|
+
count = split(substr(suffix, 2), parts, "/")
|
|
855
|
+
if (!count) return 0
|
|
856
|
+
for (i = 1; i <= count; i++) {
|
|
857
|
+
if (parts[i] == "" || parts[i] == "." || parts[i] == "..") return 0
|
|
858
|
+
}
|
|
859
|
+
return 1
|
|
860
|
+
}
|
|
861
|
+
function environment_prefix(word, require_descendant, name, suffix, end) {
|
|
862
|
+
if (word ~ /^\$\{(PWD|HOME|TMPDIR)\}(\/|$)/) {
|
|
863
|
+
end = index(word, "}"); name = substr(word, 3, end - 3); suffix = substr(word, end + 1)
|
|
864
|
+
} else if (word ~ /^\$(PWD|HOME|TMPDIR)(\/|$)/) {
|
|
865
|
+
name = substr(word, 2); sub(/\/.*/, "", name); suffix = substr(word, length(name) + 2)
|
|
866
|
+
} else return "!"
|
|
867
|
+
if (require_descendant && !descendant_suffix(suffix)) return "!"
|
|
868
|
+
return (name == "PWD" ? ENVIRON["GSW_CWD"] : ENVIRON[name]) suffix
|
|
869
|
+
}
|
|
870
|
+
function resolved(word, quoted, cwd, uncertain, double_quoted, ordinary, expanded, suffix) {
|
|
871
|
+
expanded = word ~ /^\$/ || (!quoted && word ~ /^~/)
|
|
872
|
+
if (expanded && !ordinary && (!exception_allowed || double_quoted != 1)) return "!"
|
|
873
|
+
if (word ~ /^\$/) word = double_quoted == 1 ? environment_prefix(word, !ordinary) : "!"
|
|
874
|
+
else if (!quoted && word ~ /^~(\/|$)/) {
|
|
875
|
+
suffix = substr(word, 2)
|
|
876
|
+
word = ordinary || descendant_suffix(suffix) ? ENVIRON["HOME"] suffix : "!"
|
|
877
|
+
} else if (!quoted && word ~ /^~\+(\/|$)/) {
|
|
878
|
+
suffix = substr(word, 3)
|
|
879
|
+
word = ordinary || descendant_suffix(suffix) ? ENVIRON["GSW_CWD"] suffix : "!"
|
|
880
|
+
} else if (!quoted && word ~ /^~/) return "!"
|
|
881
|
+
if (word == "!" || word ~ /[$`]/ || (expanded && word ~ /^-/)) return "!"
|
|
830
882
|
if (word ~ /^\//) return word
|
|
831
883
|
if (uncertain) return "!"
|
|
832
884
|
return cwd "/" word
|
|
833
885
|
}
|
|
834
|
-
function operand(word, quoted, cwd, uncertain) {
|
|
835
|
-
if (word != "" && word != "{}") emit(resolved(word, quoted, cwd, uncertain))
|
|
886
|
+
function operand(word, quoted, cwd, uncertain, double_quoted) {
|
|
887
|
+
if (word != "" && word != "{}") emit(resolved(word, quoted, cwd, uncertain, double_quoted))
|
|
836
888
|
}
|
|
837
889
|
# Heredoc delimiters are quote-removed, never expanded or executed.
|
|
838
890
|
function heredoc_word(text, start, i, c, quote, word, active) {
|
|
@@ -914,10 +966,11 @@ function data_substitutions(text, d, word, i, c, body, k) {
|
|
|
914
966
|
}
|
|
915
967
|
}
|
|
916
968
|
}
|
|
917
|
-
function lex(text, d, i, c, nextc, quote, word, quoted, active, n, body, k, pending, delimiter, strip, hd_index, end) {
|
|
969
|
+
function lex(text, d, i, c, nextc, quote, word, quoted, active, n, body, k, pending, delimiter, strip, hd_index, end, word_start) {
|
|
918
970
|
n = 0; quote = ""; word = ""; active = 0; quoted = 0; pending = 0
|
|
919
971
|
for (i = 1; i <= length(text); i++) {
|
|
920
972
|
c = substr(text, i, 1); nextc = substr(text, i + 1, 1)
|
|
973
|
+
if (!active) word_start = i
|
|
921
974
|
if (quote != "\047" && (k = arithmetic_prefix(text, i, quote != ""))) {
|
|
922
975
|
body = arithmetic(text, k, arithmetic_bracket); unclassified(body)
|
|
923
976
|
i = arithmetic_end; word = word "$__arithmetic"; active = 1; continue
|
|
@@ -949,7 +1002,7 @@ function lex(text, d, i, c, nextc, quote, word, quoted, active, n, body, k, p
|
|
|
949
1002
|
}
|
|
950
1003
|
if (c == "{" && nextc == "}") { word = word "{}"; i++; active = 1; continue }
|
|
951
1004
|
if (c ~ /[ \t\r\n;&|(){}<>]/) {
|
|
952
|
-
if (active) { W[d, ++n] = word; Q[d, n] = quoted; K[d, n] = "word"; T[d, n] = i - 1; F[d, n] = !quoted && word ~ /^[0-9]+$/ && substr(text, i - length(word), length(word)) == word; word = ""; active = quoted = 0 }
|
|
1005
|
+
if (active) { W[d, ++n] = word; Q[d, n] = quoted; DQ[d, n] = quoted_prefix(substr(text, word_start, i - word_start)); CT[d, n] = literal_current_directory(substr(text, word_start, i - word_start), word); K[d, n] = "word"; T[d, n] = i - 1; F[d, n] = !quoted && word ~ /^[0-9]+$/ && substr(text, i - length(word), length(word)) == word; word = ""; active = quoted = 0 }
|
|
953
1006
|
if (c ~ /[ \t\r]/) continue
|
|
954
1007
|
if (c == "<" && nextc == "<") {
|
|
955
1008
|
if (substr(text, i, 3) == "<<<") { W[d, ++n] = "<<<"; K[d, n] = "<<<"; T[d, n] = i; i += 2; continue }
|
|
@@ -984,7 +1037,7 @@ function lex(text, d, i, c, nextc, quote, word, quoted, active, n, body, k, p
|
|
|
984
1037
|
}
|
|
985
1038
|
word = word c; active = 1
|
|
986
1039
|
}
|
|
987
|
-
if (active) { W[d, ++n] = word; Q[d, n] = quoted; K[d, n] = "word" }
|
|
1040
|
+
if (active) { W[d, ++n] = word; Q[d, n] = quoted; DQ[d, n] = quoted_prefix(substr(text, word_start)); CT[d, n] = literal_current_directory(substr(text, word_start), word); K[d, n] = "word" }
|
|
988
1041
|
if (quote != "" || pending) unclassified(remaining(d, 1, n))
|
|
989
1042
|
return n
|
|
990
1043
|
}
|
|
@@ -1019,7 +1072,7 @@ function wrapper_flag(program, option) {
|
|
|
1019
1072
|
# Dispatch uses an argv copy, never shell source. Every prefix shares the same
|
|
1020
1073
|
# redirection tail and inherited pipe input; splitting env argv cannot discard either.
|
|
1021
1074
|
function copy_token(source, from, dest, to, j) {
|
|
1022
|
-
W[dest, to] = W[source, from]; Q[dest, to] = Q[source, from]; K[dest, to] = K[source, from]
|
|
1075
|
+
W[dest, to] = W[source, from]; Q[dest, to] = Q[source, from]; DQ[dest, to] = DQ[source, from]; K[dest, to] = K[source, from]
|
|
1023
1076
|
H[dest, to] = H[source, from]; T[dest, to] = T[source, from]; F[dest, to] = F[source, from]
|
|
1024
1077
|
BC[dest, to] = BC[source, from]
|
|
1025
1078
|
for (j = 1; j <= BC[source, from]; j++) B[dest, to, j] = B[source, from, j]
|
|
@@ -1079,7 +1132,7 @@ function env_words(text, slot, i, c, nextc, quote, word, active, n) {
|
|
|
1079
1132
|
function executable(d, start, end, i, j, program, option, split_at, text, slot, count, first, expansions) {
|
|
1080
1133
|
prefix_uncertain = 0; prefix_fed = 0; dispatch_end = end; i = start
|
|
1081
1134
|
while (i <= end) {
|
|
1082
|
-
if (W[d, i]
|
|
1135
|
+
if (command_prefix(W[d, i])) { i++; continue }
|
|
1083
1136
|
program = base(W[d, i])
|
|
1084
1137
|
if (!wrapper(program)) return redirection(d, i) ? 0 : i
|
|
1085
1138
|
if (member("chroot nsenter", program)) prefix_uncertain = 1
|
|
@@ -1123,7 +1176,7 @@ function removal(d, verb, end, cwd, uncertain, findpaths, i, w, count, option
|
|
|
1123
1176
|
if (w ~ /^--target-directory=/ || w ~ /^-t./) { target = 1; continue }
|
|
1124
1177
|
}
|
|
1125
1178
|
if (options && w ~ /^-/) continue
|
|
1126
|
-
O[d, ++count] = w; OQ[d, count] = Q[d, i]
|
|
1179
|
+
O[d, ++count] = w; OQ[d, count] = Q[d, i]; ODQ[d, count] = DQ[d, i]
|
|
1127
1180
|
}
|
|
1128
1181
|
if (base(W[d, verb]) == "mv" && !target) count--
|
|
1129
1182
|
for (j = 1; j <= count; j++) {
|
|
@@ -1131,7 +1184,7 @@ function removal(d, verb, end, cwd, uncertain, findpaths, i, w, count, option
|
|
|
1131
1184
|
if (w == "{}") {
|
|
1132
1185
|
if (findpaths != "") emit(findpaths)
|
|
1133
1186
|
else emit("!")
|
|
1134
|
-
} else operand(w, OQ[d, j], cwd, uncertain)
|
|
1187
|
+
} else operand(w, OQ[d, j], cwd, uncertain, ODQ[d, j])
|
|
1135
1188
|
sources++
|
|
1136
1189
|
}
|
|
1137
1190
|
}
|
|
@@ -1140,7 +1193,7 @@ function git_clean(d, verb, end, cwd, uncertain, findpaths, depth, fed, i, j,
|
|
|
1140
1193
|
for (i = verb + 1; i <= end; i++) {
|
|
1141
1194
|
w = W[d, i]
|
|
1142
1195
|
if (w == "-C") {
|
|
1143
|
-
cwd = resolved(W[d, ++i], Q[d, i], cwd, uncertain)
|
|
1196
|
+
cwd = resolved(W[d, ++i], Q[d, i], cwd, uncertain, DQ[d, i])
|
|
1144
1197
|
if (cwd == "!") uncertain = 1
|
|
1145
1198
|
} else if (w == "-c") {
|
|
1146
1199
|
alias = W[d, ++i]
|
|
@@ -1148,8 +1201,9 @@ function git_clean(d, verb, end, cwd, uncertain, findpaths, depth, fed, i, j,
|
|
|
1148
1201
|
name = alias; sub(/^alias\./, "", name); sub(/=.*/, "", name)
|
|
1149
1202
|
sub(/^[^=]*=/, "", alias); A[call, name] = alias
|
|
1150
1203
|
}
|
|
1204
|
+
} else if (w ~ /[$`]/) { emit("!"); return }
|
|
1151
1205
|
# Git 2.50.1 git.c handle_options(), plus legacy --super-prefix.
|
|
1152
|
-
|
|
1206
|
+
else if (member("--git-dir --work-tree --namespace --config-env --attr-source --super-prefix --shallow-file", w)) i++
|
|
1153
1207
|
else if (w ~ /^--(git-dir|work-tree|namespace|config-env|attr-source|super-prefix|exec-path)=/) continue
|
|
1154
1208
|
else if (member("-h --help -v --version --html-path --man-path --info-path --exec-path", w) || w ~ /^--list-cmds=/) return
|
|
1155
1209
|
else if (member("-p --paginate -P --no-pager --no-replace-objects --no-lazy-fetch --no-optional-locks --no-advice --bare --literal-pathspecs --no-literal-pathspecs --glob-pathspecs --noglob-pathspecs --icase-pathspecs", w)) continue
|
|
@@ -1171,6 +1225,9 @@ function git_clean(d, verb, end, cwd, uncertain, findpaths, depth, fed, i, j,
|
|
|
1171
1225
|
for (i = subcommand + 1; i <= end; i++) {
|
|
1172
1226
|
w = W[d, i]
|
|
1173
1227
|
if (K[d, i] ~ /^[<>]/) break
|
|
1228
|
+
# An expansion may supply Git options, even when shell-quoted. Only an
|
|
1229
|
+
# eligible, fully double-quoted environment path has a proven argv shape.
|
|
1230
|
+
if (w ~ /[$`]/ && (!DQ[d, i] || resolved(w, Q[d, i], cwd, uncertain, DQ[d, i]) == "!")) { emit("!"); return }
|
|
1174
1231
|
if (!skip && w == "--") { skip = 1; continue }
|
|
1175
1232
|
if (!skip && w == "--exclude") { i++; continue }
|
|
1176
1233
|
if (!skip && w ~ /^--exclude=/) continue
|
|
@@ -1193,7 +1250,7 @@ function git_clean(d, verb, end, cwd, uncertain, findpaths, depth, fed, i, j,
|
|
|
1193
1250
|
if (w ~ /^:\// || w ~ /^:\(top/) emit(ENVIRON["GSW_ROOT"])
|
|
1194
1251
|
else if (w ~ /^:\(/) emit("!")
|
|
1195
1252
|
else if (w == "{}" && findpaths != "") emit(findpaths)
|
|
1196
|
-
else operand(w, Q[d, i], cwd, uncertain)
|
|
1253
|
+
else operand(w, Q[d, i], cwd, uncertain, DQ[d, i])
|
|
1197
1254
|
}
|
|
1198
1255
|
if (!paths) operand(".", 0, cwd, uncertain)
|
|
1199
1256
|
}
|
|
@@ -1202,14 +1259,24 @@ function find_command(d, verb, end, cwd, uncertain, depth, fed, i, j, start,
|
|
|
1202
1259
|
for (i = verb + 1; i <= end; i++) {
|
|
1203
1260
|
w = W[d, i]
|
|
1204
1261
|
if (member("-H -L -P", w)) continue
|
|
1262
|
+
# A bare expanded word may be a predicate rather than a starting path;
|
|
1263
|
+
# an unquoted expansion can additionally supply several argument words.
|
|
1264
|
+
if (w ~ /[$`]/ && (!Q[d, i] || (w !~ /\// && environment_prefix(w) == "!"))) { emit("!"); return }
|
|
1205
1265
|
if (w ~ /^-/ || w == "!" || w == "(") break
|
|
1206
|
-
p = resolved(w, Q[d, i], cwd, uncertain)
|
|
1266
|
+
p = resolved(w, Q[d, i], cwd, uncertain, DQ[d, i])
|
|
1207
1267
|
FP[depth, ++have] = p
|
|
1208
1268
|
}
|
|
1209
1269
|
if (!have) FP[depth, ++have] = resolved(".", 0, cwd, uncertain)
|
|
1210
1270
|
for (j = 1; j <= have; j++) paths = paths (j == 1 ? "" : "\n") FP[depth, j]
|
|
1211
1271
|
for (; i <= end; i++) {
|
|
1212
1272
|
w = W[d, i]
|
|
1273
|
+
# Arguments to known predicates are data, not possible injected actions.
|
|
1274
|
+
if (member("-name -iname -path -ipath -wholename -iwholename -regex -iregex -lname -ilname -type -xtype -size -user -group -uid -gid -perm -mtime -atime -ctime -mmin -amin -cmin -newer -newermt -maxdepth -mindepth -printf -fprint -fprint0 -samefile -links -inum -fstype -used -context", w)) {
|
|
1275
|
+
i++
|
|
1276
|
+
if (W[d, i] ~ /[$`]/ && !DQ[d, i]) { emit("!"); return }
|
|
1277
|
+
continue
|
|
1278
|
+
}
|
|
1279
|
+
if (w ~ /[$`]/) { emit("!"); return }
|
|
1213
1280
|
if (w == "-delete") deleted = 1
|
|
1214
1281
|
if (member("-exec -execdir -ok -okdir", w)) {
|
|
1215
1282
|
start = i + 1
|
|
@@ -1324,13 +1391,17 @@ function shell_command(d, head, end, cwd, uncertain, depth, pipe, fed, i, j,
|
|
|
1324
1391
|
script = stdin_data(d, head + 1, end, pipe)
|
|
1325
1392
|
if (script != "") parse(script, cwd, uncertain, depth + 1, fed)
|
|
1326
1393
|
}
|
|
1327
|
-
function segment(d, start, end, cwd, uncertain, depth, findpaths, pipe, fed, outgoing, head, i, j, k, w, script, context) {
|
|
1394
|
+
function segment(d, start, end, cwd, uncertain, depth, findpaths, pipe, fed, outgoing, head, i, j, k, w, script, context, target) {
|
|
1328
1395
|
if (start > end) return ""
|
|
1396
|
+
exception_allowed = simple_tool && d == 0 && start == 1 && end == N[0]
|
|
1329
1397
|
# Substitutions/redirections execute in the calling shell, even for unknown programs.
|
|
1330
1398
|
if (depth > 4) unclassified(remaining(d, start, end))
|
|
1331
1399
|
for (i = start; depth <= 4 && i <= end; i++) {
|
|
1332
1400
|
for (k = 1; k <= BC[d, i]; k++) parse(B[d, i, k], cwd, uncertain, depth + 1, 0)
|
|
1333
|
-
if ((K[d, i] == ">" || K[d, i] == "&>") && i < end && W[d, i + 1] !~ /[$`]/ && W[d, i + 1] != "/dev/null")
|
|
1401
|
+
if ((K[d, i] == ">" || K[d, i] == "&>") && i < end && W[d, i + 1] !~ /[$`]/ && W[d, i + 1] != "/dev/null") {
|
|
1402
|
+
target = resolved(W[d, i + 1], Q[d, i + 1], cwd, uncertain, DQ[d, i + 1], 1)
|
|
1403
|
+
emit(target)
|
|
1404
|
+
}
|
|
1334
1405
|
}
|
|
1335
1406
|
d = dispatch(d, start, end); head = dispatch_head; end = dispatch_end
|
|
1336
1407
|
context = uncertain || prefix_uncertain; fed = fed || prefix_fed
|
|
@@ -1358,22 +1429,31 @@ function segment(d, start, end, cwd, uncertain, depth, findpaths, pipe, fed, out
|
|
|
1358
1429
|
function parse(text, cwd, uncertain, depth, fed, n, i, start, kind, level, head, path, old, j, pipe, data) {
|
|
1359
1430
|
# Lex before the depth fallback so properly terminated heredoc bodies stay data.
|
|
1360
1431
|
# A depth slot may be reused by several script words.
|
|
1361
|
-
for (i = 1; i <= N[depth]; i++) { delete W[depth, i]; delete Q[depth, i]; delete K[depth, i]; delete H[depth, i]; delete T[depth, i]; delete F[depth, i]; BC[depth, i] = 0 }
|
|
1432
|
+
for (i = 1; i <= N[depth]; i++) { delete W[depth, i]; delete Q[depth, i]; delete DQ[depth, i]; delete CT[depth, i]; delete K[depth, i]; delete H[depth, i]; delete T[depth, i]; delete F[depth, i]; BC[depth, i] = 0 }
|
|
1362
1433
|
n = lex(text, depth); N[depth] = n; start = 1; level = 0
|
|
1434
|
+
if (depth == 0) simple_tool = simple_command(text, depth, n)
|
|
1363
1435
|
for (i = 1; i <= n + 1; i++) {
|
|
1364
1436
|
kind = K[depth, i]
|
|
1365
1437
|
if (i <= n && kind != ";" && kind != "\n" && kind != "&" && kind != "&&" && kind != "|" && kind != "|&" && kind != "||" && kind != "(" && kind != ")" && kind != "{" && kind != "}") continue
|
|
1366
1438
|
data = segment(depth, start, i - 1, cwd, uncertain, depth, "", pipe, fed, kind)
|
|
1367
1439
|
pipe = (kind == "|" || kind == "|&" ? data : "")
|
|
1368
1440
|
head = start
|
|
1369
|
-
while (head < i && W[depth, head]
|
|
1441
|
+
while (head < i && command_prefix(W[depth, head])) head++
|
|
1370
1442
|
if (kind != "|" && kind != "|&" && member("cd pushd popd", W[depth, head])) {
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1443
|
+
old = ""
|
|
1444
|
+
for (j = head + 1; j < i; j++) {
|
|
1445
|
+
if (K[depth, j] == "word" && W[depth, j] ~ /^-/) { old = "!"; break }
|
|
1446
|
+
}
|
|
1447
|
+
j = head + 1
|
|
1448
|
+
path = W[depth, j]
|
|
1449
|
+
if (old == "!" || W[depth, head] == "popd" || path == "") uncertain = 1
|
|
1374
1450
|
else {
|
|
1375
|
-
|
|
1376
|
-
|
|
1451
|
+
# The sole expansion proof is an initial, top-level cd ~+/literal.
|
|
1452
|
+
# Nested/later destinations never consult an environment prefix.
|
|
1453
|
+
if (depth == 0 && level == 0 && start == 1 && head == 1 && W[depth, head] == "cd" && CT[depth, j] && !uncertain) old = ENVIRON["GSW_CWD"] substr(path, 3)
|
|
1454
|
+
else if (path ~ /[$`~*?\[{}]/) old = "!"
|
|
1455
|
+
else if (path ~ /^\//) old = path
|
|
1456
|
+
else old = uncertain ? "!" : cwd "/" path
|
|
1377
1457
|
if (old == "!") uncertain = 1
|
|
1378
1458
|
else { cwd = old; uncertain = 0 }
|
|
1379
1459
|
}
|