Revision: 41392
          http://brlcad.svn.sourceforge.net/brlcad/?rev=41392&view=rev
Author:   brlcad
Date:     2010-11-17 18:25:44 +0000 (Wed, 17 Nov 2010)

Log Message:
-----------
Restructure to avoid forward decls, indent and get consistency on style and ws, 
quell index warning, remove authors, remove globals.

Modified Paths:
--------------
    brlcad/trunk/src/fb/cmap-fb.c

Modified: brlcad/trunk/src/fb/cmap-fb.c
===================================================================
--- brlcad/trunk/src/fb/cmap-fb.c       2010-11-17 18:22:28 UTC (rev 41391)
+++ brlcad/trunk/src/fb/cmap-fb.c       2010-11-17 18:25:44 UTC (rev 41392)
@@ -20,12 +20,8 @@
  */
 /** @file cmap-fb.c
  *
- *  Load a colormap into a framebuffer.
+ * Load a colormap into a framebuffer.
  *
- *  Author -
- *     Robert Reschly
- *     Phillip Dykstra
- *
  */
 
 #include "common.h"
@@ -38,130 +34,130 @@
 #include "bu.h"
 #include "fb.h"
 
-static char *nextsym(char *b, char *cp);
-static int htoi(char *s);
 
-ColorMap cm;
-static char usage[] = "\
-Usage: cmap-fb [-h -o] [colormap]\n";
+/*
+ * Puts the next symbol from cp into the buffer b.
+ * Returns a pointer to the current location (one
+ * char beyond the symbol or at a NULL).
+ */
+static
+char *
+nextsym(char *b, char *cp)
+{
+    /* skip white */
+    while (isspace(*cp))
+       cp++;
 
+    while (*cp != '\0' && !isspace(*cp))
+       *b++ = *cp++;
+
+    *b = '\0';
+    return cp;
+}
+
+
+/*
+ * Hex to integer
+ * must have NO leading blanks
+ * does not check for errors.
+ */
+static
 int
+htoi(char *s)
+{
+    int i;
+
+    i = 0;
+
+    while (*s != '\0') {
+       i <<= 4;        /* times 16 */
+       if (*s == 'x' || *s == 'X')
+           i = 0;
+       else if (*s >= 'a')
+           i += *s - 'a' + 10;
+       else if (*s >= 'A')
+           i += *s - 'A' + 10;
+       else
+           i += *s - '0';
+       s++;
+    }
+    return i;
+}
+
+
+int
 main(int argc, char **argv)
 {
-    FBIO       *fbp;
-    FILE       *fp;
-    int        fbsize = 512;
-    int        overlay = 0;
-    int        index, ret;
-    char       line[512], buf[512], *str;
+    ColorMap cm;
+    char usage[] = "Usage: cmap-fb [-h -o] [colormap]\n";
 
-    while ( argc > 1 ) {
-       if ( strcmp(argv[1], "-h") == 0 ) {
+    FBIO *fbp;
+    FILE *fp;
+    int fbsize = 512;
+    int overlay = 0;
+    int idx, ret;
+    char line[512], buf[512], *str;
+
+    while (argc > 1) {
+       if (strcmp(argv[1], "-h") == 0) {
            fbsize = 1024;
-       } else if ( strcmp(argv[1], "-o") == 0 ) {
+       } else if (strcmp(argv[1], "-o") == 0) {
            overlay++;
-       } else if ( argv[1][0] == '-' ) {
+       } else if (argv[1][0] == '-') {
            /* unknown flag */
-           bu_exit(1, "%s", usage );
+           bu_exit(1, "%s", usage);
        } else
            break;      /* must be a filename */
        argc--;
        argv++;
     }
 
-    if ( argc > 1 ) {
-       if ( (fp = fopen(argv[1], "rb")) == NULL ) {
-           fprintf( stderr, "cmap-fb: can't open \"%s\"\n", argv[1] );
-           bu_exit(2, "%s", usage );
+    if (argc > 1) {
+       if ((fp = fopen(argv[1], "rb")) == NULL) {
+           fprintf(stderr, "cmap-fb: can't open \"%s\"\n", argv[1]);
+           bu_exit(2, "%s", usage);
        }
     } else
        fp = stdin;
 
-    if ( (fbp = fb_open( NULL, fbsize, fbsize )) == FBIO_NULL )
-       bu_exit( 3, "Unable to open framebuffer\n" );
+    if ((fbp = fb_open(NULL, fbsize, fbsize)) == FBIO_NULL)
+       bu_exit(3, "Unable to open framebuffer\n");
 
-    if ( overlay )
-       fb_rmap( fbp, &cm );
+    if (overlay)
+       fb_rmap(fbp, &cm);
 
-    while ( bu_fgets(line, 511, fp) != NULL ) {
+    while (bu_fgets(line, 511, fp) != NULL) {
        str = line;
-       str = nextsym( buf, str );
-       if ( ! isdigit(buf[0]) ) {
+       str = nextsym(buf, str);
+       if (! isdigit(buf[0])) {
            /* spare the 0 entry the garbage */
            continue;
        }
-       index = atoi( buf );
-       if ( index < 0 || index > 255 ) {
+       idx = atoi(buf);
+       if (idx < 0 || idx > 255) {
            continue;
        }
-       str = nextsym( buf, str );
-       cm.cm_red[index] = htoi( buf );
+       str = nextsym(buf, str);
+       cm.cm_red[idx] = htoi(buf);
 
-       str = nextsym( buf, str );
-       cm.cm_green[index] = htoi( buf );
+       str = nextsym(buf, str);
+       cm.cm_green[idx] = htoi(buf);
 
-       str = nextsym( buf, str );
-       cm.cm_blue[index] = htoi( buf );
+       str = nextsym(buf, str);
+       cm.cm_blue[idx] = htoi(buf);
     }
 
-    ret = fb_wmap( fbp, &cm );
-    fb_close( fbp );
-    if ( ret < 0 ) {
-       bu_exit(1, "cmap-fb: couldn't write colormap\n" );
+    ret = fb_wmap(fbp, &cm);
+    fb_close(fbp);
+    if (ret < 0) {
+       bu_exit(1, "cmap-fb: couldn't write colormap\n");
     }
 
     return 0;
 }
 
-/*
- *  Puts the next symbol from cp into the buffer b.
- *  Returns a pointer to the current location (one
- *  char beyond the symbol or at a NULL).
- */
-static
-char *
-nextsym(char *b, char *cp)
-{
-    /* skip white */
-    while ( isspace(*cp) )
-       cp++;
 
-    while ( *cp != '\0' && !isspace(*cp) )
-       *b++ = *cp++;
-
-    *b = '\0';
-    return cp;
-}
-
 /*
- *  Hex to integer
- *  must have NO leading blanks
- *  does not check for errors.
- */
-static
-int
-htoi(char *s)
-{
-    int        i;
-
-    i = 0;
-
-    while ( *s != '\0' ) {
-       i <<= 4;        /* times 16 */
-       if ( *s == 'x' || *s == 'X' )
-           i = 0;
-       else if ( *s >= 'a' )
-           i += *s - 'a' + 10;
-       else if ( *s >= 'A' )
-           i += *s - 'A' + 10;
-       else
-           i += *s - '0';
-       s++;
-    }
-    return i;
-}
-
-/*
  * Local Variables:
  * mode: C
  * tab-width: 8


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to