summaryrefslogtreecommitdiff
path: root/Build/source/texk/bibtex8/bibtex-2.c
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2013-03-19 08:15:26 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2013-03-19 08:15:26 +0000
commit151a7146c6cc3ef5413a600e6145037af4fa63f1 (patch)
tree5f981b664fb6b2f868dd632b1cd3947dcd55818c /Build/source/texk/bibtex8/bibtex-2.c
parent6da10d8e2ab5bd73ba2de9c53b957bb33366ee77 (diff)
bibtex8 and bibtexu: use identical C code
git-svn-id: svn://tug.org/texlive/trunk@29431 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/bibtex8/bibtex-2.c')
-rw-r--r--Build/source/texk/bibtex8/bibtex-2.c212
1 files changed, 196 insertions, 16 deletions
diff --git a/Build/source/texk/bibtex8/bibtex-2.c b/Build/source/texk/bibtex8/bibtex-2.c
index 546ae15c64a..5280e408d05 100644
--- a/Build/source/texk/bibtex8/bibtex-2.c
+++ b/Build/source/texk/bibtex8/bibtex-2.c
@@ -923,10 +923,29 @@ BEGIN
name_bf_xptr = name_tok[cur_token + 1];
while (name_bf_ptr < name_bf_xptr)
BEGIN
+#ifdef UTF_8
+/*
+For output the first character which is encodage UTF-8, we sould discuter different length of character. 23/sep/2009
+*/
+ if((lex_class[NAME_BUF[name_bf_ptr]] != WHITE_SPACE) && (NAME_BUF[name_bf_ptr] != LEFT_BRACE))
+ BEGIN
+ DO_UTF8(NAME_BUF[name_bf_ptr],
+ APPEND_EX_BUF_CHAR_AND_CHECK (NAME_BUF[name_bf_ptr]),
+ APPEND_EX_BUF_CHAR_AND_CHECK (NAME_BUF[name_bf_ptr]);
+ APPEND_EX_BUF_CHAR_AND_CHECK (NAME_BUF[name_bf_ptr+1]),
+ APPEND_EX_BUF_CHAR_AND_CHECK (NAME_BUF[name_bf_ptr]);
+ APPEND_EX_BUF_CHAR_AND_CHECK (NAME_BUF[name_bf_ptr+1]);
+ APPEND_EX_BUF_CHAR_AND_CHECK (NAME_BUF[name_bf_ptr+2]),
+ APPEND_EX_BUF_CHAR_AND_CHECK (NAME_BUF[name_bf_ptr]);
+ APPEND_EX_BUF_CHAR_AND_CHECK (NAME_BUF[name_bf_ptr+1]);
+ APPEND_EX_BUF_CHAR_AND_CHECK (NAME_BUF[name_bf_ptr+2]);
+ APPEND_EX_BUF_CHAR_AND_CHECK (NAME_BUF[name_bf_ptr+3]));
+#else
if (lex_class[NAME_BUF[name_bf_ptr]] == ALPHA)
BEGIN
APPEND_EX_BUF_CHAR_AND_CHECK (
NAME_BUF[name_bf_ptr]);
+#endif
goto Loop_Exit_Label;
END
else if ((NAME_BUF[name_bf_ptr] == LEFT_BRACE)
@@ -2907,15 +2926,49 @@ END
***************************************************************************/
Boolean_T less_than (CiteNumber_T arg1, CiteNumber_T arg2)
BEGIN
- Boolean_T less_than;
- Integer_T char_ptr;
StrEntLoc_T ptr1,
ptr2;
+#ifdef UTF_8
+/*
+We use ICU libs to processing UTF-8. First, we have to transform UTF-8 to
+Unicode/UChar with the fonction icu_UCHars. Then we use the UCollator
+in the ICU libs to conparer the Unicode. There is an option "location",
+we use "-o" to indicate the rule of conpare. 23/sep/2009
+*/
+ Integer_T lenk1, lenk2;
+ UChar uch1[BUF_SIZE+1], uch2[BUF_SIZE+1];
+ UBool u_less;
+ UCollator * ucol1;
+ int32_t ucap = BUF_SIZE+1;
+ int32_t uchlen1, uchlen2;
+ UErrorCode err1 = U_ZERO_ERROR;
+#else
+ Boolean_T less_than;
+ Integer_T char_ptr;
ASCIICode_T char1,
char2;
+#endif
ptr1 = (arg1 * num_ent_strs) + sort_key_num;
ptr2 = (arg2 * num_ent_strs) + sort_key_num;
+#ifdef UTF_8
+ lenk1 = strlen((char *)&ENTRY_STRS(ptr1, 0));
+ lenk2 = strlen((char *)&ENTRY_STRS(ptr2, 0));
+
+ uchlen1 = icu_toUChars(entry_strs, (ptr1 * (ENT_STR_SIZE+1)), lenk1, uch1, ucap);
+ uchlen2 = icu_toUChars(entry_strs, (ptr2 * (ENT_STR_SIZE+1)), lenk2, uch2, ucap);
+
+ if(Flag_location)
+ ucol1 = ucol_open(Str_location, &err1);
+ else
+ ucol1 = ucol_open(NULL, &err1);
+ if (!U_SUCCESS(err1))
+ printf("there is a error: U_ZERO_ERROR, open a ucol.");
+ u_less = !ucol_greaterOrEqual(ucol1, uch1, uchlen1, uch2, uchlen2);
+
+ ucol_close(ucol1);
+ return u_less;
+#else
char_ptr = 0;
LOOP
BEGIN
@@ -2947,8 +3000,6 @@ BEGIN
BEGIN
COMPARE_RETURN (FALSE);
END
-
-#ifdef SUPPORT_8BIT
else if char_less_than(char1, char2)
BEGIN
COMPARE_RETURN (TRUE);
@@ -2957,21 +3008,11 @@ BEGIN
BEGIN
COMPARE_RETURN (FALSE);
END
-#else /* NOT SUPPORT_8BIT */
- else if (char1 < char2)
- BEGIN
- COMPARE_RETURN (TRUE);
- END
- else if (char1 > char2)
- BEGIN
- COMPARE_RETURN (FALSE);
- END
-#endif /* SUPPORT_8BIT */
-
INCR (char_ptr);
END
Exit_Label:
return (less_than);
+#endif
END
/*^^^^^^^^^^^^^^^^^^^^^^^^^^ END OF SECTION 301 ^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
@@ -3010,8 +3051,147 @@ BEGIN
END
END
END
-/*^^^^^^^^^^^^^^^^^^^^^^^^^^ END OF SECTION 62 ^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
+#ifdef UTF_8
+/*
+"lower_case_uni" is the fonction for processing the characters, actually the UTF-8.
+We transform UTF-8 to Unicode, then to low case, then back to UTF-8 for output.
+When we transform the character, the length have been changed. So we have do
+some job for the length. And the output of this fonction we should be careful
+to the length. 23/sep/2009
+*/
+BufPointer_T lower_case_uni (BufType_T buf, BufPointer_T bf_ptr,
+ BufPointer_T len)
+BEGIN
+
+ UChar target[BUF_SIZE+1];
+ int32_t tarcap=BUF_SIZE+1;
+ int32_t tarlen = icu_toUChars(buf, bf_ptr, len, target, tarcap);
+
+ UChar tarlow[BUF_SIZE+1];
+ int32_t tlcap=BUF_SIZE+1;
+ int32_t tllen=icu_strToLower(tarlow, tlcap,target, tarlen);
+
+ unsigned char dest[BUF_SIZE+1];
+ int32_t destcap= BUF_SIZE-bf_ptr;
+
+ int32_t tblen=icu_fromUChars(dest, destcap, (const UChar *) tarlow, tllen);
+
+ BufPointer_T i;
+ if (tblen > 0)
+ BEGIN
+ if (len!=tblen)
+ BEGIN
+ unsigned char tmp[BUF_SIZE+1];
+ BufPointer_T tmppr=0;
+ for (i=bf_ptr+len;i<=(BUF_SIZE-tblen+len);i++)
+ BEGIN
+ tmp[tmppr]=buf[i];
+ tmppr++;
+ END
+ i=bf_ptr+tblen;
+ tmppr=0;
+ for (tmppr=0;tmppr<=(BUF_SIZE-bf_ptr-tblen);tmppr++)
+ BEGIN
+ buf[i]=tmp[tmppr];
+ i++;
+ END
+ END
+ for (i = 0; i <= (tblen - 1); i++)
+ BEGIN
+
+ buf[i+bf_ptr]=dest[i];
+
+ END
+ END
+
+ return tblen;
+END
+
+
+/*
+This fonction is for transform UTF-8 to Unicode with ICU libs. 23/sep/2009
+*/
+int32_t icu_toUChars(BufType_T buf, BufPointer_T bf_ptr,BufPointer_T len,UChar * target, int32_t tarcap)
+BEGIN
+ UConverter * ucon1;
+ UErrorCode err1 = U_ZERO_ERROR;
+ ucon1 = ucnv_open(NULL, &err1);
+ if (!U_SUCCESS(err1))
+ BEGIN
+ printf("1there is a error: U_ZERO_ERROR");
+ END
+ ucnv_toUChars(ucon1, target, tarcap, (char *)&buf[bf_ptr], len, &err1);
+ if (!U_SUCCESS(err1))
+ BEGIN
+ printf("2there is a error: U_ZERO_ERROR");
+ END
+
+ return len;
+END
+
+/*
+This fonction is for transform Unicode string to low case. 23/sep/2009
+*/
+int32_t icu_strToLower(UChar * tarlow, int32_t tlcap, UChar * target, int32_t tarlen)
+BEGIN
+ int32_t tllen;
+ UErrorCode err1 = U_ZERO_ERROR;
+ if (!U_SUCCESS(err1))
+ BEGIN
+ printf("3there is a error: U_ZERO_ERROR");
+ END
+ if (Flag_language)
+ {
+ tllen=u_strToLower(tarlow,tlcap, target,tarlen,Str_language,&err1);
+ }
+ else
+ {
+ tllen=u_strToLower(tarlow,tlcap, target,tarlen,NULL,&err1);
+ }
+ if (!U_SUCCESS(err1))
+ BEGIN
+ int16_t i=0;
+ printf("4there is a error: U_ZERO_ERROR");
+ for (i=0;i<tarlen;i++)
+ BEGIN
+ printf("%X", target[i]);
+ END
+ printf("\n");
+ for (i=0;i<tllen;i++)
+ BEGIN
+ printf("%X", tarlow[i]);
+ END
+ printf("\n");
+ END
+
+ return tllen;
+END
+
+
+/*
+This fonction is for transform Unicode to UTF-8. 23/sep/2009
+*/
+int32_t icu_fromUChars(unsigned char * dest, int32_t destcap, const UChar * src, int32_t srclen)
+BEGIN
+ UConverter * ucon2;
+ UErrorCode err2 = U_ZERO_ERROR;
+ int32_t tblen;
+ ucon2 = ucnv_open(NULL, &err2);
+ if (!U_SUCCESS(err2))
+ BEGIN
+ printf("5there is a error: U_ZERO_ERROR");
+ END
+ tblen=ucnv_fromUChars(ucon2, (char *)dest, destcap, src, srclen, &err2);
+ if (!U_SUCCESS(err2))
+ BEGIN
+ printf("6there is a error: U_ZERO_ERROR");
+ END
+
+ return tblen;
+END
+#endif
+/*^^^^^^^^^^^^^^^^^^^^^^^^^^ END OF SECTION 62 ^^^^^^^^^^^^^^^^^^^^^^^^^^^*/