| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: tparm.c,v 1.12 2013/01/24 10:41:28 roy Exp $ */ | | 1 | /* $NetBSD: tparm.c,v 1.13 2013/01/25 12:30:05 roy Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2009, 2011, 2013 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2009, 2011, 2013 The NetBSD Foundation, Inc. |
5 | * | | 5 | * |
6 | * This code is derived from software contributed to The NetBSD Foundation | | 6 | * This code is derived from software contributed to The NetBSD Foundation |
7 | * by Roy Marples. | | 7 | * by Roy Marples. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -18,27 +18,27 @@ | | | @@ -18,27 +18,27 @@ |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ | | 28 | */ |
29 | | | 29 | |
30 | #include <sys/cdefs.h> | | 30 | #include <sys/cdefs.h> |
31 | __RCSID("$NetBSD: tparm.c,v 1.12 2013/01/24 10:41:28 roy Exp $"); | | 31 | __RCSID("$NetBSD: tparm.c,v 1.13 2013/01/25 12:30:05 roy Exp $"); |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | | | 33 | |
34 | #include <assert.h> | | 34 | #include <assert.h> |
35 | #include <ctype.h> | | 35 | #include <ctype.h> |
36 | #include <errno.h> | | 36 | #include <errno.h> |
37 | #include <stdarg.h> | | 37 | #include <stdarg.h> |
38 | #include <stdio.h> | | 38 | #include <stdio.h> |
39 | #include <stdlib.h> | | 39 | #include <stdlib.h> |
40 | #include <string.h> | | 40 | #include <string.h> |
41 | #include <term_private.h> | | 41 | #include <term_private.h> |
42 | #include <term.h> | | 42 | #include <term.h> |
43 | | | 43 | |
44 | #define LONG_STR_MAX ((CHAR_BIT * sizeof(long)) / 3) | | 44 | #define LONG_STR_MAX ((CHAR_BIT * sizeof(long)) / 3) |
| @@ -213,32 +213,45 @@ _ti_tiparm(TERMINAL *term, const char *s | | | @@ -213,32 +213,45 @@ _ti_tiparm(TERMINAL *term, const char *s |
213 | if (term->_buflen == 0) { | | 213 | if (term->_buflen == 0) { |
214 | term->_buf = malloc(BUFINC); | | 214 | term->_buf = malloc(BUFINC); |
215 | if (term->_buf == NULL) | | 215 | if (term->_buf == NULL) |
216 | return NULL; | | 216 | return NULL; |
217 | term->_buflen = BUFINC; | | 217 | term->_buflen = BUFINC; |
218 | } | | 218 | } |
219 | | | 219 | |
220 | memset(&piss, 0, sizeof(piss)); | | 220 | memset(&piss, 0, sizeof(piss)); |
221 | max = _ti_parm_analyse(str, piss, TPARM_MAX); | | 221 | max = _ti_parm_analyse(str, piss, TPARM_MAX); |
222 | | | 222 | |
223 | /* Put our parameters into variables */ | | 223 | /* Put our parameters into variables */ |
224 | memset(¶ms, 0, sizeof(params)); | | 224 | memset(¶ms, 0, sizeof(params)); |
225 | for (l = 0; l < max; l++) { | | 225 | for (l = 0; l < max; l++) { |
226 | if (piss[l]) | | 226 | if (piss[l]) { |
227 | params[l].string = va_arg(parms, char *); | | 227 | if (va_long) { |
228 | else if (va_long) | | 228 | /* This only works if char * fits into a long |
229 | params[l].num = va_arg(parms, long); | | 229 | * on this platform. */ |
230 | else | | 230 | if (sizeof(char *) <= sizeof(long)/*CONSTCOND*/) |
231 | params[l].num = (long)va_arg(parms, int); | | 231 | params[l].string = |
| | | 232 | (char *)va_arg(parms, long); |
| | | 233 | else { |
| | | 234 | errno = ENOTSUP; |
| | | 235 | return NULL; |
| | | 236 | } |
| | | 237 | } else |
| | | 238 | params[l].string = va_arg(parms, char *); |
| | | 239 | } else { |
| | | 240 | if (va_long) |
| | | 241 | params[l].num = va_arg(parms, long); |
| | | 242 | else |
| | | 243 | params[l].num = (long)va_arg(parms, int); |
| | | 244 | } |
232 | } | | 245 | } |
233 | | | 246 | |
234 | memset(&stack, 0, sizeof(stack)); | | 247 | memset(&stack, 0, sizeof(stack)); |
235 | while ((c = *str++) != '\0') { | | 248 | while ((c = *str++) != '\0') { |
236 | if (c != '%' || (c = *str++) == '%') { | | 249 | if (c != '%' || (c = *str++) == '%') { |
237 | if (c == '\0') | | 250 | if (c == '\0') |
238 | break; | | 251 | break; |
239 | if (ochar(term, c) == 0) | | 252 | if (ochar(term, c) == 0) |
240 | return NULL; | | 253 | return NULL; |
241 | continue; | | 254 | continue; |
242 | } | | 255 | } |
243 | | | 256 | |
244 | /* Handle formatting. */ | | 257 | /* Handle formatting. */ |