imapext-2007

view src/ansilib/strtok.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
line source
1 /* ========================================================================
2 * Copyright 1988-2007 University of Washington
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *
11 * ========================================================================
12 */
14 /*
15 * Program: String return successive tokens
16 *
17 * Author: Mark Crispin
18 * Networks and Distributed Computing
19 * Computing & Communications
20 * University of Washington
21 * Administration Building, AG-44
22 * Seattle, WA 98195
23 *
24 * Date: 11 May 1989
25 * Last Edited: 30 January 2007
26 */
28 /* Find token in string
29 * Accepts: source pointer or NIL to use previous source
30 * vector of token delimiters pointer
31 * Returns: pointer to next token
32 */
34 static char *state = NIL; /* string to locate tokens */
36 char *strtok (char *s,char *ct)
37 {
38 return strtok_r (s,ct,&state);/* jacket into reentrant routine */
39 }
42 /* Find token in string (reentrant)
43 * Accepts: source pointer or NIL to use previous source
44 * vector of token delimiters pointer
45 * returned state pointer
46 * Returns: pointer to next token
47 */
49 char *strtok_r (char *s,char *ct,char **r)
50 {
51 char *t,*ts;
52 if (!s) s = *r; /* use previous token if none specified */
53 *r = NIL; /* default to no returned state */
54 if (!(s && *s)) return NIL; /* no tokens left */
55 /* find any leading delimiters */
56 do for (t = ct, ts = NIL; *t; t++) if (*t == *s) {
57 if (*(ts = ++s)) break; /* yes, restart search if more in string */
58 return NIL; /* else no more tokens */
59 } while (ts); /* continue until no more leading delimiters */
60 /* can we find a new delimiter? */
61 for (ts = s; *ts; ts++) for (t = ct; *t; t++) if (*t == *ts) {
62 *ts++ = '\0'; /* yes, tie off token at that point */
63 *r = ts; /* save subsequent tokens for future call */
64 return s; /* return our token */
65 }
66 return s; /* return final token */
67 }

UW-IMAP'd extensions by yuuji