ANSI escape characters in gprolog - prolog

Trying to print bold and underlined text in prolog but can't write them
write('\033[1mbold\033[0m')
Makes this (expected) error:
syntax error: \ expected in \constant\ sequence
What's the correct way to do it with gprolog ? Maybe with format ?

write('\33\[1mbold\33\[0m').
That is, octal escape sequences (and hexadecimal which start with \x) need to be closed with a \ too. En revanche, a leading zero is not required, but possible. This is in no way specific to GNU, in fact, probably all systems close to ISO Prolog have it.

Related

What is the meaning of special character sequences like `\027[0K`?

I found this commit from facebook infer, and I have no idea what \027[0K and \027[%iA means.
What does these special string mean? And (I think) if there are more strings like this, where can I find the full documentation about this?
Those are escape sequences to tell your terminal what to do.
For example, the sequence of characters represented by \027[0K (where \027 is ASCII decimal value for Esc character) tells the terminal to "clear line from cursor to the end."
One helpful document/guide on this subject can be found at https://shiroyasha.svbtle.com/escape-sequences-a-quick-guide-1
The facebook code is copied from another source here, which uses hard-coded formatters imitating termcap (this page gives some background). The original has comments indicating where its information came from.
The formatter uses "%i" for integers. That's a repeat-count for the cursor movement "cursor-up" \033[A
In most languages, \033 (octal) is used for the ASCII escape character. But this source (according to the github analysis) is written in OCaml, and is using the decimal value for the ASCII escape character. According to the OCaml syntax, you could use an octal value like this: \o033
Once you see that the formatting parts (how the escape character is represented, the use of %i to format a number), the rest of this is documented in several places.
The relevant standard is ECMA-48
the termcap (or analogous terminfo) information is in the terminal database.

What does the "%" mean in tcl?

In a situation like this for example:
[% $create_port %]
or [list [% $RTL_LIST %]]
I realized it had to do with the brackets, but what confuses me is that sometimes it is used with the brackets and variable followed, and sometimes you have brackets with variables inside without the %.
So i'm not sure what it is used for.
Any help is appreciated.
% is not a metacharacter in the Tcl language core, but it still has a few meanings in Tcl. In particular, it's the modulus operator in expr and a substitution field specifier in format, scan, clock format and clock scan. (It's also the default prompt character, and I have a trivial pass-through % command in my ~/.tclshrc to make cut-n-pasting code easier, but nobody else in the world needs to follow my lead there!)
But the code you have written does not appear to be any of those (because it would be a syntax error in all of the commands I've mentioned). It looks like it is some sort of directive processing scheme (with the special sequences being [% and %], with the brackets) though not one I recognise such as doctools or rivet. Because a program that embeds a Tcl interpreter could do an arbitrary transformation to scripts before executing them, it's extremely difficult to guess what it might really be.

Ruby regex /[\xF0-\xF7][\x80-\xBF]{3}/ -- "too short escaped multibyte character" error

This regex works in PHP:
preg_match('/[\xF0-\xF7][\x80-\xBF]{3}/', '𤋮');
I need to port it to Ruby:
/[\xF0-\xF7][\x80-\xBF]{3}/ =~ '𤋮'
Just prints too short escaped multibyte character: /[\xF0-\xF7][\x80-\xBF]{3}/ error.
What is wrong here? I don't understand what this error is saying. Tried to do more escaping with \\, but nothing.
The I think your character encoding is off. If you're trying to specify a particular unicode code point, use the \u#### escape sequence.
However, a more robust way of handling translations between string encodings is described here. That would allow you to specify an input encoding, a desired output encoding, and let Ruby do the work of removing the characters you don't want.

BASH/Readline Verbatim Null Character

I'm trying to understand exactly who among the set of TTY, kernel, line discipline, and shell actually deals with any given part of my input. In particular, I've been working through this article:
The TTY demystified
My question: if I want to have the actual delete character show up in BASH, I can use ^V to make it verbatim. E.g. I can use Ctrl+V then Ctrl+H to have a backspace character. Pretty neat!
echo '3^H'
3
My question is this: if I'm in something that reads in canonical mode (I believe cat does this) I can put a null character in there by doing Ctrl+V then Ctrl+2 (basically Ctrl+#, which is the caret notation for the null character).
BASH won't allow me to have a verbatim null character on one of its lines, though, and it looks like python and other readline programs won't either.
Does anybody know why this is, or a general-purpose workaround?
The C library uses a literal null as a string terminator, so anything using that is unable to represent strings containing literal nulls.
Programs which need to support literal nulls define their own string data type.

Is there a warning in gcc for octal literals?

ie. so that if you use any octal literals it give you a warning.
Same question for Microsoft's compiler.
If not are there any other tools to detect octal literals.
(vim seems to have a cool trick where it highlights the first leading
zero a different color, but I'm thinking more of an automated tool).
I don't believe gcc has such a warning. I just ran info gcc (for gcc 4.5.2) and searched for "octal". There were only two occurrences, neither of them useful.
I don't know about Microsoft's compiler.
You could search your source files for a regular expression that matches octal constants. If you have grep, something like this should do the trick (warning: I haven't tested this):
grep '\<0[0-7][0-7]*' foo.c
This matches a 0 followed by one or more digits in the range 0..7, at the beginning of a word. It deliberately does not match 0, which is an octal constant but presumably not one you're worried about. It's likely to give you some false positives, for example in string literals and comments. It will also match a character constant like '\007', which is octal but not as error-prone as an octal integer constant.
(Question is tagged gcc, but text asks about Microsoft's compiler as well.)
I don't think MSVC++ has a warning for general octal literals, but it will warn about suspicious octal escape sequences in string literals. For example "foo \669", will trigger "C4125 decimal digit terminates octal escape sequence" if you have the warning level turned all the way up.

Resources