--- psiconv/trunk/program/psiconv/general.c 2004/01/26 12:59:54 188 +++ psiconv/trunk/program/psiconv/general.c 2004/01/26 14:00:40 189 @@ -24,9 +24,12 @@ #include "general.h" #include #include +#include +#include +#include /* Output a UCS2 character in one of the supported encodings. */ -int output_char(psiconv_config config, psiconv_list list, +void output_char(psiconv_config config, psiconv_list list, psiconv_ucs2 character, encoding enc) { psiconv_u8 temp; @@ -34,33 +37,49 @@ if (enc == ENCODING_UCS2) { temp = character >> 8; - if ((res = psiconv_list_add(list,&temp))) - return res; + if ((res = psiconv_list_add(list,&temp))) { + fputs("Out of memory error\n",stderr); + exit(1); + } temp = character & 0xff; - if ((res = psiconv_list_add(list,&temp))) - return res; + if ((res = psiconv_list_add(list,&temp))) { + fputs("Out of memory error\n",stderr); + exit(1); + } } else if (enc == ENCODING_UTF8) { if (character < 0x80) { temp = character; - if ((res = psiconv_list_add(list,&temp))) - return res; + if ((res = psiconv_list_add(list,&temp))) { + fputs("Out of memory error\n",stderr); + exit(1); + } } else if (character < 0x800) { temp = 0xc0 + (character >> 6); - if ((res = psiconv_list_add(list,&temp))) - return res; + if ((res = psiconv_list_add(list,&temp))) { + fputs("Out of memory error\n",stderr); + exit(1); + } temp = 0x80 + (character & 0x3f); - if ((res = psiconv_list_add(list,&temp))) - return res; + if ((res = psiconv_list_add(list,&temp))) { + fputs("Out of memory error\n",stderr); + exit(1); + } } else { temp = 0xe0 + (character >> 12); - if ((res = psiconv_list_add(list,&temp))) - return res; + if ((res = psiconv_list_add(list,&temp))) { + fputs("Out of memory error\n",stderr); + exit(1); + } temp = 0x80 + ((character >> 6) & 0x3f); - if ((res = psiconv_list_add(list,&temp))) - return res; + if ((res = psiconv_list_add(list,&temp))) { + fputs("Out of memory error\n",stderr); + exit(1); + } temp = 0x80 + (character & 0x3f); - if ((res = psiconv_list_add(list,&temp))) - return res; + if ((res = psiconv_list_add(list,&temp))) { + fputs("Out of memory error\n",stderr); + exit(1); + } } } else if (enc == ENCODING_ASCII) { if (character == 0xa0) @@ -69,26 +88,48 @@ temp = '?'; else temp = character; - if ((res = psiconv_list_add(list,&temp))) - return res; + if ((res = psiconv_list_add(list,&temp))) { + fputs("Out of memory error\n",stderr); + exit(1); + } } else if (enc == ENCODING_PSION) { temp = psiconv_unicode_to_char(config,character); - if ((res = psiconv_list_add(list,&temp))) - return res; + if ((res = psiconv_list_add(list,&temp))) { + fputs("Out of memory error\n",stderr); + exit(1); + } } - return 0; } -int output_string(psiconv_config config, psiconv_list list, +void output_string(psiconv_config config, psiconv_list list, psiconv_ucs2 *string, encoding enc) { int i = 0; - int res; while (string[i]) { - if ((res = output_char(config,list,string[i],enc))) - return res; + output_char(config,list,string[i],enc); i++; } - return 0; +} + +void output_simple_chars(psiconv_config config, psiconv_list list, + char *string, encoding enc) +{ + psiconv_ucs2 *ucs_string; + int i; + + if (!(ucs_string = malloc(sizeof(*ucs_string) * (strlen(string) + 1)))) { + fputs("Out of memory error",stderr); + exit(1); + } + for (i = 0; i < strlen(string); i++) { + if ((string[i] != '\n') && ((string[i] < 0x20) || (string[i] > 0x7e))) { + fprintf(stderr,"output_simple_chars unknown char: %02x",string[i]); + exit(1); + } + ucs_string[i] = string[i]; + } + ucs_string[i] = string[i]; + output_string(config,list,ucs_string,enc); + free(ucs_string); }