From 48db208aac924dea73c865383d36a2fb3fc61ab0 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Tue, 4 Jun 2013 11:52:28 +0800 Subject: [PATCH] extract execute from main to avoid dependencies of file, random and window to main. --- Makefile | 20 +++++++----- execute.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ execute.h | 2 ++ file.c | 2 +- main.c | 93 +--------------------------------------------------- main.h | 1 - random.c | 2 +- window.c | 2 +- 8 files changed, 115 insertions(+), 105 deletions(-) create mode 100644 execute.c create mode 100644 execute.h diff --git a/Makefile b/Makefile index f175715..135d0d9 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -# makefile for emacs, updated Mon, Jun 03, 2013 12:05:22 PM +# makefile for emacs, updated Tue, Jun 04, 2013 11:39:09 AM -SRC=ansi.c basic.c bind.c buffer.c crypt.c display.c ebind.c eval.c exec.c file.c fileio.c globals.c ibmpc.c input.c isearch.c line.c lock.c main.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c vmsvt.c vt52.c window.c word.c wrapper.c -OBJ=ansi.o basic.o bind.o buffer.o crypt.o display.o ebind.o eval.o exec.o file.o fileio.o globals.o ibmpc.o input.o isearch.o line.o lock.o main.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o vmsvt.o vt52.o window.o word.o wrapper.o -HDR=basic.h bind.h buffer.h crypt.h display.h ebind.h edef.h efunc.h estruct.h eval.h exec.h file.h fileio.h input.h isearch.h line.h lock.h main.h names.h pklock.h random.h region.h search.h spawn.h termio.h utf8.h version.h window.h word.h wrapper.h +SRC=ansi.c basic.c bind.c buffer.c crypt.c display.c ebind.c eval.c exec.c execute.c file.c fileio.c globals.c ibmpc.c input.c isearch.c line.c lock.c main.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c vmsvt.c vt52.c window.c word.c wrapper.c +OBJ=ansi.o basic.o bind.o buffer.o crypt.o display.o ebind.o eval.o exec.o execute.o file.o fileio.o globals.o ibmpc.o input.o isearch.o line.o lock.o main.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o vmsvt.o vt52.o window.o word.o wrapper.o +HDR=basic.h bind.h buffer.h crypt.h display.h ebind.h edef.h efunc.h estruct.h eval.h exec.h execute.h file.h fileio.h input.h isearch.h line.h lock.h main.h names.h pklock.h random.h region.h search.h spawn.h termio.h utf8.h version.h window.h word.h wrapper.h # DO NOT ADD OR MODIFY ANY LINES ABOVE THIS -- make source creates them @@ -141,8 +141,10 @@ eval.o: eval.c eval.h estruct.h line.h utf8.h basic.h bind.h edef.h \ version.h window.h exec.o: exec.c exec.h estruct.h line.h utf8.h buffer.h bind.h edef.h \ display.h eval.h file.h input.h +execute.o: execute.c edef.h estruct.h line.h utf8.h bind.h random.h \ + display.h file.h file.o: file.c file.h buffer.h estruct.h line.h utf8.h crypt.h display.h \ - edef.h fileio.h input.h lock.h main.h window.h + edef.h execute.h fileio.h input.h lock.h window.h fileio.o: fileio.c fileio.h crypt.h display.h estruct.h line.h utf8.h \ edef.h globals.o: globals.c estruct.h line.h utf8.h edef.h @@ -154,15 +156,15 @@ isearch.o: isearch.c isearch.h basic.h display.h estruct.h line.h utf8.h \ line.o: line.c line.h utf8.h basic.h display.h estruct.h edef.h random.h lock.o: lock.c lock.h estruct.h line.h utf8.h display.h edef.h input.h main.o: main.c main.h crypt.h display.h estruct.h line.h utf8.h edef.h \ - input.h termio.h version.h basic.h bind.h buffer.h eval.h file.h lock.h \ - random.h search.h + input.h termio.h version.h basic.h bind.h buffer.h eval.h execute.h \ + file.h lock.h random.h search.h names.o: names.c names.h basic.h bind.h edef.h estruct.h line.h utf8.h \ buffer.h display.h eval.h exec.h crypt.h file.h isearch.h main.h \ region.h random.h search.h spawn.h window.h word.h pklock.o: pklock.c pklock.h estruct.h line.h utf8.h edef.h posix.o: posix.c termio.h random.o: random.c random.h basic.h display.h estruct.h line.h utf8.h \ - edef.h input.h main.h search.h + edef.h execute.h input.h search.h region.o: region.c region.h estruct.h line.h utf8.h display.h edef.h search.o: search.c search.h estruct.h line.h utf8.h basic.h display.h \ edef.h input.h @@ -174,7 +176,7 @@ utf8.o: utf8.c utf8.h vmsvt.o: vmsvt.c estruct.h line.h utf8.h edef.h vt52.o: vt52.c estruct.h line.h utf8.h edef.h window.o: window.c window.h estruct.h line.h utf8.h basic.h display.h \ - edef.h main.h wrapper.h + edef.h execute.h wrapper.h word.o: word.c word.h basic.h display.h estruct.h line.h utf8.h edef.h \ random.h region.h wrapper.o: wrapper.c wrapper.h diff --git a/execute.c b/execute.c new file mode 100644 index 0000000..7de8667 --- /dev/null +++ b/execute.c @@ -0,0 +1,98 @@ +#include "edef.h" +#include "bind.h" +#include "random.h" +#include "display.h" +#include "file.h" + +/* + * This is the general command execution routine. It handles the fake binding + * of all the keys to "self-insert". It also clears out the "thisflag" word, + * and arranges to move it to the "lastflag", so that the next command can + * look at it. Return the status of command. + */ +int execute(int c, int f, int n) +{ + int status; + fn_t execfunc; + + /* if the keystroke is a bound function...do it */ + execfunc = getbind(c); + if (execfunc != NULL) { + thisflag = 0; + status = (*execfunc) (f, n); + lastflag = thisflag; + return status; + } + + /* + * If a space was typed, fill column is defined, the argument is non- + * negative, wrap mode is enabled, and we are now past fill column, + * and we are not read-only, perform word wrap. + */ + if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 && + n >= 0 && getccol(FALSE) > fillcol && + (curwp->w_bufp->b_mode & MDVIEW) == FALSE) + execute(META | SPEC | 'W', FALSE, 1); + +#if PKCODE + if ((c >= 0x20 && c <= 0x7E) /* Self inserting. */ +#if IBMPC + || (c >= 0x80 && c <= 0xFE)) { +#else +#if VMS || BSD || USG /* 8BIT P.K. */ + || (c >= 0xA0 && c <= 0x10FFFF)) { +#else + ) { +#endif +#endif +#else + if ((c >= 0x20 && c <= 0xFF)) { /* Self inserting. */ +#endif + if (n <= 0) { /* Fenceposts. */ + lastflag = 0; + return n < 0 ? FALSE : TRUE; + } + thisflag = 0; /* For the future. */ + + /* if we are in overwrite mode, not at eol, + and next char is not a tab or we are at a tab stop, + delete a char forword */ + if (curwp->w_bufp->b_mode & MDOVER && + curwp->w_doto < curwp->w_dotp->l_used && + (lgetc(curwp->w_dotp, curwp->w_doto) != '\t' || + (curwp->w_doto) % 8 == 7)) + ldelchar(1, FALSE); + + /* do the appropriate insertion */ + if (c == '}' && (curbp->b_mode & MDCMOD) != 0) + status = insbrace(n, c); + else if (c == '#' && (curbp->b_mode & MDCMOD) != 0) + status = inspound(); + else + status = linsert(n, c); + +#if CFENCE + /* check for CMODE fence matching */ + if ((c == '}' || c == ')' || c == ']') && + (curbp->b_mode & MDCMOD) != 0) + fmatch(c); +#endif + + /* check auto-save mode */ + if (curbp->b_mode & MDASAVE) + if (--gacount == 0) { + /* and save the file if needed */ + upscreen(FALSE, 0); + filesave(FALSE, 0); + gacount = gasave; + } + + lastflag = thisflag; + return status; + } + TTbeep(); + mlwrite("(Key not bound)"); /* complain */ + lastflag = 0; /* Fake last flags. */ + return FALSE; +} + diff --git a/execute.h b/execute.h new file mode 100644 index 0000000..4cb6224 --- /dev/null +++ b/execute.h @@ -0,0 +1,2 @@ +int execute( int c, int f, int n) ; + diff --git a/file.c b/file.c index 37b2153..109df0f 100644 --- a/file.c +++ b/file.c @@ -19,11 +19,11 @@ #include "display.h" #include "estruct.h" #include "edef.h" +#include "execute.h" #include "fileio.h" #include "input.h" #include "line.h" #include "lock.h" -#include "main.h" #include "window.h" #if defined(PKCODE) diff --git a/main.c b/main.c index 04224a6..e142220 100644 --- a/main.c +++ b/main.c @@ -75,6 +75,7 @@ #include "bind.h" #include "buffer.h" #include "eval.h" +#include "execute.h" #include "file.h" #include "lock.h" #include "random.h" @@ -489,98 +490,6 @@ static void edinit(char *bname) wp->w_flag = WFMODE | WFHARD; /* Full. */ } -/* - * This is the general command execution routine. It handles the fake binding - * of all the keys to "self-insert". It also clears out the "thisflag" word, - * and arranges to move it to the "lastflag", so that the next command can - * look at it. Return the status of command. - */ -int execute(int c, int f, int n) -{ - int status; - fn_t execfunc; - - /* if the keystroke is a bound function...do it */ - execfunc = getbind(c); - if (execfunc != NULL) { - thisflag = 0; - status = (*execfunc) (f, n); - lastflag = thisflag; - return status; - } - - /* - * If a space was typed, fill column is defined, the argument is non- - * negative, wrap mode is enabled, and we are now past fill column, - * and we are not read-only, perform word wrap. - */ - if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 && - n >= 0 && getccol(FALSE) > fillcol && - (curwp->w_bufp->b_mode & MDVIEW) == FALSE) - execute(META | SPEC | 'W', FALSE, 1); - -#if PKCODE - if ((c >= 0x20 && c <= 0x7E) /* Self inserting. */ -#if IBMPC - || (c >= 0x80 && c <= 0xFE)) { -#else -#if VMS || BSD || USG /* 8BIT P.K. */ - || (c >= 0xA0 && c <= 0x10FFFF)) { -#else - ) { -#endif -#endif -#else - if ((c >= 0x20 && c <= 0xFF)) { /* Self inserting. */ -#endif - if (n <= 0) { /* Fenceposts. */ - lastflag = 0; - return n < 0 ? FALSE : TRUE; - } - thisflag = 0; /* For the future. */ - - /* if we are in overwrite mode, not at eol, - and next char is not a tab or we are at a tab stop, - delete a char forword */ - if (curwp->w_bufp->b_mode & MDOVER && - curwp->w_doto < curwp->w_dotp->l_used && - (lgetc(curwp->w_dotp, curwp->w_doto) != '\t' || - (curwp->w_doto) % 8 == 7)) - ldelchar(1, FALSE); - - /* do the appropriate insertion */ - if (c == '}' && (curbp->b_mode & MDCMOD) != 0) - status = insbrace(n, c); - else if (c == '#' && (curbp->b_mode & MDCMOD) != 0) - status = inspound(); - else - status = linsert(n, c); - -#if CFENCE - /* check for CMODE fence matching */ - if ((c == '}' || c == ')' || c == ']') && - (curbp->b_mode & MDCMOD) != 0) - fmatch(c); -#endif - - /* check auto-save mode */ - if (curbp->b_mode & MDASAVE) - if (--gacount == 0) { - /* and save the file if needed */ - upscreen(FALSE, 0); - filesave(FALSE, 0); - gacount = gasave; - } - - lastflag = thisflag; - return status; - } - TTbeep(); - mlwrite("(Key not bound)"); /* complain */ - lastflag = 0; /* Fake last flags. */ - return FALSE; -} - /* * Fancy quit command, as implemented by Norm. If the any buffer has * changed do a write on that buffer and exit emacs, otherwise simply exit. diff --git a/main.h b/main.h index fb2150c..d35d539 100644 --- a/main.h +++ b/main.h @@ -1,7 +1,6 @@ #ifndef _MAIN_H_ #define _MAIN_H_ -int execute( int c, int f, int n) ; int quickexit( int f, int n) ; int quit( int f, int n) ; int ctlxlp( int f, int n) ; diff --git a/random.c b/random.c index 7ba83c1..06e8160 100644 --- a/random.c +++ b/random.c @@ -15,9 +15,9 @@ #include "display.h" #include "estruct.h" #include "edef.h" +#include "execute.h" #include "input.h" #include "line.h" -#include "main.h" #include "search.h" int tabsize; /* Tab size (0: use real tabs) */ diff --git a/window.c b/window.c index bd70e44..2dbc0cf 100644 --- a/window.c +++ b/window.c @@ -15,8 +15,8 @@ #include "display.h" #include "estruct.h" #include "edef.h" +#include "execute.h" #include "line.h" -#include "main.h" #include "wrapper.h" /*