Lhogho  0.0.028
 All Data Structures Files Functions Variables Typedefs Macros Pages
param_parsers.c
Go to the documentation of this file.
1 //===================================================
2 // Project:TestSystem Author: Peter Armianov
3 //===================================================
4 //
5 // PARAM_PARSERS.C
6 //
7 // This file contains definitions of funcions which
8 // parse one configuration parameter line
9 //
10 // Revision history:
11 // 2007-05-21 - file created
12 // 2007-07-12 - additional comments in Doxygen style
13 //===================================================
14 #include <stdio.h>
15 #include <stdlib.h>
16 
17 #include "error.h"
18 #include "TestMaker.h"
19 #include "internal.h"
20 #include "param_parsers.h"
21 
22 //---------------------------------------------------
23 // Parser functions implementation
24 // For each new parameter here must be placed
25 // function that parse the line.
26 // Function name must be such like
27 // <param>_parser
28 // where <param> is the name used in PARSERS_LIST macro
29 //---------------------------------------------------
30 
31 //===================================================
39 //===================================================
40 RESULT name_parser(const TCHAR * parameter_name,
41  const TCHAR * parameter_optipons,
42  test_case_info * test_case_params)
43 {
44  /* if this is not parameter that can be handled here */
45  if (m_strcmp(parameter_name, TEXT("name")))
46  {
47  return ERR_INVALID_ARG;
48  }
49 
50  return extract_string(parameter_optipons, &test_case_params->test_name);
51 }
52 
53 //===================================================
61 //===================================================
62 RESULT cmd_parser(const TCHAR * parameter_name,
63  const TCHAR * parameter_optipons,
64  test_case_info * test_case_params)
65 {
66  /* if this is not parameter that can be handled here */
67  if (m_strcmp(parameter_name, TEXT("cmd")))
68  {
69  return ERR_INVALID_ARG;
70  }
71 
72  return extract_string(parameter_optipons, &test_case_params->command_line_param);
73 }
74 
75 
76 //----------------------------------------------------
77 // Basic functions implementation
78 //----------------------------------------------------
79 
80 //===================================================
90 //===================================================
91 RESULT extract_string(const TCHAR * parameter_optipons, TCHAR ** extracted_value)
92 {
93  UINT32 start = 0;
94  UINT32 end = 0;
95  BOOL escape_spaces = FALSE;
96 
97  while (parameter_optipons[start] && m_isspace(parameter_optipons[start]))
98  ++start;
99 
100  if (parameter_optipons[start] == SPACE_ESC_SYMBOL)
101  {
102  ++start;
103  escape_spaces = TRUE;
104  }
105  end = start;
106 
107  while (parameter_optipons[end] &&
108  !((escape_spaces && parameter_optipons[end] == SPACE_ESC_SYMBOL) ||
109  (!escape_spaces && m_isspace(parameter_optipons[end]))))
110  ++end;
111 
112  return m_strndup(extracted_value, parameter_optipons + start, end - start);
113 }
114 

[ HOME | INDEX | ATOMS | VARS | REFERENCE ]
Lhogho Developer's Documentation
Wed Jul 10 2013