home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / mbprg100.zip / MBPURGE.C < prev    next >
C/C++ Source or Header  |  1995-08-29  |  5KB  |  163 lines

  1. #define RDS_TITLE     "MBPURGE"                 /*  Program Name      */
  2. #ifdef __OS2__
  3.   #undef  RDS_TITLE
  4.   #define RDS_TITLE   "MBPURGEP"                /*  Program Name      */
  5. #endif
  6. #define RDS_DATES     "1995"                    /*  Copyright Date    */
  7. #define RDS_VERSION   "1.00"                    /*  Version Number    */
  8.  
  9. /******************************************************************************
  10. *******************************************************************************
  11. **
  12. **          Copyright (c) Bob Swift, 1995.  All Rights Reserved.
  13. **
  14. **   This program is used to read the MEXBANK.DAT file generated by MexBank
  15. **   and remove any users not found in the Maximus USER.BBS file.  Both files
  16. **   must be in the current directory.
  17. **
  18. **   The program is used as follows:
  19. **
  20. **                       MBPURGE [?]        for DOS version
  21. **
  22. **                          or
  23. **
  24. **                       MBPURGEP [?]       for OS/2 version
  25. **
  26. **   The program will display a VERY brief set of instructions if it is called
  27. **   with a question mark, or if it encounters an error.  The following is a
  28. **   list of the error codes returned by the program:
  29. **
  30. **             0 - No errors.  Normal termination.
  31. **             1 - Extra command line arguments.
  32. **             2 - Error creating MEXBANK.BAK backup file.
  33. **             3 - Error reading USER.BBS input file.
  34. **             4 - Error reading MEXBANK.DAT input file.
  35. **             5 - Error writing MEXBANK.DAT output file.
  36. **
  37. **   When an error is encountered, the program will exit immediately and will
  38. **   attempt to properly close all files.
  39. **
  40. *******************************************************************************
  41. *******************************************************************************
  42. **
  43. **   Revision History
  44. **   ----------------
  45. **
  46. **   1.00     95/08/29    First release version.
  47. **
  48. *******************************************************************************
  49. ******************************************************************************/
  50.  
  51. #include <stdio.h>
  52. #include <stdlib.h>
  53. #include <string.h>
  54. #include <fcntl.h>
  55. #include <sys\types.h>
  56. #include <sys\stat.h>
  57. #ifdef __OS2__
  58.   #include <os2.h>
  59. #endif
  60. #include "max_u.h"
  61.  
  62.  
  63. void helpscrn(int ernum, int instruct);
  64.  
  65. /*******************************************************************/
  66.  
  67. void main(int argc, char *argv[])
  68. {
  69.  
  70. FILE *in_max, *in_tb, *out_tb;
  71. static struct _usr user_data;
  72. char inline[128],temp[128],temp1[80];
  73. struct stat buf;
  74. int i;
  75.  
  76. printf("\n\n%s Version %s\n",RDS_TITLE,RDS_VERSION);
  77. printf("Copyright (c) Bob Swift, %s.  All Rights Reserved.\n\n",RDS_DATES);
  78.  
  79. if (argc > 1) helpscrn(1,1);
  80.  
  81. remove("mexbank.bak");
  82.  
  83. if (rename("mexbank.dat","mexbank.bak") != 0) helpscrn(2,1);
  84.  
  85. if ((in_max=fopen("user.bbs","rb")) == NULL) helpscrn(3,1);
  86.  
  87. if ((in_tb=fopen("mexbank.bak","rt")) == NULL) helpscrn(4,1);
  88.  
  89. if ((out_tb=fopen("mexbank.dat","wt")) == NULL) helpscrn(5,1);
  90.  
  91. while (fgets(inline,128,in_tb) != NULL)
  92.   {
  93.   strcpy(temp,inline);
  94.   temp[35] = '\0';
  95.   printf("\rChecking:  %s",temp);
  96.   rewind(in_max);
  97.   i = 0;
  98.   while (i == 0)
  99.     {
  100.     if (fread(&user_data,sizeof(struct _usr),1,in_max) != 1)
  101.       {
  102.       i = 1;
  103.       printf("\r%-79s\rPurged:  %s\n"," ",temp);
  104.       }
  105.     strcpy(temp1,user_data.name);
  106.     strcat(temp1,"                                   ");
  107.     temp1[35] = '\0';
  108.     if (i == 0)
  109.       {
  110.       if (strcmpi(temp1,temp) == 0)
  111.         {
  112.         i = 1;
  113.         if (fputs(inline,out_tb) == EOF) helpscrn(5,0);
  114.         }
  115.       }
  116.     }
  117.   }
  118.  
  119. fclose(in_max);
  120. fclose(in_tb);
  121. fclose(out_tb);
  122.  
  123. printf("\r%79s"," ");
  124. printf("\nComplete.  Thank-you for using %s.\n\n",RDS_TITLE);
  125. exit(0);
  126. }
  127.  
  128. /*******************************************************************/
  129.  
  130. void helpscrn(int ernum, int instruct)
  131. /*  Here are the error messages and VERY brief instructions  */
  132. {
  133. printf("\n");
  134. switch (ernum) {
  135.  
  136. /* case  1 : printf("Bad or missing command line argument\n\n"); */
  137. /*           break;                                              */
  138.  
  139. case  2 : printf("ERROR creating MEXBANK.BAK backup file.\n\n");
  140.           break;
  141.  
  142. case  3 : printf("ERROR reading USER.BBS input file.\n\n");
  143.           break;
  144.  
  145. case  4 : printf("ERROR reading MEXBANK.DAT input file.\n\n");
  146.           break;
  147.  
  148. case  5 : printf("ERROR writing MEXBANK.DAT output file.\n\n");
  149.           break;
  150.     }
  151.  
  152. if (instruct != 0)
  153.   {
  154.   printf("This program is used to read the MEXBANK.DAT file generated by MexBank\n");
  155.   printf("and remove any users not found in the Maximus USER.BBS file.  Both files\n");
  156.   printf("must be in the current directory.\n\nThe program is used as follows:   ");
  157.   printf("%s [?]\n\n",RDS_TITLE);
  158.   }
  159.  
  160. exit(ernum);
  161. }
  162.  
  163.