-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathparse.cpp
More file actions
320 lines (288 loc) · 7.58 KB
/
parse.cpp
File metadata and controls
320 lines (288 loc) · 7.58 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/* 19980321 Mvh Added define TRUNCATEFIELDNAMES for DBF compatibity (apply in makefile) */
/* 19980325 Mvh Added TruncateFieldNames entry in dicom.ini to allow DBF compatibility */
/* 19980327 Mvh Added MaxFieldLength entry in dicom.ini to allow DBF compatibility */
/* 20001105 mvh Renamed some enums and variables to allow compile in one big chunk */
/* 20010713 mvh Renamed DT_UINTxx to DT_INTxx as temp fix for bug in LEX.CPP */
/* 20010829 mvh Undone above change as LEX.CPP has been fixed by ljz */
/* 20050107 mvh Added include file gpps for GetPrivateProfileString */
/* 20050401 mvh Added WorkList Support */
/* mvh 20050404: Added DT_START/ENDSEQUENCE to code sequence in WorkList table */
/* mvh 20050902: Added HL7 column to be used for WorkList table */
/* mvh 20050908: Fixed pointer error that crashed linux version */
/* mvh 20080818: Added DT_MSTR */
/* mvh 20100122: Hex2Dec incorrect for uppercase HEX numbers! */
/* mvh 20100123: Added FL and FD types */
/* mvh 20100125: GetPrivateProfileString -> MyGetPrivateProfileString */
/* bcb 20100309: Changed int to unsigned. (gcc4.2 Warnings) */
/* mvh 20100703: Merged */
/* bcb 20120703: Removed WHEDGE */
/* bcb 20120710: Created parse.hpp; use ROOTCONFIG_SZ */
/* bcb 20130226: Replaced gpps with IniValue class. Removed all globals and routines now in IniValue class.
Version to 1.4.18a.*/
#include "parse.hpp"
#include "dgate.hpp"
#include "device.hpp"
#include "configpacs.hpp"
//#include "gpps.hpp"
#ifdef UNIX
#define mkdir(a) mkdir(a, 0777)
#endif
enum
{
TK_SCOMMENT_ = 1,
TK_ECOMMENT_,
TK_PATIENT,
TK_STUDY,
TK_SERIES,
TK_IMAGE,
TK_WORKLIST,
TK_BOPEN,
TK_BCLOSE,
TK_COMMA,
TK_QT,
TK_SQL_C_CHAR,
TK_SQL_C_DATE,
TK_DT_STR,
TK_DT_MSTR,
TK_DT_DATE,
TK_DT_UINT16,
TK_DT_UINT32,
TK_DT_TIME,
TK_DT_UI,
TK_DT_FL,
TK_DT_FD,
TK_DT_STARTSEQUENCE,
TK_DT_ENDSEQUENCE
};
TOKENSTRUCT G [] =
{
{ TK_SCOMMENT_, "/*"},
{ TK_ECOMMENT_, "*/" },
{ TK_PATIENT, "*Patient*" },
{ TK_STUDY, "*Study*" },
{ TK_SERIES, "*Series*" },
{ TK_IMAGE, "*Image*" },
{ TK_WORKLIST, "*WorkList*" },
{ TK_BOPEN, "{" },
{ TK_BCLOSE, "}" },
{ TK_COMMA, "," },
{ TK_QT, "\"" },
{ TK_SQL_C_CHAR, "SQL_C_CHAR" },
{ TK_SQL_C_DATE, "SQL_C_DATE" },
{ TK_DT_STR, "DT_STR" },
{ TK_DT_MSTR, "DT_MSTR" },
{ TK_DT_DATE, "DT_DATE" },
{ TK_DT_UINT16, "DT_UINT16" },
{ TK_DT_UINT32, "DT_UINT32" },
{ TK_DT_TIME, "DT_TIME" },
{ TK_DT_UI, "DT_UI" },
{ TK_DT_FL, "DT_FL" },
{ TK_DT_FD, "DT_FD" },
{ TK_DT_STARTSEQUENCE, "DT_STARTSEQUENCE" },
{ TK_DT_ENDSEQUENCE, "DT_ENDSEQUENCE" },
{ 0, "\0" }
};
BOOL
LoadKFactorFile(char *KFile)
{
Lex Lexxer;
Array < DBENTRY > ADBPatient, ADBStudy, ADBSeries, ADBImage, ADBWorkList;
// GetDBSpecials();
if ( !Lexxer.Start(KFile, G) )
return ( FALSE );
if(!Parse ( Lexxer, &ADBPatient, &ADBStudy, &ADBSeries, &ADBImage, &ADBWorkList ))
return ( FALSE );
ConvertDB(&PatientDB, &ADBPatient);
ConvertDB(&StudyDB, &ADBStudy);
ConvertDB(&SeriesDB, &ADBSeries);
ConvertDB(&ImageDB, &ADBImage);
ConvertDB(&WorkListDB, &ADBWorkList);
return ( TRUE );
}
static
BOOL
ConvertDB( DBENTRY **ppDBE, Array < DBENTRY > *ADB)
{
UINT Index;
DBENTRY DBE;
if(*ppDBE)
free(*ppDBE);
(*ppDBE) = (DBENTRY *)malloc(sizeof(DBENTRY) * (ADB->GetSize() + 2));
Index = 0;
while(Index < ADB->GetSize() )
{
(*ppDBE) [Index] = ADB->Get(Index);
++Index;
}
DBE.Group = 0;
DBE.Element = 0;
memcpy((void *) (&(*ppDBE)[Index]), (void*) &DBE, sizeof(DBENTRY));
return ( TRUE );
}
static
BOOL Parse (
Lex &Lexxer,
Array < DBENTRY > *ADBPatient,
Array < DBENTRY > *ADBStudy,
Array < DBENTRY > *ADBSeries,
Array < DBENTRY > *ADBImage,
Array < DBENTRY > *ADBWorkList
)
{
TK Tk;
Lexxer.Get(&Tk);
while ( TRUE )
{
switch ( Lexxer.Peek(&Tk) )
{
case TK_SCOMMENT_:
ParseComment (Lexxer);
break;
case TK_PATIENT:
ParseDB(Lexxer, ADBPatient, FALSE);
break;
case TK_STUDY:
ParseDB(Lexxer, ADBStudy, FALSE);
break;
case TK_SERIES:
ParseDB(Lexxer, ADBSeries, FALSE);
break;
case TK_IMAGE:
ParseDB(Lexxer, ADBImage, FALSE);
break;
case TK_WORKLIST:
ParseDB(Lexxer, ADBWorkList, TRUE);
break;
case TOKEN_END:
return ( TRUE );
default:
fprintf ( stderr, "Parse error : Parse : %s\n",
Tk.Str);
return ( FALSE );
}
Lexxer.Get(&Tk);
}
return ( FALSE );
}
BOOL
ParseComment ( Lex &Lexxer )
{
TK Tk;
while ( Lexxer.Get(&Tk) != TK_ECOMMENT_ )
{
if(Tk.Value == TOKEN_END)
return ( FALSE );
}
return ( TRUE );
}
static
BOOL
ParseDB(Lex &Lexxer, Array < DBENTRY > *DBName, BOOL HasHL7)
{
TK Tk, TKGroup, TKElement, TKColumn, TKLength, TKSQLType, TKDICOMType, TKHL7Tag;
DBENTRY DBE;
Lexxer.Get(&Tk);
if(Tk.Value!=TK_BOPEN)
{
fprintf(stderr, "Expected: Database { : %s\n", Tk.Str);
exit(1);
return ( FALSE );
}
IniValue *iniValuePtr = IniValue::GetInstance();
Lexxer.Get(&Tk);
while ( Tk.Value == TK_BOPEN )
{
Lexxer.Get(&TKGroup);
Lexxer.Get(&Tk);
Lexxer.Get(&TKElement);
Lexxer.Get(&Tk);
Lexxer.Get(&Tk);
Lexxer.Get(&TKColumn);
Lexxer.Get(&Tk);
Lexxer.Get(&Tk);
Lexxer.Get(&TKLength);
Lexxer.Get(&Tk);
Lexxer.Get(&TKSQLType);
Lexxer.Get(&Tk);
Lexxer.Get(&TKDICOMType);
Lexxer.Get(&Tk);
if(HasHL7 && Tk.Value==TK_COMMA)
{
Lexxer.Get(&Tk);
Lexxer.Get(&TKHL7Tag);
Lexxer.Get(&Tk);
Lexxer.Get(&Tk);
}
if(Tk.Value!=TK_BCLOSE)
{
fprintf(stderr, "Expected { Group, Element, Column, Length, SQLType, DICOMType }\n");
fprintf(stderr, "Got { %s, %s, %s, %s, %s, %s }\n",
TKGroup.Str, TKElement.Str, TKColumn.Str,
TKLength.Str, TKSQLType.Str, TKDICOMType.Str);
exit(1);
return ( FALSE );
}
Lexxer.Get(&Tk);
if(Tk.Value == TK_COMMA)
Lexxer.Get(&Tk);
DBE.Group = ConvertNumber(TKGroup.Str);
DBE.Element = ConvertNumber(TKElement.Str);
strcpy(DBE.SQLColumn, TKColumn.Str);
if (HasHL7) strcpy(DBE.HL7Tag, TKHL7Tag.Str); else DBE.HL7Tag[0]=0;
if (iniValuePtr->sscscpPtr->TruncateFieldNames)
DBE.SQLColumn[iniValuePtr->sscscpPtr->TruncateFieldNames] = 0;
DBE.SQLLength = ConvertNumber(TKLength.Str);
if (iniValuePtr->sscscpPtr->MaxFieldLength)
if (DBE.SQLLength >= iniValuePtr->sscscpPtr->MaxFieldLength)
DBE.SQLLength = iniValuePtr->sscscpPtr->MaxFieldLength;
if(TKSQLType.Value == TK_SQL_C_CHAR)
DBE.SQLType = SQL_C_CHAR;
else
if(TKSQLType.Value == TK_SQL_C_DATE)
DBE.SQLType = SQL_C_DATE;
else
{
fprintf(stderr, "Unknown SQL Type: %s\n", TKSQLType.Str);
exit(1);
}
if(TKDICOMType.Value == TK_DT_STR)
DBE.DICOMType = DT_STR;
else
if(TKDICOMType.Value == TK_DT_MSTR)
DBE.DICOMType = DT_MSTR;
else
if(TKDICOMType.Value == TK_DT_UI)
DBE.DICOMType = DT_UI;
else
if(TKDICOMType.Value == TK_DT_DATE)
DBE.DICOMType = DT_DATE;
else
if(TKDICOMType.Value == TK_DT_UINT16)
DBE.DICOMType = DT_UINT16;
else
if(TKDICOMType.Value == TK_DT_UINT32)
DBE.DICOMType = DT_UINT32;
else
if(TKDICOMType.Value == TK_DT_TIME)
DBE.DICOMType = DT_DATE; // yes, intentional
else
if(TKDICOMType.Value == TK_DT_FL)
DBE.DICOMType = DT_FL;
else
if(TKDICOMType.Value == TK_DT_FD)
DBE.DICOMType = DT_FD;
else
if(TKDICOMType.Value == TK_DT_STARTSEQUENCE)
DBE.DICOMType = DT_STARTSEQUENCE;
else
if(TKDICOMType.Value == TK_DT_ENDSEQUENCE)
DBE.DICOMType = DT_ENDSEQUENCE;
else
{
fprintf(stderr, "Unknown DICOM Type: %s\n", TKDICOMType.Str);
exit(1);
}
DBName->Add(DBE);
}
return ( TRUE );
}