Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtappbuilder / src / libAButil / util_err.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23
24 /*
25  *      $XConsortium: util_err.c /main/4 1995/11/06 18:53:42 rswiston $
26  *
27  * @(#)util_err.c       1.7 09 Jan 1995 cde_app_builder/src/libAButil
28  *
29  *      RESTRICTED CONFIDENTIAL INFORMATION:
30  *      
31  *      The information in this document is subject to special
32  *      restrictions in a confidential disclosure agreement between
33  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
34  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
35  *      Sun's specific written approval.  This document and all copies
36  *      and derivative works thereof must be returned or destroyed at
37  *      Sun's request.
38  *
39  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
40  *
41  */
42
43
44 /*
45  * File: util_err.c
46  */
47 #include <stdio.h>
48 #include <ab_private/util_err.h>
49 #include "utilP.h"
50
51 /*************************************************************************
52 **                                                                      **
53 **       Private Function Declarations                                  **
54 **                                                                      **
55 **************************************************************************/
56
57
58 /*************************************************************************
59 **                                                                      **
60 **       Data                                                           **
61 **                                                                      **
62 **************************************************************************/
63
64 /*************************************************************************
65 **                                                                      **
66 **       Function Definitions                                           **
67 **                                                                      **
68 **************************************************************************/
69
70 STRING
71 util_err_string(int errCode)
72 {
73     STRING      err = NULL;
74
75     switch (errCode)
76     {
77         case ERR_INTERNAL:      
78             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 4, "Internal error");
79         break;
80         case ERR_RECURSION:     
81             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 5, "Recursive function calls");
82         break;
83         case ERR_NOT_ALLOWED:
84             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 6, "Permission denied");
85         break;
86         case ERR_DATA_SPACE_FULL:
87             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 8, "Data space is full");
88         break;
89         case ERR_BUFFER_TOO_SMALL:
90             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 9, "Buffer is too small");
91         break;
92         case ERR_NOT_IMPLEMENTED: 
93         err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 10, "Functionality is not implemented");
94         break;
95         case ERR_NOT_INITIALIZED: 
96         err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 11, "Not initialized");
97         break;
98         case ERR_CLIENT: 
99         err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 12, "Client error");
100         break;
101         case ERR_NOT_FOUND: 
102         err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 13, "Not found");
103         break;
104         case ERR_DUPLICATE_KEY: 
105         err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 14, "Duplicate key");
106         break;
107         case ERR_BAD_PARAM: 
108         err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 15, "Bad parameter");
109         break;
110         case ERR_IO: 
111         err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 16, "I/O error");
112         break;
113         case ERR_FILE_NOT_FOUND: 
114         err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 17, "File not found");
115         break;
116         case ERR_OPEN:
117             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 18, "Could not open file");
118         break;
119         case ERR_WRITE:
120             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 19, "Could not write to file");
121         break;
122         case ERR_READ:
123             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 20, "Could not read file");
124         break;
125         case ERR_EOF:
126             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 21, "End of file");
127         break;
128         case ERR_BAD_FILE_FORMAT:
129             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 22, "Bad file format");
130         break;
131         case ERR_RENAME:
132             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 23, "Could not rename file");
133         break;
134         case ERR_MEMORY:
135             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 24, "Memory error");
136         break;
137         case ERR_NO_MEMORY:
138             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 25, "No memory");
139         break;
140         case ERR_MEMORY_CORRUPT:
141             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 26, "Memory is corrupt");
142         break;
143         case ERR_MULTIPLE_FREE:
144             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 27, "Multiple free of memory");
145         break;
146         case ERR_READ_ONLY:
147             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 28, "Read-only file");
148         break;
149         case ERR_BACKUP:
150             err= catgets(UTIL_MESSAGE_CATD, UTIL_MESSAGE_SET, 29, "Could not backup file");
151         break;
152     }
153
154     /*
155      * An error has already occurred. Don't return NULL and cause a 
156      * core dump!
157      */
158     return err == NULL?"":err;
159 }
160
161 int
162 util_print_error(
163     int         errCode, 
164     STRING      string
165 )
166 {
167     STRING      errmsg = NULL;
168
169     errmsg = util_err_string(errCode);
170     if (string)
171         util_printf_err("%s: %s\n", string, errmsg);
172     else
173         util_printf_err("%s\n", errmsg);
174
175     return 0;
176 }