home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 147_01 / catalog.dsk < prev    next >
Text File  |  1985-03-10  |  11KB  |  472 lines

  1. );    
  2. }
  3. /****************************************************************/
  4. nu_user()
  5. {
  6.     int    fd;
  7.  
  8.     outstr("Creating new USERS.CCC...",2);
  9.     unlink(DSK(USERS.CCC));
  10.     if ( (fd = creat(DSK(USERS.CCC))) == ERROR)
  11.         ioerr("Creating USERS.CCC");
  12.     formrec(tmpstr,SECSIZ);
  13.     sprintf(tmpstr+NM,"%s","SYSOP");    /* NM:    */
  14.     sprintf(tmpstr+PRV,"%c%c",'!',0);    /* PRV:    */
  15.     sprintf(tmpstr+UBL,"%1d",FALSE);    /* UBL:    */
  16.     sprintf(tmpstr+UXP,"%1d",TRUE);        /* UXP:    */
  17.     sprintf(tmpstr+PWD,"%s","123456");    /* PWD:    */
  18.     sprintf(tmpstr+LLG,"%s",sysdate);    /* LLG:    */
  19.     sprintf(tmpstr+FRM,"%s",SYSITE);    /* FRM:    */
  20.     sprintf(tmpstr+LMG0,"%03d",0);        /* LMG0:*/
  21.     sprintf(tmpstr+LMG1,"%03d",0);        /* LMG1:*/
  22.     sprintf(tmpstr+LMG2,"%03d",0);        /* LMG2:*/
  23.     sprintf(tmpstr+LMG3,"%03d",0);        /* LMG3:*/
  24.     sprintf(tmpstr+LMG4,"%03d",0);        /* LMG4:*/
  25.     sprintf(tmpstr+LMG5,"%03d",0);        /* LMG5:*/
  26.     sprintf(tmpstr+LMG6,"%03d",0);        /* LMG6:*/
  27.     Rriterec(fd,1,1,tmpstr);
  28.  
  29.     formrec(tmpstr,SECSIZ);
  30.     sprintf(tmpstr,"MAX REC: %3d",1);
  31.     Rriterec(fd,0,1,tmpstr);
  32.     close(fd);
  33. }
  34. /****************************************************************/
  35. rite_user(u)
  36. struct    _user    *u;
  37. {
  38.     int    i,j,k;
  39.     int     auto;
  40.     int    fdin,fdout;
  41.     int    inct,outct;
  42.  
  43.     outct = 1;
  44.     auto = FALSE;
  45.     if ( getyn("Write deleted records w/o asking"))
  46.         auto = TRUE;
  47.     if ( (fdin = open(DSK(USERS.CCC),2)) == ERROR)
  48.         ioerr("Cannot open USERS.CCC");
  49. #if    LOCKEM
  50.     if (lokrec(fdin,-1))
  51.         ioerr("locking USERS.CCC");
  52. #endif
  53.     if ((fdout= creat(DSK(USERS.$$$)))== ERROR)
  54.         ioerr("Creating USERS.$$$ file");
  55.     if ( seek(fdout,1,0) == ERROR)
  56.         ioerr("Seek in USERS.$$$");
  57.     readrec(fdin,0,tmpstr,1);
  58.     sscanf(tmpstr,"MAX REC: %d",&inct);
  59.     for ( i = 1; i <= inct; i++)
  60.     {
  61.         formrec(tmpstr,SECSIZ);
  62.         readrec(fdin,i,tmpstr,1);
  63.         sscanf(tmpstr+NM,"%s",u->nm);        /* NM:    */
  64.         sscanf(tmpstr+LLG,"%s",u->lastlog);    /* LLG:    */
  65.         sscanf(tmpstr+FRM,"%s",u->from);    /* FRM:    */
  66.         sscanf(tmpstr+PRV,"%s",u->ustat);    /* PRV: */
  67.         if (auto && (*(u->ustat) != '#'))/* GOODBYE TWITS*/
  68.         {
  69.             printuser(u);
  70.             Rriterec(fdout,outct++,1,tmpstr);
  71.         }
  72.         if (!auto)
  73.         {
  74.             printuser(u);
  75.             crlf(1);
  76.             if ( getyn("Write rec"))
  77.             {
  78.                 Rriterec(fdout,outct++,1,tmpstr);
  79.             }
  80.         }
  81.     }
  82.     formrec(tmpstr,SECSIZ);
  83.     sprintf(tmpstr,"MAX REC: %d",--outct);
  84.     Rriterec(fdout,0,1,tmpstr);
  85.     if ( close(fdout) == ERROR)
  86.         ioerr("Closing USERS.$$$");
  87.  
  88. #if    LOCKEM
  89.     frerec(fdin,-1);
  90. #endif
  91.     if ( close(fdin) == ERROR)
  92.         ioerr("Closing USERS.CCC");
  93.     unlink(DSK(USERS.BAK));
  94.     if ( rename(DSK(USERS.CCC),DSK(USERS.BAK)) == ERROR)
  95.         ioerr("Renaming USERS.CCC to USERS.BAK");
  96.     if ( rename(DSK(USERS.$$$),DSK(USERS.CCC)) == ERROR)
  97.         ioerr("Renaming USERS.$$$ to USERS.CCC");
  98. }
  99. /****************************************************************/
  100. #if    !PERSONLY
  101. subject()
  102. {
  103.     int    i,fd,n;
  104.  
  105.     crlf(1);
  106.     if ( (fd = open(DSK(SUBJECTS.CCC),2)) == ERROR)
  107.         fd = creat_subj(fd);
  108.     if ( readrec(fd,0,tmpstr,1) == ERROR)
  109.         ioerr("reading the subject record");
  110.     sscanf(tmpstr,"%d",&n);
  111.     displ_subj(fd,n,tmpstr);
  112.     close(fd);    
  113. }
  114. /****************************************************************/
  115. creat_subj(fd)
  116. int    fd;
  117. {
  118.     int    i;
  119.  
  120.     outstr("Creating new SUBJECTS.CCC...",1);
  121.     if ( (fd = creat(DSK(SUBJECTS.CCC))) == ERROR)
  122.         ioerr("creating SUBJECTS.CCC");
  123.     for ( i = 0; i < SECSIZ; i++)
  124.         *(tmpstr+i) = ' ';
  125.     sprintf(tmpstr,"%02d",2);
  126.     sprintf(tmpstr+8,"PERSONAL");
  127.     sprintf(tmpstr+16,"GENERAL ");
  128.     Rriterec(fd,0,1,tmpstr);
  129.     return fd;
  130. }
  131. /****************************************************************/
  132. add_subj()
  133. {
  134.     int    i,fd,n;
  135.     char    input[17];
  136.     char    rec[SECSIZ];
  137.  
  138.     if ( (fd = open(DSK(SUBJECTS.CCC),2)) == ERROR)
  139.         ioerr("opening subject");
  140. #if    LOCKEM
  141.     if (lokrec(fd,-1))
  142.         ioerr("locking SUBJECTS.CCC");
  143. #endif
  144.     if ( readrec(fd,0,rec,1) == ERROR)
  145.         ioerr("reading the subject record");
  146.     sscanf(rec,"%d",&n);
  147.     displ_subj(fd,n,rec);
  148.         do
  149.         {
  150.         outstr("Enter new subject <Max 8 chars>: ",4);
  151.         instr("",input,8);
  152.         capstr(input);
  153.         } while (!strlen(input));
  154.     strcat(input,"        ");
  155.     sprintf(rec+8*(++n),"%8.8s",input);
  156.     sprintf(rec,"%02d",n);
  157.     Rriterec(fd,0,1,rec);
  158. #if    LOCKEM
  159.     frerec(fd,-1);
  160. #endif
  161.     close(fd);    
  162. }
  163. /****************************************************************/
  164. select_subj(choice,s)
  165. int    choice;
  166. struct    _sum    *s;
  167. {
  168.     int    fd,n;
  169.     char    input[3];
  170.     char    rec[SECSIZ];
  171.  
  172.     if ( (fd = open(DSK(SUBJECTS.CCC),2)) == ERROR)
  173.         ioerr("opening SUBJECTS.CCC");
  174.     if (readrec(fd,0,rec,1) == ERROR)
  175.         ioerr("reading SUBJECTS.CCC");
  176.     sscanf(rec,"%d",&n);
  177.     if (!choice)
  178.     {
  179.         outstr("Subjects are:",2);
  180.         displ_subj(fd,n,rec);
  181.         outstr("File number: ",4);
  182.         instr("",input,3);
  183.         crlf(1);
  184.         choice = atoi(input);
  185.     }
  186.     setmem(cmsgfile,9,0);
  187.     movmem(rec+8*choice,cmsgfile,8);
  188.     sprintf(msgfile,"%s%s%s",DRIVE,capstr(cmsgfile),".MSG");
  189.     sprintf(tmpstr,"Current SUBJECT File: %s",msgfile);
  190.     outstr(tmpstr,2);
  191.     crlf(1);
  192.     close(fd);    
  193. }
  194. #endif
  195. /****************************************************************/
  196. superuser()
  197. {
  198.     char    name[NAMELGTH+1];
  199.     char    input[5];
  200.     struct    _user    u2;
  201.     int    ufd;
  202.     int    i;
  203.  
  204.     if ( (ufd = open(DSK(USERS.CCC),2)) == ERROR)
  205.         ioerr("opening USERS");
  206.     crlf(1);
  207. #if    LOCKEM
  208.     if (lokrec(ufd,-1))
  209.         ioerr("locking USERS");
  210. #endif
  211.     while ( (getname(name,"Enter user name: ")) )
  212.         crlf(1);
  213.     if (!checkuser(ufd,name,u2,0))
  214.     {
  215.         crlf(1);
  216.         if (getyn("User not found.  Add this user") )
  217.         {
  218.             belflg = FALSE;
  219.             expert = FALSE;
  220.             newuser(u2,name,ufd);
  221.         }
  222. #if    LOCKEM
  223.         frerec(ufd,-1);
  224. #endif
  225.         close(ufd);
  226.         return;
  227.     }
  228.     else
  229.     {
  230.         printuser(u2);
  231.         for ( i = 2; i <= 8; ++i)
  232.         {
  233.     sprintf(tmpstr,"Last msg (File #%d): %d, change it",i,u2.lstmsg[i-2]);
  234.             while(getyn(tmpstr))
  235.             {
  236.                 outstr("Enter new value: ",5);
  237.                 instr("",input,4);
  238.                 u2.lstmsg[i-2] = atoi(input);
  239.     sprintf(tmpstr,"Last msg (File #%d): %d, change it",i,u2.lstmsg[i-2]);
  240.                 crlf(1);
  241.             }
  242.         }
  243.         sprintf(tmpstr,"MF stat: %s, change it",u2.ustat);
  244.         while(getyn(tmpstr))
  245.         {
  246.             outstr("Enter new value: ",5);
  247.             instr("",u2.ustat,1);
  248.             sprintf(tmpstr,"MF stat: %s, change it",u2.ustat);
  249.             crlf(1);
  250.         }
  251.         sprintf(tmpstr,"Password: %s, change it",u2.pwd);
  252.         while(getyn(tmpstr))
  253.         {
  254.             outstr("Enter: ",5);
  255.             instr("",u2.pwd,6);
  256.             sprintf(tmpstr,"Password: %s, change it",u2.pwd);
  257.             crlf(1);
  258.         }
  259.         belflg = u2.bellflag;
  260.         expert = u2.xpert;
  261.         updtuser(u2,ufd);
  262.     }
  263. #if    LOCKEM
  264.     frerec(ufd,-1);
  265. #endif
  266.     close(ufd);
  267. }
  268. /****************************************************************/
  269. printuser(u)
  270. struct    _user    *u;
  271. {
  272.     char    temp[SECSIZ];
  273.  
  274.     crlf(1);
  275.     sprintf(temp,"USER NAME:  %s",u->nm);
  276.     outstr(temp,3);
  277.     sprintf(temp,"USER SITE:  %s",u->from);
  278.     outstr(temp,3);
  279.     sprintf(temp,"LAST LOGON: %s",u->lastlog);
  280.     outstr(temp,2);
  281.     crlf(1);
  282. }
  283. /****************************************************************/
  284. newuser(u,name,fd)        /*DOUBLE CHECKS NEW USER & GETS    */
  285. struct    _user    *u;        /*INFO TO ADD NEW USER. ADDS    */
  286. char    *name;            /*NEW USER TO FILE. DOES NOT    */
  287. int    fd;            /*CLOSE USER FILE        */
  288. {
  289.     int    correct;
  290.     char    place[31];
  291.     char    passwd[7];
  292. #if    LOCKEM
  293.     char    temp[SECSIZ];
  294. #endif
  295.  
  296.     correct = FALSE;
  297.     crlf(1);
  298.     do
  299.     {
  300.         sprintf(tmpstr,"Enter user's %s: ",SITEPROMPT);
  301.         outstr(tmpstr,4);
  302.         instr("",place,30);
  303.         capstr(place);
  304.         crlf(1);
  305.         sprintf(tmpstr,"Is the name, %s, correct",place);
  306.         correct = getyn(tmpstr);
  307.     }while(!correct);
  308.     chkpwd(passwd);
  309.  
  310.     formrec(tmpstr,SECSIZ);
  311.     sprintf(tmpstr+NM,"%s",name);        /* NM:    */
  312.     sprintf(tmpstr+PRV,"%c%c",'+',0);    /* PRV:    */
  313.     sprintf(tmpstr+UBL,"%1d",belflg);    /* UBL:    */
  314.     sprintf(tmpstr+UXP,"%1d",expert);    /* UXP:    */
  315.     sprintf(tmpstr+PWD,"%s",passwd);    /* PWD:    */
  316.     sprintf(tmpstr+LLG,"%s",logdate);    /* LLG:    */
  317.     sprintf(tmpstr+FRM,"%s",place);        /* FRM:    */
  318.     sprintf(tmpstr+LMG0,"%03d",0);        /* LMG0:*/
  319.     sprintf(tmpstr+LMG1,"%03d",0);        /* LMG1:*/
  320.     sprintf(tmpstr+LMG2,"%03d",0);        /* LMG2:*/
  321.     sprintf(tmpstr+LMG3,"%03d",0);        /* LMG3:*/
  322.     sprintf(tmpstr+LMG4,"%03d",0);        /* LMG4:*/
  323.     sprintf(tmpstr+LMG5,"%03d",0);        /* LMG5:*/
  324.     sprintf(tmpstr+LMG6,"%03d",0);        /* LMG6:*/
  325. #if    LOCKEM
  326.     formrec(temp,SECSIZ);
  327.     if (lokrec(fd,-1))
  328.         ioerr("locking USERS.CCC");
  329.     readrec(fd,0,temp,1);
  330.     sscanf(temp,"MAX REC: %d",&u->maxno);
  331. #endif
  332.     Rriterec(fd,++u->maxno,1,tmpstr);
  333.  
  334.     formrec(tmpstr,SECSIZ);
  335.     sprintf(tmpstr,"MAX REC: %3d",u->maxno);
  336.     Rriterec(fd,0,1,tmpstr);
  337. #if    LOCKEM
  338.     frerec(fd,-1);
  339. #endif
  340.  
  341.     return (TRUE);
  342. }
  343. /****************************************************************/
  344. ntrlong(ufd,u,s)    
  345. int    ufd;
  346. struct    _user    *u;
  347. struct    _sum    *s;
  348. {
  349.     struct    _sum    s2;
  350.     int    msgfd;
  351.  
  352.     msgfd = openfile(msgfile);
  353.     s->mstat = TRUE;
  354.     strcpy(s->date,sysdate);
  355.     if (!check_to(ufd,s,TRUE))
  356.         return;
  357.     strcpy(s->fnm,u->nm);
  358.     *(s->subj) = 0;
  359.     get_subj(s);
  360. #if    LOCKEM
  361.     if (lokrec(msgfd,-1))
  362.         ioerr("locking .MSG file");
  363. #endif
  364.     msgct = loadsum(msgfd,s2); /* Loads last msg no if updated    */
  365.     msg_info(msgct,FALSE);
  366.     s->msgno = ++lastmsg;
  367.     ++msgct;
  368.     if ( (s->lct = longtxt(msgfd,mndx[msgct])) == ERROR)
  369.     {
  370. #if        LOCKEM
  371.         frerec(msgfd,-1);
  372. #endif
  373.         return;
  374.     }
  375.     mndx[msgct+1] = ritesum(msgfd,mndx[msgct],s);
  376.     mno[msgct] = s->msgno;
  377.     mno[msgct+1] = 0;
  378. #if    LOCKEM
  379.     frerec(msgfd,-1);
  380. #endif
  381.     sprintf(tmpstr,"Message stored as #%d.",s->msgno);
  382.     outstr(tmpstr,1);
  383.     return TRUE;
  384. }
  385. /***************************************************************/
  386. prnt_instr()
  387. {
  388.     int    test;
  389.  
  390. outstr("To enter text this way, all line should be 60 chars or less",1);
  391. outstr("with no high order bits set.  Otherwise, exit now:  ",0);
  392.     test = getyn("Continue");
  393.     crlf(1);
  394.     return test;
  395. }
  396. /***************************************************************/    
  397. longtxt(fd,start)
  398. int    fd,start;
  399. {
  400.     int    lnct;
  401.     char    file[18];
  402.     char    name[13];
  403.     char    buf[BUFSIZ];
  404.     char    line[SECSIZ];
  405.  
  406.     lnct = 0;
  407.     outstr("File name to read: ",0);
  408.     instr("",name,13);
  409.     crlf(1);
  410.     capstr(name);
  411.     sprintf(file,"%s%s",DRIVE,name);
  412.     outstr(file,1);
  413.     if (fopen(file,buf) != ERROR)
  414.     {
  415.         while ( (fgets(line,buf)))
  416.         {
  417.             if(strlen(line) > 61)
  418.                 *(line + 61) = 0;
  419.             else
  420.                 *(line+strlen(line)-1) = 0;
  421.             if ( !((lnct++)%2))
  422.             {
  423.                 formrec(tmpstr,SECSIZ);
  424.                 movmem(line,tmpstr,SECSIZ/2);
  425.             }
  426.             else
  427.             {
  428.                 movmem(line,tmpstr+SECSIZ/2,SECSIZ/2);
  429.                 rite_line(fd,++start,tmpstr);
  430.             }
  431.         }
  432.         if (!lnct)
  433.         {
  434.             rite_line(fd,++start,tmpstr);
  435.             fclose(buf);
  436.             return lnct;
  437.         }
  438.         else
  439.         {
  440.             fclose(buf);
  441.             return --lnct;
  442.         }
  443.     }
  444.     return ERROR;
  445. }
  446. /***************************************************************/    
  447. rite_line(fd,line,source)
  448. int    fd,line;
  449. char    *source;
  450. {
  451.     outstr(tmpstr,1);
  452.     outstr(tmpstr+SECSIZ/2,1);
  453.     seek_blk(fd,line);
  454.     if ( write(fd,source,1) == ERROR)
  455.     {
  456.         sprintf(tmpstr,"Rite err in fd: %d, rec: %d",fd,line);
  457.         outstr(tmpstr,1);
  458.         rexit();
  459.     }
  460. }
  461. /***************************************************************/    
  462. );
  463.     crlf(1);
  464.     capstr(name);
  465.     sprintf(file,"%s%s",DRIVE,name);
  466.     outstrlnct;
  467.         }
  468.     }
  469.     return ERROR;
  470. }
  471. /***************************************************************/    
  472. rite_line(fd,line,source)