Post Categories
- Announcements (21)
- Examples (9)
- Software (35)
- C# (5)
- C++ (27)
- Shell scripting (3)
- wxWidgets (1)
- Tutorials (8)
- VHDL (3)
- Websites (7)
- Google Analytics (2)
- HTML/CSS (6)
- Javascript (1)
- MySQL (5)
- PHP (6)
- SEO (2)
- WordPress (1)
-
Recent Posts
STLplus 3.7 Released
This is an update incorporating a number of small changes and bug-fixes. I have also rearranged the IDE project files to be separate from the source code.
See http://stlplus.sourceforge.net/stlplus3/docs/changes.html for more details.
See http://stlplus.sourceforge.net/stlplus3/docs/changes.html for more details.
Posted in Announcements, C++, Software
Comments Off
VHDL for Logic Synthesis – 3rd Edition Due 8 April 2011
John Wiley & Sons are proposing to publish the new, 3rd edition of my book “VHDL for Logic Synthesis” on 8 April this year.
See the Amazon pages for prices and ordering details:
This has been a long time coming. Plans for a third edition were made in June 2009. The idea was to bring the book, now 12 years old, up to date with modern methods and with extensions to the language and libraries added by the VHDL-2008 re-standardisation.
I’m really pleased with the result, despite the long development time from plan to publication. I think this is a significant update which introduces themes like fixed-point and floating-point synthesis using the new packages added in 2008.
The new examples have been tested using Mentor’s ModelSim for simulation, Altera’s Quartus and Xilinx 11 for synthesis. However, the new synthesis packages are also available for Cadence ncvhdl, Synopsys, Synplicity and Leonardo Spectrum so all the examples should work with those tools as well.
For more on this, see the page on my website “VHDL for Logic Synthesis”.
Posted in Announcements, VHDL, VHDL for Logic Synthesis
Leave a comment
Example – Andy Rushton Programming
This website is an example in itself. It uses WordPress as a Content Management System (CMS) so that it can be modified, expanded and updated very easily.
It is hosted on an ISP which provides just the basic LAMP combination – that is, Linux, Apache, MySQL database and PHP scripting. This is the most common and most robust combination on the Web and I recommend it to all customers. It uses the minimum requirements – at the time of writing it was using less than 50MB of disk space for the WordPress install plus the images for the theme and the content, plus a single MySQL database with about 150kB of postings.
The main benefits of using WordPress are:
- WordPress is a Content Management System (CMS) which makes it easy to add pages and manage the menus
- WordPress is also a Blogging System which makes it easy to add postings and categorise them
- I can update online by posting through the Administrative interface
- I can update remotely using Blogging software on my desktop computer, such as Windows Live Writer, BloGTK or QTM
- WordPress emphasises ease of use, so it is much easier for non-programmers to update and modify than just about any other CMS available
- There’s a huge development community contributing themes and plugins to customise the appearance and modify the functionality of a website
- Automatic Search-Engine Optimisation (SEO) added as a plugin
- Automatic backups of posts by email added as a plugin
- Built-in comment-spam blocker added as a plugin
- Integrated Google Analytics added as a plugin
- Automatic merging of my STLplus RSS feed added as a plugin
The visual design is my own, using the convention with WordPress that you start with a standard theme and then customise it by altering the proportions, fonts, colours and graphics. This is easy to do and therefore cheap to the customer. In this case, customisation took only a few hours work, most of which was designing the banner incorporating my logo and then blending-in the colours of the rest of the website.
Posted in Examples, Google Analytics, HTML/CSS, MySQL, PHP, SEO, Websites, WordPress
Leave a comment
Shell scripting tutorials – prefix commands
Prefix commands are a seriously useful concept in shell scripting. These are commands that you put before another command to modify its behaviour. The Bourne shell (sh) and Bash shells (bash) have several prefix commands built in, which I’ll cover briefly, but most of this tutorial is about how to write your own.
Built-in Prefix Commands
Lets say you have a script called backup. You can run this from the shell by simply typing backup or including this command in a script:
$ backup
However, this might hog your system resources. So you can lower the priority of the command by using the nice prefix command:
$ nice backup
This will run the backup command at a lower priority. What’s good about this is that you don’t need to modify your backup script to do this, the nice command can be used to lower the priority of any command.
Prefix commands can have options. The default nice command lowers the priority of its command by 10. However, the -n option can be used to modify that:
$ nice -n 20 backup
This will run at an even lower priority. Alternatively, you can raise the priority of a command, provided you have sufficient privileges to do so (on many Unixy platforms, you cannot raise the priority above 0, which is the default) by using a negative argument:
$ nice -n -10 backup
Other built-in prefix commands that I use regularly are:
time– measure the CPU time used by the commandenv– modify the environment of the command
So, for example, I can set an environment variable needed by my backup script using the env prefix command:
$ env BACKUP_TARGET=$HOME backup
This will set the environment variable BACKUP_TARGET for the duration of the backup command only.
A prefix command returns the exit status of the command so that adding a prefix does not modify the behaviour of a script containing the command. For example nice backup returns the same exit status as backup. This also allows prefix commands to be chained. For example, nice time backup will both lower the priority and measure the CPU time, returning the exit status of the backup command.
Writing Your Own Prefix Commands
A prefix command is just a shell script which takes as its parameters some options followed by another command.
The task of the prefix command script is to:
- parse command-line options
- modify the environment
- run the command
- return the exit status of the command
As an example, I’ll demonstrate how to write a script that pauses for a specified time before running the command. I use this in logon scripts to start maintenance tasks some time after the business of logon has died down.
The objective is to write a command with the following syntax:
usage: sleep-before [ -h ] [ -w <wait> ] <command>
Where the -h options prints out help information and the -w option determines the wait time in seconds before the command is started.
Basic Shell Script
The start of any shell script is to create a file where the filename is the same as the command, in this case sleep-before. There is no extension on a shell script. This file should be created with execute privileges. The easiest way to do this is to create the file with touch (creates an empty file if there is none) and then change its permissions with chmod:
touch sleep-before chmod +x sleep-before
Now edit the file and add the usual shebang starting line:
#!/bin/sh
I tend to specify /bin/sh as the shell where possible, because this is likely to be more portable between OSs than /bin/bash. However, bash has extra functionality and sometimes this just makes scripting much easier, so make your own choice there.
A preliminary stage that I always include when writing scripts is to write a help function that prints out help information either on request or on error. I always prefer to do this as a function so it can be called from anywhere:
function usage()
{
cat >&2 <<-EOF
usage: $0 [ -h ] [ -w <wait> ] <command>
a prefix operator that waits before executing <command>
<command> : the command to execute in the background
-h : this help
-w <wait> : the delay in seconds to wait before (default 0)
EOF
}
This has been implemented as a ‘here doc’, where the text is enclosed between two strings (in this case EOF but it can be anything), piped into the cat command which prints it to standard error.
Parse Command-Line Options
The first stage in the script is to perform command-line parsing. I do this using the getopts shell command:
error=0
wait=0
# process options
while getopts w:h option; do
case $option in
w) wait=$OPTARG ;;
h) usage; exit 0 ;;
\?) error=1 ;;
esac
done
shift $((OPTIND-1))
# check for the existence of a script to run
if [ $# -eq 0 ]; then
echo "$0: a command to run is required" >&2
error=1
fi
# give up on error
if [ $error -gt 0 ]; then
usage
exit 2
fi
See the manual page for details of the getopts command. Basically, this parses the -h and -w options, rejects any other options and stops parsing when it gets to a non-option. The shift operation then discards the processed options, leaving just the command to be executed in the command-line.
The remainder of this code is error checking – there must be at least one argument making up the command and then the script exits if any errors were found in the command-line parsing phase. The exit status is 2 because this is a common convention for ‘incorrect usage’ errors.
Note that the default wait is 0, which is set right at the start of this sequence.
Wait Before Performing Command
The second stage of a prefix command is to modify the environment of the command, in this case by waiting before performing the command itself. This is done using the sleep command:
if [ $wait -gt 0 ]; then
echo -n "sleeping for ${wait}s..."
sleep $wait
echo "done"
fi
The sleep is only performed if the wait option is positive.
Perform the Command
The third stage of the script is to perform the command itself. This is done by executing the remainder of the sleep-before command’s command line now that the options have been discarded:
"$@"
This is a standard bit of boilerplate that turns the command-line arguments ($@) into a command and quotes any arguments that need quoting, either because they contain spaces or other special characters.
Return the Exit Status
In shell scripts, the default exit status is the exit status of the last command in the script. So to meet the prefix command requirement of returning the command’s status, we don’t need to do anything at all, just end the script here.
However, often there is some clean-up script after the command has executed. In that case, the exit status of the command must be stored in a variable and then used in an explicit exit command later:
"$@" status=$? <clean-up commands> exit $status
The $? variable contains the exit status of the last-executed command. It needs to be captured before any other commands are executed which would overwrite the value.
Posted in Shell scripting, Software, Tutorials
Leave a comment
Shell scripting tutorials – best references
Shell scripting is a powerful way of automating tasks. In these tutorials I refer to shell scripting to mean using the Bourne Shell (sh) or Bourne-Again Shell (bash) in a Unix (e.g. Linux) environment.
However, I also use these scripts on Windows using the Cygwin system. This is a Linux-like environment which runs on Windows, allowing Unix-like shell scripting.
There are a lot of websites and blogs on shell scripting, but I’ve found just a few of them particularly useful. So I thought I’d share those with you.
- Bourne Shell Scripting a wiki book by several authors. A good introduction which nevertheless covers pretty well everything yu need to know
- Advanced Bash-Scripting Guide by Mendel Cooper – a comprehensive and thorough guide with a lot that I didn’t know before
- A Shell Programming Primer by Greg Goebel – a short but useful introduction which has been partly incorporated into (1)
The idea of my set of tutorials is to put some of this theory into practice by using some of the scripts that I use as examples.
Posted in Shell scripting, Software, Tutorials
Leave a comment
Example – 1st Policy
1st Policy is a company specialising in buying and selling endowment policies. The visual design is a copy of their old website, but uses standards-compliant website design methods to improve their Search-Engine Optimisation (SEO) results – see for example Google’s guidelines.
This design uses many of the features explained in the Website Features section – it is a dynamic design, using PHP to generate standards-compliant pages in HTML and CSS. The website is customer-editable, so the text on the various pages can be easily edited and uploaded using a Web interface. Transactions are tracked on the website using Google Analytics providing valuable feedback on the effectiveness of the design. The customer requests for valuations of endowment policies are managed by a MySQL database which can then be uploaded to the company’s computers using a bespoke program.
Posted in Examples, Google Analytics, HTML/CSS, MySQL, PHP, SEO, Websites
Leave a comment
Example – IQS Group
This is a work in progress and is not publically available.
IQS Group is an international company trading in futures. This website promotes the company and provides information to their clients. The visual design is new and was designed in collaboration with the IQS Group. It uses standards-compliant website design methods to ensure cross-browser support, future-proofing and to improve their Search-Engine Optimisation (SEO) results – see for example Google’s guidelines.
This design uses many of the features explained in the Website Features section – it is a dynamic design, using PHP to generate standards-compliant pages in HTML and CSS. The website is customer-editable, so the text on the various pages can be easily edited and uploaded using a Web interface. Client records are maintained in a MySQL database which can be updated and seen by the customer and the staff of IQS Group. Due to the nature of the company’s business, security of customer information was a high priority in this design.
Example – David Mossman Photography
David Mossman is a London-based photographer. This website showcases his photography. It uses a mixture of Standard-compliant website design combined with an off-the-shelf Flash image viewer. This combination yields a visually simple but extremely functional design, at little cost to the client because of the use of off-the-shelf components.
This design is a dynamic design using PHP to generate standards-compliant pages in HTML and CSS. The website is customer-editable, so collections of photos can be simply uploaded by the customer to add to the site. The image viewer is in Flash and is called SimpleViewer.
Posted in Examples, HTML/CSS, PHP, Websites
Leave a comment
Example – STLplus Library Collection
STLplus is an open-source collection of C++ classes which I developed to put back in to the Open Source community a small fraction of the vast amount that I have got out of it. It is an extension to the C++ language and is portable between many computer types. It is really a showcase for my programming skills, requiring for its implementation an expertise in C++ that comes from over 15 years of using the language.
Posted in C++, Examples, Software, Websites
Leave a comment
Example – Stewart & Wight
Stewart & Wight is a London-based company investing in property. This website provides information about the company to their clients. The visual design is new and was designed in collaboration with the client. It uses standards-compliant website design methods to ensure cross-browser support, future-proofing and ease of use.
This design uses many of the features explained in the Website Features section. The website is customer-editable, so the text on the various pages can be easily edited and uploaded using a Web interface. Also, complete documents (PDFs, Word documents, Excel Spreadsheets, images etc.) can be uploaded and automatically made available for download by clients.






