1 | /* |
1 | /* |
2 | parse_aux.c - Part of psiconv, a PSION 5 file formats converter |
2 | parse_aux.c - Part of psiconv, a PSION 5 file formats converter |
3 | Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> |
3 | Copyright (c) 1999, 2000 Frodo Looijaard <frodol@dds.nl> |
4 | |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
8 | (at your option) any later version. |
… | |
… | |
16 | along with this program; if not, write to the Free Software |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
18 | */ |
18 | */ |
19 | |
19 | |
20 | #include "config.h" |
20 | #include "config.h" |
|
|
21 | #include "compat.h" |
21 | #include <stdarg.h> |
22 | #include <stdarg.h> |
22 | #include <stdio.h> |
23 | #include <stdio.h> |
23 | #include <stdlib.h> |
24 | #include <stdlib.h> |
|
|
25 | #include <string.h> |
|
|
26 | #include "common.h" |
24 | |
27 | |
25 | char *psiconv_make_printable(const char *s) |
28 | #ifdef DMALLOC |
|
|
29 | #include <dmalloc.h> |
|
|
30 | #endif |
|
|
31 | |
|
|
32 | |
|
|
33 | char *psiconv_make_printable(const psiconv_config config, |
|
|
34 | const psiconv_string_t input) |
26 | { |
35 | { |
27 | int i; |
36 | int i,len; |
28 | char *res = malloc(strlen(s) + 1); |
37 | psiconv_u8 *intermed; |
29 | if (!res) |
38 | char *output; |
|
|
39 | int res; |
|
|
40 | |
|
|
41 | if ((res = psiconv_unicode_to_chars(config,input,&intermed))) |
30 | return NULL; |
42 | return NULL; |
|
|
43 | |
|
|
44 | len = 0; |
|
|
45 | while (intermed[len]) |
|
|
46 | len++; |
|
|
47 | |
|
|
48 | if (!(output = malloc(sizeof(*output) * (len + 1)))) { |
|
|
49 | free(intermed); |
|
|
50 | return NULL; |
|
|
51 | } |
|
|
52 | |
31 | for (i = 0; i < strlen(s); i ++) |
53 | for (i = 0; i < len; i ++) |
32 | if (s[i] < 0x20 || s[i] >= 0x7f) |
54 | if (intermed[i] < 0x20 || intermed[i] >= 0x7f) |
33 | res[i] = '.'; |
55 | output[i] = '.'; |
34 | else |
56 | else |
35 | res[i] = s[i]; |
57 | output[i] = intermed[i]; |
36 | res[strlen(s)] = 0; |
58 | output[i] = 0; |
37 | return res; |
59 | free(intermed); |
|
|
60 | return output; |
38 | } |
61 | } |