home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mm / mm-0.90 / doinit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-18  |  3.8 KB  |  134 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/doinit.c,v 2.3 90/10/10 14:58:03 melissa Exp $";
  10. #endif
  11.  
  12. #include "mm.h"
  13. #include "set.h"
  14. #include "parse.h"
  15.  
  16. cmd_create_init(n)
  17. int n;
  18. {
  19.     confirm();
  20.     write_init();
  21. }
  22.  
  23. cmd_profile(n) 
  24. int n;
  25. {
  26.     confirm();
  27.     ask_profile_questions();
  28.     write_init();
  29. }
  30.  
  31. ask_profile_questions() {
  32.     int ask;
  33.     reply_include_me =
  34.     yesno("Do you want to receive copies of your replies to messages? ",
  35.           "no");
  36.     printf("By default, the REPLY and ANSWER commands send replies only to\n\
  37. to the address in the \"From:\" header of the original message.\n\
  38. However, you can specify that replies should, by default, be sent to\n\
  39. everyone listed in the \"To:\" and \"cc:\" headers as well.\n");
  40.     reply_all = yesno ("Do you want replies to go to everyone? ",
  41.                reply_all ? "yes" : "no");
  42.     clear_screen = yesno(
  43. "Do you want to have the screen cleared at startup and between messages? ",
  44.              clear_screen ? "yes" : "no");
  45.     printf("Normally, typing Control-N causes MM to stop what it's \
  46. doing and ask\n\
  47. if the current command should be aborted.\n");
  48.     ask = yesno("Do you want Control-N to abort without asking? ",
  49.         control_n_abort == SET_ASK ? "no" : "yes");
  50.     if (ask)
  51.     control_n_abort = SET_ALWAYS;    /* always abort */
  52.     else
  53.     control_n_abort = SET_ASK;    /* ask first */
  54.  
  55.     printf("Other profile options may be set by using the SET command to set\n\
  56. the option, and SAVE-INIT to update your \".mminit\" file.  You may\n\
  57. also edit .mminit with an editor.  Use the \"HELP SET variable-name\"\n\
  58. command for descriptions of individual .mminit options, and the SHOW\n\
  59. command to list the complete environment.\n");
  60. }
  61.  
  62. write_init() {
  63.     FILE *fp;
  64.     int i;
  65.     struct stat sbuf;
  66.     int gotstat;
  67.     char filename[BUFSIZ];
  68.     char ofile[BUFSIZ];
  69.     extern variable set_variables[];
  70.     extern int set_variable_count;
  71.     extern int write_fast_init_file();
  72.  
  73.     if (HOME == NULL)
  74.     return false;
  75.     sprintf (filename, "%s/.mminit", HOME);
  76.     if (stat(filename,&sbuf) == 0) {
  77.     sprintf(ofile,"%s~", filename);
  78.     rename(filename,ofile);
  79.     gotstat = TRUE;
  80.     }
  81.     else
  82.     gotstat = FALSE;
  83.     fp = fopen(filename, "w");
  84.     for (i = 0; i < set_variable_count; i++) {
  85.     if (!set_variables[i].changed)
  86.         continue;
  87.     if (i != SET_MAIL_ALIASES)
  88.         show_variable (fp, i, true);
  89.     }
  90.     for (i = 0; i < mail_aliases.count; i++)
  91.     disp_alias (fp, i, true,false);
  92.     if (gotstat) {            /* old file, keep protection */
  93.     if (chmod (filename, sbuf.st_mode & 07777) != 0)
  94.         perror ("Trouble fixing file mode of new init file");
  95.     }    
  96.     fclose(fp);
  97.  
  98.     if ((fast_init_file == SET_YES) || /* Only write it if asked to! */
  99.     ((fast_init_file == SET_ASK) &&
  100.      (yesno ("Write fast init file too? ", "yes"))))
  101.       return write_fast_init_file();
  102.     else
  103.       return true;        /* Otherwise do nothing */
  104. }
  105.  
  106. var_not_empty(n) 
  107. {
  108.     extern variable set_variables[];
  109.     variable *v = &set_variables[n];
  110.     switch(v->type) {
  111.     case VAR_TEXT:
  112.     case VAR_FILE:
  113.     case VAR_OFILE:
  114.     case VAR_COMMAND:
  115.     case VAR_QUOTEDSTR:
  116.     case VAR_USERNAME:
  117.     if (strlen(v->addr) == 0) return(false);
  118.     break;
  119.     case VAR_KEYLIST:
  120.     case VAR_FILES:
  121.     if (v->addr == NULL) return(false);
  122.     if (*v->addr == NULL) return(false);
  123.     break;
  124.     case VAR_ADDRLIST:
  125.     if (v->addr == NULL) return(false);
  126.     if (((addresslist *)v->addr)->first == nil) return(false);
  127.     case VAR_KEYWORDS:
  128.     if (v->addr == NULL || ((setkey *)v->addr)->current == NULL)
  129.         return(false);
  130.     break;
  131.     }
  132.     return(true);
  133. }
  134.