home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / bbs_opus / chgarea.arj / CHGAREA.C next >
C/C++ Source or Header  |  1991-07-20  |  4KB  |  94 lines

  1. /*--------------------------------------------------------------------------*/
  2. /* CHGAREA.COM:                                                             */
  3. /*                                                                          */
  4. /* This is just a dumb little program to quickly move all the listings      */
  5. /* for one area in FILESBBS.DAT to another area, that is, if you have       */
  6. /* an existing file area 23, and decide you want to move that area to       */
  7. /* area 30, you can just run:                                               */
  8. /*                                                                          */
  9. /*  chgarea 23 30                                                           */
  10. /*                                                                          */
  11. /* And everything that used to be associated with file area 23 in your      */
  12. /* FILESBBS database will now know that its in file area 30. Then all       */
  13. /* you have to do is edit your CTL file to create the new file area 30.     */
  14. /*                                                                          */
  15. /* CHGAREA.COM will only work when it's in the same directory as            */
  16. /* FILESBBS.DAT and FILESBBS.ADX.                                           */
  17. /*                                                                          */
  18. /*                                        Doug Boone FidoNet 1:119/5        */
  19. /*--------------------------------------------------------------------------*/
  20. #include   <stdio.h>
  21. #include   <io.h>
  22. #include   <fcntl.h>
  23. #include   <stdlib.h>
  24. #include   "opus.h"
  25. #include   "system.h"
  26. #include   "nfile.h"
  27.  
  28. void usage(void);
  29.  
  30. void cdecl main(int argc,char *argv[])
  31. {
  32.    struct  _afile  afile;
  33.    struct  _numb_idx   numbers;
  34.    long    skip;
  35.    int     fh;
  36.    int     oldarea;
  37.    int     newarea;
  38.  
  39.    if (argc<3) 
  40.        usage();
  41.    oldarea = atoi(argv[1]);
  42.    newarea = atoi(argv[2]);
  43.  
  44.    if (oldarea == newarea)
  45.        usage();
  46.  
  47.    if ((fh = open("FILESBBS.ADX",O_BINARY|O_RDWR)) < 0)
  48.        usage();
  49.    while (read(fh,(char *)&numbers,sizeof(struct _numb_idx)) == sizeof(struct _numb_idx)) {
  50.        if (newarea == numbers.area_number) {        /* Make sure new area doesn't already exist! */
  51.            close(fh);
  52.            usage();
  53.            }
  54.        }
  55.    lseek(fh,0L,SEEK_SET);
  56.    while (read(fh,(char *)&numbers,sizeof(struct _numb_idx)) == sizeof(struct _numb_idx)) {
  57.        if (oldarea == numbers.area_number) {
  58.            numbers.area_number = newarea;        /* Update FILESBBS.ADX */
  59.            lseek(fh,-((long)(sizeof(struct _numb_idx))),SEEK_CUR);
  60.            write(fh,(char *)&numbers,sizeof(struct _numb_idx));
  61.            close(fh);
  62.            fh = open("FILESBBS.DAT",O_BINARY|O_RDWR);
  63.            lseek(fh,numbers.pos,SEEK_SET);
  64.            while (read(fh,(char*)&afile,sizeof(struct _afile)) == sizeof(struct _afile)) {
  65.                if (afile.area_number == oldarea) {
  66.                    afile.area_number = newarea;
  67.                    if (afile.name[0] > ' ')
  68.                        printf("\nMoving %14s from area %d to area %d",afile.name,oldarea,newarea);
  69.                    lseek(fh,-((long)(sizeof(struct _afile))),SEEK_CUR);
  70.                    write(fh,(char*)&afile,sizeof(struct _afile));
  71.                    skip = (long) afile.descr_len;
  72.                    skip += (long) afile.altpath_len;
  73.                    skip += (long) afile.upld_by_len;
  74.                    lseek(fh,skip,SEEK_CUR);
  75.                    }
  76.                }        /* End of FILESBBS.DAT */
  77.            close(fh);
  78.            exit(0);
  79.            }
  80.        }
  81.    printf("\nDidn't find area %d in FILESBBS.ADX!\n",oldarea);
  82.    usage();
  83. }
  84.  
  85.  
  86.  
  87. void usage(void)
  88. {
  89.    printf("\n\nCHGAREA.EXE\n\n\tChanges the area number for all the files in one area of\n");
  90.    printf("\t FILESBBS.DAT to another area. Run as:\n\t\tCHGAREA 30 31\n\tMoves all files from area 30 to area 31.\n\n");
  91.    exit(1);
  92. }
  93.  
  94.