File: parser.h

package info (click to toggle)
motor 2%3A3.2.2-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,196 kB
  • ctags: 2,153
  • sloc: cpp: 13,649; ansic: 3,732; sh: 509; makefile: 379; sed: 93
file content (224 lines) | stat: -rw-r--r-- 6,615 bytes parent folder | download | duplicates (3)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* parser.h - Parser functions
*
* Copyright (C) 1999-2001 by Roman Khnykin <romaroma@rr.org.ua>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* Created:	22.06.1999	romaroma	Initial revision.
* Changed:	05.03.2000	romaroma	Documentation added.
* Changed:	06.03.2000	romaroma	Changed mechanism of parse
*						svalue tag.
* Changed:	30.03.2000	romaroma	Changed to version 1.2.0
* Changed:	19.07.2000	romaroma	Changed to version 1.3.1
* Changed:	02.08.2000	romaroma	Changed to version 1.3.2
* Changed:	09.08.2000	romaroma	Changed to version 1.3.3
* Changed:	17.08.2000	romaroma	Changed to version 1.4.0
* Changed:	23.08.2000	romaroma	Changed to version 1.4.1
* Changed:	04.09.2000	romaroma	Changed to version 1.4.2
*
*/

#ifndef _PARSER_H
#define _PARSER_H

#ifdef __cplusplus
extern "C" {
#endif 

#include <stdio.h>
#include "parlist.h"

/*****************************************************************************/
/* External parser data */
/*****************************************************************************/

/*
* parser_file_base - string which will add to any included file name
*/
extern char *parser_file_base;

/*
* parser_extension_proc - Procedure for process external tags
* 
* Parameters:
*	char *tag - language command
*	char *params - command parameters
*	pparamslist *params - current parameters list
*	void out_proc - pointer to procedure for output text
*
* Return value:
* 	none
*/
extern void (*parser_extension_proc)(const char *tag, const char *tagparams,
    pparamslist *params, void out_proc(const char *txt, int len));

/***** value/svalue tag *****/
/*
* parser_svalue_proc - Type of procedure for process special value ("svalue")
*	tag.
* WARNING: This function must allocate new string for result returning.
* 
* Parameters:
*	char *value - value fetched from svalue command
*	char *key - key fetched from svalue command
*
* Return value:
*	char * - new string (or NULL if no match key found).
*/
typedef char * (parser_svalue_proc) (const char *value, const char *key);

/*
* parser_svalue_reg, parser_svalue_unreg - Add/remove procedure for process
*	special value ("svalue") tag.
* WARNING: Registered function must allocate new string for result returning.
* 
* Parameters:
*	parser_svalue_proc *proc - procedure address
*
* Return value:
* 	none
*/
void parser_svalue_reg(parser_svalue_proc *proc);
void parser_svalue_unreg(parser_svalue_proc *proc);

/***** exec tag *****/
/*
* parser_exec_proc - Type of procedure that will be
* 	executed by exec tag
* 
* Parameters:
*	int argc - count of parameters in exec tag
*	char *argv[] - parameters, specified in exec tag
*
* Return value:
*	none
*/
typedef void (parser_exec_proc) (int argc, const char *argv[]);

/*
* parser_exec_reg, parser_exec_unreg - Add/remove procedure that will be
* 	executed by exec tag
* 
* Parameters:
*	char *procname - procedure name for exec tag
*	parser_exec_proc *proc - procedure address
*
* Return value:
* 	none
*/
void parser_exec_reg(char *procname, parser_exec_proc *proc);
void parser_exec_unreg(char *procname);

/*****************************************************************************/
/* Parser functions */
/*****************************************************************************/

/*
* fstrparse - Parse source string and put parsed data to file.
* 
* Parameters:
*	char *plainText - source string
*	pparamslist *params - parameters list
*	FILE *f - file for output parsed data
*
* Return value:
* 	none
*/
void fstrparse(const char *plainText, pparamslist *params, FILE *f);

/*
* fstrparse - Parse source string and put parsed data to string.
* WARNING: This function can process memory allocation.
* 
* Parameters:
*	char *plainText - source string
*	pparamslist *params - parameters list
*
* Return value:
* 	char * - parsed string location
*/
char *sstrparse(const char *plainText, pparamslist *params);

/*
* strparse - Parse process function. It can get source text from string or load
* 	it from file. Also it has two methods of loading included files: read
* 	files into memory or use mmap to load theys.
* WARNING: This function can process memory allocation.
* 
* Parameters:
*	char *fileNameOrSrc - specify file name for parsing or prevousely
* 		loaded source text.
*	char *sizeNameOrSrc - if fileNameOrSrc specified text in memory this
* 		parameter is specify text length. For NULL-terminated string
* 		it can be -1.
*	pparamslist *params - parameters list
* 	FILE *outFile - output file or NULL for allocate new string with result
* 	int srcMode - what is in fileNameOrSrc parameter: filename or loaded
* 		text
* 	int loadMode - which mechanism will be used for files loading: load to
* 		memory or use mmap
*
* Return value:
* 	char * - parsed string location or NULL if parsed to file
*/
#define PARSER_SRC_STR		0
#define PARSER_SRC_FILE		1

#define PARSER_FLOAD_MEM	0
#define PARSER_FLOAD_MMAP	1

char *strparse(const char *fileNameOrSrc, int sizeNameOrSrc, pparamslist *params,
    FILE *outFile, int srcMode, int loadMode);

/*
* loadTextFromFile - load text from file using loading method (memory or mmap)
*
* WARNING: This function can process memory allocation.
* 
* Parameters:
*	char *filename - name of file
* 	int loadMode - which mechanism will be used for files loading: load to
* 		memory or use mmap
* 	int *size - pointer to int where loaded data size will be stored
*
* Return value:
* 	char * - loaded text location or NULL if load fails
*/
char *loadTextFromFile(const char *filename, int loadMode, int *size);

/*
* unloadTextFromFile - unload text from memory or mmap file
*
* WARNING: This function can process memory reallocation.
* 
* Parameters:
*	char *text - prevousely loaded text location
* 	int loadMode - which mechanism will be used for unloading: free memory
* 		or munmap
* 	int size - size of text
*
* Return value:
* 	none
*/
void unloadTextFromFile(char *text, int loadMode, int size);

#ifdef __cplusplus
}
#endif 

#endif
 /* _PARSER_H */