Overview of the program and main()

Previous: wftk core index ] [ Top: wftk core index ] [ Next: In-memory XML data structures and functionality ]

The structure of the program file is the same as any single-file C program: #include directives, followed by declarations, followed by the main program. A literate presentation is

So let's go ahead and define our #includes, shall we?
 
#include <stdio.h>
#include <malloc.h>
#include <stdarg.h>
#include <string.h>
#include "xmlparse.h"
#include "localdefs.h"
void output (char type, const char *format, ...);
The localdefs.h file contains whatever local definitions a particular wftk installation needs: particularly the locations of the process definition repository and the datasheet repository (remember that in this version both of these are simply directories in the local filesystem, but that later we'll have much more flexible options for both locations.) Next we define all our data structures and helper functions. XML and expat are rather core to this. Under the rubric of "XML" we'll define our central XML data structures and the functions we'll use to work with them. The use of the expat parser to parse XML text into these structures will be in a separate section because it's not trivial.
 
See In-memory XML data structures and functionality
See xml_read: Using expat to parse XML files into memory
Next up, let's look at how we will read our command input, and how we'll create our output. Commands will be read from the command line or from a command stream and placed into a linked list of command objects. This will enhance the usability of this code in other projects, I hope. It'll also make it easy to write a different parsing front end for the interpreter.
 
See The command stack and how to load it
See Our oh-so-complex output stream
Now we're getting close to the main program: let's define our globals.
 
See Global variables: state
All the underpinnings out of the way, now we can look at the command interpreter. The interpreter is broken into two parts -- really two interpreters. The entire process is driven by the command stack, but the commands on that stack drive the real work of interpretation, which is doing whatever the procdef tells us to do. Execution state is contained in the datasheet, so that it can be reloaded between runs. (Thus the datasheet represents persistent storage implemented via XML -- lots of buzzwords in that!)
 
See Interpreting the process definition
See Interpreting command streams
And hey! Just as you were losing hope, there's some code in this item after all! Not much, granted, but all it has to do is to read the command from the command line, use that to initialize the command stack, and then call the interpreter on the command stack.
 
int main(int argc, char * argv[])
{
   See Initializing global variables from the command line

   interpret (command_stack);

   xml_free (datasheet);
   xml_free (procdef);
   return 0;
}


Print usage description
Here is as good a place as any to define the text we'll print if the command line doesn't suit us. There's not much that will offend us, I'm sure.
 
printf ("usage: wftk <command> <arguments>\n");
printf ("  Commands:\n");
printf ("  start <process id> <procdef>\n");
printf ("  activate <process id> <locator> <task id>\n");
printf ("  complete <process id> <task id>\n");
printf ("  reject <process id> <task id>\n");
printf ("  setvalue <process id> <name> <type> <file> or value on stdin\n");
printf ("  settaskvalue <process id> <task id> <name> <type> <file> or value on stdin\n");
printf ("  script <process id> <file> or command list on stdin\n");
Previous: wftk core index ] [ Top: wftk core index ] [ Next: In-memory XML data structures and functionality ]


This code and documentation are released under the terms of the GNU license. They are additionally copyright (c) 2000, Vivtek. All rights reserved except those explicitly granted under the terms of the GNU license.