|
|||||||||
|
|||||||||
Related Syntax | |||||||||
Command-line syntax |
You write an OmniMark command line to be run from the Command Prompt in Windows NT or from your favorite shell in UNIX.
There are three types of command-line options you can include:
Command-line options, are OmniMark options you can use but not change.
Your own command-line options are explained in this topic in "Defining your own command-line options".
Your own command-line arguments are explained in this topic in "Specifying your own command-line arguments".
Information on external function libraries and include files (how to identify your OmniMark libraries) and on running OmniMark programs can be found in Developing and running OmniMark programs.
Specifying your own command-line arguments
When you use your own command-line arguments, there are two ways you can choose to use them in your programs:
#main-input
, in which case they will all be interpreted as input filenames and their contents concatenated.
#args
, in which case they can be read one by one and you can sort out values from filenames.
Using #args gives you more flexibility, as this code shows:
; my-args-4.xom ; command line: "omnimark -s my-args-4.xom one.txt two.txt three.txt foo" process repeat for integer i from 1 to 3 output file #args[i] again output #args[4] ; Output: "one is the contents of one.txt ; two is the contents of two.txt ; three is the contents of three.txt ; foo"
Defining your own command-line options
You can set values on the OmniMark command line by using the double-dash option. Using the double dash lets you define your own command-line options, in this case the name of a stream shelf followed by the stream index and then the value of the stream shelf item.
; cl-args.xom ; How to set arbitrary items of a stream shelf from the command line ; ; Sample command line: ; omnimark -s cl-args.xom --file-list 3 "blah" --file-list 7 "another" global stream file-list variable initial-size 10 process-start local integer i initial {1} repeat exit when i > number of #args do when #args[i] = "--file-list" set file-list[#args[i + 1]] to #args[i + 2] increment i by 3 done catch #program-error message msg ; handle out-of-range entries put #error msg || "%n" again ; now test the command line repeat over file-list do when file-list is attached output "file-list[%d(#item)] = '%g(file-list)'%n" done again ; ; Output: " file-list[3] = 'blah' ; file-list[7] = 'another' "
You loop over the command-line arguments (the number of command-line arguments is given by #args), incrementing integer i by 3 because your file-list items come in groups of three:
--file-list
3
blah
The heart of this program lies in setting up the do when
loop and in filling in the values in the stream shelf from what's passed to you on the command line. You do this by setting the index for file-list item to one beyond the word "file-list", and setting the value of that item to 2 beyond the word "file-list":
set file-list[#args[i + 1]] to #args[i + 2]
Related Syntax #args #main-input |
---- |