Debian Codegraph @

COSMIC/strnxtfmt.c

raw
1 #include <stdio.h>
2 #include <ctype.h>
3 #include "xtdio.h"
4
5 /* ----------------------------------------------------------------------
6 * Local Definitions:
7 */
8 #define BUFSIZE 256
9
10 /* ---------------------------------------------------------------------- */
11
12 /* strnxtfmt: this function returns a pointer to the end of a format code
13 *
14 * Use:
15 * strnxtfmt(fmt) : initialize and return first single format code string
16 * strnxtfmt((char *) NULL) : use previous fmt string
17 *
18 * Returns a pointer to a single format until no more single formats are
19 * left, in which case a NULL pointer is returned.
20 */
21 #ifdef __PROTOTYPE__
22 char *strnxtfmt(char *fmt)
23 #else /* __PROTOTYPE__ */
24 char *strnxtfmt(fmt)
25 char *fmt;
26 #endif /* __PROTOTYPE__ */
27 {
28 char *lb;
29 static char locbuf[BUFSIZE];
30 static char *f=NULL;
31
32
33 /* select format string to be processed */
34 if(!fmt) fmt= f;
35 else f = fmt;
36
37 if(!fmt || !*fmt) {
38 return (char *) NULL;
39 }
40
41 /* Set up a single format string from the fmt variable */
42 for(lb= locbuf; *fmt; ++fmt) {
43 if(*fmt == '%') {
44 if(fmt[1] == '%') { /* enter %% pairs into locbuf directly */
45 *lb++ = *fmt;
46 *lb++ = *++fmt;
47 }
48 else { /* decipher format code: [0-9.hlL\-]*[a-zA-Z] */
49 for(*lb++= *fmt++; *fmt; ++fmt) {
50 if(isdigit(*fmt) ||
51 *fmt == 'l' || *fmt == 'L' || *fmt == 'h' ||
52 *fmt == '-' || *fmt == '.') *lb++= *fmt;
53 else break;
54 }
55 if(*fmt) *lb++ = *fmt++;/* more fmt to be available */
56 else *lb = '\0'; /* end of fmt string encountered */
57 break;
58 }
59 }
60 else *(lb++)= *fmt;
61 }
62 *lb= '\0'; /* terminate locbuf properly */
63
64 /* read strnxtfmt for next call */
65 f= fmt;
66
67 return locbuf;
68 }
69
70 /* ----------------------------------------------------------------------- */
71