home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume4 / settz / scheck.c < prev    next >
C/C++ Source or Header  |  1986-11-30  |  1KB  |  71 lines

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