Frank Heckenbach wrote:
Rick Engebretson wrote:
I've been trying to learn how one would use pascal programs to be used in shell scripts.
The original pascal used the program header to specify such input, output interfaces. ie;
Program foo(input, output, file1, file2) ;
The input and output are the standard in, out but are text file types. TurboPascal on DOS mostly forgot about this.
Not really. BP supports `Input' and `Output', though it doesn't require declaring them in the program header. GPC does the same, except in ISO Pascal modes.
Also, BP's CRT unit redirects `Input' and `Output' automatically. Again, GPC's CRT unit does the same. For programs used in shell scripts, that's often irrelevant as batch mode programs don't use CRT anyway. (And if the scripts are meant to call interactive programs, the redirection is fine again.) In case you need a program that uses CRT sometimes, but not always (e.g., depending on command-line arguments), you can re-open `Input' and `Output' to '' (empty name, BP compatible) or '-' (as in many Unix programs) again.
For the arguments, Frank D. Engel, Jr. already mentioned `ParamCount' and `ParamStr' (also BP compatible).
Automatically assigning addtional files mentioned in the header to the names given in arguments has been discussed, but I'm not really convinced of its usefulness. Many programs need to accept options apart from file names. So this 1:1 mapping would work only for simple cases.
Frank
I appreciate your response. I'm familiar with the paramstr and paramcount and some of the rest.
An old book, "TurboPascal Programmers' Library (1987)" discusses the topic as "filters". Some compiler flags are set for this use (get and put buffers are created). Old Unix and newer Linux books cover the topic a little, too. With C.
Shell facilities like timers, pipes, forks, job control, buffers, process management, event signals are available. For example, a pascal framebuffer draw routine uses numeric input and outputs to /dev/fb0. None of this is text input or output. Perhaps it would be best, however, to convert to pure text.
I don't know. That's why I was looking for some references.