#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
#define DEBUG 0
+#if DEBUG
+static void debug_buffer (FILE *, const char *);
+#endif
+
static mexp_h *
create_handle (void)
{
h->buffer[h->len] = '\0';
#if DEBUG
fprintf (stderr, "DEBUG: read %zd bytes from pty\n", rs);
- fprintf (stderr, "DEBUG: buffer content: %s\n", h->buffer);
+ fprintf (stderr, "DEBUG: buffer content: ");
+ debug_buffer (stderr, h->buffer);
+ fprintf (stderr, "\n");
#endif
try_match:
return -1;
#if DEBUG
- fprintf (stderr, "DEBUG: writing: %s\n", msg);
+ fprintf (stderr, "DEBUG: writing: ");
+ debug_buffer (stderr, msg);
+ fprintf (stderr, "\n");
#endif
n = len;
{
return write (h->fd, "\003", 1);
}
+
+#if DEBUG
+/* Print escaped buffer to fp. */
+static void
+debug_buffer (FILE *fp, const char *buf)
+{
+ while (*buf) {
+ if (isprint (*buf))
+ fputc (*buf, fp);
+ else {
+ switch (*buf) {
+ case '\0': fputs ("\\0", fp); break;
+ case '\a': fputs ("\\a", fp); break;
+ case '\b': fputs ("\\b", fp); break;
+ case '\f': fputs ("\\f", fp); break;
+ case '\n': fputs ("\\n", fp); break;
+ case '\r': fputs ("\\r", fp); break;
+ case '\t': fputs ("\\t", fp); break;
+ case '\v': fputs ("\\v", fp); break;
+ default:
+ fprintf (fp, "\\x%x", (unsigned char) *buf);
+ }
+ }
+ buf++;
+ }
+}
+#endif
+