+static
+void print_escape_string(struct text_component *text, const char *str)
+{
+ int i;
+
+ fputc('"', text->out);
+ for (i = 0; i < strlen(str); i++) {
+ /* Escape sequences not recognized by iscntrl(). */
+ switch (str[i]) {
+ case '\\':
+ fputs("\\\\", text->out);
+ continue;
+ case '\'':
+ fputs("\\\'", text->out);
+ continue;
+ case '\"':
+ fputs("\\\"", text->out);
+ continue;
+ case '\?':
+ fputs("\\\?", text->out);
+ continue;
+ }
+
+ /* Standard characters. */
+ if (!iscntrl(str[i])) {
+ fputc(str[i], text->out);
+ continue;
+ }
+
+ switch (str[i]) {
+ case '\0':
+ fputs("\\0", text->out);
+ break;
+ case '\a':
+ fputs("\\a", text->out);
+ break;
+ case '\b':
+ fputs("\\b", text->out);
+ break;
+ case '\e':
+ fputs("\\e", text->out);
+ break;
+ case '\f':
+ fputs("\\f", text->out);
+ break;
+ case '\n':
+ fputs("\\n", text->out);
+ break;
+ case '\r':
+ fputs("\\r", text->out);
+ break;
+ case '\t':
+ fputs("\\t", text->out);
+ break;
+ case '\v':
+ fputs("\\v", text->out);
+ break;
+ default:
+ /* Unhandled control-sequence, print as hex. */
+ fprintf(text->out, "\\x%02x", str[i]);
+ break;
+ }
+ }
+ fputc('"', text->out);
+}
+