按提示词完善loadusr解析

结论:对齐LinuxCNC halcmd loadusr getopt(+wWin:)和补全表,生成器能正确跳过-Wn/-n等待名并提取实际用户态程序。
This commit is contained in:
cnc
2026-06-04 05:37:51 +08:00
parent 81c7b061a8
commit 3c2df90872

View File

@@ -71,6 +71,9 @@ fi
linuxcnc_root=$(cd "$linuxcnc_root" && pwd) linuxcnc_root=$(cd "$linuxcnc_root" && pwd)
# LinuxCNC source basis: src/hal/utils/halcmd_commands.cc do_loadusr_cmd()
# parses loadusr options with getopt("+wWin:"), and
# src/hal/utils/halcmd_completion.c lists the common -W/-Wn/-w/-iw forms.
read_ini_switchkins_config() { read_ini_switchkins_config() {
local file=$1 local file=$1
awk ' awk '
@@ -79,6 +82,31 @@ read_ini_switchkins_config() {
sub(/[[:space:]]*$/, "", value) sub(/[[:space:]]*$/, "", value)
return value return value
} }
function loadusr_program(value, fields, field_count, i, token) {
sub(/^.*(^|[[:space:]])loadusr[[:space:]]+/, "", value)
field_count = split(value, fields, /[[:space:]]+/)
for (i = 1; i <= field_count; i++) {
token = fields[i]
if (token == "-W" || token == "-w" || token == "-i") {
continue
}
if (token == "-Wn" || token == "-n") {
i++
continue
}
if (token ~ /^-Wn.+/ || token ~ /^-n.+/) {
continue
}
if (token ~ /^-[wWi]+$/) {
continue
}
if (token ~ /^-/) {
continue
}
return token
}
return ""
}
{ {
line = $0 line = $0
sub(/[[:space:]]*[#;].*$/, "", line) sub(/[[:space:]]*[#;].*$/, "", line)
@@ -108,12 +136,7 @@ read_ini_switchkins_config() {
} else if (section == "hal" && key == "halcmd") { } else if (section == "hal" && key == "halcmd") {
lower = tolower(value) lower = tolower(value)
if (lower ~ /(^|[[:space:]])loadusr([[:space:]]|$)/) { if (lower ~ /(^|[[:space:]])loadusr([[:space:]]|$)/) {
command = value command = loadusr_program(value)
sub(/^.*(^|[[:space:]])loadusr[[:space:]]+/, "", command)
while (command ~ /^-[^[:space:]]+[[:space:]]+/) {
sub(/^-[^[:space:]]+[[:space:]]+/, "", command)
}
sub(/[[:space:]].*$/, "", command)
if (command != "") { if (command != "") {
print "halcmd_loadusr\t" command print "halcmd_loadusr\t" command
} }
@@ -167,6 +190,31 @@ read_loadusr_commands() {
sub(/[[:space:]]*$/, "", value) sub(/[[:space:]]*$/, "", value)
return value return value
} }
function loadusr_program(value, fields, field_count, i, token) {
sub(/^.*(^|[[:space:]])loadusr[[:space:]]+/, "", value)
field_count = split(value, fields, /[[:space:]]+/)
for (i = 1; i <= field_count; i++) {
token = fields[i]
if (token == "-W" || token == "-w" || token == "-i") {
continue
}
if (token == "-Wn" || token == "-n") {
i++
continue
}
if (token ~ /^-Wn.+/ || token ~ /^-n.+/) {
continue
}
if (token ~ /^-[wWi]+$/) {
continue
}
if (token ~ /^-/) {
continue
}
return token
}
return ""
}
{ {
line = $0 line = $0
sub(/[[:space:]]*#.*/, "", line) sub(/[[:space:]]*#.*/, "", line)
@@ -175,13 +223,9 @@ read_loadusr_commands() {
if (lower !~ /(^|[[:space:]])loadusr([[:space:]]|$)/) { if (lower !~ /(^|[[:space:]])loadusr([[:space:]]|$)/) {
next next
} }
sub(/^.*(^|[[:space:]])loadusr[[:space:]]+/, "", line) command = loadusr_program(line)
while (line ~ /^-[^[:space:]]+[[:space:]]+/) { if (command != "") {
sub(/^-[^[:space:]]+[[:space:]]+/, "", line) print command
}
sub(/[[:space:]].*$/, "", line)
if (line != "") {
print line
} }
} }
' "$file" ' "$file"