Skip to content

Do not mistake -%i and -@i for the -i continue flag#618

Open
xroche wants to merge 2 commits into
masterfrom
fix-argorder
Open

Do not mistake -%i and -@i for the -i continue flag#618
xroche wants to merge 2 commits into
masterfrom
fix-argorder

Conversation

@xroche

@xroche xroche commented Jul 16, 2026

Copy link
Copy Markdown
Owner

httrack <URL> --build-top-index exits 255 on the usage screen instead of crawling. The pass in htscoremain.c that counts URLs also detects -i (continue), and it looked for a bare i with strchr() on anything cmdl_opt() calls an option. That test runs after optalias_check() has expanded the long aliases, so --build-top-index (-%i) and --protocol N (-@iN) matched the letter and wiped the URL list. The neighbouring strchr(..., 'q') has the same flaw, where -%q / --include-query-string quietly forces quiet mode.

The flag is now found by walking the cluster the way the parser does (htscoremain.c:948): %, &, @ and # each take the letter after them into another option set, whatever their position, so the i of -%i is not the main-set -i while the one in -%Mi still is. & is on that list because the -& to -% rewrite only fires at position 0, leaving -q&i to reach the parser as-is. Testing the second character alone was not enough: it dropped continue mode for -%qi and -%Mi and left -q%i on the usage screen. No documented option or alias reaches those spellings, since they all put the prefix first, but the helper agrees with the parser now. -i, -iC1, -iC2, --continue and --update keep forcing continue and dropping the URL list exactly as they do today.

I went through the alias table rather than patching the two spellings I had: -i, -iC1 and -iC2 are the intended matches, -%i and -@i the broken ones. The rule only runs one way, argv_url = -1 when the user asked to continue. The reverse has never held and still does not, because cmdl_opt()'s heuristic hands a filter like -imagedir to the same branch. Filters carrying a ., / or * were never in scope.

Tests go in the existing offline 01_engine-cmdline.test. Six cases fail on master and pass here, and the continue guards look for the usage screen rather than any nonzero exit, so they show continue mode was actually entered. They discriminate in both directions: the second-character helper fails four of them, -q%i and -q@i for the bug plus -%qi and -%Mi for the regression, and mutating the helper to always return false fires the -i guard. The -%q case has no teeth and I left it labelled that way. A run whose stdout is not a tty is forced quiet before argv parsing (htscoremain.c:174), so the suite cannot see that flag at all. I checked that half under a pty instead, where master -%q prints usage and this branch opens the wizard, with -q and -%g0 as controls.

Closes #615

xroche and others added 2 commits July 16, 2026 23:42
The pass that counts URLs also detects -i (continue), and for anything
cmdl_opt() calls an option it looked for a bare 'i' with strchr(). That runs
after optalias_check() has expanded the long aliases, so --build-top-index
(-%i) and --protocol N (-@in) matched too: they wiped the URL list and left
the run on the usage screen, exit 255. The neighbouring 'q' test had the same
flaw, with -%q silently forcing quiet mode.

Look for the flag in plain short-option clusters only, so -i, -iC1, -iC2 and
--continue keep forcing continue mode while prefixed options stay distinct.

Closes #615

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
The helper tested the second character only, which disagreed with the parser
in both directions: it dropped continue mode for -%qi and -%Mi, where the
trailing i does reach the main set, and it still mistook the i of -q%i for
-i, leaving that spelling on the usage screen.

Walk the cluster instead, letting %, &, @ and # take the letter after them
into another set wherever they sit. & matters because the -& to -% rewrite
only fires at position 0, so -q&i reaches the parser as-is.

None of this is reachable through a documented option or an alias, which all
place the prefix first; it keeps the helper honest against hand-written
clusters.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Xavier Roche <roche@httrack.com>
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.

httrack <URL> --build-top-index exits 255 with the usage screen instead of crawling

1 participant