1 /* $NetBSD: nxtarg.c,v 1.5 2002/07/10 20:19:41 wiz Exp $ */
4 * Copyright (c) 1991 Carnegie Mellon University
7 * Permission to use, copy, modify and distribute this software and its
8 * documentation is hereby granted, provided that both the copyright
9 * notice and this permission notice appear in all copies of the
10 * software, derivative works or modified versions, and any portions
11 * thereof, and that both notices appear in supporting documentation.
13 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
14 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
15 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 * Carnegie Mellon requests users of this software to return to
19 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
20 * School of Computer Science
21 * Carnegie Mellon University
22 * Pittsburgh PA 15213-3890
24 * any improvements or extensions that they make and grant Carnegie the rights
25 * to redistribute these changes.
28 * nxtarg -- strip off arguments from a string
30 * Usage: p = nxtarg (&q,sep);
32 * extern char _argbreak;
34 * q is pointer to next argument in string
35 * after call, p points to string containing argument,
36 * q points to remainder of string
38 * Leading blanks and tabs are skipped; the argument ends at the
39 * first occurence of one of the characters in the string "sep".
40 * When such a character is found, it is put into the external
41 * variable "_argbreak", and replaced by a null character; if the
42 * arg string ends before that, then the null character is
43 * placed into _argbreak;
44 * If "sep" is 0, then " " is substituted.
47 * 01-Jul-83 Steven Shafer (sas) at Carnegie-Mellon University
48 * Bug fix: added check for "back >= front" in loop to chop trailing
51 * 20-Nov-79 Steven Shafer (sas) at Carnegie-Mellon University
52 * Rewritten for VAX. By popular demand, a table of break characters
53 * has been added (implemented as a string passed into nxtarg).
55 * Originally from klg (Ken Greer); IUS/SUS UNIX.
58 #include "supextern.h"
63 nxtarg(char **q
, const char *sep
)
66 front
= *q
; /* start of string */
67 /* leading blanks and tabs */
68 while (*front
&& (*front
== ' ' || *front
== '\t'))
70 /* find break character at end */
73 back
= skipto(front
, sep
);
75 *q
= (*back
? back
+ 1 : back
); /* next arg start loc */
76 /* elim trailing blanks and tabs */
78 while ((back
>= front
) && (*back
== ' ' || *back
== '\t'))