[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] accented characters in MAILTO requests
From: |
Gaius Mulley |
Subject: |
Re: [Groff] accented characters in MAILTO requests |
Date: |
Fri, 21 Jan 2000 01:43:04 +0000 (GMT) |
Hi Werner,
> the following doesn't work as expected:
>
> .MAILTO address@hidden "J\(:orgen H\(:agg"
>
> I get the following warning message from troff:
>
> a special character is illegal within \X
>
> Can you fix this?
yes :-) - here is the patch. troff wants to encode such
characters by the tcommand 'tC:o` and of course the device
specific 'special' character tcommand is encoded as:
x X etc
and we cannot nest tcommands -
so I've had to alter troff to encode any named character
as \(name\) within the x X command. This functionality
is turned on from within the devhtml/DESC file which
now contains:
use_charnames_in_special
So, hopefully, these changes will not break any other devices.
I've also added a 'pass_filenames' line to the html DESC file
as this will be used to pass the current filename from troff
to the device driver - at a later date - to fix the image file
name problem. I've altered grohtml to decode the named characters
within the x X tcommand. Are these alterations acceptable?
Hopefully it will allow the homepage to be constructed now :-)
cheers Gaius
diff -aruN groff-cvs/include/font.h groff-html/include/font.h
--- groff-cvs/include/font.h Sat Jan 15 11:35:20 2000
+++ groff-html/include/font.h Fri Jan 21 01:38:39 2000
@@ -73,6 +73,8 @@
static int spare2;
static int sizescale;
static int tcommand;
+ static int pass_filenames;
+ static int use_charnames_in_special;
static const char **font_name_table;
static const char **style_table;
diff -aruN groff-cvs/troff/charinfo.h groff-html/troff/charinfo.h
--- groff-cvs/troff/charinfo.h Fri May 21 05:50:38 1999
+++ groff-html/troff/charinfo.h Thu Jan 20 09:12:21 2000
@@ -74,6 +74,7 @@
void set_number(int);
int get_number();
int numbered();
+ symbol *get_symbol();
};
charinfo *get_charinfo(symbol);
@@ -162,4 +163,9 @@
not_found = 1;
return 1;
}
+}
+
+inline symbol *charinfo::get_symbol()
+{
+ return( &nm );
}
diff -aruN groff-cvs/troff/input.cc groff-html/troff/input.cc
--- groff-cvs/troff/input.cc Sat Jan 15 11:35:25 2000
+++ groff-html/troff/input.cc Thu Jan 20 10:00:56 2000
@@ -3927,6 +3927,38 @@
return new non_interpreted_node(mac);
}
+static void encode_char (macro *mac, char c)
+{
+ if (c == '\0') {
+ if (tok.special() && (font::use_charnames_in_special)) {
+ charinfo *ci=tok.get_char(1);
+ const char *s=ci->get_symbol()->contents();
+
+ if (s[0] != (char)0) {
+ mac->append('\\');
+ mac->append('(');
+ int i=0;
+ while (s[i] != (char)0) {
+ mac->append(s[i]);
+ i++;
+ }
+ mac->append('\\');
+ mac->append(')');
+ }
+ } else {
+ error("%1 is illegal within \\X", tok.description());
+ }
+ } else {
+ if ((font::use_charnames_in_special) && (c == '\\')) {
+ /*
+ * add escape escape sequence
+ */
+ mac->append(c);
+ }
+ mac->append(c);
+ }
+}
+
node *do_special()
{
token start;
@@ -3956,10 +3988,7 @@
c = '\b';
else
c = tok.ch();
- if (c == '\0')
- error("%1 is illegal within \\X", tok.description());
- else
- mac.append(c);
+ encode_char(&mac, c);
}
return new special_node(mac);
}
diff -aruN groff-cvs/troff/token.h groff-html/troff/token.h
--- groff-cvs/troff/token.h Fri May 21 05:50:39 1999
+++ groff-html/troff/token.h Wed Jan 19 20:50:47 2000
@@ -68,6 +68,7 @@
int nspaces(); // 1 if space, 2 if double space, 0 otherwise
int space(); // is it a space or double space?
int white_space(); // is the current token space or tab?
+ int special(); // is the current token a special character?
int newline(); // is the current token a newline?
int tab(); // is the current token a tab?
int leader();
@@ -122,6 +123,11 @@
inline int token::space()
{
return type == TOKEN_SPACE;
+}
+
+inline int token::special()
+{
+ return type == TOKEN_SPECIAL;
}
inline int token::nspaces()
diff -aruN groff-cvs/libgroff/font.cc groff-html/libgroff/font.cc
--- groff-cvs/libgroff/font.cc Sat Jan 15 11:35:21 2000
+++ groff-html/libgroff/font.cc Thu Jan 20 10:00:26 2000
@@ -767,6 +767,12 @@
else if (strcmp("tcommand", p) == 0) {
tcommand = 1;
}
+ else if (strcmp("pass_filenames", p) == 0) {
+ pass_filenames = 1;
+ }
+ else if (strcmp("use_charnames_in_special", p) == 0) {
+ use_charnames_in_special = 1;
+ }
else if (strcmp("family", p) == 0) {
p = strtok(0, WS);
if (!p) {
diff -aruN groff-cvs/libgroff/fontfile.cc groff-html/libgroff/fontfile.cc
--- groff-cvs/libgroff/fontfile.cc Fri May 21 05:50:38 1999
+++ groff-html/libgroff/fontfile.cc Thu Jan 20 10:00:29 2000
@@ -43,6 +43,8 @@
int font::spare2 = 0;
int font::sizescale = 1;
int font::tcommand = 0;
+int font::pass_filenames = 0;
+int font::use_charnames_in_special = 0;
const char **font::font_name_table = 0;
int *font::sizes = 0;
const char *font::family = 0;
diff -aruN groff-cvs/grohtml/html.cc groff-html/grohtml/html.cc
--- groff-cvs/grohtml/html.cc Sat Jan 15 11:30:17 2000
+++ groff-html/grohtml/html.cc Thu Jan 20 10:47:29 2000
@@ -1585,12 +1585,16 @@
{
int index;
- index = f->name_to_index(name);
- if (index == 0) {
- error("character `%s' not found", name);
- return( NULL );
+ if (f == 0) {
+ return( 0 );
} else {
- return( (char *)f->get_special_device_encoding(index) );
+ index = f->name_to_index(name);
+ if (index == 0) {
+ error("character `%s' not found", name);
+ return( NULL );
+ } else {
+ return( (char *)f->get_special_device_encoding(index) );
+ }
}
}
@@ -1598,9 +1602,11 @@
* str_translate_to_html - converts a string, str, into html text. It places
* the output input buffer, buf. It truncates string,
str, if
* there is not enough space in buf.
+ * It looks up the html character encoding of single
characters
+ * if, and_single, is TRUE. Characters such as < > &
etc.
*/
-void str_translate_to_html (font *f, char *buf, int buflen, char *str, int len)
+void str_translate_to_html (font *f, char *buf, int buflen, char *str, int
len, int and_single)
{
int l;
char *translation;
@@ -1651,17 +1657,27 @@
}
}
} else {
- char name[2];
+ if (and_single) {
+ char name[2];
- name[0] = str[i];
- name[1] = (char)0;
- translation = get_html_translation(f, name);
- if (translation) {
- l = strlen(translation);
- t = max(0, min(l, buflen-b));
- strncpy(&buf[b], translation, t);
- b += t;
+ name[0] = str[i];
+ name[1] = (char)0;
+ translation = get_html_translation(f, name);
+ if (translation) {
+ l = strlen(translation);
+ t = max(0, min(l, buflen-b));
+ strncpy(&buf[b], translation, t);
+ b += t;
+ } else {
+ if (b<buflen) {
+ buf[b] = str[i];
+ b++;
+ }
+ }
} else {
+ /*
+ * do not attempt to encode single characters
+ */
if (b<buflen) {
buf[b] = str[i];
b++;
@@ -1721,7 +1737,7 @@
((start_region == -1) || (t->maxv < start_region))) {
start_title_vpos = t->minv;
end_title_hpos = t->minh;
- str_translate_to_html(t->text_style.f, buf, MAX_STRING_LENGTH,
t->text_string, t->text_length);
+ str_translate_to_html(t->text_style.f, buf, MAX_STRING_LENGTH,
t->text_string, t->text_length, TRUE);
strcpy((char *)title.text, buf);
height = t->text_style.point_size*r/72;
found_title_start = TRUE;
@@ -1736,7 +1752,7 @@
start_title_vpos = min(t->minv, start_title_vpos);
end_title_hpos = max(t->maxh, end_title_hpos);
strcat(title.text, " ");
- str_translate_to_html(t->text_style.f, buf, MAX_STRING_LENGTH,
t->text_string, t->text_length);
+ str_translate_to_html(t->text_style.f, buf, MAX_STRING_LENGTH,
t->text_string, t->text_length, TRUE);
strcat(title.text, buf);
page_contents->words.sub_move_right();
removed_from_head = ((!page_contents->words.is_empty()) &&
@@ -2819,7 +2835,7 @@
{
char buf[MAX_STRING_LENGTH];
- str_translate_to_html(f, buf, MAX_STRING_LENGTH, str, len);
+ str_translate_to_html(f, buf, MAX_STRING_LENGTH, str, len, TRUE);
strncpy(str, buf, max(len, strlen(buf)+1));
}
@@ -2868,7 +2884,7 @@
do {
l = g;
current_vpos = g->minv;
- str_translate_to_html(g->text_style.f, buf, MAX_STRING_LENGTH,
g->text_string, g->text_length);
+ str_translate_to_html(g->text_style.f, buf, MAX_STRING_LENGTH,
g->text_string, g->text_length, TRUE);
strcat(header.header_buffer, (char *)buf);
page_contents->words.move_right();
g = page_contents->words.get_data();
@@ -5814,7 +5830,7 @@
char buf[MAX_STRING_LENGTH];
str_translate_to_html(g->text_style.f, buf, MAX_STRING_LENGTH,
- g->text_string, g->text_length);
+ g->text_string, g->text_length, TRUE);
html.put_string(buf);
}
@@ -6369,8 +6385,17 @@
}
} else if (strncmp(s, "html:", 5) == 0) {
int r=font::res; // resolution of the device
+ char buf[MAX_STRING_LENGTH];
+ font *f=sbuf_style.f;
- page_contents->add_html_command(&sbuf_style, &s[5], strlen(s)-5,
+ if (f == NULL) {
+ int found=FALSE;
+
+ f = font::load_font("TR", &found);
+ }
+ str_translate_to_html(f, buf, MAX_STRING_LENGTH,
+ &s[5], strlen(s)-5, FALSE);
+ page_contents->add_html_command(&sbuf_style, buf, strlen(buf),
// need to pass rest of string through to html output during flush
diff -aruN groff-cvs/devhtml/DESC groff-html/devhtml/DESC
--- groff-cvs/devhtml/DESC Sun Sep 12 08:29:59 1999
+++ groff-html/devhtml/DESC Thu Jan 20 09:53:33 2000
@@ -8,3 +8,5 @@
vert 1
unitwidth 10
postpro grohtml
+use_charnames_in_special
+pass_filenames