249ca2047cbd9b75e021f1a6943e8bb768a25354
[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 NONULL(x) x?x:""
16
17 # define HUGE_STRING     5120
18 # define LONG_STRING     1024
19 # define STRING          256
20 # define SHORT_STRING    128
21
22 /*
23  * Create a format string to be used with scanf.
24  * To use it, write, for instance, MUTT_FORMAT(HUGE_STRING).
25  * 
26  * See K&R 2nd ed, p. 231 for an explanation.
27  */
28 # define _MUTT_FORMAT_2(a,b)    "%" a  b
29 # define _MUTT_FORMAT_1(a, b)   _MUTT_FORMAT_2(#a, b)
30 # define MUTT_FORMAT(a)         _MUTT_FORMAT_1(a, "s")
31 # define MUTT_FORMAT2(a,b)      _MUTT_FORMAT_1(a, b)
32
33 # define ISSPACE(c) isspace((unsigned char)c)
34 # define ISBLANK(c) (c == ' ' || c == '\t')
35 # define strfcpy(A,B,C) strncpy(A,B,C), *(A+(C)-1)=0
36 /* this macro must check for *c == 0 since isspace(0) has
37  * unreliable behavior on some systems */
38 # define SKIPWS(c) while (*(c) && isspace ((unsigned char) *(c))) c++;
39
40 /*
41  * safety wrappers/replacements
42  * (mostly only difference: safely handle NULL strings)
43  */
44 char *str_cat (char*, size_t, const char*);
45 char *str_ncat (char*, size_t, const char*, size_t);
46 int str_cmp (const char*, const char*);
47 int str_casecmp (const char*, const char*);
48 int str_ncmp (const char*, const char*, size_t);
49 int str_ncasecmp (const char*, const char*, size_t);
50 int str_coll (const char*, const char*);
51
52 /*
53  * tools
54  */
55 char *str_tolower (char*);
56 char *str_substrcpy (char*, const char*, const char*, size_t);
57 char *str_substrdup (const char*, const char*);
58 void str_replace (char**, const char*);
59 void str_adjust (char**);
60 int str_eq (const char*, const char*);
61 const char *str_isstr (const char*, const char*);
62 char* str_skip_initws (char*);
63 void str_skip_trailws (char*);
64
65 #endif /* !_LIB_STR_H */