summaryrefslogtreecommitdiff
path: root/src/roff
diff options
context:
space:
mode:
authorwlemb <wlemb>2000-08-25 07:44:04 +0000
committerwlemb <wlemb>2000-08-25 07:44:04 +0000
commit3dae0e3967da084830d4a22f322f550144e3b54c (patch)
treed16a31d940907a1138ab504204517cb962eaf9ea /src/roff
parent9bf5b5d572f3af295a7a720878a0103b192e4873 (diff)
downloadgroff-3dae0e3967da084830d4a22f322f550144e3b54c.tar.gz
* src/include/posix.h: Remove definition of FILENAME_MAX.
* src/preproc/html2/pre-html.h, pre-html.cc: Add return type to `sys_fatal' and `stop' function(). * test-groff: Updated. Added the new troff command .output <arg> to suppress output (while still obeying motion) and also the opminx, opminy, opmaxx, opmaxy registers (for passing the output dimensions to the output device). * src/roff/troff/div.cc (top_level_diversion::output): Use `width' parameter. * src/roff/troff/node.h, src/roff/troff/node.cc (troff_output_file::really_print_line, ascii_output_file::really_print_line, supress_output_file::really_print_line): Use `width' parameter. (troff_output_file::really_on, troff_output_file::really_off, output_file::on, output_file::off, real_output_file::on, real_output_file::off, real_output_file::really_on, real_output_file::really_off): New functions. (real_output_file:public output_file): New variable `output_on'. (real_output_file::begin_page, real_output_file::copy_file, real_output_file::transparent_char, real_output_file::print_line): Use it. (real_output_file::print_line): Use check_output_limits. * src/roff/troff/reg.h, src/roff/troff/request.h, src/roff/troff/input.cc (assign_registers): New function to remove two `goto's. (do_ps_file): Use it. (check_output_limits, reset_output_registers, output_request, init_output_requests): New functions. (init_input_requests): Updated. Added new grohtml2 device and html2 preprocessor (coding not yet finished) which will eventually replace grohtml. * Makefile.in, tmac/Makefile.sub, tmac/eqnrc, tmac/troffrc-end: Updated. * src/include/htmlindicate.h, src/include/htmlindicate (html_begin_suppress, html_end_suppress): New functions. * src/preproc/tbl/main.cc: Use it. * src/roff/groff/groff.cc: Add support for html2 device (which will automatically invoke the html2 preprocessor). * src/roff/troff/input.cc (is_html2): New variable. * src/roff/troff/troff.h, src/roff/troff/env.h, src/roff/troff/env.cc (environment::add_html_tag): New function (uses `is_html2'). (environment::do_break): Use it. * font/devhtml2/*: New files. * src/devices/grohtml2: New device. * src/preproc/html2: New preprocessor. * tmac/tmac.html-tags, tmac/tmac.html2: New files.
Diffstat (limited to 'src/roff')
-rw-r--r--src/roff/groff/groff.cc42
-rw-r--r--src/roff/troff/div.cc4
-rw-r--r--src/roff/troff/env.cc16
-rw-r--r--src/roff/troff/env.h1
-rw-r--r--src/roff/troff/input.cc101
-rw-r--r--src/roff/troff/node.cc92
-rw-r--r--src/roff/troff/node.h4
-rw-r--r--src/roff/troff/reg.h2
-rw-r--r--src/roff/troff/request.h1
-rw-r--r--src/roff/troff/troff.h1
10 files changed, 225 insertions, 39 deletions
diff --git a/src/roff/groff/groff.cc b/src/roff/groff/groff.cc
index 034052a8..c80be644 100644
--- a/src/roff/groff/groff.cc
+++ b/src/roff/groff/groff.cc
@@ -84,7 +84,8 @@ public:
int lflag = 0;
char *spooler = 0;
-char *driver = 0;
+char *postdriver = 0;
+char *predriver = 0;
possible_command commands[NCOMMANDS];
@@ -191,6 +192,10 @@ int main(int argc, char **argv)
safer_flag = 0;
break;
case 'T':
+ if (strcmp(optarg, "html2") == 0) {
+ // force soelim to aid the html preprocessor
+ commands[SOELIM_INDEX].set_name(command_prefix, "soelim");
+ }
if (strcmp(optarg, "Xps") == 0) {
warning("-TXps option is obsolete: use -X -Tps instead");
device = "ps";
@@ -251,17 +256,23 @@ int main(int argc, char **argv)
font::set_unknown_desc_command_handler(handle_unknown_desc_command);
if (!font::load_desc())
fatal("invalid device `%1'", device);
- if (!driver)
+ if (!postdriver)
fatal("no `postpro' command in DESC file for device `%1'", device);
+
+ if (predriver) {
+ commands[TROFF_INDEX].insert_arg(commands[TROFF_INDEX].get_name());
+ commands[TROFF_INDEX].set_name(predriver);
+ }
+
const char *real_driver = 0;
if (Xflag) {
- real_driver = driver;
- driver = GXDITVIEW;
+ real_driver = postdriver;
+ postdriver = GXDITVIEW;
commands[TROFF_INDEX].append_arg("-r" XREG "=", "1");
}
- if (driver)
- commands[POST_INDEX].set_name(driver);
- int gxditview_flag = driver && strcmp(xbasename(driver), GXDITVIEW) == 0;
+ if (postdriver)
+ commands[POST_INDEX].set_name(postdriver);
+ int gxditview_flag = postdriver && strcmp(xbasename(postdriver), GXDITVIEW) == 0;
if (gxditview_flag && argc - optind == 1) {
commands[POST_INDEX].append_arg("-title");
commands[POST_INDEX].append_arg(argv[optind]);
@@ -372,6 +383,21 @@ void handle_unknown_desc_command(const char *command, const char *arg,
else
spooler = strsave(arg);
}
+ if (strcmp(command, "prepro") == 0) {
+ if (arg == 0)
+ error_with_file_and_line(filename, lineno,
+ "`prepro' command requires an argument");
+ else {
+ for (const char *p = arg; *p; p++)
+ if (csspace(*p)) {
+ error_with_file_and_line(filename, lineno,
+ "invalid `prepro' argument `%1'"
+ ": program name required", arg);
+ return;
+ }
+ predriver = strsave(arg);
+ }
+ }
if (strcmp(command, "postpro") == 0) {
if (arg == 0)
error_with_file_and_line(filename, lineno,
@@ -384,7 +410,7 @@ void handle_unknown_desc_command(const char *command, const char *arg,
": program name required", arg);
return;
}
- driver = strsave(arg);
+ postdriver = strsave(arg);
}
}
}
diff --git a/src/roff/troff/div.cc b/src/roff/troff/div.cc
index 013ea669..8566cd0f 100644
--- a/src/roff/troff/div.cc
+++ b/src/roff/troff/div.cc
@@ -328,7 +328,7 @@ vunits top_level_diversion::distance_to_next_trap()
}
void top_level_diversion::output(node *nd, int retain_size,
- vunits vs, vunits post_vs, hunits /*width*/)
+ vunits vs, vunits post_vs, hunits width)
{
no_space_mode = 0;
vunits next_trap_pos;
@@ -346,7 +346,7 @@ void top_level_diversion::output(node *nd, int retain_size,
vertical_position += v.pre;
vertical_position += v.pre_extra;
the_output->print_line(page_offset, vertical_position, nd,
- v.pre + v.pre_extra, v.post_extra);
+ v.pre + v.pre_extra, v.post_extra, width);
vertical_position += v.post_extra;
if (vertical_position > high_water_mark)
high_water_mark = vertical_position;
diff --git a/src/roff/troff/env.cc b/src/roff/troff/env.cc
index fbea78ed..b5e1ed74 100644
--- a/src/roff/troff/env.cc
+++ b/src/roff/troff/env.cc
@@ -1936,9 +1936,24 @@ void environment::final_break()
do_break();
}
+void environment::add_html_tag (const char *name)
+{
+ if (is_html2) {
+ // need to emit tag for post-grohtml
+ macro *m = new macro;
+
+ for (const char *p = name; *p; p++)
+ if (!illegal_input_char((unsigned char)*p))
+ m->append(*p);
+ output_pending_lines();
+ output_line(new special_node(*m), 0);
+ }
+}
+
void environment::do_break()
{
if (curdiv == topdiv && topdiv->before_first_page) {
+ add_html_tag("html-tag:eol");
topdiv->begin_page();
return;
}
@@ -1969,6 +1984,7 @@ void environment::do_break()
break;
}
}
+ add_html_tag("html-tag:eol");
node *tem = line;
line = 0;
output_line(tem, width_total);
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index 1db463da..d2a1fb34 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -270,6 +270,7 @@ public:
void spread() { spread_flag = 1; }
void do_break(); // .br
void final_break();
+ void add_html_tag (const char *name);
void newline();
void handle_tab(int is_leader = 0); // do a tab or leader
void add_node(node *);
diff --git a/src/roff/troff/input.cc b/src/roff/troff/input.cc
index 529a70f1..b4e9c70c 100644
--- a/src/roff/troff/input.cc
+++ b/src/roff/troff/input.cc
@@ -101,6 +101,7 @@ static symbol blank_line_macro_name;
static int compatible_flag = 0;
int ascii_output_flag = 0;
int suppress_output_flag = 0;
+int is_html2 = 0;
int tcommand_flag = 0;
@@ -4540,6 +4541,14 @@ int ps_get_line(char *buf, FILE *fp, const char* filename)
return 1;
}
+inline void assign_registers(int llx, int lly, int urx, int ury)
+{
+ llx_reg_contents = llx;
+ lly_reg_contents = lly;
+ urx_reg_contents = urx;
+ ury_reg_contents = ury;
+}
+
void do_ps_file(FILE *fp, const char* filename)
{
bounding_box bb;
@@ -4562,9 +4571,10 @@ void do_ps_file(FILE *fp, const char* filename)
break;
if (strncmp(buf + 2, "BoundingBox:", 12) == 0) {
int res = parse_bounding_box(buf + 14, &bb);
- if (res == 1)
- goto assign_registers;
- else if (res == 2) {
+ if (res == 1) {
+ assign_registers(bb.llx, bb.lly, bb.urx, bb.ury);
+ return;
+ } else if (res == 2) {
bb_at_end = 1;
break;
}
@@ -4611,18 +4621,13 @@ void do_ps_file(FILE *fp, const char* filename)
}
}
}
- if (got_bb)
- goto assign_registers;
+ if (got_bb) {
+ assign_registers(bb.llx, bb.lly, bb.urx, bb.ury);
+ return;
+ }
}
}
error("%%%%BoundingBox comment not found in `%1'", filename);
- return;
-
-assign_registers:
- llx_reg_contents = bb.llx;
- lly_reg_contents = bb.lly;
- urx_reg_contents = bb.urx;
- ury_reg_contents = bb.ury;
}
void ps_bbox_request()
@@ -5689,6 +5694,7 @@ int main(int argc, char **argv)
case 'T':
device = optarg;
tflag = 1;
+ is_html2 = (strcmp(device, "html2") == 0);
break;
case 'C':
compatible_flag = 1;
@@ -5797,6 +5803,7 @@ int main(int argc, char **argv)
init_column_requests();
#endif /* COLUMN */
init_node_requests();
+ init_output_requests();
number_reg_dictionary.define(".T", new constant_reg(tflag ? "1" : "0"));
init_registers();
init_reg_requests();
@@ -5871,6 +5878,72 @@ static void init_registers()
: "0"));
}
+/*
+ * .output request and associated registers
+ */
+
+static int output_reg_minx_contents = -1;
+static int output_reg_miny_contents = -1;
+static int output_reg_maxx_contents = -1;
+static int output_reg_maxy_contents = -1;
+
+void check_output_limits (int x, int y)
+{
+ if ((output_reg_minx_contents == -1) || (x < output_reg_minx_contents)) {
+ output_reg_minx_contents = x;
+ }
+ if (x > output_reg_maxx_contents) {
+ output_reg_maxx_contents = x;
+ }
+ if ((output_reg_miny_contents == -1) || (y < output_reg_miny_contents)) {
+ output_reg_miny_contents = y;
+ }
+ if (y > output_reg_maxy_contents) {
+ output_reg_maxy_contents = y;
+ }
+ // fprintf(stderr, "x = %d y=%d miny=%d maxy=%d\n", x, y, output_reg_miny_contents, output_reg_maxy_contents);
+}
+
+void reset_output_registers()
+{
+ // fprintf(stderr, "reset_output_registers\n");
+ output_reg_minx_contents = -1;
+ output_reg_miny_contents = -1;
+ output_reg_maxx_contents = -1;
+ output_reg_maxy_contents = -1;
+}
+
+void output_request()
+{
+ if (has_arg()) {
+ int n;
+
+ if (! get_integer(&n)) {
+ error("missing integer argument for output request");
+ n = 1;
+ }
+
+ if (break_flag)
+ curenv->do_break();
+
+ if (!the_output)
+ init_output();
+ if (n == 0) {
+ the_output->off();
+ } else {
+ the_output->on();
+ }
+ } else {
+ error("missing argument for output request");
+ }
+ skip_line();
+}
+
+void init_output_requests()
+{
+ init_request("output", output_request);
+}
+
void init_input_requests()
{
init_request("ds", define_string);
@@ -5960,6 +6033,10 @@ void init_input_requests()
number_reg_dictionary.define("lly", new variable_reg(&lly_reg_contents));
number_reg_dictionary.define("urx", new variable_reg(&urx_reg_contents));
number_reg_dictionary.define("ury", new variable_reg(&ury_reg_contents));
+ number_reg_dictionary.define("opminx", new variable_reg(&output_reg_minx_contents));
+ number_reg_dictionary.define("opminy", new variable_reg(&output_reg_miny_contents));
+ number_reg_dictionary.define("opmaxx", new variable_reg(&output_reg_maxx_contents));
+ number_reg_dictionary.define("opmaxy", new variable_reg(&output_reg_maxy_contents));
}
object_dictionary request_dictionary(501);
diff --git a/src/roff/troff/node.cc b/src/roff/troff/node.cc
index d53bf333..3c0d936e 100644
--- a/src/roff/troff/node.cc
+++ b/src/roff/troff/node.cc
@@ -647,13 +647,16 @@ class real_output_file : public output_file {
#ifndef POPEN_MISSING
int piped;
#endif
- int printing;
+ int printing; // decision via optional page list
+ int output_on; // .output 1 or .output 0 requests
virtual void really_transparent_char(unsigned char) = 0;
virtual void really_print_line(hunits x, vunits y, node *n,
- vunits before, vunits after) = 0;
+ vunits before, vunits after, hunits width) = 0;
virtual void really_begin_page(int pageno, vunits page_length) = 0;
virtual void really_copy_file(hunits x, vunits y, const char *filename);
virtual void really_put_filename(const char *filename);
+ virtual void really_on();
+ virtual void really_off();
protected:
FILE *fp;
public:
@@ -661,9 +664,11 @@ public:
~real_output_file();
void flush();
void transparent_char(unsigned char);
- void print_line(hunits x, vunits y, node *n, vunits before, vunits after);
+ void print_line(hunits x, vunits y, node *n, vunits before, vunits after, hunits width);
void begin_page(int pageno, vunits page_length);
void put_filename(const char *filename);
+ void on();
+ void off();
int is_printing();
void copy_file(hunits x, vunits y, const char *filename);
};
@@ -672,7 +677,7 @@ class suppress_output_file : public real_output_file {
public:
suppress_output_file();
void really_transparent_char(unsigned char);
- void really_print_line(hunits x, vunits y, node *n, vunits, vunits);
+ void really_print_line(hunits x, vunits y, node *n, vunits, vunits, hunits width);
void really_begin_page(int pageno, vunits page_length);
};
@@ -680,7 +685,7 @@ class ascii_output_file : public real_output_file {
public:
ascii_output_file();
void really_transparent_char(unsigned char);
- void really_print_line(hunits x, vunits y, node *n, vunits, vunits);
+ void really_print_line(hunits x, vunits y, node *n, vunits, vunits, hunits width);
void really_begin_page(int pageno, vunits page_length);
void outc(unsigned char c);
void outs(const char *s);
@@ -740,10 +745,12 @@ public:
void end_special();
void word_marker();
void really_transparent_char(unsigned char c);
- void really_print_line(hunits x, vunits y, node *n, vunits before, vunits after);
+ void really_print_line(hunits x, vunits y, node *n, vunits before, vunits after, hunits width);
void really_begin_page(int pageno, vunits page_length);
void really_copy_file(hunits x, vunits y, const char *filename);
void really_put_filename(const char *filename);
+ void really_on();
+ void really_off();
void draw(char, hvpair *, int, font_size);
int get_hpos() { return hpos; }
int get_vpos() { return vpos; }
@@ -801,7 +808,7 @@ inline void troff_output_file::moveto(hunits h, vunits v)
}
void troff_output_file::really_print_line(hunits x, vunits y, node *n,
- vunits before, vunits after)
+ vunits before, vunits after, hunits width)
{
moveto(x, y);
while (n != 0) {
@@ -1092,6 +1099,16 @@ void troff_output_file::draw(char code, hvpair *point, int npoints,
put('\n');
}
+void troff_output_file::really_on ()
+{
+ flush_tbuf();
+}
+
+void troff_output_file::really_off ()
+{
+ flush_tbuf();
+}
+
void troff_output_file::really_put_filename(const char *filename)
{
flush_tbuf();
@@ -1213,8 +1230,16 @@ void output_file::put_filename(const char *filename)
{
}
+void output_file::on()
+{
+}
+
+void output_file::off()
+{
+}
+
real_output_file::real_output_file()
-: printing(0)
+: printing(0), output_on(1)
{
#ifndef POPEN_MISSING
if (pipe_command) {
@@ -1277,27 +1302,36 @@ int real_output_file::is_printing()
void real_output_file::begin_page(int pageno, vunits page_length)
{
printing = in_output_page_list(pageno);
- if (printing)
+ if (printing && output_on)
really_begin_page(pageno, page_length);
}
void real_output_file::copy_file(hunits x, vunits y, const char *filename)
{
- if (printing)
+ if (printing && output_on)
really_copy_file(x, y, filename);
+ check_output_limits(x.to_units(), y.to_units());
}
void real_output_file::transparent_char(unsigned char c)
{
- if (printing)
+ if (printing && output_on)
really_transparent_char(c);
}
void real_output_file::print_line(hunits x, vunits y, node *n,
- vunits before, vunits after)
+ vunits before, vunits after, hunits width)
{
- if (printing)
- really_print_line(x, y, n, before, after);
+ if (printing && output_on)
+ really_print_line(x, y, n, before, after, width);
+
+ if (before.to_units() < after.to_units()) {
+ check_output_limits(x.to_units() , y.to_units()+before.to_units());
+ check_output_limits(x.to_units()+width.to_units(), y.to_units()+after.to_units()+n->size());
+ } else {
+ check_output_limits(x.to_units() , y.to_units()+after.to_units());
+ check_output_limits(x.to_units()+width.to_units(), y.to_units()+before.to_units()+n->size());
+ }
delete_node_list(n);
}
@@ -1315,6 +1349,32 @@ void real_output_file::really_put_filename(const char *filename)
{
}
+void real_output_file::on()
+{
+ really_on();
+ if (output_on == 0) {
+ output_on = 1;
+ }
+ /*
+ * lastly we reset the output registers
+ */
+ reset_output_registers();
+}
+
+void real_output_file::off()
+{
+ really_off();
+ output_on = 0;
+}
+
+void real_output_file::really_on()
+{
+}
+
+void real_output_file::really_off()
+{
+}
+
/* ascii_output_file */
void ascii_output_file::really_transparent_char(unsigned char c)
@@ -1322,7 +1382,7 @@ void ascii_output_file::really_transparent_char(unsigned char c)
putc(c, fp);
}
-void ascii_output_file::really_print_line(hunits, vunits, node *n, vunits, vunits)
+void ascii_output_file::really_print_line(hunits, vunits, node *n, vunits, vunits, hunits width)
{
while (n != 0) {
n->ascii_print(this);
@@ -1346,7 +1406,7 @@ suppress_output_file::suppress_output_file()
{
}
-void suppress_output_file::really_print_line(hunits, vunits, node *, vunits, vunits)
+void suppress_output_file::really_print_line(hunits, vunits, node *, vunits, vunits, hunits)
{
}
diff --git a/src/roff/troff/node.h b/src/roff/troff/node.h
index b5095575..21e585dc 100644
--- a/src/roff/troff/node.h
+++ b/src/roff/troff/node.h
@@ -462,11 +462,13 @@ public:
virtual void flush() = 0;
virtual void transparent_char(unsigned char) = 0;
virtual void print_line(hunits x, vunits y, node *n,
- vunits before, vunits after) = 0;
+ vunits before, vunits after, hunits width) = 0;
virtual void begin_page(int pageno, vunits page_length) = 0;
virtual void copy_file(hunits x, vunits y, const char *filename) = 0;
virtual int is_printing() = 0;
virtual void put_filename (const char *filename);
+ virtual void on();
+ virtual void off();
#ifdef COLUMN
virtual void vjustify(vunits, symbol);
#endif /* COLUMN */
diff --git a/src/roff/troff/reg.h b/src/roff/troff/reg.h
index 51d5b9a1..b983b875 100644
--- a/src/roff/troff/reg.h
+++ b/src/roff/troff/reg.h
@@ -66,6 +66,8 @@ public:
extern object_dictionary number_reg_dictionary;
extern void set_number_reg(symbol nm, units n);
+extern void check_output_limits(int x, int y);
+extern void reset_output_registers (void);
reg *lookup_number_reg(symbol);
#if 0
diff --git a/src/roff/troff/request.h b/src/roff/troff/request.h
index 57031756..7b3ad014 100644
--- a/src/roff/troff/request.h
+++ b/src/roff/troff/request.h
@@ -66,6 +66,7 @@ public:
};
extern void init_input_requests();
+extern void init_output_requests();
extern void init_div_requests();
extern void init_node_requests();
extern void init_reg_requests();
diff --git a/src/roff/troff/troff.h b/src/roff/troff/troff.h
index c5585016..1f1e612b 100644
--- a/src/roff/troff/troff.h
+++ b/src/roff/troff/troff.h
@@ -41,6 +41,7 @@ extern units units_per_inch;
extern int ascii_output_flag;
extern int suppress_output_flag;
+extern int is_html2;
extern int tcommand_flag;
extern int vresolution;