1
0
mirror of https://github.com/rfivet/uemacs.git synced 2025-11-23 11:41:15 -05:00

68 Commits
4.2.1 ... 4.2.4

Author SHA1 Message Date
dab92e74ff Increase µEMACS version number.
Add message line in maze script.
2017-06-17 17:18:17 +08:00
1ff2491d88 Insure virtual screen dimensions support maximum zoom out with mintty on 180p 2017-06-01 15:31:39 +08:00
b6c89d6eca Cleanup virtual terminal allocation code. 2017-06-01 13:02:47 +08:00
57363dcb19 Increase maximum virtual terminal size. 2017-06-01 08:05:59 +08:00
35f2184253 Insure that virtual terminal is always initialized with maximum size (MAXROW X MAXCOL) while current maximum size is inherited from actual terminal. 2017-05-29 16:27:46 +08:00
5d46ffc3dc Fix newly reported coverity issues (Memory leak and flase positive of Use after Free). 2017-05-27 16:07:56 +08:00
5368877ebb Add gmake to the dependencies in README.MD.
Remove reference to encryption in emacs.hlp.
2017-05-24 11:32:24 +08:00
6d40d82dea Add sample script to solve maze using blind mouse algorithm. 2017-05-20 16:10:13 +08:00
b4ff6798cd Seed the pseudo-random generator on initialization.
Add example script to solve a maze by flood painting.
2017-05-19 11:19:13 +08:00
674a3baba4 Setting $curcol works on line containing UTF-8 encoded characters. 2017-05-18 12:16:07 +08:00
df0d663b35 Rebuild with updated MinGW32. 2017-05-17 07:49:03 +08:00
4873021e37 &left and &mid handling of UTF-8 encoded characters. 2017-05-16 12:13:12 +08:00
918a310601 Improve ernd as &rnd( 2) always returned same pattern. 2017-05-14 15:18:28 +08:00
ba87641122 README.md edited online with Bitbucket 2017-05-07 06:15:05 +00:00
774475a4f6 Correct column position when displaying double width unicode character (assumed in range \u3000-\u3FFF). 2017-05-07 14:05:47 +08:00
18cd0ba37f revert to cuserid for systems where getlogin fails 2017-05-07 10:50:09 +08:00
9d864d8b00 Fix new warnings in updated gcc 2017-05-06 08:51:02 +08:00
99487b126f Consistent unicode handling in buffer-position (CTL-X =) and $curchar. 2017-05-05 10:49:02 +08:00
3ef30d1c23 Review help command line option message. 2017-05-03 12:11:09 +08:00
7f8ab2d2a5 Avoid copy to buffer name using same source as destination to accomodate sensitive implementation of str(n)cpy. 2017-05-02 12:15:19 +08:00
19e33fef82 Increase version number before merge to master branch. 2017-03-22 14:37:26 +08:00
5b7d419b1d Add comments clarifying $overlap and $target 2017-03-22 14:18:29 +08:00
7e71cf52a3 Review cursor move commands in basic. 2016-05-22 22:22:39 +08:00
14e6240b9c Transpose-characters valid with mixed UTF-8 and extended ASCII. 2016-05-21 07:52:19 +08:00
f11dea468f Insure transpose-characters works with UTF8. 2016-05-20 20:42:37 +08:00
92078e5595 Check consistency of forwchar/backchar calls.
Review entab dot movement.
2016-05-20 19:46:54 +08:00
2b21a98e9c Review forwchar and backchar. 2016-05-19 21:27:26 +08:00
d4b2a4c1aa Review ldelchar and ldelete. 2016-05-19 14:02:43 +08:00
a7c34c747d cppcheck: The scope of the variable 'bp' can be reduced. 2016-05-19 11:26:07 +08:00
ef7207b421 cppcheck: Variable 'startflag' was assigned a value that is never used. 2016-05-19 11:20:21 +08:00
1b2307e056 Partial fix of issues when using unicode sequence with describe-key, search-forward, query-replace-string. 2016-04-09 11:46:40 +08:00
f83ab08609 Review formatted string printing when '%' is at end of string.
Clean up unused IO return code.
2016-04-05 11:33:38 +08:00
16e6f87ad5 Review windows update when reading or writing buffers to file. 2016-04-01 13:25:05 +08:00
af23c6b3b5 Fix previous commit break: Handle case of non override of locked file in Linux. 2016-03-30 20:14:19 +08:00
ac3c2aa6dd Review file read and write into buffers. 2016-03-30 17:44:46 +08:00
06eba37779 Include stddef on Linux for offsetof macro definition. 2016-03-25 19:27:09 +08:00
135866231d Rework line allocation. 2016-03-25 14:56:34 +08:00
3e2d73394a Review buffer list related functions. 2016-03-24 21:53:36 +08:00
9669fea1ce Review buffer list and mode line printing.
Increase version number as two buffer modes have been removed (Spell and Crypt).
2016-03-24 15:25:48 +08:00
645a0d734b Remove encryption as implementation is too weak. 2016-03-23 21:11:05 +08:00
8c968322f6 Remove Spell buffer mode as it is not connected to any implemented functionality. 2016-03-23 20:25:16 +08:00
3af4ee19a2 Adjust maximum file length in pklock. 2016-03-19 14:36:27 +08:00
a0ea6d07e6 Increase maximum file name length to 255 (Windows & Linux). 2016-03-19 11:37:54 +08:00
187b0ce4a3 Review echo of input on message line. 2016-03-12 12:58:05 +08:00
910e6576b5 Update Makefile after make depend.
Suppress warning when reaching end of main on Linux.
2016-03-03 21:17:23 +08:00
f781d458aa Review universal arg command and Alt-# processing in kbd_loop. 2016-03-03 21:15:45 +08:00
7188773d13 Move command loop from main to kbd_loop in execute. 2016-03-02 21:37:43 +08:00
5c6aac1ae9 Review execute keystroke handling logic. 2016-03-02 19:17:31 +08:00
ee667b25ed Move insbrace and fmatch to execute.
Review execute.
2016-03-01 19:17:39 +08:00
14ef4f50ab Review insbrace, getfence and fmatch.
Adjust timing to pause when highlighting matching brace.
$tpause <= 0 disable matching brace highlight.
2016-02-29 21:23:43 +08:00
663fc2e554 Fix: In C-mode, auto-indent increment was not correct when matching opening brace is first character of buffer. 2016-02-29 19:02:09 +08:00
775b16c7b1 Rewrite cinsert to avoid buffer size constraint when doing indentation in C mode. 2016-02-25 21:50:04 +08:00
a42c60045d Improve consistency of tab insertion behaviour while indenting and brace matching. 2016-02-25 17:08:27 +08:00
998559464b In C mode, insure indentation is correct when inserting newline at end of white lines. 2016-02-24 22:18:37 +08:00
15e5796426 In C mode, insertion of pound # can take a count as argument. 2016-02-24 21:43:11 +08:00
3436443807 Introduce boolean $hardtab to control insertion of hardcoded tab or soft ones (spaces). Review insert_tab accordingly. 2016-02-24 21:17:45 +08:00
8dfa92ba44 Review inspound, '#' insertion in C mode. 2016-02-24 20:00:44 +08:00
c390cf2a3e Remove tab width constraints, was [2, 4, 8], now [1... 2016-02-24 13:22:54 +08:00
3e27fcf19e Fix: handle tab size other than 8 in overwrite mode. 2016-02-23 22:00:05 +08:00
893658b3ef Fix issue #5 by rolling back commit 06b0d3f. This insure compatibility with both CYGWIN and XTERM terminals under Cygwin. 2016-02-12 13:11:50 +08:00
c378a80204 Recompile with -pedantic. 2015-11-25 10:42:33 +08:00
e3d7efda7f Add CRYPT mode to buffer when doing a set-encryption-key on a buffer where the mode is not set yet. 2015-11-06 11:33:05 +08:00
8aeb526a2a Clean up abs usage versus implementation.
Clarify ernd() behaviour.
2015-10-27 12:51:40 +08:00
83b4028c95 Avoid 176719 periodicity of &rnd 0. 2015-10-22 16:57:56 +08:00
9b1c5f48a2 Consistent use of upmode() to update all mode lines. 2015-10-22 15:26:07 +08:00
c1ebad4808 Always re-write entire line if reversed. This avoid minor redraw error with apropos.
Remove DEC Rainbow 100 specific code.
2015-10-22 10:10:39 +08:00
e5e2ca0636 Fix CID114556: Copy into fixed size buffer. 2015-10-05 17:44:05 +08:00
4feb70b484 Fix CID114555: Unchecked return value. 2015-10-05 17:42:57 +08:00
51 changed files with 2198 additions and 2386 deletions

124
Makefile
View File

@@ -1,8 +1,8 @@
# Makefile for emacs, updated Fri, Feb 13, 2015 12:02:52 PM
SRC=basic.c bind.c bindable.c buffer.c crypt.c display.c ebind.c eval.c exec.c execute.c file.c fileio.c flook.c input.c isearch.c line.c lock.c main.c mingw32.c mlout.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c window.c word.c wrapper.c wscreen.c
OBJ=basic.o bind.o bindable.o buffer.o crypt.o display.o ebind.o eval.o exec.o execute.o file.o fileio.o flook.o input.o isearch.o line.o lock.o main.o mingw32.o mlout.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o window.o word.o wrapper.o wscreen.o
HDR=basic.h bind.h bindable.h buffer.h crypt.h defines.h display.h ebind.h estruct.h eval.h exec.h execute.h file.h fileio.h flook.h input.h isearch.h line.h lock.h mlout.h names.h pklock.h random.h region.h retcode.h search.h spawn.h terminal.h termio.h utf8.h version.h window.h word.h wrapper.h wscreen.h
SRC=basic.c bind.c bindable.c buffer.c display.c ebind.c eval.c exec.c execute.c file.c fileio.c flook.c input.c isearch.c line.c lock.c main.c mingw32.c mlout.c names.c pklock.c posix.c random.c region.c search.c spawn.c tcap.c termio.c utf8.c window.c word.c wrapper.c wscreen.c
OBJ=basic.o bind.o bindable.o buffer.o display.o ebind.o eval.o exec.o execute.o file.o fileio.o flook.o input.o isearch.o line.o lock.o main.o mingw32.o mlout.o names.o pklock.o posix.o random.o region.o search.o spawn.o tcap.o termio.o utf8.o window.o word.o wrapper.o wscreen.o
HDR=basic.h bind.h bindable.h buffer.h defines.h display.h ebind.h estruct.h eval.h exec.h execute.h file.h fileio.h flook.h input.h isearch.h line.h lock.h mlout.h names.h pklock.h random.h region.h retcode.h search.h spawn.h terminal.h termio.h utf8.h version.h window.h word.h wrapper.h wscreen.h
# DO NOT ADD OR MODIFY ANY LINES ABOVE THIS -- make source creates them
@@ -26,14 +26,14 @@ uname_S := $(shell sh -c 'echo $(uname_S) | sed s/_.*$$//')
PROGRAM=ue
CC=gcc
WARNINGS=-Wall -Wextra -Wstrict-prototypes -Wno-unused-parameter
WARNINGS=-pedantic -Wall -Wextra -Wstrict-prototypes -Wno-unused-parameter
CFLAGS=-O2 $(WARNINGS)
#CC=c89 +O3 # HP
#CFLAGS= -D_HPUX_SOURCE -DSYSV
#CFLAGS=-O4 -DSVR4 # Sun
#CFLAGS=-O -qchars=signed # RS/6000
ifeq ($(uname_S),Linux)
DEFINES=-DAUTOCONF -DPROGRAM=$(PROGRAM) -DPOSIX -DUSG -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600
DEFINES=-DAUTOCONF -DPROGRAM=$(PROGRAM) -DPOSIX -DUSG
LIBS=-lcurses
endif
ifeq ($(uname_S),FreeBSD)
@@ -43,7 +43,7 @@ ifeq ($(uname_S),Darwin)
DEFINES=-DAUTOCONF -DPOSIX -DSYSV -D_DARWIN_C_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600
endif
ifeq ($(uname_S),CYGWIN)
DEFINES=-DAUTOCONF -DCYGWIN -DPOSIX -DSYSV -DPROGRAM=$(PROGRAM)
DEFINES=-DAUTOCONF -DCYGWIN -DSYSV -DPROGRAM=$(PROGRAM)
LIBS=-lcurses
endif
ifeq ($(uname_S),MINGW32)
@@ -117,7 +117,7 @@ depend: ${SRC}
@sed -n -e '1,/^# DO NOT DELETE THIS LINE/p' Makefile.bak > Makefile
@echo >> Makefile
@for i in ${SRC}; do\
cc ${DEFINES} -MM $$i ; done >> Makefile
$(CC) ${DEFINES} -MM $$i ; done >> Makefile
@echo '' >>Makefile
@echo '# DEPENDENCIES MUST END AT END OF FILE' >>Makefile
@echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >>Makefile
@@ -129,73 +129,71 @@ depend: ${SRC}
# DO NOT DELETE THIS LINE -- make depend uses it
basic.o: basic.c basic.h buffer.h crypt.h line.h retcode.h utf8.h \
estruct.h input.h bind.h mlout.h random.h terminal.h defines.h window.h
bind.o: bind.c bind.h estruct.h bindable.h buffer.h crypt.h line.h \
retcode.h utf8.h display.h ebind.h exec.h file.h flook.h input.h names.h \
window.h defines.h
bindable.o: bindable.c bindable.h defines.h buffer.h crypt.h line.h \
retcode.h utf8.h display.h estruct.h file.h input.h bind.h lock.h \
mlout.h terminal.h
buffer.o: buffer.c buffer.h crypt.h line.h retcode.h utf8.h defines.h \
estruct.h file.h input.h bind.h mlout.h window.h
crypt.o: crypt.c crypt.h
display.o: display.c display.h estruct.h buffer.h crypt.h line.h \
retcode.h utf8.h input.h bind.h termio.h terminal.h defines.h version.h \
wrapper.h window.h
ebind.o: ebind.c ebind.h basic.h bind.h estruct.h bindable.h buffer.h \
crypt.h line.h retcode.h utf8.h eval.h exec.h file.h isearch.h random.h \
region.h search.h spawn.h window.h defines.h word.h
eval.o: eval.c eval.h basic.h bind.h buffer.h crypt.h line.h retcode.h \
utf8.h display.h estruct.h exec.h execute.h flook.h input.h random.h \
search.h terminal.h defines.h termio.h version.h window.h
exec.o: exec.c exec.h retcode.h buffer.h crypt.h line.h utf8.h bind.h \
display.h estruct.h eval.h file.h flook.h input.h random.h window.h \
basic.o: basic.c basic.h retcode.h input.h bind.h mlout.h random.h \
terminal.h defines.h utf8.h window.h buffer.h line.h
bind.o: bind.c bind.h estruct.h bindable.h buffer.h line.h retcode.h \
utf8.h display.h ebind.h exec.h file.h flook.h input.h names.h window.h \
defines.h
execute.o: execute.c execute.h estruct.h bind.h random.h display.h file.h \
buffer.h crypt.h line.h retcode.h utf8.h mlout.h window.h defines.h
file.o: file.c file.h buffer.h crypt.h line.h retcode.h utf8.h defines.h \
estruct.h execute.h fileio.h input.h bind.h lock.h mlout.h window.h
fileio.o: fileio.c fileio.h crypt.h retcode.h defines.h utf8.h
flook.o: flook.c flook.h retcode.h defines.h fileio.h crypt.h
input.o: input.c input.h bind.h estruct.h bindable.h display.h exec.h \
retcode.h names.h terminal.h defines.h utf8.h wrapper.h
isearch.o: isearch.c isearch.h basic.h buffer.h crypt.h line.h retcode.h \
utf8.h display.h estruct.h exec.h input.h bind.h search.h terminal.h \
defines.h window.h
line.o: line.c line.h retcode.h utf8.h buffer.h crypt.h estruct.h mlout.h \
bindable.o: bindable.c bindable.h defines.h buffer.h line.h retcode.h \
utf8.h display.h estruct.h file.h input.h bind.h lock.h mlout.h \
terminal.h
buffer.o: buffer.c buffer.h line.h retcode.h utf8.h defines.h estruct.h \
file.h input.h bind.h mlout.h window.h
display.o: display.c display.h estruct.h utf8.h buffer.h line.h retcode.h \
input.h bind.h termio.h terminal.h defines.h version.h wrapper.h \
window.h
ebind.o: ebind.c ebind.h basic.h retcode.h bind.h estruct.h bindable.h \
buffer.h line.h utf8.h eval.h exec.h file.h isearch.h random.h region.h \
search.h spawn.h window.h defines.h word.h
eval.o: eval.c eval.h basic.h retcode.h bind.h buffer.h line.h utf8.h \
display.h estruct.h exec.h execute.h flook.h input.h random.h search.h \
terminal.h defines.h termio.h version.h window.h
exec.o: exec.c exec.h retcode.h buffer.h line.h utf8.h bind.h display.h \
estruct.h eval.h file.h flook.h input.h random.h window.h defines.h
execute.o: execute.c execute.h estruct.h bind.h random.h retcode.h \
display.h utf8.h file.h buffer.h line.h input.h mlout.h search.h \
terminal.h defines.h window.h
file.o: file.c file.h buffer.h line.h retcode.h utf8.h defines.h \
display.h estruct.h execute.h fileio.h input.h bind.h lock.h mlout.h \
window.h
fileio.o: fileio.c fileio.h defines.h retcode.h utf8.h
flook.o: flook.c flook.h retcode.h defines.h fileio.h
input.o: input.c input.h bind.h estruct.h bindable.h display.h utf8.h \
exec.h retcode.h names.h terminal.h defines.h wrapper.h
isearch.o: isearch.c isearch.h basic.h retcode.h buffer.h line.h utf8.h \
display.h estruct.h exec.h input.h bind.h search.h terminal.h defines.h \
window.h
line.o: line.c line.h retcode.h utf8.h buffer.h estruct.h mlout.h \
window.h defines.h
lock.o: lock.c estruct.h lock.h
main.o: main.c estruct.h basic.h bind.h bindable.h buffer.h crypt.h \
line.h retcode.h utf8.h display.h eval.h execute.h file.h input.h lock.h \
mlout.h random.h search.h terminal.h defines.h termio.h version.h \
window.h
main.o: main.c estruct.h basic.h retcode.h bind.h bindable.h buffer.h \
line.h utf8.h display.h eval.h execute.h file.h lock.h mlout.h random.h \
search.h terminal.h defines.h termio.h version.h window.h
mingw32.o: mingw32.c
mlout.o: mlout.c mlout.h
names.o: names.c names.h basic.h bind.h bindable.h buffer.h crypt.h \
line.h retcode.h utf8.h display.h estruct.h eval.h exec.h file.h \
isearch.h region.h random.h search.h spawn.h window.h defines.h word.h
names.o: names.c names.h basic.h retcode.h bind.h bindable.h buffer.h \
line.h utf8.h display.h estruct.h eval.h exec.h file.h isearch.h \
region.h random.h search.h spawn.h window.h defines.h word.h
pklock.o: pklock.c estruct.h pklock.h
posix.o: posix.c termio.h estruct.h retcode.h utf8.h
random.o: random.c random.h basic.h buffer.h crypt.h line.h retcode.h \
utf8.h display.h estruct.h execute.h input.h bind.h search.h terminal.h \
posix.o: posix.c
random.o: random.c random.h retcode.h basic.h buffer.h line.h utf8.h \
display.h estruct.h execute.h input.h bind.h search.h terminal.h \
defines.h window.h
region.o: region.c region.h line.h retcode.h utf8.h buffer.h crypt.h \
estruct.h mlout.h random.h window.h defines.h
region.o: region.c region.h line.h retcode.h utf8.h buffer.h estruct.h \
mlout.h random.h window.h defines.h
search.o: search.c search.h line.h retcode.h utf8.h basic.h buffer.h \
crypt.h display.h estruct.h input.h bind.h mlout.h terminal.h defines.h \
display.h estruct.h input.h bind.h mlout.h terminal.h defines.h window.h
spawn.o: spawn.c spawn.h defines.h buffer.h line.h retcode.h utf8.h \
display.h estruct.h exec.h file.h flook.h input.h bind.h terminal.h \
window.h
spawn.o: spawn.c spawn.h defines.h buffer.h crypt.h line.h retcode.h \
utf8.h display.h estruct.h exec.h file.h flook.h input.h bind.h \
terminal.h window.h
tcap.o: tcap.c terminal.h defines.h retcode.h display.h estruct.h \
tcap.o: tcap.c terminal.h defines.h retcode.h utf8.h display.h estruct.h \
termio.h
termio.o: termio.c
termio.o: termio.c termio.h utf8.h estruct.h retcode.h
utf8.o: utf8.c utf8.h
window.o: window.c window.h defines.h buffer.h crypt.h line.h retcode.h \
utf8.h basic.h display.h estruct.h execute.h terminal.h wrapper.h
word.o: word.c word.h basic.h buffer.h crypt.h line.h retcode.h utf8.h \
estruct.h mlout.h random.h region.h window.h defines.h
window.o: window.c window.h defines.h buffer.h line.h retcode.h utf8.h \
basic.h display.h estruct.h execute.h terminal.h wrapper.h
word.o: word.c word.h basic.h retcode.h buffer.h line.h utf8.h estruct.h \
mlout.h random.h region.h window.h defines.h
wrapper.o: wrapper.c wrapper.h
wscreen.o: wscreen.c wscreen.h

View File

@@ -1,6 +1,6 @@
# README #
Ciguë is µEMACS (ue) on Cygwin/Linux, based on uEmacs/PK (em) from kernel.org.
µEMACS (ue) on Cygwin/Linux, based on uEmacs/PK (em) from kernel.org.
### Changes compare to uEmacs/PK ###
* Line termination detection with new buffer mode (either Unix or DOS).
@@ -11,7 +11,7 @@ Ciguë is µEMACS (ue) on Cygwin/Linux, based on uEmacs/PK (em) from kernel.org.
* Some defaults changed due to 'finger habits': ue instead of em, ^S in commands mapping...
### How to build ###
* dependencies: ncurses.
* dependencies: gmake, ncurses.
* make depend ; make
* MINGW32 target is experimental and lacks screen/kbd support.

318
basic.c
View File

@@ -2,8 +2,6 @@
#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
@@ -18,19 +16,18 @@
#include <stdio.h>
#include <stdlib.h>
#include "buffer.h"
#include "estruct.h"
#include "input.h"
#include "line.h"
#include "mlout.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 */
#define CVMVAS 1 /* arguments to page forward/back in pages */
int overlap = DEFAULT_OVERLAP ; /* line overlap in forw/back page */
int curgoal ; /* Goal for C-P, C-N */
/*
@@ -38,7 +35,7 @@ int curgoal ; /* Goal for C-P, C-N */
* column, return the best choice for the offset. The offset is returned.
* Used by "C-N" and "C-P".
*/
static unsigned getgoal( struct line *dlp) {
static unsigned getgoal( line_p dlp) {
int col ;
unsigned idx ;
const unsigned len = llength( dlp) ;
@@ -51,13 +48,14 @@ static unsigned getgoal( struct line *dlp) {
/* Take tabs, ^X and \xx hex characters into account */
if( c == '\t')
col |= tabmask ;
col += tabwidth - col % tabwidth ;
else if( c < 0x20 || c == 0x7F)
col += 1 ;
else if( c >= 0x80 && c <= 0xA0)
col += 2 ;
else if( c >= 0x80 && c <= 0xA0)
col += 3 ;
else
col += 1 ;
col += 1 ;
if( col > curgoal)
break ;
@@ -68,21 +66,117 @@ static unsigned getgoal( struct line *dlp) {
}
/*
* Move the cursor to the beginning of the current line.
* Move the cursor to the beginning of the current line of active window.
*/
int gotobol(int f, int n)
{
curwp->w_doto = 0;
return TRUE;
boolean gotobol( int f, int n) {
curwp->w_doto = 0 ;
return TRUE ;
}
/*
* Move the cursor to the end of the current line. Trivial. No errors.
* Move the cursor to the end of the current line of active window.
*/
int gotoeol(int f, int n)
{
curwp->w_doto = llength(curwp->w_dotp);
return TRUE;
boolean gotoeol( int f, int n) {
curwp->w_doto = llength( curwp->w_dotp) ;
return TRUE ;
}
/*
* Goto the beginning of the buffer. Massive adjustment of dot. This is
* considered to be hard motion; it really isn't if the original value of dot
* is the same as the new value of dot. Normally bound to "M-<".
*/
boolean gotobob( int f, int n) {
curwp->w_dotp = lforw( curbp->b_linep) ;
curwp->w_doto = 0 ;
curwp->w_flag |= WFHARD ;
return TRUE ;
}
/*
* Move to the end of the buffer. Dot is always put at the end of the file
* (ZJ). The standard screen code does most of the hard parts of update.
* Bound to "M->".
*/
boolean gotoeob( int f, int n) {
curwp->w_dotp = curbp->b_linep ;
curwp->w_doto = 0 ;
curwp->w_flag |= WFHARD ;
return TRUE ;
}
/*
* Move forward by full lines. If the number of lines to move is less than
* zero, call the backward line function to actually do it. The last command
* controls how the goal column is set. Bound to "C-N". No errors are
* possible.
*/
boolean forwline( int f, int n) {
line_p dlp ;
if (n < 0)
return backline(f, -n);
/* if we are on the last line as we start....fail the command */
if (curwp->w_dotp == curbp->b_linep)
return FALSE;
/* if the last command was not a line move, reset the goal column */
if ((lastflag & CFCPCN) == 0)
curgoal = getccol(FALSE);
/* flag this command as a line move */
thisflag |= CFCPCN;
/* and move the point down */
dlp = curwp->w_dotp;
while( n && dlp != curbp->b_linep) {
dlp = lforw( dlp) ;
n -= 1 ;
}
/* reseting the current position */
curwp->w_dotp = dlp;
curwp->w_doto = getgoal(dlp);
curwp->w_flag |= WFMOVE;
return (n == 0) ? TRUE : FALSE ;
}
/*
* This function is like "forwline", but goes backwards. The scheme is exactly
* the same. Check for arguments that are less than zero and call your
* alternate. Figure out the new line and call "movedot" to perform the
* motion. No errors are possible. Bound to "C-P".
*/
boolean backline( int f, int n) {
line_p dlp ;
if (n < 0)
return forwline(f, -n);
/* if we are on the first line as we start....fail the command */
if (lback(curwp->w_dotp) == curbp->b_linep)
return FALSE;
/* if the last command was not a line move, reset the goal column */
if ((lastflag & CFCPCN) == 0)
curgoal = getccol(FALSE);
/* flag this command as a line move */
thisflag |= CFCPCN;
/* and move the point up */
dlp = curwp->w_dotp;
while( n && lback( dlp) != curbp->b_linep) {
dlp = lback( dlp) ;
n -= 1 ;
}
/* reseting the current position */
curwp->w_dotp = dlp;
curwp->w_doto = getgoal(dlp);
curwp->w_flag |= WFMOVE;
return (n == 0) ? TRUE : FALSE ;
}
/*
@@ -119,107 +213,7 @@ int gotoline( int f, int n) {
/* First, we go to the begin of the buffer. */
gotobob(f, n);
return forwline(f, n - 1);
}
/*
* Goto the beginning of the buffer. Massive adjustment of dot. This is
* considered to be hard motion; it really isn't if the original value of dot
* is the same as the new value of dot. Normally bound to "M-<".
*/
int gotobob(int f, int n)
{
curwp->w_dotp = lforw(curbp->b_linep);
curwp->w_doto = 0;
curwp->w_flag |= WFHARD;
return TRUE;
}
/*
* Move to the end of the buffer. Dot is always put at the end of the file
* (ZJ). The standard screen code does most of the hard parts of update.
* Bound to "M->".
*/
int gotoeob(int f, int n)
{
curwp->w_dotp = curbp->b_linep;
curwp->w_doto = 0;
curwp->w_flag |= WFHARD;
return TRUE;
}
/*
* Move forward by full lines. If the number of lines to move is less than
* zero, call the backward line function to actually do it. The last command
* controls how the goal column is set. Bound to "C-N". No errors are
* possible.
*/
int forwline(int f, int n)
{
struct line *dlp;
if (n < 0)
return backline(f, -n);
/* if we are on the last line as we start....fail the command */
if (curwp->w_dotp == curbp->b_linep)
return FALSE;
/* if the last command was not note a line move,
reset the goal column */
if ((lastflag & CFCPCN) == 0)
curgoal = getccol(FALSE);
/* flag this command as a line move */
thisflag |= CFCPCN;
/* and move the point down */
dlp = curwp->w_dotp;
while (n-- && dlp != curbp->b_linep)
dlp = lforw(dlp);
/* reseting the current position */
curwp->w_dotp = dlp;
curwp->w_doto = getgoal(dlp);
curwp->w_flag |= WFMOVE;
return TRUE;
}
/*
* This function is like "forwline", but goes backwards. The scheme is exactly
* the same. Check for arguments that are less than zero and call your
* alternate. Figure out the new line and call "movedot" to perform the
* motion. No errors are possible. Bound to "C-P".
*/
int backline(int f, int n)
{
struct line *dlp;
if (n < 0)
return forwline(f, -n);
/* if we are on the last line as we start....fail the command */
if (lback(curwp->w_dotp) == curbp->b_linep)
return FALSE;
/* if the last command was not note a line move,
reset the goal column */
if ((lastflag & CFCPCN) == 0)
curgoal = getccol(FALSE);
/* flag this command as a line move */
thisflag |= CFCPCN;
/* and move the point up */
dlp = curwp->w_dotp;
while (n-- && lback(dlp) != curbp->b_linep)
dlp = lback(dlp);
/* reseting the current position */
curwp->w_dotp = dlp;
curwp->w_doto = getgoal(dlp);
curwp->w_flag |= WFMOVE;
return TRUE;
return (n == 1) ? TRUE : forwline( f, n - 1) ;
}
/*
@@ -228,20 +222,20 @@ int backline(int f, int n)
* the overlap; this value is the default overlap value in ITS EMACS. Because
* this zaps the top line in the display window, we have to do a hard update.
*/
int forwpage(int f, int n)
{
struct line *lp;
boolean forwpage( int f, int n) {
line_p lp ;
if (f == FALSE) {
#if SCROLLCODE
if (term.t_scroll != NULL)
if (overlap == 0)
n = curwp->w_ntrows / 3 * 2;
if (term.t_scroll != NULL) /* $scroll == FALSE */
if (overlap == 0) /* $overlap == 0 */
n = curwp->w_ntrows * 2 / 3 ;
else
n = curwp->w_ntrows - overlap;
else
#endif
n = curwp->w_ntrows - 2; /* Default scroll. */
if (n <= 0) /* Forget the overlap. */
n = 1; /* If tiny window. */
} else if (n < 0)
@@ -250,12 +244,19 @@ int forwpage(int f, int n)
else /* Convert from pages. */
n *= curwp->w_ntrows; /* To lines. */
#endif
lp = curwp->w_linep;
while (n-- && lp != curbp->b_linep)
lp = lforw(lp);
curwp->w_linep = lp;
/* lp = curwp->w_linep; */
lp = curwp->w_dotp ;
while( n && lp != curbp->b_linep) {
lp = lforw( lp) ;
n -= 1 ;
}
/* curwp->w_linep = lp; */
curwp->w_dotp = lp;
curwp->w_doto = 0;
reposition( TRUE, 0) ;
#if SCROLLCODE
curwp->w_flag |= WFHARD | WFKILLS;
#else
@@ -270,20 +271,28 @@ int forwpage(int f, int n)
* EMACS manual. Bound to "M-V". We do a hard update for exactly the same
* reason.
*/
int backpage(int f, int n)
{
struct line *lp;
boolean backpage( int f, int n) {
line_p lp ;
if (f == FALSE) { /* interactive, default n = 1 supplied */
/* in interactive mode, first move dot to top of window */
if( curwp->w_dotp != curwp->w_linep) {
curwp->w_dotp = curwp->w_linep ;
curwp->w_doto = 0 ;
/* curwp->w_flag |= WFMOVE ; */
return TRUE ;
}
if (f == FALSE) {
#if SCROLLCODE
if (term.t_scroll != NULL)
if (overlap == 0)
n = curwp->w_ntrows / 3 * 2;
if (term.t_scroll != NULL) /* $scroll != FALSE */
if (overlap == 0) /* $overlap == 0 */
n = curwp->w_ntrows * 2 / 3 ;
else
n = curwp->w_ntrows - overlap;
else
#endif
n = curwp->w_ntrows - 2; /* Default scroll. */
if (n <= 0) /* Don't blow up if the. */
n = 1; /* Window is tiny. */
} else if (n < 0)
@@ -292,12 +301,19 @@ int backpage(int f, int n)
else /* Convert from pages. */
n *= curwp->w_ntrows; /* To lines. */
#endif
lp = curwp->w_linep;
while (n-- && lback(lp) != curbp->b_linep)
lp = lback(lp);
curwp->w_linep = lp;
/* lp = curwp->w_linep; */
lp = curwp->w_dotp ;
while( n && lback( lp) != curbp->b_linep) {
lp = lback( lp) ;
n -= 1 ;
}
/* curwp->w_linep = lp; */
curwp->w_dotp = lp;
curwp->w_doto = 0;
reposition( TRUE, (f == FALSE) ? 1 : 0) ;
#if SCROLLCODE
curwp->w_flag |= WFHARD | WFINS;
#else
@@ -310,8 +326,7 @@ int backpage(int f, int n)
* Set the mark in the current window to the value of "." in the window. No
* errors are possible. Bound to "M-.".
*/
int setmark(int f, int n)
{
boolean setmark( int f, int n) {
curwp->w_markp = curwp->w_dotp;
curwp->w_marko = curwp->w_doto;
mloutstr( "(Mark set)") ;
@@ -320,13 +335,12 @@ int setmark(int f, int n)
/*
* Swap the values of "." and "mark" in the current window. This is pretty
* easy, bacause all of the hard work gets done by the standard routine
* easy, because all of the hard work gets done by the standard routine
* that moves the mark about. The only possible error is "no mark". Bound to
* "C-X C-X".
*/
int swapmark(int f, int n)
{
struct line *odotp;
boolean swapmark( int f, int n) {
line_p odotp ;
int odoto;
if( curwp->w_markp == NULL) {
@@ -343,3 +357,5 @@ int swapmark(int f, int n)
curwp->w_flag |= WFMOVE;
return TRUE;
}
/* end of basic.c */

37
basic.h
View File

@@ -1,20 +1,35 @@
/* basic.h -- basic commands for cursor movement in active window */
#ifndef _BASIC_H_
#define _BASIC_H_
#include "retcode.h"
/*
** $overlap is the size of the line overlap when kbd calls page forw/back
** if 0, page will move by 2/3 of the window size (1/3 page overlap)
** default to 0
*/
#define DEFAULT_OVERLAP 0
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) ;
/* $target (== curgoal) is the column target when doing line move */
extern int curgoal ; /* Goal for C-P previous-line, C-N next-line */
boolean gotobol( int f, int n) ;
boolean 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) ;
boolean gotobob( int f, int n) ;
boolean gotoeob( int f, int n) ;
boolean forwline( int f, int n) ;
boolean backline( int f, int n) ;
boolean forwpage( int f, int n) ;
boolean backpage( int f, int n) ;
boolean setmark( int f, int n) ;
boolean swapmark( int f, int n) ;
#endif
/* end of basic.h */

27
bind.c
View File

@@ -44,7 +44,6 @@ int help(int f, int n)
{ /* give me some help!!!!
bring up a fake buffer and read the help file
into it with view mode */
struct window *wp; /* scaning pointer to windows */
struct buffer *bp; /* buffer pointer to help */
char *fname = NULL; /* ptr to file returned by flook() */
@@ -73,11 +72,7 @@ int help(int f, int n)
/* make this window in VIEW mode, update all mode lines */
curwp->w_bufp->b_mode |= MDVIEW;
curwp->w_bufp->b_flag |= BFINVS;
wp = wheadp;
while (wp != NULL) {
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
upmode() ;
return TRUE;
}
@@ -387,15 +382,11 @@ static int buildlist( char *mstring) {
}
}
curwp->w_bufp->b_mode |= MDVIEW; /* put this buffer view mode */
curbp->b_flag &= ~BFCHG; /* don't flag this as a change */
bp->b_mode |= MDVIEW; /* put this buffer view mode */
bp->b_flag &= ~BFCHG; /* don't flag this as a change */
wp->w_dotp = lforw(bp->b_linep); /* back to the beginning */
wp->w_doto = 0;
wp = wheadp; /* and update ALL mode lines */
while (wp != NULL) {
wp->w_flag |= WFMODE;
wp = wp->w_wndp;
}
upmode() ; /* and update ALL mode lines */
mlwrite(""); /* clear the mode line */
return TRUE;
}
@@ -465,14 +456,14 @@ static unsigned int getckey( int mflag) {
* char *fname; name of startup file (null if default)
*/
int startup( const char *fname) {
if( !fname || *fname == 0) /* use default if empty parameter */
fname = rcfname ;
if( !fname || *fname == 0) /* use default if empty parameter */
fname = rcfname ;
fname = flook( fname, TRUE) ; /* look up the startup file */
if( fname == NULL) /* if it isn't around, don't sweat it */
return TRUE ;
if( fname == NULL) /* if it isn't around, don't sweat it */
return TRUE ;
return dofile( fname) ; /* otherwise, execute the sucker */
return dofile( fname) ; /* otherwise, execute the sucker */
}
/*

68
blindmaz.cmd Normal file
View File

@@ -0,0 +1,68 @@
## blindmaz.cmd -- solve maze by walking a left-handed blind mouse
#7 set $seed
execute-file maze.cmd
#execute-file floodmaz.cmd
set %x 2
set %y $curline
end-of-line
set %stopcol &sub $curcol 1
set %DX0 1
set %DY0 0
set %DX1 0
set %DY1 1
set %DX2 -1
set %DY2 0
set %DX3 0
set %DY3 -1
set %dotc &asc "."
12 store-macro
set %OX &ind &cat "%DX" %nD
set %OY &ind &cat "%DY" %nD
set %nx &add %x %OX
set %ny &add %y %OY
set $curline %ny
set $curcol %nx
!if &or &equ $curchar 32 &equ $curchar %dotc
!if &equ $curchar 32
set %C %dotc
!else
set %C &asc " " # erase when backtracking (or highlight)
!endif
set %D %nD
set $curchar %C
set $curline %y
set $curcol %x
set $curchar %C
set %x &add %nx %OX
set %y &add %ny %OY
set $curline %y
set $curcol %x
set %res TRUE
!else
set %res FALSE
!endif
!endm
set %D 0 # looking EAST
!while &les %x %stopcol
set %nD &mod &add %D 3 4 # Can go left?
execute-macro-12
!if &seq %res FALSE
set %nD %D # Can go straight?
execute-macro-12
!if &seq %res FALSE
set %nD &mod &add %D 1 4 # Can go right?
execute-macro-12
!if &seq %res FALSE
set %D &mod &add %D 2 4 # Go back!
!endif
!endif
!endif
!endwhile
beginning-of-file
set $curline 3
set $curcol 1

192
buffer.c
View File

@@ -29,21 +29,13 @@ struct buffer *bheadp ; /* Head of list of buffers */
struct buffer *blistp ; /* Buffer for C-X C-B */
const char *modename[] = { /* name of modes */
"Wrap", "Cmode", "Spell", "Exact", "View", "Over",
"Wrap", "Cmode", "Exact", "View", "Over",
"Magic",
#if CRYPT
"Crypt",
#else
"",
#endif
"Asave", "Utf-8", "Dos"
} ;
int gmode = 0 ; /* global editor mode */
static const char modecode[] = "WCSEVOMYAUD" ; /* letters to represent modes */
static int makelist( int iflag) ;
static int addline( char *text) ;
static void l_to_a( char *buf, int width, long num) ;
@@ -254,7 +246,9 @@ ask:
bp = bp->b_bufp ; /* onward */
}
strcpy( curbp->b_bname, bufn) ; /* copy buffer name to structure */
/* copy buffer name to structure */
strncpy( curbp->b_bname, bufn, sizeof( bname_t) - 1) ;
curbp->b_bname[ sizeof( bname_t) - 1] = '\0' ;
free( bufn) ;
curwp->w_flag |= WFMODE ; /* make mode line replot */
@@ -275,12 +269,13 @@ ask:
int listbuffers(int f, int n)
{
struct window *wp;
struct buffer *bp;
int s;
if ((s = makelist(f)) != TRUE)
return s;
if (blistp->b_nwnd == 0) { /* Not on screen yet. */
struct buffer *bp ;
if ((wp = wpopup()) == NULL)
return FALSE;
bp = wp->w_bufp;
@@ -319,123 +314,101 @@ int listbuffers(int f, int n)
*
* int iflag; list hidden buffer flag
*/
#define MAXLINE MAXCOL
/* Layout: "ACT MODES Size Buffer File"
AAA MMMMMMMMMSSSSSSSSSS BBBBBBBBBBBBBBB FFF...
FNAMSTART ---------------------------------------^
*/
#define FNAMSTART (3 + 1 + NUMMODES + 10 + 1 + (sizeof( bname_t) - 1) + 1)
static void do_layout( char *line, int mode) {
int i ;
/* build line to report global mode settings */
strcpy( line, " WCEVOMAUD Global Modes") ;
/* output the mode codes */
for( i = 0 ; i < NUMMODES ; i++)
if( 0 == (mode & (1 << i)))
line[ 4 + i] = '.' ;
}
static int makelist( int iflag)
{
char *cp1;
char *cp2;
int c;
struct buffer *bp;
struct line *lp;
int s;
int i;
long nbytes; /* # of bytes in current buffer */
long nlines ; /* # of lines in current buffer */
char b[ 8 + 1] ;
char line[MAXLINE];
char line[ FNAMSTART + sizeof( fname_t)] ;
blistp->b_flag &= ~BFCHG; /* Don't complain! */
blistp->b_flag &= ~BFCHG; /* Don't complain! Mute bclear() */
if ((s = bclear(blistp)) != TRUE) /* Blow old text away */
return s;
strcpy(blistp->b_fname, "");
blistp->b_fname[ 0] = 0 ; /* in case of user override */
if( addline("ACT MODES Size Buffer File") == FALSE
|| addline("‾‾‾ ‾‾‾‾‾ ‾‾‾‾ ‾‾‾‾‾‾ ‾‾‾‾") == FALSE)
return FALSE;
bp = bheadp; /* For all buffers */
/* build line to report global mode settings */
cp1 = &line[0];
*cp1++ = ' ';
*cp1++ = ' ';
*cp1++ = ' ';
*cp1++ = ' ';
/* report global mode settings */
do_layout( line, gmode) ;
if( addline( line) == FALSE)
return FALSE ;
/* output the mode codes */
for (i = 0; i < NUMMODES; i++)
if (gmode & (1 << i))
*cp1++ = modecode[i];
else
*cp1++ = '.';
strcpy(cp1, " Global Modes");
if (addline(line) == FALSE)
return FALSE;
/* output the list of buffers */
for( bp = bheadp ; bp != NULL ; bp = bp->b_bufp) { /* For all buffers */
char *cp1, *cp2 ;
int c ;
struct line *lp ;
long nbytes ; /* # of bytes in current buffer */
long nlines ; /* # of lines in current buffer */
/* output the list of buffers */
while (bp != NULL) {
/* skip invisable buffers if iflag is false */
if (((bp->b_flag & BFINVS) != 0) && (iflag != TRUE)) {
bp = bp->b_bufp;
/* skip invisible buffers if iflag is false */
if (((bp->b_flag & BFINVS) != 0) && (iflag != TRUE))
continue;
}
cp1 = &line[0]; /* Start at left edge */
/* output status of ACTIVE flag (has the file been read in? */
if (bp->b_active == TRUE) /* "@" if activated */
*cp1++ = '@';
else
*cp1++ = ' ';
do_layout( line, bp->b_mode) ;
cp1 = line ; /* Start at left edge */
/* output status of changed flag */
if ((bp->b_flag & BFCHG) != 0) /* "*" if changed */
*cp1++ = '*';
else
*cp1++ = ' ';
/* output status of ACTIVE flag ('@' when the file has been read in) */
*cp1++ = (bp->b_active == TRUE) ? '@' : ' ' ;
/* report if the file is truncated */
if ((bp->b_flag & BFTRUNC) != 0)
*cp1++ = '#';
else
*cp1++ = ' ';
/* report if the file is truncated */
*cp1++ = ((bp->b_flag & BFTRUNC) != 0) ? '#' : ' ' ;
*cp1++ = ' '; /* space */
/* output status of changed flag ('*' when the buffer is changed) */
*cp1 = ((bp->b_flag & BFCHG) != 0) ? '*' : ' ' ;
/* output the mode codes */
for (i = 0; i < NUMMODES; i++) {
if (bp->b_mode & (1 << i))
*cp1++ = modecode[i];
else
*cp1++ = '.';
}
/* No gap as buffer size if left padded with space */
/* Buffer size */
nbytes = 0L; /* Count bytes in buf. */
nlines = 0 ;
lp = lforw(bp->b_linep);
while (lp != bp->b_linep) {
for( lp = lforw( bp->b_linep) ; lp != bp->b_linep ; lp = lforw( lp)) {
nbytes += (long) llength(lp) + 1L;
nlines += 1 ;
lp = lforw(lp);
}
if( bp->b_mode & MDDOS)
nbytes += nlines ;
l_to_a( b, sizeof b, nbytes) ; /* 8 digits string buffer size. */
cp2 = &b[0];
while ((c = *cp2++) != 0)
*cp1++ = c;
*cp1++ = ' '; /* Gap. */
l_to_a( &line[ 13], 10 + 1, nbytes) ; /* "%10d" formatted numbers */
cp1 = &line[ 23] ;
*cp1++ = ' ' ;
cp2 = &bp->b_bname[0]; /* Buffer name */
while ((c = *cp2++) != 0)
*cp1++ = c;
cp2 = &bp->b_fname[0]; /* File name */
if (*cp2 != 0) {
while( cp1 < &line[ 3 + 1 + NUMMODES + 8 + 1 + (NBUFN-1) + 1])
*cp1++ = ' ';
while ((c = *cp2++) != 0) {
if (cp1 < &line[MAXLINE - 1])
*cp1++ = c;
}
}
*cp1 = 0; /* Add to the buffer. */
if (addline(line) == FALSE)
return FALSE;
bp = bp->b_bufp;
if( bp->b_fname[ 0] != 0) {
while( cp1 < &line[ FNAMSTART])
*cp1++ = ' ' ;
strncpy( cp1, bp->b_fname, &line[ sizeof line - 1] - cp1) ;
line[ sizeof line - 1] = 0 ;
} else
*cp1 = 0 ; /* Terminate string */
if( addline( line) == FALSE) /* Add to the buffer. */
return FALSE ;
}
return TRUE; /* All done */
return TRUE ; /* All done */
}
static void l_to_a(char *buf, int width, long num)
@@ -511,15 +484,12 @@ int anycb(void)
struct buffer *bfind( const char *bname, int cflag, int bflag)
{
struct buffer *bp;
struct buffer *sb; /* buffer to insert after */
struct line *lp;
bp = bheadp;
while (bp != NULL) {
if (strcmp(bname, bp->b_bname) == 0)
return bp;
bp = bp->b_bufp;
}
for( bp = bheadp ; bp != NULL ; bp = bp->b_bufp)
if( strcmp( bname, bp->b_bname) == 0)
return bp ;
if (cflag != FALSE) {
if ((bp = (struct buffer *)malloc(sizeof(struct buffer))) == NULL)
return NULL;
@@ -533,16 +503,15 @@ struct buffer *bfind( const char *bname, int cflag, int bflag)
bp->b_bufp = bheadp;
bheadp = bp;
} else {
sb = bheadp;
while (sb->b_bufp != NULL) {
if (strcmp(sb->b_bufp->b_bname, bname) > 0)
break;
sb = sb->b_bufp;
}
struct buffer *sb; /* buffer to insert after */
for( sb = bheadp ; sb->b_bufp != NULL ; sb = sb->b_bufp)
if( strcmp( sb->b_bufp->b_bname, bname) > 0)
break ;
/* and insert it */
bp->b_bufp = sb->b_bufp;
sb->b_bufp = bp;
bp->b_bufp = sb->b_bufp ;
sb->b_bufp = bp ;
}
/* and set up the other buffer fields */
@@ -558,9 +527,6 @@ struct buffer *bfind( const char *bname, int cflag, int bflag)
bp->b_fname[ 0] = '\0' ;
strncpy( bp->b_bname, bname, sizeof( bname_t) - 1) ;
bp->b_bname[ sizeof( bname_t) - 1] = '\0' ;
#if CRYPT
bp->b_key[0] = 0;
#endif
lp->l_fp = lp;
lp->l_bp = lp;
}

View File

@@ -1,16 +1,10 @@
#ifndef _BUFFER_H_
#define _BUFFER_H_
#include "crypt.h"
#include "line.h"
typedef char fname_t[ 80] ; /* file name type */
typedef char bname_t[ 16] ; /* buffer name type */
#define NBUFN sizeof( bname_t)
#if CRYPT
typedef char ekey_t[ 128] ; /* encryption key type */
#endif
typedef char fname_t[ 256] ; /* file name type */
typedef char bname_t[ 16] ; /* buffer name type */
/*
* Text is kept in buffers. A buffer header, described below, exists for every
@@ -36,9 +30,6 @@ struct buffer {
char b_flag; /* Flags */
fname_t b_fname ; /* File name */
bname_t b_bname ; /* Buffer name */
#if CRYPT
ekey_t b_key ; /* current encrypted key */
#endif
};
extern struct buffer *curbp ; /* Current buffer */
@@ -50,21 +41,17 @@ extern struct buffer *blistp ; /* Buffer for C-X C-B */
#define BFTRUNC 0x04 /* buffer was truncated when read */
/* mode flags */
#define NUMMODES 11 /* # of defined modes */
#define NUMMODES 9 /* # of defined modes */
#define MDWRAP 0x0001 /* word wrap */
#define MDCMOD 0x0002 /* C indentation and fence match */
#define MDSPELL 0x0004 /* spell error parcing */
#define MDEXACT 0x0008 /* Exact matching for searches */
#define MDVIEW 0x0010 /* read-only buffer */
#define MDOVER 0x0020 /* overwrite mode */
#define MDMAGIC 0x0040 /* regular expresions in search */
#if CRYPT
#define MDCRYPT 0x0080 /* encrytion mode active */
#endif
#define MDASAVE 0x0100 /* auto-save mode */
#define MDUTF8 0x0200 /* utf8 mode */
#define MDDOS 0x0400 /* CRLF eol mode */
#define MDEXACT 0x0004 /* Exact matching for searches */
#define MDVIEW 0x0008 /* read-only buffer */
#define MDOVER 0x0010 /* overwrite mode */
#define MDMAGIC 0x0020 /* regular expresions in search */
#define MDASAVE 0x0040 /* auto-save mode */
#define MDUTF8 0x0080 /* utf8 mode */
#define MDDOS 0x0100 /* CRLF eol mode */
extern const char *modename[] ; /* text names of modes */

190
crypt.c
View File

@@ -1,190 +0,0 @@
/* crypt.c -- implements crypt.h */
#include "crypt.h"
/* CRYPT.C
*
* Encryption routines
*
* written by Dana Hoggatt and Daniel Lawrence
*/
#if CRYPT
#include <stdio.h>
static int mod95(int);
/**********
*
* myencrypt - in place encryption/decryption of a buffer
*
* (C) Copyright 1986, Dana L. Hoggatt
* 1216, Beck Lane, Lafayette, IN
*
* When consulting directly with the author of this routine,
* please refer to this routine as the "DLH-POLY-86-B CIPHER".
*
* This routine was written for Dan Lawrence, for use in V3.8 of
* MicroEMACS, a public domain text/program editor.
*
* I kept the following goals in mind when preparing this function:
*
* 1. All printable characters were to be encrypted back
* into the printable range, control characters and
* high-bit characters were to remain unaffected. this
* way, encrypted would still be just as cheap to
* transmit down a 7-bit data path as they were before.
*
* 2. The encryption had to be portable. The encrypted
* file from one computer should be able to be decrypted
* on another computer.
*
* 3. The encryption had to be inexpensive, both in terms
* of speed and space.
*
* 4. The system needed to be secure against all but the
* most determined of attackers.
*
* For encryption of a block of data, one calls myencrypt passing
* a pointer to the data block and its length. The data block is
* encrypted in place, that is, the encrypted output overwrites
* the input. Decryption is totally isomorphic, and is performed
* in the same manner by the same routine.
*
* Before using this routine for encrypting data, you are expected
* to specify an encryption key. This key is an arbitrary string,
* to be supplied by the user. To set the key takes two calls to
* myencrypt(). First, you call
*
* myencrypt(NULL, vector)
*
* This resets all internal control information. Typically (and
* specifically in the case on MICRO-emacs) you would use a "vector"
* of 0. Other values can be used to customize your editor to be
* "incompatable" with the normally distributed version. For
* this purpose, the best results will be obtained by avoiding
* multiples of 95.
*
* Then, you "encrypt" your password by calling
*
* myencrypt(pass, strlen(pass))
*
* where "pass" is your password string. Myencrypt() will destroy
* the original copy of the password (it becomes encrypted),
* which is good. You do not want someone on a multiuser system
* to peruse your memory space and bump into your password.
* Still, it is a better idea to erase the password buffer to
* defeat memory perusal by a more technical snooper.
*
* For the interest of cryptologists, at the heart of this
* function is a Beaufort Cipher. The cipher alphabet is the
* range of printable characters (' ' to '~'), all "control"
* and "high-bit" characters are left unaltered.
*
* The key is a variant autokey, derived from a wieghted sum
* of all the previous clear text and cipher text. A counter
* is used as salt to obiterate any simple cyclic behavior
* from the clear text, and key feedback is used to assure
* that the entire message is based on the original key,
* preventing attacks on the last part of the message as if
* it were a pure autokey system.
*
* Overall security of encrypted data depends upon three
* factors: the fundamental cryptographic system must be
* difficult to compromise; exhaustive searching of the key
* space must be computationally expensive; keys and plaintext
* must remain out of sight. This system satisfies this set
* of conditions to within the degree desired for MicroEMACS.
*
* Though direct methods of attack (against systems such as
* this) do exist, they are not well known and will consume
* considerable amounts of computing time. An exhaustive
* search requires over a billion investigations, on average.
*
* The choice, entry, storage, manipulation, alteration,
* protection and security of the keys themselves are the
* responsiblity of the user.
*
*
* char *bptr; buffer of characters to be encrypted
* unsigned len; number of characters in the buffer
*
**********/
void myencrypt(char *bptr, unsigned len)
{
int cc; /* current character being considered */
static long key = 0; /* 29 bit encipherment key */
static int salt = 0; /* salt to spice up key with */
if (!bptr) { /* is there anything here to encrypt? */
key = len; /* set the new key */
salt = len; /* set the new salt */
return;
}
while (len--) { /* for every character in the buffer */
cc = *bptr; /* get a character out of the buffer */
/* only encipher printable characters */
if ((cc >= ' ') && (cc <= '~')) {
/** If the upper bit (bit 29) is set, feed it back into the key. This
assures us that the starting key affects the entire message. **/
key &= 0x1FFFFFFFL; /* strip off overflow */
if (key & 0x10000000L) {
key ^= 0x0040A001L; /* feedback */
}
/** Down-bias the character, perform a Beaufort encipherment, and
up-bias the character again. We want key to be positive
so that the left shift here will be more portable and the
mod95() faster **/
cc = mod95((int) (key % 95) - (cc - ' ')) + ' ';
/** the salt will spice up the key a little bit, helping to obscure
any patterns in the clear text, particularly when all the
characters (or long sequences of them) are the same. We do
not want the salt to go negative, or it will affect the key
too radically. It is always a good idea to chop off cyclics
to prime values. **/
if (++salt >= 20857) { /* prime modulus */
salt = 0;
}
/** our autokey (a special case of the running key) is being
generated by a wieghted checksum of clear text, cipher
text, and salt. **/
key = key + key + cc + *bptr + salt;
}
*bptr++ = cc; /* put character back into buffer */
}
return;
}
static int mod95(int val)
{
/* The mathematical MOD does not match the computer MOD */
/* Yes, what I do here may look strange, but it gets the
job done, and portably at that. */
while (val >= 9500)
val -= 9500;
while (val >= 950)
val -= 950;
while (val >= 95)
val -= 95;
while (val < 0)
val += 95;
return val;
}
#endif

10
crypt.h
View File

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

View File

@@ -15,15 +15,10 @@
#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) */
/* Actual 380x134 on a 1920x1080 screen in landscape,
if smaller font or portrait orientation limit to 400x150 */
#define MAXCOL 400
#define MAXROW 150
#define CONTROL 0x01000000 /* Control flag, or'ed in */
#define META 0x02000000 /* Meta flag, or'ed in */
#define CTLX 0x04000000 /* ^X flag, or'ed in */
#define SPEC 0x08000000 /* special key (function keys) */
#endif

166
display.c
View File

@@ -39,7 +39,7 @@ struct video {
int v_rfcolor; /* requested forground color */
int v_rbcolor; /* requested background color */
#endif
unicode_t v_text[1]; /* Screen data. */
unicode_t v_text[] ; /* Screen data. */
};
#define VFCHG 0x0001 /* Changed flag */
@@ -73,6 +73,8 @@ static int taboff = 0 ; /* tab offset for display */
int mpresf = FALSE ; /* TRUE if message in last line */
int scrollcount = 1 ; /* number of lines to scroll */
int discmd = TRUE ; /* display command flag */
int disinp = TRUE ; /* display input characters (echo) */
static int reframe(struct window *wp);
static void updone(struct window *wp);
@@ -92,10 +94,6 @@ static void mlputs( unsigned char *s) ;
static int newscreensize(int h, int w);
#endif
#if RAINBOW
static void putline(int row, int col, char *buf);
#endif
/*
* Initialize the data structures used by the display code. The edge vectors
* used to access the screens are set up. The operating system's terminal I/O
@@ -111,13 +109,13 @@ void vtinit(void)
TTopen(); /* open the screen */
TTkopen(); /* open the keyboard */
TTrev(FALSE);
vscreen = xmalloc(term.t_mrow * sizeof(struct video *));
vscreen = xmalloc( term.t_maxrow * sizeof( struct video *)) ;
#if MEMMAP == 0 || SCROLLCODE
pscreen = xmalloc(term.t_mrow * sizeof(struct video *));
pscreen = xmalloc( term.t_maxrow * sizeof( struct video *)) ;
#endif
for (i = 0; i < term.t_mrow; ++i) {
vp = xmalloc(sizeof(struct video) + term.t_mcol*4);
for( i = 0 ; i < term.t_maxrow ; ++i) {
vp = xmalloc( sizeof( struct video) + term.t_maxcol * sizeof( unicode_t)) ;
vp->v_flag = 0;
#if COLOR
vp->v_rfcolor = 7;
@@ -125,7 +123,7 @@ void vtinit(void)
#endif
vscreen[i] = vp;
#if MEMMAP == 0 || SCROLLCODE
vp = xmalloc(sizeof(struct video) + term.t_mcol*4);
vp = xmalloc( sizeof( struct video) + term.t_maxcol * sizeof( unicode_t)) ;
vp->v_flag = 0;
pscreen[i] = vp;
#endif
@@ -138,7 +136,7 @@ void vtinit(void)
void vtfree(void)
{
int i;
for (i = 0; i < term.t_mrow; ++i) {
for( i = 0 ; i < term.t_maxrow; ++i ) {
free(vscreen[i]);
#if MEMMAP == 0 || SCROLLCODE
free(pscreen[i]);
@@ -214,8 +212,9 @@ static void vtputc(int c)
if (c == '\t') {
do {
vtputc(' ');
} while (((vtcol + taboff) & tabmask) != 0);
return;
} while( ((vtcol + taboff) % tabwidth) != 0) ;
return ;
}
if (c < 0x20) {
@@ -584,13 +583,15 @@ void updpos(void)
i += utf8_to_unicode( lp->l_text, i, curwp->w_doto, &c) ;
if( c == '\t')
curcol |= tabmask ;
curcol += tabwidth - curcol % tabwidth ;
else if( c < 0x20 || c == 0x7F)
curcol += 1 ; /* displayed as ^c */
curcol += 2 ; /* displayed as ^c */
else if( c >= 0x80 && c <= 0xA0)
curcol += 2 ; /* displayed as \xx */
++curcol;
curcol += 3 ; /* displayed as \xx */
else if( c >= 0x3000 && c <= 0x3FFF)
curcol += 2 ; /* double width unicode character */
else
curcol += 1 ;
}
/* if extended, flag so and update the virtual line image */
@@ -909,8 +910,7 @@ static void updext(void)
/*
* Update a single line. This does not know how to use insert or delete
* character sequences; we are using VT52 functionality. Update the physical
* row and column variables. It does try an exploit erase to end of line. The
* RAINBOW version of this routine uses fast video.
* row and column variables. It does try an exploit erase to end of line.
*/
#if MEMMAP
/* UPDATELINE specific code for the IBM-PC and other compatables */
@@ -957,29 +957,6 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
*/
static int updateline(int row, struct video *vp1, struct video *vp2)
{
#if RAINBOW
/* UPDATELINE specific code for the DEC rainbow 100 micro */
unicode_t *cp1;
unicode_t *cp2;
int nch;
/* since we don't know how to make the rainbow do this, turn it off */
flags &= (~VFREV & ~VFREQ);
cp1 = &vp1->v_text[0]; /* Use fast video. */
cp2 = &vp2->v_text[0];
putline(row + 1, 1, cp1);
nch = term.t_ncol;
do {
*cp2 = *cp1;
++cp2;
++cp1;
}
while (--nch);
*flags &= ~VFCHG;
#else
/* UPDATELINE code for all other versions */
unicode_t *cp1;
@@ -1004,20 +981,18 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
#endif
#if REVSTA | COLOR
/* if we need to change the reverse video status of the
current line, we need to re-write the entire line */
/* do a re-write of the entire line if it is reverse or there
** is a request to change the reverse status */
rev = (vp1->v_flag & VFREV) == VFREV;
req = (vp1->v_flag & VFREQ) == VFREQ;
if ((rev != req)
if( req || (req != rev)
#if COLOR
|| (vp1->v_fcolor != vp1->v_rfcolor)
|| (vp1->v_bcolor != vp1->v_rbcolor)
#endif
) {
movecursor(row, 0); /* Go to start of line. */
/* set rev video if needed */
if (rev != req)
(*term.t_rev) (req);
TTrev( req) ; /* set needed rev video state */
/* scan through the line and dump it to the screen and
the virtual screen array */
@@ -1027,9 +1002,8 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
++ttcol;
*cp2++ = *cp1++;
}
/* turn rev video off */
if (rev != req)
(*term.t_rev) (FALSE);
TTrev( FALSE) ; /* turn rev video off */
/* update the needed flags */
vp1->v_flag &= ~VFCHG;
@@ -1107,7 +1081,6 @@ static int updateline(int row, struct video *vp1, struct video *vp2)
#endif
vp1->v_flag &= ~VFCHG; /* flag this line as updated */
return TRUE;
#endif
}
#endif
@@ -1147,18 +1120,8 @@ static void modeline(struct window *wp)
lchar = '-';
bp = wp->w_bufp;
#if PKCODE == 0
if ((bp->b_flag & BFTRUNC) != 0)
vtputc('#');
else
#endif
vtputc(lchar);
if ((bp->b_flag & BFCHG) != 0) /* "*" if changed. */
vtputc('*');
else
vtputc(lchar);
vtputc( ((bp->b_flag & BFTRUNC) != 0) ? '#' : lchar) ; /* truncated? */
vtputc( ((bp->b_flag & BFCHG) != 0) ? '*' : lchar) ; /* changed? */
vtputc( ' ') ;
if( n == term.t_nrow - 1)
@@ -1323,13 +1286,27 @@ void mlerase( void) {
TTflush() ;
}
static void mlputc( char c) {
static void mlputc( unicode_t c) {
if( ttcol < term.t_ncol) {
TTputc( c) ;
++ttcol ;
}
}
/*
* output a string of output characters
*
* char *s; string to output
*/
void ostring( char *s) {
unsigned char c ;
if( discmd)
while( (c = *s++) != 0)
mlputc( c) ;
}
/*
* Write a message into the message line. Keep track of the physical cursor
* position. A small class of printf like format items is handled. Assumes the
@@ -1360,12 +1337,14 @@ void vmlwrite( const char *fmt, va_list ap) {
movecursor( term.t_nrow, 0) ;
mpresf = *fmt ? TRUE : FALSE ; /* flag if line has content or not */
while ((c = *fmt++) != 0) {
if (c != '%')
while( ( c = *fmt++) != 0)
if( c != '%')
mlputc( c) ;
else {
c = *fmt++;
switch (c) {
else if( ( c = *fmt++) == 0) {
mlputc( '%') ;
break ;
} else
switch( c) {
case 'd':
mlputi(va_arg(ap, int), 10);
break;
@@ -1395,10 +1374,11 @@ void vmlwrite( const char *fmt, va_list ap) {
break ;
default:
mlputc( '%') ;
/* fallthrough */
case '%':
mlputc( c) ;
}
}
}
/* if we can, erase to the end of screen */
if( eolexist == TRUE && ttcol < term.t_ncol)
@@ -1511,18 +1491,6 @@ static void mlputf( int s) {
mlputc((f % 10) + '0') ;
}
#if RAINBOW
static void putline(int row, int col, char *buf)
{
int n;
n = strlen(buf);
if (col + n - 1 > term.t_ncol)
n = term.t_ncol - col + 1;
Put_Data(row, col, n, buf);
}
#endif
/* Get terminal size from system.
Store number of lines into *heightp and width into *widthp.
@@ -1553,8 +1521,8 @@ void sizesignal(int signr)
getscreensize(&w, &h);
if( h > 0 && w > 0) {
term.t_mrow = h = h < MAXROW ? h : MAXROW ;
term.t_mcol = w = w < MAXCOL ? w : MAXCOL ;
term.t_mrow = h = h < term.t_maxrow ? h : term.t_maxrow ;
term.t_mcol = w = w < term.t_maxcol ? w : term.t_maxcol ;
if( h - 1 != term.t_nrow || w != term.t_ncol)
newscreensize( h, w) ;
}
@@ -1582,3 +1550,27 @@ static int newscreensize(int h, int w)
}
#endif
/*
* output a character when echo is enabled
*
* char c ; character to output
*/
void echoc( unicode_t c) {
if( disinp)
TTputc( c) ;
}
/*
* output a string of characters when display input is enabled
*
* char *s; string to output
*/
void echos( char *s) {
if( disinp)
while( *s)
TTputc( *s++) ;
}
/* end of display.c */

View File

@@ -4,10 +4,12 @@
#include <stdarg.h>
#include "estruct.h"
#include "utf8.h"
extern int mpresf ; /* Stuff in message line */
extern int scrollcount ; /* number of lines to scroll */
extern int discmd ; /* display command flag */
extern int disinp ; /* display input characters (echo) */
extern int gfcolor ; /* global forgrnd color (white) */
extern int gbcolor ; /* global backgrnd color (black) */
@@ -26,6 +28,9 @@ void movecursor( int row, int col) ;
void mlerase( void) ;
void vmlwrite( const char *fmt, va_list ap) ;
void mlwrite( const char *fmt, ...) ;
void ostring( char *s) ;
void echoc( unicode_t c) ;
void echos( char *s) ;
void getscreensize( int *widthp, int *heightp) ;
#if UNIX

76
ebind.c
View File

@@ -35,17 +35,17 @@
* control-X commands.
*/
struct key_tab keytab[NBINDS] = {
{CONTROL | 'A', gotobol}
{CONTROL | 'A', (fn_t) gotobol}
,
{CONTROL | 'B', backchar}
{CONTROL | 'B', (fn_t) backchar}
,
{CONTROL | 'C', insspace}
,
{CONTROL | 'D', forwdel}
,
{CONTROL | 'E', gotoeol}
{CONTROL | 'E', (fn_t) gotoeol}
,
{CONTROL | 'F', forwchar}
{CONTROL | 'F', (fn_t) forwchar}
,
{CONTROL | 'G', ctrlg}
,
@@ -61,11 +61,11 @@ struct key_tab keytab[NBINDS] = {
,
{CONTROL | 'M', insert_newline}
,
{CONTROL | 'N', forwline}
{CONTROL | 'N', (fn_t) forwline}
,
{CONTROL | 'O', openline}
,
{CONTROL | 'P', backline}
{CONTROL | 'P', (fn_t) backline}
,
{CONTROL | 'Q', quote}
,
@@ -73,11 +73,11 @@ struct key_tab keytab[NBINDS] = {
,
{CONTROL | 'S', forwsearch}
,
{CONTROL | 'T', twiddle}
{CONTROL | 'T', (fn_t) twiddle}
,
{CONTROL | 'U', unarg}
,
{CONTROL | 'V', forwpage}
{CONTROL | 'V', (fn_t) forwpage}
,
{CONTROL | 'W', killregion}
,
@@ -85,7 +85,7 @@ struct key_tab keytab[NBINDS] = {
,
{CONTROL | 'Y', yank}
,
{CONTROL | 'Z', backpage}
{CONTROL | 'Z', (fn_t) backpage}
,
{CONTROL | ']', metafn}
,
@@ -138,7 +138,7 @@ struct key_tab keytab[NBINDS] = {
,
{CTLX | CONTROL | 'W', filewrite}
,
{CTLX | CONTROL | 'X', swapmark}
{CTLX | CONTROL | 'X', (fn_t) swapmark}
,
{CTLX | CONTROL | 'Z', shrinkwind}
,
@@ -246,17 +246,17 @@ struct key_tab keytab[NBINDS] = {
#endif
{META | CONTROL | 'Z', scrnextup}
,
{META | ' ', setmark}
{META | ' ', (fn_t) setmark}
,
{META | '?', help}
,
{META | '!', reposition}
,
{META | '.', setmark}
{META | '.', (fn_t) setmark}
,
{META | '>', gotoeob}
{META | '>', (fn_t) gotoeob}
,
{META | '<', gotobob}
{META | '<', (fn_t) gotobob}
,
{META | '~', unmark}
,
@@ -270,10 +270,6 @@ struct key_tab keytab[NBINDS] = {
,
{META | 'D', delfword}
,
#if CRYPT
{META | 'E', set_encryption_key}
,
#endif
{META | 'F', forwword}
,
{META | 'G', gotoline}
@@ -311,7 +307,7 @@ struct key_tab keytab[NBINDS] = {
#endif
{META | 'U', upperword}
,
{META | 'V', backpage}
{META | 'V', (fn_t) backpage}
,
{META | 'W', copyregion}
,
@@ -327,21 +323,21 @@ struct key_tab keytab[NBINDS] = {
,
{SPEC | CONTROL | 'S', backhunt}
,
{SPEC | 71, gotobol}
{SPEC | 71, (fn_t) gotobol}
,
{SPEC | 72, backline}
{SPEC | 72, (fn_t) backline}
,
{SPEC | 73, backpage}
{SPEC | 73, (fn_t) backpage}
,
{SPEC | 75, backchar}
{SPEC | 75, (fn_t) backchar}
,
{SPEC | 77, forwchar}
{SPEC | 77, (fn_t) forwchar}
,
{SPEC | 79, gotoeol}
{SPEC | 79, (fn_t) gotoeol}
,
{SPEC | 80, forwline}
{SPEC | 80, (fn_t) forwline}
,
{SPEC | 81, forwpage}
{SPEC | 81, (fn_t) forwpage}
,
{SPEC | 82, insspace}
,
@@ -378,9 +374,9 @@ struct key_tab keytab[NBINDS] = {
{SPEC | 93, cbuf10}
,
#if PKCODE
{SPEC | 117, gotoeob}
{SPEC | 117, (fn_t) gotoeob}
,
{SPEC | 119, gotobob}
{SPEC | 119, (fn_t) gotobob}
,
{SPEC | 141, gotobop}
,
@@ -394,33 +390,33 @@ struct key_tab keytab[NBINDS] = {
#endif
#if VT220
{SPEC | '1', gotobob /* fisearch */}
{SPEC | '1', (fn_t) gotobob /* fisearch */}
, /* VT220 keys */
{SPEC | '2', yank}
,
{SPEC | '3', forwdel /* killregion */}
,
{SPEC | '4', gotoeob /* setmark */}
{SPEC | '4', (fn_t) gotoeob /* setmark */}
,
{SPEC | '5', backpage}
{SPEC | '5', (fn_t) backpage}
,
{SPEC | '6', forwpage}
{SPEC | '6', (fn_t) forwpage}
,
{SPEC | 'A', backline}
{SPEC | 'A', (fn_t) backline}
,
{SPEC | 'B', forwline}
{SPEC | 'B', (fn_t) forwline}
,
{SPEC | 'C', forwchar}
{SPEC | 'C', (fn_t) forwchar}
,
{SPEC | 'D', backchar}
{SPEC | 'D', (fn_t) backchar}
,
{SPEC | 'c', metafn}
,
{SPEC | 'd', backchar}
{SPEC | 'd', (fn_t) backchar}
,
{SPEC | 'e', forwline}
{SPEC | 'e', (fn_t) forwline}
,
{SPEC | 'f', gotobob}
{SPEC | 'f', (fn_t) gotobob}
,
{SPEC | 'h', help}
,

View File

@@ -1,4 +1,4 @@
=> uEmacs/PK 4.0 HELP INDEX
=> µEMACS 4.2 HELP INDEX
.. The very basics
.. Cursor movement
.. File commands
@@ -140,7 +140,7 @@ Clear and redraw ...... ^L Exchange point and mark ^X ^X
Redraw display ........ Meta ^L
Execute named command . Meta X Insert string ......... not bound
Execute command line .. not bound Overwrite string ...... not bound
Set encryption key .... Meta E Wrap word ............. not bound
Wrap word ............. not bound
Count words ........... Meta ^C Update screen ......... not bound
-------------------------------------------------------------------------------
=> SYSTEM VARIABLES

View File

@@ -183,12 +183,6 @@
#define poke(a,b,c,d) movedata(FP_SEG(c),FP_OFF(c),a,b,d)
#endif
#if VMS
#define atoi xatoi
#define abs xabs
#define getname xgetname
#endif
#if MSDOS & MSC
#include <dos.h>
#include <memory.h>
@@ -215,12 +209,6 @@
#define ENVFUNC 0
#endif
/* Internal defined functions */
#ifdef abs
#undef abs
#endif
/* DIFCASE represents the integer difference between upper
and lower case letters. It is an xor-able value, which is
fortunate, since the relative positions of upper to lower

127
eval.c
View File

@@ -13,6 +13,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "basic.h"
#include "bind.h"
@@ -129,7 +130,8 @@ static const char *envars[] = {
"line", /* text of current line */
"gflags", /* global internal emacs flags */
"rval", /* child process return value */
"tab", /* tab 4 or 8 */
"tab", /* tab width, 1... */
"hardtab", /* TRUE for hard coded tab, FALSE for soft ones */
"overlap",
"jump",
#if SCROLLCODE
@@ -177,15 +179,16 @@ static const char *envars[] = {
#define EVGFLAGS 35
#define EVRVAL 36
#define EVTAB 37
#define EVOVERLAP 38
#define EVSCROLLCOUNT 39
#define EVSCROLL 40
#define EVHARDTAB 38
#define EVOVERLAP 39
#define EVSCROLLCOUNT 40
#define EVSCROLL 41
enum function_type {
NILNAMIC = 0,
MONAMIC = (1 << 6),
DYNAMIC = (2 << 6),
TRINAMIC = (3 << 6),
TRINAMIC = (3 << 6)
} ;
enum function_code {
@@ -195,7 +198,7 @@ enum function_code {
UFAND, UFOR, UFLENGTH, UFUPPER, UFLOWER, UFTRUTH,
UFASCII, UFCHR, UFGTKEY, UFRND, UFABS, UFSINDEX,
UFENV, UFBIND, UFEXIST, UFFIND, UFBAND, UFBOR,
UFBXOR, UFBNOT, UFXLATE,
UFBXOR, UFBNOT, UFXLATE
} ;
/* List of recognized user functions. */
@@ -288,7 +291,7 @@ static int putctext( char *iline)
static char *result ; /* string result */
static int ressize = 0 ; /* mark result as uninitialized */
static int ernd( void) ;
static int ernd( int i) ;
static int sindex( char *source, char *pattern) ;
static char *xlat( char *source, char *lookup, char *trans) ;
@@ -303,6 +306,8 @@ void varinit(void)
result = malloc( NSTRING) ;
ressize = NSTRING ;
}
seed = time( NULL) ;
}
/*
@@ -410,8 +415,22 @@ static char *gtfun( char *fname) {
retstr = result ;
}
break ;
case UFLEFT | DYNAMIC:
sz = atoi( arg2) ;
case UFLEFT | DYNAMIC: {
int sz1, i ;
sz1 = strlen( arg1) ;
sz = 0 ;
for( i = atoi( arg2) ; i > 0 ; i -= 1) {
unicode_t c ;
int bytc ;
bytc = utf8_to_unicode( arg1, sz, sz1, &c) ;
if( bytc == 0)
break ;
else
sz += bytc ;
}
if( sz >= ressize) {
free( result) ;
result = malloc( sz + 1) ;
@@ -421,6 +440,7 @@ static char *gtfun( char *fname) {
strncpy( result, arg1, sz) ;
result[ sz] = 0 ;
retstr = result ;
}
break ;
case UFRIGHT | DYNAMIC:
sz = atoi( arg2) ;
@@ -432,17 +452,40 @@ static char *gtfun( char *fname) {
retstr = strcpy( result, &arg1[ strlen( arg1) - sz]) ;
break ;
case UFMID | TRINAMIC:
sz = atoi( arg3) ;
case UFMID | TRINAMIC: {
int sz1, start, i, bytc ;
unicode_t c ;
sz1 = strlen( arg1) ;
start = 0 ;
for( i = atoi( arg2) - 1 ; i > 0 ; i -= 1) {
bytc = utf8_to_unicode( arg1, start, sz1, &c) ;
if( bytc == 0)
break ;
else
start += bytc ;
}
sz = start ;
for( i = atoi( arg3) ; i > 0 ; i -= 1) {
bytc = utf8_to_unicode( arg1, sz, sz1, &c) ;
if( bytc == 0)
break ;
else
sz += bytc ;
}
sz -= start ;
if( sz >= ressize) {
free( result) ;
result = malloc( sz + 1) ;
ressize = sz + 1 ;
}
strncpy( result, &arg1[ atoi( arg2) - 1], sz) ;
strncpy( result, &arg1[ start], sz) ;
result[ sz] = 0 ;
retstr = result ;
}
break ;
case UFNOT | MONAMIC:
retstr = ltos( stol( arg1) == FALSE) ;
@@ -537,13 +580,7 @@ static char *gtfun( char *fname) {
retstr = result ;
break ;
case UFRND | MONAMIC:
sz = abs( atoi( arg1)) ;
if( sz == 0)
sz = ernd() ;
else
sz = ernd() % sz + 1 ;
retstr = i_to_a( sz) ;
retstr = i_to_a( ernd( atoi( arg1))) ;
break ;
case UFABS | MONAMIC:
retstr = i_to_a( abs( atoi( arg1))) ;
@@ -690,10 +727,13 @@ static char *gtenv( char *vname) {
return i_to_a(gacount);
case EVLASTKEY:
return i_to_a(lastkey);
case EVCURCHAR:
return (curwp->w_dotp->l_used ==
curwp->w_doto ? i_to_a('\n') :
i_to_a(lgetc(curwp->w_dotp, curwp->w_doto)));
case EVCURCHAR: {
unicode_t c ;
lgetchar( &c) ;
return i_to_a( c) ;
}
case EVDISCMD:
return ltos(discmd);
case EVVERSION:
@@ -740,7 +780,9 @@ static char *gtenv( char *vname) {
case EVRVAL:
return i_to_a(rval);
case EVTAB:
return i_to_a(tabmask + 1);
return i_to_a( tabwidth) ;
case EVHARDTAB:
return ltos( hardtab) ;
case EVOVERLAP:
return i_to_a(overlap);
case EVSCROLLCOUNT:
@@ -1055,11 +1097,17 @@ static int svar(struct variable_description *var, char *value)
case EVRVAL:
break;
case EVTAB:
tabmask = atoi(value) - 1;
if( tabmask != 0x07 && tabmask != 0x03 && tabmask != 1)
tabmask = 0x07;
curwp->w_flag |= WFHARD;
c = atoi( value) ;
if( c > 0) {
tabwidth = c ;
curwp->w_flag |= WFHARD;
} else
status = FALSE ;
break;
case EVHARDTAB:
hardtab = stol( value) ;
break ;
case EVOVERLAP:
overlap = atoi(value);
break;
@@ -1311,20 +1359,21 @@ char *mklower(char *str)
return str;
}
/*
* take the absolute value of an integer
*/
int abs(int x)
{
return x < 0 ? -x : x;
}
/*
* returns a random integer
* ernd( 0) [ 0 .. 2147483647]
* ernd( -2147483648) [ 0 .. 2147483647]
* ernd( 1) [ 1]
* ernd( i) [ 1 .. abs( i)]
*/
static int ernd( void) {
seed = abs(seed * 1721 + 10007);
return seed;
static int ernd( int i) {
int s ;
seed = seed * 1721 + 10007 ;
s = ((seed >> 16) & 0x0000FFFF) | (seed << 16) ;
s &= ~(1 << 31) ; /* avoid abs() */
i = i < 0 ? -i : i ; /* abs( i) */
return (i <= 0) ? s : s % i + 1 ;
}
/*

1
eval.h
View File

@@ -22,7 +22,6 @@ int setvar( int f, int n) ;
char *getval( char *token) ;
int stol( char *val) ;
char *mklower( char *str) ;
int abs( int x) ;
int clrmes( int f, int n) ;
int writemsg( int f, int n) ;

26
exec.c
View File

@@ -131,10 +131,10 @@ int execcmd( int f, int n) {
execlevel = 0 ;
while( status == TRUE && n-- > 0)
status = docmd( cmdstr) ;
status = docmd( cmdstr) ;
free( cmdstr) ;
return status ;
free( cmdstr) ;
return status ;
}
/*
@@ -302,10 +302,10 @@ static char *newtoken( char *src, char **tokref) {
if (*src)
++src;
if( tok != NULL)
tok[ idx] = 0 ;
if( tok != NULL)
tok[ idx] = 0 ;
*tokref = tok ;
*tokref = tok ;
return src;
}
@@ -513,7 +513,7 @@ int execproc( int f, int n) {
while( status == TRUE && n-- > 0)
status = dobuf( bp) ;
return status ;
return status ;
}
#endif
@@ -712,6 +712,7 @@ static int dobuf(struct buffer *bp)
c = mdbugout( "<<<%s:%d:%s>>>", bp->b_bname, execlevel, eline) ;
if( c == abortc) {
freewhile( whlist) ;
free( einit) ;
return FALSE ;
} else if( c == metac) {
macbug = FALSE ;
@@ -733,6 +734,7 @@ static int dobuf(struct buffer *bp)
if (dirnum == NUMDIRS) {
mlwrite("%%Unknown Directive");
freewhile(whlist);
free( einit) ;
return FALSE;
}
@@ -752,9 +754,9 @@ static int dobuf(struct buffer *bp)
/* allocate the space for the line */
linlen = strlen(eline);
if ((mp = lalloc(linlen)) == NULL) {
mlwrite
("Out of memory while storing macro");
return FALSE;
free( einit) ;
mlwrite( "Out of memory while storing macro") ;
return FALSE ;
}
/* copy the text into the new line */
@@ -965,7 +967,7 @@ int execfile( int f, int n) {
char *fname ; /* name of file to execute */
char *fspec ; /* full file spec */
status = newmlarg( &fname, "File to execute: ", 0) ;
status = newmlarg( &fname, "Execute file: ", 0) ;
if( status != TRUE)
return status ;
@@ -981,7 +983,7 @@ int execfile( int f, int n) {
while( status == TRUE && n-- > 0)
status = dofile( fspec) ;
return status ;
return status ;
}
/*

450
execute.c
View File

@@ -1,108 +1,418 @@
/* execute.c -- implements execute.h */
#include "execute.h"
#define CLRMSG 0 /* space clears the message line with no insert */
#include <stdlib.h>
#include <unistd.h>
#include "estruct.h"
#include "bind.h"
#include "random.h"
#include "display.h"
#include "file.h"
#include "input.h"
#include "mlout.h"
#include "search.h"
#include "terminal.h"
#include "window.h"
int gasave = 256 ; /* global ASAVE size */
int gacount = 256 ; /* count until next ASAVE */
/* insert a # into the text here...we are in CMODE */
static int inspound( int n) {
/* if we are at the beginning of the line, no go */
if( n == 1 && curwp->w_doto != 0) {
int i ;
/* scan to see if all space before this is white space */
for( i = curwp->w_doto - 1 ; i >= 0 ; i -= 1) {
int ch ; /* last character before input */
ch = lgetc( curwp->w_dotp, i) ;
if( ch != ' ' && ch != '\t')
break ;
}
/* delete back first */
if( i < 0)
while( getccol( FALSE) >= 1)
backdel( FALSE, 1) ;
}
/* and insert the required pound */
return linsert( n, '#') ;
}
/*
* insert a brace into the text here...we are in CMODE
*
* int n; repeat count
* int c; brace to insert (if not }, just normal insertion).
*/
static int insbrace( int n, int c) {
int ch ; /* last character before input */
int oc ; /* caractere oppose a c */
int i, count ;
int target ; /* column brace should go after */
struct line *oldlp ;
int oldoff ;
/* if not called with {, acts as insertion */
if( c == '}')
oc = '{' ;
else
return linsert( n, c) ;
/* scan to see if all preceding spaces are white spaces, if not, insert */
for( i = curwp->w_doto - 1 ; i >= 0 ; --i) {
ch = lgetc( curwp->w_dotp, i) ;
if( ch != ' ' && ch != '\t')
return linsert( n, c) ;
}
oldlp = curwp->w_dotp ;
oldoff = curwp->w_doto ;
count = 1 ;
do {
if( boundry( curwp->w_dotp, curwp->w_doto, REVERSE)) {
/* at beginning of buffer, no match to be found */
curwp->w_dotp = oldlp ;
curwp->w_doto = oldoff ;
return linsert( n, c) ;
}
backchar( FALSE, 1) ;
/* if not eol */
if( curwp->w_doto != llength( curwp->w_dotp)) {
ch = lgetc( curwp->w_dotp, curwp->w_doto) ;
if( ch == c)
++count ;
else if( ch == oc)
--count ;
}
} while( count > 0) ;
curwp->w_doto = 0 ; /* debut de ligne */
/* aller au debut de la ligne apres la tabulation */
while( (ch = lgetc( curwp->w_dotp, curwp->w_doto)) == ' '
|| ch == '\t')
forwchar( FALSE, 1) ;
/* delete back first */
target = getccol( FALSE) ; /* c'est l'indent que l'on doit avoir */
curwp->w_dotp = oldlp ;
curwp->w_doto = oldoff ;
while( target != getccol( FALSE)) {
if( target < getccol( FALSE)) /* on doit detruire des caracteres */
while( getccol( FALSE) > target)
backdel( FALSE, 1) ;
else { /* on doit en inserer */
while( target - getccol( FALSE) >= tabwidth)
insert_tab( FALSE, 1) ;
linsert( target - getccol( FALSE), ' ') ;
}
}
/* and insert the required brace(s) */
return linsert( n, c) ;
}
#if CFENCE
/*
* Close fences are matched against their partners, and if
* on screen the cursor briefly lights there
*
* char ch; fence type to match against
*/
static void fmatch( int ch) {
struct line *oldlp ; /* original line pointer */
int oldoff ; /* and offset */
struct line *toplp ; /* top line in current window */
int count ; /* current fence level count */
int opench ; /* open fence */
/* $tpause <= 0 disable fmatch */
if( term.t_pause <= 0)
return ;
/* first get the display update out there */
update( FALSE) ;
/* save the original cursor position */
oldlp = curwp->w_dotp ;
oldoff = curwp->w_doto ;
/* setup proper open fence for passed close fence */
if( ch == ')')
opench = '(' ;
else if( ch == '}')
opench = '{' ;
else
opench = '[' ;
/* find the top line and set up for scan */
toplp = curwp->w_linep->l_bp ;
backchar( FALSE, 1) ; /* . was after the }, move back */
/* scan back until we find it, or reach past the top of the window */
count = 1 ;
do {
/* At beginning of window or buffer, no match to be found */
if( curwp->w_dotp == toplp
|| boundry( curwp->w_dotp, curwp->w_doto, REVERSE))
break ;
backchar( FALSE, 1) ;
/* if not eol */
if( curwp->w_doto != llength(curwp->w_dotp)) {
int c ; /* current character in scan */
c = lgetc( curwp->w_dotp, curwp->w_doto) ;
if( c == ch)
++count ;
else if( c == opench)
--count ;
}
} while( count > 0) ;
/* if count is zero, we have a match, display the sucker */
if( count == 0) {
int i ;
/* there is a real machine dependant timing problem here we have
yet to solve......... */
for( i = 0 ; i < term.t_pause ; i++) {
update( FALSE) ;
usleep( 10000L) ;
}
}
/* restore the current position */
curwp->w_dotp = oldlp ;
curwp->w_doto = oldoff ;
}
#endif
/*
* This is the general command execution routine. It handles the fake binding
* of all the keys to "self-insert". It also clears out the "thisflag" word,
* and arranges to move it to the "lastflag", so that the next command can
* look at it. Return the status of command.
*/
int execute(int c, int f, int n)
{
int status;
fn_t execfunc;
int execute( int c, int f, int n) {
int status ;
fn_t execfunc ;
/* if the keystroke is a bound function...do it */
execfunc = getbind(c);
if (execfunc != NULL) {
thisflag = 0;
status = (*execfunc) (f, n);
lastflag = thisflag;
return status;
/* if the keystroke is a bound function...do it */
execfunc = getbind( c) ;
if( execfunc != NULL) {
thisflag = 0 ;
status = execfunc( f, n) ;
lastflag = thisflag ;
return status ;
}
/*
* If a space was typed, fill column is defined, the argument is non-
* negative, wrap mode is enabled, and we are now past fill column,
* and we are not read-only, perform word wrap.
*/
if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 &&
n >= 0 && getccol(FALSE) > fillcol &&
(curwp->w_bufp->b_mode & MDVIEW) == FALSE)
execute(META | SPEC | 'W', FALSE, 1);
/* non insertable character can only be bound to function */
if( c < 0x20
|| (c >= 0x7F && c < 0xA0)
|| c > 0x10FFFF) { /* last valid unicode */
lastflag = 0 ; /* Fake last flags. */
mloutfmt( "%B(Key not bound)") ; /* Complain */
return FALSE ;
}
#if PKCODE
if ((c >= 0x20 && c <= 0x7E) /* Self inserting. */
#if IBMPC
|| (c >= 0x80 && c <= 0xFE)) {
#else
#if VMS || BSD || USG /* 8BIT P.K. */
|| (c >= 0xA0 && c <= 0x10FFFF)) {
#else
) {
#endif
#endif
#else
if ((c >= 0x20 && c <= 0xFF)) { /* Self inserting. */
#endif
if (n <= 0) { /* Fenceposts. */
lastflag = 0;
return n < 0 ? FALSE : TRUE;
/* insertable character => self insert, check if buffer is read only */
if( curbp->b_mode & MDVIEW) {
lastflag = 0 ;
return rdonly() ;
}
/* check valid count */
if( n <= 0) {
lastflag = 0 ;
return n < 0 ? FALSE : TRUE ;
}
/* wrap on space after fill column in wrap mode */
if( c == ' '
&& (curwp->w_bufp->b_mode & MDWRAP)
&& fillcol > 0
&& getccol( FALSE) > fillcol) {
status = execute( META | SPEC | 'W', FALSE, 1) ; /* defaults to wrapword */
if( status != TRUE) {
lastflag = 0 ;
return status ;
}
thisflag = 0; /* For the future. */
}
/* if we are in overwrite mode, not at eol,
and next char is not a tab or we are at a tab stop,
delete a char forword */
if (curwp->w_bufp->b_mode & MDOVER &&
curwp->w_doto < curwp->w_dotp->l_used &&
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
(curwp->w_doto) % 8 == 7))
ldelchar(1, FALSE);
thisflag = 0 ; /* For the future. */
/* do the appropriate insertion */
if (c == '}' && (curbp->b_mode & MDCMOD) != 0)
status = insbrace(n, c);
else if (c == '#' && (curbp->b_mode & MDCMOD) != 0)
status = inspound();
else
status = linsert(n, c);
/* following handling of overwrite is only valid when n == 1 */
/* if we are in overwrite mode, not at eol,
and next char is not a tab or we are at a tab stop,
delete a char forward */
if( curbp->b_mode & MDOVER
&& curwp->w_doto < curwp->w_dotp->l_used
&& (lgetc( curwp->w_dotp, curwp->w_doto) != '\t' ||
((curwp->w_doto) % tabwidth) == (tabwidth - 1)))
ldelchar( 1, FALSE) ;
/* do the appropriate insertion */
switch( c) {
case '}':
case ']':
case ')':
case '#':
if( (curbp->b_mode & MDCMOD) != 0) {
if( c == '#')
status = inspound( n) ;
else {
status = insbrace( n, c) ;
#if CFENCE
/* check for CMODE fence matching */
if ((c == '}' || c == ')' || c == ']') &&
(curbp->b_mode & MDCMOD) != 0)
fmatch(c);
if( status == TRUE)
fmatch( c) ; /* check for CMODE fence matching */
#endif
/* check auto-save mode */
if (curbp->b_mode & MDASAVE)
if (--gacount == 0) {
/* and save the file if needed */
upscreen(FALSE, 0);
filesave(FALSE, 0);
gacount = gasave;
}
lastflag = thisflag;
return status;
break ;
}
default:
status = linsert( n, c) ;
}
lastflag = 0 ; /* Fake last flags. */
mloutfmt( "%B(Key not bound)") ; /* Complain */
return FALSE ;
/* perform auto-save */
if( status == TRUE /* successful insertion */
&& (curbp->b_mode & MDASAVE) /* auto save is on */
&& (--gacount == 0)) { /* insertion count reached */
/* and save the file if needed */
upscreen( FALSE, 0) ;
filesave( FALSE, 0) ;
gacount = gasave ;
}
lastflag = thisflag ;
return status ;
}
void kbd_loop( void) {
int c = -1 ; /* command character */
/* Setup to process commands. */
lastflag = 0 ; /* Fake last flags. */
for( ;;) {
int saveflag ; /* temp store for lastflag */
int basec ; /* c stripped of meta character */
int f ; /* default flag */
int n ; /* numeric repeat count */
/* Execute the "command" macro...normally null. */
saveflag = lastflag ; /* Preserve lastflag through this. */
execute( META | SPEC | 'C', FALSE, 1) ;
lastflag = saveflag ;
#if TYPEAH && PKCODE
if( typahead()) {
int newc ;
newc = getcmd() ;
update( FALSE) ;
do {
fn_t execfunc ;
if( c == newc
&& (execfunc = getbind( c)) != NULL
&& execfunc != insert_newline
&& execfunc != insert_tab)
newc = getcmd() ;
else
break ;
} while( typahead()) ;
c = newc ;
} else {
update( FALSE) ;
c = getcmd() ;
}
#else
/* Fix up the screen */
update( FALSE) ;
/* get the next command from the keyboard */
c = getcmd() ;
#endif
/* if there is something on the command line, clear it */
if( mpresf != FALSE) {
mloutstr( "") ;
update( FALSE) ;
#if CLRMSG
if( c == ' ') /* ITS EMACS does this */
continue ;
#endif
}
f = FALSE ;
n = 1 ;
/* do META-# processing if needed */
/* do ^U repeat argument processing */
while( c == reptc
||( (c & META)
&& (((basec = c & ~META) >= '0' && basec <= '9') || basec == '-'))) {
int mflag = 0 ; /* minus flag, default to positive */
f = TRUE ;
if( c == reptc) {
n = 4 ;
basec = 2 ; /* lead by universal arg cmd */
} else if( c & META) {
if( basec == '-') {
mflag = TRUE ; /* negative */
n = 1 ;
basec = 1 ; /* lead by M-- */
} else {
n = basec - '0' ;
basec = 0 ; /* lead by M-# */
}
}
mloutfmt( "Arg: %s%d", mflag ? "-" : "", n) ;
while( ((c = getcmd()) >= '0' && c <= '9') || c == '-') {
if( c == '-') {
if( basec == 2) { /* directly follows universal arg cmd */
n = 1 ;
basec = 1 ;
mflag = TRUE ;
} else
break ;
} else {
if( basec) { /* follows universal arg cmd or leading dash */
n = c - '0' ;
basec = 0 ;
} else if( n <= 0xCCCCCCB) /* avoid overflow */
n = n * 10 + c - '0' ;
}
mloutfmt( "Arg: %s%d", mflag ? "-" : "", n) ;
}
if( mflag)
n = -n ;
}
/* and execute the command */
execute( c, f, n) ;
}
}
/* end of execute.c */

View File

@@ -2,4 +2,4 @@ extern int gasave ; /* global ASAVE size */
extern int gacount ; /* count until next ASAVE */
int execute( int c, int f, int n) ;
void kbd_loop( void) ;

944
file.c

File diff suppressed because it is too large Load Diff

6
file.h
View File

@@ -2,14 +2,8 @@
#define _FILE_H_
#include "buffer.h"
#include "crypt.h"
#include "retcode.h"
#if CRYPT
void cryptbufferkey( struct buffer *bp) ;
int set_encryption_key( int f, int n) ;
#endif
extern boolean restflag ; /* restricted use? */
boolean resterr( void) ; /* restricted error message */

136
fileio.c
View File

@@ -23,10 +23,6 @@
#include "retcode.h"
#include "utf8.h"
#if CRYPT
boolean is_crypted ; /* currently encrypting? */
#endif
char *fline = NULL ; /* dynamic return line */
static int flen = 0 ; /* current allocated length of fline */
int ftype ;
@@ -103,20 +99,6 @@ fio_code ffclose(void)
* Check only at the newline.
*/
fio_code ffputline( char *buf, int nbuf, int dosflag) {
#if CRYPT
if( is_crypted) {
int i ;
for( i = 0 ; i < nbuf ; i++) {
char c ;
c = buf[ i] ;
myencrypt( &c, 1) ;
fputc( c, ffp) ;
}
} else
#endif
fwrite( buf, 1, nbuf, ffp) ;
if( dosflag)
@@ -136,57 +118,57 @@ fio_code ffputline( char *buf, int nbuf, int dosflag) {
* at the end of the file that don't have a newline present. Check for I/O
* errors too. Return status.
*/
fio_code ffgetline(void)
{
int c; /* current character read */
int i; /* current index into fline */
int lcode = FCODE_ASCII ; /* line encoding, defaults to ASCII */
fio_code ffgetline( void) {
int c ; /* current character read */
int i ; /* current index into fline */
int lcode = FCODE_ASCII ; /* line encoding, defaults to ASCII */
/* 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 */
i = 0;
while ((c = fgetc(ffp)) != EOF && c != '\r' && c != '\n') {
fline[i++] = c;
/* read the line in */
i = 0 ;
while( (c = fgetc( ffp)) != EOF && c != '\r' && c != '\n') {
/* if line is full, get more room */
if( i >= flen) {
char *tmpline ; /* temp storage for expanding line */
tmpline = malloc( flen + NSTRING) ;
if( tmpline == NULL)
return FIOMEM ;
memcpy( tmpline, fline, flen) ;
flen += NSTRING ;
free( fline) ;
fline = tmpline ;
}
fline[ i++] = c ;
lcode |= 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 ;
lcode &= FCODE_MASK ;
if( lcode && (fcode != FCODE_MIXED)) { /* line contains extended chars */
/* Check if consistent UTF-8 encoding */
int bytes ;
int pos = 0 ;
unicode_t uc ;
while( (pos < i) && (lcode != FCODE_MIXED)) {
unicode_t uc ;
int bytes ;
bytes = utf8_to_unicode( fline, pos, i, &uc) ;
pos += bytes ;
if( bytes > 1) /* Multi byte UTF-8 sequence */
@@ -198,30 +180,24 @@ fio_code ffgetline(void)
fcode |= lcode ;
}
/* test for any errors that may have occured */
if (c == EOF) {
if( ferror( ffp))
return FIOERR ;
/* 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 ;
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
return FIOSUC;
return FIOSUC ;
}

View File

@@ -1,15 +1,12 @@
#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 */
FIOMEM /* File I/O, out of memory */
} fio_code ;
#define FTYPE_NONE 0
@@ -24,12 +21,6 @@ typedef enum {
#define FCODE_EXTND 0x82
#define FCODE_MIXED 0x83
#if CRYPT
#include "retcode.h"
extern boolean is_crypted ; /* currently encrypting? */
#endif
extern char *fline ; /* dynamic return line */
extern int ftype ;
extern int fcode ; /* encoding type */

63
floodmaz.cmd Normal file
View File

@@ -0,0 +1,63 @@
# 6 set $seed
execute-file maze.cmd
set %thisbuf $cbufname
10 store-macro # push x y
set %x $curcol
set %y $curline
select-buffer stack
beginning-of-file
insert-string %x
newline
insert-string %y
newline
select-buffer %thisbuf
!endm
11 store-macro # pop x y
select-buffer stack
beginning-of-file
set %x $line
1 kill-to-end-of-line
set %y $line
1 kill-to-end-of-line
select-buffer %thisbuf
set $curline %y
set $curcol %x
!endm
set $curline 1
set $curcol 0
execute-macro-10 #push stop position
set %x 1
set $curline 4
set $curcol %x
set %OC $curchar
set %NC &asc ""
!while &not &equ %x 0
set $curchar %NC
set %cc $curcol
set %ll $curline
set $curcol &add %cc 1
!if &equ $curchar %OC
execute-macro-10
!endif
set $curcol &add %cc -1
!if &equ $curchar %OC
execute-macro-10
!endif
set $curline &add %ll 1
set $curcol %cc
!if &equ $curchar %OC
execute-macro-10
!endif
set $curline &add %ll -1
set $curcol %cc
!if &equ $curchar %OC
execute-macro-10
!endif
execute-macro-11
!endwhile
set $curline 3
set $curcol 1

96
input.c
View File

@@ -45,8 +45,6 @@ kbdstate kbdmode = STOP ; /* current keyboard macro mode */
int lastkey = 0 ; /* last keystoke */
int kbdrep = 0 ; /* number of repetitions */
int disinp = TRUE ; /* display input characters */
int metac = CONTROL | '[' ; /* current meta character */
int ctlxc = CONTROL | 'X' ; /* current control X prefix char */
int reptc = CONTROL | 'U' ; /* current universal repeat char */
@@ -56,7 +54,6 @@ const int nlc = CONTROL | 'J' ; /* end of input char */
static const int quotec = 0x11 ; /* quote char during getstring() */
static void outstring( char *s) ;
/*
* Ask a yes or no question in the message line. Return either TRUE, FALSE, or
@@ -164,8 +161,6 @@ int ectoc(int c)
fn_t getname(void)
{
int cpos; /* current column on screen output */
int c;
char *sp; /* pointer to string for output */
struct name_bind *ffp; /* first ptr to entry in name binding table */
struct name_bind *cffp; /* current ptr to entry in name binding table */
struct name_bind *lffp; /* last ptr to entry in name binding table */
@@ -183,6 +178,8 @@ fn_t getname(void)
/* build a name string from the keyboard */
while (TRUE) {
int c ;
c = tgetc();
/* if we are at the end, just match it */
@@ -199,9 +196,7 @@ fn_t getname(void)
} else if (c == 0x7F || c == 0x08) { /* rubout/erase */
if (cpos != 0) {
TTputc('\b');
TTputc(' ');
TTputc('\b');
echos( "\b \b") ;
--ttcol;
--cpos;
TTflush();
@@ -209,9 +204,7 @@ fn_t getname(void)
} else if (c == 0x15) { /* C-U, kill */
while (cpos != 0) {
TTputc('\b');
TTputc(' ');
TTputc('\b');
echos( "\b \b") ;
--cpos;
--ttcol;
}
@@ -232,9 +225,7 @@ fn_t getname(void)
(buf, (ffp + 1)->n_name,
strlen(buf)) != 0)) {
/* no...we match, print it */
sp = ffp->n_name + cpos;
while (*sp)
TTputc(*sp++);
echos( ffp->n_name + cpos) ;
TTflush();
return ffp->n_func;
} else {
@@ -278,8 +269,7 @@ fn_t getname(void)
}
/* add the character */
TTputc(buf
[cpos++]);
echoc( buf[ cpos++]) ;
}
/* << << << << << << << << << << << << << << << << << */
}
@@ -295,7 +285,7 @@ fn_t getname(void)
} else {
if (cpos < NSTRING - 1 && c > ' ') {
buf[cpos++] = c;
TTputc(c);
echoc( c) ;
}
++ttcol;
@@ -529,12 +519,9 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
static char tmp[] = "/tmp/meXXXXXX";
FILE *tmpf = NULL;
#endif
ffile = (strcmp(prompt, "Find file: ") == 0
|| strcmp(prompt, "View file: ") == 0
|| strcmp(prompt, "Insert file: ") == 0
|| strcmp(prompt, "Write file: ") == 0
|| strcmp(prompt, "Read file: ") == 0
|| strcmp(prompt, "File to execute: ") == 0);
/* Look for "Find file: ", "View file: ", "Insert file: ", "Write file: ",
** "Read file: ", "Execute file: " */
ffile = NULL != strstr( prompt, " file: ") ;
#endif
cpos = 0;
@@ -596,15 +583,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
} else if ((c == 0x7F || c == 0x08) && quotef == FALSE) {
/* rubout/erase */
if (cpos != 0) {
outstring("\b \b");
echos("\b \b");
--ttcol;
if (buf[--cpos] < 0x20) {
outstring("\b \b");
echos("\b \b");
--ttcol;
}
if (buf[cpos] == '\n') {
outstring("\b\b \b\b");
echos("\b\b \b\b");
ttcol -= 2;
}
@@ -614,15 +601,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
} else if (c == 0x15 && quotef == FALSE) {
/* C-U, kill */
while (cpos != 0) {
outstring("\b \b");
echos("\b \b");
--ttcol;
if (buf[--cpos] < 0x20) {
outstring("\b \b");
echos("\b \b");
--ttcol;
}
if (buf[cpos] == '\n') {
outstring("\b\b \b\b");
echos("\b\b \b\b");
ttcol -= 2;
}
}
@@ -642,15 +629,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
didtry = 1;
ocpos = cpos;
while (cpos != 0) {
outstring("\b \b");
echos("\b \b");
--ttcol;
if (buf[--cpos] < 0x20) {
outstring("\b \b");
echos("\b \b");
--ttcol;
}
if (buf[cpos] == '\n') {
outstring("\b\b \b\b");
echos("\b\b \b\b");
ttcol -= 2;
}
if (buf[cpos] == '*' || buf[cpos] == '?')
@@ -737,16 +724,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
for (n = 0; n < cpos; n++) {
c = buf[n];
if ((c < ' ') && (c != '\n')) {
outstring("^");
echoc( '^') ;
++ttcol;
c ^= 0x40;
}
if (c != '\n') {
if (disinp)
TTputc(c);
} else { /* put out <NL> for <ret> */
outstring("<NL>");
if( c != '\n')
echoc( c) ;
else { /* put out <NL> for <ret> */
echos("<NL>");
ttcol += 3;
}
++ttcol;
@@ -765,16 +751,15 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
buf[cpos++] = c;
if ((c < ' ') && (c != '\n')) {
outstring("^");
echoc( '^') ;
++ttcol;
c ^= 0x40;
}
if (c != '\n') {
if (disinp)
TTputc(c);
} else { /* put out <NL> for <ret> */
outstring("<NL>");
if( c != '\n')
echoc( c) ;
else { /* put out <NL> for <ret> */
echos("<NL>");
ttcol += 3;
}
++ttcol;
@@ -783,26 +768,3 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
}
}
}
/*
* output a string of characters when display input is enabled
*
* char *s; string to output
*/
static void outstring( char *s) {
if( disinp)
while( *s)
TTputc( *s++) ;
}
/*
* output a string of output characters
*
* char *s; string to output
*/
void ostring( char *s)
{
if (discmd)
while (*s)
TTputc( *s++ & 0xFF) ;
}

View File

@@ -13,7 +13,6 @@ extern int kbdrep ; /* number of repetitions */
extern int kbdm[] ; /* Holds kayboard macro data */
extern int *kbdptr ; /* current position in keyboard buf */
extern int *kbdend ; /* ptr to end of the keyboard */
extern int disinp ; /* display input characters */
extern int metac; /* current meta character */
extern int ctlxc; /* current control X prefix char */
@@ -31,6 +30,5 @@ int tgetc( void) ;
int get1key( void) ;
int getcmd( void) ;
int getstring( const char *prompt, char *buf, int nbuf, int eolchar) ;
void ostring( char *s) ;
#endif

210
line.c
View File

@@ -16,6 +16,7 @@
#include "line.h"
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -26,9 +27,7 @@
#include "window.h"
int tabmask = 0x07 ; /* tabulator mask */
#define BLOCK_SIZE 16 /* Line block chunk size. */
int tabwidth = 8 ; /* column span of a tab */
static int ldelnewline( void) ;
@@ -92,16 +91,39 @@ char *getkill( void) {
* 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) {
static unsigned utf8_revdelta( unsigned char *p, unsigned pos) {
unsigned delta = 0 ;
if( (*p & 0xC0) == 0x80) {
unsigned char c ;
c = *--p ;
if( (c & 0xE0) == 0xC0) /* valid 2 bytes unicode seq */
delta = 1 ;
else if( ((c & 0xC0) == 0x80) && (pos > 1)) {
c = *--p ;
if( (c & 0xF0) == 0xE0) /* valid 3 bytes unicode seq */
delta = 2 ;
else if( ((c & 0xC0) == 0x80) && (pos > 2))
if( (p[ -1] & 0xF8) == 0xF0) /* valid 4 bytes unicode seq */
delta = 3 ;
}
}
return delta ;
}
boolean backchar( int f, int n) {
assert( f == TRUE || (f == FALSE && n == 1)) ;
if( n < 0)
return forwchar( f, -n) ;
while( n--) {
if( curwp->w_doto == 0) {
struct line *lp ;
if( curwp->w_doto == 0) { /* at beginning of line */
line_p lp ;
lp = lback( curwp->w_dotp) ;
if( lp == curbp->b_linep)
if( lp == curbp->b_linep) /* at beginning of buffer */
return FALSE ;
curwp->w_dotp = lp ;
@@ -111,29 +133,8 @@ int backchar( int f, int n) {
unsigned pos ;
pos = curwp->w_doto -= 1 ;
if( pos > 0) {
unsigned char *p ;
p = (unsigned char *) &( (curwp->w_dotp)->l_text[ pos]) ;
if( (*p & 0xC0) == 0x80) {
unsigned char c ;
int delta = 0 ;
c = *--p ;
if( (c & 0xE0) == 0xC0) /* valid 2 bytes unicode seq */
delta = 1 ;
else if( ((c & 0xC0) == 0x80) && (pos > 1)) {
c = *--p ;
if( (c & 0xF0) == 0xE0) /* valid 3 bytes unicode seq */
delta = 2 ;
else if( ((c & 0xC0) == 0x80) && (pos > 2))
if( (p[ -1] & 0xF8) == 0xF0) /* valid 4 bytes unicode seq */
delta = 3 ;
}
curwp->w_doto -= delta ;
}
}
if( pos > 0)
curwp->w_doto -= utf8_revdelta( (unsigned char *) &( (curwp->w_dotp)->l_text[ pos]), pos) ;
}
}
@@ -146,18 +147,20 @@ int backchar( int f, int n) {
* 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;
boolean forwchar( int f, int n) {
assert( f == TRUE || (f == FALSE && n == 1)) ;
if( n < 0)
return backchar( f, -n) ;
while( n--) {
int len = llength( curwp->w_dotp) ;
if( curwp->w_doto == len) { /* at end of line */
if( curwp->w_dotp == curbp->b_linep) /* at end of buffer */
return FALSE ;
curwp->w_dotp = lforw( curwp->w_dotp) ;
curwp->w_doto = 0 ;
curwp->w_flag |= WFMOVE ;
} else {
unicode_t unc ;
unsigned bytes ;
@@ -166,7 +169,8 @@ int forwchar(int f, int n)
curwp->w_doto += bytes ;
}
}
return TRUE;
return TRUE ;
}
/*
@@ -175,21 +179,22 @@ int forwchar(int f, int n)
* a pointer to the new block, or NULL if there isn't any memory left. Print a
* message in the message line if no space.
*/
struct line *lalloc(int used)
{
struct line *lp;
int size;
line_p lalloc( int used) {
#define BLOCK_SIZE 16 /* Line block chunk size. */
line_p lp ;
int size ;
size = (used + BLOCK_SIZE - 1) & ~(BLOCK_SIZE - 1);
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) {
/* size = used + BLOCK_SIZE - used % BLOCK_SIZE ; */
size = (used + BLOCK_SIZE) & ~(BLOCK_SIZE - 1) ; /* as BLOCK_SIZE is power of 2 */
lp = (line_p) malloc( offsetof( struct line, l_text) + size) ;
if( lp == NULL)
mloutstr( "(OUT OF MEMORY)") ;
return NULL;
else {
lp->l_size = size ;
lp->l_used = used ;
}
lp->l_size = size;
lp->l_used = used;
return lp;
return lp ;
}
/*
@@ -198,8 +203,7 @@ struct line *lalloc(int used)
* might be in. Release the memory. The buffers are updated too; the magic
* conditions described in the above comments don't hold here.
*/
void lfree(struct line *lp)
{
void lfree( line_p lp) {
struct buffer *bp;
struct window *wp;
@@ -273,8 +277,6 @@ int insspace(int f, int n)
return TRUE;
}
static int linsert_byte( int n, int c) ;
/*
* linstr -- Insert a string at the current point
*/
@@ -287,7 +289,7 @@ int linstr( char *instr) {
while( (tmpc = *instr++ & 0xFF)) {
status =
(tmpc == '\n' ? lnewline() : linsert_byte( 1, tmpc)) ;
(tmpc == '\n' ? lnewline() : (int) linsert_byte( 1, tmpc)) ;
/* Insertion error? */
if( status != TRUE) {
@@ -310,8 +312,7 @@ int linstr( char *instr) {
* well, and FALSE on errors.
*/
static int linsert_byte(int n, int c)
{
boolean linsert_byte( int n, int c) {
char *cp1;
char *cp2;
struct line *lp1;
@@ -392,24 +393,27 @@ static int linsert_byte(int n, int c)
}
int linsert( int n, unicode_t c) {
char utf8[6];
int bytes, i ;
assert( n > 0) ;
assert( n >= 0) ;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
bytes = unicode_to_utf8(c, utf8) ;
if (bytes == 1)
return linsert_byte(n, (unsigned char) utf8[0]);
for (i = 0; i < n; i++) {
int j;
for (j = 0; j < bytes; j++) {
unsigned char c = utf8[j];
if (!linsert_byte(1, c))
return FALSE;
}
if( n > 0) {
char utf8[ 4] ;
int bytes ;
bytes = unicode_to_utf8(c, utf8) ;
if (bytes == 1)
return linsert_byte(n, (unsigned char) utf8[0]);
do {
int j ;
for( j = 0 ; j < bytes ; j += 1)
if( !linsert_byte( 1, (unsigned char) utf8[ j]))
return FALSE ;
} while( --n > 0) ;
}
return TRUE;
}
@@ -418,13 +422,15 @@ int linsert( int n, unicode_t c) {
*
* int c; character to overwrite on current position
*/
static int lowrite(int c)
{
if (curwp->w_doto < curwp->w_dotp->l_used &&
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
((curwp->w_doto) & tabmask) == tabmask))
ldelchar(1, FALSE);
return linsert(1, c);
static int lowrite( int c) {
if( curwp->w_doto < curwp->w_dotp->l_used
&& (
lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
((curwp->w_doto) % tabwidth) == (tabwidth - 1)
))
ldelchar( 1, FALSE) ;
return linsert( 1, c) ;
}
/*
@@ -512,11 +518,13 @@ int lnewline(void)
return TRUE;
}
int lgetchar(unicode_t *c)
{
int len = llength(curwp->w_dotp);
char *buf = curwp->w_dotp->l_text;
return utf8_to_unicode(buf, curwp->w_doto, len, c);
int lgetchar( unicode_t *c) {
if( curwp->w_dotp->l_used == curwp->w_doto) {
*c = (curbp->b_mode & MDDOS) ? '\r' : '\n' ;
return 1 ;
} else
return utf8_to_unicode( curwp->w_dotp->l_text, curwp->w_doto,
llength( curwp->w_dotp), c) ;
}
/*
@@ -526,8 +534,8 @@ int lgetchar(unicode_t *c)
*
* If you want to delete characters, use ldelchar().
*/
int ldelchar(long n, int kflag)
{
boolean ldelchar( long n, boolean kflag) {
/* testing for read only mode is done by ldelete() */
while (n-- > 0) {
unicode_t c;
if (!ldelete(lgetchar(&c), kflag))
@@ -545,8 +553,7 @@ int ldelchar(long n, int kflag)
* long n; # of chars to delete
* int kflag; put killed text in kill buffer flag
*/
int ldelete(long n, int kflag)
{
boolean ldelete( long n, boolean kflag) {
char *cp1;
char *cp2;
struct line *dotp;
@@ -556,7 +563,8 @@ int ldelete(long n, int kflag)
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
while (n != 0) {
while( n > 0) {
dotp = curwp->w_dotp;
doto = curwp->w_doto;
if (dotp == curbp->b_linep) /* Hit end of buffer. */
@@ -613,18 +621,14 @@ int ldelete(long n, int kflag)
* getctext: grab and return a string with the text of
* the current line
*/
char *getctext(void)
{
struct line *lp; /* line to copy */
char *getctext( void) {
line_p lp ; /* line to copy */
int size; /* length of line to return */
char *sp; /* string pointer into line */
char *dp; /* string pointer into returned line */
static int rsize = 0 ;
static char *rline ; /* line to return */
/* find the contents of the current line and its length */
lp = curwp->w_dotp;
sp = lp->l_text;
size = lp->l_used;
if( size >= rsize) {
if( rsize)
@@ -639,11 +643,9 @@ char *getctext(void)
}
/* copy it across */
dp = rline;
while (size--)
*dp++ = *sp++;
*dp = 0;
return rline;
memcpy( rline, lp->l_text, size) ;
rline[ size] = 0 ;
return rline ;
}
/*

37
line.h
View File

@@ -4,23 +4,21 @@
#include "retcode.h"
#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
* buffer). This line is pointed to by the "struct buffer". Each line contains a the
* 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
* buffer). This line is pointed to by the "struct buffer". Each line contains a
* number of bytes in the line (the "used" size), the size of the text array,
* and the text. The end of line is not stored as a byte; it's implied. Future
* additions will include update hints, and a list of marks into the line.
*/
struct line {
struct line *l_fp; /* Link to the next line */
struct line *l_bp; /* Link to the previous line */
int l_size; /* Allocated size */
int l_used; /* Used size */
char l_text[1]; /* A bunch of characters. */
};
typedef struct line {
struct line *l_fp ; /* Forward link to the next line */
struct line *l_bp ; /* Backward link to the previous line */
int l_size ; /* Allocated size */
int l_used ; /* Used size */
char l_text[ 1] ; /* A bunch of characters */
} *line_p ;
#define lforw(lp) ((lp)->l_fp)
#define lback(lp) ((lp)->l_bp)
@@ -28,28 +26,29 @@ struct line {
#define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
#define llength(lp) ((lp)->l_used)
extern int tabmask ;
extern int tabwidth ; /* Map to $tab, default to 8, can be set to [1, .. */
char *getkill( void) ;
int backchar( int f, int n) ;
int forwchar( int f, int n) ;
boolean backchar( int f, int n) ;
boolean forwchar( int f, int n) ;
void lfree( struct line *lp) ;
void lfree( line_p lp) ;
void lchange( int flag) ;
int insspace( int f, int n) ;
int linstr( char *instr) ;
int linsert( int n, unicode_t c) ;
boolean linsert_byte( int n, int c) ;
int lover( char *ostr) ;
int lnewline( void) ;
int ldelete( long n, int kflag) ;
int ldelchar( long n, int kflag) ;
boolean ldelete( long n, boolean kflag) ;
boolean ldelchar( long n, boolean 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. */
line_p lalloc( int minsize) ; /* Allocate a line of at least minsize chars. */
boolean rdonly( void) ; /* Read Only error message */

7
lock.c
View File

@@ -1,3 +1,5 @@
/* lock.c -- implements lock.h */
#include "estruct.h"
#include "lock.h"
@@ -167,4 +169,9 @@ void lckerror(char *errstr)
strcat(obuf, strerror(errno));
mlwrite(obuf);
}
#else
typedef void _pedantic_empty_translation_unit ;
#endif
/* end of lock.c */

181
main.c
View File

@@ -1,7 +1,5 @@
/* main.c -- */
#define CLRMSG 0 /* space clears the message line with no insert */
/*
* main.c
*
@@ -84,7 +82,6 @@
#include "eval.h"
#include "execute.h"
#include "file.h"
#include "input.h"
#include "lock.h"
#include "mlout.h"
#include "random.h"
@@ -119,51 +116,37 @@ static void version( void) {
static void usage( void) {
fputs( "Usage: " PROGRAM_NAME " [OPTION].. [FILE]..\n\n"
fputs( "Usage: " PROGRAM_NAME " [OPTION|FILE]..\n\n"
" + start at the end of file\n"
" +<n> start at line <n>\n"
" --help display this help and exit\n"
" --version output version information and exit\n"
" @cmdfile execute startup file\n"
" -a|A process error file\n"
" -e|E edit file\n"
" -g|G<n> go to line <n>\n"
#if CRYPT
" -k|K<key> use code key\n"
#endif
" -r|R restrictive use\n"
" -s|S<string> search string\n"
" -v|V view file\n"
" -x|Xcmdfile\n"
" -x|X cmdfile execute command file\n"
" @cmdfile execute startup file\n"
, stdout) ;
}
int main(int argc, char **argv)
{
int c = -1; /* command character */
int f; /* default flag */
int n; /* numeric repeat count */
int mflag; /* negative flag on repeat */
struct buffer *bp; /* temp buffer pointer */
int firstfile; /* first file flag */
int carg; /* current arg to scan */
int startflag; /* startup executed flag */
struct buffer *firstbp = NULL; /* ptr to first buffer in cmd line */
int basec; /* c stripped of meta character */
int viewflag; /* are we starting in view mode? */
int gotoflag; /* do we need to goto a line at start? */
int gline = 0; /* if so, what line? */
int searchflag; /* Do we need to search at start? */
int saveflag; /* temp store for lastflag */
int errflag; /* C error processing? */
bname_t bname ; /* buffer name of file to read */
#if CRYPT
int cryptflag; /* encrypting on the way in? */
ekey_t ekey ; /* startup encryption key */
#endif
int newc;
#if PKCODE & VMS
(void) umask(-1); /* Use old protection (this is at wrong place). */
@@ -202,9 +185,6 @@ int main(int argc, char **argv)
firstfile = TRUE; /* no file to edit yet */
startflag = FALSE; /* startup file not executed yet */
errflag = FALSE; /* not doing C error parsing */
#if CRYPT
cryptflag = FALSE; /* no encryption by default */
#endif
/* Insure screen is initialized before startup and goto/search */
update( FALSE) ;
@@ -234,14 +214,6 @@ int main(int argc, char **argv)
gotoflag = TRUE;
gline = atoi(&argv[carg][2]);
break;
#if CRYPT
case 'k': /* -k<key> for code key */
case 'K':
cryptflag = TRUE;
strncpy( ekey, &argv[ carg][ 2], sizeof ekey - 1) ;
ekey[ sizeof ekey - 1] = 0 ;
break;
#endif
case 'r': /* -r restrictive use */
case 'R':
restflag = TRUE;
@@ -307,13 +279,6 @@ int main(int argc, char **argv)
/* set the modes appropriatly */
if (viewflag)
bp->b_mode |= MDVIEW;
#if CRYPT
if (cryptflag) {
bp->b_mode |= MDCRYPT;
strncpy( bp->b_key, ekey, sizeof ekey) ;
cryptbufferkey( bp) ;
}
#endif
}
}
@@ -332,10 +297,9 @@ int main(int argc, char **argv)
/* if invoked with no other startup files,
run the system startup file here */
if (startflag == FALSE) {
startup("");
startflag = TRUE;
}
if( (startflag == FALSE) && (startup( "") != TRUE))
mloutstr( "Default startup failed!") ;
discmd = TRUE; /* P.K. */
/* if there are any files to read, read the first one! */
@@ -364,133 +328,11 @@ int main(int argc, char **argv)
if( forwhunt( FALSE, 0))
mloutfmt( "Found on line %d", getcline()) ;
/* Setup to process commands. */
lastflag = 0; /* Fake last flags. */
loop:
/* Execute the "command" macro...normally null. */
saveflag = lastflag; /* Preserve lastflag through this. */
execute(META | SPEC | 'C', FALSE, 1);
lastflag = saveflag;
#if TYPEAH && PKCODE
if (typahead()) {
newc = getcmd();
update(FALSE);
do {
fn_t execfunc;
if (c == newc && (execfunc = getbind(c)) != NULL
&& execfunc != insert_newline
&& execfunc != insert_tab)
newc = getcmd();
else
break;
} while (typahead());
c = newc;
} else {
update(FALSE);
c = getcmd();
}
#else
/* Fix up the screen */
update(FALSE);
/* get the next command from the keyboard */
c = getcmd();
#endif
/* if there is something on the command line, clear it */
if (mpresf != FALSE) {
mloutstr( "") ;
update(FALSE);
#if CLRMSG
if (c == ' ') /* ITS EMACS does this */
goto loop;
#endif
}
f = FALSE;
n = 1;
/* do META-# processing if needed */
basec = c & ~META; /* strip meta char off if there */
if ((c & META) && ((basec >= '0' && basec <= '9') || basec == '-')) {
f = TRUE; /* there is a # arg */
n = 0; /* start with a zero default */
mflag = 1; /* current minus flag */
c = basec; /* strip the META */
while ((c >= '0' && c <= '9') || (c == '-')) {
if (c == '-') {
/* already hit a minus or digit? */
if ((mflag == -1) || (n != 0))
break;
mflag = -1;
} else {
n = n * 10 + (c - '0');
}
if ((n == 0) && (mflag == -1)) /* lonely - */
mloutstr( "Arg:") ;
else
mloutfmt( "Arg: %d", n * mflag) ;
c = getcmd(); /* get the next key */
}
n = n * mflag; /* figure in the sign */
}
/* do ^U repeat argument processing */
if (c == reptc) { /* ^U, start argument */
f = TRUE;
n = 4; /* with argument of 4 */
mflag = 0; /* that can be discarded. */
mloutstr( "Arg: 4") ;
while (((c = getcmd()) >= '0' && c <= '9') || c == reptc
|| c == '-') {
if (c == reptc)
if ((n > 0) == ((n * 4) > 0))
n = n * 4;
else
n = 1;
/*
* If dash, and start of argument string, set arg.
* to -1. Otherwise, insert it.
*/
else if (c == '-') {
if (mflag)
break;
n = 0;
mflag = -1;
}
/*
* If first digit entered, replace previous argument
* with digit and set sign. Otherwise, append to arg.
*/
else {
if (!mflag) {
n = 0;
mflag = 1;
}
n = 10 * n + c - '0';
}
mloutfmt( "Arg: %d", (mflag >= 0) ? n : (n ? -n : -1)) ;
}
/*
* Make arguments preceded by a minus sign negative and change
* the special argument "^U -" to an effective "^U -1".
*/
if (mflag == -1) {
if (n == 0)
n++;
n = -n;
}
}
/* and execute the command */
execute(c, f, n);
goto loop;
kbd_loop() ;
return EXIT_SUCCESS ; /* never reached */
}
/*
* Initialize all of the buffers and windows. The buffer name is passed down
* as an argument, because the main routine may have been told to read in a
@@ -501,10 +343,9 @@ static void edinit(char *bname)
struct buffer *bp;
struct window *wp;
bp = bfind(bname, TRUE, 0); /* First buffer */
blistp = bfind("*List*", TRUE, BFINVS); /* Buffer list buffer */
wp = (struct window *)malloc(sizeof(struct window)); /* First window */
if (bp == NULL || wp == NULL || blistp == NULL) {
if( NULL == (bp = bfind( bname, TRUE, 0)) /* First buffer */
|| NULL == (blistp = bfind( "*List*", TRUE, BFINVS)) /* Buffer list buffer */
|| NULL == (wp = (struct window *) malloc( sizeof( struct window)))) { /* First window */
fputs( "First initialisation failed!\n", stderr) ;
exit( EXIT_FAILURE) ;
}

99
maze.cmd Normal file
View File

@@ -0,0 +1,99 @@
# record seed
# 5 set $seed
set %S $seed
# setup direction offsets
set %D1 0
set %D2 1
set %D3 0
set %D4 -1
set %D5 0
# draw the maze layout
$curwidth insert-string " "
newline
set %w &sub $curwidth 2
!if &equ 0 &mod %w 2
set %w &sub %w 1
!endif
insert-string " "
%w insert-string ""
insert-string " "
set %buf $line
set %l &sub $pagelen 4
!if &equ 1 &mod %l 2
set %l &sub %l 1
!endif
set %cnt %l
!while &less 0 %cnt
set %cnt &sub %cnt 1
newline
insert-string %buf
!endwhile
newline
set %w &add %w 1
%w insert-string " "
set %l &add %l 3
# draw the exit
set $curline &sub %l 2
set $curcol &sub %w 1
set $curchar 32
# draw the maze
set %x 2
set %y 3
set $curline %y
set $curcol %x
set $curchar 32
set %flags 0
set %cnt &tim &sub &div %w 2 1 &sub &div %l 2 1
!while &les 1 %cnt
!if &or &equ %flags 15 &not &equ $curchar 32
set %flags 0
set %y &add %y 2
!if &equ %y %l
set %y 3
set %x &add %x 2
!if &equ %x %w
set %x 2
!endif
!endif
!else
set %D &rnd 4
set %OX &ind &cat "%D" %D
set %OY &ind &cat "%D" &add %D 1
set $curline &add %y &tim 2 %OY
set %i &add %x &tim 2 %OX
set $curcol %i
!if &equ $curchar 32
!if &equ %D 3 # turn direction into bitmask {1,2,4,8}
set %D 8
!endif
set %flags &bor %flags %D # mark direction as checked
!else
set $curchar 32
set %y $curline # update current position
set %x %i
set $curline &sub %y %OY # erase path between old and cur pos
set $curcol &sub %x %OX
set $curchar 32
set %flags 0
set %cnt &sub %cnt 1
!endif
!endif
set $curline %y
set $curcol %x
!endwhile
# id maze
beginning-of-file
kill-to-end-of-line
insert-string &cat " Maze " &cat %w &cat "x" &cat &sub %l 2 &cat " #" %S
write-message $line
&sub $curwidth $curcol insert-string " "
# draw the entrance
set $curline 3
set $curcol 1
set $curchar 32

View File

@@ -1,3 +1,5 @@
/* mingw32.c -- */
#ifdef MINGW32
#include "termio.h"
#include "terminal.h"
@@ -77,7 +79,7 @@ void ttopen( void) {
void ttclose( void) {
}
int ttputc( int c) {
int ttputc( unicode_t c) {
char utf8[ 6] ;
int bytes ;
@@ -188,4 +190,8 @@ static void ttmove( int l, int c) {
wgoxy( c, l) ;
}
#else
typedef void _pedantic_empty_translation_unit ;
#endif
/* end of mingw32.c */

29
names.c
View File

@@ -34,10 +34,10 @@ struct name_bind names[] = {
#if APROP
{"apropos", apro},
#endif
{"backward-character", backchar},
{"backward-character", (fn_t) backchar},
{"begin-macro", ctlxlp},
{"beginning-of-file", gotobob},
{"beginning-of-line", gotobol},
{"beginning-of-file", (fn_t) gotobob},
{"beginning-of-line", (fn_t) gotobol},
{"bind-to-key", bindtokey},
{"buffer-position", showcpos},
{"case-region-lower", lowerregion},
@@ -71,12 +71,12 @@ struct name_bind names[] = {
{"detab-line", detab},
#endif
{"end-macro", ctlxrp},
{"end-of-file", gotoeob},
{"end-of-line", gotoeol},
{"end-of-file", (fn_t) gotoeob},
{"end-of-line", (fn_t) gotoeol},
#if AEDIT
{"entab-line", entab},
#endif
{"exchange-point-and-mark", swapmark},
{"exchange-point-and-mark", (fn_t) swapmark},
{"execute-buffer", execbuf},
{"execute-command-line", execcmd},
{"execute-file", execfile},
@@ -132,7 +132,7 @@ struct name_bind names[] = {
#endif
{"filter-buffer", filter_buffer},
{"find-file", filefind},
{"forward-character", forwchar},
{"forward-character", (fn_t) forwchar},
{"goto-line", gotoline},
#if CFENCE
{"goto-matching-fence", getfence},
@@ -165,8 +165,8 @@ struct name_bind names[] = {
{"newline", insert_newline},
{"newline-and-indent", indent},
{"next-buffer", nextbuffer},
{"next-line", forwline},
{"next-page", forwpage},
{"next-line", (fn_t) forwline},
{"next-page", (fn_t) forwpage},
#if WORDPRO
{"next-paragraph", gotoeop},
#endif
@@ -176,8 +176,8 @@ struct name_bind names[] = {
{"open-line", openline},
{"overwrite-string", ovstring},
{"pipe-command", pipecmd},
{"previous-line", backline},
{"previous-page", backpage},
{"previous-line", (fn_t) backline},
{"previous-page", (fn_t) backpage},
#if WORDPRO
{"previous-paragraph", gotobop},
#endif
@@ -205,11 +205,8 @@ struct name_bind names[] = {
{"search-reverse", backsearch},
{"select-buffer", usebuffer},
{"set", setvar},
#if CRYPT
{"set-encryption-key", set_encryption_key},
#endif
{"set-fill-column", setfillcol},
{"set-mark", setmark},
{"set-mark", (fn_t) setmark},
{"shell-command", spawn},
{"shrink-window", shrinkwind},
{"split-current-window", splitwind},
@@ -220,7 +217,7 @@ struct name_bind names[] = {
#if BSD | __hpux | SVR4
{"suspend-emacs", bktoshell},
#endif
{"transpose-characters", twiddle},
{"transpose-characters", (fn_t) twiddle},
#if AEDIT
{"trim-line", trim},
#endif

View File

@@ -20,7 +20,8 @@
#endif
#include <errno.h>
#define MAXLOCK 512
/* Maximum file length name 255 */
#define MAXLOCK 256
#define MAXNAME 128
#if defined(SVR4) && ! defined(__linux__)
@@ -32,6 +33,7 @@ int gethostname(char *name, int namelen)
}
#endif
char *cuserid( char *retbuf) ; /* should have been declared in stdio.h */
/**********************
@@ -44,11 +46,14 @@ int gethostname(char *name, int namelen)
char *dolock( const char *fname)
{
int fd, n;
static char lname[MAXLOCK], locker[MAXNAME + 1];
char lname[ MAXLOCK] ;
static char locker[ MAXNAME + 1] ;
int mask;
struct stat sbuf;
strcat(strcpy(lname, fname), ".lock~");
strncpy( lname, fname, sizeof lname - 1 - 6) ;
lname[ sizeof lname - 1 - 6] = 0 ;
strcat( lname, ".lock~") ;
/* check that we are not being cheated, qname must point to */
/* a regular file - even this code leaves a small window of */
@@ -80,8 +85,15 @@ char *dolock( const char *fname)
}
if ((n = read(fd, locker, MAXNAME)) < 1) {
lseek(fd, 0, SEEK_SET);
/* strcpy(locker, getlogin()); */
cuserid(locker);
/*
** Since Ubuntu 17.04, cuserid prototype seems missing. Replacing it by
** getlogin does the trick on 64 bits but fails on 32 bits.
** So let's work around with cuserid for a while.
** logname = getlogin() ;
** strcpy( locker, logname ? logname : cuserid( NULL)) ;
*/
strcpy( locker, cuserid( NULL)) ;
strcat(locker + strlen(locker), "@");
gethostname(locker + strlen(locker), 64);
{
@@ -111,11 +123,12 @@ char *dolock( const char *fname)
*
*********************/
char *undolock( const char *fname)
{
static char lname[MAXLOCK];
char *undolock( const char *fname) {
char lname[ MAXLOCK] ;
strcat(strcpy(lname, fname), ".lock~");
strncpy( lname, fname, sizeof lname - 1 - 6) ;
lname[ sizeof lname - 1 - 6] = 0 ;
strcat( lname, ".lock~") ;
if (unlink(lname) != 0) {
if (errno == EACCES || errno == ENOENT)
return NULL;
@@ -127,4 +140,9 @@ char *undolock( const char *fname)
}
return NULL;
}
#else
typedef void _pedantic_empty_translation_unit ;
#endif
/* end of pklock.c */

View File

@@ -119,8 +119,7 @@ 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).
*/
int ttputc(int c)
{
int ttputc( unicode_t c) {
char utf8[6];
int bytes;
@@ -250,4 +249,8 @@ int typahead(void)
return x;
}
#endif /* POSIX */
#else
typedef void _pedantic_empty_translation_unit ;
#endif /* not POSIX */
/* end of posix.c */

636
random.c
View File

@@ -1,8 +1,6 @@
/* random.c -- implements random.h */
#include "random.h"
#define NBRACE 1 /* new style brace matching command */
/* random.c
*
* This file contains the command processing functions for a number of
@@ -40,7 +38,7 @@ static const char *cname[] = { /* names of colors */
int gfcolor = NCOLORS - 1 ; /* global forgrnd color (white) */
int gbcolor = 0 ; /* global backgrnd color (black) */
static int tabsize ; /* Tab size (0: use real tabs) */
boolean hardtab = TRUE ; /* use hard tab instead of soft tab */
int fillcol = 72 ; /* Current fill column */
/* uninitialized global definitions */
@@ -83,33 +81,21 @@ int showcpos(int f, int n)
int savepos; /* temp save for current offset */
int ecol; /* column pos/end of current line */
/* starting at the beginning of the buffer */
lp = lforw(curbp->b_linep);
/* start counting chars and lines */
numchars = 0;
numlines = 0;
predchars = 0;
predlines = 0;
curchar = 0;
bytes = 1 ;
while (lp != curbp->b_linep) {
bytes = lgetchar( &curchar) ;
for( lp = lforw( curbp->b_linep) ; lp != curbp->b_linep ; lp = lforw( lp)) {
/* if we are on the current line, record it */
if (lp == curwp->w_dotp) {
int len ;
predlines = numlines;
predchars = numchars + curwp->w_doto;
len = llength( lp) ;
if( (curwp->w_doto) == len)
curchar = (curbp->b_mode & MDDOS) ? '\r' : '\n' ;
else
bytes = utf8_to_unicode( lp->l_text, curwp->w_doto, len, &curchar) ;
}
/* on to the next line */
++numlines;
numchars += llength( lp) + ((curbp->b_mode & MDDOS) ? 2 : 1) ;
lp = lforw(lp);
}
/* if at end of file, record it */
@@ -179,12 +165,13 @@ int getccol(int bflg)
if( bflg && c != ' ' && c != '\t') /* Request Stop at first non-blank */
break;
if (c == '\t')
col |= tabmask;
col += tabwidth - col % tabwidth ;
else if (c < 0x20 || c == 0x7F) /* displayed as ^c */
++col;
col += 2 ;
else if (c >= 0x80 && c <= 0xa0) /* displayed as \xx */
col += 2;
++col;
col += 3 ;
else
col += 1 ;
}
return col;
}
@@ -194,35 +181,36 @@ int getccol(int bflg)
*
* int pos; position to set cursor
*/
int setccol(int pos)
{
int c; /* character being scanned */
boolean setccol( int pos) {
int i; /* index into current line */
int col; /* current cursor column */
int llen; /* length of line in bytes */
char *text ;
col = 0;
llen = llength(curwp->w_dotp);
text = curwp->w_dotp->l_text ;
/* scan the line until we are at or past the target column */
for (i = 0; i < llen; ++i) {
/* upon reaching the target, drop out */
if (col >= pos)
break;
for( i = 0 ; i < llen && col < pos ; ) {
unicode_t c ; /* character being scanned */
/* advance one character */
c = lgetc(curwp->w_dotp, i);
/* advance one character */
i += utf8_to_unicode( text, i, llen, &c) ;
if (c == '\t')
col |= tabmask;
else if (c < 0x20 || c == 0x7F)
++col;
++col;
col += tabwidth - col % tabwidth ;
else if (c < 0x20 || c == 0x7F) /* displayed as ^C */
col += 2 ;
else if (c >= 0x80 && c <= 0xa0) /* displayed as \xx */
col += 3 ;
else
col += 1 ;
}
/* set us at the new position */
curwp->w_doto = i;
/* and tell weather we made it */
/* and tell whether we made it */
return col >= pos;
}
@@ -233,27 +221,36 @@ int setccol(int pos)
* work. This fixes up a very common typo with a single stroke. Normally bound
* to "C-T". This always works within a line, so "WFEDIT" is good enough.
*/
int twiddle(int f, int n)
{
struct line *dotp;
int doto;
int cl;
int cr;
boolean twiddle( int f, int n) {
unicode_t c ;
int len ;
boolean eof_f = FALSE ;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
dotp = curwp->w_dotp;
doto = curwp->w_doto;
if (doto == llength(dotp) && --doto < 0)
return FALSE;
cr = lgetc(dotp, doto);
if (--doto < 0)
return FALSE;
cl = lgetc(dotp, doto);
lputc(dotp, doto + 0, cr);
lputc(dotp, doto + 1, cl);
lchange(WFEDIT);
return TRUE;
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
len = llength( curwp->w_dotp) ;
if( len < 2 || curwp->w_doto == 0) /* at least 2 chars & not bol */
return FALSE ;
if( curwp->w_doto == len) { /* at end of line */
backchar( FALSE, 1) ;
eof_f = TRUE ;
}
len = lgetchar( &c) ; /* len => unicode or extended ASCII */
ldelchar( 1, FALSE) ;
backchar( FALSE, 1) ;
if( len == 1)
linsert_byte( 1, c) ;
else
linsert( 1, c) ;
if( eof_f == TRUE)
forwchar( FALSE, 1) ;
lchange( WFEDIT) ;
return TRUE ;
}
/*
@@ -264,7 +261,6 @@ int twiddle(int f, int n)
*/
int quote(int f, int n)
{
int s;
int c;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
@@ -275,6 +271,8 @@ int quote(int f, int n)
if (n == 0)
return TRUE;
if (c == '\n') {
int s ;
do {
s = lnewline();
} while (s == TRUE && --n);
@@ -290,17 +288,21 @@ int quote(int f, int n)
* done in this slightly funny way because the tab (in ASCII) has been turned
* into "C-I" (in 10 bit code) already. Bound to "C-I".
*/
int insert_tab(int f, int n)
{
if (n < 0)
return FALSE;
if (n == 0 || n > 1) {
tabsize = n;
return TRUE;
}
if (!tabsize)
return linsert(1, '\t');
return linsert(tabsize - (getccol(FALSE) % tabsize), ' ');
int insert_tab( int f, int n) {
int status ;
if( n < 0)
status = FALSE ;
else if( n == 0)
status = TRUE ;
else if( hardtab == TRUE)
status = linsert( n, '\t') ;
else /* softtab */
do {
status = linsert( tabwidth - getccol( FALSE) % tabwidth, ' ') ;
} while( status != FALSE && --n) ;
return status ;
}
#if AEDIT
@@ -327,23 +329,27 @@ int detab(int f, int n)
/* detab the entire current line */
while (curwp->w_doto < llength(curwp->w_dotp)) {
/* if we have a tab */
if (lgetc(curwp->w_dotp, curwp->w_doto) == '\t') {
ldelchar(1, FALSE);
insspace(TRUE,
(tabmask + 1) -
(curwp->w_doto & tabmask));
}
forwchar(FALSE, 1);
if( curwbyte() == '\t') {
int size ;
ldelchar( 1, FALSE) ;
size = tabwidth - curwp->w_doto % tabwidth ;
insspace( TRUE, size) ;
forwchar( TRUE, size) ;
} else
forwchar( FALSE, 1) ;
}
/* advance/or back to the next line */
forwline(TRUE, inc);
if( forwline( TRUE, inc) == FALSE)
break ;
n -= inc;
}
curwp->w_doto = 0; /* to the begining of the line */
thisflag &= ~CFCPCN; /* flag that this resets the goal column */
lchange(WFEDIT); /* yes, we have made at least an edit */
return TRUE;
return (n == 0) ? TRUE : FALSE ;
}
/*
@@ -353,12 +359,9 @@ int detab(int f, int n)
*/
int entab(int f, int n)
{
#define nextab(a) (a & ~tabmask) + (tabmask+1)
#define nextab(a) (a + tabwidth - a % tabwidth)
int inc; /* increment to next line [sgn(n)] */
int fspace; /* pointer to first space if in a run */
int ccol; /* current cursor column */
char cchar; /* current character */
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
@@ -369,6 +372,9 @@ int entab(int f, int n)
/* loop thru entabbing n lines */
inc = ((n > 0) ? 1 : -1);
while (n) {
int fspace ; /* pointer to first space if in a run */
int ccol ; /* current cursor column */
curwp->w_doto = 0; /* start at the beginning */
/* entab the entire current line */
@@ -383,17 +389,14 @@ int entab(int f, int n)
/* there is a bug here dealing with mixed space/tabed
lines.......it will get fixed */
backchar(TRUE, ccol - fspace);
ldelete((long) (ccol - fspace),
FALSE);
ldelete( (long) (ccol - fspace), FALSE) ;
linsert(1, '\t');
fspace = -1;
}
}
/* get the current character */
cchar = lgetc(curwp->w_dotp, curwp->w_doto);
switch (cchar) {
switch( curwbyte()) {
case '\t': /* a tab...count em up */
ccol = nextab(ccol);
break;
@@ -407,19 +410,21 @@ int entab(int f, int n)
default: /* any other char...just count */
ccol++;
fspace = -1;
break;
}
forwchar(FALSE, 1);
}
/* advance/or back to the next line */
forwline(TRUE, inc);
if( forwline( TRUE, inc) == FALSE)
break ;
n -= inc;
}
curwp->w_doto = 0; /* to the begining of the line */
thisflag &= ~CFCPCN; /* flag that this resets the goal column */
lchange(WFEDIT); /* yes, we have made at least an edit */
return TRUE;
return (n == 0) ? TRUE : FALSE ;
}
/*
@@ -429,9 +434,6 @@ int entab(int f, int n)
*/
int trim(int f, int n)
{
struct line *lp; /* current line pointer */
int offset; /* original line offset position */
int length; /* current length */
int inc; /* increment to next line [sgn(n)] */
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
@@ -443,26 +445,31 @@ int trim(int f, int n)
/* loop thru trimming n lines */
inc = ((n > 0) ? 1 : -1);
while (n) {
line_p lp ; /* current line pointer */
int offset ; /* original line offset position */
int length ; /* current length */
lp = curwp->w_dotp; /* find current line text */
offset = curwp->w_doto; /* save original offset */
length = lp->l_used; /* find current length */
/* trim the current line */
while (length > offset) {
if (lgetc(lp, length - 1) != ' ' &&
lgetc(lp, length - 1) != '\t')
break;
length--;
for( length = lp->l_used ; length > offset ; length--) {
char c = lgetc( lp, length - 1) ;
if( c != ' ' && c != '\t')
break ;
}
lp->l_used = length;
/* advance/or back to the next line */
forwline(TRUE, inc);
if( forwline( TRUE, inc) == FALSE)
break ;
n -= inc;
}
lchange(WFEDIT);
thisflag &= ~CFCPCN; /* flag that this resets the goal column */
return TRUE;
return (n == 0) ? TRUE : FALSE ;
}
#endif
@@ -497,8 +504,6 @@ int openline(int f, int n)
*/
int insert_newline(int f, int n)
{
int s;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (n < 0)
@@ -521,6 +526,8 @@ int insert_newline(int f, int n)
/* insert some lines */
while (n--) {
int s ;
if ((s = lnewline()) != TRUE)
return s;
#if SCROLLCODE
@@ -535,197 +542,59 @@ static int cinsert(void)
char *cptr; /* string pointer into text to copy */
int tptr; /* index to scan into line */
int bracef; /* was there a brace at the end of line? */
int i;
char ichar[NSTRING]; /* buffer to hold indent of last line */
int i, nicol ;
/* grab a pointer to text to copy indentation from */
cptr = &curwp->w_dotp->l_text[0];
/* check for a brace */
tptr = curwp->w_doto - 1;
bracef = (cptr[tptr] == '{');
tptr = curwp->w_doto ;
bracef = (tptr > 0) && (cptr[ tptr - 1] == '{') ;
/* save the indent of the previous line */
i = 0;
while ((i < tptr) && (cptr[i] == ' ' || cptr[i] == '\t')
&& (i < NSTRING - 1)) {
ichar[i] = cptr[i];
++i;
nicol = 0 ;
for( i = 0 ; i < tptr ; i += 1) {
int ch ;
ch = cptr[ i] ;
if( ch == ' ')
nicol += 1 ;
else if( ch == '\t')
nicol += tabwidth - nicol % tabwidth ;
else
break ;
}
ichar[i] = 0; /* terminate it */
if( i == tptr) { /* all line is blank */
curwp->w_doto = 0 ; /* gotobol */
lnewline() ;
curwp->w_doto = tptr ; /* gotoeol */
} else {
/* put in the newline */
if (lnewline() == FALSE)
return FALSE;
if (lnewline() == FALSE)
return FALSE;
/* and the saved indentation */
linstr(ichar);
i = nicol % tabwidth ; /* spaces */
nicol /= tabwidth ; /* tabs */
if( bracef) {
/* and one more tab for a brace */
nicol += 1 ;
i = 0 ;
}
/* and one more tab for a brace */
if (bracef)
insert_tab(FALSE, 1);
if( nicol > 0)
insert_tab( FALSE, nicol) ;
if( i > 0)
linsert( i, ' ') ;
}
#if SCROLLCODE
curwp->w_flag |= WFINS;
#endif
return TRUE;
}
#if NBRACE
/*
* insert a brace into the text here...we are in CMODE
*
* int n; repeat count
* int c; brace to insert (always } for now)
*/
int insbrace(int n, int c)
{
int ch; /* last character before input */
int oc; /* caractere oppose a c */
int i, count;
int target; /* column brace should go after */
struct line *oldlp;
int oldoff;
/* if we aren't at the beginning of the line... */
if (curwp->w_doto != 0)
/* scan to see if all space before this is white space */
for (i = curwp->w_doto - 1; i >= 0; --i) {
ch = lgetc(curwp->w_dotp, i);
if (ch != ' ' && ch != '\t')
return linsert(n, c);
}
/* chercher le caractere oppose correspondant */
switch (c) {
case '}':
oc = '{';
break;
case ']':
oc = '[';
break;
case ')':
oc = '(';
break;
default:
return FALSE;
}
oldlp = curwp->w_dotp;
oldoff = curwp->w_doto;
count = 1;
backchar(FALSE, 1);
while (count > 0) {
if (curwp->w_doto == llength(curwp->w_dotp))
ch = '\n';
else
ch = lgetc(curwp->w_dotp, curwp->w_doto);
if (ch == c)
++count;
if (ch == oc)
--count;
backchar(FALSE, 1);
if (boundry(curwp->w_dotp, curwp->w_doto, REVERSE))
break;
}
if (count != 0) { /* no match */
curwp->w_dotp = oldlp;
curwp->w_doto = oldoff;
return linsert(n, c);
}
curwp->w_doto = 0; /* debut de ligne */
/* aller au debut de la ligne apres la tabulation */
while ((ch = lgetc(curwp->w_dotp, curwp->w_doto)) == ' '
|| ch == '\t')
forwchar(FALSE, 1);
/* delete back first */
target = getccol(FALSE); /* c'est l'indent que l'on doit avoir */
curwp->w_dotp = oldlp;
curwp->w_doto = oldoff;
while (target != getccol(FALSE)) {
if (target < getccol(FALSE)) /* on doit detruire des caracteres */
while (getccol(FALSE) > target)
backdel(FALSE, 1);
else { /* on doit en inserer */
while (target - getccol(FALSE) >= 8)
linsert(1, '\t');
linsert(target - getccol(FALSE), ' ');
}
}
/* and insert the required brace(s) */
return linsert(n, c);
}
#else
/*
* insert a brace into the text here...we are in CMODE
*
* int n; repeat count
* int c; brace to insert (always { for now)
*/
int insbrace(int n, int c)
{
int ch; /* last character before input */
int i;
int target; /* column brace should go after */
/* if we are at the beginning of the line, no go */
if (curwp->w_doto == 0)
return linsert(n, c);
/* scan to see if all space before this is white space */
for (i = curwp->w_doto - 1; i >= 0; --i) {
ch = lgetc(curwp->w_dotp, i);
if (ch != ' ' && ch != '\t')
return linsert(n, c);
}
/* delete back first */
target = getccol(FALSE); /* calc where we will delete to */
target -= 1;
target -= target % (tabsize == 0 ? 8 : tabsize);
while (getccol(FALSE) > target)
backdel(FALSE, 1);
/* and insert the required brace(s) */
return linsert(n, c);
}
#endif
int inspound(void)
{ /* insert a # into the text here...we are in CMODE */
int ch; /* last character before input */
int i;
/* if we are at the beginning of the line, no go */
if (curwp->w_doto == 0)
return linsert(1, '#');
/* scan to see if all space before this is white space */
for (i = curwp->w_doto - 1; i >= 0; --i) {
ch = lgetc(curwp->w_dotp, i);
if (ch != ' ' && ch != '\t')
return linsert(1, '#');
}
/* delete back first */
while (getccol(FALSE) >= 1)
backdel(FALSE, 1);
/* and insert the required pound */
return linsert(1, '#');
}
/*
* Delete blank lines around dot. What this command does depends if dot is
@@ -759,38 +628,45 @@ int deblank(int f, int n)
/*
* Insert a newline, then enough tabs and spaces to duplicate the indentation
* of the previous line. Assumes tabs are every eight characters. Quite simple.
* of the previous line. Assumes tabs are every tabwidth characters.
* Figure out the indentation of the current line. Insert a newline by calling
* the standard routine. Insert the indentation by inserting the right number
* of tabs and spaces. Return TRUE if all ok. Return FALSE if one of the
* subcomands failed. Normally bound to "C-J".
*/
int indent(int f, int n)
{
int nicol;
int c;
int i;
int indent( int f, int n) {
int nicol ;
int i ;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (n < 0)
return FALSE;
while (n--) {
nicol = 0;
for (i = 0; i < llength(curwp->w_dotp); ++i) {
c = lgetc(curwp->w_dotp, i);
if (c != ' ' && c != '\t')
break;
if (c == '\t')
nicol |= tabmask;
++nicol;
}
if (lnewline() == FALSE
|| ((i = nicol / 8) != 0 && linsert(i, '\t') == FALSE)
|| ((i = nicol % 8) != 0 && linsert(i, ' ') == FALSE))
return FALSE;
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
if( n < 0)
return FALSE ;
/* number of columns to indent */
nicol = 0 ;
for( i = 0 ; i < llength( curwp->w_dotp) ; i += 1) {
int c ;
c = lgetc( curwp->w_dotp, i) ;
if( c == '\t')
nicol += tabwidth - nicol % tabwidth ;
else if( c == ' ')
nicol += 1 ;
else
break ;
}
return TRUE;
i = nicol / tabwidth ; /* # of tab to insert */
nicol %= tabwidth ; /* # of space to insert */
while( n--)
if( lnewline() == FALSE
|| ( i != 0 && insert_tab( FALSE, i) == FALSE)
|| ( nicol != 0 && linsert( nicol, ' ') == FALSE))
return FALSE ;
return TRUE ;
}
/*
@@ -799,18 +675,22 @@ int indent(int f, int n)
* If any argument is present, it kills rather than deletes, to prevent loss
* of text if typed with a big argument. Normally bound to "C-D".
*/
int forwdel(int f, int n)
{
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (n < 0)
return backdel(f, -n);
int forwdel( int f, int n) {
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
if( n == 0)
return TRUE ;
else if( n < 0)
return backdel( f, -n) ;
if (f != FALSE) { /* Really a kill. */
if ((lastflag & CFKILL) == 0)
kdelete();
thisflag |= CFKILL;
}
return ldelchar((long) n, f);
return ldelchar( n, f != FALSE) ;
}
/*
@@ -819,22 +699,22 @@ int forwdel(int f, int n)
* forward, this actually does a kill if presented with an argument. Bound to
* both "RUBOUT" and "C-H".
*/
int backdel(int f, int n)
{
int s;
int backdel( int f, int n) {
if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly() ; /* we are in read only mode */
if( n == 0)
return TRUE ;
else if( n < 0)
return forwdel( f, -n) ;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
if (n < 0)
return forwdel(f, -n);
if (f != FALSE) { /* Really a kill. */
if ((lastflag & CFKILL) == 0)
kdelete();
thisflag |= CFKILL;
}
if ((s = backchar(f, n)) == TRUE)
s = ldelchar(n, f);
return s;
return backchar( f, n) && ldelchar( n, f != FALSE) ;
}
/*
@@ -1077,115 +957,39 @@ int getfence(int f, int n)
return FALSE;
}
/* set up for scan */
count = 1;
if (sdir == REVERSE)
backchar(FALSE, 1);
else
forwchar(FALSE, 1);
/* scan until we find a match, or reach the end of file */
count = 1 ;
do {
if( boundry( curwp->w_dotp, curwp->w_doto, sdir)) {
/* at buffer limit, no match to be found */
/* restore the current position */
curwp->w_dotp = oldlp ;
curwp->w_doto = oldoff ;
TTbeep() ;
return FALSE ;
}
/* scan until we find it, or reach the end of file */
while (count > 0) {
if (curwp->w_doto == llength(curwp->w_dotp))
c = '\n';
if( sdir == FORWARD)
forwchar( FALSE, 1) ;
else
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (c == ch)
++count;
if (c == ofence)
--count;
if (sdir == FORWARD)
forwchar(FALSE, 1);
else
backchar(FALSE, 1);
if (boundry(curwp->w_dotp, curwp->w_doto, sdir))
break;
}
backchar( FALSE, 1) ;
/* if count is zero, we have a match, move the sucker */
if (count == 0) {
if (sdir == FORWARD)
backchar(FALSE, 1);
else
forwchar(FALSE, 1);
curwp->w_flag |= WFMOVE;
return TRUE;
}
/* if no eol */
if( curwp->w_doto != llength(curwp->w_dotp)) {
c = curwbyte() ;
if( c == ch)
++count ;
else if( c == ofence)
--count ;
}
} while( count > 0) ;
/* restore the current position */
curwp->w_dotp = oldlp;
curwp->w_doto = oldoff;
TTbeep();
return FALSE;
/* we have a match, move the sucker */
curwp->w_flag |= WFMOVE ;
return TRUE ;
}
#endif
/*
* Close fences are matched against their partners, and if
* on screen the cursor briefly lights there
*
* char ch; fence type to match against
*/
int fmatch(int ch)
{
struct line *oldlp; /* original line pointer */
int oldoff; /* and offset */
struct line *toplp; /* top line in current window */
int count; /* current fence level count */
char opench; /* open fence */
char c; /* current character in scan */
int i;
/* first get the display update out there */
update(FALSE);
/* save the original cursor position */
oldlp = curwp->w_dotp;
oldoff = curwp->w_doto;
/* setup proper open fence for passed close fence */
if (ch == ')')
opench = '(';
else if (ch == '}')
opench = '{';
else
opench = '[';
/* find the top line and set up for scan */
toplp = curwp->w_linep->l_bp;
count = 1;
backchar(FALSE, 2);
/* scan back until we find it, or reach past the top of the window */
while (count > 0 && curwp->w_dotp != toplp) {
if (curwp->w_doto == llength(curwp->w_dotp))
c = '\n';
else
c = lgetc(curwp->w_dotp, curwp->w_doto);
if (c == ch)
++count;
if (c == opench)
--count;
backchar(FALSE, 1);
if (curwp->w_dotp == curwp->w_bufp->b_linep->l_fp &&
curwp->w_doto == 0)
break;
}
/* if count is zero, we have a match, display the sucker */
/* there is a real machine dependant timing problem here we have
yet to solve......... */
if (count == 0) {
forwchar(FALSE, 1);
for (i = 0; i < term.t_pause; i++)
update(FALSE);
}
/* restore the current position */
curwp->w_dotp = oldlp;
curwp->w_doto = oldoff;
return TRUE;
}
static int iovstring( int f, int n, const char *prompt, int (*fun)( char *)) {
int status ; /* status return code */

View File

@@ -1,9 +1,14 @@
#ifndef _RANDOM_H_
#define _RANDOM_H_
#include "retcode.h"
#define AEDIT 1
extern int fillcol ; /* Fill column */
extern boolean hardtab ; /* Use hard tab instead of soft tab */
/* Uninitialized global external declarations. */
@@ -18,8 +23,8 @@ 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) ;
boolean setccol( int pos) ;
boolean twiddle( int f, int n) ;
int quote( int f, int n) ;
int insert_tab( int f, int n) ;
#if AEDIT
@@ -29,8 +34,6 @@ int trim( int f, int n) ;
#endif
int openline( int f, int n) ;
int insert_newline( int f, int n) ;
int insbrace( int n, int c) ;
int inspound( void) ;
int deblank( int f, int n) ;
int indent( int f, int n) ;
int forwdel( int f, int n) ;
@@ -41,7 +44,6 @@ int delmode( int f, int n) ;
int setgmode( int f, int n) ;
int delgmode( int f, int n) ;
int getfence( int f, int n) ;
int fmatch( int ch) ;
int istring( int f, int n) ;
int ovstring( int f, int n) ;

View File

@@ -2,24 +2,19 @@
#define __RETCODE_H__
#ifdef FALSE
#error "FALSE shouldn't be defined"
#undef FALSE
#endif
#ifdef TRUE
#error "TRUE shouldn't be defined"
#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
FALSE, /* 0, false, no, bad, etc. */
TRUE /* 1, true, yes, good, etc. */
} boolean ;
#define ABORT 2
#define ABORT 2 /* 2, death, ^G, abort, etc. */
#endif

10
screensize.cmd Normal file
View File

@@ -0,0 +1,10 @@
# Visualize Screen Dimensions
insert-string &cat $curwidth &cat "x" $pagelen
insert-string &rig "---------+" &sub 10 $curcol
&sub &div $curwidth 10 1 insert-string "---------+"
insert-string &lef "1234567890" &mod $curwidth 10
end-of-file
&sub $pagelen 3 execute-command-line "insert-string &cat $curline ~n"
beginning-of-file
unmark-buffer
write-message $line

36
tcap.c
View File

@@ -88,7 +88,9 @@ static char *CS, *DL, *AL, *SF, *SR;
#endif
struct terminal term = {
0, /* These four values are set dynamically at open time. */
270, /* actual 269 on 1920x1080 landscape terminal window */
1910, /* actual 1901 */
0, /* These four values are set dynamically at open time. */
0,
0,
0,
@@ -144,34 +146,24 @@ static void tcapopen(void)
}
/* Get screen size from system, or else from termcap. */
getscreensize(&int_col, &int_row);
term.t_nrow = int_row - 1;
term.t_ncol = int_col;
if ((term.t_nrow <= 0)
&& (term.t_nrow = (short) tgetnum("li") - 1) == -1) {
getscreensize( &int_col, &int_row) ;
if( (int_row <= 0)
&& ((int_row = tgetnum("li")) == -1)) {
fputs( "termcap entry incomplete (lines)\n", stderr) ;
exit( EXIT_FAILURE) ;
}
if ((term.t_ncol <= 0)
&& (term.t_ncol = (short) tgetnum("co")) == -1) {
if( (int_col <= 0)
&& ((int_col = tgetnum("co")) == -1)) {
fputs( "Termcap entry incomplete (columns)\n", stderr) ;
exit( EXIT_FAILURE) ;
}
#ifdef SIGWINCH
/* At initialization we use maximum size even if current OS window is smaller */
term.t_mrow = MAXROW ;
term.t_mcol = MAXCOL ;
if( term.t_nrow >= term.t_mrow)
term.t_nrow = term.t_mrow - 1 ;
if( term.t_ncol > term.t_mcol)
term.t_ncol = term.t_mcol ;
#else
term.t_mrow = term.t_nrow > MAXROW ? MAXROW : term.t_nrow;
term.t_mcol = term.t_ncol > MAXCOL ? MAXCOL : term.t_ncol;
#endif
term.t_mrow = int_row < term.t_maxrow ? int_row : term.t_maxrow ;
term.t_nrow = term.t_mrow - 1 ;
term.t_mcol = int_col < term.t_maxcol ? int_col : term.t_maxcol ;
term.t_ncol = term.t_mcol ;
p = tcapbuf;
t = tgetstr("pc", &p);
if (t)
@@ -370,6 +362,6 @@ static void tcapbeep(void)
static void putpad(char *str)
{
tputs(str, 1, ttputc);
tputs( str, 1, (int (*)( int)) ttputc) ;
}
#endif /* TERMCAP */

View File

@@ -4,6 +4,8 @@
#include "defines.h" /* COLOR, SCROLLCODE */
#include "retcode.h"
#include "utf8.h"
/*
* The editor communicates with the display using a high level interface. A
@@ -15,10 +17,12 @@
* 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. */
const short t_maxrow ; /* max number of rows allowable */
const short t_maxcol ; /* max number of columns allowable */
short t_mrow ; /* max number of rows displayable */
short t_nrow ; /* current number of rows displayed */
short t_mcol ; /* max number of rows displayable */
short t_ncol ; /* current number of columns displayed */
short t_margin; /* min margin for extended lines */
short t_scrsiz; /* size of scroll region " */
int t_pause; /* # times thru update to pause */
@@ -27,7 +31,7 @@ struct terminal {
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. */
int (*t_putchar)( unicode_t) ; /* 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. */

View File

@@ -276,30 +276,15 @@ void ttclose(void)
}
/*
* Write a character to the display. On VMS, terminal output is buffered, and
* we just put the characters in the big array, after checking for overflow.
* 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).
* Write a character to the display.
*/
int ttputc( int c) {
#if VMS
if (nobuf >= NOBUF)
ttflush();
obuf[nobuf++] = c;
#endif
int ttputc( unicode_t c) {
char utf8[ 4] ;
int bytes ;
#if MSDOS & ~IBMPC
bdos(6, c, 0);
#endif
#if V7 | USG | BSD
char utf8[6];
int bytes;
bytes = unicode_to_utf8(c, utf8);
fwrite(utf8, 1, bytes, stdout);
#endif
return 0 ;
bytes = unicode_to_utf8( c, utf8) ;
fwrite( utf8, 1, bytes, stdout) ;
return 0 ;
}
/*
@@ -463,4 +448,8 @@ int typahead( void)
}
#endif
#else
typedef void _pedantic_empty_translation_unit ;
#endif /* not POSIX */
/* end of termio.c */

View File

@@ -1,6 +1,8 @@
#ifndef _TERMIO_H_
#define _TERMIO_H_
#include "utf8.h"
#define TYPEAH 1 /* type ahead causes update to be skipped */
#define HUGE 1000 /* Huge number (for row/col) */
@@ -10,7 +12,7 @@ extern int ttcol ; /* Column location of HW cursor */
void ttopen( void) ;
void ttclose( void) ;
int ttputc( int c) ;
int ttputc( unicode_t c) ;
void ttflush( void) ;
int ttgetc( void) ;
int typahead( void) ;

View File

@@ -28,17 +28,14 @@ insert-string 123456789012345678901234567890123456789012345678901234567890123456
next-line
insert-string _________1_________2_________3_________4_________5_________6_________7_________8_________9_________0_________1_________2_________3
next-line
; Create and insert string variable until size exceed string limit [will be truncated to NSTRING - 1 (127)
; Create and insert string variable until size exceed 1024 characters or variable get truncated
set %nam 123
set %expect &len %nam
!while &equ &len %nam %expect
!while &and &les %expect 1024 &equ &len %nam %expect
insert-string %nam
newline
set %nam &cat %nam %nam
set %expect &tim %expect 2
!if &not &les %expect 1024
!break
!endif
!endwhile
insert-string %nam
newline
@@ -47,6 +44,7 @@ newline
insert-string &cat "Expected: " %expect
newline
; Use the variable as filename [will be truncated to NFILEN - 1 (79)]
set %nam &mid %nam 1 255
write-file %nam
insert-string &cat "Filename: " $cfname
newline
@@ -71,3 +69,4 @@ set-mark
end-of-file
copy-region
insert-string $kill
redraw-display

29
utf8.c
View File

@@ -17,13 +17,16 @@
* NOTE 2! This does *not* verify things like minimality. So overlong forms
* are happily accepted and decoded, as are the various "invalid values".
*/
unsigned utf8_to_unicode(char *line, unsigned index, unsigned len, unicode_t *res)
{
unsigned utf8_to_unicode( char *line, unsigned index, unsigned len,
unicode_t *res) {
unicode_t value ;
unsigned c = line[ index] & 0xFFU ;
unsigned c ;
unsigned bytes, mask, i;
*res = c;
if( index >= len)
return 0 ;
*res = c = line[ index] & 0xFFU ;
/*
* 0xxxxxxx is valid one byte utf8
@@ -66,15 +69,6 @@ unsigned utf8_to_unicode(char *line, unsigned index, unsigned len, unicode_t *re
return bytes;
}
static void reverse_string(char *begin, char *end)
{
do {
char a = *begin, b = *end;
*end = a; *begin = b;
begin++; end--;
} while (begin < end);
}
/*
* unicode_to_utf8()
*
@@ -108,8 +102,13 @@ unsigned unicode_to_utf8( unicode_t c, char *utf8) {
c >>= 6 ;
} while( c >= prefix) ;
*p = (char) (c - 2 * prefix) ;
reverse_string( utf8, p) ;
*p-- = *utf8 ;
*utf8++ = (char) (c - 2 * prefix) ;
if( utf8 < p) { /* swap middle two bytes if 4 bytes utf-8 code */
char c = *p ;
*p = *utf8 ;
*utf8 = c ;
}
}
return bytes ;

View File

@@ -12,6 +12,6 @@
# define PROGRAM_NAME_PFX "\xC2"
# define PROGRAM_NAME_LONG "\xB5""EMACS" /* UTF-8 µEMACS */
# define VERSION "4.2.1"
# define VERSION "4.2.4"
#endif /* VERSION_H_ */

View File

@@ -9,6 +9,7 @@
*
*/
#include <assert.h>
#include <stdio.h>
#include "basic.h"
@@ -623,6 +624,7 @@ int newsize(int f, int n)
} else {
/* rebuild the window structure */
assert( wheadp->w_toprow == 0) ; /* proves coverity wrong */
nextwp = wheadp;
wp = NULL;
lastwp = NULL;

View File

@@ -13,13 +13,13 @@
* the full blown redisplay is just too expensive to run for every input
* character.
*/
struct window {
typedef 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 "." */
line_p w_linep ; /* Top line in the window */
line_p w_dotp ; /* Line containing "." */
line_p w_markp ; /* Line containing "mark" */
int w_doto ; /* Byte offset for "." */
int w_marko; /* Byte offset for "mark" */
int w_toprow ; /* Origin 0 top row of window */
int w_ntrows ; /* # of rows of text in window */
@@ -29,10 +29,13 @@ struct window {
char w_fcolor; /* current forground color */
char w_bcolor; /* current background color */
#endif
};
} *window_p ;
extern struct window *curwp ; /* Current window */
extern struct window *wheadp ; /* Head of list of windows */
extern window_p curwp ; /* Current window */
extern window_p wheadp ; /* Head of list of windows */
/* curwbyte return the byte after the dot in current window */
#define curwbyte() lgetc( curwp->w_dotp, curwp->w_doto)
#define WFFORCE 0x01 /* Window needs forced reframe */
#define WFMOVE 0x02 /* Movement from line to line */
@@ -66,6 +69,6 @@ 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. */
window_p wpopup( void) ; /* Pop up window creation. */
#endif

View File

@@ -8,7 +8,7 @@
#include <stdio.h>
/* Standard error macro for reporting API errors */
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %ld from %s \
on line %d\n", __FILE__, GetLastError(), api, __LINE__);}
static void cls( HANDLE hConsole )