@@ -88,8 +88,7 @@ _CPPP_API int reiconv_lookup_from_codepage(int codepage)
8888
8989_CPPP_API reiconv_t reiconv_open_from_index (int fromcode , int tocode , bool discard_ilseq )
9090{
91- struct conv_struct * cd ;
92- cd = (struct conv_struct * )malloc (sizeof (struct conv_struct ));
91+ struct conv_struct * cd = (struct conv_struct * )malloc (sizeof (struct conv_struct ));
9392 if (cd == NULL )
9493 {
9594 errno = ENOMEM ;
@@ -142,6 +141,51 @@ _CPPP_API reiconv_t reiconv_open_from_name(const char *fromcode, const char *toc
142141 return reiconv_open_from_index (from_index , to_index , discard_ilseq );
143142}
144143
144+ _CPPP_API reiconv_t reiconv_open (const char * tocode , const char * fromcode )
145+ {
146+ char fromcode_buf [MAX_WORD_LENGTH + 2 ];
147+ char tocode_buf [MAX_WORD_LENGTH + 2 ];
148+
149+ size_t fromcode_len = reiconv_name_canonicalize (fromcode , fromcode_buf );
150+ size_t tocode_len = reiconv_name_canonicalize (tocode , tocode_buf );
151+
152+ bool discard_ilseq = false;
153+
154+ for (size_t i = 0 ; i < fromcode_len ; i ++ )
155+ {
156+ if (i < fromcode_len && fromcode_buf [i ] == '/' )
157+ {
158+ fromcode_buf [i ] = '\0' ;
159+ if (i + 7 < fromcode_len && memcmp (fromcode_buf + i + 1 , "/IGNORE" , 8 ) == 0 )
160+ {
161+ discard_ilseq = true;
162+ }
163+ }
164+ }
165+
166+ for (size_t i = 0 ; i < tocode_len ; i ++ )
167+ {
168+ if (tocode_buf [i ] == '/' )
169+ {
170+ tocode_buf [i ] = '\0' ;
171+ if (i + 7 < fromcode_len && memcmp (tocode_buf + i + 1 , "/IGNORE" , 8 ) == 0 )
172+ {
173+ discard_ilseq = true;
174+ }
175+ }
176+ }
177+
178+ int from_index = reiconv_lookup_from_name (fromcode_buf );
179+ int to_index = reiconv_lookup_from_name (tocode_buf );
180+ if (from_index == -1 || to_index == -1 )
181+ {
182+ errno = EINVAL ;
183+ return (reiconv_t )(-1 );
184+ }
185+
186+ return reiconv_open_from_index (from_index , to_index , discard_ilseq );
187+ }
188+
145189_CPPP_API size_t reiconv_iconv (reiconv_t cd , char * * inbuf , size_t * inbytesleft , char * * outbuf , size_t * outbytesleft )
146190{
147191 if (inbuf == NULL || * inbuf == NULL )
0 commit comments