blob: 152ebc1086ae9a80fffffe31390bf3d10ba7615d [file] [log] [blame]
Michal Krol0e7b1d82004-03-03 18:10:40 +00001#ifndef GRAMMAR_H
2#define GRAMMAR_H
3
4
5#ifndef GRAMMAR_PORT_INCLUDE
6#error Do not include this file directly, include your grammar_XXX.h instead
7#endif
8
9
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14void grammar_alloc_free (void *);
15void *grammar_alloc_malloc (unsigned int);
16void *grammar_alloc_realloc (void *, unsigned int, unsigned int);
17void *grammar_memory_copy (void *, const void *, unsigned int);
18int grammar_string_compare (const byte *, const byte *);
19int grammar_string_compare_n (const byte *, const byte *, unsigned int);
20byte *grammar_string_copy (byte *, const byte *);
21byte *grammar_string_copy_n (byte *, const byte *, unsigned int);
22byte *grammar_string_duplicate (const byte *);
23unsigned int grammar_string_length (const byte *);
24
25/*
26 loads grammar script from null-terminated ASCII <text>
27 returns unique grammar id to grammar object
28 returns 0 if an error occurs (call grammar_get_last_error to retrieve the error text)
29*/
30grammar grammar_load_from_text (const byte *text);
31
32/*
33 sets a new <value> to a register <name> for grammar <id>
34 returns 0 on error (call grammar_get_last_error to retrieve the error text)
35 returns 1 on success
36*/
37int grammar_set_reg8 (grammar id, const byte *name, byte value);
38
39/*
40 checks if a null-terminated <text> matches given grammar <id>
41 returns 0 on error (call grammar_get_last_error to retrieve the error text)
42 returns 1 on success, the <prod> points to newly allocated buffer with production and <size>
43 is filled with the production size
44 call grammar_alloc_free to free the memory block pointed by <prod>
45*/
46int grammar_check (grammar id, const byte *text, byte **prod, unsigned int *size);
47
48/*
49 destroys grammar object identified by <id>
50 returns 0 on error (call grammar_get_last_error to retrieve the error text)
51 returns 1 on success
52*/
53int grammar_destroy (grammar id);
54
55/*
56 retrieves last grammar error reported either by grammar_load_from_text, grammar_check
57 or grammar_destroy
58 the user allocated <text> buffer receives error description, <pos> points to error position,
59 <size> is the size of the text buffer to fill in - it must be at least 4 bytes long,
60*/
61void grammar_get_last_error (byte *text, unsigned int size, int *pos);
62
63#ifdef __cplusplus
64}
65#endif
66
67#endif
68