1700
|
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 * $Source$
|
|
7 * $Author: warmenhoven $
|
|
8 *
|
|
9 * Copyright (c) 1987 by the Massachusetts Institute of Technology.
|
|
10 * For copying and distribution information, see the file
|
|
11 * "mit-copyright.h".
|
|
12 */
|
|
13 /* $Header$ */
|
|
14
|
|
15 #include <internal.h>
|
|
16 #include <assert.h>
|
|
17
|
|
18 #ifndef lint
|
|
19 static const char rcsid_ZMakeAscii_c[] = "$Id: ZMakeAscii.c 1710 2001-04-12 09:21:16Z warmenhoven $";
|
|
20 #endif
|
|
21
|
|
22 static char *itox_chars = "0123456789ABCDEF";
|
|
23
|
|
24 Code_t ZMakeAscii(ptr, len, field, num)
|
|
25 register char *ptr;
|
|
26 int len;
|
|
27 unsigned char *field;
|
|
28 int num;
|
|
29 {
|
|
30 int i;
|
|
31
|
|
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--;
|
|
41 }
|
|
42 *ptr++ = '0';
|
|
43 *ptr++ = 'x';
|
|
44 len -= 2;
|
|
45 }
|
|
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;
|
|
51 }
|
|
52
|
|
53 *ptr = '\0';
|
|
54 return ZERR_NONE;
|
|
55 }
|
|
56
|
|
57 Code_t ZMakeAscii32(ptr, len, value)
|
|
58 register char *ptr;
|
|
59 int len;
|
|
60 unsigned long value;
|
|
61 {
|
|
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;
|
|
76 }
|
|
77
|
|
78 Code_t ZMakeAscii16(ptr, len, value)
|
|
79 register char *ptr;
|
|
80 int len;
|
|
81 unsigned int value;
|
|
82 {
|
|
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;
|
|
93 }
|
|
94
|