X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib%2Fstr.h;h=b2457d41d5c243759bcd6097340775b06fb06d63;hp=b9adfec89fcc2a47952acb51d3268be6d70da763;hb=2ea77d3b2827ba23feb756ce2fb936565ae38998;hpb=203e950e3d3c76795fa49895d040f732adad2049 diff --git a/lib/str.h b/lib/str.h index b9adfec..b2457d4 100644 --- a/lib/str.h +++ b/lib/str.h @@ -7,12 +7,56 @@ * It's licensed under the GNU General Public License, * please see the file GPL in the top level source directory. */ - -/* mutt functions which are generally useful. */ - #ifndef _LIB_STR_H #define _LIB_STR_H -#define NONULL(x) x?x:"" +#include + +# define HUGE_STRING 5120 +# define LONG_STRING 1024 +# define STRING 256 +# define SHORT_STRING 128 + +/* + * Create a format string to be used with scanf. + * To use it, write, for instance, MUTT_FORMAT(HUGE_STRING). + * + * See K&R 2nd ed, p. 231 for an explanation. + */ +# define _MUTT_FORMAT_2(a,b) "%" a b +# define _MUTT_FORMAT_1(a, b) _MUTT_FORMAT_2(#a, b) +# define MUTT_FORMAT(a) _MUTT_FORMAT_1(a, "s") +# define MUTT_FORMAT2(a,b) _MUTT_FORMAT_1(a, b) + +# define ISSPACE(c) isspace((unsigned char)c) +# define ISBLANK(c) (c == ' ' || c == '\t') +# define strfcpy(A,B,C) strncpy(A,B,C), *(A+(C)-1)=0 +/* this macro must check for *c == 0 since isspace(0) has + * unreliable behavior on some systems */ +# define SKIPWS(c) while (*(c) && isspace ((unsigned char) *(c))) c++; + +/* + * safety wrappers/replacements + * (mostly only difference: safely handle NULL strings) + */ +char *str_cat (char*, size_t, const char*); +char *str_ncat (char*, size_t, const char*, size_t); +int str_casecmp (const char*, const char*); +int str_ncmp (const char*, const char*, size_t); +int str_ncasecmp (const char*, const char*, size_t); +int str_coll (const char*, const char*); + +/* + * tools + */ +char *str_tolower (char*); +char *str_substrcpy (char*, const char*, const char*, size_t); +char *str_substrdup (const char*, const char*); +void str_replace (char**, const char*); +void str_adjust (char**); +int str_eq (const char*, const char*); +const char *str_isstr (const char*, const char*); +char* str_skip_initws (char*); +void str_skip_trailws (char*); #endif /* !_LIB_STR_H */