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

sbbs.editfile() now returns bool.

parent 4264b42c
No related branches found
No related tags found
No related merge requests found
......@@ -1005,7 +1005,7 @@ js_editfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
cstr=JS_GetStringBytes(str);
rc=JS_SUSPENDREQUEST(cx);
sbbs->editfile(JS_GetStringBytes(str));
*rval = BOOLEAN_TO_JSVAL(sbbs->editfile(JS_GetStringBytes(str)));
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
}
......@@ -1514,7 +1514,7 @@ static jsSyncMethodSpec js_console_functions[] = {
,JSDOCSTR("print last x lines of file with optional mode")
,310
},
{"editfile", js_editfile, 1, JSTYPE_VOID, JSDOCSTR("filename")
{"editfile", js_editfile, 1, JSTYPE_BOOLEAN, JSDOCSTR("filename")
,JSDOCSTR("edit/create a text file using the user's preferred message editor")
,310
},
......
......@@ -476,7 +476,7 @@ public:
void forwardmail(smbmsg_t* msg, int usernum);
void removeline(char *str, char *str2, char num, char skip);
ulong msgeditor(char *buf, const char *top, char *title);
void editfile(char *path);
bool editfile(char *path);
int loadmsg(smbmsg_t *msg, ulong number);
ushort chmsgattr(ushort attr);
void show_msgattr(ushort attr);
......
......@@ -953,7 +953,7 @@ ulong sbbs_t::msgeditor(char *buf, const char *top, char *title)
/****************************************************************************/
/* Edits an existing file or creates a new one in MSG format */
/****************************************************************************/
void sbbs_t::editfile(char *fname)
bool sbbs_t::editfile(char *fname)
{
char *buf,path[MAX_PATH+1];
char msgtmp[MAX_PATH+1];
......@@ -990,18 +990,18 @@ void sbbs_t::editfile(char *fname)
}
CLS;
rioctl(IOCM|PAUSE|ABORT);
if(external(cmdstr(cfg.xedit[useron.xedit-1]->rcmd,msgtmp,nulstr,NULL),mode,cfg.node_dir)==0) {
if(external(cmdstr(cfg.xedit[useron.xedit-1]->rcmd,msgtmp,nulstr,NULL),mode,cfg.node_dir)!=0)
return false;
l=process_edited_file(msgtmp, path, /* mode: */0, &lines);
SAFEPRINTF4(str,"%s created or edited file: %s (%u bytes, %u lines)"
,useron.alias, path, l, lines);
logline(nulstr,str);
}
rioctl(IOSM|PAUSE|ABORT);
return;
return true;
}
if((buf=(char *)malloc(maxlines*MAX_LINE_LEN))==NULL) {
errormsg(WHERE,ERR_ALLOC,nulstr,maxlines*MAX_LINE_LEN);
return;
return false;
}
if((file=nopen(fname,O_RDONLY))!=-1) {
length=filelength(file);
......@@ -1011,13 +1011,13 @@ void sbbs_t::editfile(char *fname)
attr(cfg.color[clr_err]);
bprintf("\7\r\nFile size (%lu bytes) is larger than %lu (maxlines: %lu).\r\n"
,length, (ulong)maxlines*MAX_LINE_LEN, maxlines);
return;
return false;
}
if(read(file,buf,length)!=length) {
close(file);
free(buf);
errormsg(WHERE,ERR_READ,fname,length);
return;
return false;
}
buf[length]=0;
close(file);
......@@ -1028,13 +1028,13 @@ void sbbs_t::editfile(char *fname)
}
if(!msgeditor(buf,nulstr,nulstr)) {
free(buf);
return;
return false;
}
bputs(text[Saving]);
if((stream=fnopen(NULL,fname,O_CREAT|O_WRONLY|O_TRUNC))==NULL) {
errormsg(WHERE,ERR_OPEN,fname,O_CREAT|O_WRONLY|O_TRUNC);
free(buf);
return;
return false;
}
l=process_edited_text(buf,stream,/* mode: */0,&lines);
bprintf(text[SavedNBytes],l,lines);
......@@ -1043,6 +1043,7 @@ void sbbs_t::editfile(char *fname)
SAFEPRINTF4(str,"%s created or edited file: %s (%u bytes, %u lines)"
,useron.alias, fname, l, lines);
logline(nulstr,str);
return true;
}
/*************************/
......@@ -1264,7 +1265,8 @@ void sbbs_t::editmsg(smbmsg_t *msg, uint subnum)
msg_tmp_fname(useron.xedit, msgtmp, sizeof(msgtmp));
removecase(msgtmp);
msgtotxt(msg,msgtmp,0,1);
editfile(msgtmp);
if(!editfile(msgtmp))
return;
length=flength(msgtmp);
if(length<1L)
return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment