home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / DEVBBS.ZIP / USERLST.C < prev    next >
C/C++ Source or Header  |  1992-08-04  |  2KB  |  68 lines

  1. #include <stdio.h>
  2. #include <io.h>
  3. #include <fcntl.h>
  4. #include <sys\stat.h>
  5. #include "vardec.h"
  6.  
  7. int exist(char *string)
  8. {
  9.   int f;
  10.  
  11.   f=open(string,O_RDONLY | O_BINARY);
  12.   close(f);
  13.   if (f>0)
  14.     return(1);
  15.   else
  16.     return(0);
  17. }
  18.  
  19. main(int argc, char *argv[])
  20. {
  21.   int binfile;
  22.   FILE *txtfile;
  23.   userrec u;
  24.   unsigned int loop,num=0;
  25.   unsigned long len;
  26.   char s[81],s1[81];
  27.  
  28.   if (argc<3) {
  29.     puts("\nRequires TWO parameters.\n");
  30.     puts("USERLST [path to USER.LST] [dest filename & path]\n");
  31.     abort();
  32.   }
  33.   if ((binfile=open(argv[1],O_RDWR|O_BINARY,S_IREAD|S_IWRITE))<=0) {
  34.     puts("\nCould not open USER.LST\n");
  35.     close(binfile);
  36.     abort();
  37.   }
  38.   if (exist(argv[2])) {
  39.     printf("\nCould not open output file %s.  Same file exists.\n",argv[1]);
  40.     abort();
  41.   }
  42.   if (binfile<0) {
  43.     puts("\nNo users to process!\n");
  44.     close(binfile);
  45.     abort();
  46.   }
  47.   txtfile=fopen(argv[2],"a+");
  48.   len=filelength(binfile);
  49.   num=(len/sizeof(userrec))+!(len%sizeof(userrec));
  50.   for (loop=1; loop<num; ++loop) {
  51.     printf("\015Processing user #%u of %u",loop,num);
  52.     read(binfile,&u,sizeof(userrec));
  53.     if (u.inact == 0) {
  54.     sprintf(s,"%s c/o %s %s\n",u.name,u.realname,u.lastname);
  55.     fputs(s,txtfile);
  56.     sprintf(s,"%s\n",u.stretadd);
  57.     fputs(s,txtfile);
  58.     sprintf(s,"%s\n",u.citstate);
  59.     fputs(s,txtfile);
  60.     sprintf(s,"   %s\n",u.zipcode);
  61.     fputs(s,txtfile);
  62.       fputs("\r\n",txtfile);
  63.     }
  64.   }
  65.   close(binfile);
  66.   fclose(txtfile);
  67.   return(0);
  68.   }