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

  1. /*------------------------------------------------------------------------
  2.        Name: bbscbult.c
  3.    Comments: Display file areas and select one
  4.   ------------------------------------------------------------------------*/
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <ctype.h>
  9. #include <signal.h>
  10. #include "bbscdef.h"
  11.  
  12.  
  13. extern int      user_priv;
  14. extern char     port_id[4];
  15. extern timer(), mon_toggle(), sys_toggle(), chat(), hanged();
  16.  
  17.  
  18. additional(addfile)
  19. char *addfile;
  20. {
  21.     FILE           *fpt, *fopen();
  22.     char           *fgets(), *getenv();
  23.     char            choice[4];
  24. #ifndef SYSV
  25.     char            dir_priv_ascii[7];
  26. #endif
  27. #ifdef SYSV
  28.     char            dir_priv_ascii[20];
  29. #endif
  30.     char           *buf_ptr;
  31.     char        af[99];
  32.     int             line_cnt, ret, i;
  33.     int             index_value, ptr;
  34.     int             length;
  35.  
  36.     strcpy ( af, addfile );
  37.     while (1) {
  38.  
  39. do_again:
  40.  
  41.     if ((fpt = fopen(af, "r")) == NULL) {
  42.         portsout("\n\r\n\rThere are no user supplied functions today!\n\r\n\r");
  43.         return ;
  44.     }
  45.     portsout("\n\r\n\r\n\r                  *********************************\n\r");
  46.     portsout("                  * Available Routines to Execute *\n\r");
  47.     portsout("                  *********************************\n\r\n\r");
  48.     portsout("\n\r                      Program                          Description   \n\r");
  49.     portsout("    ================================================== ================== \n\r");
  50.  
  51.     line_cnt = 0;
  52.     while (fpt) {
  53.         zfl(f_lines[line_cnt], 83);
  54.         if ((fgets(f_lines[line_cnt], 82, fpt)) == NULL) {
  55.             if (line_cnt == 0) {
  56.                 portsout("\n\rEOF Unexpected in Function List: Notify Sysop!\n\r");
  57.                 return;
  58.             }
  59.             break;    /* if not 1st line */
  60.         }        /* end of if ((fgets)) */
  61.         if (line_cnt > 0) {
  62.             length = strlen(f_lines[line_cnt]);
  63.             length -= 74;
  64.             if(length > 6)
  65.                 length = 6;
  66.             substr(f_lines[line_cnt], dir_priv_ascii, 74, length);
  67.             dir_priv[line_cnt] = atoi(dir_priv_ascii);
  68.             if (dir_priv[line_cnt] > user_priv)
  69.                 goto next_read;
  70.             strcpy(who_am_i, f_lines[line_cnt]);
  71.             buf_ptr = who_am_i;
  72.             buf_ptr += 73;
  73.             strip(who_am_i);
  74.             for (ptr = 0; ptr < 6; ptr++)
  75.                 *buf_ptr++ = '\0';
  76.             *buf_ptr='\0';
  77.             sprintf(buf128, "%2d) %s", line_cnt, who_am_i);
  78.             strip(buf128);
  79.             term_space(buf128);
  80.             portsout(buf128);
  81.             portsout("\n\r");
  82.         }
  83. next_read:
  84.         ++line_cnt;
  85.     }            /* end of while (fpt) */
  86.     if (line_cnt <= 1)
  87.         {
  88.         portsout("\n\r\n\rThere are no user supplied functions today!\n\r\n\r");
  89.         return;
  90.         }
  91.     portsout(CRLF);
  92.     portsout(" Q) Quit --- exit user function section");
  93.     portsout(CRLF);
  94.     fclose(fpt);
  95.     portsout(CRLF);
  96.  
  97.         portsout("Enter Selection ===> ");
  98.         portsin_cmp(choice, 2, "Qq");
  99.         portsout(CRLF);
  100.         *choice = toupper(*choice);
  101.  
  102.         if (*choice == 'Q')
  103.             return;
  104.  
  105.  
  106.         index_value = atoi(choice);
  107.         if (index_value > 0 && index_value < line_cnt) {
  108.             if (dir_priv[index_value] <= user_priv) {
  109.                 parse_fun(f_lines[index_value]);
  110.                 continue;
  111.             }
  112.         }
  113.     }
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120. parse_fun(string)
  121.     char           *string;
  122. {
  123.  
  124.     register char  *file_ptr, *xptr;
  125.     register int    i;
  126.  
  127.     file_ptr = buf128;
  128.     substr(string, buf128, 1, 50);
  129.     strip(buf128);
  130.     term_space(buf128);
  131.     if(string[78] != '*')
  132.     {
  133.         strcat(buf128," > ");
  134.         strcat(buf128,TMPFILE);
  135.         strcat(buf128,port_id);
  136.     }
  137.     else
  138.     {
  139.         portsout("\n\r\n\rSwitching to default Unix Parameters!\n\r\n\r");
  140.         restoremodes();
  141.         portrst();
  142.         STDerr = freopen("/dev/tty","w+", stderr);
  143.     }
  144.  
  145.  
  146.         (void)system(buf128);
  147.     if(string[78] != '*')
  148.     {
  149.         strcpy(buf128,TMPFILE);
  150.         strcat(buf128,port_id);
  151.         cmd_p(buf128);
  152.     }
  153.     else
  154.     {
  155.         strcpy(buf128, STDERR);
  156.         strcat(buf128, port_id);
  157.         STDerr = freopen(buf128,"w+",stderr);
  158.         portinit();
  159.         setmodes();
  160.         signal(SIGALRM, timer);
  161.         signal(SIGHUP, hanged);
  162.         signal(SIGUSR1, mon_toggle);
  163.         signal(SIGUSR2, sys_toggle);
  164.         signal(SIGPIPE, chat);
  165.         portsout("\n\r\n\rBack to BBS terminal parameters!\n\r\n\r");
  166.     }
  167. }
  168. zfl(ptr, n)
  169. char *ptr;
  170. int n;
  171. {
  172.     while(n) {
  173.         *ptr++ = '\0';
  174.         n--;
  175.     }
  176. }
  177.