home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / libz / scheck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-23  |  1.1 KB  |  65 lines

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