iff.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  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 3 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, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __IFF_H
  19. #define __IFF_H
  20. #define MakeID(a,b,c,d) ( (int) ( ( (int) (a) ) << 24 | ( (int) (b) ) << 16 | \
  21. ( (int) (c) ) << 8 | ( (int) (d) ) ) )
  22. #define vIFF_ID_FORM MakeID('F','O','R','M')
  23. #define vIFF_ID_CAT MakeID('C','A','T',' ')
  24. #define vIFF_ID_LIST MakeID('L','I','S','T')
  25. #define vIFF_ID_PROP MakeID('P','R','O','P')
  26. #define vIFF_ID_FILLER W_MakeID(' ',' ',' ',' ')
  27. /* IFF_FILE:
  28. IFF File handling structure
  29. */
  30. /* defines for IFF_FILE->flags */
  31. #define mIFF_FILE_FORMOPEN (1<<0) /* in a form */
  32. #define mIFF_FILE_CHUNKOPEN (1<<1) /* in a chunk */
  33. #define mIFF_FILE_LOADED (1<<2) /* file is in memory */
  34. typedef struct
  35. {
  36. int ID; /* Chunk ID */
  37. int Size; /* Chunk size in bytes */
  38. } IFF_CHUNK;
  39. typedef struct {
  40. /* public fields */
  41. int FormID;
  42. int ChunkID;
  43. int FormSize;
  44. int ChunkSize;
  45. /* private fields */
  46. int fp;
  47. int flags;
  48. int next_byte;
  49. int chunk_size_pos;
  50. int form_size_pos;
  51. int pad_form;
  52. int pad_chunk;
  53. int file_size;
  54. int file_pos;
  55. char *mem_file;
  56. } IFF_FILE;
  57. IFF_FILE* IFF_Open ( const char * );
  58. IFF_FILE* IFF_Load ( const char * );
  59. VOID IFF_Reset ( IFF_FILE * );
  60. VOID IFF_Close ( IFF_FILE * );
  61. VOID IFF_goto_form_end ( IFF_FILE *);
  62. VOID IFF_goto_chunk_end ( IFF_FILE *);
  63. int IFF_NextForm ( IFF_FILE *);
  64. int IFF_NextChunk ( IFF_FILE *);
  65. int IFF_Read ( IFF_FILE *, void *, int );
  66. int IFF_Write ( IFF_FILE *, void *, int );
  67. IFF_FILE* IFF_New ( const char * );
  68. int IFF_NewForm ( IFF_FILE *, int );
  69. int IFF_NewChunk ( IFF_FILE *, int );
  70. int IFF_CloseForm ( IFF_FILE * );
  71. int IFF_CloseChunk ( IFF_FILE * );
  72. #define DO_OPEN(P,N,F,E) {if (!((P)=open(N,(F)))) goto E;}
  73. #define DO_READ(P,B,S,E) {if ( read((P),(B),(S))!=(S)) goto E;}
  74. #define DO_WRITE(P,B,S,E) {if ( write((P),(B),(S))!=(S)) goto E;}
  75. #define IFF_READ(iff,data,size,label) {if ( IFF_Read ( (iff), (data), (size)) != (size)) goto label;}
  76. #define IFF_WRITE(iff,data,size,label) {if ( IFF_Write ( (iff), (data), (size)) != (size)) goto label;}
  77. #define IFF_NEWCHUNK(iff,id,label) { if ( !IFF_NewChunk ( (iff), (id))) goto label; }
  78. #define IFF_NEWFORM(iff,id,label) { if ( !IFF_NewForm ( (iff), (id))) goto label; }
  79. #define Reverse32(L) ( (( (L)>>24 ) & 0xff) | (((L)>>8) &0xff00) | (((L)<<8)&0xff0000) | (((L)<<24)&0xff000000))
  80. #define Reverse16(L) ( (( (L)>>8 ) & 0xff) | (((L)<<8)&0xff00) )
  81. #define __CPU_BIG_ENDIAN__ 0
  82. #if __CPU_BIG_ENDIAN__
  83. #define BgEn32(L) (L)
  84. #define BgEn16(L) (L)
  85. #define LtEn32(L) Reverse32(L)
  86. #define LtEn16(L) Reverse16(L)
  87. #else
  88. #define BgEn32(L) Reverse32(L)
  89. #define BgEn16(L) Reverse16(L)
  90. #define LtEn32(L) (L)
  91. #define LtEn16(L) (L)
  92. #endif
  93. #endif /* __IFF_H */