On Sun, 2021-04-18 at 12:38 -0900, Philip Guenther wrote: > On Sun, Apr 18, 2021 at 12:04 PM Martijn van Duren > <openbsd+t...@list.imperialat.at> wrote: > > On Sun, 2021-04-18 at 11:17 -0900, Philip Guenther wrote: > > > > > > I'll just throw in a note that the current POSIX spec does not include > > > support for \x in the printf(1) format or in the argument to the %b > > > format specifier. At least for \x in the format string > > it > > > appears to require that it _not_ be interpreted, such that > > > printf '\x61\n' > > > must output > > > \x61 > > > and not > > > a > > > > Could you point out where it states that an escape-sequence not > > specified must output the original text? The way I read it[0][1]: > > > > In addition to the escape sequences shown in XBD File Format Notation ( > > '\\', '\a', '\b', '\f', '\n', '\r', '\t', '\v' ), "\ddd", where ddd is a > > one, two, or three-digit octal number, shall be written as a byte with > > the numeric value specified by the octal number. > > > > and > > > > Escape Sequences and Associated Actions lists escape sequences and > > associated actions on display devices capable of the action. > > > > > Before that statement in XBD 5 is this: > ----- > The format is a character string that contains three types of objects defined > below: > > 1. Characters that are not "escape sequences" or "conversion > specifications", as described > below, shall be copied to the output. > > 2. Escape Sequences represent non-graphic characters and the escape > character (<backslash>). > > 3. Conversion Specifications specify the output format of each argument; > see below. > ----- > > So, per (1) above, if it's not an escape sequence or conversion > specification, it SHALL be copied to the output. Unfortunately, the list of > escape sequences is just a table, and while the printf(1) > specification has the clause you cited that adds \ddd to the list, there's > nothing to state that, for formats, <backslash> followed by anything else > results in unspecified behavior. Ergo \x isn't > an escape sequence under (2) and, since it's not a converspecification, it > must follow (1) and be copied to the output.
I read (1) as "escape sequences" as backslash followed by <something>, but you're right: it doesn't state that. > > Anyway, POSIX wording will probably change, it's just a place to note in the > manual that handling \xXX is an extension to the POSIX standard and that > compliant (or portable) applications must use > \ddd instead. > My diff already added \x to the extensions list in printf(1), so I guess that's already covered. Or do you think it needs to be more explicit? > > Philip Guenther >