OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
analyse_error.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 <stdlib.h>
24#include <stdio.h>
25#include <string.h>
26
27#include "analyse_define.h"/* ANALYSE_SIZE_OF_LINE
28 ANALYSE_ERROR_TITLE ANALYSE_ERROR_DESCRIPTION */
29
30#include "analyse_getall.h" /* analyse_getkey analyse_getline */
31#include "analyse_print.h" /* Analyse_Print_Error_Level Analyse_Print_Error */
32#include "analyse_memory.h" /* analyse_malloc analyse_free */
33#include "analyse_comment.h" /* analyse_fill_description analyse_get_right_commment */
34#include "analyse_read_tools.h" /* analyse_read_comment */
35
36#include "analyse_error.h"
37
38static int ANALYSE_NB_ERROR=0;
39
40static int compar_error(const void *error_1_p, const void *error_2_p)
41{
42 analyse_error_info_t *error_1 = (analyse_error_info_t *)error_1_p;
43 analyse_error_info_t *error_2 = (analyse_error_info_t *)error_2_p;
44
45 if ( (error_1->id < 0) &&(error_2->id < 0)) return (error_2->id - error_1->id);
46 if (error_1->id < 0) return 1;
47 if (error_2->id < 0) return -1;
48
49 return (error_1->id - error_2->id);
50}
51
53{
54 int i=0;
55 analyse_error_info_t *error_info;
56
57 error_info = (analyse_error_info_t *)analyse_malloc(size*sizeof(analyse_error_info_t));
58
59 for ( i=0; i<size; i++)
60 {
61 (error_info+i)->id = -i-1;
62 (error_info+i)->global_cnt=0;
63 (error_info+i)->tmp_cnt=0;
64 (error_info+i)->title = NULL;
65 (error_info+i)->description = NULL;
66 (error_info+i)->comment = NULL;
67 }
68 return error_info;
69
70}
71
72/**************************** Cls41l04 +++ ********************************/
73void analyse_error_cnt(analyse_error_info_t *error_list, int id)
74{
75 analyse_error_info_t tmp_error;
76 analyse_error_info_t *work_error=NULL;
77
78 /* Search Error */
79 tmp_error.id = id;
80 work_error = bsearch( &tmp_error, error_list, ANALYSE_NB_ERROR, sizeof(analyse_error_info_t), compar_error);
81
82 if (work_error != NULL)
83 {
84 work_error->global_cnt++;
85 work_error->tmp_cnt++;
86 }
87}
88
89void analyse_error_set_tmp_cnt(analyse_error_info_t *error_list, int id, int value)
90{
91 analyse_error_info_t tmp_error;
92 analyse_error_info_t *work_error;
93
94 /* Search Error */
95 tmp_error.id = id;
96 work_error = bsearch( &tmp_error, error_list, ANALYSE_NB_ERROR, sizeof(analyse_error_info_t), compar_error);
97
98 if (work_error != NULL)
99 {
100 work_error->tmp_cnt=value;
101 }
102}
103
104void analyse_error_get_cnt(analyse_error_info_t *error_list, int id, int *global_cnt, int *tmp_cnt)
105{
106 analyse_error_info_t tmp_error;
107 analyse_error_info_t *work_error;
108
109 /* Search Error */
110 tmp_error.id = id;
111 work_error = bsearch( &tmp_error, error_list, ANALYSE_NB_ERROR, sizeof(analyse_error_info_t), compar_error);
112
113 if (work_error != NULL)
114 {
115 if ( global_cnt != NULL)
116 {
117 *global_cnt = work_error->global_cnt;
118 }
119
120 if ( tmp_cnt != NULL)
121 {
122 *tmp_cnt = work_error->tmp_cnt;
123 }
124 }
125}
126/**************************** Cls41l04 --- ********************************/
127
128void analyse_error_return_message(analyse_error_info_t *error_list, int error_warning_type,
129 int language, int id, char **title, char **description, char **comment)
130{
131 analyse_comment_t *scan_comment;
132 analyse_error_info_t *work_error;
133 analyse_error_info_t tmp_error;
134 char line[ANALYSE_SIZE_OF_LINE];
135
136
137 /* Search Error */
138 tmp_error.id = id;
139 work_error = bsearch( &tmp_error, error_list, ANALYSE_NB_ERROR, sizeof(analyse_error_info_t), compar_error);
140
141 if (work_error == NULL)
142 {
143 sprintf(line, "Unknown Id for Error %d\nNo Message Available\n", id );
145
146 if ( title != NULL ) *title = NULL;
147 if ( description != NULL ) *description = NULL;
148 if ( comment != NULL ) *comment = NULL;
149
150 return;
151 }
152 else
153 {
154 /* Get Title */
155 if ( title != NULL )
156 {
157 if (work_error->title== NULL)
158 {
159 *title = NULL;
160 }
161 else
162 {
163 scan_comment = analyse_get_right_comment(work_error->title,language,ANALYSE_ENGLISH);
164 #ifdef _WIN64
165 *title = _strdup(scan_comment->text);
166 #else
167 *title = strdup(scan_comment->text);
168 #endif
169 }
170 }
171
172 /* Get Description */
173 if ( description != NULL )
174 {
175 if (work_error->description== NULL)
176 {
177 *description = NULL;
178 }
179 else
180 {
181 scan_comment = analyse_get_right_comment(work_error->description,language,ANALYSE_ENGLISH);
182 *description = analyse_fill_description(error_warning_type, scan_comment->text);
183 }
184 }
185
186 /* Get Comment */
187 if ( comment != NULL )
188 {
189 if (work_error->comment== NULL)
190 {
191 *comment = NULL;
192 }
193 else
194 {
195 scan_comment = analyse_get_right_comment(work_error->comment,language,ANALYSE_ENGLISH);
196 #ifdef _WIN64
197 *comment = _strdup(scan_comment->text);
198 #else
199 *comment = strdup(scan_comment->text);
200 #endif
201 }
202 }
203 }
204}
205
206/*
207 This Function is the equivalent of a part of the Main, in build_default_file.c
208*/
209void analyse_error_file_read(analyse_error_info_t **error_p, char *infilename)
210{
211/* ls41k10 */
212 FILE *infile=NULL;
213
214 char line[ANALYSE_SIZE_OF_LINE];
215 char key[ANALYSE_SIZE_OF_LINE];
216 int id;
217 int linecount = 0;
218
219 analyse_comment_t *comment;
220 analyse_error_info_t *work_error;
221 analyse_error_info_t tmp_error;
222
223 int new_count = 0;
224 int already_print = 0;
225
226 int cnt, size;
227 int *tab;
228
229
230 /*************/
231 /* Open File */
232 /*************/
233/* ls41k10+++ */
234 /* security, in case fopen crashes with error_filename = NULL */
235 if (infilename != NULL)
236 {
237 infile = fopen(infilename,"r");
238 }
239/* ls41k10 --- */
240
241 if (infile == NULL)
242 {
243 /*
244 Analyse_Print_Error_Level("*** Analyse Read Error : Unable to read Error Definition File :\n", 2);
245 Analyse_Print_Error(infilename);
246 return;
247 */
248
249 Analyse_Print_Debug(" \nNo Error File Found. Use Default\n");
250
251
252 return;
253 }
254
255
256 /***************************/
257 /* Allocate Message Memory */
258 /***************************/
259
260 /* Count message */
261 analyse_count_error(line, infile, infilename, &linecount, &cnt);
262 rewind(infile);
263 analyse_stack_error(line, infile, infilename, &linecount, &cnt, &size, &tab);
264
265 ANALYSE_NB_ERROR = cnt;
266 analyse_free(tab);
267
268 *error_p = error_create(ANALYSE_NB_ERROR);
269
270
271 /****************/
272 /* Read Message */
273 /****************/
274 rewind(infile);
275 while ( ( analyse_getline(line, infile, infilename, &linecount) != -1) &&
276 ( strncmp(line, "/END", 4) != 0 ))
277 {
278
279 /* ls41l33 if (strstr(line, "/ANALYSE/ERROR/") != NULL) */
280 if (strstr(line, "/ANALYSE/MESSAGE/") != NULL)
281 {
282 /* Search Error */
283 analyse_getkey(3 , line, key);
284 sscanf(key, "%d", &id );
285
286 tmp_error.id = id;
287 work_error = bsearch( &tmp_error, *error_p, ANALYSE_NB_ERROR, sizeof(analyse_error_info_t), compar_error);
288
289 if (work_error == NULL)
290 {
291 if (new_count >= ANALYSE_NB_ERROR)
292 {
293 if ( already_print == 0)
294 {
295 Analyse_Print_Error_Level("\n\n*** Analyse Internal Error (ANALYSE_NB_ERROR) : Too Many Messages \n\n", 2);
296 already_print = 1;
297 }
298 continue;
299 }
300
301 work_error = *error_p + new_count;
302 new_count++;
303
304 work_error->id = id;
305
306 /* Note : if file order is in id increase, this qsort does nothing ... */
308 tmp_error.id = id;
309 /* .. and this bsearch gives the same work_error */
310 work_error = bsearch( &tmp_error, *error_p, ANALYSE_NB_ERROR, sizeof(analyse_error_info_t), compar_error);
311
312 }
313
314 analyse_getkey(4 , line, key);
315 if ( (strncmp(key, "TITLE", 5) == 0) ||
316 (strncmp(key, "DESCRIPTION", 11) == 0) )
317 {
318 /* Read Comment */
319 comment = analyse_read_comment(line, infile, infilename, &linecount);
320
321 /* Add Comment */
322 if (strncmp(key, "TITLE", 5)== 0)
323 {
324 analyse_add_comment(ANALYSE_ERROR_TITLE, work_error, comment);
325 }
326 else if (strncmp(key, "DESCRIPTION", 11)== 0)
327 {
328 analyse_add_comment(ANALYSE_ERROR_DESCRIPTION, work_error, comment);
329 }
330 }
331 }
332 }
333
334 fclose(infile);
335}
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_ERROR_DESCRIPTION
#define ANALYSE_ERROR_TITLE
#define ANALYSE_SIZE_OF_LINE
#define ANALYSE_ENGLISH
void analyse_error_return_message(analyse_error_info_t *error_list, int error_warning_type, int language, int id, char **title, char **description, char **comment)
static analyse_error_info_t * error_create(int size)
void analyse_error_cnt(analyse_error_info_t *error_list, int id)
static int ANALYSE_NB_ERROR
void analyse_error_get_cnt(analyse_error_info_t *error_list, int id, int *global_cnt, int *tmp_cnt)
static int compar_error(const void *error_1_p, const void *error_2_p)
void analyse_error_file_read(analyse_error_info_t **error_p, char *infilename)
void analyse_error_set_tmp_cnt(analyse_error_info_t *error_list, int id, int value)
struct analyse_error_info_s analyse_error_info_t
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)
void Analyse_Print_Error_Level(char *text, int level)
void Analyse_Print_Debug(char *text)
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)
void analyse_stack_error(char *line, FILE *infile, char *infilename, int *linecount_p, int *cnt_p, int *size_p, int **tab_p)
recursive subroutine qsort(a, idx, first, last)
initmumps id
analyse_comment_t * description
analyse_comment_t * title
analyse_comment_t * comment