home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mm / mm-0.90 / sys-prof.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-18  |  11.3 KB  |  342 lines

  1. /*
  2.  * Copyright (c) 1986, 1990 by The Trustees of Columbia University in
  3.  * the City of New York.  Permission is granted to any individual or
  4.  * institution to use, copy, or redistribute this software so long as it
  5.  * is not sold for profit, provided this copyright notice is retained.
  6.  */
  7.  
  8. #ifndef lint
  9. static char *rcsid = "$Header: /f/src2/encore.bin/cucca/mm/tarring-it-up/RCS/sys-prof.c,v 2.1 90/10/04 18:26:50 melissa Exp $";
  10. #endif
  11.  
  12. /*
  13.  * sys-profile:
  14.  * like mm's profile command, but this writes the system-wide mminit file
  15.  */
  16.  
  17. #include "mm.h"
  18. #include "ccmd.h"
  19. #include "set.h"            /* so we can set things */
  20. #include "version.h"
  21.  
  22. #define comment cmcsb._cmntb        /* comment character */
  23. #define tempfilename "mm.conf"
  24. #define Prompt(x) {cmseter(); prompt(x); cmsetrp();}
  25.  
  26. int cmdbuf[BUFLEN];            /* ccmd work buffers */
  27. static buffer wrkbuf;
  28. buffer atmbuf, sprbuf;
  29. extern char cmcont;            /* line continuation character */
  30. pval pv;                /* parse value */
  31. fdb *used;                /* which fdb was used to parse field */
  32.  
  33. /* break mask for an email address */
  34. static brktab rembrk = {        /* break table for remote user name */
  35.     {                    /* letters, $ only in first position */
  36.       0xff, 0xff, 0xff, 0xff, 0xf7, 0xef, 0xff, 0xff,
  37.       0x80, 0x00, 0x00, 0x1e, 0x80, 0x00, 0x00, 0x1f
  38.     },
  39.     {                    /* letters, digits and hyphens here */
  40.       0xff, 0xff, 0xff, 0xff, 0xb2, 0xe9, 0x00, 0x3f,
  41.       0x00, 0x00, 0x00, 0x1e, 0x80, 0x00, 0x00, 0x1f
  42.     }                    /* (also @+%_.!) */
  43. };
  44. static fdb remarks = { _CMFLD, CM_SDH, NULL, NULL, "local bug-report address",
  45.                NULL, &rembrk };
  46. static fdb number = { _CMNUM, CM_SDH, NULL, (pdat) 10,
  47.               "number from above list" };
  48. extern keytab formattab;
  49. extern char *defmailfile[];
  50. static fdb formatfdb = { _CMKEY, 0 , NULL, (pdat)&formattab, 
  51.                  "default format, ", NULL, NULL };
  52.  
  53.  
  54. char *bugmmcomment="bug-mm is a local consultant who handles most mm problems";
  55.  
  56. char *paths[] = {
  57.     "bug-mm@columbia.edu", 
  58.     "rutgers!columbia!bug-mm",
  59.     "bug-mm%columbia@cuvma.bitnet"
  60.  /* "cunixc::bug-mm", */
  61.     };
  62. numpaths = sizeof(paths) / sizeof(char *);
  63.  
  64. static keywrd yesnokeys[] = {
  65.     { "always", 0, SET_YES },        /* 0 */
  66.     { "false", 0, SET_NO },        /* 1 */
  67.     { "never", 0, SET_NO },        /* 2 */
  68.     { "no", 0, SET_NO },        /* 3 */
  69.     { "ok", 0, SET_YES },        /* 4 */
  70.     { "true", 0, SET_YES },        /* 5 */
  71.     { "yes", 0, SET_YES },        /* 6 */
  72.     { "0", KEY_INV, SET_NO },        /* 7 */
  73.     { "1", KEY_INV, SET_YES },        /* 8 */
  74.     { "n", KEY_ABR|KEY_INV, (keyval) 3 } /* this means "no" */
  75. };
  76.  
  77. keytab yesnotab = { sizeof(yesnokeys) / sizeof(keywrd), yesnokeys };
  78. fdb yesno_fdb = { _CMKEY, 0, NULL, (pdat) &yesnotab, "keyword, "};
  79.  
  80. /*
  81.  * here it is, here's main!!!
  82.  */
  83. main(argc,argv)
  84. int argc;
  85. char *argv[];
  86. {
  87.     FILE *tmpfile;
  88.     int i, gnu, format;
  89.     int noremarks = TRUE;        /* no local remarks address */
  90.     char *progname;
  91.  
  92.     init();
  93.     if ((tmpfile = fopen (tempfilename, "w")) == NULL) {
  94.     fprintf (stderr, "Can't open temp file for composing %s\n", SYSINIT);
  95.     cmdone();
  96.     exit();
  97.     }
  98.  
  99.     /* get name without path */
  100.     if ((progname = rindex (argv[0], '/')) == NULL)
  101.     progname = argv[0];
  102.     else
  103.     progname++;
  104.  
  105.     printf("\n\
  106. This is the %s program, which will help you set up a\n\
  107. site-wide initialization file for MM.  It asks you a series of\n\
  108. questions and then makes MM remember them (via the\n\
  109. %s file).\n\
  110. \n\
  111. You will not be bound to these choices -- the init file is plain text\n\
  112. and can be easily modified with your favorite editor.  Every time a\n\
  113. user on your system starts up MM, this environment will be read in.\n\
  114. \n\
  115. Everything set in this initialization file can be changed by\n\
  116. individual users to suit their own needs.  MM provides various means\n\
  117. to help them write their own init file.  The variables that they are\n\
  118. unlikely to want to change will be invisible, but still valid.\n\
  119. \n\
  120. We will not go through all of the settable variables, but will attempt\n\
  121. to set those options that seem most important in a site-wide\n\
  122. initialization file.  To set the fancier options, you can use the SET\n\
  123. command along with CREATE-INIT, then merge the resulting personal init\n\
  124. file with %s, or just use an editor on the\n\
  125. sysem-wide initialization file.  The HELP SET <option-name> command,\n\
  126. or the SHOW command will document each particular option, e.g.\n\
  127. \"help set default-mail-type\".\n\n",
  128.        progname, SYSINIT, SYSINIT);    
  129.     hold();
  130.  
  131.     fprintf (tmpfile, "\
  132. %s System-wide initialization file for %s\n\
  133. %s note that all lines beginning with \"%s\" are comments\n",
  134.          comment, MM_VERSION, comment, comment);
  135.  
  136.     printf ("\
  137. MM supports various different mail formats.  To find out about them,\n\
  138. type \"help ?\" inside MM, and try the various keywords listed as\n\
  139. formats.  Please pick one to be the default for your site.  Briefly,\n\
  140. \"mtxt\" format is the fastest, but is not compatible with any other\n\
  141. UNIX mail programs, while \"mbox\" is compatible with the Berkeley\n\
  142. mail(1) program provided with UNIX.  Hit a question mark to see all\n\
  143. the options.\n\n");
  144.  
  145.     fprintf (tmpfile, "\n%s default mail format\n", comment);
  146.     Prompt ("Default mail format for your site: ");
  147.     parse(&formatfdb, &pv, &used);
  148.     strcpy  (sprbuf, atmbuf);
  149.     format = pv._pvkey;
  150.     confirm();
  151.     fprintf (tmpfile, "set default-mail-type %s\n", sprbuf);
  152.  
  153.     printf ("The default name for that kind of mail file is %s.\n",
  154.         defmailfile[format]);
  155.     fprintf (tmpfile, "%s default mail file\n", comment);
  156.     Prompt ("Shall I set MM to look for that? ");
  157.     parse (&yesno_fdb, &pv, &used);
  158.     confirm();
  159.     if (pv._pvint)
  160.     fprintf (tmpfile, "set mail-file %s\n", defmailfile[format]);
  161.     else {
  162.     printf ("\
  163. Okay, I'll need to know where you do want it -- I'll parse for a file\n\
  164. in your directory, but remember the file as \"~/filename\" so it will\n\
  165. work for all users.\n");
  166.     Prompt ("File for storing users' mail, relative to home dir: ");
  167.     parse_file ("mail file", "~/");
  168. /* ************* make sure they didn't type /cu/sy/melissa/mailfile */
  169.     if (atmbuf[0] == '~')
  170.         strcpy (sprbuf, &atmbuf[2]); /* past ~/ */
  171.     else
  172.         strcpy (sprbuf, atmbuf);
  173.     confirm();
  174.     fprintf (tmpfile, "set mail-file ~/%s\n", sprbuf);
  175.     }
  176.  
  177.     printf ("\
  178. \n\
  179. Because MM is always being improved upon, we invite users to report\n\
  180. any bugs they notice, or send us any suggestions they might have,\n\
  181. using MM's \"bug\" command.  However, we have found that many \"bugs\" are\n\
  182. just misunderstandings, and many suggestions have already been\n\
  183. implemented (perhaps under a different name than the user expected).\n\
  184. In addition, we get many bug-reports that should have been sent to\n\
  185. Postmaster (or Mailman, or the local equivalent).\n\
  186. \n\
  187. In order to cut down on the level of network traffic generated, we\n\
  188. would like to have a local systems person filter the bug-mm mail and\n\
  189. send us only those things which seem appropriate.  On many systems,\n\
  190. there is already a \"consultant\" or \"remarks\" address for this sort of\n\
  191. mail.\n\n");
  192.  
  193.     Prompt ("Will you be able to provide such a person? ");
  194.     parse (&yesno_fdb, &pv, &used);
  195.     confirm();
  196.     if (pv._pvint == SET_YES) {
  197.     noremarks = FALSE;        /* they DO have one! */
  198.     fprintf(tmpfile, "\n%s %s\n", comment, bugmmcomment);
  199.     printf ("\n\
  200. What is the email address of that user?  Please note that you can\n\
  201. later change this address by modifying the line saying\n\
  202. \"define bug-mm ...\" in the init file.\n\n"); 
  203.     Prompt("email address? ");
  204.     parse(&remarks, &pv, &used);
  205.     strcpy  (sprbuf, atmbuf);
  206.     confirm();
  207.     printf ("Thank you.\n");
  208.     fprintf (tmpfile, "define bug-mm %s\n", sprbuf);
  209.     }
  210.     
  211.     printf ("\
  212. \n\
  213. Next we need to know the path for sending bugs to mm's authors.  This\n\
  214. will be defined as \"mm-authors\" in the init file.  This is where the\n\
  215. user receiving bug-mm mail should forward non-local problems and\n\
  216. suggestions.\n\
  217. \n\
  218. Here are several possibilities for the path.  If you do not know which\n\
  219. will work, just pick the one that looks most reasonable.  You can\n\
  220. always change it later, since all the possibilities will be in the\n\
  221. init file, with all but one commented out.\n\n");
  222.     fprintf (tmpfile, "\n%s possible paths for the mm authors\n", comment);
  223.  
  224.     for (i = 0; i < numpaths; i++)    /* show choices */
  225.     printf ("%3d\) %s\n", i+1, paths[i]);
  226.  
  227.     do {
  228.     printf ("\n\
  229. Pick the number from the above list corresponding to the address you\n\
  230. think will work.\n");
  231.     Prompt("Which address: ");
  232.     parse(&number, &pv, &used);
  233.     } while ((pv._pvint <= 0) || (pv._pvint > numpaths));
  234.  
  235.     for (i = 0; i < numpaths; i++) {
  236.     if (i != pv._pvint-1)        /* comment out unselected ones */
  237.         fprintf (tmpfile, "%s ", comment);
  238.     fprintf (tmpfile, "define mm-authors %s\n", paths[i]);
  239.     }
  240.     if (noremarks) {
  241.     fprintf (tmpfile, "\n%s %s\n", comment, bugmmcomment);
  242.     fprintf (tmpfile, "%s (No local bug address)\n", comment);
  243.     fprintf (tmpfile, "define bug-mm mm-authors\n");
  244.     }
  245.  
  246.     printf("\n\
  247. MM forks up an editor for composing outgoing mail and editing received\n\
  248. mail.  It works well with editors such as emacs which support multiple\n\
  249. buffers, and comes with a module to support GNU Emacs (available from\n\
  250. the Free Software Foundation, 1000 Mass Ave, Cambridge, MA 02138, and\n\
  251. distributed with many versions of Unix).  The \"editor\" variable can be\n\
  252. set by any user, but you should set a default.\n\n");
  253.  
  254.     fprintf (tmpfile, "\n%s path of default editor\n", comment);
  255.     Prompt ("Absolute path of default editor: ");
  256.     parse_file("default editor", "/");
  257.     strcpy  (sprbuf, atmbuf);
  258.     confirm();
  259.     fprintf (tmpfile, "set editor %s\n", sprbuf);
  260.  
  261.     putchar ('\n');
  262.     Prompt ("Is that GNU Emacs? ");
  263.     parse (&yesno_fdb, &pv, &used);
  264.     confirm();
  265.     gnu = pv._pvint;
  266.     fprintf (tmpfile, "%s is editor GNU Emacs\n", comment);
  267.     fprintf (tmpfile, "set gnuemacs-mmail %s\n",
  268.          gnu == SET_YES ? "yes" : "no");
  269.  
  270.     printf ("\
  271. \n\
  272. MM will run a spell-checker on messages, and needs the path of a\n\
  273. program that will read from a file and write corrections back to that\n\
  274. same file.  ispell will do this, if you have it.\n\
  275. \n");
  276.  
  277.     fprintf (tmpfile, "\n%s path for spell program\n", comment);
  278.     Prompt ("Absolute path of spell program: ");
  279.     parse_file("spell checker", "/");
  280.     strcpy  (sprbuf, atmbuf);
  281.     confirm();
  282.     fprintf (tmpfile, "set speller %s\n", sprbuf);
  283.  
  284.  
  285. #ifdef undef
  286.     cmsystem("/bin/mv -i /tmp/mminit SYSINIT");
  287. #endif /* undef */
  288.     printf ("\nDone\n");
  289.     cmdone();
  290.     exit(0);
  291. }
  292.  
  293. /*
  294.  * init:
  295.  * initialize some stuff
  296.  */
  297. init()
  298. {
  299.     cmcont = '\\';            /* lines are continued with \ */
  300.     cmbufs (cmdbuf, sizeof cmdbuf, atmbuf, sizeof atmbuf,
  301.         wrkbuf, sizeof wrkbuf);    /* set up buffers for ccmd */
  302.  
  303.     cmseti (stdin, stdout, stderr);    /* set up file descriptors */
  304.     cmcsb._cmntb = "#";            /* comments start with # */
  305. }
  306.  
  307.  
  308. fdb textfdb = { _CMTXT, CM_SDH, NULL, NULL, "confirm to continue" };
  309. fdb cfmfdb = { _CMCFM, CM_SDH };
  310.  
  311. /*
  312.  * hold:
  313.  * wait for carriage return
  314.  */
  315. hold() {
  316.     Prompt ("Hit return to continue ");
  317.     parse (fdbchn(&textfdb, &cfmfdb, NULL), &pv, &used);
  318.     putchar('\n');
  319. }
  320.  
  321. /*
  322.  * parse_file:
  323.  * parse for a filename, but don't insist on its existing
  324.  */
  325. parse_file(hlp, dir)
  326. char *hlp, *dir;
  327. {
  328.     static fdb filefdb = {
  329.     _CMFIL, FIL_NODIR|FIL_PO, NULL, NULL, NULL, NULL, NULL};
  330.     filblk fb;
  331.     static char *dirs[] = { nil , nil }; /* start them at root */
  332.  
  333.     dirs[0] = dir;
  334.     fb.pathv = dirs;
  335.     fb.exceptionspec = nil;
  336.     fb.def_extension = nil;
  337.     filefdb._cmdat = (pdat) &fb;
  338.     filefdb._cmhlp = hlp;
  339.  
  340.     parse (&filefdb, &pv, &used);
  341. }
  342.