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

Compare commits

..

No commits in common. "a370d748c4c88a9f1a47cf1ba6322f7fb697ccf8" and "ab34471d4d9291ad04265d0a03a295d3329dc83e" have entirely different histories.

5 changed files with 88 additions and 72 deletions

View File

@ -29,6 +29,7 @@
#define MSDOS 0 #define MSDOS 0
#define IBMPC MSDOS #define IBMPC MSDOS
#define COLOR MSDOS #define COLOR MSDOS
#define MEMMAP IBMPC
#define FILOCK (SVR4 | BSD) #define FILOCK (SVR4 | BSD)
@ -45,8 +46,8 @@
void *allocate( size_t size) ; void *allocate( size_t size) ;
void release( void *ptr) ; void release( void *ptr) ;
# define malloc allocate # define malloc allocate
# define free release # define free release
#endif #endif
/* De-allocate memory always on exit (if the operating system or main /* De-allocate memory always on exit (if the operating system or main

View File

@ -2,7 +2,6 @@
#include "display.h" #include "display.h"
#define REVSTA 1 /* Status line appears in reverse video */ #define REVSTA 1 /* Status line appears in reverse video */
#define MEMMAP 0
/* The functions in this file handle redisplay. There are two halves, the /* The functions in this file handle redisplay. There are two halves, the
ones that update the virtual display screen, and the ones that make the ones that update the virtual display screen, and the ones that make the
@ -12,7 +11,6 @@
Modified by Petri Kutvonen Modified by Petri Kutvonen
*/ */
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <locale.h> #include <locale.h>
#include <stdarg.h> #include <stdarg.h>
@ -205,9 +203,8 @@ static void sane_vtputc( unicode_t c) {
static void vtputc( unicode_t c) { static void vtputc( unicode_t c) {
/* In case somebody passes us a signed char.. */ /* In case somebody passes us a signed char.. */
// if( c > 0x10FFFF) /* Let's assume this is due to sign extension */ if( c > 0x10FFFF) /* Let's assume this is due to sign extension */
// c &= 0xFF ; c &= 0xFF ;
assert( c <= 0x10FFFF) ;
if( c == '\t') { if( c == '\t') {
sane_vtputc( viewtab ? 0xBB : ' ') ; /* 0xBB: '»' */ sane_vtputc( viewtab ? 0xBB : ' ') ; /* 0xBB: '»' */

128
line.c
View File

@ -172,8 +172,8 @@ BBINDABLE( forwchar) {
return TRUE ; return TRUE ;
} }
/*
/* This routine allocates a block of memory large enough to hold a struct line * This routine allocates a block of memory large enough to hold a struct line
* containing "used" characters. The block is always rounded up a bit. Return * containing "used" characters. The block is always rounded up a bit. Return
* a pointer to the new block, or NULL if there isn't any memory left. Print a * 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. * message in the message line if no space.
@ -181,13 +181,13 @@ BBINDABLE( forwchar) {
line_p lalloc( int used) { line_p lalloc( int used) {
#define BLOCK_SIZE 16 /* Line block chunk size. */ #define BLOCK_SIZE 16 /* Line block chunk size. */
/* rounding down use masking instead of modulo when BLOCK_SIZE is power of 2 */ /* rounding down use masking instead or modulo when BLOCK_SIZE is power of 2 */
#if (BLOCK_SIZE & -BLOCK_SIZE) == BLOCK_SIZE #if (BLOCK_SIZE & -BLOCK_SIZE) == BLOCK_SIZE
int size = (used + BLOCK_SIZE) & ~(BLOCK_SIZE - 1) ; int size = (used + BLOCK_SIZE) & ~(BLOCK_SIZE - 1) ;
#else #else
int size = used + BLOCK_SIZE - used % BLOCK_SIZE ; int size = used + BLOCK_SIZE - used % BLOCK_SIZE ;
#endif #endif
line_p lp = malloc( sizeof *lp + size) ; line_p lp = (line_p) malloc( offsetof( struct line, l_text) + size) ;
if( lp == NULL) if( lp == NULL)
mloutstr( "(OUT OF MEMORY)") ; mloutstr( "(OUT OF MEMORY)") ;
else { else {
@ -266,8 +266,8 @@ void lchange(int flag)
} }
} }
/*
/* insert spaces forward into text * insert spaces forward into text
* *
* int f, n; default flag and numeric argument * int f, n; default flag and numeric argument
*/ */
@ -278,18 +278,24 @@ BINDABLE( insspace) {
return TRUE ; return TRUE ;
} }
/*
* linstr -- Insert a string at the current point
*/
int linstr( char *instr) {
int status = TRUE ;
/* linstr -- Insert a string at the current point */
boolean linstr( char *instr) {
boolean status = TRUE ;
if( instr != NULL) { if( instr != NULL) {
int c ; unicode_t tmpc ;
while( (c = (unsigned char) *instr++)) { while( (tmpc = *instr++ & 0xFF)) {
status = (c == '\n') ? lnewline() : linsert_byte( 1, c) ; status =
if( status != TRUE) { /* Insertion error? */ (tmpc == '\n' ? lnewline() : (int) linsert_byte( 1, tmpc)) ;
/* Insertion error? */
if( status != TRUE) {
mloutstr( "%Out of memory while inserting") ; mloutstr( "%Out of memory while inserting") ;
break ; return status ;
} }
} }
} }
@ -387,7 +393,7 @@ boolean linsert_byte( int n, int c) {
return TRUE; return TRUE;
} }
boolean linsert( int n, unicode_t c) { int linsert( int n, unicode_t c) {
assert( n >= 0) ; assert( n >= 0) ;
assert( !(curbp->b_mode & MDVIEW)) ; assert( !(curbp->b_mode & MDVIEW)) ;
@ -415,7 +421,7 @@ boolean linsert( int n, unicode_t c) {
* *
* int c ; character to overwrite on current position * int c ; character to overwrite on current position
*/ */
static boolean lowrite( int c) { static int lowrite( int c) {
if( curwp->w_doto < curwp->w_dotp->l_used if( curwp->w_doto < curwp->w_dotp->l_used
&& ( lgetc( curwp->w_dotp, curwp->w_doto) != '\t' && ( lgetc( curwp->w_dotp, curwp->w_doto) != '\t'
|| (curwp->w_doto % tabwidth) == (tabwidth - 1) || (curwp->w_doto % tabwidth) == (tabwidth - 1)
@ -425,18 +431,20 @@ static boolean lowrite( int c) {
return linsert( 1, c) ; return linsert( 1, c) ;
} }
/*
* lover -- Overwrite a string at the current point
*/
int lover( char *ostr) {
int status = TRUE ;
/* lover -- Overwrite a string at the current point */
boolean lover( char *ostr) {
boolean status = TRUE ;
if( ostr != NULL) { if( ostr != NULL) {
int c ; char tmpc ;
while( (c = (unsigned char) *ostr++)) { while( (tmpc = *ostr++)) {
status = (c == '\n') ? lnewline() : lowrite( c) ; status = (tmpc == '\n' ? lnewline() : lowrite( tmpc)) ;
if( status != TRUE) { /* Insertion error? */ if( status != TRUE) { /* Insertion error? */
mloutstr( "%Out of memory while overwriting") ; mloutstr( "%Out of memory while overwriting") ;
break ; return status ;
} }
} }
} }
@ -444,15 +452,21 @@ boolean lover( char *ostr) {
return status ; return status ;
} }
/*
/* Insert a newline into the buffer at the current location of dot in the * Insert a newline into the buffer at the current location of dot in the
current window. The funny ass-backwards way it does things is not a * current window. The funny ass-backwards way it does things is not a botch;
botch; it just makes the last line in the file not a special case. * it just makes the last line in the file not a special case. Return TRUE if
Return TRUE if everything works out and FALSE on error (memory * everything works out and FALSE on error (memory allocation failure). The
allocation failure). The update of dot and mark is a bit easier then in * update of dot and mark is a bit easier then in the above case, because the
the above case, because the split forces more updating. * split forces more updating.
*/ */
boolean lnewline( void) { int lnewline( void) {
char *cp1;
char *cp2;
line_p lp1, lp2 ;
int doto;
struct window *wp;
assert( !(curbp->b_mode & MDVIEW)) ; assert( !(curbp->b_mode & MDVIEW)) ;
#if SCROLLCODE #if SCROLLCODE
@ -460,39 +474,43 @@ boolean lnewline( void) {
#else #else
lchange(WFHARD); lchange(WFHARD);
#endif #endif
line_p lp1 = curwp->w_dotp ; /* Get the address and */ lp1 = curwp->w_dotp; /* Get the address and */
int doto = curwp->w_doto ; /* offset of "." */ doto = curwp->w_doto; /* offset of "." */
line_p lp2 = lalloc( doto) ; /* New first half line */ lp2 = lalloc( doto) ; /* New first half line */
if( lp2 == NULL) if( lp2 == NULL)
return FALSE ; return FALSE ;
memcpy( lp2->l_text, lp1->l_text, doto) ; cp1 = &lp1->l_text[0]; /* Shuffle text around */
lp1->l_used -= doto ; cp2 = &lp2->l_text[0];
memcpy( lp1->l_text, &lp1->l_text[ doto], lp1->l_used) ; while (cp1 != &lp1->l_text[doto])
lp2->l_fp = lp1 ; *cp2++ = *cp1++;
lp2->l_bp = lp1->l_bp ; cp2 = &lp1->l_text[0];
lp1->l_bp = lp2 ; while (cp1 != &lp1->l_text[lp1->l_used])
lp2->l_bp->l_fp = lp2 ; *cp2++ = *cp1++;
for( window_p wp = wheadp ; wp != NULL ; wp = wp->w_wndp) { lp1->l_used -= doto;
if( wp->w_linep == lp1) lp2->l_bp = lp1->l_bp;
wp->w_linep = lp2 ; lp1->l_bp = lp2;
lp2->l_bp->l_fp = lp2;
if( wp->w_dotp == lp1) { lp2->l_fp = lp1;
if( wp->w_doto < doto) wp = wheadp; /* Windows */
wp->w_dotp = lp2 ; while (wp != NULL) {
if (wp->w_linep == lp1)
wp->w_linep = lp2;
if (wp->w_dotp == lp1) {
if (wp->w_doto < doto)
wp->w_dotp = lp2;
else else
wp->w_doto -= doto ; wp->w_doto -= doto;
} }
if (wp->w_markp == lp1) { if (wp->w_markp == lp1) {
if( wp->w_marko < doto) if (wp->w_marko < doto)
wp->w_markp = lp2 ; wp->w_markp = lp2;
else else
wp->w_marko -= doto ; wp->w_marko -= doto;
} }
wp = wp->w_wndp;
} }
return TRUE;
return TRUE ;
} }

18
line.h
View File

@ -14,11 +14,11 @@
list of marks into the line. list of marks into the line.
*/ */
typedef struct line { typedef struct line {
struct line *l_fp ; /* Forward link to the next line */ struct line *l_fp ; /* Forward link to the next line */
struct line *l_bp ; /* Backward link to the previous line */ struct line *l_bp ; /* Backward link to the previous line */
int l_size ; /* Allocated size */ int l_size ; /* Allocated size */
int l_used ; /* Used size */ int l_used ; /* Used size */
char l_text[] ; /* A bunch of characters */ char l_text[ 1] ; /* A bunch of characters */
} *line_p ; } *line_p ;
#define lforw(lp) ((lp)->l_fp) #define lforw(lp) ((lp)->l_fp)
@ -39,11 +39,11 @@ BBINDABLE( forwchar) ;
void lfree( line_p lp) ; void lfree( line_p lp) ;
void lchange( int flag) ; void lchange( int flag) ;
boolean linstr( char *instr) ; int linstr( char *instr) ;
boolean linsert( int n, unicode_t c) ; int linsert( int n, unicode_t c) ;
boolean linsert_byte( int n, int c) ; boolean linsert_byte( int n, int c) ;
boolean lover( char *ostr) ; int lover( char *ostr) ;
boolean lnewline( void) ; int lnewline( void) ;
boolean ldelete( long n, boolean kflag) ; boolean ldelete( long n, boolean kflag) ;
boolean ldelchar( long n, boolean kflag) ; boolean ldelchar( long n, boolean kflag) ;
int lgetchar( unicode_t *cref) ; int lgetchar( unicode_t *cref) ;

View File

@ -837,7 +837,7 @@ static int adjustmode( int kind, int global) {
} }
static int iovstring( int f, int n, const char *prompt, boolean (*fun)( char *)) { static int iovstring( int f, int n, const char *prompt, int (*fun)( char *)) {
char *tstring ; /* string to add */ char *tstring ; /* string to add */
/* ask for string to insert */ /* ask for string to insert */