vsta

Check-in [f2a0dfc9bb]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Support for %n format.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:f2a0dfc9bb8374579f20da9c4fb00942d82b1dfa36c1905d2c2126fe546ecbb6
User & Date: vandys 2001-12-21 14:41:25
Context
2001-12-21
14:50
Fix warnings. Add missing file. check-in: 2e2f499e93 user: vandys tags: master, trunk
14:41
Support for %n format. check-in: f2a0dfc9bb user: vandys tags: master, trunk
14:41
More CVS fallout. check-in: a022ec8942 user: vandys tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to vsta/src/lib/scanf.c.

48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
..
63
64
65
66
67
68
69
70
71




72
73
74
75
76
77
78
79
80
81
82
83
84
85


86
87
88
89

90
91
92
93
94
95
96
..
98
99
100
101
102
103
104
105

106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
...
125
126
127
128
129
130
131
132





133
134
135
136


137
138
139
140

141

142
143
144
145
146
147
148
149
...
169
170
171
172
173
174
175
176


177
178
179
180
181
182
183
184
185
186
187
188

189
190
191
192
193
194
195
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
...
298
299
300
301
302
303
304
305
306








307

308
309
310
311
312
313
314
315
316
317
318
319






320
321


322
323
324
325
326

327
328
329
330
331
332
333
	SPC,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
};

static int
instr(char *ptr, int type, int len, FILE *fp, int *eofptr)

{
	int ch;
	char *optr;
	int ignstp;

	*eofptr = 0;
	optr = ptr;
................................................................................
	if (type=='c' && len==30000) {
		len = 1;
	}
	ignstp = 0;
	if (type == 's') {
		ignstp = SPC;
	}
	while ((ch = getc(fp)) != EOF && _sctab[ch] & ignstp) {
		;




	}
	ignstp = SPC;
	if (type=='c')
		ignstp = 0;
	else if (type=='[')
		ignstp = STP;
	while (ch != EOF && (_sctab[ch]&ignstp)==0) {
		if (ptr) {
			*ptr++ = ch;
		}
		if (--len <= 0) {
			break;
		}
		ch = getc(fp);


	}
	if (ch != EOF) {
		if (len > 0) {
			ungetc(ch, fp);

		}
		*eofptr = 0;
	} else {
		*eofptr = 1;
	}
	if (ptr && ptr!=optr) {
		if (type != 'c') {
................................................................................
		}
		return(1);
	}
	return(0);
}

static int
innum(int **ptr, int type, int len, int size, FILE *fp, int *eofptr)

{
	char *np;
	char numbuf[64];
	int c, base;
	int expseen, scale, negflg, c1, ndigit;
	long lcval;

	if (type=='c' || type=='s' || type=='[') {
		return(instr(ptr ? *(char **)ptr :
			(char *)NULL, type, len, fp, eofptr));
	}
	lcval = 0;
	ndigit = 0;
	scale = INT;
	if (type=='e'||type=='f') {
		scale = FLOAT;
	}
................................................................................
		base = 8;
	} else if (type=='x') {
		base = 16;
	}
	np = numbuf;
	expseen = 0;
	negflg = 0;
	while ((c = getc(fp)) == ' ' || c == '\t' || c == '\n');





	if (c=='-') {
		negflg++;
		*np++ = c;
		c = getc(fp);


		len--;
	} else if (c=='+') {
		len--;
		c = getc(fp);

	}

	for ( ; --len>=0; *np++ = c, c = getc(fp)) {
		if (isdigit(c)
		 || base==16 && ('a'<=c && c<='f' || 'A'<=c && c<='F')) {
			ndigit++;
			if (base == 8) {
				lcval <<=3;
			} else if (base==10) {
				lcval = ((lcval<<2) + lcval)<<1;
................................................................................
			continue;
		} else if ((c=='e'||c=='E') && expseen==0) {
			if (base != 10 || scale == INT || ndigit == 0) {
				break;
			}
			expseen++;
			*np++ = c;
			c = getc(fp);


			if (c!='+'&&c!='-'&&('0'>c||c>'9')) {
				break;
			}
		} else {
			break;
		}
	}
	if (negflg) {
		lcval = -lcval;
	}
	if (c != EOF) {
		ungetc(c, fp);

		*eofptr = 0;
	} else {
		*eofptr = 1;
	}
 	if (ptr == NULL || np == numbuf || (negflg && np == numbuf+1) ) {
		return(0);
	}
................................................................................
	}
	return((char *)s);
}

int
_doscan(FILE *fp, const char *fmt, void *argp2)
{
	int ch;
	int nmatch, len, ch1;
	int **ptr, fileended, size;
	void **argp = argp2;

	nmatch = 0;
	fileended = 0;
	for (;;) switch (ch = *fmt++) {
	case '\0': 
		return (nmatch);
................................................................................
		} else if (ch=='[') {
			fmt = getccl((unsigned char *)fmt);
		}
		if (isupper(ch)) {
			ch = tolower(ch);
			size = LONG;
		}
		if (ch == '\0')
			return(-1);








		if (innum(ptr, ch, len, size, fp, &fileended) && ptr) {

			nmatch++;
		}
		if (fileended) {
			return(nmatch? nmatch: -1);
		}
		break;

	case ' ':
	case '\n':
	case '\t': 
		while ((ch1 = getc(fp))==' ' || ch1=='\t' || ch1=='\n')
			;






		if (ch1 != EOF)
			ungetc(ch1, fp);


		break;

	default: 
	def:
		ch1 = getc(fp);

		if (ch1 != ch) {
			if (ch1==EOF)
				return(-1);
			ungetc(ch1, fp);
			return(nmatch);
		}
	}







|
>







 







|
<
>
>
>
>













|
>
>




>







 







|
>









|







 







|
>
>
>
>
>



|
>
>



|
>
|
>
|







 







|
>
>












>







 







<
<
|







 







|

>
>
>
>
>
>
>
>
|
>










|
<
>
>
>
>
>
>
|

>
>





>







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
..
64
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
...
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
...
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
...
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
...
278
279
280
281
282
283
284


285
286
287
288
289
290
291
292
...
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345

346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
	SPC,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,
};

static int
instr(char *ptr, int type, int len, FILE *fp, int *eofptr,
	int *nreadp)
{
	int ch;
	char *optr;
	int ignstp;

	*eofptr = 0;
	optr = ptr;
................................................................................
	if (type=='c' && len==30000) {
		len = 1;
	}
	ignstp = 0;
	if (type == 's') {
		ignstp = SPC;
	}
	while ((ch = getc(fp)) != EOF) {

		*nreadp += 1;
		if (!(_sctab[ch] & ignstp)) {
			break;
		}
	}
	ignstp = SPC;
	if (type=='c')
		ignstp = 0;
	else if (type=='[')
		ignstp = STP;
	while (ch != EOF && (_sctab[ch]&ignstp)==0) {
		if (ptr) {
			*ptr++ = ch;
		}
		if (--len <= 0) {
			break;
		}
		if ((ch = getc(fp)) != EOF) {
			*nreadp += 1;
		}
	}
	if (ch != EOF) {
		if (len > 0) {
			ungetc(ch, fp);
			*nreadp -= 1;
		}
		*eofptr = 0;
	} else {
		*eofptr = 1;
	}
	if (ptr && ptr!=optr) {
		if (type != 'c') {
................................................................................
		}
		return(1);
	}
	return(0);
}

static int
innum(int **ptr, int type, int len, int size, FILE *fp,
	int *eofptr, int *nreadp)
{
	char *np;
	char numbuf[64];
	int c, base;
	int expseen, scale, negflg, c1, ndigit;
	long lcval;

	if (type=='c' || type=='s' || type=='[') {
		return(instr(ptr ? *(char **)ptr :
			(char *)NULL, type, len, fp, eofptr, nreadp));
	}
	lcval = 0;
	ndigit = 0;
	scale = INT;
	if (type=='e'||type=='f') {
		scale = FLOAT;
	}
................................................................................
		base = 8;
	} else if (type=='x') {
		base = 16;
	}
	np = numbuf;
	expseen = 0;
	negflg = 0;
	while ((c = getc(fp)) != EOF) {
		*nreadp += 1;
		if ((c != ' ') && (c != '\t') && (c != '\n')) {
			break;
		}
	}
	if (c=='-') {
		negflg++;
		*np++ = c;
		if ((c = getc(fp)) != EOF) {
			*nreadp += 1;
		}
		len--;
	} else if (c=='+') {
		len--;
		if ((c = getc(fp)) != EOF) {
			*nreadp += 1;
		}
	}
	for ( ; --len>=0; *np++ = c, c = getc(fp), ++*nreadp) {
		if (isdigit(c)
		 || base==16 && ('a'<=c && c<='f' || 'A'<=c && c<='F')) {
			ndigit++;
			if (base == 8) {
				lcval <<=3;
			} else if (base==10) {
				lcval = ((lcval<<2) + lcval)<<1;
................................................................................
			continue;
		} else if ((c=='e'||c=='E') && expseen==0) {
			if (base != 10 || scale == INT || ndigit == 0) {
				break;
			}
			expseen++;
			*np++ = c;
			if ((c = getc(fp)) != EOF) {
				*nreadp += 1;
			}
			if (c!='+'&&c!='-'&&('0'>c||c>'9')) {
				break;
			}
		} else {
			break;
		}
	}
	if (negflg) {
		lcval = -lcval;
	}
	if (c != EOF) {
		ungetc(c, fp);
		*nreadp -= 1;
		*eofptr = 0;
	} else {
		*eofptr = 1;
	}
 	if (ptr == NULL || np == numbuf || (negflg && np == numbuf+1) ) {
		return(0);
	}
................................................................................
	}
	return((char *)s);
}

int
_doscan(FILE *fp, const char *fmt, void *argp2)
{


	int ch, nmatch, len, ch1, **ptr, fileended, size, nread = 0;
	void **argp = argp2;

	nmatch = 0;
	fileended = 0;
	for (;;) switch (ch = *fmt++) {
	case '\0': 
		return (nmatch);
................................................................................
		} else if (ch=='[') {
			fmt = getccl((unsigned char *)fmt);
		}
		if (isupper(ch)) {
			ch = tolower(ch);
			size = LONG;
		}
		if (ch == '\0') {
			return(-1);
		}
		if (ch == 'n') {
			if (ptr) {
				**ptr = nread;
				nmatch += 1;
			}
			break;
		}
		if (innum(ptr, ch, len, size, fp, &fileended, &nread) &&
				ptr) {
			nmatch++;
		}
		if (fileended) {
			return(nmatch? nmatch: -1);
		}
		break;

	case ' ':
	case '\n':
	case '\t': 
		while ((ch1 = getc(fp)) != EOF) {

			nread += 1;
			if ((ch1 != ' ') && (ch1 != '\t') &&
					(ch1 != '\n')) {
				break;
			}
		}
		if (ch1 != EOF) {
			ungetc(ch1, fp);
			nread -= 1;
		}
		break;

	default: 
	def:
		ch1 = getc(fp);
		nread += 1;
		if (ch1 != ch) {
			if (ch1==EOF)
				return(-1);
			ungetc(ch1, fp);
			return(nmatch);
		}
	}