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

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