blob: bae4d4f35fea37d402a4969de2c5a73bd89fd741 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
/*
* Portable routines to create argv[] argument lists for exec and spawn.
* $Id$
* Copyright (c) 1997 by Tycho Softworks.
* For conditions of distribution and reuse see product license.
*/
#include <other/string.h>
int getargv(char *base[], char *cbuf)
{
int arg = 0;
int qflag = 0;
int sflag = 1;
while(*cbuf)
{
switch(*cbuf)
{
case ' ':
case '\t':
if(qflag)
break;
if(!sflag)
{
*cbuf = 0;
sflag = 1;
}
break;
case '\"':
if(!qflag)
{
*cbuf = 0;
base[arg++] = cbuf + 1;
sflag = 0;
qflag = 1;
}
else
{
*cbuf = 0;
sflag = 1;
qflag = 0;
}
break;
default:
if(sflag)
{
base[arg++] = cbuf;
sflag = 0;
}
}
++cbuf;
}
base[arg] = NULL;
return arg;
}
|