diff --git a/Makefile b/Makefile index 76a8122..e2a8caa 100644 --- a/Makefile +++ b/Makefile @@ -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 V = @@ -14,23 +20,7 @@ export E Q uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not') -PROGRAM=em - -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 +PROGRAM=ue CC=gcc WARNINGS=-Wall -Wstrict-prototypes @@ -48,9 +38,21 @@ endif ifeq ($(uname_S),Darwin) DEFINES=-DAUTOCONF -DPOSIX -DSYSV -D_DARWIN_C_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600 endif +ifeq ($(uname_S),CYGWIN_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 #LIBS=-ltermcap # BSD -LIBS=-lcurses # SYSV +#LIBS=-lcurses # SYSV #LIBS=-ltermlib #LIBS=-L/usr/lib/termcap -ltermcap LFLAGS=-hbx @@ -69,14 +71,14 @@ sparse: 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) strip $(PROGRAM) - cp em ${BINDIR} + cp $(PROGRAM) ${BINDIR} cp emacs.hlp ${LIBDIR} cp emacs.rc ${LIBDIR}/.emacsrc - chmod 755 ${BINDIR}/em + chmod 755 ${BINDIR}/$(PROGRAM) chmod 644 ${LIBDIR}/emacs.hlp ${LIBDIR}/.emacsrc lint: ${SRC} @@ -86,40 +88,43 @@ lint: ${SRC} errs: @rm -f makeout - make em >makeout + make $(PROGRAM) >makeout tags: ${SRC} @rm -f tags ctags ${SRC} source: - @mv makefile makefile.bak - @echo "# makefile for emacs, updated `date`" >makefile - @echo '' >>makefile - @echo SRC=`ls *.c` >>makefile - @echo OBJ=`ls *.c | sed s/c$$/o/` >>makefile - @echo HDR=`ls *.h` >>makefile - @echo '' >>makefile - @sed -n -e '/^# DO NOT ADD OR MODIFY/,$$p' >makefile + @mv Makefile Makefile.bak + @echo "# Makefile for emacs, updated `date`" >Makefile + @echo '' >>Makefile + @echo SRC=`ls *.c` >>Makefile + @echo OBJ=`ls *.c | sed s/c$$/o/` >>Makefile + @echo HDR=`ls *.h` >>Makefile + @echo '' >>Makefile + @sed -n -e '/^# DO NOT ADD OR MODIFY/,$$p' >Makefile depend: ${SRC} @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 + cc ${DEFINES} -MM $$i ; done >makedep @echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep @echo '$$r ./makedep' >>eddep @echo 'w' >>eddep - @cp makefile makefile.bak - @ed - makefile >makefile - @echo '# DEPENDENCIES MUST END AT END OF FILE' >>makefile - @echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >>makefile - @echo '# see make depend above' >>makefile + @echo '' >>Makefile + @echo '# DEPENDENCIES MUST END AT END OF FILE' >>Makefile + @echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >>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: $(E) " CC " $@ @@ -127,35 +132,79 @@ depend: ${SRC} # DO NOT DELETE THIS LINE -- make depend uses it -ansi.o: ansi.c estruct.h edef.h -basic.o: basic.c estruct.h edef.h -bind.o: bind.c estruct.h edef.h epath.h -buffer.o: buffer.c estruct.h edef.h -crypt.o: crypt.c estruct.h edef.h -display.o: display.c estruct.h edef.h utf8.h -eval.o: eval.c estruct.h edef.h evar.h -exec.o: exec.c estruct.h edef.h -file.o: file.c estruct.h edef.h -fileio.o: fileio.c estruct.h edef.h -ibmpc.o: ibmpc.c estruct.h edef.h -input.o: input.c estruct.h edef.h -isearch.o: isearch.c estruct.h edef.h -line.o: line.c estruct.h edef.h -lock.o: lock.c estruct.h edef.h -main.o: main.c estruct.h efunc.h edef.h ebind.h -pklock.o: pklock.c estruct.h -posix.o: posix.c estruct.h utf8.h -random.o: random.c estruct.h edef.h -region.o: region.c estruct.h edef.h -search.o: search.c estruct.h edef.h -spawn.o: spawn.c estruct.h edef.h -tcap.o: tcap.c estruct.h edef.h -termio.o: termio.c estruct.h edef.h +ansi.o: ansi.c estruct.h +basic.o: basic.c basic.h buffer.h crypt.h line.h utf8.h display.h \ + estruct.h input.h bind.h random.h terminal.h defines.h retcode.h \ + window.h +bind.o: bind.c bind.h estruct.h bindable.h buffer.h crypt.h line.h utf8.h \ + display.h ebind.h exec.h retcode.h file.h flook.h input.h names.h \ + window.h defines.h +bindable.o: bindable.c bindable.h defines.h buffer.h crypt.h line.h \ + utf8.h display.h estruct.h file.h retcode.h input.h bind.h lock.h \ + terminal.h +buffer.o: buffer.c buffer.h crypt.h line.h utf8.h defines.h display.h \ + estruct.h file.h retcode.h input.h bind.h window.h +crypt.o: crypt.c crypt.h +display.o: display.c display.h buffer.h crypt.h line.h utf8.h estruct.h \ + input.h bind.h termio.h terminal.h defines.h retcode.h version.h \ + wrapper.h window.h +ebind.o: ebind.c ebind.h basic.h bind.h estruct.h bindable.h buffer.h \ + crypt.h line.h utf8.h eval.h exec.h retcode.h file.h isearch.h random.h \ + region.h search.h spawn.h window.h defines.h word.h +eval.o: eval.c eval.h basic.h bind.h buffer.h crypt.h line.h utf8.h \ + display.h estruct.h exec.h retcode.h execute.h flook.h input.h random.h \ + search.h terminal.h defines.h termio.h version.h window.h +exec.o: exec.c exec.h retcode.h buffer.h crypt.h line.h utf8.h bind.h \ + display.h estruct.h eval.h file.h flook.h input.h random.h window.h \ + 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 -vmsvt.o: vmsvt.c estruct.h edef.h -vt52.o: vt52.c estruct.h edef.h -window.o: window.c estruct.h edef.h -word.o: word.c estruct.h edef.h +vmsvt.o: vmsvt.c estruct.h +vt52.o: vt52.c estruct.h +window.o: window.c window.h defines.h buffer.h crypt.h line.h utf8.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 # IF YOU PUT STUFF HERE IT WILL GO AWAY diff --git a/README.md b/README.md new file mode 100644 index 0000000..a923e7f --- /dev/null +++ b/README.md @@ -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 \ No newline at end of file diff --git a/ansi.c b/ansi.c index a60eb64..425d96c 100644 --- a/ansi.c +++ b/ansi.c @@ -11,7 +11,7 @@ #include #include "estruct.h" -#include "edef.h" + #if ANSI diff --git a/basic.c b/basic.c index 5071047..90f492b 100644 --- a/basic.c +++ b/basic.c @@ -1,3 +1,9 @@ +/* basic.c -- implements basic.h */ + +#include "basic.h" + +#define CVMVAS 1 /* arguments to page forward/back in pages */ + /* basic.c * * The routines in this file move the cursor around on the screen. They @@ -10,12 +16,22 @@ */ #include +#include +#include "buffer.h" +#include "display.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include "input.h" #include "line.h" +#include "random.h" +#include "terminal.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 @@ -62,38 +78,6 @@ int gotobol(int f, int n) 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. */ @@ -103,37 +87,6 @@ int gotoeol(int f, int n) 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. * @@ -269,106 +222,6 @@ int backline(int f, int n) return TRUE; } -#if WORDPRO -/* - * go back to the beginning of the current paragraph - * here we look for a or or - * 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 or - or a */ - 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 or or - * 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 or - or a */ - 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 * argument. Bound to "C-V". The "2" in the arithmetic on the window size is diff --git a/basic.h b/basic.h new file mode 100644 index 0000000..20631db --- /dev/null +++ b/basic.h @@ -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 diff --git a/bind.c b/bind.c index eb28c1f..53747b0 100644 --- a/bind.c +++ b/bind.c @@ -1,248 +1,261 @@ -/* bind.c +/* bind.c -- implements bind.h */ +#include "bind.h" + +/* bind.c * - * This file is for functions having to do with key bindings, - * descriptions, help commands and startup file. + * This file is for functions having to do with key bindings, + * descriptions, help commands and startup file. * - * Written 11-feb-86 by Daniel Lawrence - * Modified by Petri Kutvonen + * Written 11-feb-86 by Daniel Lawrence + * Modified by Petri Kutvonen */ #include +#include #include "estruct.h" -#include "edef.h" -#include "efunc.h" -#include "epath.h" +#include "bindable.h" +#include "buffer.h" +#include "display.h" +#include "ebind.h" +#include "exec.h" +#include "file.h" +#include "flook.h" +#include "input.h" #include "line.h" -#include "util.h" +#include "names.h" +#include "window.h" + + +static char *getfname( fn_t) ; int help(int f, int n) -{ /* give me some help!!!! - bring up a fake buffer and read the help file - into it with view mode */ - struct window *wp; /* scaning pointer to windows */ - struct buffer *bp; /* buffer pointer to help */ - char *fname = NULL; /* ptr to file returned by flook() */ +{ /* give me some help!!!! + bring up a fake buffer and read the help file + into it with view mode */ + struct window *wp; /* scaning pointer to windows */ + struct buffer *bp; /* buffer pointer to help */ + char *fname = NULL; /* ptr to file returned by flook() */ - /* first check if we are already here */ - bp = bfind("emacs.hlp", FALSE, BFINVS); + /* first check if we are already here */ + bp = bfind( hlpfname, FALSE, BFINVS); - if (bp == NULL) { - fname = flook(pathname[1], FALSE); - if (fname == NULL) { - mlwrite("(Help file is not online)"); - return FALSE; - } - } + if (bp == NULL) { + fname = flook( hlpfname, FALSE); + if (fname == NULL) { + mlwrite("(Help file is not online)"); + return FALSE; + } + } - /* split the current window to make room for the help stuff */ - if (splitwind(FALSE, 1) == FALSE) - return FALSE; + /* split the current window to make room for the help stuff */ + if (splitwind(FALSE, 1) == FALSE) + return FALSE; - if (bp == NULL) { - /* and read the stuff in */ - if (getfile(fname, FALSE) == FALSE) - return FALSE; - } else - swbuffer(bp); + if (bp == NULL) { + /* and read the stuff in */ + if (getfile(fname, FALSE) == FALSE) + return FALSE; + } else + swbuffer(bp); - /* make this window in VIEW mode, update all mode lines */ - curwp->w_bufp->b_mode |= MDVIEW; - curwp->w_bufp->b_flag |= BFINVS; - wp = wheadp; - while (wp != NULL) { - wp->w_flag |= WFMODE; - wp = wp->w_wndp; - } - return TRUE; + /* make this window in VIEW mode, update all mode lines */ + curwp->w_bufp->b_mode |= MDVIEW; + curwp->w_bufp->b_flag |= BFINVS; + wp = wheadp; + while (wp != NULL) { + wp->w_flag |= WFMODE; + wp = wp->w_wndp; + } + return TRUE; } int deskey(int f, int n) -{ /* describe the command for a certain key */ - int c; /* key to describe */ - char *ptr; /* string pointer to scan output strings */ - char outseq[NSTRING]; /* output buffer for command sequence */ +{ /* describe the command for a certain key */ + int c; /* key to describe */ + char *ptr; /* string pointer to scan output strings */ + char outseq[NSTRING]; /* output buffer for command sequence */ - /* prompt the user to type us a key to describe */ - mlwrite(": describe-key "); + /* prompt the user to type us a key to describe */ + mlwrite(": describe-key "); - /* get the command sequence to describe - change it to something we can print as well */ - cmdstr(c = getckey(FALSE), &outseq[0]); + /* get the command sequence to describe + change it to something we can print as well */ + cmdstr(c = getckey(FALSE), &outseq[0]); - /* and dump it out */ - ostring(outseq); - ostring(" "); + /* and dump it out */ + ostring(outseq); + ostring(" "); - /* find the right ->function */ - if ((ptr = getfname(getbind(c))) == NULL) - ptr = "Not Bound"; + /* find the right ->function */ + if ((ptr = getfname(getbind(c))) == NULL) + ptr = "Not Bound"; - /* output the command sequence */ - ostring(ptr); - return TRUE; + /* output the command sequence */ + ostring(ptr); + return TRUE; } /* * bindtokey: - * add a new key to the key binding table + * add a new key to the key binding table * - * int f, n; command arguments [IGNORED] + * int f, n; command arguments [IGNORED] */ int bindtokey(int f, int n) { - unsigned int c; /* command key to bind */ - fn_t kfunc; /* ptr to the requested function to bind to */ - struct key_tab *ktp; /* pointer into the command table */ - int found; /* matched command flag */ - char outseq[80]; /* output buffer for keystroke sequence */ + unsigned int c; /* command key to bind */ + fn_t kfunc; /* ptr to the requested function to bind to */ + struct key_tab *ktp; /* pointer into the command table */ + int found; /* matched command flag */ + char outseq[80]; /* output buffer for keystroke sequence */ - /* prompt the user to type in a key to bind */ - mlwrite(": bind-to-key "); + /* prompt the user to type in a key to bind */ + mlwrite(": bind-to-key "); - /* get the function name to bind it to */ - kfunc = getname(); - if (kfunc == NULL) { - mlwrite("(No such function)"); - return FALSE; - } - ostring(" "); + /* get the function name to bind it to */ + kfunc = getname(); + if (kfunc == NULL) { + mlwrite("(No such function)"); + return FALSE; + } + ostring(" "); - /* get the command sequence to bind */ - c = getckey((kfunc == metafn) || (kfunc == cex) || - (kfunc == unarg) || (kfunc == ctrlg)); + /* get the command sequence to bind */ + c = getckey((kfunc == metafn) || (kfunc == cex) || + (kfunc == unarg) || (kfunc == ctrlg)); - /* change it to something we can print as well */ - cmdstr(c, &outseq[0]); + /* change it to something we can print as well */ + cmdstr(c, &outseq[0]); - /* and dump it out */ - ostring(outseq); + /* and dump it out */ + ostring(outseq); - /* if the function is a prefix key */ - if (kfunc == metafn || kfunc == cex || - kfunc == unarg || kfunc == ctrlg) { + /* if the function is a prefix key */ + if (kfunc == metafn || kfunc == cex || + kfunc == unarg || kfunc == ctrlg) { - /* search for an existing binding for the prefix key */ - ktp = &keytab[0]; - found = FALSE; - while (ktp->k_fp != NULL) { - if (ktp->k_fp == kfunc) - unbindchar(ktp->k_code); - ++ktp; - } + /* search for an existing binding for the prefix key */ + ktp = &keytab[0]; + found = FALSE; + while (ktp->k_fp != NULL) { + if (ktp->k_fp == kfunc) + unbindchar(ktp->k_code); + ++ktp; + } - /* reset the appropriate global prefix variable */ - if (kfunc == metafn) - metac = c; - if (kfunc == cex) - ctlxc = c; - if (kfunc == unarg) - reptc = c; - if (kfunc == ctrlg) - abortc = c; - } + /* reset the appropriate global prefix variable */ + if (kfunc == metafn) + metac = c; + if (kfunc == cex) + ctlxc = c; + if (kfunc == unarg) + reptc = c; + if (kfunc == ctrlg) + abortc = c; + } - /* search the table to see if it exists */ - ktp = &keytab[0]; - found = FALSE; - while (ktp->k_fp != NULL) { - if (ktp->k_code == c) { - found = TRUE; - break; - } - ++ktp; - } + /* search the table to see if it exists */ + ktp = &keytab[0]; + found = FALSE; + while (ktp->k_fp != NULL) { + if (ktp->k_code == c) { + found = TRUE; + break; + } + ++ktp; + } - if (found) { /* it exists, just change it then */ - ktp->k_fp = kfunc; - } else { /* otherwise we need to add it to the end */ - /* if we run out of binding room, bitch */ - if (ktp >= &keytab[NBINDS]) { - mlwrite("Binding table FULL!"); - return FALSE; - } + if (found) { /* it exists, just change it then */ + ktp->k_fp = kfunc; + } else { /* otherwise we need to add it to the end */ + /* if we run out of binding room, bitch */ + if (ktp >= &keytab[NBINDS]) { + mlwrite("Binding table FULL!"); + return FALSE; + } - ktp->k_code = c; /* add keycode */ - ktp->k_fp = kfunc; /* and the function pointer */ - ++ktp; /* and make sure the next is null */ - ktp->k_code = 0; - ktp->k_fp = NULL; - } - return TRUE; + ktp->k_code = c; /* add keycode */ + ktp->k_fp = kfunc; /* and the function pointer */ + ++ktp; /* and make sure the next is null */ + ktp->k_code = 0; + ktp->k_fp = NULL; + } + return TRUE; } /* * unbindkey: - * delete a key from the key binding table + * delete a key from the key binding table * - * int f, n; command arguments [IGNORED] + * int f, n; command arguments [IGNORED] */ int unbindkey(int f, int n) { - int c; /* command key to unbind */ - char outseq[80]; /* output buffer for keystroke sequence */ + int c; /* command key to unbind */ + char outseq[80]; /* output buffer for keystroke sequence */ - /* prompt the user to type in a key to unbind */ - mlwrite(": unbind-key "); + /* prompt the user to type in a key to unbind */ + mlwrite(": unbind-key "); - /* get the command sequence to unbind */ - c = getckey(FALSE); /* get a command sequence */ + /* get the command sequence to unbind */ + c = getckey(FALSE); /* get a command sequence */ - /* change it to something we can print as well */ - cmdstr(c, &outseq[0]); + /* change it to something we can print as well */ + cmdstr(c, &outseq[0]); - /* and dump it out */ - ostring(outseq); + /* and dump it out */ + ostring(outseq); - /* if it isn't bound, bitch */ - if (unbindchar(c) == FALSE) { - mlwrite("(Key not bound)"); - return FALSE; - } - return TRUE; + /* if it isn't bound, bitch */ + if (unbindchar(c) == FALSE) { + mlwrite("(Key not bound)"); + return FALSE; + } + return TRUE; } /* * unbindchar() * - * int c; command key to unbind + * int c; command key to unbind */ int unbindchar(int c) { - struct key_tab *ktp; /* pointer into the command table */ - struct key_tab *sktp; /* saved pointer into the command table */ - int found; /* matched command flag */ + struct key_tab *ktp; /* pointer into the command table */ + struct key_tab *sktp; /* saved pointer into the command table */ + int found; /* matched command flag */ - /* search the table to see if the key exists */ - ktp = &keytab[0]; - found = FALSE; - while (ktp->k_fp != NULL) { - if (ktp->k_code == c) { - found = TRUE; - break; - } - ++ktp; - } + /* search the table to see if the key exists */ + ktp = &keytab[0]; + found = FALSE; + while (ktp->k_fp != NULL) { + if (ktp->k_code == c) { + found = TRUE; + break; + } + ++ktp; + } - /* if it isn't bound, bitch */ - if (!found) - return FALSE; + /* if it isn't bound, bitch */ + if (!found) + return FALSE; - /* save the pointer and scan to the end of the table */ - sktp = ktp; - while (ktp->k_fp != NULL) - ++ktp; - --ktp; /* backup to the last legit entry */ + /* save the pointer and scan to the end of the table */ + sktp = ktp; + while (ktp->k_fp != NULL) + ++ktp; + --ktp; /* backup to the last legit entry */ - /* copy the last entry to the current one */ - sktp->k_code = ktp->k_code; - sktp->k_fp = ktp->k_fp; + /* copy the last entry to the current one */ + sktp->k_code = ktp->k_code; + sktp->k_fp = ktp->k_fp; - /* null out the last one */ - ktp->k_code = 0; - ktp->k_fp = NULL; - return TRUE; + /* null out the last one */ + ktp->k_code = 0; + ktp->k_fp = NULL; + return TRUE; } /* describe bindings @@ -250,469 +263,386 @@ int unbindchar(int c) * into it with view mode */ int desbind(int f, int n) -#if APROP +#if APROP { - buildlist(TRUE, ""); - return TRUE; + buildlist(TRUE, ""); + return TRUE; } int apro(int f, int n) -{ /* Apropos (List functions that match a substring) */ - char mstring[NSTRING]; /* string to match cmd names to */ - int status; /* status return */ +{ /* Apropos (List functions that match a substring) */ + char mstring[NSTRING]; /* string to match cmd names to */ + int status; /* status return */ - status = mlreply("Apropos string: ", mstring, NSTRING - 1); - if (status != TRUE) - return status; + status = mlreply("Apropos string: ", mstring, NSTRING - 1); + if (status != TRUE) + return status; - return buildlist(FALSE, mstring); + return buildlist(FALSE, mstring); } /* * build a binding list (limited or full) * - * int type; true = full list, false = partial list - * char *mstring; match string if a partial list + * int type; true = full list, false = partial list + * char *mstring; match string if a partial list */ int buildlist(int type, char *mstring) #endif { - struct window *wp; /* scanning pointer to windows */ - struct key_tab *ktp; /* pointer into the command table */ - struct name_bind *nptr; /* pointer into the name binding table */ - struct buffer *bp; /* buffer to put binding list into */ - int cpos; /* current position to use in outseq */ - char outseq[80]; /* output buffer for keystroke sequence */ + struct window *wp; /* scanning pointer to windows */ + struct key_tab *ktp; /* pointer into the command table */ + struct name_bind *nptr; /* pointer into the name binding table */ + struct buffer *bp; /* buffer to put binding list into */ + int cpos; /* current position to use in outseq */ + char outseq[80]; /* output buffer for keystroke sequence */ - /* split the current window to make room for the binding list */ - if (splitwind(FALSE, 1) == FALSE) - return FALSE; + /* split the current window to make room for the binding list */ + if (splitwind(FALSE, 1) == FALSE) + return FALSE; - /* and get a buffer for it */ - bp = bfind("*Binding list*", TRUE, 0); - if (bp == NULL || bclear(bp) == FALSE) { - mlwrite("Can not display binding list"); - return FALSE; - } + /* and get a buffer for it */ + bp = bfind("*Binding list*", TRUE, 0); + if (bp == NULL || bclear(bp) == FALSE) { + mlwrite("Can not display binding list"); + return FALSE; + } - /* let us know this is in progress */ - mlwrite("(Building binding list)"); + /* let us know this is in progress */ + mlwrite("(Building binding list)"); - /* disconect the current buffer */ - if (--curbp->b_nwnd == 0) { /* Last use. */ - curbp->b_dotp = curwp->w_dotp; - curbp->b_doto = curwp->w_doto; - curbp->b_markp = curwp->w_markp; - curbp->b_marko = curwp->w_marko; - } + /* disconect the current buffer */ + if (--curbp->b_nwnd == 0) { /* Last use. */ + curbp->b_dotp = curwp->w_dotp; + curbp->b_doto = curwp->w_doto; + curbp->b_markp = curwp->w_markp; + curbp->b_marko = curwp->w_marko; + } - /* connect the current window to this buffer */ - curbp = bp; /* make this buffer current in current window */ - bp->b_mode = 0; /* no modes active in binding list */ - bp->b_nwnd++; /* mark us as more in use */ - wp = curwp; - wp->w_bufp = bp; - wp->w_linep = bp->b_linep; - wp->w_flag = WFHARD | WFFORCE; - wp->w_dotp = bp->b_dotp; - wp->w_doto = bp->b_doto; - wp->w_markp = NULL; - wp->w_marko = 0; + /* connect the current window to this buffer */ + curbp = bp; /* make this buffer current in current window */ + bp->b_mode = 0; /* no modes active in binding list */ + bp->b_nwnd++; /* mark us as more in use */ + wp = curwp; + wp->w_bufp = bp; + wp->w_linep = bp->b_linep; + wp->w_flag = WFHARD | WFFORCE; + wp->w_dotp = bp->b_dotp; + wp->w_doto = bp->b_doto; + wp->w_markp = NULL; + wp->w_marko = 0; - /* build the contents of this window, inserting it line by line */ - nptr = &names[0]; - while (nptr->n_func != NULL) { + /* build the contents of this window, inserting it line by line */ + nptr = &names[0]; + while (nptr->n_func != NULL) { - /* add in the command name */ - strcpy(outseq, nptr->n_name); - cpos = strlen(outseq); + /* add in the command name */ + strcpy(outseq, nptr->n_name); + cpos = strlen(outseq); -#if APROP - /* if we are executing an apropos command..... */ - if (type == FALSE && - /* and current string doesn't include the search string */ - strinc(outseq, mstring) == FALSE) - goto fail; +#if APROP + /* if we are executing an apropos command..... */ + if (type == FALSE && + /* and current string doesn't include the search string */ + strinc(outseq, mstring) == FALSE) + goto fail; #endif - /* search down any keys bound to this */ - ktp = &keytab[0]; - while (ktp->k_fp != NULL) { - if (ktp->k_fp == nptr->n_func) { - /* padd out some spaces */ - while (cpos < 28) - outseq[cpos++] = ' '; + /* search down any keys bound to this */ + ktp = &keytab[0]; + while (ktp->k_fp != NULL) { + if (ktp->k_fp == nptr->n_func) { + /* padd out some spaces */ + while (cpos < 28) + outseq[cpos++] = ' '; - /* add in the command sequence */ - cmdstr(ktp->k_code, &outseq[cpos]); - strcat(outseq, "\n"); + /* add in the command sequence */ + cmdstr(ktp->k_code, &outseq[cpos]); + strcat(outseq, "\n"); - /* and add it as a line into the buffer */ - if (linstr(outseq) != TRUE) - return FALSE; + /* and add it as a line into the buffer */ + if (linstr(outseq) != TRUE) + return FALSE; - cpos = 0; /* and clear the line */ - } - ++ktp; - } + cpos = 0; /* and clear the line */ + } + ++ktp; + } - /* if no key was bound, we need to dump it anyway */ - if (cpos > 0) { - outseq[cpos++] = '\n'; - outseq[cpos] = 0; - if (linstr(outseq) != TRUE) - return FALSE; - } + /* if no key was bound, we need to dump it anyway */ + if (cpos > 0) { + outseq[cpos++] = '\n'; + outseq[cpos] = 0; + if (linstr(outseq) != TRUE) + return FALSE; + } - fail: /* and on to the next name */ - ++nptr; - } + fail: /* and on to the next name */ + ++nptr; + } - curwp->w_bufp->b_mode |= MDVIEW; /* put this buffer view mode */ - curbp->b_flag &= ~BFCHG; /* don't flag this as a change */ - wp->w_dotp = lforw(bp->b_linep); /* back to the beginning */ - wp->w_doto = 0; - wp = wheadp; /* and update ALL mode lines */ - while (wp != NULL) { - wp->w_flag |= WFMODE; - wp = wp->w_wndp; - } - mlwrite(""); /* clear the mode line */ - return TRUE; + curwp->w_bufp->b_mode |= MDVIEW; /* put this buffer view mode */ + curbp->b_flag &= ~BFCHG; /* don't flag this as a change */ + wp->w_dotp = lforw(bp->b_linep); /* back to the beginning */ + wp->w_doto = 0; + wp = wheadp; /* and update ALL mode lines */ + while (wp != NULL) { + wp->w_flag |= WFMODE; + wp = wp->w_wndp; + } + mlwrite(""); /* clear the mode line */ + return TRUE; } -#if APROP +#if APROP /* * does source include sub? * - * char *source; string to search in - * char *sub; substring to look for + * char *source; string to search in + * char *sub; substring to look for */ int strinc(char *source, char *sub) { - char *sp; /* ptr into source */ - char *nxtsp; /* next ptr into source */ - char *tp; /* ptr into substring */ + char *sp; /* ptr into source */ + char *nxtsp; /* next ptr into source */ + char *tp; /* ptr into substring */ - /* for each character in the source string */ - sp = source; - while (*sp) { - tp = sub; - nxtsp = sp; + /* for each character in the source string */ + sp = source; + while (*sp) { + tp = sub; + nxtsp = sp; - /* is the substring here? */ - while (*tp) { - if (*nxtsp++ != *tp) - break; - else - tp++; - } + /* is the substring here? */ + while (*tp) { + if (*nxtsp++ != *tp) + break; + else + tp++; + } - /* yes, return a success */ - if (*tp == 0) - return TRUE; + /* yes, return a success */ + if (*tp == 0) + return TRUE; - /* no, onward */ - sp++; - } - return FALSE; + /* no, onward */ + sp++; + } + return FALSE; } #endif /* * get a command key sequence from the keyboard * - * int mflag; going for a meta sequence? + * int mflag; going for a meta sequence? */ unsigned int getckey(int mflag) { - unsigned int c; /* character fetched */ - char tok[NSTRING]; /* command incoming */ + unsigned int c; /* character fetched */ + char tok[NSTRING]; /* command incoming */ - /* check to see if we are executing a command line */ - if (clexec) { - macarg(tok); /* get the next token */ - return stock(tok); - } + /* check to see if we are executing a command line */ + if (clexec) { + macarg(tok); /* get the next token */ + return stock(tok); + } - /* or the normal way */ - if (mflag) - c = get1key(); - else - c = getcmd(); - return c; + /* or the normal way */ + if (mflag) + c = get1key(); + else + c = getcmd(); + return c; } /* * execute the startup file * - * char *sfname; name of startup file (null if default) + * char *sfname; name of startup file (null if default) */ int startup(char *sfname) { - char *fname; /* resulting file name to execute */ + char *fname; /* resulting file name to execute */ - /* look up the startup file */ - if (*sfname != 0) - fname = flook(sfname, TRUE); - else - fname = flook(pathname[0], TRUE); + /* look up the startup file */ + if (*sfname != 0) + fname = flook(sfname, TRUE); + else + fname = flook( rcfname, TRUE); - /* if it isn't around, don't sweat it */ - if (fname == NULL) - return TRUE; + /* if it isn't around, don't sweat it */ + if (fname == NULL) + return TRUE; - /* otherwise, execute the sucker */ - 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 */ + /* otherwise, execute the sucker */ + return dofile(fname); } /* * change a key command to a string we can print out * - * int c; sequence to translate - * char *seq; destination string for sequence + * int c; sequence to translate + * char *seq; destination string for sequence */ void cmdstr(int c, char *seq) { - char *ptr; /* pointer into current position in sequence */ + char *ptr; /* pointer into current position in sequence */ - ptr = seq; + ptr = seq; - /* apply meta sequence if needed */ - if (c & META) { - *ptr++ = 'M'; - *ptr++ = '-'; - } + /* apply meta sequence if needed */ + if (c & META) { + *ptr++ = 'M'; + *ptr++ = '-'; + } - /* apply ^X sequence if needed */ - if (c & CTLX) { - *ptr++ = '^'; - *ptr++ = 'X'; - } + /* apply ^X sequence if needed */ + if (c & CTLX) { + *ptr++ = '^'; + *ptr++ = 'X'; + } - /* apply SPEC sequence if needed */ - if (c & SPEC) { - *ptr++ = 'F'; - *ptr++ = 'N'; - } + /* apply SPEC sequence if needed */ + if (c & SPEC) { + *ptr++ = 'F'; + *ptr++ = 'N'; + } - /* apply control sequence if needed */ - if (c & CONTROL) { - *ptr++ = '^'; - } + /* apply control sequence if needed */ + if (c & CONTROL) { + *ptr++ = '^'; + } - /* and output the final sequence */ + /* and output the final sequence */ - *ptr++ = c & 255; /* strip the prefixes */ + *ptr++ = c & 255; /* strip the prefixes */ - *ptr = 0; /* terminate the string */ + *ptr = 0; /* terminate the string */ } /* * This function looks a key binding up in the binding table * - * int c; key to find what is bound to it + * int c; key to find what is bound to it */ int (*getbind(int c))(int, int) { - struct key_tab *ktp; + struct key_tab *ktp; - ktp = &keytab[0]; /* Look in key table. */ - while (ktp->k_fp != NULL) { - if (ktp->k_code == c) - return ktp->k_fp; - ++ktp; - } + ktp = &keytab[0]; /* Look in key table. */ + while (ktp->k_fp != NULL) { + if (ktp->k_code == c) + return ktp->k_fp; + ++ktp; + } - /* no such binding */ - return NULL; + /* no such binding */ + return NULL; } /* * getfname: - * This function takes a ptr to function and gets the name - * associated with it. + * This function takes a ptr to function and gets the name + * 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 */ - /* skim through the table, looking for a match */ - nptr = &names[0]; - while (nptr->n_func != NULL) { - if (nptr->n_func == func) - return nptr->n_name; - ++nptr; - } - return NULL; + /* skim through the table, looking for a match */ + nptr = &names[0]; + while (nptr->n_func != NULL) { + if (nptr->n_func == func) + return nptr->n_name; + ++nptr; + } + return NULL; } /* * match fname to a function in the names table * and return any match or NULL if none * - * char *fname; name to attempt to match + * char *fname; name to attempt to match */ int (*fncmatch(char *fname)) (int, int) { - struct name_bind *ffp; /* pointer to entry in name binding table */ + struct name_bind *ffp; /* pointer to entry in name binding table */ - /* scan through the table, returning any match */ - ffp = &names[0]; - while (ffp->n_func != NULL) { - if (strcmp(fname, ffp->n_name) == 0) - return ffp->n_func; - ++ffp; - } - return NULL; + /* scan through the table, returning any match */ + ffp = &names[0]; + while (ffp->n_func != NULL) { + if (strcmp(fname, ffp->n_name) == 0) + return ffp->n_func; + ++ffp; + } + return NULL; } /* * stock: - * String key name TO Command Key + * String key name TO Command Key * - * char *keyname; name of key to translate to Command key form + * char *keyname; name of key to translate to Command key form */ unsigned int stock(char *keyname) { - unsigned int c; /* key sequence to return */ + unsigned int c; /* key sequence to return */ - /* parse it up */ - c = 0; + /* parse it up */ + c = 0; - /* first, the META prefix */ - if (*keyname == 'M' && *(keyname + 1) == '-') { - c = META; - keyname += 2; - } + /* first, the META prefix */ + if (*keyname == 'M' && *(keyname + 1) == '-') { + c = META; + keyname += 2; + } - /* next the function prefix */ - if (*keyname == 'F' && *(keyname + 1) == 'N') { - c |= SPEC; - keyname += 2; - } + /* next the function prefix */ + if (*keyname == 'F' && *(keyname + 1) == 'N') { + c |= SPEC; + keyname += 2; + } - /* control-x as well... (but not with FN) */ - if (*keyname == '^' && *(keyname + 1) == 'X' && !(c & SPEC)) { - c |= CTLX; - keyname += 2; - } + /* control-x as well... (but not with FN) */ + if (*keyname == '^' && *(keyname + 1) == 'X' && !(c & SPEC)) { + c |= CTLX; + keyname += 2; + } - /* a control char? */ - if (*keyname == '^' && *(keyname + 1) != 0) { - c |= CONTROL; - ++keyname; - } - if (*keyname < 32) { - c |= CONTROL; - *keyname += 'A'; - } + /* a control char? */ + if (*keyname == '^' && *(keyname + 1) != 0) { + c |= CONTROL; + ++keyname; + } + if (*keyname < 32) { + c |= CONTROL; + *keyname += 'A'; + } - /* make sure we are not lower case (not with function keys) */ - if (*keyname >= 'a' && *keyname <= 'z' && !(c & SPEC)) - *keyname -= 32; + /* make sure we are not lower case (not with function keys) */ + if (*keyname >= 'a' && *keyname <= 'z' && !(c & SPEC)) + *keyname -= 32; - /* the final sequence... */ - c |= *keyname; - return c; + /* the final sequence... */ + c |= *keyname; + return c; } /* * string key name to binding name.... * - * char *skey; name of keey to get binding for + * char *skey; name of keey to get binding for */ char *transbind(char *skey) { - char *bindname; + char *bindname; - bindname = getfname(getbind(stock(skey))); - if (bindname == NULL) - bindname = "ERROR"; + bindname = getfname(getbind(stock(skey))); + if (bindname == NULL) + bindname = "ERROR"; - return bindname; + return bindname; } diff --git a/bind.h b/bind.h new file mode 100644 index 0000000..3e4c569 --- /dev/null +++ b/bind.h @@ -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 diff --git a/bindable.c b/bindable.c new file mode 100644 index 0000000..ac69788 --- /dev/null +++ b/bindable.c @@ -0,0 +1,180 @@ +/* bindable.h -- implements bindable.c */ +#include "bindable.h" + +#include + + +#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 +#define GOOD (SS$_NORMAL) +#endif + +#ifndef GOOD +#define GOOD 0 +#endif + +/* + * Fancy quit command, as implemented by Norm. If the any buffer has + * changed do a write on that buffer and exit emacs, otherwise simply exit. + */ +int quickexit(int f, int n) +{ + struct buffer *bp; /* scanning pointer to buffers */ + struct buffer *oldcb; /* original current buffer */ + int status; + + oldcb = curbp; /* save in case we fail */ + + bp = bheadp; + while (bp != NULL) { + if ((bp->b_flag & BFCHG) != 0 /* Changed. */ + && (bp->b_flag & BFTRUNC) == 0 /* Not truncated P.K. */ + && (bp->b_flag & BFINVS) == 0) { /* Real. */ + curbp = bp; /* make that buffer cur */ + mlwrite("(Saving %s)", bp->b_fname); +#if PKCODE +#else + mlwrite("\n"); +#endif + if ((status = filesave(f, n)) != TRUE) { + curbp = oldcb; /* restore curbp */ + return status; + } + } + bp = bp->b_bufp; /* on to the next buffer */ + } + quit(f, n); /* conditionally quit */ + return TRUE; +} + +/* + * Quit command. If an argument, always quit. Otherwise confirm if a buffer + * has been changed and not written out. Normally bound to "C-X C-C". + */ +int quit(int f, int n) +{ + int s; + + if (f != FALSE /* Argument forces it. */ + || anycb() == FALSE /* All buffers clean. */ + /* User says it's OK. */ + || (s = + mlyesno("Modified buffers exist. Leave anyway")) == TRUE) { +#if (FILOCK && BSD) || SVR4 + if (lockrel() != TRUE) { + TTputc('\n'); + TTputc('\r'); + TTclose(); + TTkclose(); + exit(1); + } +#endif + vttidy(); + if (f) + exit(n); + else + exit(GOOD); + } + mlwrite(""); + return s; +} + +/* + * Begin a keyboard macro. + * Error if not at the top level in keyboard processing. Set up variables and + * return. + */ +int ctlxlp(int f, int n) +{ + if (kbdmode != STOP) { + mlwrite("%%Macro already active"); + return FALSE; + } + mlwrite("(Start macro)"); + kbdptr = &kbdm[0]; + kbdend = kbdptr; + kbdmode = RECORD; + return TRUE; +} + +/* + * End keyboard macro. Check for the same limit conditions as the above + * routine. Set up the variables and return to the caller. + */ +int ctlxrp(int f, int n) +{ + if (kbdmode == STOP) { + mlwrite("%%Macro not active"); + return FALSE; + } + if (kbdmode == RECORD) { + mlwrite("(End macro)"); + kbdmode = STOP; + } + return TRUE; +} + +/* + * Execute a macro. + * The command argument is the number of times to loop. Quit as soon as a + * command gets an error. Return TRUE if all ok, else FALSE. + */ +int ctlxe(int f, int n) +{ + if (kbdmode != STOP) { + mlwrite("%%Macro already active"); + return FALSE; + } + if (n <= 0) + return TRUE; + kbdrep = n; /* remember how many times to execute */ + kbdmode = PLAY; /* start us in play mode */ + kbdptr = &kbdm[0]; /* at the beginning */ + return TRUE; +} + +/* + * Abort. + * Beep the beeper. Kill off any keyboard macro, etc., that is in progress. + * Sometimes called as a routine, to do general aborting of stuff. + */ +int ctrlg(int f, int n) +{ + TTbeep(); + kbdmode = STOP; + mlwrite("(Aborted)"); + return ABORT; +} + +/* user function that does NOTHING */ +int nullproc(int f, int n) +{ + return TRUE; +} + +/* dummy function for binding to meta prefix */ +int metafn(int f, int n) +{ + return TRUE; +} + +/* dummy function for binding to control-x prefix */ +int cex(int f, int n) +{ + return TRUE; +} + +/* dummy function for binding to universal-argument */ +int unarg(int f, int n) +{ + return TRUE; +} diff --git a/bindable.h b/bindable.h new file mode 100644 index 0000000..8e10ac6 --- /dev/null +++ b/bindable.h @@ -0,0 +1,11 @@ +/* functions that can be bound to keys or procedure names */ +int quickexit( int f, int n) ; +int quit( int f, int n) ; +int ctlxlp( int f, int n) ; +int ctlxrp( int f, int n) ; +int ctlxe( int f, int n) ; +int ctrlg( int f, int n) ; +int nullproc( int f, int n) ; +int metafn( int f, int n) ; +int cex( int f, int n) ; +int unarg( int f, int n) ; diff --git a/buffer.c b/buffer.c index 9aaf530..625e1b7 100644 --- a/buffer.c +++ b/buffer.c @@ -1,3 +1,6 @@ +/* buffer.c -- implements buffer.h */ +#include "buffer.h" + /* buffer.c * * Buffer management. @@ -9,12 +12,42 @@ * modified by Petri Kutvonen */ -#include +#include +#include +#include +#include "defines.h" +#include "display.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" -#include "line.h" +#include "file.h" +#include "input.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 @@ -26,9 +59,9 @@ int usebuffer(int f, int n) { struct buffer *bp; 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; if ((bp = bfind(bufn, TRUE, 0)) == NULL) return FALSE; @@ -135,9 +168,9 @@ int killbuffer(int f, int n) { struct buffer *bp; 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; if ((bp = bfind(bufn, FALSE, 0)) == NULL) /* Easy if unknown. */ return TRUE; @@ -185,10 +218,10 @@ int zotbuf(struct buffer *bp) int namebuffer(int f, int n) { 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 */ - ask:if (mlreply("Change buffer name to: ", bufn, NBUFN) != + ask:if (mlreply("Change buffer name to: ", bufn, sizeof bufn) != TRUE) return FALSE; @@ -267,7 +300,7 @@ int listbuffers(int f, int n) * int iflag; list hidden buffer flag */ #define MAXLINE MAXCOL -int makelist(int iflag) +static int makelist( int iflag) { char *cp1; char *cp2; @@ -277,16 +310,15 @@ int makelist(int iflag) int s; int i; long nbytes; /* # of bytes in current buffer */ - char b[7 + 1]; + char b[ 8 + 1] ; char line[MAXLINE]; blistp->b_flag &= ~BFCHG; /* Don't complain! */ if ((s = bclear(blistp)) != TRUE) /* Blow old text away */ return s; strcpy(blistp->b_fname, ""); - if (addline("ACT MODES Size Buffer File") == FALSE - || addline("--- ----- ---- ------ ----") == - FALSE) + if( addline("ACT MODES Size Buffer File") == FALSE + || addline("--- ----- ---- ------ ----") == FALSE) return FALSE; bp = bheadp; /* For all buffers */ @@ -343,24 +375,28 @@ int makelist(int iflag) else *cp1++ = '.'; } - *cp1++ = ' '; /* Gap. */ + + /* No gap as buffer size if left padded with space */ + + /* Buffer size */ nbytes = 0L; /* Count bytes in buf. */ lp = lforw(bp->b_linep); while (lp != bp->b_linep) { nbytes += (long) llength(lp) + 1L; 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]; while ((c = *cp2++) != 0) *cp1++ = c; + *cp1++ = ' '; /* Gap. */ cp2 = &bp->b_bname[0]; /* Buffer name */ while ((c = *cp2++) != 0) *cp1++ = c; cp2 = &bp->b_fname[0]; /* File name */ if (*cp2 != 0) { - while (cp1 < &line[3 + 1 + 5 + 1 + 6 + 4 + NBUFN]) + while( cp1 < &line[ 3 + 1 + NUMMODES + 8 + 1 + (NBUFN-1) + 1]) *cp1++ = ' '; while ((c = *cp2++) != 0) { if (cp1 < &line[MAXLINE - 1]) @@ -375,15 +411,15 @@ int makelist(int iflag) 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. */ buf[--width] = (int) (num % 10L) + '0'; num /= 10L; } buf[--width] = (int) num + '0'; /* Always 1 digit. */ - while (width != 0) /* Pad with blanks. */ + while( width > 0) /* Pad with blanks. */ buf[--width] = ' '; } @@ -394,7 +430,7 @@ void ltoa(char *buf, int width, long num) * on the end. Return TRUE if it worked and * FALSE if you ran out of room. */ -int addline(char *text) +static int addline( char *text) { struct line *lp; int i; @@ -445,7 +481,7 @@ int anycb(void) * and the "cflag" is TRUE, create it. The "bflag" is * 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 *sb; /* buffer to insert after */ diff --git a/buffer.h b/buffer.h new file mode 100644 index 0000000..878df4f --- /dev/null +++ b/buffer.h @@ -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 diff --git a/count.cmd b/count.cmd new file mode 100644 index 0000000..69223cf --- /dev/null +++ b/count.cmd @@ -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 diff --git a/crypt.c b/crypt.c index 5f11ff5..3384410 100644 --- a/crypt.c +++ b/crypt.c @@ -1,3 +1,7 @@ +/* crypt.c -- implements crypt.h */ + +#include "crypt.h" + /* CRYPT.C * * Encryption routines @@ -5,46 +9,12 @@ * written by Dana Hoggatt and Daniel Lawrence */ -#include -#include "estruct.h" -#include "edef.h" -#include "efunc.h" - #if CRYPT +#include + 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; return val; } -#else -static void myennocrypt(void) -{ -} + #endif diff --git a/crypt.h b/crypt.h new file mode 100644 index 0000000..e0ea3e9 --- /dev/null +++ b/crypt.h @@ -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 diff --git a/defines.h b/defines.h new file mode 100644 index 0000000..b710333 --- /dev/null +++ b/defines.h @@ -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 diff --git a/display.c b/display.c index d6d3dba..404a03d 100644 --- a/display.c +++ b/display.c @@ -1,3 +1,9 @@ +/* display.c -- implements display.h */ + +#include "display.h" + +#define REVSTA 1 /* Status line appears in reverse video */ + /* display.c * * The functions in this file handle redisplay. There are two halves, the @@ -11,15 +17,19 @@ #include #include #include +#include #include +#include "buffer.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include "input.h" #include "line.h" +#include "termio.h" +#include "terminal.h" #include "version.h" #include "wrapper.h" #include "utf8.h" +#include "window.h" struct video { int v_flag; /* Flags */ @@ -53,6 +63,17 @@ static int displaying = TRUE; int chg_width, chg_height; #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 void updone(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 mlputli(long l, int r); static void mlputf(int s); +#if SIGWINCH static int newscreensize(int h, int w); +#endif #if RAINBOW 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 *cp5; int nbflag; /* non-blanks to the right flag? */ - int rev; /* reverse video flag */ - int req; /* reverse video request flag */ +#if REVSTA + int rev; /* reverse video flag */ +#endif + int req = FALSE ; /* reverse video request flag */ /* set up pointers to virtual and physical lines */ @@ -1093,7 +1118,7 @@ static void modeline(struct window *wp) #endif vtmove(n, 0); /* Seek to right line. */ if (wp == curwp) /* mark the current buffer */ -#if PKCODE +#if PKCODE && REVSTA lchar = '-'; #else lchar = '='; @@ -1121,12 +1146,7 @@ static void modeline(struct window *wp) n = 2; - strcpy(tline, " "); - strcat(tline, PROGRAM_NAME_LONG); - strcat(tline, " "); - strcat(tline, VERSION); - strcat(tline, ": "); - cp = &tline[0]; + cp = " " PROGRAM_NAME_LONG " " VERSION ": " ; while ((c = *cp++) != 0) { vtputc(c); ++n; @@ -1152,7 +1172,7 @@ static void modeline(struct window *wp) if (firstm != TRUE) strcat(tline, " "); firstm = FALSE; - strcat(tline, mode2name[i]); + strcat( tline, modename[ i]) ; } strcat(tline, ") "); diff --git a/display.h b/display.h new file mode 100644 index 0000000..84ab229 --- /dev/null +++ b/display.h @@ -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 diff --git a/ebind.c b/ebind.c new file mode 100644 index 0000000..90b9cc4 --- /dev/null +++ b/ebind.c @@ -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 + + +#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} +}; diff --git a/ebind.h b/ebind.h index f245246..4f129df 100644 --- a/ebind.h +++ b/ebind.h @@ -1,425 +1,9 @@ -/* ebind.h - * - * Initial default key to function bindings - * - * Modified by Petri Kutvonen - */ +/* 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 */ +} ; -#ifndef EBIND_H_ -#define EBIND_H_ +#define NBINDS 256 /* max # of bound keys */ +extern struct key_tab keytab[ NBINDS] ; /* key bind to functions table */ -#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_ */ diff --git a/edef.h b/edef.h deleted file mode 100644 index b70c9cd..0000000 --- a/edef.h +++ /dev/null @@ -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 -#include - -/* 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_ */ diff --git a/efunc.h b/efunc.h deleted file mode 100644 index 6d0ffbc..0000000 --- a/efunc.h +++ /dev/null @@ -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); diff --git a/epath.h b/epath.h deleted file mode 100644 index 1e85aaa..0000000 --- a/epath.h +++ /dev/null @@ -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_ */ diff --git a/estruct.h b/estruct.h index 3c382ce..cb2e2d4 100644 --- a/estruct.h +++ b/estruct.h @@ -1,3 +1,6 @@ +#ifndef _ESTRUCT_H_ +#define _ESTRUCT_H_ + /* ESTRUCT.H * * Structure and preprocessor defines @@ -8,8 +11,6 @@ * modified by Petri Kutvonen */ -#define MAXCOL 500 -#define MAXROW 500 #ifdef MSDOS #undef MSDOS @@ -17,9 +18,6 @@ #ifdef EGA #undef EGA #endif -#ifdef CTRLZ -#undef CTRLZ -#endif /* Machine/OS definitions. */ @@ -47,7 +45,7 @@ #undef BSD #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 */ #else #define USG 0 @@ -89,7 +87,9 @@ /* Debugging options */ #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 @@ -106,6 +106,17 @@ #define TERMCAP 0 /* Use TERMCAP */ #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 #define VT220 (UNIX | VMS) @@ -121,16 +132,8 @@ /* 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 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 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 @@ -148,13 +151,6 @@ #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 ASCII 1 /* always using ASCII char sequences for now */ @@ -219,107 +215,8 @@ #define ENVFUNC 0 #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 */ -#define nextab(a) (a & ~tabmask) + (tabmask+1) #ifdef abs #undef abs #endif @@ -386,6 +283,9 @@ /* Dynamic RAM tracking and reporting redefinitions */ #if RAMSIZE +#include +void *allocate( size_t size) ; +void release( void *ptr) ; #define malloc allocate #define free release #endif @@ -396,285 +296,8 @@ #if CLEAN #define exit(a) cexit(a) + +int cexit( int status) ; #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 -}; - -#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 */ diff --git a/eval.c b/eval.c index fd4993b..18d4f0d 100644 --- a/eval.c +++ b/eval.c @@ -1,3 +1,6 @@ +/* eval.c -- implements eval.h */ +#include "eval.h" + /* eval.c * * Expression evaluation functions @@ -7,20 +10,289 @@ */ #include +#include +#include +#include "basic.h" +#include "bind.h" +#include "buffer.h" +#include "display.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" -#include "evar.h" +#include "exec.h" +#include "execute.h" +#include "flook.h" +#include "input.h" #include "line.h" -#include "util.h" +#include "random.h" +#include "search.h" +#include "terminal.h" +#include "termio.h" #include "version.h" +#include "window.h" #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 */ 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. */ void varinit(void) { @@ -76,17 +348,17 @@ char *gtfun(char *fname) /* and now evaluate it! */ switch (fnum) { case UFADD: - return itoa(atoi(arg1) + atoi(arg2)); + return i_to_a(atoi(arg1) + atoi(arg2)); case UFSUB: - return itoa(atoi(arg1) - atoi(arg2)); + return i_to_a(atoi(arg1) - atoi(arg2)); case UFTIMES: - return itoa(atoi(arg1) * atoi(arg2)); + return i_to_a(atoi(arg1) * atoi(arg2)); case UFDIV: - return itoa(atoi(arg1) / atoi(arg2)); + return i_to_a(atoi(arg1) / atoi(arg2)); case UFMOD: - return itoa(atoi(arg1) % atoi(arg2)); + return i_to_a(atoi(arg1) % atoi(arg2)); case UFNEG: - return itoa(-atoi(arg1)); + return i_to_a(-atoi(arg1)); case UFCAT: strcpy(result, arg1); return strcat(result, arg2); @@ -119,7 +391,7 @@ char *gtfun(char *fname) case UFOR: return ltos(stol(arg1) || stol(arg2)); case UFLENGTH: - return itoa(strlen(arg1)); + return i_to_a(strlen(arg1)); case UFUPPER: return mkupper(arg1); case UFLOWER: @@ -127,7 +399,7 @@ char *gtfun(char *fname) case UFTRUTH: return ltos(atoi(arg1) == 42); case UFASCII: - return itoa((int) arg1[0]); + return i_to_a((int) arg1[0]); case UFCHR: result[0] = atoi(arg1); result[1] = 0; @@ -137,11 +409,11 @@ char *gtfun(char *fname) result[1] = 0; return result; case UFRND: - return itoa((ernd() % abs(atoi(arg1))) + 1); + return i_to_a((ernd() % abs(atoi(arg1))) + 1); case UFABS: - return itoa(abs(atoi(arg1))); + return i_to_a(abs(atoi(arg1))); case UFSINDEX: - return itoa(sindex(arg1, arg2)); + return i_to_a(sindex(arg1, arg2)); case UFENV: #if ENVFUNC tsp = getenv(arg1); @@ -157,13 +429,13 @@ char *gtfun(char *fname) tsp = flook(arg1, TRUE); return tsp == NULL ? "" : tsp; case UFBAND: - return itoa(atoi(arg1) & atoi(arg2)); + return i_to_a(atoi(arg1) & atoi(arg2)); case UFBOR: - return itoa(atoi(arg1) | atoi(arg2)); + return i_to_a(atoi(arg1) | atoi(arg2)); case UFBXOR: - return itoa(atoi(arg1) ^ atoi(arg2)); + return i_to_a(atoi(arg1) ^ atoi(arg2)); case UFBNOT: - return itoa(~atoi(arg1)); + return i_to_a(~atoi(arg1)); case UFXLATE: return xlat(arg1, arg2, arg3); } @@ -193,8 +465,6 @@ char *gtusr(char *vname) return errorm; } -extern char *getkill(void); - /* * gtenv() * @@ -227,19 +497,19 @@ char *gtenv(char *vname) /* otherwise, fetch the appropriate value */ switch (vnum) { case EVFILLCOL: - return itoa(fillcol); + return i_to_a(fillcol); case EVPAGELEN: - return itoa(term.t_nrow + 1); + return i_to_a(term.t_nrow + 1); case EVCURCOL: - return itoa(getccol(FALSE)); + return i_to_a(getccol(FALSE)); case EVCURLINE: - return itoa(getcline()); + return i_to_a(getcline()); case EVRAM: - return itoa((int) (envram / 1024l)); + return i_to_a((int) (envram / 1024l)); case EVFLICKER: return ltos(flickcode); case EVCURWIDTH: - return itoa(term.t_ncol); + return i_to_a(term.t_ncol); case EVCBUFNAME: return curbp->b_bname; case EVCFNAME: @@ -250,18 +520,22 @@ char *gtenv(char *vname) return ltos(macbug); case EVSTATUS: return ltos(cmdstatus); - case EVPALETTE: + case EVPALETTE: { + static char palstr[ 49] = "" ; /* palette string */ + return palstr; + } + case EVASAVE: - return itoa(gasave); + return i_to_a(gasave); case EVACOUNT: - return itoa(gacount); + return i_to_a(gacount); case EVLASTKEY: - return itoa(lastkey); + return i_to_a(lastkey); case EVCURCHAR: return (curwp->w_dotp->l_used == - curwp->w_doto ? itoa('\n') : - itoa(lgetc(curwp->w_dotp, curwp->w_doto))); + curwp->w_doto ? i_to_a('\n') : + i_to_a(lgetc(curwp->w_dotp, curwp->w_doto))); case EVDISCMD: return ltos(discmd); case EVVERSION: @@ -269,16 +543,16 @@ char *gtenv(char *vname) case EVPROGNAME: return PROGRAM_NAME_LONG; case EVSEED: - return itoa(seed); + return i_to_a(seed); case EVDISINP: return ltos(disinp); case EVWLINE: - return itoa(curwp->w_ntrows); + return i_to_a(curwp->w_ntrows); case EVCWLINE: - return itoa(getwpos()); + return i_to_a(getwpos()); case EVTARGET: saveflag = lastflag; - return itoa(curgoal); + return i_to_a(curgoal); case EVSEARCH: return pat; case EVREPLACE: @@ -288,11 +562,11 @@ char *gtenv(char *vname) case EVKILL: return getkill(); case EVCMODE: - return itoa(curbp->b_mode); + return i_to_a(curbp->b_mode); case EVGMODE: - return itoa(gmode); + return i_to_a(gmode); case EVTPAUSE: - return itoa(term.t_pause); + return i_to_a(term.t_pause); case EVPENDING: #if TYPEAH return ltos(typahead()); @@ -300,19 +574,19 @@ char *gtenv(char *vname) return falsem; #endif case EVLWIDTH: - return itoa(llength(curwp->w_dotp)); + return i_to_a(llength(curwp->w_dotp)); case EVLINE: return getctext(); case EVGFLAGS: - return itoa(gflags); + return i_to_a(gflags); case EVRVAL: - return itoa(rval); + return i_to_a(rval); case EVTAB: - return itoa(tabmask + 1); + return i_to_a(tabmask + 1); case EVOVERLAP: - return itoa(overlap); + return i_to_a(overlap); case EVSCROLLCOUNT: - return itoa(scrollcount); + return i_to_a(scrollcount); #if SCROLLCODE case EVSCROLL: return ltos(term.t_scroll != NULL); @@ -324,30 +598,6 @@ char *gtenv(char *vname) 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 * @@ -357,10 +607,6 @@ char *getkill(void) int setvar(int f, int n) { 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 */ char var[NVSIZE + 1]; /* name of variable to fetch */ char value[NSTRING]; /* value to set variable to */ @@ -386,7 +632,7 @@ int setvar(int f, int n) /* get the value for that variable */ if (f == TRUE) - strcpy(value, itoa(n)); + strcpy(value, i_to_a(n)); else { status = mlreply("Value: ", &value[0], NSTRING); if (status != TRUE) @@ -401,6 +647,8 @@ int setvar(int f, int n) that effect here. */ if (macbug) { + char *sp ; /* temp string pointer */ + strcpy(outline, "((("); /* assignment status */ @@ -419,6 +667,8 @@ int setvar(int f, int n) sp = outline; while (*sp) if (*sp++ == '%') { + char *ep ; /* ptr to end of outline */ + /* advance to the end */ ep = --sp; while (*ep++); @@ -455,7 +705,7 @@ int setvar(int f, int n) * @vd: structure to hold type and pointer. * @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 vtype; /* type to return */ @@ -513,7 +763,7 @@ fvar: * @var: variable to set. * @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 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 * inconsistant to use the system's * * 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 */ char *sp; /* pointer into result */ int sign; /* sign of resulting number */ @@ -869,8 +1121,11 @@ int stol(char *val) * * 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) return truem; else diff --git a/eval.h b/eval.h new file mode 100644 index 0000000..84a5b58 --- /dev/null +++ b/eval.h @@ -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 diff --git a/evar.h b/evar.h deleted file mode 100644 index 6e7cb6b..0000000 --- a/evar.h +++ /dev/null @@ -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_ */ diff --git a/exec.c b/exec.c index 2937966..d37ffcd 100644 --- a/exec.c +++ b/exec.c @@ -1,3 +1,6 @@ +/* exec.c -- implements exec.h */ +#include "exec.h" + /* exec.c * * This file is for functions dealing with execution of @@ -8,11 +11,74 @@ */ #include +#include +#include +#include "buffer.h" +#include "bind.h" +#include "display.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include "eval.h" +#include "file.h" +#include "flook.h" +#include "input.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. @@ -35,6 +101,8 @@ int namedcmd(int f, int n) return kfunc(f, n); } +static int docmd( char *cline) ; + /* * execcmd: * 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 */ -int docmd(char *cline) -{ +static int docmd( char *cline) { int f; /* default argument flag */ int n; /* numeric repeat value */ fn_t fnc; /* function to execute */ 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 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 savcle; /* buffer to store original clexec */ + boolean savcle ; /* buffer to store original clexec */ int status; savcle = clexec; /* save execution mode */ @@ -222,12 +289,12 @@ int macarg(char *tok) * nextarg: * 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 * int size; size of the buffer * 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 (clexec == FALSE) @@ -237,7 +304,8 @@ int nextarg(char *prompt, char *buffer, int size, int terminator) execstr = token(execstr, buffer, size); /* evaluate it */ - strcpy(buffer, getval(buffer)); + strncpy( buffer, getval( buffer), size - 1) ; + buffer[ size - 1] = '\0' ; return TRUE; } @@ -252,7 +320,7 @@ int nextarg(char *prompt, char *buffer, int size, int terminator) int storemac(int f, int n) { 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 */ if (f == FALSE) { @@ -299,7 +367,7 @@ int storeproc(int f, int n) { struct buffer *bp; /* pointer to macro buffer */ 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 */ if (f == TRUE) @@ -307,7 +375,7 @@ int storeproc(int f, int n) /* get the name of the procedure */ if ((status = - mlreply("Procedure name: ", &bname[1], NBUFN - 2)) != TRUE) + mlreply("Procedure name: ", &bname[1], sizeof bname - 2)) != TRUE) return status; /* construct the macro buffer name */ @@ -374,10 +442,10 @@ int execbuf(int f, int n) { struct buffer *bp; /* ptr to buffer to execute */ 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 */ - if ((status = mlreply("Execute buffer: ", bufn, NBUFN)) != TRUE) + if ((status = mlreply("Execute buffer: ", bufn, sizeof bufn)) != TRUE) return status; /* find the pointer to that buffer */ @@ -416,7 +484,7 @@ int execbuf(int f, int n) * * struct buffer *bp; buffer to execute */ -int dobuf(struct buffer *bp) +static int dobuf(struct buffer *bp) { int status; /* status return */ struct line *lp; /* pointer to line to execute */ @@ -426,7 +494,6 @@ int dobuf(struct buffer *bp) int dirnum; /* directive index */ int linlen; /* length of line to execute */ int i; /* index */ - int c; /* temp character */ int force; /* force TRUE result? */ struct window *wp; /* ptr to windows to scan */ 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 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 */ execlevel = 0; whlist = NULL; @@ -557,6 +619,9 @@ int dobuf(struct buffer *bp) ^G will abort the command */ if (macbug) { + char *sp ; /* temp for building debug string */ + int c ; /* temp character */ + strcpy(outline, "<<<"); /* debug macro name */ @@ -564,7 +629,7 @@ int dobuf(struct buffer *bp) strcat(outline, ":"); /* debug if levels */ - strcat(outline, itoa(execlevel)); + strcat(outline, i_to_a(execlevel)); strcat(outline, ":"); /* and lastly the line */ @@ -575,6 +640,8 @@ int dobuf(struct buffer *bp) sp = outline; while (*sp) if (*sp++ == '%') { + char *ep ; /* ptr to end of outline */ + /* advance to the end */ ep = --sp; while (*ep++); @@ -732,7 +799,7 @@ int dobuf(struct buffer *bp) /* grab label to jump to */ eline = - token(eline, golabel, NPAT); + token( eline, golabel, sizeof golabel) ; linlen = strlen(golabel); glp = hlp->l_fp; while (glp != hlp) { @@ -833,7 +900,7 @@ int dobuf(struct buffer *bp) * * 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) return; @@ -886,7 +953,7 @@ int dofile(char *fname) struct buffer *bp; /* buffer to place file to exeute */ struct buffer *cb; /* temp to hold current buf while we read */ 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 */ unqname(bname); /* make sure we don't stomp things */ diff --git a/exec.h b/exec.h new file mode 100644 index 0000000..7ac4b1c --- /dev/null +++ b/exec.h @@ -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 diff --git a/execute.c b/execute.c new file mode 100644 index 0000000..78333da --- /dev/null +++ b/execute.c @@ -0,0 +1,108 @@ +/* execute.c -- implements execute.h */ +#include "execute.h" + +#include + +#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; +} + diff --git a/execute.h b/execute.h new file mode 100644 index 0000000..a172652 --- /dev/null +++ b/execute.h @@ -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) ; + diff --git a/file.c b/file.c index 1feb97a..9594553 100644 --- a/file.c +++ b/file.c @@ -1,25 +1,55 @@ -/* file.c +/* file.c -- implements file.h */ + +#include "file.h" + +/* file.c * - * The routines in this file handle the reading, writing - * and lookup of disk files. All of details about the - * reading and writing of the disk are in "fileio.c". + * The routines in this file handle the reading, writing + * and lookup of disk files. All of details about the + * reading and writing of the disk are in "fileio.c". * - * modified by Petri Kutvonen + * modified by Petri Kutvonen */ #include +#include #include +#include "buffer.h" +#include "crypt.h" +#include "defines.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include "execute.h" +#include "fileio.h" +#include "input.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. */ -#define MAXNLINE 10000000 +#define MAXNLINE 10000000 #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 * buffer. This is really easy; all you do it @@ -29,14 +59,14 @@ */ int fileread(int f, int n) { - int s; - char fname[NFILEN]; + int s; + fname_t fname ; - if (restflag) /* don't allow this command if restricted */ - return resterr(); - if ((s = mlreply("Read file: ", fname, NFILEN)) != TRUE) - return s; - return readin(fname, TRUE); + if (restflag) /* don't allow this command if restricted */ + return resterr(); + if ((s = mlreply("Read file: ", fname, sizeof fname)) != TRUE) + return s; + return readin(fname, TRUE); } /* @@ -48,18 +78,18 @@ int fileread(int f, int n) */ int insfile(int f, int n) { - int s; - char fname[NFILEN]; + int s; + fname_t fname ; - if (restflag) /* don't allow this command if restricted */ - return resterr(); - if (curbp->b_mode & MDVIEW) /* don't allow this command if */ - return rdonly(); /* we are in read only mode */ - if ((s = mlreply("Insert file: ", fname, NFILEN)) != TRUE) - return s; - if ((s = ifile(fname)) != TRUE) - return s; - return reposition(TRUE, -1); + if (restflag) /* don't allow this command if restricted */ + return resterr(); + if (curbp->b_mode & MDVIEW) /* don't allow this command if */ + return rdonly(); /* we are in read only mode */ + if ((s = mlreply("Insert file: ", fname, sizeof fname)) != TRUE) + return s; + if ((s = ifile(fname)) != TRUE) + return s; + return reposition(TRUE, -1); } /* @@ -73,132 +103,165 @@ int insfile(int f, int n) */ int filefind(int f, int n) { - char fname[NFILEN]; /* file user wishes to find */ - int s; /* status return */ + fname_t fname ; /* file user wishes to find */ + int s; /* status return */ - if (restflag) /* don't allow this command if restricted */ - return resterr(); - if ((s = mlreply("Find file: ", fname, NFILEN)) != TRUE) - return s; - return getfile(fname, TRUE); + if (restflag) /* don't allow this command if restricted */ + return resterr(); + if ((s = mlreply("Find file: ", fname, sizeof fname)) != TRUE) + return s; + return getfile(fname, TRUE); } int viewfile(int f, int n) -{ /* visit a file in VIEW mode */ - char fname[NFILEN]; /* file user wishes to find */ - int s; /* status return */ - struct window *wp; /* scan for windows that need updating */ +{ /* visit a file in VIEW mode */ + fname_t fname ; /* file user wishes to find */ + int s; /* status return */ + struct window *wp; /* scan for windows that need updating */ - if (restflag) /* don't allow this command if restricted */ - return resterr(); - if ((s = mlreply("View file: ", fname, NFILEN)) != TRUE) - return s; - s = getfile(fname, FALSE); - if (s) { /* if we succeed, put it in view mode */ - curwp->w_bufp->b_mode |= MDVIEW; + if (restflag) /* don't allow this command if restricted */ + return resterr(); + if ((s = mlreply("View file: ", fname, sizeof fname)) != TRUE) + return s; + s = getfile(fname, FALSE); + if (s) { /* if we succeed, put it in view mode */ + curwp->w_bufp->b_mode |= MDVIEW; - /* scan through and update mode lines of all windows */ - wp = wheadp; - while (wp != NULL) { - wp->w_flag |= WFMODE; - wp = wp->w_wndp; - } - } - return s; + /* scan through and update mode lines of all windows */ + wp = wheadp; + while (wp != NULL) { + wp->w_flag |= WFMODE; + wp = wp->w_wndp; + } + } + return s; } -#if CRYPT -static int resetkey(void) -{ /* reset the encryption key if needed */ - int s; /* return status */ +#if CRYPT +void cryptbufferkey( struct buffer *bp) { + myencrypt( (char *) NULL, 0) ; + myencrypt( bp->b_key, strlen( bp->b_key)) ; +} - /* turn off the encryption flag */ - cryptflag = FALSE; +/* + * 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 */ - /* if we are in crypt mode */ - if (curbp->b_mode & MDCRYPT) { - if (curbp->b_key[0] == 0) { - s = set_encryption_key(FALSE, 0); - if (s != TRUE) - return s; - } + /* turn command input echo off */ + odisinp = disinp; + disinp = FALSE; - /* let others know... */ - cryptflag = TRUE; - - /* and set up the key to be used! */ - /* de-encrypt it */ - myencrypt((char *) NULL, 0); - myencrypt(curbp->b_key, strlen(curbp->b_key)); - - /* re-encrypt it...seeding it to start */ - myencrypt((char *) NULL, 0); - myencrypt(curbp->b_key, strlen(curbp->b_key)); - } + /* 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) +{ /* reset the encryption key if needed */ + int s; /* return status */ + + /* turn off the encryption flag */ + is_crypted = FALSE; + + /* if we are in crypt mode */ + if (curbp->b_mode & MDCRYPT) { + if (curbp->b_key[0] == 0) { + s = set_encryption_key(FALSE, 0); + if (s != TRUE) + return s; + } + + /* let others know... */ + is_crypted = TRUE; + + /* and set up the key to be used! */ + /* de-encrypt it */ + cryptbufferkey( curbp) ; + + /* re-encrypt it...seeding it to start */ + cryptbufferkey( curbp) ; + } + + return TRUE; +} #endif /* * getfile() * - * char fname[]; file name to find - * int lockfl; check the file for locks? + * char fname[]; file name to find + * boolean lockfl; check the file for locks? */ -int getfile(char *fname, int lockfl) +int getfile( const char *fname, boolean lockfl) { - struct buffer *bp; - struct line *lp; - int i; - int s; - char bname[NBUFN]; /* buffer name to put file */ + struct buffer *bp; + struct line *lp; + int i; + int s; + bname_t bname ; /* buffer name to put file */ -#if MSDOS - mklower(fname); /* msdos isn't case sensitive */ +#if MSDOS + mklower(fname); /* msdos isn't case sensitive */ #endif - for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { - if ((bp->b_flag & BFINVS) == 0 - && strcmp(bp->b_fname, fname) == 0) { - swbuffer(bp); - lp = curwp->w_dotp; - i = curwp->w_ntrows / 2; - while (i-- && lback(lp) != curbp->b_linep) - lp = lback(lp); - curwp->w_linep = lp; - curwp->w_flag |= WFMODE | WFHARD; - cknewwindow(); - mlwrite("(Old buffer)"); - return TRUE; - } - } - makename(bname, fname); /* New buffer name. */ - while ((bp = bfind(bname, FALSE, 0)) != NULL) { - /* old buffer name conflict code */ - s = mlreply("Buffer name: ", bname, NBUFN); - if (s == ABORT) /* ^G to just quit */ - return s; - if (s == FALSE) { /* CR to clobber it */ - makename(bname, fname); - break; - } - } - if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) { - mlwrite("Cannot create buffer"); - return FALSE; - } - if (--curbp->b_nwnd == 0) { /* Undisplay. */ - curbp->b_dotp = curwp->w_dotp; - curbp->b_doto = curwp->w_doto; - curbp->b_markp = curwp->w_markp; - curbp->b_marko = curwp->w_marko; - } - curbp = bp; /* Switch to it. */ - curwp->w_bufp = bp; - curbp->b_nwnd++; - s = readin(fname, lockfl); /* Read it in. */ - cknewwindow(); - return s; + for (bp = bheadp; bp != NULL; bp = bp->b_bufp) { + if ((bp->b_flag & BFINVS) == 0 + && strcmp(bp->b_fname, fname) == 0) { + swbuffer(bp); + lp = curwp->w_dotp; + i = curwp->w_ntrows / 2; + while (i-- && lback(lp) != curbp->b_linep) + lp = lback(lp); + curwp->w_linep = lp; + curwp->w_flag |= WFMODE | WFHARD; + cknewwindow(); + logwrite("(Old buffer)"); + return TRUE; + } + } + makename(bname, fname); /* New buffer name. */ + while ((bp = bfind(bname, FALSE, 0)) != NULL) { + /* old buffer name conflict code */ + s = mlreply("Buffer name: ", bname, sizeof bname); + if (s == ABORT) /* ^G to just quit */ + return s; + if (s == FALSE) { /* CR to clobber it */ + makename(bname, fname); + break; + } + } + if (bp == NULL && (bp = bfind(bname, TRUE, 0)) == NULL) { + logwrite("Cannot create buffer"); + return FALSE; + } + if (--curbp->b_nwnd == 0) { /* Undisplay. */ + curbp->b_dotp = curwp->w_dotp; + curbp->b_doto = curwp->w_doto; + curbp->b_markp = curwp->w_markp; + curbp->b_marko = curwp->w_marko; + } + curbp = bp; /* Switch to it. */ + curwp->w_bufp = bp; + curbp->b_nwnd++; + s = readin(fname, lockfl); /* Read it in. */ + cknewwindow(); + return s; } /* @@ -209,110 +272,136 @@ int getfile(char *fname, int lockfl) * The command bound to M-FNR is called after the buffer is set up * and before it is read. * - * char fname[]; name of file to read - * int lockfl; check for file locks? + * char fname[]; name of file to read + * boolean lockfl; check for file locks? */ -int readin(char *fname, int lockfl) +int readin(const char *fname, boolean lockfl) { - struct line *lp1; - struct line *lp2; - int i; - struct window *wp; - struct buffer *bp; - int s; - int nbytes; - int nline; - char mesg[NSTRING]; + struct line *lp1; + struct line *lp2; + struct window *wp; + struct buffer *bp; + int s; + eoltype found_eol ; + int nbytes; + int nline; + char mesg[NSTRING]; -#if (FILOCK && BSD) || SVR4 - if (lockfl && lockchk(fname) == ABORT) +#if (FILOCK && BSD) || SVR4 + if (lockfl && lockchk(fname) == ABORT) #if PKCODE - { - s = FIOFNF; - bp = curbp; - strcpy(bp->b_fname, ""); - goto out; - } + { + s = FIOFNF; + bp = curbp; + strcpy(bp->b_fname, ""); + goto out; + } #else - return ABORT; + return ABORT; #endif #endif -#if CRYPT - s = resetkey(); - if (s != TRUE) - return s; +#if CRYPT + s = resetkey(); + if (s != TRUE) + return s; #endif - bp = curbp; /* Cheap. */ - if ((s = bclear(bp)) != TRUE) /* Might be old. */ - return s; - bp->b_flag &= ~(BFINVS | BFCHG); - strcpy(bp->b_fname, fname); + bp = curbp; /* Cheap. */ + if ((s = bclear(bp)) != TRUE) /* Might be old. */ + return s; + bp->b_flag &= ~(BFINVS | BFCHG); + strcpy(bp->b_fname, fname); - /* let a user macro get hold of things...if he wants */ - execute(META | SPEC | 'R', FALSE, 1); + /* let a user macro get hold of things...if he wants */ + execute(META | SPEC | 'R', FALSE, 1); - if ((s = ffropen(fname)) == FIOERR) /* Hard file open. */ - goto out; + if ((s = ffropen(fname)) == FIOERR) /* Hard file open. */ + goto out; - if (s == FIOFNF) { /* File not found. */ - mlwrite("(New file)"); - goto out; - } + if (s == FIOFNF) { /* File not found. */ + logwrite("(New file)"); + goto out; + } - /* read the file in */ - mlwrite("(Reading file)"); - nline = 0; - while ((s = ffgetline()) == FIOSUC) { - nbytes = strlen(fline); - if ((lp1 = lalloc(nbytes)) == NULL) { - s = FIOMEM; /* Keep message on the */ - break; /* display. */ - } -#if PKCODE - if (nline > MAXNLINE) { - s = FIOMEM; - break; - } + /* read the file in */ + logwrite("(Reading file)"); + nline = 0; + while ((s = ffgetline()) == FIOSUC) { + nbytes = fpayload ; +#if PKCODE + if (nline > MAXNLINE) { + s = FIOMEM; + break; + } #endif - lp2 = lback(curbp->b_linep); - lp2->l_fp = lp1; - lp1->l_fp = curbp->b_linep; - lp1->l_bp = lp2; - curbp->b_linep->l_bp = lp1; - for (i = 0; i < nbytes; ++i) - lputc(lp1, i, fline[i]); - ++nline; + if ((lp1 = lalloc(nbytes)) == NULL) { + s = FIOMEM; /* Keep message on the */ + break; /* display. */ + } + lp2 = lback(curbp->b_linep); + lp2->l_fp = lp1; + lp1->l_fp = curbp->b_linep; + lp1->l_bp = lp2; + curbp->b_linep->l_bp = lp1; + memcpy( lp1->l_text, fline, nbytes) ; + ++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. */ - strcpy(mesg, "("); - if (s == FIOERR) { - strcat(mesg, "I/O ERROR, "); - curbp->b_flag |= BFTRUNC; - } - if (s == FIOMEM) { - strcat(mesg, "OUT OF MEMORY, "); - curbp->b_flag |= BFTRUNC; - } - sprintf(&mesg[strlen(mesg)], "Read %d line", nline); - if (nline != 1) - strcat(mesg, "s"); - strcat(mesg, ")"); - mlwrite(mesg); + + ffclose(); /* Ignore errors. */ + strcpy(mesg, "("); + if (s == FIOERR) { + strcat(mesg, "I/O ERROR, "); + curbp->b_flag |= BFTRUNC; + } + if (s == FIOMEM) { + strcat(mesg, "OUT OF MEMORY, "); + curbp->b_flag |= BFTRUNC; + } + sprintf(&mesg[strlen(mesg)], "Read %d line", nline); + if (nline != 1) + strcat(mesg, "s"); + + strcat( mesg, ", eol = ") ; + strcat( mesg, eolname[ found_eol]) ; + strcat(mesg, ")"); + logwrite(mesg); out: - for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { - if (wp->w_bufp == curbp) { - wp->w_linep = lforw(curbp->b_linep); - wp->w_dotp = lforw(curbp->b_linep); - wp->w_doto = 0; - wp->w_markp = NULL; - wp->w_marko = 0; - wp->w_flag |= WFMODE | WFHARD; - } - } - if (s == FIOERR || s == FIOFNF) /* False if error. */ - return FALSE; - return TRUE; + for (wp = wheadp; wp != NULL; wp = wp->w_wndp) { + if (wp->w_bufp == curbp) { + wp->w_linep = lforw(curbp->b_linep); + wp->w_dotp = lforw(curbp->b_linep); + wp->w_doto = 0; + wp->w_markp = NULL; + wp->w_marko = 0; + wp->w_flag |= WFMODE | WFHARD; + } + } + if (s == FIOERR || s == FIOFNF) /* False if error. */ + return FALSE; + return TRUE; } /* @@ -322,61 +411,61 @@ int readin(char *fname, int lockfl) * I suppose that this information could be put in * a better place than a line of code. */ -void makename(char *bname, char *fname) +void makename( bname_t bname, const char *fname) { - char *cp1; - char *cp2; + const char *cp1; + char *cp2; - cp1 = &fname[0]; - while (*cp1 != 0) - ++cp1; + cp1 = &fname[0]; + while (*cp1 != 0) + ++cp1; #if VMS -#if PKCODE - while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != ']' - && cp1[-1] != '>') +#if PKCODE + while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != ']' + && cp1[-1] != '>') #else - while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != ']') + while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != ']') #endif - --cp1; + --cp1; #endif #if MSDOS - while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != '\\' - && cp1[-1] != '/') - --cp1; + while (cp1 != &fname[0] && cp1[-1] != ':' && cp1[-1] != '\\' + && cp1[-1] != '/') + --cp1; #endif #if V7 | USG | BSD - while (cp1 != &fname[0] && cp1[-1] != '/') - --cp1; + while (cp1 != &fname[0] && cp1[-1] != '/') + --cp1; #endif - cp2 = &bname[0]; - while (cp2 != &bname[NBUFN - 1] && *cp1 != 0 && *cp1 != ';') - *cp2++ = *cp1++; - *cp2 = 0; + cp2 = &bname[0]; + while( cp2 != &bname[ sizeof( bname_t) - 1] && *cp1 != 0 && *cp1 != ';') + *cp2++ = *cp1++; + *cp2 = 0; } /* * make sure a buffer name is unique * - * char *name; name to check on + * char *name; name to check on */ void unqname(char *name) { - char *sp; + char *sp; - /* check to see if it is in the buffer list */ - while (bfind(name, 0, FALSE) != NULL) { + /* check to see if it is in the buffer list */ + while (bfind(name, 0, FALSE) != NULL) { - /* go to the end of the name */ - sp = name; - while (*sp) - ++sp; - if (sp == name || (*(sp - 1) < '0' || *(sp - 1) > '8')) { - *sp++ = '0'; - *sp = 0; - } else - *(--sp) += 1; - } + /* go to the end of the name */ + sp = name; + while (*sp) + ++sp; + if (sp == name || (*(sp - 1) < '0' || *(sp - 1) > '8')) { + *sp++ = '0'; + *sp = 0; + } else + *(--sp) += 1; + } } /* @@ -390,25 +479,25 @@ void unqname(char *name) */ int filewrite(int f, int n) { - struct window *wp; - int s; - char fname[NFILEN]; + struct window *wp; + int s; + fname_t fname ; - if (restflag) /* don't allow this command if restricted */ - return resterr(); - if ((s = mlreply("Write file: ", fname, NFILEN)) != TRUE) - return s; - if ((s = writeout(fname)) == TRUE) { - strcpy(curbp->b_fname, fname); - curbp->b_flag &= ~BFCHG; - wp = wheadp; /* Update mode lines. */ - while (wp != NULL) { - if (wp->w_bufp == curbp) - wp->w_flag |= WFMODE; - wp = wp->w_wndp; - } - } - return s; + if (restflag) /* don't allow this command if restricted */ + return resterr(); + if ((s = mlreply("Write file: ", fname, sizeof fname)) != TRUE) + return s; + if ((s = writeout(fname)) == TRUE) { + strcpy(curbp->b_fname, fname); + curbp->b_flag &= ~BFCHG; + wp = wheadp; /* Update mode lines. */ + while (wp != NULL) { + if (wp->w_bufp == curbp) + wp->w_flag |= WFMODE; + wp = wp->w_wndp; + } + } + return s; } /* @@ -421,36 +510,36 @@ int filewrite(int f, int n) */ int filesave(int f, int n) { - struct window *wp; - int s; + struct window *wp; + int s; - if (curbp->b_mode & MDVIEW) /* don't allow this command if */ - return rdonly(); /* we are in read only mode */ - if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */ - return TRUE; - if (curbp->b_fname[0] == 0) { /* Must have a name. */ - mlwrite("No file name"); - return FALSE; - } + if (curbp->b_mode & MDVIEW) /* don't allow this command if */ + return rdonly(); /* we are in read only mode */ + if ((curbp->b_flag & BFCHG) == 0) /* Return, no changes. */ + return TRUE; + if (curbp->b_fname[0] == 0) { /* Must have a name. */ + logwrite("No file name"); + return FALSE; + } - /* complain about truncated files */ - if ((curbp->b_flag & BFTRUNC) != 0) { - if (mlyesno("Truncated file ... write it out") == FALSE) { - mlwrite("(Aborted)"); - return FALSE; - } - } + /* complain about truncated files */ + if ((curbp->b_flag & BFTRUNC) != 0) { + if (mlyesno("Truncated file ... write it out") == FALSE) { + logwrite("(Aborted)"); + return FALSE; + } + } - if ((s = writeout(curbp->b_fname)) == TRUE) { - curbp->b_flag &= ~BFCHG; - wp = wheadp; /* Update mode lines. */ - while (wp != NULL) { - if (wp->w_bufp == curbp) - wp->w_flag |= WFMODE; - wp = wp->w_wndp; - } - } - return s; + if ((s = writeout(curbp->b_fname)) == TRUE) { + curbp->b_flag &= ~BFCHG; + wp = wheadp; /* Update mode lines. */ + while (wp != NULL) { + if (wp->w_bufp == curbp) + wp->w_flag |= WFMODE; + wp = wp->w_wndp; + } + } + return s; } /* @@ -461,43 +550,49 @@ int filesave(int f, int n) * a macro for this. Most of the grief is error * checking of some sort. */ -int writeout(char *fn) +int writeout( const char *fn) { - int s; - struct line *lp; - int nline; + int s; + struct line *lp; + int nline; -#if CRYPT - s = resetkey(); - if (s != TRUE) - return s; +#if CRYPT + s = resetkey(); + if (s != TRUE) + return s; #endif - if ((s = ffwopen(fn)) != FIOSUC) { /* Open writes message. */ - return FALSE; - } - mlwrite("(Writing...)"); /* tell us were writing */ - lp = lforw(curbp->b_linep); /* First line. */ - nline = 0; /* Number of lines. */ - while (lp != curbp->b_linep) { - if ((s = ffputline(&lp->l_text[0], llength(lp))) != FIOSUC) - break; - ++nline; - lp = lforw(lp); - } - if (s == FIOSUC) { /* No write error. */ - s = ffclose(); - if (s == FIOSUC) { /* No close error. */ - if (nline == 1) - mlwrite("(Wrote 1 line)"); - else - mlwrite("(Wrote %d lines)", nline); - } - } else /* Ignore close error */ - ffclose(); /* if a write error. */ - if (s != FIOSUC) /* Some sort of error. */ - return FALSE; - return TRUE; + if ((s = ffwopen(fn)) != FIOSUC) { /* Open writes message. */ + logwrite( "Cannot open file for writing") ; + return FALSE; + } + logwrite("(Writing...)"); /* tell us were writing */ + lp = lforw(curbp->b_linep); /* First line. */ + nline = 0; /* Number of lines. */ + while (lp != curbp->b_linep) { + s = ffputline( &lp->l_text[0], llength(lp), curbp->b_mode & MDDOS) ; + if( s != FIOSUC) { + logwrite( "Write I/O error") ; + break; + } + + ++nline; + lp = lforw(lp); + } + if (s == FIOSUC) { /* No write error. */ + s = ffclose(); + if (s == FIOSUC) { /* No close error. */ + if (nline == 1) + logwrite("(Wrote 1 line)"); + else + logwrite("(Wrote %d lines)", nline); + } else + logwrite( "Error closing file") ; + } else /* Ignore close error */ + ffclose(); /* if a write error. */ + if (s != FIOSUC) /* Some sort of error. */ + return FALSE; + return TRUE; } /* @@ -511,26 +606,26 @@ int writeout(char *fn) */ int filename(int f, int n) { - struct window *wp; - int s; - char fname[NFILEN]; + struct window *wp; + int s; + fname_t fname ; - if (restflag) /* don't allow this command if restricted */ - return resterr(); - if ((s = mlreply("Name: ", fname, NFILEN)) == ABORT) - return s; - if (s == FALSE) - strcpy(curbp->b_fname, ""); - else - strcpy(curbp->b_fname, fname); - wp = wheadp; /* Update mode lines. */ - while (wp != NULL) { - if (wp->w_bufp == curbp) - wp->w_flag |= WFMODE; - wp = wp->w_wndp; - } - curbp->b_mode &= ~MDVIEW; /* no longer read only mode */ - return TRUE; + if (restflag) /* don't allow this command if restricted */ + return resterr(); + if ((s = mlreply("Name: ", fname, sizeof fname)) == ABORT) + return s; + if (s == FALSE) + strcpy(curbp->b_fname, ""); + else + strcpy(curbp->b_fname, fname); + wp = wheadp; /* Update mode lines. */ + while (wp != NULL) { + if (wp->w_bufp == curbp) + wp->w_flag |= WFMODE; + wp = wp->w_wndp; + } + curbp->b_mode &= ~MDVIEW; /* no longer read only mode */ + return TRUE; } /* @@ -538,91 +633,89 @@ int filename(int f, int n) * buffer, Called by insert file command. Return the final * status of the read. */ -int ifile(char *fname) +int ifile( const char *fname) { - struct line *lp0; - struct line *lp1; - struct line *lp2; - int i; - struct buffer *bp; - int s; - int nbytes; - int nline; - char mesg[NSTRING]; + struct line *lp0; + struct line *lp1; + struct line *lp2; + struct buffer *bp; + int s; + int nbytes; + int nline; + char mesg[NSTRING]; - bp = curbp; /* Cheap. */ - bp->b_flag |= BFCHG; /* we have changed */ - bp->b_flag &= ~BFINVS; /* and are not temporary */ - if ((s = ffropen(fname)) == FIOERR) /* Hard file open. */ - goto out; - if (s == FIOFNF) { /* File not found. */ - mlwrite("(No such file)"); - return FALSE; - } - mlwrite("(Inserting file)"); + bp = curbp; /* Cheap. */ + bp->b_flag |= BFCHG; /* we have changed */ + bp->b_flag &= ~BFINVS; /* and are not temporary */ + if ((s = ffropen(fname)) == FIOERR) /* Hard file open. */ + goto out; + if (s == FIOFNF) { /* File not found. */ + logwrite("(No such file)"); + return FALSE; + } + logwrite("(Inserting file)"); -#if CRYPT - s = resetkey(); - if (s != TRUE) - return s; +#if CRYPT + s = resetkey(); + if (s != TRUE) + return s; #endif - /* back up a line and save the mark here */ - curwp->w_dotp = lback(curwp->w_dotp); - curwp->w_doto = 0; - curwp->w_markp = curwp->w_dotp; - curwp->w_marko = 0; + /* back up a line and save the mark here */ + curwp->w_dotp = lback(curwp->w_dotp); + curwp->w_doto = 0; + curwp->w_markp = curwp->w_dotp; + curwp->w_marko = 0; - nline = 0; - while ((s = ffgetline()) == FIOSUC) { - nbytes = strlen(fline); - if ((lp1 = lalloc(nbytes)) == NULL) { - s = FIOMEM; /* Keep message on the */ - break; /* display. */ - } - lp0 = curwp->w_dotp; /* line previous to insert */ - lp2 = lp0->l_fp; /* line after insert */ + nline = 0; + while ((s = ffgetline()) == FIOSUC) { + nbytes = fpayload ; + if ((lp1 = lalloc(nbytes)) == NULL) { + s = FIOMEM; /* Keep message on the */ + break; /* display. */ + } + lp0 = curwp->w_dotp; /* line previous to insert */ + lp2 = lp0->l_fp; /* line after insert */ - /* re-link new line between lp0 and lp2 */ - lp2->l_bp = lp1; - lp0->l_fp = lp1; - lp1->l_bp = lp0; - lp1->l_fp = lp2; + /* re-link new line between lp0 and lp2 */ + lp2->l_bp = lp1; + lp0->l_fp = lp1; + lp1->l_bp = lp0; + lp1->l_fp = lp2; - /* and advance and write out the current line */ - curwp->w_dotp = lp1; - for (i = 0; i < nbytes; ++i) - lputc(lp1, i, fline[i]); - ++nline; - } - ffclose(); /* Ignore errors. */ - curwp->w_markp = lforw(curwp->w_markp); - strcpy(mesg, "("); - if (s == FIOERR) { - strcat(mesg, "I/O ERROR, "); - curbp->b_flag |= BFTRUNC; - } - if (s == FIOMEM) { - strcat(mesg, "OUT OF MEMORY, "); - curbp->b_flag |= BFTRUNC; - } - sprintf(&mesg[strlen(mesg)], "Inserted %d line", nline); - if (nline > 1) - strcat(mesg, "s"); - strcat(mesg, ")"); - mlwrite(mesg); + /* and advance and write out the current line */ + curwp->w_dotp = lp1; + memcpy( lp1->l_text, fline, nbytes) ; + ++nline; + } + ffclose(); /* Ignore errors. */ + curwp->w_markp = lforw(curwp->w_markp); + strcpy(mesg, "("); + if (s == FIOERR) { + strcat(mesg, "I/O ERROR, "); + curbp->b_flag |= BFTRUNC; + } + if (s == FIOMEM) { + strcat(mesg, "OUT OF MEMORY, "); + curbp->b_flag |= BFTRUNC; + } + sprintf(&mesg[strlen(mesg)], "Inserted %d line", nline); + if (nline > 1) + strcat(mesg, "s"); + strcat(mesg, ")"); + logwrite(mesg); out: - /* advance to the next line and mark the window for changes */ - curwp->w_dotp = lforw(curwp->w_dotp); - curwp->w_flag |= WFHARD | WFMODE; + /* advance to the next line and mark the window for changes */ + curwp->w_dotp = lforw(curwp->w_dotp); + curwp->w_flag |= WFHARD | WFMODE; - /* copy window parameters back to the buffer structure */ - curbp->b_dotp = curwp->w_dotp; - curbp->b_doto = curwp->w_doto; - curbp->b_markp = curwp->w_markp; - curbp->b_marko = curwp->w_marko; + /* copy window parameters back to the buffer structure */ + curbp->b_dotp = curwp->w_dotp; + curbp->b_doto = curwp->w_doto; + curbp->b_markp = curwp->w_markp; + curbp->b_marko = curwp->w_marko; - if (s == FIOERR) /* False if error. */ - return FALSE; - return TRUE; + if (s == FIOERR) /* False if error. */ + return FALSE; + return TRUE; } diff --git a/file.h b/file.h new file mode 100644 index 0000000..53417ad --- /dev/null +++ b/file.h @@ -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 diff --git a/fileio.c b/fileio.c index bab566e..18812c3 100644 --- a/fileio.c +++ b/fileio.c @@ -1,76 +1,96 @@ -/* FILEIO.C +/* 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 * * The routines in this file read and write ASCII files from the disk. All of * the knowledge about files are here. * - * modified by Petri Kutvonen + * modified by Petri Kutvonen */ -#include -#include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include +#include +#include + +#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 boolean eofflag ; /* end-of-file flag */ -static FILE *ffp; /* File pointer, all functions. */ -static int eofflag; /* end-of-file flag */ /* * Open a file for reading. */ -int ffropen(char *fn) +fio_code ffropen( const char *fn) { - if ((ffp = fopen(fn, "r")) == NULL) - return FIOFNF; - eofflag = FALSE; - return FIOSUC; + if ((ffp = fopen(fn, "r")) == NULL) + return FIOFNF; + eofflag = FALSE; + ftype = FTYPE_NONE ; + return FIOSUC; } /* * Open a file for writing. Return TRUE if all is well, and FALSE on error * (cannot create). */ -int ffwopen(char *fn) +fio_code ffwopen( const char *fn) { #if VMS - int fd; + int fd; - if ((fd = creat(fn, 0666, "rfm=var", "rat=cr")) < 0 - || (ffp = fdopen(fd, "w")) == NULL) { + if ((fd = creat(fn, 0666, "rfm=var", "rat=cr")) < 0 + || (ffp = fdopen(fd, "w")) == NULL) #else - if ((ffp = fopen(fn, "w")) == NULL) { + if ((ffp = fopen(fn, "w")) == NULL) #endif - mlwrite("Cannot open file for writing"); - return FIOERR; - } - return FIOSUC; + return FIOERR; + + return FIOSUC; } /* * 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 */ - if (fline) { - free(fline); - fline = NULL; - } - eofflag = FALSE; + /* free this since we do not need it anymore */ + if (fline) { + free(fline); + fline = NULL; + } + eofflag = FALSE; + ftype = FTYPE_NONE ; -#if MSDOS & CTRLZ - fputc(26, ffp); /* add a ^Z at the end of the file */ +#if MSDOS & CTRLZ + fputc(26, ffp); /* add a ^Z at the end of the file */ #endif #if V7 | USG | BSD | (MSDOS & (MSC | TURBO)) - if (fclose(ffp) != FALSE) { - mlwrite("Error closing file"); - return FIOERR; - } - return FIOSUC; + if (fclose(ffp) != FALSE) + return FIOERR; #else - fclose(ffp); - return FIOSUC; + fclose(ffp); #endif + return FIOSUC; } /* @@ -78,34 +98,32 @@ int ffclose(void) * and the "nbuf" is its length, less the free newline. Return the status. * Check only at the newline. */ -int ffputline(char *buf, int nbuf) -{ - int i; -#if CRYPT - char c; /* character to translate */ +fio_code ffputline( char *buf, int nbuf, int dosflag) { +#if CRYPT + if( is_crypted) { + int i ; - if (cryptflag) { - for (i = 0; i < nbuf; ++i) { - c = buf[i] & 0xff; - myencrypt(&c, 1); - fputc(c, ffp); + for( i = 0 ; i < nbuf ; i++) { + char c ; + + c = buf[ i] ; + myencrypt( &c, 1) ; + fputc( c, ffp) ; } } 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 - fputc('\n', ffp); + fwrite( buf, 1, nbuf, ffp) ; + + if( dosflag) + fputc( '\r', ffp) ; - if (ferror(ffp)) { - mlwrite("Write I/O error"); - return FIOERR; - } + fputc( '\n', ffp) ; - return FIOSUC; + if( ferror( ffp)) + return FIOERR ; + + return FIOSUC ; } /* @@ -114,109 +132,72 @@ int ffputline(char *buf, int nbuf) * at the end of the file that don't have a newline present. Check for I/O * errors too. Return status. */ -int ffgetline(void) +fio_code ffgetline(void) { - int c; /* current character read */ - int i; /* current index into fline */ - char *tmpline; /* temp storage for expanding line */ + int c; /* current character read */ + int i; /* current index into fline */ - /* if we are at the end...return it */ - if (eofflag) - return FIOEOF; + /* if we are at the end...return it */ + if (eofflag) + return FIOEOF; - /* dump fline if it ended up too big */ - if (flen > NSTRING) { - free(fline); - fline = NULL; - } + /* dump fline if it ended up too big */ + if (flen > NSTRING) { + free(fline); + fline = NULL; + } - /* if we don't have an fline, allocate one */ - if (fline == NULL) - if ((fline = malloc(flen = NSTRING)) == NULL) - return FIOMEM; + /* if we don't have an fline, allocate one */ + if (fline == NULL) + if ((fline = malloc(flen = NSTRING)) == NULL) + return FIOMEM; - /* read the line in */ -#if PKCODE - if (!nullflag) { - if (fgets(fline, NSTRING, ffp) == (char *) NULL) { /* EOF ? */ - i = 0; - c = EOF; - } 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') { + /* read the line in */ + i = 0; + while ((c = fgetc(ffp)) != EOF && c != '\r' && c != '\n') { + fline[i++] = c; + /* if it's longer, get more room */ + if (i >= flen) { + char *tmpline; /* temp storage for expanding line */ + + fpayload = i ; + tmpline = malloc(flen + NSTRING) ; + if( tmpline == NULL) + return FIOMEM ; + + memcpy( tmpline, fline, flen) ; + flen += NSTRING; + free(fline); + fline = tmpline; + } + } + + fpayload = i ; + + /* test for any errors that may have occured */ + if (c == EOF) { + if( ferror( ffp)) + return FIOERR ; + + if (i != 0) + eofflag = TRUE; + else + 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 */ + fline[i] = 0; +#if CRYPT + if( is_crypted) + myencrypt( fline, fpayload); #endif -#if PKCODE - if (c) { -#endif - fline[i++] = c; - /* if it's longer, get more room */ - if (i >= flen) { - if ((tmpline = - malloc(flen + NSTRING)) == NULL) - return FIOMEM; - strncpy(tmpline, fline, flen); - flen += NSTRING; - free(fline); - fline = tmpline; - } -#if PKCODE - } - c = fgetc(ffp); -#endif - } - - /* test for any errors that may have occured */ - if (c == EOF) { - if (ferror(ffp)) { - mlwrite("File read error"); - return FIOERR; - } - - if (i != 0) - eofflag = TRUE; - else - return FIOEOF; - } - - /* terminate and decrypt the string */ - fline[i] = 0; -#if CRYPT - if (cryptflag) - myencrypt(fline, strlen(fline)); -#endif - return FIOSUC; -} - -/* - * does 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; + return FIOSUC; } diff --git a/fileio.h b/fileio.h new file mode 100644 index 0000000..3ee7ff2 --- /dev/null +++ b/fileio.h @@ -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 diff --git a/flook.c b/flook.c new file mode 100644 index 0000000..2971edb --- /dev/null +++ b/flook.c @@ -0,0 +1,152 @@ +/* flook.c -- implements flook.h */ +#include "flook.h" + + +#include +#include +#include + + +#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 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 */ +} + diff --git a/flook.h b/flook.h new file mode 100644 index 0000000..e56358c --- /dev/null +++ b/flook.h @@ -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) ; + diff --git a/globals.c b/globals.c deleted file mode 100644 index c2d4c37..0000000 --- a/globals.c +++ /dev/null @@ -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 diff --git a/ibmpc.c b/ibmpc.c index 577017d..7cdd3bc 100644 --- a/ibmpc.c +++ b/ibmpc.c @@ -12,7 +12,6 @@ #include #include "estruct.h" -#include "edef.h" #if IBMPC #if PKCODE diff --git a/input.c b/input.c index 28d6ada..e599cde 100644 --- a/input.c +++ b/input.c @@ -1,59 +1,86 @@ -/* input.c +/* input.c -- implements input.h */ + +#include "input.h" + +/* input.c * - * Various input routines + * Various input routines * - * written by Daniel Lawrence 5/9/86 - * modified by Petri Kutvonen + * written by Daniel Lawrence 5/9/86 + * modified by Petri Kutvonen */ #include +#include #include +#include "bind.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include "bindable.h" +#include "display.h" +#include "exec.h" +#include "names.h" +#include "terminal.h" #include "wrapper.h" -#if PKCODE +#if PKCODE #if MSDOS && TURBO -#include +#include #endif #endif -#if PKCODE && (UNIX || (MSDOS && TURBO)) -#define COMPLC 1 +#if PKCODE && (UNIX || (MSDOS && TURBO)) +#define COMPLC 1 #else -#define COMPLC 0 +#define COMPLC 0 #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 * ABORT. The ABORT status is returned if the user bumps out of the question * with a ^G. Used any time a confirmation is required. */ -int mlyesno(char *prompt) +int mlyesno( const char *prompt) { - char c; /* input character */ - char buf[NPAT]; /* prompt to user */ + char c; /* input character */ + char buf[ NSTRING] ; /* prompt to user */ - for (;;) { - /* build and prompt the user */ - strcpy(buf, prompt); - strcat(buf, " (y/n)? "); - mlwrite(buf); + for (;;) { + /* build and prompt the user */ + strcpy(buf, prompt); + strcat(buf, " (y/n)? "); + mlwrite(buf); - /* get the responce */ - c = tgetc(); + /* get the response */ + c = tgetc(); - if (c == ectoc(abortc)) /* Bail out! */ - return ABORT; + if (c == ectoc(abortc)) /* Bail out! */ + return ABORT; - if (c == 'y' || c == 'Y') - return TRUE; + if (c == 'y' || c == 'Y') + return TRUE; - if (c == 'n' || c == 'N') - return FALSE; - } + if (c == 'n' || c == 'N') + return FALSE; + } } /* @@ -64,40 +91,40 @@ int mlyesno(char *prompt) * 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); } /* * ectoc: - * expanded character to character - * collapse the CONTROL and SPEC flags back into an ascii code + * expanded character to character + * collapse the CONTROL and SPEC flags back into an ascii code */ int ectoc(int c) { - if (c & CONTROL) - c = c & ~(CONTROL | 0x40); - if (c & SPEC) - c = c & 255; - return c; + if (c & CONTROL) + c = c & ~(CONTROL | 0x40); + if (c & SPEC) + c = c & 255; + return c; } /* * ctoec: - * character to extended character - * pull out the CONTROL and SPEC prefixes (if possible) + * character to extended character + * pull out the CONTROL and SPEC prefixes (if possible) */ int ctoec(int c) { - if (c >= 0x00 && c <= 0x1F) - c = CONTROL | (c + '@'); - return c; + if (c >= 0x00 && c <= 0x1F) + c = CONTROL | (c + '@'); + return c; } /* @@ -107,615 +134,615 @@ int ctoec(int c) */ fn_t getname(void) { - int cpos; /* current column on screen output */ - int c; - char *sp; /* pointer to string for output */ - struct name_bind *ffp; /* first ptr to entry in name binding table */ - struct name_bind *cffp; /* current ptr to entry in name binding table */ - struct name_bind *lffp; /* last ptr to entry in name binding table */ - char buf[NSTRING]; /* buffer to hold tentative command name */ + int cpos; /* current column on screen output */ + int c; + char *sp; /* pointer to string for output */ + struct name_bind *ffp; /* first ptr to entry in name binding table */ + struct name_bind *cffp; /* current ptr to entry in name binding table */ + struct name_bind *lffp; /* last ptr to entry in name binding table */ + char buf[NSTRING]; /* buffer to hold tentative command name */ - /* starting at the beginning of the string buffer */ - cpos = 0; + /* starting at the beginning of the string buffer */ + cpos = 0; - /* if we are executing a command line get the next arg and match it */ - if (clexec) { - if (macarg(buf) != TRUE) - return NULL; - return fncmatch(&buf[0]); - } + /* if we are executing a command line get the next arg and match it */ + if (clexec) { + if (macarg(buf) != TRUE) + return NULL; + return fncmatch(&buf[0]); + } - /* build a name string from the keyboard */ - while (TRUE) { - c = tgetc(); + /* build a name string from the keyboard */ + while (TRUE) { + c = tgetc(); - /* if we are at the end, just match it */ - if (c == 0x0d) { - buf[cpos] = 0; + /* if we are at the end, just match it */ + if (c == 0x0d) { + buf[cpos] = 0; - /* and match it off */ - return fncmatch(&buf[0]); + /* and match it off */ + return fncmatch(&buf[0]); - } else if (c == ectoc(abortc)) { /* Bell, abort */ - ctrlg(FALSE, 0); - TTflush(); - return NULL; + } else if (c == ectoc(abortc)) { /* Bell, abort */ + ctrlg(FALSE, 0); + TTflush(); + return NULL; - } else if (c == 0x7F || c == 0x08) { /* rubout/erase */ - if (cpos != 0) { - TTputc('\b'); - TTputc(' '); - TTputc('\b'); - --ttcol; - --cpos; - TTflush(); - } + } else if (c == 0x7F || c == 0x08) { /* rubout/erase */ + if (cpos != 0) { + TTputc('\b'); + TTputc(' '); + TTputc('\b'); + --ttcol; + --cpos; + TTflush(); + } - } else if (c == 0x15) { /* C-U, kill */ - while (cpos != 0) { - TTputc('\b'); - TTputc(' '); - TTputc('\b'); - --cpos; - --ttcol; - } + } else if (c == 0x15) { /* C-U, kill */ + while (cpos != 0) { + TTputc('\b'); + TTputc(' '); + TTputc('\b'); + --cpos; + --ttcol; + } - TTflush(); + TTflush(); - } else if (c == ' ' || c == 0x1b || c == 0x09) { + } else if (c == ' ' || c == 0x1b || c == 0x09) { /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ - /* attempt a completion */ - buf[cpos] = 0; /* terminate it for us */ - ffp = &names[0]; /* scan for matches */ - while (ffp->n_func != NULL) { - if (strncmp(buf, ffp->n_name, strlen(buf)) - == 0) { - /* a possible match! More than one? */ - if ((ffp + 1)->n_func == NULL || - (strncmp - (buf, (ffp + 1)->n_name, - strlen(buf)) != 0)) { - /* no...we match, print it */ - sp = ffp->n_name + cpos; - while (*sp) - TTputc(*sp++); - TTflush(); - return ffp->n_func; - } else { + /* attempt a completion */ + buf[cpos] = 0; /* terminate it for us */ + ffp = &names[0]; /* scan for matches */ + while (ffp->n_func != NULL) { + if (strncmp(buf, ffp->n_name, strlen(buf)) + == 0) { + /* a possible match! More than one? */ + if ((ffp + 1)->n_func == NULL || + (strncmp + (buf, (ffp + 1)->n_name, + strlen(buf)) != 0)) { + /* no...we match, print it */ + sp = ffp->n_name + cpos; + while (*sp) + TTputc(*sp++); + TTflush(); + return ffp->n_func; + } else { /* << << << << << << << << << << << << << << << << << */ - /* try for a partial match against the list */ + /* try for a partial match against the list */ - /* first scan down until we no longer match the current input */ - lffp = (ffp + 1); - while ((lffp + - 1)->n_func != - NULL) { - if (strncmp - (buf, - (lffp + - 1)->n_name, - strlen(buf)) - != 0) - break; - ++lffp; - } + /* first scan down until we no longer match the current input */ + lffp = (ffp + 1); + while ((lffp + + 1)->n_func != + NULL) { + if (strncmp + (buf, + (lffp + + 1)->n_name, + strlen(buf)) + != 0) + break; + ++lffp; + } - /* and now, attempt to partial complete the string, char at a time */ - while (TRUE) { - /* add the next char in */ - buf[cpos] = - ffp-> - n_name[cpos]; + /* and now, attempt to partial complete the string, char at a time */ + while (TRUE) { + /* add the next char in */ + buf[cpos] = + ffp-> + n_name[cpos]; - /* scan through the candidates */ - cffp = ffp + 1; - while (cffp <= - lffp) { - if (cffp-> - n_name - [cpos] - != - buf - [cpos]) - goto onward; - ++cffp; - } + /* scan through the candidates */ + cffp = ffp + 1; + while (cffp <= + lffp) { + if (cffp-> + n_name + [cpos] + != + buf + [cpos]) + goto onward; + ++cffp; + } - /* add the character */ - TTputc(buf - [cpos++]); - } + /* add the character */ + TTputc(buf + [cpos++]); + } /* << << << << << << << << << << << << << << << << << */ - } - } - ++ffp; - } + } + } + ++ffp; + } - /* no match.....beep and onward */ - TTbeep(); - onward:; - TTflush(); + /* no match.....beep and onward */ + TTbeep(); + onward:; + TTflush(); /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ - } else { - if (cpos < NSTRING - 1 && c > ' ') { - buf[cpos++] = c; - TTputc(c); - } + } else { + if (cpos < NSTRING - 1 && c > ' ') { + buf[cpos++] = c; + TTputc(c); + } - ++ttcol; - TTflush(); - } - } + ++ttcol; + TTflush(); + } + } } -/* tgetc: Get a key from the terminal driver, resolve any keyboard - macro action */ +/* tgetc: Get a key from the terminal driver, resolve any keyboard + macro action */ int tgetc(void) { - int c; /* fetched character */ + int c; /* fetched character */ - /* if we are playing a keyboard macro back, */ - if (kbdmode == PLAY) { + /* if we are playing a keyboard macro back, */ + if (kbdmode == PLAY) { - /* if there is some left... */ - if (kbdptr < kbdend) - return (int) *kbdptr++; + /* if there is some left... */ + if (kbdptr < kbdend) + return (int) *kbdptr++; - /* at the end of last repitition? */ - if (--kbdrep < 1) { - kbdmode = STOP; -#if VISMAC == 0 - /* force a screen update after all is done */ - update(FALSE); + /* at the end of last repitition? */ + if (--kbdrep < 1) { + kbdmode = STOP; +#if VISMAC == 0 + /* force a screen update after all is done */ + update(FALSE); #endif - } else { + } else { - /* reset the macro to the begining for the next rep */ - kbdptr = &kbdm[0]; - return (int) *kbdptr++; - } - } + /* reset the macro to the begining for the next rep */ + kbdptr = &kbdm[0]; + return (int) *kbdptr++; + } + } - /* fetch a character from the terminal driver */ - c = TTgetc(); + /* fetch a character from the terminal driver */ + c = TTgetc(); - /* record it for $lastkey */ - lastkey = c; + /* record it for $lastkey */ + lastkey = c; - /* save it if we need to */ - if (kbdmode == RECORD) { - *kbdptr++ = c; - kbdend = kbdptr; + /* save it if we need to */ + if (kbdmode == RECORD) { + *kbdptr++ = c; + kbdend = kbdptr; - /* don't overrun the buffer */ - if (kbdptr == &kbdm[NKBDM - 1]) { - kbdmode = STOP; - TTbeep(); - } - } + /* don't overrun the buffer */ + if (kbdptr == &kbdm[NKBDM - 1]) { + kbdmode = STOP; + TTbeep(); + } + } - /* and finally give the char back */ - return c; + /* and finally give the char back */ + return c; } -/* GET1KEY: Get one keystroke. The only prefixs legal here - are the SPEC and CONTROL prefixes. - */ +/* GET1KEY: Get one keystroke. The only prefixs legal here + are the SPEC and CONTROL prefixes. + */ int get1key(void) { - int c; + int c; - /* get a keystroke */ - c = tgetc(); + /* get a keystroke */ + c = tgetc(); -#if MSDOS - if (c == 0) { /* Apply SPEC prefix */ - c = tgetc(); - if (c >= 0x00 && c <= 0x1F) /* control key? */ - c = CONTROL | (c + '@'); - return SPEC | c; - } +#if MSDOS + if (c == 0) { /* Apply SPEC prefix */ + c = tgetc(); + if (c >= 0x00 && c <= 0x1F) /* control key? */ + c = CONTROL | (c + '@'); + return SPEC | c; + } #endif - if (c >= 0x00 && c <= 0x1F) /* C0 control -> C- */ - c = CONTROL | (c + '@'); - return c; + if (c >= 0x00 && c <= 0x1F) /* C0 control -> C- */ + c = CONTROL | (c + '@'); + return c; } -/* GETCMD: Get a command from the keyboard. Process all applicable - prefix keys - */ +/* GETCMD: Get a command from the keyboard. Process all applicable + prefix keys + */ int getcmd(void) { - int c; /* fetched keystroke */ + int c; /* fetched keystroke */ #if VT220 - int d; /* second character P.K. */ - int cmask = 0; + int d; /* second character P.K. */ + int cmask = 0; #endif - /* get initial character */ - c = get1key(); + /* get initial character */ + c = get1key(); #if VT220 proc_metac: #endif - if (c == 128+27) /* CSI */ - goto handle_CSI; - /* process META prefix */ - if (c == (CONTROL | '[')) { - c = get1key(); + if (c == 128+27) /* CSI */ + goto handle_CSI; + /* process META prefix */ + if (c == (CONTROL | '[')) { + c = get1key(); #if VT220 - if (c == '[' || c == 'O') { /* CSI P.K. */ + if (c == '[' || c == 'O') { /* CSI P.K. */ handle_CSI: - c = get1key(); - if (c >= 'A' && c <= 'D') - return SPEC | c | cmask; - if (c >= 'E' && c <= 'z' && c != 'i' && c != 'c') - return SPEC | c | cmask; - d = get1key(); - if (d == '~') /* ESC [ n ~ P.K. */ - return SPEC | c | cmask; - switch (c) { /* ESC [ n n ~ P.K. */ - case '1': - c = d + 32; - break; - case '2': - c = d + 48; - break; - case '3': - c = d + 64; - break; - default: - c = '?'; - break; - } - if (d != '~') /* eat tilde P.K. */ - get1key(); - if (c == 'i') { /* DO key P.K. */ - c = ctlxc; - goto proc_ctlxc; - } else if (c == 'c') /* ESC key P.K. */ - c = get1key(); - else - return SPEC | c | cmask; - } + c = get1key(); + if (c >= 'A' && c <= 'D') + return SPEC | c | cmask; + if (c >= 'E' && c <= 'z' && c != 'i' && c != 'c') + return SPEC | c | cmask; + d = get1key(); + if (d == '~') /* ESC [ n ~ P.K. */ + return SPEC | c | cmask; + switch (c) { /* ESC [ n n ~ P.K. */ + case '1': + c = d + 32; + break; + case '2': + c = d + 48; + break; + case '3': + c = d + 64; + break; + default: + c = '?'; + break; + } + if (d != '~') /* eat tilde P.K. */ + get1key(); + if (c == 'i') { /* DO key P.K. */ + c = ctlxc; + goto proc_ctlxc; + } else if (c == 'c') /* ESC key P.K. */ + c = get1key(); + else + return SPEC | c | cmask; + } #endif #if VT220 - if (c == (CONTROL | '[')) { - cmask = META; - goto proc_metac; - } + if (c == (CONTROL | '[')) { + cmask = META; + goto proc_metac; + } #endif - if (islower(c)) /* Force to upper */ - c ^= DIFCASE; - if (c >= 0x00 && c <= 0x1F) /* control key */ - c = CONTROL | (c + '@'); - return META | c; - } -#if PKCODE - else if (c == metac) { - c = get1key(); + if (islower(c)) /* Force to upper */ + c ^= DIFCASE; + if (c >= 0x00 && c <= 0x1F) /* control key */ + c = CONTROL | (c + '@'); + return META | c; + } +#if PKCODE + else if (c == metac) { + c = get1key(); #if VT220 - if (c == (CONTROL | '[')) { - cmask = META; - goto proc_metac; - } + if (c == (CONTROL | '[')) { + cmask = META; + goto proc_metac; + } #endif - if (islower(c)) /* Force to upper */ - c ^= DIFCASE; - if (c >= 0x00 && c <= 0x1F) /* control key */ - c = CONTROL | (c + '@'); - return META | c; - } + if (islower(c)) /* Force to upper */ + c ^= DIFCASE; + if (c >= 0x00 && c <= 0x1F) /* control key */ + c = CONTROL | (c + '@'); + return META | c; + } #endif -#if VT220 +#if VT220 proc_ctlxc: #endif - /* process CTLX prefix */ - if (c == ctlxc) { - c = get1key(); + /* process CTLX prefix */ + if (c == ctlxc) { + c = get1key(); #if VT220 - if (c == (CONTROL | '[')) { - cmask = CTLX; - goto proc_metac; - } + if (c == (CONTROL | '[')) { + cmask = CTLX; + goto proc_metac; + } #endif - if (c >= 'a' && c <= 'z') /* Force to upper */ - c -= 0x20; - if (c >= 0x00 && c <= 0x1F) /* control key */ - c = CONTROL | (c + '@'); - return CTLX | c; - } + if (c >= 'a' && c <= 'z') /* Force to upper */ + c -= 0x20; + if (c >= 0x00 && c <= 0x1F) /* control key */ + c = CONTROL | (c + '@'); + return CTLX | c; + } - /* otherwise, just return it */ - return c; + /* otherwise, just return it */ + return c; } -/* A more generalized prompt/reply function allowing the caller - to specify the proper terminator. If the terminator is not - a return ('\n') it will echo as "" - */ -int getstring(char *prompt, char *buf, int nbuf, int eolchar) +/* A more generalized prompt/reply function allowing the caller + to specify the proper terminator. If the terminator is not + a return ('\n') it will echo as "" + */ +int getstring( const char *prompt, char *buf, int nbuf, int eolchar) { - int cpos; /* current character position in string */ - int c; - int quotef; /* are we quoting the next char? */ -#if COMPLC - int ffile, ocpos, nskip = 0, didtry = 0; + int cpos; /* current character position in string */ + int c; + boolean quotef ; /* are we quoting the next char? */ +#if COMPLC + int ffile, ocpos, nskip = 0, didtry = 0; #if MSDOS - struct ffblk ffblk; - char *fcp; + struct ffblk ffblk; + char *fcp; #endif -#if UNIX - static char tmp[] = "/tmp/meXXXXXX"; - FILE *tmpf = NULL; +#if UNIX + static char tmp[] = "/tmp/meXXXXXX"; + FILE *tmpf = NULL; #endif - ffile = (strcmp(prompt, "Find file: ") == 0 - || strcmp(prompt, "View file: ") == 0 - || strcmp(prompt, "Insert file: ") == 0 - || strcmp(prompt, "Write file: ") == 0 - || strcmp(prompt, "Read file: ") == 0 - || strcmp(prompt, "File to execute: ") == 0); + ffile = (strcmp(prompt, "Find file: ") == 0 + || strcmp(prompt, "View file: ") == 0 + || strcmp(prompt, "Insert file: ") == 0 + || strcmp(prompt, "Write file: ") == 0 + || strcmp(prompt, "Read file: ") == 0 + || strcmp(prompt, "File to execute: ") == 0); #endif - cpos = 0; - quotef = FALSE; + cpos = 0; + quotef = FALSE; - /* prompt the user for the input string */ - mlwrite(prompt); + /* prompt the user for the input string */ + mlwrite(prompt); - for (;;) { -#if COMPLC - if (!didtry) - nskip = -1; - didtry = 0; + for (;;) { +#if COMPLC + if (!didtry) + nskip = -1; + didtry = 0; #endif - /* get a character from the user */ - c = get1key(); + /* get a character from the user */ + c = get1key(); - /* If it is a , change it to a */ -#if PKCODE - if (c == (CONTROL | 0x4d) && !quotef) + /* If it is a , change it to a */ +#if PKCODE + if (c == (CONTROL | 0x4d) && !quotef) #else - if (c == (CONTROL | 0x4d)) + if (c == (CONTROL | 0x4d)) #endif - c = CONTROL | 0x40 | '\n'; + c = CONTROL | 0x40 | '\n'; - /* if they hit the line terminate, wrap it up */ - if (c == eolchar && quotef == FALSE) { - buf[cpos++] = 0; + /* if they hit the line terminate, wrap it up */ + if (c == eolchar && quotef == FALSE) { + buf[cpos++] = 0; - /* clear the message line */ - mlwrite(""); - TTflush(); + /* clear the message line */ + mlwrite(""); + TTflush(); - /* if we default the buffer, return FALSE */ - if (buf[0] == 0) - return FALSE; + /* if we default the buffer, return FALSE */ + if (buf[0] == 0) + return FALSE; - return TRUE; - } + return TRUE; + } - /* change from command form back to character form */ - c = ectoc(c); + /* change from command form back to character form */ + c = ectoc(c); - if (c == ectoc(abortc) && quotef == FALSE) { - /* Abort the input? */ - ctrlg(FALSE, 0); - TTflush(); - return ABORT; - } else if ((c == 0x7F || c == 0x08) && quotef == FALSE) { - /* rubout/erase */ - if (cpos != 0) { - outstring("\b \b"); - --ttcol; + if (c == ectoc(abortc) && quotef == FALSE) { + /* Abort the input? */ + ctrlg(FALSE, 0); + TTflush(); + return ABORT; + } else if ((c == 0x7F || c == 0x08) && quotef == FALSE) { + /* rubout/erase */ + if (cpos != 0) { + outstring("\b \b"); + --ttcol; - if (buf[--cpos] < 0x20) { - outstring("\b \b"); - --ttcol; - } - if (buf[cpos] == '\n') { - outstring("\b\b \b\b"); - ttcol -= 2; - } + if (buf[--cpos] < 0x20) { + outstring("\b \b"); + --ttcol; + } + if (buf[cpos] == '\n') { + outstring("\b\b \b\b"); + ttcol -= 2; + } - TTflush(); - } + TTflush(); + } - } else if (c == 0x15 && quotef == FALSE) { - /* C-U, kill */ - while (cpos != 0) { - outstring("\b \b"); - --ttcol; + } else if (c == 0x15 && quotef == FALSE) { + /* C-U, kill */ + while (cpos != 0) { + outstring("\b \b"); + --ttcol; - if (buf[--cpos] < 0x20) { - outstring("\b \b"); - --ttcol; - } - if (buf[cpos] == '\n') { - outstring("\b\b \b\b"); - ttcol -= 2; - } - } - TTflush(); + if (buf[--cpos] < 0x20) { + outstring("\b \b"); + --ttcol; + } + if (buf[cpos] == '\n') { + outstring("\b\b \b\b"); + ttcol -= 2; + } + } + TTflush(); -#if COMPLC - } else if ((c == 0x09 || c == ' ') && quotef == FALSE - && ffile) { - /* TAB, complete file name */ - char ffbuf[255]; -#if MSDOS - char sffbuf[128]; - int lsav = -1; +#if COMPLC + } else if ((c == 0x09 || c == ' ') && quotef == FALSE + && ffile) { + /* TAB, complete file name */ + char ffbuf[255]; +#if MSDOS + char sffbuf[128]; + int lsav = -1; #endif - int n, iswild = 0; + int n, iswild = 0; - didtry = 1; - ocpos = cpos; - while (cpos != 0) { - outstring("\b \b"); - --ttcol; + didtry = 1; + ocpos = cpos; + while (cpos != 0) { + outstring("\b \b"); + --ttcol; - if (buf[--cpos] < 0x20) { - outstring("\b \b"); - --ttcol; - } - if (buf[cpos] == '\n') { - outstring("\b\b \b\b"); - ttcol -= 2; - } - if (buf[cpos] == '*' || buf[cpos] == '?') - iswild = 1; -#if MSDOS - if (lsav < 0 && (buf[cpos] == '\\' || - buf[cpos] == '/' || - buf[cpos] == ':' - && cpos == 1)) - lsav = cpos; + if (buf[--cpos] < 0x20) { + outstring("\b \b"); + --ttcol; + } + if (buf[cpos] == '\n') { + outstring("\b\b \b\b"); + ttcol -= 2; + } + if (buf[cpos] == '*' || buf[cpos] == '?') + iswild = 1; +#if MSDOS + if (lsav < 0 && (buf[cpos] == '\\' || + buf[cpos] == '/' || + buf[cpos] == ':' + && cpos == 1)) + lsav = cpos; #endif - } - TTflush(); - if (nskip < 0) { - buf[ocpos] = 0; -#if UNIX - if (tmpf != NULL) - fclose(tmpf); - strcpy(tmp, "/tmp/meXXXXXX"); - strcpy(ffbuf, "echo "); - strcat(ffbuf, buf); - if (!iswild) - strcat(ffbuf, "*"); - strcat(ffbuf, " >"); - xmkstemp(tmp); - strcat(ffbuf, tmp); - strcat(ffbuf, " 2>&1"); - system(ffbuf); - tmpf = fopen(tmp, "r"); + } + TTflush(); + if (nskip < 0) { + buf[ocpos] = 0; +#if UNIX + if (tmpf != NULL) + fclose(tmpf); + strcpy(tmp, "/tmp/meXXXXXX"); + strcpy(ffbuf, "echo "); + strcat(ffbuf, buf); + if (!iswild) + strcat(ffbuf, "*"); + strcat(ffbuf, " >"); + xmkstemp(tmp); + strcat(ffbuf, tmp); + strcat(ffbuf, " 2>&1"); + system(ffbuf); + tmpf = fopen(tmp, "r"); #endif -#if MSDOS - strcpy(sffbuf, buf); - if (!iswild) - strcat(sffbuf, "*.*"); +#if MSDOS + strcpy(sffbuf, buf); + if (!iswild) + strcat(sffbuf, "*.*"); #endif - nskip = 0; - } -#if UNIX - c = ' '; - for (n = nskip; n > 0; n--) - while ((c = getc(tmpf)) != EOF - && c != ' '); + nskip = 0; + } +#if UNIX + c = ' '; + for (n = nskip; n > 0; n--) + while ((c = getc(tmpf)) != EOF + && c != ' '); #endif -#if MSDOS - if (nskip == 0) { - strcpy(ffbuf, sffbuf); - c = findfirst(ffbuf, &ffblk, - FA_DIREC) ? '*' : ' '; - } else if (nskip > 0) - c = findnext(&ffblk) ? 0 : ' '; +#if MSDOS + if (nskip == 0) { + strcpy(ffbuf, sffbuf); + c = findfirst(ffbuf, &ffblk, + FA_DIREC) ? '*' : ' '; + } else if (nskip > 0) + c = findnext(&ffblk) ? 0 : ' '; #endif - nskip++; + nskip++; - if (c != ' ') { - TTbeep(); - nskip = 0; - } -#if UNIX - while ((c = getc(tmpf)) != EOF && c != '\n' - && c != ' ' && c != '*') + if (c != ' ') { + TTbeep(); + nskip = 0; + } +#if UNIX + while ((c = getc(tmpf)) != EOF && c != '\n' + && c != ' ' && c != '*') #endif -#if MSDOS - if (c == '*') - fcp = sffbuf; - else { - strncpy(buf, sffbuf, lsav + 1); - cpos = lsav + 1; - fcp = ffblk.ff_name; - } - while (c != 0 && (c = *fcp++) != 0 && c != '*') +#if MSDOS + if (c == '*') + fcp = sffbuf; + else { + strncpy(buf, sffbuf, lsav + 1); + cpos = lsav + 1; + fcp = ffblk.ff_name; + } + while (c != 0 && (c = *fcp++) != 0 && c != '*') #endif - { - if (cpos < nbuf - 1) - buf[cpos++] = c; - } -#if UNIX - if (c == '*') - TTbeep(); + { + if (cpos < nbuf - 1) + buf[cpos++] = c; + } +#if UNIX + if (c == '*') + TTbeep(); #endif - for (n = 0; n < cpos; n++) { - c = buf[n]; - if ((c < ' ') && (c != '\n')) { - outstring("^"); - ++ttcol; - c ^= 0x40; - } + for (n = 0; n < cpos; n++) { + c = buf[n]; + if ((c < ' ') && (c != '\n')) { + outstring("^"); + ++ttcol; + c ^= 0x40; + } - if (c != '\n') { - if (disinp) - TTputc(c); - } else { /* put out for */ - outstring(""); - ttcol += 3; - } - ++ttcol; - } - TTflush(); -#if UNIX - rewind(tmpf); - unlink(tmp); + if (c != '\n') { + if (disinp) + TTputc(c); + } else { /* put out for */ + outstring(""); + ttcol += 3; + } + ++ttcol; + } + TTflush(); +#if UNIX + rewind(tmpf); + unlink(tmp); #endif #endif - } else if ((c == quotec || c == 0x16) && quotef == FALSE) { - quotef = TRUE; - } else { - quotef = FALSE; - if (cpos < nbuf - 1) { - buf[cpos++] = c; + } else if ((c == quotec || c == 0x16) && quotef == FALSE) { + quotef = TRUE; + } else { + quotef = FALSE; + if (cpos < nbuf - 1) { + buf[cpos++] = c; - if ((c < ' ') && (c != '\n')) { - outstring("^"); - ++ttcol; - c ^= 0x40; - } + if ((c < ' ') && (c != '\n')) { + outstring("^"); + ++ttcol; + c ^= 0x40; + } - if (c != '\n') { - if (disinp) - TTputc(c); - } else { /* put out for */ - outstring(""); - ttcol += 3; - } - ++ttcol; - TTflush(); - } - } - } + if (c != '\n') { + if (disinp) + TTputc(c); + } else { /* put out for */ + outstring(""); + ttcol += 3; + } + ++ttcol; + TTflush(); + } + } + } } /* * output a string of characters * - * char *s; string to output + * char *s; string to output */ void outstring(char *s) { - if (disinp) - while (*s) - TTputc(*s++); + if (disinp) + while (*s) + TTputc(*s++); } /* * output a string of output characters * - * char *s; string to output + * char *s; string to output */ void ostring(char *s) { - if (discmd) - while (*s) - TTputc(*s++); + if (discmd) + while (*s) + TTputc(*s++); } diff --git a/input.h b/input.h new file mode 100644 index 0000000..98befd1 --- /dev/null +++ b/input.h @@ -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 diff --git a/isearch.c b/isearch.c index dcc408b..258d8ce 100644 --- a/isearch.c +++ b/isearch.c @@ -1,3 +1,5 @@ +#include "isearch.h" + /* isearch.c * * The functions in this file implement commands that perform incremental @@ -23,11 +25,52 @@ */ #include +#include +#include "basic.h" +#include "buffer.h" +#include "display.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include "exec.h" +#include "input.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 @@ -138,14 +181,14 @@ int fisearch(int f, int n) * 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 col; /* prompt column */ int cpos; /* character number in search string */ int c; /* current input character */ 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 */ int curoff; /* Current offset on entry */ 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_offset = 0; /* Start at the beginning of the buff */ 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 */ curoff = curwp->w_doto; /* Save the current offset */ 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_doto = curoff; /* and the offset */ 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 */ 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 */ 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"); return TRUE; /* Return an error */ } @@ -278,7 +322,7 @@ int isearch(int f, int n) * char *patrn; The entire search string (incl chr) * 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 */ 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 * 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 */ @@ -351,7 +395,7 @@ int scanmore(char *patrn, int dir) /* search forward or back for a pattern * * 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 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. */ -int promptpattern(char *prompt) +static int promptpattern(char *prompt) { 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 * next character. */ -int get_char(void) +static int get_char(void) { 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: */ -int uneat(void) +static int uneat(void) { int c; @@ -491,7 +535,7 @@ int uneat(void) 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 */ return /*(NULL) */ ; /* Don't do it again */ diff --git a/isearch.h b/isearch.h new file mode 100644 index 0000000..871ae9c --- /dev/null +++ b/isearch.h @@ -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 diff --git a/line.c b/line.c index 172c9cd..9bfcc83 100644 --- a/line.c +++ b/line.c @@ -15,15 +15,140 @@ #include "line.h" +#include #include +#include +#include +#include "buffer.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" -#include "utf8.h" +#include "log.h" +#include "window.h" + + +int tabmask = 0x07 ; /* tabulator mask */ #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 * 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. */ size = BLOCK_SIZE; /* Line is for type-in. */ if ((lp = (struct line *)malloc(sizeof(struct line) + size)) == NULL) { - mlwrite("(OUT OF MEMORY)"); + logwrite( "(OUT OF MEMORY)") ; return NULL; } lp->l_size = size; @@ -132,24 +257,23 @@ int insspace(int f, int n) * linstr -- Insert a string at the current point */ -int linstr(char *instr) -{ - int status = TRUE; - char tmpc; +int linstr( char *instr) { + int status = TRUE ; - if (instr != NULL) - while ((tmpc = *instr) && status == TRUE) { + if( instr != NULL) { + char tmpc ; + + while( (tmpc = *instr++)) { status = - (tmpc == '\n' ? lnewline() : linsert(1, tmpc)); + (tmpc == '\n' ? lnewline() : linsert( 1, tmpc)) ; /* Insertion error? */ - if (status != TRUE) { - mlwrite("%%Out of memory while inserting"); - break; - } - instr++; + if( status != TRUE) + return logger( status, FALSE, "%%Out of memory while inserting") ; } - return status; + } + + return status ; } /* @@ -173,13 +297,16 @@ static int linsert_byte(int n, int c) int i; struct window *wp; + assert( (curbp->b_mode & MDVIEW) == 0) ; +#if 0 if (curbp->b_mode & MDVIEW) /* don't allow this command if */ return rdonly(); /* we are in read only mode */ +#endif lchange(WFEDIT); lp1 = curwp->w_dotp; /* Current line */ if (lp1 == curbp->b_linep) { /* At the end: special */ if (curwp->w_doto != 0) { - mlwrite("bug: linsert"); + logwrite( "bug: linsert") ; return FALSE; } 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) { 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) return linsert_byte(n, (unsigned char) utf8[0]); 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 lowrite(int c) +static int lowrite(int c) { if (curwp->w_doto < curwp->w_dotp->l_used && (lgetc(curwp->w_dotp, curwp->w_doto) != '\t' || @@ -275,25 +407,23 @@ int lowrite(int c) /* * lover -- Overwrite a string at the current point */ -int lover(char *ostr) -{ - int status = TRUE; - char tmpc; +int lover( char *ostr) { + int status = TRUE ; - if (ostr != NULL) - while ((tmpc = *ostr) && status == TRUE) { + if (ostr != NULL) { + char tmpc ; + + while( (tmpc = *ostr++)) { status = (tmpc == '\n' ? lnewline() : lowrite(tmpc)); /* Insertion error? */ - if (status != TRUE) { - mlwrite - ("%%Out of memory while overwriting"); - break; - } - ostr++; + if( status != TRUE) + return logger( status, FALSE, "%%Out of memory while overwriting") ; } - return status; + } + + return status ; } /* @@ -481,29 +611,6 @@ char *getctext(void) 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 * 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 * "ldelete" only. */ -int ldelnewline(void) +static int ldelnewline(void) { char *cp1; char *cp2; @@ -522,8 +629,11 @@ int ldelnewline(void) struct line *lp3; struct window *wp; + assert( (curbp->b_mode & MDVIEW) == 0) ; +#if 0 if (curbp->b_mode & MDVIEW) /* don't allow this command if */ return rdonly(); /* we are in read only mode */ +#endif lp1 = curwp->w_dotp; lp2 = lp1->l_fp; if (lp2 == curbp->b_linep) { /* At the buffer end. */ @@ -614,6 +724,11 @@ void kdelete(void) /* and reset all the kill buffer pointers */ kbufh = kbufp = NULL; kused = KBLOCK; + klen = 0 ; + if( value != NULL) { + free( value) ; + value = NULL ; + } } } @@ -631,8 +746,11 @@ int kinsert(int c) if (kused >= KBLOCK) { if ((nchunk = (struct kill *)malloc(sizeof(struct kill))) == NULL) return FALSE; - if (kbufh == NULL) /* set head ptr if first time */ + if( kbufh == NULL) { /* set head ptr if first time */ kbufh = nchunk; + klen = 0 ; + } + if (kbufp != NULL) /* point the current to this new one */ kbufp->d_next = nchunk; kbufp = nchunk; @@ -642,6 +760,7 @@ int kinsert(int c) /* and now insert the character */ kbufp->d_chunk[kused++] = c; + klen += 1 ; return TRUE; } diff --git a/line.h b/line.h index 7b07a3b..a01730b 100644 --- a/line.h +++ b/line.h @@ -3,6 +3,8 @@ #include "utf8.h" +#define NLINE 256 /* # of bytes, input line */ + /* * 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 @@ -25,23 +27,27 @@ struct line { #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c)) #define llength(lp) ((lp)->l_used) -extern void lfree(struct line *lp); -extern void lchange(int flag); -extern int insspace(int f, int n); -extern int linstr(char *instr); -extern int linsert(int n, int c); -extern int lowrite(int c); -extern int lover(char *ostr); -extern int lnewline(void); -extern int ldelete(long n, int kflag); -extern int ldelchar(long n, int kflag); -extern int lgetchar(unicode_t *); -extern char *getctext(void); -extern int putctext(char *iline); -extern int ldelnewline(void); -extern void kdelete(void); -extern int kinsert(int c); -extern int yank(int f, int n); -extern struct line *lalloc(int); /* Allocate a line. */ +extern int tabmask ; + +char *getkill( void) ; + +int backchar( int f, int n) ; +int forwchar( int f, int n) ; + +void lfree( struct line *lp) ; +void lchange( int flag) ; +int insspace( int f, int n) ; +int linstr( char *instr) ; +int linsert( int n, int c) ; +int lover( char *ostr) ; +int lnewline( void) ; +int ldelete( long n, int kflag) ; +int ldelchar( long n, int kflag) ; +int lgetchar( unicode_t *) ; +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_ */ diff --git a/lock.c b/lock.c index dce53a7..d012ce3 100644 --- a/lock.c +++ b/lock.c @@ -1,3 +1,6 @@ +#include "estruct.h" +#include "lock.h" + /* LOCK.C * * File locking command routines @@ -5,24 +8,35 @@ * written by Daniel Lawrence */ -#include -#include "estruct.h" -#include "edef.h" -#include "efunc.h" - #if BSD | SVR4 +#include +#include +#include + +#include "defines.h" +#include "display.h" +#include "input.h" +#include "retcode.h" + +#if (FILOCK && BSD) || SVR4 +#include "pklock.h" +#endif + #include -static char *lname[NLOCKS]; /* names of all locked files */ -static int numlocks; /* # of current locks active */ +#define NLOCKS 100 /* max # of file locks active */ +static char *lname[ NLOCKS] ; /* names of all locked files */ +static int numlocks ; /* # of current locks active */ + +static void lckerror(char *errstr) ; /* * lockchk: * 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 status; /* return status */ @@ -34,7 +48,7 @@ int lockchk(char *fname) return TRUE; /* if we have a full locking table, bitch and leave */ - if (numlocks == NLOCKS) { + if( numlocks >= NLOCKS) { mlwrite("LOCK ERROR: Lock table full"); return ABORT; } @@ -88,9 +102,9 @@ int lockrel(void) * FALSE = file was locked and overridden * 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 */ int status; /* return status */ @@ -123,9 +137,9 @@ int lock(char *fname) * Unlock a file * 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 */ diff --git a/lock.h b/lock.h new file mode 100644 index 0000000..aa04d75 --- /dev/null +++ b/lock.h @@ -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 diff --git a/log.c b/log.c new file mode 100644 index 0000000..49d0189 --- /dev/null +++ b/log.c @@ -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)"); +} + + diff --git a/log.h b/log.h new file mode 100644 index 0000000..4441fad --- /dev/null +++ b/log.h @@ -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 *, ...) ; + diff --git a/main.c b/main.c index 08f2f19..f576afd 100644 --- a/main.c +++ b/main.c @@ -1,3 +1,7 @@ +/* main.c -- */ + +#define CLRMSG 0 /* space clears the message line with no insert */ + /* * main.c @@ -49,18 +53,38 @@ * * 4.0 Petri Kutvonen, 1-Sep-91 * + * This modified version is now called uEmacs/rf. + * + * 4.1 Renaud Fivet, 1-May-13 + * */ #include +#include +#include -/* Make global definitions not external. */ -#define maindef +#include "estruct.h" /* Global structures and defines. */ +#if UNIX +#include +#endif -#include "estruct.h" /* Global structures and defines. */ -#include "edef.h" /* Global definitions. */ -#include "efunc.h" /* Function declarations and name table. */ -#include "ebind.h" /* Default key bindings. */ +#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 "window.h" /* For MSDOS, increase the default stack space. */ #if MSDOS & TURBO @@ -71,34 +95,47 @@ extern unsigned _stklen = 32766; #endif #endif -#if VMS -#include -#define GOOD (SS$_NORMAL) -#endif - -#ifndef GOOD -#define GOOD 0 -#endif - #if UNIX -#include -static void emergencyexit(int); -#ifdef SIGWINCH -extern void sizesignal(int); -#endif -#endif - -void usage(int status) +static void emergencyexit(int signr) { - printf("Usage: %s filename\n", PROGRAM_NAME); - printf(" or: %s [options]\n\n", PROGRAM_NAME); - fputs(" + start at the end of file\n", stdout); - fputs(" + start at line \n", stdout); - fputs(" -g[G] go to line \n", stdout); - fputs(" --help display this help and exit\n", stdout); - fputs(" --version output version information and exit\n", stdout); + quickexit(FALSE, 0); + quit(TRUE, 0); +} +#endif - 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" + " + start at line \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 go to line \n" +#if CRYPT + " -k|K use code key\n" +#endif + " -r|R restrictive use\n" + " -s|S 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) @@ -119,10 +156,10 @@ int main(int argc, char **argv) int searchflag; /* Do we need to search at start? */ int saveflag; /* temp store for lastflag */ 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 int cryptflag; /* encrypting on the way in? */ - char ekey[NPAT]; /* startup encryption key */ + ekey_t ekey ; /* startup encryption key */ #endif int newc; @@ -139,18 +176,22 @@ int main(int argc, char **argv) signal(SIGWINCH, sizesignal); #endif #endif - if (argc == 2) { - if (strcmp(argv[1], "--help") == 0) { - usage(EXIT_FAILURE); + if( argc == 2) { + if( strcmp( argv[ 1], "--help") == 0) { + usage() ; + exit( EXIT_SUCCESS) ; } - if (strcmp(argv[1], "--version") == 0) { - version(); - exit(EXIT_SUCCESS); + + if( strcmp( argv[ 1], "--version") == 0) { + version() ; + exit( EXIT_SUCCESS) ; } } /* Initialize the editor. */ vtinit(); /* Display */ + logwrite = mlwrite ; + logger = mllog ; edinit("main"); /* Buffers, windows */ varinit(); /* user variables */ @@ -193,13 +234,8 @@ int main(int argc, char **argv) case 'k': /* -k for code key */ case 'K': cryptflag = TRUE; - strcpy(ekey, &argv[carg][2]); - break; -#endif -#if PKCODE - case 'n': /* -n accept null chars */ - case 'N': - nullflag = TRUE; + strncpy( ekey, &argv[ carg][ 2], sizeof ekey - 1) ; + ekey[ sizeof ekey - 1] = 0 ; break; #endif case 'r': /* -r restrictive use */ @@ -209,7 +245,8 @@ int main(int argc, char **argv) case 's': /* -s for initial search string */ case 'S': searchflag = TRUE; - strncpy(pat, &argv[carg][2], NPAT); + strncpy( pat, &argv[ carg][ 2], sizeof pat - 1) ; + pat[ sizeof pat -1] = 0 ; break; case 'v': /* -v for View File */ case 'V': @@ -237,7 +274,8 @@ int main(int argc, char **argv) /* set this to inactive */ 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; if (firstfile) { firstbp = bp; @@ -250,16 +288,17 @@ int main(int argc, char **argv) #if CRYPT if (cryptflag) { bp->b_mode |= MDCRYPT; - myencrypt((char *) NULL, 0); - myencrypt(ekey, strlen(ekey)); - strncpy(bp->b_key, ekey, NPAT); + strncpy( bp->b_key, ekey, sizeof ekey) ; + cryptbufferkey( bp) ; } #endif } } #if UNIX +#ifdef SIGHUP signal(SIGHUP, emergencyexit); +#endif signal(SIGTERM, emergencyexit); #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 * 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 window *wp; @@ -464,279 +503,6 @@ void edinit(char *bname) wp->w_flag = WFMODE | WFHARD; /* Full. */ } -/* - * This is the general command execution routine. It handles the fake binding - * of all the keys to "self-insert". It also clears out the "thisflag" word, - * and arranges to move it to the "lastflag", so that the next command can - * look at it. Return the status of command. - */ -int execute(int c, int f, int n) -{ - int status; - fn_t execfunc; - - /* if the keystroke is a bound function...do it */ - execfunc = getbind(c); - if (execfunc != NULL) { - thisflag = 0; - status = (*execfunc) (f, n); - lastflag = thisflag; - return status; - } - - /* - * If a space was typed, fill column is defined, the argument is non- - * negative, wrap mode is enabled, and we are now past fill column, - * and we are not read-only, perform word wrap. - */ - if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 && - n >= 0 && getccol(FALSE) > fillcol && - (curwp->w_bufp->b_mode & MDVIEW) == FALSE) - execute(META | SPEC | 'W', FALSE, 1); - -#if PKCODE - if ((c >= 0x20 && c <= 0x7E) /* Self inserting. */ -#if IBMPC - || (c >= 0x80 && c <= 0xFE)) { -#else -#if VMS || BSD || USG /* 8BIT P.K. */ - || (c >= 0xA0 && c <= 0x10FFFF)) { -#else - ) { -#endif -#endif -#else - if ((c >= 0x20 && c <= 0xFF)) { /* Self inserting. */ -#endif - if (n <= 0) { /* Fenceposts. */ - lastflag = 0; - return n < 0 ? FALSE : TRUE; - } - thisflag = 0; /* For the future. */ - - /* if we are in overwrite mode, not at eol, - and next char is not a tab or we are at a tab stop, - delete a char forword */ - if (curwp->w_bufp->b_mode & MDOVER && - curwp->w_doto < curwp->w_dotp->l_used && - (lgetc(curwp->w_dotp, curwp->w_doto) != '\t' || - (curwp->w_doto) % 8 == 7)) - ldelchar(1, FALSE); - - /* do the appropriate insertion */ - if (c == '}' && (curbp->b_mode & MDCMOD) != 0) - status = insbrace(n, c); - else if (c == '#' && (curbp->b_mode & MDCMOD) != 0) - status = inspound(); - else - status = linsert(n, c); - -#if CFENCE - /* check for CMODE fence matching */ - if ((c == '}' || c == ')' || c == ']') && - (curbp->b_mode & MDCMOD) != 0) - fmatch(c); -#endif - - /* check auto-save mode */ - if (curbp->b_mode & MDASAVE) - if (--gacount == 0) { - /* and save the file if needed */ - upscreen(FALSE, 0); - filesave(FALSE, 0); - gacount = gasave; - } - - lastflag = thisflag; - return status; - } - TTbeep(); - mlwrite("(Key not bound)"); /* complain */ - lastflag = 0; /* Fake last flags. */ - return FALSE; -} - -/* - * Fancy quit command, as implemented by Norm. If the any buffer has - * changed do a write on that buffer and exit emacs, otherwise simply exit. - */ -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 ****/ #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. */ +static void dspram( void) ; + #undef malloc #undef free - +#if 0 char *allocate(nbytes) /* allocate nbytes and track */ unsigned nbytes; /* # of bytes to allocate */ - +#endif +void *allocate( size_t nbytes) { char *mp; /* ptr returned from malloc */ - char *malloc(); +/* char *malloc(); */ mp = malloc(nbytes); if (mp) { @@ -771,10 +540,12 @@ unsigned nbytes; /* # of bytes to allocate */ return mp; } +#if 0 release(mp) /* release malloced memory and track */ char *mp; /* chunk of RAM to release */ - +#endif +void release( void *mp) { unsigned *lp; /* ptr to the long containing the block size */ @@ -790,7 +561,7 @@ char *mp; /* chunk of RAM to release */ } #if RAMSHOW -dspram() +static void dspram( void) { /* display the amount of RAM currently malloced */ char mbuf[20]; char *sp; diff --git a/mingw32.c b/mingw32.c new file mode 100644 index 0000000..029f67e --- /dev/null +++ b/mingw32.c @@ -0,0 +1,191 @@ +#ifdef MINGW32 +#include "termio.h" +#include "terminal.h" + +#include +#include +#include +#include +#include + +#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 diff --git a/names.c b/names.c index 4ee6228..8736721 100644 --- a/names.c +++ b/names.c @@ -1,14 +1,31 @@ +/* names.c -- implements names.h */ +#include "names.h" + /* Name to function binding table. * * 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. */ -#include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include + +#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 "region.h" +#include "random.h" +#include "search.h" +#include "spawn.h" +#include "window.h" +#include "word.h" struct name_bind names[] = { {"abort-command", ctrlg}, diff --git a/names.h b/names.h new file mode 100644 index 0000000..700b304 --- /dev/null +++ b/names.h @@ -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 */ + diff --git a/pklock.c b/pklock.c index dc30b76..4ce1b34 100644 --- a/pklock.c +++ b/pklock.c @@ -1,12 +1,12 @@ +/* pklock.c -- implements pklock.h */ +#include "estruct.h" +#include "pklock.h" + /* PKLOCK.C * * locking routines as modified by Petri Kutvonen */ -#include "estruct.h" -#include "edef.h" -#include "efunc.h" - #if (FILOCK && BSD) || SVR4 #include #include @@ -41,7 +41,7 @@ int gethostname(char *name, int namelen) * if other error, returns "LOCK ERROR: explanation" * *********************/ -char *dolock(char *fname) +char *dolock( const char *fname) { int fd, n; 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]; diff --git a/pklock.h b/pklock.h new file mode 100644 index 0000000..7cba16c --- /dev/null +++ b/pklock.h @@ -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 diff --git a/posix.c b/posix.c index 97edd9f..b1a1ae4 100644 --- a/posix.c +++ b/posix.c @@ -1,3 +1,6 @@ +/* posix.c -- implements termio.h */ +#include "termio.h" + /* posix.c * * The functions in this file negotiate with the operating system for @@ -16,14 +19,18 @@ #include #include #include +#include +#include #include #include #include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include "retcode.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. */ #if defined(SYSV) && (defined(_DARWIN_C_SOURCE) || defined(_FREEBSD_C_SOURCE)) @@ -31,6 +38,12 @@ #define XCASE 0000004 #endif +#ifdef CYGWIN +#define XCASE 0 +#define ECHOPRT 0 +#define PENDIN 0 +#endif + static int kbdflgs; /* saved keyboard fd flags */ 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 */ ntermios.c_iflag &= ~(IGNBRK | BRKINT | IGNPAR | PARMRK + | IXON | IXOFF | IXANY | INPCK | INLCR | IGNCR | ICRNL); /* raw CR/NR etc output handling */ diff --git a/random.c b/random.c index 455661d..ba87dca 100644 --- a/random.c +++ b/random.c @@ -1,3 +1,8 @@ +/* random.c -- implements random.h */ +#include "random.h" + +#define NBRACE 1 /* new style brace matching command */ + /* random.c * * This file contains the command processing functions for a number of @@ -7,13 +12,42 @@ */ #include +#include +#include "basic.h" +#include "buffer.h" +#include "display.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include "execute.h" +#include "input.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. @@ -311,6 +345,8 @@ int detab(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 fspace; /* pointer to first space if in a run */ int ccol; /* current cursor column */ @@ -898,14 +934,10 @@ int delgmode(int f, int n) */ int adjustmode(int kind, int global) { - char *scan; /* scanning pointer to convert prompt */ int i; /* loop index */ int status; /* error return on input */ -#if COLOR - int uflag; /* was modename uppercase? */ -#endif 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 */ if (global) @@ -920,32 +952,16 @@ int adjustmode(int kind, int global) /* prompt the user and get an answer */ - status = mlreply(prompt, cbuf, NPAT - 1); + status = mlreply( prompt, cbuf, sizeof cbuf - 1) ; if (status != TRUE) 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 */ -#if PKCODE & IBMPC - for (i = 0; i <= NCOLORS; i++) { -#else for (i = 0; i < NCOLORS; i++) { -#endif - if (strcmp(cbuf, cname[i]) == 0) { + if( strcasecmp( cbuf, cname[ i]) == 0) { /* finding the match, we set the color */ #if COLOR - if (uflag) { + if( *cbuf >= 'A' && *cbuf <= 'Z') { if (global) gfcolor = i; #if PKCODE == 0 @@ -971,7 +987,7 @@ int adjustmode(int kind, int global) /* test it against the modes we know */ for (i = 0; i < NUMMODES; i++) { - if (strcmp(cbuf, modename[i]) == 0) { + if( strcasecmp( cbuf, modename[ i]) == 0) { /* finding a match, we process it */ if (kind == TRUE) if (global) @@ -1017,11 +1033,11 @@ int writemsg(int f, int n) char *sp; /* pointer into buf to expand %s */ char *np; /* ptr into nbuf */ int status; - char buf[NPAT]; /* buffer to recieve message into */ - char nbuf[NPAT * 2]; /* buffer to expand string into */ + char buf[ NSTRING] ; /* buffer to recieve message into */ + char nbuf[ NSTRING * 2] ; /* buffer to expand string into */ if ((status = - mlreply("Message to write: ", buf, NPAT - 1)) != TRUE) + mlreply("Message to write: ", buf, sizeof buf - 1)) != TRUE) return status; /* expand all '%' to "%%" so mlwrite won't expect arguments */ @@ -1215,11 +1231,11 @@ int fmatch(int ch) int istring(int f, int n) { int status; /* status return code */ - char tstring[NPAT + 1]; /* string to add */ + char tstring[ 512] ; /* string to add */ /* ask for string to insert */ status = - mlreplyt("String to insert: ", tstring, NPAT, metac); + mlreplyt("String to insert: ", tstring, sizeof tstring - 1, metac) ; if (status != TRUE) return status; @@ -1243,11 +1259,11 @@ int istring(int f, int n) int ovstring(int f, int n) { int status; /* status return code */ - char tstring[NPAT + 1]; /* string to add */ + char tstring[ NSTRING + 1] ; /* string to add */ /* ask for string to insert */ status = - mlreplyt("String to overwrite: ", tstring, NPAT, metac); + mlreplyt( "String to overwrite: ", tstring, NSTRING, metac) ; if (status != TRUE) return status; diff --git a/random.h b/random.h new file mode 100644 index 0000000..749a62c --- /dev/null +++ b/random.h @@ -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 diff --git a/region.c b/region.c index 5190f86..8e70093 100644 --- a/region.c +++ b/region.c @@ -1,3 +1,6 @@ +/* region.c -- implements region.h */ +#include "region.h" + /* region.c * * The routines in this file deal with the region, that magic space @@ -9,10 +12,12 @@ #include +#include "buffer.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" #include "line.h" +#include "log.h" +#include "random.h" +#include "window.h" /* * Kill the region. Ask "getregion" @@ -69,7 +74,7 @@ int copyregion(int f, int n) ++loffs; } } - mlwrite("(region copied)"); + logwrite("(region copied)"); return TRUE; } @@ -166,7 +171,7 @@ int getregion(struct region *rp) long bsize; if (curwp->w_markp == NULL) { - mlwrite("No mark set in this window"); + logwrite("No mark set in this window"); return FALSE; } 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; } diff --git a/region.h b/region.h new file mode 100644 index 0000000..1e46e7f --- /dev/null +++ b/region.h @@ -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 diff --git a/retcode.h b/retcode.h new file mode 100644 index 0000000..947244a --- /dev/null +++ b/retcode.h @@ -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 diff --git a/search.c b/search.c index 32877ab..db2971a 100644 --- a/search.c +++ b/search.c @@ -1,3 +1,6 @@ +/* search.c -- implements search.h */ +#include "search.h" + /* search.c * * The functions in this file implement commands that search in the forward @@ -58,13 +61,90 @@ */ #include +#include +#include +#include "basic.h" +#include "buffer.h" +#include "display.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include "input.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) +/* + * 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 * 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 tapcm[NPAT]; /* The reversed magic patterni. */ static struct magic_replacement rmcpat[NPAT]; /* The replacement magic array. */ + +static int mcscanner( struct magic *mcpatrn, int direct, int beg_or_end) ; #endif 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 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 */ 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 ? */ int nlrepl; /* was a replace done on the last line? */ 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 */ int origoff; /* and offset (for . query option) */ struct line *lastline; /* position of last replace and */ int lastoff; /* offset (for 'u' query option) */ +/* rfi */ + lastline = NULL ; + lastoff = 0 ; + if (curbp->b_mode & MDVIEW) /* don't allow this command if */ return rdonly(); /* we are in read only mode */ @@ -1384,7 +1470,6 @@ static int mceq(int bc, struct magic *mt) return result; } -extern char *clearbits(void); /* * cclmake -- create the bitmap for the character class. diff --git a/search.h b/search.h new file mode 100644 index 0000000..568d553 --- /dev/null +++ b/search.h @@ -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 diff --git a/spawn.c b/spawn.c index 4a7b1e5..c7f4bad 100644 --- a/spawn.c +++ b/spawn.c @@ -1,4 +1,7 @@ -/* spaw.c +/* spawn.c -- implements spawn.h */ +#include "spawn.h" + +/* spawn.c * * Various operating system access commands. * @@ -6,11 +9,22 @@ */ #include +#include +#include #include +#include "defines.h" + +#include "buffer.h" +#include "display.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include "exec.h" +#include "file.h" +#include "flook.h" +#include "input.h" +#include "log.h" +#include "terminal.h" +#include "window.h" #if VMS #define EFN 0 /* Event flag. */ @@ -88,7 +102,7 @@ int spawncli(int f, int n) system("exec /bin/sh"); #endif sgarbf = TRUE; - sleep(2); + usleep( 2000000L) ; TTopen(); TTkopen(); #ifdef SIGWINCH @@ -387,7 +401,7 @@ int filter_buffer(int f, int n) int s; /* return status from CLI */ struct buffer *bp; /* pointer to buffer to zot */ 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 filnam1[] = "fltinp"; @@ -571,7 +585,6 @@ int execprog(char *cmd) char *fcb1; /* 4 byte pointer to FCB at PSP+5Ch */ char *fcb2; /* 4 byte pointer to FCB at PSP+6Ch */ } pblock; - char *flook(); /* parse the command name from the command line */ sp = prog; diff --git a/spawn.h b/spawn.h new file mode 100644 index 0000000..3ce690d --- /dev/null +++ b/spawn.h @@ -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) ; + diff --git a/tcap.c b/tcap.c index fa71fa6..911d866 100644 --- a/tcap.c +++ b/tcap.c @@ -1,3 +1,6 @@ +/* tcap.c -- implements terminal.h */ +#include "terminal.h" + /* tcap.c * * Unix V7 SysV and BS4 Termcap video driver @@ -5,6 +8,9 @@ * modified by Petri Kutvonen */ +#include +#include + /* * Defining this to 1 breaks tcapopen() - it doesn't check if the * sceen size has changed. @@ -13,16 +19,24 @@ #define USE_BROKEN_OPTIMIZATION 0 #define termdef 1 /* Don't define "term" external. */ +#ifndef MINGW32 #include -#include #include +#endif +#include "display.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include "termio.h" #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 #include #endif diff --git a/terminal.h b/terminal.h new file mode 100644 index 0000000..df4e9e8 --- /dev/null +++ b/terminal.h @@ -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 diff --git a/termio.c b/termio.c index 9a8d760..abb2620 100644 --- a/termio.c +++ b/termio.c @@ -1,18 +1,30 @@ +#include "termio.h" -/* TERMIO.C +/* TERMIO.C * * The functions in this file negotiate with the operating system for * characters, and write characters in a barely buffered fashion on the display. * All operating systems. * - * modified by Petri Kutvonen + * modified by Petri Kutvonen */ -#ifndef POSIX +#if !defined( POSIX) && !defined( MINGW32) -#include -#include "estruct.h" -#include "edef.h" +#include +#include + +#include "estruct.h" +#include "retcode.h" +#include "utf8.h" + + +/* rfi */ +#include +#include + +int ttrow = HUGE ; /* Row location of HW cursor */ +int ttcol = HUGE ; /* Column location of HW cursor */ #if VMS #include @@ -20,76 +32,76 @@ #include #include #include -#include +#include -#define NIBUF 128 /* Input buffer size */ -#define NOBUF 1024 /* MM says bug buffers win! */ -#define EFN 0 /* Event flag */ +#define NIBUF 128 /* Input buffer size */ +#define NOBUF 1024 /* MM says bug buffers win! */ +#define EFN 0 /* Event flag */ -char obuf[NOBUF]; /* Output buffer */ -int nobuf; /* # of bytes in above */ -char ibuf[NIBUF]; /* Input buffer */ -int nibuf; /* # of bytes in above */ -int ibufi; /* Read index */ -int oldmode[3]; /* Old TTY mode bits */ -int newmode[3]; /* New TTY mode bits */ -short iochan; /* TTY I/O channel */ +char obuf[NOBUF]; /* Output buffer */ +int nobuf; /* # of bytes in above */ +char ibuf[NIBUF]; /* Input buffer */ +int nibuf; /* # of bytes in above */ +int ibufi; /* Read index */ +int oldmode[3]; /* Old TTY mode bits */ +int newmode[3]; /* New TTY mode bits */ +short iochan; /* TTY I/O channel */ #endif #if MSDOS & (MSC | TURBO) -union REGS rg; /* cpu register for use of DOS calls */ -int nxtchar = -1; /* character held from type ahead */ +union REGS rg; /* cpu register for use of DOS calls */ +int nxtchar = -1; /* character held from type ahead */ #endif -#if USG /* System V */ -#include -#include -#include -int kbdflgs; /* saved keyboard fd flags */ -int kbdpoll; /* in O_NDELAY mode */ -int kbdqp; /* there is a char in kbdq */ -char kbdq; /* char we've already read */ -struct termio otermio; /* original terminal characteristics */ -struct termio ntermio; /* charactoristics to use inside */ -#if XONXOFF -#define XXMASK 0016000 +#if USG /* System V */ +#include +#include +#include +int kbdflgs; /* saved keyboard fd flags */ +int kbdpoll; /* in O_NDELAY mode */ +int kbdqp; /* there is a char in kbdq */ +char kbdq; /* char we've already read */ +struct termio otermio; /* original terminal characteristics */ +struct termio ntermio; /* charactoristics to use inside */ +#if XONXOFF +#define XXMASK 0016000 #endif #endif -#if V7 | BSD -#include /* for stty/gtty functions */ -#include -struct sgttyb ostate; /* saved tty state */ -struct sgttyb nstate; /* values for editor mode */ -struct tchars otchars; /* Saved terminal special character set */ -#if XONXOFF +#if V7 | BSD +#include /* for stty/gtty functions */ +#include +struct sgttyb ostate; /* saved tty state */ +struct sgttyb nstate; /* values for editor mode */ +struct tchars otchars; /* Saved terminal special character set */ +#if XONXOFF struct tchars ntchars = { 0xff, 0xff, 0x11, 0x13, 0xff, 0xff }; - /* A lot of nothing and XON/XOFF */ + /* A lot of nothing and XON/XOFF */ #else struct tchars ntchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - /* A lot of nothing */ + /* A lot of nothing */ #endif -#if BSD & PKCODE -struct ltchars oltchars; /* Saved terminal local special character set */ +#if BSD & PKCODE +struct ltchars oltchars; /* Saved terminal local special character set */ struct ltchars nltchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - /* A lot of nothing */ + /* A lot of nothing */ #endif #if BSD -#include /* to get at the typeahead */ -extern int rtfrmshell(); /* return from suspended shell */ -#define TBUFSIZ 128 -char tobuf[TBUFSIZ]; /* terminal output buffer */ +#include /* to get at the typeahead */ +extern int rtfrmshell(); /* return from suspended shell */ +#define TBUFSIZ 128 +char tobuf[TBUFSIZ]; /* terminal output buffer */ #endif #endif -#if __hpux | SVR4 -extern int rtfrmshell(); /* return from suspended shell */ +#if __hpux | SVR4 +extern int rtfrmshell(); /* return from suspended shell */ #define TBUFSIZ 128 -char tobuf[TBUFSIZ]; /* terminal output buffer */ +char tobuf[TBUFSIZ]; /* terminal output buffer */ #endif /* @@ -100,121 +112,121 @@ char tobuf[TBUFSIZ]; /* terminal output buffer */ void ttopen(void) { #if VMS - struct dsc$descriptor idsc; - struct dsc$descriptor odsc; - char oname[40]; - int iosb[2]; - int status; + struct dsc$descriptor idsc; + struct dsc$descriptor odsc; + char oname[40]; + int iosb[2]; + int status; - odsc.dsc$a_pointer = "TT"; - odsc.dsc$w_length = strlen(odsc.dsc$a_pointer); - odsc.dsc$b_dtype = DSC$K_DTYPE_T; - odsc.dsc$b_class = DSC$K_CLASS_S; - idsc.dsc$b_dtype = DSC$K_DTYPE_T; - idsc.dsc$b_class = DSC$K_CLASS_S; - do { - idsc.dsc$a_pointer = odsc.dsc$a_pointer; - idsc.dsc$w_length = odsc.dsc$w_length; - odsc.dsc$a_pointer = &oname[0]; - odsc.dsc$w_length = sizeof(oname); - status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc); - if (status != SS$_NORMAL && status != SS$_NOTRAN) - exit(status); - if (oname[0] == 0x1B) { - odsc.dsc$a_pointer += 4; - odsc.dsc$w_length -= 4; - } - } while (status == SS$_NORMAL); - status = SYS$ASSIGN(&odsc, &iochan, 0, 0); - if (status != SS$_NORMAL) - exit(status); - status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0, - oldmode, sizeof(oldmode), 0, 0, 0, 0); - if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL) - exit(status); - newmode[0] = oldmode[0]; - newmode[1] = oldmode[1] | TT$M_NOECHO; -#if XONXOFF + odsc.dsc$a_pointer = "TT"; + odsc.dsc$w_length = strlen(odsc.dsc$a_pointer); + odsc.dsc$b_dtype = DSC$K_DTYPE_T; + odsc.dsc$b_class = DSC$K_CLASS_S; + idsc.dsc$b_dtype = DSC$K_DTYPE_T; + idsc.dsc$b_class = DSC$K_CLASS_S; + do { + idsc.dsc$a_pointer = odsc.dsc$a_pointer; + idsc.dsc$w_length = odsc.dsc$w_length; + odsc.dsc$a_pointer = &oname[0]; + odsc.dsc$w_length = sizeof(oname); + status = LIB$SYS_TRNLOG(&idsc, &odsc.dsc$w_length, &odsc); + if (status != SS$_NORMAL && status != SS$_NOTRAN) + exit(status); + if (oname[0] == 0x1B) { + odsc.dsc$a_pointer += 4; + odsc.dsc$w_length -= 4; + } + } while (status == SS$_NORMAL); + status = SYS$ASSIGN(&odsc, &iochan, 0, 0); + if (status != SS$_NORMAL) + exit(status); + status = SYS$QIOW(EFN, iochan, IO$_SENSEMODE, iosb, 0, 0, + oldmode, sizeof(oldmode), 0, 0, 0, 0); + if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL) + exit(status); + newmode[0] = oldmode[0]; + newmode[1] = oldmode[1] | TT$M_NOECHO; +#if XONXOFF #else - newmode[1] &= ~(TT$M_TTSYNC | TT$M_HOSTSYNC); + newmode[1] &= ~(TT$M_TTSYNC | TT$M_HOSTSYNC); #endif - newmode[2] = oldmode[2] | TT2$M_PASTHRU; - status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0, - newmode, sizeof(newmode), 0, 0, 0, 0); - if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL) - exit(status); - term.t_nrow = (newmode[1] >> 24) - 1; - term.t_ncol = newmode[0] >> 16; + newmode[2] = oldmode[2] | TT2$M_PASTHRU; + status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0, + newmode, sizeof(newmode), 0, 0, 0, 0); + if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL) + exit(status); + term.t_nrow = (newmode[1] >> 24) - 1; + term.t_ncol = newmode[0] >> 16; #endif #if MSDOS & (TURBO | (PKCODE & MSC)) - /* kill the CONTROL-break interupt */ - rg.h.ah = 0x33; /* control-break check dos call */ - rg.h.al = 1; /* set the current state */ - rg.h.dl = 0; /* set it OFF */ - intdos(&rg, &rg); /* go for it! */ + /* kill the CONTROL-break interupt */ + rg.h.ah = 0x33; /* control-break check dos call */ + rg.h.al = 1; /* set the current state */ + rg.h.dl = 0; /* set it OFF */ + intdos(&rg, &rg); /* go for it! */ #endif -#if USG - ioctl(0, TCGETA, &otermio); /* save old settings */ - ntermio.c_iflag = 0; /* setup new settings */ -#if XONXOFF - ntermio.c_iflag = otermio.c_iflag & XXMASK; /* save XON/XOFF P.K. */ +#if USG + ioctl(0, TCGETA, &otermio); /* save old settings */ + ntermio.c_iflag = 0; /* setup new settings */ +#if XONXOFF + ntermio.c_iflag = otermio.c_iflag & XXMASK; /* save XON/XOFF P.K. */ #endif - ntermio.c_oflag = 0; - ntermio.c_cflag = otermio.c_cflag; - ntermio.c_lflag = 0; - ntermio.c_line = otermio.c_line; - ntermio.c_cc[VMIN] = 1; - ntermio.c_cc[VTIME] = 0; -#if PKCODE - ioctl(0, TCSETAW, &ntermio); /* and activate them */ + ntermio.c_oflag = 0; + ntermio.c_cflag = otermio.c_cflag; + ntermio.c_lflag = 0; + ntermio.c_line = otermio.c_line; + ntermio.c_cc[VMIN] = 1; + ntermio.c_cc[VTIME] = 0; +#if PKCODE + ioctl(0, TCSETAW, &ntermio); /* and activate them */ #else - ioctl(0, TCSETA, &ntermio); /* and activate them */ + ioctl(0, TCSETA, &ntermio); /* and activate them */ #endif - kbdflgs = fcntl(0, F_GETFL, 0); - kbdpoll = FALSE; + kbdflgs = fcntl(0, F_GETFL, 0); + kbdpoll = FALSE; #endif #if V7 | BSD - gtty(0, &ostate); /* save old state */ - gtty(0, &nstate); /* get base of new state */ -#if XONXOFF - nstate.sg_flags |= (CBREAK | TANDEM); + gtty(0, &ostate); /* save old state */ + gtty(0, &nstate); /* get base of new state */ +#if XONXOFF + nstate.sg_flags |= (CBREAK | TANDEM); #else - nstate.sg_flags |= RAW; + nstate.sg_flags |= RAW; #endif - nstate.sg_flags &= ~(ECHO | CRMOD); /* no echo for now... */ - stty(0, &nstate); /* set mode */ - ioctl(0, TIOCGETC, &otchars); /* Save old characters */ - ioctl(0, TIOCSETC, &ntchars); /* Place new character into K */ -#if BSD & PKCODE - ioctl(0, TIOCGLTC, &oltchars); /* Save old local characters */ - ioctl(0, TIOCSLTC, &nltchars); /* New local characters */ + nstate.sg_flags &= ~(ECHO | CRMOD); /* no echo for now... */ + stty(0, &nstate); /* set mode */ + ioctl(0, TIOCGETC, &otchars); /* Save old characters */ + ioctl(0, TIOCSETC, &ntchars); /* Place new character into K */ +#if BSD & PKCODE + ioctl(0, TIOCGLTC, &oltchars); /* Save old local characters */ + ioctl(0, TIOCSLTC, &nltchars); /* New local characters */ #endif -#if BSD - /* provide a smaller terminal output buffer so that - the type ahead detection works better (more often) */ - setbuffer(stdout, &tobuf[0], TBUFSIZ); - signal(SIGTSTP, SIG_DFL); /* set signals so that we can */ - signal(SIGCONT, rtfrmshell); /* suspend & restart emacs */ +#if BSD + /* provide a smaller terminal output buffer so that + the type ahead detection works better (more often) */ + setbuffer(stdout, &tobuf[0], TBUFSIZ); + signal(SIGTSTP, SIG_DFL); /* set signals so that we can */ + signal(SIGCONT, rtfrmshell); /* suspend & restart emacs */ #endif #endif -#if __hpux | SVR4 - /* provide a smaller terminal output buffer so that - the type ahead detection works better (more often) */ - setvbuf(stdout, &tobuf[0], _IOFBF, TBUFSIZ); - signal(SIGTSTP, SIG_DFL); /* set signals so that we can */ - signal(SIGCONT, rtfrmshell); /* suspend & restart emacs */ - TTflush(); -#endif /* __hpux */ +#if __hpux | SVR4 + /* provide a smaller terminal output buffer so that + the type ahead detection works better (more often) */ + setvbuf(stdout, &tobuf[0], _IOFBF, TBUFSIZ); + signal(SIGTSTP, SIG_DFL); /* set signals so that we can */ + signal(SIGCONT, rtfrmshell); /* suspend & restart emacs */ + TTflush(); +#endif /* __hpux */ - /* on all screens we are not sure of the initial position - of the cursor */ - ttrow = 999; - ttcol = 999; + /* on all screens we are not sure of the initial position + of the cursor */ + ttrow = 999; + ttcol = 999; } /* @@ -225,40 +237,40 @@ void ttopen(void) void ttclose(void) { #if VMS - int status; - int iosb[1]; + int status; + int iosb[1]; - ttflush(); - status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0, - oldmode, sizeof(oldmode), 0, 0, 0, 0); - if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL) - exit(status); - status = SYS$DASSGN(iochan); - if (status != SS$_NORMAL) - exit(status); + ttflush(); + status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0, + oldmode, sizeof(oldmode), 0, 0, 0, 0); + if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL) + exit(status); + status = SYS$DASSGN(iochan); + if (status != SS$_NORMAL) + exit(status); #endif #if MSDOS & (TURBO | (PKCODE & MSC)) - /* restore the CONTROL-break interupt */ - rg.h.ah = 0x33; /* control-break check dos call */ - rg.h.al = 1; /* set the current state */ - rg.h.dl = 1; /* set it ON */ - intdos(&rg, &rg); /* go for it! */ + /* restore the CONTROL-break interupt */ + rg.h.ah = 0x33; /* control-break check dos call */ + rg.h.al = 1; /* set the current state */ + rg.h.dl = 1; /* set it ON */ + intdos(&rg, &rg); /* go for it! */ #endif -#if USG -#if PKCODE - ioctl(0, TCSETAW, &otermio); /* restore terminal settings */ +#if USG +#if PKCODE + ioctl(0, TCSETAW, &otermio); /* restore terminal settings */ #else - ioctl(0, TCSETA, &otermio); /* restore terminal settings */ + ioctl(0, TCSETA, &otermio); /* restore terminal settings */ #endif - fcntl(0, F_SETFL, kbdflgs); + fcntl(0, F_SETFL, kbdflgs); #endif #if V7 | BSD - stty(0, &ostate); - ioctl(0, TIOCSETC, &otchars); /* Place old character into K */ -#if BSD & PKCODE - ioctl(0, TIOCSLTC, &oltchars); /* Place old local character into K */ + stty(0, &ostate); + ioctl(0, TIOCSETC, &otchars); /* Place old character into K */ +#if BSD & PKCODE + ioctl(0, TIOCSLTC, &oltchars); /* Place old local character into K */ #endif #endif } @@ -269,43 +281,46 @@ void ttclose(void) * 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). */ -void ttputc(c) -{ +int ttputc( int c) { #if VMS - if (nobuf >= NOBUF) - ttflush(); - obuf[nobuf++] = c; + if (nobuf >= NOBUF) + ttflush(); + obuf[nobuf++] = c; #endif -#if MSDOS & ~IBMPC - bdos(6, c, 0); +#if MSDOS & ~IBMPC + bdos(6, c, 0); #endif #if V7 | USG | BSD - fputc(c, stdout); + char utf8[6]; + int bytes; + + bytes = unicode_to_utf8(c, utf8); + fwrite(utf8, 1, bytes, stdout); #endif + return 0 ; } /* * 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. */ -int ttflush(void) -{ +void ttflush( void) { #if VMS - int status; - int iosb[2]; + int status; + int iosb[2]; - status = SS$_NORMAL; - if (nobuf != 0) { - status = - SYS$QIOW(EFN, iochan, IO$_WRITELBLK | IO$M_NOFORMAT, - iosb, 0, 0, obuf, nobuf, 0, 0, 0, 0); - if (status == SS$_NORMAL) - status = iosb[0] & 0xFFFF; - nobuf = 0; - } - return status; + status = SS$_NORMAL; + if (nobuf != 0) { + status = + SYS$QIOW(EFN, iochan, IO$_WRITELBLK | IO$M_NOFORMAT, + iosb, 0, 0, obuf, nobuf, 0, 0, 0, 0); + if (status == SS$_NORMAL) + status = iosb[0] & 0xFFFF; + nobuf = 0; + } + return status; #endif #if MSDOS @@ -324,13 +339,13 @@ int ttflush(void) #include - int status; + int status; - status = fflush(stdout); + status = fflush(stdout); - if (status != 0 && errno != EAGAIN) { - exit(errno); - } + if (status != 0 && errno != EAGAIN) { + exit(errno); + } #endif } @@ -339,114 +354,113 @@ int ttflush(void) * 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. */ -ttgetc() -{ +int ttgetc( void) { #if VMS - int status; - int iosb[2]; - int term[2]; + int status; + int iosb[2]; + int term[2]; - while (ibufi >= nibuf) { - ibufi = 0; - term[0] = 0; - term[1] = 0; - status = SYS$QIOW(EFN, iochan, IO$_READLBLK | IO$M_TIMED, - iosb, 0, 0, ibuf, NIBUF, 0, term, 0, 0); - if (status != SS$_NORMAL) - exit(status); - status = iosb[0] & 0xFFFF; - if (status != SS$_NORMAL && status != SS$_TIMEOUT && - status != SS$_DATAOVERUN) - exit(status); - nibuf = (iosb[0] >> 16) + (iosb[1] >> 16); - if (nibuf == 0) { - status = SYS$QIOW(EFN, iochan, IO$_READLBLK, - iosb, 0, 0, ibuf, 1, 0, term, 0, - 0); - if (status != SS$_NORMAL - || (status = (iosb[0] & 0xFFFF)) != SS$_NORMAL) - if (status != SS$_DATAOVERUN) - exit(status); - nibuf = (iosb[0] >> 16) + (iosb[1] >> 16); - } - } - return ibuf[ibufi++] & 0xFF; /* Allow multinational */ + while (ibufi >= nibuf) { + ibufi = 0; + term[0] = 0; + term[1] = 0; + status = SYS$QIOW(EFN, iochan, IO$_READLBLK | IO$M_TIMED, + iosb, 0, 0, ibuf, NIBUF, 0, term, 0, 0); + if (status != SS$_NORMAL) + exit(status); + status = iosb[0] & 0xFFFF; + if (status != SS$_NORMAL && status != SS$_TIMEOUT && + status != SS$_DATAOVERUN) + exit(status); + nibuf = (iosb[0] >> 16) + (iosb[1] >> 16); + if (nibuf == 0) { + status = SYS$QIOW(EFN, iochan, IO$_READLBLK, + iosb, 0, 0, ibuf, 1, 0, term, 0, + 0); + if (status != SS$_NORMAL + || (status = (iosb[0] & 0xFFFF)) != SS$_NORMAL) + if (status != SS$_DATAOVERUN) + exit(status); + nibuf = (iosb[0] >> 16) + (iosb[1] >> 16); + } + } + return ibuf[ibufi++] & 0xFF; /* Allow multinational */ #endif -#if MSDOS & (MSC | TURBO) - int c; /* character read */ +#if MSDOS & (MSC | TURBO) + int c; /* character read */ - /* if a char already is ready, return it */ - if (nxtchar >= 0) { - c = nxtchar; - nxtchar = -1; - return c; - } + /* if a char already is ready, return it */ + if (nxtchar >= 0) { + c = nxtchar; + nxtchar = -1; + return c; + } - /* call the dos to get a char */ - rg.h.ah = 7; /* dos Direct Console Input call */ - intdos(&rg, &rg); - c = rg.h.al; /* grab the char */ - return c & 255; + /* call the dos to get a char */ + rg.h.ah = 7; /* dos Direct Console Input call */ + intdos(&rg, &rg); + c = rg.h.al; /* grab the char */ + return c & 255; #endif #if V7 | BSD - return 255 & fgetc(stdin); /* 8BIT P.K. */ + return 255 & fgetc(stdin); /* 8BIT P.K. */ #endif -#if USG - if (kbdqp) - kbdqp = FALSE; - else { - if (kbdpoll && fcntl(0, F_SETFL, kbdflgs) < 0) - return FALSE; - kbdpoll = FALSE; - while (read(0, &kbdq, 1) != 1); - } - return kbdq & 255; +#if USG + if (kbdqp) + kbdqp = FALSE; + else { + if (kbdpoll && fcntl(0, F_SETFL, kbdflgs) < 0) + return FALSE; + kbdpoll = FALSE; + while (read(0, &kbdq, 1) != 1); + } + return kbdq & 255; #endif } -#if TYPEAH -/* typahead: Check to see if any characters are already in the - keyboard buffer +#if TYPEAH +/* typahead: Check to see if any characters are already in the + keyboard buffer */ -typahead() +int typahead( void) { -#if MSDOS & (MSC | TURBO) - if (kbhit() != 0) - return TRUE; - else - return FALSE; +#if MSDOS & (MSC | TURBO) + if (kbhit() != 0) + return TRUE; + else + return FALSE; #endif -#if BSD - int x; /* holds # of pending chars */ +#if BSD + int x; /* holds # of pending chars */ - return (ioctl(0, FIONREAD, &x) < 0) ? 0 : x; + return (ioctl(0, FIONREAD, &x) < 0) ? 0 : x; #endif -#if PKCODE & VMS - return ibufi < nibuf; +#if PKCODE & VMS + return ibufi < nibuf; #endif -#if USG - if (!kbdqp) { - if (!kbdpoll && fcntl(0, F_SETFL, kbdflgs | O_NDELAY) < 0) - return FALSE; -#if PKCODE - kbdpoll = 1; +#if USG + if (!kbdqp) { + if (!kbdpoll && fcntl(0, F_SETFL, kbdflgs | O_NDELAY) < 0) + return FALSE; +#if PKCODE + kbdpoll = 1; #endif - kbdqp = (1 == read(0, &kbdq, 1)); - } - return kbdqp; + kbdqp = (1 == read(0, &kbdq, 1)); + } + return kbdqp; #endif #if !UNIX & !VMS & !MSDOS - return FALSE; + return FALSE; #endif } #endif -#endif /* not POSIX */ +#endif /* not POSIX */ diff --git a/termio.h b/termio.h new file mode 100644 index 0000000..5a3382c --- /dev/null +++ b/termio.h @@ -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 diff --git a/tststr.cmd b/tststr.cmd new file mode 100644 index 0000000..1463032 --- /dev/null +++ b/tststr.cmd @@ -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 diff --git a/usage.c b/usage.c deleted file mode 100644 index 0ae18ce..0000000 --- a/usage.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "usage.h" - -#include -#include -#include - -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); -} diff --git a/usage.h b/usage.h deleted file mode 100644 index bb6b40e..0000000 --- a/usage.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef USAGE_H_ -#define USAGE_H_ - -extern void die(const char* err, ...); - -#endif /* USAGE_H_ */ diff --git a/utf8.h b/utf8.h index c317a6a..1a6f274 100644 --- a/utf8.h +++ b/utf8.h @@ -3,10 +3,11 @@ typedef unsigned int unicode_t; -unsigned utf8_to_unicode(char *line, unsigned index, unsigned len, unicode_t *res); -unsigned unicode_to_utf8(unsigned int c, char *utf8); +unsigned utf8_to_unicode( char *line, unsigned index, unsigned len, + unicode_t *res) ; +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) { return (c & 0xc0) != 0x80; } diff --git a/util.h b/util.h deleted file mode 100644 index 49f3649..0000000 --- a/util.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef UTIL_H_ -#define UTIL_H_ - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) - -#endif /* UTIL_H_ */ diff --git a/version.c b/version.c deleted file mode 100644 index d974764..0000000 --- a/version.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "version.h" - -void version(void) -{ - printf("%s version %s\n", PROGRAM_NAME_LONG, VERSION); -} diff --git a/version.h b/version.h index 1647462..57fc82c 100644 --- a/version.h +++ b/version.h @@ -1,12 +1,16 @@ #ifndef VERSION_H_ #define VERSION_H_ -#define PROGRAM_NAME "em" -#define PROGRAM_NAME_LONG "uEmacs/Pk" +#ifdef PROGRAM +# define _QUOTE( s) #s +# define QUOTE( s) _QUOTE( s) +# define PROGRAM_NAME QUOTE(PROGRAM) +#else +# define PROGRAM_NAME "em" +#endif -#define VERSION "4.0.15" +#define PROGRAM_NAME_LONG "uEMACS" -/* Print the version string. */ -void version(void); +#define VERSION "4.1.1" #endif /* VERSION_H_ */ diff --git a/vmsvt.c b/vmsvt.c index b04dab0..b02bd1b 100644 --- a/vmsvt.c +++ b/vmsvt.c @@ -11,7 +11,6 @@ #include /* Standard I/O package */ #include "estruct.h" /* Emacs' structures */ -#include "edef.h" /* Emacs' definitions */ #if VMSVT diff --git a/vt52.c b/vt52.c index bec7267..c11149b 100644 --- a/vt52.c +++ b/vt52.c @@ -15,7 +15,6 @@ #include #include "estruct.h" -#include "edef.h" #if VT52 diff --git a/window.c b/window.c index 86da9a8..f78ccd7 100644 --- a/window.c +++ b/window.c @@ -1,3 +1,7 @@ +/* window.c -- inplements window.h */ + +#include "window.h" + /* window.c * * Window management. Some of the functions are internal, and some are @@ -7,12 +11,22 @@ #include +#include "basic.h" +#include "buffer.h" +#include "display.h" #include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include "execute.h" #include "line.h" +#include "terminal.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 * positive, it is that line. If it is negative it is that line from the diff --git a/window.h b/window.h new file mode 100644 index 0000000..669d8e1 --- /dev/null +++ b/window.h @@ -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 diff --git a/word.c b/word.c index 83cfe9b..b29f060 100644 --- a/word.c +++ b/word.c @@ -1,3 +1,6 @@ +/* word.c -- implements word.h */ +#include "word.h" + /* word.c * * The routines in this file implement commands that work word or a @@ -9,10 +12,22 @@ #include +#include "basic.h" +#include "buffer.h" #include "estruct.h" -#include "edef.h" -#include "efunc.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 * 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 * part of a word. The word character list is hard coded. Should be setable. */ -int inword(void) +static int inword(void) { int c; @@ -413,7 +428,7 @@ int fillpara(int f, int n) if (curbp->b_mode & MDVIEW) /* don't allow this command if */ return rdonly(); /* we are in read only mode */ if (fillcol == 0) { /* no fill column set */ - mlwrite("No fill column set"); + logwrite("No fill column set"); return FALSE; } #if PKCODE @@ -512,14 +527,14 @@ int justpara(int f, int n) if (curbp->b_mode & MDVIEW) /* don't allow this command if */ return rdonly(); /* we are in read only mode */ if (fillcol == 0) { /* no fill column set */ - mlwrite("No fill column set"); + logwrite("No fill column set"); return FALSE; } justflag = TRUE; leftmarg = curwp->w_doto; if (leftmarg + 10 > fillcol) { leftmarg = 0; - mlwrite("Column too narrow"); + logwrite("Column too narrow"); return FALSE; } @@ -704,8 +719,108 @@ int wordcount(int f, int n) else 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); return TRUE; } #endif + +#if WORDPRO +/* + * go back to the beginning of the current paragraph + * here we look for a or or + * 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 or + or a */ + 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 or or + * 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 or + or a */ + 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 diff --git a/word.h b/word.h new file mode 100644 index 0000000..e89d095 --- /dev/null +++ b/word.h @@ -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 diff --git a/wrapper.c b/wrapper.c index a3301e2..43a63a2 100644 --- a/wrapper.c +++ b/wrapper.c @@ -1,22 +1,39 @@ -#include "usage.h" +/* wrapper.c -- implements wrapper.h */ +#include "wrapper.h" + +#include #include +#include + +#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 */ -int xmkstemp(char *template) -{ - int fd; +void xmkstemp( char *template) { + int fd ; - fd = mkstemp(template); - if (fd < 0) - die("Unable to create temporary file"); - return fd; + fd = mkstemp( template) ; + if( fd < 0) + die( "Unable to create temporary file") ; + + close( fd) ; } -void *xmalloc(size_t size) -{ - void *ret = malloc(size); - if (!ret) - die("Out of memory"); - return ret; +void *xmalloc( size_t size) { + void *ret = malloc( size) ; + if( !ret) + die( "Out of memory") ; + + return ret ; } + +/* end of wrapper.c */ diff --git a/wrapper.h b/wrapper.h old mode 100644 new mode 100755 index 25f5bc0..1f81c10 --- a/wrapper.h +++ b/wrapper.h @@ -1,8 +1,10 @@ #ifndef WRAPPER_H_ #define WRAPPER_H_ -extern int xmkstemp(char *template); +#include -extern void *xmalloc(size_t size); +void xmkstemp( char *template) ; + +void *xmalloc( size_t size) ; #endif /* WRAPPER_H_ */ diff --git a/wscreen.c b/wscreen.c new file mode 100644 index 0000000..45460d1 --- /dev/null +++ b/wscreen.c @@ -0,0 +1,117 @@ +/* wscreen.c -- windows screen console */ +#include "wscreen.h" + +#ifdef MINGW32 + +#include +#include +#include + +/* 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 */ diff --git a/wscreen.h b/wscreen.h new file mode 100644 index 0000000..65080f4 --- /dev/null +++ b/wscreen.h @@ -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 */