8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / krb5 / kadmin / dbutil / strtok.c
blobce9258e5176979643d8d2d047324d7b7fc2de23b
1 /*
2 * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
4 */
6 /*
7 * Copyright (c) 1988 Regents of the University of California.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms are permitted
11 * provided that: (1) source distributions retain this entire copyright
12 * notice and comment, and (2) distributions including binaries display
13 * the following acknowledgement: ``This product includes software
14 * developed by the University of California, Berkeley and its contributors''
15 * in the documentation or other materials provided with the distribution
16 * and in all advertising materials mentioning features or use of this
17 * software. Neither the name of the University nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25 #pragma ident "%Z%%M% %I% %E% SMI"
27 #include <stddef.h>
28 #include <string.h>
29 #include "nstrtok.h"
32 * Function: nstrtok
34 * Purpose: the same as strtok ... just different. does not deal with
35 * multiple tokens in row.
37 * Arguments:
38 * s (input) string to scan
39 * delim (input) list of delimiters
40 * <return value> string or null on error.
42 * Requires:
43 * nuttin
45 * Effects:
46 * sets last to string
48 * Modifies:
49 * last
53 char *
54 nstrtok(s, delim)
55 register char *s;
56 register const char *delim;
58 register const char *spanp;
59 register int c, sc;
60 char *tok;
61 static char *last;
64 if (s == NULL && (s = last) == NULL)
65 return (NULL);
68 * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
70 #ifdef OLD
71 cont:
72 c = *s++;
73 for (spanp = delim; (sc = *spanp++) != 0;) {
74 if (c == sc)
75 goto cont;
78 if (c == 0) { /* no non-delimiter characters */
79 last = NULL;
80 return (NULL);
82 tok = s - 1;
83 #else
84 tok = s;
85 #endif
88 * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
89 * Note that delim must have one NUL; we stop if we see that, too.
91 for (;;) {
92 c = *s++;
93 spanp = delim;
94 do {
95 if ((sc = *spanp++) == c) {
96 if (c == 0)
97 s = NULL;
98 else
99 s[-1] = 0;
100 last = s;
101 return (tok);
103 } while (sc != 0);
105 /* NOTREACHED */