int ascii_to_radix40(Radix40 *radix40_data, unsigned char *ascii_data, int max_chars) /* this routine converts a null-terminated ascii character string */ /* to radix 40 representation. The allowable characters are: */ /* A-Z, 0-9, period, comma, hyphen, and space. If any illegal characters */ /* are detected, they will be converted to hyphens, and the return value */ /* will be S_ILLEGAL. */ /* Lowercase letters will be upper-cased without error indication. */ /* The radix40 value will be padded with blanks to a multiple of three */ /* characters. If the number of characters in the ascii string is > max_chars */ /* only max_chars will be converted, and the return value will be S_ILLEGAL. */ /* If no error is detected, the return value will be S_OKAY. */ { int i; unsigned char j; int ascii_length; int result; int words_to_convert; int words_to_clear; int cycle; unsigned current_word_index; result = S_OKAY; ascii_length = strlen((char *)ascii_data); if (ascii_length > max_chars) { ascii_length = max_chars; result = S_ILLEGAL; } words_to_convert = ascii_length / 3; if (ascii_length % 3 != 0) words_to_convert ++; words_to_clear = max_chars / 3; if (max_chars % 3 != 0) words_to_clear ++; memset(radix40_data,0,words_to_clear*sizeof(Radix40)); current_word_index = unsigned(-1); cycle = 0; for (i = 0; i < ascii_length; i ++) { if (cycle == 0) current_word_index ++; j = lookup_chars[ascii_data[i]]; if (j & ILLEGAL) { j = HYPHEN ; /* make it a hyphen */ result = S_ILLEGAL; /* and remember that it was illegal */ } radix40_data[current_word_index] += weights[cycle] * j; cycle = (cycle + 1) % 3; } return(result); }