sombok.h
Go to the documentation of this file.
/*
* sombok.h - common definitions for Sombok library
*
* Copyright (C) 2009-2012 by Hatuka*nezumi - IKEDA Soji.
*
* This file is part of the Sombok Package. This program is free
* software; you can redistribute it and/or modify it under the terms of
* either the GNU General Public License or the Artistic License, as
* specified in the README file.
*
*/
#ifndef _SOMBOK_H_
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif /* HAVE_STRINGS_H */
#define SOMBOK_VERSION "2.4.0"
#define SOMBOK_UNICHAR_T_IS_WCHAR_T
#define SOMBOK_UNICHAR_T_IS_UNSIGNED_INT
#define SOMBOK_UNICHAR_T_IS_UNSIGNED_LONG
/***
*** Data structure.
***/
/* Primitive types */
typedef unsigned int unichar_t;
typedef unsigned char propval_t;
typedef struct {
unichar_t *str;
size_t len;
} unistr_t;
typedef struct {
size_t idx;
size_t len;
size_t col;
propval_t lbc;
propval_t elbc;
unsigned char flag;
} gcchar_t;
typedef struct {
unichar_t beg;
unichar_t end;
propval_t lbc;
propval_t eaw;
propval_t gcb;
propval_t scr;
} mapent_t;
struct linebreak_t;
typedef struct {
unichar_t *str;
size_t len;
gcchar_t *gcstr;
size_t gclen;
size_t pos;
struct linebreak_t *lbobj;
} gcstring_t;
typedef enum {
LINEBREAK_STATE_NONE = 0,
LINEBREAK_STATE_SOT, LINEBREAK_STATE_SOP, LINEBREAK_STATE_SOL,
LINEBREAK_STATE_LINE,
LINEBREAK_STATE_EOL, LINEBREAK_STATE_EOP, LINEBREAK_STATE_EOT,
LINEBREAK_STATE_MAX
} linebreak_state_t;
typedef void
(*linebreak_ref_func_t) (void *, int, int);
typedef gcstring_t *
(*linebreak_format_func_t) (struct linebreak_t *, linebreak_state_t,
gcstring_t *);
typedef double
(*linebreak_sizing_func_t) (struct linebreak_t *, double,
gcstring_t *, gcstring_t *, gcstring_t *);
typedef gcstring_t *
(*linebreak_urgent_func_t) (struct linebreak_t *, gcstring_t *);
typedef gcstring_t *
(*linebreak_prep_func_t) (struct linebreak_t *, void *, unistr_t *,
unistr_t *);
typedef gcstring_t *
(*linebreak_obs_prep_func_t) (struct linebreak_t *, unistr_t *);
typedef struct linebreak_t {
unsigned long int refcount;
int state;
unistr_t bufstr;
unistr_t bufspc;
double bufcols;
unistr_t unread;
size_t charmax;
double colmax;
double colmin;
mapent_t *map;
size_t mapsiz;
unistr_t newline;
unsigned int options;
void *format_data;
void *sizing_data;
void *urgent_data;
void *user_data;
void *stash;
linebreak_format_func_t format_func;
linebreak_sizing_func_t sizing_func;
linebreak_urgent_func_t urgent_func;
linebreak_obs_prep_func_t user_func;
linebreak_ref_func_t ref_func;
int errnum;
linebreak_prep_func_t * prep_func;
void **prep_data;
} linebreak_t;
/***
*** Constants.
***/
#define PROP_UNKNOWN ((propval_t)~0)
#define LINEBREAK_FLAG_PROHIBIT_BEFORE (1)
#define LINEBREAK_FLAG_ALLOW_BEFORE (2)
#define LINEBREAK_FLAG_BREAK_BEFORE LINEBREAK_FLAG_ALLOW_BEFORE
#define LINEBREAK_DEFAULT_CHARMAX (998)
#define LINEBREAK_OPTION_EASTASIAN_CONTEXT (1)
#define LINEBREAK_OPTION_HANGUL_AS_AL (2)
#define LINEBREAK_OPTION_LEGACY_CM (4)
#define LINEBREAK_OPTION_BREAK_INDENT (8)
#define LINEBREAK_OPTION_COMPLEX_BREAKING (16)
#define LINEBREAK_OPTION_NONSTARTER_LOOSE (32)
#define LINEBREAK_OPTION_VIRAMA_AS_JOINER (64)
#define LINEBREAK_OPTION_WIDE_NONSPACING_W (128)
#define LINEBREAK_STATE_SOT_FORMAT (-LINEBREAK_STATE_SOT)
#define LINEBREAK_STATE_SOP_FORMAT (-LINEBREAK_STATE_SOP)
#define LINEBREAK_STATE_SOL_FORMAT (-LINEBREAK_STATE_SOL)
#define LINEBREAK_REF_STASH (0)
#define LINEBREAK_REF_FORMAT (1)
#define LINEBREAK_REF_SIZING (2)
#define LINEBREAK_REF_URGENT (3)
#define LINEBREAK_REF_USER (4)
#define LINEBREAK_REF_PREP (5)
#define LINEBREAK_ACTION_MANDATORY (4)
#define LINEBREAK_ACTION_DIRECT (3)
#define LINEBREAK_ACTION_INDIRECT (2)
#define LINEBREAK_ACTION_PROHIBITED (1)
#define LINEBREAK_ELONG (-2)
#define LINEBREAK_EEXTN (-3)
#define SOMBOK_UTF8_CHECK_NONE (0)
#define SOMBOK_UTF8_CHECK_MALFORMED (1)
#define SOMBOK_UTF8_CHECK_SURROGATE (2)
#define SOMBOK_UTF8_CHECK_NONUNICODE (3)
/***
*** Public functions, global variables and macros.
***/
extern void linebreak_charprop(linebreak_t *, unichar_t,
propval_t *, propval_t *, propval_t *,
propval_t *);
extern gcstring_t *gcstring_new(unistr_t *, linebreak_t *);
extern gcstring_t *gcstring_new_from_utf8(char *, size_t, int,
linebreak_t *);
extern gcstring_t *gcstring_newcopy(unistr_t *, linebreak_t *);
extern gcstring_t *gcstring_copy(gcstring_t *);
extern void gcstring_destroy(gcstring_t *);
extern gcstring_t *gcstring_append(gcstring_t *, gcstring_t *);
extern size_t gcstring_columns(gcstring_t *);
extern int gcstring_cmp(gcstring_t *, gcstring_t *);
extern gcstring_t *gcstring_concat(gcstring_t *, gcstring_t *);
extern gcchar_t *gcstring_next(gcstring_t *);
extern void gcstring_setpos(gcstring_t *, int);
extern void gcstring_shrink(gcstring_t *, int);
extern gcstring_t *gcstring_substr(gcstring_t *, int, int);
extern gcstring_t *gcstring_replace(gcstring_t *, int, int, gcstring_t *);
#define gcstring_eos(gcstr) \
((gcstr)->gclen <= (gcstr)->pos)
#define gcstring_getpos(gcstr) \
((gcstr)->pos)
extern propval_t gcstring_lbclass(gcstring_t *, int);
extern propval_t gcstring_lbclass_ext(gcstring_t *, int);
extern linebreak_t *linebreak_new(linebreak_ref_func_t);
extern linebreak_t *linebreak_copy(linebreak_t *);
extern linebreak_t *linebreak_incref(linebreak_t *);
extern void linebreak_destroy(linebreak_t *);
extern void linebreak_set_newline(linebreak_t *, unistr_t *);
extern void linebreak_set_stash(linebreak_t *, void *);
extern void linebreak_set_format(linebreak_t *, linebreak_format_func_t,
void *);
extern void linebreak_add_prep(linebreak_t *, linebreak_prep_func_t,
void *);
extern void linebreak_set_sizing(linebreak_t *, linebreak_sizing_func_t,
void *);
extern void linebreak_set_urgent(linebreak_t *, linebreak_urgent_func_t,
void *);
extern void linebreak_set_user(linebreak_t *, linebreak_obs_prep_func_t,
void *);
extern void linebreak_reset(linebreak_t *);
extern void linebreak_update_lbclass(linebreak_t *, unichar_t, propval_t);
extern void linebreak_clear_lbclass(linebreak_t *);
extern void linebreak_update_eawidth(linebreak_t *, unichar_t, propval_t);
extern void linebreak_clear_eawidth(linebreak_t *);
extern propval_t linebreak_search_lbclass(linebreak_t *, unichar_t);
extern propval_t linebreak_search_eawidth(linebreak_t *, unichar_t);
extern void linebreak_merge_lbclass(linebreak_t *, linebreak_t *);
extern void linebreak_merge_eawidth(linebreak_t *, linebreak_t *);
extern propval_t linebreak_eawidth(linebreak_t *, unichar_t); /* obs. */
extern propval_t linebreak_get_lbrule(linebreak_t *, propval_t, propval_t);
extern propval_t linebreak_lbclass(linebreak_t *, unichar_t); /* obs. */
extern gcstring_t **linebreak_break(linebreak_t *, unistr_t *);
extern gcstring_t **linebreak_break_fast(linebreak_t *, unistr_t *);
extern gcstring_t **linebreak_break_from_utf8(linebreak_t *, char *,
size_t, int);
extern gcstring_t **linebreak_break_partial(linebreak_t *, unistr_t *);
extern void linebreak_free_result(gcstring_t **, int);
extern propval_t linebreak_lbrule(propval_t, propval_t); /* obs. */
extern const char *linebreak_unicode_version;
extern const char *linebreak_propvals_EA[];
extern const char *linebreak_propvals_LB[];
extern const char *linebreak_southeastasian_supported;
extern void linebreak_southeastasian_flagbreak(gcstring_t *);
extern unistr_t *sombok_decode_utf8(unistr_t *, size_t, const char *,
size_t, int);
extern char *sombok_encode_utf8(char *, size_t *, size_t, unistr_t *);
/***
*** Built-in callbacks for linebreak_t.
***/
extern gcstring_t *linebreak_format_SIMPLE(linebreak_t *,
linebreak_state_t,
gcstring_t *);
extern gcstring_t *linebreak_format_NEWLINE(linebreak_t *,
linebreak_state_t,
gcstring_t *);
extern gcstring_t *linebreak_format_TRIM(linebreak_t *, linebreak_state_t,
gcstring_t *);
extern gcstring_t *linebreak_prep_URIBREAK(linebreak_t *, void *,
unistr_t *, unistr_t *);
extern double linebreak_sizing_UAX11(linebreak_t *, double, gcstring_t *,
gcstring_t *, gcstring_t *);
extern gcstring_t *linebreak_urgent_ABORT(linebreak_t *, gcstring_t *);
extern gcstring_t *linebreak_urgent_FORCE(linebreak_t *, gcstring_t *);
#define _SOMBOK_H_
#endif /* _SOMBOK_H_ */
#ifdef MALLOC_DEBUG
#include "src/mymalloc.h"
#endif /* MALLOC_DEBUG */
unistr_t::len
size_t len
Definition: sombok.h:53
gcstring_t::gclen
size_t gclen
Definition: sombok.h:106
unichar_t
unsigned int unichar_t
Definition: sombok.h:39
LINEBREAK_STATE_SOL
Definition: sombok.h:117
linebreak_clear_lbclass
void linebreak_clear_lbclass(linebreak_t *)
Definition: charprop.c:540
mapent_t::beg
unichar_t beg
Definition: sombok.h:78
linebreak_set_urgent
void linebreak_set_urgent(linebreak_t *, linebreak_urgent_func_t, void *)
Definition: linebreak.c:418
linebreak_southeastasian_supported
const char * linebreak_southeastasian_supported
Definition: southeastasian.c:28
gcstring_t
Definition: sombok.h:95
linebreak_destroy
void linebreak_destroy(linebreak_t *)
Definition: linebreak.c:218
gcstring_new
gcstring_t * gcstring_new(unistr_t *, linebreak_t *)
Definition: gcstring.c:228
linebreak_t::bufspc
unistr_t bufspc
Definition: sombok.h:151
linebreak_copy
linebreak_t * linebreak_copy(linebreak_t *)
Definition: linebreak.c:69
linebreak_t::bufstr
unistr_t bufstr
Definition: sombok.h:149
linebreak_charprop
void linebreak_charprop(linebreak_t *, unichar_t, propval_t *, propval_t *, propval_t *, propval_t *)
Definition: charprop.c:134
gcstring_new_from_utf8
gcstring_t * gcstring_new_from_utf8(char *, size_t, int, linebreak_t *)
Definition: gcstring.c:314
linebreak_sizing_func_t
double(* linebreak_sizing_func_t)(struct linebreak_t *, double, gcstring_t *, gcstring_t *, gcstring_t *)
Definition: sombok.h:129
gcstring_t::str
unichar_t * str
Definition: sombok.h:99
linebreak_urgent_FORCE
gcstring_t * linebreak_urgent_FORCE(linebreak_t *, gcstring_t *)
Definition: utils.c:540
gcchar_t::flag
unsigned char flag
Definition: sombok.h:71
linebreak_format_TRIM
gcstring_t * linebreak_format_TRIM(linebreak_t *, linebreak_state_t, gcstring_t *)
Definition: utils.c:475
unistr_t
Definition: sombok.h:47
linebreak_t::unread
unistr_t unread
Definition: sombok.h:155
linebreak_t::format_data
void * format_data
Definition: sombok.h:174
gcchar_t::lbc
propval_t lbc
Definition: sombok.h:67
LINEBREAK_STATE_MAX
Definition: sombok.h:120
linebreak_propvals_EA
const char * linebreak_propvals_EA[]
linebreak_t::options
unsigned int options
Definition: sombok.h:172
linebreak_lbrule
propval_t linebreak_lbrule(propval_t, propval_t)
Definition: break.c:280
linebreak_set_stash
void linebreak_set_stash(linebreak_t *, void *)
Definition: linebreak.c:290
linebreak_break_fast
gcstring_t ** linebreak_break_fast(linebreak_t *, unistr_t *)
Definition: break.c:1217
linebreak_add_prep
void linebreak_add_prep(linebreak_t *, linebreak_prep_func_t, void *)
Definition: linebreak.c:335
gcstring_cmp
int gcstring_cmp(gcstring_t *, gcstring_t *)
Definition: gcstring.c:500
linebreak_set_user
void linebreak_set_user(linebreak_t *, linebreak_obs_prep_func_t, void *)
Definition: linebreak.c:443
gcstring_t::pos
size_t pos
Definition: sombok.h:108
linebreak_t::bufcols
double bufcols
Definition: sombok.h:153
linebreak_t::state
int state
Definition: sombok.h:147
linebreak_t::user_func
linebreak_obs_prep_func_t user_func
Definition: sombok.h:189
linebreak_merge_eawidth
void linebreak_merge_eawidth(linebreak_t *, linebreak_t *)
Definition: charprop.c:486
mapent_t::gcb
propval_t gcb
Definition: sombok.h:86
linebreak_state_t
linebreak_state_t
Definition: sombok.h:115
LINEBREAK_STATE_EOT
Definition: sombok.h:119
gcstring_next
gcchar_t * gcstring_next(gcstring_t *)
Definition: gcstring.c:560
linebreak_t::ref_func
linebreak_ref_func_t ref_func
Definition: sombok.h:197
sombok_decode_utf8
unistr_t * sombok_decode_utf8(unistr_t *, size_t, const char *, size_t, int)
Definition: utf8.c:39
gcstring_append
gcstring_t * gcstring_append(gcstring_t *, gcstring_t *)
Definition: gcstring.c:404
sombok_encode_utf8
char * sombok_encode_utf8(char *, size_t *, size_t, unistr_t *)
Definition: utf8.c:206
linebreak_clear_eawidth
void linebreak_clear_eawidth(linebreak_t *)
Definition: charprop.c:551
linebreak_lbclass
propval_t linebreak_lbclass(linebreak_t *, unichar_t)
Definition: linebreak.c:551
LINEBREAK_STATE_SOT
Definition: sombok.h:117
linebreak_ref_func_t
void(* linebreak_ref_func_t)(void *, int, int)
Definition: sombok.h:124
gcstring_setpos
void gcstring_setpos(gcstring_t *, int)
Definition: gcstring.c:577
linebreak_t::sizing_data
void * sizing_data
Definition: sombok.h:175
linebreak_prep_URIBREAK
gcstring_t * linebreak_prep_URIBREAK(linebreak_t *, void *, unistr_t *, unistr_t *)
Definition: utils.c:121
linebreak_t::prep_data
void ** prep_data
Definition: sombok.h:209
linebreak_propvals_LB
const char * linebreak_propvals_LB[]
linebreak_eawidth
propval_t linebreak_eawidth(linebreak_t *, unichar_t)
Definition: linebreak.c:581
gcchar_t
Definition: sombok.h:59
unistr_t::str
unichar_t * str
Definition: sombok.h:51
mapent_t::end
unichar_t end
Definition: sombok.h:80
linebreak_t::errnum
int errnum
Definition: sombok.h:201
linebreak_free_result
void linebreak_free_result(gcstring_t **, int)
Definition: break.c:1349
linebreak_merge_lbclass
void linebreak_merge_lbclass(linebreak_t *, linebreak_t *)
Definition: charprop.c:462
linebreak_t::sizing_func
linebreak_sizing_func_t sizing_func
Definition: sombok.h:184
linebreak_urgent_func_t
gcstring_t *(* linebreak_urgent_func_t)(struct linebreak_t *, gcstring_t *)
Definition: sombok.h:132
mapent_t::eaw
propval_t eaw
Definition: sombok.h:84
linebreak_update_eawidth
void linebreak_update_eawidth(linebreak_t *, unichar_t, propval_t)
Definition: charprop.c:450
gcstring_newcopy
gcstring_t * gcstring_newcopy(unistr_t *, linebreak_t *)
Definition: gcstring.c:290
linebreak_update_lbclass
void linebreak_update_lbclass(linebreak_t *, unichar_t, propval_t)
Definition: charprop.c:437
gcstring_substr
gcstring_t * gcstring_substr(gcstring_t *, int, int)
Definition: gcstring.c:632
mapent_t
Definition: sombok.h:76
LINEBREAK_STATE_SOP
Definition: sombok.h:117
gcstring_t::gcstr
gcchar_t * gcstr
Definition: sombok.h:104
linebreak_t::format_func
linebreak_format_func_t format_func
Definition: sombok.h:182
linebreak_incref
linebreak_t * linebreak_incref(linebreak_t *)
Definition: linebreak.c:52
LINEBREAK_STATE_EOL
Definition: sombok.h:119
linebreak_t::charmax
size_t charmax
Definition: sombok.h:161
linebreak_new
linebreak_t * linebreak_new(linebreak_ref_func_t)
Definition: linebreak.c:30
linebreak_t::urgent_data
void * urgent_data
Definition: sombok.h:176
linebreak_set_format
void linebreak_set_format(linebreak_t *, linebreak_format_func_t, void *)
Definition: linebreak.c:310
linebreak_format_func_t
gcstring_t *(* linebreak_format_func_t)(struct linebreak_t *, linebreak_state_t, gcstring_t *)
Definition: sombok.h:126
linebreak_break_partial
gcstring_t ** linebreak_break_partial(linebreak_t *, unistr_t *)
Definition: break.c:1201
linebreak_t::urgent_func
linebreak_urgent_func_t urgent_func
Definition: sombok.h:186
linebreak_t
Definition: sombok.h:141
linebreak_search_lbclass
propval_t linebreak_search_lbclass(linebreak_t *, unichar_t)
Definition: charprop.c:198
gcstring_copy
gcstring_t * gcstring_copy(gcstring_t *)
Definition: gcstring.c:353
linebreak_t::newline
unistr_t newline
Definition: sombok.h:170
linebreak_t
struct linebreak_t linebreak_t
linebreak_t::refcount
unsigned long int refcount
Definition: sombok.h:145
gcchar_t::len
size_t len
Definition: sombok.h:63
gcstring_t::len
size_t len
Definition: sombok.h:101
linebreak_search_eawidth
propval_t linebreak_search_eawidth(linebreak_t *, unichar_t)
Definition: charprop.c:211
linebreak_set_sizing
void linebreak_set_sizing(linebreak_t *, linebreak_sizing_func_t, void *)
Definition: linebreak.c:394
linebreak_break_from_utf8
gcstring_t ** linebreak_break_from_utf8(linebreak_t *, char *, size_t, int)
Definition: break.c:1331
linebreak_prep_func_t
gcstring_t *(* linebreak_prep_func_t)(struct linebreak_t *, void *, unistr_t *, unistr_t *)
Definition: sombok.h:134
linebreak_t::colmax
double colmax
Definition: sombok.h:163
linebreak_obs_prep_func_t
gcstring_t *(* linebreak_obs_prep_func_t)(struct linebreak_t *, unistr_t *)
Definition: sombok.h:137
mapent_t::scr
propval_t scr
Definition: sombok.h:88
LINEBREAK_STATE_EOP
Definition: sombok.h:119
propval_t
unsigned char propval_t
Definition: sombok.h:43
gcstring_concat
gcstring_t * gcstring_concat(gcstring_t *, gcstring_t *)
Definition: gcstring.c:538
linebreak_unicode_version
const char * linebreak_unicode_version
LINEBREAK_STATE_LINE
Definition: sombok.h:118
linebreak_format_NEWLINE
gcstring_t * linebreak_format_NEWLINE(linebreak_t *, linebreak_state_t, gcstring_t *)
Definition: utils.c:449
gcstring_lbclass
propval_t gcstring_lbclass(gcstring_t *, int)
Definition: gcstring.c:767
linebreak_break
gcstring_t ** linebreak_break(linebreak_t *, unistr_t *)
Definition: break.c:1243
gcstring_lbclass_ext
propval_t gcstring_lbclass_ext(gcstring_t *, int)
Definition: gcstring.c:786
gcstring_t::lbobj
struct linebreak_t * lbobj
Definition: sombok.h:110
linebreak_sizing_UAX11
double linebreak_sizing_UAX11(linebreak_t *, double, gcstring_t *, gcstring_t *, gcstring_t *)
Definition: utils.c:363
gcstring_shrink
void gcstring_shrink(gcstring_t *, int)
Definition: gcstring.c:597
gcchar_t::col
size_t col
Definition: sombok.h:65
linebreak_southeastasian_flagbreak
void linebreak_southeastasian_flagbreak(gcstring_t *)
Definition: southeastasian.c:36
gcstring_destroy
void gcstring_destroy(gcstring_t *)
Definition: gcstring.c:336
linebreak_t::map
mapent_t * map
Definition: sombok.h:167
gcstring_replace
gcstring_t * gcstring_replace(gcstring_t *, int, int, gcstring_t *)
Definition: gcstring.c:710
linebreak_set_newline
void linebreak_set_newline(linebreak_t *, unistr_t *)
Definition: linebreak.c:261
linebreak_t::mapsiz
size_t mapsiz
Definition: sombok.h:168
gcchar_t::idx
size_t idx
Definition: sombok.h:61
linebreak_t::prep_func
linebreak_prep_func_t * prep_func
Definition: sombok.h:207
gcstring_columns
size_t gcstring_columns(gcstring_t *)
Definition: gcstring.c:518
linebreak_t::stash
void * stash
Definition: sombok.h:180
linebreak_reset
void linebreak_reset(linebreak_t *)
Definition: linebreak.c:466
linebreak_urgent_ABORT
gcstring_t * linebreak_urgent_ABORT(linebreak_t *, gcstring_t *)
Definition: utils.c:530
linebreak_t::user_data
void * user_data
Definition: sombok.h:178
linebreak_t::colmin
double colmin
Definition: sombok.h:165
mapent_t::lbc
propval_t lbc
Definition: sombok.h:82
linebreak_get_lbrule
propval_t linebreak_get_lbrule(linebreak_t *, propval_t, propval_t)
Definition: linebreak.c:503
gcchar_t::elbc
propval_t elbc
Definition: sombok.h:69
LINEBREAK_STATE_NONE
Definition: sombok.h:116
linebreak_format_SIMPLE
gcstring_t * linebreak_format_SIMPLE(linebreak_t *, linebreak_state_t, gcstring_t *)
Definition: utils.c:416