starter: Displaying a process start form

Previous: list: Displaying the procdef directory ] [ Top: The procdef manager ] [ Next: datasheet: Generating a blank datasheet ]

The start form generator is pretty straightforward. Given a procdef identifier, we load the procdef item file first and find the current version of the definition. Then we load that definition and get some pertinent information, mostly the data items it needs to get started, but also a title. We return our data on stdout in line-based format; the first line is the title of the process, the second is the current version, and each subsequent line is a data item, formatted as a table row.
 
if (argc < 3) {
   printf ("Missing procdef identifier in starter command.\n");
   return (1);
}
sprintf (sbuf, "%s%s.xml", PROCESS_DEFINITION_REPOSITORY, argv[2]);
file = fopen (sbuf, "r");
if (!file) {
   printf ("Unable to open procdef file %s.\n", sbuf);
   return (1);
}

item = xml_read (file);
fclose (file);

if (!item) {
   printf ("Corrupt procdef file %s.\n", sbuf);
   return (1);
}

sprintf (sbuf, "%s%s_%s.xml", PROCESS_DEFINITION_REPOSITORY, argv[2], xml_attrval (item, "ver"));
file = fopen (sbuf, "r");
if (!file) {
   printf ("Unable to open procdef version file %s.\n", sbuf);
   return (1);
}

version = xml_read (file);
fclose (file);

if (!version) {
   printf ("Corrupt version file %s.\n", sbuf);
   return (1);
}

if (strcmp (xml_attrval (version, "name"), "")) {
   printf ("%s\n", xml_attrval (version, "name"));
} else {
   printf ("%s\n", argv[2]);
}
printf ("%s\n", xml_attrval (item, "ver"));

xml = xml_firstelem (version);
while (xml) {
   if (!strcmp (xml->name, "data")) {
      See Handling formatting of data items
   } else if (!strcmp (xml->name, "sequence")) {
      break;
   } else if (!strcmp (xml->name, "parallel")) {
      break;
   } else if (!strcmp (xml->name, "task")) {
      break;
   }

   xml = xml_nextelem (xml);
}


Handling formatting of data items
A starter data item is one which we encounter before encountering some action (really before encountering anything that can block.) When we find one, we need to emit a line of HTML table which will format it. How we do that depends on its type.
 
printf ("<tr><td>%s</td>\n", xml_attrval (xml, "name"));
printf ("<td>");
if (!strcmp (xml_attrval (xml, "type"), "text")) {
   printf ("<textarea name=\"%s\" rows=5 cols=40>", xml_attrval (xml, "name"));
   xml_writecontent (stdout, xml);
   printf ("</textarea>\n");
} else {
   printf ("<input name=\"%s\" value=\"", xml_attrval (xml, "name"));
   xml_writecontent (stdout, xml);
   printf ("\">\n");
}
printf ("</td></tr>\n");
Previous: list: Displaying the procdef directory ] [ Top: lpml alpha ] [ Next: datasheet: Generating a blank datasheet ]


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.