@@ -111,9 +111,9 @@ QSharedPointer<const AnalyzerResult> KaitaiStruct::analyzeBits(
111
111
progress->setProgressPercent (20 );
112
112
113
113
#ifdef Q_OS_WIN
114
- QStringList kscAgs = {" /C" , kscPath, " --debug" , " -t" , " python" , ksy.fileName ()};
114
+ QStringList kscAgs = {" /C" , kscPath, " --debug" , " --ksc-json-output " , " - t" , " python" , ksy.fileName ()};
115
115
#else
116
- QStringList kscAgs = {" --debug" , " -t" , " python" , ksy.fileName ()};
116
+ QStringList kscAgs = {" --debug" , " --ksc-json-output " , " - t" , " python" , ksy.fileName ()};
117
117
#endif
118
118
QProcess kscProcess;
119
119
QProcessEnvironment env = QProcessEnvironment::systemEnvironment ();
@@ -136,18 +136,63 @@ QSharedPointer<const AnalyzerResult> KaitaiStruct::analyzeBits(
136
136
if (errorFile.open (QIODevice::ReadOnly)) {
137
137
errorOutput = errorFile.readAll ();
138
138
errorFile.close ();
139
- kscOutput += QString (" stderr:\n %2" ).arg (errorOutput);
139
+ kscOutput += QString (" ksc stderr:\n %2" ).arg (errorOutput);
140
140
}
141
141
142
142
if (stdoutFile.open (QIODevice::ReadOnly)) {
143
143
stdOutput = stdoutFile.readAll ();
144
144
stdoutFile.close ();
145
- kscOutput += QString (" stdout:\n %2" ).arg (stdOutput);
145
+ kscOutput += QString (" ksc stdout:\n %2" ).arg (stdOutput);
146
146
}
147
147
148
+ // Check for unexpected stderr
148
149
if (!errorOutput.isEmpty ()) {
149
150
return AnalyzerResult::error (QString (" kaitai-struct-compiler error:\n %1" ).arg (kscOutput));
150
151
}
152
+ // Otherwise, parse the JSON
153
+ QJsonObject json = QJsonDocument::fromJson (stdOutput.toLatin1 ()).object ();
154
+ for (QString key : json.keys ()) {
155
+ if (!json.value (key).isObject ()) {
156
+ continue ;
157
+ }
158
+ QJsonObject obj = json.value (key).toObject ();
159
+ if (!obj.contains (" errors" ) || !obj.value (" errors" ).isArray ()) {
160
+ continue ;
161
+ }
162
+
163
+ QString errorString = " KSC Error:\n " ;
164
+ QJsonArray arr = obj.value (" errors" ).toArray ();
165
+ for (QJsonValue val: arr) {
166
+ if (!val.isObject ()) {
167
+ continue ;
168
+ }
169
+ QJsonObject valObj = val.toObject ();
170
+
171
+ QString errFile = valObj.value (" file" ).toString ();
172
+ QString errLoc = " " ;
173
+ QString errMsg = valObj.value (" message" ).toString ();
174
+
175
+ if (valObj.contains (" path" ) && valObj.value (" path" ).isArray ()) {
176
+ QJsonArray errPathArr = valObj.value (" path" ).toArray ();
177
+ QStringList errPathStrings;
178
+ for (QJsonValue pathVal: errPathArr) {
179
+ errPathStrings.append (pathVal.toString ());
180
+ }
181
+ errLoc += " " + errPathStrings.join (" /" );
182
+ }
183
+
184
+ if (valObj.contains (" line" )) {
185
+ errLoc += QString (" line:%1" ).arg (valObj.value (" line" ).toInt ());
186
+ }
187
+
188
+ if (valObj.contains (" col" )) {
189
+ errLoc += QString (" col:%1" ).arg (valObj.value (" col" ).toInt ());
190
+ }
191
+
192
+ errorString += QString (" %1%2 - %3\n " ).arg (errFile).arg (errLoc).arg (errMsg);
193
+ }
194
+ return AnalyzerResult::error (errorString);
195
+ }
151
196
152
197
}
153
198
else if (parameters.contains (PARAM_PY)
0 commit comments