bug-groff
[Top][All Lists]
Advanced

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

[bug #62909] [chem] does not restrict whitespace/comment changes to its


From: Riza Dindir
Subject: [bug #62909] [chem] does not restrict whitespace/comment changes to its own regions
Date: Tue, 23 Aug 2022 00:38:56 -0400 (EDT)

Follow-up Comment #6, bug #62909 (project groff):

I did not test this script thoroughly. It is a simple script that only
processes the chem sections (cstart/cend).

I share it here. The script has been written by myself and is not being used
on other projects.

The tabs have been removed (after I viewed it in the preview). Hope that is
not a problem.

The license should be GNU general public license.

The file is below

======================================================================================

# This awk script is a non-aggressive chem tool.
# Author: Riza Dindir
# License: The GNU General Public License applies
(<https://www.gnu.org/licenses/>)

# Resets the file by emptying its contents.
function resetFile(fn) {
        cmd = "cat /dev/null > " fn;
        print cmd | "/bin/sh";
}

# Appends line to the file with name "fn".
function appendFile(fn, line) {
        cmd = "echo \"" line "\" >> " fn;
        print cmd | "/bin/sh";
}

# Cleans the line by converting " to \".
function cleanLine(line) {
        gsub(/"/, "\\\"", line);
}

# Runs the chem tool with the given file name.
function runChem(fn) {
        system("chem " fn);
}

BEGIN {
        inchem = 0;
        fn = "~/tmp/chem.tr";
        resetFile(fn);
}

inchem == 0 && /^\.cstart/ {
        line = $0;
        cleanLine(line);
        appendFile(fn, line);
        inchem = 1;
        next;
}

inchem == 1 && /^\.cstart/ {
        print "You can not start another chem region when inside one.";
        exit 1;
}

inchem == 0 && /^\.cend/ {
        print "You can not end chem region when you are not in one.";
        exit 1;
}

inchem == 1 && /^\.cend/ {
        line = $0;
        cleanLine(line);
        appendFile(fn, line);
        runChem(fn);
        resetFile(fn);
        inchem = 0;
        next;
}

inchem == 1 {
        line = $0;
        cleanLine(line);
        appendFile(fn, line);
        next;
}

{ print $0; }

END {}




    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?62909>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/




reply via email to

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