static char rcsid[] = "@(#)$Id: save_opts.c,v 1.31 2006/04/14 21:58:59 hurtta Exp $";
/******************************************************************************
* The Elm (ME+) Mail System - $Revision: 1.31 $ $State: Exp $
*
* Modified by: Kari Hurtta <hurtta+elm@posti.FMI.FI>
* (was hurtta+elm@ozone.FMI.FI)
******************************************************************************
* The Elm Mail System
*
* Copyright (c) 1988-1992 USENET Community Trust
* Copyright (c) 1986,1987 Dave Taylor
*****************************************************************************/
/** This file contains the routine needed to allow the users to change the
Elm parameters and then save the configuration in a ".elm/elmrc" file in
their home directory. With any luck this will allow them never to have
to actually EDIT the file!!
**/
#include "def_elm.h"
#include "s_elmrc.h"
#include <errno.h>
DEBUG_VAR(Debug,__FILE__,"config");
#undef onoff
#define onoff(n) (n == 0? "OFF":"ON")
#define absolute(x) ((x) < 0? -(x) : (x))
#ifndef errno
extern int errno;
#endif
extern char version_buff[];
#include "rc_imp.h"
#include "save_opts.h"
void save_options()
{
/** Save the options currently specified to a file. This is a
fairly complex routine since it tries to put in meaningful
comments and such as it goes along. The comments are
extracted from the file ELMRC_INFO as defined in the sysdefs.h
file. THAT file has the format;
varname
<comment>
<comment>
<blank line>
and each comment is written ABOVE the variable to be added. This
program also tries to make 'pretty' stuff like the alternatives
and such.
**/
char oldfname[SLEN], newfname[SLEN];
int err,r;
strfcpy(newfname,user_rc_file,sizeof newfname);
elm_sfprintf(oldfname, sizeof oldfname,
FRM("%s/%s"),
home, old_elmrcfile);
/** first off, let's see if they already HAVE a .elm/elmrc file **/
save_file_stats(newfname);
if (access(newfname, ACCESS_EXISTS) != -1) {
/** YES! Copy it to the file ".old.elmrc".. **/
if (rename(newfname, oldfname) < 0)
DPRINT(Debug,2,(&Debug, "Unable to rename %s to %s\n",
newfname, oldfname));
(void) elm_chown(oldfname, userid, groupid);
}
/** now let's open the datafile if we can... **/
r = write_rc(newfname,NULL,0,"ELM",full_username);
restore_file_stats(newfname);
if (r)
lib_error(CATGETS(elm_msg_cat, ElmrcSet, ElmrcOptionsSavedIn,
"Options saved in file %s."), newfname);
}
static int find_opt P_((char *s));
static int find_opt(s)
char *s;
{
int x, y = 0;
for (x = 0; x < NUMBER_OF_SAVEABLE_OPTIONS; x++) {
y = strcmp(s, save_info[x].name);
if (y <= 0)
break;
}
if (y != 0)
return(-1);
return(x);
}
char *str_opt_nam(s, f)
char *s;
int f;
{
char *t = NULL;
if (0 == strcmp("aliassortby",s))
t = alias_sort_name(SHORT);
else if (0 == strcmp("userlevel",s))
t = level_name(give_dt_enumerate_as_int(&user_level));
else {
int x = find_opt(s);
if (x >= 0) {
if (RCTYPE_magic != save_info[x].dt_type->magic)
panic("RC PANIC",__FILE__,__LINE__,"str_opt_nam",
"Bad config item type",0);
/* Returns pointer to static buffer */
t = save_info[x].dt_type->get_value(& save_info[x]);
}
}
return(t);
}
/*
* Local Variables:
* mode:c
* c-basic-offset:4
* buffer-file-coding-system: iso-8859-1
* End:
*/
syntax highlighted by Code2HTML, v. 0.9.1