groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff] Re: patch for troff (building block for new grohtml)


From: Gaius Mulley
Subject: [Groff] Re: patch for troff (building block for new grohtml)
Date: Fri, 12 May 2000 19:31:54 +0100 (BST)

Hi Werner,

here are a few patches for troff. They provide some of the
building blocks for the revised grohtml. Basically I've added
a command .output <arg> which if the value of <arg> is zero
then all ditroff output is suppressed until troff encounters
a command .output 1 (or non zero).

I've also added four registers which determine the minx, miny,
maxx, maxy extent of the previous .output section.

This will allow the new grohtml:

 (i)  to easily find out where images, tables, eqns are held on
      the output device (normally -Tps but could be others as well). 
 (ii) to invoke troff with -Thtml and this will ignore all eqns,
      tables, images and not get into trouble for not knowing
      about the S font etc

On a contentious issue, I've also removed two gotos :-)

Here is some example troff input which hopefully demonstrate the
above ramblings:

-------- start of example -------
.LP
.output 1
This is my table:
.output 0
.TS
tab(!), center, allbox;
lw(2i)!s!s
l!l!l.
I wonder if
this!works!yet?
.TE
.tm grohtml-info:page \n% \n[opminx] \n[opminy] \n[opmaxx] \n[opmaxy]
.output 1
and now for something completely different.
-------- end of example -------

do the changes meet with approval? Incidentally I propose to develop the new
grohtml under the original device name grohtml-new :-)
so not to break the existing device. Sometime in the future this would
be a straight replacement for grohtml - any comments?

cheers Gaius


--- groff-cvs/src/roff/troff/input.cc   Sat Apr 22 14:17:44 2000
+++ groff-html/src/roff/troff/input.cc  Fri May 12 18:21:56 2000
@@ -4542,6 +4542,14 @@
   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;
@@ -4564,9 +4572,10 @@
       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;
       }
@@ -4613,18 +4622,13 @@
          }
        }
       }
-      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()
@@ -5795,6 +5799,7 @@
   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();
@@ -5876,6 +5881,75 @@
                                                : "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;
+  }
+}
+
+void reset_output_registers()
+{
+  output_reg_minx_contents = -1;
+  output_reg_miny_contents = -1;
+  output_reg_maxx_contents = -1;
+  output_reg_maxy_contents = -1;
+}
+
+void output_request()
+{
+  if (break_flag)
+    curenv->do_break();
+
+  if (has_arg()) {
+    int n;
+  
+    if (get_integer(&n)) {
+      if (!the_output)
+       init_output();
+      if (n == 0) {
+       the_output->off();
+      } else {
+       the_output->on();
+      }
+    } else {
+      error("missing integer argument");
+    }
+  } else {
+    error("missing argument");
+  }
+  while (!tok.newline() && !tok.eof())
+    tok.next();
+  tok.next();
+  /*
+   *  lastly we reset the output registers 
+   */
+  reset_output_registers();
+}
+
+void init_output_requests()
+{
+  init_request("output", output_request);
+}
+
 void init_input_requests()
 {
   init_request("ds", define_string);
@@ -5965,6 +6039,10 @@
   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);
--- groff-cvs/src/roff/troff/node.cc    Mon Feb 28 11:02:16 2000
+++ groff-html/src/roff/troff/node.cc   Fri May 12 18:18:42 2000
@@ -624,13 +624,16 @@
 #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:
@@ -638,9 +641,11 @@
   ~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);
 };
@@ -649,7 +654,7 @@
 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);
 };
 
@@ -657,7 +662,7 @@
 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);
@@ -717,10 +722,12 @@
   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; }
@@ -778,7 +785,7 @@
 }
 
 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) {
@@ -1069,6 +1076,16 @@
   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();
@@ -1190,8 +1207,16 @@
 {
 }
 
+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) {
@@ -1261,28 +1286,31 @@
 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);
   delete_node_list(n);
+  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());
 }
 
 void real_output_file::really_copy_file(hunits, vunits, const char *)
@@ -1299,6 +1327,26 @@
 {
 }
 
+void real_output_file::on()
+{
+  really_on();
+  output_on = 1;
+}
+
+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)
@@ -1306,7 +1354,7 @@
   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);
@@ -1330,7 +1378,7 @@
 {
 }
 
-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)
 {
 }
 
--- groff-cvs/src/roff/troff/node.h     Sun Feb  6 09:37:01 2000
+++ groff-html/src/roff/troff/node.h    Fri May 12 18:05:58 2000
@@ -462,11 +462,13 @@
   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 */
--- groff-cvs/src/roff/troff/request.h  Thu May 11 05:59:08 2000
+++ groff-html/src/roff/troff/request.h Fri May 12 18:06:23 2000
@@ -66,6 +66,7 @@
 };
 
 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();
--- groff-cvs/src/roff/troff/reg.h      Sun Feb  6 09:37:03 2000
+++ groff-html/src/roff/troff/reg.h     Fri May 12 18:06:38 2000
@@ -66,6 +66,7 @@
 
 extern object_dictionary number_reg_dictionary;
 extern void set_number_reg(symbol nm, units n);
+extern void check_output_limits(int x, int y);
 
 reg *lookup_number_reg(symbol);
 #if 0
--- groff-cvs/src/roff/troff/div.cc     Sun Mar  5 12:11:22 2000
+++ groff-html/src/roff/troff/div.cc    Fri May 12 18:08:36 2000
@@ -328,7 +328,7 @@
 }
 
 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 @@
   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;
--- groff-cvs/ChangeLog Thu May 11 05:59:07 2000
+++ groff-html/ChangeLog        Fri May 12 18:28:26 2000
@@ -1,3 +1,12 @@
+20000-05-12  Gaius Mulley  <address@hidden>
+
+       * src/roff/troff/reg.h, src/roff/troff/div.cc, src/roff/troff/div.cc,
+       src/roff/troff/input.cc, src/roff/troff/node.cc, src/roff/troff/node.h,
+       src/roff/troff/request.h: added the new troff command .output <arg>
+       and also the opminx, opminy, opmaxx, opmaxy registers.
+
+       * src/roff/troff/input.cc: removed two gotos
+
 2000-05-11  Werner LEMBERG  <address@hidden>
 
        * doc/groff.texinfo: Reading the source code shows up a lot of


reply via email to

[Prev in Thread] Current Thread [Next in Thread]