about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2013-07-24 22:18:59 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2013-07-24 22:18:59 +0000
commitd1cfc560073dbe5bfcaa412b4fea16d6831e743e (patch)
tree0e16bde705966132ed40a77001e1c95414f84306
parent6516daea481dab323982d3a2b2aa8baf6988829a (diff)
downloadnetpbm-mirror-d1cfc560073dbe5bfcaa412b4fea16d6831e743e.tar.gz
netpbm-mirror-d1cfc560073dbe5bfcaa412b4fea16d6831e743e.tar.xz
netpbm-mirror-d1cfc560073dbe5bfcaa412b4fea16d6831e743e.zip
cleanup - declare qsort comparison routines as such
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1980 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--analyzer/ppmhist.c16
-rw-r--r--converter/other/fiasco/codec/tiling.c70
-rw-r--r--converter/other/pnmtopalm/palm.h8
-rw-r--r--converter/other/pnmtopalm/palmcolormap.c8
-rw-r--r--converter/other/winicontopam.c4
-rw-r--r--converter/ppm/ppmtoilbm.c5
-rw-r--r--editor/pamsistoaglyph.c17
-rw-r--r--editor/ppmdist.c27
-rw-r--r--lib/libppmcmap.c45
9 files changed, 128 insertions, 72 deletions
diff --git a/analyzer/ppmhist.c b/analyzer/ppmhist.c
index 78e6d82a..321e4b3a 100644
--- a/analyzer/ppmhist.c
+++ b/analyzer/ppmhist.c
@@ -100,15 +100,29 @@ parseCommandLine(int argc, const char ** argv,
 
 
 
+#ifndef LITERAL_FN_DEF_MATCH
+static qsort_comparison_fn cmpfn;
+#endif
+
 static int
 countcompare(const void *ch1, const void *ch2) {
+/*----------------------------------------------------------------------------
+   This is a 'qsort' collation function.
+-----------------------------------------------------------------------------*/
     return ((colorhist_vector)ch2)->value - ((colorhist_vector)ch1)->value;
 }
 
 
+
+#ifndef LITERAL_FN_DEF_MATCH
+static qsort_comparison_fn cmpfn;
+#endif
+
 static int
 rgbcompare(const void * arg1, const void * arg2) {
-
+/*----------------------------------------------------------------------------
+   This is a 'qsort' collation function.
+-----------------------------------------------------------------------------*/
     colorhist_vector const ch1 = (colorhist_vector) arg1;
     colorhist_vector const ch2 = (colorhist_vector) arg2;
 
diff --git a/converter/other/fiasco/codec/tiling.c b/converter/other/fiasco/codec/tiling.c
index 83eb8b29..89fe3111 100644
--- a/converter/other/fiasco/codec/tiling.c
+++ b/converter/other/fiasco/codec/tiling.c
@@ -29,22 +29,7 @@
 #include "wfalib.h"
 #include "tiling.h"
 
-/*****************************************************************************
 
-				prototypes
-  
-*****************************************************************************/
-
-static int
-cmpdecvar (const void *value1, const void *value2);
-static int
-cmpincvar (const void *value1, const void *value2);
-
-/*****************************************************************************
-
-				public code
-  
-*****************************************************************************/
 
 typedef struct var_list
 {
@@ -52,6 +37,38 @@ typedef struct var_list
    real_t variance;			/* variance of tile */
 } var_list_t;
 
+#ifndef LITERAL_FN_DEF_MATCH
+static qsort_comparison_fn cmpincvar;
+#endif
+
+static int
+cmpincvar(const void * const value1,
+          const void * const value2) {
+/*----------------------------------------------------------------------------
+  Sorts by increasing variances (quicksort sorting function)
+-----------------------------------------------------------------------------*/
+    return
+        ((var_list_t *) value1)->variance - ((var_list_t *) value2)->variance;
+}
+
+
+
+#ifndef LITERAL_FN_DEF_MATCH
+static qsort_comparison_fn cmpdecvar;
+#endif
+
+static int
+cmpdecvar(const void * const value1,
+          const void * const value2) {
+/*----------------------------------------------------------------------------
+  Sorts by decreasing variances (quicksort sorting function).
+-----------------------------------------------------------------------------*/
+    return
+        ((var_list_t *) value2)->variance - ((var_list_t *) value1)->variance;
+}
+
+
+
 tiling_t *
 alloc_tiling (fiasco_tiling_e method, unsigned tiling_exponent,
 	      unsigned image_level)
@@ -214,26 +231,3 @@ perform_tiling (const image_t *image, tiling_t *tiling)
    }
 }
 
-/*****************************************************************************
-
-				private code
-  
-*****************************************************************************/
-
-static int
-cmpincvar (const void *value1, const void *value2)
-/*
- *  Sorts by increasing variances (quicksort sorting function).
- */
-{
-  return ((var_list_t *) value1)->variance - ((var_list_t *) value2)->variance;
-}
-
-static int
-cmpdecvar (const void *value1, const void *value2)
-/*
- *  Sorts by decreasing variances (quicksort sorting function).
- */
-{
-  return ((var_list_t *) value2)->variance - ((var_list_t *) value1)->variance;
-}
diff --git a/converter/other/pnmtopalm/palm.h b/converter/other/pnmtopalm/palm.h
index 170c8cec..718a66cf 100644
--- a/converter/other/pnmtopalm/palm.h
+++ b/converter/other/pnmtopalm/palm.h
@@ -44,13 +44,9 @@ typedef struct {
 
 typedef Colormap_s * Colormap;
 
-int
-palmcolor_compare_indices(const void * const p1,
-                          const void * const p2);
+qsort_comparison_fn palmcolor_compare_indices;
 
-int
-palmcolor_compare_colors(const void * const p1,
-                         const void * const p2);
+qsort_comparison_fn palmcolor_compare_colors;
 
 Colormap
 palmcolor_build_custom_8bit_colormap(unsigned int const rows,
diff --git a/converter/other/pnmtopalm/palmcolormap.c b/converter/other/pnmtopalm/palmcolormap.c
index a1a1cec1..0f47558c 100644
--- a/converter/other/pnmtopalm/palmcolormap.c
+++ b/converter/other/pnmtopalm/palmcolormap.c
@@ -10,7 +10,9 @@
 int
 palmcolor_compare_indices(const void * const p1,
                           const void * const p2) {
-
+/*----------------------------------------------------------------------------
+   This is a 'qsort' collation function.
+-----------------------------------------------------------------------------*/
     if ((*((Color) p1) & 0xFF000000) < (*((Color) p2) & 0xFF000000))
         return -1;
     else if ((*((Color) p1) & 0xFF000000) > (*((Color) p2) & 0xFF000000))
@@ -24,7 +26,9 @@ palmcolor_compare_indices(const void * const p1,
 int
 palmcolor_compare_colors(const void * const p1,
                          const void * const p2) {
-
+/*----------------------------------------------------------------------------
+   This is a 'qsort' collation function.
+-----------------------------------------------------------------------------*/
     unsigned long const val1 = *((const unsigned long *) p1) & 0xFFFFFF;
     unsigned long const val2 = *((const unsigned long *) p2) & 0xFFFFFF;
 
diff --git a/converter/other/winicontopam.c b/converter/other/winicontopam.c
index 9bee8b3c..f41a8db3 100644
--- a/converter/other/winicontopam.c
+++ b/converter/other/winicontopam.c
@@ -182,6 +182,10 @@ u32_xx(const unsigned char * const buf,
 
 
 
+#ifndef LITERAL_FN_DEF_MATCH
+static qsort_comparison_fn cmpfn;
+#endif
+
 static int
 cmpfn(const void * const aP,
       const void * const bP) {
diff --git a/converter/ppm/ppmtoilbm.c b/converter/ppm/ppmtoilbm.c
index 69784b37..c861163f 100644
--- a/converter/ppm/ppmtoilbm.c
+++ b/converter/ppm/ppmtoilbm.c
@@ -354,7 +354,6 @@ do_ham_body     ARGS((FILE *ifP, FILE *ofp, int cols, int rows, pixval maxval,
                 pixval hammaxval, int nPlanes, pixel *cmap, int colors));
 
 
-static int hcmp (const void *va, const void *vb);
 static pixel *compute_ham_cmap ARGS((int cols, int rows, int maxval, 
                                      int maxcolors, int *colorsP, int hbits));
 
@@ -365,6 +364,10 @@ typedef struct {
 } hentry;
 
 
+#ifndef LITERAL_FN_DEF_MATCH
+static qsort_comparison_fn hcmp;
+#endif
+
 static int
 hcmp(const void *va, const void *vb)
 {
diff --git a/editor/pamsistoaglyph.c b/editor/pamsistoaglyph.c
index 9866b7bd..6b093520 100644
--- a/editor/pamsistoaglyph.c
+++ b/editor/pamsistoaglyph.c
@@ -247,12 +247,19 @@ findRegionEyeSeparation( gray ** const grayArray,
 
 
 
+#ifndef LITERAL_FN_DEF_MATCH
+static qsort_comparison_fn compareInts;
+#endif
+
 static int
-compare_ints( const void * const firstP,
-              const void * const secondP ) {
+compareInts(const void * const a,
+            const void * const b) {
+
+    const int * const firstP = a;
+    const int * const secondP = b;
 
-    int const first  = *(int *)firstP;
-    int const second = *(int *)secondP;
+    int const first  = *firstP;
+    int const second = *secondP;
 
     int retval;
 
@@ -311,7 +318,7 @@ findEyeSeparation( struct pam *  const pamP,
                 rowSeparation[numValidRows++] = sep;
         }
         if (numValidRows > 0) {
-            qsort( rowSeparation, numValidRows, sizeof(int), compare_ints );
+            qsort(rowSeparation, numValidRows, sizeof(int), compareInts);
             bestSeparation = rowSeparation[numValidRows/2];
         }
         free( rowSeparation );
diff --git a/editor/ppmdist.c b/editor/ppmdist.c
index bca96adc..e8f17bff 100644
--- a/editor/ppmdist.c
+++ b/editor/ppmdist.c
@@ -22,6 +22,7 @@ struct colorToGrayEntry {
 #define MAXCOLORS 255
 
 
+
 static gray
 newGrayValue(pixel *pix, struct colorToGrayEntry *colorToGrayMap, int colors) {
 
@@ -40,20 +41,34 @@ newGrayValue(pixel *pix, struct colorToGrayEntry *colorToGrayMap, int colors) {
 
 
 
+#ifndef LITERAL_FN_DEF_MATCH
+static qsort_comparison_fn cmpColorToGrayEntryByIntensity;
+#endif
+
 static int
-cmpColorToGrayEntryByIntensity(const void *entry1, const void *entry2) {
+cmpColorToGrayEntryByIntensity(const void * const a,
+                               const void * const b) {
+
+    const struct colorToGrayEntry * const entry1P = a;
+    const struct colorToGrayEntry * const entry2P = b;
 
-    return ((struct colorToGrayEntry *) entry1)->gray -
-        ((struct colorToGrayEntry *) entry2)->gray;
+    return entry1P->gray - entry2P->gray;
 }
 
 
 
+#ifndef LITERAL_FN_DEF_MATCH
+static qsort_comparison_fn cmpColorToGrayEntryByFrequency;
+#endif
+
 static int
-cmpColorToGrayEntryByFrequency(const void * entry1, const void * entry2) {
+cmpColorToGrayEntryByFrequency(const void * const a,
+                               const void * const b) {
+
+    const struct colorToGrayEntry * const entry1P = a;
+    const struct colorToGrayEntry * const entry2P = b;
 
-    return ((struct colorToGrayEntry *) entry1)->frequency -
-        ((struct colorToGrayEntry *) entry2)->frequency;
+    return entry1P->frequency - entry2P->frequency;
 }
 
 
diff --git a/lib/libppmcmap.c b/lib/libppmcmap.c
index 27233a46..67a85ebf 100644
--- a/lib/libppmcmap.c
+++ b/lib/libppmcmap.c
@@ -689,9 +689,33 @@ fail:
 }
 
 
+
+static int (*customCmp)(pixel *, pixel *);
+
+#ifndef LITERAL_FN_DEF_MATCH
+static qsort_comparison_fn customStub;
+#endif
+
 static int
-pixel_cmp(const void * const a, const void * const b) {
-    const pixel *p1 = (const pixel *)a, *p2 = (const pixel *)b;
+customStub(const void * const a,
+           const void * const b) {
+
+    return (*customCmp)((pixel *)a, (pixel *)b);
+}
+
+
+
+#ifndef LITERAL_FN_DEF_MATCH
+static qsort_comparison_fn pixelCmp;
+#endif
+
+static int
+pixelCmp(const void * const a,
+         const void * const b) {
+
+    const pixel * const p1 = (const pixel *)a;
+    const pixel * const p2 = (const pixel *)b;
+
     int diff;
 
     diff = PPM_GETR(*p1) - PPM_GETR(*p2);
@@ -703,23 +727,18 @@ pixel_cmp(const void * const a, const void * const b) {
     return diff;
 }
 
-static int (*custom_cmp)(pixel *, pixel *);
-
-static int
-custom_stub(const void * const a, const void * const b) {
-    return (*custom_cmp)((pixel *)a, (pixel *)b);
-}
 
 
 void
-ppm_sortcolorrow(pixel * const colorrow, const int ncolors, 
+ppm_sortcolorrow(pixel * const colorrow,
+                 int     const ncolors, 
                  int (*cmpfunc)(pixel *, pixel *)) {
 
-    if( cmpfunc ) {
-        custom_cmp = cmpfunc;
-        qsort((void *)colorrow, ncolors, sizeof(pixel), custom_stub);
+    if (cmpfunc) {
+        customCmp = cmpfunc;
+        qsort((void *)colorrow, ncolors, sizeof(pixel), customStub);
     } else
-        qsort((void *)colorrow, ncolors, sizeof(pixel), pixel_cmp);
+        qsort((void *)colorrow, ncolors, sizeof(pixel), pixelCmp);
 }