FreeBSD/Linux Kernel Cross Reference
sys/kern/sscanf.c
1 /*
2 * Mach Operating System
3 * Copyright (c) 1993 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: sscanf.c,v $
29 * Revision 2.3 93/03/26 17:54:53 mrt
30 * Lint.
31 * [93/03/23 af]
32 *
33 * Revision 2.2 93/03/09 10:55:32 danner
34 * Created.
35 * [93/03/06 14:35:41 af]
36 *
37 */
38 /*
39 * File: sscanf.c
40 * Author: Alessandro Forin, Carnegie Mellon University
41 * Date: 3/93
42 *
43 * Parse trivially simple strings
44 */
45
46 #include <mach/std_types.h>
47 #if later
48 #include <sys/stdargs.h>
49 #else
50 #include <sys/varargs.h>
51 #endif
52
53 /*
54 * All I need is a miracle ...
55 * to keep this from growing like all the other sscanf!
56 */
57 #if later
58 int
59 sscanf(
60 register const unsigned char *input,
61 register const unsigned char *fmt,
62 ...)
63 #else
64 int
65 sscanf( input, fmt, va_alist )
66 unsigned char *input;
67 unsigned char *fmt;
68 va_dcl
69 #endif
70 {
71 va_list vp;
72 register int c;
73 long n;
74 boolean_t neg;
75 const unsigned char *start = input;
76
77 #if later
78 va_start(vp, fmt);
79 #else
80 va_start(vp);
81 #endif
82
83 while (c = *fmt++) {
84
85 if (c != '%' && c == *input) {
86 input++;
87 continue;
88 }
89
90 if (c != '%')
91 break; /* mismatch */
92
93 c = *fmt++;
94
95 switch (c) {
96
97 case 'd':
98 n = 0;
99 c = *input++;
100
101 neg = c == '-';
102 if (neg) c = *input++;
103
104 while (c >= '' && c <= '9') {
105 n = n * 10 + (c - '');
106 c = *input++;
107 }
108 input--; /* retract lookahead */
109
110 if (neg) n = -n;
111
112 /* done, store it away */
113 {
114 int *p = va_arg(vp, int *);
115 *p = n;
116 }
117
118 break;
119
120 default:
121 break;
122 }
123 }
124
125 va_end(vp);
126
127 return (vm_offset_t)input - (vm_offset_t)start;
128 }
Cache object: a3e2245ee79a5fc1d333d109cd8c43a9
|