Mercurial > pidgin
annotate src/protocols/zephyr/ZMakeAscii.c @ 11125:072d80ba330d
[gaim-migrate @ 13181]
One missed file.
committer: Tailor Script <tailor@pidgin.im>
author | John H. Kelm <johnkelm@gmail.com> |
---|---|
date | Tue, 19 Jul 2005 00:29:59 +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 ZMakeAscii function. | |
3 * | |
4 * Created by: Robert French | |
5 * | |
6 * Copyright (c) 1987 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 static char *itox_chars = "0123456789ABCDEF"; | |
15 | |
16 Code_t ZMakeAscii(ptr, len, field, num) | |
17 register char *ptr; | |
18 int len; | |
19 unsigned char *field; | |
20 int num; | |
21 { | |
22 int i; | |
23 | |
24 for (i=0;i<num;i++) { | |
25 /* we need to add "0x" if we are between 4 byte pieces */ | |
26 if ((i & 3) == 0) { | |
27 if (len < (i?4:3)) | |
28 return ZERR_FIELDLEN; | |
29 /* except at the beginning, put a space in before the "0x" */ | |
30 if (i) { | |
31 *ptr++ = ' '; | |
32 len--; | |
33 } | |
34 *ptr++ = '0'; | |
35 *ptr++ = 'x'; | |
36 len -= 2; | |
37 } | |
38 if (len < 3) | |
39 return ZERR_FIELDLEN; | |
40 *ptr++ = itox_chars[(int) (field[i] >> 4)]; | |
41 *ptr++ = itox_chars[(int) (field[i] & 0xf)]; | |
42 len -= 2; | |
43 } | |
44 | |
45 *ptr = '\0'; | |
46 return ZERR_NONE; | |
47 } | |
48 | |
49 Code_t ZMakeAscii32(ptr, len, value) | |
50 register char *ptr; | |
51 int len; | |
52 unsigned long value; | |
53 { | |
54 if (len < 11) | |
55 return ZERR_FIELDLEN; | |
56 *ptr++ = '0'; | |
57 *ptr++ = 'x'; | |
58 *ptr++ = itox_chars[(value >> 28) & 0xf]; | |
59 *ptr++ = itox_chars[(value >> 24) & 0xf]; | |
60 *ptr++ = itox_chars[(value >> 20) & 0xf]; | |
61 *ptr++ = itox_chars[(value >> 16) & 0xf]; | |
62 *ptr++ = itox_chars[(value >> 12) & 0xf]; | |
63 *ptr++ = itox_chars[(value >> 8) & 0xf]; | |
64 *ptr++ = itox_chars[(value >> 4) & 0xf]; | |
65 *ptr++ = itox_chars[(value >> 0) & 0xf]; | |
66 *ptr = 0; | |
67 return ZERR_NONE; | |
68 } | |
69 | |
70 Code_t ZMakeAscii16(ptr, len, value) | |
71 register char *ptr; | |
72 int len; | |
73 unsigned int value; | |
74 { | |
75 if (len < 7) | |
76 return ZERR_FIELDLEN; | |
77 *ptr++ = '0'; | |
78 *ptr++ = 'x'; | |
79 *ptr++ = itox_chars[(value >> 12) & 0xf]; | |
80 *ptr++ = itox_chars[(value >> 8) & 0xf]; | |
81 *ptr++ = itox_chars[(value >> 4) & 0xf]; | |
82 *ptr++ = itox_chars[(value >> 0) & 0xf]; | |
83 *ptr = 0; | |
84 return ZERR_NONE; | |
85 } | |
86 |