#include "script.h"
#include "error_management.h"
Go to the source code of this file.
Defines | |
#define | ADD_DATA(data_i) |
Functions | |
char * | format_data_after_float (char *_buffer) |
char * | format_data_after_int (char *_buffer) |
int | format_data_get_data (char *_input, char *_pattern, int n_arg) |
#define ADD_DATA | ( | data_i | ) |
Value:
if (cur_arg == n_arg) \
{ \
f = (float) data_i; \
value_to_print = f; \
}
Definition at line 34 of file DATA_EXTRACT/format_data.c.
Referenced by format_data_get_data().
char* format_data_after_float | ( | char * | _buffer | ) |
Definition at line 62 of file DATA_EXTRACT/format_data.c.
Referenced by format_data_get_data().
00063 { 00064 int stop = 0; 00065 00066 // Point after the first integer 00067 _buffer = format_data_after_int(_buffer); 00068 // if the next character is a comma, increment the pointer 00069 if (*_buffer == '.') 00070 _buffer++; 00071 // if the next character is a comma, increment the pointer 00072 if (*_buffer == '-') 00073 return _buffer; 00074 // Point after the next integer (corresponding to the decimals). 00075 _buffer = format_data_after_int(_buffer); 00076 00077 return _buffer; 00078 }
char* format_data_after_int | ( | char * | _buffer | ) |
Definition at line 41 of file DATA_EXTRACT/format_data.c.
Referenced by format_data_after_float(), and format_data_get_data().
00042 { 00043 int stop = 0; 00044 00045 // If there is a negative character, skip it 00046 if (*_buffer == '-') 00047 _buffer++; 00048 // loop until the character is in the range [0;9] 00049 while(*_buffer && !stop) 00050 { 00051 if (*_buffer < '0' || *_buffer > '9') 00052 stop = 1; 00053 else 00054 _buffer++; 00055 } 00056 00057 // Returns the pointer 00058 return _buffer; 00059 }
int format_data_get_data | ( | char * | _input, | |
char * | _pattern, | |||
int | n_arg | |||
) |
Definition at line 81 of file DATA_EXTRACT/format_data.c.
References ADD_DATA, format_data_after_float(), format_data_after_int(), SET_ERROR, and templates_get_string().
Referenced by format_data().
00082 { 00083 char _str[256]; 00084 char _cur_pattern[256]; 00085 char _value[32]; 00086 char _str_value[256]; 00087 char *_ppattern, *_pcur_pattern, *_pstr; 00088 int stop = 0; 00089 int cur_arg; 00090 int i_buffer = 0; 00091 int i; 00092 float f, value_to_print; 00093 char *_end_of_line; 00094 00095 char _temp[256]; 00096 char _buffer_temp[256]; 00097 00098 // Main loop 00099 while(*_input) 00100 { 00101 // To compute one line 00102 _ppattern = _pattern; 00103 // Initialization 00104 cur_arg = 0; 00105 stop = 0; 00106 00107 _end_of_line = _input; 00108 // Look for the end of line 00109 while(*_end_of_line && *_end_of_line != '\n') 00110 _end_of_line++; 00111 00112 // While the pattern matches with the current line 00113 while(*_ppattern && !stop) 00114 { 00115 // If the current pointer overflows, then break 00116 if (_input > _end_of_line) 00117 { 00118 stop = 1; 00119 break; 00120 } 00121 // Get the first sequence of characters 00122 _input = templates_get_string(_input, _str); 00123 // Get the first pattern that has to match with the string 00124 _ppattern = templates_get_string(_ppattern, _cur_pattern); 00125 00126 _pstr = _str; 00127 _pcur_pattern = _cur_pattern; 00128 // Pattern matching loop 00129 while(*_pstr && !stop) 00130 { 00131 // Check the current pattern 00132 switch(*_pcur_pattern) 00133 { 00134 // If it is a special pattern ("%i", "%f", ...) 00135 case '%': 00136 _pcur_pattern++; 00137 cur_arg++; 00138 switch(*_pcur_pattern) 00139 { 00140 // For "%i" and "%d" patterns 00141 case 'd': 00142 case 'i': 00143 // If the pattern does not match with the line, then break 00144 if (!sscanf(_pstr, "%f", &i)) 00145 stop = 1; 00146 // Else 00147 else 00148 { 00149 // Read the integer data 00150 _pstr = format_data_after_int(_pstr); 00151 // Cast it 00152 ADD_DATA(i); 00153 } 00154 break; 00155 // For "%f" pattern 00156 case 'f': 00157 // If the pattern does not match with the line, then break 00158 if (!sscanf(_pstr, "%f", &f)) 00159 stop = 1; 00160 // Else 00161 else 00162 { 00163 // Read the integer data 00164 _pstr = format_data_after_float(_pstr); 00165 // Cast it 00166 ADD_DATA(f); 00167 } 00168 break; 00169 // If it is the character % 00170 case '%': 00171 // Then just check if the line matches 00172 cur_arg--; 00173 if (*_pstr != '%') 00174 stop = 1; 00175 else 00176 _pstr++; 00177 break; 00178 default: 00179 // Set an error 00180 SET_ERROR("Pattern not supported!"); 00181 stop = 1; 00182 break; 00183 } 00184 // Next pattern 00185 _pcur_pattern++; 00186 break; 00187 // Else for classical characters 00188 default: 00189 // Just check if it matches with the line 00190 if (*_pstr != *_pcur_pattern) 00191 stop = 1; 00192 else 00193 { 00194 _pstr++; 00195 _pcur_pattern++; 00196 } 00197 } 00198 } 00199 } 00200 // If no error occured, print the number on the default output 00201 if (!stop) 00202 printf("%.10f\r\n", value_to_print); 00203 } 00204 00205 return i_buffer/sizeof(float); 00206 }