#!/bin/sh # # This is a shell archive. To extract its contents, # execute this file with /bin/sh to create the file(s): # # fgl_run.c # # This shell archive created: Wed Feb 19 16:55:46 EST 1992 # echo "Extracting file fgl_run.c" sed -e 's/^X//' <<\SHAR_EOF > fgl_run.c X/* fgl_run.c X * X * X * Summary: C Functions to run system commands from I4GL X * X * Environment: SunOS 4.1, Informix-4GL X * X * Submitted by: Harry Bochner X * X * X * Immeditately prior to executing a system command with the RUN statement, X * Informix-4GL sets up the terminal for "normal" processing. This usually X * results in at least a screen clear, which is often unnecessary or X * unwanted. X * X * These routines demonstrate one method of using C function calls to run X * system commands that will perform no terminal I/O. They should be X * tailored for your specific application. X * X */ X X X#include X#include X#include X X X/* run_var: construct a cmd with two variable arguments, and pass it X * to the shell. X * This could be done in 4gl, using the 'run' cmd, but this leads to X * unnecessary screen clearing and redisplay when the cmd is silent. X */ Xrun_var(argcnt) Xint argcnt; X{ X run_x(); X return(0); X} X X X/* alternate entry point for run_var, for cases where you need to look at X * the status returned by the system() call. X */ Xrun_status(argcnt) Xint argcnt; X{ X retint((long) run_x()); X return(1); X} X X Xrun_x() X{ char from[201], to[201], name[101], cmd[400]; X struct sgttyb oldtty, newtty; X void (*sig)(); X int ret_val; X X popquote(to, 200); X popquote(from, 200); X popquote(name, 100); X X trimstr(to); X trimstr(from); X trimstr(name); X X strcpy(cmd, name); X strcat(cmd, " "); X strcat(cmd, from); X strcat(cmd, " "); X strcat(cmd, to); X X /* make sure terminal settings are normal */ X ioctl(1, TIOCGETP, &oldtty); X newtty = oldtty; X newtty.sg_flags |= CRMOD|ECHO; X newtty.sg_flags &= ~(RAW|CBREAK); X ioctl(1, TIOCSETP, &newtty); X X /* save and restore handler for stop signal X * so that ^Z is handled cleanly X */ X sig = signal(SIGTSTP, SIG_DFL); X X ret_val = system(cmd); X X (void) signal(SIGTSTP, sig); X ioctl(1, TIOCSETP, &oldtty); /* restore settings */ X return(ret_val); /* tell 4gl no values returned */ X} X X Xtrimstr(p) Xchar *p; X{ register char *q; X X for (q=p+strlen(p); q > p; ) X if (*--q != ' ') { X *++q = 0; X break; X } X} SHAR_EOF if [ `wc -c < fgl_run.c` -ne 2260 ] then echo "Lengths do not match -- Bad Copy of fgl_run.c" fi echo "Done."