/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <cstdio> #include <cstring>
#include <Windows.h>
staticvoid print_result(constwchar_t* argv0, constwchar_t* result)
{ char output[1000]; if (WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, result, -1, output, sizeof(output), NULL,
NULL)
== 0)
{
fprintf(stderr, "%S --8.3: Could not convert result to UTF-8.\n", argv0); exit(1);
}
// Intentionally output no newline at end
printf("%s", output);
fflush(stdout);
}
int wmain(int argc, wchar_t** argv)
{ if (argc <= 1)
{
fprintf(stderr, "%S: Usage:\n", argv[0]);
fprintf(stderr, "%S --8.3 \n", argv[0]);
fprintf(stderr, " Print the 8.3 form of a Windows pathnam. Fail it not present.\n");
fprintf(stderr, "%S --read-registry [32|64] \n", argv[0]);
fprintf(stderr, " Read a string value from the Registry and print it.\n");
fprintf(stderr, "%S --list-registry [32|64] \n", argv[0]);
fprintf(stderr, " List subkeys of a key in the Registry.\n"); exit(1);
}
if (wcscmp(argv[1], L"--8.3") == 0)
{ if (argc != 3)
{
fprintf(stderr, "%S --8.3: One pathname argument expected\n", argv[0]); exit(1);
}
// The argument should be a pathname in Windows format. The // output will be the 8.3 pathname if present. If not present, // return failure.
wchar_t woutput[1000]; if (GetShortPathNameW(argv[2], woutput, sizeof(woutput) / sizeof(woutput[0])) == 0)
{
fprintf(stderr, "%S --8.3: Could not get short pathname of %S.\n", argv[0], argv[2]); exit(1);
}
REGSAM sam = parse_bitness(argv[0], L"--read-registry", argv[2]);
wchar_t* path = wcsdup(argv[3]);
for (wchar_t* p = path; *p != L'\0'; p++) if (*p == '/')
*p = '\\';
wchar_t* const first_backslash = wcschr(path, L'\\'); if (first_backslash == NULL)
{
fprintf(stderr, "%S: Invalid path %S to value in the Registry.\n", argv[0], path); exit(1);
}
wchar_t* last_backslash = wcsrchr(key_path, L'\\'); if (last_backslash == NULL)
{
fprintf(stderr, "%S: Invalid path %S\\%S to value in the Registry.\n", argv[0],
hive_name, key_path); exit(1);
}
*last_backslash = L'\0'; wchar_t* value = last_backslash + 1;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.