home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / text / frame / 2720 < prev    next >
Encoding:
Text File  |  1992-08-29  |  9.8 KB  |  380 lines

  1. Newsgroups: comp.text.frame
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!hp-col!hplsdrn
  3. From: bae@hplsdrn.col.hp.com (Bruce Erickson)
  4. Subject: List information about paragraphs
  5. Message-ID: <1992Aug28.195011.7007@col.hp.com>
  6. Sender: bnr@hplsdrn.col.hp.com
  7. Date: Fri, 28 Aug 1992 20:44:20 GMT
  8. Organization: Hewlett-Packard Logic Systems Operation
  9. Lines: 369
  10.  
  11. A while ago I posted a note asking if there was a quick way to get
  12. a table of information about paragraphs -- font names, point sizes,
  13. etc.  All responses were of the form "convert to MIF and write an
  14. [awk, sed, ....] script".  Many added "...and when you have done that,
  15. let me know!"
  16.  
  17. Well, here it is.  It only scans for paragraph formats, not for any
  18. changes to the default paragraph formats actually in the text.
  19.  
  20. Not clean code, but gives output like this:
  21.  
  22.           font       var      weight   angle    size     lead    nexttag   
  23. al0_in0   Helvetica  Regular  Regular  Regular  10.0_pt  2.0_pt  body_in1  
  24. al0_in1   Helvetica  Regular  Regular  Regular  10.0_pt  2.0_pt  al0_in1   
  25. bl_in0    Helvetica  Regular  Regular  Regular  10.0_pt  2.0_pt  body_in1  
  26. bl_in1    Helvetica  Regular  Regular  Regular  10.0_pt  2.0_pt  body_in2  
  27. Body      Times      Regular  Regular  Regular  9.0_pt   2.0_pt  none      
  28. body_in0  Helvetica  Regular  Regular  Regular  10.0_pt  2.0_pt  body_in   
  29. body_in1  Helvetica  Regular  Regular  Regular  10.0_pt  0.0_pt  body_in1  
  30. body_in2  Helvetica  Regular  Regular  Regular  10.0_pt  2.0_pt  body_in2  
  31. body_in3  Helvetica  Regular  Regular  Regular  10.0_pt  2.0_pt  body_in3  
  32. Comment   Times      Regular  Regular  Regular  9.0_pt   2.0_pt  none      
  33. Figure    Times      Regular  Regular  Regular  12.0_pt  2.0_pt  none      
  34. h1        Times      Regular  Bold     Regular  12.0_pt  2.0_pt  body_in0  
  35. h2        Times      Regular  Regular  Regular  12.0_pt  2.0_pt  body_in0  
  36. h3        Times      Regular  Regular  Regular  12.0_pt  2.0_pt  body_in0  
  37. h4        Times      Regular  Regular  Regular  12.0_pt  2.0_pt  body_in0  
  38. vl0_in0   Helvetica  Regular  Regular  Regular  10.0_pt  2.0_pt  body_in1  
  39. vl_in0    Helvetica  Regular  Regular  Regular  10.0_pt  2.0_pt  body_in1  
  40. vl_in1    Helvetica  Regular  Regular  Regular  10.0_pt  0.0_pt  body_in2  
  41. vl_in2    Helvetica  Regular  Regular  Regular  10.0_pt  2.0_pt  body_in3  
  42.  
  43. The code consists of three shell scripts (sorry non UNIX users!):
  44.     -parasumm, the outer script
  45.     -awkgen, which is a generic script I use to create awk scripts....
  46.     -awkrep, another generic script I use to convert labled data to tables..
  47.  
  48.                   - Bruce Erickson
  49.                      Hewlett Packard
  50.                      bae@col.hp.com
  51.  
  52.  
  53. # This is a shell archive.  Remove anything before this line,
  54. # then unpack it by saving it in a file and typing "sh file".
  55. #
  56. # Wrapped by Bruce Erickson <bae@hplsdrn> on Fri Aug 28 13:47:04 1992
  57. #
  58. # This archive contains:
  59. #    parasumm    awkgen        awkrep        
  60. #
  61.  
  62. LANG=""; export LANG
  63. PATH=/bin:/usr/bin:$PATH; export PATH
  64.  
  65. echo x - parasumm
  66. cat >parasumm <<'@EOF'
  67. #!/bin/ksh
  68. #    ex:se ts=3 sw=3:
  69. usage="usage: parasumm <MIF file>"
  70. #
  71. #
  72.  
  73. FMDIR=/site/frame/bin
  74. #    Set up the PATH variable
  75. PATH=/bin:/usr/bin:$FMDIR:.
  76. SHELL=/bin/ksh
  77.  
  78.  
  79. set -- `getopt "" "$@"`
  80. if [ $? -ne 0 ]
  81. then
  82.     echo "$usage" >&2
  83.     exit 1
  84. fi
  85.  
  86. while [ $# -gt 0 ]
  87. do
  88.     case $1 in
  89.         --)    shift; break;;
  90.         -*)    echo "$usage" >&2; exit 1;;
  91.     esac
  92. done
  93.  
  94. if [ $# -ne 1 ]
  95. then
  96.     echo "$usage" >&2
  97.     exit 1
  98. fi
  99.  
  100. framefile=$1
  101. tmpawk1=/usr/tmp/psawk_$$
  102. tmpawk2=/usr/tmp/psawk2_$$
  103.  
  104. trap "rm -f $tmpawk1 $tmpawk2; trap '' 0 1 2 3 4; exit" 0 1 2 3 4
  105.  
  106. if [ ${framefile%.mif} = $framefile ]
  107. then
  108.     miffile=${framefile#.*}.mif
  109.     # Must obtain .MIF file
  110.     fmbatch <<-EOF
  111.         Open $framefile
  112.         SaveAs mif $framefile $miffile
  113.         Quit
  114.     EOF
  115. else
  116.     # Passed in the .mif file -- a timesaver!
  117.     miffile=$framefile
  118. fi
  119.  
  120. #    Read in PgfCatalog; create info based on PgfTag
  121. #    When we get to a Paragraph which uses PgfTag xx, look for
  122. #    overrides of font (etc).
  123.  
  124. # remember: any $, ', or ` to be passed in must be escaped so the shell doesn't intrepret it!
  125. awkgen > $tmpawk1 <<-EOF
  126.     <PgfTag
  127.     tag
  128.                 /<PgfTag/ { s=index(\$0, "\`")+1; l=length(\$0)-s-1; tag = substr(\$0, s, l) }
  129.     font
  130.                 /<FFamily/ { s=index(\$0, "\`")+1; l=length(\$0)-s-1; font = substr(\$0, s, l) } 
  131.     var
  132.                 /<FVar/ { s=index(\$0, "\`")+1; l=length(\$0)-s-1; var = substr(\$0, s, l) }
  133.     weight
  134.                 /<FWeight/ { s=index(\$0, "\`")+1; l=length(\$0)-s-1; weight = substr(\$0, s, l) }
  135.     angle
  136.                 /<FAngle/ { s=index(\$0, "\`")+1; l=length(\$0)-s-1; angle = substr(\$0, s, l) }
  137.     size
  138.                 /<FSize/ { t = \$2 "_" \$3; size = substr(t, 1, length(t) - 1)}
  139.     lead
  140.                 /<PgfLeading/ { t = \$2 "_" \$3; lead = substr(t, 1, length(t) - 1)}
  141.     InSeRt    
  142.                 /<PgfUseNextTag/    { if (\$2 == "Yes") { nexttag = 1 } else { nexttag = 0 }}
  143.     nexttag
  144.                 /<PgfNextTag/ { if (nexttag) {s=index(\$0, "\`")+1; l=length(\$0)-s-1; nexttag = substr(\$0, s, l)} else { nexttag = "none" }}
  145. EOF
  146.     #cat $tmpawk1
  147.  
  148. sed -e '1,/^<PgfCatalog/ d' -e '/^>/,$ d' < $miffile |
  149.     awk -f $tmpawk1 > $tmpawk2
  150.  
  151. awkrep $tmpawk2
  152. @EOF
  153.  
  154. chmod 775 parasumm
  155.  
  156. echo x - awkgen
  157. cat >awkgen <<'@EOF'
  158. #!/bin/ksh
  159. #    ex:se ts=3 sw=3:
  160. usage="usage: "
  161. #
  162. #    Generate an awk file which will:
  163. #        create a file which is of the form 'aentry' 'elname' 'elvalue' ['elname' 'elvalue' ....]
  164. #    this essentially can be used to create a series of arrays:
  165. #        elname1[aentry] = elvalue1; elname2[aentry] = elvalue2.... or
  166. #        array[aentry, elname1] = elvalue1; array[aentry, elname2] = elvalue2, .....
  167. #
  168. #    This reads stdin to create the awk file:
  169. #        line  1 defines a pattern which is the start of 'aentry'.
  170. #        line 2,3 defines a pattern and an action to define 'aentry' -- it must occur prior to any elements
  171. #                aentryname '/<pattern>/ { aentryname = value }
  172. #    
  173. #    The rest of the lines define patterns and actions which define 'elname' and 'elvalue' as:
  174. #            'elname /<pattern>/ { elname = value }'
  175. #
  176. #        if $1 is 'InSeRt', then the rest of the line s a string which will be inserted into the awk
  177. #        script prior to any automatically generated statements.
  178.  
  179. #    This emits the awk file to stdout...
  180.  
  181. #    Set up the PATH variable
  182. PATH=/bin:/usr/bin:
  183. SHELL=/bin/ksh
  184.  
  185. # Cannot call getopt!
  186.  
  187. if [ $# -ne 0 ]
  188. then
  189.     echo "$usage" >&2
  190.     exit 1
  191. fi
  192.  
  193.     awk    '    
  194.                 NR == 1    {    startptn = $0 ; next }
  195.                 NR == 2    {    aentryname = $0; next }
  196.                 NR == 3    {    aentryawk = $0; next 
  197.                                 printf "BEGIN  {  %s = \"\"; }\n", aentryname
  198.                             }
  199.  
  200.                 /InSeRt/    {    getline
  201.                                 print $0; next
  202.                             }
  203.  
  204.                             {    numparts++
  205.                                 partname[numparts] = $0
  206.                                 getline
  207.                                 partawk[numparts] = $0
  208.                                 #printf "partname = @%s@, awk = @%s@\n", partname[numparts], partawk[numparts]
  209.                             }
  210.  
  211.                 END        {    
  212.                                 
  213.                                 # Found start pattern -- emit previous information if any
  214.                                 printf "/%s/    { if (%s !~ /^$/)\n", startptn, aentryname
  215.                                 printf "        {\n"
  216.                                 printf "            printf \"%%s \", %s\n", aentryname
  217.                                 for (p = 1; p <= numparts; p++)
  218.                                 {
  219.                                     printf "            printf \"%s %%s \", %s\n", partname[p], partname[p]
  220.                                 }
  221.                                 printf "            printf \"\\n\"\n        }\n"
  222.  
  223.                                 printf "    }\n"
  224.  
  225.                                 printf "%s\n", aentryawk
  226.  
  227.                                 for (p = 1; p <= numparts; p++)
  228.                                 {
  229.                                     printf "%s\n", partawk[p]
  230.                                 }
  231.  
  232.                                 printf "\n"
  233.                                 printf "END    {\n"
  234.                                 printf "    { if (%s !~ /^$/)\n", aentryname
  235.                                 printf "        {\n"
  236.                                 printf "            printf \"%%s \", %s\n", aentryname
  237.                                 for (p = 1; p <= numparts; p++)
  238.                                 {
  239.                                     printf "            printf \"%s %%s \", %s\n", partname[p], partname[p]
  240.                                 }
  241.                                 printf "            printf \"\\n\"\n        }\n"
  242.                                 printf "    }\n}"
  243.  
  244.                             }
  245.             '
  246. exit
  247. @EOF
  248.  
  249. chmod 775 awkgen
  250.  
  251. echo x - awkrep
  252. cat >awkrep <<'@EOF'
  253. #!/bin/ksh
  254. #    ex:se ts=3 sw=3:
  255. usage="usage: awkrep <file>"
  256. #
  257. #    <file> is of the form:
  258. #    <tag> <label1> <value1> [<label2> <value2> ..]
  259. #    Converts to a table of output...
  260. #    
  261. #
  262.  
  263. #    Set up the PATH variable
  264. PATH=/bin:/usr/bin:
  265. SHELL=/bin/ksh
  266.  
  267. set -- `getopt "" "$@"`
  268. if [ $? -ne 0 ]
  269. then
  270.     echo "$usage" >&2
  271.     exit 1
  272. fi
  273.  
  274. while [ $# -gt 0 ]
  275. do
  276.     case $1 in
  277.         --)    shift; break;;
  278.         -*)    echo "$usage" >&2; exit 1;;
  279.     esac
  280. done
  281.  
  282. if [ $# -ne 1 ]
  283. then
  284.     echo "$usage" >&2
  285.     exit 1
  286. fi
  287.  
  288. infile=$1
  289.  
  290. (
  291.     #    Pass 1: get list of all labels and their max width...
  292.     #    This emits a line which is of the form:
  293.     #    <label> <width> [<label> <width> ....
  294.     awk '    BEGIN    {    numlabels = 1 }
  295.  
  296.             {    for (label = 2; label <= NF; label = label + 2)
  297.                 {
  298.                     if (labels[$label] == "" )
  299.                     {
  300.                         labels[$label] = $label
  301.                         # New label!
  302.                         labellist[numlabels] = $label
  303.                         # printf "label %s is %d\n", $label, numlabels
  304.                         numlabels++
  305.                         width = length($label)
  306.                         widths[$label] = width
  307.                     }
  308.                     
  309.                     value = label + 1
  310.                     width = length($value)
  311.                     if (widths[$label] < width)
  312.                         widths[$label] = width
  313.                 }
  314.  
  315.                 if (length($1) > tagwidth)
  316.                     tagwidth = length($1)
  317.             }
  318.  
  319.         END    {    printf "%d ", tagwidth
  320.                     for (l = 1; l < numlabels; l++)
  321.                     {
  322.                         printf "%s %d ", labellist[l], widths[labellist[l]]
  323.                     }
  324.                     printf "\n"
  325.  
  326.                 }' < $infile
  327.     cat $infile
  328. ) |
  329.     awk '
  330.         NR == 1    {    # list of labels & widths, in order
  331.                         tagwidth = $1
  332.                         numlabels = 0
  333.                         for (l = 2; l <= NF; l = l + 2)
  334.                         {
  335.                             numlabels = numlabels + 1
  336.                             label2order[$l] = numlabels
  337.                             labellist[numlabels] = $l
  338.                             m = l + 1
  339.                             width[numlabels] = $m
  340.                         }
  341.  
  342.                         # Print heading
  343.                         printf "%-*s  ", tagwidth, ""
  344.                         for (l = 1; l <= numlabels; l++)
  345.                         {
  346.                             printf "%-*s  ", width[l], labellist[l]
  347.                         }
  348.                         printf "\n"
  349.                         next
  350.                     }
  351.  
  352.                     {    # Input line!  
  353.                         leader = $1
  354.  
  355.                         for (a = 1; a <= numlabels; a++)
  356.                             args[a] = ""
  357.                         
  358.                         for (b = 2; b <= NF; b++)
  359.                         {
  360.                             valn = b + 1
  361.                             value = $valn
  362.                             lnum = label2order[$b]    # Which label?
  363.                             args[lnum] = value
  364.                         }
  365.  
  366.                         # Print out line
  367.                         printf "%-*s  ", tagwidth, $1
  368.                         for (l = 1; l <= numlabels; l++)
  369.                         {
  370.                             printf "%-*s  ", width[l], args[l]
  371.                         }
  372.                         printf "\n"
  373.                     }'
  374.  
  375. @EOF
  376.  
  377. chmod 775 awkrep
  378.  
  379. exit 0
  380.