OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
analyse_read_tools.c
Go to the documentation of this file.
1//Copyright> OpenRadioss
2//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3//Copyright>
4//Copyright> This program is free software: you can redistribute it and/or modify
5//Copyright> it under the terms of the GNU Affero General Public License as published by
6//Copyright> the Free Software Foundation, either version 3 of the License, or
7//Copyright> (at your option) any later version.
8//Copyright>
9//Copyright> This program is distributed in the hope that it will be useful,
10//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//Copyright> GNU Affero General Public License for more details.
13//Copyright>
14//Copyright> You should have received a copy of the GNU Affero General Public License
15//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16//Copyright>
17//Copyright>
18//Copyright> Commercial Alternative: Altair Radioss Software
19//Copyright>
20//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21//Copyright> software under a commercial license. Contact Altair to discuss further if the
22//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23#include <string.h>
24#include <stdio.h> /* sscanf */
25#include <stdlib.h> /* qsort */
26#include <string.h>
27
28#include "analyse_define.h" /* ANALYSE_SIZE_OF_LINE */
29
30#include "analyse_memory.h" /* analyse_malloc */
31#include "analyse_getall.h" /* analyse_getline analyse_getkey */
32#include "analyse_string.h" /* analyse_string_fit_start_end */
33
34#include "analyse_read_tools.h"
35
36static int compar_int(const void *int_1_p, const void *int_2_p)
37{
38 int *int_1 = (int *)int_1_p;
39 int *int_2 = (int *)int_2_p;
40
41 return ( *int_1 - *int_2);
42}
43
44static int count_ids( int size, int *tab)
45{
46 int keep_id, i, cnt;
47
48 keep_id = -1;
49 cnt = 0;
50
51 if (tab == NULL) return cnt;
52
53 for(i=0; i<size; i++)
54 {
55 if (tab[i] != keep_id)
56 {
57 cnt++;
58 keep_id = tab[i];
59 }
60 }
61
62 return cnt;
63}
64
65
66int analyse_find_id( int size, int *tab, int id)
67{
68 int keep_id, i, cnt;
69
70 keep_id = -1;
71 cnt = 0;
72
73 for(i=0; i<size; i++)
74 {
75 if (tab[i] != keep_id)
76 {
77 cnt++;
78 keep_id = tab[i];
79 }
80
81 if (tab[i] == id)
82 break;
83 }
84
85 return cnt;
86}
87
88/* lm41n7 +++ */
89char *analyse_read_text_default(char *line, FILE *infile, char *filename, int *linecount_p)
90{
91 int i;
92 int nb_line=0;
93 int nb_dataline=0;
94 char *text;
95
96 analyse_getsize_of_enum (&nb_line, &nb_dataline, infile, filename, linecount_p);
97
98 text = (char *)analyse_malloc((nb_dataline*(ANALYSE_SIZE_OF_LINE+1))*sizeof(char));
99#ifdef _WIN64
100 strcpy_s(text, ANALYSE_SIZE_OF_LINE+1,"");
101#else
102 strcpy(text, "");
103#endif
104 for (i=0; i<nb_dataline; i++)
105 {
106 if ( analyse_getline(line, infile, filename, linecount_p) == -1)
107 {
108 analyse_free(text);
109 return NULL;
110 }
111
113 if (strlen(line) > 0)
114 {
115 #ifdef _WIN64
116 strcat_s(text,ANALYSE_SIZE_OF_LINE+1, line);
117 strcat_s(text,ANALYSE_SIZE_OF_LINE+1, "\\n");
118 #else
119 strcat(text, line);
120 strcat(text, "\\n");
121 #endif
122 }
123 }
124
125 return text;
126}
127/* lm41n7 --- */
128
129
130char *analyse_read_text(char *line, FILE *infile, char *filename, int *linecount_p)
131{
132 int i;
133 int nb_line=0;
134 int nb_dataline=0;
135 char *text;
136
137 analyse_getsize_of_enum (&nb_line, &nb_dataline, infile, filename, linecount_p);
138
139 text = (char *)analyse_malloc((nb_dataline*(ANALYSE_SIZE_OF_LINE+1))*sizeof(char));
140 #ifdef _WIN64
141 strcpy_s(text, ANALYSE_SIZE_OF_LINE+1,"");
142 #else
143 strcpy(text, "");
144 #endif
145
146 for (i=0; i<nb_dataline; i++)
147 {
148 if ( analyse_getline(line, infile, filename, linecount_p) == -1)
149 {
150 analyse_free(text);
151 return NULL;
152 }
153
155 if (strlen(line) > 0)
156 {
157 #ifdef _WIN64
158 strcat_s(text,ANALYSE_SIZE_OF_LINE+1, line);
159 strcat_s(text,ANALYSE_SIZE_OF_LINE+1, "\n");
160 #else
161 strcat(text, line);
162 strcat(text, "\n");
163 #endif
164 }
165 }
166
167 return text;
168}
169
170analyse_comment_t *analyse_read_comment(char *line, FILE *infile, char *filename, int *linecount_p)
171{
172 analyse_comment_t *comment;
173
174 /* Read Comment */
176
177 if ( analyse_getline(line, infile, filename, linecount_p) == -1)
178 {
179 analyse_free(comment);
180 return NULL;
181 }
182
183 if (strncmp(line, "ENGLISH",7) == 0)
184 comment->language = ANALYSE_ENGLISH;
185 else
186 comment->language = -1;
187
188 comment->text = analyse_read_text(line, infile, filename, linecount_p);
189
190 return comment;
191}
192
193
194void analyse_count_error(char *line, FILE *infile, char *infilename, int *linecount_p, int *cnt_p)
195{
196 *cnt_p = 0;
197
198 while ( ( analyse_getline(line, infile, infilename, linecount_p) != -1) &&
199 ( strncmp(line, "/END", 4) != 0 ))
200 {
201 /*ls41l33 if (strstr(line, "/ANALYSE/ERROR/") != NULL) (*cnt_p)++;*/
202 if (strstr(line, "/ANALYSE/MESSAGE/") != NULL) (*cnt_p)++;
203 }
204}
205
206
207void analyse_count_check(char *line, FILE *infile, char *infilename, int *linecount_p, int *cnt_check_p, int *cnt_group_p)
208{
209 *cnt_check_p = 0;
210 *cnt_group_p = 0;
211
212 while ( ( analyse_getline(line, infile, infilename, linecount_p) != -1) &&
213 ( strncmp(line, "/END", 4) != 0 ))
214 {
215 if (strstr(line, "/ANALYSE/CHECK/GROUP") != NULL)
216 {
217 (*cnt_group_p)++;
218 }
219 else if ( strstr(line, "/ANALYSE/CHECK/") != NULL)
220 {
221 (*cnt_check_p)++;
222 }
223 }
224}
225
226
227void analyse_stack_error(char *line, FILE *infile, char *infilename, int *linecount_p,
228 int *cnt_p, int *size_p, int **tab_p)
229{
230 char key[ANALYSE_SIZE_OF_LINE];
231 int step;
232
233 *size_p = *cnt_p;
234 *tab_p = (int*)analyse_malloc((*size_p)*sizeof(int));
235
236 step = 0;
237
238 while ( ( analyse_getline(line, infile, infilename, linecount_p) != -1) &&
239 ( strncmp(line, "/END", 4) != 0 ))
240 {
241 /* ls41l33 if (strstr(line, "/ANALYSE/ERROR/") != NULL) */
242 if (strstr(line, "/ANALYSE/MESSAGE/") != NULL)
243 {
244 analyse_getkey(3 , line, key);
245 #ifdef _WIN64
246 sscanf_s(key, "%d", *tab_p+ step );
247 #else
248 sscanf(key, "%d", *tab_p+ step );
249 #endif
250 step ++;
251 }
252 }
253
254 /* sort Ids */
255 qsort( *tab_p, *size_p, sizeof(int), compar_int);
256
257 /* Cnt different id */
258 *cnt_p = count_ids(*size_p, *tab_p);
259
260}
261
262
263void analyse_stack_check(char *line, FILE *infile, char *infilename, int *linecount_p,
264 int *nb_check_group_p, int *size_p, int **tab_p,
265 int *nb_check_p, int *size2_p, int **tab2_p)
266{
267 char key[ANALYSE_SIZE_OF_LINE];
268 int nb_check, nb_check_group;
269
270 *size_p = *nb_check_group_p;
271 *size2_p = *nb_check_p;
272
273 *tab_p =(int*)analyse_malloc((*size_p)*sizeof(int));
274 *tab2_p =(int*)analyse_malloc((*size2_p)*sizeof(int));
275
276 nb_check_group = 0;
277 nb_check = 0;
278
279 while ( ( analyse_getline(line, infile, infilename, linecount_p) != -1) &&
280 ( strncmp(line, "/END", 4) != 0 ))
281 {
282 if (strstr(line, "/ANALYSE/CHECK/GROUP") != NULL)
283 {
284 analyse_getkey(4 , line, key);
285 #ifdef _WIN64
286 sscanf_s(key, "%d", *tab_p+nb_check_group );
287 #else
288 sscanf(key, "%d", *tab_p+nb_check_group );
289 #endif
290 nb_check_group++;
291 }
292 else if (strstr(line, "/ANALYSE/CHECK") != NULL)
293 {
294 analyse_getkey(3 , line, key);
295 #ifdef _WIN64
296 sscanf_s(key, "%d", *tab2_p+nb_check);
297 #else
298 sscanf(key, "%d", *tab2_p+nb_check);
299 #endif
300 nb_check ++;
301 }
302 }
303
304 /* sort Ids */
305 qsort(*tab_p, *size_p, sizeof(int), compar_int);
306 qsort(*tab2_p, *size2_p, sizeof(int), compar_int);
307
308 /* Cnt different id */
309 *nb_check_group_p = count_ids(*size_p, *tab_p);
310 *nb_check_p = count_ids(*size2_p, *tab2_p);
311
312}
313
struct analyse_comment_s analyse_comment_t
#define ANALYSE_SIZE_OF_LINE
#define ANALYSE_ENGLISH
int analyse_getsize_of_enum(int *nb_line, int *nb_dataline, FILE *infile, char *infilename, int *linecount)
int analyse_getkey(int pos, char *line, char *name)
int analyse_getline(char line[], FILE *infile, char *infilename, int *linecount)
void * analyse_malloc(size_t size)
void analyse_free(void *block)
static int count_ids(int size, int *tab)
void analyse_count_check(char *line, FILE *infile, char *infilename, int *linecount_p, int *cnt_check_p, int *cnt_group_p)
int analyse_find_id(int size, int *tab, int id)
analyse_comment_t * analyse_read_comment(char *line, FILE *infile, char *filename, int *linecount_p)
void analyse_count_error(char *line, FILE *infile, char *infilename, int *linecount_p, int *cnt_p)
static int compar_int(const void *int_1_p, const void *int_2_p)
char * analyse_read_text_default(char *line, FILE *infile, char *filename, int *linecount_p)
char * analyse_read_text(char *line, FILE *infile, char *filename, int *linecount_p)
void analyse_stack_check(char *line, FILE *infile, char *infilename, int *linecount_p, int *nb_check_group_p, int *size_p, int **tab_p, int *nb_check_p, int *size2_p, int **tab2_p)
void analyse_stack_error(char *line, FILE *infile, char *infilename, int *linecount_p, int *cnt_p, int *size_p, int **tab_p)
char * analyse_string_fit_start_end(char *name)
recursive subroutine qsort(a, idx, first, last)