Files
Arquivotheca.Solaris-2.5/cmd/mail/setup_exec.c
seta75D 7c4988eac0 Init
2021-10-11 19:38:01 -03:00

72 lines
1.5 KiB
C
Executable File

/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T */
/* The copyright notice above does not evidence any */
/* actual or intended publication of such source code. */
#ident "@(#)setup_exec.c 1.5 92/07/14 SMI" /* SVr4.0 1.8 */
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <libmail.h>
#define TRUE 1
#define FALSE 0
char **
setup_exec(s)
char *s;
{
register char *p = s, *q;
static char *argvec[256]; /* is this enough? */
register int i = 0;
register int stop;
register int ignorespace = FALSE;
/* Parse up string into arg. vec. for subsequent exec. Assume */
/* whitespace delimits args. Any non-escaped double quotes will */
/* be used to group multiple whitespace-delimited tokens into */
/* a single exec arg. */
p = skipspace(p);
while (*p) {
q = p;
stop = FALSE;
while (*q && (stop == FALSE)) {
again:
switch (*q) {
case '\\':
/* Slide command string 1 char to left */
strmove (q, q+1);
break;
case '"':
ignorespace = ((ignorespace == TRUE) ?
FALSE : TRUE);
/* Slide command string 1 char to left */
strmove (q, q+1);
goto again;
default:
if (isspace(*q) && (ignorespace == FALSE)) {
stop = TRUE;
continue;
}
break;
}
q++;
}
if (*q == '\0') {
argvec[i++] = p;
break;
}
*q++ = '\0';
argvec[i++] = p;
p = skipspace(q);
}
argvec[i] = (char *)NULL;
if (i == 0) {
return ((char **)NULL);
}
return (argvec);
}