1 /* @(#)mystdio.h	1.21 20/02/26 Copyright 2006-2020 J. Schilling */
2 /*
3  *	Defines to make FILE * -> int *, used to allow
4  *	the Bourne shell to use functions that expect stdio.
5  *
6  *	Copyright (c) 2006-2020 J. Schilling
7  */
8 /*
9  * The contents of this file are subject to the terms of the
10  * Common Development and Distribution License, Version 1.0 only
11  * (the "License").  You may not use this file except in compliance
12  * with the License.
13  *
14  * See the file CDDL.Schily.txt in this distribution for details.
15  * A copy of the CDDL is also available via the Internet at
16  * http://www.opensource.org/licenses/cddl1.txt
17  *
18  * When distributing Covered Code, include this CDDL HEADER in each
19  * file and include the License file CDDL.Schily.txt from this distribution.
20  */
21 
22 #ifndef	NO_SCHILY_STDIO_H
23 #ifndef	_MYSTDIO_H
24 #define	_MYSTDIO_H
25 
26 /*
27  * First include the official stdio.h to make sure that no other system include
28  * file will pull it in, given that the platform is recent enough to protect
29  * stdio.h from multiple #includes.
30  */
31 #ifndef	_INCL_STDIO_H
32 #include <stdio.h>
33 #define	_INCL_STDIO_H
34 #endif
35 
36 /*
37  * Now make the definitions from the platforms system stdio.h vanish and
38  * replace them by what we need in order to replace "FILE *" by "int *".
39  */
40 
41 #define	_FILE_DEFINED	/* Prevent MSC from redefining FILE in wchar.h */
42 
43 #undef	FILE
44 #define	FILE	int
45 #ifdef	linux
46 #undef	__FILE
47 #define	__FILE	int	/* Needed for Linux */
48 #endif
49 #undef	EOF
50 #define	EOF	(-1)
51 
52 #undef	fflush
53 #define	fflush(a)	(0)
54 #undef	clearerr
55 #define	clearerr(a)
56 #undef	ferror
57 #define	ferror(a)	(0)
58 
59 /*
60  * shell_* names are internal
61  */
62 #undef	printf
63 #define	printf		shell_printf
64 #undef	fprintf
65 #define	fprintf		shell_fprintf
66 #undef	sprintf
67 #define	sprintf		shell_sprintf
68 #undef	snprintf
69 #define	snprintf	shell_snprintf
70 #undef	error
71 #define	error		shell_error
72 
73 #define	js_printf	shell_printf
74 #define	js_fprintf	shell_fprintf
75 #define	js_sprintf	shell_sprintf
76 #define	js_snprintf	shell_snprintf
77 
78 extern	int	__in__;
79 extern	int	__out__;
80 extern	int	__err__;
81 
82 #undef	stdin
83 #define	stdin		(&__in__)
84 #undef	stdout
85 #define	stdout		(&__out__)
86 #undef	stderr
87 #define	stderr		(&__err__)
88 
89 #if	defined(HAVE_LARGEFILES)
90 #define	fileopen64	shell_fileopen64
91 #else
92 #define	fileopen	shell_fileopen
93 #endif
94 #define	fclose		shell_fclose
95 
96 #undef	getc
97 #define	getc		shell_getc
98 #define	fgetc		shell_fgetc
99 
100 #undef	putc
101 #define	putc		shell_putc
102 
103 #define	fileread	shell_fileread
104 #define	filewrite	shell_filewrite
105 
106 #define	fdown(f)	(*(f))
107 
108 
109 extern	int	fclose	__PR((FILE *f));
110 extern	int	getc	__PR((FILE *f));
111 extern	int	fgetc	__PR((FILE *f));
112 extern	int	putc	__PR((int c, FILE *f));
113 
114 /*
115  * shedit_* names are external symbols.
116  * These are now only functions (no variables) to allow to use lazy
117  * linking and to stay within the features of the limited Mac OS X linker.
118  */
119 #define	chghistory	shedit_chghistory	/* inputc.c	*/
120 #define	histrange	shedit_histrange	/* inputc.c	*/
121 #define	remap		shedit_remap		/* map.c	*/
122 #define	list_map	shedit_list_map		/* map.c	*/
123 #define	add_map		shedit_add_map		/* map.c	*/
124 #define	del_map		shedit_del_map		/* map.c	*/
125 #define	append_line	shedit_append_line	/* inputc.c	*/
126 
127 /*
128  * dat.c
129  * These variables previously have been exported but are no longer exported
130  * in order to support lazy linking and the limited Mac OS X linker.
131  * These internal valaues are now set up from the main program via
132  * parameters to shedit_setprompts().
133  */
134 #define	prompts		shell_prompts	/* char *prompts[2] for the editor */
135 #define	prompt		shell_prompt	/* int prompt index for prompts	   */
136 #define	delim		shell_delim	/* int delim			   */
137 
138 #define	ctlc		shell_ctlc
139 #define	evarray		shell_evarray
140 #define	ex_status	shell_ex_status
141 #define	gstd		shell_gstd
142 #define	inithome	shell_inithome	/* ??? immer mit getenv("HOME") ??? */
143 #define	prflg		shell_prflg
144 #define	ttyflg		shell_ttyflg
145 
146 /*
147  * comerr.c
148  */
149 #define	_comerr		shell__comerr
150 #define	comerr		shell_comerr
151 #define	comerrno	shell_comerrno
152 #define	comexit		shell_comexit
153 #define	errmsg		shell_errmsg
154 #define	errmsgno	shell_errmsgno
155 #define	errmsgstr	shell_errmsgstr
156 #define	on_comerr	shell_on_comerr
157 #define	xcomerr		shell_xcomerr
158 #define	xcomerrno	shell_xcomerrno
159 
160 /*
161  * edit.c
162  */
163 #define	berror		shell_berror
164 #define	errstr		shell_errstr
165 #define	ev_eql		shell_ev_eql
166 #define	exitbsh		shell_exitbsh	/* Need a call into the Bourne Shell */
167 #define	is_dir		shell_is_dir
168 #define	myhome		shell_myhome	/* XXX See inithome */
169 #define	pushline	shell_pushline
170 #define	setinput	shell_setinput
171 #define	toint		shell_toint
172 /*
173  * The local getenv() putenv() routines that call functions from the
174  * main program via function pointers set up via
175  * shedit_getenv()/shedit_putenv() from the main program.
176  */
177 #define	ev_insert	shell_putenv
178 #define	getcurenv	shell_getenv
179 
180 /*
181  * error.c
182  */
183 #define	js_error	shell_error
184 
185 /*
186  * expand.c
187  */
188 #define	any_match	shell_any_match
189 #define	expand		shell_expand
190 
191 /*
192  * fgetline.c
193  */
194 #define	js_fgetline	shell_fgetline
195 #define	js_getline	shell_getline
196 
197 /*
198  * inputc.c
199  */
200 #define	_nextwc		shell__nextwc
201 #define	append_wline	shell_append_wline
202 #define	get_histlen	shell_get_histlen
203 #define	get_line	shell_get_line
204 #define	getinfile	shell_getinfile
205 #define	getnextc	shell_getnextc
206 #define	init_input	shell_init_input
207 #define	make_line	shell_make_line
208 #define	makewstr	shell_makewstr
209 #define	match_hist	shell_match_hist
210 #define	nextc		shell_nextc
211 #define	put_history	shell_put_history
212 #define	search_history	shell_search_history
213 #define	remove_history	shell_remove_history
214 #define	read_init_history	shell_read_init_history
215 #define	readhistory	shell_readhistory
216 #define	save_history	shell_save_history
217 #define	space		shell_space
218 #define	raisecond(n, p)
219 
220 /*
221  * map.c
222  */
223 #define	gmap		shell_gmap
224 #define	map_init	shell_map_init
225 #define	mapflag		shell_mapflag
226 #define	mapgetc		shell_mapgetc
227 #define	maptab		shell_maptab
228 #define	mp_init		shell_mp_init
229 #define	rxmap		shell_rxmap
230 
231 /*
232  * node.c
233  */
234 #define	_printio	shell__printio
235 #define	allocnode	shell_allocnode
236 #define	allocvec	shell_allocvec
237 #define	freevec		shell_freevec
238 #define	listlen		shell_listlen
239 #define	printio		shell_printio
240 #define	printstring	shell_printstring
241 #define	printtree	shell_printtree
242 #ifndef	freetree
243 #define	freetree	shell_freetree
244 #endif
245 
246 /*
247  * str.c
248  */
249 #define	nullstr		shell_nullstr
250 #define	ebadpattern	shell_ebadpattern
251 #define	ecantopen	shell_ecantopen
252 #define	enotfound	shell_enotfound
253 #define	eql		shell_eql
254 #define	for_read	shell_for_read
255 #define	for_wct		shell_for_wct
256 #define	histname	shell_histname
257 #define	historyname	shell_historyname
258 #define	ignoreeofname	shell_ignoreeofname
259 #define	mapname		shell_mapname
260 #define	on		shell_on
261 #define	slash		shell_slash
262 #define	sn_no_mem	shell_sn_no_mem
263 #define	special		shell_special
264 #define	termcapname	shell_termcapname
265 #define	termname	shell_termname
266 
267 /*
268  * strsubs.c
269  */
270 #define	concat		shell_concat
271 #define	concatv		shell_concatv
272 #define	fbasename	shell_fbasename
273 #define	makestr		shell_makestr
274 #define	pretty_string	shell_pretty_string
275 #define	quote_string	shell_quote_string
276 #define	strbeg		shell_strbeg
277 #define	streql		shell_streql
278 #define	streqln		shell_streqln
279 #define	strindex	shell_strindex
280 #define	wordeql		shell_wordeql
281 
282 /*
283  * ttymodes.c
284  */
285 #define	get_tty_modes	shell_get_tty_modes
286 #define	i_should_echo	shell_i_should_echo
287 #define	ins_mode	shell_ins_mode
288 #define	reset_line_disc	shell_reset_line_disc
289 #define	reset_tty_modes	shell_reset_tty_modes
290 #define	reset_tty_pgrp	shell_reset_tty_pgrp
291 #define	set_append_modes	shell_set_append_modes
292 #define	set_insert_modes	shell_set_insert_modes
293 #define	tty_getpgrp	shell_tty_getpgrp
294 #define	tty_setpgrp	shell_tty_setpgrp
295 
296 #endif /* _MYSTDIO_H */
297 #endif /* NO_SCHILY_STDIO_H */
298