Creating new TRIMpl functions

Trimtools ships with a set of functions stored in the trim.fnc file. These are simple extensions to the built-in TRIMpl functions and demonstrate how the user can create a library of project specific functions.

The easiest way to build the trim.fnc file is by using the car utility which is similar to the Unix ar utility. Type car with no parameters for a description of its usage.

Each function in trim.fnc is delineated by a RS (record separator) character. The trimgen utility uses the trim.fnc file to reconcile any undefined functions calls in your TRIMpl script.

As the number of functions in trim.fnc increases, trimgen may begin to slow down because it does a simple file scan to find references. Use the trimlib utility to convert the text file into an indexed binary file. For example, you could store your text functions in trim.fn2 and type trimlib trim.fnc trim.fn2 to create the indexed trim.fnc file.

The TRIMpl code used to create the individual html files from trim.fnc is shown below. It relies on a comment box at the beginning of each function:

/******************************************************************************/
/* Name:        should be the same as car filename                            */
/* Description: short description of what the function does                   */
/* Author:      who wrote it                                                  */
/* Date:        date written                                                  */
/* Function:    detailed description of what the function does                */
/* Parameters:  parm.0 - what is it                                           */
/*              parm.1 - what is it                                           */
/******************************************************************************/
The Author and Date are assumed to be one line. The rest can span multiple lines.
{
list il,fl,hl,ol,tl,cl;
char fnc[128],odir[255];

if (count(parm) < 1 || count(parm) > 2) {
  printf("Usage: trimrun fnc -p fnc_car_file [output_dir]");
  return;
  }
if (count(parm) == 2) {
  odir = parm.1;
  if (substr(odir,1,-1) != "/") odir = odir^^"/";
  }
else odir = "";

list_mod(hl,1,"<!DOCTYPE HTML PUBLIC ""~//W3C//DTD HTML 3.2//EN"">");
list_mod(hl,1,"<HTML<>HEAD>");
list_mod(hl,1,"<TITLE>Trifox, Inc. -- TRIMpl Function Library Reference</TITLE>");
list_mod(hl,1,"</HEAD>");
list_mod(hl,1,"<BODY BGCOLOR=""#fbfbfb""TEXT=""#000000""LINK=""#5c366a"">");
list_seek(hl,0);

list_mod(cl,1,parm.0^^" "^^parm.0^^".err");
list_mod(cl,1,"fixed");
list_mod(cl,1,NULL);
list_mod(cl,1,"C 0 80");

il = list_open(cl,1000000);                 /* read in fnc file in car format */
while (list_rows(il)) {
  tl  = tokenize(list_curr(il,0),".");      /* find car name                  */
  fnc = lower(list_curr(tl,0));             /* force lower case for sorting   */
  list_mod(il,0);                           /* dump car filename line         */
  if (substr(list_curr(il,0),1,3) != "/**") goto skip_to_rs; /* skip this one */
  list_mod(il,0);                           /* dump opening comment box line  */
  list_mod(fl,1,"<BR><A HREF="""^^fnc^^
                ".html"">"^^fnc^^"</A>");
  ol = list_copy(hl);                       /* initialize header and move to  */
  list_seek(ol,list_rows(ol)-1);            /* the end                        */
  list_mod(ol,1,"<H1>"^^fnc^^"</H1>");
  list_mod(ol,1,"<br>");
  while (substr(list_curr(il,0),1,3) == "/* ") { /* until the comment box ends*/
    tl = tokenize(list_curr(il,0));         /* tokenize on blanks             */
    if (list_rows(tl) > 2) {                /* not an empty line?             */
      list_mod(tl,0);
      if (upper(list_curr(tl,0)) == "NAME:") goto next_il; /* have fnc already*/
      if (upper(list_curr(tl,0)) == "DESCRIPTION:") {
        list_mod(tl,0);
        list_mod(ol,1,"<H2>Description</H2>");
        }
      else if ((upper(list_curr(tl,0)) == "AUTHOR:") ||
               (upper(list_curr(tl,0)) == "DATE:")) {
        list_mod(tl,0);
        goto next_il;
        }
      else if (upper(list_curr(tl,0)) == "FUNCTION:") {
        list_mod(tl,0);
        if (list_rows(tl) == 1) goto next_il;
        list_mod(ol,1,"<H2>Function</H2>");
        }
      else if (upper(list_curr(tl,0)) == "PARAMETERS:") {
        list_mod(tl,0);
        if (list_rows(tl) == 1) goto next_il;
        list_mod(ol,1,"<H2>Parameters</H2>");
        }
      else if (upper(list_curr(tl,0)) == "NOTE:") {
        list_mod(tl,0);
        if (list_rows(tl) == 1) goto next_il;
        list_mod(ol,1,"<H2>Notes</H2>");
        }
      list_mod(ol,1,NULL);
      while (list_rows(tl)-1) {             /* while remaining words          */
        list_modcol(ol,0,list_curr(ol,0)^^list_curr(tl,0)^^" ");
        list_mod(tl,0);
        }
      list_mod(ol,1,"<br>");
      }
    else list_mod(ol,1,"<p>");              /* empty line                     */
    next_il:;
    list_mod(il,0);                         /* dump input line from list      */
    }
  list_mod(ol,1,"</BODY></HTML>");          /* finishing touches              */
  list_file(ol,odir^^fnc^^".html","a");     /* file it                        */
  skip_to_rs:;
  while (ascii(substr(list_curr(il,0),1,1)) != 30 && list_rows(il))
    list_mod(il,0);
  if (list_rows(il)) list_mod(il,0);        /* dump RS line                   */
  }                                         /* listrows(il)                   */
list_sort(fl,0,true);                       /* sort function names            */
list_seek(fl,0);                            /* insert header                  */
list_mod(fl,-1,"<!DOCTYPE HTML PUBLIC ""~//W3C//DTD HTML 3.2//EN"">");
list_mod(fl,1,"<HTML>");
list_mod(fl,1,"<HEAD>");
list_mod(fl,1,"<TITLE>Trifox, Inc.");
list_mod(fl,1,"<BASE TARGET=""Functions"">");
list_mod(fl,1,"</HEAD>");
list_mod(fl,1,"<BODY BGCOLOR=""#fbfbfb""");
list_mod(fl,1,"      TEXT=""#000000""");
list_mod(fl,1,"      LINK=""5c366a""");
list_mod(fl,1,"      ALINK=""7a418e""");
list_mod(fl,1,"      VLINK=""808080"" >");
list_mod(fl,1,"<A NAME=""top"">");
list_mod(fl,1,"<H3>Function List</H3>");

list_seek(fl,list_rows(fl)-1);              /* move to end and insert footer  */
list_mod(fl,1,"<HR width=""80%""><P>");
list_mod(fl,1,"<A HREF=""#top"">Back To Top</A>");
list_mod(fl,1,"</BODY></HTML>");
list_file(fl,odir^^"fnclist.html","a");
}