]> diplodocus.org Git - nmh/blobdiff - h/mh.h
rcvtty.c: Remove duplicate prototype. Other in mts.h.
[nmh] / h / mh.h
diff --git a/h/mh.h b/h/mh.h
index 1ff275b55b4559ac81d32004819d450f13e2e277..bb06366b3de3c1553adacc99be7ef28abdadecc3 100644 (file)
--- a/h/mh.h
+++ b/h/mh.h
 #define DMAXFOLDER     4       /* typical number of digits             */
 #define MAXFOLDER   1000       /* message increment                    */
 
 #define DMAXFOLDER     4       /* typical number of digits             */
 #define MAXFOLDER   1000       /* message increment                    */
 
+/* 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.
 /*
  * This macro is for use by scan, for example, so that platforms with
  * a small BUFSIZ can easily allocate larger buffers.
 #endif
 typedef unsigned char  boolean;  /* not int so we can pack in a structure */
 
 #endif
 typedef unsigned char  boolean;  /* not int so we can pack in a structure */
 
-/* If we're using gcc then give it some information about
- * functions that abort.
- */
+/* 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__))
 #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 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
 
 #define NMH_UNUSED(i) i
 #endif
 
@@ -61,24 +79,24 @@ typedef unsigned char  boolean;  /* not int so we can pack in a structure */
 typedef struct charstring *charstring_t;
 
 charstring_t charstring_create (size_t);
 typedef struct charstring *charstring_t;
 
 charstring_t charstring_create (size_t);
-charstring_t charstring_copy (const charstring_t);
+charstring_t charstring_copy (const charstring_t) NONNULL(1);
 void charstring_free (charstring_t);
 /* Append a single-byte character: */
 void charstring_free (charstring_t);
 /* Append a single-byte character: */
-void charstring_push_back (charstring_t, const char);
+void charstring_push_back (charstring_t, const char) NONNULL(1);
 /* Append possibly multi-byte character(s): */
 /* Append possibly multi-byte character(s): */
-void charstring_push_back_chars (charstring_t, const char [], size_t, size_t);
-void charstring_append (charstring_t, const charstring_t);
-void charstring_append_cstring (charstring_t, const char []);
-void charstring_clear (charstring_t);
+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. */
 /* 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);
+const char *charstring_buffer (const charstring_t) NONNULL(1);
 /* User is responsible for free'ing result of buffer copy. */
 /* User is responsible for free'ing result of buffer copy. */
-char *charstring_buffer_copy (const charstring_t);
-size_t charstring_bytes (const charstring_t);
-size_t charstring_chars (const charstring_t);
+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. */
 /* Length of the last character in the charstring. */
-int charstring_last_char_len (const charstring_t);
+int charstring_last_char_len (const charstring_t) NONNULL(1);
 
 /*
  * user context/profile structure
 
 /*
  * user context/profile structure
@@ -202,33 +220,33 @@ struct bvector {
 typedef struct bvector *bvector_t;
 
 bvector_t bvector_create (void);
 typedef struct bvector *bvector_t;
 
 bvector_t bvector_create (void);
-void bvector_init(struct bvector *bv);
-void bvector_copy (bvector_t, bvector_t);
-void bvector_free (bvector_t);
-void bvector_fini(struct bvector *bv);
-void bvector_clear (bvector_t, size_t);
-void bvector_clear_all (bvector_t);
-void bvector_set (bvector_t, size_t);
-unsigned int bvector_at (bvector_t, size_t);
-unsigned long bvector_first_bits (bvector_t);
+void bvector_init(struct bvector *bv) NONNULL(1);
+void bvector_copy (bvector_t, bvector_t) NONNULL(1, 2);
+void bvector_free (bvector_t) NONNULL(1);
+void bvector_fini(struct bvector *bv) NONNULL(1);
+void bvector_clear (bvector_t, size_t) NONNULL(1);
+void bvector_clear_all (bvector_t) NONNULL(1);
+void bvector_set (bvector_t, size_t) NONNULL(1);
+unsigned int bvector_at (bvector_t, size_t) NONNULL(1) PURE;
+unsigned long bvector_first_bits (bvector_t) NONNULL(1) PURE;
 
 typedef struct svector *svector_t;
 
 svector_t svector_create (size_t);
 
 typedef struct svector *svector_t;
 
 svector_t svector_create (size_t);
-void svector_free (svector_t);
-char *svector_push_back (svector_t, char *);
-char *svector_at (svector_t, size_t);
-char **svector_find(svector_t, const char *);
-char **svector_strs (svector_t);
-size_t svector_size (svector_t);
+void svector_free (svector_t) NONNULL(1);
+char *svector_push_back (svector_t, char *) NONNULL(1);
+char *svector_at (svector_t, size_t) NONNULL(1);
+char **svector_find(svector_t, const char *) NONNULL(1) PURE;
+char **svector_strs (svector_t) NONNULL(1) PURE;
+size_t svector_size (svector_t) NONNULL(1) PURE;
 
 typedef struct ivector *ivector_t;
 
 ivector_t ivector_create (size_t);
 
 typedef struct ivector *ivector_t;
 
 ivector_t ivector_create (size_t);
-void ivector_free (ivector_t);
-int ivector_push_back (ivector_t, int);
-int ivector_at (ivector_t, size_t);
-int *ivector_atp (ivector_t, size_t);
+void ivector_free (ivector_t) NONNULL(1);
+int ivector_push_back (ivector_t, int) NONNULL(1);
+int ivector_at (ivector_t, size_t) NONNULL(1);
+int *ivector_atp (ivector_t, size_t) NONNULL(1);
 
 /*
  * Primary structure of folder/message information
 
 /*
  * Primary structure of folder/message information
@@ -367,12 +385,28 @@ struct msgs {
                                   followed by a colon.  Add one for
                                   terminating NULL. */
 
                                   followed by a colon.  Add one for
                                   terminating NULL. */
 
-#define LENERR  (-2)           /* Name too long error from getfld  */
-#define FMTERR  (-3)           /* Message Format error             */
-#define FLD      0             /* Field returned                   */
-#define FLDPLUS  1             /* Field returned with more to come */
-#define BODY     3             /* Body  returned with more to come */
-#define FILEEOF  5             /* Reached end of input file        */
+/* Token type or error returned from m_getfld(), and its internal state
+ * for the next call. */
+/* FLD detects the header's name is too long to fit in the fixed size
+ * array. */
+#define LENERR  (-2)
+/* FLD reaches EOF after the header's name, or the name is followed by
+ * a linefeed rather than a colon and the body buffer isn't large enough
+ * to pretend this header line starts the body. */
+#define FMTERR  (-3)
+/* The initial state, looking for headers.  Returned when the header's
+ * value finishes. */
+#define FLD      0
+/* Another chunk of the header's value has been returned, but there's
+ * more to come. */
+#define FLDPLUS  1
+/* A chunk of the email's body has been returned. */
+#define BODY     3
+/* Either the end of the input file has been reached, or the delimiter
+ * between emails has been found and the caller should
+ * m_getfld_state_reset() to reset the state to FLD for continuing
+ * through the file. */
+#define FILEEOF  5
 
 typedef struct m_getfld_state *m_getfld_state_t;
 
 
 typedef struct m_getfld_state *m_getfld_state_t;