groff
[Top][All Lists]
Advanced

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

[Groff] fixes for grohtml


From: Gaius Mulley
Subject: [Groff] fixes for grohtml
Date: Fri, 28 Apr 2000 14:16:14 +0100 (BST)

Hi Werner,

here is a patch for grohtml to improve the -m option and
fix a divide by zero bug,

cheers Gaius


--- groff-cvs/src/devices/grohtml/html.cc       Wed Mar  1 21:46:45 2000
+++ groff-html/src/devices/grohtml/html.cc      Fri Apr 28 13:48:43 2000
@@ -1155,6 +1155,7 @@
   int   get_left                      (void);
   void  can_loose_column              (text_glob *start, struct text_defn 
*last_guess, int limit);
   int   check_lack_of_hits            (struct text_defn *next_guess, struct 
text_defn *last_guess, text_glob *start, int limit);
+  int   is_in_table                   (void);
 
   // ADD HERE
 
@@ -1917,31 +1918,29 @@
 
 void html_printer::calculate_margin (void)
 {
-  if (! margin_on) {
-    text_glob    *w;
-    graphic_glob *g;
+  text_glob    *w;
+  graphic_glob *g;
 
-    // remove margin
+  // remove margin
 
-    right_margin_indent = 0;
+  right_margin_indent = 0;
 
-    if (! page_contents->words.is_empty()) {
-
-      // firstly check the words to determine the right margin
+  if (! page_contents->words.is_empty()) {
+    
+    // firstly check the words to determine the right margin
 
-      page_contents->words.start_from_head();
-      do {
-       w = page_contents->words.get_data();
-       if ((w->maxh >= 0) && (w->maxh > right_margin_indent)) {
-         right_margin_indent = w->maxh;
+    page_contents->words.start_from_head();
+    do {
+      w = page_contents->words.get_data();
+      if ((w->maxh >= 0) && (w->maxh > right_margin_indent)) {
+       right_margin_indent = w->maxh;
 #if 0
-         if (right_margin_indent == 758) stop();
+       if (right_margin_indent == 758) stop();
 #endif
-       }
-       page_contents->words.move_right();
-      } while (! page_contents->words.is_equal_to_head());
-    }
-
+      }
+      page_contents->words.move_right();
+    } while (! page_contents->words.is_equal_to_head());
+    
     /*
      *  only examine graphics if no words present
      */
@@ -1960,6 +1959,7 @@
       } while (! page_contents->lines.is_equal_to_head());
     }
 
+
     /*
      *  now we know the right margin lets do the same to find left margin
      */
@@ -1968,7 +1968,7 @@
       header_indent     = right_margin_indent;
     }
     left_margin_indent  = right_margin_indent;
-    
+      
     if (! page_contents->words.is_empty()) {
       do {
        w = page_contents->words.get_data();
@@ -3142,7 +3142,7 @@
   if (start != 0) {
     int graphic_limit = end_region_vpos;
 
-    if (is_whole_line_bold(t) && (t->minh <= left_margin_indent)) {
+    if (is_whole_line_bold(t) && (t->minh <= left_margin_indent) && 
(guess_on)) {
       /*
        *  found header therefore terminate indentation table.
        *  Return a negative number so we know a header has
@@ -3180,7 +3180,7 @@
         *  if we have found a significant gap then record it
         */
        if (((t->minh - prevh >= mingap) ||
-            ((last_cols  != 0) && (last_cols [j].left != 0) && (t->minh == 
last_cols [j].left))) &&
+            ((last_cols  != 0) && (last_cols [j].right != 0) && (t->minh == 
last_cols [j].left))) &&
            (t->minh != t->maxh)) {
          next_cols[i].left    = t->minh;
          next_cols[i].right   = t->maxh;
@@ -3276,11 +3276,11 @@
   int i=0;
   int j;
 
-  while ((column_guess[i].left != 0) && (i<MAX_WORDS_PER_LINE)) {
+  while ((column_guess[i].right != 0) && (i<MAX_WORDS_PER_LINE)) {
     j=0;
-    while ((words[j].left != 0) && (j<MAX_WORDS_PER_LINE)) {
+    while ((words[j].right != 0) && (j<MAX_WORDS_PER_LINE)) {
       if ((words[j].left <= column_guess[i].right) && (i+1<MAX_WORDS_PER_LINE) 
&&
-         (column_guess[i+1].left != 0) && (words[j].right >= 
column_guess[i+1].left)) {
+         (column_guess[i+1].right != 0) && (words[j].right >= 
column_guess[i+1].left)) {
        if (debug_table_on) {
          fprintf(stderr, "is a conflict with words\n");
          fflush(stderr);
@@ -3306,7 +3306,7 @@
 {
   int i;
 
-  for (i=0; (i<MAX_WORDS_PER_LINE) && (src[i].left != 0); i++) {
+  for (i=0; (i<MAX_WORDS_PER_LINE) && (src[i].right != 0); i++) {
     include_into_list(dest, &src[i]);
   }
   remove_redundant_columns(dest);
@@ -3318,7 +3318,7 @@
 
 void html_printer::remove_entry_in_line (struct text_defn *line, int j)
 {
-  while (line[j].left != 0) {
+  while (line[j].right != 0) {
     line[j].left  = line[j+1].left;
     line[j].right = line[j+1].right;
     j++;
@@ -3334,10 +3334,10 @@
   int i=0;
   int j=0;
 
-  while (line[i].left != 0) {
-    if ((i<MAX_WORDS_PER_LINE) && (line[i+1].left != 0)) {
+  while (line[i].right != 0) {
+    if ((i<MAX_WORDS_PER_LINE) && (line[i+1].right != 0)) {
       j = 0;
-      while ((j<MAX_WORDS_PER_LINE) && (line[j].left != 0)) {
+      while ((j<MAX_WORDS_PER_LINE) && (line[j].right != 0)) {
        if ((j != i) && (is_intersection(line[i].left, line[i].right, 
line[j].left, line[j].right))) {
          line[i].left  = min(line[i].left , line[j].left);
          line[i].right = max(line[i].right, line[j].right);
@@ -3359,11 +3359,11 @@
 {
   int i=0;
 
-  while ((i<MAX_WORDS_PER_LINE) && (line[i].left != 0) && 
(line[i].left<item->left)) {
+  while ((i<MAX_WORDS_PER_LINE) && (line[i].right != 0) && 
(line[i].left<item->left)) {
     i++;
   }
 
-  if (line[i].left == 0) {
+  if (line[i].right == 0) {
     // add to the end
     if (i<MAX_WORDS_PER_LINE) {
       if ((i>0) && (line[i-1].left > item->left)) {
@@ -3385,7 +3385,7 @@
       int l     = line[i].left;
       int r     = line[i].right;
 
-      while ((i+1<MAX_WORDS_PER_LINE) && (line[i].left != 0)) {
+      while ((i+1<MAX_WORDS_PER_LINE) && (line[i].right != 0)) {
        line[i].left  = left;
        line[i].right = right;
        i++;
@@ -3412,7 +3412,7 @@
 {
   int i=0;
 
-  while ((i<max_words) && (line[i].left != 0)) {
+  while ((i<max_words) && (line[i].right != 0)) {
     if (line[i].left == item->left) {
       return( TRUE );
     } else {
@@ -3430,7 +3430,7 @@
 {
   int i=0;
 
-  while ((i<max_words) && (line[i].left != 0)) {
+  while ((i<max_words) && (line[i].right != 0)) {
     if (i>0) {
       line[i-1].right = line[i].left;
     }
@@ -3447,7 +3447,7 @@
 {
   int i=0;
 
-  while ((i<MAX_WORDS_PER_LINE) && (line[i].left != 0)) {
+  while ((i<MAX_WORDS_PER_LINE) && (line[i].right != 0)) {
     i++;
   }
 
@@ -3472,7 +3472,7 @@
 {
   int i=0;
 
-  while ((i<max_words) && (line[i].left != 0)) {
+  while ((i<max_words) && (line[i].right != 0)) {
     i++;
   }
   if (i>0) {
@@ -3503,7 +3503,7 @@
 
     include_into_list(match, &t);
   }
-  while ((line1[i].left != 0) && (line2[i].left != 0)) {
+  while ((line1[i].right != 0) && (line2[i].right != 0)) {
     if (line1[i].left == line2[j].left) {
       // same horizontal alignment found
       include_into_list(match, &line1[i]);
@@ -3541,7 +3541,7 @@
     i=0;
     j=0;
     while ((i<n) && (j<m) &&
-          (last_guess[i].left != 0) && (next_guess[j].left != 0)) {
+          (last_guess[i].right != 0) && (next_guess[j].right != 0)) {
       if ((is_intersection(last_guess[i].left, last_guess[i].right,
                           next_guess[j].left, next_guess[j].right)) &&
          (next_guess[j].left < last_guess[i].left) &&
@@ -3576,7 +3576,7 @@
   int k=0;
   int removed=FALSE;
 
-  while ((last_guess[j].left != 0) && (next_line[k].left != 0)) {
+  while ((last_guess[j].right != 0) && (next_line[k].right != 0)) {
     if (last_guess[j].left == next_line[k].left) {
       // same horizontal alignment found
       next_guess[i].left  = last_guess[j].left;
@@ -3584,7 +3584,7 @@
       i++;
       j++;
       k++;
-      if ((next_guess[i-1].right > last_guess[j].left) && (last_guess[j].left 
!= 0)) {
+      if ((next_guess[i-1].right > last_guess[j].left) && (last_guess[j].right 
!= 0)) {
        removed = TRUE;
       }
     } else if (last_guess[j].right < next_line[k].left) {
@@ -3605,12 +3605,12 @@
       i++;
       j++;
       k++;
-      if ((next_guess[i-1].right > last_guess[j].left) && (last_guess[j].left 
!= 0)) {
+      if ((next_guess[i-1].right > last_guess[j].left) && (last_guess[j].right 
!= 0)) {
        removed = TRUE;
       }
     }
   }
-  while (next_line[k].left != 0) {
+  while (next_line[k].right != 0) {
     next_guess[i].left  = next_line[k].left;
     next_guess[i].right = next_line[k].right;
     i++;
@@ -3640,7 +3640,7 @@
 {
   int i=0;
 
-  while (line[i].left != 0) {
+  while (line[i].right != 0) {
     i++;
   }
   return( i );
@@ -3699,7 +3699,7 @@
   int i=0;
 
   fprintf(stderr, "[%s:%s]", name, word);
-  while (line[i].left != 0) {
+  while (line[i].right != 0) {
     fprintf(stderr, " <left=%d right=%d %d%%> ", line[i].left, line[i].right, 
line[i].percent);
     i++;
   }
@@ -3715,7 +3715,7 @@
 { 
   int k;
 
-  for (k=0; ((src[k].left != 0) && (k<MAX_WORDS_PER_LINE)); k++) {
+  for (k=0; ((src[k].right != 0) && (k<MAX_WORDS_PER_LINE)); k++) {
     dest[k].left  = src[k].left;
     dest[k].right = src[k].right;
   }
@@ -3735,15 +3735,15 @@
   struct text_defn t;
 
   // firstly lets see whether we need an initial column on the left hand side
-  if ((line[0].left != get_left()) && (line[0].left != 0) &&
+  if ((line[0].left != get_left()) && (line[0].right != 0) &&
       (get_left() < line[0].left) && (is_worth_column(get_left(), 
line[0].left))) {
     t.left  = get_left();
     t.right = line[0].left;
     include_into_list(line, &t);
   }
 
-  while ((i<MAX_WORDS_PER_LINE) && (line[i].left != 0)) {
-    if ((i+1<MAX_WORDS_PER_LINE) && (line[i+1].left != 0) && (line[i].right != 
line[i+1].left) &&
+  while ((i<MAX_WORDS_PER_LINE) && (line[i].right != 0)) {
+    if ((i+1<MAX_WORDS_PER_LINE) && (line[i+1].right != 0) && (line[i].right 
!= line[i+1].left) &&
        (is_worth_column(line[i].right, line[i+1].left))) {
       t.left  = line[i].right;
       t.right = line[i+1].left;
@@ -3855,7 +3855,7 @@
   if (abs(last_col[i].left - left_margin_indent) >= gap) {
     found = TRUE;
   }
-  while ((last_col[i].left != 0) && (last_col[i+1].left != 0)) {
+  while ((last_col[i].right != 0) && (last_col[i+1].right != 0)) {
     if (abs(last_col[i+1].left-last_col[i].right) >= gap) {
       found = TRUE;
       i++;
@@ -3878,13 +3878,13 @@
   int j;
 
   i=0;
-  while ((i<MAX_WORDS_PER_LINE) && (a[i].left != 0)) {
+  while ((i<MAX_WORDS_PER_LINE) && (a[i].right != 0)) {
     j=0;
-    while ((j<MAX_WORDS_PER_LINE) && (b[j].left != 0) &&
+    while ((j<MAX_WORDS_PER_LINE) && (b[j].right != 0) &&
           ((b[j].left != a[i].left) || (b[j].right != a[i].right))) {
       j++;
     }
-    if ((j==MAX_WORDS_PER_LINE) || (b[j].left == 0)) {
+    if ((j==MAX_WORDS_PER_LINE) || (b[j].right == 0)) {
       // found a different column - not a subset
       return( FALSE );
     }
@@ -3915,7 +3915,7 @@
     while ((i<no_of_columns) && (col[i].right < g->minh)) {
       i++;
     }
-    if ((col[i].left == g->minh) && (col[i].left != 0)) {
+    if ((col[i].left == g->minh) && (col[i].right != 0)) {
       col[i].is_used++;
     }
     page_contents->words.move_right();
@@ -3976,7 +3976,7 @@
 int html_printer::right_indentation (struct text_defn *last_guess)
 {
   // it assumes that last_guess contains a single column
-  return( (last_guess[0].left > left_margin_indent) );
+  return( (last_guess[0].right > left_margin_indent) );
 }
 
 /*
@@ -4261,7 +4261,11 @@
   if ((header_indent < left_margin_indent) && (header_indent != -1)) {
     return( header_indent );
   } else {
-    return( left_margin_indent );
+    if (margin_on) {
+      return( 0 );
+    } else {
+      return( left_margin_indent );
+    }
   }
 }
 
@@ -4379,7 +4383,7 @@
   if (abs(col[i].left - left_margin_indent) >= gap) {
     found = TRUE;
   }
-  while ((col[i].left != 0) && (col[i+1].left != 0)) {
+  while ((col[i].right != 0) && (col[i+1].right != 0)) {
     if (abs(col[i+1].left-col[i].right) >= gap) {
       found = TRUE;
       i++;
@@ -4566,7 +4570,7 @@
   int n=count_columns(last_guess)-1;
   return( FALSE );
 
-  if ((n>=0) && (last_guess[n].left != 0) && (last_cols[n].left != 0) && 
(next_cols[n].left != 0)) {
+  if ((n>=0) && (last_guess[n].right != 0) && (last_cols[n].right != 0) && 
(next_cols[n].right != 0)) {
     if ((last_cols[n].right != last_guess[n].right) &&
        ((next_cols[n].right == last_guess[n].right) || (next_cols[n].right == 
right_margin_indent))) {
       return( TRUE );
@@ -4999,6 +5003,17 @@
   supress_sub_sup = TRUE;
 }
 
+
+/*
+ *  is_in_table - returns TRUE if we are inside an html table.
+ */
+
+int html_printer::is_in_table (void)
+{
+  return( indentation.no_of_columns != 0 );
+}
+
+
 /*
  *  column_calculate_right_margin - scan through the column and find the right 
most margin
  */
@@ -5091,7 +5106,7 @@
 {
   int i=0;
 
-  while ((line != 0) && ((line[i].left != 0) || (line[i].right != 0)) &&
+  while ((line != 0) && ((line[i].right != 0) || (line[i].right != 0)) &&
         (! ((line[i].left<=t->minh) && (line[i].right>t->minh)))) {
     i++;
   }
@@ -5229,7 +5244,7 @@
   if (! page_contents->words.is_empty()) {
     do {
       i = find_column_index(t);
-      if (indentation.columns[i].left != 0) {
+      if (indentation.columns[i].right != 0) {
        if (debug_table_on) {
          fprintf(stderr, "[%s] in column %d at %d..%d  limit %d\n", 
t->text_string,
                  i, t->minv, t->maxv, indentation.vertical_limit); 
fflush(stderr);
@@ -5602,6 +5617,9 @@
       return( postword );
     } else {
       force_begin_paragraph();
+      if ((! is_in_table()) && (margin_on)) {
+       make_html_indent(left_margin);
+      }
       if (g->minh-left_margin != 0) {
        make_html_indent(g->minh-left_margin);
       }
--- groff-cvs/src/devices/grohtml/ChangeLog     Sat Apr  8 06:36:28 2000
+++ groff-html/src/devices/grohtml/ChangeLog    Fri Apr 28 13:55:04 2000
@@ -1,3 +1,10 @@
+2000-04-28  Gaius Mulley  <address@hidden>
+
+       * html.cc (calculate_margin): calculates the left and right margin
+       irrespective of the boolean margin_on. Fixes a divide by zero
+       bug and a column bug as reported by Steve Blinkhorn <address@hidden>.
+       Improved the behaviour of the -m (margin on) option.
+       
 2000-03-30  Werner LEMBERG  <address@hidden>
 
        * grohtml.man: Document use of whitespace between command line


reply via email to

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