mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-18 15:26:23 -05:00
Move command loop from main to kbd_loop in execute.
This commit is contained in:
parent
5c6aac1ae9
commit
7188773d13
146
execute.c
146
execute.c
@ -1,6 +1,8 @@
|
|||||||
/* execute.c -- implements execute.h */
|
/* execute.c -- implements execute.h */
|
||||||
#include "execute.h"
|
#include "execute.h"
|
||||||
|
|
||||||
|
#define CLRMSG 0 /* space clears the message line with no insert */
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -9,6 +11,7 @@
|
|||||||
#include "random.h"
|
#include "random.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
|
#include "input.h"
|
||||||
#include "mlout.h"
|
#include "mlout.h"
|
||||||
#include "search.h"
|
#include "search.h"
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
@ -301,4 +304,147 @@ int execute( int c, int f, int n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void kbd_loop( void) {
|
||||||
|
int c = -1 ; /* command character */
|
||||||
|
|
||||||
|
/* Setup to process commands. */
|
||||||
|
lastflag = 0 ; /* Fake last flags. */
|
||||||
|
|
||||||
|
for( ;;) {
|
||||||
|
int saveflag ; /* temp store for lastflag */
|
||||||
|
int basec ; /* c stripped of meta character */
|
||||||
|
int f ; /* default flag */
|
||||||
|
int n ; /* numeric repeat count */
|
||||||
|
int mflag ; /* negative flag on repeat */
|
||||||
|
|
||||||
|
/* Execute the "command" macro...normally null. */
|
||||||
|
saveflag = lastflag ; /* Preserve lastflag through this. */
|
||||||
|
execute( META | SPEC | 'C', FALSE, 1) ;
|
||||||
|
lastflag = saveflag ;
|
||||||
|
|
||||||
|
#if TYPEAH && PKCODE
|
||||||
|
if( typahead()) {
|
||||||
|
int newc ;
|
||||||
|
|
||||||
|
newc = getcmd() ;
|
||||||
|
update( FALSE) ;
|
||||||
|
do {
|
||||||
|
fn_t execfunc ;
|
||||||
|
|
||||||
|
if( c == newc
|
||||||
|
&& (execfunc = getbind( c)) != NULL
|
||||||
|
&& execfunc != insert_newline
|
||||||
|
&& execfunc != insert_tab)
|
||||||
|
newc = getcmd() ;
|
||||||
|
else
|
||||||
|
break ;
|
||||||
|
} while( typahead()) ;
|
||||||
|
c = newc ;
|
||||||
|
} else {
|
||||||
|
update( FALSE) ;
|
||||||
|
c = getcmd() ;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* Fix up the screen */
|
||||||
|
update( FALSE) ;
|
||||||
|
|
||||||
|
/* get the next command from the keyboard */
|
||||||
|
c = getcmd() ;
|
||||||
|
#endif
|
||||||
|
/* if there is something on the command line, clear it */
|
||||||
|
if( mpresf != FALSE) {
|
||||||
|
mloutstr( "") ;
|
||||||
|
update( FALSE) ;
|
||||||
|
#if CLRMSG
|
||||||
|
if( c == ' ') /* ITS EMACS does this */
|
||||||
|
continue ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
f = FALSE ;
|
||||||
|
n = 1 ;
|
||||||
|
|
||||||
|
/* do META-# processing if needed */
|
||||||
|
|
||||||
|
if( (c & META)
|
||||||
|
&& (((basec = c & ~META) >= '0' && basec <= '9') || basec == '-')) {
|
||||||
|
f = TRUE ; /* there is a # arg */
|
||||||
|
n = 0 ; /* start with a zero default */
|
||||||
|
mflag = 1 ; /* current minus flag */
|
||||||
|
c = basec ; /* strip the META */
|
||||||
|
do {
|
||||||
|
if( c == '-') {
|
||||||
|
/* already hit a minus or digit? */
|
||||||
|
if( (mflag == -1) || (n != 0))
|
||||||
|
break ;
|
||||||
|
|
||||||
|
mflag = -1 ;
|
||||||
|
} else
|
||||||
|
n = n * 10 + (c - '0') ;
|
||||||
|
|
||||||
|
if( (n == 0) && (mflag == -1)) /* lonely - */
|
||||||
|
mloutstr( "Arg:") ;
|
||||||
|
else
|
||||||
|
mloutfmt( "Arg: %d", n * mflag) ;
|
||||||
|
|
||||||
|
c = getcmd() ; /* get the next key */
|
||||||
|
} while( (c >= '0' && c <= '9') || (c == '-')) ;
|
||||||
|
|
||||||
|
n = n * mflag ; /* figure in the sign */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* do ^U repeat argument processing */
|
||||||
|
|
||||||
|
if( c == reptc) { /* ^U, start argument */
|
||||||
|
f = TRUE ;
|
||||||
|
n = 4 ; /* with argument of 4 */
|
||||||
|
mflag = 0 ; /* that can be discarded. */
|
||||||
|
mloutstr( "Arg: 4") ;
|
||||||
|
while( ((c = getcmd()) >= '0' && c <= '9') || c == reptc
|
||||||
|
|| c == '-') {
|
||||||
|
if( c == reptc)
|
||||||
|
if( (n > 0) == ((n * 4) > 0))
|
||||||
|
n = n * 4 ;
|
||||||
|
else
|
||||||
|
n = 1 ;
|
||||||
|
/*
|
||||||
|
* If dash, and start of argument string, set arg.
|
||||||
|
* to -1. Otherwise, insert it.
|
||||||
|
*/
|
||||||
|
else if( c == '-') {
|
||||||
|
if( mflag)
|
||||||
|
break ;
|
||||||
|
|
||||||
|
n = 0 ;
|
||||||
|
mflag = -1 ;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* If first digit entered, replace previous argument
|
||||||
|
* with digit and set sign. Otherwise, append to arg.
|
||||||
|
*/
|
||||||
|
else {
|
||||||
|
if( !mflag) {
|
||||||
|
n = 0 ;
|
||||||
|
mflag = 1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = 10 * n + c - '0' ;
|
||||||
|
}
|
||||||
|
|
||||||
|
mloutfmt( "Arg: %d", (mflag >= 0) ? n : (n ? -n : -1)) ;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Make arguments preceded by a minus sign negative and change
|
||||||
|
* the special argument "^U -" to an effective "^U -1".
|
||||||
|
*/
|
||||||
|
if( mflag == -1)
|
||||||
|
n = n ? -n : -1 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* and execute the command */
|
||||||
|
execute( c, f, n) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* end of execute.c */
|
/* end of execute.c */
|
||||||
|
@ -2,4 +2,4 @@ extern int gasave ; /* global ASAVE size */
|
|||||||
extern int gacount ; /* count until next ASAVE */
|
extern int gacount ; /* count until next ASAVE */
|
||||||
|
|
||||||
int execute( int c, int f, int n) ;
|
int execute( int c, int f, int n) ;
|
||||||
|
void kbd_loop( void) ;
|
||||||
|
137
main.c
137
main.c
@ -1,7 +1,5 @@
|
|||||||
/* main.c -- */
|
/* main.c -- */
|
||||||
|
|
||||||
#define CLRMSG 0 /* space clears the message line with no insert */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* main.c
|
* main.c
|
||||||
*
|
*
|
||||||
@ -84,7 +82,6 @@
|
|||||||
#include "eval.h"
|
#include "eval.h"
|
||||||
#include "execute.h"
|
#include "execute.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "input.h"
|
|
||||||
#include "lock.h"
|
#include "lock.h"
|
||||||
#include "mlout.h"
|
#include "mlout.h"
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
@ -142,28 +139,21 @@ static void usage( void) {
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c = -1; /* command character */
|
|
||||||
int f; /* default flag */
|
|
||||||
int n; /* numeric repeat count */
|
|
||||||
int mflag; /* negative flag on repeat */
|
|
||||||
struct buffer *bp; /* temp buffer pointer */
|
struct buffer *bp; /* temp buffer pointer */
|
||||||
int firstfile; /* first file flag */
|
int firstfile; /* first file flag */
|
||||||
int carg; /* current arg to scan */
|
int carg; /* current arg to scan */
|
||||||
int startflag; /* startup executed flag */
|
int startflag; /* startup executed flag */
|
||||||
struct buffer *firstbp = NULL; /* ptr to first buffer in cmd line */
|
struct buffer *firstbp = NULL; /* ptr to first buffer in cmd line */
|
||||||
int basec; /* c stripped of meta character */
|
|
||||||
int viewflag; /* are we starting in view mode? */
|
int viewflag; /* are we starting in view mode? */
|
||||||
int gotoflag; /* do we need to goto a line at start? */
|
int gotoflag; /* do we need to goto a line at start? */
|
||||||
int gline = 0; /* if so, what line? */
|
int gline = 0; /* if so, what line? */
|
||||||
int searchflag; /* Do we need to search at start? */
|
int searchflag; /* Do we need to search at start? */
|
||||||
int saveflag; /* temp store for lastflag */
|
|
||||||
int errflag; /* C error processing? */
|
int errflag; /* C error processing? */
|
||||||
bname_t bname ; /* buffer name of file to read */
|
bname_t bname ; /* buffer name of file to read */
|
||||||
#if CRYPT
|
#if CRYPT
|
||||||
int cryptflag; /* encrypting on the way in? */
|
int cryptflag; /* encrypting on the way in? */
|
||||||
ekey_t ekey ; /* startup encryption key */
|
ekey_t ekey ; /* startup encryption key */
|
||||||
#endif
|
#endif
|
||||||
int newc;
|
|
||||||
|
|
||||||
#if PKCODE & VMS
|
#if PKCODE & VMS
|
||||||
(void) umask(-1); /* Use old protection (this is at wrong place). */
|
(void) umask(-1); /* Use old protection (this is at wrong place). */
|
||||||
@ -367,133 +357,10 @@ int main(int argc, char **argv)
|
|||||||
if( forwhunt( FALSE, 0))
|
if( forwhunt( FALSE, 0))
|
||||||
mloutfmt( "Found on line %d", getcline()) ;
|
mloutfmt( "Found on line %d", getcline()) ;
|
||||||
|
|
||||||
/* Setup to process commands. */
|
kbd_loop() ;
|
||||||
lastflag = 0; /* Fake last flags. */
|
|
||||||
|
|
||||||
loop:
|
|
||||||
/* Execute the "command" macro...normally null. */
|
|
||||||
saveflag = lastflag; /* Preserve lastflag through this. */
|
|
||||||
execute(META | SPEC | 'C', FALSE, 1);
|
|
||||||
lastflag = saveflag;
|
|
||||||
|
|
||||||
#if TYPEAH && PKCODE
|
|
||||||
if (typahead()) {
|
|
||||||
newc = getcmd();
|
|
||||||
update(FALSE);
|
|
||||||
do {
|
|
||||||
fn_t execfunc;
|
|
||||||
|
|
||||||
if (c == newc && (execfunc = getbind(c)) != NULL
|
|
||||||
&& execfunc != insert_newline
|
|
||||||
&& execfunc != insert_tab)
|
|
||||||
newc = getcmd();
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
} while (typahead());
|
|
||||||
c = newc;
|
|
||||||
} else {
|
|
||||||
update(FALSE);
|
|
||||||
c = getcmd();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
/* Fix up the screen */
|
|
||||||
update(FALSE);
|
|
||||||
|
|
||||||
/* get the next command from the keyboard */
|
|
||||||
c = getcmd();
|
|
||||||
#endif
|
|
||||||
/* if there is something on the command line, clear it */
|
|
||||||
if (mpresf != FALSE) {
|
|
||||||
mloutstr( "") ;
|
|
||||||
update(FALSE);
|
|
||||||
#if CLRMSG
|
|
||||||
if (c == ' ') /* ITS EMACS does this */
|
|
||||||
goto loop;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
f = FALSE;
|
|
||||||
n = 1;
|
|
||||||
|
|
||||||
/* do META-# processing if needed */
|
|
||||||
|
|
||||||
basec = c & ~META; /* strip meta char off if there */
|
|
||||||
if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) {
|
|
||||||
f = TRUE; /* there is a # arg */
|
|
||||||
n = 0; /* start with a zero default */
|
|
||||||
mflag = 1; /* current minus flag */
|
|
||||||
c = basec; /* strip the META */
|
|
||||||
while ((c >= '0' && c <= '9') || (c == '-')) {
|
|
||||||
if (c == '-') {
|
|
||||||
/* already hit a minus or digit? */
|
|
||||||
if ((mflag == -1) || (n != 0))
|
|
||||||
break;
|
|
||||||
mflag = -1;
|
|
||||||
} else {
|
|
||||||
n = n * 10 + (c - '0');
|
|
||||||
}
|
|
||||||
if ((n == 0) && (mflag == -1)) /* lonely - */
|
|
||||||
mloutstr( "Arg:") ;
|
|
||||||
else
|
|
||||||
mloutfmt( "Arg: %d", n * mflag) ;
|
|
||||||
|
|
||||||
c = getcmd(); /* get the next key */
|
|
||||||
}
|
|
||||||
n = n * mflag; /* figure in the sign */
|
|
||||||
}
|
|
||||||
|
|
||||||
/* do ^U repeat argument processing */
|
|
||||||
|
|
||||||
if (c == reptc) { /* ^U, start argument */
|
|
||||||
f = TRUE;
|
|
||||||
n = 4; /* with argument of 4 */
|
|
||||||
mflag = 0; /* that can be discarded. */
|
|
||||||
mloutstr( "Arg: 4") ;
|
|
||||||
while (((c = getcmd()) >= '0' && c <= '9') || c == reptc
|
|
||||||
|| c == '-') {
|
|
||||||
if (c == reptc)
|
|
||||||
if ((n > 0) == ((n * 4) > 0))
|
|
||||||
n = n * 4;
|
|
||||||
else
|
|
||||||
n = 1;
|
|
||||||
/*
|
|
||||||
* If dash, and start of argument string, set arg.
|
|
||||||
* to -1. Otherwise, insert it.
|
|
||||||
*/
|
|
||||||
else if (c == '-') {
|
|
||||||
if (mflag)
|
|
||||||
break;
|
|
||||||
n = 0;
|
|
||||||
mflag = -1;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* If first digit entered, replace previous argument
|
|
||||||
* with digit and set sign. Otherwise, append to arg.
|
|
||||||
*/
|
|
||||||
else {
|
|
||||||
if (!mflag) {
|
|
||||||
n = 0;
|
|
||||||
mflag = 1;
|
|
||||||
}
|
|
||||||
n = 10 * n + c - '0';
|
|
||||||
}
|
|
||||||
mloutfmt( "Arg: %d", (mflag >= 0) ? n : (n ? -n : -1)) ;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* Make arguments preceded by a minus sign negative and change
|
|
||||||
* the special argument "^U -" to an effective "^U -1".
|
|
||||||
*/
|
|
||||||
if (mflag == -1) {
|
|
||||||
if (n == 0)
|
|
||||||
n++;
|
|
||||||
n = -n;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* and execute the command */
|
|
||||||
execute(c, f, n);
|
|
||||||
goto loop;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize all of the buffers and windows. The buffer name is passed down
|
* Initialize all of the buffers and windows. The buffer name is passed down
|
||||||
* as an argument, because the main routine may have been told to read in a
|
* as an argument, because the main routine may have been told to read in a
|
||||||
|
Loading…
Reference in New Issue
Block a user