home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / vg-2.03 / fileinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  1.3 KB  |  74 lines

  1. /*
  2.  * Copyright (C) 1992 Michael Davidson.
  3.  * All rights reserved.
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software
  6.  * and its documentation for any purpose and without fee is hereby
  7.  * granted, provided that the above copyright notice appear in all
  8.  * copies and that both that copyright notice and this permission
  9.  * notice appear in supporting documentation.
  10.  *
  11.  * This software is provided "as is" without express or implied warranty.
  12.  */
  13.  
  14. #include    <stdio.h>
  15. #include    <errno.h>
  16.  
  17. #include    "vg.h"
  18.  
  19. extern char    *gifInfo(FILE *fp);
  20. extern char    *jpegInfo(FILE *fp);
  21. extern char    *pcdInfo(FILE *fp);
  22.  
  23. void
  24. fileInfo(
  25.     char    *fname,
  26.     char    *info,
  27.     int        infolen
  28.     )
  29. {
  30.     FILE    *fp;
  31.     int        f;
  32.     long    offset;
  33.     char    *p;
  34.  
  35.     errno    = 0;
  36.     if ((fp = fopen(fname, "r")) == NULL)
  37.     {
  38.     strncpy(info, strerror(errno), infolen);
  39.     return;
  40.     }
  41.  
  42.     f        = getFileType(fname, fp);
  43.     offset    = ftell(fp);
  44.  
  45.     switch (f)
  46.     {
  47.     case F_GIF:
  48.         p = gifInfo(fp);
  49.         break;
  50.  
  51.     case F_JPEG:
  52.         p = jpegInfo(fp);
  53.         break;
  54.  
  55.     case F_PCD_O:
  56.     case F_PCD_I:
  57.         p = pcdInfo(fp);
  58.         break;
  59.  
  60.     default:
  61.         p = NULL;
  62.         break;
  63.     }
  64.  
  65.     if (p == NULL)
  66.     p = "unknown file type";
  67.  
  68.     strncpy(info, p, infolen);
  69.     if (offset == 128L)
  70.     strcat(info, " (with MAC header)");
  71.  
  72.     fclose(fp);
  73. }
  74.