|
|
1.1 root 1: /* $Header: port.h,v 1.1 87/09/11 07:56:24 toddb Exp $ */
2: /*
3: * The portable font format has the following properties:
4: * little-endian 16 and 32-bit integers
5: * no padding in structures
6: * lowest-addressed byte of a bitmap is leftmost on screen
7: * least-significant bit within a byte of a bitmap is leftmost on screen
8: * bitmaps are padded only to byte boundaries
9: *
10: * The "native" font format has the following properties:
11: * native-ended 16 and 32-bit integers
12: * padding in structures is that of the compiler with which the converter
13: * is compiled
14: * byte ordering along a scanline is set by a command-line option
15: * bit ordering within a byte of a bitmap is set by a command-line option
16: * bitmaps are padded only to byte boundaries
17: */
18: #ifndef u_char
19: #define u_char unsigned char
20: #endif
21:
22: /*
23: * put i into 32 portable bits
24: */
25: #define p32( i, pb) \
26: (pb)[0] = i & 0xff; \
27: (pb)[1] = (i & 0xff00) >> 8; \
28: (pb)[2] = (i & 0xff0000) >> 16; \
29: (pb)[3] = (i & 0xff000000) >> 24;
30:
31: /*
32: * put i into 16 portable bits
33: */
34: #define p16( i, pb) \
35: (pb)[0] = i & 0xff; \
36: (pb)[1] = (i & 0xff00) >> 8;
37:
38: /*
39: * naturalize 32 portable bits
40: */
41: #define n32( p32) \
42: (((((u_char *)(p32))[3] << 8 | ((u_char *)(p32))[2]) << 8 | ((u_char *)(p32))[1]) << 8 | ((u_char *)(p32))[0])
43:
44: /*
45: * naturalize 16 portable bits
46: */
47: #define n16( p16) \
48: (((u_char *)(p16))[1] << 8 | ((u_char *)(p16))[0])
49:
50:
51: /*
52: * These increment the byte pointer as well.
53: * no return value
54: */
55: #define port32( pb, i) \
56: p32( i, pb); \
57: pb += 4;
58:
59: #define port16( pb, i) \
60: p16( i, pb); \
61: pb += 2;
62:
63: #define nat32( pb, i) \
64: i = n32( pb); \
65: pb += 4;
66:
67: #define nat16( pb, i) \
68: i = n16( pb); \
69: pb += 2;
70:
71:
72: unsigned char _b32[4]; /* a hidden temporary */
73: /*
74: * These increment the file pointer as well.
75: * Don't put more than one of these macros in an expression!
76: * no return values
77: */
78: #define put32( i, fp) \
79: p32( (i), _b32); \
80: fwrite( _b32, 4, 1, (fp));
81:
82: #define put16( i, fp) \
83: p16( (i), _b32); \
84: fwrite( _b32, 2, 1, (fp));
85:
86: #define get32( i, fp) \
87: ( fread( _b32, 4, 1, (fp)), g32( _b32))
88:
89: #define get16( i, fp) \
90: ( fread( _b32, 2, 1, (fp)), g16( _b32))
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.