1 /* @(#)defs.h	1.3 18/09/11 Copyright 2017-2018 J. Schilling */
2 /*
3  *	Definitions for using the printf Bourne Shell builtin as standalone
4  *
5  *	Copyright (c) 2017-2018 J. Schilling
6  */
7 /*
8  * The contents of this file are subject to the terms of the
9  * Common Development and Distribution License, Version 1.0 only
10  * (the "License").  You may not use this file except in compliance
11  * with the License.
12  *
13  * See the file CDDL.Schily.txt in this distribution for details.
14  * A copy of the CDDL is also available via the Internet at
15  * http://www.opensource.org/licenses/cddl1.txt
16  *
17  * When distributing Covered Code, include this CDDL HEADER in each
18  * file and include the License file CDDL.Schily.txt from this distribution.
19  */
20 
21 #include <schily/types.h>
22 #include <schily/utypes.h>
23 #include <schily/stdio.h>
24 #include <schily/stdlib.h>
25 #include <schily/string.h>
26 #include <schily/schily.h>
27 #include <schily/locale.h>
28 #include <schily/nlsdefs.h>
29 
30 #define	DO_SYSPRINTF
31 
32 #define	C				(char *)
33 #define	UC				(unsigned char *)
34 #define	CP				(char **)
35 #define	UCP				(unsigned char **)
36 #define	nullstr				""
37 #define	ERROR				1
38 #define	usage				"Usage"
39 #define	flushb()			fflush(stdout)
40 #define	prc_buff			putchar
41 #define	bprintf				printf
42 
43 #ifndef	HAVE_REALLOC_NULL
44 #define	realloc(p, s)			___realloc(p, s, "string stack")
45 #endif
46 
47 #define	bfailure(p1, p2, p3)		{ fprintf(stderr, "%s: %s%s\n",	\
48 						p1, _(p2), p3);		\
49 						exitval = 1; }
50 #define	gfailure(p1, p2)		{ fprintf(stderr, "%s: %s\n",	\
51 						_(C p1), _(p2));	\
52 						exitval = 1; }
53 
54 extern	int	exitval;
55 
56 extern int	main			__PR((int argc, char **argv));
57 extern int	sysprintf		__PR((int argc, unsigned char **argv));
58 
59 extern unsigned char *escape_char	__PR((unsigned char *cp,
60 						unsigned char *res,
61 						int echomode));
62 
63 extern int	optskip			__PR((int argc, unsigned char **argv,
64 						const char *use));
65 
66 extern unsigned char *growstak		__PR((unsigned char *newtop));
67 extern unsigned char *movstrstak	__PR((unsigned char *a,
68 							unsigned char *b));
69 
70 extern unsigned char	*stakbot;
71 extern unsigned char	*staktop;
72 extern unsigned char	*brkend;
73 
74 #define	Rcheat(a)	((Intptr_t)(a))
75 #define	locstak()	stakbot
76 #define	relstak()	(staktop-stakbot)
77 #define	absstak(x)	(stakbot+Rcheat(x))
78 #define	pushstak(c)	(*staktop++ = (c))
79 
80 #define	GROWSTAKTOP()	if (staktop >= brkend) \
81 				(void) growstak(staktop);
82 
83 #define	round(a, b)	(((Intptr_t)(((char *)(a)+b)-1))&~((b)-1))
84 #define	BYTESPERWORD	(sizeof (char *))
85