home *** CD-ROM | disk | FTP | other *** search
-
- static char rcsid[] = "@(#)$Id: strtokq.c,v 5.2 1993/02/03 16:20:30 syd Exp $";
-
- /*******************************************************************************
- * The Elm Mail System - $Revision: 5.2 $ $State: Exp $
- *
- * Copyright (c) 1988-1992 USENET Community Trust
- * Copyright (c) 1986,1987 Dave Taylor
- *******************************************************************************
- * Bug reports, patches, comments, suggestions should be sent to:
- *
- * Syd Weinstein, Elm Coordinator
- * elm@DSI.COM dsinc!elm
- *
- *******************************************************************************
- * $Log: strtokq.c,v $
- * Revision 5.2 1993/02/03 16:20:30 syd
- * add include file
- *
- * Revision 5.1 1993/02/03 16:19:31 syd
- * Initial checkin, taken from filter/parse.c
- *
- *
- ******************************************************************************/
-
-
- /* Like strtok, but returns quoted strings as one token (quotes removed)
- * if flag is non-null. Quotes and backslahes can be escaped with backslash.
- */
-
- #include "headers.h"
-
- char *strtokq(source, keys, flag)
- char *source, *keys;
- int flag;
- {
- register int last_ch;
- static char *sourceptr = NULL;
- char *return_value;
-
- if (source != NULL)
- sourceptr = source;
-
- if (sourceptr == NULL || *sourceptr == '\0')
- return(NULL); /* we hit end-of-string last time!? */
-
- sourceptr += strspn(sourceptr, keys); /* skip leading crap */
-
- if (*sourceptr == '\0')
- return(NULL); /* we've hit end-of-string */
-
- if (flag)
- if (*sourceptr == '"' || *sourceptr == '\'') { /* quoted string */
- register char *sp;
- char quote = *sourceptr++;
-
- for (sp = sourceptr+1; *sp != '\0' && *sp != quote; sp++)
- if (*sp == '\\') sp++; /* skip escaped characters */
- /* expand_macros will fix them later */
-
- return_value = sourceptr;
- sourceptr = sp;
- if (*sourceptr != '\0') sourceptr++;
- *sp = '\0'; /* zero at end */
-
- return return_value;
- }
-
- last_ch = strcspn(sourceptr, keys); /* end of good stuff */
-
- return_value = sourceptr; /* and get the ret */
-
- sourceptr += last_ch; /* ...value */
-
- if (*sourceptr != '\0') /* don't forget if we're at END! */
- sourceptr++; /* and skipping for next time */
-
- return_value[last_ch] = '\0'; /* ..ending right */
-
- return((char *) return_value); /* and we're outta here! */
- }
-
-