+/* non-zero exit(3) values indicating the number of errors need to be
+ * capped else they interfere with the shell's use of high seven-bit
+ * values, and the shell's mapping of signals onto top-bit-set values.
+ * Plus, every so often the eight-bit value will wrap to zero, wrongly
+ * indicating success. */
+#define MAX_EXIT 120
+
+/*
+ * This macro is for use by scan, for example, so that platforms with
+ * a small BUFSIZ can easily allocate larger buffers.
+ */
+#define NMH_BUFSIZ max(BUFSIZ, 8192)
+
+#ifndef FALSE
+#define FALSE false
+#endif
+#ifndef TRUE
+#define TRUE true
+#endif
+typedef unsigned char boolean; /* not int so we can pack in a structure */
+
+/* If we're using gcc then tell it extra information so it can do more
+ * compile-time checks. */
+#if __GNUC__ > 2
+#define NORETURN __attribute__((__noreturn__))
+#define CHECK_PRINTF(fmt, arg) __attribute__((format(printf, fmt, arg)))
+#define ALLOC_SIZE(...) __attribute__((alloc_size(__VA_ARGS__)))
+#define CONST __attribute__((const))
+#define MALLOC __attribute__((malloc))
+#define NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
+#define PURE __attribute__((pure))
+#define NMH_UNUSED(i) (void) i
+#else
+#define NORETURN
+#define CHECK_PRINTF(fmt, arg)
+#define ALLOC_SIZE(...)
+#define CONST
+#define MALLOC
+#define NONNULL(...)
+#define PURE
+#define NMH_UNUSED(i) i
+#endif
+
+/* DIM gives the number of elements in the one-dimensional array a. */
+#define DIM(a) (sizeof (a) / sizeof (*(a)))
+
+/* LEN gives the strlen() of string constant s, excluding the
+ * terminating NUL. */
+#define LEN(s) (sizeof (s) - 1)
+
+/* FENDNULL fends off NULL by giving an empty string instead. */
+#define FENDNULL(s) ((s) ? (s) : "")
+
+/*
+ * char array that keeps track of size in both bytes and characters
+ * Usage note:
+ * Don't store return value of charstring_buffer() and use later
+ * after intervening push_back's; use charstring_buffer_copy()
+ * instead.
+ */
+typedef struct charstring *charstring_t;
+
+charstring_t charstring_create (size_t);
+charstring_t charstring_copy (const charstring_t) NONNULL(1);
+void charstring_free (charstring_t);
+/* Append a single-byte character: */
+void charstring_push_back (charstring_t, const char) NONNULL(1);
+/* Append possibly multi-byte character(s): */
+void charstring_push_back_chars (charstring_t, const char [], size_t, size_t) NONNULL(1);
+void charstring_append (charstring_t, const charstring_t) NONNULL(2);
+void charstring_append_cstring (charstring_t, const char []) NONNULL(2);
+void charstring_clear (charstring_t) NONNULL(1);
+/* Don't store return value of charstring_buffer() and use later after
+ intervening push_back's; use charstring_buffer_copy() instead. */
+const char *charstring_buffer (const charstring_t) NONNULL(1);
+/* User is responsible for free'ing result of buffer copy. */
+char *charstring_buffer_copy (const charstring_t) NONNULL(1);
+size_t charstring_bytes (const charstring_t) NONNULL(1) PURE;
+size_t charstring_chars (const charstring_t) NONNULL(1) PURE;
+/* Length of the last character in the charstring. */
+int charstring_last_char_len (const charstring_t) NONNULL(1);
+