home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / inspect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-27  |  1.7 KB  |  72 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: inspect.c,v 1.5 1995/10/27 00:05:15 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    inspect.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    17 Nov 1984
  9.  * Last update:
  10.  *        26 Oct 1995, mods for DEC-C (long/unsigned/int)
  11.  *        15 Jun 1985, typed 'ropen'
  12.  *        04 Feb 1985, block-encrypted files do not have proper record
  13.  *                 structure and so will exit immediately with
  14.  *                 an error/end-of-file.  Forgot to check for null
  15.  *                 file.
  16.  *
  17.  * Function:    Read the beginning of a specified file, to see if it seems
  18.  *        to be ordinary source-text.  If so, return TRUE.  We accept
  19.  *        any combination of the normal "printing" set, or the VAX/VMS
  20.  *        "space" characters (space, tab, line feed, carriage return or
  21.  *        form feed).
  22.  *
  23.  * Arguments:    filespec - null-ended string defining file name.
  24.  *        toscan     - minimum number of characters to scan (unless we
  25.  *               get an end-of-file first).
  26.  *
  27.  * Returns:    TRUE iff all scanned characters are as expected, and if the
  28.  *        longest-record length is reasonable.
  29.  */
  30.  
  31. #include    <ctype.h>
  32.  
  33. #include    "bool.h"
  34. #include    "rmsio.h"
  35.  
  36. #define    LEGAL(c) (isascii(c) && ((c == '\b') || isspace(c) || isprint(c)))
  37.  
  38. int    inspect (char *filespec, int toscan)
  39. {
  40.     int    j, c, lenr,
  41.         success    = FALSE;
  42.     unsigned mark;
  43.     RFILE    *file_    = ropen (filespec, "r");
  44.     char    z[1024];
  45.  
  46.     /*
  47.      * We need at least one non-null record, with all legal-characters.
  48.      */
  49.     if (file_)
  50.     {
  51.         if (rsize(file_) < sizeof(z))
  52.         {
  53.             while ((lenr = rgetr(file_, z, sizeof(z), &mark)) >= 0)
  54.             {
  55.                 for (j = 0; j < lenr; j++)
  56.                 {
  57.                     c = z[j];
  58.                     if (! LEGAL(c))
  59.                     {
  60.                         success = FALSE;
  61.                         goto done;
  62.                     }
  63.                 }
  64.                 if (mark > toscan)    break;
  65.                 success    = TRUE;
  66.             }
  67.         }
  68. done:        rclose (file_);
  69.     }
  70.     return (success);
  71. }
  72.