Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.5d

Application v 5.25a

  

 

Chapter ElevenSGML Functions (continued)

11.4 HTML Tables

11.4.1 Overview

A series of functions are provided to allow for easy access and modification of HTML Tables. Essentially a table is ‘mapped” creating an array of items that can be accessed by map position or by row and column. The contents and properties of each cell can be examined and to a certain extent altered.

An altered map can be written back to the source or exported to a string.

11.4.2 Operation

A table may be referenced from a string, SGML Object, Mapped Text Object or an Edit Object. A Table Object is created using the HTMLTableMap function where an optional offset or file x/y position can be provided. The <TABLE> tag must be at the position specified or the first item in the file if no position is specified.

Once the map is mapped, it can be accessed and manipulated by various functions. The following is an example of reading the latest Windows DFS file replication log and accumulating the number of pending files:

                                                              /*******************************/
int check_dfs_log(string path) {                              /* Check DFS Status            */
                                                              /*******************************/
    handle              hSGML, hTable;                        /* Parsing Handles             */
    string              list[];                               /* Enumeration List            */
    string              s1;                                   /* General                     */
    int                 x, y, rows;                           /* Position                    */
    int                 blf_cnt;                              /* Back Log File Count         */
    int                 rc;                                   /* Return Code                 */
                                                              /*                             */
                                                              /* ** Count Up Pending Files   */
                                                              /*  * Get File                 */
    list = EnumerateFiles(path + "DFSDetails*.html", 0);      /* No recursion                */
    if (list[0] == "") {                                      /* Got nothing                 */
      l_em = "No DFS Log files";                              /* Set the error               */
      return ERROR_SOFT;                                      /* Exit w/error                */
      }                                                       /* end error                   */
    SortList(list, SORT_DESCENDING);                          /* Reverse order               */
    s1 = path + list[0];                                      /* Get filename                */
                                                              /*  * Map Table                */
    hSGML = SGMLCreate(s1);                                   /* Map file                    */
    if (IsError(hSGML)) {                                     /* Error mapping               */
      l_em = "Error in Parse Load";                           /* Set the error               */
      return ERROR_SOFT;                                      /* Exit w/error                */
      }                                                       /* end error                   */
    s1 = SGMLFindElement(hSGML, HT_TABLE);                    /* Find the table              */
    if (IsError(s1)) {                                        /* Error mapping               */
      rc = GetLastError();                                    /* Get error state             */
      l_em = "Unable to Find Table";                          /* Set the error               */
      return rc;                                              /* Exit w/error                */
      }                                                       /* end error                   */
    x = SGMLGetItemPosSX(hSGML); y = SGMLGetItemPosSY(hSGML); /* Position                    */
    hTable = HTMLTableMap(hSGML, x, y);                       /* Map the table               */
    if (IsError(hTable)) {                                    /* Error mapping               */
      rc = GetLastError();                                    /* Get error state             */
      l_em = "Unable to Map Table";                           /* Set the error               */
      return rc;                                              /* Exit w/error                */
      }                                                       /* end error                   */
    rows = HTMLTableGetRowCount(hTable);                      /* Total rows                  */
    if (rows < 5) {                                           /* Error mapping               */
      l_em = "Unable to Map Table Rows";                      /* Set the error               */
      return ERROR_SOFT;                                      /* Exit w/error                */
      }                                                       /* end error                   */
                                                              /*  * Accumulate Items         */
    y = 1;                                                    /* Use as rows, skip header    */
    while (y < rows) {                                        /* Loop through                */
      s1 = HTMLTableGetCellAsText(hTable, y, 4);              /* Get the backlog of files    */
      if (IsNumeric(s1)) { blf_cnt += TextToInteger(s1); }    /* Add in value                */
      y++;                                                    /* Next row                    */
      }                                                       /* end rows                    */
                                                              /*  * Result                   */
    l_em = FormatString("%a files", blf_cnt);                 /* Get the message             */
    if (blf_cnt > 1000) {                                     /* A lot                       */
      if (blf_cnt > 5000) {                                   /* Time out                    */
        l_ec = ERROR_SOFT;                                    /* Get the error state         */
        return l_ec;                                          /* Exit w/error                */
        }                                                     /* end error                   */
      l_ec = ERROR_RANGE;                                     /* Get the error state         */
      return l_ec;                                            /* Exit w/error                */
      }                                                       /* end time error              */
    return ERROR_NONE;                                        /* Done                        */
    }                                                         /* end routine                 */

Global variables l_em and l_ec are defined elsewhere as a string and dword representing the last error message and last error code. The function locates the latest log file using the formatted date which is part of the name of the file and proceeds to map the file. It then counts up the number of files located in the 5 column of the table.

The table mapping functions do not presently support the COL, TBODY, TFOOT, and THEAD HTML elements.

11.4.3 Functions

Control and Table Management:

HTMLTableGetMapCount — Returns the total number of mapped items in a table.

HTMLTableMap — Maps a table to access and returns an HTML Table Object handle.

HTMLTableToString — Writes table content to a string as HTML.

HTMLTableToTable — Converts an HTML Table to a data table in the form of a two-dimensional array.

HTMLTableToText — Writes table object to a text string.

HTMLTableWrite — Writes/updates table code within the associated object.

Columns:

HTMLTableGetColumnCount — Returns the number of columns in a table.

HTMLTableGetColumnProperties — Returns properties for a column at a column position or discrete index.

HTMLTableGetDiscreteCount — Returns the number of discrete columns in the table.

HTMLTableGetWidths — Returns column widths in the form of a string array.

HTMLTableGetWidthValues — Returns column widths in the form of a pvalue array.

HTMLTableInsertColumn — Inserts a column at a specified position.

Rows:

HTMLTableGetRowClass

HTMLTableGetRowCount — Returns the number of rows in a table.

HTMLTableGetRowProperties

HTMLTableInsertRow — Inserts a row at a specified position

Cells and Map Entries:

HTMLTableGetCell — Gets the raw content (HTML) of a table cell.

HTMLTableGetCellAsText — Gets the content of a table cell as text.

HTMLTableGetRowClass

HTMLTableGetCellProperties — Gets the properties for a specified cell.