|
|
1.1 root 1:
2: #define SALIGN(p) (char *)(((int)p+1) & ~1)
3: #define LALIGN(p) (char *)(((int)p+3) & ~3)
4: #define SNEXT(p) (char *)((int)p + sizeof (short))
5: #define LNEXT(p) (char *)((int)p + sizeof (long))
6:
7:
8: /*
9: * convert from canonical to
10: * local representation.
11: */
12: char *
13: dkfcanon(fmt, from, to)
14: register char *fmt, *from, *to;
15: {
16: short tmp;
17: long ltmp;
18: while (*fmt) {
19: switch(*fmt++) {
20: case 's': /* short */
21: tmp = 0;
22: tmp = (*from++)&0377;
23: tmp |= ((*from++)&0377)<<8;
24: to = SALIGN(to);
25: *(short *)to = tmp;
26: to = SNEXT(to);
27: continue;
28: case 'l': /* long */
29: ltmp = 0;
30: ltmp = (*from++)&0377;
31: ltmp |= (long)((*from++)&0377)<<8;
32: ltmp |= (long)((*from++)&0377)<<16;
33: ltmp |= (long)((*from++)&0377)<<24;
34: to = LALIGN(to);
35: *(long *)to = ltmp;
36: to = LNEXT(to);
37: continue;
38: case 'b': /* byte */
39: *to++ = *from++;
40: continue;
41: default:
42: return((char *)0);
43: }
44: }
45: return(from);
46: }
47:
48: /*
49: * convert from local to
50: * canonical representation
51: */
52: char *
53: dktcanon(fmt, from, to)
54: register char *fmt, *from, *to;
55: {
56: short tmp;
57: long ltmp;
58:
59: while (*fmt) {
60: switch(*fmt++) {
61: case 's':
62: from = SALIGN(from);
63: tmp = *(short *)from;
64: from = SNEXT(from);
65: *to++ = tmp;
66: tmp >>=8;
67: *to++ = tmp;
68: continue;
69: case 'l':
70: from = LALIGN(from);
71: ltmp = *(long *)from;
72: *to++ = ltmp;
73: ltmp >>= 8;
74: *to++ = ltmp;
75: ltmp >>= 8;
76: *to++ = ltmp;
77: ltmp >>= 8;
78: *to++ = ltmp;
79: from = LNEXT(from);
80: continue;
81: case 'b':
82: *to++ = *from++;
83: continue;
84: default:
85: return((char *)0);
86: }
87: }
88: return(from);
89: }
90:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.