Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.5d

Application v 5.25a

  

 

Chapter FourteenProject Functions (continued)

14.4 Project Validation Functions

14.4.1 Introduction

The project can have specific validators attached for checking file content. Normally at application initialization, each DLL as well as the main application registers each validator for each type. Some types may just have placeholders simply displaying a message regarding the file type (such as JPG).

A script can be hooked into a specific file type to perform its own validation. The hook is called either with a specific filename or with a Mapped Text Object handle. It is also passed the expected file type to validate as a string (see FileTypeStringToCode to translate the file type as required).

The script performs its validation and load its validation results into the default log. When the hook completes its work, the log is folded into the log to be display as part of the Information View.

14.4.2 Example Validation Hook

int validate_file(string f_type, string fnTarget) {

    string              s1, s2;
    handle              hTarget;
    int                 rc;

    hTarget = OpenMappedTextFile(fnTarget);
    if (IsError(hTarget)) {
      rc = GetLastError();
      LogSetMessageType(LOG_FATAL);
      s1 = GetFilename(fnTarget);
      s2 = TranslateWindowsError(rc);
      AddMessage("Error accessing %s: %s", s1, s2);
      return ERROR_NONE;
      }

    rc = validate_mapped_text(f_type, hTarget);
    return rc;
    }

int validate_mapped_text(string f_type, handle hTarget) {

                        // local declarations  

    s1 = GetMappedTextFilename(hTarget);
    LogSetTarget(s1);
    s1 = GetFilename(s1);
    v_title = "ABS-EE XML";
    rc = load_validation_data(f_type);
    AddMessage("Validate %s for: %s", v_title, s1);

    LogIndent();
    if (IsError(rc)) {
      AddMessage("ERROR DURING INITIALIZATION 0x%08X", rc);
      return ERROR_NONE;
      }
    LogSetMessageType(LOG_FATAL);

    size = GetLineCount(hTarget);
    hWP = WordParseCreate(WP_SGML_TAG);

    while (lx < size) {

                        // validation loop
                        // add in log messages and locations

      }

    return ERROR_NONE;
    }

In the above example, two hooks have been registered. The first is called by the project in the event the file is not open as an edit window while the second is called when the file is already opened as a window. Note this example obviously applies to text based validation but it certainly can apply to binary files. The file content is just processed differently.

Note that the default log is used to add data. The applications caller will import the default log into its log and then add a summary. It also indents the default log to format it into the complete log

14.4.3 Functions