LinuxAsmTools |
"domac" text processor PURPOSE Domac is a simple alternative to unix text processors (awk,sed,m4 and others). It is easy to read and understand domac programs without a manual. It has the unique capibility to add comments everywhere, even inside commands. Also, it is designed for embedding into scripts and other languages. STARTING DOMAC The calling sequence for domac is; domac commands <data> <output> "commands" is a file name. The file has commands described in DOMAC COMMANDS section. "data" is optional file name. The data file can use a mask to include numerous files or be a single file name. The command file will work on "data" and place result in "output" file. "output" is a optional directory. The directory "out" will be used if this parameter is not provided. All processed data files will be stored here. It is possible to use ../ ./ . a directory name or full path. Some examples: 1. apply the "cmds" file to all html files in the current directory and store the output in directory "web" domac cmds *.html ./web 2. apply the "cmds" file to "foo" and store the results in default dir "out" domac cmds foo 3. create an executable commands file which sets its own inputs and outputs #!/bin/bash domac $0 exit 0 ;domac commands are placed here The above text can be placed in any file and the execute attribute set. It will run as a domac program. DOMAC OPERATION domac expects to read commands and apply them to a data file. It then builds an output file with the same name and writes it out. If the output file goes into the current directory, it will replace the input file. domac can also be programmed to manually read data files and construct output files, or modify filename created by domac. All domac commands start with "^" followed by a name. Everything else is assumed to be comments and is ignored. Once a valid command name is found, the program then expects parameters which are preceeded by "$" for labels and "#" for keywords. All available labels are text string pointers and pre definded by domac at start up. They include various file names and the input file. See the DOMAC STRINGS section for label information and the DOMAC KEYWORDS section for keyword information. DOMAC COMMANDS All domac commands work on named strings which are identified with a "$". When all processing on a data file is done, the output file will be written. ^ifeq If any named string is equal to another string then exectute the following commands until a ^endif command is found. Nesting of ^ifeq and ^ifne commands are allowed. example 1 compare two strings. The following two commands are identical in operation. ^ifeq $work $temp ^ifeq string $work and string $temp are equal example 2 check if a string exists ^ifeq $work and ("") then example 3 check a string contents ^ifeq string $work is equal to ("yes") then ^ifne If any named string is not equal to another then execute the following commands until a ^endif is found. see ^ifeq for examples ^endif ^endif signal the end of a list of "if" commands. It can be nested. ^find the ^find command searchs for a string in other strings and sets the $findptr. The $findptr is uinque, because it always points inside other strings. If we modify the $findptr we also modify the sting it points to. This is a powerful way to edit other strings by selecting a area ($findptr) and then modifying the $findptr. The ^copy, ^shrink, and ^expand commands can be applied to the $findptr. example 1. search a string and set &findptr ^find $temp in $work example 2. search a string for known text ^find ("foo") in $work ^ifeq $findptr and ("") then ^show ("not found") ^stop ^copy The ^copy command always places new contents into a named string. Data can come from another string or file. Two named strings are handled specially, the $findptr and $infile. When data is copied to the $findptr it replaces the data in the string pointed to by $findptr. The ^copy to $infile builds a default $outfilename which is used to store domac output data. syntax: ^copy ("xx") $xxx ^copy $xxx $xxx ^copy /filename $xxx ^copy /$xxx $yyy example 1. initialize a naned string ^copy the string ("hello") to $work example 2 copy named strings ^copy $temp to $work example 3 load a input file for processing ^copy /file $infile example 4 insert file into another string ^find ("insert here") in string $infile ^copy /myfile $findptr example 5 load a file with name in $doptr ^copy /$doptr $infile ^expand The ^expand command works on the beginning or end of strings. The keyword #front tells ^expand to work on front. The keyword #back says to operate on end of string. syntax: ^expand $xxxx {#front / #back} $xxx <- insert string ^expand $xxxx (#front / #back} ("xxx") <- insert string ^expand $xxxx (#front / #back} /file <- insert file ^expand $xxxx (#front / #back} #n <- move pointer n times ^expand $xxxx (#front / #back} #till ("x") <- move pointer <- till char x <- encountered example 1. insert a string at front of another ^expand string $work #front by adding ("insert") example 2. append a file to end of string ^expand string $work #back with file ./foo ^shrink The ^shrink command works on beginning of end of strings. syntax: ^shrink $xxxx (#front / #back} #n <- move pointer n times ^shrink $xxxx (#front / #back} #till ("x") <- move pointer <- till char x <- encountered example 1. Shrink the front and back of a string by 1 ^shrink the string $work #back by #1 ^shrink the string $work #front by #1 ^replace The ^replace command replaces all occurances of one string in a second string. syntax: ^replace <instring> <match string> <replacement string> The instring has to be a named string ($xxxx) The match string can be either a named string or ("string") The replacement string can be either a named string or ("string") example 1. replace all occurances of "x" in string $work with "yy" ^replace in $work all ("x") with ("yy") ^dolist The ^dolist command executes a set of commands for each line in a file or string. The current line is placed in named string $doptr. syntax: ^dolist /file ^dolist named-string All commands after the ^dolist, until a ^enddo are executed for each line on list. example 1. if file "list" has two lines as follows: I'm line 1 I'm line 2 then the following commands will list each line: ^dolist /list ^show $doptr ^enddo example 2. read a list of files ^dolist /list ^copy /$doptr $infile ;load file ^show $infile ^enddo ^enddo The ^enddo command terminates a ^dolist. This command can not be nested. ^shell The ^shell command call the resident shell with a request. The shell command can contain embedded named strings. syntax: ^shell ("shell command") example 1. list files in current directory for processing ^shell ("ls > files") example 2. execute shell command in named string ^shell $temp ^show The ^show command displays text in named string or defined string. It is normally used to debug programs or display status of processing. syntax: ^show named_string ^show ("string") example 1. show contents of $work ^show $work example 2. show status message ^show ("processing completed") ^stop The ^stop command terminates domac. It needs to be used at end of program and within any "if" commands that want to force an exit. example: 1. terminate the program if error ^ifeq $work ("") ^show ("no data present") ^stop ^endif DOMAC STRINGS The following named strings can be used with most commands. Occasionally, a named string is inappropiate and results in error message. An example is use of $findptr by ^dolist $infilename - set by domac anytime $inbuf is filled. - Max size is 200 bytes. $outfilename - set by domac anytime $inbuf is filled - Can be modified. Used to write output. - Max size is 200 bytes. $temp - 4000 byte work area $infile - input buffer (allocated memory) $findptr - psuedo string, points into other strings $doptr - current line while ^dolist executes $work - 16000 byte work area DOMAC KEYWORDS #front - used by ^expand and ^shrink #back - used by ^expand and ^shrink #till - used by ^expand and ^shrink #n - number token used by ^expand - and ^shrink. Example: #1 / - indicates a filename follows. - filenames in a string are shown - as /$ example: /$doptr DOMAC FAQ Why isn't a delete command available? The delete function is available as paat of other commands. There are two basic ways to do deletes: 1. use ^replace to replace a string with (""). This works as a delete. 2. For most deletes a copy to the $findptr is used. First, find the area to be deleted and adjust it with shring and expand. Then copy ("") to $findptr. Why do I sometimes get errors when expanding or shriking strings? Strings have fixed buffers and a length. We can't move outside the buffer or beyond the end of a string. Normally, the $findptr is used with shrink and expand because it can float anywhere inside a string. DOMAC EXAMPLES A simple hello world program. Assumes that domac is installed. Since we did not supply an output filename, the program will also give a warning. #!/bin/bash domac $0 exit 0 ^show ("hello world") ^stop We can create a standalone command file and duplicate the previous example: file cmds = ^show ("hello world") ^stop we now call domac as follows: domac cmds Next, we can list the current directory and show each filename #!/bin/bash domac $0 exit 0 ^shell ("ls > dummy") ;collect file names ^dolist /dummy ^shrink $doptr #back #1 ;remove 0ah at end ^show $doptr ;show file name ^enddo ^stop A program to replace all "2" characters with the character "3" ^copy ("1212") $work ^replace $work ("2") with ("3") ^ifeq $work ("1313") ^show ("success $work=1313") ^enddo ^stop |