From: Richard Russon Date: Fri, 24 Nov 2017 01:59:47 +0000 (+0000) Subject: move exit syslist to libmutt X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a69a0b59403d5021b6239e9e53f30234ff5b875c;p=neomutt move exit syslist to libmutt --- diff --git a/conn/tunnel.c b/conn/tunnel.c index 9d58de331..c99a210cc 100644 --- a/conn/tunnel.c +++ b/conn/tunnel.c @@ -166,7 +166,7 @@ static int tunnel_socket_close(struct Connection *conn) if (!WIFEXITED(status) || WEXITSTATUS(status)) { mutt_error(_("Tunnel to %s returned error %d (%s)"), conn->account.host, - WEXITSTATUS(status), NONULL(mutt_strsysexit(WEXITSTATUS(status)))); + WEXITSTATUS(status), NONULL(mutt_str_sysexit(WEXITSTATUS(status)))); mutt_sleep(2); } FREE(&conn->sockdata); diff --git a/mutt.h b/mutt.h index 97b3db31b..caf56eaed 100644 --- a/mutt.h +++ b/mutt.h @@ -337,15 +337,11 @@ struct AttachMatch #define FMT_CENTER 0 #define FMT_RIGHT 1 -/* Exit values used in send_msg() */ -#define S_ERR 127 -#define S_BKG 126 - int safe_asprintf(char **, const char *, ...); int mutt_inbox_cmp(const char *a, const char *b); -const char *mutt_strsysexit(int e); +const char *mutt_str_sysexit(int e); char *mutt_compile_help(char *buf, size_t buflen, int menu, const struct Mapping *items); diff --git a/mutt/string.c b/mutt/string.c index 17c0f230c..fe3762ab2 100644 --- a/mutt/string.c +++ b/mutt/string.c @@ -60,6 +60,7 @@ * | mutt_str_strnfcpy() | Copy a limited string into a buffer (guaranteeing NUL-termination) * | mutt_str_substr_cpy() | Copy a sub-string into a buffer * | mutt_str_substr_dup() | Duplicate a sub-string + * | mutt_str_sysexit() | Return a string matching an error code * | mutt_str_word_casecmp() | Find word a in word list b */ @@ -72,6 +73,83 @@ #include "debug.h" #include "memory.h" #include "string2.h" +#ifdef HAVE_SYSEXITS_H +#include +#endif + +/** + * struct SysExits - Lookup table of error messages + */ +static const struct SysExits +{ + int v; + const char *str; +} sysexits_h[] = { +#ifdef EX_USAGE + { 0xff & EX_USAGE, "Bad usage." }, +#endif +#ifdef EX_DATAERR + { 0xff & EX_DATAERR, "Data format error." }, +#endif +#ifdef EX_NOINPUT + { 0xff & EX_NOINPUT, "Cannot open input." }, +#endif +#ifdef EX_NOUSER + { 0xff & EX_NOUSER, "User unknown." }, +#endif +#ifdef EX_NOHOST + { 0xff & EX_NOHOST, "Host unknown." }, +#endif +#ifdef EX_UNAVAILABLE + { 0xff & EX_UNAVAILABLE, "Service unavailable." }, +#endif +#ifdef EX_SOFTWARE + { 0xff & EX_SOFTWARE, "Internal error." }, +#endif +#ifdef EX_OSERR + { 0xff & EX_OSERR, "Operating system error." }, +#endif +#ifdef EX_OSFILE + { 0xff & EX_OSFILE, "System file missing." }, +#endif +#ifdef EX_CANTCREAT + { 0xff & EX_CANTCREAT, "Can't create output." }, +#endif +#ifdef EX_IOERR + { 0xff & EX_IOERR, "I/O error." }, +#endif +#ifdef EX_TEMPFAIL + { 0xff & EX_TEMPFAIL, "Deferred." }, +#endif +#ifdef EX_PROTOCOL + { 0xff & EX_PROTOCOL, "Remote protocol error." }, +#endif +#ifdef EX_NOPERM + { 0xff & EX_NOPERM, "Insufficient permission." }, +#endif +#ifdef EX_CONFIG + { 0xff & EX_NOPERM, "Local configuration error." }, +#endif + { S_ERR, "Exec error." }, + { -1, NULL }, +}; + +/** + * mutt_str_sysexit - Return a string matching an error code + * @param e Error code, e.g. EX_NOPERM + */ +const char *mutt_str_sysexit(int e) +{ + int i; + + for (i = 0; sysexits_h[i].str; i++) + { + if (e == sysexits_h[i].v) + break; + } + + return sysexits_h[i].str; +} /** * mutt_str_atol - Convert ASCII string to a long diff --git a/mutt/string2.h b/mutt/string2.h index 84a7714ae..17890d92d 100644 --- a/mutt/string2.h +++ b/mutt/string2.h @@ -40,6 +40,10 @@ #define ISSPACE(c) isspace((unsigned char) c) #define EMAIL_WSP " \t\r\n" +/* Exit values */ +#define S_ERR 127 +#define S_BKG 126 + /* this macro must check for (*c == 0) since isspace(0) has unreliable behavior on some systems */ #define SKIPWS(c) \ @@ -90,6 +94,7 @@ int mutt_str_strncmp(const char *a, const char *b, size_t l); char * mutt_str_strnfcpy(char *dest, char *src, size_t size, size_t dlen); char * mutt_str_substr_cpy(char *dest, const char *begin, const char *end, size_t destlen); char * mutt_str_substr_dup(const char *begin, const char *end); +const char *mutt_str_sysexit(int e); int mutt_str_word_casecmp(const char *a, const char *b); #endif /* _MUTT_STRING_H */ diff --git a/muttlib.c b/muttlib.c index 14c3d4945..6c49bec75 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1783,82 +1783,6 @@ void mutt_get_parent_path(char *output, char *path, size_t olen) } } -#ifdef HAVE_SYSEXITS_H -#include -#else /* Make sure EX_OK is defined */ -#define EX_OK 0 -#endif - -/** - * struct SysExits - Lookup table of error messages - */ -static const struct SysExits -{ - int v; - const char *str; -} sysexits_h[] = { -#ifdef EX_USAGE - { 0xff & EX_USAGE, "Bad usage." }, -#endif -#ifdef EX_DATAERR - { 0xff & EX_DATAERR, "Data format error." }, -#endif -#ifdef EX_NOINPUT - { 0xff & EX_NOINPUT, "Cannot open input." }, -#endif -#ifdef EX_NOUSER - { 0xff & EX_NOUSER, "User unknown." }, -#endif -#ifdef EX_NOHOST - { 0xff & EX_NOHOST, "Host unknown." }, -#endif -#ifdef EX_UNAVAILABLE - { 0xff & EX_UNAVAILABLE, "Service unavailable." }, -#endif -#ifdef EX_SOFTWARE - { 0xff & EX_SOFTWARE, "Internal error." }, -#endif -#ifdef EX_OSERR - { 0xff & EX_OSERR, "Operating system error." }, -#endif -#ifdef EX_OSFILE - { 0xff & EX_OSFILE, "System file missing." }, -#endif -#ifdef EX_CANTCREAT - { 0xff & EX_CANTCREAT, "Can't create output." }, -#endif -#ifdef EX_IOERR - { 0xff & EX_IOERR, "I/O error." }, -#endif -#ifdef EX_TEMPFAIL - { 0xff & EX_TEMPFAIL, "Deferred." }, -#endif -#ifdef EX_PROTOCOL - { 0xff & EX_PROTOCOL, "Remote protocol error." }, -#endif -#ifdef EX_NOPERM - { 0xff & EX_NOPERM, "Insufficient permission." }, -#endif -#ifdef EX_CONFIG - { 0xff & EX_NOPERM, "Local configuration error." }, -#endif - { S_ERR, "Exec error." }, - { -1, NULL }, -}; - -const char *mutt_strsysexit(int e) -{ - int i; - - for (i = 0; sysexits_h[i].str; i++) - { - if (e == sysexits_h[i].v) - break; - } - - return sysexits_h[i].str; -} - #ifdef DEBUG char debugfilename[_POSIX_PATH_MAX]; FILE *debugfile = NULL; diff --git a/sendlib.c b/sendlib.c index ea69e2c31..dbdacfbff 100644 --- a/sendlib.c +++ b/sendlib.c @@ -72,9 +72,10 @@ #ifdef HAVE_SYSEXITS_H #include -#else /* Make sure EX_OK is defined */ +#else #define EX_OK 0 #endif + /* If you are debugging this file, comment out the following line. */ #define NDEBUG #ifdef NDEBUG @@ -2617,7 +2618,7 @@ int mutt_invoke_sendmail(struct Address *from, struct Address *to, struct Addres { const char *e = NULL; - e = mutt_strsysexit(i); + e = mutt_str_sysexit(i); mutt_error(_("Error sending message, child exited %d (%s)."), i, NONULL(e)); if (childout) {