forked from psi46/psi46test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
waferlist.cpp
133 lines (102 loc) · 2.23 KB
/
waferlist.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// waferlist.cpp
#include <stdio.h>
#include <time.h>
#include "waferlist.h"
bool CWaferId::Read(FILE *f)
{
int i, p1, p2;
char s[256];
do
{
if (!fgets(s, 255, f)) return feof(f) != 0;
for (i = 0; s[i]; i++) if (s[i] < ' ') s[i] = ' ';
// find begin of first string -> p1
p1 = 0;
while (s[p1] == ' ') p1++;
} while (s[p1] == 0);
// find end of first string -> p2
p2 = p1;
while (s[p2] > ' ') p2++;
if ((p2-p1) <= 0) return false;
id.assign(s, p1, p2-p1);
// find begin of second string -> p2
while (s[p2] == ' ') p2++;
// find end of second string -> p1
p1 = p2;
while ((s[p1] != ' ') && (s[p1] != 0)) p1++;
tested = (p1-p2) > 0;
if (tested) timestamp.assign(s, p2, p1-p2);
return true;
}
void CWaferId::Write(FILE *f)
{
if (tested)
fprintf(f, "%s %s\n", id.c_str(), timestamp.c_str());
else
fprintf(f, "%s\n", id.c_str());
}
void CWaferId::SetTested()
{
time_t t_raw;
tm *t;
time(&t_raw);
t = localtime(&t_raw);
tested = true;
char s[64];
sprintf(s, "%04i%02i%02i%02i%02i",
t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min);
timestamp = s;
}
bool CWaferList::Read(const std::string &fileName)
{
FILE *f = fopen(fileName.c_str(), "rt");
if (!f) return false;
while (!feof(f))
{
CWaferId w;
if (!w.Read(f)) { wafer.clear(); fclose(f); return false; }
if (!feof(f)) wafer.push_back(w);
}
fclose(f);
modified = false;
current = wafer.end();
return true;
}
void CWaferList::Write(const std::string &fileName)
{
if (!modified) return;
FILE *f = fopen(fileName.c_str(), "wt");
if (!f) return;
std::list<CWaferId>::iterator i;
for (i = wafer.begin(); i != wafer.end(); i++) i->Write(f);
}
int CWaferList::SelectWafer(const std::string &waferId)
{
for (current = wafer.begin(); current != wafer.end(); current++)
{
if (current->IsId(waferId))
{
if (!current->IsTested()) return 0; // ok
else
{
current = wafer.end();
return 2; // already tested
}
};
}
return 1; // not existing
}
void CWaferList::SetTested()
{
if (current != wafer.end())
{
current->SetTested();
modified = true;
}
}
const std::string defaultName = "?";
const std::string& CWaferList::GetId()
{
if (current != wafer.end()) return current->GetId();
return defaultName;
}