diff options
Diffstat (limited to 'converter')
61 files changed, 758 insertions, 658 deletions
diff --git a/converter/other/bmptopnm.c b/converter/other/bmptopnm.c index eed428de..091d948a 100644 --- a/converter/other/bmptopnm.c +++ b/converter/other/bmptopnm.c @@ -140,9 +140,7 @@ parseCommandLine(int argc, const char ** argv, Note that the file spec array we return is stored in the storage that was passed to us as the argv array. -----------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to OptParseOptions2 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -156,7 +154,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 == 0) diff --git a/converter/other/fitstopnm.c b/converter/other/fitstopnm.c index ca621164..90bd16f1 100644 --- a/converter/other/fitstopnm.c +++ b/converter/other/fitstopnm.c @@ -88,8 +88,7 @@ parseCommandLine(int argc, const char ** argv, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. --------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int imageSpec; @@ -121,7 +120,7 @@ parseCommandLine(int argc, const char ** argv, /* Set some defaults the lazy way (using multiple setting of variables) */ - pm_optParseOptions3(&argc, (char**)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (imageSpec) { diff --git a/converter/other/giftopnm.c b/converter/other/giftopnm.c index c1c79e26..55d7ccc6 100644 --- a/converter/other/giftopnm.c +++ b/converter/other/giftopnm.c @@ -113,10 +113,7 @@ parseCommandLine(int argc, const char ** argv, Note that the file spec array we return is stored in the storage that was passed to us as the argv array. -----------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ - + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int alphaSpec, imageSpec; @@ -144,7 +141,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ free(option_def); diff --git a/converter/other/hdifftopam.c b/converter/other/hdifftopam.c index 7464bb1a..1b058a78 100644 --- a/converter/other/hdifftopam.c +++ b/converter/other/hdifftopam.c @@ -10,15 +10,16 @@ #include <stdio.h> #include "pm_c_util.h" -#include "pam.h" -#include "shhopt.h" +#include "mallocvar.h" #include "nstring.h" +#include "shhopt.h" +#include "pam.h" -struct cmdlineInfo { +struct CmdlineInfo { /* All the information the user supplied in the command line, in a form easy for the program to use. */ - const char *inputFilespec; /* Filespecs of input files */ + const char * inputFileNm; /* Names of input files */ unsigned int pnm; unsigned int verbose; }; @@ -26,19 +27,19 @@ struct cmdlineInfo { static void -parseCommandLine(int argc, char ** argv, - struct cmdlineInfo * const cmdlineP) { +parseCommandLine(int argc, const char ** const argv, + struct CmdlineInfo * const cmdlineP) { /*---------------------------------------------------------------------------- Note that the file spec array we return is stored in the storage that was passed to us as the argv array. -----------------------------------------------------------------------------*/ - optEntry *option_def = malloc( 100*sizeof( optEntry ) ); - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; + MALLOCARRAY_NOFAIL(option_def, 100); + option_def_index = 0; /* incremented by OPTENTRY */ OPTENT3(0, "pnm", OPT_FLAG, NULL, &cmdlineP->pnm, 0); OPTENT3(0, "verbose", OPT_FLAG, NULL, &cmdlineP->verbose, 0); @@ -47,13 +48,13 @@ parseCommandLine(int argc, char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 < 1) - cmdlineP->inputFilespec = "-"; + cmdlineP->inputFileNm = "-"; else if (argc-1 == 1) - cmdlineP->inputFilespec = argv[1]; + cmdlineP->inputFileNm = argv[1]; else pm_error("Too many arguments."); } @@ -88,20 +89,21 @@ static void int -main(int argc, char *argv[]) { - FILE *ifP; - struct cmdlineInfo cmdline; +main(int argc, const char ** argv) { + + FILE * ifP; + struct CmdlineInfo cmdline; struct pam diffpam, outpam; unsigned int row; tuple * diffrow; tuple * outrow; tuple * prevrow; - pnm_init(&argc, argv); + pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); - ifP = pm_openr(cmdline.inputFilespec); + ifP = pm_openr(cmdline.inputFileNm); pnm_readpaminit(ifP, &diffpam, PAM_STRUCT_SIZE(tuple_type)); diff --git a/converter/other/infotopam.c b/converter/other/infotopam.c index 3467891c..e9ce4d04 100644 --- a/converter/other/infotopam.c +++ b/converter/other/infotopam.c @@ -29,10 +29,10 @@ * * The icon data has the following format: * - * BIT-PLANE planes, each with HEIGHT rows of (WIDTH +15) / 16 * 2 bytes - * length. + * BIT-PLANE planes, each with HEIGHT rows WIDTH bits long, rounded up to + * a multiple of 2 bytes. * - * So if you have a 9x3x2 icon, the icon data will look like this: + * So if you have a 9x3x2 icon, the icon data looks like this: * * aaaa aaaa a000 0000 * aaaa aaaa a000 0000 @@ -45,9 +45,128 @@ * bit-plane, and '0' is padding. Thanks again to Ben Hutchings for his * very helpful post! * - * This program uses code from "sidplay" and an older "infotoxpm" program I - * wrote, both of which are released under GPL. + *----------------------------------------------------------------------------- + * The following specification for the DiskObject header is from + * http://amigadev.elowar.com/read/ADCD_2.1/Libraries_Manual_guide/node0241.html + * on 2024.03.14. * + * The DiskObject C structure is defined in the include file + * <workbench/workbench.h>. For a complete listing, see the Amiga ROM Kernel + * Reference Manual: Includes and Autodocs. The DiskObject structure contains + * the following elements: + * + * struct DiskObject { + * UWORD do_Magic; magic number at start of file + * UWORD do_Version; so we can change structure + * struct Gadget do_Gadget; a copy of in core gadget + * UBYTE do_Type; + * char *do_DefaultTool; + * char **do_ToolTypes; + * LONG do_CurrentX; + * LONG do_CurrentY; + * struct DrawerData *do_DrawerData; + * char *do_ToolWindow; applies only to tools + * LONG do_StackSize; applies only to tools + * }; + * + * do_Magic + * + * A magic number that the icon library looks for to make sure that the + * file it is reading really contains an icon. It should be the manifest + * constant WB_DISKMAGIC. PutDiskObject() will put this value in the + * structure, and GetDiskObject() will not believe that a file is really + * an icon unless this value is correct. + * + * do_Version + * + * This provides a way to enhance the .info file in an upwardly-compatible + * way. It should be WB_DISKVERSION. The icon library will set this value + * for you and will not believe weird values. + * + * do_Gadget + * + * This contains all the imagery for the icon. See the "Gadget Structure" + * section below for more details. + * + * do_Type + * + * The type of the icon; can be set to any of the following values. + * + * WBDISK The root of a disk + * WBDRAWER A directory on the disk + * WBTOOL An executable program + * WBPROJECT A data file + * WBGARBAGE The Trashcan directory + * WBKICK A Kickstart disk + * WBAPPICON Any object not directly associated with a filing system + * object, such as a print spooler (new in Release 2). + * + * do_DefaultTool + * + * Default tools are used for project and disk icons. For projects (data + * files), the default tool is the program Workbench runs when the project + * is activated. Any valid AmigaDOS path may be entered in this field + * such as "SYS:myprogram", "df0:mypaint", "myeditor" or ":work/mytool". + * + * For disk icons, the default tool is the diskcopy program + * ("SYS:System/DiskCopy") that will be used when this disk is the source + * of a copy. + * + * do_ToolTypes + * + * This is an array of free-format strings. Workbench does not enforce + * any rules on these strings, but they are useful for passing + * environment information. See the section on "The Tool Types Array" + * below for more information. + * + * do_CurrentX, do_CurrentY + * + * Drawers have a virtual coordinate system. The user can scroll around + * in this system using the scroll gadgets on the window that opens when + * the drawer is activated. Each icon in the drawer has a position in + * the coordinate system. CurrentX and CurrentY contain the icon's + * current position in the drawer. Picking a position for a newly + * created icon can be tricky. NO_ICON_POSITION is a system constant + * for do_CurrentX and do_CurrentY that instructs Workbench to pick a + * reasonable place for the icon. Workbench will place the icon in an + * unused region of the drawer. If there is no space in the drawers + * window, the icon will be placed just to the right of the visible + * region. + * + * do_DrawerData + * + * If the icon is associated with a directory (WBDISK, WBDRAWER, + * WBGARBAGE), it needs a DrawerData structure to go with it. This + * structure contains an Intuition NewWindow structure (see the + * "Intuition Windows" chapter for more information): + * + * struct DrawerData { + * struct NewWindow dd_NewWindow; structure to open window + * LONG dd_CurrentX; current x coordinate of origin + * LONG dd_CurrentY; current y coordinate of origin + * }; + * + * Workbench uses this to hold the current window position and size of + * the window so it will reopen in the same place. + * + * do_ToolWindow + * + * This field is reserved for future use. + * + * do_StackSize + * + * This is the size of the stack (in bytes) used for running the tool. + * If this is NULL, then Workbench will use a reasonable default stack + * size (currently 4K bytes). + * + * When a tool is run via the default tool mechanism (i.e., a project + * was activated, not the tool itself), Workbench uses the stack size + * specified in the project's .info file and the tool's .info file is + * ignored. + * + *------------------------------------------------------------------------- + * This program uses code from "sidplay" and an older "infotoxpm" program + * Richard Griswold wrote, both of which are offered under GPL. *------------------------------------------------------------------------- * * This program is free software; you can redistribute it and/or @@ -65,42 +184,51 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "pm_c_util.h" -#include "pam.h" -#include "shhopt.h" -#include "mallocvar.h" - -#include <errno.h> -#include <stdio.h> +#include <stdbool.h> #include <stdlib.h> #include <string.h> +#include <errno.h> +#include <stdio.h> +#include "pm_c_util.h" +#include "mallocvar.h" +#include "nstring.h" +#include "shhopt.h" +#include "pam.h" -/* Struct to hold miscellaneous icon information */ -typedef struct IconInfo_ { - const char *name; /* Icon file name */ - FILE *fp; /* Input file pointer */ - bool forceColor; /* Convert 1 bitplane icon to color icon */ - unsigned int numColors; /* Number of colors to override */ - bool selected; /* Converting selected (second) icon */ +typedef struct CmdlineInfo_ { + const char * inputFileNm; + unsigned int forcecolor; + pixel colors[4]; /* Colors to use for converted icons */ + unsigned int selected; + unsigned int verbose; +} CmdlineInfo; - bool drawerData; /* Icon has drawer data */ - unsigned int version; /* Icon version */ - unsigned int width; /* Width in pixels */ - unsigned int height; /* Height in pixels */ - unsigned int depth; /* Bits of color per pixel */ - pixel colors[4]; /* Colors to use for converted icons */ - unsigned char *icon; /* Completed icon */ +typedef struct IconInfo_ { + /* Miscellaneous icon information */ + FILE * ifP; /* Input file */ + bool hasDrawerData; /* Icon has drawer data */ + unsigned int version; /* Icon version */ + unsigned int width; /* Width in pixels */ + unsigned int height; /* Height in pixels */ + unsigned int depth; /* Bits of color per pixel */ + unsigned int bpwidth; + /* Bitplane width; Width of each row in icon, including padding */ + unsigned char * icon; /* Completed icon */ } IconInfo; -/* Header for each icon image */ typedef struct IconHeader_ { /* 20 bytes */ - unsigned char pad0[4]; /* Padding (always seems to be zero) */ + /* Text of header for one icon image */ + unsigned char type[4]; + /* Reverse engineered. This always seems to be 0x00000000 in + icon headers, but we've seen 0x00000010 in some 51-byte object + we don't understand. + */ unsigned char iconWidth[2]; /* Width (usually equal to Gadget width) */ unsigned char iconHeight[2]; - /* Height (usually equal to Gadget height -1) */ + /* Height (usually equal to Gadget height -1) */ unsigned char bpp[2]; /* Bits per pixel */ unsigned char pad1[10]; /* ??? */ } IconHeader; @@ -110,6 +238,7 @@ typedef struct IconHeader_ { /* 20 bytes */ * http://www.geocities.com/SiliconValley/Lakes/5147/sidplay/linux.html */ typedef struct DiskObject_ { /* 78 bytes (including Gadget struct) */ + /* Text of Info Disk Object header */ unsigned char magic[2]; /* Magic number at the start of the file */ unsigned char version[2]; /* Object version number */ unsigned char gadget[44]; /* Copy of in memory gadget (44 by */ @@ -127,139 +256,140 @@ typedef struct DiskObject_ { /* 78 bytes (including Gadget struct) */ static void -parseCommandLine( int argc, - char * argv[], - IconInfo * const infoP ) { - - unsigned int numColorArgs, /* Number of arguments for overriding colors */ - colorIdx, /* Color index */ - i; /* Argument index */ - const char * const colors[4] = { - /* Pixel colors based on original Amiga colors */ - "#0055AA", /* Blue 0, 85, 170 */ - "#FFFFFF", /* White 255, 255, 255 */ - "#000020", /* Black 0, 0, 32 */ - "#FF8A00" /* Orange 255, 138, 0 */ - }; - - /* Option entry variables */ - optEntry *option_def; - optStruct3 opt; - unsigned int option_def_index; - unsigned int numColorsSpec, forceColorSpec, selectedSpec; +parseCommandLine(int argc, + const char ** argv, + CmdlineInfo * const cmdlineP) { + + unsigned int argIdx; + optEntry * option_def; + optStruct3 opt; + unsigned int option_def_index; + unsigned int numcolorsSpec; + unsigned int numcolors; MALLOCARRAY_NOFAIL(option_def, 100); /* Set command line options */ option_def_index = 0; /* Incremented by OPTENT3 */ - OPTENT3(0, "forcecolor", OPT_FLAG, NULL, &forceColorSpec, 0); - OPTENT3(0, "numcolors", OPT_UINT, &infoP->numColors, &numColorsSpec, 0); - OPTENT3(0, "selected", OPT_FLAG, NULL, &selectedSpec, 0); - - /* Initialize the iconInfo struct */ - infoP->name = NULL; - infoP->fp = NULL; - infoP->drawerData = FALSE; - infoP->version = 0; - infoP->width = 0; - infoP->height = 0; - infoP->depth = 0; - infoP->icon = NULL; - for ( colorIdx = 0; colorIdx < 4; colorIdx++ ) - infoP->colors[colorIdx] = - ppm_parsecolor( (char*) colors[colorIdx], 0xFF ); - - /* Initialize option structure */ + OPTENT3(0, "forcecolor", OPT_FLAG, NULL, &cmdlineP->forcecolor, + 0); + OPTENT3(0, "numcolors", OPT_UINT, &numcolors, &numcolorsSpec, + 0); + OPTENT3(0, "selected", OPT_FLAG, NULL, &cmdlineP->selected, + 0); + OPTENT3(0, "verbose", OPT_FLAG, NULL, &cmdlineP->verbose, + 0); + opt.opt_table = option_def; - opt.short_allowed = FALSE; /* No short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* No negative number parameters */ - - /* Parse the command line */ - pm_optParseOptions3( &argc, argv, opt, sizeof( opt ), 0 ); - - infoP->forceColor = forceColorSpec; - infoP->selected = selectedSpec; - if (!numColorsSpec) - infoP->numColors = 0; - - /* Get colors and file name */ - numColorArgs = infoP->numColors * 2; - if ( ( argc - 1 != numColorArgs ) && ( argc - 1 != numColorArgs + 1 ) ) { - pm_error( "Wrong number of arguments for number of colors. " - "For %u colors, you need %u color arguments, " - "with possibly one more argument for the input file name.", - infoP->numColors, numColorArgs ); - } + opt.short_allowed = false; /* No short (old-fashioned) options */ + opt.allowNegNum = false; /* No negative number parameters */ + + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); + + { + const char * const colors[4] = { + /* Pixel colors based on original Amiga colors */ + "#0055AA", /* Blue 0, 85, 170 */ + "#FFFFFF", /* White 255, 255, 255 */ + "#000020", /* Black 0, 0, 32 */ + "#FF8A00" /* Orange 255, 138, 0 */ + }; + + unsigned int colorArgCt; + /* Number of arguments for overriding colors */ - /* Convert color arguments */ - for ( i = 1; i < numColorArgs; i += 2 ) { - char * endptr; /* End pointer for strtol() */ unsigned int colorIdx; - /* Get color index from argument */ - colorIdx = strtoul( argv[i], &endptr, 0 ); + if (numcolorsSpec) { + colorArgCt = numcolors * 2; + if (argc-1 < colorArgCt) { + pm_error("Insufficient arguments for %u color " + "specifications. Need at least %u arguments", + numcolors, colorArgCt); + } + } else + colorArgCt = 0; - if ( *endptr != '\0' ) { - pm_error( "'%s' is not a valid color index", argv[i] ); - } + /* Initialize palette to defaults */ + for (colorIdx = 0; colorIdx < 4; ++colorIdx) + cmdlineP->colors[colorIdx] = + ppm_parsecolor(colors[colorIdx], 0xFF); - /* Check color index range (current 0 to 3) */ - if ( ( colorIdx < 0 ) || ( colorIdx > 3 ) ) { - pm_error( "%u is not a valid color index (minimum 0, maximum 3)", - colorIdx ); - } + /* Convert color arguments */ + for (argIdx = 1; argIdx < colorArgCt; argIdx += 2) { + char * endptr; /* End pointer for strtol() */ + unsigned int colorIdx; + + /* Get color index from argument */ + colorIdx = strtoul(argv[argIdx], &endptr, 0); + + if (*endptr != '\0') { + pm_error("'%s' is not a valid color index", argv[argIdx]); + } + + if ((colorIdx < 0) || (colorIdx > 3)) { + pm_error( + "%u is not a valid color index (minimum 0, maximum 3)", + colorIdx); + } - /* Convert the color for this color index */ - infoP->colors[colorIdx] = ppm_parsecolor( argv[i+1], 0xFF ); + cmdlineP->colors[colorIdx] = ppm_parsecolor(argv[argIdx+1], 0xFF); + } } - /* Set file name */ - if ( i > argc-1 ) - infoP->name = "-"; /* Read from standard input */ + if (argIdx > argc-1) + cmdlineP->inputFileNm = "-"; /* Read from standard input */ else - infoP->name = argv[i]; + cmdlineP->inputFileNm = argv[argIdx]; } static void -getDiskObject( IconInfo * const infoP ) { -/*------------------------------------------------------------------------- - * Get fields from disk object portion of info file - *-------------------------------------------------------------------------*/ +readDiskObjectHeader(FILE * const ifP, + unsigned int * const versionP, + bool * const hasDrawerDataP) { +/*--------------------------------------------------------------------------- + Read disk object header from file *ifP; validate it and return its contents. +----------------------------------------------------------------------------*/ DiskObject dobj; /* Disk object structure */ - size_t bytesRead; + size_t bytesReadCt; /* Read the disk object header */ - bytesRead = fread( &dobj, 1, sizeof(dobj), infoP->fp ); - if (ferror(infoP->fp)) - pm_error("Cannot read disk object header for file '%s'. " + bytesReadCt = fread(&dobj, 1, sizeof(dobj), ifP); + if (ferror(ifP)) + pm_error("Cannot read disk object header. " "fread() errno = %d (%s)", - infoP->name, errno, strerror(errno)); - else if (bytesRead != sizeof(dobj)) - pm_error("Cannot read entire disk object header for file '%s'. " + errno, strerror(errno)); + else if (bytesReadCt != sizeof(dobj)) + pm_error("Cannot read entire disk object header. " "Only read 0x%X of 0x%X bytes", - infoP->name, (unsigned)bytesRead, (unsigned)sizeof(dobj)); + (unsigned)bytesReadCt, (unsigned)sizeof(dobj)); - /* Check magic number */ + /* Validate magic number */ if ((dobj.magic[0] != 0xE3) && (dobj.magic[1] != 0x10)) - pm_error("Wrong magic number for file '%s'. " + pm_error("Wrong magic number in icon file. " "Expected 0xE310, but got 0x%X%X", - infoP->name, dobj.magic[0], dobj.magic[1]); + dobj.magic[0], dobj.magic[1]); + + *versionP = (dobj.version[0] << 8) + (dobj.version[1]); - /* Set version info and have drawer data flag */ - infoP->version = (dobj.version[0] << 8) + - (dobj.version[1] ); - infoP->drawerData = (dobj.pDrawerData[0] << 24) + + *hasDrawerDataP = + (dobj.pDrawerData[0] << 24) + (dobj.pDrawerData[1] << 16) + (dobj.pDrawerData[2] << 8) + - (dobj.pDrawerData[3] ) ? TRUE : FALSE; + (dobj.pDrawerData[3] ) + > 0; } static void -getIconHeader(IconInfo * const infoP) { +readIconHeader(FILE * const ifP, + unsigned int * const widthP, + unsigned int * const heightP, + unsigned int * const depthP, + unsigned int * const bpwidthP) { /*------------------------------------------------------------------------- * Get fields from icon header portion of info file *-------------------------------------------------------------------------*/ @@ -267,25 +397,37 @@ getIconHeader(IconInfo * const infoP) { size_t bytesRead; /* Read icon header */ - bytesRead = fread(&ihead, 1, sizeof(ihead), infoP->fp); - if (ferror(infoP->fp)) - pm_error("Cannot read icon header for file '%s'. " - "fread() errno = %d (%s)", - infoP->name, errno, strerror(errno)); + bytesRead = fread(&ihead, 1, sizeof(ihead), ifP); + if (ferror(ifP)) + pm_error("Failed to read icon header. fread() errno = %d (%s)", + errno, strerror(errno)); else if (bytesRead != sizeof(ihead)) - pm_error("Cannot read the entire icon header for file '%s'. " - "Only read 0x%X of 0x%X bytes", - infoP->name, (unsigned)bytesRead, (unsigned)sizeof(ihead)); + pm_error("Failed to read the entire icon header. " + "Read only %u of %u bytes", + (unsigned)bytesRead, (unsigned)sizeof(ihead)); + + if (!memeq(ihead.type, "\0\0\0\0", 4)) { + pm_message("Unrecognized object where icon header expected. " + "First 4 bytes are 0x%02x%02x%02x%02x. We expect " + "0x00000000", + ihead.type[0], ihead.type[1], ihead.type[2], ihead.type[3]); + } - /* Get icon width, height, and bitplanes */ - infoP->width = (ihead.iconWidth[0] << 8) + ihead.iconWidth[1]; - infoP->height = (ihead.iconHeight[0] << 8) + ihead.iconHeight[1]; - infoP->depth = (ihead.bpp[0] << 8) + ihead.bpp[1]; + *widthP = (ihead.iconWidth[0] << 8) + ihead.iconWidth[1]; + *heightP = (ihead.iconHeight[0] << 8) + ihead.iconHeight[1]; + *depthP = (ihead.bpp[0] << 8) + ihead.bpp[1]; - /* Check number of bit planes */ - if ((infoP->depth > 2) || (infoP->depth < 1)) - pm_error("We don't know how to interpret %u bitplanes file '%s'. ", - infoP->depth, infoP->name); + if (*widthP < 1) + pm_error("Invalid width value in icon header: %u", *widthP); + + if (*heightP < 1) + pm_error("Invalid height value in icon header: %u", *heightP); + + if (*depthP > 2 || *depthP < 1) + pm_error("We don't know how to interpret file with %u bitplanes. ", + *depthP); + + *bpwidthP = ROUNDUP(*widthP, 16); } @@ -298,17 +440,16 @@ addBitplane(unsigned char * const icon, Add bitplane to existing icon image -----------------------------------------------------------------------------*/ unsigned int i; - unsigned int j; - - for (i = j = 0; i < bpsize; ++i, j += 8) { - icon[j+0] = (icon[j+0] << 1) | ((buff[i] >> 7) & 0x01); - icon[j+1] = (icon[j+1] << 1) | ((buff[i] >> 6) & 0x01); - icon[j+2] = (icon[j+2] << 1) | ((buff[i] >> 5) & 0x01); - icon[j+3] = (icon[j+3] << 1) | ((buff[i] >> 4) & 0x01); - icon[j+4] = (icon[j+4] << 1) | ((buff[i] >> 3) & 0x01); - icon[j+5] = (icon[j+5] << 1) | ((buff[i] >> 2) & 0x01); - icon[j+6] = (icon[j+6] << 1) | ((buff[i] >> 1) & 0x01); - icon[j+7] = (icon[j+7] << 1) | ((buff[i] >> 0) & 0x01); + + for (i = 0; i < bpsize; ++i) { + icon[(i*8)+0] = (icon[(i*8)+0] << 1) | ((buff[i] >> 7) & 0x01); + icon[(i*8)+1] = (icon[(i*8)+1] << 1) | ((buff[i] >> 6) & 0x01); + icon[(i*8)+2] = (icon[(i*8)+2] << 1) | ((buff[i] >> 5) & 0x01); + icon[(i*8)+3] = (icon[(i*8)+3] << 1) | ((buff[i] >> 4) & 0x01); + icon[(i*8)+4] = (icon[(i*8)+4] << 1) | ((buff[i] >> 3) & 0x01); + icon[(i*8)+5] = (icon[(i*8)+5] << 1) | ((buff[i] >> 2) & 0x01); + icon[(i*8)+6] = (icon[(i*8)+6] << 1) | ((buff[i] >> 1) & 0x01); + icon[(i*8)+7] = (icon[(i*8)+7] << 1) | ((buff[i] >> 0) & 0x01); } } @@ -392,156 +533,134 @@ readIconData(FILE * const fileP, static void -writeIconData( IconInfo * const infoP, - struct pam * const pamP ) { +writeRaster(IconInfo * const infoP, + struct pam * const pamP, + bool const wantColor, + const pixel * const colors) { /*------------------------------------------------------------------------- - * Write icon data to file - *-------------------------------------------------------------------------*/ - unsigned int const bpwidth = ( ( infoP->width + 15 ) / 16 ) * 16; - /* Bitplane width; Width of each row in icon, including padding */ + Write out raster of PAM image described by *pamP. - tuple * row; /* Output row */ + 'wantColor' means the user wants the PAM to be tuple type RGB, regardless + of the input image type. - /* Allocate row */ - row = pnm_allocpamrow( pamP ); + 'colors' is the palette. It has 4 entries, one for each of the possible + color indices in the input icon raster. +--------------------------------------------------------------------------*/ + unsigned int row; + tuple * tuplerow; /* Output row */ - /* Write icon image to output file */ - /* Put if check outside for loop to reduce number of times check is made */ - if ( infoP->depth == 1 ) { - if ( infoP->forceColor ) { - /* Convert 1 bitplane icon into color PAM */ - unsigned int i; - for ( i = 0; i < infoP->height; ++i ) { - unsigned int j; - for ( j = 0; j < infoP->width; ++j ) { + tuplerow = pnm_allocpamrow(pamP); + + for (row = 0; row < infoP->height; ++row) { + unsigned int col; + + for (col = 0; col < infoP->width; ++col) { + if (infoP->depth == 1) { + if (wantColor) { /* 1 is black and 0 is white */ unsigned int colorIdx = - infoP->icon[ i * bpwidth + j ] ? 2 : 1; - row[j][PAM_RED_PLANE] = - PPM_GETR( infoP->colors[colorIdx] ); - row[j][PAM_GRN_PLANE] = - PPM_GETG( infoP->colors[colorIdx] ); - row[j][PAM_BLU_PLANE] = - PPM_GETB( infoP->colors[colorIdx] ); - } - pnm_writepamrow( pamP, row ); - } - } else { - /* Convert 1 bitplane icon into bitmap PAM */ - unsigned int i; - for ( i = 0; i < infoP->height; ++i ) { - unsigned int j; - for ( j = 0; j < infoP->width; j++ ) { + infoP->icon[row * infoP->bpwidth + col] ? 2 : 1; + + tuplerow[col][PAM_RED_PLANE] = PPM_GETR(colors[colorIdx]); + tuplerow[col][PAM_GRN_PLANE] = PPM_GETG(colors[colorIdx]); + tuplerow[col][PAM_BLU_PLANE] = PPM_GETB(colors[colorIdx]); + } else { /* 1 is black and 0 is white */ - row[j][0] = infoP->icon[ i * bpwidth + j ] ? 0 : 1; + tuplerow[col][0] = + infoP->icon[row * infoP->bpwidth + col] ? 0 : 1; } - pnm_writepamrow( pamP, row ); + } else { + unsigned int const colorIdx = + infoP->icon[row * infoP->bpwidth + col]; + tuplerow[col][PAM_RED_PLANE] = PPM_GETR(colors[colorIdx]); + tuplerow[col][PAM_GRN_PLANE] = PPM_GETG(colors[colorIdx]); + tuplerow[col][PAM_BLU_PLANE] = PPM_GETB(colors[colorIdx]); } } - } else { - /* Convert color icon into color PAM */ - unsigned int i; - for ( i = 0; i < infoP->height; ++i ) { - unsigned int j; - for ( j = 0; j < infoP->width; ++j ) { - unsigned int const colorIdx = infoP->icon[ i * bpwidth + j ]; - row[j][PAM_RED_PLANE] = PPM_GETR( infoP->colors[colorIdx] ); - row[j][PAM_GRN_PLANE] = PPM_GETG( infoP->colors[colorIdx] ); - row[j][PAM_BLU_PLANE] = PPM_GETB( infoP->colors[colorIdx] ); - } - pnm_writepamrow( pamP, row ); - } + pnm_writepamrow(pamP, tuplerow); } - /* Clean up allocated memory */ - pnm_freepamrow( row ); + pnm_freepamrow(tuplerow); } int -main( int argc, - char *argv[] ) { +main(int argc, const char **argv) { - IconInfo info; /* Miscellaneous icon information */ - struct pam pam; /* PAM header */ - int skip; /* Bytes to skip to read next icon header */ + CmdlineInfo cmdline; + IconInfo info; /* Miscellaneous icon information */ + struct pam pam; /* PAM header */ - /* Init PNM library */ - pnm_init( &argc, argv ); + pm_proginit(&argc, argv); - /* Parse command line arguments */ - parseCommandLine( argc, argv, &info ); + parseCommandLine(argc, argv, &cmdline); - /* Open input file */ - info.fp = pm_openr( info.name ); + info.ifP = pm_openr(cmdline.inputFileNm); - /* Read disk object header */ - getDiskObject( &info ); + readDiskObjectHeader(info.ifP, &info.version, &info.hasDrawerData); /* Skip drawer data, if any */ - if ( info.drawerData ) { - skip = 56; /* Draw data size */ - if ( fseek( info.fp, skip, SEEK_CUR ) < 0 ) - pm_error( "Cannot skip header information in file '%s'. " - "fseek() errno = %d (%s)", - info.name, errno, strerror( errno ) ); - } + if (info.hasDrawerData) { + unsigned int const skipCt = 56; /* Draw data size */ - /* Get dimensions for first icon */ - getIconHeader( &info ); + int rc; - /* Skip ahead to next header if converting second icon */ - if ( info.selected ) { - skip = info.height * ( ( ( info.width + 15 ) / 16 ) * 2 ) * info.depth; + rc = fseek(info.ifP, skipCt, SEEK_CUR); + if (rc < 0) { + pm_error("Failed to skip header information in input file. " + "fseek() errno = %d (%s)", + errno, strerror(errno)); + } + } - if ( fseek( info.fp, skip, SEEK_CUR ) < 0 ) - pm_error( "Cannot skip to next icon in file '%s'. " - "fseek() errno = %d (%s)", - info.name, errno, strerror( errno ) ); + /* Read header of first icon */ + readIconHeader(info.ifP, &info.width, &info.height, &info.depth, + &info.bpwidth); - /* Get dimensions for second icon */ - getIconHeader( &info ); - } + readIconData(info.ifP, info.width, info.height, info.depth, &info.icon); - /* Read icon data */ - readIconData( info.fp, info.width, info.height, info.depth, &info.icon ); + if (cmdline.selected) { + /* He wants the second icon, so update info.width, etc. to be for the + second icon. + */ + readIconHeader(info.ifP, &info.width, &info.height, &info.depth, + &info.bpwidth); - /* Print icon info */ - pm_message( "converting %s, version %d, %s icon: %d X %d X %d", - info.name, info.version, info.selected ? "second" : "first", - info.width, info.height, info.depth ); + readIconData(info.ifP, info.width, info.height, info.depth, + &info.icon); + } - /* Write PAM header */ - pam.size = sizeof( pam ); - pam.len = PAM_STRUCT_SIZE( tuple_type ); + if (cmdline.verbose) { + pm_message("Version %u .info file, %s icon: %uW x %uH x %u deep", + info.version, cmdline.selected ? "second" : "first", + info.width, info.height, info.depth); + } + pam.size = sizeof(pam); + pam.len = PAM_STRUCT_SIZE(tuple_type); pam.file = stdout; pam.height = info.height; pam.width = info.width; pam.format = PAM_FORMAT; - if ( ( info.depth == 1 ) && ( info.forceColor == FALSE ) ) { + if ((info.depth == 1) && !cmdline.forcecolor) { pam.depth = 1; pam.maxval = 1; - strcpy( pam.tuple_type, "BLACKANDWHITE" ); + strcpy(pam.tuple_type, "BLACKANDWHITE"); } else { pam.depth = 3; pam.maxval = 0xFF; - strcpy( pam.tuple_type, "RGB" ); + strcpy(pam.tuple_type, "RGB"); } - pnm_writepaminit( &pam ); + pnm_writepaminit(&pam); - /* Write icon data */ - writeIconData( &info, &pam ); + writeRaster(&info, &pam, cmdline.forcecolor, cmdline.colors); - free( info.icon ); - - /* Close input file and return */ - pm_close( pam.file ); - pm_close( info.fp ); + free(info.icon); + pm_close(pam.file); + pm_close(info.ifP); return 0; } - diff --git a/converter/other/pamtogif.c b/converter/other/pamtogif.c index 11e9bdcd..c41c778c 100644 --- a/converter/other/pamtogif.c +++ b/converter/other/pamtogif.c @@ -118,7 +118,7 @@ pamAlphaPlane(struct pam * const pamP) { static void -parseCommandLine(int argc, char ** argv, +parseCommandLine(int argc, const char ** argv, struct CmdlineInfo * const cmdlineP) { /*---------------------------------------------------------------------------- Parse the program arguments (given by argc and argv) into a form @@ -172,7 +172,7 @@ parseCommandLine(int argc, char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 == 0) @@ -212,9 +212,9 @@ Putword(int const w, FILE * const fp) { static int -closestColor(tuple const color, - struct pam * const pamP, - struct Cmap * const cmapP) { +closestColor(tuple const color, + struct pam * const pamP, + const struct Cmap * const cmapP) { /*---------------------------------------------------------------------------- Return the colormap index of the color in the colormap *cmapP that is closest to the color 'color', whose format is specified by @@ -316,7 +316,7 @@ rowReader_destroy(RowReader * const rdrP) { static void -rowReaderSkipRows(RowReader * const rdrP, +rowReader_skipRows(RowReader * const rdrP, unsigned int const rowCount, bool * const eofP) { /*---------------------------------------------------------------------------- @@ -347,7 +347,7 @@ rowReaderSkipRows(RowReader * const rdrP, static void -rowReaderGotoNextInterlaceRow(RowReader * const rdrP) { +rowReader_gotoNextInterlaceRow(RowReader * const rdrP) { /*---------------------------------------------------------------------------- Position reader to the next row in the interlace pattern, assuming it is now positioned immediately after the current row. @@ -363,16 +363,16 @@ rowReaderGotoNextInterlaceRow(RowReader * const rdrP) { switch (rdrP->pass) { case MULT8PLUS0: - rowReaderSkipRows(rdrP, 7, &endOfPass); + rowReader_skipRows(rdrP, 7, &endOfPass); break; case MULT8PLUS4: - rowReaderSkipRows(rdrP, 7, &endOfPass); + rowReader_skipRows(rdrP, 7, &endOfPass); break; case MULT4PLUS2: - rowReaderSkipRows(rdrP, 3, &endOfPass); + rowReader_skipRows(rdrP, 3, &endOfPass); break; case MULT2PLUS1: - rowReaderSkipRows(rdrP, 1, &endOfPass); + rowReader_skipRows(rdrP, 1, &endOfPass); break; } @@ -387,15 +387,15 @@ rowReaderGotoNextInterlaceRow(RowReader * const rdrP) { switch (rdrP->pass) { case MULT8PLUS0: rdrP->pass = MULT8PLUS4; - rowReaderSkipRows(rdrP, 4, &endOfPass); + rowReader_skipRows(rdrP, 4, &endOfPass); break; case MULT8PLUS4: rdrP->pass = MULT4PLUS2; - rowReaderSkipRows(rdrP, 2, &endOfPass); + rowReader_skipRows(rdrP, 2, &endOfPass); break; case MULT4PLUS2: rdrP->pass = MULT2PLUS1; - rowReaderSkipRows(rdrP, 1, &endOfPass); + rowReader_skipRows(rdrP, 1, &endOfPass); break; case MULT2PLUS1: rdrP->eof = TRUE; @@ -407,7 +407,7 @@ rowReaderGotoNextInterlaceRow(RowReader * const rdrP) { static void -rowReaderGotoNextStraightRow(RowReader * const rdrP) { +rowReader_gotoNextStraightRow(RowReader * const rdrP) { /*---------------------------------------------------------------------------- Position reader to the next row in a straight, non-interlace pattern, assuming the file is now positioned immediately after the @@ -434,19 +434,19 @@ rowReader_read(RowReader * const rdrP, ++rdrP->nextRow; if (rdrP->interlace) - rowReaderGotoNextInterlaceRow(rdrP); + rowReader_gotoNextInterlaceRow(rdrP); else - rowReaderGotoNextStraightRow(rdrP); + rowReader_gotoNextStraightRow(rdrP); } static unsigned int -gifPixel(struct pam * const pamP, - tuple const tuple, - unsigned int const alphaPlane, - sample const alphaThreshold, - struct Cmap * const cmapP) { +gifPixel(struct pam * const pamP, + tuple const tuple, + unsigned int const alphaPlane, + sample const alphaThreshold, + const struct Cmap * const cmapP) { /*---------------------------------------------------------------------------- Return the colormap index of the tuple 'tuple', whose format is described by *pamP, using colormap *cmapP. @@ -1270,89 +1270,6 @@ writePixelUncompressed(LzwCompressor * const lzwP, static void -writeRaster(struct pam * const pamP, - RowReader * const rowReaderP, - unsigned int const alphaPlane, - unsigned int const alphaThreshold, - struct Cmap * const cmapP, - unsigned int const initBits, - FILE * const ofP, - bool const lzw, - bool const noclear) { -/*---------------------------------------------------------------------------- - Write the raster to file 'ofP'. - - Get the raster to write from 'rowReaderP', which gives tuples whose - format is described by 'pamP'. - - 'alphaPlane' is the number of the plane in the tuples supplied by - 'rowReaderP' that we should use for transparency information, and - 'alphaThreshold' is the value in that plane below which we should consider - the pixel transparent for GIF purposes. - - 'alphaPlane' is zero to indicate we should not use any plane as an alpha - plane (so it's not possible to specify Plane 0 as alpha). - - Use the colormap 'cmapP' to generate the raster ('rowReaderP' gives - pixel values as RGB samples; the GIF raster is colormap indices). - - Write the raster using LZW compression, or uncompressed depending - on 'lzw'. - - If 'noclear', don't use any GIF clear codes in the output; i.e. don't - recompute the string table from current input. Once the string table gets - to maximum size, just keep using that table for the rest of the image. ------------------------------------------------------------------------------*/ - LzwCompressor * lzwP; - tuple * tuplerow; - unsigned int nRowsDone; - /* Number of rows we have read so far from the the input (the - last of which is the one we're working on now). Note that - in case of interlace, this is not the same thing as the row - number of the current row. - */ - - lzwP = lzw_create(ofP, initBits, lzw, noclear, pamP->height * pamP->width); - - tuplerow = pnm_allocpamrow(pamP); - - lzw_clearBlock(lzwP); - - nRowsDone = 0; - - while (nRowsDone < pamP->height) { - unsigned int col; - - rowReader_read(rowReaderP, tuplerow); - - for (col = 0; col < pamP->width; ++col) { - unsigned int const colorIndex = - gifPixel(pamP, tuplerow[col], alphaPlane, alphaThreshold, - cmapP); - - /* The value for the pixel in the GIF image. I.e. the colormap - index. - */ - if (lzw) - lzw_encodePixel(lzwP, colorIndex); - else - writePixelUncompressed(lzwP, colorIndex); - } - ++nRowsDone; - } - /* Gif is no good with no pixels; fortunately, that's impossible: */ - assert(nRowsDone > 0); - - lzw_flush(lzwP); - - pnm_freepamrow(tuplerow); - - lzw_destroy(lzwP); -} - - - -static void writeGlobalColorMap(FILE * const ofP, const struct Cmap * const cmapP, unsigned int const bitsPerPixel) { @@ -1404,6 +1321,23 @@ writeGlobalColorMap(FILE * const ofP, static void +reportImageInfo(bool const interlace, + unsigned int const background, + unsigned int const bitsPerPixel) { + + if (verbose) { + if (interlace) + pm_message("interlaced"); + else + pm_message("not interlaced"); + pm_message("Background color index = %u", background); + pm_message("%u bits per pixel", bitsPerPixel); + } +} + + + +static void writeGifHeader(FILE * const ofP, unsigned int const width, unsigned int const height, @@ -1460,6 +1394,15 @@ writeGifHeader(FILE * const ofP, static void +writeImageSeparator(FILE * const ofP) { + + fputc(',', ofP); + +} + + + +static void writeImageHeader(FILE * const ofP, unsigned int const leftOffset, unsigned int const topOffset, @@ -1486,42 +1429,110 @@ writeImageHeader(FILE * const ofP, static void -reportImageInfo(bool const interlace, - unsigned int const background, - unsigned int const bitsPerPixel) { +writeRaster(struct pam * const pamP, + RowReader * const rowReaderP, + unsigned int const alphaPlane, + unsigned int const alphaThreshold, + const struct Cmap * const cmapP, + unsigned int const initBits, + FILE * const ofP, + bool const lzw, + bool const noclear) { +/*---------------------------------------------------------------------------- + Write the raster to file 'ofP'. - if (verbose) { - if (interlace) - pm_message("interlaced"); - else - pm_message("not interlaced"); - pm_message("Background color index = %u", background); - pm_message("%u bits per pixel", bitsPerPixel); + Get the raster to write from 'rowReaderP', which gives tuples whose + format is described by 'pamP'. + + 'alphaPlane' is the number of the plane in the tuples supplied by + 'rowReaderP' that we should use for transparency information, and + 'alphaThreshold' is the value in that plane below which we should consider + the pixel transparent for GIF purposes. + + 'alphaPlane' is zero to indicate we should not use any plane as an alpha + plane (so it's not possible to specify Plane 0 as alpha). + + Use the colormap 'cmapP' to generate the raster ('rowReaderP' gives + pixel values as RGB samples; the GIF raster is colormap indices). + + Write the raster using LZW compression, or uncompressed depending + on 'lzw'. + + If 'noclear', don't use any GIF clear codes in the output; i.e. don't + recompute the string table from current input. Once the string table gets + to maximum size, just keep using that table for the rest of the image. +-----------------------------------------------------------------------------*/ + LzwCompressor * lzwP; + tuple * tuplerow; + unsigned int nRowsDone; + /* Number of rows we have read so far from the the input (the + last of which is the one we're working on now). Note that + in case of interlace, this is not the same thing as the row + number of the current row. + */ + + lzwP = lzw_create(ofP, initBits, lzw, noclear, pamP->height * pamP->width); + + tuplerow = pnm_allocpamrow(pamP); + + lzw_clearBlock(lzwP); + + nRowsDone = 0; + + while (nRowsDone < pamP->height) { + unsigned int col; + + rowReader_read(rowReaderP, tuplerow); + + for (col = 0; col < pamP->width; ++col) { + unsigned int const colorIndex = + gifPixel(pamP, tuplerow[col], alphaPlane, alphaThreshold, + cmapP); + + /* The value for the pixel in the GIF image. I.e. the colormap + index. + */ + if (lzw) + lzw_encodePixel(lzwP, colorIndex); + else + writePixelUncompressed(lzwP, colorIndex); + } + ++nRowsDone; } + /* Gif is no good with no pixels; fortunately, that's impossible: */ + assert(nRowsDone > 0); + + lzw_flush(lzwP); + + pnm_freepamrow(tuplerow); + + lzw_destroy(lzwP); } static void -gifEncode(struct pam * const pamP, - FILE * const ofP, - pm_filepos const rasterPos, - bool const gInterlace, - int const background, - unsigned int const bitsPerPixel, - struct Cmap * const cmapP, - char const comment[], - float const aspect, - bool const lzw, - bool const noclear, - bool const usingAlpha) { -/*---------------------------------------------------------------------------- - 'usingAlpha' means use the alpha (transparency) plane, if there is one, to - determine which GIF pixels are transparent. When this is true, the - colormap *cmapP must contain a transparent entry. ------------------------------------------------------------------------------*/ - unsigned int const leftOffset = 0; - unsigned int const topOffset = 0; +writeEndOfImage(FILE * const ofP) { + + /* An empty block marks the end of a series of blocks */ + + fputc(0, ofP); +} + + + +static void +writeGifImage(FILE * const ofP, + unsigned int const leftOffset, + unsigned int const topOffset, + struct pam * const pamP, + pm_filepos const rasterPos, + bool const gInterlace, + unsigned int const bitsPerPixel, + bool const lzw, + bool const noclear, + bool const usingAlpha, + const struct Cmap * const cmapP) { unsigned int const initCodeSize = bitsPerPixel <= 1 ? 2 : bitsPerPixel; /* The initial code size */ @@ -1535,6 +1546,52 @@ gifEncode(struct pam * const pamP, RowReader * rowReaderP; + writeImageSeparator(ofP); + + writeImageHeader(ofP, leftOffset, topOffset, pamP->width, pamP->height, + gInterlace, initCodeSize); + + rowReaderP = rowReader_create(pamP, rasterPos, gInterlace); + + writeRaster(pamP, rowReaderP, alphaPlane, alphaThreshold, + cmapP, initCodeSize + 1, ofP, lzw, noclear); + + rowReader_destroy(rowReaderP); + + writeEndOfImage(ofP); +} + + + +static void +writeGifStreamTerminator(FILE * const ofP) { + + fputc(';', ofP); +} + + + +static void +writeGif(struct pam * const pamP, + FILE * const ofP, + pm_filepos const rasterPos, + bool const gInterlace, + int const background, + unsigned int const bitsPerPixel, + const struct Cmap * const cmapP, + char const comment[], + float const aspect, + bool const lzw, + bool const noclear, + bool const usingAlpha) { +/*---------------------------------------------------------------------------- + 'usingAlpha' means use the alpha (transparency) plane, if there is one, to + determine which GIF pixels are transparent. When this is true, the + colormap *cmapP must contain a transparent entry. +-----------------------------------------------------------------------------*/ + unsigned int const leftOffset = 0; + unsigned int const topOffset = 0; + reportImageInfo(gInterlace, background, bitsPerPixel); if (pamP->width > 65535) @@ -1548,33 +1605,18 @@ gifEncode(struct pam * const pamP, writeGifHeader(ofP, pamP->width, pamP->height, background, bitsPerPixel, cmapP, comment, aspect); - /* Write an Image separator */ - fputc(',', ofP); + writeGifImage(ofP, leftOffset, topOffset, pamP, rasterPos, + gInterlace, bitsPerPixel, lzw, noclear, usingAlpha, + cmapP); - writeImageHeader(ofP, leftOffset, topOffset, pamP->width, pamP->height, - gInterlace, initCodeSize); - - rowReaderP = rowReader_create(pamP, rasterPos, gInterlace); - - /* Write the actual raster */ - - writeRaster(pamP, rowReaderP, alphaPlane, alphaThreshold, - cmapP, initCodeSize + 1, ofP, lzw, noclear); - - rowReader_destroy(rowReaderP); - - /* Write out a zero length data block (to end the series) */ - fputc(0, ofP); - - /* Write the GIF file terminator */ - fputc(';', ofP); + writeGifStreamTerminator(ofP); } static void reportTransparent(enum TransparencyType const transType, - struct Cmap * const cmapP) { + const struct Cmap * const cmapP) { if (verbose) { switch (transType) { @@ -1985,7 +2027,8 @@ destroyCmap(struct Cmap * const cmapP) { int -main(int argc, char *argv[]) { +main(int argc, const char ** argv) { + struct CmdlineInfo cmdline; FILE * ifP; struct pam pam; @@ -2000,7 +2043,7 @@ main(int argc, char *argv[]) { TRANS_ALPHA. */ - pnm_init(&argc, argv); + pm_proginit(&argc, argv); parseCommandLine(argc, argv, &cmdline); @@ -2033,11 +2076,10 @@ main(int argc, char *argv[]) { computeTransparent(transType, cmdline.transparent, fakeTransparent, &cmap); - /* All set, let's do it. */ - gifEncode(&pam, stdout, rasterPos, - cmdline.interlace, 0, bitsPerPixel, &cmap, cmdline.comment, - cmdline.aspect, !cmdline.nolzw, cmdline.noclear, - transType==TRANS_ALPHA); + writeGif(&pam, stdout, rasterPos, + cmdline.interlace, 0, bitsPerPixel, &cmap, cmdline.comment, + cmdline.aspect, !cmdline.nolzw, cmdline.noclear, + transType==TRANS_ALPHA); destroyCmap(&cmap); diff --git a/converter/other/pamtopdbimg.c b/converter/other/pamtopdbimg.c index da0f5064..1ed08f9f 100644 --- a/converter/other/pamtopdbimg.c +++ b/converter/other/pamtopdbimg.c @@ -73,9 +73,7 @@ parseCommandLine(int argc, const char ** argv, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry *option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -105,7 +103,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ diff --git a/converter/other/pamtopng.c b/converter/other/pamtopng.c index 24eb1ca2..51203df5 100644 --- a/converter/other/pamtopng.c +++ b/converter/other/pamtopng.c @@ -218,7 +218,7 @@ parseCommandLine (int argc, opt.allowNegNum = false; /* we have no parms that are negative numbers */ /* uses and sets argc, argv, and some of *cmdlineP and others */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); if (cmdlineP->chromaSpec) parseChromaOpt(chroma, &cmdlineP->chroma); diff --git a/converter/other/pamtopnm.c b/converter/other/pamtopnm.c index 11e34b45..45ab1beb 100644 --- a/converter/other/pamtopnm.c +++ b/converter/other/pamtopnm.c @@ -33,9 +33,7 @@ parseCommandLine(int argc, const char ** argv, Note that the file spec array we return is stored in the storage that was passed to us as the argv array. -----------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to OptParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -49,7 +47,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 == 0) diff --git a/converter/other/pamtoqoi.c b/converter/other/pamtoqoi.c index e3f87ae0..a188cca9 100644 --- a/converter/other/pamtoqoi.c +++ b/converter/other/pamtoqoi.c @@ -71,9 +71,7 @@ parseCommandLine(int argc, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -86,7 +84,7 @@ parseCommandLine(int argc, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 < 1) diff --git a/converter/other/pamtosrf.c b/converter/other/pamtosrf.c index b62b19df..eb2d44bd 100644 --- a/converter/other/pamtosrf.c +++ b/converter/other/pamtosrf.c @@ -45,9 +45,7 @@ parseCommandLine(int argc, const char ** argv, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry *option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -62,7 +60,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 < 1) diff --git a/converter/other/pamtotga.c b/converter/other/pamtotga.c index f596a313..c0fb524a 100644 --- a/converter/other/pamtotga.c +++ b/converter/other/pamtotga.c @@ -82,7 +82,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdline_p and others. */ if (cmap + cmap16 + mono + rgb > 1) diff --git a/converter/other/pamtotiff.c b/converter/other/pamtotiff.c index 4f25d93a..584cb840 100644 --- a/converter/other/pamtotiff.c +++ b/converter/other/pamtotiff.c @@ -236,7 +236,7 @@ parseCommandLine(int argc, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char**)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (none + packbits + lzw + g3 + g4 + flate + adobeflate > 1) diff --git a/converter/other/pamtowinicon.c b/converter/other/pamtowinicon.c index 14b29f34..4d73ccdf 100644 --- a/converter/other/pamtowinicon.c +++ b/converter/other/pamtowinicon.c @@ -47,7 +47,7 @@ parseCommandLine(int argc, const char **argv, opt3.short_allowed = false; opt3.allowNegNum = false; - pm_optParseOptions3(&argc, (char **)argv, opt3, sizeof(opt3), 0); + pm_optParseOptions4(&argc, argv, opt3, sizeof(opt3), 0); if (pngthresholdSpec) { if (UINT_MAX / cmdlineP->pngthreshold < cmdlineP->pngthreshold) diff --git a/converter/other/pdbimgtopam.c b/converter/other/pdbimgtopam.c index 4c064630..55a2ec70 100644 --- a/converter/other/pdbimgtopam.c +++ b/converter/other/pdbimgtopam.c @@ -64,9 +64,7 @@ parseCommandLine(int argc, const char ** argv, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry *option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -85,7 +83,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (!notefileSpec) diff --git a/converter/other/pgmtopbm.c b/converter/other/pgmtopbm.c index d5f67a06..b71904d8 100644 --- a/converter/other/pgmtopbm.c +++ b/converter/other/pgmtopbm.c @@ -47,9 +47,7 @@ parseCommandLine(int argc, const char ** argv, Note that the file spec array we return is stored in the storage that was passed to us as the argv array. -----------------------------------------------------------------------------*/ - optEntry *option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -83,7 +81,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We may have parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (floydOpt + thresholdOpt + hilbertOpt + dither8Opt + diff --git a/converter/other/pgmtoppm.c b/converter/other/pgmtoppm.c index dea6c4ca..822ddac7 100644 --- a/converter/other/pgmtoppm.c +++ b/converter/other/pgmtoppm.c @@ -48,9 +48,7 @@ parseCommandLine(int argc, const char ** argv, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry *option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -74,8 +72,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); - /* Uses and sets argc, argv, and some of *cmdlineP and others. */ + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); if (!mapSpec) cmdlineP->map = NULL; diff --git a/converter/other/pngtopam.c b/converter/other/pngtopam.c index a700364f..acb04599 100644 --- a/converter/other/pngtopam.c +++ b/converter/other/pngtopam.c @@ -73,9 +73,7 @@ parseCommandLine(int argc, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -109,7 +107,7 @@ parseCommandLine(int argc, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ diff --git a/converter/other/pnmtojpeg.c b/converter/other/pnmtojpeg.c index 99efa734..b80860e7 100644 --- a/converter/other/pnmtojpeg.c +++ b/converter/other/pnmtojpeg.c @@ -212,9 +212,7 @@ parseCommandLine(const int argc, const char ** argv, On the other hand, unlike other option processing functions, we do not change argv at all. -----------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to OptParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; int i; /* local loop variable */ @@ -285,7 +283,7 @@ parseCommandLine(const int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argcParse, (char **)argvParse, opt, sizeof(opt), 0); + pm_optParseOptions4(&argcParse, argvParse, opt, sizeof(opt), 0); if (!qualitySpec) cmdlineP->quality = -1; /* unspecified */ diff --git a/converter/other/pnmtopng.c b/converter/other/pnmtopng.c index 08647045..10b586b0 100644 --- a/converter/other/pnmtopng.c +++ b/converter/other/pnmtopng.c @@ -284,9 +284,7 @@ parseCommandLine(int argc, const char ** argv, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry *option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -383,7 +381,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ diff --git a/converter/other/pnmtops.c b/converter/other/pnmtops.c index d2577dd6..3dd0be79 100644 --- a/converter/other/pnmtops.c +++ b/converter/other/pnmtops.c @@ -264,7 +264,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; opt.allowNegNum = FALSE; - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); if (cmdlineP->mustturn && noturn) pm_error("You cannot specify both -turn and -noturn"); diff --git a/converter/other/pnmtorle.c b/converter/other/pnmtorle.c index a75ab218..e8a37d9b 100644 --- a/converter/other/pnmtorle.c +++ b/converter/other/pnmtorle.c @@ -71,9 +71,7 @@ parseCommandLine(int argc, const char ** argv, Note that the file spec array we return is stored in the storage that was passed to us as the argv array. -----------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. */ - + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -92,7 +90,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ free(option_def); diff --git a/converter/other/qoitopam.c b/converter/other/qoitopam.c index 51dfd1e8..68182aa3 100644 --- a/converter/other/qoitopam.c +++ b/converter/other/qoitopam.c @@ -74,9 +74,7 @@ parseCommandLine(int argc, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -89,7 +87,7 @@ parseCommandLine(int argc, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 < 1) diff --git a/converter/other/rasttopnm.c b/converter/other/rasttopnm.c index 7f6015a3..bc199ef7 100644 --- a/converter/other/rasttopnm.c +++ b/converter/other/rasttopnm.c @@ -37,9 +37,7 @@ parseCommandLine(int argc, const char ** argv, Note that the file spec array we return is stored in the storage that was passed to us as the argv array. -----------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to OptParseOptions2 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -59,7 +57,7 @@ parseCommandLine(int argc, const char ** argv, OPTENT3(0, "dumpcolormap", OPT_FLAG, NULL, &cmdlineP->dumpcolormap, 0); - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 == 0) diff --git a/converter/other/sgitopnm.c b/converter/other/sgitopnm.c index 4bacc411..09bdc669 100644 --- a/converter/other/sgitopnm.c +++ b/converter/other/sgitopnm.c @@ -56,9 +56,7 @@ parseCommandLine(int argc, const char ** argv, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -78,7 +76,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ free(option_def); diff --git a/converter/other/srftopam.c b/converter/other/srftopam.c index 78d535fb..857d6d92 100644 --- a/converter/other/srftopam.c +++ b/converter/other/srftopam.c @@ -46,9 +46,7 @@ parseCommandLine(int argc, const char ** argv, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry *option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -63,7 +61,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 < 1) diff --git a/converter/other/tifftopnm.c b/converter/other/tifftopnm.c index 44b3461b..0fbbaad0 100644 --- a/converter/other/tifftopnm.c +++ b/converter/other/tifftopnm.c @@ -105,8 +105,8 @@ parseCommandLine(int argc, const char ** const argv, sometimes, one of these strings is actually just a suffix of an entry in argv! -----------------------------------------------------------------------------*/ + optEntry * option_def; optStruct3 opt; - optEntry *option_def; unsigned int option_def_index; unsigned int alphaSpec; @@ -130,7 +130,7 @@ parseCommandLine(int argc, const char ** const argv, OPTENT3(0, "alphaout", OPT_STRING, &cmdlineP->alphaFilename, &alphaSpec, 0); - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); if (argc - 1 == 0) cmdlineP->inputFilename = strdup("-"); /* he wants stdin */ diff --git a/converter/other/winicontopam.c b/converter/other/winicontopam.c index bb39bf60..b0dbbc07 100644 --- a/converter/other/winicontopam.c +++ b/converter/other/winicontopam.c @@ -86,7 +86,7 @@ parseCommandLine(int argc, const char **argv, opt3.short_allowed = false; opt3.allowNegNum = false; - pm_optParseOptions3(&argc, (char **)argv, opt3, sizeof(opt3), 0); + pm_optParseOptions4(&argc, argv, opt3, sizeof(opt3), 0); if (cmdlineP->allimages && cmdlineP->imageSpec) pm_error("You cannot specify both -allimages and -image"); diff --git a/converter/other/xwdtopnm.c b/converter/other/xwdtopnm.c index 810d302a..5f8a56c9 100644 --- a/converter/other/xwdtopnm.c +++ b/converter/other/xwdtopnm.c @@ -95,9 +95,7 @@ parseCommandLine(int argc, const char ** argv, sometimes, one of these strings is actually just a suffix of an entry in argv! -----------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to OptParseOptions3 on how to parse our options. - */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int option_def_index; @@ -115,7 +113,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We may have parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **) argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc - 1 == 0) diff --git a/converter/other/yuy2topam.c b/converter/other/yuy2topam.c index b4742bf5..8416d393 100644 --- a/converter/other/yuy2topam.c +++ b/converter/other/yuy2topam.c @@ -44,8 +44,7 @@ parseCommandLine(int argc, const char ** argv, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. --------------------------------------------------------------------------*/ - optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. */ + optEntry * option_def; /* Used by OPTENT3 */ optStruct3 opt; unsigned int widthSpec, heightSpec; @@ -63,7 +62,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (!widthSpec) diff --git a/converter/pbm/g3topbm.c b/converter/pbm/g3topbm.c index 56462768..80b7b37d 100644 --- a/converter/pbm/g3topbm.c +++ b/converter/pbm/g3topbm.c @@ -96,7 +96,6 @@ parseCommandLine(int argc, const char ** const argv, was passed to us as the argv array. -----------------------------------------------------------------------------*/ optEntry * option_def; /* malloc'ed */ - /* Instructions to OptParseOptions3 on how to parse our options. */ optStruct3 opt; unsigned int option_def_index; @@ -126,7 +125,7 @@ parseCommandLine(int argc, const char ** const argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We may have parms that are negative numbers */ - pm_optParseOptions3(&argc, (char**)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (widthSpec && paper_sizeSpec) diff --git a/converter/pbm/pbmtoepsi.c b/converter/pbm/pbmtoepsi.c index 7ffd6103..bfa87032 100644 --- a/converter/pbm/pbmtoepsi.c +++ b/converter/pbm/pbmtoepsi.c @@ -26,14 +26,15 @@ */ #include "pm_c_util.h" -#include "pbm.h" +#include "mallocvar.h" #include "shhopt.h" +#include "pbm.h" -struct cmdlineInfo { +struct CmdlineInfo { /* All the information the user supplied in the command line, in a form easy for the program to use. */ - const char *inputFileName; + const char * inputFileName; unsigned int dpiX; /* horiz component of DPI option */ unsigned int dpiY; /* vert component of DPI option */ @@ -80,21 +81,20 @@ parseDpi(char * const dpiOpt, static void parseCommandLine(int argc, const char ** const argv, - struct cmdlineInfo * const cmdlineP) { + struct CmdlineInfo * const cmdlineP) { /*---------------------------------------------------------------------------- Note that the file spec array we return is stored in the storage that was passed to us as the argv array. -----------------------------------------------------------------------------*/ - optEntry *option_def = malloc(100*sizeof(optEntry)); - /* Instructions to OptParseOptions2 on how to parse our options. - */ + optEntry * option_def; optStruct3 opt; - unsigned int option_def_index; char * dpiOpt; unsigned int dpiOptSpec; + MALLOCARRAY_NOFAIL(option_def, 100); + option_def_index = 0; /* incremented by OPTENTRY */ OPTENT3(0, "bbonly", OPT_FLAG, NULL, &cmdlineP->bbonly, 0); OPTENT3(0, "verbose", OPT_FLAG, NULL, &cmdlineP->verbose, 0); @@ -104,7 +104,7 @@ parseCommandLine(int argc, const char ** const argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ @@ -235,7 +235,7 @@ eightPixels(bit ** const bits, int main(int argc, const char * argv[]) { - struct cmdlineInfo cmdline; + struct CmdlineInfo cmdline; FILE * ifP; bit ** bits; int rows, cols; diff --git a/converter/pbm/pbmtoepson.c b/converter/pbm/pbmtoepson.c index 69742368..293167ac 100644 --- a/converter/pbm/pbmtoepson.c +++ b/converter/pbm/pbmtoepson.c @@ -55,11 +55,8 @@ parseCommandLine(int argc, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry *option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; optStruct3 opt; - unsigned int option_def_index; char * protocol; @@ -82,7 +79,7 @@ parseCommandLine(int argc, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3( &argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4( &argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ diff --git a/converter/pbm/pbmtoescp2.c b/converter/pbm/pbmtoescp2.c index 54a77e44..d4d98388 100644 --- a/converter/pbm/pbmtoescp2.c +++ b/converter/pbm/pbmtoescp2.c @@ -49,12 +49,15 @@ parseCommandLine(int argc, const char ** argv, struct CmdlineInfo *cmdlineP) { optStruct3 opt; - unsigned int option_def_index = 0; - optEntry * option_def = malloc(100*sizeof(optEntry)); + unsigned int option_def_index; + optEntry * option_def; unsigned int compressSpec, resolutionSpec, stripeHeightSpec, rawSpec, formfeedSpec; + MALLOCARRAY(option_def, 100); + + option_def_index = 0; opt.opt_table = option_def; opt.short_allowed = FALSE; opt.allowNegNum = FALSE; @@ -69,7 +72,7 @@ parseCommandLine(int argc, const char ** argv, OPTENT3(0, "formfeed", OPT_FLAG, NULL, &formfeedSpec, 0); - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); if (argc-1 > 1) pm_error("Too many arguments: %d. " diff --git a/converter/pbm/pbmtog3.c b/converter/pbm/pbmtog3.c index 48de8885..ac190d22 100644 --- a/converter/pbm/pbmtog3.c +++ b/converter/pbm/pbmtog3.c @@ -57,11 +57,11 @@ parseCommandLine(int argc, const char ** const argv, optEntry * option_def; /* Instructions to OptParseOptions2 on how to parse our options. */ optStruct3 opt; + unsigned int option_def_index; + unsigned int nofixedwidth; unsigned int align8, align16; - unsigned int option_def_index; - MALLOCARRAY_NOFAIL(option_def, 100); option_def_index = 0; /* incremented by OPTENTRY */ @@ -84,7 +84,7 @@ parseCommandLine(int argc, const char ** const argv, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = true; /* We may have parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ free(option_def); diff --git a/converter/pbm/pbmtolj.c b/converter/pbm/pbmtolj.c index 1936544f..1805206b 100644 --- a/converter/pbm/pbmtolj.c +++ b/converter/pbm/pbmtolj.c @@ -67,11 +67,9 @@ parseCommandLine(int argc, const char ** argv, was passed to us as the argv array. -----------------------------------------------------------------------------*/ optEntry *option_def; - /* Instructions to OptParseOptions3 on how to parse our options. - */ optStruct3 opt; - unsigned int option_def_index; + unsigned int dpiSpec, copiesSpec, compressSpec; MALLOCARRAY(option_def, 100); @@ -96,7 +94,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We may have parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 == 0) diff --git a/converter/pbm/pbmtolps.c b/converter/pbm/pbmtolps.c index 2c6b01a0..e1e057f8 100644 --- a/converter/pbm/pbmtolps.c +++ b/converter/pbm/pbmtolps.c @@ -69,9 +69,7 @@ parseCommandLine(int argc, and argv. Return the information in the options as *cmdlineP. -----------------------------------------------------------------------------*/ optEntry * option_def; /* malloc'ed */ - /* Instructions to OptParseOptions3 on how to parse our options. */ optStruct3 opt; - unsigned int option_def_index; MALLOCARRAY_NOFAIL(option_def, 100); @@ -86,7 +84,7 @@ parseCommandLine(int argc, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (cmdlineP->dpiSpec) diff --git a/converter/pbm/pbmtomacp.c b/converter/pbm/pbmtomacp.c index 5fa54ad6..0a6dcf93 100644 --- a/converter/pbm/pbmtomacp.c +++ b/converter/pbm/pbmtomacp.c @@ -73,7 +73,6 @@ parseCommandLine(int argc, and argv. Return the information in the options as *cmdlineP. -----------------------------------------------------------------------------*/ optEntry * option_def; /* malloc'ed */ - /* Instructions to OptParseOptions3 on how to parse our options. */ optStruct3 opt; unsigned int norleSpec; @@ -98,7 +97,7 @@ parseCommandLine(int argc, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ cmdlineP->norle = norleSpec; diff --git a/converter/pbm/pbmtomda.c b/converter/pbm/pbmtomda.c index 2ed862fc..f684276f 100644 --- a/converter/pbm/pbmtomda.c +++ b/converter/pbm/pbmtomda.c @@ -46,8 +46,6 @@ parseCommandLine(int argc, const char ** argv, was passed to as as the argv array. -----------------------------------------------------------------------------*/ optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ optStruct3 opt; unsigned int option_def_index; @@ -62,7 +60,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others */ if (argc-1 < 1) diff --git a/converter/pbm/pbmtoxbm.c b/converter/pbm/pbmtoxbm.c index 4bd33dd8..a452d6fa 100644 --- a/converter/pbm/pbmtoxbm.c +++ b/converter/pbm/pbmtoxbm.c @@ -61,8 +61,6 @@ parseCommandLine(int argc, was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. */ - optStruct3 opt; unsigned int option_def_index; unsigned int x10, x11, nameSpec; @@ -78,7 +76,7 @@ parseCommandLine(int argc, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (!nameSpec) diff --git a/converter/pbm/pi3topbm.c b/converter/pbm/pi3topbm.c index 82665f6c..36ff4127 100644 --- a/converter/pbm/pi3topbm.c +++ b/converter/pbm/pi3topbm.c @@ -56,7 +56,6 @@ parseCommandLine(int argc, --------------------------------------------------------------------------*/ optEntry * option_def; optStruct3 opt; - /* Instructions to pm_optParseOptions3 on how to parse our options. */ unsigned int option_def_index; MALLOCARRAY_NOFAIL(option_def, 100); @@ -68,7 +67,7 @@ parseCommandLine(int argc, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 < 1) diff --git a/converter/pbm/pktopbm.c b/converter/pbm/pktopbm.c index c45af082..201b046a 100644 --- a/converter/pbm/pktopbm.c +++ b/converter/pbm/pktopbm.c @@ -52,8 +52,6 @@ parseCommandLine(int argc, const char ** argv, was passed to us as the argv array. -----------------------------------------------------------------------------*/ optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ optStruct3 opt; unsigned int option_def_index; @@ -80,7 +78,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We may have parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (characterSpec) { diff --git a/converter/pgm/rawtopgm.c b/converter/pgm/rawtopgm.c index 7eb68694..a90bbf46 100644 --- a/converter/pgm/rawtopgm.c +++ b/converter/pgm/rawtopgm.c @@ -45,8 +45,6 @@ parseCommandLine(int argc, const char ** argv, was passed to us as the argv array. -----------------------------------------------------------------------------*/ optEntry * option_def; - /* Instructions to OptParseOptions3 on how to parse our options. - */ optStruct3 opt; unsigned int option_def_index; @@ -85,7 +83,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We may have parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 == 0) { diff --git a/converter/pgm/sbigtopgm.c b/converter/pgm/sbigtopgm.c index 8b28f740..c56d5eae 100644 --- a/converter/pgm/sbigtopgm.c +++ b/converter/pgm/sbigtopgm.c @@ -46,8 +46,6 @@ parseCommandLine(int argc, const char ** argv, was passed to as as the argv array. -----------------------------------------------------------------------------*/ optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ optStruct3 opt; unsigned int option_def_index; @@ -60,7 +58,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others */ if (argc-1 < 1) diff --git a/converter/ppm/411toppm.c b/converter/ppm/411toppm.c index a50e5145..9d338fa7 100644 --- a/converter/ppm/411toppm.c +++ b/converter/ppm/411toppm.c @@ -86,8 +86,6 @@ parseCommandLine(int argc, const char ** argv, -----------------------------------------------------------------------------*/ optEntry * option_def; - /* Instructions to OptParseOptions2 on how to parse our options. - */ optStruct3 opt; unsigned int option_def_index; @@ -106,7 +104,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (cmdlineP->width <= 0) diff --git a/converter/ppm/pcxtoppm.c b/converter/ppm/pcxtoppm.c index 05e09d73..f06dd4e8 100644 --- a/converter/ppm/pcxtoppm.c +++ b/converter/ppm/pcxtoppm.c @@ -87,13 +87,13 @@ parseCommandLine(int argc, const char ** argv, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry *option_def = malloc( 100*sizeof( optEntry ) ); - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; optStruct3 opt; unsigned int option_def_index; + MALLOCARRAY_NOFAIL(option_def, 100); + option_def_index = 0; /* incremented by OPTENT3 */ OPTENT3(0, "stdpalette", OPT_FLAG, NULL, &cmdlineP->stdpalette, 0 ); @@ -101,10 +101,10 @@ parseCommandLine(int argc, const char ** argv, &cmdlineP->verbose, 0 ); opt.opt_table = option_def; - opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + opt.short_allowed = false; /* We have no short (old-fashioned) options */ + opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char**)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdline_p and others. */ if (argc-1 < 1) diff --git a/converter/ppm/picttoppm.c b/converter/ppm/picttoppm.c index 8ca553bd..fc73a92c 100644 --- a/converter/ppm/picttoppm.c +++ b/converter/ppm/picttoppm.c @@ -78,7 +78,6 @@ parseCommandLine(int argc, --------------------------------------------------------------------------*/ optEntry * option_def; optStruct3 opt; - /* Instructions to pm_optParseOptions3 on how to parse our options. */ unsigned int option_def_index; @@ -102,7 +101,7 @@ parseCommandLine(int argc, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (!fontdirSpec) diff --git a/converter/ppm/ppmtoarbtxt.c b/converter/ppm/ppmtoarbtxt.c index cb2c388b..a8d7a004 100644 --- a/converter/ppm/ppmtoarbtxt.c +++ b/converter/ppm/ppmtoarbtxt.c @@ -62,8 +62,6 @@ parseCommandLine(int argc, const char ** argv, in argv! -----------------------------------------------------------------------------*/ optEntry * option_def; - /* Instructions to OptParseOptions3 on how to parse our options. - */ optStruct3 opt; unsigned int hdSpec, tlSpec; @@ -84,7 +82,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); free(option_def); if (!hdSpec) diff --git a/converter/ppm/ppmtoascii.c b/converter/ppm/ppmtoascii.c index 524bcd2c..b7c6669d 100644 --- a/converter/ppm/ppmtoascii.c +++ b/converter/ppm/ppmtoascii.c @@ -102,7 +102,6 @@ parseCommandLine(int argc, const char **argv, struct cmdlineInfo * const cmdlineP) { optEntry * option_def; - /* Instructions to OptParseOptions3 on how to parse our options */ optStruct3 opt; unsigned int option_def_index; @@ -118,7 +117,7 @@ parseCommandLine(int argc, const char **argv, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (dim1x2Spec && dim2x4Spec) diff --git a/converter/ppm/ppmtobmp.c b/converter/ppm/ppmtobmp.c index 8590c5ef..ed44b83a 100644 --- a/converter/ppm/ppmtobmp.c +++ b/converter/ppm/ppmtobmp.c @@ -17,6 +17,7 @@ #define _BSD_SOURCE 1 /* Make sure strdup() is in string.h */ #define _XOPEN_SOURCE 500 /* Make sure strdup() is in string.h */ +#include <stdbool.h> #include <assert.h> #include <string.h> @@ -87,8 +88,6 @@ parseCommandLine(int argc, const char ** argv, in argv! -----------------------------------------------------------------------------*/ optEntry * option_def; - /* Instructions to OptParseOptions3 on how to parse our options. - */ optStruct3 opt; unsigned int windowsSpec, os2Spec, mapfileSpec; @@ -106,10 +105,10 @@ parseCommandLine(int argc, const char ** argv, &mapfileSpec, 0); opt.opt_table = option_def; - opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + opt.short_allowed = false; /* We have no short (old-fashioned) options */ + opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); if (windowsSpec && os2Spec) pm_error("Can't specify both -windows and -os2 options."); diff --git a/converter/ppm/ppmtogif.c b/converter/ppm/ppmtogif.c index 0564b7b4..b50a934d 100644 --- a/converter/ppm/ppmtogif.c +++ b/converter/ppm/ppmtogif.c @@ -14,6 +14,7 @@ #define _BSD_SOURCE /* Make sure strdup() is in string.h */ #define _XOPEN_SOURCE 500 /* Make sure strdup() is in string.h */ +#include <stdbool.h> #include <assert.h> #include <string.h> #include <stdio.h> @@ -144,10 +145,10 @@ parseCommandLine(int argc, const char ** argv, */ opt.opt_table = option_def; - opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + opt.short_allowed = false; /* We have no short (old-fashioned) options */ + opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (latex2htmlhack) diff --git a/converter/ppm/ppmtoicr.c b/converter/ppm/ppmtoicr.c index de21fc68..2c9fd3a1 100644 --- a/converter/ppm/ppmtoicr.c +++ b/converter/ppm/ppmtoicr.c @@ -50,9 +50,7 @@ parseCommandLine(int argc, const char ** argv, Note that the file spec array we return is stored in the storage that was passed to us as the argv array. -----------------------------------------------------------------------------*/ - optEntry *option_def; - /* Instructions to OptParseOptions3 on how to parse our options. - */ + optEntry * option_def; optStruct3 opt; unsigned int option_def_index; @@ -75,10 +73,10 @@ parseCommandLine(int argc, const char ** argv, &rleSpec, 0); opt.opt_table = option_def; - opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* We may have parms that are negative numbers */ + opt.short_allowed = false; /* We have no short (old-fashioned) options */ + opt.allowNegNum = false; /* We may have parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (!expandSpec) diff --git a/converter/ppm/ppmtopcx.c b/converter/ppm/ppmtopcx.c index 5b7e1003..68ad4db0 100644 --- a/converter/ppm/ppmtopcx.c +++ b/converter/ppm/ppmtopcx.c @@ -17,6 +17,7 @@ ** http://bespin.org/~qz/pc-gpe/pcx.txt ** http://web.archive.org/web/20100206055706/http://www.qzx.com/pc-gpe/pcx.txt */ +#include <stdbool.h> #include <assert.h> #include "pm_c_util.h" @@ -83,8 +84,6 @@ parseCommandLine(int argc, const char ** argv, was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ optStruct3 opt; unsigned int option_def_index; @@ -112,10 +111,10 @@ parseCommandLine(int argc, const char ** argv, OPTENT3(0, "ypos", OPT_INT, &cmdlineP->ypos, &yposSpec, 0); opt.opt_table = option_def; - opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + opt.short_allowed = false; /* We have no short (old-fashioned) options */ + opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3( &argc, (char **)argv, opt, sizeof(opt), 0 ); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0 ); /* Uses and sets argc, argv, and some of *cmdline_p and others. */ if (!xposSpec) diff --git a/converter/ppm/ppmtosixel.c b/converter/ppm/ppmtosixel.c index 4fdf6a66..24454214 100644 --- a/converter/ppm/ppmtosixel.c +++ b/converter/ppm/ppmtosixel.c @@ -102,7 +102,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = false; /* We have no short (old-fashioned) options */ opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ cmdlineP->charWidth = opt7Bit ? CHARWIDTH_7BIT : CHARWIDTH_8BIT; diff --git a/converter/ppm/ppmtospu.c b/converter/ppm/ppmtospu.c index df0fb970..4ba70f02 100644 --- a/converter/ppm/ppmtospu.c +++ b/converter/ppm/ppmtospu.c @@ -5,6 +5,7 @@ * Copyright (C) 1990, Steve Belczyk */ +#include <stdbool.h> #include <assert.h> #include <stdio.h> @@ -56,10 +57,10 @@ parseCommandLine(int argc, const char ** argv, NULL, &d4Spec, 0); opt.opt_table = option_def; - opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + opt.short_allowed = false; /* We have no short (old-fashioned) options */ + opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ diff --git a/converter/ppm/ppmtoterm.c b/converter/ppm/ppmtoterm.c index 6e41a8cb..b1d94fa2 100644 --- a/converter/ppm/ppmtoterm.c +++ b/converter/ppm/ppmtoterm.c @@ -19,6 +19,7 @@ ** */ +#include <stdbool.h> #include <assert.h> #include <string.h> @@ -43,7 +44,6 @@ parseCommandLine(int argc, const char ** argv, struct cmdlineInfo * const cmdlineP) { optEntry * option_def; - /* Instructions to OptParseOptions3 on how to parse our options */ optStruct3 opt; unsigned int option_def_index; @@ -54,10 +54,10 @@ parseCommandLine(int argc, const char ** argv, OPTENT3(0, "verbose", OPT_FLAG, NULL, &cmdlineP->verbose, 0); opt.opt_table = option_def; - opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + opt.short_allowed = false; /* We have no short (old-fashioned) options */ + opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 < 1) diff --git a/converter/ppm/ppmtowinicon.c b/converter/ppm/ppmtowinicon.c index bd478b1e..2d8ddaf7 100644 --- a/converter/ppm/ppmtowinicon.c +++ b/converter/ppm/ppmtowinicon.c @@ -10,6 +10,7 @@ ** implied warranty. */ +#include <stdbool.h> #include <assert.h> #include <math.h> #include <string.h> @@ -57,9 +58,7 @@ parseCommandLine(int argc, Note that the strings we return are stored in the storage that was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ - optEntry *option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ + optEntry * option_def; optStruct3 opt; unsigned int option_def_index; @@ -79,10 +78,10 @@ parseCommandLine(int argc, &cmdlineP->verbose, 0); opt.opt_table = option_def; - opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + opt.short_allowed = false; /* We have no short (old-fashioned) options */ + opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (!outputSpec) @@ -272,14 +271,14 @@ fillInRaster1(u1 ** const rowData, for (row = 0; row <rows; ++row) { u1 * thisRow; /* malloc'ed */ - unsigned int byteOn; - unsigned int bitOn; + unsigned int byteSeq; + unsigned int bitOnMask; MALLOCARRAY_NOFAIL(thisRow, xByteCt); - memset (thisRow, 0, xByteCt); + memset(thisRow, 0, xByteCt); /* initial value */ rowData[rows - row - 1] = thisRow; - byteOn = 0; /* initial value */ - bitOn = 128; /* initial value */ + byteSeq = 0; /* initial value */ + bitOnMask = 0x80; /* initial value */ if (pa) { unsigned int col; @@ -291,16 +290,19 @@ fillInRaster1(u1 ** const rowData, Unless the hashing function changes, 0's black. */ int const value = ppm_lookupcolor(cht, &pa[row][col]); + + assert(byteSeq < xByteCt); + if (!value) { /* leave black. */ } else { - thisRow[byteOn] |= bitOn; + thisRow[byteSeq] |= bitOnMask; } - if (bitOn == 1) { - ++byteOn; - bitOn = 128; + if (bitOnMask == 0x1) { + ++byteSeq; + bitOnMask = 0x80; } else { - bitOn >>= 1; + bitOnMask >>= 1; } } } else { @@ -323,15 +325,15 @@ fillInRaster4(u1 ** const rowData, for (row = 0; row < rows; ++row) { u1 * thisRow; - unsigned int byteOn; - unsigned int nibble; /* high nibble = 1, low nibble = 0; */ + unsigned int byteSeq; + unsigned int nibbleSig; /* high nibble = 1, low nibble = 0; */ MALLOCARRAY_NOFAIL(thisRow, xByteCt); memset(thisRow, 0, xByteCt); rowData[rows - row - 1] = thisRow; - byteOn = 0; /* initial value */ - nibble = 1; /* initial value */ + byteSeq = 0; /* initial value */ + nibbleSig = 1; /* initial value */ if (pa) { unsigned int col; @@ -339,16 +341,18 @@ fillInRaster4(u1 ** const rowData, for (col = 0; col < cols; ++col) { int value; + assert(byteSeq < xByteCt); + value = ppm_lookupcolor(cht, &pa[row][col]); /* init value */ /* Shift it, if we're putting it in the high nibble. */ - if (nibble) + if (nibbleSig == 1) value <<= 4; - thisRow[byteOn] |= value; - if (nibble == 1) - nibble = 0; + thisRow[byteSeq] |= value; + if (nibbleSig == 1) + nibbleSig = 0; else { - nibble = 1; - ++byteOn; + nibbleSig = 1; + ++byteSeq; } } } else { @@ -372,8 +376,10 @@ fillInRaster8(u1 ** const rowData, for (row = 0; row < rows; ++row) { u1 * thisRow; /* malloc'ed */ + assert(cols <= xByteCt); + MALLOCARRAY_NOFAIL(thisRow, xByteCt); - memset (thisRow, 0, xByteCt); + memset(thisRow, 0, xByteCt); rowData[rows - row - 1] = thisRow; if (pa) { unsigned int col; diff --git a/converter/ppm/ppmtoxpm.c b/converter/ppm/ppmtoxpm.c index 2167acb2..4a3336b0 100644 --- a/converter/ppm/ppmtoxpm.c +++ b/converter/ppm/ppmtoxpm.c @@ -97,9 +97,7 @@ parseCommandLine(int argc, const char ** argv, Note that the file spec array we return is stored in the storage that was passed to us as the argv array. -----------------------------------------------------------------------------*/ - optEntry *option_def; - /* Instructions to OptParseOptions3 on how to parse our options. - */ + optEntry * option_def; optStruct3 opt; unsigned int option_def_index; @@ -125,10 +123,10 @@ parseCommandLine(int argc, const char ** argv, cmdlineP->rgb = NULL; /* no rgb file specified */ opt.opt_table = option_def; - opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* We may have parms that are negative numbers */ + opt.short_allowed = false; /* We have no short (old-fashioned) options */ + opt.allowNegNum = false; /* We may have parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 == 0) diff --git a/converter/ppm/winicontoppm.c b/converter/ppm/winicontoppm.c index 54bc0809..f7847df5 100644 --- a/converter/ppm/winicontoppm.c +++ b/converter/ppm/winicontoppm.c @@ -18,6 +18,7 @@ #define _BSD_SOURCE 1 /* Make sure strdup() is in string.h */ #define _XOPEN_SOURCE 500 /* Make sure strdup() is in string.h */ +#include <stdbool.h> #include <math.h> #include <string.h> #include <assert.h> @@ -66,8 +67,6 @@ parseCommandLine (int argc, const char ** argv, was passed to us as the argv array. We also trash *argv. -----------------------------------------------------------------------------*/ optEntry * option_def; - /* Instructions to pm_optParseOptions3 on how to parse our options. - */ optStruct3 opt; unsigned int option_def_index; @@ -87,10 +86,10 @@ parseCommandLine (int argc, const char ** argv, &cmdlineP->verbose, 0 ); opt.opt_table = option_def; - opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + opt.short_allowed = false; /* We have no short (old-fashioned) options */ + opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 < 1) diff --git a/converter/ppm/ximtoppm.c b/converter/ppm/ximtoppm.c index b82463c3..c5ba7e80 100644 --- a/converter/ppm/ximtoppm.c +++ b/converter/ppm/ximtoppm.c @@ -57,10 +57,10 @@ parseCommandLine(int argc, const char ** argv, &cmdlineP->alphaFilename, &alphaoutSpec, 0); opt.opt_table = option_def; - opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ - opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ + opt.short_allowed = false; /* We have no short (old-fashioned) options */ + opt.allowNegNum = false; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char**)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and all of *cmdlineP. */ if (!alphaoutSpec) diff --git a/converter/ppm/yuvtoppm.c b/converter/ppm/yuvtoppm.c index 87f541e5..5ee250e2 100644 --- a/converter/ppm/yuvtoppm.c +++ b/converter/ppm/yuvtoppm.c @@ -43,7 +43,6 @@ parseCommandLine(int argc, const char ** argv, struct CmdlineInfo * const cmdlineP) { optEntry * option_def; - /* Instructions to OptParseOptions3 on how to parse our options */ optStruct3 opt; unsigned int option_def_index; @@ -55,7 +54,7 @@ parseCommandLine(int argc, const char ** argv, opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ opt.allowNegNum = FALSE; /* We have no parms that are negative numbers */ - pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + pm_optParseOptions4(&argc, argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ if (argc-1 < 2) |