Skip to content

Commit 67e6a4d

Browse files
committed
Cleanup, minor fixes, and documentation update for tst_output.
1 parent 48922a8 commit 67e6a4d

File tree

2 files changed

+77
-209
lines changed

2 files changed

+77
-209
lines changed

tst_output.c

Lines changed: 30 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,21 @@
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+
*/
166

177
#define _TST_OUTPUT_C_SRC
8+
#include "tst_output.h"
189

19-
/****************************************************************************/
20-
/** **/
21-
/** MODULES USED **/
22-
/** **/
23-
/****************************************************************************/
24-
#include <stdio.h>
25-
#ifdef HAVE_STRING_H
26-
# include <string.h>
27-
#endif
2810
#include <stdarg.h>
11+
#include <stdio.h>
12+
#include <string.h>
13+
2914
#include <mpi.h>
15+
3016
#include "mpi_test_suite.h"
31-
#include "tst_output.h"
3217

33-
/****************************************************************************/
34-
/** **/
35-
/** PROTOTYPES OF LOCAL FUNCTIONS **/
36-
/** **/
37-
/****************************************************************************/
3818

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-
*/
5319

5420
/* Function to replace substrings in a string
5521
*
@@ -62,7 +28,7 @@ int tst_output_parse_latex (char * src[], char * dest[]) ;
6228
* Results:
6329
* Success: number of replacements
6430
*/
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);
6632

6733

6834
/* 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,
7440
* Success: Number of replacements
7541
* Fail: -1
7642
*/
77-
static int tst_output_latex_special_chars(char * string, char * result[]);
43+
static int tst_output_latex_special_chars(char *string, char **result);
7844

7945

8046
/****************************************************************************/
@@ -104,22 +70,19 @@ extern int tst_thread_running (void);
10470
/** **/
10571
/****************************************************************************/
10672

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) {
10974
#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+
}
11478
#endif
11579
output->level = level;
11680
return level;
11781
}
11882

11983

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, ...) {
12386

12487
va_list arglist;
12588
char * fname;
@@ -137,13 +100,6 @@ tst_output_types tst_output_init (tst_output_stream * output, int rank,
137100
}
138101
#endif
139102

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
147103
/* Check if stream type uses a file and get the name of this file */
148104
if (type == TST_OUTPUT_TYPE_LOGFILE || type == TST_OUTPUT_TYPE_HTML ||
149105
type == TST_OUTPUT_TYPE_LATEX) {
@@ -207,8 +163,7 @@ tst_output_types tst_output_init (tst_output_stream * output, int rank,
207163
return output->type;
208164
}
209165

210-
int tst_output_close (tst_output_stream * output)
211-
{
166+
int tst_output_close(tst_output_stream * output) {
212167
#ifdef HAVE_MPI2_THREADS
213168
{
214169
if (tst_thread_running()) {
@@ -249,9 +204,8 @@ int tst_output_close (tst_output_stream * output)
249204
return 1;
250205
}
251206

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, ...) {
255209
int count;
256210
va_list arglist;
257211

@@ -265,8 +219,6 @@ int tst_output_printf (tst_output_stream * output,
265219
}
266220
#endif
267221

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) ;
270222
if ((output->isopen == 1) && (output->rank == tst_output_global_rank) && (error_level <= output->level)) {
271223
va_start(arglist, format);
272224
switch (output->type) {
@@ -337,8 +289,7 @@ int tst_output_printf (tst_output_stream * output,
337289
/** **/
338290
/****************************************************************************/
339291

340-
int tst_output_latex_special_chars(char * string, char * result[])
341-
{
292+
int tst_output_latex_special_chars(char *string, char **result) {
342293
int count = 0;
343294
int newlength = 0;
344295
char * strptr = NULL;
@@ -395,8 +346,7 @@ int tst_output_latex_special_chars(char * string, char * result[])
395346
return count;
396347
}
397348

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) {
400350
int count = 0, replace_count = 0;
401351
int oldlength = 0;
402352
int newlength = 0 ;
@@ -405,31 +355,20 @@ int tst_output_str_replace (char * search, char * replace, char * string, char *
405355
char * strptr = NULL;
406356
char * oldstrptr = NULL;
407357

408-
oldlength = strlen (string);
358+
oldlength = strlen(string);
409359
searchlength = strlen (search);
410360

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)) {
419363
count++;
420364
}
421-
/*
422-
* Calculate new neccessary stinglength and allocate the neccessary memory
423-
*/
365+
/* Calculate length of the resulting string and allocate the necessary memory */
424366
newlength = oldlength + count * (strlen(replace) - strlen(search));
425367
*result = (char *) malloc ( (newlength + 1) * sizeof (char) );
426368
memset (*result, 0, newlength + 1);
427369

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; ; ) {
433372
oldstrptr = strptr;
434373
strptr = strstr (strptr, search);
435374
/* all replacements done? */
@@ -446,18 +385,10 @@ int tst_output_str_replace (char * search, char * replace, char * string, char *
446385
replace_count++;
447386
}
448387

449-
/*
450-
* Safty check
451-
*/
388+
/* Safety check */
452389
if (count != replace_count) {
453390
fprintf (stderr, "Error: count (%d) != replace_count (%d)!\n", count, replace_count);
454391
exit (-1);
455392
}
456393
return count;
457394
}
458-
459-
/****************************************************************************/
460-
/** **/
461-
/** EOF **/
462-
/** **/
463-
/****************************************************************************/

0 commit comments

Comments
 (0)