Transition from logger/logwrite/mlwrite to writestr/writefmt.

This commit is contained in:
Renaud 2015-01-21 21:30:01 +08:00
parent 891f4c3238
commit 15ae2d4135
11 changed files with 70 additions and 66 deletions

15
basic.c
View File

@ -100,8 +100,10 @@ int gotoline(int f, int n)
/* Get an argument if one doesnt exist. */
if( f == FALSE) {
status = mlreply( "Line to GOTO: ", arg, sizeof arg) ;
if( status != TRUE)
return logger( status, "(Aborted)") ;
if( status != TRUE) {
writestr( "(Aborted)") ;
return status ;
}
n = atoi( arg) ;
}
@ -313,7 +315,8 @@ int setmark(int f, int n)
{
curwp->w_markp = curwp->w_dotp;
curwp->w_marko = curwp->w_doto;
return logger( TRUE, "(Mark set)") ;
writestr( "(Mark set)") ;
return TRUE ;
}
/*
@ -327,8 +330,10 @@ int swapmark(int f, int n)
struct line *odotp;
int odoto;
if( curwp->w_markp == NULL)
return logger( FALSE, "No mark in this window") ;
if( curwp->w_markp == NULL) {
writestr( "No mark in this window") ;
return FALSE ;
}
odotp = curwp->w_dotp;
odoto = curwp->w_doto;

View File

@ -150,7 +150,8 @@ int ctlxe(int f, int n)
*/
int ctrlg( int f, int n) {
kbdmode = STOP ;
return logger( ABORT, "%B(Aborted)") ;
writefmt( "%B(Aborted)") ;
return ABORT ;
}
/* user function that does NOTHING */

View File

@ -102,6 +102,7 @@ int execute(int c, int f, int n)
}
lastflag = 0 ; /* Fake last flags. */
return logger( FALSE, "%B(Key not bound)") ; /* Complain */
writefmt( "%B(Key not bound)") ; /* Complain */
return FALSE ;
}

36
file.c
View File

@ -169,7 +169,7 @@ int set_encryption_key(int f, int n)
strcpy(curbp->b_key, key);
cryptbufferkey( curbp) ;
logwrite(" "); /* clear it off the bottom line */
writestr( " ") ; /* clear it off the bottom line */
return TRUE;
}
@ -231,7 +231,7 @@ int getfile( const char *fname, boolean lockfl)
curwp->w_linep = lp;
curwp->w_flag |= WFMODE | WFHARD;
cknewwindow();
logwrite("(Old buffer)");
writestr( "(Old buffer)") ;
return TRUE;
}
}
@ -247,7 +247,7 @@ int getfile( const char *fname, boolean lockfl)
}
}
if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) {
logwrite("Cannot create buffer");
writestr( "Cannot create buffer") ;
return FALSE;
}
if (--curbp->b_nwnd == 0) { /* Undisplay. */
@ -318,12 +318,12 @@ int readin(const char *fname, boolean lockfl)
goto out;
if (s == FIOFNF) { /* File not found. */
logwrite("(New file)");
writestr( "(New file)") ;
goto out;
}
/* read the file in */
logwrite("(Reading file)");
writestr( "(Reading file)") ;
nline = 0;
while ((s = ffgetline()) == FIOSUC) {
nbytes = fpayload ;
@ -347,7 +347,7 @@ int readin(const char *fname, boolean lockfl)
}
if( s == FIOERR)
logwrite( "File read error") ;
writestr( "File read error") ;
switch( ftype) {
case FTYPE_DOS:
@ -386,7 +386,7 @@ int readin(const char *fname, boolean lockfl)
strcat( mesg, ", eol = ") ;
strcat( mesg, eolname[ found_eol]) ;
strcat(mesg, ")");
logwrite(mesg);
writestr( mesg) ;
out:
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
@ -518,14 +518,14 @@ int filesave(int f, int n)
if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */
return TRUE;
if (curbp->b_fname[0] == 0) { /* Must have a name. */
logwrite("No file name");
writestr( "No file name") ;
return FALSE;
}
/* complain about truncated files */
if ((curbp->b_flag & BFTRUNC) != 0) {
if (mlyesno("Truncated file ... write it out") == FALSE) {
logwrite("(Aborted)");
writestr( "(Aborted)") ;
return FALSE;
}
}
@ -563,16 +563,16 @@ int writeout( const char *fn)
#endif
if ((s = ffwopen(fn)) != FIOSUC) { /* Open writes message. */
logwrite( "Cannot open file for writing") ;
writestr( "Cannot open file for writing") ;
return FALSE;
}
logwrite("(Writing...)"); /* tell us were writing */
writestr( "(Writing...)") ; /* tell us were writing */
lp = lforw(curbp->b_linep); /* First line. */
nline = 0; /* Number of lines. */
while (lp != curbp->b_linep) {
s = ffputline( &lp->l_text[0], llength(lp), curbp->b_mode & MDDOS) ;
if( s != FIOSUC) {
logwrite( "Write I/O error") ;
writestr( "Write I/O error") ;
break;
}
@ -583,11 +583,11 @@ int writeout( const char *fn)
s = ffclose();
if (s == FIOSUC) { /* No close error. */
if (nline == 1)
logwrite("(Wrote 1 line)");
writestr( "(Wrote 1 line)") ;
else
logwrite("(Wrote %d lines)", nline);
writefmt( "(Wrote %d lines)", nline) ;
} else
logwrite( "Error closing file") ;
writestr( "Error closing file") ;
} else /* Ignore close error */
ffclose(); /* if a write error. */
if (s != FIOSUC) /* Some sort of error. */
@ -650,10 +650,10 @@ int ifile( const char *fname)
if ((s = ffropen(fname)) == FIOERR) /* Hard file open. */
goto out;
if (s == FIOFNF) { /* File not found. */
logwrite("(No such file)");
writestr( "(No such file)") ;
return FALSE;
}
logwrite("(Inserting file)");
writestr( "(Inserting file)") ;
#if CRYPT
s = resetkey();
@ -702,7 +702,7 @@ int ifile( const char *fname)
if (nline > 1)
strcat(mesg, "s");
strcat(mesg, ")");
logwrite(mesg);
writestr( mesg);
out:
/* advance to the next line and mark the window for changes */

16
line.c
View File

@ -164,7 +164,7 @@ struct line *lalloc(int used)
if (size == 0) /* Assume that is an empty. */
size = BLOCK_SIZE; /* Line is for type-in. */
if ((lp = (struct line *)malloc(sizeof(struct line) + size)) == NULL) {
logwrite( "(OUT OF MEMORY)") ;
writestr( "(OUT OF MEMORY)") ;
return NULL;
}
lp->l_size = size;
@ -268,8 +268,10 @@ int linstr( char *instr) {
(tmpc == '\n' ? lnewline() : linsert( 1, tmpc)) ;
/* Insertion error? */
if( status != TRUE)
return logger( status, "%%Out of memory while inserting") ;
if( status != TRUE) {
writestr( "%Out of memory while inserting") ;
return status ;
}
}
}
@ -306,7 +308,7 @@ static int linsert_byte(int n, int c)
lp1 = curwp->w_dotp; /* Current line */
if (lp1 == curbp->b_linep) { /* At the end: special */
if (curwp->w_doto != 0) {
logwrite( "bug: linsert") ;
writestr( "bug: linsert") ;
return FALSE;
}
if ((lp2 = lalloc(n)) == NULL) /* Allocate new line */
@ -418,8 +420,10 @@ int lover( char *ostr) {
(tmpc == '\n' ? lnewline() : lowrite(tmpc));
/* Insertion error? */
if( status != TRUE)
return logger( status, "%%Out of memory while overwriting") ;
if( status != TRUE) {
writestr( "%Out of memory while overwriting") ;
return status ;
}
}
}

15
log.c
View File

@ -3,25 +3,24 @@
static void logdump( const char *buf, ...) {
}
void (*logwrite)( const char *, ...) = logdump ;
void (*writefmt)( const char *, ...) = logdump ;
static boolean logit( boolean retcode, const char *buf, ...) {
return retcode ;
void writestr( const char *str) {
writefmt( "%s", str) ;
}
boolean (*logger)( boolean, const char *, ...) = logit ;
/*
* tell the user that this command is illegal while we are in
* VIEW (read-only) mode
*/
boolean rdonly( void) {
return logger( FALSE, "%B(Key illegal in VIEW mode)");
writefmt( "%B(Key illegal in VIEW mode)") ;
return FALSE ;
}
boolean resterr( void) {
return logger( FALSE, "%B(That command is RESTRICTED)");
writefmt( "%B(That command is RESTRICTED)") ;
return FALSE ;
}

8
log.h
View File

@ -1,8 +1,8 @@
#include "retcode.h"
extern void (*writefmt)( const char *, ...) ;
void writestr( const char *str) ;
boolean rdonly( void) ;
boolean resterr( void) ;
extern void (*logwrite)( const char *, ...) ;
extern boolean (*logger)( boolean, const char *, ...) ;

21
main.c
View File

@ -130,11 +130,6 @@ static void usage( void) {
}
static boolean mllog( boolean retcode, const char *buf, ...) {
mlwrite( buf) ;
return retcode ;
}
int main(int argc, char **argv)
{
int c = -1; /* command character */
@ -187,8 +182,7 @@ int main(int argc, char **argv)
/* Initialize the editor. */
vtinit(); /* Display */
logwrite = mlwrite ;
logger = mllog ;
writefmt = mlwrite ;
edinit("main"); /* Buffers, windows */
varinit(); /* user variables */
@ -324,11 +318,11 @@ int main(int argc, char **argv)
/* Deal with startup gotos and searches */
if (gotoflag && searchflag) {
update(FALSE);
mlwrite("(Can not search and goto at the same time!)");
writestr( "(Can not search and goto at the same time!)") ;
} else if (gotoflag) {
if (gotoline(TRUE, gline) == FALSE) {
update(FALSE);
mlwrite("(Bogus goto argument)");
writestr( "(Bogus goto argument)") ;
}
} else if (searchflag) {
if (forwhunt(FALSE, 0) == FALSE)
@ -400,9 +394,9 @@ int main(int argc, char **argv)
n = n * 10 + (c - '0');
}
if ((n == 0) && (mflag == -1)) /* lonely - */
mlwrite("Arg:");
writestr( "Arg:") ;
else
mlwrite("Arg: %d", n * mflag);
writefmt( "Arg: %d", n * mflag) ;
c = getcmd(); /* get the next key */
}
@ -415,7 +409,7 @@ int main(int argc, char **argv)
f = TRUE;
n = 4; /* with argument of 4 */
mflag = 0; /* that can be discarded. */
mlwrite("Arg: 4");
writestr( "Arg: 4") ;
while (((c = getcmd()) >= '0' && c <= '9') || c == reptc
|| c == '-') {
if (c == reptc)
@ -444,8 +438,7 @@ int main(int argc, char **argv)
}
n = 10 * n + c - '0';
}
mlwrite("Arg: %d",
(mflag >= 0) ? n : (n ? -n : -1));
writefmt( "Arg: %d", (mflag >= 0) ? n : (n ? -n : -1)) ;
}
/*
* Make arguments preceded by a minus sign negative and change

View File

@ -74,7 +74,7 @@ int copyregion(int f, int n)
++loffs;
}
}
logwrite("(region copied)");
writestr( "(region copied)") ;
return TRUE;
}
@ -171,7 +171,7 @@ int getregion(struct region *rp)
long bsize;
if (curwp->w_markp == NULL) {
logwrite("No mark set in this window");
writestr( "No mark set in this window") ;
return FALSE;
}
if (curwp->w_dotp == curwp->w_markp) {
@ -213,6 +213,6 @@ int getregion(struct region *rp)
}
}
}
logwrite("Bug: lost mark");
writestr( "Bug: lost mark") ;
return FALSE;
}

View File

@ -984,7 +984,8 @@ static int replaces(int kind, int f, int n)
curwp->w_flag |= WFMOVE;
case BELL: /* abort! and stay */
return logger( FALSE, "Aborted!") ;
writestr( "Aborted!") ;
return FALSE ;
default: /* bitch and beep */
TTbeep();

10
word.c
View File

@ -428,7 +428,7 @@ int fillpara(int f, int n)
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (fillcol == 0) { /* no fill column set */
logwrite("No fill column set");
writestr( "No fill column set") ;
return FALSE;
}
#if PKCODE
@ -527,14 +527,14 @@ int justpara(int f, int n)
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (fillcol == 0) { /* no fill column set */
logwrite("No fill column set");
writestr( "No fill column set") ;
return FALSE;
}
justflag = TRUE;
leftmarg = curwp->w_doto;
if (leftmarg + 10 > fillcol) {
leftmarg = 0;
logwrite("Column too narrow");
writestr( "Column too narrow") ;
return FALSE;
}
@ -719,8 +719,8 @@ int wordcount(int f, int n)
else
avgch = 0;
logwrite("Words %D Chars %D Lines %d Avg chars/word %f",
nwords, nchars, nlines + 1, avgch);
writefmt( "Words %D Chars %D Lines %d Avg chars/word %f",
nwords, nchars, nlines + 1, avgch) ;
return TRUE;
}
#endif