diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2013-07-24 22:18:59 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2013-07-24 22:18:59 +0000 |
commit | d1cfc560073dbe5bfcaa412b4fea16d6831e743e (patch) | |
tree | 0e16bde705966132ed40a77001e1c95414f84306 /lib/libppmcmap.c | |
parent | 6516daea481dab323982d3a2b2aa8baf6988829a (diff) | |
download | netpbm-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
Diffstat (limited to 'lib/libppmcmap.c')
-rw-r--r-- | lib/libppmcmap.c | 45 |
1 files changed, 32 insertions, 13 deletions
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); } |