home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume32 / xbbs / part08 / bbscsigs.c < prev    next >
C/C++ Source or Header  |  1992-09-08  |  7KB  |  316 lines

  1. /*------------------------------------------------------------------------
  2.        Name: bbscsigs.c
  3.    Comments: Display file areas and select one
  4.   ------------------------------------------------------------------------*/
  5.  
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include <signal.h>
  11. #include "bbscdef.h"
  12. #include <sys/locking.h>
  13.  
  14.  
  15. extern int      user_priv;
  16. extern int    first_time_in;
  17. extern int    first_msg_in;
  18. extern int    sigreturn;
  19. extern char     port_id[4];
  20. extern char    callers[99];
  21. extern timer(), mon_toggle(), sys_toggle(), chat(), hanged();
  22.  
  23. char    save_info[99];
  24.  
  25. sig_access()
  26. {
  27.     FILE           *fpt, *fopen();
  28.     char           *fgets(), *getenv();
  29.     char            choice[4];
  30. #ifndef SYSV
  31.     char            dir_priv_ascii[7];
  32. #endif
  33. #ifdef SYSV
  34.     char            dir_priv_ascii[20];
  35. #endif
  36.     char        signame[32], sigdisc[30], sigtype[10];
  37.     int             line_cnt, ret, i;
  38.     int             index_value, ptr;
  39.     int             length;
  40.     int        x1, x2;
  41.  
  42.     sigreturn = 1;
  43.     while (1) {
  44.  
  45. do_again:
  46.     strcpy(buf128, SIGS);
  47.  
  48.     if ((fpt = fopen(buf128, "r")) == NULL) {
  49.         portsout("\n\r\n\rThere are no SPECIAL INTEREST GROUPS today!\n\r\n\r");
  50.         return ;
  51.     }
  52.         portsout("\n\r\n\r\n\r                  *********************************\n\r");
  53.         portsout("                * Available Special Interest GROUPS *\n\r");
  54.         portsout("                  *********************************\n\r\n\r");
  55.         portsout("\n\r                SIGs                     Description           Type\n\r");
  56.         portsout("    ============================== ======================     =======\n\r");
  57.  
  58.     line_cnt = 0;
  59.     while (fpt) {
  60.         zfl(f_lines[line_cnt], 83);
  61.         if ((fgets(f_lines[line_cnt], 82, fpt)) == NULL) {
  62.             if (line_cnt == 0) {
  63.                 portsout("\n\rEOF Unexpected in Function List: Notify Sysop!\n\r");
  64.                 return;
  65.             }
  66.             break;    /* if not 1st line */
  67.         }        /* end of if ((fgets)) */
  68.         if (line_cnt > 0) {
  69.             length = strlen(f_lines[line_cnt]);
  70.             length -= 74;
  71.             if(length > 6)
  72.                 length = 6;
  73.             substr(f_lines[line_cnt], dir_priv_ascii, 74, length);
  74.             dir_priv[line_cnt] = atoi(dir_priv_ascii);
  75.             if (dir_priv[line_cnt] > user_priv)
  76.                 goto next_read;
  77.             substr(f_lines[line_cnt], signame, 1, 30);
  78.             substr(f_lines[line_cnt], sigdisc, 52,22);
  79.             x1 = strlen(signame);
  80.             for(x2=x1; x2 < 30; x2++)
  81.                 strcat(signame, " ");
  82.             x1 = strlen(sigdisc);
  83.             for(x2=x1; x2 < 26; x2++)
  84.                 strcat(sigdisc," ");
  85.             if(f_lines[line_cnt][78] == '*')
  86.                 strcpy(sigtype, "private");
  87.             else
  88.                 strcpy(sigtype, "public");
  89.             sprintf(who_am_i, "%s %s %s", signame, sigdisc, sigtype);
  90.  
  91.  
  92.             strip(who_am_i);
  93.             sprintf(buf128, "%2d) %s", line_cnt, who_am_i);
  94.             strip(buf128);
  95.             term_space(buf128);
  96.                 portsout(buf128);
  97.                 portsout("\n\r");
  98.         }
  99. next_read:
  100.         ++line_cnt;
  101.     }            /* end of while (fpt) */
  102.     if (line_cnt <= 1)
  103.         {
  104.         portsout("\n\r\n\rThere are no SPECIAL INTEREST GROUPS today!\n\r\n\r");
  105.         return;
  106.         }
  107.         portsout(CRLF);
  108.         portsout(" Q) Quit --- exit SIG function section");
  109.         portsout(CRLF);
  110.     fclose(fpt);
  111.         portsout(CRLF);
  112.  
  113.         portsout("Enter Selection ===> ");
  114.         portsin_cmp(choice, 2, "Qq");
  115.         portsout(CRLF);
  116.         *choice = toupper(*choice);
  117.  
  118.         if (*choice == 'Q')
  119.             return;
  120.  
  121.         index_value = atoi(choice);
  122.         if (index_value > 0 && index_value < line_cnt) {
  123.             if (dir_priv[index_value] <= user_priv) {
  124.                 parse_sig(f_lines[index_value]);
  125.                 if(!active) {
  126.                     sigreturn = 0;
  127.                     return;
  128.                 }
  129.                 continue;
  130.             }
  131.         }
  132.     }
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139. parse_sig(string, sn, sd, st )
  140.     char           *string;
  141. {
  142.  
  143.     register char  *file_ptr, *xptr;
  144.     register int    i, private;
  145.     char tempr[100], temps[100], tempt[100], tempu[100], tempv[100];
  146.     char tempw[100];
  147.     char sigfile[99];
  148.     char firstz[20], lastz[20];
  149.     extern int fds;
  150.     FILE *sigptr;
  151.  
  152.     file_ptr = buf128;
  153.     substr(string, buf128, 1, 50);
  154.     strip(buf128);
  155.     term_space(buf128);
  156.     if(string[78] != '*')
  157.         private = 0;
  158.     else
  159.         private = 1;
  160.     strcpy(tempr, ORGPATH);
  161.     file_ptr = (tempr + strlen(tempr));
  162.     i = 0;
  163.     who_am_I[0] = '\0';
  164.     xptr = who_am_I;
  165.     while ( string[i] != ' ') {
  166.         *file_ptr = string[i];
  167.         *xptr = string[i];
  168.         file_ptr++;
  169.         xptr++;
  170.         i++;
  171.     }
  172.     *file_ptr = '\0';
  173.     *xptr = '\0';
  174.     strcat(tempr, "/");
  175.     strcpy(temps, tempr);
  176.     strcpy(tempt, tempr);
  177.     strcpy(tempv, tempr);
  178.     strcpy(tempw, tempr);
  179.     strcpy(tempu, ORGPATH);
  180.     strcat(tempu, "helpsig.bbs");
  181.     strcat(tempt, "sigwelcome.bbs");
  182.     strcat(tempv, "sigentry.bbs");
  183.     strcat(tempw, "features.bbs");
  184.     strcat(temps, "files/");
  185.     strcat(tempr, "msgs/");
  186.     strcpy( sigfile, ORGPATH);
  187.     strcat( sigfile, who_am_I);
  188.     strcat( sigfile, ".bbs");
  189.     sigptr = fopen(sigfile, "r");
  190.     if( sigptr == NULL ) {
  191.         portsout("\n\r\n\rThat SIG is not available today.\n\r");
  192.         return;
  193.     }
  194.     while(1) {
  195.         if( fscanf( sigptr, "%s%s", firstz, lastz) == EOF ) {
  196.             fclose(sigptr);
  197.             if(private) {
  198.                 portsout("\n\rThis is a private SIG and your are not listed as a member.\n\r");
  199.                 sigptr = fopen(tempv, "r");
  200.                 if(sigptr != NULL)
  201.                     cmd_p(tempv);
  202.                 fclose(sigptr);
  203.                 return;
  204.                 }
  205.             portsout("\n\rYou are being registered into this SIG.\n\r");
  206.             sigptr = fopen(sigfile, "a");
  207.             fds = fileno(sigptr);
  208.             rewind(sigptr);
  209.             locking(fds, LK_LOCK, 0L);
  210.             fprintf( sigptr, "%s %s\n", w_fname, w_lname);
  211.             rewind(sigptr);
  212.             locking(fds, LK_UNLCK, 0L);
  213.             fclose( sigptr);
  214.             break;
  215.         }
  216.         if (( strcmp(firstz, w_fname) == 0) &&
  217.               (strcmp(lastz, w_lname) == 0)) {
  218.             portsout("\n\rYou are listed in this SIG.\n\r");
  219.             fclose( sigptr );
  220.             break;
  221.         }
  222.     }    
  223.     strcpy(save_info, who_am_I);
  224.     if(private)
  225.         strcat(save_info, "        - A Private SIG -");
  226.     else
  227.         strcat(save_info, "        - A Public SIG -");
  228.     sigptr = fopen(tempt, "r");
  229.     if( sigptr != NULL ) {
  230.         portsout(CRLF);
  231.         portsout(CRLF);
  232.         cmd_p(tempt);
  233.     }
  234.     fclose(sigptr);
  235.     if ((sigptr = fopen(callers, "a")) == NULL) {    /* create or open for
  236.                                      * append */
  237.         portsout(CRLF);
  238.         portsout("Can't open/create callers file!");
  239.         portsout(CRLF);
  240.         return;
  241.     }
  242.         i = fprintf(sigptr, "%s %s ","   Entered SIG ", save_info);
  243.         if (i < 0) {
  244.             portsout(CRLF);
  245.             portsout("Caller file has problem writing");
  246.             portsout(CRLF);
  247.         } else {
  248.             fputs("\n", sigptr);
  249.         }
  250.         fclose(sigptr);
  251.     while (1) {
  252.         if(!active)
  253.             return;
  254.         cmd_t();
  255.         portsout("\n\rSIG = ");
  256.         portsout(save_info);
  257.         portsout(CRLF);
  258.         bbsmenu(4,0);
  259.         portsin(firstz, 1);
  260.         portsout(CRLF);
  261.         *firstz = toupper(*firstz);
  262.         switch(firstz[0]) {
  263.         case ('A'):
  264.             if( !privmsg(mpZ))
  265.                 break;
  266.             additional(tempw);
  267.             break;
  268.         case ('G'):
  269.             if( !privmsg(mpG))
  270.                 break;
  271.             cmd_c();
  272.             break;
  273.         case ('?'):
  274.             if( !privmsg(mpZ))
  275.                 break;
  276.             cmd_p(tempu);
  277.             break;
  278.         case ('M'):
  279.             if( !privmsg(mpMS))
  280.                 break;
  281.             strcpy(m_pathname, tempr);
  282.             first_msg_in = FALSE;
  283.             hdrread();
  284.             check_mail();
  285.             msg_section(mpK);
  286.             break;
  287.         case ('F'):
  288.             if( !privmsg(mpF))
  289.                 break;
  290.             strcpy(f_pathname, temps);
  291.             strcpy(u_pathname, temps);
  292.             first_time_in = FALSE;
  293.             cmd_f();
  294.             break;
  295.         case ('L'):
  296.             return;
  297.             break;
  298.         case ('X'):
  299.             if( !privmsg(mpX))
  300.                 break;
  301.             cmd_x();
  302.             break;
  303.         case ('T'):
  304.             if( !privmsg(mpT))
  305.                 break;
  306.             toggle = !toggle;
  307.             if (toggle ) 
  308.                 portsout("\n\rStop Mode\n\r");
  309.             else
  310.                 portsout("\n\rContinuous Mode\n\r");
  311.         default:
  312.             break;
  313.         }
  314.     }
  315. }
  316.