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