mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-18 07:16:23 -05:00
Compare commits
No commits in common. "699dac8b27af92ebdea63febd4de155b508abc6f" and "a370d748c4c88a9f1a47cf1ba6322f7fb697ccf8" have entirely different histories.
699dac8b27
...
a370d748c4
10
defines.h
10
defines.h
@ -40,17 +40,17 @@
|
||||
/* Dynamic RAM tracking and reporting redefinitions */
|
||||
#define RAMSIZE 0 /* dynamic RAM memory usage tracking */
|
||||
#if RAMSIZE
|
||||
# define RAMSHOW 1 /* auto dynamic RAM reporting */
|
||||
# include <stdlib.h> /* size_t */
|
||||
# define RAMSHOW 1 /* auto dynamic RAM reporting */
|
||||
# include <stdlib.h>
|
||||
void *allocate( size_t size) ;
|
||||
void release( void *ptr) ;
|
||||
|
||||
# define malloc( sz) allocate(sz)
|
||||
# define free( ptr) release( ptr)
|
||||
# define malloc allocate
|
||||
# define free release
|
||||
#endif
|
||||
|
||||
/* De-allocate memory always on exit (if the operating system or main
|
||||
program can not)
|
||||
program can not
|
||||
*/
|
||||
#define CLEAN 0 /* de-alloc memory on exit */
|
||||
#if CLEAN
|
||||
|
81
display.c
81
display.c
@ -16,8 +16,6 @@
|
||||
#include <errno.h>
|
||||
#include <locale.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -28,6 +26,7 @@
|
||||
#include "termio.h"
|
||||
#include "terminal.h"
|
||||
#include "version.h"
|
||||
#include "wrapper.h"
|
||||
#include "utf8.h"
|
||||
#include "window.h"
|
||||
|
||||
@ -102,51 +101,12 @@ static int newscreensize( int h, int w) ;
|
||||
#endif
|
||||
|
||||
|
||||
/* xmalloc is used at early initialization before memory usage tracking is
|
||||
enabled so it bypass the memory tracking macroes.
|
||||
*/
|
||||
static void *xmalloc( size_t size) {
|
||||
void *ret = (malloc)( size) ;
|
||||
if( !ret) {
|
||||
fprintf( stderr, "fatal: Out of memory\n") ;
|
||||
exit( EXIT_FAILURE) ;
|
||||
}
|
||||
|
||||
return ret ;
|
||||
}
|
||||
|
||||
/* Initialize the data structures used by the display code. The edge
|
||||
vectors used to access the screens are set up. The operating system's
|
||||
terminal I/O channel is set up. All the other things get initialized at
|
||||
compile time. The original window has "WFCHG" set, so that it will get
|
||||
completely redrawn on the first call to "update".
|
||||
*/
|
||||
|
||||
static int lastmrow ; /* remember mrow for later free */
|
||||
|
||||
static void vtalloc( int maxrow, int maxcol) {
|
||||
lastmrow = maxrow ; /* remember mrow for later free */
|
||||
vscreen = xmalloc( maxrow * sizeof( video_p )) ;
|
||||
|
||||
#if MEMMAP == 0 || SCROLLCODE
|
||||
pscreen = xmalloc( maxrow * sizeof( video_p )) ;
|
||||
#endif
|
||||
for( int i = 0 ; i < maxrow ; ++i) {
|
||||
video_p vp = xmalloc( sizeof *vp + maxcol * sizeof( unicode_t)) ;
|
||||
vp->v_flag = 0 ;
|
||||
#if COLOR
|
||||
vp->v_rfcolor = 7 ;
|
||||
vp->v_rbcolor = 0 ;
|
||||
#endif
|
||||
vscreen[ i] = vp ;
|
||||
#if MEMMAP == 0 || SCROLLCODE
|
||||
vp = xmalloc( sizeof *vp + maxcol * sizeof( unicode_t)) ;
|
||||
vp->v_flag = 0 ;
|
||||
pscreen[ i] = vp ;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void vtinit( void) {
|
||||
#ifdef SIGWINCH
|
||||
signal( SIGWINCH, sizesignal) ;
|
||||
@ -156,26 +116,43 @@ void vtinit( void) {
|
||||
TTopen() ; /* open the screen */
|
||||
TTkopen() ; /* open the keyboard */
|
||||
TTrev( FALSE) ;
|
||||
vtalloc( term.t_mrow, term.t_mcol) ;
|
||||
vscreen = xmalloc( term.t_maxrow * sizeof( video_p )) ;
|
||||
|
||||
#if MEMMAP == 0 || SCROLLCODE
|
||||
pscreen = xmalloc( term.t_maxrow * sizeof( video_p )) ;
|
||||
#endif
|
||||
for( int i = 0 ; i < term.t_maxrow ; ++i) {
|
||||
video_p vp = xmalloc( sizeof *vp + term.t_maxcol * sizeof( unicode_t)) ;
|
||||
vp->v_flag = 0 ;
|
||||
#if COLOR
|
||||
vp->v_rfcolor = 7 ;
|
||||
vp->v_rbcolor = 0 ;
|
||||
#endif
|
||||
vscreen[ i] = vp ;
|
||||
#if MEMMAP == 0 || SCROLLCODE
|
||||
vp = xmalloc( sizeof *vp + term.t_maxcol * sizeof( unicode_t)) ;
|
||||
vp->v_flag = 0 ;
|
||||
pscreen[ i] = vp ;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* free up all the dynamically video structures allocated by vtalloc */
|
||||
#if CLEAN
|
||||
/* free up all the dynamically allocated video structures */
|
||||
void vtfree( void) {
|
||||
/* as xmalloc bypass the malloc macro, we need bypass the free macro too */
|
||||
for( int i = 0 ; i < lastmrow ; ++i ) {
|
||||
(free)( vscreen[ i]) ;
|
||||
for( int i = 0 ; i < term.t_maxrow ; ++i ) {
|
||||
free( vscreen[ i]) ;
|
||||
#if MEMMAP == 0 || SCROLLCODE
|
||||
(free)( pscreen[ i]) ;
|
||||
free( pscreen[ i]) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
(free)( vscreen) ;
|
||||
free( vscreen) ;
|
||||
#if MEMMAP == 0 || SCROLLCODE
|
||||
(free)( pscreen) ;
|
||||
free( pscreen) ;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* Clean up the virtual terminal system, in anticipation for a return to
|
||||
@ -1462,8 +1439,6 @@ static int newscreensize( int h, int w) {
|
||||
}
|
||||
|
||||
chg_width = chg_height = 0 ;
|
||||
vtfree() ;
|
||||
vtalloc( h, w) ;
|
||||
if( h <= term.t_mrow)
|
||||
newsize( TRUE, h) ;
|
||||
|
||||
|
2
eval.c
2
eval.c
@ -65,7 +65,7 @@ int rval = 0 ; /* return value of a subprocess */
|
||||
static int saveflag = 0 ; /* Flags, saved with the $target var */
|
||||
|
||||
|
||||
unsigned envram = 0 ; /* # of bytes current in use by malloc */
|
||||
long envram = 0l ; /* # of bytes current in use by malloc */
|
||||
|
||||
|
||||
/* User variables ******************************************/
|
||||
|
2
eval.h
2
eval.h
@ -12,7 +12,7 @@
|
||||
extern int macbug ; /* macro debuging flag */
|
||||
extern int cmdstatus ; /* last command status */
|
||||
extern int rval ; /* return value of a subprocess */
|
||||
extern unsigned envram ; /* # of bytes current in use by malloc */
|
||||
extern long envram ; /* # of bytes current in use by malloc */
|
||||
|
||||
int readfirst_f( void) ;
|
||||
int is_it_cmd( char *token) ;
|
||||
|
1
exec.c
1
exec.c
@ -13,7 +13,6 @@
|
||||
|
||||
#include "buffer.h"
|
||||
#include "bind.h"
|
||||
#include "defines.h" /* malloc/allocate, free/release */
|
||||
#include "eval.h"
|
||||
#include "file.h"
|
||||
#include "flook.h"
|
||||
|
10
line.c
10
line.c
@ -37,18 +37,18 @@ static int ldelnewline( void) ;
|
||||
* was taken up by the keycode structure).
|
||||
*/
|
||||
|
||||
#define KBLOCK 248 /* sizeof kill buffer chunks */
|
||||
#define KBLOCK 250 /* sizeof kill buffer chunks */
|
||||
|
||||
typedef struct kill {
|
||||
struct kill *d_next ; /* Link to next chunk, NULL if last. */
|
||||
char d_chunk[ KBLOCK] ; /* Deleted text. */
|
||||
struct kill *d_next; /* Link to next chunk, NULL if last. */
|
||||
char d_chunk[KBLOCK]; /* Deleted text. */
|
||||
} *kill_p ;
|
||||
|
||||
static kill_p kbufp = NULL ; /* current kill buffer chunk pointer */
|
||||
static kill_p kbufh = NULL ; /* kill buffer header pointer */
|
||||
static int kused = KBLOCK ; /* # of bytes used in kill buffer */
|
||||
static int klen ; /* length of kill buffer content */
|
||||
static char *value = NULL ; /* temp buffer for value */
|
||||
static int klen ; /* length of kill buffer content */
|
||||
static char *value = NULL ; /* temp buffer for value */
|
||||
|
||||
/*
|
||||
* return some of the contents of the kill buffer
|
||||
|
93
main.c
93
main.c
@ -347,67 +347,80 @@ static void edinit( char *bname) {
|
||||
wp->w_flag = WFMODE | WFHARD; /* Full. */
|
||||
}
|
||||
|
||||
|
||||
/***** Compiler specific Library functions ****/
|
||||
|
||||
#if RAMSIZE
|
||||
#if RAMSIZE
|
||||
/* These routines will allow me to track memory usage by placing
|
||||
a layer on top of the standard system malloc() and free() calls.
|
||||
with this code defined, the environment variable, $RAM, will
|
||||
report on the number of bytes allocated via malloc.
|
||||
|
||||
/* These routines will allow me to track memory usage by placing a layer on
|
||||
top of the standard system malloc() and free() calls. with this code
|
||||
defined, the environment variable, $RAM, will report on the number of
|
||||
bytes allocated via malloc.
|
||||
|
||||
with SHOWRAM defined, the number is also posted on the end of the bottom
|
||||
mode line and is updated whenever it is changed.
|
||||
with SHOWRAM defined, the number is also posted on the
|
||||
end of the bottom mode line and is updated whenever it is changed.
|
||||
*/
|
||||
|
||||
#if RAMSHOW
|
||||
static void dspram( void) ;
|
||||
#endif
|
||||
static void dspram( void) ;
|
||||
|
||||
void *allocate( size_t nbytes) {
|
||||
nbytes += sizeof nbytes ; /* add overhead to track allocation */
|
||||
size_t *mp = (malloc)( nbytes) ; /* call the function not the macro */
|
||||
if( mp) {
|
||||
*mp++ = nbytes ;
|
||||
envram += nbytes ;
|
||||
#undef malloc
|
||||
#undef free
|
||||
#if 0
|
||||
char *allocate(nbytes)
|
||||
/* allocate nbytes and track */
|
||||
unsigned nbytes; /* # of bytes to allocate */
|
||||
#endif
|
||||
void *allocate( size_t nbytes)
|
||||
{
|
||||
char *mp; /* ptr returned from malloc */
|
||||
/* char *malloc(); */
|
||||
|
||||
mp = malloc(nbytes);
|
||||
if (mp) {
|
||||
envram += nbytes;
|
||||
#if RAMSHOW
|
||||
dspram() ;
|
||||
dspram();
|
||||
#endif
|
||||
}
|
||||
|
||||
return mp ;
|
||||
return mp;
|
||||
}
|
||||
|
||||
void release( void *mp) {
|
||||
if( mp) {
|
||||
size_t *sp = mp ;
|
||||
sp-- ;
|
||||
#if 0
|
||||
release(mp)
|
||||
/* release malloced memory and track */
|
||||
char *mp; /* chunk of RAM to release */
|
||||
#endif
|
||||
void release( void *mp)
|
||||
{
|
||||
unsigned *lp; /* ptr to the long containing the block size */
|
||||
|
||||
if (mp) {
|
||||
/* update amount of ram currently malloced */
|
||||
envram -= *sp ;
|
||||
(free)( sp) ; /* call the function not the macro */
|
||||
lp = ((unsigned *) mp) - 1;
|
||||
envram -= (long) *lp - 2;
|
||||
free(mp);
|
||||
#if RAMSHOW
|
||||
dspram() ;
|
||||
dspram();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if RAMSHOW
|
||||
static void dspram( void) { /* display the amount of RAM currently malloced */
|
||||
char mbuf[ 20] ;
|
||||
static void dspram( void)
|
||||
{ /* display the amount of RAM currently malloced */
|
||||
char mbuf[20];
|
||||
char *sp;
|
||||
|
||||
TTmove( term.t_nrow, term.t_ncol - 12) ;
|
||||
TTmove(term.t_nrow - 1, 70);
|
||||
#if COLOR
|
||||
TTforg( 7) ;
|
||||
TTbacg(0) ;
|
||||
TTforg(7);
|
||||
TTbacg(0);
|
||||
#endif
|
||||
sprintf( mbuf, "[%10u]", envram) ;
|
||||
char *sp = mbuf ;
|
||||
while( *sp)
|
||||
TTputc( *sp++) ;
|
||||
|
||||
TTmove( term.t_nrow, 0) ;
|
||||
movecursor( term.t_nrow, 0) ;
|
||||
sprintf(mbuf, "[%lu]", envram);
|
||||
sp = &mbuf[0];
|
||||
while (*sp)
|
||||
TTputc(*sp++);
|
||||
TTmove(term.t_nrow, 0);
|
||||
movecursor(term.t_nrow, 0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@ -448,7 +461,7 @@ void cexit( int status) {
|
||||
/* and the video buffers */
|
||||
vtfree() ;
|
||||
|
||||
(exit)( status) ; /* call the function, not the macro */
|
||||
(exit)( status) ;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
1
names.c
1
names.c
@ -16,7 +16,6 @@
|
||||
#include "bind.h"
|
||||
#include "bindable.h"
|
||||
#include "buffer.h"
|
||||
#include "defines.h" /* malloc/allocate */
|
||||
#include "display.h"
|
||||
#include "eval.h"
|
||||
#include "exec.h"
|
||||
|
8
window.c
8
window.c
@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h> /* malloc(), free() */
|
||||
|
||||
#include "basic.h"
|
||||
#include "buffer.h"
|
||||
@ -53,7 +52,7 @@ TBINDABLE( redraw) {
|
||||
|
||||
/* The command make the next window (next => down the screen) the current
|
||||
window. There are no real errors, although the command does nothing if
|
||||
there is only 1 window on the screen. Bound to "C-X O".
|
||||
there is only 1 window on the screen. Bound to "C-X C-N".
|
||||
|
||||
with an argument this command finds the <n>th window from the top
|
||||
|
||||
@ -319,10 +318,7 @@ BINDABLE( splitwind) {
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
wp = malloc( sizeof *wp) ;
|
||||
if( wp == NULL)
|
||||
return mloutfail( "Out of memory") ;
|
||||
|
||||
wp = xmalloc( sizeof *wp) ;
|
||||
++curbp->b_nwnd; /* Displayed twice. */
|
||||
wp->w_bufp = curbp;
|
||||
wp->w_dotp = curwp->w_dotp;
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* wrapper.c -- implements wrapper.h */
|
||||
|
||||
#include "wrapper.h"
|
||||
|
||||
#include <stdio.h>
|
||||
@ -25,4 +26,12 @@ void xmkstemp( char *template) {
|
||||
close( fd) ;
|
||||
}
|
||||
|
||||
void *xmalloc( size_t size) {
|
||||
void *ret = malloc( size) ;
|
||||
if( !ret)
|
||||
die( "Out of memory") ;
|
||||
|
||||
return ret ;
|
||||
}
|
||||
|
||||
/* end of wrapper.c */
|
||||
|
Loading…
Reference in New Issue
Block a user