Skip to content
Snippets Groups Projects
Commit b5365030 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Replace ctrl/attr.cfg (customized text colors/attrs) with ctrl/attr.ini

Another legacy config file replaced with .ini file (for easier editing and
future extensibility).

No longer dynamically allocate scfg_t.colors (no need). There's really no
reason why this is still an array, but leave as is for now.

Also, I noticed JS console.color_list (also an array) is not enumerable
(or documented) - that should be fixed.
parent 0fd16ccc
No related branches found
No related tags found
1 merge request!455Update branch with changes from master
......@@ -2877,7 +2877,7 @@ JSObject* js_CreateConsoleObject(JSContext* cx, JSObject* parent)
,NULL, NULL, 0))
return(NULL);
for(uint i=0;i<sbbs->cfg.total_colors;i++) {
for(uint i=0; i < NUM_COLORS; i++) {
jsval val=INT_TO_JSVAL(sbbs->cfg.color[i]);
if(!JS_SetElement(cx, color_list, i, &val))
......
......@@ -31,7 +31,6 @@
#endif
static void prep_cfg(scfg_t* cfg);
static void free_attr_cfg(scfg_t* cfg);
int lprintf(int level, const char *fmt, ...); /* log output */
......@@ -352,7 +351,6 @@ void free_cfg(scfg_t* cfg)
free_file_cfg(cfg);
free_chat_cfg(cfg);
free_xtrn_cfg(cfg);
free_attr_cfg(cfg);
if(cfg->text != NULL)
free_text(cfg->text);
......@@ -409,50 +407,42 @@ int md(const char* inpath)
/****************************************************************************/
bool read_attr_cfg(scfg_t* cfg, char* error, size_t maxerrlen)
{
uint* clr;
char str[256];
long offset=0;
FILE *instream;
int i;
char value[INI_MAX_VALUE_LEN];
char path[MAX_PATH + 1];
FILE* fp;
str_list_t ini;
SAFEPRINTF(str,"%sattr.cfg",cfg->ctrl_dir);
if((instream=fnopen(NULL,str,O_RDONLY))==NULL) {
safe_snprintf(error, maxerrlen,"%d opening %s",errno,str);
return(false);
}
FREE_AND_NULL(cfg->color);
if((cfg->color=malloc(MIN_COLORS * sizeof(uint)))==NULL) {
safe_snprintf(error, maxerrlen,"Error allocating memory (%u bytes) for colors"
,MIN_COLORS);
fclose(instream);
return(false);
}
/* Setup default colors here: */
for(i = 0; i < MIN_COLORS; ++i)
cfg->color[i] = LIGHTGRAY | HIGH;
cfg->color[clr_votes_full] = WHITE|BG_MAGENTA;
cfg->color[clr_progress_full] = CYAN|HIGH|BG_BLUE;
for(cfg->total_colors=0;!feof(instream) && !ferror(instream);cfg->total_colors++) {
if(readline(&offset,str,4,instream)==NULL)
break;
if(cfg->total_colors>=MIN_COLORS) {
if((clr=realloc(cfg->color,(cfg->total_colors+1) * sizeof(uint)))==NULL)
break;
cfg->color=clr;
}
cfg->color[cfg->total_colors]=strtoattr(str, /* endptr: */NULL);
}
fclose(instream);
if(cfg->total_colors<MIN_COLORS)
cfg->total_colors=MIN_COLORS;
return(true);
}
SAFEPRINTF(path,"%sattr.ini",cfg->ctrl_dir);
fp = fnopen(NULL, path, O_RDONLY);
static void free_attr_cfg(scfg_t* cfg)
{
if(cfg->color!=NULL)
FREE_AND_NULL(cfg->color);
cfg->total_colors=0;
ini = iniReadFile(fp);
if(fp != NULL)
fclose(fp);
cfg->color[clr_mnehigh] = strtoattr(iniGetString(ini, ROOT_SECTION, "mnehigh", "WH", value), /* endptr: */NULL);
cfg->color[clr_mnelow] = strtoattr(iniGetString(ini, ROOT_SECTION, "mnelow", "G", value), /* endptr: */NULL);
cfg->color[clr_mnecmd] = strtoattr(iniGetString(ini, ROOT_SECTION, "mnecmd", "WH", value), /* endptr: */NULL);
cfg->color[clr_inputline] = strtoattr(iniGetString(ini, ROOT_SECTION, "inputline", "WH4E", value), /* endptr: */NULL);
cfg->color[clr_err] = strtoattr(iniGetString(ini, ROOT_SECTION, "error", "RH", value), /* endptr: */NULL);
cfg->color[clr_nodenum] = strtoattr(iniGetString(ini, ROOT_SECTION, "nodenum", "WH", value), /* endptr: */NULL);
cfg->color[clr_nodeuser] = strtoattr(iniGetString(ini, ROOT_SECTION, "nodeuser", "GH", value), /* endptr: */NULL);
cfg->color[clr_nodestatus] = strtoattr(iniGetString(ini, ROOT_SECTION, "nodestatus", "G", value), /* endptr: */NULL);
cfg->color[clr_filename] = strtoattr(iniGetString(ini, ROOT_SECTION, "filename", "BH", value), /* endptr: */NULL);
cfg->color[clr_filecdt] = strtoattr(iniGetString(ini, ROOT_SECTION, "filecdt", "M", value), /* endptr: */NULL);
cfg->color[clr_filedesc] = strtoattr(iniGetString(ini, ROOT_SECTION, "filedesc", "W", value), /* endptr: */NULL);
cfg->color[clr_filelsthdrbox] = strtoattr(iniGetString(ini, ROOT_SECTION, "filelisthdrbox", "YH", value), /* endptr: */NULL);
cfg->color[clr_filelstline] = strtoattr(iniGetString(ini, ROOT_SECTION, "filelistline", "B", value), /* endptr: */NULL);
cfg->color[clr_chatlocal] = strtoattr(iniGetString(ini, ROOT_SECTION, "chatlocal", "GH", value), /* endptr: */NULL);
cfg->color[clr_chatremote] = strtoattr(iniGetString(ini, ROOT_SECTION, "chatremote", "G", value), /* endptr: */NULL);
cfg->color[clr_multichat] = strtoattr(iniGetString(ini, ROOT_SECTION, "multichat", "W", value), /* endptr: */NULL);
cfg->color[clr_external] = strtoattr(iniGetString(ini, ROOT_SECTION, "external", "WH", value), /* endptr: */NULL);
cfg->color[clr_votes_full] = strtoattr(iniGetString(ini, ROOT_SECTION, "votes_full", "WH5", value), /* endptr: */NULL);
cfg->color[clr_votes_empty] = strtoattr(iniGetString(ini, ROOT_SECTION, "votes_empty", "WH", value), /* endptr: */NULL);
cfg->color[clr_progress_full] = strtoattr(iniGetString(ini, ROOT_SECTION, "progress_full", "WH5", value), /* endptr: */NULL);
cfg->color[clr_progress_empty] = strtoattr(iniGetString(ini, ROOT_SECTION, "progress_empty", "WH", value), /* endptr: */NULL);
iniFreeStringList(ini);
return(true);
}
char* prep_dir(const char* base, char* path, size_t buflen)
......
......@@ -348,7 +348,7 @@ enum {
,clr_votes_empty
,clr_progress_full
,clr_progress_empty
,MIN_COLORS
,NUM_COLORS
};
enum { /* Values for xtrn_t.type */
......
......@@ -624,8 +624,7 @@ typedef struct
uchar inactivity_warn; // percentage
uint max_getkey_inactivity; // Seconds before user inactivity hang-up
uint* color; /* Different colors for the BBS */
uint32_t total_colors;
uint color[NUM_COLORS]; /* Different colors for the BBS */
uint32_t ctrlkey_passthru; /* Bits represent control keys NOT handled by inkey() */
uint user_backup_level;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment