1.8. Creating a New Format Driver
The steps are:
- Pick an existing driver to copy.
- Copy it.
- Make the necessary changes.
- Update the sdf.ini file in the bin directory.
Simple, really! :-)
Good drivers to start from are totxt.pl, tohtml.pl and tomif.pl. The drivers can be found in the perllib/sdf directory of the SDF distribution.
The following skills are required to write a format driver:
- Good knowledge of the target format.
- Perl programming.
It also helps if one has a look at SDFAPI before beginning.
An SDF driver interacts with the core SDF system as follows:
- The sdf.ini file configures SDF so that the relevant driver is loaded and called, when necessary.
- Each driver is implemented by a single subroutine which is responsible for initialising itself, processing the input, finalising things and returning the output.
- The input should be processed by:
- calling the SdfNextPara routine within a while loop
- for each paragraph, calling the SdfNextSection routine within a while loop.
If you are considering writing a driver, it might be a good idea to let people on the SDF mailing lists know. If you're lucky, someone else might have started a driver for the same output format or be willing to assist you develop a new one. Likewise, if you're having problems, send email to firstname.lastname@example.org. Chances are, an SDF guru will try to help.
As a rule, it is a good idea to use configuration files to define the mappings from SDF entities to target entities. In this way, people can override the default mappings without changing your driver.
Depending on your skills, the amount of changes you need to make, and your knowledge of SDF, the driver can take anything from 10 minutes to 10 weeks. Good luck. :-)