Files
amiga-tz/scheck.c
T

64 lines
1.2 KiB
C
Raw Normal View History

2006-07-17 10:12:13 -04:00
/*
** This file is in the public domain, so clarified as of
** 2006-07-17 by Arthur David Olson.
*/
1988-02-17 20:02:19 -05:00
#ifndef lint
#ifndef NOID
1988-02-12 16:59:10 -05:00
static char elsieid[] = "%W%";
1988-02-17 20:02:19 -05:00
#endif /* !defined lint */
#endif /* !defined NOID */
1985-11-16 13:38:19 -05:00
1988-02-17 22:22:44 -05:00
/*LINTLIBRARY*/
1989-03-21 11:37:09 -05:00
#include "private.h"
1988-02-18 08:58:49 -05:00
2006-01-10 13:25:36 -05:00
const char *
1986-03-05 18:40:08 -05:00
scheck(string, format)
1989-02-20 20:44:23 -05:00
const char * const string;
2006-01-10 13:25:36 -05:00
const char * const format;
1985-11-16 13:38:19 -05:00
{
1988-02-18 08:58:49 -05:00
register char * fbuf;
register const char * fp;
register char * tp;
register int c;
2006-01-10 13:25:36 -05:00
register const char * result;
1988-02-18 08:58:49 -05:00
char dummy;
1985-11-16 13:38:19 -05:00
2006-01-10 13:25:36 -05:00
result = "";
1985-11-16 13:38:19 -05:00
if (string == NULL || format == NULL)
1986-03-06 09:31:07 -05:00
return result;
1994-06-07 15:20:56 -04:00
fbuf = imalloc((int) (2 * strlen(format) + 4));
1986-12-25 18:08:29 -05:00
if (fbuf == NULL)
1986-03-06 09:31:07 -05:00
return result;
1985-11-16 13:38:19 -05:00
fp = format;
tp = fbuf;
while ((*tp++ = c = *fp++) != '\0') {
if (c != '%')
continue;
if (*fp == '%') {
*tp++ = *fp++;
continue;
}
1985-11-17 20:30:59 -05:00
*tp++ = '*';
1985-11-16 13:38:19 -05:00
if (*fp == '*')
1985-11-17 20:30:59 -05:00
++fp;
1995-10-30 10:20:05 -05:00
while (is_digit(*fp))
1985-11-16 13:38:19 -05:00
*tp++ = *fp++;
1986-03-06 09:31:07 -05:00
if (*fp == 'l' || *fp == 'h')
1985-11-16 13:38:19 -05:00
*tp++ = *fp++;
else if (*fp == '[')
do *tp++ = *fp++;
while (*fp != '\0' && *fp != ']');
if ((*tp++ = *fp++) == '\0')
break;
}
1986-03-06 09:31:07 -05:00
*(tp - 1) = '%';
*tp++ = 'c';
1987-02-10 19:48:14 -05:00
*tp = '\0';
1986-03-06 09:31:07 -05:00
if (sscanf(string, fbuf, &dummy) != 1)
1989-02-20 20:44:23 -05:00
result = (char *) format;
1988-02-12 16:59:10 -05:00
ifree(fbuf);
1985-11-16 13:38:19 -05:00
return result;
}