/* sstr2arg: convert string into argument list */
static char *rcsid
= "$Header: /f/osi/compat/RCS/sstr2arg.c,v 7.3 91/02/22 09:15:54 mrose Interim $";
* $Header: /f/osi/compat/RCS/sstr2arg.c,v 7.3 91/02/22 09:15:54 mrose Interim $
* Revision 7.3 91/02/22 09:15:54 mrose
* Revision 7.2 90/10/16 11:20:29 mrose
* partial-backoff-from-jpo
* Revision 7.1 90/10/15 18:19:57 mrose
* Revision 7.0 89/11/23 21:23:34 mrose
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
stash a pointer to each field into the passed array. any common seperators
split the words. extra white-space between fields is ignored.
specially-interpreted characters:
double-quote, backslash (preceding a special char with a backslash
removes its interpretation. A backslash not followed by a special is
used to preface an octal specification for one character a string begun
with double-quote has only double-quote and backslash as special
sstr2arg (srcptr
, maxpf
, argv
, dlmstr
)
register char *srcptr
; /* source data */
int maxpf
; /* maximum number of permitted fields */
char *argv
[]; /* where to put the pointers */
char *dlmstr
; /* Delimiting character */
char gotquote
; /* currently parsing quoted string */
errno
= EINVAL
; /* emulate system-call failure */
for (ind
= 0, maxpf
-= 2;; ind
++) {
errno
= E2BIG
; /* emulate system-call failure */
/* Skip leading white space */
for (; *srcptr
== '\t' || *srcptr
== ' '; srcptr
++);
for (cp
= dlmstr
; (*cp
!= '\0') && (*cp
!= *srcptr
); cp
++);
if (gotquote
) { /* don't interpret the char */
default: /* just copy it */
case '\"': /* beginning or end of string */
gotquote
= (gotquote
) ? 0 : 1 ;
srcptr
++; /* just toggle */
case '\\': /* quote next character */
srcptr
++; /* skip the back-slash */
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
*destptr
= (*destptr
<< 3) | (*srcptr
++ - '0');
while (*srcptr
>= '0' && *srcptr
<= '7');
case 'b': *destptr
++ = '\b'; srcptr
++; break;
case 'n': *destptr
++ = '\n'; srcptr
++; break;
case 'r': *destptr
++ = '\r'; srcptr
++; break;
case 't': *destptr
++ = '\t'; srcptr
++; break;
/* Boring -- just copy ASIS */