From 3e0814cd9862b89c7a39672672937477bd87ddfb Mon Sep 17 00:00:00 2001 From: Andreas Rottmann Date: Thu, 27 May 2010 18:23:15 +0200 Subject: Imported Upstream version 0.9.3 --- lib/Makefile.am | 18 +- lib/Makefile.gnulib | 399 +- lib/Makefile.in | 601 +- lib/alloca.in.h | 4 +- lib/array-mergesort.h | 302 +- lib/c-ctype.c | 2 +- lib/c-ctype.h | 2 +- lib/c-strcase.h | 3 +- lib/c-strcasecmp.c | 4 +- lib/c-strcaseeq.h | 2 +- lib/c-strncasecmp.c | 4 +- lib/config.charset | 1116 +-- lib/dup2.c | 97 - lib/errno.in.h | 2 +- lib/float+.h | 2 +- lib/float.in.h | 2 +- lib/fpucw.h | 14 +- lib/frexp.c | 120 +- lib/frexpl.c | 2 +- lib/fseterr.c | 6 +- lib/fseterr.h | 2 +- lib/getpagesize.c | 39 - lib/glthread/lock.c | 1058 +++ lib/glthread/lock.h | 927 +++ lib/glthread/threadlib.c | 74 + lib/iconv.in.h | 60 +- lib/iconv_open-solaris.gperf | 30 + lib/iconv_open-solaris.h | 190 + lib/iconv_open.c | 87 +- lib/iconveh.h | 8 +- lib/isnan.c | 20 +- lib/isnand-nolibm.h | 2 +- lib/isnand.c | 2 +- lib/isnanf-nolibm.h | 2 +- lib/isnanf.c | 2 +- lib/isnanl-nolibm.h | 2 +- lib/isnanl.c | 2 +- lib/libunistring.rc | 6 +- lib/localcharset.c | 482 +- lib/localcharset.h | 2 +- lib/localename.c | 2257 ++++-- lib/localename.h | 38 +- lib/malloc.c | 2 +- lib/malloca.c | 66 +- lib/malloca.h | 10 +- lib/math.in.h | 586 +- lib/mbchar.c | 10 +- lib/mbchar.h | 108 +- lib/mbiter.h | 104 +- lib/mbrtowc.c | 474 +- lib/mbsinit.c | 2 +- lib/mbsnlen.c | 4 +- lib/memchr.c | 26 +- lib/memcmp2.c | 6 +- lib/memcmp2.h | 2 +- lib/memxfrm.c | 82 +- lib/memxfrm.h | 2 +- lib/minmax.h | 3 +- lib/printf-args.c | 211 +- lib/printf-args.h | 55 +- lib/printf-frexp.c | 148 +- lib/printf-frexp.h | 2 +- lib/printf-frexpl.c | 2 +- lib/printf-frexpl.h | 2 +- lib/printf-parse.c | 940 +-- lib/printf-parse.h | 21 +- lib/ref-add.sin | 2 +- lib/ref-del.sin | 2 +- lib/relocatable.c | 276 +- lib/relocatable.h | 8 +- lib/signbitd.c | 2 +- lib/signbitf.c | 2 +- lib/signbitl.c | 2 +- lib/size_max.h | 2 +- lib/stdbool.in.h | 5 +- lib/stddef.in.h | 2 +- lib/stdint.in.h | 17 +- lib/stdio-impl.h | 53 +- lib/stdlib.in.h | 622 +- lib/streq.h | 2 +- lib/striconveh.c | 1556 ++-- lib/striconveh.h | 70 +- lib/striconveha.c | 206 +- lib/striconveha.h | 20 +- lib/string.in.h | 735 +- lib/strncat.c | 33 + lib/unicase.h | 306 +- lib/unicase/cased.c | 6 +- lib/unicase/casefold.h | 2 +- lib/unicase/caseprop.h | 2 +- lib/unicase/context.h | 2 +- lib/unicase/empty-prefix-context.c | 2 +- lib/unicase/empty-suffix-context.c | 2 +- lib/unicase/ignorable.c | 14 +- lib/unicase/invariant.h | 32 +- lib/unicase/locale-language.c | 6 +- lib/unicase/simple-mapping.h | 22 +- lib/unicase/special-casing.c | 2 +- lib/unicase/special-casing.h | 2 +- lib/unicase/tocasefold.c | 2 +- lib/unicase/tolower.c | 2 +- lib/unicase/totitle.c | 2 +- lib/unicase/toupper.c | 2 +- lib/unicase/u-casecmp.h | 12 +- lib/unicase/u-casecoll.h | 14 +- lib/unicase/u-casefold.h | 10 +- lib/unicase/u-casemap.h | 630 +- lib/unicase/u-casexfrm.h | 40 +- lib/unicase/u-ct-casefold.h | 90 +- lib/unicase/u-ct-totitle.h | 740 +- lib/unicase/u-is-cased.h | 40 +- lib/unicase/u-is-invariant.h | 20 +- lib/unicase/u-totitle.h | 10 +- lib/unicase/u16-casecmp.c | 2 +- lib/unicase/u16-casecoll.c | 2 +- lib/unicase/u16-casefold.c | 2 +- lib/unicase/u16-casemap.c | 2 +- lib/unicase/u16-casexfrm.c | 2 +- lib/unicase/u16-ct-casefold.c | 2 +- lib/unicase/u16-ct-tolower.c | 18 +- lib/unicase/u16-ct-totitle.c | 2 +- lib/unicase/u16-ct-toupper.c | 18 +- lib/unicase/u16-is-cased.c | 2 +- lib/unicase/u16-is-casefolded.c | 4 +- lib/unicase/u16-is-invariant.c | 3 +- lib/unicase/u16-is-lowercase.c | 4 +- lib/unicase/u16-is-titlecase.c | 4 +- lib/unicase/u16-is-uppercase.c | 4 +- lib/unicase/u16-tolower.c | 16 +- lib/unicase/u16-totitle.c | 2 +- lib/unicase/u16-toupper.c | 16 +- lib/unicase/u32-casecmp.c | 2 +- lib/unicase/u32-casecoll.c | 2 +- lib/unicase/u32-casefold.c | 2 +- lib/unicase/u32-casemap.c | 2 +- lib/unicase/u32-casexfrm.c | 2 +- lib/unicase/u32-ct-casefold.c | 2 +- lib/unicase/u32-ct-tolower.c | 18 +- lib/unicase/u32-ct-totitle.c | 2 +- lib/unicase/u32-ct-toupper.c | 18 +- lib/unicase/u32-is-cased.c | 2 +- lib/unicase/u32-is-casefolded.c | 4 +- lib/unicase/u32-is-invariant.c | 3 +- lib/unicase/u32-is-lowercase.c | 4 +- lib/unicase/u32-is-titlecase.c | 4 +- lib/unicase/u32-is-uppercase.c | 4 +- lib/unicase/u32-tolower.c | 16 +- lib/unicase/u32-totitle.c | 2 +- lib/unicase/u32-toupper.c | 16 +- lib/unicase/u8-casecmp.c | 2 +- lib/unicase/u8-casecoll.c | 2 +- lib/unicase/u8-casefold.c | 46 +- lib/unicase/u8-casemap.c | 2 +- lib/unicase/u8-casexfrm.c | 2 +- lib/unicase/u8-ct-casefold.c | 2 +- lib/unicase/u8-ct-tolower.c | 18 +- lib/unicase/u8-ct-totitle.c | 2 +- lib/unicase/u8-ct-toupper.c | 18 +- lib/unicase/u8-is-cased.c | 2 +- lib/unicase/u8-is-casefolded.c | 4 +- lib/unicase/u8-is-invariant.c | 3 +- lib/unicase/u8-is-lowercase.c | 4 +- lib/unicase/u8-is-titlecase.c | 4 +- lib/unicase/u8-is-uppercase.c | 4 +- lib/unicase/u8-tolower.c | 60 +- lib/unicase/u8-totitle.c | 46 +- lib/unicase/u8-toupper.c | 60 +- lib/unicase/ulc-casecmp.c | 20 +- lib/unicase/ulc-casecoll.c | 2 +- lib/unicase/ulc-casexfrm.c | 20 +- lib/unicase/unicasemap.h | 44 +- lib/uniconv.h | 74 +- lib/uniconv/u-conv-from-enc.h | 44 +- lib/uniconv/u-conv-to-enc.h | 92 +- lib/uniconv/u-strconv-from-enc.h | 8 +- lib/uniconv/u-strconv-to-enc.h | 18 +- lib/uniconv/u16-conv-from-enc.c | 2 +- lib/uniconv/u16-conv-to-enc.c | 106 +- lib/uniconv/u16-strconv-from-enc.c | 2 +- lib/uniconv/u16-strconv-from-locale.c | 2 +- lib/uniconv/u16-strconv-to-enc.c | 2 +- lib/uniconv/u16-strconv-to-locale.c | 2 +- lib/uniconv/u32-conv-from-enc.c | 2 +- lib/uniconv/u32-conv-to-enc.c | 2 +- lib/uniconv/u32-strconv-from-enc.c | 2 +- lib/uniconv/u32-strconv-from-locale.c | 2 +- lib/uniconv/u32-strconv-to-enc.c | 2 +- lib/uniconv/u32-strconv-to-locale.c | 2 +- lib/uniconv/u8-conv-from-enc.c | 86 +- lib/uniconv/u8-conv-to-enc.c | 60 +- lib/uniconv/u8-strconv-from-enc.c | 2 +- lib/uniconv/u8-strconv-from-locale.c | 2 +- lib/uniconv/u8-strconv-to-enc.c | 42 +- lib/uniconv/u8-strconv-to-locale.c | 2 +- lib/unictype.h | 8 +- lib/unictype/bidi_byname.c | 216 +- lib/unictype/bidi_name.c | 2 +- lib/unictype/bidi_of.c | 34 +- lib/unictype/bidi_test.c | 2 +- lib/unictype/bitmap.h | 22 +- lib/unictype/block_test.c | 2 +- lib/unictype/blocks.c | 8 +- lib/unictype/categ_C.c | 2 +- lib/unictype/categ_Cc.c | 2 +- lib/unictype/categ_Cf.c | 2 +- lib/unictype/categ_Cn.c | 2 +- lib/unictype/categ_Co.c | 2 +- lib/unictype/categ_Cs.c | 2 +- lib/unictype/categ_L.c | 2 +- lib/unictype/categ_Ll.c | 2 +- lib/unictype/categ_Lm.c | 2 +- lib/unictype/categ_Lo.c | 2 +- lib/unictype/categ_Lt.c | 2 +- lib/unictype/categ_Lu.c | 2 +- lib/unictype/categ_M.c | 2 +- lib/unictype/categ_Mc.c | 2 +- lib/unictype/categ_Me.c | 2 +- lib/unictype/categ_Mn.c | 2 +- lib/unictype/categ_N.c | 2 +- lib/unictype/categ_Nd.c | 2 +- lib/unictype/categ_Nl.c | 2 +- lib/unictype/categ_No.c | 2 +- lib/unictype/categ_P.c | 2 +- lib/unictype/categ_Pc.c | 2 +- lib/unictype/categ_Pd.c | 2 +- lib/unictype/categ_Pe.c | 2 +- lib/unictype/categ_Pf.c | 2 +- lib/unictype/categ_Pi.c | 2 +- lib/unictype/categ_Po.c | 2 +- lib/unictype/categ_Ps.c | 2 +- lib/unictype/categ_S.c | 2 +- lib/unictype/categ_Sc.c | 2 +- lib/unictype/categ_Sk.c | 2 +- lib/unictype/categ_Sm.c | 2 +- lib/unictype/categ_So.c | 2 +- lib/unictype/categ_Z.c | 2 +- lib/unictype/categ_Zl.c | 2 +- lib/unictype/categ_Zp.c | 2 +- lib/unictype/categ_Zs.c | 2 +- lib/unictype/categ_and.c | 4 +- lib/unictype/categ_and_not.c | 4 +- lib/unictype/categ_byname.c | 132 +- lib/unictype/categ_name.c | 72 +- lib/unictype/categ_none.c | 2 +- lib/unictype/categ_of.c | 32 +- lib/unictype/categ_or.c | 4 +- lib/unictype/categ_test.c | 2 +- lib/unictype/combining.c | 24 +- lib/unictype/ctype_alnum.c | 2 +- lib/unictype/ctype_alpha.c | 2 +- lib/unictype/ctype_blank.c | 2 +- lib/unictype/ctype_cntrl.c | 2 +- lib/unictype/ctype_digit.c | 2 +- lib/unictype/ctype_graph.c | 2 +- lib/unictype/ctype_lower.c | 2 +- lib/unictype/ctype_print.c | 2 +- lib/unictype/ctype_punct.c | 2 +- lib/unictype/ctype_space.c | 2 +- lib/unictype/ctype_upper.c | 2 +- lib/unictype/ctype_xdigit.c | 2 +- lib/unictype/decdigit.c | 28 +- lib/unictype/digit.c | 28 +- lib/unictype/identsyntaxmap.h | 24 +- lib/unictype/mirror.c | 26 +- lib/unictype/numeric.c | 34 +- lib/unictype/pr_alphabetic.c | 2 +- lib/unictype/pr_ascii_hex_digit.c | 2 +- lib/unictype/pr_bidi_arabic_digit.c | 2 +- lib/unictype/pr_bidi_arabic_right_to_left.c | 2 +- lib/unictype/pr_bidi_block_separator.c | 2 +- lib/unictype/pr_bidi_boundary_neutral.c | 2 +- lib/unictype/pr_bidi_common_separator.c | 2 +- lib/unictype/pr_bidi_control.c | 2 +- lib/unictype/pr_bidi_embedding_or_override.c | 4 +- lib/unictype/pr_bidi_eur_num_separator.c | 2 +- lib/unictype/pr_bidi_eur_num_terminator.c | 2 +- lib/unictype/pr_bidi_european_digit.c | 2 +- lib/unictype/pr_bidi_hebrew_right_to_left.c | 2 +- lib/unictype/pr_bidi_left_to_right.c | 2 +- lib/unictype/pr_bidi_non_spacing_mark.c | 2 +- lib/unictype/pr_bidi_other_neutral.c | 2 +- lib/unictype/pr_bidi_pdf.c | 2 +- lib/unictype/pr_bidi_segment_separator.c | 2 +- lib/unictype/pr_bidi_whitespace.c | 2 +- lib/unictype/pr_byname.c | 12 +- lib/unictype/pr_combining.c | 2 +- lib/unictype/pr_composite.c | 2 +- lib/unictype/pr_currency_symbol.c | 2 +- lib/unictype/pr_dash.c | 2 +- lib/unictype/pr_decimal_digit.c | 2 +- lib/unictype/pr_default_ignorable_code_point.c | 2 +- lib/unictype/pr_deprecated.c | 2 +- lib/unictype/pr_diacritic.c | 2 +- lib/unictype/pr_extender.c | 2 +- lib/unictype/pr_format_control.c | 2 +- lib/unictype/pr_grapheme_base.c | 2 +- lib/unictype/pr_grapheme_extend.c | 2 +- lib/unictype/pr_grapheme_link.c | 2 +- lib/unictype/pr_hex_digit.c | 2 +- lib/unictype/pr_hyphen.c | 2 +- lib/unictype/pr_id_continue.c | 2 +- lib/unictype/pr_id_start.c | 2 +- lib/unictype/pr_ideographic.c | 2 +- lib/unictype/pr_ids_binary_operator.c | 2 +- lib/unictype/pr_ids_trinary_operator.c | 2 +- lib/unictype/pr_ignorable_control.c | 2 +- lib/unictype/pr_iso_control.c | 2 +- lib/unictype/pr_join_control.c | 2 +- lib/unictype/pr_left_of_pair.c | 2 +- lib/unictype/pr_line_separator.c | 2 +- lib/unictype/pr_logical_order_exception.c | 2 +- lib/unictype/pr_lowercase.c | 2 +- lib/unictype/pr_math.c | 2 +- lib/unictype/pr_non_break.c | 2 +- lib/unictype/pr_not_a_character.c | 2 +- lib/unictype/pr_numeric.c | 2 +- lib/unictype/pr_other_alphabetic.c | 2 +- .../pr_other_default_ignorable_code_point.c | 2 +- lib/unictype/pr_other_grapheme_extend.c | 2 +- lib/unictype/pr_other_id_continue.c | 2 +- lib/unictype/pr_other_id_start.c | 2 +- lib/unictype/pr_other_lowercase.c | 2 +- lib/unictype/pr_other_math.c | 2 +- lib/unictype/pr_other_uppercase.c | 2 +- lib/unictype/pr_paired_punctuation.c | 2 +- lib/unictype/pr_paragraph_separator.c | 2 +- lib/unictype/pr_pattern_syntax.c | 2 +- lib/unictype/pr_pattern_white_space.c | 2 +- lib/unictype/pr_private_use.c | 6 +- lib/unictype/pr_punctuation.c | 2 +- lib/unictype/pr_quotation_mark.c | 2 +- lib/unictype/pr_radical.c | 2 +- lib/unictype/pr_sentence_terminal.c | 2 +- lib/unictype/pr_soft_dotted.c | 2 +- lib/unictype/pr_space.c | 2 +- lib/unictype/pr_terminal_punctuation.c | 2 +- lib/unictype/pr_test.c | 2 +- lib/unictype/pr_titlecase.c | 2 +- lib/unictype/pr_unassigned_code_value.c | 2 +- lib/unictype/pr_unified_ideograph.c | 2 +- lib/unictype/pr_uppercase.c | 2 +- lib/unictype/pr_variation_selector.c | 2 +- lib/unictype/pr_white_space.c | 2 +- lib/unictype/pr_xid_continue.c | 2 +- lib/unictype/pr_xid_start.c | 2 +- lib/unictype/pr_zero_width.c | 2 +- lib/unictype/scripts.c | 24 +- lib/unictype/sy_c_ident.c | 2 +- lib/unictype/sy_c_whitespace.c | 2 +- lib/unictype/sy_java_ident.c | 2 +- lib/unictype/sy_java_whitespace.c | 2 +- lib/unilbrk.h | 34 +- lib/unilbrk/lbrkprop1.h | 2 +- lib/unilbrk/lbrkprop2.h | 2 +- lib/unilbrk/lbrktables.c | 6 +- lib/unilbrk/lbrktables.h | 20 +- lib/unilbrk/u16-possible-linebreaks.c | 216 +- lib/unilbrk/u16-width-linebreaks.c | 84 +- lib/unilbrk/u32-possible-linebreaks.c | 216 +- lib/unilbrk/u32-width-linebreaks.c | 84 +- lib/unilbrk/u8-possible-linebreaks.c | 290 +- lib/unilbrk/u8-width-linebreaks.c | 152 +- lib/unilbrk/ulc-common.c | 4 +- lib/unilbrk/ulc-common.h | 2 +- lib/unilbrk/ulc-possible-linebreaks.c | 196 +- lib/unilbrk/ulc-width-linebreaks.c | 232 +- lib/uniname.h | 3 +- lib/uniname/uniname.c | 644 +- lib/uninorm.h | 30 +- lib/uninorm/canonical-decomposition.c | 104 +- lib/uninorm/compat-decomposition.c | 2 +- lib/uninorm/composition-table.gperf | 2 +- lib/uninorm/composition.c | 84 +- lib/uninorm/decompose-internal.c | 2 +- lib/uninorm/decompose-internal.h | 6 +- lib/uninorm/decomposing-form.c | 2 +- lib/uninorm/decomposition-table.c | 2 +- lib/uninorm/decomposition-table.h | 20 +- lib/uninorm/decomposition.c | 96 +- lib/uninorm/nfc.c | 2 +- lib/uninorm/nfd.c | 2 +- lib/uninorm/nfkc.c | 2 +- lib/uninorm/nfkd.c | 2 +- lib/uninorm/normalize-internal.h | 2 +- lib/uninorm/u-normalize-internal.h | 566 +- lib/uninorm/u-normcmp.h | 12 +- lib/uninorm/u-normcoll.h | 14 +- lib/uninorm/u-normxfrm.h | 40 +- lib/uninorm/u16-normalize.c | 2 +- lib/uninorm/u16-normcmp.c | 2 +- lib/uninorm/u16-normcoll.c | 2 +- lib/uninorm/u16-normxfrm.c | 2 +- lib/uninorm/u32-normalize.c | 2 +- lib/uninorm/u32-normcmp.c | 2 +- lib/uninorm/u32-normcoll.c | 2 +- lib/uninorm/u32-normxfrm.c | 2 +- lib/uninorm/u8-normalize.c | 2 +- lib/uninorm/u8-normcmp.c | 2 +- lib/uninorm/u8-normcoll.c | 2 +- lib/uninorm/u8-normxfrm.c | 2 +- lib/uninorm/uninorm-filter.c | 394 +- lib/unistd.in.h | 1193 ++- lib/unistdio.h | 118 +- lib/unistdio/u-asnprintf.h | 3 +- lib/unistdio/u-asprintf.h | 3 +- lib/unistdio/u-printf-args.c | 3 +- lib/unistdio/u-printf-args.h | 3 +- lib/unistdio/u-printf-parse.h | 3 +- lib/unistdio/u-snprintf.h | 3 +- lib/unistdio/u-sprintf.h | 3 +- lib/unistdio/u-vasprintf.h | 2 +- lib/unistdio/u-vsnprintf.h | 16 +- lib/unistdio/u-vsprintf.h | 2 +- lib/unistdio/u16-asnprintf.c | 3 +- lib/unistdio/u16-asprintf.c | 3 +- lib/unistdio/u16-printf-parse.c | 3 +- lib/unistdio/u16-snprintf.c | 3 +- lib/unistdio/u16-sprintf.c | 3 +- lib/unistdio/u16-u16-asnprintf.c | 3 +- lib/unistdio/u16-u16-asprintf.c | 3 +- lib/unistdio/u16-u16-snprintf.c | 3 +- lib/unistdio/u16-u16-sprintf.c | 3 +- lib/unistdio/u16-u16-vasnprintf.c | 3 +- lib/unistdio/u16-u16-vasprintf.c | 3 +- lib/unistdio/u16-u16-vsnprintf.c | 3 +- lib/unistdio/u16-u16-vsprintf.c | 3 +- lib/unistdio/u16-vasnprintf.c | 3 +- lib/unistdio/u16-vasprintf.c | 3 +- lib/unistdio/u16-vsnprintf.c | 3 +- lib/unistdio/u16-vsprintf.c | 3 +- lib/unistdio/u32-asnprintf.c | 3 +- lib/unistdio/u32-asprintf.c | 3 +- lib/unistdio/u32-printf-parse.c | 3 +- lib/unistdio/u32-snprintf.c | 3 +- lib/unistdio/u32-sprintf.c | 3 +- lib/unistdio/u32-u32-asnprintf.c | 3 +- lib/unistdio/u32-u32-asprintf.c | 3 +- lib/unistdio/u32-u32-snprintf.c | 3 +- lib/unistdio/u32-u32-sprintf.c | 3 +- lib/unistdio/u32-u32-vasnprintf.c | 3 +- lib/unistdio/u32-u32-vasprintf.c | 3 +- lib/unistdio/u32-u32-vsnprintf.c | 3 +- lib/unistdio/u32-u32-vsprintf.c | 3 +- lib/unistdio/u32-vasnprintf.c | 3 +- lib/unistdio/u32-vasprintf.c | 3 +- lib/unistdio/u32-vsnprintf.c | 3 +- lib/unistdio/u32-vsprintf.c | 3 +- lib/unistdio/u8-asnprintf.c | 3 +- lib/unistdio/u8-asprintf.c | 3 +- lib/unistdio/u8-printf-parse.c | 3 +- lib/unistdio/u8-snprintf.c | 3 +- lib/unistdio/u8-sprintf.c | 3 +- lib/unistdio/u8-u8-asnprintf.c | 3 +- lib/unistdio/u8-u8-asprintf.c | 3 +- lib/unistdio/u8-u8-snprintf.c | 3 +- lib/unistdio/u8-u8-sprintf.c | 3 +- lib/unistdio/u8-u8-vasnprintf.c | 3 +- lib/unistdio/u8-u8-vasprintf.c | 3 +- lib/unistdio/u8-u8-vsnprintf.c | 3 +- lib/unistdio/u8-u8-vsprintf.c | 3 +- lib/unistdio/u8-vasnprintf.c | 3 +- lib/unistdio/u8-vasprintf.c | 3 +- lib/unistdio/u8-vsnprintf.c | 3 +- lib/unistdio/u8-vsprintf.c | 3 +- lib/unistdio/ulc-asnprintf.c | 3 +- lib/unistdio/ulc-asprintf.c | 3 +- lib/unistdio/ulc-fprintf.c | 12 +- lib/unistdio/ulc-printf-parse.c | 3 +- lib/unistdio/ulc-snprintf.c | 3 +- lib/unistdio/ulc-sprintf.c | 3 +- lib/unistdio/ulc-vasnprintf.c | 3 +- lib/unistdio/ulc-vasprintf.c | 3 +- lib/unistdio/ulc-vfprintf.c | 12 +- lib/unistdio/ulc-vsnprintf.c | 3 +- lib/unistdio/ulc-vsprintf.c | 3 +- lib/unistr.h | 36 +- lib/unistr/u-cmp2.h | 6 +- lib/unistr/u-cpy-alloc.h | 5 +- lib/unistr/u-cpy.h | 2 +- lib/unistr/u-endswith.h | 2 +- lib/unistr/u-move.h | 6 +- lib/unistr/u-set.h | 20 +- lib/unistr/u-startswith.h | 6 +- lib/unistr/u-stpcpy.h | 2 +- lib/unistr/u-stpncpy.h | 12 +- lib/unistr/u-strcat.h | 2 +- lib/unistr/u-strcoll.h | 76 +- lib/unistr/u-strcpy.h | 2 +- lib/unistr/u-strcspn.h | 30 +- lib/unistr/u-strdup.h | 5 +- lib/unistr/u-strlen.h | 2 +- lib/unistr/u-strncat.h | 2 +- lib/unistr/u-strncpy.h | 2 +- lib/unistr/u-strnlen.h | 2 +- lib/unistr/u-strpbrk.h | 16 +- lib/unistr/u-strspn.h | 30 +- lib/unistr/u-strstr.h | 24 +- lib/unistr/u-strtok.h | 10 +- lib/unistr/u16-check.c | 26 +- lib/unistr/u16-chr.c | 35 +- lib/unistr/u16-cmp.c | 30 +- lib/unistr/u16-cmp2.c | 2 +- lib/unistr/u16-cpy-alloc.c | 2 +- lib/unistr/u16-cpy.c | 2 +- lib/unistr/u16-endswith.c | 2 +- lib/unistr/u16-mblen.c | 23 +- lib/unistr/u16-mbsnlen.c | 11 +- lib/unistr/u16-mbtouc-aux.c | 24 +- lib/unistr/u16-mbtouc-unsafe-aux.c | 24 +- lib/unistr/u16-mbtouc-unsafe.c | 24 +- lib/unistr/u16-mbtouc.c | 24 +- lib/unistr/u16-mbtoucr.c | 28 +- lib/unistr/u16-move.c | 2 +- lib/unistr/u16-next.c | 4 +- lib/unistr/u16-prev.c | 28 +- lib/unistr/u16-set.c | 2 +- lib/unistr/u16-startswith.c | 2 +- lib/unistr/u16-stpcpy.c | 3 +- lib/unistr/u16-stpncpy.c | 2 +- lib/unistr/u16-strcat.c | 2 +- lib/unistr/u16-strchr.c | 45 +- lib/unistr/u16-strcmp.c | 24 +- lib/unistr/u16-strcoll.c | 2 +- lib/unistr/u16-strcpy.c | 2 +- lib/unistr/u16-strcspn.c | 2 +- lib/unistr/u16-strdup.c | 2 +- lib/unistr/u16-strlen.c | 2 +- lib/unistr/u16-strmblen.c | 5 +- lib/unistr/u16-strmbtouc.c | 11 +- lib/unistr/u16-strncat.c | 2 +- lib/unistr/u16-strncmp.c | 30 +- lib/unistr/u16-strncpy.c | 2 +- lib/unistr/u16-strnlen.c | 2 +- lib/unistr/u16-strpbrk.c | 2 +- lib/unistr/u16-strrchr.c | 43 +- lib/unistr/u16-strspn.c | 2 +- lib/unistr/u16-strstr.c | 2 +- lib/unistr/u16-strtok.c | 2 +- lib/unistr/u16-to-u32.c | 84 +- lib/unistr/u16-to-u8.c | 102 +- lib/unistr/u16-uctomb-aux.c | 36 +- lib/unistr/u16-uctomb.c | 44 +- lib/unistr/u32-check.c | 8 +- lib/unistr/u32-chr.c | 4 +- lib/unistr/u32-cmp.c | 10 +- lib/unistr/u32-cmp2.c | 2 +- lib/unistr/u32-cpy-alloc.c | 2 +- lib/unistr/u32-cpy.c | 2 +- lib/unistr/u32-endswith.c | 2 +- lib/unistr/u32-mblen.c | 4 +- lib/unistr/u32-mbsnlen.c | 2 +- lib/unistr/u32-mbtouc-unsafe.c | 2 +- lib/unistr/u32-mbtouc.c | 2 +- lib/unistr/u32-mbtoucr.c | 2 +- lib/unistr/u32-move.c | 2 +- lib/unistr/u32-next.c | 4 +- lib/unistr/u32-prev.c | 10 +- lib/unistr/u32-set.c | 2 +- lib/unistr/u32-startswith.c | 2 +- lib/unistr/u32-stpcpy.c | 2 +- lib/unistr/u32-stpncpy.c | 2 +- lib/unistr/u32-strcat.c | 2 +- lib/unistr/u32-strchr.c | 6 +- lib/unistr/u32-strcmp.c | 4 +- lib/unistr/u32-strcoll.c | 2 +- lib/unistr/u32-strcpy.c | 2 +- lib/unistr/u32-strcspn.c | 8 +- lib/unistr/u32-strdup.c | 2 +- lib/unistr/u32-strlen.c | 2 +- lib/unistr/u32-strmblen.c | 2 +- lib/unistr/u32-strmbtouc.c | 2 +- lib/unistr/u32-strncat.c | 2 +- lib/unistr/u32-strncmp.c | 10 +- lib/unistr/u32-strncpy.c | 2 +- lib/unistr/u32-strnlen.c | 2 +- lib/unistr/u32-strpbrk.c | 8 +- lib/unistr/u32-strrchr.c | 6 +- lib/unistr/u32-strspn.c | 8 +- lib/unistr/u32-strstr.c | 2 +- lib/unistr/u32-strtok.c | 2 +- lib/unistr/u32-to-u16.c | 90 +- lib/unistr/u32-to-u8.c | 90 +- lib/unistr/u32-uctomb.c | 12 +- lib/unistr/u8-check.c | 126 +- lib/unistr/u8-chr.c | 83 +- lib/unistr/u8-cmp.c | 2 +- lib/unistr/u8-cmp2.c | 2 +- lib/unistr/u8-cpy-alloc.c | 2 +- lib/unistr/u8-cpy.c | 2 +- lib/unistr/u8-endswith.c | 2 +- lib/unistr/u8-mblen.c | 99 +- lib/unistr/u8-mbsnlen.c | 11 +- lib/unistr/u8-mbtouc-aux.c | 224 +- lib/unistr/u8-mbtouc-unsafe-aux.c | 224 +- lib/unistr/u8-mbtouc-unsafe.c | 224 +- lib/unistr/u8-mbtouc.c | 224 +- lib/unistr/u8-mbtoucr.c | 476 +- lib/unistr/u8-move.c | 2 +- lib/unistr/u8-next.c | 4 +- lib/unistr/u8-prev.c | 92 +- lib/unistr/u8-set.c | 12 +- lib/unistr/u8-startswith.c | 2 +- lib/unistr/u8-stpcpy.c | 2 +- lib/unistr/u8-stpncpy.c | 2 +- lib/unistr/u8-strcat.c | 2 +- lib/unistr/u8-strchr.c | 105 +- lib/unistr/u8-strcmp.c | 2 +- lib/unistr/u8-strcoll.c | 2 +- lib/unistr/u8-strcpy.c | 2 +- lib/unistr/u8-strcspn.c | 2 +- lib/unistr/u8-strdup.c | 2 +- lib/unistr/u8-strlen.c | 2 +- lib/unistr/u8-strmblen.c | 75 +- lib/unistr/u8-strmbtouc.c | 135 +- lib/unistr/u8-strncat.c | 2 +- lib/unistr/u8-strncmp.c | 2 +- lib/unistr/u8-strncpy.c | 2 +- lib/unistr/u8-strnlen.c | 2 +- lib/unistr/u8-strpbrk.c | 2 +- lib/unistr/u8-strrchr.c | 105 +- lib/unistr/u8-strspn.c | 2 +- lib/unistr/u8-strstr.c | 2 +- lib/unistr/u8-strtok.c | 2 +- lib/unistr/u8-to-u16.c | 102 +- lib/unistr/u8-to-u32.c | 84 +- lib/unistr/u8-uctomb-aux.c | 6 +- lib/unistr/u8-uctomb.c | 58 +- lib/unistring/cdefs.in.h | 22 + lib/unitypes.h | 2 +- lib/uniwbrk.h | 2 +- lib/uniwbrk/u-wordbreaks.h | 166 +- lib/uniwbrk/u16-wordbreaks.c | 2 +- lib/uniwbrk/u32-wordbreaks.c | 2 +- lib/uniwbrk/u8-wordbreaks.c | 68 +- lib/uniwbrk/ulc-wordbreaks.c | 168 +- lib/uniwbrk/wbrkprop.h | 2 +- lib/uniwbrk/wbrktable.c | 22 +- lib/uniwbrk/wbrktable.h | 2 +- lib/uniwbrk/wordbreak-property.c | 20 +- lib/uniwidth.h | 3 +- lib/uniwidth/cjk.h | 2 +- lib/uniwidth/u16-strwidth.c | 2 +- lib/uniwidth/u16-width.c | 6 +- lib/uniwidth/u32-strwidth.c | 2 +- lib/uniwidth/u32-width.c | 6 +- lib/uniwidth/u8-strwidth.c | 2 +- lib/uniwidth/u8-width.c | 6 +- lib/uniwidth/width.c | 54 +- lib/vasnprintf.c | 8205 ++++++++++---------- lib/verify.h | 6 +- lib/wchar.in.h | 348 +- lib/wctype.in.h | 261 +- lib/wcwidth.c | 9 +- lib/xsize.h | 2 +- 654 files changed, 21584 insertions(+), 15506 deletions(-) mode change 100755 => 100644 lib/config.charset delete mode 100644 lib/dup2.c delete mode 100644 lib/getpagesize.c create mode 100644 lib/glthread/lock.c create mode 100644 lib/glthread/lock.h create mode 100644 lib/glthread/threadlib.c create mode 100644 lib/iconv_open-solaris.gperf create mode 100644 lib/iconv_open-solaris.h create mode 100644 lib/strncat.c create mode 100644 lib/unistring/cdefs.in.h (limited to 'lib') diff --git a/lib/Makefile.am b/lib/Makefile.am index 2c8da9d9..ffbfae22 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,5 +1,5 @@ ## Makefile for the lib subdirectory of GNU libunistring. -## Copyright (C) 2009 Free Software Foundation, Inc. +## Copyright (C) 2009-2010 Free Software Foundation, Inc. ## ## This program is free software: you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by @@ -155,6 +155,20 @@ CLEANFILES += unistring/iconveh.h # unistring/version.h is public. nobase_nodist_include_HEADERS += unistring/version.h +# unistring/cdefs.h is not public, but is included by other header files. +nobase_nodist_include_HEADERS += unistring/cdefs.h +unistring/cdefs.h : unistring/cdefs.in.h + @MKDIR_P@ unistring + rm -f $@-t $@ + sed -e '/definition of _GL_UNUSED_PARAMETER/r $(UNUSED_PARAMETER_H)' \ + < $(srcdir)/unistring/cdefs.in.h \ + > $@-t + mv $@-t $@ +BUILT_SOURCES += unistring/cdefs.h +MOSTLYCLEANFILES += unistring/cdefs.h-t +CLEANFILES += unistring/cdefs.h +EXTRA_DIST += unistring/cdefs.in.h + # unistring/woe32dll.h is not public, but is included by other header files. nobase_nodist_include_HEADERS += unistring/woe32dll.h @@ -288,7 +302,7 @@ AM_CPPFLAGS += -DDEPENDS_ON_LIBICONV=1 # Libtool's library version information for libunistring. # See the libtool documentation, section "Library interface versions". LTV_CURRENT=1 -LTV_REVISION=0 +LTV_REVISION=2 LTV_AGE=1 # How to build libunistring.la. diff --git a/lib/Makefile.gnulib b/lib/Makefile.gnulib index 735befa0..3c3c6f53 100644 --- a/lib/Makefile.gnulib +++ b/lib/Makefile.gnulib @@ -1,6 +1,6 @@ ## DO NOT EDIT! GENERATED AUTOMATICALLY! ## Process this file with automake to produce Makefile.in. -# Copyright (C) 2002-2009 Free Software Foundation, Inc. +# Copyright (C) 2002-2010 Free Software Foundation, Inc. # # This file is free software, distributed under the terms of the GNU # General Public License. As a special exception to the GNU General @@ -27,9 +27,10 @@ BUILT_SOURCES += $(ALLOCA_H) # We need the following in order to create when the system # doesn't have one that works with the given compiler. alloca.h: alloca.in.h + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ cat $(srcdir)/alloca.in.h; \ - } > $@-t + } > $@-t && \ mv -f $@-t $@ MOSTLYCLEANFILES += alloca.h alloca.h-t @@ -37,6 +38,30 @@ EXTRA_DIST += alloca.in.h ## end gnulib module alloca-opt +## begin gnulib module arg-nonnull + +# The BUILT_SOURCES created by this Makefile snippet are not used via #include +# statements but through direct file reference. Therefore this snippet must be +# present in all Makefile.am that need it. This is ensured by the applicability +# 'all' defined above. + +BUILT_SOURCES += arg-nonnull.h +# The arg-nonnull.h that gets inserted into generated .h files is the same as +# build-aux/arg-nonnull.h, except that it has the copyright header cut off. +arg-nonnull.h: $(top_srcdir)/build-aux/arg-nonnull.h + $(AM_V_GEN)rm -f $@-t $@ && \ + sed -n -e '/GL_ARG_NONNULL/,$$p' \ + < $(top_srcdir)/build-aux/arg-nonnull.h \ + > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += arg-nonnull.h arg-nonnull.h-t + +ARG_NONNULL_H=arg-nonnull.h + +EXTRA_DIST += $(top_srcdir)/build-aux/arg-nonnull.h + +## end gnulib module arg-nonnull + ## begin gnulib module array-mergesort @@ -44,6 +69,30 @@ EXTRA_DIST += array-mergesort.h ## end gnulib module array-mergesort +## begin gnulib module c++defs + +# The BUILT_SOURCES created by this Makefile snippet are not used via #include +# statements but through direct file reference. Therefore this snippet must be +# present in all Makefile.am that need it. This is ensured by the applicability +# 'all' defined above. + +BUILT_SOURCES += c++defs.h +# The c++defs.h that gets inserted into generated .h files is the same as +# build-aux/c++defs.h, except that it has the copyright header cut off. +c++defs.h: $(top_srcdir)/build-aux/c++defs.h + $(AM_V_GEN)rm -f $@-t $@ && \ + sed -n -e '/_GL_CXXDEFS/,$$p' \ + < $(top_srcdir)/build-aux/c++defs.h \ + > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += c++defs.h c++defs.h-t + +CXXDEFS_H=c++defs.h + +EXTRA_DIST += $(top_srcdir)/build-aux/c++defs.h + +## end gnulib module c++defs + ## begin gnulib module c-ctype libunistring_la_SOURCES += c-ctype.h c-ctype.c @@ -83,7 +132,7 @@ EXTRA_DIST += c-strcaseeq.h # The Automake-defined pkg* macros are appended, in the order # listed in the Automake 1.10a+ documentation. configmake.h: Makefile - rm -f $@-t + $(AM_V_GEN)rm -f $@-t && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ echo '#define PREFIX "$(prefix)"'; \ echo '#define EXEC_PREFIX "$(exec_prefix)"'; \ @@ -112,7 +161,7 @@ configmake.h: Makefile echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \ echo '#define PKGLIBDIR "$(pkglibdir)"'; \ echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \ - } | sed '/""/d' > $@-t + } | sed '/""/d' > $@-t && \ if test -f $@ && cmp $@-t $@ > /dev/null; then \ rm -f $@-t; \ else \ @@ -124,15 +173,6 @@ CLEANFILES += configmake.h configmake.h-t ## end gnulib module configmake -## begin gnulib module dup2 - - -EXTRA_DIST += dup2.c - -EXTRA_libunistring_la_SOURCES += dup2.c - -## end gnulib module dup2 - ## begin gnulib module errno BUILT_SOURCES += $(ERRNO_H) @@ -140,7 +180,7 @@ BUILT_SOURCES += $(ERRNO_H) # We need the following in order to create when the system # doesn't have one that is POSIX compliant. errno.h: errno.in.h - rm -f $@-t $@ + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ @@ -152,7 +192,7 @@ errno.h: errno.in.h -e 's|@''EOVERFLOW_HIDDEN''@|$(EOVERFLOW_HIDDEN)|g' \ -e 's|@''EOVERFLOW_VALUE''@|$(EOVERFLOW_VALUE)|g' \ < $(srcdir)/errno.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ MOSTLYCLEANFILES += errno.h errno.h-t @@ -167,13 +207,13 @@ BUILT_SOURCES += $(FLOAT_H) # We need the following in order to create when the system # doesn't have one that works with the given compiler. float.h: float.in.h - rm -f $@-t $@ + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_FLOAT_H''@|$(NEXT_FLOAT_H)|g' \ < $(srcdir)/float.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ MOSTLYCLEANFILES += float.h float.h-t @@ -205,15 +245,6 @@ EXTRA_DIST += fseterr.h stdio-impl.h ## end gnulib module fseterr -## begin gnulib module getpagesize - - -EXTRA_DIST += getpagesize.c - -EXTRA_libunistring_la_SOURCES += getpagesize.c - -## end gnulib module getpagesize - ## begin gnulib module gperf GPERF = gperf @@ -227,14 +258,14 @@ EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath ## end gnulib module havelib -## begin gnulib module iconv_open +## begin gnulib module iconv-h BUILT_SOURCES += $(ICONV_H) # We need the following in order to create when the system # doesn't have one that works with the given compiler. -iconv.h: iconv.in.h - rm -f $@-t $@ +iconv.h: iconv.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ @@ -243,11 +274,20 @@ iconv.h: iconv.in.h -e 's|@''REPLACE_ICONV''@|$(REPLACE_ICONV)|g' \ -e 's|@''REPLACE_ICONV_OPEN''@|$(REPLACE_ICONV_OPEN)|g' \ -e 's|@''REPLACE_ICONV_UTF''@|$(REPLACE_ICONV_UTF)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/iconv.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ MOSTLYCLEANFILES += iconv.h iconv.h-t +EXTRA_DIST += iconv.in.h + +## end gnulib module iconv-h + +## begin gnulib module iconv_open + iconv_open-aix.h: iconv_open-aix.gperf $(GPERF) -m 10 $(srcdir)/iconv_open-aix.gperf > $(srcdir)/iconv_open-aix.h-t mv $(srcdir)/iconv_open-aix.h-t $(srcdir)/iconv_open-aix.h @@ -260,12 +300,15 @@ iconv_open-irix.h: iconv_open-irix.gperf iconv_open-osf.h: iconv_open-osf.gperf $(GPERF) -m 10 $(srcdir)/iconv_open-osf.gperf > $(srcdir)/iconv_open-osf.h-t mv $(srcdir)/iconv_open-osf.h-t $(srcdir)/iconv_open-osf.h -BUILT_SOURCES += iconv_open-aix.h iconv_open-hpux.h iconv_open-irix.h iconv_open-osf.h -MOSTLYCLEANFILES += iconv_open-aix.h-t iconv_open-hpux.h-t iconv_open-irix.h-t iconv_open-osf.h-t -MAINTAINERCLEANFILES += iconv_open-aix.h iconv_open-hpux.h iconv_open-irix.h iconv_open-osf.h -EXTRA_DIST += iconv_open-aix.h iconv_open-hpux.h iconv_open-irix.h iconv_open-osf.h +iconv_open-solaris.h: iconv_open-solaris.gperf + $(GPERF) -m 10 $(srcdir)/iconv_open-solaris.gperf > $(srcdir)/iconv_open-solaris.h-t + mv $(srcdir)/iconv_open-solaris.h-t $(srcdir)/iconv_open-solaris.h +BUILT_SOURCES += iconv_open-aix.h iconv_open-hpux.h iconv_open-irix.h iconv_open-osf.h iconv_open-solaris.h +MOSTLYCLEANFILES += iconv_open-aix.h-t iconv_open-hpux.h-t iconv_open-irix.h-t iconv_open-osf.h-t iconv_open-solaris.h-t +MAINTAINERCLEANFILES += iconv_open-aix.h iconv_open-hpux.h iconv_open-irix.h iconv_open-osf.h iconv_open-solaris.h +EXTRA_DIST += iconv_open-aix.h iconv_open-hpux.h iconv_open-irix.h iconv_open-osf.h iconv_open-solaris.h -EXTRA_DIST += iconv.in.h iconv_open-aix.gperf iconv_open-hpux.gperf iconv_open-irix.gperf iconv_open-osf.gperf iconv_open.c +EXTRA_DIST += iconv_open-aix.gperf iconv_open-hpux.gperf iconv_open-irix.gperf iconv_open-osf.gperf iconv_open-solaris.gperf iconv_open.c EXTRA_libunistring_la_SOURCES += iconv_open.c @@ -298,14 +341,6 @@ EXTRA_libunistring_la_SOURCES += isnan.c isnanl.c ## end gnulib module isnanl-nolibm -## begin gnulib module link-warning - -LINK_WARNING_H=$(top_srcdir)/build-aux/link-warning.h - -EXTRA_DIST += $(top_srcdir)/build-aux/link-warning.h - -## end gnulib module link-warning - ## begin gnulib module localcharset libunistring_la_SOURCES += localcharset.h localcharset.c @@ -364,14 +399,14 @@ uninstall-localcharset: all-local fi charset.alias: config.charset - rm -f t-$@ $@ - $(SHELL) $(srcdir)/config.charset '$(host)' > t-$@ + $(AM_V_GEN)rm -f t-$@ $@ && \ + $(SHELL) $(srcdir)/config.charset '$(host)' > t-$@ && \ mv t-$@ $@ SUFFIXES += .sed .sin .sin.sed: - rm -f t-$@ $@ - sed -e '/^#/d' -e 's/@''PACKAGE''@/$(PACKAGE)/g' $< > t-$@ + $(AM_V_GEN)rm -f t-$@ $@ && \ + sed -e '/^#/d' -e 's/@''PACKAGE''@/$(PACKAGE)/g' $< > t-$@ && \ mv t-$@ $@ CLEANFILES += charset.alias ref-add.sed ref-del.sed @@ -388,6 +423,12 @@ EXTRA_DIST += localename.h ## end gnulib module localename +## begin gnulib module lock + +libunistring_la_SOURCES += glthread/lock.h glthread/lock.c + +## end gnulib module lock + ## begin gnulib module malloc-posix @@ -411,14 +452,19 @@ BUILT_SOURCES += math.h # We need the following in order to create when the system # doesn't have one that works with the given compiler. -math.h: math.in.h - rm -f $@-t $@ +math.h: math.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT_AS_FIRST_DIRECTIVE''@|$(INCLUDE_NEXT_AS_FIRST_DIRECTIVE)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_AS_FIRST_DIRECTIVE_MATH_H''@|$(NEXT_AS_FIRST_DIRECTIVE_MATH_H)|g' \ + -e 's|@''GNULIB_ACOSL''@|$(GNULIB_ACOSL)|g' \ + -e 's|@''GNULIB_ASINL''@|$(GNULIB_ASINL)|g' \ + -e 's|@''GNULIB_ATANL''@|$(GNULIB_ATANL)|g' \ -e 's|@''GNULIB_CEILF''@|$(GNULIB_CEILF)|g' \ -e 's|@''GNULIB_CEILL''@|$(GNULIB_CEILL)|g' \ + -e 's|@''GNULIB_COSL''@|$(GNULIB_COSL)|g' \ + -e 's|@''GNULIB_EXPL''@|$(GNULIB_EXPL)|g' \ -e 's|@''GNULIB_FLOORF''@|$(GNULIB_FLOORF)|g' \ -e 's|@''GNULIB_FLOORL''@|$(GNULIB_FLOORL)|g' \ -e 's|@''GNULIB_FREXP''@|$(GNULIB_FREXP)|g' \ @@ -430,30 +476,52 @@ math.h: math.in.h -e 's|@''GNULIB_ISNAND''@|$(GNULIB_ISNAND)|g' \ -e 's|@''GNULIB_ISNANL''@|$(GNULIB_ISNANL)|g' \ -e 's|@''GNULIB_LDEXPL''@|$(GNULIB_LDEXPL)|g' \ - -e 's|@''GNULIB_MATHL''@|$(GNULIB_MATHL)|g' \ + -e 's|@''GNULIB_LOGB''@|$(GNULIB_LOGB)|g' \ + -e 's|@''GNULIB_LOGL''@|$(GNULIB_LOGL)|g' \ -e 's|@''GNULIB_ROUND''@|$(GNULIB_ROUND)|g' \ -e 's|@''GNULIB_ROUNDF''@|$(GNULIB_ROUNDF)|g' \ -e 's|@''GNULIB_ROUNDL''@|$(GNULIB_ROUNDL)|g' \ -e 's|@''GNULIB_SIGNBIT''@|$(GNULIB_SIGNBIT)|g' \ + -e 's|@''GNULIB_SINL''@|$(GNULIB_SINL)|g' \ + -e 's|@''GNULIB_SQRTL''@|$(GNULIB_SQRTL)|g' \ + -e 's|@''GNULIB_TANL''@|$(GNULIB_TANL)|g' \ -e 's|@''GNULIB_TRUNC''@|$(GNULIB_TRUNC)|g' \ -e 's|@''GNULIB_TRUNCF''@|$(GNULIB_TRUNCF)|g' \ -e 's|@''GNULIB_TRUNCL''@|$(GNULIB_TRUNCL)|g' \ + -e 's|@''HAVE_ACOSL''@|$(HAVE_ACOSL)|g' \ + -e 's|@''HAVE_ASINL''@|$(HAVE_ASINL)|g' \ + -e 's|@''HAVE_ATANL''@|$(HAVE_ATANL)|g' \ + -e 's|@''HAVE_COSL''@|$(HAVE_COSL)|g' \ + -e 's|@''HAVE_EXPL''@|$(HAVE_EXPL)|g' \ -e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \ -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \ -e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \ + -e 's|@''HAVE_LOGL''@|$(HAVE_LOGL)|g' \ + -e 's|@''HAVE_SINL''@|$(HAVE_SINL)|g' \ + -e 's|@''HAVE_SQRTL''@|$(HAVE_SQRTL)|g' \ + -e 's|@''HAVE_TANL''@|$(HAVE_TANL)|g' \ -e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \ -e 's|@''HAVE_DECL_ASINL''@|$(HAVE_DECL_ASINL)|g' \ -e 's|@''HAVE_DECL_ATANL''@|$(HAVE_DECL_ATANL)|g' \ + -e 's|@''HAVE_DECL_CEILF''@|$(HAVE_DECL_CEILF)|g' \ + -e 's|@''HAVE_DECL_CEILL''@|$(HAVE_DECL_CEILL)|g' \ -e 's|@''HAVE_DECL_COSL''@|$(HAVE_DECL_COSL)|g' \ -e 's|@''HAVE_DECL_EXPL''@|$(HAVE_DECL_EXPL)|g' \ + -e 's|@''HAVE_DECL_FLOORF''@|$(HAVE_DECL_FLOORF)|g' \ + -e 's|@''HAVE_DECL_FLOORL''@|$(HAVE_DECL_FLOORL)|g' \ -e 's|@''HAVE_DECL_FREXPL''@|$(HAVE_DECL_FREXPL)|g' \ -e 's|@''HAVE_DECL_LDEXPL''@|$(HAVE_DECL_LDEXPL)|g' \ + -e 's|@''HAVE_DECL_LOGB''@|$(HAVE_DECL_LOGB)|g' \ -e 's|@''HAVE_DECL_LOGL''@|$(HAVE_DECL_LOGL)|g' \ + -e 's|@''HAVE_DECL_ROUND''@|$(HAVE_DECL_ROUND)|g' \ + -e 's|@''HAVE_DECL_ROUNDF''@|$(HAVE_DECL_ROUNDF)|g' \ + -e 's|@''HAVE_DECL_ROUNDL''@|$(HAVE_DECL_ROUNDL)|g' \ -e 's|@''HAVE_DECL_SINL''@|$(HAVE_DECL_SINL)|g' \ -e 's|@''HAVE_DECL_SQRTL''@|$(HAVE_DECL_SQRTL)|g' \ -e 's|@''HAVE_DECL_TANL''@|$(HAVE_DECL_TANL)|g' \ -e 's|@''HAVE_DECL_TRUNC''@|$(HAVE_DECL_TRUNC)|g' \ -e 's|@''HAVE_DECL_TRUNCF''@|$(HAVE_DECL_TRUNCF)|g' \ + -e 's|@''HAVE_DECL_TRUNCL''@|$(HAVE_DECL_TRUNCL)|g' \ -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \ -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \ -e 's|@''REPLACE_FLOORF''@|$(REPLACE_FLOORF)|g' \ @@ -472,9 +540,11 @@ math.h: math.in.h -e 's|@''REPLACE_SIGNBIT''@|$(REPLACE_SIGNBIT)|g' \ -e 's|@''REPLACE_SIGNBIT_USING_GCC''@|$(REPLACE_SIGNBIT_USING_GCC)|g' \ -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \ - -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/math.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ MOSTLYCLEANFILES += math.h math.h-t @@ -601,10 +671,10 @@ BUILT_SOURCES += $(STDBOOL_H) # We need the following in order to create when the system # doesn't have one that works. stdbool.h: stdbool.in.h - rm -f $@-t $@ + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ MOSTLYCLEANFILES += stdbool.h stdbool.h-t @@ -619,7 +689,7 @@ BUILT_SOURCES += $(STDDEF_H) # We need the following in order to create when the system # doesn't have one that works with the given compiler. stddef.h: stddef.in.h - rm -f $@-t $@ + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ @@ -627,7 +697,7 @@ stddef.h: stddef.in.h -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \ -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \ < $(srcdir)/stddef.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ MOSTLYCLEANFILES += stddef.h stddef.h-t @@ -642,7 +712,7 @@ BUILT_SOURCES += $(STDINT_H) # We need the following in order to create when the system # doesn't have one that works with the given compiler. stdint.h: stdint.in.h - rm -f $@-t $@ + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -669,7 +739,7 @@ stdint.h: stdint.in.h -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \ -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \ < $(srcdir)/stdint.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ MOSTLYCLEANFILES += stdint.h stdint.h-t @@ -683,36 +753,53 @@ BUILT_SOURCES += stdlib.h # We need the following in order to create when the system # doesn't have one that works with the given compiler. -stdlib.h: stdlib.in.h - rm -f $@-t $@ +stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \ - -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \ - -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \ - -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \ - -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \ -e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \ + -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \ + -e 's|@''GNULIB_CANONICALIZE_FILE_NAME''@|$(GNULIB_CANONICALIZE_FILE_NAME)|g' \ -e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \ -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \ + -e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \ + -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \ -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \ + -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \ + -e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \ -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \ + -e 's|@''GNULIB_MKSTEMPS''@|$(GNULIB_MKSTEMPS)|g' \ + -e 's|@''GNULIB_PTSNAME''@|$(GNULIB_PTSNAME)|g' \ -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \ -e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|g' \ + -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \ + -e 's|@''GNULIB_REALPATH''@|$(GNULIB_REALPATH)|g' \ -e 's|@''GNULIB_RPMATCH''@|$(GNULIB_RPMATCH)|g' \ -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \ -e 's|@''GNULIB_STRTOD''@|$(GNULIB_STRTOD)|g' \ -e 's|@''GNULIB_STRTOLL''@|$(GNULIB_STRTOLL)|g' \ -e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \ + -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \ -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \ -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \ + -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \ + -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ + -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \ -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \ -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \ - -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \ + -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \ + -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \ + -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \ + -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \ + -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \ + -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \ -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \ + -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \ + -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \ -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \ -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \ -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \ @@ -720,15 +807,20 @@ stdlib.h: stdlib.in.h -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \ -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \ -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \ + -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \ -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \ - -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ + -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ + -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \ + -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \ -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \ - -e 's|@''VOID_UNSETENV''@|$(VOID_UNSETENV)|g' \ - -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/stdlib.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ MOSTLYCLEANFILES += stdlib.h stdlib.h-t @@ -766,8 +858,8 @@ BUILT_SOURCES += string.h # We need the following in order to create when the system # doesn't have one that works with the given compiler. -string.h: string.in.h - rm -f $@-t $@ +string.h: string.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ @@ -795,6 +887,7 @@ string.h: string.in.h -e 's|@''GNULIB_STPNCPY''@|$(GNULIB_STPNCPY)|g' \ -e 's|@''GNULIB_STRCHRNUL''@|$(GNULIB_STRCHRNUL)|g' \ -e 's|@''GNULIB_STRDUP''@|$(GNULIB_STRDUP)|g' \ + -e 's|@''GNULIB_STRNCAT''@|$(GNULIB_STRNCAT)|g' \ -e 's|@''GNULIB_STRNDUP''@|$(GNULIB_STRNDUP)|g' \ -e 's|@''GNULIB_STRNLEN''@|$(GNULIB_STRNLEN)|g' \ -e 's|@''GNULIB_STRPBRK''@|$(GNULIB_STRPBRK)|g' \ @@ -805,6 +898,9 @@ string.h: string.in.h -e 's|@''GNULIB_STRERROR''@|$(GNULIB_STRERROR)|g' \ -e 's|@''GNULIB_STRSIGNAL''@|$(GNULIB_STRSIGNAL)|g' \ -e 's|@''GNULIB_STRVERSCMP''@|$(GNULIB_STRVERSCMP)|g' \ + < $(srcdir)/string.in.h | \ + sed -e 's|@''HAVE_MBSLEN''@|$(HAVE_MBSLEN)|g' \ + -e 's|@''HAVE_MEMCHR''@|$(HAVE_MEMCHR)|g' \ -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \ -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \ -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \ @@ -813,26 +909,32 @@ string.h: string.in.h -e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \ -e 's|@''HAVE_STRCHRNUL''@|$(HAVE_STRCHRNUL)|g' \ -e 's|@''HAVE_DECL_STRDUP''@|$(HAVE_DECL_STRDUP)|g' \ - -e 's|@''HAVE_STRNDUP''@|$(HAVE_STRNDUP)|g' \ -e 's|@''HAVE_DECL_STRNDUP''@|$(HAVE_DECL_STRNDUP)|g' \ -e 's|@''HAVE_DECL_STRNLEN''@|$(HAVE_DECL_STRNLEN)|g' \ -e 's|@''HAVE_STRPBRK''@|$(HAVE_STRPBRK)|g' \ -e 's|@''HAVE_STRSEP''@|$(HAVE_STRSEP)|g' \ -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \ -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \ - -e 's|@''HAVE_DECL_STRERROR''@|$(HAVE_DECL_STRERROR)|g' \ -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \ -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \ + -e 's|@''REPLACE_STPNCPY''@|$(REPLACE_STPNCPY)|g' \ -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \ -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \ -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \ -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \ -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \ -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \ + -e 's|@''REPLACE_STRNCAT''@|$(REPLACE_STRNCAT)|g' \ + -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \ + -e 's|@''REPLACE_STRNLEN''@|$(REPLACE_STRNLEN)|g' \ -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \ - -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \ + -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ < $(srcdir)/string.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ MOSTLYCLEANFILES += string.h string.h-t @@ -840,6 +942,23 @@ EXTRA_DIST += string.in.h ## end gnulib module string +## begin gnulib module strncat + + +EXTRA_DIST += strncat.c + +EXTRA_libunistring_la_SOURCES += strncat.c + +## end gnulib module strncat + +## begin gnulib module threadlib + +libunistring_la_SOURCES += glthread/threadlib.c + +EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath + +## end gnulib module threadlib + ## begin gnulib module unicase/base @@ -3008,8 +3127,8 @@ BUILT_SOURCES += unistd.h # We need the following in order to create an empty placeholder for # when the system doesn't have one. -unistd.h: unistd.in.h - rm -f $@-t $@ +unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -3018,56 +3137,105 @@ unistd.h: unistd.in.h -e 's|@''GNULIB_CHOWN''@|$(GNULIB_CHOWN)|g' \ -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \ -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \ + -e 's|@''GNULIB_DUP3''@|$(GNULIB_DUP3)|g' \ -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \ -e 's|@''GNULIB_EUIDACCESS''@|$(GNULIB_EUIDACCESS)|g' \ + -e 's|@''GNULIB_FACCESSAT''@|$(GNULIB_FACCESSAT)|g' \ -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \ + -e 's|@''GNULIB_FCHOWNAT''@|$(GNULIB_FCHOWNAT)|g' \ -e 's|@''GNULIB_FSYNC''@|$(GNULIB_FSYNC)|g' \ -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \ -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \ -e 's|@''GNULIB_GETDOMAINNAME''@|$(GNULIB_GETDOMAINNAME)|g' \ -e 's|@''GNULIB_GETDTABLESIZE''@|$(GNULIB_GETDTABLESIZE)|g' \ + -e 's|@''GNULIB_GETGROUPS''@|$(GNULIB_GETGROUPS)|g' \ -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \ + -e 's|@''GNULIB_GETLOGIN''@|$(GNULIB_GETLOGIN)|g' \ -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \ -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \ -e 's|@''GNULIB_GETUSERSHELL''@|$(GNULIB_GETUSERSHELL)|g' \ -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \ -e 's|@''GNULIB_LINK''@|$(GNULIB_LINK)|g' \ + -e 's|@''GNULIB_LINKAT''@|$(GNULIB_LINKAT)|g' \ -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \ + -e 's|@''GNULIB_PIPE2''@|$(GNULIB_PIPE2)|g' \ + -e 's|@''GNULIB_PREAD''@|$(GNULIB_PREAD)|g' \ -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \ + -e 's|@''GNULIB_READLINKAT''@|$(GNULIB_READLINKAT)|g' \ + -e 's|@''GNULIB_RMDIR''@|$(GNULIB_RMDIR)|g' \ -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \ + -e 's|@''GNULIB_SYMLINK''@|$(GNULIB_SYMLINK)|g' \ + -e 's|@''GNULIB_SYMLINKAT''@|$(GNULIB_SYMLINKAT)|g' \ + -e 's|@''GNULIB_TTYNAME_R''@|$(GNULIB_TTYNAME_R)|g' \ -e 's|@''GNULIB_UNISTD_H_GETOPT''@|$(GNULIB_UNISTD_H_GETOPT)|g' \ -e 's|@''GNULIB_UNISTD_H_SIGPIPE''@|$(GNULIB_UNISTD_H_SIGPIPE)|g' \ + -e 's|@''GNULIB_UNLINK''@|$(GNULIB_UNLINK)|g' \ + -e 's|@''GNULIB_UNLINKAT''@|$(GNULIB_UNLINKAT)|g' \ + -e 's|@''GNULIB_USLEEP''@|$(GNULIB_USLEEP)|g' \ -e 's|@''GNULIB_WRITE''@|$(GNULIB_WRITE)|g' \ + < $(srcdir)/unistd.in.h | \ + sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \ -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \ + -e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \ -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \ + -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \ + -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \ + -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \ -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \ -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \ -e 's|@''HAVE_GETDOMAINNAME''@|$(HAVE_GETDOMAINNAME)|g' \ -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \ + -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \ -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \ + -e 's|@''HAVE_GETLOGIN''@|$(HAVE_GETLOGIN)|g' \ -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \ - -e 's|@''HAVE_GETUSERSHELL''@|$(HAVE_GETUSERSHELL)|g' \ + -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \ -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \ + -e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \ + -e 's|@''HAVE_PIPE2''@|$(HAVE_PIPE2)|g' \ + -e 's|@''HAVE_PREAD''@|$(HAVE_PREAD)|g' \ -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \ + -e 's|@''HAVE_READLINKAT''@|$(HAVE_READLINKAT)|g' \ -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \ + -e 's|@''HAVE_SYMLINK''@|$(HAVE_SYMLINK)|g' \ + -e 's|@''HAVE_SYMLINKAT''@|$(HAVE_SYMLINKAT)|g' \ + -e 's|@''HAVE_TTYNAME_R''@|$(HAVE_TTYNAME_R)|g' \ + -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \ + -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \ -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \ -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \ + -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \ + -e 's|@''HAVE_DECL_GETUSERSHELL''@|$(HAVE_DECL_GETUSERSHELL)|g' \ -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \ -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \ -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \ -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \ + -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \ -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \ - -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \ + -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \ -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ + -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \ -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \ + -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \ + -e 's|@''REPLACE_LINKAT''@|$(REPLACE_LINKAT)|g' \ -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \ + -e 's|@''REPLACE_PREAD''@|$(REPLACE_PREAD)|g' \ + -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \ + -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \ + -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \ + -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \ + -e 's|@''REPLACE_TTYNAME_R''@|$(REPLACE_TTYNAME_R)|g' \ + -e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \ + -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \ + -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \ -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \ -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \ -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \ - -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ - < $(srcdir)/unistd.in.h; \ - } > $@-t + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ + } > $@-t && \ mv $@-t $@ MOSTLYCLEANFILES += unistd.h unistd.h-t @@ -4576,20 +4744,64 @@ EXTRA_DIST += uniwidth/cjk.h ## end gnulib module uniwidth/width +## begin gnulib module unused-parameter + +# The BUILT_SOURCES created by this Makefile snippet are not used via #include +# statements but through direct file reference. Therefore this snippet must be +# present in all Makefile.am that need it. This is ensured by the applicability +# 'all' defined above. + +BUILT_SOURCES += unused-parameter.h +# The unused-parameter.h that gets inserted into generated .h files is the same +# as build-aux/unused-parameter.h, except that it has the copyright header cut +# off. +unused-parameter.h: $(top_srcdir)/build-aux/unused-parameter.h + $(AM_V_GEN)rm -f $@-t $@ && \ + sed -n -e '/GL_UNUSED_PARAMETER/,$$p' \ + < $(top_srcdir)/build-aux/unused-parameter.h \ + > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += unused-parameter.h unused-parameter.h-t + +UNUSED_PARAMETER_H=unused-parameter.h + +EXTRA_DIST += $(top_srcdir)/build-aux/unused-parameter.h + +## end gnulib module unused-parameter + ## begin gnulib module verify libunistring_la_SOURCES += verify.h ## end gnulib module verify +## begin gnulib module warn-on-use + +BUILT_SOURCES += warn-on-use.h +# The warn-on-use.h that gets inserted into generated .h files is the same as +# build-aux/warn-on-use.h, except that it has the copyright header cut off. +warn-on-use.h: $(top_srcdir)/build-aux/warn-on-use.h + $(AM_V_GEN)rm -f $@-t $@ && \ + sed -n -e '/^.ifndef/,$$p' \ + < $(top_srcdir)/build-aux/warn-on-use.h \ + > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += warn-on-use.h warn-on-use.h-t + +WARN_ON_USE_H=warn-on-use.h + +EXTRA_DIST += $(top_srcdir)/build-aux/warn-on-use.h + +## end gnulib module warn-on-use + ## begin gnulib module wchar -BUILT_SOURCES += $(WCHAR_H) +BUILT_SOURCES += wchar.h # We need the following in order to create when the system # version does not work standalone. -wchar.h: wchar.in.h - rm -f $@-t $@ +wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ @@ -4630,9 +4842,11 @@ wchar.h: wchar.in.h -e 's|@''REPLACE_WCSRTOMBS''@|$(REPLACE_WCSRTOMBS)|g' \ -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \ -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \ - -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/wchar.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ MOSTLYCLEANFILES += wchar.h wchar.h-t @@ -4642,22 +4856,25 @@ EXTRA_DIST += wchar.in.h ## begin gnulib module wctype -BUILT_SOURCES += $(WCTYPE_H) +BUILT_SOURCES += wctype.h # We need the following in order to create when the system # doesn't have one that works with the given compiler. -wctype.h: wctype.in.h - rm -f $@-t $@ +wctype.h: wctype.in.h $(CXXDEFS_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \ + -e 's/@''HAVE_ISWBLANK''@/$(HAVE_ISWBLANK)/g' \ -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \ -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \ -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/wctype.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ MOSTLYCLEANFILES += wctype.h wctype.h-t diff --git a/lib/Makefile.in b/lib/Makefile.in index e243d6b3..6e979231 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.11 from Makefile.am. +# Makefile.in generated by automake 1.11.1 from Makefile.am. # @configure_input@ # Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, @@ -15,7 +15,7 @@ @SET_MAKE@ -# Copyright (C) 2002-2009 Free Software Foundation, Inc. +# Copyright (C) 2002-2010 Free Software Foundation, Inc. # # This file is free software, distributed under the terms of the GNU # General Public License. As a special exception to the GNU General @@ -59,17 +59,15 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/gnulib-m4/00gnulib.m4 \ $(top_srcdir)/gnulib-m4/alloca.m4 \ $(top_srcdir)/gnulib-m4/codeset.m4 \ - $(top_srcdir)/gnulib-m4/dup2.m4 \ $(top_srcdir)/gnulib-m4/eealloc.m4 \ $(top_srcdir)/gnulib-m4/environ.m4 \ $(top_srcdir)/gnulib-m4/errno_h.m4 \ $(top_srcdir)/gnulib-m4/error.m4 \ - $(top_srcdir)/gnulib-m4/exitfail.m4 \ $(top_srcdir)/gnulib-m4/exponentd.m4 \ $(top_srcdir)/gnulib-m4/exponentf.m4 \ $(top_srcdir)/gnulib-m4/exponentl.m4 \ $(top_srcdir)/gnulib-m4/extensions.m4 \ - $(top_srcdir)/gnulib-m4/fcntl_h.m4 \ + $(top_srcdir)/gnulib-m4/fcntl-o.m4 \ $(top_srcdir)/gnulib-m4/float_h.m4 \ $(top_srcdir)/gnulib-m4/fpieee.m4 \ $(top_srcdir)/gnulib-m4/frexp.m4 \ @@ -101,6 +99,7 @@ am__aclocal_m4_deps = $(top_srcdir)/gnulib-m4/00gnulib.m4 \ $(top_srcdir)/gnulib-m4/locale-zh.m4 \ $(top_srcdir)/gnulib-m4/locale_h.m4 \ $(top_srcdir)/gnulib-m4/localename.m4 \ + $(top_srcdir)/gnulib-m4/lock.m4 \ $(top_srcdir)/gnulib-m4/longlong.m4 \ $(top_srcdir)/gnulib-m4/malloc.m4 \ $(top_srcdir)/gnulib-m4/malloca.m4 \ @@ -113,13 +112,12 @@ am__aclocal_m4_deps = $(top_srcdir)/gnulib-m4/00gnulib.m4 \ $(top_srcdir)/gnulib-m4/memchr.m4 \ $(top_srcdir)/gnulib-m4/minmax.m4 \ $(top_srcdir)/gnulib-m4/mmap-anon.m4 \ - $(top_srcdir)/gnulib-m4/mode_t.m4 \ $(top_srcdir)/gnulib-m4/multiarch.m4 \ $(top_srcdir)/gnulib-m4/nocrash.m4 \ - $(top_srcdir)/gnulib-m4/open.m4 \ $(top_srcdir)/gnulib-m4/printf-frexp.m4 \ $(top_srcdir)/gnulib-m4/printf-frexpl.m4 \ $(top_srcdir)/gnulib-m4/printf.m4 \ + $(top_srcdir)/gnulib-m4/putenv.m4 \ $(top_srcdir)/gnulib-m4/relocatable-lib.m4 \ $(top_srcdir)/gnulib-m4/setenv.m4 \ $(top_srcdir)/gnulib-m4/signbit.m4 \ @@ -131,16 +129,21 @@ am__aclocal_m4_deps = $(top_srcdir)/gnulib-m4/00gnulib.m4 \ $(top_srcdir)/gnulib-m4/stdlib_h.m4 \ $(top_srcdir)/gnulib-m4/strerror.m4 \ $(top_srcdir)/gnulib-m4/string_h.m4 \ + $(top_srcdir)/gnulib-m4/strncat.m4 \ + $(top_srcdir)/gnulib-m4/thread.m4 \ + $(top_srcdir)/gnulib-m4/threadlib.m4 \ $(top_srcdir)/gnulib-m4/unistd_h.m4 \ $(top_srcdir)/gnulib-m4/vasnprintf.m4 \ - $(top_srcdir)/gnulib-m4/wchar.m4 \ + $(top_srcdir)/gnulib-m4/warn-on-use.m4 \ + $(top_srcdir)/gnulib-m4/wchar_h.m4 \ $(top_srcdir)/gnulib-m4/wchar_t.m4 \ $(top_srcdir)/gnulib-m4/wctob.m4 \ - $(top_srcdir)/gnulib-m4/wctype.m4 \ + $(top_srcdir)/gnulib-m4/wctype_h.m4 \ $(top_srcdir)/gnulib-m4/wcwidth.m4 \ $(top_srcdir)/gnulib-m4/wint_t.m4 \ $(top_srcdir)/gnulib-m4/xalloc.m4 \ - $(top_srcdir)/gnulib-m4/xsize.m4 $(top_srcdir)/m4/exported.m4 \ + $(top_srcdir)/gnulib-m4/xsize.m4 \ + $(top_srcdir)/gnulib-m4/yield.m4 $(top_srcdir)/m4/exported.m4 \ $(top_srcdir)/m4/init-package-version.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ @@ -180,10 +183,11 @@ am__DEPENDENCIES_1 = @WOE32_TRUE@am__DEPENDENCIES_2 = libunistring.res.lo am__libunistring_la_SOURCES_DIST = c-ctype.h c-ctype.c c-strcase.h \ c-strcasecmp.c c-strncasecmp.c fseterr.c localcharset.h \ - localcharset.c localename.c malloca.c mbchar.c mbiter.h \ - mbsnlen.c memcmp2.c memxfrm.c minmax.h printf-frexp.c \ - printf-frexpl.c size_max.h striconveh.h striconveh.c \ - striconveha.h striconveha.c unicase/cased.c \ + localcharset.c localename.c glthread/lock.h glthread/lock.c \ + malloca.c mbchar.c mbiter.h mbsnlen.c memcmp2.c memxfrm.c \ + minmax.h printf-frexp.c printf-frexpl.c size_max.h \ + striconveh.h striconveh.c striconveha.h striconveha.c \ + glthread/threadlib.c unicase/cased.c \ unicase/empty-prefix-context.c unicase/empty-suffix-context.c \ unicase/ignorable.c unicase/locale-language.c \ unicase/special-casing.c unicase/tocasefold.c \ @@ -411,9 +415,10 @@ am__dirstamp = $(am__leading_dot)dirstamp @WOE32DLL_TRUE@am__objects_1 = ../woe32dll/unistring-exports.lo am_libunistring_la_OBJECTS = c-ctype.lo c-strcasecmp.lo \ c-strncasecmp.lo fseterr.lo localcharset.lo localename.lo \ - malloca.lo mbchar.lo mbsnlen.lo memcmp2.lo memxfrm.lo \ - printf-frexp.lo printf-frexpl.lo striconveh.lo striconveha.lo \ - unicase/cased.lo unicase/empty-prefix-context.lo \ + glthread/lock.lo malloca.lo mbchar.lo mbsnlen.lo memcmp2.lo \ + memxfrm.lo printf-frexp.lo printf-frexpl.lo striconveh.lo \ + striconveha.lo glthread/threadlib.lo unicase/cased.lo \ + unicase/empty-prefix-context.lo \ unicase/empty-suffix-context.lo unicase/ignorable.lo \ unicase/locale-language.lo unicase/special-casing.lo \ unicase/tocasefold.lo unicase/tolower.lo unicase/totitle.lo \ @@ -735,22 +740,31 @@ EOVERFLOW_HIDDEN = @EOVERFLOW_HIDDEN@ EOVERFLOW_VALUE = @EOVERFLOW_VALUE@ ERRNO_H = @ERRNO_H@ EXEEXT = @EXEEXT@ -FCNTL_H = @FCNTL_H@ FGREP = @FGREP@ FLOAT_H = @FLOAT_H@ GLIBC21 = @GLIBC21@ GLOBAL_SYMBOL_PIPE = @GLOBAL_SYMBOL_PIPE@ +GNULIB_ACOSL = @GNULIB_ACOSL@ +GNULIB_ASINL = @GNULIB_ASINL@ +GNULIB_ATANL = @GNULIB_ATANL@ GNULIB_ATOLL = @GNULIB_ATOLL@ GNULIB_BTOWC = @GNULIB_BTOWC@ GNULIB_CALLOC_POSIX = @GNULIB_CALLOC_POSIX@ +GNULIB_CANONICALIZE_FILE_NAME = @GNULIB_CANONICALIZE_FILE_NAME@ GNULIB_CEILF = @GNULIB_CEILF@ GNULIB_CEILL = @GNULIB_CEILL@ GNULIB_CHOWN = @GNULIB_CHOWN@ GNULIB_CLOSE = @GNULIB_CLOSE@ +GNULIB_COSL = @GNULIB_COSL@ GNULIB_DUP2 = @GNULIB_DUP2@ +GNULIB_DUP3 = @GNULIB_DUP3@ +GNULIB_DUPLOCALE = @GNULIB_DUPLOCALE@ GNULIB_ENVIRON = @GNULIB_ENVIRON@ GNULIB_EUIDACCESS = @GNULIB_EUIDACCESS@ +GNULIB_EXPL = @GNULIB_EXPL@ +GNULIB_FACCESSAT = @GNULIB_FACCESSAT@ GNULIB_FCHDIR = @GNULIB_FCHDIR@ +GNULIB_FCHOWNAT = @GNULIB_FCHOWNAT@ GNULIB_FLOORF = @GNULIB_FLOORF@ GNULIB_FLOORL = @GNULIB_FLOORL@ GNULIB_FREXP = @GNULIB_FREXP@ @@ -760,12 +774,15 @@ GNULIB_FTRUNCATE = @GNULIB_FTRUNCATE@ GNULIB_GETCWD = @GNULIB_GETCWD@ GNULIB_GETDOMAINNAME = @GNULIB_GETDOMAINNAME@ GNULIB_GETDTABLESIZE = @GNULIB_GETDTABLESIZE@ +GNULIB_GETGROUPS = @GNULIB_GETGROUPS@ GNULIB_GETHOSTNAME = @GNULIB_GETHOSTNAME@ GNULIB_GETLOADAVG = @GNULIB_GETLOADAVG@ +GNULIB_GETLOGIN = @GNULIB_GETLOGIN@ GNULIB_GETLOGIN_R = @GNULIB_GETLOGIN_R@ GNULIB_GETPAGESIZE = @GNULIB_GETPAGESIZE@ GNULIB_GETSUBOPT = @GNULIB_GETSUBOPT@ GNULIB_GETUSERSHELL = @GNULIB_GETUSERSHELL@ +GNULIB_GRANTPT = @GNULIB_GRANTPT@ GNULIB_ISFINITE = @GNULIB_ISFINITE@ GNULIB_ISINF = @GNULIB_ISINF@ GNULIB_ISNAN = @GNULIB_ISNAN@ @@ -775,9 +792,11 @@ GNULIB_ISNANL = @GNULIB_ISNANL@ GNULIB_LCHOWN = @GNULIB_LCHOWN@ GNULIB_LDEXPL = @GNULIB_LDEXPL@ GNULIB_LINK = @GNULIB_LINK@ +GNULIB_LINKAT = @GNULIB_LINKAT@ +GNULIB_LOGB = @GNULIB_LOGB@ +GNULIB_LOGL = @GNULIB_LOGL@ GNULIB_LSEEK = @GNULIB_LSEEK@ GNULIB_MALLOC_POSIX = @GNULIB_MALLOC_POSIX@ -GNULIB_MATHL = @GNULIB_MATHL@ GNULIB_MBRLEN = @GNULIB_MBRLEN@ GNULIB_MBRTOWC = @GNULIB_MBRTOWC@ GNULIB_MBSCASECMP = @GNULIB_MBSCASECMP@ @@ -802,26 +821,37 @@ GNULIB_MEMMEM = @GNULIB_MEMMEM@ GNULIB_MEMPCPY = @GNULIB_MEMPCPY@ GNULIB_MEMRCHR = @GNULIB_MEMRCHR@ GNULIB_MKDTEMP = @GNULIB_MKDTEMP@ +GNULIB_MKOSTEMP = @GNULIB_MKOSTEMP@ +GNULIB_MKOSTEMPS = @GNULIB_MKOSTEMPS@ GNULIB_MKSTEMP = @GNULIB_MKSTEMP@ -GNULIB_OPEN = @GNULIB_OPEN@ +GNULIB_MKSTEMPS = @GNULIB_MKSTEMPS@ +GNULIB_PIPE2 = @GNULIB_PIPE2@ +GNULIB_PREAD = @GNULIB_PREAD@ +GNULIB_PTSNAME = @GNULIB_PTSNAME@ GNULIB_PUTENV = @GNULIB_PUTENV@ GNULIB_RANDOM_R = @GNULIB_RANDOM_R@ GNULIB_RAWMEMCHR = @GNULIB_RAWMEMCHR@ GNULIB_READLINK = @GNULIB_READLINK@ +GNULIB_READLINKAT = @GNULIB_READLINKAT@ GNULIB_REALLOC_POSIX = @GNULIB_REALLOC_POSIX@ +GNULIB_REALPATH = @GNULIB_REALPATH@ +GNULIB_RMDIR = @GNULIB_RMDIR@ GNULIB_ROUND = @GNULIB_ROUND@ GNULIB_ROUNDF = @GNULIB_ROUNDF@ GNULIB_ROUNDL = @GNULIB_ROUNDL@ GNULIB_RPMATCH = @GNULIB_RPMATCH@ GNULIB_SETENV = @GNULIB_SETENV@ GNULIB_SIGNBIT = @GNULIB_SIGNBIT@ +GNULIB_SINL = @GNULIB_SINL@ GNULIB_SLEEP = @GNULIB_SLEEP@ +GNULIB_SQRTL = @GNULIB_SQRTL@ GNULIB_STPCPY = @GNULIB_STPCPY@ GNULIB_STPNCPY = @GNULIB_STPNCPY@ GNULIB_STRCASESTR = @GNULIB_STRCASESTR@ GNULIB_STRCHRNUL = @GNULIB_STRCHRNUL@ GNULIB_STRDUP = @GNULIB_STRDUP@ GNULIB_STRERROR = @GNULIB_STRERROR@ +GNULIB_STRNCAT = @GNULIB_STRNCAT@ GNULIB_STRNDUP = @GNULIB_STRNDUP@ GNULIB_STRNLEN = @GNULIB_STRNLEN@ GNULIB_STRPBRK = @GNULIB_STRPBRK@ @@ -833,12 +863,20 @@ GNULIB_STRTOK_R = @GNULIB_STRTOK_R@ GNULIB_STRTOLL = @GNULIB_STRTOLL@ GNULIB_STRTOULL = @GNULIB_STRTOULL@ GNULIB_STRVERSCMP = @GNULIB_STRVERSCMP@ +GNULIB_SYMLINK = @GNULIB_SYMLINK@ +GNULIB_SYMLINKAT = @GNULIB_SYMLINKAT@ +GNULIB_TANL = @GNULIB_TANL@ GNULIB_TRUNC = @GNULIB_TRUNC@ GNULIB_TRUNCF = @GNULIB_TRUNCF@ GNULIB_TRUNCL = @GNULIB_TRUNCL@ +GNULIB_TTYNAME_R = @GNULIB_TTYNAME_R@ GNULIB_UNISTD_H_GETOPT = @GNULIB_UNISTD_H_GETOPT@ GNULIB_UNISTD_H_SIGPIPE = @GNULIB_UNISTD_H_SIGPIPE@ +GNULIB_UNLINK = @GNULIB_UNLINK@ +GNULIB_UNLINKAT = @GNULIB_UNLINKAT@ +GNULIB_UNLOCKPT = @GNULIB_UNLOCKPT@ GNULIB_UNSETENV = @GNULIB_UNSETENV@ +GNULIB_USLEEP = @GNULIB_USLEEP@ GNULIB_WCRTOMB = @GNULIB_WCRTOMB@ GNULIB_WCSNRTOMBS = @GNULIB_WCSNRTOMBS@ GNULIB_WCSRTOMBS = @GNULIB_WCSRTOMBS@ @@ -846,26 +884,41 @@ GNULIB_WCTOB = @GNULIB_WCTOB@ GNULIB_WCWIDTH = @GNULIB_WCWIDTH@ GNULIB_WRITE = @GNULIB_WRITE@ GREP = @GREP@ +HAVE_ACOSL = @HAVE_ACOSL@ +HAVE_ASINL = @HAVE_ASINL@ +HAVE_ATANL = @HAVE_ATANL@ HAVE_ATOLL = @HAVE_ATOLL@ HAVE_BTOWC = @HAVE_BTOWC@ HAVE_CALLOC_POSIX = @HAVE_CALLOC_POSIX@ +HAVE_CANONICALIZE_FILE_NAME = @HAVE_CANONICALIZE_FILE_NAME@ +HAVE_CHOWN = @HAVE_CHOWN@ +HAVE_COSL = @HAVE_COSL@ HAVE_DECL_ACOSL = @HAVE_DECL_ACOSL@ HAVE_DECL_ASINL = @HAVE_DECL_ASINL@ HAVE_DECL_ATANL = @HAVE_DECL_ATANL@ +HAVE_DECL_CEILF = @HAVE_DECL_CEILF@ +HAVE_DECL_CEILL = @HAVE_DECL_CEILL@ HAVE_DECL_COSL = @HAVE_DECL_COSL@ HAVE_DECL_ENVIRON = @HAVE_DECL_ENVIRON@ HAVE_DECL_EXPL = @HAVE_DECL_EXPL@ +HAVE_DECL_FLOORF = @HAVE_DECL_FLOORF@ +HAVE_DECL_FLOORL = @HAVE_DECL_FLOORL@ HAVE_DECL_FREXPL = @HAVE_DECL_FREXPL@ HAVE_DECL_GETLOADAVG = @HAVE_DECL_GETLOADAVG@ HAVE_DECL_GETLOGIN_R = @HAVE_DECL_GETLOGIN_R@ +HAVE_DECL_GETPAGESIZE = @HAVE_DECL_GETPAGESIZE@ +HAVE_DECL_GETUSERSHELL = @HAVE_DECL_GETUSERSHELL@ HAVE_DECL_LDEXPL = @HAVE_DECL_LDEXPL@ +HAVE_DECL_LOGB = @HAVE_DECL_LOGB@ HAVE_DECL_LOGL = @HAVE_DECL_LOGL@ HAVE_DECL_MEMMEM = @HAVE_DECL_MEMMEM@ HAVE_DECL_MEMRCHR = @HAVE_DECL_MEMRCHR@ +HAVE_DECL_ROUND = @HAVE_DECL_ROUND@ +HAVE_DECL_ROUNDF = @HAVE_DECL_ROUNDF@ +HAVE_DECL_ROUNDL = @HAVE_DECL_ROUNDL@ HAVE_DECL_SINL = @HAVE_DECL_SINL@ HAVE_DECL_SQRTL = @HAVE_DECL_SQRTL@ HAVE_DECL_STRDUP = @HAVE_DECL_STRDUP@ -HAVE_DECL_STRERROR = @HAVE_DECL_STRERROR@ HAVE_DECL_STRNDUP = @HAVE_DECL_STRNDUP@ HAVE_DECL_STRNLEN = @HAVE_DECL_STRNLEN@ HAVE_DECL_STRSIGNAL = @HAVE_DECL_STRSIGNAL@ @@ -873,52 +926,77 @@ HAVE_DECL_STRTOK_R = @HAVE_DECL_STRTOK_R@ HAVE_DECL_TANL = @HAVE_DECL_TANL@ HAVE_DECL_TRUNC = @HAVE_DECL_TRUNC@ HAVE_DECL_TRUNCF = @HAVE_DECL_TRUNCF@ +HAVE_DECL_TRUNCL = @HAVE_DECL_TRUNCL@ HAVE_DECL_WCTOB = @HAVE_DECL_WCTOB@ HAVE_DECL_WCWIDTH = @HAVE_DECL_WCWIDTH@ HAVE_DUP2 = @HAVE_DUP2@ +HAVE_DUP3 = @HAVE_DUP3@ +HAVE_DUPLOCALE = @HAVE_DUPLOCALE@ HAVE_EUIDACCESS = @HAVE_EUIDACCESS@ +HAVE_EXPL = @HAVE_EXPL@ +HAVE_FACCESSAT = @HAVE_FACCESSAT@ +HAVE_FCHDIR = @HAVE_FCHDIR@ +HAVE_FCHOWNAT = @HAVE_FCHOWNAT@ HAVE_FSYNC = @HAVE_FSYNC@ HAVE_FTRUNCATE = @HAVE_FTRUNCATE@ HAVE_GETDOMAINNAME = @HAVE_GETDOMAINNAME@ HAVE_GETDTABLESIZE = @HAVE_GETDTABLESIZE@ +HAVE_GETGROUPS = @HAVE_GETGROUPS@ HAVE_GETHOSTNAME = @HAVE_GETHOSTNAME@ +HAVE_GETLOGIN = @HAVE_GETLOGIN@ HAVE_GETPAGESIZE = @HAVE_GETPAGESIZE@ HAVE_GETSUBOPT = @HAVE_GETSUBOPT@ -HAVE_GETUSERSHELL = @HAVE_GETUSERSHELL@ HAVE_GLOBAL_SYMBOL_PIPE = @HAVE_GLOBAL_SYMBOL_PIPE@ +HAVE_GRANTPT = @HAVE_GRANTPT@ HAVE_INTTYPES_H = @HAVE_INTTYPES_H@ HAVE_ISNAND = @HAVE_ISNAND@ HAVE_ISNANF = @HAVE_ISNANF@ HAVE_ISNANL = @HAVE_ISNANL@ +HAVE_ISWBLANK = @HAVE_ISWBLANK@ HAVE_ISWCNTRL = @HAVE_ISWCNTRL@ +HAVE_LCHOWN = @HAVE_LCHOWN@ HAVE_LINK = @HAVE_LINK@ +HAVE_LINKAT = @HAVE_LINKAT@ +HAVE_LOGL = @HAVE_LOGL@ HAVE_LONG_LONG_INT = @HAVE_LONG_LONG_INT@ HAVE_MALLOC_POSIX = @HAVE_MALLOC_POSIX@ HAVE_MBRLEN = @HAVE_MBRLEN@ HAVE_MBRTOWC = @HAVE_MBRTOWC@ HAVE_MBSINIT = @HAVE_MBSINIT@ +HAVE_MBSLEN = @HAVE_MBSLEN@ HAVE_MBSNRTOWCS = @HAVE_MBSNRTOWCS@ HAVE_MBSRTOWCS = @HAVE_MBSRTOWCS@ +HAVE_MEMCHR = @HAVE_MEMCHR@ HAVE_MEMPCPY = @HAVE_MEMPCPY@ HAVE_MKDTEMP = @HAVE_MKDTEMP@ +HAVE_MKOSTEMP = @HAVE_MKOSTEMP@ +HAVE_MKOSTEMPS = @HAVE_MKOSTEMPS@ +HAVE_MKSTEMP = @HAVE_MKSTEMP@ +HAVE_MKSTEMPS = @HAVE_MKSTEMPS@ HAVE_OS_H = @HAVE_OS_H@ +HAVE_PIPE2 = @HAVE_PIPE2@ +HAVE_PREAD = @HAVE_PREAD@ +HAVE_PTSNAME = @HAVE_PTSNAME@ HAVE_RANDOM_H = @HAVE_RANDOM_H@ HAVE_RANDOM_R = @HAVE_RANDOM_R@ HAVE_RAWMEMCHR = @HAVE_RAWMEMCHR@ HAVE_READLINK = @HAVE_READLINK@ +HAVE_READLINKAT = @HAVE_READLINKAT@ HAVE_REALLOC_POSIX = @HAVE_REALLOC_POSIX@ +HAVE_REALPATH = @HAVE_REALPATH@ HAVE_RPMATCH = @HAVE_RPMATCH@ HAVE_SETENV = @HAVE_SETENV@ HAVE_SIGNED_SIG_ATOMIC_T = @HAVE_SIGNED_SIG_ATOMIC_T@ HAVE_SIGNED_WCHAR_T = @HAVE_SIGNED_WCHAR_T@ HAVE_SIGNED_WINT_T = @HAVE_SIGNED_WINT_T@ +HAVE_SINL = @HAVE_SINL@ HAVE_SLEEP = @HAVE_SLEEP@ +HAVE_SQRTL = @HAVE_SQRTL@ HAVE_STDINT_H = @HAVE_STDINT_H@ HAVE_STPCPY = @HAVE_STPCPY@ HAVE_STPNCPY = @HAVE_STPNCPY@ HAVE_STRCASESTR = @HAVE_STRCASESTR@ HAVE_STRCHRNUL = @HAVE_STRCHRNUL@ -HAVE_STRNDUP = @HAVE_STRNDUP@ HAVE_STRPBRK = @HAVE_STRPBRK@ HAVE_STRSEP = @HAVE_STRSEP@ HAVE_STRTOD = @HAVE_STRTOD@ @@ -926,14 +1004,21 @@ HAVE_STRTOLL = @HAVE_STRTOLL@ HAVE_STRTOULL = @HAVE_STRTOULL@ HAVE_STRUCT_RANDOM_DATA = @HAVE_STRUCT_RANDOM_DATA@ HAVE_STRVERSCMP = @HAVE_STRVERSCMP@ +HAVE_SYMLINK = @HAVE_SYMLINK@ +HAVE_SYMLINKAT = @HAVE_SYMLINKAT@ HAVE_SYS_BITYPES_H = @HAVE_SYS_BITYPES_H@ HAVE_SYS_INTTYPES_H = @HAVE_SYS_INTTYPES_H@ HAVE_SYS_LOADAVG_H = @HAVE_SYS_LOADAVG_H@ HAVE_SYS_PARAM_H = @HAVE_SYS_PARAM_H@ HAVE_SYS_TYPES_H = @HAVE_SYS_TYPES_H@ +HAVE_TANL = @HAVE_TANL@ +HAVE_TTYNAME_R = @HAVE_TTYNAME_R@ HAVE_UNISTD_H = @HAVE_UNISTD_H@ +HAVE_UNLINKAT = @HAVE_UNLINKAT@ +HAVE_UNLOCKPT = @HAVE_UNLOCKPT@ HAVE_UNSETENV = @HAVE_UNSETENV@ HAVE_UNSIGNED_LONG_LONG_INT = @HAVE_UNSIGNED_LONG_LONG_INT@ +HAVE_USLEEP = @HAVE_USLEEP@ HAVE_WCHAR_H = @HAVE_WCHAR_H@ HAVE_WCHAR_T = @HAVE_WCHAR_T@ HAVE_WCRTOMB = @HAVE_WCRTOMB@ @@ -941,6 +1026,7 @@ HAVE_WCSNRTOMBS = @HAVE_WCSNRTOMBS@ HAVE_WCSRTOMBS = @HAVE_WCSRTOMBS@ HAVE_WCTYPE_H = @HAVE_WCTYPE_H@ HAVE_WINT_T = @HAVE_WINT_T@ +HAVE_XLOCALE_H = @HAVE_XLOCALE_H@ HAVE__BOOL = @HAVE__BOOL@ HEXVERSION = @HEXVERSION@ ICONV_H = @ICONV_H@ @@ -956,27 +1042,32 @@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ +LIBMULTITHREAD = @LIBMULTITHREAD@ LIBOBJS = @LIBOBJS@ +LIBPTH = @LIBPTH@ +LIBPTH_PREFIX = @LIBPTH_PREFIX@ LIBS = @LIBS@ LIBTESTS_LIBDEPS = @LIBTESTS_LIBDEPS@ +LIBTHREAD = @LIBTHREAD@ LIBTOOL = @LIBTOOL@ LIPO = @LIPO@ LN_S = @LN_S@ LOCALCHARSET_TESTS_ENVIRONMENT = @LOCALCHARSET_TESTS_ENVIRONMENT@ LOCALE_FR = @LOCALE_FR@ LOCALE_FR_UTF8 = @LOCALE_FR_UTF8@ -LOCALE_H = @LOCALE_H@ LOCALE_JA = @LOCALE_JA@ LOCALE_TR_UTF8 = @LOCALE_TR_UTF8@ LOCALE_ZH_CN = @LOCALE_ZH_CN@ LTLIBICONV = @LTLIBICONV@ LTLIBINTL = @LTLIBINTL@ +LTLIBMULTITHREAD = @LTLIBMULTITHREAD@ LTLIBOBJS = @LTLIBOBJS@ +LTLIBPTH = @LTLIBPTH@ +LTLIBTHREAD = @LTLIBTHREAD@ MAKEINFO = @MAKEINFO@ MKDIR_P = @MKDIR_P@ NAMESPACING = @NAMESPACING@ NEXT_AS_FIRST_DIRECTIVE_ERRNO_H = @NEXT_AS_FIRST_DIRECTIVE_ERRNO_H@ -NEXT_AS_FIRST_DIRECTIVE_FCNTL_H = @NEXT_AS_FIRST_DIRECTIVE_FCNTL_H@ NEXT_AS_FIRST_DIRECTIVE_FLOAT_H = @NEXT_AS_FIRST_DIRECTIVE_FLOAT_H@ NEXT_AS_FIRST_DIRECTIVE_ICONV_H = @NEXT_AS_FIRST_DIRECTIVE_ICONV_H@ NEXT_AS_FIRST_DIRECTIVE_LOCALE_H = @NEXT_AS_FIRST_DIRECTIVE_LOCALE_H@ @@ -989,7 +1080,6 @@ NEXT_AS_FIRST_DIRECTIVE_UNISTD_H = @NEXT_AS_FIRST_DIRECTIVE_UNISTD_H@ NEXT_AS_FIRST_DIRECTIVE_WCHAR_H = @NEXT_AS_FIRST_DIRECTIVE_WCHAR_H@ NEXT_AS_FIRST_DIRECTIVE_WCTYPE_H = @NEXT_AS_FIRST_DIRECTIVE_WCTYPE_H@ NEXT_ERRNO_H = @NEXT_ERRNO_H@ -NEXT_FCNTL_H = @NEXT_FCNTL_H@ NEXT_FLOAT_H = @NEXT_FLOAT_H@ NEXT_ICONV_H = @NEXT_ICONV_H@ NEXT_LOCALE_H = @NEXT_LOCALE_H@ @@ -1022,17 +1112,21 @@ RANLIB = @RANLIB@ RC = @RC@ RELOCATABLE = @RELOCATABLE@ REPLACE_BTOWC = @REPLACE_BTOWC@ +REPLACE_CANONICALIZE_FILE_NAME = @REPLACE_CANONICALIZE_FILE_NAME@ REPLACE_CEILF = @REPLACE_CEILF@ REPLACE_CEILL = @REPLACE_CEILL@ REPLACE_CHOWN = @REPLACE_CHOWN@ REPLACE_CLOSE = @REPLACE_CLOSE@ +REPLACE_DUP = @REPLACE_DUP@ REPLACE_DUP2 = @REPLACE_DUP2@ -REPLACE_FCHDIR = @REPLACE_FCHDIR@ +REPLACE_DUPLOCALE = @REPLACE_DUPLOCALE@ +REPLACE_FCHOWNAT = @REPLACE_FCHOWNAT@ REPLACE_FLOORF = @REPLACE_FLOORF@ REPLACE_FLOORL = @REPLACE_FLOORL@ REPLACE_FREXP = @REPLACE_FREXP@ REPLACE_FREXPL = @REPLACE_FREXPL@ REPLACE_GETCWD = @REPLACE_GETCWD@ +REPLACE_GETGROUPS = @REPLACE_GETGROUPS@ REPLACE_GETPAGESIZE = @REPLACE_GETPAGESIZE@ REPLACE_HUGE_VAL = @REPLACE_HUGE_VAL@ REPLACE_ICONV = @REPLACE_ICONV@ @@ -1044,6 +1138,8 @@ REPLACE_ISNAN = @REPLACE_ISNAN@ REPLACE_ISWCNTRL = @REPLACE_ISWCNTRL@ REPLACE_LCHOWN = @REPLACE_LCHOWN@ REPLACE_LDEXPL = @REPLACE_LDEXPL@ +REPLACE_LINK = @REPLACE_LINK@ +REPLACE_LINKAT = @REPLACE_LINKAT@ REPLACE_LSEEK = @REPLACE_LSEEK@ REPLACE_MBRLEN = @REPLACE_MBRLEN@ REPLACE_MBRTOWC = @REPLACE_MBRTOWC@ @@ -1056,20 +1152,36 @@ REPLACE_MEMMEM = @REPLACE_MEMMEM@ REPLACE_MKSTEMP = @REPLACE_MKSTEMP@ REPLACE_NAN = @REPLACE_NAN@ REPLACE_NULL = @REPLACE_NULL@ -REPLACE_OPEN = @REPLACE_OPEN@ +REPLACE_PREAD = @REPLACE_PREAD@ REPLACE_PUTENV = @REPLACE_PUTENV@ +REPLACE_READLINK = @REPLACE_READLINK@ +REPLACE_REALPATH = @REPLACE_REALPATH@ +REPLACE_RMDIR = @REPLACE_RMDIR@ REPLACE_ROUND = @REPLACE_ROUND@ REPLACE_ROUNDF = @REPLACE_ROUNDF@ REPLACE_ROUNDL = @REPLACE_ROUNDL@ +REPLACE_SETENV = @REPLACE_SETENV@ REPLACE_SIGNBIT = @REPLACE_SIGNBIT@ REPLACE_SIGNBIT_USING_GCC = @REPLACE_SIGNBIT_USING_GCC@ +REPLACE_SLEEP = @REPLACE_SLEEP@ +REPLACE_STPNCPY = @REPLACE_STPNCPY@ REPLACE_STRCASESTR = @REPLACE_STRCASESTR@ REPLACE_STRDUP = @REPLACE_STRDUP@ REPLACE_STRERROR = @REPLACE_STRERROR@ +REPLACE_STRNCAT = @REPLACE_STRNCAT@ +REPLACE_STRNDUP = @REPLACE_STRNDUP@ +REPLACE_STRNLEN = @REPLACE_STRNLEN@ REPLACE_STRSIGNAL = @REPLACE_STRSIGNAL@ REPLACE_STRSTR = @REPLACE_STRSTR@ REPLACE_STRTOD = @REPLACE_STRTOD@ +REPLACE_STRTOK_R = @REPLACE_STRTOK_R@ +REPLACE_SYMLINK = @REPLACE_SYMLINK@ REPLACE_TRUNCL = @REPLACE_TRUNCL@ +REPLACE_TTYNAME_R = @REPLACE_TTYNAME_R@ +REPLACE_UNLINK = @REPLACE_UNLINK@ +REPLACE_UNLINKAT = @REPLACE_UNLINKAT@ +REPLACE_UNSETENV = @REPLACE_UNSETENV@ +REPLACE_USLEEP = @REPLACE_USLEEP@ REPLACE_WCRTOMB = @REPLACE_WCRTOMB@ REPLACE_WCSNRTOMBS = @REPLACE_WCSNRTOMBS@ REPLACE_WCSRTOMBS = @REPLACE_WCSRTOMBS@ @@ -1086,14 +1198,13 @@ STDDEF_H = @STDDEF_H@ STDINT_H = @STDINT_H@ STRIP = @STRIP@ TEXI2DVI = @TEXI2DVI@ +UNDEFINE_STRTOK_R = @UNDEFINE_STRTOK_R@ UNISTD_H_HAVE_WINSOCK2_H = @UNISTD_H_HAVE_WINSOCK2_H@ UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS = @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@ VERSION = @VERSION@ -VOID_UNSETENV = @VOID_UNSETENV@ -WCHAR_H = @WCHAR_H@ WCHAR_T_SUFFIX = @WCHAR_T_SUFFIX@ -WCTYPE_H = @WCTYPE_H@ WINT_T_SUFFIX = @WINT_T_SUFFIX@ +YIELD_LIB = @YIELD_LIB@ abs_builddir = @abs_builddir@ abs_srcdir = @abs_srcdir@ abs_top_builddir = @abs_top_builddir@ @@ -1121,6 +1232,7 @@ gl_LIBOBJS = @gl_LIBOBJS@ gl_LTLIBOBJS = @gl_LTLIBOBJS@ gltests_LIBOBJS = @gltests_LIBOBJS@ gltests_LTLIBOBJS = @gltests_LTLIBOBJS@ +gltests_WITNESS = @gltests_WITNESS@ host = @host@ host_alias = @host_alias@ host_cpu = @host_cpu@ @@ -1153,26 +1265,29 @@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = 1.5 gnits subdir-objects no-dependencies # Version information according to Woe32 conventions. -EXTRA_DIST = alloca.in.h array-mergesort.h c-strcaseeq.h dup2.c \ - errno.in.h float.in.h fpucw.h frexp.c frexpl.c fseterr.h \ - stdio-impl.h getpagesize.c \ - $(top_srcdir)/build-aux/config.rpath iconv_open-aix.h \ - iconv_open-hpux.h iconv_open-irix.h iconv_open-osf.h \ - iconv.in.h iconv_open-aix.gperf iconv_open-hpux.gperf \ - iconv_open-irix.gperf iconv_open-osf.gperf iconv_open.c \ - float+.h isnan.c isnand-nolibm.h isnand.c float+.h isnan.c \ - isnanf-nolibm.h isnanf.c float+.h isnan.c isnanl-nolibm.h \ - isnanl.c $(top_srcdir)/build-aux/link-warning.h config.charset \ - ref-add.sin ref-del.sin localename.h malloc.c malloca.h \ - malloca.valgrind math.in.h mbchar.h mbrtowc.c mbsinit.c \ - memchr.c memchr.valgrind memcmp2.h memxfrm.h printf-frexp.h \ - printf-frexp.c printf-frexpl.h relocatable.c relocatable.h \ - float+.h signbitd.c signbitf.c signbitl.c stdbool.in.h \ - stddef.in.h stdint.in.h stdlib.in.h streq.h iconveh.h \ - string.in.h unicase.h unicase/cased.h unicase/caseprop.h \ - unictype/bitmap.h unicase/caseprop.h unicase/ignorable.h \ - unictype/bitmap.h unicase/locale-languages.h \ - unicase/locale-languages.gperf unicase/special-casing-table.h \ +EXTRA_DIST = alloca.in.h $(top_srcdir)/build-aux/arg-nonnull.h \ + array-mergesort.h $(top_srcdir)/build-aux/c++defs.h \ + c-strcaseeq.h errno.in.h float.in.h fpucw.h frexp.c frexpl.c \ + fseterr.h stdio-impl.h $(top_srcdir)/build-aux/config.rpath \ + iconv.in.h iconv_open-aix.h iconv_open-hpux.h \ + iconv_open-irix.h iconv_open-osf.h iconv_open-solaris.h \ + iconv_open-aix.gperf iconv_open-hpux.gperf \ + iconv_open-irix.gperf iconv_open-osf.gperf \ + iconv_open-solaris.gperf iconv_open.c float+.h isnan.c \ + isnand-nolibm.h isnand.c float+.h isnan.c isnanf-nolibm.h \ + isnanf.c float+.h isnan.c isnanl-nolibm.h isnanl.c \ + config.charset ref-add.sin ref-del.sin localename.h malloc.c \ + malloca.h malloca.valgrind math.in.h mbchar.h mbrtowc.c \ + mbsinit.c memchr.c memchr.valgrind memcmp2.h memxfrm.h \ + printf-frexp.h printf-frexp.c printf-frexpl.h relocatable.c \ + relocatable.h float+.h signbitd.c signbitf.c signbitl.c \ + stdbool.in.h stddef.in.h stdint.in.h stdlib.in.h streq.h \ + iconveh.h string.in.h strncat.c \ + $(top_srcdir)/build-aux/config.rpath unicase.h unicase/cased.h \ + unicase/caseprop.h unictype/bitmap.h unicase/caseprop.h \ + unicase/ignorable.h unictype/bitmap.h \ + unicase/locale-languages.h unicase/locale-languages.gperf \ + unicase/special-casing-table.h \ unicase/special-casing-table.gperf unicase/special-casing.h \ unicase/casefold.h unicase/simple-mapping.h \ unicase/tocasefold.h unicase/simple-mapping.h \ @@ -1378,41 +1493,62 @@ EXTRA_DIST = alloca.in.h array-mergesort.h c-strcaseeq.h dup2.c \ unitypes.h uniwbrk.h uniwbrk/wbrktable.h \ uniwbrk/u-wordbreaks.h uniwbrk/u-wordbreaks.h \ uniwbrk/u-wordbreaks.h uniwbrk/wbrkprop.h localcharset.h \ - uniwidth.h uniwidth/cjk.h wchar.in.h wctype.in.h wcwidth.c \ - stdbool.mini.h stdint.mini.h libunistring.sym declared.sh \ - libunistring.rc -BUILT_SOURCES = $(ALLOCA_H) configmake.h $(ERRNO_H) $(FLOAT_H) \ - $(ICONV_H) iconv_open-aix.h iconv_open-hpux.h \ - iconv_open-irix.h iconv_open-osf.h math.h $(STDBOOL_H) \ - $(STDDEF_H) $(STDINT_H) stdlib.h string.h \ - unicase/locale-languages.h unicase/special-casing-table.h \ - unictype/pr_byname.h unictype/scripts_byname.h \ - uninorm/composition-table.h unistd.h $(WCHAR_H) $(WCTYPE_H) \ + uniwidth.h uniwidth/cjk.h \ + $(top_srcdir)/build-aux/unused-parameter.h \ + $(top_srcdir)/build-aux/warn-on-use.h wchar.in.h wctype.in.h \ + wcwidth.c stdbool.mini.h stdint.mini.h unistring/cdefs.in.h \ + libunistring.sym declared.sh libunistring.rc + +# The BUILT_SOURCES created by this Makefile snippet are not used via #include +# statements but through direct file reference. Therefore this snippet must be +# present in all Makefile.am that need it. This is ensured by the applicability +# 'all' defined above. + +# The BUILT_SOURCES created by this Makefile snippet are not used via #include +# statements but through direct file reference. Therefore this snippet must be +# present in all Makefile.am that need it. This is ensured by the applicability +# 'all' defined above. + +# The BUILT_SOURCES created by this Makefile snippet are not used via #include +# statements but through direct file reference. Therefore this snippet must be +# present in all Makefile.am that need it. This is ensured by the applicability +# 'all' defined above. +BUILT_SOURCES = $(ALLOCA_H) arg-nonnull.h c++defs.h configmake.h \ + $(ERRNO_H) $(FLOAT_H) $(ICONV_H) iconv_open-aix.h \ + iconv_open-hpux.h iconv_open-irix.h iconv_open-osf.h \ + iconv_open-solaris.h math.h $(STDBOOL_H) $(STDDEF_H) \ + $(STDINT_H) stdlib.h string.h unicase/locale-languages.h \ + unicase/special-casing-table.h unictype/pr_byname.h \ + unictype/scripts_byname.h uninorm/composition-table.h unistd.h \ + unused-parameter.h warn-on-use.h wchar.h wctype.h \ unistring/stdbool.h unistring/stdint.h \ - unistring/localcharset.h unistring/iconveh.h + unistring/localcharset.h unistring/iconveh.h unistring/cdefs.h # We distribute it because declared.sh relies on GNU sed. MOSTLYCLEANFILES = core *.stackdump core *.stackdump alloca.h \ - alloca.h-t errno.h errno.h-t float.h float.h-t iconv.h \ - iconv.h-t iconv_open-aix.h-t iconv_open-hpux.h-t \ - iconv_open-irix.h-t iconv_open-osf.h-t math.h math.h-t \ + alloca.h-t arg-nonnull.h arg-nonnull.h-t c++defs.h c++defs.h-t \ + errno.h errno.h-t float.h float.h-t iconv.h iconv.h-t \ + iconv_open-aix.h-t iconv_open-hpux.h-t iconv_open-irix.h-t \ + iconv_open-osf.h-t iconv_open-solaris.h-t math.h math.h-t \ stdbool.h stdbool.h-t stddef.h stddef.h-t stdint.h stdint.h-t \ stdlib.h stdlib.h-t string.h string.h-t \ unicase/locale-languages.h-t unicase/special-casing-table.h-t \ unictype/pr_byname.h-t unictype/scripts_byname.h-t \ - uninorm/composition-table.h-t unistd.h unistd.h-t wchar.h \ - wchar.h-t wctype.h wctype.h-t unistring/stdbool.h-t \ - unistring/stdint.h-t unistring/localcharset.h-t \ - unistring/iconveh.h-t libunistring.sym-t config.h config.h-t \ + uninorm/composition-table.h-t unistd.h unistd.h-t \ + unused-parameter.h unused-parameter.h-t warn-on-use.h \ + warn-on-use.h-t wchar.h wchar.h-t wctype.h wctype.h-t \ + unistring/stdbool.h-t unistring/stdint.h-t \ + unistring/localcharset.h-t unistring/iconveh.h-t \ + unistring/cdefs.h-t libunistring.sym-t config.h config.h-t \ $(am__append_4) CLEANFILES = configmake.h configmake.h-t charset.alias ref-add.sed \ ref-del.sed unistring/stdbool.h unistring/stdint.h \ - unistring/localcharset.h unistring/iconveh.h + unistring/localcharset.h unistring/iconveh.h unistring/cdefs.h DISTCLEANFILES = MAINTAINERCLEANFILES = iconv_open-aix.h iconv_open-hpux.h \ - iconv_open-irix.h iconv_open-osf.h unicase/locale-languages.h \ - unicase/special-casing-table.h unictype/pr_byname.h \ - unictype/scripts_byname.h uninorm/composition-table.h \ - libunistring.sym + iconv_open-irix.h iconv_open-osf.h iconv_open-solaris.h \ + unicase/locale-languages.h unicase/special-casing-table.h \ + unictype/pr_byname.h unictype/scripts_byname.h \ + uninorm/composition-table.h libunistring.sym SUFFIXES = .sed .sin lib_LTLIBRARIES = libunistring.la nobase_include_HEADERS = \ @@ -1442,10 +1578,11 @@ AM_CPPFLAGS = -I. -I$(srcdir) -I$(top_builddir) -I$(top_srcdir) \ # Additional source files. libunistring_la_SOURCES = c-ctype.h c-ctype.c c-strcase.h \ c-strcasecmp.c c-strncasecmp.c fseterr.c localcharset.h \ - localcharset.c localename.c malloca.c mbchar.c mbiter.h \ - mbsnlen.c memcmp2.c memxfrm.c minmax.h printf-frexp.c \ - printf-frexpl.c size_max.h striconveh.h striconveh.c \ - striconveha.h striconveha.c unicase/cased.c \ + localcharset.c localename.c glthread/lock.h glthread/lock.c \ + malloca.c mbchar.c mbiter.h mbsnlen.c memcmp2.c memxfrm.c \ + minmax.h printf-frexp.c printf-frexpl.c size_max.h \ + striconveh.h striconveh.c striconveha.h striconveha.c \ + glthread/threadlib.c unicase/cased.c \ unicase/empty-prefix-context.c unicase/empty-suffix-context.c \ unicase/ignorable.c unicase/locale-language.c \ unicase/special-casing.c unicase/tocasefold.c \ @@ -1671,23 +1808,26 @@ libunistring_la_SOURCES = c-ctype.h c-ctype.c c-strcase.h \ verify.h xsize.h version.c $(am__append_2) libunistring_la_LIBADD = $(gl_LTLIBOBJS) $(WOE32_LIBADD) libunistring_la_DEPENDENCIES = $(gl_LTLIBOBJS) $(WOE32_LIBADD) -EXTRA_libunistring_la_SOURCES = dup2.c frexp.c frexpl.c getpagesize.c \ - iconv_open.c isnan.c isnand.c isnan.c isnanf.c isnan.c \ - isnanl.c malloc.c mbrtowc.c mbsinit.c memchr.c printf-frexp.c \ - relocatable.c signbitd.c signbitf.c signbitl.c printf-args.c \ - printf-parse.c vasnprintf.c vasnprintf.c printf-parse.c \ +EXTRA_libunistring_la_SOURCES = frexp.c frexpl.c iconv_open.c isnan.c \ + isnand.c isnan.c isnanf.c isnan.c isnanl.c malloc.c mbrtowc.c \ + mbsinit.c memchr.c printf-frexp.c relocatable.c signbitd.c \ + signbitf.c signbitl.c strncat.c printf-args.c printf-parse.c \ vasnprintf.c vasnprintf.c printf-parse.c vasnprintf.c \ - vasnprintf.c printf-parse.c vasnprintf.c wcwidth.c + vasnprintf.c printf-parse.c vasnprintf.c vasnprintf.c \ + printf-parse.c vasnprintf.c wcwidth.c # How to build libunistring.la. libunistring_la_LDFLAGS = $(AM_LDFLAGS) $(am__append_1) \ $(am__append_3) -version-info \ $(LTV_CURRENT):$(LTV_REVISION):$(LTV_AGE) -rpath $(libdir) \ @INTL_MACOSX_LIBS@ -no-undefined +ARG_NONNULL_H = arg-nonnull.h +CXXDEFS_H = c++defs.h GPERF = gperf -LINK_WARNING_H = $(top_srcdir)/build-aux/link-warning.h charset_alias = $(DESTDIR)$(libdir)/charset.alias charset_tmp = $(DESTDIR)$(libdir)/charset.tmp +UNUSED_PARAMETER_H = unused-parameter.h +WARN_ON_USE_H = warn-on-use.h # The and replacements that can be installed. @@ -1697,10 +1837,12 @@ charset_tmp = $(DESTDIR)$(libdir)/charset.tmp # unistring/version.h is public. +# unistring/cdefs.h is not public, but is included by other header files. + # unistring/woe32dll.h is not public, but is included by other header files. nobase_nodist_include_HEADERS = unistring/stdbool.h unistring/stdint.h \ unistring/localcharset.h unistring/iconveh.h \ - unistring/version.h unistring/woe32dll.h + unistring/version.h unistring/cdefs.h unistring/woe32dll.h # Directories that contain some CLEANFILES. CLEANDIRS = @@ -1729,7 +1871,7 @@ HEADERS_WITH_EXTERNS = \ # Libtool's library version information for libunistring. # See the libtool documentation, section "Library interface versions". LTV_CURRENT = 1 -LTV_REVISION = 0 +LTV_REVISION = 2 LTV_AGE = 1 all: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) all-am @@ -1799,6 +1941,11 @@ clean-libLTLIBRARIES: echo "rm -f \"$${dir}/so_locations\""; \ rm -f "$${dir}/so_locations"; \ done +glthread/$(am__dirstamp): + @$(MKDIR_P) glthread + @: > glthread/$(am__dirstamp) +glthread/lock.lo: glthread/$(am__dirstamp) +glthread/threadlib.lo: glthread/$(am__dirstamp) unicase/$(am__dirstamp): @$(MKDIR_P) unicase @: > unicase/$(am__dirstamp) @@ -2320,6 +2467,10 @@ mostlyclean-compile: -rm -f *.$(OBJEXT) -rm -f ../woe32dll/unistring-exports.$(OBJEXT) -rm -f ../woe32dll/unistring-exports.lo + -rm -f glthread/lock.$(OBJEXT) + -rm -f glthread/lock.lo + -rm -f glthread/threadlib.$(OBJEXT) + -rm -f glthread/threadlib.lo -rm -f unicase/cased.$(OBJEXT) -rm -f unicase/cased.lo -rm -f unicase/empty-prefix-context.$(OBJEXT) @@ -3300,6 +3451,7 @@ mostlyclean-libtool: clean-libtool: -rm -rf .libs _libs -rm -rf ../woe32dll/.libs ../woe32dll/_libs + -rm -rf glthread/.libs glthread/_libs -rm -rf unicase/.libs unicase/_libs -rm -rf uniconv/.libs uniconv/_libs -rm -rf unictype/.libs unictype/_libs @@ -3472,6 +3624,7 @@ distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) -rm -f ../woe32dll/$(am__dirstamp) + -rm -f glthread/$(am__dirstamp) -rm -f unicase/$(am__dirstamp) -rm -f uniconv/$(am__dirstamp) -rm -f unictype/$(am__dirstamp) @@ -3587,10 +3740,27 @@ uninstall-am: uninstall-libLTLIBRARIES uninstall-local \ # We need the following in order to create when the system # doesn't have one that works with the given compiler. alloca.h: alloca.in.h + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ cat $(srcdir)/alloca.in.h; \ - } > $@-t + } > $@-t && \ mv -f $@-t $@ +# The arg-nonnull.h that gets inserted into generated .h files is the same as +# build-aux/arg-nonnull.h, except that it has the copyright header cut off. +arg-nonnull.h: $(top_srcdir)/build-aux/arg-nonnull.h + $(AM_V_GEN)rm -f $@-t $@ && \ + sed -n -e '/GL_ARG_NONNULL/,$$p' \ + < $(top_srcdir)/build-aux/arg-nonnull.h \ + > $@-t && \ + mv $@-t $@ +# The c++defs.h that gets inserted into generated .h files is the same as +# build-aux/c++defs.h, except that it has the copyright header cut off. +c++defs.h: $(top_srcdir)/build-aux/c++defs.h + $(AM_V_GEN)rm -f $@-t $@ && \ + sed -n -e '/_GL_CXXDEFS/,$$p' \ + < $(top_srcdir)/build-aux/c++defs.h \ + > $@-t && \ + mv $@-t $@ # Retrieve values of the variables through 'configure' followed by # 'make', not directly through 'configure', so that a user who @@ -3610,7 +3780,7 @@ alloca.h: alloca.in.h # The Automake-defined pkg* macros are appended, in the order # listed in the Automake 1.10a+ documentation. configmake.h: Makefile - rm -f $@-t + $(AM_V_GEN)rm -f $@-t && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ echo '#define PREFIX "$(prefix)"'; \ echo '#define EXEC_PREFIX "$(exec_prefix)"'; \ @@ -3639,7 +3809,7 @@ configmake.h: Makefile echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \ echo '#define PKGLIBDIR "$(pkglibdir)"'; \ echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \ - } | sed '/""/d' > $@-t + } | sed '/""/d' > $@-t && \ if test -f $@ && cmp $@-t $@ > /dev/null; then \ rm -f $@-t; \ else \ @@ -3649,7 +3819,7 @@ configmake.h: Makefile # We need the following in order to create when the system # doesn't have one that is POSIX compliant. errno.h: errno.in.h - rm -f $@-t $@ + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ @@ -3661,25 +3831,25 @@ errno.h: errno.in.h -e 's|@''EOVERFLOW_HIDDEN''@|$(EOVERFLOW_HIDDEN)|g' \ -e 's|@''EOVERFLOW_VALUE''@|$(EOVERFLOW_VALUE)|g' \ < $(srcdir)/errno.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ # We need the following in order to create when the system # doesn't have one that works with the given compiler. float.h: float.in.h - rm -f $@-t $@ + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_FLOAT_H''@|$(NEXT_FLOAT_H)|g' \ < $(srcdir)/float.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ # We need the following in order to create when the system # doesn't have one that works with the given compiler. -iconv.h: iconv.in.h - rm -f $@-t $@ +iconv.h: iconv.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ @@ -3688,8 +3858,11 @@ iconv.h: iconv.in.h -e 's|@''REPLACE_ICONV''@|$(REPLACE_ICONV)|g' \ -e 's|@''REPLACE_ICONV_OPEN''@|$(REPLACE_ICONV_OPEN)|g' \ -e 's|@''REPLACE_ICONV_UTF''@|$(REPLACE_ICONV_UTF)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/iconv.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ iconv_open-aix.h: iconv_open-aix.gperf @@ -3704,6 +3877,9 @@ iconv_open-irix.h: iconv_open-irix.gperf iconv_open-osf.h: iconv_open-osf.gperf $(GPERF) -m 10 $(srcdir)/iconv_open-osf.gperf > $(srcdir)/iconv_open-osf.h-t mv $(srcdir)/iconv_open-osf.h-t $(srcdir)/iconv_open-osf.h +iconv_open-solaris.h: iconv_open-solaris.gperf + $(GPERF) -m 10 $(srcdir)/iconv_open-solaris.gperf > $(srcdir)/iconv_open-solaris.h-t + mv $(srcdir)/iconv_open-solaris.h-t $(srcdir)/iconv_open-solaris.h # We need the following in order to install a simple file in $(libdir) # which is shared with other installed packages. We use a list of referencing @@ -3756,24 +3932,29 @@ uninstall-localcharset: all-local fi charset.alias: config.charset - rm -f t-$@ $@ - $(SHELL) $(srcdir)/config.charset '$(host)' > t-$@ + $(AM_V_GEN)rm -f t-$@ $@ && \ + $(SHELL) $(srcdir)/config.charset '$(host)' > t-$@ && \ mv t-$@ $@ .sin.sed: - rm -f t-$@ $@ - sed -e '/^#/d' -e 's/@''PACKAGE''@/$(PACKAGE)/g' $< > t-$@ + $(AM_V_GEN)rm -f t-$@ $@ && \ + sed -e '/^#/d' -e 's/@''PACKAGE''@/$(PACKAGE)/g' $< > t-$@ && \ mv t-$@ $@ # We need the following in order to create when the system # doesn't have one that works with the given compiler. -math.h: math.in.h - rm -f $@-t $@ +math.h: math.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT_AS_FIRST_DIRECTIVE''@|$(INCLUDE_NEXT_AS_FIRST_DIRECTIVE)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_AS_FIRST_DIRECTIVE_MATH_H''@|$(NEXT_AS_FIRST_DIRECTIVE_MATH_H)|g' \ + -e 's|@''GNULIB_ACOSL''@|$(GNULIB_ACOSL)|g' \ + -e 's|@''GNULIB_ASINL''@|$(GNULIB_ASINL)|g' \ + -e 's|@''GNULIB_ATANL''@|$(GNULIB_ATANL)|g' \ -e 's|@''GNULIB_CEILF''@|$(GNULIB_CEILF)|g' \ -e 's|@''GNULIB_CEILL''@|$(GNULIB_CEILL)|g' \ + -e 's|@''GNULIB_COSL''@|$(GNULIB_COSL)|g' \ + -e 's|@''GNULIB_EXPL''@|$(GNULIB_EXPL)|g' \ -e 's|@''GNULIB_FLOORF''@|$(GNULIB_FLOORF)|g' \ -e 's|@''GNULIB_FLOORL''@|$(GNULIB_FLOORL)|g' \ -e 's|@''GNULIB_FREXP''@|$(GNULIB_FREXP)|g' \ @@ -3785,30 +3966,52 @@ math.h: math.in.h -e 's|@''GNULIB_ISNAND''@|$(GNULIB_ISNAND)|g' \ -e 's|@''GNULIB_ISNANL''@|$(GNULIB_ISNANL)|g' \ -e 's|@''GNULIB_LDEXPL''@|$(GNULIB_LDEXPL)|g' \ - -e 's|@''GNULIB_MATHL''@|$(GNULIB_MATHL)|g' \ + -e 's|@''GNULIB_LOGB''@|$(GNULIB_LOGB)|g' \ + -e 's|@''GNULIB_LOGL''@|$(GNULIB_LOGL)|g' \ -e 's|@''GNULIB_ROUND''@|$(GNULIB_ROUND)|g' \ -e 's|@''GNULIB_ROUNDF''@|$(GNULIB_ROUNDF)|g' \ -e 's|@''GNULIB_ROUNDL''@|$(GNULIB_ROUNDL)|g' \ -e 's|@''GNULIB_SIGNBIT''@|$(GNULIB_SIGNBIT)|g' \ + -e 's|@''GNULIB_SINL''@|$(GNULIB_SINL)|g' \ + -e 's|@''GNULIB_SQRTL''@|$(GNULIB_SQRTL)|g' \ + -e 's|@''GNULIB_TANL''@|$(GNULIB_TANL)|g' \ -e 's|@''GNULIB_TRUNC''@|$(GNULIB_TRUNC)|g' \ -e 's|@''GNULIB_TRUNCF''@|$(GNULIB_TRUNCF)|g' \ -e 's|@''GNULIB_TRUNCL''@|$(GNULIB_TRUNCL)|g' \ + -e 's|@''HAVE_ACOSL''@|$(HAVE_ACOSL)|g' \ + -e 's|@''HAVE_ASINL''@|$(HAVE_ASINL)|g' \ + -e 's|@''HAVE_ATANL''@|$(HAVE_ATANL)|g' \ + -e 's|@''HAVE_COSL''@|$(HAVE_COSL)|g' \ + -e 's|@''HAVE_EXPL''@|$(HAVE_EXPL)|g' \ -e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \ -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \ -e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \ + -e 's|@''HAVE_LOGL''@|$(HAVE_LOGL)|g' \ + -e 's|@''HAVE_SINL''@|$(HAVE_SINL)|g' \ + -e 's|@''HAVE_SQRTL''@|$(HAVE_SQRTL)|g' \ + -e 's|@''HAVE_TANL''@|$(HAVE_TANL)|g' \ -e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \ -e 's|@''HAVE_DECL_ASINL''@|$(HAVE_DECL_ASINL)|g' \ -e 's|@''HAVE_DECL_ATANL''@|$(HAVE_DECL_ATANL)|g' \ + -e 's|@''HAVE_DECL_CEILF''@|$(HAVE_DECL_CEILF)|g' \ + -e 's|@''HAVE_DECL_CEILL''@|$(HAVE_DECL_CEILL)|g' \ -e 's|@''HAVE_DECL_COSL''@|$(HAVE_DECL_COSL)|g' \ -e 's|@''HAVE_DECL_EXPL''@|$(HAVE_DECL_EXPL)|g' \ + -e 's|@''HAVE_DECL_FLOORF''@|$(HAVE_DECL_FLOORF)|g' \ + -e 's|@''HAVE_DECL_FLOORL''@|$(HAVE_DECL_FLOORL)|g' \ -e 's|@''HAVE_DECL_FREXPL''@|$(HAVE_DECL_FREXPL)|g' \ -e 's|@''HAVE_DECL_LDEXPL''@|$(HAVE_DECL_LDEXPL)|g' \ + -e 's|@''HAVE_DECL_LOGB''@|$(HAVE_DECL_LOGB)|g' \ -e 's|@''HAVE_DECL_LOGL''@|$(HAVE_DECL_LOGL)|g' \ + -e 's|@''HAVE_DECL_ROUND''@|$(HAVE_DECL_ROUND)|g' \ + -e 's|@''HAVE_DECL_ROUNDF''@|$(HAVE_DECL_ROUNDF)|g' \ + -e 's|@''HAVE_DECL_ROUNDL''@|$(HAVE_DECL_ROUNDL)|g' \ -e 's|@''HAVE_DECL_SINL''@|$(HAVE_DECL_SINL)|g' \ -e 's|@''HAVE_DECL_SQRTL''@|$(HAVE_DECL_SQRTL)|g' \ -e 's|@''HAVE_DECL_TANL''@|$(HAVE_DECL_TANL)|g' \ -e 's|@''HAVE_DECL_TRUNC''@|$(HAVE_DECL_TRUNC)|g' \ -e 's|@''HAVE_DECL_TRUNCF''@|$(HAVE_DECL_TRUNCF)|g' \ + -e 's|@''HAVE_DECL_TRUNCL''@|$(HAVE_DECL_TRUNCL)|g' \ -e 's|@''REPLACE_CEILF''@|$(REPLACE_CEILF)|g' \ -e 's|@''REPLACE_CEILL''@|$(REPLACE_CEILL)|g' \ -e 's|@''REPLACE_FLOORF''@|$(REPLACE_FLOORF)|g' \ @@ -3827,24 +4030,26 @@ math.h: math.in.h -e 's|@''REPLACE_SIGNBIT''@|$(REPLACE_SIGNBIT)|g' \ -e 's|@''REPLACE_SIGNBIT_USING_GCC''@|$(REPLACE_SIGNBIT_USING_GCC)|g' \ -e 's|@''REPLACE_TRUNCL''@|$(REPLACE_TRUNCL)|g' \ - -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/math.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ # We need the following in order to create when the system # doesn't have one that works. stdbool.h: stdbool.in.h - rm -f $@-t $@ + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's/@''HAVE__BOOL''@/$(HAVE__BOOL)/g' < $(srcdir)/stdbool.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ # We need the following in order to create when the system # doesn't have one that works with the given compiler. stddef.h: stddef.in.h - rm -f $@-t $@ + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ @@ -3852,13 +4057,13 @@ stddef.h: stddef.in.h -e 's|@''HAVE_WCHAR_T''@|$(HAVE_WCHAR_T)|g' \ -e 's|@''REPLACE_NULL''@|$(REPLACE_NULL)|g' \ < $(srcdir)/stddef.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ # We need the following in order to create when the system # doesn't have one that works with the given compiler. stdint.h: stdint.in.h - rm -f $@-t $@ + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's/@''HAVE_STDINT_H''@/$(HAVE_STDINT_H)/g' \ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -3885,41 +4090,58 @@ stdint.h: stdint.in.h -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \ -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \ < $(srcdir)/stdint.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ # We need the following in order to create when the system # doesn't have one that works with the given compiler. -stdlib.h: stdlib.in.h - rm -f $@-t $@ +stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \ - -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \ - -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \ - -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \ - -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \ -e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \ + -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \ + -e 's|@''GNULIB_CANONICALIZE_FILE_NAME''@|$(GNULIB_CANONICALIZE_FILE_NAME)|g' \ -e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \ -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \ + -e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \ + -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \ -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \ + -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \ + -e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \ -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \ + -e 's|@''GNULIB_MKSTEMPS''@|$(GNULIB_MKSTEMPS)|g' \ + -e 's|@''GNULIB_PTSNAME''@|$(GNULIB_PTSNAME)|g' \ -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \ -e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|g' \ + -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \ + -e 's|@''GNULIB_REALPATH''@|$(GNULIB_REALPATH)|g' \ -e 's|@''GNULIB_RPMATCH''@|$(GNULIB_RPMATCH)|g' \ -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \ -e 's|@''GNULIB_STRTOD''@|$(GNULIB_STRTOD)|g' \ -e 's|@''GNULIB_STRTOLL''@|$(GNULIB_STRTOLL)|g' \ -e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \ + -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \ -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \ -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \ + -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \ + -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ + -e 's|@''HAVE_GRANTPT''@|$(HAVE_GRANTPT)|g' \ -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \ -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \ - -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \ + -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \ + -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \ + -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \ + -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \ + -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \ + -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \ -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \ + -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \ + -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \ -e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \ -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \ -e 's|@''HAVE_STRTOD''@|$(HAVE_STRTOD)|g' \ @@ -3927,21 +4149,26 @@ stdlib.h: stdlib.in.h -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \ -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \ -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \ + -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \ -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \ - -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ + -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ + -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \ + -e 's|@''REPLACE_SETENV''@|$(REPLACE_SETENV)|g' \ -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \ - -e 's|@''VOID_UNSETENV''@|$(VOID_UNSETENV)|g' \ - -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e 's|@''REPLACE_UNSETENV''@|$(REPLACE_UNSETENV)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/stdlib.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ # We need the following in order to create when the system # doesn't have one that works with the given compiler. -string.h: string.in.h - rm -f $@-t $@ +string.h: string.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ @@ -3969,6 +4196,7 @@ string.h: string.in.h -e 's|@''GNULIB_STPNCPY''@|$(GNULIB_STPNCPY)|g' \ -e 's|@''GNULIB_STRCHRNUL''@|$(GNULIB_STRCHRNUL)|g' \ -e 's|@''GNULIB_STRDUP''@|$(GNULIB_STRDUP)|g' \ + -e 's|@''GNULIB_STRNCAT''@|$(GNULIB_STRNCAT)|g' \ -e 's|@''GNULIB_STRNDUP''@|$(GNULIB_STRNDUP)|g' \ -e 's|@''GNULIB_STRNLEN''@|$(GNULIB_STRNLEN)|g' \ -e 's|@''GNULIB_STRPBRK''@|$(GNULIB_STRPBRK)|g' \ @@ -3979,6 +4207,9 @@ string.h: string.in.h -e 's|@''GNULIB_STRERROR''@|$(GNULIB_STRERROR)|g' \ -e 's|@''GNULIB_STRSIGNAL''@|$(GNULIB_STRSIGNAL)|g' \ -e 's|@''GNULIB_STRVERSCMP''@|$(GNULIB_STRVERSCMP)|g' \ + < $(srcdir)/string.in.h | \ + sed -e 's|@''HAVE_MBSLEN''@|$(HAVE_MBSLEN)|g' \ + -e 's|@''HAVE_MEMCHR''@|$(HAVE_MEMCHR)|g' \ -e 's|@''HAVE_DECL_MEMMEM''@|$(HAVE_DECL_MEMMEM)|g' \ -e 's|@''HAVE_MEMPCPY''@|$(HAVE_MEMPCPY)|g' \ -e 's|@''HAVE_DECL_MEMRCHR''@|$(HAVE_DECL_MEMRCHR)|g' \ @@ -3987,26 +4218,32 @@ string.h: string.in.h -e 's|@''HAVE_STPNCPY''@|$(HAVE_STPNCPY)|g' \ -e 's|@''HAVE_STRCHRNUL''@|$(HAVE_STRCHRNUL)|g' \ -e 's|@''HAVE_DECL_STRDUP''@|$(HAVE_DECL_STRDUP)|g' \ - -e 's|@''HAVE_STRNDUP''@|$(HAVE_STRNDUP)|g' \ -e 's|@''HAVE_DECL_STRNDUP''@|$(HAVE_DECL_STRNDUP)|g' \ -e 's|@''HAVE_DECL_STRNLEN''@|$(HAVE_DECL_STRNLEN)|g' \ -e 's|@''HAVE_STRPBRK''@|$(HAVE_STRPBRK)|g' \ -e 's|@''HAVE_STRSEP''@|$(HAVE_STRSEP)|g' \ -e 's|@''HAVE_STRCASESTR''@|$(HAVE_STRCASESTR)|g' \ -e 's|@''HAVE_DECL_STRTOK_R''@|$(HAVE_DECL_STRTOK_R)|g' \ - -e 's|@''HAVE_DECL_STRERROR''@|$(HAVE_DECL_STRERROR)|g' \ -e 's|@''HAVE_DECL_STRSIGNAL''@|$(HAVE_DECL_STRSIGNAL)|g' \ -e 's|@''HAVE_STRVERSCMP''@|$(HAVE_STRVERSCMP)|g' \ + -e 's|@''REPLACE_STPNCPY''@|$(REPLACE_STPNCPY)|g' \ -e 's|@''REPLACE_MEMCHR''@|$(REPLACE_MEMCHR)|g' \ -e 's|@''REPLACE_MEMMEM''@|$(REPLACE_MEMMEM)|g' \ -e 's|@''REPLACE_STRCASESTR''@|$(REPLACE_STRCASESTR)|g' \ -e 's|@''REPLACE_STRDUP''@|$(REPLACE_STRDUP)|g' \ -e 's|@''REPLACE_STRSTR''@|$(REPLACE_STRSTR)|g' \ -e 's|@''REPLACE_STRERROR''@|$(REPLACE_STRERROR)|g' \ + -e 's|@''REPLACE_STRNCAT''@|$(REPLACE_STRNCAT)|g' \ + -e 's|@''REPLACE_STRNDUP''@|$(REPLACE_STRNDUP)|g' \ + -e 's|@''REPLACE_STRNLEN''@|$(REPLACE_STRNLEN)|g' \ -e 's|@''REPLACE_STRSIGNAL''@|$(REPLACE_STRSIGNAL)|g' \ - -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e 's|@''REPLACE_STRTOK_R''@|$(REPLACE_STRTOK_R)|g' \ + -e 's|@''UNDEFINE_STRTOK_R''@|$(UNDEFINE_STRTOK_R)|g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ < $(srcdir)/string.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ unicase/locale-languages.h: $(srcdir)/unicase/locale-languages.gperf @@ -4031,8 +4268,8 @@ uninorm/composition-table.h: $(srcdir)/uninorm/composition-table.gperf # We need the following in order to create an empty placeholder for # when the system doesn't have one. -unistd.h: unistd.in.h - rm -f $@-t $@ +unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ @@ -4041,62 +4278,128 @@ unistd.h: unistd.in.h -e 's|@''GNULIB_CHOWN''@|$(GNULIB_CHOWN)|g' \ -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \ -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \ + -e 's|@''GNULIB_DUP3''@|$(GNULIB_DUP3)|g' \ -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \ -e 's|@''GNULIB_EUIDACCESS''@|$(GNULIB_EUIDACCESS)|g' \ + -e 's|@''GNULIB_FACCESSAT''@|$(GNULIB_FACCESSAT)|g' \ -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \ + -e 's|@''GNULIB_FCHOWNAT''@|$(GNULIB_FCHOWNAT)|g' \ -e 's|@''GNULIB_FSYNC''@|$(GNULIB_FSYNC)|g' \ -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \ -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \ -e 's|@''GNULIB_GETDOMAINNAME''@|$(GNULIB_GETDOMAINNAME)|g' \ -e 's|@''GNULIB_GETDTABLESIZE''@|$(GNULIB_GETDTABLESIZE)|g' \ + -e 's|@''GNULIB_GETGROUPS''@|$(GNULIB_GETGROUPS)|g' \ -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \ + -e 's|@''GNULIB_GETLOGIN''@|$(GNULIB_GETLOGIN)|g' \ -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \ -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \ -e 's|@''GNULIB_GETUSERSHELL''@|$(GNULIB_GETUSERSHELL)|g' \ -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \ -e 's|@''GNULIB_LINK''@|$(GNULIB_LINK)|g' \ + -e 's|@''GNULIB_LINKAT''@|$(GNULIB_LINKAT)|g' \ -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \ + -e 's|@''GNULIB_PIPE2''@|$(GNULIB_PIPE2)|g' \ + -e 's|@''GNULIB_PREAD''@|$(GNULIB_PREAD)|g' \ -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \ + -e 's|@''GNULIB_READLINKAT''@|$(GNULIB_READLINKAT)|g' \ + -e 's|@''GNULIB_RMDIR''@|$(GNULIB_RMDIR)|g' \ -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \ + -e 's|@''GNULIB_SYMLINK''@|$(GNULIB_SYMLINK)|g' \ + -e 's|@''GNULIB_SYMLINKAT''@|$(GNULIB_SYMLINKAT)|g' \ + -e 's|@''GNULIB_TTYNAME_R''@|$(GNULIB_TTYNAME_R)|g' \ -e 's|@''GNULIB_UNISTD_H_GETOPT''@|$(GNULIB_UNISTD_H_GETOPT)|g' \ -e 's|@''GNULIB_UNISTD_H_SIGPIPE''@|$(GNULIB_UNISTD_H_SIGPIPE)|g' \ + -e 's|@''GNULIB_UNLINK''@|$(GNULIB_UNLINK)|g' \ + -e 's|@''GNULIB_UNLINKAT''@|$(GNULIB_UNLINKAT)|g' \ + -e 's|@''GNULIB_USLEEP''@|$(GNULIB_USLEEP)|g' \ -e 's|@''GNULIB_WRITE''@|$(GNULIB_WRITE)|g' \ + < $(srcdir)/unistd.in.h | \ + sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \ -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \ + -e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \ -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \ + -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \ + -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \ + -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \ -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \ -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \ -e 's|@''HAVE_GETDOMAINNAME''@|$(HAVE_GETDOMAINNAME)|g' \ -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \ + -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \ -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \ + -e 's|@''HAVE_GETLOGIN''@|$(HAVE_GETLOGIN)|g' \ -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \ - -e 's|@''HAVE_GETUSERSHELL''@|$(HAVE_GETUSERSHELL)|g' \ + -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \ -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \ + -e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \ + -e 's|@''HAVE_PIPE2''@|$(HAVE_PIPE2)|g' \ + -e 's|@''HAVE_PREAD''@|$(HAVE_PREAD)|g' \ -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \ + -e 's|@''HAVE_READLINKAT''@|$(HAVE_READLINKAT)|g' \ -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \ + -e 's|@''HAVE_SYMLINK''@|$(HAVE_SYMLINK)|g' \ + -e 's|@''HAVE_SYMLINKAT''@|$(HAVE_SYMLINKAT)|g' \ + -e 's|@''HAVE_TTYNAME_R''@|$(HAVE_TTYNAME_R)|g' \ + -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \ + -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \ -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \ -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \ + -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \ + -e 's|@''HAVE_DECL_GETUSERSHELL''@|$(HAVE_DECL_GETUSERSHELL)|g' \ -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \ -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \ -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \ -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \ + -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \ -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \ - -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \ + -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \ -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ + -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \ -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \ + -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \ + -e 's|@''REPLACE_LINKAT''@|$(REPLACE_LINKAT)|g' \ -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \ + -e 's|@''REPLACE_PREAD''@|$(REPLACE_PREAD)|g' \ + -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \ + -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \ + -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \ + -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \ + -e 's|@''REPLACE_TTYNAME_R''@|$(REPLACE_TTYNAME_R)|g' \ + -e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \ + -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \ + -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \ -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \ -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \ -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \ - -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ - < $(srcdir)/unistd.in.h; \ - } > $@-t + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \ + } > $@-t && \ + mv $@-t $@ +# The unused-parameter.h that gets inserted into generated .h files is the same +# as build-aux/unused-parameter.h, except that it has the copyright header cut +# off. +unused-parameter.h: $(top_srcdir)/build-aux/unused-parameter.h + $(AM_V_GEN)rm -f $@-t $@ && \ + sed -n -e '/GL_UNUSED_PARAMETER/,$$p' \ + < $(top_srcdir)/build-aux/unused-parameter.h \ + > $@-t && \ + mv $@-t $@ +# The warn-on-use.h that gets inserted into generated .h files is the same as +# build-aux/warn-on-use.h, except that it has the copyright header cut off. +warn-on-use.h: $(top_srcdir)/build-aux/warn-on-use.h + $(AM_V_GEN)rm -f $@-t $@ && \ + sed -n -e '/^.ifndef/,$$p' \ + < $(top_srcdir)/build-aux/warn-on-use.h \ + > $@-t && \ mv $@-t $@ # We need the following in order to create when the system # version does not work standalone. -wchar.h: wchar.in.h - rm -f $@-t $@ +wchar.h: wchar.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ @@ -4137,25 +4440,30 @@ wchar.h: wchar.in.h -e 's|@''REPLACE_WCSRTOMBS''@|$(REPLACE_WCSRTOMBS)|g' \ -e 's|@''REPLACE_WCSNRTOMBS''@|$(REPLACE_WCSNRTOMBS)|g' \ -e 's|@''REPLACE_WCWIDTH''@|$(REPLACE_WCWIDTH)|g' \ - -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/wchar.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ # We need the following in order to create when the system # doesn't have one that works with the given compiler. -wctype.h: wctype.in.h - rm -f $@-t $@ +wctype.h: wctype.in.h $(CXXDEFS_H) $(WARN_ON_USE_H) + $(AM_V_GEN)rm -f $@-t $@ && \ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ sed -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_WCTYPE_H''@|$(NEXT_WCTYPE_H)|g' \ + -e 's/@''HAVE_ISWBLANK''@/$(HAVE_ISWBLANK)/g' \ -e 's/@''HAVE_ISWCNTRL''@/$(HAVE_ISWCNTRL)/g' \ -e 's/@''HAVE_WINT_T''@/$(HAVE_WINT_T)/g' \ -e 's/@''REPLACE_ISWCNTRL''@/$(REPLACE_ISWCNTRL)/g' \ + -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ + -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ < $(srcdir)/wctype.in.h; \ - } > $@-t + } > $@-t && \ mv $@-t $@ mostlyclean-local: mostlyclean-generic @@ -4237,6 +4545,13 @@ unistring/iconveh.h : iconveh.h rm -f $@-t $@ cp $(srcdir)/iconveh.h $@-t mv $@-t $@ +unistring/cdefs.h : unistring/cdefs.in.h + @MKDIR_P@ unistring + rm -f $@-t $@ + sed -e '/definition of _GL_UNUSED_PARAMETER/r $(UNUSED_PARAMETER_H)' \ + < $(srcdir)/unistring/cdefs.in.h \ + > $@-t + mv $@-t $@ clean-local: clean-generic @for dir in '' $(CLEANDIRS); do \ if test -n "$$dir" && test -d $$dir; then \ diff --git a/lib/alloca.in.h b/lib/alloca.in.h index 3d4f88b3..ee7aa9a8 100644 --- a/lib/alloca.in.h +++ b/lib/alloca.in.h @@ -1,7 +1,7 @@ /* Memory allocation on the stack. - Copyright (C) 1995, 1999, 2001-2004, 2006-2008 Free Software - Foundation, Inc. + Copyright (C) 1995, 1999, 2001-2004, 2006-2010 Free Software Foundation, + Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/array-mergesort.h b/lib/array-mergesort.h index 3988d289..61bf7280 100644 --- a/lib/array-mergesort.h +++ b/lib/array-mergesort.h @@ -1,5 +1,5 @@ /* Stable-sorting of an array using mergesort. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -47,40 +47,40 @@ merge (const ELEMENT *src1, size_t n1, for (;;) /* while (n1 > 0 && n2 > 0) */ { if (COMPARE (src1, src2) <= 0) - { - *dst++ = *src1++; - n1--; - if (n1 == 0) - break; - } + { + *dst++ = *src1++; + n1--; + if (n1 == 0) + break; + } else - { - *dst++ = *src2++; - n2--; - if (n2 == 0) - break; - } + { + *dst++ = *src2++; + n2--; + if (n2 == 0) + break; + } } /* Here n1 == 0 || n2 == 0 but also n1 > 0 || n2 > 0. */ if (n1 > 0) { if (dst != src1) - do - { - *dst++ = *src1++; - n1--; - } - while (n1 > 0); + do + { + *dst++ = *src1++; + n1--; + } + while (n1 > 0); } else /* n2 > 0 */ { if (dst != src2) - do - { - *dst++ = *src2++; - n2--; - } - while (n2 > 0); + do + { + *dst++ = *src2++; + n2--; + } + while (n2 > 0); } } @@ -101,79 +101,79 @@ merge_sort_fromto (const ELEMENT *src, ELEMENT *dst, size_t n, ELEMENT *tmp) case 2: /* Trivial case. */ if (COMPARE (&src[0], &src[1]) <= 0) - { - /* src[0] <= src[1] */ - dst[0] = src[0]; - dst[1] = src[1]; - } + { + /* src[0] <= src[1] */ + dst[0] = src[0]; + dst[1] = src[1]; + } else - { - dst[0] = src[1]; - dst[1] = src[0]; - } + { + dst[0] = src[1]; + dst[1] = src[0]; + } break; case 3: /* Simple case. */ if (COMPARE (&src[0], &src[1]) <= 0) - { - if (COMPARE (&src[1], &src[2]) <= 0) - { - /* src[0] <= src[1] <= src[2] */ - dst[0] = src[0]; - dst[1] = src[1]; - dst[2] = src[2]; - } - else if (COMPARE (&src[0], &src[2]) <= 0) - { - /* src[0] <= src[2] < src[1] */ - dst[0] = src[0]; - dst[1] = src[2]; - dst[2] = src[1]; - } - else - { - /* src[2] < src[0] <= src[1] */ - dst[0] = src[2]; - dst[1] = src[0]; - dst[2] = src[1]; - } - } + { + if (COMPARE (&src[1], &src[2]) <= 0) + { + /* src[0] <= src[1] <= src[2] */ + dst[0] = src[0]; + dst[1] = src[1]; + dst[2] = src[2]; + } + else if (COMPARE (&src[0], &src[2]) <= 0) + { + /* src[0] <= src[2] < src[1] */ + dst[0] = src[0]; + dst[1] = src[2]; + dst[2] = src[1]; + } + else + { + /* src[2] < src[0] <= src[1] */ + dst[0] = src[2]; + dst[1] = src[0]; + dst[2] = src[1]; + } + } else - { - if (COMPARE (&src[0], &src[2]) <= 0) - { - /* src[1] < src[0] <= src[2] */ - dst[0] = src[1]; - dst[1] = src[0]; - dst[2] = src[2]; - } - else if (COMPARE (&src[1], &src[2]) <= 0) - { - /* src[1] <= src[2] < src[0] */ - dst[0] = src[1]; - dst[1] = src[2]; - dst[2] = src[0]; - } - else - { - /* src[2] < src[1] < src[0] */ - dst[0] = src[2]; - dst[1] = src[1]; - dst[2] = src[0]; - } - } + { + if (COMPARE (&src[0], &src[2]) <= 0) + { + /* src[1] < src[0] <= src[2] */ + dst[0] = src[1]; + dst[1] = src[0]; + dst[2] = src[2]; + } + else if (COMPARE (&src[1], &src[2]) <= 0) + { + /* src[1] <= src[2] < src[0] */ + dst[0] = src[1]; + dst[1] = src[2]; + dst[2] = src[0]; + } + else + { + /* src[2] < src[1] < src[0] */ + dst[0] = src[2]; + dst[1] = src[1]; + dst[2] = src[0]; + } + } break; default: { - size_t n1 = n / 2; - size_t n2 = (n + 1) / 2; - /* Note: n1 + n2 = n, n1 <= n2. */ - /* Sort src[n1..n-1] into dst[n1..n-1], scratching tmp[0..n2/2-1]. */ - merge_sort_fromto (src + n1, dst + n1, n2, tmp); - /* Sort src[0..n1-1] into tmp[0..n1-1], scratching dst[0..n1-1]. */ - merge_sort_fromto (src, tmp, n1, dst); - /* Merge the two half results. */ - merge (tmp, n1, dst + n1, n2, dst); + size_t n1 = n / 2; + size_t n2 = (n + 1) / 2; + /* Note: n1 + n2 = n, n1 <= n2. */ + /* Sort src[n1..n-1] into dst[n1..n-1], scratching tmp[0..n2/2-1]. */ + merge_sort_fromto (src + n1, dst + n1, n2, tmp); + /* Sort src[0..n1-1] into tmp[0..n1-1], scratching dst[0..n1-1]. */ + merge_sort_fromto (src, tmp, n1, dst); + /* Merge the two half results. */ + merge (tmp, n1, dst + n1, n2, dst); } break; } @@ -193,77 +193,77 @@ merge_sort_inplace (ELEMENT *src, size_t n, ELEMENT *tmp) case 2: /* Trivial case. */ if (COMPARE (&src[0], &src[1]) <= 0) - { - /* src[0] <= src[1] */ - } + { + /* src[0] <= src[1] */ + } else - { - ELEMENT t = src[0]; - src[0] = src[1]; - src[1] = t; - } + { + ELEMENT t = src[0]; + src[0] = src[1]; + src[1] = t; + } break; case 3: /* Simple case. */ if (COMPARE (&src[0], &src[1]) <= 0) - { - if (COMPARE (&src[1], &src[2]) <= 0) - { - /* src[0] <= src[1] <= src[2] */ - } - else if (COMPARE (&src[0], &src[2]) <= 0) - { - /* src[0] <= src[2] < src[1] */ - ELEMENT t = src[1]; - src[1] = src[2]; - src[2] = t; - } - else - { - /* src[2] < src[0] <= src[1] */ - ELEMENT t = src[0]; - src[0] = src[2]; - src[2] = src[1]; - src[1] = t; - } - } + { + if (COMPARE (&src[1], &src[2]) <= 0) + { + /* src[0] <= src[1] <= src[2] */ + } + else if (COMPARE (&src[0], &src[2]) <= 0) + { + /* src[0] <= src[2] < src[1] */ + ELEMENT t = src[1]; + src[1] = src[2]; + src[2] = t; + } + else + { + /* src[2] < src[0] <= src[1] */ + ELEMENT t = src[0]; + src[0] = src[2]; + src[2] = src[1]; + src[1] = t; + } + } else - { - if (COMPARE (&src[0], &src[2]) <= 0) - { - /* src[1] < src[0] <= src[2] */ - ELEMENT t = src[0]; - src[0] = src[1]; - src[1] = t; - } - else if (COMPARE (&src[1], &src[2]) <= 0) - { - /* src[1] <= src[2] < src[0] */ - ELEMENT t = src[0]; - src[0] = src[1]; - src[1] = src[2]; - src[2] = t; - } - else - { - /* src[2] < src[1] < src[0] */ - ELEMENT t = src[0]; - src[0] = src[2]; - src[2] = t; - } - } + { + if (COMPARE (&src[0], &src[2]) <= 0) + { + /* src[1] < src[0] <= src[2] */ + ELEMENT t = src[0]; + src[0] = src[1]; + src[1] = t; + } + else if (COMPARE (&src[1], &src[2]) <= 0) + { + /* src[1] <= src[2] < src[0] */ + ELEMENT t = src[0]; + src[0] = src[1]; + src[1] = src[2]; + src[2] = t; + } + else + { + /* src[2] < src[1] < src[0] */ + ELEMENT t = src[0]; + src[0] = src[2]; + src[2] = t; + } + } break; default: { - size_t n1 = n / 2; - size_t n2 = (n + 1) / 2; - /* Note: n1 + n2 = n, n1 <= n2. */ - /* Sort src[n1..n-1], scratching tmp[0..n2-1]. */ - merge_sort_inplace (src + n1, n2, tmp); - /* Sort src[0..n1-1] into tmp[0..n1-1], scratching tmp[n1..2*n1-1]. */ - merge_sort_fromto (src, tmp, n1, tmp + n1); - /* Merge the two half results. */ - merge (tmp, n1, src + n1, n2, src); + size_t n1 = n / 2; + size_t n2 = (n + 1) / 2; + /* Note: n1 + n2 = n, n1 <= n2. */ + /* Sort src[n1..n-1], scratching tmp[0..n2-1]. */ + merge_sort_inplace (src + n1, n2, tmp); + /* Sort src[0..n1-1] into tmp[0..n1-1], scratching tmp[n1..2*n1-1]. */ + merge_sort_fromto (src, tmp, n1, tmp + n1); + /* Merge the two half results. */ + merge (tmp, n1, src + n1, n2, src); } break; } diff --git a/lib/c-ctype.c b/lib/c-ctype.c index e36a5134..403adc2a 100644 --- a/lib/c-ctype.c +++ b/lib/c-ctype.c @@ -1,6 +1,6 @@ /* Character handling in C locale. - Copyright 2000-2003, 2006 Free Software Foundation, Inc. + Copyright 2000-2003, 2006, 2009-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/c-ctype.h b/lib/c-ctype.h index d7b067e8..00c0a26c 100644 --- a/lib/c-ctype.h +++ b/lib/c-ctype.h @@ -5,7 +5,7 @@ functions' behaviour depends on the current locale set via setlocale. - Copyright (C) 2000-2003, 2006, 2008 Free Software Foundation, Inc. + Copyright (C) 2000-2003, 2006, 2008-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/c-strcase.h b/lib/c-strcase.h index 714a3c62..99e7fafa 100644 --- a/lib/c-strcase.h +++ b/lib/c-strcase.h @@ -1,5 +1,6 @@ /* Case-insensitive string comparison functions in C locale. - Copyright (C) 1995-1996, 2001, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 1995-1996, 2001, 2003, 2005, 2009-2010 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/c-strcasecmp.c b/lib/c-strcasecmp.c index a5238988..bc3e76d0 100644 --- a/lib/c-strcasecmp.c +++ b/lib/c-strcasecmp.c @@ -1,5 +1,5 @@ /* c-strcasecmp.c -- case insensitive string comparator in C locale - Copyright (C) 1998-1999, 2005-2006 Free Software Foundation, Inc. + Copyright (C) 1998-1999, 2005-2006, 2009-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -40,7 +40,7 @@ c_strcasecmp (const char *s1, const char *s2) c2 = c_tolower (*p2); if (c1 == '\0') - break; + break; ++p1; ++p2; diff --git a/lib/c-strcaseeq.h b/lib/c-strcaseeq.h index cd29b66c..0af82f30 100644 --- a/lib/c-strcaseeq.h +++ b/lib/c-strcaseeq.h @@ -1,5 +1,5 @@ /* Optimized case-insensitive string comparison in C locale. - Copyright (C) 2001-2002, 2007 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/c-strncasecmp.c b/lib/c-strncasecmp.c index c1496ca4..01dbf391 100644 --- a/lib/c-strncasecmp.c +++ b/lib/c-strncasecmp.c @@ -1,5 +1,5 @@ /* c-strncasecmp.c -- case insensitive string comparator in C locale - Copyright (C) 1998-1999, 2005-2006 Free Software Foundation, Inc. + Copyright (C) 1998-1999, 2005-2006, 2009-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -40,7 +40,7 @@ c_strncasecmp (const char *s1, const char *s2, size_t n) c2 = c_tolower (*p2); if (--n == 0 || c1 == '\0') - break; + break; ++p1; ++p2; diff --git a/lib/config.charset b/lib/config.charset old mode 100755 new mode 100644 index c1a7f5db..ae2efc4d --- a/lib/config.charset +++ b/lib/config.charset @@ -1,7 +1,7 @@ #! /bin/sh # Output a system dependent table of character encoding aliases. # -# Copyright (C) 2000-2004, 2006-2009 Free Software Foundation, Inc. +# Copyright (C) 2000-2004, 2006-2010 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by @@ -123,561 +123,561 @@ echo "# It was automatically generated from config.charset." # List of references, updated during installation: echo "# Packages using this file: " case "$os" in - linux-gnulibc1*) - # Linux libc5 doesn't have nl_langinfo(CODESET); therefore - # localcharset.c falls back to using the full locale name - # from the environment variables. - echo "C ASCII" - echo "POSIX ASCII" - for l in af af_ZA ca ca_ES da da_DK de de_AT de_BE de_CH de_DE de_LU \ - en en_AU en_BW en_CA en_DK en_GB en_IE en_NZ en_US en_ZA \ - en_ZW es es_AR es_BO es_CL es_CO es_DO es_EC es_ES es_GT \ - es_HN es_MX es_PA es_PE es_PY es_SV es_US es_UY es_VE et \ - et_EE eu eu_ES fi fi_FI fo fo_FO fr fr_BE fr_CA fr_CH fr_FR \ - fr_LU ga ga_IE gl gl_ES id id_ID in in_ID is is_IS it it_CH \ - it_IT kl kl_GL nl nl_BE nl_NL no no_NO pt pt_BR pt_PT sv \ - sv_FI sv_SE; do - echo "$l ISO-8859-1" - echo "$l.iso-8859-1 ISO-8859-1" - echo "$l.iso-8859-15 ISO-8859-15" - echo "$l.iso-8859-15@euro ISO-8859-15" - echo "$l@euro ISO-8859-15" - echo "$l.cp-437 CP437" - echo "$l.cp-850 CP850" - echo "$l.cp-1252 CP1252" - echo "$l.cp-1252@euro CP1252" - #echo "$l.atari-st ATARI-ST" # not a commonly used encoding - echo "$l.utf-8 UTF-8" - echo "$l.utf-8@euro UTF-8" - done - for l in cs cs_CZ hr hr_HR hu hu_HU pl pl_PL ro ro_RO sk sk_SK sl \ - sl_SI sr sr_CS sr_YU; do - echo "$l ISO-8859-2" - echo "$l.iso-8859-2 ISO-8859-2" - echo "$l.cp-852 CP852" - echo "$l.cp-1250 CP1250" - echo "$l.utf-8 UTF-8" - done - for l in mk mk_MK ru ru_RU; do - echo "$l ISO-8859-5" - echo "$l.iso-8859-5 ISO-8859-5" - echo "$l.koi8-r KOI8-R" - echo "$l.cp-866 CP866" - echo "$l.cp-1251 CP1251" - echo "$l.utf-8 UTF-8" - done - for l in ar ar_SA; do - echo "$l ISO-8859-6" - echo "$l.iso-8859-6 ISO-8859-6" - echo "$l.cp-864 CP864" - #echo "$l.cp-868 CP868" # not a commonly used encoding - echo "$l.cp-1256 CP1256" - echo "$l.utf-8 UTF-8" - done - for l in el el_GR gr gr_GR; do - echo "$l ISO-8859-7" - echo "$l.iso-8859-7 ISO-8859-7" - echo "$l.cp-869 CP869" - echo "$l.cp-1253 CP1253" - echo "$l.cp-1253@euro CP1253" - echo "$l.utf-8 UTF-8" - echo "$l.utf-8@euro UTF-8" - done - for l in he he_IL iw iw_IL; do - echo "$l ISO-8859-8" - echo "$l.iso-8859-8 ISO-8859-8" - echo "$l.cp-862 CP862" - echo "$l.cp-1255 CP1255" - echo "$l.utf-8 UTF-8" - done - for l in tr tr_TR; do - echo "$l ISO-8859-9" - echo "$l.iso-8859-9 ISO-8859-9" - echo "$l.cp-857 CP857" - echo "$l.cp-1254 CP1254" - echo "$l.utf-8 UTF-8" - done - for l in lt lt_LT lv lv_LV; do - #echo "$l BALTIC" # not a commonly used encoding, wrong encoding name - echo "$l ISO-8859-13" - done - for l in ru_UA uk uk_UA; do - echo "$l KOI8-U" - done - for l in zh zh_CN; do - #echo "$l GB_2312-80" # not a commonly used encoding, wrong encoding name - echo "$l GB2312" - done - for l in ja ja_JP ja_JP.EUC; do - echo "$l EUC-JP" - done - for l in ko ko_KR; do - echo "$l EUC-KR" - done - for l in th th_TH; do - echo "$l TIS-620" - done - for l in fa fa_IR; do - #echo "$l ISIRI-3342" # a broken encoding - echo "$l.utf-8 UTF-8" - done - ;; - linux* | *-gnu*) - # With glibc-2.1 or newer, we don't need any canonicalization, - # because glibc has iconv and both glibc and libiconv support all - # GNU canonical names directly. Therefore, the Makefile does not - # need to install the alias file at all. - # The following applies only to glibc-2.0.x and older libcs. - echo "ISO_646.IRV:1983 ASCII" - ;; - aix*) - echo "ISO8859-1 ISO-8859-1" - echo "ISO8859-2 ISO-8859-2" - echo "ISO8859-5 ISO-8859-5" - echo "ISO8859-6 ISO-8859-6" - echo "ISO8859-7 ISO-8859-7" - echo "ISO8859-8 ISO-8859-8" - echo "ISO8859-9 ISO-8859-9" - echo "ISO8859-15 ISO-8859-15" - echo "IBM-850 CP850" - echo "IBM-856 CP856" - echo "IBM-921 ISO-8859-13" - echo "IBM-922 CP922" - echo "IBM-932 CP932" - echo "IBM-943 CP943" - echo "IBM-1046 CP1046" - echo "IBM-1124 CP1124" - echo "IBM-1129 CP1129" - echo "IBM-1252 CP1252" - echo "IBM-eucCN GB2312" - echo "IBM-eucJP EUC-JP" - echo "IBM-eucKR EUC-KR" - echo "IBM-eucTW EUC-TW" - echo "big5 BIG5" - echo "GBK GBK" - echo "TIS-620 TIS-620" - echo "UTF-8 UTF-8" - ;; - hpux*) - echo "iso88591 ISO-8859-1" - echo "iso88592 ISO-8859-2" - echo "iso88595 ISO-8859-5" - echo "iso88596 ISO-8859-6" - echo "iso88597 ISO-8859-7" - echo "iso88598 ISO-8859-8" - echo "iso88599 ISO-8859-9" - echo "iso885915 ISO-8859-15" - echo "roman8 HP-ROMAN8" - echo "arabic8 HP-ARABIC8" - echo "greek8 HP-GREEK8" - echo "hebrew8 HP-HEBREW8" - echo "turkish8 HP-TURKISH8" - echo "kana8 HP-KANA8" - echo "tis620 TIS-620" - echo "big5 BIG5" - echo "eucJP EUC-JP" - echo "eucKR EUC-KR" - echo "eucTW EUC-TW" - echo "hp15CN GB2312" - #echo "ccdc ?" # what is this? - echo "SJIS SHIFT_JIS" - echo "utf8 UTF-8" - ;; - irix*) - echo "ISO8859-1 ISO-8859-1" - echo "ISO8859-2 ISO-8859-2" - echo "ISO8859-5 ISO-8859-5" - echo "ISO8859-7 ISO-8859-7" - echo "ISO8859-9 ISO-8859-9" - echo "eucCN GB2312" - echo "eucJP EUC-JP" - echo "eucKR EUC-KR" - echo "eucTW EUC-TW" - ;; - osf*) - echo "ISO8859-1 ISO-8859-1" - echo "ISO8859-2 ISO-8859-2" - echo "ISO8859-4 ISO-8859-4" - echo "ISO8859-5 ISO-8859-5" - echo "ISO8859-7 ISO-8859-7" - echo "ISO8859-8 ISO-8859-8" - echo "ISO8859-9 ISO-8859-9" - echo "ISO8859-15 ISO-8859-15" - echo "cp850 CP850" - echo "big5 BIG5" - echo "dechanyu DEC-HANYU" - echo "dechanzi GB2312" - echo "deckanji DEC-KANJI" - echo "deckorean EUC-KR" - echo "eucJP EUC-JP" - echo "eucKR EUC-KR" - echo "eucTW EUC-TW" - echo "GBK GBK" - echo "KSC5601 CP949" - echo "sdeckanji EUC-JP" - echo "SJIS SHIFT_JIS" - echo "TACTIS TIS-620" - echo "UTF-8 UTF-8" - ;; - solaris*) - echo "646 ASCII" - echo "ISO8859-1 ISO-8859-1" - echo "ISO8859-2 ISO-8859-2" - echo "ISO8859-3 ISO-8859-3" - echo "ISO8859-4 ISO-8859-4" - echo "ISO8859-5 ISO-8859-5" - echo "ISO8859-6 ISO-8859-6" - echo "ISO8859-7 ISO-8859-7" - echo "ISO8859-8 ISO-8859-8" - echo "ISO8859-9 ISO-8859-9" - echo "ISO8859-15 ISO-8859-15" - echo "koi8-r KOI8-R" - echo "ansi-1251 CP1251" - echo "BIG5 BIG5" - echo "Big5-HKSCS BIG5-HKSCS" - echo "gb2312 GB2312" - echo "GBK GBK" - echo "GB18030 GB18030" - echo "cns11643 EUC-TW" - echo "5601 EUC-KR" - echo "ko_KR.johap92 JOHAB" - echo "eucJP EUC-JP" - echo "PCK SHIFT_JIS" - echo "TIS620.2533 TIS-620" - #echo "sun_eu_greek ?" # what is this? - echo "UTF-8 UTF-8" - ;; - freebsd* | os2*) - # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore - # localcharset.c falls back to using the full locale name - # from the environment variables. - # Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just - # reuse FreeBSD's locale data for OS/2. - echo "C ASCII" - echo "US-ASCII ASCII" - for l in la_LN lt_LN; do - echo "$l.ASCII ASCII" - done - for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \ - fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT la_LN \ - lt_LN nl_BE nl_NL no_NO pt_PT sv_SE; do - echo "$l.ISO_8859-1 ISO-8859-1" - echo "$l.DIS_8859-15 ISO-8859-15" - done - for l in cs_CZ hr_HR hu_HU la_LN lt_LN pl_PL sl_SI; do - echo "$l.ISO_8859-2 ISO-8859-2" - done - for l in la_LN lt_LT; do - echo "$l.ISO_8859-4 ISO-8859-4" - done - for l in ru_RU ru_SU; do - echo "$l.KOI8-R KOI8-R" - echo "$l.ISO_8859-5 ISO-8859-5" - echo "$l.CP866 CP866" - done - echo "uk_UA.KOI8-U KOI8-U" - echo "zh_TW.BIG5 BIG5" - echo "zh_TW.Big5 BIG5" - echo "zh_CN.EUC GB2312" - echo "ja_JP.EUC EUC-JP" - echo "ja_JP.SJIS SHIFT_JIS" - echo "ja_JP.Shift_JIS SHIFT_JIS" - echo "ko_KR.EUC EUC-KR" - ;; - netbsd*) - echo "646 ASCII" - echo "ISO8859-1 ISO-8859-1" - echo "ISO8859-2 ISO-8859-2" - echo "ISO8859-4 ISO-8859-4" - echo "ISO8859-5 ISO-8859-5" - echo "ISO8859-7 ISO-8859-7" - echo "ISO8859-13 ISO-8859-13" - echo "ISO8859-15 ISO-8859-15" - echo "eucCN GB2312" - echo "eucJP EUC-JP" - echo "eucKR EUC-KR" - echo "eucTW EUC-TW" - echo "BIG5 BIG5" - echo "SJIS SHIFT_JIS" - ;; - openbsd*) - echo "646 ASCII" - echo "ISO8859-1 ISO-8859-1" - echo "ISO8859-2 ISO-8859-2" - echo "ISO8859-4 ISO-8859-4" - echo "ISO8859-5 ISO-8859-5" - echo "ISO8859-7 ISO-8859-7" - echo "ISO8859-13 ISO-8859-13" - echo "ISO8859-15 ISO-8859-15" - ;; - darwin[56]*) - # Darwin 6.8 doesn't have nl_langinfo(CODESET); therefore - # localcharset.c falls back to using the full locale name - # from the environment variables. - echo "C ASCII" - for l in en_AU en_CA en_GB en_US la_LN; do - echo "$l.US-ASCII ASCII" - done - for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \ - fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT nl_BE \ - nl_NL no_NO pt_PT sv_SE; do - echo "$l ISO-8859-1" - echo "$l.ISO8859-1 ISO-8859-1" - echo "$l.ISO8859-15 ISO-8859-15" - done - for l in la_LN; do - echo "$l.ISO8859-1 ISO-8859-1" - echo "$l.ISO8859-15 ISO-8859-15" - done - for l in cs_CZ hr_HR hu_HU la_LN pl_PL sl_SI; do - echo "$l.ISO8859-2 ISO-8859-2" - done - for l in la_LN lt_LT; do - echo "$l.ISO8859-4 ISO-8859-4" - done - for l in ru_RU; do - echo "$l.KOI8-R KOI8-R" - echo "$l.ISO8859-5 ISO-8859-5" - echo "$l.CP866 CP866" - done - for l in bg_BG; do - echo "$l.CP1251 CP1251" - done - echo "uk_UA.KOI8-U KOI8-U" - echo "zh_TW.BIG5 BIG5" - echo "zh_TW.Big5 BIG5" - echo "zh_CN.EUC GB2312" - echo "ja_JP.EUC EUC-JP" - echo "ja_JP.SJIS SHIFT_JIS" - echo "ko_KR.EUC EUC-KR" - ;; - darwin*) - # Darwin 7.5 has nl_langinfo(CODESET), but sometimes its value is - # useless: - # - It returns the empty string when LANG is set to a locale of the - # form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8 - # LC_CTYPE file. - # - The environment variables LANG, LC_CTYPE, LC_ALL are not set by - # the system; nl_langinfo(CODESET) returns "US-ASCII" in this case. - # - The documentation says: - # "... all code that calls BSD system routines should ensure - # that the const *char parameters of these routines are in UTF-8 - # encoding. All BSD system functions expect their string - # parameters to be in UTF-8 encoding and nothing else." - # It also says - # "An additional caveat is that string parameters for files, - # paths, and other file-system entities must be in canonical - # UTF-8. In a canonical UTF-8 Unicode string, all decomposable - # characters are decomposed ..." - # but this is not true: You can pass non-decomposed UTF-8 strings - # to file system functions, and it is the OS which will convert - # them to decomposed UTF-8 before accessing the file system. - # - The Apple Terminal application displays UTF-8 by default. - # - However, other applications are free to use different encodings: - # - xterm uses ISO-8859-1 by default. - # - TextEdit uses MacRoman by default. - # We prefer UTF-8 over decomposed UTF-8-MAC because one should - # minimize the use of decomposed Unicode. Unfortunately, through the - # Darwin file system, decomposed UTF-8 strings are leaked into user - # space nevertheless. - # Then there are also the locales with encodings other than US-ASCII - # and UTF-8. These locales can be occasionally useful to users (e.g. - # when grepping through ISO-8859-1 encoded text files), when all their - # file names are in US-ASCII. - echo "ISO8859-1 ISO-8859-1" - echo "ISO8859-2 ISO-8859-2" - echo "ISO8859-4 ISO-8859-4" - echo "ISO8859-5 ISO-8859-5" - echo "ISO8859-7 ISO-8859-7" - echo "ISO8859-9 ISO-8859-9" - echo "ISO8859-13 ISO-8859-13" - echo "ISO8859-15 ISO-8859-15" - echo "KOI8-R KOI8-R" - echo "KOI8-U KOI8-U" - echo "CP866 CP866" - echo "CP949 CP949" - echo "CP1131 CP1131" - echo "CP1251 CP1251" - echo "eucCN GB2312" - echo "GB2312 GB2312" - echo "eucJP EUC-JP" - echo "eucKR EUC-KR" - echo "Big5 BIG5" - echo "Big5HKSCS BIG5-HKSCS" - echo "GBK GBK" - echo "GB18030 GB18030" - echo "SJIS SHIFT_JIS" - echo "ARMSCII-8 ARMSCII-8" - echo "PT154 PT154" - #echo "ISCII-DEV ?" - echo "* UTF-8" - ;; - beos* | haiku*) - # BeOS and Haiku have a single locale, and it has UTF-8 encoding. - echo "* UTF-8" - ;; - msdosdjgpp*) - # DJGPP 2.03 doesn't have nl_langinfo(CODESET); therefore - # localcharset.c falls back to using the full locale name - # from the environment variables. - echo "#" - echo "# The encodings given here may not all be correct." - echo "# If you find that the encoding given for your language and" - echo "# country is not the one your DOS machine actually uses, just" - echo "# correct it in this file, and send a mail to" - echo "# Juan Manuel Guerrero " - echo "# and Bruno Haible ." - echo "#" - echo "C ASCII" - # ISO-8859-1 languages - echo "ca CP850" - echo "ca_ES CP850" - echo "da CP865" # not CP850 ?? - echo "da_DK CP865" # not CP850 ?? - echo "de CP850" - echo "de_AT CP850" - echo "de_CH CP850" - echo "de_DE CP850" - echo "en CP850" - echo "en_AU CP850" # not CP437 ?? - echo "en_CA CP850" - echo "en_GB CP850" - echo "en_NZ CP437" - echo "en_US CP437" - echo "en_ZA CP850" # not CP437 ?? - echo "es CP850" - echo "es_AR CP850" - echo "es_BO CP850" - echo "es_CL CP850" - echo "es_CO CP850" - echo "es_CR CP850" - echo "es_CU CP850" - echo "es_DO CP850" - echo "es_EC CP850" - echo "es_ES CP850" - echo "es_GT CP850" - echo "es_HN CP850" - echo "es_MX CP850" - echo "es_NI CP850" - echo "es_PA CP850" - echo "es_PY CP850" - echo "es_PE CP850" - echo "es_SV CP850" - echo "es_UY CP850" - echo "es_VE CP850" - echo "et CP850" - echo "et_EE CP850" - echo "eu CP850" - echo "eu_ES CP850" - echo "fi CP850" - echo "fi_FI CP850" - echo "fr CP850" - echo "fr_BE CP850" - echo "fr_CA CP850" - echo "fr_CH CP850" - echo "fr_FR CP850" - echo "ga CP850" - echo "ga_IE CP850" - echo "gd CP850" - echo "gd_GB CP850" - echo "gl CP850" - echo "gl_ES CP850" - echo "id CP850" # not CP437 ?? - echo "id_ID CP850" # not CP437 ?? - echo "is CP861" # not CP850 ?? - echo "is_IS CP861" # not CP850 ?? - echo "it CP850" - echo "it_CH CP850" - echo "it_IT CP850" - echo "lt CP775" - echo "lt_LT CP775" - echo "lv CP775" - echo "lv_LV CP775" - echo "nb CP865" # not CP850 ?? - echo "nb_NO CP865" # not CP850 ?? - echo "nl CP850" - echo "nl_BE CP850" - echo "nl_NL CP850" - echo "nn CP865" # not CP850 ?? - echo "nn_NO CP865" # not CP850 ?? - echo "no CP865" # not CP850 ?? - echo "no_NO CP865" # not CP850 ?? - echo "pt CP850" - echo "pt_BR CP850" - echo "pt_PT CP850" - echo "sv CP850" - echo "sv_SE CP850" - # ISO-8859-2 languages - echo "cs CP852" - echo "cs_CZ CP852" - echo "hr CP852" - echo "hr_HR CP852" - echo "hu CP852" - echo "hu_HU CP852" - echo "pl CP852" - echo "pl_PL CP852" - echo "ro CP852" - echo "ro_RO CP852" - echo "sk CP852" - echo "sk_SK CP852" - echo "sl CP852" - echo "sl_SI CP852" - echo "sq CP852" - echo "sq_AL CP852" - echo "sr CP852" # CP852 or CP866 or CP855 ?? - echo "sr_CS CP852" # CP852 or CP866 or CP855 ?? - echo "sr_YU CP852" # CP852 or CP866 or CP855 ?? - # ISO-8859-3 languages - echo "mt CP850" - echo "mt_MT CP850" - # ISO-8859-5 languages - echo "be CP866" - echo "be_BE CP866" - echo "bg CP866" # not CP855 ?? - echo "bg_BG CP866" # not CP855 ?? - echo "mk CP866" # not CP855 ?? - echo "mk_MK CP866" # not CP855 ?? - echo "ru CP866" - echo "ru_RU CP866" - echo "uk CP1125" - echo "uk_UA CP1125" - # ISO-8859-6 languages - echo "ar CP864" - echo "ar_AE CP864" - echo "ar_DZ CP864" - echo "ar_EG CP864" - echo "ar_IQ CP864" - echo "ar_IR CP864" - echo "ar_JO CP864" - echo "ar_KW CP864" - echo "ar_MA CP864" - echo "ar_OM CP864" - echo "ar_QA CP864" - echo "ar_SA CP864" - echo "ar_SY CP864" - # ISO-8859-7 languages - echo "el CP869" - echo "el_GR CP869" - # ISO-8859-8 languages - echo "he CP862" - echo "he_IL CP862" - # ISO-8859-9 languages - echo "tr CP857" - echo "tr_TR CP857" - # Japanese - echo "ja CP932" - echo "ja_JP CP932" - # Chinese - echo "zh_CN GBK" - echo "zh_TW CP950" # not CP938 ?? - # Korean - echo "kr CP949" # not CP934 ?? - echo "kr_KR CP949" # not CP934 ?? - # Thai - echo "th CP874" - echo "th_TH CP874" - # Other - echo "eo CP850" - echo "eo_EO CP850" - ;; + linux-gnulibc1*) + # Linux libc5 doesn't have nl_langinfo(CODESET); therefore + # localcharset.c falls back to using the full locale name + # from the environment variables. + echo "C ASCII" + echo "POSIX ASCII" + for l in af af_ZA ca ca_ES da da_DK de de_AT de_BE de_CH de_DE de_LU \ + en en_AU en_BW en_CA en_DK en_GB en_IE en_NZ en_US en_ZA \ + en_ZW es es_AR es_BO es_CL es_CO es_DO es_EC es_ES es_GT \ + es_HN es_MX es_PA es_PE es_PY es_SV es_US es_UY es_VE et \ + et_EE eu eu_ES fi fi_FI fo fo_FO fr fr_BE fr_CA fr_CH fr_FR \ + fr_LU ga ga_IE gl gl_ES id id_ID in in_ID is is_IS it it_CH \ + it_IT kl kl_GL nl nl_BE nl_NL no no_NO pt pt_BR pt_PT sv \ + sv_FI sv_SE; do + echo "$l ISO-8859-1" + echo "$l.iso-8859-1 ISO-8859-1" + echo "$l.iso-8859-15 ISO-8859-15" + echo "$l.iso-8859-15@euro ISO-8859-15" + echo "$l@euro ISO-8859-15" + echo "$l.cp-437 CP437" + echo "$l.cp-850 CP850" + echo "$l.cp-1252 CP1252" + echo "$l.cp-1252@euro CP1252" + #echo "$l.atari-st ATARI-ST" # not a commonly used encoding + echo "$l.utf-8 UTF-8" + echo "$l.utf-8@euro UTF-8" + done + for l in cs cs_CZ hr hr_HR hu hu_HU pl pl_PL ro ro_RO sk sk_SK sl \ + sl_SI sr sr_CS sr_YU; do + echo "$l ISO-8859-2" + echo "$l.iso-8859-2 ISO-8859-2" + echo "$l.cp-852 CP852" + echo "$l.cp-1250 CP1250" + echo "$l.utf-8 UTF-8" + done + for l in mk mk_MK ru ru_RU; do + echo "$l ISO-8859-5" + echo "$l.iso-8859-5 ISO-8859-5" + echo "$l.koi8-r KOI8-R" + echo "$l.cp-866 CP866" + echo "$l.cp-1251 CP1251" + echo "$l.utf-8 UTF-8" + done + for l in ar ar_SA; do + echo "$l ISO-8859-6" + echo "$l.iso-8859-6 ISO-8859-6" + echo "$l.cp-864 CP864" + #echo "$l.cp-868 CP868" # not a commonly used encoding + echo "$l.cp-1256 CP1256" + echo "$l.utf-8 UTF-8" + done + for l in el el_GR gr gr_GR; do + echo "$l ISO-8859-7" + echo "$l.iso-8859-7 ISO-8859-7" + echo "$l.cp-869 CP869" + echo "$l.cp-1253 CP1253" + echo "$l.cp-1253@euro CP1253" + echo "$l.utf-8 UTF-8" + echo "$l.utf-8@euro UTF-8" + done + for l in he he_IL iw iw_IL; do + echo "$l ISO-8859-8" + echo "$l.iso-8859-8 ISO-8859-8" + echo "$l.cp-862 CP862" + echo "$l.cp-1255 CP1255" + echo "$l.utf-8 UTF-8" + done + for l in tr tr_TR; do + echo "$l ISO-8859-9" + echo "$l.iso-8859-9 ISO-8859-9" + echo "$l.cp-857 CP857" + echo "$l.cp-1254 CP1254" + echo "$l.utf-8 UTF-8" + done + for l in lt lt_LT lv lv_LV; do + #echo "$l BALTIC" # not a commonly used encoding, wrong encoding name + echo "$l ISO-8859-13" + done + for l in ru_UA uk uk_UA; do + echo "$l KOI8-U" + done + for l in zh zh_CN; do + #echo "$l GB_2312-80" # not a commonly used encoding, wrong encoding name + echo "$l GB2312" + done + for l in ja ja_JP ja_JP.EUC; do + echo "$l EUC-JP" + done + for l in ko ko_KR; do + echo "$l EUC-KR" + done + for l in th th_TH; do + echo "$l TIS-620" + done + for l in fa fa_IR; do + #echo "$l ISIRI-3342" # a broken encoding + echo "$l.utf-8 UTF-8" + done + ;; + linux* | *-gnu*) + # With glibc-2.1 or newer, we don't need any canonicalization, + # because glibc has iconv and both glibc and libiconv support all + # GNU canonical names directly. Therefore, the Makefile does not + # need to install the alias file at all. + # The following applies only to glibc-2.0.x and older libcs. + echo "ISO_646.IRV:1983 ASCII" + ;; + aix*) + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-6 ISO-8859-6" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-8 ISO-8859-8" + echo "ISO8859-9 ISO-8859-9" + echo "ISO8859-15 ISO-8859-15" + echo "IBM-850 CP850" + echo "IBM-856 CP856" + echo "IBM-921 ISO-8859-13" + echo "IBM-922 CP922" + echo "IBM-932 CP932" + echo "IBM-943 CP943" + echo "IBM-1046 CP1046" + echo "IBM-1124 CP1124" + echo "IBM-1129 CP1129" + echo "IBM-1252 CP1252" + echo "IBM-eucCN GB2312" + echo "IBM-eucJP EUC-JP" + echo "IBM-eucKR EUC-KR" + echo "IBM-eucTW EUC-TW" + echo "big5 BIG5" + echo "GBK GBK" + echo "TIS-620 TIS-620" + echo "UTF-8 UTF-8" + ;; + hpux*) + echo "iso88591 ISO-8859-1" + echo "iso88592 ISO-8859-2" + echo "iso88595 ISO-8859-5" + echo "iso88596 ISO-8859-6" + echo "iso88597 ISO-8859-7" + echo "iso88598 ISO-8859-8" + echo "iso88599 ISO-8859-9" + echo "iso885915 ISO-8859-15" + echo "roman8 HP-ROMAN8" + echo "arabic8 HP-ARABIC8" + echo "greek8 HP-GREEK8" + echo "hebrew8 HP-HEBREW8" + echo "turkish8 HP-TURKISH8" + echo "kana8 HP-KANA8" + echo "tis620 TIS-620" + echo "big5 BIG5" + echo "eucJP EUC-JP" + echo "eucKR EUC-KR" + echo "eucTW EUC-TW" + echo "hp15CN GB2312" + #echo "ccdc ?" # what is this? + echo "SJIS SHIFT_JIS" + echo "utf8 UTF-8" + ;; + irix*) + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-9 ISO-8859-9" + echo "eucCN GB2312" + echo "eucJP EUC-JP" + echo "eucKR EUC-KR" + echo "eucTW EUC-TW" + ;; + osf*) + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-4 ISO-8859-4" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-8 ISO-8859-8" + echo "ISO8859-9 ISO-8859-9" + echo "ISO8859-15 ISO-8859-15" + echo "cp850 CP850" + echo "big5 BIG5" + echo "dechanyu DEC-HANYU" + echo "dechanzi GB2312" + echo "deckanji DEC-KANJI" + echo "deckorean EUC-KR" + echo "eucJP EUC-JP" + echo "eucKR EUC-KR" + echo "eucTW EUC-TW" + echo "GBK GBK" + echo "KSC5601 CP949" + echo "sdeckanji EUC-JP" + echo "SJIS SHIFT_JIS" + echo "TACTIS TIS-620" + echo "UTF-8 UTF-8" + ;; + solaris*) + echo "646 ASCII" + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-3 ISO-8859-3" + echo "ISO8859-4 ISO-8859-4" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-6 ISO-8859-6" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-8 ISO-8859-8" + echo "ISO8859-9 ISO-8859-9" + echo "ISO8859-15 ISO-8859-15" + echo "koi8-r KOI8-R" + echo "ansi-1251 CP1251" + echo "BIG5 BIG5" + echo "Big5-HKSCS BIG5-HKSCS" + echo "gb2312 GB2312" + echo "GBK GBK" + echo "GB18030 GB18030" + echo "cns11643 EUC-TW" + echo "5601 EUC-KR" + echo "ko_KR.johap92 JOHAB" + echo "eucJP EUC-JP" + echo "PCK SHIFT_JIS" + echo "TIS620.2533 TIS-620" + #echo "sun_eu_greek ?" # what is this? + echo "UTF-8 UTF-8" + ;; + freebsd* | os2*) + # FreeBSD 4.2 doesn't have nl_langinfo(CODESET); therefore + # localcharset.c falls back to using the full locale name + # from the environment variables. + # Likewise for OS/2. OS/2 has XFree86 just like FreeBSD. Just + # reuse FreeBSD's locale data for OS/2. + echo "C ASCII" + echo "US-ASCII ASCII" + for l in la_LN lt_LN; do + echo "$l.ASCII ASCII" + done + for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \ + fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT la_LN \ + lt_LN nl_BE nl_NL no_NO pt_PT sv_SE; do + echo "$l.ISO_8859-1 ISO-8859-1" + echo "$l.DIS_8859-15 ISO-8859-15" + done + for l in cs_CZ hr_HR hu_HU la_LN lt_LN pl_PL sl_SI; do + echo "$l.ISO_8859-2 ISO-8859-2" + done + for l in la_LN lt_LT; do + echo "$l.ISO_8859-4 ISO-8859-4" + done + for l in ru_RU ru_SU; do + echo "$l.KOI8-R KOI8-R" + echo "$l.ISO_8859-5 ISO-8859-5" + echo "$l.CP866 CP866" + done + echo "uk_UA.KOI8-U KOI8-U" + echo "zh_TW.BIG5 BIG5" + echo "zh_TW.Big5 BIG5" + echo "zh_CN.EUC GB2312" + echo "ja_JP.EUC EUC-JP" + echo "ja_JP.SJIS SHIFT_JIS" + echo "ja_JP.Shift_JIS SHIFT_JIS" + echo "ko_KR.EUC EUC-KR" + ;; + netbsd*) + echo "646 ASCII" + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-4 ISO-8859-4" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-13 ISO-8859-13" + echo "ISO8859-15 ISO-8859-15" + echo "eucCN GB2312" + echo "eucJP EUC-JP" + echo "eucKR EUC-KR" + echo "eucTW EUC-TW" + echo "BIG5 BIG5" + echo "SJIS SHIFT_JIS" + ;; + openbsd*) + echo "646 ASCII" + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-4 ISO-8859-4" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-13 ISO-8859-13" + echo "ISO8859-15 ISO-8859-15" + ;; + darwin[56]*) + # Darwin 6.8 doesn't have nl_langinfo(CODESET); therefore + # localcharset.c falls back to using the full locale name + # from the environment variables. + echo "C ASCII" + for l in en_AU en_CA en_GB en_US la_LN; do + echo "$l.US-ASCII ASCII" + done + for l in da_DK de_AT de_CH de_DE en_AU en_CA en_GB en_US es_ES \ + fi_FI fr_BE fr_CA fr_CH fr_FR is_IS it_CH it_IT nl_BE \ + nl_NL no_NO pt_PT sv_SE; do + echo "$l ISO-8859-1" + echo "$l.ISO8859-1 ISO-8859-1" + echo "$l.ISO8859-15 ISO-8859-15" + done + for l in la_LN; do + echo "$l.ISO8859-1 ISO-8859-1" + echo "$l.ISO8859-15 ISO-8859-15" + done + for l in cs_CZ hr_HR hu_HU la_LN pl_PL sl_SI; do + echo "$l.ISO8859-2 ISO-8859-2" + done + for l in la_LN lt_LT; do + echo "$l.ISO8859-4 ISO-8859-4" + done + for l in ru_RU; do + echo "$l.KOI8-R KOI8-R" + echo "$l.ISO8859-5 ISO-8859-5" + echo "$l.CP866 CP866" + done + for l in bg_BG; do + echo "$l.CP1251 CP1251" + done + echo "uk_UA.KOI8-U KOI8-U" + echo "zh_TW.BIG5 BIG5" + echo "zh_TW.Big5 BIG5" + echo "zh_CN.EUC GB2312" + echo "ja_JP.EUC EUC-JP" + echo "ja_JP.SJIS SHIFT_JIS" + echo "ko_KR.EUC EUC-KR" + ;; + darwin*) + # Darwin 7.5 has nl_langinfo(CODESET), but sometimes its value is + # useless: + # - It returns the empty string when LANG is set to a locale of the + # form ll_CC, although ll_CC/LC_CTYPE is a symlink to an UTF-8 + # LC_CTYPE file. + # - The environment variables LANG, LC_CTYPE, LC_ALL are not set by + # the system; nl_langinfo(CODESET) returns "US-ASCII" in this case. + # - The documentation says: + # "... all code that calls BSD system routines should ensure + # that the const *char parameters of these routines are in UTF-8 + # encoding. All BSD system functions expect their string + # parameters to be in UTF-8 encoding and nothing else." + # It also says + # "An additional caveat is that string parameters for files, + # paths, and other file-system entities must be in canonical + # UTF-8. In a canonical UTF-8 Unicode string, all decomposable + # characters are decomposed ..." + # but this is not true: You can pass non-decomposed UTF-8 strings + # to file system functions, and it is the OS which will convert + # them to decomposed UTF-8 before accessing the file system. + # - The Apple Terminal application displays UTF-8 by default. + # - However, other applications are free to use different encodings: + # - xterm uses ISO-8859-1 by default. + # - TextEdit uses MacRoman by default. + # We prefer UTF-8 over decomposed UTF-8-MAC because one should + # minimize the use of decomposed Unicode. Unfortunately, through the + # Darwin file system, decomposed UTF-8 strings are leaked into user + # space nevertheless. + # Then there are also the locales with encodings other than US-ASCII + # and UTF-8. These locales can be occasionally useful to users (e.g. + # when grepping through ISO-8859-1 encoded text files), when all their + # file names are in US-ASCII. + echo "ISO8859-1 ISO-8859-1" + echo "ISO8859-2 ISO-8859-2" + echo "ISO8859-4 ISO-8859-4" + echo "ISO8859-5 ISO-8859-5" + echo "ISO8859-7 ISO-8859-7" + echo "ISO8859-9 ISO-8859-9" + echo "ISO8859-13 ISO-8859-13" + echo "ISO8859-15 ISO-8859-15" + echo "KOI8-R KOI8-R" + echo "KOI8-U KOI8-U" + echo "CP866 CP866" + echo "CP949 CP949" + echo "CP1131 CP1131" + echo "CP1251 CP1251" + echo "eucCN GB2312" + echo "GB2312 GB2312" + echo "eucJP EUC-JP" + echo "eucKR EUC-KR" + echo "Big5 BIG5" + echo "Big5HKSCS BIG5-HKSCS" + echo "GBK GBK" + echo "GB18030 GB18030" + echo "SJIS SHIFT_JIS" + echo "ARMSCII-8 ARMSCII-8" + echo "PT154 PT154" + #echo "ISCII-DEV ?" + echo "* UTF-8" + ;; + beos* | haiku*) + # BeOS and Haiku have a single locale, and it has UTF-8 encoding. + echo "* UTF-8" + ;; + msdosdjgpp*) + # DJGPP 2.03 doesn't have nl_langinfo(CODESET); therefore + # localcharset.c falls back to using the full locale name + # from the environment variables. + echo "#" + echo "# The encodings given here may not all be correct." + echo "# If you find that the encoding given for your language and" + echo "# country is not the one your DOS machine actually uses, just" + echo "# correct it in this file, and send a mail to" + echo "# Juan Manuel Guerrero " + echo "# and Bruno Haible ." + echo "#" + echo "C ASCII" + # ISO-8859-1 languages + echo "ca CP850" + echo "ca_ES CP850" + echo "da CP865" # not CP850 ?? + echo "da_DK CP865" # not CP850 ?? + echo "de CP850" + echo "de_AT CP850" + echo "de_CH CP850" + echo "de_DE CP850" + echo "en CP850" + echo "en_AU CP850" # not CP437 ?? + echo "en_CA CP850" + echo "en_GB CP850" + echo "en_NZ CP437" + echo "en_US CP437" + echo "en_ZA CP850" # not CP437 ?? + echo "es CP850" + echo "es_AR CP850" + echo "es_BO CP850" + echo "es_CL CP850" + echo "es_CO CP850" + echo "es_CR CP850" + echo "es_CU CP850" + echo "es_DO CP850" + echo "es_EC CP850" + echo "es_ES CP850" + echo "es_GT CP850" + echo "es_HN CP850" + echo "es_MX CP850" + echo "es_NI CP850" + echo "es_PA CP850" + echo "es_PY CP850" + echo "es_PE CP850" + echo "es_SV CP850" + echo "es_UY CP850" + echo "es_VE CP850" + echo "et CP850" + echo "et_EE CP850" + echo "eu CP850" + echo "eu_ES CP850" + echo "fi CP850" + echo "fi_FI CP850" + echo "fr CP850" + echo "fr_BE CP850" + echo "fr_CA CP850" + echo "fr_CH CP850" + echo "fr_FR CP850" + echo "ga CP850" + echo "ga_IE CP850" + echo "gd CP850" + echo "gd_GB CP850" + echo "gl CP850" + echo "gl_ES CP850" + echo "id CP850" # not CP437 ?? + echo "id_ID CP850" # not CP437 ?? + echo "is CP861" # not CP850 ?? + echo "is_IS CP861" # not CP850 ?? + echo "it CP850" + echo "it_CH CP850" + echo "it_IT CP850" + echo "lt CP775" + echo "lt_LT CP775" + echo "lv CP775" + echo "lv_LV CP775" + echo "nb CP865" # not CP850 ?? + echo "nb_NO CP865" # not CP850 ?? + echo "nl CP850" + echo "nl_BE CP850" + echo "nl_NL CP850" + echo "nn CP865" # not CP850 ?? + echo "nn_NO CP865" # not CP850 ?? + echo "no CP865" # not CP850 ?? + echo "no_NO CP865" # not CP850 ?? + echo "pt CP850" + echo "pt_BR CP850" + echo "pt_PT CP850" + echo "sv CP850" + echo "sv_SE CP850" + # ISO-8859-2 languages + echo "cs CP852" + echo "cs_CZ CP852" + echo "hr CP852" + echo "hr_HR CP852" + echo "hu CP852" + echo "hu_HU CP852" + echo "pl CP852" + echo "pl_PL CP852" + echo "ro CP852" + echo "ro_RO CP852" + echo "sk CP852" + echo "sk_SK CP852" + echo "sl CP852" + echo "sl_SI CP852" + echo "sq CP852" + echo "sq_AL CP852" + echo "sr CP852" # CP852 or CP866 or CP855 ?? + echo "sr_CS CP852" # CP852 or CP866 or CP855 ?? + echo "sr_YU CP852" # CP852 or CP866 or CP855 ?? + # ISO-8859-3 languages + echo "mt CP850" + echo "mt_MT CP850" + # ISO-8859-5 languages + echo "be CP866" + echo "be_BE CP866" + echo "bg CP866" # not CP855 ?? + echo "bg_BG CP866" # not CP855 ?? + echo "mk CP866" # not CP855 ?? + echo "mk_MK CP866" # not CP855 ?? + echo "ru CP866" + echo "ru_RU CP866" + echo "uk CP1125" + echo "uk_UA CP1125" + # ISO-8859-6 languages + echo "ar CP864" + echo "ar_AE CP864" + echo "ar_DZ CP864" + echo "ar_EG CP864" + echo "ar_IQ CP864" + echo "ar_IR CP864" + echo "ar_JO CP864" + echo "ar_KW CP864" + echo "ar_MA CP864" + echo "ar_OM CP864" + echo "ar_QA CP864" + echo "ar_SA CP864" + echo "ar_SY CP864" + # ISO-8859-7 languages + echo "el CP869" + echo "el_GR CP869" + # ISO-8859-8 languages + echo "he CP862" + echo "he_IL CP862" + # ISO-8859-9 languages + echo "tr CP857" + echo "tr_TR CP857" + # Japanese + echo "ja CP932" + echo "ja_JP CP932" + # Chinese + echo "zh_CN GBK" + echo "zh_TW CP950" # not CP938 ?? + # Korean + echo "kr CP949" # not CP934 ?? + echo "kr_KR CP949" # not CP934 ?? + # Thai + echo "th CP874" + echo "th_TH CP874" + # Other + echo "eo CP850" + echo "eo_EO CP850" + ;; esac diff --git a/lib/dup2.c b/lib/dup2.c deleted file mode 100644 index a7d3cfd7..00000000 --- a/lib/dup2.c +++ /dev/null @@ -1,97 +0,0 @@ -/* Duplicate an open file descriptor to a specified file descriptor. - - Copyright (C) 1999, 2004, 2005, 2006, 2007, 2009 Free Software - Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . */ - -/* written by Paul Eggert */ - -#include - -/* Specification. */ -#include - -#include -#include - -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ -/* Get declarations of the Win32 API functions. */ -# define WIN32_LEAN_AND_MEAN -# include -#endif - -#if REPLACE_DUP2 - -# undef dup2 - -int -rpl_dup2 (int fd, int desired_fd) -{ - int result; -# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* If fd is closed, mingw hangs on dup2 (fd, fd). If fd is open, - dup2 (fd, fd) returns 0, but all further attempts to use fd in - future dup2 calls will hang. */ - if (fd == desired_fd) - { - if ((HANDLE) _get_osfhandle (fd) == INVALID_HANDLE_VALUE) - { - errno = EBADF; - return -1; - } - return fd; - } -# endif - result = dup2 (fd, desired_fd); - if (result == 0) - result = desired_fd; - return result; -} - -#else /* !REPLACE_DUP2 */ - -/* On older platforms, dup2 did not exist. */ - -# ifndef F_DUPFD -static int -dupfd (int fd, int desired_fd) -{ - int duplicated_fd = dup (fd); - if (duplicated_fd < 0 || duplicated_fd == desired_fd) - return duplicated_fd; - else - { - int r = dupfd (fd, desired_fd); - int e = errno; - close (duplicated_fd); - errno = e; - return r; - } -} -# endif - -int -dup2 (int fd, int desired_fd) -{ - if (fd == desired_fd) - return fd; - close (desired_fd); -# ifdef F_DUPFD - return fcntl (fd, F_DUPFD, desired_fd); -# else - return dupfd (fd, desired_fd); -# endif -} -#endif /* !REPLACE_DUP2 */ diff --git a/lib/errno.in.h b/lib/errno.in.h index a9b81d5d..0e6fb7f9 100644 --- a/lib/errno.in.h +++ b/lib/errno.in.h @@ -1,6 +1,6 @@ /* A POSIX-like . - Copyright (C) 2008-2009 Free Software Foundation, Inc. + Copyright (C) 2008-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/float+.h b/lib/float+.h index 2288e3d3..956eb28f 100644 --- a/lib/float+.h +++ b/lib/float+.h @@ -1,5 +1,5 @@ /* Supplemental information about the floating-point formats. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software; you can redistribute it and/or modify diff --git a/lib/float.in.h b/lib/float.in.h index 63d55f87..ad99af31 100644 --- a/lib/float.in.h +++ b/lib/float.in.h @@ -1,6 +1,6 @@ /* A correct . - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/fpucw.h b/lib/fpucw.h index 4bd00811..dbbe363d 100644 --- a/lib/fpucw.h +++ b/lib/fpucw.h @@ -1,5 +1,5 @@ /* Manipulating the FPU control word. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify @@ -70,19 +70,19 @@ typedef unsigned short fpucw_t; /* glibc calls this fpu_control_t */ # define FPU_PC_EXTENDED 0x300 /* glibc calls this _FPU_EXTENDED */ # define GET_FPUCW() \ - ({ fpucw_t _cw; \ - __asm__ __volatile__ ("fnstcw %0" : "=m" (*&_cw)); \ - _cw; \ + ({ fpucw_t _cw; \ + __asm__ __volatile__ ("fnstcw %0" : "=m" (*&_cw)); \ + _cw; \ }) # define SET_FPUCW(word) \ - (void)({ fpucw_t _ncw = (word); \ - __asm__ __volatile__ ("fldcw %0" : : "m" (*&_ncw)); \ + (void)({ fpucw_t _ncw = (word); \ + __asm__ __volatile__ ("fldcw %0" : : "m" (*&_ncw)); \ }) # define DECL_LONG_DOUBLE_ROUNDING \ fpucw_t oldcw; # define BEGIN_LONG_DOUBLE_ROUNDING() \ - (void)(oldcw = GET_FPUCW (), \ + (void)(oldcw = GET_FPUCW (), \ SET_FPUCW ((oldcw & ~FPU_PC_MASK) | FPU_PC_EXTENDED)) # define END_LONG_DOUBLE_ROUNDING() \ SET_FPUCW (oldcw) diff --git a/lib/frexp.c b/lib/frexp.c index 8c72660e..5828d624 100644 --- a/lib/frexp.c +++ b/lib/frexp.c @@ -1,5 +1,5 @@ /* Split a double into fraction and mantissa. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -85,73 +85,73 @@ FUNC (DOUBLE x, int *expptr) exponent = 0; if (x >= L_(1.0)) { - /* A positive exponent. */ - DOUBLE pow2_i; /* = pow2[i] */ - DOUBLE powh_i; /* = powh[i] */ - - /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, - x * 2^exponent = argument, x >= 1.0. */ - for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); - ; - i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) - { - if (x >= pow2_i) - { - exponent += (1 << i); - x *= powh_i; - } - else - break; - - pow2[i] = pow2_i; - powh[i] = powh_i; - } - /* Avoid making x too small, as it could become a denormalized - number and thus lose precision. */ - while (i > 0 && x < pow2[i - 1]) - { - i--; - powh_i = powh[i]; - } - exponent += (1 << i); - x *= powh_i; - /* Here 2^-2^i <= x < 1.0. */ + /* A positive exponent. */ + DOUBLE pow2_i; /* = pow2[i] */ + DOUBLE powh_i; /* = powh[i] */ + + /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, + x * 2^exponent = argument, x >= 1.0. */ + for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); + ; + i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) + { + if (x >= pow2_i) + { + exponent += (1 << i); + x *= powh_i; + } + else + break; + + pow2[i] = pow2_i; + powh[i] = powh_i; + } + /* Avoid making x too small, as it could become a denormalized + number and thus lose precision. */ + while (i > 0 && x < pow2[i - 1]) + { + i--; + powh_i = powh[i]; + } + exponent += (1 << i); + x *= powh_i; + /* Here 2^-2^i <= x < 1.0. */ } else { - /* A negative or zero exponent. */ - DOUBLE pow2_i; /* = pow2[i] */ - DOUBLE powh_i; /* = powh[i] */ - - /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, - x * 2^exponent = argument, x < 1.0. */ - for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); - ; - i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) - { - if (x < powh_i) - { - exponent -= (1 << i); - x *= pow2_i; - } - else - break; - - pow2[i] = pow2_i; - powh[i] = powh_i; - } - /* Here 2^-2^i <= x < 1.0. */ + /* A negative or zero exponent. */ + DOUBLE pow2_i; /* = pow2[i] */ + DOUBLE powh_i; /* = powh[i] */ + + /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, + x * 2^exponent = argument, x < 1.0. */ + for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); + ; + i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) + { + if (x < powh_i) + { + exponent -= (1 << i); + x *= pow2_i; + } + else + break; + + pow2[i] = pow2_i; + powh[i] = powh_i; + } + /* Here 2^-2^i <= x < 1.0. */ } /* Invariants: x * 2^exponent = argument, and 2^-2^i <= x < 1.0. */ while (i > 0) { - i--; - if (x < powh[i]) - { - exponent -= (1 << i); - x *= pow2[i]; - } + i--; + if (x < powh[i]) + { + exponent -= (1 << i); + x *= pow2[i]; + } } /* Here 0.5 <= x < 1.0. */ } diff --git a/lib/frexpl.c b/lib/frexpl.c index 08f489c9..9cf9bf6c 100644 --- a/lib/frexpl.c +++ b/lib/frexpl.c @@ -1,5 +1,5 @@ /* Split a 'long double' into fraction and mantissa. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/fseterr.c b/lib/fseterr.c index 6c31eebd..359b86e8 100644 --- a/lib/fseterr.c +++ b/lib/fseterr.c @@ -1,5 +1,5 @@ /* Set the error indicator of a stream. - Copyright (C) 2007-2009 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -63,8 +63,8 @@ fseterr (FILE *fp) fputc ('\0', fp); /* This should set the error indicator. */ fflush (fp); /* Or this. */ if (dup2 (fd2, fd) < 0) - /* Whee... we botched the stream and now cannot restore it! */ - abort (); + /* Whee... we botched the stream and now cannot restore it! */ + abort (); close (fd2); } errno = saved_errno; diff --git a/lib/fseterr.h b/lib/fseterr.h index 0adadc34..7c1d34df 100644 --- a/lib/fseterr.h +++ b/lib/fseterr.h @@ -1,5 +1,5 @@ /* Set the error indicator of a stream. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/getpagesize.c b/lib/getpagesize.c deleted file mode 100644 index 82238df1..00000000 --- a/lib/getpagesize.c +++ /dev/null @@ -1,39 +0,0 @@ -/* getpagesize emulation for systems where it cannot be done in a C macro. - - Copyright (C) 2007 Free Software Foundation, Inc. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . */ - -/* Written by Bruno Haible and Martin Lambers. */ - -#include - -/* Specification. */ -#include - -/* This implementation is only for native Win32 systems. */ -#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - -# define WIN32_LEAN_AND_MEAN -# include - -int -getpagesize (void) -{ - SYSTEM_INFO system_info; - GetSystemInfo (&system_info); - return system_info.dwPageSize; -} - -#endif diff --git a/lib/glthread/lock.c b/lib/glthread/lock.c new file mode 100644 index 00000000..2f4de9f4 --- /dev/null +++ b/lib/glthread/lock.c @@ -0,0 +1,1058 @@ +/* Locking in multithreaded situations. + Copyright (C) 2005-2010 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h, + gthr-win32.h. */ + +#include + +#include "glthread/lock.h" + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +# if HAVE_PTHREAD_RWLOCK + +# if !defined PTHREAD_RWLOCK_INITIALIZER + +int +glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_rwlock_init (&lock->rwlock, NULL); + if (err != 0) + return err; + lock->initialized = 1; + return 0; +} + +int +glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) +{ + if (!lock->initialized) + { + int err; + + err = pthread_mutex_lock (&lock->guard); + if (err != 0) + return err; + if (!lock->initialized) + { + err = glthread_rwlock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } + err = pthread_mutex_unlock (&lock->guard); + if (err != 0) + return err; + } + return pthread_rwlock_rdlock (&lock->rwlock); +} + +int +glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) +{ + if (!lock->initialized) + { + int err; + + err = pthread_mutex_lock (&lock->guard); + if (err != 0) + return err; + if (!lock->initialized) + { + err = glthread_rwlock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } + err = pthread_mutex_unlock (&lock->guard); + if (err != 0) + return err; + } + return pthread_rwlock_wrlock (&lock->rwlock); +} + +int +glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) +{ + if (!lock->initialized) + return EINVAL; + return pthread_rwlock_unlock (&lock->rwlock); +} + +int +glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) +{ + int err; + + if (!lock->initialized) + return EINVAL; + err = pthread_rwlock_destroy (&lock->rwlock); + if (err != 0) + return err; + lock->initialized = 0; + return 0; +} + +# endif + +# else + +int +glthread_rwlock_init_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_init (&lock->lock, NULL); + if (err != 0) + return err; + err = pthread_cond_init (&lock->waiting_readers, NULL); + if (err != 0) + return err; + err = pthread_cond_init (&lock->waiting_writers, NULL); + if (err != 0) + return err; + lock->waiting_writers_count = 0; + lock->runcount = 0; + return 0; +} + +int +glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_lock (&lock->lock); + if (err != 0) + return err; + /* Test whether only readers are currently running, and whether the runcount + field will not overflow. */ + /* POSIX says: "It is implementation-defined whether the calling thread + acquires the lock when a writer does not hold the lock and there are + writers blocked on the lock." Let's say, no: give the writers a higher + priority. */ + while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_readers. */ + err = pthread_cond_wait (&lock->waiting_readers, &lock->lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } + lock->runcount++; + return pthread_mutex_unlock (&lock->lock); +} + +int +glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_lock (&lock->lock); + if (err != 0) + return err; + /* Test whether no readers or writers are currently running. */ + while (!(lock->runcount == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_writers. */ + lock->waiting_writers_count++; + err = pthread_cond_wait (&lock->waiting_writers, &lock->lock); + if (err != 0) + { + lock->waiting_writers_count--; + pthread_mutex_unlock (&lock->lock); + return err; + } + lock->waiting_writers_count--; + } + lock->runcount--; /* runcount becomes -1 */ + return pthread_mutex_unlock (&lock->lock); +} + +int +glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_lock (&lock->lock); + if (err != 0) + return err; + if (lock->runcount < 0) + { + /* Drop a writer lock. */ + if (!(lock->runcount == -1)) + { + pthread_mutex_unlock (&lock->lock); + return EINVAL; + } + lock->runcount = 0; + } + else + { + /* Drop a reader lock. */ + if (!(lock->runcount > 0)) + { + pthread_mutex_unlock (&lock->lock); + return EINVAL; + } + lock->runcount--; + } + if (lock->runcount == 0) + { + /* POSIX recommends that "write locks shall take precedence over read + locks", to avoid "writer starvation". */ + if (lock->waiting_writers_count > 0) + { + /* Wake up one of the waiting writers. */ + err = pthread_cond_signal (&lock->waiting_writers); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } + else + { + /* Wake up all waiting readers. */ + err = pthread_cond_broadcast (&lock->waiting_readers); + if (err != 0) + { + pthread_mutex_unlock (&lock->lock); + return err; + } + } + } + return pthread_mutex_unlock (&lock->lock); +} + +int +glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock) +{ + int err; + + err = pthread_mutex_destroy (&lock->lock); + if (err != 0) + return err; + err = pthread_cond_destroy (&lock->waiting_readers); + if (err != 0) + return err; + err = pthread_cond_destroy (&lock->waiting_writers); + if (err != 0) + return err; + return 0; +} + +# endif + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +# if HAVE_PTHREAD_MUTEX_RECURSIVE + +# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + pthread_mutexattr_t attributes; + int err; + + err = pthread_mutexattr_init (&attributes); + if (err != 0) + return err; + err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutex_init (lock, &attributes); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutexattr_destroy (&attributes); + if (err != 0) + return err; + return 0; +} + +# else + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + pthread_mutexattr_t attributes; + int err; + + err = pthread_mutexattr_init (&attributes); + if (err != 0) + return err; + err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutex_init (&lock->recmutex, &attributes); + if (err != 0) + { + pthread_mutexattr_destroy (&attributes); + return err; + } + err = pthread_mutexattr_destroy (&attributes); + if (err != 0) + return err; + lock->initialized = 1; + return 0; +} + +int +glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) +{ + if (!lock->initialized) + { + int err; + + err = pthread_mutex_lock (&lock->guard); + if (err != 0) + return err; + if (!lock->initialized) + { + err = glthread_recursive_lock_init_multithreaded (lock); + if (err != 0) + { + pthread_mutex_unlock (&lock->guard); + return err; + } + } + err = pthread_mutex_unlock (&lock->guard); + if (err != 0) + return err; + } + return pthread_mutex_lock (&lock->recmutex); +} + +int +glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) +{ + if (!lock->initialized) + return EINVAL; + return pthread_mutex_unlock (&lock->recmutex); +} + +int +glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) +{ + int err; + + if (!lock->initialized) + return EINVAL; + err = pthread_mutex_destroy (&lock->recmutex); + if (err != 0) + return err; + lock->initialized = 0; + return 0; +} + +# endif + +# else + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + int err; + + err = pthread_mutex_init (&lock->mutex, NULL); + if (err != 0) + return err; + lock->owner = (pthread_t) 0; + lock->depth = 0; + return 0; +} + +int +glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) +{ + pthread_t self = pthread_self (); + if (lock->owner != self) + { + int err; + + err = pthread_mutex_lock (&lock->mutex); + if (err != 0) + return err; + lock->owner = self; + } + if (++(lock->depth) == 0) /* wraparound? */ + { + lock->depth--; + return EAGAIN; + } + return 0; +} + +int +glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) +{ + if (lock->owner != pthread_self ()) + return EPERM; + if (lock->depth == 0) + return EINVAL; + if (--(lock->depth) == 0) + { + lock->owner = (pthread_t) 0; + return pthread_mutex_unlock (&lock->mutex); + } + else + return 0; +} + +int +glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) +{ + if (lock->owner != (pthread_t) 0) + return EBUSY; + return pthread_mutex_destroy (&lock->mutex); +} + +# endif + +/* -------------------------- gl_once_t datatype -------------------------- */ + +static const pthread_once_t fresh_once = PTHREAD_ONCE_INIT; + +int +glthread_once_singlethreaded (pthread_once_t *once_control) +{ + /* We don't know whether pthread_once_t is an integer type, a floating-point + type, a pointer type, or a structure type. */ + char *firstbyte = (char *)once_control; + if (*firstbyte == *(const char *)&fresh_once) + { + /* First time use of once_control. Invert the first byte. */ + *firstbyte = ~ *(const char *)&fresh_once; + return 1; + } + else + return 0; +} + +#endif + +/* ========================================================================= */ + +#if USE_PTH_THREADS + +/* Use the GNU Pth threads library. */ + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +/* -------------------------- gl_once_t datatype -------------------------- */ + +static void +glthread_once_call (void *arg) +{ + void (**gl_once_temp_addr) (void) = (void (**) (void)) arg; + void (*initfunction) (void) = *gl_once_temp_addr; + initfunction (); +} + +int +glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) (void)) +{ + void (*temp) (void) = initfunction; + return (!pth_once (once_control, glthread_once_call, &temp) ? errno : 0); +} + +int +glthread_once_singlethreaded (pth_once_t *once_control) +{ + /* We know that pth_once_t is an integer type. */ + if (*once_control == PTH_ONCE_INIT) + { + /* First time use of once_control. Invert the marker. */ + *once_control = ~ PTH_ONCE_INIT; + return 1; + } + else + return 0; +} + +#endif + +/* ========================================================================= */ + +#if USE_SOLARIS_THREADS + +/* Use the old Solaris threads library. */ + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +int +glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock) +{ + int err; + + err = mutex_init (&lock->mutex, USYNC_THREAD, NULL); + if (err != 0) + return err; + lock->owner = (thread_t) 0; + lock->depth = 0; + return 0; +} + +int +glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock) +{ + thread_t self = thr_self (); + if (lock->owner != self) + { + int err; + + err = mutex_lock (&lock->mutex); + if (err != 0) + return err; + lock->owner = self; + } + if (++(lock->depth) == 0) /* wraparound? */ + { + lock->depth--; + return EAGAIN; + } + return 0; +} + +int +glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock) +{ + if (lock->owner != thr_self ()) + return EPERM; + if (lock->depth == 0) + return EINVAL; + if (--(lock->depth) == 0) + { + lock->owner = (thread_t) 0; + return mutex_unlock (&lock->mutex); + } + else + return 0; +} + +int +glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock) +{ + if (lock->owner != (thread_t) 0) + return EBUSY; + return mutex_destroy (&lock->mutex); +} + +/* -------------------------- gl_once_t datatype -------------------------- */ + +int +glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void)) +{ + if (!once_control->inited) + { + int err; + + /* Use the mutex to guarantee that if another thread is already calling + the initfunction, this thread waits until it's finished. */ + err = mutex_lock (&once_control->mutex); + if (err != 0) + return err; + if (!once_control->inited) + { + once_control->inited = 1; + initfunction (); + } + return mutex_unlock (&once_control->mutex); + } + else + return 0; +} + +int +glthread_once_singlethreaded (gl_once_t *once_control) +{ + /* We know that gl_once_t contains an integer type. */ + if (!once_control->inited) + { + /* First time use of once_control. Invert the marker. */ + once_control->inited = ~ 0; + return 1; + } + else + return 0; +} + +#endif + +/* ========================================================================= */ + +#if USE_WIN32_THREADS + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +void +glthread_lock_init_func (gl_lock_t *lock) +{ + InitializeCriticalSection (&lock->lock); + lock->guard.done = 1; +} + +int +glthread_lock_lock_func (gl_lock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glthread_lock_init (lock); + else + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + EnterCriticalSection (&lock->lock); + return 0; +} + +int +glthread_lock_unlock_func (gl_lock_t *lock) +{ + if (!lock->guard.done) + return EINVAL; + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glthread_lock_destroy_func (gl_lock_t *lock) +{ + if (!lock->guard.done) + return EINVAL; + DeleteCriticalSection (&lock->lock); + lock->guard.done = 0; + return 0; +} + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +/* In this file, the waitqueues are implemented as circular arrays. */ +#define gl_waitqueue_t gl_carray_waitqueue_t + +static inline void +gl_waitqueue_init (gl_waitqueue_t *wq) +{ + wq->array = NULL; + wq->count = 0; + wq->alloc = 0; + wq->offset = 0; +} + +/* Enqueues the current thread, represented by an event, in a wait queue. + Returns INVALID_HANDLE_VALUE if an allocation failure occurs. */ +static HANDLE +gl_waitqueue_add (gl_waitqueue_t *wq) +{ + HANDLE event; + unsigned int index; + + if (wq->count == wq->alloc) + { + unsigned int new_alloc = 2 * wq->alloc + 1; + HANDLE *new_array = + (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE)); + if (new_array == NULL) + /* No more memory. */ + return INVALID_HANDLE_VALUE; + /* Now is a good opportunity to rotate the array so that its contents + starts at offset 0. */ + if (wq->offset > 0) + { + unsigned int old_count = wq->count; + unsigned int old_alloc = wq->alloc; + unsigned int old_offset = wq->offset; + unsigned int i; + if (old_offset + old_count > old_alloc) + { + unsigned int limit = old_offset + old_count - old_alloc; + for (i = 0; i < limit; i++) + new_array[old_alloc + i] = new_array[i]; + } + for (i = 0; i < old_count; i++) + new_array[i] = new_array[old_offset + i]; + wq->offset = 0; + } + wq->array = new_array; + wq->alloc = new_alloc; + } + /* Whether the created event is a manual-reset one or an auto-reset one, + does not matter, since we will wait on it only once. */ + event = CreateEvent (NULL, TRUE, FALSE, NULL); + if (event == INVALID_HANDLE_VALUE) + /* No way to allocate an event. */ + return INVALID_HANDLE_VALUE; + index = wq->offset + wq->count; + if (index >= wq->alloc) + index -= wq->alloc; + wq->array[index] = event; + wq->count++; + return event; +} + +/* Notifies the first thread from a wait queue and dequeues it. */ +static inline void +gl_waitqueue_notify_first (gl_waitqueue_t *wq) +{ + SetEvent (wq->array[wq->offset + 0]); + wq->offset++; + wq->count--; + if (wq->count == 0 || wq->offset == wq->alloc) + wq->offset = 0; +} + +/* Notifies all threads from a wait queue and dequeues them all. */ +static inline void +gl_waitqueue_notify_all (gl_waitqueue_t *wq) +{ + unsigned int i; + + for (i = 0; i < wq->count; i++) + { + unsigned int index = wq->offset + i; + if (index >= wq->alloc) + index -= wq->alloc; + SetEvent (wq->array[index]); + } + wq->count = 0; + wq->offset = 0; +} + +void +glthread_rwlock_init_func (gl_rwlock_t *lock) +{ + InitializeCriticalSection (&lock->lock); + gl_waitqueue_init (&lock->waiting_readers); + gl_waitqueue_init (&lock->waiting_writers); + lock->runcount = 0; + lock->guard.done = 1; +} + +int +glthread_rwlock_rdlock_func (gl_rwlock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glthread_rwlock_init (lock); + else + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + EnterCriticalSection (&lock->lock); + /* Test whether only readers are currently running, and whether the runcount + field will not overflow. */ + if (!(lock->runcount + 1 > 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_readers. */ + HANDLE event = gl_waitqueue_add (&lock->waiting_readers); + if (event != INVALID_HANDLE_VALUE) + { + DWORD result; + LeaveCriticalSection (&lock->lock); + /* Wait until another thread signals this event. */ + result = WaitForSingleObject (event, INFINITE); + if (result == WAIT_FAILED || result == WAIT_TIMEOUT) + abort (); + CloseHandle (event); + /* The thread which signalled the event already did the bookkeeping: + removed us from the waiting_readers, incremented lock->runcount. */ + if (!(lock->runcount > 0)) + abort (); + return 0; + } + else + { + /* Allocation failure. Weird. */ + do + { + LeaveCriticalSection (&lock->lock); + Sleep (1); + EnterCriticalSection (&lock->lock); + } + while (!(lock->runcount + 1 > 0)); + } + } + lock->runcount++; + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glthread_rwlock_wrlock_func (gl_rwlock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glthread_rwlock_init (lock); + else + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + EnterCriticalSection (&lock->lock); + /* Test whether no readers or writers are currently running. */ + if (!(lock->runcount == 0)) + { + /* This thread has to wait for a while. Enqueue it among the + waiting_writers. */ + HANDLE event = gl_waitqueue_add (&lock->waiting_writers); + if (event != INVALID_HANDLE_VALUE) + { + DWORD result; + LeaveCriticalSection (&lock->lock); + /* Wait until another thread signals this event. */ + result = WaitForSingleObject (event, INFINITE); + if (result == WAIT_FAILED || result == WAIT_TIMEOUT) + abort (); + CloseHandle (event); + /* The thread which signalled the event already did the bookkeeping: + removed us from the waiting_writers, set lock->runcount = -1. */ + if (!(lock->runcount == -1)) + abort (); + return 0; + } + else + { + /* Allocation failure. Weird. */ + do + { + LeaveCriticalSection (&lock->lock); + Sleep (1); + EnterCriticalSection (&lock->lock); + } + while (!(lock->runcount == 0)); + } + } + lock->runcount--; /* runcount becomes -1 */ + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glthread_rwlock_unlock_func (gl_rwlock_t *lock) +{ + if (!lock->guard.done) + return EINVAL; + EnterCriticalSection (&lock->lock); + if (lock->runcount < 0) + { + /* Drop a writer lock. */ + if (!(lock->runcount == -1)) + abort (); + lock->runcount = 0; + } + else + { + /* Drop a reader lock. */ + if (!(lock->runcount > 0)) + { + LeaveCriticalSection (&lock->lock); + return EPERM; + } + lock->runcount--; + } + if (lock->runcount == 0) + { + /* POSIX recommends that "write locks shall take precedence over read + locks", to avoid "writer starvation". */ + if (lock->waiting_writers.count > 0) + { + /* Wake up one of the waiting writers. */ + lock->runcount--; + gl_waitqueue_notify_first (&lock->waiting_writers); + } + else + { + /* Wake up all waiting readers. */ + lock->runcount += lock->waiting_readers.count; + gl_waitqueue_notify_all (&lock->waiting_readers); + } + } + LeaveCriticalSection (&lock->lock); + return 0; +} + +int +glthread_rwlock_destroy_func (gl_rwlock_t *lock) +{ + if (!lock->guard.done) + return EINVAL; + if (lock->runcount != 0) + return EBUSY; + DeleteCriticalSection (&lock->lock); + if (lock->waiting_readers.array != NULL) + free (lock->waiting_readers.array); + if (lock->waiting_writers.array != NULL) + free (lock->waiting_writers.array); + lock->guard.done = 0; + return 0; +} + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +void +glthread_recursive_lock_init_func (gl_recursive_lock_t *lock) +{ + lock->owner = 0; + lock->depth = 0; + InitializeCriticalSection (&lock->lock); + lock->guard.done = 1; +} + +int +glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock) +{ + if (!lock->guard.done) + { + if (InterlockedIncrement (&lock->guard.started) == 0) + /* This thread is the first one to need this lock. Initialize it. */ + glthread_recursive_lock_init (lock); + else + /* Yield the CPU while waiting for another thread to finish + initializing this lock. */ + while (!lock->guard.done) + Sleep (0); + } + { + DWORD self = GetCurrentThreadId (); + if (lock->owner != self) + { + EnterCriticalSection (&lock->lock); + lock->owner = self; + } + if (++(lock->depth) == 0) /* wraparound? */ + { + lock->depth--; + return EAGAIN; + } + } + return 0; +} + +int +glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock) +{ + if (lock->owner != GetCurrentThreadId ()) + return EPERM; + if (lock->depth == 0) + return EINVAL; + if (--(lock->depth) == 0) + { + lock->owner = 0; + LeaveCriticalSection (&lock->lock); + } + return 0; +} + +int +glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock) +{ + if (lock->owner != 0) + return EBUSY; + DeleteCriticalSection (&lock->lock); + lock->guard.done = 0; + return 0; +} + +/* -------------------------- gl_once_t datatype -------------------------- */ + +void +glthread_once_func (gl_once_t *once_control, void (*initfunction) (void)) +{ + if (once_control->inited <= 0) + { + if (InterlockedIncrement (&once_control->started) == 0) + { + /* This thread is the first one to come to this once_control. */ + InitializeCriticalSection (&once_control->lock); + EnterCriticalSection (&once_control->lock); + once_control->inited = 0; + initfunction (); + once_control->inited = 1; + LeaveCriticalSection (&once_control->lock); + } + else + { + /* Undo last operation. */ + InterlockedDecrement (&once_control->started); + /* Some other thread has already started the initialization. + Yield the CPU while waiting for the other thread to finish + initializing and taking the lock. */ + while (once_control->inited < 0) + Sleep (0); + if (once_control->inited <= 0) + { + /* Take the lock. This blocks until the other thread has + finished calling the initfunction. */ + EnterCriticalSection (&once_control->lock); + LeaveCriticalSection (&once_control->lock); + if (!(once_control->inited > 0)) + abort (); + } + } + } +} + +#endif + +/* ========================================================================= */ diff --git a/lib/glthread/lock.h b/lib/glthread/lock.h new file mode 100644 index 00000000..47ce7738 --- /dev/null +++ b/lib/glthread/lock.h @@ -0,0 +1,927 @@ +/* Locking in multithreaded situations. + Copyright (C) 2005-2010 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2005. + Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h, + gthr-win32.h. */ + +/* This file contains locking primitives for use with a given thread library. + It does not contain primitives for creating threads or for other + synchronization primitives. + + Normal (non-recursive) locks: + Type: gl_lock_t + Declaration: gl_lock_define(extern, name) + Initializer: gl_lock_define_initialized(, name) + Initialization: gl_lock_init (name); + Taking the lock: gl_lock_lock (name); + Releasing the lock: gl_lock_unlock (name); + De-initialization: gl_lock_destroy (name); + Equivalent functions with control of error handling: + Initialization: err = glthread_lock_init (&name); + Taking the lock: err = glthread_lock_lock (&name); + Releasing the lock: err = glthread_lock_unlock (&name); + De-initialization: err = glthread_lock_destroy (&name); + + Read-Write (non-recursive) locks: + Type: gl_rwlock_t + Declaration: gl_rwlock_define(extern, name) + Initializer: gl_rwlock_define_initialized(, name) + Initialization: gl_rwlock_init (name); + Taking the lock: gl_rwlock_rdlock (name); + gl_rwlock_wrlock (name); + Releasing the lock: gl_rwlock_unlock (name); + De-initialization: gl_rwlock_destroy (name); + Equivalent functions with control of error handling: + Initialization: err = glthread_rwlock_init (&name); + Taking the lock: err = glthread_rwlock_rdlock (&name); + err = glthread_rwlock_wrlock (&name); + Releasing the lock: err = glthread_rwlock_unlock (&name); + De-initialization: err = glthread_rwlock_destroy (&name); + + Recursive locks: + Type: gl_recursive_lock_t + Declaration: gl_recursive_lock_define(extern, name) + Initializer: gl_recursive_lock_define_initialized(, name) + Initialization: gl_recursive_lock_init (name); + Taking the lock: gl_recursive_lock_lock (name); + Releasing the lock: gl_recursive_lock_unlock (name); + De-initialization: gl_recursive_lock_destroy (name); + Equivalent functions with control of error handling: + Initialization: err = glthread_recursive_lock_init (&name); + Taking the lock: err = glthread_recursive_lock_lock (&name); + Releasing the lock: err = glthread_recursive_lock_unlock (&name); + De-initialization: err = glthread_recursive_lock_destroy (&name); + + Once-only execution: + Type: gl_once_t + Initializer: gl_once_define(extern, name) + Execution: gl_once (name, initfunction); + Equivalent functions with control of error handling: + Execution: err = glthread_once (&name, initfunction); +*/ + + +#ifndef _LOCK_H +#define _LOCK_H + +#include +#include + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +/* Use the POSIX threads library. */ + +# include + +# ifdef __cplusplus +extern "C" { +# endif + +# if PTHREAD_IN_USE_DETECTION_HARD + +/* The pthread_in_use() detection needs to be done at runtime. */ +# define pthread_in_use() \ + glthread_in_use () +extern int glthread_in_use (void); + +# endif + +# if USE_POSIX_THREADS_WEAK + +/* Use weak references to the POSIX threads library. */ + +/* Weak references avoid dragging in external libraries if the other parts + of the program don't use them. Here we use them, because we don't want + every program that uses libintl to depend on libpthread. This assumes + that libpthread would not be loaded after libintl; i.e. if libintl is + loaded first, by an executable that does not depend on libpthread, and + then a module is dynamically loaded that depends on libpthread, libintl + will not be multithread-safe. */ + +/* The way to test at runtime whether libpthread is present is to test + whether a function pointer's value, such as &pthread_mutex_init, is + non-NULL. However, some versions of GCC have a bug through which, in + PIC mode, &foo != NULL always evaluates to true if there is a direct + call to foo(...) in the same function. To avoid this, we test the + address of a function in libpthread that we don't use. */ + +# pragma weak pthread_mutex_init +# pragma weak pthread_mutex_lock +# pragma weak pthread_mutex_unlock +# pragma weak pthread_mutex_destroy +# pragma weak pthread_rwlock_init +# pragma weak pthread_rwlock_rdlock +# pragma weak pthread_rwlock_wrlock +# pragma weak pthread_rwlock_unlock +# pragma weak pthread_rwlock_destroy +# pragma weak pthread_once +# pragma weak pthread_cond_init +# pragma weak pthread_cond_wait +# pragma weak pthread_cond_signal +# pragma weak pthread_cond_broadcast +# pragma weak pthread_cond_destroy +# pragma weak pthread_mutexattr_init +# pragma weak pthread_mutexattr_settype +# pragma weak pthread_mutexattr_destroy +# ifndef pthread_self +# pragma weak pthread_self +# endif + +# if !PTHREAD_IN_USE_DETECTION_HARD +# pragma weak pthread_cancel +# define pthread_in_use() (pthread_cancel != NULL) +# endif + +# else + +# if !PTHREAD_IN_USE_DETECTION_HARD +# define pthread_in_use() 1 +# endif + +# endif + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef pthread_mutex_t gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS pthread_mutex_t NAME; +# define gl_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS pthread_mutex_t NAME = gl_lock_initializer; +# define gl_lock_initializer \ + PTHREAD_MUTEX_INITIALIZER +# define glthread_lock_init(LOCK) \ + (pthread_in_use () ? pthread_mutex_init (LOCK, NULL) : 0) +# define glthread_lock_lock(LOCK) \ + (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0) +# define glthread_lock_unlock(LOCK) \ + (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0) +# define glthread_lock_destroy(LOCK) \ + (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0) + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +# if HAVE_PTHREAD_RWLOCK + +# ifdef PTHREAD_RWLOCK_INITIALIZER + +typedef pthread_rwlock_t gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS pthread_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS pthread_rwlock_t NAME = gl_rwlock_initializer; +# define gl_rwlock_initializer \ + PTHREAD_RWLOCK_INITIALIZER +# define glthread_rwlock_init(LOCK) \ + (pthread_in_use () ? pthread_rwlock_init (LOCK, NULL) : 0) +# define glthread_rwlock_rdlock(LOCK) \ + (pthread_in_use () ? pthread_rwlock_rdlock (LOCK) : 0) +# define glthread_rwlock_wrlock(LOCK) \ + (pthread_in_use () ? pthread_rwlock_wrlock (LOCK) : 0) +# define glthread_rwlock_unlock(LOCK) \ + (pthread_in_use () ? pthread_rwlock_unlock (LOCK) : 0) +# define glthread_rwlock_destroy(LOCK) \ + (pthread_in_use () ? pthread_rwlock_destroy (LOCK) : 0) + +# else + +typedef struct + { + int initialized; + pthread_mutex_t guard; /* protects the initialization */ + pthread_rwlock_t rwlock; /* read-write lock */ + } + gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; +# define gl_rwlock_initializer \ + { 0, PTHREAD_MUTEX_INITIALIZER } +# define glthread_rwlock_init(LOCK) \ + (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0) +# define glthread_rwlock_rdlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_wrlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_unlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_destroy(LOCK) \ + (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0) +extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock); + +# endif + +# else + +typedef struct + { + pthread_mutex_t lock; /* protects the remaining fields */ + pthread_cond_t waiting_readers; /* waiting readers */ + pthread_cond_t waiting_writers; /* waiting writers */ + unsigned int waiting_writers_count; /* number of waiting writers */ + int runcount; /* number of readers running, or -1 when a writer runs */ + } + gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; +# define gl_rwlock_initializer \ + { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, 0 } +# define glthread_rwlock_init(LOCK) \ + (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0) +# define glthread_rwlock_rdlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_wrlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_unlock(LOCK) \ + (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0) +# define glthread_rwlock_destroy(LOCK) \ + (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0) +extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock); +extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock); + +# endif + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +# if HAVE_PTHREAD_MUTEX_RECURSIVE + +# if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP + +typedef pthread_mutex_t gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS pthread_mutex_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS pthread_mutex_t NAME = gl_recursive_lock_initializer; +# ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER +# define gl_recursive_lock_initializer \ + PTHREAD_RECURSIVE_MUTEX_INITIALIZER +# else +# define gl_recursive_lock_initializer \ + PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP +# endif +# define glthread_recursive_lock_init(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_lock(LOCK) \ + (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0) +# define glthread_recursive_lock_unlock(LOCK) \ + (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0) +# define glthread_recursive_lock_destroy(LOCK) \ + (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0) +extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); + +# else + +typedef struct + { + pthread_mutex_t recmutex; /* recursive mutex */ + pthread_mutex_t guard; /* protects the initialization */ + int initialized; + } + gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; +# define gl_recursive_lock_initializer \ + { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, 0 } +# define glthread_recursive_lock_init(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_lock(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_unlock(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_destroy(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0) +extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock); + +# endif + +# else + +/* Old versions of POSIX threads on Solaris did not have recursive locks. + We have to implement them ourselves. */ + +typedef struct + { + pthread_mutex_t mutex; + pthread_t owner; + unsigned long depth; + } + gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; +# define gl_recursive_lock_initializer \ + { PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0, 0 } +# define glthread_recursive_lock_init(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_lock(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_unlock(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_destroy(LOCK) \ + (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0) +extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock); + +# endif + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef pthread_once_t gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT; +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (pthread_in_use () \ + ? pthread_once (ONCE_CONTROL, INITFUNCTION) \ + : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0)) +extern int glthread_once_singlethreaded (pthread_once_t *once_control); + +# ifdef __cplusplus +} +# endif + +#endif + +/* ========================================================================= */ + +#if USE_PTH_THREADS + +/* Use the GNU Pth threads library. */ + +# include + +# ifdef __cplusplus +extern "C" { +# endif + +# if USE_PTH_THREADS_WEAK + +/* Use weak references to the GNU Pth threads library. */ + +# pragma weak pth_mutex_init +# pragma weak pth_mutex_acquire +# pragma weak pth_mutex_release +# pragma weak pth_rwlock_init +# pragma weak pth_rwlock_acquire +# pragma weak pth_rwlock_release +# pragma weak pth_once + +# pragma weak pth_cancel +# define pth_in_use() (pth_cancel != NULL) + +# else + +# define pth_in_use() 1 + +# endif + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef pth_mutex_t gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS pth_mutex_t NAME; +# define gl_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS pth_mutex_t NAME = gl_lock_initializer; +# define gl_lock_initializer \ + PTH_MUTEX_INIT +# define glthread_lock_init(LOCK) \ + (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0) +# define glthread_lock_lock(LOCK) \ + (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0) +# define glthread_lock_unlock(LOCK) \ + (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0) +# define glthread_lock_destroy(LOCK) \ + ((void)(LOCK), 0) + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +typedef pth_rwlock_t gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS pth_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS pth_rwlock_t NAME = gl_rwlock_initializer; +# define gl_rwlock_initializer \ + PTH_RWLOCK_INIT +# define glthread_rwlock_init(LOCK) \ + (pth_in_use () && !pth_rwlock_init (LOCK) ? errno : 0) +# define glthread_rwlock_rdlock(LOCK) \ + (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RD, 0, NULL) ? errno : 0) +# define glthread_rwlock_wrlock(LOCK) \ + (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RW, 0, NULL) ? errno : 0) +# define glthread_rwlock_unlock(LOCK) \ + (pth_in_use () && !pth_rwlock_release (LOCK) ? errno : 0) +# define glthread_rwlock_destroy(LOCK) \ + ((void)(LOCK), 0) + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +/* In Pth, mutexes are recursive by default. */ +typedef pth_mutex_t gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS pth_mutex_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS pth_mutex_t NAME = gl_recursive_lock_initializer; +# define gl_recursive_lock_initializer \ + PTH_MUTEX_INIT +# define glthread_recursive_lock_init(LOCK) \ + (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0) +# define glthread_recursive_lock_lock(LOCK) \ + (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0) +# define glthread_recursive_lock_unlock(LOCK) \ + (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0) +# define glthread_recursive_lock_destroy(LOCK) \ + ((void)(LOCK), 0) + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef pth_once_t gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS pth_once_t NAME = PTH_ONCE_INIT; +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (pth_in_use () \ + ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \ + : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0)) +extern int glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) (void)); +extern int glthread_once_singlethreaded (pth_once_t *once_control); + +# ifdef __cplusplus +} +# endif + +#endif + +/* ========================================================================= */ + +#if USE_SOLARIS_THREADS + +/* Use the old Solaris threads library. */ + +# include +# include + +# ifdef __cplusplus +extern "C" { +# endif + +# if USE_SOLARIS_THREADS_WEAK + +/* Use weak references to the old Solaris threads library. */ + +# pragma weak mutex_init +# pragma weak mutex_lock +# pragma weak mutex_unlock +# pragma weak mutex_destroy +# pragma weak rwlock_init +# pragma weak rw_rdlock +# pragma weak rw_wrlock +# pragma weak rw_unlock +# pragma weak rwlock_destroy +# pragma weak thr_self + +# pragma weak thr_suspend +# define thread_in_use() (thr_suspend != NULL) + +# else + +# define thread_in_use() 1 + +# endif + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef mutex_t gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS mutex_t NAME; +# define gl_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS mutex_t NAME = gl_lock_initializer; +# define gl_lock_initializer \ + DEFAULTMUTEX +# define glthread_lock_init(LOCK) \ + (thread_in_use () ? mutex_init (LOCK, USYNC_THREAD, NULL) : 0) +# define glthread_lock_lock(LOCK) \ + (thread_in_use () ? mutex_lock (LOCK) : 0) +# define glthread_lock_unlock(LOCK) \ + (thread_in_use () ? mutex_unlock (LOCK) : 0) +# define glthread_lock_destroy(LOCK) \ + (thread_in_use () ? mutex_destroy (LOCK) : 0) + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +typedef rwlock_t gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS rwlock_t NAME = gl_rwlock_initializer; +# define gl_rwlock_initializer \ + DEFAULTRWLOCK +# define glthread_rwlock_init(LOCK) \ + (thread_in_use () ? rwlock_init (LOCK, USYNC_THREAD, NULL) : 0) +# define glthread_rwlock_rdlock(LOCK) \ + (thread_in_use () ? rw_rdlock (LOCK) : 0) +# define glthread_rwlock_wrlock(LOCK) \ + (thread_in_use () ? rw_wrlock (LOCK) : 0) +# define glthread_rwlock_unlock(LOCK) \ + (thread_in_use () ? rw_unlock (LOCK) : 0) +# define glthread_rwlock_destroy(LOCK) \ + (thread_in_use () ? rwlock_destroy (LOCK) : 0) + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +/* Old Solaris threads did not have recursive locks. + We have to implement them ourselves. */ + +typedef struct + { + mutex_t mutex; + thread_t owner; + unsigned long depth; + } + gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; +# define gl_recursive_lock_initializer \ + { DEFAULTMUTEX, (thread_t) 0, 0 } +# define glthread_recursive_lock_init(LOCK) \ + (thread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_lock(LOCK) \ + (thread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_unlock(LOCK) \ + (thread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 0) +# define glthread_recursive_lock_destroy(LOCK) \ + (thread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 0) +extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock); + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef struct + { + volatile int inited; + mutex_t mutex; + } + gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_once_t NAME = { 0, DEFAULTMUTEX }; +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (thread_in_use () \ + ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION) \ + : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 0)) +extern int glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) (void)); +extern int glthread_once_singlethreaded (gl_once_t *once_control); + +# ifdef __cplusplus +} +# endif + +#endif + +/* ========================================================================= */ + +#if USE_WIN32_THREADS + +# include + +# ifdef __cplusplus +extern "C" { +# endif + +/* We can use CRITICAL_SECTION directly, rather than the Win32 Event, Mutex, + Semaphore types, because + - we need only to synchronize inside a single process (address space), + not inter-process locking, + - we don't need to support trylock operations. (TryEnterCriticalSection + does not work on Windows 95/98/ME. Packages that need trylock usually + define their own mutex type.) */ + +/* There is no way to statically initialize a CRITICAL_SECTION. It needs + to be done lazily, once only. For this we need spinlocks. */ + +typedef struct { volatile int done; volatile long started; } gl_spinlock_t; + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef struct + { + gl_spinlock_t guard; /* protects the initialization */ + CRITICAL_SECTION lock; + } + gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_lock_t NAME; +# define gl_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_lock_t NAME = gl_lock_initializer; +# define gl_lock_initializer \ + { { 0, -1 } } +# define glthread_lock_init(LOCK) \ + (glthread_lock_init_func (LOCK), 0) +# define glthread_lock_lock(LOCK) \ + glthread_lock_lock_func (LOCK) +# define glthread_lock_unlock(LOCK) \ + glthread_lock_unlock_func (LOCK) +# define glthread_lock_destroy(LOCK) \ + glthread_lock_destroy_func (LOCK) +extern void glthread_lock_init_func (gl_lock_t *lock); +extern int glthread_lock_lock_func (gl_lock_t *lock); +extern int glthread_lock_unlock_func (gl_lock_t *lock); +extern int glthread_lock_destroy_func (gl_lock_t *lock); + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +/* It is impossible to implement read-write locks using plain locks, without + introducing an extra thread dedicated to managing read-write locks. + Therefore here we need to use the low-level Event type. */ + +typedef struct + { + HANDLE *array; /* array of waiting threads, each represented by an event */ + unsigned int count; /* number of waiting threads */ + unsigned int alloc; /* length of allocated array */ + unsigned int offset; /* index of first waiting thread in array */ + } + gl_carray_waitqueue_t; +typedef struct + { + gl_spinlock_t guard; /* protects the initialization */ + CRITICAL_SECTION lock; /* protects the remaining fields */ + gl_carray_waitqueue_t waiting_readers; /* waiting readers */ + gl_carray_waitqueue_t waiting_writers; /* waiting writers */ + int runcount; /* number of readers running, or -1 when a writer runs */ + } + gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME; +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer; +# define gl_rwlock_initializer \ + { { 0, -1 } } +# define glthread_rwlock_init(LOCK) \ + (glthread_rwlock_init_func (LOCK), 0) +# define glthread_rwlock_rdlock(LOCK) \ + glthread_rwlock_rdlock_func (LOCK) +# define glthread_rwlock_wrlock(LOCK) \ + glthread_rwlock_wrlock_func (LOCK) +# define glthread_rwlock_unlock(LOCK) \ + glthread_rwlock_unlock_func (LOCK) +# define glthread_rwlock_destroy(LOCK) \ + glthread_rwlock_destroy_func (LOCK) +extern void glthread_rwlock_init_func (gl_rwlock_t *lock); +extern int glthread_rwlock_rdlock_func (gl_rwlock_t *lock); +extern int glthread_rwlock_wrlock_func (gl_rwlock_t *lock); +extern int glthread_rwlock_unlock_func (gl_rwlock_t *lock); +extern int glthread_rwlock_destroy_func (gl_rwlock_t *lock); + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +/* The Win32 documentation says that CRITICAL_SECTION already implements a + recursive lock. But we need not rely on it: It's easy to implement a + recursive lock without this assumption. */ + +typedef struct + { + gl_spinlock_t guard; /* protects the initialization */ + DWORD owner; + unsigned long depth; + CRITICAL_SECTION lock; + } + gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME; +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \ + STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer; +# define gl_recursive_lock_initializer \ + { { 0, -1 }, 0, 0 } +# define glthread_recursive_lock_init(LOCK) \ + (glthread_recursive_lock_init_func (LOCK), 0) +# define glthread_recursive_lock_lock(LOCK) \ + glthread_recursive_lock_lock_func (LOCK) +# define glthread_recursive_lock_unlock(LOCK) \ + glthread_recursive_lock_unlock_func (LOCK) +# define glthread_recursive_lock_destroy(LOCK) \ + glthread_recursive_lock_destroy_func (LOCK) +extern void glthread_recursive_lock_init_func (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock); +extern int glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock); + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef struct + { + volatile int inited; + volatile long started; + CRITICAL_SECTION lock; + } + gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_once_t NAME = { -1, -1 }; +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (glthread_once_func (ONCE_CONTROL, INITFUNCTION), 0) +extern void glthread_once_func (gl_once_t *once_control, void (*initfunction) (void)); + +# ifdef __cplusplus +} +# endif + +#endif + +/* ========================================================================= */ + +#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || USE_WIN32_THREADS) + +/* Provide dummy implementation if threads are not supported. */ + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +typedef int gl_lock_t; +# define gl_lock_define(STORAGECLASS, NAME) +# define gl_lock_define_initialized(STORAGECLASS, NAME) +# define glthread_lock_init(NAME) 0 +# define glthread_lock_lock(NAME) 0 +# define glthread_lock_unlock(NAME) 0 +# define glthread_lock_destroy(NAME) 0 + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +typedef int gl_rwlock_t; +# define gl_rwlock_define(STORAGECLASS, NAME) +# define gl_rwlock_define_initialized(STORAGECLASS, NAME) +# define glthread_rwlock_init(NAME) 0 +# define glthread_rwlock_rdlock(NAME) 0 +# define glthread_rwlock_wrlock(NAME) 0 +# define glthread_rwlock_unlock(NAME) 0 +# define glthread_rwlock_destroy(NAME) 0 + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +typedef int gl_recursive_lock_t; +# define gl_recursive_lock_define(STORAGECLASS, NAME) +# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) +# define glthread_recursive_lock_init(NAME) 0 +# define glthread_recursive_lock_lock(NAME) 0 +# define glthread_recursive_lock_unlock(NAME) 0 +# define glthread_recursive_lock_destroy(NAME) 0 + +/* -------------------------- gl_once_t datatype -------------------------- */ + +typedef int gl_once_t; +# define gl_once_define(STORAGECLASS, NAME) \ + STORAGECLASS gl_once_t NAME = 0; +# define glthread_once(ONCE_CONTROL, INITFUNCTION) \ + (*(ONCE_CONTROL) == 0 ? (*(ONCE_CONTROL) = ~ 0, INITFUNCTION (), 0) : 0) + +#endif + +/* ========================================================================= */ + +/* Macros with built-in error handling. */ + +/* -------------------------- gl_lock_t datatype -------------------------- */ + +#define gl_lock_init(NAME) \ + do \ + { \ + if (glthread_lock_init (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_lock_lock(NAME) \ + do \ + { \ + if (glthread_lock_lock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_lock_unlock(NAME) \ + do \ + { \ + if (glthread_lock_unlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_lock_destroy(NAME) \ + do \ + { \ + if (glthread_lock_destroy (&NAME)) \ + abort (); \ + } \ + while (0) + +/* ------------------------- gl_rwlock_t datatype ------------------------- */ + +#define gl_rwlock_init(NAME) \ + do \ + { \ + if (glthread_rwlock_init (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_rwlock_rdlock(NAME) \ + do \ + { \ + if (glthread_rwlock_rdlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_rwlock_wrlock(NAME) \ + do \ + { \ + if (glthread_rwlock_wrlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_rwlock_unlock(NAME) \ + do \ + { \ + if (glthread_rwlock_unlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_rwlock_destroy(NAME) \ + do \ + { \ + if (glthread_rwlock_destroy (&NAME)) \ + abort (); \ + } \ + while (0) + +/* --------------------- gl_recursive_lock_t datatype --------------------- */ + +#define gl_recursive_lock_init(NAME) \ + do \ + { \ + if (glthread_recursive_lock_init (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_recursive_lock_lock(NAME) \ + do \ + { \ + if (glthread_recursive_lock_lock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_recursive_lock_unlock(NAME) \ + do \ + { \ + if (glthread_recursive_lock_unlock (&NAME)) \ + abort (); \ + } \ + while (0) +#define gl_recursive_lock_destroy(NAME) \ + do \ + { \ + if (glthread_recursive_lock_destroy (&NAME)) \ + abort (); \ + } \ + while (0) + +/* -------------------------- gl_once_t datatype -------------------------- */ + +#define gl_once(NAME, INITFUNCTION) \ + do \ + { \ + if (glthread_once (&NAME, INITFUNCTION)) \ + abort (); \ + } \ + while (0) + +/* ========================================================================= */ + +#endif /* _LOCK_H */ diff --git a/lib/glthread/threadlib.c b/lib/glthread/threadlib.c new file mode 100644 index 00000000..8cb1bb21 --- /dev/null +++ b/lib/glthread/threadlib.c @@ -0,0 +1,74 @@ +/* Multithreading primitives. + Copyright (C) 2005-2010 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2005. */ + +#include + +/* ========================================================================= */ + +#if USE_POSIX_THREADS + +/* Use the POSIX threads library. */ + +# include +# include + +# if PTHREAD_IN_USE_DETECTION_HARD + +/* The function to be executed by a dummy thread. */ +static void * +dummy_thread_func (void *arg) +{ + return arg; +} + +int +glthread_in_use (void) +{ + static int tested; + static int result; /* 1: linked with -lpthread, 0: only with libc */ + + if (!tested) + { + pthread_t thread; + + if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0) + /* Thread creation failed. */ + result = 0; + else + { + /* Thread creation works. */ + void *retval; + if (pthread_join (thread, &retval) != 0) + abort (); + result = 1; + } + tested = 1; + } + return result; +} + +# endif + +#endif + +/* ========================================================================= */ + +/* This declaration is solely to ensure that after preprocessing + this file is never empty. */ +typedef int dummy; diff --git a/lib/iconv.in.h b/lib/iconv.in.h index 915dce2e..5512c607 100644 --- a/lib/iconv.in.h +++ b/lib/iconv.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -28,17 +28,29 @@ #ifndef _GL_ICONV_H #define _GL_ICONV_H -#ifdef __cplusplus -extern "C" { -#endif +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ #if @REPLACE_ICONV_OPEN@ /* An iconv_open wrapper that supports the IANA standardized encoding names ("ISO-8859-1" etc.) as far as possible. */ -# define iconv_open rpl_iconv_open -extern iconv_t iconv_open (const char *tocode, const char *fromcode); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define iconv_open rpl_iconv_open +# endif +_GL_FUNCDECL_RPL (iconv_open, iconv_t, + (const char *tocode, const char *fromcode) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (iconv_open, iconv_t, + (const char *tocode, const char *fromcode)); +#else +_GL_CXXALIAS_SYS (iconv_open, iconv_t, + (const char *tocode, const char *fromcode)); #endif +_GL_CXXALIASWARN (iconv_open); #if @REPLACE_ICONV_UTF@ /* Special constants for supporting UTF-{16,32}{BE,LE} encodings. @@ -54,18 +66,36 @@ extern iconv_t iconv_open (const char *tocode, const char *fromcode); #endif #if @REPLACE_ICONV@ -# define iconv rpl_iconv -extern size_t iconv (iconv_t cd, - @ICONV_CONST@ char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft); -# define iconv_close rpl_iconv_close -extern int iconv_close (iconv_t cd); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define iconv rpl_iconv +# endif +_GL_FUNCDECL_RPL (iconv, size_t, + (iconv_t cd, + @ICONV_CONST@ char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft)); +_GL_CXXALIAS_RPL (iconv, size_t, + (iconv_t cd, + @ICONV_CONST@ char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft)); +#else +_GL_CXXALIAS_SYS (iconv, size_t, + (iconv_t cd, + @ICONV_CONST@ char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft)); #endif +_GL_CXXALIASWARN (iconv); - -#ifdef __cplusplus -} +#if @REPLACE_ICONV@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define iconv_close rpl_iconv_close +# endif +_GL_FUNCDECL_RPL (iconv_close, int, (iconv_t cd)); +_GL_CXXALIAS_RPL (iconv_close, int, (iconv_t cd)); +#else +_GL_CXXALIAS_SYS (iconv_close, int, (iconv_t cd)); #endif +_GL_CXXALIASWARN (iconv_close); + #endif /* _GL_ICONV_H */ #endif /* _GL_ICONV_H */ diff --git a/lib/iconv_open-solaris.gperf b/lib/iconv_open-solaris.gperf new file mode 100644 index 00000000..7d7da38e --- /dev/null +++ b/lib/iconv_open-solaris.gperf @@ -0,0 +1,30 @@ +struct mapping { int standard_name; const char vendor_name[10 + 1]; }; +%struct-type +%language=ANSI-C +%define slot-name standard_name +%define hash-function-name mapping_hash +%define lookup-function-name mapping_lookup +%readonly-tables +%global-table +%define word-array-name mappings +%pic +%% +# On Solaris 10, look in the "iconv -l" output. Some aliases are advertised but +# not actually supported by the iconv() function and by the 'iconv' program. +# For example: +# $ echo abc | iconv -f 646 -t ISO-8859-1 +# Not supported 646 to ISO-8859-1 +# $ echo abc | iconv -f 646 -t ISO8859-1 +$ abc +ASCII, "646" +ISO-8859-1, "ISO8859-1" +ISO-8859-2, "ISO8859-2" +ISO-8859-3, "ISO8859-3" +ISO-8859-4, "ISO8859-4" +ISO-8859-5, "ISO8859-5" +ISO-8859-6, "ISO8859-6" +ISO-8859-7, "ISO8859-7" +ISO-8859-8, "ISO8859-8" +ISO-8859-9, "ISO8859-9" +ISO-8859-15, "ISO8859-15" +CP1251, "ansi-1251" diff --git a/lib/iconv_open-solaris.h b/lib/iconv_open-solaris.h new file mode 100644 index 00000000..630cde16 --- /dev/null +++ b/lib/iconv_open-solaris.h @@ -0,0 +1,190 @@ +/* ANSI-C code produced by gperf version 3.0.4 */ +/* Command-line: gperf -m 10 ./iconv_open-solaris.gperf */ +/* Computed positions: -k'10' */ + +#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ + && (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \ + && ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \ + && ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \ + && ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \ + && ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \ + && ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \ + && ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \ + && ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \ + && ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \ + && ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \ + && ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \ + && ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \ + && ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \ + && ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \ + && ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \ + && ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \ + && ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \ + && ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \ + && ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \ + && ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \ + && ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)) +/* The character set is not based on ISO-646. */ +#error "gperf generated tables don't work with this execution character set. Please report a bug to ." +#endif + +#line 1 "./iconv_open-solaris.gperf" +struct mapping { int standard_name; const char vendor_name[10 + 1]; }; + +#define TOTAL_KEYWORDS 13 +#define MIN_WORD_LENGTH 5 +#define MAX_WORD_LENGTH 11 +#define MIN_HASH_VALUE 5 +#define MAX_HASH_VALUE 19 +/* maximum key range = 15, duplicates = 0 */ + +#ifdef __GNUC__ +__inline +#else +#ifdef __cplusplus +inline +#endif +#endif +static unsigned int +mapping_hash (register const char *str, register unsigned int len) +{ + static const unsigned char asso_values[] = + { + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, + 9, 8, 7, 6, 5, 4, 3, 2, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20 + }; + register int hval = len; + + switch (hval) + { + default: + hval += asso_values[(unsigned char)str[9]]; + /*FALLTHROUGH*/ + case 9: + case 8: + case 7: + case 6: + case 5: + break; + } + return hval; +} + +struct stringpool_t + { + char stringpool_str5[sizeof("ASCII")]; + char stringpool_str6[sizeof("CP1251")]; + char stringpool_str7[sizeof("$ abc")]; + char stringpool_str10[sizeof("ISO-8859-1")]; + char stringpool_str11[sizeof("ISO-8859-15")]; + char stringpool_str12[sizeof("ISO-8859-9")]; + char stringpool_str13[sizeof("ISO-8859-8")]; + char stringpool_str14[sizeof("ISO-8859-7")]; + char stringpool_str15[sizeof("ISO-8859-6")]; + char stringpool_str16[sizeof("ISO-8859-5")]; + char stringpool_str17[sizeof("ISO-8859-4")]; + char stringpool_str18[sizeof("ISO-8859-3")]; + char stringpool_str19[sizeof("ISO-8859-2")]; + }; +static const struct stringpool_t stringpool_contents = + { + "ASCII", + "CP1251", + "$ abc", + "ISO-8859-1", + "ISO-8859-15", + "ISO-8859-9", + "ISO-8859-8", + "ISO-8859-7", + "ISO-8859-6", + "ISO-8859-5", + "ISO-8859-4", + "ISO-8859-3", + "ISO-8859-2" + }; +#define stringpool ((const char *) &stringpool_contents) + +static const struct mapping mappings[] = + { + {-1}, {-1}, {-1}, {-1}, {-1}, +#line 19 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str5, "646"}, +#line 30 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str6, "ansi-1251"}, +#line 18 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str7}, + {-1}, {-1}, +#line 20 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str10, "ISO8859-1"}, +#line 29 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str11, "ISO8859-15"}, +#line 28 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str12, "ISO8859-9"}, +#line 27 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str13, "ISO8859-8"}, +#line 26 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str14, "ISO8859-7"}, +#line 25 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str15, "ISO8859-6"}, +#line 24 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str16, "ISO8859-5"}, +#line 23 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str17, "ISO8859-4"}, +#line 22 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str18, "ISO8859-3"}, +#line 21 "./iconv_open-solaris.gperf" + {(int)(long)&((struct stringpool_t *)0)->stringpool_str19, "ISO8859-2"} + }; + +#ifdef __GNUC__ +__inline +#if defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__ +__attribute__ ((__gnu_inline__)) +#endif +#endif +const struct mapping * +mapping_lookup (register const char *str, register unsigned int len) +{ + if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) + { + register int key = mapping_hash (str, len); + + if (key <= MAX_HASH_VALUE && key >= 0) + { + register int o = mappings[key].standard_name; + if (o >= 0) + { + register const char *s = o + stringpool; + + if (*str == *s && !strcmp (str + 1, s + 1)) + return &mappings[key]; + } + } + } + return 0; +} diff --git a/lib/iconv_open.c b/lib/iconv_open.c index 3d873acd..1d1c0536 100644 --- a/lib/iconv_open.c +++ b/lib/iconv_open.c @@ -1,5 +1,5 @@ /* Character set conversion. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -36,6 +36,7 @@ #define ICONV_FLAVOR_HPUX "iconv_open-hpux.h" #define ICONV_FLAVOR_IRIX "iconv_open-irix.h" #define ICONV_FLAVOR_OSF "iconv_open-osf.h" +#define ICONV_FLAVOR_SOLARIS "iconv_open-solaris.h" #ifdef ICONV_FLAVOR # include ICONV_FLAVOR @@ -66,33 +67,33 @@ rpl_iconv_open (const char *tocode, const char *fromcode) && fromcode[3] == '-') { if (c_toupper (tocode[0]) == 'U' - && c_toupper (tocode[1]) == 'T' - && c_toupper (tocode[2]) == 'F' - && tocode[3] == '-') - { - if (strcmp (fromcode + 4, "8") == 0) - { - if (c_strcasecmp (tocode + 4, "16BE") == 0) - return _ICONV_UTF8_UTF16BE; - if (c_strcasecmp (tocode + 4, "16LE") == 0) - return _ICONV_UTF8_UTF16LE; - if (c_strcasecmp (tocode + 4, "32BE") == 0) - return _ICONV_UTF8_UTF32BE; - if (c_strcasecmp (tocode + 4, "32LE") == 0) - return _ICONV_UTF8_UTF32LE; - } - else if (strcmp (tocode + 4, "8") == 0) - { - if (c_strcasecmp (fromcode + 4, "16BE") == 0) - return _ICONV_UTF16BE_UTF8; - if (c_strcasecmp (fromcode + 4, "16LE") == 0) - return _ICONV_UTF16LE_UTF8; - if (c_strcasecmp (fromcode + 4, "32BE") == 0) - return _ICONV_UTF32BE_UTF8; - if (c_strcasecmp (fromcode + 4, "32LE") == 0) - return _ICONV_UTF32LE_UTF8; - } - } + && c_toupper (tocode[1]) == 'T' + && c_toupper (tocode[2]) == 'F' + && tocode[3] == '-') + { + if (strcmp (fromcode + 4, "8") == 0) + { + if (c_strcasecmp (tocode + 4, "16BE") == 0) + return _ICONV_UTF8_UTF16BE; + if (c_strcasecmp (tocode + 4, "16LE") == 0) + return _ICONV_UTF8_UTF16LE; + if (c_strcasecmp (tocode + 4, "32BE") == 0) + return _ICONV_UTF8_UTF32BE; + if (c_strcasecmp (tocode + 4, "32LE") == 0) + return _ICONV_UTF8_UTF32LE; + } + else if (strcmp (tocode + 4, "8") == 0) + { + if (c_strcasecmp (fromcode + 4, "16BE") == 0) + return _ICONV_UTF16BE_UTF8; + if (c_strcasecmp (fromcode + 4, "16LE") == 0) + return _ICONV_UTF16LE_UTF8; + if (c_strcasecmp (fromcode + 4, "32BE") == 0) + return _ICONV_UTF32BE_UTF8; + if (c_strcasecmp (fromcode + 4, "32LE") == 0) + return _ICONV_UTF32LE_UTF8; + } + } } #endif @@ -115,20 +116,20 @@ rpl_iconv_open (const char *tocode, const char *fromcode) /* Convert the encodings to upper case, because 1. in the arguments of iconv_open() on AIX, HP-UX, and OSF/1 the case - matters, + matters, 2. it makes searching in the table faster. */ { const char *p = fromcode; char *q = fromcode_upper; while ((*q = c_toupper (*p)) != '\0') { - p++; - q++; - if (q == &fromcode_upper[SIZEOF (fromcode_upper)]) - { - errno = EINVAL; - return (iconv_t)(-1); - } + p++; + q++; + if (q == &fromcode_upper[SIZEOF (fromcode_upper)]) + { + errno = EINVAL; + return (iconv_t)(-1); + } } fromcode_upper_end = q; } @@ -138,13 +139,13 @@ rpl_iconv_open (const char *tocode, const char *fromcode) char *q = tocode_upper; while ((*q = c_toupper (*p)) != '\0') { - p++; - q++; - if (q == &tocode_upper[SIZEOF (tocode_upper)]) - { - errno = EINVAL; - return (iconv_t)(-1); - } + p++; + q++; + if (q == &tocode_upper[SIZEOF (tocode_upper)]) + { + errno = EINVAL; + return (iconv_t)(-1); + } } tocode_upper_end = q; } diff --git a/lib/iconveh.h b/lib/iconveh.h index 06cda52e..da15126b 100644 --- a/lib/iconveh.h +++ b/lib/iconveh.h @@ -1,5 +1,5 @@ /* Character set conversion handler type. - Copyright (C) 2001-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2001-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible. This program is free software: you can redistribute it and/or modify @@ -27,9 +27,9 @@ extern "C" { /* Handling of unconvertible characters. */ enum iconv_ilseq_handler { - iconveh_error, /* return and set errno = EILSEQ */ - iconveh_question_mark, /* use one '?' per unconvertible character */ - iconveh_escape_sequence /* use escape sequence \uxxxx or \Uxxxxxxxx */ + iconveh_error, /* return and set errno = EILSEQ */ + iconveh_question_mark, /* use one '?' per unconvertible character */ + iconveh_escape_sequence /* use escape sequence \uxxxx or \Uxxxxxxxx */ }; diff --git a/lib/isnan.c b/lib/isnan.c index f24f5761..a59dea79 100644 --- a/lib/isnan.c +++ b/lib/isnan.c @@ -1,5 +1,5 @@ /* Test for NaN that does not need libm. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -18,6 +18,18 @@ #include +/* Specification. */ +#ifdef USE_LONG_DOUBLE +/* Specification found in math.h or isnanl-nolibm.h. */ +extern int rpl_isnanl (long double x); +#elif ! defined USE_FLOAT +/* Specification found in math.h or isnand-nolibm.h. */ +extern int rpl_isnand (double x); +#else /* defined USE_FLOAT */ +/* Specification found in math.h or isnanf-nolibm.h. */ +extern int rpl_isnanf (float x); +#endif + #include #include @@ -128,10 +140,10 @@ FUNC (DOUBLE x) -Infinity, which have the same exponent. */ m.value = x; if (((m.word[EXPBIT0_WORD] ^ nan.word[EXPBIT0_WORD]) - & (EXP_MASK << EXPBIT0_BIT)) - == 0) + & (EXP_MASK << EXPBIT0_BIT)) + == 0) return (memcmp (&m.value, &plus_inf, SIZE) != 0 - && memcmp (&m.value, &minus_inf, SIZE) != 0); + && memcmp (&m.value, &minus_inf, SIZE) != 0); else return 0; } diff --git a/lib/isnand-nolibm.h b/lib/isnand-nolibm.h index 0a1c6ab7..cc1d4760 100644 --- a/lib/isnand-nolibm.h +++ b/lib/isnand-nolibm.h @@ -1,5 +1,5 @@ /* Test for NaN that does not need libm. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/isnand.c b/lib/isnand.c index d5220cb8..f7a15658 100644 --- a/lib/isnand.c +++ b/lib/isnand.c @@ -1,5 +1,5 @@ /* Test for NaN that does not need libm. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/isnanf-nolibm.h b/lib/isnanf-nolibm.h index cb2263e6..5e292073 100644 --- a/lib/isnanf-nolibm.h +++ b/lib/isnanf-nolibm.h @@ -1,5 +1,5 @@ /* Test for NaN that does not need libm. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/isnanf.c b/lib/isnanf.c index 6e39706e..a352fdbe 100644 --- a/lib/isnanf.c +++ b/lib/isnanf.c @@ -1,5 +1,5 @@ /* Test for NaN that does not need libm. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/isnanl-nolibm.h b/lib/isnanl-nolibm.h index 7fd46f8d..e89a7fe0 100644 --- a/lib/isnanl-nolibm.h +++ b/lib/isnanl-nolibm.h @@ -1,5 +1,5 @@ /* Test for NaN that does not need libm. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/isnanl.c b/lib/isnanl.c index b7d899b2..b45fef0a 100644 --- a/lib/isnanl.c +++ b/lib/isnanl.c @@ -1,5 +1,5 @@ /* Test for NaN that does not need libm. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/libunistring.rc b/lib/libunistring.rc index f1b51afa..e86f978b 100644 --- a/lib/libunistring.rc +++ b/lib/libunistring.rc @@ -19,12 +19,12 @@ BEGIN BEGIN BLOCK "04090000" /* Lang = US English, Charset = ASCII */ BEGIN - VALUE "Comments", "This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 or later. You should have received a copy of the GNU Lesser General Public License along with this library; if not, see \0" + VALUE "Comments", "This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 or later. You should have received a copy of the GNU Lesser General Public License along with this library; if not, see \0" VALUE "CompanyName", "Free Software Foundation\0" - VALUE "FileDescription", "LGPLed libunistring for Windows NT/2000/XP/Vista and Windows 95/98/ME\0" + VALUE "FileDescription", "LGPLed libunistring for Windows NT/2000/XP/Vista/7 and Windows 95/98/ME\0" VALUE "FileVersion", PACKAGE_VERSION_STRING "\0" VALUE "InternalName", "unistring.dll\0" - VALUE "LegalCopyright", "Copyright (C) 2001-2009\0" + VALUE "LegalCopyright", "Copyright (C) 2001-2010\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "unistring.dll\0" VALUE "ProductName", "libunistring: Unicode string library\0" diff --git a/lib/localcharset.c b/lib/localcharset.c index 93da1707..29de23d6 100644 --- a/lib/localcharset.c +++ b/lib/localcharset.c @@ -1,6 +1,6 @@ /* Determine a canonical name for the current locale's character encoding. - Copyright (C) 2000-2006, 2008-2009 Free Software Foundation, Inc. + Copyright (C) 2000-2006, 2008-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -23,6 +23,7 @@ /* Specification. */ #include "localcharset.h" +#include #include #include #include @@ -44,6 +45,7 @@ #endif #if !defined WIN32_NATIVE +# include # if HAVE_LANGINFO_CODESET # include # else @@ -75,6 +77,11 @@ # include "configmake.h" #endif +/* Define O_NOFOLLOW to 0 on platforms where it does not exist. */ +#ifndef O_NOFOLLOW +# define O_NOFOLLOW 0 +#endif + #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ /* Win32, Cygwin, OS/2, DOS */ # define ISSLASH(C) ((C) == '/' || (C) == '\\') @@ -117,192 +124,219 @@ get_charset_aliases (void) if (cp == NULL) { #if !(defined DARWIN7 || defined VMS || defined WIN32_NATIVE || defined __CYGWIN__) - FILE *fp; const char *dir; const char *base = "charset.alias"; char *file_name; /* Make it possible to override the charset.alias location. This is - necessary for running the testsuite before "make install". */ + necessary for running the testsuite before "make install". */ dir = getenv ("CHARSETALIASDIR"); if (dir == NULL || dir[0] == '\0') - dir = relocate (LIBDIR); + dir = relocate (LIBDIR); /* Concatenate dir and base into freshly allocated file_name. */ { - size_t dir_len = strlen (dir); - size_t base_len = strlen (base); - int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1])); - file_name = (char *) malloc (dir_len + add_slash + base_len + 1); - if (file_name != NULL) - { - memcpy (file_name, dir, dir_len); - if (add_slash) - file_name[dir_len] = DIRECTORY_SEPARATOR; - memcpy (file_name + dir_len + add_slash, base, base_len + 1); - } + size_t dir_len = strlen (dir); + size_t base_len = strlen (base); + int add_slash = (dir_len > 0 && !ISSLASH (dir[dir_len - 1])); + file_name = (char *) malloc (dir_len + add_slash + base_len + 1); + if (file_name != NULL) + { + memcpy (file_name, dir, dir_len); + if (add_slash) + file_name[dir_len] = DIRECTORY_SEPARATOR; + memcpy (file_name + dir_len + add_slash, base, base_len + 1); + } } - if (file_name == NULL || (fp = fopen (file_name, "r")) == NULL) - /* Out of memory or file not found, treat it as empty. */ - cp = ""; + if (file_name == NULL) + /* Out of memory. Treat the file as empty. */ + cp = ""; else - { - /* Parse the file's contents. */ - char *res_ptr = NULL; - size_t res_size = 0; - - for (;;) - { - int c; - char buf1[50+1]; - char buf2[50+1]; - size_t l1, l2; - char *old_res_ptr; - - c = getc (fp); - if (c == EOF) - break; - if (c == '\n' || c == ' ' || c == '\t') - continue; - if (c == '#') - { - /* Skip comment, to end of line. */ - do - c = getc (fp); - while (!(c == EOF || c == '\n')); - if (c == EOF) - break; - continue; - } - ungetc (c, fp); - if (fscanf (fp, "%50s %50s", buf1, buf2) < 2) - break; - l1 = strlen (buf1); - l2 = strlen (buf2); - old_res_ptr = res_ptr; - if (res_size == 0) - { - res_size = l1 + 1 + l2 + 1; - res_ptr = (char *) malloc (res_size + 1); - } - else - { - res_size += l1 + 1 + l2 + 1; - res_ptr = (char *) realloc (res_ptr, res_size + 1); - } - if (res_ptr == NULL) - { - /* Out of memory. */ - res_size = 0; - if (old_res_ptr != NULL) - free (old_res_ptr); - break; - } - strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); - strcpy (res_ptr + res_size - (l2 + 1), buf2); - } - fclose (fp); - if (res_size == 0) - cp = ""; - else - { - *(res_ptr + res_size) = '\0'; - cp = res_ptr; - } - } - - if (file_name != NULL) - free (file_name); + { + int fd; + + /* Open the file. Reject symbolic links on platforms that support + O_NOFOLLOW. This is a security feature. Without it, an attacker + could retrieve parts of the contents (namely, the tail of the + first line that starts with "* ") of an arbitrary file by placing + a symbolic link to that file under the name "charset.alias" in + some writable directory and defining the environment variable + CHARSETALIASDIR to point to that directory. */ + fd = open (file_name, + O_RDONLY | (HAVE_WORKING_O_NOFOLLOW ? O_NOFOLLOW : 0)); + if (fd < 0) + /* File not found. Treat it as empty. */ + cp = ""; + else + { + FILE *fp; + + fp = fdopen (fd, "r"); + if (fp == NULL) + { + /* Out of memory. Treat the file as empty. */ + close (fd); + cp = ""; + } + else + { + /* Parse the file's contents. */ + char *res_ptr = NULL; + size_t res_size = 0; + + for (;;) + { + int c; + char buf1[50+1]; + char buf2[50+1]; + size_t l1, l2; + char *old_res_ptr; + + c = getc (fp); + if (c == EOF) + break; + if (c == '\n' || c == ' ' || c == '\t') + continue; + if (c == '#') + { + /* Skip comment, to end of line. */ + do + c = getc (fp); + while (!(c == EOF || c == '\n')); + if (c == EOF) + break; + continue; + } + ungetc (c, fp); + if (fscanf (fp, "%50s %50s", buf1, buf2) < 2) + break; + l1 = strlen (buf1); + l2 = strlen (buf2); + old_res_ptr = res_ptr; + if (res_size == 0) + { + res_size = l1 + 1 + l2 + 1; + res_ptr = (char *) malloc (res_size + 1); + } + else + { + res_size += l1 + 1 + l2 + 1; + res_ptr = (char *) realloc (res_ptr, res_size + 1); + } + if (res_ptr == NULL) + { + /* Out of memory. */ + res_size = 0; + if (old_res_ptr != NULL) + free (old_res_ptr); + break; + } + strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); + strcpy (res_ptr + res_size - (l2 + 1), buf2); + } + fclose (fp); + if (res_size == 0) + cp = ""; + else + { + *(res_ptr + res_size) = '\0'; + cp = res_ptr; + } + } + } + + free (file_name); + } #else # if defined DARWIN7 /* To avoid the trouble of installing a file that is shared by many - GNU packages -- many packaging systems have problems with this --, - simply inline the aliases here. */ + GNU packages -- many packaging systems have problems with this --, + simply inline the aliases here. */ cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" - "ISO8859-2" "\0" "ISO-8859-2" "\0" - "ISO8859-4" "\0" "ISO-8859-4" "\0" - "ISO8859-5" "\0" "ISO-8859-5" "\0" - "ISO8859-7" "\0" "ISO-8859-7" "\0" - "ISO8859-9" "\0" "ISO-8859-9" "\0" - "ISO8859-13" "\0" "ISO-8859-13" "\0" - "ISO8859-15" "\0" "ISO-8859-15" "\0" - "KOI8-R" "\0" "KOI8-R" "\0" - "KOI8-U" "\0" "KOI8-U" "\0" - "CP866" "\0" "CP866" "\0" - "CP949" "\0" "CP949" "\0" - "CP1131" "\0" "CP1131" "\0" - "CP1251" "\0" "CP1251" "\0" - "eucCN" "\0" "GB2312" "\0" - "GB2312" "\0" "GB2312" "\0" - "eucJP" "\0" "EUC-JP" "\0" - "eucKR" "\0" "EUC-KR" "\0" - "Big5" "\0" "BIG5" "\0" - "Big5HKSCS" "\0" "BIG5-HKSCS" "\0" - "GBK" "\0" "GBK" "\0" - "GB18030" "\0" "GB18030" "\0" - "SJIS" "\0" "SHIFT_JIS" "\0" - "ARMSCII-8" "\0" "ARMSCII-8" "\0" - "PT154" "\0" "PT154" "\0" - /*"ISCII-DEV" "\0" "?" "\0"*/ - "*" "\0" "UTF-8" "\0"; + "ISO8859-2" "\0" "ISO-8859-2" "\0" + "ISO8859-4" "\0" "ISO-8859-4" "\0" + "ISO8859-5" "\0" "ISO-8859-5" "\0" + "ISO8859-7" "\0" "ISO-8859-7" "\0" + "ISO8859-9" "\0" "ISO-8859-9" "\0" + "ISO8859-13" "\0" "ISO-8859-13" "\0" + "ISO8859-15" "\0" "ISO-8859-15" "\0" + "KOI8-R" "\0" "KOI8-R" "\0" + "KOI8-U" "\0" "KOI8-U" "\0" + "CP866" "\0" "CP866" "\0" + "CP949" "\0" "CP949" "\0" + "CP1131" "\0" "CP1131" "\0" + "CP1251" "\0" "CP1251" "\0" + "eucCN" "\0" "GB2312" "\0" + "GB2312" "\0" "GB2312" "\0" + "eucJP" "\0" "EUC-JP" "\0" + "eucKR" "\0" "EUC-KR" "\0" + "Big5" "\0" "BIG5" "\0" + "Big5HKSCS" "\0" "BIG5-HKSCS" "\0" + "GBK" "\0" "GBK" "\0" + "GB18030" "\0" "GB18030" "\0" + "SJIS" "\0" "SHIFT_JIS" "\0" + "ARMSCII-8" "\0" "ARMSCII-8" "\0" + "PT154" "\0" "PT154" "\0" + /*"ISCII-DEV" "\0" "?" "\0"*/ + "*" "\0" "UTF-8" "\0"; # endif # if defined VMS /* To avoid the troubles of an extra file charset.alias_vms in the - sources of many GNU packages, simply inline the aliases here. */ + sources of many GNU packages, simply inline the aliases here. */ /* The list of encodings is taken from the OpenVMS 7.3-1 documentation - "Compaq C Run-Time Library Reference Manual for OpenVMS systems" - section 10.7 "Handling Different Character Sets". */ + "Compaq C Run-Time Library Reference Manual for OpenVMS systems" + section 10.7 "Handling Different Character Sets". */ cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" - "ISO8859-2" "\0" "ISO-8859-2" "\0" - "ISO8859-5" "\0" "ISO-8859-5" "\0" - "ISO8859-7" "\0" "ISO-8859-7" "\0" - "ISO8859-8" "\0" "ISO-8859-8" "\0" - "ISO8859-9" "\0" "ISO-8859-9" "\0" - /* Japanese */ - "eucJP" "\0" "EUC-JP" "\0" - "SJIS" "\0" "SHIFT_JIS" "\0" - "DECKANJI" "\0" "DEC-KANJI" "\0" - "SDECKANJI" "\0" "EUC-JP" "\0" - /* Chinese */ - "eucTW" "\0" "EUC-TW" "\0" - "DECHANYU" "\0" "DEC-HANYU" "\0" - "DECHANZI" "\0" "GB2312" "\0" - /* Korean */ - "DECKOREAN" "\0" "EUC-KR" "\0"; + "ISO8859-2" "\0" "ISO-8859-2" "\0" + "ISO8859-5" "\0" "ISO-8859-5" "\0" + "ISO8859-7" "\0" "ISO-8859-7" "\0" + "ISO8859-8" "\0" "ISO-8859-8" "\0" + "ISO8859-9" "\0" "ISO-8859-9" "\0" + /* Japanese */ + "eucJP" "\0" "EUC-JP" "\0" + "SJIS" "\0" "SHIFT_JIS" "\0" + "DECKANJI" "\0" "DEC-KANJI" "\0" + "SDECKANJI" "\0" "EUC-JP" "\0" + /* Chinese */ + "eucTW" "\0" "EUC-TW" "\0" + "DECHANYU" "\0" "DEC-HANYU" "\0" + "DECHANZI" "\0" "GB2312" "\0" + /* Korean */ + "DECKOREAN" "\0" "EUC-KR" "\0"; # endif # if defined WIN32_NATIVE || defined __CYGWIN__ /* To avoid the troubles of installing a separate file in the same - directory as the DLL and of retrieving the DLL's directory at - runtime, simply inline the aliases here. */ + directory as the DLL and of retrieving the DLL's directory at + runtime, simply inline the aliases here. */ cp = "CP936" "\0" "GBK" "\0" - "CP1361" "\0" "JOHAB" "\0" - "CP20127" "\0" "ASCII" "\0" - "CP20866" "\0" "KOI8-R" "\0" - "CP20936" "\0" "GB2312" "\0" - "CP21866" "\0" "KOI8-RU" "\0" - "CP28591" "\0" "ISO-8859-1" "\0" - "CP28592" "\0" "ISO-8859-2" "\0" - "CP28593" "\0" "ISO-8859-3" "\0" - "CP28594" "\0" "ISO-8859-4" "\0" - "CP28595" "\0" "ISO-8859-5" "\0" - "CP28596" "\0" "ISO-8859-6" "\0" - "CP28597" "\0" "ISO-8859-7" "\0" - "CP28598" "\0" "ISO-8859-8" "\0" - "CP28599" "\0" "ISO-8859-9" "\0" - "CP28605" "\0" "ISO-8859-15" "\0" - "CP38598" "\0" "ISO-8859-8" "\0" - "CP51932" "\0" "EUC-JP" "\0" - "CP51936" "\0" "GB2312" "\0" - "CP51949" "\0" "EUC-KR" "\0" - "CP51950" "\0" "EUC-TW" "\0" - "CP54936" "\0" "GB18030" "\0" - "CP65001" "\0" "UTF-8" "\0"; + "CP1361" "\0" "JOHAB" "\0" + "CP20127" "\0" "ASCII" "\0" + "CP20866" "\0" "KOI8-R" "\0" + "CP20936" "\0" "GB2312" "\0" + "CP21866" "\0" "KOI8-RU" "\0" + "CP28591" "\0" "ISO-8859-1" "\0" + "CP28592" "\0" "ISO-8859-2" "\0" + "CP28593" "\0" "ISO-8859-3" "\0" + "CP28594" "\0" "ISO-8859-4" "\0" + "CP28595" "\0" "ISO-8859-5" "\0" + "CP28596" "\0" "ISO-8859-6" "\0" + "CP28597" "\0" "ISO-8859-7" "\0" + "CP28598" "\0" "ISO-8859-8" "\0" + "CP28599" "\0" "ISO-8859-9" "\0" + "CP28605" "\0" "ISO-8859-15" "\0" + "CP38598" "\0" "ISO-8859-8" "\0" + "CP51932" "\0" "EUC-JP" "\0" + "CP51936" "\0" "GB2312" "\0" + "CP51949" "\0" "EUC-KR" "\0" + "CP51950" "\0" "EUC-TW" "\0" + "CP54936" "\0" "GB18030" "\0" + "CP65001" "\0" "UTF-8" "\0"; # endif #endif @@ -335,7 +369,7 @@ locale_charset (void) codeset = nl_langinfo (CODESET); # ifdef __CYGWIN__ - /* Cygwin 2006 does not have locales. nl_langinfo (CODESET) always + /* Cygwin 1.5.x does not have locales. nl_langinfo (CODESET) always returns "US-ASCII". As long as this is not fixed, return the suffix of the locale name from the environment variables (if present) or the codepage as a number. */ @@ -346,36 +380,46 @@ locale_charset (void) locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') - { - locale = getenv ("LC_CTYPE"); - if (locale == NULL || locale[0] == '\0') - locale = getenv ("LANG"); - } + { + locale = getenv ("LC_CTYPE"); + if (locale == NULL || locale[0] == '\0') + locale = getenv ("LANG"); + } if (locale != NULL && locale[0] != '\0') - { - /* If the locale name contains an encoding after the dot, return - it. */ - const char *dot = strchr (locale, '.'); - - if (dot != NULL) - { - const char *modifier; - - dot++; - /* Look for the possible @... trailer and remove it, if any. */ - modifier = strchr (dot, '@'); - if (modifier == NULL) - return dot; - if (modifier - dot < sizeof (buf)) - { - memcpy (buf, dot, modifier - dot); - buf [modifier - dot] = '\0'; - return buf; - } - } - } - - /* Woe32 has a function returning the locale's codepage as a number. */ + { + /* If the locale name contains an encoding after the dot, return + it. */ + const char *dot = strchr (locale, '.'); + + if (dot != NULL) + { + const char *modifier; + + dot++; + /* Look for the possible @... trailer and remove it, if any. */ + modifier = strchr (dot, '@'); + if (modifier == NULL) + return dot; + if (modifier - dot < sizeof (buf)) + { + memcpy (buf, dot, modifier - dot); + buf [modifier - dot] = '\0'; + return buf; + } + } + } + + /* Woe32 has a function returning the locale's codepage as a number: + GetACP(). This encoding is used by Cygwin, unless the user has set + the environment variable CYGWIN=codepage:oem (which very few people + do). + Output directed to console windows needs to be converted (to + GetOEMCP() if the console is using a raster font, or to + GetConsoleOutputCP() if it is using a TrueType font). Cygwin does + this conversion transparently (see winsup/cygwin/fhandler_console.cc), + converting to GetConsoleOutputCP(). This leads to correct results, + except when SetConsoleOutputCP has been called and a raster font is + in use. */ sprintf (buf, "CP%u", GetACP ()); codeset = buf; } @@ -397,11 +441,11 @@ locale_charset (void) { locale = getenv ("LC_ALL"); if (locale == NULL || locale[0] == '\0') - { - locale = getenv ("LC_CTYPE"); - if (locale == NULL || locale[0] == '\0') - locale = getenv ("LANG"); - } + { + locale = getenv ("LC_CTYPE"); + if (locale == NULL || locale[0] == '\0') + locale = getenv ("LANG"); + } } /* On some old systems, one used to set locale = "iso8859_1". On others, @@ -415,7 +459,13 @@ locale_charset (void) static char buf[2 + 10 + 1]; - /* Woe32 has a function returning the locale's codepage as a number. */ + /* Woe32 has a function returning the locale's codepage as a number: + GetACP(). + When the output goes to a console window, it needs to be provided in + GetOEMCP() encoding if the console is using a raster font, or in + GetConsoleOutputCP() encoding if it is using a TrueType font. + But in GUI programs and for output sent to files and pipes, GetACP() + encoding is the best bet. */ sprintf (buf, "CP%u", GetACP ()); codeset = buf; @@ -433,7 +483,7 @@ locale_charset (void) { locale = getenv ("LC_CTYPE"); if (locale == NULL || locale[0] == '\0') - locale = getenv ("LANG"); + locale = getenv ("LANG"); } if (locale != NULL && locale[0] != '\0') { @@ -441,21 +491,21 @@ locale_charset (void) const char *dot = strchr (locale, '.'); if (dot != NULL) - { - const char *modifier; - - dot++; - /* Look for the possible @... trailer and remove it, if any. */ - modifier = strchr (dot, '@'); - if (modifier == NULL) - return dot; - if (modifier - dot < sizeof (buf)) - { - memcpy (buf, dot, modifier - dot); - buf [modifier - dot] = '\0'; - return buf; - } - } + { + const char *modifier; + + dot++; + /* Look for the possible @... trailer and remove it, if any. */ + modifier = strchr (dot, '@'); + if (modifier == NULL) + return dot; + if (modifier - dot < sizeof (buf)) + { + memcpy (buf, dot, modifier - dot); + buf [modifier - dot] = '\0'; + return buf; + } + } /* Resolve through the charset.alias file. */ codeset = locale; @@ -464,12 +514,12 @@ locale_charset (void) { /* OS/2 has a function returning the locale's codepage as a number. */ if (DosQueryCp (sizeof (cp), cp, &cplen)) - codeset = ""; + codeset = ""; else - { - sprintf (buf, "CP%u", cp[0]); - codeset = buf; - } + { + sprintf (buf, "CP%u", cp[0]); + codeset = buf; + } } #endif @@ -483,10 +533,10 @@ locale_charset (void) *aliases != '\0'; aliases += strlen (aliases) + 1, aliases += strlen (aliases) + 1) if (strcmp (codeset, aliases) == 0 - || (aliases[0] == '*' && aliases[1] == '\0')) + || (aliases[0] == '*' && aliases[1] == '\0')) { - codeset = aliases + strlen (aliases) + 1; - break; + codeset = aliases + strlen (aliases) + 1; + break; } /* Don't return an empty string. GNU libc and GNU libiconv interpret diff --git a/lib/localcharset.h b/lib/localcharset.h index 1772a50f..c18f492c 100644 --- a/lib/localcharset.h +++ b/lib/localcharset.h @@ -1,5 +1,5 @@ /* Determine a canonical name for the current locale's character encoding. - Copyright (C) 2000-2003 Free Software Foundation, Inc. + Copyright (C) 2000-2003, 2009-2010 Free Software Foundation, Inc. This file is part of the GNU CHARSET Library. This program is free software; you can redistribute it and/or modify diff --git a/lib/localename.c b/lib/localename.c index 9f4c1819..ea646c50 100644 --- a/lib/localename.c +++ b/lib/localename.c @@ -1,5 +1,5 @@ /* Determine name of the currently selected locale. - Copyright (C) 1995-1999, 2000-2008 Free Software Foundation, Inc. + Copyright (C) 1995-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published @@ -29,11 +29,24 @@ # include "localename.h" #endif +#include +#include #include #include +#include + +#if HAVE_USELOCALE +/* MacOS X 10.5 defines the locale_t type in . */ +# if defined __APPLE__ && defined __MACH__ +# include +# endif +# include +# if !defined IN_LIBINTL +# include "glthread/lock.h" +# endif +#endif #if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE -# include # include # if HAVE_CFLOCALECOPYCURRENT # include @@ -46,7 +59,7 @@ # define WIN32_NATIVE #endif -#ifdef WIN32_NATIVE +#if defined WIN32_NATIVE || defined __CYGWIN__ /* WIN32 or Cygwin */ # define WIN32_LEAN_AND_MEAN # include /* List of language codes, sorted by value: @@ -72,7 +85,7 @@ 0x14 LANG_NORWEGIAN 0x15 LANG_POLISH 0x16 LANG_PORTUGUESE - 0x17 LANG_RHAETO_ROMANCE + 0x17 LANG_ROMANSH 0x18 LANG_ROMANIAN 0x19 LANG_RUSSIAN 0x1a LANG_CROATIAN == LANG_SERBIAN @@ -108,7 +121,7 @@ 0x38 LANG_FAEROESE 0x39 LANG_HINDI 0x3a LANG_MALTESE - 0x3b LANG_SAAMI + 0x3b LANG_SAMI 0x3c LANG_GAELIC 0x3d LANG_YIDDISH 0x3e LANG_MALAY @@ -156,6 +169,9 @@ 0x68 LANG_HAUSA 0x69 LANG_IBIBIO 0x6a LANG_YORUBA + 0x6d LANG_BASHKIR + 0x6e LANG_LUXEMBOURGISH + 0x6f LANG_GREENLANDIC 0x70 LANG_IGBO 0x71 LANG_KANURI 0x72 LANG_OROMO @@ -166,6 +182,18 @@ 0x77 LANG_SOMALI 0x78 LANG_YI 0x79 LANG_PAPIAMENTU + 0x7a LANG_MAPUDUNGUN + 0x7c LANG_MOHAWK + 0x7e LANG_BRETON + 0x82 LANG_OCCITAN + 0x83 LANG_CORSICAN + 0x84 LANG_ALSATIAN + 0x85 LANG_YAKUT + 0x86 LANG_KICHE + 0x87 LANG_KINYARWANDA + 0x88 LANG_WOLOF + 0x8c LANG_DARI + 0x91 LANG_SCOTTISH_GAELIC */ /* Mingw headers don't have latest language and sublanguage codes. */ # ifndef LANG_AFRIKAANS @@ -174,6 +202,9 @@ # ifndef LANG_ALBANIAN # define LANG_ALBANIAN 0x1c # endif +# ifndef LANG_ALSATIAN +# define LANG_ALSATIAN 0x84 +# endif # ifndef LANG_AMHARIC # define LANG_AMHARIC 0x5e # endif @@ -189,6 +220,9 @@ # ifndef LANG_AZERI # define LANG_AZERI 0x2c # endif +# ifndef LANG_BASHKIR +# define LANG_BASHKIR 0x6d +# endif # ifndef LANG_BASQUE # define LANG_BASQUE 0x2d # endif @@ -198,6 +232,9 @@ # ifndef LANG_BENGALI # define LANG_BENGALI 0x45 # endif +# ifndef LANG_BRETON +# define LANG_BRETON 0x7e +# endif # ifndef LANG_BURMESE # define LANG_BURMESE 0x55 # endif @@ -210,6 +247,12 @@ # ifndef LANG_CHEROKEE # define LANG_CHEROKEE 0x5c # endif +# ifndef LANG_CORSICAN +# define LANG_CORSICAN 0x83 +# endif +# ifndef LANG_DARI +# define LANG_DARI 0x8c +# endif # ifndef LANG_DIVEHI # define LANG_DIVEHI 0x65 # endif @@ -240,6 +283,9 @@ # ifndef LANG_GEORGIAN # define LANG_GEORGIAN 0x37 # endif +# ifndef LANG_GREENLANDIC +# define LANG_GREENLANDIC 0x6f +# endif # ifndef LANG_GUARANI # define LANG_GUARANI 0x74 # endif @@ -282,6 +328,12 @@ # ifndef LANG_KAZAK # define LANG_KAZAK 0x3f # endif +# ifndef LANG_KICHE +# define LANG_KICHE 0x86 +# endif +# ifndef LANG_KINYARWANDA +# define LANG_KINYARWANDA 0x87 +# endif # ifndef LANG_KONKANI # define LANG_KONKANI 0x57 # endif @@ -300,6 +352,9 @@ # ifndef LANG_LITHUANIAN # define LANG_LITHUANIAN 0x27 # endif +# ifndef LANG_LUXEMBOURGISH +# define LANG_LUXEMBOURGISH 0x6e +# endif # ifndef LANG_MACEDONIAN # define LANG_MACEDONIAN 0x2f # endif @@ -318,15 +373,24 @@ # ifndef LANG_MAORI # define LANG_MAORI 0x81 # endif +# ifndef LANG_MAPUDUNGUN +# define LANG_MAPUDUNGUN 0x7a +# endif # ifndef LANG_MARATHI # define LANG_MARATHI 0x4e # endif +# ifndef LANG_MOHAWK +# define LANG_MOHAWK 0x7c +# endif # ifndef LANG_MONGOLIAN # define LANG_MONGOLIAN 0x50 # endif # ifndef LANG_NEPALI # define LANG_NEPALI 0x61 # endif +# ifndef LANG_OCCITAN +# define LANG_OCCITAN 0x82 +# endif # ifndef LANG_ORIYA # define LANG_ORIYA 0x48 # endif @@ -345,15 +409,18 @@ # ifndef LANG_QUECHUA # define LANG_QUECHUA 0x6b # endif -# ifndef LANG_RHAETO_ROMANCE -# define LANG_RHAETO_ROMANCE 0x17 +# ifndef LANG_ROMANSH +# define LANG_ROMANSH 0x17 # endif -# ifndef LANG_SAAMI -# define LANG_SAAMI 0x3b +# ifndef LANG_SAMI +# define LANG_SAMI 0x3b # endif # ifndef LANG_SANSKRIT # define LANG_SANSKRIT 0x4f # endif +# ifndef LANG_SCOTTISH_GAELIC +# define LANG_SCOTTISH_GAELIC 0x91 +# endif # ifndef LANG_SERBIAN # define LANG_SERBIAN 0x1a # endif @@ -441,9 +508,15 @@ # ifndef LANG_WELSH # define LANG_WELSH 0x52 # endif +# ifndef LANG_WOLOF +# define LANG_WOLOF 0x88 +# endif # ifndef LANG_XHOSA # define LANG_XHOSA 0x34 # endif +# ifndef LANG_YAKUT +# define LANG_YAKUT 0x85 +# endif # ifndef LANG_YI # define LANG_YI 0x78 # endif @@ -456,6 +529,18 @@ # ifndef LANG_ZULU # define LANG_ZULU 0x35 # endif +# ifndef SUBLANG_AFRIKAANS_SOUTH_AFRICA +# define SUBLANG_AFRIKAANS_SOUTH_AFRICA 0x01 +# endif +# ifndef SUBLANG_ALBANIAN_ALBANIA +# define SUBLANG_ALBANIAN_ALBANIA 0x01 +# endif +# ifndef SUBLANG_ALSATIAN_FRANCE +# define SUBLANG_ALSATIAN_FRANCE 0x01 +# endif +# ifndef SUBLANG_AMHARIC_ETHIOPIA +# define SUBLANG_AMHARIC_ETHIOPIA 0x01 +# endif # ifndef SUBLANG_ARABIC_SAUDI_ARABIA # define SUBLANG_ARABIC_SAUDI_ARABIA 0x01 # endif @@ -504,12 +589,27 @@ # ifndef SUBLANG_ARABIC_QATAR # define SUBLANG_ARABIC_QATAR 0x10 # endif +# ifndef SUBLANG_ARMENIAN_ARMENIA +# define SUBLANG_ARMENIAN_ARMENIA 0x01 +# endif +# ifndef SUBLANG_ASSAMESE_INDIA +# define SUBLANG_ASSAMESE_INDIA 0x01 +# endif # ifndef SUBLANG_AZERI_LATIN # define SUBLANG_AZERI_LATIN 0x01 # endif # ifndef SUBLANG_AZERI_CYRILLIC # define SUBLANG_AZERI_CYRILLIC 0x02 # endif +# ifndef SUBLANG_BASHKIR_RUSSIA +# define SUBLANG_BASHKIR_RUSSIA 0x01 +# endif +# ifndef SUBLANG_BASQUE_BASQUE +# define SUBLANG_BASQUE_BASQUE 0x01 +# endif +# ifndef SUBLANG_BELARUSIAN_BELARUS +# define SUBLANG_BELARUSIAN_BELARUS 0x01 +# endif # ifndef SUBLANG_BENGALI_INDIA # define SUBLANG_BENGALI_INDIA 0x01 # endif @@ -522,6 +622,21 @@ # ifndef SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC # define SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC 0x08 # endif +# ifndef SUBLANG_BRETON_FRANCE +# define SUBLANG_BRETON_FRANCE 0x01 +# endif +# ifndef SUBLANG_BULGARIAN_BULGARIA +# define SUBLANG_BULGARIAN_BULGARIA 0x01 +# endif +# ifndef SUBLANG_CAMBODIAN_CAMBODIA +# define SUBLANG_CAMBODIAN_CAMBODIA 0x01 +# endif +# ifndef SUBLANG_CATALAN_SPAIN +# define SUBLANG_CATALAN_SPAIN 0x01 +# endif +# ifndef SUBLANG_CORSICAN_FRANCE +# define SUBLANG_CORSICAN_FRANCE 0x01 +# endif # ifndef SUBLANG_CROATIAN_CROATIA # define SUBLANG_CROATIAN_CROATIA 0x01 # endif @@ -531,6 +646,21 @@ # ifndef SUBLANG_CHINESE_MACAU # define SUBLANG_CHINESE_MACAU 0x05 # endif +# ifndef SUBLANG_CZECH_CZECH_REPUBLIC +# define SUBLANG_CZECH_CZECH_REPUBLIC 0x01 +# endif +# ifndef SUBLANG_DANISH_DENMARK +# define SUBLANG_DANISH_DENMARK 0x01 +# endif +# ifndef SUBLANG_DARI_AFGHANISTAN +# define SUBLANG_DARI_AFGHANISTAN 0x01 +# endif +# ifndef SUBLANG_DIVEHI_MALDIVES +# define SUBLANG_DIVEHI_MALDIVES 0x01 +# endif +# ifndef SUBLANG_DUTCH_SURINAM +# define SUBLANG_DUTCH_SURINAM 0x03 +# endif # ifndef SUBLANG_ENGLISH_SOUTH_AFRICA # define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07 # endif @@ -567,6 +697,18 @@ # ifndef SUBLANG_ENGLISH_SINGAPORE # define SUBLANG_ENGLISH_SINGAPORE 0x12 # endif +# ifndef SUBLANG_ESTONIAN_ESTONIA +# define SUBLANG_ESTONIAN_ESTONIA 0x01 +# endif +# ifndef SUBLANG_FAEROESE_FAROE_ISLANDS +# define SUBLANG_FAEROESE_FAROE_ISLANDS 0x01 +# endif +# ifndef SUBLANG_FARSI_IRAN +# define SUBLANG_FARSI_IRAN 0x01 +# endif +# ifndef SUBLANG_FINNISH_FINLAND +# define SUBLANG_FINNISH_FINLAND 0x01 +# endif # ifndef SUBLANG_FRENCH_LUXEMBOURG # define SUBLANG_FRENCH_LUXEMBOURG 0x05 # endif @@ -600,30 +742,147 @@ # ifndef SUBLANG_FRENCH_HAITI # define SUBLANG_FRENCH_HAITI 0x0f # endif +# ifndef SUBLANG_FRISIAN_NETHERLANDS +# define SUBLANG_FRISIAN_NETHERLANDS 0x01 +# endif +# ifndef SUBLANG_GALICIAN_SPAIN +# define SUBLANG_GALICIAN_SPAIN 0x01 +# endif +# ifndef SUBLANG_GEORGIAN_GEORGIA +# define SUBLANG_GEORGIAN_GEORGIA 0x01 +# endif # ifndef SUBLANG_GERMAN_LUXEMBOURG # define SUBLANG_GERMAN_LUXEMBOURG 0x04 # endif # ifndef SUBLANG_GERMAN_LIECHTENSTEIN # define SUBLANG_GERMAN_LIECHTENSTEIN 0x05 # endif +# ifndef SUBLANG_GREEK_GREECE +# define SUBLANG_GREEK_GREECE 0x01 +# endif +# ifndef SUBLANG_GREENLANDIC_GREENLAND +# define SUBLANG_GREENLANDIC_GREENLAND 0x01 +# endif +# ifndef SUBLANG_GUJARATI_INDIA +# define SUBLANG_GUJARATI_INDIA 0x01 +# endif +# ifndef SUBLANG_HAUSA_NIGERIA_LATIN +# define SUBLANG_HAUSA_NIGERIA_LATIN 0x01 +# endif +# ifndef SUBLANG_HEBREW_ISRAEL +# define SUBLANG_HEBREW_ISRAEL 0x01 +# endif +# ifndef SUBLANG_HINDI_INDIA +# define SUBLANG_HINDI_INDIA 0x01 +# endif +# ifndef SUBLANG_HUNGARIAN_HUNGARY +# define SUBLANG_HUNGARIAN_HUNGARY 0x01 +# endif +# ifndef SUBLANG_ICELANDIC_ICELAND +# define SUBLANG_ICELANDIC_ICELAND 0x01 +# endif +# ifndef SUBLANG_IGBO_NIGERIA +# define SUBLANG_IGBO_NIGERIA 0x01 +# endif +# ifndef SUBLANG_INDONESIAN_INDONESIA +# define SUBLANG_INDONESIAN_INDONESIA 0x01 +# endif +# ifndef SUBLANG_INUKTITUT_CANADA +# define SUBLANG_INUKTITUT_CANADA 0x01 +# endif +# undef SUBLANG_INUKTITUT_CANADA_LATIN +# define SUBLANG_INUKTITUT_CANADA_LATIN 0x02 +# undef SUBLANG_IRISH_IRELAND +# define SUBLANG_IRISH_IRELAND 0x02 +# ifndef SUBLANG_JAPANESE_JAPAN +# define SUBLANG_JAPANESE_JAPAN 0x01 +# endif +# ifndef SUBLANG_KANNADA_INDIA +# define SUBLANG_KANNADA_INDIA 0x01 +# endif # ifndef SUBLANG_KASHMIRI_INDIA # define SUBLANG_KASHMIRI_INDIA 0x02 # endif +# ifndef SUBLANG_KAZAK_KAZAKHSTAN +# define SUBLANG_KAZAK_KAZAKHSTAN 0x01 +# endif +# ifndef SUBLANG_KICHE_GUATEMALA +# define SUBLANG_KICHE_GUATEMALA 0x01 +# endif +# ifndef SUBLANG_KINYARWANDA_RWANDA +# define SUBLANG_KINYARWANDA_RWANDA 0x01 +# endif +# ifndef SUBLANG_KONKANI_INDIA +# define SUBLANG_KONKANI_INDIA 0x01 +# endif +# ifndef SUBLANG_KYRGYZ_KYRGYZSTAN +# define SUBLANG_KYRGYZ_KYRGYZSTAN 0x01 +# endif +# ifndef SUBLANG_LAO_LAOS +# define SUBLANG_LAO_LAOS 0x01 +# endif +# ifndef SUBLANG_LATVIAN_LATVIA +# define SUBLANG_LATVIAN_LATVIA 0x01 +# endif +# ifndef SUBLANG_LITHUANIAN_LITHUANIA +# define SUBLANG_LITHUANIAN_LITHUANIA 0x01 +# endif +# undef SUBLANG_LOWER_SORBIAN_GERMANY +# define SUBLANG_LOWER_SORBIAN_GERMANY 0x02 +# ifndef SUBLANG_LUXEMBOURGISH_LUXEMBOURG +# define SUBLANG_LUXEMBOURGISH_LUXEMBOURG 0x01 +# endif +# ifndef SUBLANG_MACEDONIAN_MACEDONIA +# define SUBLANG_MACEDONIAN_MACEDONIA 0x01 +# endif # ifndef SUBLANG_MALAY_MALAYSIA # define SUBLANG_MALAY_MALAYSIA 0x01 # endif # ifndef SUBLANG_MALAY_BRUNEI_DARUSSALAM # define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02 # endif +# ifndef SUBLANG_MALAYALAM_INDIA +# define SUBLANG_MALAYALAM_INDIA 0x01 +# endif +# ifndef SUBLANG_MALTESE_MALTA +# define SUBLANG_MALTESE_MALTA 0x01 +# endif +# ifndef SUBLANG_MAORI_NEW_ZEALAND +# define SUBLANG_MAORI_NEW_ZEALAND 0x01 +# endif +# ifndef SUBLANG_MAPUDUNGUN_CHILE +# define SUBLANG_MAPUDUNGUN_CHILE 0x01 +# endif +# ifndef SUBLANG_MARATHI_INDIA +# define SUBLANG_MARATHI_INDIA 0x01 +# endif +# ifndef SUBLANG_MOHAWK_CANADA +# define SUBLANG_MOHAWK_CANADA 0x01 +# endif # ifndef SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA # define SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA 0x01 # endif # ifndef SUBLANG_MONGOLIAN_PRC # define SUBLANG_MONGOLIAN_PRC 0x02 # endif +# ifndef SUBLANG_NEPALI_NEPAL +# define SUBLANG_NEPALI_NEPAL 0x01 +# endif # ifndef SUBLANG_NEPALI_INDIA # define SUBLANG_NEPALI_INDIA 0x02 # endif +# ifndef SUBLANG_OCCITAN_FRANCE +# define SUBLANG_OCCITAN_FRANCE 0x01 +# endif +# ifndef SUBLANG_ORIYA_INDIA +# define SUBLANG_ORIYA_INDIA 0x01 +# endif +# ifndef SUBLANG_PASHTO_AFGHANISTAN +# define SUBLANG_PASHTO_AFGHANISTAN 0x01 +# endif +# ifndef SUBLANG_POLISH_POLAND +# define SUBLANG_POLISH_POLAND 0x01 +# endif # ifndef SUBLANG_PUNJABI_INDIA # define SUBLANG_PUNJABI_INDIA 0x01 # endif @@ -645,12 +904,43 @@ # ifndef SUBLANG_ROMANIAN_MOLDOVA # define SUBLANG_ROMANIAN_MOLDOVA 0x02 # endif +# ifndef SUBLANG_ROMANSH_SWITZERLAND +# define SUBLANG_ROMANSH_SWITZERLAND 0x01 +# endif # ifndef SUBLANG_RUSSIAN_RUSSIA # define SUBLANG_RUSSIAN_RUSSIA 0x01 # endif # ifndef SUBLANG_RUSSIAN_MOLDAVIA # define SUBLANG_RUSSIAN_MOLDAVIA 0x02 # endif +# ifndef SUBLANG_SAMI_NORTHERN_NORWAY +# define SUBLANG_SAMI_NORTHERN_NORWAY 0x01 +# endif +# ifndef SUBLANG_SAMI_NORTHERN_SWEDEN +# define SUBLANG_SAMI_NORTHERN_SWEDEN 0x02 +# endif +# ifndef SUBLANG_SAMI_NORTHERN_FINLAND +# define SUBLANG_SAMI_NORTHERN_FINLAND 0x03 +# endif +# ifndef SUBLANG_SAMI_LULE_NORWAY +# define SUBLANG_SAMI_LULE_NORWAY 0x04 +# endif +# ifndef SUBLANG_SAMI_LULE_SWEDEN +# define SUBLANG_SAMI_LULE_SWEDEN 0x05 +# endif +# ifndef SUBLANG_SAMI_SOUTHERN_NORWAY +# define SUBLANG_SAMI_SOUTHERN_NORWAY 0x06 +# endif +# ifndef SUBLANG_SAMI_SOUTHERN_SWEDEN +# define SUBLANG_SAMI_SOUTHERN_SWEDEN 0x07 +# endif +# undef SUBLANG_SAMI_SKOLT_FINLAND +# define SUBLANG_SAMI_SKOLT_FINLAND 0x08 +# undef SUBLANG_SAMI_INARI_FINLAND +# define SUBLANG_SAMI_INARI_FINLAND 0x09 +# ifndef SUBLANG_SANSKRIT_INDIA +# define SUBLANG_SANSKRIT_INDIA 0x01 +# endif # ifndef SUBLANG_SERBIAN_LATIN # define SUBLANG_SERBIAN_LATIN 0x02 # endif @@ -665,6 +955,18 @@ # ifndef SUBLANG_SINDHI_AFGHANISTAN # define SUBLANG_SINDHI_AFGHANISTAN 0x02 # endif +# ifndef SUBLANG_SINHALESE_SRI_LANKA +# define SUBLANG_SINHALESE_SRI_LANKA 0x01 +# endif +# ifndef SUBLANG_SLOVAK_SLOVAKIA +# define SUBLANG_SLOVAK_SLOVAKIA 0x01 +# endif +# ifndef SUBLANG_SLOVENIAN_SLOVENIA +# define SUBLANG_SLOVENIAN_SLOVENIA 0x01 +# endif +# ifndef SUBLANG_SOTHO_SOUTH_AFRICA +# define SUBLANG_SOTHO_SOUTH_AFRICA 0x01 +# endif # ifndef SUBLANG_SPANISH_GUATEMALA # define SUBLANG_SPANISH_GUATEMALA 0x04 # endif @@ -719,15 +1021,42 @@ # ifndef SUBLANG_SPANISH_US # define SUBLANG_SPANISH_US 0x15 # endif +# ifndef SUBLANG_SWAHILI_KENYA +# define SUBLANG_SWAHILI_KENYA 0x01 +# endif +# ifndef SUBLANG_SWEDISH_SWEDEN +# define SUBLANG_SWEDISH_SWEDEN 0x01 +# endif # ifndef SUBLANG_SWEDISH_FINLAND # define SUBLANG_SWEDISH_FINLAND 0x02 # endif +# ifndef SUBLANG_SYRIAC_SYRIA +# define SUBLANG_SYRIAC_SYRIA 0x01 +# endif +# ifndef SUBLANG_TAGALOG_PHILIPPINES +# define SUBLANG_TAGALOG_PHILIPPINES 0x01 +# endif +# ifndef SUBLANG_TAJIK_TAJIKISTAN +# define SUBLANG_TAJIK_TAJIKISTAN 0x01 +# endif # ifndef SUBLANG_TAMAZIGHT_ARABIC # define SUBLANG_TAMAZIGHT_ARABIC 0x01 # endif # ifndef SUBLANG_TAMAZIGHT_ALGERIA_LATIN # define SUBLANG_TAMAZIGHT_ALGERIA_LATIN 0x02 # endif +# ifndef SUBLANG_TAMIL_INDIA +# define SUBLANG_TAMIL_INDIA 0x01 +# endif +# ifndef SUBLANG_TATAR_RUSSIA +# define SUBLANG_TATAR_RUSSIA 0x01 +# endif +# ifndef SUBLANG_TELUGU_INDIA +# define SUBLANG_TELUGU_INDIA 0x01 +# endif +# ifndef SUBLANG_THAI_THAILAND +# define SUBLANG_THAI_THAILAND 0x01 +# endif # ifndef SUBLANG_TIBETAN_PRC # define SUBLANG_TIBETAN_PRC 0x01 # endif @@ -739,9 +1068,24 @@ # ifndef SUBLANG_TIGRINYA_ERITREA # define SUBLANG_TIGRINYA_ERITREA 0x02 # endif +# ifndef SUBLANG_TSWANA_SOUTH_AFRICA +# define SUBLANG_TSWANA_SOUTH_AFRICA 0x01 +# endif +# ifndef SUBLANG_TURKISH_TURKEY +# define SUBLANG_TURKISH_TURKEY 0x01 +# endif +# ifndef SUBLANG_TURKMEN_TURKMENISTAN +# define SUBLANG_TURKMEN_TURKMENISTAN 0x01 +# endif # ifndef SUBLANG_UIGHUR_PRC # define SUBLANG_UIGHUR_PRC 0x01 # endif +# ifndef SUBLANG_UKRAINIAN_UKRAINE +# define SUBLANG_UKRAINIAN_UKRAINE 0x01 +# endif +# ifndef SUBLANG_UPPER_SORBIAN_GERMANY +# define SUBLANG_UPPER_SORBIAN_GERMANY 0x01 +# endif # ifndef SUBLANG_URDU_PAKISTAN # define SUBLANG_URDU_PAKISTAN 0x01 # endif @@ -754,6 +1098,30 @@ # ifndef SUBLANG_UZBEK_CYRILLIC # define SUBLANG_UZBEK_CYRILLIC 0x02 # endif +# ifndef SUBLANG_VIETNAMESE_VIETNAM +# define SUBLANG_VIETNAMESE_VIETNAM 0x01 +# endif +# ifndef SUBLANG_WELSH_UNITED_KINGDOM +# define SUBLANG_WELSH_UNITED_KINGDOM 0x01 +# endif +# ifndef SUBLANG_WOLOF_SENEGAL +# define SUBLANG_WOLOF_SENEGAL 0x01 +# endif +# ifndef SUBLANG_XHOSA_SOUTH_AFRICA +# define SUBLANG_XHOSA_SOUTH_AFRICA 0x01 +# endif +# ifndef SUBLANG_YAKUT_RUSSIA +# define SUBLANG_YAKUT_RUSSIA 0x01 +# endif +# ifndef SUBLANG_YI_PRC +# define SUBLANG_YI_PRC 0x01 +# endif +# ifndef SUBLANG_YORUBA_NIGERIA +# define SUBLANG_YORUBA_NIGERIA 0x01 +# endif +# ifndef SUBLANG_ZULU_SOUTH_AFRICA +# define SUBLANG_ZULU_SOUTH_AFRICA 0x01 +# endif /* GetLocaleInfoA operations. */ # ifndef LOCALE_SNAME # define LOCALE_SNAME 0x5c @@ -784,7 +1152,7 @@ gl_locale_name_canonicalize (char *name) MacOS X 10.3.8 function CFLocaleCreateCanonicalLocaleIdentifierFromString(). */ typedef struct { const char legacy[21+1]; const char unixy[5+1]; } - legacy_entry; + legacy_entry; static const legacy_entry legacy_table[] = { { "Afrikaans", "af" }, { "Albanian", "sq" }, @@ -922,7 +1290,7 @@ gl_locale_name_canonicalize (char *name) /* Convert new-style locale names with language tags (ISO 639 and ISO 15924) to Unix (ISO 639 and ISO 3166) names. */ typedef struct { const char langtag[7+1]; const char unixy[12+1]; } - langtag_entry; + langtag_entry; static const langtag_entry langtag_table[] = { /* MacOS X has "az-Arab", "az-Cyrl", "az-Latn". The default script for az on Unix is Latin. */ @@ -952,7 +1320,7 @@ gl_locale_name_canonicalize (char *name) /* Convert script names (ISO 15924) to Unix conventions. See http://www.unicode.org/iso15924/iso15924-codes.html */ typedef struct { const char script[4+1]; const char unixy[9+1]; } - script_entry; + script_entry; static const script_entry script_table[] = { { "Arab", "arabic" }, { "Cyrl", "cyrillic" }, @@ -966,21 +1334,21 @@ gl_locale_name_canonicalize (char *name) i1 = 0; i2 = sizeof (legacy_table) / sizeof (legacy_entry); while (i2 - i1 > 1) - { - /* At this point we know that if name occurs in legacy_table, - its index must be >= i1 and < i2. */ - unsigned int i = (i1 + i2) >> 1; - const legacy_entry *p = &legacy_table[i]; - if (strcmp (name, p->legacy) < 0) - i2 = i; - else - i1 = i; - } + { + /* At this point we know that if name occurs in legacy_table, + its index must be >= i1 and < i2. */ + unsigned int i = (i1 + i2) >> 1; + const legacy_entry *p = &legacy_table[i]; + if (strcmp (name, p->legacy) < 0) + i2 = i; + else + i1 = i; + } if (strcmp (name, legacy_table[i1].legacy) == 0) - { - strcpy (name, legacy_table[i1].unixy); - return; - } + { + strcpy (name, legacy_table[i1].unixy); + return; + } } /* Step 2: Convert using langtag_table and script_table. */ @@ -990,41 +1358,41 @@ gl_locale_name_canonicalize (char *name) i1 = 0; i2 = sizeof (langtag_table) / sizeof (langtag_entry); while (i2 - i1 > 1) - { - /* At this point we know that if name occurs in langtag_table, - its index must be >= i1 and < i2. */ - unsigned int i = (i1 + i2) >> 1; - const langtag_entry *p = &langtag_table[i]; - if (strcmp (name, p->langtag) < 0) - i2 = i; - else - i1 = i; - } + { + /* At this point we know that if name occurs in langtag_table, + its index must be >= i1 and < i2. */ + unsigned int i = (i1 + i2) >> 1; + const langtag_entry *p = &langtag_table[i]; + if (strcmp (name, p->langtag) < 0) + i2 = i; + else + i1 = i; + } if (strcmp (name, langtag_table[i1].langtag) == 0) - { - strcpy (name, langtag_table[i1].unixy); - return; - } + { + strcpy (name, langtag_table[i1].unixy); + return; + } i1 = 0; i2 = sizeof (script_table) / sizeof (script_entry); while (i2 - i1 > 1) - { - /* At this point we know that if (name + 3) occurs in script_table, - its index must be >= i1 and < i2. */ - unsigned int i = (i1 + i2) >> 1; - const script_entry *p = &script_table[i]; - if (strcmp (name + 3, p->script) < 0) - i2 = i; - else - i1 = i; - } + { + /* At this point we know that if (name + 3) occurs in script_table, + its index must be >= i1 and < i2. */ + unsigned int i = (i1 + i2) >> 1; + const script_entry *p = &script_table[i]; + if (strcmp (name + 3, p->script) < 0) + i2 = i; + else + i1 = i; + } if (strcmp (name + 3, script_table[i1].script) == 0) - { - name[2] = '@'; - strcpy (name + 3, script_table[i1].unixy); - return; - } + { + name[2] = '@'; + strcpy (name + 3, script_table[i1].unixy); + return; + } } /* Step 3: Convert new-style dash to Unix underscore. */ @@ -1032,14 +1400,14 @@ gl_locale_name_canonicalize (char *name) char *p; for (p = name; *p != '\0'; p++) if (*p == '-') - *p = '_'; + *p = '_'; } } #endif -#ifdef WIN32_NATIVE +#if defined WIN32_NATIVE || defined __CYGWIN__ /* WIN32 or Cygwin */ /* Canonicalize a Win32 native locale name to a Unix locale name. NAME is a sufficiently large buffer. @@ -1058,19 +1426,19 @@ gl_locale_name_canonicalize (char *name) for (p = name; *p != '\0'; p++) if (*p == '-') { - *p = '_'; - p++; - for (; *p != '\0'; p++) - { - if (*p >= 'a' && *p <= 'z') - *p += 'A' - 'a'; - if (*p == '-') - { - *p = '\0'; - return; - } - } - return; + *p = '_'; + p++; + for (; *p != '\0'; p++) + { + if (*p >= 'a' && *p <= 'z') + *p += 'A' - 'a'; + if (*p == '-') + { + *p = '\0'; + return; + } + } + return; } } @@ -1087,15 +1455,15 @@ gl_locale_name_from_win32_LANGID (LANGID langid) static char namebuf[256]; /* Query the system's notion of locale name. - On Windows95/98/ME, GetLocaleInfoA returns some incorrect results. - But we don't need to support systems that are so old. */ + On Windows95/98/ME, GetLocaleInfoA returns some incorrect results. + But we don't need to support systems that are so old. */ if (GetLocaleInfoA (MAKELCID (langid, SORT_DEFAULT), LOCALE_SNAME, - namebuf, sizeof (namebuf) - 1)) - { - /* Convert it to a Unix locale name. */ - gl_locale_name_canonicalize (namebuf); - return namebuf; - } + namebuf, sizeof (namebuf) - 1)) + { + /* Convert it to a Unix locale name. */ + gl_locale_name_canonicalize (namebuf); + return namebuf; + } } /* Internet Explorer has an LCID to RFC3066 name mapping stored in HKEY_CLASSES_ROOT\Mime\Database\Rfc1766. But we better don't use that @@ -1115,426 +1483,1008 @@ gl_locale_name_from_win32_LANGID (LANGID langid) For details about languages, see http://www.ethnologue.com/ . */ switch (primary) { - case LANG_AFRIKAANS: return "af_ZA"; - case LANG_ALBANIAN: return "sq_AL"; - case LANG_AMHARIC: return "am_ET"; + case LANG_AFRIKAANS: + switch (sub) + { + case SUBLANG_AFRIKAANS_SOUTH_AFRICA: return "af_ZA"; + } + return "af"; + case LANG_ALBANIAN: + switch (sub) + { + case SUBLANG_ALBANIAN_ALBANIA: return "sq_AL"; + } + return "sq"; + case LANG_ALSATIAN: + switch (sub) + { + case SUBLANG_ALSATIAN_FRANCE: return "gsw_FR"; + } + return "gsw"; + case LANG_AMHARIC: + switch (sub) + { + case SUBLANG_AMHARIC_ETHIOPIA: return "am_ET"; + } + return "am"; case LANG_ARABIC: - switch (sub) - { - case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA"; - case SUBLANG_ARABIC_IRAQ: return "ar_IQ"; - case SUBLANG_ARABIC_EGYPT: return "ar_EG"; - case SUBLANG_ARABIC_LIBYA: return "ar_LY"; - case SUBLANG_ARABIC_ALGERIA: return "ar_DZ"; - case SUBLANG_ARABIC_MOROCCO: return "ar_MA"; - case SUBLANG_ARABIC_TUNISIA: return "ar_TN"; - case SUBLANG_ARABIC_OMAN: return "ar_OM"; - case SUBLANG_ARABIC_YEMEN: return "ar_YE"; - case SUBLANG_ARABIC_SYRIA: return "ar_SY"; - case SUBLANG_ARABIC_JORDAN: return "ar_JO"; - case SUBLANG_ARABIC_LEBANON: return "ar_LB"; - case SUBLANG_ARABIC_KUWAIT: return "ar_KW"; - case SUBLANG_ARABIC_UAE: return "ar_AE"; - case SUBLANG_ARABIC_BAHRAIN: return "ar_BH"; - case SUBLANG_ARABIC_QATAR: return "ar_QA"; - } - return "ar"; - case LANG_ARMENIAN: return "hy_AM"; - case LANG_ASSAMESE: return "as_IN"; + switch (sub) + { + case SUBLANG_ARABIC_SAUDI_ARABIA: return "ar_SA"; + case SUBLANG_ARABIC_IRAQ: return "ar_IQ"; + case SUBLANG_ARABIC_EGYPT: return "ar_EG"; + case SUBLANG_ARABIC_LIBYA: return "ar_LY"; + case SUBLANG_ARABIC_ALGERIA: return "ar_DZ"; + case SUBLANG_ARABIC_MOROCCO: return "ar_MA"; + case SUBLANG_ARABIC_TUNISIA: return "ar_TN"; + case SUBLANG_ARABIC_OMAN: return "ar_OM"; + case SUBLANG_ARABIC_YEMEN: return "ar_YE"; + case SUBLANG_ARABIC_SYRIA: return "ar_SY"; + case SUBLANG_ARABIC_JORDAN: return "ar_JO"; + case SUBLANG_ARABIC_LEBANON: return "ar_LB"; + case SUBLANG_ARABIC_KUWAIT: return "ar_KW"; + case SUBLANG_ARABIC_UAE: return "ar_AE"; + case SUBLANG_ARABIC_BAHRAIN: return "ar_BH"; + case SUBLANG_ARABIC_QATAR: return "ar_QA"; + } + return "ar"; + case LANG_ARMENIAN: + switch (sub) + { + case SUBLANG_ARMENIAN_ARMENIA: return "hy_AM"; + } + return "hy"; + case LANG_ASSAMESE: + switch (sub) + { + case SUBLANG_ASSAMESE_INDIA: return "as_IN"; + } + return "as"; case LANG_AZERI: - switch (sub) - { - /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */ - case SUBLANG_AZERI_LATIN: return "az_AZ@latin"; - case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic"; - } - return "az"; + switch (sub) + { + /* FIXME: Adjust this when Azerbaijani locales appear on Unix. */ + case 0x1e: return "az@latin"; + case SUBLANG_AZERI_LATIN: return "az_AZ@latin"; + case 0x1d: return "az@cyrillic"; + case SUBLANG_AZERI_CYRILLIC: return "az_AZ@cyrillic"; + } + return "az"; + case LANG_BASHKIR: + switch (sub) + { + case SUBLANG_BASHKIR_RUSSIA: return "ba_RU"; + } + return "ba"; case LANG_BASQUE: - switch (sub) - { - case SUBLANG_DEFAULT: return "eu_ES"; - } - return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */ - case LANG_BELARUSIAN: return "be_BY"; + switch (sub) + { + case SUBLANG_BASQUE_BASQUE: return "eu_ES"; + } + return "eu"; /* Ambiguous: could be "eu_ES" or "eu_FR". */ + case LANG_BELARUSIAN: + switch (sub) + { + case SUBLANG_BELARUSIAN_BELARUS: return "be_BY"; + } + return "be"; case LANG_BENGALI: - switch (sub) - { - case SUBLANG_BENGALI_INDIA: return "bn_IN"; - case SUBLANG_BENGALI_BANGLADESH: return "bn_BD"; - } - return "bn"; - case LANG_BULGARIAN: return "bg_BG"; - case LANG_BURMESE: return "my_MM"; - case LANG_CAMBODIAN: return "km_KH"; - case LANG_CATALAN: return "ca_ES"; - case LANG_CHEROKEE: return "chr_US"; + switch (sub) + { + case SUBLANG_BENGALI_INDIA: return "bn_IN"; + case SUBLANG_BENGALI_BANGLADESH: return "bn_BD"; + } + return "bn"; + case LANG_BRETON: + switch (sub) + { + case SUBLANG_BRETON_FRANCE: return "br_FR"; + } + return "br"; + case LANG_BULGARIAN: + switch (sub) + { + case SUBLANG_BULGARIAN_BULGARIA: return "bg_BG"; + } + return "bg"; + case LANG_BURMESE: + switch (sub) + { + case SUBLANG_DEFAULT: return "my_MM"; + } + return "my"; + case LANG_CAMBODIAN: + switch (sub) + { + case SUBLANG_CAMBODIAN_CAMBODIA: return "km_KH"; + } + return "km"; + case LANG_CATALAN: + switch (sub) + { + case SUBLANG_CATALAN_SPAIN: return "ca_ES"; + } + return "ca"; + case LANG_CHEROKEE: + switch (sub) + { + case SUBLANG_DEFAULT: return "chr_US"; + } + return "chr"; case LANG_CHINESE: - switch (sub) - { - case SUBLANG_CHINESE_TRADITIONAL: return "zh_TW"; - case SUBLANG_CHINESE_SIMPLIFIED: return "zh_CN"; - case SUBLANG_CHINESE_HONGKONG: return "zh_HK"; - case SUBLANG_CHINESE_SINGAPORE: return "zh_SG"; - case SUBLANG_CHINESE_MACAU: return "zh_MO"; - } - return "zh"; - case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN - * What used to be called Serbo-Croatian - * should really now be two separate - * languages because of political reasons. - * (Says tml, who knows nothing about Serbian - * or Croatian.) - * (I can feel those flames coming already.) - */ - switch (sub) - { - case SUBLANG_CROATIAN_CROATIA: return "hr_HR"; - case SUBLANG_SERBIAN_LATIN: return "sr_CS"; - case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic"; - case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN: return "hr_BA"; - case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN: return "bs_BA"; - case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC: return "bs_BA@cyrillic"; - } - return "hr"; - case LANG_CZECH: return "cs_CZ"; - case LANG_DANISH: return "da_DK"; - case LANG_DIVEHI: return "dv_MV"; + switch (sub) + { + case SUBLANG_CHINESE_TRADITIONAL: case 0x1f: return "zh_TW"; + case SUBLANG_CHINESE_SIMPLIFIED: case 0x00: return "zh_CN"; + case SUBLANG_CHINESE_HONGKONG: return "zh_HK"; /* traditional */ + case SUBLANG_CHINESE_SINGAPORE: return "zh_SG"; /* simplified */ + case SUBLANG_CHINESE_MACAU: return "zh_MO"; /* traditional */ + } + return "zh"; + case LANG_CORSICAN: + switch (sub) + { + case SUBLANG_CORSICAN_FRANCE: return "co_FR"; + } + return "co"; + case LANG_CROATIAN: /* LANG_CROATIAN == LANG_SERBIAN == LANG_BOSNIAN + * What used to be called Serbo-Croatian + * should really now be two separate + * languages because of political reasons. + * (Says tml, who knows nothing about Serbian + * or Croatian.) + * (I can feel those flames coming already.) + */ + switch (sub) + { + /* Croatian */ + case 0x00: return "hr"; + case SUBLANG_CROATIAN_CROATIA: return "hr_HR"; + case SUBLANG_CROATIAN_BOSNIA_HERZEGOVINA_LATIN: return "hr_BA"; + /* Serbian */ + case 0x1f: return "sr"; + case 0x1c: return "sr"; /* latin */ + case SUBLANG_SERBIAN_LATIN: return "sr_CS"; /* latin */ + case 0x09: return "sr_RS"; /* latin */ + case 0x0b: return "sr_ME"; /* latin */ + case 0x06: return "sr_BA"; /* latin */ + case 0x1b: return "sr@cyrillic"; + case SUBLANG_SERBIAN_CYRILLIC: return "sr_CS@cyrillic"; + case 0x0a: return "sr_RS@cyrillic"; + case 0x0c: return "sr_ME@cyrillic"; + case 0x07: return "sr_BA@cyrillic"; + /* Bosnian */ + case 0x1e: return "bs"; + case 0x1a: return "bs"; /* latin */ + case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_LATIN: return "bs_BA"; /* latin */ + case 0x19: return "bs@cyrillic"; + case SUBLANG_BOSNIAN_BOSNIA_HERZEGOVINA_CYRILLIC: return "bs_BA@cyrillic"; + } + return "hr"; + case LANG_CZECH: + switch (sub) + { + case SUBLANG_CZECH_CZECH_REPUBLIC: return "cs_CZ"; + } + return "cs"; + case LANG_DANISH: + switch (sub) + { + case SUBLANG_DANISH_DENMARK: return "da_DK"; + } + return "da"; + case LANG_DARI: + /* FIXME: Adjust this when such locales appear on Unix. */ + switch (sub) + { + case SUBLANG_DARI_AFGHANISTAN: return "prs_AF"; + } + return "prs"; + case LANG_DIVEHI: + switch (sub) + { + case SUBLANG_DIVEHI_MALDIVES: return "dv_MV"; + } + return "dv"; case LANG_DUTCH: - switch (sub) - { - case SUBLANG_DUTCH: return "nl_NL"; - case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE"; - } - return "nl"; - case LANG_EDO: return "bin_NG"; + switch (sub) + { + case SUBLANG_DUTCH: return "nl_NL"; + case SUBLANG_DUTCH_BELGIAN: /* FLEMISH, VLAAMS */ return "nl_BE"; + case SUBLANG_DUTCH_SURINAM: return "nl_SR"; + } + return "nl"; + case LANG_EDO: + switch (sub) + { + case SUBLANG_DEFAULT: return "bin_NG"; + } + return "bin"; case LANG_ENGLISH: - switch (sub) - { - /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought - * English was the language spoken in England. - * Oh well. - */ - case SUBLANG_ENGLISH_US: return "en_US"; - case SUBLANG_ENGLISH_UK: return "en_GB"; - case SUBLANG_ENGLISH_AUS: return "en_AU"; - case SUBLANG_ENGLISH_CAN: return "en_CA"; - case SUBLANG_ENGLISH_NZ: return "en_NZ"; - case SUBLANG_ENGLISH_EIRE: return "en_IE"; - case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA"; - case SUBLANG_ENGLISH_JAMAICA: return "en_JM"; - case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */ - case SUBLANG_ENGLISH_BELIZE: return "en_BZ"; - case SUBLANG_ENGLISH_TRINIDAD: return "en_TT"; - case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW"; - case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH"; - case SUBLANG_ENGLISH_INDONESIA: return "en_ID"; - case SUBLANG_ENGLISH_HONGKONG: return "en_HK"; - case SUBLANG_ENGLISH_INDIA: return "en_IN"; - case SUBLANG_ENGLISH_MALAYSIA: return "en_MY"; - case SUBLANG_ENGLISH_SINGAPORE: return "en_SG"; - } - return "en"; - case LANG_ESTONIAN: return "et_EE"; - case LANG_FAEROESE: return "fo_FO"; - case LANG_FARSI: return "fa_IR"; - case LANG_FINNISH: return "fi_FI"; + switch (sub) + { + /* SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. Heh. I thought + * English was the language spoken in England. + * Oh well. + */ + case SUBLANG_ENGLISH_US: return "en_US"; + case SUBLANG_ENGLISH_UK: return "en_GB"; + case SUBLANG_ENGLISH_AUS: return "en_AU"; + case SUBLANG_ENGLISH_CAN: return "en_CA"; + case SUBLANG_ENGLISH_NZ: return "en_NZ"; + case SUBLANG_ENGLISH_EIRE: return "en_IE"; + case SUBLANG_ENGLISH_SOUTH_AFRICA: return "en_ZA"; + case SUBLANG_ENGLISH_JAMAICA: return "en_JM"; + case SUBLANG_ENGLISH_CARIBBEAN: return "en_GD"; /* Grenada? */ + case SUBLANG_ENGLISH_BELIZE: return "en_BZ"; + case SUBLANG_ENGLISH_TRINIDAD: return "en_TT"; + case SUBLANG_ENGLISH_ZIMBABWE: return "en_ZW"; + case SUBLANG_ENGLISH_PHILIPPINES: return "en_PH"; + case SUBLANG_ENGLISH_INDONESIA: return "en_ID"; + case SUBLANG_ENGLISH_HONGKONG: return "en_HK"; + case SUBLANG_ENGLISH_INDIA: return "en_IN"; + case SUBLANG_ENGLISH_MALAYSIA: return "en_MY"; + case SUBLANG_ENGLISH_SINGAPORE: return "en_SG"; + } + return "en"; + case LANG_ESTONIAN: + switch (sub) + { + case SUBLANG_ESTONIAN_ESTONIA: return "et_EE"; + } + return "et"; + case LANG_FAEROESE: + switch (sub) + { + case SUBLANG_FAEROESE_FAROE_ISLANDS: return "fo_FO"; + } + return "fo"; + case LANG_FARSI: + switch (sub) + { + case SUBLANG_FARSI_IRAN: return "fa_IR"; + } + return "fa"; + case LANG_FINNISH: + switch (sub) + { + case SUBLANG_FINNISH_FINLAND: return "fi_FI"; + } + return "fi"; case LANG_FRENCH: - switch (sub) - { - case SUBLANG_FRENCH: return "fr_FR"; - case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE"; - case SUBLANG_FRENCH_CANADIAN: return "fr_CA"; - case SUBLANG_FRENCH_SWISS: return "fr_CH"; - case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU"; - case SUBLANG_FRENCH_MONACO: return "fr_MC"; - case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */ - case SUBLANG_FRENCH_REUNION: return "fr_RE"; - case SUBLANG_FRENCH_CONGO: return "fr_CG"; - case SUBLANG_FRENCH_SENEGAL: return "fr_SN"; - case SUBLANG_FRENCH_CAMEROON: return "fr_CM"; - case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI"; - case SUBLANG_FRENCH_MALI: return "fr_ML"; - case SUBLANG_FRENCH_MOROCCO: return "fr_MA"; - case SUBLANG_FRENCH_HAITI: return "fr_HT"; - } - return "fr"; - case LANG_FRISIAN: return "fy_NL"; + switch (sub) + { + case SUBLANG_FRENCH: return "fr_FR"; + case SUBLANG_FRENCH_BELGIAN: /* WALLOON */ return "fr_BE"; + case SUBLANG_FRENCH_CANADIAN: return "fr_CA"; + case SUBLANG_FRENCH_SWISS: return "fr_CH"; + case SUBLANG_FRENCH_LUXEMBOURG: return "fr_LU"; + case SUBLANG_FRENCH_MONACO: return "fr_MC"; + case SUBLANG_FRENCH_WESTINDIES: return "fr"; /* Caribbean? */ + case SUBLANG_FRENCH_REUNION: return "fr_RE"; + case SUBLANG_FRENCH_CONGO: return "fr_CG"; + case SUBLANG_FRENCH_SENEGAL: return "fr_SN"; + case SUBLANG_FRENCH_CAMEROON: return "fr_CM"; + case SUBLANG_FRENCH_COTEDIVOIRE: return "fr_CI"; + case SUBLANG_FRENCH_MALI: return "fr_ML"; + case SUBLANG_FRENCH_MOROCCO: return "fr_MA"; + case SUBLANG_FRENCH_HAITI: return "fr_HT"; + } + return "fr"; + case LANG_FRISIAN: + switch (sub) + { + case SUBLANG_FRISIAN_NETHERLANDS: return "fy_NL"; + } + return "fy"; case LANG_FULFULDE: - /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */ - return "ff_NG"; + /* Spoken in Nigeria, Guinea, Senegal, Mali, Niger, Cameroon, Benin. */ + switch (sub) + { + case SUBLANG_DEFAULT: return "ff_NG"; + } + return "ff"; case LANG_GAELIC: - switch (sub) - { - case 0x01: /* SCOTTISH */ return "gd_GB"; - case 0x02: /* IRISH */ return "ga_IE"; - } - return "C"; - case LANG_GALICIAN: return "gl_ES"; - case LANG_GEORGIAN: return "ka_GE"; + switch (sub) + { + case 0x01: /* SCOTTISH */ + /* old, superseded by LANG_SCOTTISH_GAELIC */ + return "gd_GB"; + case SUBLANG_IRISH_IRELAND: return "ga_IE"; + } + return "ga"; + case LANG_GALICIAN: + switch (sub) + { + case SUBLANG_GALICIAN_SPAIN: return "gl_ES"; + } + return "gl"; + case LANG_GEORGIAN: + switch (sub) + { + case SUBLANG_GEORGIAN_GEORGIA: return "ka_GE"; + } + return "ka"; case LANG_GERMAN: - switch (sub) - { - case SUBLANG_GERMAN: return "de_DE"; - case SUBLANG_GERMAN_SWISS: return "de_CH"; - case SUBLANG_GERMAN_AUSTRIAN: return "de_AT"; - case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU"; - case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI"; - } - return "de"; - case LANG_GREEK: return "el_GR"; - case LANG_GUARANI: return "gn_PY"; - case LANG_GUJARATI: return "gu_IN"; - case LANG_HAUSA: return "ha_NG"; + switch (sub) + { + case SUBLANG_GERMAN: return "de_DE"; + case SUBLANG_GERMAN_SWISS: return "de_CH"; + case SUBLANG_GERMAN_AUSTRIAN: return "de_AT"; + case SUBLANG_GERMAN_LUXEMBOURG: return "de_LU"; + case SUBLANG_GERMAN_LIECHTENSTEIN: return "de_LI"; + } + return "de"; + case LANG_GREEK: + switch (sub) + { + case SUBLANG_GREEK_GREECE: return "el_GR"; + } + return "el"; + case LANG_GREENLANDIC: + switch (sub) + { + case SUBLANG_GREENLANDIC_GREENLAND: return "kl_GL"; + } + return "kl"; + case LANG_GUARANI: + switch (sub) + { + case SUBLANG_DEFAULT: return "gn_PY"; + } + return "gn"; + case LANG_GUJARATI: + switch (sub) + { + case SUBLANG_GUJARATI_INDIA: return "gu_IN"; + } + return "gu"; + case LANG_HAUSA: + switch (sub) + { + case 0x1f: return "ha"; + case SUBLANG_HAUSA_NIGERIA_LATIN: return "ha_NG"; + } + return "ha"; case LANG_HAWAIIAN: - /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers) - or Hawaii Creole English ("cpe_US", 600000 speakers)? */ - return "cpe_US"; - case LANG_HEBREW: return "he_IL"; - case LANG_HINDI: return "hi_IN"; - case LANG_HUNGARIAN: return "hu_HU"; - case LANG_IBIBIO: return "nic_NG"; - case LANG_ICELANDIC: return "is_IS"; - case LANG_IGBO: return "ig_NG"; - case LANG_INDONESIAN: return "id_ID"; - case LANG_INUKTITUT: return "iu_CA"; + /* FIXME: Do they mean Hawaiian ("haw_US", 1000 speakers) + or Hawaii Creole English ("cpe_US", 600000 speakers)? */ + switch (sub) + { + case SUBLANG_DEFAULT: return "cpe_US"; + } + return "cpe"; + case LANG_HEBREW: + switch (sub) + { + case SUBLANG_HEBREW_ISRAEL: return "he_IL"; + } + return "he"; + case LANG_HINDI: + switch (sub) + { + case SUBLANG_HINDI_INDIA: return "hi_IN"; + } + return "hi"; + case LANG_HUNGARIAN: + switch (sub) + { + case SUBLANG_HUNGARIAN_HUNGARY: return "hu_HU"; + } + return "hu"; + case LANG_IBIBIO: + switch (sub) + { + case SUBLANG_DEFAULT: return "nic_NG"; + } + return "nic"; + case LANG_ICELANDIC: + switch (sub) + { + case SUBLANG_ICELANDIC_ICELAND: return "is_IS"; + } + return "is"; + case LANG_IGBO: + switch (sub) + { + case SUBLANG_IGBO_NIGERIA: return "ig_NG"; + } + return "ig"; + case LANG_INDONESIAN: + switch (sub) + { + case SUBLANG_INDONESIAN_INDONESIA: return "id_ID"; + } + return "id"; + case LANG_INUKTITUT: + switch (sub) + { + case 0x1e: return "iu"; /* syllabic */ + case SUBLANG_INUKTITUT_CANADA: return "iu_CA"; /* syllabic */ + case 0x1f: return "iu@latin"; + case SUBLANG_INUKTITUT_CANADA_LATIN: return "iu_CA@latin"; + } + return "iu"; case LANG_ITALIAN: - switch (sub) - { - case SUBLANG_ITALIAN: return "it_IT"; - case SUBLANG_ITALIAN_SWISS: return "it_CH"; - } - return "it"; - case LANG_JAPANESE: return "ja_JP"; - case LANG_KANNADA: return "kn_IN"; - case LANG_KANURI: return "kr_NG"; + switch (sub) + { + case SUBLANG_ITALIAN: return "it_IT"; + case SUBLANG_ITALIAN_SWISS: return "it_CH"; + } + return "it"; + case LANG_JAPANESE: + switch (sub) + { + case SUBLANG_JAPANESE_JAPAN: return "ja_JP"; + } + return "ja"; + case LANG_KANNADA: + switch (sub) + { + case SUBLANG_KANNADA_INDIA: return "kn_IN"; + } + return "kn"; + case LANG_KANURI: + switch (sub) + { + case SUBLANG_DEFAULT: return "kr_NG"; + } + return "kr"; case LANG_KASHMIRI: - switch (sub) - { - case SUBLANG_DEFAULT: return "ks_PK"; - case SUBLANG_KASHMIRI_INDIA: return "ks_IN"; - } - return "ks"; - case LANG_KAZAK: return "kk_KZ"; + switch (sub) + { + case SUBLANG_DEFAULT: return "ks_PK"; + case SUBLANG_KASHMIRI_INDIA: return "ks_IN"; + } + return "ks"; + case LANG_KAZAK: + switch (sub) + { + case SUBLANG_KAZAK_KAZAKHSTAN: return "kk_KZ"; + } + return "kk"; + case LANG_KICHE: + /* FIXME: Adjust this when such locales appear on Unix. */ + switch (sub) + { + case SUBLANG_KICHE_GUATEMALA: return "qut_GT"; + } + return "qut"; + case LANG_KINYARWANDA: + switch (sub) + { + case SUBLANG_KINYARWANDA_RWANDA: return "rw_RW"; + } + return "rw"; case LANG_KONKANI: - /* FIXME: Adjust this when such locales appear on Unix. */ - return "kok_IN"; - case LANG_KOREAN: return "ko_KR"; - case LANG_KYRGYZ: return "ky_KG"; - case LANG_LAO: return "lo_LA"; - case LANG_LATIN: return "la_VA"; - case LANG_LATVIAN: return "lv_LV"; - case LANG_LITHUANIAN: return "lt_LT"; - case LANG_MACEDONIAN: return "mk_MK"; + /* FIXME: Adjust this when such locales appear on Unix. */ + switch (sub) + { + case SUBLANG_KONKANI_INDIA: return "kok_IN"; + } + return "kok"; + case LANG_KOREAN: + switch (sub) + { + case SUBLANG_DEFAULT: return "ko_KR"; + } + return "ko"; + case LANG_KYRGYZ: + switch (sub) + { + case SUBLANG_KYRGYZ_KYRGYZSTAN: return "ky_KG"; + } + return "ky"; + case LANG_LAO: + switch (sub) + { + case SUBLANG_LAO_LAOS: return "lo_LA"; + } + return "lo"; + case LANG_LATIN: + switch (sub) + { + case SUBLANG_DEFAULT: return "la_VA"; + } + return "la"; + case LANG_LATVIAN: + switch (sub) + { + case SUBLANG_LATVIAN_LATVIA: return "lv_LV"; + } + return "lv"; + case LANG_LITHUANIAN: + switch (sub) + { + case SUBLANG_LITHUANIAN_LITHUANIA: return "lt_LT"; + } + return "lt"; + case LANG_LUXEMBOURGISH: + switch (sub) + { + case SUBLANG_LUXEMBOURGISH_LUXEMBOURG: return "lb_LU"; + } + return "lb"; + case LANG_MACEDONIAN: + switch (sub) + { + case SUBLANG_MACEDONIAN_MACEDONIA: return "mk_MK"; + } + return "mk"; case LANG_MALAY: - switch (sub) - { - case SUBLANG_MALAY_MALAYSIA: return "ms_MY"; - case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN"; - } - return "ms"; - case LANG_MALAYALAM: return "ml_IN"; - case LANG_MALTESE: return "mt_MT"; + switch (sub) + { + case SUBLANG_MALAY_MALAYSIA: return "ms_MY"; + case SUBLANG_MALAY_BRUNEI_DARUSSALAM: return "ms_BN"; + } + return "ms"; + case LANG_MALAYALAM: + switch (sub) + { + case SUBLANG_MALAYALAM_INDIA: return "ml_IN"; + } + return "ml"; + case LANG_MALTESE: + switch (sub) + { + case SUBLANG_MALTESE_MALTA: return "mt_MT"; + } + return "mt"; case LANG_MANIPURI: - /* FIXME: Adjust this when such locales appear on Unix. */ - return "mni_IN"; - case LANG_MAORI: return "mi_NZ"; - case LANG_MARATHI: return "mr_IN"; + /* FIXME: Adjust this when such locales appear on Unix. */ + switch (sub) + { + case SUBLANG_DEFAULT: return "mni_IN"; + } + return "mni"; + case LANG_MAORI: + switch (sub) + { + case SUBLANG_MAORI_NEW_ZEALAND: return "mi_NZ"; + } + return "mi"; + case LANG_MAPUDUNGUN: + switch (sub) + { + case SUBLANG_MAPUDUNGUN_CHILE: return "arn_CL"; + } + return "arn"; + case LANG_MARATHI: + switch (sub) + { + case SUBLANG_MARATHI_INDIA: return "mr_IN"; + } + return "mr"; + case LANG_MOHAWK: + switch (sub) + { + case SUBLANG_MOHAWK_CANADA: return "moh_CA"; + } + return "moh"; case LANG_MONGOLIAN: - switch (sub) - { - case SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA: return "mn_MN"; - case SUBLANG_MONGOLIAN_PRC: return "mn_CN"; - } - return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */ + switch (sub) + { + case SUBLANG_MONGOLIAN_CYRILLIC_MONGOLIA: case 0x1e: return "mn_MN"; + case SUBLANG_MONGOLIAN_PRC: case 0x1f: return "mn_CN"; + } + return "mn"; /* Ambiguous: could be "mn_CN" or "mn_MN". */ case LANG_NEPALI: - switch (sub) - { - case SUBLANG_DEFAULT: return "ne_NP"; - case SUBLANG_NEPALI_INDIA: return "ne_IN"; - } - return "ne"; + switch (sub) + { + case SUBLANG_NEPALI_NEPAL: return "ne_NP"; + case SUBLANG_NEPALI_INDIA: return "ne_IN"; + } + return "ne"; case LANG_NORWEGIAN: - switch (sub) - { - case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO"; - case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO"; - } - return "no"; - case LANG_ORIYA: return "or_IN"; - case LANG_OROMO: return "om_ET"; - case LANG_PAPIAMENTU: return "pap_AN"; + switch (sub) + { + case 0x1f: return "nb"; + case SUBLANG_NORWEGIAN_BOKMAL: return "nb_NO"; + case 0x1e: return "nn"; + case SUBLANG_NORWEGIAN_NYNORSK: return "nn_NO"; + } + return "no"; + case LANG_OCCITAN: + switch (sub) + { + case SUBLANG_OCCITAN_FRANCE: return "oc_FR"; + } + return "oc"; + case LANG_ORIYA: + switch (sub) + { + case SUBLANG_ORIYA_INDIA: return "or_IN"; + } + return "or"; + case LANG_OROMO: + switch (sub) + { + case SUBLANG_DEFAULT: return "om_ET"; + } + return "om"; + case LANG_PAPIAMENTU: + switch (sub) + { + case SUBLANG_DEFAULT: return "pap_AN"; + } + return "pap"; case LANG_PASHTO: - return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */ - case LANG_POLISH: return "pl_PL"; + switch (sub) + { + case SUBLANG_PASHTO_AFGHANISTAN: return "ps_AF"; + } + return "ps"; /* Ambiguous: could be "ps_PK" or "ps_AF". */ + case LANG_POLISH: + switch (sub) + { + case SUBLANG_POLISH_POLAND: return "pl_PL"; + } + return "pl"; case LANG_PORTUGUESE: - switch (sub) - { - case SUBLANG_PORTUGUESE: return "pt_PT"; - /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT. - Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */ - case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR"; - } - return "pt"; + switch (sub) + { + /* Hmm. SUBLANG_PORTUGUESE_BRAZILIAN == SUBLANG_DEFAULT. + Same phenomenon as SUBLANG_ENGLISH_US == SUBLANG_DEFAULT. */ + case SUBLANG_PORTUGUESE_BRAZILIAN: return "pt_BR"; + case SUBLANG_PORTUGUESE: return "pt_PT"; + } + return "pt"; case LANG_PUNJABI: - switch (sub) - { - case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */ - case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */ - } - return "pa"; + switch (sub) + { + case SUBLANG_PUNJABI_INDIA: return "pa_IN"; /* Gurmukhi script */ + case SUBLANG_PUNJABI_PAKISTAN: return "pa_PK"; /* Arabic script */ + } + return "pa"; case LANG_QUECHUA: - switch (sub) - { - case SUBLANG_QUECHUA_BOLIVIA: return "qu_BO"; - case SUBLANG_QUECHUA_ECUADOR: return "qu_EC"; - case SUBLANG_QUECHUA_PERU: return "qu_PE"; - } - return "qu"; - case LANG_RHAETO_ROMANCE: return "rm_CH"; + /* Note: Microsoft uses the non-ISO language code "quz". */ + switch (sub) + { + case SUBLANG_QUECHUA_BOLIVIA: return "qu_BO"; + case SUBLANG_QUECHUA_ECUADOR: return "qu_EC"; + case SUBLANG_QUECHUA_PERU: return "qu_PE"; + } + return "qu"; case LANG_ROMANIAN: - switch (sub) - { - case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO"; - case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD"; - } - return "ro"; + switch (sub) + { + case SUBLANG_ROMANIAN_ROMANIA: return "ro_RO"; + case SUBLANG_ROMANIAN_MOLDOVA: return "ro_MD"; + } + return "ro"; + case LANG_ROMANSH: + switch (sub) + { + case SUBLANG_ROMANSH_SWITZERLAND: return "rm_CH"; + } + return "rm"; case LANG_RUSSIAN: - switch (sub) - { - case SUBLANG_RUSSIAN_RUSSIA: return "ru_RU"; - case SUBLANG_RUSSIAN_MOLDAVIA: return "ru_MD"; - } - return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */ - case LANG_SAAMI: /* actually Northern Sami */ return "se_NO"; - case LANG_SANSKRIT: return "sa_IN"; + switch (sub) + { + case SUBLANG_RUSSIAN_RUSSIA: return "ru_RU"; + case SUBLANG_RUSSIAN_MOLDAVIA: return "ru_MD"; + } + return "ru"; /* Ambiguous: could be "ru_RU" or "ru_UA" or "ru_MD". */ + case LANG_SAMI: + switch (sub) + { + /* Northern Sami */ + case 0x00: return "se"; + case SUBLANG_SAMI_NORTHERN_NORWAY: return "se_NO"; + case SUBLANG_SAMI_NORTHERN_SWEDEN: return "se_SE"; + case SUBLANG_SAMI_NORTHERN_FINLAND: return "se_FI"; + /* Lule Sami */ + case 0x1f: return "smj"; + case SUBLANG_SAMI_LULE_NORWAY: return "smj_NO"; + case SUBLANG_SAMI_LULE_SWEDEN: return "smj_SE"; + /* Southern Sami */ + case 0x1e: return "sma"; + case SUBLANG_SAMI_SOUTHERN_NORWAY: return "sma_NO"; + case SUBLANG_SAMI_SOUTHERN_SWEDEN: return "sma_SE"; + /* Skolt Sami */ + case 0x1d: return "sms"; + case SUBLANG_SAMI_SKOLT_FINLAND: return "sms_FI"; + /* Inari Sami */ + case 0x1c: return "smn"; + case SUBLANG_SAMI_INARI_FINLAND: return "smn_FI"; + } + return "se"; /* or "smi"? */ + case LANG_SANSKRIT: + switch (sub) + { + case SUBLANG_SANSKRIT_INDIA: return "sa_IN"; + } + return "sa"; + case LANG_SCOTTISH_GAELIC: + switch (sub) + { + case SUBLANG_DEFAULT: return "gd_GB"; + } + return "gd"; case LANG_SINDHI: - switch (sub) - { - case SUBLANG_SINDHI_INDIA: return "sd_IN"; - case SUBLANG_SINDHI_PAKISTAN: return "sd_PK"; - /*case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF";*/ - } - return "sd"; - case LANG_SINHALESE: return "si_LK"; - case LANG_SLOVAK: return "sk_SK"; - case LANG_SLOVENIAN: return "sl_SI"; - case LANG_SOMALI: return "so_SO"; + switch (sub) + { + case SUBLANG_SINDHI_INDIA: return "sd_IN"; + case SUBLANG_SINDHI_PAKISTAN: return "sd_PK"; + /*case SUBLANG_SINDHI_AFGHANISTAN: return "sd_AF";*/ + } + return "sd"; + case LANG_SINHALESE: + switch (sub) + { + case SUBLANG_SINHALESE_SRI_LANKA: return "si_LK"; + } + return "si"; + case LANG_SLOVAK: + switch (sub) + { + case SUBLANG_SLOVAK_SLOVAKIA: return "sk_SK"; + } + return "sk"; + case LANG_SLOVENIAN: + switch (sub) + { + case SUBLANG_SLOVENIAN_SLOVENIA: return "sl_SI"; + } + return "sl"; + case LANG_SOMALI: + switch (sub) + { + case SUBLANG_DEFAULT: return "so_SO"; + } + return "so"; case LANG_SORBIAN: - /* FIXME: Adjust this when such locales appear on Unix. */ - return "wen_DE"; + /* FIXME: Adjust this when such locales appear on Unix. */ + switch (sub) + { + /* Upper Sorbian */ + case 0x00: return "hsb"; + case SUBLANG_UPPER_SORBIAN_GERMANY: return "hsb_DE"; + /* Lower Sorbian */ + case 0x1f: return "dsb"; + case SUBLANG_LOWER_SORBIAN_GERMANY: return "dsb_DE"; + } + return "wen"; case LANG_SOTHO: - /* calls - it "Sepedi"; according to - - - it's the same as Northern Sotho. */ - return "nso_ZA"; + /* calls + it "Sepedi"; according to + + + it's the same as Northern Sotho. */ + switch (sub) + { + case SUBLANG_SOTHO_SOUTH_AFRICA: return "nso_ZA"; + } + return "nso"; case LANG_SPANISH: - switch (sub) - { - case SUBLANG_SPANISH: return "es_ES"; - case SUBLANG_SPANISH_MEXICAN: return "es_MX"; - case SUBLANG_SPANISH_MODERN: - return "es_ES@modern"; /* not seen on Unix */ - case SUBLANG_SPANISH_GUATEMALA: return "es_GT"; - case SUBLANG_SPANISH_COSTA_RICA: return "es_CR"; - case SUBLANG_SPANISH_PANAMA: return "es_PA"; - case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO"; - case SUBLANG_SPANISH_VENEZUELA: return "es_VE"; - case SUBLANG_SPANISH_COLOMBIA: return "es_CO"; - case SUBLANG_SPANISH_PERU: return "es_PE"; - case SUBLANG_SPANISH_ARGENTINA: return "es_AR"; - case SUBLANG_SPANISH_ECUADOR: return "es_EC"; - case SUBLANG_SPANISH_CHILE: return "es_CL"; - case SUBLANG_SPANISH_URUGUAY: return "es_UY"; - case SUBLANG_SPANISH_PARAGUAY: return "es_PY"; - case SUBLANG_SPANISH_BOLIVIA: return "es_BO"; - case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV"; - case SUBLANG_SPANISH_HONDURAS: return "es_HN"; - case SUBLANG_SPANISH_NICARAGUA: return "es_NI"; - case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR"; - case SUBLANG_SPANISH_US: return "es_US"; - } - return "es"; - case LANG_SUTU: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */ - case LANG_SWAHILI: return "sw_KE"; + switch (sub) + { + case SUBLANG_SPANISH: return "es_ES"; + case SUBLANG_SPANISH_MEXICAN: return "es_MX"; + case SUBLANG_SPANISH_MODERN: + return "es_ES@modern"; /* not seen on Unix */ + case SUBLANG_SPANISH_GUATEMALA: return "es_GT"; + case SUBLANG_SPANISH_COSTA_RICA: return "es_CR"; + case SUBLANG_SPANISH_PANAMA: return "es_PA"; + case SUBLANG_SPANISH_DOMINICAN_REPUBLIC: return "es_DO"; + case SUBLANG_SPANISH_VENEZUELA: return "es_VE"; + case SUBLANG_SPANISH_COLOMBIA: return "es_CO"; + case SUBLANG_SPANISH_PERU: return "es_PE"; + case SUBLANG_SPANISH_ARGENTINA: return "es_AR"; + case SUBLANG_SPANISH_ECUADOR: return "es_EC"; + case SUBLANG_SPANISH_CHILE: return "es_CL"; + case SUBLANG_SPANISH_URUGUAY: return "es_UY"; + case SUBLANG_SPANISH_PARAGUAY: return "es_PY"; + case SUBLANG_SPANISH_BOLIVIA: return "es_BO"; + case SUBLANG_SPANISH_EL_SALVADOR: return "es_SV"; + case SUBLANG_SPANISH_HONDURAS: return "es_HN"; + case SUBLANG_SPANISH_NICARAGUA: return "es_NI"; + case SUBLANG_SPANISH_PUERTO_RICO: return "es_PR"; + case SUBLANG_SPANISH_US: return "es_US"; + } + return "es"; + case LANG_SUTU: + switch (sub) + { + case SUBLANG_DEFAULT: return "bnt_TZ"; /* or "st_LS" or "nso_ZA"? */ + } + return "bnt"; + case LANG_SWAHILI: + switch (sub) + { + case SUBLANG_SWAHILI_KENYA: return "sw_KE"; + } + return "sw"; case LANG_SWEDISH: - switch (sub) - { - case SUBLANG_DEFAULT: return "sv_SE"; - case SUBLANG_SWEDISH_FINLAND: return "sv_FI"; - } - return "sv"; - case LANG_SYRIAC: return "syr_TR"; /* An extinct language. */ - case LANG_TAGALOG: return "tl_PH"; - case LANG_TAJIK: return "tg_TJ"; + switch (sub) + { + case SUBLANG_SWEDISH_SWEDEN: return "sv_SE"; + case SUBLANG_SWEDISH_FINLAND: return "sv_FI"; + } + return "sv"; + case LANG_SYRIAC: + switch (sub) + { + case SUBLANG_SYRIAC_SYRIA: return "syr_SY"; /* An extinct language. */ + } + return "syr"; + case LANG_TAGALOG: + switch (sub) + { + case SUBLANG_TAGALOG_PHILIPPINES: return "tl_PH"; /* or "fil_PH"? */ + } + return "tl"; /* or "fil"? */ + case LANG_TAJIK: + switch (sub) + { + case 0x1f: return "tg"; + case SUBLANG_TAJIK_TAJIKISTAN: return "tg_TJ"; + } + return "tg"; case LANG_TAMAZIGHT: - switch (sub) - { - /* FIXME: Adjust this when Tamazight locales appear on Unix. */ - case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic"; - case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin"; - } - return "ber_MA"; + /* Note: Microsoft uses the non-ISO language code "tmz". */ + switch (sub) + { + /* FIXME: Adjust this when Tamazight locales appear on Unix. */ + case SUBLANG_TAMAZIGHT_ARABIC: return "ber_MA@arabic"; + case 0x1f: return "ber@latin"; + case SUBLANG_TAMAZIGHT_ALGERIA_LATIN: return "ber_DZ@latin"; + } + return "ber"; case LANG_TAMIL: - switch (sub) - { - case SUBLANG_DEFAULT: return "ta_IN"; - } - return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */ - case LANG_TATAR: return "tt_RU"; - case LANG_TELUGU: return "te_IN"; - case LANG_THAI: return "th_TH"; + switch (sub) + { + case SUBLANG_TAMIL_INDIA: return "ta_IN"; + } + return "ta"; /* Ambiguous: could be "ta_IN" or "ta_LK" or "ta_SG". */ + case LANG_TATAR: + switch (sub) + { + case SUBLANG_TATAR_RUSSIA: return "tt_RU"; + } + return "tt"; + case LANG_TELUGU: + switch (sub) + { + case SUBLANG_TELUGU_INDIA: return "te_IN"; + } + return "te"; + case LANG_THAI: + switch (sub) + { + case SUBLANG_THAI_THAILAND: return "th_TH"; + } + return "th"; case LANG_TIBETAN: - switch (sub) - { - case SUBLANG_TIBETAN_PRC: - /* Most Tibetans would not like "bo_CN". But Tibet does not yet - have a country code of its own. */ - return "bo"; - case SUBLANG_TIBETAN_BHUTAN: return "bo_BT"; - } - return "bo"; + switch (sub) + { + case SUBLANG_TIBETAN_PRC: + /* Most Tibetans would not like "bo_CN". But Tibet does not yet + have a country code of its own. */ + return "bo"; + case SUBLANG_TIBETAN_BHUTAN: return "bo_BT"; + } + return "bo"; case LANG_TIGRINYA: - switch (sub) - { - case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET"; - case SUBLANG_TIGRINYA_ERITREA: return "ti_ER"; - } - return "ti"; - case LANG_TSONGA: return "ts_ZA"; - case LANG_TSWANA: return "tn_BW"; - case LANG_TURKISH: return "tr_TR"; - case LANG_TURKMEN: return "tk_TM"; + switch (sub) + { + case SUBLANG_TIGRINYA_ETHIOPIA: return "ti_ET"; + case SUBLANG_TIGRINYA_ERITREA: return "ti_ER"; + } + return "ti"; + case LANG_TSONGA: + switch (sub) + { + case SUBLANG_DEFAULT: return "ts_ZA"; + } + return "ts"; + case LANG_TSWANA: + /* Spoken in South Africa, Botswana. */ + switch (sub) + { + case SUBLANG_TSWANA_SOUTH_AFRICA: return "tn_ZA"; + } + return "tn"; + case LANG_TURKISH: + switch (sub) + { + case SUBLANG_TURKISH_TURKEY: return "tr_TR"; + } + return "tr"; + case LANG_TURKMEN: + switch (sub) + { + case SUBLANG_TURKMEN_TURKMENISTAN: return "tk_TM"; + } + return "tk"; case LANG_UIGHUR: - switch (sub) - { - case SUBLANG_UIGHUR_PRC: return "ug_CN"; - } - return "ug"; - case LANG_UKRAINIAN: return "uk_UA"; + switch (sub) + { + case SUBLANG_UIGHUR_PRC: return "ug_CN"; + } + return "ug"; + case LANG_UKRAINIAN: + switch (sub) + { + case SUBLANG_UKRAINIAN_UKRAINE: return "uk_UA"; + } + return "uk"; case LANG_URDU: - switch (sub) - { - case SUBLANG_URDU_PAKISTAN: return "ur_PK"; - case SUBLANG_URDU_INDIA: return "ur_IN"; - } - return "ur"; + switch (sub) + { + case SUBLANG_URDU_PAKISTAN: return "ur_PK"; + case SUBLANG_URDU_INDIA: return "ur_IN"; + } + return "ur"; case LANG_UZBEK: - switch (sub) - { - case SUBLANG_UZBEK_LATIN: return "uz_UZ"; - case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic"; - } - return "uz"; - case LANG_VENDA: return "ve_ZA"; - case LANG_VIETNAMESE: return "vi_VN"; - case LANG_WELSH: return "cy_GB"; - case LANG_XHOSA: return "xh_ZA"; - case LANG_YI: return "sit_CN"; - case LANG_YIDDISH: return "yi_IL"; - case LANG_YORUBA: return "yo_NG"; - case LANG_ZULU: return "zu_ZA"; + switch (sub) + { + case 0x1f: return "uz"; + case SUBLANG_UZBEK_LATIN: return "uz_UZ"; + case 0x1e: return "uz@cyrillic"; + case SUBLANG_UZBEK_CYRILLIC: return "uz_UZ@cyrillic"; + } + return "uz"; + case LANG_VENDA: + switch (sub) + { + case SUBLANG_DEFAULT: return "ve_ZA"; + } + return "ve"; + case LANG_VIETNAMESE: + switch (sub) + { + case SUBLANG_VIETNAMESE_VIETNAM: return "vi_VN"; + } + return "vi"; + case LANG_WELSH: + switch (sub) + { + case SUBLANG_WELSH_UNITED_KINGDOM: return "cy_GB"; + } + return "cy"; + case LANG_WOLOF: + switch (sub) + { + case SUBLANG_WOLOF_SENEGAL: return "wo_SN"; + } + return "wo"; + case LANG_XHOSA: + switch (sub) + { + case SUBLANG_XHOSA_SOUTH_AFRICA: return "xh_ZA"; + } + return "xh"; + case LANG_YAKUT: + switch (sub) + { + case SUBLANG_YAKUT_RUSSIA: return "sah_RU"; + } + return "sah"; + case LANG_YI: + switch (sub) + { + case SUBLANG_YI_PRC: return "ii_CN"; + } + return "ii"; + case LANG_YIDDISH: + switch (sub) + { + case SUBLANG_DEFAULT: return "yi_IL"; + } + return "yi"; + case LANG_YORUBA: + switch (sub) + { + case SUBLANG_YORUBA_NIGERIA: return "yo_NG"; + } + return "yo"; + case LANG_ZULU: + switch (sub) + { + case SUBLANG_ZULU_SOUTH_AFRICA: return "zu_ZA"; + } + return "zu"; default: return "C"; } } @@ -1557,6 +2507,264 @@ gl_locale_name_from_win32_LCID (LCID lcid) #endif +#if HAVE_USELOCALE /* glibc or MacOS X */ + +/* Simple hash set of strings. We don't want to drag in lots of hash table + code here. */ + +# define SIZE_BITS (sizeof (size_t) * CHAR_BIT) + +/* A hash function for NUL-terminated char* strings using + the method described by Bruno Haible. + See http://www.haible.de/bruno/hashfunc.html. */ +static size_t +string_hash (const void *x) +{ + const char *s = (const char *) x; + size_t h = 0; + + for (; *s; s++) + h = *s + ((h << 9) | (h >> (SIZE_BITS - 9))); + + return h; +} + +/* A hash table of fixed size. Multiple threads can access it read-only + simultaneously, but only one thread can insert into it at the same time. */ + +/* A node in a hash bucket collision list. */ +struct hash_node + { + struct hash_node * volatile next; + char contents[100]; /* has variable size */ + }; + +# define HASH_TABLE_SIZE 257 +static struct hash_node * volatile struniq_hash_table[HASH_TABLE_SIZE] + /* = { NULL, ..., NULL } */; + +/* This lock protects the struniq_hash_table against multiple simultaneous + insertions. */ +gl_lock_define_initialized(static, struniq_lock) + +/* Store a copy of the given string in a string pool with indefinite extent. + Return a pointer to this copy. */ +static const char * +struniq (const char *string) +{ + size_t hashcode = string_hash (string); + size_t slot = hashcode % HASH_TABLE_SIZE; + size_t size; + struct hash_node *new_node; + struct hash_node *p; + for (p = struniq_hash_table[slot]; p != NULL; p = p->next) + if (strcmp (p->contents, string) == 0) + return p->contents; + size = strlen (string) + 1; + new_node = + (struct hash_node *) + malloc (offsetof (struct hash_node, contents[0]) + size); + if (new_node == NULL) + /* Out of memory. Return a statically allocated string. */ + return "C"; + memcpy (new_node->contents, string, size); + /* Lock while inserting new_node. */ + gl_lock_lock (struniq_lock); + /* Check whether another thread already added the string while we were + waiting on the lock. */ + for (p = struniq_hash_table[slot]; p != NULL; p = p->next) + if (strcmp (p->contents, string) == 0) + { + free (new_node); + new_node = p; + goto done; + } + /* Really insert new_node into the hash table. Fill new_node entirely first, + because other threads may be iterating over the linked list. */ + new_node->next = struniq_hash_table[slot]; + struniq_hash_table[slot] = new_node; + done: + /* Unlock after new_node is inserted. */ + gl_lock_unlock (struniq_lock); + return new_node->contents; +} + +#endif + + +#if defined IN_LIBINTL || HAVE_USELOCALE + +/* Like gl_locale_name_thread, except that the result is not in storage of + indefinite extent. */ +# if !defined IN_LIBINTL +static +# endif +const char * +gl_locale_name_thread_unsafe (int category, const char *categoryname) +{ +# if HAVE_USELOCALE + { + locale_t thread_locale = uselocale (NULL); + if (thread_locale != LC_GLOBAL_LOCALE) + { +# if __GLIBC__ >= 2 + /* Work around an incorrect definition of the _NL_LOCALE_NAME macro in + glibc < 2.12. + See . */ + const char *name = + nl_langinfo (_NL_ITEM ((category), _NL_ITEM_INDEX (-1))); + if (name[0] == '\0') + /* Fallback code for glibc < 2.4, which did not implement + nl_langinfo (_NL_LOCALE_NAME (category)). */ + name = thread_locale->__names[category]; + return name; +# endif +# if defined __APPLE__ && defined __MACH__ /* MacOS X */ + /* The locale name is found deep in an undocumented data structure. + Since it's stored in a buffer of size 32 and newlocale() rejects + locale names of length > 31, we can assume that it is NUL terminated + in this buffer. But we need to make a copy of the locale name, of + indefinite extent. */ + struct _xlocale_part1_v0 /* used in MacOS X 10.5 */ + { + int32_t __refcount; + void (*__free_extra)(void *); + __darwin_mbstate_t __mbs[10]; + int64_t __magic; + }; + struct _xlocale_part1_v1 /* used in MacOS X >= 10.6.0 */ + { + int32_t __refcount; + void (*__free_extra)(void *); + __darwin_mbstate_t __mbs[10]; + /*pthread_lock_t*/ int __lock; + int64_t __magic; + }; + struct _xlocale_part2 + { + int64_t __magic; + unsigned char __collate_load_error; + unsigned char __collate_substitute_nontrivial; + unsigned char _messages_using_locale; + unsigned char _monetary_using_locale; + unsigned char _numeric_using_locale; + unsigned char _time_using_locale; + unsigned char __mlocale_changed; + unsigned char __nlocale_changed; + unsigned char __numeric_fp_cvt; + struct __xlocale_st_collate *__lc_collate; + struct __xlocale_st_runelocale *__lc_ctype; + struct __xlocale_st_messages *__lc_messages; + struct __xlocale_st_monetary *__lc_monetary; + struct __xlocale_st_numeric *__lc_numeric; + struct _xlocale *__lc_numeric_loc; + struct __xlocale_st_time *__lc_time; + /* more */ + }; + struct __xlocale_st_collate + { + int32_t __refcount; + void (*__free_extra)(void *); + char __encoding[32]; + /* more */ + }; + struct __xlocale_st_runelocale + { + int32_t __refcount; + void (*__free_extra)(void *); + char __ctype_encoding[32]; + /* more */ + }; + struct __xlocale_st_messages + { + int32_t __refcount; + void (*__free_extra)(void *); + char *_messages_locale_buf; + /* more */ + }; + struct __xlocale_st_monetary + { + int32_t __refcount; + void (*__free_extra)(void *); + char *_monetary_locale_buf; + /* more */ + }; + struct __xlocale_st_numeric { + int32_t __refcount; + void (*__free_extra)(void *); + char *_numeric_locale_buf; + /* more */ + }; + struct __xlocale_st_time { + int32_t __refcount; + void (*__free_extra)(void *); + char *_time_locale_buf; + /* more */ + }; + struct _xlocale_part2 *tlp; + if (((struct _xlocale_part1_v0 *) thread_locale)->__magic + == 0x786C6F63616C6530LL) + /* MacOS X 10.5 */ + tlp = + (struct _xlocale_part2 *) + &((struct _xlocale_part1_v0 *) thread_locale)->__magic; + else if (((struct _xlocale_part1_v1 *) thread_locale)->__magic + == 0x786C6F63616C6530LL) + /* MacOS X >= 10.6.0 */ + tlp = + (struct _xlocale_part2 *) + &((struct _xlocale_part1_v1 *) thread_locale)->__magic; + else + /* Unsupported version of MacOS X: The internals of 'struct _xlocale' + have changed again. */ + return ""; + switch (category) + { + case LC_CTYPE: + return tlp->__lc_ctype->__ctype_encoding; + case LC_NUMERIC: + return tlp->_numeric_using_locale + ? tlp->__lc_numeric->_numeric_locale_buf + : "C"; + case LC_TIME: + return tlp->_time_using_locale + ? tlp->__lc_time->_time_locale_buf + : "C"; + case LC_COLLATE: + return !tlp->__collate_load_error + ? tlp->__lc_collate->__encoding + : "C"; + case LC_MONETARY: + return tlp->_monetary_using_locale + ? tlp->__lc_monetary->_monetary_locale_buf + : "C"; + case LC_MESSAGES: + return tlp->_messages_using_locale + ? tlp->__lc_messages->_messages_locale_buf + : "C"; + default: /* We shouldn't get here. */ + return ""; + } +# endif + } + } +# endif + return NULL; +} + +#endif + +const char * +gl_locale_name_thread (int category, const char *categoryname) +{ +#if HAVE_USELOCALE + const char *name = gl_locale_name_thread_unsafe (category, categoryname); + if (name != NULL) + return struniq (name); +#endif + return NULL; +} + /* XPG3 defines the result of 'setlocale (category, NULL)' as: "Directs 'setlocale()' to query 'category' and return the current setting of 'local'." @@ -1567,12 +2775,6 @@ gl_locale_name_from_win32_LCID (LCID lcid) # define HAVE_LOCALE_NULL #endif -/* Determine the current locale's name, and canonicalize it into XPG syntax - language[_territory][.codeset][@modifier] - The codeset part in the result is not reliable; the locale_charset() - should be used for codeset information instead. - The result must not be freed; it is statically allocated. */ - const char * gl_locale_name_posix (int category, const char *categoryname) { @@ -1581,6 +2783,30 @@ gl_locale_name_posix (int category, const char *categoryname) #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL return setlocale (category, NULL); #else + /* On other systems we ignore what setlocale reports and instead look at the + environment variables directly. This is necessary + 1. on systems which have a facility for customizing the default locale + (MacOS X, native Windows, Cygwin) and where the system's setlocale() + function ignores this default locale (MacOS X, Cygwin), in two cases: + a. when the user missed to use the setlocale() override from libintl + (for example by not including ), + b. when setlocale supports only the "C" locale, such as on Cygwin + 1.5.x. In this case even the override from libintl cannot help. + 2. on all systems where setlocale supports only the "C" locale. */ + /* Strictly speaking, it is a POSIX violation to look at the environment + variables regardless whether setlocale has been called or not. POSIX + says: + "For C-language programs, the POSIX locale shall be the + default locale when the setlocale() function is not called." + But we assume that all programs that use internationalized APIs call + setlocale (LC_ALL, ""). */ + return gl_locale_name_environ (category, categoryname); +#endif +} + +const char * +gl_locale_name_environ (int category, const char *categoryname) +{ const char *retval; /* Setting of LC_ALL overrides all other. */ @@ -1594,10 +2820,21 @@ gl_locale_name_posix (int category, const char *categoryname) /* Last possibility is the LANG environment variable. */ retval = getenv ("LANG"); if (retval != NULL && retval[0] != '\0') - return retval; + { +#if HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE + /* MacOS X 10.2 or newer. + Ignore invalid LANG value set by the Terminal application. */ + if (strcmp (retval, "UTF-8") != 0) +#endif +#if defined __CYGWIN__ + /* Cygwin. + Ignore dummy LANG value set by ~/.profile. */ + if (strcmp (retval, "C.UTF-8") != 0) +#endif + return retval; + } return NULL; -#endif } const char * @@ -1610,9 +2847,28 @@ gl_locale_name_default (void) implementation-defined locale. Some implementations may provide facilities for local installation administrators to set the default locale, customizing it for each location. POSIX:2001 does not require - such a facility. */ + such a facility. -#if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined(WIN32_NATIVE)) + The systems with such a facility are MacOS X and Windows: They provide a + GUI that allows the user to choose a locale. + - On MacOS X, by default, none of LC_* or LANG are set. Starting with + MacOS X 10.4 or 10.5, LANG is set for processes launched by the + 'Terminal' application (but sometimes to an incorrect value "UTF-8"). + When no environment variable is set, setlocale (LC_ALL, "") uses the + "C" locale. + - On native Windows, by default, none of LC_* or LANG are set. + When no environment variable is set, setlocale (LC_ALL, "") uses the + locale chosen by the user. + - On Cygwin 1.5.x, by default, none of LC_* or LANG are set. + When no environment variable is set, setlocale (LC_ALL, "") uses the + "C" locale. + - On Cygwin 1.7, by default, LANG is set to "C.UTF-8" when the default + ~/.profile is executed. + When no environment variable is set, setlocale (LC_ALL, "") uses the + "C.UTF-8" locale, which operates in the same way as the "C" locale. + */ + +#if !(HAVE_CFLOCALECOPYCURRENT || HAVE_CFPREFERENCESCOPYAPPVALUE || defined WIN32_NATIVE || defined __CYGWIN__) /* The system does not have a way of setting the locale, other than the POSIX specified environment variables. We use C as default locale. */ @@ -1633,40 +2889,41 @@ gl_locale_name_default (void) if (cached_localename == NULL) { - char namebuf[256]; + char namebuf[256]; # if HAVE_CFLOCALECOPYCURRENT /* MacOS X 10.3 or newer */ - CFLocaleRef locale = CFLocaleCopyCurrent (); - CFStringRef name = CFLocaleGetIdentifier (locale); - - if (CFStringGetCString (name, namebuf, sizeof(namebuf), - kCFStringEncodingASCII)) - { - gl_locale_name_canonicalize (namebuf); - cached_localename = strdup (namebuf); - } - CFRelease (locale); + CFLocaleRef locale = CFLocaleCopyCurrent (); + CFStringRef name = CFLocaleGetIdentifier (locale); + + if (CFStringGetCString (name, namebuf, sizeof (namebuf), + kCFStringEncodingASCII)) + { + gl_locale_name_canonicalize (namebuf); + cached_localename = strdup (namebuf); + } + CFRelease (locale); # elif HAVE_CFPREFERENCESCOPYAPPVALUE /* MacOS X 10.2 or newer */ - CFTypeRef value = - CFPreferencesCopyAppValue (CFSTR ("AppleLocale"), - kCFPreferencesCurrentApplication); - if (value != NULL - && CFGetTypeID (value) == CFStringGetTypeID () - && CFStringGetCString ((CFStringRef)value, namebuf, sizeof(namebuf), - kCFStringEncodingASCII)) - { - gl_locale_name_canonicalize (namebuf); - cached_localename = strdup (namebuf); - } + CFTypeRef value = + CFPreferencesCopyAppValue (CFSTR ("AppleLocale"), + kCFPreferencesCurrentApplication); + if (value != NULL + && CFGetTypeID (value) == CFStringGetTypeID () + && CFStringGetCString ((CFStringRef)value, + namebuf, sizeof (namebuf), + kCFStringEncodingASCII)) + { + gl_locale_name_canonicalize (namebuf); + cached_localename = strdup (namebuf); + } # endif - if (cached_localename == NULL) - cached_localename = "C"; + if (cached_localename == NULL) + cached_localename = "C"; } return cached_localename; } # endif -# if defined(WIN32_NATIVE) /* WIN32, not Cygwin */ +# if defined WIN32_NATIVE || defined __CYGWIN__ /* WIN32 or Cygwin */ { LCID lcid; @@ -1679,11 +2936,21 @@ gl_locale_name_default (void) #endif } +/* Determine the current locale's name, and canonicalize it into XPG syntax + language[_territory][.codeset][@modifier] + The codeset part in the result is not reliable; the locale_charset() + should be used for codeset information instead. + The result must not be freed; it is statically allocated. */ + const char * gl_locale_name (int category, const char *categoryname) { const char *retval; + retval = gl_locale_name_thread (category, categoryname); + if (retval != NULL) + return retval; + retval = gl_locale_name_posix (category, categoryname); if (retval != NULL) return retval; diff --git a/lib/localename.h b/lib/localename.h index f633ad8b..bb7caee4 100644 --- a/lib/localename.h +++ b/lib/localename.h @@ -1,5 +1,5 @@ /* Determine name of the currently selected locale. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published @@ -25,9 +25,9 @@ extern "C" { /* Determine the current locale's name. - It considers both the POSIX notion of locale name (see function - gl_locale_name_posix) and the system notion of locale name (see function - gl_locale_name_default). + It considers both the POSIX notion of locale name (see functions + gl_locale_name_thread and gl_locale_name_posix) and the system notion + of locale name (see function gl_locale_name_default). CATEGORY is a locale category abbreviation, as defined in , but not LC_ALL. E.g. LC_MESSAGES. CATEGORYNAME is the name of CATEGORY as a string, e.g. "LC_MESSAGES". @@ -38,8 +38,21 @@ extern "C" { The result must not be freed; it is statically allocated. */ extern const char * gl_locale_name (int category, const char *categoryname); -/* Determine the current locale's name, as specified by setlocale() calls - or by environment variables. +/* Determine the current per-thread locale's name, as specified by uselocale() + calls. + CATEGORY is a locale category abbreviation, as defined in , + but not LC_ALL. E.g. LC_MESSAGES. + CATEGORYNAME is the name of CATEGORY as a string, e.g. "LC_MESSAGES". + Return the locale category's name, canonicalized into XPG syntax + language[_territory][.codeset][@modifier] + or NULL if no locale has been specified for the current thread. + The codeset part in the result is not reliable; the locale_charset() + should be used for codeset information instead. + The result must not be freed; it is statically allocated. */ +extern const char * gl_locale_name_thread (int category, const char *categoryname); + +/* Determine the thread-independent current locale's name, as specified by + setlocale() calls or by environment variables. CATEGORY is a locale category abbreviation, as defined in , but not LC_ALL. E.g. LC_MESSAGES. CATEGORYNAME is the name of CATEGORY as a string, e.g. "LC_MESSAGES". @@ -52,10 +65,17 @@ extern const char * gl_locale_name (int category, const char *categoryname); The result must not be freed; it is statically allocated. */ extern const char * gl_locale_name_posix (int category, const char *categoryname); +/* Determine the default locale's name, as specified by environment + variables. + Return the locale category's name, or NULL if no locale has been specified + by environment variables. + The result must not be freed; it is statically allocated. */ +extern const char * gl_locale_name_environ (int category, const char *categoryname); + /* Determine the default locale's name. This is the current locale's name, - if not specified by setlocale() calls or by environment variables. This - locale name is usually determined by systems settings that the user can - manipulate through a GUI. + if not specified by uselocale() calls, by setlocale() calls, or by + environment variables. This locale name is usually determined by systems + settings that the user can manipulate through a GUI. Quoting POSIX:2001: "All implementations shall define a locale as the default locale, diff --git a/lib/malloc.c b/lib/malloc.c index 9111c7a1..614320c4 100644 --- a/lib/malloc.c +++ b/lib/malloc.c @@ -1,6 +1,6 @@ /* malloc() function that is glibc compatible. - Copyright (C) 1997, 1998, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 1997-1998, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/malloca.c b/lib/malloca.c index 7905e615..39baa5e2 100644 --- a/lib/malloca.c +++ b/lib/malloca.c @@ -1,5 +1,5 @@ /* Safe automatic memory allocation. - Copyright (C) 2003, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2003, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify @@ -74,21 +74,21 @@ mmalloca (size_t n) char *p = (char *) malloc (nplus); if (p != NULL) - { - size_t slot; + { + size_t slot; - p += HEADER_SIZE; + p += HEADER_SIZE; - /* Put a magic number into the indicator word. */ - ((int *) p)[-1] = MAGIC_NUMBER; + /* Put a magic number into the indicator word. */ + ((int *) p)[-1] = MAGIC_NUMBER; - /* Enter p into the hash table. */ - slot = (unsigned long) p % HASH_TABLE_SIZE; - ((struct header *) (p - HEADER_SIZE))->next = mmalloca_results[slot]; - mmalloca_results[slot] = p; + /* Enter p into the hash table. */ + slot = (unsigned long) p % HASH_TABLE_SIZE; + ((struct header *) (p - HEADER_SIZE))->next = mmalloca_results[slot]; + mmalloca_results[slot] = p; - return p; - } + return p; + } } /* Out of memory. */ return NULL; @@ -109,28 +109,28 @@ freea (void *p) if (p != NULL) { /* Attempt to quickly distinguish the mmalloca() result - which has - a magic indicator word - and the alloca() result - which has an - uninitialized indicator word. It is for this test that sa_increment - additional bytes are allocated in the alloca() case. */ + a magic indicator word - and the alloca() result - which has an + uninitialized indicator word. It is for this test that sa_increment + additional bytes are allocated in the alloca() case. */ if (((int *) p)[-1] == MAGIC_NUMBER) - { - /* Looks like a mmalloca() result. To see whether it really is one, - perform a lookup in the hash table. */ - size_t slot = (unsigned long) p % HASH_TABLE_SIZE; - void **chain = &mmalloca_results[slot]; - for (; *chain != NULL;) - { - if (*chain == p) - { - /* Found it. Remove it from the hash table and free it. */ - char *p_begin = (char *) p - HEADER_SIZE; - *chain = ((struct header *) p_begin)->next; - free (p_begin); - return; - } - chain = &((struct header *) ((char *) *chain - HEADER_SIZE))->next; - } - } + { + /* Looks like a mmalloca() result. To see whether it really is one, + perform a lookup in the hash table. */ + size_t slot = (unsigned long) p % HASH_TABLE_SIZE; + void **chain = &mmalloca_results[slot]; + for (; *chain != NULL;) + { + if (*chain == p) + { + /* Found it. Remove it from the hash table and free it. */ + char *p_begin = (char *) p - HEADER_SIZE; + *chain = ((struct header *) p_begin)->next; + free (p_begin); + return; + } + chain = &((struct header *) ((char *) *chain - HEADER_SIZE))->next; + } + } /* At this point, we know it was not a mmalloca() result. */ } } diff --git a/lib/malloca.h b/lib/malloca.h index 7d92b0af..e39d0f42 100644 --- a/lib/malloca.h +++ b/lib/malloca.h @@ -1,5 +1,5 @@ /* Safe automatic memory allocation. - Copyright (C) 2003-2007 Free Software Foundation, Inc. + Copyright (C) 2003-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify @@ -54,7 +54,7 @@ extern "C" { the function returns. Upon failure, it returns NULL. */ #if HAVE_ALLOCA # define malloca(N) \ - ((N) < 4032 - sa_increment \ + ((N) < 4032 - sa_increment \ ? (void *) ((char *) alloca ((N) + sa_increment) + sa_increment) \ : mmalloca (N)) #else @@ -122,10 +122,10 @@ enum sa_alignment_longdouble = sa_alignof (long double), sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1) #if HAVE_LONG_LONG_INT - | (sa_alignment_longlong - 1) + | (sa_alignment_longlong - 1) #endif - | (sa_alignment_longdouble - 1) - ) + 1, + | (sa_alignment_longdouble - 1) + ) + 1, /* The increment that guarantees room for a magic word must be >= sizeof (int) and a multiple of sa_alignment_max. */ sa_increment = ((sizeof (int) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max diff --git a/lib/math.in.h b/lib/math.in.h index d4940515..c0b2f341 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - Copyright (C) 2002-2003, 2007-2009 Free Software Foundation, Inc. + Copyright (C) 2002-2003, 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -28,12 +28,42 @@ #define _GL_MATH_H -/* The definition of GL_LINK_WARNING is copied here. */ - - -#ifdef __cplusplus -extern "C" { -#endif +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + +/* Helper macros to define a portability warning for the + classification macro FUNC called with VALUE. POSIX declares the + classification macros with an argument of real-floating (that is, + one of float, double, or long double). */ +#define _GL_WARN_REAL_FLOATING_DECL(func) \ +static inline int \ +rpl_ ## func ## f (float f) \ +{ \ + return func (f); \ +} \ +static inline int \ +rpl_ ## func ## d (double d) \ +{ \ + return func (d); \ +} \ +static inline int \ +rpl_ ## func ## l (long double l) \ +{ \ + return func (l); \ +} \ +_GL_WARN_ON_USE (rpl_ ## func ## f, #func " is unportable - " \ + "use gnulib module " #func " for portability"); \ +_GL_WARN_ON_USE (rpl_ ## func ## d, #func " is unportable - " \ + "use gnulib module " #func " for portability"); \ +_GL_WARN_ON_USE (rpl_ ## func ## l, #func " is unportable - " \ + "use gnulib module " #func " for portability") +#define _GL_WARN_REAL_FLOATING_IMPL(func, value) \ + (sizeof (value) == sizeof (float) ? rpl_ ## func ## f (value) \ + : sizeof (value) == sizeof (double) ? rpl_ ## func ## d (value) \ + : rpl_ ## func ## l (value)) /* POSIX allows platforms that don't support NAN. But all major @@ -64,6 +94,7 @@ _NaN () # define HUGE_VAL (1.0 / 0.0) #endif + /* Write x as x = mantissa * 2^exp where @@ -73,130 +104,198 @@ _NaN () Store exp in *EXPPTR and return mantissa. */ #if @GNULIB_FREXP@ # if @REPLACE_FREXP@ -# define frexp rpl_frexp -extern double frexp (double x, int *expptr); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define frexp rpl_frexp +# endif +_GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (frexp, double, (double x, int *expptr)); +# else +_GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr)); # endif +_GL_CXXALIASWARN (frexp); #elif defined GNULIB_POSIXCHECK # undef frexp -# define frexp(x,e) \ - (GL_LINK_WARNING ("frexp is unportable - " \ - "use gnulib module frexp for portability"), \ - frexp (x, e)) +/* Assume frexp is always declared. */ +_GL_WARN_ON_USE (frexp, "frexp is unportable - " + "use gnulib module frexp for portability"); #endif -#if @GNULIB_MATHL@ || !@HAVE_DECL_ACOSL@ -extern long double acosl (long double x); +#if @GNULIB_LOGB@ +# if !@HAVE_DECL_LOGB@ +_GL_EXTERN_C double logb (double x); +# endif +#elif defined GNULIB_POSIXCHECK +# undef logb +# if HAVE_RAW_DECL_LOGB +_GL_WARN_ON_USE (logb, "logb is unportable - " + "use gnulib module logb for portability"); +# endif #endif -#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK + + +#if @GNULIB_ACOSL@ +# if !@HAVE_ACOSL@ || !@HAVE_DECL_ACOSL@ +_GL_FUNCDECL_SYS (acosl, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (acosl, long double, (long double x)); +_GL_CXXALIASWARN (acosl); +#elif defined GNULIB_POSIXCHECK # undef acosl -# define acosl(x) \ - (GL_LINK_WARNING ("acosl is unportable - " \ - "use gnulib module mathl for portability"), \ - acosl (x)) +# if HAVE_RAW_DECL_ACOSL +_GL_WARN_ON_USE (acosl, "acosl is unportable - " + "use gnulib module mathl for portability"); +# endif #endif -#if @GNULIB_MATHL@ || !@HAVE_DECL_ASINL@ -extern long double asinl (long double x); -#endif -#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK +#if @GNULIB_ASINL@ +# if !@HAVE_ASINL@ || !@HAVE_DECL_ASINL@ +_GL_FUNCDECL_SYS (asinl, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (asinl, long double, (long double x)); +_GL_CXXALIASWARN (asinl); +#elif defined GNULIB_POSIXCHECK # undef asinl -# define asinl(x) \ - (GL_LINK_WARNING ("asinl is unportable - " \ - "use gnulib module mathl for portability"), \ - asinl (x)) +# if HAVE_RAW_DECL_ASINL +_GL_WARN_ON_USE (asinl, "asinl is unportable - " + "use gnulib module mathl for portability"); +# endif #endif -#if @GNULIB_MATHL@ || !@HAVE_DECL_ATANL@ -extern long double atanl (long double x); -#endif -#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK +#if @GNULIB_ATANL@ +# if !@HAVE_ATANL@ || !@HAVE_DECL_ATANL@ +_GL_FUNCDECL_SYS (atanl, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (atanl, long double, (long double x)); +_GL_CXXALIASWARN (atanl); +#elif defined GNULIB_POSIXCHECK # undef atanl -# define atanl(x) \ - (GL_LINK_WARNING ("atanl is unportable - " \ - "use gnulib module mathl for portability"), \ - atanl (x)) +# if HAVE_RAW_DECL_ATANL +_GL_WARN_ON_USE (atanl, "atanl is unportable - " + "use gnulib module mathl for portability"); +# endif #endif #if @GNULIB_CEILF@ # if @REPLACE_CEILF@ -# define ceilf rpl_ceilf -extern float ceilf (float x); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define ceilf rpl_ceilf +# endif +_GL_FUNCDECL_RPL (ceilf, float, (float x)); +_GL_CXXALIAS_RPL (ceilf, float, (float x)); +# else +# if !@HAVE_DECL_CEILF@ +_GL_FUNCDECL_SYS (ceilf, float, (float x)); +# endif +_GL_CXXALIAS_SYS (ceilf, float, (float x)); # endif +_GL_CXXALIASWARN (ceilf); #elif defined GNULIB_POSIXCHECK # undef ceilf -# define ceilf(x) \ - (GL_LINK_WARNING ("ceilf is unportable - " \ - "use gnulib module ceilf for portability"), \ - ceilf (x)) +# if HAVE_RAW_DECL_CEILF +_GL_WARN_ON_USE (ceilf, "ceilf is unportable - " + "use gnulib module ceilf for portability"); +# endif #endif #if @GNULIB_CEILL@ # if @REPLACE_CEILL@ -# define ceill rpl_ceill -extern long double ceill (long double x); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define ceill rpl_ceill +# endif +_GL_FUNCDECL_RPL (ceill, long double, (long double x)); +_GL_CXXALIAS_RPL (ceill, long double, (long double x)); +# else +# if !@HAVE_DECL_CEILL@ +_GL_FUNCDECL_SYS (ceill, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (ceill, long double, (long double x)); # endif +_GL_CXXALIASWARN (ceill); #elif defined GNULIB_POSIXCHECK # undef ceill -# define ceill(x) \ - (GL_LINK_WARNING ("ceill is unportable - " \ - "use gnulib module ceill for portability"), \ - ceill (x)) +# if HAVE_RAW_DECL_CEILL +_GL_WARN_ON_USE (ceill, "ceill is unportable - " + "use gnulib module ceill for portability"); +# endif #endif -#if @GNULIB_MATHL@ || (!@HAVE_DECL_COSL@ && !defined cosl) -# undef cosl -extern long double cosl (long double x); -#endif -#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK +#if @GNULIB_COSL@ +# if !@HAVE_COSL@ || !@HAVE_DECL_COSL@ +_GL_FUNCDECL_SYS (cosl, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (cosl, long double, (long double x)); +_GL_CXXALIASWARN (cosl); +#elif defined GNULIB_POSIXCHECK # undef cosl -# define cosl(x) \ - (GL_LINK_WARNING ("cosl is unportable - " \ - "use gnulib module mathl for portability"), \ - cosl (x)) +# if HAVE_RAW_DECL_COSL +_GL_WARN_ON_USE (cosl, "cosl is unportable - " + "use gnulib module mathl for portability"); +# endif #endif -#if @GNULIB_MATHL@ || !@HAVE_DECL_EXPL@ -extern long double expl (long double x); -#endif -#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK +#if @GNULIB_EXPL@ +# if !@HAVE_EXPL@ || !@HAVE_DECL_EXPL@ +_GL_FUNCDECL_SYS (expl, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (expl, long double, (long double x)); +_GL_CXXALIASWARN (expl); +#elif defined GNULIB_POSIXCHECK # undef expl -# define expl(x) \ - (GL_LINK_WARNING ("expl is unportable - " \ - "use gnulib module mathl for portability"), \ - expl (x)) +# if HAVE_RAW_DECL_EXPL +_GL_WARN_ON_USE (expl, "expl is unportable - " + "use gnulib module mathl for portability"); +# endif #endif #if @GNULIB_FLOORF@ # if @REPLACE_FLOORF@ -# define floorf rpl_floorf -extern float floorf (float x); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define floorf rpl_floorf +# endif +_GL_FUNCDECL_RPL (floorf, float, (float x)); +_GL_CXXALIAS_RPL (floorf, float, (float x)); +#else +# if !@HAVE_DECL_FLOORF@ +_GL_FUNCDECL_SYS (floorf, float, (float x)); +# endif +_GL_CXXALIAS_SYS (floorf, float, (float x)); # endif +_GL_CXXALIASWARN (floorf); #elif defined GNULIB_POSIXCHECK # undef floorf -# define floorf(x) \ - (GL_LINK_WARNING ("floorf is unportable - " \ - "use gnulib module floorf for portability"), \ - floorf (x)) +# if HAVE_RAW_DECL_FLOORF +_GL_WARN_ON_USE (floorf, "floorf is unportable - " + "use gnulib module floorf for portability"); +# endif #endif #if @GNULIB_FLOORL@ # if @REPLACE_FLOORL@ -# define floorl rpl_floorl -extern long double floorl (long double x); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define floorl rpl_floorl +# endif +_GL_FUNCDECL_RPL (floorl, long double, (long double x)); +_GL_CXXALIAS_RPL (floorl, long double, (long double x)); +# else +# if !@HAVE_DECL_FLOORL@ +_GL_FUNCDECL_SYS (floorl, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (floorl, long double, (long double x)); # endif +_GL_CXXALIASWARN (floorl); #elif defined GNULIB_POSIXCHECK # undef floorl -# define floorl(x) \ - (GL_LINK_WARNING ("floorl is unportable - " \ - "use gnulib module floorl for portability"), \ - floorl (x)) +# if HAVE_RAW_DECL_FLOORL +_GL_WARN_ON_USE (floorl, "floorl is unportable - " + "use gnulib module floorl for portability"); +# endif #endif @@ -208,175 +307,247 @@ extern long double floorl (long double x); If x is infinite or NaN: mantissa = x, exp unspecified. Store exp in *EXPPTR and return mantissa. */ #if @GNULIB_FREXPL@ && @REPLACE_FREXPL@ -# define frexpl rpl_frexpl +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define frexpl rpl_frexpl +# endif +_GL_FUNCDECL_RPL (frexpl, long double, + (long double x, int *expptr) _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (frexpl, long double, (long double x, int *expptr)); +#else +# if !@HAVE_DECL_FREXPL@ +_GL_FUNCDECL_SYS (frexpl, long double, + (long double x, int *expptr) _GL_ARG_NONNULL ((2))); +# endif +# if @GNULIB_FREXPL@ +_GL_CXXALIAS_SYS (frexpl, long double, (long double x, int *expptr)); +# endif #endif -#if (@GNULIB_FREXPL@ && @REPLACE_FREXPL@) || !@HAVE_DECL_FREXPL@ -extern long double frexpl (long double x, int *expptr); +#if @GNULIB_FREXPL@ && !(@REPLACE_FREXPL@ && !@HAVE_DECL_FREXPL@) +_GL_CXXALIASWARN (frexpl); #endif #if !@GNULIB_FREXPL@ && defined GNULIB_POSIXCHECK # undef frexpl -# define frexpl(x,e) \ - (GL_LINK_WARNING ("frexpl is unportable - " \ - "use gnulib module frexpl for portability"), \ - frexpl (x, e)) +# if HAVE_RAW_DECL_FREXPL +_GL_WARN_ON_USE (frexpl, "frexpl is unportable - " + "use gnulib module frexpl for portability"); +# endif #endif /* Return x * 2^exp. */ #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@ -# define ldexpl rpl_ldexpl +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define ldexpl rpl_ldexpl +# endif +_GL_FUNCDECL_RPL (ldexpl, long double, (long double x, int exp)); +_GL_CXXALIAS_RPL (ldexpl, long double, (long double x, int exp)); +#else +# if !@HAVE_DECL_LDEXPL@ +_GL_FUNCDECL_SYS (ldexpl, long double, (long double x, int exp)); +# endif +# if @GNULIB_LDEXPL@ +_GL_CXXALIAS_SYS (ldexpl, long double, (long double x, int exp)); +# endif #endif -#if (@GNULIB_LDEXPL@ && @REPLACE_LDEXPL@) || !@HAVE_DECL_LDEXPL@ -extern long double ldexpl (long double x, int exp); +#if @GNULIB_LDEXPL@ +_GL_CXXALIASWARN (ldexpl); #endif #if !@GNULIB_LDEXPL@ && defined GNULIB_POSIXCHECK # undef ldexpl -# define ldexpl(x,e) \ - (GL_LINK_WARNING ("ldexpl is unportable - " \ - "use gnulib module ldexpl for portability"), \ - ldexpl (x, e)) +# if HAVE_RAW_DECL_LDEXPL +_GL_WARN_ON_USE (ldexpl, "ldexpl is unportable - " + "use gnulib module ldexpl for portability"); +# endif #endif -#if @GNULIB_MATHL@ || (!@HAVE_DECL_LOGL@ && !defined logl) -# undef logl -extern long double logl (long double x); -#endif -#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK +#if @GNULIB_LOGL@ +# if !@HAVE_LOGL@ || !@HAVE_DECL_LOGL@ +_GL_FUNCDECL_SYS (logl, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (logl, long double, (long double x)); +_GL_CXXALIASWARN (logl); +#elif defined GNULIB_POSIXCHECK # undef logl -# define logl(x) \ - (GL_LINK_WARNING ("logl is unportable - " \ - "use gnulib module mathl for portability"), \ - logl (x)) +# if HAVE_RAW_DECL_LOGL +_GL_WARN_ON_USE (logl, "logl is unportable - " + "use gnulib module mathl for portability"); +# endif #endif #if @GNULIB_ROUNDF@ # if @REPLACE_ROUNDF@ -# undef roundf -# define roundf rpl_roundf -extern float roundf (float x); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef roundf +# define roundf rpl_roundf +# endif +_GL_FUNCDECL_RPL (roundf, float, (float x)); +_GL_CXXALIAS_RPL (roundf, float, (float x)); +# else +# if !@HAVE_DECL_ROUNDF@ +_GL_FUNCDECL_SYS (roundf, float, (float x)); +# endif +_GL_CXXALIAS_SYS (roundf, float, (float x)); # endif +_GL_CXXALIASWARN (roundf); #elif defined GNULIB_POSIXCHECK # undef roundf -# define roundf(x) \ - (GL_LINK_WARNING ("roundf is unportable - " \ - "use gnulib module roundf for portability"), \ - roundf (x)) +# if HAVE_RAW_DECL_ROUNDF +_GL_WARN_ON_USE (roundf, "roundf is unportable - " + "use gnulib module roundf for portability"); +# endif #endif #if @GNULIB_ROUND@ # if @REPLACE_ROUND@ -# undef round -# define round rpl_round -extern double round (double x); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef round +# define round rpl_round +# endif +_GL_FUNCDECL_RPL (round, double, (double x)); +_GL_CXXALIAS_RPL (round, double, (double x)); +# else +# if !@HAVE_DECL_ROUND@ +_GL_FUNCDECL_SYS (round, double, (double x)); +# endif +_GL_CXXALIAS_SYS (round, double, (double x)); # endif +_GL_CXXALIASWARN (round); #elif defined GNULIB_POSIXCHECK # undef round -# define round(x) \ - (GL_LINK_WARNING ("round is unportable - " \ - "use gnulib module round for portability"), \ - round (x)) +# if HAVE_RAW_DECL_ROUND +_GL_WARN_ON_USE (round, "round is unportable - " + "use gnulib module round for portability"); +# endif #endif #if @GNULIB_ROUNDL@ # if @REPLACE_ROUNDL@ -# undef roundl -# define roundl rpl_roundl -extern long double roundl (long double x); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef roundl +# define roundl rpl_roundl +# endif +_GL_FUNCDECL_RPL (roundl, long double, (long double x)); +_GL_CXXALIAS_RPL (roundl, long double, (long double x)); +# else +# if !@HAVE_DECL_ROUNDL@ +_GL_FUNCDECL_SYS (roundl, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (roundl, long double, (long double x)); # endif +_GL_CXXALIASWARN (roundl); #elif defined GNULIB_POSIXCHECK # undef roundl -# define roundl(x) \ - (GL_LINK_WARNING ("roundl is unportable - " \ - "use gnulib module roundl for portability"), \ - roundl (x)) +# if HAVE_RAW_DECL_ROUNDL +_GL_WARN_ON_USE (roundl, "roundl is unportable - " + "use gnulib module roundl for portability"); +# endif #endif -#if @GNULIB_MATHL@ || (!@HAVE_DECL_SINL@ && !defined sinl) -# undef sinl -extern long double sinl (long double x); -#endif -#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK +#if @GNULIB_SINL@ +# if !@HAVE_SINL@ || !@HAVE_DECL_SINL@ +_GL_FUNCDECL_SYS (sinl, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (sinl, long double, (long double x)); +_GL_CXXALIASWARN (sinl); +#elif defined GNULIB_POSIXCHECK # undef sinl -# define sinl(x) \ - (GL_LINK_WARNING ("sinl is unportable - " \ - "use gnulib module mathl for portability"), \ - sinl (x)) +# if HAVE_RAW_DECL_SINL +_GL_WARN_ON_USE (sinl, "sinl is unportable - " + "use gnulib module mathl for portability"); +# endif #endif -#if @GNULIB_MATHL@ || !@HAVE_DECL_SQRTL@ -extern long double sqrtl (long double x); -#endif -#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK +#if @GNULIB_SQRTL@ +# if !@HAVE_SQRTL@ || !@HAVE_DECL_SQRTL@ +_GL_FUNCDECL_SYS (sqrtl, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (sqrtl, long double, (long double x)); +_GL_CXXALIASWARN (sqrtl); +#elif defined GNULIB_POSIXCHECK # undef sqrtl -# define sqrtl(x) \ - (GL_LINK_WARNING ("sqrtl is unportable - " \ - "use gnulib module mathl for portability"), \ - sqrtl (x)) +# if HAVE_RAW_DECL_SQRTL +_GL_WARN_ON_USE (sqrtl, "sqrtl is unportable - " + "use gnulib module mathl for portability"); +# endif #endif -#if @GNULIB_MATHL@ || !@HAVE_DECL_TANL@ -extern long double tanl (long double x); -#endif -#if !@GNULIB_MATHL@ && defined GNULIB_POSIXCHECK +#if @GNULIB_TANL@ +# if !@HAVE_TANL@ || !@HAVE_DECL_TANL@ +_GL_FUNCDECL_SYS (tanl, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (tanl, long double, (long double x)); +_GL_CXXALIASWARN (tanl); +#elif defined GNULIB_POSIXCHECK # undef tanl -# define tanl(x) \ - (GL_LINK_WARNING ("tanl is unportable - " \ - "use gnulib module mathl for portability"), \ - tanl (x)) +# if HAVE_RAW_DECL_TANL +_GL_WARN_ON_USE (tanl, "tanl is unportable - " + "use gnulib module mathl for portability"); +# endif #endif #if @GNULIB_TRUNCF@ # if !@HAVE_DECL_TRUNCF@ -# define truncf rpl_truncf -extern float truncf (float x); +_GL_FUNCDECL_SYS (truncf, float, (float x)); # endif +_GL_CXXALIAS_SYS (truncf, float, (float x)); +_GL_CXXALIASWARN (truncf); #elif defined GNULIB_POSIXCHECK # undef truncf -# define truncf(x) \ - (GL_LINK_WARNING ("truncf is unportable - " \ - "use gnulib module truncf for portability"), \ - truncf (x)) +# if HAVE_RAW_DECL_TRUNCF +_GL_WARN_ON_USE (truncf, "truncf is unportable - " + "use gnulib module truncf for portability"); +# endif #endif #if @GNULIB_TRUNC@ # if !@HAVE_DECL_TRUNC@ -# define trunc rpl_trunc -extern double trunc (double x); +_GL_FUNCDECL_SYS (trunc, double, (double x)); # endif +_GL_CXXALIAS_SYS (trunc, double, (double x)); +_GL_CXXALIASWARN (trunc); #elif defined GNULIB_POSIXCHECK # undef trunc -# define trunc(x) \ - (GL_LINK_WARNING ("trunc is unportable - " \ - "use gnulib module trunc for portability"), \ - trunc (x)) +# if HAVE_RAW_DECL_TRUNC +_GL_WARN_ON_USE (trunc, "trunc is unportable - " + "use gnulib module trunc for portability"); +# endif #endif #if @GNULIB_TRUNCL@ # if @REPLACE_TRUNCL@ -# undef truncl -# define truncl rpl_truncl -extern long double truncl (long double x); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef truncl +# define truncl rpl_truncl +# endif +_GL_FUNCDECL_RPL (truncl, long double, (long double x)); +_GL_CXXALIAS_RPL (truncl, long double, (long double x)); +# else +# if !@HAVE_DECL_TRUNCL@ +_GL_FUNCDECL_SYS (truncl, long double, (long double x)); +# endif +_GL_CXXALIAS_SYS (truncl, long double, (long double x)); # endif +_GL_CXXALIASWARN (truncl); #elif defined GNULIB_POSIXCHECK # undef truncl -# define truncl(x) \ - (GL_LINK_WARNING ("truncl is unportable - " \ - "use gnulib module truncl for portability"), \ - truncl (x)) +# if HAVE_RAW_DECL_TRUNCL +_GL_WARN_ON_USE (truncl, "truncl is unportable - " + "use gnulib module truncl for portability"); +# endif #endif #if @GNULIB_ISFINITE@ # if @REPLACE_ISFINITE@ -extern int gl_isfinitef (float x); -extern int gl_isfinited (double x); -extern int gl_isfinitel (long double x); +_GL_EXTERN_C int gl_isfinitef (float x); +_GL_EXTERN_C int gl_isfinited (double x); +_GL_EXTERN_C int gl_isfinitel (long double x); # undef isfinite # define isfinite(x) \ (sizeof (x) == sizeof (long double) ? gl_isfinitel (x) : \ @@ -384,15 +555,19 @@ extern int gl_isfinitel (long double x); gl_isfinitef (x)) # endif #elif defined GNULIB_POSIXCHECK - /* How to override a macro? */ +# if defined isfinite +_GL_WARN_REAL_FLOATING_DECL (isfinite); +# undef isfinite +# define isfinite(x) _GL_WARN_REAL_FLOATING_IMPL (isfinite, x) +# endif #endif #if @GNULIB_ISINF@ # if @REPLACE_ISINF@ -extern int gl_isinff (float x); -extern int gl_isinfd (double x); -extern int gl_isinfl (long double x); +_GL_EXTERN_C int gl_isinff (float x); +_GL_EXTERN_C int gl_isinfd (double x); +_GL_EXTERN_C int gl_isinfl (long double x); # undef isinf # define isinf(x) \ (sizeof (x) == sizeof (long double) ? gl_isinfl (x) : \ @@ -400,7 +575,11 @@ extern int gl_isinfl (long double x); gl_isinff (x)) # endif #elif defined GNULIB_POSIXCHECK - /* How to override a macro? */ +# if defined isinf +_GL_WARN_REAL_FLOATING_DECL (isinf); +# undef isinf +# define isinf(x) _GL_WARN_REAL_FLOATING_IMPL (isinf, x) +# endif #endif @@ -409,7 +588,6 @@ extern int gl_isinfl (long double x); # if @HAVE_ISNANF@ /* The original included above provides a declaration of isnan macro or (older) isnanf function. */ -# include # if __GNUC__ >= 4 /* GCC 4.0 and newer provides three built-ins for isnan. */ # undef isnanf @@ -422,7 +600,7 @@ extern int gl_isinfl (long double x); /* Test whether X is a NaN. */ # undef isnanf # define isnanf rpl_isnanf -extern int isnanf (float x); +_GL_EXTERN_C int isnanf (float x); # endif #endif @@ -432,7 +610,6 @@ extern int isnanf (float x); to 'double' numbers earlier but now is a type-generic macro. */ # if @HAVE_ISNAND@ /* The original included above provides a declaration of isnan macro. */ -# include # if __GNUC__ >= 4 /* GCC 4.0 and newer provides three built-ins for isnan. */ # undef isnand @@ -445,7 +622,7 @@ extern int isnanf (float x); /* Test whether X is a NaN. */ # undef isnand # define isnand rpl_isnand -extern int isnand (double x); +_GL_EXTERN_C int isnand (double x); # endif #endif @@ -453,7 +630,6 @@ extern int isnand (double x); /* Test for NaN for 'long double' numbers. */ # if @HAVE_ISNANL@ /* The original included above provides a declaration of isnan macro or (older) isnanl function. */ -# include # if __GNUC__ >= 4 /* GCC 4.0 and newer provides three built-ins for isnan. */ # undef isnanl @@ -466,7 +642,7 @@ extern int isnand (double x); /* Test whether X is a NaN. */ # undef isnanl # define isnanl rpl_isnanl -extern int isnanl (long double x); +_GL_EXTERN_C int isnanl (long double x); # endif #endif @@ -480,19 +656,19 @@ extern int isnanl (long double x); # if @HAVE_ISNANF@ && __GNUC__ >= 4 # define gl_isnan_f(x) __builtin_isnan ((float)(x)) # else -extern int rpl_isnanf (float x); +_GL_EXTERN_C int rpl_isnanf (float x); # define gl_isnan_f(x) rpl_isnanf (x) # endif # if @HAVE_ISNAND@ && __GNUC__ >= 4 # define gl_isnan_d(x) __builtin_isnan ((double)(x)) # else -extern int rpl_isnand (double x); +_GL_EXTERN_C int rpl_isnand (double x); # define gl_isnan_d(x) rpl_isnand (x) # endif # if @HAVE_ISNANL@ && __GNUC__ >= 4 # define gl_isnan_l(x) __builtin_isnan ((long double)(x)) # else -extern int rpl_isnanl (long double x); +_GL_EXTERN_C int rpl_isnanl (long double x); # define gl_isnan_l(x) rpl_isnanl (x) # endif # undef isnan @@ -502,7 +678,11 @@ extern int rpl_isnanl (long double x); gl_isnan_f (x)) # endif #elif defined GNULIB_POSIXCHECK - /* How to override a macro? */ +# if defined isnan +_GL_WARN_REAL_FLOATING_DECL (isnan); +# undef isnan +# define isnan(x) _GL_WARN_REAL_FLOATING_IMPL (isnan, x) +# endif #endif @@ -517,38 +697,38 @@ extern int rpl_isnanl (long double x); # endif # if @REPLACE_SIGNBIT@ # undef signbit -extern int gl_signbitf (float arg); -extern int gl_signbitd (double arg); -extern int gl_signbitl (long double arg); +_GL_EXTERN_C int gl_signbitf (float arg); +_GL_EXTERN_C int gl_signbitd (double arg); +_GL_EXTERN_C int gl_signbitl (long double arg); # if __GNUC__ >= 2 && !__STRICT_ANSI__ # if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined gl_signbitf # define gl_signbitf_OPTIMIZED_MACRO # define gl_signbitf(arg) \ - ({ union { float _value; \ + ({ union { float _value; \ unsigned int _word[(sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ - } _m; \ - _m._value = (arg); \ - (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \ + } _m; \ + _m._value = (arg); \ + (_m._word[FLT_SIGNBIT_WORD] >> FLT_SIGNBIT_BIT) & 1; \ }) # endif # if defined DBL_SIGNBIT_WORD && defined DBL_SIGNBIT_BIT && !defined gl_signbitd # define gl_signbitd_OPTIMIZED_MACRO # define gl_signbitd(arg) \ - ({ union { double _value; \ + ({ union { double _value; \ unsigned int _word[(sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ - } _m; \ - _m._value = (arg); \ - (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \ + } _m; \ + _m._value = (arg); \ + (_m._word[DBL_SIGNBIT_WORD] >> DBL_SIGNBIT_BIT) & 1; \ }) # endif # if defined LDBL_SIGNBIT_WORD && defined LDBL_SIGNBIT_BIT && !defined gl_signbitl # define gl_signbitl_OPTIMIZED_MACRO # define gl_signbitl(arg) \ - ({ union { long double _value; \ + ({ union { long double _value; \ unsigned int _word[(sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)]; \ - } _m; \ - _m._value = (arg); \ - (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \ + } _m; \ + _m._value = (arg); \ + (_m._word[LDBL_SIGNBIT_WORD] >> LDBL_SIGNBIT_BIT) & 1; \ }) # endif # endif @@ -558,13 +738,13 @@ extern int gl_signbitl (long double arg); gl_signbitf (x)) # endif #elif defined GNULIB_POSIXCHECK - /* How to override a macro? */ +# if defined signbit +_GL_WARN_REAL_FLOATING_DECL (signbit); +# undef signbit +# define signbit(x) _GL_WARN_REAL_FLOATING_IMPL (signbit, x) +# endif #endif -#ifdef __cplusplus -} -#endif - #endif /* _GL_MATH_H */ #endif /* _GL_MATH_H */ diff --git a/lib/mbchar.c b/lib/mbchar.c index 0851d8ad..da910565 100644 --- a/lib/mbchar.c +++ b/lib/mbchar.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2001, 2006, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -25,10 +25,10 @@ /* Bit table of characters in the ISO C "basic character set". */ const unsigned int is_basic_table [UCHAR_MAX / 32 + 1] = { - 0x00001a00, /* '\t' '\v' '\f' */ - 0xffffffef, /* ' '...'#' '%'...'?' */ - 0xfffffffe, /* 'A'...'Z' '[' '\\' ']' '^' '_' */ - 0x7ffffffe /* 'a'...'z' '{' '|' '}' '~' */ + 0x00001a00, /* '\t' '\v' '\f' */ + 0xffffffef, /* ' '...'#' '%'...'?' */ + 0xfffffffe, /* 'A'...'Z' '[' '\\' ']' '^' '_' */ + 0x7ffffffe /* 'a'...'z' '{' '|' '}' '~' */ /* The remaining bits are 0. */ }; diff --git a/lib/mbchar.h b/lib/mbchar.h index e184dd02..f9f52b9c 100644 --- a/lib/mbchar.h +++ b/lib/mbchar.h @@ -1,5 +1,5 @@ /* Multibyte character data type. - Copyright (C) 2001, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 2001, 2005-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -114,31 +114,31 @@ Here are the function prototypes of the macros. - extern const char * mb_ptr (const mbchar_t mbc); - extern size_t mb_len (const mbchar_t mbc); - extern bool mb_iseq (const mbchar_t mbc, char sc); - extern bool mb_isnul (const mbchar_t mbc); - extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2); - extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2); - extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2); - extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2); - extern bool mb_isalnum (const mbchar_t mbc); - extern bool mb_isalpha (const mbchar_t mbc); - extern bool mb_isascii (const mbchar_t mbc); - extern bool mb_isblank (const mbchar_t mbc); - extern bool mb_iscntrl (const mbchar_t mbc); - extern bool mb_isdigit (const mbchar_t mbc); - extern bool mb_isgraph (const mbchar_t mbc); - extern bool mb_islower (const mbchar_t mbc); - extern bool mb_isprint (const mbchar_t mbc); - extern bool mb_ispunct (const mbchar_t mbc); - extern bool mb_isspace (const mbchar_t mbc); - extern bool mb_isupper (const mbchar_t mbc); - extern bool mb_isxdigit (const mbchar_t mbc); - extern int mb_width (const mbchar_t mbc); - extern void mb_putc (const mbchar_t mbc, FILE *stream); + extern const char * mb_ptr (const mbchar_t mbc); + extern size_t mb_len (const mbchar_t mbc); + extern bool mb_iseq (const mbchar_t mbc, char sc); + extern bool mb_isnul (const mbchar_t mbc); + extern int mb_cmp (const mbchar_t mbc1, const mbchar_t mbc2); + extern int mb_casecmp (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_equal (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_caseequal (const mbchar_t mbc1, const mbchar_t mbc2); + extern bool mb_isalnum (const mbchar_t mbc); + extern bool mb_isalpha (const mbchar_t mbc); + extern bool mb_isascii (const mbchar_t mbc); + extern bool mb_isblank (const mbchar_t mbc); + extern bool mb_iscntrl (const mbchar_t mbc); + extern bool mb_isdigit (const mbchar_t mbc); + extern bool mb_isgraph (const mbchar_t mbc); + extern bool mb_islower (const mbchar_t mbc); + extern bool mb_isprint (const mbchar_t mbc); + extern bool mb_ispunct (const mbchar_t mbc); + extern bool mb_isspace (const mbchar_t mbc); + extern bool mb_isupper (const mbchar_t mbc); + extern bool mb_isxdigit (const mbchar_t mbc); + extern int mb_width (const mbchar_t mbc); + extern void mb_putc (const mbchar_t mbc, FILE *stream); extern void mb_setascii (mbchar_t *new, char sc); - extern void mb_copy (mbchar_t *new, const mbchar_t *old); + extern void mb_copy (mbchar_t *new, const mbchar_t *old); */ #ifndef _MBCHAR_H @@ -160,10 +160,10 @@ struct mbchar { - const char *ptr; /* pointer to current character */ - size_t bytes; /* number of bytes of current character, > 0 */ - bool wc_valid; /* true if wc is a valid wide character */ - wchar_t wc; /* if wc_valid: the current character */ + const char *ptr; /* pointer to current character */ + size_t bytes; /* number of bytes of current character, > 0 */ + bool wc_valid; /* true if wc is a valid wide character */ + wchar_t wc; /* if wc_valid: the current character */ char buf[MBCHAR_BUF_SIZE]; /* room for the bytes, used for file input only */ }; @@ -180,38 +180,38 @@ typedef struct mbchar mbchar_t; #define mb_iseq(mbc, sc) ((mbc).wc_valid && (mbc).wc == (sc)) #define mb_isnul(mbc) ((mbc).wc_valid && (mbc).wc == 0) #define mb_cmp(mbc1, mbc2) \ - ((mbc1).wc_valid \ - ? ((mbc2).wc_valid \ - ? (int) (mbc1).wc - (int) (mbc2).wc \ - : -1) \ - : ((mbc2).wc_valid \ - ? 1 \ - : (mbc1).bytes == (mbc2).bytes \ - ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ - : (mbc1).bytes < (mbc2).bytes \ + ((mbc1).wc_valid \ + ? ((mbc2).wc_valid \ + ? (int) (mbc1).wc - (int) (mbc2).wc \ + : -1) \ + : ((mbc2).wc_valid \ + ? 1 \ + : (mbc1).bytes == (mbc2).bytes \ + ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ + : (mbc1).bytes < (mbc2).bytes \ ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) #define mb_casecmp(mbc1, mbc2) \ - ((mbc1).wc_valid \ - ? ((mbc2).wc_valid \ - ? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \ - : -1) \ - : ((mbc2).wc_valid \ - ? 1 \ - : (mbc1).bytes == (mbc2).bytes \ - ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ - : (mbc1).bytes < (mbc2).bytes \ + ((mbc1).wc_valid \ + ? ((mbc2).wc_valid \ + ? (int) towlower ((mbc1).wc) - (int) towlower ((mbc2).wc) \ + : -1) \ + : ((mbc2).wc_valid \ + ? 1 \ + : (mbc1).bytes == (mbc2).bytes \ + ? memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) \ + : (mbc1).bytes < (mbc2).bytes \ ? (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) > 0 ? 1 : -1) \ : (memcmp ((mbc1).ptr, (mbc2).ptr, (mbc2).bytes) >= 0 ? 1 : -1))) #define mb_equal(mbc1, mbc2) \ - ((mbc1).wc_valid && (mbc2).wc_valid \ - ? (mbc1).wc == (mbc2).wc \ - : (mbc1).bytes == (mbc2).bytes \ + ((mbc1).wc_valid && (mbc2).wc_valid \ + ? (mbc1).wc == (mbc2).wc \ + : (mbc1).bytes == (mbc2).bytes \ && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) #define mb_caseequal(mbc1, mbc2) \ - ((mbc1).wc_valid && (mbc2).wc_valid \ - ? towlower ((mbc1).wc) == towlower ((mbc2).wc) \ - : (mbc1).bytes == (mbc2).bytes \ + ((mbc1).wc_valid && (mbc2).wc_valid \ + ? towlower ((mbc1).wc) == towlower ((mbc2).wc) \ + : (mbc1).bytes == (mbc2).bytes \ && memcmp ((mbc1).ptr, (mbc2).ptr, (mbc1).bytes) == 0) /* , classification. */ @@ -308,7 +308,7 @@ static inline bool is_basic (char c) { return (is_basic_table [(unsigned char) c >> 5] >> ((unsigned char) c & 31)) - & 1; + & 1; } #else diff --git a/lib/mbiter.h b/lib/mbiter.h index a4782d4b..8f443b59 100644 --- a/lib/mbiter.h +++ b/lib/mbiter.h @@ -1,5 +1,5 @@ /* Iterating through multibyte strings: macros for multi-byte encodings. - Copyright (C) 2001, 2005, 2007 Free Software Foundation, Inc. + Copyright (C) 2001, 2005, 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -69,14 +69,14 @@ Here are the function prototypes of the macros. - extern void mbi_init (mbi_iterator_t iter, - const char *startptr, size_t length); - extern bool mbi_avail (mbi_iterator_t iter); - extern void mbi_advance (mbi_iterator_t iter); - extern mbchar_t mbi_cur (mbi_iterator_t iter); - extern const char * mbi_cur_ptr (mbi_iterator_t iter); - extern void mbi_reloc (mbi_iterator_t iter, ptrdiff_t ptrdiff); - extern void mbi_copy (mbi_iterator_t *new, const mbi_iterator_t *old); + extern void mbi_init (mbi_iterator_t iter, + const char *startptr, size_t length); + extern bool mbi_avail (mbi_iterator_t iter); + extern void mbi_advance (mbi_iterator_t iter); + extern mbchar_t mbi_cur (mbi_iterator_t iter); + extern const char * mbi_cur_ptr (mbi_iterator_t iter); + extern void mbi_reloc (mbi_iterator_t iter, ptrdiff_t ptrdiff); + extern void mbi_copy (mbi_iterator_t *new, const mbi_iterator_t *old); */ #ifndef _MBITER_H @@ -99,17 +99,17 @@ struct mbiter_multi { - const char *limit; /* pointer to end of string */ - bool in_shift; /* true if next byte may not be interpreted as ASCII */ - mbstate_t state; /* if in_shift: current shift state */ - bool next_done; /* true if mbi_avail has already filled the following */ - struct mbchar cur; /* the current character: - const char *cur.ptr pointer to current character - The following are only valid after mbi_avail. - size_t cur.bytes number of bytes of current character - bool cur.wc_valid true if wc is a valid wide character - wchar_t cur.wc if wc_valid: the current character - */ + const char *limit; /* pointer to end of string */ + bool in_shift; /* true if next byte may not be interpreted as ASCII */ + mbstate_t state; /* if in_shift: current shift state */ + bool next_done; /* true if mbi_avail has already filled the following */ + struct mbchar cur; /* the current character: + const char *cur.ptr pointer to current character + The following are only valid after mbi_avail. + size_t cur.bytes number of bytes of current character + bool cur.wc_valid true if wc is a valid wide character + wchar_t cur.wc if wc_valid: the current character + */ }; static inline void @@ -123,8 +123,8 @@ mbiter_multi_next (struct mbiter_multi *iter) if (is_basic (*iter->cur.ptr)) { /* These characters are part of the basic character set. ISO C 99 - guarantees that their wide character code is identical to their - char code. */ + guarantees that their wide character code is identical to their + char code. */ iter->cur.bytes = 1; iter->cur.wc = *iter->cur.ptr; iter->cur.wc_valid = true; @@ -135,39 +135,39 @@ mbiter_multi_next (struct mbiter_multi *iter) iter->in_shift = true; with_shift: iter->cur.bytes = mbrtowc (&iter->cur.wc, iter->cur.ptr, - iter->limit - iter->cur.ptr, &iter->state); + iter->limit - iter->cur.ptr, &iter->state); if (iter->cur.bytes == (size_t) -1) - { - /* An invalid multibyte sequence was encountered. */ - iter->cur.bytes = 1; - iter->cur.wc_valid = false; - /* Whether to set iter->in_shift = false and reset iter->state - or not is not very important; the string is bogus anyway. */ - } + { + /* An invalid multibyte sequence was encountered. */ + iter->cur.bytes = 1; + iter->cur.wc_valid = false; + /* Whether to set iter->in_shift = false and reset iter->state + or not is not very important; the string is bogus anyway. */ + } else if (iter->cur.bytes == (size_t) -2) - { - /* An incomplete multibyte character at the end. */ - iter->cur.bytes = iter->limit - iter->cur.ptr; - iter->cur.wc_valid = false; - /* Whether to set iter->in_shift = false and reset iter->state - or not is not important; the string end is reached anyway. */ - } + { + /* An incomplete multibyte character at the end. */ + iter->cur.bytes = iter->limit - iter->cur.ptr; + iter->cur.wc_valid = false; + /* Whether to set iter->in_shift = false and reset iter->state + or not is not important; the string end is reached anyway. */ + } else - { - if (iter->cur.bytes == 0) - { - /* A null wide character was encountered. */ - iter->cur.bytes = 1; - assert (*iter->cur.ptr == '\0'); - assert (iter->cur.wc == 0); - } - iter->cur.wc_valid = true; - - /* When in the initial state, we can go back treating ASCII - characters more quickly. */ - if (mbsinit (&iter->state)) - iter->in_shift = false; - } + { + if (iter->cur.bytes == 0) + { + /* A null wide character was encountered. */ + iter->cur.bytes = 1; + assert (*iter->cur.ptr == '\0'); + assert (iter->cur.wc == 0); + } + iter->cur.wc_valid = true; + + /* When in the initial state, we can go back treating ASCII + characters more quickly. */ + if (mbsinit (&iter->state)) + iter->in_shift = false; + } } iter->next_done = true; } diff --git a/lib/mbrtowc.c b/lib/mbrtowc.c index 7b528e80..31f229cc 100644 --- a/lib/mbrtowc.c +++ b/lib/mbrtowc.c @@ -1,5 +1,5 @@ /* Convert multibyte character to wide character. - Copyright (C) 1999-2002, 2005-2009 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2005-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2008. This program is free software: you can redistribute it and/or modify @@ -63,30 +63,30 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) switch (nstate) { case 0: - p = s; - m = n; - break; + p = s; + m = n; + break; case 3: - buf[2] = pstate[3]; - /*FALLTHROUGH*/ + buf[2] = pstate[3]; + /*FALLTHROUGH*/ case 2: - buf[1] = pstate[2]; - /*FALLTHROUGH*/ + buf[1] = pstate[2]; + /*FALLTHROUGH*/ case 1: - buf[0] = pstate[1]; - p = buf; - m = nstate; - buf[m++] = s[0]; - if (n >= 2 && m < 4) - { - buf[m++] = s[1]; - if (n >= 3 && m < 4) - buf[m++] = s[2]; - } - break; + buf[0] = pstate[1]; + p = buf; + m = nstate; + buf[m++] = s[0]; + if (n >= 2 && m < 4) + { + buf[m++] = s[1]; + if (n >= 3 && m < 4) + buf[m++] = s[2]; + } + break; default: - errno = EINVAL; - return (size_t)(-1); + errno = EINVAL; + return (size_t)(-1); } /* Here m > 0. */ @@ -99,208 +99,208 @@ mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) int res = mbtowc (pwc, p, m); if (res >= 0) - { - if (pwc != NULL && ((*pwc == 0) != (res == 0))) - abort (); - if (nstate >= (res > 0 ? res : 1)) - abort (); - res -= nstate; - pstate[0] = 0; - return res; - } + { + if (pwc != NULL && ((*pwc == 0) != (res == 0))) + abort (); + if (nstate >= (res > 0 ? res : 1)) + abort (); + res -= nstate; + pstate[0] = 0; + return res; + } /* mbtowc does not distinguish between invalid and incomplete multibyte - sequences. But mbrtowc needs to make this distinction. - There are two possible approaches: - - Use iconv() and its return value. - - Use built-in knowledge about the possible encodings. - Given the low quality of implementation of iconv() on the systems that - lack mbrtowc(), we use the second approach. - The possible encodings are: - - 8-bit encodings, - - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS, - - UTF-8. - Use specialized code for each. */ + sequences. But mbrtowc needs to make this distinction. + There are two possible approaches: + - Use iconv() and its return value. + - Use built-in knowledge about the possible encodings. + Given the low quality of implementation of iconv() on the systems that + lack mbrtowc(), we use the second approach. + The possible encodings are: + - 8-bit encodings, + - EUC-JP, EUC-KR, GB2312, EUC-TW, BIG5, GB18030, SJIS, + - UTF-8. + Use specialized code for each. */ if (m >= 4 || m >= MB_CUR_MAX) - goto invalid; + goto invalid; /* Here MB_CUR_MAX > 1 and 0 < m < 4. */ { - const char *encoding = locale_charset (); - - if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0)) - { - /* Cf. unistr/u8-mblen.c. */ - unsigned char c = (unsigned char) p[0]; - - if (c >= 0xc2) - { - if (c < 0xe0) - { - if (m == 1) - goto incomplete; - } - else if (c < 0xf0) - { - if (m == 1) - goto incomplete; - if (m == 2) - { - unsigned char c2 = (unsigned char) p[1]; - - if ((c2 ^ 0x80) < 0x40 - && (c >= 0xe1 || c2 >= 0xa0) - && (c != 0xed || c2 < 0xa0)) - goto incomplete; - } - } - else if (c <= 0xf4) - { - if (m == 1) - goto incomplete; - else /* m == 2 || m == 3 */ - { - unsigned char c2 = (unsigned char) p[1]; - - if ((c2 ^ 0x80) < 0x40 - && (c >= 0xf1 || c2 >= 0x90) - && (c < 0xf4 || (c == 0xf4 && c2 < 0x90))) - { - if (m == 2) - goto incomplete; - else /* m == 3 */ - { - unsigned char c3 = (unsigned char) p[2]; - - if ((c3 ^ 0x80) < 0x40) - goto incomplete; - } - } - } - } - } - goto invalid; - } - - /* As a reference for this code, you can use the GNU libiconv - implementation. Look for uses of the RET_TOOFEW macro. */ - - if (STREQ (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)) - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f) - goto incomplete; - } - if (m == 2) - { - unsigned char c = (unsigned char) p[0]; - - if (c == 0x8f) - { - unsigned char c2 = (unsigned char) p[1]; - - if (c2 >= 0xa1 && c2 < 0xff) - goto incomplete; - } - } - goto invalid; - } - if (STREQ (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) - || STREQ (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0) - || STREQ (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)) - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if (c >= 0xa1 && c < 0xff) - goto incomplete; - } - goto invalid; - } - if (STREQ (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)) - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if ((c >= 0xa1 && c < 0xff) || c == 0x8e) - goto incomplete; - } - else /* m == 2 || m == 3 */ - { - unsigned char c = (unsigned char) p[0]; - - if (c == 0x8e) - goto incomplete; - } - goto invalid; - } - if (STREQ (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0)) - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe)) - goto incomplete; - } - else /* m == 2 || m == 3 */ - { - unsigned char c = (unsigned char) p[0]; - - if (c >= 0x90 && c <= 0xe3) - { - unsigned char c2 = (unsigned char) p[1]; - - if (c2 >= 0x30 && c2 <= 0x39) - { - if (m == 2) - goto incomplete; - else /* m == 3 */ - { - unsigned char c3 = (unsigned char) p[2]; - - if (c3 >= 0x81 && c3 <= 0xfe) - goto incomplete; - } - } - } - } - goto invalid; - } - if (STREQ (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0)) - { - if (m == 1) - { - unsigned char c = (unsigned char) p[0]; - - if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea) - || (c >= 0xf0 && c <= 0xf9)) - goto incomplete; - } - goto invalid; - } - - /* An unknown multibyte encoding. */ - goto incomplete; + const char *encoding = locale_charset (); + + if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0, 0)) + { + /* Cf. unistr/u8-mblen.c. */ + unsigned char c = (unsigned char) p[0]; + + if (c >= 0xc2) + { + if (c < 0xe0) + { + if (m == 1) + goto incomplete; + } + else if (c < 0xf0) + { + if (m == 1) + goto incomplete; + if (m == 2) + { + unsigned char c2 = (unsigned char) p[1]; + + if ((c2 ^ 0x80) < 0x40 + && (c >= 0xe1 || c2 >= 0xa0) + && (c != 0xed || c2 < 0xa0)) + goto incomplete; + } + } + else if (c <= 0xf4) + { + if (m == 1) + goto incomplete; + else /* m == 2 || m == 3 */ + { + unsigned char c2 = (unsigned char) p[1]; + + if ((c2 ^ 0x80) < 0x40 + && (c >= 0xf1 || c2 >= 0x90) + && (c < 0xf4 || (c == 0xf4 && c2 < 0x90))) + { + if (m == 2) + goto incomplete; + else /* m == 3 */ + { + unsigned char c3 = (unsigned char) p[2]; + + if ((c3 ^ 0x80) < 0x40) + goto incomplete; + } + } + } + } + } + goto invalid; + } + + /* As a reference for this code, you can use the GNU libiconv + implementation. Look for uses of the RET_TOOFEW macro. */ + + if (STREQ (encoding, "EUC-JP", 'E', 'U', 'C', '-', 'J', 'P', 0, 0, 0)) + { + if (m == 1) + { + unsigned char c = (unsigned char) p[0]; + + if ((c >= 0xa1 && c < 0xff) || c == 0x8e || c == 0x8f) + goto incomplete; + } + if (m == 2) + { + unsigned char c = (unsigned char) p[0]; + + if (c == 0x8f) + { + unsigned char c2 = (unsigned char) p[1]; + + if (c2 >= 0xa1 && c2 < 0xff) + goto incomplete; + } + } + goto invalid; + } + if (STREQ (encoding, "EUC-KR", 'E', 'U', 'C', '-', 'K', 'R', 0, 0, 0) + || STREQ (encoding, "GB2312", 'G', 'B', '2', '3', '1', '2', 0, 0, 0) + || STREQ (encoding, "BIG5", 'B', 'I', 'G', '5', 0, 0, 0, 0, 0)) + { + if (m == 1) + { + unsigned char c = (unsigned char) p[0]; + + if (c >= 0xa1 && c < 0xff) + goto incomplete; + } + goto invalid; + } + if (STREQ (encoding, "EUC-TW", 'E', 'U', 'C', '-', 'T', 'W', 0, 0, 0)) + { + if (m == 1) + { + unsigned char c = (unsigned char) p[0]; + + if ((c >= 0xa1 && c < 0xff) || c == 0x8e) + goto incomplete; + } + else /* m == 2 || m == 3 */ + { + unsigned char c = (unsigned char) p[0]; + + if (c == 0x8e) + goto incomplete; + } + goto invalid; + } + if (STREQ (encoding, "GB18030", 'G', 'B', '1', '8', '0', '3', '0', 0, 0)) + { + if (m == 1) + { + unsigned char c = (unsigned char) p[0]; + + if ((c >= 0x90 && c <= 0xe3) || (c >= 0xf8 && c <= 0xfe)) + goto incomplete; + } + else /* m == 2 || m == 3 */ + { + unsigned char c = (unsigned char) p[0]; + + if (c >= 0x90 && c <= 0xe3) + { + unsigned char c2 = (unsigned char) p[1]; + + if (c2 >= 0x30 && c2 <= 0x39) + { + if (m == 2) + goto incomplete; + else /* m == 3 */ + { + unsigned char c3 = (unsigned char) p[2]; + + if (c3 >= 0x81 && c3 <= 0xfe) + goto incomplete; + } + } + } + } + goto invalid; + } + if (STREQ (encoding, "SJIS", 'S', 'J', 'I', 'S', 0, 0, 0, 0, 0)) + { + if (m == 1) + { + unsigned char c = (unsigned char) p[0]; + + if ((c >= 0x81 && c <= 0x9f) || (c >= 0xe0 && c <= 0xea) + || (c >= 0xf0 && c <= 0xf9)) + goto incomplete; + } + goto invalid; + } + + /* An unknown multibyte encoding. */ + goto incomplete; } incomplete: { - size_t k = nstate; - /* Here 0 <= k < m < 4. */ - pstate[++k] = s[0]; - if (k < m) - { - pstate[++k] = s[1]; - if (k < m) - pstate[++k] = s[2]; - } - if (k != m) - abort (); + size_t k = nstate; + /* Here 0 <= k < m < 4. */ + pstate[++k] = s[0]; + if (k < m) + { + pstate[++k] = s[1]; + if (k < m) + pstate[++k] = s[2]; + } + if (k != m) + abort (); } pstate[0] = m; return (size_t)(-2); @@ -341,25 +341,25 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) if (!mbsinit (ps)) { - /* Parse the rest of the multibyte character byte for byte. */ - size_t count = 0; - for (; n > 0; s++, n--) - { - wchar_t wc; - size_t ret = mbrtowc (&wc, s, 1, ps); - - if (ret == (size_t)(-1)) - return (size_t)(-1); - count++; - if (ret != (size_t)(-2)) - { - /* The multibyte character has been completed. */ - if (pwc != NULL) - *pwc = wc; - return (wc == 0 ? 0 : count); - } - } - return (size_t)(-2); + /* Parse the rest of the multibyte character byte for byte. */ + size_t count = 0; + for (; n > 0; s++, n--) + { + wchar_t wc; + size_t ret = mbrtowc (&wc, s, 1, ps); + + if (ret == (size_t)(-1)) + return (size_t)(-1); + count++; + if (ret != (size_t)(-2)) + { + /* The multibyte character has been completed. */ + if (pwc != NULL) + *pwc = wc; + return (wc == 0 ? 0 : count); + } + } + return (size_t)(-2); } } # endif @@ -371,10 +371,10 @@ rpl_mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) if (ret != (size_t)(-1) && ret != (size_t)(-2)) { - if (pwc != NULL) - *pwc = wc; - if (wc == 0) - ret = 0; + if (pwc != NULL) + *pwc = wc; + if (wc == 0) + ret = 0; } return ret; } diff --git a/lib/mbsinit.c b/lib/mbsinit.c index 74957943..811e39bb 100644 --- a/lib/mbsinit.c +++ b/lib/mbsinit.c @@ -1,5 +1,5 @@ /* Test for initial conversion state. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc. Written by Bruno Haible , 2008. This program is free software: you can redistribute it and/or modify diff --git a/lib/mbsnlen.c b/lib/mbsnlen.c index 5ed55567..3db4eb6b 100644 --- a/lib/mbsnlen.c +++ b/lib/mbsnlen.c @@ -1,5 +1,5 @@ /* Counting the multibyte characters in a string. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify @@ -36,7 +36,7 @@ mbsnlen (const char *string, size_t len) count = 0; for (mbi_init (iter, string, len); mbi_avail (iter); mbi_advance (iter)) - count++; + count++; return count; } diff --git a/lib/memchr.c b/lib/memchr.c index 3ea1d5ba..1e897cd9 100644 --- a/lib/memchr.c +++ b/lib/memchr.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1993, 1996, 1997, 1999, 2000, 2003, 2004, 2006, 2008 +/* Copyright (C) 1991, 1993, 1996-1997, 1999-2000, 2003-2004, 2006, 2008-2010 Free Software Foundation, Inc. Based on strlen implementation by Torbjorn Granlund (tege@sics.se), @@ -97,15 +97,15 @@ __memchr (void const *s, int c_in, size_t n) repeated_one |= repeated_one << 31 << 1; repeated_c |= repeated_c << 31 << 1; if (8 < sizeof (longword)) - { - size_t i; - - for (i = 64; i < sizeof (longword) * 8; i *= 2) - { - repeated_one |= repeated_one << i; - repeated_c |= repeated_c << i; - } - } + { + size_t i; + + for (i = 64; i < sizeof (longword) * 8; i *= 2) + { + repeated_one |= repeated_one << i; + repeated_c |= repeated_c << i; + } + } } /* Instead of the traditional loop which tests each byte, we will test a @@ -144,8 +144,8 @@ __memchr (void const *s, int c_in, size_t n) longword longword1 = *longword_ptr ^ repeated_c; if ((((longword1 - repeated_one) & ~longword1) - & (repeated_one << 7)) != 0) - break; + & (repeated_one << 7)) != 0) + break; longword_ptr++; n -= sizeof (longword); } @@ -162,7 +162,7 @@ __memchr (void const *s, int c_in, size_t n) for (; n > 0; --n, ++char_ptr) { if (*char_ptr == c) - return (void *) char_ptr; + return (void *) char_ptr; } return NULL; diff --git a/lib/memcmp2.c b/lib/memcmp2.c index 7f8f6049..a0429483 100644 --- a/lib/memcmp2.c +++ b/lib/memcmp2.c @@ -1,5 +1,5 @@ /* Compare two memory areas with possibly different lengths. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -28,9 +28,9 @@ memcmp2 (const char *s1, size_t n1, const char *s2, size_t n2) if (cmp == 0) { if (n1 < n2) - cmp = -1; + cmp = -1; else if (n1 > n2) - cmp = 1; + cmp = 1; } return cmp; } diff --git a/lib/memcmp2.h b/lib/memcmp2.h index f3230554..c00e1418 100644 --- a/lib/memcmp2.h +++ b/lib/memcmp2.h @@ -1,5 +1,5 @@ /* Compare two memory areas with possibly different lengths. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/memxfrm.c b/lib/memxfrm.c index dc6eda1f..a1c6cf8a 100644 --- a/lib/memxfrm.c +++ b/lib/memxfrm.c @@ -1,5 +1,5 @@ /* Locale dependent memory area transformation for comparison. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -45,7 +45,7 @@ memxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp) allocated = (n > 0 ? n : 1); result = (char *) malloc (allocated); if (result == NULL) - goto out_of_memory_2; + goto out_of_memory_2; } length = 0; @@ -63,44 +63,44 @@ memxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp) p = s; for (;;) { - /* Search next NUL byte. */ - const char *q = p + strlen (p); - - for (;;) - { - size_t k; - - errno = 0; - k = strxfrm (result + length, p, allocated - length); - if (errno != 0) - goto fail; - if (k >= allocated - length) - { - /* Grow the result buffer. */ - char *new_result; - - allocated = 2 * allocated; - if (allocated < 64) - allocated = 64; - if (result == resultbuf) - new_result = (char *) malloc (allocated); - else - new_result = (char *) realloc (result, allocated); - if (new_result == NULL) - goto out_of_memory_1; - result = new_result; - } - else - { - length += k; - break; - } - } - - p = q + 1; - if (p == p_end) - break; - result[length] = '\0'; + /* Search next NUL byte. */ + const char *q = p + strlen (p); + + for (;;) + { + size_t k; + + errno = 0; + k = strxfrm (result + length, p, allocated - length); + if (errno != 0) + goto fail; + if (k >= allocated - length) + { + /* Grow the result buffer. */ + char *new_result; + + allocated = 2 * allocated; + if (allocated < 64) + allocated = 64; + if (result == resultbuf) + new_result = (char *) malloc (allocated); + else + new_result = (char *) realloc (result, allocated); + if (new_result == NULL) + goto out_of_memory_1; + result = new_result; + } + else + { + length += k; + break; + } + } + + p = q + 1; + if (p == p_end) + break; + result[length] = '\0'; length++; } } @@ -110,7 +110,7 @@ memxfrm (char *s, size_t n, char *resultbuf, size_t *lengthp) { char *memory = (char *) realloc (result, length > 0 ? length : 1); if (memory != NULL) - result = memory; + result = memory; } s[n] = orig_sentinel; diff --git a/lib/memxfrm.h b/lib/memxfrm.h index d78900a7..8b7284a6 100644 --- a/lib/memxfrm.h +++ b/lib/memxfrm.h @@ -1,5 +1,5 @@ /* Locale dependent memory area transformation for comparison. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/minmax.h b/lib/minmax.h index 4cafb2f2..d8ba9838 100644 --- a/lib/minmax.h +++ b/lib/minmax.h @@ -1,5 +1,6 @@ /* MIN, MAX macros. - Copyright (C) 1995, 1998, 2001, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 1995, 1998, 2001, 2003, 2005, 2009, 2010 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/printf-args.c b/lib/printf-args.c index c31d2042..597bba98 100644 --- a/lib/printf-args.c +++ b/lib/printf-args.c @@ -1,5 +1,6 @@ /* Decomposed printf argument list. - Copyright (C) 1999, 2002-2003, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002-2003, 2005-2007, 2009-2010 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -42,146 +43,146 @@ PRINTF_FETCHARGS (va_list args, arguments *a) switch (ap->type) { case TYPE_SCHAR: - ap->a.a_schar = va_arg (args, /*signed char*/ int); - break; + ap->a.a_schar = va_arg (args, /*signed char*/ int); + break; case TYPE_UCHAR: - ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); - break; + ap->a.a_uchar = va_arg (args, /*unsigned char*/ int); + break; case TYPE_SHORT: - ap->a.a_short = va_arg (args, /*short*/ int); - break; + ap->a.a_short = va_arg (args, /*short*/ int); + break; case TYPE_USHORT: - ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); - break; + ap->a.a_ushort = va_arg (args, /*unsigned short*/ int); + break; case TYPE_INT: - ap->a.a_int = va_arg (args, int); - break; + ap->a.a_int = va_arg (args, int); + break; case TYPE_UINT: - ap->a.a_uint = va_arg (args, unsigned int); - break; + ap->a.a_uint = va_arg (args, unsigned int); + break; case TYPE_LONGINT: - ap->a.a_longint = va_arg (args, long int); - break; + ap->a.a_longint = va_arg (args, long int); + break; case TYPE_ULONGINT: - ap->a.a_ulongint = va_arg (args, unsigned long int); - break; + ap->a.a_ulongint = va_arg (args, unsigned long int); + break; #if HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: - ap->a.a_longlongint = va_arg (args, long long int); - break; + ap->a.a_longlongint = va_arg (args, long long int); + break; case TYPE_ULONGLONGINT: - ap->a.a_ulonglongint = va_arg (args, unsigned long long int); - break; + ap->a.a_ulonglongint = va_arg (args, unsigned long long int); + break; #endif case TYPE_DOUBLE: - ap->a.a_double = va_arg (args, double); - break; + ap->a.a_double = va_arg (args, double); + break; case TYPE_LONGDOUBLE: - ap->a.a_longdouble = va_arg (args, long double); - break; + ap->a.a_longdouble = va_arg (args, long double); + break; case TYPE_CHAR: - ap->a.a_char = va_arg (args, int); - break; + ap->a.a_char = va_arg (args, int); + break; #if HAVE_WINT_T case TYPE_WIDE_CHAR: - /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by - default argument promotions", this is not the case in mingw32, - where wint_t is 'unsigned short'. */ - ap->a.a_wide_char = - (sizeof (wint_t) < sizeof (int) - ? va_arg (args, int) - : va_arg (args, wint_t)); - break; + /* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by + default argument promotions", this is not the case in mingw32, + where wint_t is 'unsigned short'. */ + ap->a.a_wide_char = + (sizeof (wint_t) < sizeof (int) + ? (wint_t) va_arg (args, int) + : va_arg (args, wint_t)); + break; #endif case TYPE_STRING: - ap->a.a_string = va_arg (args, const char *); - /* A null pointer is an invalid argument for "%s", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_string == NULL) - ap->a.a_string = "(NULL)"; - break; + ap->a.a_string = va_arg (args, const char *); + /* A null pointer is an invalid argument for "%s", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_string == NULL) + ap->a.a_string = "(NULL)"; + break; #if HAVE_WCHAR_T case TYPE_WIDE_STRING: - ap->a.a_wide_string = va_arg (args, const wchar_t *); - /* A null pointer is an invalid argument for "%ls", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_wide_string == NULL) - { - static const wchar_t wide_null_string[] = - { - (wchar_t)'(', - (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L', - (wchar_t)')', - (wchar_t)0 - }; - ap->a.a_wide_string = wide_null_string; - } - break; + ap->a.a_wide_string = va_arg (args, const wchar_t *); + /* A null pointer is an invalid argument for "%ls", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_wide_string == NULL) + { + static const wchar_t wide_null_string[] = + { + (wchar_t)'(', + (wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L', + (wchar_t)')', + (wchar_t)0 + }; + ap->a.a_wide_string = wide_null_string; + } + break; #endif case TYPE_POINTER: - ap->a.a_pointer = va_arg (args, void *); - break; + ap->a.a_pointer = va_arg (args, void *); + break; case TYPE_COUNT_SCHAR_POINTER: - ap->a.a_count_schar_pointer = va_arg (args, signed char *); - break; + ap->a.a_count_schar_pointer = va_arg (args, signed char *); + break; case TYPE_COUNT_SHORT_POINTER: - ap->a.a_count_short_pointer = va_arg (args, short *); - break; + ap->a.a_count_short_pointer = va_arg (args, short *); + break; case TYPE_COUNT_INT_POINTER: - ap->a.a_count_int_pointer = va_arg (args, int *); - break; + ap->a.a_count_int_pointer = va_arg (args, int *); + break; case TYPE_COUNT_LONGINT_POINTER: - ap->a.a_count_longint_pointer = va_arg (args, long int *); - break; + ap->a.a_count_longint_pointer = va_arg (args, long int *); + break; #if HAVE_LONG_LONG_INT case TYPE_COUNT_LONGLONGINT_POINTER: - ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); - break; + ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); + break; #endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ case TYPE_U8_STRING: - ap->a.a_u8_string = va_arg (args, const uint8_t *); - /* A null pointer is an invalid argument for "%U", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_u8_string == NULL) - { - static const uint8_t u8_null_string[] = - { '(', 'N', 'U', 'L', 'L', ')', 0 }; - ap->a.a_u8_string = u8_null_string; - } - break; + ap->a.a_u8_string = va_arg (args, const uint8_t *); + /* A null pointer is an invalid argument for "%U", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_u8_string == NULL) + { + static const uint8_t u8_null_string[] = + { '(', 'N', 'U', 'L', 'L', ')', 0 }; + ap->a.a_u8_string = u8_null_string; + } + break; case TYPE_U16_STRING: - ap->a.a_u16_string = va_arg (args, const uint16_t *); - /* A null pointer is an invalid argument for "%lU", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_u16_string == NULL) - { - static const uint16_t u16_null_string[] = - { '(', 'N', 'U', 'L', 'L', ')', 0 }; - ap->a.a_u16_string = u16_null_string; - } - break; + ap->a.a_u16_string = va_arg (args, const uint16_t *); + /* A null pointer is an invalid argument for "%lU", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_u16_string == NULL) + { + static const uint16_t u16_null_string[] = + { '(', 'N', 'U', 'L', 'L', ')', 0 }; + ap->a.a_u16_string = u16_null_string; + } + break; case TYPE_U32_STRING: - ap->a.a_u32_string = va_arg (args, const uint32_t *); - /* A null pointer is an invalid argument for "%llU", but in practice - it occurs quite frequently in printf statements that produce - debug output. Use a fallback in this case. */ - if (ap->a.a_u32_string == NULL) - { - static const uint32_t u32_null_string[] = - { '(', 'N', 'U', 'L', 'L', ')', 0 }; - ap->a.a_u32_string = u32_null_string; - } - break; + ap->a.a_u32_string = va_arg (args, const uint32_t *); + /* A null pointer is an invalid argument for "%llU", but in practice + it occurs quite frequently in printf statements that produce + debug output. Use a fallback in this case. */ + if (ap->a.a_u32_string == NULL) + { + static const uint32_t u32_null_string[] = + { '(', 'N', 'U', 'L', 'L', ')', 0 }; + ap->a.a_u32_string = u32_null_string; + } + break; #endif default: - /* Unknown type. */ - return -1; + /* Unknown type. */ + return -1; } return 0; } diff --git a/lib/printf-args.h b/lib/printf-args.h index 4c68f115..d76352d9 100644 --- a/lib/printf-args.h +++ b/lib/printf-args.h @@ -1,5 +1,6 @@ /* Decomposed printf argument list. - Copyright (C) 1999, 2002-2003, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002-2003, 2006-2007, 2009-2010 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -93,42 +94,42 @@ typedef struct arg_type type; union { - signed char a_schar; - unsigned char a_uchar; - short a_short; - unsigned short a_ushort; - int a_int; - unsigned int a_uint; - long int a_longint; - unsigned long int a_ulongint; + signed char a_schar; + unsigned char a_uchar; + short a_short; + unsigned short a_ushort; + int a_int; + unsigned int a_uint; + long int a_longint; + unsigned long int a_ulongint; #if HAVE_LONG_LONG_INT - long long int a_longlongint; - unsigned long long int a_ulonglongint; + long long int a_longlongint; + unsigned long long int a_ulonglongint; #endif - float a_float; - double a_double; - long double a_longdouble; - int a_char; + float a_float; + double a_double; + long double a_longdouble; + int a_char; #if HAVE_WINT_T - wint_t a_wide_char; + wint_t a_wide_char; #endif - const char* a_string; + const char* a_string; #if HAVE_WCHAR_T - const wchar_t* a_wide_string; + const wchar_t* a_wide_string; #endif - void* a_pointer; - signed char * a_count_schar_pointer; - short * a_count_short_pointer; - int * a_count_int_pointer; - long int * a_count_longint_pointer; + void* a_pointer; + signed char * a_count_schar_pointer; + short * a_count_short_pointer; + int * a_count_int_pointer; + long int * a_count_longint_pointer; #if HAVE_LONG_LONG_INT - long long int * a_count_longlongint_pointer; + long long int * a_count_longlongint_pointer; #endif #if ENABLE_UNISTDIO /* The unistdio extensions. */ - const uint8_t * a_u8_string; - const uint16_t * a_u16_string; - const uint32_t * a_u32_string; + const uint8_t * a_u8_string; + const uint16_t * a_u16_string; + const uint32_t * a_u32_string; #endif } a; diff --git a/lib/printf-frexp.c b/lib/printf-frexp.c index 014c8539..cf6efdbc 100644 --- a/lib/printf-frexp.c +++ b/lib/printf-frexp.c @@ -1,5 +1,5 @@ /* Split a double into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -92,76 +92,76 @@ FUNC (DOUBLE x, int *expptr) exponent = 0; if (x >= L_(1.0)) { - /* A nonnegative exponent. */ - { - DOUBLE pow2_i; /* = pow2[i] */ - DOUBLE powh_i; /* = powh[i] */ - - /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, - x * 2^exponent = argument, x >= 1.0. */ - for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); - ; - i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) - { - if (x >= pow2_i) - { - exponent += (1 << i); - x *= powh_i; - } - else - break; - - pow2[i] = pow2_i; - powh[i] = powh_i; - } - } - /* Here 1.0 <= x < 2^2^i. */ + /* A nonnegative exponent. */ + { + DOUBLE pow2_i; /* = pow2[i] */ + DOUBLE powh_i; /* = powh[i] */ + + /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, + x * 2^exponent = argument, x >= 1.0. */ + for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); + ; + i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) + { + if (x >= pow2_i) + { + exponent += (1 << i); + x *= powh_i; + } + else + break; + + pow2[i] = pow2_i; + powh[i] = powh_i; + } + } + /* Here 1.0 <= x < 2^2^i. */ } else { - /* A negative exponent. */ - { - DOUBLE pow2_i; /* = pow2[i] */ - DOUBLE powh_i; /* = powh[i] */ - - /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, - x * 2^exponent = argument, x < 1.0, exponent >= MIN_EXP - 1. */ - for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); - ; - i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) - { - if (exponent - (1 << i) < MIN_EXP - 1) - break; - - exponent -= (1 << i); - x *= pow2_i; - if (x >= L_(1.0)) - break; - - pow2[i] = pow2_i; - powh[i] = powh_i; - } - } - /* Here either x < 1.0 and exponent - 2^i < MIN_EXP - 1 <= exponent, - or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */ - - if (x < L_(1.0)) - /* Invariants: x * 2^exponent = argument, x < 1.0 and - exponent - 2^i < MIN_EXP - 1 <= exponent. */ - while (i > 0) - { - i--; - if (exponent - (1 << i) >= MIN_EXP - 1) - { - exponent -= (1 << i); - x *= pow2[i]; - if (x >= L_(1.0)) - break; - } - } - - /* Here either x < 1.0 and exponent = MIN_EXP - 1, - or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */ + /* A negative exponent. */ + { + DOUBLE pow2_i; /* = pow2[i] */ + DOUBLE powh_i; /* = powh[i] */ + + /* Invariants: pow2_i = 2^2^i, powh_i = 2^-2^i, + x * 2^exponent = argument, x < 1.0, exponent >= MIN_EXP - 1. */ + for (i = 0, pow2_i = L_(2.0), powh_i = L_(0.5); + ; + i++, pow2_i = pow2_i * pow2_i, powh_i = powh_i * powh_i) + { + if (exponent - (1 << i) < MIN_EXP - 1) + break; + + exponent -= (1 << i); + x *= pow2_i; + if (x >= L_(1.0)) + break; + + pow2[i] = pow2_i; + powh[i] = powh_i; + } + } + /* Here either x < 1.0 and exponent - 2^i < MIN_EXP - 1 <= exponent, + or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */ + + if (x < L_(1.0)) + /* Invariants: x * 2^exponent = argument, x < 1.0 and + exponent - 2^i < MIN_EXP - 1 <= exponent. */ + while (i > 0) + { + i--; + if (exponent - (1 << i) >= MIN_EXP - 1) + { + exponent -= (1 << i); + x *= pow2[i]; + if (x >= L_(1.0)) + break; + } + } + + /* Here either x < 1.0 and exponent = MIN_EXP - 1, + or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */ } /* Invariants: x * 2^exponent = argument, and @@ -169,12 +169,12 @@ FUNC (DOUBLE x, int *expptr) or 1.0 <= x < 2^2^i and exponent >= MIN_EXP - 1. */ while (i > 0) { - i--; - if (x >= pow2[i]) - { - exponent += (1 << i); - x *= powh[i]; - } + i--; + if (x >= pow2[i]) + { + exponent += (1 << i); + x *= powh[i]; + } } /* Here either x < 1.0 and exponent = MIN_EXP - 1, or 1.0 <= x < 2.0 and exponent >= MIN_EXP - 1. */ diff --git a/lib/printf-frexp.h b/lib/printf-frexp.h index 197898d7..1cbb0960 100644 --- a/lib/printf-frexp.h +++ b/lib/printf-frexp.h @@ -1,5 +1,5 @@ /* Split a double into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/printf-frexpl.c b/lib/printf-frexpl.c index 864b2152..6ee1e9bf 100644 --- a/lib/printf-frexpl.c +++ b/lib/printf-frexpl.c @@ -1,5 +1,5 @@ /* Split a 'long double' into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/printf-frexpl.h b/lib/printf-frexpl.h index 718093d3..4783bbb4 100644 --- a/lib/printf-frexpl.h +++ b/lib/printf-frexpl.h @@ -1,5 +1,5 @@ /* Split a 'long double' into fraction and mantissa, for hexadecimal printf. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/printf-parse.c b/lib/printf-parse.c index 85c454b2..d88ddf30 100644 --- a/lib/printf-parse.c +++ b/lib/printf-parse.c @@ -1,5 +1,5 @@ /* Formatted output to strings. - Copyright (C) 1999-2000, 2002-2003, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002-2003, 2006-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -80,10 +80,10 @@ STATIC int PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) { - const CHAR_T *cp = format; /* pointer into format */ - size_t arg_posn = 0; /* number of regular arguments consumed */ - size_t d_allocated; /* allocated elements of d->dir */ - size_t a_allocated; /* allocated elements of a->arg */ + const CHAR_T *cp = format; /* pointer into format */ + size_t arg_posn = 0; /* number of regular arguments consumed */ + size_t d_allocated; /* allocated elements of d->dir */ + size_t a_allocated; /* allocated elements of a->arg */ size_t max_width_length = 0; size_t max_precision_length = 0; @@ -99,501 +99,501 @@ PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a) a->arg = NULL; #define REGISTER_ARG(_index_,_type_) \ - { \ - size_t n = (_index_); \ - if (n >= a_allocated) \ - { \ - size_t memory_size; \ - argument *memory; \ - \ - a_allocated = xtimes (a_allocated, 2); \ - if (a_allocated <= n) \ - a_allocated = xsum (n, 1); \ - memory_size = xtimes (a_allocated, sizeof (argument)); \ - if (size_overflow_p (memory_size)) \ - /* Overflow, would lead to out of memory. */ \ - goto out_of_memory; \ - memory = (argument *) (a->arg \ - ? realloc (a->arg, memory_size) \ - : malloc (memory_size)); \ - if (memory == NULL) \ - /* Out of memory. */ \ - goto out_of_memory; \ - a->arg = memory; \ - } \ - while (a->count <= n) \ - a->arg[a->count++].type = TYPE_NONE; \ - if (a->arg[n].type == TYPE_NONE) \ - a->arg[n].type = (_type_); \ - else if (a->arg[n].type != (_type_)) \ - /* Ambiguous type for positional argument. */ \ - goto error; \ + { \ + size_t n = (_index_); \ + if (n >= a_allocated) \ + { \ + size_t memory_size; \ + argument *memory; \ + \ + a_allocated = xtimes (a_allocated, 2); \ + if (a_allocated <= n) \ + a_allocated = xsum (n, 1); \ + memory_size = xtimes (a_allocated, sizeof (argument)); \ + if (size_overflow_p (memory_size)) \ + /* Overflow, would lead to out of memory. */ \ + goto out_of_memory; \ + memory = (argument *) (a->arg \ + ? realloc (a->arg, memory_size) \ + : malloc (memory_size)); \ + if (memory == NULL) \ + /* Out of memory. */ \ + goto out_of_memory; \ + a->arg = memory; \ + } \ + while (a->count <= n) \ + a->arg[a->count++].type = TYPE_NONE; \ + if (a->arg[n].type == TYPE_NONE) \ + a->arg[n].type = (_type_); \ + else if (a->arg[n].type != (_type_)) \ + /* Ambiguous type for positional argument. */ \ + goto error; \ } while (*cp != '\0') { CHAR_T c = *cp++; if (c == '%') - { - size_t arg_index = ARG_NONE; - DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */ - - /* Initialize the next directive. */ - dp->dir_start = cp - 1; - dp->flags = 0; - dp->width_start = NULL; - dp->width_end = NULL; - dp->width_arg_index = ARG_NONE; - dp->precision_start = NULL; - dp->precision_end = NULL; - dp->precision_arg_index = ARG_NONE; - dp->arg_index = ARG_NONE; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory later. */ - goto error; - arg_index = n - 1; - cp = np + 1; - } - } - - /* Read the flags. */ - for (;;) - { - if (*cp == '\'') - { - dp->flags |= FLAG_GROUP; - cp++; - } - else if (*cp == '-') - { - dp->flags |= FLAG_LEFT; - cp++; - } - else if (*cp == '+') - { - dp->flags |= FLAG_SHOWSIGN; - cp++; - } - else if (*cp == ' ') - { - dp->flags |= FLAG_SPACE; - cp++; - } - else if (*cp == '#') - { - dp->flags |= FLAG_ALT; - cp++; - } - else if (*cp == '0') - { - dp->flags |= FLAG_ZERO; - cp++; - } - else - break; - } - - /* Parse the field width. */ - if (*cp == '*') - { - dp->width_start = cp; - cp++; - dp->width_end = cp; - if (max_width_length < 1) - max_width_length = 1; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory later. */ - goto error; - dp->width_arg_index = n - 1; - cp = np + 1; - } - } - if (dp->width_arg_index == ARG_NONE) - { - dp->width_arg_index = arg_posn++; - if (dp->width_arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->width_arg_index, TYPE_INT); - } - else if (*cp >= '0' && *cp <= '9') - { - size_t width_length; - - dp->width_start = cp; - for (; *cp >= '0' && *cp <= '9'; cp++) - ; - dp->width_end = cp; - width_length = dp->width_end - dp->width_start; - if (max_width_length < width_length) - max_width_length = width_length; - } - - /* Parse the precision. */ - if (*cp == '.') - { - cp++; - if (*cp == '*') - { - dp->precision_start = cp - 1; - cp++; - dp->precision_end = cp; - if (max_precision_length < 2) - max_precision_length = 2; - - /* Test for positional argument. */ - if (*cp >= '0' && *cp <= '9') - { - const CHAR_T *np; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - ; - if (*np == '$') - { - size_t n = 0; - - for (np = cp; *np >= '0' && *np <= '9'; np++) - n = xsum (xtimes (n, 10), *np - '0'); - if (n == 0) - /* Positional argument 0. */ - goto error; - if (size_overflow_p (n)) - /* n too large, would lead to out of memory - later. */ - goto error; - dp->precision_arg_index = n - 1; - cp = np + 1; - } - } - if (dp->precision_arg_index == ARG_NONE) - { - dp->precision_arg_index = arg_posn++; - if (dp->precision_arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->precision_arg_index, TYPE_INT); - } - else - { - size_t precision_length; - - dp->precision_start = cp - 1; - for (; *cp >= '0' && *cp <= '9'; cp++) - ; - dp->precision_end = cp; - precision_length = dp->precision_end - dp->precision_start; - if (max_precision_length < precision_length) - max_precision_length = precision_length; - } - } - - { - arg_type type; - - /* Parse argument type/size specifiers. */ - { - int flags = 0; - - for (;;) - { - if (*cp == 'h') - { - flags |= (1 << (flags & 1)); - cp++; - } - else if (*cp == 'L') - { - flags |= 4; - cp++; - } - else if (*cp == 'l') - { - flags += 8; - cp++; - } - else if (*cp == 'j') - { - if (sizeof (intmax_t) > sizeof (long)) - { - /* intmax_t = long long */ - flags += 16; - } - else if (sizeof (intmax_t) > sizeof (int)) - { - /* intmax_t = long */ - flags += 8; - } - cp++; - } - else if (*cp == 'z' || *cp == 'Z') - { - /* 'z' is standardized in ISO C 99, but glibc uses 'Z' - because the warning facility in gcc-2.95.2 understands - only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ - if (sizeof (size_t) > sizeof (long)) - { - /* size_t = long long */ - flags += 16; - } - else if (sizeof (size_t) > sizeof (int)) - { - /* size_t = long */ - flags += 8; - } - cp++; - } - else if (*cp == 't') - { - if (sizeof (ptrdiff_t) > sizeof (long)) - { - /* ptrdiff_t = long long */ - flags += 16; - } - else if (sizeof (ptrdiff_t) > sizeof (int)) - { - /* ptrdiff_t = long */ - flags += 8; - } - cp++; - } + { + size_t arg_index = ARG_NONE; + DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */ + + /* Initialize the next directive. */ + dp->dir_start = cp - 1; + dp->flags = 0; + dp->width_start = NULL; + dp->width_end = NULL; + dp->width_arg_index = ARG_NONE; + dp->precision_start = NULL; + dp->precision_end = NULL; + dp->precision_arg_index = ARG_NONE; + dp->arg_index = ARG_NONE; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory later. */ + goto error; + arg_index = n - 1; + cp = np + 1; + } + } + + /* Read the flags. */ + for (;;) + { + if (*cp == '\'') + { + dp->flags |= FLAG_GROUP; + cp++; + } + else if (*cp == '-') + { + dp->flags |= FLAG_LEFT; + cp++; + } + else if (*cp == '+') + { + dp->flags |= FLAG_SHOWSIGN; + cp++; + } + else if (*cp == ' ') + { + dp->flags |= FLAG_SPACE; + cp++; + } + else if (*cp == '#') + { + dp->flags |= FLAG_ALT; + cp++; + } + else if (*cp == '0') + { + dp->flags |= FLAG_ZERO; + cp++; + } + else + break; + } + + /* Parse the field width. */ + if (*cp == '*') + { + dp->width_start = cp; + cp++; + dp->width_end = cp; + if (max_width_length < 1) + max_width_length = 1; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory later. */ + goto error; + dp->width_arg_index = n - 1; + cp = np + 1; + } + } + if (dp->width_arg_index == ARG_NONE) + { + dp->width_arg_index = arg_posn++; + if (dp->width_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->width_arg_index, TYPE_INT); + } + else if (*cp >= '0' && *cp <= '9') + { + size_t width_length; + + dp->width_start = cp; + for (; *cp >= '0' && *cp <= '9'; cp++) + ; + dp->width_end = cp; + width_length = dp->width_end - dp->width_start; + if (max_width_length < width_length) + max_width_length = width_length; + } + + /* Parse the precision. */ + if (*cp == '.') + { + cp++; + if (*cp == '*') + { + dp->precision_start = cp - 1; + cp++; + dp->precision_end = cp; + if (max_precision_length < 2) + max_precision_length = 2; + + /* Test for positional argument. */ + if (*cp >= '0' && *cp <= '9') + { + const CHAR_T *np; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + ; + if (*np == '$') + { + size_t n = 0; + + for (np = cp; *np >= '0' && *np <= '9'; np++) + n = xsum (xtimes (n, 10), *np - '0'); + if (n == 0) + /* Positional argument 0. */ + goto error; + if (size_overflow_p (n)) + /* n too large, would lead to out of memory + later. */ + goto error; + dp->precision_arg_index = n - 1; + cp = np + 1; + } + } + if (dp->precision_arg_index == ARG_NONE) + { + dp->precision_arg_index = arg_posn++; + if (dp->precision_arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->precision_arg_index, TYPE_INT); + } + else + { + size_t precision_length; + + dp->precision_start = cp - 1; + for (; *cp >= '0' && *cp <= '9'; cp++) + ; + dp->precision_end = cp; + precision_length = dp->precision_end - dp->precision_start; + if (max_precision_length < precision_length) + max_precision_length = precision_length; + } + } + + { + arg_type type; + + /* Parse argument type/size specifiers. */ + { + int flags = 0; + + for (;;) + { + if (*cp == 'h') + { + flags |= (1 << (flags & 1)); + cp++; + } + else if (*cp == 'L') + { + flags |= 4; + cp++; + } + else if (*cp == 'l') + { + flags += 8; + cp++; + } + else if (*cp == 'j') + { + if (sizeof (intmax_t) > sizeof (long)) + { + /* intmax_t = long long */ + flags += 16; + } + else if (sizeof (intmax_t) > sizeof (int)) + { + /* intmax_t = long */ + flags += 8; + } + cp++; + } + else if (*cp == 'z' || *cp == 'Z') + { + /* 'z' is standardized in ISO C 99, but glibc uses 'Z' + because the warning facility in gcc-2.95.2 understands + only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */ + if (sizeof (size_t) > sizeof (long)) + { + /* size_t = long long */ + flags += 16; + } + else if (sizeof (size_t) > sizeof (int)) + { + /* size_t = long */ + flags += 8; + } + cp++; + } + else if (*cp == 't') + { + if (sizeof (ptrdiff_t) > sizeof (long)) + { + /* ptrdiff_t = long long */ + flags += 16; + } + else if (sizeof (ptrdiff_t) > sizeof (int)) + { + /* ptrdiff_t = long */ + flags += 8; + } + cp++; + } #if defined __APPLE__ && defined __MACH__ - /* On MacOS X 10.3, PRIdMAX is defined as "qd". - We cannot change it to "lld" because PRIdMAX must also - be understood by the system's printf routines. */ - else if (*cp == 'q') - { - if (64 / 8 > sizeof (long)) - { - /* int64_t = long long */ - flags += 16; - } - else - { - /* int64_t = long */ - flags += 8; - } - cp++; - } + /* On MacOS X 10.3, PRIdMAX is defined as "qd". + We cannot change it to "lld" because PRIdMAX must also + be understood by the system's printf routines. */ + else if (*cp == 'q') + { + if (64 / 8 > sizeof (long)) + { + /* int64_t = long long */ + flags += 16; + } + else + { + /* int64_t = long */ + flags += 8; + } + cp++; + } #endif #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - /* On native Win32, PRIdMAX is defined as "I64d". - We cannot change it to "lld" because PRIdMAX must also - be understood by the system's printf routines. */ - else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4') - { - if (64 / 8 > sizeof (long)) - { - /* __int64 = long long */ - flags += 16; - } - else - { - /* __int64 = long */ - flags += 8; - } - cp += 3; - } + /* On native Win32, PRIdMAX is defined as "I64d". + We cannot change it to "lld" because PRIdMAX must also + be understood by the system's printf routines. */ + else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4') + { + if (64 / 8 > sizeof (long)) + { + /* __int64 = long long */ + flags += 16; + } + else + { + /* __int64 = long */ + flags += 8; + } + cp += 3; + } #endif - else - break; - } - - /* Read the conversion character. */ - c = *cp++; - switch (c) - { - case 'd': case 'i': + else + break; + } + + /* Read the conversion character. */ + c = *cp++; + switch (c) + { + case 'd': case 'i': #if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ - if (flags >= 16 || (flags & 4)) - type = TYPE_LONGLONGINT; - else + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_LONGLONGINT; + else #endif - /* If 'long long' exists and is the same as 'long', we parse - "lld" into TYPE_LONGINT. */ - if (flags >= 8) - type = TYPE_LONGINT; - else if (flags & 2) - type = TYPE_SCHAR; - else if (flags & 1) - type = TYPE_SHORT; - else - type = TYPE_INT; - break; - case 'o': case 'u': case 'x': case 'X': + /* If 'long long' exists and is the same as 'long', we parse + "lld" into TYPE_LONGINT. */ + if (flags >= 8) + type = TYPE_LONGINT; + else if (flags & 2) + type = TYPE_SCHAR; + else if (flags & 1) + type = TYPE_SHORT; + else + type = TYPE_INT; + break; + case 'o': case 'u': case 'x': case 'X': #if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ - if (flags >= 16 || (flags & 4)) - type = TYPE_ULONGLONGINT; - else + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_ULONGLONGINT; + else #endif - /* If 'unsigned long long' exists and is the same as - 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ - if (flags >= 8) - type = TYPE_ULONGINT; - else if (flags & 2) - type = TYPE_UCHAR; - else if (flags & 1) - type = TYPE_USHORT; - else - type = TYPE_UINT; - break; - case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': - case 'a': case 'A': - if (flags >= 16 || (flags & 4)) - type = TYPE_LONGDOUBLE; - else - type = TYPE_DOUBLE; - break; - case 'c': - if (flags >= 8) + /* If 'unsigned long long' exists and is the same as + 'unsigned long', we parse "llu" into TYPE_ULONGINT. */ + if (flags >= 8) + type = TYPE_ULONGINT; + else if (flags & 2) + type = TYPE_UCHAR; + else if (flags & 1) + type = TYPE_USHORT; + else + type = TYPE_UINT; + break; + case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': + case 'a': case 'A': + if (flags >= 16 || (flags & 4)) + type = TYPE_LONGDOUBLE; + else + type = TYPE_DOUBLE; + break; + case 'c': + if (flags >= 8) #if HAVE_WINT_T - type = TYPE_WIDE_CHAR; + type = TYPE_WIDE_CHAR; #else - goto error; + goto error; #endif - else - type = TYPE_CHAR; - break; + else + type = TYPE_CHAR; + break; #if HAVE_WINT_T - case 'C': - type = TYPE_WIDE_CHAR; - c = 'c'; - break; + case 'C': + type = TYPE_WIDE_CHAR; + c = 'c'; + break; #endif - case 's': - if (flags >= 8) + case 's': + if (flags >= 8) #if HAVE_WCHAR_T - type = TYPE_WIDE_STRING; + type = TYPE_WIDE_STRING; #else - goto error; + goto error; #endif - else - type = TYPE_STRING; - break; + else + type = TYPE_STRING; + break; #if HAVE_WCHAR_T - case 'S': - type = TYPE_WIDE_STRING; - c = 's'; - break; + case 'S': + type = TYPE_WIDE_STRING; + c = 's'; + break; #endif - case 'p': - type = TYPE_POINTER; - break; - case 'n': + case 'p': + type = TYPE_POINTER; + break; + case 'n': #if HAVE_LONG_LONG_INT - /* If 'long long' exists and is larger than 'long': */ - if (flags >= 16 || (flags & 4)) - type = TYPE_COUNT_LONGLONGINT_POINTER; - else + /* If 'long long' exists and is larger than 'long': */ + if (flags >= 16 || (flags & 4)) + type = TYPE_COUNT_LONGLONGINT_POINTER; + else #endif - /* If 'long long' exists and is the same as 'long', we parse - "lln" into TYPE_COUNT_LONGINT_POINTER. */ - if (flags >= 8) - type = TYPE_COUNT_LONGINT_POINTER; - else if (flags & 2) - type = TYPE_COUNT_SCHAR_POINTER; - else if (flags & 1) - type = TYPE_COUNT_SHORT_POINTER; - else - type = TYPE_COUNT_INT_POINTER; - break; + /* If 'long long' exists and is the same as 'long', we parse + "lln" into TYPE_COUNT_LONGINT_POINTER. */ + if (flags >= 8) + type = TYPE_COUNT_LONGINT_POINTER; + else if (flags & 2) + type = TYPE_COUNT_SCHAR_POINTER; + else if (flags & 1) + type = TYPE_COUNT_SHORT_POINTER; + else + type = TYPE_COUNT_INT_POINTER; + break; #if ENABLE_UNISTDIO - /* The unistdio extensions. */ - case 'U': - if (flags >= 16) - type = TYPE_U32_STRING; - else if (flags >= 8) - type = TYPE_U16_STRING; - else - type = TYPE_U8_STRING; - break; + /* The unistdio extensions. */ + case 'U': + if (flags >= 16) + type = TYPE_U32_STRING; + else if (flags >= 8) + type = TYPE_U16_STRING; + else + type = TYPE_U8_STRING; + break; #endif - case '%': - type = TYPE_NONE; - break; - default: - /* Unknown conversion character. */ - goto error; - } - } - - if (type != TYPE_NONE) - { - dp->arg_index = arg_index; - if (dp->arg_index == ARG_NONE) - { - dp->arg_index = arg_posn++; - if (dp->arg_index == ARG_NONE) - /* arg_posn wrapped around. */ - goto error; - } - REGISTER_ARG (dp->arg_index, type); - } - dp->conversion = c; - dp->dir_end = cp; - } - - d->count++; - if (d->count >= d_allocated) - { - size_t memory_size; - DIRECTIVE *memory; - - d_allocated = xtimes (d_allocated, 2); - memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); - if (size_overflow_p (memory_size)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - memory = (DIRECTIVE *) realloc (d->dir, memory_size); - if (memory == NULL) - /* Out of memory. */ - goto out_of_memory; - d->dir = memory; - } - } + case '%': + type = TYPE_NONE; + break; + default: + /* Unknown conversion character. */ + goto error; + } + } + + if (type != TYPE_NONE) + { + dp->arg_index = arg_index; + if (dp->arg_index == ARG_NONE) + { + dp->arg_index = arg_posn++; + if (dp->arg_index == ARG_NONE) + /* arg_posn wrapped around. */ + goto error; + } + REGISTER_ARG (dp->arg_index, type); + } + dp->conversion = c; + dp->dir_end = cp; + } + + d->count++; + if (d->count >= d_allocated) + { + size_t memory_size; + DIRECTIVE *memory; + + d_allocated = xtimes (d_allocated, 2); + memory_size = xtimes (d_allocated, sizeof (DIRECTIVE)); + if (size_overflow_p (memory_size)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + memory = (DIRECTIVE *) realloc (d->dir, memory_size); + if (memory == NULL) + /* Out of memory. */ + goto out_of_memory; + d->dir = memory; + } + } #if CHAR_T_ONLY_ASCII else if (!c_isascii (c)) - { - /* Non-ASCII character. Not supported. */ - goto error; - } + { + /* Non-ASCII character. Not supported. */ + goto error; + } #endif } d->dir[d->count].dir_start = cp; diff --git a/lib/printf-parse.h b/lib/printf-parse.h index 0a496cbd..2cf965bb 100644 --- a/lib/printf-parse.h +++ b/lib/printf-parse.h @@ -1,5 +1,6 @@ /* Parse printf format string. - Copyright (C) 1999, 2002-2003, 2005, 2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002-2003, 2005, 2007, 2009-2010 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -26,15 +27,15 @@ /* Flags */ -#define FLAG_GROUP 1 /* ' flag */ -#define FLAG_LEFT 2 /* - flag */ -#define FLAG_SHOWSIGN 4 /* + flag */ -#define FLAG_SPACE 8 /* space flag */ -#define FLAG_ALT 16 /* # flag */ -#define FLAG_ZERO 32 +#define FLAG_GROUP 1 /* ' flag */ +#define FLAG_LEFT 2 /* - flag */ +#define FLAG_SHOWSIGN 4 /* + flag */ +#define FLAG_SPACE 8 /* space flag */ +#define FLAG_ALT 16 /* # flag */ +#define FLAG_ZERO 32 /* arg_index value indicating that no argument is consumed. */ -#define ARG_NONE (~(size_t)0) +#define ARG_NONE (~(size_t)0) /* xxx_directive: A parsed directive. xxx_directives: A parsed format string. */ @@ -163,10 +164,10 @@ extern int u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a); extern int u16_printf_parse (const uint16_t *format, u16_directives *d, - arguments *a); + arguments *a); extern int u32_printf_parse (const uint32_t *format, u32_directives *d, - arguments *a); + arguments *a); #else # ifdef STATIC STATIC diff --git a/lib/ref-add.sin b/lib/ref-add.sin index 3acdcc84..cb482d76 100644 --- a/lib/ref-add.sin +++ b/lib/ref-add.sin @@ -1,6 +1,6 @@ # Add this package to a list of references stored in a text file. # -# Copyright (C) 2000 Free Software Foundation, Inc. +# Copyright (C) 2000, 2009, 2010 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/ref-del.sin b/lib/ref-del.sin index 7923d062..74f8e1cd 100644 --- a/lib/ref-del.sin +++ b/lib/ref-del.sin @@ -1,6 +1,6 @@ # Remove this package from a list of references stored in a text file. # -# Copyright (C) 2000 Free Software Foundation, Inc. +# Copyright (C) 2000, 2009, 2010 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/relocatable.c b/lib/relocatable.c index 09ff8c9e..172e91c9 100644 --- a/lib/relocatable.c +++ b/lib/relocatable.c @@ -1,5 +1,5 @@ /* Provide relocatable packages. - Copyright (C) 2003-2006, 2008 Free Software Foundation, Inc. + Copyright (C) 2003-2006, 2008-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify it @@ -22,7 +22,7 @@ This must come before because may include , and once has been included, it's too late. */ #ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 +# define _GNU_SOURCE 1 #endif #include @@ -102,11 +102,11 @@ static size_t curr_prefix_len; instead of "/"). */ static void set_this_relocation_prefix (const char *orig_prefix_arg, - const char *curr_prefix_arg) + const char *curr_prefix_arg) { if (orig_prefix_arg != NULL && curr_prefix_arg != NULL /* Optimization: if orig_prefix and curr_prefix are equal, the - relocation is a nop. */ + relocation is a nop. */ && strcmp (orig_prefix_arg, curr_prefix_arg) != 0) { /* Duplicate the argument strings. */ @@ -118,14 +118,14 @@ set_this_relocation_prefix (const char *orig_prefix_arg, #ifdef NO_XMALLOC if (memory != NULL) #endif - { - memcpy (memory, orig_prefix_arg, orig_prefix_len + 1); - orig_prefix = memory; - memory += orig_prefix_len + 1; - memcpy (memory, curr_prefix_arg, curr_prefix_len + 1); - curr_prefix = memory; - return; - } + { + memcpy (memory, orig_prefix_arg, orig_prefix_len + 1); + orig_prefix = memory; + memory += orig_prefix_len + 1; + memcpy (memory, curr_prefix_arg, curr_prefix_len + 1); + curr_prefix = memory; + return; + } } orig_prefix = NULL; curr_prefix = NULL; @@ -168,8 +168,8 @@ static #endif char * compute_curr_prefix (const char *orig_installprefix, - const char *orig_installdir, - const char *curr_pathname) + const char *orig_installdir, + const char *curr_pathname) { char *curr_installdir; const char *rel_installdir; @@ -194,9 +194,9 @@ compute_curr_prefix (const char *orig_installprefix, while (p > p_base) { - p--; - if (ISSLASH (*p)) - break; + p--; + if (ISSLASH (*p)) + break; } q = (char *) xmalloc (p - curr_pathname + 1); @@ -219,46 +219,46 @@ compute_curr_prefix (const char *orig_installprefix, while (rp > rel_installdir && cp > cp_base) { - bool same = false; - const char *rpi = rp; - const char *cpi = cp; - - while (rpi > rel_installdir && cpi > cp_base) - { - rpi--; - cpi--; - if (ISSLASH (*rpi) || ISSLASH (*cpi)) - { - if (ISSLASH (*rpi) && ISSLASH (*cpi)) - same = true; - break; - } - /* Do case-insensitive comparison if the filesystem is always or - often case-insensitive. It's better to accept the comparison - if the difference is only in case, rather than to fail. */ + bool same = false; + const char *rpi = rp; + const char *cpi = cp; + + while (rpi > rel_installdir && cpi > cp_base) + { + rpi--; + cpi--; + if (ISSLASH (*rpi) || ISSLASH (*cpi)) + { + if (ISSLASH (*rpi) && ISSLASH (*cpi)) + same = true; + break; + } + /* Do case-insensitive comparison if the file system is always or + often case-insensitive. It's better to accept the comparison + if the difference is only in case, rather than to fail. */ #if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ - /* Win32, Cygwin, OS/2, DOS - case insignificant filesystem */ - if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi) - != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi)) - break; + /* Win32, Cygwin, OS/2, DOS - case insignificant file system */ + if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi) + != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi)) + break; #else - if (*rpi != *cpi) - break; + if (*rpi != *cpi) + break; #endif - } - if (!same) - break; - /* The last pathname component was the same. opi and cpi now point - to the slash before it. */ - rp = rpi; - cp = cpi; + } + if (!same) + break; + /* The last pathname component was the same. opi and cpi now point + to the slash before it. */ + rp = rpi; + cp = cpi; } if (rp > rel_installdir) { - /* Unexpected: The curr_installdir does not end with rel_installdir. */ - free (curr_installdir); - return NULL; + /* Unexpected: The curr_installdir does not end with rel_installdir. */ + free (curr_installdir); + return NULL; } { @@ -268,10 +268,10 @@ compute_curr_prefix (const char *orig_installprefix, curr_prefix = (char *) xmalloc (curr_prefix_len + 1); #ifdef NO_XMALLOC if (curr_prefix == NULL) - { - free (curr_installdir); - return NULL; - } + { + free (curr_installdir); + return NULL; + } #endif memcpy (curr_prefix, curr_installdir, curr_prefix_len); curr_prefix[curr_prefix_len] = '\0'; @@ -305,30 +305,30 @@ DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved) static char location[MAX_PATH]; if (!GetModuleFileName (module_handle, location, sizeof (location))) - /* Shouldn't happen. */ - return FALSE; + /* Shouldn't happen. */ + return FALSE; if (!IS_PATH_WITH_DIR (location)) - /* Shouldn't happen. */ - return FALSE; + /* Shouldn't happen. */ + return FALSE; { #if defined __CYGWIN__ - /* On Cygwin, we need to convert paths coming from Win32 system calls - to the Unix-like slashified notation. */ - static char location_as_posix_path[2 * MAX_PATH]; - /* There's no error return defined for cygwin_conv_to_posix_path. - See cygwin-api/func-cygwin-conv-to-posix-path.html. - Does it overflow the buffer of expected size MAX_PATH or does it - truncate the path? I don't know. Let's catch both. */ - cygwin_conv_to_posix_path (location, location_as_posix_path); - location_as_posix_path[MAX_PATH - 1] = '\0'; - if (strlen (location_as_posix_path) >= MAX_PATH - 1) - /* A sign of buffer overflow or path truncation. */ - return FALSE; - shared_library_fullname = strdup (location_as_posix_path); + /* On Cygwin, we need to convert paths coming from Win32 system calls + to the Unix-like slashified notation. */ + static char location_as_posix_path[2 * MAX_PATH]; + /* There's no error return defined for cygwin_conv_to_posix_path. + See cygwin-api/func-cygwin-conv-to-posix-path.html. + Does it overflow the buffer of expected size MAX_PATH or does it + truncate the path? I don't know. Let's catch both. */ + cygwin_conv_to_posix_path (location, location_as_posix_path); + location_as_posix_path[MAX_PATH - 1] = '\0'; + if (strlen (location_as_posix_path) >= MAX_PATH - 1) + /* A sign of buffer overflow or path truncation. */ + return FALSE; + shared_library_fullname = strdup (location_as_posix_path); #else - shared_library_fullname = strdup (location); + shared_library_fullname = strdup (location); #endif } } @@ -351,37 +351,37 @@ find_shared_library_fullname () { unsigned long address = (unsigned long) &find_shared_library_fullname; for (;;) - { - unsigned long start, end; - int c; - - if (fscanf (fp, "%lx-%lx", &start, &end) != 2) - break; - if (address >= start && address <= end - 1) - { - /* Found it. Now see if this line contains a filename. */ - while (c = getc (fp), c != EOF && c != '\n' && c != '/') - continue; - if (c == '/') - { - size_t size; - int len; - - ungetc (c, fp); - shared_library_fullname = NULL; size = 0; - len = getline (&shared_library_fullname, &size, fp); - if (len >= 0) - { - /* Success: filled shared_library_fullname. */ - if (len > 0 && shared_library_fullname[len - 1] == '\n') - shared_library_fullname[len - 1] = '\0'; - } - } - break; - } - while (c = getc (fp), c != EOF && c != '\n') - continue; - } + { + unsigned long start, end; + int c; + + if (fscanf (fp, "%lx-%lx", &start, &end) != 2) + break; + if (address >= start && address <= end - 1) + { + /* Found it. Now see if this line contains a filename. */ + while (c = getc (fp), c != EOF && c != '\n' && c != '/') + continue; + if (c == '/') + { + size_t size; + int len; + + ungetc (c, fp); + shared_library_fullname = NULL; size = 0; + len = getline (&shared_library_fullname, &size, fp); + if (len >= 0) + { + /* Success: filled shared_library_fullname. */ + if (len > 0 && shared_library_fullname[len - 1] == '\n') + shared_library_fullname[len - 1] = '\0'; + } + } + break; + } + while (c = getc (fp), c != EOF && c != '\n') + continue; + } fclose (fp); } #endif @@ -422,69 +422,69 @@ relocate (const char *pathname) if (!initialized) { /* At this point, orig_prefix and curr_prefix likely have already been - set through the main program's set_program_name_and_installdir - function. This is sufficient in the case that the library has - initially been installed in the same orig_prefix. But we can do - better, to also cover the cases that 1. it has been installed - in a different prefix before being moved to orig_prefix and (later) - to curr_prefix, 2. unlike the program, it has not moved away from - orig_prefix. */ + set through the main program's set_program_name_and_installdir + function. This is sufficient in the case that the library has + initially been installed in the same orig_prefix. But we can do + better, to also cover the cases that 1. it has been installed + in a different prefix before being moved to orig_prefix and (later) + to curr_prefix, 2. unlike the program, it has not moved away from + orig_prefix. */ const char *orig_installprefix = INSTALLPREFIX; const char *orig_installdir = INSTALLDIR; char *curr_prefix_better; curr_prefix_better = - compute_curr_prefix (orig_installprefix, orig_installdir, - get_shared_library_fullname ()); + compute_curr_prefix (orig_installprefix, orig_installdir, + get_shared_library_fullname ()); set_relocation_prefix (orig_installprefix, - curr_prefix_better != NULL - ? curr_prefix_better - : curr_prefix); + curr_prefix_better != NULL + ? curr_prefix_better + : curr_prefix); if (curr_prefix_better != NULL) - free (curr_prefix_better); + free (curr_prefix_better); initialized = 1; } #endif /* Note: It is not necessary to perform case insensitive comparison here, - even for DOS-like filesystems, because the pathname argument was + even for DOS-like file systems, because the pathname argument was typically created from the same Makefile variable as orig_prefix came from. */ if (orig_prefix != NULL && curr_prefix != NULL && strncmp (pathname, orig_prefix, orig_prefix_len) == 0) { if (pathname[orig_prefix_len] == '\0') - { - /* pathname equals orig_prefix. */ - char *result = (char *) xmalloc (strlen (curr_prefix) + 1); + { + /* pathname equals orig_prefix. */ + char *result = (char *) xmalloc (strlen (curr_prefix) + 1); #ifdef NO_XMALLOC - if (result != NULL) + if (result != NULL) #endif - { - strcpy (result, curr_prefix); - return result; - } - } + { + strcpy (result, curr_prefix); + return result; + } + } else if (ISSLASH (pathname[orig_prefix_len])) - { - /* pathname starts with orig_prefix. */ - const char *pathname_tail = &pathname[orig_prefix_len]; - char *result = - (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1); + { + /* pathname starts with orig_prefix. */ + const char *pathname_tail = &pathname[orig_prefix_len]; + char *result = + (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1); #ifdef NO_XMALLOC - if (result != NULL) + if (result != NULL) #endif - { - memcpy (result, curr_prefix, curr_prefix_len); - strcpy (result + curr_prefix_len, pathname_tail); - return result; - } - } + { + memcpy (result, curr_prefix, curr_prefix_len); + strcpy (result + curr_prefix_len, pathname_tail); + return result; + } + } } /* Nothing to relocate. */ return pathname; diff --git a/lib/relocatable.h b/lib/relocatable.h index 5dfd7108..6328fa83 100644 --- a/lib/relocatable.h +++ b/lib/relocatable.h @@ -1,5 +1,5 @@ /* Provide relocatable packages. - Copyright (C) 2003, 2005, 2008 Free Software Foundation, Inc. + Copyright (C) 2003, 2005, 2008, 2009, 2010 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software; you can redistribute it and/or modify it @@ -46,7 +46,7 @@ extern "C" { instead of "/"). */ extern RELOCATABLE_DLL_EXPORTED void set_relocation_prefix (const char *orig_prefix, - const char *curr_prefix); + const char *curr_prefix); /* Returns the pathname, relocated according to the current installation directory. @@ -65,8 +65,8 @@ extern const char * relocate (const char *pathname); file, and the current pathname of this file. Returns it, freshly allocated. Returns NULL upon failure. */ extern char * compute_curr_prefix (const char *orig_installprefix, - const char *orig_installdir, - const char *curr_pathname); + const char *orig_installdir, + const char *curr_pathname); #else diff --git a/lib/signbitd.c b/lib/signbitd.c index 8d082b6c..d0fb4a96 100644 --- a/lib/signbitd.c +++ b/lib/signbitd.c @@ -1,5 +1,5 @@ /* signbit() macro: Determine the sign bit of a floating-point number. - Copyright (C) 2007-2009 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/signbitf.c b/lib/signbitf.c index e75f38c7..f2ef1d9b 100644 --- a/lib/signbitf.c +++ b/lib/signbitf.c @@ -1,5 +1,5 @@ /* signbit() macro: Determine the sign bit of a floating-point number. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/signbitl.c b/lib/signbitl.c index 465937f9..adcb71eb 100644 --- a/lib/signbitl.c +++ b/lib/signbitl.c @@ -1,5 +1,5 @@ /* signbit() macro: Determine the sign bit of a floating-point number. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/size_max.h b/lib/size_max.h index 419d73a1..381eea12 100644 --- a/lib/size_max.h +++ b/lib/size_max.h @@ -1,5 +1,5 @@ /* size_max.h -- declare SIZE_MAX through system headers - Copyright (C) 2005-2006 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2010 Free Software Foundation, Inc. Written by Simon Josefsson. This program is free software; you can redistribute it and/or modify diff --git a/lib/stdbool.in.h b/lib/stdbool.in.h index 3390484f..f2510a9e 100644 --- a/lib/stdbool.in.h +++ b/lib/stdbool.in.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2003, 2006-2008 Free Software Foundation, Inc. +/* Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software; you can redistribute it and/or modify @@ -50,6 +50,9 @@ with this substitute. With this substitute, only the values 0 and 1 give the expected result when converted to _Bool' or 'bool'. + - C99 allows the use of (_Bool)0.0 in constant expressions, but + this substitute cannot always provide this property. + Also, it is suggested that programs use 'bool' rather than '_Bool'; this isn't required, but 'bool' is more common. */ diff --git a/lib/stddef.in.h b/lib/stddef.in.h index dacc83d9..b1dfb674 100644 --- a/lib/stddef.in.h +++ b/lib/stddef.in.h @@ -1,6 +1,6 @@ /* A substitute for POSIX 2008 , for platforms that have issues. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/stdint.in.h b/lib/stdint.in.h index 11a21176..997e4063 100644 --- a/lib/stdint.in.h +++ b/lib/stdint.in.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2002, 2004-2009 Free Software Foundation, Inc. +/* Copyright (C) 2001-2002, 2004-2010 Free Software Foundation, Inc. Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood. This file is part of gnulib. @@ -23,6 +23,10 @@ #ifndef _GL_STDINT_H +#if __GNUC__ >= 3 +@PRAGMA_SYSTEM_HEADER@ +#endif + /* When including a system file that in turn includes , use the system , not our substitute. This avoids problems with (for example) VMS, whose includes @@ -49,9 +53,6 @@ in would reinclude us, skipping our contents because _GL_STDINT_H is defined. The include_next requires a split double-inclusion guard. */ -# if __GNUC__ >= 3 -@PRAGMA_SYSTEM_HEADER@ -# endif # @INCLUDE_NEXT@ @NEXT_STDINT_H@ #endif @@ -102,8 +103,8 @@ ((signed) \ ? ~ _STDINT_MIN (signed, bits, zero) \ : /* The expression for the unsigned case. The subtraction of (signed) \ - is a nop in the unsigned case and avoids "signed integer overflow" \ - warnings in the signed case. */ \ + is a nop in the unsigned case and avoids "signed integer overflow" \ + warnings in the signed case. */ \ ((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1) /* 7.18.1.1. Exact-width integer types */ @@ -454,10 +455,10 @@ typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) - #undef SIG_ATOMIC_MAX #define SIG_ATOMIC_MIN \ _STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ - 0@SIG_ATOMIC_T_SUFFIX@) + 0@SIG_ATOMIC_T_SUFFIX@) #define SIG_ATOMIC_MAX \ _STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \ - 0@SIG_ATOMIC_T_SUFFIX@) + 0@SIG_ATOMIC_T_SUFFIX@) /* size_t limit */ diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h index 162d90de..528b6ef9 100644 --- a/lib/stdio-impl.h +++ b/lib/stdio-impl.h @@ -1,5 +1,5 @@ /* Implementation details of FILE streams. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2008, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -21,26 +21,31 @@ /* BSD stdio derived implementations. */ +#if defined __NetBSD__ /* NetBSD */ +/* Get __NetBSD_Version__. */ +# include +#endif + #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ # if defined __DragonFly__ /* DragonFly */ /* See . */ # define fp_ ((struct { struct __FILE_public pub; \ - struct { unsigned char *_base; int _size; } _bf; \ - void *cookie; \ - void *_close; \ - void *_read; \ - void *_seek; \ - void *_write; \ - struct { unsigned char *_base; int _size; } _ub; \ - int _ur; \ - unsigned char _ubuf[3]; \ - unsigned char _nbuf[1]; \ - struct { unsigned char *_base; int _size; } _lb; \ - int _blksize; \ - fpos_t _offset; \ - /* More fields, not relevant here. */ \ - } *) fp) + struct { unsigned char *_base; int _size; } _bf; \ + void *cookie; \ + void *_close; \ + void *_read; \ + void *_seek; \ + void *_write; \ + struct { unsigned char *_base; int _size; } _ub; \ + int _ur; \ + unsigned char _ubuf[3]; \ + unsigned char _nbuf[1]; \ + struct { unsigned char *_base; int _size; } _lb; \ + int _blksize; \ + fpos_t _offset; \ + /* More fields, not relevant here. */ \ + } *) fp) /* See . */ # define _p pub._p # define _flags pub._flags @@ -50,7 +55,7 @@ # define fp_ fp # endif -# if defined __NetBSD__ || defined __OpenBSD__ /* NetBSD, OpenBSD */ +# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ /* NetBSD >= 1.5ZA, OpenBSD */ /* See and */ struct __sfileext @@ -59,7 +64,7 @@ /* More fields, not relevant here. */ }; # define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub -# else /* FreeBSD, DragonFly, MacOS X, Cygwin */ +# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, MacOS X, Cygwin */ # define fp_ub fp_->_ub # endif @@ -74,12 +79,12 @@ # if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */ # define fp_ ((struct { unsigned char *_ptr; \ - unsigned char *_base; \ - unsigned char *_end; \ - long _cnt; \ - int _file; \ - unsigned int _flag; \ - } *) fp) + unsigned char *_base; \ + unsigned char *_end; \ + long _cnt; \ + int _file; \ + unsigned int _flag; \ + } *) fp) # else # define fp_ fp # endif diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 2a62fb73..3839ff34 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - Copyright (C) 1995, 2001-2004, 2006-2009 Free Software Foundation, Inc. + Copyright (C) 1995, 2001-2004, 2006-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -39,7 +39,7 @@ #include /* Solaris declares getloadavg() in . */ -#if @GNULIB_GETLOADAVG@ && @HAVE_SYS_LOADAVG_H@ +#if (@GNULIB_GETLOADAVG@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_LOADAVG_H@ # include #endif @@ -49,24 +49,36 @@ # include #endif -#if @GNULIB_RANDOM_R@ || !@HAVE_STRUCT_RANDOM_DATA@ +#if !@HAVE_STRUCT_RANDOM_DATA@ || (@GNULIB_RANDOM_R@ && !@HAVE_RANDOM_R@) \ + || defined GNULIB_POSIXCHECK # include #endif #if !@HAVE_STRUCT_RANDOM_DATA@ struct random_data { - int32_t *fptr; /* Front pointer. */ - int32_t *rptr; /* Rear pointer. */ - int32_t *state; /* Array of state values. */ - int rand_type; /* Type of random number generator. */ - int rand_deg; /* Degree of random number generator. */ - int rand_sep; /* Distance between front and rear. */ - int32_t *end_ptr; /* Pointer behind state table. */ + int32_t *fptr; /* Front pointer. */ + int32_t *rptr; /* Rear pointer. */ + int32_t *state; /* Array of state values. */ + int rand_type; /* Type of random number generator. */ + int rand_deg; /* Degree of random number generator. */ + int rand_sep; /* Distance between front and rear. */ + int32_t *end_ptr; /* Pointer behind state table. */ }; #endif -/* The definition of GL_LINK_WARNING is copied here. */ +#if (@GNULIB_MKSTEMP@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) +/* On MacOS X 10.3, only declares mkstemp. */ +/* On Cygwin 1.7.1, only declares getsubopt. */ +/* But avoid namespace pollution on glibc systems and native Windows. */ +# include +#endif + +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ /* Some systems do not define EXIT_*, despite otherwise supporting C89. */ @@ -83,88 +95,84 @@ struct random_data #endif -#ifdef __cplusplus -extern "C" { -#endif - - -#if @GNULIB_MALLOC_POSIX@ -# if !@HAVE_MALLOC_POSIX@ -# undef malloc -# define malloc rpl_malloc -extern void * malloc (size_t size); +#if @GNULIB_ATOLL@ +/* Parse a signed decimal integer. + Returns the value of the integer. Errors are not detected. */ +# if !@HAVE_ATOLL@ +_GL_FUNCDECL_SYS (atoll, long long, (const char *string) _GL_ARG_NONNULL ((1))); # endif +_GL_CXXALIAS_SYS (atoll, long long, (const char *string)); +_GL_CXXALIASWARN (atoll); #elif defined GNULIB_POSIXCHECK -# undef malloc -# define malloc(s) \ - (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \ - "use gnulib module malloc-posix for portability"), \ - malloc (s)) -#endif - - -#if @GNULIB_REALLOC_POSIX@ -# if !@HAVE_REALLOC_POSIX@ -# undef realloc -# define realloc rpl_realloc -extern void * realloc (void *ptr, size_t size); +# undef atoll +# if HAVE_RAW_DECL_ATOLL +_GL_WARN_ON_USE (atoll, "atoll is unportable - " + "use gnulib module atoll for portability"); # endif -#elif defined GNULIB_POSIXCHECK -# undef realloc -# define realloc(p,s) \ - (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \ - "use gnulib module realloc-posix for portability"), \ - realloc (p, s)) #endif - #if @GNULIB_CALLOC_POSIX@ # if !@HAVE_CALLOC_POSIX@ -# undef calloc -# define calloc rpl_calloc -extern void * calloc (size_t nmemb, size_t size); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef calloc +# define calloc rpl_calloc +# endif +_GL_FUNCDECL_RPL (calloc, void *, (size_t nmemb, size_t size)); +_GL_CXXALIAS_RPL (calloc, void *, (size_t nmemb, size_t size)); +# else +_GL_CXXALIAS_SYS (calloc, void *, (size_t nmemb, size_t size)); # endif +_GL_CXXALIASWARN (calloc); #elif defined GNULIB_POSIXCHECK # undef calloc -# define calloc(n,s) \ - (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \ - "use gnulib module calloc-posix for portability"), \ - calloc (n, s)) +/* Assume calloc is always declared. */ +_GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - " + "use gnulib module calloc-posix for portability"); #endif - -#if @GNULIB_ATOLL@ -# if !@HAVE_ATOLL@ -/* Parse a signed decimal integer. - Returns the value of the integer. Errors are not detected. */ -extern long long atoll (const char *string); +#if @GNULIB_CANONICALIZE_FILE_NAME@ +# if @REPLACE_CANONICALIZE_FILE_NAME@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define canonicalize_file_name rpl_canonicalize_file_name +# endif +_GL_FUNCDECL_RPL (canonicalize_file_name, char *, (const char *name) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (canonicalize_file_name, char *, (const char *name)); +# else +# if !@HAVE_CANONICALIZE_FILE_NAME@ +_GL_FUNCDECL_SYS (canonicalize_file_name, char *, (const char *name) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (canonicalize_file_name, char *, (const char *name)); # endif +_GL_CXXALIASWARN (canonicalize_file_name); #elif defined GNULIB_POSIXCHECK -# undef atoll -# define atoll(s) \ - (GL_LINK_WARNING ("atoll is unportable - " \ - "use gnulib module atoll for portability"), \ - atoll (s)) +# undef canonicalize_file_name +# if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME +_GL_WARN_ON_USE (canonicalize_file_name, "canonicalize_file_name is unportable - " + "use gnulib module canonicalize-lgpl for portability"); +# endif #endif - #if @GNULIB_GETLOADAVG@ -# if !@HAVE_DECL_GETLOADAVG@ /* Store max(NELEM,3) load average numbers in LOADAVG[]. The three numbers are the load average of the last 1 minute, the last 5 minutes, and the last 15 minutes, respectively. LOADAVG is an array of NELEM numbers. */ -extern int getloadavg (double loadavg[], int nelem); +# if !@HAVE_DECL_GETLOADAVG@ +_GL_FUNCDECL_SYS (getloadavg, int, (double loadavg[], int nelem) + _GL_ARG_NONNULL ((1))); # endif +_GL_CXXALIAS_SYS (getloadavg, int, (double loadavg[], int nelem)); +_GL_CXXALIASWARN (getloadavg); #elif defined GNULIB_POSIXCHECK # undef getloadavg -# define getloadavg(l,n) \ - (GL_LINK_WARNING ("getloadavg is not portable - " \ - "use gnulib module getloadavg for portability"), \ - getloadavg (l, n)) +# if HAVE_RAW_DECL_GETLOADAVG +_GL_WARN_ON_USE (getloadavg, "getloadavg is not portable - " + "use gnulib module getloadavg for portability"); +# endif #endif - #if @GNULIB_GETSUBOPT@ /* Assuming *OPTIONP is a comma separated list of elements of the form "token" or "token=value", getsubopt parses the first of these elements. @@ -178,37 +186,133 @@ extern int getloadavg (double loadavg[], int nelem); For more details see the POSIX:2001 specification. http://www.opengroup.org/susv3xsh/getsubopt.html */ # if !@HAVE_GETSUBOPT@ -extern int getsubopt (char **optionp, char *const *tokens, char **valuep); +_GL_FUNCDECL_SYS (getsubopt, int, + (char **optionp, char *const *tokens, char **valuep) + _GL_ARG_NONNULL ((1, 2, 3))); # endif +_GL_CXXALIAS_SYS (getsubopt, int, + (char **optionp, char *const *tokens, char **valuep)); +_GL_CXXALIASWARN (getsubopt); #elif defined GNULIB_POSIXCHECK # undef getsubopt -# define getsubopt(o,t,v) \ - (GL_LINK_WARNING ("getsubopt is unportable - " \ - "use gnulib module getsubopt for portability"), \ - getsubopt (o, t, v)) +# if HAVE_RAW_DECL_GETSUBOPT +_GL_WARN_ON_USE (getsubopt, "getsubopt is unportable - " + "use gnulib module getsubopt for portability"); +# endif +#endif + +#if @GNULIB_GRANTPT@ +/* Change the ownership and access permission of the slave side of the + pseudo-terminal whose master side is specified by FD. */ +# if !@HAVE_GRANTPT@ +_GL_FUNCDECL_SYS (grantpt, int, (int fd)); +# endif +_GL_CXXALIAS_SYS (grantpt, int, (int fd)); +_GL_CXXALIASWARN (grantpt); +#elif defined GNULIB_POSIXCHECK +# undef grantpt +# if HAVE_RAW_DECL_GRANTPT +_GL_WARN_ON_USE (ptsname, "grantpt is not portable - " + "use gnulib module grantpt for portability"); +# endif #endif +#if @GNULIB_MALLOC_POSIX@ +# if !@HAVE_MALLOC_POSIX@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef malloc +# define malloc rpl_malloc +# endif +_GL_FUNCDECL_RPL (malloc, void *, (size_t size)); +_GL_CXXALIAS_RPL (malloc, void *, (size_t size)); +# else +_GL_CXXALIAS_SYS (malloc, void *, (size_t size)); +# endif +_GL_CXXALIASWARN (malloc); +#elif defined GNULIB_POSIXCHECK +# undef malloc +/* Assume malloc is always declared. */ +_GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - " + "use gnulib module malloc-posix for portability"); +#endif #if @GNULIB_MKDTEMP@ -# if !@HAVE_MKDTEMP@ /* Create a unique temporary directory from TEMPLATE. The last six characters of TEMPLATE must be "XXXXXX"; they are replaced with a string that makes the directory name unique. Returns TEMPLATE, or a null pointer if it cannot get a unique name. The directory is created mode 700. */ -extern char * mkdtemp (char * /*template*/); +# if !@HAVE_MKDTEMP@ +_GL_FUNCDECL_SYS (mkdtemp, char *, (char * /*template*/) _GL_ARG_NONNULL ((1))); # endif +_GL_CXXALIAS_SYS (mkdtemp, char *, (char * /*template*/)); +_GL_CXXALIASWARN (mkdtemp); #elif defined GNULIB_POSIXCHECK # undef mkdtemp -# define mkdtemp(t) \ - (GL_LINK_WARNING ("mkdtemp is unportable - " \ - "use gnulib module mkdtemp for portability"), \ - mkdtemp (t)) +# if HAVE_RAW_DECL_MKDTEMP +_GL_WARN_ON_USE (mkdtemp, "mkdtemp is unportable - " + "use gnulib module mkdtemp for portability"); +# endif #endif +#if @GNULIB_MKOSTEMP@ +/* Create a unique temporary file from TEMPLATE. + The last six characters of TEMPLATE must be "XXXXXX"; + they are replaced with a string that makes the file name unique. + The flags are a bitmask, possibly including O_CLOEXEC (defined in ) + and O_TEXT, O_BINARY (defined in "binary-io.h"). + The file is then created, with the specified flags, ensuring it didn't exist + before. + The file is created read-write (mask at least 0600 & ~umask), but it may be + world-readable and world-writable (mask 0666 & ~umask), depending on the + implementation. + Returns the open file descriptor if successful, otherwise -1 and errno + set. */ +# if !@HAVE_MKOSTEMP@ +_GL_FUNCDECL_SYS (mkostemp, int, (char * /*template*/, int /*flags*/) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (mkostemp, int, (char * /*template*/, int /*flags*/)); +_GL_CXXALIASWARN (mkostemp); +#elif defined GNULIB_POSIXCHECK +# undef mkostemp +# if HAVE_RAW_DECL_MKOSTEMP +_GL_WARN_ON_USE (mkostemp, "mkostemp is unportable - " + "use gnulib module mkostemp for portability"); +# endif +#endif + +#if @GNULIB_MKOSTEMPS@ +/* Create a unique temporary file from TEMPLATE. + The last six characters of TEMPLATE before a suffix of length + SUFFIXLEN must be "XXXXXX"; + they are replaced with a string that makes the file name unique. + The flags are a bitmask, possibly including O_CLOEXEC (defined in ) + and O_TEXT, O_BINARY (defined in "binary-io.h"). + The file is then created, with the specified flags, ensuring it didn't exist + before. + The file is created read-write (mask at least 0600 & ~umask), but it may be + world-readable and world-writable (mask 0666 & ~umask), depending on the + implementation. + Returns the open file descriptor if successful, otherwise -1 and errno + set. */ +# if !@HAVE_MKOSTEMPS@ +_GL_FUNCDECL_SYS (mkostemps, int, + (char * /*template*/, int /*suffixlen*/, int /*flags*/) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (mkostemps, int, + (char * /*template*/, int /*suffixlen*/, int /*flags*/)); +_GL_CXXALIASWARN (mkostemps); +#elif defined GNULIB_POSIXCHECK +# undef mkostemps +# if HAVE_RAW_DECL_MKOSTEMPS +_GL_WARN_ON_USE (mkostemps, "mkostemps is unportable - " + "use gnulib module mkostemps for portability"); +# endif +#endif #if @GNULIB_MKSTEMP@ -# if @REPLACE_MKSTEMP@ /* Create a unique temporary file from TEMPLATE. The last six characters of TEMPLATE must be "XXXXXX"; they are replaced with a string that makes the file name unique. @@ -218,124 +322,276 @@ extern char * mkdtemp (char * /*template*/); implementation. Returns the open file descriptor if successful, otherwise -1 and errno set. */ -# define mkstemp rpl_mkstemp -extern int mkstemp (char * /*template*/); +# if @REPLACE_MKSTEMP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define mkstemp rpl_mkstemp +# endif +_GL_FUNCDECL_RPL (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (mkstemp, int, (char * /*template*/)); # else -/* On MacOS X 10.3, only declares mkstemp. */ -# include +# if ! @HAVE_MKSTEMP@ +_GL_FUNCDECL_SYS (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (mkstemp, int, (char * /*template*/)); # endif +_GL_CXXALIASWARN (mkstemp); #elif defined GNULIB_POSIXCHECK # undef mkstemp -# define mkstemp(t) \ - (GL_LINK_WARNING ("mkstemp is unportable - " \ - "use gnulib module mkstemp for portability"), \ - mkstemp (t)) +# if HAVE_RAW_DECL_MKSTEMP +_GL_WARN_ON_USE (mkstemp, "mkstemp is unportable - " + "use gnulib module mkstemp for portability"); +# endif #endif +#if @GNULIB_MKSTEMPS@ +/* Create a unique temporary file from TEMPLATE. + The last six characters of TEMPLATE prior to a suffix of length + SUFFIXLEN must be "XXXXXX"; + they are replaced with a string that makes the file name unique. + The file is then created, ensuring it didn't exist before. + The file is created read-write (mask at least 0600 & ~umask), but it may be + world-readable and world-writable (mask 0666 & ~umask), depending on the + implementation. + Returns the open file descriptor if successful, otherwise -1 and errno + set. */ +# if !@HAVE_MKSTEMPS@ +_GL_FUNCDECL_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/)); +_GL_CXXALIASWARN (mkstemps); +#elif defined GNULIB_POSIXCHECK +# undef mkstemps +# if HAVE_RAW_DECL_MKSTEMPS +_GL_WARN_ON_USE (mkstemps, "mkstemps is unportable - " + "use gnulib module mkstemps for portability"); +# endif +#endif + +#if @GNULIB_PTSNAME@ +/* Return the pathname of the pseudo-terminal slave associated with + the master FD is open on, or NULL on errors. */ +# if !@HAVE_PTSNAME@ +_GL_FUNCDECL_SYS (ptsname, char *, (int fd)); +# endif +_GL_CXXALIAS_SYS (ptsname, char *, (int fd)); +_GL_CXXALIASWARN (ptsname); +#elif defined GNULIB_POSIXCHECK +# undef ptsname +# if HAVE_RAW_DECL_PTSNAME +_GL_WARN_ON_USE (ptsname, "ptsname is not portable - " + "use gnulib module ptsname for portability"); +# endif +#endif #if @GNULIB_PUTENV@ # if @REPLACE_PUTENV@ -# undef putenv -# define putenv rpl_putenv -extern int putenv (char *string); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef putenv +# define putenv rpl_putenv +# endif +_GL_FUNCDECL_RPL (putenv, int, (char *string) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (putenv, int, (char *string)); +# else +_GL_CXXALIAS_SYS (putenv, int, (char *string)); # endif +_GL_CXXALIASWARN (putenv); #endif #if @GNULIB_RANDOM_R@ # if !@HAVE_RANDOM_R@ - # ifndef RAND_MAX # define RAND_MAX 2147483647 # endif +# endif +#endif -int srandom_r (unsigned int seed, struct random_data *rand_state); -int initstate_r (unsigned int seed, char *buf, size_t buf_size, - struct random_data *rand_state); -int setstate_r (char *arg_state, struct random_data *rand_state); -int random_r (struct random_data *buf, int32_t *result); +#if @GNULIB_RANDOM_R@ +# if !@HAVE_RANDOM_R@ +_GL_FUNCDECL_SYS (random_r, int, (struct random_data *buf, int32_t *result) + _GL_ARG_NONNULL ((1, 2))); # endif +_GL_CXXALIAS_SYS (random_r, int, (struct random_data *buf, int32_t *result)); +_GL_CXXALIASWARN (random_r); #elif defined GNULIB_POSIXCHECK # undef random_r -# define random_r(b,r) \ - (GL_LINK_WARNING ("random_r is unportable - " \ - "use gnulib module random_r for portability"), \ - random_r (b,r)) -# undef initstate_r -# define initstate_r(s,b,sz,r) \ - (GL_LINK_WARNING ("initstate_r is unportable - " \ - "use gnulib module random_r for portability"), \ - initstate_r (s,b,sz,r)) +# if HAVE_RAW_DECL_RANDOM_R +_GL_WARN_ON_USE (random_r, "random_r is unportable - " + "use gnulib module random_r for portability"); +# endif +#endif + +#if @GNULIB_RANDOM_R@ +# if !@HAVE_RANDOM_R@ +_GL_FUNCDECL_SYS (srandom_r, int, + (unsigned int seed, struct random_data *rand_state) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (srandom_r, int, + (unsigned int seed, struct random_data *rand_state)); +_GL_CXXALIASWARN (srandom_r); +#elif defined GNULIB_POSIXCHECK # undef srandom_r -# define srandom_r(s,r) \ - (GL_LINK_WARNING ("srandom_r is unportable - " \ - "use gnulib module random_r for portability"), \ - srandom_r (s,r)) +# if HAVE_RAW_DECL_SRANDOM_R +_GL_WARN_ON_USE (srandom_r, "srandom_r is unportable - " + "use gnulib module random_r for portability"); +# endif +#endif + +#if @GNULIB_RANDOM_R@ +# if !@HAVE_RANDOM_R@ +_GL_FUNCDECL_SYS (initstate_r, int, + (unsigned int seed, char *buf, size_t buf_size, + struct random_data *rand_state) + _GL_ARG_NONNULL ((2, 4))); +# endif +_GL_CXXALIAS_SYS (initstate_r, int, + (unsigned int seed, char *buf, size_t buf_size, + struct random_data *rand_state)); +_GL_CXXALIASWARN (initstate_r); +#elif defined GNULIB_POSIXCHECK +# undef initstate_r +# if HAVE_RAW_DECL_INITSTATE_R +_GL_WARN_ON_USE (initstate_r, "initstate_r is unportable - " + "use gnulib module random_r for portability"); +# endif +#endif + +#if @GNULIB_RANDOM_R@ +# if !@HAVE_RANDOM_R@ +_GL_FUNCDECL_SYS (setstate_r, int, + (char *arg_state, struct random_data *rand_state) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (setstate_r, int, + (char *arg_state, struct random_data *rand_state)); +_GL_CXXALIASWARN (setstate_r); +#elif defined GNULIB_POSIXCHECK # undef setstate_r -# define setstate_r(a,r) \ - (GL_LINK_WARNING ("setstate_r is unportable - " \ - "use gnulib module random_r for portability"), \ - setstate_r (a,r)) +# if HAVE_RAW_DECL_SETSTATE_R +_GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - " + "use gnulib module random_r for portability"); +# endif #endif +#if @GNULIB_REALLOC_POSIX@ +# if !@HAVE_REALLOC_POSIX@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef realloc +# define realloc rpl_realloc +# endif +_GL_FUNCDECL_RPL (realloc, void *, (void *ptr, size_t size)); +_GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size)); +# else +_GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size)); +# endif +_GL_CXXALIASWARN (realloc); +#elif defined GNULIB_POSIXCHECK +# undef realloc +/* Assume realloc is always declared. */ +_GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - " + "use gnulib module realloc-posix for portability"); +#endif + +#if @GNULIB_REALPATH@ +# if @REPLACE_REALPATH@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define realpath rpl_realpath +# endif +_GL_FUNCDECL_RPL (realpath, char *, (const char *name, char *resolved) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (realpath, char *, (const char *name, char *resolved)); +# else +# if !@HAVE_REALPATH@ +_GL_FUNCDECL_SYS (realpath, char *, (const char *name, char *resolved) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (realpath, char *, (const char *name, char *resolved)); +# endif +_GL_CXXALIASWARN (realpath); +#elif defined GNULIB_POSIXCHECK +# undef realpath +# if HAVE_RAW_DECL_REALPATH +_GL_WARN_ON_USE (realpath, "realpath is unportable - use gnulib module " + "canonicalize or canonicalize-lgpl for portability"); +# endif +#endif + #if @GNULIB_RPMATCH@ -# if !@HAVE_RPMATCH@ /* Test a user response to a question. Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */ -extern int rpmatch (const char *response); +# if !@HAVE_RPMATCH@ +_GL_FUNCDECL_SYS (rpmatch, int, (const char *response) _GL_ARG_NONNULL ((1))); # endif +_GL_CXXALIAS_SYS (rpmatch, int, (const char *response)); +_GL_CXXALIASWARN (rpmatch); #elif defined GNULIB_POSIXCHECK # undef rpmatch -# define rpmatch(r) \ - (GL_LINK_WARNING ("rpmatch is unportable - " \ - "use gnulib module rpmatch for portability"), \ - rpmatch (r)) +# if HAVE_RAW_DECL_RPMATCH +_GL_WARN_ON_USE (rpmatch, "rpmatch is unportable - " + "use gnulib module rpmatch for portability"); +# endif #endif - #if @GNULIB_SETENV@ -# if !@HAVE_SETENV@ /* Set NAME to VALUE in the environment. If REPLACE is nonzero, overwrite an existing value. */ -extern int setenv (const char *name, const char *value, int replace); -# endif -#endif - - -#if @GNULIB_UNSETENV@ -# if @HAVE_UNSETENV@ -# if @VOID_UNSETENV@ -/* On some systems, unsetenv() returns void. - This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */ -# define unsetenv(name) ((unsetenv)(name), 0) +# if @REPLACE_SETENV@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef setenv +# define setenv rpl_setenv # endif +_GL_FUNCDECL_RPL (setenv, int, + (const char *name, const char *value, int replace) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (setenv, int, + (const char *name, const char *value, int replace)); # else -/* Remove the variable NAME from the environment. */ -extern int unsetenv (const char *name); +# if !@HAVE_SETENV@ +_GL_FUNCDECL_SYS (setenv, int, + (const char *name, const char *value, int replace) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (setenv, int, + (const char *name, const char *value, int replace)); +# endif +_GL_CXXALIASWARN (setenv); +#elif defined GNULIB_POSIXCHECK +# undef setenv +# if HAVE_RAW_DECL_SETENV +_GL_WARN_ON_USE (setenv, "setenv is unportable - " + "use gnulib module setenv for portability"); # endif #endif - #if @GNULIB_STRTOD@ -# if @REPLACE_STRTOD@ -# define strtod rpl_strtod -# endif -# if !@HAVE_STRTOD@ || @REPLACE_STRTOD@ /* Parse a double from STRING, updating ENDP if appropriate. */ -extern double strtod (const char *str, char **endp); +# if @REPLACE_STRTOD@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define strtod rpl_strtod +# endif +_GL_FUNCDECL_RPL (strtod, double, (const char *str, char **endp) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (strtod, double, (const char *str, char **endp)); +# else +# if !@HAVE_STRTOD@ +_GL_FUNCDECL_SYS (strtod, double, (const char *str, char **endp) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (strtod, double, (const char *str, char **endp)); # endif +_GL_CXXALIASWARN (strtod); #elif defined GNULIB_POSIXCHECK # undef strtod -# define strtod(s, e) \ - (GL_LINK_WARNING ("strtod is unportable - " \ - "use gnulib module strtod for portability"), \ - strtod (s, e)) +# if HAVE_RAW_DECL_STRTOD +_GL_WARN_ON_USE (strtod, "strtod is unportable - " + "use gnulib module strtod for portability"); +# endif #endif - #if @GNULIB_STRTOLL@ -# if !@HAVE_STRTOLL@ /* Parse a signed integer whose textual representation starts at STRING. The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0, it may be decimal or octal (with prefix "0") or hexadecimal (with prefix @@ -344,19 +600,23 @@ extern double strtod (const char *str, char **endp); stored in *ENDPTR. Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set to ERANGE. */ -extern long long strtoll (const char *string, char **endptr, int base); +# if !@HAVE_STRTOLL@ +_GL_FUNCDECL_SYS (strtoll, long long, + (const char *string, char **endptr, int base) + _GL_ARG_NONNULL ((1))); # endif +_GL_CXXALIAS_SYS (strtoll, long long, + (const char *string, char **endptr, int base)); +_GL_CXXALIASWARN (strtoll); #elif defined GNULIB_POSIXCHECK # undef strtoll -# define strtoll(s,e,b) \ - (GL_LINK_WARNING ("strtoll is unportable - " \ - "use gnulib module strtoll for portability"), \ - strtoll (s, e, b)) +# if HAVE_RAW_DECL_STRTOLL +_GL_WARN_ON_USE (strtoll, "strtoll is unportable - " + "use gnulib module strtoll for portability"); +# endif #endif - #if @GNULIB_STRTOULL@ -# if !@HAVE_STRTOULL@ /* Parse an unsigned integer whose textual representation starts at STRING. The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0, it may be decimal or octal (with prefix "0") or hexadecimal (with prefix @@ -365,21 +625,63 @@ extern long long strtoll (const char *string, char **endptr, int base); stored in *ENDPTR. Upon overflow, the return value is ULLONG_MAX, and errno is set to ERANGE. */ -extern unsigned long long strtoull (const char *string, char **endptr, int base); +# if !@HAVE_STRTOULL@ +_GL_FUNCDECL_SYS (strtoull, unsigned long long, + (const char *string, char **endptr, int base) + _GL_ARG_NONNULL ((1))); # endif +_GL_CXXALIAS_SYS (strtoull, unsigned long long, + (const char *string, char **endptr, int base)); +_GL_CXXALIASWARN (strtoull); #elif defined GNULIB_POSIXCHECK # undef strtoull -# define strtoull(s,e,b) \ - (GL_LINK_WARNING ("strtoull is unportable - " \ - "use gnulib module strtoull for portability"), \ - strtoull (s, e, b)) +# if HAVE_RAW_DECL_STRTOULL +_GL_WARN_ON_USE (strtoull, "strtoull is unportable - " + "use gnulib module strtoull for portability"); +# endif #endif +#if @GNULIB_UNLOCKPT@ +/* Unlock the slave side of the pseudo-terminal whose master side is specified + by FD, so that it can be opened. */ +# if !@HAVE_UNLOCKPT@ +_GL_FUNCDECL_SYS (unlockpt, int, (int fd)); +# endif +_GL_CXXALIAS_SYS (unlockpt, int, (int fd)); +_GL_CXXALIASWARN (unlockpt); +#elif defined GNULIB_POSIXCHECK +# undef unlockpt +# if HAVE_RAW_DECL_UNLOCKPT +_GL_WARN_ON_USE (ptsname, "unlockpt is not portable - " + "use gnulib module unlockpt for portability"); +# endif +#endif -#ifdef __cplusplus -} +#if @GNULIB_UNSETENV@ +/* Remove the variable NAME from the environment. */ +# if @REPLACE_UNSETENV@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef unsetenv +# define unsetenv rpl_unsetenv +# endif +_GL_FUNCDECL_RPL (unsetenv, int, (const char *name) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (unsetenv, int, (const char *name)); +# else +# if !@HAVE_UNSETENV@ +_GL_FUNCDECL_SYS (unsetenv, int, (const char *name) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (unsetenv, int, (const char *name)); +# endif +_GL_CXXALIASWARN (unsetenv); +#elif defined GNULIB_POSIXCHECK +# undef unsetenv +# if HAVE_RAW_DECL_UNSETENV +_GL_WARN_ON_USE (unsetenv, "unsetenv is unportable - " + "use gnulib module unsetenv for portability"); +# endif #endif + #endif /* _GL_STDLIB_H */ #endif /* _GL_STDLIB_H */ #endif diff --git a/lib/streq.h b/lib/streq.h index 1b4b1c58..87915988 100644 --- a/lib/streq.h +++ b/lib/streq.h @@ -1,5 +1,5 @@ /* Optimized string comparison. - Copyright (C) 2001-2002, 2007 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/striconveh.c b/lib/striconveh.c index b39a01f1..ae10f3c1 100644 --- a/lib/striconveh.c +++ b/lib/striconveh.c @@ -1,5 +1,5 @@ /* Character set conversion with error handling. - Copyright (C) 2001-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2010 Free Software Foundation, Inc. Written by Bruno Haible and Simon Josefsson. This program is free software: you can redistribute it and/or modify @@ -40,9 +40,98 @@ #if HAVE_ICONV -/* The caller must provide CD, CD1, CD2, not just CD, because when a conversion - error occurs, we may have to determine the Unicode representation of the - inconvertible character. */ +/* The caller must provide an iconveh_t, not just an iconv_t, because when a + conversion error occurs, we may have to determine the Unicode representation + of the inconvertible character. */ + +int +iconveh_open (const char *to_codeset, const char *from_codeset, iconveh_t *cdp) +{ + iconv_t cd; + iconv_t cd1; + iconv_t cd2; + + /* Avoid glibc-2.1 bug with EUC-KR. */ +# if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION + if (c_strcasecmp (from_codeset, "EUC-KR") == 0 + || c_strcasecmp (to_codeset, "EUC-KR") == 0) + { + errno = EINVAL; + return -1; + } +# endif + + cd = iconv_open (to_codeset, from_codeset); + + if (STRCASEEQ (from_codeset, "UTF-8", 'U','T','F','-','8',0,0,0,0)) + cd1 = (iconv_t)(-1); + else + { + cd1 = iconv_open ("UTF-8", from_codeset); + if (cd1 == (iconv_t)(-1)) + { + int saved_errno = errno; + if (cd != (iconv_t)(-1)) + iconv_close (cdp->cd); + errno = saved_errno; + return -1; + } + } + + if (STRCASEEQ (to_codeset, "UTF-8", 'U','T','F','-','8',0,0,0,0) +# if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 || _LIBICONV_VERSION >= 0x0105 + || c_strcasecmp (to_codeset, "UTF-8//TRANSLIT") == 0 +# endif + ) + cd2 = (iconv_t)(-1); + else + { + cd2 = iconv_open (to_codeset, "UTF-8"); + if (cd2 == (iconv_t)(-1)) + { + int saved_errno = errno; + if (cd1 != (iconv_t)(-1)) + iconv_close (cd1); + if (cd != (iconv_t)(-1)) + iconv_close (cd); + errno = saved_errno; + return -1; + } + } + + cdp->cd = cd; + cdp->cd1 = cd1; + cdp->cd2 = cd2; + return 0; +} + +int +iconveh_close (const iconveh_t *cd) +{ + if (cd->cd2 != (iconv_t)(-1) && iconv_close (cd->cd2) < 0) + { + /* Return -1, but preserve the errno from iconv_close. */ + int saved_errno = errno; + if (cd->cd1 != (iconv_t)(-1)) + iconv_close (cd->cd1); + if (cd->cd != (iconv_t)(-1)) + iconv_close (cd->cd); + errno = saved_errno; + return -1; + } + if (cd->cd1 != (iconv_t)(-1) && iconv_close (cd->cd1) < 0) + { + /* Return -1, but preserve the errno from iconv_close. */ + int saved_errno = errno; + if (cd->cd != (iconv_t)(-1)) + iconv_close (cd->cd); + errno = saved_errno; + return -1; + } + if (cd->cd != (iconv_t)(-1) && iconv_close (cd->cd) < 0) + return -1; + return 0; +} /* iconv_carefully is like iconv, except that it stops as soon as it encounters a conversion error, and it returns in *INCREMENTED a boolean telling whether @@ -54,9 +143,9 @@ than doing a lossy conversion. */ static size_t iconv_carefully (iconv_t cd, - const char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft, - bool *incremented) + const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft, + bool *incremented) { const char *inptr = *inbuf; const char *inptr_end = inptr + *inbytesleft; @@ -73,26 +162,26 @@ iconv_carefully (iconv_t cd, res = (size_t)(-1); for (insize = 1; inptr + insize <= inptr_end; insize++) - { - res = iconv (cd, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - if (!(res == (size_t)(-1) && errno == EINVAL)) - break; - /* iconv can eat up a shift sequence but give EINVAL while attempting - to convert the first character. E.g. libiconv does this. */ - if (inptr > inptr_before) - { - res = 0; - break; - } - } + { + res = iconv (cd, + (ICONV_CONST char **) &inptr, &insize, + &outptr, &outsize); + if (!(res == (size_t)(-1) && errno == EINVAL)) + break; + /* iconv can eat up a shift sequence but give EINVAL while attempting + to convert the first character. E.g. libiconv does this. */ + if (inptr > inptr_before) + { + res = 0; + break; + } + } if (res == 0) - { - *outbuf = outptr; - *outbytesleft = outsize; - } + { + *outbuf = outptr; + *outbytesleft = outsize; + } } while (res == 0 && inptr < inptr_end); @@ -101,9 +190,9 @@ iconv_carefully (iconv_t cd, if (res != (size_t)(-1) && res > 0) { /* iconv() has already incremented INPTR. We cannot go back to a - previous INPTR, otherwise the state inside CD would become invalid, - if FROM_CODESET is a stateful encoding. So, tell the caller that - *INBUF has already been incremented. */ + previous INPTR, otherwise the state inside CD would become invalid, + if FROM_CODESET is a stateful encoding. So, tell the caller that + *INBUF has already been incremented. */ *incremented = (inptr > inptr_before); errno = EILSEQ; return (size_t)(-1); @@ -124,9 +213,9 @@ iconv_carefully (iconv_t cd, converting one character or one shift sequence. */ static size_t iconv_carefully_1 (iconv_t cd, - const char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft, - bool *incremented) + const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft, + bool *incremented) { const char *inptr_before = *inbuf; const char *inptr = inptr_before; @@ -140,17 +229,17 @@ iconv_carefully_1 (iconv_t cd, { inptr = inptr_before; res = iconv (cd, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); + (ICONV_CONST char **) &inptr, &insize, + &outptr, &outsize); if (!(res == (size_t)(-1) && errno == EINVAL)) - break; + break; /* iconv can eat up a shift sequence but give EINVAL while attempting - to convert the first character. E.g. libiconv does this. */ + to convert the first character. E.g. libiconv does this. */ if (inptr > inptr_before) - { - res = 0; - break; - } + { + res = 0; + break; + } } *inbuf = inptr; @@ -163,9 +252,9 @@ iconv_carefully_1 (iconv_t cd, if (res != (size_t)(-1) && res > 0) { /* iconv() has already incremented INPTR. We cannot go back to a - previous INPTR, otherwise the state inside CD would become invalid, - if FROM_CODESET is a stateful encoding. So, tell the caller that - *INBUF has already been incremented. */ + previous INPTR, otherwise the state inside CD would become invalid, + if FROM_CODESET is a stateful encoding. So, tell the caller that + *INBUF has already been incremented. */ *incremented = (inptr > inptr_before); errno = EILSEQ; return (size_t)(-1); @@ -190,9 +279,9 @@ iconv_carefully_1 (iconv_t cd, character. */ static size_t utf8conv_carefully (bool one_character_only, - const char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft, - bool *incremented) + const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft, + bool *incremented) { const char *inptr = *inbuf; size_t insize = *inbytesleft; @@ -209,39 +298,39 @@ utf8conv_carefully (bool one_character_only, n = u8_mbtoucr (&uc, (const uint8_t *) inptr, insize); if (n < 0) - { - errno = (n == -2 ? EINVAL : EILSEQ); - n = u8_mbtouc (&uc, (const uint8_t *) inptr, insize); - inptr += n; - insize -= n; - res = (size_t)(-1); - *incremented = true; - break; - } + { + errno = (n == -2 ? EINVAL : EILSEQ); + n = u8_mbtouc (&uc, (const uint8_t *) inptr, insize); + inptr += n; + insize -= n; + res = (size_t)(-1); + *incremented = true; + break; + } if (outsize == 0) - { - errno = E2BIG; - res = (size_t)(-1); - *incremented = false; - break; - } + { + errno = E2BIG; + res = (size_t)(-1); + *incremented = false; + break; + } m = u8_uctomb ((uint8_t *) outptr, uc, outsize); if (m == -2) - { - errno = E2BIG; - res = (size_t)(-1); - *incremented = false; - break; - } + { + errno = E2BIG; + res = (size_t)(-1); + *incremented = false; + break; + } inptr += n; insize -= n; if (m == -1) - { - errno = EILSEQ; - res = (size_t)(-1); - *incremented = true; - break; - } + { + errno = EILSEQ; + res = (size_t)(-1); + *incremented = true; + break; + } outptr += m; outsize -= m; } @@ -256,11 +345,11 @@ utf8conv_carefully (bool one_character_only, static int mem_cd_iconveh_internal (const char *src, size_t srclen, - iconv_t cd, iconv_t cd1, iconv_t cd2, - enum iconv_ilseq_handler handler, - size_t extra_alloc, - size_t *offsets, - char **resultp, size_t *lengthp) + iconv_t cd, iconv_t cd1, iconv_t cd2, + enum iconv_ilseq_handler handler, + size_t extra_alloc, + size_t *offsets, + char **resultp, size_t *lengthp) { /* When a conversion error occurs, we cannot start using CD1 and CD2 at this point: FROM_CODESET may be a stateful encoding like ISO-2022-KR. @@ -300,7 +389,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, size_t i; for (i = 0; i < srclen; i++) - offsets[i] = (size_t)(-1); + offsets[i] = (size_t)(-1); last_length = (size_t)(-1); } @@ -321,121 +410,121 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, while (insize > 0) { - char *outptr = result + length; - size_t outsize = allocated - extra_alloc - length; - bool incremented; - size_t res; - bool grow; - - if (offsets != NULL) - { - if (length != last_length) /* ensure that offset[] be increasing */ - { - offsets[inptr - src] = length; - last_length = length; - } - res = iconv_carefully_1 (cd, - &inptr, &insize, - &outptr, &outsize, - &incremented); - } - else - /* Use iconv_carefully instead of iconv here, because: - - If TO_CODESET is UTF-8, we can do the error handling in this - loop, no need for a second loop, - - With iconv() implementations other than GNU libiconv and GNU - libc, if we use iconv() in a big swoop, checking for an E2BIG - return, we lose the number of irreversible conversions. */ - res = iconv_carefully (cd, - &inptr, &insize, - &outptr, &outsize, - &incremented); - - length = outptr - result; - grow = (length + extra_alloc > allocated / 2); - if (res == (size_t)(-1)) - { - if (errno == E2BIG) - grow = true; - else if (errno == EINVAL) - break; - else if (errno == EILSEQ && handler != iconveh_error) - { - if (cd2 == (iconv_t)(-1)) - { - /* TO_CODESET is UTF-8. */ - /* Error handling can produce up to 1 byte of output. */ - if (length + 1 + extra_alloc > allocated) - { - char *memory; - - allocated = 2 * allocated; - if (length + 1 + extra_alloc > allocated) - abort (); - if (result == initial_result) - memory = (char *) malloc (allocated); - else - memory = (char *) realloc (result, allocated); - if (memory == NULL) - { - if (result != initial_result) - free (result); - errno = ENOMEM; - return -1; - } - if (result == initial_result) - memcpy (memory, initial_result, length); - result = memory; - grow = false; - } - /* The input is invalid in FROM_CODESET. Eat up one byte - and emit a question mark. */ - if (!incremented) - { - if (insize == 0) - abort (); - inptr++; - insize--; - } - result[length] = '?'; - length++; - } - else - goto indirectly; - } - else - { - if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } - return -1; - } - } - if (insize == 0) - break; - if (grow) - { - char *memory; - - allocated = 2 * allocated; - if (result == initial_result) - memory = (char *) malloc (allocated); - else - memory = (char *) realloc (result, allocated); - if (memory == NULL) - { - if (result != initial_result) - free (result); - errno = ENOMEM; - return -1; - } - if (result == initial_result) - memcpy (memory, initial_result, length); - result = memory; - } + char *outptr = result + length; + size_t outsize = allocated - extra_alloc - length; + bool incremented; + size_t res; + bool grow; + + if (offsets != NULL) + { + if (length != last_length) /* ensure that offset[] be increasing */ + { + offsets[inptr - src] = length; + last_length = length; + } + res = iconv_carefully_1 (cd, + &inptr, &insize, + &outptr, &outsize, + &incremented); + } + else + /* Use iconv_carefully instead of iconv here, because: + - If TO_CODESET is UTF-8, we can do the error handling in this + loop, no need for a second loop, + - With iconv() implementations other than GNU libiconv and GNU + libc, if we use iconv() in a big swoop, checking for an E2BIG + return, we lose the number of irreversible conversions. */ + res = iconv_carefully (cd, + &inptr, &insize, + &outptr, &outsize, + &incremented); + + length = outptr - result; + grow = (length + extra_alloc > allocated / 2); + if (res == (size_t)(-1)) + { + if (errno == E2BIG) + grow = true; + else if (errno == EINVAL) + break; + else if (errno == EILSEQ && handler != iconveh_error) + { + if (cd2 == (iconv_t)(-1)) + { + /* TO_CODESET is UTF-8. */ + /* Error handling can produce up to 1 byte of output. */ + if (length + 1 + extra_alloc > allocated) + { + char *memory; + + allocated = 2 * allocated; + if (length + 1 + extra_alloc > allocated) + abort (); + if (result == initial_result) + memory = (char *) malloc (allocated); + else + memory = (char *) realloc (result, allocated); + if (memory == NULL) + { + if (result != initial_result) + free (result); + errno = ENOMEM; + return -1; + } + if (result == initial_result) + memcpy (memory, initial_result, length); + result = memory; + grow = false; + } + /* The input is invalid in FROM_CODESET. Eat up one byte + and emit a question mark. */ + if (!incremented) + { + if (insize == 0) + abort (); + inptr++; + insize--; + } + result[length] = '?'; + length++; + } + else + goto indirectly; + } + else + { + if (result != initial_result) + { + int saved_errno = errno; + free (result); + errno = saved_errno; + } + return -1; + } + } + if (insize == 0) + break; + if (grow) + { + char *memory; + + allocated = 2 * allocated; + if (result == initial_result) + memory = (char *) malloc (allocated); + else + memory = (char *) realloc (result, allocated); + if (memory == NULL) + { + if (result != initial_result) + free (result); + errno = ENOMEM; + return -1; + } + if (result == initial_result) + memcpy (memory, initial_result, length); + result = memory; + } } } @@ -452,40 +541,40 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, res = iconv (cd, NULL, NULL, &outptr, &outsize); length = outptr - result; if (res == (size_t)(-1)) - { - if (errno == E2BIG) - { - char *memory; - - allocated = 2 * allocated; - if (result == initial_result) - memory = (char *) malloc (allocated); - else - memory = (char *) realloc (result, allocated); - if (memory == NULL) - { - if (result != initial_result) - free (result); - errno = ENOMEM; - return -1; - } - if (result == initial_result) - memcpy (memory, initial_result, length); - result = memory; - } - else - { - if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } - return -1; - } - } + { + if (errno == E2BIG) + { + char *memory; + + allocated = 2 * allocated; + if (result == initial_result) + memory = (char *) malloc (allocated); + else + memory = (char *) realloc (result, allocated); + if (memory == NULL) + { + if (result != initial_result) + free (result); + errno = ENOMEM; + return -1; + } + if (result == initial_result) + memcpy (memory, initial_result, length); + result = memory; + } + else + { + if (result != initial_result) + { + int saved_errno = errno; + free (result); + errno = saved_errno; + } + return -1; + } + } else - break; + break; } #endif @@ -500,7 +589,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, size_t i; for (i = 0; i < srclen; i++) - offsets[i] = (size_t)(-1); + offsets[i] = (size_t)(-1); last_length = (size_t)(-1); } @@ -527,350 +616,351 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, while (in1size > 0 || do_final_flush1 || utf8len > 0 || do_final_flush2) { - char *out1ptr = utf8buf + utf8len; - size_t out1size = utf8bufsize - utf8len; - bool incremented1; - size_t res1; - int errno1; - - /* Conversion step 1: from FROM_CODESET to UTF-8. */ - if (in1size > 0) - { - if (offsets != NULL - && length != last_length) /* ensure that offset[] be increasing */ - { - offsets[in1ptr - src] = length; - last_length = length; - } - if (cd1 != (iconv_t)(-1)) - { - if (slowly) - res1 = iconv_carefully_1 (cd1, - &in1ptr, &in1size, - &out1ptr, &out1size, - &incremented1); - else - res1 = iconv_carefully (cd1, - &in1ptr, &in1size, - &out1ptr, &out1size, - &incremented1); - } - else - { - /* FROM_CODESET is UTF-8. */ - res1 = utf8conv_carefully (slowly, - &in1ptr, &in1size, - &out1ptr, &out1size, - &incremented1); - } - } - else if (do_final_flush1) - { - /* Now get the conversion state of CD1 back to the initial state. - But avoid glibc-2.1 bug and Solaris 2.7 bug. */ + char *out1ptr = utf8buf + utf8len; + size_t out1size = utf8bufsize - utf8len; + bool incremented1; + size_t res1; + int errno1; + + /* Conversion step 1: from FROM_CODESET to UTF-8. */ + if (in1size > 0) + { + if (offsets != NULL + && length != last_length) /* ensure that offset[] be increasing */ + { + offsets[in1ptr - src] = length; + last_length = length; + } + if (cd1 != (iconv_t)(-1)) + { + if (slowly) + res1 = iconv_carefully_1 (cd1, + &in1ptr, &in1size, + &out1ptr, &out1size, + &incremented1); + else + res1 = iconv_carefully (cd1, + &in1ptr, &in1size, + &out1ptr, &out1size, + &incremented1); + } + else + { + /* FROM_CODESET is UTF-8. */ + res1 = utf8conv_carefully (slowly, + &in1ptr, &in1size, + &out1ptr, &out1size, + &incremented1); + } + } + else if (do_final_flush1) + { + /* Now get the conversion state of CD1 back to the initial state. + But avoid glibc-2.1 bug and Solaris 2.7 bug. */ # if defined _LIBICONV_VERSION \ || !((__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1) || defined __sun) - if (cd1 != (iconv_t)(-1)) - res1 = iconv (cd1, NULL, NULL, &out1ptr, &out1size); - else + if (cd1 != (iconv_t)(-1)) + res1 = iconv (cd1, NULL, NULL, &out1ptr, &out1size); + else # endif - res1 = 0; - do_final_flush1 = false; - incremented1 = true; - } - else - { - res1 = 0; - incremented1 = true; - } - if (res1 == (size_t)(-1) - && !(errno == E2BIG || errno == EINVAL || errno == EILSEQ)) - { - if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } - return -1; - } - if (res1 == (size_t)(-1) - && errno == EILSEQ && handler != iconveh_error) - { - /* The input is invalid in FROM_CODESET. Eat up one byte and - emit a question mark. Room for the question mark was allocated - at the end of utf8buf. */ - if (!incremented1) - { - if (in1size == 0) - abort (); - in1ptr++; - in1size--; - } - utf8buf[utf8len++] = '?'; - } - errno1 = errno; - utf8len = out1ptr - utf8buf; - - if (offsets != NULL - || in1size == 0 - || utf8len > utf8bufsize / 2 - || (res1 == (size_t)(-1) && errno1 == E2BIG)) - { - /* Conversion step 2: from UTF-8 to TO_CODESET. */ - const char *in2ptr = utf8buf; - size_t in2size = utf8len; - - while (in2size > 0 - || (in1size == 0 && !do_final_flush1 && do_final_flush2)) - { - char *out2ptr = result + length; - size_t out2size = allocated - extra_alloc - length; - bool incremented2; - size_t res2; - bool grow; - - if (in2size > 0) - { - if (cd2 != (iconv_t)(-1)) - res2 = iconv_carefully (cd2, - &in2ptr, &in2size, - &out2ptr, &out2size, - &incremented2); - else - /* TO_CODESET is UTF-8. */ - res2 = utf8conv_carefully (false, - &in2ptr, &in2size, - &out2ptr, &out2size, - &incremented2); - } - else /* in1size == 0 && !do_final_flush1 - && in2size == 0 && do_final_flush2 */ - { - /* Now get the conversion state of CD1 back to the initial - state. But avoid glibc-2.1 bug and Solaris 2.7 bug. */ + res1 = 0; + do_final_flush1 = false; + incremented1 = true; + } + else + { + res1 = 0; + incremented1 = true; + } + if (res1 == (size_t)(-1) + && !(errno == E2BIG || errno == EINVAL || errno == EILSEQ)) + { + if (result != initial_result) + { + int saved_errno = errno; + free (result); + errno = saved_errno; + } + return -1; + } + if (res1 == (size_t)(-1) + && errno == EILSEQ && handler != iconveh_error) + { + /* The input is invalid in FROM_CODESET. Eat up one byte and + emit a question mark. Room for the question mark was allocated + at the end of utf8buf. */ + if (!incremented1) + { + if (in1size == 0) + abort (); + in1ptr++; + in1size--; + } + *out1ptr++ = '?'; + res1 = 0; + } + errno1 = errno; + utf8len = out1ptr - utf8buf; + + if (offsets != NULL + || in1size == 0 + || utf8len > utf8bufsize / 2 + || (res1 == (size_t)(-1) && errno1 == E2BIG)) + { + /* Conversion step 2: from UTF-8 to TO_CODESET. */ + const char *in2ptr = utf8buf; + size_t in2size = utf8len; + + while (in2size > 0 + || (in1size == 0 && !do_final_flush1 && do_final_flush2)) + { + char *out2ptr = result + length; + size_t out2size = allocated - extra_alloc - length; + bool incremented2; + size_t res2; + bool grow; + + if (in2size > 0) + { + if (cd2 != (iconv_t)(-1)) + res2 = iconv_carefully (cd2, + &in2ptr, &in2size, + &out2ptr, &out2size, + &incremented2); + else + /* TO_CODESET is UTF-8. */ + res2 = utf8conv_carefully (false, + &in2ptr, &in2size, + &out2ptr, &out2size, + &incremented2); + } + else /* in1size == 0 && !do_final_flush1 + && in2size == 0 && do_final_flush2 */ + { + /* Now get the conversion state of CD1 back to the initial + state. But avoid glibc-2.1 bug and Solaris 2.7 bug. */ # if defined _LIBICONV_VERSION \ || !((__GLIBC__ == 2 && __GLIBC_MINOR__ <= 1) || defined __sun) - if (cd2 != (iconv_t)(-1)) - res2 = iconv (cd2, NULL, NULL, &out2ptr, &out2size); - else + if (cd2 != (iconv_t)(-1)) + res2 = iconv (cd2, NULL, NULL, &out2ptr, &out2size); + else # endif - res2 = 0; - do_final_flush2 = false; - incremented2 = true; - } - - length = out2ptr - result; - grow = (length + extra_alloc > allocated / 2); - if (res2 == (size_t)(-1)) - { - if (errno == E2BIG) - grow = true; - else if (errno == EINVAL) - break; - else if (errno == EILSEQ && handler != iconveh_error) - { - /* Error handling can produce up to 10 bytes of ASCII - output. But TO_CODESET may be UCS-2, UTF-16 or - UCS-4, so use CD2 here as well. */ - char scratchbuf[10]; - size_t scratchlen; - ucs4_t uc; - const char *inptr; - size_t insize; - size_t res; - - if (incremented2) - { - if (u8_prev (&uc, (const uint8_t *) in2ptr, - (const uint8_t *) utf8buf) - == NULL) - abort (); - } - else - { - int n; - if (in2size == 0) - abort (); - n = u8_mbtouc_unsafe (&uc, (const uint8_t *) in2ptr, - in2size); - in2ptr += n; - in2size -= n; - } - - if (handler == iconveh_escape_sequence) - { - static char hex[16] = "0123456789ABCDEF"; - scratchlen = 0; - scratchbuf[scratchlen++] = '\\'; - if (uc < 0x10000) - scratchbuf[scratchlen++] = 'u'; - else - { - scratchbuf[scratchlen++] = 'U'; - scratchbuf[scratchlen++] = hex[(uc>>28) & 15]; - scratchbuf[scratchlen++] = hex[(uc>>24) & 15]; - scratchbuf[scratchlen++] = hex[(uc>>20) & 15]; - scratchbuf[scratchlen++] = hex[(uc>>16) & 15]; - } - scratchbuf[scratchlen++] = hex[(uc>>12) & 15]; - scratchbuf[scratchlen++] = hex[(uc>>8) & 15]; - scratchbuf[scratchlen++] = hex[(uc>>4) & 15]; - scratchbuf[scratchlen++] = hex[uc & 15]; - } - else - { - scratchbuf[0] = '?'; - scratchlen = 1; - } - - inptr = scratchbuf; - insize = scratchlen; - if (cd2 != (iconv_t)(-1)) - res = iconv (cd2, - (ICONV_CONST char **) &inptr, &insize, - &out2ptr, &out2size); - else - { - /* TO_CODESET is UTF-8. */ - if (out2size >= insize) - { - memcpy (out2ptr, inptr, insize); - out2ptr += insize; - out2size -= insize; - inptr += insize; - insize = 0; - res = 0; - } - else - { - errno = E2BIG; - res = (size_t)(-1); - } - } - length = out2ptr - result; - if (res == (size_t)(-1) && errno == E2BIG) - { - char *memory; - - allocated = 2 * allocated; - if (length + 1 + extra_alloc > allocated) - abort (); - if (result == initial_result) - memory = (char *) malloc (allocated); - else - memory = (char *) realloc (result, allocated); - if (memory == NULL) - { - if (result != initial_result) - free (result); - errno = ENOMEM; - return -1; - } - if (result == initial_result) - memcpy (memory, initial_result, length); - result = memory; - grow = false; - - out2ptr = result + length; - out2size = allocated - extra_alloc - length; - if (cd2 != (iconv_t)(-1)) - res = iconv (cd2, - (ICONV_CONST char **) &inptr, - &insize, - &out2ptr, &out2size); - else - { - /* TO_CODESET is UTF-8. */ - if (!(out2size >= insize)) - abort (); - memcpy (out2ptr, inptr, insize); - out2ptr += insize; - out2size -= insize; - inptr += insize; - insize = 0; - res = 0; - } - length = out2ptr - result; - } + res2 = 0; + do_final_flush2 = false; + incremented2 = true; + } + + length = out2ptr - result; + grow = (length + extra_alloc > allocated / 2); + if (res2 == (size_t)(-1)) + { + if (errno == E2BIG) + grow = true; + else if (errno == EINVAL) + break; + else if (errno == EILSEQ && handler != iconveh_error) + { + /* Error handling can produce up to 10 bytes of ASCII + output. But TO_CODESET may be UCS-2, UTF-16 or + UCS-4, so use CD2 here as well. */ + char scratchbuf[10]; + size_t scratchlen; + ucs4_t uc; + const char *inptr; + size_t insize; + size_t res; + + if (incremented2) + { + if (u8_prev (&uc, (const uint8_t *) in2ptr, + (const uint8_t *) utf8buf) + == NULL) + abort (); + } + else + { + int n; + if (in2size == 0) + abort (); + n = u8_mbtouc_unsafe (&uc, (const uint8_t *) in2ptr, + in2size); + in2ptr += n; + in2size -= n; + } + + if (handler == iconveh_escape_sequence) + { + static char hex[16] = "0123456789ABCDEF"; + scratchlen = 0; + scratchbuf[scratchlen++] = '\\'; + if (uc < 0x10000) + scratchbuf[scratchlen++] = 'u'; + else + { + scratchbuf[scratchlen++] = 'U'; + scratchbuf[scratchlen++] = hex[(uc>>28) & 15]; + scratchbuf[scratchlen++] = hex[(uc>>24) & 15]; + scratchbuf[scratchlen++] = hex[(uc>>20) & 15]; + scratchbuf[scratchlen++] = hex[(uc>>16) & 15]; + } + scratchbuf[scratchlen++] = hex[(uc>>12) & 15]; + scratchbuf[scratchlen++] = hex[(uc>>8) & 15]; + scratchbuf[scratchlen++] = hex[(uc>>4) & 15]; + scratchbuf[scratchlen++] = hex[uc & 15]; + } + else + { + scratchbuf[0] = '?'; + scratchlen = 1; + } + + inptr = scratchbuf; + insize = scratchlen; + if (cd2 != (iconv_t)(-1)) + res = iconv (cd2, + (ICONV_CONST char **) &inptr, &insize, + &out2ptr, &out2size); + else + { + /* TO_CODESET is UTF-8. */ + if (out2size >= insize) + { + memcpy (out2ptr, inptr, insize); + out2ptr += insize; + out2size -= insize; + inptr += insize; + insize = 0; + res = 0; + } + else + { + errno = E2BIG; + res = (size_t)(-1); + } + } + length = out2ptr - result; + if (res == (size_t)(-1) && errno == E2BIG) + { + char *memory; + + allocated = 2 * allocated; + if (length + 1 + extra_alloc > allocated) + abort (); + if (result == initial_result) + memory = (char *) malloc (allocated); + else + memory = (char *) realloc (result, allocated); + if (memory == NULL) + { + if (result != initial_result) + free (result); + errno = ENOMEM; + return -1; + } + if (result == initial_result) + memcpy (memory, initial_result, length); + result = memory; + grow = false; + + out2ptr = result + length; + out2size = allocated - extra_alloc - length; + if (cd2 != (iconv_t)(-1)) + res = iconv (cd2, + (ICONV_CONST char **) &inptr, + &insize, + &out2ptr, &out2size); + else + { + /* TO_CODESET is UTF-8. */ + if (!(out2size >= insize)) + abort (); + memcpy (out2ptr, inptr, insize); + out2ptr += insize; + out2size -= insize; + inptr += insize; + insize = 0; + res = 0; + } + length = out2ptr - result; + } # if !defined _LIBICONV_VERSION && !defined __GLIBC__ - /* Irix iconv() inserts a NUL byte if it cannot convert. - NetBSD iconv() inserts a question mark if it cannot - convert. - Only GNU libiconv and GNU libc are known to prefer - to fail rather than doing a lossy conversion. */ - if (res != (size_t)(-1) && res > 0) - { - errno = EILSEQ; - res = (size_t)(-1); - } + /* Irix iconv() inserts a NUL byte if it cannot convert. + NetBSD iconv() inserts a question mark if it cannot + convert. + Only GNU libiconv and GNU libc are known to prefer + to fail rather than doing a lossy conversion. */ + if (res != (size_t)(-1) && res > 0) + { + errno = EILSEQ; + res = (size_t)(-1); + } # endif - if (res == (size_t)(-1)) - { - /* Failure converting the ASCII replacement. */ - if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } - return -1; - } - } - else - { - if (result != initial_result) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } - return -1; - } - } - if (!(in2size > 0 - || (in1size == 0 && !do_final_flush1 && do_final_flush2))) - break; - if (grow) - { - char *memory; - - allocated = 2 * allocated; - if (result == initial_result) - memory = (char *) malloc (allocated); - else - memory = (char *) realloc (result, allocated); - if (memory == NULL) - { - if (result != initial_result) - free (result); - errno = ENOMEM; - return -1; - } - if (result == initial_result) - memcpy (memory, initial_result, length); - result = memory; - } - } - - /* Move the remaining bytes to the beginning of utf8buf. */ - if (in2size > 0) - memmove (utf8buf, in2ptr, in2size); - utf8len = in2size; - } - - if (res1 == (size_t)(-1)) - { - if (errno1 == EINVAL) - in1size = 0; - else if (errno1 == EILSEQ) - { - if (result != initial_result) - free (result); - errno = errno1; - return -1; - } - } + if (res == (size_t)(-1)) + { + /* Failure converting the ASCII replacement. */ + if (result != initial_result) + { + int saved_errno = errno; + free (result); + errno = saved_errno; + } + return -1; + } + } + else + { + if (result != initial_result) + { + int saved_errno = errno; + free (result); + errno = saved_errno; + } + return -1; + } + } + if (!(in2size > 0 + || (in1size == 0 && !do_final_flush1 && do_final_flush2))) + break; + if (grow) + { + char *memory; + + allocated = 2 * allocated; + if (result == initial_result) + memory = (char *) malloc (allocated); + else + memory = (char *) realloc (result, allocated); + if (memory == NULL) + { + if (result != initial_result) + free (result); + errno = ENOMEM; + return -1; + } + if (result == initial_result) + memcpy (memory, initial_result, length); + result = memory; + } + } + + /* Move the remaining bytes to the beginning of utf8buf. */ + if (in2size > 0) + memmove (utf8buf, in2ptr, in2size); + utf8len = in2size; + } + + if (res1 == (size_t)(-1)) + { + if (errno1 == EINVAL) + in1size = 0; + else if (errno1 == EILSEQ) + { + if (result != initial_result) + free (result); + errno = errno1; + return -1; + } + } } # undef utf8bufsize } @@ -884,14 +974,14 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, memory = (char *) malloc (memsize > 0 ? memsize : 1); if (memory != NULL) - { - memcpy (memory, tmpbuf, length); - result = memory; - } + { + memcpy (memory, tmpbuf, length); + result = memory; + } else - { - errno = ENOMEM; - return -1; + { + errno = ENOMEM; + return -1; } } else if (result != *resultp && length + extra_alloc < allocated) @@ -902,7 +992,7 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, memory = (char *) realloc (result, memsize > 0 ? memsize : 1); if (memory != NULL) - result = memory; + result = memory; } *resultp = result; *lengthp = length; @@ -913,19 +1003,19 @@ mem_cd_iconveh_internal (const char *src, size_t srclen, int mem_cd_iconveh (const char *src, size_t srclen, - iconv_t cd, iconv_t cd1, iconv_t cd2, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp) + const iconveh_t *cd, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp) { - return mem_cd_iconveh_internal (src, srclen, cd, cd1, cd2, handler, 0, - offsets, resultp, lengthp); + return mem_cd_iconveh_internal (src, srclen, cd->cd, cd->cd1, cd->cd2, + handler, 0, offsets, resultp, lengthp); } char * str_cd_iconveh (const char *src, - iconv_t cd, iconv_t cd1, iconv_t cd2, - enum iconv_ilseq_handler handler) + const iconveh_t *cd, + enum iconv_ilseq_handler handler) { /* For most encodings, a trailing NUL byte in the input will be converted to a trailing NUL byte in the output. But not for UTF-7. So that this @@ -934,17 +1024,17 @@ str_cd_iconveh (const char *src, char *result = NULL; size_t length = 0; int retval = mem_cd_iconveh_internal (src, strlen (src), - cd, cd1, cd2, handler, 1, NULL, - &result, &length); + cd->cd, cd->cd1, cd->cd2, handler, 1, + NULL, &result, &length); if (retval < 0) { if (result != NULL) - { - int saved_errno = errno; - free (result); - errno = saved_errno; - } + { + int saved_errno = errno; + free (result); + errno = saved_errno; + } return NULL; } @@ -958,10 +1048,10 @@ str_cd_iconveh (const char *src, int mem_iconveh (const char *src, size_t srclen, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp) + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp) { if (srclen == 0) { @@ -974,16 +1064,16 @@ mem_iconveh (const char *src, size_t srclen, char *result; if (*resultp != NULL && *lengthp >= srclen) - result = *resultp; + result = *resultp; else - { - result = (char *) malloc (srclen); - if (result == NULL) - { - errno = ENOMEM; - return -1; - } - } + { + result = (char *) malloc (srclen); + if (result == NULL) + { + errno = ENOMEM; + return -1; + } + } memcpy (result, src, srclen); *resultp = result; *lengthp = srclen; @@ -992,126 +1082,48 @@ mem_iconveh (const char *src, size_t srclen, else { #if HAVE_ICONV - iconv_t cd; - iconv_t cd1; - iconv_t cd2; + iconveh_t cd; char *result; size_t length; int retval; - /* Avoid glibc-2.1 bug with EUC-KR. */ -# if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION - if (c_strcasecmp (from_codeset, "EUC-KR") == 0 - || c_strcasecmp (to_codeset, "EUC-KR") == 0) - { - errno = EINVAL; - return -1; - } -# endif - - cd = iconv_open (to_codeset, from_codeset); - - if (STRCASEEQ (from_codeset, "UTF-8", 'U','T','F','-','8',0,0,0,0)) - cd1 = (iconv_t)(-1); - else - { - cd1 = iconv_open ("UTF-8", from_codeset); - if (cd1 == (iconv_t)(-1)) - { - int saved_errno = errno; - if (cd != (iconv_t)(-1)) - iconv_close (cd); - errno = saved_errno; - return -1; - } - } - - if (STRCASEEQ (to_codeset, "UTF-8", 'U','T','F','-','8',0,0,0,0) -# if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 || _LIBICONV_VERSION >= 0x0105 - || c_strcasecmp (to_codeset, "UTF-8//TRANSLIT") == 0 -# endif - ) - cd2 = (iconv_t)(-1); - else - { - cd2 = iconv_open (to_codeset, "UTF-8"); - if (cd2 == (iconv_t)(-1)) - { - int saved_errno = errno; - if (cd1 != (iconv_t)(-1)) - iconv_close (cd1); - if (cd != (iconv_t)(-1)) - iconv_close (cd); - errno = saved_errno; - return -1; - } - } + if (iconveh_open (to_codeset, from_codeset, &cd) < 0) + return -1; result = *resultp; length = *lengthp; - retval = mem_cd_iconveh (src, srclen, cd, cd1, cd2, handler, offsets, - &result, &length); + retval = mem_cd_iconveh (src, srclen, &cd, handler, offsets, + &result, &length); if (retval < 0) - { - /* Close cd, cd1, cd2, but preserve the errno from str_cd_iconv. */ - int saved_errno = errno; - if (cd2 != (iconv_t)(-1)) - iconv_close (cd2); - if (cd1 != (iconv_t)(-1)) - iconv_close (cd1); - if (cd != (iconv_t)(-1)) - iconv_close (cd); - errno = saved_errno; - } + { + /* Close cd, but preserve the errno from str_cd_iconv. */ + int saved_errno = errno; + iconveh_close (&cd); + errno = saved_errno; + } else - { - if (cd2 != (iconv_t)(-1) && iconv_close (cd2) < 0) - { - /* Return -1, but free the allocated memory, and while doing - that, preserve the errno from iconv_close. */ - int saved_errno = errno; - if (cd1 != (iconv_t)(-1)) - iconv_close (cd1); - if (cd != (iconv_t)(-1)) - iconv_close (cd); - if (result != *resultp && result != NULL) - free (result); - errno = saved_errno; - return -1; - } - if (cd1 != (iconv_t)(-1) && iconv_close (cd1) < 0) - { - /* Return -1, but free the allocated memory, and while doing - that, preserve the errno from iconv_close. */ - int saved_errno = errno; - if (cd != (iconv_t)(-1)) - iconv_close (cd); - if (result != *resultp && result != NULL) - free (result); - errno = saved_errno; - return -1; - } - if (cd != (iconv_t)(-1) && iconv_close (cd) < 0) - { - /* Return -1, but free the allocated memory, and while doing - that, preserve the errno from iconv_close. */ - int saved_errno = errno; - if (result != *resultp && result != NULL) - free (result); - errno = saved_errno; - return -1; - } - *resultp = result; - *lengthp = length; - } + { + if (iconveh_close (&cd) < 0) + { + /* Return -1, but free the allocated memory, and while doing + that, preserve the errno from iconveh_close. */ + int saved_errno = errno; + if (result != *resultp && result != NULL) + free (result); + errno = saved_errno; + return -1; + } + *resultp = result; + *lengthp = length; + } return retval; #else /* This is a different error code than if iconv_open existed but didn't - support from_codeset and to_codeset, so that the caller can emit - an error message such as - "iconv() is not supported. Installing GNU libiconv and - then reinstalling this package would fix this." */ + support from_codeset and to_codeset, so that the caller can emit + an error message such as + "iconv() is not supported. Installing GNU libiconv and + then reinstalling this package would fix this." */ errno = ENOSYS; return -1; #endif @@ -1120,130 +1132,54 @@ mem_iconveh (const char *src, size_t srclen, char * str_iconveh (const char *src, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler) + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler) { if (*src == '\0' || c_strcasecmp (from_codeset, to_codeset) == 0) { char *result = strdup (src); if (result == NULL) - errno = ENOMEM; + errno = ENOMEM; return result; } else { #if HAVE_ICONV - iconv_t cd; - iconv_t cd1; - iconv_t cd2; + iconveh_t cd; char *result; - /* Avoid glibc-2.1 bug with EUC-KR. */ -# if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION - if (c_strcasecmp (from_codeset, "EUC-KR") == 0 - || c_strcasecmp (to_codeset, "EUC-KR") == 0) - { - errno = EINVAL; - return NULL; - } -# endif - - cd = iconv_open (to_codeset, from_codeset); + if (iconveh_open (to_codeset, from_codeset, &cd) < 0) + return NULL; - if (STRCASEEQ (from_codeset, "UTF-8", 'U','T','F','-','8',0,0,0,0)) - cd1 = (iconv_t)(-1); - else - { - cd1 = iconv_open ("UTF-8", from_codeset); - if (cd1 == (iconv_t)(-1)) - { - int saved_errno = errno; - if (cd != (iconv_t)(-1)) - iconv_close (cd); - errno = saved_errno; - return NULL; - } - } - - if (STRCASEEQ (to_codeset, "UTF-8", 'U','T','F','-','8',0,0,0,0) -# if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 || _LIBICONV_VERSION >= 0x0105 - || c_strcasecmp (to_codeset, "UTF-8//TRANSLIT") == 0 -# endif - ) - cd2 = (iconv_t)(-1); - else - { - cd2 = iconv_open (to_codeset, "UTF-8"); - if (cd2 == (iconv_t)(-1)) - { - int saved_errno = errno; - if (cd1 != (iconv_t)(-1)) - iconv_close (cd1); - if (cd != (iconv_t)(-1)) - iconv_close (cd); - errno = saved_errno; - return NULL; - } - } - - result = str_cd_iconveh (src, cd, cd1, cd2, handler); + result = str_cd_iconveh (src, &cd, handler); if (result == NULL) - { - /* Close cd, cd1, cd2, but preserve the errno from str_cd_iconv. */ - int saved_errno = errno; - if (cd2 != (iconv_t)(-1)) - iconv_close (cd2); - if (cd1 != (iconv_t)(-1)) - iconv_close (cd1); - if (cd != (iconv_t)(-1)) - iconv_close (cd); - errno = saved_errno; - } + { + /* Close cd, but preserve the errno from str_cd_iconv. */ + int saved_errno = errno; + iconveh_close (&cd); + errno = saved_errno; + } else - { - if (cd2 != (iconv_t)(-1) && iconv_close (cd2) < 0) - { - /* Return NULL, but free the allocated memory, and while doing - that, preserve the errno from iconv_close. */ - int saved_errno = errno; - if (cd1 != (iconv_t)(-1)) - iconv_close (cd1); - if (cd != (iconv_t)(-1)) - iconv_close (cd); - free (result); - errno = saved_errno; - return NULL; - } - if (cd1 != (iconv_t)(-1) && iconv_close (cd1) < 0) - { - /* Return NULL, but free the allocated memory, and while doing - that, preserve the errno from iconv_close. */ - int saved_errno = errno; - if (cd != (iconv_t)(-1)) - iconv_close (cd); - free (result); - errno = saved_errno; - return NULL; - } - if (cd != (iconv_t)(-1) && iconv_close (cd) < 0) - { - /* Return NULL, but free the allocated memory, and while doing - that, preserve the errno from iconv_close. */ - int saved_errno = errno; - free (result); - errno = saved_errno; - return NULL; - } - } + { + if (iconveh_close (&cd) < 0) + { + /* Return NULL, but free the allocated memory, and while doing + that, preserve the errno from iconveh_close. */ + int saved_errno = errno; + free (result); + errno = saved_errno; + return NULL; + } + } return result; #else /* This is a different error code than if iconv_open existed but didn't - support from_codeset and to_codeset, so that the caller can emit - an error message such as - "iconv() is not supported. Installing GNU libiconv and - then reinstalling this package would fix this." */ + support from_codeset and to_codeset, so that the caller can emit + an error message such as + "iconv() is not supported. Installing GNU libiconv and + then reinstalling this package would fix this." */ errno = ENOSYS; return NULL; #endif diff --git a/lib/striconveh.h b/lib/striconveh.h index 98b4d0c5..dc92ceac 100644 --- a/lib/striconveh.h +++ b/lib/striconveh.h @@ -1,5 +1,5 @@ /* Character set conversion with error handling. - Copyright (C) 2001-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2001-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible and Simon Josefsson. This program is free software: you can redistribute it and/or modify @@ -33,14 +33,38 @@ extern "C" { #if HAVE_ICONV +/* An conversion descriptor for use by the iconveh functions. */ +typedef struct + { + /* Conversion descriptor from FROM_CODESET to TO_CODESET, or (iconv_t)(-1) + if the system does not support a direct conversion from FROM_CODESET to + TO_CODESET. */ + iconv_t cd; + /* Conversion descriptor from FROM_CODESET to UTF-8 (or (iconv_t)(-1) if + FROM_CODESET is UTF-8). */ + iconv_t cd1; + /* Conversion descriptor from UTF-8 to TO_CODESET (or (iconv_t)(-1) if + TO_CODESET is UTF-8). */ + iconv_t cd2; + } + iconveh_t; + +/* Open a conversion descriptor for use by the iconveh functions. + If successful, fills *CDP and returns 0. Upon failure, return -1 with errno + set. */ +extern int + iconveh_open (const char *to_codeset, const char *from_codeset, + iconveh_t *cdp); + +/* Close a conversion descriptor created by iconveh_open(). + Return value: 0 if successful, otherwise -1 and errno set. */ +extern int + iconveh_close (const iconveh_t *cd); + /* Convert an entire string from one encoding to another, using iconv. The original string is at [SRC,...,SRC+SRCLEN-1]. - CD is the conversion descriptor from FROMCODE to TOCODE, or (iconv_t)(-1) if - the system does not support a direct conversion from FROMCODE to TOCODE. - CD1 is the conversion descriptor from FROM_CODESET to UTF-8 (or - (iconv_t)(-1) if FROM_CODESET is UTF-8). - CD2 is the conversion descriptor from UTF-8 to TO_CODESET (or (iconv_t)(-1) - if TO_CODESET is UTF-8). + CD points to the conversion descriptor from FROMCODE to TOCODE, created by + the function iconveh_open(). If OFFSETS is not NULL, it should point to an array of SRCLEN integers; this array is filled with offsets into the result, i.e. the character starting at SRC[i] corresponds to the character starting at (*RESULTP)[OFFSETS[i]], @@ -54,28 +78,24 @@ extern "C" { unchanged if no dynamic memory allocation was necessary. */ extern int mem_cd_iconveh (const char *src, size_t srclen, - iconv_t cd, iconv_t cd1, iconv_t cd2, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp); + const iconveh_t *cd, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp); /* Convert an entire string from one encoding to another, using iconv. The original string is the NUL-terminated string starting at SRC. - CD is the conversion descriptor from FROMCODE to TOCODE, or (iconv_t)(-1) if - the system does not support a direct conversion from FROMCODE to TOCODE. + CD points to the conversion descriptor from FROMCODE to TOCODE, created by + the function iconveh_open(). Both the "from" and the "to" encoding must use a single NUL byte at the end of the string (i.e. not UCS-2, UCS-4, UTF-16, UTF-32). - CD1 is the conversion descriptor from FROM_CODESET to UTF-8 (or - (iconv_t)(-1) if FROM_CODESET is UTF-8). - CD2 is the conversion descriptor from UTF-8 to TO_CODESET (or (iconv_t)(-1) - if TO_CODESET is UTF-8). Allocate a malloced memory block for the result. Return value: the freshly allocated resulting NUL-terminated string if successful, otherwise NULL and errno set. */ extern char * str_cd_iconveh (const char *src, - iconv_t cd, iconv_t cd1, iconv_t cd2, - enum iconv_ilseq_handler handler); + const iconveh_t *cd, + enum iconv_ilseq_handler handler); #endif @@ -94,10 +114,10 @@ extern char * unchanged if no dynamic memory allocation was necessary. */ extern int mem_iconveh (const char *src, size_t srclen, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp); + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp); /* Convert an entire string from one encoding to another, using iconv. The original string is the NUL-terminated string starting at SRC. @@ -108,8 +128,8 @@ extern int successful, otherwise NULL and errno set. */ extern char * str_iconveh (const char *src, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler); + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler); #ifdef __cplusplus diff --git a/lib/striconveha.c b/lib/striconveha.c index a0567b42..27e7b153 100644 --- a/lib/striconveha.c +++ b/lib/striconveha.c @@ -1,5 +1,5 @@ /* Character set conversion with error handling and autodetection. - Copyright (C) 2002, 2005, 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2005, 2007, 2009, 2010 Free Software Foundation, Inc. Written by Bruno Haible. This program is free software: you can redistribute it and/or modify @@ -82,7 +82,7 @@ static struct autodetect_alias **autodetect_list_end = int uniconv_register_autodetect (const char *name, - const char * const *try_in_order) + const char * const *try_in_order) { size_t namelen; size_t listlen; @@ -122,12 +122,12 @@ uniconv_register_autodetect (const char *name, memory += namelen; for (i = 0; i < listlen; i++) - { - size_t len = strlen (try_in_order[i]) + 1; - memcpy (memory, try_in_order[i], len); - new_try_in_order[i] = (const char *) memory; - memory += len; - } + { + size_t len = strlen (try_in_order[i]) + 1; + memcpy (memory, try_in_order[i], len); + new_try_in_order[i] = (const char *) memory; + memory += len; + } new_try_in_order[i] = NULL; /* Now insert the new alias. */ @@ -149,13 +149,13 @@ uniconv_register_autodetect (const char *name, /* Like mem_iconveha, except no handling of transliteration. */ static int mem_iconveha_notranslit (const char *src, size_t srclen, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp) + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp) { int retval = mem_iconveh (src, srclen, from_codeset, to_codeset, handler, - offsets, resultp, lengthp); + offsets, resultp, lengthp); if (retval >= 0 || errno != EINVAL) return retval; else @@ -163,45 +163,45 @@ mem_iconveha_notranslit (const char *src, size_t srclen, struct autodetect_alias *alias; /* Unsupported from_codeset or to_codeset. Check whether the caller - requested autodetection. */ + requested autodetection. */ for (alias = autodetect_list; alias != NULL; alias = alias->next) - if (strcmp (from_codeset, alias->name) == 0) - { - const char * const *encodings; - - if (handler != iconveh_error) - { - /* First try all encodings without any forgiving. */ - encodings = alias->encodings_to_try; - do - { - retval = mem_iconveha_notranslit (src, srclen, - *encodings, to_codeset, - iconveh_error, offsets, - resultp, lengthp); - if (!(retval < 0 && errno == EILSEQ)) - return retval; - encodings++; - } - while (*encodings != NULL); - } - - encodings = alias->encodings_to_try; - do - { - retval = mem_iconveha_notranslit (src, srclen, - *encodings, to_codeset, - handler, offsets, - resultp, lengthp); - if (!(retval < 0 && errno == EILSEQ)) - return retval; - encodings++; - } - while (*encodings != NULL); - - /* Return the last call's result. */ - return -1; - } + if (strcmp (from_codeset, alias->name) == 0) + { + const char * const *encodings; + + if (handler != iconveh_error) + { + /* First try all encodings without any forgiving. */ + encodings = alias->encodings_to_try; + do + { + retval = mem_iconveha_notranslit (src, srclen, + *encodings, to_codeset, + iconveh_error, offsets, + resultp, lengthp); + if (!(retval < 0 && errno == EILSEQ)) + return retval; + encodings++; + } + while (*encodings != NULL); + } + + encodings = alias->encodings_to_try; + do + { + retval = mem_iconveha_notranslit (src, srclen, + *encodings, to_codeset, + handler, offsets, + resultp, lengthp); + if (!(retval < 0 && errno == EILSEQ)) + return retval; + encodings++; + } + while (*encodings != NULL); + + /* Return the last call's result. */ + return -1; + } /* It wasn't an autodetection name. */ errno = EINVAL; @@ -211,11 +211,11 @@ mem_iconveha_notranslit (const char *src, size_t srclen, int mem_iconveha (const char *src, size_t srclen, - const char *from_codeset, const char *to_codeset, - bool transliterate, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp) + const char *from_codeset, const char *to_codeset, + bool transliterate, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp) { if (srclen == 0) { @@ -236,8 +236,8 @@ mem_iconveha (const char *src, size_t srclen, memcpy (to_codeset_suffixed + len, "//TRANSLIT", 10 + 1); retval = mem_iconveha_notranslit (src, srclen, - from_codeset, to_codeset_suffixed, - handler, offsets, resultp, lengthp); + from_codeset, to_codeset_suffixed, + handler, offsets, resultp, lengthp); freea (to_codeset_suffixed); @@ -246,15 +246,15 @@ mem_iconveha (const char *src, size_t srclen, else #endif return mem_iconveha_notranslit (src, srclen, - from_codeset, to_codeset, - handler, offsets, resultp, lengthp); + from_codeset, to_codeset, + handler, offsets, resultp, lengthp); } /* Like str_iconveha, except no handling of transliteration. */ static char * str_iconveha_notranslit (const char *src, - const char *from_codeset, const char *to_codeset, - enum iconv_ilseq_handler handler) + const char *from_codeset, const char *to_codeset, + enum iconv_ilseq_handler handler) { char *result = str_iconveh (src, from_codeset, to_codeset, handler); @@ -265,43 +265,43 @@ str_iconveha_notranslit (const char *src, struct autodetect_alias *alias; /* Unsupported from_codeset or to_codeset. Check whether the caller - requested autodetection. */ + requested autodetection. */ for (alias = autodetect_list; alias != NULL; alias = alias->next) - if (strcmp (from_codeset, alias->name) == 0) - { - const char * const *encodings; - - if (handler != iconveh_error) - { - /* First try all encodings without any forgiving. */ - encodings = alias->encodings_to_try; - do - { - result = str_iconveha_notranslit (src, - *encodings, to_codeset, - iconveh_error); - if (!(result == NULL && errno == EILSEQ)) - return result; - encodings++; - } - while (*encodings != NULL); - } - - encodings = alias->encodings_to_try; - do - { - result = str_iconveha_notranslit (src, - *encodings, to_codeset, - handler); - if (!(result == NULL && errno == EILSEQ)) - return result; - encodings++; - } - while (*encodings != NULL); - - /* Return the last call's result. */ - return NULL; - } + if (strcmp (from_codeset, alias->name) == 0) + { + const char * const *encodings; + + if (handler != iconveh_error) + { + /* First try all encodings without any forgiving. */ + encodings = alias->encodings_to_try; + do + { + result = str_iconveha_notranslit (src, + *encodings, to_codeset, + iconveh_error); + if (!(result == NULL && errno == EILSEQ)) + return result; + encodings++; + } + while (*encodings != NULL); + } + + encodings = alias->encodings_to_try; + do + { + result = str_iconveha_notranslit (src, + *encodings, to_codeset, + handler); + if (!(result == NULL && errno == EILSEQ)) + return result; + encodings++; + } + while (*encodings != NULL); + + /* Return the last call's result. */ + return NULL; + } /* It wasn't an autodetection name. */ errno = EINVAL; @@ -311,16 +311,16 @@ str_iconveha_notranslit (const char *src, char * str_iconveha (const char *src, - const char *from_codeset, const char *to_codeset, - bool transliterate, - enum iconv_ilseq_handler handler) + const char *from_codeset, const char *to_codeset, + bool transliterate, + enum iconv_ilseq_handler handler) { if (*src == '\0' || c_strcasecmp (from_codeset, to_codeset) == 0) { char *result = strdup (src); if (result == NULL) - errno = ENOMEM; + errno = ENOMEM; return result; } @@ -336,7 +336,7 @@ str_iconveha (const char *src, memcpy (to_codeset_suffixed + len, "//TRANSLIT", 10 + 1); result = str_iconveha_notranslit (src, from_codeset, to_codeset_suffixed, - handler); + handler); freea (to_codeset_suffixed); diff --git a/lib/striconveha.h b/lib/striconveha.h index c88eb52f..5f106c32 100644 --- a/lib/striconveha.h +++ b/lib/striconveha.h @@ -1,5 +1,5 @@ /* Character set conversion with error handling and autodetection. - Copyright (C) 2002, 2005, 2007-2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2005, 2007-2010 Free Software Foundation, Inc. Written by Bruno Haible. This program is free software: you can redistribute it and/or modify @@ -48,11 +48,11 @@ extern "C" { unchanged if no dynamic memory allocation was necessary. */ extern int mem_iconveha (const char *src, size_t srclen, - const char *from_codeset, const char *to_codeset, - bool transliterate, - enum iconv_ilseq_handler handler, - size_t *offsets, - char **resultp, size_t *lengthp); + const char *from_codeset, const char *to_codeset, + bool transliterate, + enum iconv_ilseq_handler handler, + size_t *offsets, + char **resultp, size_t *lengthp); /* Convert an entire string from one encoding to another, using iconv. The original string is the NUL-terminated string starting at SRC. @@ -67,9 +67,9 @@ extern int successful, otherwise NULL and errno set. */ extern char * str_iconveha (const char *src, - const char *from_codeset, const char *to_codeset, - bool transliterate, - enum iconv_ilseq_handler handler); + const char *from_codeset, const char *to_codeset, + bool transliterate, + enum iconv_ilseq_handler handler); /* In the above, FROM_CODESET can also be one of the following values: @@ -84,7 +84,7 @@ extern char * Particular errno values: ENOMEM. */ extern int uniconv_register_autodetect (const char *name, - const char * const *try_in_order); + const char * const *try_in_order); #ifdef __cplusplus diff --git a/lib/string.in.h b/lib/string.in.h index 35407658..75deca01 100644 --- a/lib/string.in.h +++ b/lib/string.in.h @@ -1,6 +1,6 @@ /* A GNU-like . - Copyright (C) 1995-1996, 2001-2009 Free Software Foundation, Inc. + Copyright (C) 1995-1996, 2001-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -31,6 +31,11 @@ /* NetBSD 5.0 mis-defines NULL. */ #include +/* MirBSD defines mbslen as a macro. */ +#if @GNULIB_MBSLEN@ && defined __MirBSD__ +# include +#endif + #ifndef __attribute__ /* This feature is available in gcc versions 2.5 and later. */ # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) @@ -43,75 +48,132 @@ #endif -/* The definition of GL_LINK_WARNING is copied here. */ +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ +/* The definition of _GL_ARG_NONNULL is copied here. */ -#ifdef __cplusplus -extern "C" { -#endif +/* The definition of _GL_WARN_ON_USE is copied here. */ /* Return the first instance of C within N bytes of S, or NULL. */ #if @GNULIB_MEMCHR@ # if @REPLACE_MEMCHR@ -# define memchr rpl_memchr -extern void *memchr (void const *__s, int __c, size_t __n) - __attribute__ ((__pure__)); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define memchr rpl_memchr +# endif +_GL_FUNCDECL_RPL (memchr, void *, (void const *__s, int __c, size_t __n) + __attribute__ ((__pure__)) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (memchr, void *, (void const *__s, int __c, size_t __n)); +# else +# if ! @HAVE_MEMCHR@ +_GL_FUNCDECL_SYS (memchr, void *, (void const *__s, int __c, size_t __n) + __attribute__ ((__pure__)) + _GL_ARG_NONNULL ((1))); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C" { const void * std::memchr (const void *, int, size_t); } + extern "C++" { void * std::memchr (void *, int, size_t); } */ +_GL_CXXALIAS_SYS_CAST2 (memchr, + void *, (void const *__s, int __c, size_t __n), + void const *, (void const *__s, int __c, size_t __n)); +# endif +# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (memchr, void *, (void *__s, int __c, size_t __n)); +_GL_CXXALIASWARN1 (memchr, void const *, + (void const *__s, int __c, size_t __n)); +# else +_GL_CXXALIASWARN (memchr); # endif #elif defined GNULIB_POSIXCHECK # undef memchr -# define memchr(s,c,n) \ - (GL_LINK_WARNING ("memchr has platform-specific bugs - " \ - "use gnulib module memchr for portability" ), \ - memchr (s, c, n)) +/* Assume memchr is always declared. */ +_GL_WARN_ON_USE (memchr, "memchr has platform-specific bugs - " + "use gnulib module memchr for portability" ); #endif /* Return the first occurrence of NEEDLE in HAYSTACK. */ #if @GNULIB_MEMMEM@ # if @REPLACE_MEMMEM@ -# define memmem rpl_memmem -# endif -# if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@ -extern void *memmem (void const *__haystack, size_t __haystack_len, - void const *__needle, size_t __needle_len) - __attribute__ ((__pure__)); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define memmem rpl_memmem +# endif +_GL_FUNCDECL_RPL (memmem, void *, + (void const *__haystack, size_t __haystack_len, + void const *__needle, size_t __needle_len) + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3))); +_GL_CXXALIAS_RPL (memmem, void *, + (void const *__haystack, size_t __haystack_len, + void const *__needle, size_t __needle_len)); +# else +# if ! @HAVE_DECL_MEMMEM@ +_GL_FUNCDECL_SYS (memmem, void *, + (void const *__haystack, size_t __haystack_len, + void const *__needle, size_t __needle_len) + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 3))); +# endif +_GL_CXXALIAS_SYS (memmem, void *, + (void const *__haystack, size_t __haystack_len, + void const *__needle, size_t __needle_len)); # endif +_GL_CXXALIASWARN (memmem); #elif defined GNULIB_POSIXCHECK # undef memmem -# define memmem(a,al,b,bl) \ - (GL_LINK_WARNING ("memmem is unportable and often quadratic - " \ - "use gnulib module memmem-simple for portability, " \ - "and module memmem for speed" ), \ - memmem (a, al, b, bl)) +# if HAVE_RAW_DECL_MEMMEM +_GL_WARN_ON_USE (memmem, "memmem is unportable and often quadratic - " + "use gnulib module memmem-simple for portability, " + "and module memmem for speed" ); +# endif #endif /* Copy N bytes of SRC to DEST, return pointer to bytes after the last written byte. */ #if @GNULIB_MEMPCPY@ # if ! @HAVE_MEMPCPY@ -extern void *mempcpy (void *restrict __dest, void const *restrict __src, - size_t __n); +_GL_FUNCDECL_SYS (mempcpy, void *, + (void *restrict __dest, void const *restrict __src, + size_t __n) + _GL_ARG_NONNULL ((1, 2))); # endif +_GL_CXXALIAS_SYS (mempcpy, void *, + (void *restrict __dest, void const *restrict __src, + size_t __n)); +_GL_CXXALIASWARN (mempcpy); #elif defined GNULIB_POSIXCHECK # undef mempcpy -# define mempcpy(a,b,n) \ - (GL_LINK_WARNING ("mempcpy is unportable - " \ - "use gnulib module mempcpy for portability"), \ - mempcpy (a, b, n)) +# if HAVE_RAW_DECL_MEMPCPY +_GL_WARN_ON_USE (mempcpy, "mempcpy is unportable - " + "use gnulib module mempcpy for portability"); +# endif #endif /* Search backwards through a block for a byte (specified as an int). */ #if @GNULIB_MEMRCHR@ # if ! @HAVE_DECL_MEMRCHR@ -extern void *memrchr (void const *, int, size_t) - __attribute__ ((__pure__)); +_GL_FUNCDECL_SYS (memrchr, void *, (void const *, int, size_t) + __attribute__ ((__pure__)) + _GL_ARG_NONNULL ((1))); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { const void * std::memrchr (const void *, int, size_t); } + extern "C++" { void * std::memrchr (void *, int, size_t); } */ +_GL_CXXALIAS_SYS_CAST2 (memrchr, + void *, (void const *, int, size_t), + void const *, (void const *, int, size_t)); +# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (memrchr, void *, (void *, int, size_t)); +_GL_CXXALIASWARN1 (memrchr, void const *, (void const *, int, size_t)); +# else +_GL_CXXALIASWARN (memrchr); # endif #elif defined GNULIB_POSIXCHECK # undef memrchr -# define memrchr(a,b,c) \ - (GL_LINK_WARNING ("memrchr is unportable - " \ - "use gnulib module memrchr for portability"), \ - memrchr (a, b, c)) +# if HAVE_RAW_DECL_MEMRCHR +_GL_WARN_ON_USE (memrchr, "memrchr is unportable - " + "use gnulib module memrchr for portability"); +# endif #endif /* Find the first occurrence of C in S. More efficient than @@ -119,119 +181,221 @@ extern void *memrchr (void const *, int, size_t) occur within N bytes. */ #if @GNULIB_RAWMEMCHR@ # if ! @HAVE_RAWMEMCHR@ -extern void *rawmemchr (void const *__s, int __c_in) - __attribute__ ((__pure__)); +_GL_FUNCDECL_SYS (rawmemchr, void *, (void const *__s, int __c_in) + __attribute__ ((__pure__)) + _GL_ARG_NONNULL ((1))); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { const void * std::rawmemchr (const void *, int); } + extern "C++" { void * std::rawmemchr (void *, int); } */ +_GL_CXXALIAS_SYS_CAST2 (rawmemchr, + void *, (void const *__s, int __c_in), + void const *, (void const *__s, int __c_in)); +# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (rawmemchr, void *, (void *__s, int __c_in)); +_GL_CXXALIASWARN1 (rawmemchr, void const *, (void const *__s, int __c_in)); +# else +_GL_CXXALIASWARN (rawmemchr); # endif #elif defined GNULIB_POSIXCHECK # undef rawmemchr -# define rawmemchr(a,b) \ - (GL_LINK_WARNING ("rawmemchr is unportable - " \ - "use gnulib module rawmemchr for portability"), \ - rawmemchr (a, b)) +# if HAVE_RAW_DECL_RAWMEMCHR +_GL_WARN_ON_USE (rawmemchr, "rawmemchr is unportable - " + "use gnulib module rawmemchr for portability"); +# endif #endif /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ #if @GNULIB_STPCPY@ # if ! @HAVE_STPCPY@ -extern char *stpcpy (char *restrict __dst, char const *restrict __src); +_GL_FUNCDECL_SYS (stpcpy, char *, + (char *restrict __dst, char const *restrict __src) + _GL_ARG_NONNULL ((1, 2))); # endif +_GL_CXXALIAS_SYS (stpcpy, char *, + (char *restrict __dst, char const *restrict __src)); +_GL_CXXALIASWARN (stpcpy); #elif defined GNULIB_POSIXCHECK # undef stpcpy -# define stpcpy(a,b) \ - (GL_LINK_WARNING ("stpcpy is unportable - " \ - "use gnulib module stpcpy for portability"), \ - stpcpy (a, b)) +# if HAVE_RAW_DECL_STPCPY +_GL_WARN_ON_USE (stpcpy, "stpcpy is unportable - " + "use gnulib module stpcpy for portability"); +# endif #endif /* Copy no more than N bytes of SRC to DST, returning a pointer past the last non-NUL byte written into DST. */ #if @GNULIB_STPNCPY@ -# if ! @HAVE_STPNCPY@ -# define stpncpy gnu_stpncpy -extern char *stpncpy (char *restrict __dst, char const *restrict __src, - size_t __n); +# if @REPLACE_STPNCPY@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define stpncpy rpl_stpncpy +# endif +_GL_FUNCDECL_RPL (stpncpy, char *, + (char *restrict __dst, char const *restrict __src, + size_t __n) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (stpncpy, char *, + (char *restrict __dst, char const *restrict __src, + size_t __n)); +# else +# if ! @HAVE_STPNCPY@ +_GL_FUNCDECL_SYS (stpncpy, char *, + (char *restrict __dst, char const *restrict __src, + size_t __n) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (stpncpy, char *, + (char *restrict __dst, char const *restrict __src, + size_t __n)); # endif +_GL_CXXALIASWARN (stpncpy); #elif defined GNULIB_POSIXCHECK # undef stpncpy -# define stpncpy(a,b,n) \ - (GL_LINK_WARNING ("stpncpy is unportable - " \ - "use gnulib module stpncpy for portability"), \ - stpncpy (a, b, n)) +# if HAVE_RAW_DECL_STPNCPY +_GL_WARN_ON_USE (stpncpy, "stpncpy is unportable - " + "use gnulib module stpncpy for portability"); +# endif #endif #if defined GNULIB_POSIXCHECK /* strchr() does not work with multibyte strings if the locale encoding is GB18030 and the character to be searched is a digit. */ # undef strchr -# define strchr(s,c) \ - (GL_LINK_WARNING ("strchr cannot work correctly on character strings " \ - "in some multibyte locales - " \ - "use mbschr if you care about internationalization"), \ - strchr (s, c)) +/* Assume strchr is always declared. */ +_GL_WARN_ON_USE (strchr, "strchr cannot work correctly on character strings " + "in some multibyte locales - " + "use mbschr if you care about internationalization"); #endif /* Find the first occurrence of C in S or the final NUL byte. */ #if @GNULIB_STRCHRNUL@ # if ! @HAVE_STRCHRNUL@ -extern char *strchrnul (char const *__s, int __c_in) - __attribute__ ((__pure__)); +_GL_FUNCDECL_SYS (strchrnul, char *, (char const *__s, int __c_in) + __attribute__ ((__pure__)) + _GL_ARG_NONNULL ((1))); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { const char * std::strchrnul (const char *, int); } + extern "C++" { char * std::strchrnul (char *, int); } */ +_GL_CXXALIAS_SYS_CAST2 (strchrnul, + char *, (char const *__s, int __c_in), + char const *, (char const *__s, int __c_in)); +# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (strchrnul, char *, (char *__s, int __c_in)); +_GL_CXXALIASWARN1 (strchrnul, char const *, (char const *__s, int __c_in)); +# else +_GL_CXXALIASWARN (strchrnul); # endif #elif defined GNULIB_POSIXCHECK # undef strchrnul -# define strchrnul(a,b) \ - (GL_LINK_WARNING ("strchrnul is unportable - " \ - "use gnulib module strchrnul for portability"), \ - strchrnul (a, b)) +# if HAVE_RAW_DECL_STRCHRNUL +_GL_WARN_ON_USE (strchrnul, "strchrnul is unportable - " + "use gnulib module strchrnul for portability"); +# endif #endif /* Duplicate S, returning an identical malloc'd string. */ #if @GNULIB_STRDUP@ # if @REPLACE_STRDUP@ -# undef strdup -# define strdup rpl_strdup -# endif -# if !(@HAVE_DECL_STRDUP@ || defined strdup) || @REPLACE_STRDUP@ -extern char *strdup (char const *__s); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strdup +# define strdup rpl_strdup +# endif +_GL_FUNCDECL_RPL (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (strdup, char *, (char const *__s)); +# else +# if !(@HAVE_DECL_STRDUP@ || defined strdup) +_GL_FUNCDECL_SYS (strdup, char *, (char const *__s) _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (strdup, char *, (char const *__s)); # endif +_GL_CXXALIASWARN (strdup); #elif defined GNULIB_POSIXCHECK # undef strdup -# define strdup(a) \ - (GL_LINK_WARNING ("strdup is unportable - " \ - "use gnulib module strdup for portability"), \ - strdup (a)) +# if HAVE_RAW_DECL_STRDUP +_GL_WARN_ON_USE (strdup, "strdup is unportable - " + "use gnulib module strdup for portability"); +# endif +#endif + +/* Append no more than N characters from SRC onto DEST. */ +#if @GNULIB_STRNCAT@ +# if @REPLACE_STRNCAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strncat +# define strncat rpl_strncat +# endif +_GL_FUNCDECL_RPL (strncat, char *, (char *dest, const char *src, size_t n) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (strncat, char *, (char *dest, const char *src, size_t n)); +# else +_GL_CXXALIAS_SYS (strncat, char *, (char *dest, const char *src, size_t n)); +# endif +_GL_CXXALIASWARN (strncat); +#elif defined GNULIB_POSIXCHECK +# undef strncat +# if HAVE_RAW_DECL_STRNCAT +_GL_WARN_ON_USE (strncat, "strncat is unportable - " + "use gnulib module strncat for portability"); +# endif #endif /* Return a newly allocated copy of at most N bytes of STRING. */ #if @GNULIB_STRNDUP@ -# if ! @HAVE_STRNDUP@ -# undef strndup -# define strndup rpl_strndup -# endif -# if ! @HAVE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@ -extern char *strndup (char const *__string, size_t __n); +# if @REPLACE_STRNDUP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strndup +# define strndup rpl_strndup +# endif +_GL_FUNCDECL_RPL (strndup, char *, (char const *__string, size_t __n) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (strndup, char *, (char const *__string, size_t __n)); +# else +# if ! @HAVE_DECL_STRNDUP@ +_GL_FUNCDECL_SYS (strndup, char *, (char const *__string, size_t __n) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (strndup, char *, (char const *__string, size_t __n)); # endif +_GL_CXXALIASWARN (strndup); #elif defined GNULIB_POSIXCHECK # undef strndup -# define strndup(a,n) \ - (GL_LINK_WARNING ("strndup is unportable - " \ - "use gnulib module strndup for portability"), \ - strndup (a, n)) +# if HAVE_RAW_DECL_STRNDUP +_GL_WARN_ON_USE (strndup, "strndup is unportable - " + "use gnulib module strndup for portability"); +# endif #endif /* Find the length (number of bytes) of STRING, but scan at most MAXLEN bytes. If no '\0' terminator is found in that many bytes, return MAXLEN. */ #if @GNULIB_STRNLEN@ -# if ! @HAVE_DECL_STRNLEN@ -extern size_t strnlen (char const *__string, size_t __maxlen) - __attribute__ ((__pure__)); +# if @REPLACE_STRNLEN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strnlen +# define strnlen rpl_strnlen +# endif +_GL_FUNCDECL_RPL (strnlen, size_t, (char const *__string, size_t __maxlen) + __attribute__ ((__pure__)) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (strnlen, size_t, (char const *__string, size_t __maxlen)); +# else +# if ! @HAVE_DECL_STRNLEN@ +_GL_FUNCDECL_SYS (strnlen, size_t, (char const *__string, size_t __maxlen) + __attribute__ ((__pure__)) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (strnlen, size_t, (char const *__string, size_t __maxlen)); # endif +_GL_CXXALIASWARN (strnlen); #elif defined GNULIB_POSIXCHECK # undef strnlen -# define strnlen(a,n) \ - (GL_LINK_WARNING ("strnlen is unportable - " \ - "use gnulib module strnlen for portability"), \ - strnlen (a, n)) +# if HAVE_RAW_DECL_STRNLEN +_GL_WARN_ON_USE (strnlen, "strnlen is unportable - " + "use gnulib module strnlen for portability"); +# endif #endif #if defined GNULIB_POSIXCHECK @@ -240,18 +404,32 @@ extern size_t strnlen (char const *__string, size_t __maxlen) locale encoding is GB18030 and one of the characters to be searched is a digit. */ # undef strcspn -# define strcspn(s,a) \ - (GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \ - "in multibyte locales - " \ - "use mbscspn if you care about internationalization"), \ - strcspn (s, a)) +/* Assume strcspn is always declared. */ +_GL_WARN_ON_USE (strcspn, "strcspn cannot work correctly on character strings " + "in multibyte locales - " + "use mbscspn if you care about internationalization"); #endif /* Find the first occurrence in S of any character in ACCEPT. */ #if @GNULIB_STRPBRK@ # if ! @HAVE_STRPBRK@ -extern char *strpbrk (char const *__s, char const *__accept) - __attribute__ ((__pure__)); +_GL_FUNCDECL_SYS (strpbrk, char *, (char const *__s, char const *__accept) + __attribute__ ((__pure__)) + _GL_ARG_NONNULL ((1, 2))); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C" { const char * strpbrk (const char *, const char *); } + extern "C++" { char * strpbrk (char *, const char *); } */ +_GL_CXXALIAS_SYS_CAST2 (strpbrk, + char *, (char const *__s, char const *__accept), + const char *, (char const *__s, char const *__accept)); +# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (strpbrk, char *, (char *__s, char const *__accept)); +_GL_CXXALIASWARN1 (strpbrk, char const *, + (char const *__s, char const *__accept)); +# else +_GL_CXXALIASWARN (strpbrk); # endif # if defined GNULIB_POSIXCHECK /* strpbrk() assumes the second argument is a list of single-byte characters. @@ -259,40 +437,36 @@ extern char *strpbrk (char const *__s, char const *__accept) locale encoding is GB18030 and one of the characters to be searched is a digit. */ # undef strpbrk -# define strpbrk(s,a) \ - (GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \ - "in multibyte locales - " \ - "use mbspbrk if you care about internationalization"), \ - strpbrk (s, a)) +_GL_WARN_ON_USE (strpbrk, "strpbrk cannot work correctly on character strings " + "in multibyte locales - " + "use mbspbrk if you care about internationalization"); # endif #elif defined GNULIB_POSIXCHECK # undef strpbrk -# define strpbrk(s,a) \ - (GL_LINK_WARNING ("strpbrk is unportable - " \ - "use gnulib module strpbrk for portability"), \ - strpbrk (s, a)) +# if HAVE_RAW_DECL_STRPBRK +_GL_WARN_ON_USE (strpbrk, "strpbrk is unportable - " + "use gnulib module strpbrk for portability"); +# endif #endif #if defined GNULIB_POSIXCHECK /* strspn() assumes the second argument is a list of single-byte characters. Even in this simple case, it cannot work with multibyte strings. */ # undef strspn -# define strspn(s,a) \ - (GL_LINK_WARNING ("strspn cannot work correctly on character strings " \ - "in multibyte locales - " \ - "use mbsspn if you care about internationalization"), \ - strspn (s, a)) +/* Assume strspn is always declared. */ +_GL_WARN_ON_USE (strspn, "strspn cannot work correctly on character strings " + "in multibyte locales - " + "use mbsspn if you care about internationalization"); #endif #if defined GNULIB_POSIXCHECK /* strrchr() does not work with multibyte strings if the locale encoding is GB18030 and the character to be searched is a digit. */ # undef strrchr -# define strrchr(s,c) \ - (GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \ - "in some multibyte locales - " \ - "use mbsrchr if you care about internationalization"), \ - strrchr (s, c)) +/* Assume strrchr is always declared. */ +_GL_WARN_ON_USE (strrchr, "strrchr cannot work correctly on character strings " + "in some multibyte locales - " + "use mbsrchr if you care about internationalization"); #endif /* Search the next delimiter (char listed in DELIM) starting at *STRINGP. @@ -313,29 +487,51 @@ extern char *strpbrk (char const *__s, char const *__accept) See also strtok_r(). */ #if @GNULIB_STRSEP@ # if ! @HAVE_STRSEP@ -extern char *strsep (char **restrict __stringp, char const *restrict __delim); +_GL_FUNCDECL_SYS (strsep, char *, + (char **restrict __stringp, char const *restrict __delim) + _GL_ARG_NONNULL ((1, 2))); # endif +_GL_CXXALIAS_SYS (strsep, char *, + (char **restrict __stringp, char const *restrict __delim)); +_GL_CXXALIASWARN (strsep); # if defined GNULIB_POSIXCHECK # undef strsep -# define strsep(s,d) \ - (GL_LINK_WARNING ("strsep cannot work correctly on character strings " \ - "in multibyte locales - " \ - "use mbssep if you care about internationalization"), \ - strsep (s, d)) +_GL_WARN_ON_USE (strsep, "strsep cannot work correctly on character strings " + "in multibyte locales - " + "use mbssep if you care about internationalization"); # endif #elif defined GNULIB_POSIXCHECK # undef strsep -# define strsep(s,d) \ - (GL_LINK_WARNING ("strsep is unportable - " \ - "use gnulib module strsep for portability"), \ - strsep (s, d)) +# if HAVE_RAW_DECL_STRSEP +_GL_WARN_ON_USE (strsep, "strsep is unportable - " + "use gnulib module strsep for portability"); +# endif #endif #if @GNULIB_STRSTR@ # if @REPLACE_STRSTR@ -# define strstr rpl_strstr -char *strstr (const char *haystack, const char *needle) - __attribute__ ((__pure__)); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define strstr rpl_strstr +# endif +_GL_FUNCDECL_RPL (strstr, char *, (const char *haystack, const char *needle) + __attribute__ ((__pure__)) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (strstr, char *, (const char *haystack, const char *needle)); +# else + /* On some systems, this function is defined as an overloaded function: + extern "C++" { const char * strstr (const char *, const char *); } + extern "C++" { char * strstr (char *, const char *); } */ +_GL_CXXALIAS_SYS_CAST2 (strstr, + char *, (const char *haystack, const char *needle), + const char *, (const char *haystack, const char *needle)); +# endif +# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (strstr, char *, (char *haystack, const char *needle)); +_GL_CXXALIASWARN1 (strstr, const char *, + (const char *haystack, const char *needle)); +# else +_GL_CXXALIASWARN (strstr); # endif #elif defined GNULIB_POSIXCHECK /* strstr() does not work with multibyte strings if the locale encoding is @@ -343,48 +539,70 @@ char *strstr (const char *haystack, const char *needle) POSIX says that it operates on "strings", and "string" in POSIX is defined as a sequence of bytes, not of characters. */ # undef strstr -# define strstr(a,b) \ - (GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \ - "work correctly on character strings in most " \ - "multibyte locales - " \ - "use mbsstr if you care about internationalization, " \ - "or use strstr if you care about speed"), \ - strstr (a, b)) +/* Assume strstr is always declared. */ +_GL_WARN_ON_USE (strstr, "strstr is quadratic on many systems, and cannot " + "work correctly on character strings in most " + "multibyte locales - " + "use mbsstr if you care about internationalization, " + "or use strstr if you care about speed"); #endif /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive comparison. */ #if @GNULIB_STRCASESTR@ # if @REPLACE_STRCASESTR@ -# define strcasestr rpl_strcasestr +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define strcasestr rpl_strcasestr +# endif +_GL_FUNCDECL_RPL (strcasestr, char *, + (const char *haystack, const char *needle) + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (strcasestr, char *, + (const char *haystack, const char *needle)); +# else +# if ! @HAVE_STRCASESTR@ +_GL_FUNCDECL_SYS (strcasestr, char *, + (const char *haystack, const char *needle) + __attribute__ ((__pure__)) _GL_ARG_NONNULL ((1, 2))); +# endif + /* On some systems, this function is defined as an overloaded function: + extern "C++" { const char * strcasestr (const char *, const char *); } + extern "C++" { char * strcasestr (char *, const char *); } */ +_GL_CXXALIAS_SYS_CAST2 (strcasestr, + char *, (const char *haystack, const char *needle), + const char *, (const char *haystack, const char *needle)); # endif -# if ! @HAVE_STRCASESTR@ || @REPLACE_STRCASESTR@ -extern char *strcasestr (const char *haystack, const char *needle) - __attribute__ ((__pure__)); +# if __GLIBC__ == 2 && __GLIBC_MINOR__ >= 10 \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)) +_GL_CXXALIASWARN1 (strcasestr, char *, (char *haystack, const char *needle)); +_GL_CXXALIASWARN1 (strcasestr, const char *, + (const char *haystack, const char *needle)); +# else +_GL_CXXALIASWARN (strcasestr); # endif #elif defined GNULIB_POSIXCHECK /* strcasestr() does not work with multibyte strings: It is a glibc extension, and glibc implements it only for unibyte locales. */ # undef strcasestr -# define strcasestr(a,b) \ - (GL_LINK_WARNING ("strcasestr does work correctly on character strings " \ - "in multibyte locales - " \ - "use mbscasestr if you care about " \ - "internationalization, or use c-strcasestr if you want " \ - "a locale independent function"), \ - strcasestr (a, b)) +# if HAVE_RAW_DECL_STRCASESTR +_GL_WARN_ON_USE (strcasestr, "strcasestr does work correctly on character " + "strings in multibyte locales - " + "use mbscasestr if you care about " + "internationalization, or use c-strcasestr if you want " + "a locale independent function"); +# endif #endif /* Parse S into tokens separated by characters in DELIM. If S is NULL, the saved pointer in SAVE_PTR is used as the next starting point. For example: - char s[] = "-abc-=-def"; - char *sp; - x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" - x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL - x = strtok_r(NULL, "=", &sp); // x = NULL - // s = "abc\0-def\0" + char s[] = "-abc-=-def"; + char *sp; + x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" + x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL + x = strtok_r(NULL, "=", &sp); // x = NULL + // s = "abc\0-def\0" This is a variant of strtok() that is multithread-safe. @@ -399,24 +617,44 @@ extern char *strcasestr (const char *haystack, const char *needle) See also strsep(). */ #if @GNULIB_STRTOK_R@ -# if ! @HAVE_DECL_STRTOK_R@ -extern char *strtok_r (char *restrict s, char const *restrict delim, - char **restrict save_ptr); +# if @REPLACE_STRTOK_R@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strtok_r +# define strtok_r rpl_strtok_r +# endif +_GL_FUNCDECL_RPL (strtok_r, char *, + (char *restrict s, char const *restrict delim, + char **restrict save_ptr) + _GL_ARG_NONNULL ((2, 3))); +_GL_CXXALIAS_RPL (strtok_r, char *, + (char *restrict s, char const *restrict delim, + char **restrict save_ptr)); +# else +# if @UNDEFINE_STRTOK_R@ || defined GNULIB_POSIXCHECK +# undef strtok_r +# endif +# if ! @HAVE_DECL_STRTOK_R@ +_GL_FUNCDECL_SYS (strtok_r, char *, + (char *restrict s, char const *restrict delim, + char **restrict save_ptr) + _GL_ARG_NONNULL ((2, 3))); +# endif +_GL_CXXALIAS_SYS (strtok_r, char *, + (char *restrict s, char const *restrict delim, + char **restrict save_ptr)); # endif +_GL_CXXALIASWARN (strtok_r); # if defined GNULIB_POSIXCHECK -# undef strtok_r -# define strtok_r(s,d,p) \ - (GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \ - "in multibyte locales - " \ - "use mbstok_r if you care about internationalization"), \ - strtok_r (s, d, p)) +_GL_WARN_ON_USE (strtok_r, "strtok_r cannot work correctly on character " + "strings in multibyte locales - " + "use mbstok_r if you care about internationalization"); # endif #elif defined GNULIB_POSIXCHECK # undef strtok_r -# define strtok_r(s,d,p) \ - (GL_LINK_WARNING ("strtok_r is unportable - " \ - "use gnulib module strtok_r for portability"), \ - strtok_r (s, d, p)) +# if HAVE_RAW_DECL_STRTOK_R +_GL_WARN_ON_USE (strtok_r, "strtok_r is unportable - " + "use gnulib module strtok_r for portability"); +# endif #endif @@ -426,13 +664,27 @@ extern char *strtok_r (char *restrict s, char const *restrict delim, #if @GNULIB_MBSLEN@ /* Return the number of multibyte characters in the character string STRING. This considers multibyte characters, unlike strlen, which counts bytes. */ -extern size_t mbslen (const char *string); +# ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */ +# undef mbslen +# endif +# if @HAVE_MBSLEN@ /* AIX, OSF/1, MirBSD define mbslen already in libc. */ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define mbslen rpl_mbslen +# endif +_GL_FUNCDECL_RPL (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (mbslen, size_t, (const char *string)); +# else +_GL_FUNCDECL_SYS (mbslen, size_t, (const char *string) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_SYS (mbslen, size_t, (const char *string)); +# endif +_GL_CXXALIASWARN (mbslen); #endif #if @GNULIB_MBSNLEN@ /* Return the number of multibyte characters in the character string starting at STRING and ending at STRING + LEN. */ -extern size_t mbsnlen (const char *string, size_t len); +_GL_EXTERN_C size_t mbsnlen (const char *string, size_t len) + _GL_ARG_NONNULL ((1)); #endif #if @GNULIB_MBSCHR@ @@ -440,8 +692,19 @@ extern size_t mbsnlen (const char *string, size_t len); and return a pointer to it. Return NULL if C is not found in STRING. Unlike strchr(), this function works correctly in multibyte locales with encodings such as GB18030. */ -# define mbschr rpl_mbschr /* avoid collision with HP-UX function */ -extern char * mbschr (const char *string, int c); +# if defined __hpux +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define mbschr rpl_mbschr /* avoid collision with HP-UX function */ +# endif +_GL_FUNCDECL_RPL (mbschr, char *, (const char *string, int c) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (mbschr, char *, (const char *string, int c)); +# else +_GL_FUNCDECL_SYS (mbschr, char *, (const char *string, int c) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_SYS (mbschr, char *, (const char *string, int c)); +# endif +_GL_CXXALIASWARN (mbschr); #endif #if @GNULIB_MBSRCHR@ @@ -449,8 +712,19 @@ extern char * mbschr (const char *string, int c); and return a pointer to it. Return NULL if C is not found in STRING. Unlike strrchr(), this function works correctly in multibyte locales with encodings such as GB18030. */ -# define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */ -extern char * mbsrchr (const char *string, int c); +# if defined __hpux +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */ +# endif +_GL_FUNCDECL_RPL (mbsrchr, char *, (const char *string, int c) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (mbsrchr, char *, (const char *string, int c)); +# else +_GL_FUNCDECL_SYS (mbsrchr, char *, (const char *string, int c) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_SYS (mbsrchr, char *, (const char *string, int c)); +# endif +_GL_CXXALIASWARN (mbsrchr); #endif #if @GNULIB_MBSSTR@ @@ -458,7 +732,8 @@ extern char * mbsrchr (const char *string, int c); string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. Unlike strstr(), this function works correctly in multibyte locales with encodings different from UTF-8. */ -extern char * mbsstr (const char *haystack, const char *needle); +_GL_EXTERN_C char * mbsstr (const char *haystack, const char *needle) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSCASECMP@ @@ -468,7 +743,8 @@ extern char * mbsstr (const char *haystack, const char *needle); Note: This function may, in multibyte locales, return 0 for strings of different lengths! Unlike strcasecmp(), this function works correctly in multibyte locales. */ -extern int mbscasecmp (const char *s1, const char *s2); +_GL_EXTERN_C int mbscasecmp (const char *s1, const char *s2) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSNCASECMP@ @@ -481,7 +757,8 @@ extern int mbscasecmp (const char *s1, const char *s2); of different lengths! Unlike strncasecmp(), this function works correctly in multibyte locales. But beware that N is not a byte count but a character count! */ -extern int mbsncasecmp (const char *s1, const char *s2, size_t n); +_GL_EXTERN_C int mbsncasecmp (const char *s1, const char *s2, size_t n) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSPCASECMP@ @@ -494,7 +771,8 @@ extern int mbsncasecmp (const char *s1, const char *s2, size_t n); smaller length than PREFIX! Unlike strncasecmp(), this function works correctly in multibyte locales. */ -extern char * mbspcasecmp (const char *string, const char *prefix); +_GL_EXTERN_C char * mbspcasecmp (const char *string, const char *prefix) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSCASESTR@ @@ -503,7 +781,8 @@ extern char * mbspcasecmp (const char *string, const char *prefix); Note: This function may, in multibyte locales, return success even if strlen (haystack) < strlen (needle) ! Unlike strcasestr(), this function works correctly in multibyte locales. */ -extern char * mbscasestr (const char *haystack, const char *needle); +_GL_EXTERN_C char * mbscasestr (const char *haystack, const char *needle) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSCSPN@ @@ -512,7 +791,8 @@ extern char * mbscasestr (const char *haystack, const char *needle); beginning of the string to this occurrence, or to the end of the string if none exists. Unlike strcspn(), this function works correctly in multibyte locales. */ -extern size_t mbscspn (const char *string, const char *accept); +_GL_EXTERN_C size_t mbscspn (const char *string, const char *accept) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSPBRK@ @@ -520,8 +800,19 @@ extern size_t mbscspn (const char *string, const char *accept); in the character string ACCEPT. Return the pointer to it, or NULL if none exists. Unlike strpbrk(), this function works correctly in multibyte locales. */ -# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */ -extern char * mbspbrk (const char *string, const char *accept); +# if defined __hpux +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */ +# endif +_GL_FUNCDECL_RPL (mbspbrk, char *, (const char *string, const char *accept) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (mbspbrk, char *, (const char *string, const char *accept)); +# else +_GL_FUNCDECL_SYS (mbspbrk, char *, (const char *string, const char *accept) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_SYS (mbspbrk, char *, (const char *string, const char *accept)); +# endif +_GL_CXXALIASWARN (mbspbrk); #endif #if @GNULIB_MBSSPN@ @@ -530,7 +821,8 @@ extern char * mbspbrk (const char *string, const char *accept); beginning of the string to this occurrence, or to the end of the string if none exists. Unlike strspn(), this function works correctly in multibyte locales. */ -extern size_t mbsspn (const char *string, const char *reject); +_GL_EXTERN_C size_t mbsspn (const char *string, const char *reject) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSSEP@ @@ -548,7 +840,8 @@ extern size_t mbsspn (const char *string, const char *reject); Caveat: The identity of the delimiting character is lost. See also mbstok_r(). */ -extern char * mbssep (char **stringp, const char *delim); +_GL_EXTERN_C char * mbssep (char **stringp, const char *delim) + _GL_ARG_NONNULL ((1, 2)); #endif #if @GNULIB_MBSTOK_R@ @@ -556,67 +849,81 @@ extern char * mbssep (char **stringp, const char *delim); the character string DELIM. If STRING is NULL, the saved pointer in SAVE_PTR is used as the next starting point. For example: - char s[] = "-abc-=-def"; - char *sp; - x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" - x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL - x = mbstok_r(NULL, "=", &sp); // x = NULL - // s = "abc\0-def\0" + char s[] = "-abc-=-def"; + char *sp; + x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" + x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL + x = mbstok_r(NULL, "=", &sp); // x = NULL + // s = "abc\0-def\0" Caveat: It modifies the original string. Caveat: These functions cannot be used on constant strings. Caveat: The identity of the delimiting character is lost. See also mbssep(). */ -extern char * mbstok_r (char *string, const char *delim, char **save_ptr); +_GL_EXTERN_C char * mbstok_r (char *string, const char *delim, char **save_ptr) + _GL_ARG_NONNULL ((2, 3)); #endif /* Map any int, typically from errno, into an error message. */ #if @GNULIB_STRERROR@ # if @REPLACE_STRERROR@ -# undef strerror -# define strerror rpl_strerror -extern char *strerror (int); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef strerror +# define strerror rpl_strerror +# endif +_GL_FUNCDECL_RPL (strerror, char *, (int)); +_GL_CXXALIAS_RPL (strerror, char *, (int)); +# else +_GL_CXXALIAS_SYS (strerror, char *, (int)); # endif +_GL_CXXALIASWARN (strerror); #elif defined GNULIB_POSIXCHECK # undef strerror -# define strerror(e) \ - (GL_LINK_WARNING ("strerror is unportable - " \ - "use gnulib module strerror to guarantee non-NULL result"), \ - strerror (e)) +/* Assume strerror is always declared. */ +_GL_WARN_ON_USE (strerror, "strerror is unportable - " + "use gnulib module strerror to guarantee non-NULL result"); #endif #if @GNULIB_STRSIGNAL@ # if @REPLACE_STRSIGNAL@ -# define strsignal rpl_strsignal -# endif -# if ! @HAVE_DECL_STRSIGNAL@ || @REPLACE_STRSIGNAL@ -extern char *strsignal (int __sig); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define strsignal rpl_strsignal +# endif +_GL_FUNCDECL_RPL (strsignal, char *, (int __sig)); +_GL_CXXALIAS_RPL (strsignal, char *, (int __sig)); +# else +# if ! @HAVE_DECL_STRSIGNAL@ +_GL_FUNCDECL_SYS (strsignal, char *, (int __sig)); +# endif +/* Need to cast, because on Cygwin 1.5.x systems, the return type is + 'const char *'. */ +_GL_CXXALIAS_SYS_CAST (strsignal, char *, (int __sig)); # endif +_GL_CXXALIASWARN (strsignal); #elif defined GNULIB_POSIXCHECK # undef strsignal -# define strsignal(a) \ - (GL_LINK_WARNING ("strsignal is unportable - " \ - "use gnulib module strsignal for portability"), \ - strsignal (a)) +# if HAVE_RAW_DECL_STRSIGNAL +_GL_WARN_ON_USE (strsignal, "strsignal is unportable - " + "use gnulib module strsignal for portability"); +# endif #endif #if @GNULIB_STRVERSCMP@ # if !@HAVE_STRVERSCMP@ -extern int strverscmp (const char *, const char *); +_GL_FUNCDECL_SYS (strverscmp, int, (const char *, const char *) + _GL_ARG_NONNULL ((1, 2))); # endif +_GL_CXXALIAS_SYS (strverscmp, int, (const char *, const char *)); +_GL_CXXALIASWARN (strverscmp); #elif defined GNULIB_POSIXCHECK # undef strverscmp -# define strverscmp(a, b) \ - (GL_LINK_WARNING ("strverscmp is unportable - " \ - "use gnulib module strverscmp for portability"), \ - strverscmp (a, b)) +# if HAVE_RAW_DECL_STRVERSCMP +_GL_WARN_ON_USE (strverscmp, "strverscmp is unportable - " + "use gnulib module strverscmp for portability"); +# endif #endif -#ifdef __cplusplus -} -#endif - #endif /* _GL_STRING_H */ #endif /* _GL_STRING_H */ diff --git a/lib/strncat.c b/lib/strncat.c new file mode 100644 index 00000000..edc3c39c --- /dev/null +++ b/lib/strncat.c @@ -0,0 +1,33 @@ +/* Concatenate strings. + Copyright (C) 1999, 2002, 2006, 2010 Free Software Foundation, Inc. + Written by Bruno Haible , 2002. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +char * +strncat (char *dest, const char *src, size_t n) +{ + char *destptr = dest + strlen (dest); + + for (; n > 0 && (*destptr = *src) != '\0'; src++, destptr++, n--) + ; + if (n == 0) + *destptr = '\0'; + return dest; +} diff --git a/lib/unicase.h b/lib/unicase.h index e360ef44..57d16db4 100644 --- a/lib/unicase.h +++ b/lib/unicase.h @@ -1,5 +1,5 @@ /* Unicode character case mappings. - Copyright (C) 2002, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -91,57 +91,57 @@ extern const char * case-mapping. It can also be NULL, for no normalization. */ extern uint8_t * u8_toupper (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_toupper (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_toupper (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Return the lowercase mapping of a string. The nf argument identifies the normalization form to apply after the case-mapping. It can also be NULL, for no normalization. */ extern uint8_t * u8_tolower (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_tolower (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_tolower (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Return the titlecase mapping of a string. The nf argument identifies the normalization form to apply after the case-mapping. It can also be NULL, for no normalization. */ extern uint8_t * u8_totitle (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_totitle (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_totitle (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* The case-mapping context given by a prefix string. */ typedef struct casing_prefix_context - { - /* These fields are private, undocumented. */ - uint32_t last_char_except_ignorable; - uint32_t last_char_normal_or_above; - } - casing_prefix_context_t; + { + /* These fields are private, undocumented. */ + uint32_t last_char_except_ignorable; + uint32_t last_char_normal_or_above; + } + casing_prefix_context_t; /* The case-mapping context of the empty prefix string. */ extern LIBUNISTRING_DLL_VARIABLE const casing_prefix_context_t unicase_empty_prefix_context; /* Return the case-mapping context of a given prefix string. */ @@ -155,22 +155,22 @@ extern casing_prefix_context_t case-mapping context of the prefix A. */ extern casing_prefix_context_t u8_casing_prefixes_context (const uint8_t *s, size_t n, - casing_prefix_context_t a_context); + casing_prefix_context_t a_context); extern casing_prefix_context_t u16_casing_prefixes_context (const uint16_t *s, size_t n, - casing_prefix_context_t a_context); + casing_prefix_context_t a_context); extern casing_prefix_context_t u32_casing_prefixes_context (const uint32_t *s, size_t n, - casing_prefix_context_t a_context); + casing_prefix_context_t a_context); /* The case-mapping context given by a suffix string. */ typedef struct casing_suffix_context - { - /* These fields are private, undocumented. */ - uint32_t first_char_except_ignorable; - uint32_t bits; - } - casing_suffix_context_t; + { + /* These fields are private, undocumented. */ + uint32_t first_char_except_ignorable; + uint32_t bits; + } + casing_suffix_context_t; /* The case-mapping context of the empty suffix string. */ extern LIBUNISTRING_DLL_VARIABLE const casing_suffix_context_t unicase_empty_suffix_context; /* Return the case-mapping context of a given suffix string. */ @@ -184,85 +184,85 @@ extern casing_suffix_context_t case-mapping context of the suffix A. */ extern casing_suffix_context_t u8_casing_suffixes_context (const uint8_t *s, size_t n, - casing_suffix_context_t a_context); + casing_suffix_context_t a_context); extern casing_suffix_context_t u16_casing_suffixes_context (const uint16_t *s, size_t n, - casing_suffix_context_t a_context); + casing_suffix_context_t a_context); extern casing_suffix_context_t u32_casing_suffixes_context (const uint32_t *s, size_t n, - casing_suffix_context_t a_context); + casing_suffix_context_t a_context); /* Return the uppercase mapping of a string that is surrounded by a prefix and a suffix. */ extern uint8_t * u8_ct_toupper (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_ct_toupper (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_ct_toupper (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Return the lowercase mapping of a string that is surrounded by a prefix and a suffix. */ extern uint8_t * u8_ct_tolower (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_ct_tolower (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_ct_tolower (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Return the titlecase mapping of a string that is surrounded by a prefix and a suffix. */ extern uint8_t * u8_ct_totitle (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_ct_totitle (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_ct_totitle (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Return the case folded string. Comparing uN_casefold (S1) and uN_casefold (S2) with uN_cmp2() is equivalent @@ -271,38 +271,38 @@ extern uint32_t * case-mapping. It can also be NULL, for no normalization. */ extern uint8_t * u8_casefold (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_casefold (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_casefold (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Likewise, for a string that is surrounded by a prefix and a suffix. */ extern uint8_t * u8_ct_casefold (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_ct_casefold (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_ct_casefold (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); /* Compare S1 and S2, ignoring differences in case and normalization. The nf argument identifies the normalization form to apply after the @@ -311,20 +311,20 @@ extern uint32_t * return 0. Upon failure, return -1 with errno set. */ extern int u8_casecmp (const uint8_t *s1, size_t n1, - const uint8_t *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const uint8_t *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); extern int u16_casecmp (const uint16_t *s1, size_t n1, - const uint16_t *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const uint16_t *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); extern int u32_casecmp (const uint32_t *s1, size_t n1, - const uint32_t *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const uint32_t *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); extern int ulc_casecmp (const char *s1, size_t n1, - const char *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const char *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); /* Convert the string S of length N to a NUL-terminated byte sequence, in such a way that comparing uN_casexfrm (S1) and uN_casexfrm (S2) with the gnulib @@ -332,16 +332,16 @@ extern int NF must be either UNINORM_NFC, UNINORM_NFKC, or NULL for no normalization. */ extern char * u8_casexfrm (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, char *resultbuf, size_t *lengthp); + uninorm_t nf, char *resultbuf, size_t *lengthp); extern char * u16_casexfrm (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, char *resultbuf, size_t *lengthp); + uninorm_t nf, char *resultbuf, size_t *lengthp); extern char * u32_casexfrm (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, char *resultbuf, size_t *lengthp); + uninorm_t nf, char *resultbuf, size_t *lengthp); extern char * ulc_casexfrm (const char *s, size_t n, const char *iso639_language, - uninorm_t nf, char *resultbuf, size_t *lengthp); + uninorm_t nf, char *resultbuf, size_t *lengthp); /* Compare S1 and S2, ignoring differences in case and normalization, using the collation rules of the current locale. @@ -352,81 +352,81 @@ extern char * return 0. Upon failure, return -1 with errno set. */ extern int u8_casecoll (const uint8_t *s1, size_t n1, - const uint8_t *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const uint8_t *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); extern int u16_casecoll (const uint16_t *s1, size_t n1, - const uint16_t *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const uint16_t *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); extern int u32_casecoll (const uint32_t *s1, size_t n1, - const uint32_t *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const uint32_t *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); extern int ulc_casecoll (const char *s1, size_t n1, - const char *s2, size_t n2, - const char *iso639_language, uninorm_t nf, int *resultp); + const char *s2, size_t n2, + const char *iso639_language, uninorm_t nf, int *resultp); /* Set *RESULTP to true if mapping NFD(S) to upper case is a no-op, or to false otherwise, and return 0. Upon failure, return -1 with errno set. */ extern int u8_is_uppercase (const uint8_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u16_is_uppercase (const uint16_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u32_is_uppercase (const uint32_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); /* Set *RESULTP to true if mapping NFD(S) to lower case is a no-op, or to false otherwise, and return 0. Upon failure, return -1 with errno set. */ extern int u8_is_lowercase (const uint8_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u16_is_lowercase (const uint16_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u32_is_lowercase (const uint32_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); /* Set *RESULTP to true if mapping NFD(S) to title case is a no-op, or to false otherwise, and return 0. Upon failure, return -1 with errno set. */ extern int u8_is_titlecase (const uint8_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u16_is_titlecase (const uint16_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u32_is_titlecase (const uint32_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); /* Set *RESULTP to true if applying case folding to NFD(S) is a no-op, or to false otherwise, and return 0. Upon failure, return -1 with errno set. */ extern int u8_is_casefolded (const uint8_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u16_is_casefolded (const uint16_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u32_is_casefolded (const uint32_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); /* Set *RESULTP to true if case matters for S, that is, if mapping NFD(S) to either upper case or lower case or title case is not a no-op. @@ -436,16 +436,16 @@ extern int Upon failure, return -1 with errno set. */ extern int u8_is_cased (const uint8_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u16_is_cased (const uint16_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); extern int u32_is_cased (const uint32_t *s, size_t n, - const char *iso639_language, - bool *resultp); + const char *iso639_language, + bool *resultp); /* ========================================================================= */ diff --git a/lib/unicase/cased.c b/lib/unicase/cased.c index 5fbf4cb7..ced6a0e5 100644 --- a/lib/unicase/cased.c +++ b/lib/unicase/cased.c @@ -1,5 +1,5 @@ /* Test whether a Unicode character is cased. - Copyright (C) 2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -33,8 +33,8 @@ bool uc_is_cased (ucs4_t uc) { return (uc_is_property_lowercase (uc) - || uc_is_property_uppercase (uc) - || uc_is_general_category (uc, UC_TITLECASE_LETTER)); + || uc_is_property_uppercase (uc) + || uc_is_general_category (uc, UC_TITLECASE_LETTER)); } #else diff --git a/lib/unicase/casefold.h b/lib/unicase/casefold.h index d1f434ca..1a4fe926 100644 --- a/lib/unicase/casefold.h +++ b/lib/unicase/casefold.h @@ -1,5 +1,5 @@ /* Casefolding of Unicode characters. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/caseprop.h b/lib/unicase/caseprop.h index f84453ec..391d1692 100644 --- a/lib/unicase/caseprop.h +++ b/lib/unicase/caseprop.h @@ -1,5 +1,5 @@ /* Case related properties of Unicode characters. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/context.h b/lib/unicase/context.h index 6a35798d..a3303d6e 100644 --- a/lib/unicase/context.h +++ b/lib/unicase/context.h @@ -1,5 +1,5 @@ /* Case-mapping contexts of UTF-8/UTF-16/UTF-32 substring. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/empty-prefix-context.c b/lib/unicase/empty-prefix-context.c index 3c46e9e3..dada1047 100644 --- a/lib/unicase/empty-prefix-context.c +++ b/lib/unicase/empty-prefix-context.c @@ -1,5 +1,5 @@ /* Case-mapping context of empty prefix string. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/empty-suffix-context.c b/lib/unicase/empty-suffix-context.c index 4e00bffe..fc59a6e2 100644 --- a/lib/unicase/empty-suffix-context.c +++ b/lib/unicase/empty-suffix-context.c @@ -1,5 +1,5 @@ /* Case-mapping context of empty suffix string. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/ignorable.c b/lib/unicase/ignorable.c index 84b2634c..9cfce9fa 100644 --- a/lib/unicase/ignorable.c +++ b/lib/unicase/ignorable.c @@ -1,5 +1,5 @@ /* Test whether a Unicode character is case-ignorable. - Copyright (C) 2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -47,12 +47,12 @@ uc_is_case_ignorable (ucs4_t uc) int wbp = uc_wordbreak_property (uc); return (wbp == WBP_MIDLETTER || wbp == WBP_MIDNUMLET - || uc_is_general_category_withtable (uc, UC_CATEGORY_MASK_Mn - | UC_CATEGORY_MASK_Me - | UC_CATEGORY_MASK_Cf - | UC_CATEGORY_MASK_Lm - | UC_CATEGORY_MASK_Sk)) - && !uc_is_cased (uc); + || uc_is_general_category_withtable (uc, UC_CATEGORY_MASK_Mn + | UC_CATEGORY_MASK_Me + | UC_CATEGORY_MASK_Cf + | UC_CATEGORY_MASK_Lm + | UC_CATEGORY_MASK_Sk)) + && !uc_is_cased (uc); } #else diff --git a/lib/unicase/invariant.h b/lib/unicase/invariant.h index 20151433..c65ae23e 100644 --- a/lib/unicase/invariant.h +++ b/lib/unicase/invariant.h @@ -1,5 +1,5 @@ /* Internal functions for Unicode character case mappings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,22 +24,22 @@ /* Return true if mapping NFD(S) to via MAPPING is a no-op. */ extern int u8_is_invariant (const uint8_t *s, size_t n, - uint8_t * (*mapping) (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp), - const char *iso639_language, - bool *resultp); + uint8_t * (*mapping) (const uint8_t *s, size_t n, const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp), + const char *iso639_language, + bool *resultp); extern int u16_is_invariant (const uint16_t *s, size_t n, - uint16_t * (*mapping) (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp), - const char *iso639_language, - bool *resultp); + uint16_t * (*mapping) (const uint16_t *s, size_t n, const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp), + const char *iso639_language, + bool *resultp); extern int u32_is_invariant (const uint32_t *s, size_t n, - uint32_t * (*mapping) (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp), - const char *iso639_language, - bool *resultp); + uint32_t * (*mapping) (const uint32_t *s, size_t n, const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp), + const char *iso639_language, + bool *resultp); diff --git a/lib/unicase/locale-language.c b/lib/unicase/locale-language.c index 074baa41..2ee65c72 100644 --- a/lib/unicase/locale-language.c +++ b/lib/unicase/locale-language.c @@ -1,5 +1,5 @@ /* Language code of current locale. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -46,9 +46,9 @@ uc_locale_language (void) if (p != locale_name) { const char *language = - uc_locale_languages_lookup (locale_name, p - locale_name); + uc_locale_languages_lookup (locale_name, p - locale_name); if (language != NULL) - return language; + return language; } return ""; diff --git a/lib/unicase/simple-mapping.h b/lib/unicase/simple-mapping.h index 44cecc81..83200b49 100644 --- a/lib/unicase/simple-mapping.h +++ b/lib/unicase/simple-mapping.h @@ -1,5 +1,5 @@ /* Simple case mapping for Unicode characters. - Copyright (C) 2002, 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -23,17 +23,17 @@ FUNC (ucs4_t uc) { int lookup1 = u_mapping.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> mapping_header_2) & mapping_header_3; - int lookup2 = u_mapping.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & mapping_header_4); - int lookup3 = u_mapping.level3[lookup2 + index3]; + { + unsigned int index2 = (uc >> mapping_header_2) & mapping_header_3; + int lookup2 = u_mapping.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & mapping_header_4); + int lookup3 = u_mapping.level3[lookup2 + index3]; - return uc + lookup3; - } - } + return uc + lookup3; + } + } } return uc; } diff --git a/lib/unicase/special-casing.c b/lib/unicase/special-casing.c index 9cc207c6..95b6c824 100644 --- a/lib/unicase/special-casing.c +++ b/lib/unicase/special-casing.c @@ -1,5 +1,5 @@ /* Special casing table. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/special-casing.h b/lib/unicase/special-casing.h index ab88b84d..33911cfc 100644 --- a/lib/unicase/special-casing.h +++ b/lib/unicase/special-casing.h @@ -1,5 +1,5 @@ /* Special casing table. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/tocasefold.c b/lib/unicase/tocasefold.c index 752ba60a..1ba79bd3 100644 --- a/lib/unicase/tocasefold.c +++ b/lib/unicase/tocasefold.c @@ -1,5 +1,5 @@ /* Casefold mapping for Unicode characters (locale and context independent). - Copyright (C) 2002, 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/tolower.c b/lib/unicase/tolower.c index 5ed0c6d2..c69f691d 100644 --- a/lib/unicase/tolower.c +++ b/lib/unicase/tolower.c @@ -1,5 +1,5 @@ /* Lowercase mapping for Unicode characters (locale and context independent). - Copyright (C) 2002, 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/totitle.c b/lib/unicase/totitle.c index 0ca5a45b..ced1b69c 100644 --- a/lib/unicase/totitle.c +++ b/lib/unicase/totitle.c @@ -1,5 +1,5 @@ /* Titlecase mapping for Unicode characters (locale and context independent). - Copyright (C) 2002, 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/toupper.c b/lib/unicase/toupper.c index d74e45c7..9642b706 100644 --- a/lib/unicase/toupper.c +++ b/lib/unicase/toupper.c @@ -1,5 +1,5 @@ /* Uppercase mapping for Unicode characters (locale and context independent). - Copyright (C) 2002, 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u-casecmp.h b/lib/unicase/u-casecmp.h index e1cf99c4..88c308b4 100644 --- a/lib/unicase/u-casecmp.h +++ b/lib/unicase/u-casecmp.h @@ -1,5 +1,5 @@ /* Case and normalization insensitive comparison of Unicode strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -45,11 +45,11 @@ FUNC (const SRC_UNIT *s1, size_t n1, const SRC_UNIT *s2, size_t n2, if (norms2 == NULL) { if (norms1 != buf1) - { - int saved_errno = errno; - free (norms1); - errno = saved_errno; - } + { + int saved_errno = errno; + free (norms1); + errno = saved_errno; + } return -1; } diff --git a/lib/unicase/u-casecoll.h b/lib/unicase/u-casecoll.h index 73094abe..700d49b1 100644 --- a/lib/unicase/u-casecoll.h +++ b/lib/unicase/u-casecoll.h @@ -1,6 +1,6 @@ /* Locale dependent, case and normalization insensitive comparison of Unicode strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -43,17 +43,17 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2, if (transformed2 == NULL) { if (transformed1 != buf1) - { - int saved_errno = errno; - free (transformed1); - errno = saved_errno; - } + { + int saved_errno = errno; + free (transformed1); + errno = saved_errno; + } return -1; } /* Compare the transformed strings. */ cmp = memcmp2 (transformed1, transformed1_length, - transformed2, transformed2_length); + transformed2, transformed2_length); if (cmp < 0) cmp = -1; else if (cmp > 0) diff --git a/lib/unicase/u-casefold.h b/lib/unicase/u-casefold.h index c41f4e18..b0dc89a6 100644 --- a/lib/unicase/u-casefold.h +++ b/lib/unicase/u-casefold.h @@ -1,5 +1,5 @@ /* Casefolding mapping for Unicode strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -21,8 +21,8 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, UNIT *resultbuf, size_t *lengthp) { return U_CT_CASEFOLD (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u-casemap.h b/lib/unicase/u-casemap.h index ea41444a..b5b4d2fc 100644 --- a/lib/unicase/u-casemap.h +++ b/lib/unicase/u-casemap.h @@ -1,5 +1,5 @@ /* Case mapping for UTF-8/UTF-16/UTF-32 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -58,311 +58,311 @@ FUNC (const UNIT *s, size_t n, while (s < s_end) { - ucs4_t uc; - int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); - - ucs4_t mapped_uc[3]; - unsigned int mapped_count; - - if (uc < 0x10000) - { - /* Look first in the special-casing table. */ - char code[3]; - - code[0] = (uc >> 8) & 0xff; - code[1] = uc & 0xff; - - for (code[2] = 0; ; code[2]++) - { - const struct special_casing_rule *rule = - gl_unicase_special_lookup (code, 3); - - if (rule == NULL) - break; - - /* Test if the condition applies. */ - /* Does the language apply? */ - if (rule->language[0] == '\0' - || (iso639_language != NULL - && iso639_language[0] == rule->language[0] - && iso639_language[1] == rule->language[1])) - { - /* Does the context apply? */ - int context = rule->context; - bool applies; - - if (context < 0) - context = - context; - switch (context) - { - case SCC_ALWAYS: - applies = true; - break; - - case SCC_FINAL_SIGMA: - /* "Before" condition: preceded by a sequence - consisting of a cased letter and a case-ignorable - sequence. - "After" condition: not followed by a sequence - consisting of a case-ignorable sequence and then a - cased letter. */ - /* Test the "before" condition. */ - applies = uc_is_cased (last_char_except_ignorable); - /* Test the "after" condition. */ - if (applies) - { - const UNIT *s2 = s + count; - for (;;) - { - if (s2 < s_end) - { - ucs4_t uc2; - int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); - /* Our uc_is_case_ignorable function is - known to return false for all cased - characters. So we can call - uc_is_case_ignorable first. */ - if (!uc_is_case_ignorable (uc2)) - { - applies = ! uc_is_cased (uc2); - break; - } - s2 += count2; - } - else - { - applies = ! uc_is_cased (suffix_context.first_char_except_ignorable); - break; - } - } - } - break; - - case SCC_AFTER_SOFT_DOTTED: - /* "Before" condition: There is a Soft_Dotted character - before it, with no intervening character of - combining class 0 or 230 (Above). */ - /* Test the "before" condition. */ - applies = uc_is_property_soft_dotted (last_char_normal_or_above); - break; - - case SCC_MORE_ABOVE: - /* "After" condition: followed by a character of - combining class 230 (Above) with no intervening - character of combining class 0 or 230 (Above). */ - /* Test the "after" condition. */ - { - const UNIT *s2 = s + count; - applies = false; - for (;;) - { - if (s2 < s_end) - { - ucs4_t uc2; - int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); - int ccc = uc_combining_class (uc2); - if (ccc == UC_CCC_A) - { - applies = true; - break; - } - if (ccc == UC_CCC_NR) - break; - s2 += count2; - } - else - { - applies = ((suffix_context.bits & SCC_MORE_ABOVE_MASK) != 0); - break; - } - } - } - break; - - case SCC_BEFORE_DOT: - /* "After" condition: followed by COMBINING DOT ABOVE - (U+0307). Any sequence of characters with a - combining class that is neither 0 nor 230 may - intervene between the current character and the - combining dot above. */ - /* Test the "after" condition. */ - { - const UNIT *s2 = s + count; - applies = false; - for (;;) - { - if (s2 < s_end) - { - ucs4_t uc2; - int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); - if (uc2 == 0x0307) /* COMBINING DOT ABOVE */ - { - applies = true; - break; - } - { - int ccc = uc_combining_class (uc2); - if (ccc == UC_CCC_A || ccc == UC_CCC_NR) - break; - } - s2 += count2; - } - else - { - applies = ((suffix_context.bits & SCC_BEFORE_DOT_MASK) != 0); - break; - } - } - } - break; - - case SCC_AFTER_I: - /* "Before" condition: There is an uppercase I before - it, and there is no intervening character of - combining class 0 or 230 (Above). */ - /* Test the "before" condition. */ - applies = (last_char_normal_or_above == 'I'); - break; - - default: - abort (); - } - if (rule->context < 0) - applies = !applies; - - if (applies) - { - /* The rule applies. - Look up the mapping (0 to 3 characters). */ - const unsigned short *mapped_in_rule = - (const unsigned short *)((const char *)rule + offset_in_rule); - - if (mapped_in_rule[0] == 0) - mapped_count = 0; - else - { - mapped_uc[0] = mapped_in_rule[0]; - if (mapped_in_rule[1] == 0) - mapped_count = 1; - else - { - mapped_uc[1] = mapped_in_rule[1]; - if (mapped_in_rule[2] == 0) - mapped_count = 2; - else - { - mapped_uc[2] = mapped_in_rule[2]; - mapped_count = 3; - } - } - } - goto found_mapping; - } - } - - /* Optimization: Save a hash table lookup in the next round. */ - if (!rule->has_next) - break; - } - } - - /* No special-cased mapping. So use the locale and context independent - mapping. */ - mapped_uc[0] = single_character_map (uc); - mapped_count = 1; + ucs4_t uc; + int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); + + ucs4_t mapped_uc[3]; + unsigned int mapped_count; + + if (uc < 0x10000) + { + /* Look first in the special-casing table. */ + char code[3]; + + code[0] = (uc >> 8) & 0xff; + code[1] = uc & 0xff; + + for (code[2] = 0; ; code[2]++) + { + const struct special_casing_rule *rule = + gl_unicase_special_lookup (code, 3); + + if (rule == NULL) + break; + + /* Test if the condition applies. */ + /* Does the language apply? */ + if (rule->language[0] == '\0' + || (iso639_language != NULL + && iso639_language[0] == rule->language[0] + && iso639_language[1] == rule->language[1])) + { + /* Does the context apply? */ + int context = rule->context; + bool applies; + + if (context < 0) + context = - context; + switch (context) + { + case SCC_ALWAYS: + applies = true; + break; + + case SCC_FINAL_SIGMA: + /* "Before" condition: preceded by a sequence + consisting of a cased letter and a case-ignorable + sequence. + "After" condition: not followed by a sequence + consisting of a case-ignorable sequence and then a + cased letter. */ + /* Test the "before" condition. */ + applies = uc_is_cased (last_char_except_ignorable); + /* Test the "after" condition. */ + if (applies) + { + const UNIT *s2 = s + count; + for (;;) + { + if (s2 < s_end) + { + ucs4_t uc2; + int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); + /* Our uc_is_case_ignorable function is + known to return false for all cased + characters. So we can call + uc_is_case_ignorable first. */ + if (!uc_is_case_ignorable (uc2)) + { + applies = ! uc_is_cased (uc2); + break; + } + s2 += count2; + } + else + { + applies = ! uc_is_cased (suffix_context.first_char_except_ignorable); + break; + } + } + } + break; + + case SCC_AFTER_SOFT_DOTTED: + /* "Before" condition: There is a Soft_Dotted character + before it, with no intervening character of + combining class 0 or 230 (Above). */ + /* Test the "before" condition. */ + applies = uc_is_property_soft_dotted (last_char_normal_or_above); + break; + + case SCC_MORE_ABOVE: + /* "After" condition: followed by a character of + combining class 230 (Above) with no intervening + character of combining class 0 or 230 (Above). */ + /* Test the "after" condition. */ + { + const UNIT *s2 = s + count; + applies = false; + for (;;) + { + if (s2 < s_end) + { + ucs4_t uc2; + int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); + int ccc = uc_combining_class (uc2); + if (ccc == UC_CCC_A) + { + applies = true; + break; + } + if (ccc == UC_CCC_NR) + break; + s2 += count2; + } + else + { + applies = ((suffix_context.bits & SCC_MORE_ABOVE_MASK) != 0); + break; + } + } + } + break; + + case SCC_BEFORE_DOT: + /* "After" condition: followed by COMBINING DOT ABOVE + (U+0307). Any sequence of characters with a + combining class that is neither 0 nor 230 may + intervene between the current character and the + combining dot above. */ + /* Test the "after" condition. */ + { + const UNIT *s2 = s + count; + applies = false; + for (;;) + { + if (s2 < s_end) + { + ucs4_t uc2; + int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); + if (uc2 == 0x0307) /* COMBINING DOT ABOVE */ + { + applies = true; + break; + } + { + int ccc = uc_combining_class (uc2); + if (ccc == UC_CCC_A || ccc == UC_CCC_NR) + break; + } + s2 += count2; + } + else + { + applies = ((suffix_context.bits & SCC_BEFORE_DOT_MASK) != 0); + break; + } + } + } + break; + + case SCC_AFTER_I: + /* "Before" condition: There is an uppercase I before + it, and there is no intervening character of + combining class 0 or 230 (Above). */ + /* Test the "before" condition. */ + applies = (last_char_normal_or_above == 'I'); + break; + + default: + abort (); + } + if (rule->context < 0) + applies = !applies; + + if (applies) + { + /* The rule applies. + Look up the mapping (0 to 3 characters). */ + const unsigned short *mapped_in_rule = + (const unsigned short *)((const char *)rule + offset_in_rule); + + if (mapped_in_rule[0] == 0) + mapped_count = 0; + else + { + mapped_uc[0] = mapped_in_rule[0]; + if (mapped_in_rule[1] == 0) + mapped_count = 1; + else + { + mapped_uc[1] = mapped_in_rule[1]; + if (mapped_in_rule[2] == 0) + mapped_count = 2; + else + { + mapped_uc[2] = mapped_in_rule[2]; + mapped_count = 3; + } + } + } + goto found_mapping; + } + } + + /* Optimization: Save a hash table lookup in the next round. */ + if (!rule->has_next) + break; + } + } + + /* No special-cased mapping. So use the locale and context independent + mapping. */ + mapped_uc[0] = single_character_map (uc); + mapped_count = 1; found_mapping: - /* Found the mapping: uc maps to mapped_uc[0..mapped_count-1]. */ - { - unsigned int i; - - for (i = 0; i < mapped_count; i++) - { - ucs4_t muc = mapped_uc[i]; - - /* Append muc to the result accumulator. */ - if (length < allocated) - { - int ret = U_UCTOMB (result + length, muc, allocated - length); - if (ret == -1) - { - errno = EINVAL; - goto fail; - } - if (ret >= 0) - { - length += ret; - goto done_appending; - } - } - { - size_t old_allocated = allocated; - size_t new_allocated = 2 * old_allocated; - if (new_allocated < 64) - new_allocated = 64; - if (new_allocated < old_allocated) /* integer overflow? */ - abort (); - { - UNIT *larger_result; - if (result == NULL) - { - larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail; - } - } - else if (result == resultbuf) - { - larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail; - } - U_CPY (larger_result, resultbuf, length); - } - else - { - larger_result = - (UNIT *) realloc (result, new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail; - } - } - result = larger_result; - allocated = new_allocated; - { - int ret = U_UCTOMB (result + length, muc, allocated - length); - if (ret == -1) - { - errno = EINVAL; - goto fail; - } - if (ret < 0) - abort (); - length += ret; - goto done_appending; - } - } - } - done_appending: ; - } - } - - if (!uc_is_case_ignorable (uc)) - last_char_except_ignorable = uc; - - { - int ccc = uc_combining_class (uc); - if (ccc == UC_CCC_A || ccc == UC_CCC_NR) - last_char_normal_or_above = uc; - } - - s += count; + /* Found the mapping: uc maps to mapped_uc[0..mapped_count-1]. */ + { + unsigned int i; + + for (i = 0; i < mapped_count; i++) + { + ucs4_t muc = mapped_uc[i]; + + /* Append muc to the result accumulator. */ + if (length < allocated) + { + int ret = U_UCTOMB (result + length, muc, allocated - length); + if (ret == -1) + { + errno = EINVAL; + goto fail; + } + if (ret >= 0) + { + length += ret; + goto done_appending; + } + } + { + size_t old_allocated = allocated; + size_t new_allocated = 2 * old_allocated; + if (new_allocated < 64) + new_allocated = 64; + if (new_allocated < old_allocated) /* integer overflow? */ + abort (); + { + UNIT *larger_result; + if (result == NULL) + { + larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail; + } + } + else if (result == resultbuf) + { + larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail; + } + U_CPY (larger_result, resultbuf, length); + } + else + { + larger_result = + (UNIT *) realloc (result, new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail; + } + } + result = larger_result; + allocated = new_allocated; + { + int ret = U_UCTOMB (result + length, muc, allocated - length); + if (ret == -1) + { + errno = EINVAL; + goto fail; + } + if (ret < 0) + abort (); + length += ret; + goto done_appending; + } + } + } + done_appending: ; + } + } + + if (!uc_is_case_ignorable (uc)) + last_char_except_ignorable = uc; + + { + int ccc = uc_combining_class (uc); + if (ccc == UC_CCC_A || ccc == UC_CCC_NR) + last_char_normal_or_above = uc; + } + + s += count; } } @@ -373,7 +373,7 @@ FUNC (const UNIT *s, size_t n, normalized_result = U_NORMALIZE (nf, result, length, resultbuf, lengthp); if (normalized_result == NULL) - goto fail; + goto fail; free (result); return normalized_result; @@ -382,15 +382,15 @@ FUNC (const UNIT *s, size_t n, if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - goto fail; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + goto fail; + } + } } else if (result != resultbuf && length < allocated) { @@ -399,7 +399,7 @@ FUNC (const UNIT *s, size_t n, memory = (UNIT *) realloc (result, length * sizeof (UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unicase/u-casexfrm.h b/lib/unicase/u-casexfrm.h index e36aff3b..5c7430c0 100644 --- a/lib/unicase/u-casexfrm.h +++ b/lib/unicase/u-casexfrm.h @@ -1,6 +1,6 @@ /* Locale dependent transformation for case insensitive comparison of Unicode strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -38,18 +38,18 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, uninorm_t nf, /* Convert it to locale encoding. */ convs_length = sizeof (convsbuf) - 1; convs = U_CONV_TO_ENCODING (locale_charset (), - iconveh_error, - foldeds, foldeds_length, - NULL, - convsbuf, &convs_length); + iconveh_error, + foldeds, foldeds_length, + NULL, + convsbuf, &convs_length); if (convs == NULL) { if (foldeds != foldedsbuf) - { - int saved_errno = errno; - free (foldeds); - errno = saved_errno; - } + { + int saved_errno = errno; + free (foldeds); + errno = saved_errno; + } return NULL; } @@ -61,11 +61,11 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, uninorm_t nf, { char *memory = (char *) realloc (convs, convs_length + 1); if (memory == NULL) - { - free (convs); - errno = ENOMEM; - return NULL; - } + { + free (convs); + errno = ENOMEM; + return NULL; + } convs = memory; } @@ -74,11 +74,11 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, uninorm_t nf, if (result == NULL) { if (convs != convsbuf) - { - int saved_errno = errno; - free (convs); - errno = saved_errno; - } + { + int saved_errno = errno; + free (convs); + errno = saved_errno; + } return NULL; } diff --git a/lib/unicase/u-ct-casefold.h b/lib/unicase/u-ct-casefold.h index d97be264..e11d0a81 100644 --- a/lib/unicase/u-ct-casefold.h +++ b/lib/unicase/u-ct-casefold.h @@ -1,5 +1,5 @@ /* Casefolding mapping for Unicode substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -36,14 +36,14 @@ FUNC (const UNIT *s, size_t n, if (nf == NULL) /* X -> toCasefold(X) */ return U_CASEMAP (s, n, prefix_context, suffix_context, iso639_language, - uc_tocasefold, offsetof (struct special_casing_rule, casefold[0]), - NULL, - resultbuf, lengthp); + uc_tocasefold, offsetof (struct special_casing_rule, casefold[0]), + NULL, + resultbuf, lengthp); else { uninorm_t nfd = uninorm_decomposing_form (nf); /* X -> nf(toCasefold(NFD(X))) or - X -> nf(toCasefold(nfd(toCasefold(NFD(X))))) */ + X -> nf(toCasefold(nfd(toCasefold(NFD(X))))) */ int repeat = (uninorm_is_compat_decomposing (nf) ? 2 : 1); UNIT tmpbuf1[2048 / sizeof (UNIT)]; UNIT tmpbuf2[2048 / sizeof (UNIT)]; @@ -55,51 +55,51 @@ FUNC (const UNIT *s, size_t n, tmp1_length = sizeof (tmpbuf1) / sizeof (UNIT); tmp1 = U_NORMALIZE (UNINORM_NFD, s, n, tmpbuf1, &tmp1_length); if (tmp1 == NULL) - /* errno is set here. */ - return NULL; + /* errno is set here. */ + return NULL; do - { - tmp2_length = sizeof (tmpbuf2) / sizeof (UNIT); - tmp2 = U_CASEMAP (tmp1, tmp1_length, - prefix_context, suffix_context, iso639_language, - uc_tocasefold, offsetof (struct special_casing_rule, casefold[0]), - NULL, - tmpbuf2, &tmp2_length); - if (tmp2 == NULL) - { - int saved_errno = errno; - if (tmp1 != tmpbuf1) - free (tmp1); - errno = saved_errno; - return NULL; - } + { + tmp2_length = sizeof (tmpbuf2) / sizeof (UNIT); + tmp2 = U_CASEMAP (tmp1, tmp1_length, + prefix_context, suffix_context, iso639_language, + uc_tocasefold, offsetof (struct special_casing_rule, casefold[0]), + NULL, + tmpbuf2, &tmp2_length); + if (tmp2 == NULL) + { + int saved_errno = errno; + if (tmp1 != tmpbuf1) + free (tmp1); + errno = saved_errno; + return NULL; + } - if (tmp1 != tmpbuf1) - free (tmp1); + if (tmp1 != tmpbuf1) + free (tmp1); - if (repeat > 1) - { - tmp1_length = sizeof (tmpbuf1) / sizeof (UNIT); - tmp1 = U_NORMALIZE (nfd, tmp2, tmp2_length, - tmpbuf1, &tmp1_length); - } - else - /* Last run through this loop. */ - tmp1 = U_NORMALIZE (nf, tmp2, tmp2_length, - resultbuf, lengthp); - if (tmp1 == NULL) - { - int saved_errno = errno; - if (tmp2 != tmpbuf2) - free (tmp2); - errno = saved_errno; - return NULL; - } + if (repeat > 1) + { + tmp1_length = sizeof (tmpbuf1) / sizeof (UNIT); + tmp1 = U_NORMALIZE (nfd, tmp2, tmp2_length, + tmpbuf1, &tmp1_length); + } + else + /* Last run through this loop. */ + tmp1 = U_NORMALIZE (nf, tmp2, tmp2_length, + resultbuf, lengthp); + if (tmp1 == NULL) + { + int saved_errno = errno; + if (tmp2 != tmpbuf2) + free (tmp2); + errno = saved_errno; + return NULL; + } - if (tmp2 != tmpbuf2) - free (tmp2); - } + if (tmp2 != tmpbuf2) + free (tmp2); + } while (--repeat > 0); return tmp1; diff --git a/lib/unicase/u-ct-totitle.h b/lib/unicase/u-ct-totitle.h index f0d4fd77..8892a5df 100644 --- a/lib/unicase/u-ct-totitle.h +++ b/lib/unicase/u-ct-totitle.h @@ -1,5 +1,5 @@ /* Titlecase mapping for UTF-8/UTF-16/UTF-32 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -55,10 +55,10 @@ FUNC (const UNIT *s, size_t n, { wordbreaks = (char *) malloc (n); if (wordbreaks == NULL) - { - errno = ENOMEM; - goto fail2; - } + { + errno = ENOMEM; + goto fail2; + } U_WORDBREAKS (s, n, wordbreaks); } else @@ -70,12 +70,12 @@ FUNC (const UNIT *s, size_t n, /* When considering the string as segmented by word boundaries: For each such segment: - - In the first part, we are searching for the first cased character. - In this state, in_word_first_part = true, and no conversion takes - place. - - In the second part, we are converting every character: the first - among these characters to title case, the other ones to lower case. - In this state, in_word_first_part = false. */ + - In the first part, we are searching for the first cased character. + In this state, in_word_first_part = true, and no conversion takes + place. + - In the second part, we are converting every character: the first + among these characters to title case, the other ones to lower case. + In this state, in_word_first_part = false. */ bool in_word_first_part = true; /* Helper for evaluating the FINAL_SIGMA condition: @@ -90,356 +90,356 @@ FUNC (const UNIT *s, size_t n, while (s < s_end) { - /* Fetch the next character. */ - ucs4_t uc; - int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); - - ucs4_t (*single_character_map) (ucs4_t); - size_t offset_in_rule; /* offset in 'struct special_casing_rule' */ - - ucs4_t mapped_uc[3]; - unsigned int mapped_count; - - if (*wp) - /* Crossing a word boundary. */ - in_word_first_part = true; - - /* Determine single_character_map, offset_in_rule. - There are three possibilities: - - uc should not be converted. - - uc should be titlecased. - - uc should be lowercased. */ - if (in_word_first_part) - { - if (uc_is_cased (uc)) - { - /* uc is to be titlecased. */ - single_character_map = uc_totitle; - offset_in_rule = offsetof (struct special_casing_rule, title[0]); - in_word_first_part = false; - } - else - { - /* uc is not converted. */ - single_character_map = NULL; - offset_in_rule = 0; - } - } - else - { - /* uc is to be lowercased. */ - single_character_map = uc_tolower; - offset_in_rule = offsetof (struct special_casing_rule, lower[0]); - } - - /* Actually map uc. */ - if (single_character_map == NULL) - { - mapped_uc[0] = uc; - mapped_count = 1; - goto found_mapping; - } - - if (uc < 0x10000) - { - /* Look first in the special-casing table. */ - char code[3]; - - code[0] = (uc >> 8) & 0xff; - code[1] = uc & 0xff; - - for (code[2] = 0; ; code[2]++) - { - const struct special_casing_rule *rule = - gl_unicase_special_lookup (code, 3); - - if (rule == NULL) - break; - - /* Test if the condition applies. */ - /* Does the language apply? */ - if (rule->language[0] == '\0' - || (iso639_language != NULL - && iso639_language[0] == rule->language[0] - && iso639_language[1] == rule->language[1])) - { - /* Does the context apply? */ - int context = rule->context; - bool applies; - - if (context < 0) - context = - context; - switch (context) - { - case SCC_ALWAYS: - applies = true; - break; - - case SCC_FINAL_SIGMA: - /* "Before" condition: preceded by a sequence - consisting of a cased letter and a case-ignorable - sequence. - "After" condition: not followed by a sequence - consisting of a case-ignorable sequence and then a - cased letter. */ - /* Test the "before" condition. */ - applies = uc_is_cased (last_char_except_ignorable); - /* Test the "after" condition. */ - if (applies) - { - const UNIT *s2 = s + count; - for (;;) - { - if (s2 < s_end) - { - ucs4_t uc2; - int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); - /* Our uc_is_case_ignorable function is - known to return false for all cased - characters. So we can call - uc_is_case_ignorable first. */ - if (!uc_is_case_ignorable (uc2)) - { - applies = ! uc_is_cased (uc2); - break; - } - s2 += count2; - } - else - { - applies = ! uc_is_cased (suffix_context.first_char_except_ignorable); - break; - } - } - } - break; - - case SCC_AFTER_SOFT_DOTTED: - /* "Before" condition: There is a Soft_Dotted character - before it, with no intervening character of - combining class 0 or 230 (Above). */ - /* Test the "before" condition. */ - applies = uc_is_property_soft_dotted (last_char_normal_or_above); - break; - - case SCC_MORE_ABOVE: - /* "After" condition: followed by a character of - combining class 230 (Above) with no intervening - character of combining class 0 or 230 (Above). */ - /* Test the "after" condition. */ - { - const UNIT *s2 = s + count; - applies = false; - for (;;) - { - if (s2 < s_end) - { - ucs4_t uc2; - int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); - int ccc = uc_combining_class (uc2); - if (ccc == UC_CCC_A) - { - applies = true; - break; - } - if (ccc == UC_CCC_NR) - break; - s2 += count2; - } - else - { - applies = ((suffix_context.bits & SCC_MORE_ABOVE_MASK) != 0); - break; - } - } - } - break; - - case SCC_BEFORE_DOT: - /* "After" condition: followed by COMBINING DOT ABOVE - (U+0307). Any sequence of characters with a - combining class that is neither 0 nor 230 may - intervene between the current character and the - combining dot above. */ - /* Test the "after" condition. */ - { - const UNIT *s2 = s + count; - applies = false; - for (;;) - { - if (s2 < s_end) - { - ucs4_t uc2; - int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); - if (uc2 == 0x0307) /* COMBINING DOT ABOVE */ - { - applies = true; - break; - } - { - int ccc = uc_combining_class (uc2); - if (ccc == UC_CCC_A || ccc == UC_CCC_NR) - break; - } - s2 += count2; - } - else - { - applies = ((suffix_context.bits & SCC_BEFORE_DOT_MASK) != 0); - break; - } - } - } - break; - - case SCC_AFTER_I: - /* "Before" condition: There is an uppercase I before - it, and there is no intervening character of - combining class 0 or 230 (Above). */ - /* Test the "before" condition. */ - applies = (last_char_normal_or_above == 'I'); - break; - - default: - abort (); - } - if (rule->context < 0) - applies = !applies; - - if (applies) - { - /* The rule applies. - Look up the mapping (0 to 3 characters). */ - const unsigned short *mapped_in_rule = - (const unsigned short *)((const char *)rule + offset_in_rule); - - if (mapped_in_rule[0] == 0) - mapped_count = 0; - else - { - mapped_uc[0] = mapped_in_rule[0]; - if (mapped_in_rule[1] == 0) - mapped_count = 1; - else - { - mapped_uc[1] = mapped_in_rule[1]; - if (mapped_in_rule[2] == 0) - mapped_count = 2; - else - { - mapped_uc[2] = mapped_in_rule[2]; - mapped_count = 3; - } - } - } - goto found_mapping; - } - } - - /* Optimization: Save a hash table lookup in the next round. */ - if (!rule->has_next) - break; - } - } - - /* No special-cased mapping. So use the locale and context independent - mapping. */ - mapped_uc[0] = single_character_map (uc); - mapped_count = 1; + /* Fetch the next character. */ + ucs4_t uc; + int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); + + ucs4_t (*single_character_map) (ucs4_t); + size_t offset_in_rule; /* offset in 'struct special_casing_rule' */ + + ucs4_t mapped_uc[3]; + unsigned int mapped_count; + + if (*wp) + /* Crossing a word boundary. */ + in_word_first_part = true; + + /* Determine single_character_map, offset_in_rule. + There are three possibilities: + - uc should not be converted. + - uc should be titlecased. + - uc should be lowercased. */ + if (in_word_first_part) + { + if (uc_is_cased (uc)) + { + /* uc is to be titlecased. */ + single_character_map = uc_totitle; + offset_in_rule = offsetof (struct special_casing_rule, title[0]); + in_word_first_part = false; + } + else + { + /* uc is not converted. */ + single_character_map = NULL; + offset_in_rule = 0; + } + } + else + { + /* uc is to be lowercased. */ + single_character_map = uc_tolower; + offset_in_rule = offsetof (struct special_casing_rule, lower[0]); + } + + /* Actually map uc. */ + if (single_character_map == NULL) + { + mapped_uc[0] = uc; + mapped_count = 1; + goto found_mapping; + } + + if (uc < 0x10000) + { + /* Look first in the special-casing table. */ + char code[3]; + + code[0] = (uc >> 8) & 0xff; + code[1] = uc & 0xff; + + for (code[2] = 0; ; code[2]++) + { + const struct special_casing_rule *rule = + gl_unicase_special_lookup (code, 3); + + if (rule == NULL) + break; + + /* Test if the condition applies. */ + /* Does the language apply? */ + if (rule->language[0] == '\0' + || (iso639_language != NULL + && iso639_language[0] == rule->language[0] + && iso639_language[1] == rule->language[1])) + { + /* Does the context apply? */ + int context = rule->context; + bool applies; + + if (context < 0) + context = - context; + switch (context) + { + case SCC_ALWAYS: + applies = true; + break; + + case SCC_FINAL_SIGMA: + /* "Before" condition: preceded by a sequence + consisting of a cased letter and a case-ignorable + sequence. + "After" condition: not followed by a sequence + consisting of a case-ignorable sequence and then a + cased letter. */ + /* Test the "before" condition. */ + applies = uc_is_cased (last_char_except_ignorable); + /* Test the "after" condition. */ + if (applies) + { + const UNIT *s2 = s + count; + for (;;) + { + if (s2 < s_end) + { + ucs4_t uc2; + int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); + /* Our uc_is_case_ignorable function is + known to return false for all cased + characters. So we can call + uc_is_case_ignorable first. */ + if (!uc_is_case_ignorable (uc2)) + { + applies = ! uc_is_cased (uc2); + break; + } + s2 += count2; + } + else + { + applies = ! uc_is_cased (suffix_context.first_char_except_ignorable); + break; + } + } + } + break; + + case SCC_AFTER_SOFT_DOTTED: + /* "Before" condition: There is a Soft_Dotted character + before it, with no intervening character of + combining class 0 or 230 (Above). */ + /* Test the "before" condition. */ + applies = uc_is_property_soft_dotted (last_char_normal_or_above); + break; + + case SCC_MORE_ABOVE: + /* "After" condition: followed by a character of + combining class 230 (Above) with no intervening + character of combining class 0 or 230 (Above). */ + /* Test the "after" condition. */ + { + const UNIT *s2 = s + count; + applies = false; + for (;;) + { + if (s2 < s_end) + { + ucs4_t uc2; + int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); + int ccc = uc_combining_class (uc2); + if (ccc == UC_CCC_A) + { + applies = true; + break; + } + if (ccc == UC_CCC_NR) + break; + s2 += count2; + } + else + { + applies = ((suffix_context.bits & SCC_MORE_ABOVE_MASK) != 0); + break; + } + } + } + break; + + case SCC_BEFORE_DOT: + /* "After" condition: followed by COMBINING DOT ABOVE + (U+0307). Any sequence of characters with a + combining class that is neither 0 nor 230 may + intervene between the current character and the + combining dot above. */ + /* Test the "after" condition. */ + { + const UNIT *s2 = s + count; + applies = false; + for (;;) + { + if (s2 < s_end) + { + ucs4_t uc2; + int count2 = U_MBTOUC_UNSAFE (&uc2, s2, s_end - s2); + if (uc2 == 0x0307) /* COMBINING DOT ABOVE */ + { + applies = true; + break; + } + { + int ccc = uc_combining_class (uc2); + if (ccc == UC_CCC_A || ccc == UC_CCC_NR) + break; + } + s2 += count2; + } + else + { + applies = ((suffix_context.bits & SCC_BEFORE_DOT_MASK) != 0); + break; + } + } + } + break; + + case SCC_AFTER_I: + /* "Before" condition: There is an uppercase I before + it, and there is no intervening character of + combining class 0 or 230 (Above). */ + /* Test the "before" condition. */ + applies = (last_char_normal_or_above == 'I'); + break; + + default: + abort (); + } + if (rule->context < 0) + applies = !applies; + + if (applies) + { + /* The rule applies. + Look up the mapping (0 to 3 characters). */ + const unsigned short *mapped_in_rule = + (const unsigned short *)((const char *)rule + offset_in_rule); + + if (mapped_in_rule[0] == 0) + mapped_count = 0; + else + { + mapped_uc[0] = mapped_in_rule[0]; + if (mapped_in_rule[1] == 0) + mapped_count = 1; + else + { + mapped_uc[1] = mapped_in_rule[1]; + if (mapped_in_rule[2] == 0) + mapped_count = 2; + else + { + mapped_uc[2] = mapped_in_rule[2]; + mapped_count = 3; + } + } + } + goto found_mapping; + } + } + + /* Optimization: Save a hash table lookup in the next round. */ + if (!rule->has_next) + break; + } + } + + /* No special-cased mapping. So use the locale and context independent + mapping. */ + mapped_uc[0] = single_character_map (uc); + mapped_count = 1; found_mapping: - /* Found the mapping: uc maps to mapped_uc[0..mapped_count-1]. */ - { - unsigned int i; - - for (i = 0; i < mapped_count; i++) - { - ucs4_t muc = mapped_uc[i]; - - /* Append muc to the result accumulator. */ - if (length < allocated) - { - int ret = U_UCTOMB (result + length, muc, allocated - length); - if (ret == -1) - { - errno = EINVAL; - goto fail1; - } - if (ret >= 0) - { - length += ret; - goto done_appending; - } - } - { - size_t old_allocated = allocated; - size_t new_allocated = 2 * old_allocated; - if (new_allocated < 64) - new_allocated = 64; - if (new_allocated < old_allocated) /* integer overflow? */ - abort (); - { - UNIT *larger_result; - if (result == NULL) - { - larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail1; - } - } - else if (result == resultbuf) - { - larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail1; - } - U_CPY (larger_result, resultbuf, length); - } - else - { - larger_result = - (UNIT *) realloc (result, new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail1; - } - } - result = larger_result; - allocated = new_allocated; - { - int ret = U_UCTOMB (result + length, muc, allocated - length); - if (ret == -1) - { - errno = EINVAL; - goto fail1; - } - if (ret < 0) - abort (); - length += ret; - goto done_appending; - } - } - } - done_appending: ; - } - } - - if (!uc_is_case_ignorable (uc)) - last_char_except_ignorable = uc; - - { - int ccc = uc_combining_class (uc); - if (ccc == UC_CCC_A || ccc == UC_CCC_NR) - last_char_normal_or_above = uc; - } - - s += count; - wp += count; + /* Found the mapping: uc maps to mapped_uc[0..mapped_count-1]. */ + { + unsigned int i; + + for (i = 0; i < mapped_count; i++) + { + ucs4_t muc = mapped_uc[i]; + + /* Append muc to the result accumulator. */ + if (length < allocated) + { + int ret = U_UCTOMB (result + length, muc, allocated - length); + if (ret == -1) + { + errno = EINVAL; + goto fail1; + } + if (ret >= 0) + { + length += ret; + goto done_appending; + } + } + { + size_t old_allocated = allocated; + size_t new_allocated = 2 * old_allocated; + if (new_allocated < 64) + new_allocated = 64; + if (new_allocated < old_allocated) /* integer overflow? */ + abort (); + { + UNIT *larger_result; + if (result == NULL) + { + larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail1; + } + } + else if (result == resultbuf) + { + larger_result = (UNIT *) malloc (new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail1; + } + U_CPY (larger_result, resultbuf, length); + } + else + { + larger_result = + (UNIT *) realloc (result, new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail1; + } + } + result = larger_result; + allocated = new_allocated; + { + int ret = U_UCTOMB (result + length, muc, allocated - length); + if (ret == -1) + { + errno = EINVAL; + goto fail1; + } + if (ret < 0) + abort (); + length += ret; + goto done_appending; + } + } + } + done_appending: ; + } + } + + if (!uc_is_case_ignorable (uc)) + last_char_except_ignorable = uc; + + { + int ccc = uc_combining_class (uc); + if (ccc == UC_CCC_A || ccc == UC_CCC_NR) + last_char_normal_or_above = uc; + } + + s += count; + wp += count; } } @@ -452,7 +452,7 @@ FUNC (const UNIT *s, size_t n, normalized_result = U_NORMALIZE (nf, result, length, resultbuf, lengthp); if (normalized_result == NULL) - goto fail2; + goto fail2; free (result); return normalized_result; @@ -461,15 +461,15 @@ FUNC (const UNIT *s, size_t n, if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - goto fail2; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + goto fail2; + } + } } else if (result != resultbuf && length < allocated) { @@ -478,7 +478,7 @@ FUNC (const UNIT *s, size_t n, memory = (UNIT *) realloc (result, length * sizeof (UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unicase/u-is-cased.h b/lib/unicase/u-is-cased.h index b96a60f0..c187a30e 100644 --- a/lib/unicase/u-is-cased.h +++ b/lib/unicase/u-is-cased.h @@ -1,5 +1,5 @@ /* Test whether case matters for a Unicode string. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -39,30 +39,30 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, /* Apply toupper mapping. */ mapped_toupper = U_TOUPPER (norms, norms_length, iso639_language, NULL, - mappedbuf, &mapped_length); + mappedbuf, &mapped_length); if (mapped_toupper == NULL) goto fail; /* Compare. */ if (!(mapped_length == norms_length - && U_CMP (mapped_toupper, norms, norms_length) == 0)) + && U_CMP (mapped_toupper, norms, norms_length) == 0)) { if (mapped_toupper != mappedbuf) - free (mapped_toupper); + free (mapped_toupper); goto yes; } /* Apply tolower mapping. */ mapped_tolower = U_TOLOWER (norms, norms_length, iso639_language, NULL, - mapped_toupper, &mapped_length); + mapped_toupper, &mapped_length); if (mapped_tolower == NULL) { if (mapped_toupper != mappedbuf) - { - int saved_errno = errno; - free (mapped_toupper); - errno = saved_errno; - } + { + int saved_errno = errno; + free (mapped_toupper); + errno = saved_errno; + } goto fail; } @@ -71,24 +71,24 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, /* Compare. */ if (!(mapped_length == norms_length - && U_CMP (mapped_tolower, norms, norms_length) == 0)) + && U_CMP (mapped_tolower, norms, norms_length) == 0)) { if (mapped_tolower != mappedbuf) - free (mapped_tolower); + free (mapped_tolower); goto yes; } /* Apply totitle mapping. */ mapped_totitle = U_TOTITLE (norms, norms_length, iso639_language, NULL, - mapped_tolower, &mapped_length); + mapped_tolower, &mapped_length); if (mapped_totitle == NULL) { if (mapped_tolower != mappedbuf) - { - int saved_errno = errno; - free (mapped_tolower); - errno = saved_errno; - } + { + int saved_errno = errno; + free (mapped_tolower); + errno = saved_errno; + } goto fail; } @@ -97,10 +97,10 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, /* Compare. */ if (!(mapped_length == norms_length - && U_CMP (mapped_totitle, norms, norms_length) == 0)) + && U_CMP (mapped_totitle, norms, norms_length) == 0)) { if (mapped_totitle != mappedbuf) - free (mapped_totitle); + free (mapped_totitle); goto yes; } diff --git a/lib/unicase/u-is-invariant.h b/lib/unicase/u-is-invariant.h index e6b7fbb4..541dd8df 100644 --- a/lib/unicase/u-is-invariant.h +++ b/lib/unicase/u-is-invariant.h @@ -1,5 +1,5 @@ /* Test whether a Unicode string is invariant under a given case mapping. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -18,8 +18,8 @@ int FUNC (const UNIT *s, size_t n, UNIT * (*mapping) (const UNIT *s, size_t n, const char *iso639_language, - uninorm_t nf, - UNIT *resultbuf, size_t *lengthp), + uninorm_t nf, + UNIT *resultbuf, size_t *lengthp), const char *iso639_language, bool *resultp) { @@ -40,21 +40,21 @@ FUNC (const UNIT *s, size_t n, /* Apply mapping. */ mapped_length = sizeof (mappedbuf) / sizeof (UNIT); mapped = mapping (norms, norms_length, iso639_language, NULL, - mappedbuf, &mapped_length); + mappedbuf, &mapped_length); if (mapped == NULL) { if (norms != normsbuf) - { - int saved_errno = errno; - free (norms); - errno = saved_errno; - } + { + int saved_errno = errno; + free (norms); + errno = saved_errno; + } return -1; } /* Compare. */ *resultp = (mapped_length == norms_length - && U_CMP (mapped, norms, norms_length) == 0); + && U_CMP (mapped, norms, norms_length) == 0); if (mapped != mappedbuf) free (mapped); diff --git a/lib/unicase/u-totitle.h b/lib/unicase/u-totitle.h index 431f000a..658c95fd 100644 --- a/lib/unicase/u-totitle.h +++ b/lib/unicase/u-totitle.h @@ -1,5 +1,5 @@ /* Titlecase mapping for UTF-8/UTF-16/UTF-32 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -21,8 +21,8 @@ FUNC (const UNIT *s, size_t n, const char *iso639_language, UNIT *resultbuf, size_t *lengthp) { return U_CT_TOTITLE (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u16-casecmp.c b/lib/unicase/u16-casecmp.c index 1110874e..e6780a99 100644 --- a/lib/unicase/u16-casecmp.c +++ b/lib/unicase/u16-casecmp.c @@ -1,5 +1,5 @@ /* Case and normalization insensitive comparison of UTF-16 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u16-casecoll.c b/lib/unicase/u16-casecoll.c index 882039cf..986bdb85 100644 --- a/lib/unicase/u16-casecoll.c +++ b/lib/unicase/u16-casecoll.c @@ -1,6 +1,6 @@ /* Locale dependent, case and normalization insensitive comparison of UTF-16 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u16-casefold.c b/lib/unicase/u16-casefold.c index 55522753..037d51fa 100644 --- a/lib/unicase/u16-casefold.c +++ b/lib/unicase/u16-casefold.c @@ -1,5 +1,5 @@ /* Casefolding mapping for UTF-16 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u16-casemap.c b/lib/unicase/u16-casemap.c index 0766de92..b8021e7f 100644 --- a/lib/unicase/u16-casemap.c +++ b/lib/unicase/u16-casemap.c @@ -1,5 +1,5 @@ /* Case mapping for UTF-16 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u16-casexfrm.c b/lib/unicase/u16-casexfrm.c index 09d08ce1..661902fc 100644 --- a/lib/unicase/u16-casexfrm.c +++ b/lib/unicase/u16-casexfrm.c @@ -1,6 +1,6 @@ /* Locale dependent transformation for case insensitive comparison of UTF-16 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u16-ct-casefold.c b/lib/unicase/u16-ct-casefold.c index 6dff77d7..65e49e75 100644 --- a/lib/unicase/u16-ct-casefold.c +++ b/lib/unicase/u16-ct-casefold.c @@ -1,5 +1,5 @@ /* Casefolding mapping for UTF-16 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u16-ct-tolower.c b/lib/unicase/u16-ct-tolower.c index 36b34e04..2b09c7e1 100644 --- a/lib/unicase/u16-ct-tolower.c +++ b/lib/unicase/u16-ct-tolower.c @@ -1,5 +1,5 @@ /* Lowercase mapping for UTF-16 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,14 +27,14 @@ uint16_t * u16_ct_tolower (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp) + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp) { return u16_casemap (s, n, prefix_context, suffix_context, iso639_language, - uc_tolower, offsetof (struct special_casing_rule, lower[0]), - nf, - resultbuf, lengthp); + uc_tolower, offsetof (struct special_casing_rule, lower[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u16-ct-totitle.c b/lib/unicase/u16-ct-totitle.c index c01021b8..095bd9f4 100644 --- a/lib/unicase/u16-ct-totitle.c +++ b/lib/unicase/u16-ct-totitle.c @@ -1,5 +1,5 @@ /* Titlecase mapping for UTF-16 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u16-ct-toupper.c b/lib/unicase/u16-ct-toupper.c index 029c74b4..d26f6c5a 100644 --- a/lib/unicase/u16-ct-toupper.c +++ b/lib/unicase/u16-ct-toupper.c @@ -1,5 +1,5 @@ /* Uppercase mapping for UTF-16 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,14 +27,14 @@ uint16_t * u16_ct_toupper (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp) + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp) { return u16_casemap (s, n, prefix_context, suffix_context, iso639_language, - uc_toupper, offsetof (struct special_casing_rule, upper[0]), - nf, - resultbuf, lengthp); + uc_toupper, offsetof (struct special_casing_rule, upper[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u16-is-cased.c b/lib/unicase/u16-is-cased.c index c2196cef..385c01a7 100644 --- a/lib/unicase/u16-is-cased.c +++ b/lib/unicase/u16-is-cased.c @@ -1,5 +1,5 @@ /* Test whether case matters for an UTF-16 string. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u16-is-casefolded.c b/lib/unicase/u16-is-casefolded.c index 64a4ec18..dd3b6c17 100644 --- a/lib/unicase/u16-is-casefolded.c +++ b/lib/unicase/u16-is-casefolded.c @@ -1,5 +1,5 @@ /* Test whether an UTF-16 string is already case-folded. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,7 +24,7 @@ int u16_is_casefolded (const uint16_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u16_is_invariant (s, n, u16_casefold, iso639_language, resultp); } diff --git a/lib/unicase/u16-is-invariant.c b/lib/unicase/u16-is-invariant.c index cace25a7..a7f40da3 100644 --- a/lib/unicase/u16-is-invariant.c +++ b/lib/unicase/u16-is-invariant.c @@ -1,5 +1,5 @@ /* Test whether an UTF-16 string is invariant under a given case mapping. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -21,6 +21,7 @@ #include "unicase/invariant.h" #include +#include #include #include "uninorm.h" diff --git a/lib/unicase/u16-is-lowercase.c b/lib/unicase/u16-is-lowercase.c index 36a01512..de51a04a 100644 --- a/lib/unicase/u16-is-lowercase.c +++ b/lib/unicase/u16-is-lowercase.c @@ -1,5 +1,5 @@ /* Test whether an UTF-16 string is entirely lower case. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,7 +24,7 @@ int u16_is_lowercase (const uint16_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u16_is_invariant (s, n, u16_tolower, iso639_language, resultp); } diff --git a/lib/unicase/u16-is-titlecase.c b/lib/unicase/u16-is-titlecase.c index 19aacea1..4192aad3 100644 --- a/lib/unicase/u16-is-titlecase.c +++ b/lib/unicase/u16-is-titlecase.c @@ -1,5 +1,5 @@ /* Test whether an UTF-16 string is entirely title case. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,7 +24,7 @@ int u16_is_titlecase (const uint16_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u16_is_invariant (s, n, u16_totitle, iso639_language, resultp); } diff --git a/lib/unicase/u16-is-uppercase.c b/lib/unicase/u16-is-uppercase.c index 53e697fd..509c9bb0 100644 --- a/lib/unicase/u16-is-uppercase.c +++ b/lib/unicase/u16-is-uppercase.c @@ -1,5 +1,5 @@ /* Test whether an UTF-16 string is entirely upper case. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,7 +24,7 @@ int u16_is_uppercase (const uint16_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u16_is_invariant (s, n, u16_toupper, iso639_language, resultp); } diff --git a/lib/unicase/u16-tolower.c b/lib/unicase/u16-tolower.c index 0629cb4d..c931cca9 100644 --- a/lib/unicase/u16-tolower.c +++ b/lib/unicase/u16-tolower.c @@ -1,5 +1,5 @@ /* Lowercase mapping for UTF-16 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,13 +27,13 @@ uint16_t * u16_tolower (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp) { return u16_casemap (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - uc_tolower, offsetof (struct special_casing_rule, lower[0]), - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + uc_tolower, offsetof (struct special_casing_rule, lower[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u16-totitle.c b/lib/unicase/u16-totitle.c index e0d14e83..f7c59462 100644 --- a/lib/unicase/u16-totitle.c +++ b/lib/unicase/u16-totitle.c @@ -1,5 +1,5 @@ /* Titlecase mapping for UTF-16 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u16-toupper.c b/lib/unicase/u16-toupper.c index f92989aa..12e888aa 100644 --- a/lib/unicase/u16-toupper.c +++ b/lib/unicase/u16-toupper.c @@ -1,5 +1,5 @@ /* Uppercase mapping for UTF-16 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,13 +27,13 @@ uint16_t * u16_toupper (const uint16_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp) { return u16_casemap (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - uc_toupper, offsetof (struct special_casing_rule, upper[0]), - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + uc_toupper, offsetof (struct special_casing_rule, upper[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u32-casecmp.c b/lib/unicase/u32-casecmp.c index e964915f..7b67bb1c 100644 --- a/lib/unicase/u32-casecmp.c +++ b/lib/unicase/u32-casecmp.c @@ -1,5 +1,5 @@ /* Case and normalization insensitive comparison of UTF-32 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u32-casecoll.c b/lib/unicase/u32-casecoll.c index 88d994a0..6d1d772d 100644 --- a/lib/unicase/u32-casecoll.c +++ b/lib/unicase/u32-casecoll.c @@ -1,6 +1,6 @@ /* Locale dependent, case and normalization insensitive comparison of UTF-32 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u32-casefold.c b/lib/unicase/u32-casefold.c index aff44f82..d1a13410 100644 --- a/lib/unicase/u32-casefold.c +++ b/lib/unicase/u32-casefold.c @@ -1,5 +1,5 @@ /* Casefolding mapping for UTF-32 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u32-casemap.c b/lib/unicase/u32-casemap.c index 43e2641c..6c8213ca 100644 --- a/lib/unicase/u32-casemap.c +++ b/lib/unicase/u32-casemap.c @@ -1,5 +1,5 @@ /* Case mapping for UTF-32 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u32-casexfrm.c b/lib/unicase/u32-casexfrm.c index cf8fee67..bd54497b 100644 --- a/lib/unicase/u32-casexfrm.c +++ b/lib/unicase/u32-casexfrm.c @@ -1,6 +1,6 @@ /* Locale dependent transformation for case insensitive comparison of UTF-32 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u32-ct-casefold.c b/lib/unicase/u32-ct-casefold.c index e206b677..f360cce7 100644 --- a/lib/unicase/u32-ct-casefold.c +++ b/lib/unicase/u32-ct-casefold.c @@ -1,5 +1,5 @@ /* Casefolding mapping for UTF-32 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u32-ct-tolower.c b/lib/unicase/u32-ct-tolower.c index 83e9fa84..7df6a563 100644 --- a/lib/unicase/u32-ct-tolower.c +++ b/lib/unicase/u32-ct-tolower.c @@ -1,5 +1,5 @@ /* Lowercase mapping for UTF-32 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,14 +27,14 @@ uint32_t * u32_ct_tolower (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp) + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp) { return u32_casemap (s, n, prefix_context, suffix_context, iso639_language, - uc_tolower, offsetof (struct special_casing_rule, lower[0]), - nf, - resultbuf, lengthp); + uc_tolower, offsetof (struct special_casing_rule, lower[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u32-ct-totitle.c b/lib/unicase/u32-ct-totitle.c index f2a38782..d9f51bb7 100644 --- a/lib/unicase/u32-ct-totitle.c +++ b/lib/unicase/u32-ct-totitle.c @@ -1,5 +1,5 @@ /* Titlecase mapping for UTF-32 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u32-ct-toupper.c b/lib/unicase/u32-ct-toupper.c index 9043ddeb..e6165564 100644 --- a/lib/unicase/u32-ct-toupper.c +++ b/lib/unicase/u32-ct-toupper.c @@ -1,5 +1,5 @@ /* Uppercase mapping for UTF-32 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,14 +27,14 @@ uint32_t * u32_ct_toupper (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp) + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp) { return u32_casemap (s, n, prefix_context, suffix_context, iso639_language, - uc_toupper, offsetof (struct special_casing_rule, upper[0]), - nf, - resultbuf, lengthp); + uc_toupper, offsetof (struct special_casing_rule, upper[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u32-is-cased.c b/lib/unicase/u32-is-cased.c index 783e57e9..e836dc15 100644 --- a/lib/unicase/u32-is-cased.c +++ b/lib/unicase/u32-is-cased.c @@ -1,5 +1,5 @@ /* Test whether case matters for an UTF-32 string. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u32-is-casefolded.c b/lib/unicase/u32-is-casefolded.c index a71c767d..6c2bbb0e 100644 --- a/lib/unicase/u32-is-casefolded.c +++ b/lib/unicase/u32-is-casefolded.c @@ -1,5 +1,5 @@ /* Test whether an UTF-32 string is already case-folded. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,7 +24,7 @@ int u32_is_casefolded (const uint32_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u32_is_invariant (s, n, u32_casefold, iso639_language, resultp); } diff --git a/lib/unicase/u32-is-invariant.c b/lib/unicase/u32-is-invariant.c index 190a30fe..aea4c61e 100644 --- a/lib/unicase/u32-is-invariant.c +++ b/lib/unicase/u32-is-invariant.c @@ -1,5 +1,5 @@ /* Test whether an UTF-32 string is invariant under a given case mapping. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -21,6 +21,7 @@ #include "unicase/invariant.h" #include +#include #include #include "uninorm.h" diff --git a/lib/unicase/u32-is-lowercase.c b/lib/unicase/u32-is-lowercase.c index 104afaae..cc2fa2dc 100644 --- a/lib/unicase/u32-is-lowercase.c +++ b/lib/unicase/u32-is-lowercase.c @@ -1,5 +1,5 @@ /* Test whether an UTF-32 string is entirely lower case. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,7 +24,7 @@ int u32_is_lowercase (const uint32_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u32_is_invariant (s, n, u32_tolower, iso639_language, resultp); } diff --git a/lib/unicase/u32-is-titlecase.c b/lib/unicase/u32-is-titlecase.c index 5b07c8dd..ee48fc73 100644 --- a/lib/unicase/u32-is-titlecase.c +++ b/lib/unicase/u32-is-titlecase.c @@ -1,5 +1,5 @@ /* Test whether an UTF-32 string is entirely title case. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,7 +24,7 @@ int u32_is_titlecase (const uint32_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u32_is_invariant (s, n, u32_totitle, iso639_language, resultp); } diff --git a/lib/unicase/u32-is-uppercase.c b/lib/unicase/u32-is-uppercase.c index bb38fc69..369a68b9 100644 --- a/lib/unicase/u32-is-uppercase.c +++ b/lib/unicase/u32-is-uppercase.c @@ -1,5 +1,5 @@ /* Test whether an UTF-32 string is entirely upper case. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,7 +24,7 @@ int u32_is_uppercase (const uint32_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u32_is_invariant (s, n, u32_toupper, iso639_language, resultp); } diff --git a/lib/unicase/u32-tolower.c b/lib/unicase/u32-tolower.c index daa5c4d3..b9c53eda 100644 --- a/lib/unicase/u32-tolower.c +++ b/lib/unicase/u32-tolower.c @@ -1,5 +1,5 @@ /* Lowercase mapping for UTF-32 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,13 +27,13 @@ uint32_t * u32_tolower (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp) { return u32_casemap (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - uc_tolower, offsetof (struct special_casing_rule, lower[0]), - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + uc_tolower, offsetof (struct special_casing_rule, lower[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u32-totitle.c b/lib/unicase/u32-totitle.c index 21e1b0d1..d144ae75 100644 --- a/lib/unicase/u32-totitle.c +++ b/lib/unicase/u32-totitle.c @@ -1,5 +1,5 @@ /* Titlecase mapping for UTF-32 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u32-toupper.c b/lib/unicase/u32-toupper.c index 3430ad95..d58c8e24 100644 --- a/lib/unicase/u32-toupper.c +++ b/lib/unicase/u32-toupper.c @@ -1,5 +1,5 @@ /* Uppercase mapping for UTF-32 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,13 +27,13 @@ uint32_t * u32_toupper (const uint32_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp) { return u32_casemap (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - uc_toupper, offsetof (struct special_casing_rule, upper[0]), - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + uc_toupper, offsetof (struct special_casing_rule, upper[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u8-casecmp.c b/lib/unicase/u8-casecmp.c index 4a55de91..4edbfc35 100644 --- a/lib/unicase/u8-casecmp.c +++ b/lib/unicase/u8-casecmp.c @@ -1,5 +1,5 @@ /* Case and normalization insensitive comparison of UTF-8 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u8-casecoll.c b/lib/unicase/u8-casecoll.c index 28170e54..694011c9 100644 --- a/lib/unicase/u8-casecoll.c +++ b/lib/unicase/u8-casecoll.c @@ -1,6 +1,6 @@ /* Locale dependent, case and normalization insensitive comparison of UTF-8 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u8-casefold.c b/lib/unicase/u8-casefold.c index 32108137..e3c91771 100644 --- a/lib/unicase/u8-casefold.c +++ b/lib/unicase/u8-casefold.c @@ -1,5 +1,5 @@ /* Casefolding mapping for UTF-8 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -47,28 +47,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -92,9 +92,9 @@ main (int argc, char * argv[]) int length = strlen (input); size_t output_length; uint8_t *output = - u8_casefold ((uint8_t *) input, length, uc_locale_language (), - NULL, - NULL, &output_length); + u8_casefold ((uint8_t *) input, length, uc_locale_language (), + NULL, + NULL, &output_length); fwrite (output, 1, output_length, stdout); diff --git a/lib/unicase/u8-casemap.c b/lib/unicase/u8-casemap.c index 6f329155..9e4d0c09 100644 --- a/lib/unicase/u8-casemap.c +++ b/lib/unicase/u8-casemap.c @@ -1,5 +1,5 @@ /* Case mapping for UTF-8 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u8-casexfrm.c b/lib/unicase/u8-casexfrm.c index 7e1d767c..b3e0c664 100644 --- a/lib/unicase/u8-casexfrm.c +++ b/lib/unicase/u8-casexfrm.c @@ -1,6 +1,6 @@ /* Locale dependent transformation for case insensitive comparison of UTF-8 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u8-ct-casefold.c b/lib/unicase/u8-ct-casefold.c index 4cc149c3..45bacfc5 100644 --- a/lib/unicase/u8-ct-casefold.c +++ b/lib/unicase/u8-ct-casefold.c @@ -1,5 +1,5 @@ /* Casefolding mapping for UTF-8 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u8-ct-tolower.c b/lib/unicase/u8-ct-tolower.c index 3755821e..1b0ee33c 100644 --- a/lib/unicase/u8-ct-tolower.c +++ b/lib/unicase/u8-ct-tolower.c @@ -1,5 +1,5 @@ /* Lowercase mapping for UTF-8 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,14 +27,14 @@ uint8_t * u8_ct_tolower (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp) + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp) { return u8_casemap (s, n, prefix_context, suffix_context, iso639_language, - uc_tolower, offsetof (struct special_casing_rule, lower[0]), - nf, - resultbuf, lengthp); + uc_tolower, offsetof (struct special_casing_rule, lower[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u8-ct-totitle.c b/lib/unicase/u8-ct-totitle.c index 64891afd..7bcdc0dc 100644 --- a/lib/unicase/u8-ct-totitle.c +++ b/lib/unicase/u8-ct-totitle.c @@ -1,5 +1,5 @@ /* Titlecase mapping for UTF-8 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u8-ct-toupper.c b/lib/unicase/u8-ct-toupper.c index 9dca2fca..c22b25af 100644 --- a/lib/unicase/u8-ct-toupper.c +++ b/lib/unicase/u8-ct-toupper.c @@ -1,5 +1,5 @@ /* Uppercase mapping for UTF-8 substrings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,14 +27,14 @@ uint8_t * u8_ct_toupper (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp) + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp) { return u8_casemap (s, n, prefix_context, suffix_context, iso639_language, - uc_toupper, offsetof (struct special_casing_rule, upper[0]), - nf, - resultbuf, lengthp); + uc_toupper, offsetof (struct special_casing_rule, upper[0]), + nf, + resultbuf, lengthp); } diff --git a/lib/unicase/u8-is-cased.c b/lib/unicase/u8-is-cased.c index 5cdcc33b..56fc9c7c 100644 --- a/lib/unicase/u8-is-cased.c +++ b/lib/unicase/u8-is-cased.c @@ -1,5 +1,5 @@ /* Test whether case matters for an UTF-8 string. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/u8-is-casefolded.c b/lib/unicase/u8-is-casefolded.c index 30122b78..007a5126 100644 --- a/lib/unicase/u8-is-casefolded.c +++ b/lib/unicase/u8-is-casefolded.c @@ -1,5 +1,5 @@ /* Test whether an UTF-8 string is already case-folded. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,7 +24,7 @@ int u8_is_casefolded (const uint8_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u8_is_invariant (s, n, u8_casefold, iso639_language, resultp); } diff --git a/lib/unicase/u8-is-invariant.c b/lib/unicase/u8-is-invariant.c index 2c4913bf..4794e567 100644 --- a/lib/unicase/u8-is-invariant.c +++ b/lib/unicase/u8-is-invariant.c @@ -1,5 +1,5 @@ /* Test whether an UTF-8 string is invariant under a given case mapping. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -21,6 +21,7 @@ #include "unicase/invariant.h" #include +#include #include #include "uninorm.h" diff --git a/lib/unicase/u8-is-lowercase.c b/lib/unicase/u8-is-lowercase.c index 5b0df8be..8501614e 100644 --- a/lib/unicase/u8-is-lowercase.c +++ b/lib/unicase/u8-is-lowercase.c @@ -1,5 +1,5 @@ /* Test whether an UTF-8 string is entirely lower case. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,7 +24,7 @@ int u8_is_lowercase (const uint8_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u8_is_invariant (s, n, u8_tolower, iso639_language, resultp); } diff --git a/lib/unicase/u8-is-titlecase.c b/lib/unicase/u8-is-titlecase.c index 474502a7..6357a34e 100644 --- a/lib/unicase/u8-is-titlecase.c +++ b/lib/unicase/u8-is-titlecase.c @@ -1,5 +1,5 @@ /* Test whether an UTF-8 string is entirely title case. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,7 +24,7 @@ int u8_is_titlecase (const uint8_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u8_is_invariant (s, n, u8_totitle, iso639_language, resultp); } diff --git a/lib/unicase/u8-is-uppercase.c b/lib/unicase/u8-is-uppercase.c index 7f14f924..817579f3 100644 --- a/lib/unicase/u8-is-uppercase.c +++ b/lib/unicase/u8-is-uppercase.c @@ -1,5 +1,5 @@ /* Test whether an UTF-8 string is entirely upper case. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -24,7 +24,7 @@ int u8_is_uppercase (const uint8_t *s, size_t n, const char *iso639_language, - bool *resultp) + bool *resultp) { return u8_is_invariant (s, n, u8_toupper, iso639_language, resultp); } diff --git a/lib/unicase/u8-tolower.c b/lib/unicase/u8-tolower.c index 1cd7cfa4..f657feb3 100644 --- a/lib/unicase/u8-tolower.c +++ b/lib/unicase/u8-tolower.c @@ -1,5 +1,5 @@ /* Lowercase mapping for UTF-8 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,15 +27,15 @@ uint8_t * u8_tolower (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp) { return u8_casemap (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - uc_tolower, offsetof (struct special_casing_rule, lower[0]), - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + uc_tolower, offsetof (struct special_casing_rule, lower[0]), + nf, + resultbuf, lengthp); } @@ -60,28 +60,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -105,9 +105,9 @@ main (int argc, char * argv[]) int length = strlen (input); size_t output_length; uint8_t *output = - u8_tolower ((uint8_t *) input, length, uc_locale_language (), - NULL, - NULL, &output_length); + u8_tolower ((uint8_t *) input, length, uc_locale_language (), + NULL, + NULL, &output_length); fwrite (output, 1, output_length, stdout); diff --git a/lib/unicase/u8-totitle.c b/lib/unicase/u8-totitle.c index cf29c1ba..e63cda9e 100644 --- a/lib/unicase/u8-totitle.c +++ b/lib/unicase/u8-totitle.c @@ -1,5 +1,5 @@ /* Titlecase mapping for UTF-8 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -47,28 +47,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -92,9 +92,9 @@ main (int argc, char * argv[]) int length = strlen (input); size_t output_length; uint8_t *output = - u8_toupper ((uint8_t *) input, length, uc_locale_language (), - NULL, - NULL, &output_length); + u8_toupper ((uint8_t *) input, length, uc_locale_language (), + NULL, + NULL, &output_length); fwrite (output, 1, output_length, stdout); diff --git a/lib/unicase/u8-toupper.c b/lib/unicase/u8-toupper.c index a97d98ce..7429e525 100644 --- a/lib/unicase/u8-toupper.c +++ b/lib/unicase/u8-toupper.c @@ -1,5 +1,5 @@ /* Uppercase mapping for UTF-8 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,15 +27,15 @@ uint8_t * u8_toupper (const uint8_t *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp) { return u8_casemap (s, n, - unicase_empty_prefix_context, unicase_empty_suffix_context, - iso639_language, - uc_toupper, offsetof (struct special_casing_rule, upper[0]), - nf, - resultbuf, lengthp); + unicase_empty_prefix_context, unicase_empty_suffix_context, + iso639_language, + uc_toupper, offsetof (struct special_casing_rule, upper[0]), + nf, + resultbuf, lengthp); } @@ -60,28 +60,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -105,9 +105,9 @@ main (int argc, char * argv[]) int length = strlen (input); size_t output_length; uint8_t *output = - u8_toupper ((uint8_t *) input, length, uc_locale_language (), - NULL, - NULL, &output_length); + u8_toupper ((uint8_t *) input, length, uc_locale_language (), + NULL, + NULL, &output_length); fwrite (output, 1, output_length, stdout); diff --git a/lib/unicase/ulc-casecmp.c b/lib/unicase/ulc-casecmp.c index e0710219..1f343cd5 100644 --- a/lib/unicase/ulc-casecmp.c +++ b/lib/unicase/ulc-casecmp.c @@ -1,5 +1,5 @@ /* Case and normalization insensitive comparison of strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -30,8 +30,8 @@ static uint8_t * ulc_u8_casefold (const char *s, size_t n, const char *iso639_language, - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp) + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp) { uint8_t convbuf[2048 / sizeof (uint8_t)]; uint8_t *conv; @@ -42,22 +42,22 @@ ulc_u8_casefold (const char *s, size_t n, const char *iso639_language, conv_length = sizeof (convbuf) / sizeof (uint8_t); conv = u8_conv_from_encoding (locale_charset (), iconveh_error, s, n, NULL, - convbuf, &conv_length); + convbuf, &conv_length); if (conv == NULL) /* errno is set here. */ return NULL; /* Case-fold and normalize. */ result = u8_casefold (conv, conv_length, iso639_language, nf, - resultbuf, lengthp); + resultbuf, lengthp); if (result == NULL) { if (conv != convbuf) - { - int saved_errno = errno; - free (conv); - errno = saved_errno; - } + { + int saved_errno = errno; + free (conv); + errno = saved_errno; + } return NULL; } diff --git a/lib/unicase/ulc-casecoll.c b/lib/unicase/ulc-casecoll.c index 9730b6dc..9645e147 100644 --- a/lib/unicase/ulc-casecoll.c +++ b/lib/unicase/ulc-casecoll.c @@ -1,5 +1,5 @@ /* Locale dependent, case and normalization insensitive comparison of strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unicase/ulc-casexfrm.c b/lib/unicase/ulc-casexfrm.c index aded556f..89982116 100644 --- a/lib/unicase/ulc-casexfrm.c +++ b/lib/unicase/ulc-casexfrm.c @@ -1,5 +1,5 @@ /* Locale dependent transformation for case insensitive comparison of strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,8 +27,8 @@ char * ulc_casexfrm (const char *s, size_t n, const char *iso639_language, - uninorm_t nf, - char *resultbuf, size_t *lengthp) + uninorm_t nf, + char *resultbuf, size_t *lengthp) { uint8_t convbuf[2048 / sizeof (uint8_t)]; uint8_t *conv; @@ -39,22 +39,22 @@ ulc_casexfrm (const char *s, size_t n, const char *iso639_language, conv_length = sizeof (convbuf) / sizeof (uint8_t); conv = u8_conv_from_encoding (locale_charset (), iconveh_error, s, n, NULL, - convbuf, &conv_length); + convbuf, &conv_length); if (conv == NULL) /* errno is set here. */ return NULL; /* Case-fold and normalize. */ result = u8_casexfrm (conv, conv_length, iso639_language, nf, - resultbuf, lengthp); + resultbuf, lengthp); if (result == NULL) { if (conv != convbuf) - { - int saved_errno = errno; - free (conv); - errno = saved_errno; - } + { + int saved_errno = errno; + free (conv); + errno = saved_errno; + } return NULL; } diff --git a/lib/unicase/unicasemap.h b/lib/unicase/unicasemap.h index 8da8c51d..01880834 100644 --- a/lib/unicase/unicasemap.h +++ b/lib/unicase/unicasemap.h @@ -1,5 +1,5 @@ /* Case mapping for UTF-8/UTF-16/UTF-32 strings (locale dependent). - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -23,30 +23,30 @@ extern uint8_t * u8_casemap (const uint8_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - ucs4_t (*single_character_map) (ucs4_t), - size_t offset_in_rule, /* offset in 'struct special_casing_rule' */ - uninorm_t nf, - uint8_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + ucs4_t (*single_character_map) (ucs4_t), + size_t offset_in_rule, /* offset in 'struct special_casing_rule' */ + uninorm_t nf, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_casemap (const uint16_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - ucs4_t (*single_character_map) (ucs4_t), - size_t offset_in_rule, /* offset in 'struct special_casing_rule' */ - uninorm_t nf, - uint16_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + ucs4_t (*single_character_map) (ucs4_t), + size_t offset_in_rule, /* offset in 'struct special_casing_rule' */ + uninorm_t nf, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_casemap (const uint32_t *s, size_t n, - casing_prefix_context_t prefix_context, - casing_suffix_context_t suffix_context, - const char *iso639_language, - ucs4_t (*single_character_map) (ucs4_t), - size_t offset_in_rule, /* offset in 'struct special_casing_rule' */ - uninorm_t nf, - uint32_t *resultbuf, size_t *lengthp); + casing_prefix_context_t prefix_context, + casing_suffix_context_t suffix_context, + const char *iso639_language, + ucs4_t (*single_character_map) (ucs4_t), + size_t offset_in_rule, /* offset in 'struct special_casing_rule' */ + uninorm_t nf, + uint32_t *resultbuf, size_t *lengthp); diff --git a/lib/uniconv.h b/lib/uniconv.h index 223386fc..bd32ae60 100644 --- a/lib/uniconv.h +++ b/lib/uniconv.h @@ -1,5 +1,5 @@ /* Conversions between Unicode and legacy encodings. - Copyright (C) 2002, 2005, 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2005, 2007, 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -55,22 +55,22 @@ extern "C" { values: EINVAL, EILSEQ, ENOMEM. */ extern uint8_t * u8_conv_from_encoding (const char *fromcode, - enum iconv_ilseq_handler handler, - const char *src, size_t srclen, - size_t *offsets, - uint8_t *resultbuf, size_t *lengthp); + enum iconv_ilseq_handler handler, + const char *src, size_t srclen, + size_t *offsets, + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_conv_from_encoding (const char *fromcode, - enum iconv_ilseq_handler handler, - const char *src, size_t srclen, - size_t *offsets, - uint16_t *resultbuf, size_t *lengthp); + enum iconv_ilseq_handler handler, + const char *src, size_t srclen, + size_t *offsets, + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_conv_from_encoding (const char *fromcode, - enum iconv_ilseq_handler handler, - const char *src, size_t srclen, - size_t *offsets, - uint32_t *resultbuf, size_t *lengthp); + enum iconv_ilseq_handler handler, + const char *src, size_t srclen, + size_t *offsets, + uint32_t *resultbuf, size_t *lengthp); /* Converts an entire Unicode string, possibly including NUL units, from a Unicode encoding to a given encoding. @@ -92,54 +92,54 @@ extern uint32_t * values: EINVAL, EILSEQ, ENOMEM. */ extern char * u8_conv_to_encoding (const char *tocode, - enum iconv_ilseq_handler handler, - const uint8_t *src, size_t srclen, - size_t *offsets, - char *resultbuf, size_t *lengthp); + enum iconv_ilseq_handler handler, + const uint8_t *src, size_t srclen, + size_t *offsets, + char *resultbuf, size_t *lengthp); extern char * u16_conv_to_encoding (const char *tocode, - enum iconv_ilseq_handler handler, - const uint16_t *src, size_t srclen, - size_t *offsets, - char *resultbuf, size_t *lengthp); + enum iconv_ilseq_handler handler, + const uint16_t *src, size_t srclen, + size_t *offsets, + char *resultbuf, size_t *lengthp); extern char * u32_conv_to_encoding (const char *tocode, - enum iconv_ilseq_handler handler, - const uint32_t *src, size_t srclen, - size_t *offsets, - char *resultbuf, size_t *lengthp); + enum iconv_ilseq_handler handler, + const uint32_t *src, size_t srclen, + size_t *offsets, + char *resultbuf, size_t *lengthp); /* Converts a NUL terminated string from a given encoding. The result is malloc allocated, or NULL (with errno set) in case of error. Particular errno values: EILSEQ, ENOMEM. */ extern uint8_t * u8_strconv_from_encoding (const char *string, - const char *fromcode, - enum iconv_ilseq_handler handler); + const char *fromcode, + enum iconv_ilseq_handler handler); extern uint16_t * u16_strconv_from_encoding (const char *string, - const char *fromcode, - enum iconv_ilseq_handler handler); + const char *fromcode, + enum iconv_ilseq_handler handler); extern uint32_t * u32_strconv_from_encoding (const char *string, - const char *fromcode, - enum iconv_ilseq_handler handler); + const char *fromcode, + enum iconv_ilseq_handler handler); /* Converts a NUL terminated string to a given encoding. The result is malloc allocated, or NULL (with errno set) in case of error. Particular errno values: EILSEQ, ENOMEM. */ extern char * u8_strconv_to_encoding (const uint8_t *string, - const char *tocode, - enum iconv_ilseq_handler handler); + const char *tocode, + enum iconv_ilseq_handler handler); extern char * u16_strconv_to_encoding (const uint16_t *string, - const char *tocode, - enum iconv_ilseq_handler handler); + const char *tocode, + enum iconv_ilseq_handler handler); extern char * u32_strconv_to_encoding (const uint32_t *string, - const char *tocode, - enum iconv_ilseq_handler handler); + const char *tocode, + enum iconv_ilseq_handler handler); /* Converts a NUL terminated string from the locale encoding. The result is malloc allocated, or NULL (with errno set) in case of error. diff --git a/lib/uniconv/u-conv-from-enc.h b/lib/uniconv/u-conv-from-enc.h index fa0f0d3d..457bd0f8 100644 --- a/lib/uniconv/u-conv-from-enc.h +++ b/lib/uniconv/u-conv-from-enc.h @@ -1,5 +1,5 @@ /* Conversion to UTF-16/UTF-32 from legacy encodings. - Copyright (C) 2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -26,7 +26,7 @@ FUNC (const char *fromcode, size_t length = *lengthp * sizeof (UNIT); if (mem_iconveha (src, srclen, fromcode, UTF_NAME, true, handler, - offsets, &result, &length) < 0) + offsets, &result, &length) < 0) return NULL; if (offsets != NULL) { @@ -35,8 +35,8 @@ FUNC (const char *fromcode, size_t *o; for (o = offsets; o < offsets_end; o++) - if (*o != (size_t)(-1)) - *o = *o / sizeof (UNIT); + if (*o != (size_t)(-1)) + *o = *o / sizeof (UNIT); } if ((length % sizeof (UNIT)) != 0) abort (); @@ -49,7 +49,7 @@ FUNC (const char *fromcode, utf8_string = u8_conv_from_encoding (fromcode, handler, src, srclen, offsets, - NULL, &utf8_length); + NULL, &utf8_length); if (utf8_string == NULL) return NULL; result = U8_TO_U (utf8_string, utf8_length, resultbuf, lengthp); @@ -65,25 +65,25 @@ FUNC (const char *fromcode, size_t length = *lengthp; size_t *offsets_end = offsets + srclen; size_t *o; - size_t off8 = 0; /* offset into utf8_string */ - size_t offunit = 0; /* offset into result */ + size_t off8 = 0; /* offset into utf8_string */ + size_t offunit = 0; /* offset into result */ for (o = offsets; o < offsets_end; o++) - if (*o != (size_t)(-1)) - { - while (off8 < *o) - { - int count8 = u8_mblen (utf8_string + off8, utf8_length - off8); - int countunit = U_MBLEN (result + offunit, length - offunit); - if (count8 < 0 || countunit < 0) - abort (); - off8 += count8; - offunit += countunit; - } - if (*o != off8) - abort (); - *o = offunit; - } + if (*o != (size_t)(-1)) + { + while (off8 < *o) + { + int count8 = u8_mblen (utf8_string + off8, utf8_length - off8); + int countunit = U_MBLEN (result + offunit, length - offunit); + if (count8 < 0 || countunit < 0) + abort (); + off8 += count8; + offunit += countunit; + } + if (*o != off8) + abort (); + *o = offunit; + } } free (utf8_string); return result; diff --git a/lib/uniconv/u-conv-to-enc.h b/lib/uniconv/u-conv-to-enc.h index ed715482..43d82c77 100644 --- a/lib/uniconv/u-conv-to-enc.h +++ b/lib/uniconv/u-conv-to-enc.h @@ -1,5 +1,5 @@ /* Conversion from UTF-16/UTF-32 to legacy encodings. - Copyright (C) 2002, 2006-2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -29,12 +29,12 @@ FUNC (const char *tocode, if (offsets != NULL && srclen > 0) { scaled_offsets = - (size_t *) malloc (srclen * sizeof (UNIT) * sizeof (size_t)); + (size_t *) malloc (srclen * sizeof (UNIT) * sizeof (size_t)); if (scaled_offsets == NULL) - { - errno = ENOMEM; - return NULL; - } + { + errno = ENOMEM; + return NULL; + } } else scaled_offsets = NULL; @@ -42,9 +42,9 @@ FUNC (const char *tocode, result = resultbuf; length = *lengthp; if (mem_iconveha ((const char *) src, srclen * sizeof (UNIT), - UTF_NAME, tocode, - handler == iconveh_question_mark, handler, - scaled_offsets, &result, &length) < 0) + UTF_NAME, tocode, + handler == iconveh_question_mark, handler, + scaled_offsets, &result, &length) < 0) { int saved_errno = errno; free (scaled_offsets); @@ -55,11 +55,11 @@ FUNC (const char *tocode, if (offsets != NULL) { /* Convert scaled_offsets[srclen * sizeof (UNIT)] to - offsets[srclen]. */ + offsets[srclen]. */ size_t i; for (i = 0; i < srclen; i++) - offsets[i] = scaled_offsets[i * sizeof (UNIT)]; + offsets[i] = scaled_offsets[i * sizeof (UNIT)]; free (scaled_offsets); } @@ -67,10 +67,10 @@ FUNC (const char *tocode, { result = (char *) malloc (1); if (result == NULL) - { - errno = ENOMEM; - return NULL; - } + { + errno = ENOMEM; + return NULL; + } } *lengthp = length; return result; @@ -91,62 +91,62 @@ FUNC (const char *tocode, { scaled_offsets = (size_t *) malloc (utf8_srclen * sizeof (size_t)); if (scaled_offsets == NULL) - { - if (utf8_src != tmpbuf) - free (utf8_src); - errno = ENOMEM; - return NULL; - } + { + if (utf8_src != tmpbuf) + free (utf8_src); + errno = ENOMEM; + return NULL; + } } else scaled_offsets = NULL; result = u8_conv_to_encoding (tocode, handler, utf8_src, utf8_srclen, - scaled_offsets, resultbuf, lengthp); + scaled_offsets, resultbuf, lengthp); if (result == NULL) { int saved_errno = errno; free (scaled_offsets); if (utf8_src != tmpbuf) - free (utf8_src); + free (utf8_src); errno = saved_errno; return NULL; } if (offsets != NULL) { - size_t iunit; /* offset into src */ - size_t i8; /* offset into utf8_src */ + size_t iunit; /* offset into src */ + size_t i8; /* offset into utf8_src */ for (iunit = 0; iunit < srclen; iunit++) - offsets[iunit] = (size_t)(-1); + offsets[iunit] = (size_t)(-1); iunit = 0; i8 = 0; while (iunit < srclen && i8 < utf8_srclen) - { - int countunit; - int count8; - - offsets[iunit] = scaled_offsets[i8]; - - countunit = U_MBLEN (src + iunit, srclen - iunit); - count8 = u8_mblen (utf8_src + i8, utf8_srclen - i8); - if (countunit < 0 || count8 < 0) - abort (); - iunit += countunit; - i8 += count8; - } + { + int countunit; + int count8; + + offsets[iunit] = scaled_offsets[i8]; + + countunit = U_MBLEN (src + iunit, srclen - iunit); + count8 = u8_mblen (utf8_src + i8, utf8_srclen - i8); + if (countunit < 0 || count8 < 0) + abort (); + iunit += countunit; + i8 += count8; + } /* Check that utf8_src has been traversed entirely. */ if (i8 < utf8_srclen) - abort (); + abort (); /* Check that src has been traversed entirely, except possibly for an - incomplete sequence of units at the end. */ + incomplete sequence of units at the end. */ if (iunit < srclen) - { - offsets[iunit] = *lengthp; - if (!(U_MBLEN (src + iunit, srclen - iunit) < 0)) - abort (); - } + { + offsets[iunit] = *lengthp; + if (!(U_MBLEN (src + iunit, srclen - iunit) < 0)) + abort (); + } free (scaled_offsets); } if (utf8_src != tmpbuf) diff --git a/lib/uniconv/u-strconv-from-enc.h b/lib/uniconv/u-strconv-from-enc.h index 25813c76..df91c384 100644 --- a/lib/uniconv/u-strconv-from-enc.h +++ b/lib/uniconv/u-strconv-from-enc.h @@ -1,5 +1,5 @@ /* Conversion to UTF-8/UTF-16/UTF-32 from legacy encodings. - Copyright (C) 2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -24,13 +24,13 @@ FUNC (const char *string, result = U_CONV_FROM_ENCODING (fromcode, handler, - string, strlen (string) + 1, NULL, - NULL, &length); + string, strlen (string) + 1, NULL, + NULL, &length); if (result == NULL) return NULL; /* Verify the result has exactly one NUL unit, at the end. */ if (!(length > 0 && result[length-1] == 0 - && U_STRLEN (result) == length-1)) + && U_STRLEN (result) == length-1)) { free (result); errno = EILSEQ; diff --git a/lib/uniconv/u-strconv-to-enc.h b/lib/uniconv/u-strconv-to-enc.h index b6e6ebb5..c15182f1 100644 --- a/lib/uniconv/u-strconv-to-enc.h +++ b/lib/uniconv/u-strconv-to-enc.h @@ -1,5 +1,5 @@ /* Conversion from UTF-16/UTF-32 to legacy encodings. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -24,9 +24,9 @@ FUNC (const UNIT *string, size_t length = 0; if (mem_iconveha ((const char *) string, (U_STRLEN (string) + 1) * sizeof (UNIT), - UTF_NAME, tocode, - handler == iconveh_question_mark, handler, - NULL, &result, &length) < 0) + UTF_NAME, tocode, + handler == iconveh_question_mark, handler, + NULL, &result, &length) < 0) return NULL; /* Verify the result has exactly one NUL byte, at the end. */ if (!(length > 0 && result[length-1] == '\0' && strlen (result) == length-1)) @@ -49,11 +49,11 @@ FUNC (const UNIT *string, if (result == NULL) { if (utf8_string != tmpbuf) - { - int saved_errno = errno; - free (utf8_string); - errno = saved_errno; - } + { + int saved_errno = errno; + free (utf8_string); + errno = saved_errno; + } return NULL; } if (utf8_string != tmpbuf) diff --git a/lib/uniconv/u16-conv-from-enc.c b/lib/uniconv/u16-conv-from-enc.c index f38add30..dc4c21d2 100644 --- a/lib/uniconv/u16-conv-from-enc.c +++ b/lib/uniconv/u16-conv-from-enc.c @@ -1,5 +1,5 @@ /* Conversion to UTF-16 from legacy encodings. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u16-conv-to-enc.c b/lib/uniconv/u16-conv-to-enc.c index ba70736c..cce454d5 100644 --- a/lib/uniconv/u16-conv-to-enc.c +++ b/lib/uniconv/u16-conv-to-enc.c @@ -1,5 +1,5 @@ /* Conversion from UTF-16 to legacy encodings. - Copyright (C) 2002, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -81,69 +81,69 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) /* Fetch a Unicode character from the input string. */ count = u16_mbtoucr (&uc, s, s_end - s); if (count < 0) - { - if (count == -2) - /* Incomplete sequence of units. */ - break; - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (count == -2) + /* Incomplete sequence of units. */ + break; + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } s += count; /* Store it in the output string. */ count = u8_uctomb (result + length, uc, allocated - length); if (count == -1) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } if (count == -2) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 6 > allocated) - allocated = length + 6; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - count = u8_uctomb (result + length, uc, allocated - length); - if (count < 0) - abort (); - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 6 > allocated) + allocated = length + 6; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + count = u8_uctomb (result + length, uc, allocated - length); + if (count < 0) + abort (); + } length += count; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -152,7 +152,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/uniconv/u16-strconv-from-enc.c b/lib/uniconv/u16-strconv-from-enc.c index 736d0c4a..ebdd62e0 100644 --- a/lib/uniconv/u16-strconv-from-enc.c +++ b/lib/uniconv/u16-strconv-from-enc.c @@ -1,5 +1,5 @@ /* Conversion to UTF-16 from legacy encodings. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u16-strconv-from-locale.c b/lib/uniconv/u16-strconv-from-locale.c index 63ddeb04..c6695d1f 100644 --- a/lib/uniconv/u16-strconv-from-locale.c +++ b/lib/uniconv/u16-strconv-from-locale.c @@ -1,5 +1,5 @@ /* Conversion to UTF-16 from the locale encoding. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u16-strconv-to-enc.c b/lib/uniconv/u16-strconv-to-enc.c index 10e895e9..c8e00e76 100644 --- a/lib/uniconv/u16-strconv-to-enc.c +++ b/lib/uniconv/u16-strconv-to-enc.c @@ -1,5 +1,5 @@ /* Conversion from UTF-16 to legacy encodings. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u16-strconv-to-locale.c b/lib/uniconv/u16-strconv-to-locale.c index 14fd7b3b..74fcbed3 100644 --- a/lib/uniconv/u16-strconv-to-locale.c +++ b/lib/uniconv/u16-strconv-to-locale.c @@ -1,5 +1,5 @@ /* Conversion from UTF-16 to the locale encoding. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u32-conv-from-enc.c b/lib/uniconv/u32-conv-from-enc.c index bac6301b..f5c6e8e1 100644 --- a/lib/uniconv/u32-conv-from-enc.c +++ b/lib/uniconv/u32-conv-from-enc.c @@ -1,5 +1,5 @@ /* Conversion to UTF-32 from legacy encodings. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u32-conv-to-enc.c b/lib/uniconv/u32-conv-to-enc.c index 9155abaa..7bfc9f46 100644 --- a/lib/uniconv/u32-conv-to-enc.c +++ b/lib/uniconv/u32-conv-to-enc.c @@ -1,5 +1,5 @@ /* Conversion from UTF-32 to legacy encodings. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u32-strconv-from-enc.c b/lib/uniconv/u32-strconv-from-enc.c index aaac74f1..65ff600b 100644 --- a/lib/uniconv/u32-strconv-from-enc.c +++ b/lib/uniconv/u32-strconv-from-enc.c @@ -1,5 +1,5 @@ /* Conversion to UTF-32 from legacy encodings. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u32-strconv-from-locale.c b/lib/uniconv/u32-strconv-from-locale.c index 2cddcb63..103e41b6 100644 --- a/lib/uniconv/u32-strconv-from-locale.c +++ b/lib/uniconv/u32-strconv-from-locale.c @@ -1,5 +1,5 @@ /* Conversion to UTF-32 from the locale encoding. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u32-strconv-to-enc.c b/lib/uniconv/u32-strconv-to-enc.c index c77e0b6e..fd45013e 100644 --- a/lib/uniconv/u32-strconv-to-enc.c +++ b/lib/uniconv/u32-strconv-to-enc.c @@ -1,5 +1,5 @@ /* Conversion from UTF-32 to legacy encodings. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u32-strconv-to-locale.c b/lib/uniconv/u32-strconv-to-locale.c index 64ab59fa..57cc47ed 100644 --- a/lib/uniconv/u32-strconv-to-locale.c +++ b/lib/uniconv/u32-strconv-to-locale.c @@ -1,5 +1,5 @@ /* Conversion from UTF-32 to the locale encoding. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u8-conv-from-enc.c b/lib/uniconv/u8-conv-from-enc.c index 7605e63e..88d666cc 100644 --- a/lib/uniconv/u8-conv-from-enc.c +++ b/lib/uniconv/u8-conv-from-enc.c @@ -1,5 +1,5 @@ /* Conversion to UTF-8 from legacy encodings. - Copyright (C) 2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -31,10 +31,10 @@ uint8_t * u8_conv_from_encoding (const char *fromcode, - enum iconv_ilseq_handler handler, - const char *src, size_t srclen, - size_t *offsets, - uint8_t *resultbuf, size_t *lengthp) + enum iconv_ilseq_handler handler, + const char *src, size_t srclen, + size_t *offsets, + uint8_t *resultbuf, size_t *lengthp) { if (STRCASEEQ (fromcode, "UTF-8", 'U','T','F','-','8',0,0,0,0)) { @@ -42,40 +42,40 @@ u8_conv_from_encoding (const char *fromcode, uint8_t *result; if (u8_check ((const uint8_t *) src, srclen)) - { - errno = EILSEQ; - return NULL; - } + { + errno = EILSEQ; + return NULL; + } if (offsets != NULL) - { - size_t i; - - for (i = 0; i < srclen; ) - { - int count = u8_mblen ((const uint8_t *) src + i, srclen - i); - /* We can rely on count > 0 because of the previous u8_check. */ - if (count <= 0) - abort (); - offsets[i] = i; - i++; - while (--count > 0) - offsets[i++] = (size_t)(-1); - } - } + { + size_t i; + + for (i = 0; i < srclen; ) + { + int count = u8_mblen ((const uint8_t *) src + i, srclen - i); + /* We can rely on count > 0 because of the previous u8_check. */ + if (count <= 0) + abort (); + offsets[i] = i; + i++; + while (--count > 0) + offsets[i++] = (size_t)(-1); + } + } /* Memory allocation. */ if (resultbuf != NULL && *lengthp >= srclen) - result = resultbuf; + result = resultbuf; else - { - result = (uint8_t *) malloc (srclen > 0 ? srclen : 1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + result = (uint8_t *) malloc (srclen > 0 ? srclen : 1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } memcpy ((char *) result, src, srclen); *lengthp = srclen; @@ -87,18 +87,18 @@ u8_conv_from_encoding (const char *fromcode, size_t length = *lengthp; if (mem_iconveha (src, srclen, fromcode, "UTF-8", true, handler, - offsets, &result, &length) < 0) - return NULL; + offsets, &result, &length) < 0) + return NULL; if (result == NULL) /* when (resultbuf == NULL && length == 0) */ - { - result = (char *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + result = (char *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } *lengthp = length; return (uint8_t *) result; } diff --git a/lib/uniconv/u8-conv-to-enc.c b/lib/uniconv/u8-conv-to-enc.c index 90acccec..cacf2596 100644 --- a/lib/uniconv/u8-conv-to-enc.c +++ b/lib/uniconv/u8-conv-to-enc.c @@ -1,5 +1,5 @@ /* Conversion from UTF-8 to legacy encodings. - Copyright (C) 2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -31,10 +31,10 @@ char * u8_conv_to_encoding (const char *tocode, - enum iconv_ilseq_handler handler, - const uint8_t *src, size_t srclen, - size_t *offsets, - char *resultbuf, size_t *lengthp) + enum iconv_ilseq_handler handler, + const uint8_t *src, size_t srclen, + size_t *offsets, + char *resultbuf, size_t *lengthp) { if (STRCASEEQ (tocode, "UTF-8", 'U','T','F','-','8',0,0,0,0)) { @@ -43,24 +43,24 @@ u8_conv_to_encoding (const char *tocode, /* Conversion from UTF-8 to UTF-8. No need to go through iconv(). */ #if CONFIG_UNICODE_SAFETY if (u8_check (src, srclen)) - { - errno = EILSEQ; - return NULL; - } + { + errno = EILSEQ; + return NULL; + } #endif /* Memory allocation. */ if (resultbuf != NULL && *lengthp >= srclen) - result = resultbuf; + result = resultbuf; else - { - result = (char *) malloc (srclen > 0 ? srclen : 1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + result = (char *) malloc (srclen > 0 ? srclen : 1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } memcpy (result, (const char *) src, srclen); *lengthp = srclen; @@ -72,20 +72,20 @@ u8_conv_to_encoding (const char *tocode, size_t length = *lengthp; if (mem_iconveha ((const char *) src, srclen, - "UTF-8", tocode, - handler == iconveh_question_mark, handler, - offsets, &result, &length) < 0) - return NULL; + "UTF-8", tocode, + handler == iconveh_question_mark, handler, + offsets, &result, &length) < 0) + return NULL; if (result == NULL) /* when (resultbuf == NULL && length == 0) */ - { - result = (char *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + result = (char *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } *lengthp = length; return result; } diff --git a/lib/uniconv/u8-strconv-from-enc.c b/lib/uniconv/u8-strconv-from-enc.c index 0f5736fc..e1776661 100644 --- a/lib/uniconv/u8-strconv-from-enc.c +++ b/lib/uniconv/u8-strconv-from-enc.c @@ -1,5 +1,5 @@ /* Conversion to UTF-8 from legacy encodings. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u8-strconv-from-locale.c b/lib/uniconv/u8-strconv-from-locale.c index a901a3d6..e149ce3a 100644 --- a/lib/uniconv/u8-strconv-from-locale.c +++ b/lib/uniconv/u8-strconv-from-locale.c @@ -1,5 +1,5 @@ /* Conversion to UTF-8 from the locale encoding. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniconv/u8-strconv-to-enc.c b/lib/uniconv/u8-strconv-to-enc.c index a3f12b6b..d593cf1b 100644 --- a/lib/uniconv/u8-strconv-to-enc.c +++ b/lib/uniconv/u8-strconv-to-enc.c @@ -1,5 +1,5 @@ /* Conversion from UTF-8 to legacy encodings. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -31,8 +31,8 @@ char * u8_strconv_to_encoding (const uint8_t *string, - const char *tocode, - enum iconv_ilseq_handler handler) + const char *tocode, + enum iconv_ilseq_handler handler) { char *result; size_t length; @@ -43,17 +43,17 @@ u8_strconv_to_encoding (const uint8_t *string, length = u8_strlen (string) + 1; #if CONFIG_UNICODE_SAFETY if (u8_check (string, length)) - { - errno = EILSEQ; - return NULL; - } + { + errno = EILSEQ; + return NULL; + } #endif result = (char *) malloc (length); if (result == NULL) - { - errno = ENOMEM; - return NULL; - } + { + errno = ENOMEM; + return NULL; + } memcpy (result, (const char *) string, length); return result; } @@ -62,18 +62,18 @@ u8_strconv_to_encoding (const uint8_t *string, result = NULL; length = 0; if (mem_iconveha ((const char *) string, u8_strlen (string) + 1, - "UTF-8", tocode, - handler == iconveh_question_mark, handler, - NULL, &result, &length) < 0) - return NULL; + "UTF-8", tocode, + handler == iconveh_question_mark, handler, + NULL, &result, &length) < 0) + return NULL; /* Verify the result has exactly one NUL byte, at the end. */ if (!(length > 0 && result[length-1] == '\0' - && strlen (result) == length-1)) - { - free (result); - errno = EILSEQ; - return NULL; - } + && strlen (result) == length-1)) + { + free (result); + errno = EILSEQ; + return NULL; + } return result; } } diff --git a/lib/uniconv/u8-strconv-to-locale.c b/lib/uniconv/u8-strconv-to-locale.c index 27c45fbf..8bdc812f 100644 --- a/lib/uniconv/u8-strconv-to-locale.c +++ b/lib/uniconv/u8-strconv-to-locale.c @@ -1,5 +1,5 @@ /* Conversion from UTF-8 to the locale encoding. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unictype.h b/lib/unictype.h index 1fc04403..e3748731 100644 --- a/lib/unictype.h +++ b/lib/unictype.h @@ -1,5 +1,5 @@ /* Unicode character classification and properties. - Copyright (C) 2002, 2005-2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -186,14 +186,14 @@ extern const uc_general_category_t _UC_CATEGORY_NONE; This corresponds to the unions of the two sets of characters. */ extern uc_general_category_t uc_general_category_or (uc_general_category_t category1, - uc_general_category_t category2); + uc_general_category_t category2); /* Return the intersection of two general categories as bit masks. This *does*not* correspond to the intersection of the two sets of characters. */ extern uc_general_category_t uc_general_category_and (uc_general_category_t category1, - uc_general_category_t category2); + uc_general_category_t category2); /* Return the intersection of a general category with the complement of a second general category, as bit masks. @@ -201,7 +201,7 @@ extern uc_general_category_t viewing the categories as sets of characters. */ extern uc_general_category_t uc_general_category_and_not (uc_general_category_t category1, - uc_general_category_t category2); + uc_general_category_t category2); /* Return the name of a general category. */ extern const char * diff --git a/lib/unictype/bidi_byname.c b/lib/unictype/bidi_byname.c index 8a6cb71a..868f05dc 100644 --- a/lib/unictype/bidi_byname.c +++ b/lib/unictype/bidi_byname.c @@ -1,5 +1,5 @@ /* Bidi categories of Unicode characters. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -27,143 +27,143 @@ uc_bidi_category_byname (const char *category_name) { case 'A': switch (category_name[1]) - { - case 'L': - if (category_name[2] == '\0') - return UC_BIDI_AL; - break; - case 'N': - if (category_name[2] == '\0') - return UC_BIDI_AN; - break; - } + { + case 'L': + if (category_name[2] == '\0') + return UC_BIDI_AL; + break; + case 'N': + if (category_name[2] == '\0') + return UC_BIDI_AN; + break; + } break; case 'B': switch (category_name[1]) - { - case '\0': - return UC_BIDI_B; - case 'N': - if (category_name[2] == '\0') - return UC_BIDI_BN; - break; - } + { + case '\0': + return UC_BIDI_B; + case 'N': + if (category_name[2] == '\0') + return UC_BIDI_BN; + break; + } break; case 'C': switch (category_name[1]) - { - case 'S': - if (category_name[2] == '\0') - return UC_BIDI_CS; - break; - } + { + case 'S': + if (category_name[2] == '\0') + return UC_BIDI_CS; + break; + } break; case 'E': switch (category_name[1]) - { - case 'N': - if (category_name[2] == '\0') - return UC_BIDI_EN; - break; - case 'S': - if (category_name[2] == '\0') - return UC_BIDI_ES; - break; - case 'T': - if (category_name[2] == '\0') - return UC_BIDI_ET; - break; - } + { + case 'N': + if (category_name[2] == '\0') + return UC_BIDI_EN; + break; + case 'S': + if (category_name[2] == '\0') + return UC_BIDI_ES; + break; + case 'T': + if (category_name[2] == '\0') + return UC_BIDI_ET; + break; + } break; case 'L': switch (category_name[1]) - { - case '\0': - return UC_BIDI_L; - case 'R': - switch (category_name[2]) - { - case 'E': - if (category_name[3] == '\0') - return UC_BIDI_LRE; - break; - case 'O': - if (category_name[3] == '\0') - return UC_BIDI_LRO; - break; - } - break; - } + { + case '\0': + return UC_BIDI_L; + case 'R': + switch (category_name[2]) + { + case 'E': + if (category_name[3] == '\0') + return UC_BIDI_LRE; + break; + case 'O': + if (category_name[3] == '\0') + return UC_BIDI_LRO; + break; + } + break; + } break; case 'N': switch (category_name[1]) - { - case 'S': - switch (category_name[2]) - { - case 'M': - if (category_name[3] == '\0') - return UC_BIDI_NSM; - break; - } - break; - } + { + case 'S': + switch (category_name[2]) + { + case 'M': + if (category_name[3] == '\0') + return UC_BIDI_NSM; + break; + } + break; + } break; case 'O': switch (category_name[1]) - { - case 'N': - if (category_name[2] == '\0') - return UC_BIDI_ON; - break; - } + { + case 'N': + if (category_name[2] == '\0') + return UC_BIDI_ON; + break; + } break; case 'P': switch (category_name[1]) - { - case 'D': - switch (category_name[2]) - { - case 'F': - if (category_name[3] == '\0') - return UC_BIDI_PDF; - break; - } - break; - } + { + case 'D': + switch (category_name[2]) + { + case 'F': + if (category_name[3] == '\0') + return UC_BIDI_PDF; + break; + } + break; + } break; case 'R': switch (category_name[1]) - { - case '\0': - return UC_BIDI_R; - case 'L': - switch (category_name[2]) - { - case 'E': - if (category_name[3] == '\0') - return UC_BIDI_RLE; - break; - case 'O': - if (category_name[3] == '\0') - return UC_BIDI_RLO; - break; - } - break; - } + { + case '\0': + return UC_BIDI_R; + case 'L': + switch (category_name[2]) + { + case 'E': + if (category_name[3] == '\0') + return UC_BIDI_RLE; + break; + case 'O': + if (category_name[3] == '\0') + return UC_BIDI_RLO; + break; + } + break; + } break; case 'S': if (category_name[1] == '\0') - return UC_BIDI_S; + return UC_BIDI_S; break; case 'W': switch (category_name[1]) - { - case 'S': - if (category_name[2] == '\0') - return UC_BIDI_WS; - break; - } + { + case 'S': + if (category_name[2] == '\0') + return UC_BIDI_WS; + break; + } break; } /* Invalid category name. */ diff --git a/lib/unictype/bidi_name.c b/lib/unictype/bidi_name.c index 76529768..28bb4baa 100644 --- a/lib/unictype/bidi_name.c +++ b/lib/unictype/bidi_name.c @@ -1,5 +1,5 @@ /* Bidi categories of Unicode characters. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/bidi_of.c b/lib/unictype/bidi_of.c index 93fc7a8b..4a293a87 100644 --- a/lib/unictype/bidi_of.c +++ b/lib/unictype/bidi_of.c @@ -1,5 +1,5 @@ /* Bidi categories of Unicode characters. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,22 +31,22 @@ uc_bidi_category (ucs4_t uc) { int lookup1 = u_bidi_category.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> bidi_category_header_2) & bidi_category_header_3; - int lookup2 = u_bidi_category.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = ((uc & bidi_category_header_4) + lookup2) * 5; - /* level3 contains 5-bit values, packed into 16-bit words. */ - unsigned int lookup3 = - ((u_bidi_category.level3[index3>>4] - | (u_bidi_category.level3[(index3>>4)+1] << 16)) - >> (index3 % 16)) - & 0x1f; - - return lookup3; - } - } + { + unsigned int index2 = (uc >> bidi_category_header_2) & bidi_category_header_3; + int lookup2 = u_bidi_category.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = ((uc & bidi_category_header_4) + lookup2) * 5; + /* level3 contains 5-bit values, packed into 16-bit words. */ + unsigned int lookup3 = + ((u_bidi_category.level3[index3>>4] + | (u_bidi_category.level3[(index3>>4)+1] << 16)) + >> (index3 % 16)) + & 0x1f; + + return lookup3; + } + } } return UC_BIDI_L; } diff --git a/lib/unictype/bidi_test.c b/lib/unictype/bidi_test.c index 72887bbc..0a9fa5c9 100644 --- a/lib/unictype/bidi_test.c +++ b/lib/unictype/bidi_test.c @@ -1,5 +1,5 @@ /* Bidi categories of Unicode characters. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/bitmap.h b/lib/unictype/bitmap.h index 280b2985..4e743c5e 100644 --- a/lib/unictype/bitmap.h +++ b/lib/unictype/bitmap.h @@ -1,5 +1,5 @@ /* Three-level bitmap lookup. - Copyright (C) 2000-2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 2000-2002, 2005-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2000-2002. This program is free software: you can redistribute it and/or modify it @@ -31,17 +31,17 @@ bitmap_lookup (const void *table, ucs4_t uc) { int lookup1 = ((const int *) table)[1 + index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> header_2) & header_3; - int lookup2 = ((const short *) table)[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc >> 5) & header_4; - unsigned int lookup3 = ((const int *) table)[lookup2 + index3]; + { + unsigned int index2 = (uc >> header_2) & header_3; + int lookup2 = ((const short *) table)[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc >> 5) & header_4; + unsigned int lookup3 = ((const int *) table)[lookup2 + index3]; - return (lookup3 >> (uc & 0x1f)) & 1; - } - } + return (lookup3 >> (uc & 0x1f)) & 1; + } + } } return 0; } diff --git a/lib/unictype/block_test.c b/lib/unictype/block_test.c index 4005ad04..04722b49 100644 --- a/lib/unictype/block_test.c +++ b/lib/unictype/block_test.c @@ -1,5 +1,5 @@ /* Blocks of Unicode characters. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/blocks.c b/lib/unictype/blocks.c index a20bbcee..e83e5469 100644 --- a/lib/unictype/blocks.c +++ b/lib/unictype/blocks.c @@ -1,5 +1,5 @@ /* Blocks of Unicode characters. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it @@ -45,11 +45,11 @@ uc_block (ucs4_t uc) { unsigned int mid_index = (first_index + last_index) / 2; if (blocks[mid_index].end < uc) - first_index = mid_index + 1; + first_index = mid_index + 1; else if (uc < blocks[mid_index].start) - last_index = mid_index; + last_index = mid_index; else - return &blocks[mid_index]; + return &blocks[mid_index]; } return NULL; } diff --git a/lib/unictype/categ_C.c b/lib/unictype/categ_C.c index d14d8c09..3c3860df 100644 --- a/lib/unictype/categ_C.c +++ b/lib/unictype/categ_C.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Cc.c b/lib/unictype/categ_Cc.c index 572f88f7..653848db 100644 --- a/lib/unictype/categ_Cc.c +++ b/lib/unictype/categ_Cc.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Cf.c b/lib/unictype/categ_Cf.c index 19cd842e..fd53e7a8 100644 --- a/lib/unictype/categ_Cf.c +++ b/lib/unictype/categ_Cf.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Cn.c b/lib/unictype/categ_Cn.c index 131704ab..63242dc0 100644 --- a/lib/unictype/categ_Cn.c +++ b/lib/unictype/categ_Cn.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Co.c b/lib/unictype/categ_Co.c index 70b5ac72..3452a17e 100644 --- a/lib/unictype/categ_Co.c +++ b/lib/unictype/categ_Co.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Cs.c b/lib/unictype/categ_Cs.c index a3f5ceab..cd94733d 100644 --- a/lib/unictype/categ_Cs.c +++ b/lib/unictype/categ_Cs.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_L.c b/lib/unictype/categ_L.c index b62b2a27..4b7f16d8 100644 --- a/lib/unictype/categ_L.c +++ b/lib/unictype/categ_L.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Ll.c b/lib/unictype/categ_Ll.c index 37da1a08..e7e752ef 100644 --- a/lib/unictype/categ_Ll.c +++ b/lib/unictype/categ_Ll.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Lm.c b/lib/unictype/categ_Lm.c index 296e53db..fc016026 100644 --- a/lib/unictype/categ_Lm.c +++ b/lib/unictype/categ_Lm.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Lo.c b/lib/unictype/categ_Lo.c index 5c7781e1..57ae6116 100644 --- a/lib/unictype/categ_Lo.c +++ b/lib/unictype/categ_Lo.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Lt.c b/lib/unictype/categ_Lt.c index 485acf66..9de263d7 100644 --- a/lib/unictype/categ_Lt.c +++ b/lib/unictype/categ_Lt.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Lu.c b/lib/unictype/categ_Lu.c index 26faae27..6000421b 100644 --- a/lib/unictype/categ_Lu.c +++ b/lib/unictype/categ_Lu.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_M.c b/lib/unictype/categ_M.c index ab7f149c..8e6ff700 100644 --- a/lib/unictype/categ_M.c +++ b/lib/unictype/categ_M.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Mc.c b/lib/unictype/categ_Mc.c index c54a565c..f4cca6bd 100644 --- a/lib/unictype/categ_Mc.c +++ b/lib/unictype/categ_Mc.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Me.c b/lib/unictype/categ_Me.c index 00e2a012..62b1ad9a 100644 --- a/lib/unictype/categ_Me.c +++ b/lib/unictype/categ_Me.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Mn.c b/lib/unictype/categ_Mn.c index 5990ee50..edcf3c50 100644 --- a/lib/unictype/categ_Mn.c +++ b/lib/unictype/categ_Mn.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_N.c b/lib/unictype/categ_N.c index 5aa92487..e326ff22 100644 --- a/lib/unictype/categ_N.c +++ b/lib/unictype/categ_N.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Nd.c b/lib/unictype/categ_Nd.c index f5ad3224..c6b02580 100644 --- a/lib/unictype/categ_Nd.c +++ b/lib/unictype/categ_Nd.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Nl.c b/lib/unictype/categ_Nl.c index 6fe93707..50a39bb0 100644 --- a/lib/unictype/categ_Nl.c +++ b/lib/unictype/categ_Nl.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_No.c b/lib/unictype/categ_No.c index 055177f6..f36899d7 100644 --- a/lib/unictype/categ_No.c +++ b/lib/unictype/categ_No.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_P.c b/lib/unictype/categ_P.c index e1dbbcdd..14f94ad4 100644 --- a/lib/unictype/categ_P.c +++ b/lib/unictype/categ_P.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Pc.c b/lib/unictype/categ_Pc.c index 06558ada..a0c9ff81 100644 --- a/lib/unictype/categ_Pc.c +++ b/lib/unictype/categ_Pc.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Pd.c b/lib/unictype/categ_Pd.c index 96516d59..8e666338 100644 --- a/lib/unictype/categ_Pd.c +++ b/lib/unictype/categ_Pd.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Pe.c b/lib/unictype/categ_Pe.c index 53155325..f911f38a 100644 --- a/lib/unictype/categ_Pe.c +++ b/lib/unictype/categ_Pe.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Pf.c b/lib/unictype/categ_Pf.c index 435e19f1..c49b52be 100644 --- a/lib/unictype/categ_Pf.c +++ b/lib/unictype/categ_Pf.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Pi.c b/lib/unictype/categ_Pi.c index 9ea1de1d..bf555000 100644 --- a/lib/unictype/categ_Pi.c +++ b/lib/unictype/categ_Pi.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Po.c b/lib/unictype/categ_Po.c index 4c2e2cb1..71cc4b0c 100644 --- a/lib/unictype/categ_Po.c +++ b/lib/unictype/categ_Po.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Ps.c b/lib/unictype/categ_Ps.c index 4e10039d..ce49d393 100644 --- a/lib/unictype/categ_Ps.c +++ b/lib/unictype/categ_Ps.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_S.c b/lib/unictype/categ_S.c index 4eb51f5f..1661bb25 100644 --- a/lib/unictype/categ_S.c +++ b/lib/unictype/categ_S.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Sc.c b/lib/unictype/categ_Sc.c index 171d5b81..f5933fa5 100644 --- a/lib/unictype/categ_Sc.c +++ b/lib/unictype/categ_Sc.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Sk.c b/lib/unictype/categ_Sk.c index 5f4d84e6..3ff45524 100644 --- a/lib/unictype/categ_Sk.c +++ b/lib/unictype/categ_Sk.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Sm.c b/lib/unictype/categ_Sm.c index 158823fd..f1f09f10 100644 --- a/lib/unictype/categ_Sm.c +++ b/lib/unictype/categ_Sm.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_So.c b/lib/unictype/categ_So.c index a1f688b5..691dcc2f 100644 --- a/lib/unictype/categ_So.c +++ b/lib/unictype/categ_So.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Z.c b/lib/unictype/categ_Z.c index eb187d63..569d82a9 100644 --- a/lib/unictype/categ_Z.c +++ b/lib/unictype/categ_Z.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Zl.c b/lib/unictype/categ_Zl.c index 4a6e3df3..58b075ec 100644 --- a/lib/unictype/categ_Zl.c +++ b/lib/unictype/categ_Zl.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Zp.c b/lib/unictype/categ_Zp.c index 23f682cd..3cc8c6c4 100644 --- a/lib/unictype/categ_Zp.c +++ b/lib/unictype/categ_Zp.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_Zs.c b/lib/unictype/categ_Zs.c index c9971577..b4cfed6f 100644 --- a/lib/unictype/categ_Zs.c +++ b/lib/unictype/categ_Zs.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_and.c b/lib/unictype/categ_and.c index 2101f94e..67a06fa4 100644 --- a/lib/unictype/categ_and.c +++ b/lib/unictype/categ_and.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it @@ -22,7 +22,7 @@ uc_general_category_t uc_general_category_and (uc_general_category_t category1, - uc_general_category_t category2) + uc_general_category_t category2) { uint32_t bitmask; uc_general_category_t result; diff --git a/lib/unictype/categ_and_not.c b/lib/unictype/categ_and_not.c index 6cc27596..b550cccc 100644 --- a/lib/unictype/categ_and_not.c +++ b/lib/unictype/categ_and_not.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it @@ -22,7 +22,7 @@ uc_general_category_t uc_general_category_and_not (uc_general_category_t category1, - uc_general_category_t category2) + uc_general_category_t category2) { uint32_t bitmask; uc_general_category_t result; diff --git a/lib/unictype/categ_byname.c b/lib/unictype/categ_byname.c index a175dd15..fb75b675 100644 --- a/lib/unictype/categ_byname.c +++ b/lib/unictype/categ_byname.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -28,77 +28,77 @@ uc_general_category_byname (const char *category_name) switch (category_name[0]) { case 'L': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_L; - case 'u': return UC_CATEGORY_Lu; - case 'l': return UC_CATEGORY_Ll; - case 't': return UC_CATEGORY_Lt; - case 'm': return UC_CATEGORY_Lm; - case 'o': return UC_CATEGORY_Lo; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_L; + case 'u': return UC_CATEGORY_Lu; + case 'l': return UC_CATEGORY_Ll; + case 't': return UC_CATEGORY_Lt; + case 'm': return UC_CATEGORY_Lm; + case 'o': return UC_CATEGORY_Lo; + } + break; case 'M': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_M; - case 'n': return UC_CATEGORY_Mn; - case 'c': return UC_CATEGORY_Mc; - case 'e': return UC_CATEGORY_Me; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_M; + case 'n': return UC_CATEGORY_Mn; + case 'c': return UC_CATEGORY_Mc; + case 'e': return UC_CATEGORY_Me; + } + break; case 'N': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_N; - case 'd': return UC_CATEGORY_Nd; - case 'l': return UC_CATEGORY_Nl; - case 'o': return UC_CATEGORY_No; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_N; + case 'd': return UC_CATEGORY_Nd; + case 'l': return UC_CATEGORY_Nl; + case 'o': return UC_CATEGORY_No; + } + break; case 'P': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_P; - case 'c': return UC_CATEGORY_Pc; - case 'd': return UC_CATEGORY_Pd; - case 's': return UC_CATEGORY_Ps; - case 'e': return UC_CATEGORY_Pe; - case 'i': return UC_CATEGORY_Pi; - case 'f': return UC_CATEGORY_Pf; - case 'o': return UC_CATEGORY_Po; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_P; + case 'c': return UC_CATEGORY_Pc; + case 'd': return UC_CATEGORY_Pd; + case 's': return UC_CATEGORY_Ps; + case 'e': return UC_CATEGORY_Pe; + case 'i': return UC_CATEGORY_Pi; + case 'f': return UC_CATEGORY_Pf; + case 'o': return UC_CATEGORY_Po; + } + break; case 'S': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_S; - case 'm': return UC_CATEGORY_Sm; - case 'c': return UC_CATEGORY_Sc; - case 'k': return UC_CATEGORY_Sk; - case 'o': return UC_CATEGORY_So; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_S; + case 'm': return UC_CATEGORY_Sm; + case 'c': return UC_CATEGORY_Sc; + case 'k': return UC_CATEGORY_Sk; + case 'o': return UC_CATEGORY_So; + } + break; case 'Z': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_Z; - case 's': return UC_CATEGORY_Zs; - case 'l': return UC_CATEGORY_Zl; - case 'p': return UC_CATEGORY_Zp; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_Z; + case 's': return UC_CATEGORY_Zs; + case 'l': return UC_CATEGORY_Zl; + case 'p': return UC_CATEGORY_Zp; + } + break; case 'C': - switch (category_name[1]) - { - case '\0': return UC_CATEGORY_C; - case 'c': return UC_CATEGORY_Cc; - case 'f': return UC_CATEGORY_Cf; - case 's': return UC_CATEGORY_Cs; - case 'o': return UC_CATEGORY_Co; - case 'n': return UC_CATEGORY_Cn; - } - break; + switch (category_name[1]) + { + case '\0': return UC_CATEGORY_C; + case 'c': return UC_CATEGORY_Cc; + case 'f': return UC_CATEGORY_Cf; + case 's': return UC_CATEGORY_Cs; + case 'o': return UC_CATEGORY_Co; + case 'n': return UC_CATEGORY_Cn; + } + break; } /* Invalid category name. */ return _UC_CATEGORY_NONE; diff --git a/lib/unictype/categ_name.c b/lib/unictype/categ_name.c index 10421efc..1243e2f0 100644 --- a/lib/unictype/categ_name.c +++ b/lib/unictype/categ_name.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -35,43 +35,43 @@ uc_general_category_name (uc_general_category_t category) if (bitmask != 0) { if ((bitmask & (bitmask - 1)) == 0) - { - int bit; - /* Take log2 using a variant of Robert Harley's method. - Found by Bruno Haible 1996. */ - uint32_t n = bitmask; - static const char ord2_tab[64] = - { - -1, 0, 1, 12, 2, 6, -1, 13, 3, -1, 7, -1, -1, -1, -1, 14, - 10, 4, -1, -1, 8, -1, -1, 25, -1, -1, -1, -1, -1, 21, 27, 15, - 31, 11, 5, -1, -1, -1, -1, -1, 9, -1, -1, 24, -1, -1, 20, 26, - 30, -1, -1, -1, -1, 23, -1, 19, 29, -1, 22, 18, 28, 17, 16, -1 - }; - n += n << 4; - n += n << 6; - n = (n << 16) - n; - bit = ord2_tab[n >> 26]; + { + int bit; + /* Take log2 using a variant of Robert Harley's method. + Found by Bruno Haible 1996. */ + uint32_t n = bitmask; + static const char ord2_tab[64] = + { + -1, 0, 1, 12, 2, 6, -1, 13, 3, -1, 7, -1, -1, -1, -1, 14, + 10, 4, -1, -1, 8, -1, -1, 25, -1, -1, -1, -1, -1, 21, 27, 15, + 31, 11, 5, -1, -1, -1, -1, -1, 9, -1, -1, 24, -1, -1, 20, 26, + 30, -1, -1, -1, -1, 23, -1, 19, 29, -1, 22, 18, 28, 17, 16, -1 + }; + n += n << 4; + n += n << 6; + n = (n << 16) - n; + bit = ord2_tab[n >> 26]; - if (bit < sizeof (u_category_name) / sizeof (u_category_name[0])) - return u_category_name[bit]; - } + if (bit < sizeof (u_category_name) / sizeof (u_category_name[0])) + return u_category_name[bit]; + } else - { - if (bitmask == UC_CATEGORY_MASK_L) - return "L"; - if (bitmask == UC_CATEGORY_MASK_M) - return "M"; - if (bitmask == UC_CATEGORY_MASK_N) - return "N"; - if (bitmask == UC_CATEGORY_MASK_P) - return "P"; - if (bitmask == UC_CATEGORY_MASK_S) - return "S"; - if (bitmask == UC_CATEGORY_MASK_Z) - return "Z"; - if (bitmask == UC_CATEGORY_MASK_C) - return "C"; - } + { + if (bitmask == UC_CATEGORY_MASK_L) + return "L"; + if (bitmask == UC_CATEGORY_MASK_M) + return "M"; + if (bitmask == UC_CATEGORY_MASK_N) + return "N"; + if (bitmask == UC_CATEGORY_MASK_P) + return "P"; + if (bitmask == UC_CATEGORY_MASK_S) + return "S"; + if (bitmask == UC_CATEGORY_MASK_Z) + return "Z"; + if (bitmask == UC_CATEGORY_MASK_C) + return "C"; + } } return NULL; } diff --git a/lib/unictype/categ_none.c b/lib/unictype/categ_none.c index 9e33ab93..39bc8b24 100644 --- a/lib/unictype/categ_none.c +++ b/lib/unictype/categ_none.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/categ_of.c b/lib/unictype/categ_of.c index 85b694f4..66cca8d0 100644 --- a/lib/unictype/categ_of.c +++ b/lib/unictype/categ_of.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,22 +31,22 @@ lookup_withtable (ucs4_t uc) { int lookup1 = u_category.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> category_header_2) & category_header_3; - int lookup2 = u_category.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = ((uc & category_header_4) + lookup2) * 5; - /* level3 contains 5-bit values, packed into 16-bit words. */ - unsigned int lookup3 = - ((u_category.level3[index3>>4] - | (u_category.level3[(index3>>4)+1] << 16)) - >> (index3 % 16)) - & 0x1f; + { + unsigned int index2 = (uc >> category_header_2) & category_header_3; + int lookup2 = u_category.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = ((uc & category_header_4) + lookup2) * 5; + /* level3 contains 5-bit values, packed into 16-bit words. */ + unsigned int lookup3 = + ((u_category.level3[index3>>4] + | (u_category.level3[(index3>>4)+1] << 16)) + >> (index3 % 16)) + & 0x1f; - return lookup3; - } - } + return lookup3; + } + } return 29; /* = log2(UC_CATEGORY_MASK_Cn) */ } return -1; diff --git a/lib/unictype/categ_or.c b/lib/unictype/categ_or.c index 9864210c..9118418d 100644 --- a/lib/unictype/categ_or.c +++ b/lib/unictype/categ_or.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it @@ -22,7 +22,7 @@ uc_general_category_t uc_general_category_or (uc_general_category_t category1, - uc_general_category_t category2) + uc_general_category_t category2) { uint32_t bitmask; uc_general_category_t result; diff --git a/lib/unictype/categ_test.c b/lib/unictype/categ_test.c index e46f0f65..dd935e77 100644 --- a/lib/unictype/categ_test.c +++ b/lib/unictype/categ_test.c @@ -1,5 +1,5 @@ /* Categories of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/combining.c b/lib/unictype/combining.c index d2e33e63..dfddc906 100644 --- a/lib/unictype/combining.c +++ b/lib/unictype/combining.c @@ -1,5 +1,5 @@ /* Combining classes of Unicode characters. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,17 +31,17 @@ uc_combining_class (ucs4_t uc) { int lookup1 = u_combclass.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> combclass_header_2) & combclass_header_3; - int lookup2 = u_combclass.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & combclass_header_4); - unsigned int lookup3 = u_combclass.level3[lookup2 + index3]; - - return lookup3; - } - } + { + unsigned int index2 = (uc >> combclass_header_2) & combclass_header_3; + int lookup2 = u_combclass.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & combclass_header_4); + unsigned int lookup3 = u_combclass.level3[lookup2 + index3]; + + return lookup3; + } + } } return 0; } diff --git a/lib/unictype/ctype_alnum.c b/lib/unictype/ctype_alnum.c index 464fbb0d..aaf74848 100644 --- a/lib/unictype/ctype_alnum.c +++ b/lib/unictype/ctype_alnum.c @@ -1,5 +1,5 @@ /* ISO C like properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/ctype_alpha.c b/lib/unictype/ctype_alpha.c index 4ca6e996..8c64b6d6 100644 --- a/lib/unictype/ctype_alpha.c +++ b/lib/unictype/ctype_alpha.c @@ -1,5 +1,5 @@ /* ISO C like properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/ctype_blank.c b/lib/unictype/ctype_blank.c index 7e5e44f7..5e2ea542 100644 --- a/lib/unictype/ctype_blank.c +++ b/lib/unictype/ctype_blank.c @@ -1,5 +1,5 @@ /* ISO C like properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/ctype_cntrl.c b/lib/unictype/ctype_cntrl.c index 8d9b148c..13869c51 100644 --- a/lib/unictype/ctype_cntrl.c +++ b/lib/unictype/ctype_cntrl.c @@ -1,5 +1,5 @@ /* ISO C like properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/ctype_digit.c b/lib/unictype/ctype_digit.c index b18d9204..ec444d49 100644 --- a/lib/unictype/ctype_digit.c +++ b/lib/unictype/ctype_digit.c @@ -1,5 +1,5 @@ /* ISO C like properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/ctype_graph.c b/lib/unictype/ctype_graph.c index 3c0ae118..474211be 100644 --- a/lib/unictype/ctype_graph.c +++ b/lib/unictype/ctype_graph.c @@ -1,5 +1,5 @@ /* ISO C like properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/ctype_lower.c b/lib/unictype/ctype_lower.c index 1bc84344..8e1e118d 100644 --- a/lib/unictype/ctype_lower.c +++ b/lib/unictype/ctype_lower.c @@ -1,5 +1,5 @@ /* ISO C like properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/ctype_print.c b/lib/unictype/ctype_print.c index 14238015..8e53e0f0 100644 --- a/lib/unictype/ctype_print.c +++ b/lib/unictype/ctype_print.c @@ -1,5 +1,5 @@ /* ISO C like properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/ctype_punct.c b/lib/unictype/ctype_punct.c index e6b79469..8071a265 100644 --- a/lib/unictype/ctype_punct.c +++ b/lib/unictype/ctype_punct.c @@ -1,5 +1,5 @@ /* ISO C like properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/ctype_space.c b/lib/unictype/ctype_space.c index 09d2c112..93ad8730 100644 --- a/lib/unictype/ctype_space.c +++ b/lib/unictype/ctype_space.c @@ -1,5 +1,5 @@ /* ISO C like properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/ctype_upper.c b/lib/unictype/ctype_upper.c index 7724a048..9348fcc3 100644 --- a/lib/unictype/ctype_upper.c +++ b/lib/unictype/ctype_upper.c @@ -1,5 +1,5 @@ /* ISO C like properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/ctype_xdigit.c b/lib/unictype/ctype_xdigit.c index 60c44c4f..e5400088 100644 --- a/lib/unictype/ctype_xdigit.c +++ b/lib/unictype/ctype_xdigit.c @@ -1,5 +1,5 @@ /* ISO C like properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/decdigit.c b/lib/unictype/decdigit.c index 48b05925..79f8339c 100644 --- a/lib/unictype/decdigit.c +++ b/lib/unictype/decdigit.c @@ -1,5 +1,5 @@ /* Values of decimal digit Unicode characters. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,19 +31,19 @@ uc_decimal_value (ucs4_t uc) { int lookup1 = u_decdigit.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> decdigit_header_2) & decdigit_header_3; - int lookup2 = u_decdigit.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & decdigit_header_4) + lookup2; - /* level3 contains 4-bit values. */ - unsigned int lookup3 = - (u_decdigit.level3[index3>>1] >> ((index3 % 2) * 4)) & 0x0f; - - return (int) lookup3 - 1; - } - } + { + unsigned int index2 = (uc >> decdigit_header_2) & decdigit_header_3; + int lookup2 = u_decdigit.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & decdigit_header_4) + lookup2; + /* level3 contains 4-bit values. */ + unsigned int lookup3 = + (u_decdigit.level3[index3>>1] >> ((index3 % 2) * 4)) & 0x0f; + + return (int) lookup3 - 1; + } + } } return -1; } diff --git a/lib/unictype/digit.c b/lib/unictype/digit.c index 21545c7b..ba999a29 100644 --- a/lib/unictype/digit.c +++ b/lib/unictype/digit.c @@ -1,5 +1,5 @@ /* Values of digit Unicode characters. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,19 +31,19 @@ uc_digit_value (ucs4_t uc) { int lookup1 = u_digit.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> digit_header_2) & digit_header_3; - int lookup2 = u_digit.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & digit_header_4) + lookup2; - /* level3 contains 4-bit values. */ - unsigned int lookup3 = - (u_digit.level3[index3>>1] >> ((index3 % 2) * 4)) & 0x0f; - - return (int) lookup3 - 1; - } - } + { + unsigned int index2 = (uc >> digit_header_2) & digit_header_3; + int lookup2 = u_digit.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & digit_header_4) + lookup2; + /* level3 contains 4-bit values. */ + unsigned int lookup3 = + (u_digit.level3[index3>>1] >> ((index3 % 2) * 4)) & 0x0f; + + return (int) lookup3 - 1; + } + } } return -1; } diff --git a/lib/unictype/identsyntaxmap.h b/lib/unictype/identsyntaxmap.h index 5d9db395..5ff13fca 100644 --- a/lib/unictype/identsyntaxmap.h +++ b/lib/unictype/identsyntaxmap.h @@ -1,5 +1,5 @@ /* Three-level bitmap lookup. - Copyright (C) 2000-2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 2000-2002, 2005-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2000-2002. This program is free software: you can redistribute it and/or modify it @@ -25,18 +25,18 @@ identsyntax_lookup (ucs4_t uc) { int lookup1 = TABLE.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> identsyntax_header_2) & identsyntax_header_3; - int lookup2 = TABLE.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & identsyntax_header_4) + lookup2; - /* level3 contains 2-bit values. */ - unsigned int lookup3 = TABLE.level3[index3 >> 3]; + { + unsigned int index2 = (uc >> identsyntax_header_2) & identsyntax_header_3; + int lookup2 = TABLE.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & identsyntax_header_4) + lookup2; + /* level3 contains 2-bit values. */ + unsigned int lookup3 = TABLE.level3[index3 >> 3]; - return (lookup3 >> (2 * (index3 & 7))) & 3; - } - } + return (lookup3 >> (2 * (index3 & 7))) & 3; + } + } } return UC_IDENTIFIER_INVALID; } diff --git a/lib/unictype/mirror.c b/lib/unictype/mirror.c index 75775447..066d9d34 100644 --- a/lib/unictype/mirror.c +++ b/lib/unictype/mirror.c @@ -1,5 +1,5 @@ /* Mirrored Unicode characters. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,18 +31,18 @@ uc_mirror_char (ucs4_t uc, ucs4_t *puc) { int lookup1 = u_mirror.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> mirror_header_2) & mirror_header_3; - int lookup2 = u_mirror.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & mirror_header_4); - int lookup3 = u_mirror.level3[lookup2 + index3]; - - *puc = uc + lookup3; - return (lookup3 != 0); - } - } + { + unsigned int index2 = (uc >> mirror_header_2) & mirror_header_3; + int lookup2 = u_mirror.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & mirror_header_4); + int lookup3 = u_mirror.level3[lookup2 + index3]; + + *puc = uc + lookup3; + return (lookup3 != 0); + } + } } *puc = uc; return false; diff --git a/lib/unictype/numeric.c b/lib/unictype/numeric.c index fb1512eb..9eb4630c 100644 --- a/lib/unictype/numeric.c +++ b/lib/unictype/numeric.c @@ -1,5 +1,5 @@ /* Values of numeric Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,22 +31,22 @@ uc_numeric_value (ucs4_t uc) { int lookup1 = u_numeric.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> numeric_header_2) & numeric_header_3; - int lookup2 = u_numeric.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = ((uc & numeric_header_4) + lookup2) * 7; - /* level3 contains 7-bit values, packed into 16-bit words. */ - unsigned int lookup3 = - ((u_numeric.level3[index3>>4] - | (u_numeric.level3[(index3>>4)+1] << 16)) - >> (index3 % 16)) - & 0x7f; - - return u_numeric_values[lookup3]; - } - } + { + unsigned int index2 = (uc >> numeric_header_2) & numeric_header_3; + int lookup2 = u_numeric.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = ((uc & numeric_header_4) + lookup2) * 7; + /* level3 contains 7-bit values, packed into 16-bit words. */ + unsigned int lookup3 = + ((u_numeric.level3[index3>>4] + | (u_numeric.level3[(index3>>4)+1] << 16)) + >> (index3 % 16)) + & 0x7f; + + return u_numeric_values[lookup3]; + } + } } { const uc_fraction_t default_value = { 0, 0 }; diff --git a/lib/unictype/pr_alphabetic.c b/lib/unictype/pr_alphabetic.c index 99920916..f94c71a9 100644 --- a/lib/unictype/pr_alphabetic.c +++ b/lib/unictype/pr_alphabetic.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_ascii_hex_digit.c b/lib/unictype/pr_ascii_hex_digit.c index 90d3d3ad..4bad897b 100644 --- a/lib/unictype/pr_ascii_hex_digit.c +++ b/lib/unictype/pr_ascii_hex_digit.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_arabic_digit.c b/lib/unictype/pr_bidi_arabic_digit.c index 15f5f6be..8bcea66b 100644 --- a/lib/unictype/pr_bidi_arabic_digit.c +++ b/lib/unictype/pr_bidi_arabic_digit.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_arabic_right_to_left.c b/lib/unictype/pr_bidi_arabic_right_to_left.c index 81667675..834d67ac 100644 --- a/lib/unictype/pr_bidi_arabic_right_to_left.c +++ b/lib/unictype/pr_bidi_arabic_right_to_left.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_block_separator.c b/lib/unictype/pr_bidi_block_separator.c index 1775d365..bec778db 100644 --- a/lib/unictype/pr_bidi_block_separator.c +++ b/lib/unictype/pr_bidi_block_separator.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_boundary_neutral.c b/lib/unictype/pr_bidi_boundary_neutral.c index 923e89f7..f64ae859 100644 --- a/lib/unictype/pr_bidi_boundary_neutral.c +++ b/lib/unictype/pr_bidi_boundary_neutral.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_common_separator.c b/lib/unictype/pr_bidi_common_separator.c index 2cc1f140..2989ca6a 100644 --- a/lib/unictype/pr_bidi_common_separator.c +++ b/lib/unictype/pr_bidi_common_separator.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_control.c b/lib/unictype/pr_bidi_control.c index 9a4f209c..6bb0adf1 100644 --- a/lib/unictype/pr_bidi_control.c +++ b/lib/unictype/pr_bidi_control.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_embedding_or_override.c b/lib/unictype/pr_bidi_embedding_or_override.c index 70265223..3af5785c 100644 --- a/lib/unictype/pr_bidi_embedding_or_override.c +++ b/lib/unictype/pr_bidi_embedding_or_override.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -40,7 +40,7 @@ uc_is_property_bidi_embedding_or_override (ucs4_t uc) { int category = uc_bidi_category (uc); return (category == UC_BIDI_LRE || category == UC_BIDI_LRO - || category == UC_BIDI_RLE || category == UC_BIDI_RLO); + || category == UC_BIDI_RLE || category == UC_BIDI_RLO); } #endif diff --git a/lib/unictype/pr_bidi_eur_num_separator.c b/lib/unictype/pr_bidi_eur_num_separator.c index 53d3ea74..97a74b3b 100644 --- a/lib/unictype/pr_bidi_eur_num_separator.c +++ b/lib/unictype/pr_bidi_eur_num_separator.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_eur_num_terminator.c b/lib/unictype/pr_bidi_eur_num_terminator.c index de1f4ab9..7376c426 100644 --- a/lib/unictype/pr_bidi_eur_num_terminator.c +++ b/lib/unictype/pr_bidi_eur_num_terminator.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_european_digit.c b/lib/unictype/pr_bidi_european_digit.c index e27c5d3a..f727dcae 100644 --- a/lib/unictype/pr_bidi_european_digit.c +++ b/lib/unictype/pr_bidi_european_digit.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_hebrew_right_to_left.c b/lib/unictype/pr_bidi_hebrew_right_to_left.c index 9dced034..42e836f6 100644 --- a/lib/unictype/pr_bidi_hebrew_right_to_left.c +++ b/lib/unictype/pr_bidi_hebrew_right_to_left.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_left_to_right.c b/lib/unictype/pr_bidi_left_to_right.c index fee8443c..3da97ebe 100644 --- a/lib/unictype/pr_bidi_left_to_right.c +++ b/lib/unictype/pr_bidi_left_to_right.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_non_spacing_mark.c b/lib/unictype/pr_bidi_non_spacing_mark.c index 660d4c13..df470bb3 100644 --- a/lib/unictype/pr_bidi_non_spacing_mark.c +++ b/lib/unictype/pr_bidi_non_spacing_mark.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_other_neutral.c b/lib/unictype/pr_bidi_other_neutral.c index f87b5fbd..0f63bca6 100644 --- a/lib/unictype/pr_bidi_other_neutral.c +++ b/lib/unictype/pr_bidi_other_neutral.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_pdf.c b/lib/unictype/pr_bidi_pdf.c index 808a1efa..7e8ace2c 100644 --- a/lib/unictype/pr_bidi_pdf.c +++ b/lib/unictype/pr_bidi_pdf.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_segment_separator.c b/lib/unictype/pr_bidi_segment_separator.c index 0b3b08af..6452b079 100644 --- a/lib/unictype/pr_bidi_segment_separator.c +++ b/lib/unictype/pr_bidi_segment_separator.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_bidi_whitespace.c b/lib/unictype/pr_bidi_whitespace.c index d16928a1..ef22a3e3 100644 --- a/lib/unictype/pr_bidi_whitespace.c +++ b/lib/unictype/pr_bidi_whitespace.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_byname.c b/lib/unictype/pr_byname.c index cb6e553d..89d59b90 100644 --- a/lib/unictype/pr_byname.c +++ b/lib/unictype/pr_byname.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it @@ -40,16 +40,16 @@ uc_property_byname (const char *property_name) { unsigned char c = (unsigned char) *cp; if (c >= 0x80) - goto invalid; + goto invalid; if (c >= 'A' && c <= 'Z') - c += 'a' - 'A'; + c += 'a' - 'A'; else if (c == ' ' || c == '-') - c = '_'; + c = '_'; *bp = c; if (c == '\0') - break; + break; if (--count == 0) - goto invalid; + goto invalid; } found = uc_property_lookup (buf, bp - buf); if (found != NULL) diff --git a/lib/unictype/pr_combining.c b/lib/unictype/pr_combining.c index 5332b361..631a1b2f 100644 --- a/lib/unictype/pr_combining.c +++ b/lib/unictype/pr_combining.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_composite.c b/lib/unictype/pr_composite.c index 4f01ea86..0aae82a4 100644 --- a/lib/unictype/pr_composite.c +++ b/lib/unictype/pr_composite.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_currency_symbol.c b/lib/unictype/pr_currency_symbol.c index 8a8723b3..1f37bb5b 100644 --- a/lib/unictype/pr_currency_symbol.c +++ b/lib/unictype/pr_currency_symbol.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_dash.c b/lib/unictype/pr_dash.c index 16bccad1..033dc6c6 100644 --- a/lib/unictype/pr_dash.c +++ b/lib/unictype/pr_dash.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_decimal_digit.c b/lib/unictype/pr_decimal_digit.c index e344158a..de31d249 100644 --- a/lib/unictype/pr_decimal_digit.c +++ b/lib/unictype/pr_decimal_digit.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_default_ignorable_code_point.c b/lib/unictype/pr_default_ignorable_code_point.c index f4b7f19e..ce0e8166 100644 --- a/lib/unictype/pr_default_ignorable_code_point.c +++ b/lib/unictype/pr_default_ignorable_code_point.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_deprecated.c b/lib/unictype/pr_deprecated.c index 2b3903b4..9f8cf618 100644 --- a/lib/unictype/pr_deprecated.c +++ b/lib/unictype/pr_deprecated.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_diacritic.c b/lib/unictype/pr_diacritic.c index f541cd12..cb23950b 100644 --- a/lib/unictype/pr_diacritic.c +++ b/lib/unictype/pr_diacritic.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_extender.c b/lib/unictype/pr_extender.c index 25f11f67..5e5a69c8 100644 --- a/lib/unictype/pr_extender.c +++ b/lib/unictype/pr_extender.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_format_control.c b/lib/unictype/pr_format_control.c index f63bb299..aca189e4 100644 --- a/lib/unictype/pr_format_control.c +++ b/lib/unictype/pr_format_control.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_grapheme_base.c b/lib/unictype/pr_grapheme_base.c index 6b090bc2..1d6530c8 100644 --- a/lib/unictype/pr_grapheme_base.c +++ b/lib/unictype/pr_grapheme_base.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_grapheme_extend.c b/lib/unictype/pr_grapheme_extend.c index c51e82eb..1a952971 100644 --- a/lib/unictype/pr_grapheme_extend.c +++ b/lib/unictype/pr_grapheme_extend.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_grapheme_link.c b/lib/unictype/pr_grapheme_link.c index e7aa1335..b3a499c5 100644 --- a/lib/unictype/pr_grapheme_link.c +++ b/lib/unictype/pr_grapheme_link.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_hex_digit.c b/lib/unictype/pr_hex_digit.c index 09357b98..ce5a73a9 100644 --- a/lib/unictype/pr_hex_digit.c +++ b/lib/unictype/pr_hex_digit.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_hyphen.c b/lib/unictype/pr_hyphen.c index 22a55b69..c2a5d0f6 100644 --- a/lib/unictype/pr_hyphen.c +++ b/lib/unictype/pr_hyphen.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_id_continue.c b/lib/unictype/pr_id_continue.c index 5903dc65..0115c467 100644 --- a/lib/unictype/pr_id_continue.c +++ b/lib/unictype/pr_id_continue.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_id_start.c b/lib/unictype/pr_id_start.c index 7d5f35fc..ec349dd9 100644 --- a/lib/unictype/pr_id_start.c +++ b/lib/unictype/pr_id_start.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_ideographic.c b/lib/unictype/pr_ideographic.c index 18f7d02a..266034cd 100644 --- a/lib/unictype/pr_ideographic.c +++ b/lib/unictype/pr_ideographic.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_ids_binary_operator.c b/lib/unictype/pr_ids_binary_operator.c index 74e50c1b..25e12a31 100644 --- a/lib/unictype/pr_ids_binary_operator.c +++ b/lib/unictype/pr_ids_binary_operator.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_ids_trinary_operator.c b/lib/unictype/pr_ids_trinary_operator.c index 422c219e..2a852211 100644 --- a/lib/unictype/pr_ids_trinary_operator.c +++ b/lib/unictype/pr_ids_trinary_operator.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_ignorable_control.c b/lib/unictype/pr_ignorable_control.c index 00a7223c..7b042444 100644 --- a/lib/unictype/pr_ignorable_control.c +++ b/lib/unictype/pr_ignorable_control.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_iso_control.c b/lib/unictype/pr_iso_control.c index 9d2f392e..bba66088 100644 --- a/lib/unictype/pr_iso_control.c +++ b/lib/unictype/pr_iso_control.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_join_control.c b/lib/unictype/pr_join_control.c index ad22cea9..8cf37065 100644 --- a/lib/unictype/pr_join_control.c +++ b/lib/unictype/pr_join_control.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_left_of_pair.c b/lib/unictype/pr_left_of_pair.c index 62b45f48..344e3f04 100644 --- a/lib/unictype/pr_left_of_pair.c +++ b/lib/unictype/pr_left_of_pair.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_line_separator.c b/lib/unictype/pr_line_separator.c index 0c0b320a..72c19646 100644 --- a/lib/unictype/pr_line_separator.c +++ b/lib/unictype/pr_line_separator.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_logical_order_exception.c b/lib/unictype/pr_logical_order_exception.c index e06f2719..720e951b 100644 --- a/lib/unictype/pr_logical_order_exception.c +++ b/lib/unictype/pr_logical_order_exception.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_lowercase.c b/lib/unictype/pr_lowercase.c index ed719da9..1dbbba28 100644 --- a/lib/unictype/pr_lowercase.c +++ b/lib/unictype/pr_lowercase.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_math.c b/lib/unictype/pr_math.c index a4971d25..35bde045 100644 --- a/lib/unictype/pr_math.c +++ b/lib/unictype/pr_math.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_non_break.c b/lib/unictype/pr_non_break.c index d1855d4f..7ef84ff1 100644 --- a/lib/unictype/pr_non_break.c +++ b/lib/unictype/pr_non_break.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_not_a_character.c b/lib/unictype/pr_not_a_character.c index 05910fe6..b8b96c3b 100644 --- a/lib/unictype/pr_not_a_character.c +++ b/lib/unictype/pr_not_a_character.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_numeric.c b/lib/unictype/pr_numeric.c index dfa2250a..7fe7633c 100644 --- a/lib/unictype/pr_numeric.c +++ b/lib/unictype/pr_numeric.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_other_alphabetic.c b/lib/unictype/pr_other_alphabetic.c index 1a880f5b..398288f6 100644 --- a/lib/unictype/pr_other_alphabetic.c +++ b/lib/unictype/pr_other_alphabetic.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_other_default_ignorable_code_point.c b/lib/unictype/pr_other_default_ignorable_code_point.c index 434977d1..1f651957 100644 --- a/lib/unictype/pr_other_default_ignorable_code_point.c +++ b/lib/unictype/pr_other_default_ignorable_code_point.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_other_grapheme_extend.c b/lib/unictype/pr_other_grapheme_extend.c index fb7af9c2..209e19fc 100644 --- a/lib/unictype/pr_other_grapheme_extend.c +++ b/lib/unictype/pr_other_grapheme_extend.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_other_id_continue.c b/lib/unictype/pr_other_id_continue.c index 75e71c3c..aeb00cc8 100644 --- a/lib/unictype/pr_other_id_continue.c +++ b/lib/unictype/pr_other_id_continue.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_other_id_start.c b/lib/unictype/pr_other_id_start.c index 1858e47f..40d09bce 100644 --- a/lib/unictype/pr_other_id_start.c +++ b/lib/unictype/pr_other_id_start.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_other_lowercase.c b/lib/unictype/pr_other_lowercase.c index c199b174..8126f3c9 100644 --- a/lib/unictype/pr_other_lowercase.c +++ b/lib/unictype/pr_other_lowercase.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_other_math.c b/lib/unictype/pr_other_math.c index 7e130e7f..30a864db 100644 --- a/lib/unictype/pr_other_math.c +++ b/lib/unictype/pr_other_math.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_other_uppercase.c b/lib/unictype/pr_other_uppercase.c index 278ce514..9c6b1deb 100644 --- a/lib/unictype/pr_other_uppercase.c +++ b/lib/unictype/pr_other_uppercase.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_paired_punctuation.c b/lib/unictype/pr_paired_punctuation.c index 52b0dbb4..1faa2cdf 100644 --- a/lib/unictype/pr_paired_punctuation.c +++ b/lib/unictype/pr_paired_punctuation.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_paragraph_separator.c b/lib/unictype/pr_paragraph_separator.c index c1aeff31..dc7260dd 100644 --- a/lib/unictype/pr_paragraph_separator.c +++ b/lib/unictype/pr_paragraph_separator.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_pattern_syntax.c b/lib/unictype/pr_pattern_syntax.c index 5f5366f6..bd46e3f1 100644 --- a/lib/unictype/pr_pattern_syntax.c +++ b/lib/unictype/pr_pattern_syntax.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_pattern_white_space.c b/lib/unictype/pr_pattern_white_space.c index 407cc7e5..6c4465c8 100644 --- a/lib/unictype/pr_pattern_white_space.c +++ b/lib/unictype/pr_pattern_white_space.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_private_use.c b/lib/unictype/pr_private_use.c index 64a28c78..815ac9b6 100644 --- a/lib/unictype/pr_private_use.c +++ b/lib/unictype/pr_private_use.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -39,8 +39,8 @@ bool uc_is_property_private_use (ucs4_t uc) { return (uc >= 0xE000 && uc <= 0xF8FF) - || (uc >= 0xF0000 && uc <= 0xFFFFD) - || (uc >= 0x100000 && uc <= 0x10FFFD); + || (uc >= 0xF0000 && uc <= 0xFFFFD) + || (uc >= 0x100000 && uc <= 0x10FFFD); } #endif diff --git a/lib/unictype/pr_punctuation.c b/lib/unictype/pr_punctuation.c index 00efeee3..39f0cfaf 100644 --- a/lib/unictype/pr_punctuation.c +++ b/lib/unictype/pr_punctuation.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_quotation_mark.c b/lib/unictype/pr_quotation_mark.c index e07fef2e..13e3239a 100644 --- a/lib/unictype/pr_quotation_mark.c +++ b/lib/unictype/pr_quotation_mark.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_radical.c b/lib/unictype/pr_radical.c index 13431628..3d82389c 100644 --- a/lib/unictype/pr_radical.c +++ b/lib/unictype/pr_radical.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_sentence_terminal.c b/lib/unictype/pr_sentence_terminal.c index 85d5e68e..81a94da9 100644 --- a/lib/unictype/pr_sentence_terminal.c +++ b/lib/unictype/pr_sentence_terminal.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_soft_dotted.c b/lib/unictype/pr_soft_dotted.c index b261d3c1..b4a5c8ba 100644 --- a/lib/unictype/pr_soft_dotted.c +++ b/lib/unictype/pr_soft_dotted.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_space.c b/lib/unictype/pr_space.c index 5bc3881e..b34b366f 100644 --- a/lib/unictype/pr_space.c +++ b/lib/unictype/pr_space.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_terminal_punctuation.c b/lib/unictype/pr_terminal_punctuation.c index 30a79f92..5843a347 100644 --- a/lib/unictype/pr_terminal_punctuation.c +++ b/lib/unictype/pr_terminal_punctuation.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_test.c b/lib/unictype/pr_test.c index 6d997b4c..e1068394 100644 --- a/lib/unictype/pr_test.c +++ b/lib/unictype/pr_test.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_titlecase.c b/lib/unictype/pr_titlecase.c index eeb7dcc5..93a6a886 100644 --- a/lib/unictype/pr_titlecase.c +++ b/lib/unictype/pr_titlecase.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_unassigned_code_value.c b/lib/unictype/pr_unassigned_code_value.c index 328b5e7c..b7baf1b2 100644 --- a/lib/unictype/pr_unassigned_code_value.c +++ b/lib/unictype/pr_unassigned_code_value.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_unified_ideograph.c b/lib/unictype/pr_unified_ideograph.c index 99096a82..b08494ff 100644 --- a/lib/unictype/pr_unified_ideograph.c +++ b/lib/unictype/pr_unified_ideograph.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_uppercase.c b/lib/unictype/pr_uppercase.c index 38c122a9..d373393a 100644 --- a/lib/unictype/pr_uppercase.c +++ b/lib/unictype/pr_uppercase.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_variation_selector.c b/lib/unictype/pr_variation_selector.c index 2f1d3888..d7604d6d 100644 --- a/lib/unictype/pr_variation_selector.c +++ b/lib/unictype/pr_variation_selector.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_white_space.c b/lib/unictype/pr_white_space.c index 1cd9c5f4..18dc4ec2 100644 --- a/lib/unictype/pr_white_space.c +++ b/lib/unictype/pr_white_space.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_xid_continue.c b/lib/unictype/pr_xid_continue.c index d7d92c3c..67faae13 100644 --- a/lib/unictype/pr_xid_continue.c +++ b/lib/unictype/pr_xid_continue.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_xid_start.c b/lib/unictype/pr_xid_start.c index 13aab1b5..b9b496f7 100644 --- a/lib/unictype/pr_xid_start.c +++ b/lib/unictype/pr_xid_start.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/pr_zero_width.c b/lib/unictype/pr_zero_width.c index 7decbdae..903e0039 100644 --- a/lib/unictype/pr_zero_width.c +++ b/lib/unictype/pr_zero_width.c @@ -1,5 +1,5 @@ /* Properties of Unicode characters. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/scripts.c b/lib/unictype/scripts.c index 092009db..822c3c56 100644 --- a/lib/unictype/scripts.c +++ b/lib/unictype/scripts.c @@ -1,5 +1,5 @@ /* Scripts of Unicode characters. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it @@ -33,18 +33,18 @@ uc_script (ucs4_t uc) { int lookup1 = u_script.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> script_header_2) & script_header_3; - int lookup2 = u_script.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & script_header_4); - unsigned char lookup3 = u_script.level3[lookup2 + index3]; + { + unsigned int index2 = (uc >> script_header_2) & script_header_3; + int lookup2 = u_script.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & script_header_4); + unsigned char lookup3 = u_script.level3[lookup2 + index3]; - if (lookup3 != 0xff) - return &scripts[lookup3]; - } - } + if (lookup3 != 0xff) + return &scripts[lookup3]; + } + } } return NULL; } diff --git a/lib/unictype/sy_c_ident.c b/lib/unictype/sy_c_ident.c index c6033c86..3d898416 100644 --- a/lib/unictype/sy_c_ident.c +++ b/lib/unictype/sy_c_ident.c @@ -1,5 +1,5 @@ /* Syntax properties of Unicode characters. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/sy_c_whitespace.c b/lib/unictype/sy_c_whitespace.c index 6d996a6f..989838f4 100644 --- a/lib/unictype/sy_c_whitespace.c +++ b/lib/unictype/sy_c_whitespace.c @@ -1,5 +1,5 @@ /* Syntax properties of Unicode characters. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/sy_java_ident.c b/lib/unictype/sy_java_ident.c index b0770d6e..1defc2b3 100644 --- a/lib/unictype/sy_java_ident.c +++ b/lib/unictype/sy_java_ident.c @@ -1,5 +1,5 @@ /* Syntax properties of Unicode characters. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unictype/sy_java_whitespace.c b/lib/unictype/sy_java_whitespace.c index 4b56f3e3..34d3afde 100644 --- a/lib/unictype/sy_java_whitespace.c +++ b/lib/unictype/sy_java_whitespace.c @@ -1,5 +1,5 @@ /* Syntax properties of Unicode characters. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unilbrk.h b/lib/unilbrk.h index 1f5e2623..ca8f42b7 100644 --- a/lib/unilbrk.h +++ b/lib/unilbrk.h @@ -1,5 +1,5 @@ /* Line breaking of Unicode strings. - Copyright (C) 2001-2003, 2005-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -58,16 +58,16 @@ enum */ extern void u8_possible_linebreaks (const uint8_t *s, size_t n, - const char *encoding, char *p); + const char *encoding, char *p); extern void u16_possible_linebreaks (const uint16_t *s, size_t n, - const char *encoding, char *p); + const char *encoding, char *p); extern void u32_possible_linebreaks (const uint32_t *s, size_t n, - const char *encoding, char *p); + const char *encoding, char *p); extern void ulc_possible_linebreaks (const char *s, size_t n, - const char *encoding, char *p); + const char *encoding, char *p); /* Choose the best line breaks, assuming the uc_width function. The string is s[0..n-1]. The maximum number of columns per line is given @@ -82,24 +82,24 @@ extern void */ extern int u8_width_linebreaks (const uint8_t *s, size_t n, int width, - int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p); + int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p); extern int u16_width_linebreaks (const uint16_t *s, size_t n, int width, - int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p); + int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p); extern int u32_width_linebreaks (const uint32_t *s, size_t n, int width, - int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p); + int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p); extern int ulc_width_linebreaks (const char *s, size_t n, int width, - int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p); + int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p); #ifdef __cplusplus diff --git a/lib/unilbrk/lbrkprop1.h b/lib/unilbrk/lbrkprop1.h index 66fd5849..ba6e1b86 100644 --- a/lib/unilbrk/lbrkprop1.h +++ b/lib/unilbrk/lbrkprop1.h @@ -2,7 +2,7 @@ /* Line breaking properties of Unicode characters. */ /* Generated automatically by gen-lbrk for Unicode 5.1.0. */ -/* Copyright (C) 2000-2002, 2004, 2008 Free Software Foundation, Inc. +/* Copyright (C) 2000-2002, 2004, 2008-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/unilbrk/lbrkprop2.h b/lib/unilbrk/lbrkprop2.h index a71b4d9e..45b93b1b 100644 --- a/lib/unilbrk/lbrkprop2.h +++ b/lib/unilbrk/lbrkprop2.h @@ -2,7 +2,7 @@ /* Line breaking properties of Unicode characters. */ /* Generated automatically by gen-lbrk for Unicode 5.1.0. */ -/* Copyright (C) 2000-2002, 2004, 2008 Free Software Foundation, Inc. +/* Copyright (C) 2000-2002, 2004, 2008-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/unilbrk/lbrktables.c b/lib/unilbrk/lbrktables.c index ae3ebf4f..fbc89311 100644 --- a/lib/unilbrk/lbrktables.c +++ b/lib/unilbrk/lbrktables.c @@ -1,5 +1,5 @@ /* Line breaking auxiliary tables. - Copyright (C) 2001-2003, 2006-2009 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -25,8 +25,8 @@ const unsigned char unilbrk_table[24][24] = { - /* after */ - /* WJ GL B2 BA BB HY CL EX IN NS OP QU IS NU PO PR SY AL H2 H3 ID JL JV JT */ + /* after */ + /* WJ GL B2 BA BB HY CL EX IN NS OP QU IS NU PO PR SY AL H2 H3 ID JL JV JT */ /* WJ */ { P, I, I, I, I, I, P, P, I, I, I, I, P, I, I, I, P, I, I, I, I, I, I, I, }, /* GL */ { P, I, I, I, I, I, P, P, I, I, I, I, P, I, I, I, P, I, I, I, I, I, I, I, }, /* B2 */ { P, I, P, I, D, I, P, P, D, I, D, I, P, D, D, D, P, D, D, D, D, D, D, D, }, diff --git a/lib/unilbrk/lbrktables.h b/lib/unilbrk/lbrktables.h index 33b525be..e86c49ff 100644 --- a/lib/unilbrk/lbrktables.h +++ b/lib/unilbrk/lbrktables.h @@ -1,5 +1,5 @@ /* Line breaking auxiliary tables. - Copyright (C) 2001-2003, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -70,15 +70,15 @@ unilbrkprop_lookup (ucs4_t uc) { int lookup1 = unilbrkprop.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> lbrkprop_header_2) & lbrkprop_header_3; - int lookup2 = unilbrkprop.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = uc & lbrkprop_header_4; - return unilbrkprop.level3[lookup2 + index3]; - } - } + { + unsigned int index2 = (uc >> lbrkprop_header_2) & lbrkprop_header_3; + int lookup2 = unilbrkprop.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = uc & lbrkprop_header_4; + return unilbrkprop.level3[lookup2 + index3]; + } + } } return LBP_XX; } diff --git a/lib/unilbrk/u16-possible-linebreaks.c b/lib/unilbrk/u16-possible-linebreaks.c index f5b69921..25b9851a 100644 --- a/lib/unilbrk/u16-possible-linebreaks.c +++ b/lib/unilbrk/u16-possible-linebreaks.c @@ -1,5 +1,5 @@ /* Line breaking of UTF-16 strings. - Copyright (C) 2001-2003, 2006-2009 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -46,117 +46,117 @@ u16_possible_linebreaks (const uint16_t *s, size_t n, const char *encoding, char int prop = unilbrkprop_lookup (uc); if (prop == LBP_BK) - { - /* Mandatory break. */ - *p = UC_BREAK_MANDATORY; - last_prop = LBP_BK; - seen_space = NULL; - seen_space2 = NULL; - } + { + /* Mandatory break. */ + *p = UC_BREAK_MANDATORY; + last_prop = LBP_BK; + seen_space = NULL; + seen_space2 = NULL; + } else - { - char *q; + { + char *q; - /* Resolve property values whose behaviour is not fixed. */ - switch (prop) - { - case LBP_AI: - /* Resolve ambiguous. */ - prop = LBP_AI_REPLACEMENT; - break; - case LBP_CB: - /* This is arbitrary. */ - prop = LBP_ID; - break; - case LBP_SA: - /* We don't handle complex scripts yet. - Treat LBP_SA like LBP_XX. */ - case LBP_XX: - /* This is arbitrary. */ - prop = LBP_AL; - break; - } + /* Resolve property values whose behaviour is not fixed. */ + switch (prop) + { + case LBP_AI: + /* Resolve ambiguous. */ + prop = LBP_AI_REPLACEMENT; + break; + case LBP_CB: + /* This is arbitrary. */ + prop = LBP_ID; + break; + case LBP_SA: + /* We don't handle complex scripts yet. + Treat LBP_SA like LBP_XX. */ + case LBP_XX: + /* This is arbitrary. */ + prop = LBP_AL; + break; + } - /* Deal with spaces and combining characters. */ - q = p; - if (prop == LBP_SP) - { - /* Don't break just before a space. */ - *p = UC_BREAK_PROHIBITED; - seen_space2 = seen_space; - seen_space = p; - } - else if (prop == LBP_ZW) - { - /* Don't break just before a zero-width space. */ - *p = UC_BREAK_PROHIBITED; - last_prop = LBP_ZW; - seen_space = NULL; - seen_space2 = NULL; - } - else if (prop == LBP_CM) - { - /* Don't break just before a combining character, except immediately after a - zero-width space. */ - if (last_prop == LBP_ZW) - { - /* Break after zero-width space. */ - *p = UC_BREAK_POSSIBLE; - /* A combining character turns a preceding space into LBP_ID. */ - last_prop = LBP_ID; - } - else - { - *p = UC_BREAK_PROHIBITED; - /* A combining character turns a preceding space into LBP_ID. */ - if (seen_space != NULL) - { - q = seen_space; - seen_space = seen_space2; - prop = LBP_ID; - goto lookup_via_table; - } - } - } - else - { - lookup_via_table: - /* prop must be usable as an index for table 7.3 of UTR #14. */ - if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) - abort (); + /* Deal with spaces and combining characters. */ + q = p; + if (prop == LBP_SP) + { + /* Don't break just before a space. */ + *p = UC_BREAK_PROHIBITED; + seen_space2 = seen_space; + seen_space = p; + } + else if (prop == LBP_ZW) + { + /* Don't break just before a zero-width space. */ + *p = UC_BREAK_PROHIBITED; + last_prop = LBP_ZW; + seen_space = NULL; + seen_space2 = NULL; + } + else if (prop == LBP_CM) + { + /* Don't break just before a combining character, except immediately after a + zero-width space. */ + if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *p = UC_BREAK_POSSIBLE; + /* A combining character turns a preceding space into LBP_ID. */ + last_prop = LBP_ID; + } + else + { + *p = UC_BREAK_PROHIBITED; + /* A combining character turns a preceding space into LBP_ID. */ + if (seen_space != NULL) + { + q = seen_space; + seen_space = seen_space2; + prop = LBP_ID; + goto lookup_via_table; + } + } + } + else + { + lookup_via_table: + /* prop must be usable as an index for table 7.3 of UTR #14. */ + if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) + abort (); - if (last_prop == LBP_BK) - { - /* Don't break at the beginning of a line. */ - *q = UC_BREAK_PROHIBITED; - } - else if (last_prop == LBP_ZW) - { - /* Break after zero-width space. */ - *q = UC_BREAK_POSSIBLE; - } - else - { - switch (unilbrk_table [last_prop] [prop]) - { - case D: - *q = UC_BREAK_POSSIBLE; - break; - case I: - *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED); - break; - case P: - *q = UC_BREAK_PROHIBITED; - break; - default: - abort (); - } - } - last_prop = prop; - seen_space = NULL; - seen_space2 = NULL; - } - } + if (last_prop == LBP_BK) + { + /* Don't break at the beginning of a line. */ + *q = UC_BREAK_PROHIBITED; + } + else if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *q = UC_BREAK_POSSIBLE; + } + else + { + switch (unilbrk_table [last_prop] [prop]) + { + case D: + *q = UC_BREAK_POSSIBLE; + break; + case I: + *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED); + break; + case P: + *q = UC_BREAK_PROHIBITED; + break; + default: + abort (); + } + } + last_prop = prop; + seen_space = NULL; + seen_space2 = NULL; + } + } s += count; p += count; diff --git a/lib/unilbrk/u16-width-linebreaks.c b/lib/unilbrk/u16-width-linebreaks.c index 64445590..152178e5 100644 --- a/lib/unilbrk/u16-width-linebreaks.c +++ b/lib/unilbrk/u16-width-linebreaks.c @@ -1,5 +1,5 @@ /* Line breaking of UTF-16 strings. - Copyright (C) 2001-2003, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -25,9 +25,9 @@ int u16_width_linebreaks (const uint16_t *s, size_t n, - int width, int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p) + int width, int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p) { const uint16_t *s_end; char *last_p; @@ -47,53 +47,53 @@ u16_width_linebreaks (const uint16_t *s, size_t n, /* Respect the override. */ if (o != NULL && *o != UC_BREAK_UNDEFINED) - *p = *o; + *p = *o; if (*p == UC_BREAK_POSSIBLE || *p == UC_BREAK_MANDATORY) - { - /* An atomic piece of text ends here. */ - if (last_p != NULL && last_column + piece_width > width) - { - /* Insert a line break. */ - *last_p = UC_BREAK_POSSIBLE; - last_column = 0; - } - } + { + /* An atomic piece of text ends here. */ + if (last_p != NULL && last_column + piece_width > width) + { + /* Insert a line break. */ + *last_p = UC_BREAK_POSSIBLE; + last_column = 0; + } + } if (*p == UC_BREAK_MANDATORY) - { - /* uc is a line break character. */ - /* Start a new piece at column 0. */ - last_p = NULL; - last_column = 0; - piece_width = 0; - } + { + /* uc is a line break character. */ + /* Start a new piece at column 0. */ + last_p = NULL; + last_column = 0; + piece_width = 0; + } else - { - /* uc is not a line break character. */ - int w; - - if (*p == UC_BREAK_POSSIBLE) - { - /* Start a new piece. */ - last_p = p; - last_column += piece_width; - piece_width = 0; - /* No line break for the moment, may be turned into - UC_BREAK_POSSIBLE later, via last_p. */ - } - - *p = UC_BREAK_PROHIBITED; - - w = uc_width (uc, encoding); - if (w >= 0) /* ignore control characters in the string */ - piece_width += w; - } + { + /* uc is not a line break character. */ + int w; + + if (*p == UC_BREAK_POSSIBLE) + { + /* Start a new piece. */ + last_p = p; + last_column += piece_width; + piece_width = 0; + /* No line break for the moment, may be turned into + UC_BREAK_POSSIBLE later, via last_p. */ + } + + *p = UC_BREAK_PROHIBITED; + + w = uc_width (uc, encoding); + if (w >= 0) /* ignore control characters in the string */ + piece_width += w; + } s += count; p += count; if (o != NULL) - o += count; + o += count; } /* The last atomic piece of text ends here. */ diff --git a/lib/unilbrk/u32-possible-linebreaks.c b/lib/unilbrk/u32-possible-linebreaks.c index c843e12b..c375a0c7 100644 --- a/lib/unilbrk/u32-possible-linebreaks.c +++ b/lib/unilbrk/u32-possible-linebreaks.c @@ -1,5 +1,5 @@ /* Line breaking of UTF-32 strings. - Copyright (C) 2001-2003, 2006-2009 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -40,117 +40,117 @@ u32_possible_linebreaks (const uint32_t *s, size_t n, const char *encoding, char int prop = unilbrkprop_lookup (uc); if (prop == LBP_BK) - { - /* Mandatory break. */ - *p = UC_BREAK_MANDATORY; - last_prop = LBP_BK; - seen_space = NULL; - seen_space2 = NULL; - } + { + /* Mandatory break. */ + *p = UC_BREAK_MANDATORY; + last_prop = LBP_BK; + seen_space = NULL; + seen_space2 = NULL; + } else - { - char *q; + { + char *q; - /* Resolve property values whose behaviour is not fixed. */ - switch (prop) - { - case LBP_AI: - /* Resolve ambiguous. */ - prop = LBP_AI_REPLACEMENT; - break; - case LBP_CB: - /* This is arbitrary. */ - prop = LBP_ID; - break; - case LBP_SA: - /* We don't handle complex scripts yet. - Treat LBP_SA like LBP_XX. */ - case LBP_XX: - /* This is arbitrary. */ - prop = LBP_AL; - break; - } + /* Resolve property values whose behaviour is not fixed. */ + switch (prop) + { + case LBP_AI: + /* Resolve ambiguous. */ + prop = LBP_AI_REPLACEMENT; + break; + case LBP_CB: + /* This is arbitrary. */ + prop = LBP_ID; + break; + case LBP_SA: + /* We don't handle complex scripts yet. + Treat LBP_SA like LBP_XX. */ + case LBP_XX: + /* This is arbitrary. */ + prop = LBP_AL; + break; + } - /* Deal with spaces and combining characters. */ - q = p; - if (prop == LBP_SP) - { - /* Don't break just before a space. */ - *p = UC_BREAK_PROHIBITED; - seen_space2 = seen_space; - seen_space = p; - } - else if (prop == LBP_ZW) - { - /* Don't break just before a zero-width space. */ - *p = UC_BREAK_PROHIBITED; - last_prop = LBP_ZW; - seen_space = NULL; - seen_space2 = NULL; - } - else if (prop == LBP_CM) - { - /* Don't break just before a combining character, except immediately after a - zero-width space. */ - if (last_prop == LBP_ZW) - { - /* Break after zero-width space. */ - *p = UC_BREAK_POSSIBLE; - /* A combining character turns a preceding space into LBP_ID. */ - last_prop = LBP_ID; - } - else - { - *p = UC_BREAK_PROHIBITED; - /* A combining character turns a preceding space into LBP_ID. */ - if (seen_space != NULL) - { - q = seen_space; - seen_space = seen_space2; - prop = LBP_ID; - goto lookup_via_table; - } - } - } - else - { - lookup_via_table: - /* prop must be usable as an index for table 7.3 of UTR #14. */ - if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) - abort (); + /* Deal with spaces and combining characters. */ + q = p; + if (prop == LBP_SP) + { + /* Don't break just before a space. */ + *p = UC_BREAK_PROHIBITED; + seen_space2 = seen_space; + seen_space = p; + } + else if (prop == LBP_ZW) + { + /* Don't break just before a zero-width space. */ + *p = UC_BREAK_PROHIBITED; + last_prop = LBP_ZW; + seen_space = NULL; + seen_space2 = NULL; + } + else if (prop == LBP_CM) + { + /* Don't break just before a combining character, except immediately after a + zero-width space. */ + if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *p = UC_BREAK_POSSIBLE; + /* A combining character turns a preceding space into LBP_ID. */ + last_prop = LBP_ID; + } + else + { + *p = UC_BREAK_PROHIBITED; + /* A combining character turns a preceding space into LBP_ID. */ + if (seen_space != NULL) + { + q = seen_space; + seen_space = seen_space2; + prop = LBP_ID; + goto lookup_via_table; + } + } + } + else + { + lookup_via_table: + /* prop must be usable as an index for table 7.3 of UTR #14. */ + if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) + abort (); - if (last_prop == LBP_BK) - { - /* Don't break at the beginning of a line. */ - *q = UC_BREAK_PROHIBITED; - } - else if (last_prop == LBP_ZW) - { - /* Break after zero-width space. */ - *q = UC_BREAK_POSSIBLE; - } - else - { - switch (unilbrk_table [last_prop] [prop]) - { - case D: - *q = UC_BREAK_POSSIBLE; - break; - case I: - *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED); - break; - case P: - *q = UC_BREAK_PROHIBITED; - break; - default: - abort (); - } - } - last_prop = prop; - seen_space = NULL; - seen_space2 = NULL; - } - } + if (last_prop == LBP_BK) + { + /* Don't break at the beginning of a line. */ + *q = UC_BREAK_PROHIBITED; + } + else if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *q = UC_BREAK_POSSIBLE; + } + else + { + switch (unilbrk_table [last_prop] [prop]) + { + case D: + *q = UC_BREAK_POSSIBLE; + break; + case I: + *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED); + break; + case P: + *q = UC_BREAK_PROHIBITED; + break; + default: + abort (); + } + } + last_prop = prop; + seen_space = NULL; + seen_space2 = NULL; + } + } s++; p++; diff --git a/lib/unilbrk/u32-width-linebreaks.c b/lib/unilbrk/u32-width-linebreaks.c index 2d362560..c5803dbf 100644 --- a/lib/unilbrk/u32-width-linebreaks.c +++ b/lib/unilbrk/u32-width-linebreaks.c @@ -1,5 +1,5 @@ /* Line breaking of UTF-32 strings. - Copyright (C) 2001-2003, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -24,9 +24,9 @@ int u32_width_linebreaks (const uint32_t *s, size_t n, - int width, int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p) + int width, int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p) { const uint32_t *s_end; char *last_p; @@ -45,53 +45,53 @@ u32_width_linebreaks (const uint32_t *s, size_t n, /* Respect the override. */ if (o != NULL && *o != UC_BREAK_UNDEFINED) - *p = *o; + *p = *o; if (*p == UC_BREAK_POSSIBLE || *p == UC_BREAK_MANDATORY) - { - /* An atomic piece of text ends here. */ - if (last_p != NULL && last_column + piece_width > width) - { - /* Insert a line break. */ - *last_p = UC_BREAK_POSSIBLE; - last_column = 0; - } - } + { + /* An atomic piece of text ends here. */ + if (last_p != NULL && last_column + piece_width > width) + { + /* Insert a line break. */ + *last_p = UC_BREAK_POSSIBLE; + last_column = 0; + } + } if (*p == UC_BREAK_MANDATORY) - { - /* uc is a line break character. */ - /* Start a new piece at column 0. */ - last_p = NULL; - last_column = 0; - piece_width = 0; - } + { + /* uc is a line break character. */ + /* Start a new piece at column 0. */ + last_p = NULL; + last_column = 0; + piece_width = 0; + } else - { - /* uc is not a line break character. */ - int w; - - if (*p == UC_BREAK_POSSIBLE) - { - /* Start a new piece. */ - last_p = p; - last_column += piece_width; - piece_width = 0; - /* No line break for the moment, may be turned into - UC_BREAK_POSSIBLE later, via last_p. */ - } - - *p = UC_BREAK_PROHIBITED; - - w = uc_width (uc, encoding); - if (w >= 0) /* ignore control characters in the string */ - piece_width += w; - } + { + /* uc is not a line break character. */ + int w; + + if (*p == UC_BREAK_POSSIBLE) + { + /* Start a new piece. */ + last_p = p; + last_column += piece_width; + piece_width = 0; + /* No line break for the moment, may be turned into + UC_BREAK_POSSIBLE later, via last_p. */ + } + + *p = UC_BREAK_PROHIBITED; + + w = uc_width (uc, encoding); + if (w >= 0) /* ignore control characters in the string */ + piece_width += w; + } s++; p++; if (o != NULL) - o++; + o++; } /* The last atomic piece of text ends here. */ diff --git a/lib/unilbrk/u8-possible-linebreaks.c b/lib/unilbrk/u8-possible-linebreaks.c index 94e14f40..d65335ea 100644 --- a/lib/unilbrk/u8-possible-linebreaks.c +++ b/lib/unilbrk/u8-possible-linebreaks.c @@ -1,5 +1,5 @@ /* Line breaking of UTF-8 strings. - Copyright (C) 2001-2003, 2006-2009 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -46,117 +46,117 @@ u8_possible_linebreaks (const uint8_t *s, size_t n, const char *encoding, char * int prop = unilbrkprop_lookup (uc); if (prop == LBP_BK) - { - /* Mandatory break. */ - *p = UC_BREAK_MANDATORY; - last_prop = LBP_BK; - seen_space = NULL; - seen_space2 = NULL; - } + { + /* Mandatory break. */ + *p = UC_BREAK_MANDATORY; + last_prop = LBP_BK; + seen_space = NULL; + seen_space2 = NULL; + } else - { - char *q; + { + char *q; - /* Resolve property values whose behaviour is not fixed. */ - switch (prop) - { - case LBP_AI: - /* Resolve ambiguous. */ - prop = LBP_AI_REPLACEMENT; - break; - case LBP_CB: - /* This is arbitrary. */ - prop = LBP_ID; - break; - case LBP_SA: - /* We don't handle complex scripts yet. - Treat LBP_SA like LBP_XX. */ - case LBP_XX: - /* This is arbitrary. */ - prop = LBP_AL; - break; - } + /* Resolve property values whose behaviour is not fixed. */ + switch (prop) + { + case LBP_AI: + /* Resolve ambiguous. */ + prop = LBP_AI_REPLACEMENT; + break; + case LBP_CB: + /* This is arbitrary. */ + prop = LBP_ID; + break; + case LBP_SA: + /* We don't handle complex scripts yet. + Treat LBP_SA like LBP_XX. */ + case LBP_XX: + /* This is arbitrary. */ + prop = LBP_AL; + break; + } - /* Deal with spaces and combining characters. */ - q = p; - if (prop == LBP_SP) - { - /* Don't break just before a space. */ - *p = UC_BREAK_PROHIBITED; - seen_space2 = seen_space; - seen_space = p; - } - else if (prop == LBP_ZW) - { - /* Don't break just before a zero-width space. */ - *p = UC_BREAK_PROHIBITED; - last_prop = LBP_ZW; - seen_space = NULL; - seen_space2 = NULL; - } - else if (prop == LBP_CM) - { - /* Don't break just before a combining character, except immediately after a - zero-width space. */ - if (last_prop == LBP_ZW) - { - /* Break after zero-width space. */ - *p = UC_BREAK_POSSIBLE; - /* A combining character turns a preceding space into LBP_ID. */ - last_prop = LBP_ID; - } - else - { - *p = UC_BREAK_PROHIBITED; - /* A combining character turns a preceding space into LBP_ID. */ - if (seen_space != NULL) - { - q = seen_space; - seen_space = seen_space2; - prop = LBP_ID; - goto lookup_via_table; - } - } - } - else - { - lookup_via_table: - /* prop must be usable as an index for table 7.3 of UTR #14. */ - if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) - abort (); + /* Deal with spaces and combining characters. */ + q = p; + if (prop == LBP_SP) + { + /* Don't break just before a space. */ + *p = UC_BREAK_PROHIBITED; + seen_space2 = seen_space; + seen_space = p; + } + else if (prop == LBP_ZW) + { + /* Don't break just before a zero-width space. */ + *p = UC_BREAK_PROHIBITED; + last_prop = LBP_ZW; + seen_space = NULL; + seen_space2 = NULL; + } + else if (prop == LBP_CM) + { + /* Don't break just before a combining character, except immediately after a + zero-width space. */ + if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *p = UC_BREAK_POSSIBLE; + /* A combining character turns a preceding space into LBP_ID. */ + last_prop = LBP_ID; + } + else + { + *p = UC_BREAK_PROHIBITED; + /* A combining character turns a preceding space into LBP_ID. */ + if (seen_space != NULL) + { + q = seen_space; + seen_space = seen_space2; + prop = LBP_ID; + goto lookup_via_table; + } + } + } + else + { + lookup_via_table: + /* prop must be usable as an index for table 7.3 of UTR #14. */ + if (!(prop >= 0 && prop < sizeof (unilbrk_table) / sizeof (unilbrk_table[0]))) + abort (); - if (last_prop == LBP_BK) - { - /* Don't break at the beginning of a line. */ - *q = UC_BREAK_PROHIBITED; - } - else if (last_prop == LBP_ZW) - { - /* Break after zero-width space. */ - *q = UC_BREAK_POSSIBLE; - } - else - { - switch (unilbrk_table [last_prop] [prop]) - { - case D: - *q = UC_BREAK_POSSIBLE; - break; - case I: - *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED); - break; - case P: - *q = UC_BREAK_PROHIBITED; - break; - default: - abort (); - } - } - last_prop = prop; - seen_space = NULL; - seen_space2 = NULL; - } - } + if (last_prop == LBP_BK) + { + /* Don't break at the beginning of a line. */ + *q = UC_BREAK_PROHIBITED; + } + else if (last_prop == LBP_ZW) + { + /* Break after zero-width space. */ + *q = UC_BREAK_POSSIBLE; + } + else + { + switch (unilbrk_table [last_prop] [prop]) + { + case D: + *q = UC_BREAK_POSSIBLE; + break; + case I: + *q = (seen_space != NULL ? UC_BREAK_POSSIBLE : UC_BREAK_PROHIBITED); + break; + case P: + *q = UC_BREAK_PROHIBITED; + break; + default: + abort (); + } + } + last_prop = prop; + seen_space = NULL; + seen_space2 = NULL; + } + } s += count; p += count; @@ -183,28 +183,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -231,24 +231,24 @@ main (int argc, char * argv[]) u8_possible_linebreaks ((uint8_t *) input, length, "UTF-8", breaks); for (i = 0; i < length; i++) - { - switch (breaks[i]) - { - case UC_BREAK_POSSIBLE: - /* U+2027 in UTF-8 encoding */ - putc (0xe2, stdout); putc (0x80, stdout); putc (0xa7, stdout); - break; - case UC_BREAK_MANDATORY: - /* U+21B2 (or U+21B5) in UTF-8 encoding */ - putc (0xe2, stdout); putc (0x86, stdout); putc (0xb2, stdout); - break; - case UC_BREAK_PROHIBITED: - break; - default: - abort (); - } - putc (input[i], stdout); - } + { + switch (breaks[i]) + { + case UC_BREAK_POSSIBLE: + /* U+2027 in UTF-8 encoding */ + putc (0xe2, stdout); putc (0x80, stdout); putc (0xa7, stdout); + break; + case UC_BREAK_MANDATORY: + /* U+21B2 (or U+21B5) in UTF-8 encoding */ + putc (0xe2, stdout); putc (0x86, stdout); putc (0xb2, stdout); + break; + case UC_BREAK_PROHIBITED: + break; + default: + abort (); + } + putc (input[i], stdout); + } free (breaks); diff --git a/lib/unilbrk/u8-width-linebreaks.c b/lib/unilbrk/u8-width-linebreaks.c index 7e7f2e97..fffe62a2 100644 --- a/lib/unilbrk/u8-width-linebreaks.c +++ b/lib/unilbrk/u8-width-linebreaks.c @@ -1,5 +1,5 @@ /* Line breaking of UTF-8 strings. - Copyright (C) 2001-2003, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -25,9 +25,9 @@ int u8_width_linebreaks (const uint8_t *s, size_t n, - int width, int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p) + int width, int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p) { const uint8_t *s_end; char *last_p; @@ -47,53 +47,53 @@ u8_width_linebreaks (const uint8_t *s, size_t n, /* Respect the override. */ if (o != NULL && *o != UC_BREAK_UNDEFINED) - *p = *o; + *p = *o; if (*p == UC_BREAK_POSSIBLE || *p == UC_BREAK_MANDATORY) - { - /* An atomic piece of text ends here. */ - if (last_p != NULL && last_column + piece_width > width) - { - /* Insert a line break. */ - *last_p = UC_BREAK_POSSIBLE; - last_column = 0; - } - } + { + /* An atomic piece of text ends here. */ + if (last_p != NULL && last_column + piece_width > width) + { + /* Insert a line break. */ + *last_p = UC_BREAK_POSSIBLE; + last_column = 0; + } + } if (*p == UC_BREAK_MANDATORY) - { - /* uc is a line break character. */ - /* Start a new piece at column 0. */ - last_p = NULL; - last_column = 0; - piece_width = 0; - } + { + /* uc is a line break character. */ + /* Start a new piece at column 0. */ + last_p = NULL; + last_column = 0; + piece_width = 0; + } else - { - /* uc is not a line break character. */ - int w; - - if (*p == UC_BREAK_POSSIBLE) - { - /* Start a new piece. */ - last_p = p; - last_column += piece_width; - piece_width = 0; - /* No line break for the moment, may be turned into - UC_BREAK_POSSIBLE later, via last_p. */ - } - - *p = UC_BREAK_PROHIBITED; - - w = uc_width (uc, encoding); - if (w >= 0) /* ignore control characters in the string */ - piece_width += w; - } + { + /* uc is not a line break character. */ + int w; + + if (*p == UC_BREAK_POSSIBLE) + { + /* Start a new piece. */ + last_p = p; + last_column += piece_width; + piece_width = 0; + /* No line break for the moment, may be turned into + UC_BREAK_POSSIBLE later, via last_p. */ + } + + *p = UC_BREAK_PROHIBITED; + + w = uc_width (uc, encoding); + if (w >= 0) /* ignore control characters in the string */ + piece_width += w; + } s += count; p += count; if (o != NULL) - o += count; + o += count; } /* The last atomic piece of text ends here. */ @@ -128,28 +128,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -177,21 +177,21 @@ main (int argc, char * argv[]) u8_width_linebreaks ((uint8_t *) input, length, width, 0, 0, NULL, "UTF-8", breaks); for (i = 0; i < length; i++) - { - switch (breaks[i]) - { - case UC_BREAK_POSSIBLE: - putc ('\n', stdout); - break; - case UC_BREAK_MANDATORY: - break; - case UC_BREAK_PROHIBITED: - break; - default: - abort (); - } - putc (input[i], stdout); - } + { + switch (breaks[i]) + { + case UC_BREAK_POSSIBLE: + putc ('\n', stdout); + break; + case UC_BREAK_MANDATORY: + break; + case UC_BREAK_PROHIBITED: + break; + default: + abort (); + } + putc (input[i], stdout); + } free (breaks); diff --git a/lib/unilbrk/ulc-common.c b/lib/unilbrk/ulc-common.c index d035ded7..1ed9c82f 100644 --- a/lib/unilbrk/ulc-common.c +++ b/lib/unilbrk/ulc-common.c @@ -1,5 +1,5 @@ /* Line breaking auxiliary functions. - Copyright (C) 2001-2003, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -43,7 +43,7 @@ is_all_ascii (const char *s, size_t n) unsigned char c = (unsigned char) *s; if (!(c_isprint (c) || c_isspace (c))) - return 0; + return 0; } return 1; } diff --git a/lib/unilbrk/ulc-common.h b/lib/unilbrk/ulc-common.h index 3b481887..bd3c6e44 100644 --- a/lib/unilbrk/ulc-common.h +++ b/lib/unilbrk/ulc-common.h @@ -1,5 +1,5 @@ /* Line breaking auxiliary functions. - Copyright (C) 2001-2003, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unilbrk/ulc-possible-linebreaks.c b/lib/unilbrk/ulc-possible-linebreaks.c index cb952419..eed59b46 100644 --- a/lib/unilbrk/ulc-possible-linebreaks.c +++ b/lib/unilbrk/ulc-possible-linebreaks.c @@ -1,5 +1,5 @@ /* Line breaking of strings. - Copyright (C) 2001-2003, 2006-2009 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -42,76 +42,76 @@ void ulc_possible_linebreaks (const char *s, size_t n, const char *encoding, - char *p) + char *p) { if (n > 0) { if (is_utf8_encoding (encoding)) - u8_possible_linebreaks ((const uint8_t *) s, n, encoding, p); + u8_possible_linebreaks ((const uint8_t *) s, n, encoding, p); else - { - /* Convert the string to UTF-8 and build a translation table - from offsets into s to offsets into the translated string. */ - size_t *offsets = (size_t *) malloc (n * sizeof (size_t)); - - if (offsets != NULL) - { - uint8_t *t; - size_t m; - - t = u8_conv_from_encoding (encoding, iconveh_question_mark, - s, n, offsets, NULL, &m); - if (t != NULL) - { - char *q = (char *) (m > 0 ? malloc (m) : NULL); - - if (m == 0 || q != NULL) - { - size_t i; - - /* Determine the possible line breaks of the UTF-8 - string. */ - u8_possible_linebreaks (t, m, encoding, q); - - /* Translate the result back to the original string. */ - memset (p, UC_BREAK_PROHIBITED, n); - for (i = 0; i < n; i++) - if (offsets[i] != (size_t)(-1)) - p[i] = q[offsets[i]]; - - free (q); - free (t); - free (offsets); - return; - } - free (t); - } - free (offsets); - } - - /* Impossible to convert. */ + { + /* Convert the string to UTF-8 and build a translation table + from offsets into s to offsets into the translated string. */ + size_t *offsets = (size_t *) malloc (n * sizeof (size_t)); + + if (offsets != NULL) + { + uint8_t *t; + size_t m; + + t = u8_conv_from_encoding (encoding, iconveh_question_mark, + s, n, offsets, NULL, &m); + if (t != NULL) + { + char *q = (char *) (m > 0 ? malloc (m) : NULL); + + if (m == 0 || q != NULL) + { + size_t i; + + /* Determine the possible line breaks of the UTF-8 + string. */ + u8_possible_linebreaks (t, m, encoding, q); + + /* Translate the result back to the original string. */ + memset (p, UC_BREAK_PROHIBITED, n); + for (i = 0; i < n; i++) + if (offsets[i] != (size_t)(-1)) + p[i] = q[offsets[i]]; + + free (q); + free (t); + free (offsets); + return; + } + free (t); + } + free (offsets); + } + + /* Impossible to convert. */ #if C_CTYPE_ASCII - if (is_all_ascii (s, n)) - { - /* ASCII is a subset of UTF-8. */ - u8_possible_linebreaks ((const uint8_t *) s, n, encoding, p); - return; - } + if (is_all_ascii (s, n)) + { + /* ASCII is a subset of UTF-8. */ + u8_possible_linebreaks ((const uint8_t *) s, n, encoding, p); + return; + } #endif - /* We have a non-ASCII string and cannot convert it. - Don't produce line breaks except those already present in the - input string. All we assume here is that the encoding is - minimally ASCII compatible. */ - { - const char *s_end = s + n; - while (s < s_end) - { - *p = (*s == '\n' ? UC_BREAK_MANDATORY : UC_BREAK_PROHIBITED); - s++; - p++; - } - } - } + /* We have a non-ASCII string and cannot convert it. + Don't produce line breaks except those already present in the + input string. All we assume here is that the encoding is + minimally ASCII compatible. */ + { + const char *s_end = s + n; + while (s < s_end) + { + *p = (*s == '\n' ? UC_BREAK_MANDATORY : UC_BREAK_PROHIBITED); + s++; + p++; + } + } + } } } @@ -136,28 +136,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -185,21 +185,21 @@ main (int argc, char * argv[]) ulc_possible_linebreaks (input, length, locale_charset (), breaks); for (i = 0; i < length; i++) - { - switch (breaks[i]) - { - case UC_BREAK_POSSIBLE: - putc ('|', stdout); - break; - case UC_BREAK_MANDATORY: - break; - case UC_BREAK_PROHIBITED: - break; - default: - abort (); - } - putc (input[i], stdout); - } + { + switch (breaks[i]) + { + case UC_BREAK_POSSIBLE: + putc ('|', stdout); + break; + case UC_BREAK_MANDATORY: + break; + case UC_BREAK_PROHIBITED: + break; + default: + abort (); + } + putc (input[i], stdout); + } free (breaks); diff --git a/lib/unilbrk/ulc-width-linebreaks.c b/lib/unilbrk/ulc-width-linebreaks.c index 3b091bf2..16b38816 100644 --- a/lib/unilbrk/ulc-width-linebreaks.c +++ b/lib/unilbrk/ulc-width-linebreaks.c @@ -1,5 +1,5 @@ /* Line breaking of strings. - Copyright (C) 2001-2003, 2006-2009 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -42,94 +42,94 @@ int ulc_width_linebreaks (const char *s, size_t n, - int width, int start_column, int at_end_columns, - const char *o, const char *encoding, - char *p) + int width, int start_column, int at_end_columns, + const char *o, const char *encoding, + char *p) { if (n > 0) { if (is_utf8_encoding (encoding)) - return u8_width_linebreaks ((const uint8_t *) s, n, width, start_column, at_end_columns, o, encoding, p); + return u8_width_linebreaks ((const uint8_t *) s, n, width, start_column, at_end_columns, o, encoding, p); else - { - /* Convert the string to UTF-8 and build a translation table - from offsets into s to offsets into the translated string. */ - size_t *offsets = (size_t *) malloc (n * sizeof (size_t)); - - if (offsets != NULL) - { - uint8_t *t; - size_t m; - - t = u8_conv_from_encoding (encoding, iconveh_question_mark, - s, n, offsets, NULL, &m); - if (t != NULL) - { - char *memory = - (char *) (m > 0 ? malloc (m + (o != NULL ? m : 0)) : NULL); - - if (m == 0 || memory != NULL) - { - char *q = (char *) memory; - char *o8 = (o != NULL ? (char *) (q + m) : NULL); - int res_column; - size_t i; - - /* Translate the overrides to the UTF-8 string. */ - if (o != NULL) - { - memset (o8, UC_BREAK_UNDEFINED, m); - for (i = 0; i < n; i++) - if (offsets[i] != (size_t)(-1)) - o8[offsets[i]] = o[i]; - } - - /* Determine the line breaks of the UTF-8 string. */ - res_column = - u8_width_linebreaks (t, m, width, start_column, at_end_columns, o8, encoding, q); - - /* Translate the result back to the original string. */ - memset (p, UC_BREAK_PROHIBITED, n); - for (i = 0; i < n; i++) - if (offsets[i] != (size_t)(-1)) - p[i] = q[offsets[i]]; - - free (memory); - free (t); - free (offsets); - return res_column; - } - free (t); - } - free (offsets); - } - /* Impossible to convert. */ + { + /* Convert the string to UTF-8 and build a translation table + from offsets into s to offsets into the translated string. */ + size_t *offsets = (size_t *) malloc (n * sizeof (size_t)); + + if (offsets != NULL) + { + uint8_t *t; + size_t m; + + t = u8_conv_from_encoding (encoding, iconveh_question_mark, + s, n, offsets, NULL, &m); + if (t != NULL) + { + char *memory = + (char *) (m > 0 ? malloc (m + (o != NULL ? m : 0)) : NULL); + + if (m == 0 || memory != NULL) + { + char *q = (char *) memory; + char *o8 = (o != NULL ? (char *) (q + m) : NULL); + int res_column; + size_t i; + + /* Translate the overrides to the UTF-8 string. */ + if (o != NULL) + { + memset (o8, UC_BREAK_UNDEFINED, m); + for (i = 0; i < n; i++) + if (offsets[i] != (size_t)(-1)) + o8[offsets[i]] = o[i]; + } + + /* Determine the line breaks of the UTF-8 string. */ + res_column = + u8_width_linebreaks (t, m, width, start_column, at_end_columns, o8, encoding, q); + + /* Translate the result back to the original string. */ + memset (p, UC_BREAK_PROHIBITED, n); + for (i = 0; i < n; i++) + if (offsets[i] != (size_t)(-1)) + p[i] = q[offsets[i]]; + + free (memory); + free (t); + free (offsets); + return res_column; + } + free (t); + } + free (offsets); + } + /* Impossible to convert. */ #if C_CTYPE_ASCII - if (is_all_ascii (s, n)) - { - /* ASCII is a subset of UTF-8. */ - return u8_width_linebreaks ((const uint8_t *) s, n, width, start_column, at_end_columns, o, encoding, p); - } + if (is_all_ascii (s, n)) + { + /* ASCII is a subset of UTF-8. */ + return u8_width_linebreaks ((const uint8_t *) s, n, width, start_column, at_end_columns, o, encoding, p); + } #endif - /* We have a non-ASCII string and cannot convert it. - Don't produce line breaks except those already present in the - input string. All we assume here is that the encoding is - minimally ASCII compatible. */ - { - const char *s_end = s + n; - while (s < s_end) - { - *p = ((o != NULL && *o == UC_BREAK_MANDATORY) || *s == '\n' - ? UC_BREAK_MANDATORY - : UC_BREAK_PROHIBITED); - s++; - p++; - if (o != NULL) - o++; - } - /* We cannot compute widths in this case. */ - } - } + /* We have a non-ASCII string and cannot convert it. + Don't produce line breaks except those already present in the + input string. All we assume here is that the encoding is + minimally ASCII compatible. */ + { + const char *s_end = s + n; + while (s < s_end) + { + *p = ((o != NULL && *o == UC_BREAK_MANDATORY) || *s == '\n' + ? UC_BREAK_MANDATORY + : UC_BREAK_PROHIBITED); + s++; + p++; + if (o != NULL) + o++; + } + /* We cannot compute widths in this case. */ + } + } } return start_column; } @@ -154,28 +154,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -204,21 +204,21 @@ main (int argc, char * argv[]) ulc_width_linebreaks (input, length, width, 0, 0, NULL, locale_charset (), breaks); for (i = 0; i < length; i++) - { - switch (breaks[i]) - { - case UC_BREAK_POSSIBLE: - putc ('\n', stdout); - break; - case UC_BREAK_MANDATORY: - break; - case UC_BREAK_PROHIBITED: - break; - default: - abort (); - } - putc (input[i], stdout); - } + { + switch (breaks[i]) + { + case UC_BREAK_POSSIBLE: + putc ('\n', stdout); + break; + case UC_BREAK_MANDATORY: + break; + case UC_BREAK_PROHIBITED: + break; + default: + abort (); + } + putc (input[i], stdout); + } free (breaks); diff --git a/lib/uniname.h b/lib/uniname.h index 7b5a367d..1d0f81c1 100644 --- a/lib/uniname.h +++ b/lib/uniname.h @@ -1,5 +1,6 @@ /* Association between Unicode characters and their names. - Copyright (C) 2000-2002, 2005, 2007 Free Software Foundation, Inc. + Copyright (C) 2000-2002, 2005, 2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniname/uniname.c b/lib/uniname/uniname.c index bef58af3..e4b81cc3 100644 --- a/lib/uniname/uniname.c +++ b/lib/uniname/uniname.c @@ -1,5 +1,5 @@ /* Association between Unicode characters and their names. - Copyright (C) 2000-2002, 2005-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2000-2002, 2005-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -73,16 +73,16 @@ unicode_name_word (unsigned int index, unsigned int *lengthp) { unsigned int i = (i1 + i2) >> 1; if (unicode_name_by_length[i].ind_offset <= index) - i1 = i; + i1 = i; else - i2 = i; + i2 = i; } i = i1; assert (unicode_name_by_length[i].ind_offset <= index - && index < unicode_name_by_length[i+1].ind_offset); + && index < unicode_name_by_length[i+1].ind_offset); *lengthp = i; return &unicode_name_words[unicode_name_by_length[i].extra_offset - + (index-unicode_name_by_length[i].ind_offset)*i]; + + (index-unicode_name_by_length[i].ind_offset)*i]; } /* Looks up the index of a word. */ @@ -97,32 +97,32 @@ unicode_name_word_lookup (const char *word, unsigned int length) unsigned int i1 = i0; unsigned int i2 = unicode_name_by_length[length+1].ind_offset; while (i2 - i1 > 0) - { - unsigned int i = (i1 + i2) >> 1; - const char *p = &unicode_name_words[extra_offset + (i-i0)*length]; - const char *w = word; - unsigned int n = length; - for (;;) - { - if (*p < *w) - { - if (i1 == i) - return -1; - /* Note here: i1 < i < i2. */ - i1 = i; - break; - } - if (*p > *w) - { - /* Note here: i1 <= i < i2. */ - i2 = i; - break; - } - p++; w++; n--; - if (n == 0) - return i; - } - } + { + unsigned int i = (i1 + i2) >> 1; + const char *p = &unicode_name_words[extra_offset + (i-i0)*length]; + const char *w = word; + unsigned int n = length; + for (;;) + { + if (*p < *w) + { + if (i1 == i) + return -1; + /* Note here: i1 < i < i2. */ + i1 = i; + break; + } + if (*p > *w) + { + /* Note here: i1 <= i < i2. */ + i2 = i; + break; + } + p++; w++; n--; + if (n == 0) + return i; + } + } } return -1; } @@ -171,21 +171,21 @@ unicode_character_name (ucs4_t c, char *buf) q = jamo_initial_short_name[index1]; while (*q != '\0') - *ptr++ = *q++; + *ptr++ = *q++; q = jamo_medial_short_name[index2]; while (*q != '\0') - *ptr++ = *q++; + *ptr++ = *q++; q = jamo_final_short_name[index3]; while (*q != '\0') - *ptr++ = *q++; + *ptr++ = *q++; *ptr = '\0'; return buf; } else if ((c >= 0xF900 && c <= 0xFA2D) || (c >= 0xFA30 && c <= 0xFA6A) - || (c >= 0xFA70 && c <= 0xFAD9) || (c >= 0x2F800 && c <= 0x2FA1D)) + || (c >= 0xFA70 && c <= 0xFAD9) || (c >= 0x2F800 && c <= 0x2FA1D)) { /* Special case for CJK compatibility ideographs. Keeps the tables - small. */ + small. */ char *ptr; int i; @@ -194,10 +194,10 @@ unicode_character_name (ucs4_t c, char *buf) ptr = buf + 28; for (i = (c < 0x10000 ? 12 : 16); i >= 0; i -= 4) - { - unsigned int x = (c >> i) & 0xf; - *ptr++ = (x < 10 ? '0' : 'A' - 10) + x; - } + { + unsigned int x = (c >> i) & 0xf; + *ptr++ = (x < 10 ? '0' : 'A' - 10) + x; + } *ptr = '\0'; return buf; } @@ -207,91 +207,91 @@ unicode_character_name (ucs4_t c, char *buf) /* Transform the code so that it fits in 16 bits. */ switch (c >> 12) - { - case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: - break; - case 0x0A: - c -= 0x05000; - break; - case 0x0F: - c -= 0x09000; - break; - case 0x10: - c -= 0x09000; - break; - case 0x12: - c -= 0x0A000; - break; - case 0x1D: - c -= 0x14000; - break; - case 0x1F: - c -= 0x15000; - break; - case 0x2F: - c -= 0x24000; - break; - case 0xE0: - c -= 0xD4000; - break; - default: - return NULL; - } + { + case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: + break; + case 0x0A: + c -= 0x05000; + break; + case 0x0F: + c -= 0x09000; + break; + case 0x10: + c -= 0x09000; + break; + case 0x12: + c -= 0x0A000; + break; + case 0x1D: + c -= 0x14000; + break; + case 0x1F: + c -= 0x15000; + break; + case 0x2F: + c -= 0x24000; + break; + case 0xE0: + c -= 0xD4000; + break; + default: + return NULL; + } { - /* Binary search in unicode_code_to_name. */ - unsigned int i1 = 0; - unsigned int i2 = SIZEOF (unicode_code_to_name); - for (;;) - { - unsigned int i = (i1 + i2) >> 1; - if (unicode_code_to_name[i].code == c) - { - words = &unicode_names[unicode_code_to_name[i].name]; - break; - } - else if (unicode_code_to_name[i].code < c) - { - if (i1 == i) - { - words = NULL; - break; - } - /* Note here: i1 < i < i2. */ - i1 = i; - } - else if (unicode_code_to_name[i].code > c) - { - if (i2 == i) - { - words = NULL; - break; - } - /* Note here: i1 <= i < i2. */ - i2 = i; - } - } + /* Binary search in unicode_code_to_name. */ + unsigned int i1 = 0; + unsigned int i2 = SIZEOF (unicode_code_to_name); + for (;;) + { + unsigned int i = (i1 + i2) >> 1; + if (unicode_code_to_name[i].code == c) + { + words = &unicode_names[unicode_code_to_name[i].name]; + break; + } + else if (unicode_code_to_name[i].code < c) + { + if (i1 == i) + { + words = NULL; + break; + } + /* Note here: i1 < i < i2. */ + i1 = i; + } + else if (unicode_code_to_name[i].code > c) + { + if (i2 == i) + { + words = NULL; + break; + } + /* Note here: i1 <= i < i2. */ + i2 = i; + } + } } if (words != NULL) - { - /* Found it in unicode_code_to_name. Now concatenate the words. */ - /* buf needs to have at least UNICODE_CHARNAME_MAX_LENGTH bytes. */ - char *ptr = buf; - for (;;) - { - unsigned int wordlen; - const char *word = unicode_name_word (*words>>1, &wordlen); - do - *ptr++ = *word++; - while (--wordlen > 0); - if ((*words & 1) == 0) - break; - *ptr++ = ' '; - words++; - } - *ptr = '\0'; - return buf; - } + { + /* Found it in unicode_code_to_name. Now concatenate the words. */ + /* buf needs to have at least UNICODE_CHARNAME_MAX_LENGTH bytes. */ + char *ptr = buf; + for (;;) + { + unsigned int wordlen; + const char *word = unicode_name_word (*words>>1, &wordlen); + do + *ptr++ = *word++; + while (--wordlen > 0); + if ((*words & 1) == 0) + break; + *ptr++ = ' '; + words++; + } + *ptr = '\0'; + return buf; + } return NULL; } } @@ -308,209 +308,209 @@ unicode_name_character (const char *name) char buf[UNICODE_CHARNAME_MAX_LENGTH]; char *ptr = buf; for (;;) - { - char c = *name++; - if (!(c >= ' ' && c <= '~')) - break; - *ptr++ = (c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c); - if (--len == 0) - goto filled_buf; - } + { + char c = *name++; + if (!(c >= ' ' && c <= '~')) + break; + *ptr++ = (c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c); + if (--len == 0) + goto filled_buf; + } if (false) filled_buf: - { - /* Convert the constituents to uint16_t words. */ - uint16_t words[UNICODE_CHARNAME_MAX_WORDS]; - uint16_t *wordptr = words; - { - const char *p1 = buf; - for (;;) - { - { - int word; - const char *p2 = p1; - while (p2 < ptr && *p2 != ' ') - p2++; - word = unicode_name_word_lookup (p1, p2 - p1); - if (word < 0) - break; - if (wordptr == &words[UNICODE_CHARNAME_MAX_WORDS]) - break; - *wordptr++ = word; - if (p2 == ptr) - goto filled_words; - p1 = p2 + 1; - } - /* Special case for Hangul syllables. Keeps the tables small. */ - if (wordptr == &words[2] - && words[0] == UNICODE_CHARNAME_WORD_HANGUL - && words[1] == UNICODE_CHARNAME_WORD_SYLLABLE) - { - /* Split the last word [p1..ptr) into three parts: - 1) [BCDGHJKMNPRST] - 2) [AEIOUWY] - 3) [BCDGHIJKLMNPST] - */ - const char *p2; - const char *p3; - const char *p4; - - p2 = p1; - while (p2 < ptr - && (*p2 == 'B' || *p2 == 'C' || *p2 == 'D' - || *p2 == 'G' || *p2 == 'H' || *p2 == 'J' - || *p2 == 'K' || *p2 == 'M' || *p2 == 'N' - || *p2 == 'P' || *p2 == 'R' || *p2 == 'S' - || *p2 == 'T')) - p2++; - p3 = p2; - while (p3 < ptr - && (*p3 == 'A' || *p3 == 'E' || *p3 == 'I' - || *p3 == 'O' || *p3 == 'U' || *p3 == 'W' - || *p3 == 'Y')) - p3++; - p4 = p3; - while (p4 < ptr - && (*p4 == 'B' || *p4 == 'C' || *p4 == 'D' - || *p4 == 'G' || *p4 == 'H' || *p4 == 'I' - || *p4 == 'J' || *p4 == 'K' || *p4 == 'L' - || *p4 == 'M' || *p4 == 'N' || *p4 == 'P' - || *p4 == 'S' || *p4 == 'T')) - p4++; - if (p4 == ptr) - { - unsigned int n1 = p2 - p1; - unsigned int n2 = p3 - p2; - unsigned int n3 = p4 - p3; - - if (n1 <= 2 && (n2 >= 1 && n2 <= 3) && n3 <= 2) - { - unsigned int index1; - - for (index1 = 0; index1 < 19; index1++) - if (memcmp(jamo_initial_short_name[index1], p1, n1) == 0 - && jamo_initial_short_name[index1][n1] == '\0') - { - unsigned int index2; - - for (index2 = 0; index2 < 21; index2++) - if (memcmp(jamo_medial_short_name[index2], p2, n2) == 0 - && jamo_medial_short_name[index2][n2] == '\0') - { - unsigned int index3; - - for (index3 = 0; index3 < 28; index3++) - if (memcmp(jamo_final_short_name[index3], p3, n3) == 0 - && jamo_final_short_name[index3][n3] == '\0') - { - return 0xAC00 + (index1 * 21 + index2) * 28 + index3; - } - break; - } - break; - } - } - } - } - /* Special case for CJK compatibility ideographs. Keeps the - tables small. */ - if (wordptr == &words[2] - && words[0] == UNICODE_CHARNAME_WORD_CJK - && words[1] == UNICODE_CHARNAME_WORD_COMPATIBILITY - && p1 + 14 <= ptr - && p1 + 15 >= ptr - && memcmp (p1, "IDEOGRAPH-", 10) == 0) - { - const char *p2 = p1 + 10; - - if (*p2 != '0') - { - unsigned int c = 0; - - for (;;) - { - if (*p2 >= '0' && *p2 <= '9') - c += (*p2 - '0'); - else if (*p2 >= 'A' && *p2 <= 'F') - c += (*p2 - 'A' + 10); - else - break; - p2++; - if (p2 == ptr) - { - if ((c >= 0xF900 && c <= 0xFA2D) - || (c >= 0xFA30 && c <= 0xFA6A) - || (c >= 0xFA70 && c <= 0xFAD9) - || (c >= 0x2F800 && c <= 0x2FA1D)) - return c; - else - break; - } - c = c << 4; - } - } - } - } - } - if (false) - filled_words: - { - /* Multiply by 2, to simplify later comparisons. */ - unsigned int words_length = wordptr - words; - { - int i = words_length - 1; - words[i] = 2 * words[i]; - for (; --i >= 0; ) - words[i] = 2 * words[i] + 1; - } - /* Binary search in unicode_name_to_code. */ - { - unsigned int i1 = 0; - unsigned int i2 = SIZEOF (unicode_name_to_code); - for (;;) - { - unsigned int i = (i1 + i2) >> 1; - const uint16_t *w = words; - const uint16_t *p = &unicode_names[unicode_name_to_code[i].name]; - unsigned int n = words_length; - for (;;) - { - if (*p < *w) - { - if (i1 == i) - goto name_not_found; - /* Note here: i1 < i < i2. */ - i1 = i; - break; - } - else if (*p > *w) - { - if (i2 == i) - goto name_not_found; - /* Note here: i1 <= i < i2. */ - i2 = i; - break; - } - p++; w++; n--; - if (n == 0) - { - unsigned int c = unicode_name_to_code[i].code; - - /* Undo the transformation to 16-bit space. */ - static const unsigned int offset[13] = - { - 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, - 0x05000, 0x09000, 0x09000, 0x0A000, 0x14000, - 0x15000, 0x24000, 0xD4000 - }; - return c + offset[c >> 12]; - } - } - } - } - name_not_found: ; - } - } + { + /* Convert the constituents to uint16_t words. */ + uint16_t words[UNICODE_CHARNAME_MAX_WORDS]; + uint16_t *wordptr = words; + { + const char *p1 = buf; + for (;;) + { + { + int word; + const char *p2 = p1; + while (p2 < ptr && *p2 != ' ') + p2++; + word = unicode_name_word_lookup (p1, p2 - p1); + if (word < 0) + break; + if (wordptr == &words[UNICODE_CHARNAME_MAX_WORDS]) + break; + *wordptr++ = word; + if (p2 == ptr) + goto filled_words; + p1 = p2 + 1; + } + /* Special case for Hangul syllables. Keeps the tables small. */ + if (wordptr == &words[2] + && words[0] == UNICODE_CHARNAME_WORD_HANGUL + && words[1] == UNICODE_CHARNAME_WORD_SYLLABLE) + { + /* Split the last word [p1..ptr) into three parts: + 1) [BCDGHJKMNPRST] + 2) [AEIOUWY] + 3) [BCDGHIJKLMNPST] + */ + const char *p2; + const char *p3; + const char *p4; + + p2 = p1; + while (p2 < ptr + && (*p2 == 'B' || *p2 == 'C' || *p2 == 'D' + || *p2 == 'G' || *p2 == 'H' || *p2 == 'J' + || *p2 == 'K' || *p2 == 'M' || *p2 == 'N' + || *p2 == 'P' || *p2 == 'R' || *p2 == 'S' + || *p2 == 'T')) + p2++; + p3 = p2; + while (p3 < ptr + && (*p3 == 'A' || *p3 == 'E' || *p3 == 'I' + || *p3 == 'O' || *p3 == 'U' || *p3 == 'W' + || *p3 == 'Y')) + p3++; + p4 = p3; + while (p4 < ptr + && (*p4 == 'B' || *p4 == 'C' || *p4 == 'D' + || *p4 == 'G' || *p4 == 'H' || *p4 == 'I' + || *p4 == 'J' || *p4 == 'K' || *p4 == 'L' + || *p4 == 'M' || *p4 == 'N' || *p4 == 'P' + || *p4 == 'S' || *p4 == 'T')) + p4++; + if (p4 == ptr) + { + unsigned int n1 = p2 - p1; + unsigned int n2 = p3 - p2; + unsigned int n3 = p4 - p3; + + if (n1 <= 2 && (n2 >= 1 && n2 <= 3) && n3 <= 2) + { + unsigned int index1; + + for (index1 = 0; index1 < 19; index1++) + if (memcmp (jamo_initial_short_name[index1], p1, n1) == 0 + && jamo_initial_short_name[index1][n1] == '\0') + { + unsigned int index2; + + for (index2 = 0; index2 < 21; index2++) + if (memcmp (jamo_medial_short_name[index2], p2, n2) == 0 + && jamo_medial_short_name[index2][n2] == '\0') + { + unsigned int index3; + + for (index3 = 0; index3 < 28; index3++) + if (memcmp (jamo_final_short_name[index3], p3, n3) == 0 + && jamo_final_short_name[index3][n3] == '\0') + { + return 0xAC00 + (index1 * 21 + index2) * 28 + index3; + } + break; + } + break; + } + } + } + } + /* Special case for CJK compatibility ideographs. Keeps the + tables small. */ + if (wordptr == &words[2] + && words[0] == UNICODE_CHARNAME_WORD_CJK + && words[1] == UNICODE_CHARNAME_WORD_COMPATIBILITY + && p1 + 14 <= ptr + && p1 + 15 >= ptr + && memcmp (p1, "IDEOGRAPH-", 10) == 0) + { + const char *p2 = p1 + 10; + + if (*p2 != '0') + { + unsigned int c = 0; + + for (;;) + { + if (*p2 >= '0' && *p2 <= '9') + c += (*p2 - '0'); + else if (*p2 >= 'A' && *p2 <= 'F') + c += (*p2 - 'A' + 10); + else + break; + p2++; + if (p2 == ptr) + { + if ((c >= 0xF900 && c <= 0xFA2D) + || (c >= 0xFA30 && c <= 0xFA6A) + || (c >= 0xFA70 && c <= 0xFAD9) + || (c >= 0x2F800 && c <= 0x2FA1D)) + return c; + else + break; + } + c = c << 4; + } + } + } + } + } + if (false) + filled_words: + { + /* Multiply by 2, to simplify later comparisons. */ + unsigned int words_length = wordptr - words; + { + int i = words_length - 1; + words[i] = 2 * words[i]; + for (; --i >= 0; ) + words[i] = 2 * words[i] + 1; + } + /* Binary search in unicode_name_to_code. */ + { + unsigned int i1 = 0; + unsigned int i2 = SIZEOF (unicode_name_to_code); + for (;;) + { + unsigned int i = (i1 + i2) >> 1; + const uint16_t *w = words; + const uint16_t *p = &unicode_names[unicode_name_to_code[i].name]; + unsigned int n = words_length; + for (;;) + { + if (*p < *w) + { + if (i1 == i) + goto name_not_found; + /* Note here: i1 < i < i2. */ + i1 = i; + break; + } + else if (*p > *w) + { + if (i2 == i) + goto name_not_found; + /* Note here: i1 <= i < i2. */ + i2 = i; + break; + } + p++; w++; n--; + if (n == 0) + { + unsigned int c = unicode_name_to_code[i].code; + + /* Undo the transformation to 16-bit space. */ + static const unsigned int offset[13] = + { + 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, + 0x05000, 0x09000, 0x09000, 0x0A000, 0x14000, + 0x15000, 0x24000, 0xD4000 + }; + return c + offset[c >> 12]; + } + } + } + } + name_not_found: ; + } + } } return UNINAME_INVALID; } diff --git a/lib/uninorm.h b/lib/uninorm.h index 6850967e..5fdcc22a 100644 --- a/lib/uninorm.h +++ b/lib/uninorm.h @@ -1,5 +1,5 @@ /* Normalization forms (composition and decomposition) of Unicode strings. - Copyright (C) 2001-2002, 2009 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -143,13 +143,13 @@ extern uninorm_t uninorm_decomposing_form (uninorm_t nf); /* Return the specified normalization form of a string. */ extern uint8_t * u8_normalize (uninorm_t nf, const uint8_t *s, size_t n, - uint8_t *resultbuf, size_t *lengthp); + uint8_t *resultbuf, size_t *lengthp); extern uint16_t * u16_normalize (uninorm_t nf, const uint16_t *s, size_t n, - uint16_t *resultbuf, size_t *lengthp); + uint16_t *resultbuf, size_t *lengthp); extern uint32_t * u32_normalize (uninorm_t nf, const uint32_t *s, size_t n, - uint32_t *resultbuf, size_t *lengthp); + uint32_t *resultbuf, size_t *lengthp); /* Compare S1 and S2, ignoring differences in normalization. @@ -158,13 +158,13 @@ extern uint32_t * return 0. Upon failure, return -1 with errno set. */ extern int u8_normcmp (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2, - uninorm_t nf, int *resultp); + uninorm_t nf, int *resultp); extern int u16_normcmp (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2, - uninorm_t nf, int *resultp); + uninorm_t nf, int *resultp); extern int u32_normcmp (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2, - uninorm_t nf, int *resultp); + uninorm_t nf, int *resultp); /* Converts the string S of length N to a NUL-terminated byte sequence, in such @@ -173,13 +173,13 @@ extern int NF must be either UNINORM_NFC or UNINORM_NFKC. */ extern char * u8_normxfrm (const uint8_t *s, size_t n, uninorm_t nf, - char *resultbuf, size_t *lengthp); + char *resultbuf, size_t *lengthp); extern char * u16_normxfrm (const uint16_t *s, size_t n, uninorm_t nf, - char *resultbuf, size_t *lengthp); + char *resultbuf, size_t *lengthp); extern char * u32_normxfrm (const uint32_t *s, size_t n, uninorm_t nf, - char *resultbuf, size_t *lengthp); + char *resultbuf, size_t *lengthp); /* Compare S1 and S2, ignoring differences in normalization, using the @@ -189,13 +189,13 @@ extern char * return 0. Upon failure, return -1 with errno set. */ extern int u8_normcoll (const uint8_t *s1, size_t n1, const uint8_t *s2, size_t n2, - uninorm_t nf, int *resultp); + uninorm_t nf, int *resultp); extern int u16_normcoll (const uint16_t *s1, size_t n1, const uint16_t *s2, size_t n2, - uninorm_t nf, int *resultp); + uninorm_t nf, int *resultp); extern int u32_normcoll (const uint32_t *s1, size_t n1, const uint32_t *s2, size_t n2, - uninorm_t nf, int *resultp); + uninorm_t nf, int *resultp); /* Normalization of a stream of Unicode characters. @@ -216,8 +216,8 @@ struct uninorm_filter; Return the new filter, or NULL with errno set upon failure. */ extern struct uninorm_filter * uninorm_filter_create (uninorm_t nf, - int (*stream_func) (void *stream_data, ucs4_t uc), - void *stream_data); + int (*stream_func) (void *stream_data, ucs4_t uc), + void *stream_data); /* Stuff a Unicode character into a normalizing filter. Return 0 if successful, or -1 with errno set upon failure. */ diff --git a/lib/uninorm/canonical-decomposition.c b/lib/uninorm/canonical-decomposition.c index 210b74b9..e6e39e0b 100644 --- a/lib/uninorm/canonical-decomposition.c +++ b/lib/uninorm/canonical-decomposition.c @@ -1,5 +1,5 @@ /* Canonical decomposition of Unicode characters. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -31,77 +31,77 @@ uc_canonical_decomposition (ucs4_t uc, ucs4_t *decomposition) { /* Hangul syllable. See Unicode standard, chapter 3, section "Hangul Syllable Decomposition", See also the clarification at - , section - "Clarification of Hangul Jamo Handling". */ + , section + "Clarification of Hangul Jamo Handling". */ unsigned int t; uc -= 0xAC00; t = uc % 28; if (t == 0) - { - unsigned int v, l; + { + unsigned int v, l; - uc = uc / 28; - v = uc % 21; - l = uc / 21; + uc = uc / 28; + v = uc % 21; + l = uc / 21; - decomposition[0] = 0x1100 + l; - decomposition[1] = 0x1161 + v; - return 2; - } + decomposition[0] = 0x1100 + l; + decomposition[1] = 0x1161 + v; + return 2; + } else - { + { #if 1 /* Return the pairwise decomposition, not the full decomposition. */ - decomposition[0] = 0xAC00 + uc - t; /* = 0xAC00 + (l * 21 + v) * 28; */ - decomposition[1] = 0x11A7 + t; - return 2; + decomposition[0] = 0xAC00 + uc - t; /* = 0xAC00 + (l * 21 + v) * 28; */ + decomposition[1] = 0x11A7 + t; + return 2; #else - unsigned int v, l; + unsigned int v, l; - uc = uc / 28; - v = uc % 21; - l = uc / 21; + uc = uc / 28; + v = uc % 21; + l = uc / 21; - decomposition[0] = 0x1100 + l; - decomposition[1] = 0x1161 + v; - decomposition[2] = 0x11A7 + t; - return 3; + decomposition[0] = 0x1100 + l; + decomposition[1] = 0x1161 + v; + decomposition[2] = 0x11A7 + t; + return 3; #endif - } + } } else if (uc < 0x110000) { unsigned short entry = decomp_index (uc); /* An entry of (unsigned short)(-1) denotes an absent entry. - Otherwise, bit 15 of the entry tells whether the decomposition - is a canonical one. */ + Otherwise, bit 15 of the entry tells whether the decomposition + is a canonical one. */ if (entry < 0x8000) - { - const unsigned char *p; - unsigned int element; - unsigned int length; - - p = &gl_uninorm_decomp_chars_table[3 * entry]; - element = (p[0] << 16) | (p[1] << 8) | p[2]; - /* The first element has 5 bits for the decomposition type. */ - if (((element >> 18) & 0x1f) != UC_DECOMP_CANONICAL) - abort (); - length = 1; - for (;;) - { - /* Every element has an 18 bits wide Unicode code point. */ - *decomposition = element & 0x3ffff; - /* Bit 23 tells whether there are more elements, */ - if ((element & (1 << 23)) == 0) - break; - p += 3; - element = (p[0] << 16) | (p[1] << 8) | p[2]; - decomposition++; - length++; - } - return length; - } + { + const unsigned char *p; + unsigned int element; + unsigned int length; + + p = &gl_uninorm_decomp_chars_table[3 * entry]; + element = (p[0] << 16) | (p[1] << 8) | p[2]; + /* The first element has 5 bits for the decomposition type. */ + if (((element >> 18) & 0x1f) != UC_DECOMP_CANONICAL) + abort (); + length = 1; + for (;;) + { + /* Every element has an 18 bits wide Unicode code point. */ + *decomposition = element & 0x3ffff; + /* Bit 23 tells whether there are more elements, */ + if ((element & (1 << 23)) == 0) + break; + p += 3; + element = (p[0] << 16) | (p[1] << 8) | p[2]; + decomposition++; + length++; + } + return length; + } } return -1; } diff --git a/lib/uninorm/compat-decomposition.c b/lib/uninorm/compat-decomposition.c index 19ec87e3..740cc5c7 100644 --- a/lib/uninorm/compat-decomposition.c +++ b/lib/uninorm/compat-decomposition.c @@ -1,5 +1,5 @@ /* Compatibility decomposition of Unicode characters. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/composition-table.gperf b/lib/uninorm/composition-table.gperf index f7f0febc..4651725c 100644 --- a/lib/uninorm/composition-table.gperf +++ b/lib/uninorm/composition-table.gperf @@ -2,7 +2,7 @@ /* Canonical composition of Unicode characters. */ /* Generated automatically by gen-uni-tables for Unicode 5.1.0. */ -/* Copyright (C) 2009 Free Software Foundation, Inc. +/* Copyright (C) 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/uninorm/composition.c b/lib/uninorm/composition.c index 4caf9a06..c9cddbec 100644 --- a/lib/uninorm/composition.c +++ b/lib/uninorm/composition.c @@ -1,5 +1,5 @@ /* Canonical composition of Unicode characters. - Copyright (C) 2002, 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -32,54 +32,54 @@ uc_composition (ucs4_t uc1, ucs4_t uc2) if (uc1 < 0x10000 && uc2 < 0x10000) { if (uc2 >= 0x1161 && uc2 < 0x1161 + 21 - && uc1 >= 0x1100 && uc1 < 0x1100 + 19) - { - /* Hangul: Combine single letter L and single letter V to form - two-letter syllable LV. */ - return 0xAC00 + ((uc1 - 0x1100) * 21 + (uc2 - 0x1161)) * 28; - } + && uc1 >= 0x1100 && uc1 < 0x1100 + 19) + { + /* Hangul: Combine single letter L and single letter V to form + two-letter syllable LV. */ + return 0xAC00 + ((uc1 - 0x1100) * 21 + (uc2 - 0x1161)) * 28; + } else if (uc2 > 0x11A7 && uc2 < 0x11A7 + 28 - && uc1 >= 0xAC00 && uc1 < 0xD7A4 && ((uc1 - 0xAC00) % 28) == 0) - { - /* Hangul: Combine two-letter syllable LV with single-letter T - to form three-letter syllable LVT. */ - return uc1 + (uc2 - 0x11A7); - } + && uc1 >= 0xAC00 && uc1 < 0xD7A4 && ((uc1 - 0xAC00) % 28) == 0) + { + /* Hangul: Combine two-letter syllable LV with single-letter T + to form three-letter syllable LVT. */ + return uc1 + (uc2 - 0x11A7); + } else - { + { #if 0 - unsigned int uc = MUL1 * uc1 * MUL2 * uc2; - unsigned int index1 = uc >> composition_header_0; - if (index1 < composition_header_1) - { - int lookup1 = u_composition.level1[index1]; - if (lookup1 >= 0) - { - unsigned int index2 = (uc >> composition_header_2) & composition_header_3; - int lookup2 = u_composition.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = (uc & composition_header_4); - unsigned int lookup3 = u_composition.level3[lookup2 + index3]; - if ((lookup3 >> 16) == uc2) - return lookup3 & ((1U << 16) - 1); - } - } - } + unsigned int uc = MUL1 * uc1 * MUL2 * uc2; + unsigned int index1 = uc >> composition_header_0; + if (index1 < composition_header_1) + { + int lookup1 = u_composition.level1[index1]; + if (lookup1 >= 0) + { + unsigned int index2 = (uc >> composition_header_2) & composition_header_3; + int lookup2 = u_composition.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = (uc & composition_header_4); + unsigned int lookup3 = u_composition.level3[lookup2 + index3]; + if ((lookup3 >> 16) == uc2) + return lookup3 & ((1U << 16) - 1); + } + } + } #else - char codes[4]; - const struct composition_rule *rule; + char codes[4]; + const struct composition_rule *rule; - codes[0] = (uc1 >> 8) & 0xff; - codes[1] = uc1 & 0xff; - codes[2] = (uc2 >> 8) & 0xff; - codes[3] = uc2 & 0xff; + codes[0] = (uc1 >> 8) & 0xff; + codes[1] = uc1 & 0xff; + codes[2] = (uc2 >> 8) & 0xff; + codes[3] = uc2 & 0xff; - rule = gl_uninorm_compose_lookup (codes, 4); - if (rule != NULL) - return rule->combined; + rule = gl_uninorm_compose_lookup (codes, 4); + if (rule != NULL) + return rule->combined; #endif - } + } } return 0; } diff --git a/lib/uninorm/decompose-internal.c b/lib/uninorm/decompose-internal.c index 53b745da..f9c2277c 100644 --- a/lib/uninorm/decompose-internal.c +++ b/lib/uninorm/decompose-internal.c @@ -1,5 +1,5 @@ /* Decomposition of Unicode strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/decompose-internal.h b/lib/uninorm/decompose-internal.h index c1bf1258..d952e2fd 100644 --- a/lib/uninorm/decompose-internal.h +++ b/lib/uninorm/decompose-internal.h @@ -1,5 +1,5 @@ /* Decomposition of Unicode strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -27,10 +27,10 @@ extern int struct ucs4_with_ccc { ucs4_t code; - int ccc; /* range 0..255 */ + int ccc; /* range 0..255 */ }; /* Stable-sort an array of 'struct ucs4_with_ccc'. */ extern void gl_uninorm_decompose_merge_sort_inplace (struct ucs4_with_ccc *src, size_t n, - struct ucs4_with_ccc *tmp); + struct ucs4_with_ccc *tmp); diff --git a/lib/uninorm/decomposing-form.c b/lib/uninorm/decomposing-form.c index 3b49cb8b..a19f6d3f 100644 --- a/lib/uninorm/decomposing-form.c +++ b/lib/uninorm/decomposing-form.c @@ -1,5 +1,5 @@ /* Decomposing variant of a normalization form. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/decomposition-table.c b/lib/uninorm/decomposition-table.c index 63f64427..b19b47a0 100644 --- a/lib/uninorm/decomposition-table.c +++ b/lib/uninorm/decomposition-table.c @@ -1,5 +1,5 @@ /* Decomposition of Unicode characters. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/decomposition-table.h b/lib/uninorm/decomposition-table.h index ad0e1a3f..9238ff95 100644 --- a/lib/uninorm/decomposition-table.h +++ b/lib/uninorm/decomposition-table.h @@ -1,5 +1,5 @@ /* Decomposition of Unicode characters. - Copyright (C) 2001-2003, 2009 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -34,15 +34,15 @@ decomp_index (ucs4_t uc) { int lookup1 = gl_uninorm_decomp_index_table.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> decomp_header_2) & decomp_header_3; - int lookup2 = gl_uninorm_decomp_index_table.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = uc & decomp_header_4; - return gl_uninorm_decomp_index_table.level3[lookup2 + index3]; - } - } + { + unsigned int index2 = (uc >> decomp_header_2) & decomp_header_3; + int lookup2 = gl_uninorm_decomp_index_table.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = uc & decomp_header_4; + return gl_uninorm_decomp_index_table.level3[lookup2 + index3]; + } + } } return (unsigned short)(-1); } diff --git a/lib/uninorm/decomposition.c b/lib/uninorm/decomposition.c index af030182..a29e105c 100644 --- a/lib/uninorm/decomposition.c +++ b/lib/uninorm/decomposition.c @@ -1,5 +1,5 @@ /* Decomposition of Unicode characters. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -29,8 +29,8 @@ uc_decomposition (ucs4_t uc, int *decomp_tag, ucs4_t *decomposition) { /* Hangul syllable. See Unicode standard, chapter 3, section "Hangul Syllable Decomposition", See also the clarification at - , section - "Clarification of Hangul Jamo Handling". */ + , section + "Clarification of Hangul Jamo Handling". */ unsigned int t; uc -= 0xAC00; @@ -38,65 +38,65 @@ uc_decomposition (ucs4_t uc, int *decomp_tag, ucs4_t *decomposition) *decomp_tag = UC_DECOMP_CANONICAL; if (t == 0) - { - unsigned int v, l; + { + unsigned int v, l; - uc = uc / 28; - v = uc % 21; - l = uc / 21; + uc = uc / 28; + v = uc % 21; + l = uc / 21; - decomposition[0] = 0x1100 + l; - decomposition[1] = 0x1161 + v; - return 2; - } + decomposition[0] = 0x1100 + l; + decomposition[1] = 0x1161 + v; + return 2; + } else - { + { #if 1 /* Return the pairwise decomposition, not the full decomposition. */ - decomposition[0] = 0xAC00 + uc - t; /* = 0xAC00 + (l * 21 + v) * 28; */ - decomposition[1] = 0x11A7 + t; - return 2; + decomposition[0] = 0xAC00 + uc - t; /* = 0xAC00 + (l * 21 + v) * 28; */ + decomposition[1] = 0x11A7 + t; + return 2; #else - unsigned int v, l; + unsigned int v, l; - uc = uc / 28; - v = uc % 21; - l = uc / 21; + uc = uc / 28; + v = uc % 21; + l = uc / 21; - decomposition[0] = 0x1100 + l; - decomposition[1] = 0x1161 + v; - decomposition[2] = 0x11A7 + t; - return 3; + decomposition[0] = 0x1100 + l; + decomposition[1] = 0x1161 + v; + decomposition[2] = 0x11A7 + t; + return 3; #endif - } + } } else if (uc < 0x110000) { unsigned short entry = decomp_index (uc); if (entry != (unsigned short)(-1)) - { - const unsigned char *p; - unsigned int element; - unsigned int length; + { + const unsigned char *p; + unsigned int element; + unsigned int length; - p = &gl_uninorm_decomp_chars_table[3 * (entry & 0x7FFF)]; - element = (p[0] << 16) | (p[1] << 8) | p[2]; - /* The first element has 5 bits for the decomposition type. */ - *decomp_tag = (element >> 18) & 0x1f; - length = 1; - for (;;) - { - /* Every element has an 18 bits wide Unicode code point. */ - *decomposition = element & 0x3ffff; - /* Bit 23 tells whether there are more elements, */ - if ((element & (1 << 23)) == 0) - break; - p += 3; - element = (p[0] << 16) | (p[1] << 8) | p[2]; - decomposition++; - length++; - } - return length; - } + p = &gl_uninorm_decomp_chars_table[3 * (entry & 0x7FFF)]; + element = (p[0] << 16) | (p[1] << 8) | p[2]; + /* The first element has 5 bits for the decomposition type. */ + *decomp_tag = (element >> 18) & 0x1f; + length = 1; + for (;;) + { + /* Every element has an 18 bits wide Unicode code point. */ + *decomposition = element & 0x3ffff; + /* Bit 23 tells whether there are more elements, */ + if ((element & (1 << 23)) == 0) + break; + p += 3; + element = (p[0] << 16) | (p[1] << 8) | p[2]; + decomposition++; + length++; + } + return length; + } } return -1; } diff --git a/lib/uninorm/nfc.c b/lib/uninorm/nfc.c index c205b166..ecc1aba6 100644 --- a/lib/uninorm/nfc.c +++ b/lib/uninorm/nfc.c @@ -1,5 +1,5 @@ /* Unicode Normalization Form C. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/nfd.c b/lib/uninorm/nfd.c index 54c98bc2..1e7194d0 100644 --- a/lib/uninorm/nfd.c +++ b/lib/uninorm/nfd.c @@ -1,5 +1,5 @@ /* Unicode Normalization Form D. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/nfkc.c b/lib/uninorm/nfkc.c index 1fb52f13..fdd05ac6 100644 --- a/lib/uninorm/nfkc.c +++ b/lib/uninorm/nfkc.c @@ -1,5 +1,5 @@ /* Unicode Normalization Form KC. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/nfkd.c b/lib/uninorm/nfkd.c index 871dd647..cff0df2e 100644 --- a/lib/uninorm/nfkd.c +++ b/lib/uninorm/nfkd.c @@ -1,5 +1,5 @@ /* Unicode Normalization Form KD. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/normalize-internal.h b/lib/uninorm/normalize-internal.h index 0b346c65..f4c8c8e3 100644 --- a/lib/uninorm/normalize-internal.h +++ b/lib/uninorm/normalize-internal.h @@ -1,5 +1,5 @@ /* Normalization of Unicode strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/u-normalize-internal.h b/lib/uninorm/u-normalize-internal.h index 70c32551..43b7ec32 100644 --- a/lib/uninorm/u-normalize-internal.h +++ b/lib/uninorm/u-normalize-internal.h @@ -1,5 +1,5 @@ /* Decomposition and composition of Unicode strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -56,293 +56,293 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n, for (;;) { - int count; - ucs4_t decomposed[UC_DECOMPOSITION_MAX_LENGTH]; - int decomposed_count; - int i; - - if (s < s_end) - { - /* Fetch the next character. */ - count = U_MBTOUC_UNSAFE (&decomposed[0], s, s_end - s); - decomposed_count = 1; - - /* Decompose it, recursively. - It would be possible to precompute the recursive decomposition - and store it in a table. But this would significantly increase - the size of the decomposition tables, because for example for - U+1FC1 the recursive canonical decomposition and the recursive - compatibility decomposition are different. */ - { - int curr; - - for (curr = 0; curr < decomposed_count; ) - { - /* Invariant: decomposed[0..curr-1] is fully decomposed, i.e. - all elements are atomic. */ - ucs4_t curr_decomposed[UC_DECOMPOSITION_MAX_LENGTH]; - int curr_decomposed_count; - - curr_decomposed_count = decomposer (decomposed[curr], curr_decomposed); - if (curr_decomposed_count >= 0) - { - /* Move curr_decomposed[0..curr_decomposed_count-1] over - decomposed[curr], making room. It's not worth using - memcpy() here, since the counts are so small. */ - int shift = curr_decomposed_count - 1; - - if (shift < 0) - abort (); - if (shift > 0) - { - int j; - - decomposed_count += shift; - if (decomposed_count > UC_DECOMPOSITION_MAX_LENGTH) - abort (); - for (j = decomposed_count - 1 - shift; j > curr; j--) - decomposed[j + shift] = decomposed[j]; - } - for (; shift >= 0; shift--) - decomposed[curr + shift] = curr_decomposed[shift]; - } - else - { - /* decomposed[curr] is atomic. */ - curr++; - } - } - } - } - else - { - count = 0; - decomposed_count = 0; - } - - i = 0; - for (;;) - { - ucs4_t uc; - int ccc; - - if (s < s_end) - { - /* Fetch the next character from the decomposition. */ - if (i == decomposed_count) - break; - uc = decomposed[i]; - ccc = uc_combining_class (uc); - } - else - { - /* End of string reached. */ - uc = 0; - ccc = 0; - } - - if (ccc == 0) - { - size_t j; - - /* Apply the canonical ordering algorithm to the accumulated - sequence of characters. */ - if (sortbuf_count > 1) - gl_uninorm_decompose_merge_sort_inplace (sortbuf, sortbuf_count, - sortbuf + sortbuf_count); - - if (composer != NULL) - { - /* Attempt to combine decomposed characters, as specified - in the Unicode Standard Annex #15 "Unicode Normalization - Forms". We need to check - 1. whether the first accumulated character is a - "starter" (i.e. has ccc = 0). This is usually the - case. But when the string starts with a - non-starter, the sortbuf also starts with a - non-starter. Btw, this check could also be - omitted, because the composition table has only - entries (code1, code2) for which code1 is a - starter; if the first accumulated character is not - a starter, no lookup will succeed. - 2. If the sortbuf has more than one character, check - for each of these characters that are not "blocked" - from the starter (i.e. have a ccc that is higher - than the ccc of the previous character) whether it - can be combined with the first character. - 3. If only one character is left in sortbuf, check - whether it can be combined with the next character - (also a starter). */ - if (sortbuf_count > 0 && sortbuf[0].ccc == 0) - { - for (j = 1; j < sortbuf_count; ) - { - if (sortbuf[j].ccc > sortbuf[j - 1].ccc) - { - ucs4_t combined = - composer (sortbuf[0].code, sortbuf[j].code); - if (combined) - { - size_t k; - - sortbuf[0].code = combined; - /* sortbuf[0].ccc = 0, still valid. */ - for (k = j + 1; k < sortbuf_count; k++) - sortbuf[k - 1] = sortbuf[k]; - sortbuf_count--; - continue; - } - } - j++; - } - if (s < s_end && sortbuf_count == 1) - { - ucs4_t combined = - composer (sortbuf[0].code, uc); - if (combined) - { - uc = combined; - ccc = 0; - /* uc could be further combined with subsequent - characters. So don't put it into sortbuf[0] in - this round, only in the next round. */ - sortbuf_count = 0; - } - } - } - } - - for (j = 0; j < sortbuf_count; j++) - { - ucs4_t muc = sortbuf[j].code; - - /* Append muc to the result accumulator. */ - if (length < allocated) - { - int ret = - U_UCTOMB (result + length, muc, allocated - length); - if (ret == -1) - { - errno = EINVAL; - goto fail; - } - if (ret >= 0) - { - length += ret; - goto done_appending; - } - } - { - size_t old_allocated = allocated; - size_t new_allocated = 2 * old_allocated; - if (new_allocated < 64) - new_allocated = 64; - if (new_allocated < old_allocated) /* integer overflow? */ - abort (); - { - UNIT *larger_result; - if (result == NULL) - { - larger_result = - (UNIT *) malloc (new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail; - } - } - else if (result == resultbuf) - { - larger_result = - (UNIT *) malloc (new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail; - } - U_CPY (larger_result, resultbuf, length); - } - else - { - larger_result = - (UNIT *) realloc (result, new_allocated * sizeof (UNIT)); - if (larger_result == NULL) - { - errno = ENOMEM; - goto fail; - } - } - result = larger_result; - allocated = new_allocated; - { - int ret = - U_UCTOMB (result + length, muc, allocated - length); - if (ret == -1) - { - errno = EINVAL; - goto fail; - } - if (ret < 0) - abort (); - length += ret; - goto done_appending; - } - } - } - done_appending: ; - } - - /* sortbuf is now empty. */ - sortbuf_count = 0; - } - - if (!(s < s_end)) - /* End of string reached. */ - break; - - /* Append (uc, ccc) to sortbuf. */ - if (sortbuf_count == sortbuf_allocated) - { - struct ucs4_with_ccc *new_sortbuf; - - sortbuf_allocated = 2 * sortbuf_allocated; - if (sortbuf_allocated < sortbuf_count) /* integer overflow? */ - abort (); - new_sortbuf = - (struct ucs4_with_ccc *) malloc (2 * sortbuf_allocated * sizeof (struct ucs4_with_ccc)); - memcpy (new_sortbuf, sortbuf, - sortbuf_count * sizeof (struct ucs4_with_ccc)); - if (sortbuf != sortbuf_preallocated) - free (sortbuf); - sortbuf = new_sortbuf; - } - sortbuf[sortbuf_count].code = uc; - sortbuf[sortbuf_count].ccc = ccc; - sortbuf_count++; - - i++; - } - - if (!(s < s_end)) - /* End of string reached. */ - break; - - s += count; + int count; + ucs4_t decomposed[UC_DECOMPOSITION_MAX_LENGTH]; + int decomposed_count; + int i; + + if (s < s_end) + { + /* Fetch the next character. */ + count = U_MBTOUC_UNSAFE (&decomposed[0], s, s_end - s); + decomposed_count = 1; + + /* Decompose it, recursively. + It would be possible to precompute the recursive decomposition + and store it in a table. But this would significantly increase + the size of the decomposition tables, because for example for + U+1FC1 the recursive canonical decomposition and the recursive + compatibility decomposition are different. */ + { + int curr; + + for (curr = 0; curr < decomposed_count; ) + { + /* Invariant: decomposed[0..curr-1] is fully decomposed, i.e. + all elements are atomic. */ + ucs4_t curr_decomposed[UC_DECOMPOSITION_MAX_LENGTH]; + int curr_decomposed_count; + + curr_decomposed_count = decomposer (decomposed[curr], curr_decomposed); + if (curr_decomposed_count >= 0) + { + /* Move curr_decomposed[0..curr_decomposed_count-1] over + decomposed[curr], making room. It's not worth using + memcpy() here, since the counts are so small. */ + int shift = curr_decomposed_count - 1; + + if (shift < 0) + abort (); + if (shift > 0) + { + int j; + + decomposed_count += shift; + if (decomposed_count > UC_DECOMPOSITION_MAX_LENGTH) + abort (); + for (j = decomposed_count - 1 - shift; j > curr; j--) + decomposed[j + shift] = decomposed[j]; + } + for (; shift >= 0; shift--) + decomposed[curr + shift] = curr_decomposed[shift]; + } + else + { + /* decomposed[curr] is atomic. */ + curr++; + } + } + } + } + else + { + count = 0; + decomposed_count = 0; + } + + i = 0; + for (;;) + { + ucs4_t uc; + int ccc; + + if (s < s_end) + { + /* Fetch the next character from the decomposition. */ + if (i == decomposed_count) + break; + uc = decomposed[i]; + ccc = uc_combining_class (uc); + } + else + { + /* End of string reached. */ + uc = 0; + ccc = 0; + } + + if (ccc == 0) + { + size_t j; + + /* Apply the canonical ordering algorithm to the accumulated + sequence of characters. */ + if (sortbuf_count > 1) + gl_uninorm_decompose_merge_sort_inplace (sortbuf, sortbuf_count, + sortbuf + sortbuf_count); + + if (composer != NULL) + { + /* Attempt to combine decomposed characters, as specified + in the Unicode Standard Annex #15 "Unicode Normalization + Forms". We need to check + 1. whether the first accumulated character is a + "starter" (i.e. has ccc = 0). This is usually the + case. But when the string starts with a + non-starter, the sortbuf also starts with a + non-starter. Btw, this check could also be + omitted, because the composition table has only + entries (code1, code2) for which code1 is a + starter; if the first accumulated character is not + a starter, no lookup will succeed. + 2. If the sortbuf has more than one character, check + for each of these characters that are not "blocked" + from the starter (i.e. have a ccc that is higher + than the ccc of the previous character) whether it + can be combined with the first character. + 3. If only one character is left in sortbuf, check + whether it can be combined with the next character + (also a starter). */ + if (sortbuf_count > 0 && sortbuf[0].ccc == 0) + { + for (j = 1; j < sortbuf_count; ) + { + if (sortbuf[j].ccc > sortbuf[j - 1].ccc) + { + ucs4_t combined = + composer (sortbuf[0].code, sortbuf[j].code); + if (combined) + { + size_t k; + + sortbuf[0].code = combined; + /* sortbuf[0].ccc = 0, still valid. */ + for (k = j + 1; k < sortbuf_count; k++) + sortbuf[k - 1] = sortbuf[k]; + sortbuf_count--; + continue; + } + } + j++; + } + if (s < s_end && sortbuf_count == 1) + { + ucs4_t combined = + composer (sortbuf[0].code, uc); + if (combined) + { + uc = combined; + ccc = 0; + /* uc could be further combined with subsequent + characters. So don't put it into sortbuf[0] in + this round, only in the next round. */ + sortbuf_count = 0; + } + } + } + } + + for (j = 0; j < sortbuf_count; j++) + { + ucs4_t muc = sortbuf[j].code; + + /* Append muc to the result accumulator. */ + if (length < allocated) + { + int ret = + U_UCTOMB (result + length, muc, allocated - length); + if (ret == -1) + { + errno = EINVAL; + goto fail; + } + if (ret >= 0) + { + length += ret; + goto done_appending; + } + } + { + size_t old_allocated = allocated; + size_t new_allocated = 2 * old_allocated; + if (new_allocated < 64) + new_allocated = 64; + if (new_allocated < old_allocated) /* integer overflow? */ + abort (); + { + UNIT *larger_result; + if (result == NULL) + { + larger_result = + (UNIT *) malloc (new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail; + } + } + else if (result == resultbuf) + { + larger_result = + (UNIT *) malloc (new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail; + } + U_CPY (larger_result, resultbuf, length); + } + else + { + larger_result = + (UNIT *) realloc (result, new_allocated * sizeof (UNIT)); + if (larger_result == NULL) + { + errno = ENOMEM; + goto fail; + } + } + result = larger_result; + allocated = new_allocated; + { + int ret = + U_UCTOMB (result + length, muc, allocated - length); + if (ret == -1) + { + errno = EINVAL; + goto fail; + } + if (ret < 0) + abort (); + length += ret; + goto done_appending; + } + } + } + done_appending: ; + } + + /* sortbuf is now empty. */ + sortbuf_count = 0; + } + + if (!(s < s_end)) + /* End of string reached. */ + break; + + /* Append (uc, ccc) to sortbuf. */ + if (sortbuf_count == sortbuf_allocated) + { + struct ucs4_with_ccc *new_sortbuf; + + sortbuf_allocated = 2 * sortbuf_allocated; + if (sortbuf_allocated < sortbuf_count) /* integer overflow? */ + abort (); + new_sortbuf = + (struct ucs4_with_ccc *) malloc (2 * sortbuf_allocated * sizeof (struct ucs4_with_ccc)); + memcpy (new_sortbuf, sortbuf, + sortbuf_count * sizeof (struct ucs4_with_ccc)); + if (sortbuf != sortbuf_preallocated) + free (sortbuf); + sortbuf = new_sortbuf; + } + sortbuf[sortbuf_count].code = uc; + sortbuf[sortbuf_count].ccc = ccc; + sortbuf_count++; + + i++; + } + + if (!(s < s_end)) + /* End of string reached. */ + break; + + s += count; } } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - goto fail; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + goto fail; + } + } } else if (result != resultbuf && length < allocated) { @@ -351,7 +351,7 @@ FUNC (uninorm_t nf, const UNIT *s, size_t n, memory = (UNIT *) realloc (result, length * sizeof (UNIT)); if (memory != NULL) - result = memory; + result = memory; } if (sortbuf_count > 0) diff --git a/lib/uninorm/u-normcmp.h b/lib/uninorm/u-normcmp.h index 66164406..5cda5db3 100644 --- a/lib/uninorm/u-normcmp.h +++ b/lib/uninorm/u-normcmp.h @@ -1,5 +1,5 @@ /* Normalization insensitive comparison of Unicode strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -40,11 +40,11 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2, if (norms2 == NULL) { if (norms1 != buf1) - { - int saved_errno = errno; - free (norms1); - errno = saved_errno; - } + { + int saved_errno = errno; + free (norms1); + errno = saved_errno; + } return -1; } diff --git a/lib/uninorm/u-normcoll.h b/lib/uninorm/u-normcoll.h index e30880b0..d76e7258 100644 --- a/lib/uninorm/u-normcoll.h +++ b/lib/uninorm/u-normcoll.h @@ -1,5 +1,5 @@ /* Locale dependent, normalization insensitive comparison of Unicode strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -40,17 +40,17 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2, if (transformed2 == NULL) { if (transformed1 != buf1) - { - int saved_errno = errno; - free (transformed1); - errno = saved_errno; - } + { + int saved_errno = errno; + free (transformed1); + errno = saved_errno; + } return -1; } /* Compare the transformed strings. */ cmp = memcmp2 (transformed1, transformed1_length, - transformed2, transformed2_length); + transformed2, transformed2_length); if (cmp < 0) cmp = -1; else if (cmp > 0) diff --git a/lib/uninorm/u-normxfrm.h b/lib/uninorm/u-normxfrm.h index 6ed1e3c3..ce84ff67 100644 --- a/lib/uninorm/u-normxfrm.h +++ b/lib/uninorm/u-normxfrm.h @@ -1,5 +1,5 @@ /* Locale dependent transformation for comparison of Unicode strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -37,18 +37,18 @@ FUNC (const UNIT *s, size_t n, uninorm_t nf, /* Convert it to locale encoding. */ convs_length = sizeof (convsbuf) - 1; convs = U_CONV_TO_ENCODING (locale_charset (), - iconveh_error, - norms, norms_length, - NULL, - convsbuf, &convs_length); + iconveh_error, + norms, norms_length, + NULL, + convsbuf, &convs_length); if (convs == NULL) { if (norms != normsbuf) - { - int saved_errno = errno; - free (norms); - errno = saved_errno; - } + { + int saved_errno = errno; + free (norms); + errno = saved_errno; + } return NULL; } @@ -60,11 +60,11 @@ FUNC (const UNIT *s, size_t n, uninorm_t nf, { char *memory = (char *) realloc (convs, convs_length + 1); if (memory == NULL) - { - free (convs); - errno = ENOMEM; - return NULL; - } + { + free (convs); + errno = ENOMEM; + return NULL; + } convs = memory; } @@ -73,11 +73,11 @@ FUNC (const UNIT *s, size_t n, uninorm_t nf, if (result == NULL) { if (convs != convsbuf) - { - int saved_errno = errno; - free (convs); - errno = saved_errno; - } + { + int saved_errno = errno; + free (convs); + errno = saved_errno; + } return NULL; } diff --git a/lib/uninorm/u16-normalize.c b/lib/uninorm/u16-normalize.c index 86334d53..df50e8d3 100644 --- a/lib/uninorm/u16-normalize.c +++ b/lib/uninorm/u16-normalize.c @@ -1,5 +1,5 @@ /* Normalization of UTF-16 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/u16-normcmp.c b/lib/uninorm/u16-normcmp.c index c66cc1be..e246a268 100644 --- a/lib/uninorm/u16-normcmp.c +++ b/lib/uninorm/u16-normcmp.c @@ -1,5 +1,5 @@ /* Normalization insensitive comparison of UTF-16 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/u16-normcoll.c b/lib/uninorm/u16-normcoll.c index a4f76c1b..b851472c 100644 --- a/lib/uninorm/u16-normcoll.c +++ b/lib/uninorm/u16-normcoll.c @@ -1,5 +1,5 @@ /* Locale dependent, normalization insensitive comparison of UTF-16 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/u16-normxfrm.c b/lib/uninorm/u16-normxfrm.c index cc22d8e3..41d274ab 100644 --- a/lib/uninorm/u16-normxfrm.c +++ b/lib/uninorm/u16-normxfrm.c @@ -1,5 +1,5 @@ /* Locale dependent transformation for comparison of UTF-16 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/u32-normalize.c b/lib/uninorm/u32-normalize.c index 6549423f..9ab8e5df 100644 --- a/lib/uninorm/u32-normalize.c +++ b/lib/uninorm/u32-normalize.c @@ -1,5 +1,5 @@ /* Normalization of UTF-32 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/u32-normcmp.c b/lib/uninorm/u32-normcmp.c index 58f890d6..705c3457 100644 --- a/lib/uninorm/u32-normcmp.c +++ b/lib/uninorm/u32-normcmp.c @@ -1,5 +1,5 @@ /* Normalization insensitive comparison of UTF-32 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/u32-normcoll.c b/lib/uninorm/u32-normcoll.c index 0343f760..37708030 100644 --- a/lib/uninorm/u32-normcoll.c +++ b/lib/uninorm/u32-normcoll.c @@ -1,5 +1,5 @@ /* Locale dependent, normalization insensitive comparison of UTF-32 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/u32-normxfrm.c b/lib/uninorm/u32-normxfrm.c index 4b4dbc05..7e953f98 100644 --- a/lib/uninorm/u32-normxfrm.c +++ b/lib/uninorm/u32-normxfrm.c @@ -1,5 +1,5 @@ /* Locale dependent transformation for comparison of UTF-32 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/u8-normalize.c b/lib/uninorm/u8-normalize.c index 7e003ec2..63679945 100644 --- a/lib/uninorm/u8-normalize.c +++ b/lib/uninorm/u8-normalize.c @@ -1,5 +1,5 @@ /* Normalization of UTF-8 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/u8-normcmp.c b/lib/uninorm/u8-normcmp.c index 6994f6c5..02a4d5e3 100644 --- a/lib/uninorm/u8-normcmp.c +++ b/lib/uninorm/u8-normcmp.c @@ -1,5 +1,5 @@ /* Normalization insensitive comparison of UTF-8 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/u8-normcoll.c b/lib/uninorm/u8-normcoll.c index 4d163d41..5c392d91 100644 --- a/lib/uninorm/u8-normcoll.c +++ b/lib/uninorm/u8-normcoll.c @@ -1,5 +1,5 @@ /* Locale dependent, normalization insensitive comparison of UTF-8 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/u8-normxfrm.c b/lib/uninorm/u8-normxfrm.c index 31da05d1..47d4fdc0 100644 --- a/lib/uninorm/u8-normxfrm.c +++ b/lib/uninorm/u8-normxfrm.c @@ -1,5 +1,5 @@ /* Locale dependent transformation for comparison of UTF-8 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uninorm/uninorm-filter.c b/lib/uninorm/uninorm-filter.c index 1d03cfaf..dbc5e10c 100644 --- a/lib/uninorm/uninorm-filter.c +++ b/lib/uninorm/uninorm-filter.c @@ -1,5 +1,5 @@ /* Stream-based normalization of Unicode strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -50,8 +50,8 @@ struct uninorm_filter struct uninorm_filter * uninorm_filter_create (uninorm_t nf, - int (*stream_func) (void *stream_data, ucs4_t uc), - void *stream_data) + int (*stream_func) (void *stream_data, ucs4_t uc), + void *stream_data) { struct uninorm_filter *filter = (struct uninorm_filter *) malloc (sizeof (struct uninorm_filter)); @@ -92,40 +92,40 @@ uninorm_filter_write (struct uninorm_filter *filter, ucs4_t uc_arg) for (curr = 0; curr < decomposed_count; ) { - /* Invariant: decomposed[0..curr-1] is fully decomposed, i.e. - all elements are atomic. */ - ucs4_t curr_decomposed[UC_DECOMPOSITION_MAX_LENGTH]; - int curr_decomposed_count; - - curr_decomposed_count = - filter->decomposer (decomposed[curr], curr_decomposed); - if (curr_decomposed_count >= 0) - { - /* Move curr_decomposed[0..curr_decomposed_count-1] over - decomposed[curr], making room. It's not worth using - memcpy() here, since the counts are so small. */ - int shift = curr_decomposed_count - 1; - - if (shift < 0) - abort (); - if (shift > 0) - { - int j; - - decomposed_count += shift; - if (decomposed_count > UC_DECOMPOSITION_MAX_LENGTH) - abort (); - for (j = decomposed_count - 1 - shift; j > curr; j--) - decomposed[j + shift] = decomposed[j]; - } - for (; shift >= 0; shift--) - decomposed[curr + shift] = curr_decomposed[shift]; - } - else - { - /* decomposed[curr] is atomic. */ - curr++; - } + /* Invariant: decomposed[0..curr-1] is fully decomposed, i.e. + all elements are atomic. */ + ucs4_t curr_decomposed[UC_DECOMPOSITION_MAX_LENGTH]; + int curr_decomposed_count; + + curr_decomposed_count = + filter->decomposer (decomposed[curr], curr_decomposed); + if (curr_decomposed_count >= 0) + { + /* Move curr_decomposed[0..curr_decomposed_count-1] over + decomposed[curr], making room. It's not worth using + memcpy() here, since the counts are so small. */ + int shift = curr_decomposed_count - 1; + + if (shift < 0) + abort (); + if (shift > 0) + { + int j; + + decomposed_count += shift; + if (decomposed_count > UC_DECOMPOSITION_MAX_LENGTH) + abort (); + for (j = decomposed_count - 1 - shift; j > curr; j--) + decomposed[j + shift] = decomposed[j]; + } + for (; shift >= 0; shift--) + decomposed[curr + shift] = curr_decomposed[shift]; + } + else + { + /* decomposed[curr] is atomic. */ + curr++; + } } } @@ -137,119 +137,119 @@ uninorm_filter_write (struct uninorm_filter *filter, ucs4_t uc_arg) for (i = 0; i < decomposed_count; i++) { - /* Fetch the next character from the decomposition. */ - ucs4_t uc = decomposed[i]; - int ccc = uc_combining_class (uc); - - if (ccc == 0) - { - size_t j; - - /* Apply the canonical ordering algorithm to the accumulated - sequence of characters. */ - if (sortbuf_count > 1) - gl_uninorm_decompose_merge_sort_inplace (sortbuf, sortbuf_count, - sortbuf + sortbuf_count); - - if (filter->composer != NULL) - { - /* Attempt to combine decomposed characters, as specified - in the Unicode Standard Annex #15 "Unicode Normalization - Forms". We need to check - 1. whether the first accumulated character is a - "starter" (i.e. has ccc = 0). This is usually the - case. But when the string starts with a - non-starter, the sortbuf also starts with a - non-starter. Btw, this check could also be - omitted, because the composition table has only - entries (code1, code2) for which code1 is a - starter; if the first accumulated character is not - a starter, no lookup will succeed. - 2. If the sortbuf has more than one character, check - for each of these characters that are not "blocked" - from the starter (i.e. have a ccc that is higher - than the ccc of the previous character) whether it - can be combined with the first character. - 3. If only one character is left in sortbuf, check - whether it can be combined with the next character - (also a starter). */ - if (sortbuf_count > 0 && sortbuf[0].ccc == 0) - { - for (j = 1; j < sortbuf_count; ) - { - if (sortbuf[j].ccc > sortbuf[j - 1].ccc) - { - ucs4_t combined = - filter->composer (sortbuf[0].code, sortbuf[j].code); - if (combined) - { - size_t k; - - sortbuf[0].code = combined; - /* sortbuf[0].ccc = 0, still valid. */ - for (k = j + 1; k < sortbuf_count; k++) - sortbuf[k - 1] = sortbuf[k]; - sortbuf_count--; - continue; - } - } - j++; - } - if (sortbuf_count == 1) - { - ucs4_t combined = - filter->composer (sortbuf[0].code, uc); - if (combined) - { - uc = combined; - ccc = 0; - /* uc could be further combined with subsequent - characters. So don't put it into sortbuf[0] in - this round, only in the next round. */ - sortbuf_count = 0; - } - } - } - } - - for (j = 0; j < sortbuf_count; j++) - { - ucs4_t muc = sortbuf[j].code; - - /* Output muc to the encapsulated stream. */ - int ret = filter->stream_func (filter->stream_data, muc); - if (ret < 0) - { - /* errno is set here. */ - filter->sortbuf_count = 0; - return -1; - } - } - - /* sortbuf is now empty. */ - sortbuf_count = 0; - } - - /* Append (uc, ccc) to sortbuf. */ - if (sortbuf_count == filter->sortbuf_allocated) - { - struct ucs4_with_ccc *new_sortbuf; - - filter->sortbuf_allocated = 2 * filter->sortbuf_allocated; - if (filter->sortbuf_allocated < sortbuf_count) /* integer overflow? */ - abort (); - new_sortbuf = - (struct ucs4_with_ccc *) - malloc (2 * filter->sortbuf_allocated * sizeof (struct ucs4_with_ccc)); - memcpy (new_sortbuf, filter->sortbuf, - sortbuf_count * sizeof (struct ucs4_with_ccc)); - if (filter->sortbuf != filter->sortbuf_preallocated) - free (filter->sortbuf); - filter->sortbuf = new_sortbuf; - } - filter->sortbuf[sortbuf_count].code = uc; - filter->sortbuf[sortbuf_count].ccc = ccc; - sortbuf_count++; + /* Fetch the next character from the decomposition. */ + ucs4_t uc = decomposed[i]; + int ccc = uc_combining_class (uc); + + if (ccc == 0) + { + size_t j; + + /* Apply the canonical ordering algorithm to the accumulated + sequence of characters. */ + if (sortbuf_count > 1) + gl_uninorm_decompose_merge_sort_inplace (sortbuf, sortbuf_count, + sortbuf + sortbuf_count); + + if (filter->composer != NULL) + { + /* Attempt to combine decomposed characters, as specified + in the Unicode Standard Annex #15 "Unicode Normalization + Forms". We need to check + 1. whether the first accumulated character is a + "starter" (i.e. has ccc = 0). This is usually the + case. But when the string starts with a + non-starter, the sortbuf also starts with a + non-starter. Btw, this check could also be + omitted, because the composition table has only + entries (code1, code2) for which code1 is a + starter; if the first accumulated character is not + a starter, no lookup will succeed. + 2. If the sortbuf has more than one character, check + for each of these characters that are not "blocked" + from the starter (i.e. have a ccc that is higher + than the ccc of the previous character) whether it + can be combined with the first character. + 3. If only one character is left in sortbuf, check + whether it can be combined with the next character + (also a starter). */ + if (sortbuf_count > 0 && sortbuf[0].ccc == 0) + { + for (j = 1; j < sortbuf_count; ) + { + if (sortbuf[j].ccc > sortbuf[j - 1].ccc) + { + ucs4_t combined = + filter->composer (sortbuf[0].code, sortbuf[j].code); + if (combined) + { + size_t k; + + sortbuf[0].code = combined; + /* sortbuf[0].ccc = 0, still valid. */ + for (k = j + 1; k < sortbuf_count; k++) + sortbuf[k - 1] = sortbuf[k]; + sortbuf_count--; + continue; + } + } + j++; + } + if (sortbuf_count == 1) + { + ucs4_t combined = + filter->composer (sortbuf[0].code, uc); + if (combined) + { + uc = combined; + ccc = 0; + /* uc could be further combined with subsequent + characters. So don't put it into sortbuf[0] in + this round, only in the next round. */ + sortbuf_count = 0; + } + } + } + } + + for (j = 0; j < sortbuf_count; j++) + { + ucs4_t muc = sortbuf[j].code; + + /* Output muc to the encapsulated stream. */ + int ret = filter->stream_func (filter->stream_data, muc); + if (ret < 0) + { + /* errno is set here. */ + filter->sortbuf_count = 0; + return -1; + } + } + + /* sortbuf is now empty. */ + sortbuf_count = 0; + } + + /* Append (uc, ccc) to sortbuf. */ + if (sortbuf_count == filter->sortbuf_allocated) + { + struct ucs4_with_ccc *new_sortbuf; + + filter->sortbuf_allocated = 2 * filter->sortbuf_allocated; + if (filter->sortbuf_allocated < sortbuf_count) /* integer overflow? */ + abort (); + new_sortbuf = + (struct ucs4_with_ccc *) + malloc (2 * filter->sortbuf_allocated * sizeof (struct ucs4_with_ccc)); + memcpy (new_sortbuf, filter->sortbuf, + sortbuf_count * sizeof (struct ucs4_with_ccc)); + if (filter->sortbuf != filter->sortbuf_preallocated) + free (filter->sortbuf); + filter->sortbuf = new_sortbuf; + } + filter->sortbuf[sortbuf_count].code = uc; + filter->sortbuf[sortbuf_count].ccc = ccc; + sortbuf_count++; } filter->sortbuf_count = sortbuf_count; @@ -276,53 +276,53 @@ uninorm_filter_flush (struct uninorm_filter *filter) sequence of characters. */ if (sortbuf_count > 1) gl_uninorm_decompose_merge_sort_inplace (sortbuf, sortbuf_count, - sortbuf + sortbuf_count); + sortbuf + sortbuf_count); if (filter->composer != NULL) { /* Attempt to combine decomposed characters, as specified - in the Unicode Standard Annex #15 "Unicode Normalization - Forms". We need to check - 1. whether the first accumulated character is a - "starter" (i.e. has ccc = 0). This is usually the - case. But when the string starts with a - non-starter, the sortbuf also starts with a - non-starter. Btw, this check could also be - omitted, because the composition table has only - entries (code1, code2) for which code1 is a - starter; if the first accumulated character is not - a starter, no lookup will succeed. - 2. If the sortbuf has more than one character, check - for each of these characters that are not "blocked" - from the starter (i.e. have a ccc that is higher - than the ccc of the previous character) whether it - can be combined with the first character. - 3. If only one character is left in sortbuf, check - whether it can be combined with the next character - (also a starter). */ + in the Unicode Standard Annex #15 "Unicode Normalization + Forms". We need to check + 1. whether the first accumulated character is a + "starter" (i.e. has ccc = 0). This is usually the + case. But when the string starts with a + non-starter, the sortbuf also starts with a + non-starter. Btw, this check could also be + omitted, because the composition table has only + entries (code1, code2) for which code1 is a + starter; if the first accumulated character is not + a starter, no lookup will succeed. + 2. If the sortbuf has more than one character, check + for each of these characters that are not "blocked" + from the starter (i.e. have a ccc that is higher + than the ccc of the previous character) whether it + can be combined with the first character. + 3. If only one character is left in sortbuf, check + whether it can be combined with the next character + (also a starter). */ if (sortbuf_count > 0 && sortbuf[0].ccc == 0) - { - for (j = 1; j < sortbuf_count; ) - { - if (sortbuf[j].ccc > sortbuf[j - 1].ccc) - { - ucs4_t combined = - filter->composer (sortbuf[0].code, sortbuf[j].code); - if (combined) - { - size_t k; - - sortbuf[0].code = combined; - /* sortbuf[0].ccc = 0, still valid. */ - for (k = j + 1; k < sortbuf_count; k++) - sortbuf[k - 1] = sortbuf[k]; - sortbuf_count--; - continue; - } - } - j++; - } - } + { + for (j = 1; j < sortbuf_count; ) + { + if (sortbuf[j].ccc > sortbuf[j - 1].ccc) + { + ucs4_t combined = + filter->composer (sortbuf[0].code, sortbuf[j].code); + if (combined) + { + size_t k; + + sortbuf[0].code = combined; + /* sortbuf[0].ccc = 0, still valid. */ + for (k = j + 1; k < sortbuf_count; k++) + sortbuf[k - 1] = sortbuf[k]; + sortbuf_count--; + continue; + } + } + j++; + } + } } for (j = 0; j < sortbuf_count; j++) @@ -332,11 +332,11 @@ uninorm_filter_flush (struct uninorm_filter *filter) /* Output muc to the encapsulated stream. */ int ret = filter->stream_func (filter->stream_data, muc); if (ret < 0) - { - /* errno is set here. */ - filter->sortbuf_count = 0; - return -1; - } + { + /* errno is set here. */ + filter->sortbuf_count = 0; + return -1; + } } /* sortbuf is now empty. */ diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 19bf5be8..fa82bbf2 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -1,5 +1,5 @@ /* Substitute for and wrapper around . - Copyright (C) 2003-2009 Free Software Foundation, Inc. + Copyright (C) 2003-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -15,85 +15,171 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef _GL_UNISTD_H - #if __GNUC__ >= 3 @PRAGMA_SYSTEM_HEADER@ #endif +/* Special invocation convention: + - On mingw, several headers, including , include , + but we need to ensure that both the system and + are completely included before we replace gethostname. */ +#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \ + && !defined _GL_WINSOCK2_H_WITNESS && defined _WINSOCK2_H +/* is being indirectly included for the first time from + ; avoid declaring any overrides. */ +# if @HAVE_UNISTD_H@ +# @INCLUDE_NEXT@ @NEXT_UNISTD_H@ +# else +# error unexpected; report this to bug-gnulib@gnu.org +# endif +# define _GL_WINSOCK2_H_WITNESS + +/* Normal invocation. */ +#elif !defined _GL_UNISTD_H + /* The include_next requires a split double-inclusion guard. */ #if @HAVE_UNISTD_H@ # @INCLUDE_NEXT@ @NEXT_UNISTD_H@ #endif -#ifndef _GL_UNISTD_H +/* Get all possible declarations of gethostname(). */ +#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \ + && !defined _GL_INCLUDING_WINSOCK2_H +# define _GL_INCLUDING_WINSOCK2_H +# include +# undef _GL_INCLUDING_WINSOCK2_H +#endif + +#if !defined _GL_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H #define _GL_UNISTD_H /* NetBSD 5.0 mis-defines NULL. Also get size_t. */ #include /* mingw doesn't define the SEEK_* or *_FILENO macros in . */ -#if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) +/* Cygwin 1.7.1 declares symlinkat in , not in . */ +/* But avoid namespace pollution on glibc systems. */ +#if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \ + || (@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK)) \ + && ! defined __GLIBC__ # include #endif +/* Cygwin 1.7.1 declares unlinkat in , not in . */ +/* But avoid namespace pollution on glibc systems. */ +#if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ +# include +#endif + /* mingw fails to declare _exit in . */ /* mingw, BeOS, Haiku declare environ in , not in . */ -#include +/* Solaris declares getcwd not only in but also in . */ +/* But avoid namespace pollution on glibc systems. */ +#ifndef __GLIBC__ +# include +#endif + +/* mingw declares getcwd in , not in . */ +#if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \ + && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) +# include +#endif -#if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@ +#if (@GNULIB_WRITE@ || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \ + || @GNULIB_PREAD@ || defined GNULIB_POSIXCHECK) /* Get ssize_t. */ # include #endif -/* Get getopt(), optarg, optind, opterr, optopt. */ -#if @GNULIB_UNISTD_H_GETOPT@ +/* Get getopt(), optarg, optind, opterr, optopt. + But avoid namespace pollution on glibc systems. */ +#if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT # include #endif +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_ARG_NONNULL is copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + + #if @GNULIB_GETHOSTNAME@ /* Get all possible declarations of gethostname(). */ # if @UNISTD_H_HAVE_WINSOCK2_H@ -# include # if !defined _GL_SYS_SOCKET_H -# undef socket -# define socket socket_used_without_including_sys_socket_h -# undef connect -# define connect connect_used_without_including_sys_socket_h -# undef accept -# define accept accept_used_without_including_sys_socket_h -# undef bind -# define bind bind_used_without_including_sys_socket_h -# undef getpeername -# define getpeername getpeername_used_without_including_sys_socket_h -# undef getsockname -# define getsockname getsockname_used_without_including_sys_socket_h -# undef getsockopt -# define getsockopt getsockopt_used_without_including_sys_socket_h -# undef listen -# define listen listen_used_without_including_sys_socket_h -# undef recv -# define recv recv_used_without_including_sys_socket_h -# undef send -# define send send_used_without_including_sys_socket_h -# undef recvfrom -# define recvfrom recvfrom_used_without_including_sys_socket_h -# undef sendto -# define sendto sendto_used_without_including_sys_socket_h -# undef setsockopt -# define setsockopt setsockopt_used_without_including_sys_socket_h -# undef shutdown -# define shutdown shutdown_used_without_including_sys_socket_h +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef socket +# define socket socket_used_without_including_sys_socket_h +# undef connect +# define connect connect_used_without_including_sys_socket_h +# undef accept +# define accept accept_used_without_including_sys_socket_h +# undef bind +# define bind bind_used_without_including_sys_socket_h +# undef getpeername +# define getpeername getpeername_used_without_including_sys_socket_h +# undef getsockname +# define getsockname getsockname_used_without_including_sys_socket_h +# undef getsockopt +# define getsockopt getsockopt_used_without_including_sys_socket_h +# undef listen +# define listen listen_used_without_including_sys_socket_h +# undef recv +# define recv recv_used_without_including_sys_socket_h +# undef send +# define send send_used_without_including_sys_socket_h +# undef recvfrom +# define recvfrom recvfrom_used_without_including_sys_socket_h +# undef sendto +# define sendto sendto_used_without_including_sys_socket_h +# undef setsockopt +# define setsockopt setsockopt_used_without_including_sys_socket_h +# undef shutdown +# define shutdown shutdown_used_without_including_sys_socket_h +# else + _GL_WARN_ON_USE (socket, + "socket() used without including "); + _GL_WARN_ON_USE (connect, + "connect() used without including "); + _GL_WARN_ON_USE (accept, + "accept() used without including "); + _GL_WARN_ON_USE (bind, + "bind() used without including "); + _GL_WARN_ON_USE (getpeername, + "getpeername() used without including "); + _GL_WARN_ON_USE (getsockname, + "getsockname() used without including "); + _GL_WARN_ON_USE (getsockopt, + "getsockopt() used without including "); + _GL_WARN_ON_USE (listen, + "listen() used without including "); + _GL_WARN_ON_USE (recv, + "recv() used without including "); + _GL_WARN_ON_USE (send, + "send() used without including "); + _GL_WARN_ON_USE (recvfrom, + "recvfrom() used without including "); + _GL_WARN_ON_USE (sendto, + "sendto() used without including "); + _GL_WARN_ON_USE (setsockopt, + "setsockopt() used without including "); + _GL_WARN_ON_USE (shutdown, + "shutdown() used without including "); +# endif # endif # if !defined _GL_SYS_SELECT_H -# undef select -# define select select_used_without_including_sys_select_h +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef select +# define select select_used_without_including_sys_select_h +# else + _GL_WARN_ON_USE (select, + "select() used without including "); +# endif # endif # endif #endif -/* The definition of GL_LINK_WARNING is copied here. */ - /* OS/2 EMX lacks these macros. */ #ifndef STDIN_FILENO @@ -106,75 +192,147 @@ # define STDERR_FILENO 2 #endif +/* Ensure *_OK macros exist. */ +#ifndef F_OK +# define F_OK 0 +# define X_OK 1 +# define W_OK 2 +# define R_OK 4 +#endif + + /* Declare overridden functions. */ -#ifdef __cplusplus -extern "C" { + +#if defined GNULIB_POSIXCHECK +/* The access() function is a security risk. */ +_GL_WARN_ON_USE (access, "the access function is a security risk - " + "use the gnulib module faccessat instead"); #endif #if @GNULIB_CHOWN@ -# if @REPLACE_CHOWN@ -# ifndef REPLACE_CHOWN -# define REPLACE_CHOWN 1 -# endif -# if REPLACE_CHOWN /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE to GID (if GID is not -1). Follow symbolic links. Return 0 if successful, otherwise -1 and errno set. See the POSIX:2001 specification . */ +# if @REPLACE_CHOWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef chown # define chown rpl_chown -extern int chown (const char *file, uid_t uid, gid_t gid); # endif +_GL_FUNCDECL_RPL (chown, int, (const char *file, uid_t uid, gid_t gid) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (chown, int, (const char *file, uid_t uid, gid_t gid)); +# else +# if !@HAVE_CHOWN@ +_GL_FUNCDECL_SYS (chown, int, (const char *file, uid_t uid, gid_t gid) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (chown, int, (const char *file, uid_t uid, gid_t gid)); # endif +_GL_CXXALIASWARN (chown); #elif defined GNULIB_POSIXCHECK # undef chown -# define chown(f,u,g) \ - (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \ - "doesn't treat a uid or gid of -1 on some systems - " \ - "use gnulib module chown for portability"), \ - chown (f, u, g)) +# if HAVE_RAW_DECL_CHOWN +_GL_WARN_ON_USE (chown, "chown fails to follow symlinks on some systems and " + "doesn't treat a uid or gid of -1 on some systems - " + "use gnulib module chown for portability"); +# endif #endif #if @GNULIB_CLOSE@ # if @REPLACE_CLOSE@ /* Automatically included by modules that need a replacement for close. */ -# undef close -# define close rpl_close -extern int close (int); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef close +# define close rpl_close +# endif +_GL_FUNCDECL_RPL (close, int, (int fd)); +_GL_CXXALIAS_RPL (close, int, (int fd)); +# else +_GL_CXXALIAS_SYS (close, int, (int fd)); # endif +_GL_CXXALIASWARN (close); #elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@ # undef close # define close close_used_without_requesting_gnulib_module_close #elif defined GNULIB_POSIXCHECK # undef close -# define close(f) \ - (GL_LINK_WARNING ("close does not portably work on sockets - " \ - "use gnulib module close for portability"), \ - close (f)) +/* Assume close is always declared. */ +_GL_WARN_ON_USE (close, "close does not portably work on sockets - " + "use gnulib module close for portability"); #endif -#if @GNULIB_DUP2@ -# if @REPLACE_DUP2@ -# define dup2 rpl_dup2 +#if @REPLACE_DUP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define dup rpl_dup # endif -# if !@HAVE_DUP2@ || @REPLACE_DUP2@ +_GL_FUNCDECL_RPL (dup, int, (int oldfd)); +_GL_CXXALIAS_RPL (dup, int, (int oldfd)); +#else +_GL_CXXALIAS_SYS (dup, int, (int oldfd)); +#endif +_GL_CXXALIASWARN (dup); + + +#if @GNULIB_DUP2@ /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if NEWFD = OLDFD, otherwise close NEWFD first if it is open. Return newfd if successful, otherwise -1 and errno set. See the POSIX:2001 specification . */ -extern int dup2 (int oldfd, int newfd); +# if @REPLACE_DUP2@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define dup2 rpl_dup2 +# endif +_GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd)); +_GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd)); +# else +# if !@HAVE_DUP2@ +_GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd)); +# endif +_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd)); # endif +_GL_CXXALIASWARN (dup2); #elif defined GNULIB_POSIXCHECK # undef dup2 -# define dup2(o,n) \ - (GL_LINK_WARNING ("dup2 is unportable - " \ - "use gnulib module dup2 for portability"), \ - dup2 (o, n)) +# if HAVE_RAW_DECL_DUP2 +_GL_WARN_ON_USE (dup2, "dup2 is unportable - " + "use gnulib module dup2 for portability"); +# endif +#endif + + +#if @GNULIB_DUP3@ +/* Copy the file descriptor OLDFD into file descriptor NEWFD, with the + specified flags. + The flags are a bitmask, possibly including O_CLOEXEC (defined in ) + and O_TEXT, O_BINARY (defined in "binary-io.h"). + Close NEWFD first if it is open. + Return newfd if successful, otherwise -1 and errno set. + See the Linux man page at + . */ +# if @HAVE_DUP3@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define dup3 rpl_dup3 +# endif +_GL_FUNCDECL_RPL (dup3, int, (int oldfd, int newfd, int flags)); +_GL_CXXALIAS_RPL (dup3, int, (int oldfd, int newfd, int flags)); +# else +_GL_FUNCDECL_SYS (dup3, int, (int oldfd, int newfd, int flags)); +_GL_CXXALIAS_SYS (dup3, int, (int oldfd, int newfd, int flags)); +# endif +_GL_CXXALIASWARN (dup3); +#elif defined GNULIB_POSIXCHECK +# undef dup3 +# if HAVE_RAW_DECL_DUP3 +_GL_WARN_ON_USE (dup3, "dup3 is unportable - " + "use gnulib module dup3 for portability"); +# endif #endif @@ -186,59 +344,126 @@ extern int dup2 (int oldfd, int newfd); # include # define environ (*_NSGetEnviron ()) # else +# ifdef __cplusplus +extern "C" { +# endif extern char **environ; +# ifdef __cplusplus +} +# endif # endif # endif #elif defined GNULIB_POSIXCHECK -# undef environ -# define environ \ - (GL_LINK_WARNING ("environ is unportable - " \ - "use gnulib module environ for portability"), \ - environ) +# if HAVE_RAW_DECL_ENVIRON +static inline char *** +rpl_environ (void) +{ + return &environ; +} +_GL_WARN_ON_USE (rpl_environ, "environ is unportable - " + "use gnulib module environ for portability"); +# undef environ +# define environ (*rpl_environ ()) +# endif #endif #if @GNULIB_EUIDACCESS@ -# if !@HAVE_EUIDACCESS@ -/* Like access(), except that is uses the effective user id and group id of +/* Like access(), except that it uses the effective user id and group id of the current process. */ -extern int euidaccess (const char *filename, int mode); +# if !@HAVE_EUIDACCESS@ +_GL_FUNCDECL_SYS (euidaccess, int, (const char *filename, int mode) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (euidaccess, int, (const char *filename, int mode)); +_GL_CXXALIASWARN (euidaccess); +# if defined GNULIB_POSIXCHECK +/* Like access(), this function is a security risk. */ +_GL_WARN_ON_USE (euidaccess, "the euidaccess function is a security risk - " + "use the gnulib module faccessat instead"); # endif #elif defined GNULIB_POSIXCHECK # undef euidaccess -# define euidaccess(f,m) \ - (GL_LINK_WARNING ("euidaccess is unportable - " \ - "use gnulib module euidaccess for portability"), \ - euidaccess (f, m)) +# if HAVE_RAW_DECL_EUIDACCESS +_GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - " + "use gnulib module euidaccess for portability"); +# endif #endif -#if @GNULIB_FCHDIR@ -# if @REPLACE_FCHDIR@ +#if @GNULIB_FACCESSAT@ +# if !@HAVE_FACCESSAT@ +_GL_FUNCDECL_SYS (faccessat, int, + (int fd, char const *file, int mode, int flag) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (faccessat, int, + (int fd, char const *file, int mode, int flag)); +_GL_CXXALIASWARN (faccessat); +#elif defined GNULIB_POSIXCHECK +# undef faccessat +# if HAVE_RAW_DECL_FACCESSAT +_GL_WARN_ON_USE (faccessat, "faccessat is not portable - " + "use gnulib module faccessat for portability"); +# endif +#endif + +#if @GNULIB_FCHDIR@ /* Change the process' current working directory to the directory on which the given file descriptor is open. Return 0 if successful, otherwise -1 and errno set. See the POSIX:2001 specification . */ -extern int fchdir (int /*fd*/); +# if ! @HAVE_FCHDIR@ +_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/)); -# define dup rpl_dup -extern int dup (int); - -# if @REPLACE_DUP2@ -# undef dup2 -# endif -# define dup2 rpl_dup2_fchdir -extern int dup2 (int, int); +/* Gnulib internal hooks needed to maintain the fchdir metadata. */ +_GL_EXTERN_C int _gl_register_fd (int fd, const char *filename) + _GL_ARG_NONNULL ((2)); +_GL_EXTERN_C void _gl_unregister_fd (int fd); +_GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd); +_GL_EXTERN_C const char *_gl_directory_name (int fd); # endif +_GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/)); +_GL_CXXALIASWARN (fchdir); #elif defined GNULIB_POSIXCHECK # undef fchdir -# define fchdir(f) \ - (GL_LINK_WARNING ("fchdir is unportable - " \ - "use gnulib module fchdir for portability"), \ - fchdir (f)) +# if HAVE_RAW_DECL_FCHDIR +_GL_WARN_ON_USE (fchdir, "fchdir is unportable - " + "use gnulib module fchdir for portability"); +# endif +#endif + + +#if @GNULIB_FCHOWNAT@ +# if @REPLACE_FCHOWNAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef fchownat +# define fchownat rpl_fchownat +# endif +_GL_FUNCDECL_RPL (fchownat, int, (int fd, char const *file, + uid_t owner, gid_t group, int flag) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (fchownat, int, (int fd, char const *file, + uid_t owner, gid_t group, int flag)); +# else +# if !@HAVE_FCHOWNAT@ +_GL_FUNCDECL_SYS (fchownat, int, (int fd, char const *file, + uid_t owner, gid_t group, int flag) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file, + uid_t owner, gid_t group, int flag)); +# endif +_GL_CXXALIASWARN (fchownat); +#elif defined GNULIB_POSIXCHECK +# undef fchownat +# if HAVE_RAW_DECL_FCHOWNAT +_GL_WARN_ON_USE (fchownat, "fchownat is not portable - " + "use gnulib module openat for portability"); +# endif #endif @@ -248,39 +473,39 @@ extern int dup2 (int, int); See POSIX:2001 specification . */ # if !@HAVE_FSYNC@ -extern int fsync (int fd); +_GL_FUNCDECL_SYS (fsync, int, (int fd)); # endif +_GL_CXXALIAS_SYS (fsync, int, (int fd)); +_GL_CXXALIASWARN (fsync); #elif defined GNULIB_POSIXCHECK # undef fsync -# define fsync(fd) \ - (GL_LINK_WARNING ("fsync is unportable - " \ - "use gnulib module fsync for portability"), \ - fsync (fd)) +# if HAVE_RAW_DECL_FSYNC +_GL_WARN_ON_USE (fsync, "fsync is unportable - " + "use gnulib module fsync for portability"); +# endif #endif #if @GNULIB_FTRUNCATE@ -# if !@HAVE_FTRUNCATE@ /* Change the size of the file to which FD is opened to become equal to LENGTH. Return 0 if successful, otherwise -1 and errno set. See the POSIX:2001 specification . */ -extern int ftruncate (int fd, off_t length); +# if !@HAVE_FTRUNCATE@ +_GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length)); # endif +_GL_CXXALIAS_SYS (ftruncate, int, (int fd, off_t length)); +_GL_CXXALIASWARN (ftruncate); #elif defined GNULIB_POSIXCHECK # undef ftruncate -# define ftruncate(f,l) \ - (GL_LINK_WARNING ("ftruncate is unportable - " \ - "use gnulib module ftruncate for portability"), \ - ftruncate (f, l)) +# if HAVE_RAW_DECL_FTRUNCATE +_GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - " + "use gnulib module ftruncate for portability"); +# endif #endif #if @GNULIB_GETCWD@ -/* Include the headers that might declare getcwd so that they will not - cause confusion if included after this file. */ -# include -# if @REPLACE_GETCWD@ /* Get the name of the current working directory, and put it in SIZE bytes of BUF. Return BUF if successful, or NULL if the directory couldn't be determined @@ -291,15 +516,24 @@ extern int ftruncate (int fd, off_t length); extension: If BUF is NULL, an array is allocated with 'malloc'; the array is SIZE bytes long, unless SIZE == 0, in which case it is as big as necessary. */ -# define getcwd rpl_getcwd -extern char * getcwd (char *buf, size_t size); +# if @REPLACE_GETCWD@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define getcwd rpl_getcwd +# endif +_GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size)); +_GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size)); +# else +/* Need to cast, because on mingw, the second parameter is + int size. */ +_GL_CXXALIAS_SYS_CAST (getcwd, char *, (char *buf, size_t size)); # endif +_GL_CXXALIASWARN (getcwd); #elif defined GNULIB_POSIXCHECK # undef getcwd -# define getcwd(b,s) \ - (GL_LINK_WARNING ("getcwd is unportable - " \ - "use gnulib module getcwd for portability"), \ - getcwd (b, s)) +# if HAVE_RAW_DECL_GETCWD +_GL_WARN_ON_USE (getcwd, "getcwd is unportable - " + "use gnulib module getcwd for portability"); +# endif #endif @@ -315,28 +549,65 @@ extern char * getcwd (char *buf, size_t size); If the NIS domain name is longer than LEN, set errno = EINVAL and return -1. Return 0 if successful, otherwise set errno and return -1. */ # if !@HAVE_GETDOMAINNAME@ -extern int getdomainname(char *name, size_t len); +_GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len) + _GL_ARG_NONNULL ((1))); # endif +/* Need to cast, because on MacOS X 10.5 systems, the second parameter is + int len. */ +_GL_CXXALIAS_SYS_CAST (getdomainname, int, (char *name, size_t len)); +_GL_CXXALIASWARN (getdomainname); #elif defined GNULIB_POSIXCHECK # undef getdomainname -# define getdomainname(n,l) \ - (GL_LINK_WARNING ("getdomainname is unportable - " \ - "use gnulib module getdomainname for portability"), \ - getdomainname (n, l)) +# if HAVE_RAW_DECL_GETDOMAINNAME +_GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - " + "use gnulib module getdomainname for portability"); +# endif #endif #if @GNULIB_GETDTABLESIZE@ +/* Return the maximum number of file descriptors in the current process. + In POSIX, this is same as sysconf (_SC_OPEN_MAX). */ # if !@HAVE_GETDTABLESIZE@ -/* Return the maximum number of file descriptors in the current process. */ -extern int getdtablesize (void); +_GL_FUNCDECL_SYS (getdtablesize, int, (void)); # endif +_GL_CXXALIAS_SYS (getdtablesize, int, (void)); +_GL_CXXALIASWARN (getdtablesize); #elif defined GNULIB_POSIXCHECK # undef getdtablesize -# define getdtablesize() \ - (GL_LINK_WARNING ("getdtablesize is unportable - " \ - "use gnulib module getdtablesize for portability"), \ - getdtablesize ()) +# if HAVE_RAW_DECL_GETDTABLESIZE +_GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - " + "use gnulib module getdtablesize for portability"); +# endif +#endif + + +#if @GNULIB_GETGROUPS@ +/* Return the supplemental groups that the current process belongs to. + It is unspecified whether the effective group id is in the list. + If N is 0, return the group count; otherwise, N describes how many + entries are available in GROUPS. Return -1 and set errno if N is + not 0 and not large enough. Fails with ENOSYS on some systems. */ +# if @REPLACE_GETGROUPS@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef getgroups +# define getgroups rpl_getgroups +# endif +_GL_FUNCDECL_RPL (getgroups, int, (int n, gid_t *groups)); +_GL_CXXALIAS_RPL (getgroups, int, (int n, gid_t *groups)); +# else +# if !@HAVE_GETGROUPS@ +_GL_FUNCDECL_SYS (getgroups, int, (int n, gid_t *groups)); +# endif +_GL_CXXALIAS_SYS (getgroups, int, (int n, gid_t *groups)); +# endif +_GL_CXXALIASWARN (getgroups); +#elif defined GNULIB_POSIXCHECK +# undef getgroups +# if HAVE_RAW_DECL_GETGROUPS +_GL_WARN_ON_USE (getgroups, "getgroups is unportable - " + "use gnulib module getgroups for portability"); +# endif #endif @@ -349,21 +620,57 @@ extern int getdtablesize (void); If the host name is longer than LEN, set errno = EINVAL and return -1. Return 0 if successful, otherwise set errno and return -1. */ # if @UNISTD_H_HAVE_WINSOCK2_H@ -# undef gethostname -# define gethostname rpl_gethostname -# endif -# if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@ -extern int gethostname(char *name, size_t len); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef gethostname +# define gethostname rpl_gethostname +# endif +_GL_FUNCDECL_RPL (gethostname, int, (char *name, size_t len) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (gethostname, int, (char *name, size_t len)); +# else +# if !@HAVE_GETHOSTNAME@ +_GL_FUNCDECL_SYS (gethostname, int, (char *name, size_t len) + _GL_ARG_NONNULL ((1))); +# endif +/* Need to cast, because on Solaris 10 systems, the second parameter is + int len. */ +_GL_CXXALIAS_SYS_CAST (gethostname, int, (char *name, size_t len)); # endif +_GL_CXXALIASWARN (gethostname); #elif @UNISTD_H_HAVE_WINSOCK2_H@ # undef gethostname # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname #elif defined GNULIB_POSIXCHECK # undef gethostname -# define gethostname(n,l) \ - (GL_LINK_WARNING ("gethostname is unportable - " \ - "use gnulib module gethostname for portability"), \ - gethostname (n, l)) +# if HAVE_RAW_DECL_GETHOSTNAME +_GL_WARN_ON_USE (gethostname, "gethostname is unportable - " + "use gnulib module gethostname for portability"); +# endif +#endif + + +#if @GNULIB_GETLOGIN@ +/* Returns the user's login name, or NULL if it cannot be found. Upon error, + returns NULL with errno set. + + See . + + Most programs don't need to use this function, because the information is + available through environment variables: + ${LOGNAME-$USER} on Unix platforms, + $USERNAME on native Windows platforms. + */ +# if !@HAVE_GETLOGIN@ +_GL_FUNCDECL_SYS (getlogin, char *, (void)); +# endif +_GL_CXXALIAS_SYS (getlogin, char *, (void)); +_GL_CXXALIASWARN (getlogin); +#elif defined GNULIB_POSIXCHECK +# undef getlogin +# if HAVE_RAW_DECL_GETLOGIN +_GL_WARN_ON_USE (getlogin, "getlogin is unportable - " + "use gnulib module getlogin for portability"); +# endif #endif @@ -376,123 +683,184 @@ extern int gethostname(char *name, size_t len); provided (this case is hopefully rare but is left open by the POSIX spec). See . + + Most programs don't need to use this function, because the information is + available through environment variables: + ${LOGNAME-$USER} on Unix platforms, + $USERNAME on native Windows platforms. */ # if !@HAVE_DECL_GETLOGIN_R@ -extern int getlogin_r (char *name, size_t size); +_GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size) + _GL_ARG_NONNULL ((1))); # endif +/* Need to cast, because on Solaris 10 systems, the second argument is + int size. */ +_GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size)); +_GL_CXXALIASWARN (getlogin_r); #elif defined GNULIB_POSIXCHECK # undef getlogin_r -# define getlogin_r(n,s) \ - (GL_LINK_WARNING ("getlogin_r is unportable - " \ - "use gnulib module getlogin_r for portability"), \ - getlogin_r (n, s)) +# if HAVE_RAW_DECL_GETLOGIN_R +_GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - " + "use gnulib module getlogin_r for portability"); +# endif #endif #if @GNULIB_GETPAGESIZE@ # if @REPLACE_GETPAGESIZE@ -# define getpagesize rpl_getpagesize -extern int getpagesize (void); -# elif !@HAVE_GETPAGESIZE@ -/* This is for POSIX systems. */ -# if !defined getpagesize && defined _SC_PAGESIZE -# if ! (defined __VMS && __VMS_VER < 70000000) -# define getpagesize() sysconf (_SC_PAGESIZE) -# endif +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define getpagesize rpl_getpagesize # endif +_GL_FUNCDECL_RPL (getpagesize, int, (void)); +_GL_CXXALIAS_RPL (getpagesize, int, (void)); +# else +# if !@HAVE_GETPAGESIZE@ +# if !defined getpagesize +/* This is for POSIX systems. */ +# if !defined _gl_getpagesize && defined _SC_PAGESIZE +# if ! (defined __VMS && __VMS_VER < 70000000) +# define _gl_getpagesize() sysconf (_SC_PAGESIZE) +# endif +# endif /* This is for older VMS. */ -# if !defined getpagesize && defined __VMS -# ifdef __ALPHA -# define getpagesize() 8192 -# else -# define getpagesize() 512 -# endif -# endif +# if !defined _gl_getpagesize && defined __VMS +# ifdef __ALPHA +# define _gl_getpagesize() 8192 +# else +# define _gl_getpagesize() 512 +# endif +# endif /* This is for BeOS. */ -# if !defined getpagesize && @HAVE_OS_H@ -# include -# if defined B_PAGE_SIZE -# define getpagesize() B_PAGE_SIZE -# endif -# endif +# if !defined _gl_getpagesize && @HAVE_OS_H@ +# include +# if defined B_PAGE_SIZE +# define _gl_getpagesize() B_PAGE_SIZE +# endif +# endif /* This is for AmigaOS4.0. */ -# if !defined getpagesize && defined __amigaos4__ -# define getpagesize() 2048 -# endif +# if !defined _gl_getpagesize && defined __amigaos4__ +# define _gl_getpagesize() 2048 +# endif /* This is for older Unix systems. */ -# if !defined getpagesize && @HAVE_SYS_PARAM_H@ -# include -# ifdef EXEC_PAGESIZE -# define getpagesize() EXEC_PAGESIZE -# else -# ifdef NBPG -# ifndef CLSIZE -# define CLSIZE 1 +# if !defined _gl_getpagesize && @HAVE_SYS_PARAM_H@ +# include +# ifdef EXEC_PAGESIZE +# define _gl_getpagesize() EXEC_PAGESIZE +# else +# ifdef NBPG +# ifndef CLSIZE +# define CLSIZE 1 +# endif +# define _gl_getpagesize() (NBPG * CLSIZE) +# else +# ifdef NBPC +# define _gl_getpagesize() NBPC +# endif +# endif # endif -# define getpagesize() (NBPG * CLSIZE) +# endif +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define getpagesize() _gl_getpagesize () # else -# ifdef NBPC -# define getpagesize() NBPC -# endif +static inline int +getpagesize () +{ + return _gl_getpagesize (); +} # endif # endif # endif +/* Need to cast, because on Cygwin 1.5.x systems, the return type is size_t. */ +_GL_CXXALIAS_SYS_CAST (getpagesize, int, (void)); +# endif +# if @HAVE_DECL_GETPAGESIZE@ +_GL_CXXALIASWARN (getpagesize); # endif #elif defined GNULIB_POSIXCHECK # undef getpagesize -# define getpagesize() \ - (GL_LINK_WARNING ("getpagesize is unportable - " \ - "use gnulib module getpagesize for portability"), \ - getpagesize ()) +# if HAVE_RAW_DECL_GETPAGESIZE +_GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - " + "use gnulib module getpagesize for portability"); +# endif #endif #if @GNULIB_GETUSERSHELL@ -# if !@HAVE_GETUSERSHELL@ /* Return the next valid login shell on the system, or NULL when the end of the list has been reached. */ -extern char *getusershell (void); +# if !@HAVE_DECL_GETUSERSHELL@ +_GL_FUNCDECL_SYS (getusershell, char *, (void)); +# endif +_GL_CXXALIAS_SYS (getusershell, char *, (void)); +_GL_CXXALIASWARN (getusershell); +#elif defined GNULIB_POSIXCHECK +# undef getusershell +# if HAVE_RAW_DECL_GETUSERSHELL +_GL_WARN_ON_USE (getusershell, "getusershell is unportable - " + "use gnulib module getusershell for portability"); +# endif +#endif + +#if @GNULIB_GETUSERSHELL@ /* Rewind to pointer that is advanced at each getusershell() call. */ -extern void setusershell (void); +# if !@HAVE_DECL_GETUSERSHELL@ +_GL_FUNCDECL_SYS (setusershell, void, (void)); +# endif +_GL_CXXALIAS_SYS (setusershell, void, (void)); +_GL_CXXALIASWARN (setusershell); +#elif defined GNULIB_POSIXCHECK +# undef setusershell +# if HAVE_RAW_DECL_SETUSERSHELL +_GL_WARN_ON_USE (setusershell, "setusershell is unportable - " + "use gnulib module getusershell for portability"); +# endif +#endif + +#if @GNULIB_GETUSERSHELL@ /* Free the pointer that is advanced at each getusershell() call and associated resources. */ -extern void endusershell (void); +# if !@HAVE_DECL_GETUSERSHELL@ +_GL_FUNCDECL_SYS (endusershell, void, (void)); # endif +_GL_CXXALIAS_SYS (endusershell, void, (void)); +_GL_CXXALIASWARN (endusershell); #elif defined GNULIB_POSIXCHECK -# undef getusershell -# define getusershell() \ - (GL_LINK_WARNING ("getusershell is unportable - " \ - "use gnulib module getusershell for portability"), \ - getusershell ()) -# undef setusershell -# define setusershell() \ - (GL_LINK_WARNING ("setusershell is unportable - " \ - "use gnulib module getusershell for portability"), \ - setusershell ()) # undef endusershell -# define endusershell() \ - (GL_LINK_WARNING ("endusershell is unportable - " \ - "use gnulib module getusershell for portability"), \ - endusershell ()) +# if HAVE_RAW_DECL_ENDUSERSHELL +_GL_WARN_ON_USE (endusershell, "endusershell is unportable - " + "use gnulib module getusershell for portability"); +# endif #endif #if @GNULIB_LCHOWN@ -# if @REPLACE_LCHOWN@ /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE to GID (if GID is not -1). Do not follow symbolic links. Return 0 if successful, otherwise -1 and errno set. See the POSIX:2001 specification . */ -# define lchown rpl_lchown -extern int lchown (char const *file, uid_t owner, gid_t group); +# if @REPLACE_LCHOWN@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef lchown +# define lchown rpl_lchown +# endif +_GL_FUNCDECL_RPL (lchown, int, (char const *file, uid_t owner, gid_t group) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (lchown, int, (char const *file, uid_t owner, gid_t group)); +# else +# if !@HAVE_LCHOWN@ +_GL_FUNCDECL_SYS (lchown, int, (char const *file, uid_t owner, gid_t group) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (lchown, int, (char const *file, uid_t owner, gid_t group)); # endif +_GL_CXXALIASWARN (lchown); #elif defined GNULIB_POSIXCHECK # undef lchown -# define lchown(f,u,g) \ - (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \ - "systems - use gnulib module lchown for portability"), \ - lchown (f, u, g)) +# if HAVE_RAW_DECL_LCHOWN +_GL_WARN_ON_USE (lchown, "lchown is unportable to pre-POSIX.1-2001 systems - " + "use gnulib module lchown for portability"); +# endif #endif @@ -501,33 +869,150 @@ extern int lchown (char const *file, uid_t owner, gid_t group); Return 0 if successful, otherwise -1 and errno set. See POSIX:2001 specification . */ -# if !@HAVE_LINK@ -extern int link (const char *path1, const char *path2); +# if @REPLACE_LINK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define link rpl_link +# endif +_GL_FUNCDECL_RPL (link, int, (const char *path1, const char *path2) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (link, int, (const char *path1, const char *path2)); +# else +# if !@HAVE_LINK@ +_GL_FUNCDECL_SYS (link, int, (const char *path1, const char *path2) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (link, int, (const char *path1, const char *path2)); # endif +_GL_CXXALIASWARN (link); #elif defined GNULIB_POSIXCHECK # undef link -# define link(path1,path2) \ - (GL_LINK_WARNING ("link is unportable - " \ - "use gnulib module link for portability"), \ - link (path1, path2)) +# if HAVE_RAW_DECL_LINK +_GL_WARN_ON_USE (link, "link is unportable - " + "use gnulib module link for portability"); +# endif +#endif + + +#if @GNULIB_LINKAT@ +/* Create a new hard link for an existing file, relative to two + directories. FLAG controls whether symlinks are followed. + Return 0 if successful, otherwise -1 and errno set. */ +# if @REPLACE_LINKAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef linkat +# define linkat rpl_linkat +# endif +_GL_FUNCDECL_RPL (linkat, int, + (int fd1, const char *path1, int fd2, const char *path2, + int flag) + _GL_ARG_NONNULL ((2, 4))); +_GL_CXXALIAS_RPL (linkat, int, + (int fd1, const char *path1, int fd2, const char *path2, + int flag)); +# else +# if !@HAVE_LINKAT@ +_GL_FUNCDECL_SYS (linkat, int, + (int fd1, const char *path1, int fd2, const char *path2, + int flag) + _GL_ARG_NONNULL ((2, 4))); +# endif +_GL_CXXALIAS_SYS (linkat, int, + (int fd1, const char *path1, int fd2, const char *path2, + int flag)); +# endif +_GL_CXXALIASWARN (linkat); +#elif defined GNULIB_POSIXCHECK +# undef linkat +# if HAVE_RAW_DECL_LINKAT +_GL_WARN_ON_USE (linkat, "linkat is unportable - " + "use gnulib module linkat for portability"); +# endif #endif #if @GNULIB_LSEEK@ -# if @REPLACE_LSEEK@ /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END. Return the new offset if successful, otherwise -1 and errno set. See the POSIX:2001 specification . */ -# define lseek rpl_lseek - extern off_t lseek (int fd, off_t offset, int whence); +# if @REPLACE_LSEEK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define lseek rpl_lseek +# endif +_GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence)); +_GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence)); +# else +_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence)); # endif +_GL_CXXALIASWARN (lseek); #elif defined GNULIB_POSIXCHECK # undef lseek -# define lseek(f,o,w) \ - (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \ - "systems - use gnulib module lseek for portability"), \ - lseek (f, o, w)) +# if HAVE_RAW_DECL_LSEEK +_GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some " + "systems - use gnulib module lseek for portability"); +# endif +#endif + + +#if @GNULIB_PIPE2@ +/* Create a pipe, applying the given flags when opening the read-end of the + pipe and the write-end of the pipe. + The flags are a bitmask, possibly including O_CLOEXEC (defined in ) + and O_TEXT, O_BINARY (defined in "binary-io.h"). + Store the read-end as fd[0] and the write-end as fd[1]. + Return 0 upon success, or -1 with errno set upon failure. + See also the Linux man page at + . */ +# if @HAVE_PIPE2@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define pipe2 rpl_pipe2 +# endif +_GL_FUNCDECL_RPL (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (pipe2, int, (int fd[2], int flags)); +# else +_GL_FUNCDECL_SYS (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_SYS (pipe2, int, (int fd[2], int flags)); +# endif +_GL_CXXALIASWARN (pipe2); +#elif defined GNULIB_POSIXCHECK +# undef pipe2 +# if HAVE_RAW_DECL_PIPE2 +_GL_WARN_ON_USE (pipe2, "pipe2 is unportable - " + "use gnulib module pipe2 for portability"); +# endif +#endif + + +#if @GNULIB_PREAD@ +/* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET. + Return the number of bytes placed into BUF if successful, otherwise + set errno and return -1. 0 indicates EOF. See the POSIX:2001 + specification . */ +# if @REPLACE_PREAD@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define pread rpl_pread +# endif +_GL_FUNCDECL_RPL (pread, ssize_t, + (int fd, void *buf, size_t bufsize, off_t offset) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (pread, ssize_t, + (int fd, void *buf, size_t bufsize, off_t offset)); +# else +# if !@HAVE_PREAD@ +_GL_FUNCDECL_SYS (pread, ssize_t, + (int fd, void *buf, size_t bufsize, off_t offset) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (pread, ssize_t, + (int fd, void *buf, size_t bufsize, off_t offset)); +# endif +_GL_CXXALIASWARN (pread); +#elif defined GNULIB_POSIXCHECK +# undef pread +# if HAVE_RAW_DECL_PREAD +_GL_WARN_ON_USE (pread, "pread is unportable - " + "use gnulib module pread for portability"); +# endif #endif @@ -537,15 +1022,70 @@ extern int link (const char *path1, const char *path2); successful, otherwise -1 and errno set. See the POSIX:2001 specification . */ -# if !@HAVE_READLINK@ -extern int readlink (const char *file, char *buf, size_t bufsize); +# if @REPLACE_READLINK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define readlink rpl_readlink +# endif +_GL_FUNCDECL_RPL (readlink, ssize_t, + (const char *file, char *buf, size_t bufsize) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (readlink, ssize_t, + (const char *file, char *buf, size_t bufsize)); +# else +# if !@HAVE_READLINK@ +_GL_FUNCDECL_SYS (readlink, ssize_t, + (const char *file, char *buf, size_t bufsize) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (readlink, ssize_t, + (const char *file, char *buf, size_t bufsize)); # endif +_GL_CXXALIASWARN (readlink); #elif defined GNULIB_POSIXCHECK # undef readlink -# define readlink(f,b,s) \ - (GL_LINK_WARNING ("readlink is unportable - " \ - "use gnulib module readlink for portability"), \ - readlink (f, b, s)) +# if HAVE_RAW_DECL_READLINK +_GL_WARN_ON_USE (readlink, "readlink is unportable - " + "use gnulib module readlink for portability"); +# endif +#endif + + +#if @GNULIB_READLINKAT@ +# if !@HAVE_READLINKAT@ +_GL_FUNCDECL_SYS (readlinkat, ssize_t, + (int fd, char const *file, char *buf, size_t len) + _GL_ARG_NONNULL ((2, 3))); +# endif +_GL_CXXALIAS_SYS (readlinkat, ssize_t, + (int fd, char const *file, char *buf, size_t len)); +_GL_CXXALIASWARN (readlinkat); +#elif defined GNULIB_POSIXCHECK +# undef readlinkat +# if HAVE_RAW_DECL_READLINKAT +_GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - " + "use gnulib module symlinkat for portability"); +# endif +#endif + + +#if @GNULIB_RMDIR@ +/* Remove the directory DIR. */ +# if @REPLACE_RMDIR@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define rmdir rpl_rmdir +# endif +_GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (rmdir, int, (char const *name)); +# else +_GL_CXXALIAS_SYS (rmdir, int, (char const *name)); +# endif +_GL_CXXALIASWARN (rmdir); +#elif defined GNULIB_POSIXCHECK +# undef rmdir +# if HAVE_RAW_DECL_RMDIR +_GL_WARN_ON_USE (rmdir, "rmdir is unportable - " + "use gnulib module rmdir for portability"); +# endif #endif @@ -554,36 +1094,197 @@ extern int readlink (const char *file, char *buf, size_t bufsize); Returns the number of seconds left to sleep. See the POSIX:2001 specification . */ -# if !@HAVE_SLEEP@ -extern unsigned int sleep (unsigned int n); +# if @REPLACE_SLEEP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef sleep +# define sleep rpl_sleep +# endif +_GL_FUNCDECL_RPL (sleep, unsigned int, (unsigned int n)); +_GL_CXXALIAS_RPL (sleep, unsigned int, (unsigned int n)); +# else +# if !@HAVE_SLEEP@ +_GL_FUNCDECL_SYS (sleep, unsigned int, (unsigned int n)); +# endif +_GL_CXXALIAS_SYS (sleep, unsigned int, (unsigned int n)); # endif +_GL_CXXALIASWARN (sleep); #elif defined GNULIB_POSIXCHECK # undef sleep -# define sleep(n) \ - (GL_LINK_WARNING ("sleep is unportable - " \ - "use gnulib module sleep for portability"), \ - sleep (n)) +# if HAVE_RAW_DECL_SLEEP +_GL_WARN_ON_USE (sleep, "sleep is unportable - " + "use gnulib module sleep for portability"); +# endif #endif -#if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@ -/* Write up to COUNT bytes starting at BUF to file descriptor FD. - See the POSIX:2001 specification - . */ -# undef write -# define write rpl_write -extern ssize_t write (int fd, const void *buf, size_t count); +#if @GNULIB_SYMLINK@ +# if @REPLACE_SYMLINK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef symlink +# define symlink rpl_symlink +# endif +_GL_FUNCDECL_RPL (symlink, int, (char const *contents, char const *file) + _GL_ARG_NONNULL ((1, 2))); +_GL_CXXALIAS_RPL (symlink, int, (char const *contents, char const *file)); +# else +# if !@HAVE_SYMLINK@ +_GL_FUNCDECL_SYS (symlink, int, (char const *contents, char const *file) + _GL_ARG_NONNULL ((1, 2))); +# endif +_GL_CXXALIAS_SYS (symlink, int, (char const *contents, char const *file)); +# endif +_GL_CXXALIASWARN (symlink); +#elif defined GNULIB_POSIXCHECK +# undef symlink +# if HAVE_RAW_DECL_SYMLINK +_GL_WARN_ON_USE (symlink, "symlink is not portable - " + "use gnulib module symlink for portability"); +# endif #endif -#ifdef FCHDIR_REPLACEMENT -/* gnulib internal function. */ -extern void _gl_unregister_fd (int fd); +#if @GNULIB_SYMLINKAT@ +# if !@HAVE_SYMLINKAT@ +_GL_FUNCDECL_SYS (symlinkat, int, + (char const *contents, int fd, char const *file) + _GL_ARG_NONNULL ((1, 3))); +# endif +_GL_CXXALIAS_SYS (symlinkat, int, + (char const *contents, int fd, char const *file)); +_GL_CXXALIASWARN (symlinkat); +#elif defined GNULIB_POSIXCHECK +# undef symlinkat +# if HAVE_RAW_DECL_SYMLINKAT +_GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - " + "use gnulib module symlinkat for portability"); +# endif #endif -#ifdef __cplusplus -} +#if @GNULIB_TTYNAME_R@ +/* Store at most BUFLEN characters of the pathname of the terminal FD is + open on in BUF. Return 0 on success, otherwise an error number. */ +# if @REPLACE_TTYNAME_R@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef ttyname_r +# define ttyname_r rpl_ttyname_r +# endif +_GL_FUNCDECL_RPL (ttyname_r, int, + (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (ttyname_r, int, + (int fd, char *buf, size_t buflen)); +# else +# if !@HAVE_TTYNAME_R@ +_GL_FUNCDECL_SYS (ttyname_r, int, + (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (ttyname_r, int, + (int fd, char *buf, size_t buflen)); +# endif +_GL_CXXALIASWARN (ttyname_r); +#elif defined GNULIB_POSIXCHECK +# undef ttyname_r +# if HAVE_RAW_DECL_TTYNAME_R +_GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - " + "use gnulib module ttyname_r for portability"); +# endif +#endif + + +#if @GNULIB_UNLINK@ +# if @REPLACE_UNLINK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef unlink +# define unlink rpl_unlink +# endif +_GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (unlink, int, (char const *file)); +# else +_GL_CXXALIAS_SYS (unlink, int, (char const *file)); +# endif +_GL_CXXALIASWARN (unlink); +#elif defined GNULIB_POSIXCHECK +# undef unlink +# if HAVE_RAW_DECL_UNLINK +_GL_WARN_ON_USE (unlink, "unlink is not portable - " + "use gnulib module unlink for portability"); +# endif +#endif + + +#if @GNULIB_UNLINKAT@ +# if @REPLACE_UNLINKAT@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef unlinkat +# define unlinkat rpl_unlinkat +# endif +_GL_FUNCDECL_RPL (unlinkat, int, (int fd, char const *file, int flag) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (unlinkat, int, (int fd, char const *file, int flag)); +# else +# if !@HAVE_UNLINKAT@ +_GL_FUNCDECL_SYS (unlinkat, int, (int fd, char const *file, int flag) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (unlinkat, int, (int fd, char const *file, int flag)); +# endif +_GL_CXXALIASWARN (unlinkat); +#elif defined GNULIB_POSIXCHECK +# undef unlinkat +# if HAVE_RAW_DECL_UNLINKAT +_GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - " + "use gnulib module openat for portability"); +# endif +#endif + + +#if @GNULIB_USLEEP@ +/* Pause the execution of the current thread for N microseconds. + Returns 0 on completion, or -1 on range error. + See the POSIX:2001 specification + . */ +# if @REPLACE_USLEEP@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef usleep +# define usleep rpl_usleep +# endif +_GL_FUNCDECL_RPL (usleep, int, (useconds_t n)); +_GL_CXXALIAS_RPL (usleep, int, (useconds_t n)); +# else +# if !@HAVE_USLEEP@ +_GL_FUNCDECL_SYS (usleep, int, (useconds_t n)); +# endif +_GL_CXXALIAS_SYS (usleep, int, (useconds_t n)); +# endif +_GL_CXXALIASWARN (usleep); +#elif defined GNULIB_POSIXCHECK +# undef usleep +# if HAVE_RAW_DECL_USLEEP +_GL_WARN_ON_USE (usleep, "usleep is unportable - " + "use gnulib module usleep for portability"); +# endif +#endif + + +#if @GNULIB_WRITE@ +/* Write up to COUNT bytes starting at BUF to file descriptor FD. + See the POSIX:2001 specification + . */ +# if @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef write +# define write rpl_write +# endif +_GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count)); +# else +/* Need to cast, because on mingw, the third parameter is + unsigned int count + and the return type is 'int'. */ +_GL_CXXALIAS_SYS_CAST (write, ssize_t, (int fd, const void *buf, size_t count)); +# endif +_GL_CXXALIASWARN (write); #endif diff --git a/lib/unistdio.h b/lib/unistdio.h index d9eca02f..8eb69222 100644 --- a/lib/unistdio.h +++ b/lib/unistdio.h @@ -1,5 +1,5 @@ /* Elementary Unicode string functions. - Copyright (C) 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2007, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -62,192 +62,192 @@ extern "C" { /* ASCII format string, result in locale dependent encoded 'char *'. */ extern int ulc_sprintf (char *buf, - const char *format, ...); + const char *format, ...); extern int ulc_snprintf (char *buf, size_t size, - const char *format, ...); + const char *format, ...); extern int ulc_asprintf (char **resultp, - const char *format, ...); + const char *format, ...); extern char * ulc_asnprintf (char *resultbuf, size_t *lengthp, - const char *format, ...); + const char *format, ...); extern int ulc_vsprintf (char *buf, - const char *format, va_list ap); + const char *format, va_list ap); extern int ulc_vsnprintf (char *buf, size_t size, - const char *format, va_list ap); + const char *format, va_list ap); extern int ulc_vasprintf (char **resultp, - const char *format, va_list ap); + const char *format, va_list ap); extern char * ulc_vasnprintf (char *resultbuf, size_t *lengthp, - const char *format, va_list ap); + const char *format, va_list ap); /* ASCII format string, result in UTF-8 format. */ extern int u8_sprintf (uint8_t *buf, - const char *format, ...); + const char *format, ...); extern int u8_snprintf (uint8_t *buf, size_t size, - const char *format, ...); + const char *format, ...); extern int u8_asprintf (uint8_t **resultp, - const char *format, ...); + const char *format, ...); extern uint8_t * u8_asnprintf (uint8_t *resultbuf, size_t *lengthp, - const char *format, ...); + const char *format, ...); extern int u8_vsprintf (uint8_t *buf, - const char *format, va_list ap); + const char *format, va_list ap); extern int u8_vsnprintf (uint8_t *buf, size_t size, - const char *format, va_list ap); + const char *format, va_list ap); extern int u8_vasprintf (uint8_t **resultp, - const char *format, va_list ap); + const char *format, va_list ap); extern uint8_t * u8_vasnprintf (uint8_t *resultbuf, size_t *lengthp, - const char *format, va_list ap); + const char *format, va_list ap); /* UTF-8 format string, result in UTF-8 format. */ extern int u8_u8_sprintf (uint8_t *buf, - const uint8_t *format, ...); + const uint8_t *format, ...); extern int u8_u8_snprintf (uint8_t *buf, size_t size, - const uint8_t *format, ...); + const uint8_t *format, ...); extern int u8_u8_asprintf (uint8_t **resultp, - const uint8_t *format, ...); + const uint8_t *format, ...); extern uint8_t * u8_u8_asnprintf (uint8_t *resultbuf, size_t *lengthp, - const uint8_t *format, ...); + const uint8_t *format, ...); extern int u8_u8_vsprintf (uint8_t *buf, - const uint8_t *format, va_list ap); + const uint8_t *format, va_list ap); extern int u8_u8_vsnprintf (uint8_t *buf, size_t size, - const uint8_t *format, va_list ap); + const uint8_t *format, va_list ap); extern int u8_u8_vasprintf (uint8_t **resultp, - const uint8_t *format, va_list ap); + const uint8_t *format, va_list ap); extern uint8_t * u8_u8_vasnprintf (uint8_t *resultbuf, size_t *lengthp, - const uint8_t *format, va_list ap); + const uint8_t *format, va_list ap); /* ASCII format string, result in UTF-16 format. */ extern int u16_sprintf (uint16_t *buf, - const char *format, ...); + const char *format, ...); extern int u16_snprintf (uint16_t *buf, size_t size, - const char *format, ...); + const char *format, ...); extern int u16_asprintf (uint16_t **resultp, - const char *format, ...); + const char *format, ...); extern uint16_t * u16_asnprintf (uint16_t *resultbuf, size_t *lengthp, - const char *format, ...); + const char *format, ...); extern int u16_vsprintf (uint16_t *buf, - const char *format, va_list ap); + const char *format, va_list ap); extern int u16_vsnprintf (uint16_t *buf, size_t size, - const char *format, va_list ap); + const char *format, va_list ap); extern int u16_vasprintf (uint16_t **resultp, - const char *format, va_list ap); + const char *format, va_list ap); extern uint16_t * u16_vasnprintf (uint16_t *resultbuf, size_t *lengthp, - const char *format, va_list ap); + const char *format, va_list ap); /* UTF-16 format string, result in UTF-16 format. */ extern int u16_u16_sprintf (uint16_t *buf, - const uint16_t *format, ...); + const uint16_t *format, ...); extern int u16_u16_snprintf (uint16_t *buf, size_t size, - const uint16_t *format, ...); + const uint16_t *format, ...); extern int u16_u16_asprintf (uint16_t **resultp, - const uint16_t *format, ...); + const uint16_t *format, ...); extern uint16_t * u16_u16_asnprintf (uint16_t *resultbuf, size_t *lengthp, - const uint16_t *format, ...); + const uint16_t *format, ...); extern int u16_u16_vsprintf (uint16_t *buf, - const uint16_t *format, va_list ap); + const uint16_t *format, va_list ap); extern int u16_u16_vsnprintf (uint16_t *buf, size_t size, - const uint16_t *format, va_list ap); + const uint16_t *format, va_list ap); extern int u16_u16_vasprintf (uint16_t **resultp, - const uint16_t *format, va_list ap); + const uint16_t *format, va_list ap); extern uint16_t * u16_u16_vasnprintf (uint16_t *resultbuf, size_t *lengthp, - const uint16_t *format, va_list ap); + const uint16_t *format, va_list ap); /* ASCII format string, result in UTF-32 format. */ extern int u32_sprintf (uint32_t *buf, - const char *format, ...); + const char *format, ...); extern int u32_snprintf (uint32_t *buf, size_t size, - const char *format, ...); + const char *format, ...); extern int u32_asprintf (uint32_t **resultp, - const char *format, ...); + const char *format, ...); extern uint32_t * u32_asnprintf (uint32_t *resultbuf, size_t *lengthp, - const char *format, ...); + const char *format, ...); extern int u32_vsprintf (uint32_t *buf, - const char *format, va_list ap); + const char *format, va_list ap); extern int u32_vsnprintf (uint32_t *buf, size_t size, - const char *format, va_list ap); + const char *format, va_list ap); extern int u32_vasprintf (uint32_t **resultp, - const char *format, va_list ap); + const char *format, va_list ap); extern uint32_t * u32_vasnprintf (uint32_t *resultbuf, size_t *lengthp, - const char *format, va_list ap); + const char *format, va_list ap); /* UTF-32 format string, result in UTF-32 format. */ extern int u32_u32_sprintf (uint32_t *buf, - const uint32_t *format, ...); + const uint32_t *format, ...); extern int u32_u32_snprintf (uint32_t *buf, size_t size, - const uint32_t *format, ...); + const uint32_t *format, ...); extern int u32_u32_asprintf (uint32_t **resultp, - const uint32_t *format, ...); + const uint32_t *format, ...); extern uint32_t * u32_u32_asnprintf (uint32_t *resultbuf, size_t *lengthp, - const uint32_t *format, ...); + const uint32_t *format, ...); extern int u32_u32_vsprintf (uint32_t *buf, - const uint32_t *format, va_list ap); + const uint32_t *format, va_list ap); extern int u32_u32_vsnprintf (uint32_t *buf, size_t size, - const uint32_t *format, va_list ap); + const uint32_t *format, va_list ap); extern int u32_u32_vasprintf (uint32_t **resultp, - const uint32_t *format, va_list ap); + const uint32_t *format, va_list ap); extern uint32_t * u32_u32_vasnprintf (uint32_t *resultbuf, size_t *lengthp, - const uint32_t *format, va_list ap); + const uint32_t *format, va_list ap); /* ASCII format string, output to FILE in locale dependent encoding. */ extern int ulc_fprintf (FILE *stream, - const char *format, ...); + const char *format, ...); extern int ulc_vfprintf (FILE *stream, - const char *format, va_list ap); + const char *format, va_list ap); #ifdef __cplusplus } diff --git a/lib/unistdio/u-asnprintf.h b/lib/unistdio/u-asnprintf.h index 8fd08d7f..693e35eb 100644 --- a/lib/unistdio/u-asnprintf.h +++ b/lib/unistdio/u-asnprintf.h @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u-asprintf.h b/lib/unistdio/u-asprintf.h index ba82faba..b7f5cb29 100644 --- a/lib/unistdio/u-asprintf.h +++ b/lib/unistdio/u-asprintf.h @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u-printf-args.c b/lib/unistdio/u-printf-args.c index 22fbc088..b357f3c0 100644 --- a/lib/unistdio/u-printf-args.c +++ b/lib/unistdio/u-printf-args.c @@ -1,5 +1,6 @@ /* Decomposed printf argument list. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u-printf-args.h b/lib/unistdio/u-printf-args.h index 7b2255a2..4e099fc9 100644 --- a/lib/unistdio/u-printf-args.h +++ b/lib/unistdio/u-printf-args.h @@ -1,5 +1,6 @@ /* Decomposed printf argument list. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u-printf-parse.h b/lib/unistdio/u-printf-parse.h index 11a953f9..0f593f82 100644 --- a/lib/unistdio/u-printf-parse.h +++ b/lib/unistdio/u-printf-parse.h @@ -1,5 +1,6 @@ /* Parse printf format string. - Copyright (C) 1999, 2002, 2005, 2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005, 2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u-snprintf.h b/lib/unistdio/u-snprintf.h index 1665bc23..391709ba 100644 --- a/lib/unistdio/u-snprintf.h +++ b/lib/unistdio/u-snprintf.h @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u-sprintf.h b/lib/unistdio/u-sprintf.h index 8a1b5544..94f3c820 100644 --- a/lib/unistdio/u-sprintf.h +++ b/lib/unistdio/u-sprintf.h @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u-vasprintf.h b/lib/unistdio/u-vasprintf.h index 965bfbf5..e67c4cba 100644 --- a/lib/unistdio/u-vasprintf.h +++ b/lib/unistdio/u-vasprintf.h @@ -1,5 +1,5 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u-vsnprintf.h b/lib/unistdio/u-vsnprintf.h index 481a22f0..2b2e0d57 100644 --- a/lib/unistdio/u-vsnprintf.h +++ b/lib/unistdio/u-vsnprintf.h @@ -1,5 +1,5 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -31,13 +31,13 @@ VSNPRINTF (DCHAR_T *buf, size_t size, const FCHAR_T *format, va_list args) if (result != buf) { if (size != 0) - { - /* The result did not fit into the buffer. Copy the initial segment - into the buffer, truncating it if necessary. */ - size_t n = (length < size ? length : size - 1); - DCHAR_CPY (buf, result, n); - buf[n] = '\0'; - } + { + /* The result did not fit into the buffer. Copy the initial segment + into the buffer, truncating it if necessary. */ + size_t n = (length < size ? length : size - 1); + DCHAR_CPY (buf, result, n); + buf[n] = '\0'; + } free (result); } diff --git a/lib/unistdio/u-vsprintf.h b/lib/unistdio/u-vsprintf.h index 36ebd9fa..0caf0736 100644 --- a/lib/unistdio/u-vsprintf.h +++ b/lib/unistdio/u-vsprintf.h @@ -1,5 +1,5 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-asnprintf.c b/lib/unistdio/u16-asnprintf.c index bbe4bacb..0705dd9e 100644 --- a/lib/unistdio/u16-asnprintf.c +++ b/lib/unistdio/u16-asnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-asprintf.c b/lib/unistdio/u16-asprintf.c index 79f3969c..f7710bb8 100644 --- a/lib/unistdio/u16-asprintf.c +++ b/lib/unistdio/u16-asprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-printf-parse.c b/lib/unistdio/u16-printf-parse.c index 3a8acd32..fbc10831 100644 --- a/lib/unistdio/u16-printf-parse.c +++ b/lib/unistdio/u16-printf-parse.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2010 Free Software + Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-snprintf.c b/lib/unistdio/u16-snprintf.c index afed8a7e..c2b99a07 100644 --- a/lib/unistdio/u16-snprintf.c +++ b/lib/unistdio/u16-snprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-sprintf.c b/lib/unistdio/u16-sprintf.c index 48603652..b0e0799d 100644 --- a/lib/unistdio/u16-sprintf.c +++ b/lib/unistdio/u16-sprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-u16-asnprintf.c b/lib/unistdio/u16-u16-asnprintf.c index 64c257c2..bfb184ae 100644 --- a/lib/unistdio/u16-u16-asnprintf.c +++ b/lib/unistdio/u16-u16-asnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-u16-asprintf.c b/lib/unistdio/u16-u16-asprintf.c index 38469c6e..84f1d665 100644 --- a/lib/unistdio/u16-u16-asprintf.c +++ b/lib/unistdio/u16-u16-asprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-u16-snprintf.c b/lib/unistdio/u16-u16-snprintf.c index 7229add1..d1642e9e 100644 --- a/lib/unistdio/u16-u16-snprintf.c +++ b/lib/unistdio/u16-u16-snprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-u16-sprintf.c b/lib/unistdio/u16-u16-sprintf.c index 1c517c36..58043672 100644 --- a/lib/unistdio/u16-u16-sprintf.c +++ b/lib/unistdio/u16-u16-sprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-u16-vasnprintf.c b/lib/unistdio/u16-u16-vasnprintf.c index e33851e2..5c356bf8 100644 --- a/lib/unistdio/u16-u16-vasnprintf.c +++ b/lib/unistdio/u16-u16-vasnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to UTF-16 strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-u16-vasprintf.c b/lib/unistdio/u16-u16-vasprintf.c index 3d8fc508..6202a8bf 100644 --- a/lib/unistdio/u16-u16-vasprintf.c +++ b/lib/unistdio/u16-u16-vasprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-u16-vsnprintf.c b/lib/unistdio/u16-u16-vsnprintf.c index 6bbf8251..2bf5c0ea 100644 --- a/lib/unistdio/u16-u16-vsnprintf.c +++ b/lib/unistdio/u16-u16-vsnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-u16-vsprintf.c b/lib/unistdio/u16-u16-vsprintf.c index 1a7e93c2..b87f17e5 100644 --- a/lib/unistdio/u16-u16-vsprintf.c +++ b/lib/unistdio/u16-u16-vsprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-vasnprintf.c b/lib/unistdio/u16-vasnprintf.c index 3ce19d42..05d0adfc 100644 --- a/lib/unistdio/u16-vasnprintf.c +++ b/lib/unistdio/u16-vasnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to UTF-16 strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-vasprintf.c b/lib/unistdio/u16-vasprintf.c index b63dd183..f917f68f 100644 --- a/lib/unistdio/u16-vasprintf.c +++ b/lib/unistdio/u16-vasprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-vsnprintf.c b/lib/unistdio/u16-vsnprintf.c index b06ca094..0b8bfce5 100644 --- a/lib/unistdio/u16-vsnprintf.c +++ b/lib/unistdio/u16-vsnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u16-vsprintf.c b/lib/unistdio/u16-vsprintf.c index 4811bc15..7026a689 100644 --- a/lib/unistdio/u16-vsprintf.c +++ b/lib/unistdio/u16-vsprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-asnprintf.c b/lib/unistdio/u32-asnprintf.c index dad1ae49..c4eefd6b 100644 --- a/lib/unistdio/u32-asnprintf.c +++ b/lib/unistdio/u32-asnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-asprintf.c b/lib/unistdio/u32-asprintf.c index 11e23f01..67730320 100644 --- a/lib/unistdio/u32-asprintf.c +++ b/lib/unistdio/u32-asprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-printf-parse.c b/lib/unistdio/u32-printf-parse.c index a5772566..bc3c7f25 100644 --- a/lib/unistdio/u32-printf-parse.c +++ b/lib/unistdio/u32-printf-parse.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2010 Free Software + Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-snprintf.c b/lib/unistdio/u32-snprintf.c index 7d670171..0636eef4 100644 --- a/lib/unistdio/u32-snprintf.c +++ b/lib/unistdio/u32-snprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-sprintf.c b/lib/unistdio/u32-sprintf.c index 6f930d09..207078bc 100644 --- a/lib/unistdio/u32-sprintf.c +++ b/lib/unistdio/u32-sprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-u32-asnprintf.c b/lib/unistdio/u32-u32-asnprintf.c index b3a02745..bd37c808 100644 --- a/lib/unistdio/u32-u32-asnprintf.c +++ b/lib/unistdio/u32-u32-asnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-u32-asprintf.c b/lib/unistdio/u32-u32-asprintf.c index 91a96fc4..edc16e70 100644 --- a/lib/unistdio/u32-u32-asprintf.c +++ b/lib/unistdio/u32-u32-asprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-u32-snprintf.c b/lib/unistdio/u32-u32-snprintf.c index cf88529c..a36c1239 100644 --- a/lib/unistdio/u32-u32-snprintf.c +++ b/lib/unistdio/u32-u32-snprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-u32-sprintf.c b/lib/unistdio/u32-u32-sprintf.c index ccf6d028..eb322fc9 100644 --- a/lib/unistdio/u32-u32-sprintf.c +++ b/lib/unistdio/u32-u32-sprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-u32-vasnprintf.c b/lib/unistdio/u32-u32-vasnprintf.c index b272af33..17ae282c 100644 --- a/lib/unistdio/u32-u32-vasnprintf.c +++ b/lib/unistdio/u32-u32-vasnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to UTF-32 strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-u32-vasprintf.c b/lib/unistdio/u32-u32-vasprintf.c index bacc7c1b..678e2fd9 100644 --- a/lib/unistdio/u32-u32-vasprintf.c +++ b/lib/unistdio/u32-u32-vasprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-u32-vsnprintf.c b/lib/unistdio/u32-u32-vsnprintf.c index 7f436236..c42678b7 100644 --- a/lib/unistdio/u32-u32-vsnprintf.c +++ b/lib/unistdio/u32-u32-vsnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-u32-vsprintf.c b/lib/unistdio/u32-u32-vsprintf.c index 46d299ac..6a185987 100644 --- a/lib/unistdio/u32-u32-vsprintf.c +++ b/lib/unistdio/u32-u32-vsprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-vasnprintf.c b/lib/unistdio/u32-vasnprintf.c index 6aac6235..86a3564a 100644 --- a/lib/unistdio/u32-vasnprintf.c +++ b/lib/unistdio/u32-vasnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to UTF-32 strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-vasprintf.c b/lib/unistdio/u32-vasprintf.c index e6883e31..ef4ed97d 100644 --- a/lib/unistdio/u32-vasprintf.c +++ b/lib/unistdio/u32-vasprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-vsnprintf.c b/lib/unistdio/u32-vsnprintf.c index a55e1c76..ba47a3c5 100644 --- a/lib/unistdio/u32-vsnprintf.c +++ b/lib/unistdio/u32-vsnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u32-vsprintf.c b/lib/unistdio/u32-vsprintf.c index a850e45f..26b1e959 100644 --- a/lib/unistdio/u32-vsprintf.c +++ b/lib/unistdio/u32-vsprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-asnprintf.c b/lib/unistdio/u8-asnprintf.c index b8e7a276..839e6e24 100644 --- a/lib/unistdio/u8-asnprintf.c +++ b/lib/unistdio/u8-asnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-asprintf.c b/lib/unistdio/u8-asprintf.c index 22b01705..8004b964 100644 --- a/lib/unistdio/u8-asprintf.c +++ b/lib/unistdio/u8-asprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-printf-parse.c b/lib/unistdio/u8-printf-parse.c index a3555481..6b872991 100644 --- a/lib/unistdio/u8-printf-parse.c +++ b/lib/unistdio/u8-printf-parse.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2010 Free Software + Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-snprintf.c b/lib/unistdio/u8-snprintf.c index 87290541..ce0f7dec 100644 --- a/lib/unistdio/u8-snprintf.c +++ b/lib/unistdio/u8-snprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-sprintf.c b/lib/unistdio/u8-sprintf.c index 330feaee..2467fbb3 100644 --- a/lib/unistdio/u8-sprintf.c +++ b/lib/unistdio/u8-sprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-u8-asnprintf.c b/lib/unistdio/u8-u8-asnprintf.c index 9379c72a..cdcd6c8f 100644 --- a/lib/unistdio/u8-u8-asnprintf.c +++ b/lib/unistdio/u8-u8-asnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-u8-asprintf.c b/lib/unistdio/u8-u8-asprintf.c index 59745278..8e34f3d9 100644 --- a/lib/unistdio/u8-u8-asprintf.c +++ b/lib/unistdio/u8-u8-asprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-u8-snprintf.c b/lib/unistdio/u8-u8-snprintf.c index 26dfac0e..615c5cbd 100644 --- a/lib/unistdio/u8-u8-snprintf.c +++ b/lib/unistdio/u8-u8-snprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-u8-sprintf.c b/lib/unistdio/u8-u8-sprintf.c index 53b3c96b..57c5642e 100644 --- a/lib/unistdio/u8-u8-sprintf.c +++ b/lib/unistdio/u8-u8-sprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-u8-vasnprintf.c b/lib/unistdio/u8-u8-vasnprintf.c index 7535d4ca..588947da 100644 --- a/lib/unistdio/u8-u8-vasnprintf.c +++ b/lib/unistdio/u8-u8-vasnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to UTF-8 strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-u8-vasprintf.c b/lib/unistdio/u8-u8-vasprintf.c index bb28dc5f..6a3732d0 100644 --- a/lib/unistdio/u8-u8-vasprintf.c +++ b/lib/unistdio/u8-u8-vasprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-u8-vsnprintf.c b/lib/unistdio/u8-u8-vsnprintf.c index f9e99223..2ebb19ae 100644 --- a/lib/unistdio/u8-u8-vsnprintf.c +++ b/lib/unistdio/u8-u8-vsnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-u8-vsprintf.c b/lib/unistdio/u8-u8-vsprintf.c index 9e66018a..ca4c656e 100644 --- a/lib/unistdio/u8-u8-vsprintf.c +++ b/lib/unistdio/u8-u8-vsprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-vasnprintf.c b/lib/unistdio/u8-vasnprintf.c index 0067e6ce..304c54c5 100644 --- a/lib/unistdio/u8-vasnprintf.c +++ b/lib/unistdio/u8-vasnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to UTF-8 strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-vasprintf.c b/lib/unistdio/u8-vasprintf.c index 304d4965..5b7f719d 100644 --- a/lib/unistdio/u8-vasprintf.c +++ b/lib/unistdio/u8-vasprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-vsnprintf.c b/lib/unistdio/u8-vsnprintf.c index 87388e29..4f6f1fa7 100644 --- a/lib/unistdio/u8-vsnprintf.c +++ b/lib/unistdio/u8-vsnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/u8-vsprintf.c b/lib/unistdio/u8-vsprintf.c index aa0b52d2..7397d289 100644 --- a/lib/unistdio/u8-vsprintf.c +++ b/lib/unistdio/u8-vsprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/ulc-asnprintf.c b/lib/unistdio/ulc-asnprintf.c index 31d3f220..5a79c8ca 100644 --- a/lib/unistdio/ulc-asnprintf.c +++ b/lib/unistdio/ulc-asnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/ulc-asprintf.c b/lib/unistdio/ulc-asprintf.c index 4f760e1d..a97a3fef 100644 --- a/lib/unistdio/ulc-asprintf.c +++ b/lib/unistdio/ulc-asprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/ulc-fprintf.c b/lib/unistdio/ulc-fprintf.c index ac8ab6fe..fb2b9e25 100644 --- a/lib/unistdio/ulc-fprintf.c +++ b/lib/unistdio/ulc-fprintf.c @@ -1,5 +1,5 @@ /* Formatted output to a stream. - Copyright (C) 2004, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2004, 2006-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -55,11 +55,11 @@ ulc_fprintf (FILE *fp, const char *format, ...) if (fwrite (output, 1, len, fp) < len) { if (output != buf) - { - int saved_errno = errno; - free (output); - errno = saved_errno; - } + { + int saved_errno = errno; + free (output); + errno = saved_errno; + } return -1; } diff --git a/lib/unistdio/ulc-printf-parse.c b/lib/unistdio/ulc-printf-parse.c index 81af3690..a2e22b2a 100644 --- a/lib/unistdio/ulc-printf-parse.c +++ b/lib/unistdio/ulc-printf-parse.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2010 Free Software + Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/ulc-snprintf.c b/lib/unistdio/ulc-snprintf.c index f774ac04..9b57ada7 100644 --- a/lib/unistdio/ulc-snprintf.c +++ b/lib/unistdio/ulc-snprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/ulc-sprintf.c b/lib/unistdio/ulc-sprintf.c index 466ffb40..a9f3c4ea 100644 --- a/lib/unistdio/ulc-sprintf.c +++ b/lib/unistdio/ulc-sprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2005-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/ulc-vasnprintf.c b/lib/unistdio/ulc-vasnprintf.c index e89b7fff..ef652b99 100644 --- a/lib/unistdio/ulc-vasnprintf.c +++ b/lib/unistdio/ulc-vasnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/ulc-vasprintf.c b/lib/unistdio/ulc-vasprintf.c index 8773ab46..24c77238 100644 --- a/lib/unistdio/ulc-vasprintf.c +++ b/lib/unistdio/ulc-vasprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/ulc-vfprintf.c b/lib/unistdio/ulc-vfprintf.c index 586fe13a..d7140108 100644 --- a/lib/unistdio/ulc-vfprintf.c +++ b/lib/unistdio/ulc-vfprintf.c @@ -1,5 +1,5 @@ /* Formatted output to a stream. - Copyright (C) 2004, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2004, 2006-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -52,11 +52,11 @@ ulc_vfprintf (FILE *fp, const char *format, va_list args) if (fwrite (output, 1, len, fp) < len) { if (output != buf) - { - int saved_errno = errno; - free (output); - errno = saved_errno; - } + { + int saved_errno = errno; + free (output); + errno = saved_errno; + } return -1; } diff --git a/lib/unistdio/ulc-vsnprintf.c b/lib/unistdio/ulc-vsnprintf.c index c1665359..7a43eb27 100644 --- a/lib/unistdio/ulc-vsnprintf.c +++ b/lib/unistdio/ulc-vsnprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistdio/ulc-vsprintf.c b/lib/unistdio/ulc-vsprintf.c index 0cccc05d..9b19a331 100644 --- a/lib/unistdio/ulc-vsprintf.c +++ b/lib/unistdio/ulc-vsprintf.c @@ -1,5 +1,6 @@ /* Formatted output to strings. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/unistr.h b/lib/unistr.h index 01ecc372..4d3c3259 100644 --- a/lib/unistr.h +++ b/lib/unistr.h @@ -1,5 +1,5 @@ /* Elementary Unicode string functions. - Copyright (C) 2001-2002, 2005-2009 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2005-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -19,6 +19,9 @@ #include "unitypes.h" +/* Get common macros for C. */ +#include + /* Get inline if available. */ #include @@ -84,32 +87,32 @@ extern const uint32_t * /* Convert an UTF-8 string to an UTF-16 string. */ extern uint16_t * u8_to_u16 (const uint8_t *s, size_t n, uint16_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UTF-8 string to an UCS-4 string. */ extern uint32_t * u8_to_u32 (const uint8_t *s, size_t n, uint32_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UTF-16 string to an UTF-8 string. */ extern uint8_t * u16_to_u8 (const uint16_t *s, size_t n, uint8_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UTF-16 string to an UCS-4 string. */ extern uint32_t * u16_to_u32 (const uint16_t *s, size_t n, uint32_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UCS-4 string to an UTF-8 string. */ extern uint8_t * u32_to_u8 (const uint32_t *s, size_t n, uint8_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Convert an UCS-4 string to an UTF-16 string. */ extern uint16_t * u32_to_u16 (const uint32_t *s, size_t n, uint16_t *resultbuf, - size_t *lengthp); + size_t *lengthp); /* Elementary string functions. */ @@ -186,7 +189,8 @@ extern int u32_mbtouc_unsafe (ucs4_t *puc, const uint32_t *s, size_t n); # else static inline int -u32_mbtouc_unsafe (ucs4_t *puc, const uint32_t *s, size_t n _UNUSED_PARAMETER_) +u32_mbtouc_unsafe (ucs4_t *puc, + const uint32_t *s, size_t n _GL_UNUSED_PARAMETER) { uint32_t c = *s; @@ -256,7 +260,7 @@ extern int u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n); # else static inline int -u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n _UNUSED_PARAMETER_) +u32_mbtouc (ucs4_t *puc, const uint32_t *s, size_t n _GL_UNUSED_PARAMETER) { uint32_t c = *s; @@ -354,12 +358,12 @@ u32_uctomb (uint32_t *s, ucs4_t uc, int n) if (uc < 0xd800 || (uc >= 0xe000 && uc < 0x110000)) { if (n > 0) - { - *s = uc; - return 1; - } + { + *s = uc; + return 1; + } else - return -2; + return -2; } else return -1; @@ -528,8 +532,8 @@ extern uint16_t * extern uint32_t * u32_strncpy (uint32_t *dest, const uint32_t *src, size_t n); -/* Copy no more than N units of SRC to DEST, returning the address of - the last unit written into DEST. */ +/* Copy no more than N units of SRC to DEST. Return a pointer past the last + non-NUL unit written into DEST. */ /* Similar to stpncpy(). */ extern uint8_t * u8_stpncpy (uint8_t *dest, const uint8_t *src, size_t n); diff --git a/lib/unistr/u-cmp2.h b/lib/unistr/u-cmp2.h index ae3750c4..6058c4a5 100644 --- a/lib/unistr/u-cmp2.h +++ b/lib/unistr/u-cmp2.h @@ -1,5 +1,5 @@ /* Compare pieces of UTF-8/UTF-16/UTF-32 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -23,9 +23,9 @@ FUNC (const UNIT *s1, size_t n1, const UNIT *s2, size_t n2) if (cmp == 0) { if (n1 < n2) - cmp = -1; + cmp = -1; else if (n1 > n2) - cmp = 1; + cmp = 1; } return cmp; diff --git a/lib/unistr/u-cpy-alloc.h b/lib/unistr/u-cpy-alloc.h index dace3e2e..f36a8d03 100644 --- a/lib/unistr/u-cpy-alloc.h +++ b/lib/unistr/u-cpy-alloc.h @@ -1,5 +1,6 @@ /* Copy piece of UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -30,7 +31,7 @@ FUNC (const UNIT *s, size_t n) UNIT *destptr = dest; for (; n > 0; n--) - *destptr++ = *s++; + *destptr++ = *s++; #else memcpy ((char *) dest, (const char *) s, n * sizeof (UNIT)); #endif diff --git a/lib/unistr/u-cpy.h b/lib/unistr/u-cpy.h index c660eae0..6dad9525 100644 --- a/lib/unistr/u-cpy.h +++ b/lib/unistr/u-cpy.h @@ -1,5 +1,5 @@ /* Copy piece of UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u-endswith.h b/lib/unistr/u-endswith.h index 739bfbb1..094a87fb 100644 --- a/lib/unistr/u-endswith.h +++ b/lib/unistr/u-endswith.h @@ -1,5 +1,5 @@ /* Substring test for UTF-8/UTF-16/UTF-32 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u-move.h b/lib/unistr/u-move.h index 77b6788b..d8d58b0a 100644 --- a/lib/unistr/u-move.h +++ b/lib/unistr/u-move.h @@ -1,5 +1,5 @@ /* Copy piece of UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -27,7 +27,7 @@ FUNC (UNIT *dest, const UNIT *src, size_t n) const UNIT *srcptr = src; for (; n > 0; n--) - *destptr++ = *srcptr++; + *destptr++ = *srcptr++; } else if (dest > src) { @@ -35,7 +35,7 @@ FUNC (UNIT *dest, const UNIT *src, size_t n) const UNIT *srcptr = src + n - 1; for (; n > 0; n--) - *destptr-- = *srcptr--; + *destptr-- = *srcptr--; } #else memmove ((char *) dest, (const char *) src, n * sizeof (UNIT)); diff --git a/lib/unistr/u-set.h b/lib/unistr/u-set.h index a093e7f6..de78a8eb 100644 --- a/lib/unistr/u-set.h +++ b/lib/unistr/u-set.h @@ -1,5 +1,5 @@ /* Fill UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -23,17 +23,17 @@ FUNC (UNIT *s, ucs4_t uc, size_t n) if (n > 0) { if (IS_SINGLE_UNIT (uc)) - { - UNIT *ptr = s; + { + UNIT *ptr = s; - for (; n > 0; n--) - *ptr++ = uc; - } + for (; n > 0; n--) + *ptr++ = uc; + } else - { - errno = EILSEQ; - return NULL; - } + { + errno = EILSEQ; + return NULL; + } } return s; } diff --git a/lib/unistr/u-startswith.h b/lib/unistr/u-startswith.h index 0486ef88..16966512 100644 --- a/lib/unistr/u-startswith.h +++ b/lib/unistr/u-startswith.h @@ -1,5 +1,5 @@ /* Substring test for UTF-8/UTF-16/UTF-32 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -23,8 +23,8 @@ FUNC (const UNIT *str, const UNIT *prefix) UNIT uc1 = *str++; UNIT uc2 = *prefix++; if (uc2 == 0) - return true; + return true; if (uc1 != uc2) - return false; + return false; } } diff --git a/lib/unistr/u-stpcpy.h b/lib/unistr/u-stpcpy.h index b13e816f..483f3c2a 100644 --- a/lib/unistr/u-stpcpy.h +++ b/lib/unistr/u-stpcpy.h @@ -1,5 +1,5 @@ /* Copy UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u-stpncpy.h b/lib/unistr/u-stpncpy.h index 09bf434c..4d6dd3c7 100644 --- a/lib/unistr/u-stpncpy.h +++ b/lib/unistr/u-stpncpy.h @@ -1,5 +1,5 @@ /* Copy UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -23,8 +23,12 @@ FUNC (UNIT *dest, const UNIT *src, size_t n) /* This behavior is rarely useful, but it is here for consistency with strncpy and wcsncpy. */ - for (; n > 0; n--) - *dest++ = 0; + { + UNIT *destptr = dest; - return dest - 1; + for (; n > 0; n--) + *destptr++ = 0; + } + + return dest; } diff --git a/lib/unistr/u-strcat.h b/lib/unistr/u-strcat.h index e86bbf99..84430fc9 100644 --- a/lib/unistr/u-strcat.h +++ b/lib/unistr/u-strcat.h @@ -1,5 +1,5 @@ /* Concatenate UTF-8/UTF-16/UTF-32 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u-strcoll.h b/lib/unistr/u-strcoll.h index af404a04..9ec5c601 100644 --- a/lib/unistr/u-strcoll.h +++ b/lib/unistr/u-strcoll.h @@ -1,6 +1,6 @@ /* Compare UTF-8/UTF-16/UTF-32 strings using the collation rules of the current locale. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -32,48 +32,54 @@ FUNC (const UNIT *s1, const UNIT *s2) { sl2 = U_STRCONV_TO_LOCALE (s2); if (sl2 != NULL) - { - /* Compare sl1 and sl2. */ - errno = 0; - result = strcoll (sl1, sl2); - if (errno == 0) - { - /* strcoll succeeded. */ - free (sl1); - free (sl2); - } - else - { - /* strcoll failed. */ - final_errno = errno; - free (sl1); - free (sl2); - result = U_STRCMP (s1, s2); - } - } + { + /* Compare sl1 and sl2. */ + errno = 0; + result = strcoll (sl1, sl2); + if (errno == 0) + { + /* strcoll succeeded. */ + free (sl1); + free (sl2); + /* The conversion to locale encoding can do transliteration or + map some characters to question marks. Therefore sl1 and sl2 + may be equal when s1 and s2 were in fact different. Return a + nonzero result in this case. */ + if (result == 0) + result = U_STRCMP (s1, s2); + } + else + { + /* strcoll failed. */ + final_errno = errno; + free (sl1); + free (sl2); + result = U_STRCMP (s1, s2); + } + } else - { - /* s1 could be converted to locale encoding, s2 not. */ - final_errno = errno; - free (sl1); - result = -1; - } + { + /* s1 could be converted to locale encoding, s2 not. */ + final_errno = errno; + free (sl1); + result = -1; + } } else { final_errno = errno; sl2 = U_STRCONV_TO_LOCALE (s2); if (sl2 != NULL) - { - /* s2 could be converted to locale encoding, s1 not. */ - free (sl2); - result = 1; - } + { + /* s2 could be converted to locale encoding, s1 not. */ + free (sl2); + result = 1; + } else - { - /* Neither s1 nor s2 could be converted to locale encoding. */ - result = U_STRCMP (s1, s2); - } + { + /* Neither s1 nor s2 could be converted to locale encoding. */ + result = U_STRCMP (s1, s2); + } } errno = final_errno; diff --git a/lib/unistr/u-strcpy.h b/lib/unistr/u-strcpy.h index 153f60ec..b059aea4 100644 --- a/lib/unistr/u-strcpy.h +++ b/lib/unistr/u-strcpy.h @@ -1,5 +1,5 @@ /* Copy UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u-strcspn.h b/lib/unistr/u-strcspn.h index de326563..77b95508 100644 --- a/lib/unistr/u-strcspn.h +++ b/lib/unistr/u-strcspn.h @@ -1,5 +1,5 @@ /* Search for some characters in UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -26,11 +26,11 @@ FUNC (const UNIT *str, const UNIT *reject) int count = U_STRMBTOUC (&uc, reject); if (count >= 0 && reject[count] == 0) { - const UNIT *found = U_STRCHR (str, uc); - if (found != NULL) - return found - str; - else - return U_STRLEN (str); + const UNIT *found = U_STRCHR (str, uc); + if (found != NULL) + return found - str; + else + return U_STRLEN (str); } } /* General case. */ @@ -39,15 +39,15 @@ FUNC (const UNIT *str, const UNIT *reject) for (;;) { - ucs4_t uc; - int count = U_STRMBTOUC (&uc, ptr); - if (count == 0) - return ptr - str; - if (count < 0) - break; - if (U_STRCHR (reject, uc)) - return ptr - str; - ptr += count; + ucs4_t uc; + int count = U_STRMBTOUC (&uc, ptr); + if (count == 0) + return ptr - str; + if (count < 0) + break; + if (U_STRCHR (reject, uc)) + return ptr - str; + ptr += count; } return U_STRLEN (str); } diff --git a/lib/unistr/u-strdup.h b/lib/unistr/u-strdup.h index 71e527a7..a92e1efa 100644 --- a/lib/unistr/u-strdup.h +++ b/lib/unistr/u-strdup.h @@ -1,5 +1,6 @@ /* Copy UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,7 +32,7 @@ FUNC (const UNIT *s) UNIT *destptr = dest; for (; n > 0; n--) - *destptr++ = *s++; + *destptr++ = *s++; #else memcpy ((char *) dest, (const char *) s, n * sizeof (UNIT)); #endif diff --git a/lib/unistr/u-strlen.h b/lib/unistr/u-strlen.h index 51dcae00..a54d614c 100644 --- a/lib/unistr/u-strlen.h +++ b/lib/unistr/u-strlen.h @@ -1,5 +1,5 @@ /* Determine length of UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u-strncat.h b/lib/unistr/u-strncat.h index 40b442ec..e5c9a045 100644 --- a/lib/unistr/u-strncat.h +++ b/lib/unistr/u-strncat.h @@ -1,5 +1,5 @@ /* Concatenate UTF-8/UTF-16/UTF-32 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u-strncpy.h b/lib/unistr/u-strncpy.h index 3d441b51..55a4f672 100644 --- a/lib/unistr/u-strncpy.h +++ b/lib/unistr/u-strncpy.h @@ -1,5 +1,5 @@ /* Copy UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u-strnlen.h b/lib/unistr/u-strnlen.h index 6a1d2ad2..9bcc3da3 100644 --- a/lib/unistr/u-strnlen.h +++ b/lib/unistr/u-strnlen.h @@ -1,5 +1,5 @@ /* Determine bounded length of UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u-strpbrk.h b/lib/unistr/u-strpbrk.h index 2ff46182..34aabc53 100644 --- a/lib/unistr/u-strpbrk.h +++ b/lib/unistr/u-strpbrk.h @@ -1,5 +1,5 @@ /* Search for some characters in UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -33,13 +33,13 @@ FUNC (const UNIT *str, const UNIT *accept) for (;;) { - ucs4_t uc; - int count = U_STRMBTOUC (&uc, ptr); - if (count <= 0) - break; - if (U_STRCHR (accept, uc)) - return (UNIT *) ptr; - ptr += count; + ucs4_t uc; + int count = U_STRMBTOUC (&uc, ptr); + if (count <= 0) + break; + if (U_STRCHR (accept, uc)) + return (UNIT *) ptr; + ptr += count; } return NULL; } diff --git a/lib/unistr/u-strspn.h b/lib/unistr/u-strspn.h index 6502ce4b..d6669af8 100644 --- a/lib/unistr/u-strspn.h +++ b/lib/unistr/u-strspn.h @@ -1,5 +1,5 @@ /* Search for some characters in UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -26,11 +26,11 @@ FUNC (const UNIT *str, const UNIT *accept) int count = U_STRMBTOUC (&uc, accept); if (count >= 0 && accept[count] == 0) { - const UNIT *ptr = str; - for (; *ptr != 0; ptr += count) - if (U_CMP (ptr, accept, count) != 0) - break; - return ptr - str; + const UNIT *ptr = str; + for (; *ptr != 0; ptr += count) + if (U_CMP (ptr, accept, count) != 0) + break; + return ptr - str; } } /* General case. */ @@ -39,15 +39,15 @@ FUNC (const UNIT *str, const UNIT *accept) for (;;) { - ucs4_t uc; - int count = U_STRMBTOUC (&uc, ptr); - if (count == 0) - return ptr - str; - if (count < 0) - break; - if (!U_STRCHR (accept, uc)) - return ptr - str; - ptr += count; + ucs4_t uc; + int count = U_STRMBTOUC (&uc, ptr); + if (count == 0) + return ptr - str; + if (count < 0) + break; + if (!U_STRCHR (accept, uc)) + return ptr - str; + ptr += count; } return U_STRLEN (str); } diff --git a/lib/unistr/u-strstr.h b/lib/unistr/u-strstr.h index 55b5a31d..df32be8b 100644 --- a/lib/unistr/u-strstr.h +++ b/lib/unistr/u-strstr.h @@ -1,5 +1,5 @@ /* Substring test for UTF-8/UTF-16/UTF-32 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -32,17 +32,17 @@ FUNC (const UNIT *haystack, const UNIT *needle) for (; *haystack != 0; haystack++) if (*haystack == first) { - /* Compare with needle's remaining units. */ - const UNIT *hptr = haystack + 1; - const UNIT *nptr = needle + 1; - for (;;) - { - if (*hptr != *nptr) - break; - hptr++; nptr++; - if (*nptr == 0) - return (UNIT *) haystack; - } + /* Compare with needle's remaining units. */ + const UNIT *hptr = haystack + 1; + const UNIT *nptr = needle + 1; + for (;;) + { + if (*hptr != *nptr) + break; + hptr++; nptr++; + if (*nptr == 0) + return (UNIT *) haystack; + } } return NULL; diff --git a/lib/unistr/u-strtok.h b/lib/unistr/u-strtok.h index 7ed57d6f..7fdef578 100644 --- a/lib/unistr/u-strtok.h +++ b/lib/unistr/u-strtok.h @@ -1,5 +1,5 @@ /* Tokenize UTF-8/UTF-16/UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -22,7 +22,7 @@ FUNC (UNIT *str, const UNIT *delim, UNIT **ptr) { str = *ptr; if (str == NULL) - return NULL; /* reminder that end of token sequence has been reached */ + return NULL; /* reminder that end of token sequence has been reached */ } /* Skip leading delimiters. */ @@ -40,9 +40,9 @@ FUNC (UNIT *str, const UNIT *delim, UNIT **ptr) UNIT *token_end = U_STRPBRK (str, delim); if (token_end) { - /* NUL-terminate the token. */ - *token_end = 0; - *ptr = token_end + 1; + /* NUL-terminate the token. */ + *token_end = 0; + *ptr = token_end + 1; } else *ptr = NULL; diff --git a/lib/unistr/u16-check.c b/lib/unistr/u16-check.c index 380cec2c..4f18383b 100644 --- a/lib/unistr/u16-check.c +++ b/lib/unistr/u16-check.c @@ -1,5 +1,5 @@ /* Check UTF-16 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,19 +31,19 @@ u16_check (const uint16_t *s, size_t n) uint16_t c = *s; if (c < 0xd800 || c >= 0xe000) - { - s++; - continue; - } + { + s++; + continue; + } if (c < 0xdc00) - { - if (s + 2 <= s_end - && s[1] >= 0xdc00 && s[1] < 0xe000) - { - s += 2; - continue; - } - } + { + if (s + 2 <= s_end + && s[1] >= 0xdc00 && s[1] < 0xe000) + { + s += 2; + continue; + } + } /* invalid or incomplete multibyte character */ return s; } diff --git a/lib/unistr/u16-chr.c b/lib/unistr/u16-chr.c index 2d7d797e..13deef4d 100644 --- a/lib/unistr/u16-chr.c +++ b/lib/unistr/u16-chr.c @@ -1,5 +1,6 @@ /* Search character in piece of UTF-16 string. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -30,27 +31,27 @@ u16_chr (const uint16_t *s, size_t n, ucs4_t uc) uint16_t c0 = uc; for (; n > 0; s++, n--) - { - if (*s == c0) - return (uint16_t *) s; - } + { + if (*s == c0) + return (uint16_t *) s; + } } else switch (u16_uctomb_aux (c, uc, 2)) { case 2: - if (n > 1) - { - uint16_t c0 = c[0]; - uint16_t c1 = c[1]; - - for (n--; n > 0; s++, n--) - { - if (*s == c0 && s[1] == c1) - return (uint16_t *) s; - } - } - break; + if (n > 1) + { + uint16_t c0 = c[0]; + uint16_t c1 = c[1]; + + for (n--; n > 0; s++, n--) + { + if (*s == c0 && s[1] == c1) + return (uint16_t *) s; + } + } + break; } return NULL; } diff --git a/lib/unistr/u16-cmp.c b/lib/unistr/u16-cmp.c index 0130d271..b71c1c34 100644 --- a/lib/unistr/u16-cmp.c +++ b/lib/unistr/u16-cmp.c @@ -1,5 +1,5 @@ /* Compare pieces of UTF-16 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,22 +31,22 @@ u16_cmp (const uint16_t *s1, const uint16_t *s2, size_t n) uint16_t c1 = *s1++; uint16_t c2 = *s2++; if (c1 == c2) - { - n--; - continue; - } + { + n--; + continue; + } if (c1 < 0xd800 || c1 >= 0xe000) - { - if (!(c2 < 0xd800 || c2 >= 0xe000)) - /* c2 is a surrogate, but c1 is not. */ - return -1; - } + { + if (!(c2 < 0xd800 || c2 >= 0xe000)) + /* c2 is a surrogate, but c1 is not. */ + return -1; + } else - { - if (c2 < 0xd800 || c2 >= 0xe000) - /* c1 is a surrogate, but c2 is not. */ - return 1; - } + { + if (c2 < 0xd800 || c2 >= 0xe000) + /* c1 is a surrogate, but c2 is not. */ + return 1; + } return (int)c1 - (int)c2; /* > 0 if c1 > c2, < 0 if c1 < c2. */ } diff --git a/lib/unistr/u16-cmp2.c b/lib/unistr/u16-cmp2.c index 766dcd2d..8c2a8d6e 100644 --- a/lib/unistr/u16-cmp2.c +++ b/lib/unistr/u16-cmp2.c @@ -1,5 +1,5 @@ /* Compare pieces of UTF-16 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-cpy-alloc.c b/lib/unistr/u16-cpy-alloc.c index 047977eb..33984f9c 100644 --- a/lib/unistr/u16-cpy-alloc.c +++ b/lib/unistr/u16-cpy-alloc.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-cpy.c b/lib/unistr/u16-cpy.c index 13e04b81..614d24c4 100644 --- a/lib/unistr/u16-cpy.c +++ b/lib/unistr/u16-cpy.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-endswith.c b/lib/unistr/u16-endswith.c index d9abf464..27dcd5aa 100644 --- a/lib/unistr/u16-endswith.c +++ b/lib/unistr/u16-endswith.c @@ -1,5 +1,5 @@ /* Substring test for UTF-16 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-mblen.c b/lib/unistr/u16-mblen.c index 6bb35ac8..9e7a93a1 100644 --- a/lib/unistr/u16-mblen.c +++ b/lib/unistr/u16-mblen.c @@ -1,5 +1,6 @@ /* Look at first character in UTF-16 string. - Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2010 Free Software + Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -29,19 +30,19 @@ u16_mblen (const uint16_t *s, size_t n) uint16_t c = *s; if (c < 0xd800 || c >= 0xe000) - return (c != 0 ? 1 : 0); + return (c != 0 ? 1 : 0); #if CONFIG_UNICODE_SAFETY if (c < 0xdc00) - { - if (n >= 2 - && s[1] >= 0xdc00 && s[1] < 0xe000) - return 2; - } + { + if (n >= 2 + && s[1] >= 0xdc00 && s[1] < 0xe000) + return 2; + } #else - { - if (n >= 2) - return 2; - } + { + if (n >= 2) + return 2; + } #endif } /* invalid or incomplete multibyte character */ diff --git a/lib/unistr/u16-mbsnlen.c b/lib/unistr/u16-mbsnlen.c index 881958e1..601d81d6 100644 --- a/lib/unistr/u16-mbsnlen.c +++ b/lib/unistr/u16-mbsnlen.c @@ -1,5 +1,5 @@ /* Count characters in UTF-16 string. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it @@ -28,12 +28,15 @@ u16_mbsnlen (const uint16_t *s, size_t n) characters = 0; while (n > 0) { - int count = u16_mblen (s, n); + ucs4_t uc; + int count = u16_mbtoucr (&uc, s, n); + characters++; + if (count == -2) + break; if (count <= 0) - count = 1; + count = 1; s += count; n -= count; - characters++; } return characters; } diff --git a/lib/unistr/u16-mbtouc-aux.c b/lib/unistr/u16-mbtouc-aux.c index 5f35b867..bee77fcf 100644 --- a/lib/unistr/u16-mbtouc-aux.c +++ b/lib/unistr/u16-mbtouc-aux.c @@ -1,5 +1,5 @@ /* Conversion UTF-16 to UCS-4. - Copyright (C) 2001-2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -30,18 +30,18 @@ u16_mbtouc_aux (ucs4_t *puc, const uint16_t *s, size_t n) if (c < 0xdc00) { if (n >= 2) - { - if (s[1] >= 0xdc00 && s[1] < 0xe000) - { - *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); - return 2; - } - /* invalid multibyte character */ - } + { + if (s[1] >= 0xdc00 && s[1] < 0xe000) + { + *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); + return 2; + } + /* invalid multibyte character */ + } else - { - /* incomplete multibyte character */ - } + { + /* incomplete multibyte character */ + } } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u16-mbtouc-unsafe-aux.c b/lib/unistr/u16-mbtouc-unsafe-aux.c index 9906e301..f2d72259 100644 --- a/lib/unistr/u16-mbtouc-unsafe-aux.c +++ b/lib/unistr/u16-mbtouc-unsafe-aux.c @@ -1,5 +1,5 @@ /* Conversion UTF-16 to UCS-4. - Copyright (C) 2001-2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -32,20 +32,20 @@ u16_mbtouc_unsafe_aux (ucs4_t *puc, const uint16_t *s, size_t n) #endif { if (n >= 2) - { + { #if CONFIG_UNICODE_SAFETY - if (s[1] >= 0xdc00 && s[1] < 0xe000) + if (s[1] >= 0xdc00 && s[1] < 0xe000) #endif - { - *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); - return 2; - } - /* invalid multibyte character */ - } + { + *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); + return 2; + } + /* invalid multibyte character */ + } else - { - /* incomplete multibyte character */ - } + { + /* incomplete multibyte character */ + } } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u16-mbtouc-unsafe.c b/lib/unistr/u16-mbtouc-unsafe.c index cc858d88..a5a3638b 100644 --- a/lib/unistr/u16-mbtouc-unsafe.c +++ b/lib/unistr/u16-mbtouc-unsafe.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-16 string. - Copyright (C) 1999-2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -43,20 +43,20 @@ u16_mbtouc_unsafe (ucs4_t *puc, const uint16_t *s, size_t n) #endif { if (n >= 2) - { + { #if CONFIG_UNICODE_SAFETY - if (s[1] >= 0xdc00 && s[1] < 0xe000) + if (s[1] >= 0xdc00 && s[1] < 0xe000) #endif - { - *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); - return 2; - } - /* invalid multibyte character */ - } + { + *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); + return 2; + } + /* invalid multibyte character */ + } else - { - /* incomplete multibyte character */ - } + { + /* incomplete multibyte character */ + } } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u16-mbtouc.c b/lib/unistr/u16-mbtouc.c index 2691db83..26b60890 100644 --- a/lib/unistr/u16-mbtouc.c +++ b/lib/unistr/u16-mbtouc.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-16 string. - Copyright (C) 1999-2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -40,18 +40,18 @@ u16_mbtouc (ucs4_t *puc, const uint16_t *s, size_t n) if (c < 0xdc00) { if (n >= 2) - { - if (s[1] >= 0xdc00 && s[1] < 0xe000) - { - *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); - return 2; - } - /* invalid multibyte character */ - } + { + if (s[1] >= 0xdc00 && s[1] < 0xe000) + { + *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); + return 2; + } + /* invalid multibyte character */ + } else - { - /* incomplete multibyte character */ - } + { + /* incomplete multibyte character */ + } } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u16-mbtoucr.c b/lib/unistr/u16-mbtoucr.c index a1bd8ee9..00b7b708 100644 --- a/lib/unistr/u16-mbtoucr.c +++ b/lib/unistr/u16-mbtoucr.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-16 string, returning an error code. - Copyright (C) 1999-2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -33,20 +33,20 @@ u16_mbtoucr (ucs4_t *puc, const uint16_t *s, size_t n) if (c < 0xdc00) { if (n >= 2) - { - if (s[1] >= 0xdc00 && s[1] < 0xe000) - { - *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); - return 2; - } - /* invalid multibyte character */ - } + { + if (s[1] >= 0xdc00 && s[1] < 0xe000) + { + *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); + return 2; + } + /* invalid multibyte character */ + } else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u16-move.c b/lib/unistr/u16-move.c index 2bf8c619..f6efb888 100644 --- a/lib/unistr/u16-move.c +++ b/lib/unistr/u16-move.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-next.c b/lib/unistr/u16-next.c index 7c49f72f..8245f11a 100644 --- a/lib/unistr/u16-next.c +++ b/lib/unistr/u16-next.c @@ -1,5 +1,5 @@ /* Iterate over next character in UTF-16 string. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,7 +31,7 @@ u16_next (ucs4_t *puc, const uint16_t *s) else { if (count < 0) - *puc = 0xfffd; + *puc = 0xfffd; return NULL; } } diff --git a/lib/unistr/u16-prev.c b/lib/unistr/u16-prev.c index 3beecf01..4c902ad2 100644 --- a/lib/unistr/u16-prev.c +++ b/lib/unistr/u16-prev.c @@ -1,5 +1,5 @@ /* Iterate over previous character in UTF-16 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -29,25 +29,25 @@ u16_prev (ucs4_t *puc, const uint16_t *s, const uint16_t *start) uint16_t c_1 = s[-1]; if (c_1 < 0xd800 || c_1 >= 0xe000) - { - *puc = c_1; - return s - 1; - } + { + *puc = c_1; + return s - 1; + } #if CONFIG_UNICODE_SAFETY if (c_1 >= 0xdc00) #endif - if (s - 1 != start) - { - uint16_t c_2 = s[-2]; + if (s - 1 != start) + { + uint16_t c_2 = s[-2]; #if CONFIG_UNICODE_SAFETY - if (c_2 >= 0xd800 && c_2 < 0xdc00) + if (c_2 >= 0xd800 && c_2 < 0xdc00) #endif - { - *puc = 0x10000 + ((c_2 - 0xd800) << 10) + (c_1 - 0xdc00); - return s - 2; - } - } + { + *puc = 0x10000 + ((c_2 - 0xd800) << 10) + (c_1 - 0xdc00); + return s - 2; + } + } } return NULL; } diff --git a/lib/unistr/u16-set.c b/lib/unistr/u16-set.c index 9ef307f2..7bad3d61 100644 --- a/lib/unistr/u16-set.c +++ b/lib/unistr/u16-set.c @@ -1,5 +1,5 @@ /* Fill UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-startswith.c b/lib/unistr/u16-startswith.c index 2f39d74f..22a5d5fe 100644 --- a/lib/unistr/u16-startswith.c +++ b/lib/unistr/u16-startswith.c @@ -1,5 +1,5 @@ /* Substring test for UTF-16 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-stpcpy.c b/lib/unistr/u16-stpcpy.c index 9207edc1..59467f7a 100644 --- a/lib/unistr/u16-stpcpy.c +++ b/lib/unistr/u16-stpcpy.c @@ -1,5 +1,6 @@ /* Copy UTF-16 string. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-stpncpy.c b/lib/unistr/u16-stpncpy.c index 30ef7e30..49c616ef 100644 --- a/lib/unistr/u16-stpncpy.c +++ b/lib/unistr/u16-stpncpy.c @@ -1,5 +1,5 @@ /* Copy UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strcat.c b/lib/unistr/u16-strcat.c index bb88f1b5..8b358683 100644 --- a/lib/unistr/u16-strcat.c +++ b/lib/unistr/u16-strcat.c @@ -1,5 +1,5 @@ /* Concatenate UTF-16 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strchr.c b/lib/unistr/u16-strchr.c index 673152f9..1f8719fa 100644 --- a/lib/unistr/u16-strchr.c +++ b/lib/unistr/u16-strchr.c @@ -1,5 +1,6 @@ /* Search character in UTF-16 string. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -30,33 +31,33 @@ u16_strchr (const uint16_t *s, ucs4_t uc) uint16_t c0 = uc; for (;; s++) - { - if (*s == c0) - break; - if (*s == 0) - goto notfound; - } + { + if (*s == c0) + break; + if (*s == 0) + goto notfound; + } return (uint16_t *) s; } else switch (u16_uctomb_aux (c, uc, 2)) { case 2: - if (*s == 0) - goto notfound; - { - uint16_t c0 = c[0]; - uint16_t c1 = c[1]; - - for (;; s++) - { - if (s[1] == 0) - goto notfound; - if (*s == c0 && s[1] == c1) - break; - } - return (uint16_t *) s; - } + if (*s == 0) + goto notfound; + { + uint16_t c0 = c[0]; + uint16_t c1 = c[1]; + + for (;; s++) + { + if (s[1] == 0) + goto notfound; + if (*s == c0 && s[1] == c1) + break; + } + return (uint16_t *) s; + } } notfound: return NULL; diff --git a/lib/unistr/u16-strcmp.c b/lib/unistr/u16-strcmp.c index c161c65b..b781211a 100644 --- a/lib/unistr/u16-strcmp.c +++ b/lib/unistr/u16-strcmp.c @@ -1,5 +1,5 @@ /* Compare UTF-16 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,19 +31,19 @@ u16_strcmp (const uint16_t *s1, const uint16_t *s2) uint16_t c1 = *s1++; uint16_t c2 = *s2++; if (c1 != 0 && c1 == c2) - continue; + continue; if (c1 < 0xd800 || c1 >= 0xe000) - { - if (!(c2 < 0xd800 || c2 >= 0xe000)) - /* c2 is a surrogate, but c1 is not. */ - return -1; - } + { + if (!(c2 < 0xd800 || c2 >= 0xe000)) + /* c2 is a surrogate, but c1 is not. */ + return -1; + } else - { - if (c2 < 0xd800 || c2 >= 0xe000) - /* c1 is a surrogate, but c2 is not. */ - return 1; - } + { + if (c2 < 0xd800 || c2 >= 0xe000) + /* c1 is a surrogate, but c2 is not. */ + return 1; + } return (int)c1 - (int)c2; /* > 0 if c1 > c2, < 0 if c1 < c2. */ } diff --git a/lib/unistr/u16-strcoll.c b/lib/unistr/u16-strcoll.c index 280ba83e..5a504bf4 100644 --- a/lib/unistr/u16-strcoll.c +++ b/lib/unistr/u16-strcoll.c @@ -1,5 +1,5 @@ /* Compare UTF-16 strings using the collation rules of the current locale. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strcpy.c b/lib/unistr/u16-strcpy.c index 92c3e7ec..ecde75da 100644 --- a/lib/unistr/u16-strcpy.c +++ b/lib/unistr/u16-strcpy.c @@ -1,5 +1,5 @@ /* Copy UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strcspn.c b/lib/unistr/u16-strcspn.c index 2f5ba435..b18bb374 100644 --- a/lib/unistr/u16-strcspn.c +++ b/lib/unistr/u16-strcspn.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strdup.c b/lib/unistr/u16-strdup.c index 22242c29..4a944513 100644 --- a/lib/unistr/u16-strdup.c +++ b/lib/unistr/u16-strdup.c @@ -1,5 +1,5 @@ /* Copy UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strlen.c b/lib/unistr/u16-strlen.c index 9c05541c..da613c2e 100644 --- a/lib/unistr/u16-strlen.c +++ b/lib/unistr/u16-strlen.c @@ -1,5 +1,5 @@ /* Determine length of UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strmblen.c b/lib/unistr/u16-strmblen.c index e7f36250..f07ca0b9 100644 --- a/lib/unistr/u16-strmblen.c +++ b/lib/unistr/u16-strmblen.c @@ -1,5 +1,6 @@ /* Look at first character in UTF-16 string. - Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2010 Free Software + Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -32,7 +33,7 @@ u16_strmblen (const uint16_t *s) if (c < 0xdc00) { if (s[1] >= 0xdc00 && s[1] < 0xe000) - return 2; + return 2; } #else if (s[1] != 0) diff --git a/lib/unistr/u16-strmbtouc.c b/lib/unistr/u16-strmbtouc.c index 78d482ee..9aa5d43c 100644 --- a/lib/unistr/u16-strmbtouc.c +++ b/lib/unistr/u16-strmbtouc.c @@ -1,5 +1,6 @@ /* Look at first character in UTF-16 string. - Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2010 Free Software + Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -40,10 +41,10 @@ u16_strmbtouc (ucs4_t *puc, const uint16_t *s) #else if (s[1] != 0) #endif - { - *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); - return 2; - } + { + *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); + return 2; + } } /* invalid or incomplete multibyte character */ return -1; diff --git a/lib/unistr/u16-strncat.c b/lib/unistr/u16-strncat.c index 9e14388c..70827160 100644 --- a/lib/unistr/u16-strncat.c +++ b/lib/unistr/u16-strncat.c @@ -1,5 +1,5 @@ /* Concatenate UTF-16 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strncmp.c b/lib/unistr/u16-strncmp.c index 7278b6f0..3ed59c37 100644 --- a/lib/unistr/u16-strncmp.c +++ b/lib/unistr/u16-strncmp.c @@ -1,5 +1,5 @@ /* Compare UTF-16 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,22 +31,22 @@ u16_strncmp (const uint16_t *s1, const uint16_t *s2, size_t n) uint16_t c1 = *s1++; uint16_t c2 = *s2++; if (c1 != 0 && c1 == c2) - { - n--; - continue; - } + { + n--; + continue; + } if (c1 < 0xd800 || c1 >= 0xe000) - { - if (!(c2 < 0xd800 || c2 >= 0xe000)) - /* c2 is a surrogate, but c1 is not. */ - return -1; - } + { + if (!(c2 < 0xd800 || c2 >= 0xe000)) + /* c2 is a surrogate, but c1 is not. */ + return -1; + } else - { - if (c2 < 0xd800 || c2 >= 0xe000) - /* c1 is a surrogate, but c2 is not. */ - return 1; - } + { + if (c2 < 0xd800 || c2 >= 0xe000) + /* c1 is a surrogate, but c2 is not. */ + return 1; + } return (int)c1 - (int)c2; /* > 0 if c1 > c2, < 0 if c1 < c2, = 0 if c1 and c2 are both 0. */ } diff --git a/lib/unistr/u16-strncpy.c b/lib/unistr/u16-strncpy.c index 65676aaa..bd2eb6f6 100644 --- a/lib/unistr/u16-strncpy.c +++ b/lib/unistr/u16-strncpy.c @@ -1,5 +1,5 @@ /* Copy UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strnlen.c b/lib/unistr/u16-strnlen.c index 1cd80c41..49e6d58c 100644 --- a/lib/unistr/u16-strnlen.c +++ b/lib/unistr/u16-strnlen.c @@ -1,5 +1,5 @@ /* Determine bounded length of UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strpbrk.c b/lib/unistr/u16-strpbrk.c index 63605819..45353fa0 100644 --- a/lib/unistr/u16-strpbrk.c +++ b/lib/unistr/u16-strpbrk.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strrchr.c b/lib/unistr/u16-strrchr.c index b3c7ab03..3cf3de2a 100644 --- a/lib/unistr/u16-strrchr.c +++ b/lib/unistr/u16-strrchr.c @@ -1,5 +1,6 @@ /* Search character in UTF-16 string. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -33,32 +34,32 @@ u16_strrchr (const uint16_t *s, ucs4_t uc) uint16_t c0 = uc; for (;; s++) - { - if (*s == c0) - result = (uint16_t *) s; - if (*s == 0) - break; - } + { + if (*s == c0) + result = (uint16_t *) s; + if (*s == 0) + break; + } } else switch (u16_uctomb_aux (c, uc, 2)) { case 2: - if (*s) - { - uint16_t c0 = c[0]; - uint16_t c1 = c[1]; + if (*s) + { + uint16_t c0 = c[0]; + uint16_t c1 = c[1]; - /* FIXME: Maybe walking the string via u16_mblen is a win? */ - for (;; s++) - { - if (s[1] == 0) - break; - if (*s == c0 && s[1] == c1) - result = (uint16_t *) s; - } - } - break; + /* FIXME: Maybe walking the string via u16_mblen is a win? */ + for (;; s++) + { + if (s[1] == 0) + break; + if (*s == c0 && s[1] == c1) + result = (uint16_t *) s; + } + } + break; } return result; } diff --git a/lib/unistr/u16-strspn.c b/lib/unistr/u16-strspn.c index 04ba8e69..ab812ebc 100644 --- a/lib/unistr/u16-strspn.c +++ b/lib/unistr/u16-strspn.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strstr.c b/lib/unistr/u16-strstr.c index bc61233d..54a74d62 100644 --- a/lib/unistr/u16-strstr.c +++ b/lib/unistr/u16-strstr.c @@ -1,5 +1,5 @@ /* Substring test for UTF-16 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-strtok.c b/lib/unistr/u16-strtok.c index dd9b247d..f84c4655 100644 --- a/lib/unistr/u16-strtok.c +++ b/lib/unistr/u16-strtok.c @@ -1,5 +1,5 @@ /* Tokenize UTF-16 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u16-to-u32.c b/lib/unistr/u16-to-u32.c index 2f39dcd7..3544cde3 100644 --- a/lib/unistr/u16-to-u32.c +++ b/lib/unistr/u16-to-u32.c @@ -1,5 +1,5 @@ /* Convert UTF-16 string to UTF-32 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -58,57 +58,57 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) int count; /* Fetch a Unicode character from the input string. */ - count = u16_mbtouc (&uc, s, s_end - s); + count = u16_mbtoucr (&uc, s, s_end - s); if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } s += count; /* Store it in the output string. */ if (length + 1 > allocated) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 1 > allocated) - allocated = length + 1; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 1 > allocated) + allocated = length + 1; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + } result[length++] = uc; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -117,7 +117,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unistr/u16-to-u8.c b/lib/unistr/u16-to-u8.c index 38b27ec0..f92cc930 100644 --- a/lib/unistr/u16-to-u8.c +++ b/lib/unistr/u16-to-u8.c @@ -1,5 +1,5 @@ /* Convert UTF-16 string to UTF-8 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -58,68 +58,68 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) int count; /* Fetch a Unicode character from the input string. */ - count = u16_mbtouc (&uc, s, s_end - s); + count = u16_mbtoucr (&uc, s, s_end - s); if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } s += count; /* Store it in the output string. */ count = u8_uctomb (result + length, uc, allocated - length); if (count == -1) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } if (count == -2) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 6 > allocated) - allocated = length + 6; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - count = u8_uctomb (result + length, uc, allocated - length); - if (count < 0) - abort (); - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 6 > allocated) + allocated = length + 6; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + count = u8_uctomb (result + length, uc, allocated - length); + if (count < 0) + abort (); + } length += count; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -128,7 +128,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unistr/u16-uctomb-aux.c b/lib/unistr/u16-uctomb-aux.c index 384452ba..e2acc9ee 100644 --- a/lib/unistr/u16-uctomb-aux.c +++ b/lib/unistr/u16-uctomb-aux.c @@ -1,5 +1,5 @@ /* Conversion UCS-4 to UTF-16. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -30,29 +30,29 @@ u16_uctomb_aux (uint16_t *s, ucs4_t uc, int n) else if (uc < 0x10000) { if (uc >= 0xe000) - { - if (n >= 1) - { - s[0] = uc; - return 1; - } - } + { + if (n >= 1) + { + s[0] = uc; + return 1; + } + } else - return -1; + return -1; } else { if (uc < 0x110000) - { - if (n >= 2) - { - s[0] = 0xd800 + ((uc - 0x10000) >> 10); - s[1] = 0xdc00 + ((uc - 0x10000) & 0x3ff); - return 2; - } - } + { + if (n >= 2) + { + s[0] = 0xd800 + ((uc - 0x10000) >> 10); + s[1] = 0xdc00 + ((uc - 0x10000) & 0x3ff); + return 2; + } + } else - return -1; + return -1; } return -2; } diff --git a/lib/unistr/u16-uctomb.c b/lib/unistr/u16-uctomb.c index 6ac5ada5..cbc1abcf 100644 --- a/lib/unistr/u16-uctomb.c +++ b/lib/unistr/u16-uctomb.c @@ -1,5 +1,5 @@ /* Store a character in UTF-16 string. - Copyright (C) 2002, 2005-2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -33,38 +33,38 @@ u16_uctomb (uint16_t *s, ucs4_t uc, int n) if (uc < 0xd800) { if (n > 0) - { - s[0] = uc; - return 1; - } + { + s[0] = uc; + return 1; + } /* else return -2, below. */ } else if (uc < 0x10000) { if (uc >= 0xe000) - { - if (n >= 1) - { - s[0] = uc; - return 1; - } - } + { + if (n >= 1) + { + s[0] = uc; + return 1; + } + } else - return -1; + return -1; } else { if (uc < 0x110000) - { - if (n >= 2) - { - s[0] = 0xd800 + ((uc - 0x10000) >> 10); - s[1] = 0xdc00 + ((uc - 0x10000) & 0x3ff); - return 2; - } - } + { + if (n >= 2) + { + s[0] = 0xd800 + ((uc - 0x10000) >> 10); + s[1] = 0xdc00 + ((uc - 0x10000) & 0x3ff); + return 2; + } + } else - return -1; + return -1; } return -2; } diff --git a/lib/unistr/u32-check.c b/lib/unistr/u32-check.c index 87e91271..8c5f5180 100644 --- a/lib/unistr/u32-check.c +++ b/lib/unistr/u32-check.c @@ -1,5 +1,5 @@ /* Check UTF-32 string. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -30,10 +30,10 @@ u32_check (const uint32_t *s, size_t n) uint32_t c = *s; if (c < 0xd800 || (c >= 0xe000 && c < 0x110000)) - s++; + s++; else - /* invalid Unicode character */ - return s; + /* invalid Unicode character */ + return s; } return NULL; } diff --git a/lib/unistr/u32-chr.c b/lib/unistr/u32-chr.c index 5a594b25..19002889 100644 --- a/lib/unistr/u32-chr.c +++ b/lib/unistr/u32-chr.c @@ -1,5 +1,5 @@ /* Search character in piece of UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -26,7 +26,7 @@ u32_chr (const uint32_t *s, size_t n, ucs4_t uc) for (; n > 0; s++, n--) { if (*s == uc) - return (uint32_t *) s; + return (uint32_t *) s; } return NULL; } diff --git a/lib/unistr/u32-cmp.c b/lib/unistr/u32-cmp.c index a273b10b..36496f74 100644 --- a/lib/unistr/u32-cmp.c +++ b/lib/unistr/u32-cmp.c @@ -1,5 +1,5 @@ /* Compare pieces of UTF-32 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -28,10 +28,10 @@ u32_cmp (const uint32_t *s1, const uint32_t *s2, size_t n) uint32_t uc1 = *s1++; uint32_t uc2 = *s2++; if (uc1 == uc2) - { - n--; - continue; - } + { + n--; + continue; + } /* Note that uc1 and uc2 each have at most 31 bits. */ return (int)uc1 - (int)uc2; /* > 0 if uc1 > uc2, < 0 if uc1 < uc2. */ diff --git a/lib/unistr/u32-cmp2.c b/lib/unistr/u32-cmp2.c index 6924c482..32476025 100644 --- a/lib/unistr/u32-cmp2.c +++ b/lib/unistr/u32-cmp2.c @@ -1,5 +1,5 @@ /* Compare pieces of UTF-32 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-cpy-alloc.c b/lib/unistr/u32-cpy-alloc.c index f9c69608..b9ebefe0 100644 --- a/lib/unistr/u32-cpy-alloc.c +++ b/lib/unistr/u32-cpy-alloc.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-cpy.c b/lib/unistr/u32-cpy.c index 2493b65a..747430be 100644 --- a/lib/unistr/u32-cpy.c +++ b/lib/unistr/u32-cpy.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-endswith.c b/lib/unistr/u32-endswith.c index d77fa8cf..cee0d939 100644 --- a/lib/unistr/u32-endswith.c +++ b/lib/unistr/u32-endswith.c @@ -1,5 +1,5 @@ /* Substring test for UTF-32 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-mblen.c b/lib/unistr/u32-mblen.c index a48c8b21..4530fe42 100644 --- a/lib/unistr/u32-mblen.c +++ b/lib/unistr/u32-mblen.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-32 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -30,7 +30,7 @@ u32_mblen (const uint32_t *s, size_t n) #if CONFIG_UNICODE_SAFETY if (c < 0xd800 || (c >= 0xe000 && c < 0x110000)) #endif - return (c != 0 ? 1 : 0); + return (c != 0 ? 1 : 0); } /* invalid or incomplete multibyte character */ return -1; diff --git a/lib/unistr/u32-mbsnlen.c b/lib/unistr/u32-mbsnlen.c index b7a5d185..0a71293e 100644 --- a/lib/unistr/u32-mbsnlen.c +++ b/lib/unistr/u32-mbsnlen.c @@ -1,5 +1,5 @@ /* Count characters in UTF-32 string. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-mbtouc-unsafe.c b/lib/unistr/u32-mbtouc-unsafe.c index 4bd9e817..8dbbfe45 100644 --- a/lib/unistr/u32-mbtouc-unsafe.c +++ b/lib/unistr/u32-mbtouc-unsafe.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-32 string. - Copyright (C) 2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-mbtouc.c b/lib/unistr/u32-mbtouc.c index 4eeef58c..05f7c774 100644 --- a/lib/unistr/u32-mbtouc.c +++ b/lib/unistr/u32-mbtouc.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-32 string. - Copyright (C) 2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-mbtoucr.c b/lib/unistr/u32-mbtoucr.c index 7d7993cc..83f77820 100644 --- a/lib/unistr/u32-mbtoucr.c +++ b/lib/unistr/u32-mbtoucr.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-32 string, returning an error code. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-move.c b/lib/unistr/u32-move.c index d6c08f4b..6362d853 100644 --- a/lib/unistr/u32-move.c +++ b/lib/unistr/u32-move.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-next.c b/lib/unistr/u32-next.c index c529295c..987fb027 100644 --- a/lib/unistr/u32-next.c +++ b/lib/unistr/u32-next.c @@ -1,5 +1,5 @@ /* Iterate over next character in UTF-32 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -32,7 +32,7 @@ u32_next (ucs4_t *puc, const uint32_t *s) { #if CONFIG_UNICODE_SAFETY if (count < 0) - *puc = 0xfffd; + *puc = 0xfffd; #endif return NULL; } diff --git a/lib/unistr/u32-prev.c b/lib/unistr/u32-prev.c index bc20c93f..f20b1b79 100644 --- a/lib/unistr/u32-prev.c +++ b/lib/unistr/u32-prev.c @@ -1,5 +1,5 @@ /* Iterate over previous character in UTF-32 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -30,10 +30,10 @@ u32_prev (ucs4_t *puc, const uint32_t *s, const uint32_t *start) #if CONFIG_UNICODE_SAFETY if (c_1 < 0xd800 || (c_1 >= 0xe000 && c_1 < 0x110000)) #endif - { - *puc = c_1; - return s - 1; - } + { + *puc = c_1; + return s - 1; + } } return NULL; } diff --git a/lib/unistr/u32-set.c b/lib/unistr/u32-set.c index de10e09e..5c517cd1 100644 --- a/lib/unistr/u32-set.c +++ b/lib/unistr/u32-set.c @@ -1,5 +1,5 @@ /* Fill UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-startswith.c b/lib/unistr/u32-startswith.c index 0f9a1859..7fcb5979 100644 --- a/lib/unistr/u32-startswith.c +++ b/lib/unistr/u32-startswith.c @@ -1,5 +1,5 @@ /* Substring test for UTF-32 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-stpcpy.c b/lib/unistr/u32-stpcpy.c index 5df82339..3cbfa924 100644 --- a/lib/unistr/u32-stpcpy.c +++ b/lib/unistr/u32-stpcpy.c @@ -1,5 +1,5 @@ /* Copy UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-stpncpy.c b/lib/unistr/u32-stpncpy.c index 19a08943..e55891e7 100644 --- a/lib/unistr/u32-stpncpy.c +++ b/lib/unistr/u32-stpncpy.c @@ -1,5 +1,5 @@ /* Copy UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-strcat.c b/lib/unistr/u32-strcat.c index cd4737fd..4e26bb48 100644 --- a/lib/unistr/u32-strcat.c +++ b/lib/unistr/u32-strcat.c @@ -1,5 +1,5 @@ /* Concatenate UTF-32 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-strchr.c b/lib/unistr/u32-strchr.c index 57a3a3cf..b5df7b7d 100644 --- a/lib/unistr/u32-strchr.c +++ b/lib/unistr/u32-strchr.c @@ -1,5 +1,5 @@ /* Search character in UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -26,9 +26,9 @@ u32_strchr (const uint32_t *s, ucs4_t uc) for (;; s++) { if (*s == uc) - break; + break; if (*s == 0) - goto notfound; + goto notfound; } return (uint32_t *) s; notfound: diff --git a/lib/unistr/u32-strcmp.c b/lib/unistr/u32-strcmp.c index b82d5ede..5f336ce9 100644 --- a/lib/unistr/u32-strcmp.c +++ b/lib/unistr/u32-strcmp.c @@ -1,5 +1,5 @@ /* Compare UTF-32 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -28,7 +28,7 @@ u32_strcmp (const uint32_t *s1, const uint32_t *s2) uint32_t uc1 = *s1++; uint32_t uc2 = *s2++; if (uc1 != 0 && uc1 == uc2) - continue; + continue; /* Note that uc1 and uc2 each have at most 31 bits. */ return (int)uc1 - (int)uc2; /* > 0 if uc1 > uc2, < 0 if uc1 < uc2. */ diff --git a/lib/unistr/u32-strcoll.c b/lib/unistr/u32-strcoll.c index d5e1482c..97488553 100644 --- a/lib/unistr/u32-strcoll.c +++ b/lib/unistr/u32-strcoll.c @@ -1,5 +1,5 @@ /* Compare UTF-32 strings using the collation rules of the current locale. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-strcpy.c b/lib/unistr/u32-strcpy.c index e5001005..f3c70e6c 100644 --- a/lib/unistr/u32-strcpy.c +++ b/lib/unistr/u32-strcpy.c @@ -1,5 +1,5 @@ /* Copy UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-strcspn.c b/lib/unistr/u32-strcspn.c index f93ab2ef..595d32e9 100644 --- a/lib/unistr/u32-strcspn.c +++ b/lib/unistr/u32-strcspn.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -36,8 +36,8 @@ FUNC (const UNIT *str, const UNIT *reject) ucs4_t uc = reject[0]; const UNIT *ptr = str; for (; *ptr != 0; ptr++) - if (*ptr == uc) - break; + if (*ptr == uc) + break; return ptr - str; } /* General case. */ @@ -45,7 +45,7 @@ FUNC (const UNIT *str, const UNIT *reject) const UNIT *ptr = str; for (; *ptr != 0; ptr++) if (U_STRCHR (reject, *ptr)) - break; + break; return ptr - str; } } diff --git a/lib/unistr/u32-strdup.c b/lib/unistr/u32-strdup.c index 66e9393e..da4cc5aa 100644 --- a/lib/unistr/u32-strdup.c +++ b/lib/unistr/u32-strdup.c @@ -1,5 +1,5 @@ /* Copy UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-strlen.c b/lib/unistr/u32-strlen.c index eb64cc2a..95d32abd 100644 --- a/lib/unistr/u32-strlen.c +++ b/lib/unistr/u32-strlen.c @@ -1,5 +1,5 @@ /* Determine length of UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-strmblen.c b/lib/unistr/u32-strmblen.c index 4dde3fff..54b78d7f 100644 --- a/lib/unistr/u32-strmblen.c +++ b/lib/unistr/u32-strmblen.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-32 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-strmbtouc.c b/lib/unistr/u32-strmbtouc.c index e94ac300..4c067b9d 100644 --- a/lib/unistr/u32-strmbtouc.c +++ b/lib/unistr/u32-strmbtouc.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-32 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-strncat.c b/lib/unistr/u32-strncat.c index 86f895b5..c9260b0f 100644 --- a/lib/unistr/u32-strncat.c +++ b/lib/unistr/u32-strncat.c @@ -1,5 +1,5 @@ /* Concatenate UTF-32 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-strncmp.c b/lib/unistr/u32-strncmp.c index 026ce50c..dcbb9352 100644 --- a/lib/unistr/u32-strncmp.c +++ b/lib/unistr/u32-strncmp.c @@ -1,5 +1,5 @@ /* Compare UTF-32 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -28,10 +28,10 @@ u32_strncmp (const uint32_t *s1, const uint32_t *s2, size_t n) uint32_t uc1 = *s1++; uint32_t uc2 = *s2++; if (uc1 != 0 && uc1 == uc2) - { - n--; - continue; - } + { + n--; + continue; + } /* Note that uc1 and uc2 each have at most 31 bits. */ return (int)uc1 - (int)uc2; /* > 0 if uc1 > uc2, < 0 if uc1 < uc2, = 0 if uc1 and uc2 are both 0. */ diff --git a/lib/unistr/u32-strncpy.c b/lib/unistr/u32-strncpy.c index c8f409bb..9a54f97e 100644 --- a/lib/unistr/u32-strncpy.c +++ b/lib/unistr/u32-strncpy.c @@ -1,5 +1,5 @@ /* Copy UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-strnlen.c b/lib/unistr/u32-strnlen.c index 2ead8f26..8102ac7f 100644 --- a/lib/unistr/u32-strnlen.c +++ b/lib/unistr/u32-strnlen.c @@ -1,5 +1,5 @@ /* Determine bounded length of UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-strpbrk.c b/lib/unistr/u32-strpbrk.c index 9579a1b0..2c4b6bc8 100644 --- a/lib/unistr/u32-strpbrk.c +++ b/lib/unistr/u32-strpbrk.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -35,8 +35,8 @@ FUNC (const UNIT *str, const UNIT *accept) ucs4_t uc = accept[0]; const UNIT *ptr = str; for (; *ptr != 0; ptr++) - if (*ptr == uc) - return (UNIT *) ptr; + if (*ptr == uc) + return (UNIT *) ptr; return NULL; } /* General case. */ @@ -44,7 +44,7 @@ FUNC (const UNIT *str, const UNIT *accept) const UNIT *ptr = str; for (; *ptr != 0; ptr++) if (U_STRCHR (accept, *ptr)) - return (UNIT *) ptr; + return (UNIT *) ptr; return NULL; } } diff --git a/lib/unistr/u32-strrchr.c b/lib/unistr/u32-strrchr.c index b4641f33..f0030e5c 100644 --- a/lib/unistr/u32-strrchr.c +++ b/lib/unistr/u32-strrchr.c @@ -1,5 +1,5 @@ /* Search character in UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -30,9 +30,9 @@ u32_strrchr (const uint32_t *s, ucs4_t uc) for (;; s++) { if (*s == uc) - result = (uint32_t *) s; + result = (uint32_t *) s; if (*s == 0) - break; + break; } return result; } diff --git a/lib/unistr/u32-strspn.c b/lib/unistr/u32-strspn.c index 6f802029..e2571d5b 100644 --- a/lib/unistr/u32-strspn.c +++ b/lib/unistr/u32-strspn.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -35,8 +35,8 @@ FUNC (const UNIT *str, const UNIT *accept) ucs4_t uc = accept[0]; const UNIT *ptr = str; for (; *ptr != 0; ptr++) - if (*ptr != uc) - break; + if (*ptr != uc) + break; return ptr - str; } /* General case. */ @@ -44,7 +44,7 @@ FUNC (const UNIT *str, const UNIT *accept) const UNIT *ptr = str; for (; *ptr != 0; ptr++) if (!U_STRCHR (accept, *ptr)) - break; + break; return ptr - str; } } diff --git a/lib/unistr/u32-strstr.c b/lib/unistr/u32-strstr.c index 285746de..cad06fcc 100644 --- a/lib/unistr/u32-strstr.c +++ b/lib/unistr/u32-strstr.c @@ -1,5 +1,5 @@ /* Substring test for UTF-32 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-strtok.c b/lib/unistr/u32-strtok.c index 3f219192..067122f0 100644 --- a/lib/unistr/u32-strtok.c +++ b/lib/unistr/u32-strtok.c @@ -1,5 +1,5 @@ /* Tokenize UTF-32 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u32-to-u16.c b/lib/unistr/u32-to-u16.c index 3a32162c..be327703 100644 --- a/lib/unistr/u32-to-u16.c +++ b/lib/unistr/u32-to-u16.c @@ -1,5 +1,5 @@ /* Convert UTF-32 string to UTF-16 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -60,60 +60,60 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) /* Fetch a Unicode character from the input string. */ uc = *s++; /* No need to call the safe variant u32_mbtouc, because - u16_uctomb will verify uc anyway. */ + u16_uctomb will verify uc anyway. */ /* Store it in the output string. */ count = u16_uctomb (result + length, uc, allocated - length); if (count == -1) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } if (count == -2) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 2 > allocated) - allocated = length + 2; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - count = u16_uctomb (result + length, uc, allocated - length); - if (count < 0) - abort (); - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 2 > allocated) + allocated = length + 2; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + count = u16_uctomb (result + length, uc, allocated - length); + if (count < 0) + abort (); + } length += count; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -122,7 +122,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unistr/u32-to-u8.c b/lib/unistr/u32-to-u8.c index 4dce896b..36710d3c 100644 --- a/lib/unistr/u32-to-u8.c +++ b/lib/unistr/u32-to-u8.c @@ -1,5 +1,5 @@ /* Convert UTF-32 string to UTF-8 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -60,60 +60,60 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) /* Fetch a Unicode character from the input string. */ uc = *s++; /* No need to call the safe variant u32_mbtouc, because - u8_uctomb will verify uc anyway. */ + u8_uctomb will verify uc anyway. */ /* Store it in the output string. */ count = u8_uctomb (result + length, uc, allocated - length); if (count == -1) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } if (count == -2) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 6 > allocated) - allocated = length + 6; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - count = u8_uctomb (result + length, uc, allocated - length); - if (count < 0) - abort (); - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 6 > allocated) + allocated = length + 6; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + count = u8_uctomb (result + length, uc, allocated - length); + if (count < 0) + abort (); + } length += count; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -122,7 +122,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unistr/u32-uctomb.c b/lib/unistr/u32-uctomb.c index 583b3b66..3ac58b43 100644 --- a/lib/unistr/u32-uctomb.c +++ b/lib/unistr/u32-uctomb.c @@ -1,5 +1,5 @@ /* Store a character in UTF-32 string. - Copyright (C) 2002, 2005-2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -33,12 +33,12 @@ u32_uctomb (uint32_t *s, ucs4_t uc, int n) if (uc < 0xd800 || (uc >= 0xe000 && uc < 0x110000)) { if (n > 0) - { - *s = uc; - return 1; - } + { + *s = uc; + return 1; + } else - return -2; + return -2; } else return -1; diff --git a/lib/unistr/u8-check.c b/lib/unistr/u8-check.c index 53897fc5..368042b0 100644 --- a/lib/unistr/u8-check.c +++ b/lib/unistr/u8-check.c @@ -1,5 +1,5 @@ /* Check UTF-8 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,73 +31,73 @@ u8_check (const uint8_t *s, size_t n) uint8_t c = *s; if (c < 0x80) - { - s++; - continue; - } + { + s++; + continue; + } if (c >= 0xc2) - { - if (c < 0xe0) - { - if (s + 2 <= s_end - && (s[1] ^ 0x80) < 0x40) - { - s += 2; - continue; - } - } - else if (c < 0xf0) - { - if (s + 3 <= s_end - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) - { - s += 3; - continue; - } - } - else if (c < 0xf8) - { - if (s + 4 <= s_end - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + { + if (c < 0xe0) + { + if (s + 2 <= s_end + && (s[1] ^ 0x80) < 0x40) + { + s += 2; + continue; + } + } + else if (c < 0xf0) + { + if (s + 3 <= s_end + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) + { + s += 3; + continue; + } + } + else if (c < 0xf8) + { + if (s + 4 <= s_end + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) - { - s += 4; - continue; - } - } + ) + { + s += 4; + continue; + } + } #if 0 - else if (c < 0xfc) - { - if (s + 5 <= s_end - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) - { - s += 5; - continue; - } - } - else if (c < 0xfe) - { - if (s + 6 <= s_end - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) - { - s += 6; - continue; - } - } + else if (c < 0xfc) + { + if (s + 5 <= s_end + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) + { + s += 5; + continue; + } + } + else if (c < 0xfe) + { + if (s + 6 <= s_end + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) + { + s += 6; + continue; + } + } #endif - } + } /* invalid or incomplete multibyte character */ return s; } diff --git a/lib/unistr/u8-chr.c b/lib/unistr/u8-chr.c index 2c4d7687..435d1be6 100644 --- a/lib/unistr/u8-chr.c +++ b/lib/unistr/u8-chr.c @@ -1,5 +1,6 @@ /* Search character in piece of UTF-8 string. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -30,58 +31,58 @@ u8_chr (const uint8_t *s, size_t n, ucs4_t uc) uint8_t c0 = uc; for (; n > 0; s++, n--) - { - if (*s == c0) - return (uint8_t *) s; - } + { + if (*s == c0) + return (uint8_t *) s; + } } else switch (u8_uctomb_aux (c, uc, 6)) { case 2: - if (n > 1) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; + if (n > 1) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; - for (n--; n > 0; s++, n--) - { - if (*s == c0 && s[1] == c1) - return (uint8_t *) s; - } - } - break; + for (n--; n > 0; s++, n--) + { + if (*s == c0 && s[1] == c1) + return (uint8_t *) s; + } + } + break; case 3: - if (n > 2) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; + if (n > 2) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; - for (n -= 2; n > 0; s++, n--) - { - if (*s == c0 && s[1] == c1 && s[2] == c2) - return (uint8_t *) s; - } - } - break; + for (n -= 2; n > 0; s++, n--) + { + if (*s == c0 && s[1] == c1 && s[2] == c2) + return (uint8_t *) s; + } + } + break; case 4: - if (n > 3) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; - uint8_t c3 = c[3]; + if (n > 3) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; + uint8_t c3 = c[3]; - for (n -= 3; n > 0; s++, n--) - { - if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) - return (uint8_t *) s; - } - } - break; + for (n -= 3; n > 0; s++, n--) + { + if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) + return (uint8_t *) s; + } + } + break; } return NULL; } diff --git a/lib/unistr/u8-cmp.c b/lib/unistr/u8-cmp.c index 77b2402d..d021b1ab 100644 --- a/lib/unistr/u8-cmp.c +++ b/lib/unistr/u8-cmp.c @@ -1,5 +1,5 @@ /* Compare pieces of UTF-8 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-cmp2.c b/lib/unistr/u8-cmp2.c index 99cee9f2..8a97db40 100644 --- a/lib/unistr/u8-cmp2.c +++ b/lib/unistr/u8-cmp2.c @@ -1,5 +1,5 @@ /* Compare pieces of UTF-8 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-cpy-alloc.c b/lib/unistr/u8-cpy-alloc.c index b2dcc5dc..18845165 100644 --- a/lib/unistr/u8-cpy-alloc.c +++ b/lib/unistr/u8-cpy-alloc.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-8 string. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-cpy.c b/lib/unistr/u8-cpy.c index bf3a55bc..2f29200e 100644 --- a/lib/unistr/u8-cpy.c +++ b/lib/unistr/u8-cpy.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-8 string. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-endswith.c b/lib/unistr/u8-endswith.c index e40613aa..833b3e18 100644 --- a/lib/unistr/u8-endswith.c +++ b/lib/unistr/u8-endswith.c @@ -1,5 +1,5 @@ /* Substring test for UTF-8 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-mblen.c b/lib/unistr/u8-mblen.c index 1981befe..f6a20271 100644 --- a/lib/unistr/u8-mblen.c +++ b/lib/unistr/u8-mblen.c @@ -1,5 +1,6 @@ /* Look at first character in UTF-8 string. - Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2010 Free Software + Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -29,69 +30,69 @@ u8_mblen (const uint8_t *s, size_t n) uint8_t c = *s; if (c < 0x80) - return (c != 0 ? 1 : 0); + return (c != 0 ? 1 : 0); if (c >= 0xc2) - { - if (c < 0xe0) - { - if (n >= 2 + { + if (c < 0xe0) + { + if (n >= 2 #if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 + && (s[1] ^ 0x80) < 0x40 #endif - ) - return 2; - } - else if (c < 0xf0) - { - if (n >= 3 + ) + return 2; + } + else if (c < 0xf0) + { + if (n >= 3 #if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0) + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0) #endif - ) - return 3; - } - else if (c < 0xf8) - { - if (n >= 4 + ) + return 3; + } + else if (c < 0xf8) + { + if (n >= 4 #if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif #endif - ) - return 4; - } + ) + return 4; + } #if 0 - else if (c < 0xfc) - { - if (n >= 5 + else if (c < 0xfc) + { + if (n >= 5 #if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88) + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88) #endif - ) - return 5; - } - else if (c < 0xfe) - { - if (n >= 6 + ) + return 5; + } + else if (c < 0xfe) + { + if (n >= 6 #if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84) + && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84) #endif - ) - return 6; - } + ) + return 6; + } #endif - } + } } /* invalid or incomplete multibyte character */ return -1; diff --git a/lib/unistr/u8-mbsnlen.c b/lib/unistr/u8-mbsnlen.c index 29af297f..9ddc42ea 100644 --- a/lib/unistr/u8-mbsnlen.c +++ b/lib/unistr/u8-mbsnlen.c @@ -1,5 +1,5 @@ /* Count characters in UTF-8 string. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2007. This program is free software: you can redistribute it and/or modify it @@ -28,12 +28,15 @@ u8_mbsnlen (const uint8_t *s, size_t n) characters = 0; while (n > 0) { - int count = u8_mblen (s, n); + ucs4_t uc; + int count = u8_mbtoucr (&uc, s, n); + characters++; + if (count == -2) + break; if (count <= 0) - count = 1; + count = 1; s += count; n -= count; - characters++; } return characters; } diff --git a/lib/unistr/u8-mbtouc-aux.c b/lib/unistr/u8-mbtouc-aux.c index 53d02bf0..c9975896 100644 --- a/lib/unistr/u8-mbtouc-aux.c +++ b/lib/unistr/u8-mbtouc-aux.c @@ -1,5 +1,5 @@ /* Conversion UTF-8 to UCS-4. - Copyright (C) 2001-2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -30,124 +30,124 @@ u8_mbtouc_aux (ucs4_t *puc, const uint8_t *s, size_t n) if (c >= 0xc2) { if (c < 0xe0) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x1f) << 6) - | (unsigned int) (s[1] ^ 0x80); - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x1f) << 6) + | (unsigned int) (s[1] ^ 0x80); + return 2; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf0) - { - if (n >= 3) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) - { - *puc = ((unsigned int) (c & 0x0f) << 12) - | ((unsigned int) (s[1] ^ 0x80) << 6) - | (unsigned int) (s[2] ^ 0x80); - return 3; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 3) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) + { + *puc = ((unsigned int) (c & 0x0f) << 12) + | ((unsigned int) (s[1] ^ 0x80) << 6) + | (unsigned int) (s[2] ^ 0x80); + return 3; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf8) - { - if (n >= 4) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + { + if (n >= 4) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) - { - *puc = ((unsigned int) (c & 0x07) << 18) - | ((unsigned int) (s[1] ^ 0x80) << 12) - | ((unsigned int) (s[2] ^ 0x80) << 6) - | (unsigned int) (s[3] ^ 0x80); - return 4; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + ) + { + *puc = ((unsigned int) (c & 0x07) << 18) + | ((unsigned int) (s[1] ^ 0x80) << 12) + | ((unsigned int) (s[2] ^ 0x80) << 6) + | (unsigned int) (s[3] ^ 0x80); + return 4; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #if 0 else if (c < 0xfc) - { - if (n >= 5) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 5) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) + { + *puc = ((unsigned int) (c & 0x03) << 24) + | ((unsigned int) (s[1] ^ 0x80) << 18) + | ((unsigned int) (s[2] ^ 0x80) << 12) + | ((unsigned int) (s[3] ^ 0x80) << 6) + | (unsigned int) (s[4] ^ 0x80); + return 5; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xfe) - { - if (n >= 6) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 6) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) + { + *puc = ((unsigned int) (c & 0x01) << 30) + | ((unsigned int) (s[1] ^ 0x80) << 24) + | ((unsigned int) (s[2] ^ 0x80) << 18) + | ((unsigned int) (s[3] ^ 0x80) << 12) + | ((unsigned int) (s[4] ^ 0x80) << 6) + | (unsigned int) (s[5] ^ 0x80); + return 6; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #endif } /* invalid multibyte character */ diff --git a/lib/unistr/u8-mbtouc-unsafe-aux.c b/lib/unistr/u8-mbtouc-unsafe-aux.c index 43e4a360..47590e39 100644 --- a/lib/unistr/u8-mbtouc-unsafe-aux.c +++ b/lib/unistr/u8-mbtouc-unsafe-aux.c @@ -1,5 +1,5 @@ /* Conversion UTF-8 to UCS-4. - Copyright (C) 2001-2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -30,134 +30,134 @@ u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n) if (c >= 0xc2) { if (c < 0xe0) - { - if (n >= 2) - { + { + if (n >= 2) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40) + if ((s[1] ^ 0x80) < 0x40) #endif - { - *puc = ((unsigned int) (c & 0x1f) << 6) - | (unsigned int) (s[1] ^ 0x80); - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x1f) << 6) + | (unsigned int) (s[1] ^ 0x80); + return 2; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf0) - { - if (n >= 3) - { + { + if (n >= 3) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) #endif - { - *puc = ((unsigned int) (c & 0x0f) << 12) - | ((unsigned int) (s[1] ^ 0x80) << 6) - | (unsigned int) (s[2] ^ 0x80); - return 3; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x0f) << 12) + | ((unsigned int) (s[1] ^ 0x80) << 6) + | (unsigned int) (s[2] ^ 0x80); + return 3; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf8) - { - if (n >= 4) - { + { + if (n >= 4) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) + ) #endif - { - *puc = ((unsigned int) (c & 0x07) << 18) - | ((unsigned int) (s[1] ^ 0x80) << 12) - | ((unsigned int) (s[2] ^ 0x80) << 6) - | (unsigned int) (s[3] ^ 0x80); - return 4; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x07) << 18) + | ((unsigned int) (s[1] ^ 0x80) << 12) + | ((unsigned int) (s[2] ^ 0x80) << 6) + | (unsigned int) (s[3] ^ 0x80); + return 4; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #if 0 else if (c < 0xfc) - { - if (n >= 5) - { + { + if (n >= 5) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) #endif - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x03) << 24) + | ((unsigned int) (s[1] ^ 0x80) << 18) + | ((unsigned int) (s[2] ^ 0x80) << 12) + | ((unsigned int) (s[3] ^ 0x80) << 6) + | (unsigned int) (s[4] ^ 0x80); + return 5; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xfe) - { - if (n >= 6) - { + { + if (n >= 6) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) #endif - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x01) << 30) + | ((unsigned int) (s[1] ^ 0x80) << 24) + | ((unsigned int) (s[2] ^ 0x80) << 18) + | ((unsigned int) (s[3] ^ 0x80) << 12) + | ((unsigned int) (s[4] ^ 0x80) << 6) + | (unsigned int) (s[5] ^ 0x80); + return 6; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #endif } /* invalid multibyte character */ diff --git a/lib/unistr/u8-mbtouc-unsafe.c b/lib/unistr/u8-mbtouc-unsafe.c index 46615696..41583f96 100644 --- a/lib/unistr/u8-mbtouc-unsafe.c +++ b/lib/unistr/u8-mbtouc-unsafe.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-8 string. - Copyright (C) 1999-2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -41,134 +41,134 @@ u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n) else if (c >= 0xc2) { if (c < 0xe0) - { - if (n >= 2) - { + { + if (n >= 2) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40) + if ((s[1] ^ 0x80) < 0x40) #endif - { - *puc = ((unsigned int) (c & 0x1f) << 6) - | (unsigned int) (s[1] ^ 0x80); - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x1f) << 6) + | (unsigned int) (s[1] ^ 0x80); + return 2; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf0) - { - if (n >= 3) - { + { + if (n >= 3) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) #endif - { - *puc = ((unsigned int) (c & 0x0f) << 12) - | ((unsigned int) (s[1] ^ 0x80) << 6) - | (unsigned int) (s[2] ^ 0x80); - return 3; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x0f) << 12) + | ((unsigned int) (s[1] ^ 0x80) << 6) + | (unsigned int) (s[2] ^ 0x80); + return 3; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf8) - { - if (n >= 4) - { + { + if (n >= 4) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) + ) #endif - { - *puc = ((unsigned int) (c & 0x07) << 18) - | ((unsigned int) (s[1] ^ 0x80) << 12) - | ((unsigned int) (s[2] ^ 0x80) << 6) - | (unsigned int) (s[3] ^ 0x80); - return 4; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x07) << 18) + | ((unsigned int) (s[1] ^ 0x80) << 12) + | ((unsigned int) (s[2] ^ 0x80) << 6) + | (unsigned int) (s[3] ^ 0x80); + return 4; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #if 0 else if (c < 0xfc) - { - if (n >= 5) - { + { + if (n >= 5) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) #endif - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x03) << 24) + | ((unsigned int) (s[1] ^ 0x80) << 18) + | ((unsigned int) (s[2] ^ 0x80) << 12) + | ((unsigned int) (s[3] ^ 0x80) << 6) + | (unsigned int) (s[4] ^ 0x80); + return 5; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xfe) - { - if (n >= 6) - { + { + if (n >= 6) + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) #endif - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + *puc = ((unsigned int) (c & 0x01) << 30) + | ((unsigned int) (s[1] ^ 0x80) << 24) + | ((unsigned int) (s[2] ^ 0x80) << 18) + | ((unsigned int) (s[3] ^ 0x80) << 12) + | ((unsigned int) (s[4] ^ 0x80) << 6) + | (unsigned int) (s[5] ^ 0x80); + return 6; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #endif } /* invalid multibyte character */ diff --git a/lib/unistr/u8-mbtouc.c b/lib/unistr/u8-mbtouc.c index ff624f17..96cd5b74 100644 --- a/lib/unistr/u8-mbtouc.c +++ b/lib/unistr/u8-mbtouc.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-8 string. - Copyright (C) 1999-2002, 2006-2007, 2009 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -40,124 +40,124 @@ u8_mbtouc (ucs4_t *puc, const uint8_t *s, size_t n) else if (c >= 0xc2) { if (c < 0xe0) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x1f) << 6) - | (unsigned int) (s[1] ^ 0x80); - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x1f) << 6) + | (unsigned int) (s[1] ^ 0x80); + return 2; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf0) - { - if (n >= 3) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) - { - *puc = ((unsigned int) (c & 0x0f) << 12) - | ((unsigned int) (s[1] ^ 0x80) << 6) - | (unsigned int) (s[2] ^ 0x80); - return 3; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 3) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) + { + *puc = ((unsigned int) (c & 0x0f) << 12) + | ((unsigned int) (s[1] ^ 0x80) << 6) + | (unsigned int) (s[2] ^ 0x80); + return 3; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xf8) - { - if (n >= 4) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + { + if (n >= 4) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) - { - *puc = ((unsigned int) (c & 0x07) << 18) - | ((unsigned int) (s[1] ^ 0x80) << 12) - | ((unsigned int) (s[2] ^ 0x80) << 6) - | (unsigned int) (s[3] ^ 0x80); - return 4; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + ) + { + *puc = ((unsigned int) (c & 0x07) << 18) + | ((unsigned int) (s[1] ^ 0x80) << 12) + | ((unsigned int) (s[2] ^ 0x80) << 6) + | (unsigned int) (s[3] ^ 0x80); + return 4; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #if 0 else if (c < 0xfc) - { - if (n >= 5) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 5) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) + { + *puc = ((unsigned int) (c & 0x03) << 24) + | ((unsigned int) (s[1] ^ 0x80) << 18) + | ((unsigned int) (s[2] ^ 0x80) << 12) + | ((unsigned int) (s[3] ^ 0x80) << 6) + | (unsigned int) (s[4] ^ 0x80); + return 5; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } else if (c < 0xfe) - { - if (n >= 6) - { - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } + { + if (n >= 6) + { + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) + { + *puc = ((unsigned int) (c & 0x01) << 30) + | ((unsigned int) (s[1] ^ 0x80) << 24) + | ((unsigned int) (s[2] ^ 0x80) << 18) + | ((unsigned int) (s[3] ^ 0x80) << 12) + | ((unsigned int) (s[4] ^ 0x80) << 6) + | (unsigned int) (s[5] ^ 0x80); + return 6; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return n; + } + } #endif } /* invalid multibyte character */ diff --git a/lib/unistr/u8-mbtoucr.c b/lib/unistr/u8-mbtoucr.c index dd833524..a749c48c 100644 --- a/lib/unistr/u8-mbtoucr.c +++ b/lib/unistr/u8-mbtoucr.c @@ -1,5 +1,5 @@ /* Look at first character in UTF-8 string, returning an error code. - Copyright (C) 1999-2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify it @@ -33,250 +33,250 @@ u8_mbtoucr (ucs4_t *puc, const uint8_t *s, size_t n) else if (c >= 0xc2) { if (c < 0xe0) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x1f) << 6) - | (unsigned int) (s[1] ^ 0x80); - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x1f) << 6) + | (unsigned int) (s[1] ^ 0x80); + return 2; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } else if (c < 0xf0) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) - { - if (n >= 3) - { - if ((s[2] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x0f) << 12) - | ((unsigned int) (s[1] ^ 0x80) << 6) - | (unsigned int) (s[2] ^ 0x80); - return 3; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) + { + if (n >= 3) + { + if ((s[2] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x0f) << 12) + | ((unsigned int) (s[1] ^ 0x80) << 6) + | (unsigned int) (s[2] ^ 0x80); + return 3; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } else if (c < 0xf8) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) - { - if (n >= 3) - { - if ((s[2] ^ 0x80) < 0x40) - { - if (n >= 4) - { - if ((s[3] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x07) << 18) - | ((unsigned int) (s[1] ^ 0x80) << 12) - | ((unsigned int) (s[2] ^ 0x80) << 6) - | (unsigned int) (s[3] ^ 0x80); - return 4; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } + ) + { + if (n >= 3) + { + if ((s[2] ^ 0x80) < 0x40) + { + if (n >= 4) + { + if ((s[3] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x07) << 18) + | ((unsigned int) (s[1] ^ 0x80) << 12) + | ((unsigned int) (s[2] ^ 0x80) << 6) + | (unsigned int) (s[3] ^ 0x80); + return 4; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } #if 0 else if (c < 0xfc) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) - { - if (n >= 3) - { - if ((s[2] ^ 0x80) < 0x40) - { - if (n >= 4) - { - if ((s[3] ^ 0x80) < 0x40) - { - if (n >= 5) - { - if ((s[4] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) + { + if (n >= 3) + { + if ((s[2] ^ 0x80) < 0x40) + { + if (n >= 4) + { + if ((s[3] ^ 0x80) < 0x40) + { + if (n >= 5) + { + if ((s[4] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x03) << 24) + | ((unsigned int) (s[1] ^ 0x80) << 18) + | ((unsigned int) (s[2] ^ 0x80) << 12) + | ((unsigned int) (s[3] ^ 0x80) << 6) + | (unsigned int) (s[4] ^ 0x80); + return 5; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } else if (c < 0xfe) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) - { - if (n >= 3) - { - if ((s[2] ^ 0x80) < 0x40) - { - if (n >= 4) - { - if ((s[3] ^ 0x80) < 0x40) - { - if (n >= 5) - { - if ((s[4] ^ 0x80) < 0x40) - { - if (n >= 6) - { - if ((s[5] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } + { + if (n >= 2) + { + if ((s[1] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) + { + if (n >= 3) + { + if ((s[2] ^ 0x80) < 0x40) + { + if (n >= 4) + { + if ((s[3] ^ 0x80) < 0x40) + { + if (n >= 5) + { + if ((s[4] ^ 0x80) < 0x40) + { + if (n >= 6) + { + if ((s[5] ^ 0x80) < 0x40) + { + *puc = ((unsigned int) (c & 0x01) << 30) + | ((unsigned int) (s[1] ^ 0x80) << 24) + | ((unsigned int) (s[2] ^ 0x80) << 18) + | ((unsigned int) (s[3] ^ 0x80) << 12) + | ((unsigned int) (s[4] ^ 0x80) << 6) + | (unsigned int) (s[5] ^ 0x80); + return 6; + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } + /* invalid multibyte character */ + } + else + { + /* incomplete multibyte character */ + *puc = 0xfffd; + return -2; + } + } #endif } /* invalid multibyte character */ diff --git a/lib/unistr/u8-move.c b/lib/unistr/u8-move.c index 5a30be8c..5c48411b 100644 --- a/lib/unistr/u8-move.c +++ b/lib/unistr/u8-move.c @@ -1,5 +1,5 @@ /* Copy piece of UTF-8 string. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-next.c b/lib/unistr/u8-next.c index ecf4f80a..34249aa5 100644 --- a/lib/unistr/u8-next.c +++ b/lib/unistr/u8-next.c @@ -1,5 +1,5 @@ /* Iterate over next character in UTF-8 string. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,7 +31,7 @@ u8_next (ucs4_t *puc, const uint8_t *s) else { if (count < 0) - *puc = 0xfffd; + *puc = 0xfffd; return NULL; } } diff --git a/lib/unistr/u8-prev.c b/lib/unistr/u8-prev.c index 245d22ff..97a27f55 100644 --- a/lib/unistr/u8-prev.c +++ b/lib/unistr/u8-prev.c @@ -1,5 +1,5 @@ /* Iterate over previous character in UTF-8 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -29,65 +29,65 @@ u8_prev (ucs4_t *puc, const uint8_t *s, const uint8_t *start) uint8_t c_1 = s[-1]; if (c_1 < 0x80) - { - *puc = c_1; - return s - 1; - } + { + *puc = c_1; + return s - 1; + } #if CONFIG_UNICODE_SAFETY if ((c_1 ^ 0x80) < 0x40) #endif - if (s - 1 != start) - { - uint8_t c_2 = s[-2]; + if (s - 1 != start) + { + uint8_t c_2 = s[-2]; - if (c_2 >= 0xc2 && c_2 < 0xe0) - { - *puc = ((unsigned int) (c_2 & 0x1f) << 6) - | (unsigned int) (c_1 ^ 0x80); - return s - 2; - } + if (c_2 >= 0xc2 && c_2 < 0xe0) + { + *puc = ((unsigned int) (c_2 & 0x1f) << 6) + | (unsigned int) (c_1 ^ 0x80); + return s - 2; + } #if CONFIG_UNICODE_SAFETY - if ((c_2 ^ 0x80) < 0x40) + if ((c_2 ^ 0x80) < 0x40) #endif - if (s - 2 != start) - { - uint8_t c_3 = s[-3]; + if (s - 2 != start) + { + uint8_t c_3 = s[-3]; - if (c_3 >= 0xe0 && c_3 < 0xf0 + if (c_3 >= 0xe0 && c_3 < 0xf0 #if CONFIG_UNICODE_SAFETY - && (c_3 >= 0xe1 || c_2 >= 0xa0) - && (c_3 != 0xed || c_2 < 0xa0) + && (c_3 >= 0xe1 || c_2 >= 0xa0) + && (c_3 != 0xed || c_2 < 0xa0) #endif - ) - { - *puc = ((unsigned int) (c_3 & 0x0f) << 12) - | ((unsigned int) (c_2 ^ 0x80) << 6) - | (unsigned int) (c_1 ^ 0x80); - return s - 3; - } + ) + { + *puc = ((unsigned int) (c_3 & 0x0f) << 12) + | ((unsigned int) (c_2 ^ 0x80) << 6) + | (unsigned int) (c_1 ^ 0x80); + return s - 3; + } #if CONFIG_UNICODE_SAFETY - if ((c_3 ^ 0x80) < 0x40) + if ((c_3 ^ 0x80) < 0x40) #endif - if (s - 3 != start) - { - uint8_t c_4 = s[-4]; + if (s - 3 != start) + { + uint8_t c_4 = s[-4]; - if (c_4 >= 0xf0 && c_4 < 0xf8 + if (c_4 >= 0xf0 && c_4 < 0xf8 #if CONFIG_UNICODE_SAFETY - && (c_4 >= 0xf1 || c_3 >= 0x90) - && (c_4 < 0xf4 || (c_4 == 0xf4 && c_3 < 0x90)) + && (c_4 >= 0xf1 || c_3 >= 0x90) + && (c_4 < 0xf4 || (c_4 == 0xf4 && c_3 < 0x90)) #endif - ) - { - *puc = ((unsigned int) (c_4 & 0x07) << 18) - | ((unsigned int) (c_3 ^ 0x80) << 12) - | ((unsigned int) (c_2 ^ 0x80) << 6) - | (unsigned int) (c_1 ^ 0x80); - return s - 4; - } - } - } - } + ) + { + *puc = ((unsigned int) (c_4 & 0x07) << 18) + | ((unsigned int) (c_3 ^ 0x80) << 12) + | ((unsigned int) (c_2 ^ 0x80) << 6) + | (unsigned int) (c_1 ^ 0x80); + return s - 4; + } + } + } + } } return NULL; } diff --git a/lib/unistr/u8-set.c b/lib/unistr/u8-set.c index 5bb4fd7a..3cca23b2 100644 --- a/lib/unistr/u8-set.c +++ b/lib/unistr/u8-set.c @@ -1,5 +1,5 @@ /* Fill UTF-8 string. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -33,12 +33,12 @@ FUNC (UNIT *s, ucs4_t uc, size_t n) if (n > 0) { if (IS_SINGLE_UNIT (uc)) - memset ((char *) s, uc, n); + memset ((char *) s, uc, n); else - { - errno = EILSEQ; - return NULL; - } + { + errno = EILSEQ; + return NULL; + } } return s; } diff --git a/lib/unistr/u8-startswith.c b/lib/unistr/u8-startswith.c index 671e3d9f..4cc436a2 100644 --- a/lib/unistr/u8-startswith.c +++ b/lib/unistr/u8-startswith.c @@ -1,5 +1,5 @@ /* Substring test for UTF-8 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-stpcpy.c b/lib/unistr/u8-stpcpy.c index a5c15c5d..0faba413 100644 --- a/lib/unistr/u8-stpcpy.c +++ b/lib/unistr/u8-stpcpy.c @@ -1,5 +1,5 @@ /* Copy UTF-8 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-stpncpy.c b/lib/unistr/u8-stpncpy.c index 87f254d7..a456beac 100644 --- a/lib/unistr/u8-stpncpy.c +++ b/lib/unistr/u8-stpncpy.c @@ -1,5 +1,5 @@ /* Copy UTF-8 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strcat.c b/lib/unistr/u8-strcat.c index 25ec5d37..2b54badf 100644 --- a/lib/unistr/u8-strcat.c +++ b/lib/unistr/u8-strcat.c @@ -1,5 +1,5 @@ /* Concatenate UTF-8 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strchr.c b/lib/unistr/u8-strchr.c index 370a7930..3be14c79 100644 --- a/lib/unistr/u8-strchr.c +++ b/lib/unistr/u8-strchr.c @@ -1,5 +1,6 @@ /* Search character in UTF-8 string. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -30,70 +31,70 @@ u8_strchr (const uint8_t *s, ucs4_t uc) uint8_t c0 = uc; for (;; s++) - { - if (*s == c0) - break; - if (*s == 0) - goto notfound; - } + { + if (*s == c0) + break; + if (*s == 0) + goto notfound; + } return (uint8_t *) s; } else switch (u8_uctomb_aux (c, uc, 6)) { case 2: - if (*s == 0) - goto notfound; - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; + if (*s == 0) + goto notfound; + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; - for (;; s++) - { - if (s[1] == 0) - goto notfound; - if (*s == c0 && s[1] == c1) - break; - } - return (uint8_t *) s; - } + for (;; s++) + { + if (s[1] == 0) + goto notfound; + if (*s == c0 && s[1] == c1) + break; + } + return (uint8_t *) s; + } case 3: - if (*s == 0 || s[1] == 0) - goto notfound; - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; + if (*s == 0 || s[1] == 0) + goto notfound; + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; - for (;; s++) - { - if (s[2] == 0) - goto notfound; - if (*s == c0 && s[1] == c1 && s[2] == c2) - break; - } - return (uint8_t *) s; - } + for (;; s++) + { + if (s[2] == 0) + goto notfound; + if (*s == c0 && s[1] == c1 && s[2] == c2) + break; + } + return (uint8_t *) s; + } case 4: - if (*s == 0 || s[1] == 0 || s[2] == 0) - goto notfound; - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; - uint8_t c3 = c[3]; + if (*s == 0 || s[1] == 0 || s[2] == 0) + goto notfound; + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; + uint8_t c3 = c[3]; - for (;; s++) - { - if (s[3] == 0) - goto notfound; - if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) - break; - } - return (uint8_t *) s; - } + for (;; s++) + { + if (s[3] == 0) + goto notfound; + if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) + break; + } + return (uint8_t *) s; + } } notfound: return NULL; diff --git a/lib/unistr/u8-strcmp.c b/lib/unistr/u8-strcmp.c index 58b4b8c2..82a44147 100644 --- a/lib/unistr/u8-strcmp.c +++ b/lib/unistr/u8-strcmp.c @@ -1,5 +1,5 @@ /* Compare UTF-8 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strcoll.c b/lib/unistr/u8-strcoll.c index ca08609e..9ffa135e 100644 --- a/lib/unistr/u8-strcoll.c +++ b/lib/unistr/u8-strcoll.c @@ -1,5 +1,5 @@ /* Compare UTF-8 strings using the collation rules of the current locale. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strcpy.c b/lib/unistr/u8-strcpy.c index b93c8cb4..9662de58 100644 --- a/lib/unistr/u8-strcpy.c +++ b/lib/unistr/u8-strcpy.c @@ -1,5 +1,5 @@ /* Copy UTF-8 string. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strcspn.c b/lib/unistr/u8-strcspn.c index a43b53fb..4b5b8e07 100644 --- a/lib/unistr/u8-strcspn.c +++ b/lib/unistr/u8-strcspn.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-8 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strdup.c b/lib/unistr/u8-strdup.c index feaa8725..58a30772 100644 --- a/lib/unistr/u8-strdup.c +++ b/lib/unistr/u8-strdup.c @@ -1,5 +1,5 @@ /* Copy UTF-8 string. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strlen.c b/lib/unistr/u8-strlen.c index cf5b9ceb..b8bebf0e 100644 --- a/lib/unistr/u8-strlen.c +++ b/lib/unistr/u8-strlen.c @@ -1,5 +1,5 @@ /* Determine length of UTF-8 string. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strmblen.c b/lib/unistr/u8-strmblen.c index 52db99d0..52242c58 100644 --- a/lib/unistr/u8-strmblen.c +++ b/lib/unistr/u8-strmblen.c @@ -1,5 +1,6 @@ /* Look at first character in UTF-8 string. - Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2010 Free Software + Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -31,64 +32,64 @@ u8_strmblen (const uint8_t *s) if (c >= 0xc2) { if (c < 0xe0) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40) + if ((s[1] ^ 0x80) < 0x40) #else - if (s[1] != 0) + if (s[1] != 0) #endif - return 2; - } + return 2; + } else if (c < 0xf0) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) #else - if (s[1] != 0 && s[2] != 0) + if (s[1] != 0 && s[2] != 0) #endif - return 3; - } + return 3; + } else if (c < 0xf8) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) + ) #else - if (s[1] != 0 && s[2] != 0 && s[3] != 0) + if (s[1] != 0 && s[2] != 0 && s[3] != 0) #endif - return 4; - } + return 4; + } #if 0 else if (c < 0xfc) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) #else - if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0) + if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0) #endif - return 5; - } + return 5; + } else if (c < 0xfe) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) #else - if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0 && s[5] != 0) + if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0 && s[5] != 0) #endif - return 6; - } + return 6; + } #endif } /* invalid or incomplete multibyte character */ diff --git a/lib/unistr/u8-strmbtouc.c b/lib/unistr/u8-strmbtouc.c index bc2fdb0d..67016c65 100644 --- a/lib/unistr/u8-strmbtouc.c +++ b/lib/unistr/u8-strmbtouc.c @@ -1,5 +1,6 @@ /* Look at first character in UTF-8 string. - Copyright (C) 1999-2000, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999-2000, 2002, 2006-2007, 2009-2010 Free Software + Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -34,94 +35,94 @@ u8_strmbtouc (ucs4_t *puc, const uint8_t *s) if (c >= 0xc2) { if (c < 0xe0) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40) + if ((s[1] ^ 0x80) < 0x40) #else - if (s[1] != 0) + if (s[1] != 0) #endif - { - *puc = ((unsigned int) (c & 0x1f) << 6) - | (unsigned int) (s[1] ^ 0x80); - return 2; - } - } + { + *puc = ((unsigned int) (c & 0x1f) << 6) + | (unsigned int) (s[1] ^ 0x80); + return 2; + } + } else if (c < 0xf0) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (c >= 0xe1 || s[1] >= 0xa0) + && (c != 0xed || s[1] < 0xa0)) #else - if (s[1] != 0 && s[2] != 0) + if (s[1] != 0 && s[2] != 0) #endif - { - *puc = ((unsigned int) (c & 0x0f) << 12) - | ((unsigned int) (s[1] ^ 0x80) << 6) - | (unsigned int) (s[2] ^ 0x80); - return 3; - } - } + { + *puc = ((unsigned int) (c & 0x0f) << 12) + | ((unsigned int) (s[1] ^ 0x80) << 6) + | (unsigned int) (s[2] ^ 0x80); + return 3; + } + } else if (c < 0xf8) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 - && (c >= 0xf1 || s[1] >= 0x90) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 + && (c >= 0xf1 || s[1] >= 0x90) #if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) #endif - ) + ) #else - if (s[1] != 0 && s[2] != 0 && s[3] != 0) + if (s[1] != 0 && s[2] != 0 && s[3] != 0) #endif - { - *puc = ((unsigned int) (c & 0x07) << 18) - | ((unsigned int) (s[1] ^ 0x80) << 12) - | ((unsigned int) (s[2] ^ 0x80) << 6) - | (unsigned int) (s[3] ^ 0x80); - return 4; - } - } + { + *puc = ((unsigned int) (c & 0x07) << 18) + | ((unsigned int) (s[1] ^ 0x80) << 12) + | ((unsigned int) (s[2] ^ 0x80) << 6) + | (unsigned int) (s[3] ^ 0x80); + return 4; + } + } #if 0 else if (c < 0xfc) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (c >= 0xf9 || s[1] >= 0x88)) #else - if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0) + if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0) #endif - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - } + { + *puc = ((unsigned int) (c & 0x03) << 24) + | ((unsigned int) (s[1] ^ 0x80) << 18) + | ((unsigned int) (s[2] ^ 0x80) << 12) + | ((unsigned int) (s[3] ^ 0x80) << 6) + | (unsigned int) (s[4] ^ 0x80); + return 5; + } + } else if (c < 0xfe) - { + { #if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) + if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 + && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 + && (s[5] ^ 0x80) < 0x40 + && (c >= 0xfd || s[1] >= 0x84)) #else - if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0 && s[5] != 0) + if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0 && s[5] != 0) #endif - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - } + { + *puc = ((unsigned int) (c & 0x01) << 30) + | ((unsigned int) (s[1] ^ 0x80) << 24) + | ((unsigned int) (s[2] ^ 0x80) << 18) + | ((unsigned int) (s[3] ^ 0x80) << 12) + | ((unsigned int) (s[4] ^ 0x80) << 6) + | (unsigned int) (s[5] ^ 0x80); + return 6; + } + } #endif } /* invalid or incomplete multibyte character */ diff --git a/lib/unistr/u8-strncat.c b/lib/unistr/u8-strncat.c index d9654602..47803505 100644 --- a/lib/unistr/u8-strncat.c +++ b/lib/unistr/u8-strncat.c @@ -1,5 +1,5 @@ /* Concatenate UTF-8 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strncmp.c b/lib/unistr/u8-strncmp.c index 5aad7e76..286450be 100644 --- a/lib/unistr/u8-strncmp.c +++ b/lib/unistr/u8-strncmp.c @@ -1,5 +1,5 @@ /* Compare UTF-8 strings. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strncpy.c b/lib/unistr/u8-strncpy.c index f478fab6..5ef757bd 100644 --- a/lib/unistr/u8-strncpy.c +++ b/lib/unistr/u8-strncpy.c @@ -1,5 +1,5 @@ /* Copy UTF-8 string. - Copyright (C) 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strnlen.c b/lib/unistr/u8-strnlen.c index 32ce7b88..e732ea2e 100644 --- a/lib/unistr/u8-strnlen.c +++ b/lib/unistr/u8-strnlen.c @@ -1,5 +1,5 @@ /* Determine bounded length of UTF-8 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strpbrk.c b/lib/unistr/u8-strpbrk.c index 1538faa7..ec6dc278 100644 --- a/lib/unistr/u8-strpbrk.c +++ b/lib/unistr/u8-strpbrk.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-8 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strrchr.c b/lib/unistr/u8-strrchr.c index 309f3234..6d8e2971 100644 --- a/lib/unistr/u8-strrchr.c +++ b/lib/unistr/u8-strrchr.c @@ -1,5 +1,6 @@ /* Search character in UTF-8 string. - Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006-2007, 2009-2010 Free Software Foundation, + Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -33,69 +34,69 @@ u8_strrchr (const uint8_t *s, ucs4_t uc) uint8_t c0 = uc; for (;; s++) - { - if (*s == c0) - result = (uint8_t *) s; - if (*s == 0) - break; - } + { + if (*s == c0) + result = (uint8_t *) s; + if (*s == 0) + break; + } } else switch (u8_uctomb_aux (c, uc, 6)) { case 2: - if (*s) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; + if (*s) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; - /* FIXME: Maybe walking the string via u8_mblen is a win? */ - for (;; s++) - { - if (s[1] == 0) - break; - if (*s == c0 && s[1] == c1) - result = (uint8_t *) s; - } - } - break; + /* FIXME: Maybe walking the string via u8_mblen is a win? */ + for (;; s++) + { + if (s[1] == 0) + break; + if (*s == c0 && s[1] == c1) + result = (uint8_t *) s; + } + } + break; case 3: - if (*s && s[1]) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; + if (*s && s[1]) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; - /* FIXME: Maybe walking the string via u8_mblen is a win? */ - for (;; s++) - { - if (s[2] == 0) - break; - if (*s == c0 && s[1] == c1 && s[2] == c2) - result = (uint8_t *) s; - } - } - break; + /* FIXME: Maybe walking the string via u8_mblen is a win? */ + for (;; s++) + { + if (s[2] == 0) + break; + if (*s == c0 && s[1] == c1 && s[2] == c2) + result = (uint8_t *) s; + } + } + break; case 4: - if (*s && s[1] && s[2]) - { - uint8_t c0 = c[0]; - uint8_t c1 = c[1]; - uint8_t c2 = c[2]; - uint8_t c3 = c[3]; + if (*s && s[1] && s[2]) + { + uint8_t c0 = c[0]; + uint8_t c1 = c[1]; + uint8_t c2 = c[2]; + uint8_t c3 = c[3]; - /* FIXME: Maybe walking the string via u8_mblen is a win? */ - for (;; s++) - { - if (s[3] == 0) - break; - if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) - result = (uint8_t *) s; - } - } - break; + /* FIXME: Maybe walking the string via u8_mblen is a win? */ + for (;; s++) + { + if (s[3] == 0) + break; + if (*s == c0 && s[1] == c1 && s[2] == c2 && s[3] == c3) + result = (uint8_t *) s; + } + } + break; } return result; } diff --git a/lib/unistr/u8-strspn.c b/lib/unistr/u8-strspn.c index 582c8259..7747815b 100644 --- a/lib/unistr/u8-strspn.c +++ b/lib/unistr/u8-strspn.c @@ -1,5 +1,5 @@ /* Search for some characters in UTF-8 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strstr.c b/lib/unistr/u8-strstr.c index b5cbf249..cce37adc 100644 --- a/lib/unistr/u8-strstr.c +++ b/lib/unistr/u8-strstr.c @@ -1,5 +1,5 @@ /* Substring test for UTF-8 strings. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-strtok.c b/lib/unistr/u8-strtok.c index a8d3821d..e5c72037 100644 --- a/lib/unistr/u8-strtok.c +++ b/lib/unistr/u8-strtok.c @@ -1,5 +1,5 @@ /* Tokenize UTF-8 string. - Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1999, 2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/unistr/u8-to-u16.c b/lib/unistr/u8-to-u16.c index 03c66000..3745c2bd 100644 --- a/lib/unistr/u8-to-u16.c +++ b/lib/unistr/u8-to-u16.c @@ -1,5 +1,5 @@ /* Convert UTF-8 string to UTF-16 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -58,68 +58,68 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) int count; /* Fetch a Unicode character from the input string. */ - count = u8_mbtouc (&uc, s, s_end - s); + count = u8_mbtoucr (&uc, s, s_end - s); if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } s += count; /* Store it in the output string. */ count = u16_uctomb (result + length, uc, allocated - length); if (count == -1) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } if (count == -2) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 2 > allocated) - allocated = length + 2; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - count = u16_uctomb (result + length, uc, allocated - length); - if (count < 0) - abort (); - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 2 > allocated) + allocated = length + 2; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + count = u16_uctomb (result + length, uc, allocated - length); + if (count < 0) + abort (); + } length += count; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -128,7 +128,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unistr/u8-to-u32.c b/lib/unistr/u8-to-u32.c index 2a0ad39e..de2a35e6 100644 --- a/lib/unistr/u8-to-u32.c +++ b/lib/unistr/u8-to-u32.c @@ -1,5 +1,5 @@ /* Convert UTF-8 string to UTF-32 string. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -58,57 +58,57 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) int count; /* Fetch a Unicode character from the input string. */ - count = u8_mbtouc (&uc, s, s_end - s); + count = u8_mbtoucr (&uc, s, s_end - s); if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = EILSEQ; - return NULL; - } + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = EILSEQ; + return NULL; + } s += count; /* Store it in the output string. */ if (length + 1 > allocated) - { - DST_UNIT *memory; - - allocated = (allocated > 0 ? 2 * allocated : 12); - if (length + 1 > allocated) - allocated = length + 1; - if (result == resultbuf || result == NULL) - memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); - else - memory = - (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); - - if (memory == NULL) - { - if (!(result == resultbuf || result == NULL)) - free (result); - errno = ENOMEM; - return NULL; - } - if (result == resultbuf && length > 0) - memcpy ((char *) memory, (char *) result, - length * sizeof (DST_UNIT)); - result = memory; - } + { + DST_UNIT *memory; + + allocated = (allocated > 0 ? 2 * allocated : 12); + if (length + 1 > allocated) + allocated = length + 1; + if (result == resultbuf || result == NULL) + memory = (DST_UNIT *) malloc (allocated * sizeof (DST_UNIT)); + else + memory = + (DST_UNIT *) realloc (result, allocated * sizeof (DST_UNIT)); + + if (memory == NULL) + { + if (!(result == resultbuf || result == NULL)) + free (result); + errno = ENOMEM; + return NULL; + } + if (result == resultbuf && length > 0) + memcpy ((char *) memory, (char *) result, + length * sizeof (DST_UNIT)); + result = memory; + } result[length++] = uc; } if (length == 0) { if (result == NULL) - { - /* Return a non-NULL value. NULL means error. */ - result = (DST_UNIT *) malloc (1); - if (result == NULL) - { - errno = ENOMEM; - return NULL; - } - } + { + /* Return a non-NULL value. NULL means error. */ + result = (DST_UNIT *) malloc (1); + if (result == NULL) + { + errno = ENOMEM; + return NULL; + } + } } else if (result != resultbuf && length < allocated) { @@ -117,7 +117,7 @@ FUNC (const SRC_UNIT *s, size_t n, DST_UNIT *resultbuf, size_t *lengthp) memory = (DST_UNIT *) realloc (result, length * sizeof (DST_UNIT)); if (memory != NULL) - result = memory; + result = memory; } *lengthp = length; diff --git a/lib/unistr/u8-uctomb-aux.c b/lib/unistr/u8-uctomb-aux.c index c42fa501..695921d6 100644 --- a/lib/unistr/u8-uctomb-aux.c +++ b/lib/unistr/u8-uctomb-aux.c @@ -1,5 +1,5 @@ /* Conversion UCS-4 to UTF-8. - Copyright (C) 2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -33,9 +33,9 @@ u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n) else if (uc < 0x10000) { if (uc < 0xd800 || uc >= 0xe000) - count = 3; + count = 3; else - return -1; + return -1; } #if 0 else if (uc < 0x200000) diff --git a/lib/unistr/u8-uctomb.c b/lib/unistr/u8-uctomb.c index 33921669..fd33c05c 100644 --- a/lib/unistr/u8-uctomb.c +++ b/lib/unistr/u8-uctomb.c @@ -1,5 +1,5 @@ /* Store a character in UTF-8 string. - Copyright (C) 2002, 2005-2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -33,10 +33,10 @@ u8_uctomb (uint8_t *s, ucs4_t uc, int n) if (uc < 0x80) { if (n > 0) - { - s[0] = uc; - return 1; - } + { + s[0] = uc; + return 1; + } /* else return -2, below. */ } else @@ -44,43 +44,43 @@ u8_uctomb (uint8_t *s, ucs4_t uc, int n) int count; if (uc < 0x800) - count = 2; + count = 2; else if (uc < 0x10000) - { - if (uc < 0xd800 || uc >= 0xe000) - count = 3; - else - return -1; - } + { + if (uc < 0xd800 || uc >= 0xe000) + count = 3; + else + return -1; + } #if 0 else if (uc < 0x200000) - count = 4; + count = 4; else if (uc < 0x4000000) - count = 5; + count = 5; else if (uc <= 0x7fffffff) - count = 6; + count = 6; #else else if (uc < 0x110000) - count = 4; + count = 4; #endif else - return -1; + return -1; if (n >= count) - { - switch (count) /* note: code falls through cases! */ - { + { + switch (count) /* note: code falls through cases! */ + { #if 0 - case 6: s[5] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x4000000; - case 5: s[4] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x200000; + case 6: s[5] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x4000000; + case 5: s[4] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x200000; #endif - case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000; - case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800; - case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0; - /*case 1:*/ s[0] = uc; - } - return count; - } + case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000; + case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800; + case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0; + /*case 1:*/ s[0] = uc; + } + return count; + } } return -2; } diff --git a/lib/unistring/cdefs.in.h b/lib/unistring/cdefs.in.h new file mode 100644 index 00000000..2be62c27 --- /dev/null +++ b/lib/unistring/cdefs.in.h @@ -0,0 +1,22 @@ +/* Common macro definitions for C include files. + Copyright (C) 2009 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +#ifndef _UNISTRING_CDEFS_H +#define _UNISTRING_CDEFS_H + +/* The definition of _GL_UNUSED_PARAMETER is copied here. */ + +#endif /* _UNISTRING_CDEFS_H */ diff --git a/lib/unitypes.h b/lib/unitypes.h index 515f7adc..376ffc21 100644 --- a/lib/unitypes.h +++ b/lib/unitypes.h @@ -1,5 +1,5 @@ /* Elementary types for the GNU UniString library. - Copyright (C) 2002, 2005-2006 Free Software Foundation, Inc. + Copyright (C) 2002, 2005-2006, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniwbrk.h b/lib/uniwbrk.h index c6ad971e..25cf33a8 100644 --- a/lib/uniwbrk.h +++ b/lib/uniwbrk.h @@ -1,5 +1,5 @@ /* Word breaks in Unicode strings. - Copyright (C) 2001-2003, 2005-2009 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uniwbrk/u-wordbreaks.h b/lib/uniwbrk/u-wordbreaks.h index 5ef4e8c1..b0fd301e 100644 --- a/lib/uniwbrk/u-wordbreaks.h +++ b/lib/uniwbrk/u-wordbreaks.h @@ -1,5 +1,5 @@ /* Word breaks in UTF-8/UTF-16/UTF-32 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -23,105 +23,105 @@ FUNC (const UNIT *s, size_t n, char *p) const UNIT *s_end = s + n; /* Word break property of the last character. - -1 at the very beginning of the string. */ + -1 at the very beginning of the string. */ int last_char_prop = -1; /* Format and Extend characters are ignored; this means, the mostly used - unit is the complex character (= character with subsequent ignored - characters). - Word break property of the last complex character. - -1 at the very beginning of the string. */ + unit is the complex character (= character with subsequent ignored + characters). + Word break property of the last complex character. + -1 at the very beginning of the string. */ int last_compchar_prop = -1; char *last_compchar_ptr = NULL; /* For recognizing rules involving 3 complex characters: - Word break property of the second-to-last complex character. - -1 at the very beginning of the string. */ + Word break property of the second-to-last complex character. + -1 at the very beginning of the string. */ int secondlast_compchar_prop = -1; /* Don't break inside multibyte characters. */ memset (p, 0, n); while (s < s_end) - { - ucs4_t uc; - int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); - int prop = uc_wordbreak_property (uc); + { + ucs4_t uc; + int count = U_MBTOUC_UNSAFE (&uc, s, s_end - s); + int prop = uc_wordbreak_property (uc); - /* No break at the start of the string. */ - if (last_char_prop >= 0) - { - /* No break between CR and LF. */ - if (last_char_prop == WBP_CR && prop == WBP_LF) - /* *p = 0 */; - /* Break before and after newlines. */ - else if (last_char_prop >= WBP_NEWLINE - /* same as: - last_char_prop == WBP_CR - || last_char_prop == WBP_LF - || last_char_prop == WBP_NEWLINE */ - || prop >= WBP_NEWLINE - /* same as: - prop == WBP_CR - || prop == WBP_LF - || prop == WBP_NEWLINE */) - *p = 1; - /* Ignore Format and Extend characters. */ - else if (!(prop == WBP_EXTEND || prop == WBP_FORMAT)) - { - /* No break in these situations (see UAX #29): + /* No break at the start of the string. */ + if (last_char_prop >= 0) + { + /* No break between CR and LF. */ + if (last_char_prop == WBP_CR && prop == WBP_LF) + /* *p = 0 */; + /* Break before and after newlines. */ + else if (last_char_prop >= WBP_NEWLINE + /* same as: + last_char_prop == WBP_CR + || last_char_prop == WBP_LF + || last_char_prop == WBP_NEWLINE */ + || prop >= WBP_NEWLINE + /* same as: + prop == WBP_CR + || prop == WBP_LF + || prop == WBP_NEWLINE */) + *p = 1; + /* Ignore Format and Extend characters. */ + else if (!(prop == WBP_EXTEND || prop == WBP_FORMAT)) + { + /* No break in these situations (see UAX #29): - secondlast last current + secondlast last current - ALetter (MidLetter | MidNumLet) × ALetter (WB7) - ALetter × (MidLetter | MidNumLet) ALetter (WB6) - Numeric (MidNum | MidNumLet) × Numeric (WB11) - Numeric × (MidNum | MidNumLet) Numeric (WB12) - ALetter × ALetter (WB5) - ALetter × Numeric (WB9) - Numeric × ALetter (WB10) - Numeric × Numeric (WB8) - Katakana × Katakana (WB13) - (ALetter | Numeric | Katakana) × ExtendNumLet (WB13a) - ExtendNumLet × ExtendNumLet (WB13a) - ExtendNumLet × (ALetter | Numeric | Katakana) (WB13b) - */ - /* No break across certain punctuation. Also, disable word - breaks that were recognized earlier (due to lookahead of - only one complex character). */ - if ((prop == WBP_ALETTER - && (last_compchar_prop == WBP_MIDLETTER - || last_compchar_prop == WBP_MIDNUMLET) - && secondlast_compchar_prop == WBP_ALETTER) - || (prop == WBP_NUMERIC - && (last_compchar_prop == WBP_MIDNUM - || last_compchar_prop == WBP_MIDNUMLET) - && secondlast_compchar_prop == WBP_NUMERIC)) - { - *last_compchar_ptr = 0; - /* *p = 0; */ - } - else - { - /* Perform a single table lookup. */ - if (uniwbrk_table[last_compchar_prop][prop]) - *p = 1; - /* else *p = 0; */ - } - } - } + ALetter (MidLetter | MidNumLet) × ALetter (WB7) + ALetter × (MidLetter | MidNumLet) ALetter (WB6) + Numeric (MidNum | MidNumLet) × Numeric (WB11) + Numeric × (MidNum | MidNumLet) Numeric (WB12) + ALetter × ALetter (WB5) + ALetter × Numeric (WB9) + Numeric × ALetter (WB10) + Numeric × Numeric (WB8) + Katakana × Katakana (WB13) + (ALetter | Numeric | Katakana) × ExtendNumLet (WB13a) + ExtendNumLet × ExtendNumLet (WB13a) + ExtendNumLet × (ALetter | Numeric | Katakana) (WB13b) + */ + /* No break across certain punctuation. Also, disable word + breaks that were recognized earlier (due to lookahead of + only one complex character). */ + if ((prop == WBP_ALETTER + && (last_compchar_prop == WBP_MIDLETTER + || last_compchar_prop == WBP_MIDNUMLET) + && secondlast_compchar_prop == WBP_ALETTER) + || (prop == WBP_NUMERIC + && (last_compchar_prop == WBP_MIDNUM + || last_compchar_prop == WBP_MIDNUMLET) + && secondlast_compchar_prop == WBP_NUMERIC)) + { + *last_compchar_ptr = 0; + /* *p = 0; */ + } + else + { + /* Perform a single table lookup. */ + if (uniwbrk_table[last_compchar_prop][prop]) + *p = 1; + /* else *p = 0; */ + } + } + } - last_char_prop = prop; - /* Ignore Format and Extend characters, except at the start of the string. */ - if (last_compchar_prop < 0 || !(prop == WBP_EXTEND || prop == WBP_FORMAT)) - { - secondlast_compchar_prop = last_compchar_prop; - last_compchar_prop = prop; - last_compchar_ptr = p; - } + last_char_prop = prop; + /* Ignore Format and Extend characters, except at the start of the string. */ + if (last_compchar_prop < 0 || !(prop == WBP_EXTEND || prop == WBP_FORMAT)) + { + secondlast_compchar_prop = last_compchar_prop; + last_compchar_prop = prop; + last_compchar_ptr = p; + } - s += count; - p += count; - } + s += count; + p += count; + } } } diff --git a/lib/uniwbrk/u16-wordbreaks.c b/lib/uniwbrk/u16-wordbreaks.c index 3398fd3a..ea2a53d2 100644 --- a/lib/uniwbrk/u16-wordbreaks.c +++ b/lib/uniwbrk/u16-wordbreaks.c @@ -1,5 +1,5 @@ /* Word breaks in UTF-16 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uniwbrk/u32-wordbreaks.c b/lib/uniwbrk/u32-wordbreaks.c index 6763fb9e..86a26160 100644 --- a/lib/uniwbrk/u32-wordbreaks.c +++ b/lib/uniwbrk/u32-wordbreaks.c @@ -1,5 +1,5 @@ /* Word breaks in UTF-32 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uniwbrk/u8-wordbreaks.c b/lib/uniwbrk/u8-wordbreaks.c index 59d2076d..c7edfe9e 100644 --- a/lib/uniwbrk/u8-wordbreaks.c +++ b/lib/uniwbrk/u8-wordbreaks.c @@ -1,5 +1,5 @@ /* Word breaks in UTF-8 strings. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -50,28 +50,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -98,20 +98,20 @@ main (int argc, char * argv[]) u8_wordbreaks ((uint8_t *) input, length, breaks); for (i = 0; i < length; i++) - { - switch (breaks[i]) - { - case 1: - /* U+2027 in UTF-8 encoding */ - putc (0xe2, stdout); putc (0x80, stdout); putc (0xa7, stdout); - break; - case 0: - break; - default: - abort (); - } - putc (input[i], stdout); - } + { + switch (breaks[i]) + { + case 1: + /* U+2027 in UTF-8 encoding */ + putc (0xe2, stdout); putc (0x80, stdout); putc (0xa7, stdout); + break; + case 0: + break; + default: + abort (); + } + putc (input[i], stdout); + } free (breaks); diff --git a/lib/uniwbrk/ulc-wordbreaks.c b/lib/uniwbrk/ulc-wordbreaks.c index cb6e131c..6e17026b 100644 --- a/lib/uniwbrk/ulc-wordbreaks.c +++ b/lib/uniwbrk/ulc-wordbreaks.c @@ -1,5 +1,5 @@ /* Word breaks in strings. - Copyright (C) 2001-2003, 2006-2009 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -49,60 +49,60 @@ ulc_wordbreaks (const char *s, size_t n, char *p) const char *encoding = locale_charset (); if (is_utf8_encoding (encoding)) - u8_wordbreaks ((const uint8_t *) s, n, p); + u8_wordbreaks ((const uint8_t *) s, n, p); else - { - /* Convert the string to UTF-8 and build a translation table - from offsets into s to offsets into the translated string. */ - size_t *offsets = (size_t *) malloc (n * sizeof (size_t)); - - if (offsets != NULL) - { - uint8_t *t; - size_t m; - - t = u8_conv_from_encoding (encoding, iconveh_question_mark, - s, n, offsets, NULL, &m); - if (t != NULL) - { - char *q = (char *) (m > 0 ? malloc (m) : NULL); - - if (m == 0 || q != NULL) - { - size_t i; - - /* Determine the word breaks of the UTF-8 string. */ - u8_wordbreaks (t, m, q); - - /* Translate the result back to the original string. */ - memset (p, 0, n); - for (i = 0; i < n; i++) - if (offsets[i] != (size_t)(-1)) - p[i] = q[offsets[i]]; - - free (q); - free (t); - free (offsets); - return; - } - free (t); - } - free (offsets); - } - - /* Impossible to convert. */ + { + /* Convert the string to UTF-8 and build a translation table + from offsets into s to offsets into the translated string. */ + size_t *offsets = (size_t *) malloc (n * sizeof (size_t)); + + if (offsets != NULL) + { + uint8_t *t; + size_t m; + + t = u8_conv_from_encoding (encoding, iconveh_question_mark, + s, n, offsets, NULL, &m); + if (t != NULL) + { + char *q = (char *) (m > 0 ? malloc (m) : NULL); + + if (m == 0 || q != NULL) + { + size_t i; + + /* Determine the word breaks of the UTF-8 string. */ + u8_wordbreaks (t, m, q); + + /* Translate the result back to the original string. */ + memset (p, 0, n); + for (i = 0; i < n; i++) + if (offsets[i] != (size_t)(-1)) + p[i] = q[offsets[i]]; + + free (q); + free (t); + free (offsets); + return; + } + free (t); + } + free (offsets); + } + + /* Impossible to convert. */ #if C_CTYPE_ASCII - if (is_all_ascii (s, n)) - { - /* ASCII is a subset of UTF-8. */ - u8_wordbreaks ((const uint8_t *) s, n, p); - return; - } + if (is_all_ascii (s, n)) + { + /* ASCII is a subset of UTF-8. */ + u8_wordbreaks ((const uint8_t *) s, n, p); + return; + } #endif - /* We have a non-ASCII string and cannot convert it. - Don't produce any word breaks. */ - memset (p, 0, n); - } + /* We have a non-ASCII string and cannot convert it. + Don't produce any word breaks. */ + memset (p, 0, n); + } } } @@ -127,28 +127,28 @@ read_file (FILE *stream) while (! feof (stream)) { if (size + BUFSIZE > alloc) - { - alloc = alloc + alloc / 2; - if (alloc < size + BUFSIZE) - alloc = size + BUFSIZE; - buf = realloc (buf, alloc); - if (buf == NULL) - { - fprintf (stderr, "out of memory\n"); - exit (1); - } - } + { + alloc = alloc + alloc / 2; + if (alloc < size + BUFSIZE) + alloc = size + BUFSIZE; + buf = realloc (buf, alloc); + if (buf == NULL) + { + fprintf (stderr, "out of memory\n"); + exit (1); + } + } count = fread (buf + size, 1, BUFSIZE, stream); if (count == 0) - { - if (ferror (stream)) - { - perror ("fread"); - exit (1); - } - } + { + if (ferror (stream)) + { + perror ("fread"); + exit (1); + } + } else - size += count; + size += count; } buf = realloc (buf, size + 1); if (buf == NULL) @@ -176,19 +176,19 @@ main (int argc, char * argv[]) ulc_wordbreaks (input, length, breaks); for (i = 0; i < length; i++) - { - switch (breaks[i]) - { - case 1: - putc ('|', stdout); - break; - case 0: - break; - default: - abort (); - } - putc (input[i], stdout); - } + { + switch (breaks[i]) + { + case 1: + putc ('|', stdout); + break; + case 0: + break; + default: + abort (); + } + putc (input[i], stdout); + } free (breaks); diff --git a/lib/uniwbrk/wbrkprop.h b/lib/uniwbrk/wbrkprop.h index 3b50e17e..77fd61de 100644 --- a/lib/uniwbrk/wbrkprop.h +++ b/lib/uniwbrk/wbrkprop.h @@ -2,7 +2,7 @@ /* Line breaking properties of Unicode characters. */ /* Generated automatically by gen-uni-tables for Unicode 5.1.0. */ -/* Copyright (C) 2000-2002, 2004, 2007-2009 Free Software Foundation, Inc. +/* Copyright (C) 2000-2002, 2004, 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by diff --git a/lib/uniwbrk/wbrktable.c b/lib/uniwbrk/wbrktable.c index 81a2323e..ff25fb31 100644 --- a/lib/uniwbrk/wbrktable.c +++ b/lib/uniwbrk/wbrktable.c @@ -1,5 +1,5 @@ /* Word break auxiliary table. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -22,22 +22,22 @@ /* This table contains the following rules (see UAX #29): - last current + last current - ALetter × ALetter (WB5) - ALetter × Numeric (WB9) - Numeric × ALetter (WB10) - Numeric × Numeric (WB8) - Katakana × Katakana (WB13) + ALetter × ALetter (WB5) + ALetter × Numeric (WB9) + Numeric × ALetter (WB10) + Numeric × Numeric (WB8) + Katakana × Katakana (WB13) (ALetter | Numeric | Katakana) × ExtendNumLet (WB13a) - ExtendNumLet × ExtendNumLet (WB13a) - ExtendNumLet × (ALetter | Numeric | Katakana) (WB13b) + ExtendNumLet × ExtendNumLet (WB13a) + ExtendNumLet × (ALetter | Numeric | Katakana) (WB13b) */ const unsigned char uniwbrk_table[10][8] = { /* current: OTHER MIDNUMLET NUMERIC */ - /* KATAKANA MIDLETTER EXTENDNUMLET */ - /* ALETTER MIDNUM */ + /* KATAKANA MIDLETTER EXTENDNUMLET */ + /* ALETTER MIDNUM */ /* last */ /* WBP_OTHER */ { 1, 1, 1, 1, 1, 1, 1, 1 }, /* WBP_KATAKANA */ { 1, 0, 1, 1, 1, 1, 1, 0 }, diff --git a/lib/uniwbrk/wbrktable.h b/lib/uniwbrk/wbrktable.h index 14efee90..8a13378b 100644 --- a/lib/uniwbrk/wbrktable.h +++ b/lib/uniwbrk/wbrktable.h @@ -1,5 +1,5 @@ /* Word break auxiliary table. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uniwbrk/wordbreak-property.c b/lib/uniwbrk/wordbreak-property.c index 4d0a212d..9d98b0b5 100644 --- a/lib/uniwbrk/wordbreak-property.c +++ b/lib/uniwbrk/wordbreak-property.c @@ -1,5 +1,5 @@ /* Word break property. - Copyright (C) 2001-2003, 2006-2009 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2009. This program is free software: you can redistribute it and/or modify it @@ -30,15 +30,15 @@ uc_wordbreak_property (ucs4_t uc) { int lookup1 = uniwbrkprop.level1[index1]; if (lookup1 >= 0) - { - unsigned int index2 = (uc >> wbrkprop_header_2) & wbrkprop_header_3; - int lookup2 = uniwbrkprop.level2[lookup1 + index2]; - if (lookup2 >= 0) - { - unsigned int index3 = uc & wbrkprop_header_4; - return uniwbrkprop.level3[lookup2 + index3]; - } - } + { + unsigned int index2 = (uc >> wbrkprop_header_2) & wbrkprop_header_3; + int lookup2 = uniwbrkprop.level2[lookup1 + index2]; + if (lookup2 >= 0) + { + unsigned int index3 = uc & wbrkprop_header_4; + return uniwbrkprop.level3[lookup2 + index3]; + } + } } return WBP_OTHER; } diff --git a/lib/uniwidth.h b/lib/uniwidth.h index 4f867b33..4e18162c 100644 --- a/lib/uniwidth.h +++ b/lib/uniwidth.h @@ -1,5 +1,6 @@ /* Display width functions. - Copyright (C) 2001-2002, 2005, 2007 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2005, 2007, 2009-2010 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published diff --git a/lib/uniwidth/cjk.h b/lib/uniwidth/cjk.h index 6124e1a4..5d8ef126 100644 --- a/lib/uniwidth/cjk.h +++ b/lib/uniwidth/cjk.h @@ -1,5 +1,5 @@ /* Test for CJK encoding. - Copyright (C) 2001-2002, 2005-2007 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2005-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uniwidth/u16-strwidth.c b/lib/uniwidth/u16-strwidth.c index e938bd25..01dc33b0 100644 --- a/lib/uniwidth/u16-strwidth.c +++ b/lib/uniwidth/u16-strwidth.c @@ -1,5 +1,5 @@ /* Determine display width of UTF-16 string. - Copyright (C) 2001-2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uniwidth/u16-width.c b/lib/uniwidth/u16-width.c index b866b3c9..49a1204f 100644 --- a/lib/uniwidth/u16-width.c +++ b/lib/uniwidth/u16-width.c @@ -1,5 +1,5 @@ /* Determine display width of UTF-16 string. - Copyright (C) 2001-2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -36,11 +36,11 @@ u16_width (const uint16_t *s, size_t n, const char *encoding) s += u16_mbtouc_unsafe (&uc, s, s_end - s); if (uc == 0) - break; /* end of string reached */ + break; /* end of string reached */ w = uc_width (uc, encoding); if (w >= 0) /* ignore control characters in the string */ - width += w; + width += w; } return width; diff --git a/lib/uniwidth/u32-strwidth.c b/lib/uniwidth/u32-strwidth.c index ee4eb4a5..c21e6aa1 100644 --- a/lib/uniwidth/u32-strwidth.c +++ b/lib/uniwidth/u32-strwidth.c @@ -1,5 +1,5 @@ /* Determine display width of UTF-32 string. - Copyright (C) 2001-2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uniwidth/u32-width.c b/lib/uniwidth/u32-width.c index f928fa45..32c41336 100644 --- a/lib/uniwidth/u32-width.c +++ b/lib/uniwidth/u32-width.c @@ -1,5 +1,5 @@ /* Determine display width of UTF-32 string. - Copyright (C) 2001-2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -32,11 +32,11 @@ u32_width (const uint32_t *s, size_t n, const char *encoding) int w; if (uc == 0) - break; /* end of string reached */ + break; /* end of string reached */ w = uc_width (uc, encoding); if (w >= 0) /* ignore control characters in the string */ - width += w; + width += w; } return width; diff --git a/lib/uniwidth/u8-strwidth.c b/lib/uniwidth/u8-strwidth.c index 961f26b5..d3404b30 100644 --- a/lib/uniwidth/u8-strwidth.c +++ b/lib/uniwidth/u8-strwidth.c @@ -1,5 +1,5 @@ /* Determine display width of UTF-8 string. - Copyright (C) 2001-2002, 2006 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it diff --git a/lib/uniwidth/u8-width.c b/lib/uniwidth/u8-width.c index ad0d49d8..fd27cab0 100644 --- a/lib/uniwidth/u8-width.c +++ b/lib/uniwidth/u8-width.c @@ -1,5 +1,5 @@ /* Determine display width of UTF-8 string. - Copyright (C) 2001-2002, 2006-2007 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -36,11 +36,11 @@ u8_width (const uint8_t *s, size_t n, const char *encoding) s += u8_mbtouc_unsafe (&uc, s, s_end - s); if (uc == 0) - break; /* end of string reached */ + break; /* end of string reached */ w = uc_width (uc, encoding); if (w >= 0) /* ignore control characters in the string */ - width += w; + width += w; } return width; diff --git a/lib/uniwidth/width.c b/lib/uniwidth/width.c index 25ff0c73..c88fdb66 100644 --- a/lib/uniwidth/width.c +++ b/lib/uniwidth/width.c @@ -1,5 +1,5 @@ /* Determine display width of Unicode character. - Copyright (C) 2001-2002, 2006-2009 Free Software Foundation, Inc. + Copyright (C) 2001-2002, 2006-2010 Free Software Foundation, Inc. Written by Bruno Haible , 2002. This program is free software: you can redistribute it and/or modify it @@ -310,26 +310,26 @@ uc_width (ucs4_t uc, const char *encoding) { int ind = nonspacing_table_ind[uc >> 9]; if (ind >= 0) - if ((nonspacing_table_data[64*ind + ((uc >> 3) & 63)] >> (uc & 7)) & 1) - { - if (uc > 0 && uc < 0xa0) - return -1; - else - return 0; - } + if ((nonspacing_table_data[64*ind + ((uc >> 3) & 63)] >> (uc & 7)) & 1) + { + if (uc > 0 && uc < 0xa0) + return -1; + else + return 0; + } } else if ((uc >> 9) == (0xe0000 >> 9)) { if (uc >= 0xe0100) - { - if (uc <= 0xe01ef) - return 0; - } + { + if (uc <= 0xe01ef) + return 0; + } else - { - if (uc >= 0xe0020 ? uc <= 0xe007f : uc == 0xe0001) - return 0; - } + { + if (uc >= 0xe0020 ? uc <= 0xe007f : uc == 0xe0001) + return 0; + } } /* Test for double-width character. * Generated from "grep '^....;[WF]' EastAsianWidth.txt" @@ -337,17 +337,17 @@ uc_width (ucs4_t uc, const char *encoding) */ if (uc >= 0x1100 && ((uc < 0x1160) /* Hangul Jamo */ - || (uc >= 0x2329 && uc < 0x232b) /* Angle Brackets */ - || (uc >= 0x2e80 && uc < 0xa4d0 /* CJK ... Yi */ - && !(uc == 0x303f) && !(uc >= 0x4dc0 && uc < 0x4e00)) - || (uc >= 0xac00 && uc < 0xd7a4) /* Hangul Syllables */ - || (uc >= 0xf900 && uc < 0xfb00) /* CJK Compatibility Ideographs */ - || (uc >= 0xfe10 && uc < 0xfe20) /* Presentation Forms for Vertical */ - || (uc >= 0xfe30 && uc < 0xfe70) /* CJK Compatibility Forms */ - || (uc >= 0xff00 && uc < 0xff61) /* Fullwidth Forms */ - || (uc >= 0xffe0 && uc < 0xffe7) /* Fullwidth Signs */ - || (uc >= 0x20000 && uc <= 0x2a6d6) /* CJK */ - || (uc >= 0x2f800 && uc <= 0x2fa1d) /* CJK Compatibility Ideographs */ + || (uc >= 0x2329 && uc < 0x232b) /* Angle Brackets */ + || (uc >= 0x2e80 && uc < 0xa4d0 /* CJK ... Yi */ + && !(uc == 0x303f) && !(uc >= 0x4dc0 && uc < 0x4e00)) + || (uc >= 0xac00 && uc < 0xd7a4) /* Hangul Syllables */ + || (uc >= 0xf900 && uc < 0xfb00) /* CJK Compatibility Ideographs */ + || (uc >= 0xfe10 && uc < 0xfe20) /* Presentation Forms for Vertical */ + || (uc >= 0xfe30 && uc < 0xfe70) /* CJK Compatibility Forms */ + || (uc >= 0xff00 && uc < 0xff61) /* Fullwidth Forms */ + || (uc >= 0xffe0 && uc < 0xffe7) /* Fullwidth Signs */ + || (uc >= 0x20000 && uc <= 0x2a6d6) /* CJK */ + || (uc >= 0x2f800 && uc <= 0x2fa1d) /* CJK Compatibility Ideographs */ ) ) return 2; /* In ancient CJK encodings, Cyrillic and most other characters are diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 35db978c..daaec6ac 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -1,5 +1,5 @@ /* vsprintf with automatic memory allocation. - Copyright (C) 1999, 2002-2009 Free Software Foundation, Inc. + Copyright (C) 1999, 2002-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -67,13 +67,13 @@ # endif #endif -#include /* localeconv() */ -#include /* snprintf(), sprintf() */ -#include /* abort(), malloc(), realloc(), free() */ -#include /* memcpy(), strlen() */ -#include /* errno */ -#include /* CHAR_BIT */ -#include /* DBL_MAX_EXP, LDBL_MAX_EXP */ +#include /* localeconv() */ +#include /* snprintf(), sprintf() */ +#include /* abort(), malloc(), realloc(), free() */ +#include /* memcpy(), strlen() */ +#include /* errno */ +#include /* CHAR_BIT */ +#include /* DBL_MAX_EXP, LDBL_MAX_EXP */ #if HAVE_NL_LANGINFO # include #endif @@ -148,8 +148,14 @@ # define USE_SNPRINTF 1 # if HAVE_DECL__SNWPRINTF /* On Windows, the function swprintf() has a different signature than - on Unix; we use the _snwprintf() function instead. */ -# define SNPRINTF _snwprintf + on Unix; we use the function _snwprintf() or - on mingw - snwprintf() + instead. The mingw function snwprintf() has fewer bugs than the + MSVCRT function _snwprintf(), so prefer that. */ +# if defined __MINGW32__ +# define SNPRINTF snwprintf +# else +# define SNPRINTF _snwprintf +# endif # else /* Unix. */ # define SNPRINTF swprintf @@ -167,8 +173,15 @@ # define USE_SNPRINTF 0 # endif # if HAVE_DECL__SNPRINTF - /* Windows. */ -# define SNPRINTF _snprintf + /* Windows. The mingw function snprintf() has fewer bugs than the MSVCRT + function _snprintf(), so prefer that. */ +# if defined __MINGW32__ +# define SNPRINTF snprintf + /* Here we need to call the native snprintf, not rpl_snprintf. */ +# undef snprintf +# else +# define SNPRINTF _snprintf +# endif # else /* Unix. */ # define SNPRINTF snprintf @@ -194,7 +207,7 @@ #undef remainder #define remainder rem -#if !USE_SNPRINTF && !WIDE_CHAR_VERSION +#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && !WIDE_CHAR_VERSION # if (HAVE_STRNLEN && !defined _AIX) # define local_strnlen strnlen # else @@ -210,7 +223,7 @@ local_strnlen (const char *string, size_t maxlen) # endif #endif -#if (!USE_SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T && (WIDE_CHAR_VERSION || DCHAR_IS_TCHAR) +#if (((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && WIDE_CHAR_VERSION) || ((!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && !WIDE_CHAR_VERSION && DCHAR_IS_TCHAR)) && HAVE_WCHAR_T # if HAVE_WCSLEN # define local_wcslen wcslen # else @@ -233,7 +246,7 @@ local_wcslen (const wchar_t *s) # endif #endif -#if !USE_SNPRINTF && HAVE_WCHAR_T && WIDE_CHAR_VERSION +#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99) && HAVE_WCHAR_T && WIDE_CHAR_VERSION # if HAVE_WCSNLEN # define local_wcsnlen wcsnlen # else @@ -257,14 +270,14 @@ local_wcsnlen (const wchar_t *s, size_t maxlen) # ifndef decimal_point_char_defined # define decimal_point_char_defined 1 static char -decimal_point_char () +decimal_point_char (void) { const char *point; /* Determine it in a multithread-safe way. We know nl_langinfo is - multithread-safe on glibc systems, but is not required to be multithread- - safe by POSIX. sprintf(), however, is multithread-safe. localeconv() - is rarely multithread-safe. */ -# if HAVE_NL_LANGINFO && __GLIBC__ + multithread-safe on glibc systems and MacOS X systems, but is not required + to be multithread-safe by POSIX. sprintf(), however, is multithread-safe. + localeconv() is rarely multithread-safe. */ +# if HAVE_NL_LANGINFO && (__GLIBC__ || (defined __APPLE__ && defined __MACH__)) point = nl_langinfo (RADIXCHAR); # elif 1 char pointbuf[5]; @@ -364,26 +377,26 @@ multiply (mpn_t src1, mpn_t src2, mpn_t *dest) dlen = len1 + len2; dp = (mp_limb_t *) malloc (dlen * sizeof (mp_limb_t)); if (dp == NULL) - return NULL; + return NULL; for (k = len2; k > 0; ) - dp[--k] = 0; + dp[--k] = 0; for (i = 0; i < len1; i++) - { - mp_limb_t digit1 = p1[i]; - mp_twolimb_t carry = 0; - for (j = 0; j < len2; j++) - { - mp_limb_t digit2 = p2[j]; - carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; - carry += dp[i + j]; - dp[i + j] = (mp_limb_t) carry; - carry = carry >> GMP_LIMB_BITS; - } - dp[i + len2] = (mp_limb_t) carry; - } + { + mp_limb_t digit1 = p1[i]; + mp_twolimb_t carry = 0; + for (j = 0; j < len2; j++) + { + mp_limb_t digit2 = p2[j]; + carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; + carry += dp[i + j]; + dp[i + j] = (mp_limb_t) carry; + carry = carry >> GMP_LIMB_BITS; + } + dp[i + len2] = (mp_limb_t) carry; + } /* Normalise. */ while (dlen > 0 && dp[dlen - 1] == 0) - dlen--; + dlen--; dest->nlimbs = dlen; dest->limbs = dp; } @@ -477,12 +490,12 @@ divide (mpn_t a, mpn_t b, mpn_t *q) for (;;) { if (b_len == 0) - /* Division by zero. */ - abort (); + /* Division by zero. */ + abort (); if (b_ptr[b_len - 1] == 0) - b_len--; + b_len--; else - break; + break; } /* Here m = a_len >= 0 and n = b_len > 0. */ @@ -499,261 +512,261 @@ divide (mpn_t a, mpn_t b, mpn_t *q) else if (b_len == 1) { /* n=1: single precision division. - beta^(m-1) <= a < beta^m ==> beta^(m-2) <= a/b < beta^m */ + beta^(m-1) <= a < beta^m ==> beta^(m-2) <= a/b < beta^m */ r_ptr = roomptr; q_ptr = roomptr + 1; { - mp_limb_t den = b_ptr[0]; - mp_limb_t remainder = 0; - const mp_limb_t *sourceptr = a_ptr + a_len; - mp_limb_t *destptr = q_ptr + a_len; - size_t count; - for (count = a_len; count > 0; count--) - { - mp_twolimb_t num = - ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr; - *--destptr = num / den; - remainder = num % den; - } - /* Normalise and store r. */ - if (remainder > 0) - { - r_ptr[0] = remainder; - r_len = 1; - } - else - r_len = 0; - /* Normalise q. */ - q_len = a_len; - if (q_ptr[q_len - 1] == 0) - q_len--; + mp_limb_t den = b_ptr[0]; + mp_limb_t remainder = 0; + const mp_limb_t *sourceptr = a_ptr + a_len; + mp_limb_t *destptr = q_ptr + a_len; + size_t count; + for (count = a_len; count > 0; count--) + { + mp_twolimb_t num = + ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--sourceptr; + *--destptr = num / den; + remainder = num % den; + } + /* Normalise and store r. */ + if (remainder > 0) + { + r_ptr[0] = remainder; + r_len = 1; + } + else + r_len = 0; + /* Normalise q. */ + q_len = a_len; + if (q_ptr[q_len - 1] == 0) + q_len--; } } else { /* n>1: multiple precision division. - beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==> - beta^(m-n-1) <= a/b < beta^(m-n+1). */ + beta^(m-1) <= a < beta^m, beta^(n-1) <= b < beta^n ==> + beta^(m-n-1) <= a/b < beta^(m-n+1). */ /* Determine s. */ size_t s; { - mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ - s = 31; - if (msd >= 0x10000) - { - msd = msd >> 16; - s -= 16; - } - if (msd >= 0x100) - { - msd = msd >> 8; - s -= 8; - } - if (msd >= 0x10) - { - msd = msd >> 4; - s -= 4; - } - if (msd >= 0x4) - { - msd = msd >> 2; - s -= 2; - } - if (msd >= 0x2) - { - msd = msd >> 1; - s -= 1; - } + mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */ + s = 31; + if (msd >= 0x10000) + { + msd = msd >> 16; + s -= 16; + } + if (msd >= 0x100) + { + msd = msd >> 8; + s -= 8; + } + if (msd >= 0x10) + { + msd = msd >> 4; + s -= 4; + } + if (msd >= 0x4) + { + msd = msd >> 2; + s -= 2; + } + if (msd >= 0x2) + { + msd = msd >> 1; + s -= 1; + } } /* 0 <= s < GMP_LIMB_BITS. - Copy b, shifting it left by s bits. */ + Copy b, shifting it left by s bits. */ if (s > 0) - { - tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t)); - if (tmp_roomptr == NULL) - { - free (roomptr); - return NULL; - } - { - const mp_limb_t *sourceptr = b_ptr; - mp_limb_t *destptr = tmp_roomptr; - mp_twolimb_t accu = 0; - size_t count; - for (count = b_len; count > 0; count--) - { - accu += (mp_twolimb_t) *sourceptr++ << s; - *destptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - /* accu must be zero, since that was how s was determined. */ - if (accu != 0) - abort (); - } - b_ptr = tmp_roomptr; - } + { + tmp_roomptr = (mp_limb_t *) malloc (b_len * sizeof (mp_limb_t)); + if (tmp_roomptr == NULL) + { + free (roomptr); + return NULL; + } + { + const mp_limb_t *sourceptr = b_ptr; + mp_limb_t *destptr = tmp_roomptr; + mp_twolimb_t accu = 0; + size_t count; + for (count = b_len; count > 0; count--) + { + accu += (mp_twolimb_t) *sourceptr++ << s; + *destptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + /* accu must be zero, since that was how s was determined. */ + if (accu != 0) + abort (); + } + b_ptr = tmp_roomptr; + } /* Copy a, shifting it left by s bits, yields r. - Memory layout: - At the beginning: r = roomptr[0..a_len], - at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */ + Memory layout: + At the beginning: r = roomptr[0..a_len], + at the end: r = roomptr[0..b_len-1], q = roomptr[b_len..a_len] */ r_ptr = roomptr; if (s == 0) - { - memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t)); - r_ptr[a_len] = 0; - } + { + memcpy (r_ptr, a_ptr, a_len * sizeof (mp_limb_t)); + r_ptr[a_len] = 0; + } else - { - const mp_limb_t *sourceptr = a_ptr; - mp_limb_t *destptr = r_ptr; - mp_twolimb_t accu = 0; - size_t count; - for (count = a_len; count > 0; count--) - { - accu += (mp_twolimb_t) *sourceptr++ << s; - *destptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - *destptr++ = (mp_limb_t) accu; - } + { + const mp_limb_t *sourceptr = a_ptr; + mp_limb_t *destptr = r_ptr; + mp_twolimb_t accu = 0; + size_t count; + for (count = a_len; count > 0; count--) + { + accu += (mp_twolimb_t) *sourceptr++ << s; + *destptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + *destptr++ = (mp_limb_t) accu; + } q_ptr = roomptr + b_len; q_len = a_len - b_len + 1; /* q will have m-n+1 limbs */ { - size_t j = a_len - b_len; /* m-n */ - mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */ - mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */ - mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */ - ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd; - /* Division loop, traversed m-n+1 times. - j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */ - for (;;) - { - mp_limb_t q_star; - mp_limb_t c1; - if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */ - { - /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */ - mp_twolimb_t num = - ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS) - | r_ptr[j + b_len - 1]; - q_star = num / b_msd; - c1 = num % b_msd; - } - else - { - /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */ - q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */ - /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta - <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta - <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) - {<= beta !}. - If yes, jump directly to the subtraction loop. - (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta - <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */ - if (r_ptr[j + b_len] > b_msd - || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd) - /* r[j+n] >= b[n-1]+1 or - r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a - carry. */ - goto subtract; - } - /* q_star = q*, - c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, 0, decrease it by - b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2 - this can happen only twice. */ - if (c3 > c2) - { - q_star = q_star - 1; /* q* := q* - 1 */ - if (c3 - c2 > b_msdd) - q_star = q_star - 1; /* q* := q* - 1 */ - } - } - if (q_star > 0) - subtract: - { - /* Subtract r := r - b * q* * beta^j. */ - mp_limb_t cr; - { - const mp_limb_t *sourceptr = b_ptr; - mp_limb_t *destptr = r_ptr + j; - mp_twolimb_t carry = 0; - size_t count; - for (count = b_len; count > 0; count--) - { - /* Here 0 <= carry <= q*. */ - carry = - carry - + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++ - + (mp_limb_t) ~(*destptr); - /* Here 0 <= carry <= beta*q* + beta-1. */ - *destptr++ = ~(mp_limb_t) carry; - carry = carry >> GMP_LIMB_BITS; /* <= q* */ - } - cr = (mp_limb_t) carry; - } - /* Subtract cr from r_ptr[j + b_len], then forget about - r_ptr[j + b_len]. */ - if (cr > r_ptr[j + b_len]) - { - /* Subtraction gave a carry. */ - q_star = q_star - 1; /* q* := q* - 1 */ - /* Add b back. */ - { - const mp_limb_t *sourceptr = b_ptr; - mp_limb_t *destptr = r_ptr + j; - mp_limb_t carry = 0; - size_t count; - for (count = b_len; count > 0; count--) - { - mp_limb_t source1 = *sourceptr++; - mp_limb_t source2 = *destptr; - *destptr++ = source1 + source2 + carry; - carry = - (carry - ? source1 >= (mp_limb_t) ~source2 - : source1 > (mp_limb_t) ~source2); - } - } - /* Forget about the carry and about r[j+n]. */ - } - } - /* q* is determined. Store it as q[j]. */ - q_ptr[j] = q_star; - if (j == 0) - break; - j--; - } + size_t j = a_len - b_len; /* m-n */ + mp_limb_t b_msd = b_ptr[b_len - 1]; /* b[n-1] */ + mp_limb_t b_2msd = b_ptr[b_len - 2]; /* b[n-2] */ + mp_twolimb_t b_msdd = /* b[n-1]*beta+b[n-2] */ + ((mp_twolimb_t) b_msd << GMP_LIMB_BITS) | b_2msd; + /* Division loop, traversed m-n+1 times. + j counts down, b is unchanged, beta/2 <= b[n-1] < beta. */ + for (;;) + { + mp_limb_t q_star; + mp_limb_t c1; + if (r_ptr[j + b_len] < b_msd) /* r[j+n] < b[n-1] ? */ + { + /* Divide r[j+n]*beta+r[j+n-1] by b[n-1], no overflow. */ + mp_twolimb_t num = + ((mp_twolimb_t) r_ptr[j + b_len] << GMP_LIMB_BITS) + | r_ptr[j + b_len - 1]; + q_star = num / b_msd; + c1 = num % b_msd; + } + else + { + /* Overflow, hence r[j+n]*beta+r[j+n-1] >= beta*b[n-1]. */ + q_star = (mp_limb_t)~(mp_limb_t)0; /* q* = beta-1 */ + /* Test whether r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] >= beta + <==> r[j+n]*beta+r[j+n-1] + b[n-1] >= beta*b[n-1]+beta + <==> b[n-1] < floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) + {<= beta !}. + If yes, jump directly to the subtraction loop. + (Otherwise, r[j+n]*beta+r[j+n-1] - (beta-1)*b[n-1] < beta + <==> floor((r[j+n]*beta+r[j+n-1]+b[n-1])/beta) = b[n-1] ) */ + if (r_ptr[j + b_len] > b_msd + || (c1 = r_ptr[j + b_len - 1] + b_msd) < b_msd) + /* r[j+n] >= b[n-1]+1 or + r[j+n] = b[n-1] and the addition r[j+n-1]+b[n-1] gives a + carry. */ + goto subtract; + } + /* q_star = q*, + c1 = (r[j+n]*beta+r[j+n-1]) - q* * b[n-1] (>=0, 0, decrease it by + b[n-1]*beta+b[n-2]. Because of b[n-1]*beta+b[n-2] >= beta^2/2 + this can happen only twice. */ + if (c3 > c2) + { + q_star = q_star - 1; /* q* := q* - 1 */ + if (c3 - c2 > b_msdd) + q_star = q_star - 1; /* q* := q* - 1 */ + } + } + if (q_star > 0) + subtract: + { + /* Subtract r := r - b * q* * beta^j. */ + mp_limb_t cr; + { + const mp_limb_t *sourceptr = b_ptr; + mp_limb_t *destptr = r_ptr + j; + mp_twolimb_t carry = 0; + size_t count; + for (count = b_len; count > 0; count--) + { + /* Here 0 <= carry <= q*. */ + carry = + carry + + (mp_twolimb_t) q_star * (mp_twolimb_t) *sourceptr++ + + (mp_limb_t) ~(*destptr); + /* Here 0 <= carry <= beta*q* + beta-1. */ + *destptr++ = ~(mp_limb_t) carry; + carry = carry >> GMP_LIMB_BITS; /* <= q* */ + } + cr = (mp_limb_t) carry; + } + /* Subtract cr from r_ptr[j + b_len], then forget about + r_ptr[j + b_len]. */ + if (cr > r_ptr[j + b_len]) + { + /* Subtraction gave a carry. */ + q_star = q_star - 1; /* q* := q* - 1 */ + /* Add b back. */ + { + const mp_limb_t *sourceptr = b_ptr; + mp_limb_t *destptr = r_ptr + j; + mp_limb_t carry = 0; + size_t count; + for (count = b_len; count > 0; count--) + { + mp_limb_t source1 = *sourceptr++; + mp_limb_t source2 = *destptr; + *destptr++ = source1 + source2 + carry; + carry = + (carry + ? source1 >= (mp_limb_t) ~source2 + : source1 > (mp_limb_t) ~source2); + } + } + /* Forget about the carry and about r[j+n]. */ + } + } + /* q* is determined. Store it as q[j]. */ + q_ptr[j] = q_star; + if (j == 0) + break; + j--; + } } r_len = b_len; /* Normalise q. */ if (q_ptr[q_len - 1] == 0) - q_len--; + q_len--; # if 0 /* Not needed here, since we need r only to compare it with b/2, and - b is shifted left by s bits. */ + b is shifted left by s bits. */ /* Shift r right by s bits. */ if (s > 0) - { - mp_limb_t ptr = r_ptr + r_len; - mp_twolimb_t accu = 0; - size_t count; - for (count = r_len; count > 0; count--) - { - accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS; - accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s); - *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS); - } - } + { + mp_limb_t ptr = r_ptr + r_len; + mp_twolimb_t accu = 0; + size_t count; + for (count = r_len; count > 0; count--) + { + accu = (mp_twolimb_t) (mp_limb_t) accu << GMP_LIMB_BITS; + accu += (mp_twolimb_t) *--ptr << (GMP_LIMB_BITS - s); + *ptr = (mp_limb_t) (accu >> GMP_LIMB_BITS); + } + } # endif /* Normalise r. */ while (r_len > 0 && r_ptr[r_len - 1] == 0) - r_len--; + r_len--; } /* Compare r << 1 with b. */ if (r_len > b_len) @@ -762,17 +775,17 @@ divide (mpn_t a, mpn_t b, mpn_t *q) size_t i; for (i = b_len;;) { - mp_limb_t r_i = - (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0) - | (i < r_len ? r_ptr[i] << 1 : 0); - mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0); - if (r_i > b_i) - goto increment_q; - if (r_i < b_i) - goto keep_q; - if (i == 0) - break; - i--; + mp_limb_t r_i = + (i <= r_len && i > 0 ? r_ptr[i - 1] >> (GMP_LIMB_BITS - 1) : 0) + | (i < r_len ? r_ptr[i] << 1 : 0); + mp_limb_t b_i = (i < b_len ? b_ptr[i] : 0); + if (r_i > b_i) + goto increment_q; + if (r_i < b_i) + goto keep_q; + if (i == 0) + break; + i--; } } if (q_len > 0 && ((q_ptr[0] & 1) != 0)) @@ -781,8 +794,8 @@ divide (mpn_t a, mpn_t b, mpn_t *q) { size_t i; for (i = 0; i < q_len; i++) - if (++(q_ptr[i]) != 0) - goto keep_q; + if (++(q_ptr[i]) != 0) + goto keep_q; q_ptr[q_len++] = 1; } keep_q: @@ -811,36 +824,36 @@ convert_to_decimal (mpn_t a, size_t extra_zeroes) { char *d_ptr = c_ptr; for (; extra_zeroes > 0; extra_zeroes--) - *d_ptr++ = '0'; + *d_ptr++ = '0'; while (a_len > 0) - { - /* Divide a by 10^9, in-place. */ - mp_limb_t remainder = 0; - mp_limb_t *ptr = a_ptr + a_len; - size_t count; - for (count = a_len; count > 0; count--) - { - mp_twolimb_t num = - ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr; - *ptr = num / 1000000000; - remainder = num % 1000000000; - } - /* Store the remainder as 9 decimal digits. */ - for (count = 9; count > 0; count--) - { - *d_ptr++ = '0' + (remainder % 10); - remainder = remainder / 10; - } - /* Normalize a. */ - if (a_ptr[a_len - 1] == 0) - a_len--; - } + { + /* Divide a by 10^9, in-place. */ + mp_limb_t remainder = 0; + mp_limb_t *ptr = a_ptr + a_len; + size_t count; + for (count = a_len; count > 0; count--) + { + mp_twolimb_t num = + ((mp_twolimb_t) remainder << GMP_LIMB_BITS) | *--ptr; + *ptr = num / 1000000000; + remainder = num % 1000000000; + } + /* Store the remainder as 9 decimal digits. */ + for (count = 9; count > 0; count--) + { + *d_ptr++ = '0' + (remainder % 10); + remainder = remainder / 10; + } + /* Normalize a. */ + if (a_ptr[a_len - 1] == 0) + a_len--; + } /* Remove leading zeroes. */ while (d_ptr > c_ptr && d_ptr[-1] == '0') - d_ptr--; + d_ptr--; /* But keep at least one zero. */ if (d_ptr == c_ptr) - *d_ptr++ = '0'; + *d_ptr++ = '0'; /* Terminate the string. */ *d_ptr = '\0'; } @@ -885,12 +898,12 @@ decode_long_double (long double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; } # else @@ -900,7 +913,7 @@ decode_long_double (long double x, int *ep, mpn_t *mp) d = (int) y; y -= d; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); m.limbs[LDBL_MANT_BIT / GMP_LIMB_BITS] = d; } # endif @@ -912,12 +925,12 @@ decode_long_double (long double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0L && y < 1.0L)) - abort (); + abort (); m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; } #if 0 /* On FreeBSD 6.1/x86, 'long double' numbers sometimes have excess @@ -973,12 +986,12 @@ decode_double (double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = (hi << (GMP_LIMB_BITS / 2)) | lo; } # else @@ -988,7 +1001,7 @@ decode_double (double x, int *ep, mpn_t *mp) d = (int) y; y -= d; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); m.limbs[DBL_MANT_BIT / GMP_LIMB_BITS] = d; } # endif @@ -1000,12 +1013,12 @@ decode_double (double x, int *ep, mpn_t *mp) hi = (int) y; y -= hi; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); y *= (mp_limb_t) 1 << (GMP_LIMB_BITS / 2); lo = (int) y; y -= lo; if (!(y >= 0.0 && y < 1.0)) - abort (); + abort (); m.limbs[--i] = (hi << (GMP_LIMB_BITS / 2)) | lo; } if (!(y == 0.0)) @@ -1063,8 +1076,8 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) abs_n = (n >= 0 ? n : -n); abs_s = (s >= 0 ? s : -s); pow5_ptr = (mp_limb_t *) malloc (((int)(abs_n * (2.322f / GMP_LIMB_BITS)) + 1 - + abs_s / GMP_LIMB_BITS + 1) - * sizeof (mp_limb_t)); + + abs_s / GMP_LIMB_BITS + 1) + * sizeof (mp_limb_t)); if (pow5_ptr == NULL) { free (memory); @@ -1077,26 +1090,26 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) if (abs_n > 0) { static mp_limb_t const small_pow5[13 + 1] = - { - 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, - 48828125, 244140625, 1220703125 - }; + { + 1, 5, 25, 125, 625, 3125, 15625, 78125, 390625, 1953125, 9765625, + 48828125, 244140625, 1220703125 + }; unsigned int n13; for (n13 = 0; n13 <= abs_n; n13 += 13) - { - mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13]; - size_t j; - mp_twolimb_t carry = 0; - for (j = 0; j < pow5_len; j++) - { - mp_limb_t digit2 = pow5_ptr[j]; - carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; - pow5_ptr[j] = (mp_limb_t) carry; - carry = carry >> GMP_LIMB_BITS; - } - if (carry > 0) - pow5_ptr[pow5_len++] = (mp_limb_t) carry; - } + { + mp_limb_t digit1 = small_pow5[n13 + 13 <= abs_n ? 13 : abs_n - n13]; + size_t j; + mp_twolimb_t carry = 0; + for (j = 0; j < pow5_len; j++) + { + mp_limb_t digit2 = pow5_ptr[j]; + carry += (mp_twolimb_t) digit1 * (mp_twolimb_t) digit2; + pow5_ptr[j] = (mp_limb_t) carry; + carry = carry >> GMP_LIMB_BITS; + } + if (carry > 0) + pow5_ptr[pow5_len++] = (mp_limb_t) carry; + } } s_limbs = abs_s / GMP_LIMB_BITS; s_bits = abs_s % GMP_LIMB_BITS; @@ -1104,129 +1117,129 @@ scale10_round_decimal_decoded (int e, mpn_t m, void *memory, int n) { /* Multiply with 2^|s|. */ if (s_bits > 0) - { - mp_limb_t *ptr = pow5_ptr; - mp_twolimb_t accu = 0; - size_t count; - for (count = pow5_len; count > 0; count--) - { - accu += (mp_twolimb_t) *ptr << s_bits; - *ptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - if (accu > 0) - { - *ptr = (mp_limb_t) accu; - pow5_len++; - } - } + { + mp_limb_t *ptr = pow5_ptr; + mp_twolimb_t accu = 0; + size_t count; + for (count = pow5_len; count > 0; count--) + { + accu += (mp_twolimb_t) *ptr << s_bits; + *ptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + if (accu > 0) + { + *ptr = (mp_limb_t) accu; + pow5_len++; + } + } if (s_limbs > 0) - { - size_t count; - for (count = pow5_len; count > 0;) - { - count--; - pow5_ptr[s_limbs + count] = pow5_ptr[count]; - } - for (count = s_limbs; count > 0;) - { - count--; - pow5_ptr[count] = 0; - } - pow5_len += s_limbs; - } + { + size_t count; + for (count = pow5_len; count > 0;) + { + count--; + pow5_ptr[s_limbs + count] = pow5_ptr[count]; + } + for (count = s_limbs; count > 0;) + { + count--; + pow5_ptr[count] = 0; + } + pow5_len += s_limbs; + } pow5.limbs = pow5_ptr; pow5.nlimbs = pow5_len; if (n >= 0) - { - /* Multiply m with pow5. No division needed. */ - z_memory = multiply (m, pow5, &z); - } + { + /* Multiply m with pow5. No division needed. */ + z_memory = multiply (m, pow5, &z); + } else - { - /* Divide m by pow5 and round. */ - z_memory = divide (m, pow5, &z); - } + { + /* Divide m by pow5 and round. */ + z_memory = divide (m, pow5, &z); + } } else { pow5.limbs = pow5_ptr; pow5.nlimbs = pow5_len; if (n >= 0) - { - /* n >= 0, s < 0. - Multiply m with pow5, then divide by 2^|s|. */ - mpn_t numerator; - mpn_t denominator; - void *tmp_memory; - tmp_memory = multiply (m, pow5, &numerator); - if (tmp_memory == NULL) - { - free (pow5_ptr); - free (memory); - return NULL; - } - /* Construct 2^|s|. */ - { - mp_limb_t *ptr = pow5_ptr + pow5_len; - size_t i; - for (i = 0; i < s_limbs; i++) - ptr[i] = 0; - ptr[s_limbs] = (mp_limb_t) 1 << s_bits; - denominator.limbs = ptr; - denominator.nlimbs = s_limbs + 1; - } - z_memory = divide (numerator, denominator, &z); - free (tmp_memory); - } + { + /* n >= 0, s < 0. + Multiply m with pow5, then divide by 2^|s|. */ + mpn_t numerator; + mpn_t denominator; + void *tmp_memory; + tmp_memory = multiply (m, pow5, &numerator); + if (tmp_memory == NULL) + { + free (pow5_ptr); + free (memory); + return NULL; + } + /* Construct 2^|s|. */ + { + mp_limb_t *ptr = pow5_ptr + pow5_len; + size_t i; + for (i = 0; i < s_limbs; i++) + ptr[i] = 0; + ptr[s_limbs] = (mp_limb_t) 1 << s_bits; + denominator.limbs = ptr; + denominator.nlimbs = s_limbs + 1; + } + z_memory = divide (numerator, denominator, &z); + free (tmp_memory); + } else - { - /* n < 0, s > 0. - Multiply m with 2^s, then divide by pow5. */ - mpn_t numerator; - mp_limb_t *num_ptr; - num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1) - * sizeof (mp_limb_t)); - if (num_ptr == NULL) - { - free (pow5_ptr); - free (memory); - return NULL; - } - { - mp_limb_t *destptr = num_ptr; - { - size_t i; - for (i = 0; i < s_limbs; i++) - *destptr++ = 0; - } - if (s_bits > 0) - { - const mp_limb_t *sourceptr = m.limbs; - mp_twolimb_t accu = 0; - size_t count; - for (count = m.nlimbs; count > 0; count--) - { - accu += (mp_twolimb_t) *sourceptr++ << s_bits; - *destptr++ = (mp_limb_t) accu; - accu = accu >> GMP_LIMB_BITS; - } - if (accu > 0) - *destptr++ = (mp_limb_t) accu; - } - else - { - const mp_limb_t *sourceptr = m.limbs; - size_t count; - for (count = m.nlimbs; count > 0; count--) - *destptr++ = *sourceptr++; - } - numerator.limbs = num_ptr; - numerator.nlimbs = destptr - num_ptr; - } - z_memory = divide (numerator, pow5, &z); - free (num_ptr); - } + { + /* n < 0, s > 0. + Multiply m with 2^s, then divide by pow5. */ + mpn_t numerator; + mp_limb_t *num_ptr; + num_ptr = (mp_limb_t *) malloc ((m.nlimbs + s_limbs + 1) + * sizeof (mp_limb_t)); + if (num_ptr == NULL) + { + free (pow5_ptr); + free (memory); + return NULL; + } + { + mp_limb_t *destptr = num_ptr; + { + size_t i; + for (i = 0; i < s_limbs; i++) + *destptr++ = 0; + } + if (s_bits > 0) + { + const mp_limb_t *sourceptr = m.limbs; + mp_twolimb_t accu = 0; + size_t count; + for (count = m.nlimbs; count > 0; count--) + { + accu += (mp_twolimb_t) *sourceptr++ << s_bits; + *destptr++ = (mp_limb_t) accu; + accu = accu >> GMP_LIMB_BITS; + } + if (accu > 0) + *destptr++ = (mp_limb_t) accu; + } + else + { + const mp_limb_t *sourceptr = m.limbs; + size_t count; + for (count = m.nlimbs; count > 0; count--) + *destptr++ = *sourceptr++; + } + numerator.limbs = num_ptr; + numerator.nlimbs = destptr - num_ptr; + } + z_memory = divide (numerator, pow5, &z); + free (num_ptr); + } } free (pow5_ptr); free (memory); @@ -1298,35 +1311,35 @@ floorlog10l (long double x) if (y < 0.5L) { while (y < (1.0L / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) - { - y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); - exp -= GMP_LIMB_BITS; - } + { + y *= 1.0L * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); + exp -= GMP_LIMB_BITS; + } if (y < (1.0L / (1 << 16))) - { - y *= 1.0L * (1 << 16); - exp -= 16; - } + { + y *= 1.0L * (1 << 16); + exp -= 16; + } if (y < (1.0L / (1 << 8))) - { - y *= 1.0L * (1 << 8); - exp -= 8; - } + { + y *= 1.0L * (1 << 8); + exp -= 8; + } if (y < (1.0L / (1 << 4))) - { - y *= 1.0L * (1 << 4); - exp -= 4; - } + { + y *= 1.0L * (1 << 4); + exp -= 4; + } if (y < (1.0L / (1 << 2))) - { - y *= 1.0L * (1 << 2); - exp -= 2; - } + { + y *= 1.0L * (1 << 2); + exp -= 2; + } if (y < (1.0L / (1 << 1))) - { - y *= 1.0L * (1 << 1); - exp -= 1; - } + { + y *= 1.0L * (1 << 1); + exp -= 1; + } } if (!(y >= 0.5L && y < 1.0L)) abort (); @@ -1389,35 +1402,35 @@ floorlog10 (double x) if (y < 0.5) { while (y < (1.0 / (1 << (GMP_LIMB_BITS / 2)) / (1 << (GMP_LIMB_BITS / 2)))) - { - y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); - exp -= GMP_LIMB_BITS; - } + { + y *= 1.0 * (1 << (GMP_LIMB_BITS / 2)) * (1 << (GMP_LIMB_BITS / 2)); + exp -= GMP_LIMB_BITS; + } if (y < (1.0 / (1 << 16))) - { - y *= 1.0 * (1 << 16); - exp -= 16; - } + { + y *= 1.0 * (1 << 16); + exp -= 16; + } if (y < (1.0 / (1 << 8))) - { - y *= 1.0 * (1 << 8); - exp -= 8; - } + { + y *= 1.0 * (1 << 8); + exp -= 8; + } if (y < (1.0 / (1 << 4))) - { - y *= 1.0 * (1 << 4); - exp -= 4; - } + { + y *= 1.0 * (1 << 4); + exp -= 4; + } if (y < (1.0 / (1 << 2))) - { - y *= 1.0 * (1 << 2); - exp -= 2; - } + { + y *= 1.0 * (1 << 2); + exp -= 2; + } if (y < (1.0 / (1 << 1))) - { - y *= 1.0 * (1 << 1); - exp -= 1; - } + { + y *= 1.0 * (1 << 1); + exp -= 1; + } } if (!(y >= 0.5 && y < 1.0)) abort (); @@ -1474,9 +1487,261 @@ is_borderline (const char *digits, size_t precision) #endif +#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 + +/* Use a different function name, to make it possible that the 'wchar_t' + parametrization and the 'char' parametrization get compiled in the same + translation unit. */ +# if WIDE_CHAR_VERSION +# define MAX_ROOM_NEEDED wmax_room_needed +# else +# define MAX_ROOM_NEEDED max_room_needed +# endif + +/* Returns the number of TCHAR_T units needed as temporary space for the result + of sprintf or SNPRINTF of a single conversion directive. */ +static inline size_t +MAX_ROOM_NEEDED (const arguments *ap, size_t arg_index, FCHAR_T conversion, + arg_type type, int flags, size_t width, int has_precision, + size_t precision, int pad_ourselves) +{ + size_t tmp_length; + + switch (conversion) + { + case 'd': case 'i': case 'u': +# if HAVE_LONG_LONG_INT + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + else +# endif + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Multiply by 2, as an estimate for FLAG_GROUP. */ + tmp_length = xsum (tmp_length, tmp_length); + /* Add 1, to account for a leading sign. */ + tmp_length = xsum (tmp_length, 1); + break; + + case 'o': +# if HAVE_LONG_LONG_INT + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + else +# endif + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Add 1, to account for a leading sign. */ + tmp_length = xsum (tmp_length, 1); + break; + + case 'x': case 'X': +# if HAVE_LONG_LONG_INT + if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else +# endif + if (type == TYPE_LONGINT || type == TYPE_ULONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (sizeof (unsigned int) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Add 2, to account for a leading sign or alternate form. */ + tmp_length = xsum (tmp_length, 2); + break; + + case 'f': case 'F': + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) (LDBL_MAX_EXP + * 0.30103 /* binary -> decimal */ + * 2 /* estimate for FLAG_GROUP */ + ) + + 1 /* turn floor into ceil */ + + 10; /* sign, decimal point etc. */ + else + tmp_length = + (unsigned int) (DBL_MAX_EXP + * 0.30103 /* binary -> decimal */ + * 2 /* estimate for FLAG_GROUP */ + ) + + 1 /* turn floor into ceil */ + + 10; /* sign, decimal point etc. */ + tmp_length = xsum (tmp_length, precision); + break; + + case 'e': case 'E': case 'g': case 'G': + tmp_length = + 12; /* sign, decimal point, exponent etc. */ + tmp_length = xsum (tmp_length, precision); + break; + + case 'a': case 'A': + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) (LDBL_DIG + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) (DBL_DIG + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); + break; + + case 'c': +# if HAVE_WINT_T && !WIDE_CHAR_VERSION + if (type == TYPE_WIDE_CHAR) + tmp_length = MB_CUR_MAX; + else +# endif + tmp_length = 1; + break; + + case 's': +# if HAVE_WCHAR_T + if (type == TYPE_WIDE_STRING) + { +# if WIDE_CHAR_VERSION + /* ISO C says about %ls in fwprintf: + "If the precision is not specified or is greater than the size + of the array, the array shall contain a null wide character." + So if there is a precision, we must not use wcslen. */ + const wchar_t *arg = ap->arg[arg_index].a.a_wide_string; + + if (has_precision) + tmp_length = local_wcsnlen (arg, precision); + else + tmp_length = local_wcslen (arg); +# else + /* ISO C says about %ls in fprintf: + "If a precision is specified, no more than that many bytes are + written (including shift sequences, if any), and the array + shall contain a null wide character if, to equal the multibyte + character sequence length given by the precision, the function + would need to access a wide character one past the end of the + array." + So if there is a precision, we must not use wcslen. */ + /* This case has already been handled separately in VASNPRINTF. */ + abort (); +# endif + } + else +# endif + { +# if WIDE_CHAR_VERSION + /* ISO C says about %s in fwprintf: + "If the precision is not specified or is greater than the size + of the converted array, the converted array shall contain a + null wide character." + So if there is a precision, we must not use strlen. */ + /* This case has already been handled separately in VASNPRINTF. */ + abort (); +# else + /* ISO C says about %s in fprintf: + "If the precision is not specified or greater than the size of + the array, the array shall contain a null character." + So if there is a precision, we must not use strlen. */ + const char *arg = ap->arg[arg_index].a.a_string; + + if (has_precision) + tmp_length = local_strnlen (arg, precision); + else + tmp_length = strlen (arg); +# endif + } + break; + + case 'p': + tmp_length = + (unsigned int) (sizeof (void *) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1 /* turn floor into ceil */ + + 2; /* account for leading 0x */ + break; + + default: + abort (); + } + + if (!pad_ourselves) + { +# if ENABLE_UNISTDIO + /* Padding considers the number of characters, therefore the number of + elements after padding may be + > max (tmp_length, width) + but is certainly + <= tmp_length + width. */ + tmp_length = xsum (tmp_length, width); +# else + /* Padding considers the number of elements, says POSIX. */ + if (tmp_length < width) + tmp_length = width; +# endif + } + + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + + return tmp_length; +} + +#endif + DCHAR_T * VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, - const FCHAR_T *format, va_list args) + const FCHAR_T *format, va_list args) { DIRECTIVES d; arguments a; @@ -1486,8 +1751,8 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, return NULL; #define CLEANUP() \ - free (d.dir); \ - if (a.arg) \ + free (d.dir); \ + if (a.arg) \ free (a.arg); if (PRINTF_FETCHARGS (args, &a) < 0) @@ -1516,30 +1781,30 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, #if HAVE_ALLOCA if (buf_neededlength < 4000 / sizeof (TCHAR_T)) { - buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T)); - buf_malloced = NULL; + buf = (TCHAR_T *) alloca (buf_neededlength * sizeof (TCHAR_T)); + buf_malloced = NULL; } else #endif { - size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T)); - if (size_overflow_p (buf_memsize)) - goto out_of_memory_1; - buf = (TCHAR_T *) malloc (buf_memsize); - if (buf == NULL) - goto out_of_memory_1; - buf_malloced = buf; + size_t buf_memsize = xtimes (buf_neededlength, sizeof (TCHAR_T)); + if (size_overflow_p (buf_memsize)) + goto out_of_memory_1; + buf = (TCHAR_T *) malloc (buf_memsize); + if (buf == NULL) + goto out_of_memory_1; + buf_malloced = buf; } if (resultbuf != NULL) { - result = resultbuf; - allocated = *lengthp; + result = resultbuf; + allocated = *lengthp; } else { - result = NULL; - allocated = 0; + result = NULL; + allocated = 0; } length = 0; /* Invariants: @@ -1549,3881 +1814,3692 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, /* Ensures that allocated >= needed. Aborts through a jump to out_of_memory if needed is SIZE_MAX or otherwise too big. */ #define ENSURE_ALLOCATION(needed) \ - if ((needed) > allocated) \ - { \ - size_t memory_size; \ - DCHAR_T *memory; \ - \ - allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ - if ((needed) > allocated) \ - allocated = (needed); \ - memory_size = xtimes (allocated, sizeof (DCHAR_T)); \ - if (size_overflow_p (memory_size)) \ - goto out_of_memory; \ - if (result == resultbuf || result == NULL) \ - memory = (DCHAR_T *) malloc (memory_size); \ - else \ - memory = (DCHAR_T *) realloc (result, memory_size); \ - if (memory == NULL) \ - goto out_of_memory; \ - if (result == resultbuf && length > 0) \ - DCHAR_CPY (memory, result, length); \ - result = memory; \ + if ((needed) > allocated) \ + { \ + size_t memory_size; \ + DCHAR_T *memory; \ + \ + allocated = (allocated > 0 ? xtimes (allocated, 2) : 12); \ + if ((needed) > allocated) \ + allocated = (needed); \ + memory_size = xtimes (allocated, sizeof (DCHAR_T)); \ + if (size_overflow_p (memory_size)) \ + goto out_of_memory; \ + if (result == resultbuf || result == NULL) \ + memory = (DCHAR_T *) malloc (memory_size); \ + else \ + memory = (DCHAR_T *) realloc (result, memory_size); \ + if (memory == NULL) \ + goto out_of_memory; \ + if (result == resultbuf && length > 0) \ + DCHAR_CPY (memory, result, length); \ + result = memory; \ } for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++) { - if (cp != dp->dir_start) - { - size_t n = dp->dir_start - cp; - size_t augmented_length = xsum (length, n); - - ENSURE_ALLOCATION (augmented_length); - /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we - need that the format string contains only ASCII characters - if FCHAR_T and DCHAR_T are not the same type. */ - if (sizeof (FCHAR_T) == sizeof (DCHAR_T)) - { - DCHAR_CPY (result + length, (const DCHAR_T *) cp, n); - length = augmented_length; - } - else - { - do - result[length++] = (unsigned char) *cp++; - while (--n > 0); - } - } - if (i == d.count) - break; - - /* Execute a single directive. */ - if (dp->conversion == '%') - { - size_t augmented_length; - - if (!(dp->arg_index == ARG_NONE)) - abort (); - augmented_length = xsum (length, 1); - ENSURE_ALLOCATION (augmented_length); - result[length] = '%'; - length = augmented_length; - } - else - { - if (!(dp->arg_index != ARG_NONE)) - abort (); - - if (dp->conversion == 'n') - { - switch (a.arg[dp->arg_index].type) - { - case TYPE_COUNT_SCHAR_POINTER: - *a.arg[dp->arg_index].a.a_count_schar_pointer = length; - break; - case TYPE_COUNT_SHORT_POINTER: - *a.arg[dp->arg_index].a.a_count_short_pointer = length; - break; - case TYPE_COUNT_INT_POINTER: - *a.arg[dp->arg_index].a.a_count_int_pointer = length; - break; - case TYPE_COUNT_LONGINT_POINTER: - *a.arg[dp->arg_index].a.a_count_longint_pointer = length; - break; + if (cp != dp->dir_start) + { + size_t n = dp->dir_start - cp; + size_t augmented_length = xsum (length, n); + + ENSURE_ALLOCATION (augmented_length); + /* This copies a piece of FCHAR_T[] into a DCHAR_T[]. Here we + need that the format string contains only ASCII characters + if FCHAR_T and DCHAR_T are not the same type. */ + if (sizeof (FCHAR_T) == sizeof (DCHAR_T)) + { + DCHAR_CPY (result + length, (const DCHAR_T *) cp, n); + length = augmented_length; + } + else + { + do + result[length++] = (unsigned char) *cp++; + while (--n > 0); + } + } + if (i == d.count) + break; + + /* Execute a single directive. */ + if (dp->conversion == '%') + { + size_t augmented_length; + + if (!(dp->arg_index == ARG_NONE)) + abort (); + augmented_length = xsum (length, 1); + ENSURE_ALLOCATION (augmented_length); + result[length] = '%'; + length = augmented_length; + } + else + { + if (!(dp->arg_index != ARG_NONE)) + abort (); + + if (dp->conversion == 'n') + { + switch (a.arg[dp->arg_index].type) + { + case TYPE_COUNT_SCHAR_POINTER: + *a.arg[dp->arg_index].a.a_count_schar_pointer = length; + break; + case TYPE_COUNT_SHORT_POINTER: + *a.arg[dp->arg_index].a.a_count_short_pointer = length; + break; + case TYPE_COUNT_INT_POINTER: + *a.arg[dp->arg_index].a.a_count_int_pointer = length; + break; + case TYPE_COUNT_LONGINT_POINTER: + *a.arg[dp->arg_index].a.a_count_longint_pointer = length; + break; #if HAVE_LONG_LONG_INT - case TYPE_COUNT_LONGLONGINT_POINTER: - *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; - break; + case TYPE_COUNT_LONGLONGINT_POINTER: + *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; + break; #endif - default: - abort (); - } - } + default: + abort (); + } + } #if ENABLE_UNISTDIO - /* The unistdio extensions. */ - else if (dp->conversion == 'U') - { - arg_type type = a.arg[dp->arg_index].type; - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 0; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } - - switch (type) - { - case TYPE_U8_STRING: - { - const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string; - const uint8_t *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only PRECISION characters, from the left. */ - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count = u8_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of - characters. */ - arg_end = arg; - characters = 0; - for (;;) - { - int count = u8_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + u8_strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } + /* The unistdio extensions. */ + else if (dp->conversion == 'U') + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 0; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + + switch (type) + { + case TYPE_U8_STRING: + { + const uint8_t *arg = a.arg[dp->arg_index].a.a_u8_string; + const uint8_t *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only PRECISION characters, from the left. */ + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count = u8_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of + characters. */ + arg_end = arg; + characters = 0; + for (;;) + { + int count = u8_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + u8_strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } # if DCHAR_IS_UINT8_T - { - size_t n = arg_end - arg; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_CPY (result + length, arg, n); - length += n; - } + { + size_t n = arg_end - arg; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_CPY (result + length, arg, n); + length += n; + } # else - { /* Convert. */ - DCHAR_T *converted = result + length; - size_t converted_len = allocated - length; + { /* Convert. */ + DCHAR_T *converted = result + length; + size_t converted_len = allocated - length; # if DCHAR_IS_TCHAR - /* Convert from UTF-8 to locale encoding. */ - converted = - u8_conv_to_encoding (locale_charset (), - iconveh_question_mark, - arg, arg_end - arg, NULL, - converted, &converted_len); + /* Convert from UTF-8 to locale encoding. */ + converted = + u8_conv_to_encoding (locale_charset (), + iconveh_question_mark, + arg, arg_end - arg, NULL, + converted, &converted_len); # else - /* Convert from UTF-8 to UTF-16/UTF-32. */ - converted = - U8_TO_DCHAR (arg, arg_end - arg, - converted, &converted_len); + /* Convert from UTF-8 to UTF-16/UTF-32. */ + converted = + U8_TO_DCHAR (arg, arg_end - arg, + converted, &converted_len); # endif - if (converted == NULL) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - if (converted != result + length) - { - ENSURE_ALLOCATION (xsum (length, converted_len)); - DCHAR_CPY (result + length, converted, converted_len); - free (converted); - } - length += converted_len; - } + if (converted == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + if (converted != result + length) + { + ENSURE_ALLOCATION (xsum (length, converted_len)); + DCHAR_CPY (result + length, converted, converted_len); + free (converted); + } + length += converted_len; + } # endif - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - break; - - case TYPE_U16_STRING: - { - const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string; - const uint16_t *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only PRECISION characters, from the left. */ - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count = u16_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of - characters. */ - arg_end = arg; - characters = 0; - for (;;) - { - int count = u16_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + u16_strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + break; + + case TYPE_U16_STRING: + { + const uint16_t *arg = a.arg[dp->arg_index].a.a_u16_string; + const uint16_t *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only PRECISION characters, from the left. */ + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count = u16_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of + characters. */ + arg_end = arg; + characters = 0; + for (;;) + { + int count = u16_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + u16_strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } # if DCHAR_IS_UINT16_T - { - size_t n = arg_end - arg; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_CPY (result + length, arg, n); - length += n; - } + { + size_t n = arg_end - arg; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_CPY (result + length, arg, n); + length += n; + } # else - { /* Convert. */ - DCHAR_T *converted = result + length; - size_t converted_len = allocated - length; + { /* Convert. */ + DCHAR_T *converted = result + length; + size_t converted_len = allocated - length; # if DCHAR_IS_TCHAR - /* Convert from UTF-16 to locale encoding. */ - converted = - u16_conv_to_encoding (locale_charset (), - iconveh_question_mark, - arg, arg_end - arg, NULL, - converted, &converted_len); + /* Convert from UTF-16 to locale encoding. */ + converted = + u16_conv_to_encoding (locale_charset (), + iconveh_question_mark, + arg, arg_end - arg, NULL, + converted, &converted_len); # else - /* Convert from UTF-16 to UTF-8/UTF-32. */ - converted = - U16_TO_DCHAR (arg, arg_end - arg, - converted, &converted_len); + /* Convert from UTF-16 to UTF-8/UTF-32. */ + converted = + U16_TO_DCHAR (arg, arg_end - arg, + converted, &converted_len); # endif - if (converted == NULL) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - if (converted != result + length) - { - ENSURE_ALLOCATION (xsum (length, converted_len)); - DCHAR_CPY (result + length, converted, converted_len); - free (converted); - } - length += converted_len; - } + if (converted == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + if (converted != result + length) + { + ENSURE_ALLOCATION (xsum (length, converted_len)); + DCHAR_CPY (result + length, converted, converted_len); + free (converted); + } + length += converted_len; + } # endif - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - break; - - case TYPE_U32_STRING: - { - const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string; - const uint32_t *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only PRECISION characters, from the left. */ - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count = u32_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of - characters. */ - arg_end = arg; - characters = 0; - for (;;) - { - int count = u32_strmblen (arg_end); - if (count == 0) - break; - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + u32_strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + break; + + case TYPE_U32_STRING: + { + const uint32_t *arg = a.arg[dp->arg_index].a.a_u32_string; + const uint32_t *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only PRECISION characters, from the left. */ + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count = u32_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of + characters. */ + arg_end = arg; + characters = 0; + for (;;) + { + int count = u32_strmblen (arg_end); + if (count == 0) + break; + if (count < 0) + { + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + u32_strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } # if DCHAR_IS_UINT32_T - { - size_t n = arg_end - arg; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_CPY (result + length, arg, n); - length += n; - } + { + size_t n = arg_end - arg; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_CPY (result + length, arg, n); + length += n; + } # else - { /* Convert. */ - DCHAR_T *converted = result + length; - size_t converted_len = allocated - length; + { /* Convert. */ + DCHAR_T *converted = result + length; + size_t converted_len = allocated - length; # if DCHAR_IS_TCHAR - /* Convert from UTF-32 to locale encoding. */ - converted = - u32_conv_to_encoding (locale_charset (), - iconveh_question_mark, - arg, arg_end - arg, NULL, - converted, &converted_len); + /* Convert from UTF-32 to locale encoding. */ + converted = + u32_conv_to_encoding (locale_charset (), + iconveh_question_mark, + arg, arg_end - arg, NULL, + converted, &converted_len); # else - /* Convert from UTF-32 to UTF-8/UTF-16. */ - converted = - U32_TO_DCHAR (arg, arg_end - arg, - converted, &converted_len); + /* Convert from UTF-32 to UTF-8/UTF-16. */ + converted = + U32_TO_DCHAR (arg, arg_end - arg, + converted, &converted_len); # endif - if (converted == NULL) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - if (converted != result + length) - { - ENSURE_ALLOCATION (xsum (length, converted_len)); - DCHAR_CPY (result + length, converted, converted_len); - free (converted); - } - length += converted_len; - } + if (converted == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + if (converted != result + length) + { + ENSURE_ALLOCATION (xsum (length, converted_len)); + DCHAR_CPY (result + length, converted, converted_len); + free (converted); + } + length += converted_len; + } # endif - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - break; - - default: - abort (); - } - } + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + break; + + default: + abort (); + } + } #endif -#if (!USE_SNPRINTF || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T - else if (dp->conversion == 's' +#if (!USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || (NEED_PRINTF_DIRECTIVE_LS && !defined IN_LIBINTL)) && HAVE_WCHAR_T + else if (dp->conversion == 's' # if WIDE_CHAR_VERSION - && a.arg[dp->arg_index].type != TYPE_WIDE_STRING + && a.arg[dp->arg_index].type != TYPE_WIDE_STRING # else - && a.arg[dp->arg_index].type == TYPE_WIDE_STRING + && a.arg[dp->arg_index].type == TYPE_WIDE_STRING # endif - ) - { - /* The normal handling of the 's' directive below requires - allocating a temporary buffer. The determination of its - length (tmp_length), in the case when a precision is - specified, below requires a conversion between a char[] - string and a wchar_t[] wide string. It could be done, but - we have no guarantee that the implementation of sprintf will - use the exactly same algorithm. Without this guarantee, it - is possible to have buffer overrun bugs. In order to avoid - such bugs, we implement the entire processing of the 's' - directive ourselves. */ - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 6; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } + ) + { + /* The normal handling of the 's' directive below requires + allocating a temporary buffer. The determination of its + length (tmp_length), in the case when a precision is + specified, below requires a conversion between a char[] + string and a wchar_t[] wide string. It could be done, but + we have no guarantee that the implementation of sprintf will + use the exactly same algorithm. Without this guarantee, it + is possible to have buffer overrun bugs. In order to avoid + such bugs, we implement the entire processing of the 's' + directive ourselves. */ + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 6; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } # if WIDE_CHAR_VERSION - /* %s in vasnwprintf. See the specification of fwprintf. */ - { - const char *arg = a.arg[dp->arg_index].a.a_string; - const char *arg_end; - size_t characters; - - if (has_precision) - { - /* Use only as many bytes as needed to produce PRECISION - wide characters, from the left. */ + /* %s in vasnwprintf. See the specification of fwprintf. */ + { + const char *arg = a.arg[dp->arg_index].a.a_string; + const char *arg_end; + size_t characters; + + if (has_precision) + { + /* Use only as many bytes as needed to produce PRECISION + wide characters, from the left. */ # if HAVE_MBRTOWC - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - for (; precision > 0; precision--) - { - int count; + arg_end = arg; + characters = 0; + for (; precision > 0; precision--) + { + int count; # if HAVE_MBRTOWC - count = mbrlen (arg_end, MB_CUR_MAX, &state); + count = mbrlen (arg_end, MB_CUR_MAX, &state); # else - count = mblen (arg_end, MB_CUR_MAX); + count = mblen (arg_end, MB_CUR_MAX); # endif - if (count == 0) - /* Found the terminating NUL. */ - break; - if (count < 0) - { - /* Invalid or incomplete multibyte character. */ - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else if (has_width) - { - /* Use the entire string, and count the number of wide - characters. */ + if (count == 0) + /* Found the terminating NUL. */ + break; + if (count < 0) + { + /* Invalid or incomplete multibyte character. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else if (has_width) + { + /* Use the entire string, and count the number of wide + characters. */ # if HAVE_MBRTOWC - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - for (;;) - { - int count; + arg_end = arg; + characters = 0; + for (;;) + { + int count; # if HAVE_MBRTOWC - count = mbrlen (arg_end, MB_CUR_MAX, &state); + count = mbrlen (arg_end, MB_CUR_MAX, &state); # else - count = mblen (arg_end, MB_CUR_MAX); + count = mblen (arg_end, MB_CUR_MAX); # endif - if (count == 0) - /* Found the terminating NUL. */ - break; - if (count < 0) - { - /* Invalid or incomplete multibyte character. */ - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end += count; - characters++; - } - } - else - { - /* Use the entire string. */ - arg_end = arg + strlen (arg); - /* The number of characters doesn't matter. */ - characters = 0; - } - - if (has_width && width > characters - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - - if (has_precision || has_width) - { - /* We know the number of wide characters in advance. */ - size_t remaining; + if (count == 0) + /* Found the terminating NUL. */ + break; + if (count < 0) + { + /* Invalid or incomplete multibyte character. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end += count; + characters++; + } + } + else + { + /* Use the entire string. */ + arg_end = arg + strlen (arg); + /* The number of characters doesn't matter. */ + characters = 0; + } + + if (has_width && width > characters + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + + if (has_precision || has_width) + { + /* We know the number of wide characters in advance. */ + size_t remaining; # if HAVE_MBRTOWC - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - ENSURE_ALLOCATION (xsum (length, characters)); - for (remaining = characters; remaining > 0; remaining--) - { - wchar_t wc; - int count; + ENSURE_ALLOCATION (xsum (length, characters)); + for (remaining = characters; remaining > 0; remaining--) + { + wchar_t wc; + int count; # if HAVE_MBRTOWC - count = mbrtowc (&wc, arg, arg_end - arg, &state); + count = mbrtowc (&wc, arg, arg_end - arg, &state); # else - count = mbtowc (&wc, arg, arg_end - arg); + count = mbtowc (&wc, arg, arg_end - arg); # endif - if (count <= 0) - /* mbrtowc not consistent with mbrlen, or mbtowc - not consistent with mblen. */ - abort (); - result[length++] = wc; - arg += count; - } - if (!(arg == arg_end)) - abort (); - } - else - { + if (count <= 0) + /* mbrtowc not consistent with mbrlen, or mbtowc + not consistent with mblen. */ + abort (); + result[length++] = wc; + arg += count; + } + if (!(arg == arg_end)) + abort (); + } + else + { # if HAVE_MBRTOWC - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - while (arg < arg_end) - { - wchar_t wc; - int count; + while (arg < arg_end) + { + wchar_t wc; + int count; # if HAVE_MBRTOWC - count = mbrtowc (&wc, arg, arg_end - arg, &state); + count = mbrtowc (&wc, arg, arg_end - arg, &state); # else - count = mbtowc (&wc, arg, arg_end - arg); + count = mbtowc (&wc, arg, arg_end - arg); # endif - if (count <= 0) - /* mbrtowc not consistent with mbrlen, or mbtowc - not consistent with mblen. */ - abort (); - ENSURE_ALLOCATION (xsum (length, 1)); - result[length++] = wc; - arg += count; - } - } - - if (has_width && width > characters - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - characters; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } + if (count <= 0) + /* mbrtowc not consistent with mbrlen, or mbtowc + not consistent with mblen. */ + abort (); + ENSURE_ALLOCATION (xsum (length, 1)); + result[length++] = wc; + arg += count; + } + } + + if (has_width && width > characters + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - characters; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } # else - /* %ls in vasnprintf. See the specification of fprintf. */ - { - const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; - const wchar_t *arg_end; - size_t characters; + /* %ls in vasnprintf. See the specification of fprintf. */ + { + const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; + const wchar_t *arg_end; + size_t characters; # if !DCHAR_IS_TCHAR - /* This code assumes that TCHAR_T is 'char'. */ - typedef int TCHAR_T_verify[2 * (sizeof (TCHAR_T) == 1) - 1]; - TCHAR_T *tmpsrc; - DCHAR_T *tmpdst; - size_t tmpdst_len; + /* This code assumes that TCHAR_T is 'char'. */ + typedef int TCHAR_T_verify[2 * (sizeof (TCHAR_T) == 1) - 1]; + TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t tmpdst_len; # endif - size_t w; - - if (has_precision) - { - /* Use only as many wide characters as needed to produce - at most PRECISION bytes, from the left. */ -# if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + size_t w; + + if (has_precision) + { + /* Use only as many wide characters as needed to produce + at most PRECISION bytes, from the left. */ +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - while (precision > 0) - { - char buf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; - - if (*arg_end == 0) - /* Found the terminating null wide character. */ - break; -# if HAVE_WCRTOMB - count = wcrtomb (buf, *arg_end, &state); + arg_end = arg; + characters = 0; + while (precision > 0) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg_end == 0) + /* Found the terminating null wide character. */ + break; +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + count = wcrtomb (cbuf, *arg_end, &state); # else - count = wctomb (buf, *arg_end); + count = wctomb (cbuf, *arg_end); # endif - if (count < 0) - { - /* Cannot convert. */ - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - if (precision < count) - break; - arg_end++; - characters += count; - precision -= count; - } - } + if (count < 0) + { + /* Cannot convert. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + if (precision < count) + break; + arg_end++; + characters += count; + precision -= count; + } + } # if DCHAR_IS_TCHAR - else if (has_width) + else if (has_width) # else - else + else # endif - { - /* Use the entire string, and count the number of - bytes. */ -# if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + { + /* Use the entire string, and count the number of + bytes. */ +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - arg_end = arg; - characters = 0; - for (;;) - { - char buf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; - - if (*arg_end == 0) - /* Found the terminating null wide character. */ - break; -# if HAVE_WCRTOMB - count = wcrtomb (buf, *arg_end, &state); + arg_end = arg; + characters = 0; + for (;;) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg_end == 0) + /* Found the terminating null wide character. */ + break; +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + count = wcrtomb (cbuf, *arg_end, &state); # else - count = wctomb (buf, *arg_end); + count = wctomb (cbuf, *arg_end); # endif - if (count < 0) - { - /* Cannot convert. */ - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EILSEQ; - return NULL; - } - arg_end++; - characters += count; - } - } + if (count < 0) + { + /* Cannot convert. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + arg_end++; + characters += count; + } + } # if DCHAR_IS_TCHAR - else - { - /* Use the entire string. */ - arg_end = arg + local_wcslen (arg); - /* The number of bytes doesn't matter. */ - characters = 0; - } + else + { + /* Use the entire string. */ + arg_end = arg + local_wcslen (arg); + /* The number of bytes doesn't matter. */ + characters = 0; + } # endif # if !DCHAR_IS_TCHAR - /* Convert the string into a piece of temporary memory. */ - tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T)); - if (tmpsrc == NULL) - goto out_of_memory; - { - TCHAR_T *tmpptr = tmpsrc; - size_t remaining; -# if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + /* Convert the string into a piece of temporary memory. */ + tmpsrc = (TCHAR_T *) malloc (characters * sizeof (TCHAR_T)); + if (tmpsrc == NULL) + goto out_of_memory; + { + TCHAR_T *tmpptr = tmpsrc; + size_t remaining; +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - for (remaining = characters; remaining > 0; ) - { - char buf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; - - if (*arg == 0) - abort (); -# if HAVE_WCRTOMB - count = wcrtomb (buf, *arg, &state); + for (remaining = characters; remaining > 0; ) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg == 0) + abort (); +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + count = wcrtomb (cbuf, *arg, &state); # else - count = wctomb (buf, *arg); + count = wctomb (cbuf, *arg); # endif - if (count <= 0) - /* Inconsistency. */ - abort (); - memcpy (tmpptr, buf, count); - tmpptr += count; - arg++; - remaining -= count; - } - if (!(arg == arg_end)) - abort (); - } - - /* Convert from TCHAR_T[] to DCHAR_T[]. */ - tmpdst = - DCHAR_CONV_FROM_ENCODING (locale_charset (), - iconveh_question_mark, - tmpsrc, characters, - NULL, - NULL, &tmpdst_len); - if (tmpdst == NULL) - { - int saved_errno = errno; - free (tmpsrc); - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - free (tmpsrc); + if (count <= 0) + /* Inconsistency. */ + abort (); + memcpy (tmpptr, cbuf, count); + tmpptr += count; + arg++; + remaining -= count; + } + if (!(arg == arg_end)) + abort (); + } + + /* Convert from TCHAR_T[] to DCHAR_T[]. */ + tmpdst = + DCHAR_CONV_FROM_ENCODING (locale_charset (), + iconveh_question_mark, + tmpsrc, characters, + NULL, + NULL, &tmpdst_len); + if (tmpdst == NULL) + { + int saved_errno = errno; + free (tmpsrc); + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + free (tmpsrc); # endif - if (has_width) - { + if (has_width) + { # if ENABLE_UNISTDIO - /* Outside POSIX, it's preferrable to compare the width - against the number of _characters_ of the converted - value. */ - w = DCHAR_MBSNLEN (result + length, characters); + /* Outside POSIX, it's preferrable to compare the width + against the number of _characters_ of the converted + value. */ + w = DCHAR_MBSNLEN (result + length, characters); # else - /* The width is compared against the number of _bytes_ - of the converted value, says POSIX. */ - w = characters; + /* The width is compared against the number of _bytes_ + of the converted value, says POSIX. */ + w = characters; # endif - } - else - /* w doesn't matter. */ - w = 0; - - if (has_width && width > w - && !(dp->flags & FLAG_LEFT)) - { - size_t n = width - w; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } + } + else + /* w doesn't matter. */ + w = 0; + + if (has_width && width > w + && !(dp->flags & FLAG_LEFT)) + { + size_t n = width - w; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } # if DCHAR_IS_TCHAR - if (has_precision || has_width) - { - /* We know the number of bytes in advance. */ - size_t remaining; -# if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + if (has_precision || has_width) + { + /* We know the number of bytes in advance. */ + size_t remaining; +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - ENSURE_ALLOCATION (xsum (length, characters)); - for (remaining = characters; remaining > 0; ) - { - char buf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; - - if (*arg == 0) - abort (); -# if HAVE_WCRTOMB - count = wcrtomb (buf, *arg, &state); + ENSURE_ALLOCATION (xsum (length, characters)); + for (remaining = characters; remaining > 0; ) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg == 0) + abort (); +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + count = wcrtomb (cbuf, *arg, &state); # else - count = wctomb (buf, *arg); + count = wctomb (cbuf, *arg); # endif - if (count <= 0) - /* Inconsistency. */ - abort (); - memcpy (result + length, buf, count); - length += count; - arg++; - remaining -= count; - } - if (!(arg == arg_end)) - abort (); - } - else - { -# if HAVE_WCRTOMB - mbstate_t state; - memset (&state, '\0', sizeof (mbstate_t)); + if (count <= 0) + /* Inconsistency. */ + abort (); + memcpy (result + length, cbuf, count); + length += count; + arg++; + remaining -= count; + } + if (!(arg == arg_end)) + abort (); + } + else + { +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + mbstate_t state; + memset (&state, '\0', sizeof (mbstate_t)); # endif - while (arg < arg_end) - { - char buf[64]; /* Assume MB_CUR_MAX <= 64. */ - int count; - - if (*arg == 0) - abort (); -# if HAVE_WCRTOMB - count = wcrtomb (buf, *arg, &state); + while (arg < arg_end) + { + char cbuf[64]; /* Assume MB_CUR_MAX <= 64. */ + int count; + + if (*arg == 0) + abort (); +# if HAVE_WCRTOMB && !defined GNULIB_defined_mbstate_t + count = wcrtomb (cbuf, *arg, &state); # else - count = wctomb (buf, *arg); + count = wctomb (cbuf, *arg); # endif - if (count <= 0) - /* Inconsistency. */ - abort (); - ENSURE_ALLOCATION (xsum (length, count)); - memcpy (result + length, buf, count); - length += count; - arg++; - } - } + if (count <= 0) + { + /* Cannot convert. */ + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = EILSEQ; + return NULL; + } + ENSURE_ALLOCATION (xsum (length, count)); + memcpy (result + length, cbuf, count); + length += count; + arg++; + } + } # else - ENSURE_ALLOCATION (xsum (length, tmpdst_len)); - DCHAR_CPY (result + length, tmpdst, tmpdst_len); - free (tmpdst); - length += tmpdst_len; + ENSURE_ALLOCATION (xsum (length, tmpdst_len)); + DCHAR_CPY (result + length, tmpdst, tmpdst_len); + free (tmpdst); + length += tmpdst_len; # endif - if (has_width && width > w - && (dp->flags & FLAG_LEFT)) - { - size_t n = width - w; - ENSURE_ALLOCATION (xsum (length, n)); - DCHAR_SET (result + length, ' ', n); - length += n; - } - } - } + if (has_width && width > w + && (dp->flags & FLAG_LEFT)) + { + size_t n = width - w; + ENSURE_ALLOCATION (xsum (length, n)); + DCHAR_SET (result + length, ' ', n); + length += n; + } + } + } # endif #endif #if (NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE) && !defined IN_LIBINTL - else if ((dp->conversion == 'a' || dp->conversion == 'A') + else if ((dp->conversion == 'a' || dp->conversion == 'A') # if !(NEED_PRINTF_DIRECTIVE_A || (NEED_PRINTF_LONG_DOUBLE && NEED_PRINTF_DOUBLE)) - && (0 + && (0 # if NEED_PRINTF_DOUBLE - || a.arg[dp->arg_index].type == TYPE_DOUBLE + || a.arg[dp->arg_index].type == TYPE_DOUBLE # endif # if NEED_PRINTF_LONG_DOUBLE - || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE + || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE # endif - ) + ) # endif - ) - { - arg_type type = a.arg[dp->arg_index].type; - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - size_t tmp_length; - DCHAR_T tmpbuf[700]; - DCHAR_T *tmp; - DCHAR_T *pad_ptr; - DCHAR_T *p; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 0; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } - - /* Allocate a temporary buffer of sufficient size. */ - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) ((LDBL_DIG + 1) - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) ((DBL_DIG + 1) - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Account for sign, decimal point etc. */ - tmp_length = xsum (tmp_length, 12); - - if (tmp_length < width) - tmp_length = width; - - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - - if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); - - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (DCHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } - - pad_ptr = NULL; - p = tmp; - if (type == TYPE_LONGDOUBLE) - { + ) + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + size_t tmp_length; + DCHAR_T tmpbuf[700]; + DCHAR_T *tmp; + DCHAR_T *pad_ptr; + DCHAR_T *p; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 0; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + + /* Allocate a temporary buffer of sufficient size. */ + if (type == TYPE_LONGDOUBLE) + tmp_length = + (unsigned int) ((LDBL_DIG + 1) + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else + tmp_length = + (unsigned int) ((DBL_DIG + 1) + * 0.831 /* decimal -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + if (tmp_length < precision) + tmp_length = precision; + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); + + if (tmp_length < width) + tmp_length = width; + + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + + if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); + + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (DCHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } + + pad_ptr = NULL; + p = tmp; + if (type == TYPE_LONGDOUBLE) + { # if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_LONG_DOUBLE - long double arg = a.arg[dp->arg_index].a.a_longdouble; - - if (isnanl (arg)) - { - if (dp->conversion == 'A') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - DECL_LONG_DOUBLE_ROUNDING - - BEGIN_LONG_DOUBLE_ROUNDING (); - - if (signbit (arg)) /* arg < 0.0L or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0L && arg + arg == arg) - { - if (dp->conversion == 'A') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { - int exponent; - long double mantissa; - - if (arg > 0.0L) - mantissa = printf_frexpl (arg, &exponent); - else - { - exponent = 0; - mantissa = 0.0L; - } - - if (has_precision - && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1) - { - /* Round the mantissa. */ - long double tail = mantissa; - size_t q; - - for (q = precision; ; q--) - { - int digit = (int) tail; - tail -= digit; - if (q == 0) - { - if (digit & 1 ? tail >= 0.5L : tail > 0.5L) - tail = 1 - tail; - else - tail = - tail; - break; - } - tail *= 16.0L; - } - if (tail != 0.0L) - for (q = precision; q > 0; q--) - tail *= 0.0625L; - mantissa += tail; - } - - *p++ = '0'; - *p++ = dp->conversion - 'A' + 'X'; - pad_ptr = p; - { - int digit; - - digit = (int) mantissa; - mantissa -= digit; - *p++ = '0' + digit; - if ((flags & FLAG_ALT) - || mantissa > 0.0L || precision > 0) - { - *p++ = decimal_point_char (); - /* This loop terminates because we assume - that FLT_RADIX is a power of 2. */ - while (mantissa > 0.0L) - { - mantissa *= 16.0L; - digit = (int) mantissa; - mantissa -= digit; - *p++ = digit - + (digit < 10 - ? '0' - : dp->conversion - 10); - if (precision > 0) - precision--; - } - while (precision > 0) - { - *p++ = '0'; - precision--; - } - } - } - *p++ = dp->conversion - 'A' + 'P'; + long double arg = a.arg[dp->arg_index].a.a_longdouble; + + if (isnanl (arg)) + { + if (dp->conversion == 'A') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + DECL_LONG_DOUBLE_ROUNDING + + BEGIN_LONG_DOUBLE_ROUNDING (); + + if (signbit (arg)) /* arg < 0.0L or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0L && arg + arg == arg) + { + if (dp->conversion == 'A') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { + int exponent; + long double mantissa; + + if (arg > 0.0L) + mantissa = printf_frexpl (arg, &exponent); + else + { + exponent = 0; + mantissa = 0.0L; + } + + if (has_precision + && precision < (unsigned int) ((LDBL_DIG + 1) * 0.831) + 1) + { + /* Round the mantissa. */ + long double tail = mantissa; + size_t q; + + for (q = precision; ; q--) + { + int digit = (int) tail; + tail -= digit; + if (q == 0) + { + if (digit & 1 ? tail >= 0.5L : tail > 0.5L) + tail = 1 - tail; + else + tail = - tail; + break; + } + tail *= 16.0L; + } + if (tail != 0.0L) + for (q = precision; q > 0; q--) + tail *= 0.0625L; + mantissa += tail; + } + + *p++ = '0'; + *p++ = dp->conversion - 'A' + 'X'; + pad_ptr = p; + { + int digit; + + digit = (int) mantissa; + mantissa -= digit; + *p++ = '0' + digit; + if ((flags & FLAG_ALT) + || mantissa > 0.0L || precision > 0) + { + *p++ = decimal_point_char (); + /* This loop terminates because we assume + that FLT_RADIX is a power of 2. */ + while (mantissa > 0.0L) + { + mantissa *= 16.0L; + digit = (int) mantissa; + mantissa -= digit; + *p++ = digit + + (digit < 10 + ? '0' + : dp->conversion - 10); + if (precision > 0) + precision--; + } + while (precision > 0) + { + *p++ = '0'; + precision--; + } + } + } + *p++ = dp->conversion - 'A' + 'P'; # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + { + static const wchar_t decimal_format[] = + { '%', '+', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } # endif - } + } - END_LONG_DOUBLE_ROUNDING (); - } + END_LONG_DOUBLE_ROUNDING (); + } # else - abort (); + abort (); # endif - } - else - { + } + else + { # if NEED_PRINTF_DIRECTIVE_A || NEED_PRINTF_DOUBLE - double arg = a.arg[dp->arg_index].a.a_double; - - if (isnand (arg)) - { - if (dp->conversion == 'A') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - - if (signbit (arg)) /* arg < 0.0 or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0 && arg + arg == arg) - { - if (dp->conversion == 'A') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { - int exponent; - double mantissa; - - if (arg > 0.0) - mantissa = printf_frexp (arg, &exponent); - else - { - exponent = 0; - mantissa = 0.0; - } - - if (has_precision - && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1) - { - /* Round the mantissa. */ - double tail = mantissa; - size_t q; - - for (q = precision; ; q--) - { - int digit = (int) tail; - tail -= digit; - if (q == 0) - { - if (digit & 1 ? tail >= 0.5 : tail > 0.5) - tail = 1 - tail; - else - tail = - tail; - break; - } - tail *= 16.0; - } - if (tail != 0.0) - for (q = precision; q > 0; q--) - tail *= 0.0625; - mantissa += tail; - } - - *p++ = '0'; - *p++ = dp->conversion - 'A' + 'X'; - pad_ptr = p; - { - int digit; - - digit = (int) mantissa; - mantissa -= digit; - *p++ = '0' + digit; - if ((flags & FLAG_ALT) - || mantissa > 0.0 || precision > 0) - { - *p++ = decimal_point_char (); - /* This loop terminates because we assume - that FLT_RADIX is a power of 2. */ - while (mantissa > 0.0) - { - mantissa *= 16.0; - digit = (int) mantissa; - mantissa -= digit; - *p++ = digit - + (digit < 10 - ? '0' - : dp->conversion - 10); - if (precision > 0) - precision--; - } - while (precision > 0) - { - *p++ = '0'; - precision--; - } - } - } - *p++ = dp->conversion - 'A' + 'P'; + double arg = a.arg[dp->arg_index].a.a_double; + + if (isnand (arg)) + { + if (dp->conversion == 'A') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + + if (signbit (arg)) /* arg < 0.0 or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0 && arg + arg == arg) + { + if (dp->conversion == 'A') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { + int exponent; + double mantissa; + + if (arg > 0.0) + mantissa = printf_frexp (arg, &exponent); + else + { + exponent = 0; + mantissa = 0.0; + } + + if (has_precision + && precision < (unsigned int) ((DBL_DIG + 1) * 0.831) + 1) + { + /* Round the mantissa. */ + double tail = mantissa; + size_t q; + + for (q = precision; ; q--) + { + int digit = (int) tail; + tail -= digit; + if (q == 0) + { + if (digit & 1 ? tail >= 0.5 : tail > 0.5) + tail = 1 - tail; + else + tail = - tail; + break; + } + tail *= 16.0; + } + if (tail != 0.0) + for (q = precision; q > 0; q--) + tail *= 0.0625; + mantissa += tail; + } + + *p++ = '0'; + *p++ = dp->conversion - 'A' + 'X'; + pad_ptr = p; + { + int digit; + + digit = (int) mantissa; + mantissa -= digit; + *p++ = '0' + digit; + if ((flags & FLAG_ALT) + || mantissa > 0.0 || precision > 0) + { + *p++ = decimal_point_char (); + /* This loop terminates because we assume + that FLT_RADIX is a power of 2. */ + while (mantissa > 0.0) + { + mantissa *= 16.0; + digit = (int) mantissa; + mantissa -= digit; + *p++ = digit + + (digit < 10 + ? '0' + : dp->conversion - 10); + if (precision > 0) + precision--; + } + while (precision > 0) + { + *p++ = '0'; + precision--; + } + } + } + *p++ = dp->conversion - 'A' + 'P'; # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + { + static const wchar_t decimal_format[] = + { '%', '+', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } # endif - } - } + } + } # else - abort (); + abort (); # endif - } - /* The generated string now extends from tmp to p, with the - zero padding insertion point being at pad_ptr. */ - if (has_width && p - tmp < width) - { - size_t pad = width - (p - tmp); - DCHAR_T *end = p + pad; - - if (flags & FLAG_LEFT) - { - /* Pad with spaces on the right. */ - for (; pad > 0; pad--) - *p++ = ' '; - } - else if ((flags & FLAG_ZERO) && pad_ptr != NULL) - { - /* Pad with zeroes. */ - DCHAR_T *q = end; - - while (p > pad_ptr) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = '0'; - } - else - { - /* Pad with spaces on the left. */ - DCHAR_T *q = end; - - while (p > tmp) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = ' '; - } - - p = end; - } - - { - size_t count = p - tmp; - - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); - - /* Make room for the result. */ - if (count >= allocated - length) - { - size_t n = xsum (length, count); - - ENSURE_ALLOCATION (n); - } - - /* Append the result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); - if (tmp != tmpbuf) - free (tmp); - length += count; - } - } + } + /* The generated string now extends from tmp to p, with the + zero padding insertion point being at pad_ptr. */ + if (has_width && p - tmp < width) + { + size_t pad = width - (p - tmp); + DCHAR_T *end = p + pad; + + if (flags & FLAG_LEFT) + { + /* Pad with spaces on the right. */ + for (; pad > 0; pad--) + *p++ = ' '; + } + else if ((flags & FLAG_ZERO) && pad_ptr != NULL) + { + /* Pad with zeroes. */ + DCHAR_T *q = end; + + while (p > pad_ptr) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = '0'; + } + else + { + /* Pad with spaces on the left. */ + DCHAR_T *q = end; + + while (p > tmp) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = ' '; + } + + p = end; + } + + { + size_t count = p - tmp; + + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); + + /* Make room for the result. */ + if (count >= allocated - length) + { + size_t n = xsum (length, count); + + ENSURE_ALLOCATION (n); + } + + /* Append the result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); + if (tmp != tmpbuf) + free (tmp); + length += count; + } + } #endif #if (NEED_PRINTF_INFINITE_DOUBLE || NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE || NEED_PRINTF_LONG_DOUBLE) && !defined IN_LIBINTL - else if ((dp->conversion == 'f' || dp->conversion == 'F' - || dp->conversion == 'e' || dp->conversion == 'E' - || dp->conversion == 'g' || dp->conversion == 'G' - || dp->conversion == 'a' || dp->conversion == 'A') - && (0 + else if ((dp->conversion == 'f' || dp->conversion == 'F' + || dp->conversion == 'e' || dp->conversion == 'E' + || dp->conversion == 'g' || dp->conversion == 'G' + || dp->conversion == 'a' || dp->conversion == 'A') + && (0 # if NEED_PRINTF_DOUBLE - || a.arg[dp->arg_index].type == TYPE_DOUBLE + || a.arg[dp->arg_index].type == TYPE_DOUBLE # elif NEED_PRINTF_INFINITE_DOUBLE - || (a.arg[dp->arg_index].type == TYPE_DOUBLE - /* The systems (mingw) which produce wrong output - for Inf, -Inf, and NaN also do so for -0.0. - Therefore we treat this case here as well. */ - && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double)) + || (a.arg[dp->arg_index].type == TYPE_DOUBLE + /* The systems (mingw) which produce wrong output + for Inf, -Inf, and NaN also do so for -0.0. + Therefore we treat this case here as well. */ + && is_infinite_or_zero (a.arg[dp->arg_index].a.a_double)) # endif # if NEED_PRINTF_LONG_DOUBLE - || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE + || a.arg[dp->arg_index].type == TYPE_LONGDOUBLE # elif NEED_PRINTF_INFINITE_LONG_DOUBLE - || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE - /* Some systems produce wrong output for Inf, - -Inf, and NaN. Some systems in this category - (IRIX 5.3) also do so for -0.0. Therefore we - treat this case here as well. */ - && is_infinite_or_zerol (a.arg[dp->arg_index].a.a_longdouble)) + || (a.arg[dp->arg_index].type == TYPE_LONGDOUBLE + /* Some systems produce wrong output for Inf, + -Inf, and NaN. Some systems in this category + (IRIX 5.3) also do so for -0.0. Therefore we + treat this case here as well. */ + && is_infinite_or_zerol (a.arg[dp->arg_index].a.a_longdouble)) # endif - )) - { + )) + { # if (NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE) && (NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE) - arg_type type = a.arg[dp->arg_index].type; + arg_type type = a.arg[dp->arg_index].type; # endif - int flags = dp->flags; - int has_width; - size_t width; - int has_precision; - size_t precision; - size_t tmp_length; - DCHAR_T tmpbuf[700]; - DCHAR_T *tmp; - DCHAR_T *pad_ptr; - DCHAR_T *p; - - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } - - has_precision = 0; - precision = 0; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } - - /* POSIX specifies the default precision to be 6 for %f, %F, - %e, %E, but not for %g, %G. Implementations appear to use - the same default precision also for %g, %G. But for %a, %A, - the default precision is 0. */ - if (!has_precision) - if (!(dp->conversion == 'a' || dp->conversion == 'A')) - precision = 6; - - /* Allocate a temporary buffer of sufficient size. */ + int flags = dp->flags; + int has_width; + size_t width; + int has_precision; + size_t precision; + size_t tmp_length; + DCHAR_T tmpbuf[700]; + DCHAR_T *tmp; + DCHAR_T *pad_ptr; + DCHAR_T *p; + + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } + + has_precision = 0; + precision = 0; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } + + /* POSIX specifies the default precision to be 6 for %f, %F, + %e, %E, but not for %g, %G. Implementations appear to use + the same default precision also for %g, %G. But for %a, %A, + the default precision is 0. */ + if (!has_precision) + if (!(dp->conversion == 'a' || dp->conversion == 'A')) + precision = 6; + + /* Allocate a temporary buffer of sufficient size. */ # if NEED_PRINTF_DOUBLE && NEED_PRINTF_LONG_DOUBLE - tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1); + tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : DBL_DIG + 1); # elif NEED_PRINTF_INFINITE_DOUBLE && NEED_PRINTF_LONG_DOUBLE - tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0); + tmp_length = (type == TYPE_LONGDOUBLE ? LDBL_DIG + 1 : 0); # elif NEED_PRINTF_LONG_DOUBLE - tmp_length = LDBL_DIG + 1; + tmp_length = LDBL_DIG + 1; # elif NEED_PRINTF_DOUBLE - tmp_length = DBL_DIG + 1; + tmp_length = DBL_DIG + 1; # else - tmp_length = 0; + tmp_length = 0; # endif - if (tmp_length < precision) - tmp_length = precision; + if (tmp_length < precision) + tmp_length = precision; # if NEED_PRINTF_LONG_DOUBLE # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - if (type == TYPE_LONGDOUBLE) + if (type == TYPE_LONGDOUBLE) # endif - if (dp->conversion == 'f' || dp->conversion == 'F') - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - if (!(isnanl (arg) || arg + arg == arg)) - { - /* arg is finite and nonzero. */ - int exponent = floorlog10l (arg < 0 ? -arg : arg); - if (exponent >= 0 && tmp_length < exponent + precision) - tmp_length = exponent + precision; - } - } + if (dp->conversion == 'f' || dp->conversion == 'F') + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + if (!(isnanl (arg) || arg + arg == arg)) + { + /* arg is finite and nonzero. */ + int exponent = floorlog10l (arg < 0 ? -arg : arg); + if (exponent >= 0 && tmp_length < exponent + precision) + tmp_length = exponent + precision; + } + } # endif # if NEED_PRINTF_DOUBLE # if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE - if (type == TYPE_DOUBLE) + if (type == TYPE_DOUBLE) # endif - if (dp->conversion == 'f' || dp->conversion == 'F') - { - double arg = a.arg[dp->arg_index].a.a_double; - if (!(isnand (arg) || arg + arg == arg)) - { - /* arg is finite and nonzero. */ - int exponent = floorlog10 (arg < 0 ? -arg : arg); - if (exponent >= 0 && tmp_length < exponent + precision) - tmp_length = exponent + precision; - } - } + if (dp->conversion == 'f' || dp->conversion == 'F') + { + double arg = a.arg[dp->arg_index].a.a_double; + if (!(isnand (arg) || arg + arg == arg)) + { + /* arg is finite and nonzero. */ + int exponent = floorlog10 (arg < 0 ? -arg : arg); + if (exponent >= 0 && tmp_length < exponent + precision) + tmp_length = exponent + precision; + } + } # endif - /* Account for sign, decimal point etc. */ - tmp_length = xsum (tmp_length, 12); + /* Account for sign, decimal point etc. */ + tmp_length = xsum (tmp_length, 12); - if (tmp_length < width) - tmp_length = width; + if (tmp_length < width) + tmp_length = width; - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ + tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); + if (tmp_length <= sizeof (tmpbuf) / sizeof (DCHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (DCHAR_T)); - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (DCHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (DCHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } - pad_ptr = NULL; - p = tmp; + pad_ptr = NULL; + p = tmp; # if NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_INFINITE_LONG_DOUBLE # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - if (type == TYPE_LONGDOUBLE) + if (type == TYPE_LONGDOUBLE) # endif - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - - if (isnanl (arg)) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - DECL_LONG_DOUBLE_ROUNDING - - BEGIN_LONG_DOUBLE_ROUNDING (); - - if (signbit (arg)) /* arg < 0.0L or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0L && arg + arg == arg) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + + if (isnanl (arg)) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + DECL_LONG_DOUBLE_ROUNDING + + BEGIN_LONG_DOUBLE_ROUNDING (); + + if (signbit (arg)) /* arg < 0.0L or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0L && arg + arg == arg) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { # if NEED_PRINTF_LONG_DOUBLE - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - char *digits; - size_t ndigits; - - digits = - scale10_round_decimal_long_double (arg, precision); - if (digits == NULL) - { - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - ndigits = strlen (digits); - - if (ndigits > precision) - do - { - --ndigits; - *p++ = digits[ndigits]; - } - while (ndigits > precision); - else - *p++ = '0'; - /* Here ndigits <= precision. */ - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > ndigits; precision--) - *p++ = '0'; - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - int exponent; - - if (arg == 0.0L) - { - exponent = 0; - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else - { - /* arg > 0.0L. */ - int adjusted; - char *digits; - size_t ndigits; - - exponent = floorlog10l (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_long_double (arg, - (int)precision - exponent); - if (digits == NULL) - { - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - ndigits = strlen (digits); - - if (ndigits == precision + 1) - break; - if (ndigits < precision - || ndigits > precision + 2) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits == precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision+1. */ - if (is_borderline (digits, precision)) - { - /* Maybe the exponent guess was too high - and a smaller exponent can be reached - by turning a 10...0 into 9...9x. */ - char *digits2 = - scale10_round_decimal_long_double (arg, - (int)precision - exponent + 1); - if (digits2 == NULL) - { - free (digits); - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - if (strlen (digits2) == precision + 1) - { - free (digits); - digits = digits2; - exponent -= 1; - } - else - free (digits2); - } - /* Here ndigits = precision+1. */ - - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - - *p++ = dp->conversion; /* 'e' or 'E' */ + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + char *digits; + size_t ndigits; + + digits = + scale10_round_decimal_long_double (arg, precision); + if (digits == NULL) + { + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + ndigits = strlen (digits); + + if (ndigits > precision) + do + { + --ndigits; + *p++ = digits[ndigits]; + } + while (ndigits > precision); + else + *p++ = '0'; + /* Here ndigits <= precision. */ + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > ndigits; precision--) + *p++ = '0'; + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + int exponent; + + if (arg == 0.0L) + { + exponent = 0; + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else + { + /* arg > 0.0L. */ + int adjusted; + char *digits; + size_t ndigits; + + exponent = floorlog10l (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_long_double (arg, + (int)precision - exponent); + if (digits == NULL) + { + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + ndigits = strlen (digits); + + if (ndigits == precision + 1) + break; + if (ndigits < precision + || ndigits > precision + 2) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits == precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision+1. */ + if (is_borderline (digits, precision)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_long_double (arg, + (int)precision - exponent + 1); + if (digits2 == NULL) + { + free (digits); + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + if (strlen (digits2) == precision + 1) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision+1. */ + + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + + *p++ = dp->conversion; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', '.', '2', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + { + static const wchar_t decimal_format[] = + { '%', '+', '.', '2', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+.2d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+.2d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+.2d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+.2d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } # endif - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - if (precision == 0) - precision = 1; - /* precision >= 1. */ - - if (arg == 0.0L) - /* The exponent is 0, >= -4, < precision. - Use fixed-point notation. */ - { - size_t ndigits = precision; - /* Number of trailing zeroes that have to be - dropped. */ - size_t nzeroes = - (flags & FLAG_ALT ? 0 : precision - 1); - - --ndigits; - *p++ = '0'; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = '0'; - } - } - } - else - { - /* arg > 0.0L. */ - int exponent; - int adjusted; - char *digits; - size_t ndigits; - size_t nzeroes; - - exponent = floorlog10l (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_long_double (arg, - (int)(precision - 1) - exponent); - if (digits == NULL) - { - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - ndigits = strlen (digits); - - if (ndigits == precision) - break; - if (ndigits < precision - 1 - || ndigits > precision + 1) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits < precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision. */ - if (is_borderline (digits, precision - 1)) - { - /* Maybe the exponent guess was too high - and a smaller exponent can be reached - by turning a 10...0 into 9...9x. */ - char *digits2 = - scale10_round_decimal_long_double (arg, - (int)(precision - 1) - exponent + 1); - if (digits2 == NULL) - { - free (digits); - END_LONG_DOUBLE_ROUNDING (); - goto out_of_memory; - } - if (strlen (digits2) == precision) - { - free (digits); - digits = digits2; - exponent -= 1; - } - else - free (digits2); - } - /* Here ndigits = precision. */ - - /* Determine the number of trailing zeroes - that have to be dropped. */ - nzeroes = 0; - if ((flags & FLAG_ALT) == 0) - while (nzeroes < ndigits - && digits[nzeroes] == '0') - nzeroes++; - - /* The exponent is now determined. */ - if (exponent >= -4 - && exponent < (long)precision) - { - /* Fixed-point notation: - max(exponent,0)+1 digits, then the - decimal point, then the remaining - digits without trailing zeroes. */ - if (exponent >= 0) - { - size_t count = exponent + 1; - /* Note: count <= precision = ndigits. */ - for (; count > 0; count--) - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - size_t count = -exponent - 1; - *p++ = '0'; - *p++ = decimal_point_char (); - for (; count > 0; count--) - *p++ = '0'; - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - /* Exponential notation. */ - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + if (precision == 0) + precision = 1; + /* precision >= 1. */ + + if (arg == 0.0L) + /* The exponent is 0, >= -4, < precision. + Use fixed-point notation. */ + { + size_t ndigits = precision; + /* Number of trailing zeroes that have to be + dropped. */ + size_t nzeroes = + (flags & FLAG_ALT ? 0 : precision - 1); + + --ndigits; + *p++ = '0'; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = '0'; + } + } + } + else + { + /* arg > 0.0L. */ + int exponent; + int adjusted; + char *digits; + size_t ndigits; + size_t nzeroes; + + exponent = floorlog10l (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_long_double (arg, + (int)(precision - 1) - exponent); + if (digits == NULL) + { + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + ndigits = strlen (digits); + + if (ndigits == precision) + break; + if (ndigits < precision - 1 + || ndigits > precision + 1) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits < precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision. */ + if (is_borderline (digits, precision - 1)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_long_double (arg, + (int)(precision - 1) - exponent + 1); + if (digits2 == NULL) + { + free (digits); + END_LONG_DOUBLE_ROUNDING (); + goto out_of_memory; + } + if (strlen (digits2) == precision) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision. */ + + /* Determine the number of trailing zeroes + that have to be dropped. */ + nzeroes = 0; + if ((flags & FLAG_ALT) == 0) + while (nzeroes < ndigits + && digits[nzeroes] == '0') + nzeroes++; + + /* The exponent is now determined. */ + if (exponent >= -4 + && exponent < (long)precision) + { + /* Fixed-point notation: + max(exponent,0)+1 digits, then the + decimal point, then the remaining + digits without trailing zeroes. */ + if (exponent >= 0) + { + size_t count = exponent + 1; + /* Note: count <= precision = ndigits. */ + for (; count > 0; count--) + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + size_t count = -exponent - 1; + *p++ = '0'; + *p++ = decimal_point_char (); + for (; count > 0; count--) + *p++ = '0'; + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + /* Exponential notation. */ + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - { '%', '+', '.', '2', 'd', '\0' }; - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + { + static const wchar_t decimal_format[] = + { '%', '+', '.', '2', 'd', '\0' }; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, "%+.2d", exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, "%+.2d", exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, "%+.2d", exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, "%+.2d", exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } # endif - } + } - free (digits); - } - } - else - abort (); + free (digits); + } + } + else + abort (); # else - /* arg is finite. */ - if (!(arg == 0.0L)) - abort (); - - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - *p++ = dp->conversion; /* 'e' or 'E' */ - *p++ = '+'; - *p++ = '0'; - *p++ = '0'; - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - *p++ = '0'; - if (flags & FLAG_ALT) - { - size_t ndigits = - (precision > 0 ? precision - 1 : 0); - *p++ = decimal_point_char (); - for (; ndigits > 0; --ndigits) - *p++ = '0'; - } - } - else if (dp->conversion == 'a' || dp->conversion == 'A') - { - *p++ = '0'; - *p++ = dp->conversion - 'A' + 'X'; - pad_ptr = p; - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - *p++ = dp->conversion - 'A' + 'P'; - *p++ = '+'; - *p++ = '0'; - } - else - abort (); + /* arg is finite. */ + if (!(arg == 0.0L)) + abort (); + + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + *p++ = dp->conversion; /* 'e' or 'E' */ + *p++ = '+'; + *p++ = '0'; + *p++ = '0'; + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + *p++ = '0'; + if (flags & FLAG_ALT) + { + size_t ndigits = + (precision > 0 ? precision - 1 : 0); + *p++ = decimal_point_char (); + for (; ndigits > 0; --ndigits) + *p++ = '0'; + } + } + else if (dp->conversion == 'a' || dp->conversion == 'A') + { + *p++ = '0'; + *p++ = dp->conversion - 'A' + 'X'; + pad_ptr = p; + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + *p++ = dp->conversion - 'A' + 'P'; + *p++ = '+'; + *p++ = '0'; + } + else + abort (); # endif - } + } - END_LONG_DOUBLE_ROUNDING (); - } - } + END_LONG_DOUBLE_ROUNDING (); + } + } # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - else + else # endif # endif # if NEED_PRINTF_DOUBLE || NEED_PRINTF_INFINITE_DOUBLE - { - double arg = a.arg[dp->arg_index].a.a_double; - - if (isnand (arg)) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; - } - else - { - *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; - } - } - else - { - int sign = 0; - - if (signbit (arg)) /* arg < 0.0 or negative zero */ - { - sign = -1; - arg = -arg; - } - - if (sign < 0) - *p++ = '-'; - else if (flags & FLAG_SHOWSIGN) - *p++ = '+'; - else if (flags & FLAG_SPACE) - *p++ = ' '; - - if (arg > 0.0 && arg + arg == arg) - { - if (dp->conversion >= 'A' && dp->conversion <= 'Z') - { - *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; - } - else - { - *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; - } - } - else - { + { + double arg = a.arg[dp->arg_index].a.a_double; + + if (isnand (arg)) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'N'; *p++ = 'A'; *p++ = 'N'; + } + else + { + *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; + } + } + else + { + int sign = 0; + + if (signbit (arg)) /* arg < 0.0 or negative zero */ + { + sign = -1; + arg = -arg; + } + + if (sign < 0) + *p++ = '-'; + else if (flags & FLAG_SHOWSIGN) + *p++ = '+'; + else if (flags & FLAG_SPACE) + *p++ = ' '; + + if (arg > 0.0 && arg + arg == arg) + { + if (dp->conversion >= 'A' && dp->conversion <= 'Z') + { + *p++ = 'I'; *p++ = 'N'; *p++ = 'F'; + } + else + { + *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; + } + } + else + { # if NEED_PRINTF_DOUBLE - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - char *digits; - size_t ndigits; - - digits = - scale10_round_decimal_double (arg, precision); - if (digits == NULL) - goto out_of_memory; - ndigits = strlen (digits); - - if (ndigits > precision) - do - { - --ndigits; - *p++ = digits[ndigits]; - } - while (ndigits > precision); - else - *p++ = '0'; - /* Here ndigits <= precision. */ - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > ndigits; precision--) - *p++ = '0'; - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - int exponent; - - if (arg == 0.0) - { - exponent = 0; - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else - { - /* arg > 0.0. */ - int adjusted; - char *digits; - size_t ndigits; - - exponent = floorlog10 (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_double (arg, - (int)precision - exponent); - if (digits == NULL) - goto out_of_memory; - ndigits = strlen (digits); - - if (ndigits == precision + 1) - break; - if (ndigits < precision - || ndigits > precision + 2) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits == precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision+1. */ - if (is_borderline (digits, precision)) - { - /* Maybe the exponent guess was too high - and a smaller exponent can be reached - by turning a 10...0 into 9...9x. */ - char *digits2 = - scale10_round_decimal_double (arg, - (int)precision - exponent + 1); - if (digits2 == NULL) - { - free (digits); - goto out_of_memory; - } - if (strlen (digits2) == precision + 1) - { - free (digits); - digits = digits2; - exponent -= 1; - } - else - free (digits2); - } - /* Here ndigits = precision+1. */ - - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - while (ndigits > 0) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - - free (digits); - } - - *p++ = dp->conversion; /* 'e' or 'E' */ + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + char *digits; + size_t ndigits; + + digits = + scale10_round_decimal_double (arg, precision); + if (digits == NULL) + goto out_of_memory; + ndigits = strlen (digits); + + if (ndigits > precision) + do + { + --ndigits; + *p++ = digits[ndigits]; + } + while (ndigits > precision); + else + *p++ = '0'; + /* Here ndigits <= precision. */ + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > ndigits; precision--) + *p++ = '0'; + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + int exponent; + + if (arg == 0.0) + { + exponent = 0; + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else + { + /* arg > 0.0. */ + int adjusted; + char *digits; + size_t ndigits; + + exponent = floorlog10 (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_double (arg, + (int)precision - exponent); + if (digits == NULL) + goto out_of_memory; + ndigits = strlen (digits); + + if (ndigits == precision + 1) + break; + if (ndigits < precision + || ndigits > precision + 2) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits == precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision+1. */ + if (is_borderline (digits, precision)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_double (arg, + (int)precision - exponent + 1); + if (digits2 == NULL) + { + free (digits); + goto out_of_memory; + } + if (strlen (digits2) == precision + 1) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision+1. */ + + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + while (ndigits > 0) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + + free (digits); + } + + *p++ = dp->conversion; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - /* Produce the same number of exponent digits - as the native printf implementation. */ + { + static const wchar_t decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - { '%', '+', '.', '3', 'd', '\0' }; + { '%', '+', '.', '3', 'd', '\0' }; # else - { '%', '+', '.', '2', 'd', '\0' }; + { '%', '+', '.', '2', 'd', '\0' }; # endif - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - { - static const char decimal_format[] = - /* Produce the same number of exponent digits - as the native printf implementation. */ + { + static const char decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - "%+.3d"; + "%+.3d"; # else - "%+.2d"; + "%+.2d"; # endif - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, decimal_format, exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, decimal_format, exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, decimal_format, exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, decimal_format, exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } + } # endif - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - if (precision == 0) - precision = 1; - /* precision >= 1. */ - - if (arg == 0.0) - /* The exponent is 0, >= -4, < precision. - Use fixed-point notation. */ - { - size_t ndigits = precision; - /* Number of trailing zeroes that have to be - dropped. */ - size_t nzeroes = - (flags & FLAG_ALT ? 0 : precision - 1); - - --ndigits; - *p++ = '0'; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = '0'; - } - } - } - else - { - /* arg > 0.0. */ - int exponent; - int adjusted; - char *digits; - size_t ndigits; - size_t nzeroes; - - exponent = floorlog10 (arg); - adjusted = 0; - for (;;) - { - digits = - scale10_round_decimal_double (arg, - (int)(precision - 1) - exponent); - if (digits == NULL) - goto out_of_memory; - ndigits = strlen (digits); - - if (ndigits == precision) - break; - if (ndigits < precision - 1 - || ndigits > precision + 1) - /* The exponent was not guessed - precisely enough. */ - abort (); - if (adjusted) - /* None of two values of exponent is - the right one. Prevent an endless - loop. */ - abort (); - free (digits); - if (ndigits < precision) - exponent -= 1; - else - exponent += 1; - adjusted = 1; - } - /* Here ndigits = precision. */ - if (is_borderline (digits, precision - 1)) - { - /* Maybe the exponent guess was too high - and a smaller exponent can be reached - by turning a 10...0 into 9...9x. */ - char *digits2 = - scale10_round_decimal_double (arg, - (int)(precision - 1) - exponent + 1); - if (digits2 == NULL) - { - free (digits); - goto out_of_memory; - } - if (strlen (digits2) == precision) - { - free (digits); - digits = digits2; - exponent -= 1; - } - else - free (digits2); - } - /* Here ndigits = precision. */ - - /* Determine the number of trailing zeroes - that have to be dropped. */ - nzeroes = 0; - if ((flags & FLAG_ALT) == 0) - while (nzeroes < ndigits - && digits[nzeroes] == '0') - nzeroes++; - - /* The exponent is now determined. */ - if (exponent >= -4 - && exponent < (long)precision) - { - /* Fixed-point notation: - max(exponent,0)+1 digits, then the - decimal point, then the remaining - digits without trailing zeroes. */ - if (exponent >= 0) - { - size_t count = exponent + 1; - /* Note: count <= precision = ndigits. */ - for (; count > 0; count--) - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - size_t count = -exponent - 1; - *p++ = '0'; - *p++ = decimal_point_char (); - for (; count > 0; count--) - *p++ = '0'; - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - } - else - { - /* Exponential notation. */ - *p++ = digits[--ndigits]; - if ((flags & FLAG_ALT) || ndigits > nzeroes) - { - *p++ = decimal_point_char (); - while (ndigits > nzeroes) - { - --ndigits; - *p++ = digits[ndigits]; - } - } - *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + if (precision == 0) + precision = 1; + /* precision >= 1. */ + + if (arg == 0.0) + /* The exponent is 0, >= -4, < precision. + Use fixed-point notation. */ + { + size_t ndigits = precision; + /* Number of trailing zeroes that have to be + dropped. */ + size_t nzeroes = + (flags & FLAG_ALT ? 0 : precision - 1); + + --ndigits; + *p++ = '0'; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = '0'; + } + } + } + else + { + /* arg > 0.0. */ + int exponent; + int adjusted; + char *digits; + size_t ndigits; + size_t nzeroes; + + exponent = floorlog10 (arg); + adjusted = 0; + for (;;) + { + digits = + scale10_round_decimal_double (arg, + (int)(precision - 1) - exponent); + if (digits == NULL) + goto out_of_memory; + ndigits = strlen (digits); + + if (ndigits == precision) + break; + if (ndigits < precision - 1 + || ndigits > precision + 1) + /* The exponent was not guessed + precisely enough. */ + abort (); + if (adjusted) + /* None of two values of exponent is + the right one. Prevent an endless + loop. */ + abort (); + free (digits); + if (ndigits < precision) + exponent -= 1; + else + exponent += 1; + adjusted = 1; + } + /* Here ndigits = precision. */ + if (is_borderline (digits, precision - 1)) + { + /* Maybe the exponent guess was too high + and a smaller exponent can be reached + by turning a 10...0 into 9...9x. */ + char *digits2 = + scale10_round_decimal_double (arg, + (int)(precision - 1) - exponent + 1); + if (digits2 == NULL) + { + free (digits); + goto out_of_memory; + } + if (strlen (digits2) == precision) + { + free (digits); + digits = digits2; + exponent -= 1; + } + else + free (digits2); + } + /* Here ndigits = precision. */ + + /* Determine the number of trailing zeroes + that have to be dropped. */ + nzeroes = 0; + if ((flags & FLAG_ALT) == 0) + while (nzeroes < ndigits + && digits[nzeroes] == '0') + nzeroes++; + + /* The exponent is now determined. */ + if (exponent >= -4 + && exponent < (long)precision) + { + /* Fixed-point notation: + max(exponent,0)+1 digits, then the + decimal point, then the remaining + digits without trailing zeroes. */ + if (exponent >= 0) + { + size_t count = exponent + 1; + /* Note: count <= precision = ndigits. */ + for (; count > 0; count--) + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + size_t count = -exponent - 1; + *p++ = '0'; + *p++ = decimal_point_char (); + for (; count > 0; count--) + *p++ = '0'; + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + } + else + { + /* Exponential notation. */ + *p++ = digits[--ndigits]; + if ((flags & FLAG_ALT) || ndigits > nzeroes) + { + *p++ = decimal_point_char (); + while (ndigits > nzeroes) + { + --ndigits; + *p++ = digits[ndigits]; + } + } + *p++ = dp->conversion - 'G' + 'E'; /* 'e' or 'E' */ # if WIDE_CHAR_VERSION - { - static const wchar_t decimal_format[] = - /* Produce the same number of exponent digits - as the native printf implementation. */ + { + static const wchar_t decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - { '%', '+', '.', '3', 'd', '\0' }; + { '%', '+', '.', '3', 'd', '\0' }; # else - { '%', '+', '.', '2', 'd', '\0' }; + { '%', '+', '.', '2', 'd', '\0' }; # endif - SNPRINTF (p, 6 + 1, decimal_format, exponent); - } - while (*p != '\0') - p++; + SNPRINTF (p, 6 + 1, decimal_format, exponent); + } + while (*p != '\0') + p++; # else - { - static const char decimal_format[] = - /* Produce the same number of exponent digits - as the native printf implementation. */ + { + static const char decimal_format[] = + /* Produce the same number of exponent digits + as the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - "%+.3d"; + "%+.3d"; # else - "%+.2d"; + "%+.2d"; # endif - if (sizeof (DCHAR_T) == 1) - { - sprintf ((char *) p, decimal_format, exponent); - while (*p != '\0') - p++; - } - else - { - char expbuf[6 + 1]; - const char *ep; - sprintf (expbuf, decimal_format, exponent); - for (ep = expbuf; (*p = *ep) != '\0'; ep++) - p++; - } - } + if (sizeof (DCHAR_T) == 1) + { + sprintf ((char *) p, decimal_format, exponent); + while (*p != '\0') + p++; + } + else + { + char expbuf[6 + 1]; + const char *ep; + sprintf (expbuf, decimal_format, exponent); + for (ep = expbuf; (*p = *ep) != '\0'; ep++) + p++; + } + } # endif - } + } - free (digits); - } - } - else - abort (); + free (digits); + } + } + else + abort (); # else - /* arg is finite. */ - if (!(arg == 0.0)) - abort (); - - pad_ptr = p; - - if (dp->conversion == 'f' || dp->conversion == 'F') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - } - else if (dp->conversion == 'e' || dp->conversion == 'E') - { - *p++ = '0'; - if ((flags & FLAG_ALT) || precision > 0) - { - *p++ = decimal_point_char (); - for (; precision > 0; precision--) - *p++ = '0'; - } - *p++ = dp->conversion; /* 'e' or 'E' */ - *p++ = '+'; - /* Produce the same number of exponent digits as - the native printf implementation. */ + /* arg is finite. */ + if (!(arg == 0.0)) + abort (); + + pad_ptr = p; + + if (dp->conversion == 'f' || dp->conversion == 'F') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + } + else if (dp->conversion == 'e' || dp->conversion == 'E') + { + *p++ = '0'; + if ((flags & FLAG_ALT) || precision > 0) + { + *p++ = decimal_point_char (); + for (; precision > 0; precision--) + *p++ = '0'; + } + *p++ = dp->conversion; /* 'e' or 'E' */ + *p++ = '+'; + /* Produce the same number of exponent digits as + the native printf implementation. */ # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - *p++ = '0'; + *p++ = '0'; # endif - *p++ = '0'; - *p++ = '0'; - } - else if (dp->conversion == 'g' || dp->conversion == 'G') - { - *p++ = '0'; - if (flags & FLAG_ALT) - { - size_t ndigits = - (precision > 0 ? precision - 1 : 0); - *p++ = decimal_point_char (); - for (; ndigits > 0; --ndigits) - *p++ = '0'; - } - } - else - abort (); + *p++ = '0'; + *p++ = '0'; + } + else if (dp->conversion == 'g' || dp->conversion == 'G') + { + *p++ = '0'; + if (flags & FLAG_ALT) + { + size_t ndigits = + (precision > 0 ? precision - 1 : 0); + *p++ = decimal_point_char (); + for (; ndigits > 0; --ndigits) + *p++ = '0'; + } + } + else + abort (); # endif - } - } - } + } + } + } # endif - /* The generated string now extends from tmp to p, with the - zero padding insertion point being at pad_ptr. */ - if (has_width && p - tmp < width) - { - size_t pad = width - (p - tmp); - DCHAR_T *end = p + pad; - - if (flags & FLAG_LEFT) - { - /* Pad with spaces on the right. */ - for (; pad > 0; pad--) - *p++ = ' '; - } - else if ((flags & FLAG_ZERO) && pad_ptr != NULL) - { - /* Pad with zeroes. */ - DCHAR_T *q = end; - - while (p > pad_ptr) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = '0'; - } - else - { - /* Pad with spaces on the left. */ - DCHAR_T *q = end; - - while (p > tmp) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = ' '; - } - - p = end; - } - - { - size_t count = p - tmp; - - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); - - /* Make room for the result. */ - if (count >= allocated - length) - { - size_t n = xsum (length, count); - - ENSURE_ALLOCATION (n); - } - - /* Append the result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); - if (tmp != tmpbuf) - free (tmp); - length += count; - } - } + /* The generated string now extends from tmp to p, with the + zero padding insertion point being at pad_ptr. */ + if (has_width && p - tmp < width) + { + size_t pad = width - (p - tmp); + DCHAR_T *end = p + pad; + + if (flags & FLAG_LEFT) + { + /* Pad with spaces on the right. */ + for (; pad > 0; pad--) + *p++ = ' '; + } + else if ((flags & FLAG_ZERO) && pad_ptr != NULL) + { + /* Pad with zeroes. */ + DCHAR_T *q = end; + + while (p > pad_ptr) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = '0'; + } + else + { + /* Pad with spaces on the left. */ + DCHAR_T *q = end; + + while (p > tmp) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = ' '; + } + + p = end; + } + + { + size_t count = p - tmp; + + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); + + /* Make room for the result. */ + if (count >= allocated - length) + { + size_t n = xsum (length, count); + + ENSURE_ALLOCATION (n); + } + + /* Append the result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); + if (tmp != tmpbuf) + free (tmp); + length += count; + } + } #endif - else - { - arg_type type = a.arg[dp->arg_index].type; - int flags = dp->flags; -#if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - int has_width; - size_t width; + else + { + arg_type type = a.arg[dp->arg_index].type; + int flags = dp->flags; +#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION + int has_width; + size_t width; #endif -#if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION - int has_precision; - size_t precision; +#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION + int has_precision; + size_t precision; #endif #if NEED_PRINTF_UNBOUNDED_PRECISION - int prec_ourselves; + int prec_ourselves; #else -# define prec_ourselves 0 +# define prec_ourselves 0 #endif #if NEED_PRINTF_FLAG_LEFTADJUST -# define pad_ourselves 1 +# define pad_ourselves 1 #elif !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - int pad_ourselves; + int pad_ourselves; #else -# define pad_ourselves 0 +# define pad_ourselves 0 #endif - TCHAR_T *fbp; - unsigned int prefix_count; - int prefixes[2] IF_LINT (= { 0 }); + TCHAR_T *fbp; + unsigned int prefix_count; + int prefixes[2] IF_LINT (= { 0 }); #if !USE_SNPRINTF - size_t tmp_length; - TCHAR_T tmpbuf[700]; - TCHAR_T *tmp; + size_t tmp_length; + TCHAR_T tmpbuf[700]; + TCHAR_T *tmp; #endif -#if !USE_SNPRINTF || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - has_width = 0; - width = 0; - if (dp->width_start != dp->width_end) - { - if (dp->width_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->width_arg_index].a.a_int; - if (arg < 0) - { - /* "A negative field width is taken as a '-' flag - followed by a positive field width." */ - flags |= FLAG_LEFT; - width = (unsigned int) (-arg); - } - else - width = arg; - } - else - { - const FCHAR_T *digitp = dp->width_start; - - do - width = xsum (xtimes (width, 10), *digitp++ - '0'); - while (digitp != dp->width_end); - } - has_width = 1; - } +#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION + has_width = 0; + width = 0; + if (dp->width_start != dp->width_end) + { + if (dp->width_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->width_arg_index].a.a_int; + if (arg < 0) + { + /* "A negative field width is taken as a '-' flag + followed by a positive field width." */ + flags |= FLAG_LEFT; + width = (unsigned int) (-arg); + } + else + width = arg; + } + else + { + const FCHAR_T *digitp = dp->width_start; + + do + width = xsum (xtimes (width, 10), *digitp++ - '0'); + while (digitp != dp->width_end); + } + has_width = 1; + } #endif -#if !USE_SNPRINTF || NEED_PRINTF_UNBOUNDED_PRECISION - has_precision = 0; - precision = 6; - if (dp->precision_start != dp->precision_end) - { - if (dp->precision_arg_index != ARG_NONE) - { - int arg; - - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - arg = a.arg[dp->precision_arg_index].a.a_int; - /* "A negative precision is taken as if the precision - were omitted." */ - if (arg >= 0) - { - precision = arg; - has_precision = 1; - } - } - else - { - const FCHAR_T *digitp = dp->precision_start + 1; - - precision = 0; - while (digitp != dp->precision_end) - precision = xsum (xtimes (precision, 10), *digitp++ - '0'); - has_precision = 1; - } - } +#if !USE_SNPRINTF || !HAVE_SNPRINTF_RETVAL_C99 || NEED_PRINTF_UNBOUNDED_PRECISION + has_precision = 0; + precision = 6; + if (dp->precision_start != dp->precision_end) + { + if (dp->precision_arg_index != ARG_NONE) + { + int arg; + + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + arg = a.arg[dp->precision_arg_index].a.a_int; + /* "A negative precision is taken as if the precision + were omitted." */ + if (arg >= 0) + { + precision = arg; + has_precision = 1; + } + } + else + { + const FCHAR_T *digitp = dp->precision_start + 1; + + precision = 0; + while (digitp != dp->precision_end) + precision = xsum (xtimes (precision, 10), *digitp++ - '0'); + has_precision = 1; + } + } #endif - /* Decide whether to handle the precision ourselves. */ + /* Decide whether to handle the precision ourselves. */ #if NEED_PRINTF_UNBOUNDED_PRECISION - switch (dp->conversion) - { - case 'd': case 'i': case 'u': - case 'o': - case 'x': case 'X': case 'p': - prec_ourselves = has_precision && (precision > 0); - break; - default: - prec_ourselves = 0; - break; - } + switch (dp->conversion) + { + case 'd': case 'i': case 'u': + case 'o': + case 'x': case 'X': case 'p': + prec_ourselves = has_precision && (precision > 0); + break; + default: + prec_ourselves = 0; + break; + } #endif - /* Decide whether to perform the padding ourselves. */ + /* Decide whether to perform the padding ourselves. */ #if !NEED_PRINTF_FLAG_LEFTADJUST && (!DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION) - switch (dp->conversion) - { + switch (dp->conversion) + { # if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO - /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need - to perform the padding after this conversion. Functions - with unistdio extensions perform the padding based on - character count rather than element count. */ - case 'c': case 's': + /* If we need conversion from TCHAR_T[] to DCHAR_T[], we need + to perform the padding after this conversion. Functions + with unistdio extensions perform the padding based on + character count rather than element count. */ + case 'c': case 's': # endif # if NEED_PRINTF_FLAG_ZERO - case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': - case 'a': case 'A': + case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': + case 'a': case 'A': # endif - pad_ourselves = 1; - break; - default: - pad_ourselves = prec_ourselves; - break; - } + pad_ourselves = 1; + break; + default: + pad_ourselves = prec_ourselves; + break; + } #endif #if !USE_SNPRINTF - /* Allocate a temporary buffer of sufficient size for calling - sprintf. */ - { - switch (dp->conversion) - { - - case 'd': case 'i': case 'u': -# if HAVE_LONG_LONG_INT - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - ) - + 1; /* turn floor into ceil */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.30103 /* binary -> decimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Multiply by 2, as an estimate for FLAG_GROUP. */ - tmp_length = xsum (tmp_length, tmp_length); - /* Add 1, to account for a leading sign. */ - tmp_length = xsum (tmp_length, 1); - break; - - case 'o': -# if HAVE_LONG_LONG_INT - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1; /* turn floor into ceil */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.333334 /* binary -> octal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Add 1, to account for a leading sign. */ - tmp_length = xsum (tmp_length, 1); - break; - - case 'x': case 'X': -# if HAVE_LONG_LONG_INT - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else -# endif - if (type == TYPE_LONGINT || type == TYPE_ULONGINT) - tmp_length = - (unsigned int) (sizeof (unsigned long) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (sizeof (unsigned int) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Add 2, to account for a leading sign or alternate form. */ - tmp_length = xsum (tmp_length, 2); - break; - - case 'f': case 'F': - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) (LDBL_MAX_EXP - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 10; /* sign, decimal point etc. */ - else - tmp_length = - (unsigned int) (DBL_MAX_EXP - * 0.30103 /* binary -> decimal */ - * 2 /* estimate for FLAG_GROUP */ - ) - + 1 /* turn floor into ceil */ - + 10; /* sign, decimal point etc. */ - tmp_length = xsum (tmp_length, precision); - break; - - case 'e': case 'E': case 'g': case 'G': - tmp_length = - 12; /* sign, decimal point, exponent etc. */ - tmp_length = xsum (tmp_length, precision); - break; - - case 'a': case 'A': - if (type == TYPE_LONGDOUBLE) - tmp_length = - (unsigned int) (LDBL_DIG - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - else - tmp_length = - (unsigned int) (DBL_DIG - * 0.831 /* decimal -> hexadecimal */ - ) - + 1; /* turn floor into ceil */ - if (tmp_length < precision) - tmp_length = precision; - /* Account for sign, decimal point etc. */ - tmp_length = xsum (tmp_length, 12); - break; - - case 'c': -# if HAVE_WINT_T && !WIDE_CHAR_VERSION - if (type == TYPE_WIDE_CHAR) - tmp_length = MB_CUR_MAX; - else -# endif - tmp_length = 1; - break; - - case 's': -# if HAVE_WCHAR_T - if (type == TYPE_WIDE_STRING) - { -# if WIDE_CHAR_VERSION - /* ISO C says about %ls in fwprintf: - "If the precision is not specified or is greater - than the size of the array, the array shall - contain a null wide character." - So if there is a precision, we must not use - wcslen. */ - const wchar_t *arg = - a.arg[dp->arg_index].a.a_wide_string; - - if (has_precision) - tmp_length = local_wcsnlen (arg, precision); - else - tmp_length = local_wcslen (arg); -# else - /* ISO C says about %ls in fprintf: - "If a precision is specified, no more than that - many bytes are written (including shift - sequences, if any), and the array shall contain - a null wide character if, to equal the - multibyte character sequence length given by - the precision, the function would need to - access a wide character one past the end of the - array." - So if there is a precision, we must not use - wcslen. */ - /* This case has already been handled above. */ - abort (); -# endif - } - else -# endif - { -# if WIDE_CHAR_VERSION - /* ISO C says about %s in fwprintf: - "If the precision is not specified or is greater - than the size of the converted array, the - converted array shall contain a null wide - character." - So if there is a precision, we must not use - strlen. */ - /* This case has already been handled above. */ - abort (); -# else - /* ISO C says about %s in fprintf: - "If the precision is not specified or greater - than the size of the array, the array shall - contain a null character." - So if there is a precision, we must not use - strlen. */ - const char *arg = a.arg[dp->arg_index].a.a_string; - - if (has_precision) - tmp_length = local_strnlen (arg, precision); - else - tmp_length = strlen (arg); -# endif - } - break; - - case 'p': - tmp_length = - (unsigned int) (sizeof (void *) * CHAR_BIT - * 0.25 /* binary -> hexadecimal */ - ) - + 1 /* turn floor into ceil */ - + 2; /* account for leading 0x */ - break; - - default: - abort (); - } - - if (!pad_ourselves) - { -# if ENABLE_UNISTDIO - /* Padding considers the number of characters, therefore - the number of elements after padding may be - > max (tmp_length, width) - but is certainly - <= tmp_length + width. */ - tmp_length = xsum (tmp_length, width); -# else - /* Padding considers the number of elements, - says POSIX. */ - if (tmp_length < width) - tmp_length = width; -# endif - } - - tmp_length = xsum (tmp_length, 1); /* account for trailing NUL */ - } - - if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T)) - tmp = tmpbuf; - else - { - size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T)); - - if (size_overflow_p (tmp_memsize)) - /* Overflow, would lead to out of memory. */ - goto out_of_memory; - tmp = (TCHAR_T *) malloc (tmp_memsize); - if (tmp == NULL) - /* Out of memory. */ - goto out_of_memory; - } + /* Allocate a temporary buffer of sufficient size for calling + sprintf. */ + tmp_length = + MAX_ROOM_NEEDED (&a, dp->arg_index, dp->conversion, type, + flags, width, has_precision, precision, + pad_ourselves); + + if (tmp_length <= sizeof (tmpbuf) / sizeof (TCHAR_T)) + tmp = tmpbuf; + else + { + size_t tmp_memsize = xtimes (tmp_length, sizeof (TCHAR_T)); + + if (size_overflow_p (tmp_memsize)) + /* Overflow, would lead to out of memory. */ + goto out_of_memory; + tmp = (TCHAR_T *) malloc (tmp_memsize); + if (tmp == NULL) + /* Out of memory. */ + goto out_of_memory; + } #endif - /* Construct the format string for calling snprintf or - sprintf. */ - fbp = buf; - *fbp++ = '%'; + /* Construct the format string for calling snprintf or + sprintf. */ + fbp = buf; + *fbp++ = '%'; #if NEED_PRINTF_FLAG_GROUPING - /* The underlying implementation doesn't support the ' flag. - Produce no grouping characters in this case; this is - acceptable because the grouping is locale dependent. */ + /* The underlying implementation doesn't support the ' flag. + Produce no grouping characters in this case; this is + acceptable because the grouping is locale dependent. */ #else - if (flags & FLAG_GROUP) - *fbp++ = '\''; + if (flags & FLAG_GROUP) + *fbp++ = '\''; #endif - if (flags & FLAG_LEFT) - *fbp++ = '-'; - if (flags & FLAG_SHOWSIGN) - *fbp++ = '+'; - if (flags & FLAG_SPACE) - *fbp++ = ' '; - if (flags & FLAG_ALT) - *fbp++ = '#'; - if (!pad_ourselves) - { - if (flags & FLAG_ZERO) - *fbp++ = '0'; - if (dp->width_start != dp->width_end) - { - size_t n = dp->width_end - dp->width_start; - /* The width specification is known to consist only - of standard ASCII characters. */ - if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) - { - memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T)); - fbp += n; - } - else - { - const FCHAR_T *mp = dp->width_start; - do - *fbp++ = (unsigned char) *mp++; - while (--n > 0); - } - } - } - if (!prec_ourselves) - { - if (dp->precision_start != dp->precision_end) - { - size_t n = dp->precision_end - dp->precision_start; - /* The precision specification is known to consist only - of standard ASCII characters. */ - if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) - { - memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T)); - fbp += n; - } - else - { - const FCHAR_T *mp = dp->precision_start; - do - *fbp++ = (unsigned char) *mp++; - while (--n > 0); - } - } - } - - switch (type) - { + if (flags & FLAG_LEFT) + *fbp++ = '-'; + if (flags & FLAG_SHOWSIGN) + *fbp++ = '+'; + if (flags & FLAG_SPACE) + *fbp++ = ' '; + if (flags & FLAG_ALT) + *fbp++ = '#'; + if (!pad_ourselves) + { + if (flags & FLAG_ZERO) + *fbp++ = '0'; + if (dp->width_start != dp->width_end) + { + size_t n = dp->width_end - dp->width_start; + /* The width specification is known to consist only + of standard ASCII characters. */ + if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) + { + memcpy (fbp, dp->width_start, n * sizeof (TCHAR_T)); + fbp += n; + } + else + { + const FCHAR_T *mp = dp->width_start; + do + *fbp++ = (unsigned char) *mp++; + while (--n > 0); + } + } + } + if (!prec_ourselves) + { + if (dp->precision_start != dp->precision_end) + { + size_t n = dp->precision_end - dp->precision_start; + /* The precision specification is known to consist only + of standard ASCII characters. */ + if (sizeof (FCHAR_T) == sizeof (TCHAR_T)) + { + memcpy (fbp, dp->precision_start, n * sizeof (TCHAR_T)); + fbp += n; + } + else + { + const FCHAR_T *mp = dp->precision_start; + do + *fbp++ = (unsigned char) *mp++; + while (--n > 0); + } + } + } + + switch (type) + { #if HAVE_LONG_LONG_INT - case TYPE_LONGLONGINT: - case TYPE_ULONGLONGINT: + case TYPE_LONGLONGINT: + case TYPE_ULONGLONGINT: # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ - *fbp++ = 'I'; - *fbp++ = '6'; - *fbp++ = '4'; - break; + *fbp++ = 'I'; + *fbp++ = '6'; + *fbp++ = '4'; + break; # else - *fbp++ = 'l'; - /*FALLTHROUGH*/ + *fbp++ = 'l'; + /*FALLTHROUGH*/ # endif #endif - case TYPE_LONGINT: - case TYPE_ULONGINT: + case TYPE_LONGINT: + case TYPE_ULONGINT: #if HAVE_WINT_T - case TYPE_WIDE_CHAR: + case TYPE_WIDE_CHAR: #endif #if HAVE_WCHAR_T - case TYPE_WIDE_STRING: + case TYPE_WIDE_STRING: #endif - *fbp++ = 'l'; - break; - case TYPE_LONGDOUBLE: - *fbp++ = 'L'; - break; - default: - break; - } + *fbp++ = 'l'; + break; + case TYPE_LONGDOUBLE: + *fbp++ = 'L'; + break; + default: + break; + } #if NEED_PRINTF_DIRECTIVE_F - if (dp->conversion == 'F') - *fbp = 'f'; - else + if (dp->conversion == 'F') + *fbp = 'f'; + else #endif - *fbp = dp->conversion; + *fbp = dp->conversion; #if USE_SNPRINTF # if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) - fbp[1] = '%'; - fbp[2] = 'n'; - fbp[3] = '\0'; + fbp[1] = '%'; + fbp[2] = 'n'; + fbp[3] = '\0'; # else - /* On glibc2 systems from glibc >= 2.3 - probably also older - ones - we know that snprintf's returns value conforms to - ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes. - Therefore we can avoid using %n in this situation. - On glibc2 systems from 2004-10-18 or newer, the use of %n - in format strings in writable memory may crash the program - (if compiled with _FORTIFY_SOURCE=2), so we should avoid it - in this situation. */ - /* On native Win32 systems (such as mingw), we can avoid using - %n because: - - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, - snprintf does not write more than the specified number - of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes - '4', '5', '6' into buf, not '4', '5', '\0'.) - - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf - allows us to recognize the case of an insufficient - buffer size: it returns -1 in this case. - On native Win32 systems (such as mingw) where the OS is - Windows Vista, the use of %n in format strings by default - crashes the program. See - and - - So we should avoid %n in this situation. */ - fbp[1] = '\0'; + /* On glibc2 systems from glibc >= 2.3 - probably also older + ones - we know that snprintf's returns value conforms to + ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes. + Therefore we can avoid using %n in this situation. + On glibc2 systems from 2004-10-18 or newer, the use of %n + in format strings in writable memory may crash the program + (if compiled with _FORTIFY_SOURCE=2), so we should avoid it + in this situation. */ + /* On native Win32 systems (such as mingw), we can avoid using + %n because: + - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, + snprintf does not write more than the specified number + of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes + '4', '5', '6' into buf, not '4', '5', '\0'.) + - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf + allows us to recognize the case of an insufficient + buffer size: it returns -1 in this case. + On native Win32 systems (such as mingw) where the OS is + Windows Vista, the use of %n in format strings by default + crashes the program. See + and + + So we should avoid %n in this situation. */ + fbp[1] = '\0'; # endif #else - fbp[1] = '\0'; + fbp[1] = '\0'; #endif - /* Construct the arguments for calling snprintf or sprintf. */ - prefix_count = 0; - if (!pad_ourselves && dp->width_arg_index != ARG_NONE) - { - if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) - abort (); - prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; - } - if (!prec_ourselves && dp->precision_arg_index != ARG_NONE) - { - if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) - abort (); - prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; - } + /* Construct the arguments for calling snprintf or sprintf. */ + prefix_count = 0; + if (!pad_ourselves && dp->width_arg_index != ARG_NONE) + { + if (!(a.arg[dp->width_arg_index].type == TYPE_INT)) + abort (); + prefixes[prefix_count++] = a.arg[dp->width_arg_index].a.a_int; + } + if (!prec_ourselves && dp->precision_arg_index != ARG_NONE) + { + if (!(a.arg[dp->precision_arg_index].type == TYPE_INT)) + abort (); + prefixes[prefix_count++] = a.arg[dp->precision_arg_index].a.a_int; + } #if USE_SNPRINTF - /* The SNPRINTF result is appended after result[0..length]. - The latter is an array of DCHAR_T; SNPRINTF appends an - array of TCHAR_T to it. This is possible because - sizeof (TCHAR_T) divides sizeof (DCHAR_T) and - alignof (TCHAR_T) <= alignof (DCHAR_T). */ + /* The SNPRINTF result is appended after result[0..length]. + The latter is an array of DCHAR_T; SNPRINTF appends an + array of TCHAR_T to it. This is possible because + sizeof (TCHAR_T) divides sizeof (DCHAR_T) and + alignof (TCHAR_T) <= alignof (DCHAR_T). */ # define TCHARS_PER_DCHAR (sizeof (DCHAR_T) / sizeof (TCHAR_T)) - /* Ensure that maxlen below will be >= 2. Needed on BeOS, - where an snprintf() with maxlen==1 acts like sprintf(). */ - ENSURE_ALLOCATION (xsum (length, - (2 + TCHARS_PER_DCHAR - 1) - / TCHARS_PER_DCHAR)); - /* Prepare checking whether snprintf returns the count - via %n. */ - *(TCHAR_T *) (result + length) = '\0'; + /* Ensure that maxlen below will be >= 2. Needed on BeOS, + where an snprintf() with maxlen==1 acts like sprintf(). */ + ENSURE_ALLOCATION (xsum (length, + (2 + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR)); + /* Prepare checking whether snprintf returns the count + via %n. */ + *(TCHAR_T *) (result + length) = '\0'; #endif - for (;;) - { - int count = -1; + for (;;) + { + int count = -1; #if USE_SNPRINTF - int retcount = 0; - size_t maxlen = allocated - length; - /* SNPRINTF can fail if its second argument is - > INT_MAX. */ - if (maxlen > INT_MAX / TCHARS_PER_DCHAR) - maxlen = INT_MAX / TCHARS_PER_DCHAR; - maxlen = maxlen * TCHARS_PER_DCHAR; + int retcount = 0; + size_t maxlen = allocated - length; + /* SNPRINTF can fail if its second argument is + > INT_MAX. */ + if (maxlen > INT_MAX / TCHARS_PER_DCHAR) + maxlen = INT_MAX / TCHARS_PER_DCHAR; + maxlen = maxlen * TCHARS_PER_DCHAR; # define SNPRINTF_BUF(arg) \ - switch (prefix_count) \ - { \ - case 0: \ - retcount = SNPRINTF ((TCHAR_T *) (result + length), \ - maxlen, buf, \ - arg, &count); \ - break; \ - case 1: \ - retcount = SNPRINTF ((TCHAR_T *) (result + length), \ - maxlen, buf, \ - prefixes[0], arg, &count); \ - break; \ - case 2: \ - retcount = SNPRINTF ((TCHAR_T *) (result + length), \ - maxlen, buf, \ - prefixes[0], prefixes[1], arg, \ - &count); \ - break; \ - default: \ - abort (); \ - } + switch (prefix_count) \ + { \ + case 0: \ + retcount = SNPRINTF ((TCHAR_T *) (result + length), \ + maxlen, buf, \ + arg, &count); \ + break; \ + case 1: \ + retcount = SNPRINTF ((TCHAR_T *) (result + length), \ + maxlen, buf, \ + prefixes[0], arg, &count); \ + break; \ + case 2: \ + retcount = SNPRINTF ((TCHAR_T *) (result + length), \ + maxlen, buf, \ + prefixes[0], prefixes[1], arg, \ + &count); \ + break; \ + default: \ + abort (); \ + } #else # define SNPRINTF_BUF(arg) \ - switch (prefix_count) \ - { \ - case 0: \ - count = sprintf (tmp, buf, arg); \ - break; \ - case 1: \ - count = sprintf (tmp, buf, prefixes[0], arg); \ - break; \ - case 2: \ - count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ - arg); \ - break; \ - default: \ - abort (); \ - } + switch (prefix_count) \ + { \ + case 0: \ + count = sprintf (tmp, buf, arg); \ + break; \ + case 1: \ + count = sprintf (tmp, buf, prefixes[0], arg); \ + break; \ + case 2: \ + count = sprintf (tmp, buf, prefixes[0], prefixes[1],\ + arg); \ + break; \ + default: \ + abort (); \ + } #endif - switch (type) - { - case TYPE_SCHAR: - { - int arg = a.arg[dp->arg_index].a.a_schar; - SNPRINTF_BUF (arg); - } - break; - case TYPE_UCHAR: - { - unsigned int arg = a.arg[dp->arg_index].a.a_uchar; - SNPRINTF_BUF (arg); - } - break; - case TYPE_SHORT: - { - int arg = a.arg[dp->arg_index].a.a_short; - SNPRINTF_BUF (arg); - } - break; - case TYPE_USHORT: - { - unsigned int arg = a.arg[dp->arg_index].a.a_ushort; - SNPRINTF_BUF (arg); - } - break; - case TYPE_INT: - { - int arg = a.arg[dp->arg_index].a.a_int; - SNPRINTF_BUF (arg); - } - break; - case TYPE_UINT: - { - unsigned int arg = a.arg[dp->arg_index].a.a_uint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_LONGINT: - { - long int arg = a.arg[dp->arg_index].a.a_longint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_ULONGINT: - { - unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; - SNPRINTF_BUF (arg); - } - break; + errno = 0; + switch (type) + { + case TYPE_SCHAR: + { + int arg = a.arg[dp->arg_index].a.a_schar; + SNPRINTF_BUF (arg); + } + break; + case TYPE_UCHAR: + { + unsigned int arg = a.arg[dp->arg_index].a.a_uchar; + SNPRINTF_BUF (arg); + } + break; + case TYPE_SHORT: + { + int arg = a.arg[dp->arg_index].a.a_short; + SNPRINTF_BUF (arg); + } + break; + case TYPE_USHORT: + { + unsigned int arg = a.arg[dp->arg_index].a.a_ushort; + SNPRINTF_BUF (arg); + } + break; + case TYPE_INT: + { + int arg = a.arg[dp->arg_index].a.a_int; + SNPRINTF_BUF (arg); + } + break; + case TYPE_UINT: + { + unsigned int arg = a.arg[dp->arg_index].a.a_uint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_LONGINT: + { + long int arg = a.arg[dp->arg_index].a.a_longint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_ULONGINT: + { + unsigned long int arg = a.arg[dp->arg_index].a.a_ulongint; + SNPRINTF_BUF (arg); + } + break; #if HAVE_LONG_LONG_INT - case TYPE_LONGLONGINT: - { - long long int arg = a.arg[dp->arg_index].a.a_longlongint; - SNPRINTF_BUF (arg); - } - break; - case TYPE_ULONGLONGINT: - { - unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; - SNPRINTF_BUF (arg); - } - break; + case TYPE_LONGLONGINT: + { + long long int arg = a.arg[dp->arg_index].a.a_longlongint; + SNPRINTF_BUF (arg); + } + break; + case TYPE_ULONGLONGINT: + { + unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; + SNPRINTF_BUF (arg); + } + break; #endif - case TYPE_DOUBLE: - { - double arg = a.arg[dp->arg_index].a.a_double; - SNPRINTF_BUF (arg); - } - break; - case TYPE_LONGDOUBLE: - { - long double arg = a.arg[dp->arg_index].a.a_longdouble; - SNPRINTF_BUF (arg); - } - break; - case TYPE_CHAR: - { - int arg = a.arg[dp->arg_index].a.a_char; - SNPRINTF_BUF (arg); - } - break; + case TYPE_DOUBLE: + { + double arg = a.arg[dp->arg_index].a.a_double; + SNPRINTF_BUF (arg); + } + break; + case TYPE_LONGDOUBLE: + { + long double arg = a.arg[dp->arg_index].a.a_longdouble; + SNPRINTF_BUF (arg); + } + break; + case TYPE_CHAR: + { + int arg = a.arg[dp->arg_index].a.a_char; + SNPRINTF_BUF (arg); + } + break; #if HAVE_WINT_T - case TYPE_WIDE_CHAR: - { - wint_t arg = a.arg[dp->arg_index].a.a_wide_char; - SNPRINTF_BUF (arg); - } - break; + case TYPE_WIDE_CHAR: + { + wint_t arg = a.arg[dp->arg_index].a.a_wide_char; + SNPRINTF_BUF (arg); + } + break; #endif - case TYPE_STRING: - { - const char *arg = a.arg[dp->arg_index].a.a_string; - SNPRINTF_BUF (arg); - } - break; + case TYPE_STRING: + { + const char *arg = a.arg[dp->arg_index].a.a_string; + SNPRINTF_BUF (arg); + } + break; #if HAVE_WCHAR_T - case TYPE_WIDE_STRING: - { - const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; - SNPRINTF_BUF (arg); - } - break; + case TYPE_WIDE_STRING: + { + const wchar_t *arg = a.arg[dp->arg_index].a.a_wide_string; + SNPRINTF_BUF (arg); + } + break; #endif - case TYPE_POINTER: - { - void *arg = a.arg[dp->arg_index].a.a_pointer; - SNPRINTF_BUF (arg); - } - break; - default: - abort (); - } + case TYPE_POINTER: + { + void *arg = a.arg[dp->arg_index].a.a_pointer; + SNPRINTF_BUF (arg); + } + break; + default: + abort (); + } #if USE_SNPRINTF - /* Portability: Not all implementations of snprintf() - are ISO C 99 compliant. Determine the number of - bytes that snprintf() has produced or would have - produced. */ - if (count >= 0) - { - /* Verify that snprintf() has NUL-terminated its - result. */ - if (count < maxlen - && ((TCHAR_T *) (result + length)) [count] != '\0') - abort (); - /* Portability hack. */ - if (retcount > count) - count = retcount; - } - else - { - /* snprintf() doesn't understand the '%n' - directive. */ - if (fbp[1] != '\0') - { - /* Don't use the '%n' directive; instead, look - at the snprintf() return value. */ - fbp[1] = '\0'; - continue; - } - else - { - /* Look at the snprintf() return value. */ - if (retcount < 0) - { - /* HP-UX 10.20 snprintf() is doubly deficient: - It doesn't understand the '%n' directive, - *and* it returns -1 (rather than the length - that would have been required) when the - buffer is too small. */ - size_t bigger_need = - xsum (xtimes (allocated, 2), 12); - ENSURE_ALLOCATION (bigger_need); - continue; - } - else - count = retcount; - } - } + /* Portability: Not all implementations of snprintf() + are ISO C 99 compliant. Determine the number of + bytes that snprintf() has produced or would have + produced. */ + if (count >= 0) + { + /* Verify that snprintf() has NUL-terminated its + result. */ + if (count < maxlen + && ((TCHAR_T *) (result + length)) [count] != '\0') + abort (); + /* Portability hack. */ + if (retcount > count) + count = retcount; + } + else + { + /* snprintf() doesn't understand the '%n' + directive. */ + if (fbp[1] != '\0') + { + /* Don't use the '%n' directive; instead, look + at the snprintf() return value. */ + fbp[1] = '\0'; + continue; + } + else + { + /* Look at the snprintf() return value. */ + if (retcount < 0) + { +# if !HAVE_SNPRINTF_RETVAL_C99 + /* HP-UX 10.20 snprintf() is doubly deficient: + It doesn't understand the '%n' directive, + *and* it returns -1 (rather than the length + that would have been required) when the + buffer is too small. + But a failure at this point can also come + from other reasons than a too small buffer, + such as an invalid wide string argument to + the %ls directive, or possibly an invalid + floating-point argument. */ + size_t tmp_length = + MAX_ROOM_NEEDED (&a, dp->arg_index, + dp->conversion, type, flags, + width, has_precision, + precision, pad_ourselves); + + if (maxlen < tmp_length) + { + /* Make more room. But try to do through + this reallocation only once. */ + size_t bigger_need = + xsum (length, + xsum (tmp_length, + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR); + /* And always grow proportionally. + (There may be several arguments, each + needing a little more room than the + previous one.) */ + size_t bigger_need2 = + xsum (xtimes (allocated, 2), 12); + if (bigger_need < bigger_need2) + bigger_need = bigger_need2; + ENSURE_ALLOCATION (bigger_need); + continue; + } +# endif + } + else + count = retcount; + } + } #endif - /* Attempt to handle failure. */ - if (count < 0) - { - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = EINVAL; - return NULL; - } + /* Attempt to handle failure. */ + if (count < 0) + { + /* SNPRINTF or sprintf failed. Save and use the errno + that it has set, if any. */ + int saved_errno = errno; + + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = + (saved_errno != 0 + ? saved_errno + : (dp->conversion == 'c' || dp->conversion == 's' + ? EILSEQ + : EINVAL)); + return NULL; + } #if USE_SNPRINTF - /* Handle overflow of the allocated buffer. - If such an overflow occurs, a C99 compliant snprintf() - returns a count >= maxlen. However, a non-compliant - snprintf() function returns only count = maxlen - 1. To - cover both cases, test whether count >= maxlen - 1. */ - if ((unsigned int) count + 1 >= maxlen) - { - /* If maxlen already has attained its allowed maximum, - allocating more memory will not increase maxlen. - Instead of looping, bail out. */ - if (maxlen == INT_MAX / TCHARS_PER_DCHAR) - goto overflow; - else - { - /* Need at least (count + 1) * sizeof (TCHAR_T) - bytes. (The +1 is for the trailing NUL.) - But ask for (count + 2) * sizeof (TCHAR_T) - bytes, so that in the next round, we likely get - maxlen > (unsigned int) count + 1 - and so we don't get here again. - And allocate proportionally, to avoid looping - eternally if snprintf() reports a too small - count. */ - size_t n = - xmax (xsum (length, - ((unsigned int) count + 2 - + TCHARS_PER_DCHAR - 1) - / TCHARS_PER_DCHAR), - xtimes (allocated, 2)); - - ENSURE_ALLOCATION (n); - continue; - } - } + /* Handle overflow of the allocated buffer. + If such an overflow occurs, a C99 compliant snprintf() + returns a count >= maxlen. However, a non-compliant + snprintf() function returns only count = maxlen - 1. To + cover both cases, test whether count >= maxlen - 1. */ + if ((unsigned int) count + 1 >= maxlen) + { + /* If maxlen already has attained its allowed maximum, + allocating more memory will not increase maxlen. + Instead of looping, bail out. */ + if (maxlen == INT_MAX / TCHARS_PER_DCHAR) + goto overflow; + else + { + /* Need at least (count + 1) * sizeof (TCHAR_T) + bytes. (The +1 is for the trailing NUL.) + But ask for (count + 2) * sizeof (TCHAR_T) + bytes, so that in the next round, we likely get + maxlen > (unsigned int) count + 1 + and so we don't get here again. + And allocate proportionally, to avoid looping + eternally if snprintf() reports a too small + count. */ + size_t n = + xmax (xsum (length, + ((unsigned int) count + 2 + + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR), + xtimes (allocated, 2)); + + ENSURE_ALLOCATION (n); + continue; + } + } #endif #if NEED_PRINTF_UNBOUNDED_PRECISION - if (prec_ourselves) - { - /* Handle the precision. */ - TCHAR_T *prec_ptr = + if (prec_ourselves) + { + /* Handle the precision. */ + TCHAR_T *prec_ptr = # if USE_SNPRINTF - (TCHAR_T *) (result + length); + (TCHAR_T *) (result + length); # else - tmp; + tmp; # endif - size_t prefix_count; - size_t move; - - prefix_count = 0; - /* Put the additional zeroes after the sign. */ - if (count >= 1 - && (*prec_ptr == '-' || *prec_ptr == '+' - || *prec_ptr == ' ')) - prefix_count = 1; - /* Put the additional zeroes after the 0x prefix if - (flags & FLAG_ALT) || (dp->conversion == 'p'). */ - else if (count >= 2 - && prec_ptr[0] == '0' - && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X')) - prefix_count = 2; - - move = count - prefix_count; - if (precision > move) - { - /* Insert zeroes. */ - size_t insert = precision - move; - TCHAR_T *prec_end; + size_t prefix_count; + size_t move; + + prefix_count = 0; + /* Put the additional zeroes after the sign. */ + if (count >= 1 + && (*prec_ptr == '-' || *prec_ptr == '+' + || *prec_ptr == ' ')) + prefix_count = 1; + /* Put the additional zeroes after the 0x prefix if + (flags & FLAG_ALT) || (dp->conversion == 'p'). */ + else if (count >= 2 + && prec_ptr[0] == '0' + && (prec_ptr[1] == 'x' || prec_ptr[1] == 'X')) + prefix_count = 2; + + move = count - prefix_count; + if (precision > move) + { + /* Insert zeroes. */ + size_t insert = precision - move; + TCHAR_T *prec_end; # if USE_SNPRINTF - size_t n = - xsum (length, - (count + insert + TCHARS_PER_DCHAR - 1) - / TCHARS_PER_DCHAR); - length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; - ENSURE_ALLOCATION (n); - length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; - prec_ptr = (TCHAR_T *) (result + length); + size_t n = + xsum (length, + (count + insert + TCHARS_PER_DCHAR - 1) + / TCHARS_PER_DCHAR); + length += (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; + ENSURE_ALLOCATION (n); + length -= (count + TCHARS_PER_DCHAR - 1) / TCHARS_PER_DCHAR; + prec_ptr = (TCHAR_T *) (result + length); # endif - prec_end = prec_ptr + count; - prec_ptr += prefix_count; + prec_end = prec_ptr + count; + prec_ptr += prefix_count; - while (prec_end > prec_ptr) - { - prec_end--; - prec_end[insert] = prec_end[0]; - } + while (prec_end > prec_ptr) + { + prec_end--; + prec_end[insert] = prec_end[0]; + } - prec_end += insert; - do - *--prec_end = '0'; - while (prec_end > prec_ptr); + prec_end += insert; + do + *--prec_end = '0'; + while (prec_end > prec_ptr); - count += insert; - } - } + count += insert; + } + } #endif #if !USE_SNPRINTF - if (count >= tmp_length) - /* tmp_length was incorrectly calculated - fix the - code above! */ - abort (); + if (count >= tmp_length) + /* tmp_length was incorrectly calculated - fix the + code above! */ + abort (); #endif #if !DCHAR_IS_TCHAR - /* Convert from TCHAR_T[] to DCHAR_T[]. */ - if (dp->conversion == 'c' || dp->conversion == 's') - { - /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING - TYPE_WIDE_STRING. - The result string is not certainly ASCII. */ - const TCHAR_T *tmpsrc; - DCHAR_T *tmpdst; - size_t tmpdst_len; - /* This code assumes that TCHAR_T is 'char'. */ - typedef int TCHAR_T_verify - [2 * (sizeof (TCHAR_T) == 1) - 1]; + /* Convert from TCHAR_T[] to DCHAR_T[]. */ + if (dp->conversion == 'c' || dp->conversion == 's') + { + /* type = TYPE_CHAR or TYPE_WIDE_CHAR or TYPE_STRING + TYPE_WIDE_STRING. + The result string is not certainly ASCII. */ + const TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t tmpdst_len; + /* This code assumes that TCHAR_T is 'char'. */ + typedef int TCHAR_T_verify + [2 * (sizeof (TCHAR_T) == 1) - 1]; # if USE_SNPRINTF - tmpsrc = (TCHAR_T *) (result + length); + tmpsrc = (TCHAR_T *) (result + length); # else - tmpsrc = tmp; + tmpsrc = tmp; # endif - tmpdst = - DCHAR_CONV_FROM_ENCODING (locale_charset (), - iconveh_question_mark, - tmpsrc, count, - NULL, - NULL, &tmpdst_len); - if (tmpdst == NULL) - { - int saved_errno = errno; - if (!(result == resultbuf || result == NULL)) - free (result); - if (buf_malloced != NULL) - free (buf_malloced); - CLEANUP (); - errno = saved_errno; - return NULL; - } - ENSURE_ALLOCATION (xsum (length, tmpdst_len)); - DCHAR_CPY (result + length, tmpdst, tmpdst_len); - free (tmpdst); - count = tmpdst_len; - } - else - { - /* The result string is ASCII. - Simple 1:1 conversion. */ + tmpdst = + DCHAR_CONV_FROM_ENCODING (locale_charset (), + iconveh_question_mark, + tmpsrc, count, + NULL, + NULL, &tmpdst_len); + if (tmpdst == NULL) + { + int saved_errno = errno; + if (!(result == resultbuf || result == NULL)) + free (result); + if (buf_malloced != NULL) + free (buf_malloced); + CLEANUP (); + errno = saved_errno; + return NULL; + } + ENSURE_ALLOCATION (xsum (length, tmpdst_len)); + DCHAR_CPY (result + length, tmpdst, tmpdst_len); + free (tmpdst); + count = tmpdst_len; + } + else + { + /* The result string is ASCII. + Simple 1:1 conversion. */ # if USE_SNPRINTF - /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a - no-op conversion, in-place on the array starting - at (result + length). */ - if (sizeof (DCHAR_T) != sizeof (TCHAR_T)) + /* If sizeof (DCHAR_T) == sizeof (TCHAR_T), it's a + no-op conversion, in-place on the array starting + at (result + length). */ + if (sizeof (DCHAR_T) != sizeof (TCHAR_T)) # endif - { - const TCHAR_T *tmpsrc; - DCHAR_T *tmpdst; - size_t n; + { + const TCHAR_T *tmpsrc; + DCHAR_T *tmpdst; + size_t n; # if USE_SNPRINTF - if (result == resultbuf) - { - tmpsrc = (TCHAR_T *) (result + length); - /* ENSURE_ALLOCATION will not move tmpsrc - (because it's part of resultbuf). */ - ENSURE_ALLOCATION (xsum (length, count)); - } - else - { - /* ENSURE_ALLOCATION will move the array - (because it uses realloc(). */ - ENSURE_ALLOCATION (xsum (length, count)); - tmpsrc = (TCHAR_T *) (result + length); - } + if (result == resultbuf) + { + tmpsrc = (TCHAR_T *) (result + length); + /* ENSURE_ALLOCATION will not move tmpsrc + (because it's part of resultbuf). */ + ENSURE_ALLOCATION (xsum (length, count)); + } + else + { + /* ENSURE_ALLOCATION will move the array + (because it uses realloc(). */ + ENSURE_ALLOCATION (xsum (length, count)); + tmpsrc = (TCHAR_T *) (result + length); + } # else - tmpsrc = tmp; - ENSURE_ALLOCATION (xsum (length, count)); + tmpsrc = tmp; + ENSURE_ALLOCATION (xsum (length, count)); # endif - tmpdst = result + length; - /* Copy backwards, because of overlapping. */ - tmpsrc += count; - tmpdst += count; - for (n = count; n > 0; n--) - *--tmpdst = (unsigned char) *--tmpsrc; - } - } + tmpdst = result + length; + /* Copy backwards, because of overlapping. */ + tmpsrc += count; + tmpdst += count; + for (n = count; n > 0; n--) + *--tmpdst = (unsigned char) *--tmpsrc; + } + } #endif #if DCHAR_IS_TCHAR && !USE_SNPRINTF - /* Make room for the result. */ - if (count > allocated - length) - { - /* Need at least count elements. But allocate - proportionally. */ - size_t n = - xmax (xsum (length, count), xtimes (allocated, 2)); - - ENSURE_ALLOCATION (n); - } + /* Make room for the result. */ + if (count > allocated - length) + { + /* Need at least count elements. But allocate + proportionally. */ + size_t n = + xmax (xsum (length, count), xtimes (allocated, 2)); + + ENSURE_ALLOCATION (n); + } #endif - /* Here count <= allocated - length. */ + /* Here count <= allocated - length. */ - /* Perform padding. */ + /* Perform padding. */ #if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO || NEED_PRINTF_FLAG_LEFTADJUST || NEED_PRINTF_FLAG_ZERO || NEED_PRINTF_UNBOUNDED_PRECISION - if (pad_ourselves && has_width) - { - size_t w; + if (pad_ourselves && has_width) + { + size_t w; # if ENABLE_UNISTDIO - /* Outside POSIX, it's preferrable to compare the width - against the number of _characters_ of the converted - value. */ - w = DCHAR_MBSNLEN (result + length, count); + /* Outside POSIX, it's preferrable to compare the width + against the number of _characters_ of the converted + value. */ + w = DCHAR_MBSNLEN (result + length, count); # else - /* The width is compared against the number of _bytes_ - of the converted value, says POSIX. */ - w = count; + /* The width is compared against the number of _bytes_ + of the converted value, says POSIX. */ + w = count; # endif - if (w < width) - { - size_t pad = width - w; - - /* Make room for the result. */ - if (xsum (count, pad) > allocated - length) - { - /* Need at least count + pad elements. But - allocate proportionally. */ - size_t n = - xmax (xsum3 (length, count, pad), - xtimes (allocated, 2)); + if (w < width) + { + size_t pad = width - w; + + /* Make room for the result. */ + if (xsum (count, pad) > allocated - length) + { + /* Need at least count + pad elements. But + allocate proportionally. */ + size_t n = + xmax (xsum3 (length, count, pad), + xtimes (allocated, 2)); # if USE_SNPRINTF - length += count; - ENSURE_ALLOCATION (n); - length -= count; + length += count; + ENSURE_ALLOCATION (n); + length -= count; # else - ENSURE_ALLOCATION (n); + ENSURE_ALLOCATION (n); # endif - } - /* Here count + pad <= allocated - length. */ + } + /* Here count + pad <= allocated - length. */ - { + { # if !DCHAR_IS_TCHAR || USE_SNPRINTF - DCHAR_T * const rp = result + length; + DCHAR_T * const rp = result + length; # else - DCHAR_T * const rp = tmp; + DCHAR_T * const rp = tmp; # endif - DCHAR_T *p = rp + count; - DCHAR_T *end = p + pad; - DCHAR_T *pad_ptr; + DCHAR_T *p = rp + count; + DCHAR_T *end = p + pad; + DCHAR_T *pad_ptr; # if !DCHAR_IS_TCHAR || ENABLE_UNISTDIO - if (dp->conversion == 'c' - || dp->conversion == 's') - /* No zero-padding for string directives. */ - pad_ptr = NULL; - else + if (dp->conversion == 'c' + || dp->conversion == 's') + /* No zero-padding for string directives. */ + pad_ptr = NULL; + else # endif - { - pad_ptr = (*rp == '-' ? rp + 1 : rp); - /* No zero-padding of "inf" and "nan". */ - if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z') - || (*pad_ptr >= 'a' && *pad_ptr <= 'z')) - pad_ptr = NULL; - } - /* The generated string now extends from rp to p, - with the zero padding insertion point being at - pad_ptr. */ - - count = count + pad; /* = end - rp */ - - if (flags & FLAG_LEFT) - { - /* Pad with spaces on the right. */ - for (; pad > 0; pad--) - *p++ = ' '; - } - else if ((flags & FLAG_ZERO) && pad_ptr != NULL) - { - /* Pad with zeroes. */ - DCHAR_T *q = end; - - while (p > pad_ptr) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = '0'; - } - else - { - /* Pad with spaces on the left. */ - DCHAR_T *q = end; - - while (p > rp) - *--q = *--p; - for (; pad > 0; pad--) - *p++ = ' '; - } - } - } - } + { + pad_ptr = (*rp == '-' ? rp + 1 : rp); + /* No zero-padding of "inf" and "nan". */ + if ((*pad_ptr >= 'A' && *pad_ptr <= 'Z') + || (*pad_ptr >= 'a' && *pad_ptr <= 'z')) + pad_ptr = NULL; + } + /* The generated string now extends from rp to p, + with the zero padding insertion point being at + pad_ptr. */ + + count = count + pad; /* = end - rp */ + + if (flags & FLAG_LEFT) + { + /* Pad with spaces on the right. */ + for (; pad > 0; pad--) + *p++ = ' '; + } + else if ((flags & FLAG_ZERO) && pad_ptr != NULL) + { + /* Pad with zeroes. */ + DCHAR_T *q = end; + + while (p > pad_ptr) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = '0'; + } + else + { + /* Pad with spaces on the left. */ + DCHAR_T *q = end; + + while (p > rp) + *--q = *--p; + for (; pad > 0; pad--) + *p++ = ' '; + } + } + } + } #endif - /* Here still count <= allocated - length. */ + /* Here still count <= allocated - length. */ #if !DCHAR_IS_TCHAR || USE_SNPRINTF - /* The snprintf() result did fit. */ + /* The snprintf() result did fit. */ #else - /* Append the sprintf() result. */ - memcpy (result + length, tmp, count * sizeof (DCHAR_T)); + /* Append the sprintf() result. */ + memcpy (result + length, tmp, count * sizeof (DCHAR_T)); #endif #if !USE_SNPRINTF - if (tmp != tmpbuf) - free (tmp); + if (tmp != tmpbuf) + free (tmp); #endif #if NEED_PRINTF_DIRECTIVE_F - if (dp->conversion == 'F') - { - /* Convert the %f result to upper case for %F. */ - DCHAR_T *rp = result + length; - size_t rc; - for (rc = count; rc > 0; rc--, rp++) - if (*rp >= 'a' && *rp <= 'z') - *rp = *rp - 'a' + 'A'; - } + if (dp->conversion == 'F') + { + /* Convert the %f result to upper case for %F. */ + DCHAR_T *rp = result + length; + size_t rc; + for (rc = count; rc > 0; rc--, rp++) + if (*rp >= 'a' && *rp <= 'z') + *rp = *rp - 'a' + 'A'; + } #endif - length += count; - break; - } - } - } + length += count; + break; + } + } + } } /* Add the final NUL. */ @@ -5432,12 +5508,12 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, if (result != resultbuf && length + 1 < allocated) { - /* Shrink the allocated memory if possible. */ - DCHAR_T *memory; + /* Shrink the allocated memory if possible. */ + DCHAR_T *memory; - memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T)); - if (memory != NULL) - result = memory; + memory = (DCHAR_T *) realloc (result, (length + 1) * sizeof (DCHAR_T)); + if (memory != NULL) + result = memory; } if (buf_malloced != NULL) @@ -5473,6 +5549,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, } } +#undef MAX_ROOM_NEEDED #undef TCHARS_PER_DCHAR #undef SNPRINTF #undef USE_SNPRINTF diff --git a/lib/verify.h b/lib/verify.h index e82fa02d..7773c794 100644 --- a/lib/verify.h +++ b/lib/verify.h @@ -1,6 +1,6 @@ /* Compile-time assert-like macros. - Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -110,8 +110,8 @@ #if 4 <= __GNUC__ # define verify(R) \ - extern int (* verify_function__ (void)) \ - [__builtin_constant_p (R) && (R) ? 1 : -1] + extern int (* verify_function__ (void)) \ + [__builtin_constant_p (R) && (R) ? 1 : -1] #endif * In C++, any struct definition inside sizeof is invalid. diff --git a/lib/wchar.in.h b/lib/wchar.in.h index 1f1f1309..3e3a0c39 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -1,6 +1,6 @@ /* A substitute for ISO C99 , for platforms that have issues. - Copyright (C) 2007-2009 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -30,9 +30,9 @@ @PRAGMA_SYSTEM_HEADER@ #endif -#if defined __need_mbstate_t || (defined __hpux && ((defined _INTTYPES_INCLUDED && !defined strtoimax) || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) || defined _GL_ALREADY_INCLUDING_WCHAR_H +#if defined __need_mbstate_t || defined __need_wint_t || (defined __hpux && ((defined _INTTYPES_INCLUDED && !defined strtoimax) || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) || defined _GL_ALREADY_INCLUDING_WCHAR_H /* Special invocation convention: - - Inside uClibc header files. + - Inside glibc and uClibc header files. - On HP-UX 11.00 we have a sequence of nested includes -> -> , and the latter includes , once indirectly -> -> -> @@ -55,10 +55,13 @@ /* Tru64 with Desktop Toolkit C has a bug: must be included before . BSD/OS 4.0.1 has a bug: , and must be - included before . */ -#include -#include -#include + included before . + But avoid namespace pollution on glibc systems. */ +#ifndef __GLIBC__ +# include +# include +# include +#endif /* Include the original if it exists. Some builds of uClibc lack it. */ @@ -72,19 +75,23 @@ #ifndef _GL_WCHAR_H #define _GL_WCHAR_H -/* The definition of GL_LINK_WARNING is copied here. */ +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ -#ifdef __cplusplus -extern "C" { -#endif +/* The definition of _GL_ARG_NONNULL is copied here. */ +/* The definition of _GL_WARN_ON_USE is copied here. */ -/* Define wint_t. (Also done in wctype.in.h.) */ + +/* Define wint_t and WEOF. (Also done in wctype.in.h.) */ #if !@HAVE_WINT_T@ && !defined wint_t # define wint_t int # ifndef WEOF # define WEOF -1 # endif +#else +# ifndef WEOF +# define WEOF ((wint_t) -1) +# endif #endif @@ -102,209 +109,320 @@ typedef int rpl_mbstate_t; /* Convert a single-byte character to a wide character. */ #if @GNULIB_BTOWC@ # if @REPLACE_BTOWC@ -# undef btowc -# define btowc rpl_btowc -# endif -# if !@HAVE_BTOWC@ || @REPLACE_BTOWC@ -extern wint_t btowc (int c); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef btowc +# define btowc rpl_btowc +# endif +_GL_FUNCDECL_RPL (btowc, wint_t, (int c)); +_GL_CXXALIAS_RPL (btowc, wint_t, (int c)); +# else +# if !@HAVE_BTOWC@ +_GL_FUNCDECL_SYS (btowc, wint_t, (int c)); +# endif +_GL_CXXALIAS_SYS (btowc, wint_t, (int c)); # endif +_GL_CXXALIASWARN (btowc); #elif defined GNULIB_POSIXCHECK # undef btowc -# define btowc(c) \ - (GL_LINK_WARNING ("btowc is unportable - " \ - "use gnulib module btowc for portability"), \ - btowc (c)) +# if HAVE_RAW_DECL_BTOWC +_GL_WARN_ON_USE (btowc, "btowc is unportable - " + "use gnulib module btowc for portability"); +# endif #endif /* Convert a wide character to a single-byte character. */ #if @GNULIB_WCTOB@ # if @REPLACE_WCTOB@ -# undef wctob -# define wctob rpl_wctob -# endif -# if (!defined wctob && !@HAVE_DECL_WCTOB@) || @REPLACE_WCTOB@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wctob +# define wctob rpl_wctob +# endif +_GL_FUNCDECL_RPL (wctob, int, (wint_t wc)); +_GL_CXXALIAS_RPL (wctob, int, (wint_t wc)); +# else +# if !defined wctob && !@HAVE_DECL_WCTOB@ /* wctob is provided by gnulib, or wctob exists but is not declared. */ -extern int wctob (wint_t wc); +_GL_FUNCDECL_SYS (wctob, int, (wint_t wc)); +# endif +_GL_CXXALIAS_SYS (wctob, int, (wint_t wc)); # endif +_GL_CXXALIASWARN (wctob); #elif defined GNULIB_POSIXCHECK # undef wctob -# define wctob(w) \ - (GL_LINK_WARNING ("wctob is unportable - " \ - "use gnulib module wctob for portability"), \ - wctob (w)) +# if HAVE_RAW_DECL_WCTOB +_GL_WARN_ON_USE (wctob, "wctob is unportable - " + "use gnulib module wctob for portability"); +# endif #endif /* Test whether *PS is in the initial state. */ #if @GNULIB_MBSINIT@ # if @REPLACE_MBSINIT@ -# undef mbsinit -# define mbsinit rpl_mbsinit -# endif -# if !@HAVE_MBSINIT@ || @REPLACE_MBSINIT@ -extern int mbsinit (const mbstate_t *ps); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mbsinit +# define mbsinit rpl_mbsinit +# endif +_GL_FUNCDECL_RPL (mbsinit, int, (const mbstate_t *ps)); +_GL_CXXALIAS_RPL (mbsinit, int, (const mbstate_t *ps)); +# else +# if !@HAVE_MBSINIT@ +_GL_FUNCDECL_SYS (mbsinit, int, (const mbstate_t *ps)); +# endif +_GL_CXXALIAS_SYS (mbsinit, int, (const mbstate_t *ps)); # endif +_GL_CXXALIASWARN (mbsinit); #elif defined GNULIB_POSIXCHECK # undef mbsinit -# define mbsinit(p) \ - (GL_LINK_WARNING ("mbsinit is unportable - " \ - "use gnulib module mbsinit for portability"), \ - mbsinit (p)) +# if HAVE_RAW_DECL_MBSINIT +_GL_WARN_ON_USE (mbsinit, "mbsinit is unportable - " + "use gnulib module mbsinit for portability"); +# endif #endif /* Convert a multibyte character to a wide character. */ #if @GNULIB_MBRTOWC@ # if @REPLACE_MBRTOWC@ -# undef mbrtowc -# define mbrtowc rpl_mbrtowc -# endif -# if !@HAVE_MBRTOWC@ || @REPLACE_MBRTOWC@ -extern size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mbrtowc +# define mbrtowc rpl_mbrtowc +# endif +_GL_FUNCDECL_RPL (mbrtowc, size_t, + (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); +_GL_CXXALIAS_RPL (mbrtowc, size_t, + (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); +# else +# if !@HAVE_MBRTOWC@ +_GL_FUNCDECL_SYS (mbrtowc, size_t, + (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); +# endif +_GL_CXXALIAS_SYS (mbrtowc, size_t, + (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)); # endif +_GL_CXXALIASWARN (mbrtowc); #elif defined GNULIB_POSIXCHECK # undef mbrtowc -# define mbrtowc(w,s,n,p) \ - (GL_LINK_WARNING ("mbrtowc is unportable - " \ - "use gnulib module mbrtowc for portability"), \ - mbrtowc (w, s, n, p)) +# if HAVE_RAW_DECL_MBRTOWC +_GL_WARN_ON_USE (mbrtowc, "mbrtowc is unportable - " + "use gnulib module mbrtowc for portability"); +# endif #endif /* Recognize a multibyte character. */ #if @GNULIB_MBRLEN@ # if @REPLACE_MBRLEN@ -# undef mbrlen -# define mbrlen rpl_mbrlen -# endif -# if !@HAVE_MBRLEN@ || @REPLACE_MBRLEN@ -extern size_t mbrlen (const char *s, size_t n, mbstate_t *ps); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mbrlen +# define mbrlen rpl_mbrlen +# endif +_GL_FUNCDECL_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); +_GL_CXXALIAS_RPL (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); +# else +# if !@HAVE_MBRLEN@ +_GL_FUNCDECL_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); +# endif +_GL_CXXALIAS_SYS (mbrlen, size_t, (const char *s, size_t n, mbstate_t *ps)); # endif +_GL_CXXALIASWARN (mbrlen); #elif defined GNULIB_POSIXCHECK # undef mbrlen -# define mbrlen(s,n,p) \ - (GL_LINK_WARNING ("mbrlen is unportable - " \ - "use gnulib module mbrlen for portability"), \ - mbrlen (s, n, p)) +# if HAVE_RAW_DECL_MBRLEN +_GL_WARN_ON_USE (mbrlen, "mbrlen is unportable - " + "use gnulib module mbrlen for portability"); +# endif #endif /* Convert a string to a wide string. */ #if @GNULIB_MBSRTOWCS@ # if @REPLACE_MBSRTOWCS@ -# undef mbsrtowcs -# define mbsrtowcs rpl_mbsrtowcs -# endif -# if !@HAVE_MBSRTOWCS@ || @REPLACE_MBSRTOWCS@ -extern size_t mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mbsrtowcs +# define mbsrtowcs rpl_mbsrtowcs +# endif +_GL_FUNCDECL_RPL (mbsrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (mbsrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t len, + mbstate_t *ps)); +# else +# if !@HAVE_MBSRTOWCS@ +_GL_FUNCDECL_SYS (mbsrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (mbsrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t len, + mbstate_t *ps)); # endif +_GL_CXXALIASWARN (mbsrtowcs); #elif defined GNULIB_POSIXCHECK # undef mbsrtowcs -# define mbsrtowcs(d,s,l,p) \ - (GL_LINK_WARNING ("mbsrtowcs is unportable - " \ - "use gnulib module mbsrtowcs for portability"), \ - mbsrtowcs (d, s, l, p)) +# if HAVE_RAW_DECL_MBSRTOWCS +_GL_WARN_ON_USE (mbsrtowcs, "mbsrtowcs is unportable - " + "use gnulib module mbsrtowcs for portability"); +# endif #endif /* Convert a string to a wide string. */ #if @GNULIB_MBSNRTOWCS@ # if @REPLACE_MBSNRTOWCS@ -# undef mbsnrtowcs -# define mbsnrtowcs rpl_mbsnrtowcs -# endif -# if !@HAVE_MBSNRTOWCS@ || @REPLACE_MBSNRTOWCS@ -extern size_t mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef mbsnrtowcs +# define mbsnrtowcs rpl_mbsnrtowcs +# endif +_GL_FUNCDECL_RPL (mbsnrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t srclen, size_t len, + mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (mbsnrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t srclen, size_t len, + mbstate_t *ps)); +# else +# if !@HAVE_MBSNRTOWCS@ +_GL_FUNCDECL_SYS (mbsnrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t srclen, size_t len, + mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (mbsnrtowcs, size_t, + (wchar_t *dest, const char **srcp, size_t srclen, size_t len, + mbstate_t *ps)); # endif +_GL_CXXALIASWARN (mbsnrtowcs); #elif defined GNULIB_POSIXCHECK # undef mbsnrtowcs -# define mbsnrtowcs(d,s,n,l,p) \ - (GL_LINK_WARNING ("mbsnrtowcs is unportable - " \ - "use gnulib module mbsnrtowcs for portability"), \ - mbsnrtowcs (d, s, n, l, p)) +# if HAVE_RAW_DECL_MBSNRTOWCS +_GL_WARN_ON_USE (mbsnrtowcs, "mbsnrtowcs is unportable - " + "use gnulib module mbsnrtowcs for portability"); +# endif #endif /* Convert a wide character to a multibyte character. */ #if @GNULIB_WCRTOMB@ # if @REPLACE_WCRTOMB@ -# undef wcrtomb -# define wcrtomb rpl_wcrtomb -# endif -# if !@HAVE_WCRTOMB@ || @REPLACE_WCRTOMB@ -extern size_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcrtomb +# define wcrtomb rpl_wcrtomb +# endif +_GL_FUNCDECL_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); +_GL_CXXALIAS_RPL (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); +# else +# if !@HAVE_WCRTOMB@ +_GL_FUNCDECL_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); +# endif +_GL_CXXALIAS_SYS (wcrtomb, size_t, (char *s, wchar_t wc, mbstate_t *ps)); # endif +_GL_CXXALIASWARN (wcrtomb); #elif defined GNULIB_POSIXCHECK # undef wcrtomb -# define wcrtomb(s,w,p) \ - (GL_LINK_WARNING ("wcrtomb is unportable - " \ - "use gnulib module wcrtomb for portability"), \ - wcrtomb (s, w, p)) +# if HAVE_RAW_DECL_WCRTOMB +_GL_WARN_ON_USE (wcrtomb, "wcrtomb is unportable - " + "use gnulib module wcrtomb for portability"); +# endif #endif /* Convert a wide string to a string. */ #if @GNULIB_WCSRTOMBS@ # if @REPLACE_WCSRTOMBS@ -# undef wcsrtombs -# define wcsrtombs rpl_wcsrtombs -# endif -# if !@HAVE_WCSRTOMBS@ || @REPLACE_WCSRTOMBS@ -extern size_t wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcsrtombs +# define wcsrtombs rpl_wcsrtombs +# endif +_GL_FUNCDECL_RPL (wcsrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (wcsrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t len, + mbstate_t *ps)); +# else +# if !@HAVE_WCSRTOMBS@ +_GL_FUNCDECL_SYS (wcsrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (wcsrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t len, + mbstate_t *ps)); # endif +_GL_CXXALIASWARN (wcsrtombs); #elif defined GNULIB_POSIXCHECK # undef wcsrtombs -# define wcsrtombs(d,s,l,p) \ - (GL_LINK_WARNING ("wcsrtombs is unportable - " \ - "use gnulib module wcsrtombs for portability"), \ - wcsrtombs (d, s, l, p)) +# if HAVE_RAW_DECL_WCSRTOMBS +_GL_WARN_ON_USE (wcsrtombs, "wcsrtombs is unportable - " + "use gnulib module wcsrtombs for portability"); +# endif #endif /* Convert a wide string to a string. */ #if @GNULIB_WCSNRTOMBS@ # if @REPLACE_WCSNRTOMBS@ -# undef wcsnrtombs -# define wcsnrtombs rpl_wcsnrtombs -# endif -# if !@HAVE_WCSNRTOMBS@ || @REPLACE_WCSNRTOMBS@ -extern size_t wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcsnrtombs +# define wcsnrtombs rpl_wcsnrtombs +# endif +_GL_FUNCDECL_RPL (wcsnrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t srclen, size_t len, + mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +_GL_CXXALIAS_RPL (wcsnrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t srclen, size_t len, + mbstate_t *ps)); +# else +# if !@HAVE_WCSNRTOMBS@ +_GL_FUNCDECL_SYS (wcsnrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t srclen, size_t len, + mbstate_t *ps) + _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (wcsnrtombs, size_t, + (char *dest, const wchar_t **srcp, size_t srclen, size_t len, + mbstate_t *ps)); # endif +_GL_CXXALIASWARN (wcsnrtombs); #elif defined GNULIB_POSIXCHECK # undef wcsnrtombs -# define wcsnrtombs(d,s,n,l,p) \ - (GL_LINK_WARNING ("wcsnrtombs is unportable - " \ - "use gnulib module wcsnrtombs for portability"), \ - wcsnrtombs (d, s, n, l, p)) +# if HAVE_RAW_DECL_WCSNRTOMBS +_GL_WARN_ON_USE (wcsnrtombs, "wcsnrtombs is unportable - " + "use gnulib module wcsnrtombs for portability"); +# endif #endif /* Return the number of screen columns needed for WC. */ #if @GNULIB_WCWIDTH@ # if @REPLACE_WCWIDTH@ -# undef wcwidth -# define wcwidth rpl_wcwidth -extern int wcwidth (wchar_t); +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcwidth +# define wcwidth rpl_wcwidth +# endif +_GL_FUNCDECL_RPL (wcwidth, int, (wchar_t)); +_GL_CXXALIAS_RPL (wcwidth, int, (wchar_t)); # else -# if !defined wcwidth && !@HAVE_DECL_WCWIDTH@ +# if !@HAVE_DECL_WCWIDTH@ /* wcwidth exists but is not declared. */ -extern int wcwidth (int /* actually wchar_t */); +_GL_FUNCDECL_SYS (wcwidth, int, (wchar_t)); # endif +_GL_CXXALIAS_SYS (wcwidth, int, (wchar_t)); # endif +_GL_CXXALIASWARN (wcwidth); #elif defined GNULIB_POSIXCHECK # undef wcwidth -# define wcwidth(w) \ - (GL_LINK_WARNING ("wcwidth is unportable - " \ - "use gnulib module wcwidth for portability"), \ - wcwidth (w)) +# if HAVE_RAW_DECL_WCWIDTH +_GL_WARN_ON_USE (wcwidth, "wcwidth is unportable - " + "use gnulib module wcwidth for portability"); +# endif #endif -#ifdef __cplusplus -} -#endif - #endif /* _GL_WCHAR_H */ #endif /* _GL_WCHAR_H */ #endif diff --git a/lib/wctype.in.h b/lib/wctype.in.h index a583a044..8cfdfb07 100644 --- a/lib/wctype.in.h +++ b/lib/wctype.in.h @@ -1,6 +1,6 @@ /* A substitute for ISO C99 , for platforms that lack it. - Copyright (C) 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2006-2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -54,17 +54,27 @@ #ifndef _GL_WCTYPE_H #define _GL_WCTYPE_H -/* Define wint_t. (Also done in wchar.in.h.) */ +/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + +/* The definition of _GL_WARN_ON_USE is copied here. */ + +/* Define wint_t and WEOF. (Also done in wchar.in.h.) */ #if !@HAVE_WINT_T@ && !defined wint_t # define wint_t int # ifndef WEOF # define WEOF -1 # endif +#else +# ifndef WEOF +# define WEOF ((wint_t) -1) +# endif #endif + /* FreeBSD 4.4 to 4.11 has but lacks the functions. Linux libc5 has and the functions but they are broken. - Assume all 12 functions are implemented the same way, or not at all. */ + Assume all 11 functions (all isw* except iswblank) are implemented the + same way, or not at all. */ #if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@ /* IRIX 5.3 has macros but no functions, its isw* macros refer to an @@ -72,21 +82,24 @@ refer to system functions like _iswctype that are not in the standard C library. Rather than try to get ancient buggy implementations like this to work, just disable them. */ -# undef iswalnum -# undef iswalpha -# undef iswblank -# undef iswcntrl -# undef iswdigit -# undef iswgraph -# undef iswlower -# undef iswprint -# undef iswpunct -# undef iswspace -# undef iswupper -# undef iswxdigit +# undef iswalnum +# undef iswalpha +# undef iswblank +# undef iswcntrl +# undef iswdigit +# undef iswgraph +# undef iswlower +# undef iswprint +# undef iswpunct +# undef iswspace +# undef iswupper +# undef iswxdigit +# undef towlower +# undef towupper /* Linux libc5 has and the functions but they are broken. */ -# if @REPLACE_ISWCNTRL@ +# if @REPLACE_ISWCNTRL@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) # define iswalnum rpl_iswalnum # define iswalpha rpl_iswalpha # define iswblank rpl_iswblank @@ -99,86 +112,266 @@ # define iswspace rpl_iswspace # define iswupper rpl_iswupper # define iswxdigit rpl_iswxdigit +# define towlower rpl_towlower +# define towupper rpl_towupper # endif +# endif static inline int -iswalnum (wint_t wc) +# if @REPLACE_ISWCNTRL@ +rpl_iswalnum +# else +iswalnum +# endif + (wint_t wc) { return ((wc >= '0' && wc <= '9') - || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')); + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')); } static inline int -iswalpha (wint_t wc) +# if @REPLACE_ISWCNTRL@ +rpl_iswalpha +# else +iswalpha +# endif + (wint_t wc) { return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'; } static inline int -iswblank (wint_t wc) +# if @REPLACE_ISWCNTRL@ +rpl_iswblank +# else +iswblank +# endif + (wint_t wc) { return wc == ' ' || wc == '\t'; } static inline int -iswcntrl (wint_t wc) +# if @REPLACE_ISWCNTRL@ +rpl_iswcntrl +# else +iswcntrl +# endif + (wint_t wc) { return (wc & ~0x1f) == 0 || wc == 0x7f; } static inline int -iswdigit (wint_t wc) +# if @REPLACE_ISWCNTRL@ +rpl_iswdigit +# else +iswdigit +# endif + (wint_t wc) { return wc >= '0' && wc <= '9'; } static inline int -iswgraph (wint_t wc) +# if @REPLACE_ISWCNTRL@ +rpl_iswgraph +# else +iswgraph +# endif + (wint_t wc) { return wc >= '!' && wc <= '~'; } static inline int -iswlower (wint_t wc) +# if @REPLACE_ISWCNTRL@ +rpl_iswlower +# else +iswlower +# endif + (wint_t wc) { return wc >= 'a' && wc <= 'z'; } static inline int -iswprint (wint_t wc) +# if @REPLACE_ISWCNTRL@ +rpl_iswprint +# else +iswprint +# endif + (wint_t wc) { return wc >= ' ' && wc <= '~'; } static inline int -iswpunct (wint_t wc) +# if @REPLACE_ISWCNTRL@ +rpl_iswpunct +# else +iswpunct +# endif + (wint_t wc) { return (wc >= '!' && wc <= '~' - && !((wc >= '0' && wc <= '9') - || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'))); + && !((wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'))); } static inline int -iswspace (wint_t wc) +# if @REPLACE_ISWCNTRL@ +rpl_iswspace +# else +iswspace +# endif + (wint_t wc) { return (wc == ' ' || wc == '\t' - || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r'); + || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r'); } static inline int -iswupper (wint_t wc) +# if @REPLACE_ISWCNTRL@ +rpl_iswupper +# else +iswupper +# endif + (wint_t wc) { return wc >= 'A' && wc <= 'Z'; } static inline int -iswxdigit (wint_t wc) +# if @REPLACE_ISWCNTRL@ +rpl_iswxdigit +# else +iswxdigit +# endif + (wint_t wc) { return ((wc >= '0' && wc <= '9') - || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F')); + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F')); } -# endif /* ! HAVE_ISWCNTRL */ +static inline wint_t +# if @REPLACE_ISWCNTRL@ +rpl_towlower +# else +towlower +# endif + (wint_t wc) +{ + return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc); +} + +static inline wint_t +# if @REPLACE_ISWCNTRL@ +rpl_towupper +# else +towupper +# endif + (wint_t wc) +{ + return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc); +} + +#elif ! @HAVE_ISWBLANK@ +/* Only the iswblank function is missing. */ + +static inline int +iswblank (wint_t wc) +{ + return wc == ' ' || wc == '\t'; +} + +#endif + +#if defined __MINGW32__ + +/* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t. + The functions towlower and towupper are implemented in the MSVCRT library + to take a wchar_t argument and return a wchar_t result. mingw declares + these functions to take a wint_t argument and return a wint_t result. + This means that: + 1. When the user passes an argument outside the range 0x0000..0xFFFF, the + function will look only at the lower 16 bits. This is allowed according + to POSIX. + 2. The return value is returned in the lower 16 bits of the result register. + The upper 16 bits are random: whatever happened to be in that part of the + result register. We need to fix this by adding a zero-extend from + wchar_t to wint_t after the call. */ + +static inline wint_t +rpl_towlower (wint_t wc) +{ + return (wint_t) (wchar_t) towlower (wc); +} +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define towlower rpl_towlower +# endif + +static inline wint_t +rpl_towupper (wint_t wc) +{ + return (wint_t) (wchar_t) towupper (wc); +} +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define towupper rpl_towupper +# endif + +#endif /* __MINGW32__ */ + +#if @REPLACE_ISWCNTRL@ +_GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswblank, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswlower, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswprint, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswspace, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswupper, int, (wint_t wc)); +_GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc)); +#else +_GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswblank, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswlower, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswprint, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswspace, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswupper, int, (wint_t wc)); +_GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc)); +#endif +_GL_CXXALIASWARN (iswalnum); +_GL_CXXALIASWARN (iswalpha); +_GL_CXXALIASWARN (iswblank); +_GL_CXXALIASWARN (iswcntrl); +_GL_CXXALIASWARN (iswdigit); +_GL_CXXALIASWARN (iswgraph); +_GL_CXXALIASWARN (iswlower); +_GL_CXXALIASWARN (iswprint); +_GL_CXXALIASWARN (iswpunct); +_GL_CXXALIASWARN (iswspace); +_GL_CXXALIASWARN (iswupper); +_GL_CXXALIASWARN (iswxdigit); + +#if @REPLACE_ISWCNTRL@ || defined __MINGW32__ +_GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc)); +_GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc)); +#else +_GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc)); +_GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc)); +#endif +_GL_CXXALIASWARN (towlower); +_GL_CXXALIASWARN (towupper); + #endif /* _GL_WCTYPE_H */ #endif /* _GL_WCTYPE_H */ diff --git a/lib/wcwidth.c b/lib/wcwidth.c index 8dea6118..e5c27f54 100644 --- a/lib/wcwidth.c +++ b/lib/wcwidth.c @@ -1,5 +1,5 @@ /* Determine the number of screen columns needed for a character. - Copyright (C) 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 2006-2007, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -26,17 +26,16 @@ #include "streq.h" #include "uniwidth.h" -#undef wcwidth - int -rpl_wcwidth (wchar_t wc) +wcwidth (wchar_t wc) +#undef wcwidth { /* In UTF-8 locales, use a Unicode aware width function. */ const char *encoding = locale_charset (); if (STREQ (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0 ,0)) { /* We assume that in a UTF-8 locale, a wide character is the same as a - Unicode character. */ + Unicode character. */ return uc_width (wc, encoding); } else diff --git a/lib/xsize.h b/lib/xsize.h index 0b30045e..33822809 100644 --- a/lib/xsize.h +++ b/lib/xsize.h @@ -1,6 +1,6 @@ /* xsize.h -- Checked size_t computations. - Copyright (C) 2003, 2008 Free Software Foundation, Inc. + Copyright (C) 2003, 2008, 2009, 2010 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by -- cgit v1.2.3