home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Web / Utilities / wwwcount-2.3 / combine / readim.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-02  |  2.2 KB  |  114 lines

  1. /*
  2.  *  ReadImge
  3.  *
  4.  *  RCS:
  5.  *      $Revision: 2.3 $
  6.  *      $Date: 1996/05/03 02:21:34 $
  7.  *
  8.  *  Security:
  9.  *      Unclassified
  10.  *
  11.  *  Description:
  12.  *      text
  13.  *
  14.  *  Input Parameters:
  15.  *      type    identifier  description
  16.  *
  17.  *      text
  18.  *
  19.  *  Output Parameters:
  20.  *      type    identifier  description
  21.  *
  22.  *      text
  23.  *
  24.  *  Return Values:
  25.  *      value   description
  26.  *
  27.  *  Side Effects:
  28.  *      text
  29.  *
  30.  *  Limitations and Comments:
  31.  *      text
  32.  *
  33.  *  Development History:
  34.  *      who                 when        why
  35.  *      muquit@semcor.com   11-Jul-95   first cut
  36.  */
  37.  
  38. #include "combine.h"
  39.  
  40. Image *ReadImage (filename)
  41. char
  42.     *filename;
  43. {
  44.     FILE
  45.         *fp = (FILE *) NULL;
  46.  
  47.     Image
  48.         *image = (Image *) NULL;
  49.  
  50.     char
  51.         type[12];
  52.  
  53.     int
  54.         rc = 0;
  55.  
  56. #ifdef DEBUG
  57.     (void) fprintf (stderr," File: %s\n", filename);
  58. #endif
  59.  
  60.     *type = '\0';
  61.  
  62.     fp = fopen (filename, "rb");
  63.     if (fp == (FILE *) NULL)
  64.     {
  65.         (void) fprintf (stderr,
  66.             "Unable to open file: %s\n", filename);
  67.         return ((Image *) NULL);
  68.     }
  69.     
  70.     (void) strcpy (type, "unk");
  71.     (void) Read_Data (type, sizeof(char), sizeof(type), fp);
  72.     (void) fclose (fp);
  73.  
  74. #ifdef DEBUG
  75.     (void) fprintf (stderr," Format: %s\n", type);
  76. #endif
  77.     if (*type != 'u')
  78.     {
  79.         if (*type == 'G')
  80.         {
  81.             image = AllocateImageStruct ();
  82.             if (image == (Image *) NULL)
  83.             {
  84.                 (void) fprintf (stderr,
  85.                     "Malloc failed: AllocateImageStruct()!\n");
  86.                 return ((Image *) NULL);
  87.             }
  88.             (void) strcpy (image->type, "GIF");
  89.             (void) strcpy (image->filename, filename);
  90.  
  91.             rc = ReadGIFImage (image);
  92.             if (rc)
  93.             {
  94.                 DestroyAnyImageStruct (&image);
  95.                 (void) fprintf (stderr,
  96.                     "Failed to read GIF image: %s\n", filename);
  97.                 return ((Image *) NULL);
  98.             }
  99.             return (image);
  100.  
  101.         }
  102.         else
  103.         {
  104.             (void) fprintf (stderr,"Not a GIF image!\n");
  105.             return ((Image *) NULL);
  106.         }
  107.     }
  108.     else
  109.     {
  110.         (void) fprintf (stderr,"Not a GIF image!\n");
  111.         return ((Image *) NULL);
  112.     }
  113. }
  114.