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