1 |
/* Copyright (C) 2001-2003 Stephane Thiell <mbuna@undernet.org> |
2 |
* |
3 |
* This file is part of pxyservd (from pxys) |
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 |
*/ |
20 |
#ifndef INCLUDED_TOKENIZER_H |
21 |
#define INCLUDED_TOKENIZER_H |
22 |
|
23 |
/* Zero copy tokenizer: one use only, max tokens not extensible at run time, |
24 |
* and modify the original buffer (must be mutable). You still want to use it? |
25 |
* Originally written for the pxys v1 IRC parser. |
26 |
*/ |
27 |
|
28 |
struct toktab |
29 |
{ |
30 |
char **tok; /* Array of char pointers to each word (token) of the string */ |
31 |
int size; /* Size of the array (the number of words) */ |
32 |
}; |
33 |
|
34 |
typedef struct toktab toktab; |
35 |
typedef struct toktab * toktabptr; |
36 |
|
37 |
#define tokenizer_malloc memory_alloc |
38 |
#define tokenizer_free memory_free |
39 |
|
40 |
/* Initialize tokenizer */ |
41 |
extern void tokenizer_init(); |
42 |
|
43 |
/* Destroy tokenizer */ |
44 |
extern void tokenizer_destroy(); |
45 |
|
46 |
/* Do the tokenization from a mutable buffer, but no more than maxtok tokens. |
47 |
* Ownership of original buffer is momentarily transfered to the tokenizer, you |
48 |
* shouldn't modify it until the end of tokenizer operations. |
49 |
*/ |
50 |
extern toktabptr tokenize(char *s, int maxtok); |
51 |
|
52 |
/* Untokenize a toktabptr: restore original buffer content |
53 |
* Still zerocopy. Use the original buffer too |
54 |
*/ |
55 |
extern char* untokenize(toktabptr ttab, int start); |
56 |
|
57 |
#endif /* INCLUDED_TOKENIZER_H */ |