1: #include <stdio.h>
   2: #include <sys/types.h>
   3: #include <sys/stat.h>
   4: #include "bm.h"
   5: int
   6: GetPatFile(PatFile, DescVec)
   7: char *PatFile;
   8: struct PattDesc *DescVec[];
   9: /* read patterns from a file and set up a pattern descriptor vector */
  10: {
  11:     extern char *malloc();
  12:     FILE *PFile;
  13:     struct stat StatBuff;
  14:     int PatSize; /* the number of chars in all the patterns */
  15:     char *PatBuff; /* hold the patterns */
  16:     if (!(PFile = fopen(PatFile,"r"))) {
  17:         fprintf(stderr,"bm: can't open pattern file %s\n",PatFile);
  18:         exit(2);
  19:     } /* if */
  20:     /* find out how big the patterns are */
  21:     if (fstat(fileno(PFile),&StatBuff) == -1) {
  22:         fprintf(stderr,"bm: can't fstat %s\n",PatFile);
  23:         exit(2);
  24:     } /* if */
  25:     PatSize = StatBuff.st_size;
  26:     if (!PatSize) {
  27:         fprintf(stderr,"bm: pattern file is empty\n");
  28:         exit(2);
  29:     } /* if */
  30:     if (!(PatBuff = malloc(PatSize))) {
  31:            fprintf(stderr,"bm: insufficient memory to store patterns\n");
  32:         exit(2);
  33:     } /* if */
  34:     fread(PatBuff,1,PatSize,PFile); /* get the patterns */
  35:     /* make sure the patterns are null-terminated. We can't have
  36: 	* nulls in the patterns */
  37:     if (PatBuff[PatSize-1] == '\n')
  38:         PatBuff[PatSize-1] = '\0';
  39:     else
  40:         PatBuff[PatSize] = '\0';
  41:     return(MkDescVec(DescVec,PatBuff));
  42: } /* GetPatFile */

Defined functions

GetPatFile defined in line 5; used 1 times
Last modified: 1985-09-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2854
Valid CSS Valid XHTML 1.0 Strict