merrg.c
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* merrg.c - merge errors from output log into output tab file
*
*
*/
#include <stdio.h>
main(int argc, char **argv)
{
FILE *Outfile, *Tabfile;
int i, err_no, vec_no = 0, done = 0;
char tab_line[2048], err_line[1024], time_str[50], comment;
if(argc != 3)
{
printf("Usage: %s <tab_file> <out_file>\n", argv[0]);
exit(0);
}
if((Outfile = fopen(argv[2], "r")) == NULL)
{
fprintf(stderr,"Unable to open outfile %s\n", argv[2]);
exit(911);
}
if((Tabfile = fopen(argv[1], "r")) == NULL)
{
fprintf(stderr,"Unable to open tabfile %s\n", argv[1]);
exit(911);
}
/* echo header */
while(fgets(tab_line, 2048, Tabfile))
{
printf("%s", tab_line);
if(tab_line[0] == '\n')
break;
}
/* read first error, skip first two lines */
for(i = 0; i < 3; i++)
{
if(!fgets(err_line, 2048, Outfile))
++done;
}
time_str[0] = '\0';
sscanf(err_line, "%s %*s %*s %d\n", time_str, &err_no);
if(strcmp(time_str, "Time")) /* out of errors */
++done;
/* read vectors */
while(fgets(tab_line, 2048, Tabfile))
{
printf("%04d: %s", vec_no+1, tab_line);
sscanf(tab_line,"%c", &comment);
if(comment != '#')
++vec_no;
/* really a vector, and we still have errors */
if(!done && comment != '#')
{
if(vec_no == err_no)
{
printf("****** %s", err_line);
/* echo all errors for this vector */
while(fgets(err_line, 2048, Outfile))
{
time_str[0] = '\0';
sscanf(err_line, "%s %*s %*s %d\n", time_str, &err_no);
if(strcmp(time_str, "Time")) /* out of errors */
{
++done;
break;
}
if(err_no == vec_no)
printf("****** %s", err_line);
else
break;
}
if(feof(Outfile))
++done;
}
}
}
fclose(Outfile);
fclose(Tabfile);
return(0);
}