Fix netstat -- don't print all v4 addresses as v4-mapped-in-v6.
[oss-qm-packages.git] / lib / getargs.c
blob41700977f6f50c9bb55e1f6220d30287c12883a2
1 /*
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.
15 #include "config.h"
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <net/if.h>
19 #include <errno.h>
20 #include <signal.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.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);
33 char temp[len+1];
34 char *sp, *ptr;
35 int i, argc;
36 char want;
39 * Copy the string into a buffer. We may have to modify
40 * the original string because of all the quoting...
42 sp = string;
43 i = 0;
44 strcpy(temp, string);
45 ptr = temp;
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')
54 ptr++;
56 /* Set string pointer. */
57 arguments[i++] = sp;
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.
66 want = *ptr++;
67 while (*ptr != '\0') {
68 if (*ptr == want && *(ptr - 1) != '\\') {
69 ptr++;
70 break;
72 *sp++ = *ptr++;
74 } else {
75 /* Just copy the string up to any whitespace. */
76 while (*ptr != '\0' && *ptr != ' ' && *ptr != '\t')
77 *sp++ = *ptr++;
79 *sp++ = '\0';
81 /* Skip trailing whitespace. */
82 if (*ptr != '\0') {
83 while (*ptr == ' ' || *ptr == '\t')
84 ptr++;
87 argc = i;
88 while (i < 32)
89 arguments[i++] = (char *) NULL;
90 return (argc);