[gaim-migrate @ 5229]
[pidgin-git.git] / src / protocols / zephyr / ZMakeAscii.c
blob2765e8ea74d74849c6aaacf69b22fd8a16a0f611
1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains source for the ZMakeAscii function.
4 * Created by: Robert French
6 * $Source$
7 * $Author: warmenhoven $
9 * Copyright (c) 1987 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, see the file
11 * "mit-copyright.h".
13 /* $Header$ */
15 #include <internal.h>
16 #include <assert.h>
18 #ifndef lint
19 static const char rcsid_ZMakeAscii_c[] = "$Id: ZMakeAscii.c 2096 2001-07-31 01:00:39Z warmenhoven $";
20 #endif
22 static char *itox_chars = "0123456789ABCDEF";
24 Code_t ZMakeAscii(ptr, len, field, num)
25 register char *ptr;
26 int len;
27 unsigned char *field;
28 int num;
30 int i;
32 for (i=0;i<num;i++) {
33 /* we need to add "0x" if we are between 4 byte pieces */
34 if ((i & 3) == 0) {
35 if (len < (i?4:3))
36 return ZERR_FIELDLEN;
37 /* except at the beginning, put a space in before the "0x" */
38 if (i) {
39 *ptr++ = ' ';
40 len--;
42 *ptr++ = '0';
43 *ptr++ = 'x';
44 len -= 2;
46 if (len < 3)
47 return ZERR_FIELDLEN;
48 *ptr++ = itox_chars[(int) (field[i] >> 4)];
49 *ptr++ = itox_chars[(int) (field[i] & 0xf)];
50 len -= 2;
53 *ptr = '\0';
54 return ZERR_NONE;
57 Code_t ZMakeAscii32(ptr, len, value)
58 register char *ptr;
59 int len;
60 unsigned long value;
62 if (len < 11)
63 return ZERR_FIELDLEN;
64 *ptr++ = '0';
65 *ptr++ = 'x';
66 *ptr++ = itox_chars[(value >> 28) & 0xf];
67 *ptr++ = itox_chars[(value >> 24) & 0xf];
68 *ptr++ = itox_chars[(value >> 20) & 0xf];
69 *ptr++ = itox_chars[(value >> 16) & 0xf];
70 *ptr++ = itox_chars[(value >> 12) & 0xf];
71 *ptr++ = itox_chars[(value >> 8) & 0xf];
72 *ptr++ = itox_chars[(value >> 4) & 0xf];
73 *ptr++ = itox_chars[(value >> 0) & 0xf];
74 *ptr = 0;
75 return ZERR_NONE;
78 Code_t ZMakeAscii16(ptr, len, value)
79 register char *ptr;
80 int len;
81 unsigned int value;
83 if (len < 7)
84 return ZERR_FIELDLEN;
85 *ptr++ = '0';
86 *ptr++ = 'x';
87 *ptr++ = itox_chars[(value >> 12) & 0xf];
88 *ptr++ = itox_chars[(value >> 8) & 0xf];
89 *ptr++ = itox_chars[(value >> 4) & 0xf];
90 *ptr++ = itox_chars[(value >> 0) & 0xf];
91 *ptr = 0;
92 return ZERR_NONE;