Extended the function of the "findlabel" command; previously, the

documentation implied that "findlabel -glob <pattern> <n>" is a
meaningful set of command options, but in fact was not implemented
and did not raise an error for wrong number of arguments.  Instead,
this has now been implemented to mean find (and set the box position
to) the <n>th label containing <pattern>.
This commit is contained in:
R. Timothy Edwards 2026-07-17 12:07:25 -04:00
parent cc4da9a05f
commit 42b346e318
2 changed files with 42 additions and 10 deletions

View File

@ -1 +1 @@
8.3.675 8.3.676

View File

@ -814,7 +814,9 @@ CmdFindLabel(
int found, occur, plainargs; int found, occur, plainargs;
bool doglob = FALSE; /* csh-style glob matching (see utils/match.c) */ bool doglob = FALSE; /* csh-style glob matching (see utils/match.c) */
LabSearchRec lsr; LabSearchRec lsr;
int dbListLabels(SearchContext *scx, Label *label, TerminalPath *tpath, ClientData cdarg); /* forward declaration */
/* Forward declaration */
int dbListLabels(SearchContext *scx, Label *label, TerminalPath *tpath, int *occur);
plainargs = cmd->tx_argc; plainargs = cmd->tx_argc;
if ((plainargs > 2) && !strncmp(cmd->tx_argv[1], "-glob", 5)) if ((plainargs > 2) && !strncmp(cmd->tx_argv[1], "-glob", 5))
@ -825,10 +827,10 @@ CmdFindLabel(
if ((plainargs != 2) && (plainargs != 3)) if ((plainargs != 2) && (plainargs != 3))
goto usage; goto usage;
occur = 0; occur = -1;
if (plainargs == 3) if (plainargs == 3)
{ {
char *occurstr = cmd->tx_argv[plainargs - 1]; char *occurstr = cmd->tx_argv[cmd->tx_argc - 1];
if (StrIsInt(occurstr)) if (StrIsInt(occurstr))
occur = atoi(occurstr); occur = atoi(occurstr);
} }
@ -867,12 +869,13 @@ CmdFindLabel(
scx.scx_trans = GeoIdentityTransform; scx.scx_trans = GeoIdentityTransform;
DBSearchLabel(&scx, &DBAllButSpaceAndDRCBits, 0, labname, DBSearchLabel(&scx, &DBAllButSpaceAndDRCBits, 0, labname,
dbListLabels, (ClientData) 0); dbListLabels, (ClientData)&occur);
} }
else else
{ {
/* Exact-match label search (corrected by Nishit, 10/14/04) */ /* Exact-match label search (corrected by Nishit, 10/14/04) */
if (occur < 0) occur = 0;
lsr.lsr_occur = occur; lsr.lsr_occur = occur;
found = DBSrLabelLoc(labUse, labname, cmdFindLabelFunc, found = DBSrLabelLoc(labUse, labname, cmdFindLabelFunc,
@ -897,8 +900,22 @@ usage:
} }
/* /*
* ----------------------------------------------------------------------------
*
* dbListLabels --
*
* Callback routine for listing pattern-matched labels. * Callback routine for listing pattern-matched labels.
* Always return zero to keep the search going. * If "occur" is -1, then list every pattern-matched label found.
* Otherwise, if "occur" is >= 0, list only the matched label at this
* index (if any).
*
* Results:
* Always return zero to keep the search going.
*
* Side effects:
* Client data "occur" is decremented if it is >= 0.
*
* ----------------------------------------------------------------------------
*/ */
int int
@ -906,21 +923,36 @@ dbListLabels(
SearchContext *scx, SearchContext *scx,
Label *label, /* Pointer to label structure */ Label *label, /* Pointer to label structure */
TerminalPath *tpath, /* Full pathname of terminal */ TerminalPath *tpath, /* Full pathname of terminal */
ClientData cdarg) /* (unused) */ int *occur) /* If >= 0, find nth occurrence */
{ {
char *n = tpath->tp_next; char *n = tpath->tp_next;
char c = *n; char c = *n;
strcpy(n, label->lab_text); strcpy(n, label->lab_text);
if (((*occur) == 0) || ((*occur) == -1))
{
#ifdef MAGIC_WRAPPER #ifdef MAGIC_WRAPPER
Tcl_AppendElement(magicinterp, tpath->tp_first); Tcl_AppendElement(magicinterp, tpath->tp_first);
#else #else
TxPrintf("%s\n", tpath->tp_first); TxPrintf("%s\n", tpath->tp_first);
#endif #endif
if ((*occur) == 0)
{
Rect r;
(*occur) = -2;
r = label->lab_rect;
if (r.r_xbot == r.r_xtop) r.r_xtop++;
if (r.r_ybot == r.r_ytop) r.r_ytop++;
ToolMoveBox(TOOL_BL, &r.r_ll, FALSE, scx->scx_use->cu_def);
ToolMoveCorner(TOOL_TR, &r.r_ur, FALSE, scx->scx_use->cu_def);
}
}
if ((*occur) > 0) (*occur)--;
*n = c; *n = c;
return 0; return 0;
} }
/* /*
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
* *