Seeking function which encodes an input string for xrm usage... - Xwindows

This is a discussion on Seeking function which encodes an input string for xrm usage... - Xwindows ; Hi! ---- Is there any function in libX11 or elsewhere which "encodes" an input string in a way that all special chars like '**, '\'', '"', ' ', '\n' etc. are escaped in a way that they don't cause chaos ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Seeking function which encodes an input string for xrm usage...

  1. Seeking function which encodes an input string for xrm usage...


    Hi!

    ----

    Is there any function in libX11 or elsewhere which "encodes" an input
    string in a way that all special chars like '**, '\'', '"', ' ', '\n'
    etc. are escaped in a way that they don't cause chaos in a XRM database
    ? I'd like to add random strings to a XRM database and like to ensure
    that the input doesn't screw-up the database...

    ----

    Bye,
    Roland

    --
    __ . . __
    (o.\ \/ /.o) roland.mainz@nrubsig.org
    \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
    /O /==\ O\ TEL +49 641 7950090
    (;O/ \/ \O

  2. Re: Seeking function which encodes an input string for xrm usage...

    Roland Mainz wrote:

    > Hi!


    > ----


    > Is there any function in libX11 or elsewhere which "encodes" an input
    > string in a way that all special chars like '**, '\'', '"', ' ', '\n'
    > etc. are escaped in a way that they don't cause chaos in a XRM database
    > ? I'd like to add random strings to a XRM database and like to ensure
    > that the input doesn't screw-up the database...


    man X:

    Any whitespace character before or after the name or colon
    in a ResourceSpec are ignored. To allow a Value to begin
    with whitespace, the two-character sequence ``\space''
    (backslash followed by space) is recognized and replaced by
    a space character, and the two-character sequence ``\tab''
    (backslash followed by horizontal tab) is recognized and
    replaced by a horizontal tab character. To allow a Value to
    contain embedded newline characters, the two-character
    sequence ``\n'' is recognized and replaced by a newline
    character. To allow a Value to be broken across multiple
    lines in a text file, the two-character sequence ``\new-
    line'' (backslash followed by newline) is recognized and
    removed from the value. To allow a Value to contain arbi-
    trary character codes, the four-character sequence ``\nnn'',
    where each n is a digit character in the range of
    ``0''-``7'', is recognized and replaced with a single byte
    that contains the octal value specified by the sequence.
    Finally, the two-character sequence ``\\'' is recognized and
    replaced with a single backslash.


    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net

  3. Re: Seeking function which encodes an input string for xrm usage...

    Thomas Dickey wrote:
    > > Is there any function in libX11 or elsewhere which "encodes" an input
    > > string in a way that all special chars like '**, '\'', '"', ' ', '\n'
    > > etc. are escaped in a way that they don't cause chaos in a XRM database
    > > ? I'd like to add random strings to a XRM database and like to ensure
    > > that the input doesn't screw-up the database...

    >
    > man X:
    >
    > Any whitespace character before or after the name or colon
    > in a ResourceSpec are ignored. To allow a Value to begin
    > with whitespace, the two-character sequence ``\space''
    > (backslash followed by space) is recognized and replaced by
    > a space character, and the two-character sequence ``\tab''
    > (backslash followed by horizontal tab) is recognized and
    > replaced by a horizontal tab character. To allow a Value to
    > contain embedded newline characters, the two-character
    > sequence ``\n'' is recognized and replaced by a newline
    > character. To allow a Value to be broken across multiple
    > lines in a text file, the two-character sequence ``\new-
    > line'' (backslash followed by newline) is recognized and
    > removed from the value. To allow a Value to contain arbi-
    > trary character codes, the four-character sequence ``\nnn'',
    > where each n is a digit character in the range of
    > ``0''-``7'', is recognized and replaced with a single byte
    > that contains the octal value specified by the sequence.
    > Finally, the two-character sequence ``\\'' is recognized and
    > replaced with a single backslash.


    There is no function in libX11 which takes care about encoding/decoding
    per above rules, right ?

    ----

    Bye,
    Roland

    --
    __ . . __
    (o.\ \/ /.o) roland.mainz@nrubsig.org
    \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
    /O /==\ O\ TEL +49 641 7950090
    (;O/ \/ \O

  4. Re: Seeking function which encodes an input string for xrm usage...

    Roland Mainz wrote:

    > There is no function in libX11 which takes care about encoding/decoding
    > per above rules, right ?


    not that I'm aware of. However, there are a lot of undocumented functions
    in X's libraries (anything like this, which isn't essential, is likely
    to fall into that category). Other than by grep'ing around for related
    scanf's or atoi's, etc, you're not likely to stumble upon it(*).

    If it did exist, I'd expect to find it in Xt or one of the libraries that
    depend on that, rather than X11. Functions that belong to X11 are related
    to the X protocol. Xt manages the resources.

    (*) of course you might stumble upon something which is listed in a public
    header file, and feel entitled to use it...

    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net

  5. Re: Seeking function which encodes an input string for xrm usage...

    Thomas Dickey wrote:

    > not that I'm aware of. However, there are a lot of undocumented functions


    I use grep (of course) to find information in the X libraries. And followup
    with grep on the related X specs & documentation. Sadly, the documentation
    generally lacks the detail that I'm looking for. (If it didn't, xterm's
    manpage wouldn't be the largest one in the X tree).

    --
    Thomas E. Dickey
    http://invisible-island.net
    ftp://invisible-island.net

  6. Re: Seeking function which encodes an input string for xrm usage...

    Roland Mainz wrote:
    >Thomas Dickey wrote:
    >> > Is there any function in libX11 or elsewhere which "encodes" an input
    >> > string in a way that all special chars like '**, '\'', '"', ' ', '\n'
    >> > etc. are escaped in a way that they don't cause chaos in a XRM database
    >> > ? I'd like to add random strings to a XRM database and like to ensure
    >> > that the input doesn't screw-up the database...

    >>
    >> man X:
    >>
    >> Any whitespace character before or after the name or colon
    >> in a ResourceSpec are ignored. To allow a Value to begin
    >> with whitespace, the two-character sequence ``\space''
    >> (backslash followed by space) is recognized and replaced by
    >> a space character, and the two-character sequence ``\tab''
    >> (backslash followed by horizontal tab) is recognized and
    >> replaced by a horizontal tab character. To allow a Value to
    >> contain embedded newline characters, the two-character
    >> sequence ``\n'' is recognized and replaced by a newline
    >> character. To allow a Value to be broken across multiple
    >> lines in a text file, the two-character sequence ``\new-
    >> line'' (backslash followed by newline) is recognized and
    >> removed from the value. To allow a Value to contain arbi-
    >> trary character codes, the four-character sequence ``\nnn'',
    >> where each n is a digit character in the range of
    >> ``0''-``7'', is recognized and replaced with a single byte
    >> that contains the octal value specified by the sequence.
    >> Finally, the two-character sequence ``\\'' is recognized and
    >> replaced with a single backslash.

    >
    >There is no function in libX11 which takes care about encoding/decoding
    >per above rules, right ?


    XrmPutFileDatabase will do this, but I doubt it's the way to go.

    Xt resources are built around converters; much as printf/scanf will
    convert to/from "123" and 123, Xt allows you to define converters to
    convert between the internal and external forms of a resource. The
    external form is always XtRString, and it is a multibyte string (in
    the current locale), possibly including the above escapes.

    So, consider something like an encryption key or MD5 sum, which is a
    string of arbitrary bytes. The external form is the printable
    hexadecimal representation, and this is what should be stored in a .ad
    file. You simply define a converter that converts the printed hex to
    an internal string.

    In this example, using the escaped octal form is piker programming:
    it might not be read back correctly under a different locale.


+ Reply to Thread