Deleted Added
full compact
subr_scanf.c (42680) subr_scanf.c (43300)
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * $Id$
36 * $Id: subr_scanf.c,v 1.1 1999/01/15 00:03:39 msmith Exp $
37 * From: Id: vfscanf.c,v 1.13 1998/09/25 12:20:27 obrien Exp
38 */
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <machine/limits.h>
44

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

86#define isspace(c) ((c) == ' ' || (c) == '\t' || \
87 (c) == '\r' || (c) == '\n')
88#define isascii(c) (((c) & ~0x7f) == 0)
89#define isupper(c) ((c) >= 'A' && (c) <= 'Z')
90#define islower(c) ((c) >= 'a' && (c) <= 'z')
91#define isalpha(c) (isupper(c) || (islower(c)))
92#define isdigit(c) ((c) >= '0' && (c) <= '9')
93
37 * From: Id: vfscanf.c,v 1.13 1998/09/25 12:20:27 obrien Exp
38 */
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <machine/limits.h>
44

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

86#define isspace(c) ((c) == ' ' || (c) == '\t' || \
87 (c) == '\r' || (c) == '\n')
88#define isascii(c) (((c) & ~0x7f) == 0)
89#define isupper(c) ((c) >= 'A' && (c) <= 'Z')
90#define islower(c) ((c) >= 'a' && (c) <= 'z')
91#define isalpha(c) (isupper(c) || (islower(c)))
92#define isdigit(c) ((c) >= '0' && (c) <= '9')
93
94static u_char *__sccl(char *, u_char *);
94static const u_char *__sccl(char *, const u_char *);
95
96int
97sscanf(const char *ibuf, const char *fmt, ...)
98{
99 va_list ap;
100 int ret;
101
102 va_start(ap, fmt);
103 ret = vsscanf(ibuf, fmt, ap);
104 va_end(ap);
105 return(ret);
106}
107
108int
109vsscanf(const char *inp, char const *fmt0, va_list ap)
110{
111 int inr;
95
96int
97sscanf(const char *ibuf, const char *fmt, ...)
98{
99 va_list ap;
100 int ret;
101
102 va_start(ap, fmt);
103 ret = vsscanf(ibuf, fmt, ap);
104 va_end(ap);
105 return(ret);
106}
107
108int
109vsscanf(const char *inp, char const *fmt0, va_list ap)
110{
111 int inr;
112 u_char *fmt = (u_char *)fmt0;
112 const u_char *fmt = (const u_char *)fmt0;
113 int c; /* character from format, or conversion */
114 size_t width; /* field width, or 0 */
115 char *p; /* points into all kinds of strings */
116 int n; /* handy integer */
117 int flags; /* flags as defined above */
118 char *p0; /* saves original value of p when necessary */
119 int nassigned; /* number of fields assigned */
120 int nconversions; /* number of conversions */

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

318
319 case CT_CCL:
320 /* scan a (nonempty) character class (sets NOSKIP) */
321 if (width == 0)
322 width = (size_t)~0; /* `infinity' */
323 /* take only those things in the class */
324 if (flags & SUPPRESS) {
325 n = 0;
113 int c; /* character from format, or conversion */
114 size_t width; /* field width, or 0 */
115 char *p; /* points into all kinds of strings */
116 int n; /* handy integer */
117 int flags; /* flags as defined above */
118 char *p0; /* saves original value of p when necessary */
119 int nassigned; /* number of fields assigned */
120 int nconversions; /* number of conversions */

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

318
319 case CT_CCL:
320 /* scan a (nonempty) character class (sets NOSKIP) */
321 if (width == 0)
322 width = (size_t)~0; /* `infinity' */
323 /* take only those things in the class */
324 if (flags & SUPPRESS) {
325 n = 0;
326 while (ccltab[*inp]) {
326 while (ccltab[(int)(unsigned char)*inp]) {
327 n++, inr--, inp++;
328 if (--width == 0)
329 break;
330 if (inr <= 0) {
331 if (n == 0)
332 goto input_failure;
333 break;
334 }
335 }
336 if (n == 0)
337 goto match_failure;
338 } else {
339 p0 = p = va_arg(ap, char *);
327 n++, inr--, inp++;
328 if (--width == 0)
329 break;
330 if (inr <= 0) {
331 if (n == 0)
332 goto input_failure;
333 break;
334 }
335 }
336 if (n == 0)
337 goto match_failure;
338 } else {
339 p0 = p = va_arg(ap, char *);
340 while (ccltab[*inp]) {
340 while (ccltab[(int)(unsigned char)*inp]) {
341 inr--;
342 *p++ = *inp++;
343 if (--width == 0)
344 break;
345 if (inr <= 0) {
346 if (p == p0)
347 goto input_failure;
348 break;

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

541}
542
543/*
544 * Fill in the given table from the scanset at the given format
545 * (just after `['). Return a pointer to the character past the
546 * closing `]'. The table has a 1 wherever characters should be
547 * considered part of the scanset.
548 */
341 inr--;
342 *p++ = *inp++;
343 if (--width == 0)
344 break;
345 if (inr <= 0) {
346 if (p == p0)
347 goto input_failure;
348 break;

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

541}
542
543/*
544 * Fill in the given table from the scanset at the given format
545 * (just after `['). Return a pointer to the character past the
546 * closing `]'. The table has a 1 wherever characters should be
547 * considered part of the scanset.
548 */
549static u_char *
550__sccl(char *tab, u_char *fmt)
549static const u_char *
550__sccl(char *tab, const u_char *fmt)
551{
552 int c, n, v;
553
554 /* first `clear' the whole table */
555 c = *fmt++; /* first char hat => negated scanset */
556 if (c == '^') {
557 v = 1; /* default => accept */
558 c = *fmt++; /* get new first char */

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

692 acc += c;
693 }
694 }
695 if (any < 0) {
696 acc = UQUAD_MAX;
697 } else if (neg)
698 acc = -acc;
699 if (endptr != 0)
551{
552 int c, n, v;
553
554 /* first `clear' the whole table */
555 c = *fmt++; /* first char hat => negated scanset */
556 if (c == '^') {
557 v = 1; /* default => accept */
558 c = *fmt++; /* get new first char */

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

692 acc += c;
693 }
694 }
695 if (any < 0) {
696 acc = UQUAD_MAX;
697 } else if (neg)
698 acc = -acc;
699 if (endptr != 0)
700 *endptr = (char *)(any ? s - 1 : nptr);
700 *endptr = (const char *)(any ? s - 1 : nptr);
701 return (acc);
702}
703
704/*
705 * Convert a string to a quad integer.
706 *
707 * Ignores `locale' stuff. Assumes that the upper and lower case
708 * alphabets and digits are each contiguous.

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

783 acc += c;
784 }
785 }
786 if (any < 0) {
787 acc = neg ? QUAD_MIN : QUAD_MAX;
788 } else if (neg)
789 acc = -acc;
790 if (endptr != 0)
701 return (acc);
702}
703
704/*
705 * Convert a string to a quad integer.
706 *
707 * Ignores `locale' stuff. Assumes that the upper and lower case
708 * alphabets and digits are each contiguous.

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

783 acc += c;
784 }
785 }
786 if (any < 0) {
787 acc = neg ? QUAD_MIN : QUAD_MAX;
788 } else if (neg)
789 acc = -acc;
790 if (endptr != 0)
791 *endptr = (char *)(any ? s - 1 : nptr);
791 *endptr = (const char *)(any ? s - 1 : nptr);
792 return (acc);
793}
792 return (acc);
793}