Unity 0.7
Parser for unit strings
|
00001 /* GENERATED by Makefile.in */ 00002 /* DO NOT EDIT */ 00003 #ifndef UNITY_H_LOADED 00004 #define UNITY_H_LOADED 1 00005 /* From known-syntaxes.h */ 00006 /* KNOWN_SYNTAXES+ */ 00013 #define UNITY_SYNTAX_FITS 0 00014 00020 #define UNITY_SYNTAX_OGIP 1 00021 00027 #define UNITY_SYNTAX_CDS 2 00028 00034 #define UNITY_SYNTAX_VOU 3 00035 #ifdef UNITY_INTERNAL 00036 /* Number of syntaxes */ 00037 #define U_NSYNTAXES 4 00038 #endif 00039 /* KNOWN_SYNTAXES- */ 00040 00041 /* From unitylib.h ... */ 00042 #ifndef UNITYLIB_H_LOADED 00043 #define UNITYLIB_H_LOADED 1 00044 00049 /* forward definition -- see unit-definitions.h */ 00050 struct unit_definition; 00051 00052 /* forward definition -- see function-definitions.h */ 00053 struct function_definition; 00054 00055 struct function_application_struct { 00056 const struct function_definition* definition; /* precisely one of definition and name should be non-null */ 00057 const char* name; 00058 const struct unit_struct* operand; 00059 }; 00060 00061 struct simple_unit_struct { 00066 int prefix_power; /* -24 to +24 */ 00072 const struct unit_definition* base_unit_def; 00077 char* base_unit_string; /* eg Hz or aangstrom */ 00078 }; 00079 00080 typedef enum { 00081 simple_unit_type, function_application_type 00082 } UnitTypes; 00083 00084 struct unit_struct { 00085 UnitTypes type; 00090 float power; 00091 union { 00092 struct simple_unit_struct u; 00093 struct function_application_struct f; 00094 }; 00096 struct unit_struct *next; 00097 }; 00098 00099 00100 #if 0 00101 00105 struct unit_struct { 00110 int prefix_power; /* -24 to +24 */ 00116 const struct unit_definition* base_unit_def; 00121 char* base_unit_string; /* eg Hz or aangstrom */ 00126 float power; 00128 struct unit_struct *next; 00129 }; 00130 #endif 00131 00132 typedef struct unit_struct Unit; 00133 00137 typedef struct { 00142 float log_factor; 00146 const Unit* unit_sequence; 00147 } UnitExpression; 00148 00149 const UnitExpression* unity_parse_string(const char* unit_string, const int syntax); 00150 00151 /* unity_parse_error is defined in lex.lex */ 00162 const char* unity_parse_error(void); 00163 00164 const char** unity_parser_names(void); 00165 00166 int unity_identify_parser(const char* parser_name); 00167 const char* unity_parser_name(const int parser_id); 00168 void unity_free_expression(const UnitExpression* u); 00169 const char* unity_version_string(); 00170 int unity_version_number(); 00171 00172 /* Checking units */ 00174 #define UNITY_CHECK_RECOGNISED 1 00175 00176 #define UNITY_CHECK_RECOMMENDED 2 00177 00178 #define UNITY_CHECK_CONSTRAINTS 4 00179 00184 #define UNITY_CHECK_ALL UNITY_CHECK_RECOGNISED | UNITY_CHECK_RECOMMENDED | UNITY_CHECK_CONSTRAINTS 00185 int unity_check_unit(const Unit* u, const int syntax, const int flags); 00186 int unity_check_expression(const UnitExpression* ue, const int syntax, const int flags); 00187 00188 #ifdef UNITY_INTERNAL 00189 /* Internal functions */ 00190 Unit* u_new_unit(const char* unitString, const float power, int syntax); 00191 Unit* u_function_application(const char* functionName, 00192 const Unit* unit_sequence, 00193 int syntax); 00194 Unit* u_unit_append(Unit* u1, Unit* u2); 00195 void u_receive_result(float, const Unit* unit_sequence); 00196 int u_prefix_to_power(const char pfx); 00197 //char* u_copy_string(const char c, const char* s); 00198 Unit* u_divide_units(Unit* num, Unit* den); 00199 Unit* u_unit_reciprocal(Unit* u); 00200 void u_free_unit(const Unit* u); 00201 #endif 00202 00203 #endif 00204 /* ...end unitylib.h */ 00205 00206 /* From writers.h ... */ 00207 #ifndef WRITERS_H_LOADED 00208 #define WRITERS_H_LOADED 1 00209 00210 #include <stdio.h> 00211 00212 #ifdef UNITY_INTERNAL 00213 typedef struct { 00214 int nwritten; 00215 int len; 00216 char* buf; 00217 } Buf; 00218 typedef Buf* (*writef_ptr) (Buf*, const UnitExpression*); 00219 #endif 00220 00221 char* unity_write_formatted(char* buf, int buflen, const UnitExpression*, const char*); 00222 const char** unity_formatter_names(void); 00223 00224 #endif 00225 /* ...end writers.h */ 00226 00227 /* From unit-definitions.h ... */ 00228 #ifndef UNIT_DEFINITIONS_H 00229 #define UNIT_DEFINITIONS_H 1 00230 00231 00232 /* The functions exported by this module are the only ones which need 00233 access to the data structures dumped into this file, which are 00234 potentially subject to change. The implementation of this header 00235 file is generated by ../grammar/ParseUnits.java, using the 00236 unit-definitions.c.template file in that directory. 00237 00238 The structure elements with leading underscores are intended to be internal to 00239 this unit-definition.c module. 00240 */ 00241 00242 struct unit_definition { 00243 const char* uri; /* the name for this unit, as a URI */ 00244 int _idx; /* the internal index for this unit, in the list of unit_definition entries */ 00245 const char* name; /* the name of the unit, such as 'Metre' -- not the abbreviation 'm' */ 00246 const char* type; /* type such as 'length', as a URI */ 00247 const char* dimension; /* the dimensions of this unit, as a string, eg "M L-2" */ 00248 const char* description; /* for example 'Hz = s-1', NULL if no notes present */ 00249 const char* latex_form; /* an abbrev suitable for LaTeX, if different from a preferred syntax */ 00250 }; 00257 typedef struct unit_definition UnitDef; 00258 00259 #if UNITY_INTERNAL 00260 /* A unit_representation indicates how a particular unit may be used in a particular syntax. */ 00261 struct unit_representation { 00262 const char* symbol; /* a symbol for this unit, in one syntax */ 00263 int _unit_index; /* the index in the array of unit_definition entries */ 00264 int si_prefixes_p; /* true if this unit may be given SI prefixes */ 00265 int is_deprecated_p; /* true if this unit is deprecated */ 00266 int is_preferred_p; /* true if this unit is the preferred unit amongst some alternatives */ 00267 }; 00268 typedef struct unit_representation UnitRep; 00269 UnitRep* u_get_unit_representation(const Unit*, const int syntax); 00270 #endif 00271 00272 const UnitDef* unity_get_unit(const char* abbrev, int syntax); 00273 const char* unity_get_syntax_name(int syntax); 00274 const char* unity_get_unit_uri(const UnitDef*); 00275 const char* unity_get_unit_name(const UnitDef*); 00276 const char* unity_get_unit_type(const UnitDef*); 00277 const char* unity_get_unit_dimension(const UnitDef*); 00278 const char* unity_get_unit_description(const UnitDef*); 00279 const char* unity_get_unit_latex_form(const UnitDef*); 00280 #endif /* UNIT_DEFINITIONS_H */ 00281 /* ...end unit-definitions.h */ 00282 00283 /* From function-definitions.h ... */ 00284 #ifndef FUNCTION_DEFINITIONS_H 00285 #define FUNCTION_DEFINITIONS_H 1 00286 00287 00288 /* The functions exported by this module are the only ones which need 00289 * access to the data structures dumped into this file, which are 00290 * potentially subject to change. The implementation of this header 00291 * file is generated by ../grammar/ParseFunctions.java, using the 00292 * function-definitions.c.template file in that directory. 00293 * 00294 * The structure elements with leading underscores are intended to be internal to 00295 * this function-definition.c module. 00296 */ 00297 00298 struct function_definition { 00299 const char* description; 00300 const char* latex_form; 00301 }; 00302 typedef struct function_definition FunctionDef; 00303 00304 const FunctionDef* unity_get_function(const char* abbrev, const int syntax); 00305 const char* unity_get_function_abbreviation(const FunctionDef* def, 00306 const int syntax); 00307 00308 #endif /* FUNCTION_DEFINITIONS_H */ 00309 /* ...end function-definitions.h */ 00310 #endif