home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / mrl1.zip / scan.c < prev    next >
C/C++ Source or Header  |  1995-09-12  |  1KB  |  57 lines

  1. #include <stdlib.h>
  2. #include <malloc.h>
  3. #include <io.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <dirent.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10.  
  11. #include "mrl.h"
  12.  
  13. int Scan(const char *dir)
  14.   DIR *mdir;
  15.   struct dirent *pol;
  16.   unsigned char *tmp;
  17.   if(!(tmp=malloc(MAXNAMLEN))) 
  18.          { WriteLog(logname," Malloc error in Scan",'!');return -1;}
  19.   if(!(mdir=opendir(dir))) 
  20.    { 
  21.      sprintf(tmp,"opendir %s failed",dir);
  22.      WriteLog(logname,tmp,'!');
  23.      free(tmp);
  24.      return -1;}
  25.   rewinddir(mdir);
  26.   while((pol=readdir(mdir)))
  27.   {
  28.     strupr(pol->d_name);
  29.     if (!strcmp("LASTREAD",pol->d_name))  
  30.       { /*Read Last-read pointer in low-hi byte order */
  31.         int i;
  32.         strcpy(tmp,dir);
  33.         strcat(tmp,"\\");
  34.         strcat(tmp,pol->d_name);
  35.         i=open(tmp,O_RDONLY|O_BINARY);
  36.         if(i!=-1) {
  37.                    if(-1!=read(i,tmp,2)) toINT(tmp,&mlast);
  38.                      close(i);
  39.                   }
  40.       } 
  41.     if (strstr(pol->d_name,".MSG"))
  42.       { 
  43.         mmsgs++;
  44.         strncpy(tmp,pol->d_name,strlen(pol->d_name)-4);
  45.         *(tmp+strlen(pol->d_name)-4)='\0';
  46.         if(atoi(tmp)>mmax) {
  47.                 mmax=atoi(tmp);
  48.             }
  49.         if((atoi(tmp)<mmin)&&(atoi(tmp)!=0)) mmin=atoi(tmp);
  50.       }
  51.   }
  52.   closedir(mdir);
  53.   free(tmp);
  54.   return 0;
  55. }  
  56.