Function Syntax: PREF_SUFF_OKR_TXT Version: 1 Date: 0509.2025 N/A Description This LISP defines a small “text mass-edit” utility with a DCL dialog and several commands for adding/removing prefixes or suffixes (including wildcard-aware patterns), and for rounding numeric text to a specified number of decimal digits. It operates on TEXT, MTEXT, ATTRIB, and INSERT (but only the first attribute of the INSERT is edited). It persists dialog settings using environment variables (getenv/setenv). Commands provided - PREF_SUFF_OKR_TXT — main command, shows the dialog and then runs the chosen operation. - PREF — runs stored Prefix Add/Remove directly (no dialog). - SUFF — runs stored Suffix Add/Remove directly (no dialog). - OKR_TXT — rounds numeric text using stored digit count (no dialog). What the dialog does The dialog (written to a temp DCL at runtime) has three “modes” selected via radio buttons: 1) Prefix (rbPref): enables two input boxes: - Add (templated) value: pfx_add - Remove (wildcard) value: pfx_rem 2) Suffix (rbSuff): enables two input boxes: - Add (templated) value: sfx_add - Remove (wildcard) value: sfx_rem 3) Digits (rbOkr): enables one input box: - Digits (integer): digits There is also a Clear button that clears all inputs and sets digits to 0, plus OK/Cancel. Persistence (saved defaults) The routine stores and reloads its last-used settings via environment variables: - PSOT_ACT (1=Prefix, 2=Suffix, 3=Digits; default 3) - PSOT_PFX_ADD, PSOT_PFX_REM - PSOT_SFX_ADD, PSOT_SFX_REM - PSOT_DIG (digits string; default “0”) It also uses USERR1 as a temporary “mode flag” while the dialog is open (1/2/3). Selection scope and entity behavior When an operation runs (prefix/suffix add/remove or rounding), it prompts: Select TEXT/MTEXT/INSERT (first ATTRIB will be updated): and performs (ssget '((0 . "TEXT,MTEXT,INSERT,ATTRIB"))). For each selected item: - If it is TEXT / MTEXT / ATTRIB: edits group code 1 (text content) in-place via entmod. - If it is INSERT: finds the first attached attribute entity (ATTRIB) and edits that attribute’s group code 1 only. It does not iterate all attributes; only the first ATTRIB following the INSERT in the entity chain is modified. Prefix/Suffix Add behavior (templated) Add operations support two modes depending on whether the add string contains wildcards: - If the add string contains no * or ?: it is literal concatenation. - Prefix Add: (strcat pfx txt) - Suffix Add: (strcat txt sfx) - If the add string contains * or ?: it is treated as a template, where every occurrence of * and ? is replaced by the original text (the same text is substituted for both wildcard characters). - Implementation: PSOT-Template-Apply does “replace all ? with txt” then “replace all * with txt”. Example (template add): - Original text: ABC - Prefix add pattern: "[?]-" ⇒ becomes "[ABC]-" - Suffix add pattern: "-*" ⇒ becomes "-ABC" appended, i.e. ABC-ABC Note: because both “*” and “?” are replaced with the full original text, templates are “macro insertion,” not classic wildcard matching semantics. Prefix/Suffix Remove behavior (wildcard-aware, capture-retaining) Remove operations have two distinct behaviors depending on whether the remove pattern includes wildcards: - No wildcards (* or ? absent): strict string comparison removal. - Prefix Remove: if text starts with pfx, remove exactly that pfx. - Suffix Remove: if text ends with sfx, remove exactly that sfx. - Wildcard pattern present: uses a custom anchored wildcard engine for prefix or suffix matching, and then removes the matched portion while keeping a “captured” substring that comes from matching wildcard regions. How the wildcard engine works Supported pattern characters: - * matches any sequence (including empty). - ? matches any single character. All other characters must match exactly (case-sensitive as written). The engine is anchored by design: - Prefix remove uses PSOT-WC-Prefix-Match-CAP which attempts to match the pattern from the beginning of the string. - Suffix remove uses PSOT-WC-Suffix-Match-CAP, which reverses both string and pattern, runs the same prefix engine, then reverses the captured result back. Return value from the wildcard engine is either nil (no match) or a two-element list: - (len cap) Where: - len = number of characters from the source string consumed by the match. - cap = concatenation of characters consumed specifically via wildcard steps (from both “*” and “?” expansions), in left-to-right order. “Keeps captured” removal logic When a wildcard prefix match succeeds for text txt and pattern pfx, the prefix remover returns: (strcat cap (substr txt (1+ len))) Meaning: it removes the matched prefix of length len, but it prepends the captured wildcard text (cap) back to the front. When a wildcard suffix match succeeds for text txt and pattern sfx, the suffix remover returns: (strcat (substr txt 1 (- (strlen txt) len)) cap) Meaning: it removes the matched suffix of length len, but appends the captured wildcard text (cap) back at the end. This is a deliberate “remove wrapper but preserve wildcard-captured portion” behavior, not a traditional regex replace. Practically, it is useful for removing known surrounding patterns while retaining the variable part matched by wildcards. Concrete wildcard examples (1) Prefix remove with capture: - Text: PRE_123_X - Remove prefix patt