Unity 0.5
Parser for unit strings
unity.h
Go to the documentation of this file.
00001 #ifndef UNITY_H_LOADED
00002 #define UNITY_H_LOADED 1
00003 
00004 /* From known-syntaxes.h ... */
00005 /* KNOWN_SYNTAXES+ */
00011 #define UNITY_SYNTAX_FITS 0
00012 
00017 #define UNITY_SYNTAX_OGIP 1
00018 
00023 #define UNITY_SYNTAX_CDS 2
00024 #ifdef UNITY_INTERNAL
00025 /* Number of syntaxes */
00026 #define U_NSYNTAXES 3
00027 #endif
00028 /* KNOWN_SYNTAXES- */
00029 /* ...end known-syntaxes.h */
00030 
00031 /* From unitylib.h ... */
00032 #ifndef UNITYLIB_H_LOADED
00033 #define UNITYLIB_H_LOADED 1
00034 
00039 /* forward definition -- see unit-definition.h */
00040 struct unit_definition;
00041 
00046 struct unit_struct {
00051     int prefix_power;           /* -24 to +24 */
00057     const struct unit_definition* base_unit_def;
00062     char* base_unit_string;     /* eg Hz or aangstrom */
00067     float power;
00069     struct unit_struct *next;
00070 };
00072 typedef struct unit_struct Unit;
00073 
00077 typedef struct {
00082     float log_factor;
00086     Unit* unit_sequence;
00087 } UnitExpression;
00088 
00089 const UnitExpression* unity_parse_string(const char* unit_string, const int syntax);
00090 /* unity_parse_error is defined in lex.lex */
00099 const char* unity_parse_error(void);
00100 const char** unity_parser_names(void);
00101 
00102 int unity_identify_parser(const char* parser_name);
00103 const char* unity_parser_name(const int parser_id);
00104 void unity_free_expression(const UnitExpression* u);
00105 const char* unity_version_string();
00106 int unity_version_number();
00107 
00108 /* Checking units */
00109 #define UNITY_CHECK_RECOGNISED 1
00110 #define UNITY_CHECK_RECOMMENDED 2
00111 #define UNITY_CHECK_CONSTRAINTS 4
00112 #define UNITY_CHECK_ALL UNITY_CHECK_RECOGNISED | UNITY_CHECK_RECOMMENDED | UNITY_CHECK_CONSTRAINTS
00113 int unity_check_unit(const Unit* u, const int syntax, const int flags);
00114 int unity_check_expression(const UnitExpression* ue, const int syntax, const int flags);
00115 
00116 #ifdef UNITY_INTERNAL
00117 /* Internal functions */
00118 Unit* u_new_unit(const char* unitString, const float power, int syntax);
00119 Unit* u_unit_append(Unit* u1, Unit* u2);
00120 void u_receive_result(float, Unit* unit_sequence);
00121 int u_prefix_to_power(const char pfx);
00122 //char* u_copy_string(const char c, const char* s);
00123 Unit* u_divide_units(Unit* num, Unit* den);
00124 Unit* u_unit_reciprocal(Unit* u);
00125 void u_free_unit(Unit* u);
00126 #endif
00127 
00128 #endif
00129 /* ...end unitylib.h */
00130 
00131 /* From writers.h ... */
00132 #ifndef WRITERS_H_LOADED
00133 #define WRITERS_H_LOADED 1
00134 
00135 #include <stdio.h>
00136 
00137 #ifdef UNITY_INTERNAL
00138 typedef char* (*writef_ptr) (char*, int, const UnitExpression*);
00139 #endif
00140 
00141 char* unity_write_formatted(char* buf, int buflen, const UnitExpression*, const char*);
00142 const char** unity_formatter_names(void);
00143 
00144 #endif
00145 /* ...end writers.h */
00146 
00147 /* From unit-definitions.h ... */
00148 #ifndef UNIT_DEFINITIONS_H
00149 #define UNIT_DEFINITIONS_H 1
00150 
00151 
00152 /* The functions exported by this module are the only ones which need
00153    access to the data structures dumped into this file, which are
00154    potentially subject to change.  The implementation of this header
00155    file is generated by ../grammar/ParseUnits.java, using the
00156    unit-definitions.c.template file in that directory.
00157 
00158    The structure elements with leading underscores are intended to be internal to
00159    this unit-definition.c module.
00160 */
00161 
00162 struct unit_definition {
00163     const char* uri;            /* the name for this unit, as a URI */
00164     int _idx;                   /* the internal index for this unit, in the list of unit_definition entries */
00165     const char* name; /* the name of the unit, such as 'Metre' -- not the abbreviation 'm' */
00166     const char* type; /* type such as 'length', as a URI */
00167     const char* dimension; /* the dimensions of this unit, as a string, eg "M L-2" */
00168     const char* description; /* for example 'Hz = s-1', NULL if no notes present */
00169     const char* latex_form; /* an abbrev suitable for LaTeX, if different from a preferred syntax */
00170 };
00171 typedef struct unit_definition UnitDef;
00172 
00173 #if UNITY_INTERNAL
00174 /* A unit_representation indicates how a particular unit may be used in a particular syntax. */
00175 struct unit_representation {
00176     const char* symbol;         /* a symbol for this unit, in one syntax */
00177     int _unit_index;            /* the index in the array of unit_definition entries */
00178     int si_prefixes_p;          /* true if this unit may be given SI prefixes */
00179     int is_deprecated_p;        /* true if this unit is deprecated */
00180     int is_preferred_p;         /* true if this unit is the preferred unit amongst some alternatives */
00181 };
00182 typedef struct unit_representation UnitRep;
00183 UnitRep* u_get_unit_representation(const Unit*, const int syntax);
00184 #endif
00185 
00186 const UnitDef* unity_get_unit(const char* abbrev, int syntax);
00187 const char* unity_get_syntax_name(int syntax);
00188 const char* unity_get_unit_uri(UnitDef*);
00189 const char* unity_get_unit_name(UnitDef*);
00190 const char* unity_get_unit_type(UnitDef*);
00191 const char* unity_get_unit_dimension(UnitDef*);
00192 const char* unity_get_unit_description(UnitDef*);
00193 const char* unity_get_unit_latex_form(UnitDef*);
00194 #endif /* UNIT_DEFINITIONS_H */
00195 /* ...end unit-definitions.h */
00196 #endif
 All Data Structures Files Functions Variables Typedefs Defines