1 /****************************************************************************
2 * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Thomas E. Dickey 2001 *
31 ****************************************************************************/
33 #include <curses.priv.h>
37 MODULE_ID("$Id: varargs.c,v 1.8 2008/11/16 00:19:59 juergen Exp $")
44 atUnknown = 0, atInteger, atFloat, atPoint, atString
47 #define VA_INT(type) ival = (int) va_arg(ap, type)
48 #define VA_FLT(type) fval = va_arg(ap, type)
49 #define VA_PTR(type) pval = (char *)va_arg(ap, type)
50 #define VA_STR(type) sval = va_arg(ap, type)
52 #define MyBuffer _nc_globals.tracearg_buf
53 #define MyLength _nc_globals.tracearg_used
56 * Returns a string that represents the parameter list of a printf-style call.
58 NCURSES_EXPORT(char *)
59 _nc_varargs(const char *fmt, va_list ap)
61 static char dummy[] = "";
67 if (fmt == 0 || *fmt == '\0')
70 MyBuffer = typeMalloc(char, MyLength = BUFSIZ);
75 while (*fmt != '\0') {
77 char *pval = 0; /* avoid const-cast */
78 const char *sval = "";
83 ARGTYPE parm[MAX_PARMS];
85 ARGTYPE used = atUnknown;
87 while (*++fmt != '\0' && !done) {
91 if (parms < MAX_PARMS)
92 parm[parms++] = atInteger;
93 } else if (isalpha(UChar(*fmt))) {
96 case 'Z': /* FALLTHRU */
97 case 'h': /* FALLTHRU */
98 case 'l': /* FALLTHRU */
102 case 'i': /* FALLTHRU */
103 case 'd': /* FALLTHRU */
104 case 'u': /* FALLTHRU */
105 case 'x': /* FALLTHRU */
106 case 'X': /* FALLTHRU */
109 else if (type == 'Z')
115 case 'f': /* FALLTHRU */
116 case 'e': /* FALLTHRU */
117 case 'E': /* FALLTHRU */
118 case 'g': /* FALLTHRU */
119 case 'G': /* FALLTHRU */
128 VA_STR(const char *);
142 } else if (*fmt == '%') {
145 if (used != atUnknown && parms < MAX_PARMS) {
146 parm[parms++] = used;
147 for (n = 0; n < parms; ++n) {
152 sprintf(buffer, "%d", ival);
155 sprintf(buffer, "%f", fval);
158 sprintf(buffer, "%p", pval);
161 param = _nc_visbuf2(1, sval);
168 MyLength += strlen(param) + 2;
169 MyBuffer = typeRealloc(char, MyLength, MyBuffer);
170 sprintf(MyBuffer + strlen(MyBuffer), ", %s", param);
183 EMPTY_MODULE(_nc_varargs)