about summary refs log tree commit diff
path: root/converter/other/pamtotga.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-11-03 23:56:33 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-11-03 23:56:33 +0000
commite57c025f5a698fdd2b01175da5ff0cd50709bbd5 (patch)
tree55675d1acfb728957a51c56e0b3f7c7ce6f3bf49 /converter/other/pamtotga.c
parent87769289405a9aed9d4e93b903489b64d77ac411 (diff)
downloadnetpbm-mirror-e57c025f5a698fdd2b01175da5ff0cd50709bbd5.tar.gz
netpbm-mirror-e57c025f5a698fdd2b01175da5ff0cd50709bbd5.tar.xz
netpbm-mirror-e57c025f5a698fdd2b01175da5ff0cd50709bbd5.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3415 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/pamtotga.c')
-rw-r--r--converter/other/pamtotga.c48
1 files changed, 25 insertions, 23 deletions
diff --git a/converter/other/pamtotga.c b/converter/other/pamtotga.c
index 548da1f1..4b4cfb98 100644
--- a/converter/other/pamtotga.c
+++ b/converter/other/pamtotga.c
@@ -14,6 +14,7 @@
 #define _BSD_SOURCE  /* Make sure string.h contains strdup() */
 #define _XOPEN_SOURCE 500  /* Make sure strdup() is in string.h */
 
+#include <assert.h>
 #include <string.h>
 
 #include "pm_c_util.h"
@@ -27,12 +28,12 @@
 /* Max number of colors allowed for colormapped output. */
 #define MAXCOLORS 256
 
-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;  /* Filespec of input file */
-    char *outName;
+    const char * inputFileName;
+    const char * outName;
     enum TGAbaseImageType imgType;
     bool defaultFormat;
     unsigned int norle;
@@ -41,8 +42,8 @@ struct cmdlineInfo {
 
 
 static void
-parseCommandLine(int argc, char ** argv,
-                 struct cmdlineInfo * const cmdlineP) {
+parseCommandLine(int argc, const char ** argv,
+                 struct CmdlineInfo * const cmdlineP) {
 /*----------------------------------------------------------------------------
    Parse the program arguments (given by argc and argv) into a form
    the program can deal with more easily -- a cmdline_info structure.
@@ -75,7 +76,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_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0);
         /* Uses and sets argc, argv, and some of *cmdline_p and others. */
 
     if (cmap + mono + rgb > 1)
@@ -98,12 +99,12 @@ parseCommandLine(int argc, char ** argv,
         cmdlineP->outName = NULL;
 
     if (argc-1 == 0)
-        cmdlineP->inputFilespec = "-";
+        cmdlineP->inputFileName = "-";
     else if (argc-1 != 1)
         pm_error("Program takes zero or one argument (filename).  You "
                  "specified %d", argc-1);
     else
-        cmdlineP->inputFilespec = argv[1];
+        cmdlineP->inputFileName = argv[1];
 
 }
 
@@ -215,7 +216,8 @@ putMapEntry(struct pam * const pamP,
         putchar(pnm_scalesample(value[0],
                                 pamP->maxval, TGA_MAXVAL));
     else {
-        /* Must be 24 or 32 */
+        assert(size == 24 || size == 32);
+
         putchar(pnm_scalesample(value[PAM_BLU_PLANE],
                                 pamP->maxval, TGA_MAXVAL));
         putchar(pnm_scalesample(value[PAM_GRN_PLANE],
@@ -271,18 +273,18 @@ computeRunlengths(struct pam * const pamP,
 
 
 static void
-computeOutName(struct cmdlineInfo const cmdline,
+computeOutName(struct CmdlineInfo const cmdline,
                const char **      const outNameP) {
 
     char * workarea;
 
     if (cmdline.outName)
         workarea = strdup(cmdline.outName);
-    else if (streq(cmdline.inputFilespec, "-"))
+    else if (streq(cmdline.inputFileName, "-"))
         workarea = NULL;
     else {
         char * cp;
-        workarea = strdup(cmdline.inputFilespec);
+        workarea = strdup(cmdline.inputFileName);
         cp = strchr(workarea, '.');
         if (cp != NULL)
         	*cp = '\0';	/* remove extension */
@@ -325,7 +327,7 @@ validateTupleType(struct pam * const pamP) {
 
 static void
 computeImageType_cht(struct pam *            const pamP,
-                     struct cmdlineInfo      const cmdline,
+                     struct CmdlineInfo      const cmdline,
                      tuple **                const tuples,
                      enum TGAbaseImageType * const baseImgTypeP,
                      bool *                  const withAlphaP,
@@ -519,25 +521,25 @@ writeTgaRaster(struct pam *          const pamP,
 
 
 int
-main(int argc, char *argv[]) {
+main(int argc, const char **argv) {
 
-    struct cmdlineInfo cmdline;
+    struct CmdlineInfo cmdline;
     FILE * ifP;
     tuple ** tuples;
     struct pam pam;
-    int ncolors;
+    int colorCt;
     tupletable chv;
     tuplehash cht;
     struct ImageHeader tgaHeader;
     enum TGAbaseImageType baseImgType;
     bool withAlpha;
-    const char *outName;
+    const char * outName;
 
-    pnm_init( &argc, argv );
+    pm_proginit(&argc, argv);
 
     parseCommandLine(argc, argv, &cmdline);
 
-    ifP = pm_openr(cmdline.inputFilespec);
+    ifP = pm_openr(cmdline.inputFileName);
 
     computeOutName(cmdline, &outName);
 
@@ -545,17 +547,17 @@ main(int argc, char *argv[]) {
     pm_close(ifP);
 
     computeImageType_cht(&pam, cmdline, tuples,
-                         &baseImgType, &withAlpha, &chv, &cht, &ncolors);
+                         &baseImgType, &withAlpha, &chv, &cht, &colorCt);
 
     /* Do the Targa header */
     computeTgaHeader(&pam, baseImgType, withAlpha, !cmdline.norle,
-                     ncolors, 0, outName, &tgaHeader);
+                     colorCt, 0, outName, &tgaHeader);
     writeTgaHeader(tgaHeader);
 
     if (baseImgType == TGA_MAP_TYPE) {
         /* Write out the Targa colormap. */
-        int i;
-        for (i = 0; i < ncolors; ++i)
+        unsigned int i;
+        for (i = 0; i < colorCt; ++i)
             putMapEntry(&pam, chv[i]->tuple, tgaHeader.CoSize);
     }