📄 configur.c
字号:
/*--------------------------------------------------------------------*/
if ( (*cp != '\0') && !processconfig(cp,sysmode,program,table,btable))
printmsg(0,
"Unknown keyword \"%s\" in %s configuration file ignored",
buff, sysmode ? "system" : "user");
} /*while*/
return TRUE;
} /*getconfig*/
/*--------------------------------------------------------------------*/
/* o p t i o n s */
/* */
/* Process a line of boolean option flags. */
/*--------------------------------------------------------------------*/
void options(char *s, SYSMODE sysmode , FLAGTABLE *flags, boolean *barray)
{
char *token;
strlwr(s);
token = strtok(s,WHITESPACE);
while (token != NULL)
{
size_t subscript;
boolean hit = FALSE;
boolean negate;
negate = equaln(token,"no",2) && (strlen(token) > 2);
for ( subscript=0; (flags[subscript].sym != NULL ) && !hit; subscript++)
{
if ((flags[subscript].bits & B_GLOBAL) && (sysmode != SYSTEM_CONFIG))
continue;
if (negate)
{
if (equal(&token[2],flags[subscript].sym))
{
barray[ flags[subscript].position ] = FALSE;
hit = TRUE;
}
} /* if negate */
else {
if (equal(token,flags[subscript].sym))
{
barray[ flags[subscript].position ] = TRUE;
hit = TRUE;
}
} /* else */
} /* for */
if (!hit)
printf("Invalid or system option '%s' specified\n",token);
token = strtok(NULL,WHITESPACE); /* Step to next token on line */
} /* while */
} /* options */
/*--------------------------------------------------------------------*/
/* c o n f i g u r e */
/* */
/* Define the global parameters of UUPC/extended */
/*--------------------------------------------------------------------*/
boolean configure( CONFIGBITS program)
{
char *sysrc, *usrrc;
FILE *fp;
boolean success;
char buf[BUFSIZ];
int subscript = 0;
char *s;
CONFIGTABLE *tptr;
static char *envlist[] = { "EDITOR", "EDITOR",
"HOME", "HOME",
"NAME", "NAME",
"MAILBOX", "MAILBOX",
"TEMP", "TEMPDIR",
"TMP", "TEMPDIR",
NULL } ;
typedef struct _DEFAULTS {
char **value;
char *literal;
} DEFAULTS;
static DEFAULTS deflist[] = {
{&E_archivedir, "archive" },
{&E_maildir, "mail" },
{&E_newsdir, "news" },
{&E_pubdir, "public" },
{&E_spooldir, "spool" },
{&E_tempdir, "tmp" },
{&E_systems, "systems" },
{&E_passwd, "passwd" },
{&E_tz, "tz" },
{ NULL }
} ;
/*--------------------------------------------------------------------*/
/* In Windows/NT, set the console input mode to non-linebased */
/*--------------------------------------------------------------------*/
#ifdef WIN32
setstdinmode();
#endif
/*--------------------------------------------------------------------*/
/* Determine the active environment */
/*--------------------------------------------------------------------*/
#if !defined(__TURBOC__) && !defined(BIT32ENV)
if (_osmode != DOS_MODE)
active_env = ENV_OS2 | ENV_BIT16;
#endif
if (!getrcnames(&sysrc, &usrrc))
return FALSE;
/*--------------------------------------------------------------------*/
/* Extract selected variables from our environment */
/*--------------------------------------------------------------------*/
while( envlist[subscript] != NULL )
{
s = getenv( envlist[subscript++] );
if (s != NULL )
{
sprintf(buf,"%s=%s",envlist[subscript], s );
processconfig( buf, SYSTEM_CONFIG, program, envtable, configFlags);
} /* if (sysrc != NULL ) */
subscript++; /* Step to next environment var in list */
}
/*--------------------------------------------------------------------*/
/* Determine configuration directory from UUPCSYSRC */
/*--------------------------------------------------------------------*/
E_confdir = normalize( sysrc ); // Make 'em all slashes
s = strrchr( E_confdir, '/' ); // Get end of path component
if ( s == NULL ) // There WAS one, right?
{ // Er, no, sorry.
printmsg(0,"No path name in UUPCSYSRC: %s", sysrc);
panic();
}
*(s+1) = '\0'; // Terminate for Config Directory
E_confdir = newstr(normalize( E_confdir ));
// Drop trailing slash unless
// root directory and save
/*--------------------------------------------------------------------*/
/* Process the system configuration file */
/*--------------------------------------------------------------------*/
if ((fp = FOPEN(sysrc, "r",TEXT_MODE)) == nil(FILE))
{
printmsg(0, "Cannot open system configuration file \"%s\"", sysrc);
printerr(sysrc);
return FALSE;
}
PushDir( E_confdir );
success = getconfig(fp, SYSTEM_CONFIG, program, envtable, configFlags);
fclose(fp);
if (!success)
{
PopDir();
return FALSE;
}
/*--------------------------------------------------------------------*/
/* Process the user configuration value */
/*--------------------------------------------------------------------*/
if (usrrc != nil(char))
{
usrrc = normalize( usrrc );
if ((fp = FOPEN(usrrc, "r",TEXT_MODE)) == nil(FILE))
{
printmsg(0, "Cannot open user configuration file \"%s\"", usrrc);
PopDir();
return FALSE;
}
success = getconfig(fp, USER_CONFIG, program, envtable, configFlags);
fclose(fp);
if (!success)
{
PopDir();
return FALSE;
}
}
/*--------------------------------------------------------------------*/
/* Display our copyright */
/*--------------------------------------------------------------------*/
if (! bflag[F_SUPPRESSCOPYRIGHT] &&
(program != B_MTA) &&
isatty(fileno(stdout)))
fprintf(stdout,
"Changes and Compilation Copyright (c) 1990-1993 by Kendra Electronic\n"
"Wonderworks. May be freely distributed if original documentation and\n"
"source is included.\n" );
/*--------------------------------------------------------------------*/
/* Validate that all required parameters were given */
/*--------------------------------------------------------------------*/
for (tptr = envtable; tptr->sym != nil(char); tptr++)
{
if ((tptr->bits & (B_REQUIRED | B_FOUND)) == B_REQUIRED)
{
printmsg(0, "%s configuration parameter \"%s\" must be set.",
(tptr->bits & B_GLOBAL) ? "System" : "User",
tptr->sym);
success = FALSE;
} /* if */
} /* for */
/*--------------------------------------------------------------------*/
/* Fill in derived parameters */
/*--------------------------------------------------------------------*/
subscript = 0;
while( deflist[subscript].value != NULL )
{
if ( *(deflist[subscript].value) == NULL )
*(deflist[subscript].value) =
newstr( normalize(deflist[subscript].literal ) );
subscript++;
}
/*--------------------------------------------------------------------*/
/* Set our time zone */
/*--------------------------------------------------------------------*/
if ((getenv("TZ") == NULL) && (E_tz != NULL))
{
sprintf( buf, "TZ=%s", E_tz );
E_tz = newstr( E_tz );
putenv( E_tz );
}
tzset(); /* Set up time zone information */
PopDir();
return success;
} /*configure*/
/*--------------------------------------------------------------------*/
/* g e t r c n a m e s */
/* */
/* Return the name of the configuration files */
/*--------------------------------------------------------------------*/
static boolean getrcnames(char **sysp,char **usrp)
{
char *debugp = NULL; /* Pointer to debug environment variable */
if ((*sysp = getenv(SYSRCSYM)) == nil(char))
{
printf("environment variable %s must be specified\n", SYSRCSYM);
return FALSE;
}
*usrp = getenv(USRRCSYM);
debugp = getenv(SYSDEBUG);
if ( debugp != nil(char)) /* Debug specified in environment? */
debuglevel = atoi(debugp); /* Yes --> preset debuglevel for user */
return TRUE;
} /*getrcnames*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -