home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / graphic / xicon / src / iconio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-04  |  3.7 KB  |  174 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.   unsigned char Ca[4];
  29.   int datum;
  30.  
  31.   rc = fread(&Ca, 1, 4, input);
  32.   datum = (Ca[3] << 24) + (Ca[2] << 16) + (Ca[1] << 8) + (Ca[0]);
  33.   return datum;
  34.  
  35. /*
  36.   int datum;
  37.   rc = fread(&datum, sizeof (datum), 1, input);
  38.   return datum;
  39. */
  40. }
  41.  
  42. short int read_shortint()
  43. {
  44.   unsigned char Ca[2];
  45.   int datum;
  46.  
  47.   rc = fread(&Ca, 1, 2, input);
  48.   datum = (Ca[1] << 8) + (Ca[0]);
  49.   return datum;
  50.  
  51. /*
  52.   short int datum;
  53.   rc = fread(&datum, sizeof (datum), 1, input);
  54.   return datum;
  55. */
  56. }
  57.  
  58. unsigned char read_char()
  59. {
  60.   unsigned char datum;
  61.   rc = fread(&datum, sizeof (datum), 1, input);
  62.   return datum;
  63. }
  64.  
  65. int read_macint()
  66. {
  67.   unsigned char Ca[4];
  68.   int datum;
  69.  
  70.   rc = fread(&Ca, 1, 4, input);
  71.   datum = (Ca[0] << 24) + (Ca[1] << 16) + (Ca[2] << 8) + (Ca[3]);
  72.   return datum;
  73. }
  74.  
  75. int read_macint3()
  76. {
  77.   unsigned char Ca[3];
  78.   int datum;
  79.  
  80.   rc = fread(&Ca, 1, 3, input);
  81.   datum = (Ca[0] << 16) + (Ca[1] << 8) + (Ca[2]);
  82.   return datum;
  83. }
  84.  
  85. short int read_macshortint()
  86. {
  87.   unsigned char Ca[2];
  88.   int datum;
  89.  
  90.   rc = fread(&Ca, 1, 2, input);
  91.   datum = (Ca[0] << 8) + (Ca[1]);
  92.   return datum;
  93. }
  94.  
  95. unsigned char read_macchar()
  96. {
  97.   return read_char();
  98. }
  99.  
  100. void write_int(unsigned int datum)
  101. {
  102.   rc = fwrite(&datum, sizeof (datum), 1, output);
  103. }
  104.  
  105. void write_shortint(unsigned short int datum)
  106. {
  107.   rc = fwrite(&datum, sizeof (datum), 1, output);
  108. }
  109.  
  110. void write_char(unsigned char datum)
  111. {
  112.   rc = fwrite(&datum, sizeof (datum), 1, output);
  113. }
  114.  
  115. enum iconFileType QueryFileType()
  116. {
  117.   USHORT id;
  118.   USHORT type;
  119.   RsrcHdrStruct MacHeader;
  120.   RsrcMapStruct MacMap;
  121.   char bytes[5];
  122.  
  123.   /* First, is this thing likely to be a Mac icon? */
  124.   fseek(input, 0, SEEK_SET);
  125.   MacHeader = read_mac_header();
  126.   fseek(input, MacHeader.MapOffset, SEEK_SET);
  127.   MacMap = read_mac_map();
  128.  
  129.   if (MacHeader.MapOffset != 0
  130.       && MacHeader.DataOffset == MacMap.MapCopy[0]
  131.       && MacHeader.MapOffset == MacMap.MapCopy[1]
  132.       && MacHeader.DataLen == MacMap.MapCopy[2]
  133.       && MacHeader.MapLen == MacMap.MapCopy[3])
  134.     return MacIcon;
  135.  
  136.   fseek(input, 0, SEEK_SET);
  137.   id = read_shortint();
  138.   type = read_int();
  139.  
  140.   fseek(input, 0, SEEK_SET);
  141.   fread(&bytes, 1, 4, input);
  142.   bytes[4] = 0;
  143.  
  144.   switch (id)
  145.     {
  146.     case 0x4142:
  147.       if (type == 0x5C)
  148.         return OS2Icon20;
  149.       else
  150.         if (type == 0x28)
  151.           return OS2Icon12;
  152.       break;
  153.     case 0x4943:
  154.       if (type == 0x4E)
  155.     return OS2Icon20;
  156.       else 
  157.     if (type == 0x1A)
  158.       return OS2Icon12;
  159.       break;
  160.     case 0x0000:
  161.       if (type = 0x0001)
  162.         return WinIcon;
  163.       break;
  164.     default:
  165.       if (strcmp(bytes, "#def") == 0)
  166.     return XBMicon;
  167.       break;
  168.     }
  169.  
  170.   return UnkFile;
  171. }
  172.  
  173.  
  174.