diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-04-27 06:57:24 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-04-27 06:57:24 +0300 |
commit | fd12f39ce43fe465dac987f078355c77d1dbbb07 (patch) | |
tree | b7f03e24961dd54d252857335374c2b1e4f97dc9 | |
parent | 05569802996888f857ead155631fd3bd9c680876 (diff) | |
download | videoteco-fork-fd12f39ce43fe465dac987f078355c77d1dbbb07.tar.gz |
the magic struct fields are omitted now unless DEBUG1 is defined
* The magic field is now always called __magic.
* Saves some memory, which is important especially on MS-DOS.
-rw-r--r-- | tecbuf.c | 18 | ||||
-rw-r--r-- | tecdebug.c | 38 | ||||
-rw-r--r-- | tecdisp.c | 12 | ||||
-rw-r--r-- | teco.h | 16 |
4 files changed, 48 insertions, 36 deletions
@@ -182,12 +182,12 @@ register int i = 0; if(bp == NULL) return(NULL); memset(bp,0,sizeof(*bp)); - bp->buf_magic = MAGIC_BUFFER; + MAGIC_UPDATE(bp, MAGIC_BUFFER); bp->buf_hash = stringHash( name ); bp->name = tec_alloc(TYPE_C_CBUFF,strlen(name)+1); if(bp->name == NULL){ - bp->buf_magic = 0; + MAGIC_UPDATE(bp, 0); tec_release(TYPE_C_BHDR,(char *)bp); return(NULL); }/* End IF */ @@ -213,7 +213,7 @@ register int i = 0; */ lbp = allocate_line_buffer(1); if(lbp == NULL){ - bp->buf_magic = 0; + MAGIC_UPDATE(bp, 0); tec_release(TYPE_C_CBUFF,bp->name); tec_release(TYPE_C_BHDR,(char *)bp); return((struct buff_header *)NULL); @@ -278,7 +278,7 @@ register struct buff_line *dlp; (void) strcpy(dbp->name,sbp->name); - dbp->buf_magic = MAGIC_BUFFER; + MAGIC_UPDATE(dbp, MAGIC_BUFFER); dbp->ismodified = sbp->ismodified; dbp->isreadonly = sbp->isreadonly; dbp->isbackedup = sbp->isbackedup; @@ -2449,7 +2449,7 @@ register struct buff_line *lbp; lbp->prev_line = NULL; lbp->format_line = NULL; lbp->byte_count = 0; - lbp->lin_magic = MAGIC_LINE; + MAGIC_UPDATE(lbp, MAGIC_LINE); return(lbp); }/* End IF */ }/* End IF */ @@ -2479,7 +2479,7 @@ register struct buff_line *lbp; return(NULL); }/* End IF */ - lbp->lin_magic = MAGIC_LINE; + MAGIC_UPDATE(lbp, MAGIC_LINE); return(lbp); }/* End Routine */ @@ -2506,10 +2506,10 @@ buff_free_line_buffer( struct buff_line *lbp ) * If this is a standard size line buffer, place it back on the lookaside list * rather than giving it back to tec_alloc. */ - lbp->lin_magic = 0; + MAGIC_UPDATE(lbp, 0); if(lbp->buffer_size == INITIAL_LINE_BUFFER_SIZE){ - lbp->lin_magic = MAGIC_LINE_LOOKASIDE; + MAGIC_UPDATE(lbp, MAGIC_LINE_LOOKASIDE); lbp->next_line = line_buffer_lookaside_list; line_buffer_lookaside_list = lbp; return; @@ -2554,7 +2554,7 @@ register struct buff_line *lbp; while((lbp = line_buffer_lookaside_list) != NULL){ line_buffer_lookaside_list = lbp->next_line; - lbp->lin_magic = 0; + MAGIC_UPDATE(lbp, 0); tec_release(TYPE_C_LINEBUF,lbp->buffer); tec_release(TYPE_C_LINE,(char *)lbp); }/* End While */ @@ -32,6 +32,8 @@ char *tecdebug_c_version = "tecdebug.c: $Revision: 1.2 $"; #include "teco.h" #include "tecparse.h" +#ifdef DEBUG1 + extern struct screen_line *saved_screen; extern char saved_screen_valid; extern int term_lines; @@ -79,13 +81,13 @@ register struct screen_line *sbp; */ if(saved_screen_valid){ for(sbp = saved_screen,i = 0; i < term_lines && sbp != NULL;i++,sbp++){ - if(sbp->scr_magic != MAGIC_SCREEN){ + if(sbp->__magic != MAGIC_SCREEN){ restore_tty(); fprintf( stderr, "?saved_screen[%d] bad magic#, 0x%08x should be 0x%08x\n", i, - sbp->scr_magic, + sbp->__magic, (int)MAGIC_SCREEN ); CAUSE_BUS_ERROR(); @@ -103,7 +105,7 @@ register struct screen_line *sbp; * the correct magic number. */ void -tecdebug_check_buffer_magic() +__magic() { register struct buff_header *bp; register char saw_curbuf; @@ -114,13 +116,13 @@ register int count; saw_curbuf = 0; while(bp){ if(bp == curbuf) saw_curbuf = 1; - if(bp->buf_magic != MAGIC_BUFFER){ + if(bp->__magic != MAGIC_BUFFER){ restore_tty(); fprintf( stderr, "?buff_headers[%d] bad magic#, 0x%08x should be 0x%08x\n", count, - bp->buf_magic, + bp->__magic, (int)MAGIC_BUFFER ); CAUSE_BUS_ERROR(); @@ -138,13 +140,13 @@ register int count; bp = qregister_push_down_list; count = 0; while(bp){ - if(bp->buf_magic != MAGIC_BUFFER){ + if(bp->__magic != MAGIC_BUFFER){ restore_tty(); fprintf( stderr, "?qpushdown[%d] bad magic#, 0x%08x should be 0x%08x\n", count, - bp->buf_magic, + bp->__magic, (int)MAGIC_BUFFER ); CAUSE_BUS_ERROR(); @@ -163,7 +165,7 @@ register int count; * the correct magic number. */ void -tecdebug_check_line_magic() +__magic() { register struct buff_header *bp; register struct buff_line *lbp; @@ -174,14 +176,14 @@ register int count; lbp = bp->first_line; count = 0; while(lbp){ - if(lbp->lin_magic != MAGIC_LINE){ + if(lbp->__magic != MAGIC_LINE){ restore_tty(); fprintf( stderr, "?buf[%s] line %d bad magic#, 0x%08x should be 0x%08x\n", bp->name, count, - lbp->lin_magic, + lbp->__magic, (int)MAGIC_LINE ); CAUSE_BUS_ERROR(); @@ -197,13 +199,13 @@ register int count; lbp = bp->first_line; count = 0; while(lbp){ - if(lbp->lin_magic != MAGIC_LINE){ + if(lbp->__magic != MAGIC_LINE){ restore_tty(); fprintf( stderr, "?qreg pdl line %d bad magic#, 0x%08x should be 0x%08x\n", count, - lbp->lin_magic, + lbp->__magic, (int)MAGIC_LINE ); CAUSE_BUS_ERROR(); @@ -224,19 +226,19 @@ register int count; * the correct magic number. */ void -tecdebug_check_format_magic() +__magic() { register struct format_line *fp; register int count; fp = format_line_alloc_list; while(fp){ - if(fp->fmt_magic != MAGIC_FORMAT){ + if(fp->__magic != MAGIC_FORMAT){ restore_tty(); fprintf( stderr, "?format line bad magic#, 0x%08x should be 0x%08x\n", - fp->fmt_magic, + fp->__magic, (int)MAGIC_FORMAT ); CAUSE_BUS_ERROR(); @@ -247,13 +249,13 @@ register int count; fp = format_line_free_list; count = 0; while(fp){ - if(fp->fmt_magic != MAGIC_FORMAT_LOOKASIDE){ + if(fp->__magic != MAGIC_FORMAT_LOOKASIDE){ restore_tty(); fprintf( stderr, "?format lookaside[%d] bad magic#, 0x%08x should be 0x%08x\n", count, - fp->fmt_magic, + fp->__magic, (int)MAGIC_FORMAT_LOOKASIDE ); CAUSE_BUS_ERROR(); @@ -375,3 +377,5 @@ char saw_our_format_line; }/* End FOR */ }/* End Routine */ + +#endif /* DEBUG1 */ @@ -173,7 +173,7 @@ register short *sp; screen_sequence = 1; for(lp = saved_screen, i = 0; i < term_lines; i++,lp++){ - lp->scr_magic = MAGIC_SCREEN; + MAGIC_UPDATE(lp, MAGIC_SCREEN); lp->companion = NULL; lp->sequence = 0; lp->buffer = (short *) @@ -231,13 +231,13 @@ register short *sp; message_line.fmt_permanent = 1; message_line.fmt_saved_line = lp; - message_line.fmt_magic = MAGIC_FORMAT_LOOKASIDE; + MAGIC_UPDATE(&magic_line, MAGIC_FORMAT_LOOKASIDE); lp->companion = &message_line; lp += 1; echo_line.fmt_permanent = 1; echo_line.fmt_saved_line = lp; - echo_line.fmt_magic = MAGIC_FORMAT_LOOKASIDE; + MAGIC_UPDATE(&echo_line, MAGIC_FORMAT_LOOKASIDE); lp->companion = &echo_line; screen_label_line(curbuf," TECO",LABEL_C_TECONAME); @@ -2033,7 +2033,7 @@ register struct format_line *next_win; /* * Take it off the head of the list and place it on the free list. */ - sbp->fmt_magic = MAGIC_FORMAT_LOOKASIDE; + MAGIC_UPDATE(sbp, MAGIC_FORMAT_LOOKASIDE); osbp = sbp; sbp = sbp->fmt_next_line; if(sbp == NULL) sbp = next_win; @@ -2109,7 +2109,7 @@ register struct format_line *sbp; while((sbp = format_line_free_list) != NULL){ format_line_free_list = sbp->fmt_next_line; - sbp->fmt_magic = 0; + MAGIC_UPDATE(sbp, 0); tec_release(TYPE_C_SCREENBUF,(char *)sbp->fmt_buffer); tec_release(TYPE_C_SCREEN,(char *)sbp); }/* End While */ @@ -2421,7 +2421,7 @@ struct buff_header *hbp = wptr->win_buffer; }/* End IF */ }/* End Else */ - sbp->fmt_magic = MAGIC_FORMAT; + MAGIC_UPDATE(sbp, MAGIC_FORMAT); sbp->fmt_owning_buffer = hbp; sbp->fmt_buffer_line = lbp; sbp->fmt_sequence = screen_sequence; @@ -410,6 +410,11 @@ void do_preamble_checks(void); void do_return_checks(void); +#define MAGIC_HEADER() \ + int __magic +#define MAGIC_UPDATE(X, VAL) \ + do (X)->__magic = (VAL); while (0) + #define PREAMBLE() \ do_preamble_checks(); @@ -421,6 +426,9 @@ void do_return_checks(void); do_return_checks(); \ return(val); #else +#define MAGIC_HEADER() +#define MAGIC_UPDATE(X, VAL) \ + do {} while (0) #define PREAMBLE() #define RETURN #define RETURN_VAL() @@ -453,7 +461,7 @@ void do_return_checks(void); } struct buff_header { - int buf_magic; + MAGIC_HEADER(); unsigned int buf_hash; char *name; int buffer_number; @@ -470,7 +478,7 @@ void do_return_checks(void); }; struct buff_line { - int lin_magic; + MAGIC_HEADER(); size_t buffer_size; size_t byte_count; char *buffer; @@ -480,7 +488,7 @@ void do_return_checks(void); }; struct format_line { - int fmt_magic; + MAGIC_HEADER(); struct buff_header *fmt_owning_buffer; struct buff_line *fmt_buffer_line; size_t fmt_buffer_size; @@ -500,7 +508,7 @@ void do_return_checks(void); }; struct screen_line { - int scr_magic; + MAGIC_HEADER(); short *buffer; struct format_line *companion; int sequence; |