Michal Krol | 0e7b1d8 | 2004-03-03 18:10:40 +0000 | [diff] [blame] | 1 | #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
|
| 11 | extern "C" {
|
| 12 | #endif
|
| 13 |
|
| 14 | void grammar_alloc_free (void *);
|
| 15 | void *grammar_alloc_malloc (unsigned int);
|
| 16 | void *grammar_alloc_realloc (void *, unsigned int, unsigned int);
|
| 17 | void *grammar_memory_copy (void *, const void *, unsigned int);
|
| 18 | int grammar_string_compare (const byte *, const byte *);
|
| 19 | int grammar_string_compare_n (const byte *, const byte *, unsigned int);
|
| 20 | byte *grammar_string_copy (byte *, const byte *);
|
| 21 | byte *grammar_string_copy_n (byte *, const byte *, unsigned int);
|
| 22 | byte *grammar_string_duplicate (const byte *);
|
| 23 | unsigned 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 | */
|
| 30 | grammar 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 | */
|
| 37 | int 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 | */
|
| 46 | int 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 | */
|
| 53 | int 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 | */
|
| 61 | void grammar_get_last_error (byte *text, unsigned int size, int *pos);
|
| 62 |
|
| 63 | #ifdef __cplusplus
|
| 64 | }
|
| 65 | #endif
|
| 66 |
|
| 67 | #endif
|
| 68 |
|