70
70
/*-------------------------------------------------------------------------------------*/
71
71
static int sci_strcat_three_rhs(char *fname)
73
int Row_One = 0,Col_One = 0;
74
74
char **Input_String_One = NULL;
75
char **Output_String = NULL;
76
static char def_sep[] ="";
76
static char def_sep[] = "";
77
77
char *Input_String_Two = def_sep;
79
int Row_One = 0,Col_One = 0;
81
int i = 0,j = 0,k = 0;
82
int Row_Two = 0,Col_Two = 0;
83
int Row_Three = 0,Col_Three = 0;
84
int l3 = 0,nchars = 0;
89
GetRhsVar(1,MATRIX_OF_STRING_DATATYPE,&Row_One,&Col_One,&Input_String_One);
93
/* second argument always a string and not a matrix of string */
95
GetRhsVar(2,STRING_DATATYPE,&Row_Two,&Col_Two,&l2);
96
Input_String_Two = cstk(l2);
100
GetRhsVar(3,STRING_DATATYPE,&Row_Three,&Col_Three,&l3);
101
if ( Row_Three*Col_Three != 0) typ = cstk(l3)[0];
102
if (typ != COL && typ != ROW )
104
Scierror(999,_("%s: Wrong type for input argument #%d: ''%s'' or ''%s'' expected.\n"),fname,3,"c","r");
81
if (VarType(1) != sci_strings)
83
Scierror(999,_("%s: Wrong type for input argument #%d: a string vector expected.\n"),fname,1);
87
if (VarType(2) != sci_strings)
89
Scierror(999,"%s : Wrong size for input argument #%d: Single string expected.\n",fname,2);
93
if (VarType(3) != sci_strings)
95
Scierror(999,"%s : Wrong size for input argument #%d: Single string expected.\n",fname,3);
99
GetRhsVar(1,MATRIX_OF_STRING_DATATYPE,&Row_One,&Col_One,&Input_String_One);
100
mn = Row_One*Col_One;
104
/* second argument always a string and not a matrix of string */
106
int Row_Two = 0,Col_Two = 0;
107
GetRhsVar(2,STRING_DATATYPE,&Row_Two,&Col_Two,&l2);
108
Input_String_Two = cstk(l2);
113
int Row_Three = 0,Col_Three = 0;
115
GetRhsVar(3,STRING_DATATYPE,&Row_Three,&Col_Three,&l3);
116
if ( Row_Three*Col_Three != 0) typ = cstk(l3)[0];
117
if (typ != COL && typ != ROW )
119
Scierror(999,_("%s: Wrong type for input argument #%d: ''%s'' or ''%s'' expected.\n"),fname,3,"c","r");
111
/* just return one string */
112
for ( i = 0 ; i < mn ; i++ ) nchars += (int)strlen(Input_String_One[i]);
113
nchars += (mn-1)*(int)strlen(Input_String_Two);
114
CreateVar(Rhs+1,STRING_DATATYPE,&un,&nchars,&l3);
116
for ( i = 0 ; i < mn ; i++ )
118
for ( j =0 ; j < (int)strlen(Input_String_One[i]) ; j++ ) *cstk(l3+ k++) = Input_String_One[i][j];
119
if ( i != mn-1) for ( j =0 ; j < (int)strlen(Input_String_Two) ; j++ ) *cstk(l3+ k++) = Input_String_Two[j];
133
/* just return one string */
134
for ( i = 0 ; i < mn ; i++ ) nchars += (int)strlen(Input_String_One[i]);
135
nchars += (mn-1)*(int)strlen(Input_String_Two);
137
CreateVar(Rhs+1,STRING_DATATYPE,&one,&nchars,&l3);
139
for ( i = 0 ; i < mn ; i++ )
142
for ( j =0 ; j < (int)strlen(Input_String_One[i]) ; j++ ) *cstk(l3+ k++) = Input_String_One[i][j];
143
if ( i != mn-1) for ( j =0 ; j < (int)strlen(Input_String_Two) ; j++ ) *cstk(l3+ k++) = Input_String_Two[j];
145
freeArrayOfString(Input_String_One,mn);
121
freeArrayOfString(Input_String_One,mn);
125
/* return a column matrix */
126
if ( (Output_String = (char**)MALLOC((Row_One+1)*sizeof(char *)))==NULL)
128
Scierror(999,_("%s: No more memory.\n"),fname);
131
Output_String[Row_One]=NULL;
132
for (i= 0 ; i < Row_One ; i++)
134
/* length of row i */
136
for ( j = 0 ; j < Col_One ; j++ ) nchars += (int)strlen(Input_String_One[i+ Row_One*j]);
137
nchars += (Col_One-1)*(int)strlen(Input_String_Two);
139
Output_String[i]=(char*)MALLOC((nchars+1)*sizeof(char));
140
if ( Output_String[i] == NULL)
142
Scierror(999,_("%s: No more memory.\n"),fname);
145
/* fill the string */
146
strcpy(Output_String[i],Input_String_One[i]);
148
if ( Output_String[i] == NULL)
150
Scierror(999,_("%s: No more memory.\n"),fname);
154
for ( j = 1 ; j < Col_One ; j++ )
156
strcat(Output_String[i],Input_String_Two);
157
strcat(Output_String[i],Input_String_One[i+ Row_One*j]);
162
CreateVarFromPtr(Rhs+1,MATRIX_OF_STRING_DATATYPE, &Row_One, &un, Output_String);
163
freeArrayOfString(Input_String_One,mn);
164
freeArrayOfString(Output_String,Row_One+1);
169
/* return a row matrix */
170
if ( (Output_String = MALLOC((Col_One+1)*sizeof(char *)))==NULL)
172
Scierror(999,_("%s: No more memory.\n"),fname);
175
Output_String[Col_One]=NULL;
176
for (j= 0 ; j < Col_One ; j++)
178
/* length of col j */
180
for ( i = 0 ; i < Row_One ; i++ )
182
nchars += (int)strlen(Input_String_One[i+ Row_One*j]);
184
nchars += (Row_One-1)*(int)strlen(Input_String_Two);
186
Output_String[j] = strdup(Input_String_One[j*Row_One]);
188
if ( Output_String[j] == NULL)
190
Scierror(999,_("%s: No more memory.\n"),fname);
194
for ( i = 1 ; i < Row_One ; i++ )
196
strcat(Output_String[j],Input_String_Two);
197
strcat(Output_String[j],Input_String_One[i+ Row_One*j]);
200
CreateVarFromPtr(Rhs+1,MATRIX_OF_STRING_DATATYPE, &un, &Col_One, Output_String);
201
freeArrayOfString(Input_String_One,mn);
202
freeArrayOfString(Output_String,Col_One+1);
151
char **Output_String = NULL;
154
/* return a column matrix */
155
if ( (Output_String = (char**)MALLOC((Row_One+1)*sizeof(char *)))==NULL)
157
Scierror(999,_("%s: No more memory.\n"),fname);
160
Output_String[Row_One]=NULL;
161
for (i= 0 ; i < Row_One ; i++)
164
/* length of row i */
166
for ( j = 0 ; j < Col_One ; j++ ) nchars += (int)strlen(Input_String_One[i+ Row_One*j]);
167
nchars += (Col_One-1)*(int)strlen(Input_String_Two);
169
Output_String[i]=(char*)MALLOC((nchars+1)*sizeof(char));
170
if ( Output_String[i] == NULL)
172
Scierror(999,_("%s: No more memory.\n"),fname);
175
/* fill the string */
176
strcpy(Output_String[i],Input_String_One[i]);
178
if ( Output_String[i] == NULL)
180
Scierror(999,_("%s: No more memory.\n"),fname);
184
for ( j = 1 ; j < Col_One ; j++ )
186
strcat(Output_String[i],Input_String_Two);
187
strcat(Output_String[i],Input_String_One[i+ Row_One*j]);
192
CreateVarFromPtr(Rhs+1,MATRIX_OF_STRING_DATATYPE, &Row_One, &one, Output_String);
193
freeArrayOfString(Input_String_One,mn);
194
freeArrayOfString(Output_String,Row_One+1);
201
char **Output_String = NULL;
205
/* return a row matrix */
206
if ( (Output_String = MALLOC((Col_One+1)*sizeof(char *)))==NULL)
208
Scierror(999,_("%s: No more memory.\n"),fname);
211
Output_String[Col_One]=NULL;
212
for (j= 0 ; j < Col_One ; j++)
214
/* length of col j */
216
for ( i = 0 ; i < Row_One ; i++ )
218
nchars += (int)strlen(Input_String_One[i+ Row_One*j]);
220
nchars += (Row_One-1)*(int)strlen(Input_String_Two);
222
Output_String[j] = strdup(Input_String_One[j*Row_One]);
224
if ( Output_String[j] == NULL)
226
Scierror(999,_("%s: No more memory.\n"),fname);
230
for ( i = 1 ; i < Row_One ; i++ )
232
strcat(Output_String[j],Input_String_Two);
233
strcat(Output_String[j],Input_String_One[i+ Row_One*j]);
236
CreateVarFromPtr(Rhs+1,MATRIX_OF_STRING_DATATYPE, &one, &Col_One, Output_String);
237
freeArrayOfString(Input_String_One,mn);
238
freeArrayOfString(Output_String,Col_One+1);
245
freeArrayOfString(Input_String_One,mn);
246
Scierror(999,_("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"),fname,3,"c","r");
212
252
C2F(putlhsvar)();