home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
pocketbk
/
utilsr
/
shell3a
/
PROGRAM.TXT
< prev
next >
Wrap
Text File
|
1995-04-17
|
4KB
|
125 lines
Notes for programming external shell modules
============================================
When a command is typed the shell processes it as follows:
(1) The input is compared with the aliases and any substitutions
are made. A '\' as the first non-blank character prevents
aliases being expanded.
(2) The arguments are parsed one at a time. If a wildcard is
found this is expanded. If no matches are found an error is
generated, otherwise all arguments are stored in memory. The
array argv%() points to successive arguments. The last
argument in this array is always 0.
(3) Redirection of output is handled.
(4) The first argument is matched against the following:-
(a) The shell builtins
(b) Stored entries in the path
(c) A valid directory to 'cd' to
(d) A valid .opo or .bat file
Modules are stored in the shell's path as their basename. ie.
LOC::M:\OPO\MORE.OPO would be stored as just 'more'. When 'more'
is typed at the prompt and found not to match any of the builtin
functions or aliases, the path is searched and it's found here.
The module LOC::M:\OPO\MORE.OPO is then LOADMed and a function
more%:(x%) is called.
The module MUST contain a function of this specification - it
must be called the same as the .opo file, return an integer and
take 1 integer argument. Currently the return value of the
procedure isn't used.
e.g. To have a command 'newcom' recognized:
(1) Write an opl module with a procedure newcom%:(int%)
(2) Compile this module to newcom.opo
(3) Move newcom.opo into a directory in the path
(4) Use the 'rehash' command to put the new command in your path
(5) If you want a manual page for your command (e.g. if you want
to distribute the module), compile a help file 'newcom.hlp'
using the hcp.opo module, and put it in the helppath directory.
Programming notes:
(a) Command arguments (this may change in future releases)
---------------------
The input string is parsed by the shell and split into separate
arguments. These are stored on the heap and are referenced by
the argv%(n%) array. For example
cp file1.txt file2.txt
Stores: argv%(1)="cp"
argv%(2)="file1.txt"
argv%(3)="file2.txt"
argv%(4)=0 <- marks the end of the list
Your module is passed the number of arguments - in this case 3 -
as it's only parameter.
All text within quotes is stored as a single argument.
(b) Wildcards
-------------
Wildcards are expanded before they are passed to the individual
commands. e.g. ls LOC::M:/ would pass 'ls' a command line like
ls,LOC::M:\AGN,LOC::M:\APP,LOC::M:\OPO,...
Note that wildcards are expanded to absolute pathnames and always
have the native separator '\'.
To pass wildcards to a module they need to be quoted "*".
(c) Useful functions (specifications may change in future releases)
--------------------
ret%=Fparse%:(addr%,src$)
An 'enhanced' version of the OPL parse$ function. It handles
relative paths and appends the trailed \ onto directories.
addr% - the address of a string, length 128 bytes. This will
contain the parsed string.
src$ - the path to be parsed.
ret% - the status of the file as follows:
-33 : File / directory doesn't exist
-127: Path contains wildcards
<0 : OPL error - the status of the returned pathname is undefined
and shouldn't be used.
>0 : Bit 0: file is not ReadOnly
Bit 1: file is Hidden
Bit 2: file is a System file
Bit 3: file is a Volume name
Bit 4: file is a Directory
Bit 5: file is Modified
These are the values returned by the system call FilStatusGet
(Fn $87 Sub $08)
eg. To test for a directory
LOCAL x%,path$(128)
x%=Fparse%:(ADDR(path$),"LOC::M:/APP/TEST")
IF x%<0
IF x%=-33
PRINT "Directory doesn't exist"
ELSE
PRINT ERR$(x%)
ENDIF
ELSEIF x% AND 16
PRINT "Found directory"
ELSE
PRINT "Isn't a directory"
ENDIF
-------------------------------------------------------------------
ret%=fprint%:(string$)
This procedure should be used to make use of output redirection.
Depending on internal variables it either prints the string to the
screen or to the file specified on the command line.