mirror of
https://github.com/rfivet/uemacs.git
synced 2025-11-23 11:41:15 -05:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dab92e74ff | |||
| 1ff2491d88 | |||
| b6c89d6eca | |||
| 57363dcb19 | |||
| 35f2184253 | |||
| 5d46ffc3dc | |||
| 5368877ebb | |||
| 6d40d82dea | |||
| b4ff6798cd | |||
| 674a3baba4 | |||
| df0d663b35 | |||
| 4873021e37 | |||
| 918a310601 | |||
| ba87641122 | |||
| 774475a4f6 | |||
| 18cd0ba37f | |||
| 9d864d8b00 | |||
| 99487b126f | |||
| 3ef30d1c23 | |||
| 7f8ab2d2a5 |
4
Makefile
4
Makefile
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
10
bind.c
10
bind.c
@@ -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
68
blindmaz.cmd
Normal 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
|
||||
@@ -20,11 +20,6 @@
|
||||
#define CTLX 0x04000000 /* ^X flag, or'ed in */
|
||||
#define SPEC 0x08000000 /* 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
|
||||
|
||||
#endif
|
||||
|
||||
/* end of defines.h */
|
||||
|
||||
20
display.c
20
display.c
@@ -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 ;
|
||||
}
|
||||
@@ -1519,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) ;
|
||||
}
|
||||
|
||||
@@ -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
80
eval.c
@@ -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
24
exec.c
@@ -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 ;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
6
file.c
6
file.c
@@ -283,8 +283,10 @@ int readin(const char *fname, boolean lockfl)
|
||||
return status ;
|
||||
|
||||
bp->b_flag &= ~(BFINVS | BFCHG);
|
||||
strncpy( bp->b_fname, fname, sizeof( fname_t) - 1) ;
|
||||
bp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
|
||||
if( fname != bp->b_fname) { /* Copy if source differs from destination */
|
||||
strncpy( bp->b_fname, fname, sizeof( fname_t) - 1) ;
|
||||
bp->b_fname[ sizeof( fname_t) - 1] = '\0' ;
|
||||
}
|
||||
|
||||
/* let a user macro get hold of things...if he wants */
|
||||
execute(META | SPEC | 'R', FALSE, 1);
|
||||
|
||||
63
floodmaz.cmd
Normal file
63
floodmaz.cmd
Normal 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 ¬ &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
|
||||
30
line.c
30
line.c
@@ -398,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;
|
||||
@@ -520,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) ;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
4
main.c
4
main.c
@@ -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) ;
|
||||
}
|
||||
|
||||
|
||||
99
maze.cmd
Normal file
99
maze.cmd
Normal 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 ¬ &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
|
||||
@@ -79,7 +79,7 @@ void ttopen( void) {
|
||||
void ttclose( void) {
|
||||
}
|
||||
|
||||
int ttputc( int c) {
|
||||
int ttputc( unicode_t c) {
|
||||
char utf8[ 6] ;
|
||||
int bytes ;
|
||||
|
||||
|
||||
12
pklock.c
12
pklock.c
@@ -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);
|
||||
{
|
||||
|
||||
31
random.c
31
random.c
@@ -86,20 +86,12 @@ int showcpos(int f, int n)
|
||||
numlines = 0;
|
||||
predchars = 0;
|
||||
predlines = 0;
|
||||
curchar = 0;
|
||||
bytes = 1 ;
|
||||
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;
|
||||
@@ -189,29 +181,28 @@ int getccol(int bflg)
|
||||
*
|
||||
* int pos; position to set cursor
|
||||
*/
|
||||
int setccol(int pos)
|
||||
{
|
||||
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) {
|
||||
int c; /* character being scanned */
|
||||
for( i = 0 ; i < llen && col < pos ; ) {
|
||||
unicode_t c ; /* character being scanned */
|
||||
|
||||
/* upon reaching the target, drop out */
|
||||
if (col >= pos)
|
||||
break;
|
||||
|
||||
/* 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 ;
|
||||
}
|
||||
|
||||
2
random.h
2
random.h
@@ -23,7 +23,7 @@ int setfillcol( int f, int n) ;
|
||||
int showcpos( int f, int n) ;
|
||||
int getcline( void) ;
|
||||
int getccol( int bflg) ;
|
||||
int setccol( int pos) ;
|
||||
boolean setccol( int pos) ;
|
||||
boolean twiddle( int f, int n) ;
|
||||
int quote( int f, int n) ;
|
||||
int insert_tab( int f, int n) ;
|
||||
|
||||
10
screensize.cmd
Normal file
10
screensize.cmd
Normal 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
|
||||
34
tcap.c
34
tcap.c
@@ -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)
|
||||
|
||||
11
terminal.h
11
terminal.h
@@ -6,6 +6,7 @@
|
||||
#include "retcode.h"
|
||||
#include "utf8.h"
|
||||
|
||||
|
||||
/*
|
||||
* The editor communicates with the display using a high level interface. A
|
||||
* "TERM" structure holds useful variables, and indirect pointers to routines
|
||||
@@ -16,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
termio.c
27
termio.c
@@ -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( unicode_t c) {
|
||||
#if VMS
|
||||
if (nobuf >= NOBUF)
|
||||
ttflush();
|
||||
obuf[nobuf++] = c;
|
||||
#endif
|
||||
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 ;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
29
utf8.c
29
utf8.c
@@ -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 ;
|
||||
|
||||
@@ -12,6 +12,6 @@
|
||||
# define PROGRAM_NAME_PFX "\xC2"
|
||||
# define PROGRAM_NAME_LONG "\xB5""EMACS" /* UTF-8 µEMACS */
|
||||
|
||||
# define VERSION "4.2.3"
|
||||
# define VERSION "4.2.4"
|
||||
|
||||
#endif /* VERSION_H_ */
|
||||
|
||||
2
window.c
2
window.c
@@ -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;
|
||||
|
||||
@@ -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 )
|
||||
|
||||
Reference in New Issue
Block a user