removed trailing whitespace
[xboard.git] / zic2xpm.c
index c2cda05..2fdd078 100644 (file)
--- a/zic2xpm.c
+++ b/zic2xpm.c
@@ -4,18 +4,18 @@
        Program to convert pieces from ZIICS format to XPM & XIM format.
        (C version)  By Frank McIngvale <frankm@hiwaay.net>.
 
-       Copyright (C) 1996, 2009, 2010 Free Software Foundation, Inc.
+       Copyright (C) 1996, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
 
        NOTICE: The piece images distributed with ZIICS are
-           copyrighted works of their original creators.  Images 
+           copyrighted works of their original creators.  Images
             converted with zic2xpm may not be redistributed without
            the permission of the copyright holders.  Do not contact
            the authors of zic2xpm or of ZIICS itself to request
-           permission. 
+           permission.
 
        NOTICE:  The format of the ZIICS piece file was gleaned from
            SHOWSETS.PAS, a part of ZIICS.  Thanks to Andy McFarland
-           (Zek on ICC) for making this source available!  ZIICS is a 
+           (Zek on ICC) for making this source available!  ZIICS is a
            completely separate and copyrighted work of Andy
            McFarland.  Use and distribution of ZIICS falls under the
            ZIICS license, NOT the GNU General Public License.
            License as published by the Free Software Foundation,
            either version 3 of the License, or (at your option) any
            later version.
-           
+
            GNU XBoard 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, see
            http://www.gnu.org/licenses/.
@@ -59,7 +59,7 @@
                size = Piece size.
 
        Plus 4 files for the light & dark squares.
-       
+
        This means that you can extract multiple SIZES in one directory
        without name clashes. Extracting two sets of the SAME
        size in a directory will cause the second to overwrite
@@ -132,15 +132,15 @@ z2xpm z2xpm_tab[NR_ZIICS_COLORS] = {
   { 14, '*', "light_square", "gray" },
   { 2, '.', "dark_square", "green" } };
 
-void fatal( str )
-        char *str;
+void
+fatal (char *str)
 {
   printf("Fatal error: %s\n", str );
   exit(1);
 }
 
-z2xim *lookup_xim_color( color )
-        int color;
+z2xim *
+lookup_xim_color (int color)
 {
   int i;
 
@@ -156,8 +156,8 @@ z2xim *lookup_xim_color( color )
   return NULL;                                 /* Make compiler happy */
 }
 
-z2xpm *lookup_xpm_color( color )
-        int color;
+z2xpm *
+lookup_xpm_color (int color)
 {
   int i;
 
@@ -175,8 +175,8 @@ z2xpm *lookup_xpm_color( color )
 
 char *src_name;
 
-int up8( i )
-        int i;
+int
+up8 (int i)
 {
   int r;
 
@@ -187,8 +187,8 @@ int up8( i )
   return i + 8 - r;
 }
 
-unsigned int vga_imagesize( w, h )
-        int w, h;
+unsigned int
+vga_imagesize (int w, int h)
 {
   int w8;
   unsigned int s;
@@ -200,9 +200,8 @@ unsigned int vga_imagesize( w, h )
   return s;
 }
 
-unsigned char *decode_byte( dest, b, w )
-        unsigned char *dest, *b;
-        int w;
+unsigned char *
+decode_byte (unsigned char *dest, unsigned char *b, int w)
 {
   int i, j;
   unsigned char byte, bit;
@@ -232,9 +231,8 @@ unsigned char *decode_byte( dest, b, w )
    SRC is in packed pixel format.
    DEST is filled with 1 BYTE per PIXEL.
 */
-unsigned char *decode_line( dest, src, w )
-        unsigned char *dest, *src;
-        int w;
+unsigned char *
+decode_line (unsigned char *dest, unsigned char *src, int w)
 {
   unsigned int w8;
   unsigned int bpp;
@@ -266,19 +264,17 @@ unsigned char *decode_line( dest, src, w )
   return (src + bpp * 4);
 }
 
-int write_xim_header( fp, w, h )
-        FILE *fp;
-        int w, h;
+int
+write_xim_header (FILE *fp, int w, int h)
 {
   fputc( w, fp );
   fputc( h, fp );
-  
+
   return 0;
 }
 
-int write_xpm_header( fp, w, h )
-        FILE *fp;
-        int w, h;
+int
+write_xpm_header (FILE *fp, int w, int h)
 {
   int i;
   z2xpm *cv;
@@ -308,17 +304,15 @@ int write_xpm_header( fp, w, h )
   return 0;
 }
 
-void create_piece_xim( outname, fpin, W, H )
-        char *outname;
-        FILE *fpin;
-        int W, H;
+void
+create_piece_xim (char *outname, FILE *fpin, int W, int H)
 {
   FILE *fpout;
   int w, h, i, j, c;
   unsigned char *lump, *p, *line;
   long size;
   z2xim *ent;
-  
+
   fpout = fopen( outname, "wb" );
   if ( !fpout )
        fatal( "Can't create output file.");
@@ -329,11 +323,11 @@ void create_piece_xim( outname, fpin, W, H )
 
   c = fgetc( fpin );
   h = (fgetc(fpin) << 8) | c;
-  
+
   ++w; ++h;
 
   if ( w != W || h != H )
-       fatal( "Bad header." );   
+       fatal( "Bad header." );
 
   size = vga_imagesize( w, h ) - 4;
   lump = (unsigned char*)malloc( size );
@@ -348,35 +342,33 @@ void create_piece_xim( outname, fpin, W, H )
   write_xim_header( fpout, w, h );
 
   p = lump;
-  
+
   /* Write XIM data */
   for( i=0; i<h; ++i )
        {
          p = decode_line( line, p, w );
-         
+
          for( j=0; j<w; ++j )
                {
                  ent = lookup_xim_color( line[j] );
                  fputc( ent->xval, fpout );
                }
        }
-  
+
   free( lump );
   free( line );
   fclose( fpout );
 }
 
-void create_piece_xpm( outname, fpin, W, H )
-        char *outname;
-        FILE *fpin;
-        int W, H;
+void
+create_piece_xpm (char *outname, FILE *fpin, int W, int H)
 {
   FILE *fpout;
   int w, h, i, j, c;
   unsigned char *lump, *p, *line;
   long size;
   z2xpm *cv;
-  
+
   fpout = fopen( outname, "wb" );
   if ( !fpout )
        fatal( "Can't create output file.");
@@ -387,11 +379,11 @@ void create_piece_xpm( outname, fpin, W, H )
 
   c = fgetc( fpin );
   h = (fgetc(fpin) << 8) | c;
-  
+
   ++w; ++h;
 
   if ( w != W || h != H )
-       fatal( "Bad header." );   
+       fatal( "Bad header." );
 
   size = vga_imagesize( w, h ) - 4;
   lump = (unsigned char*)malloc( size );
@@ -406,12 +398,12 @@ void create_piece_xpm( outname, fpin, W, H )
   write_xpm_header( fpout, w, h );
 
   p = lump;
-  
+
   /* Write XPM data */
   for( i=0; i<h; ++i )
        {
          p = decode_line( line, p, w );
-         
+
          fprintf( fpout, "\"" );
          for( j=0; j<w; ++j )
                {
@@ -422,7 +414,7 @@ void create_piece_xpm( outname, fpin, W, H )
        }
 
   fprintf( fpout, "};\n" );
-  
+
   free( lump );
   free( line );
   fclose( fpout );
@@ -435,8 +427,8 @@ char *pname[] = { "Pawn", "Rook", "King", "Queen", "Bishop", "Knight" };
 /* The suborder - Light/Light, Light/Dark, etc. */
 char *prefixes[] = { "ll", "ld", "dl", "dd" };
 
-int process_file_xim( filename )
-        char *filename;
+int
+process_file_xim (char *filename)
 {
   int w, h, piece, kind, c;
   int nr_pieces = 6;
@@ -445,18 +437,18 @@ int process_file_xim( filename )
   char buf[BUFLEN];
 
   src_name = filename;
-  
+
   fp = fopen( filename, "rb" );
   if ( !fp )
        fatal( "Can't open input file." );
-  
+
   /* Header is two ints -- Width then Height, x86 format */
   c = fgetc( fp );
   w = (fgetc(fp) << 8) | c;
 
   c = fgetc( fp );
   h = (fgetc(fp) << 8) | c;
-  
+
   ++w; ++h;
 
   if ( w != h )
@@ -469,12 +461,12 @@ int process_file_xim( filename )
   printf("Creating XIM files...\n");
   printf("File: %s, W=%d, H=%d\n", filename, w, h );
   fseek( fp, 0, SEEK_SET );
-  
+
   /* Write .XIM files */
   for( piece = 0; piece < nr_pieces; ++piece )
        {
          printf("%s ", pname[piece] );
-         
+
          for( kind = 0; kind < nr_kinds; ++kind )
                {
                  printf( "." );
@@ -492,18 +484,18 @@ int process_file_xim( filename )
 
   snprintf( buf, BUFLEN, "dsq%d.xim", w );
   printf("\nDark Square" );
-  create_piece_xim( buf, fp, w, h );  
+  create_piece_xim( buf, fp, w, h );
   printf("\n");
-  
+
   printf("Successfully converted!!\n" );
 
   fclose( fp );
-  
+
   return 0;
 }
 
-int process_file_xpm( filename )
-        char *filename;
+int
+process_file_xpm (char *filename)
 {
   int w, h, piece, kind, c;
   int nr_pieces = 6;
@@ -512,18 +504,18 @@ int process_file_xpm( filename )
   char buf[BUFLEN];
 
   src_name = filename;
-  
+
   fp = fopen( filename, "rb" );
   if ( !fp )
        fatal( "Can't open input file." );
-  
+
   /* Header is two ints -- Width then Height, x86 format */
   c = fgetc( fp );
   w = (fgetc(fp) << 8) | c;
 
   c = fgetc( fp );
   h = (fgetc(fp) << 8) | c;
-  
+
   ++w; ++h;
 
   if ( w != h )
@@ -532,16 +524,16 @@ int process_file_xpm( filename )
          printf("       (This set is %dx%d)\n", w, h );
          exit(1);
        }
-  
+
   printf("Creating XPM files...\n");
   printf("File: %s, W=%d, H=%d\n", filename, w, h );
   fseek( fp, 0, SEEK_SET );
-  
+
   /* Write .XPM files */
   for( piece = 0; piece < nr_pieces; ++piece )
        {
          printf("%s ", pname[piece] );
-         
+
          for( kind = 0; kind < nr_kinds; ++kind )
                {
                  printf( "." );
@@ -559,22 +551,21 @@ int process_file_xpm( filename )
 
   snprintf( buf, BUFLEN, "dsq%d.xpm", w );
   printf("\nDark Square" );
-  create_piece_xpm( buf, fp, w, h );  
+  create_piece_xpm( buf, fp, w, h );
   printf("\n");
-  
+
   printf("Successfully converted!!\n" );
 
   fclose( fp );
-  
+
   return 0;
 }
 
-int main( argc, argv )
-        int argc;
-        char *argv[];
+int
+main (int argc, char **argv)
 {
   int i;
-  
+
   if ( argc < 2 )
        {
          printf("ZIC2XPM 2.01 - by Frank McIngvale (frankm@hiwaay.net)\n");
@@ -588,13 +579,13 @@ int main( argc, argv )
 
 
   setbuf( stdout, NULL );
-  
+
   for( i=1; i<argc; ++i )
        {
          process_file_xpm( argv[i] );
          process_file_xim( argv[i] );
        }
-  
+
   fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n",
          "NOTICE: The piece images distributed with ZIICS are",
          "    copyrighted works of their original creators.  Images",