home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / xicon05.zip / iconio.c < prev    next >
C/C++ Source or Header  |  1993-05-06  |  3KB  |  149 lines

  1. /* This file is iconio.c (part of XIcon)
  2.  *
  3.  * Copyright (C) 1993 by Norman Walsh
  4.  *
  5.  *   This program is free software; you can redistribute it and/or modify
  6.  *   it under the terms of the GNU General Public License as published by
  7.  *   the Free Software Foundation; either version 2 of the License, or
  8.  *   (at your option) any later version.
  9.  *
  10.  *   This program is distributed in the hope that it will be useful,
  11.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *   GNU General Public License for more details.
  14.  *
  15.  *   You should have received a copy of the GNU General Public License
  16.  *   along with this program; if not, write to the Free Software
  17.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  ************************************************************************/
  19.  
  20. #include <stdio.h>
  21. #include "iconio.h"
  22. #include "icondata.h"
  23. #include "macdata.h"
  24. #include "macread.h"
  25.  
  26. int read_int()
  27. {
  28.   int datum;
  29.   rc = fread(&datum, sizeof (datum), 1, input);
  30.   return datum;
  31. }
  32.  
  33. short int read_shortint()
  34. {
  35.   short int datum;
  36.   rc = fread(&datum, sizeof (datum), 1, input);
  37.   return datum;
  38. }
  39.  
  40. unsigned char read_char()
  41. {
  42.   unsigned char datum;
  43.   rc = fread(&datum, sizeof (datum), 1, input);
  44.   return datum;
  45. }
  46.  
  47. int read_macint()
  48. {
  49.   unsigned char Ca[4];
  50.   int datum;
  51.  
  52.   rc = fread(&Ca, 1, 4, input);
  53.   datum = (Ca[0] << 24) + (Ca[1] << 16) + (Ca[2] << 8) + (Ca[3]);
  54.   return datum;
  55. }
  56.  
  57. int read_macint3()
  58. {
  59.   unsigned char Ca[3];
  60.   int datum;
  61.  
  62.   rc = fread(&Ca, 1, 3, input);
  63.   datum = (Ca[0] << 16) + (Ca[1] << 8) + (Ca[2]);
  64.   return datum;
  65. }
  66.  
  67. short int read_macshortint()
  68. {
  69.   unsigned char Ca[2];
  70.   int datum;
  71.  
  72.   rc = fread(&Ca, 1, 2, input);
  73.   datum = (Ca[0] << 8) + (Ca[1]);
  74.   return datum;
  75. }
  76.  
  77. unsigned char read_macchar()
  78. {
  79.   return read_char();
  80. }
  81.  
  82. void write_int(unsigned int datum)
  83. {
  84.   rc = fwrite(&datum, sizeof (datum), 1, output);
  85. }
  86.  
  87. void write_shortint(unsigned short int datum)
  88. {
  89.   rc = fwrite(&datum, sizeof (datum), 1, output);
  90. }
  91.  
  92. void write_char(unsigned char datum)
  93. {
  94.   rc = fwrite(&datum, sizeof (datum), 1, output);
  95. }
  96.  
  97. enum iconFileType QueryFileType()
  98. {
  99.   USHORT id;
  100.   USHORT type;
  101.   RsrcHdrStruct MacHeader;
  102.   RsrcMapStruct MacMap;
  103.   char bytes[5];
  104.  
  105.   /* First, is this thing likely to be a Mac icon? */
  106.   fseek(input, 0, SEEK_SET);
  107.   MacHeader = read_mac_header();
  108.   fseek(input, MacHeader.MapOffset, SEEK_SET);
  109.   MacMap = read_mac_map();
  110.  
  111.   if (MacHeader.MapOffset != 0
  112.       && MacHeader.DataOffset == MacMap.MapCopy[0]
  113.       && MacHeader.MapOffset == MacMap.MapCopy[1]
  114.       && MacHeader.DataLen == MacMap.MapCopy[2]
  115.       && MacHeader.MapLen == MacMap.MapCopy[3])
  116.     return MacIcon;
  117.  
  118.   fseek(input, 0, SEEK_SET);
  119.   id = read_shortint();
  120.   type = read_int();
  121.  
  122.   fseek(input, 0, SEEK_SET);
  123.   fread(&bytes, 1, 4, input);
  124.   bytes[4] = 0;
  125.  
  126.   switch (id)
  127.     {
  128.     case 0x4142:
  129.       if (type == 0x5C)
  130.         return OS2Icon20;
  131.       else
  132.         if (type == 0x28)
  133.           return OS2Icon12;
  134.       break;
  135.     case 0x0000:
  136.       if (type = 0x0001)
  137.         return WinIcon;
  138.       break;
  139.     default:
  140.       if (strcmp(bytes, "#def") == 0)
  141.     return XBMicon;
  142.       break;
  143.     }
  144.  
  145.   return UnkFile;
  146. }
  147.  
  148.  
  149.