From 3c2df9087235ea2091ac652d103d2a74ff8f8dfc Mon Sep 17 00:00:00 2001 From: cnc Date: Thu, 4 Jun 2026 05:37:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E6=8F=90=E7=A4=BA=E8=AF=8D=E5=AE=8C?= =?UTF-8?q?=E5=96=84loadusr=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 结论:对齐LinuxCNC halcmd loadusr getopt(+wWin:)和补全表,生成器能正确跳过-Wn/-n等待名并提取实际用户态程序。 --- generate-linuxcnc-switchkins-remap-table.sh | 70 +++++++++++++++++---- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/generate-linuxcnc-switchkins-remap-table.sh b/generate-linuxcnc-switchkins-remap-table.sh index 130511f..394e6fc 100755 --- a/generate-linuxcnc-switchkins-remap-table.sh +++ b/generate-linuxcnc-switchkins-remap-table.sh @@ -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"