Skip to content
Snippets Groups Projects
Commit ef24265f authored by rswindell's avatar rswindell
Browse files

Create and use sbbs_t::menu_exists() - solves a couple of long-standing issues:

- if the sysop had text/menu/<filename>.bak (for example), the optoinal menu
  would attempt to load, resulting in an error ("<filename>.asc not found")
- if the sysop specified menu_file or menu_dir (e.g. via Baja), the existing
  checks for optional menu file existance would not work
parent 14dc698a
Branches
Tags
No related merge requests found
...@@ -372,8 +372,7 @@ void sbbs_t::multinodechat(int channel) ...@@ -372,8 +372,7 @@ void sbbs_t::multinodechat(int channel)
done=1; done=1;
break; break;
case '*': case '*':
sprintf(str,"%smenu/chan.*",cfg.text_dir); if(menu_exists("chan"))
if(fexist(str))
menu("chan"); menu("chan");
else { else {
bputs(text[ChatChanLstHdr]); bputs(text[ChatChanLstHdr]);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* * * *
* Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html * * Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License * * modify it under the terms of the GNU General Public License *
...@@ -53,8 +53,7 @@ int sbbs_t::exec_file(csi_t *csi) ...@@ -53,8 +53,7 @@ int sbbs_t::exec_file(csi_t *csi)
while(online) { while(online) {
j=0; j=0;
if(usrlibs>1) { if(usrlibs>1) {
sprintf(str,"%smenu/libs.*", cfg.text_dir); if(menu_exists("libs"))
if(fexist(str))
menu("libs"); menu("libs");
else { else {
bputs(text[CfgLibLstHdr]); bputs(text[CfgLibLstHdr]);
...@@ -78,9 +77,8 @@ int sbbs_t::exec_file(csi_t *csi) ...@@ -78,9 +77,8 @@ int sbbs_t::exec_file(csi_t *csi)
else else
j--; j--;
} }
sprintf(str,"%smenu/dirs%u.*", cfg.text_dir, usrlib[j]+1);
if(fexist(str)) {
sprintf(str,"dirs%u",usrlib[j]+1); sprintf(str,"dirs%u",usrlib[j]+1);
if(menu_exists(str)) {
menu(str); menu(str);
} }
else { else {
...@@ -202,8 +200,7 @@ int sbbs_t::exec_file(csi_t *csi) ...@@ -202,8 +200,7 @@ int sbbs_t::exec_file(csi_t *csi)
case CS_FILE_SHOW_LIBRARIES: case CS_FILE_SHOW_LIBRARIES:
if(!usrlibs) return(0); if(!usrlibs) return(0);
sprintf(str,"%smenu/libs.*", cfg.text_dir); if(menu_exists("libs")) {
if(fexist(str)) {
menu("libs"); menu("libs");
return(0); return(0);
} }
...@@ -220,9 +217,8 @@ int sbbs_t::exec_file(csi_t *csi) ...@@ -220,9 +217,8 @@ int sbbs_t::exec_file(csi_t *csi)
case CS_FILE_SHOW_DIRECTORIES: case CS_FILE_SHOW_DIRECTORIES:
if(!usrlibs) return(0); if(!usrlibs) return(0);
sprintf(str,"%smenu/dirs%u.*", cfg.text_dir, usrlib[curlib]+1);
if(fexist(str)) {
sprintf(str,"dirs%u",usrlib[curlib]+1); sprintf(str,"dirs%u",usrlib[curlib]+1);
if(menu_exists(str)) {
menu(str); menu(str);
return(0); return(0);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* * * *
* Copyright 2009 Rob Swindell - http://www.synchro.net/copyright.html * * Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License * * modify it under the terms of the GNU General Public License *
...@@ -51,8 +51,7 @@ int sbbs_t::exec_msg(csi_t *csi) ...@@ -51,8 +51,7 @@ int sbbs_t::exec_msg(csi_t *csi)
while(online) { while(online) {
j=0; j=0;
if(usrgrps>1) { if(usrgrps>1) {
sprintf(str,"%smenu/grps.*", cfg.text_dir); if(menu_exists("grps"))
if(fexist(str))
menu("grps"); menu("grps");
else { else {
bputs(text[CfgGrpLstHdr]); bputs(text[CfgGrpLstHdr]);
...@@ -75,9 +74,8 @@ int sbbs_t::exec_msg(csi_t *csi) ...@@ -75,9 +74,8 @@ int sbbs_t::exec_msg(csi_t *csi)
else else
j--; j--;
} }
sprintf(str,"%smenu/subs%u.*", cfg.text_dir, usrgrp[j]+1);
if(fexist(str)) {
sprintf(str,"subs%u",usrgrp[j]+1); sprintf(str,"subs%u",usrgrp[j]+1);
if(menu_exists(str)) {
menu(str); menu(str);
} }
else { else {
...@@ -209,8 +207,7 @@ int sbbs_t::exec_msg(csi_t *csi) ...@@ -209,8 +207,7 @@ int sbbs_t::exec_msg(csi_t *csi)
case CS_MSG_SHOW_GROUPS: case CS_MSG_SHOW_GROUPS:
if(!usrgrps) return(0); if(!usrgrps) return(0);
sprintf(str,"%smenu/grps.*", cfg.text_dir); if(menu_exists("grps")) {
if(fexist(str)) {
menu("grps"); menu("grps");
return(0); return(0);
} }
...@@ -227,9 +224,8 @@ int sbbs_t::exec_msg(csi_t *csi) ...@@ -227,9 +224,8 @@ int sbbs_t::exec_msg(csi_t *csi)
case CS_MSG_SHOW_SUBBOARDS: case CS_MSG_SHOW_SUBBOARDS:
if(!usrgrps) return(0); if(!usrgrps) return(0);
sprintf(str,"%smenu/subs%u.*", cfg.text_dir, usrgrp[curgrp]+1);
if(fexist(str)) {
sprintf(str,"subs%u",usrgrp[curgrp]+1); sprintf(str,"subs%u",usrgrp[curgrp]+1);
if(menu_exists(str)) {
menu(str); menu(str);
return(0); return(0);
} }
......
...@@ -132,12 +132,9 @@ void sbbs_t::show_msghdr(smbmsg_t* msg) ...@@ -132,12 +132,9 @@ void sbbs_t::show_msghdr(smbmsg_t* msg)
else else
CRLF; CRLF;
SAFEPRINTF(str,"%smenu/msghdr.*", cfg.text_dir); if(menu_exists("msghdr")) {
if(fexist(str)) {
menu("msghdr"); menu("msghdr");
return; } else {
}
bprintf(text[MsgSubj],msg->subj); bprintf(text[MsgSubj],msg->subj);
if(msg->hdr.attr) if(msg->hdr.attr)
show_msgattr(msg); show_msgattr(msg);
...@@ -164,9 +161,8 @@ void sbbs_t::show_msghdr(smbmsg_t* msg) ...@@ -164,9 +161,8 @@ void sbbs_t::show_msghdr(smbmsg_t* msg)
,timestr(msg->hdr.when_written.time) ,timestr(msg->hdr.when_written.time)
,smb_zonestr(msg->hdr.when_written.zone,NULL) ,smb_zonestr(msg->hdr.when_written.zone,NULL)
,age_of_posted_item(age, sizeof(age), msg->hdr.when_written.time - (smb_tzutc(msg->hdr.when_written.zone) * 60))); ,age_of_posted_item(age, sizeof(age), msg->hdr.when_written.time - (smb_tzutc(msg->hdr.when_written.zone) * 60)));
CRLF; CRLF;
}
for(i=0;i<msg->total_hfields;i++) { for(i=0;i<msg->total_hfields;i++) {
if(msg->hfield[i].type==SENDER) if(msg->hfield[i].type==SENDER)
sender=(char *)msg->hfield_dat[i]; sender=(char *)msg->hfield_dat[i];
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* * * *
* Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html * * Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License * * modify it under the terms of the GNU General Public License *
...@@ -75,8 +75,9 @@ void sbbs_t::printfile(char *str, long mode) ...@@ -75,8 +75,9 @@ void sbbs_t::printfile(char *str, long mode)
sys_status&=~SS_ABORT; sys_status&=~SS_ABORT;
} }
if(!(mode&P_NOCRLF) && !tos && !wip && !rip && !html) if(!(mode&P_NOCRLF) && !tos && !wip && !rip && !html) {
CRLF; CRLF;
}
if((stream=fnopen(&file,str,O_RDONLY|O_DENYNONE))==NULL) { if((stream=fnopen(&file,str,O_RDONLY|O_DENYNONE))==NULL) {
lprintf(LOG_NOTICE,"Node %d !Error %d (%s) opening: %s" lprintf(LOG_NOTICE,"Node %d !Error %d (%s) opening: %s"
...@@ -187,35 +188,43 @@ void sbbs_t::printtail(char *str, int lines, long mode) ...@@ -187,35 +188,43 @@ void sbbs_t::printtail(char *str, int lines, long mode)
/****************************************************************************/ /****************************************************************************/
void sbbs_t::menu(const char *code) void sbbs_t::menu(const char *code)
{ {
char str[MAX_PATH+1],path[MAX_PATH+1]; char str[MAX_PATH-5],path[MAX_PATH+1];
sys_status&=~SS_ABORT; sys_status&=~SS_ABORT;
if(menu_file[0]) if(menu_file[0])
strcpy(path,menu_file); SAFECOPY(path,menu_file);
else { else {
if(isfullpath(code)) if(isfullpath(code))
SAFECOPY(str, code); SAFECOPY(str, code);
else { else {
sprintf(str,"%smenu/",cfg.text_dir); backslash(menu_dir);
if(menu_dir[0]) { SAFEPRINTF3(str, "%smenu/%s%s", cfg.text_dir, menu_dir, code);
strcat(str,menu_dir);
strcat(str,"/");
}
strcat(str,code);
} }
strcat(str,"."); sprintf(path,"%s.%s",str,term_supports(WIP) ? "wip": term_supports(RIP) ? "rip" : "html");
sprintf(path,"%s%s",str,term_supports(WIP) ? "wip": term_supports(RIP) ? "rip" : "html");
if(!(term_supports()&(RIP|WIP|HTML)) || !fexistcase(path)) { if(!(term_supports()&(RIP|WIP|HTML)) || !fexistcase(path)) {
sprintf(path,"%smon",str); SAFEPRINTF(path, "%s.mon", str);
if((term_supports()&(COLOR|ANSI))!=ANSI || !fexistcase(path)) { if((term_supports()&(COLOR|ANSI))!=ANSI || !fexistcase(path)) {
sprintf(path,"%sans",str); SAFEPRINTF(path, "%s.ans", str);
if(!term_supports(ANSI) || !fexistcase(path)) if(!term_supports(ANSI) || !fexistcase(path))
sprintf(path,"%sasc",str); SAFEPRINTF(path, "%s.asc", str);
} }
} }
} }
printfile(path,P_OPENCLOSE); long mode = P_OPENCLOSE;
if(column == 0)
mode |= P_NOCRLF;
printfile(path, mode);
} }
bool sbbs_t::menu_exists(const char *code)
{
char path[MAX_PATH+1];
if(menu_file[0])
return fexistcase(menu_file) ? true : false;
backslash(menu_dir);
SAFEPRINTF3(path, "%smenu/%s%s.asc", cfg.text_dir, menu_dir, code);
return fexistcase(path) ? true : false;
}
...@@ -712,6 +712,7 @@ public: ...@@ -712,6 +712,7 @@ public:
void printfile(char *str, long mode); void printfile(char *str, long mode);
void printtail(char *str, int lines, long mode); void printtail(char *str, int lines, long mode);
void menu(const char *code); void menu(const char *code);
bool menu_exists(const char *code);
int uselect(int add, uint n, const char *title, const char *item, const uchar *ar); int uselect(int add, uint n, const char *title, const char *item, const uchar *ar);
uint uselect_total, uselect_num[500]; uint uselect_total, uselect_num[500];
......
...@@ -929,11 +929,8 @@ void sbbs_t::user_info() ...@@ -929,11 +929,8 @@ void sbbs_t::user_info()
void sbbs_t::xfer_policy() void sbbs_t::xfer_policy()
{ {
char str[MAX_PATH+1];
if(!usrlibs) return; if(!usrlibs) return;
sprintf(str,"%smenu/tpolicy.*", cfg.text_dir); if(menu_exists("tpolicy"))
if(fexist(str))
menu("tpolicy"); menu("tpolicy");
else { else {
bprintf(text[TransferPolicyHdr],cfg.sys_name); bprintf(text[TransferPolicyHdr],cfg.sys_name);
...@@ -954,10 +951,7 @@ const char* prot_menu_file[] = { ...@@ -954,10 +951,7 @@ const char* prot_menu_file[] = {
void sbbs_t::xfer_prot_menu(enum XFER_TYPE type) void sbbs_t::xfer_prot_menu(enum XFER_TYPE type)
{ {
char path[MAX_PATH+1]; if(menu_exists(prot_menu_file[type])) {
sprintf(path,"%smenu/%s.*",cfg.text_dir,prot_menu_file[type]);
if(fexistcase(path)) {
menu(prot_menu_file[type]); menu(prot_menu_file[type]);
return; return;
} }
......
...@@ -66,8 +66,7 @@ int sbbs_t::text_sec() ...@@ -66,8 +66,7 @@ int sbbs_t::text_sec()
} }
action=NODE_RTXT; action=NODE_RTXT;
while(online) { while(online) {
sprintf(str,"%smenu/text_sec.*",cfg.text_dir); if(menu_exists("text_sec"))
if(fexist(str))
menu("text_sec"); menu("text_sec");
else { else {
bputs(text[TextSectionLstHdr]); bputs(text[TextSectionLstHdr]);
...@@ -83,9 +82,8 @@ int sbbs_t::text_sec() ...@@ -83,9 +82,8 @@ int sbbs_t::text_sec()
break; break;
cursec--; cursec--;
while(online) { while(online) {
sprintf(str,"%smenu/text%lu.*",cfg.text_dir,cursec+1);
if(fexist(str)) {
sprintf(str,"text%lu",cursec+1); sprintf(str,"text%lu",cursec+1);
if(menu_exists(str)) {
menu(str); menu(str);
usemenu=1; usemenu=1;
} }
......
...@@ -779,8 +779,7 @@ ulong sbbs_t::msgeditor(char *buf, const char *top, char *title) ...@@ -779,8 +779,7 @@ ulong sbbs_t::msgeditor(char *buf, const char *top, char *title)
bprintf("\r\nMessage editor: Read in %d lines\r\n",lines); bprintf("\r\nMessage editor: Read in %d lines\r\n",lines);
bprintf(text[EnterMsgNow],maxlines); bprintf(text[EnterMsgNow],maxlines);
SAFEPRINTF(path,"%smenu/msgtabs.*", cfg.text_dir); if(menu_exists("msgtabs"))
if(fexist(path))
menu("msgtabs"); menu("msgtabs");
else { else {
for(i=0;i<79;i++) { for(i=0;i<79;i++) {
......
...@@ -79,8 +79,7 @@ int sbbs_t::xtrn_sec() ...@@ -79,8 +79,7 @@ int sbbs_t::xtrn_sec()
return(1); return(1);
} }
if(usrxsecs>1) { if(usrxsecs>1) {
sprintf(str,"%smenu/xtrn_sec.*",cfg.text_dir); if(menu_exists("xtrn_sec")) {
if(fexist(str)) {
menu("xtrn_sec"); menu("xtrn_sec");
xsec=getnum(usrxsecs); xsec=getnum(usrxsecs);
if(xsec<=0) if(xsec<=0)
...@@ -125,9 +124,8 @@ int sbbs_t::xtrn_sec() ...@@ -125,9 +124,8 @@ int sbbs_t::xtrn_sec()
pause(); pause();
break; break;
} }
sprintf(str,"%smenu/xtrn%u.*",cfg.text_dir,xsec+1);
if(fexist(str)) {
sprintf(str,"xtrn%u",xsec+1); sprintf(str,"xtrn%u",xsec+1);
if(menu_exists(str)) {
menu(str); menu(str);
} }
else { else {
...@@ -173,9 +171,8 @@ int sbbs_t::xtrn_sec() ...@@ -173,9 +171,8 @@ int sbbs_t::xtrn_sec()
if((l=getnum(usrxtrns))<1) if((l=getnum(usrxtrns))<1)
break; break;
l--; l--;
sprintf(str,"%smenu/xtrn/%s.*",cfg.text_dir,cfg.xtrn[usrxtrn[l]]->code);
if(fexist(str)) {
sprintf(str,"xtrn/%s",cfg.xtrn[usrxtrn[l]]->code); sprintf(str,"xtrn/%s",cfg.xtrn[usrxtrn[l]]->code);
if(menu_exists(str)) {
menu(str); menu(str);
lncntr=0; lncntr=0;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment