From a1334b7d76864cbc331d1ff8a440ffced93bdb20 Mon Sep 17 00:00:00 2001 From: behdad Date: Thu, 16 May 2002 11:04:30 +0000 Subject: Type names cleaned (int32, ...). --- ChangeLog | 4 + fribidi.c | 34 +++--- fribidi.h | 64 ++++++----- fribidi_char_sets.c | 12 +-- fribidi_char_sets.h | 4 +- fribidi_char_sets_cap_rtl.c | 8 +- fribidi_char_sets_cap_rtl.h | 4 +- fribidi_char_sets_utf8.c | 18 ++-- fribidi_env.c | 40 ++++--- fribidi_env.h | 21 ++-- fribidi_main.c | 82 +++++++------- fribidi_mem.h | 33 +++--- fribidi_mirroring.c | 4 +- fribidi_types.h | 10 +- fribidi_utils.c | 26 ++--- fribidi_wcwidth.c | 254 ++++++++++++++++++++++---------------------- 16 files changed, 325 insertions(+), 293 deletions(-) diff --git a/ChangeLog b/ChangeLog index f8a7b38..8ba4b9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ * fribidi_wcwidth.c: Updated to latest source of 2002-05-08. * fribidi_wcwidth.i: Added, fribidi_wcwidth.c includes this to reduces changes needed in fribidi_wcwidth.c. + * fribidi_mem.h, fribidi_types.h, *.c: Common type names like int32, + boolean, ..., changed name to have fribidi prefix. + * fribidi_char_sets_utf8.c: Fixed to support 4-byte length utf-8 + sequences. 2002-05-04 Behdad Esfahbod * fribidi_wcwidth.c: Updated to latest source of 2002-05-03. diff --git a/fribidi.c b/fribidi.c index 5566a98..864afab 100644 --- a/fribidi.c +++ b/fribidi.c @@ -748,7 +748,7 @@ fribidi_analyse_string (FriBidiEnv *fribidienv, DBG ("Resolving weak types\n"); { FriBidiCharType last_strong, prev_type_org; - boolean w4; + fribidi_boolean w4; last_strong = base_dir; @@ -797,7 +797,7 @@ fribidi_analyse_string (FriBidiEnv *fribidienv, /* Resolving dependency of loops for rules W4 and W5, W5 may want to prevent W4 to take effect in the next turn, do this through "w4". */ - w4 = TRUE; + w4 = FRIBIDI_TRUE; /* Resolving dependency of loops for rules W4 and W5 with W7, W7 may change an EN to L but it sets the prev_type_org if needed, so W4 and W5 in next turn can still do their works. */ @@ -818,7 +818,7 @@ fribidi_analyse_string (FriBidiEnv *fribidienv, if (this_type == FRIBIDI_TYPE_AL) { RL_TYPE (pp) = FRIBIDI_TYPE_RTL; - w4 = TRUE; + w4 = FRIBIDI_TRUE; prev_type_org = FRIBIDI_TYPE_ON; continue; } @@ -835,7 +835,7 @@ fribidi_analyse_string (FriBidiEnv *fribidienv, RL_TYPE (pp) = prev_type; this_type = RL_TYPE (pp); } - w4 = TRUE; + w4 = FRIBIDI_TRUE; /* W5. A sequence of European terminators adjacent to European numbers changes to All European numbers. */ @@ -844,7 +844,7 @@ fribidi_analyse_string (FriBidiEnv *fribidienv, || next_type == FRIBIDI_TYPE_EN)) { RL_TYPE (pp) = FRIBIDI_TYPE_EN; - w4 = FALSE; + w4 = FRIBIDI_FALSE; this_type = RL_TYPE (pp); } @@ -1079,7 +1079,7 @@ fribidi_remove_bidi_marks (FriBidiEnv *fribidienv, FriBidiLevel *embedding_level_list) { FriBidiStrIndex i, j; - boolean private_from_this = FALSE; + fribidi_boolean private_from_this = FRIBIDI_FALSE; DBG ("Entering fribidi_remove_bidi_marks()\n"); @@ -1087,7 +1087,7 @@ fribidi_remove_bidi_marks (FriBidiEnv *fribidienv, not given by the caller, we have to make a private instance of it. */ if (position_to_this_list && !position_from_this_list) { - private_from_this = TRUE; + private_from_this = FRIBIDI_TRUE; position_from_this_list = (FriBidiStrIndex *) fribidi_malloc (fribidienv, sizeof (FriBidiStrIndex) * @@ -1130,7 +1130,7 @@ fribidi_remove_bidi_marks (FriBidiEnv *fribidienv, * fribidi_log2vis() calls the function_analyse_string() and then * does reordering and fills in the output strings. *----------------------------------------------------------------------*/ -boolean +fribidi_boolean fribidi_log2vis (FriBidiEnv *fribidienv, /* input */ const FriBidiChar *str, FriBidiStrIndex len, @@ -1143,21 +1143,21 @@ fribidi_log2vis (FriBidiEnv *fribidienv, { TypeLink *type_rl_list, *pp = (TypeLink *) NULL; FriBidiLevel max_level; - boolean private_V_to_L = FALSE; + fribidi_boolean private_V_to_L = FRIBIDI_FALSE; DBG ("Entering fribidi_log2vis()\n"); if (len == 0) { DBG ("Leaving fribidi_log2vis()\n"); - return TRUE; + return FRIBIDI_TRUE; } /* If l2v is to be calculated we must have v2l as well. If it is not given by the caller, we have to make a private instance of it. */ if (position_L_to_V_list && !position_V_to_L_list) { - private_V_to_L = TRUE; + private_V_to_L = FRIBIDI_TRUE; position_V_to_L_list = (FriBidiStrIndex *) fribidi_malloc (fribidienv, sizeof (FriBidiStrIndex) * len); @@ -1169,7 +1169,7 @@ fribidi_log2vis (FriBidiEnv *fribidienv, fprintf (stderr, "%s: cannot handle strings > %ld characters\n", FRIBIDI_PACKAGE, (long) FRIBIDI_MAX_STRING_LENGTH); #endif - return FALSE; + return FRIBIDI_FALSE; } fribidi_analyse_string (fribidienv, str, len, pbase_dir, /* output */ @@ -1251,7 +1251,7 @@ fribidi_log2vis (FriBidiEnv *fribidienv, if (pp->level & 1) { FriBidiStrIndex i; - boolean is_nsm_seq, seq_end; + fribidi_boolean is_nsm_seq, seq_end; is_nsm_seq = 0; for (i = RL_POS (pp) + RL_LEN (pp) - 1; i >= RL_POS (pp); @@ -1334,7 +1334,7 @@ fribidi_log2vis (FriBidiEnv *fribidienv, free_rl_list (fribidienv, type_rl_list); DBG ("Leaving fribidi_log2vis()\n"); - return TRUE; + return FRIBIDI_TRUE; } @@ -1342,7 +1342,7 @@ fribidi_log2vis (FriBidiEnv *fribidienv, * fribidi_log2vis_get_embedding_levels() is used in order to just get * the embedding levels. *----------------------------------------------------------------------*/ -boolean +fribidi_boolean fribidi_log2vis_get_embedding_levels (FriBidiEnv *fribidienv, /* input */ const FriBidiChar *str, @@ -1359,7 +1359,7 @@ fribidi_log2vis_get_embedding_levels (FriBidiEnv *fribidienv, if (len == 0) { DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n"); - return TRUE; + return FRIBIDI_TRUE; } fribidi_analyse_string (fribidienv, str, len, pbase_dir, @@ -1377,7 +1377,7 @@ fribidi_log2vis_get_embedding_levels (FriBidiEnv *fribidienv, free_rl_list (fribidienv, type_rl_list); DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n"); - return TRUE; + return FRIBIDI_TRUE; } diff --git a/fribidi.h b/fribidi.h index 101ba30..d963b08 100644 --- a/fribidi.h +++ b/fribidi.h @@ -39,24 +39,28 @@ extern "C" { #endif - boolean fribidi_log2vis (FriBidiEnv *fribidienv, - /* input */ - const FriBidiChar *str, - FriBidiStrIndex len, FriBidiCharType *pbase_dirs, - /* output */ - FriBidiChar *visual_str, - FriBidiStrIndex *position_L_to_V_list, - FriBidiStrIndex *position_V_to_L_list, - FriBidiLevel *embedding_level_list); + fribidi_boolean fribidi_log2vis (FriBidiEnv *fribidienv, + /* input */ + const FriBidiChar *str, + FriBidiStrIndex len, + FriBidiCharType *pbase_dirs, + /* output */ + FriBidiChar *visual_str, + FriBidiStrIndex *position_L_to_V_list, + FriBidiStrIndex *position_V_to_L_list, + FriBidiLevel *embedding_level_list); - boolean fribidi_log2vis_get_embedding_levels (FriBidiEnv *fribidienv, - /* input */ - const FriBidiChar *str, - FriBidiStrIndex len, - FriBidiCharType *pbase_dir, - /* output */ - FriBidiLevel - *embedding_level_list); + fribidi_boolean fribidi_log2vis_get_embedding_levels (FriBidiEnv + *fribidienv, + /* input */ + const FriBidiChar + *str, + FriBidiStrIndex len, + FriBidiCharType + *pbase_dir, + /* output */ + FriBidiLevel + *embedding_level_list); /*====================================================================== * fribidi_remove_bidi_marks() removes bidirectional marks, and returns @@ -96,11 +100,11 @@ extern "C" * character has a mirror, or the input itself. * if mirrored_ch is NULL, just returns if character has a mirror or not. *----------------------------------------------------------------------*/ - boolean fribidi_get_mirror_char (FriBidiEnv *fribidienv, - /* Input */ - FriBidiChar ch, - /* Output */ - FriBidiChar *mirrored_ch); + fribidi_boolean fribidi_get_mirror_char (FriBidiEnv *fribidienv, + /* Input */ + FriBidiChar ch, + /* Output */ + FriBidiChar *mirrored_ch); /*====================================================================== * The following functions were moved to fribidi_env: * - fribidi_mirroring_status() @@ -150,7 +154,7 @@ extern "C" * FriBidiStrIndex sel_span[2] = {10,45}; * * fribidi_map_range(sel_span, - * TRUE, + * FRIBIDI_TRUE, * length, * vis2log_map, * embedding_levels, @@ -161,7 +165,7 @@ extern "C" /* input */ FriBidiStrIndex span[2], FriBidiStrIndex len, - boolean is_v2l_map, + fribidi_boolean is_v2l_map, const FriBidiStrIndex *position_map, const FriBidiLevel *embedding_level_list, /* output */ @@ -172,9 +176,11 @@ extern "C" * was resolved in the rtl direction. This simply involves asking * if the embedding level for the character is odd. *----------------------------------------------------------------------*/ - boolean fribidi_is_char_rtl (FriBidiEnv *fribidienv, - const FriBidiLevel *embedding_level_list, - FriBidiCharType base_dir, FriBidiStrIndex idx); + fribidi_boolean fribidi_is_char_rtl (FriBidiEnv *fribidienv, + const FriBidiLevel + *embedding_level_list, + FriBidiCharType base_dir, + FriBidiStrIndex idx); /*====================================================================== * fribidi_xpos_resolve() does the complicated translation of @@ -236,8 +242,8 @@ extern "C" FriBidiStrIndex *res_log_pos, FriBidiStrIndex *res_vis_pos, int *res_cursor_x_pos, - boolean *res_cursor_dir_is_rtl, - boolean *res_attach_before); + fribidi_boolean * res_cursor_dir_is_rtl, + fribidi_boolean * res_attach_before); /*====================================================================== * fribidi_runs_log2vis takes a list of logical runs and returns a diff --git a/fribidi_char_sets.c b/fribidi_char_sets.c index 33abf77..aed5f5f 100644 --- a/fribidi_char_sets.c +++ b/fribidi_char_sets.c @@ -47,11 +47,11 @@ typedef struct char *(*desc) (void); /* Some charsets like CapRTL may need to change some fribidis tables, by calling this function, they can do this changes. */ - boolean (*enter) (void); + fribidi_boolean (*enter) (void); /* Some charsets like CapRTL may need to change some fribidis tables, by calling this function, they can undo their changes, perhaps to enter another mode. */ - boolean (*leave) (void); + fribidi_boolean (*leave) (void); } FriBidiCharSetHandler; @@ -149,7 +149,7 @@ static FriBidiCharSet current_char_set = FRIBIDI_CHARSET_DEFAULT; /* Some charsets like CapRTL may need to change some fribidis tables, by calling this function, they can do this changes. */ -boolean +fribidi_boolean fribidi_char_set_enter (FriBidiCharSet char_set) { if (char_set != current_char_set && fribidi_char_sets[char_set].enter) @@ -159,19 +159,19 @@ fribidi_char_set_enter (FriBidiCharSet char_set) return (*fribidi_char_sets[char_set].enter) (); } else - return TRUE; + return FRIBIDI_TRUE; } /* Some charsets like CapRTL may need to change some fribidis tables, by calling this function, they can undo their changes, maybe to enter another mode. */ -boolean +fribidi_boolean fribidi_char_set_leave (FriBidiCharSet char_set) { if (char_set == current_char_set && fribidi_char_sets[char_set].leave) return (*fribidi_char_sets[char_set].leave) (); else - return TRUE; + return FRIBIDI_TRUE; } diff --git a/fribidi_char_sets.h b/fribidi_char_sets.h index 22936b2..1d0ae9f 100644 --- a/fribidi_char_sets.h +++ b/fribidi_char_sets.h @@ -92,12 +92,12 @@ extern "C" /* Some charsets like CapRTL may need to change some fribidis tables, by calling this function, they can do this changes. */ - boolean fribidi_char_set_enter (FriBidiCharSet char_set); + fribidi_boolean fribidi_char_set_enter (FriBidiCharSet char_set); /* Some charsets like CapRTL may need to change some fribidis tables, by calling this function, they can undo their changes, perhaps to enter another mode. */ - boolean fribidi_char_set_leave (FriBidiCharSet char_set); + fribidi_boolean fribidi_char_set_leave (FriBidiCharSet char_set); /* Return the charset which name is "s". */ FriBidiCharSet fribidi_parse_charset (char *s); diff --git a/fribidi_char_sets_cap_rtl.c b/fribidi_char_sets_cap_rtl.c index 070284f..db33c28 100644 --- a/fribidi_char_sets_cap_rtl.c +++ b/fribidi_char_sets_cap_rtl.c @@ -253,7 +253,7 @@ fribidi_char_set_desc_cap_rtl (void) return s; } -boolean +fribidi_boolean fribidi_char_set_enter_cap_rtl (void) { if (!caprtl_to_unicode) @@ -297,13 +297,13 @@ fribidi_char_set_enter_cap_rtl (void) } } - return TRUE; + return FRIBIDI_TRUE; } -boolean +fribidi_boolean fribidi_char_set_leave_cap_rtl (void) { - return TRUE; + return FRIBIDI_TRUE; } #endif diff --git a/fribidi_char_sets_cap_rtl.h b/fribidi_char_sets_cap_rtl.h index f20522e..3d58c3c 100644 --- a/fribidi_char_sets_cap_rtl.h +++ b/fribidi_char_sets_cap_rtl.h @@ -37,8 +37,8 @@ extern "C" #define fribidi_char_set_name_cap_rtl "CapRTL" #define fribidi_char_set_title_cap_rtl "CapRTL (Test)" char *fribidi_char_set_desc_cap_rtl (void); - boolean fribidi_char_set_enter_cap_rtl (void); - boolean fribidi_char_set_leave_cap_rtl (void); + fribidi_boolean fribidi_char_set_enter_cap_rtl (void); + fribidi_boolean fribidi_char_set_leave_cap_rtl (void); int fribidi_cap_rtl_to_unicode (char *s, int length, /* Output */ diff --git a/fribidi_char_sets_utf8.c b/fribidi_char_sets_utf8.c index 8537fd5..aba3ee9 100644 --- a/fribidi_char_sets_utf8.c +++ b/fribidi_char_sets_utf8.c @@ -80,16 +80,22 @@ fribidi_unicode_to_utf8 (FriBidiChar *us, int length, char *s) } else if (mychar <= 0x7FF) /* 11 sig bits */ { - *t++ = 0xC0 | (uint8) ((mychar >> 6) & 0x1F); /* upper 5 bits */ - *t++ = 0x80 | (uint8) (mychar & 0x3F); /* lower 6 bits */ + *t++ = 0xC0 | (unsigned char) ((mychar >> 6) & 0x1F); /* upper 5 bits */ + *t++ = 0x80 | (unsigned char) (mychar & 0x3F); /* lower 6 bits */ } else if (mychar <= 0xFFFF) { /* 16 sig bits */ - *t++ = 0xE0 | (uint8) ((mychar >> 12) & 0x0F); /* upper 4 bits */ - *t++ = 0x80 | (uint8) ((mychar >> 6) & 0x3F); /* next 6 bits */ - *t++ = 0x80 | (uint8) (mychar & 0x3F); /* lowest 6 bits */ + *t++ = 0xE0 | (unsigned char) ((mychar >> 12) & 0x0F); /* upper 4 bits */ + *t++ = 0x80 | (unsigned char) ((mychar >> 6) & 0x3F); /* next 6 bits */ + *t++ = 0x80 | (unsigned char) (mychar & 0x3F); /* lowest 6 bits */ + } + else if (mychar < FRIBIDI_UNICODE_CHARS) + { /* 21 sig bits */ + *t++ = 0xF0 | (unsigned char) ((mychar >> 18) & 0x07); /* upper 3 bits */ + *t++ = 0x80 | (unsigned char) ((mychar >> 12) & 0x3F); /* next 6 bits */ + *t++ = 0x80 | (unsigned char) ((mychar >> 6) & 0x3F); /* next 6 bits */ + *t++ = 0x80 | (unsigned char) (mychar & 0x3F); /* lowest 6 bits */ } - /* TODO */ } *t = 0; diff --git a/fribidi_env.c b/fribidi_env.c index 507bc2e..1559f67 100644 --- a/fribidi_env.c +++ b/fribidi_env.c @@ -184,23 +184,26 @@ fribidi_free (FriBidiEnv *fribidienv, void *ptr) * fribidi_mirroring_status() returns whether mirroring is on or off, * default is on. *----------------------------------------------------------------------*/ -boolean +fribidi_boolean fribidi_mirroring_status (FriBidiEnv *fbenv) { VALIDATE_FRIBIDIENV (fbenv); - return (0 != (fbenv->iFlags & FRIBIDIENV_MIRRORING_MODE) ? TRUE : FALSE); + return (0 != + (fbenv-> + iFlags & FRIBIDIENV_MIRRORING_MODE) ? FRIBIDI_TRUE : + FRIBIDI_FALSE); } /*====================================================================== * fribidi_set_mirroring() sets mirroring on or off. *----------------------------------------------------------------------*/ void -fribidi_set_mirroring (FriBidiEnv *fbenv, boolean mirror) +fribidi_set_mirroring (FriBidiEnv *fbenv, fribidi_boolean mirror) { VALIDATE_FRIBIDIENV (fbenv); - if (FALSE != mirror) + if (FRIBIDI_FALSE != mirror) { fbenv->iFlags |= FRIBIDIENV_MIRRORING_MODE; } @@ -214,23 +217,26 @@ fribidi_set_mirroring (FriBidiEnv *fbenv, boolean mirror) * fribidi_reorder_nsm_status() returns whether reordering of nsm * sequences is on or off, default is off. *----------------------------------------------------------------------*/ -boolean +fribidi_boolean fribidi_reorder_nsm_status (FriBidiEnv *fbenv) { VALIDATE_FRIBIDIENV (fbenv); - return (0 != (fbenv->iFlags & FRIBIDIENV_REORDER_NSM_MODE) ? TRUE : FALSE); + return (0 != + (fbenv-> + iFlags & FRIBIDIENV_REORDER_NSM_MODE) ? FRIBIDI_TRUE : + FRIBIDI_FALSE); } /*====================================================================== * fribidi_set_reorder_nsm() sets reordering of nsm sequences on or off. *----------------------------------------------------------------------*/ void -fribidi_set_reorder_nsm (FriBidiEnv *fbenv, boolean reorder) +fribidi_set_reorder_nsm (FriBidiEnv *fbenv, fribidi_boolean reorder) { VALIDATE_FRIBIDIENV (fbenv); - if (FALSE != reorder) + if (FRIBIDI_FALSE != reorder) { fbenv->iFlags |= FRIBIDIENV_REORDER_NSM_MODE; } @@ -244,30 +250,32 @@ fribidi_set_reorder_nsm (FriBidiEnv *fbenv, boolean reorder) * fribidi_debug_status() returns whether debugging is on or off, * default is off. *----------------------------------------------------------------------*/ -boolean +fribidi_boolean fribidi_debug_status (FriBidiEnv *fbenv) { #ifdef DEBUG VALIDATE_FRIBIDIENV (fbenv); - return (0 != (fbenv->iFlags & FRIBIDIENV_DEBUG_MODE) ? TRUE : FALSE); + return (0 != + (fbenv-> + iFlags & FRIBIDIENV_DEBUG_MODE) ? FRIBIDI_TRUE : FRIBIDI_FALSE); #else /* DEBUG */ - return FALSE; + return FRIBIDI_FALSE; #endif /* DEBUG */ } /*====================================================================== * fribidi_set_debug() turn on or off debugging, default is off. * if the library was compiled without DEBUG option, this function - * returns FALSE. + * returns FRIBIDI_FALSE. *----------------------------------------------------------------------*/ -boolean -fribidi_set_debug (FriBidiEnv *fbenv, boolean debug) +fribidi_boolean +fribidi_set_debug (FriBidiEnv *fbenv, fribidi_boolean debug) { #ifdef DEBUG VALIDATE_FRIBIDIENV (fbenv); - if (FALSE != debug) + if (FRIBIDI_FALSE != debug) { fbenv->iFlags |= FRIBIDIENV_DEBUG_MODE; } @@ -277,7 +285,7 @@ fribidi_set_debug (FriBidiEnv *fbenv, boolean debug) } return debug; #else /* DEBUG */ - return FALSE; + return FRIBIDI_FALSE; #endif /* DEBUG */ } diff --git a/fribidi_env.h b/fribidi_env.h index d146f81..723bee2 100644 --- a/fribidi_env.h +++ b/fribidi_env.h @@ -106,7 +106,7 @@ extern "C" * currently defined. * But we want to keep all FriBidiEnv fields word-aligned. */ - typedef uint32 FriBidiFlags; + typedef fribidi_uint32 FriBidiFlags; /* The following is defined in fribidi_mem.h, must be defined * there due to forward references. @@ -135,8 +135,8 @@ extern "C" /* The following are reserved for future expansion without breaking * binary compatibility of existing software. */ - uint32 iReserved1; - uint32 iReserved2; + fribidi_uint32 iReserved1; + fribidi_uint32 iReserved2; void *iReserved3; /* If necessary, will point at extension to FriBidiEnv. */ }; @@ -199,37 +199,38 @@ extern "C" * fribidi_mirroring_status() returns whether mirroring is on or off, * default is on. *----------------------------------------------------------------------*/ - boolean fribidi_mirroring_status (FriBidiEnv *fbenv); + fribidi_boolean fribidi_mirroring_status (FriBidiEnv *fbenv); /*====================================================================== * fribidi_set_mirroring() sets mirroring on or off. *----------------------------------------------------------------------*/ - void fribidi_set_mirroring (FriBidiEnv *fbenv, boolean mirror); + void fribidi_set_mirroring (FriBidiEnv *fbenv, fribidi_boolean mirror); /*====================================================================== * fribidi_reorder_nsm_status() returns whether reordering of nsm * sequences is on or off, default is off. *----------------------------------------------------------------------*/ - boolean fribidi_reorder_nsm_status (FriBidiEnv *fbenv); + fribidi_boolean fribidi_reorder_nsm_status (FriBidiEnv *fbenv); /*====================================================================== * fribidi_set_reorder_nsm() sets reordering of nsm sequences on or off. *----------------------------------------------------------------------*/ - void fribidi_set_reorder_nsm (FriBidiEnv *fbenv, boolean reorder); + void fribidi_set_reorder_nsm (FriBidiEnv *fbenv, fribidi_boolean reorder); /*====================================================================== * fribidi_debug_status() returns whether debugging is on or off, * default is off. Returns false if fribidi is not compiled with debug * enabled. *----------------------------------------------------------------------*/ - boolean fribidi_debug_status (FriBidiEnv *fbenv); + fribidi_boolean fribidi_debug_status (FriBidiEnv *fbenv); /*====================================================================== * fribidi_set_debug() turn on or off debugging, default is off. * if the library was compiled without DEBUG option, this function - * returns FALSE. + * returns FRIBIDI_FALSE. *----------------------------------------------------------------------*/ - boolean fribidi_set_debug (FriBidiEnv *fbenv, boolean debug); + fribidi_boolean fribidi_set_debug (FriBidiEnv *fbenv, + fribidi_boolean debug); /*====================================================================== * Management of various styles of defining and using FriBidiEnv. diff --git a/fribidi_main.c b/fribidi_main.c index 06be6f7..a962bee 100644 --- a/fribidi_main.c +++ b/fribidi_main.c @@ -62,9 +62,9 @@ die (char *fmt, ...) exit (-1); } -boolean do_break, do_pad, do_mirror, do_reorder_nsm, do_clean, show_input, - show_changes; -boolean show_visual, show_basedir, show_ltov, show_vtol, show_levels; +fribidi_boolean do_break, do_pad, do_mirror, do_reorder_nsm, do_clean, + show_input, show_changes; +fribidi_boolean show_visual, show_basedir, show_ltov, show_vtol, show_levels; int text_width; char *char_set; char *bol_text, *eol_text; @@ -162,23 +162,23 @@ int main (int argc, char *argv[]) { int exit_val; - boolean file_found; + fribidi_boolean file_found; char *s; FILE *IN; text_width = 80; - do_break = TRUE; - do_pad = TRUE; - do_mirror = TRUE; - do_clean = FALSE; - do_reorder_nsm = FALSE; - show_input = FALSE; - show_visual = TRUE; - show_basedir = FALSE; - show_ltov = FALSE; - show_vtol = FALSE; - show_levels = FALSE; - show_changes = FALSE; + do_break = FRIBIDI_TRUE; + do_pad = FRIBIDI_TRUE; + do_mirror = FRIBIDI_TRUE; + do_clean = FRIBIDI_FALSE; + do_reorder_nsm = FRIBIDI_FALSE; + show_input = FRIBIDI_FALSE; + show_visual = FRIBIDI_TRUE; + show_basedir = FRIBIDI_FALSE; + show_ltov = FRIBIDI_FALSE; + show_vtol = FRIBIDI_FALSE; + show_levels = FRIBIDI_FALSE; + show_changes = FRIBIDI_FALSE; char_set = "UTF-8"; bol_text = NULL; eol_text = NULL; @@ -213,25 +213,25 @@ main (int argc, char *argv[]) {"charsetdesc", 1, 0, CHARSETDESC}, {"caprtl", 0, 0, CAPRTL}, #endif - {"showinput", 0, &show_input, TRUE}, - {"nopad", 0, &do_pad, FALSE}, - {"nobreak", 0, &do_break, FALSE}, + {"showinput", 0, &show_input, FRIBIDI_TRUE}, + {"nopad", 0, &do_pad, FRIBIDI_FALSE}, + {"nobreak", 0, &do_break, FRIBIDI_FALSE}, {"width", 1, 0, 'w'}, {"bol", 1, 0, 'B'}, {"eol", 1, 0, 'E'}, - {"nomirror", 0, &do_mirror, FALSE}, - {"reordernsm", 0, &do_reorder_nsm, TRUE}, - {"clean", 0, &do_clean, TRUE}, + {"nomirror", 0, &do_mirror, FRIBIDI_FALSE}, + {"reordernsm", 0, &do_reorder_nsm, FRIBIDI_TRUE}, + {"clean", 0, &do_clean, FRIBIDI_TRUE}, {"ltr", 0, (int *) &input_base_direction, FRIBIDI_TYPE_L}, {"rtl", 0, (int *) &input_base_direction, FRIBIDI_TYPE_R}, {"wltr", 0, (int *) &input_base_direction, FRIBIDI_TYPE_WL}, {"wrtl", 0, (int *) &input_base_direction, FRIBIDI_TYPE_WR}, - {"basedir", 0, &show_basedir, TRUE}, - {"ltov", 0, &show_ltov, TRUE}, - {"vtol", 0, &show_vtol, TRUE}, - {"levels", 0, &show_levels, TRUE}, - {"changes", 0, &show_changes, TRUE}, - {"novisual", 0, &show_visual, FALSE}, + {"basedir", 0, &show_basedir, FRIBIDI_TRUE}, + {"ltov", 0, &show_ltov, FRIBIDI_TRUE}, + {"vtol", 0, &show_vtol, FRIBIDI_TRUE}, + {"levels", 0, &show_levels, FRIBIDI_TRUE}, + {"changes", 0, &show_changes, FRIBIDI_TRUE}, + {"novisual", 0, &show_visual, FRIBIDI_FALSE}, {0, 0, 0, 0} }; @@ -252,11 +252,11 @@ main (int argc, char *argv[]) version (); break; case 'v': - show_basedir = TRUE; - show_ltov = TRUE; - show_vtol = TRUE; - show_levels = TRUE; - show_changes = TRUE; + show_basedir = FRIBIDI_TRUE; + show_ltov = FRIBIDI_TRUE; + show_vtol = FRIBIDI_TRUE; + show_levels = FRIBIDI_TRUE; + show_changes = FRIBIDI_TRUE; break; case 'w': text_width = atoi (optarg); @@ -270,16 +270,16 @@ main (int argc, char *argv[]) eol_text = optarg; break; case 'd': - if (!fribidi_set_debug (NULL, TRUE)) + if (!fribidi_set_debug (NULL, FRIBIDI_TRUE)) die ("%s lib must be compiled with DEBUG option to enable\nturn debug info on.\n", FRIBIDI_PACKAGE); break; case 't': - do_clean = TRUE; - show_input = TRUE; - do_break = FALSE; - do_reorder_nsm = TRUE; + do_clean = FRIBIDI_TRUE; + show_input = FRIBIDI_TRUE; + do_break = FRIBIDI_FALSE; + do_reorder_nsm = FRIBIDI_TRUE; break; case 'c': char_set = strdup (optarg); @@ -329,13 +329,13 @@ main (int argc, char *argv[]) fribidi_set_mirroring (NULL, do_mirror); fribidi_set_reorder_nsm (NULL, do_reorder_nsm); exit_val = 0; - file_found = FALSE; + file_found = FRIBIDI_FALSE; while (optind < argc || !file_found) { char *S_; S_ = optind < argc ? argv[optind++] : "-"; - file_found = TRUE; + file_found = FRIBIDI_TRUE; /* Open the infile for reading */ if (S_[0] == '-' && !S_[1]) @@ -400,7 +400,7 @@ main (int argc, char *argv[]) FriBidiStrIndex *ltov, *vtol; FriBidiLevel *levels; FriBidiStrIndex new_len; - boolean log2vis; + fribidi_boolean log2vis; visual = show_visual ? ALLOCATE (NULL, FriBidiChar, len + 1) : NULL; diff --git a/fribidi_mem.h b/fribidi_mem.h index bc558b6..082195c 100644 --- a/fribidi_mem.h +++ b/fribidi_mem.h @@ -32,21 +32,24 @@ extern "C" { #endif -#define INT8 char -#define INT16 short -#define INT32 long - - typedef int boolean; - - typedef signed INT8 int8; - typedef unsigned INT8 uint8; - typedef signed INT16 int16; - typedef unsigned INT16 uint16; - typedef signed INT32 int32; - typedef unsigned INT32 uint32; - -#define TRUE 1 -#define FALSE 0 +#define FRIBIDI_INT8 char +#define FRIBIDI_INT16 short +#define FRIBIDI_INT32 long +#define FRIBIDI_INT int + + typedef int fribidi_boolean; + + typedef signed FRIBIDI_INT8 fribidi_int8; + typedef unsigned FRIBIDI_INT8 fribidi_uint8; + typedef signed FRIBIDI_INT16 fribidi_int16; + typedef unsigned FRIBIDI_INT16 fribidi_uint16; + typedef signed FRIBIDI_INT32 fribidi_int32; + typedef unsigned FRIBIDI_INT32 fribidi_uint32; + typedef signed FRIBIDI_INT fribidi_int; + typedef unsigned FRIBIDI_INT fribidi_uint; + +#define FRIBIDI_TRUE 1 +#define FRIBIDI_FALSE 0 typedef struct _FriBidiList FriBidiList; struct _FriBidiList diff --git a/fribidi_mirroring.c b/fribidi_mirroring.c index 8857f2a..08c3bdf 100644 --- a/fribidi_mirroring.c +++ b/fribidi_mirroring.c @@ -29,7 +29,7 @@ #include "fribidi_tab_mirroring.i" -boolean +fribidi_boolean fribidi_get_mirror_char (FriBidiEnv *fribidienv, /* Input */ FriBidiChar ch, @@ -37,7 +37,7 @@ fribidi_get_mirror_char (FriBidiEnv *fribidienv, FriBidiChar *mirrored_ch) { int pos, step; - boolean found; + fribidi_boolean found; pos = step = (nFriBidiMirroredChars / 2) + 1; diff --git a/fribidi_types.h b/fribidi_types.h index f7b6b42..558620d 100644 --- a/fribidi_types.h +++ b/fribidi_types.h @@ -30,10 +30,10 @@ extern "C" { #endif - typedef int8 FriBidiLevel; - typedef uint32 FriBidiChar; - typedef int FriBidiStrIndex; - typedef int32 FriBidiMaskType; + typedef fribidi_int8 FriBidiLevel; + typedef fribidi_uint32 FriBidiChar; + typedef fribidi_int FriBidiStrIndex; + typedef fribidi_int32 FriBidiMaskType; typedef FriBidiMaskType FriBidiCharType; char *fribidi_type_name (FriBidiCharType c); @@ -41,7 +41,7 @@ extern "C" /* The following type is used by fribidi_utils */ typedef struct { - int length; + FriBidiStrIndex length; void *attribute; } FriBidiRunType; diff --git a/fribidi_utils.c b/fribidi_utils.c index e632324..d3305f9 100644 --- a/fribidi_utils.c +++ b/fribidi_utils.c @@ -53,7 +53,7 @@ * FriBidiStrIndex sel_span[2] = {10,45}; * * fribidi_map_range(sel_span, - * TRUE, + * FRIBIDI_TRUE, * length, * vis2log_map, * embedding_levels, @@ -64,14 +64,14 @@ void fribidi_map_range (FriBidiEnv *fribidienv, /* input */ FriBidiStrIndex in_span[2], /* Start and end span */ - FriBidiStrIndex len, boolean is_v2l_map, /* Needed for embedding_level */ + FriBidiStrIndex len, fribidi_boolean is_v2l_map, /* Needed for embedding_level */ const FriBidiStrIndex *position_map, const FriBidiLevel *embedding_level_list, /* output */ int *num_mapped_spans, FriBidiStrIndex mapped_spans[63][2]) { FriBidiStrIndex ch_idx; - boolean in_range = FALSE; + fribidi_boolean in_range = FRIBIDI_FALSE; FriBidiStrIndex start_idx = in_span[0]; FriBidiStrIndex end_idx = in_span[1]; @@ -95,14 +95,14 @@ fribidi_map_range (FriBidiEnv *fribidienv, if (!in_range && mapped_pos >= start_idx && mapped_pos < end_idx) { - in_range = TRUE; + in_range = FRIBIDI_TRUE; (*num_mapped_spans)++; mapped_spans[(*num_mapped_spans) - 1][0] = ch_idx; } else if (in_range && (mapped_pos < start_idx || mapped_pos >= end_idx)) { mapped_spans[(*num_mapped_spans) - 1][1] = ch_idx; - in_range = FALSE; + in_range = FRIBIDI_FALSE; } } } @@ -203,8 +203,8 @@ fribidi_xpos_resolve (FriBidiEnv *fribidienv, FriBidiStrIndex *res_log_pos, FriBidiStrIndex *res_vis_pos, int *res_cursor_x_pos, - boolean *res_cursor_dir_is_rtl, - boolean *res_attach_before) + fribidi_boolean * res_cursor_dir_is_rtl, + fribidi_boolean * res_attach_before) { int char_width_sum = 0; FriBidiStrIndex char_idx; @@ -246,11 +246,11 @@ fribidi_xpos_resolve (FriBidiEnv *fribidienv, if (*res_cursor_dir_is_rtl) { log_pos++; - *res_attach_before = FALSE; + *res_attach_before = FRIBIDI_FALSE; } /* LTR */ else - *res_attach_before = TRUE; + *res_attach_before = FRIBIDI_TRUE; *res_cursor_x_pos = x_offset + char_width_sum; } /* We are in the right hand side. */ @@ -260,11 +260,11 @@ fribidi_xpos_resolve (FriBidiEnv *fribidienv, if (!*res_cursor_dir_is_rtl) { log_pos++; - *res_attach_before = FALSE; + *res_attach_before = FRIBIDI_FALSE; } /* RTL */ else - *res_attach_before = TRUE; + *res_attach_before = FRIBIDI_TRUE; *res_cursor_x_pos = x_offset + char_width_sum + char_width; (*res_vis_pos)++; @@ -288,7 +288,7 @@ fribidi_xpos_resolve (FriBidiEnv *fribidienv, *res_log_pos = len; *res_cursor_x_pos = char_width_sum + x_offset; *res_vis_pos = len; - *res_attach_before = TRUE; + *res_attach_before = FRIBIDI_TRUE; } } @@ -301,7 +301,7 @@ fribidi_xpos_resolve (FriBidiEnv *fribidienv, * was resolved in the rtl direction. This simply involves asking * if the embedding level for the character is odd. *----------------------------------------------------------------------*/ -boolean +fribidi_boolean fribidi_is_char_rtl (FriBidiEnv *fribidienv, const FriBidiLevel *embedding_level_list, FriBidiCharType base_dir, FriBidiStrIndex idx) diff --git a/fribidi_wcwidth.c b/fribidi_wcwidth.c index eec17a4..6ffe6a5 100644 --- a/fribidi_wcwidth.c +++ b/fribidi_wcwidth.c @@ -61,27 +61,31 @@ #include "fribidi_wcwidth.i" -struct interval { +struct interval +{ int first; int last; }; /* auxiliary function for binary search in interval table */ -static int bisearch(wchar_t ucs, const struct interval *table, int max) { +static int +bisearch (wchar_t ucs, const struct interval *table, int max) +{ int min = 0; int mid; if (ucs < table[0].first || ucs > table[max].last) return 0; - while (max >= min) { - mid = (min + max) / 2; - if (ucs > table[mid].last) - min = mid + 1; - else if (ucs < table[mid].first) - max = mid - 1; - else - return 1; - } + while (max >= min) + { + mid = (min + max) / 2; + if (ucs > table[mid].last) + min = mid + 1; + else if (ucs < table[mid].first) + max = mid - 1; + else + return 1; + } return 0; } @@ -117,49 +121,50 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) { * in ISO 10646. */ -int mk_wcwidth(wchar_t ucs) +int +mk_wcwidth (wchar_t ucs) { /* sorted list of non-overlapping intervals of non-spacing characters */ /* generated with "uniset +cat=Me +cat=Mn +cat=Cf +1160-11FF +200B c" */ static const struct interval combining[] = { - { 0x0300, 0x034F }, { 0x0360, 0x036F }, { 0x0483, 0x0486 }, - { 0x0488, 0x0489 }, { 0x0591, 0x05A1 }, { 0x05A3, 0x05B9 }, - { 0x05BB, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 }, - { 0x05C4, 0x05C4 }, { 0x064B, 0x0655 }, { 0x0670, 0x0670 }, - { 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED }, - { 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A }, - { 0x07A6, 0x07B0 }, { 0x0901, 0x0902 }, { 0x093C, 0x093C }, - { 0x0941, 0x0948 }, { 0x094D, 0x094D }, { 0x0951, 0x0954 }, - { 0x0962, 0x0963 }, { 0x0981, 0x0981 }, { 0x09BC, 0x09BC }, - { 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD }, { 0x09E2, 0x09E3 }, - { 0x0A02, 0x0A02 }, { 0x0A3C, 0x0A3C }, { 0x0A41, 0x0A42 }, - { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D }, { 0x0A70, 0x0A71 }, - { 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC }, { 0x0AC1, 0x0AC5 }, - { 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD }, { 0x0B01, 0x0B01 }, - { 0x0B3C, 0x0B3C }, { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, - { 0x0B4D, 0x0B4D }, { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, - { 0x0BC0, 0x0BC0 }, { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, - { 0x0C46, 0x0C48 }, { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, - { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD }, - { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D }, { 0x0DCA, 0x0DCA }, - { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 }, { 0x0E31, 0x0E31 }, - { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E }, { 0x0EB1, 0x0EB1 }, - { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC }, { 0x0EC8, 0x0ECD }, - { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 }, { 0x0F37, 0x0F37 }, - { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E }, { 0x0F80, 0x0F84 }, - { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 }, { 0x0F99, 0x0FBC }, - { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 }, { 0x1032, 0x1032 }, - { 0x1036, 0x1037 }, { 0x1039, 0x1039 }, { 0x1058, 0x1059 }, - { 0x1160, 0x11FF }, { 0x1712, 0x1714 }, { 0x1732, 0x1734 }, - { 0x1752, 0x1753 }, { 0x1772, 0x1773 }, { 0x17B7, 0x17BD }, - { 0x17C6, 0x17C6 }, { 0x17C9, 0x17D3 }, { 0x180B, 0x180E }, - { 0x18A9, 0x18A9 }, { 0x200B, 0x200F }, { 0x202A, 0x202E }, - { 0x2060, 0x2063 }, { 0x206A, 0x206F }, { 0x20D0, 0x20EA }, - { 0x302A, 0x302F }, { 0x3099, 0x309A }, { 0xFB1E, 0xFB1E }, - { 0xFE00, 0xFE0F }, { 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF }, - { 0xFFF9, 0xFFFB }, { 0x1D167, 0x1D169 }, { 0x1D173, 0x1D182 }, - { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD }, { 0xE0001, 0xE0001 }, - { 0xE0020, 0xE007F } + {0x0300, 0x034F}, {0x0360, 0x036F}, {0x0483, 0x0486}, + {0x0488, 0x0489}, {0x0591, 0x05A1}, {0x05A3, 0x05B9}, + {0x05BB, 0x05BD}, {0x05BF, 0x05BF}, {0x05C1, 0x05C2}, + {0x05C4, 0x05C4}, {0x064B, 0x0655}, {0x0670, 0x0670}, + {0x06D6, 0x06E4}, {0x06E7, 0x06E8}, {0x06EA, 0x06ED}, + {0x070F, 0x070F}, {0x0711, 0x0711}, {0x0730, 0x074A}, + {0x07A6, 0x07B0}, {0x0901, 0x0902}, {0x093C, 0x093C}, + {0x0941, 0x0948}, {0x094D, 0x094D}, {0x0951, 0x0954}, + {0x0962, 0x0963}, {0x0981, 0x0981}, {0x09BC, 0x09BC}, + {0x09C1, 0x09C4}, {0x09CD, 0x09CD}, {0x09E2, 0x09E3}, + {0x0A02, 0x0A02}, {0x0A3C, 0x0A3C}, {0x0A41, 0x0A42}, + {0x0A47, 0x0A48}, {0x0A4B, 0x0A4D}, {0x0A70, 0x0A71}, + {0x0A81, 0x0A82}, {0x0ABC, 0x0ABC}, {0x0AC1, 0x0AC5}, + {0x0AC7, 0x0AC8}, {0x0ACD, 0x0ACD}, {0x0B01, 0x0B01}, + {0x0B3C, 0x0B3C}, {0x0B3F, 0x0B3F}, {0x0B41, 0x0B43}, + {0x0B4D, 0x0B4D}, {0x0B56, 0x0B56}, {0x0B82, 0x0B82}, + {0x0BC0, 0x0BC0}, {0x0BCD, 0x0BCD}, {0x0C3E, 0x0C40}, + {0x0C46, 0x0C48}, {0x0C4A, 0x0C4D}, {0x0C55, 0x0C56}, + {0x0CBF, 0x0CBF}, {0x0CC6, 0x0CC6}, {0x0CCC, 0x0CCD}, + {0x0D41, 0x0D43}, {0x0D4D, 0x0D4D}, {0x0DCA, 0x0DCA}, + {0x0DD2, 0x0DD4}, {0x0DD6, 0x0DD6}, {0x0E31, 0x0E31}, + {0x0E34, 0x0E3A}, {0x0E47, 0x0E4E}, {0x0EB1, 0x0EB1}, + {0x0EB4, 0x0EB9}, {0x0EBB, 0x0EBC}, {0x0EC8, 0x0ECD}, + {0x0F18, 0x0F19}, {0x0F35, 0x0F35}, {0x0F37, 0x0F37}, + {0x0F39, 0x0F39}, {0x0F71, 0x0F7E}, {0x0F80, 0x0F84}, + {0x0F86, 0x0F87}, {0x0F90, 0x0F97}, {0x0F99, 0x0FBC}, + {0x0FC6, 0x0FC6}, {0x102D, 0x1030}, {0x1032, 0x1032}, + {0x1036, 0x1037}, {0x1039, 0x1039}, {0x1058, 0x1059}, + {0x1160, 0x11FF}, {0x1712, 0x1714}, {0x1732, 0x1734}, + {0x1752, 0x1753}, {0x1772, 0x1773}, {0x17B7, 0x17BD}, + {0x17C6, 0x17C6}, {0x17C9, 0x17D3}, {0x180B, 0x180E}, + {0x18A9, 0x18A9}, {0x200B, 0x200F}, {0x202A, 0x202E}, + {0x2060, 0x2063}, {0x206A, 0x206F}, {0x20D0, 0x20EA}, + {0x302A, 0x302F}, {0x3099, 0x309A}, {0xFB1E, 0xFB1E}, + {0xFE00, 0xFE0F}, {0xFE20, 0xFE23}, {0xFEFF, 0xFEFF}, + {0xFFF9, 0xFFFB}, {0x1D167, 0x1D169}, {0x1D173, 0x1D182}, + {0x1D185, 0x1D18B}, {0x1D1AA, 0x1D1AD}, {0xE0001, 0xE0001}, + {0xE0020, 0xE007F} }; /* test for 8-bit control characters */ @@ -169,33 +174,30 @@ int mk_wcwidth(wchar_t ucs) return -1; /* binary search in table of non-spacing characters */ - if (bisearch(ucs, combining, - sizeof(combining) / sizeof(struct interval) - 1)) + if (bisearch (ucs, combining, + sizeof (combining) / sizeof (struct interval) - 1)) return 0; /* if we arrive here, ucs is not a combining or C0/C1 control character */ - return 1 + - (ucs >= 0x1100 && - (ucs <= 0x115f || /* Hangul Jamo init. consonants */ - ucs == 0x2329 || ucs == 0x232a || - (ucs >= 0x2e80 && ucs <= 0xa4cf && - ucs != 0x303f) || /* CJK ... Yi */ - (ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */ - (ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */ - (ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */ - (ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */ - (ucs >= 0xffe0 && ucs <= 0xffe6) || - (ucs >= 0x20000 && ucs <= 0x2ffff))); + return 1 + (ucs >= 0x1100 && (ucs <= 0x115f || /* Hangul Jamo init. consonants */ + ucs == 0x2329 || ucs == 0x232a || (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs != 0x303f) || /* CJK ... Yi */ + (ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */ + (ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */ + (ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */ + (ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */ + (ucs >= 0xffe0 && ucs <= 0xffe6) || + (ucs >= 0x20000 && ucs <= 0x2ffff))); } -int mk_wcswidth(const wchar_t *pwcs, size_t n) +int +mk_wcswidth (const wchar_t * pwcs, size_t n) { int w, width = 0; - for (;*pwcs && n-- > 0; pwcs++) - if ((w = mk_wcwidth(*pwcs)) < 0) + for (; *pwcs && n-- > 0; pwcs++) + if ((w = mk_wcwidth (*pwcs)) < 0) return -1; else width += w; @@ -213,79 +215,81 @@ int mk_wcswidth(const wchar_t *pwcs, size_t n) * the traditional terminal character-width behaviour. It is not * otherwise recommended for general use. */ -static int mk_wcwidth_cjk(wchar_t ucs) +static int +mk_wcwidth_cjk (wchar_t ucs) { /* sorted list of non-overlapping intervals of East Asian Ambiguous * characters, generated with "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */ static const struct interval ambiguous[] = { - { 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 }, - { 0x00AA, 0x00AA }, { 0x00AD, 0x00AE }, { 0x00B0, 0x00B4 }, - { 0x00B6, 0x00BA }, { 0x00BC, 0x00BF }, { 0x00C6, 0x00C6 }, - { 0x00D0, 0x00D0 }, { 0x00D7, 0x00D8 }, { 0x00DE, 0x00E1 }, - { 0x00E6, 0x00E6 }, { 0x00E8, 0x00EA }, { 0x00EC, 0x00ED }, - { 0x00F0, 0x00F0 }, { 0x00F2, 0x00F3 }, { 0x00F7, 0x00FA }, - { 0x00FC, 0x00FC }, { 0x00FE, 0x00FE }, { 0x0101, 0x0101 }, - { 0x0111, 0x0111 }, { 0x0113, 0x0113 }, { 0x011B, 0x011B }, - { 0x0126, 0x0127 }, { 0x012B, 0x012B }, { 0x0131, 0x0133 }, - { 0x0138, 0x0138 }, { 0x013F, 0x0142 }, { 0x0144, 0x0144 }, - { 0x0148, 0x014B }, { 0x014D, 0x014D }, { 0x0152, 0x0153 }, - { 0x0166, 0x0167 }, { 0x016B, 0x016B }, { 0x01CE, 0x01CE }, - { 0x01D0, 0x01D0 }, { 0x01D2, 0x01D2 }, { 0x01D4, 0x01D4 }, - { 0x01D6, 0x01D6 }, { 0x01D8, 0x01D8 }, { 0x01DA, 0x01DA }, - { 0x01DC, 0x01DC }, { 0x0251, 0x0251 }, { 0x0261, 0x0261 }, - { 0x02C4, 0x02C4 }, { 0x02C7, 0x02C7 }, { 0x02C9, 0x02CB }, - { 0x02CD, 0x02CD }, { 0x02D0, 0x02D0 }, { 0x02D8, 0x02DB }, - { 0x02DD, 0x02DD }, { 0x02DF, 0x02DF }, { 0x0391, 0x03A1 }, - { 0x03A3, 0x03A9 }, { 0x03B1, 0x03C1 }, { 0x03C3, 0x03C9 }, - { 0x0401, 0x0401 }, { 0x0410, 0x044F }, { 0x0451, 0x0451 }, - { 0x2010, 0x2010 }, { 0x2013, 0x2016 }, { 0x2018, 0x2019 }, - { 0x201C, 0x201D }, { 0x2020, 0x2022 }, { 0x2024, 0x2027 }, - { 0x2030, 0x2030 }, { 0x2032, 0x2033 }, { 0x2035, 0x2035 }, - { 0x203B, 0x203B }, { 0x203E, 0x203E }, { 0x2074, 0x2074 }, - { 0x207F, 0x207F }, { 0x2081, 0x2084 }, { 0x20AC, 0x20AC }, - { 0x2103, 0x2103 }, { 0x2105, 0x2105 }, { 0x2109, 0x2109 }, - { 0x2113, 0x2113 }, { 0x2116, 0x2116 }, { 0x2121, 0x2122 }, - { 0x2126, 0x2126 }, { 0x212B, 0x212B }, { 0x2153, 0x2154 }, - { 0x215B, 0x215E }, { 0x2160, 0x216B }, { 0x2170, 0x2179 }, - { 0x2190, 0x2199 }, { 0x21B8, 0x21B9 }, { 0x21D2, 0x21D2 }, - { 0x21D4, 0x21D4 }, { 0x21E7, 0x21E7 }, { 0x2200, 0x2200 }, - { 0x2202, 0x2203 }, { 0x2207, 0x2208 }, { 0x220B, 0x220B }, - { 0x220F, 0x220F }, { 0x2211, 0x2211 }, { 0x2215, 0x2215 }, - { 0x221A, 0x221A }, { 0x221D, 0x2220 }, { 0x2223, 0x2223 }, - { 0x2225, 0x2225 }, { 0x2227, 0x222C }, { 0x222E, 0x222E }, - { 0x2234, 0x2237 }, { 0x223C, 0x223D }, { 0x2248, 0x2248 }, - { 0x224C, 0x224C }, { 0x2252, 0x2252 }, { 0x2260, 0x2261 }, - { 0x2264, 0x2267 }, { 0x226A, 0x226B }, { 0x226E, 0x226F }, - { 0x2282, 0x2283 }, { 0x2286, 0x2287 }, { 0x2295, 0x2295 }, - { 0x2299, 0x2299 }, { 0x22A5, 0x22A5 }, { 0x22BF, 0x22BF }, - { 0x2312, 0x2312 }, { 0x2460, 0x24E9 }, { 0x24EB, 0x24FE }, - { 0x2500, 0x254B }, { 0x2550, 0x2573 }, { 0x2580, 0x258F }, - { 0x2592, 0x2595 }, { 0x25A0, 0x25A1 }, { 0x25A3, 0x25A9 }, - { 0x25B2, 0x25B3 }, { 0x25B6, 0x25B7 }, { 0x25BC, 0x25BD }, - { 0x25C0, 0x25C1 }, { 0x25C6, 0x25C8 }, { 0x25CB, 0x25CB }, - { 0x25CE, 0x25D1 }, { 0x25E2, 0x25E5 }, { 0x25EF, 0x25EF }, - { 0x2605, 0x2606 }, { 0x2609, 0x2609 }, { 0x260E, 0x260F }, - { 0x261C, 0x261C }, { 0x261E, 0x261E }, { 0x2640, 0x2640 }, - { 0x2642, 0x2642 }, { 0x2660, 0x2661 }, { 0x2663, 0x2665 }, - { 0x2667, 0x266A }, { 0x266C, 0x266D }, { 0x266F, 0x266F }, - { 0x273D, 0x273D }, { 0x2776, 0x277F }, { 0xFFFD, 0xFFFD } + {0x00A1, 0x00A1}, {0x00A4, 0x00A4}, {0x00A7, 0x00A8}, + {0x00AA, 0x00AA}, {0x00AD, 0x00AE}, {0x00B0, 0x00B4}, + {0x00B6, 0x00BA}, {0x00BC, 0x00BF}, {0x00C6, 0x00C6}, + {0x00D0, 0x00D0}, {0x00D7, 0x00D8}, {0x00DE, 0x00E1}, + {0x00E6, 0x00E6}, {0x00E8, 0x00EA}, {0x00EC, 0x00ED}, + {0x00F0, 0x00F0}, {0x00F2, 0x00F3}, {0x00F7, 0x00FA}, + {0x00FC, 0x00FC}, {0x00FE, 0x00FE}, {0x0101, 0x0101}, + {0x0111, 0x0111}, {0x0113, 0x0113}, {0x011B, 0x011B}, + {0x0126, 0x0127}, {0x012B, 0x012B}, {0x0131, 0x0133}, + {0x0138, 0x0138}, {0x013F, 0x0142}, {0x0144, 0x0144}, + {0x0148, 0x014B}, {0x014D, 0x014D}, {0x0152, 0x0153}, + {0x0166, 0x0167}, {0x016B, 0x016B}, {0x01CE, 0x01CE}, + {0x01D0, 0x01D0}, {0x01D2, 0x01D2}, {0x01D4, 0x01D4}, + {0x01D6, 0x01D6}, {0x01D8, 0x01D8}, {0x01DA, 0x01DA}, + {0x01DC, 0x01DC}, {0x0251, 0x0251}, {0x0261, 0x0261}, + {0x02C4, 0x02C4}, {0x02C7, 0x02C7}, {0x02C9, 0x02CB}, + {0x02CD, 0x02CD}, {0x02D0, 0x02D0}, {0x02D8, 0x02DB}, + {0x02DD, 0x02DD}, {0x02DF, 0x02DF}, {0x0391, 0x03A1}, + {0x03A3, 0x03A9}, {0x03B1, 0x03C1}, {0x03C3, 0x03C9}, + {0x0401, 0x0401}, {0x0410, 0x044F}, {0x0451, 0x0451}, + {0x2010, 0x2010}, {0x2013, 0x2016}, {0x2018, 0x2019}, + {0x201C, 0x201D}, {0x2020, 0x2022}, {0x2024, 0x2027}, + {0x2030, 0x2030}, {0x2032, 0x2033}, {0x2035, 0x2035}, + {0x203B, 0x203B}, {0x203E, 0x203E}, {0x2074, 0x2074}, + {0x207F, 0x207F}, {0x2081, 0x2084}, {0x20AC, 0x20AC}, + {0x2103, 0x2103}, {0x2105, 0x2105}, {0x2109, 0x2109}, + {0x2113, 0x2113}, {0x2116, 0x2116}, {0x2121, 0x2122}, + {0x2126, 0x2126}, {0x212B, 0x212B}, {0x2153, 0x2154}, + {0x215B, 0x215E}, {0x2160, 0x216B}, {0x2170, 0x2179}, + {0x2190, 0x2199}, {0x21B8, 0x21B9}, {0x21D2, 0x21D2}, + {0x21D4, 0x21D4}, {0x21E7, 0x21E7}, {0x2200, 0x2200}, + {0x2202, 0x2203}, {0x2207, 0x2208}, {0x220B, 0x220B}, + {0x220F, 0x220F}, {0x2211, 0x2211}, {0x2215, 0x2215}, + {0x221A, 0x221A}, {0x221D, 0x2220}, {0x2223, 0x2223}, + {0x2225, 0x2225}, {0x2227, 0x222C}, {0x222E, 0x222E}, + {0x2234, 0x2237}, {0x223C, 0x223D}, {0x2248, 0x2248}, + {0x224C, 0x224C}, {0x2252, 0x2252}, {0x2260, 0x2261}, + {0x2264, 0x2267}, {0x226A, 0x226B}, {0x226E, 0x226F}, + {0x2282, 0x2283}, {0x2286, 0x2287}, {0x2295, 0x2295}, + {0x2299, 0x2299}, {0x22A5, 0x22A5}, {0x22BF, 0x22BF}, + {0x2312, 0x2312}, {0x2460, 0x24E9}, {0x24EB, 0x24FE}, + {0x2500, 0x254B}, {0x2550, 0x2573}, {0x2580, 0x258F}, + {0x2592, 0x2595}, {0x25A0, 0x25A1}, {0x25A3, 0x25A9}, + {0x25B2, 0x25B3}, {0x25B6, 0x25B7}, {0x25BC, 0x25BD}, + {0x25C0, 0x25C1}, {0x25C6, 0x25C8}, {0x25CB, 0x25CB}, + {0x25CE, 0x25D1}, {0x25E2, 0x25E5}, {0x25EF, 0x25EF}, + {0x2605, 0x2606}, {0x2609, 0x2609}, {0x260E, 0x260F}, + {0x261C, 0x261C}, {0x261E, 0x261E}, {0x2640, 0x2640}, + {0x2642, 0x2642}, {0x2660, 0x2661}, {0x2663, 0x2665}, + {0x2667, 0x266A}, {0x266C, 0x266D}, {0x266F, 0x266F}, + {0x273D, 0x273D}, {0x2776, 0x277F}, {0xFFFD, 0xFFFD} }; /* binary search in table of non-spacing characters */ - if (bisearch(ucs, ambiguous, - sizeof(ambiguous) / sizeof(struct interval) - 1)) + if (bisearch (ucs, ambiguous, + sizeof (ambiguous) / sizeof (struct interval) - 1)) return 2; - return mk_wcwidth(ucs); + return mk_wcwidth (ucs); } -int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) +int +mk_wcswidth_cjk (const wchar_t * pwcs, size_t n) { int w, width = 0; - for (;*pwcs && n-- > 0; pwcs++) - if ((w = mk_wcwidth_cjk(*pwcs)) < 0) + for (; *pwcs && n-- > 0; pwcs++) + if ((w = mk_wcwidth_cjk (*pwcs)) < 0) return -1; else width += w; -- cgit v1.2.3