units-filter-3.5.orig/0000755000175000017500000000000011626235643015153 5ustar georgeskgeorgeskunits-filter-3.5.orig/COPYING0000644000175000017500000004306711222440702016202 0ustar georgeskgeorgesk GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy 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., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. units-filter-3.5.orig/README0000644000175000017500000000243711222440702016023 0ustar georgeskgeorgesk ------------------------------------------- Units-filter V0.9 ------------------------------------------- (c)2000 G. Khaznadar ------------------------------------------- Units-filter is a basic standalone filter written in C language, flex and bison. It inputs strings like "1.5e3 µN.m.s^-1" (it could be the time growth ratio of a torque) and outputs the value in standard SI unit, followed by the physical dimension of this value. example :~/src$ echo 1.5e3 µN.m.s^-1 | units-filter 0.0015 2 1 -3 0 0 0 0 example :~/src$ 2 -3 which means : 0.0015 (SI unit) m .kg.s When the input is not successfully parsed, the filter fails with the exit code 1. This filter can be embedded in educational test systems, in order to analyze a student's answer to a problem of physics or chemistry. This software snippet is GPL, see the file COPYING. Feedback is welcome. -- Georges. ----------------------------------------------------------- INSTALLATION ----------------------------------------------------------- inside the src/ subdirectory, run "make". You can try the script units-test to see some typical inputs and outputs. units-filter-3.5.orig/src/0000755000175000017500000000000011626235616015742 5ustar georgeskgeorgeskunits-filter-3.5.orig/src/lex.yy.c0000644000175000017500000015215111250735145017336 0ustar georgeskgeorgesk #line 3 "lex.yy.c" #define YY_INT_ALIGNED short int /* A lexical scanner generated by flex */ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 #define YY_FLEX_SUBMINOR_VERSION 35 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif /* First, we deal with platform-specific or compiler-specific issues. */ /* begin standard C headers. */ #include #include #include #include /* end standard C headers. */ /* flex integer type definitions */ #ifndef FLEXINT_H #define FLEXINT_H /* C99 systems have . Non-C99 systems may or may not. */ #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, * if you want the limit (max/min) macros for int types. */ #ifndef __STDC_LIMIT_MACROS #define __STDC_LIMIT_MACROS 1 #endif #include typedef int8_t flex_int8_t; typedef uint8_t flex_uint8_t; typedef int16_t flex_int16_t; typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; #else typedef signed char flex_int8_t; typedef short int flex_int16_t; typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; /* Limits of integral types. */ #ifndef INT8_MIN #define INT8_MIN (-128) #endif #ifndef INT16_MIN #define INT16_MIN (-32767-1) #endif #ifndef INT32_MIN #define INT32_MIN (-2147483647-1) #endif #ifndef INT8_MAX #define INT8_MAX (127) #endif #ifndef INT16_MAX #define INT16_MAX (32767) #endif #ifndef INT32_MAX #define INT32_MAX (2147483647) #endif #ifndef UINT8_MAX #define UINT8_MAX (255U) #endif #ifndef UINT16_MAX #define UINT16_MAX (65535U) #endif #ifndef UINT32_MAX #define UINT32_MAX (4294967295U) #endif #endif /* ! C99 */ #endif /* ! FLEXINT_H */ #ifdef __cplusplus /* The "const" storage-class-modifier is valid. */ #define YY_USE_CONST #else /* ! __cplusplus */ /* C99 requires __STDC__ to be defined as 1. */ #if defined (__STDC__) #define YY_USE_CONST #endif /* defined (__STDC__) */ #endif /* ! __cplusplus */ #ifdef YY_USE_CONST #define yyconst const #else #define yyconst #endif /* Returned upon end-of-file. */ #define YY_NULL 0 /* Promotes a possibly negative, possibly signed char to an unsigned * integer for use as an array index. If the signed char is negative, * we want to instead treat it as an 8-bit unsigned char, hence the * double cast. */ #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. */ #define BEGIN (yy_start) = 1 + 2 * /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ #define YY_START (((yy_start) - 1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ #define YY_NEW_FILE yyrestart(yyin ) #define YY_END_OF_BUFFER_CHAR 0 /* Size of default input buffer. */ #ifndef YY_BUF_SIZE #ifdef __ia64__ /* On IA-64, the buffer size is 16k, not 8k. * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. * Ditto for the __ia64__ case accordingly. */ #define YY_BUF_SIZE 32768 #else #define YY_BUF_SIZE 16384 #endif /* __ia64__ */ #endif /* The state buf must be large enough to hold one state per character in the main buffer. */ #define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) #ifndef YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif extern int yyleng; extern FILE *yyin, *yyout; #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 #define YY_LESS_LINENO(n) /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ do \ { \ /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ *yy_cp = (yy_hold_char); \ YY_RESTORE_YY_MORE_OFFSET \ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) #define unput(c) yyunput( c, (yytext_ptr) ) #ifndef YY_TYPEDEF_YY_SIZE_T #define YY_TYPEDEF_YY_SIZE_T typedef size_t yy_size_t; #endif #ifndef YY_STRUCT_YY_BUFFER_STATE #define YY_STRUCT_YY_BUFFER_STATE struct yy_buffer_state { FILE *yy_input_file; char *yy_ch_buf; /* input buffer */ char *yy_buf_pos; /* current position in input buffer */ /* Size of input buffer in bytes, not including room for EOB * characters. */ yy_size_t yy_buf_size; /* Number of characters read into yy_ch_buf, not including EOB * characters. */ int yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to * delete it. */ int yy_is_our_buffer; /* Whether this is an "interactive" input source; if so, and * if we're using stdio for input, then we want to use getc() * instead of fread(), to make sure we stop fetching input after * each newline. */ int yy_is_interactive; /* Whether we're considered to be at the beginning of a line. * If so, '^' rules will be active on the next match, otherwise * not. */ int yy_at_bol; int yy_bs_lineno; /**< The line count. */ int yy_bs_column; /**< The column count. */ /* Whether to try to fill the input buffer when we reach the * end of it. */ int yy_fill_buffer; int yy_buffer_status; #define YY_BUFFER_NEW 0 #define YY_BUFFER_NORMAL 1 /* When an EOF's been seen but there's still some text to process * then we mark the buffer as YY_EOF_PENDING, to indicate that we * shouldn't try reading from the input source any more. We might * still have a bunch of tokens to match, though, because of * possible backing-up. * * When we actually see the EOF, we change the status to "new" * (via yyrestart()), so that the user can continue scanning by * just pointing yyin at a new input file. */ #define YY_BUFFER_EOF_PENDING 2 }; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ /* Stack of input buffers. */ static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general * "scanner state". * * Returns the top of the stack, or NULL. */ #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] /* yy_hold_char holds the character lost when yytext is formed. */ static char yy_hold_char; static int yy_n_chars; /* number of characters read into yy_ch_buf */ int yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = (char *) 0; static int yy_init = 0; /* whether we need to initialize */ static int yy_start = 0; /* start state number */ /* Flag which is used to allow yywrap()'s to do buffer switches * instead of setting up a fresh yyin. A bit of a hack ... */ static int yy_did_buffer_switch_on_eof; void yyrestart (FILE *input_file ); void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); void yy_delete_buffer (YY_BUFFER_STATE b ); void yy_flush_buffer (YY_BUFFER_STATE b ); void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); void yypop_buffer_state (void ); static void yyensure_buffer_stack (void ); static void yy_load_buffer_state (void ); static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); #define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); void *yyalloc (yy_size_t ); void *yyrealloc (void *,yy_size_t ); void yyfree (void * ); #define yy_new_buffer yy_create_buffer #define yy_set_interactive(is_interactive) \ { \ if ( ! YY_CURRENT_BUFFER ){ \ yyensure_buffer_stack (); \ YY_CURRENT_BUFFER_LVALUE = \ yy_create_buffer(yyin,YY_BUF_SIZE ); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } #define yy_set_bol(at_bol) \ { \ if ( ! YY_CURRENT_BUFFER ){\ yyensure_buffer_stack (); \ YY_CURRENT_BUFFER_LVALUE = \ yy_create_buffer(yyin,YY_BUF_SIZE ); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } #define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) #define yywrap(n) 1 #define YY_SKIP_YYWRAP typedef unsigned char YY_CHAR; FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; typedef int yy_state_type; extern int yylineno; int yylineno = 1; extern char *yytext; #define yytext_ptr yytext static yy_state_type yy_get_previous_state (void ); static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); static int yy_get_next_buffer (void ); static void yy_fatal_error (yyconst char msg[] ); /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION \ (yytext_ptr) = yy_bp; \ yyleng = (size_t) (yy_cp - yy_bp); \ (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; #define YY_NUM_RULES 55 #define YY_END_OF_BUFFER 56 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info { flex_int32_t yy_verify; flex_int32_t yy_nxt; }; static yyconst flex_int16_t yy_accept[113] = { 0, 0, 0, 56, 53, 48, 54, 53, 39, 53, 53, 36, 37, 1, 52, 8, 53, 17, 35, 21, 35, 24, 15, 9, 43, 13, 53, 35, 20, 22, 18, 16, 53, 5, 42, 35, 35, 53, 6, 2, 43, 4, 53, 53, 7, 44, 47, 53, 38, 33, 34, 48, 0, 0, 36, 37, 52, 0, 0, 49, 40, 0, 1, 36, 37, 1, 0, 0, 52, 27, 28, 12, 0, 14, 29, 23, 0, 0, 32, 0, 11, 35, 46, 25, 26, 0, 0, 0, 0, 31, 0, 50, 41, 9, 49, 0, 0, 1, 0, 0, 1, 19, 45, 3, 10, 30, 47, 50, 50, 51, 0, 51, 0 } ; static yyconst flex_int32_t yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 4, 1, 5, 1, 6, 1, 1, 1, 7, 1, 8, 9, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 1, 1, 1, 1, 1, 1, 13, 14, 15, 1, 16, 17, 18, 19, 1, 20, 21, 22, 23, 24, 25, 26, 1, 1, 27, 28, 1, 29, 30, 1, 23, 23, 1, 1, 1, 31, 1, 1, 32, 33, 34, 35, 36, 23, 37, 38, 39, 1, 23, 40, 41, 42, 43, 23, 44, 45, 46, 47, 48, 49, 1, 50, 51, 52, 1, 1, 1, 53, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 54, 1, 55, 56, 1, 23, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } ; static yyconst flex_int32_t yy_meta[57] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } ; static yyconst flex_int16_t yy_base[113] = { 0, 0, 0, 177, 178, 55, 178, 165, 169, 50, 163, 171, 170, 61, 169, 178, 126, 178, 178, 178, 118, 116, 178, 178, 178, 178, 129, 134, 116, 178, 178, 131, 67, 178, 131, 127, 129, 131, 178, 178, 30, 40, 121, 126, 112, 178, 114, 143, 53, 178, 178, 80, 142, 144, 149, 148, 147, 91, 137, 74, 178, 89, 94, 145, 144, 79, 134, 105, 142, 178, 178, 178, 102, 178, 178, 178, 112, 131, 130, 95, 178, 178, 178, 178, 178, 97, 97, 91, 93, 178, 95, 107, 178, 178, 123, 115, 83, 120, 127, 113, 110, 178, 178, 178, 178, 178, 178, 104, 102, 99, 68, 58, 178 } ; static yyconst flex_int16_t yy_def[113] = { 0, 112, 1, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 0 } ; static yyconst flex_int16_t yy_nxt[235] = { 0, 4, 5, 6, 7, 4, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 18, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 18, 42, 4, 43, 44, 45, 46, 4, 4, 18, 18, 47, 48, 49, 50, 51, 61, 52, 111, 62, 53, 65, 54, 55, 92, 56, 93, 76, 66, 83, 62, 109, 77, 77, 94, 67, 78, 85, 84, 65, 51, 86, 52, 59, 57, 53, 109, 54, 55, 95, 56, 76, 110, 67, 65, 67, 77, 77, 96, 111, 78, 66, 107, 62, 107, 98, 58, 107, 67, 57, 99, 99, 76, 67, 100, 95, 108, 77, 77, 100, 65, 78, 100, 94, 96, 106, 105, 98, 67, 97, 101, 58, 99, 99, 67, 104, 100, 103, 102, 78, 78, 101, 68, 97, 64, 63, 91, 68, 64, 63, 61, 59, 91, 90, 67, 89, 88, 87, 82, 81, 80, 79, 75, 74, 73, 72, 71, 70, 69, 68, 64, 63, 62, 60, 59, 112, 3, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112 } ; static yyconst flex_int16_t yy_chk[235] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 9, 5, 111, 9, 5, 13, 5, 5, 48, 5, 48, 32, 13, 40, 13, 110, 32, 32, 59, 13, 32, 41, 40, 65, 51, 41, 51, 59, 5, 51, 96, 51, 51, 61, 51, 57, 96, 65, 62, 13, 57, 57, 61, 109, 57, 62, 108, 62, 107, 67, 5, 91, 62, 51, 67, 67, 76, 65, 67, 95, 91, 76, 76, 100, 97, 76, 99, 94, 95, 90, 88, 98, 62, 97, 87, 51, 98, 98, 97, 86, 98, 85, 79, 78, 77, 72, 68, 66, 64, 63, 58, 56, 55, 54, 53, 52, 47, 46, 97, 44, 43, 42, 37, 36, 35, 34, 31, 28, 27, 26, 21, 20, 16, 14, 12, 11, 10, 8, 7, 3, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112, 112 } ; static yy_state_type yy_last_accepting_state; static char *yy_last_accepting_cpos; extern int yy_flex_debug; int yy_flex_debug = 0; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. */ #define REJECT reject_used_but_not_detected #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET char *yytext; #line 1 "unites.l" /* coding: iso-8859-1 */ #include #include "unites.h" /* les nombres */ /*quelques séparateurs particuliers*/ /* les unités de temps hors système */ /* les unités du SI */ /* Handbook of Chemistry & Physics 78, CRC Press 1997, page 1-20 */ /* unités annexes, voir page 1-22 */ /* prefixes sauf milli et téra */ /* Handbook of Chemistry & Physics 78, CRC Press 1997, page 1-21 */ /* notation des exposants */ #line 562 "lex.yy.c" #define INITIAL 0 #ifndef YY_NO_UNISTD_H /* Special case for "unistd.h", since it is non-ANSI. We include it way * down here because we want the user's section 1 to have been scanned first. * The user has a chance to override it with an option. */ #include #endif #ifndef YY_EXTRA_TYPE #define YY_EXTRA_TYPE void * #endif static int yy_init_globals (void ); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ int yylex_destroy (void ); int yyget_debug (void ); void yyset_debug (int debug_flag ); YY_EXTRA_TYPE yyget_extra (void ); void yyset_extra (YY_EXTRA_TYPE user_defined ); FILE *yyget_in (void ); void yyset_in (FILE * in_str ); FILE *yyget_out (void ); void yyset_out (FILE * out_str ); int yyget_leng (void ); char *yyget_text (void ); int yyget_lineno (void ); void yyset_lineno (int line_number ); /* Macros after this point can all be overridden by user definitions in * section 1. */ #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus extern "C" int yywrap (void ); #else extern int yywrap (void ); #endif #endif static void yyunput (int c,char *buf_ptr ); #ifndef yytext_ptr static void yy_flex_strncpy (char *,yyconst char *,int ); #endif #ifdef YY_NEED_STRLEN static int yy_flex_strlen (yyconst char * ); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (void ); #else static int input (void ); #endif #endif /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE #ifdef __ia64__ /* On IA-64, the buffer size is 16k, not 8k */ #define YY_READ_BUF_SIZE 16384 #else #define YY_READ_BUF_SIZE 8192 #endif /* __ia64__ */ #endif /* Copy whatever the last rule matched to the standard output. */ #ifndef ECHO /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ #define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, * is returned in "result". */ #ifndef YY_INPUT #define YY_INPUT(buf,result,max_size) \ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ size_t n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ if ( c == '\n' ) \ buf[n++] = (char) c; \ if ( c == EOF && ferror( yyin ) ) \ YY_FATAL_ERROR( "input in flex scanner failed" ); \ result = n; \ } \ else \ { \ errno=0; \ while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ { \ if( errno != EINTR) \ { \ YY_FATAL_ERROR( "input in flex scanner failed" ); \ break; \ } \ errno=0; \ clearerr(yyin); \ } \ }\ \ #endif /* No semi-colon after return; correct usage is to write "yyterminate();" - * we don't want an extra ';' after the "return" because that will cause * some compilers to complain about unreachable statements. */ #ifndef yyterminate #define yyterminate() return YY_NULL #endif /* Number of entries by which start-condition stack grows. */ #ifndef YY_START_STACK_INCR #define YY_START_STACK_INCR 25 #endif /* Report a fatal error. */ #ifndef YY_FATAL_ERROR #define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) #endif /* end tables serialization structures and prototypes */ /* Default declaration of generated scanner - a define so the user can * easily add parameters. */ #ifndef YY_DECL #define YY_DECL_IS_OURS 1 extern int yylex (void); #define YY_DECL int yylex (void) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng * have been set up. */ #ifndef YY_USER_ACTION #define YY_USER_ACTION #endif /* Code executed at the end of each rule. */ #ifndef YY_BREAK #define YY_BREAK break; #endif #define YY_RULE_SETUP \ YY_USER_ACTION /** The main scanner function which does all the work. */ YY_DECL { register yy_state_type yy_current_state; register char *yy_cp, *yy_bp; register int yy_act; #line 83 "unites.l" #line 753 "lex.yy.c" if ( !(yy_init) ) { (yy_init) = 1; #ifdef YY_USER_INIT YY_USER_INIT; #endif if ( ! (yy_start) ) (yy_start) = 1; /* first start state */ if ( ! yyin ) yyin = stdin; if ( ! yyout ) yyout = stdout; if ( ! YY_CURRENT_BUFFER ) { yyensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin,YY_BUF_SIZE ); } yy_load_buffer_state( ); } while ( 1 ) /* loops until end-of-file is reached */ { yy_cp = (yy_c_buf_p); /* Support of yytext. */ *yy_cp = (yy_hold_char); /* yy_bp points to the position in yy_ch_buf of the start of * the current run. */ yy_bp = yy_cp; yy_current_state = (yy_start); yy_match: do { register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; (yy_last_accepting_cpos) = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 113 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } while ( yy_base[yy_current_state] != 178 ); yy_find_action: yy_act = yy_accept[yy_current_state]; if ( yy_act == 0 ) { /* have to back up */ yy_cp = (yy_last_accepting_cpos); yy_current_state = (yy_last_accepting_state); yy_act = yy_accept[yy_current_state]; } YY_DO_BEFORE_ACTION; do_action: /* This label is used only to access EOF actions. */ switch ( yy_act ) { /* beginning of action switch */ case 0: /* must back up */ /* undo the effects of YY_DO_BEFORE_ACTION */ *yy_cp = (yy_hold_char); yy_cp = (yy_last_accepting_cpos); yy_current_state = (yy_last_accepting_state); goto yy_find_action; case 1: YY_RULE_SETUP #line 86 "unites.l" { val_real = atof1(yytext); yylval.v=strdup(yytext); pos+=yyleng; return REAL;} YY_BREAK case 2: YY_RULE_SETUP #line 87 "unites.l" { pos+=yyleng; return Uh;} YY_BREAK case 3: YY_RULE_SETUP #line 88 "unites.l" { pos+=yyleng; return Umin;} YY_BREAK case 4: YY_RULE_SETUP #line 89 "unites.l" { pos+=yyleng; return Um;} YY_BREAK case 5: YY_RULE_SETUP #line 90 "unites.l" {pos+=yyleng; return Uare;} YY_BREAK case 6: YY_RULE_SETUP #line 91 "unites.l" { pos+=yyleng; return Ug;} YY_BREAK case 7: YY_RULE_SETUP #line 92 "unites.l" { pos+=yyleng; return Us;} YY_BREAK case 8: YY_RULE_SETUP #line 93 "unites.l" { pos+=yyleng; return UA;} YY_BREAK case 9: YY_RULE_SETUP #line 94 "unites.l" { pos+=yyleng; return UK;} YY_BREAK case 10: YY_RULE_SETUP #line 95 "unites.l" { pos+=yyleng; return Umol;} YY_BREAK case 11: YY_RULE_SETUP #line 96 "unites.l" { pos+=yyleng; return Ucd;} YY_BREAK case 12: YY_RULE_SETUP #line 97 "unites.l" { pos+=yyleng; return UHz;} YY_BREAK case 13: YY_RULE_SETUP #line 98 "unites.l" { pos+=yyleng; return UN;} YY_BREAK case 14: YY_RULE_SETUP #line 99 "unites.l" { pos+=yyleng; return UPa;} YY_BREAK case 15: YY_RULE_SETUP #line 100 "unites.l" { pos+=yyleng; return UJ;} YY_BREAK case 16: YY_RULE_SETUP #line 101 "unites.l" { pos+=yyleng; return UW;} YY_BREAK case 17: YY_RULE_SETUP #line 102 "unites.l" { pos+=yyleng; return UC;} YY_BREAK case 18: YY_RULE_SETUP #line 103 "unites.l" { pos+=yyleng; return UV;} YY_BREAK case 19: YY_RULE_SETUP #line 104 "unites.l" { pos+=yyleng; return Uohm;} YY_BREAK case 20: YY_RULE_SETUP #line 105 "unites.l" { pos+=yyleng; return US;} YY_BREAK case 21: YY_RULE_SETUP #line 106 "unites.l" { pos+=yyleng; return UF;} YY_BREAK case 22: YY_RULE_SETUP #line 107 "unites.l" { pos+=yyleng; return UT;} YY_BREAK case 23: YY_RULE_SETUP #line 108 "unites.l" { pos+=yyleng; return UWb;} YY_BREAK case 24: YY_RULE_SETUP #line 109 "unites.l" { pos+=yyleng; return UH;} YY_BREAK case 25: YY_RULE_SETUP #line 110 "unites.l" { pos+=yyleng; return Ulm;} YY_BREAK case 26: YY_RULE_SETUP #line 111 "unites.l" { pos+=yyleng; return Ulx;} YY_BREAK case 27: YY_RULE_SETUP #line 112 "unites.l" { pos+=yyleng; return UBq;} YY_BREAK case 28: YY_RULE_SETUP #line 113 "unites.l" { pos+=yyleng; return UGy;} YY_BREAK case 29: YY_RULE_SETUP #line 114 "unites.l" { pos+=yyleng; return USv;} YY_BREAK case 30: YY_RULE_SETUP #line 115 "unites.l" { pos+=yyleng; return Urad;} YY_BREAK case 31: YY_RULE_SETUP #line 116 "unites.l" { pos+=yyleng; return Usr;} YY_BREAK case 32: YY_RULE_SETUP #line 117 "unites.l" { pos+=yyleng; while (!index("-0123456789", *yytext)) yytext++; return PUIS;} YY_BREAK case 33: YY_RULE_SETUP #line 118 "unites.l" { yytext="2"; pos+=yyleng; return PUIS;} YY_BREAK case 34: YY_RULE_SETUP #line 119 "unites.l" { yytext="3"; pos+=yyleng; return PUIS;} YY_BREAK case 35: YY_RULE_SETUP #line 120 "unites.l" { pos+=yyleng; return PP;} YY_BREAK case 36: YY_RULE_SETUP #line 121 "unites.l" { pos+=yyleng; return POINT;} YY_BREAK case 37: YY_RULE_SETUP #line 122 "unites.l" { pos+=yyleng; return BARRE;} YY_BREAK case 38: YY_RULE_SETUP #line 123 "unites.l" {pos+=yyleng; return Uda;} YY_BREAK case 39: YY_RULE_SETUP #line 124 "unites.l" {pos+=yyleng; return Uma;} YY_BREAK case 40: YY_RULE_SETUP #line 125 "unites.l" {pos+=yyleng; return Usa;} YY_BREAK case 41: YY_RULE_SETUP #line 126 "unites.l" {pos+=yyleng; return Uangs;} YY_BREAK case 42: YY_RULE_SETUP #line 127 "unites.l" {pos+=yyleng; return Ubarn;} YY_BREAK case 43: YY_RULE_SETUP #line 128 "unites.l" { pos+=yyleng; return Ul;} YY_BREAK case 44: YY_RULE_SETUP #line 129 "unites.l" {pos+=yyleng; return Ut;} YY_BREAK case 45: YY_RULE_SETUP #line 130 "unites.l" {pos+=yyleng; return Ubar;} YY_BREAK case 46: YY_RULE_SETUP #line 131 "unites.l" {pos+=yyleng; return UeV;} YY_BREAK case 47: YY_RULE_SETUP #line 132 "unites.l" {pos+=yyleng; return Uuam;} YY_BREAK case 48: YY_RULE_SETUP #line 133 "unites.l" { pos+=yyleng; return SPC;} YY_BREAK case 49: YY_RULE_SETUP #line 134 "unites.l" {pos+=yyleng; val_int=atoi(strchr(yytext,'#')+1); return Signif;} YY_BREAK case 50: YY_RULE_SETUP #line 135 "unites.l" {pos+=yyleng; val_int=atoi(strchr(yytext,'~')+1); return PlusminPC;} YY_BREAK case 51: YY_RULE_SETUP #line 136 "unites.l" {pos+=yyleng; val_int=atoi(strchr(yytext,'+')+2); return PlusminPC;} YY_BREAK case 52: YY_RULE_SETUP #line 137 "unites.l" {pos+=yyleng; return COLON;} YY_BREAK case 53: YY_RULE_SETUP #line 139 "unites.l" pos+=yyleng; YY_BREAK case 54: /* rule 54 can match eol */ YY_RULE_SETUP #line 140 "unites.l" pos+=yyleng; YY_BREAK case 55: YY_RULE_SETUP #line 141 "unites.l" ECHO; YY_BREAK #line 1112 "lex.yy.c" case YY_STATE_EOF(INITIAL): yyterminate(); case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ *yy_cp = (yy_hold_char); YY_RESTORE_YY_MORE_OFFSET if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) { /* We're scanning a new file or input source. It's * possible that this happened because the user * just pointed yyin at a new source and called * yylex(). If so, then we have to assure * consistency between YY_CURRENT_BUFFER and our * globals. Here is the right place to do so, because * this is the first action (other than possibly a * back-up) that will match for the new input source. */ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; } /* Note that here we test for yy_c_buf_p "<=" to the position * of the first EOB in the buffer, since yy_c_buf_p will * already have been incremented past the NUL character * (since all states make transitions on EOB to the * end-of-buffer state). Contrast this with the test * in input(). */ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) { /* This was really a NUL. */ yy_state_type yy_next_state; (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; yy_current_state = yy_get_previous_state( ); /* Okay, we're now positioned to make the NUL * transition. We couldn't have * yy_get_previous_state() go ahead and do it * for us because it doesn't know how to deal * with the possibility of jamming (and we don't * want to build jamming into it because then it * will run more slowly). */ yy_next_state = yy_try_NUL_trans( yy_current_state ); yy_bp = (yytext_ptr) + YY_MORE_ADJ; if ( yy_next_state ) { /* Consume the NUL. */ yy_cp = ++(yy_c_buf_p); yy_current_state = yy_next_state; goto yy_match; } else { yy_cp = (yy_c_buf_p); goto yy_find_action; } } else switch ( yy_get_next_buffer( ) ) { case EOB_ACT_END_OF_FILE: { (yy_did_buffer_switch_on_eof) = 0; if ( yywrap( ) ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up * yytext, we can now set up * yy_c_buf_p so that if some total * hoser (like flex itself) wants to * call the scanner after we return the * YY_NULL, it'll still work - another * YY_NULL will get returned. */ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; yy_act = YY_STATE_EOF(YY_START); goto do_action; } else { if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; } break; } case EOB_ACT_CONTINUE_SCAN: (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; yy_current_state = yy_get_previous_state( ); yy_cp = (yy_c_buf_p); yy_bp = (yytext_ptr) + YY_MORE_ADJ; goto yy_match; case EOB_ACT_LAST_MATCH: (yy_c_buf_p) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; yy_current_state = yy_get_previous_state( ); yy_cp = (yy_c_buf_p); yy_bp = (yytext_ptr) + YY_MORE_ADJ; goto yy_find_action; } break; } default: YY_FATAL_ERROR( "fatal flex scanner internal error--no action found" ); } /* end of action switch */ } /* end of scanning one token */ } /* end of yylex */ /* yy_get_next_buffer - try to read in a new buffer * * Returns a code representing an action: * EOB_ACT_LAST_MATCH - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ static int yy_get_next_buffer (void) { register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; register char *source = (yytext_ptr); register int number_to_move, i; int ret_val; if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) YY_FATAL_ERROR( "fatal flex scanner internal error--end of buffer missed" ); if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) { /* Don't try to fill the buffer, so this is an EOF. */ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) { /* We matched a single character, the EOB, so * treat this as a final EOF. */ return EOB_ACT_END_OF_FILE; } else { /* We matched some text prior to the EOB, first * process it. */ return EOB_ACT_LAST_MATCH; } } /* Try to read more data. */ /* First move last chars to start of buffer. */ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) /* don't do the read, it's not guaranteed to return an EOF, * just force an EOF */ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; else { int num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) { /* Not enough room in the buffer - grow it. */ /* just a shorter name for the current buffer */ YY_BUFFER_STATE b = YY_CURRENT_BUFFER; int yy_c_buf_p_offset = (int) ((yy_c_buf_p) - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { int new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; else b->yy_buf_size *= 2; b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); } else /* Can't grow it, we don't own it. */ b->yy_ch_buf = 0; if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; } if ( num_to_read > YY_READ_BUF_SIZE ) num_to_read = YY_READ_BUF_SIZE; /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), (yy_n_chars), (size_t) num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } if ( (yy_n_chars) == 0 ) { if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; yyrestart(yyin ); } else { ret_val = EOB_ACT_LAST_MATCH; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_EOF_PENDING; } } else ret_val = EOB_ACT_CONTINUE_SCAN; if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); } (yy_n_chars) += number_to_move; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ static yy_state_type yy_get_previous_state (void) { register yy_state_type yy_current_state; register char *yy_cp; yy_current_state = (yy_start); for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) { register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; (yy_last_accepting_cpos) = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 113 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; } return yy_current_state; } /* yy_try_NUL_trans - try to make a transition on the NUL character * * synopsis * next_state = yy_try_NUL_trans( current_state ); */ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) { register int yy_is_jam; register char *yy_cp = (yy_c_buf_p); register YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { (yy_last_accepting_state) = yy_current_state; (yy_last_accepting_cpos) = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; if ( yy_current_state >= 113 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_is_jam = (yy_current_state == 112); return yy_is_jam ? 0 : yy_current_state; } static void yyunput (int c, register char * yy_bp ) { register char *yy_cp; yy_cp = (yy_c_buf_p); /* undo effects of setting up yytext */ *yy_cp = (yy_hold_char); if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) { /* need to shift things up to make room */ /* +2 for EOB chars. */ register int number_to_move = (yy_n_chars) + 2; register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; register char *source = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) *--dest = *--source; yy_cp += (int) (dest - source); yy_bp += (int) (dest - source); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) YY_FATAL_ERROR( "flex scanner push-back overflow" ); } *--yy_cp = (char) c; (yytext_ptr) = yy_bp; (yy_hold_char) = *yy_cp; (yy_c_buf_p) = yy_cp; } #ifndef YY_NO_INPUT #ifdef __cplusplus static int yyinput (void) #else static int input (void) #endif { int c; *(yy_c_buf_p) = (yy_hold_char); if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) { /* yy_c_buf_p now points to the character we want to return. * If this occurs *before* the EOB characters, then it's a * valid NUL; if not, then we've hit the end of the buffer. */ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) /* This was really a NUL. */ *(yy_c_buf_p) = '\0'; else { /* need more input */ int offset = (yy_c_buf_p) - (yytext_ptr); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) { case EOB_ACT_LAST_MATCH: /* This happens because yy_g_n_b() * sees that we've accumulated a * token and flags that we need to * try matching the token before * proceeding. But for input(), * there's no matching to consider. * So convert the EOB_ACT_LAST_MATCH * to EOB_ACT_END_OF_FILE. */ /* Reset buffer status. */ yyrestart(yyin ); /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { if ( yywrap( ) ) return EOF; if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; #ifdef __cplusplus return yyinput(); #else return input(); #endif } case EOB_ACT_CONTINUE_SCAN: (yy_c_buf_p) = (yytext_ptr) + offset; break; } } } c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ *(yy_c_buf_p) = '\0'; /* preserve yytext */ (yy_hold_char) = *++(yy_c_buf_p); return c; } #endif /* ifndef YY_NO_INPUT */ /** Immediately switch to a different input stream. * @param input_file A readable stream. * * @note This function does not reset the start condition to @c INITIAL . */ void yyrestart (FILE * input_file ) { if ( ! YY_CURRENT_BUFFER ){ yyensure_buffer_stack (); YY_CURRENT_BUFFER_LVALUE = yy_create_buffer(yyin,YY_BUF_SIZE ); } yy_init_buffer(YY_CURRENT_BUFFER,input_file ); yy_load_buffer_state( ); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. * */ void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) { /* TODO. We should be able to replace this entire function body * with * yypop_buffer_state(); * yypush_buffer_state(new_buffer); */ yyensure_buffer_stack (); if ( YY_CURRENT_BUFFER == new_buffer ) return; if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ *(yy_c_buf_p) = (yy_hold_char); YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } YY_CURRENT_BUFFER_LVALUE = new_buffer; yy_load_buffer_state( ); /* We don't actually know whether we did this switch during * EOF (yywrap()) processing, but the only time this flag * is looked at is after yywrap() is called, so it's safe * to go ahead and always set it. */ (yy_did_buffer_switch_on_eof) = 1; } static void yy_load_buffer_state (void) { (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; (yy_hold_char) = *(yy_c_buf_p); } /** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. * * @return the allocated buffer state. */ YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) { YY_BUFFER_STATE b; b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_buf_size = size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_is_our_buffer = 1; yy_init_buffer(b,file ); return b; } /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() * */ void yy_delete_buffer (YY_BUFFER_STATE b ) { if ( ! b ) return; if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) yyfree((void *) b->yy_ch_buf ); yyfree((void *) b ); } #ifndef __cplusplus extern int isatty (int ); #endif /* __cplusplus */ /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. */ static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) { int oerrno = errno; yy_flush_buffer(b ); b->yy_input_file = file; b->yy_fill_buffer = 1; /* If b is the current buffer, then yy_init_buffer was _probably_ * called from yyrestart() or through yy_get_next_buffer. * In that case, we don't want to reset the lineno or column. */ if (b != YY_CURRENT_BUFFER){ b->yy_bs_lineno = 1; b->yy_bs_column = 0; } b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; errno = oerrno; } /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. * */ void yy_flush_buffer (YY_BUFFER_STATE b ) { if ( ! b ) return; b->yy_n_chars = 0; /* We always need two end-of-buffer characters. The first causes * a transition to the end-of-buffer state. The second causes * a jam in that state. */ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; b->yy_buf_pos = &b->yy_ch_buf[0]; b->yy_at_bol = 1; b->yy_buffer_status = YY_BUFFER_NEW; if ( b == YY_CURRENT_BUFFER ) yy_load_buffer_state( ); } /** Pushes the new state onto the stack. The new state becomes * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. * */ void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) { if (new_buffer == NULL) return; yyensure_buffer_stack(); /* This block is copied from yy_switch_to_buffer. */ if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ *(yy_c_buf_p) = (yy_hold_char); YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); } /* Only push if top exists. Otherwise, replace top. */ if (YY_CURRENT_BUFFER) (yy_buffer_stack_top)++; YY_CURRENT_BUFFER_LVALUE = new_buffer; /* copied from yy_switch_to_buffer. */ yy_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. * */ void yypop_buffer_state (void) { if (!YY_CURRENT_BUFFER) return; yy_delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; if ((yy_buffer_stack_top) > 0) --(yy_buffer_stack_top); if (YY_CURRENT_BUFFER) { yy_load_buffer_state( ); (yy_did_buffer_switch_on_eof) = 1; } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ static void yyensure_buffer_stack (void) { int num_to_alloc; if (!(yy_buffer_stack)) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); if ( ! (yy_buffer_stack) ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; (yy_buffer_stack_top) = 0; return; } if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ /* Increase the buffer to prepare for a possible push. */ int grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc ((yy_buffer_stack), num_to_alloc * sizeof(struct yy_buffer_state*) ); if ( ! (yy_buffer_stack) ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); /* zero only the new slots.*/ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); (yy_buffer_stack_max) = num_to_alloc; } } /** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer * * @return the newly allocated buffer state object. */ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) { YY_BUFFER_STATE b; if ( size < 2 || base[size-2] != YY_END_OF_BUFFER_CHAR || base[size-1] != YY_END_OF_BUFFER_CHAR ) /* They forgot to leave room for the EOB's. */ return 0; b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ b->yy_buf_pos = b->yy_ch_buf = base; b->yy_is_our_buffer = 0; b->yy_input_file = 0; b->yy_n_chars = b->yy_buf_size; b->yy_is_interactive = 0; b->yy_at_bol = 1; b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; yy_switch_to_buffer(b ); return b; } /** Setup the input buffer state to scan a string. The next call to yylex() will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan * * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) { return yy_scan_bytes(yystr,strlen(yystr) ); } /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. * * @return the newly allocated buffer state object. */ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) { YY_BUFFER_STATE b; char *buf; yy_size_t n; int i; /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; buf = (char *) yyalloc(n ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); for ( i = 0; i < _yybytes_len; ++i ) buf[i] = yybytes[i]; buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; b = yy_scan_buffer(buf,n ); if ( ! b ) YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); /* It's okay to grow etc. this buffer, and we should throw it * away when we're done. */ b->yy_is_our_buffer = 1; return b; } #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif static void yy_fatal_error (yyconst char* msg ) { (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } /* Redefine yyless() so it works in section 3 code. */ #undef yyless #define yyless(n) \ do \ { \ /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ yytext[yyleng] = (yy_hold_char); \ (yy_c_buf_p) = yytext + yyless_macro_arg; \ (yy_hold_char) = *(yy_c_buf_p); \ *(yy_c_buf_p) = '\0'; \ yyleng = yyless_macro_arg; \ } \ while ( 0 ) /* Accessor methods (get/set functions) to struct members. */ /** Get the current line number. * */ int yyget_lineno (void) { return yylineno; } /** Get the input stream. * */ FILE *yyget_in (void) { return yyin; } /** Get the output stream. * */ FILE *yyget_out (void) { return yyout; } /** Get the length of the current token. * */ int yyget_leng (void) { return yyleng; } /** Get the current token. * */ char *yyget_text (void) { return yytext; } /** Set the current line number. * @param line_number * */ void yyset_lineno (int line_number ) { yylineno = line_number; } /** Set the input stream. This does not discard the current * input buffer. * @param in_str A readable stream. * * @see yy_switch_to_buffer */ void yyset_in (FILE * in_str ) { yyin = in_str ; } void yyset_out (FILE * out_str ) { yyout = out_str ; } int yyget_debug (void) { return yy_flex_debug; } void yyset_debug (int bdebug ) { yy_flex_debug = bdebug ; } static int yy_init_globals (void) { /* Initialization is the same as for the non-reentrant scanner. * This function is called from yylex_destroy(), so don't allocate here. */ (yy_buffer_stack) = 0; (yy_buffer_stack_top) = 0; (yy_buffer_stack_max) = 0; (yy_c_buf_p) = (char *) 0; (yy_init) = 0; (yy_start) = 0; /* Defined in main.c */ #ifdef YY_STDINIT yyin = stdin; yyout = stdout; #else yyin = (FILE *) 0; yyout = (FILE *) 0; #endif /* For future reference: Set errno on error, since we are called by * yylex_init() */ return 0; } /* yylex_destroy is for both reentrant and non-reentrant scanners. */ int yylex_destroy (void) { /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ yy_delete_buffer(YY_CURRENT_BUFFER ); YY_CURRENT_BUFFER_LVALUE = NULL; yypop_buffer_state(); } /* Destroy the stack itself. */ yyfree((yy_buffer_stack) ); (yy_buffer_stack) = NULL; /* Reset the globals. This is important in a non-reentrant scanner so the next time * yylex() is called, initialization will occur. */ yy_init_globals( ); return 0; } /* * Internal utility routines. */ #ifndef yytext_ptr static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) { register int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } #endif #ifdef YY_NEED_STRLEN static int yy_flex_strlen (yyconst char * s ) { register int n; for ( n = 0; s[n]; ++n ) ; return n; } #endif void *yyalloc (yy_size_t size ) { return (void *) malloc( size ); } void *yyrealloc (void * ptr, yy_size_t size ) { /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter * because both ANSI C and C++ allow castless assignment from * any pointer type to void*, and deal with argument conversions * as though doing an assignment. */ return (void *) realloc( (char *) ptr, size ); } void yyfree (void * ptr ) { free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" #line 141 "unites.l" units-filter-3.5.orig/src/unites.l0000644000175000017500000001322611601117457017425 0ustar georgeskgeorgesk/* -*- coding: iso-8859-1 -*- */ %option noyywrap %option c++ #include #include "unites.h" spc [ \t]+ /* les nombres */ digits [0-9] int [+-]?{digits}+ mantisse {digits}+ ee [Ee]|\*10^ decimal {int}([.]{mantisse}) signif {spc}*\#{digits}+{spc}* plusminpc {spc}*~{digits}{digits}?{spc}* plusminpcbis {spc}*\+\-{spc}*{digits}{digits}?%{spc}* /*quelques séparateurs particuliers*/ point {spc}*\.{spc}* barre {spc}*\/{spc}* puis {spc}*^{spc}* colon {spc}*:{spc}* /* les unités de temps hors système */ heure_ou_hecto h minute min /* les unités du SI */ /* Handbook of Chemistry & Physics 78, CRC Press 1997, page 1-20 */ milli_ou_metre m are a gramme g seconde s ampere A kelvin K degre_c °C mole mol candela cd hertz Hz newton N pascal Pa joule J watt W coulomb C volt V ohm Ohm|ohm siemens S farad F tera_ou_tesla T weber Wb henry H lumen lm lux lx becquerel Bq gray Gy sievert Sv radian rad steradian sr /* unités annexes, voir page 1-22 */ degre_angle ° minute_angle \' seconde_angle \'\' angstrom °A barn b litre l|L tonne t bar bar ev eV uam u|uma /* prefixes sauf milli et téra */ /* Handbook of Chemistry & Physics 78, CRC Press 1997, page 1-21 */ prefixe_pur [yzafpnµcdhkMGPEZY]|da /* notation des exposants */ puissance {puis}{int} carre ² cube ³ %% {ee} { pos+=yyleng; yylval.s=strdup(yytext); return EE;} {decimal} { atodecimal(yytext, val_decimal); yylval.v=strdup(yytext); pos+=yyleng; return DECIMAL;} {int} { atodecimal(yytext, val_decimal); yylval.v=strdup(yytext); pos+=yyleng; return INT;} {heure_ou_hecto} { pos+=yyleng; yylval.s=strdup(yytext); return Uh;} {minute} { pos+=yyleng; yylval.s=strdup(yytext); return Umin;} {milli_ou_metre} { pos+=yyleng; yylval.s=strdup(yytext); return Um;} {are} { pos+=yyleng; yylval.s=strdup(yytext); return Uare;} {gramme} { pos+=yyleng; yylval.s=strdup(yytext); return Ug;} {seconde} { pos+=yyleng; yylval.s=strdup(yytext); return Us;} {ampere} { pos+=yyleng; yylval.s=strdup(yytext); return UA;} {kelvin}|{degre_c} { pos+=yyleng; yylval.s=strdup(yytext); return UK;} {mole} { pos+=yyleng; yylval.s=strdup(yytext); return Umol;} {candela} { pos+=yyleng; yylval.s=strdup(yytext); return Ucd;} {hertz} { pos+=yyleng; yylval.s=strdup(yytext); return UHz;} {newton} { pos+=yyleng; yylval.s=strdup(yytext); return UN;} {pascal} { pos+=yyleng; yylval.s=strdup(yytext); return UPa;} {joule} { pos+=yyleng; yylval.s=strdup(yytext); return UJ;} {watt} { pos+=yyleng; yylval.s=strdup(yytext); return UW;} {coulomb} { pos+=yyleng; yylval.s=strdup(yytext); return UC;} {volt} { pos+=yyleng; yylval.s=strdup(yytext); return UV;} {ohm} { pos+=yyleng; yylval.s=strdup(yytext); return Uohm;} {siemens} { pos+=yyleng; yylval.s=strdup(yytext); return US;} {farad} { pos+=yyleng; yylval.s=strdup(yytext); return UF;} {tera_ou_tesla} { pos+=yyleng; yylval.s=strdup(yytext); return UT;} {weber} { pos+=yyleng; yylval.s=strdup(yytext); return UWb;} {henry} { pos+=yyleng; yylval.s=strdup(yytext); return UH;} {lumen} { pos+=yyleng; yylval.s=strdup(yytext); return Ulm;} {lux} { pos+=yyleng; yylval.s=strdup(yytext); return Ulx;} {becquerel} { pos+=yyleng; yylval.s=strdup(yytext); return UBq;} {gray} { pos+=yyleng; yylval.s=strdup(yytext); return UGy;} {sievert} { pos+=yyleng; yylval.s=strdup(yytext); return USv;} {radian} { pos+=yyleng; yylval.s=strdup(yytext); return Urad;} {steradian} { pos+=yyleng; yylval.s=strdup(yytext); return Usr;} {puissance} { pos+=yyleng; while (!index("-0123456789", *yytext)) yytext++; val_int=atoi(yytext); return PUIS;} {carre} { val_int=2; pos+=yyleng; return PUIS;} {cube} { val_int=3; pos+=yyleng; return PUIS;} {prefixe_pur} { pos+=yyleng; yylval.s=strdup(yytext); return PP;} {point} { pos+=yyleng; return POINT;} {barre} { pos+=yyleng; return BARRE;} {degre_angle} { pos+=yyleng; yylval.s=strdup(yytext); return Uda;} {minute_angle} { pos+=yyleng; yylval.s=strdup(yytext); return Uma;} {seconde_angle} { pos+=yyleng; yylval.s=strdup(yytext); return Usa;} {angstrom} { pos+=yyleng; yylval.s=strdup(yytext); return Uangs;} {barn} { pos+=yyleng; yylval.s=strdup(yytext); return Ubarn;} {litre} { pos+=yyleng; yylval.s=strdup(yytext); return Ul;} {tonne} { pos+=yyleng; yylval.s=strdup(yytext); return Ut;} {bar} { pos+=yyleng; yylval.s=strdup(yytext); return Ubar;} {ev} { pos+=yyleng; yylval.s=strdup(yytext); return UeV;} {uam} { pos+=yyleng; yylval.s=strdup(yytext); return Uuam;} {spc} { pos+=yyleng; return SPC;} {signif} { pos+=yyleng; val_int=atoi(strchr(yytext,'#')+1); return Signif;} {plusminpc} { pos+=yyleng; val_int=atoi(strchr(yytext,'~')+1); return PlusminPC;} {plusminpcbis} { pos+=yyleng; val_int=atoi(strchr(yytext,'+')+2); return PlusminPC;} {colon} { pos+=yyleng; return COLON;} . pos+=yyleng; \n pos+=yyleng; units-filter-3.5.orig/src/unites.h0000644000175000017500000000124611601117522017411 0ustar georgeskgeorgesk#ifndef UNITES_H #define UNITES_H #include #include typedef enum { TUh, TUmin, TUm, TUg, TUs, TUA, TUK, TUmol, TUcd, TUHz, TUN, TUPa, TUJ, TUW, TUC, TUV, TUohm, TUS, TUF, TUT, TUWb, TUH, TUlm, TUlx, TUBq, TUGy, TUSv, TUrad, TUsr, TUnull, TUda, TUma, TUsa, TUangs, TUbarn, TUare, TUl, TUt, TUbar, TUeV, TUuam, TU_LAST /* doit rester en dernier */ } uniteSI; typedef enum { BUM,BUK,BUS,BUA,BUKel,BUmol,BUcd, BU_LAST /* doit rester en dernier */ } baseSI; typedef struct{ char sym[8]; char nom[12]; double multiplicateur; int base[BU_LAST]; } unite_data; extern mpq_class val_real; void atodecimal(char* s, mpq_class & r); #endif units-filter-3.5.orig/src/units-test0000755000175000017500000000007711222440702017775 0ustar georgeskgeorgesk#!/bin/sh cat test.1 test.2 test.3 test.4 | perl units-test.pl units-filter-3.5.orig/src/test.30000644000175000017500000000020211222440702016761 0ustar georgeskgeorgeskoptions=-o 1 mol.L^-1:mol/L 1 mol/L options=-o 1V 1 V options=-o 1V:Wb/s 1 Wb/s options=-o 1.0A.h:C 3.6e3 C options=-o 1A.h 1 A.h units-filter-3.5.orig/src/unites.y0000644000175000017500000006246011626235414017447 0ustar georgeskgeorgesk%{ /* inclusions, définition */ #include #include #include #include #include #include #include #include "unites.h" #include #include using namespace std; int yylex(); int yyerror(const char * msg); const char * unit_names[BU_LAST]={"m","kg","s","A","K","mol","cd"}; /* typedef struct{ */ /* int i; */ /* mpq_class multip, maxmultip, wanted_multip; */ /* /\* mutiplicators are mutiprecisions rationals *\/ */ /* uniteSI unite; */ /* int base[BU_LAST]; */ /* char * s, * v; */ /* string wanted_unit; */ /* mpq_class val; */ /* /\* values are mutiprecisions rationals *\/ */ /* int signif; */ /* int pcent; /\* percent tolerance *\/ */ /* } yystype; */ class yystype{ public: int i; mpq_class multip, maxmultip, wanted_multip; /* mutiplicators are mutiprecisions rationals */ uniteSI unite; int base[BU_LAST]; char * s, * v; string wanted_unit; mpq_class val; /* values are mutiprecisions rationals */ int signif; int pcent; /* percent tolerance */ yystype(){ s=(char*) NULL; v=(char*) NULL; } }; ostream & operator << (ostream & o, yystype data); ostream & operator << (ostream & o, yystype data){ o << "YYSTYPE[" <<"i="<text && *(end-1)==' '){ // removes the rightmost spaces end--; *end=0; } for(i=0; i='0'&&text[j]<='9'||text[j]=='.');j++){ if (text[j]!='.') { result++; } else { //skip the decimal point } } } return result; } %} %token EE %token DECIMAL %token INT %token SPC %token COLON %token Uh %token Umin %token Um %token Ug %token Us %token UA %token UK %token Umol %token Ucd %token UHz %token UN %token UPa %token UJ %token UW %token UC %token UV %token Uohm %token US %token UF %token UT %token UWb %token UH %token Ulm %token Ulx %token UBq %token UGy %token USv %token Urad %token Usr %token PUIS %token PP %token POINT %token BARRE %token Uda %token Uma %token Usa %token Uangs %token Ubarn %token Uare %token Ul %token Ut %token Ubar %token UeV %token Uuam %token Signif %token PlusminPC %% /* les règles */ but : valeur_mixte {result = $1;} | sans_unite {result = $1;} ; valeur_mixte : valeur spc valeur_mixte { int i; for(i=0; i < BU_LAST; i++){ if ($1.base[i] != $3.base[i]) yyerror ("not homogeneous units"); } if ($1.multip <= $3.maxmultip) yyerror ("incorrect mutiple units ordering"); $$.val=$1.val*$1.multip+$3.val*$3.multip; $$.multip=1; $$.maxmultip = $1.multip; $$.wanted_unit=""; } | valeur {$$=$1; $$.maxmultip=$1.multip;$$.wanted_unit="";} | valeur COLON style { int i; $$=$1; $$.maxmultip=$1.multip; for(i=0; i < BU_LAST; i++){ if ($1.base[i] != $3.base[i]) yyerror ("wanted unit not homogeneous"); } $$.wanted_multip=$3.multip; $$.wanted_unit=$3.s; } ; style : unite {$$=$1;} ; valeur : decimal spc unite {$$=$3; $$.val=val_decimal; $$.signif=0; $$.pcent=0; $$.v=$1.v;} | decimal spc unite Signif { $$=$3; $$.val=val_decimal; $$.signif=val_int; $$.pcent=0; } | decimal spc unite PlusminPC { $$=$3; $$.val=val_decimal; $$.pcent=val_int; $$.signif=0; } ; sans_unite :decimal { int i; $$=$1; $$.val=val_decimal; for (i=0; i < BU_LAST; i++){$$.base[i]=unites[TUnull].base[i];} $$.multip=1.0; $$.signif=0; $$.pcent=0; $$.wanted_unit=""; } | decimal Signif { int i; $$=$1; $$.val=val_decimal; for (i=0; i < BU_LAST; i++){$$.base[i]=unites[TUnull].base[i];} $$.multip=1.0; $$.signif=val_int; $$.pcent=0; } | decimal PlusminPC { int i; $$=$1; $$.val=val_decimal; for (i=0; i < BU_LAST; i++){$$.base[i]=unites[TUnull].base[i];} $$.multip=1.0; $$.signif=0; $$.pcent=val_int; } ; spc : /*rien*/ |SPC ; unite : unite suiv_unit{ int index; $$.unite = TU_LAST; /* unité non renseignée */ strncpy(buffer,$1.s,MAXBUF); strncat(buffer,$2.s,MAXBUF-strlen($1.s)); free($1.s); free($2.s); $$.s=strdup(buffer); for(index=0; index< BU_LAST; index++){ $$.base[index] = $1.base[index]+$2.base[index] ; } $$.multip = $1.multip*$2.multip; } | prim_unit { $$=$1; } ; suiv_unit : point prim_unit{ $$=$2; strncpy(buffer,".",MAXBUF); strncat(buffer,$2.s,MAXBUF-1); free($2.s); $$.s=strdup(buffer); } | BARRE prim_unit{ int index; $$=$2; $$.multip = 1/ $$.multip; strncpy(buffer,"/",MAXBUF); strncat(buffer,$2.s,MAXBUF-1); free($2.s); $$.s=strdup(buffer); for(index=0; index< BU_LAST; index++){ $$.base[index] *= -1; } } ; point : POINT ; prim_unit1 : Um base_unite { $$=$2; strncpy(buffer,"m",MAXBUF); strncat(buffer,$2.s,MAXBUF-1); free($2.s); $$.s = strdup(buffer); $$.multip*=1e-3; } | UT base_unite { $$=$2; strncpy(buffer,"T",MAXBUF); strncat(buffer,$2.s,MAXBUF-1); free($2.s); $$.s = strdup(buffer); $$.multip*=1e12; } | Uh base_unite { $$=$2; strncpy(buffer,"h",MAXBUF); strncat(buffer,$2.s,MAXBUF-1); free($2.s); $$.s = strdup(buffer); $$.multip*=1e2; } | prefixe base_unite { $$=$2; strncpy(buffer, $1.s,MAXBUF); strncat(buffer, $2.s, MAXBUF-strlen($1.s)); free($1.s); free($2.s);$$.s=strdup(buffer); $$.multip*=$1.multip; } | base_unite { $$=$1; } ; prim_unit : prim_unit1 puissance01 { int index; mpq_class r; $$.i=$2.i; strncpy(buffer, $1.s,MAXBUF); if ($2.i!=1){ strncat(buffer, "^%d",MAXBUF-strlen($1.s)); sprintf(buffer2, buffer, $2.i); } else strncpy(buffer2,buffer,MAXBUF); $$.s=strdup(buffer2); free($1.s); for(index=0; index< BU_LAST; index++){ $$.base[index] = unites[$1.unite].base[index]*$2.i; } if ($2.i>0){ for(index=0, r=1; index<$2.i ; index++){ r*= $$.multip; } } else { for(index=0, r=1; index>$2.i ; index--){ r /= $$.multip; } } $$.multip=r; } ; puissance01 : /*rien*/ {$$.i=1;} | PUIS {$$.i = val_int;} ; decimal : INT {$$.val=val_decimal;} | DECIMAL {$$.val=val_decimal;} | DECIMAL EE INT {atodecimal($1.v,val_decimal); int e = atoi($3.v); if (e>0) for (int i=0; i0) for (int i=0; i #include #include #ifdef RECODE_SUPPORT #include #endif #include const char *program_name; int isUTF8; /* le programme lui-même */ typedef enum {option_default, option_s, option_o, option_l} optiontype; yyFlexLexer lexer; yyFlexLexer * thelexer = &lexer; int yylex(){ return thelexer->yylex(); } inline int yyerror(const char * msg){ printf("ERROR at %ld : %s\n", pos, msg); exit(1); } void test_verbeux(){ int i; yyparse(); if (result.s) { if (result.unite == TU_LAST){ cout << result.s << " " << result.multip*result.val << " SI (équation aux dimensions : "; for (i=0; i1){ printf("."); for (int i=1; i=10){powten*=10; absval/=10;} while(absval < 1) {powten/=10; absval*=10;} for (int i=1;i0){ y = x+halfUnit;} else { y = x-halfUnit;} mpz_class q=y.get_num()/y.get_den(); return q; } void sortie_texte(optiontype option){ /***************************************************/ /* le format des données en sortie est : */ /* double string */ /* et signifie dans l'ordre */ /***************************************************/ /* valeur (compte tenu des chiffres significatifs) */ /* unité (SI) +- pcent % */ /***************************************************/ int i,j, s=0,pc=0, notfirst=0, trouve=0, nb_pref=sizeof(pref_units)/sizeof(pref_units[0]); //mpq_class val, r, powten, absval; /* val r powten and absval are multiprecision rationals */ int puisdix; yyparse(); if (!result.signif) { s=significative(result.v); /* le nombre de chiffres significatifs est déduit de la valeur donnée */ } else { s=result.signif; /* le nombre de chiffres significatifs a été explicité */ } pc=result.pcent; // arrondit en tenant compte du nombre de chiffres significatifs if (result.wanted_unit.length()>0){ result.multip /= result.wanted_multip; }else{ // met le multiplicateur à 1 si l'unité d'entrée a été repérée if (result.s && strlen(result.s)>0){ result.multip = mpq_class(1,1); } } printValue(option, result, s); // affiche l'unité SI. // renvoie l'unité demandée si elle existe if (result.wanted_unit.length()>0){ printUnit(option, result.wanted_unit, pc); return; } // affiche l'unité donnée à l'entrée par défaut if (result.s && strlen(result.s)>0){ printUnit(option, result.s, pc); return; } // recherche s'il y a une unité préférentielle for (i=0; i0) visible_unit=1; if(visible_unit!=0){ // on ne marque les unités que s'il y en a ! for (i=0; i> r; } else { // found a dot; erase it, convert the result, then divide it by a power of ten. string s1; ss>>s1; s1.erase(found,1); stringstream ss1(stringstream::in | stringstream::out); ss1 << s1; ss1 >> r; size_t pow=s1.size()-found; while (pow>0){ r/=10; pow--;} } return; } units-filter-3.5.orig/src/Makefile0000644000175000017500000000134411625452746017410 0ustar georgeskgeorgeskCC = gcc CXX = g++ #CXXFLAGS= -g -O1 CXXFLAGS= -g RECODE_SUPPORT = $(shell if grep -q Debian /etc/issue; then echo -DRECODE_SUPPORT=1; else echo; fi) LIBS = $(shell if grep -q Debian /etc/issue; then echo -lm -lrecode -lgmp -lgmpxx; else echo -lm -lgmp -lgmpxx; fi) all : units-filter test : all sh units-test units-filter : unitesparser.o ${CXX} $(CXXFLAGS) -o units-filter unitesparser.o $(LIBS) unitesparser.o : uniteslex.cc unitesparser.cc ${CXX} $(CXXFLAGS) -c $(RECODE_SUPPORT) unitesparser.cc uniteslex.cc : unites.l unites.y unites.h flex -ouniteslex.cc unites.l unitesparser.cc: unites.y bison --verbose -o unitesparser.cc unites.y clean : rm -f *~ uniteslex.cc unitesparser.cc *.o *.output units-filter tmp.* units-filter-3.5.orig/src/units-test.pl0000755000175000017500000000100411222440702020376 0ustar georgeskgeorgesk#!/usr/bin/perl while(chomp($essai = )){ if(length($essai) != 0){ if ($essai =~ /options=(.*)/){ $options = $1; chomp($essai = ); } chomp($reponse=); $essai_ = $essai; $essai_ =~ s/\'/\\\'/g; @args = ("echo $essai_ | ./units-filter $options > tmp.1"); system @args; open (TMP,'tmp.1'); chomp($result=); if ($reponse eq $result){print "OK\t $essai ---> $reponse\n";} else{ print "***ERREUR***\n $essai ---> $result\n on attendait $reponse\n"; } } } units-filter-3.5.orig/src/unites.y.orig10000644000175000017500000005634211250735145020470 0ustar georgeskgeorgesk%{ /* inclusions, définition */ #include #include #include #include #include #include #include #include "unites.h" int yylex(); int yyerror(const char * msg); const char * unit_names[BU_LAST]={"m","kg","s","A","K","mol","cd"}; typedef struct{ int i; mpq_class multip, maxmultip, wanted_multip; /* mutiplicators are mutiprecisions rationals */ uniteSI unite; int base[BU_LAST]; char * s, * v; std::string wanted_unit; mpq_class val; /* values are mutiprecisions rationals */ int signif; int pcent; /* percent tolerance */ } yystype; #define YYSTYPE yystype extern char * yytext; extern FILE * yyin; /* variables globales */ #define MAXBUF 255 char buffer[MAXBUF+1], buffer2[MAXBUF+1]; yystype result; double val_real; int val_int, count_signif=0; long pos; /* les unités du SI */ /* Handbook of Chemistry & Physics 78, CRC Press 1997, page 1-20 */ unite_data unites[TU_LAST] ={ /*TUh*/ {"h", "seconde",3600.0, { 0, 0, 1, 0, 0, 0, 0}}, /*TUmin*/ {"min", "seconde", 60.0, { 0, 0, 1, 0, 0, 0, 0}}, /*TUm*/ {"m", "mètre", 1.0, { 1, 0, 0, 0, 0, 0, 0}}, /*TUg*/ {"g", "kilogramme",1.0e-3, { 0, 1, 0, 0, 0, 0, 0}}, /*TUs*/ {"s", "seconde", 1.0, { 0, 0, 1, 0, 0, 0, 0}}, /*TUA*/ {"A", "ampère", 1.0, { 0, 0, 0, 1, 0, 0, 0}}, /*TUK*/ {"K", "kelvin", 1.0, { 0, 0, 0, 0, 1, 0, 0}}, /*TUmol*/ {"mol", "mol", 1.0, { 0, 0, 0, 0, 0, 1, 0}}, /*TUcd*/ {"cd", "candela", 1.0, { 0, 0, 0, 0, 0, 0, 1}}, /*TUHz*/ {"Hz", "hetrz", 1.0, { 0,-1, 0, 0, 0, 0, 0}}, /*TUN*/ {"N", "newton", 1.0, { 1, 1,-2, 0, 0, 0, 0}}, /*TUPa*/ {"Pa", "pascal", 1.0, {-1, 1,-2, 0, 0, 0, 0}}, /*TUJ*/ {"J", "joule", 1.0, { 2, 1,-2, 0, 0, 0, 0}}, /*TUW */ {"W", "watt", 1.0, { 2, 1,-3, 0, 0, 0, 0}}, /*TUC*/ {"C", "coulomb", 1.0, { 0, 0, 1, 1, 0, 0, 0}}, /*TUV*/ {"V", "volt", 1.0, { 2, 1,-3,-1, 0, 0, 0}}, /*TUohm*/ {"\\Omega","ohm", 1.0, { 2, 1,-3,-2, 0, 0, 0}}, /*TUS*/ {"S", "siemens", 1.0, {-2,-1, 3, 2, 0, 0, 0}}, /*TUF*/ {"F", "farad", 1.0, {-2,-1, 4, 2, 0, 0, 0}}, /*TUT*/ {"T", "tesla", 1.0, { 0, 1,-2,-1, 0, 0, 0}}, /*TUWb*/ {"Wb", "weber", 1.0, { 2, 1,-2,-1, 0, 0, 0}}, /*TUH*/ {"H", "henry", 1.0, { 2, 1,-2,-2, 0, 0, 0}}, /*TUlm*/ {"lm", "lumen", 1.0, { 0, 0, 0, 0, 0, 0, 1}}, /*TUlx*/ {"lx", "lux", 1.0, {-2, 0, 0, 0, 0, 0, 1}}, /*TUBq */ {"Bq", "becquerel",1.0, { 0, 0,-1, 0, 0, 0, 0}}, /*TUGy*/ {"Gy", "gray", 1.0, { 2, 0,-2, 0, 0, 0, 0}}, /*TUSv*/ {"Sv", "sievert", 1.0, { 2, 0,-2, 0, 0, 0, 0}}, /*TUrad*/ {"rad", "radian", 1.0, { 0, 0, 0, 0, 0, 0, 0}}, /*TUsr*/ {"sr" , "stéradian",1.0, { 0, 0, 0, 0, 0, 0, 0}}, /*TUnull*/{"" , "sans unité",1.0, { 0, 0, 0, 0, 0, 0, 0}}, /*TUda*/ {"°", "degré", M_PI/180.0, { 0, 0, 0, 0, 0, 0, 0}}, /*TUma*/ {"'", "minute", M_PI/10800, { 0, 0, 0, 0, 0, 0, 0}}, /*TUsa*/ {"''","seconde",M_PI/648000 , { 0, 0, 0, 0, 0, 0, 0}}, /*TUangs*/ {"\\o{A}", "angström", 1e-10, { 1, 0, 0, 0, 0, 0, 0}}, /*TUbarn*/ {"b", "barn", 1e-28, { 2, 0, 0, 0, 0, 0, 0}}, /*TUare*/ {"a", "are", 1e2, { 2, 0, 0, 0, 0, 0, 0}}, /*TUl*/ {"L", "litre", 1e-3, { 3, 0, 0, 0, 0, 0, 0}}, /*TUt*/ {"t", "tonne", 1e3, { 0, 1, 0, 0, 0, 0, 0}}, /*TUbar*/ {"bar", "bar", 1e5, {-1, 1,-2, 0, 0, 0, 0}}, /*TUeV*/ {"eV", "eV", 1.60218e-19, { 2, 1,-2, 0, 0, 0, 0}}, /*TUuam*/ {"uma", "uma", 1.66054e-27, { 0, 1, 0, 0, 0, 0, 0}} }; unite_data pref_units[] ={ /*TUm*/ {"m", "mètre", 1.0, { 1, 0, 0, 0, 0, 0, 0}}, /* */ {"kg", "kilogramme",1.0, { 0, 1, 0, 0, 0, 0, 0}}, /*TUs*/ {"s", "seconde", 1.0, { 0, 0, 1, 0, 0, 0, 0}}, /*TUA*/ {"A", "ampère", 1.0, { 0, 0, 0, 1, 0, 0, 0}}, /*TUK*/ {"K", "kelvin", 1.0, { 0, 0, 0, 0, 1, 0, 0}}, /*TUmol*/ {"mol", "mol", 1.0, { 0, 0, 0, 0, 0, 1, 0}}, /*TUcd*/ {"cd", "candela", 1.0, { 0, 0, 0, 0, 0, 0, 1}}, /*TUHz*/ {"Hz", "hetrz", 1.0, { 0,-1, 0, 0, 0, 0, 0}}, /*TUN*/ {"N", "newton", 1.0, { 1, 1,-2, 0, 0, 0, 0}}, /*TUPa*/ {"Pa", "pascal", 1.0, {-1, 1,-2, 0, 0, 0, 0}}, /*TUJ*/ {"J", "joule", 1.0, { 2, 1,-2, 0, 0, 0, 0}}, /*TUW */ {"W", "watt", 1.0, { 2, 1,-3, 0, 0, 0, 0}}, /*TUC*/ {"C", "coulomb", 1.0, { 0, 0, 1, 1, 0, 0, 0}}, /*TUV*/ {"V", "volt", 1.0, { 2, 1,-3,-1, 0, 0, 0}}, /*TUohm*/ {"ohm", "ohm", 1.0, { 2, 1,-3,-2, 0, 0, 0}}, /*TUS*/ {"S", "siemens", 1.0, {-2,-1, 3, 2, 0, 0, 0}}, /*TUF*/ {"F", "farad", 1.0, {-2,-1, 4, 2, 0, 0, 0}}, /*TUT*/ {"T", "tesla", 1.0, { 0, 1,-2,-1, 0, 0, 0}}, /*TUWb*/ {"Wb", "weber", 1.0, { 2, 1,-2,-1, 0, 0, 0}}, /*TUH*/ {"H", "henry", 1.0, { 2, 1,-2,-2, 0, 0, 0}}, /*TUlm*/ {"lm", "lumen", 1.0, { 0, 0, 0, 0, 0, 0, 1}}, /*TUlx*/ {"lx", "lux", 1.0, {-2, 0, 0, 0, 0, 0, 1}}, }; int significative(char* text); int significative(char* text){ // returns the number of significative numbers of a real // if the real is null returns zero. int i,j,result=0; for(i=0; i='0'&&text[j]<='9'||text[j]=='.');j++){ if (text[j]!='.') { result++; } else { //skip the decimal point } } return result; } %} %token REAL %token SPC %token COLON %token Uh %token Umin %token Um %token Ug %token Us %token UA %token UK %token Umol %token Ucd %token UHz %token UN %token UPa %token UJ %token UW %token UC %token UV %token Uohm %token US %token UF %token UT %token UWb %token UH %token Ulm %token Ulx %token UBq %token UGy %token USv %token Urad %token Usr %token PUIS %token PP %token POINT %token BARRE %token Uda %token Uma %token Usa %token Uangs %token Ubarn %token Uare %token Ul %token Ut %token Ubar %token UeV %token Uuam %token Signif %token PlusminPC %% /* les règles */ but : valeur_mixte {result = $1;} | sans_unite {result = $1;} ; valeur_mixte : valeur spc valeur_mixte { int i; for(i=0; i < BU_LAST; i++){ if ($1.base[i] != $3.base[i]) yyerror ("not homogeneous units"); } if ($1.multip <= $3.maxmultip) yyerror ("incorrect mutiple units ordering"); $$.val=$1.val*$1.multip+$3.val*$3.multip; $$.multip=1; $$.maxmultip = $1.multip; $$.wanted_unit=""; } | valeur {$$=$1; $$.maxmultip=$1.multip;$$.wanted_unit="";} | valeur COLON style { int i; $$=$1; $$.maxmultip=$1.multip; for(i=0; i < BU_LAST; i++){ if ($1.base[i] != $3.base[i]) yyerror ("wanted unit not homogeneous"); } $$.wanted_multip=$3.multip; $$.wanted_unit=$3.s; } ; style : unite {$$=$1;} ; valeur : REAL spc unite {$$=$3; $$.val=val_real; $$.signif=0; $$.pcent=0;} | REAL spc unite Signif { $$=$3; $$.val=val_real; $$.signif=val_int; $$.pcent=0; } | REAL spc unite PlusminPC { $$=$3; $$.val=val_real; $$.pcent=val_int; $$.signif=0; } ; sans_unite :REAL { int i; $$=$1; $$.val=val_real; for (i=0; i < BU_LAST; i++){$$.base[i]=unites[TUnull].base[i];} $$.multip=1.0; $$.signif=0; $$.pcent=0; $$.wanted_unit=""; } | REAL Signif { int i; $$=$1; $$.val=val_real; for (i=0; i < BU_LAST; i++){$$.base[i]=unites[TUnull].base[i];} $$.multip=1.0; $$.signif=val_int; $$.pcent=0; } | REAL PlusminPC { int i; $$=$1; $$.val=val_real; for (i=0; i < BU_LAST; i++){$$.base[i]=unites[TUnull].base[i];} $$.multip=1.0; $$.signif=0; $$.pcent=val_int; } ; spc : /*rien*/ |SPC ; unite : unite suiv_unit{ int index; $$.unite = TU_LAST; /* unité non renseignée */ strncpy(buffer,$1.s,MAXBUF); strncat(buffer,$2.s,MAXBUF-strlen($1.s)); free($1.s); free($2.s); $$.s=strdup(buffer); for(index=0; index< BU_LAST; index++){ $$.base[index] = $1.base[index]+$2.base[index] ; } $$.multip = $1.multip*$2.multip; } | prim_unit { $$=$1; } ; suiv_unit : point prim_unit{ $$=$2; strncpy(buffer,".",MAXBUF); strncat(buffer,$2.s,MAXBUF-1); free($2.s); $$.s=strdup(buffer); } | BARRE prim_unit{ int index; $$=$2; $$.multip = 1/ $$.multip; strncpy(buffer,"/",MAXBUF); strncat(buffer,$2.s,MAXBUF-1); free($2.s); $$.s=strdup(buffer); for(index=0; index< BU_LAST; index++){ $$.base[index] *= -1; } } ; point : POINT ; prim_unit1 : Um base_unite { $$=$2; strncpy(buffer,"m",MAXBUF); strncat(buffer,$2.s,MAXBUF-1); free($2.s); $$.s = strdup(buffer); $$.multip*=1e-3; } | UT base_unite { $$=$2; strncpy(buffer,"T",MAXBUF); strncat(buffer,$2.s,MAXBUF-1); free($2.s); $$.s = strdup(buffer); $$.multip*=1e12; } | Uh base_unite { $$=$2; strncpy(buffer,"h",MAXBUF); strncat(buffer,$2.s,MAXBUF-1); free($2.s); $$.s = strdup(buffer); $$.multip*=1e2; } | prefixe base_unite { $$=$2; strncpy(buffer, $1.s,MAXBUF); strncat(buffer, $2.s, MAXBUF-strlen($1.s)); free($1.s); free($2.s);$$.s=strdup(buffer); $$.multip*=$1.multip; } | base_unite { $$=$1; } ; prim_unit : prim_unit1 puissance01 { int index; mpq_class r; $$.i=$2.i; strncpy(buffer, $1.s,MAXBUF); if ($2.i!=1){ strncat(buffer, "^%d",MAXBUF-strlen($1.s)); sprintf(buffer2, buffer, $2.i); } else strncpy(buffer2,buffer,MAXBUF); $$.s=strdup(buffer2); free($1.s); for(index=0; index< BU_LAST; index++){ $$.base[index] = unites[$1.unite].base[index]*$2.i; } if ($2.i>0){ for(index=0, r=1; index<$2.i ; index++){ r*= $$.multip; } } else { for(index=0, r=1; index>$2.i ; index--){ r /= $$.multip; } } $$.multip=r; } ; puissance01 : /*rien*/ {$$.i=1;} | PUIS {$$.i = val_int;} ; prefixe : PP {$$.s = strdup(yytext); $$.multip=1.0; switch (yytext[0]){ case 'y' : $$.multip = 1e-24; break; case 'z' : $$.multip = 1e-21; break; case 'a' : $$.multip = 1e-18; break; case 'f' : $$.multip = 1e-15; break; case 'p' : $$.multip = 1e-12; break; case 'n' : $$.multip = 1e-9; break; case 'µ' : $$.multip = 1e-6; break; case 'c' : $$.multip = 1e-2; break; case 'd' : if (!strcmp (yytext,"da") ) $$.multip = 10.0; else $$.multip = 0.1; break; case 'h' : $$.multip = 1e2; break; case 'k' : $$.multip = 1e3; break; case 'M' : $$.multip = 1e6; break; case 'G' : $$.multip = 1e9; break; case 'P' : $$.multip = 1e15; break; case 'E' : $$.multip = 1e18; break; case 'Z' : $$.multip = 1e21; break; case 'Y': $$.multip = 1e24; break; } } ; base_unite : Uh {$$.unite=TUh; $$.s = strdup("h"); $$.multip=unites[$$.unite].multiplicateur;} | Umin {$$.unite=TUmin; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Um {$$.unite=TUm; $$.s = strdup("m"); $$.multip=unites[$$.unite].multiplicateur;} | Ug {$$.unite=TUg; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Us {$$.unite=TUs; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UA { $$.unite = TUA; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UK { $$.unite = TUK; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Umol { $$.unite = TUmol; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Ucd { $$.unite = TUcd; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UHz { $$.unite = TUHz; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UN { $$.unite = TUN; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UPa { $$.unite = TUPa; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UJ { $$.unite = TUJ; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UT { $$.unite = TUT; $$.s = strdup("T"); $$.multip=unites[$$.unite].multiplicateur;} | UW { $$.unite = TUW; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UC { $$.unite = TUC; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UV { $$.unite = TUV; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Uohm { $$.unite = TUohm; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | US { $$.unite = TUS; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UF { $$.unite = TUF; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UWb { $$.unite = TUWb; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UH { $$.unite = TUH; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Ulm { $$.unite = TUlm; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Ulx { $$.unite = TUlx; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UBq { $$.unite = TUBq; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UGy { $$.unite = TUGy; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | USv { $$.unite = TUSv; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Urad { $$.unite = TUrad; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Usr { $$.unite = TUsr; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Uda { $$.unite = TUda; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Uma { $$.unite = TUma; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Usa { $$.unite = TUsa; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Uangs { $$.unite = TUangs; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Ubarn { $$.unite = TUbarn; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Uare { $$.unite = TUare; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Ul { $$.unite = TUl; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Ut { $$.unite = TUt; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Ubar { $$.unite = TUbar; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | UeV { $$.unite = TUeV; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} | Uuam { $$.unite = TUuam; $$.s = strdup(yytext); $$.multip=unites[$$.unite].multiplicateur;} ; %% #include "uniteslex.cc" #include #include #include #ifdef RECODE_SUPPORT #include #endif #include const char *program_name; int isUTF8; /* le programme lui-même */ typedef enum {option_default, option_s, option_o, option_l} optiontype; yyFlexLexer lexer; yyFlexLexer * thelexer = &lexer; int yylex(){ return thelexer->yylex(); } inline int yyerror(const char * msg){ printf("ERROR at %ld : %s\n", pos, msg); exit(1); } void test_verbeux(){ int i; yyparse(); if (result.s) { if (result.unite == TU_LAST){ std::cout << result.s << " " << result.multip*result.val << " SI (équation aux dimensions : "; for (i=0; i0){ result.multip /= result.wanted_multip; }else{ // met le multiplicateur à 1 si l'unité d'entrée a été repérée if (result.s && strlen(result.s)>0){ result.multip = 1.0; } } std::cout << "DEBUG\n" << "val=" << val << "\n"; printValue(option, result, s); std::cout << "DEBUG\n" << "val=" << val << "\n"; // affiche l'unité SI. // renvoie l'unité demandée si elle existe if (result.wanted_unit.length()>0){ printUnit(option, result.wanted_unit, pc); return; } // affiche l'unité donnée à l'entrée par défaut if (result.s && strlen(result.s)>0){ printUnit(option, result.s, pc); return; } // recherche s'il y a une unité préférentielle for (i=0; i units-filter.1.gz (cd src; ${MAKE} all) test : all (cd src; ${MAKE} test) clean : rm -f *~ *stamp *.gz *.1 (cd src; ${MAKE} clean) install : all install -m 775 -d ${DESTDIR}/usr/bin install -m 775 -d ${DESTDIR}/usr/share/man/man1 install -m 755 src/units-filter ${DESTDIR}/usr/bin install -m 644 units-filter.1.gz ${DESTDIR}/usr/share/man/man1 uninstall : rm -f ${DESTDIR}/usr/bin/units-filter rm -f ${DESTDIR}/usr/share/man/man1/units-filter.1.gz units-filter.1: manpage.xml xsltproc -''-nonet -''-param man.charmap.use.subset "0" \ -''-param make.year.ranges "1" \ -''-param make.single.year.ranges "1" \ /usr/share/xml/docbook/stylesheet/nwalsh/manpages/docbook.xsl \ manpage.xml units-filter-3.5.orig/LISEZMOI0000644000175000017500000000256711222440702016325 0ustar georgeskgeorgesk ------------------------------------------- Units-filter V0.9 ------------------------------------------- (c)2000 G. Khaznadar ------------------------------------------- Units-filter est un filtre simple et autonome écrit en langage C, flex et bison. Il accepte des entrées telles que "1.5e3 µN.m.s^-1" (Ce pourrait être le taux de croissance temporel d'un couple) et et sort une valeur en unité SI, suivie de la dimension physique de cette valeur. exemple :~/src$ echo 1.5e3 µN.m.s^-1 | units-filter 0.0015 2 1 -3 0 0 0 0 exemple :~/src$ 2 -3 ce qui signifie : 0.0015 (SI unit) m .kg.s Quand la chaîne d'entrée n'est pas reconnue, le filtre échoue et renvoie un code 1. Ce filtre peut être utilisé au sein de systèmes d'examens éducatifs, pour analyser la réponse d'un étudiant à un problème de physique ou de chimie. Ce petit bout de code est sous GPL, voyez le fichier COPYING. Les suggestions sont bienvenues. -- Georges. ----------------------------------------------------------- INSTALLATION ----------------------------------------------------------- Dans le sous-répertoire src/, lancez "make". Vous pouvez essayer le script units-test pour voir quelques entrées typiques et leurs résultats. units-filter-3.5.orig/manpage.xml0000644000175000017500000002117711222440702017277 0ustar georgeskgeorgesk .
will be generated. You may view the manual page with: nroff -man .
| less'. A typical entry in a Makefile or Makefile.am is: DB2MAN = /usr/share/sgml/docbook/stylesheet/xsl/nwalsh/manpages/docbook.xsl XP = xsltproc -''-nonet -''-param man.charmap.use.subset "0" manpage.1: manpage.xml $(XP) $(DB2MAN) $< The xsltproc binary is found in the xsltproc package. The XSL files are in docbook-xsl. A description of the parameters you can use can be found in the docbook-xsl-doc-* packages. Please remember that if you create the nroff version in one of the debian/rules file targets (such as build), you will need to include xsltproc and docbook-xsl in your Build-Depends control field. Alternatively use the xmlto command/package. That will also automatically pull in xsltproc and docbook-xsl. Notes for using docbook2x: docbook2x-man does not automatically create the AUTHOR(S) and COPYRIGHT sections. In this case, please add them manually as ... . To disable the automatic creation of the AUTHOR(S) and COPYRIGHT sections read /usr/share/doc/docbook-xsl/doc/manpages/authors.html. This file can be found in the docbook-xsl-doc-html package. Validation can be done using: `xmllint -''-noout -''-valid manpage.xml` General documentation about man-pages and man-page-formatting: man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ --> ]> &dhtitle; &dhpackage; &dhfirstname; &dhsurname; Wrote this manpage.
&dhemail;
2009 &dhusername; Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 or (at your option) any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL.
&dhucpackage; &dhsection; &dhpackage; is a parser for physical and chemical quantities &dhpackage; DESCRIPTION &dhpackage; is a basic standalone parser written in C language, flex and bison. It inputs strings like "1.5e3 nN.m.s^-1" (it could be the time growth ratio of a torque) and outputs the value in standard SI unit, followed by the physical dimension of this value. OPTIONS Like Significative. Takes in account the number of significative digits. For example 1.0 m contains 2 significative digits, while 0.00100 contains 3 significative digits. It is possible to enforce the number of significative digits by using a special syntax : if units-filter parses the input "1.0m#6", it interprets it as a value with exactly 6 significative digits, like "1.00000 m". The number following the # sign is the forced number of significative digits. The number of significative digits appears just before the last zero in the output of the command (this zero is a placeholder for future extensions). Like Output. Outputs a correct representation of the physical quantity with its physical unit in the International System notation. There may be some simplification with usual units. For example, a newton will be represented by the unit N in place of m.kg.s^-2. The value is expressed as a floating number with one digit before the decimal point, and as many digits in the mantissa as necessary to fit the desired number of significative digits (see an example below). It is possible to enforce the output unit : just add a colon and the desired unit at the end of the input. If this unit is homogeneous with the former one, it will be used to format the output. Like LaTeX. Outputs a correct representation of the physical quantity with its physical unit in the International System notation, in LaTeX language. EXAMPLES Establishing the SI value and units exponents of a quantity in the mksa system: ~$ echo 1.5e3 nN.m.s^-1 | units-filter 1.5e-6 2 1 -3 0 0 0 0 which means : 1.5e-6 (SI unit) m^2.kg.s^-3 Comparing to different physical quantities: ~$ e1=$(echo "1.2e-3 V" | units-filter) ~$ e2=$(echo "1200e3 nWb/s"| units-filter) ~$ if [ "$e1" = "$e2" ]; then echo ok; else echo ko; fi ok ... which emphasizes that webers by unit time are the same than volts. Playing with the number of significative digits: ~$ echo "0.00100m" | src/units-filter -s 0.001 1 0 0 0 0 0 0 3 0 ~$ echo "0.00100m #2" | src/units-filter -s 0.001 1 0 0 0 0 0 0 2 0 Giving a value for the relative precision: ~$ echo "1kV~2" | units-filter -o 1e+03 V +-2% Turning on the LaTeX output: ~$ echo "1kohm+-2%" | units-filter -l 1\times 10^{+03}\, \Omega \pm 2\,\% Turning on the output of a canonical physical notation: ~$ echo "1.0 m.kg.s^-2 #7" | units-filter -o 1.000000e+00N Choosing a non-standard unit for the output: ~$ echo 1800C:A.h| units-filter -o 5.000e-01 A.h KNOWN BUGS Few units out of the mksa system are sucessfuly parsed.