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

Pass max_lines to editfile() and msgeditor() functions

Rather than recomputing (possibly differently) the max lines in multiple
places.

This also enables the possibility that editfile() could be used to edit files
of > 10K lines in the future. <shrug>
parent 0ecf245c
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #4071 passed
...@@ -768,8 +768,8 @@ public: ...@@ -768,8 +768,8 @@ public:
, int mode = WM_NONE, smb_t* resmb = NULL, smbmsg_t* remsg = NULL); , int mode = WM_NONE, smb_t* resmb = NULL, smbmsg_t* remsg = NULL);
bool forwardmsg(smb_t*, smbmsg_t*, const char* to, const char* subject = NULL, const char* comment = NULL); bool forwardmsg(smb_t*, smbmsg_t*, const char* to, const char* subject = NULL, const char* comment = NULL);
void removeline(char *str, char *str2, char num, char skip); void removeline(char *str, char *str2, char num, char skip);
uint msgeditor(char *buf, const char *top, char *title); uint msgeditor(char *buf, const char *top, char *title, uint max_lines, uint max_line_len);
bool editfile(char *path, bool msg=false); bool editfile(char *path, uint max_lines = 10000);
ushort chmsgattr(const smbmsg_t*); ushort chmsgattr(const smbmsg_t*);
bool quotemsg(smb_t*, smbmsg_t*, bool tails = false); bool quotemsg(smb_t*, smbmsg_t*, bool tails = false);
bool editmsg(smb_t*, smbmsg_t*); bool editmsg(smb_t*, smbmsg_t*);
......
...@@ -1083,7 +1083,7 @@ void sbbs_t::maindflts(user_t* user) ...@@ -1083,7 +1083,7 @@ void sbbs_t::maindflts(user_t* user)
if(fexist(str) && yesno(text[ViewSignatureQ])) if(fexist(str) && yesno(text[ViewSignatureQ]))
printfile(str,P_NOATCODES); printfile(str,P_NOATCODES);
if(!noyes(text[CreateEditSignatureQ])) if(!noyes(text[CreateEditSignatureQ]))
editfile(str); editfile(str, cfg.level_linespermsg[user->level] / 10);
else if(fexist(str) && !noyes(text[DeleteSignatureQ])) else if(fexist(str) && !noyes(text[DeleteSignatureQ]))
remove(str); remove(str);
break; break;
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "git_branch.h" #include "git_branch.h"
#include "git_hash.h" #include "git_hash.h"
#define MAX_LINES 10000
#define MAX_LINE_LEN ((cols - 1) + 2) #define MAX_LINE_LEN ((cols - 1) + 2)
const char *quote_fmt=" > %.*s\r\n"; const char *quote_fmt=" > %.*s\r\n";
...@@ -687,7 +686,7 @@ bool sbbs_t::writemsg(const char *fname, const char *top, char *subj, int mode, ...@@ -687,7 +686,7 @@ bool sbbs_t::writemsg(const char *fname, const char *top, char *subj, int mode,
// remove(msgtmp); // remove(msgtmp);
} }
} }
if(!(msgeditor((char *)buf,mode&WM_NOTOP ? nulstr : top, subj))) { if(!(msgeditor((char *)buf,mode&WM_NOTOP ? nulstr : top, subj, cfg.level_linespermsg[useron_level], MAX_LINE_LEN))) {
if(!online) { if(!online) {
FILE* fp = fopen(draft, "wb"); FILE* fp = fopen(draft, "wb");
if(fp == NULL) if(fp == NULL)
...@@ -916,9 +915,10 @@ void sbbs_t::removeline(char *str, char *str2, char num, char skip) ...@@ -916,9 +915,10 @@ void sbbs_t::removeline(char *str, char *str2, char num, char skip)
/* The Synchronet editor. */ /* The Synchronet editor. */
/* Returns the number of lines edited. */ /* Returns the number of lines edited. */
/*****************************************************************************/ /*****************************************************************************/
uint sbbs_t::msgeditor(char *buf, const char *top, char *title) uint sbbs_t::msgeditor(char *buf, const char *top, char *title, uint maxlines, uint max_line_len)
{ {
int i,j,line,lines=0,maxlines; int i,j;
uint line,lines=0;
char strin[TERM_COLS_MAX + 1]; char strin[TERM_COLS_MAX + 1];
char tmp[512]; char tmp[512];
str_list_t str; str_list_t str;
...@@ -932,8 +932,6 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title) ...@@ -932,8 +932,6 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title)
rioctl(IOCM|ABORT); rioctl(IOCM|ABORT);
rioctl(IOCS|ABORT); rioctl(IOCS|ABORT);
maxlines=cfg.level_linespermsg[useron.level];
if((str = strListDivide(NULL, buf, "\n")) == NULL) { if((str = strListDivide(NULL, buf, "\n")) == NULL) {
errormsg(WHERE,ERR_ALLOC,"msgeditor",sizeof(char *)*(maxlines+1)); errormsg(WHERE,ERR_ALLOC,"msgeditor",sizeof(char *)*(maxlines+1));
return(0); return(0);
...@@ -967,7 +965,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title) ...@@ -967,7 +965,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title)
while(online) { while(online) {
if(line < 0) if(line < 0)
line = 0; line = 0;
if(line>(maxlines-10)) { if((int)line>(int)maxlines-10) {
if(line >= maxlines) if(line >= maxlines)
bprintf(text[NoMoreLines],line); bprintf(text[NoMoreLines],line);
else else
...@@ -1045,12 +1043,12 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title) ...@@ -1045,12 +1043,12 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title)
i=atoi(strin+2)-1; i=atoi(strin+2)-1;
if(i==-1) /* /D means delete last line */ if(i==-1) /* /D means delete last line */
i=lines-1; i=lines-1;
if(i>=lines || i<0) if(i>=(int)lines || i<0)
bputs(text[InvalidLineNumber]); bputs(text[InvalidLineNumber]);
else { else {
free(str[i]); free(str[i]);
lines--; lines--;
while(i<lines) { while(i<(int)lines) {
str[i]=str[i+1]; str[i]=str[i+1];
i++; i++;
} }
...@@ -1067,7 +1065,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title) ...@@ -1067,7 +1065,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title)
i=atoi(strin+2)-1; i=atoi(strin+2)-1;
if(i < 0) if(i < 0)
i = lines - 1; i = lines - 1;
if(i >= lines || i < 0) if(i >= (int)lines || i < 0)
bputs(text[InvalidLineNumber]); bputs(text[InvalidLineNumber]);
else { else {
strListInsert(&str, "", i); strListInsert(&str, "", i);
...@@ -1085,7 +1083,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title) ...@@ -1085,7 +1083,7 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title)
i=lines-1; i=lines-1;
j|=K_WRAP; /* wrap when editing last line */ j|=K_WRAP; /* wrap when editing last line */
} }
if(i>=lines || i<0) if(i>=(int)lines || i<0)
bputs(text[InvalidLineNumber]); bputs(text[InvalidLineNumber]);
else { else {
SAFECOPY(strin, str[i]); SAFECOPY(strin, str[i]);
...@@ -1208,8 +1206,8 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title) ...@@ -1208,8 +1206,8 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title)
errormsg(WHERE, ERR_CHK, tmp, lines); errormsg(WHERE, ERR_CHK, tmp, lines);
lines = maxlines; lines = maxlines;
} }
for(i=0;i<lines;i++) for(i=0;i<(int)lines;i++)
snprintf(buf + strlen(buf), MAX_LINE_LEN, "%s\r\n", str[i]); snprintf(buf + strlen(buf), max_line_len, "%s\r\n", str[i]);
strListFree(&str); strListFree(&str);
if(!online) if(!online)
return 0; return 0;
...@@ -1219,29 +1217,25 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title) ...@@ -1219,29 +1217,25 @@ uint sbbs_t::msgeditor(char *buf, const char *top, char *title)
/****************************************************************************/ /****************************************************************************/
/* Edits an existing file or creates a new one in MSG format */ /* Edits an existing file or creates a new one in MSG format */
/****************************************************************************/ /****************************************************************************/
bool sbbs_t::editfile(char *fname, bool msg) bool sbbs_t::editfile(char *fname, uint maxlines)
{ {
char *buf,path[MAX_PATH+1]; char *buf,path[MAX_PATH+1];
char msgtmp[MAX_PATH+1]; char msgtmp[MAX_PATH+1];
char str[MAX_PATH+1]; char str[MAX_PATH+1];
int file; int file;
long length,maxlines,l,mode=0; long length,l,mode=0;
FILE* stream; FILE* stream;
unsigned lines; unsigned lines;
ushort useron_xedit = useron.xedit; ushort useron_xedit = useron.xedit;
if(cols < 2) { if(cols < TERM_COLS_MIN) {
errormsg(WHERE, ERR_CHK, "columns", cols); errormsg(WHERE, ERR_CHK, "columns (too narrow)", cols);
return false; return false;
} }
if(useron_xedit && !chk_ar(cfg.xedit[useron_xedit-1]->ar, &useron, &client)) if(useron_xedit && !chk_ar(cfg.xedit[useron_xedit-1]->ar, &useron, &client))
useron_xedit = 0; useron_xedit = 0;
if(msg)
maxlines=cfg.level_linespermsg[useron.level];
else
maxlines=MAX_LINES;
quotes_fname(useron_xedit, path, sizeof(path)); quotes_fname(useron_xedit, path, sizeof(path));
(void)removecase(path); (void)removecase(path);
...@@ -1306,7 +1300,7 @@ bool sbbs_t::editfile(char *fname, bool msg) ...@@ -1306,7 +1300,7 @@ bool sbbs_t::editfile(char *fname, bool msg)
buf[0]=0; buf[0]=0;
bputs(text[NewFile]); bputs(text[NewFile]);
} }
if(!msgeditor(buf,nulstr,/* title: */(char*)nulstr)) { if(!msgeditor(buf,nulstr,/* title: */(char*)nulstr, maxlines, MAX_LINE_LEN)) {
free(buf); free(buf);
return false; return false;
} }
...@@ -1640,7 +1634,7 @@ bool sbbs_t::editmsg(smb_t* smb, smbmsg_t *msg) ...@@ -1640,7 +1634,7 @@ bool sbbs_t::editmsg(smb_t* smb, smbmsg_t *msg)
msg_tmp_fname(useron.xedit, msgtmp, sizeof(msgtmp)); msg_tmp_fname(useron.xedit, msgtmp, sizeof(msgtmp));
(void)removecase(msgtmp); (void)removecase(msgtmp);
msgtotxt(smb, msg, msgtmp, /* header: */false, /* mode: */is_msg ? GETMSGTXT_ALL : GETMSGTXT_BODY_ONLY); msgtotxt(smb, msg, msgtmp, /* header: */false, /* mode: */is_msg ? GETMSGTXT_ALL : GETMSGTXT_BODY_ONLY);
if(!editfile(msgtmp, is_msg)) if(!editfile(msgtmp, cfg.level_linespermsg[useron.level]))
return false; return false;
length=(long)flength(msgtmp); length=(long)flength(msgtmp);
if(length<1L) if(length<1L)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment