Debian Codegraph @

libsrc/os/vms/osmessage.c

raw
1 /* @(#)osmessage.c 19.1 (ES0-DMD) 02/25/03 13:56:13 */
2 /*===========================================================================
3 Copyright (C) 1995 European Southern Observatory (ESO)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public
16 License along with this program; if not, write to the Free
17 Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
18 MA 02139, USA.
19
20 Corresponding concerning ESO-MIDAS should be addressed as follows:
21 Internet e-mail: [email protected]
22 Postal address: European Southern Observatory
23 Data Management Division
24 Karl-Schwarzschild-Strasse 2
25 D 85748 Garching bei Muenchen
26 GERMANY
27 ===========================================================================*/
28
29 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
31 .TYPE Module
32 .IDENTIFICATION osmessage
33 .AUTHOR Francois Ochsenbein [ESO-IPG]
34 .LANGUAGE C
35 .VERSION 1.0 08-Oct-1987: Creation
36 .VERSION 1.1 19-Jan-1988: Added external pointer to be used
37 as message when oserror = -1.
38 .KEYWORDS System error messages
39 .ENVIRONMENT VAX/VMS Version
40 .COMMENTS The ``message'' list can be generated with
41 a program listed below as a comment. The following externals
42 are defined here:
43 \begin{TeX}
44 \begin{itemize}
45 \item oserror ({\em int}), system-independant error number
46 \item vmserror ({\em int}), VMS error code (on VMS only)
47 \item oserrmsg ({\em char *}), pointer to a text string to be used if
48 oserror has the value $-1$.
49 \end{itemize}
50 \end{TeX}
51
52 ----------------------------------------------------------------------------*/
53
54 #include <osdefos.h>
55 #include <macrogen.h>
56
57 #define dsc$w_length len
58 #define dsc$a_pointer s
59 #include <descrip.h> /* System */
60 MID_GLOBAL int vmserror = 0; /* VMS-specific error code */
61 #define LINESIZE 120 /* Maximum size of message */
62
63 MID_STATIC char msg_s[LINESIZE] = "?";
64 static short int msglen; /* Returned length from SYS$GETMSG */
65 MID_STATIC struct dsc$descriptor_s msg =
66 { sizeof(msg_s)-1, DSC$K_DTYPE_T, DSC$K_CLASS_S, msg_s };
67 MID_RSTATIC char *sys_errlist[] = { "?"
68 ,"not owner" /* EPERM */
69 ,"no such file or directory" /* ENOENT */
70 ,"no such process" /* ESRCH */
71 ,"interrupted system call" /* EINTR */
72 ,"i/o error" /* EIO */
73 ,"no such device or address" /* ENXIO */
74 ,"arg list too long" /* E2BIG */
75 ,"exec format error" /* ENOEXEC */
76 ,"bad file number" /* EBADF */
77 ,"no children" /* ECHILD */
78 ,"no more processes" /* EAGAIN */
79 ,"not enough core" /* ENOMEM */
80 ,"permission denied" /* EACCES */
81 ,"bad address" /* EFAULT */
82 ,"block device required" /* ENOTBLK */
83 ,"mount device busy" /* EBUSY */
84 ,"file exists" /* EEXIST */
85 ,"cross-device link" /* EXDEV */
86 ,"no such device" /* ENODEV */
87 ,"not a directory" /* ENOTDIR */
88 ,"is a directory" /* EISDIR */
89 ,"invalid argument" /* EINVAL */
90 ,"file table overflow" /* ENFILE */
91 ,"too many open files" /* EMFILE */
92 ,"not a typewriter" /* ENOTTY */
93 ,"text file busy" /* ETXTBSY */
94 ,"file too large" /* EFBIG */
95 ,"no space left on device" /* ENOSPC */
96 ,"illegal seek" /* ESPIPE */
97 ,"read-only file system" /* EROFS */
98 ,"too many links" /* EMLINK */
99 ,"broken pipe" /* EPIPE */
100 ,"math argument" /* EDOM */
101 ,"result too large" /* ERANGE */
102 ,"I/O operation would block channel" /* EWOULDBLOCK */
103 };
104 MID_STATIC int sys_nerr = ITEMS(sys_errlist);
105
106 MID_GLOBAL int oserror = 0; /* System error code */
107 MID_GLOBAL char *oserrmsg = NULL_PTR(char); /* If oserror == -1 */
108
109 /*==========================================================================*/
110 char *osmsg()
111 /*+++
112 .PURPOSE Provide a text explaining the error.
113 .RETURNS Pointer to the relevant message. VMS messages are included.
114 ---*/
115 {
116 register char *p;
117 register char *q;
118
119 if (oserror < 0 ) p = oserrmsg;
120 else
121 { if (oserror >= sys_nerr) oserror = 0;
122 p = sys_errlist[oserror];
123
124 for (q = msg_s; *p != EOS; p++, q++) *q = *p;
125 *(q++) = ' ';
126 msg.s = q;
127 msg.len= sizeof(msg_s) - 3 - (q-msg_s);
128 if (vmserror) SYS$GETMSG(vmserror,&msglen,&msg,15,0);
129 else msglen = 0;
130 q += msglen;
131 *(q++) = ':';
132 *(q++) = ' ';
133 *q = EOS;
134 p = msg_s;
135 }
136
137 return(p);
138 }
139
140
141 /* ------------- The following is the program to retrieve error messages */
142 #if 0
143 \begin{TeX}
144 \begin{verbatim}
145 #include <osparms.h>
146 #include <atype.h>
147
148 main()
149 {
150 int fin, fout, n, n0, i, j, i0;
151 static char line[200];
152
153 #if MID_OS_VMS
154 fin = osdopen("SYS$LIBRARY:errno.h", READ);
155 #else
156 fin = osdopen("/usr/include/errno.h", READ);
157 #endif
158 fout = osdopen("errno.lis", WRITE);
159 if (fout < 0) printf("****Bad Output File***");
160 n0 = 1;
161 osdputs(fout, "static char *sys_errlist[] = { \"?\"");
162
163 while (osdgets(fin, line, sizeof(line)) > 0)
164 { if (line[0] != '#') continue;
165 if (line[1] != 'd') continue;
166 i = 2;
167 while(isgraph(line[i])) i++;
168 while(isspace(line[i])) i++;
169 i0 = i;
170 while(isgraph(line[i])) i++;
171 while(isspace(line[i])) i++;
172 n = atoi(&line[i]);
173 if (n != n0) { printf("Bad number in: %s\n", line);
174 continue;
175 }
176 n0++;
177 while(line[i] != '/') i++;
178 i++;
179 i++;
180 while(isspace(line[i])) i++;
181 j = strlen(line) - 3;
182 while(isspace(line[j])) j--;
183 line[--i] = '"';
184 line[--i] = ',';
185 line[--i] = '\t';
186 # if MID_OS_VMS
187 # else
188 line[++j] = ':';
189 line[++j] = ' ';
190 # endif
191 line[++j] = '"';
192 while((j-i) < 48) line[++j] = ' ';
193 line[++j] = '/';
194 line[++j] = '*';
195 line[++j] = ' ';
196 while(isgraph(line[i0])) line[++j] = line[i0++];
197 line[++j] = ' ';
198 line[++j] = '*';
199 line[++j] = '/';
200 line[++j] = EOS;
201 osdputs(fout, &line[i]);
202 }
203
204 osdputs(fout, "\t};");
205 osdclose(fout);
206 ospexit(0);
207 }
208 #endif