Unity  0.8
Parser for unit strings
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
unity.h
Go to the documentation of this file.
1 /* GENERATED by Makefile.in */
2 /* DO NOT EDIT */
3 #ifndef UNITY_H_LOADED
4 #define UNITY_H_LOADED 1
5 /* From known-syntaxes.h */
6 /* KNOWN_SYNTAXES+ */
13 #define UNITY_SYNTAX_FITS 0
14 
20 #define UNITY_SYNTAX_OGIP 1
21 
27 #define UNITY_SYNTAX_CDS 2
28 
34 #define UNITY_SYNTAX_VOUNITS 3
35 #ifdef UNITY_INTERNAL
36 /* Number of syntaxes */
37 #define U_NSYNTAXES 4
38 #endif
39 /* KNOWN_SYNTAXES- */
40 
41 /* From unitylib.h ... */
42 #ifndef UNITYLIB_H_LOADED
43 #define UNITYLIB_H_LOADED 1
44 
49 /* forward definition -- see unit-definitions.h */
50 struct unit_definition;
51 
52 /* forward definition -- see function-definitions.h */
53 struct function_definition;
54 
61 typedef struct {
64  const struct function_definition* definition;
67  const char* name;
69  const struct unit_struct* operand;
71 
75 typedef struct {
80  int prefix_power; /* -24 to +24 */
85  int base10_p;
91  const struct unit_definition* base_unit_def;
96  char* base_unit_string; /* eg Hz or aangstrom */
97 } SimpleUnit;
98 
101 typedef enum {
106 } UnitTypes;
107 
113 struct unit_struct {
118  float power;
125  union {
130  };
132  struct unit_struct *next;
133 };
134 
135 
137 typedef struct unit_struct Unit;
138 
142 typedef struct {
147  float log_factor;
153 
154 const UnitExpression* unity_parse_string(const char* unit_string, const int syntax);
155 
156 /* The function unity_parse_error is declared (and documented) here,
157  and defined in lex.lex */
168 const char* unity_parse_error(void);
169 
170 const char** unity_parser_names(void);
171 
172 int unity_identify_parser(const char* parser_name);
173 const char* unity_parser_name(const int parser_id);
175 const char* unity_version_string();
177 
178 /* Checking units */
180 #define UNITY_CHECK_RECOGNISED 1
181 
182 #define UNITY_CHECK_RECOMMENDED 2
183 
184 #define UNITY_CHECK_CONSTRAINTS 4
185 
190 #define UNITY_CHECK_ALL UNITY_CHECK_RECOGNISED | UNITY_CHECK_RECOMMENDED | UNITY_CHECK_CONSTRAINTS
191 int unity_check_unit(const Unit* u, const int syntax, const int flags);
192 int unity_check_expression(const UnitExpression* ue, const int syntax, const int flags);
193 
194 #ifdef UNITY_INTERNAL
195 /* Internal functions */
196 Unit* u_new_unit(const char* unitString, const float power, int syntax);
197 Unit* u_function_application(const char* functionName,
198  const Unit* unit_sequence,
199  int syntax);
200 Unit* u_unit_append(Unit* u1, Unit* u2);
201 void u_receive_result(float, const Unit* unit_sequence);
202 int u_prefix_to_power(const char pfx);
203 //char* u_copy_string(const char c, const char* s);
204 Unit* u_divide_units(Unit* num, Unit* den);
205 Unit* u_unit_reciprocal(Unit* u);
206 void u_free_unit(const Unit* u);
207 #endif
208 
209 #endif
210 /* ...end unitylib.h */
211 
212 /* From writers.h ... */
213 #ifndef WRITERS_H_LOADED
214 #define WRITERS_H_LOADED 1
215 
216 #include <stdio.h>
217 
218 #ifdef UNITY_INTERNAL
219 typedef struct {
220  int nwritten;
221  int len;
222  char* buf;
223 } Buf;
224 typedef Buf* (*writef_ptr) (Buf*, const UnitExpression*);
225 #endif
226 
227 char* unity_write_formatted(char* buf, int buflen, const UnitExpression*, const char*);
228 const char** unity_formatter_names(void);
229 
230 #endif
231 /* ...end writers.h */
232 
233 /* From unit-definitions.h ... */
234 #ifndef UNIT_DEFINITIONS_H
235 #define UNIT_DEFINITIONS_H 1
236 
237 
238 /* The functions exported by this module are the only ones which need
239  access to the data structures dumped into this file, which are
240  potentially subject to change. The implementation of this header
241  file is generated by ../grammar/ParseUnits.java, using the
242  unit-definitions.c.template file in that directory.
243 
244  The structure elements with leading underscores are intended to be internal to
245  this unit-definition.c module.
246 */
247 
248 struct unit_definition {
249  const char* uri; /* the name for this unit, as a URI */
250  int _idx; /* the internal index for this unit, in the list of unit_definition entries */
251  const char* name; /* the name of the unit, such as 'Metre' -- not the abbreviation 'm' */
252  const char* type; /* type such as 'length', as a URI */
253  const char* dimension; /* the dimensions of this unit, as a string, eg "M L-2" */
254  const char* description; /* for example 'Hz = s-1', NULL if no notes present */
255  const char* latex_form; /* an abbrev suitable for LaTeX, if different from a preferred syntax */
256 };
263 typedef struct unit_definition UnitDef;
264 
265 #if UNITY_INTERNAL
266 /* A unit_representation indicates how a particular unit may be used in a particular syntax. */
267 struct unit_representation {
268  const char* symbol; /* a symbol for this unit, in one syntax */
269  int _unit_index; /* the index in the array of unit_definition entries */
270  int si_prefixes_p; /* true if this unit may be given SI prefixes */
271  int binary_prefixes_p; /* true if this unit may be given binary prefixes */
272  int is_deprecated_p; /* true if this unit is deprecated */
273  int is_preferred_p; /* true if this unit is the preferred unit amongst some alternatives */
274 };
275 typedef struct unit_representation UnitRep;
276 UnitRep* u_get_unit_representation(const Unit*, const int syntax);
277 #endif
278 
279 const UnitDef* unity_get_unit(const char* abbrev, int syntax);
280 const char* unity_get_syntax_name(int syntax);
281 const char* unity_get_unit_uri(const UnitDef*);
282 const char* unity_get_unit_name(const UnitDef*);
283 const char* unity_get_unit_type(const UnitDef*);
284 const char* unity_get_unit_dimension(const UnitDef*);
285 const char* unity_get_unit_description(const UnitDef*);
286 const char* unity_get_unit_latex_form(const UnitDef*);
287 #endif /* UNIT_DEFINITIONS_H */
288 /* ...end unit-definitions.h */
289 
290 /* From function-definitions.h ... */
291 #ifndef FUNCTION_DEFINITIONS_H
292 #define FUNCTION_DEFINITIONS_H 1
293 
294 
295 /* The functions exported by this module are the only ones which need
296  * access to the data structures dumped into this file, which are
297  * potentially subject to change. The implementation of this header
298  * file is generated by ../grammar/ParseFunctions.java, using the
299  * function-definitions.c.template file in that directory.
300  *
301  * The structure elements with leading underscores are intended to be internal to
302  * this function-definition.c module.
303  */
304 
305 struct function_definition {
306  const char* description;
307  const char* latex_form;
308 };
309 typedef struct function_definition FunctionDef;
310 
311 const FunctionDef* unity_get_function(const char* abbrev, const int syntax);
312 const char* unity_get_function_abbreviation(const FunctionDef* def,
313  const int syntax);
314 
315 #endif /* FUNCTION_DEFINITIONS_H */
316 /* ...end function-definitions.h */
317 #endif