FTAM/9000 Programmer's Guide
Chapter 10 379
Example Programs
Setting Ae_dir_dn and P_address Utility Example
void
char_to_hex(ch_string, ch_length, padr_string, padr_length)
char *ch_string;
int ch_length;
char *padr_string;
Uint32 *padr_length;
{
static char hex[] = “0123456789ABCDEF”;
int padr_index;
int ch_index;
char ch;
char *position;
if (ch_length % 2 != 0) {
(void)printf(“Character string won't fit into P_address field\n”);
exit(ERROR);
}
/*
** Fill the p_addr byte with zeros.
*/
for (padr_index = 0; padr_index %< (ch_length/2); ++padr_index)
padr_string[padr_index] = 0x00;
padr_index = 0;
ch_index = 0;
while (ch_index %< ch_length) {
/*
** Put the first hex char into first half of byte.
*/
ch = ch_string[ch_index];
if (ch == ‘\0’) {
break;
}
position = strchr(hex, ch);
if (position == NULL) {
(void)printf(“Invalid hex character in P_address\n”);
exit(ERROR);
}
padr_string[padr_index] = (position-hex) %<%< 4;
++ch_index;
/*
** Put the second hex char into second half of byte.
*/
ch = ch_string[ch_index];
if (ch == ‘\0’) {
break;
}
position = strchr(hex, ch);
if (position == NULL) {
(void)printf(“Invalid hex character in P_address\n”);
exit(ERROR);
}
padr_string[padr_index] |= ((position-hex) & 0x0F);
++ch_index;
++padr_index;
}
*padr_length = padr_index;
}