14192
|
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 * Copyright (c) 1987, 1990 by the Massachusetts Institute of Technology.
|
|
7 * For copying and distribution information, see the file
|
|
8 * "mit-copyright.h".
|
|
9 */
|
|
10
|
|
11 #include "internal.h"
|
|
12
|
|
13 #define Z_cnvt_xtoi(c) ((temp=(c)-'0'),(temp<10)?temp:((temp-='A'-'9'-1),(temp<16)?temp:-1))
|
|
14
|
|
15 Code_t ZReadAscii(ptr, len, field, num)
|
|
16 char *ptr;
|
|
17 int len;
|
|
18 unsigned char *field;
|
|
19 int num;
|
|
20 {
|
|
21 int i;
|
|
22 unsigned int hexbyte;
|
|
23 register int c1, c2;
|
|
24 register unsigned int temp;
|
|
25
|
|
26 for (i=0;i<num;i++) {
|
|
27 if (*ptr == ' ') {
|
|
28 ptr++;
|
|
29 if (--len < 0)
|
|
30 return ZERR_BADFIELD;
|
|
31 }
|
|
32 if (ptr[0] == '0' && ptr[1] == 'x') {
|
|
33 ptr += 2;
|
|
34 len -= 2;
|
|
35 if (len < 0)
|
|
36 return ZERR_BADFIELD;
|
|
37 }
|
|
38 c1 = Z_cnvt_xtoi(ptr[0]);
|
|
39 if (c1 < 0)
|
|
40 return ZERR_BADFIELD;
|
|
41 c2 = Z_cnvt_xtoi(ptr[1]);
|
|
42 if (c2 < 0)
|
|
43 return ZERR_BADFIELD;
|
|
44 hexbyte = (c1 << 4) | c2;
|
|
45 field[i] = hexbyte;
|
|
46 ptr += 2;
|
|
47 len -= 2;
|
|
48 if (len < 0)
|
|
49 return ZERR_BADFIELD;
|
|
50 }
|
|
51
|
|
52 return *ptr ? ZERR_BADFIELD : ZERR_NONE;
|
|
53 }
|
|
54
|
|
55 Code_t ZReadAscii32(ptr, len, value_ptr)
|
|
56 char *ptr;
|
|
57 int len;
|
|
58 unsigned long *value_ptr;
|
|
59 {
|
|
60 unsigned char buf[4];
|
|
61 Code_t retval;
|
|
62
|
|
63 retval = ZReadAscii(ptr, len, buf, 4);
|
|
64 if (retval != ZERR_NONE)
|
|
65 return retval;
|
|
66 *value_ptr = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
|
|
67 return ZERR_NONE;
|
|
68 }
|
|
69
|
|
70 Code_t ZReadAscii16(ptr, len, value_ptr)
|
|
71 char *ptr;
|
|
72 int len;
|
|
73 unsigned short *value_ptr;
|
|
74 {
|
|
75 unsigned char buf[2];
|
|
76 Code_t retval;
|
|
77
|
|
78 retval = ZReadAscii(ptr, len, buf, 2);
|
|
79 if (retval != ZERR_NONE)
|
|
80 return retval;
|
|
81 *value_ptr = (buf[0] << 8) | buf[1];
|
|
82 return ZERR_NONE;
|
|
83 }
|
|
84
|