From 15ae2d4135cec17d046f716b15ad70d7750e4652 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Wed, 21 Jan 2015 21:30:01 +0800 Subject: [PATCH] Transition from logger/logwrite/mlwrite to writestr/writefmt. --- basic.c | 15 ++++++++++----- bindable.c | 3 ++- execute.c | 3 ++- file.c | 36 ++++++++++++++++++------------------ line.c | 16 ++++++++++------ log.c | 15 +++++++-------- log.h | 8 ++++---- main.c | 21 +++++++-------------- region.c | 6 +++--- search.c | 3 ++- word.c | 10 +++++----- 11 files changed, 70 insertions(+), 66 deletions(-) diff --git a/basic.c b/basic.c index 0d79d04..271a13c 100644 --- a/basic.c +++ b/basic.c @@ -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; diff --git a/bindable.c b/bindable.c index 8777f4f..375ae49 100644 --- a/bindable.c +++ b/bindable.c @@ -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 */ diff --git a/execute.c b/execute.c index 255501e..4829d18 100644 --- a/execute.c +++ b/execute.c @@ -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 ; } diff --git a/file.c b/file.c index 9594553..38c9da4 100644 --- a/file.c +++ b/file.c @@ -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 */ diff --git a/line.c b/line.c index 060f7f2..c4ec6d6 100644 --- a/line.c +++ b/line.c @@ -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 ; + } } } diff --git a/log.c b/log.c index 492ad21..75e6671 100644 --- a/log.c +++ b/log.c @@ -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 ; } - - diff --git a/log.h b/log.h index b23a661..e330be9 100644 --- a/log.h +++ b/log.h @@ -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 *, ...) ; - diff --git a/main.c b/main.c index 6ab7832..be019a3 100644 --- a/main.c +++ b/main.c @@ -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 diff --git a/region.c b/region.c index 8e70093..355b500 100644 --- a/region.c +++ b/region.c @@ -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; } diff --git a/search.c b/search.c index 38ebbff..09482e4 100644 --- a/search.c +++ b/search.c @@ -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(); diff --git a/word.c b/word.c index b29f060..51adc78 100644 --- a/word.c +++ b/word.c @@ -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