Mercurial > hg > dmlib
annotate dmfile.c @ 526:f7df57cafdd9
Add support for Interpaint (unpacked) and Doodle (unpacked) hires formats.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 22 Nov 2012 01:07:45 +0200 |
parents | c1f6def0c1da |
children | b2b461829c61 |
rev | line source |
---|---|
0 | 1 /* |
2 * DMLib | |
414
c452a459e552
Clear up the file descriptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
405
diff
changeset
|
3 * -- Standard I/O (stdio) file write/read endianess helpers |
0 | 4 * Programmed and designed by Matti 'ccr' Hamalainen |
5 * (C) Copyright 2011 Tecnic Software productions (TNSP) | |
6 */ | |
7 #include "dmfile.h" | |
8 | |
9 | |
405
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
10 BOOL dm_fread_str(FILE *f, void *buf, const size_t len) |
0 | 11 { |
12 return fread(buf, len, 1, f) == 1; | |
13 } | |
14 | |
15 | |
405
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
16 BOOL dm_fread_byte(FILE *f, Uint8 *val) |
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
17 { |
438
c1f6def0c1da
Adjust dm_fread_byte() and dm_fwrite_byte() stdio helper functions to match
Matti Hamalainen <ccr@tnsp.org>
parents:
414
diff
changeset
|
18 int tmp = fgetc(f); |
c1f6def0c1da
Adjust dm_fread_byte() and dm_fwrite_byte() stdio helper functions to match
Matti Hamalainen <ccr@tnsp.org>
parents:
414
diff
changeset
|
19 *val = tmp; |
c1f6def0c1da
Adjust dm_fread_byte() and dm_fwrite_byte() stdio helper functions to match
Matti Hamalainen <ccr@tnsp.org>
parents:
414
diff
changeset
|
20 return tmp != EOF; |
405
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
21 } |
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
22 |
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
23 |
0 | 24 #define DM_DEFINE_FFUNC(xname, xtype, xmacro) \ |
25 BOOL dm_fread_ ## xname (FILE *f, xtype *v) { \ | |
26 xtype result; \ | |
27 if (fread(&result, sizeof( xtype ), 1, f) != 1) \ | |
28 return FALSE; \ | |
29 *v = DM_ ## xmacro ## _TO_NATIVE (result); \ | |
30 return TRUE; \ | |
31 } | |
32 | |
33 #include "dmfiletmpl.h" | |
34 | |
35 | |
36 #undef DM_DEFINE_FFUNC | |
37 | |
405
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
38 |
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
39 BOOL dm_fwrite_str(FILE *f, const void *buf, const size_t len) |
0 | 40 { |
41 return fwrite(buf, len, 1, f) == 1; | |
42 } | |
43 | |
44 | |
405
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
45 BOOL dm_fwrite_byte(FILE *f, const Uint8 val) |
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
46 { |
438
c1f6def0c1da
Adjust dm_fread_byte() and dm_fwrite_byte() stdio helper functions to match
Matti Hamalainen <ccr@tnsp.org>
parents:
414
diff
changeset
|
47 return fputc(val, f) == val; |
405
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
48 } |
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
49 |
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
50 |
0 | 51 #define DM_DEFINE_FFUNC(xname, xtype, xmacro) \ |
405
d0257d0004f6
Implement dm_{read,write}_byte() and constify.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
52 BOOL dm_fwrite_ ## xname (FILE *f, const xtype v) { \ |
0 | 53 xtype result = DM_NATIVE_TO_ ## xmacro (v); \ |
54 if (fwrite(&result, sizeof( xtype ), 1, f) != 1) \ | |
55 return FALSE; \ | |
56 return TRUE; \ | |
57 } | |
58 | |
59 #include "dmfiletmpl.h" | |
60 | |
61 #undef DM_DEFINE_FFUNC |