How to customize the web search (scripting language)?
Syntax of the scripting language. General rules:
- first line should contain the declaration of variables, e.g.
def #title, #author, #isbn, #publisher
- second line should contain the declaration of private variables, e.g.
def #n, #count
- each variable name should start from # character
- each function name should start from $ character
- function parameters are enclosed in brackets, e.g.
#title=$rtrim(#title)
#title=$copyuntil(<)
- a function parameter is either a variable or a string
- a function returns the result always as a string
- a function name is always in lower case
List of all functions:
- $find(string) - find text in the source file and the cursor is set right after it
- $uppercase(string) - convert a string to upper case
- $lowercase(string) - convert a string to lower case
- $gotop - go to beginning of the source file
- $goend - go to end of the source file
- $copyuntil(string) - the result is text from the current cursor position (e.g. set by $find) until the "string"; the cursor is set immediately after "string" returned
- $struntil(string, str) - the result is text from the str string until the "string"
- $strfromuntil(from_str, until_str, str) - the result is text from the str starting from from_str string until until_str
- $skiptonewline - skip to the next line
- $rtrim(string) - remove spaces and tabs from the end of the string
- $ltrim(string) - remove spaces and tabs from the beginning of the string
- $exit - exit the script
- $length(string) - return the number of characters in the string; the result has the string type
- $substr(string,from,count) - return a substring of string beginning at from position; the length of the substring is specified by count; from and count can be numbers or variables e.g.
$substr(#mytext,1,#var1)
- $lastfound(0) - if the result is '1' the last $find function found the string, if the result is '0' the last
$find function failed to find the string
- $delstring(string,#param) - delete a substring from a variable
- $strdelhtml(string) - delete html tags from a string variable
- $replacestr(withstr,whatstr,string) - replaces the first occurence of whatstring in string with withstring
- $replaceallstr(withstr, whatstr,string) - replaces all occurences of whatstring in string with withstring
- $findstr(what,string) - if what is found in string the result is the index of the first character found; the result is 0 if the string is not found
- $replacespecial(string) - replace html codes with special characters
& = &
> = >
< = <
- $addstring(str1,str2) - the result is a string: str1 + str2
- $break - break the script and do not close the input file; it is useful when you want to extract multiple records; when Process can be called in a loop until the end of file is reached or $finish function is called in the script.
- $finduntil(string) - all following $find functions will stop searching on the first occurence of string; the cursor will be set just before this string
- $eof - returns '1' if end of the text file
- $setbookmark - save the current location in the source file (current line and character index)
- $gotobookmark - go to the previously saved bookmark
- $clearbookmark - clear previously saved bookmark
- $date - returns the system(computer) date (e.g. #date=$date)
- $time - returns the system(computer) time (e.g. #time=$time)
Assignment:
- assignment: you can assign the result of a function to a variable,
e.g.
#title=$rtrim(#title)
- empty string assignment: "" means empty string, e.g.:
#str1="" (use this in the script)
{Title}="" (use this in the mapping window)
New Line:
- declare a local variable. e.g.: #newline
- assign $newline function to your local variable. e.g.:
#newln=$newline
- Then, you can use #newln variable in any function. e.g.:
#subjects=$addstring(#subjects,#newln)
If statement.
-
it has the following format :
if (expression)
statements executed when expression is true
else
statements executed when expression is false
endif
-
the if expression can use: =,<,>,<> operators
example if statement:
if (#left=John)
#text=$copyuntil(&)
$gotop
else
#text=$copyuntil(a#)
endif
While .. endwhile statement.
$find(string)
while ($lastfound(0)=1)
statements executed when expression is true
$find(string)
endwhile
Comments
Use // at the beginning of the line to include a comment in your script file.
|
|