[Top][All Lists]

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

Removing *all* occurrences of a set of lines.

From: Daniel Pittman
Subject: Removing *all* occurrences of a set of lines.
Date: Tue, 14 Jan 2003 23:45:41 +1100
User-agent: Gnus/5.090011 (Oort Gnus v0.11) XEmacs/21.5 (brussels sprouts, i686-pc-linux)

I am trying to work out how the 'editfiles' action can be used to
implement a particular operation and having no luck. I figure that
someone here will either tell me how it's done or suggest a better way
of doing it.

To manage /etc/hosts.allow[1], I want to be able to add a delimited
block of settings in the style:

# IMAP start $Revision 1.3$
# IMAP end

The $Revision...$ tag is, of course, updated when the configuration file
is checked out of the RCS repository and, as such, an automatic
indicator that the file has been changed.[2]

What I am having trouble with is working out how to remove *all* the
outdated sections from the file. I use the following code:

         BeginGroupIfNoLineContaining "# IMAP support $Revision: 1.12 $"
            # Remove any old block
            LocateLineMatching   "^# IMAP support.*"
            DeleteToLineMatching "^# IMAP support end.*"
            DeleteNLines "1"            # remove the endpoint line too.
            CatchAbort                  # jump to here on failure
            DeleteLinesStarting "imap:"

            Append "# IMAP support $Revision: 1.12 $"
            Append "imap:"
            Append "imap:"
            Append "# IMAP support end"

That takes care of the first old block in the file, plus any stray perit

Since I managed to screw up the 'LocateLineMatching' statement at first,
though, I ended up with about five revisions worth of the start and end

So, can anyone suggest a better way of implementing this?


[1]  ...and other files, but that's the one I am testing this technique on.

[2]  I kept forgetting to update the manual serial numbers on the
     editfiles sections. This means some excess work, but not much, and
     never too little.

C makes it easy to shoot yourself in the foot.
C++ makes it harder, but when you do, it blows away your whole leg.
        -- Bjarne Stroustrup

reply via email to

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