diff -ur ps2eps-1.68.orig/src/C/bbox.c ps2eps-1.68/src/C/bbox.c --- ps2eps-1.68.orig/src/C/bbox.c 2010-08-31 10:58:37.000000000 +0200 +++ ps2eps-1.68/src/C/bbox.c 2010-12-15 13:39:27.000000000 +0100 @@ -4,25 +4,25 @@ /** Author: Roland Bless **/ /** Copyright (C) 1998-2009 Roland Bless **/ /** To compile simply use: **/ -/** "cc bbox.c -o bbox" or "make bbox" **/ +/** "cc bbox.c -o bbox" or "make bbox" **/ /********************************************************************/ /* * $Id: bbox.c,v 1.18 2009-10-13 15:03:49 bless Exp $ */ /** -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * **/ @@ -69,12 +69,14 @@ 1 }; -unsigned int minus_one(const unsigned x) +static +unsigned int minus_one(const unsigned x) { return (x == 0) ? x : x-1; } -unsigned int plus_one(const unsigned x) +static +unsigned int plus_one(const unsigned x) { return (x == (unsigned int) ~0U) ? x : x+1; } @@ -95,8 +97,9 @@ * and printed to stdout * ************************************************************************/ /* calculate the bounding box in postscript points, given a resolution in dpi */ -void readppm_and_calcbb(const char *name, - const unsigned int resolution, +static +void readppm_and_calcbb(const char *name, + const unsigned int resolution, const unsigned char tight) { FILE *inputfile; @@ -109,29 +112,29 @@ double hllx, hlly, hurx, hury; /* hires bounding box */ unsigned char *image_row, /* ImageRow */ *tmpcolumnbytep; - unsigned int width,height; /* Image Size */ + unsigned int width,height; /* Image Size */ unsigned int byte_width; unsigned char stepsize; unsigned char colormax= 0; /* max color value */ unsigned int ui_colormax= 0; /* max color value */ - - if ( name == NULL ) + + if ( name == NULL ) { inputfile = stdin; name = "- STDIN -"; } - else + else { inputfile = fopen(name,"r"); if ( inputfile == NULL ) { - fprintf(stderr,"%s: ERROR -- could not open file %s\n", + fprintf(stderr,"%s: ERROR -- could not open file %s\n", prgname, name); return; } } /** check for magic number **/ - do + do { fgets(inputline, 1024, inputfile); #ifdef DEBUG @@ -150,7 +153,7 @@ } } while ( !feof(inputfile) && !magic_found ); - + if ( !magic_found ) { fprintf(stderr,"%s: ERROR -- %s is not in ppmraw or pbmraw format\n", @@ -158,7 +161,7 @@ return; } /** skip comments **/ - do + do { fgets(inputline, 1024, inputfile); #ifdef DEBUG @@ -175,15 +178,16 @@ if ( magic_found == 6 ) /* PPM file has maximum color-component value */ { fgets(inputline, 1024, inputfile); - sscanf(inputline,"%u",&ui_colormax); + sscanf(inputline,"%u",&ui_colormax); colormax = (unsigned char) ui_colormax; /* this is safer */ } #ifdef DEBUG fprintf(stderr,"\nreading picture: %s size X: %u Y: %u\n",name,width,height); #endif + x = 0; /* avoid uninitialized warning */ x_min= width>0 ? width-1 : 0; - x_max= 0; - y_min= height>0 ? height-1 : 0; + x_max= 0; + y_min= height>0 ? height-1 : 0; y_max= 0; if ( magic_found == 4 ) /* PBMRAW = Bitmap */ { /** read raw pbmfile **/ @@ -192,12 +196,12 @@ byte_width++; } else /** assume ppm raw **/ - { + { byte_width= width * 3; /* we have RGB, i.e. three bytes for each pixel */ } - /* + /* * Now read a raster of Width * Height pixels, proceeding through the image in normal English reading order, - * i.e., starting from top left then moving right + * i.e., starting from top left then moving right */ /* we allocate only one line */ image_row= malloc(byte_width); @@ -258,8 +262,8 @@ { /* there was a pixel with no background color */ tmpcolumnbytep= image_row+byte_width-1; /* inspect this line from the right */ - for (byte_x= byte_width-1; - byte_x >= 0; + for (byte_x= byte_width-1; + byte_x >= 0; byte_x--,tmpcolumnbytep--) { if ( *tmpcolumnbytep != colormax ) /* there are pixels not white */ @@ -292,7 +296,7 @@ y_min,y_max,x_min,x_max); #endif break; - } /* if there are pixels not white */ + } /* if there are pixels not white */ } /* end for byte_x */ } /* if line contained not only background color */ } /* end for y */ @@ -303,7 +307,7 @@ hllx= (x_min*pt_dpi_dbl)/resolution; /* distance from the bottom edge to the bottommost point */ hlly= ((minus_one(height)-y_max)*pt_dpi_dbl)/resolution; - /* distance from the left edge to the righmost point */ + /* distance from the left edge to the righmost point */ hurx= (plus_one(x_max)*pt_dpi_dbl)/resolution; /* distance from the bottom edge to the uppermost point */ hury= ((height-y_min)*pt_dpi_dbl)/resolution; @@ -315,7 +319,7 @@ llx= minus_one((unsigned int) ((unsigned long) x_min*72UL)/resolution); /* distance from the bottom edge to the bottommost point */ lly= minus_one((unsigned int) ((unsigned long) (minus_one(height)-y_max)*72UL)/resolution); - /* distance from the left edge to the righmost point */ + /* distance from the left edge to the righmost point */ urx= plus_one((unsigned int) ((unsigned long) plus_one(x_max)*72UL)/resolution); /* distance from the bottom edge to the uppermost point */ ury= plus_one((unsigned int) ((unsigned long) (height-y_min)*72UL)/resolution); @@ -335,7 +339,7 @@ llx= (unsigned int) ((unsigned long) x_min*72UL)/resolution; /* distance from the bottom edge to the bottommost point */ lly= (unsigned int) ((unsigned long) (minus_one(height)-y_max)*72UL)/resolution; - /* distance from the left edge to the righmost point */ + /* distance from the left edge to the righmost point */ urx= (unsigned int) ((unsigned long) plus_one(x_max)*72UL)/resolution; /* round up if we got a remainder */ if ( (((unsigned long) plus_one(x_max)*72UL) % resolution) != 0 ) @@ -357,15 +361,15 @@ } else fprintf(stderr,"%s: ERROR -- not enough memory to read in one row of the picture\n",prgname); - + fclose(inputfile); free(image_row); } -int +int main(int argc, char **argv) -{ +{ int i; char *filename= NULL; unsigned int resolution= 72; /* use 72 dpi as default resolution */