home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume28 / yapp / part02 / change.c next >
Encoding:
C/C++ Source or Header  |  1994-05-29  |  11.7 KB  |  343 lines

  1. /* CHANGE.C */
  2. static    char sccsid[] = "@(#)change.c 1.3 94/01/20 (c)1993 thalerd";
  3. /* PHASE 1: Conference Subsystem 
  4.          Be able to enter/exit the program, and move between conferences
  5.          Commands: join, next, quit, source
  6.          Files: rc files, cflist, login, logout, bull
  7. */
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include <sys/types.h>
  13. #include <sys/stat.h>
  14. #include <errno.h>
  15. #include <time.h>
  16. #include "config.h"
  17. #include "struct.h"
  18. #include "globals.h"
  19. #include "conf.h"
  20. #include "lib.h"
  21. #include "joq.h"
  22. #include "sum.h"
  23. #include "item.h"
  24. #include "range.h"
  25. #include "macro.h"
  26. #include "system.h"
  27. #include "sep.h"
  28. #include "xalloc.h"
  29. #include "stats.h" /* for get_config */
  30.  
  31. char *cfiles[]={ "logi_n", "logo_ut", "in_dex", "b_ull",
  32.      "we_lcome", "rc", "sec_ret", "ul_ist", "" };
  33.  
  34. /******************************************************************************/
  35. /* CHANGE SYSTEM PARAMETERS                                                   */
  36. /******************************************************************************/
  37. int              /* RETURNS: (nothing)     */
  38. change(argc,argv) /* ARGUMENTS:             */
  39. int    argc;      /*    Number of arguments */
  40. char **argv;      /*    Argument list       */
  41. {
  42.    char buff[MAX_LINE_LENGTH];
  43.    char done;
  44.    short i,j;
  45.     char **config;
  46.  
  47.    if (argc<2) {
  48.       printf("Change what?\n");
  49.       return 1;
  50.    }
  51.  
  52.    for (j=1; j<argc; j++) {
  53.  
  54.       /* Security measure */
  55.       if (mode==M_SANE && match(argv[j],"noverbose"))
  56.          continue;
  57.  
  58.       /* Process changing flags */
  59.       for (done=0,i=0; i<NUM_OPTIONS; i++) {
  60.          if (match(argv[j],option[i].name)) {
  61.             flags |=  option[i].mask;
  62.             done=1;
  63.             break;
  64.          } else if(!strncmp(argv[j],"no",2) && match(argv[j]+2,option[i].name)){
  65.             flags &= ~option[i].mask;
  66.             done=1;
  67.             break;
  68.          }
  69.       }
  70.       if (done) continue;
  71.  
  72.       if (match(argv[j],"n_ame")
  73.        || match(argv[j],"u_ser")) {
  74.          printf("Your old name is: %s\n",st_glob.fullname);
  75.          printf("Enter replacement or return to keep old? ");
  76.          if (ngets(buff,st_glob.inp) && strlen(buff))
  77.             strcpy(st_glob.fullname,buff);
  78.          else
  79.             printf("Name not changed.\n");
  80.       } else if (match(argv[j],"p_assword")
  81.        ||        match(argv[j],"passwd")) {      unix_cmd("/bin/passwd");
  82.       } else if (match(argv[j],"li_st")) {       edit(work,".cflist",0);
  83.       } else if (match(argv[j],"ig_noreeof")) {  unix_cmd("/bin/stty eof ^-");
  84.       } else if (match(argv[j],"noig_noreeof")){ unix_cmd("/bin/stty eof ^D");
  85.       } else if (match(argv[j],"ch_at")) {       unix_cmd("mesg y");
  86.       } else if (match(argv[j],"noch_at")) {     unix_cmd("mesg n");
  87.       } else if (match(argv[j],"resign")) {      command("resign",0);
  88.       } else if (match(argv[j],"sa_ne")) {       undefine(DM_SANE);
  89.       } else if (match(argv[j],"supers_ane")) {  undefine(DM_SANE|DM_SUPERSANE);
  90.       } else if (match(argv[j],"save_seen")) {
  91.          if (confidx>=0) {
  92.                 if (config = get_config(confidx))
  93.                    write_part(config[CF_PARTFILE]);
  94.          }
  95.       } else if (match(argv[j],"sum_mary")) {
  96.          if (!(st_glob.c_status & CS_FW)) {
  97.             wputs("Sorry, you can't do that!\n");
  98.             return 1;
  99.          }
  100.          printf("Regenerating summary file; please wait\n");
  101.          refresh_sum(0,confidx,sum,part,&st_glob);
  102.          save_sum(sum,(short)-1,confidx,&st_glob);
  103.       } else if (match(argv[j],"nosum_mary")) {
  104.          if (!(st_glob.c_status & CS_FW)) {
  105.             wputs("Sorry, you can't do that!\n");
  106.             return 1;
  107.          }
  108.          sprintf(buff,"%s/sum",conflist[confidx].location);
  109.          rm(buff,SL_OWNER);
  110.       } else if (match(argv[j],"rel_oad")) {
  111.          if (confidx>=0) {
  112.                 if (config = get_config(confidx))
  113.                    read_part(config[CF_PARTFILE],part,&st_glob,confidx);
  114.          }
  115.          st_glob.sumtime = 0;
  116.       } else {
  117.          for (i=0; cfiles[i][0]; i++) {
  118.             if (match(argv[j],cfiles[i])) {
  119.                char file[MAX_LINE_LENGTH],bufr[MAX_LINE_LENGTH];
  120.    
  121.                if (!(st_glob.c_status & CS_FW)) {
  122.                   printf("You aren't a fair-witness.\n");
  123.                   return 1;
  124.                }
  125.                sprintf(file,"%s/%s",
  126.                 conflist[confidx].location,compress(cfiles[i]));
  127.                sprintf(bufr,"%s/cf.buffer",work);
  128.    
  129.                /* Copy file to cf.buffer owned by user */
  130.                copy_file(file,bufr,SL_USER);
  131.    
  132.                if (!edit(bufr,(char*)0,0)) 
  133.                   printf("UNK Aborting...\n");
  134.                else {
  135.                   if (get_yes("Ok to install this? "))
  136.                      copy_file(bufr,file,SL_OWNER);
  137.                   rm(bufr,SL_USER);
  138.                }
  139.                return 1;
  140.             }
  141.          }
  142.          printf("Bad parameters near \"%s\"\n",argv[j]);
  143.          return 2;
  144.       }
  145.    }
  146.    return 1;
  147. }
  148.  
  149. /******************************************************************************/
  150. /* DISPLAY SYSTEM PARAMETERS                                                  */
  151. /******************************************************************************/
  152. int               /* RETURNS: (nothing)     */
  153. display(argc,argv) /* ARGUMENTS:             */
  154. int    argc;       /*    Number of arguments */
  155. char **argv;       /*    Argument list       */
  156. {
  157.    static time_t newmail=0;
  158.    time_t t;
  159.    char *noconferr="Not in a conference!\n",*var;
  160.    short  i,done,j;
  161.     char **config;
  162.  
  163.    for (j=1; j<argc; j++) {
  164.  
  165.       /* Display flag settings */
  166.       for (done=0,i=0; i<NUM_OPTIONS; i++) {
  167.          if (match(argv[j],option[i].name)) {
  168.             printf("%s flag is %s\n",compress(option[i].name),
  169.              (flags & option[i].mask)? "on" : "off" );
  170.             done=1;
  171.             break;
  172.          }
  173.       }
  174.       if (match(argv[j],"ma_iltext")) {
  175.          refresh_stats(sum,part,&st_glob);
  176.          check_mail(1);
  177.       }
  178.       if (done) continue;
  179.  
  180.       if (match(argv[j],"fl_ags")) {
  181.          for (done=0,i=0; i<NUM_OPTIONS; i++) {
  182.             printf("%-10s : %s%s",compress(option[i].name),
  183.              (flags & option[i].mask)? "ON " : "off",
  184.          (i%4 == 3)? "\n":"    ");
  185.          }
  186.      if (NUM_OPTIONS%4) printf("\n");
  187.       } else if (match(argv[j],"c_onference")) {
  188.          sepinit(IS_START);
  189.          confsep("confmsg",confidx,&st_glob,part,0);
  190.       } else if (match(argv[j],"conferences")) {
  191.          command("list",0);
  192.       } else if (match(argv[j],"d_ate") || match(argv[j],"t_ime")) {
  193.          (void)time(&t);
  194.          (void)printf("Time is %s",ctime(&t));
  195.       } else if (match(argv[j],"def_initions") || match(argv[j],"ma_cros")) {
  196.          define(1,(char **)0);
  197.       } else if (match(argv[j],"v_ersion")) {
  198.          struct stat st;
  199.          char path[MAX_LINE_LENGTH];
  200.  
  201.          (void)printf("YAPP 2.%d  Copyright (c)1993 David G. Thaler\n",VERSION);
  202.          sprintf(path,"%s/registered",bbsdir);
  203.          if (!stat(path,&st)) 
  204.             more(bbsdir,"registered");
  205.          else
  206.             printf("Shareware version: Currently unregistered\n");
  207.       } else if (match(argv[j],"ret_ired")) {
  208.          int c=0;
  209.  
  210.          refresh_sum(0,confidx,sum,part,&st_glob);
  211.          printf("Items retired:");
  212.          for (i=0; i<MAX_ITEMS; i++) {
  213.             if (sum[i].flags & IF_RETIRED) {
  214.                if (!c) printf("\n");
  215.                printf("%4d",i+1);
  216.                c++;
  217.             }
  218.          }
  219.          if (c)
  220.             printf("\nTotal: %d items retired.\n",c);
  221.          else
  222.             printf(" <none>\n");
  223.       } else if (match(argv[j],"fro_zen")) {
  224.          int c=0;
  225.         
  226.          refresh_sum(0,confidx,sum,part,&st_glob);
  227.          printf("Items frozen:");
  228.          for (i=0; i<MAX_ITEMS; i++) {
  229.             if (sum[i].flags & IF_FROZEN) {
  230.                if (!c) printf("\n");
  231.                printf("%4d",i+1);
  232.                c++;
  233.             }
  234.          }
  235.          if (c)
  236.             printf("\nTotal: %d items frozen.\n",c);
  237.          else
  238.             printf(" <none>\n");
  239.       } else if (match(argv[j],"f_orgotten")) {
  240.          int c=0;
  241.          printf("Items forgotten:");
  242.          for (i=0; i<MAX_ITEMS; i++) {
  243.             if (part[i].nr<0) {
  244.                if (!c) printf("\n");
  245.                printf("%4d",i+1);
  246.                c++;
  247.             }
  248.          }
  249.          if (c)
  250.             printf("\nTotal: %d items forgotten.\n",c);
  251.          else
  252.             printf(" <none>\n");
  253.       } else if (match(argv[j],"sup_eruser")) {
  254.          printf("fw superuser %s\n",(st_glob.c_status & CS_FW)?"yes":"no");
  255.       } else if (match(argv[j],"fw_slist")
  256.        ||        match(argv[j],"fair_witnesslist")
  257.        ||        match(argv[j],"fair_witnesses")) {
  258.          if (confidx<0) wputs(noconferr);
  259.          else {
  260.                 if (config = get_config(confidx))
  261.                printf("fair witnesses: %s\n",config[CF_FWLIST]);
  262.          }
  263.       } else if (match(argv[j],"i_ndex")
  264.        ||        match(argv[j],"ag_enda")) {
  265.          sepinit(IS_START);
  266.          confsep("indxmsg",confidx,&st_glob,part,0);
  267.       } else if (match(argv[j],"li_st")) {
  268.          refresh_list();
  269.          for (i=0; i<xsizeof(cflist); i++) 
  270.             printf("%s %s\n",(current==i)? "-->" : "   ",cflist[i]);
  271.       } else if (match(argv[j],"b_ulletin")) {
  272.          sepinit(IS_START);
  273.          confsep("bullmsg",confidx,&st_glob,part,0);
  274.       } else if (match(argv[j],"w_elcome")) {
  275.          sepinit(IS_START);
  276.          confsep("wellmsg",confidx,&st_glob,part,0);
  277.       } else if (match(argv[j],"logi_n")) {
  278.          sepinit(IS_START);
  279.          confsep("linmsg",confidx,&st_glob,part,0);
  280.       } else if (match(argv[j],"logo_ut")) {
  281.          sepinit(IS_START);
  282.          confsep("loutmsg",confidx,&st_glob,part,0);
  283.       } else if (match(argv[j],"ul_ist")) {
  284.          if (confidx<0) wputs(noconferr);
  285.          else more(conflist[confidx].location,"ulist");
  286.       } else if (match(argv[j],"rc")) {
  287.          if (confidx<0) wputs(noconferr);
  288.          else more(conflist[confidx].location,"rc");
  289.       } else if (match(argv[j],"log_messages")) {
  290.          if (confidx<0) wputs(noconferr);
  291.          else {
  292.             printf("login message:\n");
  293.             more(conflist[confidx].location,"login");
  294.             printf("logout message:\n");
  295.             more(conflist[confidx].location,"logout");
  296.          }
  297.       } else if (match(argv[j],"n_ew")) {
  298.          refresh_sum(0,confidx,sum,part,&st_glob);
  299.          sepinit(IS_ITEM);
  300.          open_pipe();
  301.          confsep("linmsg",confidx,&st_glob,part,0);
  302.          check_mail(1);
  303.       } else if (match(argv[j],"n_ame") || match(argv[j],"u_ser"))
  304.          (void)printf("User: %s\n",st_glob.fullname);
  305.       else if (match(argv[j],"p_articipants")) {
  306.          participants(0,(char**)0);
  307.       } else if (match(argv[j],"s_een")) {
  308.          int c=0;
  309.          FILE *fp;
  310.  
  311.          refresh_sum(0,confidx,sum,part,&st_glob);
  312.    
  313.          /* Display seen item status */
  314.          open_pipe();
  315.          if (status & S_REDIRECT) fp = st_glob.outp;
  316.          else                     fp = stdout;
  317.          fprintf(fp,"item se re fl   lastseen             etime                mtime\n\n");
  318.          for (i=0; i<MAX_ITEMS; i++) {
  319.             if (!part[i].nr) continue;
  320.             fprintf(fp,"%4d %2d %2d %2X   %s %s %s\n",i+1,abs(part[i].nr),sum[i].nr,
  321.               sum[i].flags, get_date(part[i].last,0)+4, get_date(sum[i].first,0)+4,
  322.               get_date(sum[i].last,0)+4);
  323.             c++;
  324.          }
  325.          fprintf(fp,"total %d items in seen map\n\n",c);
  326.       } else if (match(argv[j],"s_ize"))
  327.          xstat();
  328.       else if (match(argv[j],"strings"))
  329.          xdump();
  330.       else if (match(argv[j],"fds"))
  331.          mdump();
  332.       else if (match(argv[j],"w_hoison")) 
  333.          unix_cmd("who");
  334.       else if (var=expand(argv[j],~0))
  335.          printf("%s = %s\n",argv[j],var);
  336.       else {
  337.          printf("Bad parameters near \"%s\"\n",argv[j]);
  338.          return 2;
  339.       }
  340.    }
  341.    return 1;
  342. }
  343.