-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprotocol.cpp
112 lines (92 loc) · 1.82 KB
/
protocol.cpp
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* -------------------------------------------------------------
*
* file: protocol.cpp
*
* description: log file for PSI46V1 Wafer tester
*
* author: Beat Meier
* modified: 24.1.2004
*
* rev:
*
* -------------------------------------------------------------
*/
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include "protocol.h"
#include "psi46test.h"
bool CProtocol::open(const char filename[])
{
f = fopen(filename, "wt");
if (f != NULL)
{
timestamp("OPEN");
section("VERSION", false);
fputs(VERSIONINFO "\n", f);
return true;
}
return false;
}
bool CProtocol::append(const char filename[])
{
f = fopen(filename, "at");
if (f != NULL)
{
timestamp("OPEN");
section("VERSION", false);
fputs(VERSIONINFO "\n", f);
return true;
}
return false;
}
void CProtocol::close()
{
if (f == NULL) return;
timestamp("CLOSE");
fclose(f);
f = NULL;
}
void CProtocol::timestamp(const char s[])
{
if (f == NULL) return;
time_t t;
struct tm *dt;
time(&t);
dt = localtime(&t);
fprintf(f, "[%s] %s", s, asctime(dt));
}
void CProtocol::section(const char s[], bool crlf)
{
if (f == NULL) return;
if (crlf) fprintf(f, "[%s]\n", s);
else fprintf(f, "[%s] ", s);
}
void CProtocol::section(const char s[], const char par[])
{
if (f == NULL) return;
fprintf(f, "[%s] %s\n", s, par);
}
void CProtocol::puts(const char s[])
{
if (f == NULL) return;
fputs(s, f);
}
void CProtocol::puts(const std::string s)
{
if (f == NULL) return;
fputs(s.c_str(), f);
}
void CProtocol::printf(const char *fmt, ...)
{
va_list ap;
if (f == NULL) return;
va_start(ap,fmt);
vfprintf(f, fmt, ap);
va_end(ap);
}
void CProtocol::flush()
{
if (f == NULL) return;
fflush(f);
}