2 * Copyright 2008, Haiku.
3 * Distributed under the terms of the MIT license.
6 * Michael Pfeiffer <laplace@users.sourceforge.net>
12 #include <StopWatch.h>
17 Parser
parser(gPPDFile
);
18 if (parser
.InitCheck() != B_OK
) {
19 fprintf(stderr
, "Could not open ppd file %s\n", gPPDFile
);
25 statement
= parser
.Parse();
26 if (statement
!= NULL
) {
30 } while (statement
!= NULL
);
33 #include "PPDParser.h"
35 static PPD
* OpenTestFile(bool all
, bool timing
)
37 BStopWatch
* stopWatch
= NULL
;
39 stopWatch
= new BStopWatch("PPDParser");
41 PPDParser
parser(gPPDFile
);
43 if (parser
.InitCheck() != B_OK
) {
44 fprintf(stderr
, "Could not open ppd file %s\n", gPPDFile
);
48 PPD
* ppd
= all
? parser
.ParseAll() : parser
.ParseHeader();
53 fprintf(stderr
, "Parser returned NULL\n");
54 fprintf(stderr
, "%s\n", parser
.GetErrorMessage());
61 void TestPPDParser(bool all
, bool verbose
)
63 PPD
* ppd
= OpenTestFile(all
, !verbose
);
64 if (ppd
== NULL
) return;
71 void ExtractChildren(StatementList
* list
, int level
);
73 void Indent(int level
)
75 for (; level
> 0; level
--) {
80 void PrintValue(const char* label
, Value
* arg
, int level
)
89 BString
* value
= arg
->GetValue();
90 BString
* translation
= arg
->GetTranslation();
91 if (translation
!= NULL
) {
92 printf("%s", translation
->String());
95 printf(" [%s]", value
->String());
104 bool ExtractGroup(Statement
* statement
, int level
)
106 GroupStatement
group(statement
);
107 if (group
.IsOpenGroup()) {
108 const char* translation
= group
.GetGroupTranslation();
110 if (translation
!= NULL
) {
111 printf("%s", translation
);
113 const char* name
= group
.GetGroupName();
115 printf("[%s]", name
);
118 ExtractChildren(statement
->GetChildren(), level
+1);
124 void ExtractChildren(StatementList
* list
, int level
)
126 if (list
== NULL
) return;
127 for (int32 i
= 0; i
< list
->Size(); i
++) {
128 Statement
* statement
= list
->StatementAt(i
);
129 if (!ExtractGroup(statement
, level
)) {
130 if (statement
->GetType() == Statement::kValue
) {
131 PrintValue(NULL
, statement
->GetOption(), level
);
132 } else if (statement
->GetType() == Statement::kDefault
) {
133 PrintValue("Default", statement
->GetValue(), level
);
141 PPD
* ppd
= OpenTestFile(true, false);
142 if (ppd
== NULL
) return;
144 for (int32 i
= 0; i
< ppd
->Size(); i
++) {
145 Statement
* statement
= ppd
->StatementAt(i
);
146 ExtractGroup(statement
, 0);