10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*6812Sraf * Common Development and Distribution License (the "License").
6*6812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
211219Sraf
22*6812Sraf /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24*6812Sraf * Use is subject to license terms.
25*6812Sraf */
26*6812Sraf
270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
30*6812Sraf #pragma ident "%Z%%M% %I% %E% SMI"
310Sstevel@tonic-gate
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <ctype.h>
340Sstevel@tonic-gate #include "libmail.h"
350Sstevel@tonic-gate
360Sstevel@tonic-gate #define TRUE 1
370Sstevel@tonic-gate #define FALSE 0
380Sstevel@tonic-gate
390Sstevel@tonic-gate char **
setup_exec(char * s)400Sstevel@tonic-gate setup_exec(char *s)
410Sstevel@tonic-gate {
420Sstevel@tonic-gate char *p = s, *q;
430Sstevel@tonic-gate static char *argvec[256]; /* is this enough? */
440Sstevel@tonic-gate int i = 0;
450Sstevel@tonic-gate int stop;
460Sstevel@tonic-gate int ignorespace = FALSE;
470Sstevel@tonic-gate
480Sstevel@tonic-gate /* Parse up string into arg. vec. for subsequent exec. Assume */
490Sstevel@tonic-gate /* whitespace delimits args. Any non-escaped double quotes will */
500Sstevel@tonic-gate /* be used to group multiple whitespace-delimited tokens into */
510Sstevel@tonic-gate /* a single exec arg. */
520Sstevel@tonic-gate p = skipspace(p);
530Sstevel@tonic-gate while (*p) {
540Sstevel@tonic-gate q = p;
550Sstevel@tonic-gate stop = FALSE;
560Sstevel@tonic-gate while (*q && (stop == FALSE)) {
57*6812Sraf again:
580Sstevel@tonic-gate switch (*q) {
590Sstevel@tonic-gate case '\\':
600Sstevel@tonic-gate /* Slide command string 1 char to left */
610Sstevel@tonic-gate strmove(q, q+1);
620Sstevel@tonic-gate break;
630Sstevel@tonic-gate case '"':
640Sstevel@tonic-gate ignorespace = ((ignorespace == TRUE) ?
65*6812Sraf FALSE : TRUE);
660Sstevel@tonic-gate /* Slide command string 1 char to left */
670Sstevel@tonic-gate strmove(q, q+1);
680Sstevel@tonic-gate goto again;
690Sstevel@tonic-gate default:
700Sstevel@tonic-gate if (isspace((int)*q) &&
710Sstevel@tonic-gate (ignorespace == FALSE)) {
720Sstevel@tonic-gate stop = TRUE;
730Sstevel@tonic-gate continue;
740Sstevel@tonic-gate }
750Sstevel@tonic-gate break;
760Sstevel@tonic-gate }
770Sstevel@tonic-gate q++;
780Sstevel@tonic-gate }
790Sstevel@tonic-gate if (*q == '\0') {
800Sstevel@tonic-gate argvec[i++] = p;
810Sstevel@tonic-gate break;
820Sstevel@tonic-gate }
830Sstevel@tonic-gate *q++ = '\0';
840Sstevel@tonic-gate argvec[i++] = p;
850Sstevel@tonic-gate p = skipspace(q);
860Sstevel@tonic-gate }
870Sstevel@tonic-gate argvec[i] = NULL;
880Sstevel@tonic-gate if (i == 0) {
890Sstevel@tonic-gate return (NULL);
900Sstevel@tonic-gate }
910Sstevel@tonic-gate return (argvec);
920Sstevel@tonic-gate }
93