mirror of
https://github.com/rfivet/uemacs.git
synced 2025-11-23 11:41:15 -05:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9669fea1ce | |||
| 645a0d734b | |||
| 8c968322f6 | |||
| 3af4ee19a2 | |||
| a0ea6d07e6 | |||
| 187b0ce4a3 | |||
| 910e6576b5 | |||
| f781d458aa | |||
| 7188773d13 | |||
| 5c6aac1ae9 | |||
| ee667b25ed | |||
| 14ef4f50ab | |||
| 663fc2e554 | |||
| 775b16c7b1 | |||
| a42c60045d | |||
| 998559464b | |||
| 15e5796426 | |||
| 3436443807 | |||
| 8dfa92ba44 | |||
| c390cf2a3e | |||
| 3e27fcf19e | |||
| 893658b3ef | |||
| c378a80204 | |||
| e3d7efda7f | |||
| 8aeb526a2a | |||
| 83b4028c95 | |||
| 9b1c5f48a2 | |||
| c1ebad4808 | |||
| e5e2ca0636 | |||
| 4feb70b484 |
114
Makefile
114
Makefile
@@ -1,8 +1,8 @@
|
||||
# Makefile for emacs, updated Fri, Feb 13, 2015 12:02:52 PM
|
||||
|
||||
SRC=basic.c bind.c bindable.c buffer.c crypt.c display.c ebind.c eval.c exec.c execute.c file.c fileio.c flook.c input.c isearch.c line.c lock.c main.c mingw32.c mlout.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c window.c word.c wrapper.c wscreen.c
|
||||
OBJ=basic.o bind.o bindable.o buffer.o crypt.o display.o ebind.o eval.o exec.o execute.o file.o fileio.o flook.o input.o isearch.o line.o lock.o main.o mingw32.o mlout.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o window.o word.o wrapper.o wscreen.o
|
||||
HDR=basic.h bind.h bindable.h buffer.h crypt.h defines.h display.h ebind.h estruct.h eval.h exec.h execute.h file.h fileio.h flook.h input.h isearch.h line.h lock.h mlout.h names.h pklock.h random.h region.h retcode.h search.h spawn.h terminal.h termio.h utf8.h version.h window.h word.h wrapper.h wscreen.h
|
||||
SRC=basic.c bind.c bindable.c buffer.c display.c ebind.c eval.c exec.c execute.c file.c fileio.c flook.c input.c isearch.c line.c lock.c main.c mingw32.c mlout.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c window.c word.c wrapper.c wscreen.c
|
||||
OBJ=basic.o bind.o bindable.o buffer.o display.o ebind.o eval.o exec.o execute.o file.o fileio.o flook.o input.o isearch.o line.o lock.o main.o mingw32.o mlout.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o window.o word.o wrapper.o wscreen.o
|
||||
HDR=basic.h bind.h bindable.h buffer.h defines.h display.h ebind.h estruct.h eval.h exec.h execute.h file.h fileio.h flook.h input.h isearch.h line.h lock.h mlout.h names.h pklock.h random.h region.h retcode.h search.h spawn.h terminal.h termio.h utf8.h version.h window.h word.h wrapper.h wscreen.h
|
||||
|
||||
# DO NOT ADD OR MODIFY ANY LINES ABOVE THIS -- make source creates them
|
||||
|
||||
@@ -26,7 +26,7 @@ uname_S := $(shell sh -c 'echo $(uname_S) | sed s/_.*$$//')
|
||||
PROGRAM=ue
|
||||
|
||||
CC=gcc
|
||||
WARNINGS=-Wall -Wextra -Wstrict-prototypes -Wno-unused-parameter
|
||||
WARNINGS=-pedantic -Wall -Wextra -Wstrict-prototypes -Wno-unused-parameter
|
||||
CFLAGS=-O2 $(WARNINGS)
|
||||
#CC=c89 +O3 # HP
|
||||
#CFLAGS= -D_HPUX_SOURCE -DSYSV
|
||||
@@ -43,7 +43,7 @@ ifeq ($(uname_S),Darwin)
|
||||
DEFINES=-DAUTOCONF -DPOSIX -DSYSV -D_DARWIN_C_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600
|
||||
endif
|
||||
ifeq ($(uname_S),CYGWIN)
|
||||
DEFINES=-DAUTOCONF -DCYGWIN -DPOSIX -DSYSV -DPROGRAM=$(PROGRAM)
|
||||
DEFINES=-DAUTOCONF -DCYGWIN -DSYSV -DPROGRAM=$(PROGRAM)
|
||||
LIBS=-lcurses
|
||||
endif
|
||||
ifeq ($(uname_S),MINGW32)
|
||||
@@ -129,73 +129,71 @@ depend: ${SRC}
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend uses it
|
||||
|
||||
basic.o: basic.c basic.h buffer.h crypt.h line.h retcode.h utf8.h \
|
||||
estruct.h input.h bind.h mlout.h random.h terminal.h defines.h window.h
|
||||
bind.o: bind.c bind.h estruct.h bindable.h buffer.h crypt.h line.h \
|
||||
retcode.h utf8.h display.h ebind.h exec.h file.h flook.h input.h names.h \
|
||||
window.h defines.h
|
||||
bindable.o: bindable.c bindable.h defines.h buffer.h crypt.h line.h \
|
||||
retcode.h utf8.h display.h estruct.h file.h input.h bind.h lock.h \
|
||||
mlout.h terminal.h
|
||||
buffer.o: buffer.c buffer.h crypt.h line.h retcode.h utf8.h defines.h \
|
||||
estruct.h file.h input.h bind.h mlout.h window.h
|
||||
crypt.o: crypt.c crypt.h
|
||||
display.o: display.c display.h estruct.h buffer.h crypt.h line.h \
|
||||
retcode.h utf8.h input.h bind.h termio.h terminal.h defines.h version.h \
|
||||
wrapper.h window.h
|
||||
ebind.o: ebind.c ebind.h basic.h bind.h estruct.h bindable.h buffer.h \
|
||||
crypt.h line.h retcode.h utf8.h eval.h exec.h file.h isearch.h random.h \
|
||||
region.h search.h spawn.h window.h defines.h word.h
|
||||
eval.o: eval.c eval.h basic.h bind.h buffer.h crypt.h line.h retcode.h \
|
||||
utf8.h display.h estruct.h exec.h execute.h flook.h input.h random.h \
|
||||
search.h terminal.h defines.h termio.h version.h window.h
|
||||
exec.o: exec.c exec.h retcode.h buffer.h crypt.h line.h utf8.h bind.h \
|
||||
display.h estruct.h eval.h file.h flook.h input.h random.h window.h \
|
||||
basic.o: basic.c basic.h buffer.h line.h retcode.h utf8.h estruct.h \
|
||||
input.h bind.h mlout.h random.h terminal.h defines.h window.h
|
||||
bind.o: bind.c bind.h estruct.h bindable.h buffer.h line.h retcode.h \
|
||||
utf8.h display.h ebind.h exec.h file.h flook.h input.h names.h window.h \
|
||||
defines.h
|
||||
execute.o: execute.c execute.h estruct.h bind.h random.h display.h file.h \
|
||||
buffer.h crypt.h line.h retcode.h utf8.h mlout.h window.h defines.h
|
||||
file.o: file.c file.h buffer.h crypt.h line.h retcode.h utf8.h defines.h \
|
||||
estruct.h execute.h fileio.h input.h bind.h lock.h mlout.h window.h
|
||||
fileio.o: fileio.c fileio.h crypt.h retcode.h defines.h utf8.h
|
||||
flook.o: flook.c flook.h retcode.h defines.h fileio.h crypt.h
|
||||
bindable.o: bindable.c bindable.h defines.h buffer.h line.h retcode.h \
|
||||
utf8.h display.h estruct.h file.h input.h bind.h lock.h mlout.h \
|
||||
terminal.h
|
||||
buffer.o: buffer.c buffer.h line.h retcode.h utf8.h defines.h estruct.h \
|
||||
file.h input.h bind.h mlout.h window.h
|
||||
display.o: display.c display.h estruct.h buffer.h line.h retcode.h utf8.h \
|
||||
input.h bind.h termio.h terminal.h defines.h version.h wrapper.h \
|
||||
window.h
|
||||
ebind.o: ebind.c ebind.h basic.h bind.h estruct.h bindable.h buffer.h \
|
||||
line.h retcode.h utf8.h eval.h exec.h file.h isearch.h random.h region.h \
|
||||
search.h spawn.h window.h defines.h word.h
|
||||
eval.o: eval.c eval.h basic.h bind.h buffer.h line.h retcode.h utf8.h \
|
||||
display.h estruct.h exec.h execute.h flook.h input.h random.h search.h \
|
||||
terminal.h defines.h termio.h version.h window.h
|
||||
exec.o: exec.c exec.h retcode.h buffer.h line.h utf8.h bind.h display.h \
|
||||
estruct.h eval.h file.h flook.h input.h random.h window.h defines.h
|
||||
execute.o: execute.c execute.h estruct.h bind.h random.h retcode.h \
|
||||
display.h file.h buffer.h line.h utf8.h input.h mlout.h search.h \
|
||||
terminal.h defines.h window.h
|
||||
file.o: file.c file.h buffer.h line.h retcode.h utf8.h defines.h \
|
||||
display.h estruct.h execute.h fileio.h input.h bind.h lock.h mlout.h \
|
||||
window.h
|
||||
fileio.o: fileio.c fileio.h defines.h retcode.h utf8.h
|
||||
flook.o: flook.c flook.h retcode.h defines.h fileio.h
|
||||
input.o: input.c input.h bind.h estruct.h bindable.h display.h exec.h \
|
||||
retcode.h names.h terminal.h defines.h utf8.h wrapper.h
|
||||
isearch.o: isearch.c isearch.h basic.h buffer.h crypt.h line.h retcode.h \
|
||||
utf8.h display.h estruct.h exec.h input.h bind.h search.h terminal.h \
|
||||
defines.h window.h
|
||||
line.o: line.c line.h retcode.h utf8.h buffer.h crypt.h estruct.h mlout.h \
|
||||
isearch.o: isearch.c isearch.h basic.h buffer.h line.h retcode.h utf8.h \
|
||||
display.h estruct.h exec.h input.h bind.h search.h terminal.h defines.h \
|
||||
window.h
|
||||
line.o: line.c line.h retcode.h utf8.h buffer.h estruct.h mlout.h \
|
||||
window.h defines.h
|
||||
lock.o: lock.c estruct.h lock.h
|
||||
main.o: main.c estruct.h basic.h bind.h bindable.h buffer.h crypt.h \
|
||||
line.h retcode.h utf8.h display.h eval.h execute.h file.h input.h lock.h \
|
||||
mlout.h random.h search.h terminal.h defines.h termio.h version.h \
|
||||
window.h
|
||||
main.o: main.c estruct.h basic.h bind.h bindable.h buffer.h line.h \
|
||||
retcode.h utf8.h display.h eval.h execute.h file.h lock.h mlout.h \
|
||||
random.h search.h terminal.h defines.h termio.h version.h window.h
|
||||
mingw32.o: mingw32.c
|
||||
mlout.o: mlout.c mlout.h
|
||||
names.o: names.c names.h basic.h bind.h bindable.h buffer.h crypt.h \
|
||||
line.h retcode.h utf8.h display.h estruct.h eval.h exec.h file.h \
|
||||
isearch.h region.h random.h search.h spawn.h window.h defines.h word.h
|
||||
names.o: names.c names.h basic.h bind.h bindable.h buffer.h line.h \
|
||||
retcode.h utf8.h display.h estruct.h eval.h exec.h file.h isearch.h \
|
||||
region.h random.h search.h spawn.h window.h defines.h word.h
|
||||
pklock.o: pklock.c estruct.h pklock.h
|
||||
posix.o: posix.c termio.h estruct.h retcode.h utf8.h
|
||||
random.o: random.c random.h basic.h buffer.h crypt.h line.h retcode.h \
|
||||
utf8.h display.h estruct.h execute.h input.h bind.h search.h terminal.h \
|
||||
posix.o: posix.c
|
||||
random.o: random.c random.h retcode.h basic.h buffer.h line.h utf8.h \
|
||||
display.h estruct.h execute.h input.h bind.h search.h terminal.h \
|
||||
defines.h window.h
|
||||
region.o: region.c region.h line.h retcode.h utf8.h buffer.h crypt.h \
|
||||
estruct.h mlout.h random.h window.h defines.h
|
||||
region.o: region.c region.h line.h retcode.h utf8.h buffer.h estruct.h \
|
||||
mlout.h random.h window.h defines.h
|
||||
search.o: search.c search.h line.h retcode.h utf8.h basic.h buffer.h \
|
||||
crypt.h display.h estruct.h input.h bind.h mlout.h terminal.h defines.h \
|
||||
display.h estruct.h input.h bind.h mlout.h terminal.h defines.h window.h
|
||||
spawn.o: spawn.c spawn.h defines.h buffer.h line.h retcode.h utf8.h \
|
||||
display.h estruct.h exec.h file.h flook.h input.h bind.h terminal.h \
|
||||
window.h
|
||||
spawn.o: spawn.c spawn.h defines.h buffer.h crypt.h line.h retcode.h \
|
||||
utf8.h display.h estruct.h exec.h file.h flook.h input.h bind.h \
|
||||
terminal.h window.h
|
||||
tcap.o: tcap.c terminal.h defines.h retcode.h display.h estruct.h \
|
||||
termio.h
|
||||
termio.o: termio.c
|
||||
termio.o: termio.c termio.h estruct.h retcode.h utf8.h
|
||||
utf8.o: utf8.c utf8.h
|
||||
window.o: window.c window.h defines.h buffer.h crypt.h line.h retcode.h \
|
||||
utf8.h basic.h display.h estruct.h execute.h terminal.h wrapper.h
|
||||
word.o: word.c word.h basic.h buffer.h crypt.h line.h retcode.h utf8.h \
|
||||
estruct.h mlout.h random.h region.h window.h defines.h
|
||||
window.o: window.c window.h defines.h buffer.h line.h retcode.h utf8.h \
|
||||
basic.h display.h estruct.h execute.h terminal.h wrapper.h
|
||||
word.o: word.c word.h basic.h buffer.h line.h retcode.h utf8.h estruct.h \
|
||||
mlout.h random.h region.h window.h defines.h
|
||||
wrapper.o: wrapper.c wrapper.h
|
||||
wscreen.o: wscreen.c wscreen.h
|
||||
|
||||
|
||||
9
basic.c
9
basic.c
@@ -51,13 +51,14 @@ static unsigned getgoal( struct line *dlp) {
|
||||
|
||||
/* Take tabs, ^X and \xx hex characters into account */
|
||||
if( c == '\t')
|
||||
col |= tabmask ;
|
||||
col += tabwidth - col % tabwidth ;
|
||||
else if( c < 0x20 || c == 0x7F)
|
||||
col += 1 ;
|
||||
else if( c >= 0x80 && c <= 0xA0)
|
||||
col += 2 ;
|
||||
else if( c >= 0x80 && c <= 0xA0)
|
||||
col += 3 ;
|
||||
else
|
||||
col += 1 ;
|
||||
|
||||
col += 1 ;
|
||||
if( col > curgoal)
|
||||
break ;
|
||||
|
||||
|
||||
17
bind.c
17
bind.c
@@ -44,7 +44,6 @@ int help(int f, int n)
|
||||
{ /* give me some help!!!!
|
||||
bring up a fake buffer and read the help file
|
||||
into it with view mode */
|
||||
struct window *wp; /* scaning pointer to windows */
|
||||
struct buffer *bp; /* buffer pointer to help */
|
||||
char *fname = NULL; /* ptr to file returned by flook() */
|
||||
|
||||
@@ -73,11 +72,7 @@ int help(int f, int n)
|
||||
/* make this window in VIEW mode, update all mode lines */
|
||||
curwp->w_bufp->b_mode |= MDVIEW;
|
||||
curwp->w_bufp->b_flag |= BFINVS;
|
||||
wp = wheadp;
|
||||
while (wp != NULL) {
|
||||
wp->w_flag |= WFMODE;
|
||||
wp = wp->w_wndp;
|
||||
}
|
||||
upmode() ;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -387,15 +382,11 @@ static int buildlist( char *mstring) {
|
||||
}
|
||||
}
|
||||
|
||||
curwp->w_bufp->b_mode |= MDVIEW; /* put this buffer view mode */
|
||||
curbp->b_flag &= ~BFCHG; /* don't flag this as a change */
|
||||
bp->b_mode |= MDVIEW; /* put this buffer view mode */
|
||||
bp->b_flag &= ~BFCHG; /* don't flag this as a change */
|
||||
wp->w_dotp = lforw(bp->b_linep); /* back to the beginning */
|
||||
wp->w_doto = 0;
|
||||
wp = wheadp; /* and update ALL mode lines */
|
||||
while (wp != NULL) {
|
||||
wp->w_flag |= WFMODE;
|
||||
wp = wp->w_wndp;
|
||||
}
|
||||
upmode() ; /* and update ALL mode lines */
|
||||
mlwrite(""); /* clear the mode line */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
109
buffer.c
109
buffer.c
@@ -29,19 +29,14 @@ struct buffer *bheadp ; /* Head of list of buffers */
|
||||
struct buffer *blistp ; /* Buffer for C-X C-B */
|
||||
|
||||
const char *modename[] = { /* name of modes */
|
||||
"Wrap", "Cmode", "Spell", "Exact", "View", "Over",
|
||||
"Wrap", "Cmode", "Exact", "View", "Over",
|
||||
"Magic",
|
||||
#if CRYPT
|
||||
"Crypt",
|
||||
#else
|
||||
"",
|
||||
#endif
|
||||
"Asave", "Utf-8", "Dos"
|
||||
} ;
|
||||
|
||||
int gmode = 0 ; /* global editor mode */
|
||||
|
||||
static const char modecode[] = "WCSEVOMYAUD" ; /* letters to represent modes */
|
||||
static const char modecode[] = "WCEVOMAUD" ; /* letters to represent modes */
|
||||
|
||||
|
||||
static int makelist( int iflag) ;
|
||||
@@ -254,7 +249,9 @@ ask:
|
||||
bp = bp->b_bufp ; /* onward */
|
||||
}
|
||||
|
||||
strcpy( curbp->b_bname, bufn) ; /* copy buffer name to structure */
|
||||
/* copy buffer name to structure */
|
||||
strncpy( curbp->b_bname, bufn, sizeof( bname_t) - 1) ;
|
||||
curbp->b_bname[ sizeof( bname_t) - 1] = '\0' ;
|
||||
free( bufn) ;
|
||||
|
||||
curwp->w_flag |= WFMODE ; /* make mode line replot */
|
||||
@@ -319,7 +316,12 @@ int listbuffers(int f, int n)
|
||||
*
|
||||
* int iflag; list hidden buffer flag
|
||||
*/
|
||||
#define MAXLINE MAXCOL
|
||||
/* Layout: "ACT MODES Size Buffer File"
|
||||
AAA MMMMMMMMMSSSSSSSSSS BBBBBBBBBBBBBBB FFF...
|
||||
FNAMSTART ---------------------------------------^
|
||||
*/
|
||||
#define FNAMSTART (3 + 1 + NUMMODES + 10 + 1 + (sizeof( bname_t) - 1) + 1)
|
||||
|
||||
static int makelist( int iflag)
|
||||
{
|
||||
char *cp1;
|
||||
@@ -331,24 +333,21 @@ static int makelist( int iflag)
|
||||
int i;
|
||||
long nbytes; /* # of bytes in current buffer */
|
||||
long nlines ; /* # of lines in current buffer */
|
||||
char b[ 8 + 1] ;
|
||||
char line[MAXLINE];
|
||||
char line[ FNAMSTART + sizeof( fname_t)] ;
|
||||
|
||||
blistp->b_flag &= ~BFCHG; /* Don't complain! */
|
||||
if ((s = bclear(blistp)) != TRUE) /* Blow old text away */
|
||||
return s;
|
||||
strcpy(blistp->b_fname, "");
|
||||
|
||||
blistp->b_fname[ 0] = 0 ;
|
||||
|
||||
if( addline("ACT MODES Size Buffer File") == FALSE
|
||||
|| addline("‾‾‾ ‾‾‾‾‾ ‾‾‾‾ ‾‾‾‾‾‾ ‾‾‾‾") == FALSE)
|
||||
return FALSE;
|
||||
bp = bheadp; /* For all buffers */
|
||||
|
||||
/* build line to report global mode settings */
|
||||
cp1 = &line[0];
|
||||
*cp1++ = ' ';
|
||||
*cp1++ = ' ';
|
||||
*cp1++ = ' ';
|
||||
*cp1++ = ' ';
|
||||
strcpy( line, " ") ;
|
||||
cp1 = &line[ 4] ;
|
||||
|
||||
/* output the mode codes */
|
||||
for (i = 0; i < NUMMODES; i++)
|
||||
@@ -356,36 +355,27 @@ static int makelist( int iflag)
|
||||
*cp1++ = modecode[i];
|
||||
else
|
||||
*cp1++ = '.';
|
||||
strcpy(cp1, " Global Modes");
|
||||
|
||||
strcpy(cp1, " Global Modes");
|
||||
if (addline(line) == FALSE)
|
||||
return FALSE;
|
||||
|
||||
/* output the list of buffers */
|
||||
while (bp != NULL) {
|
||||
/* skip invisable buffers if iflag is false */
|
||||
if (((bp->b_flag & BFINVS) != 0) && (iflag != TRUE)) {
|
||||
bp = bp->b_bufp;
|
||||
for( bp = bheadp ; bp != NULL ; bp = bp->b_bufp) { /* For all buffers */
|
||||
/* skip invisible buffers if iflag is false */
|
||||
if (((bp->b_flag & BFINVS) != 0) && (iflag != TRUE))
|
||||
continue;
|
||||
}
|
||||
|
||||
cp1 = &line[0]; /* Start at left edge */
|
||||
|
||||
/* output status of ACTIVE flag (has the file been read in? */
|
||||
if (bp->b_active == TRUE) /* "@" if activated */
|
||||
*cp1++ = '@';
|
||||
else
|
||||
*cp1++ = ' ';
|
||||
|
||||
/* output status of changed flag */
|
||||
if ((bp->b_flag & BFCHG) != 0) /* "*" if changed */
|
||||
*cp1++ = '*';
|
||||
else
|
||||
*cp1++ = ' ';
|
||||
/* output status of ACTIVE flag ('@' when the file has been read in) */
|
||||
*cp1++ = (bp->b_active == TRUE) ? '@' : ' ' ;
|
||||
|
||||
/* report if the file is truncated */
|
||||
if ((bp->b_flag & BFTRUNC) != 0)
|
||||
*cp1++ = '#';
|
||||
else
|
||||
*cp1++ = ' ';
|
||||
*cp1++ = ((bp->b_flag & BFTRUNC) != 0) ? '#' : ' ' ;
|
||||
|
||||
/* output status of changed flag ('*' when the buffer is changed) */
|
||||
*cp1++ = ((bp->b_flag & BFCHG) != 0) ? '*' : ' ' ;
|
||||
|
||||
*cp1++ = ' '; /* space */
|
||||
|
||||
@@ -397,8 +387,8 @@ static int makelist( int iflag)
|
||||
*cp1++ = '.';
|
||||
}
|
||||
|
||||
/* No gap as buffer size if left padded with space */
|
||||
|
||||
/* No gap as buffer size is left-padded with space */
|
||||
|
||||
/* Buffer size */
|
||||
nbytes = 0L; /* Count bytes in buf. */
|
||||
nlines = 0 ;
|
||||
@@ -412,30 +402,28 @@ static int makelist( int iflag)
|
||||
if( bp->b_mode & MDDOS)
|
||||
nbytes += nlines ;
|
||||
|
||||
l_to_a( b, sizeof b, nbytes) ; /* 8 digits string buffer size. */
|
||||
cp2 = &b[0];
|
||||
while ((c = *cp2++) != 0)
|
||||
*cp1++ = c;
|
||||
l_to_a( cp1, 10 + 1, nbytes) ; /* "%10d" formatted numbers */
|
||||
cp1 += 10 ;
|
||||
|
||||
*cp1++ = ' '; /* Gap. */
|
||||
cp2 = &bp->b_bname[0]; /* Buffer name */
|
||||
while ((c = *cp2++) != 0)
|
||||
*cp1++ = c;
|
||||
cp2 = &bp->b_fname[0]; /* File name */
|
||||
if (*cp2 != 0) {
|
||||
while( cp1 < &line[ 3 + 1 + NUMMODES + 8 + 1 + (NBUFN-1) + 1])
|
||||
*cp1++ = ' ';
|
||||
while ((c = *cp2++) != 0) {
|
||||
if (cp1 < &line[MAXLINE - 1])
|
||||
*cp1++ = c;
|
||||
}
|
||||
}
|
||||
*cp1 = 0; /* Add to the buffer. */
|
||||
if (addline(line) == FALSE)
|
||||
return FALSE;
|
||||
bp = bp->b_bufp;
|
||||
|
||||
if( bp->b_fname[ 0] != 0) {
|
||||
while( cp1 < &line[ FNAMSTART])
|
||||
*cp1++ = ' ' ;
|
||||
|
||||
strncpy( cp1, bp->b_fname, &line[ sizeof line - 1] - cp1) ;
|
||||
line[ sizeof line - 1] = 0 ;
|
||||
} else
|
||||
*cp1 = 0 ; /* Terminate string */
|
||||
|
||||
if( addline( line) == FALSE) /* Add to the buffer. */
|
||||
return FALSE ;
|
||||
}
|
||||
return TRUE; /* All done */
|
||||
|
||||
return TRUE ; /* All done */
|
||||
}
|
||||
|
||||
static void l_to_a(char *buf, int width, long num)
|
||||
@@ -558,9 +546,6 @@ struct buffer *bfind( const char *bname, int cflag, int bflag)
|
||||
bp->b_fname[ 0] = '\0' ;
|
||||
strncpy( bp->b_bname, bname, sizeof( bname_t) - 1) ;
|
||||
bp->b_bname[ sizeof( bname_t) - 1] = '\0' ;
|
||||
#if CRYPT
|
||||
bp->b_key[0] = 0;
|
||||
#endif
|
||||
lp->l_fp = lp;
|
||||
lp->l_bp = lp;
|
||||
}
|
||||
|
||||
33
buffer.h
33
buffer.h
@@ -1,16 +1,10 @@
|
||||
#ifndef _BUFFER_H_
|
||||
#define _BUFFER_H_
|
||||
|
||||
#include "crypt.h"
|
||||
#include "line.h"
|
||||
|
||||
typedef char fname_t[ 80] ; /* file name type */
|
||||
typedef char bname_t[ 16] ; /* buffer name type */
|
||||
#define NBUFN sizeof( bname_t)
|
||||
|
||||
#if CRYPT
|
||||
typedef char ekey_t[ 128] ; /* encryption key type */
|
||||
#endif
|
||||
typedef char fname_t[ 256] ; /* file name type */
|
||||
typedef char bname_t[ 16] ; /* buffer name type */
|
||||
|
||||
/*
|
||||
* Text is kept in buffers. A buffer header, described below, exists for every
|
||||
@@ -36,9 +30,6 @@ struct buffer {
|
||||
char b_flag; /* Flags */
|
||||
fname_t b_fname ; /* File name */
|
||||
bname_t b_bname ; /* Buffer name */
|
||||
#if CRYPT
|
||||
ekey_t b_key ; /* current encrypted key */
|
||||
#endif
|
||||
};
|
||||
|
||||
extern struct buffer *curbp ; /* Current buffer */
|
||||
@@ -50,21 +41,17 @@ extern struct buffer *blistp ; /* Buffer for C-X C-B */
|
||||
#define BFTRUNC 0x04 /* buffer was truncated when read */
|
||||
|
||||
/* mode flags */
|
||||
#define NUMMODES 11 /* # of defined modes */
|
||||
#define NUMMODES 9 /* # of defined modes */
|
||||
|
||||
#define MDWRAP 0x0001 /* word wrap */
|
||||
#define MDCMOD 0x0002 /* C indentation and fence match */
|
||||
#define MDSPELL 0x0004 /* spell error parcing */
|
||||
#define MDEXACT 0x0008 /* Exact matching for searches */
|
||||
#define MDVIEW 0x0010 /* read-only buffer */
|
||||
#define MDOVER 0x0020 /* overwrite mode */
|
||||
#define MDMAGIC 0x0040 /* regular expresions in search */
|
||||
#if CRYPT
|
||||
#define MDCRYPT 0x0080 /* encrytion mode active */
|
||||
#endif
|
||||
#define MDASAVE 0x0100 /* auto-save mode */
|
||||
#define MDUTF8 0x0200 /* utf8 mode */
|
||||
#define MDDOS 0x0400 /* CRLF eol mode */
|
||||
#define MDEXACT 0x0004 /* Exact matching for searches */
|
||||
#define MDVIEW 0x0008 /* read-only buffer */
|
||||
#define MDOVER 0x0010 /* overwrite mode */
|
||||
#define MDMAGIC 0x0020 /* regular expresions in search */
|
||||
#define MDASAVE 0x0040 /* auto-save mode */
|
||||
#define MDUTF8 0x0080 /* utf8 mode */
|
||||
#define MDDOS 0x0100 /* CRLF eol mode */
|
||||
|
||||
|
||||
extern const char *modename[] ; /* text names of modes */
|
||||
|
||||
190
crypt.c
190
crypt.c
@@ -1,190 +0,0 @@
|
||||
/* crypt.c -- implements crypt.h */
|
||||
|
||||
#include "crypt.h"
|
||||
|
||||
/* CRYPT.C
|
||||
*
|
||||
* Encryption routines
|
||||
*
|
||||
* written by Dana Hoggatt and Daniel Lawrence
|
||||
*/
|
||||
|
||||
#if CRYPT
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
static int mod95(int);
|
||||
|
||||
|
||||
/**********
|
||||
*
|
||||
* myencrypt - in place encryption/decryption of a buffer
|
||||
*
|
||||
* (C) Copyright 1986, Dana L. Hoggatt
|
||||
* 1216, Beck Lane, Lafayette, IN
|
||||
*
|
||||
* When consulting directly with the author of this routine,
|
||||
* please refer to this routine as the "DLH-POLY-86-B CIPHER".
|
||||
*
|
||||
* This routine was written for Dan Lawrence, for use in V3.8 of
|
||||
* MicroEMACS, a public domain text/program editor.
|
||||
*
|
||||
* I kept the following goals in mind when preparing this function:
|
||||
*
|
||||
* 1. All printable characters were to be encrypted back
|
||||
* into the printable range, control characters and
|
||||
* high-bit characters were to remain unaffected. this
|
||||
* way, encrypted would still be just as cheap to
|
||||
* transmit down a 7-bit data path as they were before.
|
||||
*
|
||||
* 2. The encryption had to be portable. The encrypted
|
||||
* file from one computer should be able to be decrypted
|
||||
* on another computer.
|
||||
*
|
||||
* 3. The encryption had to be inexpensive, both in terms
|
||||
* of speed and space.
|
||||
*
|
||||
* 4. The system needed to be secure against all but the
|
||||
* most determined of attackers.
|
||||
*
|
||||
* For encryption of a block of data, one calls myencrypt passing
|
||||
* a pointer to the data block and its length. The data block is
|
||||
* encrypted in place, that is, the encrypted output overwrites
|
||||
* the input. Decryption is totally isomorphic, and is performed
|
||||
* in the same manner by the same routine.
|
||||
*
|
||||
* Before using this routine for encrypting data, you are expected
|
||||
* to specify an encryption key. This key is an arbitrary string,
|
||||
* to be supplied by the user. To set the key takes two calls to
|
||||
* myencrypt(). First, you call
|
||||
*
|
||||
* myencrypt(NULL, vector)
|
||||
*
|
||||
* This resets all internal control information. Typically (and
|
||||
* specifically in the case on MICRO-emacs) you would use a "vector"
|
||||
* of 0. Other values can be used to customize your editor to be
|
||||
* "incompatable" with the normally distributed version. For
|
||||
* this purpose, the best results will be obtained by avoiding
|
||||
* multiples of 95.
|
||||
*
|
||||
* Then, you "encrypt" your password by calling
|
||||
*
|
||||
* myencrypt(pass, strlen(pass))
|
||||
*
|
||||
* where "pass" is your password string. Myencrypt() will destroy
|
||||
* the original copy of the password (it becomes encrypted),
|
||||
* which is good. You do not want someone on a multiuser system
|
||||
* to peruse your memory space and bump into your password.
|
||||
* Still, it is a better idea to erase the password buffer to
|
||||
* defeat memory perusal by a more technical snooper.
|
||||
*
|
||||
* For the interest of cryptologists, at the heart of this
|
||||
* function is a Beaufort Cipher. The cipher alphabet is the
|
||||
* range of printable characters (' ' to '~'), all "control"
|
||||
* and "high-bit" characters are left unaltered.
|
||||
*
|
||||
* The key is a variant autokey, derived from a wieghted sum
|
||||
* of all the previous clear text and cipher text. A counter
|
||||
* is used as salt to obiterate any simple cyclic behavior
|
||||
* from the clear text, and key feedback is used to assure
|
||||
* that the entire message is based on the original key,
|
||||
* preventing attacks on the last part of the message as if
|
||||
* it were a pure autokey system.
|
||||
*
|
||||
* Overall security of encrypted data depends upon three
|
||||
* factors: the fundamental cryptographic system must be
|
||||
* difficult to compromise; exhaustive searching of the key
|
||||
* space must be computationally expensive; keys and plaintext
|
||||
* must remain out of sight. This system satisfies this set
|
||||
* of conditions to within the degree desired for MicroEMACS.
|
||||
*
|
||||
* Though direct methods of attack (against systems such as
|
||||
* this) do exist, they are not well known and will consume
|
||||
* considerable amounts of computing time. An exhaustive
|
||||
* search requires over a billion investigations, on average.
|
||||
*
|
||||
* The choice, entry, storage, manipulation, alteration,
|
||||
* protection and security of the keys themselves are the
|
||||
* responsiblity of the user.
|
||||
*
|
||||
*
|
||||
* char *bptr; buffer of characters to be encrypted
|
||||
* unsigned len; number of characters in the buffer
|
||||
*
|
||||
**********/
|
||||
|
||||
void myencrypt(char *bptr, unsigned len)
|
||||
{
|
||||
int cc; /* current character being considered */
|
||||
|
||||
static long key = 0; /* 29 bit encipherment key */
|
||||
static int salt = 0; /* salt to spice up key with */
|
||||
|
||||
if (!bptr) { /* is there anything here to encrypt? */
|
||||
key = len; /* set the new key */
|
||||
salt = len; /* set the new salt */
|
||||
return;
|
||||
}
|
||||
while (len--) { /* for every character in the buffer */
|
||||
|
||||
cc = *bptr; /* get a character out of the buffer */
|
||||
|
||||
/* only encipher printable characters */
|
||||
if ((cc >= ' ') && (cc <= '~')) {
|
||||
|
||||
/** If the upper bit (bit 29) is set, feed it back into the key. This
|
||||
assures us that the starting key affects the entire message. **/
|
||||
|
||||
key &= 0x1FFFFFFFL; /* strip off overflow */
|
||||
if (key & 0x10000000L) {
|
||||
key ^= 0x0040A001L; /* feedback */
|
||||
}
|
||||
|
||||
/** Down-bias the character, perform a Beaufort encipherment, and
|
||||
up-bias the character again. We want key to be positive
|
||||
so that the left shift here will be more portable and the
|
||||
mod95() faster **/
|
||||
|
||||
cc = mod95((int) (key % 95) - (cc - ' ')) + ' ';
|
||||
|
||||
/** the salt will spice up the key a little bit, helping to obscure
|
||||
any patterns in the clear text, particularly when all the
|
||||
characters (or long sequences of them) are the same. We do
|
||||
not want the salt to go negative, or it will affect the key
|
||||
too radically. It is always a good idea to chop off cyclics
|
||||
to prime values. **/
|
||||
|
||||
if (++salt >= 20857) { /* prime modulus */
|
||||
salt = 0;
|
||||
}
|
||||
|
||||
/** our autokey (a special case of the running key) is being
|
||||
generated by a wieghted checksum of clear text, cipher
|
||||
text, and salt. **/
|
||||
|
||||
key = key + key + cc + *bptr + salt;
|
||||
}
|
||||
*bptr++ = cc; /* put character back into buffer */
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static int mod95(int val)
|
||||
{
|
||||
/* The mathematical MOD does not match the computer MOD */
|
||||
|
||||
/* Yes, what I do here may look strange, but it gets the
|
||||
job done, and portably at that. */
|
||||
|
||||
while (val >= 9500)
|
||||
val -= 9500;
|
||||
while (val >= 950)
|
||||
val -= 950;
|
||||
while (val >= 95)
|
||||
val -= 95;
|
||||
while (val < 0)
|
||||
val += 95;
|
||||
return val;
|
||||
}
|
||||
|
||||
#endif
|
||||
10
crypt.h
10
crypt.h
@@ -1,10 +0,0 @@
|
||||
#ifndef _CRYPT_H_
|
||||
#define _CRYPT_H_
|
||||
|
||||
#define CRYPT 1 /* file encryption enabled? */
|
||||
|
||||
#if CRYPT
|
||||
void myencrypt( char *bptr, unsigned len) ;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
127
display.c
127
display.c
@@ -73,6 +73,8 @@ static int taboff = 0 ; /* tab offset for display */
|
||||
int mpresf = FALSE ; /* TRUE if message in last line */
|
||||
int scrollcount = 1 ; /* number of lines to scroll */
|
||||
int discmd = TRUE ; /* display command flag */
|
||||
int disinp = TRUE ; /* display input characters (echo) */
|
||||
|
||||
|
||||
static int reframe(struct window *wp);
|
||||
static void updone(struct window *wp);
|
||||
@@ -92,10 +94,6 @@ static void mlputs( unsigned char *s) ;
|
||||
static int newscreensize(int h, int w);
|
||||
#endif
|
||||
|
||||
#if RAINBOW
|
||||
static void putline(int row, int col, char *buf);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Initialize the data structures used by the display code. The edge vectors
|
||||
* used to access the screens are set up. The operating system's terminal I/O
|
||||
@@ -214,8 +212,9 @@ static void vtputc(int c)
|
||||
if (c == '\t') {
|
||||
do {
|
||||
vtputc(' ');
|
||||
} while (((vtcol + taboff) & tabmask) != 0);
|
||||
return;
|
||||
} while( ((vtcol + taboff) % tabwidth) != 0) ;
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
if (c < 0x20) {
|
||||
@@ -584,13 +583,13 @@ void updpos(void)
|
||||
|
||||
i += utf8_to_unicode( lp->l_text, i, curwp->w_doto, &c) ;
|
||||
if( c == '\t')
|
||||
curcol |= tabmask ;
|
||||
curcol += tabwidth - curcol % tabwidth ;
|
||||
else if( c < 0x20 || c == 0x7F)
|
||||
curcol += 1 ; /* displayed as ^c */
|
||||
curcol += 2 ; /* displayed as ^c */
|
||||
else if( c >= 0x80 && c <= 0xA0)
|
||||
curcol += 2 ; /* displayed as \xx */
|
||||
|
||||
++curcol;
|
||||
curcol += 3 ; /* displayed as \xx */
|
||||
else
|
||||
curcol += 1 ;
|
||||
}
|
||||
|
||||
/* if extended, flag so and update the virtual line image */
|
||||
@@ -909,8 +908,7 @@ static void updext(void)
|
||||
/*
|
||||
* Update a single line. This does not know how to use insert or delete
|
||||
* character sequences; we are using VT52 functionality. Update the physical
|
||||
* row and column variables. It does try an exploit erase to end of line. The
|
||||
* RAINBOW version of this routine uses fast video.
|
||||
* row and column variables. It does try an exploit erase to end of line.
|
||||
*/
|
||||
#if MEMMAP
|
||||
/* UPDATELINE specific code for the IBM-PC and other compatables */
|
||||
@@ -957,29 +955,6 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
|
||||
*/
|
||||
static int updateline(int row, struct video *vp1, struct video *vp2)
|
||||
{
|
||||
#if RAINBOW
|
||||
/* UPDATELINE specific code for the DEC rainbow 100 micro */
|
||||
|
||||
unicode_t *cp1;
|
||||
unicode_t *cp2;
|
||||
int nch;
|
||||
|
||||
/* since we don't know how to make the rainbow do this, turn it off */
|
||||
flags &= (~VFREV & ~VFREQ);
|
||||
|
||||
cp1 = &vp1->v_text[0]; /* Use fast video. */
|
||||
cp2 = &vp2->v_text[0];
|
||||
putline(row + 1, 1, cp1);
|
||||
nch = term.t_ncol;
|
||||
|
||||
do {
|
||||
*cp2 = *cp1;
|
||||
++cp2;
|
||||
++cp1;
|
||||
}
|
||||
while (--nch);
|
||||
*flags &= ~VFCHG;
|
||||
#else
|
||||
/* UPDATELINE code for all other versions */
|
||||
|
||||
unicode_t *cp1;
|
||||
@@ -1004,20 +979,18 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
|
||||
#endif
|
||||
|
||||
#if REVSTA | COLOR
|
||||
/* if we need to change the reverse video status of the
|
||||
current line, we need to re-write the entire line */
|
||||
/* do a re-write of the entire line if it is reverse or there
|
||||
** is a request to change the reverse status */
|
||||
rev = (vp1->v_flag & VFREV) == VFREV;
|
||||
req = (vp1->v_flag & VFREQ) == VFREQ;
|
||||
if ((rev != req)
|
||||
if( req || (req != rev)
|
||||
#if COLOR
|
||||
|| (vp1->v_fcolor != vp1->v_rfcolor)
|
||||
|| (vp1->v_bcolor != vp1->v_rbcolor)
|
||||
#endif
|
||||
) {
|
||||
movecursor(row, 0); /* Go to start of line. */
|
||||
/* set rev video if needed */
|
||||
if (rev != req)
|
||||
(*term.t_rev) (req);
|
||||
TTrev( req) ; /* set needed rev video state */
|
||||
|
||||
/* scan through the line and dump it to the screen and
|
||||
the virtual screen array */
|
||||
@@ -1027,9 +1000,8 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
|
||||
++ttcol;
|
||||
*cp2++ = *cp1++;
|
||||
}
|
||||
/* turn rev video off */
|
||||
if (rev != req)
|
||||
(*term.t_rev) (FALSE);
|
||||
|
||||
TTrev( FALSE) ; /* turn rev video off */
|
||||
|
||||
/* update the needed flags */
|
||||
vp1->v_flag &= ~VFCHG;
|
||||
@@ -1107,7 +1079,6 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
|
||||
#endif
|
||||
vp1->v_flag &= ~VFCHG; /* flag this line as updated */
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1147,18 +1118,8 @@ static void modeline(struct window *wp)
|
||||
lchar = '-';
|
||||
|
||||
bp = wp->w_bufp;
|
||||
#if PKCODE == 0
|
||||
if ((bp->b_flag & BFTRUNC) != 0)
|
||||
vtputc('#');
|
||||
else
|
||||
#endif
|
||||
vtputc(lchar);
|
||||
|
||||
if ((bp->b_flag & BFCHG) != 0) /* "*" if changed. */
|
||||
vtputc('*');
|
||||
else
|
||||
vtputc(lchar);
|
||||
|
||||
vtputc( ((bp->b_flag & BFTRUNC) != 0) ? '#' : lchar) ; /* truncated? */
|
||||
vtputc( ((bp->b_flag & BFCHG) != 0) ? '*' : lchar) ; /* changed? */
|
||||
vtputc( ' ') ;
|
||||
|
||||
if( n == term.t_nrow - 1)
|
||||
@@ -1330,6 +1291,18 @@ static void mlputc( char c) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* output a string of output characters
|
||||
*
|
||||
* char *s; string to output
|
||||
*/
|
||||
void ostring( char *s) {
|
||||
if( discmd)
|
||||
while( *s)
|
||||
mlputc( *s++ & 0xFF) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Write a message into the message line. Keep track of the physical cursor
|
||||
* position. A small class of printf like format items is handled. Assumes the
|
||||
@@ -1395,6 +1368,8 @@ void vmlwrite( const char *fmt, va_list ap) {
|
||||
break ;
|
||||
|
||||
default:
|
||||
mlputc( '%') ;
|
||||
case '%':
|
||||
mlputc( c) ;
|
||||
}
|
||||
}
|
||||
@@ -1511,18 +1486,6 @@ static void mlputf( int s) {
|
||||
mlputc((f % 10) + '0') ;
|
||||
}
|
||||
|
||||
#if RAINBOW
|
||||
|
||||
static void putline(int row, int col, char *buf)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = strlen(buf);
|
||||
if (col + n - 1 > term.t_ncol)
|
||||
n = term.t_ncol - col + 1;
|
||||
Put_Data(row, col, n, buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Get terminal size from system.
|
||||
Store number of lines into *heightp and width into *widthp.
|
||||
@@ -1582,3 +1545,27 @@ static int newscreensize(int h, int w)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* output a character when echo is enabled
|
||||
*
|
||||
* char c ; character to output
|
||||
*/
|
||||
void echoc( char c) {
|
||||
if( disinp)
|
||||
TTputc( c) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* output a string of characters when display input is enabled
|
||||
*
|
||||
* char *s; string to output
|
||||
*/
|
||||
void echos( char *s) {
|
||||
if( disinp)
|
||||
while( *s)
|
||||
TTputc( *s++) ;
|
||||
}
|
||||
|
||||
|
||||
/* end of display.c */
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
extern int mpresf ; /* Stuff in message line */
|
||||
extern int scrollcount ; /* number of lines to scroll */
|
||||
extern int discmd ; /* display command flag */
|
||||
extern int disinp ; /* display input characters (echo) */
|
||||
extern int gfcolor ; /* global forgrnd color (white) */
|
||||
extern int gbcolor ; /* global backgrnd color (black) */
|
||||
|
||||
@@ -26,6 +27,9 @@ void movecursor( int row, int col) ;
|
||||
void mlerase( void) ;
|
||||
void vmlwrite( const char *fmt, va_list ap) ;
|
||||
void mlwrite( const char *fmt, ...) ;
|
||||
void ostring( char *s) ;
|
||||
void echoc( char c) ;
|
||||
void echos( char *s) ;
|
||||
void getscreensize( int *widthp, int *heightp) ;
|
||||
|
||||
#if UNIX
|
||||
|
||||
4
ebind.c
4
ebind.c
@@ -270,10 +270,6 @@ struct key_tab keytab[NBINDS] = {
|
||||
,
|
||||
{META | 'D', delfword}
|
||||
,
|
||||
#if CRYPT
|
||||
{META | 'E', set_encryption_key}
|
||||
,
|
||||
#endif
|
||||
{META | 'F', forwword}
|
||||
,
|
||||
{META | 'G', gotoline}
|
||||
|
||||
12
estruct.h
12
estruct.h
@@ -183,12 +183,6 @@
|
||||
#define poke(a,b,c,d) movedata(FP_SEG(c),FP_OFF(c),a,b,d)
|
||||
#endif
|
||||
|
||||
#if VMS
|
||||
#define atoi xatoi
|
||||
#define abs xabs
|
||||
#define getname xgetname
|
||||
#endif
|
||||
|
||||
#if MSDOS & MSC
|
||||
#include <dos.h>
|
||||
#include <memory.h>
|
||||
@@ -215,12 +209,6 @@
|
||||
#define ENVFUNC 0
|
||||
#endif
|
||||
|
||||
/* Internal defined functions */
|
||||
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif
|
||||
|
||||
/* DIFCASE represents the integer difference between upper
|
||||
and lower case letters. It is an xor-able value, which is
|
||||
fortunate, since the relative positions of upper to lower
|
||||
|
||||
65
eval.c
65
eval.c
@@ -129,7 +129,8 @@ static const char *envars[] = {
|
||||
"line", /* text of current line */
|
||||
"gflags", /* global internal emacs flags */
|
||||
"rval", /* child process return value */
|
||||
"tab", /* tab 4 or 8 */
|
||||
"tab", /* tab width, 1... */
|
||||
"hardtab", /* TRUE for hard coded tab, FALSE for soft ones */
|
||||
"overlap",
|
||||
"jump",
|
||||
#if SCROLLCODE
|
||||
@@ -177,15 +178,16 @@ static const char *envars[] = {
|
||||
#define EVGFLAGS 35
|
||||
#define EVRVAL 36
|
||||
#define EVTAB 37
|
||||
#define EVOVERLAP 38
|
||||
#define EVSCROLLCOUNT 39
|
||||
#define EVSCROLL 40
|
||||
#define EVHARDTAB 38
|
||||
#define EVOVERLAP 39
|
||||
#define EVSCROLLCOUNT 40
|
||||
#define EVSCROLL 41
|
||||
|
||||
enum function_type {
|
||||
NILNAMIC = 0,
|
||||
MONAMIC = (1 << 6),
|
||||
DYNAMIC = (2 << 6),
|
||||
TRINAMIC = (3 << 6),
|
||||
TRINAMIC = (3 << 6)
|
||||
} ;
|
||||
|
||||
enum function_code {
|
||||
@@ -195,7 +197,7 @@ enum function_code {
|
||||
UFAND, UFOR, UFLENGTH, UFUPPER, UFLOWER, UFTRUTH,
|
||||
UFASCII, UFCHR, UFGTKEY, UFRND, UFABS, UFSINDEX,
|
||||
UFENV, UFBIND, UFEXIST, UFFIND, UFBAND, UFBOR,
|
||||
UFBXOR, UFBNOT, UFXLATE,
|
||||
UFBXOR, UFBNOT, UFXLATE
|
||||
} ;
|
||||
|
||||
/* List of recognized user functions. */
|
||||
@@ -288,7 +290,7 @@ static int putctext( char *iline)
|
||||
static char *result ; /* string result */
|
||||
static int ressize = 0 ; /* mark result as uninitialized */
|
||||
|
||||
static int ernd( void) ;
|
||||
static int ernd( int i) ;
|
||||
static int sindex( char *source, char *pattern) ;
|
||||
static char *xlat( char *source, char *lookup, char *trans) ;
|
||||
|
||||
@@ -537,13 +539,7 @@ static char *gtfun( char *fname) {
|
||||
retstr = result ;
|
||||
break ;
|
||||
case UFRND | MONAMIC:
|
||||
sz = abs( atoi( arg1)) ;
|
||||
if( sz == 0)
|
||||
sz = ernd() ;
|
||||
else
|
||||
sz = ernd() % sz + 1 ;
|
||||
|
||||
retstr = i_to_a( sz) ;
|
||||
retstr = i_to_a( ernd( atoi( arg1))) ;
|
||||
break ;
|
||||
case UFABS | MONAMIC:
|
||||
retstr = i_to_a( abs( atoi( arg1))) ;
|
||||
@@ -740,7 +736,9 @@ static char *gtenv( char *vname) {
|
||||
case EVRVAL:
|
||||
return i_to_a(rval);
|
||||
case EVTAB:
|
||||
return i_to_a(tabmask + 1);
|
||||
return i_to_a( tabwidth) ;
|
||||
case EVHARDTAB:
|
||||
return ltos( hardtab) ;
|
||||
case EVOVERLAP:
|
||||
return i_to_a(overlap);
|
||||
case EVSCROLLCOUNT:
|
||||
@@ -1055,11 +1053,17 @@ static int svar(struct variable_description *var, char *value)
|
||||
case EVRVAL:
|
||||
break;
|
||||
case EVTAB:
|
||||
tabmask = atoi(value) - 1;
|
||||
if( tabmask != 0x07 && tabmask != 0x03 && tabmask != 1)
|
||||
tabmask = 0x07;
|
||||
curwp->w_flag |= WFHARD;
|
||||
c = atoi( value) ;
|
||||
if( c > 0) {
|
||||
tabwidth = c ;
|
||||
curwp->w_flag |= WFHARD;
|
||||
} else
|
||||
status = FALSE ;
|
||||
|
||||
break;
|
||||
case EVHARDTAB:
|
||||
hardtab = stol( value) ;
|
||||
break ;
|
||||
case EVOVERLAP:
|
||||
overlap = atoi(value);
|
||||
break;
|
||||
@@ -1311,20 +1315,21 @@ char *mklower(char *str)
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* take the absolute value of an integer
|
||||
*/
|
||||
int abs(int x)
|
||||
{
|
||||
return x < 0 ? -x : x;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns a random integer
|
||||
* ernd( 0) [ 0 .. 2147483647]
|
||||
* ernd( i) [ 1 .. abs( i)]
|
||||
* ernd( 1) [ 1]
|
||||
* ernd( -2147483648) [ 1 .. 2147483647] actually 2147482413
|
||||
*/
|
||||
static int ernd( void) {
|
||||
seed = abs(seed * 1721 + 10007);
|
||||
return seed;
|
||||
static int ernd( int i) {
|
||||
seed = seed * 1721 + 10007 ;
|
||||
seed &= ~(1 << 31) ; /* avoid abs() which introduces 176719 periodicity */
|
||||
if( i == 0)
|
||||
return seed ;
|
||||
|
||||
i = i < 0 ? -i : i ; /* abs( i) */
|
||||
return seed % i + 1 ;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
1
eval.h
1
eval.h
@@ -22,7 +22,6 @@ int setvar( int f, int n) ;
|
||||
char *getval( char *token) ;
|
||||
int stol( char *val) ;
|
||||
char *mklower( char *str) ;
|
||||
int abs( int x) ;
|
||||
|
||||
int clrmes( int f, int n) ;
|
||||
int writemsg( int f, int n) ;
|
||||
|
||||
2
exec.c
2
exec.c
@@ -965,7 +965,7 @@ int execfile( int f, int n) {
|
||||
char *fname ; /* name of file to execute */
|
||||
char *fspec ; /* full file spec */
|
||||
|
||||
status = newmlarg( &fname, "File to execute: ", 0) ;
|
||||
status = newmlarg( &fname, "Execute file: ", 0) ;
|
||||
if( status != TRUE)
|
||||
return status ;
|
||||
|
||||
|
||||
450
execute.c
450
execute.c
@@ -1,108 +1,418 @@
|
||||
/* execute.c -- implements execute.h */
|
||||
#include "execute.h"
|
||||
|
||||
#define CLRMSG 0 /* space clears the message line with no insert */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "estruct.h"
|
||||
#include "bind.h"
|
||||
#include "random.h"
|
||||
#include "display.h"
|
||||
#include "file.h"
|
||||
#include "input.h"
|
||||
#include "mlout.h"
|
||||
#include "search.h"
|
||||
#include "terminal.h"
|
||||
#include "window.h"
|
||||
|
||||
int gasave = 256 ; /* global ASAVE size */
|
||||
int gacount = 256 ; /* count until next ASAVE */
|
||||
|
||||
|
||||
/* insert a # into the text here...we are in CMODE */
|
||||
static int inspound( int n) {
|
||||
/* if we are at the beginning of the line, no go */
|
||||
if( n == 1 && curwp->w_doto != 0) {
|
||||
int i ;
|
||||
|
||||
/* scan to see if all space before this is white space */
|
||||
for( i = curwp->w_doto - 1 ; i >= 0 ; i -= 1) {
|
||||
int ch ; /* last character before input */
|
||||
|
||||
ch = lgetc( curwp->w_dotp, i) ;
|
||||
if( ch != ' ' && ch != '\t')
|
||||
break ;
|
||||
}
|
||||
|
||||
/* delete back first */
|
||||
if( i < 0)
|
||||
while( getccol( FALSE) >= 1)
|
||||
backdel( FALSE, 1) ;
|
||||
}
|
||||
|
||||
/* and insert the required pound */
|
||||
return linsert( n, '#') ;
|
||||
}
|
||||
|
||||
/*
|
||||
* insert a brace into the text here...we are in CMODE
|
||||
*
|
||||
* int n; repeat count
|
||||
* int c; brace to insert (if not }, just normal insertion).
|
||||
*/
|
||||
static int insbrace( int n, int c) {
|
||||
int ch ; /* last character before input */
|
||||
int oc ; /* caractere oppose a c */
|
||||
int i, count ;
|
||||
int target ; /* column brace should go after */
|
||||
struct line *oldlp ;
|
||||
int oldoff ;
|
||||
|
||||
/* if not called with {, acts as insertion */
|
||||
if( c == '}')
|
||||
oc = '{' ;
|
||||
else
|
||||
return linsert( n, c) ;
|
||||
|
||||
/* scan to see if all preceding spaces are white spaces, if not, insert */
|
||||
for( i = curwp->w_doto - 1 ; i >= 0 ; --i) {
|
||||
ch = lgetc( curwp->w_dotp, i) ;
|
||||
if( ch != ' ' && ch != '\t')
|
||||
return linsert( n, c) ;
|
||||
}
|
||||
|
||||
oldlp = curwp->w_dotp ;
|
||||
oldoff = curwp->w_doto ;
|
||||
|
||||
count = 1 ;
|
||||
do {
|
||||
if( boundry( curwp->w_dotp, curwp->w_doto, REVERSE)) {
|
||||
/* at beginning of buffer, no match to be found */
|
||||
curwp->w_dotp = oldlp ;
|
||||
curwp->w_doto = oldoff ;
|
||||
return linsert( n, c) ;
|
||||
}
|
||||
|
||||
backchar( FALSE, 1) ;
|
||||
|
||||
/* if not eol */
|
||||
if( curwp->w_doto != llength( curwp->w_dotp)) {
|
||||
ch = lgetc( curwp->w_dotp, curwp->w_doto) ;
|
||||
if( ch == c)
|
||||
++count ;
|
||||
else if( ch == oc)
|
||||
--count ;
|
||||
}
|
||||
} while( count > 0) ;
|
||||
|
||||
curwp->w_doto = 0 ; /* debut de ligne */
|
||||
/* aller au debut de la ligne apres la tabulation */
|
||||
while( (ch = lgetc( curwp->w_dotp, curwp->w_doto)) == ' '
|
||||
|| ch == '\t')
|
||||
forwchar( FALSE, 1) ;
|
||||
|
||||
/* delete back first */
|
||||
target = getccol( FALSE) ; /* c'est l'indent que l'on doit avoir */
|
||||
curwp->w_dotp = oldlp ;
|
||||
curwp->w_doto = oldoff ;
|
||||
|
||||
while( target != getccol( FALSE)) {
|
||||
if( target < getccol( FALSE)) /* on doit detruire des caracteres */
|
||||
while( getccol( FALSE) > target)
|
||||
backdel( FALSE, 1) ;
|
||||
else { /* on doit en inserer */
|
||||
while( target - getccol( FALSE) >= tabwidth)
|
||||
insert_tab( FALSE, 1) ;
|
||||
|
||||
linsert( target - getccol( FALSE), ' ') ;
|
||||
}
|
||||
}
|
||||
|
||||
/* and insert the required brace(s) */
|
||||
return linsert( n, c) ;
|
||||
}
|
||||
|
||||
#if CFENCE
|
||||
/*
|
||||
* Close fences are matched against their partners, and if
|
||||
* on screen the cursor briefly lights there
|
||||
*
|
||||
* char ch; fence type to match against
|
||||
*/
|
||||
static void fmatch( int ch) {
|
||||
struct line *oldlp ; /* original line pointer */
|
||||
int oldoff ; /* and offset */
|
||||
struct line *toplp ; /* top line in current window */
|
||||
int count ; /* current fence level count */
|
||||
int opench ; /* open fence */
|
||||
|
||||
/* $tpause <= 0 disable fmatch */
|
||||
if( term.t_pause <= 0)
|
||||
return ;
|
||||
|
||||
/* first get the display update out there */
|
||||
update( FALSE) ;
|
||||
|
||||
/* save the original cursor position */
|
||||
oldlp = curwp->w_dotp ;
|
||||
oldoff = curwp->w_doto ;
|
||||
|
||||
/* setup proper open fence for passed close fence */
|
||||
if( ch == ')')
|
||||
opench = '(' ;
|
||||
else if( ch == '}')
|
||||
opench = '{' ;
|
||||
else
|
||||
opench = '[' ;
|
||||
|
||||
/* find the top line and set up for scan */
|
||||
toplp = curwp->w_linep->l_bp ;
|
||||
backchar( FALSE, 1) ; /* . was after the }, move back */
|
||||
|
||||
/* scan back until we find it, or reach past the top of the window */
|
||||
count = 1 ;
|
||||
do {
|
||||
/* At beginning of window or buffer, no match to be found */
|
||||
if( curwp->w_dotp == toplp
|
||||
|| boundry( curwp->w_dotp, curwp->w_doto, REVERSE))
|
||||
break ;
|
||||
|
||||
backchar( FALSE, 1) ;
|
||||
|
||||
/* if not eol */
|
||||
if( curwp->w_doto != llength(curwp->w_dotp)) {
|
||||
int c ; /* current character in scan */
|
||||
|
||||
c = lgetc( curwp->w_dotp, curwp->w_doto) ;
|
||||
if( c == ch)
|
||||
++count ;
|
||||
else if( c == opench)
|
||||
--count ;
|
||||
}
|
||||
} while( count > 0) ;
|
||||
|
||||
/* if count is zero, we have a match, display the sucker */
|
||||
if( count == 0) {
|
||||
int i ;
|
||||
|
||||
/* there is a real machine dependant timing problem here we have
|
||||
yet to solve......... */
|
||||
for( i = 0 ; i < term.t_pause ; i++) {
|
||||
update( FALSE) ;
|
||||
usleep( 10000L) ;
|
||||
}
|
||||
}
|
||||
|
||||
/* restore the current position */
|
||||
curwp->w_dotp = oldlp ;
|
||||
curwp->w_doto = oldoff ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* 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;
|
||||
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 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);
|
||||
/* non insertable character can only be bound to function */
|
||||
if( c < 0x20
|
||||
|| (c >= 0x7F && c < 0xA0)
|
||||
|| c > 0x10FFFF) { /* last valid unicode */
|
||||
lastflag = 0 ; /* Fake last flags. */
|
||||
mloutfmt( "%B(Key not bound)") ; /* Complain */
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
#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;
|
||||
/* insertable character => self insert, check if buffer is read only */
|
||||
if( curbp->b_mode & MDVIEW) {
|
||||
lastflag = 0 ;
|
||||
return rdonly() ;
|
||||
}
|
||||
|
||||
/* check valid count */
|
||||
if( n <= 0) {
|
||||
lastflag = 0 ;
|
||||
return n < 0 ? FALSE : TRUE ;
|
||||
}
|
||||
|
||||
/* wrap on space after fill column in wrap mode */
|
||||
if( c == ' '
|
||||
&& (curwp->w_bufp->b_mode & MDWRAP)
|
||||
&& fillcol > 0
|
||||
&& getccol( FALSE) > fillcol) {
|
||||
status = execute( META | SPEC | 'W', FALSE, 1) ; /* defaults to wrapword */
|
||||
if( status != TRUE) {
|
||||
lastflag = 0 ;
|
||||
return status ;
|
||||
}
|
||||
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);
|
||||
thisflag = 0 ; /* For the future. */
|
||||
|
||||
/* 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);
|
||||
/* following handling of overwrite is only valid when n == 1 */
|
||||
/* 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 forward */
|
||||
if( curbp->b_mode & MDOVER
|
||||
&& curwp->w_doto < curwp->w_dotp->l_used
|
||||
&& (lgetc( curwp->w_dotp, curwp->w_doto) != '\t' ||
|
||||
((curwp->w_doto) % tabwidth) == (tabwidth - 1)))
|
||||
ldelchar( 1, FALSE) ;
|
||||
|
||||
/* do the appropriate insertion */
|
||||
switch( c) {
|
||||
case '}':
|
||||
case ']':
|
||||
case ')':
|
||||
case '#':
|
||||
if( (curbp->b_mode & MDCMOD) != 0) {
|
||||
if( c == '#')
|
||||
status = inspound( n) ;
|
||||
else {
|
||||
status = insbrace( n, c) ;
|
||||
#if CFENCE
|
||||
/* check for CMODE fence matching */
|
||||
if ((c == '}' || c == ')' || c == ']') &&
|
||||
(curbp->b_mode & MDCMOD) != 0)
|
||||
fmatch(c);
|
||||
if( status == TRUE)
|
||||
fmatch( c) ; /* check for CMODE fence matching */
|
||||
#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;
|
||||
break ;
|
||||
}
|
||||
default:
|
||||
status = linsert( n, c) ;
|
||||
}
|
||||
|
||||
lastflag = 0 ; /* Fake last flags. */
|
||||
mloutfmt( "%B(Key not bound)") ; /* Complain */
|
||||
return FALSE ;
|
||||
/* perform auto-save */
|
||||
if( status == TRUE /* successful insertion */
|
||||
&& (curbp->b_mode & MDASAVE) /* auto save is on */
|
||||
&& (--gacount == 0)) { /* insertion count reached */
|
||||
/* and save the file if needed */
|
||||
upscreen( FALSE, 0) ;
|
||||
filesave( FALSE, 0) ;
|
||||
gacount = gasave ;
|
||||
}
|
||||
|
||||
lastflag = thisflag ;
|
||||
return status ;
|
||||
}
|
||||
|
||||
|
||||
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 */
|
||||
|
||||
/* 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 */
|
||||
/* do ^U repeat argument processing */
|
||||
while( c == reptc
|
||||
||( (c & META)
|
||||
&& (((basec = c & ~META) >= '0' && basec <= '9') || basec == '-'))) {
|
||||
int mflag = 0 ; /* minus flag, default to positive */
|
||||
|
||||
f = TRUE ;
|
||||
if( c == reptc) {
|
||||
n = 4 ;
|
||||
basec = 2 ; /* lead by universal arg cmd */
|
||||
} else if( c & META) {
|
||||
if( basec == '-') {
|
||||
mflag = TRUE ; /* negative */
|
||||
n = 1 ;
|
||||
basec = 1 ; /* lead by M-- */
|
||||
} else {
|
||||
n = basec - '0' ;
|
||||
basec = 0 ; /* lead by M-# */
|
||||
}
|
||||
}
|
||||
|
||||
mloutfmt( "Arg: %s%d", mflag ? "-" : "", n) ;
|
||||
while( ((c = getcmd()) >= '0' && c <= '9') || c == '-') {
|
||||
if( c == '-') {
|
||||
if( basec == 2) { /* directly follows universal arg cmd */
|
||||
n = 1 ;
|
||||
basec = 1 ;
|
||||
mflag = TRUE ;
|
||||
} else
|
||||
break ;
|
||||
} else {
|
||||
if( basec) { /* follows universal arg cmd or leading dash */
|
||||
n = c - '0' ;
|
||||
basec = 0 ;
|
||||
} else if( n <= 0xCCCCCCB) /* avoid overflow */
|
||||
n = n * 10 + c - '0' ;
|
||||
}
|
||||
|
||||
mloutfmt( "Arg: %s%d", mflag ? "-" : "", n) ;
|
||||
}
|
||||
|
||||
if( mflag)
|
||||
n = -n ;
|
||||
}
|
||||
|
||||
/* and execute the command */
|
||||
execute( c, f, n) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* end of execute.c */
|
||||
|
||||
@@ -2,4 +2,4 @@ extern int gasave ; /* global ASAVE size */
|
||||
extern int gacount ; /* count until next ASAVE */
|
||||
|
||||
int execute( int c, int f, int n) ;
|
||||
|
||||
void kbd_loop( void) ;
|
||||
|
||||
114
file.c
114
file.c
@@ -17,8 +17,8 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "buffer.h"
|
||||
#include "crypt.h"
|
||||
#include "defines.h"
|
||||
#include "display.h"
|
||||
#include "estruct.h"
|
||||
#include "execute.h"
|
||||
#include "fileio.h"
|
||||
@@ -173,73 +173,6 @@ int viewfile( int f, int n) { /* visit a file in VIEW mode */
|
||||
return status ;
|
||||
}
|
||||
|
||||
#if CRYPT
|
||||
void cryptbufferkey( struct buffer *bp) {
|
||||
myencrypt( (char *) NULL, 0) ;
|
||||
myencrypt( bp->b_key, strlen( bp->b_key)) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* reset encryption key of current buffer
|
||||
*
|
||||
* int f; default flag
|
||||
* int n; numeric argument
|
||||
*/
|
||||
int set_encryption_key( int f, int n) {
|
||||
int status ; /* return status */
|
||||
int odisinp ; /* original value of disinp */
|
||||
char *key ; /* new encryption string */
|
||||
|
||||
/* turn command input echo off */
|
||||
odisinp = disinp ;
|
||||
disinp = FALSE ;
|
||||
|
||||
/* get the string to use as an encrytion string */
|
||||
status = newmlarg( &key, "Encryption String: ", sizeof( ekey_t)) ;
|
||||
disinp = odisinp ;
|
||||
if( status != TRUE)
|
||||
return status ;
|
||||
|
||||
/* save it off and encrypt it*/
|
||||
strncpy( curbp->b_key, key, sizeof( ekey_t) - 1) ;
|
||||
curbp->b_key[ sizeof( ekey_t) - 1] = '\0' ;
|
||||
free( key) ;
|
||||
cryptbufferkey( curbp) ;
|
||||
|
||||
mloutstr( "") ; /* clear the message line */
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
static int resetkey(void)
|
||||
{ /* reset the encryption key if needed */
|
||||
int s; /* return status */
|
||||
|
||||
/* turn off the encryption flag */
|
||||
is_crypted = FALSE;
|
||||
|
||||
/* if we are in crypt mode */
|
||||
if (curbp->b_mode & MDCRYPT) {
|
||||
if (curbp->b_key[0] == 0) {
|
||||
s = set_encryption_key(FALSE, 0);
|
||||
if (s != TRUE)
|
||||
return s;
|
||||
}
|
||||
|
||||
/* let others know... */
|
||||
is_crypted = TRUE;
|
||||
|
||||
/* and set up the key to be used! */
|
||||
/* de-encrypt it */
|
||||
cryptbufferkey( curbp) ;
|
||||
|
||||
/* re-encrypt it...seeding it to start */
|
||||
cryptbufferkey( curbp) ;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* getfile()
|
||||
*
|
||||
@@ -343,11 +276,6 @@ int readin(const char *fname, boolean lockfl)
|
||||
#else
|
||||
return ABORT;
|
||||
#endif
|
||||
#endif
|
||||
#if CRYPT
|
||||
s = resetkey();
|
||||
if (s != TRUE)
|
||||
return s;
|
||||
#endif
|
||||
bp = curbp; /* Cheap. */
|
||||
if ((s = bclear(bp)) != TRUE) /* Might be old. */
|
||||
@@ -532,21 +460,24 @@ int filewrite( int f, int n) {
|
||||
|
||||
status = newmlarg( &fname, "Write file: ", sizeof( fname_t)) ;
|
||||
if( status == TRUE) {
|
||||
status = writeout( fname) ;
|
||||
if( status == TRUE) {
|
||||
struct window *wp ;
|
||||
if( strlen( fname) > sizeof( fname_t) - 1)
|
||||
status = FALSE ;
|
||||
else {
|
||||
status = writeout( fname) ;
|
||||
if( status == TRUE) {
|
||||
struct window *wp ;
|
||||
|
||||
strncpy( curbp->b_fname, fname, sizeof( fname_t) - 1) ;
|
||||
curbp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
|
||||
curbp->b_flag &= ~BFCHG ;
|
||||
wp = wheadp ; /* Update mode lines. */
|
||||
while( wp != NULL) {
|
||||
if( wp->w_bufp == curbp)
|
||||
wp->w_flag |= WFMODE ;
|
||||
strcpy( curbp->b_fname, fname) ;
|
||||
curbp->b_flag &= ~BFCHG ;
|
||||
wp = wheadp ; /* Update mode lines. */
|
||||
while( wp != NULL) {
|
||||
if( wp->w_bufp == curbp)
|
||||
wp->w_flag |= WFMODE ;
|
||||
|
||||
wp = wp->w_wndp ;
|
||||
}
|
||||
}
|
||||
wp = wp->w_wndp ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free( fname) ;
|
||||
}
|
||||
@@ -610,12 +541,6 @@ int writeout( const char *fn)
|
||||
struct line *lp;
|
||||
int nline;
|
||||
|
||||
#if CRYPT
|
||||
s = resetkey();
|
||||
if (s != TRUE)
|
||||
return s;
|
||||
#endif
|
||||
|
||||
if ((s = ffwopen(fn)) != FIOSUC) { /* Open writes message. */
|
||||
mloutstr( "Cannot open file for writing") ;
|
||||
return FALSE;
|
||||
@@ -715,11 +640,6 @@ static int ifile( const char *fname) {
|
||||
}
|
||||
mloutstr( "(Inserting file)") ;
|
||||
|
||||
#if CRYPT
|
||||
s = resetkey();
|
||||
if (s != TRUE)
|
||||
return s;
|
||||
#endif
|
||||
/* back up a line and save the mark here */
|
||||
curwp->w_dotp = lback(curwp->w_dotp);
|
||||
curwp->w_doto = 0;
|
||||
|
||||
6
file.h
6
file.h
@@ -2,14 +2,8 @@
|
||||
#define _FILE_H_
|
||||
|
||||
#include "buffer.h"
|
||||
#include "crypt.h"
|
||||
#include "retcode.h"
|
||||
|
||||
#if CRYPT
|
||||
void cryptbufferkey( struct buffer *bp) ;
|
||||
int set_encryption_key( int f, int n) ;
|
||||
#endif
|
||||
|
||||
extern boolean restflag ; /* restricted use? */
|
||||
boolean resterr( void) ; /* restricted error message */
|
||||
|
||||
|
||||
24
fileio.c
24
fileio.c
@@ -23,10 +23,6 @@
|
||||
#include "retcode.h"
|
||||
#include "utf8.h"
|
||||
|
||||
#if CRYPT
|
||||
boolean is_crypted ; /* currently encrypting? */
|
||||
#endif
|
||||
|
||||
char *fline = NULL ; /* dynamic return line */
|
||||
static int flen = 0 ; /* current allocated length of fline */
|
||||
int ftype ;
|
||||
@@ -103,20 +99,6 @@ fio_code ffclose(void)
|
||||
* Check only at the newline.
|
||||
*/
|
||||
fio_code ffputline( char *buf, int nbuf, int dosflag) {
|
||||
#if CRYPT
|
||||
if( is_crypted) {
|
||||
int i ;
|
||||
|
||||
for( i = 0 ; i < nbuf ; i++) {
|
||||
char c ;
|
||||
|
||||
c = buf[ i] ;
|
||||
myencrypt( &c, 1) ;
|
||||
fputc( c, ffp) ;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
|
||||
fwrite( buf, 1, nbuf, ffp) ;
|
||||
|
||||
if( dosflag)
|
||||
@@ -217,11 +199,7 @@ fio_code ffgetline(void)
|
||||
} else /* c == '\n' */
|
||||
ftype |= FTYPE_UNIX ;
|
||||
|
||||
/* terminate and decrypt the string */
|
||||
/* terminate the string */
|
||||
fline[i] = 0;
|
||||
#if CRYPT
|
||||
if( is_crypted)
|
||||
myencrypt( fline, fpayload);
|
||||
#endif
|
||||
return FIOSUC;
|
||||
}
|
||||
|
||||
8
fileio.h
8
fileio.h
@@ -1,8 +1,6 @@
|
||||
#ifndef _FILEIO_H_
|
||||
#define _FILEIO_H_
|
||||
|
||||
#include "crypt.h"
|
||||
|
||||
typedef enum {
|
||||
FIOSUC, /* File I/O, success. */
|
||||
FIOFNF, /* File I/O, file not found. */
|
||||
@@ -24,12 +22,6 @@ typedef enum {
|
||||
#define FCODE_EXTND 0x82
|
||||
#define FCODE_MIXED 0x83
|
||||
|
||||
#if CRYPT
|
||||
#include "retcode.h"
|
||||
|
||||
extern boolean is_crypted ; /* currently encrypting? */
|
||||
#endif
|
||||
|
||||
extern char *fline ; /* dynamic return line */
|
||||
extern int ftype ;
|
||||
extern int fcode ; /* encoding type */
|
||||
|
||||
96
input.c
96
input.c
@@ -45,8 +45,6 @@ kbdstate kbdmode = STOP ; /* current keyboard macro mode */
|
||||
int lastkey = 0 ; /* last keystoke */
|
||||
int kbdrep = 0 ; /* number of repetitions */
|
||||
|
||||
int disinp = TRUE ; /* display input characters */
|
||||
|
||||
int metac = CONTROL | '[' ; /* current meta character */
|
||||
int ctlxc = CONTROL | 'X' ; /* current control X prefix char */
|
||||
int reptc = CONTROL | 'U' ; /* current universal repeat char */
|
||||
@@ -56,7 +54,6 @@ const int nlc = CONTROL | 'J' ; /* end of input char */
|
||||
|
||||
static const int quotec = 0x11 ; /* quote char during getstring() */
|
||||
|
||||
static void outstring( char *s) ;
|
||||
|
||||
/*
|
||||
* Ask a yes or no question in the message line. Return either TRUE, FALSE, or
|
||||
@@ -164,8 +161,6 @@ int ectoc(int c)
|
||||
fn_t getname(void)
|
||||
{
|
||||
int cpos; /* current column on screen output */
|
||||
int c;
|
||||
char *sp; /* pointer to string for output */
|
||||
struct name_bind *ffp; /* first ptr to entry in name binding table */
|
||||
struct name_bind *cffp; /* current ptr to entry in name binding table */
|
||||
struct name_bind *lffp; /* last ptr to entry in name binding table */
|
||||
@@ -183,6 +178,8 @@ fn_t getname(void)
|
||||
|
||||
/* build a name string from the keyboard */
|
||||
while (TRUE) {
|
||||
int c ;
|
||||
|
||||
c = tgetc();
|
||||
|
||||
/* if we are at the end, just match it */
|
||||
@@ -199,9 +196,7 @@ fn_t getname(void)
|
||||
|
||||
} else if (c == 0x7F || c == 0x08) { /* rubout/erase */
|
||||
if (cpos != 0) {
|
||||
TTputc('\b');
|
||||
TTputc(' ');
|
||||
TTputc('\b');
|
||||
echos( "\b \b") ;
|
||||
--ttcol;
|
||||
--cpos;
|
||||
TTflush();
|
||||
@@ -209,9 +204,7 @@ fn_t getname(void)
|
||||
|
||||
} else if (c == 0x15) { /* C-U, kill */
|
||||
while (cpos != 0) {
|
||||
TTputc('\b');
|
||||
TTputc(' ');
|
||||
TTputc('\b');
|
||||
echos( "\b \b") ;
|
||||
--cpos;
|
||||
--ttcol;
|
||||
}
|
||||
@@ -232,9 +225,7 @@ fn_t getname(void)
|
||||
(buf, (ffp + 1)->n_name,
|
||||
strlen(buf)) != 0)) {
|
||||
/* no...we match, print it */
|
||||
sp = ffp->n_name + cpos;
|
||||
while (*sp)
|
||||
TTputc(*sp++);
|
||||
echos( ffp->n_name + cpos) ;
|
||||
TTflush();
|
||||
return ffp->n_func;
|
||||
} else {
|
||||
@@ -278,8 +269,7 @@ fn_t getname(void)
|
||||
}
|
||||
|
||||
/* add the character */
|
||||
TTputc(buf
|
||||
[cpos++]);
|
||||
echoc( buf[ cpos++]) ;
|
||||
}
|
||||
/* << << << << << << << << << << << << << << << << << */
|
||||
}
|
||||
@@ -295,7 +285,7 @@ fn_t getname(void)
|
||||
} else {
|
||||
if (cpos < NSTRING - 1 && c > ' ') {
|
||||
buf[cpos++] = c;
|
||||
TTputc(c);
|
||||
echoc( c) ;
|
||||
}
|
||||
|
||||
++ttcol;
|
||||
@@ -529,12 +519,9 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
|
||||
static char tmp[] = "/tmp/meXXXXXX";
|
||||
FILE *tmpf = NULL;
|
||||
#endif
|
||||
ffile = (strcmp(prompt, "Find file: ") == 0
|
||||
|| strcmp(prompt, "View file: ") == 0
|
||||
|| strcmp(prompt, "Insert file: ") == 0
|
||||
|| strcmp(prompt, "Write file: ") == 0
|
||||
|| strcmp(prompt, "Read file: ") == 0
|
||||
|| strcmp(prompt, "File to execute: ") == 0);
|
||||
/* Look for "Find file: ", "View file: ", "Insert file: ", "Write file: ",
|
||||
** "Read file: ", "Execute file: " */
|
||||
ffile = NULL != strstr( prompt, " file: ") ;
|
||||
#endif
|
||||
|
||||
cpos = 0;
|
||||
@@ -596,15 +583,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
|
||||
} else if ((c == 0x7F || c == 0x08) && quotef == FALSE) {
|
||||
/* rubout/erase */
|
||||
if (cpos != 0) {
|
||||
outstring("\b \b");
|
||||
echos("\b \b");
|
||||
--ttcol;
|
||||
|
||||
if (buf[--cpos] < 0x20) {
|
||||
outstring("\b \b");
|
||||
echos("\b \b");
|
||||
--ttcol;
|
||||
}
|
||||
if (buf[cpos] == '\n') {
|
||||
outstring("\b\b \b\b");
|
||||
echos("\b\b \b\b");
|
||||
ttcol -= 2;
|
||||
}
|
||||
|
||||
@@ -614,15 +601,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
|
||||
} else if (c == 0x15 && quotef == FALSE) {
|
||||
/* C-U, kill */
|
||||
while (cpos != 0) {
|
||||
outstring("\b \b");
|
||||
echos("\b \b");
|
||||
--ttcol;
|
||||
|
||||
if (buf[--cpos] < 0x20) {
|
||||
outstring("\b \b");
|
||||
echos("\b \b");
|
||||
--ttcol;
|
||||
}
|
||||
if (buf[cpos] == '\n') {
|
||||
outstring("\b\b \b\b");
|
||||
echos("\b\b \b\b");
|
||||
ttcol -= 2;
|
||||
}
|
||||
}
|
||||
@@ -642,15 +629,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
|
||||
didtry = 1;
|
||||
ocpos = cpos;
|
||||
while (cpos != 0) {
|
||||
outstring("\b \b");
|
||||
echos("\b \b");
|
||||
--ttcol;
|
||||
|
||||
if (buf[--cpos] < 0x20) {
|
||||
outstring("\b \b");
|
||||
echos("\b \b");
|
||||
--ttcol;
|
||||
}
|
||||
if (buf[cpos] == '\n') {
|
||||
outstring("\b\b \b\b");
|
||||
echos("\b\b \b\b");
|
||||
ttcol -= 2;
|
||||
}
|
||||
if (buf[cpos] == '*' || buf[cpos] == '?')
|
||||
@@ -737,16 +724,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
|
||||
for (n = 0; n < cpos; n++) {
|
||||
c = buf[n];
|
||||
if ((c < ' ') && (c != '\n')) {
|
||||
outstring("^");
|
||||
echos("^");
|
||||
++ttcol;
|
||||
c ^= 0x40;
|
||||
}
|
||||
|
||||
if (c != '\n') {
|
||||
if (disinp)
|
||||
TTputc(c);
|
||||
} else { /* put out <NL> for <ret> */
|
||||
outstring("<NL>");
|
||||
if( c != '\n')
|
||||
echoc( c) ;
|
||||
else { /* put out <NL> for <ret> */
|
||||
echos("<NL>");
|
||||
ttcol += 3;
|
||||
}
|
||||
++ttcol;
|
||||
@@ -765,16 +751,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
|
||||
buf[cpos++] = c;
|
||||
|
||||
if ((c < ' ') && (c != '\n')) {
|
||||
outstring("^");
|
||||
echos("^");
|
||||
++ttcol;
|
||||
c ^= 0x40;
|
||||
}
|
||||
|
||||
if (c != '\n') {
|
||||
if (disinp)
|
||||
TTputc(c);
|
||||
} else { /* put out <NL> for <ret> */
|
||||
outstring("<NL>");
|
||||
if( c != '\n')
|
||||
echoc( c) ;
|
||||
else { /* put out <NL> for <ret> */
|
||||
echos("<NL>");
|
||||
ttcol += 3;
|
||||
}
|
||||
++ttcol;
|
||||
@@ -783,26 +768,3 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* output a string of characters when display input is enabled
|
||||
*
|
||||
* char *s; string to output
|
||||
*/
|
||||
static void outstring( char *s) {
|
||||
if( disinp)
|
||||
while( *s)
|
||||
TTputc( *s++) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* output a string of output characters
|
||||
*
|
||||
* char *s; string to output
|
||||
*/
|
||||
void ostring( char *s)
|
||||
{
|
||||
if (discmd)
|
||||
while (*s)
|
||||
TTputc( *s++ & 0xFF) ;
|
||||
}
|
||||
|
||||
2
input.h
2
input.h
@@ -13,7 +13,6 @@ extern int kbdrep ; /* number of repetitions */
|
||||
extern int kbdm[] ; /* Holds kayboard macro data */
|
||||
extern int *kbdptr ; /* current position in keyboard buf */
|
||||
extern int *kbdend ; /* ptr to end of the keyboard */
|
||||
extern int disinp ; /* display input characters */
|
||||
|
||||
extern int metac; /* current meta character */
|
||||
extern int ctlxc; /* current control X prefix char */
|
||||
@@ -31,6 +30,5 @@ int tgetc( void) ;
|
||||
int get1key( void) ;
|
||||
int getcmd( void) ;
|
||||
int getstring( const char *prompt, char *buf, int nbuf, int eolchar) ;
|
||||
void ostring( char *s) ;
|
||||
|
||||
#endif
|
||||
|
||||
49
line.c
49
line.c
@@ -26,7 +26,7 @@
|
||||
#include "window.h"
|
||||
|
||||
|
||||
int tabmask = 0x07 ; /* tabulator mask */
|
||||
int tabwidth = 8 ; /* column span of a tab */
|
||||
|
||||
#define BLOCK_SIZE 16 /* Line block chunk size. */
|
||||
|
||||
@@ -392,24 +392,29 @@ static int linsert_byte(int n, int c)
|
||||
}
|
||||
|
||||
int linsert( int n, unicode_t c) {
|
||||
char utf8[6];
|
||||
int bytes, i ;
|
||||
|
||||
assert( n > 0) ;
|
||||
assert( n >= 0) ;
|
||||
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||
return rdonly(); /* we are in read only mode */
|
||||
|
||||
bytes = unicode_to_utf8(c, utf8) ;
|
||||
if (bytes == 1)
|
||||
return linsert_byte(n, (unsigned char) utf8[0]);
|
||||
for (i = 0; i < n; i++) {
|
||||
int j;
|
||||
for (j = 0; j < bytes; j++) {
|
||||
unsigned char c = utf8[j];
|
||||
if (!linsert_byte(1, c))
|
||||
return FALSE;
|
||||
if( n > 0) {
|
||||
char utf8[ 6] ;
|
||||
int bytes, i ;
|
||||
|
||||
bytes = unicode_to_utf8(c, utf8) ;
|
||||
if (bytes == 1)
|
||||
return linsert_byte(n, (unsigned char) utf8[0]);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
int j;
|
||||
|
||||
for (j = 0; j < bytes; j++) {
|
||||
unsigned char c = utf8[j];
|
||||
if (!linsert_byte(1, c))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -418,13 +423,15 @@ int linsert( int n, unicode_t c) {
|
||||
*
|
||||
* int c; character to overwrite on current position
|
||||
*/
|
||||
static int lowrite(int c)
|
||||
{
|
||||
if (curwp->w_doto < curwp->w_dotp->l_used &&
|
||||
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
|
||||
((curwp->w_doto) & tabmask) == tabmask))
|
||||
ldelchar(1, FALSE);
|
||||
return linsert(1, c);
|
||||
static int lowrite( int c) {
|
||||
if( curwp->w_doto < curwp->w_dotp->l_used
|
||||
&& (
|
||||
lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
|
||||
((curwp->w_doto) % tabwidth) == (tabwidth - 1)
|
||||
))
|
||||
ldelchar( 1, FALSE) ;
|
||||
|
||||
return linsert( 1, c) ;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
2
line.h
2
line.h
@@ -28,7 +28,7 @@ struct line {
|
||||
#define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
|
||||
#define llength(lp) ((lp)->l_used)
|
||||
|
||||
extern int tabmask ;
|
||||
extern int tabwidth ;
|
||||
|
||||
char *getkill( void) ;
|
||||
|
||||
|
||||
7
lock.c
7
lock.c
@@ -1,3 +1,5 @@
|
||||
/* lock.c -- implements lock.h */
|
||||
|
||||
#include "estruct.h"
|
||||
#include "lock.h"
|
||||
|
||||
@@ -167,4 +169,9 @@ void lckerror(char *errstr)
|
||||
strcat(obuf, strerror(errno));
|
||||
mlwrite(obuf);
|
||||
}
|
||||
|
||||
#else
|
||||
typedef void _pedantic_empty_translation_unit ;
|
||||
#endif
|
||||
|
||||
/* end of lock.c */
|
||||
|
||||
172
main.c
172
main.c
@@ -1,7 +1,5 @@
|
||||
/* main.c -- */
|
||||
|
||||
#define CLRMSG 0 /* space clears the message line with no insert */
|
||||
|
||||
/*
|
||||
* main.c
|
||||
*
|
||||
@@ -84,7 +82,6 @@
|
||||
#include "eval.h"
|
||||
#include "execute.h"
|
||||
#include "file.h"
|
||||
#include "input.h"
|
||||
#include "lock.h"
|
||||
#include "mlout.h"
|
||||
#include "random.h"
|
||||
@@ -128,9 +125,6 @@ static void usage( void) {
|
||||
" -a|A process error file\n"
|
||||
" -e|E edit file\n"
|
||||
" -g|G<n> go to line <n>\n"
|
||||
#if CRYPT
|
||||
" -k|K<key> use code key\n"
|
||||
#endif
|
||||
" -r|R restrictive use\n"
|
||||
" -s|S<string> search string\n"
|
||||
" -v|V view file\n"
|
||||
@@ -142,28 +136,17 @@ static void usage( void) {
|
||||
|
||||
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 */
|
||||
int firstfile; /* first file flag */
|
||||
int carg; /* current arg to scan */
|
||||
int startflag; /* startup executed flag */
|
||||
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 gotoflag; /* do we need to goto a line at start? */
|
||||
int gline = 0; /* if so, what line? */
|
||||
int searchflag; /* Do we need to search at start? */
|
||||
int saveflag; /* temp store for lastflag */
|
||||
int errflag; /* C error processing? */
|
||||
bname_t bname ; /* buffer name of file to read */
|
||||
#if CRYPT
|
||||
int cryptflag; /* encrypting on the way in? */
|
||||
ekey_t ekey ; /* startup encryption key */
|
||||
#endif
|
||||
int newc;
|
||||
|
||||
#if PKCODE & VMS
|
||||
(void) umask(-1); /* Use old protection (this is at wrong place). */
|
||||
@@ -202,9 +185,6 @@ int main(int argc, char **argv)
|
||||
firstfile = TRUE; /* no file to edit yet */
|
||||
startflag = FALSE; /* startup file not executed yet */
|
||||
errflag = FALSE; /* not doing C error parsing */
|
||||
#if CRYPT
|
||||
cryptflag = FALSE; /* no encryption by default */
|
||||
#endif
|
||||
|
||||
/* Insure screen is initialized before startup and goto/search */
|
||||
update( FALSE) ;
|
||||
@@ -234,14 +214,6 @@ int main(int argc, char **argv)
|
||||
gotoflag = TRUE;
|
||||
gline = atoi(&argv[carg][2]);
|
||||
break;
|
||||
#if CRYPT
|
||||
case 'k': /* -k<key> for code key */
|
||||
case 'K':
|
||||
cryptflag = TRUE;
|
||||
strncpy( ekey, &argv[ carg][ 2], sizeof ekey - 1) ;
|
||||
ekey[ sizeof ekey - 1] = 0 ;
|
||||
break;
|
||||
#endif
|
||||
case 'r': /* -r restrictive use */
|
||||
case 'R':
|
||||
restflag = TRUE;
|
||||
@@ -307,13 +279,6 @@ int main(int argc, char **argv)
|
||||
/* set the modes appropriatly */
|
||||
if (viewflag)
|
||||
bp->b_mode |= MDVIEW;
|
||||
#if CRYPT
|
||||
if (cryptflag) {
|
||||
bp->b_mode |= MDCRYPT;
|
||||
strncpy( bp->b_key, ekey, sizeof ekey) ;
|
||||
cryptbufferkey( bp) ;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,10 +297,13 @@ int main(int argc, char **argv)
|
||||
|
||||
/* if invoked with no other startup files,
|
||||
run the system startup file here */
|
||||
if (startflag == FALSE) {
|
||||
startup("");
|
||||
startflag = TRUE;
|
||||
if( startflag == FALSE) {
|
||||
if( startup( "") != TRUE)
|
||||
mloutstr( "Default startup failed!") ;
|
||||
|
||||
startflag = TRUE ;
|
||||
}
|
||||
|
||||
discmd = TRUE; /* P.K. */
|
||||
|
||||
/* if there are any files to read, read the first one! */
|
||||
@@ -364,133 +332,11 @@ int main(int argc, char **argv)
|
||||
if( forwhunt( FALSE, 0))
|
||||
mloutfmt( "Found on line %d", getcline()) ;
|
||||
|
||||
/* Setup to process commands. */
|
||||
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;
|
||||
kbd_loop() ;
|
||||
return EXIT_SUCCESS ; /* never reached */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* mingw32.c -- */
|
||||
|
||||
#ifdef MINGW32
|
||||
#include "termio.h"
|
||||
#include "terminal.h"
|
||||
@@ -188,4 +190,8 @@ static void ttmove( int l, int c) {
|
||||
wgoxy( c, l) ;
|
||||
}
|
||||
|
||||
#else
|
||||
typedef void _pedantic_empty_translation_unit ;
|
||||
#endif
|
||||
|
||||
/* end of mingw32.c */
|
||||
|
||||
3
names.c
3
names.c
@@ -205,9 +205,6 @@ struct name_bind names[] = {
|
||||
{"search-reverse", backsearch},
|
||||
{"select-buffer", usebuffer},
|
||||
{"set", setvar},
|
||||
#if CRYPT
|
||||
{"set-encryption-key", set_encryption_key},
|
||||
#endif
|
||||
{"set-fill-column", setfillcol},
|
||||
{"set-mark", setmark},
|
||||
{"shell-command", spawn},
|
||||
|
||||
24
pklock.c
24
pklock.c
@@ -20,7 +20,8 @@
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#define MAXLOCK 512
|
||||
/* Maximum file length name 255 */
|
||||
#define MAXLOCK 256
|
||||
#define MAXNAME 128
|
||||
|
||||
#if defined(SVR4) && ! defined(__linux__)
|
||||
@@ -44,11 +45,14 @@ int gethostname(char *name, int namelen)
|
||||
char *dolock( const char *fname)
|
||||
{
|
||||
int fd, n;
|
||||
static char lname[MAXLOCK], locker[MAXNAME + 1];
|
||||
char lname[ MAXLOCK] ;
|
||||
static char locker[ MAXNAME + 1] ;
|
||||
int mask;
|
||||
struct stat sbuf;
|
||||
|
||||
strcat(strcpy(lname, fname), ".lock~");
|
||||
strncpy( lname, fname, sizeof lname - 1 - 6) ;
|
||||
lname[ sizeof lname - 1 - 6] = 0 ;
|
||||
strcat( lname, ".lock~") ;
|
||||
|
||||
/* check that we are not being cheated, qname must point to */
|
||||
/* a regular file - even this code leaves a small window of */
|
||||
@@ -111,11 +115,12 @@ char *dolock( const char *fname)
|
||||
*
|
||||
*********************/
|
||||
|
||||
char *undolock( const char *fname)
|
||||
{
|
||||
static char lname[MAXLOCK];
|
||||
char *undolock( const char *fname) {
|
||||
char lname[ MAXLOCK] ;
|
||||
|
||||
strcat(strcpy(lname, fname), ".lock~");
|
||||
strncpy( lname, fname, sizeof lname - 1 - 6) ;
|
||||
lname[ sizeof lname - 1 - 6] = 0 ;
|
||||
strcat( lname, ".lock~") ;
|
||||
if (unlink(lname) != 0) {
|
||||
if (errno == EACCES || errno == ENOENT)
|
||||
return NULL;
|
||||
@@ -127,4 +132,9 @@ char *undolock( const char *fname)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
typedef void _pedantic_empty_translation_unit ;
|
||||
#endif
|
||||
|
||||
/* end of pklock.c */
|
||||
|
||||
6
posix.c
6
posix.c
@@ -250,4 +250,8 @@ int typahead(void)
|
||||
return x;
|
||||
}
|
||||
|
||||
#endif /* POSIX */
|
||||
#else
|
||||
typedef void _pedantic_empty_translation_unit ;
|
||||
#endif /* not POSIX */
|
||||
|
||||
/* end of posix.c */
|
||||
|
||||
446
random.c
446
random.c
@@ -1,8 +1,6 @@
|
||||
/* random.c -- implements random.h */
|
||||
#include "random.h"
|
||||
|
||||
#define NBRACE 1 /* new style brace matching command */
|
||||
|
||||
/* random.c
|
||||
*
|
||||
* This file contains the command processing functions for a number of
|
||||
@@ -40,7 +38,7 @@ static const char *cname[] = { /* names of colors */
|
||||
int gfcolor = NCOLORS - 1 ; /* global forgrnd color (white) */
|
||||
int gbcolor = 0 ; /* global backgrnd color (black) */
|
||||
|
||||
static int tabsize ; /* Tab size (0: use real tabs) */
|
||||
boolean hardtab = TRUE ; /* use hard tab instead of soft tab */
|
||||
int fillcol = 72 ; /* Current fill column */
|
||||
|
||||
/* uninitialized global definitions */
|
||||
@@ -179,12 +177,13 @@ int getccol(int bflg)
|
||||
if( bflg && c != ' ' && c != '\t') /* Request Stop at first non-blank */
|
||||
break;
|
||||
if (c == '\t')
|
||||
col |= tabmask;
|
||||
col += tabwidth - col % tabwidth ;
|
||||
else if (c < 0x20 || c == 0x7F) /* displayed as ^c */
|
||||
++col;
|
||||
col += 2 ;
|
||||
else if (c >= 0x80 && c <= 0xa0) /* displayed as \xx */
|
||||
col += 2;
|
||||
++col;
|
||||
col += 3 ;
|
||||
else
|
||||
col += 1 ;
|
||||
}
|
||||
return col;
|
||||
}
|
||||
@@ -213,10 +212,11 @@ int setccol(int pos)
|
||||
/* advance one character */
|
||||
c = lgetc(curwp->w_dotp, i);
|
||||
if (c == '\t')
|
||||
col |= tabmask;
|
||||
col += tabwidth - col % tabwidth ;
|
||||
else if (c < 0x20 || c == 0x7F)
|
||||
++col;
|
||||
++col;
|
||||
col += 2 ;
|
||||
else
|
||||
col += 1 ;
|
||||
}
|
||||
|
||||
/* set us at the new position */
|
||||
@@ -290,17 +290,21 @@ int quote(int f, int n)
|
||||
* done in this slightly funny way because the tab (in ASCII) has been turned
|
||||
* into "C-I" (in 10 bit code) already. Bound to "C-I".
|
||||
*/
|
||||
int insert_tab(int f, int n)
|
||||
{
|
||||
if (n < 0)
|
||||
return FALSE;
|
||||
if (n == 0 || n > 1) {
|
||||
tabsize = n;
|
||||
return TRUE;
|
||||
}
|
||||
if (!tabsize)
|
||||
return linsert(1, '\t');
|
||||
return linsert(tabsize - (getccol(FALSE) % tabsize), ' ');
|
||||
int insert_tab( int f, int n) {
|
||||
int status ;
|
||||
|
||||
if( n < 0)
|
||||
status = FALSE ;
|
||||
else if( n == 0)
|
||||
status = TRUE ;
|
||||
else if( hardtab == TRUE)
|
||||
status = linsert( n, '\t') ;
|
||||
else /* softtab */
|
||||
do {
|
||||
status = linsert( tabwidth - getccol( FALSE) % tabwidth, ' ') ;
|
||||
} while( status != FALSE && --n) ;
|
||||
|
||||
return status ;
|
||||
}
|
||||
|
||||
#if AEDIT
|
||||
@@ -329,10 +333,9 @@ int detab(int f, int n)
|
||||
/* if we have a tab */
|
||||
if (lgetc(curwp->w_dotp, curwp->w_doto) == '\t') {
|
||||
ldelchar(1, FALSE);
|
||||
insspace(TRUE,
|
||||
(tabmask + 1) -
|
||||
(curwp->w_doto & tabmask));
|
||||
insspace( TRUE, tabwidth - curwp->w_doto % tabwidth);
|
||||
}
|
||||
|
||||
forwchar(FALSE, 1);
|
||||
}
|
||||
|
||||
@@ -353,7 +356,7 @@ int detab(int f, int n)
|
||||
*/
|
||||
int entab(int f, int n)
|
||||
{
|
||||
#define nextab(a) (a & ~tabmask) + (tabmask+1)
|
||||
#define nextab(a) (a + tabwidth - a % tabwidth)
|
||||
|
||||
int inc; /* increment to next line [sgn(n)] */
|
||||
int fspace; /* pointer to first space if in a run */
|
||||
@@ -497,8 +500,6 @@ int openline(int f, int n)
|
||||
*/
|
||||
int insert_newline(int f, int n)
|
||||
{
|
||||
int s;
|
||||
|
||||
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||
return rdonly(); /* we are in read only mode */
|
||||
if (n < 0)
|
||||
@@ -521,6 +522,8 @@ int insert_newline(int f, int n)
|
||||
|
||||
/* insert some lines */
|
||||
while (n--) {
|
||||
int s ;
|
||||
|
||||
if ((s = lnewline()) != TRUE)
|
||||
return s;
|
||||
#if SCROLLCODE
|
||||
@@ -535,197 +538,59 @@ static int cinsert(void)
|
||||
char *cptr; /* string pointer into text to copy */
|
||||
int tptr; /* index to scan into line */
|
||||
int bracef; /* was there a brace at the end of line? */
|
||||
int i;
|
||||
char ichar[NSTRING]; /* buffer to hold indent of last line */
|
||||
int i, nicol ;
|
||||
|
||||
/* grab a pointer to text to copy indentation from */
|
||||
cptr = &curwp->w_dotp->l_text[0];
|
||||
|
||||
/* check for a brace */
|
||||
tptr = curwp->w_doto - 1;
|
||||
bracef = (cptr[tptr] == '{');
|
||||
tptr = curwp->w_doto ;
|
||||
bracef = (tptr > 0) && (cptr[ tptr - 1] == '{') ;
|
||||
|
||||
/* save the indent of the previous line */
|
||||
i = 0;
|
||||
while ((i < tptr) && (cptr[i] == ' ' || cptr[i] == '\t')
|
||||
&& (i < NSTRING - 1)) {
|
||||
ichar[i] = cptr[i];
|
||||
++i;
|
||||
nicol = 0 ;
|
||||
for( i = 0 ; i < tptr ; i += 1) {
|
||||
int ch ;
|
||||
|
||||
ch = cptr[ i] ;
|
||||
if( ch == ' ')
|
||||
nicol += 1 ;
|
||||
else if( ch == '\t')
|
||||
nicol += tabwidth - nicol % tabwidth ;
|
||||
else
|
||||
break ;
|
||||
}
|
||||
ichar[i] = 0; /* terminate it */
|
||||
|
||||
if( i == tptr) { /* all line is blank */
|
||||
curwp->w_doto = 0 ; /* gotobol */
|
||||
lnewline() ;
|
||||
curwp->w_doto = tptr ; /* gotoeol */
|
||||
} else {
|
||||
/* put in the newline */
|
||||
if (lnewline() == FALSE)
|
||||
return FALSE;
|
||||
if (lnewline() == FALSE)
|
||||
return FALSE;
|
||||
|
||||
/* and the saved indentation */
|
||||
linstr(ichar);
|
||||
i = nicol % tabwidth ; /* spaces */
|
||||
nicol /= tabwidth ; /* tabs */
|
||||
if( bracef) {
|
||||
/* and one more tab for a brace */
|
||||
nicol += 1 ;
|
||||
i = 0 ;
|
||||
}
|
||||
|
||||
/* and one more tab for a brace */
|
||||
if (bracef)
|
||||
insert_tab(FALSE, 1);
|
||||
if( nicol > 0)
|
||||
insert_tab( FALSE, nicol) ;
|
||||
|
||||
if( i > 0)
|
||||
linsert( i, ' ') ;
|
||||
}
|
||||
#if SCROLLCODE
|
||||
curwp->w_flag |= WFINS;
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if NBRACE
|
||||
/*
|
||||
* insert a brace into the text here...we are in CMODE
|
||||
*
|
||||
* int n; repeat count
|
||||
* int c; brace to insert (always } for now)
|
||||
*/
|
||||
int insbrace(int n, int c)
|
||||
{
|
||||
int ch; /* last character before input */
|
||||
int oc; /* caractere oppose a c */
|
||||
int i, count;
|
||||
int target; /* column brace should go after */
|
||||
struct line *oldlp;
|
||||
int oldoff;
|
||||
|
||||
/* if we aren't at the beginning of the line... */
|
||||
if (curwp->w_doto != 0)
|
||||
|
||||
/* scan to see if all space before this is white space */
|
||||
for (i = curwp->w_doto - 1; i >= 0; --i) {
|
||||
ch = lgetc(curwp->w_dotp, i);
|
||||
if (ch != ' ' && ch != '\t')
|
||||
return linsert(n, c);
|
||||
}
|
||||
|
||||
/* chercher le caractere oppose correspondant */
|
||||
switch (c) {
|
||||
case '}':
|
||||
oc = '{';
|
||||
break;
|
||||
case ']':
|
||||
oc = '[';
|
||||
break;
|
||||
case ')':
|
||||
oc = '(';
|
||||
break;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
oldlp = curwp->w_dotp;
|
||||
oldoff = curwp->w_doto;
|
||||
|
||||
count = 1;
|
||||
backchar(FALSE, 1);
|
||||
|
||||
while (count > 0) {
|
||||
if (curwp->w_doto == llength(curwp->w_dotp))
|
||||
ch = '\n';
|
||||
else
|
||||
ch = lgetc(curwp->w_dotp, curwp->w_doto);
|
||||
|
||||
if (ch == c)
|
||||
++count;
|
||||
if (ch == oc)
|
||||
--count;
|
||||
|
||||
backchar(FALSE, 1);
|
||||
if (boundry(curwp->w_dotp, curwp->w_doto, REVERSE))
|
||||
break;
|
||||
}
|
||||
|
||||
if (count != 0) { /* no match */
|
||||
curwp->w_dotp = oldlp;
|
||||
curwp->w_doto = oldoff;
|
||||
return linsert(n, c);
|
||||
}
|
||||
|
||||
curwp->w_doto = 0; /* debut de ligne */
|
||||
/* aller au debut de la ligne apres la tabulation */
|
||||
while ((ch = lgetc(curwp->w_dotp, curwp->w_doto)) == ' '
|
||||
|| ch == '\t')
|
||||
forwchar(FALSE, 1);
|
||||
|
||||
/* delete back first */
|
||||
target = getccol(FALSE); /* c'est l'indent que l'on doit avoir */
|
||||
curwp->w_dotp = oldlp;
|
||||
curwp->w_doto = oldoff;
|
||||
|
||||
while (target != getccol(FALSE)) {
|
||||
if (target < getccol(FALSE)) /* on doit detruire des caracteres */
|
||||
while (getccol(FALSE) > target)
|
||||
backdel(FALSE, 1);
|
||||
else { /* on doit en inserer */
|
||||
while (target - getccol(FALSE) >= 8)
|
||||
linsert(1, '\t');
|
||||
linsert(target - getccol(FALSE), ' ');
|
||||
}
|
||||
}
|
||||
|
||||
/* and insert the required brace(s) */
|
||||
return linsert(n, c);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* insert a brace into the text here...we are in CMODE
|
||||
*
|
||||
* int n; repeat count
|
||||
* int c; brace to insert (always { for now)
|
||||
*/
|
||||
int insbrace(int n, int c)
|
||||
{
|
||||
int ch; /* last character before input */
|
||||
int i;
|
||||
int target; /* column brace should go after */
|
||||
|
||||
/* if we are at the beginning of the line, no go */
|
||||
if (curwp->w_doto == 0)
|
||||
return linsert(n, c);
|
||||
|
||||
/* scan to see if all space before this is white space */
|
||||
for (i = curwp->w_doto - 1; i >= 0; --i) {
|
||||
ch = lgetc(curwp->w_dotp, i);
|
||||
if (ch != ' ' && ch != '\t')
|
||||
return linsert(n, c);
|
||||
}
|
||||
|
||||
/* delete back first */
|
||||
target = getccol(FALSE); /* calc where we will delete to */
|
||||
target -= 1;
|
||||
target -= target % (tabsize == 0 ? 8 : tabsize);
|
||||
while (getccol(FALSE) > target)
|
||||
backdel(FALSE, 1);
|
||||
|
||||
/* and insert the required brace(s) */
|
||||
return linsert(n, c);
|
||||
}
|
||||
#endif
|
||||
|
||||
int inspound(void)
|
||||
{ /* insert a # into the text here...we are in CMODE */
|
||||
int ch; /* last character before input */
|
||||
int i;
|
||||
|
||||
/* if we are at the beginning of the line, no go */
|
||||
if (curwp->w_doto == 0)
|
||||
return linsert(1, '#');
|
||||
|
||||
/* scan to see if all space before this is white space */
|
||||
for (i = curwp->w_doto - 1; i >= 0; --i) {
|
||||
ch = lgetc(curwp->w_dotp, i);
|
||||
if (ch != ' ' && ch != '\t')
|
||||
return linsert(1, '#');
|
||||
}
|
||||
|
||||
/* delete back first */
|
||||
while (getccol(FALSE) >= 1)
|
||||
backdel(FALSE, 1);
|
||||
|
||||
/* and insert the required pound */
|
||||
return linsert(1, '#');
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete blank lines around dot. What this command does depends if dot is
|
||||
@@ -759,38 +624,45 @@ int deblank(int f, int n)
|
||||
|
||||
/*
|
||||
* Insert a newline, then enough tabs and spaces to duplicate the indentation
|
||||
* of the previous line. Assumes tabs are every eight characters. Quite simple.
|
||||
* of the previous line. Assumes tabs are every tabwidth characters.
|
||||
* Figure out the indentation of the current line. Insert a newline by calling
|
||||
* the standard routine. Insert the indentation by inserting the right number
|
||||
* of tabs and spaces. Return TRUE if all ok. Return FALSE if one of the
|
||||
* subcomands failed. Normally bound to "C-J".
|
||||
*/
|
||||
int indent(int f, int n)
|
||||
{
|
||||
int nicol;
|
||||
int c;
|
||||
int i;
|
||||
int indent( int f, int n) {
|
||||
int nicol ;
|
||||
int i ;
|
||||
|
||||
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||
return rdonly(); /* we are in read only mode */
|
||||
if (n < 0)
|
||||
return FALSE;
|
||||
while (n--) {
|
||||
nicol = 0;
|
||||
for (i = 0; i < llength(curwp->w_dotp); ++i) {
|
||||
c = lgetc(curwp->w_dotp, i);
|
||||
if (c != ' ' && c != '\t')
|
||||
break;
|
||||
if (c == '\t')
|
||||
nicol |= tabmask;
|
||||
++nicol;
|
||||
}
|
||||
if (lnewline() == FALSE
|
||||
|| ((i = nicol / 8) != 0 && linsert(i, '\t') == FALSE)
|
||||
|| ((i = nicol % 8) != 0 && linsert(i, ' ') == FALSE))
|
||||
return FALSE;
|
||||
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
|
||||
return rdonly() ; /* we are in read only mode */
|
||||
|
||||
if( n < 0)
|
||||
return FALSE ;
|
||||
|
||||
/* number of columns to indent */
|
||||
nicol = 0 ;
|
||||
for( i = 0 ; i < llength( curwp->w_dotp) ; i += 1) {
|
||||
int c ;
|
||||
|
||||
c = lgetc( curwp->w_dotp, i) ;
|
||||
if( c == '\t')
|
||||
nicol += tabwidth - nicol % tabwidth ;
|
||||
else if( c == ' ')
|
||||
nicol += 1 ;
|
||||
else
|
||||
break ;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
i = nicol / tabwidth ; /* # of tab to insert */
|
||||
nicol %= tabwidth ; /* # of space to insert */
|
||||
while( n--)
|
||||
if( lnewline() == FALSE
|
||||
|| ( i != 0 && insert_tab( FALSE, i) == FALSE)
|
||||
|| ( nicol != 0 && linsert( nicol, ' ') == FALSE))
|
||||
return FALSE ;
|
||||
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1077,115 +949,39 @@ int getfence(int f, int n)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* set up for scan */
|
||||
count = 1;
|
||||
if (sdir == REVERSE)
|
||||
backchar(FALSE, 1);
|
||||
else
|
||||
forwchar(FALSE, 1);
|
||||
/* scan until we find a match, or reach the end of file */
|
||||
count = 1 ;
|
||||
do {
|
||||
if( boundry( curwp->w_dotp, curwp->w_doto, sdir)) {
|
||||
/* at buffer limit, no match to be found */
|
||||
/* restore the current position */
|
||||
curwp->w_dotp = oldlp ;
|
||||
curwp->w_doto = oldoff ;
|
||||
TTbeep() ;
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
/* scan until we find it, or reach the end of file */
|
||||
while (count > 0) {
|
||||
if (curwp->w_doto == llength(curwp->w_dotp))
|
||||
c = '\n';
|
||||
if( sdir == FORWARD)
|
||||
forwchar( FALSE, 1) ;
|
||||
else
|
||||
c = lgetc(curwp->w_dotp, curwp->w_doto);
|
||||
if (c == ch)
|
||||
++count;
|
||||
if (c == ofence)
|
||||
--count;
|
||||
if (sdir == FORWARD)
|
||||
forwchar(FALSE, 1);
|
||||
else
|
||||
backchar(FALSE, 1);
|
||||
if (boundry(curwp->w_dotp, curwp->w_doto, sdir))
|
||||
break;
|
||||
}
|
||||
backchar( FALSE, 1) ;
|
||||
|
||||
/* if count is zero, we have a match, move the sucker */
|
||||
if (count == 0) {
|
||||
if (sdir == FORWARD)
|
||||
backchar(FALSE, 1);
|
||||
else
|
||||
forwchar(FALSE, 1);
|
||||
curwp->w_flag |= WFMOVE;
|
||||
return TRUE;
|
||||
}
|
||||
/* if no eol */
|
||||
if( curwp->w_doto != llength(curwp->w_dotp)) {
|
||||
c = lgetc( curwp->w_dotp, curwp->w_doto) ;
|
||||
if( c == ch)
|
||||
++count ;
|
||||
else if( c == ofence)
|
||||
--count ;
|
||||
}
|
||||
} while( count > 0) ;
|
||||
|
||||
/* restore the current position */
|
||||
curwp->w_dotp = oldlp;
|
||||
curwp->w_doto = oldoff;
|
||||
TTbeep();
|
||||
return FALSE;
|
||||
/* we have a match, move the sucker */
|
||||
curwp->w_flag |= WFMOVE ;
|
||||
return TRUE ;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Close fences are matched against their partners, and if
|
||||
* on screen the cursor briefly lights there
|
||||
*
|
||||
* char ch; fence type to match against
|
||||
*/
|
||||
int fmatch(int ch)
|
||||
{
|
||||
struct line *oldlp; /* original line pointer */
|
||||
int oldoff; /* and offset */
|
||||
struct line *toplp; /* top line in current window */
|
||||
int count; /* current fence level count */
|
||||
char opench; /* open fence */
|
||||
char c; /* current character in scan */
|
||||
int i;
|
||||
|
||||
/* first get the display update out there */
|
||||
update(FALSE);
|
||||
|
||||
/* save the original cursor position */
|
||||
oldlp = curwp->w_dotp;
|
||||
oldoff = curwp->w_doto;
|
||||
|
||||
/* setup proper open fence for passed close fence */
|
||||
if (ch == ')')
|
||||
opench = '(';
|
||||
else if (ch == '}')
|
||||
opench = '{';
|
||||
else
|
||||
opench = '[';
|
||||
|
||||
/* find the top line and set up for scan */
|
||||
toplp = curwp->w_linep->l_bp;
|
||||
count = 1;
|
||||
backchar(FALSE, 2);
|
||||
|
||||
/* scan back until we find it, or reach past the top of the window */
|
||||
while (count > 0 && curwp->w_dotp != toplp) {
|
||||
if (curwp->w_doto == llength(curwp->w_dotp))
|
||||
c = '\n';
|
||||
else
|
||||
c = lgetc(curwp->w_dotp, curwp->w_doto);
|
||||
if (c == ch)
|
||||
++count;
|
||||
if (c == opench)
|
||||
--count;
|
||||
backchar(FALSE, 1);
|
||||
if (curwp->w_dotp == curwp->w_bufp->b_linep->l_fp &&
|
||||
curwp->w_doto == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
/* if count is zero, we have a match, display the sucker */
|
||||
/* there is a real machine dependant timing problem here we have
|
||||
yet to solve......... */
|
||||
if (count == 0) {
|
||||
forwchar(FALSE, 1);
|
||||
for (i = 0; i < term.t_pause; i++)
|
||||
update(FALSE);
|
||||
}
|
||||
|
||||
/* restore the current position */
|
||||
curwp->w_dotp = oldlp;
|
||||
curwp->w_doto = oldoff;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int iovstring( int f, int n, const char *prompt, int (*fun)( char *)) {
|
||||
int status ; /* status return code */
|
||||
|
||||
8
random.h
8
random.h
@@ -1,9 +1,14 @@
|
||||
#ifndef _RANDOM_H_
|
||||
#define _RANDOM_H_
|
||||
|
||||
|
||||
#include "retcode.h"
|
||||
|
||||
|
||||
#define AEDIT 1
|
||||
|
||||
extern int fillcol ; /* Fill column */
|
||||
extern boolean hardtab ; /* Use hard tab instead of soft tab */
|
||||
|
||||
|
||||
/* Uninitialized global external declarations. */
|
||||
@@ -29,8 +34,6 @@ int trim( int f, int n) ;
|
||||
#endif
|
||||
int openline( int f, int n) ;
|
||||
int insert_newline( int f, int n) ;
|
||||
int insbrace( int n, int c) ;
|
||||
int inspound( void) ;
|
||||
int deblank( int f, int n) ;
|
||||
int indent( int f, int n) ;
|
||||
int forwdel( int f, int n) ;
|
||||
@@ -41,7 +44,6 @@ int delmode( int f, int n) ;
|
||||
int setgmode( int f, int n) ;
|
||||
int delgmode( int f, int n) ;
|
||||
int getfence( int f, int n) ;
|
||||
int fmatch( int ch) ;
|
||||
int istring( int f, int n) ;
|
||||
int ovstring( int f, int n) ;
|
||||
|
||||
|
||||
4
termio.c
4
termio.c
@@ -463,4 +463,8 @@ int typahead( void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
typedef void _pedantic_empty_translation_unit ;
|
||||
#endif /* not POSIX */
|
||||
|
||||
/* end of termio.c */
|
||||
|
||||
@@ -28,17 +28,14 @@ insert-string 123456789012345678901234567890123456789012345678901234567890123456
|
||||
next-line
|
||||
insert-string _________1_________2_________3_________4_________5_________6_________7_________8_________9_________0_________1_________2_________3
|
||||
next-line
|
||||
; Create and insert string variable until size exceed string limit [will be truncated to NSTRING - 1 (127)
|
||||
; Create and insert string variable until size exceed 1024 characters or variable get truncated
|
||||
set %nam 123
|
||||
set %expect &len %nam
|
||||
!while &equ &len %nam %expect
|
||||
!while &and &les %expect 1024 &equ &len %nam %expect
|
||||
insert-string %nam
|
||||
newline
|
||||
set %nam &cat %nam %nam
|
||||
set %expect &tim %expect 2
|
||||
!if ¬ &les %expect 1024
|
||||
!break
|
||||
!endif
|
||||
!endwhile
|
||||
insert-string %nam
|
||||
newline
|
||||
@@ -47,6 +44,7 @@ newline
|
||||
insert-string &cat "Expected: " %expect
|
||||
newline
|
||||
; Use the variable as filename [will be truncated to NFILEN - 1 (79)]
|
||||
set %nam &mid %nam 1 255
|
||||
write-file %nam
|
||||
insert-string &cat "Filename: " $cfname
|
||||
newline
|
||||
@@ -71,3 +69,4 @@ set-mark
|
||||
end-of-file
|
||||
copy-region
|
||||
insert-string $kill
|
||||
redraw-display
|
||||
|
||||
Reference in New Issue
Block a user