home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume6 / newbatcha / bst.c next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.1 KB  |  62 lines

  1. /*
  2.  *    bst.c - a utility for indicating how many
  3.  *        news articles are ready for batching
  4.  *        for each site in the BACTHDIR directory.
  5.  *
  6.  *    R.J. Esposito
  7.  *    Bell of Penna.
  8.  *    June 1986
  9.  *
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <sys/types.h>
  14. #include <sys/stat.h>
  15. #include <sys/dir.h>
  16.  
  17.  
  18. char buf[512];
  19. FILE *dd;
  20. struct direct dp;
  21. struct stat st;
  22.  
  23. main()
  24. {
  25.     int fd, j;
  26.     int bcnt, lcnt;
  27.  
  28.     if(chdir(BATCHDIR) != 0) {
  29.         perror(BATCHDIR);
  30.         exit(1);
  31.     }
  32.  
  33.     if((dd=fopen(".", "r")) == NULL) {
  34.         printf("can't open %s\n", BATCHDIR);
  35.         exit(1);
  36.     }
  37.  
  38.     while((fread((char *)&dp, sizeof(dp), 1, dd)) == 1) {
  39.         if(dp.d_ino == 0 || dp.d_name[0] == '.')
  40.             continue;
  41.         if(stat(dp.d_name, &st) != 0) {
  42.             printf("can't stat %s\n", dp.d_name);
  43.             exit(1);
  44.         }
  45.         if(st.st_size <= 0 )
  46.             continue;
  47.         if((fd=open(dp.d_name, 0)) < 0) {
  48.             printf("can't open %s\n", dp.d_name);
  49.             exit(1);
  50.         }
  51.         lcnt = 0;
  52.         while((bcnt=read(fd,buf,512)) > 0) {
  53.             for(j=0; j<=bcnt; j++)
  54.                 if(buf[j] == '\n')
  55.                     lcnt += 1;
  56.         }
  57.         close(fd);
  58.         printf("%s\t  %d article", dp.d_name, lcnt);
  59.         printf("%c\n", lcnt > 1 ? 's' : ' ');
  60.     }
  61. }
  62.