about summary refs log tree commit diff
path: root/converter/pbm/pbmtoepsi.c
diff options
context:
space:
mode:
Diffstat (limited to 'converter/pbm/pbmtoepsi.c')
-rw-r--r--converter/pbm/pbmtoepsi.c62
1 files changed, 33 insertions, 29 deletions
diff --git a/converter/pbm/pbmtoepsi.c b/converter/pbm/pbmtoepsi.c
index 87985a1f..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 */
@@ -45,7 +46,7 @@ struct cmdlineInfo {
 
 
 static void
-parseDpi(char *         const dpiOpt, 
+parseDpi(char *         const dpiOpt,
          unsigned int * const dpiXP,
          unsigned int * const dpiYP) {
 
@@ -53,7 +54,7 @@ parseDpi(char *         const dpiOpt,
     unsigned int dpiX, dpiY;
 
     dpiX = strtol(dpiOpt, &dpistr2, 10);
-    if (dpistr2 == dpiOpt) 
+    if (dpistr2 == dpiOpt)
         pm_error("Invalid value for -dpi: '%s'.  Must be either number "
                  "or NxN ", dpiOpt);
     else {
@@ -64,7 +65,7 @@ parseDpi(char *         const dpiOpt,
             char * dpistr3;
 
             dpistr2++;  /* Move past 'x' */
-            dpiY = strtol(dpistr2, &dpistr3, 10);        
+            dpiY = strtol(dpistr2, &dpistr3, 10);
             if (dpistr3 != dpistr2 && *dpistr3 == '\0') {
                 *dpiXP = dpiX;
                 *dpiYP = dpiY;
@@ -77,23 +78,23 @@ 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);
@@ -103,19 +104,19 @@ 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. */
-    
+
 
     if (dpiOptSpec)
         parseDpi(dpiOpt, &cmdlineP->dpiX, &cmdlineP->dpiY);
     else
         cmdlineP->dpiX = cmdlineP->dpiY = 72;
-    
+
     if ((argc-1) > 1)
         pm_error("Too many arguments (%d).  Only argument is input file name",
                  argc-1);
-    
+
     if (argc-1 == 0)
         cmdlineP->inputFileName = "-";
     else
@@ -125,7 +126,7 @@ parseCommandLine(int argc, const char ** const argv,
 
 
 static void
-findPrincipalImage(bit **         const bits, 
+findPrincipalImage(bit **         const bits,
                    unsigned int   const rows,
                    unsigned int   const cols,
                    unsigned int * const topP,
@@ -151,25 +152,25 @@ findPrincipalImage(bit **         const bits,
     bottom = 0;
     left   = cols;
     right  = 0;
- 
+
     for (row = 0; row < rows; ++row) {
         unsigned int col;
         for (col = 0; col < cols; ++col) {
             if (bits[row][col] == PBM_BLACK) {
-                if (row < top) 
+                if (row < top)
                     top = row;
-                if (row > bottom) 
+                if (row > bottom)
                     bottom = row;
-                if (col < left) 
+                if (col < left)
                     left = col;
-                if (col > right) 
+                if (col > right)
                     right = col;
             }
         }
     }
 
     if (top > bottom) {
-        /* No black pixels encountered */ 
+        /* No black pixels encountered */
         pm_message("Blank page");
         top    = 0;
         left   = 0;
@@ -194,8 +195,8 @@ outputBoundingBox(int const top, int const bottom,
     float const xScale = 72.0 / dpiX;
     float const yScale = 72.0 / dpiY;
 
-    printf("%%%%BoundingBox: %d %d %d %d\n", 
-           ROUND(left*xScale),  ROUND((rows - bottom)*yScale), 
+    printf("%%%%BoundingBox: %d %d %d %d\n",
+           ROUND(left*xScale),  ROUND((rows - bottom)*yScale),
            ROUND(right*xScale), ROUND((rows - top)*yScale));
 }
 
@@ -234,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;
@@ -244,7 +245,7 @@ main(int argc, const char * argv[]) {
         */
 
     pm_proginit(&argc, argv);
-    
+
     parseCommandLine(argc, argv, &cmdline);
 
     ifP = pm_openr(cmdline.inputFileName);
@@ -255,12 +256,12 @@ main(int argc, const char * argv[]) {
 
     printf("%%!PS-Adobe-2.0 EPSF-1.2\n");
 
-    outputBoundingBox(top, bottom, left, right, rows, 
+    outputBoundingBox(top, bottom, left, right, rows,
                       cmdline.dpiX, cmdline.dpiY);
 
     if (!cmdline.bbonly) {
         int row;
-        printf("%%%%BeginPreview: %d %d 1 %d\n", 
+        printf("%%%%BeginPreview: %d %d 1 %d\n",
                right - left + 1, bottom - top + 1, bottom - top + 1);
 
         for (row = top; row <= bottom; row++) {
@@ -274,7 +275,7 @@ main(int argc, const char * argv[]) {
                 if (outChars == 72) {
                     printf("\n%% ");
                     outChars = 2;
-                }  
+                }
 
                 printf("%02x", eightPixels(bits, row, col, cols));
                 outChars += 2;
@@ -287,3 +288,6 @@ main(int argc, const char * argv[]) {
     }
     return 0;
 }
+
+
+