Unity  0.9
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 #ifndef KNOWN_SYNTAXES_H
7 #define KNOWN_SYNTAXES_H 1
8 
12 typedef enum {
73 } UnitySyntax;
74 
75 #if 0
76 /* XXX DELETE */
77 #ifdef UNITY_INTERNAL
78 /* Number of syntaxes */
79 #define U_NSYNTAXES 6
80 #endif
81 #endif
82 
83 #endif /* KNOWN_SYNTAXES_H */
84 
85 /* From function-definitions.h ... */
86 #ifndef FUNCTION_DEFINITIONS_H
87 #define FUNCTION_DEFINITIONS_H 1
88 
89 
90 /* The functions exported by this module are the only ones which need
91  * access to the data structures dumped into this file, which are
92  * potentially subject to change. The implementation of this header
93  * file is generated by ../grammar/ParseFunctions.java, using the
94  * function-definitions.c.template file in that directory.
95  *
96  * The structure elements with leading underscores are intended to be internal to
97  * this function-definition.c module.
98  */
99 
105  const char* description;
107  const char* latex_form;
108 };
109 typedef struct function_definition FunctionDef;
110 
111 const FunctionDef* unity_get_functiondef_from_string(const char* abbrev, UnitySyntax syntax);
112 const char* unity_get_function_abbreviation(const FunctionDef* def, UnitySyntax syntax);
113 
114 #endif /* FUNCTION_DEFINITIONS_H */
115 /* ...end function-definitions.h */
116 
117 /* From unit-definitions.h ... */
118 #ifndef UNIT_DEFINITIONS_H
119 #define UNIT_DEFINITIONS_H 1
120 
121 
122 /* The functions exported by this module are the only ones which need
123  * access to the data structures dumped into this file, which are
124  * potentially subject to change. The implementation of this header
125  * file is generated by ../grammar/ParseUnits.java, using the
126  * unit-definitions.c.template file in that directory.
127  *
128  * The structure elements with leading underscores are intended to be internal to
129  * this unit-definition.c module.
130 */
131 
138 typedef struct {
139  const char* uri; /* the name for this unit, as a URI */
140  int _idx; /* the internal index for this unit, in the list of unit_definition entries */
141  const char* name; /* the name of the unit, such as 'Metre' -- not the abbreviation 'm' */
142  const char* type; /* type such as 'length', as a URI */
143  const char* dimension; /* the dimensions of this unit, as a string, eg "M L-2" */
144  const char* description; /* for example 'Hz = s-1', NULL if no notes present */
145  const char* latex_form; /* an abbrev suitable for LaTeX, if different from a preferred syntax */
146 } UnitDef;
147 
148 //typedef struct unit_definition UnitDef;
149 
150 #if UNITY_INTERNAL
151 /* A unit_representation indicates how a particular unit may be used in a particular syntax. */
152 struct unit_representation {
153  const char* symbol; /* a symbol for this unit, in one syntax */
154  int _unit_index; /* the index in the array of unit_definition entries */
155  int si_prefixes_p; /* true if this unit may be given SI prefixes */
156  int binary_prefixes_p; /* true if this unit may be given binary prefixes */
157  int is_deprecated_p; /* true if this unit is deprecated */
158  int is_preferred_p; /* true if this unit is the preferred unit amongst some alternatives */
159 };
160 typedef struct unit_representation UnitRep;
161 UnitRep* u_get_unit_representation(const UnitDef*, UnitySyntax syntax);
162 UnitRep* u_get_unit_representation_any(const UnitDef*);
163 #endif
164 
165 const UnitDef* unity_get_unitdef_from_string(const char* abbrev, UnitySyntax syntax);
166 const char* unity_get_syntax_name(UnitySyntax syntax);
167 const char* unity_get_unit_uri(const UnitDef*);
168 const char* unity_get_unit_name(const UnitDef*);
169 const char* unity_get_unit_type(const UnitDef*);
170 const char* unity_get_unit_dimension(const UnitDef*);
171 const char* unity_get_unit_description(const UnitDef*);
172 const char* unity_get_unit_latex_form(const UnitDef*);
173 #endif /* UNIT_DEFINITIONS_H */
174 /* ...end unit-definitions.h */
175 
176 /* From unitylib.h ... */
177 #ifndef UNITYLIB_H_LOADED
178 #define UNITYLIB_H_LOADED 1
179 
188 typedef struct {
193  float log_factor;
197  const struct unit_struct* unit_sequence;
198 
199  /* a sorted version of the unit_sequence */
200  struct unit_struct** sorted_unit_sequence;
201  int nunits;
203 
210 typedef struct {
216  const char* name;
218  //const struct unit_struct* operand;
221 
225 typedef struct {
230  int prefix_power; /* -24 to +24 */
235  char base10_p;
246  char* base_unit_string; /* eg Hz or aangstrom */
247 } SimpleUnit;
248 
252 typedef enum {
257 } UnitTypes;
258 
274 struct unit_struct {
279  float power;
286  union {
291  };
293  struct unit_struct *next;
294 
301 };
302 
303 
305 typedef struct unit_struct Unit;
306 
307 const UnitExpression* unity_parse_string(const char* unit_string, const UnitySyntax syntax);
308 
309 /* The function unity_parse_error is declared (and documented) here,
310  and defined in lex.lex */
321 const char* unity_parse_error(void);
322 
323 const char** unity_parser_names(void);
324 
325 UnitySyntax unity_identify_parser(const char* parser_name);
326 const char* unity_parser_name(const UnitySyntax parser_id);
328 const char* unity_version_string();
330 
331 /* Selecting units (convenience functions, since the UnitExpression struct is open */
332 const Unit* unity_get_unit_by_index(const UnitExpression*, int i);
335 
336 /* Checking units */
338 #define UNITY_CHECK_RECOGNISED 1
339 
340 #define UNITY_CHECK_RECOMMENDED 2
341 
342 #define UNITY_CHECK_CONSTRAINTS 4
343 
348 #define UNITY_CHECK_ALL UNITY_CHECK_RECOGNISED | UNITY_CHECK_RECOMMENDED | UNITY_CHECK_CONSTRAINTS
349 int unity_check_unit(const Unit* u, const UnitySyntax syntax, const int flags);
350 int unity_check_expression(const UnitExpression* ue, const UnitySyntax syntax, const int flags);
351 int unity_equal_unit_p(const Unit*, const Unit*);
353 
354 #ifdef UNITY_INTERNAL
355 /* Internal functions */
356 Unit* u_new_unit(const char* unitString, const float power, const UnitySyntax syntax);
357 Unit* u_quoted_unit(const char* pfx, const char* unitString,
358  const float power, UnitySyntax syntax);
359 Unit* u_function_application(const char* functionName,
360  const Unit* unit_sequence,
361  const UnitySyntax syntax,
362  char is_quoted);
363 Unit* u_unit_append(Unit* u1, const Unit* u2);
364 void u_receive_result(float, const Unit* unit_sequence);
365 int u_prefix_to_power(const char pfx);
366 Unit* u_divide_units(Unit* num, Unit* den);
367 Unit* u_unit_reciprocal(Unit* u);
368 void u_free_unit(const Unit* u);
369 Unit** u_get_sorted_unit_sequence(UnitExpression*, int*);
370 #endif
371 
372 #endif
373 /* ...end unitylib.h */
374 
375 /* From writers.h ... */
376 #ifndef WRITERS_H_LOADED
377 #define WRITERS_H_LOADED 1
378 
379 #include <stdio.h>
380 
381 #ifdef UNITY_INTERNAL
382 typedef struct {
383  int nwritten;
384  int len;
385  char* buf;
386 } Buf;
387 typedef Buf* (*writef_ptr) (Buf*, const UnitExpression*);
388 #endif
389 
390 char* unity_write_formatted(char* buf, int buflen, const UnitExpression*, UnitySyntax);
391 const char** unity_formatter_names(void);
392 
393 #endif
394 /* ...end writers.h */
395 #endif