home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / GIFINFO1.ZIP / GIFINFO.C < prev    next >
C/C++ Source or Header  |  1989-11-25  |  5KB  |  180 lines

  1. /* Aaron Walton 1990 */
  2.  
  3. #define INCL_DOS
  4. #include <os2.h>
  5.  
  6.    USHORT cbWritten, cbRead;
  7.    char achFailName[128];
  8.    HDIR hdir = 0xFFFF;
  9.    FILEFINDBUF findbuf;
  10.    USHORT usSearchCount = 1;
  11.    int code;
  12.    int find_result;
  13.    char *path;   
  14.    char *temp_path;
  15.    char *error_log; 
  16.    char *error_message;
  17.    ULONG ulFilePointer = 0;
  18.    HFILE open_fh;
  19.    USHORT usAction;
  20.    int open_result;
  21.    char *gif_file;
  22.    char msg_buf[100];
  23.    int dos_close;
  24.    int dos_read;
  25.    USHORT usAttribute;
  26.    int mode_result;
  27.    char szFoundFile[128];
  28.    int search_result = 0;
  29.    int error_check = 0;
  30.    struct GIF_INFO {
  31.       char Signature[6];
  32.       int Width;
  33.       int Height;
  34.       BYTE Color_Pixels;
  35.       BYTE background;
  36.       BYTE Reserved1;
  37.       }  GIF_Info;
  38.                      
  39. main(argc, argv)
  40. int argc;
  41. char *argv[];
  42. {
  43. /*   DosWrite(1,"\r\nGIFINFO - version 1.00 - OS/2\r\n",32,&cbWritten);*/
  44.  
  45.    path = (char *) malloc(128);   
  46.    memset(path,0,128);
  47.    strcpy(path, argv[1]); 
  48.    temp_path = (char *) malloc(128);
  49.    memset(temp_path,0,128);
  50.    strcpy(temp_path, strupr(path));
  51.    error_log = (char *) malloc(128);
  52.    memset(error_log,0,128);
  53.    error_message = (char *) malloc(128);
  54.    memset(error_message,0,128);
  55.    gif_file = (char *) malloc(128);
  56.    memset(gif_file,0,128);
  57.    
  58.    
  59.    findfirstgif();
  60.     
  61.    if (find_result == 0)
  62.      findrestgif();            
  63.    else
  64.      usage();
  65.      
  66.    if (error_check != 0)
  67.      {
  68.      memset(error_message, 0, 128);
  69.      strcpy(error_message, "\r\n ");
  70.      strcat(error_message, szFoundFile);
  71.      DosWrite(1,error_message,strlen(error_message),&cbWritten);
  72.        }
  73.        
  74.    DosExit(EXIT_THREAD,0);
  75. }
  76.  
  77. findfirstgif()
  78. {
  79.    find_result = DosFindFirst(path,&hdir,0x00,&findbuf,sizeof(findbuf),
  80.                               &usSearchCount,0L);
  81.  
  82.    if (find_result == 0)
  83.      {
  84.      justpathname(temp_path);
  85.      strcpy(gif_file, temp_path);
  86.      strcat(gif_file, findbuf.achName);
  87.      mode_result = DosQFileMode(gif_file,&usAttribute,0L);     
  88.      open_result = DosOpen(gif_file, &open_fh, &usAction, 0L, 0x00, FILE_OPEN,
  89.                    OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, 0L);        
  90.      if (open_result == 0)
  91.        {
  92.        /* Read Header and Output Data */
  93.        dos_read = DosRead(open_fh, &GIF_Info, 13, &cbRead);
  94.        memset(error_message, 0, 128);
  95.        memset(error_log, 0, 128);
  96.        strcpy(error_message, findbuf.achName);
  97.        sprintf(error_log, " [%ux%ux%u]", GIF_Info.Width, GIF_Info.Height, 2^(GIF_Info.Color_Pixels & 0x90));
  98.        strcat(error_message, error_log);
  99.        strcat(error_message, "\n");
  100.        DosWrite(1,error_message,strlen(error_message),&cbWritten);     
  101.        dos_close = DosClose(open_fh);                          
  102.        }       
  103.      }
  104. }
  105.  
  106. findrestgif()
  107. {
  108.    while (DosFindNext(hdir,&findbuf,sizeof(findbuf),&usSearchCount) == 0)
  109.      {
  110.      strcpy(gif_file, temp_path);
  111.      strcat(gif_file, findbuf.achName);
  112.      mode_result = DosQFileMode(gif_file,&usAttribute,0L);     
  113.      open_result = DosOpen(gif_file, &open_fh, &usAction, 0L, 0x00, FILE_OPEN,
  114.                    OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, 0L);        
  115.      if (open_result == 0)
  116.        {
  117.        dos_read = DosRead(open_fh, &GIF_Info, 13, &cbRead);
  118.        memset(error_message, 0, 128);
  119.        memset(error_log, 0, 128);
  120.        strcpy(error_message, findbuf.achName);
  121.        sprintf(error_log, " [%ux%ux%u]", GIF_Info.Width, GIF_Info.Height, 2^(GIF_Info.Color_Pixels & 0x90));
  122.        strcat(error_message, error_log);
  123.        strcat(error_message, "\n");
  124.        DosWrite(1,error_message,strlen(error_message),&cbWritten);     
  125.        dos_close = DosClose(open_fh);                          
  126.        }      
  127.      }
  128. }
  129.  
  130. usage()
  131. {
  132.    DosWrite(1,"\r\n",2,&cbWritten);
  133.    DosWrite(1,"Usage:",6,&cbWritten);
  134.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  135.    DosWrite(1,"GIFINFO n",9,&cbWritten);
  136.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  137.    DosWrite(1,"Where n is full path to GIF file/s to check",43,&cbWritten);
  138.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  139.    DosWrite(1,"Ex: GIFINFO C:\\FILES\\SOME*.GIF",32,&cbWritten);
  140.    DosWrite(1,"\r\n\r\n",4,&cbWritten);
  141.    DosWrite(1,"Ex: GIFINFO D:\\SOME*.GIF",24,&cbWritten);
  142.    DosWrite(1,"\r\n",2,&cbWritten);
  143. }
  144.  
  145. justpathname(temp_path)
  146.  
  147. char temp_path[];
  148.  
  149. {
  150.    char *path;
  151.    char *drive;
  152.    char *dir;
  153.    char *fname;
  154.    char *ext;
  155.    
  156.    path = (char *) malloc(128);  
  157.    drive = (char *) malloc(128);
  158.    dir = (char *) malloc(128);
  159.    fname = (char *) malloc(128);
  160.    ext = (char *) malloc(128);
  161.  
  162.    memset(path,0,128);
  163.    memset(drive,0,128);
  164.    memset(dir,0,128);
  165.    memset(fname,0,128);
  166.    memset(ext,0,128);
  167.  
  168.    strcpy(path,temp_path);
  169.    _splitpath(temp_path,drive,dir,fname,ext);
  170.    strcpy(path,drive);
  171.    strcat(path,dir);
  172.    strcpy(temp_path,path);
  173.  
  174.    free(path);
  175.    free(drive);
  176.    free(dir);
  177.    free(fname);
  178.    free(ext);
  179. }
  180.