groff
[Top][All Lists]
Advanced

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

Re: [Groff] Writing in gray with groff... possible?


From: baruchel
Subject: Re: [Groff] Writing in gray with groff... possible?
Date: Sun, 6 Aug 2000 00:22:23 +0200
User-agent: Mutt/1.2.5i

Brest, le dimanche 6 août
On Sat, Jun 24, 2000 at 05:38:44PM +0100, Ted Harding wrote:

> There is no provision at present in tbl for cell-background-filling, so
> you would have to fake it.
> 
I wrote this very ugly code to do the stuff:
('til now, it works only with the 'allbox' option)

just the line before .TS, put
\!meta-tbl: fill x y n

which means fill the cell x y with an intensity of n (for the gray)

for instance this file:
======================
Hello
\!meta-tbl: fill 3 2 240
.TS
center tab(&) allbox;
c c c c.
dog&cat&duck&mouse
tree&flower&plant&rose
.TE
======================
could be preprocess like this:
meta-tbl file | grops > output.ps

The result would be a table with the cell (3,2) filled
It is just a beginning, since I think about writing a huge processor in C to
handle several meta-tbl operations:
  - filling one or several cells
  - filling a whole line (or column)
  - etc.

Here is the code:
================
#!/bin/sh
export FILE="$1"
export TROFF_COMMAND=troff

# parse the file to see if the meta-tbl command is always followed by .TS
export RESULT=`awk 'BEGIN {m = 0}
     {
       if ((m == 1) && ($1 != ".TS")) {
         print 0
       }
       if ($1 == "\\!meta-tbl:") {
         m = 1
       }
       if ($1 == ".TS") {
         m = 0
       }
     }
     END { print 1 }' $FILE`
case $RESULT in
  "1") ;;
  *) { echo "Syntax error in $FILE";
       exit ; };;
esac

# troff output
tbl $FILE | $TROFF_COMMAND > /tmp/troff_output
awk '
  BEGIN {
          m = 0
          e = 0
        }
  { if ($1 == "meta-tbl:") {
      m = 1
      e = 0
    }
    if ((m == 1) && ($1 == "Dl") && ($2 == 0) && ($3 < 0)) {
      e = 6
    }
    if (e > 1) {
      e = e -1
    }
    if ((e == 1) && (($1 != "Dl") || ($2 != "0") || ($3 > -1))) {
      m = 0
    }
    if (m == 1) {
      print $0
    }
  }' /tmp/troff_output | sed -e "s/^meta-tbl:/*meta-tbl:/
                                     s/^V/*V /
                                     s/^H/*H /
                                     s/^Dl/*Dl /
                                     /^[^\*]/d" | awk '
BEGIN { line = 0
        col = 0
        l = 0
        c = 0
      }
     { if ($1 == "*V") {
         l = $2
       }
       if ($1 == "*H") {
         c = $2
       }
       if ($1 == "*meta-tbl:") {
         line = 0
         col = 0
         l = 0
         c = 0
         print $0
       }
       if (($1 == "*Dl") && ($3 == 0)){
         line = line + 1
         $0 = $0 " l " line " " l
         print $0
       }
       if (($1 == "*Dl") && ($2 == 0)){
         col = col + 1
         $0 = $0 " c " col " " c
         print $0
       }
     }' > /tmp/meta-tbl.tmp
awk 'BEGIN {
             m = 0
             l = 0
           }
  { if (($1 == "*meta-tbl:") && ( m > 0)) {
      m = m +1
      t = l
      for (i = 1; i <= l; i++) {
        if (index(a[i],"Dl  0") == 0) {
          t--
          print a[i]
        }
        else {
          split(a[i],b," ")
          if (b[5] == 1) {
            print b[1] " " b[2] " " b[3] " " b[4] " " t " " b[6]
          }
          if (b[5] == 2) {
            print b[1] " " b[2] " " b[3] " " b[4] " 1 " b[6]
          }
          if (b[5] > 2) {
            print b[1] " " b[2] " " b[3] " " b[4] " " (-(b[5]-t)+2) " " b[6]
          }
          
        }
      }
      print "==="
      print $0
      l = 0
    }
    if ($1 != "*meta-tbl:") {
      l = l + 1
      a[l] = $0
    }
    if (($1 == "*meta-tbl:") && (m == 0)) {
      m = 1
      print $0
    }
  }
  END {
      t = l
      for (i = 1; i <= l; i++) {
        if (index(a[i],"Dl  0 ") == 0) {
          t--
          print a[i]
        }
        else {
          split(a[i],b," ")
          if (b[5] == 1) {
            print b[1] " " b[2] " " b[3] " " b[4] " " t " " b[6]
          }
          if (b[5] == 2) {
            print b[1] " " b[2] " " b[3] " " b[4] " 1 " b[6]
          }
          if (b[5] > 2) {
            print b[1] " " b[2] " " b[3] " " b[4] " " (-(b[5]-t)+2) " " b[6]
          }
          
        }
      }
    print "==="
  }' /tmp/meta-tbl.tmp > /tmp/meta-tbl.2.tmp
awk 'BEGIN { nn = 0 }
     { if ($1 == "*meta-tbl:") {
         m = $0
         i = 0
         j = 0
       }
       if (index($0,"0 l") > 0) {
         i++
         l[i] = $0
       }
       if (index ($0,"Dl 0 ") > 0) {
         split($0,k," ")
         j++
         c[k[5]] = $0
       }
       if ($1 == "===") {
         nn++
         split(m,k," ")
         if (k[2]=="fill") {
           x = k[3]
           y = k[4]
           x1 = c[x]
           x2 = c[x+1]
           y1 = l[y]
           y2 = l[y+1]
           split(x1,xx1," ")
           split(x2,xx2," ")
           split(y1,yy1," ")
           split(y2,yy2," ")
           rr = "V" yy1[6] "\n" "H" xx1[6] "\n"
           larg = xx2[6] - xx1[6]
           haut = yy2[6] - yy1[6]
           r = rr "DP " larg " " 0 " " 0 " " haut " -" larg " " 0 " " 0 " -" 
haut
           rr = "Df " k[5] " 0\n" r "\nDf 0 0"
           print rr > "/tmp/meta-tbl." nn
         }
       }
     }' /tmp/meta-tbl.2.tmp
awk 'BEGIN {nn = 0}
     { if ($1 == "meta-tbl:")
         { nn++
           system("cat /tmp/meta-tbl." nn) }
       else print $0 }' /tmp/troff_output

reply via email to

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