Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / sup / source / nxtarg.c
blob3331d0a4e2697871739a855ab474c9f467e1f36d
1 /* $NetBSD: nxtarg.c,v 1.5 2002/07/10 20:19:41 wiz Exp $ */
3 /*
4 * Copyright (c) 1991 Carnegie Mellon University
5 * All Rights Reserved.
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);
31 * char *p,*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.
46 * HISTORY
47 * 01-Jul-83 Steven Shafer (sas) at Carnegie-Mellon University
48 * Bug fix: added check for "back >= front" in loop to chop trailing
49 * white space.
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.
57 #include "supcdefs.h"
58 #include "supextern.h"
60 char _argbreak;
62 char *
63 nxtarg(char **q, const char *sep)
65 char *front, *back;
66 front = *q; /* start of string */
67 /* leading blanks and tabs */
68 while (*front && (*front == ' ' || *front == '\t'))
69 front++;
70 /* find break character at end */
71 if (sep == 0)
72 sep = " ";
73 back = skipto(front, sep);
74 _argbreak = *back;
75 *q = (*back ? back + 1 : back); /* next arg start loc */
76 /* elim trailing blanks and tabs */
77 back -= 1;
78 while ((back >= front) && (*back == ' ' || *back == '\t'))
79 back--;
80 back++;
81 if (*back)
82 *back = '\0';
83 return (front);