home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource3 / 147_01 / utilfn.c < prev    next >
Text File  |  1985-03-11  |  16KB  |  667 lines

  1. /****************************************************************
  2. * UTILFN.C                            *
  3.  
  4. Release 7: RBBS 4.1 Edit 02 - Changed the SYSOP's entry to have
  5.                   a "!" instead of "+" as the MF Flag.
  6.                 - Changed getname prompt in superuser.
  7. Release 6: RBBS 4.1 Edit 01 - Added continuous modes for updating
  8.                   USERS.CCC and .MSG files
  9. Release 5: RBBS 4.1 Edit 00 - Names now one large field
  10.                 - Activated lstmsg for 1st 7 non-PERSONALs
  11.                 - Inserted PERSONLY conditional
  12.  
  13. * Functions included in this file are:
  14.  
  15. * rite_active    (Case 1) creates cmsgfile.$$$, selectively copies
  16.                 each message, one at a time from cmsgfile.MSG.
  17.                 Then renames cmsgfile.MSG to cmsgfile.BAK, and
  18.                 cmsgfile.$$$ to cmsgfile.MSG.
  19.  
  20. * prnt_ndx    displays the index data
  21.  
  22. * read_msgs    (Case 2) offers to display any particular message
  23.  
  24. * chk_user    checks to see if USERS.CCC exists, and calls nu_user
  25.         to create it if it doesn't.
  26.  
  27. * nu_user    (Case 3) deletes any existing USERS.CCC and creates a
  28.         fresh one, with SYSOP as the first entry.
  29.  
  30. * rite_user    (Case 7) creates USER.$$$, selectively copies each
  31.         user, one at a time from USER.CCC. Then renames
  32.         USER.CCC to USER.BAK and USER.$$$ to USER.BAK
  33.  
  34. * subject    checks to see if SUBJECTS.CCC exists, and calls
  35.         creat_subj if not.  Then calls displ_subj to
  36.         display the available subjects.
  37.  
  38. * creat_subj    creates SUBJECT.CCC with two initial entries:
  39.         PERSONAL and GENERAL.
  40.  
  41. * add_subj    (Case 5) calls creat_subject if SUBJECT.CCC
  42.         doesn't exist and prompts the user to add a
  43.         new entry
  44.  
  45. * select_subj    (Case 4) reads and displays SUBJECT.CCC and
  46.         prompts user to select one to be the current
  47.         .MSG file.
  48.  
  49. * superuser    sysop only functions
  50.  
  51. * printuser    called by superuser
  52.  
  53. * ntrlong    enter a long message into the subject file that
  54.         is active
  55.  
  56. * prnt_instr    print instructions about long text entry
  57.  
  58. * txtlong    enter the long text from a file
  59.  
  60. * rite_line    write a single line of text
  61.  
  62. ****************************************************************/
  63.  
  64. #include    <bdscio.h>
  65. #include    "rbbs4.h"
  66.  
  67. /****************************************************************/
  68. rite_active(ct,s)
  69. int    ct;
  70. struct    _sum    *s;
  71. {
  72.     int    i,j,k;
  73.     int    auto,rite_it;
  74.     int    fdin,fdout;
  75.     int    blks,msgnum,tmsgnum;
  76.  
  77.     auto = FALSE;
  78.     if ( getyn("Write active records w/o asking"))
  79.         auto = TRUE;
  80.     msgnum = 0;
  81.     fdin = openfile(msgfile);
  82. #if    LOCKEM
  83.     if (lokrec(fdin,-1))
  84.         ioerr("locking .MSG");
  85. #endif
  86.     sprintf(tmpstr,"%s%s%s",DRIVE,capstr(cmsgfile),".$$$");
  87.     if ( (fdout = creat(tmpstr)) == ERROR)
  88.         ioerr("Creating $$$ file");
  89.     if ( seek(fdout,0,0) == ERROR)
  90.         ioerr("Seek in $$$");
  91.     for ( i = 1; i <= ct; i++)
  92.     {
  93.         sprintf(tmpstr,"mno[%d]: %d",i,mno[i]);
  94.         outstr(tmpstr,1);
  95.         if (mno[i])
  96.         {
  97.         readsum(fdin,mndx[i],s);
  98.         if (!auto)
  99.         {
  100.             outstr("**********",1);
  101.             prnt_sum(s);
  102.             crlf(1);
  103.             rite_it = FALSE;
  104.             if (getyn("Write rec")) 
  105.                 rite_it = TRUE;
  106.         }    
  107.         if (auto || rite_it)
  108.         {
  109.             tmsgnum = ritesum(fdout,msgnum,s);
  110.             blks = (s->lct+1)/2;
  111.             for ( j = 1; j <= blks; j++)
  112.             {
  113.                 readrec(fdin,mndx[i]+j,tmpstr,1);
  114.                 Rriterec(fdout,msgnum+j,1,tmpstr);
  115.             }
  116.         }
  117.         msgnum = tmsgnum;
  118.         }
  119.     }
  120.     if (close(fdout) == ERROR)
  121.         ioerr("Closing .$$$");
  122. #if    LOCKEM
  123.     frerec(fdin,-1);
  124. #endif
  125.     if (close(fdin) == ERROR)
  126.         ioerr("Closing .MSG");
  127.     sprintf(tmpstr,"%s%s%s",DRIVE,capstr(cmsgfile),".BAK");
  128.     unlink(tmpstr);
  129.     if ( rename(msgfile,tmpstr) == ERROR)
  130.         ioerr("Renaming .MSG to .BAK");
  131.     sprintf(tmpstr,"%s%s%s",DRIVE,capstr(cmsgfile),".$$$");
  132.     if ( rename(tmpstr,msgfile) == ERROR)
  133.         ioerr("Renaming .$$$ to .CCC");
  134. }
  135. /***************************************************************/
  136. prnt_ndx(i)
  137. int    i;
  138. {
  139.     sprintf(tmpstr,"no(%2d): %3d, ndx(%2d): %3d  ",i,mno[i],i,mndx[i]);
  140.     outstr(tmpstr,0);
  141.     if ( !(i % 2))
  142.         crlf(1);
  143. }
  144. /****************************************************************/
  145. read_msgs(msgct,s)
  146. int    msgct;
  147. struct    _sum    *s;
  148. {
  149.     int    i,j,k;
  150.     int    msgfd;
  151.     int    msglim;
  152.     char    input[5];
  153.  
  154.     msgfd = openfile(msgfile);
  155.     k = msgct+1;
  156.     while (k)
  157.     {
  158.         while (k > msgct)
  159.         {
  160.             sprintf(tmpstr,"Msg # (1:%d, or 0 to quit): ",msgct);
  161.             outstr(tmpstr,4);
  162.             instr("",input,3);
  163.             k = atoi(input);
  164.          }
  165.         if (!k)
  166.         {
  167.             close(msgfd);
  168.             break;
  169.         }
  170.         readsum(msgfd,mndx[k],s);
  171.         outstr("**********",1);
  172.         prnt_sum(s);
  173.         readtxt(msgfd,mndx[k],s);
  174.         crlf(1);
  175.         k = msgct+1;
  176.     }
  177. }
  178. /****************************************************************/
  179. chk_user()
  180. {
  181.     int    fd;
  182.     int    bias;
  183.     char    input[10];
  184.  
  185.     crlf(1);
  186.     if ( (fd = open(DSK(USERS.CCC),2)) == ERROR)
  187.         nu_user();
  188.     else
  189.         close(fd);    
  190.     if ( (fd = open(DSK(CALLERS.CCC),2)) == ERROR)
  191.         if ( (fd = creat(DSK(CALLERS.CCC))) == ERROR)
  192.             ioerr("Cannot create CALLERS.CCC");
  193.         else
  194.         {
  195. outstr("Enter highest caller number of old CALLERS file, or 0 if new: ",4);
  196.             instr("",input,10);
  197.             bias = atoi(input);
  198.             formrec(tmpstr,SECSIZ);
  199.             sprintf(tmpstr,"MAX CALR: %d %d",0,bias);
  200.             Rriterec(fd,0,1,tmpstr);
  201.         }
  202.     close(fd);    
  203. }
  204. /****************************************************************/
  205. nu_user()
  206. {
  207.     int    fd;
  208.  
  209.     outstr("Creating new USERS.CCC...",2);
  210.     unlink(DSK(USERS.CCC));
  211.     if ( (fd = creat(DSK(USERS.CCC))) == ERROR)
  212.         ioerr("Creating USERS.CCC");
  213.     formrec(tmpstr,SECSIZ);
  214.     sprintf(tmpstr+NM,"%s","SYSOP");    /* NM:    */
  215.     sprintf(tmpstr+PRV,"%c%c",'!',0);    /* PRV:    */
  216.     sprintf(tmpstr+UBL,"%1d",FALSE);    /* UBL:    */
  217.     sprintf(tmpstr+UXP,"%1d",TRUE);        /* UXP:    */
  218.     sprintf(tmpstr+PWD,"%s","123456");    /* PWD:    */
  219.     sprintf(tmpstr+LLG,"%s",sysdate);    /* LLG:    */
  220.     sprintf(tmpstr+FRM,"%s",SYSITE);    /* FRM:    */
  221.     sprintf(tmpstr+LMG0,"%03d",0);        /* LMG0:*/
  222.     sprintf(tmpstr+LMG1,"%03d",0);        /* LMG1:*/
  223.     sprintf(tmpstr+LMG2,"%03d",0);        /* LMG2:*/
  224.     sprintf(tmpstr+LMG3,"%03d",0);        /* LMG3:*/
  225.     sprintf(tmpstr+LMG4,"%03d",0);        /* LMG4:*/
  226.     sprintf(tmpstr+LMG5,"%03d",0);        /* LMG5:*/
  227.     sprintf(tmpstr+LMG6,"%03d",0);        /* LMG6:*/
  228.     Rriterec(fd,1,1,tmpstr);
  229.  
  230.     formrec(tmpstr,SECSIZ);
  231.     sprintf(tmpstr,"MAX REC: %3d",1);
  232.     Rriterec(fd,0,1,tmpstr);
  233.     close(fd);
  234. }
  235. /****************************************************************/
  236. rite_user(u)
  237. struct    _user    *u;
  238. {
  239.     int    i,j,k;
  240.     int     auto;
  241.     int    fdin,fdout;
  242.     int    inct,outct;
  243.  
  244.     outct = 1;
  245.     auto = FALSE;
  246.     if ( getyn("Write deleted records w/o asking"))
  247.         auto = TRUE;
  248.     if ( (fdin = open(DSK(USERS.CCC),2)) == ERROR)
  249.         ioerr("Cannot open USERS.CCC");
  250. #if    LOCKEM
  251.     if (lokrec(fdin,-1))
  252.         ioerr("locking USERS.CCC");
  253. #endif
  254.     if ((fdout= creat(DSK(USERS.$$$)))== ERROR)
  255.         ioerr("Creating USERS.$$$ file");
  256.     if ( seek(fdout,1,0) == ERROR)
  257.         ioerr("Seek in USERS.$$$");
  258.     readrec(fdin,0,tmpstr,1);
  259.     sscanf(tmpstr,"MAX REC: %d",&inct);
  260.     for ( i = 1; i <= inct; i++)
  261.     {
  262.         formrec(tmpstr,SECSIZ);
  263.         readrec(fdin,i,tmpstr,1);
  264.         sscanf(tmpstr+NM,"%s",u->nm);        /* NM:    */
  265.         sscanf(tmpstr+LLG,"%s",u->lastlog);    /* LLG:    */
  266.         sscanf(tmpstr+FRM,"%s",u->from);    /* FRM:    */
  267.         sscanf(tmpstr+PRV,"%s",u->ustat);    /* PRV: */
  268.         if (auto && (*(u->ustat) != '#'))/* GOODBYE TWITS*/
  269.         {
  270.             printuser(u);
  271.             Rriterec(fdout,outct++,1,tmpstr);
  272.         }
  273.         if (!auto)
  274.         {
  275.             printuser(u);
  276.             crlf(1);
  277.             if ( getyn("Write rec"))
  278.             {
  279.                 Rriterec(fdout,outct++,1,tmpstr);
  280.             }
  281.         }
  282.     }
  283.     formrec(tmpstr,SECSIZ);
  284.     sprintf(tmpstr,"MAX REC: %d",--outct);
  285.     Rriterec(fdout,0,1,tmpstr);
  286.     if ( close(fdout) == ERROR)
  287.         ioerr("Closing USERS.$$$");
  288.  
  289. #if    LOCKEM
  290.     frerec(fdin,-1);
  291. #endif
  292.     if ( close(fdin) == ERROR)
  293.         ioerr("Closing USERS.CCC");
  294.     unlink(DSK(USERS.BAK));
  295.     if ( rename(DSK(USERS.CCC),DSK(USERS.BAK)) == ERROR)
  296.         ioerr("Renaming USERS.CCC to USERS.BAK");
  297.     if ( rename(DSK(USERS.$$$),DSK(USERS.CCC)) == ERROR)
  298.         ioerr("Renaming USERS.$$$ to USERS.CCC");
  299. }
  300. /****************************************************************/
  301. #if    !PERSONLY
  302. subject()
  303. {
  304.     int    i,fd,n;
  305.  
  306.     crlf(1);
  307.     if ( (fd = open(DSK(SUBJECTS.CCC),2)) == ERROR)
  308.         fd = creat_subj(fd);
  309.     if ( readrec(fd,0,tmpstr,1) == ERROR)
  310.         ioerr("reading the subject record");
  311.     sscanf(tmpstr,"%d",&n);
  312.     displ_subj(fd,n,tmpstr);
  313.     close(fd);    
  314. }
  315. /***************