• Problem: format and backslash string

    From aotto1968@21:1/5 to All on Thu Feb 2 12:21:46 2023
    Hi,

    I use a "format" to get table-like data

    puts -nonewline [format {regsub: %-50s -> %-20s : } "$RX" "$RP"]

    but get

    regsub: [[:space:]]+[[:xdigit:]]+[.] -> XXX. : OK
    regsub: [\[]\d+:\d+[\]] -> DDD : KO


    the problem seems to be the '\' who are in real '\\'.

    my problem is *not* that '\\' is reduced to '\', my problem is that '%50s' does not really *recognize*
    the '\\' and does *not* create final 50-char-string.

    *OR*

    the '\\' is handled proper by "format" *but* the terminal *eat* the '\\'. this is a than a problem from 'puts' to encode
    '\\' into real '\\'

    my encoding is: de_DE.UTF-8


    ao

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From heinrichmartin@21:1/5 to All on Thu Feb 2 05:38:00 2023
    On Thursday, February 2, 2023 at 12:26:54 PM UTC+1, ao wrote:
    puts -nonewline [format {regsub: %-50s -> %-20s : } "$RX" "$RP"]

    What is RX? I.e. how did you set the variable? What does [puts $RX] show?

    regsub: [[:space:]]+[[:xdigit:]]+[.] -> XXX. : OK
    regsub: [\[]\d+:\d+[\]] -> DDD : KO

    I am reading your message on a reader that screws up space; so I might drop out if I cannot contribute further.

    the problem seems to be the '\' who are in real '\\'.

    my problem is *not* that '\\' is reduced to '\', my problem is that '%50s' does not really *recognize*
    the '\\' and does *not* create final 50-char-string.

    I cannot reproduce this issue:
    set t {[\[]\d+:\d+[\]]}
    puts $t ;# [\[]\d+:\d+[\]]
    puts [format {>>>%-50s<<<} $t] ;# >>>[\[]\d+:\d+[\]] <<<
    puts [format {>>>%50s<<<} $t] ;# >>> [\[]\d+:\d+[\]]<<<

    HTH
    Martin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Harald Oehlmann@21:1/5 to All on Thu Feb 2 14:36:42 2023
    Am 02.02.2023 um 12:21 schrieb aotto1968:
    Hi,

    I use a "format" to get table-like data

    puts -nonewline [format {regsub: %-50s -> %-20s : } "$RX" "$RP"]

    but get

    regsub: [[:space:]]+[[:xdigit:]]+[.]                       ->
    XXX.                 : OK
    regsub: [\[]\d+:\d+[\]]                                ->
    DDD                  : KO


    the problem seems to be the '\' who are in real '\\'.

    my problem is *not* that '\\' is reduced to '\', my problem is that
    '%50s' does not really *recognize*
    the '\\' and does *not* create final 50-char-string.

    *OR*

    the '\\' is handled proper by "format" *but* the terminal *eat* the
    '\\'. this is a than a problem from 'puts' to encode
    '\\' into real '\\'

    my encoding is: de_DE.UTF-8


    ao

    Andreas,
    thank you for the question. I have not seen this. But with "\" it is
    sometimes hard to find the real string content.
    Could you show a whole example with input string in TCL ?

    For me, the "format "%-5s" works well, as long as the data is less or
    equal to 5 characters in length. Also remember, that "out glyphs" and characters may be something else.

    Example:

    % # String with \AB\ -> 4 Chars in length
    % set s "\\AB\\"
    % set o [format %-5s $s]
    \AB\
    % string length $o
    5

    If the data is more than 5 characters, it is not shortened.
    % format %-5s 123456
    123456

    Harald

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rich@21:1/5 to aotto1968@t-online.de on Thu Feb 2 14:53:28 2023
    aotto1968 <aotto1968@t-online.de> wrote:
    Hi,

    I use a "format" to get table-like data

    puts -nonewline [format {regsub: %-50s -> %-20s : } "$RX" "$RP"]

    but get

    regsub: [[:space:]]+[[:xdigit:]]+[.] -> XXX. : OK
    regsub: [\[]\d+:\d+[\]] -> DDD : KO


    the problem seems to be the '\' who are in real '\\'.

    my problem is *not* that '\\' is reduced to '\', my problem is that
    '%50s' does not really *recognize* the '\\' and does *not* create
    final 50-char-string.

    *OR*

    the '\\' is handled proper by "format" *but* the terminal *eat* the
    '\\'. this is a than a problem from 'puts' to encode '\\' into real
    '\\'

    my encoding is: de_DE.UTF-8

    You'll need to post some actual code, that is self contained and
    executable, including actual inputs that trigger the issue because
    given your description above I can not trigger the problem:

    Test code:

    #!/usr/bin/tclsh

    puts "regsub: [string repeat | 50] -> [string repeat | 20] : "

    set RX "qwerty"
    set RP "UIOP"

    puts [format {regsub: %-50s -> %-20s : } "$RX" "$RP"]

    set RX "qwerty \\ \\ \\ \\ qwerty"
    set RP "uiop \\ % \$ uiop"

    puts [format {regsub: %-50s -> %-20s : } "$RX" "$RP"]

    set RX "qwerty \\\\\\\\\\\\\\\\\\\\ qwerty"
    set RP "uiop \\\\\\ uiop \\\\"

    puts [format {regsub: %-50s -> %-20s : } "$RX" "$RP"]

    Test run (note, long lines, but on a monospace display everything
    lines up properly):

    $ ./tt
    regsub: |||||||||||||||||||||||||||||||||||||||||||||||||| -> |||||||||||||||||||| :
    regsub: qwerty -> UIOP :
    regsub: qwerty \ \ \ \ qwerty -> uiop \ % $ uiop :
    regsub: qwerty \\\\\\\\\\ qwerty -> uiop \\\ uiop \\ :

    So presence of a backslash in the variable being formatted by the %s
    format specifier does not appear to have any impact on the correct
    output.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ralf Fassel@21:1/5 to All on Thu Feb 2 18:13:59 2023
    * aotto1968 <aotto1968@t-online.de>
    | I use a "format" to get table-like data

    | puts -nonewline [format {regsub: %-50s -> %-20s : } "$RX" "$RP"]

    Are there TABs in RX or RP? They would print additional whitespace
    which messes up the columns.

    Maybe try

    format {regsub: {%-50s} -> {%-20s} : } ...

    so you see where the variable content starts and ends.

    HTH
    R'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From aotto1968@21:1/5 to All on Fri Feb 3 09:43:18 2023
    On 02.02.23 12:21, aotto1968 wrote:
    Hi,

    I use a "format" to get table-like data

    puts -nonewline [format {regsub: %-50s -> %-20s : } "$RX" "$RP"]

    but get

    regsub: [[:space:]]+[[:xdigit:]]+[.]                       -> XXX.                 : OK
    regsub: [\[]\d+:\d+[\]]                                -> DDD                  : KO


    the problem seems to be the '\' who are in real '\\'.

    my problem is *not* that '\\' is reduced to '\', my problem is that '%50s' does not really *recognize*
    the '\\' and does *not* create final 50-char-string.

    *OR*

    the '\\' is handled proper by "format" *but* the terminal *eat* the '\\'. this is a than a problem from 'puts' to encode
    '\\' into real '\\'

    my encoding is: de_DE.UTF-8


    ao

    Well, sometimes it is the user and not the tool

    exec 3< <(eval ${SANITIZE} $PREFIX "$EXE" "${@@Q}" |& tee "$log")
    while read -r -u3 line; do
    flag=0
    echo -E "$line"
    [[ ( "$line" == $cmd:*Total* && !("$line" =~ .*Failed.*[1-9].*) ) ||
    "$line" == *"SRV_LST is empty"* ]] && EXIT=0
    done

    This formatting-error happen during post-processing of the test-result and the problem was the missing '-r' in read

    ao

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)