File: support.c

package info (click to toggle)
sident 3.6-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,960 kB
  • ctags: 719
  • sloc: sh: 8,131; ansic: 6,784; makefile: 231; perl: 147
file content (52 lines) | stat: -rw-r--r-- 933 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*  $Id: support.c 550 2004-06-17 01:27:41Z eagle $
**
**  Support utilities for libsident.
**
**  Written by Pr Emanuelsson <pell@lysator.liu.se>
**  Modifications by Peter Eriksson <pen@lysator.liu.se>
*/

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "sident.h"

char *
id_strtok(char *cp, char *cs, char *dc)
{
    static char *bp = 0;

    if (cp != NULL)
        bp = cp;

    /* No delimitor cs - return whole buffer and point at end. */
    if (cs == NULL) {
        while (*bp)
            bp++;
        return cs;
    }

    /* Skip leading spaces. */
    while (isspace(*bp))
        bp++;

    /* No token found? */
    if (*bp == '\0')
        return 0;

    cp = bp;
    while (*bp && !strchr(cs, *bp))
        bp++;

    /* Remove trailing spaces. */
    *dc = *bp;
    for (dc = bp - 1; dc > cp && isspace(*dc); dc--)
        ;
    *++dc = '\0';

    bp++;

    return cp;
}