Skip to content

ls: GNU width chain for the COLUMNS face (base-0, overflow=no-limit, -w 0 decided, UTF-8 quotes) - #1540

Merged
caomengxuan666 merged 4 commits into
mainfrom
fix/WINX1536-wave1
Nov 9, 2026
Merged

caomengxuan666 merged 4 commits into
mainfrom
fix/WINX1536-wave1

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Refs #1536

内容

把 #1534 合入的 ls COLUMNS 面与 GNU coreutils 9.4 的五处分歧收敛到一条宽度链:decode_line_length()(ls.c:1867-1886,xstrtoumax base-0 语义)统一解析 -w 与 COLUMNS,resolve_output_width() 统一三处布局消费点(print_grid / -m 链 / 已删除的 print_columns)。

  1. base-0 解析:COLUMNS 与 -w 均按 base-0 解码(0100=64、0x20=32),不再是 base-10(COLUMNS 原为 strtol(...,10),-w 原为框架 from_chars base-10)。-w 选项类型 INT_TYPE→STRING_TYPE,镜像 -T 的既有先例(STRING_TYPE + occurrences 扫描 + 手工解析)。
  2. 溢出 = 无限制:解码溢出与大于 INT_MAX 的值映射为无限制哨兵 kLsNoLineLimit,不再 warn + 回退 80;-w 溢出同理(原框架直接报 invalid argument)。
  3. -w 0 不穿透:resolve_output_width 以 occurrences 是否存在判「已给」,0 即无限制,不再跌落到终端宽度/COLUMNS。
  4. -x 无限制布局:-x 与 -C 共用 print_grid 的单行 separator 路径;分歧的单列 clamp 位于无调用点的 print_columns,本次删除(见下)。
  5. 警告引号:无效 COLUMNS 警告改用 GNU quote() 的 UTF-8 ‘’ 形;无效 -w 新增 GNU 诊断 ls: invalid line width: ‘…’ 并以 exit 2 退出(ls.c:2024,LS_FAILURE),经 validate_arguments + 主错误出口的 exit-2 前缀表(扩展 invalid tab size 先例)。

钉:tests/unit/ls/ls_issue1536_test.cpp 13 格(先行提交 e859b8a),覆盖五处分歧的 -C/-x/-m 三面与解码边界(前导空白/尾随垃圾/十六进制/八进制/溢出/无效)。#1534 的既有测试 ls_columns_invalid_warns_and_falls_back_to_80_issue1504 同步改为 UTF-8 引号期望(其断言的正是分歧 5 的旧形)。

i18n drift:新警告引号片段产生 1 个新 legacy key(legacy.7d2d2cf903edeae3,提取串 ’),已按仓内 sanctioned 路径以 scripts/check_i18n_drift.py --update-baseline 记录于本 PR(24→25 项,本地以 fresh i18n 仓复刻 CI 腿复查 OK)。

本 PR 删除了什么

  • src/commands/ls.cpp 的 print_columns 函数(约 120 行):全仓无调用点的死代码,且其 width-0 单列 clamp 正是分歧 4 记录的非 GNU 规则;-x 实际路径为 print_grid(across),由统一宽度链覆盖。
  • get_terminal_width() 内的 base-10 strtol COLUMNS 解析块与 [DIFFERS] ASCII 引号警告:由 decode_line_length() + UTF-8 引号警告替代。
  • 三处布局消费点各自的 -w/--width/get_terminal_width() 穿透链:由 resolve_output_width() 单点替代(净删重复链 3 份)。

- decode_line_length(): coreutils ls.c:1867 xstrtoumax base-0
  semantics for both COLUMNS and -w (0100=64, 0x20=32); 0 and
  overflow mean no limit, never warn+80 or a parse error.
- -w becomes STRING_TYPE (the -T precedent) so ls decodes the raw
  value itself; resolve_output_width() treats presence, not value,
  as decided, so -w 0 no longer falls through to the terminal.
- kLsNoLineLimit sentinel carries the no-limit state to print_grid
  (-C/-x) and the -m chain; print_columns, the dead duplicate layout
  engine carrying the width-0 single-column clamp, is removed.
- Invalid COLUMNS warns with quote()'s UTF-8 ‘’ marks; an invalid
  -w dies with 'invalid line width' at exit 2 (ls.c:2024).
- i18n drift baseline records the one deliberate new fragment.
@caomengxuan666
caomengxuan666 merged commit 8f2a85f into main Nov 9, 2026
12 of 13 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 9, 2026
…f/who) (#1547)

# gap-fill: w 测试补齐 + 6 命令 #1462 式 oracle 审计(arch/locale/pinky/pwd/stdbuf/who)

独立 worktree 分支。方法按 #1462:oracle 源码/活 oracle 先行,再裁决,再修复。全部对照 WSL GNU oracle(coreutils 9.4、procps-ng 4.0.4、glibc 2.39),脚本文件形态,stdout/stderr/exit 三向对照。

## Task 1 — w(唯一无测试的已审计命令)

- 新增 `tests/unit/w`(13 枚 session-count-independent pin):header 存在/-h 抑制、-s tail、-f toggle、-i force-FROM、-p/-o 接受、无匹配 user 过滤恰留 2 行 header 且 exit 0、非法选项诊断 + exit 1、--help/--version。
- WSL procps-ng 4.0.4 差分门:可比面 exit code 与首行诊断逐字节一致。
- 记录残余(不改):header 与上游 procps-ng v4.0.4 git 源码一致(src/w.c:799-806,67/45 列);Ubuntu 构建的 4.0.4 oracle 印 68/46——发行版补丁 vs git tag;上游源码仍为合同。
- 附带:修 C4477(time_ival7 中 `%02d` 配 `long long` 参数的错误转换)。

## Task 2 — 6 份审计(`tests/differential/audit-<cmd>.md`)

| 命令 | 结论 | 一句话 |
| --- | --- | --- |
| arch | **clean** | 全部面逐字节一致(除仓库级 quotearg/help 约定) |
| pwd | **clean** | -L/-P last-wins、POSIXLY_CORRECT 存在性测试、PWD 校验回退全部一致 |
| stdbuf | **clean** | 全矩阵,含 optstring-'+' 操作数边界、bare-K xstrtol 规则、125/127 退出码 |
| locale | **notes**(4 处修复) | bare -c/-k 改静默(并删一段破损字面量拼接块)、未知名白名单 `locale: unknown name "X"`、编造名(codeset/month/…)被拒 + `mon` 加入、-k print_item 引号 |
| pinky | **notes**(3 处修复) | -l 补 try-help 行、`--lookup` 被拒(9.4 无此长选项)、When 列 `%b %e`;heading 在 LC_ALL=C 下逐字节一致 |
| who | **notes**(3 处修复) | 缺 FILE 操作数静默 exit 0(旧 pin 与 oracle 矛盾,已翻转)、双 `who: who:` 前缀修复、时间面切 C-locale 12 列分支(who.c:803-811) |

平台面按 W4 协调裁决维持(mesg、utmp 视图、WTS 行、locale 仿真模型),各在审计文件内引用。locale 值模型重做(C-locale 空表/-a/-m 清单/分类转储)需 locale-database 仿真层(niu #758 依赖),已在审计文件内记录为后续跟进。

## 验证

- Debug 构建绿(scripts/build-with-vs.ps1,pcre2 preset)。
- 触及命令单测 89/89 绿(`w.* locale.* pinky.* who.* pwd.* stdbuf.* arch.*`)。
- CI 全套:3830/3830 通过(x64 default,`[ctest-gate] all tests passed`);队长复核确认:baseline 红腿为主干既有 WSL 侧进程杀死基建红(与 #1540 同族,main 同签名复现);i18n-drift 红腿为本 PR 孤儿 key(删 --lookup 选项 + locale 值表提取口径)——合入前须先在 winuxcmd-i18n 仓同步 PR 清掉并 bump VERSION(或本 PR 内 `--update-baseline` 记录),见文末复核注。
- 净行:+886/−159,15 文件(4 src + 7 audit md + 4 单测),零 arch/pwd/stdbuf 产品改动。

## 本 PR 删除了什么

- `pinky --lookup` 长选项一个(GNU 9.4 无此选项,属编造项;删后 `--lookup` 按 GNU 措辞被拒,exit 1)。
- locale 旧 `-k` 无参分支整段破损输出(含字面量拼接块 `LC_CTYPE= + get_system_locale() + ` 等 6 行)与旧 `month`/`codeset`/`collate`/`ctype`/`monetary`/`numeric`/`time`/`default_language` 编造名应答。
- who 对缺失 FILE 操作数的 `No such file or directory` 报错(旧 pin 一并翻转)。
- locale 旧报错措辞 `locale: unknown keyword 'X'`(改为 GNU 的 `locale: unknown name "X"`)。
- 其余皆为新增(测试、审计记录、白名单表),无产品功能删除。

Refs #1488, #1462, #1545

---
复核注(队长复核员):i18n 同步提交落地前本稿不适用;同步落地后重核 C2 门脚本 rc=0 与正文删除节即可合入。
复核记录:~/workspace/review-1547/CAPTAIN-VERIFY.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant