OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
analyse_check.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 <stdio.h>
24#include <string.h>
25#include <stdlib.h> /* bsearch qsort */
26
27#include "analyse_define.h" /* ANALYSE_CHECK ANALYSE_CHECK_GROUP */
28#include "analyse_name.inc" /* AN_CHECK */
29
30#include "analyse.h" /* analyse*/
31
32#include "analyse_print.h" /* Analyse_Print_Error_Level Analyse_Print_Error */
33#include "analyse_memory.h" /* analyse_malloc */
34#include "analyse_getall.h" /* analyse_getlist_of_int */
35#include "analyse_comment.h" /* analyse_add_comment */
36#include "analyse_read_tools.h" /* analyse_read_comment */
37
38#include "analyse_check.h"
39
41static int ANALYSE_NB_CHECK=0;
42
43static int compar_check_group(const void *group_1_p, const void *group_2_p)
44{
45 analyse_check_group_t *group_1 = (analyse_check_group_t *)group_1_p;
46 analyse_check_group_t *group_2 = (analyse_check_group_t *)group_2_p;
47
48 if ( (group_1->id < 0) &&(group_2->id < 0)) return (group_2->id - group_1->id);
49 if (group_1->id < 0) return 1;
50 if (group_2->id < 0) return -1;
51
52 return (group_1->id - group_2->id);
53}
54
55static int compar_check_group_by_order(const void *group_1_p, const void *group_2_p)
56{
57 analyse_check_group_t *group_1 = (analyse_check_group_t *)group_1_p;
58 analyse_check_group_t *group_2 = (analyse_check_group_t *)group_2_p;
59
60 if ( (group_1->order < 0) &&(group_2->order < 0)) return (group_2->order - group_1->order);
61 if (group_1->order < 0) return 1;
62 if (group_2->order < 0) return -1;
63
64 return (group_1->order - group_2->order);
65}
66
67static int compar_check(const void *check_1_p, const void *check_2_p)
68{
69 analyse_check_t *check_1 = (analyse_check_t *)check_1_p;
70 analyse_check_t *check_2 = (analyse_check_t *)check_2_p;
71
72 if ( (check_1->id < 0) &&(check_2->id < 0)) return (check_2->id - check_1->id);
73 if (check_1->id < 0) return 1;
74 if (check_2->id < 0) return -1;
75
76 return (check_1->id - check_2->id);
77}
78
79
80static analyse_check_group_t *check_group_create(int nb_check_group)
81{
82 analyse_check_group_t *check_group;
83 int i;
84
85 check_group = (analyse_check_group_t *)analyse_malloc(nb_check_group*sizeof(analyse_check_group_t));
86
87 for(i=0; i<nb_check_group; i++)
88 {
89 (check_group+i)->order = 0;
90 (check_group+i)->id = -i-1;
91 (check_group+i)->title = NULL;
92 (check_group+i)->nb_check = 0;
93 (check_group+i)->check_list = NULL;
94 (check_group+i)->check_message = NULL;
95 }
96
97 return check_group;
98}
99
100static analyse_check_t *check_create(int nb_check)
101{
102 analyse_check_t *check;
103 int i;
104
105 check = (analyse_check_t *)analyse_malloc(nb_check*sizeof(analyse_check_t));
106
107 for(i=0; i<nb_check; i++)
108 {
109 (check+i)->id = -i-1;
110 (check+i)->title = NULL;
111 (check+i)->check_message = NULL;
112 }
113
114 return check;
115}
116
117
118void analyse_check_store(analyse_check_t *check_list, int language, int id)
119{
120 analyse_comment_t *scan_comment;
121 analyse_check_t tmp_check;
122 analyse_check_t *work_check;
123
124 char line[ANALYSE_SIZE_OF_LINE];
125
126 /* Search id */
127 tmp_check.id = id;
128 work_check = bsearch( &tmp_check, check_list, ANALYSE_NB_CHECK, sizeof(analyse_check_t), compar_check);
129
130 if ( work_check == NULL)
131 {
132 sprintf(line, "Unknown Id for Check %d\nNo Message Available\n", id );
134 }
135
136 if ( work_check->check_message != NULL )
137 {
138 analyse_free(work_check->check_message);
139 work_check->check_message = NULL;
140 }
141
142 scan_comment = analyse_get_right_comment( work_check->title, language, ANALYSE_ENGLISH);
143
144 work_check->check_message = analyse_fill_description(AN_CHECK, scan_comment->text);
145
146}
147
148
149/*
150 This Function is the equivalent of a part of the Main, in build_default_file.c
151*/
152void analyse_check_file_read(analyse_check_t **check_p, analyse_check_group_t **check_group_p, char *infilename )
153{
154 FILE *infile=NULL;
155 char line[ANALYSE_SIZE_OF_LINE];
156 char key[ANALYSE_SIZE_OF_LINE];
157 int i, id;
158 int linecount = 0;
159
160 analyse_comment_t *comment;
161
162 analyse_check_t *work_check;
163 analyse_check_t tmp_check;
164
165 analyse_check_group_t *work_check_group;
166 analyse_check_group_t tmp_check_group;
167
168 int count_check_group = 0;
169 int check_group_already_print = 0;
170
171 int count_check = 0;
172 int check_already_print = 0;
173
174 int nb_check, nb_check_group, size, size2;
175 int *tab, *tab2;
176
177 int nb_elt;
178 int *elt;
179
180 /*************/
181 /* Open File */
182 /*************/
183 if (infilename != NULL)
184 {
185 infile = fopen(infilename,"r");
186 }
187
188 if (infile == NULL)
189 {
190 Analyse_Print_Debug("\nNo Check File Found. Use Default\n\n");
191
192
193 return;
194 }
195
196
197 /***************************/
198 /* Allocate Message Memory */
199 /***************************/
200
201 /* Count message */
202 analyse_count_check(line, infile, infilename, &linecount, &nb_check, &nb_check_group);
203 rewind(infile);
204 analyse_stack_check(line, infile, infilename, &linecount, &nb_check_group, &size, &tab, &nb_check, &size2, &tab2 );
205
206 ANALYSE_NB_CHECK_GROUP = nb_check_group;
207 ANALYSE_NB_CHECK = nb_check;
208
209 analyse_free(tab);
210 analyse_free(tab2);
211
212 *check_p = check_create(ANALYSE_NB_CHECK);
214
215
216 /****************/
217 /* Read Message */
218 /****************/
219 rewind(infile);
220 while ( ( analyse_getline(line, infile, infilename, &linecount) != -1) &&
221 ( strncmp(line, "/END", 4) != 0 ))
222 {
223 if (strstr(line, "/ANALYSE/CHECK/GROUP") != NULL)
224 {
225 /* Search Group id */
226 analyse_getkey(4 , line, key);
227 sscanf(key, "%d", &id );
228
229 /* Search id */
230 tmp_check_group.id = id;
231 work_check_group = bsearch( &tmp_check_group, *check_group_p, ANALYSE_NB_CHECK_GROUP, sizeof(analyse_check_group_t), compar_check_group);
232
233 if ( work_check_group == NULL)
234 {
235 if (count_check_group >= ANALYSE_NB_CHECK_GROUP)
236 {
237 if ( check_group_already_print == 0)
238 {
239 Analyse_Print_Error_Level("\n\n*** Analyse Internal Error (ANALYSE_NB_CHECK_GROUP) : Too Many Messages \n\n", 2);
240 check_group_already_print = 1;
241 }
242 continue;
243 }
244
245 work_check_group = *check_group_p + count_check_group;
246
247 work_check_group->order = count_check_group;
248 work_check_group->id = id;
249
250 /* Note : if file order is in id increase, this qsort does nothing ... */
252 tmp_check_group.id = id;
253 /* .. and this bsearch gives the same work_group */
254 work_check_group = bsearch( &tmp_check_group, *check_group_p, ANALYSE_NB_CHECK_GROUP, sizeof(analyse_check_group_t), compar_check_group);
255
256 count_check_group++;
257 }
258
259 analyse_getkey(5 , line, key);
260
261 if (strncmp(key, "TITLE", 5) == 0)
262 {
263 /* Read Comment */
264 comment = analyse_read_comment(line, infile, infilename, &linecount);
265 analyse_add_comment(ANALYSE_CHECK_GROUP, (void *)work_check_group, comment);
266 }
267 else if (strncmp(key, "DESCRIPTION", 5) == 0)
268 {
269 /* Read list of ids */
270 if ( analyse_getlist_of_int(&nb_elt, &elt, infile, infilename, &linecount) == 0)
271 {
272 work_check_group->check_list = (int *)analyse_realloc(work_check_group->check_list, (work_check_group->nb_check + nb_elt)*sizeof(int));
273 work_check_group->check_message = (char **)analyse_realloc(work_check_group->check_message, (work_check_group->nb_check + nb_elt)*sizeof(char *));
274
275 for(i=0; i<nb_elt; i++)
276 {
277 work_check_group->check_list[work_check_group->nb_check + i] = elt[i];
278 work_check_group->check_message[work_check_group->nb_check + i] = NULL;
279 }
280 analyse_free(elt);
281 work_check_group->nb_check = work_check_group->nb_check + nb_elt;
282 }
283 }
284 }
285 else if (strstr(line, "/ANALYSE/CHECK") != NULL)
286 {
287 analyse_getkey(3 , line, key);
288 sscanf(key, "%d", &id );
289
290 /* Search id */
291 tmp_check.id = id;
292 work_check = bsearch( &tmp_check, *check_p, ANALYSE_NB_CHECK, sizeof(analyse_check_t), compar_check);
293
294 if ( work_check == NULL)
295 {
296 if (count_check >= ANALYSE_NB_CHECK)
297 {
298 if ( check_already_print == 0)
299 {
300 Analyse_Print_Error_Level("\n\n*** Analyse Internal Error (ANALYSE_NB_CHECK) : Too Many Messages \n\n", 2);
301 check_already_print = 1;
302 }
303 continue;
304 }
305
306 work_check = *check_p + count_check;
307 count_check++;
308
309 work_check->id = id;
310
311 /* Note : if file order is in id increase, this qsort does nothing ... */
313 tmp_check.id = id;
314 /* .. and this bsearch gives the same work_check */
315 work_check = bsearch( &tmp_check, *check_p, ANALYSE_NB_CHECK, sizeof(analyse_check_t), compar_check);
316
317 }
318
319 /* Read Comment */
320 comment = analyse_read_comment(line, infile, infilename, &linecount);
321 analyse_add_comment(ANALYSE_CHECK, (void *)work_check, comment);
322
323 }
324 }
325
326 fclose(infile);
327
328}
329
330void analyse_check_file_write(analyse_check_t *check_list, analyse_check_group_t *check_group_list, int language)
331{
332 int i,j, nb_check;
333
334 analyse_comment_t *scan_comment;
335
336 analyse_check_group_t *work_check_group;
337
338 analyse_check_t tmp_check;
339 analyse_check_t *work_check;
340
341 /* re order groups by order appearance in file, and no more by id */
343
344 for (i=0; i<ANALYSE_NB_CHECK_GROUP; i++)
345 {
346 work_check_group = check_group_list+i;
347 nb_check = work_check_group->nb_check;
348
349 scan_comment = analyse_get_right_comment( work_check_group->title, language, ANALYSE_ENGLISH);
350
351 if ((scan_comment != NULL) && (scan_comment->text != NULL))
352 {
353 analyse_write_f("\n\n");
354 analyse_write_f(scan_comment->text);
355 /* analyse_write_f("\n"); */
356 }
357
358 for( j=0; j<nb_check; j++)
359 {
360 tmp_check.id = work_check_group->check_list[j];
361 work_check = bsearch( &tmp_check, check_list, ANALYSE_NB_CHECK, sizeof(analyse_check_t), compar_check);
362
363 if ((work_check != NULL) && (work_check->check_message!= NULL))
364 {
365 analyse_write_f(work_check->check_message);
366 /* analyse_write_f("\n"); */
367 }
368 }
369 }
370}
371
373{
374
375
376}
void analyse_write_f(char *message)
Definition analyse.c:1022
static int compar_check(const void *check_1_p, const void *check_2_p)
static int ANALYSE_NB_CHECK_GROUP
static analyse_check_group_t * check_group_create(int nb_check_group)
void analyse_check_file_read(analyse_check_t **check_p, analyse_check_group_t **check_group_p, char *infilename)
void analyse_check_file_write(analyse_check_t *check_list, analyse_check_group_t *check_group_list, int language)
static analyse_check_t * check_create(int nb_check)
void analyse_check_store(analyse_check_t *check_list, int language, int id)
static int ANALYSE_NB_CHECK
static int compar_check_group(const void *group_1_p, const void *group_2_p)
static int compar_check_group_by_order(const void *group_1_p, const void *group_2_p)
void analyse_check_clean_memory(analyse_check_t *check_list, analyse_check_group_t *check_group_list)
struct analyse_check_group_s analyse_check_group_t
struct analyse_check_s analyse_check_t
void analyse_add_comment(int object_type, void *object, analyse_comment_t *comment)
analyse_comment_t * analyse_get_right_comment(analyse_comment_t *start_comment, int language, int default_language)
char * analyse_fill_description(int object_type, char *description)
struct analyse_comment_s analyse_comment_t
#define ANALYSE_CHECK
#define ANALYSE_CHECK_GROUP
#define ANALYSE_SIZE_OF_LINE
#define ANALYSE_ENGLISH
int analyse_getkey(int pos, char *line, char *name)
int analyse_getlist_of_int(int *nb_elt, int **elt, FILE *infile, char *infilename, int *linecount)
int analyse_getline(char line[], FILE *infile, char *infilename, int *linecount)
void * analyse_malloc(size_t size)
void analyse_free(void *block)
void * analyse_realloc(void *block, size_t size)
void Analyse_Print_Error_Level(char *text, int level)
void Analyse_Print_Debug(char *text)
void analyse_count_check(char *line, FILE *infile, char *infilename, int *linecount_p, int *cnt_check_p, int *cnt_group_p)
analyse_comment_t * analyse_read_comment(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)
recursive subroutine qsort(a, idx, first, last)
initmumps id
analyse_comment_t * title
analyse_comment_t * title