[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lynx-dev patch for multilingual bookmarks...
From: |
Leonid Pauzner |
Subject: |
lynx-dev patch for multilingual bookmarks... |
Date: |
Wed, 12 Aug 1998 03:20:17 +0400 (MSD) |
This is a long avaiting patch, it was discussed with Klaus about a year ago...
It was proposed to store non-ascii characters in bookmark titles with
a more consistent and independent way, by keeping them as &#UUUU;
The patch 'almost' working: I cannot manage to cast
'long' integer with a buffer string (see near the last line).
Leonid.
diff -u old/lybookma.c ./lybookma.c
--- old/lybookma.c Fri Aug 7 15:47:58 1998
+++ ./lybookma.c Wed Aug 12 01:59:46 1998
@@ -7,7 +7,8 @@
#include <LYSignal.h>
#include <LYSystem.h>
#include <LYKeymap.h>
-#include <LYCharUtils.h>
+#include <LYCharUtils.h> /* need for META charset */
+#include <LYCharSets.h> /* need for LYHaveCJKCharacterSet */
#include <LYCurses.h>
#include <GridText.h>
@@ -178,6 +179,9 @@
return(newfile);
}
+PRIVATE BOOLEAN have8bit PARAMS((char *Title));
+PRIVATE char* title_convert8bit PARAMS((char *Title));
+
/*
* Adds a link to a bookmark file, creating the file
* if it doesn't already exist, and making sure that
@@ -279,9 +283,15 @@
* Create the Title with any left-angle-brackets
* converted to < entities and any ampersands
* converted to & entities. - FM
+ *
+ * Covnert 8-bit letters to &#xUUUU to avoid dependencies
+ * from display character set.
+ * Do NOT convert any 8-bit chars if we have CJK display.
*/
StrAllocCopy(Title, string_buffer);
LYEntify(&Title, TRUE);
+ if (have8bit(Title) && (!LYHaveCJKCharacterSet))
+ StrAllocCopy(Title, title_convert8bit(Title));
/*
* Create the bookmark file, if it doesn't exist already,
@@ -880,7 +890,7 @@
* _statusline() so that any multibyte/CJK characters in the
* string will be handled properly. - FM
*/
- PUBLIC void LYMBM_statusline ARGS1(
+PUBLIC void LYMBM_statusline ARGS1(
char *, text)
{
if (LYMultiBookmarks == TRUE && user_mode == NOVICE_MODE) {
@@ -890,4 +900,82 @@
} else {
_statusline(text);
}
+}
+
+/*
+ * Check whether string have 8 bit chars.
+ */
+PRIVATE BOOLEAN have8bit ARGS1(char *, Title)
+{
+ CONST char *p = Title;
+
+ for ( ; *p; p++) {
+ if ((unsigned char)*p > 127)
+ return(TRUE);
+ }
+return(FALSE); /* if we came here */
+}
+
+/*
+ * Ok, title have 8-bit characters and they are in display charset.
+ * Bookmarks is a permanent file. To avoid dependencies from display
+ * character set which may be changed with time
+ * we store 8-bit characters as numeric character reference (NCR),
+ * so where the character encoded as unicode number in form of &#xUUUU;
+ *
+ * Starting with version 2.7.2 Lynx support NCR's translation
+ * as part of I18N and HTML4.0
+ * We do not want use META charset tag in bookmarks file:
+ * is will never be changed later :-(
+ *
+ * To make bookmarks more readable for human (&#xXXXX certainly not)
+ * we add a comment with '7-bit approximation' from the converted string.
+ * This is a valid HTML and bookmarks code.
+ *
+ */
+PRIVATE char* title_convert8bit ARGS1(char *, Title)
+{
+ CONST char *p = Title;
+ char *q;
+ char *comment = NULL;
+ char *ncr = NULL;
+ char *buf = NULL;
+
+ for ( ; *p; p++) {
+ LYstrncpy(q, p, 1);
+ if ((unsigned char)*q <= 127) {
+ StrAllocCat(comment, q);
+ StrAllocCat(ncr, q);
+ } else {
+ int charset_in, charset_out, uck;
+ long unicode;
+ char replace_buf [10];
+
+ charset_in = current_char_set;
+ charset_out = UCGetLYhndl_byMIME("us-ascii");
+ uck = UCTransCharStr(replace_buf, sizeof(replace_buf), *q,
+ charset_in, charset_out, YES);
+ if (uck >0)
+ StrAllocCat(comment, replace_buf); /* 7-bit approx */
+
+ unicode = UCTransToUni( *q, charset_in);
+
+ StrAllocCat(ncr, "&#");
+ /* StrAllocCat(ncr, ???unicode); casting from long to text string ? */
+
+ StrAllocCat(ncr, ";");
+
+ }
+ }
+
+ /*
+ * valid bookmark should be a single line (no linebreaks!).
+ */
+ StrAllocCat(buf, "<!-- ");
+ StrAllocCat(buf, comment);
+ StrAllocCat(buf, " -->");
+ StrAllocCat(buf, ncr);
+
+return(buf);
+
}
- lynx-dev patch for multilingual bookmarks...,
Leonid Pauzner <=