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