[LDR][APPHELP] Add a shim that disables manifest compatibility version parsing
[reactos.git] / sdk / tools / hhpcomp / utils.cpp
1
2 // This file is part of hhpcomp, a free HTML Help Project (*.hhp) compiler.
3 // Copyright (C) 2015 Benedikt Freisen
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20 #include <string>
21 #include <algorithm>
22 #include <stdexcept>
23
24 #if defined(_WIN32)
25 #define WIN32_LEAN_AND_MEAN
26 #include <windows.h> // for GetFullPathNameA
27 #else
28 #include <unistd.h>
29 #endif
30
31 #include <stdlib.h>
32
33 using namespace std;
34
35 string to_upper(string s)
36 {
37 string temp = s;
38 transform(temp.begin(), temp.end(), temp.begin(), ::toupper);
39 return temp;
40 }
41
42 string real_path(const char* path)
43 {
44 char* temp = NULL;
45 #if defined(_WIN32)
46 char temp2[MAX_PATH];
47 if (GetFullPathNameA(path, MAX_PATH, temp2, NULL)) {
48 temp = temp2;
49 }
50 #else
51 temp = realpath(path, NULL);
52 #endif
53 if (temp == NULL)
54 throw runtime_error("realpath failed");
55 string result(temp);
56 #if !defined(_WIN32)
57 free(temp);
58 #endif
59 return result;
60 }
61
62 string replace_backslashes(string s)
63 {
64 string temp = s;
65 for (string::iterator it = temp.begin(); it != temp.end(); ++it)
66 if (*it == '\\')
67 *it = '/';
68 return temp;
69 }