2 Copyright (C) 2004-2007, The Perl Foundation.
7 src/encoding.c - global encoding functions
11 These are parrot's generic encoding handling functions
19 #define PARROT_NO_EXTERN_ENCODING_PTRS
20 #include "parrot/parrot.h"
22 /* HEADERIZER HFILE: include/parrot/encoding.h */
24 /* HEADERIZER BEGIN: static */
25 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
27 static INTVAL
register_encoding(PARROT_INTERP
,
28 ARGIN(const char *encodingname
),
29 ARGIN(ENCODING
*encoding
))
30 __attribute__nonnull__(1)
31 __attribute__nonnull__(2)
32 __attribute__nonnull__(3);
34 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
35 /* HEADERIZER END: static */
37 ENCODING
*Parrot_default_encoding_ptr
;
38 ENCODING
*Parrot_fixed_8_encoding_ptr
;
39 ENCODING
*Parrot_utf8_encoding_ptr
;
40 ENCODING
*Parrot_ucs2_encoding_ptr
;
41 ENCODING
*Parrot_utf16_encoding_ptr
;
43 typedef struct One_encoding
{
44 NOTNULL(ENCODING
*encoding
);
48 typedef struct All_encodings
{
53 static All_encodings
*all_encodings
;
57 =item C<void parrot_init_encodings_2>
59 RT#48260: Not yet documented!!!
66 parrot_init_encodings_2(void)
68 const int n
= all_encodings
->n_encodings
;
71 for (i
= 0; i
< n
; ++i
) {
72 all_encodings
->enc
[i
].name
->charset
= Parrot_default_charset_ptr
;
78 =item C<void parrot_deinit_encodings>
80 RT#48260: Not yet documented!!!
87 parrot_deinit_encodings(void)
89 const int n
= all_encodings
->n_encodings
;
92 for (i
= 0; i
< n
; ++i
) {
93 mem_sys_free(all_encodings
->enc
[i
].encoding
);
95 mem_sys_free(all_encodings
->enc
);
96 mem_sys_free(all_encodings
);
102 =item C<ENCODING * Parrot_new_encoding>
104 RT#48260: Not yet documented!!!
112 PARROT_CANNOT_RETURN_NULL
114 Parrot_new_encoding(SHIM_INTERP
)
116 return mem_allocate_typed(ENCODING
);
121 =item C<const ENCODING * Parrot_find_encoding>
123 RT#48260: Not yet documented!!!
130 PARROT_WARN_UNUSED_RESULT
131 PARROT_CAN_RETURN_NULL
133 Parrot_find_encoding(SHIM_INTERP
, ARGIN(const char *encodingname
))
135 const int n
= all_encodings
->n_encodings
;
138 for (i
= 0; i
< n
; ++i
)
139 if (STREQ(all_encodings
->enc
[i
].encoding
->name
, encodingname
))
140 return all_encodings
->enc
[i
].encoding
;
146 =item C<const ENCODING * Parrot_load_encoding>
148 RT#48260: Not yet documented!!!
154 /* Yep, this needs to be a char * parameter -- it's tough to load in
155 encodings and such for strings if we can't be sure we've got enough
156 info set up to actually build strings... */
159 PARROT_WARN_UNUSED_RESULT
160 PARROT_CANNOT_RETURN_NULL
162 Parrot_load_encoding(PARROT_INTERP
, ARGIN(const char *encodingname
))
164 UNUSED(encodingname
);
165 real_exception(interp
, NULL
, UNIMPLEMENTED
, "Can't load encodings yet");
170 =item C<INTVAL Parrot_encoding_number>
172 Return the number of the encoding or -1 if not found.
179 PARROT_WARN_UNUSED_RESULT
181 Parrot_encoding_number(PARROT_INTERP
, ARGIN(const STRING
*encodingname
))
183 const int n
= all_encodings
->n_encodings
;
186 for (i
= 0; i
< n
; ++i
) {
187 if (!string_equal(interp
, all_encodings
->enc
[i
].name
,
196 =item C<INTVAL Parrot_encoding_number_of_str>
198 Return the number of the encoding of the given string or -1 if not found.
205 PARROT_WARN_UNUSED_RESULT
207 Parrot_encoding_number_of_str(SHIM_INTERP
, ARGIN(const STRING
*src
))
209 const int n
= all_encodings
->n_encodings
;
212 for (i
= 0; i
< n
; ++i
) {
213 if (src
->encoding
== all_encodings
->enc
[i
].encoding
)
221 =item C<STRING* Parrot_encoding_name>
223 RT#48260: Not yet documented!!!
230 PARROT_WARN_UNUSED_RESULT
231 PARROT_CAN_RETURN_NULL
233 Parrot_encoding_name(SHIM_INTERP
, INTVAL number_of_encoding
)
235 if (number_of_encoding
>= all_encodings
->n_encodings
)
237 return all_encodings
->enc
[number_of_encoding
].name
;
242 =item C<const ENCODING* Parrot_get_encoding>
244 RT#48260: Not yet documented!!!
251 PARROT_WARN_UNUSED_RESULT
252 PARROT_CAN_RETURN_NULL
254 Parrot_get_encoding(SHIM_INTERP
, INTVAL number_of_encoding
)
256 if (number_of_encoding
>= all_encodings
->n_encodings
)
258 return all_encodings
->enc
[number_of_encoding
].encoding
;
263 =item C<const char * Parrot_encoding_c_name>
265 RT#48260: Not yet documented!!!
272 PARROT_WARN_UNUSED_RESULT
273 PARROT_CAN_RETURN_NULL
275 Parrot_encoding_c_name(SHIM_INTERP
, INTVAL number_of_encoding
)
277 if (number_of_encoding
>= all_encodings
->n_encodings
)
279 return all_encodings
->enc
[number_of_encoding
].encoding
->name
;
284 =item C<static INTVAL register_encoding>
286 RT#48260: Not yet documented!!!
293 register_encoding(PARROT_INTERP
, ARGIN(const char *encodingname
),
294 ARGIN(ENCODING
*encoding
))
296 const int n
= all_encodings
->n_encodings
;
299 for (i
= 0; i
< n
; ++i
) {
300 if (STREQ(all_encodings
->enc
[i
].encoding
->name
, encodingname
))
305 * this needs either a LOCK or we just forbid dynamic
306 * loading of encodings from inside threads
309 all_encodings
->enc
= mem_allocate_typed(One_encoding
);
311 all_encodings
->enc
= (One_encoding
*)mem_sys_realloc(all_encodings
->enc
,
312 (n
+ 1) * sizeof (One_encoding
));
313 all_encodings
->n_encodings
++;
314 all_encodings
->enc
[n
].encoding
= encoding
;
315 all_encodings
->enc
[n
].name
= const_string(interp
, encodingname
);
322 =item C<INTVAL Parrot_register_encoding>
324 RT#48260: Not yet documented!!!
332 Parrot_register_encoding(PARROT_INTERP
, ARGIN(const char *encodingname
),
333 ARGIN(ENCODING
*encoding
))
335 if (!all_encodings
) {
336 all_encodings
= mem_allocate_typed(All_encodings
);
337 all_encodings
->n_encodings
= 0;
338 all_encodings
->enc
= NULL
;
340 if (STREQ("fixed_8", encodingname
)) {
341 Parrot_fixed_8_encoding_ptr
= encoding
;
342 if (!Parrot_default_encoding_ptr
) {
343 Parrot_default_encoding_ptr
= encoding
;
346 return register_encoding(interp
, encodingname
, encoding
);
348 if (STREQ("utf8", encodingname
)) {
349 Parrot_utf8_encoding_ptr
= encoding
;
350 return register_encoding(interp
, encodingname
, encoding
);
352 if (STREQ("utf16", encodingname
)) {
353 Parrot_utf16_encoding_ptr
= encoding
;
354 return register_encoding(interp
, encodingname
, encoding
);
356 if (STREQ("ucs2", encodingname
)) {
357 Parrot_ucs2_encoding_ptr
= encoding
;
358 return register_encoding(interp
, encodingname
, encoding
);
365 =item C<INTVAL Parrot_make_default_encoding>
367 RT#48260: Not yet documented!!!
375 Parrot_make_default_encoding(SHIM_INTERP
, SHIM(const char *encodingname
),
376 ARGIN(ENCODING
*encoding
))
378 Parrot_default_encoding_ptr
= encoding
;
384 =item C<const ENCODING * Parrot_default_encoding>
386 RT#48260: Not yet documented!!!
393 PARROT_WARN_UNUSED_RESULT
394 PARROT_CANNOT_RETURN_NULL
396 Parrot_default_encoding(SHIM_INTERP
)
398 return Parrot_default_encoding_ptr
;
403 =item C<encoding_converter_t Parrot_find_encoding_converter>
405 RT#48260: Not yet documented!!!
413 Parrot_find_encoding_converter(PARROT_INTERP
, ARGIN(ENCODING
*lhs
), ARGIN(ENCODING
*rhs
))
419 /* XXX Apparently unwritten */
427 * c-file-style: "parrot"
429 * vim: expandtab shiftwidth=4: