mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-18 07:16:23 -05:00
Rework line allocation.
This commit is contained in:
parent
3e2d73394a
commit
135866231d
16
line.c
16
line.c
@ -28,8 +28,6 @@
|
|||||||
|
|
||||||
int tabwidth = 8 ; /* column span of a tab */
|
int tabwidth = 8 ; /* column span of a tab */
|
||||||
|
|
||||||
#define BLOCK_SIZE 16 /* Line block chunk size. */
|
|
||||||
|
|
||||||
static int ldelnewline( void) ;
|
static int ldelnewline( void) ;
|
||||||
|
|
||||||
/* The editor holds deleted text chunks in the struct kill buffer. The
|
/* The editor holds deleted text chunks in the struct kill buffer. The
|
||||||
@ -175,18 +173,18 @@ int forwchar(int f, int n)
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
struct line *lalloc(int used)
|
line_p lalloc( int used) {
|
||||||
{
|
#define BLOCK_SIZE 16 /* Line block chunk size. */
|
||||||
struct line *lp;
|
line_p lp ;
|
||||||
int size ;
|
int size ;
|
||||||
|
|
||||||
size = (used + BLOCK_SIZE - 1) & ~(BLOCK_SIZE - 1);
|
size = used + BLOCK_SIZE - used % BLOCK_SIZE ;
|
||||||
if (size == 0) /* Assume that is an empty. */
|
lp = (line_p) malloc( offsetof( struct line, l_text) + size) ;
|
||||||
size = BLOCK_SIZE; /* Line is for type-in. */
|
if( lp == NULL) {
|
||||||
if ((lp = (struct line *)malloc(sizeof(struct line) + size)) == NULL) {
|
|
||||||
mloutstr( "(OUT OF MEMORY)") ;
|
mloutstr( "(OUT OF MEMORY)") ;
|
||||||
return NULL ;
|
return NULL ;
|
||||||
}
|
}
|
||||||
|
|
||||||
lp->l_size = size ;
|
lp->l_size = size ;
|
||||||
lp->l_used = used ;
|
lp->l_used = used ;
|
||||||
return lp ;
|
return lp ;
|
||||||
|
24
line.h
24
line.h
@ -4,23 +4,21 @@
|
|||||||
#include "retcode.h"
|
#include "retcode.h"
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
|
|
||||||
#define NLINE 256 /* # of bytes, input line */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* All text is kept in circularly linked lists of "struct line" structures. These
|
* All text is kept in circularly linked lists of "struct line" structures.
|
||||||
* begin at the header line (which is the blank line beyond the end of the
|
* 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
|
* 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,
|
* 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
|
* 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.
|
* additions will include update hints, and a list of marks into the line.
|
||||||
*/
|
*/
|
||||||
struct line {
|
typedef struct line {
|
||||||
struct line *l_fp; /* Link to the next line */
|
struct line *l_fp ; /* Forward link to the next line */
|
||||||
struct line *l_bp; /* 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[1]; /* A bunch of characters. */
|
char l_text[ 1] ; /* A bunch of characters */
|
||||||
};
|
} *line_p ;
|
||||||
|
|
||||||
#define lforw(lp) ((lp)->l_fp)
|
#define lforw(lp) ((lp)->l_fp)
|
||||||
#define lback(lp) ((lp)->l_bp)
|
#define lback(lp) ((lp)->l_bp)
|
||||||
@ -28,14 +26,14 @@ struct line {
|
|||||||
#define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
|
#define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
|
||||||
#define llength(lp) ((lp)->l_used)
|
#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) ;
|
char *getkill( void) ;
|
||||||
|
|
||||||
int backchar( int f, int n) ;
|
int backchar( int f, int n) ;
|
||||||
int forwchar( int f, int n) ;
|
int forwchar( int f, int n) ;
|
||||||
|
|
||||||
void lfree( struct line *lp) ;
|
void lfree( line_p lp) ;
|
||||||
void lchange( int flag) ;
|
void lchange( int flag) ;
|
||||||
int insspace( int f, int n) ;
|
int insspace( int f, int n) ;
|
||||||
int linstr( char *instr) ;
|
int linstr( char *instr) ;
|
||||||
@ -49,7 +47,7 @@ char *getctext( void) ;
|
|||||||
void kdelete( void) ;
|
void kdelete( void) ;
|
||||||
int kinsert( int c) ;
|
int kinsert( int c) ;
|
||||||
int yank( int f, int n) ;
|
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 */
|
boolean rdonly( void) ; /* Read Only error message */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user