sh.err.c (6c02b4a4b46fecc2fa6bf1ab6b5e3255ad1d0767) sh.err.c (258f91c6020f3614878f3dcd49df02d9e004de2c)
1/*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
6/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
7/* All Rights Reserved */
8
9/*
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley Software License Agreement
12 * specifies the terms and conditions for redistribution.
13 */
14
1/*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
6/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
7/* All Rights Reserved */
8
9/*
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley Software License Agreement
12 * specifies the terms and conditions for redistribution.
13 */
14
15#pragma ident "%Z%%M% %I% %E% SMI"
16
17#include "sh.h"
18#include <locale.h>
19#include <dirent.h>
20#include <string.h>
21/*
22 * #include <sys/ioctl.h>
23 * #include <stdlib.h>
24 */
25#include "sh.tconst.h"
26/*
27 * C Shell
28 */
29
15#include "sh.h"
16#include <locale.h>
17#include <dirent.h>
18#include <string.h>
19/*
20 * #include <sys/ioctl.h>
21 * #include <stdlib.h>
22 */
23#include "sh.tconst.h"
24/*
25 * C Shell
26 */
27
30
28bool child;
29bool didfds;
30bool exiterr;
31bool errspl; /* Argument to error was spliced by seterr2 */
31bool errspl; /* Argument to error was spliced by seterr2 */
32bool haderr;
33jmp_buf reslab;
32tchar one[2] = { '1', 0 };
33tchar *onev[2] = { one, NOSTR };
34tchar one[2] = { '1', 0 };
35tchar *onev[2] = { one, NOSTR };
34/*
36short SHDIAG;
37int tpgrp;
38
39/*
35 * contains DIR * for last opendir_(), its left open if an error
36 * longjmp (reset) occurs before it gets closed via closedir.
37 * if its not null in the error handler, then closedir it.
38 */
39DIR *Dirp = NULL;
40
41/*
42 * Print error string s with optional argument arg.

--- 17 unchanged lines hidden (view full) ---

60 * Must flush before we print as we wish output before the error
61 * to go on (some form of) standard output, while output after
62 * goes on (some form of) diagnostic output.
63 * If didfds then output will go to 1/2 else to FSHOUT/FSHDIAG.
64 * See flush in sh.print.c.
65 */
66 flush();
67 haderr = 1; /* Now to diagnostic output */
40 * contains DIR * for last opendir_(), its left open if an error
41 * longjmp (reset) occurs before it gets closed via closedir.
42 * if its not null in the error handler, then closedir it.
43 */
44DIR *Dirp = NULL;
45
46/*
47 * Print error string s with optional argument arg.

--- 17 unchanged lines hidden (view full) ---

65 * Must flush before we print as we wish output before the error
66 * to go on (some form of) standard output, while output after
67 * goes on (some form of) diagnostic output.
68 * If didfds then output will go to 1/2 else to FSHOUT/FSHDIAG.
69 * See flush in sh.print.c.
70 */
71 flush();
72 haderr = 1; /* Now to diagnostic output */
68 timflg = 0; /* This isn't otherwise reset */
69 if (v = pargv)
70 pargv = 0, blkfree(v);
71 if (v = gargv)
72 gargv = 0, blkfree(v);
73
74 /*
75 * A zero arguments causes no printing, else print
76 * an error diagnostic here.
77 */
78 if (s) {
73 if (v = pargv)
74 pargv = 0, blkfree(v);
75 if (v = gargv)
76 gargv = 0, blkfree(v);
77
78 /*
79 * A zero arguments causes no printing, else print
80 * an error diagnostic here.
81 */
82 if (s) {
79 printf(s, a1, a2), printf("\n");
83 printf(s, a1, a2), printf("\n");
80 }
84 }
81
82
85
86
83 didfds = 0; /* Forget about 0,1,2 */
87 didfds = 0; /* Forget about 0,1,2 */
84 if ((ep = err) && errspl) {
88 if ((ep = err_msg) && errspl) {
85 errspl = 0;
86 xfree(ep);
87 }
88 errspl = 0;
89
90 if ( Dirp ){
91 closedir(Dirp);
92 Dirp = NULL;

--- 57 unchanged lines hidden (view full) ---

150 * The parser and scanner set up errors for later by calling seterr,
151 * which sets the variable err as a side effect; later to be tested,
152 * e.g. in process.
153 */
154void
155seterr(char *s)
156{
157
89 errspl = 0;
90 xfree(ep);
91 }
92 errspl = 0;
93
94 if ( Dirp ){
95 closedir(Dirp);
96 Dirp = NULL;

--- 57 unchanged lines hidden (view full) ---

154 * The parser and scanner set up errors for later by calling seterr,
155 * which sets the variable err as a side effect; later to be tested,
156 * e.g. in process.
157 */
158void
159seterr(char *s)
160{
161
158 if (err == 0)
159 err = s, errspl = 0;
162 if (err_msg == NULL)
163 err_msg = s, errspl = 0;
160}
161
162/* Set err to a splice of cp and dp, to be freed later in error() */
163void
164seterr2(tchar *cp, char *dp)
165{
166 char chbuf[BUFSIZ];
167 char *gdp;
168
164}
165
166/* Set err to a splice of cp and dp, to be freed later in error() */
167void
168seterr2(tchar *cp, char *dp)
169{
170 char chbuf[BUFSIZ];
171 char *gdp;
172
169 if (err)
173 if (err_msg)
170 return;
171
172 /* Concatinate cp and dp in the allocated space. */
173 tstostr(chbuf, cp);
174 gdp = gettext(dp);
174 return;
175
176 /* Concatinate cp and dp in the allocated space. */
177 tstostr(chbuf, cp);
178 gdp = gettext(dp);
175 err = (char *)xalloc(strlen(chbuf)+strlen(gdp)+1);
176 strcpy(err, chbuf);
177 strcat(err, gdp);
179 err_msg = (char *)xalloc(strlen(chbuf)+strlen(gdp)+1);
180 strcpy(err_msg, chbuf);
181 strcat(err_msg, gdp);
178
182
179 errspl++;/* Remember to xfree(err). */
183 errspl++;/* Remember to xfree(err_msg). */
180}
181
182/* Set err to a splice of cp with a string form of character d */
183void
184seterrc(char *cp, tchar d)
185{
184}
185
186/* Set err to a splice of cp with a string form of character d */
187void
188seterrc(char *cp, tchar d)
189{
186 char chbuf[MB_LEN_MAX+1];
190 char chbuf[MB_LEN_MAX+1];
187
188 /* don't overwrite an existing error message */
191
192 /* don't overwrite an existing error message */
189 if (err)
193 if (err_msg)
190 return;
191
192#ifdef MBCHAR
193 {
194 wchar_t wcd=(wchar_t)(d&TRIM);
195 int i;
196
197 i = wctomb(chbuf, wcd); /* chbuf holds d in multibyte representation. */
198 chbuf[(i>0)?i:0] = (char) 0;
199 }
200#else
201 chbuf[0]=(char)(d&TRIM); chbuf[1]=(char)0;
202#endif
203
204
205 /* Concatinate cp and d in the allocated space. */
194 return;
195
196#ifdef MBCHAR
197 {
198 wchar_t wcd=(wchar_t)(d&TRIM);
199 int i;
200
201 i = wctomb(chbuf, wcd); /* chbuf holds d in multibyte representation. */
202 chbuf[(i>0)?i:0] = (char) 0;
203 }
204#else
205 chbuf[0]=(char)(d&TRIM); chbuf[1]=(char)0;
206#endif
207
208
209 /* Concatinate cp and d in the allocated space. */
206 err = (char *)xalloc(strlen(cp)+strlen(chbuf)+1);
207 strcpy(err, cp);
208 strcat(err, chbuf);
210 err_msg = (char *)xalloc(strlen(cp)+strlen(chbuf)+1);
211 strcpy(err_msg, cp);
212 strcat(err_msg, chbuf);
209
213
210 errspl++; /* Remember to xfree(err). */
214 errspl++; /* Remember to xfree(err_msg). */
211}
215}