VirtualBox

source: vbox/trunk/src/VBox/Runtime/win/errmsgwin-sorter.cpp@ 100108

Last change on this file since 100108 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 14.4 KB
Line 
1/* $Id: errmsgwin-sorter.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT - Status code messages, Windows, sorter build program.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/win/windows.h>
42
43#include <iprt/errcore.h>
44#include <iprt/asm.h>
45#include <iprt/string.h>
46
47#include <stdio.h>
48#include <stdlib.h>
49
50
51/*
52 * Include the string table code.
53 */
54#define BLDPROG_STRTAB_MAX_STRLEN 1024
55#define BLDPROG_STRTAB_WITH_COMPRESSION
56#define BLDPROG_STRTAB_PURE_ASCII
57#define BLDPROG_STRTAB_WITH_CAMEL_WORDS
58#include <iprt/bldprog-strtab-template.cpp.h>
59
60
61/*********************************************************************************************************************************
62* Defined Constants And Macros *
63*********************************************************************************************************************************/
64/* This is define casts the result to DWORD, whereas HRESULT and RTWINERRMSG
65 are using long, causing newer compilers to complain. */
66#undef _NDIS_ERROR_TYPEDEF_
67#define _NDIS_ERROR_TYPEDEF_(lErr) (long)(lErr)
68
69
70/*********************************************************************************************************************************
71* Structures and Typedefs *
72*********************************************************************************************************************************/
73typedef long VBOXSTATUSTYPE; /* used by errmsgvboxcomdata.h */
74
75/** Used for raw-input and sorting. */
76typedef struct RTWINERRMSGINT1
77{
78 /** Pointer to the full message string. */
79 const char *pszMsgFull;
80 /** Pointer to the define string. */
81 const char *pszDefine;
82 /** Status code number. */
83 long iCode;
84 /** Set if duplicate. */
85 bool fDuplicate;
86} RTWINERRMSGINT1;
87typedef RTWINERRMSGINT1 *PRTWINERRMSGINT1;
88
89
90/** This is used when building the string table and printing it. */
91typedef struct RTWINERRMSGINT2
92{
93 /** The full message string. */
94 BLDPROGSTRING MsgFull;
95 /** The define string. */
96 BLDPROGSTRING Define;
97 /** Pointer to the define string. */
98 const char *pszDefine;
99 /** Status code number. */
100 long iCode;
101} RTWINERRMSGINT2;
102typedef RTWINERRMSGINT2 *PRTWINERRMSGINT2;
103
104
105/*********************************************************************************************************************************
106* Global Variables *
107*********************************************************************************************************************************/
108static const char *g_pszProgName = "errmsgwin-sorter";
109static RTWINERRMSGINT1 g_aStatusMsgs[] =
110{
111#if !defined(IPRT_NO_ERROR_DATA) && !defined(DOXYGEN_RUNNING)
112# include "errmsgwindata.h"
113# if defined(VBOX) && !defined(IN_GUEST)
114# include "errmsgvboxcomdata.h"
115# endif
116
117/* A few hardcoded items not in winerror.h */
118# define HARDCODED_ENTRY(a_Name, aValue) { #a_Name, #a_Name, aValue, false }
119 HARDCODED_ENTRY(AUDCLNT_E_NOT_INITIALIZED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x01)),
120 HARDCODED_ENTRY(AUDCLNT_E_ALREADY_INITIALIZED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x02)),
121 HARDCODED_ENTRY(AUDCLNT_E_WRONG_ENDPOINT_TYPE , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x03)),
122 HARDCODED_ENTRY(AUDCLNT_E_DEVICE_INVALIDATED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x04)),
123 HARDCODED_ENTRY(AUDCLNT_E_NOT_STOPPED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x05)),
124 HARDCODED_ENTRY(AUDCLNT_E_BUFFER_TOO_LARGE , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x06)),
125 HARDCODED_ENTRY(AUDCLNT_E_OUT_OF_ORDER , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x07)),
126 HARDCODED_ENTRY(AUDCLNT_E_UNSUPPORTED_FORMAT , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x08)),
127 HARDCODED_ENTRY(AUDCLNT_E_INVALID_SIZE , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x09)),
128 HARDCODED_ENTRY(AUDCLNT_E_DEVICE_IN_USE , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x0a)),
129 HARDCODED_ENTRY(AUDCLNT_E_BUFFER_OPERATION_PENDING , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x0b)),
130 HARDCODED_ENTRY(AUDCLNT_E_THREAD_NOT_REGISTERED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x0c)),
131 HARDCODED_ENTRY(AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x0e)),
132 HARDCODED_ENTRY(AUDCLNT_E_ENDPOINT_CREATE_FAILED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x0f)),
133 HARDCODED_ENTRY(AUDCLNT_E_SERVICE_NOT_RUNNING , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x10)),
134 HARDCODED_ENTRY(AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x11)),
135 HARDCODED_ENTRY(AUDCLNT_E_EXCLUSIVE_MODE_ONLY , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x12)),
136 HARDCODED_ENTRY(AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x13)),
137 HARDCODED_ENTRY(AUDCLNT_E_EVENTHANDLE_NOT_SET , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x14)),
138 HARDCODED_ENTRY(AUDCLNT_E_INCORRECT_BUFFER_SIZE , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x15)),
139 HARDCODED_ENTRY(AUDCLNT_E_BUFFER_SIZE_ERROR , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x16)),
140 HARDCODED_ENTRY(AUDCLNT_E_CPUUSAGE_EXCEEDED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x17)),
141 HARDCODED_ENTRY(AUDCLNT_E_BUFFER_ERROR , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x18)),
142 HARDCODED_ENTRY(AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x19)),
143 HARDCODED_ENTRY(AUDCLNT_E_INVALID_DEVICE_PERIOD , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x20)),
144 HARDCODED_ENTRY(AUDCLNT_E_INVALID_STREAM_FLAG , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x21)),
145 HARDCODED_ENTRY(AUDCLNT_E_ENDPOINT_OFFLOAD_NOT_CAPABLE , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x22)),
146 HARDCODED_ENTRY(AUDCLNT_E_OUT_OF_OFFLOAD_RESOURCES , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x23)),
147 HARDCODED_ENTRY(AUDCLNT_E_OFFLOAD_MODE_ONLY , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x24)),
148 HARDCODED_ENTRY(AUDCLNT_E_NONOFFLOAD_MODE_ONLY , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x25)),
149 HARDCODED_ENTRY(AUDCLNT_E_RESOURCES_INVALIDATED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x26)),
150 HARDCODED_ENTRY(AUDCLNT_E_RAW_MODE_UNSUPPORTED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x27)),
151 HARDCODED_ENTRY(AUDCLNT_E_ENGINE_PERIODICITY_LOCKED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x28)),
152 HARDCODED_ENTRY(AUDCLNT_E_ENGINE_FORMAT_LOCKED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x29)),
153 HARDCODED_ENTRY(AUDCLNT_E_HEADTRACKING_ENABLED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x30)),
154 HARDCODED_ENTRY(AUDCLNT_E_HEADTRACKING_UNSUPPORTED , MAKE_HRESULT(SEVERITY_ERROR, 2185, 0x40)),
155 HARDCODED_ENTRY(AUDCLNT_S_BUFFER_EMPTY , MAKE_SCODE(SEVERITY_SUCCESS, 2185, 1)),
156 HARDCODED_ENTRY(AUDCLNT_S_THREAD_ALREADY_REGISTERED , MAKE_SCODE(SEVERITY_SUCCESS, 2185, 2)),
157 HARDCODED_ENTRY(AUDCLNT_S_POSITION_STALLED , MAKE_SCODE(SEVERITY_SUCCESS, 2185, 3)),
158# undef HARDCODED_ENTRY
159#endif
160 { "Success.", "ERROR_SUCCESS", 0, false },
161};
162
163
164static RTEXITCODE error(const char *pszFormat, ...)
165{
166 va_list va;
167 va_start(va, pszFormat);
168 fprintf(stderr, "%s: error: ", g_pszProgName);
169 vfprintf(stderr, pszFormat, va);
170 va_end(va);
171 return RTEXITCODE_FAILURE;
172}
173
174
175/** qsort callback. */
176static int CompareWinErrMsg(const void *pv1, const void *pv2) RT_NOTHROW_DEF
177{
178 PCRTWINERRMSG p1 = (PCRTWINERRMSG)pv1;
179 PCRTWINERRMSG p2 = (PCRTWINERRMSG)pv2;
180 int iDiff;
181 if (p1->iCode < p2->iCode)
182 iDiff = -1;
183 else if (p1->iCode > p2->iCode)
184 iDiff = 1;
185 else
186 iDiff = 0;
187 return iDiff;
188}
189
190
191int main(int argc, char **argv)
192{
193 /*
194 * Parse arguments.
195 */
196 enum { kMode_All, kMode_OnlyDefines } enmMode;
197 if (argc == 3 && strcmp(argv[1], "--all") == 0)
198 enmMode = kMode_All;
199 else if (argc == 3 && strcmp(argv[1], "--only-defines") == 0)
200 enmMode = kMode_OnlyDefines;
201 else
202 {
203 fprintf(stderr,
204 "syntax error!\n"
205 "Usage: %s <--all|--only-defines> <outfile>\n", argv[0]);
206 return RTEXITCODE_SYNTAX;
207 }
208 const char * const pszOutFile = argv[2];
209
210 /*
211 * Sort the table and mark duplicates.
212 */
213 qsort(g_aStatusMsgs, RT_ELEMENTS(g_aStatusMsgs), sizeof(g_aStatusMsgs[0]), CompareWinErrMsg);
214
215 int rcExit = RTEXITCODE_SUCCESS;
216 long iPrev = (long)0x80000000;
217 bool fHaveSuccess = false;
218 for (size_t i = 0; i < RT_ELEMENTS(g_aStatusMsgs); i++)
219 {
220 PRTWINERRMSGINT1 pMsg = &g_aStatusMsgs[i];
221 if (pMsg->iCode == iPrev && i != 0)
222 {
223 pMsg->fDuplicate = true;
224
225 if (iPrev == 0)
226 continue;
227
228 PRTWINERRMSGINT1 pPrev = &g_aStatusMsgs[i - 1];
229 if (strcmp(pMsg->pszDefine, pPrev->pszDefine) == 0)
230 continue;
231 rcExit = error("Duplicate value %#lx (%ld) - %s and %s\n",
232 (unsigned long)iPrev, iPrev, pMsg->pszDefine, pPrev->pszDefine);
233 }
234 else
235 {
236 pMsg->fDuplicate = false;
237 iPrev = pMsg->iCode;
238 if (iPrev == 0)
239 fHaveSuccess = true;
240 }
241 }
242 if (!fHaveSuccess)
243 rcExit = error("No zero / success value in the table!\n");
244
245 /*
246 * Create a string table for it all.
247 */
248 BLDPROGSTRTAB StrTab;
249 if (!BldProgStrTab_Init(&StrTab, RT_ELEMENTS(g_aStatusMsgs) * 3))
250 return error("Out of memory!\n");
251
252 static RTWINERRMSGINT2 s_aStatusMsgs2[RT_ELEMENTS(g_aStatusMsgs)];
253 size_t cStatusMsgs = 0;
254 for (size_t i = 0; i < RT_ELEMENTS(g_aStatusMsgs); i++)
255 {
256 if (!g_aStatusMsgs[i].fDuplicate)
257 {
258 s_aStatusMsgs2[cStatusMsgs].iCode = g_aStatusMsgs[i].iCode;
259 s_aStatusMsgs2[cStatusMsgs].pszDefine = g_aStatusMsgs[i].pszDefine;
260 BldProgStrTab_AddStringDup(&StrTab, &s_aStatusMsgs2[cStatusMsgs].Define, g_aStatusMsgs[i].pszDefine);
261 if (enmMode != kMode_OnlyDefines)
262 BldProgStrTab_AddStringDup(&StrTab, &s_aStatusMsgs2[cStatusMsgs].MsgFull, g_aStatusMsgs[i].pszMsgFull);
263 cStatusMsgs++;
264 }
265 }
266
267 if (!BldProgStrTab_CompileIt(&StrTab, true))
268 return error("BldProgStrTab_CompileIt failed!\n");
269
270 /*
271 * Prepare output file.
272 */
273 FILE *pOut = fopen(pszOutFile, "wt");
274 if (pOut)
275 {
276 /*
277 * Print the table.
278 */
279 fprintf(pOut,
280 "\n"
281 "typedef struct RTMSGWINENTRYINT\n"
282 "{\n"
283 " uint32_t offDefine : 20;\n"
284 " uint32_t cchDefine : 9;\n"
285 "%s"
286 " int32_t iCode;\n"
287 "} RTMSGWINENTRYINT;\n"
288 "typedef RTMSGWINENTRYINT *PCRTMSGWINENTRYINT;\n"
289 "\n"
290 "static const RTMSGWINENTRYINT g_aWinMsgs[ /*%lu*/ ] =\n"
291 "{\n"
292 ,
293 enmMode == kMode_All
294 ? " uint32_t offMsgFull : 23;\n"
295 " uint32_t cchMsgFull : 9;\n" : "",
296 (unsigned long)cStatusMsgs);
297
298 if (enmMode == kMode_All)
299 for (size_t i = 0; i < cStatusMsgs; i++)
300 fprintf(pOut, "/*%#010lx:*/ { %#08x, %3u, %#08x, %3u, %ld },\n",
301 s_aStatusMsgs2[i].iCode,
302 s_aStatusMsgs2[i].Define.offStrTab,
303 (unsigned)s_aStatusMsgs2[i].Define.cchString,
304 s_aStatusMsgs2[i].MsgFull.offStrTab,
305 (unsigned)s_aStatusMsgs2[i].MsgFull.cchString,
306 s_aStatusMsgs2[i].iCode);
307 else if (enmMode == kMode_OnlyDefines)
308 for (size_t i = 0; i < cStatusMsgs; i++)
309 fprintf(pOut, "/*%#010lx:*/ { %#08x, %3u, %ld },\n",
310 s_aStatusMsgs2[i].iCode,
311 s_aStatusMsgs2[i].Define.offStrTab,
312 (unsigned)s_aStatusMsgs2[i].Define.cchString,
313 s_aStatusMsgs2[i].iCode);
314 else
315 return error("Unsupported message selection (%d)!\n", enmMode);
316 fprintf(pOut,
317 "};\n"
318 "\n");
319
320 BldProgStrTab_WriteStringTable(&StrTab, pOut, "static ", "g_", "WinMsgStrTab");
321
322 /*
323 * Close the output file and we're done.
324 */
325 fflush(pOut);
326 if (ferror(pOut))
327 rcExit = error("Error writing '%s'!\n", pszOutFile);
328 if (fclose(pOut) != 0)
329 rcExit = error("Failed to close '%s' after writing it!\n", pszOutFile);
330 }
331 else
332 rcExit = error("Failed to open '%s' for writing!\n", pszOutFile);
333 return rcExit;
334}
335
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette