Nico Golde:
[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 # define TRUE 1
33 # define FALSE 0
34
35 # define HUGE_STRING    5120
36 # define LONG_STRING     1024
37 # define STRING          256
38 # define SHORT_STRING    128
39
40 /*
41  * Create a format string to be used with scanf.
42  * To use it, write, for instance, MUTT_FORMAT(HUGE_STRING).
43  * 
44  * See K&R 2nd ed, p. 231 for an explanation.
45  */
46 # define _MUTT_FORMAT_2(a,b)    "%" a  b
47 # define _MUTT_FORMAT_1(a, b)   _MUTT_FORMAT_2(#a, b)
48 # define MUTT_FORMAT(a)         _MUTT_FORMAT_1(a, "s")
49 # define MUTT_FORMAT2(a,b)      _MUTT_FORMAT_1(a, b)
50
51 # define ISSPACE(c) isspace((unsigned char)c)
52 # define strfcpy(A,B,C) strncpy(A,B,C), *(A+(C)-1)=0
53
54 # undef MAX
55 # undef MIN
56 # define MAX(a,b) ((a) < (b) ? (b) : (a))
57 # define MIN(a,b) ((a) < (b) ? (a) : (b))
58
59 #define FOREVER while (1)
60
61 /* this macro must check for *c == 0 since isspace(0) has unreliable behavior
62    on some systems */
63 # define SKIPWS(c) while (*(c) && isspace ((unsigned char) *(c))) c++;
64
65 #define ISBLANK(c) (c == ' ' || c == '\t')
66 /*
67  * These functions aren't defined in lib.c, but
68  * they are used there.
69  *
70  * A non-mutt "implementation" (ahem) can be found in extlib.c.
71  */
72
73 # ifndef _EXTLIB_C
74 extern void (*mutt_error) (const char *, ...);
75 # endif
76 void mutt_exit (int);
77
78 /* The actual library functions. */
79
80 FILE *safe_fopen (const char *, const char *);
81
82 char *mutt_concat_path (char *, const char *, const char *, size_t);
83 char *mutt_read_line (char *, size_t *, FILE *, int *);
84 char *mutt_skip_whitespace (char *);
85 char *mutt_strlower (char *);
86 char *mutt_substrcpy (char *, const char *, const char *, size_t);
87 char *mutt_substrdup (const char *, const char *);
88 char *safe_strcat (char *, size_t, const char *);
89 char *safe_strncat (char *, size_t, const char *, size_t);
90 char *safe_strdup (const char *);
91
92 const char *mutt_stristr (const char *, const char *);
93 const char *mutt_basename (const char *);
94
95 int mutt_copy_stream (FILE *, FILE *);
96 int mutt_copy_bytes (FILE *, FILE *, size_t);
97 int mutt_rx_sanitize_string (char *, size_t, const char *);
98 int mutt_strcasecmp (const char *, const char *);
99 int mutt_strcmp (const char *, const char *);
100 int mutt_strncasecmp (const char *, const char *, size_t);
101 int mutt_strncmp (const char *, const char *, size_t);
102 int mutt_strcoll (const char *, const char *);
103 int safe_open (const char *, int);
104 int safe_symlink (const char *, const char *);
105 int safe_rename (const char *, const char *);
106 int safe_fclose (FILE **);
107
108 size_t mutt_quote_filename (char *, size_t, const char *);
109 size_t mutt_strlen (const char *);
110
111 void mutt_nocurses_error (const char *, ...);
112 void mutt_remove_trailing_ws (char *);
113 void mutt_sanitize_filename (char *, short);
114 void mutt_str_replace (char **p, const char *s);
115 void mutt_str_adjust (char **p);
116 void mutt_unlink (const char *);
117
118 #endif