… | |
… | |
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 "error.h" |
22 | #include "error.h" |
22 | #include "compat.h" |
23 | #include "unicode.h" |
23 | |
24 | |
24 | #include <stdio.h> |
25 | #include <stdio.h> |
25 | #include <stdlib.h> |
26 | #include <stdlib.h> |
26 | #include <string.h> |
27 | #include <string.h> |
|
|
28 | #include <strings.h> |
27 | #include <sys/types.h> |
29 | #include <sys/types.h> |
28 | #include <sys/stat.h> |
30 | #include <sys/stat.h> |
29 | #include <unistd.h> |
31 | #include <unistd.h> |
30 | #include <fcntl.h> |
32 | #include <fcntl.h> |
31 | |
33 | |
… | |
… | |
37 | |
39 | |
38 | #ifndef CONFIGURATION_SEARCH_PATH |
40 | #ifndef CONFIGURATION_SEARCH_PATH |
39 | #define CONFIGURATION_SEARCH_PATH "/etc/psiconv.conf:~/.psiconv.conf" |
41 | #define CONFIGURATION_SEARCH_PATH "/etc/psiconv.conf:~/.psiconv.conf" |
40 | #endif |
42 | #endif |
41 | static struct psiconv_config_s default_config = |
43 | static struct psiconv_config_s default_config = |
42 | { PSICONV_VERB_WARN, 2, 0,0,0,psiconv_bool_false,NULL }; |
44 | { PSICONV_VERB_WARN, 2, 0,0,0,psiconv_bool_false,NULL,'?' }; |
43 | |
45 | |
44 | static void psiconv_config_parse_statement(const char *filename, |
46 | static void psiconv_config_parse_statement(const char *filename, |
45 | int linenr, |
47 | int linenr, |
46 | const char *var, int value, |
48 | const char *var, int value, |
47 | psiconv_config *config); |
49 | psiconv_config *config); |
… | |
… | |
63 | void psiconv_config_parse_statement(const char *filename, |
65 | void psiconv_config_parse_statement(const char *filename, |
64 | int linenr, |
66 | int linenr, |
65 | const char *var, int value, |
67 | const char *var, int value, |
66 | psiconv_config *config) |
68 | psiconv_config *config) |
67 | { |
69 | { |
|
|
70 | int charnr; |
|
|
71 | |
68 | if (!(strcasecmp(var,"verbosity"))) { |
72 | if (!(strcasecmp(var,"verbosity"))) { |
69 | if ((value >= 1) && (value <= 4)) |
73 | if ((value >= 1) && (value <= 4)) |
70 | (*config)->verbosity = value; |
74 | (*config)->verbosity = value; |
71 | else |
75 | else |
72 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
76 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
73 | "Verbosity should be between 1 and 4",filename,linenr); |
77 | "Verbosity should be between 1 and 5",filename,linenr); |
74 | } else if (!(strcasecmp(var,"color"))) { |
78 | } else if (!(strcasecmp(var,"color"))) { |
75 | if ((value == 0) || (value == 1)) |
79 | if ((value == 0) || (value == 1)) |
76 | (*config)->color = value; |
80 | (*config)->color = value; |
77 | else |
81 | else |
78 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
82 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
… | |
… | |
99 | if ((value >= 0) && (value <= 32)) |
103 | if ((value >= 0) && (value <= 32)) |
100 | (*config)->bluebits = value; |
104 | (*config)->bluebits = value; |
101 | else |
105 | else |
102 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
106 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
103 | "BlueBits should be between 1 and 32 or 0",filename,linenr); |
107 | "BlueBits should be between 1 and 32 or 0",filename,linenr); |
|
|
108 | } else if (!(strcasecmp(var,"characterset"))) { |
|
|
109 | if ((value >= 0) && (value <= 1)) |
|
|
110 | psiconv_unicode_select_characterset(*config,value); |
|
|
111 | else |
|
|
112 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
|
|
113 | "CharacterSet should be between 0 and 0", |
|
|
114 | filename,linenr); |
|
|
115 | } else if (!(strcasecmp(var,"unknownunicodechar"))) { |
|
|
116 | if ((value >= 1) && (value < 0x10000)) |
|
|
117 | (*config)->unknown_unicode_char = value; |
|
|
118 | else |
|
|
119 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
|
|
120 | "UnknownUnicodeChar should be between 1 and 65535", |
|
|
121 | filename,linenr); |
|
|
122 | } else if (!(strcasecmp(var,"unknownepocchar"))) { |
|
|
123 | if ((value >= 1) && (value < 0x100)) |
|
|
124 | (*config)->unknown_epoc_char = value; |
|
|
125 | else |
|
|
126 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
|
|
127 | "UnknownEPOCChar should be between 1 and 255", |
|
|
128 | filename,linenr); |
|
|
129 | } else if (sscanf(var,"char%d",&charnr) == strlen(var)) { |
|
|
130 | if ((charnr < 0) || (charnr > 255)) |
|
|
131 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
|
|
132 | "CharXXX should have XXX between 0 and 255", |
|
|
133 | filename,linenr); |
|
|
134 | if ((value >= 1) && (value <= 0x10000)) |
|
|
135 | (*config)->unicode_table[charnr] = value; |
|
|
136 | else |
|
|
137 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
|
|
138 | "CharXXX should be between 1 and 65535", |
|
|
139 | filename,linenr); |
104 | } else { |
140 | } else { |
105 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
141 | psiconv_fatal(*config,0,0,"Configuration file %s, line %d: " |
106 | "Unknown variable %s",filename,linenr,var); |
142 | "Unknown variable %s",filename,linenr,var); |
107 | } |
143 | } |
108 | psiconv_debug(*config,0,0,"Configuration file %s, line %d: " |
144 | psiconv_debug(*config,0,0,"Configuration file %s, line %d: " |