about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-09-21 02:46:51 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-09-21 02:46:51 +0000
commit0707fc7baff7a84cc5482acc4f845cc8841112cd (patch)
treec2e43ca5112dde4d8c24016740a17805c2234750
parent6ed02eab7700594cdd1aeb6baba06297caa536f7 (diff)
downloadnetpbm-mirror-0707fc7baff7a84cc5482acc4f845cc8841112cd.tar.gz
netpbm-mirror-0707fc7baff7a84cc5482acc4f845cc8841112cd.tar.xz
netpbm-mirror-0707fc7baff7a84cc5482acc4f845cc8841112cd.zip
Convert to modern optParseOptions3
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1294 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/ppm/411toppm.c48
-rw-r--r--converter/ppm/xpmtoppm.c52
2 files changed, 53 insertions, 47 deletions
diff --git a/converter/ppm/411toppm.c b/converter/ppm/411toppm.c
index 6ece4c4b..126553a8 100644
--- a/converter/ppm/411toppm.c
+++ b/converter/ppm/411toppm.c
@@ -59,19 +59,19 @@
 #include <stdlib.h>
 
 #include "pm_c_util.h"
-#include "ppm.h"
-#include "shhopt.h"
 #include "mallocvar.h"
+#include "shhopt.h"
+#include "ppm.h"
 
 typedef unsigned char uint8;
 
 #define CHOP(x)     ((x < 0) ? 0 : ((x > 255) ? 255 : x))
 
-struct cmdline_info {
+struct cmdlineInfo {
     /* All the information the user supplied in the command line,
        in a form easy for the program to use.
     */
-    const char *input_filespec;  /* Filespec of input file */
+    const char * inputFileName;
     int width;
     int height;
 };
@@ -79,38 +79,40 @@ struct cmdline_info {
 
 
 static void
-parse_command_line(int argc, char ** argv,
-                   struct cmdline_info *cmdline_p) {
+parseCommandLine(int argc, char ** argv,
+                 struct cmdlineInfo *cmdlineP) {
 /*----------------------------------------------------------------------------
    Note that the file spec array we return is stored in the storage that
    was passed to us as the argv array.
 -----------------------------------------------------------------------------*/
 
-    optStruct *option_def = malloc(100*sizeof(optStruct));
+    optEntry * option_def;
         /* Instructions to OptParseOptions2 on how to parse our options.
          */
-    optStruct2 opt;
+    optStruct3 opt;
 
     unsigned int option_def_index;
 
-    option_def_index = 0;   /* incremented by OPTENTRY */
-    OPTENTRY(0,   "width",      OPT_INT,    &cmdline_p->width,          0);
-    OPTENTRY(0,   "height",     OPT_INT,    &cmdline_p->height,         0);
+    MALLOCARRAY_NOFAIL(option_def, 100);
+
+    option_def_index = 0;   /* incremented by OPTENT3 */
+    OPTENT3(0,   "width",      OPT_INT,    &cmdlineP->width,  NULL,   0);
+    OPTENT3(0,   "height",     OPT_INT,    &cmdlineP->height, NULL,   0);
 
     /* Set the defaults */
-    cmdline_p->width = 64;
-    cmdline_p->height = 48;
+    cmdlineP->width = 64;
+    cmdlineP->height = 48;
 
     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 */
     
-    optParseOptions2(&argc, argv, opt, 0);
-        /* Uses and sets argc, argv, and some of *cmdline_p and others. */
+    optParseOptions3(&argc, argv, opt, sizeof(opt), 0);
+        /* Uses and sets argc, argv, and some of *cmdlineP and others. */
 
-    if (cmdline_p->width <= 0)
+    if (cmdlineP->width <= 0)
         pm_error("-width must be positive.");
-    if (cmdline_p->height <= 0)
+    if (cmdlineP->height <= 0)
         pm_error("-height must be positive.");
 
     if (argc > 2)
@@ -118,9 +120,9 @@ parse_command_line(int argc, char ** argv,
                  "You supplied %d", argc-1);
     else {
         if (argc > 1)
-            cmdline_p->input_filespec = argv[1];
+            cmdlineP->inputFileName = argv[1];
         else
-            cmdline_p->input_filespec = "-";
+            cmdlineP->inputFileName = "-";
     }
 }
 
@@ -233,20 +235,20 @@ YUVtoPPM(const int width, const int height,
 int
 main(int argc, char **argv) {
     FILE *infile;
-    struct cmdline_info cmdline;
+    struct cmdlineInfo cmdline;
     uint8 **orig_y, **orig_cb, **orig_cr;
     pixel **ppm_image;
 
     ppm_init(&argc, argv);
 
-    parse_command_line(argc, argv, &cmdline);
+    parseCommandLine(argc, argv, &cmdline);
 
     AllocYCC(cmdline.width, cmdline.height, &orig_y, &orig_cr, &orig_cb);
     ppm_image = ppm_allocarray(cmdline.width, cmdline.height);
 
     pm_message("Reading (%dx%d):  %s\n", cmdline.width, cmdline.height, 
-               cmdline.input_filespec);
-    infile = pm_openr(cmdline.input_filespec);
+               cmdline.inputFileName);
+    infile = pm_openr(cmdline.inputFileName);
     ReadYUV(infile, cmdline.width, cmdline.height, orig_y, orig_cb, orig_cr);
     pm_close(infile);
 
diff --git a/converter/ppm/xpmtoppm.c b/converter/ppm/xpmtoppm.c
index b13f2cad..5f5e6b59 100644
--- a/converter/ppm/xpmtoppm.c
+++ b/converter/ppm/xpmtoppm.c
@@ -35,10 +35,10 @@
 #include <string.h>
 
 #include "pm_c_util.h"
-#include "ppm.h"
+#include "mallocvar.h"
 #include "shhopt.h"
 #include "nstring.h"
-#include "mallocvar.h"
+#include "ppm.h"
 
 #define MAX_LINE (8 * 1024)
   /* The maximum size XPM input line we can handle. */
@@ -55,12 +55,12 @@ const char *xpmColorKeys[] =
  "c",					/* key #5: color visual */
 };
 
-struct cmdline_info {
+struct cmdlineInfo {
     /* All the information the user supplied in the command line,
        in a form easy for the program to use.
     */
-    char *input_filespec;  /* Filespecs of input files */
-    char *alpha_filename;
+    const char * input_filespec;  /* Filespecs of input files */
+    const char * alpha_filename;
     int alpha_stdout;
     int verbose;
 };
@@ -70,46 +70,50 @@ static int verbose;
 
 
 static void
-parse_command_line(int argc, char ** argv,
-                   struct cmdline_info *cmdline_p) {
+parseCommandLine(int argc, char ** argv,
+                 struct cmdlineInfo *cmdlineP) {
 /*----------------------------------------------------------------------------
    Note that the file spec array we return is stored in the storage that
    was passed to us as the argv array.
 -----------------------------------------------------------------------------*/
-    optStruct *option_def = malloc(100*sizeof(optStruct));
+    optEntry * option_def;
         /* Instructions to OptParseOptions2 on how to parse our options.
          */
-    optStruct2 opt;
+    optStruct3 opt;
 
     unsigned int option_def_index;
 
-    option_def_index = 0;   /* incremented by OPTENTRY */
-    OPTENTRY(0,   "alphaout",   OPT_STRING, &cmdline_p->alpha_filename, 0);
-    OPTENTRY(0,   "verbose",    OPT_FLAG,   &cmdline_p->verbose,        0);
+    MALLOCARRAY_NOFAIL(option_def, 100);
+
+    option_def_index = 0;   /* incremented by OPTENT3 */
+    OPTENT3(0,   "alphaout",   OPT_STRING, &cmdlineP->alpha_filename,
+            NULL, 0);
+    OPTENT3(0,   "verbose",    OPT_FLAG,   &cmdlineP->verbose,
+            NULL, 0);
 
-    cmdline_p->alpha_filename = NULL;
-    cmdline_p->verbose = FALSE;
+    cmdlineP->alpha_filename = NULL;
+    cmdlineP->verbose = FALSE;
 
     opt.opt_table = option_def;
     opt.short_allowed = FALSE;  /* We have no short (old-fashioned) options */
     opt.allowNegNum = TRUE;  /* We may have parms that are negative numbers */
 
-    optParseOptions2(&argc, argv, opt, 0);
-        /* Uses and sets argc, argv, and some of *cmdline_p and others. */
+    optParseOptions3(&argc, argv, opt, sizeof(opt), 0);
+        /* Uses and sets argc, argv, and some of *cmdlineP and others. */
 
     if (argc - 1 == 0)
-        cmdline_p->input_filespec = NULL;  /* he wants stdin */
+        cmdlineP->input_filespec = NULL;  /* he wants stdin */
     else if (argc - 1 == 1)
-        cmdline_p->input_filespec = strdup(argv[1]);
+        cmdlineP->input_filespec = strdup(argv[1]);
     else 
         pm_error("Too many arguments.  The only argument accepted\n"
                  "is the input file specification");
 
-    if (cmdline_p->alpha_filename && 
-        streq(cmdline_p->alpha_filename, "-"))
-        cmdline_p->alpha_stdout = TRUE;
+    if (cmdlineP->alpha_filename && 
+        streq(cmdlineP->alpha_filename, "-"))
+        cmdlineP->alpha_stdout = TRUE;
     else 
-        cmdline_p->alpha_stdout = FALSE;
+        cmdlineP->alpha_stdout = FALSE;
 
 }
 
@@ -848,11 +852,11 @@ main(int argc, char *argv[]) {
            being an index int colormap[].
         */
 
-    struct cmdline_info cmdline;
+    struct cmdlineInfo cmdline;
 
     ppm_init(&argc, argv);
 
-    parse_command_line(argc, argv, &cmdline);
+    parseCommandLine(argc, argv, &cmdline);
 
     verbose = cmdline.verbose;