home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
CMDS
/
pvic_10a.lzh
/
SRCE
/
locfuncs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-06-09
|
4KB
|
219 lines
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#include "pvic.h"
#include "locdefs.h"
#include <sgstat.h>
/* Read one character from the terminal without echoing it. */
int local_get_character()
{
char c;
if(read(0,&c,1)!=1)return '\033';
else return c;
}
/* Test if there is a character to be read from the terminal. If so the
return value is possitive. If not the return value is zero. If we are
not able to determine whether a character is waiting or not, the return
value is negative. */
int local_is_input_pending()
{
return _gs_rdy(0)>0?1:0;
}
/* Initialize PVIC. If the shell name is defined in an environment
variable it replaces the default name. The tab size defaults to the
size defined in the editing terminal's path. */
void local_init()
{
char *shell_ptr;
struct sgbuf opts;
shell_ptr = getenv(LOCAL_SHELL_ENVIRONMENT_VAR);
if (shell_ptr)
if (strlen(shell_ptr))
shell_name = shell_ptr;
if (_gs_opt(1,&opts) != -1)
PARAMETER_VALUE(PARAMETER_TABSTOP) = opts.sg_tabsiz;
return;
}
/* Deinitialize PVIC. */
void local_deinit()
{
return;
}
static struct sgbuf old_settings;
/* Initialize the terminal I/O. */
void local_init_terminal_io()
{
struct sgbuf new_settings;
_gs_opt(0,&old_settings);
_gs_opt(0,&new_settings);
new_settings._sgm._sgs._sgs_pause=0;
new_settings._sgm._sgs._sgs_echo=0;
new_settings._sgm._sgs._sgs_eofch=0;
new_settings._sgm._sgs._sgs_bspch=0;
new_settings._sgm._sgs._sgs_dlnch=0;
new_settings._sgm._sgs._sgs_dulnch=0;
new_settings._sgm._sgs._sgs_psch=0;
new_settings._sgm._sgs._sgs_kbich=0;
new_settings._sgm._sgs._sgs_kbach=0;
new_settings._sgm._sgs._sgs_bsech=0;
new_settings._sgm._sgs._sgs_bellch=0;
_ss_opt(0,&new_settings);
return;
}
/* Deinitialize the terminal I/O. */
void local_deinit_terminal_io()
{
_ss_opt(0,&old_settings);
return;
}
/* Flag which is set by local_control_c_handler if control-c is pressed. */
static int control_c_pressed=0;
/* Function called when control-c is pressed. */
void local_control_c_handler()
{
control_c_pressed=1;
}
/* Reset the control_c_pressed flag. */
void local_reset_control_c_pressed()
{
control_c_pressed=0;
}
/* Get the value of the control_c_pressed flag. */
int local_control_c_pressed()
{
return control_c_pressed;
}
/* Rename a file */
rename(old,new)
char *old,*new;
{
char cmd[128];
sprintf(cmd,"rename %s %s",old,new);
system(cmd);
}
/* This is a replacement for system() to be called whenever the
* environment variable array must be passed to the child process
*/
int local_system(cmd)
char *cmd;
{
int reply;
int i;
int n;
int find_space;
char **args;
int argnum;
extern int os9forkc(); char *modname;
n = strlen(cmd);
args = (char**)malloc(sizeof(char*)*(n + 2));
if (!args)
{
printf("Can't allocate argument pointer storage\n");
return(-1);
}
argnum = 0;
if (strcmp(shell_name, cmd) != 0)
args[argnum++] = shell_name;
find_space = 1;
for(i=0; i<n; i++)
{
if (find_space)
{
if (!isspace(cmd[i]))
{
args[argnum++] = &cmd[i];
find_space = 0;
}
}
else
{
if (isspace(cmd[i]))
{
cmd[i] = 0;
find_space = 1;
}
}
}
args[argnum] = 0;
printf("\n");
if ((reply = os9exec(os9forkc, shell_name, args, environ_array, 0, 0, 3))
> 0)
wait(0);
else
printf("Can't run %s\n", cmd);
free(args);
return (reply);
}
/* This function handles reading and processing the local initialisation
* file. If there is no initialisation file this should be a null function.
*/
int local_ini_file()
{
FILE *ini;
char buf[128];
char *hp;
int lth;
if ((hp = getenv(LOCAL_HOME_ENVIRONMENT_VAR)) == NULL)
return (-1);
sprintf(buf, "%s%s", hp, LOCAL_INI_FILE);
ini = fopen(buf, "r");
if (ini)
{
while (fgets(buf, 128, ini))
{
lth = strlen(buf) -1;
buf[lth] = NULL;
if (lth > 0)
do_command_line(buf);
}
fclose(ini);
}
else
return(0);
}