diff options
Diffstat (limited to 'converter')
32 files changed, 244 insertions, 150 deletions
diff --git a/converter/other/infotopam.c b/converter/other/infotopam.c index bb7d2e74..e9ce4d04 100644 --- a/converter/other/infotopam.c +++ b/converter/other/infotopam.c @@ -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 @@ -72,9 +191,10 @@ #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" typedef struct CmdlineInfo_ { @@ -101,7 +221,11 @@ typedef struct IconInfo_ { typedef struct IconHeader_ { /* 20 bytes */ /* Text of header for one icon image */ - unsigned char pad0[4]; /* Padding (always seems to be zero) */ + 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) */ @@ -282,16 +406,28 @@ readIconHeader(FILE * const ifP, "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]); + } + *widthP = (ihead.iconWidth[0] << 8) + ihead.iconWidth[1]; *heightP = (ihead.iconHeight[0] << 8) + ihead.iconHeight[1]; *depthP = (ihead.bpp[0] << 8) + ihead.bpp[1]; - *bpwidthP = ROUNDUP(*widthP, 16); + 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); - /* Validate number of bit planes */ if (*depthP > 2 || *depthP < 1) pm_error("We don't know how to interpret file with %u bitplanes. ", *depthP); + + *bpwidthP = ROUNDUP(*widthP, 16); } 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 69baa2f6..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) diff --git a/converter/ppm/ppmtoxpm.c b/converter/ppm/ppmtoxpm.c index 2167acb2..9cbab8f3 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) @@ -271,8 +269,7 @@ static void genCmap(colorhist_vector const chv, unsigned int const ncolors, pixval const maxval, - colorhash_table const colornameHash, - const char ** const colornames, + ppm_ColorDict * const colorDictP, bool const includeTransparent, CixelMap ** const cmapP, unsigned int * const transIndexP, @@ -290,14 +287,10 @@ genCmap(colorhist_vector const chv, This map includes an entry for transparency, whether the raster uses it or not. We return its index as *transIndexP. - In the map, identify colors by the names given by 'colornameHash' and - colornames[]. 'colornameHash' maps a color in 'pixel' form to an - index into colornames[]; colornames[] contains the text to identify the - color in the XPM format. The colors in 'colornameHash' have maxval 255. - If a color is not in 'colornameHash', use hexadecimal notation in the - output colormap. + In the map, identify colors by the names given by *colorDictP. If a color + is not in *colorDictP, use hexadecimal notation in the output colormap. - But if 'colornameHash' is null, don't use color names at all. Just use + But if *colorDictP is null, don't use color names at all. Just use hexadecimal notation. Return as *charsPerPixel the number of characters, or digits, that @@ -338,13 +331,13 @@ genCmap(colorhist_vector const chv, PPM_DEPTH(color255, color, maxval, 255); - if (colornameHash == NULL) + if (!colorDictP) colorname = NULL; else { int colornameIndex; - colornameIndex = ppm_lookupcolor(colornameHash, &color255); + colornameIndex = ppm_lookupcolor(colorDictP->cht, &color255); if (colornameIndex >= 0) - colorname = strdup(colornames[colornameIndex]); + colorname = strdup(colorDictP->name[colornameIndex]); else colorname = NULL; } @@ -537,7 +530,7 @@ computecolorhash(pixel ** const pixels, ++ncolors; } } else - *transparentSomewhereP = TRUE; + *transparentSomewhereP = true; } } *chtP = cht; @@ -599,12 +592,7 @@ main(int argc, const char * *argv) { colorhash_table cht; colorhist_vector chv; - colorhash_table colornameHash; - /* Hash table to map colors to their names */ - const char ** colornames; - /* Table of color names; 'colornameHash' yields an index into this - array. - */ + ppm_ColorDict * colorDictP; /* The color name dictionary we use */ pixel ** pixels; gray ** alpha; @@ -638,28 +626,26 @@ main(int argc, const char * *argv) { &chv, &cht, &ncolors, &transparentSomewhere); if (cmdline.hexonly) - colornameHash = NULL; + colorDictP = NULL; else if (cmdline.rgb) - ppm_readcolornamefile(cmdline.rgb, TRUE, &colornameHash, &colornames); + colorDictP = ppm_colorDict_new(cmdline.rgb, true); else - ppm_readcolornamefile(NULL, FALSE, &colornameHash, &colornames); + colorDictP = ppm_colorDict_new(NULL, false); /* Now generate the character-pixel colormap table. */ - genCmap(chv, ncolors, maxval, - colornameHash, colornames, transparentSomewhere, + genCmap(chv, ncolors, maxval, colorDictP, transparentSomewhere, &cmap, &transIndex, &cmapSize, &charsPerPixel); writeXpmFile(stdout, pixels, alpha, alphaMaxval, cmdline.name, cols, rows, cmapSize, charsPerPixel, cmap, cht, transIndex); - if (colornameHash) { - ppm_freecolorhash(colornameHash); - ppm_freecolornames(colornames); - } + if (colorDictP) + ppm_colorDict_destroy(colorDictP); destroyCmap(cmap, cmapSize); ppm_freearray(pixels, rows); - if (alpha) pgm_freearray(alpha, rows); + if (alpha) + pgm_freearray(alpha, rows); return 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) |