diff options
Diffstat (limited to 'urt')
-rw-r--r-- | urt/Runput.c | 343 | ||||
-rw-r--r-- | urt/Runput.h | 32 | ||||
-rw-r--r-- | urt/cmd_name.c | 3 | ||||
-rw-r--r-- | urt/rle.h | 8 | ||||
-rw-r--r-- | urt/rle_addhist.c | 153 | ||||
-rw-r--r-- | urt/rle_code.h | 23 | ||||
-rw-r--r-- | urt/rle_getcom.c | 2 | ||||
-rw-r--r-- | urt/rle_getrow.c | 337 | ||||
-rw-r--r-- | urt/rle_getskip.c | 3 | ||||
-rw-r--r-- | urt/rle_open_f.c | 3 | ||||
-rw-r--r-- | urt/rle_put.h | 8 | ||||
-rw-r--r-- | urt/rle_putcom.c | 107 | ||||
-rw-r--r-- | urt/rle_putrow.c | 9 | ||||
-rw-r--r-- | urt/rle_row_alc.c | 4 | ||||
-rw-r--r-- | urt/vaxshort.c | 30 | ||||
-rw-r--r-- | urt/vaxshort.h | 6 |
16 files changed, 615 insertions, 456 deletions
diff --git a/urt/Runput.c b/urt/Runput.c index 1a7f2f7b..d4281bb9 100644 --- a/urt/Runput.c +++ b/urt/Runput.c @@ -90,14 +90,18 @@ * follow the last byte in the run. */ -#include <string.h> -#include <stdio.h> +#include <assert.h> +#include <string.h> +#include <stdio.h> -#include "rle_put.h" -#include "rle.h" -#include "rle_code.h" -#include "vaxshort.h" -#include "Runput.h" +#include "mallocvar.h" +#include "pm.h" + +#include "rle_put.h" +#include "rle.h" +#include "rle_code.h" +#include "vaxshort.h" +#include "Runput.h" #define UPPER 255 /* anything bigger ain't a byte */ @@ -105,7 +109,7 @@ * Macros to make writing instructions with correct byte order easier. */ /* Write a two-byte value in little_endian order. */ -#define put16(a) (putc((a)&0xff,rle_fd),putc((char)(((a)>>8)&0xff),rle_fd)) +#define put16(a) (putc((a)&0xff,rle_fd),putc((char)(((a)>>8)&0xff),rle_fd)) /* short instructions */ #define mk_short_1(oper,a1) /* one argument short */ \ @@ -119,8 +123,8 @@ putc((char)(LONG|oper),rle_fd), putc('\0', rle_fd), put16(a1) #define mk_long_2(oper,a1,a2) /* two argument long */ \ - putc((char)(LONG|oper),rle_fd), putc('\0', rle_fd), \ - put16(a1), put16(a2) + putc((char)(LONG|oper),rle_fd), putc('\0', rle_fd), \ + put16(a1), put16(a2) /* choose between long and short format instructions */ /* NOTE: these macros can only be used where a STATEMENT is legal */ @@ -159,198 +163,245 @@ #define REOF mk_inst_1(REOFOp,0) /* Really opcode only */ -/***************************************************************** - * TAG( RunSetup ) - * Put out initial setup data for RLE files. - */ + void -RunSetup(rle_hdr * the_hdr) -{ +RunSetup(rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Put out initial setup data for RLE files. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + struct XtndRsetup setup; - FILE * rle_fd = the_hdr->rle_file; - put16( RLE_MAGIC ); + put16(RLE_MAGIC); - if ( the_hdr->background == 2 ) + if (hdrP->background == 2) setup.h_flags = H_CLEARFIRST; - else if ( the_hdr->background == 0 ) + else if (hdrP->background == 0) setup.h_flags = H_NO_BACKGROUND; else setup.h_flags = 0; - if ( the_hdr->alpha ) + + if (hdrP->alpha) setup.h_flags |= H_ALPHA; - if ( the_hdr->comments != NULL && *the_hdr->comments != NULL ) + + if (hdrP->comments != NULL && *hdrP->comments != NULL) setup.h_flags |= H_COMMENT; - setup.h_ncolors = the_hdr->ncolors; + if (hdrP->ncolors > 255) + pm_error("Too many colors (%u) for RLE format. Maximum is 255", + hdrP->ncolors); + + setup.h_ncolors = (unsigned char)hdrP->ncolors; setup.h_pixelbits = 8; /* Grinnell dependent */ - if ( the_hdr->ncmap > 0 && the_hdr->cmap == NULL ) - { - fprintf( stderr, - "%s: Color map of size %d*%d specified, but not supplied, writing %s\n", - the_hdr->cmd, the_hdr->ncmap, (1 << the_hdr->cmaplen), - the_hdr->file_name ); - the_hdr->ncmap = 0; + + if ((hdrP->cmaplen) > sizeof(UINT_MAX) * 8 - 1) { + pm_error("Color map size logarithm (%u) " + "is too large for computation. Maximum is %lu", + hdrP->cmaplen, sizeof(UINT_MAX) * 8 - 2); + } + /* We need to be able to count 2 bytes for each channel of each entry + in the color map: + */ + if (hdrP->ncmap > 0 && 1 << hdrP->cmaplen > UINT_MAX/2/hdrP->ncmap) { + pm_error("Color map length %u and number of color channels in the " + "color map %u are too large for computation", + 1 << hdrP->cmaplen, hdrP->ncmap); + } + + if (hdrP->ncmap > 255) + pm_error("Too many color channels in the color map (%u) " + "for the RLE format. Maximum is 255", hdrP->ncmap); + setup.h_ncmap = hdrP->ncmap; /* no of color channels */ + + if (hdrP->ncmap > 0 && hdrP->cmap == NULL) { + pm_message("Warning: " + "Color map of size %d*%d specified, but not supplied, " + "writing '%s'", + hdrP->ncmap, (1 << hdrP->cmaplen), hdrP->file_name); + hdrP->ncmap = 0; } - setup.h_cmaplen = the_hdr->cmaplen; /* log2 of color map size */ - setup.h_ncmap = the_hdr->ncmap; /* no of color channels */ - vax_pshort(setup.hc_xpos,the_hdr->xmin); - vax_pshort(setup.hc_ypos,the_hdr->ymin); - vax_pshort(setup.hc_xlen,the_hdr->xmax - the_hdr->xmin + 1); - vax_pshort(setup.hc_ylen,the_hdr->ymax - the_hdr->ymin + 1); + setup.h_cmaplen = (unsigned char)hdrP->cmaplen; + + vax_pshort(setup.hc_xpos,hdrP->xmin); + vax_pshort(setup.hc_ypos,hdrP->ymin); + vax_pshort(setup.hc_xlen,hdrP->xmax - hdrP->xmin + 1); + vax_pshort(setup.hc_ylen,hdrP->ymax - hdrP->ymin + 1); + fwrite((char *)&setup, SETUPSIZE, 1, rle_fd); - if ( the_hdr->background != 0 ) - { - int i; - rle_pixel *background = - (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) ); - int *bg_color; - /* - * If even number of bg color bytes, put out one more to get to - * 16 bit boundary. - */ - bg_color = the_hdr->bg_color; - for ( i = 0; i < the_hdr->ncolors; i++ ) + + if (hdrP->background != 0) { + unsigned int i; + rle_pixel * background; + int * bg_color; + + assert(hdrP->ncolors < UINT_MAX); + + MALLOCARRAY_NOFAIL(background, hdrP->ncolors + 1); + + /* If even number of bg color bytes, put out one more to get to + 16 bit boundary. + */ + + for (i = 0, bg_color = hdrP->bg_color; i < hdrP->ncolors; ++i) background[i] = *bg_color++; - /* Extra byte, if written, should be 0. */ + + /* Extra byte; if written, should be 0. */ background[i] = 0; - fwrite((char *)background, (the_hdr->ncolors / 2) * 2 + 1, 1, rle_fd); - free( background ); - } - else - putc( '\0', rle_fd ); - if (the_hdr->ncmap > 0) - { + + fwrite(background, (hdrP->ncolors / 2) * 2 + 1, 1, rle_fd); + + free(background); + } else + putc('\0', rle_fd); + + if (hdrP->ncmap > 0) { /* Big-endian machines are harder */ - int i, nmap = (1 << the_hdr->cmaplen) * - the_hdr->ncmap; - char *h_cmap = (char *)malloc( nmap * 2 ); - if ( h_cmap == NULL ) - { - fprintf( stderr, - "%s: Malloc failed for color map of size %d, writing %s\n", - the_hdr->cmd, nmap, the_hdr->file_name ); - exit( 1 ); + unsigned int const nmap = (1 << hdrP->cmaplen) * hdrP->ncmap; + + unsigned char * h_cmap; + unsigned int i; + + MALLOCARRAY(h_cmap, nmap * 2); + + if (!h_cmap) { + pm_error("Failed to allocate memory for color map of size %u, " + "writing '%s'", + nmap, hdrP->file_name); } - for ( i = 0; i < nmap; i++ ) - vax_pshort( &h_cmap[i*2], the_hdr->cmap[i] ); + for (i = 0; i < nmap; ++i) + vax_pshort(&h_cmap[i*2], hdrP->cmap[i]); + + fwrite(h_cmap, nmap, 2, rle_fd); - fwrite( h_cmap, nmap, 2, rle_fd ); - free( h_cmap ); + free(h_cmap); } /* Now write out comments if given */ - if ( setup.h_flags & H_COMMENT ) - { - int comlen; - CONST_DECL char ** com_p; + if (setup.h_flags & H_COMMENT) { + unsigned int comlen; + const char ** comP; /* Get the total length of comments */ - comlen = 0; - for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ ) - comlen += 1 + strlen( *com_p ); + for (comP = hdrP->comments, comlen = 0; *comP != NULL; ++comP) + comlen += 1 + strlen(*comP); - put16( comlen ); - for ( com_p = the_hdr->comments; *com_p != NULL; com_p++ ) - fwrite( *com_p, 1, strlen( *com_p ) + 1, rle_fd ); + put16(comlen); - if ( comlen & 1 ) /* if odd length, round up */ - putc( '\0', rle_fd ); + for (comP = hdrP->comments; *comP != NULL; ++comP) + fwrite(*comP, 1, strlen(*comP) + 1, rle_fd); + + if (comlen & 0x1) /* if odd length, round up */ + putc('\0', rle_fd); } } -/***************************************************************** - * TAG( RunSkipBlankLines ) - * Skip one or more blank lines in the RLE file. - */ + + void -RunSkipBlankLines(int nblank, rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; +RunSkipBlankLines(unsigned int const nblank, + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Skip one or more blank lines in the RLE file. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + RSkipLines(nblank); } -/***************************************************************** - * TAG( RunSetColor ) - * Select a color and do carriage return. - * color: 0 = Red, 1 = Green, 2 = Blue. - */ + + void -RunSetColor(int c, rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; +RunSetColor(int const c, + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Select a color and do carriage return. + color: 0 = Red, 1 = Green, 2 = Blue. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + RSetColor(c); } -/***************************************************************** - * TAG( RunSkipPixels ) - * Skip a run of background. - */ -/* ARGSUSED */ + void -RunSkipPixels(int nskip, int last, int wasrun, rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; - if (! last && nskip > 0) - { +RunSkipPixels(unsigned int const nskip, + int const last, + int const wasrun, + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Skip a run of background. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + + if (!last && nskip > 0) { RSkipPixels(nskip); } } -/***************************************************************** - * TAG( RunNewScanLine ) - * Perform a newline action. Since CR is implied by the Set Color - * operation, only generate code if the newline flag is true. - */ + + void -RunNewScanLine(int flag, rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; - if (flag) - { +RunNewScanLine(int const flag, + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Perform a newline action. Since CR is implied by the Set Color operation, + only generate code if the newline flag is true. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + + if (flag) { RNewLine; } } -/***************************************************************** - * TAG( Runputdata ) - * Put one or more pixels of byte data into the output file. - */ + + void -Runputdata(rle_pixel * buf, int n, rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; - if (n == 0) - return; - - RByteData(n-1); - fwrite((char *)buf, n, 1, rle_fd); - if ( n & 1 ) - putc( 0, rle_fd ); +Runputdata(rle_pixel * const buf, + unsigned int const n, + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Put one or more pixels of byte data into the output file. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + + if (n != 0) { + RByteData(n - 1); + + fwrite(buf, n, 1, rle_fd); + + if (n & 0x1) + putc(0, rle_fd); + } } -/***************************************************************** - * TAG( Runputrun ) - * Output a single color run. - */ -/* ARGSUSED */ + void -Runputrun(int color, int n, int last, rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; - RRunData(n-1,color); +Runputrun(int const color, + unsigned int const n, + int const last, + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Output a single color run. +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + + RRunData(n - 1, color); } -/***************************************************************** - * TAG( RunputEof ) - * Output an EOF opcode - */ + void -RunputEof(rle_hdr * the_hdr) -{ - FILE * rle_fd = the_hdr->rle_file; +RunputEof(rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Output an EOF opcode +-----------------------------------------------------------------------------*/ + FILE * const rle_fd = hdrP->rle_file; + REOF; } + + diff --git a/urt/Runput.h b/urt/Runput.h index 1d22a971..57a45564 100644 --- a/urt/Runput.h +++ b/urt/Runput.h @@ -1,23 +1,39 @@ +#ifndef RUNPUT_H_INCLUDED +#define RUNPUT_H_INCLUDED + void -RunSetup(rle_hdr * the_hdr); +RunSetup(rle_hdr * const hdrP); void -RunSkipBlankLines(int nblank, rle_hdr * the_hdr); +RunSkipBlankLines(unsigned int const nblank, + rle_hdr * const hdrP); void -RunSetColor(int c, rle_hdr * the_hdr); +RunSetColor(int const c, + rle_hdr * const hdrP); void -RunSkipPixels(int nskip, int last, int wasrun, rle_hdr * the_hdr); +RunSkipPixels(unsigned int const nskip, + int const last, + int const wasrun, + rle_hdr * const hdrP); void -RunNewScanLine(int flag, rle_hdr * the_hdr); +RunNewScanLine(int const flag, + rle_hdr * const hdrP); void -Runputdata(rle_pixel * buf, int n, rle_hdr * the_hdr); +Runputdata(rle_pixel * const buf, + unsigned int const n, + rle_hdr * const hdrP); void -Runputrun(int color, int n, int last, rle_hdr * the_hdr); +Runputrun(int const color, + unsigned int const n, + int const last, + rle_hdr * const hdrP); void -RunputEof(rle_hdr * the_hdr); +RunputEof(rle_hdr * const hdrP); + +#endif diff --git a/urt/cmd_name.c b/urt/cmd_name.c index 4b3f169b..6d48a63b 100644 --- a/urt/cmd_name.c +++ b/urt/cmd_name.c @@ -55,3 +55,6 @@ char **argv; return cp; } + + + diff --git a/urt/rle.h b/urt/rle.h index 1e7ddd0c..ee9eb379 100644 --- a/urt/rle.h +++ b/urt/rle.h @@ -80,7 +80,7 @@ typedef #endif struct rle_hdr { enum rle_dispatch dispatch; /* Type of file to create. */ - int ncolors; /* Number of color channels. */ + unsigned int ncolors; /* Number of color channels. */ int * bg_color; /* Pointer to bg color vector. */ int alpha; /* If !0, save alpha channel. */ int background; /* 0->just save all pixels, */ @@ -327,9 +327,9 @@ rle_open_f_noexit(const char * const prog_name, /* Append history information to the HISTORY comment. */ void -rle_addhist(char * argv[], - rle_hdr * const in_hdr, - rle_hdr * const out_hdr); +rle_addhist(const char ** const argv, + rle_hdr * const in_hdr, + rle_hdr * const out_hdr); /* From cmd_name.c. */ /***************************************************************** diff --git a/urt/rle_addhist.c b/urt/rle_addhist.c index 45c3dbfd..f319a40e 100644 --- a/urt/rle_addhist.c +++ b/urt/rle_addhist.c @@ -30,80 +30,119 @@ #include <time.h> #include "netpbm/mallocvar.h" + #include "rle.h" -/***************************************************************** - * TAG( rle_addhist ) - * - * Put a history comment into the header struct. - * Inputs: - * argv: Command line history to add to comments. - * in_hdr: Incoming header struct to use. - * Outputs: - * out_hdr: Outgoing header struct to add to. - * Assumptions: - * If no incoming struct then value is NULL. - * Algorithm: - * Calculate length of all comment strings, malloc and then set via - * rle_putcom. - */ -void -rle_addhist(char * argv[], - rle_hdr * const in_hdr, - rle_hdr * const out_hdr) { +static unsigned int +newCommentLen(const char * const histoire, + const char * const old, + const char ** const argv, + const char * const timedate, + const char * const padding) { - const char * const histoire = "HISTORY"; - const char * const padding = "\t"; + unsigned int length; + unsigned int i; - int length; - int i; - time_t temp; - /* padding must give number of characters in histoire */ - /* plus one for "=" */ - char * timedate; - const char * old; - static char * newc; + length = 0; /* initial value */ - if (getenv("NO_ADD_RLE_HISTORY")) - return; + /* Add length of each arg plus space. */ - length = 0; - for (i = 0; argv[i]; ++i) - length += strlen(argv[i]) +1; /* length of each arg plus space. */ + for (i = 0; argv[i]; ++i) { + size_t const thisArgLen = strlen(argv[i]); + if (thisArgLen < UINT_MAX - length - 100) { + length += thisArgLen; + length += 1; /* For the space */ + } + } - time(&temp); - timedate = ctime(&temp); - length += strlen(timedate); /* length of date and time in ASCII. */ + /* Add length of date and time in ASCII. */ + length += strlen(timedate); + /* Add length of padding, "on ", and length of history name plus "="*/ length += strlen(padding) + 3 + strlen(histoire) + 1; - /* length of padding, "on " and length of history name plus "="*/ - if (in_hdr) /* if we are interested in the old comments... */ - old = rle_getcom(histoire, in_hdr); /* get old comment. */ - else - old = NULL; if (old && *old) length += strlen(old); /* add length if there. */ - ++length; /*Cater for the null. */ + ++length; /* Add size of terminating NUL. */ - MALLOCARRAY(newc, length); + return length; +} - if (newc == NULL) - return; - strcpy(newc,histoire);(void)strcat(newc,"="); - if (old && *old) - strcat(newc, old); /* add old string if there. */ - for (i=0;argv[i];i++) { - strcat(newc, argv[i]); - strcat(newc, " "); - } - strcat(newc,"on "); - strcat(newc,timedate); /* \n supplied by time. */ - strcat(newc,padding); /* to line up multiple histories.*/ - rle_putcom(newc, out_hdr); +void +rle_addhist(const char ** const argv, + rle_hdr * const inHdrP, + rle_hdr * const outHdrP) { +/*---------------------------------------------------------------------------- + Put a history comment into the header struct. + Inputs: + argv: Command line history to add to comments. + *inHdrP: Incoming header struct to use. + Outputs: + *outHdrP: Outgoing header struct to add to. + Assumptions: + If no incoming struct then value is NULL. + Algorithm: + Calculate length of all comment strings, malloc and then set via + rle_putcom. + If we run out of memory, don't put the history comment in. +-----------------------------------------------------------------------------*/ + if (!getenv("NO_ADD_RLE_HISTORY")) { + const char * const histoire = "HISTORY"; + const char * const padding = "\t"; + + unsigned int length; + /* length of combined comment - the history comment we are adding + and any history comment that is already there (to which we + append) + */ + time_t nowTime; + /* padding must give number of characters in histoire */ + /* plus one for "=" */ + const char * timedate; + const char * old; + char * newc; + + if (inHdrP) /* if we are interested in the old comments... */ + old = rle_getcom(histoire, inHdrP); /* get old comment. */ + else + old = NULL; + + time(&nowTime); + timedate = ctime(&nowTime); + + length = newCommentLen(histoire, old, argv, timedate, padding); + + MALLOCARRAY(newc, length); + + if (newc) { + unsigned int i; + + strcpy(newc, histoire); + strcat(newc, "="); + + if (old) + strcat(newc, old); /* add old string if there. */ + + for (i = 0; argv[i]; ++i) { + strcat(newc, argv[i]); + strcat(newc, " "); + } + strcat(newc, "on "); + strcat(newc, timedate); /* \n supplied by 'ctime'. */ + strcat(newc, padding); /* to line up multiple histories.*/ + + rle_putcom(newc, outHdrP); + /* Creates reference to 'newc', may destroy reference to + previous comment memory, which will thereby leak. + */ + } + } } + + + diff --git a/urt/rle_code.h b/urt/rle_code.h index 493cdc02..525066d4 100644 --- a/urt/rle_code.h +++ b/urt/rle_code.h @@ -46,17 +46,18 @@ #define H_ALPHA 0x4 /* if set, alpha channel (-1) present */ #define H_COMMENT 0x8 /* if set, comments present */ -struct XtndRsetup -{ - char hc_xpos[2], - hc_ypos[2], - hc_xlen[2], - hc_ylen[2]; - char h_flags, - h_ncolors, - h_pixelbits, - h_ncmap, - h_cmaplen; +struct XtndRsetup { + /* This maps the layout of the header text in the file */ + + unsigned char hc_xpos[2]; + unsigned char hc_ypos[2]; + unsigned char hc_xlen[2]; + unsigned char hc_ylen[2]; + unsigned char h_flags; + unsigned char h_ncolors; + unsigned char h_pixelbits; + unsigned char h_ncmap; + unsigned char h_cmaplen; /* log2 of color map size */ }; #define SETUPSIZE ((4*2)+5) diff --git a/urt/rle_getcom.c b/urt/rle_getcom.c index a0a1e5ae..a85daa97 100644 --- a/urt/rle_getcom.c +++ b/urt/rle_getcom.c @@ -98,3 +98,5 @@ rle_getcom(const char * const name, return NULL; } + + diff --git a/urt/rle_getrow.c b/urt/rle_getrow.c index a24870ac..6a25c987 100644 --- a/urt/rle_getrow.c +++ b/urt/rle_getrow.c @@ -52,14 +52,74 @@ static int debug_f; /* If non-zero, print debug info. */ + + +static void +readComments(rle_hdr * const hdrP) { + + FILE * ifP = hdrP->rle_file; + + /* There are comments */ + short comlen; + char * cp; + + VAXSHORT(comlen, ifP); /* get comment length */ + + if (comlen < 0) + pm_error("Negative comment length in RLE header"); + else if (comlen > 0) { + unsigned int const evenlen = (comlen + 1) & ~1; /* make it even */ + + char * commentHeap; + unsigned int i; + + MALLOCARRAY(commentHeap, evenlen); + + if (commentHeap == NULL) { + pm_error("Malloc failed for comment buffer of size %u " + "in rle_get_setup, reading '%s'", + evenlen, hdrP->file_name ); + } + fread(commentHeap, 1, evenlen, ifP); + /* Count the comments */ + for (i = 0, cp = commentHeap; cp < commentHeap + comlen; ++cp) { + if (*cp == '\0') + ++i; + } + ++i; /* extra for NULL pointer at end */ + /* Get space to put pointers to comments */ + MALLOCARRAY(hdrP->comments, i); + if (hdrP->comments == NULL) { + pm_error("Malloc failed for %d comment pointers " + "in rle_get_setup, reading '%s'", + i, hdrP->file_name ); + } + /* Set comment heap */ + hdrP->comments[0] = commentHeap; + + /* Set pointers to individual comments in the heap as + hdrP->comments[1], hdrP->comments[2], etc. + */ + for (i = 1, cp = commentHeap + 1; + cp < commentHeap + comlen; + ++cp) + if (*(cp - 1) == '\0') + hdrP->comments[i++] = cp; + hdrP->comments[i] = NULL; + } else + hdrP->comments = NULL; +} + + + int -rle_get_setup(rle_hdr * const the_hdr) { +rle_get_setup(rle_hdr * const hdrP) { /*----------------------------------------------------------------------------- Read the initialization information from an RLE file. Inputs: - the_hdr: Contains pointer to the input file. + hdrP: Contains pointer to the input file. Outputs: - the_hdr: Initialized with information from the input file. + hdrP: Initialized with information from the input file. Returns 0 on success, -1 if the file is not an RLE file, @@ -67,151 +127,113 @@ rle_get_setup(rle_hdr * const the_hdr) { -3 if an immediate EOF is hit (empty input file) -4 if an EOF is encountered reading the setup information. Assumptions: - infile points to the "magic" number in an RLE file (usually byte 0 - in the file). + input file is positioned to the "magic" number in an RLE file (usually + first byte of the file). Algorithm: - Read in the setup info and fill in the_hdr. + Read in the setup info and fill in *hdrP. ---------------------------------------------------------------------------- */ struct XtndRsetup setup; short magic; - FILE * infile = the_hdr->rle_file; + FILE * ifP = hdrP->rle_file; int i; - char * comment_buf; /* Clear old stuff out of the header. */ - rle_hdr_clear(the_hdr); - if (the_hdr->is_init != RLE_INIT_MAGIC) - rle_names(the_hdr, "Urt", "some file", 0); - ++the_hdr->img_num; /* Count images. */ + rle_hdr_clear(hdrP); + if (hdrP->is_init != RLE_INIT_MAGIC) + rle_names(hdrP, "Urt", "some file", 0); + ++hdrP->img_num; /* Count images. */ - VAXSHORT(magic, infile); - if (feof(infile)) + VAXSHORT(magic, ifP); + if (feof(ifP)) return RLE_EMPTY; if (magic != RLE_MAGIC) return RLE_NOT_RLE; - fread(&setup, 1, SETUPSIZE, infile); /* assume VAX packing */ - if (feof( infile)) + fread(&setup, 1, SETUPSIZE, ifP); /* assume VAX packing */ + if (feof( ifP)) return RLE_EOF; /* Extract information from setup */ - the_hdr->ncolors = setup.h_ncolors; - for (i = 0; i < the_hdr->ncolors; ++i) - RLE_SET_BIT(*the_hdr, i); + hdrP->ncolors = setup.h_ncolors; + for (i = 0; i < hdrP->ncolors; ++i) + RLE_SET_BIT(*hdrP, i); if (!(setup.h_flags & H_NO_BACKGROUND) && setup.h_ncolors > 0) { rle_pixel * bg_color; - MALLOCARRAY(the_hdr->bg_color, setup.h_ncolors); - if (!the_hdr->bg_color) + MALLOCARRAY(hdrP->bg_color, setup.h_ncolors); + if (!hdrP->bg_color) pm_error("Failed to allocation array for %u background colors", setup.h_ncolors); MALLOCARRAY(bg_color, 1 + (setup.h_ncolors / 2) * 2); if (!bg_color) pm_error("Failed to allocation array for %u background colors", 1+(setup.h_ncolors / 2) * 2); - fread((char *)bg_color, 1, 1 + (setup.h_ncolors / 2) * 2, infile); + fread((char *)bg_color, 1, 1 + (setup.h_ncolors / 2) * 2, ifP); for (i = 0; i < setup.h_ncolors; ++i) - the_hdr->bg_color[i] = bg_color[i]; + hdrP->bg_color[i] = bg_color[i]; free(bg_color); } else { - getc(infile); /* skip filler byte */ - the_hdr->bg_color = NULL; + getc(ifP); /* skip filler byte */ + hdrP->bg_color = NULL; } if (setup.h_flags & H_NO_BACKGROUND) - the_hdr->background = 0; + hdrP->background = 0; else if (setup.h_flags & H_CLEARFIRST) - the_hdr->background = 2; + hdrP->background = 2; else - the_hdr->background = 1; + hdrP->background = 1; if (setup.h_flags & H_ALPHA) { - the_hdr->alpha = 1; - RLE_SET_BIT( *the_hdr, RLE_ALPHA ); + hdrP->alpha = 1; + RLE_SET_BIT( *hdrP, RLE_ALPHA ); } else - the_hdr->alpha = 0; + hdrP->alpha = 0; - the_hdr->xmin = vax_gshort(setup.hc_xpos); - the_hdr->ymin = vax_gshort(setup.hc_ypos); - the_hdr->xmax = the_hdr->xmin + vax_gshort(setup.hc_xlen) - 1; - the_hdr->ymax = the_hdr->ymin + vax_gshort(setup.hc_ylen) - 1; + hdrP->xmin = vax_gshort(setup.hc_xpos); + hdrP->ymin = vax_gshort(setup.hc_ypos); + hdrP->xmax = hdrP->xmin + vax_gshort(setup.hc_xlen) - 1; + hdrP->ymax = hdrP->ymin + vax_gshort(setup.hc_ylen) - 1; - the_hdr->ncmap = setup.h_ncmap; - the_hdr->cmaplen = setup.h_cmaplen; - if (the_hdr->ncmap > 0) { - int const maplen = the_hdr->ncmap * (1 << the_hdr->cmaplen); + hdrP->ncmap = setup.h_ncmap; + hdrP->cmaplen = setup.h_cmaplen; - int i; - char *maptemp; + if (hdrP->ncmap > 0) { + int const maplen = hdrP->ncmap * (1 << hdrP->cmaplen); - MALLOCARRAY(the_hdr->cmap, maplen); + unsigned int i; + unsigned char *maptemp; + + MALLOCARRAY(hdrP->cmap, maplen); MALLOCARRAY(maptemp, 2 * maplen); - if (the_hdr->cmap == NULL || maptemp == NULL) { + if (hdrP->cmap == NULL || maptemp == NULL) { pm_error("Malloc failed for color map of size %d*%d " "in rle_get_setup, reading '%s'", - the_hdr->ncmap, (1 << the_hdr->cmaplen), - the_hdr->file_name ); + hdrP->ncmap, (1 << hdrP->cmaplen), + hdrP->file_name ); return RLE_NO_SPACE; } - fread(maptemp, 2, maplen, infile); + fread(maptemp, 2, maplen, ifP); for (i = 0; i < maplen; ++i) - the_hdr->cmap[i] = vax_gshort(&maptemp[i * 2]); + hdrP->cmap[i] = vax_gshort(&maptemp[i * 2]); free(maptemp); } - /* Check for comments */ - if (setup.h_flags & H_COMMENT) { - short comlen, evenlen; - char * cp; - - VAXSHORT(comlen, infile); /* get comment length */ - evenlen = (comlen + 1) & ~1; /* make it even */ - if (evenlen) { - MALLOCARRAY(comment_buf, evenlen); - - if (comment_buf == NULL) { - pm_error("Malloc failed for comment buffer of size %d " - "in rle_get_setup, reading '%s'", - comlen, the_hdr->file_name ); - return RLE_NO_SPACE; - } - fread(comment_buf, 1, evenlen, infile); - /* Count the comments */ - for (i = 0, cp = comment_buf; cp < comment_buf + comlen; ++cp) - if (*cp == '\0') - ++i; - ++i; /* extra for NULL pointer at end */ - /* Get space to put pointers to comments */ - MALLOCARRAY(the_hdr->comments, i); - if (the_hdr->comments == NULL) { - pm_error("Malloc failed for %d comment pointers " - "in rle_get_setup, reading '%s'", - i, the_hdr->file_name ); - return RLE_NO_SPACE; - } - /* Get pointers to the comments */ - *the_hdr->comments = comment_buf; - for (i = 1, cp = comment_buf + 1; - cp < comment_buf + comlen; - ++cp) - if (*(cp - 1) == '\0') - the_hdr->comments[i++] = cp; - the_hdr->comments[i] = NULL; - } else - the_hdr->comments = NULL; - } else - the_hdr->comments = NULL; + if (setup.h_flags & H_COMMENT) + readComments(hdrP); + else + hdrP->comments = NULL; /* Initialize state for rle_getrow */ - the_hdr->priv.get.scan_y = the_hdr->ymin; - the_hdr->priv.get.vert_skip = 0; - the_hdr->priv.get.is_eof = 0; - the_hdr->priv.get.is_seek = ftell(infile) > 0; + hdrP->priv.get.scan_y = hdrP->ymin; + hdrP->priv.get.vert_skip = 0; + hdrP->priv.get.is_eof = 0; + hdrP->priv.get.is_seek = ftell(ifP) > 0; debug_f = 0; - if (!feof(infile)) + if (!feof(ifP)) return RLE_SUCCESS; /* success! */ else { - the_hdr->priv.get.is_eof = 1; + hdrP->priv.get.is_eof = 1; return RLE_EOF; } } @@ -219,24 +241,24 @@ rle_get_setup(rle_hdr * const the_hdr) { int -rle_getrow(rle_hdr * const the_hdr, +rle_getrow(rle_hdr * const hdrP, rle_pixel ** const scanline) { /*----------------------------------------------------------------------------- Get a scanline from the input file. Inputs: - the_hdr: Header structure containing information about + hdrP: Header structure containing information about the input file. Outputs: scanline: an array of pointers to the individual color scanlines. Scanline is assumed to have - the_hdr->ncolors pointers to arrays of rle_pixel, - each of which is at least the_hdr->xmax+1 long. + hdrP->ncolors pointers to arrays of rle_pixel, + each of which is at least hdrP->xmax+1 long. Returns the current scanline number. Assumptions: rle_get_setup has already been called. Algorithm: If a vertical skip is being executed, and clear-to-background is - specified (the_hdr->background is true), just set the + specified (hdrP->background is true), just set the scanlines to the background color. If clear-to-background is not set, just increment the scanline number and return. @@ -246,7 +268,7 @@ rle_getrow(rle_hdr * const the_hdr, If ymax is reached (or, somehow, passed), continue reading and discarding input until end of image. ---------------------------------------------------------------------------- */ - FILE * const infile = the_hdr->rle_file; + FILE * const ifP = hdrP->rle_file; rle_pixel * scanc; @@ -258,73 +280,73 @@ rle_getrow(rle_hdr * const the_hdr, short word, long_data; char inst[2]; - scan_x = the_hdr->xmin; /* initial value */ - max_x = the_hdr->xmax; /* initial value */ + scan_x = hdrP->xmin; /* initial value */ + max_x = hdrP->xmax; /* initial value */ channel = 0; /* initial value */ /* Clear to background if specified */ - if (the_hdr->background != 1) { - if (the_hdr->alpha && RLE_BIT( *the_hdr, -1)) - memset((char *)scanline[-1] + the_hdr->xmin, 0, - the_hdr->xmax - the_hdr->xmin + 1); - for (nc = 0; nc < the_hdr->ncolors; ++nc) { - if (RLE_BIT( *the_hdr, nc)) { + if (hdrP->background != 1) { + if (hdrP->alpha && RLE_BIT( *hdrP, -1)) + memset((char *)scanline[-1] + hdrP->xmin, 0, + hdrP->xmax - hdrP->xmin + 1); + for (nc = 0; nc < hdrP->ncolors; ++nc) { + if (RLE_BIT( *hdrP, nc)) { /* Unless bg color given explicitly, use 0. */ - if (the_hdr->background != 2 || the_hdr->bg_color[nc] == 0) - memset((char *)scanline[nc] + the_hdr->xmin, 0, - the_hdr->xmax - the_hdr->xmin + 1); + if (hdrP->background != 2 || hdrP->bg_color[nc] == 0) + memset((char *)scanline[nc] + hdrP->xmin, 0, + hdrP->xmax - hdrP->xmin + 1); else - memset((char *)scanline[nc] + the_hdr->xmin, - the_hdr->bg_color[nc], - the_hdr->xmax - the_hdr->xmin + 1); + memset((char *)scanline[nc] + hdrP->xmin, + hdrP->bg_color[nc], + hdrP->xmax - hdrP->xmin + 1); } } } /* If skipping, then just return */ - if (the_hdr->priv.get.vert_skip > 0) { - --the_hdr->priv.get.vert_skip; - ++the_hdr->priv.get.scan_y; - if (the_hdr->priv.get.vert_skip > 0) { - if (the_hdr->priv.get.scan_y >= the_hdr->ymax) { - int const y = the_hdr->priv.get.scan_y; - while (rle_getskip(the_hdr) != 32768) + if (hdrP->priv.get.vert_skip > 0) { + --hdrP->priv.get.vert_skip; + ++hdrP->priv.get.scan_y; + if (hdrP->priv.get.vert_skip > 0) { + if (hdrP->priv.get.scan_y >= hdrP->ymax) { + int const y = hdrP->priv.get.scan_y; + while (rle_getskip(hdrP) != 32768) ; return y; } else - return the_hdr->priv.get.scan_y; + return hdrP->priv.get.scan_y; } } /* If EOF has been encountered, return also */ - if (the_hdr->priv.get.is_eof) - return ++the_hdr->priv.get.scan_y; + if (hdrP->priv.get.is_eof) + return ++hdrP->priv.get.scan_y; /* Otherwise, read and interpret instructions until a skipLines instruction is encountered. */ - if (RLE_BIT(*the_hdr, channel)) + if (RLE_BIT(*hdrP, channel)) scanc = scanline[channel] + scan_x; else scanc = NULL; for (;;) { - inst[0] = getc(infile); - inst[1] = getc(infile); - if (feof(infile)) { - the_hdr->priv.get.is_eof = 1; + inst[0] = getc(ifP); + inst[1] = getc(ifP); + if (feof(ifP)) { + hdrP->priv.get.is_eof = 1; break; /* <--- one of the exits */ } switch(OPCODE(inst)) { case RSkipLinesOp: if (LONGP(inst)) { - VAXSHORT(the_hdr->priv.get.vert_skip, infile); + VAXSHORT(hdrP->priv.get.vert_skip, ifP); } else - the_hdr->priv.get.vert_skip = DATUM(inst); + hdrP->priv.get.vert_skip = DATUM(inst); if (debug_f) pm_message("Skip %d Lines (to %d)", - the_hdr->priv.get.vert_skip, - the_hdr->priv.get.scan_y + - the_hdr->priv.get.vert_skip); + hdrP->priv.get.vert_skip, + hdrP->priv.get.scan_y + + hdrP->priv.get.vert_skip); break; /* need to break for() here, too */ @@ -332,8 +354,8 @@ rle_getrow(rle_hdr * const the_hdr, channel = DATUM(inst); /* select color channel */ if (channel == 255) channel = -1; - scan_x = the_hdr->xmin; - if (RLE_BIT(*the_hdr, channel)) + scan_x = hdrP->xmin; + if (RLE_BIT(*hdrP, channel)) scanc = scanline[channel]+scan_x; if (debug_f) pm_message("Set color to %d (reset x to %d)", @@ -342,7 +364,7 @@ rle_getrow(rle_hdr * const the_hdr, case RSkipPixelsOp: if (LONGP(inst)) { - VAXSHORT(long_data, infile); + VAXSHORT(long_data, ifP); scan_x += long_data; scanc += long_data; if (debug_f) @@ -357,40 +379,40 @@ rle_getrow(rle_hdr * const the_hdr, case RByteDataOp: if (LONGP(inst)) { - VAXSHORT(nc, infile); + VAXSHORT(nc, ifP); } else nc = DATUM(inst); ++nc; if (debug_f) { - if (RLE_BIT(*the_hdr, channel)) + if (RLE_BIT(*hdrP, channel)) pm_message("Pixel data %d (to %d):", nc, scan_x + nc); else pm_message("Pixel data %d (to %d)", nc, scan_x + nc); } - if (RLE_BIT(*the_hdr, channel)) { + if (RLE_BIT(*hdrP, channel)) { /* Don't fill past end of scanline! */ if (scan_x + nc > max_x) { ns = scan_x + nc - max_x - 1; nc -= ns; } else ns = 0; - fread((char *)scanc, 1, nc, infile); + fread((char *)scanc, 1, nc, ifP); while (ns-- > 0) - getc(infile); + getc(ifP); if (nc & 0x1) - getc(infile); /* throw away odd byte */ + getc(ifP); /* throw away odd byte */ } else { - if (the_hdr->priv.get.is_seek) - fseek(infile, ((nc + 1) / 2) * 2, 1); + if (hdrP->priv.get.is_seek) + fseek(ifP, ((nc + 1) / 2) * 2, 1); else { int ii; for (ii = ((nc + 1) / 2) * 2; ii > 0; --ii) - getc(infile); /* discard it */ + getc(ifP); /* discard it */ } } scanc += nc; scan_x += nc; - if (debug_f && RLE_BIT(*the_hdr, channel)) { + if (debug_f && RLE_BIT(*hdrP, channel)) { rle_pixel * cp; for (cp = scanc - nc; nc > 0; --nc) fprintf(stderr, "%02x", *cp++); @@ -400,17 +422,17 @@ rle_getrow(rle_hdr * const the_hdr, case RRunDataOp: if (LONGP(inst)) { - VAXSHORT(nc, infile); + VAXSHORT(nc, ifP); } else nc = DATUM(inst); ++nc; scan_x += nc; - VAXSHORT(word, infile); + VAXSHORT(word, ifP); if (debug_f) pm_message("Run length %d (to %d), data %02x", nc, scan_x, word); - if (RLE_BIT(*the_hdr, channel)) { + if (RLE_BIT(*hdrP, channel)) { if (scan_x > max_x) { ns = scan_x - max_x - 1; nc -= ns; @@ -427,29 +449,28 @@ rle_getrow(rle_hdr * const the_hdr, break; case REOFOp: - the_hdr->priv.get.is_eof = 1; + hdrP->priv.get.is_eof = 1; if (debug_f) pm_message("End of Image"); break; default: pm_error("rle_getrow: Unrecognized opcode: %d, reading %s", - inst[0], the_hdr->file_name); + inst[0], hdrP->file_name); } if (OPCODE(inst) == RSkipLinesOp || OPCODE(inst) == REOFOp) break; /* <--- the other loop exit */ } /* If at end, skip the rest of a malformed image. */ - if (the_hdr->priv.get.scan_y >= the_hdr->ymax) { - int const y = the_hdr->priv.get.scan_y; - while (rle_getskip(the_hdr) != 32768 ) + if (hdrP->priv.get.scan_y >= hdrP->ymax) { + int const y = hdrP->priv.get.scan_y; + while (rle_getskip(hdrP) != 32768 ) ; return y; } - return the_hdr->priv.get.scan_y; + return hdrP->priv.get.scan_y; } - diff --git a/urt/rle_getskip.c b/urt/rle_getskip.c index 3d36fba4..2482f2bf 100644 --- a/urt/rle_getskip.c +++ b/urt/rle_getskip.c @@ -162,3 +162,6 @@ rle_hdr *the_hdr; else return the_hdr->priv.get.scan_y; } + + + diff --git a/urt/rle_open_f.c b/urt/rle_open_f.c index 65362a53..834a0c6d 100644 --- a/urt/rle_open_f.c +++ b/urt/rle_open_f.c @@ -226,7 +226,6 @@ dealWithSubprocess(const char * const file_name, - /* * Purpose : Open a file for input or output as controlled by the mode * parameter. If no file name is specified (ie. file_name is null) then @@ -322,3 +321,5 @@ rle_open_f(const char * prog_name, const char * file_name, const char * mode) return fp; } + + diff --git a/urt/rle_put.h b/urt/rle_put.h index bfabd617..015a15f3 100644 --- a/urt/rle_put.h +++ b/urt/rle_put.h @@ -52,13 +52,13 @@ typedef int rle_fn( ARB_ARGS ); struct rle_dispatch_tab { CONST_DECL char *magic; /* magic type flags */ void (*setup)(rle_hdr * the_hdr); /* startup function */ - void (*skipBlankLines)(int nblank, rle_hdr * the_hdr); + void (*skipBlankLines)(unsigned int nblank, rle_hdr * the_hdr); void(*setColor)(int c, rle_hdr * the_hdr); - void(*skipPixels)(int nskip, int last, int wasrun, rle_hdr * the_hdr); + void(*skipPixels)(unsigned int nskip, int last, int wasrun, rle_hdr * the_hdr); void(*newScanLine)(int flag, rle_hdr * the_hdr); - void(*putdat)(rle_pixel * buf, int n, rle_hdr * the_hdr); + void(*putdat)(rle_pixel * buf, unsigned int n, rle_hdr * the_hdr); /* put a set of differing pixels */ - void(*putrn)(int color, int n, int last, rle_hdr * the_hdr); + void(*putrn)(int color, unsigned int n, int last, rle_hdr * the_hdr); /* put a run all the same */ void (*blockHook)(rle_hdr * the_hdr); /* hook called at start of new output block */ diff --git a/urt/rle_putcom.c b/urt/rle_putcom.c index 0bebd8d7..ff27cb20 100644 --- a/urt/rle_putcom.c +++ b/urt/rle_putcom.c @@ -25,34 +25,35 @@ * Copyright (c) 1987, University of Utah */ +#include <limits.h> +#include <assert.h> #include <stdio.h> #include "netpbm/mallocvar.h" #include "netpbm/pm.h" #include "rle.h" -/***************************************************************** - * TAG( match ) - * - * Match a name against a test string for "name=value" or "name". - * If it matches name=value, return pointer to value part, if just - * name, return pointer to NUL at end of string. If no match, return NULL. - * - * Inputs: - * n: Name to match. May also be "name=value" to make it easier - * to replace comments. - * v: Test string. - * Outputs: - * Returns pointer as above. - * Assumptions: - * [None] - * Algorithm: - * [None] - */ + + static const char * match(const char * const nArg, const char * const vArg) { +/*---------------------------------------------------------------------------- + Match a name against a test string for "name=value" or "name". + If it matches name=value, return pointer to value part, if just + name, return pointer to NUL at end of string. If no match, return NULL. + Inputs: + n: Name to match. May also be "name=value" to make it easier + to replace comments. + v: Test string. + Outputs: + Returns pointer as above. + Assumptions: + [None] + Algorithm: + [None] +-----------------------------------------------------------------------------*/ const char * n; const char * v; @@ -70,57 +71,63 @@ match(const char * const nArg, -/***************************************************************** - * TAG( rle_putcom ) - * - * Put a comment into the header struct. - * Inputs: - * value: Value to add to comments. - * the_hdr: Header struct to add to. - * Outputs: - * the_hdr: Modified header struct. - * Returns previous value; - * Assumptions: - * value pointer can be used as is (data is NOT copied). - * Algorithm: - * Find match if any, else add at end (realloc to make bigger). - */ const char * rle_putcom(const char * const value, - rle_hdr * const the_hdr) { - - if ( the_hdr->comments == NULL) { - MALLOCARRAY_NOFAIL(the_hdr->comments, 2); - the_hdr->comments[0] = value; - the_hdr->comments[1] = NULL; + rle_hdr * const hdrP) { +/*---------------------------------------------------------------------------- + Put a comment into the header struct, replacing the existing one + that has the same key, if there is one. + Inputs: + value: Value to add to comments. + *hdrP: Header struct to add to. + Outputs: + *hdrP: Modified header struct. + Returns previous comment having the same key; NULL if none + Assumptions: + value pointer can be used as is (data is NOT copied). + Algorithm: + Find match if any, else add at end (realloc to make bigger). +-----------------------------------------------------------------------------*/ + if ( hdrP->comments == NULL) { + MALLOCARRAY_NOFAIL(hdrP->comments, 2); + hdrP->comments[0] = value; + hdrP->comments[1] = NULL; } else { const char ** cp; const char * v; - const char ** old_comments; - int i; - for (i = 2, cp = the_hdr->comments; *cp != NULL; ++i, ++cp) + const char ** oldComments; + unsigned int i; + + for (i = 2, cp = hdrP->comments; + *cp != NULL && i < UINT_MAX; + ++i, ++cp) { if (match(value, *cp) != NULL) { v = *cp; *cp = value; return v; } + } /* Not found */ /* Can't realloc because somebody else might be pointing to this * comments block. Of course, if this were true, then the * assignment above would change the comments for two headers. - * But at least, that won't crash the program. Realloc will. + * But at least that won't crash the program. Realloc will. * This would work a lot better in C++, where hdr1 = hdr2 * could copy the pointers, too. */ - old_comments = the_hdr->comments; - MALLOCARRAY(the_hdr->comments, i); - if (the_hdr->comments == NULL) + oldComments = hdrP->comments; + MALLOCARRAY(hdrP->comments, i); + if (hdrP->comments == NULL) pm_error("Unable to allocate memory for comments"); - the_hdr->comments[--i] = NULL; - the_hdr->comments[--i] = value; - for (--i; i >= 0; --i) - the_hdr->comments[i] = old_comments[i]; + assert(i >= 2); + hdrP->comments[--i] = NULL; + hdrP->comments[--i] = value; + for (; i > 0; --i) + hdrP->comments[i-1] = oldComments[i-1]; } return NULL; } + + + diff --git a/urt/rle_putrow.c b/urt/rle_putrow.c index 5f808c92..31a596c8 100644 --- a/urt/rle_putrow.c +++ b/urt/rle_putrow.c @@ -502,6 +502,7 @@ rle_hdr * the_hdr; } + /***************************************************************** * TAG( rle_put_init ) * @@ -540,6 +541,8 @@ rle_hdr *the_hdr; RLE_CLR_BIT( *the_hdr, -1 ); } + + /***************************************************************** * TAG( rle_put_setup ) * @@ -562,12 +565,16 @@ rle_hdr * the_hdr; Setup(); } + + void DefaultBlockHook(rle_hdr * the_hdr) { /* Do nothing */ } + + /***************************************************************** * TAG( rle_puteof ) * Write an EOF code into the output file. @@ -591,6 +598,8 @@ rle_hdr * the_hdr; the_hdr->dispatch = NO_DISPATCH; } + + #ifndef FASTRUNS /***************************************************************** * TAG( same_color ) diff --git a/urt/rle_row_alc.c b/urt/rle_row_alc.c index d7631744..4ed19880 100644 --- a/urt/rle_row_alc.c +++ b/urt/rle_row_alc.c @@ -97,6 +97,7 @@ rle_pixel ***scanp; } + /***************************************************************** * TAG( rle_row_free ) * @@ -129,3 +130,6 @@ rle_pixel **scanp; } free( (char *)scanp ); } + + + diff --git a/urt/vaxshort.c b/urt/vaxshort.c index c39e78ec..b9c8e1ce 100644 --- a/urt/vaxshort.c +++ b/urt/vaxshort.c @@ -27,26 +27,28 @@ * stored in VAX order, regardless of word alignment. */ int -vax_gshort(char *msgp) -{ - unsigned char *p = (unsigned char *) msgp; - int i; - - if( (i = (p[1] << 8) | p[0]) & 0x8000 ) - return(i | ~0xFFFF); /* Sign extend */ - return(i); +vax_gshort(unsigned char * const msgp) { + + int i; + + if ((i = (msgp[1] << 8) | msgp[0]) & 0x8000) + return i | ~0xFFFF; /* Sign extend */ + return(i); } + + /* * V A X _ P S H O R T */ -char * -vax_pshort(char *msgp, unsigned short s) -{ +unsigned char * +vax_pshort(unsigned char * const msgp, + unsigned short const s) { + + msgp[0] = s & 0xFF; + msgp[1] = s >> 8; - msgp[0] = s & 0xFF; - msgp[1] = s >> 8; - return(msgp+2); + return msgp + 2; } diff --git a/urt/vaxshort.h b/urt/vaxshort.h index daeb856b..7a1d14ae 100644 --- a/urt/vaxshort.h +++ b/urt/vaxshort.h @@ -1,5 +1,5 @@ int -vax_gshort(char *msgp); +vax_gshort(unsigned char *msgp); -char * -vax_pshort(char *msgp, unsigned short s); +unsigned char * +vax_pshort(unsigned char *msgp, unsigned short s); |