Subject: a2p: problems and solution for translating `chem.awk' Package: perl Version: 5.8.8-6.1 Severity: normal
*** Please type your report below this line *** This mail describes how to make running `chem.awk' in Perl. Some problems of `a2p' are discussed. `chem' was written by Brian Kernighan: http://cm.bell-labs.com/cm/cs/who/bwk/index.html The `chem' source is available at: http://cm.bell-labs.com/netlib/typesetting/chem.gz To this mail, I appended a `tar' file about `chem'. It contains the `awk' version of `chem' with a slight correction and some Perl versions translated with a2p. Its file structure is: awk/ # subdirectory with the original `awk' source awk/chem # shell script that runs `chem' awk/chem.awk # `awk' file of `chem' awk/chem.macros # macro file that is loaded by the output of `chem.awk' awk/README # README file of Brian Kernighan example/ # subdirecteory with 3 example files of Kernighan perl/ # subdirectory for the `a2p' generated Perl versions perl/0.0 # translation of `a2p' with output errors, does not work perl/0.1 # corrected version of generated Perl file, working perl/0.2 # working version with activated warnings You can run `chem' in the directories `akw/' of `perl/0.*/' by the command ./chem files to get its `pic' output and by ./chem files | groffer to view the output in graphical mode. `files' is either one or several of the example files or empty for standard input. ########## 1st error at call of `a2p' When one tries to run `a2p' on `chem.awk', an error occurs: $ a2p awk/chem.awk Search pattern not terminated: $1 == "size" { if ($NF <= 4) size = $NF; else size = $NF/10 `a2p' cannot read the division slash. That's a bug in `a2p' that should be easy to fix. The error can be avoided by replacing the division slash by a multiplication. The following `diff' fixes this. $ diff -u chem.awk.orig chem.awk --- chem.awk.orig 2006-10-14 18:33:37.000000000 +0200 +++ chem.awk 2006-10-15 12:36:38.000000000 +0200 @@ -51,7 +51,7 @@ $1 == "textht" { textht = $NF; next } $1 == "cwid" { cwid = $NF; next } $1 == "db" { db = $NF; next } -$1 == "size" { if ($NF <= 4) size = $NF; else size = $NF/10 +$1 == "size" { if ($NF <= 4) size = $NF; else size = $NF*0.1 setparams(size); next } You find a corrected `chem.awk' in `perl/0.0/'. After this correction, `a2p' works on `chem.awk', the result is stored in the file `perl/0.0/chem.pl'. But this result produces wrong output and wrong graphs when compared to the `awk' original. ########## error correction in `perl/0.1/' It's easy to correct the errors in the `a2p' translation `perl/0.0/'. There are 3 errors, all arise from wrongly created `$_'. You should think about fixing this in `a2p' as well. The following is a diff to do the correction. ##### --- 0.0/chem.pl 2006-10-15 13:38:42.000000000 +0200 +++ 0.1/chem.pl 2006-10-16 18:38:19.000000000 +0200 @@ -248,7 +248,7 @@ &labsave($lastname, $Last, $dir); } if ($goes) { - $_ = $goes; + @Fld = ($goes); &molecule(); } } @@ -308,9 +308,8 @@ } $n =~ s/[^A-Za-z0-9]//g;# for stuff like C(OH3): zap non-alnum if ($Fld[2] eq '') { - printf "Last: %s: %s with .%s at Last.%s\n", $n, $_, &leave($type, - - $dir + 180), &leave($Last, $dir); + printf "Last: %s: %s with .%s at Last.%s\n", + $n, join($,, @Fld), &leave($type, $dir + 180), &leave($Last, $dir); } elsif ($Fld[2] eq 'below') { printf "Last: %s: %s with .n at %s.s\n", $n, $Fld[1], $Fld[3]; @@ -329,7 +328,7 @@ $dew; } else { - printf "Last: %s: %s\n", $n, $_; + printf "Last: %s: %s\n", $n, join($,, @Fld); } $Last = $type; if ($lastname ne '') { ##### You can find the corrected version in `perl/0.1/'. This `chem.pl' generates correct output, equivalent to the `awk' version, such that the graphs are right. But the error messages are suppressed because no warnings are active. ########## correction with warnings in `perl/0.2/' Running a Perl program without warnings is not good at all. But I'm not sure if you want to change this. In `perl/0.2/' you find a corrected version of `chem.pl' that has `-w' activated and performs correct output without error messages. I do not display a diff of this version. By `-w' or `use warnings;' the warnings are activated. This produces a lot of error messages. The following actions remove these error reports: - `Name "..." used only once: possible typo': Comment the lines of these only once used variables out. - `Undefined value assigned to typeglob': Remove function `set()' and replace its use by a setting of a hash `%dc'. - `Use of uninitialized value in ...': Add some test for each uninitialized variable. Good look for `a2p' Bernd Warken -- System Information: Debian Release: testing/unstable APT prefers testing APT policy: (500, 'testing'), (500, 'stable') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.6.17-2-k7 Locale: [EMAIL PROTECTED], [EMAIL PROTECTED] (charmap=ISO-8859-15) Versions of packages perl depends on: ii libc6 2.3.6.ds1-4 GNU C Library: Shared libraries ii libdb4.4 4.4.20-8 Berkeley v4.4 Database Libraries [ ii libgdbm3 1.8.3-3 GNU dbm database routines (runtime ii perl-base 5.8.8-6.1 The Pathologically Eclectic Rubbis ii perl-modules 5.8.8-6.1 Core Perl modules Versions of packages perl recommends: ii perl-doc 5.8.8-6.1 Perl documentation -- no debconf information _____________________________________________________________________ Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! http://smartsurfer.web.de/?mc=100071&distributionid=000000000066 -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]