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

  1. /*------------------------------------------------------------------------
  2.        Name: bbscarea.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 "bbscdef.h"
  10.  
  11. int             set_yet = FALSE;
  12. extern int      user_priv;
  13.  
  14.  
  15. change_area(type) int 
  16.     type;
  17. {
  18.     FILE           *fpt, *fopen();
  19.     char           *fgets(), *getenv();
  20.     char            choice[4];
  21. #ifndef SYSV
  22.     char            dir_priv_ascii[7];
  23. #endif
  24. #ifdef SYSV
  25.     char            dir_priv_ascii[20];
  26. #endif
  27.     char           *buf_ptr;
  28.     int             line_cnt, ret, i;
  29.     int             index_value, ptr;
  30.     int        allx;
  31.  
  32.     if(type == -1)
  33.         return;
  34.  
  35.     if(type > 1000) {
  36.         type -=1000;
  37.         allx = 1;
  38.     }
  39.     else
  40.         allx = 0;
  41.  
  42. do_again:
  43.     strcpy(buf128, AREAS);
  44.  
  45.     if ((fpt = fopen(buf128, "r")) == NULL) {
  46.         portsout("\n\rError Opening File Area List: Notify Sysop!\n\r");
  47.         return (-1);
  48.     }
  49.     if(!type) {
  50.         portsout("\n\r    Directory     Description                                      Upload Path\n\r");
  51.         portsout("    ============= ==========================================       ============\n\r");
  52.     }
  53.     line_cnt = 0;
  54.     while (fpt) {
  55.         zfl(f_lines[line_cnt], 81);
  56.         if ((fgets(f_lines[line_cnt], 80, fpt)) == NULL) {
  57.             if (line_cnt == 0) {
  58.                 portsout("\n\rEOF Unexpected in File Area List: Notify Sysop!\n\r");
  59.                 return (-1);
  60.             }
  61.             break;    /* if not 1st line */
  62.         }        /* end of if ((fgets)) */
  63.         if (line_cnt > 0) {
  64.             substr(f_lines[line_cnt], dir_priv_ascii, 57, 5);
  65.             dir_priv[line_cnt] = atoi(dir_priv_ascii);
  66.             if (dir_priv[line_cnt] > user_priv)
  67.                 goto next_read;
  68.             strcpy(who_am_i, f_lines[line_cnt]);
  69.             buf_ptr = who_am_i;
  70.             buf_ptr += 56;
  71.             for (ptr = 0; ptr < 5; ptr++)
  72.                 *buf_ptr++ = ' ';
  73.             sprintf(buf128, "%2d) %s", line_cnt, who_am_i);
  74.             if (!type) {
  75.                 strip(buf128);
  76.                 term_space(buf128);
  77.                 portsout(buf128);
  78.                 portsout("\n\r");
  79.             }
  80.         }
  81. next_read:
  82.         ++line_cnt;
  83.     }            /* end of while (fpt) */
  84.     if (set_yet && !type) {
  85.         portsout(CRLF);
  86.         portsout(" Q) Quit to Previous Menu");
  87.     }
  88.     if(!type)portsout(CRLF);
  89.     fclose(fpt);
  90.     if(!type)portsout(CRLF);
  91.     if (line_cnt <= 1)
  92.         return;
  93.  
  94.     while (1) {
  95.         if (!type) {
  96.             portsout("Enter Selection ===> ");
  97.             portsin_cmp(choice, 2, "Qq");
  98.             portsout(CRLF);
  99.             *choice = toupper(*choice);
  100.  
  101.             if (*choice == 'Q' && set_yet)
  102.                 return (-1);
  103.  
  104.  
  105.             index_value = atoi(choice);
  106.         } else
  107.             index_value = type;
  108.         if(allx && index_value >= line_cnt)
  109.             return(999);
  110.         if (index_value > 0 && index_value < line_cnt) {
  111.             if (dir_priv[index_value] <= user_priv) {
  112.                 parse_args(f_lines[index_value]);
  113.                 set_yet = TRUE;
  114.                 itoa(buf128, index_value);
  115.                 if( !allx) {
  116.                     if(index_value > 9)
  117.                         strcpy(l_f_base, buf128);
  118.                     else {
  119.                         strcpy(l_f_base, "0");
  120.                         strcat(l_f_base, buf128);
  121.                     }
  122.                     rewritx();
  123.                 }
  124.                 return (0);
  125.             }
  126.         }
  127.         if( type != 0 ) {
  128.             type = 0;
  129.             if(allx)
  130.                 return(99);
  131.             portsout("\n\rInvalid directory request!\n\r");
  132.             goto do_again;
  133.         }
  134.     }
  135. }
  136.  
  137. allnew()
  138. {
  139.     char savef[99], saveu[99];
  140.     char savea[99], savep[99];
  141.     char strg[15], choice[5];
  142.     int i, ret, choi;
  143.     char *fileptr;
  144.     strcpy(savef, f_pathname);
  145.     strcpy(saveu, u_pathname);
  146.     strcpy(savea, area_name);
  147.     strcpy(savep, f_pathtext);
  148.     bbsmenu(5,0);
  149.     portsin(choice, 1);
  150.     portsout(CRLF);
  151.     switch(choice[0]) {
  152.     case ('L'):
  153.     case ('l'):
  154.         choi = 1;
  155.         portsout("\n\r\n\rInput file name substring (max 14 characters): ");
  156.         portsin(strg, 14);
  157.         ret = strlen(strg);
  158.         portsout(CRLF);
  159.         if (!ret)
  160.             return;
  161.         fileptr = strchr(strg, '*');
  162.         if( fileptr != NULL ) {
  163.             portsout("\n\rDo not use an asterisk as part of the string.\n\r\n\r");
  164.             return;
  165.         }
  166.         break;
  167.     case ('F'):
  168.     case ('f'):
  169.         choi = 2;
  170.         break;
  171.     case ('N'):
  172.     case ('n'):
  173.         choi = 3;
  174.         break;
  175.     case ('R'):
  176.     case ('r'):
  177.         choi = 4;
  178.         break;
  179.     default:
  180.         return;
  181.     }
  182.     for( i=1001; i<1100; i++) {
  183.         if (stop_that) {
  184.             stop_that = FALSE;
  185.             strcpy(f_pathname, savef);
  186.             strcpy(u_pathname, saveu);
  187.             strcpy(area_name, savea);
  188.             strcpy(f_pathtext, savep);
  189.             return;
  190.         }
  191.         ret = change_area(i);
  192.         if (stop_that) {
  193.             stop_that = FALSE;
  194.             strcpy(f_pathname, savef);
  195.             strcpy(u_pathname, saveu);
  196.             strcpy(area_name, savea);
  197.             strcpy(f_pathtext, savep);
  198.             return;
  199.         }
  200.         if( ret == 999) {
  201.             strcpy(f_pathname, savef);
  202.             strcpy(u_pathname, saveu);
  203.             strcpy(area_name, savea);
  204.             strcpy(f_pathtext, savep);
  205.             return;
  206.         }
  207.         if( ret == 99)
  208.             continue;
  209.         portsout("\n\r-------------------------------------------------------------------\n\r");
  210.         portsout("\n\r\n\rFile listing for area '");
  211.         portsout(area_name);
  212.         portsout("'\n\r");
  213.         switch(choi){
  214.         case (1):
  215.             file_loc(strg);
  216.             break;
  217.         case (2):
  218.             file_l();
  219.             break;
  220.         case (3):
  221.             file_n();
  222.             break;
  223.         case (4):
  224.             file_r();
  225.             break;
  226.         }
  227.     }
  228.     strcpy(f_pathname, savef);
  229.     strcpy(u_pathname, saveu);
  230.     strcpy(area_name, savea);
  231.     strcpy(f_pathtext, savep);
  232.     return;
  233. }
  234.         
  235.         
  236.  
  237.  
  238.  
  239.  
  240. parse_args(string)
  241.     char           *string;
  242. {
  243.  
  244.     register char  *file_ptr, *name_ptr, *up_ptr, *desc_ptr;
  245.     register int    i;
  246.  
  247.     strcpy(f_pathname, ORGPATH);
  248.     strcpy(u_pathname, ORGPATH);
  249.     file_ptr = (f_pathname + strlen(f_pathname));
  250.     up_ptr = (u_pathname + strlen(u_pathname));
  251.  
  252.     name_ptr = area_name;
  253.     desc_ptr = f_pathtext;
  254.  
  255.     i = 0;
  256.     while (string[i] != ' ') {
  257.         *file_ptr = string[i];
  258.         *name_ptr = string[i];
  259.         ++file_ptr;
  260.         ++name_ptr;
  261.         ++i;
  262.     }
  263.     *file_ptr = '/';
  264.     ++file_ptr;
  265.     *file_ptr = '\0';
  266.     *name_ptr = '\0';
  267.  
  268.     for (i = 14; i < 61; ++i) {
  269.         *desc_ptr = string[i];
  270.         ++desc_ptr;
  271.     }
  272.     *desc_ptr = '\0';
  273.  
  274.     i = 63;
  275.     while ((string[i] != ' ') && (string[i] != '\n')) {
  276.         *up_ptr = string[i];
  277.         ++up_ptr;
  278.         ++i;
  279.     }
  280.     *up_ptr = '/';
  281.     ++up_ptr;
  282.     *up_ptr = '\0';
  283. }
  284.