move mutt_strsysexit into lib-sys/exit.[hc]
[apps/madmutt.git] / lib-sys / exit.c
1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; either version 2 of the License, or (at
5  *  your option) any later version.
6  *
7  *  This program is distributed in the hope that it will be useful, but
8  *  WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  *  General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
15  *  MA 02110-1301, USA.
16  *
17  *  Copyright © 2006 Pierre Habouzit
18  */
19 /*
20  * Copyright notice from original mutt:
21  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
22  * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
23  *
24  * This file is part of mutt-ng, see http://www.muttng.org/.
25  * It's licensed under the GNU General Public License,
26  * please see the file GPL in the top level source directory.
27  */
28
29 #if HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <stdlib.h>
34 #ifdef HAVE_SYSEXITS_H
35 #include <sysexits.h>
36 #else /* Make sure EX_OK is defined <philiph@pobox.com> */
37 #define EX_OK 0
38 #endif
39
40 #include <lib-lib/mem.h>
41
42 #include "exit.h"
43
44 static const struct {
45     int v;
46     const char *str;
47 } sysexits_h[] = {
48 #ifdef EX_USAGE
49     { 0xff & EX_USAGE, "Bad usage." },
50 #endif
51 #ifdef EX_DATAERR
52     { 0xff & EX_DATAERR, "Data format error." },
53 #endif
54 #ifdef EX_NOINPUT
55     { 0xff & EX_NOINPUT, "Cannot open input." },
56 #endif
57 #ifdef EX_NOUSER
58     { 0xff & EX_NOUSER, "User unknown." },
59 #endif
60 #ifdef EX_NOHOST
61     { 0xff & EX_NOHOST, "Host unknown." },
62 #endif
63 #ifdef EX_UNAVAILABLE
64     { 0xff & EX_UNAVAILABLE, "Service unavailable." },
65 #endif
66 #ifdef EX_SOFTWARE
67     { 0xff & EX_SOFTWARE, "Internal error." },
68 #endif
69 #ifdef EX_OSERR
70     { 0xff & EX_OSERR, "Operating system error." },
71 #endif
72 #ifdef EX_OSFILE
73     { 0xff & EX_OSFILE, "System file missing." },
74 #endif
75 #ifdef EX_CANTCREAT
76     { 0xff & EX_CANTCREAT, "Can't create output." },
77 #endif
78 #ifdef EX_IOERR
79     { 0xff & EX_IOERR, "I/O error." },
80 #endif
81 #ifdef EX_TEMPFAIL
82     { 0xff & EX_TEMPFAIL, "Deferred." },
83 #endif
84 #ifdef EX_PROTOCOL
85     { 0xff & EX_PROTOCOL, "Remote protocol error." },
86 #endif
87 #ifdef EX_NOPERM
88     { 0xff & EX_NOPERM, "Insufficient permission." },
89 #endif
90 #ifdef EX_CONFIG
91     { 0xff & EX_NOPERM, "Local configuration error." },
92 #endif
93     { S_ERR, "Exec error." },
94 };
95
96 const char *m_strsysexit(int e)
97 {
98     int i;
99
100     for (i = 0; countof(sysexits_h); i++) {
101         if (e == sysexits_h[i].v)
102             return sysexits_h[i].str;
103     }
104
105     return "";
106 }