Remove dependencies from line to display: Move rdonly from display to loc and create instantiable function logger( retcode, beep, string).

This commit is contained in:
Renaud 2013-09-18 10:56:11 +08:00
parent 451b12319a
commit 245c4a0477
6 changed files with 63 additions and 41 deletions

View File

@ -158,9 +158,9 @@ input.o: input.c input.h edef.h estruct.h line.h utf8.h bind.h bindable.h \
display.h exec.h names.h wrapper.h
isearch.o: isearch.c isearch.h basic.h display.h estruct.h line.h utf8.h \
edef.h input.h search.h
line.o: line.c line.h utf8.h display.h estruct.h edef.h log.h
line.o: line.c line.h utf8.h estruct.h edef.h log.h
lock.o: lock.c lock.h estruct.h line.h utf8.h display.h edef.h input.h
log.o: log.c log.h
log.o: log.c log.h estruct.h line.h utf8.h
main.o: main.c basic.h bind.h edef.h estruct.h line.h utf8.h bindable.h \
buffer.h display.h eval.h execute.h file.h input.h lock.h log.h random.h \
search.h termio.h version.h

View File

@ -1553,17 +1553,6 @@ static int newscreensize(int h, int w)
#endif
/*
* tell the user that this command is illegal while we are in
* VIEW (read-only) mode
*/
int rdonly(void)
{
TTbeep();
mlwrite("(Key illegal in VIEW mode)");
return FALSE;
}
int resterr(void)
{
TTbeep();

49
line.c
View File

@ -18,7 +18,6 @@
#include <assert.h>
#include <stdio.h>
#include "display.h"
#include "estruct.h"
#include "edef.h"
#include "log.h"
@ -199,24 +198,23 @@ int insspace(int f, int n)
* linstr -- Insert a string at the current point
*/
int linstr(char *instr)
{
int status = TRUE;
char tmpc;
int linstr( char *instr) {
int status = TRUE ;
if (instr != NULL)
while ((tmpc = *instr) && status == TRUE) {
if( instr != NULL) {
char tmpc ;
while( (tmpc = *instr++)) {
status =
(tmpc == '\n' ? lnewline() : linsert(1, tmpc));
(tmpc == '\n' ? lnewline() : linsert( 1, tmpc)) ;
/* Insertion error? */
if (status != TRUE) {
logwrite( "%%Out of memory while inserting") ;
break;
}
instr++;
if( status != TRUE)
return logger( status, FALSE, "%%Out of memory while inserting") ;
}
return status;
}
return status ;
}
/*
@ -350,24 +348,23 @@ static int lowrite(int c)
/*
* lover -- Overwrite a string at the current point
*/
int lover(char *ostr)
{
int status = TRUE;
char tmpc;
int lover( char *ostr) {
int status = TRUE ;
if (ostr != NULL)
while ((tmpc = *ostr) && status == TRUE) {
if (ostr != NULL) {
char tmpc ;
while( (tmpc = *ostr++)) {
status =
(tmpc == '\n' ? lnewline() : lowrite(tmpc));
/* Insertion error? */
if (status != TRUE) {
logwrite( "%%Out of memory while overwriting") ;
break;
}
ostr++;
if( status != TRUE)
return logger( status, FALSE, "%%Out of memory while overwriting") ;
}
return status;
}
return status ;
}
/*

26
log.c
View File

@ -1,6 +1,30 @@
#include "log.h"
void logdump( const char *buf, ...) {
#include "estruct.h"
static void logdump( const char *buf, ...) {
}
void (*logwrite)( const char *, ...) = logdump ;
static int logit( int retcode, int beep_f, const char *buf, ...) {
return retcode ;
}
int (*logger)( int, int, const char *, ...) = logit ;
/*
* tell the user that this command is illegal while we are in
* VIEW (read-only) mode
*/
int rdonly(void)
{
/* TTbeep();
mlwrite("(Key illegal in VIEW mode)");
return FALSE;
*/
return logger( FALSE, TRUE, "(Key illegal in VIEW mode)");
}

5
log.h
View File

@ -1,2 +1,5 @@
extern void (*logwrite)( const char *, ...) ;
int rdonly( void) ;
extern void (*logwrite)( const char *, ...) ;
extern int (*logger)( int, int, const char *, ...) ;

9
main.c
View File

@ -124,6 +124,14 @@ static void usage( void) {
}
static int mllog( int retcode, int beep_f, const char *buf, ...) {
if( beep_f)
TTbeep() ;
mlwrite( buf) ;
return retcode ;
}
int main(int argc, char **argv)
{
int c = -1; /* command character */
@ -177,6 +185,7 @@ int main(int argc, char **argv)
/* Initialize the editor. */
vtinit(); /* Display */
logwrite = mlwrite ;
logger = mllog ;
edinit("main"); /* Buffers, windows */
varinit(); /* user variables */