From c96138add58a368c82202775a274921b640675fa Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Wed, 5 Jun 2013 11:48:40 +0800 Subject: [PATCH] remove left dependencies to main: bindable functions. --- Makefile | 25 ++++---- bind.c | 2 +- bindable.c | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++ bindable.h | 11 ++++ ebind.c | 2 +- input.c | 2 +- main.c | 179 +++-------------------------------------------------- main.h | 12 +--- names.c | 2 +- 9 files changed, 211 insertions(+), 198 deletions(-) create mode 100644 bindable.c create mode 100644 bindable.h diff --git a/Makefile b/Makefile index 135d0d9..9791d54 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ -# makefile for emacs, updated Tue, Jun 04, 2013 11:39:09 AM +# makefile for emacs, updated Wed, Jun 05, 2013 11:36:19 AM -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 +SRC=ansi.c basic.c bind.c bindable.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 bindable.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 bindable.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 @@ -126,15 +126,16 @@ depend: ${SRC} ansi.o: ansi.c estruct.h line.h utf8.h edef.h basic.o: basic.c basic.h display.h estruct.h line.h utf8.h edef.h input.h \ random.h word.h -bind.o: bind.c bind.h edef.h estruct.h line.h utf8.h buffer.h display.h \ - ebind.h exec.h file.h fileio.h input.h main.h names.h window.h +bind.o: bind.c bind.h edef.h estruct.h line.h utf8.h bindable.h buffer.h \ + display.h ebind.h exec.h file.h fileio.h input.h names.h window.h +bindable.o: bindable.c bindable.h buffer.o: buffer.c buffer.h estruct.h line.h utf8.h display.h edef.h \ file.h input.h window.h crypt.o: crypt.c crypt.h display.h estruct.h line.h utf8.h edef.h input.h display.o: display.c display.h estruct.h line.h utf8.h edef.h termio.h \ version.h wrapper.h window.h ebind.o: ebind.c ebind.h basic.h bind.h edef.h estruct.h line.h utf8.h \ - buffer.h crypt.h eval.h exec.h file.h isearch.h main.h random.h \ + bindable.h buffer.h crypt.h eval.h exec.h file.h isearch.h random.h \ region.h search.h spawn.h window.h word.h eval.o: eval.c eval.h estruct.h line.h utf8.h basic.h bind.h edef.h \ buffer.h display.h exec.h fileio.h input.h random.h search.h termio.h \ @@ -149,17 +150,17 @@ 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 ibmpc.o: ibmpc.c estruct.h line.h utf8.h edef.h -input.o: input.c input.h edef.h estruct.h line.h utf8.h bind.h display.h \ - exec.h main.h names.h wrapper.h +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 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 execute.h \ - file.h lock.h random.h search.h + input.h termio.h version.h basic.h bind.h bindable.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 \ + bindable.h buffer.h display.h eval.h exec.h crypt.h file.h isearch.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 diff --git a/bind.c b/bind.c index 075f582..62f20b5 100644 --- a/bind.c +++ b/bind.c @@ -12,6 +12,7 @@ #include +#include "bindable.h" #include "buffer.h" #include "display.h" #include "ebind.h" @@ -20,7 +21,6 @@ #include "fileio.h" #include "input.h" #include "line.h" -#include "main.h" #include "names.h" #include "window.h" diff --git a/bindable.c b/bindable.c new file mode 100644 index 0000000..2dd341a --- /dev/null +++ b/bindable.c @@ -0,0 +1,174 @@ +/* bindable.h -- implements bindable.c */ +#include "bindable.h" + +#include "buffer.h" +#include "display.h" +#include "edef.h" +#include "file.h" +#include "input.h" + +#if VMS +#include +#define GOOD (SS$_NORMAL) +#endif + +#ifndef GOOD +#define GOOD 0 +#endif + +/* + * 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. + */ +int quickexit(int f, int n) +{ + struct buffer *bp; /* scanning pointer to buffers */ + struct buffer *oldcb; /* original current buffer */ + int status; + + oldcb = curbp; /* save in case we fail */ + + bp = bheadp; + while (bp != NULL) { + if ((bp->b_flag & BFCHG) != 0 /* Changed. */ + && (bp->b_flag & BFTRUNC) == 0 /* Not truncated P.K. */ + && (bp->b_flag & BFINVS) == 0) { /* Real. */ + curbp = bp; /* make that buffer cur */ + mlwrite("(Saving %s)", bp->b_fname); +#if PKCODE +#else + mlwrite("\n"); +#endif + if ((status = filesave(f, n)) != TRUE) { + curbp = oldcb; /* restore curbp */ + return status; + } + } + bp = bp->b_bufp; /* on to the next buffer */ + } + quit(f, n); /* conditionally quit */ + return TRUE; +} + +/* + * Quit command. If an argument, always quit. Otherwise confirm if a buffer + * has been changed and not written out. Normally bound to "C-X C-C". + */ +int quit(int f, int n) +{ + int s; + + if (f != FALSE /* Argument forces it. */ + || anycb() == FALSE /* All buffers clean. */ + /* User says it's OK. */ + || (s = + mlyesno("Modified buffers exist. Leave anyway")) == TRUE) { +#if (FILOCK && BSD) || SVR4 + if (lockrel() != TRUE) { + TTputc('\n'); + TTputc('\r'); + TTclose(); + TTkclose(); + exit(1); + } +#endif + vttidy(); + if (f) + exit(n); + else + exit(GOOD); + } + mlwrite(""); + return s; +} + +/* + * Begin a keyboard macro. + * Error if not at the top level in keyboard processing. Set up variables and + * return. + */ +int ctlxlp(int f, int n) +{ + if (kbdmode != STOP) { + mlwrite("%%Macro already active"); + return FALSE; + } + mlwrite("(Start macro)"); + kbdptr = &kbdm[0]; + kbdend = kbdptr; + kbdmode = RECORD; + return TRUE; +} + +/* + * End keyboard macro. Check for the same limit conditions as the above + * routine. Set up the variables and return to the caller. + */ +int ctlxrp(int f, int n) +{ + if (kbdmode == STOP) { + mlwrite("%%Macro not active"); + return FALSE; + } + if (kbdmode == RECORD) { + mlwrite("(End macro)"); + kbdmode = STOP; + } + return TRUE; +} + +/* + * Execute a macro. + * The command argument is the number of times to loop. Quit as soon as a + * command gets an error. Return TRUE if all ok, else FALSE. + */ +int ctlxe(int f, int n) +{ + if (kbdmode != STOP) { + mlwrite("%%Macro already active"); + return FALSE; + } + if (n <= 0) + return TRUE; + kbdrep = n; /* remember how many times to execute */ + kbdmode = PLAY; /* start us in play mode */ + kbdptr = &kbdm[0]; /* at the beginning */ + return TRUE; +} + +/* + * Abort. + * Beep the beeper. Kill off any keyboard macro, etc., that is in progress. + * Sometimes called as a routine, to do general aborting of stuff. + */ +int ctrlg(int f, int n) +{ + TTbeep(); + kbdmode = STOP; + mlwrite("(Aborted)"); + return ABORT; +} + +/* user function that does NOTHING */ +int nullproc(int f, int n) +{ + return TRUE; +} + +/* dummy function for binding to meta prefix */ +int metafn(int f, int n) +{ + return TRUE; +} + +/* dummy function for binding to control-x prefix */ +int cex(int f, int n) +{ + return TRUE; +} + +/* dummy function for binding to universal-argument */ +int unarg(int f, int n) +{ + return TRUE; +} diff --git a/bindable.h b/bindable.h new file mode 100644 index 0000000..8e10ac6 --- /dev/null +++ b/bindable.h @@ -0,0 +1,11 @@ +/* functions that can be bound to keys or procedure names */ +int quickexit( int f, int n) ; +int quit( int f, int n) ; +int ctlxlp( int f, int n) ; +int ctlxrp( int f, int n) ; +int ctlxe( int f, int n) ; +int ctrlg( int f, int n) ; +int nullproc( int f, int n) ; +int metafn( int f, int n) ; +int cex( int f, int n) ; +int unarg( int f, int n) ; diff --git a/ebind.c b/ebind.c index 2f2b33b..2f9e9ad 100644 --- a/ebind.c +++ b/ebind.c @@ -10,6 +10,7 @@ #include "basic.h" #include "bind.h" +#include "bindable.h" #include "buffer.h" #include "crypt.h" #include "eval.h" @@ -17,7 +18,6 @@ #include "file.h" #include "isearch.h" #include "line.h" -#include "main.h" #include "random.h" #include "region.h" #include "search.h" diff --git a/input.c b/input.c index c0cd844..1bd797d 100644 --- a/input.c +++ b/input.c @@ -14,9 +14,9 @@ #include #include "bind.h" +#include "bindable.h" #include "display.h" #include "exec.h" -#include "main.h" #include "names.h" #include "wrapper.h" diff --git a/main.c b/main.c index e142220..352a0b1 100644 --- a/main.c +++ b/main.c @@ -73,6 +73,7 @@ #include "basic.h" #include "bind.h" +#include "bindable.h" #include "buffer.h" #include "eval.h" #include "execute.h" @@ -90,21 +91,18 @@ extern unsigned _stklen = 32766; #endif #endif -#if VMS -#include -#define GOOD (SS$_NORMAL) -#endif - -#ifndef GOOD -#define GOOD 0 -#endif - #if UNIX #include static void emergencyexit(int); #ifdef SIGWINCH extern void sizesignal(int); #endif + +static void emergencyexit(int signr) +{ + quickexit(FALSE, 0); + quit(TRUE, 0); +} #endif static void edinit( char *bname) ; @@ -490,169 +488,6 @@ static void edinit(char *bname) wp->w_flag = WFMODE | WFHARD; /* Full. */ } -/* - * 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. - */ -int quickexit(int f, int n) -{ - struct buffer *bp; /* scanning pointer to buffers */ - struct buffer *oldcb; /* original current buffer */ - int status; - - oldcb = curbp; /* save in case we fail */ - - bp = bheadp; - while (bp != NULL) { - if ((bp->b_flag & BFCHG) != 0 /* Changed. */ - && (bp->b_flag & BFTRUNC) == 0 /* Not truncated P.K. */ - && (bp->b_flag & BFINVS) == 0) { /* Real. */ - curbp = bp; /* make that buffer cur */ - mlwrite("(Saving %s)", bp->b_fname); -#if PKCODE -#else - mlwrite("\n"); -#endif - if ((status = filesave(f, n)) != TRUE) { - curbp = oldcb; /* restore curbp */ - return status; - } - } - bp = bp->b_bufp; /* on to the next buffer */ - } - quit(f, n); /* conditionally quit */ - return TRUE; -} - -static void emergencyexit(int signr) -{ - quickexit(FALSE, 0); - quit(TRUE, 0); -} - -/* - * Quit command. If an argument, always quit. Otherwise confirm if a buffer - * has been changed and not written out. Normally bound to "C-X C-C". - */ -int quit(int f, int n) -{ - int s; - - if (f != FALSE /* Argument forces it. */ - || anycb() == FALSE /* All buffers clean. */ - /* User says it's OK. */ - || (s = - mlyesno("Modified buffers exist. Leave anyway")) == TRUE) { -#if (FILOCK && BSD) || SVR4 - if (lockrel() != TRUE) { - TTputc('\n'); - TTputc('\r'); - TTclose(); - TTkclose(); - exit(1); - } -#endif - vttidy(); - if (f) - exit(n); - else - exit(GOOD); - } - mlwrite(""); - return s; -} - -/* - * Begin a keyboard macro. - * Error if not at the top level in keyboard processing. Set up variables and - * return. - */ -int ctlxlp(int f, int n) -{ - if (kbdmode != STOP) { - mlwrite("%%Macro already active"); - return FALSE; - } - mlwrite("(Start macro)"); - kbdptr = &kbdm[0]; - kbdend = kbdptr; - kbdmode = RECORD; - return TRUE; -} - -/* - * End keyboard macro. Check for the same limit conditions as the above - * routine. Set up the variables and return to the caller. - */ -int ctlxrp(int f, int n) -{ - if (kbdmode == STOP) { - mlwrite("%%Macro not active"); - return FALSE; - } - if (kbdmode == RECORD) { - mlwrite("(End macro)"); - kbdmode = STOP; - } - return TRUE; -} - -/* - * Execute a macro. - * The command argument is the number of times to loop. Quit as soon as a - * command gets an error. Return TRUE if all ok, else FALSE. - */ -int ctlxe(int f, int n) -{ - if (kbdmode != STOP) { - mlwrite("%%Macro already active"); - return FALSE; - } - if (n <= 0) - return TRUE; - kbdrep = n; /* remember how many times to execute */ - kbdmode = PLAY; /* start us in play mode */ - kbdptr = &kbdm[0]; /* at the beginning */ - return TRUE; -} - -/* - * Abort. - * Beep the beeper. Kill off any keyboard macro, etc., that is in progress. - * Sometimes called as a routine, to do general aborting of stuff. - */ -int ctrlg(int f, int n) -{ - TTbeep(); - kbdmode = STOP; - mlwrite("(Aborted)"); - return ABORT; -} - -/* user function that does NOTHING */ -int nullproc(int f, int n) -{ - return TRUE; -} - -/* dummy function for binding to meta prefix */ -int metafn(int f, int n) -{ - return TRUE; -} - -/* dummy function for binding to control-x prefix */ -int cex(int f, int n) -{ - return TRUE; -} - -/* dummy function for binding to universal-argument */ -int unarg(int f, int n) -{ - return TRUE; -} - /***** Compiler specific Library functions ****/ #if RAMSIZE diff --git a/main.h b/main.h index d35d539..34c2f3b 100644 --- a/main.h +++ b/main.h @@ -1,16 +1,8 @@ #ifndef _MAIN_H_ #define _MAIN_H_ -int quickexit( int f, int n) ; -int quit( int f, int n) ; -int ctlxlp( int f, int n) ; -int ctlxrp( int f, int n) ; -int ctlxe( int f, int n) ; -int ctrlg( int f, int n) ; -int nullproc( int f, int n) ; -int metafn( int f, int n) ; -int cex( int f, int n) ; -int unarg( int f, int n) ; +#if CLEAN int cexit( int status) ; +#endif #endif diff --git a/names.c b/names.c index 17c9cf3..82dfa0b 100644 --- a/names.c +++ b/names.c @@ -10,6 +10,7 @@ #include "basic.h" #include "bind.h" +#include "bindable.h" #include "buffer.h" #include "display.h" #include "eval.h" @@ -18,7 +19,6 @@ #include "file.h" #include "isearch.h" #include "line.h" -#include "main.h" #include "region.h" #include "random.h" #include "search.h"