20 #include "headcpp.hpp"
21 #include "name_tools.hpp"
25 void trim_spaces (
char* dest,
const char* name) {
28 bool inspace = (name[0] ==
' ') ?
true :
false ;
33 while (name[in_input]!=
'\0') {
34 isspace = (name[in_input]==
' ') ?
true :
false ;
35 if ((isspace==
false) || ((isspace==
true) && (inspace==
false))) {
36 auxi[in_output] = name[in_input] ;
43 if (auxi[in_output-1]!=
' ') {
44 auxi[in_output] =
' ' ;
47 auxi[in_output] =
'\0' ;
51 int last = in_output-2 ;
56 bool needtodo = (auxi[first]==
'(') ?
true :
false ;
61 for (
int i=first ; i<last ; i++) {
66 if ((auxi[i]==
')') && (ninside==0))
70 if ((needtodo) && (auxi[last] ==
')')) {
79 for (
int i=first ; i<in_output-first-1 ; i++) {
89 void get_util (
char* res,
char* input) {
92 trim_spaces(auxi, input) ;
96 while ((first==0) && (auxi[conte]!=
'\0')) {
97 if (input[conte]==
'_')
99 if (input[conte]==
'^')
108 get_term (auxi, res,
'_') ;
110 else get_term(auxi, res,
'^') ;
114 int nbr_char (
const char* name,
char xx) {
116 const char* copie = name ;
118 while (*copie!=
'\0') {
127 void get_term (
char* input,
char* output,
char sep) {
129 char* found = strchr(input, sep) ;
132 for (
int i=0 ; i<int(strlen(input)-strlen(found)) ; i++)
134 auxi[int(strlen(input)-strlen(found))]=
'\0' ;
136 trim_spaces(output, auxi) ;
141 while (*found !=
'\0') {
149 void get_parts (
const char* input,
char* first,
char* second,
char sep,
int place) {
151 int length =
static_cast<int>(strlen(input)) ;
153 bool finloop = false ;
154 int pos = length - 1 ;
172 for (
int i=0 ; i<pos ; i++)
173 auxi1[i] = input[i] ;
175 trim_spaces(first, auxi1) ;
178 for (
int i=pos+1 ; i<length ; i++)
179 auxi2[i-pos-1] = input[i] ;
180 auxi2[length-1-pos]=
'\0' ;
181 trim_spaces(second, auxi2) ;
186 bool is_tensor (
const char* input,
const char* name_tensor,
int& valence,
char*& name_ind, Array<int>*& type_ind) {
188 bool res = (nbr_char(input,
' ')==1) ?
true :
false ;
194 while ((first==0) && (input[conte]!=
'\0')) {
195 if (input[conte]==
'_')
197 if (input[conte]==
'^')
208 int same = strcmp(input, name_tensor);
217 while ((input[kant]!=
'_') && (input[kant]!=
'^')) {
218 name[kant] = input[kant] ;
222 name[kant+1] =
'\0' ;
225 while (input[kant]!=
'\0') {
226 ind[kkant] = input[kant] ;
231 ind[kkant+1] =
'\0' ;
234 int same = strcmp(name, name_tensor);
240 while (ind[cc]!=
'\0') {
241 if ((ind[cc]!=
' ') && (ind[cc]!=
'_') && (ind[cc]!=
'^'))
248 type_ind =
new Array<int> (valence) ;
251 name_ind =
new char [valence] ;
256 while (ind[cc]!=
'\0') {
257 if ((ind[cc]!=
' ') && (ind[cc]!=
'_') && (ind[cc]!=
'^')) {
258 name_ind[nind] = ind[cc] ;
260 type_ind->set(nind) = COV ;
262 type_ind->set(nind) = CON ;