original netbsd's tr(1)
[minix.git] / commands / zoneinfo / scheck.c
blob9a37c2beebb216c57300ef53f967b7e5d8879fdc
3 /*LINTLIBRARY*/
5 #include <string.h>
6 #include <stdlib.h>
8 #include "stdio.h"
10 #ifndef lint
11 #ifndef NOID
12 static char sccsid[] = "@(#)scheck.c 7.15";
13 #endif /* !NOID */
14 #endif /* !lint */
16 #include "ctype.h"
17 #include "private.h"
19 const char *
20 scheck(string, format)
21 const char * string;
22 const char * format;
24 register char * fbuf;
25 register char * fp;
26 register char * tp;
27 register int c;
28 register char * result;
29 char dummy;
31 result = "";
32 if (string == NULL || format == NULL)
33 return result;
34 fbuf = imalloc(2 * strlen(format) + 4);
35 if (fbuf == NULL)
36 return result;
37 fp = (char *) format;
38 tp = (char *) fbuf;
39 while ((*tp++ = c = *fp++) != '\0') {
40 if (c != '%')
41 continue;
42 if (*fp == '%') {
43 *tp++ = *fp++;
44 continue;
46 *tp++ = '*';
47 if (*fp == '*')
48 ++fp;
49 while (isascii(*fp) && isdigit(*fp))
50 *tp++ = *fp++;
51 if (*fp == 'l' || *fp == 'h')
52 *tp++ = *fp++;
53 else if (*fp == '[')
54 do *tp++ = *fp++;
55 while (*fp != '\0' && *fp != ']');
56 if ((*tp++ = *fp++) == '\0')
57 break;
59 *(tp - 1) = '%';
60 *tp++ = 'c';
61 *tp = '\0';
62 if (sscanf(string, fbuf, &dummy) != 1)
63 result = (char *) format;
64 free(fbuf);
65 return result;