}
-#ifndef HAVE_ICONV
-
-iconv_t iconv_open (const char *tocode, const char *fromcode)
-{
- return (iconv_t) (-1);
-}
-
-size_t iconv (iconv_t cd, const char **inbuf, size_t * inbytesleft,
- char **outbuf, size_t * outbytesleft)
-{
- return 0;
-}
-
-int iconv_close (iconv_t cd)
-{
- return 0;
-}
-
-#endif /* !HAVE_ICONV */
-
-
/*
* Like iconv_open, but canonicalises the charsets
*/
size_t obl = *outbytesleft;
for (;;) {
- ret1 = iconv (cd, &ib, &ibl, &ob, &obl);
+ ret1 = my_iconv(cd, &ib, &ibl, &ob, &obl);
if (ret1 != (size_t) - 1)
ret += ret1;
if (ibl && obl && errno == EILSEQ) {
char *ob1 = ob;
size_t obl1 = obl;
- iconv (cd, &ib1, &ibl1, &ob1, &obl1);
+ my_iconv(cd, &ib1, &ibl1, &ob1, &obl1);
if (!ibl1) {
++ib, --ibl;
ob = ob1, obl = obl1;
/* Replace the output */
if (!outrepl)
outrepl = "?";
- iconv (cd, 0, 0, &ob, &obl);
+ my_iconv(cd, 0, 0, &ob, &obl);
if (obl) {
int n = str_len (outrepl);
++ib, --ibl;
ob += n, obl -= n;
++ret;
- iconv (cd, 0, 0, 0, 0); /* for good measure */
+ my_iconv(cd, 0, 0, 0, 0); /* for good measure */
continue;
}
}
if (fc->ibl) {
size_t obl = sizeof (fc->bufo);
- iconv (fc->cd, (const char **) &fc->ib, &fc->ibl, &fc->ob, &obl);
+ my_iconv(fc->cd, (const char **) &fc->ib, &fc->ibl, &fc->ob, &obl);
if (fc->p < fc->ob)
return (unsigned char) *(fc->p)++;
}
return (size_t) (-1);
obl = 4 * flen + 1;
ob = buf = mem_malloc (obl);
- n = iconv (cd, &f, &flen, &ob, &obl);
- if (n == (size_t) (-1) || iconv (cd, 0, 0, &ob, &obl) == (size_t) (-1)) {
+ n = my_iconv(cd, &f, &flen, &ob, &obl);
+ if (n == (size_t) (-1) || my_iconv(cd, 0, 0, &ob, &obl) == (size_t) (-1)) {
e = errno;
mem_free (&buf);
iconv_close (cd);
#endif
#ifndef HAVE_ICONV
- iconv_t iconv_open (const char *, const char *);
-size_t iconv (iconv_t, const char **, size_t *, char **, size_t *);
-int iconv_close (iconv_t);
+# define iconv_open(a, b) ((iconv_t)(-1))
+# define my_iconv(a,b,c,d,e) 0
+# define iconv_close(a) 0
+#else
+static inline size_t my_iconv(iconv_t ict, const char **inbuf, size_t *ilen,
+ char **outbuf, size_t *olen)
+{
+ return iconv(ict, (char **)inbuf, ilen, outbuf, olen);
+}
#endif
int mutt_convert_string (char **, const char *, const char *, int);
buf = mem_malloc (n + 1);
ib = uid, ibl = d - uid + 1, ob = buf, obl = n;
- iconv (cd, &ib, &ibl, &ob, &obl);
+ my_iconv(cd, &ib, &ibl, &ob, &obl);
if (!ibl) {
if (ob - buf < n) {
memcpy (uid, buf, ob - buf);
}
}
-static void enriched_puts (char *s, struct enriched_state *stte)
+static void enriched_puts (const char *s, struct enriched_state *stte)
{
char *c;
* data data to associate with `key'
* allow_dup if nonzero, duplicate keys are allowed in the table
*/
-int hash_insert (HASH * table, const char *key, void *data, int allow_dup)
+int hash_insert (HASH * table, const char *key, const void *data, int allow_dup)
{
struct hash_elem *ptr;
int h;
HASH *hash_create (int nelem);
int hash_string (const unsigned char *s, int n);
-int hash_insert (HASH * table, const char *key, void *data, int allow_dup);
+int hash_insert (HASH * table, const char *key, const void *data, int allow_dup);
HASH *hash_resize (HASH * table, int nelem);
void *hash_find_hash (const HASH * table, int hash, const char *key);
void hash_delete_hash (HASH * table, int hash, const char *key,
static void sys_to_string (char* dst, size_t dstlen,
struct option_t* option) {
- char* val = NULL, *t = NULL;
+ char *val = NULL, *t = NULL;
int clean = 0;
/* get some $muttng_ values dynamically */
try == user entered data for completion.
len == length of dest buffer.
*/
-static void candidate (char *dest, char *try, char *src, int len)
+static void candidate (char *dest, char *try, const char *src, int len)
{
int l;
|| !str_ncmp (buffer, "unset", 5)
|| !str_ncmp (buffer, "reset", 5)
|| !str_ncmp (buffer, "toggle", 6)) { /* complete variables */
- char *prefixes[] = { "no", "inv", "?", "&", 0 };
+ const char *prefixes[] = { "no", "inv", "?", "&", NULL };
pt++;
/* loop through all the possible prefixes (no, inv, ...) */
char tmp[LONG_STRING], tmp2[LONG_STRING];
char *s, *d;
size_t dlen = buffer + len - pt - spaces;
- char *vals[] = { "no", "yes", "ask-no", "ask-yes" };
+ const char *vals[] = { "no", "yes", "ask-no", "ask-yes" };
tmp[0] = '\0';
"", p);
}
else if (DTYPE (option->type) == DT_MAGIC) {
- char *p;
+ const char *p;
switch (DefaultMagic) {
case M_MBOX:
p = "mbox";
return 0;
}
-char *mutt_getnamebyvalue (int val, const struct mapping_t *map)
+const char *mutt_getnamebyvalue (int val, const struct mapping_t *map)
{
int i;
{
struct passwd *pw;
struct utsname utsname;
- char *p, buffer[STRING], error[STRING];
+ const char *p;
+ char buffer[STRING], error[STRING];
int i, default_rc = 0, need_pause = 0;
BUFFER err;
#ifdef USE_NNTP
{
FILE *f;
- char *i;
+ char *q;
if ((f = safe_fopen (SYSCONFDIR "/nntpserver", "r"))) {
buffer[0] = '\0';
fgets (buffer, sizeof (buffer), f);
- p = (char*) &buffer;
+ p = (char*)&buffer;
SKIPWS (p);
- i = p;
- while (*i && (*i != ' ') && (*i != '\t') && (*i != '\r')
- && (*i != '\n'))
- i++;
- *i = '\0';
+ q = p;
+ while (*q && !isspace(*q))
+ q++;
+ *q = '\0';
NewsServer = str_dup (p);
fclose (f);
}
*/
#endif
/*--*/
- { NULL }
+ { NULL, -1, R_NONE, -1, NULL }
};
static const char* Features[] = {
{"date", SORT_DATE},
{"size", SORT_SIZE},
{"unsorted", SORT_ORDER},
- {NULL}
+ {NULL, 0}
};
const struct mapping_t SortAliasMethods[] = {
{"alias", SORT_ALIAS},
{"address", SORT_ADDRESS},
{"unsorted", SORT_ORDER},
- {NULL}
+ {NULL, 0}
};
const struct mapping_t SortKeyMethods[] = {
{"date", SORT_DATE},
{"keyid", SORT_KEYID},
{"trust", SORT_TRUST},
- {NULL}
+ {NULL, 0}
};
{"unscore", mutt_parse_unscore, 0},
{"unset", parse_set, M_SET_UNSET},
{"unsubscribe", parse_unsubscribe, 0},
- {NULL}
+ {NULL, NULL, 0}
};
/* insert a key sequence into the specified map. the map is sorted by ASCII
* value (lowest to highest)
*/
-void km_bind (char *s, int menu, int op, char *macro, char *descr)
+void km_bind (const char *s, int menu, int op, char *macro, char *descr)
{
struct keymap_t *map, *tmp, *last = NULL, *next;
keycode_t buf[MAX_SEQ];
Keymaps[menu] = map;
}
-void km_bindkey (char *s, int menu, int op)
+void km_bindkey (const char *s, int menu, int op)
{
km_bind (s, menu, op, NULL, NULL);
}
/* type for key storage, the rest of mutt works fine with int type */
typedef short keycode_t;
-void km_bind (char *, int, int, char *, char *);
-void km_bindkey (char *, int, int);
+void km_bind (const char *, int, int, char *, char *);
+void km_bindkey (const char *, int, int);
int km_dokey (int);
/* entry in the keymap tree */
extern struct mapping_t Menus[];
struct binding_t {
- char *name; /* name of the function */
- int op; /* function id number */
- char *seq; /* default key binding */
+ const char *name; /* name of the function */
+ int op; /* function id number */
+ const char *seq; /* default key binding */
};
struct binding_t *km_get_table (int menu);
int value;
};
-char *mutt_getnamebyvalue (int, const struct mapping_t *);
+const char *mutt_getnamebyvalue (int, const struct mapping_t *);
char *mutt_compile_help (char *, size_t, int, struct mapping_t *);
int mutt_getvaluebyname (const char *, const struct mapping_t *);
ib = buf;
ob = s;
obl = MB_LEN_MAX;
- r = iconv (cd, &ib, &ibl, &ob, &obl);
+ r = my_iconv(cd, &ib, &ibl, &ob, &obl);
}
else {
ib = "";
ibl = 1;
ob = buf;
obl = sizeof (buf);
- r = iconv (cd, &ib, &ibl, &ob, &obl);
+ r = my_iconv(cd, &ib, &ibl, &ob, &obl);
}
return ob - s;
}
ibl = 1;
for (;;) {
- r = iconv (cd, &ib, &ibl, &ob, &obl);
+ r = my_iconv(cd, &ib, &ibl, &ob, &obl);
if (ob > bufo && (!k || ib > bufi + k)) {
/* we have a character */
memset (ps, 0, sizeof (*ps));
}
#endif /* USE_INODESORT */
-#if USE_HCACHE
+#ifdef USE_HCACHE
static size_t maildir_hcache_keylen (const char *fn)
{
const char *p = strchr (fn, ':');
char fn[_POSIX_PATH_MAX];
int count;
-#if USE_HCACHE
+#ifdef USE_HCACHE
void *hc = NULL;
void *data;
struct timeval *when = NULL;
if (!(p && p->h && !p->header_parsed))
continue;
-#if USE_HCACHE
+#ifdef USE_HCACHE
data = mutt_hcache_fetch (hc, p->h->path + 3, &maildir_hcache_keylen);
when = (struct timeval *) data;
#endif
mutt_message (_("Reading %s... %d"), ctx->path, count);
snprintf (fn, sizeof (fn), "%s/%s", ctx->path, p->h->path);
-#if USE_HCACHE
+#ifdef USE_HCACHE
if (option (OPTHCACHEVERIFY)) {
ret = stat (fn, &lastchanged);
}
if (maildir_parse_message (ctx->magic, fn, p->h->old, p->h)) {
p->header_parsed = 1;
maildir_parse_flags (p->h, fn);
-#if USE_HCACHE
+#ifdef USE_HCACHE
mutt_hcache_store (hc, p->h->path + 3, p->h, 0, &maildir_hcache_keylen);
#endif
}
else
mutt_free_header (&p->h);
-#if USE_HCACHE
+#ifdef USE_HCACHE
mem_free (&data);
#endif
}
-#if USE_HCACHE
+#ifdef USE_HCACHE
mutt_hcache_close (hc);
#endif
}
char path[_POSIX_PATH_MAX], tmp[_POSIX_PATH_MAX];
int i, j;
-#if USE_HCACHE
+#ifdef USE_HCACHE
void *hc = NULL;
#endif /* USE_HCACHE */
if (i != 0)
return i;
-#if USE_HCACHE
+#ifdef USE_HCACHE
if (ctx->magic == M_MAILDIR)
hc = mutt_hcache_open (HeaderCache, ctx->path);
#endif /* USE_HCACHE */
snprintf (path, sizeof (path), "%s/%s", ctx->path, ctx->hdrs[i]->path);
if (ctx->magic == M_MAILDIR
|| (option (OPTMHPURGE) && ctx->magic == M_MH)) {
-#if USE_HCACHE
+#ifdef USE_HCACHE
if (ctx->magic == M_MAILDIR)
mutt_hcache_delete (hc, ctx->hdrs[i]->path + 3,
&maildir_hcache_keylen);
}
}
-#if USE_HCACHE
+#ifdef USE_HCACHE
if (ctx->magic == M_MAILDIR)
mutt_hcache_close (hc);
#endif /* USE_HCACHE */
return 0;
err:
-#if USE_HCACHE
+#ifdef USE_HCACHE
if (ctx->magic == M_MAILDIR)
mutt_hcache_close (hc);
#endif /* USE_HCACHE */
typedef struct {
char *major;
int major_int;
- char *minor;
+ const char *minor;
regex_t minor_rx;
} ATTACH_MATCH;
return 0;
}
-/* prepend the path part of *path to *link */
-void mutt_expand_link (char *newpath, const char *path, const char *link)
+/* prepend the path part of *path to *lnk */
+void mutt_expand_link (char *newpath, const char *path, const char *lnk)
{
const char *lb = NULL;
size_t len;
- /* link is full path */
- if (*link == '/') {
- strfcpy (newpath, link, _POSIX_PATH_MAX);
+ /* lnk is full path */
+ if (*lnk == '/') {
+ strfcpy (newpath, lnk, _POSIX_PATH_MAX);
return;
}
if ((lb = strrchr (path, '/')) == NULL) {
- /* no path in link */
- strfcpy (newpath, link, _POSIX_PATH_MAX);
+ /* no path in lnk */
+ strfcpy (newpath, lnk, _POSIX_PATH_MAX);
return;
}
len = lb - path + 1;
memcpy (newpath, path, len);
- strfcpy (newpath + len, link, _POSIX_PATH_MAX - len);
+ strfcpy (newpath + len, lnk, _POSIX_PATH_MAX - len);
}
char *mutt_expand_path (char *s, size_t slen)
char tmp[_POSIX_PATH_MAX];
char *t;
- char *tail = "";
+ const char *tail = "";
int recurse = 0;
break; /* skip rest of input */
}
else {
- short tolower = 0;
+ short lower = 0;
short nodots = 0;
while (ch == '_' || ch == ':') {
if (ch == '_')
- tolower = 1;
+ lower = 1;
else if (ch == ':')
nodots = 1;
callback (buf, sizeof (buf), ch, src, prefix, ifstring, elsestring,
data, flags);
- if (tolower)
+ if (lower)
str_tolower (buf);
if (nodots) {
char *p = buf;
then we assume it is a commmand to run instead of a normal file. */
FILE *mutt_open_read (const char *path, pid_t * thepid)
{
- FILE *f;
- struct stat s;
-
- int len = str_len (path);
-
- if (path[len - 1] == '|') {
- /* read from a pipe */
-
- char *s = str_dup (path);
-
- s[len - 1] = 0;
- mutt_endwin (NULL);
- *thepid = mutt_create_filter (s, NULL, &f, NULL);
- mem_free (&s);
- }
- else {
- if (stat (path, &s) < 0)
- return (NULL);
- if (S_ISDIR (s.st_mode)) {
- errno = EINVAL;
- return (NULL);
+ int len = str_len (path);
+ FILE *f;
+
+ if (path[len - 1] == '|') {
+ char *s = str_dup (path);
+
+ /* read from a pipe */
+
+ s[len - 1] = 0;
+ mutt_endwin (NULL);
+ *thepid = mutt_create_filter (s, NULL, &f, NULL);
+ mem_free (&s);
+ } else {
+ struct stat st;
+
+ if (stat (path, &st) < 0)
+ return (NULL);
+ if (S_ISDIR (st.st_mode)) {
+ errno = EINVAL;
+ return (NULL);
+ }
+ f = fopen (path, "r");
+ *thepid = -1;
}
- f = fopen (path, "r");
- *thepid = -1;
- }
- return (f);
+
+ return (f);
}
/* returns 0 if OK to proceed, -1 to abort, 1 to retry */
#define memmove(d,s,n) bcopy((s),(d),(n))
#endif
+#ifdef _AIX
/* AIX doesn't define these in any headers (sigh) */
int strcasecmp (const char *, const char *);
int strncasecmp (const char *, const char *, size_t);
-#ifdef _AIX
int setegid (gid_t);
#endif /* _AIX */
return (size_t) (-1);
obl = 4 * flen + 1;
ob = buf = mem_malloc (obl);
- n = iconv (cd, &f, &flen, &ob, &obl);
- if (n == (size_t) (-1) || iconv (cd, 0, 0, &ob, &obl) == (size_t) (-1)) {
+ n = my_iconv(cd, &f, &flen, &ob, &obl);
+ if (n == (size_t) (-1) || my_iconv(cd, 0, 0, &ob, &obl) == (size_t) (-1)) {
e = errno;
mem_free (&buf);
iconv_close (cd);
cd = mutt_iconv_open (tocode, fromcode, 0);
assert (cd != (iconv_t) (-1));
ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - str_len (tocode);
- if (iconv (cd, &ib, &ibl, &ob, &obl) == (size_t) (-1) ||
- iconv (cd, 0, 0, &ob, &obl) == (size_t) (-1)) {
+ if (my_iconv(cd, &ib, &ibl, &ob, &obl) == (size_t) (-1) ||
+ my_iconv(cd, 0, 0, &ob, &obl) == (size_t) (-1)) {
assert (errno == E2BIG);
iconv_close (cd);
assert (ib > d);
cd = mutt_iconv_open (tocode, fromcode, 0);
assert (cd != (iconv_t) (-1));
ib = d, ibl = dlen, ob = buf1, obl = sizeof (buf1) - str_len (tocode);
- n1 = iconv (cd, &ib, &ibl, &ob, &obl);
- n2 = iconv (cd, 0, 0, &ob, &obl);
+ n1 = my_iconv(cd, &ib, &ibl, &ob, &obl);
+ n2 = my_iconv(cd, 0, 0, &ob, &obl);
assert (n1 != (size_t) (-1) && n2 != (size_t) (-1));
iconv_close (cd);
return (*encoder) (s, buf1, ob - buf1, tocode);
/* Convert to UTF-8 */
ib = bufi;
ob = bufu, obl = sizeof (bufu);
- n = iconv (cd1, ibl ? &ib : 0, &ibl, &ob, &obl);
+ n = my_iconv(cd1, ibl ? &ib : 0, &ibl, &ob, &obl);
assert (n == (size_t) (-1) || !n || ICONV_NONTRANS);
if (n == (size_t) (-1) &&
((errno != EINVAL && errno != E2BIG) || ib == bufi)) {
if (cd[i] != (iconv_t) (-1) && score[i] != (size_t) (-1)) {
ub = bufu, ubl = ubl1;
ob = bufo, obl = sizeof (bufo);
- n = iconv (cd[i], (ibl || ubl) ? &ub : 0, &ubl, &ob, &obl);
+ n = my_iconv(cd[i], (ibl || ubl) ? &ub : 0, &ubl, &ob, &obl);
if (n == (size_t) (-1)) {
assert (errno == E2BIG ||
(BUGGY_ICONV && (errno == EILSEQ || errno == ENOENT)));
if (!bufi) {
if (cd != (iconv_t) (-1)) {
ob = bufo, obl = sizeof (bufo);
- iconv (cd, 0, 0, &ob, &obl);
+ my_iconv(cd, 0, 0, &ob, &obl);
if (ob != bufo)
state_prefix_put (bufo, ob - bufo, s);
}