/[LeafOK_CVS]/pvpgn-1.7.4/src/common/token.c
ViewVC logotype

Annotation of /pvpgn-1.7.4/src/common/token.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (vendor branch)
Tue Jun 6 03:41:38 2006 UTC (19 years, 9 months ago) by sysadm
Branch: GNU, MAIN
CVS Tags: arelease, HEAD
Changes since 1.1: +0 -0 lines
Content type: text/x-csrc
no message

1 sysadm 1.1 /*
2     * Copyright (C) 2001 Rob Crittenden (rcrit@greyoak.com)
3     * Copyright (C) 2001 Ross Combs (rocombs@cs.nmsu.edu)
4     *
5     * This program is free software; you can redistribute it and/or
6     * modify it under the terms of the GNU General Public License
7     * as published by the Free Software Foundation; either version 2
8     * of the License, or (at your option) any later version.
9     *
10     * This program is distributed in the hope that it will be useful,
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     * GNU General Public License for more details.
14     *
15     * You should have received a copy of the GNU General Public License
16     * along with this program; if not, write to the Free Software
17     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18     */
19     #define PREFS_INTERNAL_ACCESS
20     #include "common/setup_before.h"
21     #include <stdio.h>
22     #ifdef HAVE_STDDEF_H
23     # include <stddef.h>
24     #else
25     # ifndef NULL
26     # define NULL ((void *)0)
27     # endif
28     #endif
29     #ifdef STDC_HEADERS
30     # include <stdlib.h>
31     #else
32     # ifdef HAVE_MALLOC_H
33     # include <malloc.h>
34     # endif
35     #endif
36     #ifdef HAVE_STRING_H
37     # include <string.h>
38     #else
39     # ifdef HAVE_STRINGS_H
40     # include <strings.h>
41     # endif
42     #endif
43     #include <ctype.h>
44     #include "token.h"
45     #include "common/eventlog.h"
46     #include "common/setup_after.h"
47    
48     /*
49     * Given a string and an integer pointer skip past pos characters and return
50     * the next white-space delimited string, setting pos to the new position.
51     */
52     extern char * next_token(char * ptr, unsigned int * pos)
53     {
54     unsigned int i;
55     unsigned int start;
56     int quoted;
57    
58     if (!ptr || !pos)
59     return NULL;
60    
61     /* skip leading whitespace */
62     for (i=*pos; isspace((int)ptr[i]); i++);
63    
64     if (ptr[i]=='\0')
65     return NULL; /* if after whitespace, we're done */
66    
67     if (ptr[i]=='"')
68     {
69     quoted = 1;
70     i++;
71     }
72     else
73     quoted = 0;
74    
75     start = i;
76     for (;;)
77     {
78     if (ptr[i]=='\0')
79     break;
80     if (quoted) /* FIXME: add handling of escape chars so quotes can be in tokens */
81     {
82     if (ptr[i]=='"')
83     break;
84     }
85     else
86     if (isspace((int)ptr[i]))
87     break;
88     i++;
89     }
90    
91     if (ptr[i]!='\0')
92     {
93     ptr[i] = '\0'; /* terminate the string */
94     *pos = i+1; /* remember the position of the next char */
95     }
96     else
97     *pos = i; /* this was the last token, just remember the NUL */
98    
99     return &ptr[start];
100     }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1