~ubuntu-branches/ubuntu/lucid/scilab/lucid

« back to all changes in this revision

Viewing changes to modules/string/sci_gateway/c/sci_strcat.c

  • Committer: Bazaar Package Importer
  • Author(s): Sylvestre Ledru
  • Date: 2009-04-28 18:47:03 UTC
  • mfrom: (1.1.7 upstream) (4.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090428184703-7thddz8vtwqmxmx2
Tags: 5.1.1-4
* librefblas3-dev does not exist (yet). Thanks to Jose Ramon
* Do not stop when ocamlopt is not available on the arch 
  (ocaml-not-available.diff)
* Provide a clear error message for archs where modelicac compiler is 
  not available (modelicac-not-available.diff)
* scilab startup script moved from package scilab => scilab-bin (because of
  the ocamlopt problem, I cannot predict if modelicac will be available or
  not. Therefor, I ship usr/bin/ instead of binary per binary. This will
  also simplifies the packaging of Scilab 5.2)

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
/*-------------------------------------------------------------------------------------*/
71
71
static int sci_strcat_three_rhs(char *fname) 
72
72
73
 
        char typ = 0;
 
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[] ="";
 
75
        int mn = 0;
 
76
        static char def_sep[] = "";
77
77
        char *Input_String_Two = def_sep;
78
 
        static int un=1;
79
 
        int Row_One = 0,Col_One = 0;
80
 
        int mn = 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; 
85
 
 
86
 
        switch ( VarType(1)) 
87
 
        {
88
 
        case sci_strings :
89
 
                GetRhsVar(1,MATRIX_OF_STRING_DATATYPE,&Row_One,&Col_One,&Input_String_One);
90
 
                mn = Row_One*Col_One;  
91
 
                if (Rhs >= 2) 
92
 
                { 
93
 
                        /* second argument always a string and not a matrix of string */
94
 
                        int l2 = 0;
95
 
                        GetRhsVar(2,STRING_DATATYPE,&Row_Two,&Col_Two,&l2);
96
 
                        Input_String_Two = cstk(l2);
97
 
                }
98
 
                if (Rhs >= 3) 
99
 
                {
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 ) 
103
 
                        {
104
 
                                Scierror(999,_("%s: Wrong type for input argument #%d: ''%s'' or ''%s'' expected.\n"),fname,3,"c","r");
105
 
                                return 0;
106
 
                        }
107
 
                }
108
 
                switch ( typ ) 
109
 
                {
 
78
        char typ = 0;
 
79
        int i = 0;
 
80
 
 
81
        if (VarType(1) != sci_strings)
 
82
        {
 
83
                Scierror(999,_("%s: Wrong type for input argument #%d: a string vector expected.\n"),fname,1); 
 
84
                return 0;
 
85
        }
 
86
 
 
87
        if (VarType(2) != sci_strings)
 
88
        {
 
89
                Scierror(999,"%s : Wrong size for input argument #%d: Single string expected.\n",fname,2);
 
90
                return 0;
 
91
        }
 
92
 
 
93
        if (VarType(3) != sci_strings)
 
94
        {
 
95
                Scierror(999,"%s : Wrong size for input argument #%d: Single string expected.\n",fname,3);
 
96
                return 0;
 
97
        }
 
98
 
 
99
        GetRhsVar(1,MATRIX_OF_STRING_DATATYPE,&Row_One,&Col_One,&Input_String_One);
 
100
        mn = Row_One*Col_One;  
 
101
 
 
102
        if (Rhs >= 2) 
 
103
        { 
 
104
                /* second argument always a string and not a matrix of string */
 
105
                int l2 = 0;
 
106
                int Row_Two = 0,Col_Two = 0;
 
107
                GetRhsVar(2,STRING_DATATYPE,&Row_Two,&Col_Two,&l2);
 
108
                Input_String_Two = cstk(l2);
 
109
        }
 
110
 
 
111
        if (Rhs >= 3) 
 
112
        {
 
113
                int Row_Three = 0,Col_Three = 0;
 
114
                int l3 = 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 ) 
 
118
                {
 
119
                        Scierror(999,_("%s: Wrong type for input argument #%d: ''%s'' or ''%s'' expected.\n"),fname,3,"c","r");
 
120
                        return 0;
 
121
                }
 
122
        }
 
123
 
 
124
        switch ( typ ) 
 
125
        {
110
126
                case STAR : 
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);
115
 
                        k=0;
116
 
                        for ( i = 0 ; i < mn ; i++ ) 
117
127
                        {
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];
 
128
                                int nchars = 0; 
 
129
                                int one = 1;
 
130
                                int l3 = 0;
 
131
                                int k = 0;
 
132
 
 
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);
 
136
 
 
137
                                CreateVar(Rhs+1,STRING_DATATYPE,&one,&nchars,&l3);
 
138
 
 
139
                                for ( i = 0 ; i < mn ; i++ ) 
 
140
                                {
 
141
                                        int j = 0;
 
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];
 
144
                                }
 
145
                                freeArrayOfString(Input_String_One,mn);
 
146
                                LhsVar(1) = Rhs+1  ;
120
147
                        }
121
 
                        freeArrayOfString(Input_String_One,mn);
122
 
                        LhsVar(1) = Rhs+1  ;
123
 
                        break;
 
148
                break;
124
149
                case COL: 
125
 
                        /* return a column matrix */ 
126
 
                        if ( (Output_String = (char**)MALLOC((Row_One+1)*sizeof(char *)))==NULL) 
127
 
                        {
128
 
                                Scierror(999,_("%s: No more memory.\n"),fname);
129
 
                                return 0;
130
 
                        }
131
 
                        Output_String[Row_One]=NULL;
132
 
                        for (i= 0 ; i < Row_One ; i++) 
133
 
                        {
134
 
                                /* length of row i */ 
135
 
                                nchars = 0;
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); 
138
 
 
139
 
                                Output_String[i]=(char*)MALLOC((nchars+1)*sizeof(char));
140
 
                                if ( Output_String[i] == NULL) 
141
 
                                {
142
 
                                        Scierror(999,_("%s: No more memory.\n"),fname);
143
 
                                        return 0;
144
 
                                } 
145
 
                                /* fill the string */
146
 
                                strcpy(Output_String[i],Input_String_One[i]);
147
 
 
148
 
                                if ( Output_String[i] == NULL) 
149
 
                                {
150
 
                                        Scierror(999,_("%s: No more memory.\n"),fname);
151
 
                                        return 0;
152
 
                                } 
153
 
 
154
 
                                for ( j = 1 ; j < Col_One ; j++ ) 
155
 
                                {
156
 
                                        strcat(Output_String[i],Input_String_Two); 
157
 
                                        strcat(Output_String[i],Input_String_One[i+ Row_One*j]);
158
 
                                }
159
 
                                
160
 
                        }
161
 
                        
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);
165
 
                        LhsVar(1) = Rhs+1  ;
166
 
                        
167
 
                        break;
168
 
                case ROW: 
169
 
                        /* return a row matrix */ 
170
 
                        if ( (Output_String = MALLOC((Col_One+1)*sizeof(char *)))==NULL) 
171
 
                        {
172
 
                                Scierror(999,_("%s: No more memory.\n"),fname);
173
 
                                return 0;
174
 
                        }
175
 
                        Output_String[Col_One]=NULL;
176
 
                        for (j= 0 ; j < Col_One ; j++) 
177
 
                        {
178
 
                                /* length of col j */ 
179
 
                                nchars = 0;
180
 
                                for ( i = 0 ; i < Row_One ; i++ ) 
181
 
                                {
182
 
                                        nchars += (int)strlen(Input_String_One[i+ Row_One*j]);
183
 
                                }
184
 
                                nchars += (Row_One-1)*(int)strlen(Input_String_Two); 
185
 
 
186
 
                                Output_String[j] = strdup(Input_String_One[j*Row_One]);
187
 
 
188
 
                                if ( Output_String[j] == NULL) 
189
 
                                {
190
 
                                        Scierror(999,_("%s: No more memory.\n"),fname);
191
 
                                        return 0;
192
 
                                } 
193
 
 
194
 
                                for ( i = 1 ; i < Row_One ; i++ ) 
195
 
                                {
196
 
                                        strcat(Output_String[j],Input_String_Two); 
197
 
                                        strcat(Output_String[j],Input_String_One[i+ Row_One*j]);
198
 
                                }
199
 
                        }
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);
203
 
                        LhsVar(1) = Rhs+1  ;
204
 
                        break;
205
 
                }
206
 
                break; 
207
 
        default : 
208
 
                OverLoad(1);
209
 
                break; 
 
150
                        {
 
151
                                char **Output_String = NULL;
 
152
                                int nchars = 0;
 
153
                                int one = 1;
 
154
                                /* return a column matrix */ 
 
155
                                if ( (Output_String = (char**)MALLOC((Row_One+1)*sizeof(char *)))==NULL) 
 
156
                                {
 
157
                                        Scierror(999,_("%s: No more memory.\n"),fname);
 
158
                                        return 0;
 
159
                                }
 
160
                                Output_String[Row_One]=NULL;
 
161
                                for (i= 0 ; i < Row_One ; i++) 
 
162
                                {
 
163
                                        int j = 0;
 
164
                                        /* length of row i */ 
 
165
                                        nchars = 0;
 
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); 
 
168
 
 
169
                                        Output_String[i]=(char*)MALLOC((nchars+1)*sizeof(char));
 
170
                                        if ( Output_String[i] == NULL) 
 
171
                                        {
 
172
                                                Scierror(999,_("%s: No more memory.\n"),fname);
 
173
                                                return 0;
 
174
                                        } 
 
175
                                        /* fill the string */
 
176
                                        strcpy(Output_String[i],Input_String_One[i]);
 
177
 
 
178
                                        if ( Output_String[i] == NULL) 
 
179
                                        {
 
180
                                                Scierror(999,_("%s: No more memory.\n"),fname);
 
181
                                                return 0;
 
182
                                        } 
 
183
 
 
184
                                        for ( j = 1 ; j < Col_One ; j++ ) 
 
185
                                        {
 
186
                                                strcat(Output_String[i],Input_String_Two); 
 
187
                                                strcat(Output_String[i],Input_String_One[i+ Row_One*j]);
 
188
                                        }
 
189
 
 
190
                                }
 
191
 
 
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);
 
195
                                LhsVar(1) = Rhs+1  ;
 
196
                        }
 
197
                break;
 
198
 
 
199
                case ROW:
 
200
                        {
 
201
                                char **Output_String = NULL;
 
202
                                int nchars = 0;
 
203
                                int j = 0;
 
204
                                int one = 1;
 
205
                                /* return a row matrix */ 
 
206
                                if ( (Output_String = MALLOC((Col_One+1)*sizeof(char *)))==NULL) 
 
207
                                {
 
208
                                        Scierror(999,_("%s: No more memory.\n"),fname);
 
209
                                        return 0;
 
210
                                }
 
211
                                Output_String[Col_One]=NULL;
 
212
                                for (j= 0 ; j < Col_One ; j++) 
 
213
                                {
 
214
                                        /* length of col j */ 
 
215
                                        nchars = 0;
 
216
                                        for ( i = 0 ; i < Row_One ; i++ ) 
 
217
                                        {
 
218
                                                nchars += (int)strlen(Input_String_One[i+ Row_One*j]);
 
219
                                        }
 
220
                                        nchars += (Row_One-1)*(int)strlen(Input_String_Two); 
 
221
 
 
222
                                        Output_String[j] = strdup(Input_String_One[j*Row_One]);
 
223
 
 
224
                                        if ( Output_String[j] == NULL) 
 
225
                                        {
 
226
                                                Scierror(999,_("%s: No more memory.\n"),fname);
 
227
                                                return 0;
 
228
                                        } 
 
229
 
 
230
                                        for ( i = 1 ; i < Row_One ; i++ ) 
 
231
                                        {
 
232
                                                strcat(Output_String[j],Input_String_Two); 
 
233
                                                strcat(Output_String[j],Input_String_One[i+ Row_One*j]);
 
234
                                        }
 
235
                                }
 
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);
 
239
                                LhsVar(1) = Rhs+1  ;
 
240
                        }
 
241
                break;
 
242
 
 
243
                default:
 
244
                        {
 
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");
 
247
                                return 0;
 
248
                        }
 
249
                break;
 
250
 
210
251
        }
211
 
 
212
252
        C2F(putlhsvar)();
213
253
        return 0;
214
254
}
223
263
        
224
264
        if (Type_Two != sci_strings)
225
265
        {
226
 
                Scierror(246,_("%s: Wrong type for input argument #%d: Single string expected.\n"),fname); 
 
266
                Scierror(246,_("%s: Wrong type for input argument #%d: Single string expected.\n"),fname,2); 
227
267
                return 0;
228
268
        }
229
269
        else /* sci_strings */
236
276
                if (Number_Inputs_Two != 1)
237
277
                {
238
278
                        freeArrayOfString(Input_String_Two,Number_Inputs_Two);
239
 
                        Scierror(36,"%s : Wrong type for input argument #%d: Single string expected.\n",fname,2);
 
279
                        Scierror(36,"%s : Wrong size for input argument #%d: Single string expected.\n",fname,2);
240
280
                        return 0;
241
281
                }
242
282
        }