Mercurial > pidgin.yaz
annotate src/protocols/zephyr/ZReadAscii.c @ 11156:339b61819edc
[gaim-migrate @ 13241]
aparently this never got removed when the function did...
committer: Tailor Script <tailor@pidgin.im>
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Mon, 25 Jul 2005 19:36:44 +0000 |
parents | 64895571248f |
children | 26e316f9e136 |
rev | line source |
---|---|
2086 | 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 | |
8792
43d6c08d7e96
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
2086
diff
changeset
|
11 #include "internal.h" |
2086 | 12 #include <assert.h> |
13 | |
14 #define Z_cnvt_xtoi(c) ((temp=(c)-'0'),(temp<10)?temp:((temp-='A'-'9'-1),(temp<16)?temp:-1)) | |
15 | |
16 Code_t ZReadAscii(ptr, len, field, num) | |
17 char *ptr; | |
18 int len; | |
19 unsigned char *field; | |
20 int num; | |
21 { | |
22 int i; | |
23 unsigned int hexbyte; | |
24 register int c1, c2; | |
25 register unsigned int temp; | |
26 | |
27 for (i=0;i<num;i++) { | |
28 if (*ptr == ' ') { | |
29 ptr++; | |
30 if (--len < 0) | |
31 return ZERR_BADFIELD; | |
32 } | |
33 if (ptr[0] == '0' && ptr[1] == 'x') { | |
34 ptr += 2; | |
35 len -= 2; | |
36 if (len < 0) | |
37 return ZERR_BADFIELD; | |
38 } | |
39 c1 = Z_cnvt_xtoi(ptr[0]); | |
40 if (c1 < 0) | |
41 return ZERR_BADFIELD; | |
42 c2 = Z_cnvt_xtoi(ptr[1]); | |
43 if (c2 < 0) | |
44 return ZERR_BADFIELD; | |
45 hexbyte = (c1 << 4) | c2; | |
46 field[i] = hexbyte; | |
47 ptr += 2; | |
48 len -= 2; | |
49 if (len < 0) | |
50 return ZERR_BADFIELD; | |
51 } | |
52 | |
53 return *ptr ? ZERR_BADFIELD : ZERR_NONE; | |
54 } | |
55 | |
56 Code_t ZReadAscii32(ptr, len, value_ptr) | |
57 char *ptr; | |
58 int len; | |
59 unsigned long *value_ptr; | |
60 { | |
61 unsigned char buf[4]; | |
62 Code_t retval; | |
63 | |
64 retval = ZReadAscii(ptr, len, buf, 4); | |
65 if (retval != ZERR_NONE) | |
66 return retval; | |
67 *value_ptr = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; | |
68 return ZERR_NONE; | |
69 } | |
70 | |
71 Code_t ZReadAscii16(ptr, len, value_ptr) | |
72 char *ptr; | |
73 int len; | |
74 unsigned short *value_ptr; | |
75 { | |
76 unsigned char buf[2]; | |
77 Code_t retval; | |
78 | |
79 retval = ZReadAscii(ptr, len, buf, 2); | |
80 if (retval != ZERR_NONE) | |
81 return retval; | |
82 *value_ptr = (buf[0] << 8) | buf[1]; | |
83 return ZERR_NONE; | |
84 } | |
85 |