Command Files

Commands can be placed in files (known as command files).

Reading Command Files

Reading and then read into TinTin using two basic methods:

#class {<classname>} {read} {<filename>}
#read {filename}

The #class {read} {filename} command is basically shorthand for:

#class {name} {open}; #read {filename}; #class {close};

Using the #class {read} {filename} method imposes some limitations on us:

  1. Everything in the file will be part of the class (we can’t mix non-class code in a file read in this way).
  2. We don’t explicitly remove the existing data before reading it in, therefore unexpected results can occur (if reloading command files on the fly).

I prefer the more flexible approach (using the #read command with explicit #class commands) as described next.

Execution Order

Command files can load each other. When they do, the command file is immediately read and the commands are immediately executed as soon as #read statement is encountered. The following scripts demonstrate this behavior:

#nop init.tin;

#showme {<fba>DEBUG:INIT         Start of init.tin.};

#alias read {
    #showme {<fba>DEBUG:INIT:READ    Reading %1.};
    #line verbose #read %1;
}

#showme {<fba>DEBUG:INIT         Just before read alias commands.};

read module1.tin;
read module2.tin;

#showme {<fba>DEBUG:INIT         Just after read alias commands.};

#showme {<fba>DEBUG:INIT         Reading module3.tin started.};
#read module3.tin;
#showme {<fba>DEBUG:INIT         Reading module3.tin completed.};


#nop module1.tin;
#showme {<fba>DEBUG:MODULE1:     Inside of module1.tin.};

#nop module2.tin;
#showme {<fba>DEBUG:MODULE2:     Inside of module2.tin.};

#nop module3.tin;
#showme {<fba>DEBUG:MODULE3:     Inside of module3.tin.};

When we execute init.tin with:

tt++ -v -r init.tin

We see the following output:

#CONFIG {VERBOSE} HAS BEEN SET TO {ON}.
#CONFIG {TINTIN CHAR} HAS BEEN SET TO {#}.
DEBUG:INIT         Start of init.tin.
#CONFIG {COMMAND ECHO} HAS BEEN SET TO {ON}.
#CONFIG {VERBOSE} HAS BEEN SET TO {ON}.
#OK. {reload} NOW ALIASES {#system {tput clear};#kill {all};#read init.tin;} @ {5}.
#OK. {read} NOW ALIASES {#showme {<fba>DEBUG:INIT:READ    Reading %1.};#line verbose #read %1;} @ {5}.
DEBUG:INIT         Just before read alias commands.
DEBUG:INIT:READ    Reading module1.tin.
#CONFIG {TINTIN CHAR} HAS BEEN SET TO {#}.
DEBUG:MODULE1: Inside of module1.tin.
DEBUG:INIT:READ    Reading module2.tin.
#CONFIG {TINTIN CHAR} HAS BEEN SET TO {#}.
DEBUG:MODULE2: Inside of module2.tin.
DEBUG:INIT         Just after read alias commands.
DEBUG:INIT         Reading module3.tin started.
#CONFIG {TINTIN CHAR} HAS BEEN SET TO {#}.
DEBUG:MODULE3: Inside of module3.tin.
DEBUG:INIT         Reading module3.tin completed.