URL: <https://savannah.gnu.org/bugs/?62909>
Summary: Preprocessror problem - Groff with dformat and chem Project: GNU troff Submitter: None Submitted: Thu 18 Aug 2022 04:07:00 AM UTC Category: Preprocessor - others/general Severity: 3 - Normal Item Group: None Status: None Privacy: Public Assigned to: None Open/Closed: Open Discussion Lock: Any Planned Release: None _______________________________________________________ Follow-up Comments: ------------------------------------------------------- Date: Thu 18 Aug 2022 04:07:00 AM UTC By: Anonymous Hello, I am having trouble with chem and dformat preprocessors. I have downloaded dfromat from (https://github.com/arnoldrobbins/dformat). I have an example document that has one section that is a dformat structure, another that has a chem structure. I think that the chem preprocessor processes incorrectly all the lines in the document. It should only process the lines defined in its own block delimited with cstart/cend. But to the contrary, I am seeing that the chem preprocessor removes the whitespaces that are infront of the lines in the whole document, and other filters that depend on these whitespace characters (dformat) can not function properly. Also chem processes comments in the whole document (commensts start with a # and extend to the end of line), but it should only process its own block for comments (delimited with cstart/cend). Below are the problems... Problem 1: Chem strips all the whitespace preceeding the lines in dformat (and maybe all the whitespace of all the lines in the document). It should only do this inside its own block (cstart/cend). When I run cat test.ms | chem > test-chem.tr chem strips all the whitespace in the dformat section. dformat requires whitespace preceeding the format specs. You can check the dformat block in the test.ms file and test-chem.tr file. Problem 2: chem processes all the comments (comments start with a # and continue to the end of line) in the document, not in its own block (cstart/cend) When I run cat test.ms | dformat | chem > test-dformat-chem.tr chem will process all the comments in the whole document. But it should only process comments in its own block (delimited with cstart/cend). If you inspect the test-dformat-chem.tr You will see that the item in dformat that reads "Channel #" is processed to "Channel the line is incorrect. It should have been "Channel #" at BoxB.c with whitespaces infront of it. But chem did strip these too. See and compare test-dformat.tr and test-dformat.chem.tr. Note: The test-dformat.tr has been generated using cat test.ms | dformat > test-dformat.tr I have attached the document (test.ms) and the outputs to the bug report. I could not include the dformat preprocessor. But have mentioned the link to it and am including these below. I am using the preprocessor as such: dformat (shell script) ====================== #!/bin/sh awk -f dformat.awk $* dforamt.awk =========== function error(s) { print("dformat error: " s " near input line " NR) | "cat 1>&2" } BEGIN { s = "recht 0.3 addrht 0.055 recspread 0.15 " s = s "charwid 0.07 textht 0.167 addrdelta 4 " s = s "bitwid 0.125 linedisp 0.04 addr both " s = s "fill off linethrutext 1 " s = s "shaded off" n = split(s, x, FS) for (i = 1; i <= n - 1; i += 2) oparm[x[i]] = parm[x[i]] = x[i + 1] } inlang == 0 { if ($0 !~ /^\.begin[ \t]/ || $2 != "dformat") { print } else { inlang = 1 print ".PS" boxacnt = 0 if (firstpic != 1) { firstpic = 1 print "fillval = 0.1" } } next } /^\.end/ { inlang = 0 print ".PE" next } $1 == "style" { if (! ($2 in parm)) { error("unrecognized name: " $2) } else if ($3 == "reset") { t = oparm[$2] oparm[$2] = parm[$2] parm[$2] = t } else { oparm[$2] = parm[$2] parm[$2] = $3 #error("set shaded to: " $3) } next } $1 == "pic" { $1 = "" print $0 next } /^[^ \t]/ { printf "BoxA: box invis ht %g wid 0", parm["recht"] if (boxacnt++) { printf " with .n at BoxA.s - (0, %g)", parm["recspread"] + maxdy * parm["textht"] } printf "\n" maxdy = sumboxlen = 0 gsub(/[ \t]+$/, "", $0) if ($0 != "noname") { printf " \"%s \" rjust at BoxA.w\n", $0 printf " box invis with .e at BoxA.w ht 0 wid %g\n", parm["charwid"] * (length($0) + 3) } printf " BoxB: box invis ht %g wid 0 at BoxA\n", parm["recht"] next } /./ { boxname = "" if ($1 ~ /:$/) { boxname = substr($1, 1, length($1) - 1) $1 = "" $0 = " " $0 } range = $1 $1 = "" gsub(/^[ \t]+/, "", $0) gsub(/[ \t]+$/, "", $0) text = $0 n = split(range, x, "-") rlo = x[1] rhi = (n >= 2) ? x[2] : rlo cwid = (rhi >= rlo) ? rhi - rlo + 1 : rlo - rhi + 1 rwid = (n >= 3) ? (0 + x[3]) : cwid btype = x[4] if (btype !~ /^(dot|dash|invis)/) { btype = "solid" } textlen = parm["charwid"] * length(text) boxlen = parm["bitwid"] * rwid dy = 0 if (textlen > boxlen) { # set dy, the channel for this text chan[maxdy + 1] = -999 for (dy = 1; chan[dy] + textlen > sumboxlen; dy++); if (dy > maxdy) { maxdy = dy } if (parm["linethrutext"] == 0) { for (k = 1; k <= dy; k++) { chan[k] = sumboxlen + boxlen } } else { chan[dy] = sumboxlen } } sumboxlen += boxlen fill = "" if (parm["fill"] == "on") { fill = " fill " } shaded = "" if (parm["shaded"] != "off") { shaded = " shaded " shaded = shaded "\"" parm["shaded"] "\" " } if (boxname != "") { printf " %s:", boxname } printf " BoxB: box %s %s %s ht %g wid %g with .w at BoxB.e\n", shaded, fill, btype, parm["recht"], boxlen if (dy == 0) { printf " \"%s\" at BoxB.c\n", text } else { if (rwid < 2) { start = "BoxB.s" } else { start = "BoxB.se - (" parm["linedisp"] ",0)" } printf " line from %s down %g\n", start, dy * parm["textht"] printf " \"%s\\|\" at last line .s rjust\n", text printf " box invis with .e at last line .s ht 0 wid %g\n", textlen } if (parm["addr"] ~ /^(left|right|both)$/) { dp = int(parm["addrdelta"]) # Delta Point size if (dp < 0 || dp > 9) { error("bad addrdelta value: " dp) } dah = parm["addrht"] # Delta Addr Height pb = parm["addr"] # Parameter for Bits if (rlo == rhi) { printf " \"\\s-%d%s\\s+%d\" at BoxB.s + (0,%g)\n", dp, rlo, dp, dah } else { if (pb == "left" || pb == "both") { printf "\t\"\\|\\s-%d%s\\s+%d\" ljust at BoxB.sw + (0,%g)\n", dp, rlo, dp, dah } if (pb == "right" || pb == "both") { printf "\t\"\\s-%d%s\\s+%d\\|\" rjust at BoxB.se + (0,%g)\n", dp, rhi, dp, dah } } } } END { if (inlang) { error("eof inside begin/end") } } _______________________________________________________ File Attachments: ------------------------------------------------------- Date: Thu 18 Aug 2022 04:07:00 AM UTC Name: test.ms Size: 1KiB By: None main document and output files. <http://savannah.gnu.org/bugs/download.php?file_id=53575> ------------------------------------------------------- Date: Thu 18 Aug 2022 04:07:00 AM UTC Name: test-chem.tr Size: 4KiB By: None main document and output files. <http://savannah.gnu.org/bugs/download.php?file_id=53576> ------------------------------------------------------- Date: Thu 18 Aug 2022 04:07:00 AM UTC Name: test-dformat.tr Size: 4KiB By: None main document and output files. <http://savannah.gnu.org/bugs/download.php?file_id=53577> ------------------------------------------------------- Date: Thu 18 Aug 2022 04:07:00 AM UTC Name: test-dformat-chem.tr Size: 7KiB By: None main document and output files. <http://savannah.gnu.org/bugs/download.php?file_id=53578> _______________________________________________________ Reply to this item at: <https://savannah.gnu.org/bugs/?62909> _______________________________________________ Message sent via Savannah https://savannah.gnu.org/