home *** CD-ROM | disk | FTP | other *** search
/ 1st Canadian Shareware Disc / 1st_Canadian_Shareware_Disc_1991.ISO / graphics / gifdir2 / gifdir.c next >
C/C++ Source or Header  |  1990-05-19  |  3KB  |  104 lines

  1. /*Gifdir.c - Frank Imburgio CIS ID 76666,317
  2.   displays simple info from gif header on colors and size
  3.   written for Turbo C 2.0, but should work ok with MicroSoft 5.1*/
  4. #include <stdio.h>
  5. #include <dir.h>
  6. #include <dos.h>
  7. #include <string.h>
  8.  
  9. unsigned int getbytes(FILE *dev);
  10.  
  11. main(int argc, char *argv[])
  12. {
  13. struct   ffblk ffblk;
  14. char     gifspec[10];
  15. char     pathspec[80];
  16. char     drive[MAXDRIVE],dir[MAXDIR],name[MAXFILE],ext[MAXEXT];
  17. unsigned int junk,width,height,byte1,bits_per_pix,colors;
  18. FILE     *f;
  19.  
  20. /* check for input file or use *.gif as default */
  21. if (argc>1) {
  22.    strcpy(pathspec,argv[1]);
  23.    /* if user sent filename without extension, paste .gif on */
  24.    if (! strchr(pathspec,'.')) {
  25.       strcat(pathspec,".GIF");
  26.       /* check to if the gif file is there - if not, revert to original */
  27.       if (findfirst(pathspec,&ffblk,0)==-1)
  28.      strcpy(pathspec,argv[1]);
  29.    }
  30.    /* check to see if this is a path without the final backslash */
  31.    if (pathspec[strlen(pathspec)]!='\\' && findfirst(pathspec,&ffblk,0)==-1)
  32.       strcat(pathspec,"\\");
  33.    /* if not a valid filename now, paste *.gif on.... */
  34.    if (findfirst(pathspec,&ffblk,0)==-1)
  35.       strcat(pathspec,"*.GIF");
  36. }
  37. else
  38.    strcpy(pathspec,"*.GIF");
  39. if (findfirst(pathspec,&ffblk,0)==-1) {
  40.    printf("No GIF files in filespec %s!\n",pathspec);
  41.    exit(99);
  42.    }
  43. /* split and save components of filespec for later */
  44. fnsplit(pathspec,drive,dir,name,ext);
  45. while (1) {
  46.    /* build full pathname back from findnext function */
  47.    fnmerge(pathspec,drive,dir,ffblk.ff_name,0);
  48.  
  49.  
  50.    /* print filename */
  51.    printf("%13s\t",ffblk.ff_name);
  52.  
  53.    /* open file */
  54.    f = fopen(pathspec,"r");
  55.    if (! f) {
  56.       printf("* could not open file *\n");
  57.       fclose(f);
  58.       if (findnext(&ffblk))
  59.       break;
  60.       continue;
  61.    }
  62.    /* read gif header byte*/
  63.    fscanf(f,"%6s",gifspec);
  64.    if (stricmp(gifspec,"gif87a")) {
  65.       printf("*invalid GIF header format - not gif87a*\n");
  66.       fclose(f);
  67.       if (findnext(&ffblk))
  68.       break;
  69.       continue;
  70.    }
  71.  
  72.    /* determine the image width */
  73.    width = getbytes(f);
  74.  
  75.    /* determine the image height */
  76.    height = getbytes(f);
  77.  
  78.    /* determine the number of colors */
  79.    byte1 = getc(f);
  80.    bits_per_pix = byte1 & 0x07;
  81.    bits_per_pix++;
  82.    colors = 1 << bits_per_pix;
  83.  
  84.    printf ("%-3d X %-3d X %-4d\n",width,height,colors);
  85.    fclose(f);
  86.    if (findnext(&ffblk))
  87.        break;
  88.    }
  89. }
  90.  
  91. unsigned int getbytes(FILE *dev)
  92. {
  93.     int byte1;
  94.     int byte2;
  95.     int result;
  96.  
  97.     byte1 = getc(dev);
  98.     byte2 = getc(dev);
  99.  
  100.     result = (byte2 << 8) | byte1;
  101.  
  102.     return result;
  103. }
  104.