format_data.c File Reference

#include "format_data.h"
#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 Documentation

#define ADD_DATA ( data_i   ) 

Value:

if (cur_arg == n_arg) \
                            { \
                              f = (float) data_i; \
                              value_to_print = f; \
                            }

Definition at line 36 of file DATA_EXTRACT/format_data.c.

Referenced by format_data_get_data().


Function Documentation

char* format_data_after_float ( char *  _buffer  ) 

Definition at line 64 of file DATA_EXTRACT/format_data.c.

Referenced by format_data_get_data().

00065 {
00066      int stop = 0;
00067 
00068      // Point after the first integer
00069      _buffer = format_data_after_int(_buffer);
00070      // if the next character is a comma, increment the pointer
00071      if (*_buffer == '.')
00072         _buffer++;
00073      // if the next character is a comma, increment the pointer
00074      if (*_buffer == '-')
00075         return _buffer;
00076      // Point after the next integer (corresponding to the decimals).
00077      _buffer = format_data_after_int(_buffer);
00078 
00079      return _buffer;
00080 }

char* format_data_after_int ( char *  _buffer  ) 

Definition at line 43 of file DATA_EXTRACT/format_data.c.

Referenced by format_data_after_float(), and format_data_get_data().

00044 {
00045      int stop = 0;
00046 
00047      // If there is a negative character, skip it
00048      if (*_buffer == '-')
00049         _buffer++;
00050      // loop until the character is in the range [0;9]
00051      while(*_buffer && !stop)
00052      {
00053           if (*_buffer < '0' || *_buffer > '9')
00054               stop = 1;
00055           else
00056               _buffer++;
00057      }
00058 
00059      // Returns the pointer
00060      return _buffer;
00061 }

int format_data_get_data ( char *  _input,
char *  _pattern,
int  n_arg 
)

Definition at line 83 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().

00084 {
00085      char _str[256];
00086      char _cur_pattern[256];
00087      char _value[32];
00088      char _str_value[256];
00089      char *_ppattern, *_pcur_pattern, *_pstr;
00090      int stop = 0;
00091      int cur_arg;
00092      int i_buffer = 0;
00093      int i;
00094      float f, value_to_print;
00095      char *_end_of_line;     
00096 
00097      char _temp[256];
00098      char _buffer_temp[256];
00099 
00100      // Main loop
00101      while(*_input)
00102      {
00103          // To compute one line
00104          _ppattern = _pattern;
00105          // Initialization
00106          cur_arg = 0;
00107          stop = 0;
00108 
00109          _end_of_line = _input;
00110          // Look for the end of line
00111          while(*_end_of_line && *_end_of_line != '\n')
00112             _end_of_line++;
00113 
00114          // While the pattern matches with the current line
00115          while(*_ppattern && !stop)
00116          {
00117              // If the current pointer overflows, then break
00118              if (_input > _end_of_line)
00119              {
00120                 stop = 1;
00121                 break;
00122              }
00123              // Get the first sequence of characters
00124              _input = templates_get_string(_input, _str);
00125              // Get the first pattern that has to match with the string
00126              _ppattern = templates_get_string(_ppattern, _cur_pattern);
00127 
00128              _pstr = _str;
00129              _pcur_pattern = _cur_pattern;
00130              // Pattern matching loop
00131              while(*_pstr && !stop)
00132              {
00133                    // Check the current pattern
00134                    switch(*_pcur_pattern)  
00135                    {
00136                    // If it is a special pattern ("%i", "%f", ...)
00137                    case '%':
00138                         _pcur_pattern++;
00139                         cur_arg++;
00140                         switch(*_pcur_pattern)
00141                         {
00142                         // For "%i" and "%d" patterns
00143                         case 'd':
00144                         case 'i':
00145                              // If the pattern does not match with the line, then break
00146                              if (!sscanf(_pstr, "%f", &i))
00147                                 stop = 1;
00148                              // Else
00149                              else
00150                              {
00151                                  // Read the integer data
00152                                  _pstr = format_data_after_int(_pstr);
00153                                  // Cast it
00154                                  ADD_DATA(i);
00155                              }
00156                              break;
00157                         // For "%f" pattern
00158                         case 'f':
00159                              // If the pattern does not match with the line, then break
00160                              if (!sscanf(_pstr, "%f", &f))
00161                                 stop = 1;
00162                              // Else
00163                              else
00164                              {
00165                                  // Read the integer data
00166                                  _pstr = format_data_after_float(_pstr);
00167                                  // Cast it
00168                                  ADD_DATA(f);
00169                              }
00170                              break;
00171                         // If it is the character %
00172                         case '%':
00173                              // Then just check if the line matches
00174                              cur_arg--;
00175                              if (*_pstr != '%')
00176                                 stop = 1;
00177                              else
00178                                 _pstr++;
00179                              break;
00180                         default:
00181                              // Set an error
00182                              SET_ERROR("Pattern not supported!");
00183                              stop = 1;
00184                              break;
00185                         }
00186                         // Next pattern
00187                         _pcur_pattern++;
00188                         break;
00189                    // Else for classical characters
00190                    default:
00191                         // Just check if it matches with the line
00192                         if (*_pstr != *_pcur_pattern)
00193                            stop = 1;
00194                         else
00195                         {
00196                             _pstr++;
00197                             _pcur_pattern++;
00198                         }
00199                    }
00200              }
00201          }
00202          // If no error occured, print the number on the default output
00203          if (!stop)
00204             printf("%.10f\r\n", value_to_print);
00205     }
00206 
00207     return i_buffer/sizeof(float);
00208 }


Generated on Fri Feb 19 02:23:19 2010 for AVR32 UC3 - EVK1104 DSPLib Demo Documentation by  doxygen 1.5.5