]> diplodocus.org Git - nmh/blob - h/utils.h
c866a52c194936c5da286bd045e0399ca901a6cb
[nmh] / h / utils.h
1
2 /*
3 * utils.h -- utility prototypes
4 */
5
6 /* Call malloc(3), exiting on NULL return. */
7 void *mh_xmalloc(size_t size);
8
9 /* Call realloc(3), exiting on NULL return. */
10 void *mh_xrealloc(void *ptr, size_t size);
11
12 /* Call calloc(3), exiting on NULL return. */
13 void *mh_xcalloc(size_t nelem, size_t elsize);
14
15 /* Call free(3), if ptr isn't NULL. */
16 void mh_xfree(void *ptr);
17
18 /* Set p to point to newly allocated, uninitialised, memory. */
19 #define NEW(p) ((p) = mh_xmalloc(sizeof *(p)))
20
21 /* Set p to point to newly allocated, zeroed, memory. */
22 #define NEW0(p) ((p) = mh_xcalloc(1, sizeof *(p)))
23
24 char *pwd(void);
25 char *add(const char *, char *);
26 char *addlist(char *, const char *);
27 int folder_exists(const char *);
28 void create_folder(char *, int, void (*)(int));
29 int num_digits(int);
30
31 /*
32 * A vector of char array, used to hold a list of string message numbers
33 * or command arguments.
34 */
35
36 struct msgs_array {
37 int max, size;
38 char **msgs;
39 };
40
41 /*
42 * Same as msgs_array, but for a vector of ints
43 */
44
45 struct msgnum_array {
46 int max, size;
47 int *msgnums;
48 };
49
50 /*
51 * Add a argument to the given msgs_array or msgnum_array structure; extend
52 * the array size if necessary
53 */
54
55 void app_msgarg(struct msgs_array *, char *);
56 void app_msgnum(struct msgnum_array *, int);
57
58 int open_form(char **, char *);
59 char *find_str (const char [], size_t, const char *);
60 char *rfind_str (const char [], size_t, const char *);
61 char *nmh_strcasestr (const char *, const char *);
62
63 /*
64 * See if a string contains 8 bit characters (use isascii() for the test).
65 * Arguments include:
66 *
67 * start - Pointer to start of string to test.
68 * end - End of string to test (test will stop before reaching
69 * this point). If NULL, continue until reaching '\0'.
70 *
71 * This function always stops at '\0' regardless of the value of 'end'.
72 * Returns 1 if the string contains an 8-bit character, 0 if it does not.
73 */
74 int contains8bit(const char *start, const char *end);
75
76 /*
77 * See if file has any 8-bit bytes.
78 * Arguments include:
79 *
80 * fd - file descriptor
81 * eightbit - address of result, will be set to 1 if the file contains
82 * any 8-bit bytes, 0 otherwise.
83 *
84 * Returns OK on success, NOTOK on read failure.
85 *
86 */
87 int scan_input (int fd, int *eightbit);
88
89
90 /*
91 * Compares prior version of nmh with current version. Returns 1
92 * if they compare the be the same, 0 if not.
93 *
94 * older - 0 for difference comparison, 1 for only if older
95 */
96 int nmh_version_changed (int older);