PennMUSH Community

Changeset 1302

Show
Ignore:
Timestamp:
10/01/08 01:21:51 (2 months ago)
Author:
shawnw
Message:

#7687: @config/save

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/devel/CHANGES.183

    r1301 r1302  
    1717 
    1818Version 1.8.3 patchlevel 8                      ??? ??, 200?  
     19 
     20Minor changes: 
     21 * @config/save foo=bar acts like @config/set but also attempts to 
     22   alter the original configuration file to reflect the new value. 
    1923  
    2024Version 1.8.3 patchlevel 7                      Oct 01, 2008 
    2125 
    22 Minor changes: 
    2326Minor changes: 
    2427 * If compiling with a recent enough version of gcc to support the 
  • 1.8.3/branches/devel/config.h.in

    r1272 r1302  
    351351#undef SENDMAIL 
    352352 
     353#undef HAVE_ED 
     354#undef ED_PATH 
     355 
    353356#undef HAVE_SAFE_TOUPPER 
    354357 
  • 1.8.3/branches/devel/configure

    r1285 r1302  
    658658GREP 
    659659CPP 
     660ED 
    660661SENDMAIL 
    661662UPTIME 
     
    749750PERL 
    750751SENDMAIL 
     752ED 
    751753CPP 
    752754CXX 
     
    14051407  PERL        Absolute path to perl executable 
    14061408  SENDMAIL    Path to sendmail 
     1409  ED          Path to ed 
    14071410  CPP         C preprocessor 
    14081411  CXX         C++ compiler command 
     
    40714074fi 
    40724075 
     4076 
     4077# Extract the first word of "ed", so it can be a program name with args. 
     4078set dummy ed; ac_word=$2 
     4079{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5 
     4080$as_echo_n "checking for $ac_word... " >&6; } 
     4081if test "${ac_cv_path_ED+set}" = set; then 
     4082  $as_echo_n "(cached) " >&6 
     4083else 
     4084  case $ED in 
     4085  [\\/]* | ?:[\\/]*) 
     4086  ac_cv_path_ED="$ED" # Let the user override the test with a path. 
     4087  ;; 
     4088  *) 
     4089  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR 
     4090for as_dir in $PATH 
     4091do 
     4092  IFS=$as_save_IFS 
     4093  test -z "$as_dir" && as_dir=. 
     4094  for ac_exec_ext in '' $ac_executable_extensions; do 
     4095  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then 
     4096    ac_cv_path_ED="$as_dir/$ac_word$ac_exec_ext" 
     4097    $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 
     4098    break 2 
     4099  fi 
     4100done 
     4101done 
     4102IFS=$as_save_IFS 
     4103 
     4104  ;; 
     4105esac 
     4106fi 
     4107ED=$ac_cv_path_ED 
     4108if test -n "$ED"; then 
     4109  { $as_echo "$as_me:$LINENO: result: $ED" >&5 
     4110$as_echo "$ED" >&6; } 
     4111else 
     4112  { $as_echo "$as_me:$LINENO: result: no" >&5 
     4113$as_echo "no" >&6; } 
     4114fi 
     4115 
     4116 
     4117if test "${ED+set}" = "set"; then 
     4118   cat >>confdefs.h <<\_ACEOF 
     4119#define HAVE_ED 1 
     4120_ACEOF 
     4121 
     4122   cat >>confdefs.h <<_ACEOF 
     4123#define ED_PATH "$ED -s" 
     4124_ACEOF 
     4125 
     4126fi 
    40734127 
    40744128### Headers 
  • 1.8.3/branches/devel/configure.in

    r1285 r1302  
    8686fi 
    8787 
    88 AC_ARG_VAR(SENDMAIL, Path to sendmail
     88AC_ARG_VAR(SENDMAIL, [Path to sendmail]
    8989AC_PATH_PROG(SENDMAIL, sendmail) 
    9090if test "${SENDMAIL+set}" = "set"; then 
     
    9393fi 
    9494 
     95AC_ARG_VAR(ED, [Path to ed]) 
     96AC_PATH_PROG(ED, ed) 
     97if test "${ED+set}" = "set"; then 
     98   AC_DEFINE([HAVE_ED]) 
     99   AC_DEFINE_UNQUOTED([ED_PATH], "$ED -s") 
     100fi 
    95101 
    96102### Headers 
  • 1.8.3/branches/devel/game/txt/hlp/penncmd.hlp

    r1298 r1302  
    672672  @config/flags 
    673673  @config/list[/lowercase] [<option|option-type>] 
    674   @config/set option=value 
     674  @config/set|save option=value 
    675675   
    676676  This command lists the MUSH configuration parameters, indicating what 
     
    686686  /set        --   Wizard only, changes parameters from the mush. See 
    687687                   help @config parameters for available ones. 
     688  /save       --   Like /set, but also modifies the config file so the 
     689                   change persists over reboots. 
    688690& @conformat 
    689691  @conformat <object> [=<format>] 
  • 1.8.3/branches/devel/hdrs/switches.h

    r1070 r1302  
    119119#define SWITCH_ROOMS 116 
    120120#define SWITCH_RSARGS 117 
    121 #define SWITCH_SEE 118 
    122 #define SWITCH_SEEFLAG 119 
    123 #define SWITCH_SELF 120 
    124 #define SWITCH_SEND 121 
    125 #define SWITCH_SET 122 
    126 #define SWITCH_SILENT 123 
    127 #define SWITCH_SKIPDEFAULTS 124 
    128 #define SWITCH_SPEAK 125 
    129 #define SWITCH_SPOOF 126 
    130 #define SWITCH_STATS 127 
    131 #define SWITCH_SUMMARY 128 
    132 #define SWITCH_TABLES 129 
    133 #define SWITCH_TAG 130 
    134 #define SWITCH_TELEPORT 131 
    135 #define SWITCH_TF 132 
    136 #define SWITCH_THINGS 133 
    137 #define SWITCH_TITLE 134 
    138 #define SWITCH_TRACE 135 
    139 #define SWITCH_TYPE 136 
    140 #define SWITCH_UNCLEAR 137 
    141 #define SWITCH_UNFOLDER 138 
    142 #define SWITCH_UNGAG 139 
    143 #define SWITCH_UNHIDE 140 
    144 #define SWITCH_UNMUTE 141 
    145 #define SWITCH_UNTAG 142 
    146 #define SWITCH_UNTIL 143 
    147 #define SWITCH_URGENT 144 
    148 #define SWITCH_USEFLAG 145 
    149 #define SWITCH_WHAT 146 
    150 #define SWITCH_WHO 147 
    151 #define SWITCH_WIPE 148 
    152 #define SWITCH_WIZ 149 
    153 #define SWITCH_WIZARD 150 
    154 #define SWITCH_YES 151 
    155 #define SWITCH_ZONE 152 
     121#define SWITCH_SAVE 118 
     122#define SWITCH_SEE 119 
     123#define SWITCH_SEEFLAG 120 
     124#define SWITCH_SELF 121 
     125#define SWITCH_SEND 122 
     126#define SWITCH_SET 123 
     127#define SWITCH_SILENT 124 
     128#define SWITCH_SKIPDEFAULTS 125 
     129#define SWITCH_SPEAK 126 
     130#define SWITCH_SPOOF 127 
     131#define SWITCH_STATS 128 
     132#define SWITCH_SUMMARY 129 
     133#define SWITCH_TABLES 130 
     134#define SWITCH_TAG 131 
     135#define SWITCH_TELEPORT 132 
     136#define SWITCH_TF 133 
     137#define SWITCH_THINGS 134 
     138#define SWITCH_TITLE 135 
     139#define SWITCH_TRACE 136 
     140#define SWITCH_TYPE 137 
     141#define SWITCH_UNCLEAR 138 
     142#define SWITCH_UNFOLDER 139 
     143#define SWITCH_UNGAG 140 
     144#define SWITCH_UNHIDE 141 
     145#define SWITCH_UNMUTE 142 
     146#define SWITCH_UNTAG 143 
     147#define SWITCH_UNTIL 144 
     148#define SWITCH_URGENT 145 
     149#define SWITCH_USEFLAG 146 
     150#define SWITCH_WHAT 147 
     151#define SWITCH_WHO 148 
     152#define SWITCH_WIPE 149 
     153#define SWITCH_WIZ 150 
     154#define SWITCH_WIZARD 151 
     155#define SWITCH_YES 152 
     156#define SWITCH_ZONE 153 
    156157#endif                          /* SWITCHES_H */ 
  • 1.8.3/branches/devel/src/SWITCHES

    r892 r1302  
    116116ROOMS 
    117117RSARGS 
     118SAVE 
    118119SEE 
    119120SEEFLAG 
  • 1.8.3/branches/devel/src/cmds.c

    r1213 r1302  
    170170  else if (SW_ISSET(sw, SWITCH_POWERS)) 
    171171    do_list_flags("POWER", player, arg_left, lc, T("Powers")); 
    172   else if (SW_ISSET(sw, SWITCH_SET)) { 
     172  else if (SW_ISSET(sw, SWITCH_SET) || SW_ISSET(sw, SWITCH_SAVE)) { 
    173173    if (!Wizard(player)) { 
    174174      notify(player, T("You can't remake the world in your image.")); 
     
    179179      return; 
    180180    } 
    181     if (!config_set(arg_left, arg_right, 1, 0) 
    182         && !config_set(arg_left, arg_right, 1, 1)) 
    183       notify(player, T("Couldn't set that option")); 
    184     else 
    185       notify(player, T("Option set.")); 
     181    { 
     182      int source = SW_ISSET(sw, SWITCH_SAVE) ? 2 : 1; 
     183      if (!config_set(arg_left, arg_right, source, 0) 
     184      && !config_set(arg_left, arg_right, source, 1)) 
     185    notify(player, T("Couldn't set that option")); 
     186      else { 
     187    if (source == 2) { 
     188#ifdef HAVE_ED 
     189      notify(player, T("Option set and saved.")); 
     190#else 
     191      notify(player, T("Option set but not saved.")); 
     192#endif 
     193    } else 
     194      notify(player, T("Option set.")); 
     195      } 
     196    } 
    186197  } else 
    187198    do_config_list(player, arg_left, lc); 
  • 1.8.3/branches/devel/src/command.c

    r1237 r1302  
    112112   CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_NOGAGGED, 0, 0}, 
    113113  {"@CONFIG", 
    114    "SET LOWERCASE LIST GLOBALS DEFAULTS COSTS FLAGS FUNCTIONS COMMANDS ATTRIBS", 
     114   "SET SAVE LOWERCASE LIST GLOBALS DEFAULTS COSTS FLAGS FUNCTIONS COMMANDS ATTRIBS", 
    115115   cmd_config, CMD_T_ANY | CMD_T_EQSPLIT, 0, 0}, 
    116116  {"@CPATTR", "CONVERT NOFLAGCOPY", cmd_cpattr, 
  • 1.8.3/branches/devel/src/conf.c

    r1213 r1302  
    2424#include <stdlib.h> 
    2525#include <ctype.h> 
     26#include <errno.h> 
    2627 
    2728#include "conf.h" 
     
    4445 
    4546static void show_compile_options(dbref player); 
    46 static char *config_list_helper(dbref player, PENNCONF *cp, int lc); 
    47 static char *config_list_helper2(dbref player, PENNCONF *cp, int lc); 
     47static char *config_to_string(dbref player, PENNCONF *cp, int lc); 
    4848 
    4949OPTTAB options;         /**< The table of configuration options */ 
     
    880880} 
    881881 
     882static char *toplevel_cfile = NULL; 
     883 
     884static void 
     885append_restriction(const char *r, const char *what, const char *opts) 
     886{ 
     887  FILE *out; 
     888 
     889  out = fopen(toplevel_cfile, "a"); 
     890  if (out) { 
     891    fprintf(out, "# Added by @config/save\n%s %s %s\n\n", 
     892        r, what, opts); 
     893    fclose(out); 
     894  } 
     895} 
     896 
     897/* Not perfect -- things defined in included config files won't 
     898   get changed -- but it'll catch most cases. 
     899*/ 
     900static void 
     901save_config_option(PENNCONF *cp) 
     902{ 
     903#if defined(HAVE_ED) 
     904  FILE *ed; 
     905   
     906  /* ed is the standard! Why reinvent it? */ 
     907 
     908  ed = popen(ED_PATH, "w"); 
     909  if (!ed) { 
     910    do_rawlog(LT_ERR, "Unable to open ed: %s", strerror(errno)); 
     911    return; 
     912  } 
     913   
     914  fprintf(ed, "e %s\n", toplevel_cfile); 
     915  fprintf(ed, ",s/^[[:space:]]*%s[[:space:]].*$/%s/\n", cp->name, 
     916      trim_space_sep(config_to_string(GOD, cp, 1), ' ')); 
     917  fputs("wq\n", ed); 
     918  pclose(ed); 
     919#endif 
     920 
     921} 
     922 
    882923/** Set a configuration option. 
    883924 * This function sets a runtime configuration option. During the load 
     
    887928 * \param opt name of the option. 
    888929 * \param val value to set the option to. 
    889  * \param source 0 if being set from mush.cnf, 1 from softcode
     930 * \param source 0 if being set from mush.cnf, 1 from softcode, 2 from softcode and saving
    890931 * \param restrictions 1 if we're setting restriction options, 0 for others. 
    891932 * \retval 1 success. 
     
    924965      return 0; 
    925966    } 
     967    if (source == 2) 
     968      append_restriction("restrict_command", val, p); 
    926969    return 1; 
    927970  } else if (!strcasecmp(opt, "restrict_function")) { 
     
    947990      return 0; 
    948991    } 
     992    if (source == 2) 
     993      append_restriction("restrict_function", val, p); 
    949994    return 1; 
    950995  } else if (!strcasecmp(opt, "reserve_alias")) { 
     
    9721017      return 0; 
    9731018    } 
     1019    if (source == 2) 
     1020      append_restriction("reserve_alias", val, p); 
    9741021    return 1; 
    9751022  } else if (!strcasecmp(opt, "attribute_alias")) { 
     
    9921039      return 0; 
    9931040    } 
     1041    if (source == 2) 
     1042      append_restriction("attribute_alias", val, p); 
    9941043    return 1; 
    9951044  } else if (!strcasecmp(opt, "function_alias")) { 
     
    10121061      return 0; 
    10131062    } 
     1063    if (source == 2) 
     1064      append_restriction("function_alias", val, p); 
    10141065    return 1; 
    10151066  } else if (!strcasecmp(opt, "help_command") 
     
    10201071      return 0; 
    10211072    /* Add a new help-like command */ 
    1022     if (source == 1) 
     1073    if (source >= 1) /* Can't do this from @config/set */ 
    10231074      return 0; 
    10241075    if (!val || !*val) { 
     
    10531104        && !strcasecmp(cp->name, opt)) { 
    10541105      i = cp->handler(opt, val, cp->loc, cp->max, source); 
    1055       if (i) 
     1106      if (i) { 
    10561107        cp->overridden = 1; 
     1108    if (source == 2) 
     1109      save_config_option(cp); 
     1110      } 
    10571111      return i; 
    10581112    } 
    10591113  } 
    1060   for (cp = (PENNCONF *) hash_firstentry(&local_options); cp; 
    1061        cp = (PENNCONF *) hash_nextentry(&local_options)) { 
     1114  for (cp = hash_firstentry(&local_options); cp; 
     1115       cp = hash_nextentry(&local_options)) { 
    10621116    int i = 0; 
    10631117    if ((!source || (cp->group && strcmp(cp->group, "files") != 0 
     
    10651119        && !strcasecmp(cp->name, opt)) { 
    10661120      i = cp->handler(opt, val, cp->loc, cp->max, source); 
    1067       if (i) 
     1121      if (i) { 
    10681122        cp->overridden = 1; 
     1123    if (source == 2) 
     1124      save_config_option(cp); 
     1125      } 
    10691126      return i; 
    10701127    } 
     
    12871344  char tbuf1[BUFFER_LEN]; 
    12881345  char *p, *q, *s; 
    1289  
    12901346  static char cfile[BUFFER_LEN];        /* Remember the last one */ 
     1347 
    12911348  if (conf_recursion == 0) { 
    12921349    if (conf && *conf) 
     
    12981355    } 
    12991356    do_rawlog(LT_ERR, "Reading %s", cfile); 
     1357    if (toplevel_cfile == NULL) 
     1358      toplevel_cfile = mush_strdup(cfile, "config.file"); 
    13001359  } else { 
    13011360    if (conf && *conf) 
     
    14521511      for (cp = conftable; cp->name; cp++) { 
    14531512        if (cp->group && string_prefix(cp->name, type)) { 
    1454           notify(player, config_list_helper(player, cp, lc)); 
     1513          notify(player, config_to_string(player, cp, lc)); 
    14551514          found = 1; 
    14561515        } 
     
    14611520             cp = (PENNCONF *) hash_nextentry(&local_options)) { 
    14621521          if (cp->group && !strcasecmp(cp->name, type)) { 
    1463             notify(player, config_list_helper(player, cp, lc)); 
     1522            notify(player, config_to_string(player, cp, lc)); 
    14641523            found = 1; 
    14651524          } 
     
    14821541        for (cp = conftable; cp->name; cp++) { 
    14831542          if (cp->group && !strcmp(cp->group, cgp->name)) { 
    1484             notify(player, config_list_helper(player, cp, lc)); 
     1543            notify(player, config_to_string(player, cp, lc)); 
    14851544          } 
    14861545        } 
     
    14881547             cp = (PENNCONF *) hash_nextentry(&local_options)) { 
    14891548          if (cp->group && !strcasecmp(cp->group, cgp->name)) { 
    1490             notify(player, config_list_helper(player, cp, lc)); 
     1549            notify(player, config_to_string(player, cp, lc)); 
    14911550          } 
    14921551        } 
     
    15091568#define MAYBE_LC(x) (lc ? strlower(x) : x) 
    15101569static char * 
    1511 config_list_helper(dbref player 
     1570config_to_string(dbref player 
    15121571                   __attribute__ ((__unused__)), PENNCONF *cp, int lc) 
    15131572{ 
     
    15501609/* This one doesn't return the names */ 
    15511610static char * 
    1552 config_list_helper2(dbref player 
     1611config_to_string2(dbref player 
    15531612                    __attribute__ ((__unused__)), PENNCONF *cp, int lc 
    15541613                    __attribute__ ((__unused__))) 
     
    15961655    for (cp = conftable; cp->name; cp++) { 
    15971656      if (cp->group && !strcasecmp(cp->name, args[0])) { 
    1598         safe_str(config_list_helper2(executor, cp, 0), buff, bp); 
     1657        safe_str(config_to_string2(executor, cp, 0), buff, bp); 
    15991658        return; 
    16001659      } 
     
    16031662         cp = (PENNCONF *) hash_nextentry(&local_options)) { 
    16041663      if (cp->group && !strcasecmp(cp->name, args[0])) { 
    1605         safe_str(config_list_helper2(executor, cp, 0), buff, bp); 
     1664        safe_str(config_to_string2(executor, cp, 0), buff, bp); 
    16061665        return; 
    16071666      } 
  • 1.8.3/branches/devel/src/switchinc.c

    r947 r1302  
    118118  {"ROOMS", SWITCH_ROOMS}, 
    119119  {"RSARGS", SWITCH_RSARGS}, 
     120  {"SAVE", SWITCH_SAVE}, 
    120121  {"SEE", SWITCH_SEE}, 
    121122  {"SEEFLAG", SWITCH_SEEFLAG},