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

38 Commits
4.2.2 ... 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
40 changed files with 1423 additions and 1184 deletions

View File

@@ -33,7 +33,7 @@ CFLAGS=-O2 $(WARNINGS)
#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)
@@ -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,8 +129,8 @@ depend: ${SRC}
# DO NOT DELETE THIS LINE -- make depend uses it
basic.o: basic.c basic.h buffer.h line.h retcode.h utf8.h estruct.h \
input.h bind.h mlout.h random.h terminal.h defines.h window.h
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
@@ -139,40 +139,40 @@ bindable.o: bindable.c bindable.h defines.h buffer.h line.h retcode.h \
terminal.h
buffer.o: buffer.c buffer.h line.h retcode.h utf8.h defines.h estruct.h \
file.h input.h bind.h mlout.h window.h
display.o: display.c display.h estruct.h buffer.h line.h retcode.h utf8.h \
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 bind.h estruct.h bindable.h buffer.h \
line.h retcode.h utf8.h eval.h exec.h file.h isearch.h random.h region.h \
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 bind.h buffer.h line.h retcode.h utf8.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 file.h buffer.h line.h utf8.h input.h mlout.h search.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 exec.h \
retcode.h names.h terminal.h defines.h utf8.h wrapper.h
isearch.o: isearch.c isearch.h basic.h buffer.h line.h retcode.h utf8.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 line.h \
retcode.h utf8.h display.h eval.h execute.h file.h lock.h mlout.h \
random.h search.h terminal.h defines.h termio.h version.h window.h
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 line.h \
retcode.h utf8.h display.h estruct.h eval.h exec.h file.h isearch.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
@@ -186,13 +186,13 @@ search.o: search.c search.h line.h retcode.h utf8.h basic.h buffer.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
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.h estruct.h retcode.h utf8.h
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 line.h retcode.h utf8.h \
basic.h display.h estruct.h execute.h terminal.h wrapper.h
word.o: word.c word.h basic.h buffer.h line.h retcode.h utf8.h estruct.h \
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.

309
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) ;
@@ -69,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 ;
}
/*
@@ -120,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) ;
}
/*
@@ -229,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)
@@ -251,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
@@ -271,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)
@@ -293,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
@@ -311,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)") ;
@@ -321,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) {
@@ -344,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 */

10
bind.c
View File

@@ -456,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

117
buffer.c
View File

@@ -36,9 +36,6 @@ const char *modename[] = { /* name of modes */
int gmode = 0 ; /* global editor mode */
static const char modecode[] = "WCEVOMAUD" ; /* 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) ;
@@ -272,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;
@@ -322,90 +320,77 @@ int listbuffers(int f, int n)
*/
#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 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;
blistp->b_fname[ 0] = 0 ;
blistp->b_fname[ 0] = 0 ; /* in case of user override */
if( addline("ACT MODES Size Buffer File") == FALSE
|| addline("‾‾‾ ‾‾‾‾‾ ‾‾‾‾ ‾‾‾‾‾‾ ‾‾‾‾") == FALSE)
return FALSE;
/* build line to report global mode settings */
strcpy( line, " ") ;
cp1 = &line[ 4] ;
/* 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 */
/* output the list of buffers */
for( bp = bheadp ; bp != NULL ; bp = bp->b_bufp) { /* For all buffers */
/* skip invisible buffers if iflag is false */
char *cp1, *cp2 ;
int c ;
struct line *lp ;
long nbytes ; /* # of bytes in current buffer */
long nlines ; /* # of lines in current buffer */
/* skip invisible buffers if iflag is false */
if (((bp->b_flag & BFINVS) != 0) && (iflag != TRUE))
continue;
cp1 = &line[0]; /* Start at left edge */
do_layout( line, bp->b_mode) ;
cp1 = line ; /* Start at left edge */
/* output status of ACTIVE flag ('@' when the file has been read in) */
/* output status of ACTIVE flag ('@' when the file has been read in) */
*cp1++ = (bp->b_active == TRUE) ? '@' : ' ' ;
/* report if the file is truncated */
/* report if the file is truncated */
*cp1++ = ((bp->b_flag & BFTRUNC) != 0) ? '#' : ' ' ;
/* output status of changed flag ('*' when the buffer is changed) */
*cp1++ = ((bp->b_flag & BFCHG) != 0) ? '*' : ' ' ;
*cp1++ = ' '; /* space */
/* 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 is left-padded with space */
/* output status of changed flag ('*' when the buffer is changed) */
*cp1 = ((bp->b_flag & BFCHG) != 0) ? '*' : ' ' ;
/* 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( cp1, 10 + 1, nbytes) ; /* "%10d" formatted numbers */
cp1 += 10 ;
*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;
@@ -499,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;
@@ -521,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 */

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

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 */
@@ -109,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;
@@ -123,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
@@ -136,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]);
@@ -588,6 +588,8 @@ void updpos(void)
curcol += 2 ; /* displayed as ^c */
else if( c >= 0x80 && c <= 0xA0)
curcol += 3 ; /* displayed as \xx */
else if( c >= 0x3000 && c <= 0x3FFF)
curcol += 2 ; /* double width unicode character */
else
curcol += 1 ;
}
@@ -1284,7 +1286,7 @@ void mlerase( void) {
TTflush() ;
}
static void mlputc( char c) {
static void mlputc( unicode_t c) {
if( ttcol < term.t_ncol) {
TTputc( c) ;
++ttcol ;
@@ -1297,9 +1299,11 @@ static void mlputc( char c) {
* char *s; string to output
*/
void ostring( char *s) {
unsigned char c ;
if( discmd)
while( *s)
mlputc( *s++ & 0xFF) ;
while( (c = *s++) != 0)
mlputc( c) ;
}
@@ -1333,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;
@@ -1369,11 +1375,10 @@ void vmlwrite( const char *fmt, va_list ap) {
default:
mlputc( '%') ;
/* fallthrough */
case '%':
mlputc( c) ;
}
}
}
/* if we can, erase to the end of screen */
if( eolexist == TRUE && ttcol < term.t_ncol)
@@ -1516,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) ;
}
@@ -1551,7 +1556,7 @@ static int newscreensize(int h, int w)
*
* char c ; character to output
*/
void echoc( char c) {
void echoc( unicode_t c) {
if( disinp)
TTputc( c) ;
}

View File

@@ -4,6 +4,7 @@
#include <stdarg.h>
#include "estruct.h"
#include "utf8.h"
extern int mpresf ; /* Stuff in message line */
extern int scrollcount ; /* number of lines to scroll */
@@ -28,7 +29,7 @@ void mlerase( void) ;
void vmlwrite( const char *fmt, va_list ap) ;
void mlwrite( const char *fmt, ...) ;
void ostring( char *s) ;
void echoc( char c) ;
void echoc( unicode_t c) ;
void echos( char *s) ;
void getscreensize( int *widthp, int *heightp) ;

72
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}
,
@@ -307,7 +307,7 @@ struct key_tab keytab[NBINDS] = {
#endif
{META | 'U', upperword}
,
{META | 'V', backpage}
{META | 'V', (fn_t) backpage}
,
{META | 'W', copyregion}
,
@@ -323,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}
,
@@ -374,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}
,
@@ -390,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

80
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"
@@ -305,6 +306,8 @@ void varinit(void)
result = malloc( NSTRING) ;
ressize = NSTRING ;
}
seed = time( NULL) ;
}
/*
@@ -412,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) ;
@@ -423,6 +440,7 @@ static char *gtfun( char *fname) {
strncpy( result, arg1, sz) ;
result[ sz] = 0 ;
retstr = result ;
}
break ;
case UFRIGHT | DYNAMIC:
sz = atoi( arg2) ;
@@ -434,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) ;
@@ -686,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:
@@ -1317,19 +1361,19 @@ char *mklower(char *str)
/*
* returns a random integer
* ernd( 0) [ 0 .. 2147483647]
* ernd( i) [ 1 .. abs( i)]
* ernd( 1) [ 1]
* ernd( -2147483648) [ 1 .. 2147483647] actually 2147482413
* ernd( 0) [ 0 .. 2147483647]
* ernd( -2147483648) [ 0 .. 2147483647]
* ernd( 1) [ 1]
* ernd( i) [ 1 .. abs( i)]
*/
static int ernd( int i) {
seed = seed * 1721 + 10007 ;
seed &= ~(1 << 31) ; /* avoid abs() which introduces 176719 periodicity */
if( i == 0)
return seed ;
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 seed % i + 1 ;
return (i <= 0) ? s : s % i + 1 ;
}
/*

24
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 */
@@ -981,7 +983,7 @@ int execfile( int f, int n) {
while( status == TRUE && n-- > 0)
status = dofile( fspec) ;
return status ;
return status ;
}
/*

858
file.c

File diff suppressed because it is too large Load Diff

114
fileio.c
View File

@@ -118,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 */
@@ -180,26 +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 the string */
fline[i] = 0;
return FIOSUC;
return FIOSUC ;
}

View File

@@ -6,8 +6,7 @@ typedef enum {
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

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

View File

@@ -724,7 +724,7 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
for (n = 0; n < cpos; n++) {
c = buf[n];
if ((c < ' ') && (c != '\n')) {
echos("^");
echoc( '^') ;
++ttcol;
c ^= 0x40;
}
@@ -751,7 +751,7 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar)
buf[cpos++] = c;
if ((c < ' ') && (c != '\n')) {
echos("^");
echoc( '^') ;
++ttcol;
c ^= 0x40;
}

179
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>
@@ -28,8 +29,6 @@
int tabwidth = 8 ; /* column span of a tab */
#define BLOCK_SIZE 16 /* Line block chunk size. */
static int ldelnewline( void) ;
/* The editor holds deleted text chunks in the struct kill buffer. The
@@ -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;
@@ -397,22 +398,20 @@ int linsert( int n, unicode_t c) {
return rdonly(); /* we are in read only mode */
if( n > 0) {
char utf8[ 6] ;
int bytes, i ;
char utf8[ 4] ;
int bytes ;
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;
do {
int j ;
for (j = 0; j < bytes; j++) {
unsigned char c = utf8[j];
if (!linsert_byte(1, c))
return FALSE;
}
}
for( j = 0 ; j < bytes ; j += 1)
if( !linsert_byte( 1, (unsigned char) utf8[ j]))
return FALSE ;
} while( --n > 0) ;
}
return TRUE;
@@ -519,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) ;
}
/*
@@ -533,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))
@@ -552,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;
@@ -563,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. */
@@ -620,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)
@@ -646,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 tabwidth ;
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 */

19
main.c
View File

@@ -116,12 +116,11 @@ 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"
@@ -130,6 +129,7 @@ static void usage( void) {
" -v|V view file\n"
" -x|Xcmdfile\n"
" -x|X cmdfile execute command file\n"
" @cmdfile execute startup file\n"
, stdout) ;
}
@@ -297,12 +297,8 @@ int main(int argc, char **argv)
/* if invoked with no other startup files,
run the system startup file here */
if( startflag == FALSE) {
if( startup( "") != TRUE)
mloutstr( "Default startup failed!") ;
startflag = TRUE ;
}
if( (startflag == FALSE) && (startup( "") != TRUE))
mloutstr( "Default startup failed!") ;
discmd = TRUE; /* P.K. */
@@ -347,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

@@ -79,7 +79,7 @@ void ttopen( void) {
void ttclose( void) {
}
int ttputc( int c) {
int ttputc( unicode_t c) {
char utf8[ 6] ;
int bytes ;

26
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
@@ -206,7 +206,7 @@ struct name_bind names[] = {
{"select-buffer", usebuffer},
{"set", setvar},
{"set-fill-column", setfillcol},
{"set-mark", setmark},
{"set-mark", (fn_t) setmark},
{"shell-command", spawn},
{"shrink-window", shrinkwind},
{"split-current-window", splitwind},
@@ -217,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

@@ -33,6 +33,7 @@ int gethostname(char *name, int namelen)
}
#endif
char *cuserid( char *retbuf) ; /* should have been declared in stdio.h */
/**********************
@@ -84,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);
{

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;

194
random.c
View File

@@ -81,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 */
@@ -193,28 +181,28 @@ 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 += tabwidth - col % tabwidth ;
else if (c < 0x20 || c == 0x7F)
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 ;
}
@@ -222,7 +210,7 @@ int setccol(int pos)
/* 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);
@@ -331,22 +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, tabwidth - curwp->w_doto % tabwidth);
}
if( curwbyte() == '\t') {
int size ;
forwchar(FALSE, 1);
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 ;
}
/*
@@ -359,9 +362,6 @@ int entab(int f, int n)
#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 */
@@ -372,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 */
@@ -386,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;
@@ -410,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 ;
}
/*
@@ -432,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 */
@@ -446,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
@@ -671,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) ;
}
/*
@@ -691,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) ;
}
/*
@@ -968,7 +976,7 @@ int getfence(int f, int n)
/* if no eol */
if( curwp->w_doto != llength(curwp->w_dotp)) {
c = lgetc( curwp->w_dotp, curwp->w_doto) ;
c = curwbyte() ;
if( c == ch)
++count ;
else if( c == ofence)

View File

@@ -23,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

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 ;
}
/*

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) ;

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.2"
# 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 )