![]() |
Using MtSgmlQL |
The general format of the mtsgmlql command is:
mtsgmlql [options] [queryfile [args] ]
MtSgmlQL can be invoked in three different ways:
mtsgmlql
mtsgmlql queryfile [ args ] mtsgmlql -query inline-query [ args ]
#!/usr/local/bin/mtsgmlql
MtSgmlQL accepts the following command line arguments and options:
The first argument is interpreted as the name of a file containing the query. Following arguments are passed to the script. MtSgmlQL enters non-interactive mode.
Example
mtsgmlql queryfile
to give a simple query as a string on the command line. MtSgmlQL enters non-interactive mode.
Example
mtsgmlql -query "every DATE in stdin"
to specify the language to use. <xx> should be one of 'tbl.iso.lang' Default language is set to 'fr'.
to specify the charset to use. <charset> should be a valid charset name (See mtrecode). Default charset is set to iso_8859_1.
Prints the current version of the tool.
Prints a short on-line help.
When invoked with no arguments, MtSgmlQL enters interactive mode. In this mode, a primary prompt is given before the each query:
Example
Query[1]>
The number between brackets is incremented at each query. Each query is interpreted and results are output immediately on the standard output.
When a query is to be continued on a new line,
a secondary prompt is given to each new line until the completion of the
current
query. The number between brackets stays to the same value:
Example
Query[11]$ global .....[11]> $_mybook = file "mybook.html" .....[11]> ; Query[12]$
Output can be interrupted by typing ^C.
Interactive mode can be exited by typing ^D or one of the queries bye, exit or quit.
When MtSgmlQL is called from the command line and the -query option is used. If the -query option is not used, the first argument is the name of the file containing the query.
MtSgmlQL variables are assigned values as follows:
MtSgmlQL provides a rudimetary inline-help that may help you to check the syntax of all operators.
This Help is invoked with the operator ?:
? ?
? <keyword>
The first form gives information about help; The second gives information about the <keyword>.
2357$ mtsgmlql Query[1]$ ?? ? shows the syntax of an operator syntax : ?? | ? <KEYWORD> type : none examples : ?select ?file keywords: -------+--------+-----+-----+---------+------+-----------+--------+------- Shell Var/Func Const Num Str Logic Attr Elem Select List/Set Doc -------+--------+-----+-----+---------+------+-----------+--------+------- cd global 0 + . not = element if pwd let TRUE - regsub and -> attr: then stdin $* FALSE * regsuball or attr content: else file define NAME / text empty restrict-to content select format: [] %% ~ split exists excluding gi transpose empty: {} "" == eq forall document from stdout shrink '' != ne dockw: where stderr `` > gt docdtd: within into < lt body: remove eval >= ge dockw replace exit <= le docdtd quit count match body bye -------+--------+-----+-----+---------+------+-----------+--------+------- Query[2]$
Query[2]$ ?replace replace scans the SGML tree of element in preorder traversal and returns the element with all descendants matching replaced. syntax : replace <sel> [ as <VARNAME> ] within <ELEMENT> by <LIST> replace <sel> as <VARNAME> within <ELEMENT> by <LIST> where <BOOLEAN> with <sel>::= FIRST | TOP | BOTTOM | EVERY [ '[' <NUMBER> [ : [ <NUMBER> ] ] ']' ] [ [ excluding ] <SET of NAME> ] type : <ELEMENT> example : replace every {ABBR,TITLE,NAME} as $x within file "doc.sgml" by content($x) Query[3]$
In the current version, handling of errors is still rudimentary in case of syntax error. In the non-interactive mode, the name of the script, the line number are also reported.
The predefined global variable $_status is updated after each query. Its boolean value reflects the status of the query (This is really like the $? or $status bourne-shell or cshell variables).
Error messages are as follows:
<ERROR TYPE> ... the query line from which the error was detected... ^^^^ Operator '<OP1>', <ERROR MESSAGE>
or
<ERROR TYPE> ... the query line from which the error was detected... ^^^^ Operator '<OP1>', <ERROR MESSAGE> from '<OP2>'
... the query line from which the error occured ....
^^^^^
The <ERROR TYPE> contains references of
the script file, the line number if necessary. This is a short
descripttion of the error (Examples: Bad type / Division by zero / ...).
The <ERROR MESSAGE> is a complete explanation of the error.
The <OP1> is the name of the operator that detected the error (from one of its operands or from its execution).
The <OP2> is the name of the operator that give to <OP1> a wrong value...
Examples:
Query[13]$ foo; Bad function name foo; ^^^ Operator 'function', 'foo' not such user function! Query[14]$ select from where parse error select from where ^^^^ Query[15]$
Example:
Query[21]$ 1 + "un"; Bad type 1 + "un"; ^ Operator '+', Waits for one <NUMBER> but gets one <CDATA> from operator '"..."' 1 + "un"; ^^^^ Query[22]$ if 1 then 2; Bad type if 1 then 2; ^^ Operator 'if', Waits for one <BOOLEAN> but gets one <NUMBER> from operator 'number' if 1 then 2; ^ Query[23]$
Example:
Query[24]$ global $a = 0; Query[25]$ 12 / $a; Division by zero 12 / $a; ^ Operator '/', waits a value not equal to zero but gets it from operator 'variable' 12 / $a; ^^ Query[26]$ define plus($a,$b) as $a + $b; Query[27]$ plus(1,2); 3 Query[28]$ 12 / plus(0,0); Division by zero 12 / plus(0,0); ^ Operator '/', waits a value not equal to zero but gets it from operator 'function' 12 / plus(0,0); ^^^^ Query[29]$Example (from a file "trial.html")
2364$ ./mtsgmlql trial.html 3 mtsgmlql: In file "trial.html", line 3: Division by zero 12 / plus(0,0); ^ Operator '/', waits a value not equal to zero but gets it from operator 'function' 12 / plus(0,0); ^^^^ 2365$
Example:
Query[32]$ every B within file "trial.html"; I/O: Error, file 'trial.html': No such file or directory Query[33]$