home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / WWIV2.ZIP / CONVERT.C < prev    next >
C/C++ Source or Header  |  1993-01-06  |  11KB  |  380 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1993 by Wayne Bell
  5.  
  6. Distribution of the source code for WWIV, in any form, modified or unmodified,
  7. without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
  8. Distribution of compiled versions of WWIV is limited to copies compiled BY
  9. THE AUTHOR.  Distribution of any copies of WWIV not compiled by the author
  10. is expressly prohibited.
  11.  
  12.  
  13. *****************************************************************************/
  14.  
  15.  
  16. #include <stdio.h>
  17. #include <io.h>
  18. #include <fcntl.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. #include <sys\stat.h>
  22. #include <dos.h>
  23. #include <alloc.h>
  24. #include <time.h>
  25.  
  26. #include "vardec.h"
  27.  
  28. /****************************************************************************/
  29.  
  30. #define OFFOF(x) (FP_OFF(&(u.x))-FP_OFF(&u))
  31. #define C_STR(a) strncpy(new.a,old.a,sizeof(new.a)-1)
  32. #define C_NUM(a) new.a=old.a
  33.  
  34.  
  35. /****************************************************************************/
  36.  
  37.  
  38.  
  39. /* DATA FOR EVERY USER */
  40. typedef struct {
  41.     char        name[31],        /* user's name */
  42.             realname[21],        /* user's real name */
  43.             callsign[7],        /* user's amateur callsign */
  44.             phone[13],        /* user's phone number */
  45.             pw[9],            /* user's password */
  46.             laston[9],        /* last date on */
  47.             firston[9],        /* first date on */
  48.             note[41],        /* sysop's note about user */
  49.             macros[3][81],        /* macro keys */
  50.             sex;            /* user's sex */
  51.     unsigned char    age,            /* user's age */
  52.             inact,            /* if deleted or inactive */
  53.             comp_type,        /* computer type */
  54.             defprot,        /* deflt transfer protocol */
  55.             defed,            /* default editor */
  56.             screenchars,screenlines,/* screen size */
  57.             sl,            /* security level */
  58.             dsl,            /* transfer security level */
  59.             exempt,            /* exempt from ratios, etc */
  60.             colors[8],        /* user's colors */
  61.             votes[20],        /* user's votes */
  62.             illegal,        /* illegal logons */
  63.             waiting,        /* number mail waiting */
  64.             sysopsub,        /* sysop sub board number */
  65.             ontoday;        /* num times on today */
  66.     unsigned short    homeuser,homesys,    /* where user can be found */
  67.             forwardusr,forwardsys,    /* where to forward mail */
  68.             msgpost,        /* number messages posted */
  69.             emailsent,        /* number of email sent */
  70.             feedbacksent,        /* number of f-back sent */
  71.             posttoday,        /* number posts today */
  72.             etoday,            /* number emails today */
  73.             ar,            /* board access */
  74.             dar,            /* directory access */
  75.             restrict,        /* restrictions on account */
  76.             ass_pts,        /* bad things the user did */
  77.             uploaded,        /* number files uploaded */
  78.             downloaded,        /* number files downloaded */
  79.             lastrate,        /* last baud rate on */
  80.             logons;            /* total number of logons */
  81.     unsigned long    msgread,        /* total num msgs read */
  82.             uk,            /* number of k uploaded */
  83.             dk,            /* number of k downloaded */
  84.             qscn,            /* which subs to n-scan */
  85.                         qscnptr[33],            /* q-scan pointers */
  86.             nscn1,nscn2,        /* which dirs to n-scan */
  87.             daten,            /* numerical time last on */
  88.             sysstatus;        /* status/defaults */
  89.     float        timeontoday,        /* time on today */
  90.             extratime,        /* time left today */
  91.             timeon,            /* total time on system */
  92.             pos_account,        /* $ credit */
  93.             neg_account,        /* $ debit */
  94.             gold;            /* game money */
  95.     unsigned char    bwcolors[8];        /* b&w colors */
  96.     unsigned char    month,day,year;        /* user's birthday */
  97.     unsigned int    emailnet,        /* email sent into net */
  98.             postnet;        /* posts sent into net */
  99.     unsigned short    fsenttoday1;        /* feedbacks today */
  100.         unsigned char   num_extended;           /* num lines of ext desc */
  101.         unsigned char   optional_val;           /* optional lines in msgs */
  102.         unsigned long   wwiv_regnum;            /* users WWIV reg number */
  103.         unsigned char   net_num;                /* net_num for forwarding */
  104.         char            res[28];                /* reserved bytes */
  105.         unsigned long   qscn2;                  /* additional qscan ptr */
  106.         unsigned long   qscnptr2[32];           /* additional quickscan ptrs */
  107. } olduserrec;
  108.  
  109. /****************************************************************************/
  110.  
  111. static int ouf, nuf, qf, qfl;
  112. static char oun[128],nun[128],qfn[128],sun[128];
  113. static unsigned long *qsc, *qsc_n, *qsc_q, *qsc_p;
  114.  
  115. #ifdef INIT
  116. extern configrec syscfg;
  117. #else
  118. static configrec syscfg;
  119. #endif
  120.  
  121.  
  122. /****************************************************************************/
  123.  
  124. void c_setup(void)
  125. {
  126.   int f;
  127.  
  128. #ifndef INIT
  129.   f=open("CONFIG.DAT",O_RDONLY|O_BINARY);
  130.   if (f>0) {
  131.     read(f,&syscfg,sizeof(syscfg));
  132.     close(f);
  133.  
  134. #endif
  135.     sprintf(oun,"%sUSER.LST",syscfg.datadir);
  136.     sprintf(nun,"%sUSER.NEW",syscfg.datadir);
  137.     sprintf(qfn,"%sUSER.QSC",syscfg.datadir);
  138.     sprintf(sun,"%sUSER.OLD",syscfg.datadir);
  139. #ifndef INIT
  140.   } else {
  141.     printf("CONFIG.DAT not found; run in main BBS dir.\n");
  142.   }
  143. #endif
  144.   if (!syscfg.max_subs)
  145.     syscfg.max_subs=64;
  146.   if (!syscfg.max_dirs)
  147.     syscfg.max_dirs=64;
  148.  
  149.   if (!syscfg.userreclen)
  150.     syscfg.userreclen=sizeof(olduserrec);
  151.  
  152.   qfl=4*(1+syscfg.max_subs+((syscfg.max_subs+31)/32)+((syscfg.max_dirs+31)/32));
  153.   syscfg.qscn_len=qfl;
  154.  
  155.   qsc=(unsigned long *)farmalloc(qfl);
  156.  
  157.   qsc_n=qsc+1;
  158.   qsc_q=qsc_n+((syscfg.max_dirs+31)/32);
  159.   qsc_p=qsc_q+((syscfg.max_subs+31)/32);
  160. }
  161.  
  162. /****************************************************************************/
  163.  
  164. void c_old_to_new(void)
  165. {
  166.   int nu,i,i1,f;
  167.   olduserrec old;
  168.   userrec new,u;
  169.  
  170.   ouf=open(oun,O_RDONLY|O_BINARY);
  171.   if (ouf<0) {
  172.     printf("Couldn't open '%s'\n",oun);
  173.     return;
  174.   }
  175.   nuf=open(nun,O_RDWR|O_BINARY|O_CREAT|O_TRUNC, S_IREAD|S_IWRITE);
  176.   if (nuf<0) {
  177.     close(ouf);
  178.     printf("Couldn't create '%s'\n",nun);
  179.     return;
  180.   }
  181.   qf=open(qfn,O_RDWR|O_BINARY|O_CREAT|O_TRUNC, S_IREAD|S_IWRITE);
  182.   if (qf<0) {
  183.     close(ouf);
  184.     close(nuf);
  185.     printf("Couldn't create '%s'\n",qfn);
  186.     return;
  187.   }
  188.  
  189.   nu=filelength(ouf)/syscfg.userreclen;
  190.  
  191.   for (i=0; i<nu; i++) {
  192.     if (i%10 == 0)
  193.       printf("%u/%u\r",i,nu);
  194.  
  195.     memset(&old,0,sizeof(old));
  196.     memset(&new,0,sizeof(new));
  197.     memset(qsc,0,qfl);
  198.  
  199.     if (i) {
  200.       lseek(ouf,((long)i)*((long)syscfg.userreclen), SEEK_SET);
  201.       read(ouf,&old,syscfg.userreclen);
  202.  
  203.       C_STR(name);
  204.       C_STR(realname);
  205.       C_STR(callsign);
  206.       C_STR(phone);
  207.       C_STR(pw);
  208.       C_STR(laston);
  209.       C_STR(firston);
  210.       C_STR(note);
  211.       for (i1=0; i1<3; i1++)
  212.         C_STR(macros[i1]);
  213.       C_NUM(sex);
  214.       C_NUM(age);
  215.       C_NUM(inact);
  216.       C_NUM(comp_type);
  217.       C_NUM(defprot);
  218.       C_NUM(defed);
  219.       C_NUM(screenchars);
  220.       C_NUM(screenlines);
  221.       C_NUM(sl);
  222.       C_NUM(dsl);
  223.       C_NUM(exempt);
  224.       for (i1=0; i1<8; i1++) {
  225.         C_NUM(colors[i1]);
  226.         C_NUM(bwcolors[i1]);
  227.       }
  228.       new.colors[8]=1;
  229.       new.colors[9]=3;
  230.       new.bwcolors[8]=7;
  231.       new.bwcolors[9]=7;
  232.       for (i1=0; i1<20; i1++)
  233.         C_NUM(votes[i1]);
  234.       C_NUM(illegal);
  235.       C_NUM(waiting);
  236.       C_NUM(ontoday);
  237.       C_NUM(homeuser);
  238.       C_NUM(homesys);
  239.       C_NUM(forwardusr);
  240.       C_NUM(forwardsys);
  241.       C_NUM(msgpost);
  242.       C_NUM(emailsent);
  243.       C_NUM(feedbacksent);
  244.       C_NUM(posttoday);
  245.       C_NUM(etoday);
  246.       C_NUM(ar);
  247.       C_NUM(dar);
  248.       C_NUM(restrict);
  249.       C_NUM(ass_pts);
  250.       C_NUM(uploaded);
  251.       C_NUM(downloaded);
  252.       C_NUM(lastrate);
  253.       C_NUM(logons);
  254.       C_NUM(msgread);
  255.       C_NUM(uk);
  256.       C_NUM(dk);
  257.       C_NUM(daten);
  258.       C_NUM(sysstatus);
  259.       C_NUM(timeontoday);
  260.       C_NUM(extratime);
  261.       C_NUM(timeon);
  262.       C_NUM(pos_account);
  263.       C_NUM(neg_account);
  264.       C_NUM(gold);
  265.       C_NUM(month);
  266.       C_NUM(day);
  267.       C_NUM(year);
  268.       C_NUM(emailnet);
  269.       C_NUM(postnet);
  270.       C_NUM(fsenttoday1);
  271.       C_NUM(num_extended);
  272.       C_NUM(optional_val);
  273.       C_NUM(wwiv_regnum);
  274.       C_NUM(net_num);
  275.  
  276.       *qsc=old.sysopsub;
  277.       if (*qsc==255)
  278.         *qsc=999;
  279.       qsc_n[0]=old.nscn1;
  280.       qsc_n[1]=old.nscn2;
  281.       qsc_q[0]=old.qscn;
  282.       qsc_q[1]=old.qscn2;
  283.  
  284.       for (i1=0; i1<32; i1++) {
  285.         qsc_p[i1]=old.qscnptr[i1];
  286.         qsc_p[i1+32]=old.qscnptr2[i1];
  287.       }
  288.     }
  289.  
  290.     lseek(nuf,((long)i)*((long)sizeof(new)), SEEK_SET);
  291.     write(nuf,&new,sizeof(new));
  292.  
  293.     lseek(qf,((long)i)*((long)qfl),SEEK_SET);
  294.     write(qf,qsc,qfl);
  295.  
  296.   }
  297.   close(ouf);
  298.   close(nuf);
  299.   close(qf);
  300.  
  301.   unlink(sun);
  302.   rename(oun,sun);
  303.   rename(nun,oun);
  304.  
  305.   syscfg.userreclen=sizeof(u);
  306.   syscfg.waitingoffset=OFFOF(waiting);
  307.   syscfg.inactoffset=OFFOF(inact);
  308.   syscfg.sysstatusoffset=OFFOF(sysstatus);
  309.   syscfg.fuoffset=OFFOF(forwardusr);
  310.   syscfg.fsoffset=OFFOF(forwardsys);
  311.   syscfg.fnoffset=OFFOF(net_num);
  312.  
  313.   f=open("CONFIG.DAT",O_RDWR|O_BINARY|O_CREAT,S_IREAD|S_IWRITE);
  314.   if (f>0) {
  315.     write(f,&syscfg,sizeof(syscfg));
  316.     close(f);
  317.   }
  318.   printf("\nDone.\n");
  319. }
  320.  
  321. /****************************************************************************/
  322.  
  323. int c_check(void)
  324. {
  325.   if (access(qfn,0)==0)
  326.     /* new format */
  327.     return(1);
  328.   else
  329.     /* old format */
  330.     return(0);
  331. }
  332.  
  333. /****************************************************************************/
  334.  
  335. int c_check_old_struct(void)
  336. {
  337.   olduserrec u;
  338.  
  339.   if ((syscfg.userreclen) && (syscfg.userreclen!=sizeof(u)) && (syscfg.userreclen!=700))
  340.     return(1);
  341.   if ((syscfg.waitingoffset) && (syscfg.waitingoffset != OFFOF(waiting)))
  342.     return(1);
  343.   if ((syscfg.inactoffset) && (syscfg.inactoffset != OFFOF(inact)))
  344.     return(1);
  345.   if ((syscfg.sysstatusoffset) && (syscfg.sysstatusoffset != OFFOF(sysstatus)))
  346.     return(1);
  347.   if ((syscfg.fuoffset) && (syscfg.fuoffset != OFFOF(forwardusr)))
  348.     return(1);
  349.   if ((syscfg.fsoffset) && (syscfg.fsoffset != OFFOF(forwardsys)))
  350.     return(1);
  351.   if ((syscfg.fnoffset) && (syscfg.fnoffset != OFFOF(net_num)))
  352.     return(1);
  353.  
  354.   return(0);
  355. }
  356.  
  357. /****************************************************************************/
  358.  
  359. #ifndef INIT
  360. void main()
  361. {
  362.   c_setup();
  363.  
  364.   if (c_check()==1) {
  365.     /* convert back to old format */
  366.     printf("Your userrec is already in the new format.\n");
  367.   } else {
  368.     /* convert to new format */
  369.     if (c_check_old_struct()) {
  370.       printf("Your current userrec format is unknown.\n");
  371.       printf("Please copy your old userrec format into convert.c,\n");
  372.       printf("and compile and run it.\n");
  373.     } else {
  374.       c_old_to_new();
  375.       printf("Userlist converted.\n");
  376.     }
  377.   }
  378. }
  379. #endif
  380.