script.c File Reference

#include "error_management.h"
#include "script.h"

Go to the source code of this file.

Functions

int script_get_value (char *_str)
void script_set_is_separator_fct (_fct_is_separator is_separator)
char * templates_get_arg (char *_args, int num)
char * templates_get_string (char *_src, char *_dst)
int templates_is_space (char c)
char * templates_skip_spaces (char *_str)

Variables

_fct_is_separator script_is_separator = NULL


Function Documentation

int script_get_value ( char *  _str  ) 

Definition at line 142 of file DATA_PRINT/script.c.

References ASSERT, and templates_skip_spaces().

00143 {
00144     int value;
00145     char *_pstr;
00146 
00147     ASSERT(_str);
00148     // Skip the first spaces
00149     _str = templates_skip_spaces(_str);
00150 
00151     value = 0;
00152 
00153     // If the number is an hexadecimal value
00154     if (_str[0] == '0' && _str[1] == 'x')
00155         sscanf(&_str[2], "%X", &value);
00156     // The same
00157     else if (_pstr = strchr(_str, 'h'))
00158     {
00159          *_pstr = '\0';
00160          sscanf(_str, "%X", &value);
00161          *_pstr = 'h';
00162     }
00163     // Else it is decimal value
00164     else
00165          sscanf(_str, "%i", &value);
00166 
00167     return value;
00168 }

void script_set_is_separator_fct ( _fct_is_separator  is_separator  ) 

Definition at line 64 of file DATA_PRINT/script.c.

References script_is_separator.

00065 {
00066      // Set the new is_separator function as an extension of the templates_is_space function
00067      script_is_separator = is_separator;
00068 }

char* templates_get_arg ( char *  _args,
int  num 
)

Definition at line 84 of file DATA_PRINT/script.c.

References ASSERT, templates_is_space(), and templates_skip_spaces().

00085 {
00086      char *_new_args;
00087      int i;
00088 
00089      ASSERT(_args);
00090 
00091      _new_args = _args;
00092      // Skip the first spaces
00093      _new_args = templates_skip_spaces(_new_args);
00094 
00095      // This loop permits to point on the "num"th argument
00096      for(i=0; i<num; i++)
00097      {
00098          // Skip the non-spaces
00099          while(!templates_is_space(*_new_args))
00100              _new_args++;
00101          // skip the spaces
00102          _new_args = templates_skip_spaces(_new_args);
00103      }
00104      
00105      // Return a pointer on the argument
00106      return _new_args;
00107 }

char* templates_get_string ( char *  _src,
char *  _dst 
)

Definition at line 109 of file DATA_PRINT/script.c.

References ASSERT, FALSE, templates_is_space(), and templates_skip_spaces().

00110 {
00111      BOOL hold;
00112 
00113      ASSERT(_src);
00114      // Skip spaces
00115      _src = templates_skip_spaces(_src);
00116 
00117      hold = FALSE;
00118      // While it is not a space or we are inside a quotes and the end of the string is not reached
00119      while((!templates_is_space(*_src) || hold) && *_src)
00120      {
00121           // Test the character
00122           switch(*_src)
00123           {
00124           // If it is a " character
00125           case '\"':
00126                // hold the string
00127                 hold = !hold;
00128                 break;
00129           // Else copy the string
00130           default:
00131                 *_dst++ = *_src;
00132           }
00133           *_src++;
00134      }
00135      *_dst = '\0';
00136      // Skip spaces
00137      _src = templates_skip_spaces(_src);
00138 
00139      return _src;
00140 }

int templates_is_space ( char  c  ) 

Definition at line 37 of file DATA_PRINT/script.c.

References script_is_separator.

00038 {
00039     int result;
00040 
00041     switch(c)
00042     {
00043     // If the character is a basic space
00044     case ' ':
00045     case '\t':
00046     case '\n':
00047     case '\r':
00048          // Return 1
00049          result = 1;
00050          break;
00051     // Else
00052     default:
00053          // If the extension function is set returns its result
00054          if (script_is_separator)
00055             result = script_is_separator(c);
00056          // Else returns 0
00057          else
00058             result = 0;
00059     }
00060 
00061     return result;
00062 }

char* templates_skip_spaces ( char *  _str  ) 

Definition at line 70 of file DATA_PRINT/script.c.

References ASSERT, and templates_is_space().

00071 {
00072      char *_pstr;
00073 
00074      ASSERT(_str);
00075 
00076      _pstr = _str;
00077      // Skip spaces
00078      while(templates_is_space(*_pstr))
00079          _pstr++;
00080          
00081      return _pstr;
00082 }


Variable Documentation

Definition at line 35 of file DATA_PRINT/script.c.


Generated on Thu Dec 17 19:57:24 2009 for AVR32 UC3 - EVK1104 DSPLib Demo Documentation by  doxygen 1.5.5