home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / fbm / src / fbinfo.c < prev    next >
C/C++ Source or Header  |  1990-06-24  |  3KB  |  114 lines

  1. /*****************************************************************
  2.  * fbinfo.c: FBM Release 1.0 25-Feb-90 Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989,1990 by Michael Mauldin.  Permission is granted
  5.  * to use this file in whole or in part for any purpose, educational,
  6.  * recreational or commercial, provided that this copyright notice
  7.  * is retained unchanged.  This software is available to all free of
  8.  * charge by anonymous FTP and in the UUNET archives.
  9.  *
  10.  * fbinfo.c: 
  11.  *
  12.  * USAGE
  13.  *    % fbinfo files...
  14.  *
  15.  * EDITLOG
  16.  *    LastEditDate = Mon Jun 25 00:03:01 1990 - Michael Mauldin
  17.  *    LastFileName = /usr2/mlm/src/misc/fbm/fbinfo.c
  18.  *
  19.  * HISTORY
  20.  * 25-Jun-90  Michael Mauldin (mlm@cs.cmu.edu) Carnegie Mellon
  21.  *    Package for Release 1.0
  22.  *
  23.  * 03-May-89  Michael Mauldin (mlm) at Carnegie Mellon University
  24.  *    Beta release (version 0.93) mlm@cs.cmu.edu
  25.  *
  26.  * 26-Sep-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  27.  *    Created.
  28.  *****************************************************************/
  29.  
  30.  
  31. # include <stdio.h>
  32. # include <math.h>
  33. # include "fbm.h"
  34.  
  35. # define USAGE "Usage: fbinfo files..."
  36.  
  37. #ifndef lint
  38. static char *fbmid =
  39. "$FBM fbinfo.c <1.0> 25-Jun-90  (C) 1989,1990 by Michael Mauldin, source \
  40. code available free from MLM@CS.CMU.EDU and from UUNET archives$";
  41. #endif
  42.  
  43. main (argc, argv)
  44. char *argv[];
  45. { register int i;
  46.   FILE *infile;
  47.   char name[128], cmd[256];
  48.  
  49.   if (argc == 1)
  50.   { binfo ((char *) NULL, stdin); }
  51.   else
  52.   { for (i=1; i<argc; i++)
  53.     { strcpy (name, argv[i]);
  54.  
  55.       if (strcmp (name + strlen (name) - 2, ".Z") == 0)
  56.       { sprintf (cmd, "(uncompress < %s | select 0 255) 2> /dev/null", name); 
  57.         if (infile = popen (cmd, "r"))
  58.     { binfo (name, infile); pclose (infile); }
  59.     else
  60.     { perror (cmd); }
  61.       }
  62.       else if (infile = fopen (argv[i], "r"))
  63.       { binfo (argv[i], infile); fclose (infile); }
  64.       else
  65.       { perror (argv[i]); }
  66.     }
  67.   }
  68. }
  69.  
  70. binfo (name, file)
  71. char *name;
  72. FILE *file;
  73. { FBM image;
  74.   FBMHDR *hdr;
  75.  
  76.   image.cm = image.bm = (unsigned char *) NULL;
  77.  
  78.   /* Read the file header format the bitmap description */
  79.   if (read_hdr_fbm (&image, file, (char *) NULL, 0))
  80.   { hdr = &(image.hdr);
  81.  
  82.     if (name) printf ("%-15s\t", name);
  83.  
  84.     if (hdr->title[0])        { printf ("\"%s\"\n", hdr->title); }
  85.     else            { printf ("(untitled)\n"); }
  86.  
  87.     if (hdr->credits[0])
  88.     { if (name) printf ("\t\t");
  89.       printf ("[ %s ]\n", hdr->credits);
  90.     }
  91.     
  92.     if (name) printf ("\t\t");
  93.  
  94.     if (hdr->planes == 1)
  95.     { printf ("[%dx%dx%d]    %d physbits  %1.4lg aspect ratio\n",
  96.           hdr->cols, hdr->rows, hdr->bits, hdr->physbits, hdr->aspect);
  97.     }
  98.     else
  99.     { printf ("[%dx%dx%dx%d]  %d physbits  %1.4lg aspect ratio\n",
  100.           hdr->planes, hdr->cols, hdr->rows, hdr->bits, hdr->physbits, 
  101.           hdr->aspect);
  102.     }
  103.  
  104.     if (name) printf ("\t\t");
  105.  
  106.     printf ("row length %d, plane length %d, colormap length %d\n",
  107.         hdr->rowlen, hdr->plnlen, hdr->clrlen);
  108.  
  109.     return (1);
  110.   }
  111.  
  112.   return (0);
  113. }
  114.