home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 1
/
GoldFishApril1994_CD2.img
/
d4xx
/
d473
/
cnewssrc
/
cnews_src.lzh
/
libamiga
/
shell.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-25
|
816b
|
42 lines
/*
* shell
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int shell(char *cmd, char *in, char *out)
{
static char *buff;
static int bsiz = 0;
register int tmp;
if (!cmd || !*cmd) return( -1 );
if (!in || !*in) in = "NIL:";
if (!out || !*out) out = "NIL:";
if ((tmp = strlen(in) + strlen(out) + strlen(cmd) + 8) > bsiz)
buff = (char *) realloc((char *) buff, bsiz = tmp);
if (buff) {
register char *p;
if ((p=strchr(cmd, ' ')) || (p=strchr(cmd, '\t'))) {
*p = '\0';
while (isspace(*++p))
;
}
sprintf(buff, "%s <%s >%s %s", cmd, in, out, p ? p : "");
fprintf(stderr, "%s\n", buff);
fflush(stdout);
fflush(stderr);
if (Execute(buff, 0L, 0L))
return( 0 );
} else {
fprintf(stderr, "No memory for command: \"%s\"\n", buff);
bsiz = 0;
}
return( 1 );
}