1
- /*
2
- ******************************* C SOURCE FILE *******************************
3
- ** **
4
- ** project : MPI Testsuite **
5
- ** filename : TST_OUTPUT.C **
6
- ** version : 1 **
7
- ** date : June 11, 2006 **
8
- ** Revised by: Christoph Niethammer **
9
- ** **
10
- *****************************************************************************
11
- Todo:
12
- - Multiple outputs at the same time
13
- - Rankspecific output
14
- - Macros for different output types
15
- */
1
+ /**
2
+ * \todo Multiple outputs at the same time
3
+ * \todo Rank specific output
4
+ * \todo Macros for different output types
5
+ */
16
6
17
7
#define _TST_OUTPUT_C_SRC
8
+ #include "tst_output.h"
18
9
19
- /****************************************************************************/
20
- /** **/
21
- /** MODULES USED **/
22
- /** **/
23
- /****************************************************************************/
24
- #include <stdio.h>
25
- #ifdef HAVE_STRING_H
26
- # include <string.h>
27
- #endif
28
10
#include <stdarg.h>
11
+ #include <stdio.h>
12
+ #include <string.h>
13
+
29
14
#include <mpi.h>
15
+
30
16
#include "mpi_test_suite.h"
31
- #include "tst_output.h"
32
17
33
- /****************************************************************************/
34
- /** **/
35
- /** PROTOTYPES OF LOCAL FUNCTIONS **/
36
- /** **/
37
- /****************************************************************************/
38
18
39
- /* Functions to parse output for LaTeX/HTML files
40
- *
41
- * Parameters:
42
- * char * src[] source
43
- * char * dest[] destination
44
- *
45
- * Results:
46
- * Sucess: Value unequal 0
47
- * Fail: 0
48
- */
49
- /*
50
- int tst_output_parse_html (char * src[], char * dest[]);
51
- int tst_output_parse_latex (char * src[], char * dest[]) ;
52
- */
53
19
54
20
/* Function to replace substrings in a string
55
21
*
@@ -62,7 +28,7 @@ int tst_output_parse_latex (char * src[], char * dest[]) ;
62
28
* Results:
63
29
* Success: number of replacements
64
30
*/
65
- static int tst_output_str_replace (char * search , char * replace , char * string , char * result [] );
31
+ static int tst_output_str_replace (char * search , char * replace , char * string , char * * result );
66
32
67
33
68
34
/* Function to mask special chars for latex in a string
@@ -74,7 +40,7 @@ static int tst_output_str_replace (char * search, char * replace, char * string,
74
40
* Success: Number of replacements
75
41
* Fail: -1
76
42
*/
77
- static int tst_output_latex_special_chars (char * string , char * result [] );
43
+ static int tst_output_latex_special_chars (char * string , char * * result );
78
44
79
45
80
46
/****************************************************************************/
@@ -104,22 +70,19 @@ extern int tst_thread_running (void);
104
70
/** **/
105
71
/****************************************************************************/
106
72
107
- int tst_output_set_level (tst_output_stream * output , tst_report_types level )
108
- {
73
+ int tst_output_set_level (tst_output_stream * output , tst_report_types level ) {
109
74
#ifdef HAVE_MPI2_THREADS
110
- if (tst_thread_running () && tst_thread_get_num () != 0 )
111
- {
112
- return 0 ;
113
- }
75
+ if (tst_thread_running () && tst_thread_get_num () != 0 ) {
76
+ return 0 ;
77
+ }
114
78
#endif
115
79
output -> level = level ;
116
80
return level ;
117
81
}
118
82
119
83
120
- tst_output_types tst_output_init (tst_output_stream * output , int rank ,
121
- tst_report_types level , tst_output_types type , ...)
122
- {
84
+ tst_output_types tst_output_init (tst_output_stream * output , int rank ,
85
+ tst_report_types level , tst_output_types type , ...) {
123
86
124
87
va_list arglist ;
125
88
char * fname ;
@@ -137,13 +100,6 @@ tst_output_types tst_output_init (tst_output_stream * output, int rank,
137
100
}
138
101
#endif
139
102
140
- /* Checking if stream is already opened */
141
- #if 0
142
- if (output -> isopen ) {
143
- fprintf (stderr , "Error opening stream: Stream allready opened." );
144
- return output -> type ;
145
- }
146
- #endif
147
103
/* Check if stream type uses a file and get the name of this file */
148
104
if (type == TST_OUTPUT_TYPE_LOGFILE || type == TST_OUTPUT_TYPE_HTML ||
149
105
type == TST_OUTPUT_TYPE_LATEX ) {
@@ -207,8 +163,7 @@ tst_output_types tst_output_init (tst_output_stream * output, int rank,
207
163
return output -> type ;
208
164
}
209
165
210
- int tst_output_close (tst_output_stream * output )
211
- {
166
+ int tst_output_close (tst_output_stream * output ) {
212
167
#ifdef HAVE_MPI2_THREADS
213
168
{
214
169
if (tst_thread_running ()) {
@@ -249,9 +204,8 @@ int tst_output_close (tst_output_stream * output)
249
204
return 1 ;
250
205
}
251
206
252
- int tst_output_printf (tst_output_stream * output ,
253
- tst_report_types error_level , char * format , ...)
254
- {
207
+ int tst_output_printf (tst_output_stream * output ,
208
+ tst_report_types error_level , char * format , ...) {
255
209
int count ;
256
210
va_list arglist ;
257
211
@@ -265,8 +219,6 @@ int tst_output_printf (tst_output_stream * output,
265
219
}
266
220
#endif
267
221
268
- // XXX CN should be removed
269
- //printf ("Open: %d\nOutput Rank: %d\nglobal rank: %d\nerror Level: %d\nLog Level: %d\n" , output->isopen, output->rank , tst_output_global_rank , error_level ,output->level) ;
270
222
if ((output -> isopen == 1 ) && (output -> rank == tst_output_global_rank ) && (error_level <= output -> level )) {
271
223
va_start (arglist , format );
272
224
switch (output -> type ) {
@@ -337,8 +289,7 @@ int tst_output_printf (tst_output_stream * output,
337
289
/** **/
338
290
/****************************************************************************/
339
291
340
- int tst_output_latex_special_chars (char * string , char * result [])
341
- {
292
+ int tst_output_latex_special_chars (char * string , char * * result ) {
342
293
int count = 0 ;
343
294
int newlength = 0 ;
344
295
char * strptr = NULL ;
@@ -395,8 +346,7 @@ int tst_output_latex_special_chars(char * string, char * result[])
395
346
return count ;
396
347
}
397
348
398
- int tst_output_str_replace (char * search , char * replace , char * string , char * result [])
399
- {
349
+ int tst_output_str_replace (char * search , char * replace , char * string , char * * result ) {
400
350
int count = 0 , replace_count = 0 ;
401
351
int oldlength = 0 ;
402
352
int newlength = 0 ;
@@ -405,31 +355,20 @@ int tst_output_str_replace (char * search, char * replace, char * string, char *
405
355
char * strptr = NULL ;
406
356
char * oldstrptr = NULL ;
407
357
408
- oldlength = strlen (string );
358
+ oldlength = strlen (string );
409
359
searchlength = strlen (search );
410
360
411
- /*
412
- * Calculate number of neccessary replacements
413
- */
414
- for (strptr = string ; strptr ; strptr ++ )
415
- {
416
- strptr = strstr (strptr , search );
417
- if (strptr == NULL )
418
- break ;
361
+ /* Calculate number of replacements to be preformed */
362
+ for (strptr = strstr (string , search ); strptr != NULL ; strptr = strstr (++ strptr , search )) {
419
363
count ++ ;
420
364
}
421
- /*
422
- * Calculate new neccessary stinglength and allocate the neccessary memory
423
- */
365
+ /* Calculate length of the resulting string and allocate the necessary memory */
424
366
newlength = oldlength + count * (strlen (replace ) - strlen (search ));
425
367
* result = (char * ) malloc ( (newlength + 1 ) * sizeof (char ) );
426
368
memset (* result , 0 , newlength + 1 );
427
369
428
- /*
429
- * Generate the new String
430
- */
431
- for (strptr = string ; ; )
432
- {
370
+ /* Perform replacements and store result to new string */
371
+ for (strptr = string ; ; ) {
433
372
oldstrptr = strptr ;
434
373
strptr = strstr (strptr , search );
435
374
/* all replacements done? */
@@ -446,18 +385,10 @@ int tst_output_str_replace (char * search, char * replace, char * string, char *
446
385
replace_count ++ ;
447
386
}
448
387
449
- /*
450
- * Safty check
451
- */
388
+ /* Safety check */
452
389
if (count != replace_count ) {
453
390
fprintf (stderr , "Error: count (%d) != replace_count (%d)!\n" , count , replace_count );
454
391
exit (-1 );
455
392
}
456
393
return count ;
457
394
}
458
-
459
- /****************************************************************************/
460
- /** **/
461
- /** EOF **/
462
- /** **/
463
- /****************************************************************************/
0 commit comments