15b0fe478SBruce M Simpson /*- 25b0fe478SBruce M Simpson * Copyright (c) 1990, 1993 35b0fe478SBruce M Simpson * The Regents of the University of California. All rights reserved. 45b0fe478SBruce M Simpson * 55b0fe478SBruce M Simpson * Redistribution and use in source and binary forms, with or without 65b0fe478SBruce M Simpson * modification, are permitted provided that the following conditions 75b0fe478SBruce M Simpson * are met: 85b0fe478SBruce M Simpson * 1. Redistributions of source code must retain the above copyright 95b0fe478SBruce M Simpson * notice, this list of conditions and the following disclaimer. 105b0fe478SBruce M Simpson * 2. Redistributions in binary form must reproduce the above copyright 115b0fe478SBruce M Simpson * notice, this list of conditions and the following disclaimer in the 125b0fe478SBruce M Simpson * documentation and/or other materials provided with the distribution. 135b0fe478SBruce M Simpson * 3. All advertising materials mentioning features or use of this software 145b0fe478SBruce M Simpson * must display the following acknowledgement: 155b0fe478SBruce M Simpson * This product includes software developed by the University of 165b0fe478SBruce M Simpson * California, Berkeley and its contributors. 175b0fe478SBruce M Simpson * 4. Neither the name of the University nor the names of its contributors 185b0fe478SBruce M Simpson * may be used to endorse or promote products derived from this software 195b0fe478SBruce M Simpson * without specific prior written permission. 205b0fe478SBruce M Simpson * 215b0fe478SBruce M Simpson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 225b0fe478SBruce M Simpson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 235b0fe478SBruce M Simpson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 245b0fe478SBruce M Simpson * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 255b0fe478SBruce M Simpson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 265b0fe478SBruce M Simpson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 275b0fe478SBruce M Simpson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 285b0fe478SBruce M Simpson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 295b0fe478SBruce M Simpson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 305b0fe478SBruce M Simpson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 315b0fe478SBruce M Simpson * SUCH DAMAGE. 325b0fe478SBruce M Simpson */ 335b0fe478SBruce M Simpson 345b0fe478SBruce M Simpson #ifdef HAVE_CONFIG_H 355b0fe478SBruce M Simpson #include <config.h> 365b0fe478SBruce M Simpson #endif 375b0fe478SBruce M Simpson 38*3340d773SGleb Smirnoff #include <netdissect-stdinc.h> 395b0fe478SBruce M Simpson 405b0fe478SBruce M Simpson #include <string.h> 415b0fe478SBruce M Simpson 42*3340d773SGleb Smirnoff #include "netdissect.h" 438bdc5a62SPatrick Kelsey 445b0fe478SBruce M Simpson /* 455b0fe478SBruce M Simpson * Get next token from string *stringp, where tokens are possibly-empty 465b0fe478SBruce M Simpson * strings separated by characters from delim. 475b0fe478SBruce M Simpson * 485b0fe478SBruce M Simpson * Writes NULs into the string at *stringp to end tokens. 495b0fe478SBruce M Simpson * delim need not remain constant from call to call. 505b0fe478SBruce M Simpson * On return, *stringp points past the last NUL written (if there might 515b0fe478SBruce M Simpson * be further tokens), or is NULL (if there are definitely no more tokens). 525b0fe478SBruce M Simpson * 535b0fe478SBruce M Simpson * If *stringp is NULL, strsep returns NULL. 545b0fe478SBruce M Simpson */ 555b0fe478SBruce M Simpson char * 565b0fe478SBruce M Simpson strsep(char **stringp, const char *delim) 575b0fe478SBruce M Simpson { 585b0fe478SBruce M Simpson register char *s; 595b0fe478SBruce M Simpson register const char *spanp; 605b0fe478SBruce M Simpson register int c, sc; 615b0fe478SBruce M Simpson char *tok; 625b0fe478SBruce M Simpson 635b0fe478SBruce M Simpson if ((s = *stringp) == NULL) 645b0fe478SBruce M Simpson return (NULL); 655b0fe478SBruce M Simpson for (tok = s;;) { 665b0fe478SBruce M Simpson c = *s++; 675b0fe478SBruce M Simpson spanp = delim; 685b0fe478SBruce M Simpson do { 695b0fe478SBruce M Simpson if ((sc = *spanp++) == c) { 705b0fe478SBruce M Simpson if (c == 0) 715b0fe478SBruce M Simpson s = NULL; 725b0fe478SBruce M Simpson else 735b0fe478SBruce M Simpson s[-1] = 0; 745b0fe478SBruce M Simpson *stringp = s; 755b0fe478SBruce M Simpson return (tok); 765b0fe478SBruce M Simpson } 775b0fe478SBruce M Simpson } while (sc != 0); 785b0fe478SBruce M Simpson } 795b0fe478SBruce M Simpson /* NOTREACHED */ 805b0fe478SBruce M Simpson } 81