Skip to content

inifile: accept dash in section and variable identifiers - #4573

Draft
grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:xhc-ini-hyphen
Draft

grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:xhc-ini-hyphen

Conversation

@grandixximo

Copy link
Copy Markdown
Contributor

The new ini parser restricts identifiers to letters, digits and underscore, which rejects names containing a dash. The historic parser had no identifier character restrictions, so dashed names parsed fine for decades. Two things break on master because of this:

  • the xhc-hb04 sample configs use dashed button names in [XHC_HB04_BUTTONS] (start-pause, goto-zero-x, ...), so these configs fail to load
  • the xhc-hb04 component's own layout cfg files use a [XHC-HB04] section, and the component parses them with the same IniFile class, so it exits at startup with "Could not open configuration file"

Renaming the identifiers is not a good option: the [XHC-HB04] section name is hardcoded in xhc-hb04.cc, and user pendant cfg files in the wild use the dashed layout format.

A dash is unambiguous in this grammar (not a delimiter, comment or quoting character), so this PR accepts it in identifiers. Identifiers starting with a dash remain rejected, same as those starting with a digit.

Docs updated (ini-config.adoc, inivalue.1.adoc), the inivalue test is extended with leading-dash rejection cases, and a new hyphen_identifiers test covers dashed section and variable names. Full inifile suite passes 11/11, and all four xhc-hb04 sample configs boot with the pendant's hal pins present.

@BsAtHome: was dropping the dash from the identifier set an intentional choice, or an omission? If it was deliberate (some ambiguity I am missing), the alternative is fixing the xhc-hb04 side instead, but that changes a long-documented cfg format and breaks existing user configs, so I would rather not.

The new ini parser restricts identifiers to letters, digits and underscore, rejecting names containing a dash. The historic parser had no identifier character restrictions, so files using dashes parsed fine for decades and now fail:

- the xhc-hb04 sample configs use dashed button names in [XHC_HB04_BUTTONS] (start-pause, goto-zero-x, ...), which makes these configs fail to load
- the xhc-hb04 component's own layout cfg files use a [XHC-HB04] section, so the component exits at startup with "Could not open configuration file"

A dash is unambiguous in this grammar (it is neither a delimiter, nor a comment or quoting character), so accept it in identifiers. Identifiers starting with a dash remain rejected, like those starting with a digit.

Update the identifier documentation accordingly, extend the inivalue test with leading-dash rejection cases, and add a hyphen_identifiers test covering dashed section and variable names.
@BsAtHome

Copy link
Copy Markdown
Contributor

It was intentional to drop the '-' and restrict the names to a real identifier.

The pendent was obviously missed. It also uses a very strange mismatch of underscore and dash.

What is even more telling is that the example int configs/sim/axis/ja_tests/xyzx_mpg/ has an include for the pendent, but it does not use the [XHC-HB04] section. It has [XHC_HB04_CONFIG] and [XHC_HB04_BUTTONS]. These are used in a Tcl wrapper lib/hallib/xhc-hb04.tcl, which is a HAL file to create signals and connections. The user-space application uses the [XHC-HB04] section for button mapping, usually from LIB:xhc-hb04-layout[12].cfg.

It is IMO a bit messy. Not sure whether we should keep it by adding the dash or actually clean up and refactor the code and process.

@grandixximo
grandixximo marked this pull request as draft September 19, 2026 23:45
@grandixximo

Copy link
Copy Markdown
Contributor Author

Thanks for the context. On the cleanup question, I looked at what a refactor would actually touch.

The dashed names are the documented, user-facing format in two places:

  1. The INI [XHC_HB04_BUTTONS] section. The tcl wrapper reads each key as a button name and generates nets against the comp's pins, so a user who remapped buttons the documented way has keys like "start-pause" in their INI.
  2. The comp's layout cfg file, which uses the [XHC-HB04] section and the same dashed button names.

Since the strict parser fails the whole file on the first dashed identifier, a rename to underscores makes all existing user INI and cfg files unreadable on upgrade. That said, 2.10 already breaks configs elsewhere (#4565, with #4499 and #4256 as migration tooling), so a deliberate rename of the pendant identifiers is not off the table. The button names live in the HAL pin names too (xhc-hb04.button-start-pause), so a rename would need migration coverage for INI keys, the layout cfg and HAL files. That feels like a decision for the Sunday meeting (agenda in #4566) rather than something to settle in this PR.

Whichever way that goes, this PR restores the pre-refactor behavior for the files that exist today, and a rename with migration support can still land on top if the meeting decides for it.

If the decision is to keep the dash, the only cosmetic cleanup left is:

  • xhc-hb04.cc accepts [XHC_HB04] as an alias for [XHC-HB04] when reading its layout cfg
  • the shipped lib/hallib/xhc-hb04-layout1.cfg and layout2.cfg and the man page examples move to the underscored spelling

Happy to do that as a follow-up, or to work on the full rename if the meeting prefers that route. Converting this PR to draft until there is a decision.

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.

2 participants