Download iconDownload
scald
Laptop LDAP
Fedora Nano
appliance-config
Mac Software

More projects...

Articles...

SRPM...

Patches...
The Oakbud Co.
Home...

scald

Markup language for generating source code

Overview

Scald can assist lazy developers. Scald is a tool to generate program code from an HTML-like XML description. For example, scald will process an XML description into C code that prints an HTML form and saves user input data into a configuration file.

Nasty Details

There are many XSLT processors available to developers. The following examples use xmllint from libxml2 and xsltproc from libxslt. Here is example.xml, an example XML document that follows the scald schema:

<?xml version="1.0"?>

<!DOCTYPE webapp PUBLIC "-//Flyn Computing//DTD Scald XML Unstable//EN"
                           "http://www.flyn.org/xml/dtd/unstable/webapp.dtd">

<webapp name="/cgi-bin/example.cgi" short-name="example" description="Example">

	<form name="example" save-data-as="config" save-to-dir="/tmp/">
		<input name="example-input" type="text" label="Example Input"/>
		<submit value="Save"/>
	</form>

</webapp>

The file example.xml may be validated with the command xmllint --noout example.xml and processed with xsltproc http://www.flyn.org/xml/xslt/unstable/webapp-c.xslt example.xml. The result will be a CGI program written in C that:

  1. Looks for an existing configuration file.
  2. Creates an HTML form.
  3. Populates the form with the existing settings, as read from the configuration file.
  4. Responds to a POST request, reading the new settings from the form and saving them to the configuration file.

The scald schema also allows for dependencies between inputs. For example, the fragment below describes an input, password, that is only enabled if another input, authenticate, is selected. This dependency is enforced by JavaScript code that scald automatically generates.

<input name="authenticate" type="checkbox" label="Use Authentication"/>
<input name="password" type="password" label="Password"
       enabled-by="document.formname.authenticate"/>

The call-print- entites allow one to generate custom HTML at run runtime. The following fragment indicates that options should be generated at runtime by a custom function:

<form name="initialize" save-data-as="config" save-to-dir="/tmp/">
	<select name="device">
		<call-print-options-fn/>
	</select>
</form>

Scald will generate code that expects the function print_document_initialize_device_options() to be defined in a seperate file and linked against the C output that scald generates. Here is a simple implementation of print_document_initialize_device_options():

void print_document_initialize_device_options(char *obj)
{
        printf("<option value=\"foo\">Foo</option>");
	printf("<option value=\"bar\">Bar</option>");
}