按提示词完善loadusr解析
结论:对齐LinuxCNC halcmd loadusr getopt(+wWin:)和补全表,生成器能正确跳过-Wn/-n等待名并提取实际用户态程序。
This commit is contained in:
@@ -71,6 +71,9 @@ fi
|
||||
|
||||
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() {
|
||||
local file=$1
|
||||
awk '
|
||||
@@ -79,6 +82,31 @@ read_ini_switchkins_config() {
|
||||
sub(/[[:space:]]*$/, "", 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
|
||||
sub(/[[:space:]]*[#;].*$/, "", line)
|
||||
@@ -108,12 +136,7 @@ read_ini_switchkins_config() {
|
||||
} else if (section == "hal" && key == "halcmd") {
|
||||
lower = tolower(value)
|
||||
if (lower ~ /(^|[[:space:]])loadusr([[:space:]]|$)/) {
|
||||
command = value
|
||||
sub(/^.*(^|[[:space:]])loadusr[[:space:]]+/, "", command)
|
||||
while (command ~ /^-[^[:space:]]+[[:space:]]+/) {
|
||||
sub(/^-[^[:space:]]+[[:space:]]+/, "", command)
|
||||
}
|
||||
sub(/[[:space:]].*$/, "", command)
|
||||
command = loadusr_program(value)
|
||||
if (command != "") {
|
||||
print "halcmd_loadusr\t" command
|
||||
}
|
||||
@@ -167,6 +190,31 @@ read_loadusr_commands() {
|
||||
sub(/[[:space:]]*$/, "", 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
|
||||
sub(/[[:space:]]*#.*/, "", line)
|
||||
@@ -175,13 +223,9 @@ read_loadusr_commands() {
|
||||
if (lower !~ /(^|[[:space:]])loadusr([[:space:]]|$)/) {
|
||||
next
|
||||
}
|
||||
sub(/^.*(^|[[:space:]])loadusr[[:space:]]+/, "", line)
|
||||
while (line ~ /^-[^[:space:]]+[[:space:]]+/) {
|
||||
sub(/^-[^[:space:]]+[[:space:]]+/, "", line)
|
||||
}
|
||||
sub(/[[:space:]].*$/, "", line)
|
||||
if (line != "") {
|
||||
print line
|
||||
command = loadusr_program(line)
|
||||
if (command != "") {
|
||||
print command
|
||||
}
|
||||
}
|
||||
' "$file"
|
||||
|
||||
Reference in New Issue
Block a user