Rocco Rutte:
[apps/madmutt.git] / lib.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
11 /* mutt functions which are generally useful. */
12
13 #ifndef _LIB_H
14 # define _LIB_H
15
16 # include <stdio.h>
17 # include <string.h>
18 # ifdef HAVE_UNISTD_H
19 #  include <unistd.h>           /* needed for SEEK_SET */
20 # endif
21 # include <sys/types.h>
22 # include <sys/stat.h>
23 # include <time.h>
24 # include <limits.h>
25 # include <stdarg.h>
26 # include <signal.h>
27
28 # ifndef _POSIX_PATH_MAX
29 #  include <posix1_lim.h>
30 # endif
31
32 # ifdef ENABLE_NLS
33 #  include <libintl.h>
34 # define _(a) (gettext (a))
35 #  ifdef gettext_noop
36 #   define N_(a) gettext_noop (a)
37 #  else
38 #   define N_(a) (a)
39 #  endif
40 # else
41 #  define _(a) (a)
42 #  define N_(a) a
43 # endif
44
45 # define TRUE 1
46 # define FALSE 0
47
48 # define HUGE_STRING    5120
49 # define LONG_STRING     1024
50 # define STRING          256
51 # define SHORT_STRING    128
52
53 /*
54  * Create a format string to be used with scanf.
55  * To use it, write, for instance, MUTT_FORMAT(HUGE_STRING).
56  * 
57  * See K&R 2nd ed, p. 231 for an explanation.
58  */
59 # define _MUTT_FORMAT_2(a,b)    "%" a  b
60 # define _MUTT_FORMAT_1(a, b)   _MUTT_FORMAT_2(#a, b)
61 # define MUTT_FORMAT(a)         _MUTT_FORMAT_1(a, "s")
62 # define MUTT_FORMAT2(a,b)      _MUTT_FORMAT_1(a, b)
63
64
65 # define FREE(x) safe_free(x)
66 # define NONULL(x) x?x:""
67 # define ISSPACE(c) isspace((unsigned char)c)
68 # define strfcpy(A,B,C) strncpy(A,B,C), *(A+(C)-1)=0
69
70 # undef MAX
71 # undef MIN
72 # define MAX(a,b) ((a) < (b) ? (b) : (a))
73 # define MIN(a,b) ((a) < (b) ? (a) : (b))
74
75
76 #define FOREVER while (1)
77
78 /* this macro must check for *c == 0 since isspace(0) has unreliable behavior
79    on some systems */
80 # define SKIPWS(c) while (*(c) && isspace ((unsigned char) *(c))) c++;
81
82 #define ISBLANK(c) (c == ' ' || c == '\t')
83 /*
84  * These functions aren't defined in lib.c, but
85  * they are used there.
86  *
87  * A non-mutt "implementation" (ahem) can be found in extlib.c.
88  */
89
90 # ifndef _EXTLIB_C
91 extern void (*mutt_error) (const char *, ...);
92 # endif
93 void mutt_exit (int);
94
95 /* The actual library functions. */
96
97 FILE *safe_fopen (const char *, const char *);
98
99 char *mutt_concat_path (char *, const char *, const char *, size_t);
100 char *mutt_read_line (char *, size_t *, FILE *, int *);
101 char *mutt_skip_whitespace (char *);
102 char *mutt_strlower (char *);
103 char *mutt_substrcpy (char *, const char *, const char *, size_t);
104 char *mutt_substrdup (const char *, const char *);
105 char *safe_strcat (char *, size_t, const char *);
106 char *safe_strncat (char *, size_t, const char *, size_t);
107 char *safe_strdup (const char *);
108
109 const char *mutt_stristr (const char *, const char *);
110 const char *mutt_basename (const char *);
111
112 int mutt_copy_stream (FILE *, FILE *);
113 int mutt_copy_bytes (FILE *, FILE *, size_t);
114 int mutt_rx_sanitize_string (char *, size_t, const char *);
115 int mutt_strcasecmp (const char *, const char *);
116 int mutt_strcmp (const char *, const char *);
117 int mutt_strncasecmp (const char *, const char *, size_t);
118 int mutt_strncmp (const char *, const char *, size_t);
119 int mutt_strcoll (const char *, const char *);
120 int safe_open (const char *, int);
121 int safe_symlink (const char *, const char *);
122 int safe_rename (const char *, const char *);
123 int safe_fclose (FILE **);
124
125 size_t mutt_quote_filename (char *, size_t, const char *);
126 size_t mutt_strlen (const char *);
127
128 void *safe_calloc (size_t, size_t);
129 void *safe_malloc (size_t);
130 void mutt_nocurses_error (const char *, ...);
131 void mutt_remove_trailing_ws (char *);
132 void mutt_sanitize_filename (char *, short);
133 void mutt_str_replace (char **p, const char *s);
134 void mutt_str_adjust (char **p);
135 void mutt_unlink (const char *);
136 void safe_free (void *);
137 void safe_realloc (void *, size_t);
138
139 #endif