This function receives the raw string passed from the command line * \param string The passed string * \param name The extracted name of the function * \param params The extracted string between brackets */
| 135 | * \param params The extracted string between brackets |
| 136 | */ |
| 137 | int parse_function(const char * string, char * name, char * params) |
| 138 | { |
| 139 | int i; |
| 140 | /* num of whitespaces in front of the function */ |
| 141 | int num_front_whitespaces = 0; |
| 142 | /* num of character that bears the first parameter char - beyond '(' */ |
| 143 | int in_parameters = 0; |
| 144 | /* trim the leading whitespaces */ |
| 145 | for (i = 0; i < long_strlen - 1; i++) |
| 146 | if(string[i] == ' ' || string[i] == '\t') |
| 147 | num_front_whitespaces++; |
| 148 | else |
| 149 | break; |
| 150 | /* copy the function name */ |
| 151 | for (; i < long_strlen - 1 && string[i] != '('; i++) |
| 152 | if(string[i] == ' ' || string[i] == '\t') |
| 153 | break; |
| 154 | else |
| 155 | name[i - num_front_whitespaces] = string[i]; |
| 156 | /* terminate the string */ |
| 157 | name[i - num_front_whitespaces] = '\0'; |
| 158 | /* finally get the parameter */ |
| 159 | for (; i < long_strlen - 1 && string[i] != ')'; i++) |
| 160 | if(string[i] == '(') |
| 161 | { |
| 162 | in_parameters = i + 1; |
| 163 | continue; |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | if(in_parameters != 0) |
| 168 | params[i - in_parameters] = string[i]; |
| 169 | } |
| 170 | /* again terminate the string */ |
| 171 | params[i - in_parameters] = '\0'; |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | /** Takes a string and removes whitespaces within |
| 176 | * \param string The input string |