Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit ef24265f authored by rswindell's avatar rswindell

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
......@@ -372,8 +372,7 @@ void sbbs_t::multinodechat(int channel)
done=1;
break;
case '*':
sprintf(str,"%smenu/chan.*",cfg.text_dir);
if(fexist(str))
if(menu_exists("chan"))
menu("chan");
else {
bputs(text[ChatChanLstHdr]);
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @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 *
* modify it under the terms of the GNU General Public License *
......@@ -53,8 +53,7 @@ int sbbs_t::exec_file(csi_t *csi)
while(online) {
j=0;
if(usrlibs>1) {
sprintf(str,"%smenu/libs.*", cfg.text_dir);
if(fexist(str))
if(menu_exists("libs"))
menu("libs");
else {
bputs(text[CfgLibLstHdr]);
......@@ -78,9 +77,8 @@ int sbbs_t::exec_file(csi_t *csi)
else
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);
}
else {
......@@ -202,8 +200,7 @@ int sbbs_t::exec_file(csi_t *csi)
case CS_FILE_SHOW_LIBRARIES:
if(!usrlibs) return(0);
sprintf(str,"%smenu/libs.*", cfg.text_dir);
if(fexist(str)) {
if(menu_exists("libs")) {
menu("libs");
return(0);
}
......@@ -220,9 +217,8 @@ int sbbs_t::exec_file(csi_t *csi)
case CS_FILE_SHOW_DIRECTORIES:
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);
return(0);
}
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @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 *
* modify it under the terms of the GNU General Public License *
......@@ -51,8 +51,7 @@ int sbbs_t::exec_msg(csi_t *csi)
while(online) {
j=0;
if(usrgrps>1) {
sprintf(str,"%smenu/grps.*", cfg.text_dir);
if(fexist(str))
if(menu_exists("grps"))
menu("grps");
else {
bputs(text[CfgGrpLstHdr]);
......@@ -75,9 +74,8 @@ int sbbs_t::exec_msg(csi_t *csi)
else
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);
}
else {
......@@ -209,8 +207,7 @@ int sbbs_t::exec_msg(csi_t *csi)
case CS_MSG_SHOW_GROUPS:
if(!usrgrps) return(0);
sprintf(str,"%smenu/grps.*", cfg.text_dir);
if(fexist(str)) {
if(menu_exists("grps")) {
menu("grps");
return(0);
}
......@@ -227,9 +224,8 @@ int sbbs_t::exec_msg(csi_t *csi)
case CS_MSG_SHOW_SUBBOARDS:
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);
return(0);
}
......
......@@ -132,41 +132,37 @@ void sbbs_t::show_msghdr(smbmsg_t* msg)
else
CRLF;
SAFEPRINTF(str,"%smenu/msghdr.*", cfg.text_dir);
if(fexist(str)) {
if(menu_exists("msghdr")) {
menu("msghdr");
return;
}
bprintf(text[MsgSubj],msg->subj);
if(msg->hdr.attr)
show_msgattr(msg);
if(msg->to && *msg->to) {
bprintf(text[MsgTo],msg->to);
if(msg->to_net.addr!=NULL)
bprintf(text[MsgToNet],smb_netaddrstr(&msg->to_net,str));
if(msg->to_ext)
bprintf(text[MsgToExt],msg->to_ext);
}
if(!(msg->hdr.attr&MSG_ANONYMOUS) || SYSOP) {
bprintf(text[MsgFrom],msg->from);
if(msg->from_ext)
bprintf(text[MsgFromExt],msg->from_ext);
if(msg->from_net.addr!=NULL && strchr(msg->from,'@')==NULL)
bprintf(text[MsgFromNet],smb_netaddrstr(&msg->from_net,str));
} else {
bprintf(text[MsgSubj],msg->subj);
if(msg->hdr.attr)
show_msgattr(msg);
if(msg->to && *msg->to) {
bprintf(text[MsgTo],msg->to);
if(msg->to_net.addr!=NULL)
bprintf(text[MsgToNet],smb_netaddrstr(&msg->to_net,str));
if(msg->to_ext)
bprintf(text[MsgToExt],msg->to_ext);
}
if(!(msg->hdr.attr&MSG_ANONYMOUS) || SYSOP) {
bprintf(text[MsgFrom],msg->from);
if(msg->from_ext)
bprintf(text[MsgFromExt],msg->from_ext);
if(msg->from_net.addr!=NULL && strchr(msg->from,'@')==NULL)
bprintf(text[MsgFromNet],smb_netaddrstr(&msg->from_net,str));
}
if(!(msg->hdr.attr&MSG_POLL) && (msg->upvotes || msg->downvotes))
bprintf(text[MsgVotes]
,msg->upvotes, msg->user_voted==1 ? text[PollAnswerChecked] : nulstr
,msg->downvotes, msg->user_voted==2 ? text[PollAnswerChecked] : nulstr
,msg->upvotes - msg->downvotes);
bprintf(text[MsgDate]
,timestr(msg->hdr.when_written.time)
,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)));
CRLF;
}
if(!(msg->hdr.attr&MSG_POLL) && (msg->upvotes || msg->downvotes))
bprintf(text[MsgVotes]
,msg->upvotes, msg->user_voted==1 ? text[PollAnswerChecked] : nulstr
,msg->downvotes, msg->user_voted==2 ? text[PollAnswerChecked] : nulstr
,msg->upvotes - msg->downvotes);
bprintf(text[MsgDate]
,timestr(msg->hdr.when_written.time)
,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)));
CRLF;
for(i=0;i<msg->total_hfields;i++) {
if(msg->hfield[i].type==SENDER)
sender=(char *)msg->hfield_dat[i];
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @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 *
* modify it under the terms of the GNU General Public License *
......@@ -75,8 +75,9 @@ void sbbs_t::printfile(char *str, long mode)
sys_status&=~SS_ABORT;
}
if(!(mode&P_NOCRLF) && !tos && !wip && !rip && !html)
if(!(mode&P_NOCRLF) && !tos && !wip && !rip && !html) {
CRLF;
}
if((stream=fnopen(&file,str,O_RDONLY|O_DENYNONE))==NULL) {
lprintf(LOG_NOTICE,"Node %d !Error %d (%s) opening: %s"
......@@ -187,35 +188,43 @@ void sbbs_t::printtail(char *str, int lines, long mode)
/****************************************************************************/
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;
if(menu_file[0])
strcpy(path,menu_file);
SAFECOPY(path,menu_file);
else {
if(isfullpath(code))
SAFECOPY(str, code);
else {
sprintf(str,"%smenu/",cfg.text_dir);
if(menu_dir[0]) {
strcat(str,menu_dir);
strcat(str,"/");
}
strcat(str,code);
backslash(menu_dir);
SAFEPRINTF3(str, "%smenu/%s%s", cfg.text_dir, menu_dir, 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)) {
sprintf(path,"%smon",str);
SAFEPRINTF(path, "%s.mon", str);
if((term_supports()&(COLOR|ANSI))!=ANSI || !fexistcase(path)) {
sprintf(path,"%sans",str);
SAFEPRINTF(path, "%s.ans", str);
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:
void printfile(char *str, long mode);
void printtail(char *str, int lines, long mode);
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);
uint uselect_total, uselect_num[500];
......
......@@ -929,11 +929,8 @@ void sbbs_t::user_info()
void sbbs_t::xfer_policy()
{
char str[MAX_PATH+1];
if(!usrlibs) return;
sprintf(str,"%smenu/tpolicy.*", cfg.text_dir);
if(fexist(str))
if(menu_exists("tpolicy"))
menu("tpolicy");
else {
bprintf(text[TransferPolicyHdr],cfg.sys_name);
......@@ -954,10 +951,7 @@ const char* prot_menu_file[] = {
void sbbs_t::xfer_prot_menu(enum XFER_TYPE type)
{
char path[MAX_PATH+1];
sprintf(path,"%smenu/%s.*",cfg.text_dir,prot_menu_file[type]);
if(fexistcase(path)) {
if(menu_exists(prot_menu_file[type])) {
menu(prot_menu_file[type]);
return;
}
......
......@@ -66,8 +66,7 @@ int sbbs_t::text_sec()
}
action=NODE_RTXT;
while(online) {
sprintf(str,"%smenu/text_sec.*",cfg.text_dir);
if(fexist(str))
if(menu_exists("text_sec"))
menu("text_sec");
else {
bputs(text[TextSectionLstHdr]);
......@@ -83,9 +82,8 @@ int sbbs_t::text_sec()
break;
cursec--;
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);
usemenu=1;
}
......
......@@ -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(text[EnterMsgNow],maxlines);
SAFEPRINTF(path,"%smenu/msgtabs.*", cfg.text_dir);
if(fexist(path))
if(menu_exists("msgtabs"))
menu("msgtabs");
else {
for(i=0;i<79;i++) {
......
......@@ -79,8 +79,7 @@ int sbbs_t::xtrn_sec()
return(1);
}
if(usrxsecs>1) {
sprintf(str,"%smenu/xtrn_sec.*",cfg.text_dir);
if(fexist(str)) {
if(menu_exists("xtrn_sec")) {
menu("xtrn_sec");
xsec=getnum(usrxsecs);
if(xsec<=0)
......@@ -125,9 +124,8 @@ int sbbs_t::xtrn_sec()
pause();
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);
}
else {
......@@ -173,9 +171,8 @@ int sbbs_t::xtrn_sec()
if((l=getnum(usrxtrns))<1)
break;
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);
lncntr=0;
}
......
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