[brlcad-commits] SF.net SVN: brlcad:[36429] brlcad/trunk/src/util/pix-ppm.c
Open Source Solid Modeling CAD
Brought to you by:
brlcad
From: <br...@us...> - 2009-11-06 17:45:29
|
Revision: 36429 http://brlcad.svn.sourceforge.net/brlcad/?rev=36429&view=rev Author: brlcad Date: 2009-11-06 17:45:21 +0000 (Fri, 06 Nov 2009) Log Message: ----------- cleanup formatting but more importantly improve the usage statement to indicate that output is on stdout Modified Paths: -------------- brlcad/trunk/src/util/pix-ppm.c Modified: brlcad/trunk/src/util/pix-ppm.c =================================================================== --- brlcad/trunk/src/util/pix-ppm.c 2009-11-06 15:20:53 UTC (rev 36428) +++ brlcad/trunk/src/util/pix-ppm.c 2009-11-06 17:45:21 UTC (rev 36429) @@ -33,35 +33,33 @@ #include "bu.h" #include "vmath.h" #include "bn.h" +#include "fb.h" -static long int file_width = 512L; /* default input width */ -static long int file_height = 512L; /* default input height */ +static long int file_width = 512L; /* default input width */ +static long int file_height = 512L; /* default input height */ -static int autosize = 0; /* !0 to autosize input */ +static int autosize = 0; /* !0 to autosize input */ -static int fileinput = 0; /* file of pipe on input? */ -static char *file_name; -static FILE *infp; +static int fileinput = 0; /* file of pipe on input? */ +static char *file_name; +static FILE *infp; -static int pixbytes = 3; +static int pixbytes = 3; #define ROWSIZE (file_width * pixbytes) #define SIZE (file_width * file_height * pixbytes) char *scanbuf; -static char usage[] = "\ -Usage: pix-ppm [-a] [-#bytes] [-w file_width] [-n file_height]\n\ - [-s square_file_size] [file.pix]\n"; int -get_args(int argc, register char **argv) +get_args(int argc, char *argv[]) { - register int c; + int c; - while ( (c = bu_getopt( argc, argv, "a#:s:w:n:" )) != EOF ) { - switch ( c ) { + while ((c = bu_getopt(argc, argv, "a#:s:w:n:")) != EOF) { + switch (c) { case '#': pixbytes = atoi(bu_optarg); break; @@ -87,63 +85,57 @@ } } - if ( bu_optind >= argc ) { - if ( isatty(fileno(stdin)) ) + if (bu_optind >= argc) { + if (isatty(fileno(stdin))) return(0); file_name = "-"; infp = stdin; } else { file_name = argv[bu_optind]; - if ( (infp = fopen(file_name, "r")) == NULL ) { + if ((infp = fopen(file_name, "r")) == NULL) { perror(file_name); - (void)fprintf( stderr, - "pix-ppm: cannot open \"%s\" for reading\n", - file_name ); - bu_exit (1, NULL); + bu_exit(1, "pix-ppm: cannot open \"%s\" for reading\n", file_name); } fileinput++; } - if ( argc > ++bu_optind ) - (void)fprintf( stderr, "pix-ppm: excess argument(s) ignored\n" ); + if (argc > ++bu_optind) + bu_log("pix-ppm: excess argument(s) ignored\n"); return(1); /* OK */ } int -main(int argc, char **argv) +main(int argc, char *argv[]) { int i; char *row; + static char usage[] = "Usage: pix-ppm [-a] [-#bytes] [-w file_width] [-n file_height] [-s square_file_size] [file.pix] > file.ppm"; - - if ( !get_args( argc, argv ) ) { - (void)fputs(usage, stderr); - bu_exit ( 1, NULL ); + if (!get_args(argc, argv)) { + bu_exit (1, "%s\n", usage); } /* autosize input? */ - if ( fileinput && autosize ) { - unsigned long int w, h; - if ( fb_common_file_size(&w, &h, file_name, pixbytes) ) { + if (fileinput && autosize) { + unsigned long int w, h; + if (fb_common_file_size(&w, &h, file_name, pixbytes)) { file_width = (long)w; file_height = (long)h; } else { - fprintf(stderr, "pix-ppm: unable to autosize\n"); + bu_log("pix-ppm: unable to autosize\n"); } } - /* * gobble up the bytes */ - scanbuf = bu_malloc( SIZE, "scanbuf" ); - if ( fread(scanbuf, 1, SIZE, infp) == 0 ) { - fprintf(stderr, "pix-ppm: Short read\n"); - bu_exit (1, NULL); + scanbuf = bu_malloc(SIZE, "scanbuf"); + if (fread(scanbuf, 1, SIZE, infp) == 0) { + bu_exit (1, "pix-ppm: Short read\n"); } - if ( pixbytes == 1 ) { + if (pixbytes == 1) { /* PGM magic number */ printf("P2\n"); } else { @@ -163,7 +155,7 @@ * input is upside down. */ - for ( i = 0; i < file_height; i++ ) { + for (i = 0; i < file_height; i++) { row = scanbuf + (file_height-1 - i) * ROWSIZE; fwrite(row, 1, ROWSIZE, stdout); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |