less horrible strncpy's
[apps/madmutt.git] / lib / str.h
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4  * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
5  *
6  * This file is part of mutt-ng, see http://www.muttng.org/.
7  * It's licensed under the GNU General Public License,
8  * please see the file GPL in the top level source directory.
9  */
10 #ifndef _LIB_STR_H
11 #define _LIB_STR_H
12
13 #include <sys/types.h>
14
15 # define HUGE_STRING     5120
16 # define LONG_STRING     1024
17 # define STRING          256
18 # define SHORT_STRING    128
19
20 /*
21  * Create a format string to be used with scanf.
22  * To use it, write, for instance, MUTT_FORMAT(HUGE_STRING).
23  * 
24  * See K&R 2nd ed, p. 231 for an explanation.
25  */
26 # define _MUTT_FORMAT_2(a,b)    "%" a  b
27 # define _MUTT_FORMAT_1(a, b)   _MUTT_FORMAT_2(#a, b)
28 # define MUTT_FORMAT(a)         _MUTT_FORMAT_1(a, "s")
29 # define MUTT_FORMAT2(a,b)      _MUTT_FORMAT_1(a, b)
30
31 # define ISSPACE(c) isspace((unsigned char)c)
32 # define ISBLANK(c) (c == ' ' || c == '\t')
33 # define strfcpy(A,B,C)  m_strcpy(A,C,B)
34 /* this macro must check for *c == 0 since isspace(0) has
35  * unreliable behavior on some systems */
36 # define SKIPWS(c) while (*(c) && isspace ((unsigned char) *(c))) c++;
37
38 /*
39  * safety wrappers/replacements
40  * (mostly only difference: safely handle NULL strings)
41  */
42 char *str_cat (char*, size_t, const char*);
43 char *str_ncat (char*, size_t, const char*, size_t);
44 int str_casecmp (const char*, const char*);
45 int str_ncmp (const char*, const char*, size_t);
46 int str_ncasecmp (const char*, const char*, size_t);
47 int str_coll (const char*, const char*);
48
49 /*
50  * tools
51  */
52 char *str_tolower (char*);
53 char *str_substrcpy (char*, const char*, const char*, size_t);
54 char *str_substrdup (const char*, const char*);
55 void str_replace (char**, const char*);
56 void str_adjust (char**);
57 int str_eq (const char*, const char*);
58 const char *str_isstr (const char*, const char*);
59 char* str_skip_initws (char*);
60 void str_skip_trailws (char*);
61
62 #endif /* !_LIB_STR_H */