| |
1 /* This file is part of the Project Athena Zephyr Notification System. |
| |
2 * It contains source for the ZReadAscii function. |
| |
3 * |
| |
4 * Created by: Robert French |
| |
5 * |
| |
6 * $Source$ |
| |
7 * $Author: warmenhoven $ |
| |
8 * |
| |
9 * Copyright (c) 1987, 1990 by the Massachusetts Institute of Technology. |
| |
10 * For copying and distribution information, see the file |
| |
11 * "mit-copyright.h". |
| |
12 */ |
| |
13 /* $Header$ */ |
| |
14 |
| |
15 #ifndef lint |
| |
16 static char rcsid_ZReadAscii_c[] = "$Header$"; |
| |
17 #endif /* lint */ |
| |
18 |
| |
19 #include <internal.h> |
| |
20 #include <assert.h> |
| |
21 |
| |
22 #if 0 |
| |
23 static __inline__ |
| |
24 int |
| |
25 Z_cnvt_xtoi (char c) |
| |
26 { |
| |
27 c -= '0'; |
| |
28 if (c < 10) |
| |
29 return c; |
| |
30 c -= 'A'-'9'-1; |
| |
31 if (c < 16) |
| |
32 return c; |
| |
33 return -1; |
| |
34 } |
| |
35 #endif |
| |
36 |
| |
37 #define Z_cnvt_xtoi(c) ((temp=(c)-'0'),(temp<10)?temp:((temp-='A'-'9'-1),(temp<16)?temp:-1)) |
| |
38 |
| |
39 Code_t ZReadAscii(ptr, len, field, num) |
| |
40 char *ptr; |
| |
41 int len; |
| |
42 unsigned char *field; |
| |
43 int num; |
| |
44 { |
| |
45 int i; |
| |
46 unsigned int hexbyte; |
| |
47 register int c1, c2; |
| |
48 register unsigned int temp; |
| |
49 |
| |
50 for (i=0;i<num;i++) { |
| |
51 if (*ptr == ' ') { |
| |
52 ptr++; |
| |
53 if (--len < 0) |
| |
54 return ZERR_BADFIELD; |
| |
55 } |
| |
56 if (ptr[0] == '0' && ptr[1] == 'x') { |
| |
57 ptr += 2; |
| |
58 len -= 2; |
| |
59 if (len < 0) |
| |
60 return ZERR_BADFIELD; |
| |
61 } |
| |
62 c1 = Z_cnvt_xtoi(ptr[0]); |
| |
63 if (c1 < 0) |
| |
64 return ZERR_BADFIELD; |
| |
65 c2 = Z_cnvt_xtoi(ptr[1]); |
| |
66 if (c2 < 0) |
| |
67 return ZERR_BADFIELD; |
| |
68 hexbyte = (c1 << 4) | c2; |
| |
69 field[i] = hexbyte; |
| |
70 ptr += 2; |
| |
71 len -= 2; |
| |
72 if (len < 0) |
| |
73 return ZERR_BADFIELD; |
| |
74 } |
| |
75 |
| |
76 return *ptr ? ZERR_BADFIELD : ZERR_NONE; |
| |
77 } |
| |
78 |
| |
79 Code_t ZReadAscii32(ptr, len, value_ptr) |
| |
80 char *ptr; |
| |
81 int len; |
| |
82 unsigned long *value_ptr; |
| |
83 { |
| |
84 unsigned char buf[4]; |
| |
85 Code_t retval; |
| |
86 |
| |
87 retval = ZReadAscii(ptr, len, buf, 4); |
| |
88 if (retval != ZERR_NONE) |
| |
89 return retval; |
| |
90 *value_ptr = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; |
| |
91 return ZERR_NONE; |
| |
92 } |
| |
93 |
| |
94 Code_t ZReadAscii16(ptr, len, value_ptr) |
| |
95 char *ptr; |
| |
96 int len; |
| |
97 unsigned short *value_ptr; |
| |
98 { |
| |
99 unsigned char buf[2]; |
| |
100 Code_t retval; |
| |
101 |
| |
102 retval = ZReadAscii(ptr, len, buf, 2); |
| |
103 if (retval != ZERR_NONE) |
| |
104 return retval; |
| |
105 *value_ptr = (buf[0] << 8) | buf[1]; |
| |
106 return ZERR_NONE; |
| |
107 } |
| |
108 |