Script-based Website Maintenance



Tools

GNU m4

GNU m4 is a general-purpose macro processor.

We can use it to produce common or often-repeated sequences of HTML, and each use can be parameterised.

For more information, see GNU m4 - GNU Project - Free Software Foundation (FSF)at http://www.gnu.org/software/m4/m4.html.

m4 attempts to process everything it can as a macro. If you want some literal text to go though m4 without being changed, you have two choices:

  1. Place quotes around words that might be misinterpreted as macros, for example:

    You should not `include' any of your own opinions.
    
    Here are mine:
    
    include(myopins.txt)
    
    Are they interesting?
    

    (include is a built-in m4 macro.)

    GNU m4 can help by prefixing the names of all its built-ins with m4_. Just use the switch -P or --prefix-builtins.

  2. Place quotes around all literal text, then ‘unquote’ macros, for example:

    `You should not include any of your own opinions.
    
    Here are mine:
    
    'include(`myopins.txt')`
    
    Are they interesting?'
    

It is my opinion that the second approach is better, since it means that you don't have to remember which words are dangerous. However, there are other problems – e.g. the line numbers of errors tend to not be helpful – but I don't find them to be terribly difficult.

Patch for m4

I have encountered a problem with the m4 macros substr and translit (and others). There is no way to prevent their results from being expanded. Here is a patch to make them accept an extra argument which is the number of additional pairs of quotes to wrap around the result: m4-1.4.12-quotes-1.diff.bz2

Apply the patch this way:

% ls
m4-1.4.tar.gz  m4-1.4-quotes-2.diff.bz2
% tar xzf m4-1.4.tar.gz
% bunzip2 < m4-1.4-quotes-2.diff.bz2 | patch -p0

Here's an example of substr being used with the extra argument:

% m4
define(`bark',``tree'')dnl
substr(`woodbarkloaf',4,4)
tree
substr(`woodbarkloaf',4,4,1)
bark
substr(`woodbarkloaf',4,4,2)
`bark'

Michael Breen has an alternative solution which doesn't require a patch: String macro problem workaround. It generates one character at a time so that the result cannot be interpreted as a whole macro name. You have to avoid using 1-character macro names to use this method safely, but it may be sufficient in some cases.

HTML Tidy

We can use HTML Tidy as an XML/HTML post-processor. Its use has several benefits:

For more information, see Clean up your Web pages with HTML TIDY at http://www.w3.org/People/Raggett/tidy/.

GNU Make

GNU Make is used to work out the minimum sequence of commands to build one group of files out of another. You give it information about how one file depends on another, and it works out from the files' timestamps whether a rebuild is in order.

Version 3.80 has some additional useful functions.

For more information, see GNU Make - GNU Project - Free Software Foundation (FSF) at http://www.gnu.org/software/make/make.html.

A number of GNU extensions to make are used, so other versions may be unsuitable.

Sed

Sed is a stream editor found on most UNIX systems.

For a GNU version of sed, see - GNU Project - Free Software Foundation (FSF)at http://www.gnu.org/software/sed/sed.html.

Awk

Awk is a programmable stream editor found on most UNIX systems.

For a GNU version of awk, Gawk, see - GNU Project - Free Software Foundation (FSF)at http://www.gnu.org/software/gawk/gawk.html.



Updated: 2011-Dec-20 13:19 GMT
Contact Steven Simpson

Ĉi tiu paĝo disponeblas ĉi-lingve, laŭ via krozila agordo.