int ascii_to_radix40_2(radix40_data,ascii_data,max_chars) unsigned *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; int j; int ascii_length; int result; int conversion_status; int words_to_convert; int words_to_clear; int cycle; unsigned current_word_index; unsigned char *temp_ascii_data; result = S_OKAY; ascii_length = strlen((char *)ascii_data); if (ascii_length > max_chars) { ascii_length = max_chars; result = S_ILLEGAL; } temp_ascii_data = malloc(ascii_length+1); for (i = 0; i < ascii_length+1; i ++) temp_ascii_data[i] = toupper(ascii_data[i]); 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 ++; for (i = 0; i < words_to_clear; i ++) radix40_data[i] = 0; /* this blanks out the output string */ current_word_index = -1; cycle = 0; for (i = 0; i < ascii_length; i ++) { if (cycle == 0) current_word_index ++; conversion_status = 0; for (j = 0; j < 40; j ++) if (legal_chars[j] == temp_ascii_data[i]) { conversion_status = 1; break; } if (conversion_status == 0) { result = S_ILLEGAL; j = HYPHEN; /* code for hyphen */ } radix40_data[current_word_index] += weights[cycle] * j; cycle = (cycle + 1) % 3; } free(temp_ascii_data); return(result); }