1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-18 23:36:23 -05:00

Merge remote-tracking branch 'origin/cigue'

This commit is contained in:
Renaud 2014-12-24 09:49:30 +08:00
commit 3a67809c74
85 changed files with 5645 additions and 4586 deletions

191
Makefile
View File

@ -1,4 +1,10 @@
# makefile for emacs, updated Sun Apr 28 17:59:07 EET DST 1996 # Makefile for emacs, updated Mon, Nov 17, 2014 1:05:02 PM
SRC=ansi.c basic.c bind.c bindable.c buffer.c crypt.c display.c ebind.c eval.c exec.c execute.c file.c fileio.c flook.c ibmpc.c input.c isearch.c line.c lock.c log.c main.c mingw32.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c vmsvt.c vt52.c window.c word.c wrapper.c wscreen.c
OBJ=ansi.o basic.o bind.o bindable.o buffer.o crypt.o display.o ebind.o eval.o exec.o execute.o file.o fileio.o flook.o ibmpc.o input.o isearch.o line.o lock.o log.o main.o mingw32.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o vmsvt.o vt52.o window.o word.o wrapper.o 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 log.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
# Make the build silent by default # Make the build silent by default
V = V =
@ -14,23 +20,7 @@ export E Q
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
PROGRAM=em PROGRAM=ue
SRC=ansi.c basic.c bind.c buffer.c crypt.c display.c eval.c exec.c \
file.c fileio.c ibmpc.c input.c isearch.c line.c lock.c main.c \
pklock.c posix.c random.c region.c search.c spawn.c tcap.c \
termio.c vmsvt.c vt52.c window.c word.c names.c globals.c version.c \
usage.c wrapper.c utf8.c
OBJ=ansi.o basic.o bind.o buffer.o crypt.o display.o eval.o exec.o \
file.o fileio.o ibmpc.o input.o isearch.o line.o lock.o main.o \
pklock.o posix.o random.o region.o search.o spawn.o tcap.o \
termio.o vmsvt.o vt52.o window.o word.o names.o globals.o version.o \
usage.o wrapper.o utf8.o
HDR=ebind.h edef.h efunc.h epath.h estruct.h evar.h util.h version.h
# DO NOT ADD OR MODIFY ANY LINES ABOVE THIS -- make source creates them
CC=gcc CC=gcc
WARNINGS=-Wall -Wstrict-prototypes WARNINGS=-Wall -Wstrict-prototypes
@ -48,9 +38,21 @@ endif
ifeq ($(uname_S),Darwin) ifeq ($(uname_S),Darwin)
DEFINES=-DAUTOCONF -DPOSIX -DSYSV -D_DARWIN_C_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600 DEFINES=-DAUTOCONF -DPOSIX -DSYSV -D_DARWIN_C_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600
endif endif
ifeq ($(uname_S),CYGWIN_NT-6.1-WOW64)
DEFINES=-DAUTOCONF -DCYGWIN -DPROGRAM=$(PROGRAM)
LIBS=-lcurses # SYSV
endif
ifeq ($(uname_S),CYGWIN_NT-6.1)
DEFINES=-DAUTOCONF -DCYGWIN -DPROGRAM=$(PROGRAM)
LIBS=-lcurses # SYSV
endif
ifeq ($(uname_S),MINGW32_NT-6.1)
DEFINES=-DAUTOCONF -DSYSV -DMINGW32 -DPROGRAM=$(PROGRAM)
LIBS=
endif
#DEFINES=-DAUTOCONF #DEFINES=-DAUTOCONF
#LIBS=-ltermcap # BSD #LIBS=-ltermcap # BSD
LIBS=-lcurses # SYSV #LIBS=-lcurses # SYSV
#LIBS=-ltermlib #LIBS=-ltermlib
#LIBS=-L/usr/lib/termcap -ltermcap #LIBS=-L/usr/lib/termcap -ltermcap
LFLAGS=-hbx LFLAGS=-hbx
@ -69,14 +71,14 @@ sparse:
clean: clean:
$(E) " CLEAN" $(E) " CLEAN"
$(Q) rm -f $(PROGRAM) core lintout makeout tags makefile.bak *.o $(Q) rm -f $(PROGRAM) core lintout makeout tags Makefile.bak *.o
install: $(PROGRAM) install: $(PROGRAM)
strip $(PROGRAM) strip $(PROGRAM)
cp em ${BINDIR} cp $(PROGRAM) ${BINDIR}
cp emacs.hlp ${LIBDIR} cp emacs.hlp ${LIBDIR}
cp emacs.rc ${LIBDIR}/.emacsrc cp emacs.rc ${LIBDIR}/.emacsrc
chmod 755 ${BINDIR}/em chmod 755 ${BINDIR}/$(PROGRAM)
chmod 644 ${LIBDIR}/emacs.hlp ${LIBDIR}/.emacsrc chmod 644 ${LIBDIR}/emacs.hlp ${LIBDIR}/.emacsrc
lint: ${SRC} lint: ${SRC}
@ -86,40 +88,43 @@ lint: ${SRC}
errs: errs:
@rm -f makeout @rm -f makeout
make em >makeout make $(PROGRAM) >makeout
tags: ${SRC} tags: ${SRC}
@rm -f tags @rm -f tags
ctags ${SRC} ctags ${SRC}
source: source:
@mv makefile makefile.bak @mv Makefile Makefile.bak
@echo "# makefile for emacs, updated `date`" >makefile @echo "# Makefile for emacs, updated `date`" >Makefile
@echo '' >>makefile @echo '' >>Makefile
@echo SRC=`ls *.c` >>makefile @echo SRC=`ls *.c` >>Makefile
@echo OBJ=`ls *.c | sed s/c$$/o/` >>makefile @echo OBJ=`ls *.c | sed s/c$$/o/` >>Makefile
@echo HDR=`ls *.h` >>makefile @echo HDR=`ls *.h` >>Makefile
@echo '' >>makefile @echo '' >>Makefile
@sed -n -e '/^# DO NOT ADD OR MODIFY/,$$p' <makefile.bak >>makefile @sed -n -e '/^# DO NOT ADD OR MODIFY/,$$p' <Makefile.bak >>Makefile
depend: ${SRC} depend: ${SRC}
@for i in ${SRC}; do\ @for i in ${SRC}; do\
cc ${DEFINES} -M $$i | sed -e 's, \./, ,' | grep -v '/usr/include' | \ cc ${DEFINES} -MM $$i ; done >makedep
awk '{ if ($$1 != prev) { if (rec != "") print rec; \
rec = $$0; prev = $$1; } \
else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
else rec = rec " " $$2 } } \
END { print rec }'; done >makedep
@echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep @echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
@echo '$$r ./makedep' >>eddep @echo '$$r ./makedep' >>eddep
@echo 'w' >>eddep @echo 'w' >>eddep
@cp makefile makefile.bak @cp Makefile Makefile.bak
@ed - makefile <eddep @ed - Makefile <eddep
@rm eddep makedep @rm eddep makedep
@echo '' >>makefile @echo '' >>Makefile
@echo '# DEPENDENCIES MUST END AT END OF FILE' >>makefile @echo '# DEPENDENCIES MUST END AT END OF FILE' >>Makefile
@echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >>makefile @echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >>Makefile
@echo '# see make depend above' >>makefile @echo '# see make depend above' >>Makefile
# @for i in ${SRC}; do\
# cc ${DEFINES} -M $$i | sed -e 's, \./, ,' | grep -v '/usr/include' | \
# awk '{ if ($$1 != prev) { if (rec != "") print rec; \
# rec = $$0; prev = $$1; } \
# else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
# else rec = rec " " $$2 } } \
# END { print rec }'; done >makedep
.c.o: .c.o:
$(E) " CC " $@ $(E) " CC " $@
@ -127,35 +132,79 @@ depend: ${SRC}
# DO NOT DELETE THIS LINE -- make depend uses it # DO NOT DELETE THIS LINE -- make depend uses it
ansi.o: ansi.c estruct.h edef.h ansi.o: ansi.c estruct.h
basic.o: basic.c estruct.h edef.h basic.o: basic.c basic.h buffer.h crypt.h line.h utf8.h display.h \
bind.o: bind.c estruct.h edef.h epath.h estruct.h input.h bind.h random.h terminal.h defines.h retcode.h \
buffer.o: buffer.c estruct.h edef.h window.h
crypt.o: crypt.c estruct.h edef.h bind.o: bind.c bind.h estruct.h bindable.h buffer.h crypt.h line.h utf8.h \
display.o: display.c estruct.h edef.h utf8.h display.h ebind.h exec.h retcode.h file.h flook.h input.h names.h \
eval.o: eval.c estruct.h edef.h evar.h window.h defines.h
exec.o: exec.c estruct.h edef.h bindable.o: bindable.c bindable.h defines.h buffer.h crypt.h line.h \
file.o: file.c estruct.h edef.h utf8.h display.h estruct.h file.h retcode.h input.h bind.h lock.h \
fileio.o: fileio.c estruct.h edef.h terminal.h
ibmpc.o: ibmpc.c estruct.h edef.h buffer.o: buffer.c buffer.h crypt.h line.h utf8.h defines.h display.h \
input.o: input.c estruct.h edef.h estruct.h file.h retcode.h input.h bind.h window.h
isearch.o: isearch.c estruct.h edef.h crypt.o: crypt.c crypt.h
line.o: line.c estruct.h edef.h display.o: display.c display.h buffer.h crypt.h line.h utf8.h estruct.h \
lock.o: lock.c estruct.h edef.h input.h bind.h termio.h terminal.h defines.h retcode.h version.h \
main.o: main.c estruct.h efunc.h edef.h ebind.h wrapper.h window.h
pklock.o: pklock.c estruct.h ebind.o: ebind.c ebind.h basic.h bind.h estruct.h bindable.h buffer.h \
posix.o: posix.c estruct.h utf8.h crypt.h line.h utf8.h eval.h exec.h retcode.h file.h isearch.h random.h \
random.o: random.c estruct.h edef.h region.h search.h spawn.h window.h defines.h word.h
region.o: region.c estruct.h edef.h eval.o: eval.c eval.h basic.h bind.h buffer.h crypt.h line.h utf8.h \
search.o: search.c estruct.h edef.h display.h estruct.h exec.h retcode.h execute.h flook.h input.h random.h \
spawn.o: spawn.c estruct.h edef.h search.h terminal.h defines.h termio.h version.h window.h
tcap.o: tcap.c estruct.h edef.h exec.o: exec.c exec.h retcode.h buffer.h crypt.h line.h utf8.h bind.h \
termio.o: termio.c estruct.h edef.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 display.h file.h \
buffer.h crypt.h line.h utf8.h retcode.h terminal.h defines.h window.h
file.o: file.c file.h buffer.h crypt.h line.h utf8.h retcode.h defines.h \
estruct.h execute.h fileio.h input.h bind.h lock.h log.h window.h
fileio.o: fileio.c fileio.h crypt.h retcode.h defines.h
flook.o: flook.c flook.h retcode.h defines.h fileio.h crypt.h
ibmpc.o: ibmpc.c estruct.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 wrapper.h
isearch.o: isearch.c isearch.h basic.h buffer.h crypt.h line.h utf8.h \
display.h estruct.h exec.h retcode.h input.h bind.h search.h terminal.h \
defines.h window.h
line.o: line.c line.h utf8.h buffer.h crypt.h estruct.h log.h retcode.h \
window.h defines.h
lock.o: lock.c estruct.h lock.h
log.o: log.c log.h retcode.h
main.o: main.c estruct.h basic.h bind.h bindable.h buffer.h crypt.h \
line.h utf8.h display.h eval.h execute.h file.h retcode.h input.h lock.h \
log.h random.h search.h terminal.h defines.h termio.h version.h window.h
mingw32.o: mingw32.c
names.o: names.c names.h basic.h bind.h bindable.h buffer.h crypt.h \
line.h utf8.h display.h eval.h exec.h retcode.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
random.o: random.c random.h basic.h buffer.h crypt.h line.h utf8.h \
display.h estruct.h execute.h input.h bind.h log.h retcode.h search.h \
terminal.h defines.h window.h
region.o: region.c region.h line.h utf8.h buffer.h crypt.h estruct.h \
log.h retcode.h random.h window.h defines.h
search.o: search.c search.h line.h utf8.h basic.h buffer.h crypt.h \
display.h estruct.h input.h bind.h log.h retcode.h terminal.h defines.h \
window.h
spawn.o: spawn.c spawn.h defines.h buffer.h crypt.h line.h utf8.h \
display.h estruct.h exec.h retcode.h file.h flook.h input.h bind.h log.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.h estruct.h retcode.h utf8.h
utf8.o: utf8.c utf8.h utf8.o: utf8.c utf8.h
vmsvt.o: vmsvt.c estruct.h edef.h vmsvt.o: vmsvt.c estruct.h
vt52.o: vt52.c estruct.h edef.h vt52.o: vt52.c estruct.h
window.o: window.c estruct.h edef.h window.o: window.c window.h defines.h buffer.h crypt.h line.h utf8.h \
word.o: word.c estruct.h edef.h basic.h display.h estruct.h execute.h terminal.h retcode.h wrapper.h
word.o: word.c word.h basic.h buffer.h crypt.h line.h utf8.h estruct.h \
log.h retcode.h random.h region.h window.h defines.h
wrapper.o: wrapper.c wrapper.h
wscreen.o: wscreen.c wscreen.h
# DEPENDENCIES MUST END AT END OF FILE # DEPENDENCIES MUST END AT END OF FILE
# IF YOU PUT STUFF HERE IT WILL GO AWAY # IF YOU PUT STUFF HERE IT WILL GO AWAY

29
README.md Normal file
View File

@ -0,0 +1,29 @@
# README #
Cigue is ue on Cygwin, based on uEmacs/PK from kernel.org.
### What is this repository for? ###
* Quick summary
* Version
* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo)
### How do I get set up? ###
* Summary of set up
* Configuration
* Dependencies
* Database configuration
* How to run tests
* Deployment instructions
### Contribution guidelines ###
* Writing tests
* Code review
* Other guidelines
### Who do I talk to? ###
* Repo owner or admin
* Other community or team contact

2
ansi.c
View File

@ -11,7 +11,7 @@
#include <stdio.h> #include <stdio.h>
#include "estruct.h" #include "estruct.h"
#include "edef.h"
#if ANSI #if ANSI

183
basic.c
View File

@ -1,3 +1,9 @@
/* basic.c -- implements basic.h */
#include "basic.h"
#define CVMVAS 1 /* arguments to page forward/back in pages */
/* basic.c /* basic.c
* *
* The routines in this file move the cursor around on the screen. They * The routines in this file move the cursor around on the screen. They
@ -10,12 +16,22 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "buffer.h"
#include "display.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "input.h"
#include "efunc.h"
#include "line.h" #include "line.h"
#include "random.h"
#include "terminal.h"
#include "utf8.h" #include "utf8.h"
#include "window.h"
int overlap = 0 ; /* line overlap in forw/back page */
int curgoal ; /* Goal for C-P, C-N */
/* /*
* This routine, given a pointer to a struct line, and the current cursor goal * This routine, given a pointer to a struct line, and the current cursor goal
@ -62,38 +78,6 @@ int gotobol(int f, int n)
return TRUE; return TRUE;
} }
/*
* Move the cursor backwards by "n" characters. If "n" is less than zero call
* "forwchar" to actually do the move. Otherwise compute the new cursor
* location. Error if you try and move out of the buffer. Set the flag if the
* line pointer for dot changes.
*/
int backchar(int f, int n)
{
struct line *lp;
if (n < 0)
return forwchar(f, -n);
while (n--) {
if (curwp->w_doto == 0) {
if ((lp = lback(curwp->w_dotp)) == curbp->b_linep)
return FALSE;
curwp->w_dotp = lp;
curwp->w_doto = llength(lp);
curwp->w_flag |= WFMOVE;
} else {
do {
unsigned char c;
curwp->w_doto--;
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (is_beginning_utf8(c))
break;
} while (curwp->w_doto);
}
}
return TRUE;
}
/* /*
* Move the cursor to the end of the current line. Trivial. No errors. * Move the cursor to the end of the current line. Trivial. No errors.
*/ */
@ -103,37 +87,6 @@ int gotoeol(int f, int n)
return TRUE; return TRUE;
} }
/*
* Move the cursor forwards by "n" characters. If "n" is less than zero call
* "backchar" to actually do the move. Otherwise compute the new cursor
* location, and move ".". Error if you try and move off the end of the
* buffer. Set the flag if the line pointer for dot changes.
*/
int forwchar(int f, int n)
{
if (n < 0)
return backchar(f, -n);
while (n--) {
int len = llength(curwp->w_dotp);
if (curwp->w_doto == len) {
if (curwp->w_dotp == curbp->b_linep)
return FALSE;
curwp->w_dotp = lforw(curwp->w_dotp);
curwp->w_doto = 0;
curwp->w_flag |= WFMOVE;
} else {
do {
unsigned char c;
curwp->w_doto++;
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (is_beginning_utf8(c))
break;
} while (curwp->w_doto < len);
}
}
return TRUE;
}
/* /*
* Move to a particular line. * Move to a particular line.
* *
@ -269,106 +222,6 @@ int backline(int f, int n)
return TRUE; return TRUE;
} }
#if WORDPRO
/*
* go back to the beginning of the current paragraph
* here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE>
* combination to delimit the beginning of a paragraph
*
* int f, n; default Flag & Numeric argument
*/
int gotobop(int f, int n)
{
int suc; /* success of last backchar */
if (n < 0) /* the other way... */
return gotoeop(f, -n);
while (n-- > 0) { /* for each one asked for */
/* first scan back until we are in a word */
suc = backchar(FALSE, 1);
while (!inword() && suc)
suc = backchar(FALSE, 1);
curwp->w_doto = 0; /* and go to the B-O-Line */
/* and scan back until we hit a <NL><NL> or <NL><TAB>
or a <NL><SPACE> */
while (lback(curwp->w_dotp) != curbp->b_linep)
if (llength(curwp->w_dotp) != 0 &&
#if PKCODE
((justflag == TRUE) ||
#endif
(lgetc(curwp->w_dotp, curwp->w_doto) != TAB &&
lgetc(curwp->w_dotp, curwp->w_doto) != ' '))
#if PKCODE
)
#endif
curwp->w_dotp = lback(curwp->w_dotp);
else
break;
/* and then forward until we are in a word */
suc = forwchar(FALSE, 1);
while (suc && !inword())
suc = forwchar(FALSE, 1);
}
curwp->w_flag |= WFMOVE; /* force screen update */
return TRUE;
}
/*
* Go forword to the end of the current paragraph
* here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE>
* combination to delimit the beginning of a paragraph
*
* int f, n; default Flag & Numeric argument
*/
int gotoeop(int f, int n)
{
int suc; /* success of last backchar */
if (n < 0) /* the other way... */
return gotobop(f, -n);
while (n-- > 0) { /* for each one asked for */
/* first scan forward until we are in a word */
suc = forwchar(FALSE, 1);
while (!inword() && suc)
suc = forwchar(FALSE, 1);
curwp->w_doto = 0; /* and go to the B-O-Line */
if (suc) /* of next line if not at EOF */
curwp->w_dotp = lforw(curwp->w_dotp);
/* and scan forword until we hit a <NL><NL> or <NL><TAB>
or a <NL><SPACE> */
while (curwp->w_dotp != curbp->b_linep) {
if (llength(curwp->w_dotp) != 0 &&
#if PKCODE
((justflag == TRUE) ||
#endif
(lgetc(curwp->w_dotp, curwp->w_doto) != TAB &&
lgetc(curwp->w_dotp, curwp->w_doto) != ' '))
#if PKCODE
)
#endif
curwp->w_dotp = lforw(curwp->w_dotp);
else
break;
}
/* and then backward until we are in a word */
suc = backchar(FALSE, 1);
while (suc && !inword()) {
suc = backchar(FALSE, 1);
}
curwp->w_doto = llength(curwp->w_dotp); /* and to the EOL */
}
curwp->w_flag |= WFMOVE; /* force screen update */
return TRUE;
}
#endif
/* /*
* Scroll forward by a specified number of lines, or by a full page if no * Scroll forward by a specified number of lines, or by a full page if no
* argument. Bound to "C-V". The "2" in the arithmetic on the window size is * argument. Bound to "C-V". The "2" in the arithmetic on the window size is

20
basic.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef _BASIC_H_
#define _BASIC_H_
extern int overlap ; /* line overlap in forw/back page */
extern int curgoal ; /* Goal for C-P, C-N */
int gotobol( int f, int n) ;
int gotoeol( int f, int n) ;
int gotoline( int f, int n) ;
int gotobob( int f, int n) ;
int gotoeob( int f, int n) ;
int forwline( int f, int n) ;
int backline( int f, int n) ;
int forwpage( int f, int n) ;
int backpage( int f, int n) ;
int setmark( int f, int n) ;
int swapmark( int f, int n) ;
#endif

112
bind.c
View File

@ -1,3 +1,6 @@
/* bind.c -- implements bind.h */
#include "bind.h"
/* bind.c /* bind.c
* *
* This file is for functions having to do with key bindings, * This file is for functions having to do with key bindings,
@ -8,13 +11,23 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "bindable.h"
#include "efunc.h" #include "buffer.h"
#include "epath.h" #include "display.h"
#include "ebind.h"
#include "exec.h"
#include "file.h"
#include "flook.h"
#include "input.h"
#include "line.h" #include "line.h"
#include "util.h" #include "names.h"
#include "window.h"
static char *getfname( fn_t) ;
int help(int f, int n) int help(int f, int n)
{ /* give me some help!!!! { /* give me some help!!!!
@ -25,10 +38,10 @@ int help(int f, int n)
char *fname = NULL; /* ptr to file returned by flook() */ char *fname = NULL; /* ptr to file returned by flook() */
/* first check if we are already here */ /* first check if we are already here */
bp = bfind("emacs.hlp", FALSE, BFINVS); bp = bfind( hlpfname, FALSE, BFINVS);
if (bp == NULL) { if (bp == NULL) {
fname = flook(pathname[1], FALSE); fname = flook( hlpfname, FALSE);
if (fname == NULL) { if (fname == NULL) {
mlwrite("(Help file is not online)"); mlwrite("(Help file is not online)");
return FALSE; return FALSE;
@ -456,7 +469,7 @@ int startup(char *sfname)
if (*sfname != 0) if (*sfname != 0)
fname = flook(sfname, TRUE); fname = flook(sfname, TRUE);
else else
fname = flook(pathname[0], TRUE); fname = flook( rcfname, TRUE);
/* if it isn't around, don't sweat it */ /* if it isn't around, don't sweat it */
if (fname == NULL) if (fname == NULL)
@ -466,89 +479,6 @@ int startup(char *sfname)
return dofile(fname); return dofile(fname);
} }
/*
* Look up the existance of a file along the normal or PATH
* environment variable. Look first in the HOME directory if
* asked and possible
*
* char *fname; base file name to search for
* int hflag; Look in the HOME environment variable first?
*/
char *flook(char *fname, int hflag)
{
char *home; /* path to home directory */
char *path; /* environmental PATH variable */
char *sp; /* pointer into path spec */
int i; /* index */
static char fspec[NSTRING]; /* full path spec to search */
#if ENVFUNC
if (hflag) {
home = getenv("HOME");
if (home != NULL) {
/* build home dir file spec */
strcpy(fspec, home);
strcat(fspec, "/");
strcat(fspec, fname);
/* and try it out */
if (ffropen(fspec) == FIOSUC) {
ffclose();
return fspec;
}
}
}
#endif
/* always try the current directory first */
if (ffropen(fname) == FIOSUC) {
ffclose();
return fname;
}
#if ENVFUNC
/* get the PATH variable */
path = getenv("PATH");
if (path != NULL)
while (*path) {
/* build next possible file spec */
sp = fspec;
while (*path && (*path != PATHCHR))
*sp++ = *path++;
/* add a terminating dir separator if we need it */
if (sp != fspec)
*sp++ = '/';
*sp = 0;
strcat(fspec, fname);
/* and try it out */
if (ffropen(fspec) == FIOSUC) {
ffclose();
return fspec;
}
if (*path == PATHCHR)
++path;
}
#endif
/* look it up via the old table method */
for (i = 2; i < ARRAY_SIZE(pathname); i++) {
strcpy(fspec, pathname[i]);
strcat(fspec, fname);
/* and try it out */
if (ffropen(fspec) == FIOSUC) {
ffclose();
return fspec;
}
}
return NULL; /* no such luck */
}
/* /*
* change a key command to a string we can print out * change a key command to a string we can print out
* *
@ -616,7 +546,7 @@ int (*getbind(int c))(int, int)
* This function takes a ptr to function and gets the name * This function takes a ptr to function and gets the name
* associated with it. * associated with it.
*/ */
char *getfname(fn_t func) static char *getfname(fn_t func)
{ {
struct name_bind *nptr; /* pointer into the name binding table */ struct name_bind *nptr; /* pointer into the name binding table */

29
bind.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef _BIND_H_
#define _BIND_H_
#define APROP 1 /* Add code for Apropos command */
#if APROP
int apro( int f, int n) ;
int strinc( char *source, char *sub) ;
#endif
/* Some global fuction declarations. */
typedef int (*fn_t)(int, int);
int help( int f, int n) ;
int deskey( int f, int n) ;
int bindtokey( int f, int n) ;
int unbindkey( int f, int n) ;
int unbindchar( int c) ;
int desbind( int f, int n) ;
int buildlist( int type, char *mstring) ;
unsigned int getckey( int mflag) ;
int startup( char *sfname) ;
void cmdstr( int c, char *seq) ;
fn_t getbind( int c) ;
fn_t fncmatch( char *) ;
unsigned int stock( char *keyname) ;
char *transbind( char *skey) ;
#endif

180
bindable.c Normal file
View File

@ -0,0 +1,180 @@
/* bindable.h -- implements bindable.c */
#include "bindable.h"
#include <stdlib.h>
#include "defines.h"
#include "buffer.h"
#include "display.h"
#include "estruct.h"
#include "file.h"
#include "input.h"
#include "lock.h"
#include "terminal.h"
#if VMS
#include <ssdef.h>
#define GOOD (SS$_NORMAL)
#endif
#ifndef GOOD
#define GOOD 0
#endif
/*
* Fancy quit command, as implemented by Norm. If the any buffer has
* changed do a write on that buffer and exit emacs, otherwise simply exit.
*/
int quickexit(int f, int n)
{
struct buffer *bp; /* scanning pointer to buffers */
struct buffer *oldcb; /* original current buffer */
int status;
oldcb = curbp; /* save in case we fail */
bp = bheadp;
while (bp != NULL) {
if ((bp->b_flag & BFCHG) != 0 /* Changed. */
&& (bp->b_flag & BFTRUNC) == 0 /* Not truncated P.K. */
&& (bp->b_flag & BFINVS) == 0) { /* Real. */
curbp = bp; /* make that buffer cur */
mlwrite("(Saving %s)", bp->b_fname);
#if PKCODE
#else
mlwrite("\n");
#endif
if ((status = filesave(f, n)) != TRUE) {
curbp = oldcb; /* restore curbp */
return status;
}
}
bp = bp->b_bufp; /* on to the next buffer */
}
quit(f, n); /* conditionally quit */
return TRUE;
}
/*
* Quit command. If an argument, always quit. Otherwise confirm if a buffer
* has been changed and not written out. Normally bound to "C-X C-C".
*/
int quit(int f, int n)
{
int s;
if (f != FALSE /* Argument forces it. */
|| anycb() == FALSE /* All buffers clean. */
/* User says it's OK. */
|| (s =
mlyesno("Modified buffers exist. Leave anyway")) == TRUE) {
#if (FILOCK && BSD) || SVR4
if (lockrel() != TRUE) {
TTputc('\n');
TTputc('\r');
TTclose();
TTkclose();
exit(1);
}
#endif
vttidy();
if (f)
exit(n);
else
exit(GOOD);
}
mlwrite("");
return s;
}
/*
* Begin a keyboard macro.
* Error if not at the top level in keyboard processing. Set up variables and
* return.
*/
int ctlxlp(int f, int n)
{
if (kbdmode != STOP) {
mlwrite("%%Macro already active");
return FALSE;
}
mlwrite("(Start macro)");
kbdptr = &kbdm[0];
kbdend = kbdptr;
kbdmode = RECORD;
return TRUE;
}
/*
* End keyboard macro. Check for the same limit conditions as the above
* routine. Set up the variables and return to the caller.
*/
int ctlxrp(int f, int n)
{
if (kbdmode == STOP) {
mlwrite("%%Macro not active");
return FALSE;
}
if (kbdmode == RECORD) {
mlwrite("(End macro)");
kbdmode = STOP;
}
return TRUE;
}
/*
* Execute a macro.
* The command argument is the number of times to loop. Quit as soon as a
* command gets an error. Return TRUE if all ok, else FALSE.
*/
int ctlxe(int f, int n)
{
if (kbdmode != STOP) {
mlwrite("%%Macro already active");
return FALSE;
}
if (n <= 0)
return TRUE;
kbdrep = n; /* remember how many times to execute */
kbdmode = PLAY; /* start us in play mode */
kbdptr = &kbdm[0]; /* at the beginning */
return TRUE;
}
/*
* Abort.
* Beep the beeper. Kill off any keyboard macro, etc., that is in progress.
* Sometimes called as a routine, to do general aborting of stuff.
*/
int ctrlg(int f, int n)
{
TTbeep();
kbdmode = STOP;
mlwrite("(Aborted)");
return ABORT;
}
/* user function that does NOTHING */
int nullproc(int f, int n)
{
return TRUE;
}
/* dummy function for binding to meta prefix */
int metafn(int f, int n)
{
return TRUE;
}
/* dummy function for binding to control-x prefix */
int cex(int f, int n)
{
return TRUE;
}
/* dummy function for binding to universal-argument */
int unarg(int f, int n)
{
return TRUE;
}

11
bindable.h Normal file
View File

@ -0,0 +1,11 @@
/* functions that can be bound to keys or procedure names */
int quickexit( int f, int n) ;
int quit( int f, int n) ;
int ctlxlp( int f, int n) ;
int ctlxrp( int f, int n) ;
int ctlxe( int f, int n) ;
int ctrlg( int f, int n) ;
int nullproc( int f, int n) ;
int metafn( int f, int n) ;
int cex( int f, int n) ;
int unarg( int f, int n) ;

View File

@ -1,3 +1,6 @@
/* buffer.c -- implements buffer.h */
#include "buffer.h"
/* buffer.c /* buffer.c
* *
* Buffer management. * Buffer management.
@ -10,11 +13,41 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "defines.h"
#include "display.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "file.h"
#include "efunc.h" #include "input.h"
#include "line.h" #include "window.h"
struct buffer *curbp ; /* Current buffer */
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",
"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 int makelist( int iflag) ;
static int addline( char *text) ;
static void l_to_a( char *buf, int width, long num) ;
/* /*
* Attach a buffer to a window. The * Attach a buffer to a window. The
@ -26,9 +59,9 @@ int usebuffer(int f, int n)
{ {
struct buffer *bp; struct buffer *bp;
int s; int s;
char bufn[NBUFN]; bname_t bufn ;
if ((s = mlreply("Use buffer: ", bufn, NBUFN)) != TRUE) if ((s = mlreply("Use buffer: ", bufn, sizeof bufn)) != TRUE)
return s; return s;
if ((bp = bfind(bufn, TRUE, 0)) == NULL) if ((bp = bfind(bufn, TRUE, 0)) == NULL)
return FALSE; return FALSE;
@ -135,9 +168,9 @@ int killbuffer(int f, int n)
{ {
struct buffer *bp; struct buffer *bp;
int s; int s;
char bufn[NBUFN]; bname_t bufn ;
if ((s = mlreply("Kill buffer: ", bufn, NBUFN)) != TRUE) if ((s = mlreply("Kill buffer: ", bufn, sizeof bufn)) != TRUE)
return s; return s;
if ((bp = bfind(bufn, FALSE, 0)) == NULL) /* Easy if unknown. */ if ((bp = bfind(bufn, FALSE, 0)) == NULL) /* Easy if unknown. */
return TRUE; return TRUE;
@ -185,10 +218,10 @@ int zotbuf(struct buffer *bp)
int namebuffer(int f, int n) int namebuffer(int f, int n)
{ {
struct buffer *bp; /* pointer to scan through all buffers */ struct buffer *bp; /* pointer to scan through all buffers */
char bufn[NBUFN]; /* buffer to hold buffer name */ bname_t bufn ; /* buffer to hold buffer name */
/* prompt for and get the new buffer name */ /* prompt for and get the new buffer name */
ask:if (mlreply("Change buffer name to: ", bufn, NBUFN) != ask:if (mlreply("Change buffer name to: ", bufn, sizeof bufn) !=
TRUE) TRUE)
return FALSE; return FALSE;
@ -267,7 +300,7 @@ int listbuffers(int f, int n)
* int iflag; list hidden buffer flag * int iflag; list hidden buffer flag
*/ */
#define MAXLINE MAXCOL #define MAXLINE MAXCOL
int makelist(int iflag) static int makelist( int iflag)
{ {
char *cp1; char *cp1;
char *cp2; char *cp2;
@ -277,7 +310,7 @@ int makelist(int iflag)
int s; int s;
int i; int i;
long nbytes; /* # of bytes in current buffer */ long nbytes; /* # of bytes in current buffer */
char b[7 + 1]; char b[ 8 + 1] ;
char line[MAXLINE]; char line[MAXLINE];
blistp->b_flag &= ~BFCHG; /* Don't complain! */ blistp->b_flag &= ~BFCHG; /* Don't complain! */
@ -285,8 +318,7 @@ int makelist(int iflag)
return s; return s;
strcpy(blistp->b_fname, ""); strcpy(blistp->b_fname, "");
if( addline("ACT MODES Size Buffer File") == FALSE if( addline("ACT MODES Size Buffer File") == FALSE
|| addline("--- ----- ---- ------ ----") == || addline("--- ----- ---- ------ ----") == FALSE)
FALSE)
return FALSE; return FALSE;
bp = bheadp; /* For all buffers */ bp = bheadp; /* For all buffers */
@ -343,24 +375,28 @@ int makelist(int iflag)
else else
*cp1++ = '.'; *cp1++ = '.';
} }
*cp1++ = ' '; /* Gap. */
/* No gap as buffer size if left padded with space */
/* Buffer size */
nbytes = 0L; /* Count bytes in buf. */ nbytes = 0L; /* Count bytes in buf. */
lp = lforw(bp->b_linep); lp = lforw(bp->b_linep);
while (lp != bp->b_linep) { while (lp != bp->b_linep) {
nbytes += (long) llength(lp) + 1L; nbytes += (long) llength(lp) + 1L;
lp = lforw(lp); lp = lforw(lp);
} }
ltoa(b, 7, nbytes); /* 6 digit buffer size. */ l_to_a( b, sizeof b, nbytes) ; /* 8 digits string buffer size. */
cp2 = &b[0]; cp2 = &b[0];
while ((c = *cp2++) != 0) while ((c = *cp2++) != 0)
*cp1++ = c; *cp1++ = c;
*cp1++ = ' '; /* Gap. */ *cp1++ = ' '; /* Gap. */
cp2 = &bp->b_bname[0]; /* Buffer name */ cp2 = &bp->b_bname[0]; /* Buffer name */
while ((c = *cp2++) != 0) while ((c = *cp2++) != 0)
*cp1++ = c; *cp1++ = c;
cp2 = &bp->b_fname[0]; /* File name */ cp2 = &bp->b_fname[0]; /* File name */
if (*cp2 != 0) { if (*cp2 != 0) {
while (cp1 < &line[3 + 1 + 5 + 1 + 6 + 4 + NBUFN]) while( cp1 < &line[ 3 + 1 + NUMMODES + 8 + 1 + (NBUFN-1) + 1])
*cp1++ = ' '; *cp1++ = ' ';
while ((c = *cp2++) != 0) { while ((c = *cp2++) != 0) {
if (cp1 < &line[MAXLINE - 1]) if (cp1 < &line[MAXLINE - 1])
@ -375,15 +411,15 @@ int makelist(int iflag)
return TRUE; /* All done */ return TRUE; /* All done */
} }
void ltoa(char *buf, int width, long num) static void l_to_a(char *buf, int width, long num)
{ {
buf[width] = 0; /* End of string. */ buf[ --width] = 0 ; /* End of string. */
while (num >= 10) { /* Conditional digits. */ while (num >= 10) { /* Conditional digits. */
buf[--width] = (int) (num % 10L) + '0'; buf[--width] = (int) (num % 10L) + '0';
num /= 10L; num /= 10L;
} }
buf[--width] = (int) num + '0'; /* Always 1 digit. */ buf[--width] = (int) num + '0'; /* Always 1 digit. */
while (width != 0) /* Pad with blanks. */ while( width > 0) /* Pad with blanks. */
buf[--width] = ' '; buf[--width] = ' ';
} }
@ -394,7 +430,7 @@ void ltoa(char *buf, int width, long num)
* on the end. Return TRUE if it worked and * on the end. Return TRUE if it worked and
* FALSE if you ran out of room. * FALSE if you ran out of room.
*/ */
int addline(char *text) static int addline( char *text)
{ {
struct line *lp; struct line *lp;
int i; int i;
@ -445,7 +481,7 @@ int anycb(void)
* and the "cflag" is TRUE, create it. The "bflag" is * and the "cflag" is TRUE, create it. The "bflag" is
* the settings for the flags in in buffer. * the settings for the flags in in buffer.
*/ */
struct buffer *bfind(char *bname, int cflag, int bflag) struct buffer *bfind( const char *bname, int cflag, int bflag)
{ {
struct buffer *bp; struct buffer *bp;
struct buffer *sb; /* buffer to insert after */ struct buffer *sb; /* buffer to insert after */

87
buffer.h Normal file
View File

@ -0,0 +1,87 @@
#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
/*
* Text is kept in buffers. A buffer header, described below, exists for every
* buffer in the system. The buffers are kept in a big list, so that commands
* that search for a buffer by name can find the buffer header. There is a
* safe store for the dot and mark in the header, but this is only valid if
* the buffer is not being displayed (that is, if "b_nwnd" is 0). The text for
* the buffer is kept in a circularly linked list of lines, with a pointer to
* the header line in "b_linep".
* Buffers may be "Inactive" which means the files associated with them
* have not been read in yet. These get read in at "use buffer" time.
*/
struct buffer {
struct buffer *b_bufp; /* Link to next struct buffer */
struct line *b_dotp; /* Link to "." struct line structure */
struct line *b_markp; /* The same as the above two, */
struct line *b_linep; /* Link to the header struct line */
int b_doto; /* Offset of "." in above struct line */
int b_marko; /* but for the "mark" */
int b_mode; /* editor mode of this buffer */
char b_active; /* window activated flag */
char b_nwnd; /* Count of windows on 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 */
extern struct buffer *bheadp ; /* Head of list of buffers */
extern struct buffer *blistp ; /* Buffer for C-X C-B */
#define BFINVS 0x01 /* Internal invisable buffer */
#define BFCHG 0x02 /* Changed since last write */
#define BFTRUNC 0x04 /* buffer was truncated when read */
/* mode flags */
#define NUMMODES 11 /* # 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 */
extern const char *modename[] ; /* text names of modes */
extern int gmode ; /* global editor mode */
int usebuffer( int f, int n) ;
int nextbuffer( int f, int n) ;
int swbuffer( struct buffer *bp) ;
int killbuffer( int f, int n) ;
int zotbuf( struct buffer *bp) ;
int namebuffer( int f, int n) ;
int listbuffers( int f, int n) ;
int anycb( void) ;
int bclear( struct buffer *bp) ;
int unmark( int f, int n) ;
/* Lookup a buffer by name. */
struct buffer *bfind( const char *bname, int cflag, int bflag) ;
#endif

9
count.cmd Normal file
View File

@ -0,0 +1,9 @@
; count.cmd -- create a buffer with digit from 1 to n
set %i 1
!while &less %i 2000000
insert-string %i
newline
set %i &add %i 1
!endwhile
write-file count.txt
exit-emacs

47
crypt.c
View File

@ -1,3 +1,7 @@
/* crypt.c -- implements crypt.h */
#include "crypt.h"
/* CRYPT.C /* CRYPT.C
* *
* Encryption routines * Encryption routines
@ -5,46 +9,12 @@
* written by Dana Hoggatt and Daniel Lawrence * written by Dana Hoggatt and Daniel Lawrence
*/ */
#include <stdio.h>
#include "estruct.h"
#include "edef.h"
#include "efunc.h"
#if CRYPT #if CRYPT
#include <stdio.h>
static int mod95(int); static int mod95(int);
/*
* 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 vlaue of disinp */
char key[NPAT]; /* new encryption string */
/* turn command input echo off */
odisinp = disinp;
disinp = FALSE;
/* get the string to use as an encrytion string */
status = mlreply("Encryption String: ", key, NPAT - 1);
disinp = odisinp;
if (status != TRUE)
return status;
/* and encrypt it */
myencrypt((char *) NULL, 0);
myencrypt(key, strlen(key));
/* and save it off */
strcpy(curbp->b_key, key);
mlwrite(" "); /* clear it off the bottom line */
return TRUE;
}
/********** /**********
* *
@ -216,8 +186,5 @@ static int mod95(int val)
val += 95; val += 95;
return val; return val;
} }
#else
static void myennocrypt(void)
{
}
#endif #endif

10
crypt.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _CRYPT_H_
#define _CRYPT_H_
#define CRYPT 1 /* file encryption enabled? */
#if CRYPT
void myencrypt( char *bptr, unsigned len) ;
#endif
#endif

18
defines.h Normal file
View File

@ -0,0 +1,18 @@
/* Must define one of
VMS | V7 | USG | BSD | MSDOS
*/
#define USG 1
#define PKCODE 1
#define SCROLLCODE 1 /* scrolling code P.K. */
#define ENVFUNC 1
#define NSTRING 128 /* # of bytes, string buffers */
#define CONTROL 0x10000000 /* Control flag, or'ed in */
#define META 0x20000000 /* Meta flag, or'ed in */
#define CTLX 0x40000000 /* ^X flag, or'ed in */
#define SPEC 0x80000000 /* special key (function keys) */
#define MAXCOL 500
#define MAXROW 500

View File

@ -1,3 +1,9 @@
/* display.c -- implements display.h */
#include "display.h"
#define REVSTA 1 /* Status line appears in reverse video */
/* display.c /* display.c
* *
* The functions in this file handle redisplay. There are two halves, the * The functions in this file handle redisplay. There are two halves, the
@ -11,15 +17,19 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "buffer.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "input.h"
#include "efunc.h"
#include "line.h" #include "line.h"
#include "termio.h"
#include "terminal.h"
#include "version.h" #include "version.h"
#include "wrapper.h" #include "wrapper.h"
#include "utf8.h" #include "utf8.h"
#include "window.h"
struct video { struct video {
int v_flag; /* Flags */ int v_flag; /* Flags */
@ -53,6 +63,17 @@ static int displaying = TRUE;
int chg_width, chg_height; int chg_width, chg_height;
#endif #endif
static int currow ; /* Cursor row */
static int curcol ; /* Cursor column */
static int vtrow = 0 ; /* Row location of SW cursor */
static int vtcol = 0 ; /* Column location of SW cursor */
static int lbound = 0 ; /* leftmost column of current line being displayed */
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 */
static int reframe(struct window *wp); static int reframe(struct window *wp);
static void updone(struct window *wp); static void updone(struct window *wp);
static void updall(struct window *wp); static void updall(struct window *wp);
@ -66,7 +87,9 @@ static void modeline(struct window *wp);
static void mlputi(int i, int r); static void mlputi(int i, int r);
static void mlputli(long l, int r); static void mlputli(long l, int r);
static void mlputf(int s); static void mlputf(int s);
#if SIGWINCH
static int newscreensize(int h, int w); static int newscreensize(int h, int w);
#endif
#if RAINBOW #if RAINBOW
static void putline(int row, int col, char *buf); static void putline(int row, int col, char *buf);
@ -947,8 +970,10 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
unicode_t *cp4; unicode_t *cp4;
unicode_t *cp5; unicode_t *cp5;
int nbflag; /* non-blanks to the right flag? */ int nbflag; /* non-blanks to the right flag? */
#if REVSTA
int rev; /* reverse video flag */ int rev; /* reverse video flag */
int req; /* reverse video request flag */ #endif
int req = FALSE ; /* reverse video request flag */
/* set up pointers to virtual and physical lines */ /* set up pointers to virtual and physical lines */
@ -1093,7 +1118,7 @@ static void modeline(struct window *wp)
#endif #endif
vtmove(n, 0); /* Seek to right line. */ vtmove(n, 0); /* Seek to right line. */
if (wp == curwp) /* mark the current buffer */ if (wp == curwp) /* mark the current buffer */
#if PKCODE #if PKCODE && REVSTA
lchar = '-'; lchar = '-';
#else #else
lchar = '='; lchar = '=';
@ -1121,12 +1146,7 @@ static void modeline(struct window *wp)
n = 2; n = 2;
strcpy(tline, " "); cp = " " PROGRAM_NAME_LONG " " VERSION ": " ;
strcat(tline, PROGRAM_NAME_LONG);
strcat(tline, " ");
strcat(tline, VERSION);
strcat(tline, ": ");
cp = &tline[0];
while ((c = *cp++) != 0) { while ((c = *cp++) != 0) {
vtputc(c); vtputc(c);
++n; ++n;
@ -1152,7 +1172,7 @@ static void modeline(struct window *wp)
if (firstm != TRUE) if (firstm != TRUE)
strcat(tline, " "); strcat(tline, " ");
firstm = FALSE; firstm = FALSE;
strcat(tline, mode2name[i]); strcat( tline, modename[ i]) ;
} }
strcat(tline, ") "); strcat(tline, ") ");

32
display.h Normal file
View File

@ -0,0 +1,32 @@
#ifndef _DISPLAY_H_
#define _DISPLAY_H_
extern int mpresf ; /* Stuff in message line */
extern int scrollcount ; /* number of lines to scroll */
extern int discmd ; /* display command flag */
extern int gfcolor ; /* global forgrnd color (white) */
extern int gbcolor ; /* global backgrnd color (black) */
void vtinit( void) ;
void vtfree( void) ;
void vttidy( void) ;
void vtmove( int row, int col) ;
int upscreen( int f, int n) ;
int update( int force) ;
void updpos( void) ;
void upddex( void) ;
void updgar( void) ;
int updupd( int force) ;
void upmode( void) ;
void movecursor( int row, int col) ;
void mlerase( void) ;
void mlwrite( const char *fmt, ...) ;
void mlforce( char *s) ;
void mlputs( char *s) ;
void getscreensize( int *widthp, int *heightp) ;
#ifdef SIGWINCH
void sizesignal( int signr) ;
#endif
#endif

441
ebind.c Normal file
View File

@ -0,0 +1,441 @@
/* ebind.c -- implements ebind.h */
#include "ebind.h"
/* ebind.c
*
* Initial default key to function bindings
*
* Modified by Petri Kutvonen
*/
#include <stdlib.h>
#include "basic.h"
#include "bind.h"
#include "estruct.h"
#include "bindable.h"
#include "buffer.h"
#include "eval.h"
#include "exec.h"
#include "file.h"
#include "isearch.h"
#include "line.h"
#include "random.h"
#include "region.h"
#include "search.h"
#include "spawn.h"
#include "window.h"
#include "word.h"
/*
* Command table.
* This table is *roughly* in ASCII order, left to right across the
* characters of the command. This explains the funny location of the
* control-X commands.
*/
struct key_tab keytab[NBINDS] = {
{CONTROL | 'A', gotobol}
,
{CONTROL | 'B', backchar}
,
{CONTROL | 'C', insspace}
,
{CONTROL | 'D', forwdel}
,
{CONTROL | 'E', gotoeol}
,
{CONTROL | 'F', forwchar}
,
{CONTROL | 'G', ctrlg}
,
{CONTROL | 'H', backdel}
,
{CONTROL | 'I', insert_tab}
,
{CONTROL | 'J', indent}
,
{CONTROL | 'K', killtext}
,
{CONTROL | 'L', redraw}
,
{CONTROL | 'M', insert_newline}
,
{CONTROL | 'N', forwline}
,
{CONTROL | 'O', openline}
,
{CONTROL | 'P', backline}
,
{CONTROL | 'Q', quote}
,
{CONTROL | 'R', backsearch}
,
{CONTROL | 'S', forwsearch}
,
{CONTROL | 'T', twiddle}
,
{CONTROL | 'U', unarg}
,
{CONTROL | 'V', forwpage}
,
{CONTROL | 'W', killregion}
,
{CONTROL | 'X', cex}
,
{CONTROL | 'Y', yank}
,
{CONTROL | 'Z', backpage}
,
{CONTROL | ']', metafn}
,
{CTLX | CONTROL | 'B', listbuffers}
,
{CTLX | CONTROL | 'C', quit}
, /* Hard quit. */
#if PKCODE & AEDIT
{CTLX | CONTROL | 'A', detab}
,
#endif
#if PKCODE
{CTLX | CONTROL | 'D', filesave}
, /* alternative */
#else
#if AEDIT
{CTLX | CONTROL | 'D', detab}
,
#endif
#endif
#if AEDIT
{CTLX | CONTROL | 'E', entab}
,
#endif
{CTLX | CONTROL | 'F', filefind}
,
{CTLX | CONTROL | 'I', insfile}
,
{CTLX | CONTROL | 'L', lowerregion}
,
{CTLX | CONTROL | 'M', delmode}
,
{CTLX | CONTROL | 'N', mvdnwind}
,
{CTLX | CONTROL | 'O', deblank}
,
{CTLX | CONTROL | 'P', mvupwind}
,
{CTLX | CONTROL | 'R', fileread}
,
{CTLX | CONTROL | 'S', filesave}
,
#if AEDIT
{CTLX | CONTROL | 'T', trim}
,
#endif
{CTLX | CONTROL | 'U', upperregion}
,
{CTLX | CONTROL | 'V', viewfile}
,
{CTLX | CONTROL | 'W', filewrite}
,
{CTLX | CONTROL | 'X', swapmark}
,
{CTLX | CONTROL | 'Z', shrinkwind}
,
{CTLX | '?', deskey}
,
{CTLX | '!', spawn}
,
{CTLX | '@', pipecmd}
,
{CTLX | '#', filter_buffer}
,
{CTLX | '$', execprg}
,
{CTLX | '=', showcpos}
,
{CTLX | '(', ctlxlp}
,
{CTLX | ')', ctlxrp}
,
{CTLX | '^', enlargewind}
,
{CTLX | '0', delwind}
,
{CTLX | '1', onlywind}
,
{CTLX | '2', splitwind}
,
{CTLX | 'A', setvar}
,
{CTLX | 'B', usebuffer}
,
{CTLX | 'C', spawncli}
,
#if BSD | __hpux | SVR4
{CTLX | 'D', bktoshell}
,
#endif
{CTLX | 'E', ctlxe}
,
{CTLX | 'F', setfillcol}
,
{CTLX | 'K', killbuffer}
,
{CTLX | 'M', setemode}
,
{CTLX | 'N', filename}
,
{CTLX | 'O', nextwind}
,
{CTLX | 'P', prevwind}
,
#if PKCODE
{CTLX | 'Q', quote}
, /* alternative */
#endif
#if ISRCH
{CTLX | 'R', risearch}
,
{CTLX | 'S', fisearch}
,
#endif
{CTLX | 'W', resize}
,
{CTLX | 'X', nextbuffer}
,
{CTLX | 'Z', enlargewind}
,
#if WORDPRO
{META | CONTROL | 'C', wordcount}
,
#endif
#if PKCODE
{META | CONTROL | 'D', newsize}
,
#endif
#if PROC
{META | CONTROL | 'E', execproc}
,
#endif
#if CFENCE
{META | CONTROL | 'F', getfence}
,
#endif
{META | CONTROL | 'H', delbword}
,
{META | CONTROL | 'K', unbindkey}
,
{META | CONTROL | 'L', reposition}
,
{META | CONTROL | 'M', delgmode}
,
{META | CONTROL | 'N', namebuffer}
,
{META | CONTROL | 'R', qreplace}
,
{META | CONTROL | 'S', newsize}
,
{META | CONTROL | 'T', newwidth}
,
{META | CONTROL | 'V', scrnextdw}
,
#if WORDPRO
{META | CONTROL | 'W', killpara}
,
#endif
{META | CONTROL | 'Z', scrnextup}
,
{META | ' ', setmark}
,
{META | '?', help}
,
{META | '!', reposition}
,
{META | '.', setmark}
,
{META | '>', gotoeob}
,
{META | '<', gotobob}
,
{META | '~', unmark}
,
#if APROP
{META | 'A', apro}
,
#endif
{META | 'B', backword}
,
{META | 'C', capword}
,
{META | 'D', delfword}
,
#if CRYPT
{META | 'E', set_encryption_key}
,
#endif
{META | 'F', forwword}
,
{META | 'G', gotoline}
,
#if PKCODE
#if WORDPRO
{META | 'J', justpara}
,
#endif
#endif
{META | 'K', bindtokey}
,
{META | 'L', lowerword}
,
{META | 'M', setgmode}
,
#if WORDPRO
{META | 'N', gotoeop}
,
{META | 'P', gotobop}
,
{META | 'Q', fillpara}
,
#endif
{META | 'R', sreplace}
,
#if PKCODE
{META | 'S', forwsearch}
, /* alternative P.K. */
#else
#if BSD
{META | 'S', bktoshell}
,
#endif
#endif
{META | 'U', upperword}
,
{META | 'V', backpage}
,
{META | 'W', copyregion}
,
{META | 'X', namedcmd}
,
{META | 'Z', quickexit}
,
{META | 0x7F, delbword}
,
#if MSDOS
{SPEC | CONTROL | '_', forwhunt}
,
{SPEC | CONTROL | 'S', backhunt}
,
{SPEC | 71, gotobol}
,
{SPEC | 72, backline}
,
{SPEC | 73, backpage}
,
{SPEC | 75, backchar}
,
{SPEC | 77, forwchar}
,
{SPEC | 79, gotoeol}
,
{SPEC | 80, forwline}
,
{SPEC | 81, forwpage}
,
{SPEC | 82, insspace}
,
{SPEC | 83, forwdel}
,
{SPEC | 115, backword}
,
{SPEC | 116, forwword}
,
#if WORDPRO
{SPEC | 132, gotobop}
,
{SPEC | 118, gotoeop}
,
#endif
{SPEC | 84, cbuf1}
,
{SPEC | 85, cbuf2}
,
{SPEC | 86, cbuf3}
,
{SPEC | 87, cbuf4}
,
{SPEC | 88, cbuf5}
,
{SPEC | 89, cbuf6}
,
{SPEC | 90, cbuf7}
,
{SPEC | 91, cbuf8}
,
{SPEC | 92, cbuf9}
,
{SPEC | 93, cbuf10}
,
#if PKCODE
{SPEC | 117, gotoeob}
,
{SPEC | 119, gotobob}
,
{SPEC | 141, gotobop}
,
{SPEC | 145, gotoeop}
,
{SPEC | 146, yank}
,
{SPEC | 147, killregion}
,
#endif
#endif
#if VT220
{SPEC | '1', gotobob /* fisearch */}
, /* VT220 keys */
{SPEC | '2', yank}
,
{SPEC | '3', forwdel /* killregion */}
,
{SPEC | '4', gotoeob /* setmark */}
,
{SPEC | '5', backpage}
,
{SPEC | '6', forwpage}
,
{SPEC | 'A', backline}
,
{SPEC | 'B', forwline}
,
{SPEC | 'C', forwchar}
,
{SPEC | 'D', backchar}
,
{SPEC | 'c', metafn}
,
{SPEC | 'd', backchar}
,
{SPEC | 'e', forwline}
,
{SPEC | 'f', gotobob}
,
{SPEC | 'h', help}
,
{SPEC | 'i', cex}
,
#endif
{0x7F, backdel}
,
/* special internal bindings */
{ SPEC | META | 'W', wrapword }, /* called on word wrap */
{ SPEC | META | 'C', nullproc }, /* every command input */
{ SPEC | META | 'R', nullproc }, /* on file read */
{ SPEC | META | 'X', nullproc }, /* on window change P.K. */
{0, NULL}
};

430
ebind.h
View File

@ -1,425 +1,9 @@
/* ebind.h /* Structure for the table of initial key bindings. */
* struct key_tab {
* Initial default key to function bindings int k_code ; /* Key code */
* int (*k_fp)( int, int) ; /* Routine to handle it */
* Modified by Petri Kutvonen
*/
#ifndef EBIND_H_
#define EBIND_H_
#include "line.h"
/*
* Command table.
* This table is *roughly* in ASCII order, left to right across the
* characters of the command. This explains the funny location of the
* control-X commands.
*/
struct key_tab keytab[NBINDS] = {
{CONTROL | 'A', gotobol}
,
{CONTROL | 'B', backchar}
,
{CONTROL | 'C', insspace}
,
{CONTROL | 'D', forwdel}
,
{CONTROL | 'E', gotoeol}
,
{CONTROL | 'F', forwchar}
,
{CONTROL | 'G', ctrlg}
,
{CONTROL | 'H', backdel}
,
{CONTROL | 'I', insert_tab}
,
{CONTROL | 'J', indent}
,
{CONTROL | 'K', killtext}
,
{CONTROL | 'L', redraw}
,
{CONTROL | 'M', insert_newline}
,
{CONTROL | 'N', forwline}
,
{CONTROL | 'O', openline}
,
{CONTROL | 'P', backline}
,
{CONTROL | 'Q', quote}
,
{CONTROL | 'R', backsearch}
,
{CONTROL | 'S', forwsearch}
,
{CONTROL | 'T', twiddle}
,
{CONTROL | 'U', unarg}
,
{CONTROL | 'V', forwpage}
,
{CONTROL | 'W', killregion}
,
{CONTROL | 'X', cex}
,
{CONTROL | 'Y', yank}
,
{CONTROL | 'Z', backpage}
,
{CONTROL | ']', metafn}
,
{CTLX | CONTROL | 'B', listbuffers}
,
{CTLX | CONTROL | 'C', quit}
, /* Hard quit. */
#if PKCODE & AEDIT
{CTLX | CONTROL | 'A', detab}
,
#endif
#if PKCODE
{CTLX | CONTROL | 'D', filesave}
, /* alternative */
#else
#if AEDIT
{CTLX | CONTROL | 'D', detab}
,
#endif
#endif
#if AEDIT
{CTLX | CONTROL | 'E', entab}
,
#endif
{CTLX | CONTROL | 'F', filefind}
,
{CTLX | CONTROL | 'I', insfile}
,
{CTLX | CONTROL | 'L', lowerregion}
,
{CTLX | CONTROL | 'M', delmode}
,
{CTLX | CONTROL | 'N', mvdnwind}
,
{CTLX | CONTROL | 'O', deblank}
,
{CTLX | CONTROL | 'P', mvupwind}
,
{CTLX | CONTROL | 'R', fileread}
,
{CTLX | CONTROL | 'S', filesave}
,
#if AEDIT
{CTLX | CONTROL | 'T', trim}
,
#endif
{CTLX | CONTROL | 'U', upperregion}
,
{CTLX | CONTROL | 'V', viewfile}
,
{CTLX | CONTROL | 'W', filewrite}
,
{CTLX | CONTROL | 'X', swapmark}
,
{CTLX | CONTROL | 'Z', shrinkwind}
,
{CTLX | '?', deskey}
,
{CTLX | '!', spawn}
,
{CTLX | '@', pipecmd}
,
{CTLX | '#', filter_buffer}
,
{CTLX | '$', execprg}
,
{CTLX | '=', showcpos}
,
{CTLX | '(', ctlxlp}
,
{CTLX | ')', ctlxrp}
,
{CTLX | '^', enlargewind}
,
{CTLX | '0', delwind}
,
{CTLX | '1', onlywind}
,
{CTLX | '2', splitwind}
,
{CTLX | 'A', setvar}
,
{CTLX | 'B', usebuffer}
,
{CTLX | 'C', spawncli}
,
#if BSD | __hpux | SVR4
{CTLX | 'D', bktoshell}
,
#endif
{CTLX | 'E', ctlxe}
,
{CTLX | 'F', setfillcol}
,
{CTLX | 'K', killbuffer}
,
{CTLX | 'M', setemode}
,
{CTLX | 'N', filename}
,
{CTLX | 'O', nextwind}
,
{CTLX | 'P', prevwind}
,
#if PKCODE
{CTLX | 'Q', quote}
, /* alternative */
#endif
#if ISRCH
{CTLX | 'R', risearch}
,
{CTLX | 'S', fisearch}
,
#endif
{CTLX | 'W', resize}
,
{CTLX | 'X', nextbuffer}
,
{CTLX | 'Z', enlargewind}
,
#if WORDPRO
{META | CONTROL | 'C', wordcount}
,
#endif
#if PKCODE
{META | CONTROL | 'D', newsize}
,
#endif
#if PROC
{META | CONTROL | 'E', execproc}
,
#endif
#if CFENCE
{META | CONTROL | 'F', getfence}
,
#endif
{META | CONTROL | 'H', delbword}
,
{META | CONTROL | 'K', unbindkey}
,
{META | CONTROL | 'L', reposition}
,
{META | CONTROL | 'M', delgmode}
,
{META | CONTROL | 'N', namebuffer}
,
{META | CONTROL | 'R', qreplace}
,
{META | CONTROL | 'S', newsize}
,
{META | CONTROL | 'T', newwidth}
,
{META | CONTROL | 'V', scrnextdw}
,
#if WORDPRO
{META | CONTROL | 'W', killpara}
,
#endif
{META | CONTROL | 'Z', scrnextup}
,
{META | ' ', setmark}
,
{META | '?', help}
,
{META | '!', reposition}
,
{META | '.', setmark}
,
{META | '>', gotoeob}
,
{META | '<', gotobob}
,
{META | '~', unmark}
,
#if APROP
{META | 'A', apro}
,
#endif
{META | 'B', backword}
,
{META | 'C', capword}
,
{META | 'D', delfword}
,
#if CRYPT
{META | 'E', set_encryption_key}
,
#endif
{META | 'F', forwword}
,
{META | 'G', gotoline}
,
#if PKCODE
#if WORDPRO
{META | 'J', justpara}
,
#endif
#endif
{META | 'K', bindtokey}
,
{META | 'L', lowerword}
,
{META | 'M', setgmode}
,
#if WORDPRO
{META | 'N', gotoeop}
,
{META | 'P', gotobop}
,
{META | 'Q', fillpara}
,
#endif
{META | 'R', sreplace}
,
#if PKCODE
{META | 'S', forwsearch}
, /* alternative P.K. */
#else
#if BSD
{META | 'S', bktoshell}
,
#endif
#endif
{META | 'U', upperword}
,
{META | 'V', backpage}
,
{META | 'W', copyregion}
,
{META | 'X', namedcmd}
,
{META | 'Z', quickexit}
,
{META | 0x7F, delbword}
,
#if MSDOS
{SPEC | CONTROL | '_', forwhunt}
,
{SPEC | CONTROL | 'S', backhunt}
,
{SPEC | 71, gotobol}
,
{SPEC | 72, backline}
,
{SPEC | 73, backpage}
,
{SPEC | 75, backchar}
,
{SPEC | 77, forwchar}
,
{SPEC | 79, gotoeol}
,
{SPEC | 80, forwline}
,
{SPEC | 81, forwpage}
,
{SPEC | 82, insspace}
,
{SPEC | 83, forwdel}
,
{SPEC | 115, backword}
,
{SPEC | 116, forwword}
,
#if WORDPRO
{SPEC | 132, gotobop}
,
{SPEC | 118, gotoeop}
,
#endif
{SPEC | 84, cbuf1}
,
{SPEC | 85, cbuf2}
,
{SPEC | 86, cbuf3}
,
{SPEC | 87, cbuf4}
,
{SPEC | 88, cbuf5}
,
{SPEC | 89, cbuf6}
,
{SPEC | 90, cbuf7}
,
{SPEC | 91, cbuf8}
,
{SPEC | 92, cbuf9}
,
{SPEC | 93, cbuf10}
,
#if PKCODE
{SPEC | 117, gotoeob}
,
{SPEC | 119, gotobob}
,
{SPEC | 141, gotobop}
,
{SPEC | 145, gotoeop}
,
{SPEC | 146, yank}
,
{SPEC | 147, killregion}
,
#endif
#endif
#if VT220
{SPEC | '1', fisearch}
, /* VT220 keys */
{SPEC | '2', yank}
,
{SPEC | '3', killregion}
,
{SPEC | '4', setmark}
,
{SPEC | '5', backpage}
,
{SPEC | '6', forwpage}
,
{SPEC | 'A', backline}
,
{SPEC | 'B', forwline}
,
{SPEC | 'C', forwchar}
,
{SPEC | 'D', backchar}
,
{SPEC | 'c', metafn}
,
{SPEC | 'd', backchar}
,
{SPEC | 'e', forwline}
,
{SPEC | 'f', gotobob}
,
{SPEC | 'h', help}
,
{SPEC | 'i', cex}
,
#endif
{0x7F, backdel}
,
/* special internal bindings */
{ SPEC | META | 'W', wrapword }, /* called on word wrap */
{ SPEC | META | 'C', nullproc }, /* every command input */
{ SPEC | META | 'R', nullproc }, /* on file read */
{ SPEC | META | 'X', nullproc }, /* on window change P.K. */
{0, NULL}
} ; } ;
#endif /* EBIND_H_ */ #define NBINDS 256 /* max # of bound keys */
extern struct key_tab keytab[ NBINDS] ; /* key bind to functions table */

128
edef.h
View File

@ -1,128 +0,0 @@
/* edef.h
*
* Global variable definitions
*
* written by Dave G. Conroy
* modified by Steve Wilhite, George Jones
* greatly modified by Daniel Lawrence
* modified by Petri Kutvonen
*/
#ifndef EDEF_H_
#define EDEF_H_
#include <stdlib.h>
#include <string.h>
/* Some global fuction declarations. */
typedef int (*fn_t)(int, int);
/* Initialized global external declarations. */
extern int fillcol; /* Fill column */
extern int kbdm[]; /* Holds kayboard macro data */
extern char pat[]; /* Search pattern */
extern char rpat[]; /* Replacement pattern */
extern char *execstr; /* pointer to string to execute */
extern char golabel[]; /* current line to go to */
extern int execlevel; /* execution IF level */
extern int eolexist; /* does clear to EOL exist? */
extern int revexist; /* does reverse video exist? */
extern int flickcode; /* do flicker supression? */
extern char *modename[]; /* text names of modes */
extern char *mode2name[]; /* text names of modes */
extern char modecode[]; /* letters to represent modes */
extern struct key_tab keytab[]; /* key bind to functions table */
extern struct name_bind names[];/* name to function table */
extern int gmode; /* global editor mode */
extern int gflags; /* global control flag */
extern int gfcolor; /* global forgrnd color (white) */
extern int gbcolor; /* global backgrnd color (black) */
extern int gasave; /* global ASAVE size */
extern int gacount; /* count until next ASAVE */
extern int sgarbf; /* State of screen unknown */
extern int mpresf; /* Stuff in message line */
extern int clexec; /* command line execution flag */
extern int mstore; /* storing text to macro flag */
extern int discmd; /* display command flag */
extern int disinp; /* display input characters */
extern struct buffer *bstore; /* buffer to store macro text to */
extern int vtrow; /* Row location of SW cursor */
extern int vtcol; /* Column location of SW cursor */
extern int ttrow; /* Row location of HW cursor */
extern int ttcol; /* Column location of HW cursor */
extern int lbound; /* leftmost column of current line
being displayed */
extern int taboff; /* tab offset for display */
extern int metac; /* current meta character */
extern int ctlxc; /* current control X prefix char */
extern int reptc; /* current universal repeat char */
extern int abortc; /* current abort command char */
extern int quotec; /* quote char during mlreply() */
extern int tabmask;
extern char *cname[]; /* names of colors */
extern struct kill *kbufp; /* current kill buffer chunk pointer */
extern struct kill *kbufh; /* kill buffer header pointer */
extern int kused; /* # of bytes used in KB */
extern struct window *swindow; /* saved window pointer */
extern int cryptflag; /* currently encrypting? */
extern int *kbdptr; /* current position in keyboard buf */
extern int *kbdend; /* ptr to end of the keyboard */
extern int kbdmode; /* current keyboard macro mode */
extern int kbdrep; /* number of repetitions */
extern int restflag; /* restricted use? */
extern int lastkey; /* last keystoke */
extern int seed; /* random number seed */
extern long envram; /* # of bytes current in use by malloc */
extern int macbug; /* macro debuging flag */
extern char errorm[]; /* error literal */
extern char truem[]; /* true literal */
extern char falsem[]; /* false litereal */
extern int cmdstatus; /* last command status */
extern char palstr[]; /* palette string */
extern int saveflag; /* Flags, saved with the $target var */
extern char *fline; /* dynamic return line */
extern int flen; /* current length of fline */
extern int rval; /* return value of a subprocess */
#if PKCODE
extern int nullflag;
extern int justflag; /* justify, don't fill */
#endif
extern int overlap; /* line overlap in forw/back page */
extern int scrollcount; /* number of lines to scroll */
/* Uninitialized global external declarations. */
extern int currow; /* Cursor row */
extern int curcol; /* Cursor column */
extern int thisflag; /* Flags, this command */
extern int lastflag; /* Flags, last command */
extern int curgoal; /* Goal for C-P, C-N */
extern struct window *curwp; /* Current window */
extern struct buffer *curbp; /* Current buffer */
extern struct window *wheadp; /* Head of list of windows */
extern struct buffer *bheadp; /* Head of list of buffers */
extern struct buffer *blistp; /* Buffer for C-X C-B */
extern char sres[NBUFN]; /* Current screen resolution. */
extern char pat[]; /* Search pattern. */
extern char tap[]; /* Reversed pattern array. */
extern char rpat[]; /* Replacement pattern. */
extern unsigned int matchlen;
extern unsigned int mlenold;
extern char *patmatch;
extern struct line *matchline;
extern int matchoff;
extern char *dname[]; /* Directive name table. */
#if DEBUGM
/* Vars needed for macro debugging output. */
extern char outline[]; /* Global string to hold debug line text. */
#endif
/* Terminal table defined only in term.c */
extern struct terminal term;
#endif /* EDEF_H_ */

364
efunc.h
View File

@ -1,364 +0,0 @@
/* efunc.h
*
* Function declarations and names.
*
* This file list all the C code functions used and the names to use
* to bind keys to them. To add functions, declare it here in both the
* extern function list and the name binding table.
*
* modified by Petri Kutvonen
*/
/* External function declarations. */
/* word.c */
extern int wrapword(int f, int n);
extern int backword(int f, int n);
extern int forwword(int f, int n);
extern int upperword(int f, int n);
extern int lowerword(int f, int n);
extern int capword(int f, int n);
extern int delfword(int f, int n);
extern int delbword(int f, int n);
extern int inword(void);
extern int fillpara(int f, int n);
extern int justpara(int f, int n);
extern int killpara(int f, int n);
extern int wordcount(int f, int n);
/* window.c */
extern int reposition(int f, int n);
extern int redraw(int f, int n);
extern int nextwind(int f, int n);
extern int prevwind(int f, int n);
extern int mvdnwind(int f, int n);
extern int mvupwind(int f, int n);
extern int onlywind(int f, int n);
extern int delwind(int f, int n);
extern int splitwind(int f, int n);
extern int enlargewind(int f, int n);
extern int shrinkwind(int f, int n);
extern int resize(int f, int n);
extern int scrnextup(int f, int n);
extern int scrnextdw(int f, int n);
extern int savewnd(int f, int n);
extern int restwnd(int f, int n);
extern int newsize(int f, int n);
extern int newwidth(int f, int n);
extern int getwpos(void);
extern void cknewwindow(void);
extern struct window *wpopup(void); /* Pop up window creation. */
/* basic.c */
extern int gotobol(int f, int n);
extern int backchar(int f, int n);
extern int gotoeol(int f, int n);
extern int forwchar(int f, int n);
extern int gotoline(int f, int n);
extern int gotobob(int f, int n);
extern int gotoeob(int f, int n);
extern int forwline(int f, int n);
extern int backline(int f, int n);
extern int gotobop(int f, int n);
extern int gotoeop(int f, int n);
extern int forwpage(int f, int n);
extern int backpage(int f, int n);
extern int setmark(int f, int n);
extern int swapmark(int f, int n);
/* random.c */
extern int tabsize; /* Tab size (0: use real tabs). */
extern int setfillcol(int f, int n);
extern int showcpos(int f, int n);
extern int getcline(void);
extern int getccol(int bflg);
extern int setccol(int pos);
extern int twiddle(int f, int n);
extern int quote(int f, int n);
extern int insert_tab(int f, int n);
extern int detab(int f, int n);
extern int entab(int f, int n);
extern int trim(int f, int n);
extern int openline(int f, int n);
extern int insert_newline(int f, int n);
extern int cinsert(void);
extern int insbrace(int n, int c);
extern int inspound(void);
extern int deblank(int f, int n);
extern int indent(int f, int n);
extern int forwdel(int f, int n);
extern int backdel(int f, int n);
extern int killtext(int f, int n);
extern int setemode(int f, int n);
extern int delmode(int f, int n);
extern int setgmode(int f, int n);
extern int delgmode(int f, int n);
extern int adjustmode(int kind, int global);
extern int clrmes(int f, int n);
extern int writemsg(int f, int n);
extern int getfence(int f, int n);
extern int fmatch(int ch);
extern int istring(int f, int n);
extern int ovstring(int f, int n);
/* main.c */
extern void edinit(char *bname);
extern int execute(int c, int f, int n);
extern int quickexit(int f, int n);
extern int quit(int f, int n);
extern int ctlxlp(int f, int n);
extern int ctlxrp(int f, int n);
extern int ctlxe(int f, int n);
extern int ctrlg(int f, int n);
extern int rdonly(void);
extern int resterr(void);
extern int nullproc(int f, int n);
extern int metafn(int f, int n);
extern int cex(int f, int n);
extern int unarg(int f, int n);
extern int cexit(int status);
/* display.c */
extern void vtinit(void);
extern void vtfree(void);
extern void vttidy(void);
extern void vtmove(int row, int col);
extern int upscreen(int f, int n);
extern int update(int force);
extern void updpos(void);
extern void upddex(void);
extern void updgar(void);
extern int updupd(int force);
extern void upmode(void);
extern void movecursor(int row, int col);
extern void mlerase(void);
extern void mlwrite(const char *fmt, ...);
extern void mlforce(char *s);
extern void mlputs(char *s);
extern void getscreensize(int *widthp, int *heightp);
extern void sizesignal(int signr);
/* region.c */
extern int killregion(int f, int n);
extern int copyregion(int f, int n);
extern int lowerregion(int f, int n);
extern int upperregion(int f, int n);
extern int getregion(struct region *rp);
/* posix.c */
extern void ttopen(void);
extern void ttclose(void);
extern int ttputc(int c);
extern void ttflush(void);
extern int ttgetc(void);
extern int typahead(void);
/* input.c */
extern int mlyesno(char *prompt);
extern int mlreply(char *prompt, char *buf, int nbuf);
extern int mlreplyt(char *prompt, char *buf, int nbuf, int eolchar);
extern int ectoc(int c);
extern int ctoec(int c);
extern fn_t getname(void);
extern int tgetc(void);
extern int get1key(void);
extern int getcmd(void);
extern int getstring(char *prompt, char *buf, int nbuf, int eolchar);
extern void outstring(char *s);
extern void ostring(char *s);
/* bind.c */
extern int help(int f, int n);
extern int deskey(int f, int n);
extern int bindtokey(int f, int n);
extern int unbindkey(int f, int n);
extern int unbindchar(int c);
extern int desbind(int f, int n);
extern int apro(int f, int n);
extern int buildlist(int type, char *mstring);
extern int strinc(char *source, char *sub);
extern unsigned int getckey(int mflag);
extern int startup(char *sfname);
extern char *flook(char *fname, int hflag);
extern void cmdstr(int c, char *seq);
extern fn_t getbind(int c);
extern char *getfname(fn_t);
extern fn_t fncmatch(char *);
extern unsigned int stock(char *keyname);
extern char *transbind(char *skey);
/* buffer.c */
extern int usebuffer(int f, int n);
extern int nextbuffer(int f, int n);
extern int swbuffer(struct buffer *bp);
extern int killbuffer(int f, int n);
extern int zotbuf(struct buffer *bp);
extern int namebuffer(int f, int n);
extern int listbuffers(int f, int n);
extern int makelist(int iflag);
extern void ltoa(char *buf, int width, long num);
extern int addline(char *text);
extern int anycb(void);
extern int bclear(struct buffer *bp);
extern int unmark(int f, int n);
/* Lookup a buffer by name. */
extern struct buffer *bfind(char *bname, int cflag, int bflag);
/* file.c */
extern int fileread(int f, int n);
extern int insfile(int f, int n);
extern int filefind(int f, int n);
extern int viewfile(int f, int n);
extern int getfile(char *fname, int lockfl);
extern int readin(char *fname, int lockfl);
extern void makename(char *bname, char *fname);
extern void unqname(char *name);
extern int filewrite(int f, int n);
extern int filesave(int f, int n);
extern int writeout(char *fn);
extern int filename(int f, int n);
extern int ifile(char *fname);
/* fileio.c */
extern int ffropen(char *fn);
extern int ffwopen(char *fn);
extern int ffclose(void);
extern int ffputline(char *buf, int nbuf);
extern int ffgetline(void);
extern int fexist(char *fname);
/* exec.c */
extern int namedcmd(int f, int n);
extern int execcmd(int f, int n);
extern int docmd(char *cline);
extern char *token(char *src, char *tok, int size);
extern int macarg(char *tok);
extern int nextarg(char *prompt, char *buffer, int size, int terminator);
extern int storemac(int f, int n);
extern int storeproc(int f, int n);
extern int execproc(int f, int n);
extern int execbuf(int f, int n);
extern int dobuf(struct buffer *bp);
extern void freewhile(struct while_block *wp);
extern int execfile(int f, int n);
extern int dofile(char *fname);
extern int cbuf(int f, int n, int bufnum);
extern int cbuf1(int f, int n);
extern int cbuf2(int f, int n);
extern int cbuf3(int f, int n);
extern int cbuf4(int f, int n);
extern int cbuf5(int f, int n);
extern int cbuf6(int f, int n);
extern int cbuf7(int f, int n);
extern int cbuf8(int f, int n);
extern int cbuf9(int f, int n);
extern int cbuf10(int f, int n);
extern int cbuf11(int f, int n);
extern int cbuf12(int f, int n);
extern int cbuf13(int f, int n);
extern int cbuf14(int f, int n);
extern int cbuf15(int f, int n);
extern int cbuf16(int f, int n);
extern int cbuf17(int f, int n);
extern int cbuf18(int f, int n);
extern int cbuf19(int f, int n);
extern int cbuf20(int f, int n);
extern int cbuf21(int f, int n);
extern int cbuf22(int f, int n);
extern int cbuf23(int f, int n);
extern int cbuf24(int f, int n);
extern int cbuf25(int f, int n);
extern int cbuf26(int f, int n);
extern int cbuf27(int f, int n);
extern int cbuf28(int f, int n);
extern int cbuf29(int f, int n);
extern int cbuf30(int f, int n);
extern int cbuf31(int f, int n);
extern int cbuf32(int f, int n);
extern int cbuf33(int f, int n);
extern int cbuf34(int f, int n);
extern int cbuf35(int f, int n);
extern int cbuf36(int f, int n);
extern int cbuf37(int f, int n);
extern int cbuf38(int f, int n);
extern int cbuf39(int f, int n);
extern int cbuf40(int f, int n);
/* spawn.c */
extern int spawncli(int f, int n);
extern int bktoshell(int f, int n);
extern void rtfrmshell(void);
extern int spawn(int f, int n);
extern int execprg(int f, int n);
extern int pipecmd(int f, int n);
extern int filter_buffer(int f, int n);
extern int sys(char *cmd);
extern int shellprog(char *cmd);
extern int execprog(char *cmd);
/* search.c */
extern int forwsearch(int f, int n);
extern int forwhunt(int f, int n);
extern int backsearch(int f, int n);
extern int backhunt(int f, int n);
extern int mcscanner(struct magic *mcpatrn, int direct, int beg_or_end);
extern int scanner(const char *patrn, int direct, int beg_or_end);
extern int eq(unsigned char bc, unsigned char pc);
extern void savematch(void);
extern void rvstrcpy(char *rvstr, char *str);
extern int sreplace(int f, int n);
extern int qreplace(int f, int n);
extern int delins(int dlength, char *instr, int use_meta);
extern int expandp(char *srcstr, char *deststr, int maxlength);
extern int boundry(struct line *curline, int curoff, int dir);
extern void mcclear(void);
extern void rmcclear(void);
/* isearch.c */
extern int risearch(int f, int n);
extern int fisearch(int f, int n);
extern int isearch(int f, int n);
extern int checknext(char chr, char *patrn, int dir);
extern int scanmore(char *patrn, int dir);
extern int match_pat(char *patrn);
extern int promptpattern(char *prompt);
extern int get_char(void);
extern int uneat(void);
extern void reeat(int c);
/* eval.c */
extern void varinit(void);
extern char *gtfun(char *fname);
extern char *gtusr(char *vname);
extern char *gtenv(char *vname);
extern char *getkill(void);
extern int setvar(int f, int n);
extern void findvar(char *var, struct variable_description *vd, int size);
extern int svar(struct variable_description *var, char *value);
extern char *itoa(int i);
extern int gettyp(char *token);
extern char *getval(char *token);
extern int stol(char *val);
extern char *ltos(int val);
extern char *mkupper(char *str);
extern char *mklower(char *str);
extern int abs(int x);
extern int ernd(void);
extern int sindex(char *source, char *pattern);
extern char *xlat(char *source, char *lookup, char *trans);
/* crypt.c */
extern int set_encryption_key(int f, int n);
extern void myencrypt(char *bptr, unsigned len);
/* lock.c */
extern int lockchk(char *fname);
extern int lockrel(void);
extern int lock(char *fname);
extern int unlock(char *fname);
extern void lckerror(char *errstr);
/* pklock.c */
extern char *dolock(char *fname);
extern char *undolock(char *fname);

43
epath.h
View File

@ -1,43 +0,0 @@
/* EPATH.H
*
* This file contains certain info needed to locate the
* initialization (etc) files on a system dependent basis
*
* modified by Petri Kutvonen
*/
#ifndef EPATH_H_
#define EPATH_H_
/* possible names and paths of help files under different OSs */
static char *pathname[] =
#if MSDOS
{
"emacs.rc",
"emacs.hlp",
"\\sys\\public\\",
"\\usr\\bin\\",
"\\bin\\",
"\\",
""
};
#endif
#if V7 | BSD | USG
{
".emacsrc", "emacs.hlp",
#if PKCODE
"/usr/global/lib/", "/usr/local/bin/", "/usr/local/lib/",
#endif
"/usr/local/", "/usr/lib/", ""};
#endif
#if VMS
{
"emacs.rc", "emacs.hlp", "",
#if PKCODE
"sys$login:", "emacs_dir:",
#endif
"sys$sysdevice:[vmstools]"};
#endif
#endif /* EPATH_H_ */

423
estruct.h
View File

@ -1,3 +1,6 @@
#ifndef _ESTRUCT_H_
#define _ESTRUCT_H_
/* ESTRUCT.H /* ESTRUCT.H
* *
* Structure and preprocessor defines * Structure and preprocessor defines
@ -8,8 +11,6 @@
* modified by Petri Kutvonen * modified by Petri Kutvonen
*/ */
#define MAXCOL 500
#define MAXROW 500
#ifdef MSDOS #ifdef MSDOS
#undef MSDOS #undef MSDOS
@ -17,9 +18,6 @@
#ifdef EGA #ifdef EGA
#undef EGA #undef EGA
#endif #endif
#ifdef CTRLZ
#undef CTRLZ
#endif
/* Machine/OS definitions. */ /* Machine/OS definitions. */
@ -47,7 +45,7 @@
#undef BSD #undef BSD
#endif #endif
#if defined(SYSV) || defined(u3b2) || defined(_AIX) || (defined(i386) && defined(unix)) || defined(__hpux) #if defined(SYSV) || defined(u3b2) || defined(_AIX) || (defined(i386) && defined(unix)) || defined(__hpux) || defined( __unix__)
#define USG 1 /* System V UNIX */ #define USG 1 /* System V UNIX */
#else #else
#define USG 0 #define USG 0
@ -89,7 +87,9 @@
/* Debugging options */ /* Debugging options */
#define RAMSIZE 0 /* dynamic RAM memory usage tracking */ #define RAMSIZE 0 /* dynamic RAM memory usage tracking */
#define RAMSHOW 0 /* auto dynamic RAM reporting */ #if RAMSIZE
#define RAMSHOW 1 /* auto dynamic RAM reporting */
#endif
#ifndef AUTOCONF #ifndef AUTOCONF
@ -106,6 +106,17 @@
#define TERMCAP 0 /* Use TERMCAP */ #define TERMCAP 0 /* Use TERMCAP */
#define IBMPC 1 /* IBM-PC CGA/MONO/EGA driver */ #define IBMPC 1 /* IBM-PC CGA/MONO/EGA driver */
#elif defined( MINGW32)
#define VT220 (UNIX | VMS)
#define VT100 0
#define ANSI 0
#define VMSVT 0
#define VT52 0
#define TERMCAP 0
#define IBMPC 0
#else #else
#define VT220 (UNIX | VMS) #define VT220 (UNIX | VMS)
@ -121,16 +132,8 @@
/* Configuration options */ /* Configuration options */
#define CVMVAS 1 /* arguments to page forward/back in pages */
#define CLRMSG 0 /* space clears the message line with no insert */
#define CFENCE 1 /* fench matching in CMODE */ #define CFENCE 1 /* fench matching in CMODE */
#define TYPEAH 1 /* type ahead causes update to be skipped */
#define DEBUGM 1 /* $debug triggers macro debugging */
#define VISMAC 0 /* update display during keyboard macros */ #define VISMAC 0 /* update display during keyboard macros */
#define CTRLZ 0 /* add a ^Z at end of files under MSDOS only */
#define ADDCR 0 /* ajout d'un CR en fin de chaque ligne (ST520) */
#define NBRACE 1 /* new style brace matching command */
#define REVSTA 1 /* Status line appears in reverse video */
#ifndef AUTOCONF #ifndef AUTOCONF
@ -148,13 +151,6 @@
#endif /* Autoconf. */ #endif /* Autoconf. */
#define ISRCH 1 /* Incremental searches like ITS EMACS */
#define WORDPRO 1 /* Advanced word processing features */
#define APROP 1 /* Add code for Apropos command */
#define CRYPT 1 /* file encryption enabled? */
#define MAGIC 1 /* include regular expression matching? */
#define AEDIT 1 /* advanced editing options: en/detabbing */
#define PROC 1 /* named procedures */
#define CLEAN 0 /* de-alloc memory on exit */ #define CLEAN 0 /* de-alloc memory on exit */
#define ASCII 1 /* always using ASCII char sequences for now */ #define ASCII 1 /* always using ASCII char sequences for now */
@ -219,107 +215,8 @@
#define ENVFUNC 0 #define ENVFUNC 0
#endif #endif
/* Emacs global flag bit definitions (for gflags). */
#define GFREAD 1
/* Internal constants. */
#define NBINDS 256 /* max # of bound keys */
#define NFILEN 80 /* # of bytes, file name */
#define NBUFN 16 /* # of bytes, buffer name */
#define NLINE 256 /* # of bytes, input line */
#define NSTRING 128 /* # of bytes, string buffers */
#define NKBDM 256 /* # of strokes, keyboard macro */
#define NPAT 128 /* # of bytes, pattern */
#define HUGE 1000 /* Huge number */
#define NLOCKS 100 /* max # of file locks active */
#define NCOLORS 8 /* number of supported colors */
#define KBLOCK 250 /* sizeof kill buffer chunks */
#define CONTROL 0x10000000 /* Control flag, or'ed in */
#define META 0x20000000 /* Meta flag, or'ed in */
#define CTLX 0x40000000 /* ^X flag, or'ed in */
#define SPEC 0x80000000 /* special key (function keys) */
#ifdef FALSE
#undef FALSE
#endif
#ifdef TRUE
#undef TRUE
#endif
#define FALSE 0 /* False, no, bad, etc. */
#define TRUE 1 /* True, yes, good, etc. */
#define ABORT 2 /* Death, ^G, abort, etc. */
#define FAILED 3 /* not-quite fatal false return */
#define STOP 0 /* keyboard macro not in use */
#define PLAY 1 /* playing */
#define RECORD 2 /* recording */
/* Directive definitions */
#define DIF 0
#define DELSE 1
#define DENDIF 2
#define DGOTO 3
#define DRETURN 4
#define DENDM 5
#define DWHILE 6
#define DENDWHILE 7
#define DBREAK 8
#define DFORCE 9
#define NUMDIRS 10
/*
* PTBEG, PTEND, FORWARD, and REVERSE are all toggle-able values for
* the scan routines.
*/
#define PTBEG 0 /* Leave the point at the beginning on search */
#define PTEND 1 /* Leave the point at the end on search */
#define FORWARD 0 /* forward direction */
#define REVERSE 1 /* backwards direction */
#define FIOSUC 0 /* File I/O, success. */
#define FIOFNF 1 /* File I/O, file not found. */
#define FIOEOF 2 /* File I/O, end of file. */
#define FIOERR 3 /* File I/O, error. */
#define FIOMEM 4 /* File I/O, out of memory */
#define FIOFUN 5 /* File I/O, eod of file/bad line */
#define CFCPCN 0x0001 /* Last command was C-P, C-N */
#define CFKILL 0x0002 /* Last command was a kill */
#define BELL 0x07 /* a bell character */
#define TAB 0x09 /* a tab character */
#if V7 | USG | BSD
#define PATHCHR ':'
#else
#define PATHCHR ';'
#endif
#define INTWIDTH sizeof(int) * 3
/* Macro argument token types */
#define TKNUL 0 /* end-of-string */
#define TKARG 1 /* interactive argument */
#define TKBUF 2 /* buffer argument */
#define TKVAR 3 /* user variables */
#define TKENV 4 /* environment variables */
#define TKFUN 5 /* function.... */
#define TKDIR 6 /* directive */
#define TKLBL 7 /* line label */
#define TKLIT 8 /* numeric literal */
#define TKSTR 9 /* quoted string literal */
#define TKCMD 10 /* command name */
/* Internal defined functions */ /* Internal defined functions */
#define nextab(a) (a & ~tabmask) + (tabmask+1)
#ifdef abs #ifdef abs
#undef abs #undef abs
#endif #endif
@ -386,6 +283,9 @@
/* Dynamic RAM tracking and reporting redefinitions */ /* Dynamic RAM tracking and reporting redefinitions */
#if RAMSIZE #if RAMSIZE
#include <stdlib.h>
void *allocate( size_t size) ;
void release( void *ptr) ;
#define malloc allocate #define malloc allocate
#define free release #define free release
#endif #endif
@ -396,285 +296,8 @@
#if CLEAN #if CLEAN
#define exit(a) cexit(a) #define exit(a) cexit(a)
int cexit( int status) ;
#endif #endif
/*
* There is a window structure allocated for every active display window. The
* windows are kept in a big list, in top to bottom screen order, with the
* listhead at "wheadp". Each window contains its own values of dot and mark.
* The flag field contains some bits that are set by commands to guide
* redisplay. Although this is a bit of a compromise in terms of decoupling,
* the full blown redisplay is just too expensive to run for every input
* character.
*/
struct window {
struct window *w_wndp; /* Next window */
struct buffer *w_bufp; /* Buffer displayed in window */
struct line *w_linep; /* Top line in the window */
struct line *w_dotp; /* Line containing "." */
struct line *w_markp; /* Line containing "mark" */
int w_doto; /* Byte offset for "." */
int w_marko; /* Byte offset for "mark" */
char w_toprow; /* Origin 0 top row of window */
char w_ntrows; /* # of rows of text in window */
char w_force; /* If NZ, forcing row. */
char w_flag; /* Flags. */
#if COLOR
char w_fcolor; /* current forground color */
char w_bcolor; /* current background color */
#endif #endif
};
#define WFFORCE 0x01 /* Window needs forced reframe */
#define WFMOVE 0x02 /* Movement from line to line */
#define WFEDIT 0x04 /* Editing within a line */
#define WFHARD 0x08 /* Better to a full display */
#define WFMODE 0x10 /* Update mode line. */
#define WFCOLR 0x20 /* Needs a color change */
#if SCROLLCODE
#define WFKILLS 0x40 /* something was deleted */
#define WFINS 0x80 /* something was inserted */
#endif
/*
* Text is kept in buffers. A buffer header, described below, exists for every
* buffer in the system. The buffers are kept in a big list, so that commands
* that search for a buffer by name can find the buffer header. There is a
* safe store for the dot and mark in the header, but this is only valid if
* the buffer is not being displayed (that is, if "b_nwnd" is 0). The text for
* the buffer is kept in a circularly linked list of lines, with a pointer to
* the header line in "b_linep".
* Buffers may be "Inactive" which means the files associated with them
* have not been read in yet. These get read in at "use buffer" time.
*/
struct buffer {
struct buffer *b_bufp; /* Link to next struct buffer */
struct line *b_dotp; /* Link to "." struct line structure */
struct line *b_markp; /* The same as the above two, */
struct line *b_linep; /* Link to the header struct line */
int b_doto; /* Offset of "." in above struct line */
int b_marko; /* but for the "mark" */
int b_mode; /* editor mode of this buffer */
char b_active; /* window activated flag */
char b_nwnd; /* Count of windows on buffer */
char b_flag; /* Flags */
char b_fname[NFILEN]; /* File name */
char b_bname[NBUFN]; /* Buffer name */
#if CRYPT
char b_key[NPAT]; /* current encrypted key */
#endif
};
#define BFINVS 0x01 /* Internal invisable buffer */
#define BFCHG 0x02 /* Changed since last write */
#define BFTRUNC 0x04 /* buffer was truncated when read */
/* mode flags */
#define NUMMODES 10 /* # 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 */
#define MDCRYPT 0x0080 /* encrytion mode active */
#define MDASAVE 0x0100 /* auto-save mode */
/*
* The starting position of a region, and the size of the region in
* characters, is kept in a region structure. Used by the region commands.
*/
struct region {
struct line *r_linep; /* Origin struct line address. */
int r_offset; /* Origin struct line offset. */
long r_size; /* Length in characters. */
};
/*
* The editor communicates with the display using a high level interface. A
* "TERM" structure holds useful variables, and indirect pointers to routines
* that do useful operations. The low level get and put routines are here too.
* This lets a terminal, in addition to having non standard commands, have
* funny get and put character code too. The calls might get changed to
* "termp->t_field" style in the future, to make it possible to run more than
* one terminal type.
*/
struct terminal {
short t_mrow; /* max number of rows allowable */
short t_nrow; /* current number of rows used */
short t_mcol; /* max Number of columns. */
short t_ncol; /* current Number of columns. */
short t_margin; /* min margin for extended lines */
short t_scrsiz; /* size of scroll region " */
int t_pause; /* # times thru update to pause */
void (*t_open)(void); /* Open terminal at the start. */
void (*t_close)(void); /* Close terminal at end. */
void (*t_kopen)(void); /* Open keyboard */
void (*t_kclose)(void); /* close keyboard */
int (*t_getchar)(void); /* Get character from keyboard. */
int (*t_putchar)(int); /* Put character to display. */
void (*t_flush) (void); /* Flush output buffers. */
void (*t_move)(int, int);/* Move the cursor, origin 0. */
void (*t_eeol)(void); /* Erase to end of line. */
void (*t_eeop)(void); /* Erase to end of page. */
void (*t_beep)(void); /* Beep. */
void (*t_rev)(int); /* set reverse video state */
int (*t_rez)(char *); /* change screen resolution */
#if COLOR
int (*t_setfor) (); /* set forground color */
int (*t_setback) (); /* set background color */
#endif
#if SCROLLCODE
void (*t_scroll)(int, int,int); /* scroll a region of the screen */
#endif
};
/* TEMPORARY macros for terminal I/O (to be placed in a machine
dependant place later) */
#define TTopen (*term.t_open)
#define TTclose (*term.t_close)
#define TTkopen (*term.t_kopen)
#define TTkclose (*term.t_kclose)
#define TTgetc (*term.t_getchar)
#define TTputc (*term.t_putchar)
#define TTflush (*term.t_flush)
#define TTmove (*term.t_move)
#define TTeeol (*term.t_eeol)
#define TTeeop (*term.t_eeop)
#define TTbeep (*term.t_beep)
#define TTrev (*term.t_rev)
#define TTrez (*term.t_rez)
#if COLOR
#define TTforg (*term.t_setfor)
#define TTbacg (*term.t_setback)
#endif
/* Structure for the table of initial key bindings. */
struct key_tab {
int k_code; /* Key code */
int (*k_fp)(int, int); /* Routine to handle it */
};
/* Structure for the name binding table. */
struct name_bind {
char *n_name; /* name of function key */
int (*n_func)(int, int); /* function name is bound to */
};
/* The editor holds deleted text chunks in the struct kill buffer. The
* kill buffer is logically a stream of ascii characters, however
* due to its unpredicatable size, it gets implemented as a linked
* list of chunks. (The d_ prefix is for "deleted" text, as k_
* was taken up by the keycode structure).
*/
struct kill {
struct kill *d_next; /* Link to next chunk, NULL if last. */
char d_chunk[KBLOCK]; /* Deleted text. */
};
/* When emacs' command interpetor needs to get a variable's name,
* rather than it's value, it is passed back as a variable description
* structure. The v_num field is a index into the appropriate variable table.
*/
struct variable_description {
int v_type; /* Type of variable. */
int v_num; /* Ordinal pointer to variable in list. */
};
/* The !WHILE directive in the execution language needs to
* stack references to pending whiles. These are stored linked
* to each currently open procedure via a linked list of
* the following structure.
*/
struct while_block {
struct line *w_begin; /* ptr to !while statement */
struct line *w_end; /* ptr to the !endwhile statement */
int w_type; /* block type */
struct while_block *w_next; /* next while */
};
#define BTWHILE 1
#define BTBREAK 2
/*
* Incremental search defines.
*/
#if ISRCH
#define CMDBUFLEN 256 /* Length of our command buffer */
#define IS_ABORT 0x07 /* Abort the isearch */
#define IS_BACKSP 0x08 /* Delete previous char */
#define IS_TAB 0x09 /* Tab character (allowed search char) */
#define IS_NEWLINE 0x0D /* New line from keyboard (Carriage return) */
#define IS_QUOTE 0x11 /* Quote next character */
#define IS_REVERSE 0x12 /* Search backward */
#define IS_FORWARD 0x13 /* Search forward */
#define IS_VMSQUOTE 0x16 /* VMS quote character */
#define IS_VMSFORW 0x18 /* Search forward for VMS */
#define IS_QUIT 0x1B /* Exit the search */
#define IS_RUBOUT 0x7F /* Delete previous character */
/* IS_QUIT is no longer used, the variable metac is used instead */
#endif
#if defined(MAGIC)
/*
* Defines for the metacharacters in the regular expression
* search routines.
*/
#define MCNIL 0 /* Like the '\0' for strings. */
#define LITCHAR 1 /* Literal character, or string. */
#define ANY 2
#define CCL 3
#define NCCL 4
#define BOL 5
#define EOL 6
#define DITTO 7
#define CLOSURE 256 /* An or-able value. */
#define MASKCL (CLOSURE - 1)
#define MC_ANY '.' /* 'Any' character (except newline). */
#define MC_CCL '[' /* Character class. */
#define MC_NCCL '^' /* Negate character class. */
#define MC_RCCL '-' /* Range in character class. */
#define MC_ECCL ']' /* End of character class. */
#define MC_BOL '^' /* Beginning of line. */
#define MC_EOL '$' /* End of line. */
#define MC_CLOSURE '*' /* Closure - does not extend past newline. */
#define MC_DITTO '&' /* Use matched string in replacement. */
#define MC_ESC '\\' /* Escape - suppress meta-meaning. */
#define BIT(n) (1 << (n)) /* An integer with one bit set. */
#define CHCASE(c) ((c) ^ DIFCASE) /* Toggle the case of a letter. */
/* HICHAR - 1 is the largest character we will deal with.
* HIBYTE represents the number of bytes in the bitmap.
*/
#define HICHAR 256
#define HIBYTE HICHAR >> 3
/* Typedefs that define the meta-character structure for MAGIC mode searching
* (struct magic), and the meta-character structure for MAGIC mode replacement
* (struct magic_replacement).
*/
struct magic {
short int mc_type;
union {
int lchar;
char *cclmap;
} u;
};
struct magic_replacement {
short int mc_type;
char *rstr;
};
#endif /* MAGIC */

415
eval.c
View File

@ -1,3 +1,6 @@
/* eval.c -- implements eval.h */
#include "eval.h"
/* eval.c /* eval.c
* *
* Expression evaluation functions * Expression evaluation functions
@ -7,20 +10,289 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "basic.h"
#include "bind.h"
#include "buffer.h"
#include "display.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "exec.h"
#include "efunc.h" #include "execute.h"
#include "evar.h" #include "flook.h"
#include "input.h"
#include "line.h" #include "line.h"
#include "util.h" #include "random.h"
#include "search.h"
#include "terminal.h"
#include "termio.h"
#include "version.h" #include "version.h"
#include "window.h"
#define MAXVARS 255 #define MAXVARS 255
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#if DEBUGM
/* vars needed for macro debugging output */
char outline[ NSTRING] ; /* global string to hold debug line text */
#endif
int gflags = GFREAD ; /* global control flag */
int macbug = FALSE ; /* macro debuging flag */
int cmdstatus = TRUE ; /* last command status */
int flickcode = FALSE ; /* do flicker supression? */
int rval = 0 ; /* return value of a subprocess */
static int saveflag = 0 ; /* Flags, saved with the $target var */
long envram = 0l ; /* # of bytes current in use by malloc */
/* Max #chars in a var name. */
#define NVSIZE 10
/* Structure to hold user variables and their definitions. */
struct user_variable {
char u_name[NVSIZE + 1]; /* name of user variable */
char *u_value; /* value (string) */
};
static char errorm[] = "ERROR" ; /* error literal */
static int seed = 0 ; /* random number seed */
static char *ltos( int val) ;
/* List of recognized environment variables. */
static const char *envars[] = {
"fillcol", /* current fill column */
"pagelen", /* number of lines used by editor */
"curcol", /* current column pos of cursor */
"curline", /* current line in file */
"ram", /* ram in use by malloc */
"flicker", /* flicker supression */
"curwidth", /* current screen width */
"cbufname", /* current buffer name */
"cfname", /* current file name */
"sres", /* current screen resolution */
"debug", /* macro debugging */
"status", /* returns the status of the last command */
"palette", /* current palette string */
"asave", /* # of chars between auto-saves */
"acount", /* # of chars until next auto-save */
"lastkey", /* last keyboard char struck */
"curchar", /* current character under the cursor */
"discmd", /* display commands on command line */
"version", /* current version number */
"progname", /* returns current prog name - "MicroEMACS" */
"seed", /* current random number seed */
"disinp", /* display command line input characters */
"wline", /* # of lines in current window */
"cwline", /* current screen line in window */
"target", /* target for line moves */
"search", /* search pattern */
"replace", /* replacement pattern */
"match", /* last matched magic pattern */
"kill", /* kill buffer (read only) */
"cmode", /* mode of current buffer */
"gmode", /* global modes */
"tpause", /* length to pause for paren matching */
"pending", /* type ahead pending flag */
"lwidth", /* width of current line */
"line", /* text of current line */
"gflags", /* global internal emacs flags */
"rval", /* child process return value */
"tab", /* tab 4 or 8 */
"overlap",
"jump",
#if SCROLLCODE
"scroll", /* scroll enabled */
#endif
};
/* And its preprocesor definitions. */
#define EVFILLCOL 0
#define EVPAGELEN 1
#define EVCURCOL 2
#define EVCURLINE 3
#define EVRAM 4
#define EVFLICKER 5
#define EVCURWIDTH 6
#define EVCBUFNAME 7
#define EVCFNAME 8
#define EVSRES 9
#define EVDEBUG 10
#define EVSTATUS 11
#define EVPALETTE 12
#define EVASAVE 13
#define EVACOUNT 14
#define EVLASTKEY 15
#define EVCURCHAR 16
#define EVDISCMD 17
#define EVVERSION 18
#define EVPROGNAME 19
#define EVSEED 20
#define EVDISINP 21
#define EVWLINE 22
#define EVCWLINE 23
#define EVTARGET 24
#define EVSEARCH 25
#define EVREPLACE 26
#define EVMATCH 27
#define EVKILL 28
#define EVCMODE 29
#define EVGMODE 30
#define EVTPAUSE 31
#define EVPENDING 32
#define EVLWIDTH 33
#define EVLINE 34
#define EVGFLAGS 35
#define EVRVAL 36
#define EVTAB 37
#define EVOVERLAP 38
#define EVSCROLLCOUNT 39
#define EVSCROLL 40
enum function_type {
NILNAMIC = 0,
MONAMIC,
DYNAMIC,
TRINAMIC,
};
/* List of recognized user functions. */
static struct {
const char f_name[ 4] ;
const enum function_type f_type ;
} funcs[] = {
{ "add", DYNAMIC }, /* add two numbers together */
{ "sub", DYNAMIC }, /* subtraction */
{ "tim", DYNAMIC }, /* multiplication */
{ "div", DYNAMIC }, /* division */
{ "mod", DYNAMIC }, /* mod */
{ "neg", MONAMIC }, /* negate */
{ "cat", DYNAMIC }, /* concatinate string */
{ "lef", DYNAMIC }, /* left string(string, len) */
{ "rig", DYNAMIC }, /* right string(string, pos) */
{ "mid", TRINAMIC }, /* mid string(string, pos, len) */
{ "not", MONAMIC }, /* logical not */
{ "equ", DYNAMIC }, /* logical equality check */
{ "les", DYNAMIC }, /* logical less than */
{ "gre", DYNAMIC }, /* logical greater than */
{ "seq", DYNAMIC }, /* string logical equality check */
{ "sle", DYNAMIC }, /* string logical less than */
{ "sgr", DYNAMIC }, /* string logical greater than */
{ "ind", MONAMIC }, /* evaluate indirect value */
{ "and", DYNAMIC }, /* logical and */
{ "or", DYNAMIC }, /* logical or */
{ "len", MONAMIC }, /* string length */
{ "upp", MONAMIC }, /* uppercase string */
{ "low", MONAMIC }, /* lower case string */
{ "tru", MONAMIC }, /* Truth of the universe logical test */
{ "asc", MONAMIC }, /* char to integer conversion */
{ "chr", MONAMIC }, /* integer to char conversion */
{ "gtk", NILNAMIC }, /* get 1 charater */
{ "rnd", MONAMIC }, /* get a random number */
{ "abs", MONAMIC }, /* absolute value of a number */
{ "sin", DYNAMIC }, /* find the index of one string in another */
{ "env", MONAMIC }, /* retrieve a system environment var */
{ "bin", MONAMIC }, /* loopup what function name is bound to a key */
{ "exi", MONAMIC }, /* check if a file exists */
{ "fin", MONAMIC }, /* look for a file on the path... */
{ "ban", DYNAMIC }, /* bitwise and 9-10-87 jwm */
{ "bor", DYNAMIC }, /* bitwise or 9-10-87 jwm */
{ "bxo", DYNAMIC }, /* bitwise xor 9-10-87 jwm */
{ "bno", MONAMIC }, /* bitwise not */
{ "xla", TRINAMIC }, /* XLATE character string translation */
};
/* And its preprocesor definitions. */
#define UFADD 0
#define UFSUB 1
#define UFTIMES 2
#define UFDIV 3
#define UFMOD 4
#define UFNEG 5
#define UFCAT 6
#define UFLEFT 7
#define UFRIGHT 8
#define UFMID 9
#define UFNOT 10
#define UFEQUAL 11
#define UFLESS 12
#define UFGREATER 13
#define UFSEQUAL 14
#define UFSLESS 15
#define UFSGREAT 16
#define UFIND 17
#define UFAND 18
#define UFOR 19
#define UFLENGTH 20
#define UFUPPER 21
#define UFLOWER 22
#define UFTRUTH 23
#define UFASCII 24
#define UFCHR 25
#define UFGTKEY 26
#define UFRND 27
#define UFABS 28
#define UFSINDEX 29
#define UFENV 30
#define UFBIND 31
#define UFEXIST 32
#define UFFIND 33
#define UFBAND 34
#define UFBOR 35
#define UFBXOR 36
#define UFBNOT 37
#define UFXLATE 38
/* User variables */ /* User variables */
static struct user_variable uv[MAXVARS + 1]; static struct user_variable uv[MAXVARS + 1];
/* When emacs' command interpetor needs to get a variable's name,
* rather than it's value, it is passed back as a variable description
* structure. The v_num field is a index into the appropriate variable table.
*/
struct variable_description {
int v_type; /* Type of variable. */
int v_num; /* Ordinal pointer to variable in list. */
};
static void findvar( char *var, struct variable_description *vd, int size) ;
static int svar( struct variable_description *var, char *value) ;
/*
* putctext:
* replace the current line with the passed in text
*
* char *iline; contents of new line
*/
static int putctext( char *iline)
{
int status;
/* delete the current line */
curwp->w_doto = 0; /* starting at the beginning of the line */
if ((status = killtext(TRUE, 1)) != TRUE)
return status;
/* insert the new line */
if ((status = linstr(iline)) != TRUE)
return status;
status = lnewline();
backline(TRUE, 1);
return status;
}
/* Initialize the user variable list. */ /* Initialize the user variable list. */
void varinit(void) void varinit(void)
{ {
@ -76,17 +348,17 @@ char *gtfun(char *fname)
/* and now evaluate it! */ /* and now evaluate it! */
switch (fnum) { switch (fnum) {
case UFADD: case UFADD:
return itoa(atoi(arg1) + atoi(arg2)); return i_to_a(atoi(arg1) + atoi(arg2));
case UFSUB: case UFSUB:
return itoa(atoi(arg1) - atoi(arg2)); return i_to_a(atoi(arg1) - atoi(arg2));
case UFTIMES: case UFTIMES:
return itoa(atoi(arg1) * atoi(arg2)); return i_to_a(atoi(arg1) * atoi(arg2));
case UFDIV: case UFDIV:
return itoa(atoi(arg1) / atoi(arg2)); return i_to_a(atoi(arg1) / atoi(arg2));
case UFMOD: case UFMOD:
return itoa(atoi(arg1) % atoi(arg2)); return i_to_a(atoi(arg1) % atoi(arg2));
case UFNEG: case UFNEG:
return itoa(-atoi(arg1)); return i_to_a(-atoi(arg1));
case UFCAT: case UFCAT:
strcpy(result, arg1); strcpy(result, arg1);
return strcat(result, arg2); return strcat(result, arg2);
@ -119,7 +391,7 @@ char *gtfun(char *fname)
case UFOR: case UFOR:
return ltos(stol(arg1) || stol(arg2)); return ltos(stol(arg1) || stol(arg2));
case UFLENGTH: case UFLENGTH:
return itoa(strlen(arg1)); return i_to_a(strlen(arg1));
case UFUPPER: case UFUPPER:
return mkupper(arg1); return mkupper(arg1);
case UFLOWER: case UFLOWER:
@ -127,7 +399,7 @@ char *gtfun(char *fname)
case UFTRUTH: case UFTRUTH:
return ltos(atoi(arg1) == 42); return ltos(atoi(arg1) == 42);
case UFASCII: case UFASCII:
return itoa((int) arg1[0]); return i_to_a((int) arg1[0]);
case UFCHR: case UFCHR:
result[0] = atoi(arg1); result[0] = atoi(arg1);
result[1] = 0; result[1] = 0;
@ -137,11 +409,11 @@ char *gtfun(char *fname)
result[1] = 0; result[1] = 0;
return result; return result;
case UFRND: case UFRND:
return itoa((ernd() % abs(atoi(arg1))) + 1); return i_to_a((ernd() % abs(atoi(arg1))) + 1);
case UFABS: case UFABS:
return itoa(abs(atoi(arg1))); return i_to_a(abs(atoi(arg1)));
case UFSINDEX: case UFSINDEX:
return itoa(sindex(arg1, arg2)); return i_to_a(sindex(arg1, arg2));
case UFENV: case UFENV:
#if ENVFUNC #if ENVFUNC
tsp = getenv(arg1); tsp = getenv(arg1);
@ -157,13 +429,13 @@ char *gtfun(char *fname)
tsp = flook(arg1, TRUE); tsp = flook(arg1, TRUE);
return tsp == NULL ? "" : tsp; return tsp == NULL ? "" : tsp;
case UFBAND: case UFBAND:
return itoa(atoi(arg1) & atoi(arg2)); return i_to_a(atoi(arg1) & atoi(arg2));
case UFBOR: case UFBOR:
return itoa(atoi(arg1) | atoi(arg2)); return i_to_a(atoi(arg1) | atoi(arg2));
case UFBXOR: case UFBXOR:
return itoa(atoi(arg1) ^ atoi(arg2)); return i_to_a(atoi(arg1) ^ atoi(arg2));
case UFBNOT: case UFBNOT:
return itoa(~atoi(arg1)); return i_to_a(~atoi(arg1));
case UFXLATE: case UFXLATE:
return xlat(arg1, arg2, arg3); return xlat(arg1, arg2, arg3);
} }
@ -193,8 +465,6 @@ char *gtusr(char *vname)
return errorm; return errorm;
} }
extern char *getkill(void);
/* /*
* gtenv() * gtenv()
* *
@ -227,19 +497,19 @@ char *gtenv(char *vname)
/* otherwise, fetch the appropriate value */ /* otherwise, fetch the appropriate value */
switch (vnum) { switch (vnum) {
case EVFILLCOL: case EVFILLCOL:
return itoa(fillcol); return i_to_a(fillcol);
case EVPAGELEN: case EVPAGELEN:
return itoa(term.t_nrow + 1); return i_to_a(term.t_nrow + 1);
case EVCURCOL: case EVCURCOL:
return itoa(getccol(FALSE)); return i_to_a(getccol(FALSE));
case EVCURLINE: case EVCURLINE:
return itoa(getcline()); return i_to_a(getcline());
case EVRAM: case EVRAM:
return itoa((int) (envram / 1024l)); return i_to_a((int) (envram / 1024l));
case EVFLICKER: case EVFLICKER:
return ltos(flickcode); return ltos(flickcode);
case EVCURWIDTH: case EVCURWIDTH:
return itoa(term.t_ncol); return i_to_a(term.t_ncol);
case EVCBUFNAME: case EVCBUFNAME:
return curbp->b_bname; return curbp->b_bname;
case EVCFNAME: case EVCFNAME:
@ -250,18 +520,22 @@ char *gtenv(char *vname)
return ltos(macbug); return ltos(macbug);
case EVSTATUS: case EVSTATUS:
return ltos(cmdstatus); return ltos(cmdstatus);
case EVPALETTE: case EVPALETTE: {
static char palstr[ 49] = "" ; /* palette string */
return palstr; return palstr;
}
case EVASAVE: case EVASAVE:
return itoa(gasave); return i_to_a(gasave);
case EVACOUNT: case EVACOUNT:
return itoa(gacount); return i_to_a(gacount);
case EVLASTKEY: case EVLASTKEY:
return itoa(lastkey); return i_to_a(lastkey);
case EVCURCHAR: case EVCURCHAR:
return (curwp->w_dotp->l_used == return (curwp->w_dotp->l_used ==
curwp->w_doto ? itoa('\n') : curwp->w_doto ? i_to_a('\n') :
itoa(lgetc(curwp->w_dotp, curwp->w_doto))); i_to_a(lgetc(curwp->w_dotp, curwp->w_doto)));
case EVDISCMD: case EVDISCMD:
return ltos(discmd); return ltos(discmd);
case EVVERSION: case EVVERSION:
@ -269,16 +543,16 @@ char *gtenv(char *vname)
case EVPROGNAME: case EVPROGNAME:
return PROGRAM_NAME_LONG; return PROGRAM_NAME_LONG;
case EVSEED: case EVSEED:
return itoa(seed); return i_to_a(seed);
case EVDISINP: case EVDISINP:
return ltos(disinp); return ltos(disinp);
case EVWLINE: case EVWLINE:
return itoa(curwp->w_ntrows); return i_to_a(curwp->w_ntrows);
case EVCWLINE: case EVCWLINE:
return itoa(getwpos()); return i_to_a(getwpos());
case EVTARGET: case EVTARGET:
saveflag = lastflag; saveflag = lastflag;
return itoa(curgoal); return i_to_a(curgoal);
case EVSEARCH: case EVSEARCH:
return pat; return pat;
case EVREPLACE: case EVREPLACE:
@ -288,11 +562,11 @@ char *gtenv(char *vname)
case EVKILL: case EVKILL:
return getkill(); return getkill();
case EVCMODE: case EVCMODE:
return itoa(curbp->b_mode); return i_to_a(curbp->b_mode);
case EVGMODE: case EVGMODE:
return itoa(gmode); return i_to_a(gmode);
case EVTPAUSE: case EVTPAUSE:
return itoa(term.t_pause); return i_to_a(term.t_pause);
case EVPENDING: case EVPENDING:
#if TYPEAH #if TYPEAH
return ltos(typahead()); return ltos(typahead());
@ -300,19 +574,19 @@ char *gtenv(char *vname)
return falsem; return falsem;
#endif #endif
case EVLWIDTH: case EVLWIDTH:
return itoa(llength(curwp->w_dotp)); return i_to_a(llength(curwp->w_dotp));
case EVLINE: case EVLINE:
return getctext(); return getctext();
case EVGFLAGS: case EVGFLAGS:
return itoa(gflags); return i_to_a(gflags);
case EVRVAL: case EVRVAL:
return itoa(rval); return i_to_a(rval);
case EVTAB: case EVTAB:
return itoa(tabmask + 1); return i_to_a(tabmask + 1);
case EVOVERLAP: case EVOVERLAP:
return itoa(overlap); return i_to_a(overlap);
case EVSCROLLCOUNT: case EVSCROLLCOUNT:
return itoa(scrollcount); return i_to_a(scrollcount);
#if SCROLLCODE #if SCROLLCODE
case EVSCROLL: case EVSCROLL:
return ltos(term.t_scroll != NULL); return ltos(term.t_scroll != NULL);
@ -324,30 +598,6 @@ char *gtenv(char *vname)
exit(-12); /* again, we should never get here */ exit(-12); /* again, we should never get here */
} }
/*
* return some of the contents of the kill buffer
*/
char *getkill(void)
{
int size; /* max number of chars to return */
static char value[NSTRING]; /* temp buffer for value */
if (kbufh == NULL)
/* no kill buffer....just a null string */
value[0] = 0;
else {
/* copy in the contents... */
if (kused < NSTRING)
size = kused;
else
size = NSTRING - 1;
strncpy(value, kbufh->d_chunk, size);
}
/* and return the constructed value */
return value;
}
/* /*
* set a variable * set a variable
* *
@ -357,10 +607,6 @@ char *getkill(void)
int setvar(int f, int n) int setvar(int f, int n)
{ {
int status; /* status return */ int status; /* status return */
#if DEBUGM
char *sp; /* temp string pointer */
char *ep; /* ptr to end of outline */
#endif
struct variable_description vd; /* variable num/type */ struct variable_description vd; /* variable num/type */
char var[NVSIZE + 1]; /* name of variable to fetch */ char var[NVSIZE + 1]; /* name of variable to fetch */
char value[NSTRING]; /* value to set variable to */ char value[NSTRING]; /* value to set variable to */
@ -386,7 +632,7 @@ int setvar(int f, int n)
/* get the value for that variable */ /* get the value for that variable */
if (f == TRUE) if (f == TRUE)
strcpy(value, itoa(n)); strcpy(value, i_to_a(n));
else { else {
status = mlreply("Value: ", &value[0], NSTRING); status = mlreply("Value: ", &value[0], NSTRING);
if (status != TRUE) if (status != TRUE)
@ -401,6 +647,8 @@ int setvar(int f, int n)
that effect here. */ that effect here. */
if (macbug) { if (macbug) {
char *sp ; /* temp string pointer */
strcpy(outline, "((("); strcpy(outline, "(((");
/* assignment status */ /* assignment status */
@ -419,6 +667,8 @@ int setvar(int f, int n)
sp = outline; sp = outline;
while (*sp) while (*sp)
if (*sp++ == '%') { if (*sp++ == '%') {
char *ep ; /* ptr to end of outline */
/* advance to the end */ /* advance to the end */
ep = --sp; ep = --sp;
while (*ep++); while (*ep++);
@ -455,7 +705,7 @@ int setvar(int f, int n)
* @vd: structure to hold type and pointer. * @vd: structure to hold type and pointer.
* @size: size of variable array. * @size: size of variable array.
*/ */
void findvar(char *var, struct variable_description *vd, int size) static void findvar(char *var, struct variable_description *vd, int size)
{ {
int vnum; /* subscript in variable arrays */ int vnum; /* subscript in variable arrays */
int vtype; /* type to return */ int vtype; /* type to return */
@ -513,7 +763,7 @@ fvar:
* @var: variable to set. * @var: variable to set.
* @value: value to set to. * @value: value to set to.
*/ */
int svar(struct variable_description *var, char *value) static int svar(struct variable_description *var, char *value)
{ {
int vnum; /* ordinal number of var refrenced */ int vnum; /* ordinal number of var refrenced */
int vtype; /* type of variable to set */ int vtype; /* type of variable to set */
@ -679,14 +929,16 @@ int svar(struct variable_description *var, char *value)
} }
/* /*
* itoa: * i_to_a:
* integer to ascii string.......... This is too * integer to ascii string.......... This is too
* inconsistant to use the system's * inconsistant to use the system's
* *
* int i; integer to translate to a string * int i; integer to translate to a string
*/ */
char *itoa(int i) char *i_to_a(int i)
{ {
#define INTWIDTH sizeof( int) * 3
int digit; /* current digit being used */ int digit; /* current digit being used */
char *sp; /* pointer into result */ char *sp; /* pointer into result */
int sign; /* sign of resulting number */ int sign; /* sign of resulting number */
@ -869,8 +1121,11 @@ int stol(char *val)
* *
* int val; value to translate * int val; value to translate
*/ */
char *ltos(int val) static char *ltos( int val)
{ {
static char truem[] = "TRUE" ; /* true literal */
static char falsem[] = "FALSE" ; /* false literal */
if (val) if (val)
return truem; return truem;
else else

56
eval.h Normal file
View File

@ -0,0 +1,56 @@
#ifndef _EVAL_H_
#define _EVAL_H_
#define DEBUGM 1 /* $debug triggers macro debugging */
#if DEBUGM
/* Vars needed for macro debugging output. */
extern char outline[] ; /* Global string to hold debug line text. */
#endif
/* Emacs global flag bit definitions (for gflags). */
#define GFREAD 1
extern int gflags ; /* global control flag */
extern int macbug ; /* macro debuging flag */
extern int cmdstatus ; /* last command status */
extern int flickcode ; /* do flicker supression? */
extern int rval ; /* return value of a subprocess */
extern long envram ; /* # of bytes current in use by malloc */
/* Macro argument token types */
#define TKNUL 0 /* end-of-string */
#define TKARG 1 /* interactive argument */
#define TKBUF 2 /* buffer argument */
#define TKVAR 3 /* user variables */
#define TKENV 4 /* environment variables */
#define TKFUN 5 /* function.... */
#define TKDIR 6 /* directive */
#define TKLBL 7 /* line label */
#define TKLIT 8 /* numeric literal */
#define TKSTR 9 /* quoted string literal */
#define TKCMD 10 /* command name */
int gettyp( char *token) ;
void varinit( void) ;
char *gtfun( char *fname) ;
char *gtusr( char *vname) ;
char *gtenv( char *vname) ;
int setvar( int f, int n) ;
char *i_to_a( int i) ;
char *getval( char *token) ;
int stol( char *val) ;
char *mkupper( char *str) ;
char *mklower( char *str) ;
int abs( int x) ;
int ernd( void) ;
int sindex( char *source, char *pattern) ;
char *xlat( char *source, char *lookup, char *trans) ;
#endif

209
evar.h
View File

@ -1,209 +0,0 @@
/* EVAR.H
*
* Environment and user variable definitions
*
* written 1986 by Daniel Lawrence
* modified by Petri Kutvonen
*/
#ifndef EVAR_H_
#define EVAR_H_
/* Max #chars in a var name. */
#define NVSIZE 10
/* Structure to hold user variables and their definitions. */
struct user_variable {
char u_name[NVSIZE + 1]; /* name of user variable */
char *u_value; /* value (string) */
};
/* List of recognized environment variables. */
static char *envars[] = {
"fillcol", /* current fill column */
"pagelen", /* number of lines used by editor */
"curcol", /* current column pos of cursor */
"curline", /* current line in file */
"ram", /* ram in use by malloc */
"flicker", /* flicker supression */
"curwidth", /* current screen width */
"cbufname", /* current buffer name */
"cfname", /* current file name */
"sres", /* current screen resolution */
"debug", /* macro debugging */
"status", /* returns the status of the last command */
"palette", /* current palette string */
"asave", /* # of chars between auto-saves */
"acount", /* # of chars until next auto-save */
"lastkey", /* last keyboard char struck */
"curchar", /* current character under the cursor */
"discmd", /* display commands on command line */
"version", /* current version number */
"progname", /* returns current prog name - "MicroEMACS" */
"seed", /* current random number seed */
"disinp", /* display command line input characters */
"wline", /* # of lines in current window */
"cwline", /* current screen line in window */
"target", /* target for line moves */
"search", /* search pattern */
"replace", /* replacement pattern */
"match", /* last matched magic pattern */
"kill", /* kill buffer (read only) */
"cmode", /* mode of current buffer */
"gmode", /* global modes */
"tpause", /* length to pause for paren matching */
"pending", /* type ahead pending flag */
"lwidth", /* width of current line */
"line", /* text of current line */
"gflags", /* global internal emacs flags */
"rval", /* child process return value */
"tab", /* tab 4 or 8 */
"overlap",
"jump",
#if SCROLLCODE
"scroll", /* scroll enabled */
#endif
};
/* And its preprocesor definitions. */
#define EVFILLCOL 0
#define EVPAGELEN 1
#define EVCURCOL 2
#define EVCURLINE 3
#define EVRAM 4
#define EVFLICKER 5
#define EVCURWIDTH 6
#define EVCBUFNAME 7
#define EVCFNAME 8
#define EVSRES 9
#define EVDEBUG 10
#define EVSTATUS 11
#define EVPALETTE 12
#define EVASAVE 13
#define EVACOUNT 14
#define EVLASTKEY 15
#define EVCURCHAR 16
#define EVDISCMD 17
#define EVVERSION 18
#define EVPROGNAME 19
#define EVSEED 20
#define EVDISINP 21
#define EVWLINE 22
#define EVCWLINE 23
#define EVTARGET 24
#define EVSEARCH 25
#define EVREPLACE 26
#define EVMATCH 27
#define EVKILL 28
#define EVCMODE 29
#define EVGMODE 30
#define EVTPAUSE 31
#define EVPENDING 32
#define EVLWIDTH 33
#define EVLINE 34
#define EVGFLAGS 35
#define EVRVAL 36
#define EVTAB 37
#define EVOVERLAP 38
#define EVSCROLLCOUNT 39
#define EVSCROLL 40
enum function_type {
NILNAMIC = 0,
MONAMIC,
DYNAMIC,
TRINAMIC,
};
/* List of recognized user functions. */
struct user_function {
char *f_name;
enum function_type f_type;
};
static struct user_function funcs[] = {
{ "add", DYNAMIC }, /* add two numbers together */
{ "sub", DYNAMIC }, /* subtraction */
{ "tim", DYNAMIC }, /* multiplication */
{ "div", DYNAMIC }, /* division */
{ "mod", DYNAMIC }, /* mod */
{ "neg", MONAMIC }, /* negate */
{ "cat", DYNAMIC }, /* concatinate string */
{ "lef", DYNAMIC }, /* left string(string, len) */
{ "rig", DYNAMIC }, /* right string(string, pos) */
{ "mid", TRINAMIC }, /* mid string(string, pos, len) */
{ "not", MONAMIC }, /* logical not */
{ "equ", DYNAMIC }, /* logical equality check */
{ "les", DYNAMIC }, /* logical less than */
{ "gre", DYNAMIC }, /* logical greater than */
{ "seq", DYNAMIC }, /* string logical equality check */
{ "sle", DYNAMIC }, /* string logical less than */
{ "sgr", DYNAMIC }, /* string logical greater than */
{ "ind", MONAMIC }, /* evaluate indirect value */
{ "and", DYNAMIC }, /* logical and */
{ "or", DYNAMIC }, /* logical or */
{ "len", MONAMIC }, /* string length */
{ "upp", MONAMIC }, /* uppercase string */
{ "low", MONAMIC }, /* lower case string */
{ "tru", MONAMIC }, /* Truth of the universe logical test */
{ "asc", MONAMIC }, /* char to integer conversion */
{ "chr", MONAMIC }, /* integer to char conversion */
{ "gtk", NILNAMIC }, /* get 1 charater */
{ "rnd", MONAMIC }, /* get a random number */
{ "abs", MONAMIC }, /* absolute value of a number */
{ "sin", DYNAMIC }, /* find the index of one string in another */
{ "env", MONAMIC }, /* retrieve a system environment var */
{ "bin", MONAMIC }, /* loopup what function name is bound to a key */
{ "exi", MONAMIC }, /* check if a file exists */
{ "fin", MONAMIC }, /* look for a file on the path... */
{ "ban", DYNAMIC }, /* bitwise and 9-10-87 jwm */
{ "bor", DYNAMIC }, /* bitwise or 9-10-87 jwm */
{ "bxo", DYNAMIC }, /* bitwise xor 9-10-87 jwm */
{ "bno", MONAMIC }, /* bitwise not */
{ "xla", TRINAMIC }, /* XLATE character string translation */
};
/* And its preprocesor definitions. */
#define UFADD 0
#define UFSUB 1
#define UFTIMES 2
#define UFDIV 3
#define UFMOD 4
#define UFNEG 5
#define UFCAT 6
#define UFLEFT 7
#define UFRIGHT 8
#define UFMID 9
#define UFNOT 10
#define UFEQUAL 11
#define UFLESS 12
#define UFGREATER 13
#define UFSEQUAL 14
#define UFSLESS 15
#define UFSGREAT 16
#define UFIND 17
#define UFAND 18
#define UFOR 19
#define UFLENGTH 20
#define UFUPPER 21
#define UFLOWER 22
#define UFTRUTH 23
#define UFASCII 24
#define UFCHR 25
#define UFGTKEY 26
#define UFRND 27
#define UFABS 28
#define UFSINDEX 29
#define UFENV 30
#define UFBIND 31
#define UFEXIST 32
#define UFFIND 33
#define UFBAND 34
#define UFBOR 35
#define UFBXOR 36
#define UFBNOT 37
#define UFXLATE 38
#endif /* EVAR_H_ */

117
exec.c
View File

@ -1,3 +1,6 @@
/* exec.c -- implements exec.h */
#include "exec.h"
/* exec.c /* exec.c
* *
* This file is for functions dealing with execution of * This file is for functions dealing with execution of
@ -8,11 +11,74 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "buffer.h"
#include "bind.h"
#include "display.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "eval.h"
#include "efunc.h" #include "file.h"
#include "flook.h"
#include "input.h"
#include "line.h" #include "line.h"
#include "random.h"
#include "window.h"
char *execstr = NULL ; /* pointer to string to execute */
boolean clexec = FALSE ; /* command line execution flag */
/* Directive definitions */
#define DIF 0
#define DELSE 1
#define DENDIF 2
#define DGOTO 3
#define DRETURN 4
#define DENDM 5
#define DWHILE 6
#define DENDWHILE 7
#define DBREAK 8
#define DFORCE 9
#define NUMDIRS 10
/* The !WHILE directive in the execution language needs to
* stack references to pending whiles. These are stored linked
* to each currently open procedure via a linked list of
* the following structure.
*/
struct while_block {
struct line *w_begin; /* ptr to !while statement */
struct line *w_end; /* ptr to the !endwhile statement */
int w_type; /* block type */
struct while_block *w_next; /* next while */
};
#define BTWHILE 1
#define BTBREAK 2
/* directive name table:
This holds the names of all the directives.... */
static const char *dname[] = {
"if", "else", "endif",
"goto", "return", "endm",
"while", "endwhile", "break",
"force"
};
static char golabel[ NSTRING] = "" ; /* current line to go to */
static int execlevel = 0 ; /* execution IF level */
static struct buffer *bstore = NULL ; /* buffer to store macro text to */
static int mstore = FALSE ; /* storing text to macro flag */
static int dobuf( struct buffer *bp) ;
static void freewhile( struct while_block *wp) ;
/* /*
* Execute a named command even if it is not bound. * Execute a named command even if it is not bound.
@ -35,6 +101,8 @@ int namedcmd(int f, int n)
return kfunc(f, n); return kfunc(f, n);
} }
static int docmd( char *cline) ;
/* /*
* execcmd: * execcmd:
* Execute a command line command to be typed in * Execute a command line command to be typed in
@ -68,13 +136,12 @@ int execcmd(int f, int n)
* *
* char *cline; command line to execute * char *cline; command line to execute
*/ */
int docmd(char *cline) static int docmd( char *cline) {
{
int f; /* default argument flag */ int f; /* default argument flag */
int n; /* numeric repeat value */ int n; /* numeric repeat value */
fn_t fnc; /* function to execute */ fn_t fnc; /* function to execute */
int status; /* return status of function */ int status; /* return status of function */
int oldcle; /* old contents of clexec flag */ boolean oldcle ; /* old contents of clexec flag */
char *oldestr; /* original exec string */ char *oldestr; /* original exec string */
char tkn[NSTRING]; /* next token off of command line */ char tkn[NSTRING]; /* next token off of command line */
@ -208,7 +275,7 @@ char *token(char *src, char *tok, int size)
*/ */
int macarg(char *tok) int macarg(char *tok)
{ {
int savcle; /* buffer to store original clexec */ boolean savcle ; /* buffer to store original clexec */
int status; int status;
savcle = clexec; /* save execution mode */ savcle = clexec; /* save execution mode */
@ -222,12 +289,12 @@ int macarg(char *tok)
* nextarg: * nextarg:
* get the next argument * get the next argument
* *
* char *prompt; prompt to use if we must be interactive * const char *prompt; prompt to use if we must be interactive
* char *buffer; buffer to put token into * char *buffer; buffer to put token into
* int size; size of the buffer * int size; size of the buffer
* int terminator; terminating char to be used on interactive fetch * int terminator; terminating char to be used on interactive fetch
*/ */
int nextarg(char *prompt, char *buffer, int size, int terminator) int nextarg(const char *prompt, char *buffer, int size, int terminator)
{ {
/* if we are interactive, go get it! */ /* if we are interactive, go get it! */
if (clexec == FALSE) if (clexec == FALSE)
@ -237,7 +304,8 @@ int nextarg(char *prompt, char *buffer, int size, int terminator)
execstr = token(execstr, buffer, size); execstr = token(execstr, buffer, size);
/* evaluate it */ /* evaluate it */
strcpy(buffer, getval(buffer)); strncpy( buffer, getval( buffer), size - 1) ;
buffer[ size - 1] = '\0' ;
return TRUE; return TRUE;
} }
@ -252,7 +320,7 @@ int nextarg(char *prompt, char *buffer, int size, int terminator)
int storemac(int f, int n) int storemac(int f, int n)
{ {
struct buffer *bp; /* pointer to macro buffer */ struct buffer *bp; /* pointer to macro buffer */
char bname[NBUFN]; /* name of buffer to use */ bname_t bname ; /* name of buffer to use */
/* must have a numeric argument to this function */ /* must have a numeric argument to this function */
if (f == FALSE) { if (f == FALSE) {
@ -299,7 +367,7 @@ int storeproc(int f, int n)
{ {
struct buffer *bp; /* pointer to macro buffer */ struct buffer *bp; /* pointer to macro buffer */
int status; /* return status */ int status; /* return status */
char bname[NBUFN]; /* name of buffer to use */ bname_t bname ; /* name of buffer to use */
/* a numeric argument means its a numbered macro */ /* a numeric argument means its a numbered macro */
if (f == TRUE) if (f == TRUE)
@ -307,7 +375,7 @@ int storeproc(int f, int n)
/* get the name of the procedure */ /* get the name of the procedure */
if ((status = if ((status =
mlreply("Procedure name: ", &bname[1], NBUFN - 2)) != TRUE) mlreply("Procedure name: ", &bname[1], sizeof bname - 2)) != TRUE)
return status; return status;
/* construct the macro buffer name */ /* construct the macro buffer name */
@ -374,10 +442,10 @@ int execbuf(int f, int n)
{ {
struct buffer *bp; /* ptr to buffer to execute */ struct buffer *bp; /* ptr to buffer to execute */
int status; /* status return */ int status; /* status return */
char bufn[NSTRING]; /* name of buffer to execute */ bname_t bufn ; /* name of buffer to execute */
/* find out what buffer the user wants to execute */ /* find out what buffer the user wants to execute */
if ((status = mlreply("Execute buffer: ", bufn, NBUFN)) != TRUE) if ((status = mlreply("Execute buffer: ", bufn, sizeof bufn)) != TRUE)
return status; return status;
/* find the pointer to that buffer */ /* find the pointer to that buffer */
@ -416,7 +484,7 @@ int execbuf(int f, int n)
* *
* struct buffer *bp; buffer to execute * struct buffer *bp; buffer to execute
*/ */
int dobuf(struct buffer *bp) static int dobuf(struct buffer *bp)
{ {
int status; /* status return */ int status; /* status return */
struct line *lp; /* pointer to line to execute */ struct line *lp; /* pointer to line to execute */
@ -426,7 +494,6 @@ int dobuf(struct buffer *bp)
int dirnum; /* directive index */ int dirnum; /* directive index */
int linlen; /* length of line to execute */ int linlen; /* length of line to execute */
int i; /* index */ int i; /* index */
int c; /* temp character */
int force; /* force TRUE result? */ int force; /* force TRUE result? */
struct window *wp; /* ptr to windows to scan */ struct window *wp; /* ptr to windows to scan */
struct while_block *whlist; /* ptr to !WHILE list */ struct while_block *whlist; /* ptr to !WHILE list */
@ -436,11 +503,6 @@ int dobuf(struct buffer *bp)
char *eline; /* text of line to execute */ char *eline; /* text of line to execute */
char tkn[NSTRING]; /* buffer to evaluate an expresion in */ char tkn[NSTRING]; /* buffer to evaluate an expresion in */
#if DEBUGM
char *sp; /* temp for building debug string */
char *ep; /* ptr to end of outline */
#endif
/* clear IF level flags/while ptr */ /* clear IF level flags/while ptr */
execlevel = 0; execlevel = 0;
whlist = NULL; whlist = NULL;
@ -557,6 +619,9 @@ int dobuf(struct buffer *bp)
^G will abort the command */ ^G will abort the command */
if (macbug) { if (macbug) {
char *sp ; /* temp for building debug string */
int c ; /* temp character */
strcpy(outline, "<<<"); strcpy(outline, "<<<");
/* debug macro name */ /* debug macro name */
@ -564,7 +629,7 @@ int dobuf(struct buffer *bp)
strcat(outline, ":"); strcat(outline, ":");
/* debug if levels */ /* debug if levels */
strcat(outline, itoa(execlevel)); strcat(outline, i_to_a(execlevel));
strcat(outline, ":"); strcat(outline, ":");
/* and lastly the line */ /* and lastly the line */
@ -575,6 +640,8 @@ int dobuf(struct buffer *bp)
sp = outline; sp = outline;
while (*sp) while (*sp)
if (*sp++ == '%') { if (*sp++ == '%') {
char *ep ; /* ptr to end of outline */
/* advance to the end */ /* advance to the end */
ep = --sp; ep = --sp;
while (*ep++); while (*ep++);
@ -732,7 +799,7 @@ int dobuf(struct buffer *bp)
/* grab label to jump to */ /* grab label to jump to */
eline = eline =
token(eline, golabel, NPAT); token( eline, golabel, sizeof golabel) ;
linlen = strlen(golabel); linlen = strlen(golabel);
glp = hlp->l_fp; glp = hlp->l_fp;
while (glp != hlp) { while (glp != hlp) {
@ -833,7 +900,7 @@ int dobuf(struct buffer *bp)
* *
* struct while_block *wp; head of structure to free * struct while_block *wp; head of structure to free
*/ */
void freewhile(struct while_block *wp) static void freewhile(struct while_block *wp)
{ {
if (wp == NULL) if (wp == NULL)
return; return;
@ -886,7 +953,7 @@ int dofile(char *fname)
struct buffer *bp; /* buffer to place file to exeute */ struct buffer *bp; /* buffer to place file to exeute */
struct buffer *cb; /* temp to hold current buf while we read */ struct buffer *cb; /* temp to hold current buf while we read */
int status; /* results of various calls */ int status; /* results of various calls */
char bname[NBUFN]; /* name of buffer */ bname_t bname ; /* name of buffer */
makename(bname, fname); /* derive the name of the buffer */ makename(bname, fname); /* derive the name of the buffer */
unqname(bname); /* make sure we don't stomp things */ unqname(bname); /* make sure we don't stomp things */

71
exec.h Normal file
View File

@ -0,0 +1,71 @@
#ifndef _EXEC_H_
#define _EXEC_H_
#include "retcode.h"
#define PROC 1 /* named procedures */
#if PROC
int storeproc( int f, int n) ;
int execproc( int f, int n) ;
#endif
extern char *execstr ; /* pointer to string to execute */
extern boolean clexec ; /* command line execution flag */
int namedcmd( int f, int n) ;
int execcmd( int f, int n) ;
char *token( char *src, char *tok, int size) ;
int macarg( char *tok) ;
int nextarg( const char *prompt, char *buffer, int size, int terminator) ;
int storemac( int f, int n) ;
int execbuf( int f, int n) ;
int execfile( int f, int n) ;
int dofile( char *fname) ;
int cbuf( int f, int n, int bufnum) ;
int cbuf1( int f, int n) ;
int cbuf2( int f, int n) ;
int cbuf3( int f, int n) ;
int cbuf4( int f, int n) ;
int cbuf5( int f, int n) ;
int cbuf6( int f, int n) ;
int cbuf7( int f, int n) ;
int cbuf8( int f, int n) ;
int cbuf9( int f, int n) ;
int cbuf10( int f, int n) ;
int cbuf11( int f, int n) ;
int cbuf12( int f, int n) ;
int cbuf13( int f, int n) ;
int cbuf14( int f, int n) ;
int cbuf15( int f, int n) ;
int cbuf16( int f, int n) ;
int cbuf17( int f, int n) ;
int cbuf18( int f, int n) ;
int cbuf19( int f, int n) ;
int cbuf20( int f, int n) ;
int cbuf21( int f, int n) ;
int cbuf22( int f, int n) ;
int cbuf23( int f, int n) ;
int cbuf24( int f, int n) ;
int cbuf25( int f, int n) ;
int cbuf26( int f, int n) ;
int cbuf27( int f, int n) ;
int cbuf28( int f, int n) ;
int cbuf29( int f, int n) ;
int cbuf30( int f, int n) ;
int cbuf31( int f, int n) ;
int cbuf32( int f, int n) ;
int cbuf33( int f, int n) ;
int cbuf34( int f, int n) ;
int cbuf35( int f, int n) ;
int cbuf36( int f, int n) ;
int cbuf37( int f, int n) ;
int cbuf38( int f, int n) ;
int cbuf39( int f, int n) ;
int cbuf40( int f, int n) ;
#endif

108
execute.c Normal file
View File

@ -0,0 +1,108 @@
/* execute.c -- implements execute.h */
#include "execute.h"
#include <stdlib.h>
#include "estruct.h"
#include "bind.h"
#include "random.h"
#include "display.h"
#include "file.h"
#include "terminal.h"
#include "window.h"
int gasave = 256 ; /* global ASAVE size */
int gacount = 256 ; /* count until next ASAVE */
/*
* This is the general command execution routine. It handles the fake binding
* of all the keys to "self-insert". It also clears out the "thisflag" word,
* and arranges to move it to the "lastflag", so that the next command can
* look at it. Return the status of command.
*/
int execute(int c, int f, int n)
{
int status;
fn_t execfunc;
/* if the keystroke is a bound function...do it */
execfunc = getbind(c);
if (execfunc != NULL) {
thisflag = 0;
status = (*execfunc) (f, n);
lastflag = thisflag;
return status;
}
/*
* If a space was typed, fill column is defined, the argument is non-
* negative, wrap mode is enabled, and we are now past fill column,
* and we are not read-only, perform word wrap.
*/
if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 &&
n >= 0 && getccol(FALSE) > fillcol &&
(curwp->w_bufp->b_mode & MDVIEW) == FALSE)
execute(META | SPEC | 'W', FALSE, 1);
#if PKCODE
if ((c >= 0x20 && c <= 0x7E) /* Self inserting. */
#if IBMPC
|| (c >= 0x80 && c <= 0xFE)) {
#else
#if VMS || BSD || USG /* 8BIT P.K. */
|| (c >= 0xA0 && c <= 0x10FFFF)) {
#else
) {
#endif
#endif
#else
if ((c >= 0x20 && c <= 0xFF)) { /* Self inserting. */
#endif
if (n <= 0) { /* Fenceposts. */
lastflag = 0;
return n < 0 ? FALSE : TRUE;
}
thisflag = 0; /* For the future. */
/* if we are in overwrite mode, not at eol,
and next char is not a tab or we are at a tab stop,
delete a char forword */
if (curwp->w_bufp->b_mode & MDOVER &&
curwp->w_doto < curwp->w_dotp->l_used &&
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
(curwp->w_doto) % 8 == 7))
ldelchar(1, FALSE);
/* do the appropriate insertion */
if (c == '}' && (curbp->b_mode & MDCMOD) != 0)
status = insbrace(n, c);
else if (c == '#' && (curbp->b_mode & MDCMOD) != 0)
status = inspound();
else
status = linsert(n, c);
#if CFENCE
/* check for CMODE fence matching */
if ((c == '}' || c == ')' || c == ']') &&
(curbp->b_mode & MDCMOD) != 0)
fmatch(c);
#endif
/* check auto-save mode */
if (curbp->b_mode & MDASAVE)
if (--gacount == 0) {
/* and save the file if needed */
upscreen(FALSE, 0);
filesave(FALSE, 0);
gacount = gasave;
}
lastflag = thisflag;
return status;
}
TTbeep();
mlwrite("(Key not bound)"); /* complain */
lastflag = 0; /* Fake last flags. */
return FALSE;
}

5
execute.h Normal file
View File

@ -0,0 +1,5 @@
extern int gasave ; /* global ASAVE size */
extern int gacount ; /* count until next ASAVE */
int execute( int c, int f, int n) ;

211
file.c
View File

@ -1,3 +1,7 @@
/* file.c -- implements file.h */
#include "file.h"
/* file.c /* file.c
* *
* The routines in this file handle the reading, writing * The routines in this file handle the reading, writing
@ -8,18 +12,44 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "buffer.h"
#include "crypt.h"
#include "defines.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "execute.h"
#include "efunc.h" #include "fileio.h"
#include "input.h"
#include "line.h" #include "line.h"
#include "lock.h"
#include "log.h"
#include "window.h"
#if defined(PKCODE) #if PKCODE
/* Max number of lines from one file. */ /* Max number of lines from one file. */
#define MAXNLINE 10000000 #define MAXNLINE 10000000
#endif #endif
typedef enum {
EOL_NONE,
EOL_UNIX,
EOL_DOS,
EOL_MAC,
EOL_MIXED
} eoltype ;
static const char *eolname[] = {
"NONE",
"UNIX",
"DOS",
"MAC",
"MIXED"
} ;
boolean restflag = FALSE ; /* restricted use? */
/* /*
* Read a file into the current * Read a file into the current
* buffer. This is really easy; all you do it * buffer. This is really easy; all you do it
@ -30,11 +60,11 @@
int fileread(int f, int n) int fileread(int f, int n)
{ {
int s; int s;
char fname[NFILEN]; fname_t fname ;
if (restflag) /* don't allow this command if restricted */ if (restflag) /* don't allow this command if restricted */
return resterr(); return resterr();
if ((s = mlreply("Read file: ", fname, NFILEN)) != TRUE) if ((s = mlreply("Read file: ", fname, sizeof fname)) != TRUE)
return s; return s;
return readin(fname, TRUE); return readin(fname, TRUE);
} }
@ -49,13 +79,13 @@ int fileread(int f, int n)
int insfile(int f, int n) int insfile(int f, int n)
{ {
int s; int s;
char fname[NFILEN]; fname_t fname ;
if (restflag) /* don't allow this command if restricted */ if (restflag) /* don't allow this command if restricted */
return resterr(); return resterr();
if (curbp->b_mode & MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */ return rdonly(); /* we are in read only mode */
if ((s = mlreply("Insert file: ", fname, NFILEN)) != TRUE) if ((s = mlreply("Insert file: ", fname, sizeof fname)) != TRUE)
return s; return s;
if ((s = ifile(fname)) != TRUE) if ((s = ifile(fname)) != TRUE)
return s; return s;
@ -73,25 +103,25 @@ int insfile(int f, int n)
*/ */
int filefind(int f, int n) int filefind(int f, int n)
{ {
char fname[NFILEN]; /* file user wishes to find */ fname_t fname ; /* file user wishes to find */
int s; /* status return */ int s; /* status return */
if (restflag) /* don't allow this command if restricted */ if (restflag) /* don't allow this command if restricted */
return resterr(); return resterr();
if ((s = mlreply("Find file: ", fname, NFILEN)) != TRUE) if ((s = mlreply("Find file: ", fname, sizeof fname)) != TRUE)
return s; return s;
return getfile(fname, TRUE); return getfile(fname, TRUE);
} }
int viewfile(int f, int n) int viewfile(int f, int n)
{ /* visit a file in VIEW mode */ { /* visit a file in VIEW mode */
char fname[NFILEN]; /* file user wishes to find */ fname_t fname ; /* file user wishes to find */
int s; /* status return */ int s; /* status return */
struct window *wp; /* scan for windows that need updating */ struct window *wp; /* scan for windows that need updating */
if (restflag) /* don't allow this command if restricted */ if (restflag) /* don't allow this command if restricted */
return resterr(); return resterr();
if ((s = mlreply("View file: ", fname, NFILEN)) != TRUE) if ((s = mlreply("View file: ", fname, sizeof fname)) != TRUE)
return s; return s;
s = getfile(fname, FALSE); s = getfile(fname, FALSE);
if (s) { /* if we succeed, put it in view mode */ if (s) { /* if we succeed, put it in view mode */
@ -108,12 +138,47 @@ int viewfile(int f, int n)
} }
#if CRYPT #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 vlaue of disinp */
ekey_t key ; /* new encryption string */
/* turn command input echo off */
odisinp = disinp;
disinp = FALSE;
/* get the string to use as an encrytion string */
status = mlreply("Encryption String: ", key, sizeof key - 1);
disinp = odisinp;
if (status != TRUE)
return status;
/* save it off and encrypt it*/
strcpy(curbp->b_key, key);
cryptbufferkey( curbp) ;
logwrite(" "); /* clear it off the bottom line */
return TRUE;
}
static int resetkey(void) static int resetkey(void)
{ /* reset the encryption key if needed */ { /* reset the encryption key if needed */
int s; /* return status */ int s; /* return status */
/* turn off the encryption flag */ /* turn off the encryption flag */
cryptflag = FALSE; is_crypted = FALSE;
/* if we are in crypt mode */ /* if we are in crypt mode */
if (curbp->b_mode & MDCRYPT) { if (curbp->b_mode & MDCRYPT) {
@ -124,16 +189,14 @@ static int resetkey(void)
} }
/* let others know... */ /* let others know... */
cryptflag = TRUE; is_crypted = TRUE;
/* and set up the key to be used! */ /* and set up the key to be used! */
/* de-encrypt it */ /* de-encrypt it */
myencrypt((char *) NULL, 0); cryptbufferkey( curbp) ;
myencrypt(curbp->b_key, strlen(curbp->b_key));
/* re-encrypt it...seeding it to start */ /* re-encrypt it...seeding it to start */
myencrypt((char *) NULL, 0); cryptbufferkey( curbp) ;
myencrypt(curbp->b_key, strlen(curbp->b_key));
} }
return TRUE; return TRUE;
@ -144,15 +207,15 @@ static int resetkey(void)
* getfile() * getfile()
* *
* char fname[]; file name to find * char fname[]; file name to find
* int lockfl; check the file for locks? * boolean lockfl; check the file for locks?
*/ */
int getfile(char *fname, int lockfl) int getfile( const char *fname, boolean lockfl)
{ {
struct buffer *bp; struct buffer *bp;
struct line *lp; struct line *lp;
int i; int i;
int s; int s;
char bname[NBUFN]; /* buffer name to put file */ bname_t bname ; /* buffer name to put file */
#if MSDOS #if MSDOS
mklower(fname); /* msdos isn't case sensitive */ mklower(fname); /* msdos isn't case sensitive */
@ -168,14 +231,14 @@ int getfile(char *fname, int lockfl)
curwp->w_linep = lp; curwp->w_linep = lp;
curwp->w_flag |= WFMODE | WFHARD; curwp->w_flag |= WFMODE | WFHARD;
cknewwindow(); cknewwindow();
mlwrite("(Old buffer)"); logwrite("(Old buffer)");
return TRUE; return TRUE;
} }
} }
makename(bname, fname); /* New buffer name. */ makename(bname, fname); /* New buffer name. */
while ((bp = bfind(bname, FALSE, 0)) != NULL) { while ((bp = bfind(bname, FALSE, 0)) != NULL) {
/* old buffer name conflict code */ /* old buffer name conflict code */
s = mlreply("Buffer name: ", bname, NBUFN); s = mlreply("Buffer name: ", bname, sizeof bname);
if (s == ABORT) /* ^G to just quit */ if (s == ABORT) /* ^G to just quit */
return s; return s;
if (s == FALSE) { /* CR to clobber it */ if (s == FALSE) { /* CR to clobber it */
@ -184,7 +247,7 @@ int getfile(char *fname, int lockfl)
} }
} }
if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) { if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) {
mlwrite("Cannot create buffer"); logwrite("Cannot create buffer");
return FALSE; return FALSE;
} }
if (--curbp->b_nwnd == 0) { /* Undisplay. */ if (--curbp->b_nwnd == 0) { /* Undisplay. */
@ -210,16 +273,16 @@ int getfile(char *fname, int lockfl)
* and before it is read. * and before it is read.
* *
* char fname[]; name of file to read * char fname[]; name of file to read
* int lockfl; check for file locks? * boolean lockfl; check for file locks?
*/ */
int readin(char *fname, int lockfl) int readin(const char *fname, boolean lockfl)
{ {
struct line *lp1; struct line *lp1;
struct line *lp2; struct line *lp2;
int i;
struct window *wp; struct window *wp;
struct buffer *bp; struct buffer *bp;
int s; int s;
eoltype found_eol ;
int nbytes; int nbytes;
int nline; int nline;
char mesg[NSTRING]; char mesg[NSTRING];
@ -255,34 +318,57 @@ int readin(char *fname, int lockfl)
goto out; goto out;
if (s == FIOFNF) { /* File not found. */ if (s == FIOFNF) { /* File not found. */
mlwrite("(New file)"); logwrite("(New file)");
goto out; goto out;
} }
/* read the file in */ /* read the file in */
mlwrite("(Reading file)"); logwrite("(Reading file)");
nline = 0; nline = 0;
while ((s = ffgetline()) == FIOSUC) { while ((s = ffgetline()) == FIOSUC) {
nbytes = strlen(fline); nbytes = fpayload ;
if ((lp1 = lalloc(nbytes)) == NULL) {
s = FIOMEM; /* Keep message on the */
break; /* display. */
}
#if PKCODE #if PKCODE
if (nline > MAXNLINE) { if (nline > MAXNLINE) {
s = FIOMEM; s = FIOMEM;
break; break;
} }
#endif #endif
if ((lp1 = lalloc(nbytes)) == NULL) {
s = FIOMEM; /* Keep message on the */
break; /* display. */
}
lp2 = lback(curbp->b_linep); lp2 = lback(curbp->b_linep);
lp2->l_fp = lp1; lp2->l_fp = lp1;
lp1->l_fp = curbp->b_linep; lp1->l_fp = curbp->b_linep;
lp1->l_bp = lp2; lp1->l_bp = lp2;
curbp->b_linep->l_bp = lp1; curbp->b_linep->l_bp = lp1;
for (i = 0; i < nbytes; ++i) memcpy( lp1->l_text, fline, nbytes) ;
lputc(lp1, i, fline[i]);
++nline; ++nline;
} }
if( s == FIOERR)
logwrite( "File read error") ;
switch( ftype) {
case FTYPE_DOS:
found_eol = EOL_DOS ;
curbp->b_mode |= MDDOS ;
break ;
case FTYPE_UNIX:
found_eol = EOL_UNIX ;
break ;
case FTYPE_MAC:
found_eol = EOL_MAC ;
break ;
case FTYPE_NONE:
found_eol = EOL_NONE ;
break ;
default:
found_eol = EOL_MIXED ;
curbp->b_mode |= MDVIEW ; /* add view mode as we have lost
** information */
}
ffclose(); /* Ignore errors. */ ffclose(); /* Ignore errors. */
strcpy(mesg, "("); strcpy(mesg, "(");
if (s == FIOERR) { if (s == FIOERR) {
@ -296,8 +382,11 @@ int readin(char *fname, int lockfl)
sprintf(&mesg[strlen(mesg)], "Read %d line", nline); sprintf(&mesg[strlen(mesg)], "Read %d line", nline);
if (nline != 1) if (nline != 1)
strcat(mesg, "s"); strcat(mesg, "s");
strcat( mesg, ", eol = ") ;
strcat( mesg, eolname[ found_eol]) ;
strcat(mesg, ")"); strcat(mesg, ")");
mlwrite(mesg); logwrite(mesg);
out: out:
for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { for (wp = wheadp; wp != NULL; wp = wp->w_wndp) {
@ -322,9 +411,9 @@ int readin(char *fname, int lockfl)
* I suppose that this information could be put in * I suppose that this information could be put in
* a better place than a line of code. * a better place than a line of code.
*/ */
void makename(char *bname, char *fname) void makename( bname_t bname, const char *fname)
{ {
char *cp1; const char *cp1;
char *cp2; char *cp2;
cp1 = &fname[0]; cp1 = &fname[0];
@ -350,7 +439,7 @@ void makename(char *bname, char *fname)
--cp1; --cp1;
#endif #endif
cp2 = &bname[0]; cp2 = &bname[0];
while (cp2 != &bname[NBUFN - 1] && *cp1 != 0 && *cp1 != ';') while( cp2 != &bname[ sizeof( bname_t) - 1] && *cp1 != 0 && *cp1 != ';')
*cp2++ = *cp1++; *cp2++ = *cp1++;
*cp2 = 0; *cp2 = 0;
} }
@ -392,11 +481,11 @@ int filewrite(int f, int n)
{ {
struct window *wp; struct window *wp;
int s; int s;
char fname[NFILEN]; fname_t fname ;
if (restflag) /* don't allow this command if restricted */ if (restflag) /* don't allow this command if restricted */
return resterr(); return resterr();
if ((s = mlreply("Write file: ", fname, NFILEN)) != TRUE) if ((s = mlreply("Write file: ", fname, sizeof fname)) != TRUE)
return s; return s;
if ((s = writeout(fname)) == TRUE) { if ((s = writeout(fname)) == TRUE) {
strcpy(curbp->b_fname, fname); strcpy(curbp->b_fname, fname);
@ -429,14 +518,14 @@ int filesave(int f, int n)
if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */ if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */
return TRUE; return TRUE;
if (curbp->b_fname[0] == 0) { /* Must have a name. */ if (curbp->b_fname[0] == 0) { /* Must have a name. */
mlwrite("No file name"); logwrite("No file name");
return FALSE; return FALSE;
} }
/* complain about truncated files */ /* complain about truncated files */
if ((curbp->b_flag & BFTRUNC) != 0) { if ((curbp->b_flag & BFTRUNC) != 0) {
if (mlyesno("Truncated file ... write it out") == FALSE) { if (mlyesno("Truncated file ... write it out") == FALSE) {
mlwrite("(Aborted)"); logwrite("(Aborted)");
return FALSE; return FALSE;
} }
} }
@ -461,7 +550,7 @@ int filesave(int f, int n)
* a macro for this. Most of the grief is error * a macro for this. Most of the grief is error
* checking of some sort. * checking of some sort.
*/ */
int writeout(char *fn) int writeout( const char *fn)
{ {
int s; int s;
struct line *lp; struct line *lp;
@ -474,14 +563,19 @@ int writeout(char *fn)
#endif #endif
if ((s = ffwopen(fn)) != FIOSUC) { /* Open writes message. */ if ((s = ffwopen(fn)) != FIOSUC) { /* Open writes message. */
logwrite( "Cannot open file for writing") ;
return FALSE; return FALSE;
} }
mlwrite("(Writing...)"); /* tell us were writing */ logwrite("(Writing...)"); /* tell us were writing */
lp = lforw(curbp->b_linep); /* First line. */ lp = lforw(curbp->b_linep); /* First line. */
nline = 0; /* Number of lines. */ nline = 0; /* Number of lines. */
while (lp != curbp->b_linep) { while (lp != curbp->b_linep) {
if ((s = ffputline(&lp->l_text[0], llength(lp))) != FIOSUC) s = ffputline( &lp->l_text[0], llength(lp), curbp->b_mode & MDDOS) ;
if( s != FIOSUC) {
logwrite( "Write I/O error") ;
break; break;
}
++nline; ++nline;
lp = lforw(lp); lp = lforw(lp);
} }
@ -489,10 +583,11 @@ int writeout(char *fn)
s = ffclose(); s = ffclose();
if (s == FIOSUC) { /* No close error. */ if (s == FIOSUC) { /* No close error. */
if (nline == 1) if (nline == 1)
mlwrite("(Wrote 1 line)"); logwrite("(Wrote 1 line)");
else else
mlwrite("(Wrote %d lines)", nline); logwrite("(Wrote %d lines)", nline);
} } else
logwrite( "Error closing file") ;
} else /* Ignore close error */ } else /* Ignore close error */
ffclose(); /* if a write error. */ ffclose(); /* if a write error. */
if (s != FIOSUC) /* Some sort of error. */ if (s != FIOSUC) /* Some sort of error. */
@ -513,11 +608,11 @@ int filename(int f, int n)
{ {
struct window *wp; struct window *wp;
int s; int s;
char fname[NFILEN]; fname_t fname ;
if (restflag) /* don't allow this command if restricted */ if (restflag) /* don't allow this command if restricted */
return resterr(); return resterr();
if ((s = mlreply("Name: ", fname, NFILEN)) == ABORT) if ((s = mlreply("Name: ", fname, sizeof fname)) == ABORT)
return s; return s;
if (s == FALSE) if (s == FALSE)
strcpy(curbp->b_fname, ""); strcpy(curbp->b_fname, "");
@ -538,12 +633,11 @@ int filename(int f, int n)
* buffer, Called by insert file command. Return the final * buffer, Called by insert file command. Return the final
* status of the read. * status of the read.
*/ */
int ifile(char *fname) int ifile( const char *fname)
{ {
struct line *lp0; struct line *lp0;
struct line *lp1; struct line *lp1;
struct line *lp2; struct line *lp2;
int i;
struct buffer *bp; struct buffer *bp;
int s; int s;
int nbytes; int nbytes;
@ -556,10 +650,10 @@ int ifile(char *fname)
if ((s = ffropen(fname)) == FIOERR) /* Hard file open. */ if ((s = ffropen(fname)) == FIOERR) /* Hard file open. */
goto out; goto out;
if (s == FIOFNF) { /* File not found. */ if (s == FIOFNF) { /* File not found. */
mlwrite("(No such file)"); logwrite("(No such file)");
return FALSE; return FALSE;
} }
mlwrite("(Inserting file)"); logwrite("(Inserting file)");
#if CRYPT #if CRYPT
s = resetkey(); s = resetkey();
@ -574,7 +668,7 @@ int ifile(char *fname)
nline = 0; nline = 0;
while ((s = ffgetline()) == FIOSUC) { while ((s = ffgetline()) == FIOSUC) {
nbytes = strlen(fline); nbytes = fpayload ;
if ((lp1 = lalloc(nbytes)) == NULL) { if ((lp1 = lalloc(nbytes)) == NULL) {
s = FIOMEM; /* Keep message on the */ s = FIOMEM; /* Keep message on the */
break; /* display. */ break; /* display. */
@ -590,8 +684,7 @@ int ifile(char *fname)
/* and advance and write out the current line */ /* and advance and write out the current line */
curwp->w_dotp = lp1; curwp->w_dotp = lp1;
for (i = 0; i < nbytes; ++i) memcpy( lp1->l_text, fline, nbytes) ;
lputc(lp1, i, fline[i]);
++nline; ++nline;
} }
ffclose(); /* Ignore errors. */ ffclose(); /* Ignore errors. */
@ -609,7 +702,7 @@ int ifile(char *fname)
if (nline > 1) if (nline > 1)
strcat(mesg, "s"); strcat(mesg, "s");
strcat(mesg, ")"); strcat(mesg, ")");
mlwrite(mesg); logwrite(mesg);
out: out:
/* advance to the next line and mark the window for changes */ /* advance to the next line and mark the window for changes */

29
file.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef _FILE_H_
#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? */
int fileread( int f, int n) ;
int insfile( int f, int n) ;
int filefind( int f, int n) ;
int viewfile( int f, int n) ;
int getfile( const char *fname, boolean lockfl) ;
int readin( const char *fname, boolean lockfl) ;
void makename( bname_t bname, const char *fname) ;
void unqname( char *name) ;
int filewrite( int f, int n) ;
int filesave( int f, int n) ;
int writeout( const char *fn) ;
int filename( int f, int n) ;
int ifile( const char *fname) ;
#endif

163
fileio.c
View File

@ -1,3 +1,12 @@
/* fileio.c -- implements fileio.h */
#include "fileio.h"
#ifdef CTRLZ
#undef CTRLZ
#endif
#define CTRLZ 0 /* add a ^Z at end of files under MSDOS only */
/* FILEIO.C /* FILEIO.C
* *
* The routines in this file read and write ASCII files from the disk. All of * The routines in this file read and write ASCII files from the disk. All of
@ -7,21 +16,35 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include "estruct.h" #include <stdlib.h>
#include "edef.h" #include <string.h>
#include "efunc.h"
#include "defines.h"
#include "retcode.h"
#if CRYPT
boolean is_crypted ; /* currently encrypting? */
#endif
char *fline = NULL ; /* dynamic return line */
int flen = 0 ; /* current allocated length of fline */
int ftype ;
int fpayload ; /* actual length of fline content */
static FILE *ffp ; /* File pointer, all functions. */ static FILE *ffp ; /* File pointer, all functions. */
static int eofflag; /* end-of-file flag */ static boolean eofflag ; /* end-of-file flag */
/* /*
* Open a file for reading. * Open a file for reading.
*/ */
int ffropen(char *fn) fio_code ffropen( const char *fn)
{ {
if ((ffp = fopen(fn, "r")) == NULL) if ((ffp = fopen(fn, "r")) == NULL)
return FIOFNF; return FIOFNF;
eofflag = FALSE; eofflag = FALSE;
ftype = FTYPE_NONE ;
return FIOSUC; return FIOSUC;
} }
@ -29,26 +52,25 @@ int ffropen(char *fn)
* Open a file for writing. Return TRUE if all is well, and FALSE on error * Open a file for writing. Return TRUE if all is well, and FALSE on error
* (cannot create). * (cannot create).
*/ */
int ffwopen(char *fn) fio_code ffwopen( const char *fn)
{ {
#if VMS #if VMS
int fd; int fd;
if ((fd = creat(fn, 0666, "rfm=var", "rat=cr")) < 0 if ((fd = creat(fn, 0666, "rfm=var", "rat=cr")) < 0
|| (ffp = fdopen(fd, "w")) == NULL) { || (ffp = fdopen(fd, "w")) == NULL)
#else #else
if ((ffp = fopen(fn, "w")) == NULL) { if ((ffp = fopen(fn, "w")) == NULL)
#endif #endif
mlwrite("Cannot open file for writing");
return FIOERR; return FIOERR;
}
return FIOSUC; return FIOSUC;
} }
/* /*
* Close a file. Should look at the status in all systems. * Close a file. Should look at the status in all systems.
*/ */
int ffclose(void) fio_code ffclose(void)
{ {
/* free this since we do not need it anymore */ /* free this since we do not need it anymore */
if (fline) { if (fline) {
@ -56,21 +78,19 @@ int ffclose(void)
fline = NULL; fline = NULL;
} }
eofflag = FALSE; eofflag = FALSE;
ftype = FTYPE_NONE ;
#if MSDOS & CTRLZ #if MSDOS & CTRLZ
fputc(26, ffp); /* add a ^Z at the end of the file */ fputc(26, ffp); /* add a ^Z at the end of the file */
#endif #endif
#if V7 | USG | BSD | (MSDOS & (MSC | TURBO)) #if V7 | USG | BSD | (MSDOS & (MSC | TURBO))
if (fclose(ffp) != FALSE) { if (fclose(ffp) != FALSE)
mlwrite("Error closing file");
return FIOERR; return FIOERR;
}
return FIOSUC;
#else #else
fclose(ffp); fclose(ffp);
return FIOSUC;
#endif #endif
return FIOSUC;
} }
/* /*
@ -78,32 +98,30 @@ int ffclose(void)
* and the "nbuf" is its length, less the free newline. Return the status. * and the "nbuf" is its length, less the free newline. Return the status.
* Check only at the newline. * Check only at the newline.
*/ */
int ffputline(char *buf, int nbuf) fio_code ffputline( char *buf, int nbuf, int dosflag) {
{
int i;
#if CRYPT #if CRYPT
char c; /* character to translate */ if( is_crypted) {
int i ;
if (cryptflag) { for( i = 0 ; i < nbuf ; i++) {
for (i = 0; i < nbuf; ++i) { char c ;
c = buf[i] & 0xff;
c = buf[ i] ;
myencrypt( &c, 1) ; myencrypt( &c, 1) ;
fputc( c, ffp) ; fputc( c, ffp) ;
} }
} else } else
for (i = 0; i < nbuf; ++i)
fputc(buf[i] & 0xFF, ffp);
#else
for (i = 0; i < nbuf; ++i)
fputc(buf[i] & 0xFF, ffp);
#endif #endif
fwrite( buf, 1, nbuf, ffp) ;
if( dosflag)
fputc( '\r', ffp) ;
fputc( '\n', ffp) ; fputc( '\n', ffp) ;
if (ferror(ffp)) { if( ferror( ffp))
mlwrite("Write I/O error");
return FIOERR ; return FIOERR ;
}
return FIOSUC ; return FIOSUC ;
} }
@ -114,11 +132,10 @@ int ffputline(char *buf, int nbuf)
* at the end of the file that don't have a newline present. Check for I/O * at the end of the file that don't have a newline present. Check for I/O
* errors too. Return status. * errors too. Return status.
*/ */
int ffgetline(void) fio_code ffgetline(void)
{ {
int c; /* current character read */ int c; /* current character read */
int i; /* current index into fline */ int i; /* current index into fline */
char *tmpline; /* temp storage for expanding line */
/* if we are at the end...return it */ /* if we are at the end...return it */
if (eofflag) if (eofflag)
@ -136,87 +153,51 @@ int ffgetline(void)
return FIOMEM; return FIOMEM;
/* read the line in */ /* read the line in */
#if PKCODE
if (!nullflag) {
if (fgets(fline, NSTRING, ffp) == (char *) NULL) { /* EOF ? */
i = 0; i = 0;
c = EOF; while ((c = fgetc(ffp)) != EOF && c != '\r' && c != '\n') {
} else {
i = strlen(fline);
c = 0;
if (i > 0) {
c = fline[i - 1];
i--;
}
}
} else {
i = 0;
c = fgetc(ffp);
}
while (c != EOF && c != '\n') {
#else
i = 0;
while ((c = fgetc(ffp)) != EOF && c != '\n') {
#endif
#if PKCODE
if (c) {
#endif
fline[i++] = c; fline[i++] = c;
/* if it's longer, get more room */ /* if it's longer, get more room */
if (i >= flen) { if (i >= flen) {
if ((tmpline = char *tmpline; /* temp storage for expanding line */
malloc(flen + NSTRING)) == NULL)
fpayload = i ;
tmpline = malloc(flen + NSTRING) ;
if( tmpline == NULL)
return FIOMEM ; return FIOMEM ;
strncpy(tmpline, fline, flen);
memcpy( tmpline, fline, flen) ;
flen += NSTRING; flen += NSTRING;
free(fline); free(fline);
fline = tmpline; fline = tmpline;
} }
#if PKCODE
}
c = fgetc(ffp);
#endif
} }
fpayload = i ;
/* test for any errors that may have occured */ /* test for any errors that may have occured */
if (c == EOF) { if (c == EOF) {
if (ferror(ffp)) { if( ferror( ffp))
mlwrite("File read error");
return FIOERR ; return FIOERR ;
}
if (i != 0) if (i != 0)
eofflag = TRUE; eofflag = TRUE;
else else
return FIOEOF; return FIOEOF;
} } else if( c == '\r') {
c = fgetc( ffp) ;
if( c != '\n') {
ftype |= FTYPE_MAC ;
ungetc( c, ffp) ;
} else
ftype |= FTYPE_DOS ;
} else /* c == '\n' */
ftype |= FTYPE_UNIX ;
/* terminate and decrypt the string */ /* terminate and decrypt the string */
fline[i] = 0; fline[i] = 0;
#if CRYPT #if CRYPT
if (cryptflag) if( is_crypted)
myencrypt(fline, strlen(fline)); myencrypt( fline, fpayload);
#endif #endif
return FIOSUC; return FIOSUC;
} }
/*
* does <fname> exist on disk?
*
* char *fname; file to check for existance
*/
int fexist(char *fname)
{
FILE *fp;
/* try to open the file for reading */
fp = fopen(fname, "r");
/* if it fails, just return false! */
if (fp == NULL)
return FALSE;
/* otherwise, close it and report true */
fclose(fp);
return TRUE;
}

38
fileio.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef _FILEIO_H_
#define _FILEIO_H_
#include "crypt.h"
typedef enum {
FIOSUC, /* File I/O, success. */
FIOFNF, /* File I/O, file not found. */
FIOEOF, /* File I/O, end of file. */
FIOERR, /* File I/O, error. */
FIOMEM, /* File I/O, out of memory */
FIOFUN /* File I/O, eod of file/bad line */
} fio_code ;
#define FTYPE_NONE 0
#define FTYPE_UNIX 1
#define FTYPE_DOS 2
#define FTYPE_MAC 4
/* FTYPE_MIXED [ 3, 5, 6, 7] */
#if CRYPT
#include "retcode.h"
extern boolean is_crypted ; /* currently encrypting? */
#endif
extern char *fline ; /* dynamic return line */
extern int flen ; /* current allocated length of fline */
extern int ftype ;
extern int fpayload ; /* actual length of fline content */
fio_code ffclose( void) ;
fio_code ffgetline( void) ;
fio_code ffputline( char *buf, int nbuf, int dosflag) ;
fio_code ffropen( const char *fn) ;
fio_code ffwopen( const char *fn) ;
#endif

152
flook.c Normal file
View File

@ -0,0 +1,152 @@
/* flook.c -- implements flook.h */
#include "flook.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "defines.h"
#include "fileio.h"
/* possible names and paths of help files under different OSs */
const char *pathname[] = {
#if MSDOS
"emacs.rc",
"emacs.hlp",
"\\sys\\public\\",
"\\usr\\bin\\",
"\\bin\\",
"\\",
""
#endif
#if V7 | BSD | USG
".emacsrc",
"emacs.hlp",
#if PKCODE
"/usr/global/lib/", "/usr/local/bin/", "/usr/local/lib/",
#endif
"/usr/local/", "/usr/lib/", ""
#endif
#if VMS
{
"emacs.rc", "emacs.hlp", "",
#if PKCODE
"sys$login:", "emacs_dir:",
#endif
"sys$sysdevice:[vmstools]"
#endif
};
#define PATHNAME_SIZE (sizeof pathname / sizeof pathname[ 0])
/*
* does <fname> exist on disk?
*
* char *fname; file to check for existance
*/
boolean fexist( const char *fname)
{
FILE *fp;
/* try to open the file for reading */
fp = fopen(fname, "r");
/* if it fails, just return false! */
if (fp == NULL)
return FALSE;
/* otherwise, close it and report true */
fclose(fp);
return TRUE;
}
/*
* Look up the existance of a file along the normal or PATH
* environment variable. Look first in the HOME directory if
* asked and possible
*
* char *fname; base file name to search for
* boolean hflag; Look in the HOME environment variable first?
*/
char *flook( const char *fname, boolean hflag)
{
int i; /* index */
static char fspec[NSTRING]; /* full path spec to search */
#if ENVFUNC
char *path; /* environmental PATH variable */
if (hflag) {
char *home; /* path to home directory */
home = getenv("HOME");
if (home != NULL) {
/* build home dir file spec */
strcpy(fspec, home);
strcat(fspec, "/");
strcat(fspec, fname);
/* and try it out */
if( fexist( fspec))
return fspec ;
}
}
#endif
/* always try the current directory first */
strcpy( fspec, fname) ;
if( fexist( fspec))
return fspec ;
#if ENVFUNC
#if V7 | USG | BSD
#define PATHCHR ':'
#else
#define PATHCHR ';'
#endif
/* get the PATH variable */
path = getenv("PATH");
if (path != NULL)
while (*path) {
char *sp; /* pointer into path spec */
/* build next possible file spec */
sp = fspec;
while (*path && (*path != PATHCHR))
*sp++ = *path++;
/* add a terminating dir separator if we need it */
if (sp != fspec)
*sp++ = '/';
*sp = 0;
strcat(fspec, fname);
/* and try it out */
if( fexist( fspec))
return fspec ;
if (*path == PATHCHR)
++path;
}
#endif
/* look it up via the old table method */
for( i = 2; i < PATHNAME_SIZE ; i++) {
strcpy(fspec, pathname[i]);
strcat(fspec, fname);
/* and try it out */
if( fexist( fspec))
return fspec ;
}
return NULL; /* no such luck */
}

12
flook.h Normal file
View File

@ -0,0 +1,12 @@
#include "retcode.h"
#define rcfname pathname[ 0]
#define hlpfname pathname[ 1]
extern const char *pathname[] ;
boolean fexist( const char *fname) ;
char *flook( const char *fname, boolean hflag) ;

135
globals.c
View File

@ -1,135 +0,0 @@
#include "estruct.h"
#include "edef.h"
/* initialized global definitions */
int fillcol = 72; /* Current fill column */
int kbdm[NKBDM]; /* Macro */
char *execstr = NULL; /* pointer to string to execute */
char golabel[NPAT] = ""; /* current line to go to */
int execlevel = 0; /* execution IF level */
int eolexist = TRUE; /* does clear to EOL exist */
int revexist = FALSE; /* does reverse video exist? */
int flickcode = FALSE; /* do flicker supression? */
char *modename[] = { /* name of modes */
"WRAP", "CMODE", "SPELL", "EXACT", "VIEW", "OVER",
"MAGIC", "CRYPT", "ASAVE", "UTF-8"
};
char *mode2name[] = { /* name of modes */
"Wrap", "Cmode", "Spell", "Exact", "View", "Over",
"Magic", "Crypt", "Asave", "utf-8"
};
char modecode[] = "WCSEVOMYAU"; /* letters to represent modes */
int gmode = 0; /* global editor mode */
int gflags = GFREAD; /* global control flag */
#if PKCODE & IBMPC
int gfcolor = 8; /* global forgrnd color (white) */
#else
int gfcolor = 7; /* global forgrnd color (white) */
#endif
int gbcolor = 0; /* global backgrnd color (black) */
int gasave = 256; /* global ASAVE size */
int gacount = 256; /* count until next ASAVE */
int sgarbf = TRUE; /* TRUE if screen is garbage */
int mpresf = FALSE; /* TRUE if message in last line */
int clexec = FALSE; /* command line execution flag */
int mstore = FALSE; /* storing text to macro flag */
int discmd = TRUE; /* display command flag */
int disinp = TRUE; /* display input characters */
struct buffer *bstore = NULL; /* buffer to store macro text to */
int vtrow = 0; /* Row location of SW cursor */
int vtcol = 0; /* Column location of SW cursor */
int ttrow = HUGE; /* Row location of HW cursor */
int ttcol = HUGE; /* Column location of HW cursor */
int lbound = 0; /* leftmost column of current line
being displayed */
int taboff = 0; /* tab offset for display */
int metac = CONTROL | '['; /* current meta character */
int ctlxc = CONTROL | 'X'; /* current control X prefix char */
int reptc = CONTROL | 'U'; /* current universal repeat char */
int abortc = CONTROL | 'G'; /* current abort command char */
int quotec = 0x11; /* quote char during mlreply() */
int tabmask = 0x07; /* tabulator mask */
char *cname[] = { /* names of colors */
"BLACK", "RED", "GREEN", "YELLOW", "BLUE",
"MAGENTA", "CYAN", "WHITE"
#if PKCODE & IBMPC
, "HIGH"
#endif
};
struct kill *kbufp = NULL; /* current kill buffer chunk pointer */
struct kill *kbufh = NULL; /* kill buffer header pointer */
int kused = KBLOCK; /* # of bytes used in kill buffer */
struct window *swindow = NULL; /* saved window pointer */
int cryptflag = FALSE; /* currently encrypting? */
int *kbdptr; /* current position in keyboard buf */
int *kbdend = &kbdm[0]; /* ptr to end of the keyboard */
int kbdmode = STOP; /* current keyboard macro mode */
int kbdrep = 0; /* number of repetitions */
int restflag = FALSE; /* restricted use? */
int lastkey = 0; /* last keystoke */
int seed = 0; /* random number seed */
long envram = 0l; /* # of bytes current in use by malloc */
int macbug = FALSE; /* macro debuging flag */
char errorm[] = "ERROR"; /* error literal */
char truem[] = "TRUE"; /* true literal */
char falsem[] = "FALSE"; /* false litereal */
int cmdstatus = TRUE; /* last command status */
char palstr[49] = ""; /* palette string */
int saveflag = 0; /* Flags, saved with the $target var */
char *fline = NULL; /* dynamic return line */
int flen = 0; /* current length of fline */
int rval = 0; /* return value of a subprocess */
#if PKCODE
int nullflag = FALSE; /* accept null characters */
int justflag = FALSE; /* justify, don't fill */
#endif
int overlap = 0; /* line overlap in forw/back page */
int scrollcount = 1; /* number of lines to scroll */
/* uninitialized global definitions */
int currow; /* Cursor row */
int curcol; /* Cursor column */
int thisflag; /* Flags, this command */
int lastflag; /* Flags, last command */
int curgoal; /* Goal for C-P, C-N */
struct window *curwp; /* Current window */
struct buffer *curbp; /* Current buffer */
struct window *wheadp; /* Head of list of windows */
struct buffer *bheadp; /* Head of list of buffers */
struct buffer *blistp; /* Buffer for C-X C-B */
char sres[NBUFN]; /* current screen resolution */
char pat[NPAT]; /* Search pattern */
char tap[NPAT]; /* Reversed pattern array. */
char rpat[NPAT]; /* replacement pattern */
/* The variable matchlen holds the length of the matched
* string - used by the replace functions.
* The variable patmatch holds the string that satisfies
* the search command.
* The variables matchline and matchoff hold the line and
* offset position of the *start* of match.
*/
unsigned int matchlen = 0;
unsigned int mlenold = 0;
char *patmatch = NULL;
struct line *matchline = NULL;
int matchoff = 0;
/* directive name table:
This holds the names of all the directives.... */
char *dname[] = {
"if", "else", "endif",
"goto", "return", "endm",
"while", "endwhile", "break",
"force"
};
#if DEBUGM
/* vars needed for macro debugging output */
char outline[NSTRING]; /* global string to hold debug line text */
#endif

View File

@ -12,7 +12,6 @@
#include <stdio.h> #include <stdio.h>
#include "estruct.h" #include "estruct.h"
#include "edef.h"
#if IBMPC #if IBMPC
#if PKCODE #if PKCODE

45
input.c
View File

@ -1,3 +1,7 @@
/* input.c -- implements input.h */
#include "input.h"
/* input.c /* input.c
* *
* Various input routines * Various input routines
@ -7,11 +11,16 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "bind.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "bindable.h"
#include "efunc.h" #include "display.h"
#include "exec.h"
#include "names.h"
#include "terminal.h"
#include "wrapper.h" #include "wrapper.h"
#if PKCODE #if PKCODE
@ -26,15 +35,33 @@
#define COMPLC 0 #define COMPLC 0
#endif #endif
#define NKBDM 256 /* # of strokes, keyboard macro */
int kbdm[ NKBDM] ; /* Macro */
int *kbdptr ; /* current position in keyboard buf */
int *kbdend = &kbdm[0] ; /* ptr to end of the keyboard */
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 */
int abortc = CONTROL | 'G' ; /* current abort command char */
static const int quotec = 0x11 ; /* quote char during mlreply() */
/* /*
* Ask a yes or no question in the message line. Return either TRUE, FALSE, or * Ask a yes or no question in the message line. Return either TRUE, FALSE, or
* ABORT. The ABORT status is returned if the user bumps out of the question * ABORT. The ABORT status is returned if the user bumps out of the question
* with a ^G. Used any time a confirmation is required. * with a ^G. Used any time a confirmation is required.
*/ */
int mlyesno(char *prompt) int mlyesno( const char *prompt)
{ {
char c; /* input character */ char c; /* input character */
char buf[NPAT]; /* prompt to user */ char buf[ NSTRING] ; /* prompt to user */
for (;;) { for (;;) {
/* build and prompt the user */ /* build and prompt the user */
@ -42,7 +69,7 @@ int mlyesno(char *prompt)
strcat(buf, " (y/n)? "); strcat(buf, " (y/n)? ");
mlwrite(buf); mlwrite(buf);
/* get the responce */ /* get the response */
c = tgetc(); c = tgetc();
if (c == ectoc(abortc)) /* Bail out! */ if (c == ectoc(abortc)) /* Bail out! */
@ -64,12 +91,12 @@ int mlyesno(char *prompt)
* return. Handle erase, kill, and abort keys. * return. Handle erase, kill, and abort keys.
*/ */
int mlreply(char *prompt, char *buf, int nbuf) int mlreply( const char *prompt, char *buf, int nbuf)
{ {
return nextarg(prompt, buf, nbuf, ctoec('\n')); return nextarg(prompt, buf, nbuf, ctoec('\n'));
} }
int mlreplyt(char *prompt, char *buf, int nbuf, int eolchar) int mlreplyt(const char *prompt, char *buf, int nbuf, int eolchar)
{ {
return nextarg(prompt, buf, nbuf, eolchar); return nextarg(prompt, buf, nbuf, eolchar);
} }
@ -438,11 +465,11 @@ handle_CSI:
to specify the proper terminator. If the terminator is not to specify the proper terminator. If the terminator is not
a return ('\n') it will echo as "<NL>" a return ('\n') it will echo as "<NL>"
*/ */
int getstring(char *prompt, char *buf, int nbuf, int eolchar) int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
{ {
int cpos; /* current character position in string */ int cpos; /* current character position in string */
int c; int c;
int quotef; /* are we quoting the next char? */ boolean quotef ; /* are we quoting the next char? */
#if COMPLC #if COMPLC
int ffile, ocpos, nskip = 0, didtry = 0; int ffile, ocpos, nskip = 0, didtry = 0;
#if MSDOS #if MSDOS

36
input.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef _INPUT_H_
#define _INPUT_H_
#include "bind.h"
typedef enum {
STOP, PLAY, RECORD
} kbdstate ;
extern kbdstate kbdmode ; /* current keyboard macro mode */
extern int lastkey ; /* last keystoke */
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 */
extern int reptc; /* current universal repeat char */
extern int abortc; /* current abort command char */
int mlyesno( const char *prompt) ;
int mlreply( const char *prompt, char *buf, int nbuf) ;
int mlreplyt( const char *prompt, char *buf, int nbuf, int eolchar) ;
int ectoc( int c) ;
int ctoec( int c) ;
fn_t getname( void) ;
int tgetc( void) ;
int get1key( void) ;
int getcmd( void) ;
int getstring( const char *prompt, char *buf, int nbuf, int eolchar) ;
void outstring( char *s) ;
void ostring( char *s) ;
#endif

View File

@ -1,3 +1,5 @@
#include "isearch.h"
/* isearch.c /* isearch.c
* *
* The functions in this file implement commands that perform incremental * The functions in this file implement commands that perform incremental
@ -23,11 +25,52 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "basic.h"
#include "buffer.h"
#include "display.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "exec.h"
#include "efunc.h" #include "input.h"
#include "line.h" #include "line.h"
#include "search.h"
#include "terminal.h"
#include "window.h"
/*
* Incremental search defines.
*/
#if ISRCH
#define CMDBUFLEN 256 /* Length of our command buffer */
#define IS_ABORT 0x07 /* Abort the isearch */
#define IS_BACKSP 0x08 /* Delete previous char */
#define IS_TAB 0x09 /* Tab character (allowed search char) */
#define IS_NEWLINE 0x0D /* New line from keyboard (Carriage return) */
#define IS_QUOTE 0x11 /* Quote next character */
#define IS_REVERSE 0x12 /* Search backward */
#define IS_FORWARD 0x13 /* Search forward */
#define IS_VMSQUOTE 0x16 /* VMS quote character */
#define IS_VMSFORW 0x18 /* Search forward for VMS */
#define IS_QUIT 0x1B /* Exit the search */
#define IS_RUBOUT 0x7F /* Delete previous character */
/* IS_QUIT is no longer used, the variable metac is used instead */
#endif
static int isearch( int f, int n) ;
static int checknext( char chr, char *patrn, int dir) ;
static int scanmore( char *patrn, int dir) ;
static int match_pat( char *patrn) ;
static int promptpattern( char *prompt) ;
static int get_char( void) ;
static int uneat( void) ;
static void reeat( int c) ;
#if ISRCH #if ISRCH
@ -138,14 +181,14 @@ int fisearch(int f, int n)
* exists (or until the search is aborted). * exists (or until the search is aborted).
*/ */
int isearch(int f, int n) static int isearch(int f, int n)
{ {
int status; /* Search status */ int status; /* Search status */
int col; /* prompt column */ int col; /* prompt column */
int cpos; /* character number in search string */ int cpos; /* character number in search string */
int c; /* current input character */ int c; /* current input character */
int expc; /* function expanded input char */ int expc; /* function expanded input char */
char pat_save[NPAT]; /* Saved copy of the old pattern str */ spat_t pat_save ; /* Saved copy of the old pattern str */
struct line *curline; /* Current line on entry */ struct line *curline; /* Current line on entry */
int curoff; /* Current offset on entry */ int curoff; /* Current offset on entry */
int init_direction; /* The initial search direction */ int init_direction; /* The initial search direction */
@ -155,7 +198,7 @@ int isearch(int f, int n)
cmd_reexecute = -1; /* We're not re-executing (yet?) */ cmd_reexecute = -1; /* We're not re-executing (yet?) */
cmd_offset = 0; /* Start at the beginning of the buff */ cmd_offset = 0; /* Start at the beginning of the buff */
cmd_buff[0] = '\0'; /* Init the command buffer */ cmd_buff[0] = '\0'; /* Init the command buffer */
strncpy(pat_save, pat, NPAT); /* Save the old pattern string */ strncpy( pat_save, pat, sizeof pat_save) ; /* Save the old pattern string */
curline = curwp->w_dotp; /* Save the current line pointer */ curline = curwp->w_dotp; /* Save the current line pointer */
curoff = curwp->w_doto; /* Save the current offset */ curoff = curwp->w_doto; /* Save the current offset */
init_direction = n; /* Save the initial search direction */ init_direction = n; /* Save the initial search direction */
@ -233,7 +276,7 @@ int isearch(int f, int n)
curwp->w_dotp = curline; /* Reset the line pointer */ curwp->w_dotp = curline; /* Reset the line pointer */
curwp->w_doto = curoff; /* and the offset */ curwp->w_doto = curoff; /* and the offset */
n = init_direction; /* Reset the search direction */ n = init_direction; /* Reset the search direction */
strncpy(pat, pat_save, NPAT); /* Restore the old search str */ strncpy( pat, pat_save, sizeof pat) ; /* Restore the old search str */
cmd_reexecute = 0; /* Start the whole mess over */ cmd_reexecute = 0; /* Start the whole mess over */
goto start_over; /* Let it take care of itself */ goto start_over; /* Let it take care of itself */
@ -249,7 +292,8 @@ int isearch(int f, int n)
/* I guess we got something to search for, so search for it */ /* I guess we got something to search for, so search for it */
pat[cpos++] = c; /* put the char in the buffer */ pat[cpos++] = c; /* put the char in the buffer */
if (cpos >= NPAT) { /* too many chars in string? *//* Yup. Complain about it */ if (cpos >= sizeof pat) { /* too many chars in string? */
/* Yup. Complain about it */
mlwrite("? Search string too long"); mlwrite("? Search string too long");
return TRUE; /* Return an error */ return TRUE; /* Return an error */
} }
@ -278,7 +322,7 @@ int isearch(int f, int n)
* char *patrn; The entire search string (incl chr) * char *patrn; The entire search string (incl chr)
* int dir; Search direction * int dir; Search direction
*/ */
int checknext(char chr, char *patrn, int dir) /* Check next character in search string */ static int checknext(char chr, char *patrn, int dir) /* Check next character in search string */
{ {
struct line *curline; /* current line during scan */ struct line *curline; /* current line during scan */
int curoff; /* position within current line */ int curoff; /* position within current line */
@ -322,7 +366,7 @@ int checknext(char chr, char *patrn, int dir) /* Check next character in search
* char *patrn; string to scan for * char *patrn; string to scan for
* int dir; direction to search * int dir; direction to search
*/ */
int scanmore(char *patrn, int dir) /* search forward or back for a pattern */ static int scanmore(char *patrn, int dir) /* search forward or back for a pattern */
{ {
int sts; /* search status */ int sts; /* search status */
@ -351,7 +395,7 @@ int scanmore(char *patrn, int dir) /* search forward or back for a pattern
* *
* char *patrn; String to match to buffer * char *patrn; String to match to buffer
*/ */
int match_pat(char *patrn) /* See if the pattern string matches string at "." */ static int match_pat(char *patrn) /* See if the pattern string matches string at "." */
{ {
int i; /* Generic loop index/offset */ int i; /* Generic loop index/offset */
int buffchar; /* character at current position */ int buffchar; /* character at current position */
@ -383,7 +427,7 @@ int match_pat(char *patrn) /* See if the pattern string matches string at "."
/* /*
* Routine to prompt for I-Search string. * Routine to prompt for I-Search string.
*/ */
int promptpattern(char *prompt) static int promptpattern(char *prompt)
{ {
char tpat[NPAT + 20]; char tpat[NPAT + 20];
@ -450,7 +494,7 @@ static int echo_char(int c, int col)
* Otherwise, we must be re-executing the command string, so just return the * Otherwise, we must be re-executing the command string, so just return the
* next character. * next character.
*/ */
int get_char(void) static int get_char(void)
{ {
int c; /* A place to get a character */ int c; /* A place to get a character */
@ -481,7 +525,7 @@ int get_char(void)
/* Come here on the next term.t_getchar call: */ /* Come here on the next term.t_getchar call: */
int uneat(void) static int uneat(void)
{ {
int c; int c;
@ -491,7 +535,7 @@ int uneat(void)
return c; /* and return the last char */ return c; /* and return the last char */
} }
void reeat(int c) static void reeat(int c)
{ {
if (eaten_char != -1) /* If we've already been here */ if (eaten_char != -1) /* If we've already been here */
return /*(NULL) */ ; /* Don't do it again */ return /*(NULL) */ ; /* Don't do it again */

11
isearch.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef __ISEARCH_H__
#define __ISEARCH_H__
#define ISRCH 1 /* Incremental searches like ITS EMACS */
#if ISRCH
int risearch( int f, int n) ;
int fisearch( int f, int n) ;
#endif
#endif

217
line.c
View File

@ -15,15 +15,140 @@
#include "line.h" #include "line.h"
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "buffer.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "log.h"
#include "efunc.h" #include "window.h"
#include "utf8.h"
int tabmask = 0x07 ; /* tabulator mask */
#define BLOCK_SIZE 16 /* Line block chunk size. */ #define BLOCK_SIZE 16 /* Line block chunk size. */
static int ldelnewline( void) ;
/* The editor holds deleted text chunks in the struct kill buffer. The
* kill buffer is logically a stream of ascii characters, however
* due to its unpredicatable size, it gets implemented as a linked
* list of chunks. (The d_ prefix is for "deleted" text, as k_
* was taken up by the keycode structure).
*/
#define KBLOCK 250 /* sizeof kill buffer chunks */
struct kill {
struct kill *d_next; /* Link to next chunk, NULL if last. */
char d_chunk[KBLOCK]; /* Deleted text. */
};
static struct kill *kbufp = NULL ; /* current kill buffer chunk pointer */
static struct kill *kbufh = NULL ; /* kill buffer header pointer */
static int kused = KBLOCK ; /* # of bytes used in kill buffer */
static int klen ; /* length of kill buffer content */
static char *value = NULL ; /* temp buffer for value */
/*
* return some of the contents of the kill buffer
*/
char *getkill( void) {
struct kill *kp ;
char *cp ;
if (kbufh == NULL)
/* no kill buffer....just a null string */
return "" ;
if( value != NULL)
free( value) ;
value = (char *) malloc( klen + 1) ;
cp = value ;
for( kp = kbufh ; kp != NULL ; kp = kp->d_next) {
int size ;
if( kp->d_next != NULL)
size = KBLOCK ;
else
size = kused ;
memcpy( cp, kp->d_chunk, size) ;
cp += size ;
}
*cp = 0 ;
/* and return the constructed value */
return value;
}
/*
* Move the cursor backwards by "n" characters. If "n" is less than zero call
* "forwchar" to actually do the move. Otherwise compute the new cursor
* location. Error if you try and move out of the buffer. Set the flag if the
* line pointer for dot changes.
*/
int backchar(int f, int n)
{
struct line *lp;
if (n < 0)
return forwchar(f, -n);
while (n--) {
if (curwp->w_doto == 0) {
if ((lp = lback(curwp->w_dotp)) == curbp->b_linep)
return FALSE;
curwp->w_dotp = lp;
curwp->w_doto = llength(lp);
curwp->w_flag |= WFMOVE;
} else {
do {
unsigned char c;
curwp->w_doto--;
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (is_beginning_utf8(c))
break;
} while (curwp->w_doto);
}
}
return TRUE;
}
/*
* Move the cursor forwards by "n" characters. If "n" is less than zero call
* "backchar" to actually do the move. Otherwise compute the new cursor
* location, and move ".". Error if you try and move off the end of the
* buffer. Set the flag if the line pointer for dot changes.
*/
int forwchar(int f, int n)
{
if (n < 0)
return backchar(f, -n);
while (n--) {
int len = llength(curwp->w_dotp);
if (curwp->w_doto == len) {
if (curwp->w_dotp == curbp->b_linep)
return FALSE;
curwp->w_dotp = lforw(curwp->w_dotp);
curwp->w_doto = 0;
curwp->w_flag |= WFMOVE;
} else {
do {
unsigned char c;
curwp->w_doto++;
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (is_beginning_utf8(c))
break;
} while (curwp->w_doto < len);
}
}
return TRUE;
}
/* /*
* This routine allocates a block of memory large enough to hold a struct line * This routine allocates a block of memory large enough to hold a struct line
* containing "used" characters. The block is always rounded up a bit. Return * containing "used" characters. The block is always rounded up a bit. Return
@ -39,7 +164,7 @@ struct line *lalloc(int used)
if (size == 0) /* Assume that is an empty. */ if (size == 0) /* Assume that is an empty. */
size = BLOCK_SIZE; /* Line is for type-in. */ size = BLOCK_SIZE; /* Line is for type-in. */
if ((lp = (struct line *)malloc(sizeof(struct line) + size)) == NULL) { if ((lp = (struct line *)malloc(sizeof(struct line) + size)) == NULL) {
mlwrite("(OUT OF MEMORY)"); logwrite( "(OUT OF MEMORY)") ;
return NULL; return NULL;
} }
lp->l_size = size; lp->l_size = size;
@ -132,23 +257,22 @@ int insspace(int f, int n)
* linstr -- Insert a string at the current point * linstr -- Insert a string at the current point
*/ */
int linstr(char *instr) int linstr( char *instr) {
{
int status = TRUE ; int status = TRUE ;
if( instr != NULL) {
char tmpc ; char tmpc ;
if (instr != NULL) while( (tmpc = *instr++)) {
while ((tmpc = *instr) && status == TRUE) {
status = status =
(tmpc == '\n' ? lnewline() : linsert( 1, tmpc)) ; (tmpc == '\n' ? lnewline() : linsert( 1, tmpc)) ;
/* Insertion error? */ /* Insertion error? */
if (status != TRUE) { if( status != TRUE)
mlwrite("%%Out of memory while inserting"); return logger( status, FALSE, "%%Out of memory while inserting") ;
break;
} }
instr++;
} }
return status ; return status ;
} }
@ -173,13 +297,16 @@ static int linsert_byte(int n, int c)
int i; int i;
struct window *wp; struct window *wp;
assert( (curbp->b_mode & MDVIEW) == 0) ;
#if 0
if (curbp->b_mode & MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */ return rdonly(); /* we are in read only mode */
#endif
lchange(WFEDIT); lchange(WFEDIT);
lp1 = curwp->w_dotp; /* Current line */ lp1 = curwp->w_dotp; /* Current line */
if (lp1 == curbp->b_linep) { /* At the end: special */ if (lp1 == curbp->b_linep) { /* At the end: special */
if (curwp->w_doto != 0) { if (curwp->w_doto != 0) {
mlwrite("bug: linsert"); logwrite( "bug: linsert") ;
return FALSE; return FALSE;
} }
if ((lp2 = lalloc(n)) == NULL) /* Allocate new line */ if ((lp2 = lalloc(n)) == NULL) /* Allocate new line */
@ -243,8 +370,13 @@ static int linsert_byte(int n, int c)
int linsert(int n, int c) int linsert(int n, int c)
{ {
char utf8[6]; char utf8[6];
int bytes = unicode_to_utf8(c, utf8), i; int bytes, i ;
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) if (bytes == 1)
return linsert_byte(n, (unsigned char) utf8[0]); return linsert_byte(n, (unsigned char) utf8[0]);
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
@ -263,7 +395,7 @@ int linsert(int n, int c)
* *
* int c; character to overwrite on current position * int c; character to overwrite on current position
*/ */
int lowrite(int c) static int lowrite(int c)
{ {
if (curwp->w_doto < curwp->w_dotp->l_used && if (curwp->w_doto < curwp->w_dotp->l_used &&
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' || (lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
@ -275,24 +407,22 @@ int lowrite(int c)
/* /*
* lover -- Overwrite a string at the current point * lover -- Overwrite a string at the current point
*/ */
int lover(char *ostr) int lover( char *ostr) {
{
int status = TRUE ; int status = TRUE ;
if (ostr != NULL) {
char tmpc ; char tmpc ;
if (ostr != NULL) while( (tmpc = *ostr++)) {
while ((tmpc = *ostr) && status == TRUE) {
status = status =
(tmpc == '\n' ? lnewline() : lowrite(tmpc)); (tmpc == '\n' ? lnewline() : lowrite(tmpc));
/* Insertion error? */ /* Insertion error? */
if (status != TRUE) { if( status != TRUE)
mlwrite return logger( status, FALSE, "%%Out of memory while overwriting") ;
("%%Out of memory while overwriting");
break;
} }
ostr++;
} }
return status ; return status ;
} }
@ -481,29 +611,6 @@ char *getctext(void)
return rline; return rline;
} }
/*
* putctext:
* replace the current line with the passed in text
*
* char *iline; contents of new line
*/
int putctext(char *iline)
{
int status;
/* delete the current line */
curwp->w_doto = 0; /* starting at the beginning of the line */
if ((status = killtext(TRUE, 1)) != TRUE)
return status;
/* insert the new line */
if ((status = linstr(iline)) != TRUE)
return status;
status = lnewline();
backline(TRUE, 1);
return status;
}
/* /*
* Delete a newline. Join the current line with the next line. If the next line * Delete a newline. Join the current line with the next line. If the next line
* is the magic header line always return TRUE; merging the last line with the * is the magic header line always return TRUE; merging the last line with the
@ -513,7 +620,7 @@ int putctext(char *iline)
* about in memory. Return FALSE on error and TRUE if all looks ok. Called by * about in memory. Return FALSE on error and TRUE if all looks ok. Called by
* "ldelete" only. * "ldelete" only.
*/ */
int ldelnewline(void) static int ldelnewline(void)
{ {
char *cp1; char *cp1;
char *cp2; char *cp2;
@ -522,8 +629,11 @@ int ldelnewline(void)
struct line *lp3; struct line *lp3;
struct window *wp; struct window *wp;
assert( (curbp->b_mode & MDVIEW) == 0) ;
#if 0
if (curbp->b_mode & MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */ return rdonly(); /* we are in read only mode */
#endif
lp1 = curwp->w_dotp; lp1 = curwp->w_dotp;
lp2 = lp1->l_fp; lp2 = lp1->l_fp;
if (lp2 == curbp->b_linep) { /* At the buffer end. */ if (lp2 == curbp->b_linep) { /* At the buffer end. */
@ -614,6 +724,11 @@ void kdelete(void)
/* and reset all the kill buffer pointers */ /* and reset all the kill buffer pointers */
kbufh = kbufp = NULL; kbufh = kbufp = NULL;
kused = KBLOCK; kused = KBLOCK;
klen = 0 ;
if( value != NULL) {
free( value) ;
value = NULL ;
}
} }
} }
@ -631,8 +746,11 @@ int kinsert(int c)
if (kused >= KBLOCK) { if (kused >= KBLOCK) {
if ((nchunk = (struct kill *)malloc(sizeof(struct kill))) == NULL) if ((nchunk = (struct kill *)malloc(sizeof(struct kill))) == NULL)
return FALSE; return FALSE;
if (kbufh == NULL) /* set head ptr if first time */ if( kbufh == NULL) { /* set head ptr if first time */
kbufh = nchunk; kbufh = nchunk;
klen = 0 ;
}
if (kbufp != NULL) /* point the current to this new one */ if (kbufp != NULL) /* point the current to this new one */
kbufp->d_next = nchunk; kbufp->d_next = nchunk;
kbufp = nchunk; kbufp = nchunk;
@ -642,6 +760,7 @@ int kinsert(int c)
/* and now insert the character */ /* and now insert the character */
kbufp->d_chunk[kused++] = c; kbufp->d_chunk[kused++] = c;
klen += 1 ;
return TRUE; return TRUE;
} }

42
line.h
View File

@ -3,6 +3,8 @@
#include "utf8.h" #include "utf8.h"
#define NLINE 256 /* # of bytes, input line */
/* /*
* All text is kept in circularly linked lists of "struct line" structures. These * All text is kept in circularly linked lists of "struct line" structures. These
* begin at the header line (which is the blank line beyond the end of the * begin at the header line (which is the blank line beyond the end of the
@ -25,23 +27,27 @@ struct line {
#define lputc(lp, n, c) ((lp)->l_text[(n)]=(c)) #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
#define llength(lp) ((lp)->l_used) #define llength(lp) ((lp)->l_used)
extern void lfree(struct line *lp); extern int tabmask ;
extern void lchange(int flag);
extern int insspace(int f, int n); char *getkill( void) ;
extern int linstr(char *instr);
extern int linsert(int n, int c); int backchar( int f, int n) ;
extern int lowrite(int c); int forwchar( int f, int n) ;
extern int lover(char *ostr);
extern int lnewline(void); void lfree( struct line *lp) ;
extern int ldelete(long n, int kflag); void lchange( int flag) ;
extern int ldelchar(long n, int kflag); int insspace( int f, int n) ;
extern int lgetchar(unicode_t *); int linstr( char *instr) ;
extern char *getctext(void); int linsert( int n, int c) ;
extern int putctext(char *iline); int lover( char *ostr) ;
extern int ldelnewline(void); int lnewline( void) ;
extern void kdelete(void); int ldelete( long n, int kflag) ;
extern int kinsert(int c); int ldelchar( long n, int kflag) ;
extern int yank(int f, int n); int lgetchar( unicode_t *) ;
extern struct line *lalloc(int); /* Allocate a line. */ char *getctext( void) ;
void kdelete( void) ;
int kinsert( int c) ;
int yank( int f, int n) ;
struct line *lalloc( int) ; /* Allocate a line. */
#endif /* LINE_H_ */ #endif /* LINE_H_ */

38
lock.c
View File

@ -1,3 +1,6 @@
#include "estruct.h"
#include "lock.h"
/* LOCK.C /* LOCK.C
* *
* File locking command routines * File locking command routines
@ -5,24 +8,35 @@
* written by Daniel Lawrence * written by Daniel Lawrence
*/ */
#include <stdio.h>
#include "estruct.h"
#include "edef.h"
#include "efunc.h"
#if BSD | SVR4 #if BSD | SVR4
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "defines.h"
#include "display.h"
#include "input.h"
#include "retcode.h"
#if (FILOCK && BSD) || SVR4
#include "pklock.h"
#endif
#include <sys/errno.h> #include <sys/errno.h>
#define NLOCKS 100 /* max # of file locks active */
static char *lname[ NLOCKS] ; /* names of all locked files */ static char *lname[ NLOCKS] ; /* names of all locked files */
static int numlocks ; /* # of current locks active */ static int numlocks ; /* # of current locks active */
static void lckerror(char *errstr) ;
/* /*
* lockchk: * lockchk:
* check a file for locking and add it to the list * check a file for locking and add it to the list
* *
* char *fname; file to check for a lock * const char *fname; file to check for a lock
*/ */
int lockchk(char *fname) int lockchk( const char *fname)
{ {
int i; /* loop indexes */ int i; /* loop indexes */
int status; /* return status */ int status; /* return status */
@ -34,7 +48,7 @@ int lockchk(char *fname)
return TRUE; return TRUE;
/* if we have a full locking table, bitch and leave */ /* if we have a full locking table, bitch and leave */
if (numlocks == NLOCKS) { if( numlocks >= NLOCKS) {
mlwrite("LOCK ERROR: Lock table full"); mlwrite("LOCK ERROR: Lock table full");
return ABORT; return ABORT;
} }
@ -88,9 +102,9 @@ int lockrel(void)
* FALSE = file was locked and overridden * FALSE = file was locked and overridden
* ABORT = file was locked, abort command * ABORT = file was locked, abort command
* *
* char *fname; file name to lock * const char *fname; file name to lock
*/ */
int lock(char *fname) int lock( const char *fname)
{ {
char *locker; /* lock error message */ char *locker; /* lock error message */
int status; /* return status */ int status; /* return status */
@ -123,9 +137,9 @@ int lock(char *fname)
* Unlock a file * Unlock a file
* this only warns the user if it fails * this only warns the user if it fails
* *
* char *fname; file to unlock * const char *fname; file to unlock
*/ */
int unlock(char *fname) int unlock( const char *fname)
{ {
char *locker; /* undolock return string */ char *locker; /* undolock return string */

16
lock.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef _LOCK_H_
#define _LOCK_H_
#ifndef _ESTRUCT_H_
#error uEmacs compilation settings needs to be done!
#endif
#if BSD | SVR4
int lockchk( const char *fname) ;
int lockrel( void) ;
int lock( const char *fname) ;
int unlock( const char *fname) ;
#endif
#endif

38
log.c Normal file
View File

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

8
log.h Normal file
View File

@ -0,0 +1,8 @@
#include "retcode.h"
boolean rdonly( void) ;
boolean resterr( void) ;
extern void (*logwrite)( const char *, ...) ;
extern boolean (*logger)( boolean, boolean, const char *, ...) ;

421
main.c
View File

@ -1,3 +1,7 @@
/* main.c -- */
#define CLRMSG 0 /* space clears the message line with no insert */
/* /*
* main.c * main.c
@ -49,18 +53,38 @@
* *
* 4.0 Petri Kutvonen, 1-Sep-91 * 4.0 Petri Kutvonen, 1-Sep-91
* *
* This modified version is now called uEmacs/rf.
*
* 4.1 Renaud Fivet, 1-May-13
*
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
/* Make global definitions not external. */ #include <string.h>
#define maindef
#include "estruct.h" /* Global structures and defines. */ #include "estruct.h" /* Global structures and defines. */
#include "edef.h" /* Global definitions. */ #if UNIX
#include "efunc.h" /* Function declarations and name table. */ #include <signal.h>
#include "ebind.h" /* Default key bindings. */ #endif
#include "basic.h"
#include "bind.h"
#include "bindable.h"
#include "buffer.h"
#include "display.h"
#include "eval.h"
#include "execute.h"
#include "file.h"
#include "input.h"
#include "lock.h"
#include "log.h"
#include "random.h"
#include "search.h"
#include "terminal.h"
#include "termio.h"
#include "version.h" #include "version.h"
#include "window.h"
/* For MSDOS, increase the default stack space. */ /* For MSDOS, increase the default stack space. */
#if MSDOS & TURBO #if MSDOS & TURBO
@ -71,34 +95,47 @@ extern unsigned _stklen = 32766;
#endif #endif
#endif #endif
#if VMS
#include <ssdef.h>
#define GOOD (SS$_NORMAL)
#endif
#ifndef GOOD
#define GOOD 0
#endif
#if UNIX #if UNIX
#include <signal.h> static void emergencyexit(int signr)
static void emergencyexit(int);
#ifdef SIGWINCH
extern void sizesignal(int);
#endif
#endif
void usage(int status)
{ {
printf("Usage: %s filename\n", PROGRAM_NAME); quickexit(FALSE, 0);
printf(" or: %s [options]\n\n", PROGRAM_NAME); quit(TRUE, 0);
fputs(" + start at the end of file\n", stdout); }
fputs(" +<n> start at line <n>\n", stdout); #endif
fputs(" -g[G]<n> go to line <n>\n", stdout);
fputs(" --help display this help and exit\n", stdout);
fputs(" --version output version information and exit\n", stdout);
exit(status); static void edinit( char *bname) ;
static void version( void) {
fputs( PROGRAM_NAME_LONG " version " VERSION "\n", stdout) ;
}
static void usage( void) {
fputs( "Usage: " PROGRAM_NAME " [OPTION].. [FILE]..\n\n"
" + start at the end of file\n"
" +<n> start at line <n>\n"
" --help display this help and exit\n"
" --version output version information and exit\n"
" @cmdfile execute command file\n"
" -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"
, stdout) ;
}
static boolean mllog( boolean retcode, boolean beep_f, const char *buf, ...) {
if( beep_f)
TTbeep() ;
mlwrite( buf) ;
return retcode ;
} }
int main(int argc, char **argv) int main(int argc, char **argv)
@ -119,10 +156,10 @@ int main(int argc, char **argv)
int searchflag; /* Do we need to search at start? */ int searchflag; /* Do we need to search at start? */
int saveflag; /* temp store for lastflag */ int saveflag; /* temp store for lastflag */
int errflag; /* C error processing? */ int errflag; /* C error processing? */
char bname[NBUFN]; /* buffer name of file to read */ bname_t bname ; /* buffer name of file to read */
#if CRYPT #if CRYPT
int cryptflag; /* encrypting on the way in? */ int cryptflag; /* encrypting on the way in? */
char ekey[NPAT]; /* startup encryption key */ ekey_t ekey ; /* startup encryption key */
#endif #endif
int newc; int newc;
@ -141,8 +178,10 @@ int main(int argc, char **argv)
#endif #endif
if( argc == 2) { if( argc == 2) {
if( strcmp( argv[ 1], "--help") == 0) { if( strcmp( argv[ 1], "--help") == 0) {
usage(EXIT_FAILURE); usage() ;
exit( EXIT_SUCCESS) ;
} }
if( strcmp( argv[ 1], "--version") == 0) { if( strcmp( argv[ 1], "--version") == 0) {
version() ; version() ;
exit( EXIT_SUCCESS) ; exit( EXIT_SUCCESS) ;
@ -151,6 +190,8 @@ int main(int argc, char **argv)
/* Initialize the editor. */ /* Initialize the editor. */
vtinit(); /* Display */ vtinit(); /* Display */
logwrite = mlwrite ;
logger = mllog ;
edinit("main"); /* Buffers, windows */ edinit("main"); /* Buffers, windows */
varinit(); /* user variables */ varinit(); /* user variables */
@ -193,13 +234,8 @@ int main(int argc, char **argv)
case 'k': /* -k<key> for code key */ case 'k': /* -k<key> for code key */
case 'K': case 'K':
cryptflag = TRUE; cryptflag = TRUE;
strcpy(ekey, &argv[carg][2]); strncpy( ekey, &argv[ carg][ 2], sizeof ekey - 1) ;
break; ekey[ sizeof ekey - 1] = 0 ;
#endif
#if PKCODE
case 'n': /* -n accept null chars */
case 'N':
nullflag = TRUE;
break; break;
#endif #endif
case 'r': /* -r restrictive use */ case 'r': /* -r restrictive use */
@ -209,7 +245,8 @@ int main(int argc, char **argv)
case 's': /* -s for initial search string */ case 's': /* -s for initial search string */
case 'S': case 'S':
searchflag = TRUE; searchflag = TRUE;
strncpy(pat, &argv[carg][2], NPAT); strncpy( pat, &argv[ carg][ 2], sizeof pat - 1) ;
pat[ sizeof pat -1] = 0 ;
break; break;
case 'v': /* -v for View File */ case 'v': /* -v for View File */
case 'V': case 'V':
@ -237,7 +274,8 @@ int main(int argc, char **argv)
/* set this to inactive */ /* set this to inactive */
bp = bfind(bname, TRUE, 0); bp = bfind(bname, TRUE, 0);
strcpy(bp->b_fname, argv[carg]); strncpy( bp->b_fname, argv[ carg], sizeof bp->b_fname - 1) ; /* max filename length limited to NFILEN - 1 (79) */
bp->b_fname[ sizeof bp->b_fname - 1] = 0 ;
bp->b_active = FALSE; bp->b_active = FALSE;
if (firstfile) { if (firstfile) {
firstbp = bp; firstbp = bp;
@ -250,16 +288,17 @@ int main(int argc, char **argv)
#if CRYPT #if CRYPT
if (cryptflag) { if (cryptflag) {
bp->b_mode |= MDCRYPT; bp->b_mode |= MDCRYPT;
myencrypt((char *) NULL, 0); strncpy( bp->b_key, ekey, sizeof ekey) ;
myencrypt(ekey, strlen(ekey)); cryptbufferkey( bp) ;
strncpy(bp->b_key, ekey, NPAT);
} }
#endif #endif
} }
} }
#if UNIX #if UNIX
#ifdef SIGHUP
signal(SIGHUP, emergencyexit); signal(SIGHUP, emergencyexit);
#endif
signal(SIGTERM, emergencyexit); signal(SIGTERM, emergencyexit);
#endif #endif
@ -432,7 +471,7 @@ int main(int argc, char **argv)
* as an argument, because the main routine may have been told to read in a * as an argument, because the main routine may have been told to read in a
* file by default, and we want the buffer name to be right. * file by default, and we want the buffer name to be right.
*/ */
void edinit(char *bname) static void edinit(char *bname)
{ {
struct buffer *bp; struct buffer *bp;
struct window *wp; struct window *wp;
@ -464,279 +503,6 @@ void edinit(char *bname)
wp->w_flag = WFMODE | WFHARD; /* Full. */ wp->w_flag = WFMODE | WFHARD; /* Full. */
} }
/*
* This is the general command execution routine. It handles the fake binding
* of all the keys to "self-insert". It also clears out the "thisflag" word,
* and arranges to move it to the "lastflag", so that the next command can
* look at it. Return the status of command.
*/
int execute(int c, int f, int n)
{
int status;
fn_t execfunc;
/* if the keystroke is a bound function...do it */
execfunc = getbind(c);
if (execfunc != NULL) {
thisflag = 0;
status = (*execfunc) (f, n);
lastflag = thisflag;
return status;
}
/*
* If a space was typed, fill column is defined, the argument is non-
* negative, wrap mode is enabled, and we are now past fill column,
* and we are not read-only, perform word wrap.
*/
if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 &&
n >= 0 && getccol(FALSE) > fillcol &&
(curwp->w_bufp->b_mode & MDVIEW) == FALSE)
execute(META | SPEC | 'W', FALSE, 1);
#if PKCODE
if ((c >= 0x20 && c <= 0x7E) /* Self inserting. */
#if IBMPC
|| (c >= 0x80 && c <= 0xFE)) {
#else
#if VMS || BSD || USG /* 8BIT P.K. */
|| (c >= 0xA0 && c <= 0x10FFFF)) {
#else
) {
#endif
#endif
#else
if ((c >= 0x20 && c <= 0xFF)) { /* Self inserting. */
#endif
if (n <= 0) { /* Fenceposts. */
lastflag = 0;
return n < 0 ? FALSE : TRUE;
}
thisflag = 0; /* For the future. */
/* if we are in overwrite mode, not at eol,
and next char is not a tab or we are at a tab stop,
delete a char forword */
if (curwp->w_bufp->b_mode & MDOVER &&
curwp->w_doto < curwp->w_dotp->l_used &&
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
(curwp->w_doto) % 8 == 7))
ldelchar(1, FALSE);
/* do the appropriate insertion */
if (c == '}' && (curbp->b_mode & MDCMOD) != 0)
status = insbrace(n, c);
else if (c == '#' && (curbp->b_mode & MDCMOD) != 0)
status = inspound();
else
status = linsert(n, c);
#if CFENCE
/* check for CMODE fence matching */
if ((c == '}' || c == ')' || c == ']') &&
(curbp->b_mode & MDCMOD) != 0)
fmatch(c);
#endif
/* check auto-save mode */
if (curbp->b_mode & MDASAVE)
if (--gacount == 0) {
/* and save the file if needed */
upscreen(FALSE, 0);
filesave(FALSE, 0);
gacount = gasave;
}
lastflag = thisflag;
return status;
}
TTbeep();
mlwrite("(Key not bound)"); /* complain */
lastflag = 0; /* Fake last flags. */
return FALSE;
}
/*
* Fancy quit command, as implemented by Norm. If the any buffer has
* changed do a write on that buffer and exit emacs, otherwise simply exit.
*/
int quickexit(int f, int n)
{
struct buffer *bp; /* scanning pointer to buffers */
struct buffer *oldcb; /* original current buffer */
int status;
oldcb = curbp; /* save in case we fail */
bp = bheadp;
while (bp != NULL) {
if ((bp->b_flag & BFCHG) != 0 /* Changed. */
&& (bp->b_flag & BFTRUNC) == 0 /* Not truncated P.K. */
&& (bp->b_flag & BFINVS) == 0) { /* Real. */
curbp = bp; /* make that buffer cur */
mlwrite("(Saving %s)", bp->b_fname);
#if PKCODE
#else
mlwrite("\n");
#endif
if ((status = filesave(f, n)) != TRUE) {
curbp = oldcb; /* restore curbp */
return status;
}
}
bp = bp->b_bufp; /* on to the next buffer */
}
quit(f, n); /* conditionally quit */
return TRUE;
}
static void emergencyexit(int signr)
{
quickexit(FALSE, 0);
quit(TRUE, 0);
}
/*
* Quit command. If an argument, always quit. Otherwise confirm if a buffer
* has been changed and not written out. Normally bound to "C-X C-C".
*/
int quit(int f, int n)
{
int s;
if (f != FALSE /* Argument forces it. */
|| anycb() == FALSE /* All buffers clean. */
/* User says it's OK. */
|| (s =
mlyesno("Modified buffers exist. Leave anyway")) == TRUE) {
#if (FILOCK && BSD) || SVR4
if (lockrel() != TRUE) {
TTputc('\n');
TTputc('\r');
TTclose();
TTkclose();
exit(1);
}
#endif
vttidy();
if (f)
exit(n);
else
exit(GOOD);
}
mlwrite("");
return s;
}
/*
* Begin a keyboard macro.
* Error if not at the top level in keyboard processing. Set up variables and
* return.
*/
int ctlxlp(int f, int n)
{
if (kbdmode != STOP) {
mlwrite("%%Macro already active");
return FALSE;
}
mlwrite("(Start macro)");
kbdptr = &kbdm[0];
kbdend = kbdptr;
kbdmode = RECORD;
return TRUE;
}
/*
* End keyboard macro. Check for the same limit conditions as the above
* routine. Set up the variables and return to the caller.
*/
int ctlxrp(int f, int n)
{
if (kbdmode == STOP) {
mlwrite("%%Macro not active");
return FALSE;
}
if (kbdmode == RECORD) {
mlwrite("(End macro)");
kbdmode = STOP;
}
return TRUE;
}
/*
* Execute a macro.
* The command argument is the number of times to loop. Quit as soon as a
* command gets an error. Return TRUE if all ok, else FALSE.
*/
int ctlxe(int f, int n)
{
if (kbdmode != STOP) {
mlwrite("%%Macro already active");
return FALSE;
}
if (n <= 0)
return TRUE;
kbdrep = n; /* remember how many times to execute */
kbdmode = PLAY; /* start us in play mode */
kbdptr = &kbdm[0]; /* at the beginning */
return TRUE;
}
/*
* Abort.
* Beep the beeper. Kill off any keyboard macro, etc., that is in progress.
* Sometimes called as a routine, to do general aborting of stuff.
*/
int ctrlg(int f, int n)
{
TTbeep();
kbdmode = STOP;
mlwrite("(Aborted)");
return ABORT;
}
/*
* tell the user that this command is illegal while we are in
* VIEW (read-only) mode
*/
int rdonly(void)
{
TTbeep();
mlwrite("(Key illegal in VIEW mode)");
return FALSE;
}
int resterr(void)
{
TTbeep();
mlwrite("(That command is RESTRICTED)");
return FALSE;
}
/* user function that does NOTHING */
int nullproc(int f, int n)
{
return TRUE;
}
/* dummy function for binding to meta prefix */
int metafn(int f, int n)
{
return TRUE;
}
/* dummy function for binding to control-x prefix */
int cex(int f, int n)
{
return TRUE;
}
/* dummy function for binding to universal-argument */
int unarg(int f, int n)
{
return TRUE;
}
/***** Compiler specific Library functions ****/ /***** Compiler specific Library functions ****/
#if RAMSIZE #if RAMSIZE
@ -749,16 +515,19 @@ int unarg(int f, int n)
end of the bottom mode line and is updated whenever it is changed. end of the bottom mode line and is updated whenever it is changed.
*/ */
static void dspram( void) ;
#undef malloc #undef malloc
#undef free #undef free
#if 0
char *allocate(nbytes) char *allocate(nbytes)
/* allocate nbytes and track */ /* allocate nbytes and track */
unsigned nbytes; /* # of bytes to allocate */ unsigned nbytes; /* # of bytes to allocate */
#endif
void *allocate( size_t nbytes)
{ {
char *mp; /* ptr returned from malloc */ char *mp; /* ptr returned from malloc */
char *malloc(); /* char *malloc(); */
mp = malloc(nbytes); mp = malloc(nbytes);
if (mp) { if (mp) {
@ -771,10 +540,12 @@ unsigned nbytes; /* # of bytes to allocate */
return mp; return mp;
} }
#if 0
release(mp) release(mp)
/* release malloced memory and track */ /* release malloced memory and track */
char *mp; /* chunk of RAM to release */ char *mp; /* chunk of RAM to release */
#endif
void release( void *mp)
{ {
unsigned *lp; /* ptr to the long containing the block size */ unsigned *lp; /* ptr to the long containing the block size */
@ -790,7 +561,7 @@ char *mp; /* chunk of RAM to release */
} }
#if RAMSHOW #if RAMSHOW
dspram() static void dspram( void)
{ /* display the amount of RAM currently malloced */ { /* display the amount of RAM currently malloced */
char mbuf[20]; char mbuf[20];
char *sp; char *sp;

191
mingw32.c Normal file
View File

@ -0,0 +1,191 @@
#ifdef MINGW32
#include "termio.h"
#include "terminal.h"
#include <errno.h>
#include <io.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include "utf8.h"
#include "wscreen.h"
static void vv( void) {}
static void vi( int i) {}
static int is( char *s) { return *s ; }
static void ttmove( int l, int c) ;
#define MARGIN 8
#define SCRSIZ 64
#define NPAUSE 10 /* # times thru update to pause. */
struct terminal term = {
24, /* These four values are set dynamically at open time. */
24,
80,
80,
MARGIN,
SCRSIZ,
NPAUSE,
ttopen,
#if PKCODE
ttclose,
#else
ttclose,
#endif
vv, /* ttkopen, */
vv, /* ttkclose, */
ttgetc,
ttputc,
ttflush,
ttmove,
vv, /* tteeol, */
vv, /* tteeop, */
vv, /* ttbeep, */
vi, /* ttrev, */
is /* ttcres */
#if COLOR
, iv, /* ttfcol, */
iv /* ttbcol */
#endif
#if SCROLLCODE
, NULL /* set dynamically at open time */
#endif
} ;
int ttrow ; /* Row location of HW cursor */
int ttcol ; /* Column location of HW cursor */
boolean eolexist = TRUE ; /* does clear to EOL exist? */
boolean revexist = FALSE ; /* does reverse video exist? */
boolean sgarbf = TRUE ; /* State of screen unknown */
char sres[ 16] ; /* Current screen resolution. */
/* NORMAL, CGA, EGA, VGA */
void ttopen( void) {
winit() ;
wcls() ;
term.t_mrow = term.t_nrow = wbottom() - wtop() ;
term.t_mcol = term.t_ncol = wright() - wleft() + 1 ;
wtitle( "uEMACS") ;
}
void ttclose( void) {
}
int ttputc( int c) {
char utf8[ 6] ;
int bytes ;
bytes = unicode_to_utf8( c, utf8) ;
fwrite( utf8, 1, bytes, stdout);
return 0 ;
}
void ttflush( void) {
int status ;
status = fflush( stdout);
while( status < 0 && errno == EAGAIN) {
_sleep( 1) ;
status = fflush( stdout) ;
}
if( status < 0)
exit( 15) ;
}
int ttgetc( void) {
static char buffer[ 32] ;
static int pending ;
unicode_t c ;
int count, bytes = 1, expected ;
count = pending ;
if( !count) {
count = read( 0, buffer, sizeof( buffer)) ;
if( count <= 0)
return 0 ;
pending = count ;
}
c = (unsigned char) buffer[ 0] ;
if( c >= 32 && c < 128)
goto done ;
/*
* Lazy. We don't bother calculating the exact
* expected length. We want at least two characters
* for the special character case (ESC+[) and for
* the normal short UTF8 sequence that starts with
* the 110xxxxx pattern.
*
* But if we have any of the other patterns, just
* try to get more characters. At worst, that will
* just result in a barely perceptible 0.1 second
* delay for some *very* unusual utf8 character
* input.
*/
expected = 2 ;
if( (c & 0xe0) == 0xe0)
expected = 6 ;
/* Special character - try to fill buffer */
if( count < expected) {
int n;
#if 0
ntermios.c_cc[VMIN] = 0;
ntermios.c_cc[VTIME] = 1; /* A .1 second lag */
tcsetattr(0, TCSANOW, &ntermios);
#endif
n = read(0, buffer + count, sizeof(buffer) - count);
/* Undo timeout */
#if 0
ntermios.c_cc[VMIN] = 1;
ntermios.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &ntermios);
#endif
if (n > 0)
pending += n;
}
if( pending > 1) {
unsigned char second = buffer[1];
/* Turn ESC+'[' into CSI */
if (c == 27 && second == '[') {
bytes = 2;
c = 128+27;
goto done;
}
}
bytes = utf8_to_unicode( buffer, 0, pending, &c) ;
done:
pending -= bytes ;
memmove( buffer, buffer+bytes, pending) ;
return c ;
}
int typahead( void) {
int x ; /* holds # of pending chars */
#ifdef FIONREAD
if( ioctl( 0, FIONREAD, &x) < 0)
#endif
x = 0 ;
return x ;
}
static void ttmove( int l, int c) {
wgoxy( c, l) ;
}
#endif

25
names.c
View File

@ -1,14 +1,31 @@
/* names.c -- implements names.h */
#include "names.h"
/* Name to function binding table. /* Name to function binding table.
* *
* This table gives the names of all the bindable functions * This table gives the names of all the bindable functions
* end their C function address. These are used for the bind-to-key * and their C function address. These are used for the bind-to-key
* function. * function.
*/ */
#include "estruct.h" #include <stdlib.h>
#include "edef.h"
#include "efunc.h" #include "basic.h"
#include "bind.h"
#include "bindable.h"
#include "buffer.h"
#include "display.h"
#include "eval.h"
#include "exec.h"
#include "file.h"
#include "isearch.h"
#include "line.h" #include "line.h"
#include "region.h"
#include "random.h"
#include "search.h"
#include "spawn.h"
#include "window.h"
#include "word.h"
struct name_bind names[] = { struct name_bind names[] = {
{"abort-command", ctrlg}, {"abort-command", ctrlg},

8
names.h Normal file
View File

@ -0,0 +1,8 @@
/* Structure for the name binding table. */
struct name_bind {
char *n_name; /* name of function key */
int (*n_func)(int, int); /* function name is bound to */
};
extern struct name_bind names[];/* name to function table */

View File

@ -1,12 +1,12 @@
/* pklock.c -- implements pklock.h */
#include "estruct.h"
#include "pklock.h"
/* PKLOCK.C /* PKLOCK.C
* *
* locking routines as modified by Petri Kutvonen * locking routines as modified by Petri Kutvonen
*/ */
#include "estruct.h"
#include "edef.h"
#include "efunc.h"
#if (FILOCK && BSD) || SVR4 #if (FILOCK && BSD) || SVR4
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -41,7 +41,7 @@ int gethostname(char *name, int namelen)
* if other error, returns "LOCK ERROR: explanation" * if other error, returns "LOCK ERROR: explanation"
* *
*********************/ *********************/
char *dolock(char *fname) char *dolock( const char *fname)
{ {
int fd, n; int fd, n;
static char lname[MAXLOCK], locker[MAXNAME + 1]; static char lname[MAXLOCK], locker[MAXNAME + 1];
@ -102,7 +102,7 @@ char *dolock(char *fname)
* *
*********************/ *********************/
char *undolock(char *fname) char *undolock( const char *fname)
{ {
static char lname[MAXLOCK]; static char lname[MAXLOCK];

15
pklock.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef _PKLOCK_H_
#define _PKLOCK_H_
#ifndef _ESTRUCT_H_
#error uEmacs compilation settings needs to be done!
#endif
#if (FILOCK && BSD) || SVR4
char *dolock( const char *fname) ;
char *undolock( const char *fname) ;
#endif
#endif

18
posix.c
View File

@ -1,3 +1,6 @@
/* posix.c -- implements termio.h */
#include "termio.h"
/* posix.c /* posix.c
* *
* The functions in this file negotiate with the operating system for * The functions in this file negotiate with the operating system for
@ -16,14 +19,18 @@
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h> #include <termios.h>
#include <unistd.h> #include <unistd.h>
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "retcode.h"
#include "efunc.h"
#include "utf8.h" #include "utf8.h"
int ttrow = HUGE ; /* Row location of HW cursor */
int ttcol = HUGE ; /* Column location of HW cursor */
/* Since Mac OS X's termios.h doesn't have the following 2 macros, define them. /* Since Mac OS X's termios.h doesn't have the following 2 macros, define them.
*/ */
#if defined(SYSV) && (defined(_DARWIN_C_SOURCE) || defined(_FREEBSD_C_SOURCE)) #if defined(SYSV) && (defined(_DARWIN_C_SOURCE) || defined(_FREEBSD_C_SOURCE))
@ -31,6 +38,12 @@
#define XCASE 0000004 #define XCASE 0000004
#endif #endif
#ifdef CYGWIN
#define XCASE 0
#define ECHOPRT 0
#define PENDIN 0
#endif
static int kbdflgs; /* saved keyboard fd flags */ static int kbdflgs; /* saved keyboard fd flags */
static int kbdpoll; /* in O_NDELAY mode */ static int kbdpoll; /* in O_NDELAY mode */
@ -58,6 +71,7 @@ void ttopen(void)
/* raw CR/NL etc input handling, but keep ISTRIP if we're on a 7-bit line */ /* raw CR/NL etc input handling, but keep ISTRIP if we're on a 7-bit line */
ntermios.c_iflag &= ~(IGNBRK | BRKINT | IGNPAR | PARMRK ntermios.c_iflag &= ~(IGNBRK | BRKINT | IGNPAR | PARMRK
| IXON | IXOFF | IXANY
| INPCK | INLCR | IGNCR | ICRNL); | INPCK | INLCR | IGNCR | ICRNL);
/* raw CR/NR etc output handling */ /* raw CR/NR etc output handling */

View File

@ -1,3 +1,8 @@
/* random.c -- implements random.h */
#include "random.h"
#define NBRACE 1 /* new style brace matching command */
/* random.c /* random.c
* *
* This file contains the command processing functions for a number of * This file contains the command processing functions for a number of
@ -7,13 +12,42 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include "basic.h"
#include "buffer.h"
#include "display.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "execute.h"
#include "efunc.h" #include "input.h"
#include "line.h" #include "line.h"
#include "log.h"
#include "search.h"
#include "terminal.h"
#include "window.h"
static const char *cname[] = { /* names of colors */
"BLACK", "RED", "GREEN", "YELLOW", "BLUE",
"MAGENTA", "CYAN", "WHITE"
#if PKCODE & IBMPC
, "HIGH"
#endif
} ;
#define NCOLORS (sizeof cname / sizeof( *cname)) /* # of supported 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) */
int fillcol = 72 ; /* Current fill column */
/* uninitialized global definitions */
int thisflag ; /* Flags, this command */
int lastflag ; /* Flags, last command */
int tabsize; /* Tab size (0: use real tabs) */
/* /*
* Set fill column to n. * Set fill column to n.
@ -311,6 +345,8 @@ int detab(int f, int n)
*/ */
int entab(int f, int n) int entab(int f, int n)
{ {
#define nextab(a) (a & ~tabmask) + (tabmask+1)
int inc; /* increment to next line [sgn(n)] */ int inc; /* increment to next line [sgn(n)] */
int fspace; /* pointer to first space if in a run */ int fspace; /* pointer to first space if in a run */
int ccol; /* current cursor column */ int ccol; /* current cursor column */
@ -898,14 +934,10 @@ int delgmode(int f, int n)
*/ */
int adjustmode(int kind, int global) int adjustmode(int kind, int global)
{ {
char *scan; /* scanning pointer to convert prompt */
int i; /* loop index */ int i; /* loop index */
int status; /* error return on input */ int status; /* error return on input */
#if COLOR
int uflag; /* was modename uppercase? */
#endif
char prompt[50]; /* string to prompt user with */ char prompt[50]; /* string to prompt user with */
char cbuf[NPAT]; /* buffer to recieve mode name into */ char cbuf[ NSTRING] ; /* buffer to recieve mode name into */
/* build the proper prompt string */ /* build the proper prompt string */
if (global) if (global)
@ -920,32 +952,16 @@ int adjustmode(int kind, int global)
/* prompt the user and get an answer */ /* prompt the user and get an answer */
status = mlreply(prompt, cbuf, NPAT - 1); status = mlreply( prompt, cbuf, sizeof cbuf - 1) ;
if (status != TRUE) if (status != TRUE)
return status; return status;
/* make it uppercase */
scan = cbuf;
#if COLOR
uflag = (*scan >= 'A' && *scan <= 'Z');
#endif
while (*scan != 0) {
if (*scan >= 'a' && *scan <= 'z')
*scan = *scan - 32;
scan++;
}
/* test it first against the colors we know */ /* test it first against the colors we know */
#if PKCODE & IBMPC
for (i = 0; i <= NCOLORS; i++) {
#else
for (i = 0; i < NCOLORS; i++) { for (i = 0; i < NCOLORS; i++) {
#endif if( strcasecmp( cbuf, cname[ i]) == 0) {
if (strcmp(cbuf, cname[i]) == 0) {
/* finding the match, we set the color */ /* finding the match, we set the color */
#if COLOR #if COLOR
if (uflag) { if( *cbuf >= 'A' && *cbuf <= 'Z') {
if (global) if (global)
gfcolor = i; gfcolor = i;
#if PKCODE == 0 #if PKCODE == 0
@ -971,7 +987,7 @@ int adjustmode(int kind, int global)
/* test it against the modes we know */ /* test it against the modes we know */
for (i = 0; i < NUMMODES; i++) { for (i = 0; i < NUMMODES; i++) {
if (strcmp(cbuf, modename[i]) == 0) { if( strcasecmp( cbuf, modename[ i]) == 0) {
/* finding a match, we process it */ /* finding a match, we process it */
if (kind == TRUE) if (kind == TRUE)
if (global) if (global)
@ -1017,11 +1033,11 @@ int writemsg(int f, int n)
char *sp; /* pointer into buf to expand %s */ char *sp; /* pointer into buf to expand %s */
char *np; /* ptr into nbuf */ char *np; /* ptr into nbuf */
int status; int status;
char buf[NPAT]; /* buffer to recieve message into */ char buf[ NSTRING] ; /* buffer to recieve message into */
char nbuf[NPAT * 2]; /* buffer to expand string into */ char nbuf[ NSTRING * 2] ; /* buffer to expand string into */
if ((status = if ((status =
mlreply("Message to write: ", buf, NPAT - 1)) != TRUE) mlreply("Message to write: ", buf, sizeof buf - 1)) != TRUE)
return status; return status;
/* expand all '%' to "%%" so mlwrite won't expect arguments */ /* expand all '%' to "%%" so mlwrite won't expect arguments */
@ -1215,11 +1231,11 @@ int fmatch(int ch)
int istring(int f, int n) int istring(int f, int n)
{ {
int status; /* status return code */ int status; /* status return code */
char tstring[NPAT + 1]; /* string to add */ char tstring[ 512] ; /* string to add */
/* ask for string to insert */ /* ask for string to insert */
status = status =
mlreplyt("String to insert<META>: ", tstring, NPAT, metac); mlreplyt("String to insert<META>: ", tstring, sizeof tstring - 1, metac) ;
if (status != TRUE) if (status != TRUE)
return status; return status;
@ -1243,11 +1259,11 @@ int istring(int f, int n)
int ovstring(int f, int n) int ovstring(int f, int n)
{ {
int status; /* status return code */ int status; /* status return code */
char tstring[NPAT + 1]; /* string to add */ char tstring[ NSTRING + 1] ; /* string to add */
/* ask for string to insert */ /* ask for string to insert */
status = status =
mlreplyt("String to overwrite<META>: ", tstring, NPAT, metac); mlreplyt( "String to overwrite<META>: ", tstring, NSTRING, metac) ;
if (status != TRUE) if (status != TRUE)
return status; return status;

52
random.h Normal file
View File

@ -0,0 +1,52 @@
#ifndef _RANDOM_H_
#define _RANDOM_H_
#define AEDIT 1
extern int fillcol ; /* Fill column */
/* Uninitialized global external declarations. */
#define CFCPCN 0x0001 /* Last command was C-P, C-N */
#define CFKILL 0x0002 /* Last command was a kill */
extern int thisflag ; /* Flags, this command */
extern int lastflag ; /* Flags, last command */
int setfillcol( int f, int n) ;
int showcpos( int f, int n) ;
int getcline( void) ;
int getccol( int bflg) ;
int setccol( int pos) ;
int twiddle( int f, int n) ;
int quote( int f, int n) ;
int insert_tab( int f, int n) ;
#if AEDIT
int detab( int f, int n) ;
int entab( int f, int n) ;
int trim( int f, int n) ;
#endif
int openline( int f, int n) ;
int insert_newline( int f, int n) ;
int cinsert( void) ;
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) ;
int backdel( int f, int n) ;
int killtext( int f, int n) ;
int setemode( int f, int n) ;
int delmode( int f, int n) ;
int setgmode( int f, int n) ;
int delgmode( int f, int n) ;
int adjustmode( int kind, int global) ;
int clrmes( int f, int n) ;
int writemsg( 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) ;
#endif

View File

@ -1,3 +1,6 @@
/* region.c -- implements region.h */
#include "region.h"
/* region.c /* region.c
* *
* The routines in this file deal with the region, that magic space * The routines in this file deal with the region, that magic space
@ -9,10 +12,12 @@
#include <stdio.h> #include <stdio.h>
#include "buffer.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h"
#include "efunc.h"
#include "line.h" #include "line.h"
#include "log.h"
#include "random.h"
#include "window.h"
/* /*
* Kill the region. Ask "getregion" * Kill the region. Ask "getregion"
@ -69,7 +74,7 @@ int copyregion(int f, int n)
++loffs; ++loffs;
} }
} }
mlwrite("(region copied)"); logwrite("(region copied)");
return TRUE; return TRUE;
} }
@ -166,7 +171,7 @@ int getregion(struct region *rp)
long bsize; long bsize;
if (curwp->w_markp == NULL) { if (curwp->w_markp == NULL) {
mlwrite("No mark set in this window"); logwrite("No mark set in this window");
return FALSE; return FALSE;
} }
if (curwp->w_dotp == curwp->w_markp) { if (curwp->w_dotp == curwp->w_markp) {
@ -208,6 +213,6 @@ int getregion(struct region *rp)
} }
} }
} }
mlwrite("Bug: lost mark"); logwrite("Bug: lost mark");
return FALSE; return FALSE;
} }

22
region.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef _REGION_H_
#define _REGION_H_
#include "line.h"
/*
* The starting position of a region, and the size of the region in
* characters, is kept in a region structure. Used by the region commands.
*/
struct region {
struct line *r_linep; /* Origin struct line address. */
int r_offset; /* Origin struct line offset. */
long r_size; /* Length in characters. */
};
int killregion( int f, int n) ;
int copyregion( int f, int n) ;
int lowerregion( int f, int n) ;
int upperregion( int f, int n) ;
int getregion( struct region *rp) ;
#endif

25
retcode.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef __RETCODE_H__
#define __RETCODE_H__
#ifdef FALSE
#undef FALSE
#endif
#ifdef TRUE
#undef TRUE
#endif
#if 0
#define FALSE 0 /* False, no, bad, etc. */
#define TRUE 1 /* True, yes, good, etc. */
#define ABORT 2 /* Death, ^G, abort, etc. */
#define FAILED 3 /* not-quite fatal false return */
#endif
typedef enum {
FALSE,
TRUE
} boolean ;
#define ABORT 2
#endif

View File

@ -1,3 +1,6 @@
/* search.c -- implements search.h */
#include "search.h"
/* search.c /* search.c
* *
* The functions in this file implement commands that search in the forward * The functions in this file implement commands that search in the forward
@ -58,13 +61,90 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "basic.h"
#include "buffer.h"
#include "display.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "input.h"
#include "efunc.h"
#include "line.h" #include "line.h"
#include "log.h"
#include "terminal.h"
#include "window.h"
/* The variable matchlen holds the length of the matched
* string - used by the replace functions.
* The variable patmatch holds the string that satisfies
* the search command.
* The variables matchline and matchoff hold the line and
* offset position of the *start* of match.
*/
unsigned int matchlen = 0 ;
static unsigned int mlenold = 0 ;
char *patmatch = NULL ;
static struct line *matchline = NULL;
static int matchoff = 0;
spat_t pat ; /* Search pattern */
spat_t tap ; /* Reversed pattern array. */
spat_t rpat ; /* replacement pattern */
#if defined(MAGIC) #if defined(MAGIC)
/*
* Defines for the metacharacters in the regular expression
* search routines.
*/
#define MCNIL 0 /* Like the '\0' for strings. */
#define LITCHAR 1 /* Literal character, or string. */
#define ANY 2
#define CCL 3
#define NCCL 4
#define BOL 5
#define EOL 6
#define DITTO 7
#define CLOSURE 256 /* An or-able value. */
#define MASKCL (CLOSURE - 1)
#define MC_ANY '.' /* 'Any' character (except newline). */
#define MC_CCL '[' /* Character class. */
#define MC_NCCL '^' /* Negate character class. */
#define MC_RCCL '-' /* Range in character class. */
#define MC_ECCL ']' /* End of character class. */
#define MC_BOL '^' /* Beginning of line. */
#define MC_EOL '$' /* End of line. */
#define MC_CLOSURE '*' /* Closure - does not extend past newline. */
#define MC_DITTO '&' /* Use matched string in replacement. */
#define MC_ESC '\\' /* Escape - suppress meta-meaning. */
#define BIT(n) (1 << (n)) /* An integer with one bit set. */
#define CHCASE(c) ((c) ^ DIFCASE) /* Toggle the case of a letter. */
/* HICHAR - 1 is the largest character we will deal with.
* HIBYTE represents the number of bytes in the bitmap.
*/
#define HICHAR 256
#define HIBYTE HICHAR >> 3
/* Typedefs that define the meta-character structure for MAGIC mode searching
* (struct magic), and the meta-character structure for MAGIC mode replacement
* (struct magic_replacement).
*/
struct magic {
short int mc_type;
union {
int lchar;
char *cclmap;
} u;
};
struct magic_replacement {
short int mc_type;
char *rstr;
};
/* /*
* The variables magical and rmagical determine if there * The variables magical and rmagical determine if there
* were actual metacharacters in the search and replace strings - * were actual metacharacters in the search and replace strings -
@ -76,6 +156,8 @@ static short int rmagical;
static struct magic mcpat[NPAT]; /* The magic pattern. */ static struct magic mcpat[NPAT]; /* The magic pattern. */
static struct magic tapcm[NPAT]; /* The reversed magic patterni. */ static struct magic tapcm[NPAT]; /* The reversed magic patterni. */
static struct magic_replacement rmcpat[NPAT]; /* The replacement magic array. */ static struct magic_replacement rmcpat[NPAT]; /* The replacement magic array. */
static int mcscanner( struct magic *mcpatrn, int direct, int beg_or_end) ;
#endif #endif
static int amatch(struct magic *mcptr, int direct, struct line **pcwline, int *pcwoff); static int amatch(struct magic *mcptr, int direct, struct line **pcwline, int *pcwoff);
@ -301,7 +383,7 @@ int backhunt(int f, int n)
* int direct; which way to go. * int direct; which way to go.
* int beg_or_end; put point at beginning or end of pattern. * int beg_or_end; put point at beginning or end of pattern.
*/ */
int mcscanner(struct magic *mcpatrn, int direct, int beg_or_end) static int mcscanner(struct magic *mcpatrn, int direct, int beg_or_end)
{ {
struct line *curline; /* current line during scan */ struct line *curline; /* current line during scan */
int curoff; /* position within current line */ int curoff; /* position within current line */
@ -733,12 +815,16 @@ static int replaces(int kind, int f, int n)
int nlflag; /* last char of search string a <NL>? */ int nlflag; /* last char of search string a <NL>? */
int nlrepl; /* was a replace done on the last line? */ int nlrepl; /* was a replace done on the last line? */
char c; /* input char for query */ char c; /* input char for query */
char tpat[NPAT]; /* temporary to hold search pattern */ spat_t tpat ; /* temporary to hold search pattern */
struct line *origline; /* original "." position */ struct line *origline; /* original "." position */
int origoff; /* and offset (for . query option) */ int origoff; /* and offset (for . query option) */
struct line *lastline; /* position of last replace and */ struct line *lastline; /* position of last replace and */
int lastoff; /* offset (for 'u' query option) */ int lastoff; /* offset (for 'u' query option) */
/* rfi */
lastline = NULL ;
lastoff = 0 ;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */ return rdonly(); /* we are in read only mode */
@ -1384,7 +1470,6 @@ static int mceq(int bc, struct magic *mt)
return result; return result;
} }
extern char *clearbits(void);
/* /*
* cclmake -- create the bitmap for the character class. * cclmake -- create the bitmap for the character class.

49
search.h Normal file
View File

@ -0,0 +1,49 @@
#ifndef _SEARCH_H_
#define _SEARCH_H_
#define MAGIC 1 /* include regular expression matching? */
#include "line.h"
#define BELL 0x07 /* a bell character */
typedef char spat_t[ 128] ; /* search pattern type */
#define NPAT sizeof( spat_t) /* # of bytes, pattern */
extern unsigned int matchlen ;
extern char *patmatch ;
extern spat_t pat ; /* Search pattern */
extern spat_t tap ; /* Reversed pattern array. */
extern spat_t rpat ; /* replacement pattern */
/*
* PTBEG, PTEND, FORWARD, and REVERSE are all toggle-able values for
* the scan routines.
*/
#define PTBEG 0 /* Leave the point at the beginning on search */
#define PTEND 1 /* Leave the point at the end on search */
#define FORWARD 0 /* forward direction */
#define REVERSE 1 /* backwards direction */
int scanner( const char *patrn, int direct, int beg_or_end) ;
int forwsearch( int f, int n) ;
int forwhunt( int f, int n) ;
int backsearch( int f, int n) ;
int backhunt( int f, int n) ;
int eq( unsigned char bc, unsigned char pc) ;
void savematch( void) ;
void rvstrcpy( char *rvstr, char *str) ;
int sreplace( int f, int n) ;
int qreplace( int f, int n) ;
int delins( int dlength, char *instr, int use_meta) ;
int expandp( char *srcstr, char *deststr, int maxlength) ;
int boundry( struct line *curline, int curoff, int dir) ;
#if MAGIC
void mcclear( void) ;
void rmcclear( void) ;
#endif
#endif

25
spawn.c
View File

@ -1,4 +1,7 @@
/* spaw.c /* spawn.c -- implements spawn.h */
#include "spawn.h"
/* spawn.c
* *
* Various operating system access commands. * Various operating system access commands.
* *
@ -6,11 +9,22 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "defines.h"
#include "buffer.h"
#include "display.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "exec.h"
#include "efunc.h" #include "file.h"
#include "flook.h"
#include "input.h"
#include "log.h"
#include "terminal.h"
#include "window.h"
#if VMS #if VMS
#define EFN 0 /* Event flag. */ #define EFN 0 /* Event flag. */
@ -88,7 +102,7 @@ int spawncli(int f, int n)
system("exec /bin/sh"); system("exec /bin/sh");
#endif #endif
sgarbf = TRUE; sgarbf = TRUE;
sleep(2); usleep( 2000000L) ;
TTopen(); TTopen();
TTkopen(); TTkopen();
#ifdef SIGWINCH #ifdef SIGWINCH
@ -387,7 +401,7 @@ int filter_buffer(int f, int n)
int s; /* return status from CLI */ int s; /* return status from CLI */
struct buffer *bp; /* pointer to buffer to zot */ struct buffer *bp; /* pointer to buffer to zot */
char line[NLINE]; /* command line send to shell */ char line[NLINE]; /* command line send to shell */
char tmpnam[NFILEN]; /* place to store real file name */ fname_t tmpnam ; /* place to store real file name */
static char bname1[] = "fltinp"; static char bname1[] = "fltinp";
static char filnam1[] = "fltinp"; static char filnam1[] = "fltinp";
@ -571,7 +585,6 @@ int execprog(char *cmd)
char *fcb1; /* 4 byte pointer to FCB at PSP+5Ch */ char *fcb1; /* 4 byte pointer to FCB at PSP+5Ch */
char *fcb2; /* 4 byte pointer to FCB at PSP+6Ch */ char *fcb2; /* 4 byte pointer to FCB at PSP+6Ch */
} pblock; } pblock;
char *flook();
/* parse the command name from the command line */ /* parse the command name from the command line */
sp = prog; sp = prog;

11
spawn.h Normal file
View File

@ -0,0 +1,11 @@
int spawncli( int f, int n) ;
int bktoshell( int f, int n) ;
void rtfrmshell( void) ;
int spawn( int f, int n) ;
int execprg( int f, int n) ;
int pipecmd( int f, int n) ;
int filter_buffer( int f, int n) ;
int sys( char *cmd) ;
int shellprog( char *cmd) ;
int execprog( char *cmd) ;

20
tcap.c
View File

@ -1,3 +1,6 @@
/* tcap.c -- implements terminal.h */
#include "terminal.h"
/* tcap.c /* tcap.c
* *
* Unix V7 SysV and BS4 Termcap video driver * Unix V7 SysV and BS4 Termcap video driver
@ -5,6 +8,9 @@
* modified by Petri Kutvonen * modified by Petri Kutvonen
*/ */
#include <stdlib.h>
#include <string.h>
/* /*
* Defining this to 1 breaks tcapopen() - it doesn't check if the * Defining this to 1 breaks tcapopen() - it doesn't check if the
* sceen size has changed. * sceen size has changed.
@ -13,16 +19,24 @@
#define USE_BROKEN_OPTIMIZATION 0 #define USE_BROKEN_OPTIMIZATION 0
#define termdef 1 /* Don't define "term" external. */ #define termdef 1 /* Don't define "term" external. */
#ifndef MINGW32
#include <curses.h> #include <curses.h>
#include <stdio.h>
#include <term.h> #include <term.h>
#endif
#include "display.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "termio.h"
#include "efunc.h"
#if TERMCAP #if TERMCAP
boolean eolexist = TRUE ; /* does clear to EOL exist */
boolean revexist = FALSE ; /* does reverse video exist? */
boolean sgarbf = TRUE ; /* TRUE if screen is garbage */
char sres[ 16] ; /* current screen resolution */
/* NORMAL, CGA, EGA, VGA */
#if UNIX #if UNIX
#include <signal.h> #include <signal.h>
#endif #endif

81
terminal.h Normal file
View File

@ -0,0 +1,81 @@
#ifndef __TERMINAL_H__
#define __TERMINAL_H__
#include "defines.h" /* COLOR, SCROLLCODE */
#include "retcode.h"
/*
* The editor communicates with the display using a high level interface. A
* "TERM" structure holds useful variables, and indirect pointers to routines
* that do useful operations. The low level get and put routines are here too.
* This lets a terminal, in addition to having non standard commands, have
* funny get and put character code too. The calls might get changed to
* "termp->t_field" style in the future, to make it possible to run more than
* one terminal type.
*/
struct terminal {
short t_mrow; /* max number of rows allowable */
short t_nrow; /* current number of rows used */
short t_mcol; /* max Number of columns. */
short t_ncol; /* current Number of columns. */
short t_margin; /* min margin for extended lines */
short t_scrsiz; /* size of scroll region " */
int t_pause; /* # times thru update to pause */
void (*t_open)(void); /* Open terminal at the start. */
void (*t_close)(void); /* Close terminal at end. */
void (*t_kopen)(void); /* Open keyboard */
void (*t_kclose)(void); /* close keyboard */
int (*t_getchar)(void); /* Get character from keyboard. */
int (*t_putchar)(int); /* Put character to display. */
void (*t_flush) (void); /* Flush output buffers. */
void (*t_move)(int, int);/* Move the cursor, origin 0. */
void (*t_eeol)(void); /* Erase to end of line. */
void (*t_eeop)(void); /* Erase to end of page. */
void (*t_beep)(void); /* Beep. */
void (*t_rev)(int); /* set reverse video state */
int (*t_rez)(char *); /* change screen resolution */
#if COLOR
int (*t_setfor) (); /* set forground color */
int (*t_setback) (); /* set background color */
#endif
#if SCROLLCODE
void (*t_scroll)(int, int,int); /* scroll a region of the screen */
#endif
};
/* TEMPORARY macros for terminal I/O (to be placed in a machine
dependant place later) */
#define TTopen (*term.t_open)
#define TTclose (*term.t_close)
#define TTkopen (*term.t_kopen)
#define TTkclose (*term.t_kclose)
#define TTgetc (*term.t_getchar)
#define TTputc (*term.t_putchar)
#define TTflush (*term.t_flush)
#define TTmove (*term.t_move)
#define TTeeol (*term.t_eeol)
#define TTeeop (*term.t_eeop)
#define TTbeep (*term.t_beep)
#define TTrev (*term.t_rev)
#define TTrez (*term.t_rez)
#if COLOR
#define TTforg (*term.t_setfor)
#define TTbacg (*term.t_setback)
#endif
/* Terminal table defined only in term.c */
extern struct terminal term ;
extern int ttrow ; /* Row location of HW cursor */
extern int ttcol ; /* Column location of HW cursor */
extern boolean eolexist ; /* does clear to EOL exist? */
extern boolean revexist ; /* does reverse video exist? */
extern boolean sgarbf ; /* State of screen unknown */
extern char sres[] ; /* Current screen resolution. */
/* NORMAL, CGA, EGA, VGA */
#endif

View File

@ -1,3 +1,4 @@
#include "termio.h"
/* TERMIO.C /* TERMIO.C
* *
@ -8,11 +9,22 @@
* modified by Petri Kutvonen * modified by Petri Kutvonen
*/ */
#ifndef POSIX #if !defined( POSIX) && !defined( MINGW32)
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "retcode.h"
#include "utf8.h"
/* rfi */
#include <unistd.h>
#include <sys/ioctl.h>
int ttrow = HUGE ; /* Row location of HW cursor */
int ttcol = HUGE ; /* Column location of HW cursor */
#if VMS #if VMS
#include <stsdef.h> #include <stsdef.h>
@ -269,8 +281,7 @@ void ttclose(void)
* On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on * On CPM terminal I/O unbuffered, so we just write the byte out. Ditto on
* MS-DOS (use the very very raw console output routine). * MS-DOS (use the very very raw console output routine).
*/ */
void ttputc(c) int ttputc( int c) {
{
#if VMS #if VMS
if (nobuf >= NOBUF) if (nobuf >= NOBUF)
ttflush(); ttflush();
@ -282,16 +293,20 @@ void ttputc(c)
#endif #endif
#if V7 | USG | BSD #if V7 | USG | BSD
fputc(c, stdout); char utf8[6];
int bytes;
bytes = unicode_to_utf8(c, utf8);
fwrite(utf8, 1, bytes, stdout);
#endif #endif
return 0 ;
} }
/* /*
* Flush terminal buffer. Does real work where the terminal output is buffered * Flush terminal buffer. Does real work where the terminal output is buffered
* up. A no-operation on systems where byte at a time terminal I/O is done. * up. A no-operation on systems where byte at a time terminal I/O is done.
*/ */
int ttflush(void) void ttflush( void) {
{
#if VMS #if VMS
int status; int status;
int iosb[2]; int iosb[2];
@ -339,8 +354,7 @@ int ttflush(void)
* at all. More complex in VMS that almost anyplace else, which figures. Very * at all. More complex in VMS that almost anyplace else, which figures. Very
* simple on CPM, because the system can do exactly what you want. * simple on CPM, because the system can do exactly what you want.
*/ */
ttgetc() int ttgetc( void) {
{
#if VMS #if VMS
int status; int status;
int iosb[2]; int iosb[2];
@ -412,7 +426,7 @@ ttgetc()
keyboard buffer keyboard buffer
*/ */
typahead() int typahead( void)
{ {
#if MSDOS & (MSC | TURBO) #if MSDOS & (MSC | TURBO)
if (kbhit() != 0) if (kbhit() != 0)

18
termio.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef _TERMIO_H_
#define _TERMIO_H_
#define TYPEAH 1 /* type ahead causes update to be skipped */
#define HUGE 1000 /* Huge number (for row/col) */
extern int ttrow ; /* Row location of HW cursor */
extern int ttcol ; /* Column location of HW cursor */
void ttopen( void) ;
void ttclose( void) ;
int ttputc( int c) ;
void ttflush( void) ;
int ttgetc( void) ;
int typahead( void) ;
#endif

69
tststr.cmd Normal file
View File

@ -0,0 +1,69 @@
; Insert long environment variables [will be truncated to NSTRING - 1 (127)]
insert-string &env PATH
newline
insert-string $PATH
newline
insert-string &cat $PATH $PATH
newline
set %mypath $PATH
insert-string %mypath
newline
insert-string &cat "Length of $PATH: " &len $PATH
newline
; Insert string with escaped characters
insert-string "hello, world~n"
newline
; Insert 512 long token [will be truncated to sizeof istring buffer - 2 (510)]
insert-string 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
newline
; Insert 512 long quoted string [will be truncated to sizeof istring buffer - 3 (509)]
insert-string "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
newline
; Insert long quoted string [will be truncated to NSTRING - 2 (126)]
insert-string "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
next-line
; Insert long tokens [will be truncated to NSTRING - 1 (127)]
insert-string 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
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)
set %nam 123
set %expect &len %nam
!while &equ &len %nam %expect
insert-string %nam
newline
set %nam &cat %nam %nam
set %expect &tim %expect 2
!endwhile
insert-string %nam
newline
insert-string &cat "Actual: " &len %nam
newline
insert-string &cat "Expected: " %expect
newline
; Use the variable as filename [will be truncated to NFILEN - 1 (79)]
write-file %nam
insert-string &cat "Filename: " $cfname
newline
insert-string "Filename length: "
insert-string &len $cfname
end-of-file
; Create a line longer than 1 kill block (250), 2 * 127 + 21 = 255
insert-string 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
insert-string 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
insert-string "#12345678901234567890"
; kill and yank
beginning-of-line
kill-to-end-of-line
kill-to-end-of-line
yank
yank
; insert kill variable (up to 127 characters), was 25 before fix
insert-string $kill
save-file
beginning-of-file
set-mark
end-of-file
copy-region
insert-string $kill

22
usage.c
View File

@ -1,22 +0,0 @@
#include "usage.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
static void report(const char* prefix, const char *err, va_list params)
{
char msg[4096];
vsnprintf(msg, sizeof(msg), err, params);
fprintf(stderr, "%s%s\n", prefix, msg);
}
void die(const char* err, ...)
{
va_list params;
va_start(params, err);
report("fatal: ", err, params);
va_end(params);
exit(128);
}

View File

@ -1,6 +0,0 @@
#ifndef USAGE_H_
#define USAGE_H_
extern void die(const char* err, ...);
#endif /* USAGE_H_ */

3
utf8.h
View File

@ -3,7 +3,8 @@
typedef unsigned int unicode_t; typedef unsigned int unicode_t;
unsigned utf8_to_unicode(char *line, unsigned index, unsigned len, unicode_t *res); unsigned utf8_to_unicode( char *line, unsigned index, unsigned len,
unicode_t *res) ;
unsigned unicode_to_utf8( unsigned int c, char *utf8) ; unsigned unicode_to_utf8( unsigned int c, char *utf8) ;
static inline int is_beginning_utf8( unsigned char c) static inline int is_beginning_utf8( unsigned char c)

6
util.h
View File

@ -1,6 +0,0 @@
#ifndef UTIL_H_
#define UTIL_H_
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#endif /* UTIL_H_ */

View File

@ -1,7 +0,0 @@
#include <stdio.h>
#include "version.h"
void version(void)
{
printf("%s version %s\n", PROGRAM_NAME_LONG, VERSION);
}

View File

@ -1,12 +1,16 @@
#ifndef VERSION_H_ #ifndef VERSION_H_
#define VERSION_H_ #define VERSION_H_
#ifdef PROGRAM
# define _QUOTE( s) #s
# define QUOTE( s) _QUOTE( s)
# define PROGRAM_NAME QUOTE(PROGRAM)
#else
# define PROGRAM_NAME "em" # define PROGRAM_NAME "em"
#define PROGRAM_NAME_LONG "uEmacs/Pk" #endif
#define VERSION "4.0.15" #define PROGRAM_NAME_LONG "uEMACS"
/* Print the version string. */ #define VERSION "4.1.1"
void version(void);
#endif /* VERSION_H_ */ #endif /* VERSION_H_ */

View File

@ -11,7 +11,6 @@
#include <stdio.h> /* Standard I/O package */ #include <stdio.h> /* Standard I/O package */
#include "estruct.h" /* Emacs' structures */ #include "estruct.h" /* Emacs' structures */
#include "edef.h" /* Emacs' definitions */
#if VMSVT #if VMSVT

1
vt52.c
View File

@ -15,7 +15,6 @@
#include <stdio.h> #include <stdio.h>
#include "estruct.h" #include "estruct.h"
#include "edef.h"
#if VT52 #if VT52

View File

@ -1,3 +1,7 @@
/* window.c -- inplements window.h */
#include "window.h"
/* window.c /* window.c
* *
* Window management. Some of the functions are internal, and some are * Window management. Some of the functions are internal, and some are
@ -7,12 +11,22 @@
#include <stdio.h> #include <stdio.h>
#include "basic.h"
#include "buffer.h"
#include "display.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h" #include "execute.h"
#include "efunc.h"
#include "line.h" #include "line.h"
#include "terminal.h"
#include "wrapper.h" #include "wrapper.h"
struct window *curwp ; /* Current window */
struct window *wheadp ; /* Head of list of windows */
static struct window *swindow = NULL ; /* saved window pointer */
/* /*
* Reposition dot in the current window to line "n". If the argument is * Reposition dot in the current window to line "n". If the argument is
* positive, it is that line. If it is negative it is that line from the * positive, it is that line. If it is negative it is that line from the

71
window.h Normal file
View File

@ -0,0 +1,71 @@
#ifndef _WINDOW_H_
#define _WINDOW_H_
#include "defines.h" /* COLOR, SCROLLCODE */
#include "buffer.h" /* buffer, line */
/*
* There is a window structure allocated for every active display window. The
* windows are kept in a big list, in top to bottom screen order, with the
* listhead at "wheadp". Each window contains its own values of dot and mark.
* The flag field contains some bits that are set by commands to guide
* redisplay. Although this is a bit of a compromise in terms of decoupling,
* the full blown redisplay is just too expensive to run for every input
* character.
*/
struct window {
struct window *w_wndp; /* Next window */
struct buffer *w_bufp; /* Buffer displayed in window */
struct line *w_linep; /* Top line in the window */
struct line *w_dotp; /* Line containing "." */
struct line *w_markp; /* Line containing "mark" */
int w_doto; /* Byte offset for "." */
int w_marko; /* Byte offset for "mark" */
char w_toprow; /* Origin 0 top row of window */
char w_ntrows; /* # of rows of text in window */
char w_force; /* If NZ, forcing row. */
char w_flag; /* Flags. */
#if COLOR
char w_fcolor; /* current forground color */
char w_bcolor; /* current background color */
#endif
};
extern struct window *curwp ; /* Current window */
extern struct window *wheadp ; /* Head of list of windows */
#define WFFORCE 0x01 /* Window needs forced reframe */
#define WFMOVE 0x02 /* Movement from line to line */
#define WFEDIT 0x04 /* Editing within a line */
#define WFHARD 0x08 /* Better to a full display */
#define WFMODE 0x10 /* Update mode line. */
#define WFCOLR 0x20 /* Needs a color change */
#if SCROLLCODE
#define WFKILLS 0x40 /* something was deleted */
#define WFINS 0x80 /* something was inserted */
#endif
int reposition( int f, int n);
int redraw( int f, int n) ;
int nextwind( int f, int n) ;
int prevwind( int f, int n) ;
int mvdnwind( int f, int n) ;
int mvupwind( int f, int n) ;
int onlywind( int f, int n) ;
int delwind( int f, int n) ;
int splitwind( int f, int n) ;
int enlargewind( int f, int n) ;
int shrinkwind( int f, int n) ;
int resize( int f, int n) ;
int scrnextup( int f, int n) ;
int scrnextdw( int f, int n) ;
int savewnd( int f, int n) ;
int restwnd( int f, int n) ;
int newsize( int f, int n) ;
int newwidth( int f, int n) ;
int getwpos( void) ;
void cknewwindow( void) ;
struct window *wpopup( void) ; /* Pop up window creation. */
#endif

129
word.c
View File

@ -1,3 +1,6 @@
/* word.c -- implements word.h */
#include "word.h"
/* word.c /* word.c
* *
* The routines in this file implement commands that work word or a * The routines in this file implement commands that work word or a
@ -9,10 +12,22 @@
#include <stdio.h> #include <stdio.h>
#include "basic.h"
#include "buffer.h"
#include "estruct.h" #include "estruct.h"
#include "edef.h"
#include "efunc.h"
#include "line.h" #include "line.h"
#include "log.h"
#include "random.h"
#include "region.h"
#include "window.h"
#define TAB 0x09 /* a tab character */
#if PKCODE
static int justflag = FALSE ; /* justify, don't fill */
#endif
static int inword( void) ;
/* Word wrap on n-spaces. Back-over whatever precedes the point on the current /* Word wrap on n-spaces. Back-over whatever precedes the point on the current
* line and stop on the first word-break or the beginning of the line. If we * line and stop on the first word-break or the beginning of the line. If we
@ -370,7 +385,7 @@ int delbword(int f, int n)
* Return TRUE if the character at dot is a character that is considered to be * Return TRUE if the character at dot is a character that is considered to be
* part of a word. The word character list is hard coded. Should be setable. * part of a word. The word character list is hard coded. Should be setable.
*/ */
int inword(void) static int inword(void)
{ {
int c; int c;
@ -413,7 +428,7 @@ int fillpara(int f, int n)
if (curbp->b_mode & MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */ return rdonly(); /* we are in read only mode */
if (fillcol == 0) { /* no fill column set */ if (fillcol == 0) { /* no fill column set */
mlwrite("No fill column set"); logwrite("No fill column set");
return FALSE; return FALSE;
} }
#if PKCODE #if PKCODE
@ -512,14 +527,14 @@ int justpara(int f, int n)
if (curbp->b_mode & MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */ return rdonly(); /* we are in read only mode */
if (fillcol == 0) { /* no fill column set */ if (fillcol == 0) { /* no fill column set */
mlwrite("No fill column set"); logwrite("No fill column set");
return FALSE; return FALSE;
} }
justflag = TRUE; justflag = TRUE;
leftmarg = curwp->w_doto; leftmarg = curwp->w_doto;
if (leftmarg + 10 > fillcol) { if (leftmarg + 10 > fillcol) {
leftmarg = 0; leftmarg = 0;
mlwrite("Column too narrow"); logwrite("Column too narrow");
return FALSE; return FALSE;
} }
@ -704,8 +719,108 @@ int wordcount(int f, int n)
else else
avgch = 0; avgch = 0;
mlwrite("Words %D Chars %D Lines %d Avg chars/word %f", logwrite("Words %D Chars %D Lines %d Avg chars/word %f",
nwords, nchars, nlines + 1, avgch); nwords, nchars, nlines + 1, avgch);
return TRUE; return TRUE;
} }
#endif #endif
#if WORDPRO
/*
* go back to the beginning of the current paragraph
* here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE>
* combination to delimit the beginning of a paragraph
*
* int f, n; default Flag & Numeric argument
*/
int gotobop(int f, int n)
{
int suc; /* success of last backchar */
if (n < 0) /* the other way... */
return gotoeop(f, -n);
while (n-- > 0) { /* for each one asked for */
/* first scan back until we are in a word */
suc = backchar(FALSE, 1);
while (!inword() && suc)
suc = backchar(FALSE, 1);
curwp->w_doto = 0; /* and go to the B-O-Line */
/* and scan back until we hit a <NL><NL> or <NL><TAB>
or a <NL><SPACE> */
while (lback(curwp->w_dotp) != curbp->b_linep)
if (llength(curwp->w_dotp) != 0 &&
#if PKCODE
((justflag == TRUE) ||
#endif
(lgetc(curwp->w_dotp, curwp->w_doto) != TAB &&
lgetc(curwp->w_dotp, curwp->w_doto) != ' '))
#if PKCODE
)
#endif
curwp->w_dotp = lback(curwp->w_dotp);
else
break;
/* and then forward until we are in a word */
suc = forwchar(FALSE, 1);
while (suc && !inword())
suc = forwchar(FALSE, 1);
}
curwp->w_flag |= WFMOVE; /* force screen update */
return TRUE;
}
/*
* Go forword to the end of the current paragraph
* here we look for a <NL><NL> or <NL><TAB> or <NL><SPACE>
* combination to delimit the beginning of a paragraph
*
* int f, n; default Flag & Numeric argument
*/
int gotoeop(int f, int n)
{
int suc; /* success of last backchar */
if (n < 0) /* the other way... */
return gotobop(f, -n);
while (n-- > 0) { /* for each one asked for */
/* first scan forward until we are in a word */
suc = forwchar(FALSE, 1);
while (!inword() && suc)
suc = forwchar(FALSE, 1);
curwp->w_doto = 0; /* and go to the B-O-Line */
if (suc) /* of next line if not at EOF */
curwp->w_dotp = lforw(curwp->w_dotp);
/* and scan forword until we hit a <NL><NL> or <NL><TAB>
or a <NL><SPACE> */
while (curwp->w_dotp != curbp->b_linep) {
if (llength(curwp->w_dotp) != 0 &&
#if PKCODE
((justflag == TRUE) ||
#endif
(lgetc(curwp->w_dotp, curwp->w_doto) != TAB &&
lgetc(curwp->w_dotp, curwp->w_doto) != ' '))
#if PKCODE
)
#endif
curwp->w_dotp = lforw(curwp->w_dotp);
else
break;
}
/* and then backward until we are in a word */
suc = backchar(FALSE, 1);
while (suc && !inword()) {
suc = backchar(FALSE, 1);
}
curwp->w_doto = llength(curwp->w_dotp); /* and to the EOL */
}
curwp->w_flag |= WFMOVE; /* force screen update */
return TRUE;
}
#endif

23
word.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef _WORD_H_
#define _WORD_H_
#define WORDPRO 1
int wrapword( int f, int n) ;
int backword( int f, int n) ;
int forwword( int f, int n) ;
int upperword( int f, int n) ;
int lowerword( int f, int n) ;
int capword( int f, int n) ;
int delfword( int f, int n) ;
int delbword( int f, int n) ;
#if WORDPRO
int gotobop( int f, int n) ;
int gotoeop( int f, int n) ;
int fillpara( int f, int n) ;
int justpara( int f, int n) ;
int killpara( int f, int n) ;
int wordcount( int f, int n) ;
#endif
#endif

View File

@ -1,22 +1,39 @@
#include "usage.h" /* wrapper.c -- implements wrapper.h */
#include "wrapper.h"
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#ifdef MINGW32
int mkstemp( char *template) {
return -1 ;
}
#endif
static void die( const char *err) {
fprintf( stderr, "fatal: %s\n", err) ;
exit( EXIT_FAILURE) ;
}
/* Function copyright: git */ /* Function copyright: git */
int xmkstemp(char *template) void xmkstemp( char *template) {
{
int fd ; int fd ;
fd = mkstemp( template) ; fd = mkstemp( template) ;
if( fd < 0) if( fd < 0)
die( "Unable to create temporary file") ; die( "Unable to create temporary file") ;
return fd;
close( fd) ;
} }
void *xmalloc(size_t size) void *xmalloc( size_t size) {
{
void *ret = malloc( size) ; void *ret = malloc( size) ;
if( !ret) if( !ret)
die( "Out of memory") ; die( "Out of memory") ;
return ret ; return ret ;
} }
/* end of wrapper.c */

6
wrapper.h Normal file → Executable file
View File

@ -1,8 +1,10 @@
#ifndef WRAPPER_H_ #ifndef WRAPPER_H_
#define WRAPPER_H_ #define WRAPPER_H_
extern int xmkstemp(char *template); #include <stdlib.h>
extern void *xmalloc(size_t size); void xmkstemp( char *template) ;
void *xmalloc( size_t size) ;
#endif /* WRAPPER_H_ */ #endif /* WRAPPER_H_ */

117
wscreen.c Normal file
View File

@ -0,0 +1,117 @@
/* wscreen.c -- windows screen console */
#include "wscreen.h"
#ifdef MINGW32
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
/* Standard error macro for reporting API errors */
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \
on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
static void cls( HANDLE hConsole )
{
COORD coordScreen = { 0, 0 }; /* here's where we'll home the
cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in
the current buffer */
/* get the number of character cells in the current buffer */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "GetConsoleScreenBufferInfo" );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
/* fill the entire screen with blanks */
bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ',
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputCharacter" );
/* get the current text attribute */
bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "ConsoleScreenBufferInfo" );
/* now set the buffer's attributes accordingly */
bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputAttribute" );
/* put the cursor at (0, 0) */
bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
PERR( bSuccess, "SetConsoleCursorPosition" );
return;
}
void wcls( void) {
cls( GetStdHandle( STD_OUTPUT_HANDLE)) ;
}
static struct {
int width ;
int height ;
int curTop, curBot, curRight, curLeft ;
} Screen ;
void winit( void) {
CONSOLE_SCREEN_BUFFER_INFO csbInfo ;
wcls() ;
if( GetConsoleScreenBufferInfo(
GetStdHandle( STD_OUTPUT_HANDLE), &csbInfo)) {
Screen.width = csbInfo.dwSize.X ;
Screen.height = csbInfo.dwSize.Y ;
Screen.curLeft = csbInfo.srWindow.Left ;
Screen.curTop = csbInfo.srWindow.Top ;
Screen.curRight = csbInfo.srWindow.Right ;
Screen.curBot = csbInfo.srWindow.Bottom ;
}
}
int wwidth( void) {
return Screen.width ;
}
int wheight( void) {
return Screen.height ;
}
int wleft( void) {
return Screen.curLeft ;
}
int wtop( void) {
return Screen.curTop ;
}
int wright( void) {
return Screen.curRight ;
}
int wbottom( void) {
return Screen.curBot ;
}
void wgoxy( int x, int y) {
COORD coord ;
coord.X = x ;
coord.Y = y ;
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE), coord );
}
void wtitle( const char *title) {
SetConsoleTitle( title) ;
}
#endif
/* end of wscreen.c */

14
wscreen.h Normal file
View File

@ -0,0 +1,14 @@
/* wscreen.h -- character screen drawing */
void winit( void) ;
void wcls( void) ;
void wgoxy( int x, int y) ;
void wtitle( const char *title) ;
int wwidth( void) ;
int wheight( void) ;
int wleft( void) ;
int wright( void) ;
int wtop( void) ;
int wbottom( void) ;
/* end of wscreen.h */