Using OS Services
Don't reinvent the wheel. Although it is great fun to program scripts, the script programmer should not forget UNIX tools. UNIX text filters (sed, awk, ed, grep, tr, cut, paste ...) are especially handy when there is a need to process contents of text files. Have a look at the good old "man" pages describing these tools.
The dmutils package contains hooks to execute UNIX commands:
#include include/dmutil.h #include include/pm.h
/* This script demonstrates executing UNIX commands via SYS_EXEC_CMND()*/
main()
{
fname = "incomes"; htype = SYS_GETENV("PMS_HOSTTYPE");
/* SUN Sparcstations running OpenView */
if ( htype == "sparc" ) { cmnd = "setenv TERM sun; vi " + fname + "; exit"; SYS_EXEC_CMND("shelltool -I '" + cmnd + "'"); } else {
/* Hp PA or series-400 workstations with VUE */
if ( htype == "hp_400" | htype == "hp_pa" ){ cmnd = "hpterm -e vi "+fname; SYS_EXEC_CMND(cmnd); } else {
/* By default start xterm with vi editor (mwm) */
cmnd = "xterm -e vi "+fname; SYS_EXEC_CMND(cmnd); }
}
}
The script executes a command line which first creates a shell window, then opens the file incomes for editing ( 'vi' editor ). The shell window is created slightly differently in different machines. The standard environment of a CADMATIC user includes the environment variable "PMS_HOSTTYPE".