2 * lib/getargs.c General argument parser.
4 * Version: $Id: getargs.c,v 1.3 1998/11/15 20:09:43 freitag Exp $
6 * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
7 * Copyright 1993,1994 MicroWalt Corporation
9 * This program is free software; you can redistribute it
10 * and/or modify it under the terms of the GNU General
11 * Public License as published by the Free Software
12 * Foundation; either version 2 of the License, or (at
13 * your option) any later version.
16 #include <sys/types.h>
17 #include <sys/socket.h>
25 #include "net-support.h"
26 #include "pathnames.h"
29 /* Split the input string into multiple fields. */
30 int getargs(char *string
, char *arguments
[])
32 int len
= strlen(string
);
39 * Copy the string into a buffer. We may have to modify
40 * the original string because of all the quoting...
48 * Look for delimiters ("); if present whatever
49 * they enclose will be considered one argument.
51 while (*ptr
!= '\0' && i
< 31) {
52 /* Ignore leading whitespace on input string. */
53 while (*ptr
== ' ' || *ptr
== '\t')
56 /* Set string pointer. */
59 /* Check for any delimiters. */
60 if (*ptr
== '"' || *ptr
== '\'') {
62 * Copy the string up to any whitespace OR the next
63 * delimiter. If the delimiter was escaped, skip it
64 * as it if was not there.
67 while (*ptr
!= '\0') {
68 if (*ptr
== want
&& *(ptr
- 1) != '\\') {
75 /* Just copy the string up to any whitespace. */
76 while (*ptr
!= '\0' && *ptr
!= ' ' && *ptr
!= '\t')
81 /* Skip trailing whitespace. */
83 while (*ptr
== ' ' || *ptr
== '\t')
89 arguments
[i
++] = (char *) NULL
;