*** empty log message ***
[m17n/m17n-lib.git] / src / m17n-core.h
1 /* m17n-core.h -- header file for the CORE API of the m17n library.
2    Copyright (C) 2003, 2004
3      National Institute of Advanced Industrial Science and Technology (AIST)
4      Registration Number H15PRO112
5
6    This file is part of the m17n library.
7
8    The m17n library is free software; you can redistribute it and/or
9    modify it under the terms of the GNU Lesser General Public License
10    as published by the Free Software Foundation; either version 2.1 of
11    the License, or (at your option) any later version.
12
13    The m17n library is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    Lesser General Public License for more details.
17
18    You should have received a copy of the GNU Lesser General Public
19    License along with the m17n library; if not, write to the Free
20    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21    02111-1307, USA.  */
22
23 #ifndef _M17N_CORE_H_
24 #define _M17N_CORE_H_
25
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30
31 /*
32  * Header file for m17n library.
33  */
34
35 /* (C1) Introduction */
36
37 /***en @defgroup m17nIntro Introduction  */
38 /***ja @defgroup m17nIntro ¤Ï¤¸¤á¤Ë  */
39 /*=*/
40
41 #define M17NLIB_MAJOR_VERSION 1
42 #define M17NLIB_MINOR_VERSION 0
43 #define M17NLIB_VERSION_NAME "1.0"
44
45 extern void m17n_init_core (void);
46 #define M17N_INIT() m17n_init_core ()
47 extern void m17n_fini_core (void);
48 #define M17N_FINI() m17n_fini_core ()
49
50 /***en @defgroup m17nCore CORE API  */
51 /***ja @defgroup m17nCore CORE API */
52 /*=*/
53 /*** @ingroup m17nCore */
54 /***en @defgroup m17nObject Managed Object */
55 /***ja @defgroup m17nObject ´ÉÍý²¼¥ª¥Ö¥¸¥§¥¯¥È */
56 /*=*/
57
58 /*** @ingroup m17nObject  */
59 /***en
60     @brief The first member of a managed object.
61
62     When an application program defines a new structure for managed
63     objects, its first member must be of the type @c struct
64     #M17NObjectHead.  Its contents are used by the m17n library, and
65     application programs should never touch them.  */
66
67 typedef struct
68 {
69   void *filler[2];
70 } M17NObjectHead;
71
72 /*=*/
73
74 /* Return a newly allocated managed object.  */
75 extern void *m17n_object_setup (int size, void (*freer) (void *));
76
77 /* Increment the reference count of managed object OBJECT.  */
78 extern int m17n_object_ref (void *object);
79
80 /* Decrement the reference count of managed object OBJECT.  */
81 extern int m17n_object_unref (void *object);
82
83 /*=*/
84
85 /* (C2) Symbol handling */
86
87 /*** @ingroup m17nCore */
88 /***en @defgroup m17nSymbol Symbol  */
89 /***ja @defgroup m17nSymbol ¥·¥ó¥Ü¥ë */
90 /*=*/
91
92 /***
93     @ingroup m17nSymbol */
94 /***en
95     @brief Type of symbols.
96
97     The type #MSymbol is for a @e symbol object.  Its internal
98     structure is concealed from application programs.  */
99
100 /***ja
101     @brief ¥·¥ó¥Ü¥ë¤Î·¿
102
103     #MSymbol ¤Ï¥·¥ó¥Ü¥ë¥ª¥Ö¥¸¥§¥¯¥È¤Î·¿¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë¡£ */
104
105 typedef struct MSymbol *MSymbol;
106
107 /*=*/
108
109 /* Predefined symbols. */ 
110 extern MSymbol Mnil;
111 extern MSymbol Mt;
112 extern MSymbol Mstring;
113 extern MSymbol Msymbol;
114 extern MSymbol Mtext;
115
116 /* Return a symbol of name NAME.  */
117 extern MSymbol msymbol (const char *name);
118
119 /* Return a managing key of name NAME.  */
120 extern MSymbol msymbol_as_managing_key (const char *name);
121
122 /* Return a symbol of name NAME if it already exists.  */
123 extern MSymbol msymbol_exist (const char *name);
124
125 /* Return the name of SYMBOL.  */
126 extern char *msymbol_name (MSymbol symbol);
127
128 /* Give SYMBOL KEY property with value VALUE.  */
129 extern int msymbol_put (MSymbol symbol, MSymbol key, void *val);
130
131 /*** Return KEY property value of SYMBOL.  */
132 extern void *msymbol_get (MSymbol symbol, MSymbol key);
133
134 /* 
135  *  (2-1) Property List
136  */
137
138 /*** @ingroup m17nCore */
139 /***en @defgroup m17nPlist Property List */
140 /***ja @defgroup m17nPlist ¥×¥í¥Ñ¥Æ¥£¥ê¥¹¥È¡¦¥ª¥Ö¥¸¥§¥¯¥È */
141 /*=*/
142
143 /***
144     @ingroup m17nPlist */ 
145 /***en
146     @brief Type of property list objects.
147
148     The type #MPlist is for a property list object.  Its internal
149     structure is concealed from application programs.  */
150
151 typedef struct MPlist MPlist;
152
153 /*=*/
154
155 extern MSymbol Mplist, Minteger;
156
157 extern MPlist *mplist ();
158
159 extern MPlist *mplist_copy (MPlist *plist);
160
161 extern MPlist *mplist_add (MPlist *plist, MSymbol key, void *val);
162
163 extern MPlist *mplist_push (MPlist *plist, MSymbol key, void *val);
164
165 extern void *mplist_pop (MPlist *plist);
166
167 extern MPlist *mplist_put (MPlist *plist, MSymbol key, void *val);
168
169 extern void *mplist_get (MPlist *plist, MSymbol key);
170
171 extern MPlist *mplist_find_by_key (MPlist *plist, MSymbol key);
172
173 extern MPlist *mplist_find_by_value (MPlist *plist, void *val);
174
175 extern MPlist *mplist_next (MPlist *plist);
176
177 extern MPlist *mplist_set (MPlist *plist, MSymbol key, void *val);
178
179 extern int mplist_length (MPlist *plist);
180
181 extern MSymbol mplist_key (MPlist *plist);
182
183 extern void *mplist_value (MPlist *plist);
184
185 /* (S1) Characters */
186
187 /*=*/
188 /*** @ingroup m17nCore */
189 /***en @defgroup m17nCharacter Character */
190 /***ja @defgroup m17nCharacter Ê¸»ú */
191 /*=*/
192
193 #define MCHAR_MAX 0x3FFFFF
194 /*#define MCHAR_MAX 0x7FFFFFFF*/
195
196 extern MSymbol Mscript;
197 extern MSymbol Mname;
198 extern MSymbol Mcategory;
199 extern MSymbol Mcombining_class;
200 extern MSymbol Mbidi_category;
201 extern MSymbol Msimple_case_folding;
202 extern MSymbol Mcomplicated_case_folding;
203
204 extern MSymbol mchar_define_property (char *name, MSymbol type);
205
206 extern void *mchar_get_prop (int c, MSymbol key);
207
208 extern int mchar_put_prop (int c, MSymbol key, void *val);
209
210 /* (C3) Handling chartable */
211
212 /*** @ingroup m17nCore */
213 /***en @defgroup m17nChartable Chartable */
214 /***ja @defgroup m17nChartable Ê¸»ú¥Æ¡¼¥Ö¥ë */
215 /*=*/
216 extern MSymbol Mchar_table;
217
218 /***
219     @ingroup m17nChartable */
220 /***en
221     @brief Type of chartables.
222
223     The type #MCharTable is for a @e chartable objects.  Its
224     internal structure is concealed from application programs.  */
225
226 /***ja
227     @brief Ê¸»ú¥Æ¡¼¥Ö¥ë¤Î·¿
228
229     #MCharTable ·¿¤Ï @e Ê¸»ú¥Æ¡¼¥Ö¥ë ¥ª¥Ö¥¸¥§¥¯¥ÈÍѤι½Â¤ÂΤǤ¢¤ë¡£
230     ÆâÉô¹½Â¤¤Ï¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£  */
231
232 typedef struct MCharTable MCharTable;
233 /*=*/
234
235 extern MCharTable *mchartable (MSymbol key, void *default_value);
236
237 extern void *mchartable_lookup (MCharTable *table, int c);
238
239 extern int mchartable_set (MCharTable *table, int c, void *val);
240
241 extern int mchartable_set_range (MCharTable *table, int from, int to,
242                                  void *val);
243
244 extern int mchartable_map (MCharTable *table, void *ignore,
245                            void (*func) (int from, int to,
246                                          void *val, void *arg), 
247                            void *func_arg);
248
249 extern void mchartable_range (MCharTable *table, int *from, int *to);
250
251 /*
252  *  (5) Handling M-text.
253  *      "M" of M-text stands for:
254  *      o Multilingual
255  *      o Metamorphic
256  *      o More than string
257  */
258
259 /*** @ingroup m17nCore */
260 /***en @defgroup m17nMtext M-text */
261 /***ja @defgroup m17nMtext M-text */
262 /*=*/
263
264 /*
265  * (5-1) M-text basics
266  */
267
268 /*** @ingroup m17nMtext */
269 /***en
270     @brief Type of @e M-texts.
271
272     The type #MText is for an @e M-text object.  Its internal
273     structure is concealed from application programs.  */
274
275 /***ja
276     @brief @e MText Íѹ½Â¤ÂΠ
277
278     #Mtext ¹½Â¤ÂΤϠ@e M-text ¥ª¥Ö¥¸¥§¥¯¥È¤ËÍѤ¤¤é¤ì¤ë¡£ÆâÉô¹½Â¤¤Ï¥¢
279     ¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤«¤é¤Ï¸«¤¨¤Ê¤¤¡£
280
281     @latexonly \IPAlabel{MText} @endlatexonly
282     @latexonly \IPAlabel{MText->MPlist} @endlatexonly  */
283
284 typedef struct MText MText;
285
286 /*=*/
287
288 extern MText *mtext ();
289
290 /*=*/
291
292 /***en
293     @brief Enumeration for specifying the format of an M-text.
294
295     The enum #MTextFormat is used as an argument of the
296     mtext_from_data () function to specify the format of data from
297     which an M-text is created.  */
298
299 enum MTextFormat
300   {
301     MTEXT_FORMAT_US_ASCII,
302     MTEXT_FORMAT_UTF_8,
303     MTEXT_FORMAT_UTF_16LE,
304     MTEXT_FORMAT_UTF_16BE,
305     MTEXT_FORMAT_UTF_32LE,
306     MTEXT_FORMAT_UTF_32BE,
307     MTEXT_FORMAT_MAX
308   };
309 /*=*/
310
311 extern MText *mtext_from_data (void *data, int nitems,
312                                enum MTextFormat format);
313
314
315 /*=*/
316
317 /*
318  *  (5-2) Functions to manipulate M-texts.  They correspond to string
319  *   manipulating functions in libc.
320  *   In the following functions, mtext_XXX() corresponds to strXXX().
321  */
322
323 extern int mtext_len (MText *mt);
324
325 extern int mtext_ref_char (MText *mt, int pos);
326
327 extern int mtext_set_char (MText *mt, int pos, int c);
328
329 extern MText *mtext_copy (MText *mt1, int pos, MText *mt2, int from, int to);
330
331 extern int mtext_compare (MText *mt1, int from1, int to1,
332                           MText *mt2, int from2, int to2);
333
334 extern int mtext_case_compare (MText *mt1, int from1, int to1,
335                                MText *mt2, int from2, int to2);
336
337 extern int mtext_character (MText *mt, int from, int to, int c);
338
339 extern int mtext_del (MText *mt, int from, int to);
340
341 extern int mtext_ins (MText *mt1, int pos, MText *mt2);
342
343 extern int mtext_ins_char (MText *mt, int pos, int c, int n);
344
345 extern MText *mtext_cat_char (MText *mt, int c);
346
347 extern MText *mtext_duplicate (MText *mt, int from, int to);
348
349 extern MText *mtext_dup (MText *mt);
350
351 extern MText *mtext_cat (MText *mt1, MText *mt2);
352
353 extern MText *mtext_ncat (MText *mt1, MText *mt2, int n);
354
355 extern MText *mtext_cpy (MText *mt1, MText *mt2);
356
357 extern MText *mtext_ncpy (MText *mt1, MText *mt2, int n);
358
359 extern int mtext_chr (MText *mt, int c);
360
361 extern int mtext_rchr (MText *mt, int c);
362
363 extern int mtext_cmp (MText *mt1, MText *mt2);
364
365 extern int mtext_ncmp (MText *mt1, MText *mt2, int n);
366
367 extern int mtext_spn (MText *mt1, MText *mt2);
368
369 extern int mtext_cspn (MText *mt1, MText *mt2);
370
371 extern int mtext_pbrk (MText *mt1, MText *mt2);
372
373 extern int mtext_text (MText *mt1, int pos, MText *mt2);
374
375 extern int mtext_search (MText *mt1, int from, int to, MText *mt2);
376
377 extern MText *mtext_tok (MText *mt, MText *delim, int *pos);
378
379 extern int mtext_casecmp (MText *mt1, MText *mt2);
380
381 extern int mtext_ncasecmp (MText *mt1, MText *mt2, int n);
382
383 /*
384  * (5-3) Text properties
385  */
386
387 /*** @ingroup m17nCore */
388 /***en @defgroup m17nTextProperty Text Property */
389 /***ja @defgroup m17nTextProperty ¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£ */
390 /*=*/
391 /*** @ingroup m17nTextProperty */
392 /***en
393     @brief Flag bits to control text property.
394
395     The mtext_property () funciton accepts logical OR of these flag
396     bits as an argument.  They control the behaviour of the created
397     text property as described in the documentation of each flag
398     bit.  */
399
400 enum MTextPropertyControl
401   {
402     /***en If this flag bit is on, an M-text inserted at the start
403         position or at the middle of the text property inherits the
404         text property.  */
405     MTEXTPROP_FRONT_STICKY = 0x01,
406
407     /***en If this flag bit is on, an M-text inserted at the end
408         position or at the middle of the text property inherits the
409         text property.  */
410     MTEXTPROP_REAR_STICKY = 0x02,
411
412     /***en If this flag bit is on, the text property is removed if a
413         text in its region is modified.  */
414     MTEXTPROP_VOLATILE_WEAK = 0x04,
415
416     /***en If this flag bit is on, the text property is removed if a
417         text or the other text property in its region is modified.  */
418     MTEXTPROP_VOLATILE_STRONG = 0x08,
419
420     /***en If this flag bit is on, the text property is not
421         automatically merged with the others.  */
422     MTEXTPROP_NO_MERGE = 0x10,
423
424     MTEXTPROP_CONTROL_MAX = 0x1F
425   };
426
427 /*=*/
428 extern MSymbol Mtext_prop_serializer;
429 extern MSymbol Mtext_prop_deserializer;
430
431
432 /*** @ingroup m17nTextProperty */
433 /***en
434     @brief Type of serializer functions.
435
436     This is the type of serializer functions.  If the key of a symbol
437     property is #Msymbol_prop_serializer, the value must be of this
438     type.
439
440     @seealso Mtext_prop_serialize (), Mtext_prop_serializer
441 */
442
443 typedef MPlist *(*MTextPropSerializeFunc) (void *val);
444
445 /*** @ingroup m17nTextProperty */
446 /***en
447     @brief Type of deserializer functions.
448
449     This is the type of deserializer functions.  If the key of a
450     symbol property is #Msymbol_prop_deserializer, the value must be
451     of this type.
452
453     @seealso Mtext_prop_deserialize (), Mtext_prop_deserializer
454 */
455 typedef void *(*MTextPropDeserializeFunc) (MPlist *plist);
456
457 extern void *mtext_get_prop (MText *mt, int pos, MSymbol key);
458
459 extern int mtext_get_prop_values (MText *mt, int pos, MSymbol key,
460                                   void **values, int num);
461
462 extern int mtext_get_prop_keys (MText *mt, int pos, MSymbol **keys);
463
464 extern int mtext_put_prop (MText *mt, int from, int to,
465                            MSymbol key, void *val);
466
467 extern int mtext_put_prop_values (MText *mt, int from, int to,
468                                   MSymbol key, void **values, int num);
469
470 extern int mtext_push_prop (MText *mt, int from, int to,
471                             MSymbol key, void *val);
472
473 extern int mtext_pop_prop (MText *mt, int from, int to,
474                            MSymbol key);
475
476 extern int mtext_change_prop (MText *mt, int from, int to,
477                               MSymbol key,
478                               int (*func) (int, void ***, int *));
479
480 extern int mtext_prop_range (MText *mt, MSymbol key, int pos,
481                              int *from, int *to, int deeper);
482
483 /*=*/
484 typedef struct MTextProperty MTextProperty;
485
486 /*=*/
487
488 extern MTextProperty *mtext_property (MSymbol key, void *val,
489                                       int control_bits);
490
491 extern MText *mtext_property_mtext (MTextProperty *prop);
492
493 extern MSymbol mtext_property_key (MTextProperty *prop);
494
495 extern void *mtext_property_value (MTextProperty *prop);
496
497 extern int mtext_property_start (MTextProperty *prop);
498
499 extern int mtext_property_end (MTextProperty *prop);
500
501 extern MTextProperty *mtext_get_property (MText *mt, int pos, MSymbol key);
502
503 extern int mtext_get_properties (MText *mt, int pos, MSymbol key,
504                                  MTextProperty **props, int num);
505
506 extern int mtext_attach_property (MText *mt, int from, int to,
507                                   MTextProperty *prop);
508
509 extern int mtext_detach_property (MTextProperty *prop);
510
511 extern int mtext_push_property (MText *mt, int from, int to,
512                                 MTextProperty *prop);
513
514 extern MText *mtext_serialize (MText *mt, int from, int to,
515                                MPlist *property_list);
516
517 extern MText *mtext_deserialize (MText *mt);
518
519 #ifdef __cplusplus
520 }
521 #endif
522
523 #endif /* _M17N_CORE_H_ */
524
525 /*
526   Local Variables:
527   coding: euc-japan
528   End:
529 */