Commit b236be71 authored by rswindell's avatar rswindell

Add/use a new get_ctrl_dir() function to query the SBBSCTRL env var and if

not set (or blank), use the default ("/sbbs/ctrl") and print a warning to
stderr. This resolves a FAQ for sysops that struggle with setting the SBBSCTRL
env var, but do have sbbs install in /sbbs or a symlink from /sbbs to where
sbbs is actually installed.

Note: this function is different than the one previously defined in getctrl.c
but never used. If/when we ever really need to support PREFIX, then perhaps
we'll use that one (which copies a string to a buffer).
parent fbcbdb83
......@@ -728,12 +728,7 @@ int main(int argc, char **argv)
return(1);
}
p=getenv("SBBSCTRL");
if(p==NULL) {
printf("\nSBBSCTRL environment variable not set.\n");
printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
exit(1);
}
p = get_ctrl_dir();
memset(&scfg,0,sizeof(scfg));
scfg.size=sizeof(scfg);
......
......@@ -117,16 +117,7 @@ int main(int argc, char **argv)
return(0);
}
p=getenv("SBBSCTRL");
if(p==NULL) {
printf("\nSBBSCTRL environment variable not set.\n");
#ifdef __unix__
printf("\nExample: export SBBSCTRL=/sbbs/ctrl\n");
#else
printf("\nExample: SET SBBSCTRL=C:\\SBBS\\CTRL\n");
#endif
return(1);
}
p = get_ctrl_dir();
memset(&cfg, 0, sizeof(cfg));
cfg.size=sizeof(cfg);
......
/* $Id$ */
// vi: tabstop=4
#include "sbbs.h"
#include "crc32.h"
......@@ -76,16 +77,7 @@ int main(int argc,char **argv)
fprintf(stderr,"\nDUPEFIND Version %s (%s) - Synchronet Duplicate File "
"Finder\n", DUPEFIND_VER, PLATFORM_DESC);
p=getenv("SBBSCTRL");
if(p==NULL) {
fprintf(stderr,"\nSBBSCTRL environment variable must be set.\n");
#ifdef __unix__
fprintf(stderr,"\nExample: export SBBSCTRL=/sbbs/ctrl\n");
#else
fprintf(stderr,"\nExample: SET SBBSCTRL=C:\\SBBS\\CTRL\n");
#endif
return(1);
}
p = get_ctrl_dir();
if(argc>1 && (!stricmp(argv[1],"/?") || !stricmp(argv[1],"?") || !stricmp(argv[1],"-?"))) {
fprintf(stderr,"\n");
......
......@@ -102,7 +102,7 @@ int main(int argc, char **argv)
{
char revision[16];
char error[512];
char *p,str[256],fname[256],ext,not[MAX_NOTS][9];
char str[256],fname[256],ext,not[MAX_NOTS][9];
uchar *datbuf,*ixbbuf;
int i,j,file,dirnum,libnum,desc_off,lines,nots=0
,omode=O_WRONLY|O_CREAT|O_TRUNC;
......@@ -152,18 +152,11 @@ int main(int argc, char **argv)
exit(0);
}
p=getenv("SBBSCTRL");
if(p==NULL) {
printf("\nSBBSCTRL environment variable not set.\n");
printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
exit(1);
}
now=time32(NULL);
memset(&scfg,0,sizeof(scfg));
scfg.size=sizeof(scfg);
SAFECOPY(scfg.ctrl_dir,p);
SAFECOPY(scfg.ctrl_dir, get_ctrl_dir());
if(chdir(scfg.ctrl_dir)!=0)
fprintf(stderr,"!ERROR changing directory to: %s", scfg.ctrl_dir);
......
......@@ -441,15 +441,11 @@ gtk_widget_set_sensitive(w, TRUE);
int read_config(void)
{
char ctrl_dir[MAX_PATH+1];
char *p;
p=getenv("SBBSCTRL");
if(p==NULL)
p="/sbbs/ctrl";
SAFECOPY(ctrl_dir, p);
SAFECOPY(ctrl_dir, get_ctrl_dir());
prep_dir("",ctrl_dir,sizeof(ctrl_dir));
if(!isdir(ctrl_dir)) {
display_message("Environment Errpr","SBBSCTRL does not point to a directory","gtk-dialog-error");
display_message("Environment Error","SBBSCTRL does not point to a directory","gtk-dialog-error");
return(-1);
}
memset(&cfg,0,sizeof(cfg));
......
......@@ -1321,13 +1321,7 @@ int main(int argc, char **argv, char** env)
#ifndef JSDOOR
if(scfg.ctrl_dir[0]==0) {
if((p=getenv("SBBSCTRL"))==NULL) {
fprintf(errfp,"\nSBBSCTRL environment variable not set and -c option not specified.\n");
fprintf(errfp,"\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
fprintf(errfp,"\n or: %s -c /sbbs/ctrl [module]\n",argv[0]);
return(do_bail(1));
}
SAFECOPY(scfg.ctrl_dir,p);
SAFECOPY(scfg.ctrl_dir, get_ctrl_dir());
}
#endif
......
......@@ -105,12 +105,7 @@ int main(int argc, char **argv)
if(strcspn(argv[first_arg],"/\\")!=strlen(argv[first_arg]))
p=argv[first_arg++];
else
p=getenv("SBBSCTRL");
if(p==NULL) {
printf("\nSBBSCTRL environment variable not set.\n");
printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
exit(1);
}
p = get_ctrl_dir();
memset(&scfg,0,sizeof(scfg));
scfg.size=sizeof(scfg);
......
......@@ -172,7 +172,6 @@ int main(int argc, char **argv)
FILE *route,*users,*nodes;
time_t now;
smbmsg_t msg;
char *ctrl_dir;
char revision[16];
sscanf("$Revision$", "%*s %s", revision);
......@@ -253,13 +252,7 @@ int main(int argc, char **argv)
}
cfg.size=sizeof(cfg);
ctrl_dir=getenv("SBBSCTRL");
if(ctrl_dir==NULL || ctrl_dir[0]==0) {
ctrl_dir="/sbbs/ctrl"; /* Not set? Use default */
printf("!SBBSCTRL environment variable not set, using default value: %s\n\n"
,ctrl_dir);
}
SAFECOPY(cfg.ctrl_dir, ctrl_dir);
SAFECOPY(cfg.ctrl_dir, get_ctrl_dir());
if(!load_cfg(&cfg, NULL, TRUE, str)) {
printf("\7\n%s\n",str);
......
......@@ -1176,6 +1176,7 @@ extern "C" {
DLLEXPORT BOOL str_is_ascii(const char*);
DLLEXPORT char * utf8_to_cp437_str(char* str);
DLLEXPORT char * subnewsgroupname(scfg_t*, sub_t*, char*, size_t);
DLLEXPORT char * get_ctrl_dir(void);
/* msg_id.c */
DLLEXPORT char * DLLCALL ftn_msgid(sub_t*, smbmsg_t*, char* msgid, size_t);
......
......@@ -1399,12 +1399,7 @@ int main(int argc, char** argv)
loginAttemptListInit(&login_attempt_list);
atexit(cleanup);
ctrl_dir=getenv("SBBSCTRL"); /* read from environment variable */
if(ctrl_dir==NULL || ctrl_dir[0]==0) {
ctrl_dir="/sbbs/ctrl"; /* Not set? Use default */
printf("!SBBSCTRL environment variable not set, using default value: %s\n\n"
,ctrl_dir);
}
ctrl_dir = get_ctrl_dir();
if(!winsock_startup())
return(-1);
......
......@@ -60,6 +60,8 @@
#define COPYRIGHT_NOTICE "Copyright 2019 Rob Swindell"
#define COPYRIGHT_CRC 0x0E0503DF
#define SBBSCTRL_DEFAULT "/sbbs/ctrl"
#define Y2K_2DIGIT_WINDOW 70
#define FNOPEN_BUF_SIZE (2*1024)
......
......@@ -84,16 +84,7 @@ int main(int argc, char **argv)
"or less\n");
return(0); }
p=getenv("SBBSCTRL");
if(p==NULL) {
printf("\nSBBSCTRL environment variable not set.\n");
#ifdef __unix__
printf("\nExample: export SBBSCTRL=/sbbs/ctrl\n");
#else
printf("\nExample: SET SBBSCTRL=C:\\SBBS\\CTRL\n");
#endif
return(1);
}
p = get_ctrl_dir();
memset(&cfg,0,sizeof(cfg));
cfg.size=sizeof(cfg);
......
......@@ -719,3 +719,14 @@ char* subnewsgroupname(scfg_t* cfg, sub_t* sub, char* str, size_t size)
}
return str;
}
char* get_ctrl_dir(void)
{
char* p = getenv("SBBSCTRL");
if(p == NULL || *p == '\0') {
fprintf(stderr, "!SBBSCTRL environment variable not set, using default value: " SBBSCTRL_DEFAULT "\n\n");
p = SBBSCTRL_DEFAULT;
}
return p;
}
......@@ -191,9 +191,8 @@ int main(int argc, char **argv)
FILE *text_js;
FILE *text_defaults_c;
if((p=getenv("SBBSCTRL"))==NULL)
p="/sbbs/ctrl";
sprintf(path,"%s/text.dat",p);
p = get_ctrl_dir();
SAFEPRINTF(path,"%s/text.dat",p);
if((text_dat=fopen(path,"r"))==NULL) {
perror(path);
return(1);
......
......@@ -1895,7 +1895,7 @@ int main(int argc, char** argv) {
int main_dflt=0;
int main_bar=0;
char revision[16];
char str[256],ctrl_dir[41],*p;
char str[256],ctrl_dir[MAX_PATH + 1];
char title[256];
int i,j;
scfg_t cfg;
......@@ -1917,17 +1917,7 @@ int main(int argc, char** argv) {
printf("\nSynchronet User Editor %s-%s Copyright %s "
"Rob Swindell\n",revision,PLATFORM_DESC,__DATE__+7);
p=getenv("SBBSCTRL");
if(p==NULL) {
printf("\7\nSBBSCTRL environment variable is not set.\n");
printf("This environment variable must be set to your CTRL directory.");
printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
exit(1); }
sprintf(ctrl_dir,"%.40s",p);
if(ctrl_dir[strlen(ctrl_dir)-1]!='\\'
&& ctrl_dir[strlen(ctrl_dir)-1]!='/')
strcat(ctrl_dir,"/");
SAFECOPY(ctrl_dir, get_ctrl_dir());
gethostname(str,sizeof(str)-1);
......
......@@ -786,7 +786,7 @@ int main(int argc, char** argv) {
int main_dflt=0;
int main_bar=0;
char revision[16];
char str[256],ctrl_dir[41],*p;
char str[256],ctrl_dir[MAX_PATH + 1];
char title[256];
int i,j;
node_t node;
......@@ -810,17 +810,7 @@ int main(int argc, char** argv) {
printf("\nSynchronet UNIX Monitor %s-%s Copyright %s "
"Rob Swindell\n",revision,PLATFORM_DESC,__DATE__+7);
p=getenv("SBBSCTRL");
if(p==NULL) {
printf("\7\nSBBSCTRL environment variable is not set.\n");
printf("This environment variable must be set to your CTRL directory.");
printf("\nExample: SET SBBSCTRL=/sbbs/ctrl\n");
exit(1); }
sprintf(ctrl_dir,"%.40s",p);
if(ctrl_dir[strlen(ctrl_dir)-1]!='\\'
&& ctrl_dir[strlen(ctrl_dir)-1]!='/')
strcat(ctrl_dir,"/");
SAFECOPY(ctrl_dir, get_ctrl_dir());
gethostname(str,sizeof(str)-1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment