home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / FIXFIL10.ZIP / FIXFILE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-03  |  2.7 KB  |  89 lines

  1. /* this program modifies files.ra of RA 2.5x so that older RA2.0x utilities
  2.    can still work.
  3.  
  4.    Whenever the file areas have been altered (inserted/deleted/moved/renamed
  5.    areas) follow these steps:
  6.  
  7.    1. Run this program. It will create a new, compatible FILES.RA, rename the
  8.       old file FILES.OLD, and delete the FILES.RDX file.
  9.    2. Run RACONFIG and go the the file area manager. This will cause a new
  10.       FILES.RDX to be created.
  11.    3. When you are satisfied everything is working, delete the FILES.OLD.
  12.  
  13.    This program will not run if FILES.OLD exists or FILES.RDX is missing.
  14.  
  15.    Note -- FILES.RA will have as many records as the largest used file area
  16.    number. It's not a good idea to use large area numbers unless you need
  17.    to do so!
  18.  
  19.    IMPORTANT -- Area #0 is not supported.
  20.  
  21. */
  22. #include <stdio.h>
  23. #include "ra250.h"
  24.  
  25. void main(void) {
  26.     FILES buff, nobuf={0};
  27.     FILE *rdx, *ra, *ranew;
  28.     unsigned areanum, offset=1;
  29.  
  30.     fprintf(stderr, "Fix Filebase for RemoteAccess 2.5x\n"
  31.             "You should read the instructions before using!\n\n");
  32.  
  33.     if (fopen("files.old", "rb") != NULL) {
  34.         fprintf(stderr, "Delete the old database file, FILES.OLD before running.\n");
  35.         return;
  36.     }
  37.     if ((rdx = fopen("files.rdx", "rb")) == NULL) {
  38.         fprintf(stderr, "The file FILES.RDX must exist to run this program.\n"
  39.                 "Run RACONFIG and enter the file area manager to re-create.\n");
  40.         return;
  41.     }
  42.     if ((ra = fopen("files.ra", "rb")) == NULL) {
  43.         fprintf(stderr, "The FILES.RA file is missing! You are in big trouble.\n");
  44.         return;
  45.     }
  46.     if ((ranew = fopen("newfiles.$$$", "wb")) == NULL) {
  47.         fprintf(stderr, "I can't create the temporary file NEWFILES.$$$\n");
  48.         return;
  49.     }
  50.  
  51.     while (fread(&areanum, sizeof(unsigned int), 1, rdx) > 0) {
  52.         if (areanum != 0) {
  53.             printf("New area %d from original position %d\n",
  54.                     offset, areanum);
  55.             
  56.             /* got a live one! */
  57.             fseek(ra, sizeof(FILES)*(areanum-1), SEEK_SET);
  58.             if (fread(&buff, sizeof(FILES), 1, ra) != 1) {
  59.                 fprintf(stderr,"There's a problem reading FILES.RA -- aborting\n");
  60.                 return;
  61.             }
  62.             buff.AreaNum = offset++;
  63.             if (fwrite(&buff, sizeof(FILES), 1, ranew) < 1) {
  64.                 fprintf(stderr, "Disk full -- aborting\n");
  65.                 return;
  66.             }
  67.         }
  68.         else {
  69.             /* empty area */
  70.             printf("Empty area %d\n", offset);
  71.             nobuf.AreaNum = offset++;
  72.             if (fwrite(&nobuf, sizeof(FILES), 1, ranew) < 1) {
  73.                 fprintf(stderr, "Disk full -- aborting\n");
  74.                 return;
  75.             }
  76.         }
  77.     }
  78.     fclose(rdx);
  79.     fclose(ra);
  80.     fclose(ranew);
  81.     if(rename("files.ra", "files.old") != 0) {
  82.         fprintf(stderr, "Darn, so close! I can't rename the original FILES.RA file -- aborting.\n");
  83.         return;
  84.     }
  85.     rename("newfiles.$$$", "files.ra");
  86.     remove("files.rdx");
  87. }
  88.  
  89.