home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume19 / fbm / part02 / fbinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-08  |  2.6 KB  |  108 lines

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