ReactOS 0.4.15-dev-8428-g6910fa6
utils.cpp
Go to the documentation of this file.
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 <intrin.h>
27 #include <windows.h> // for GetFullPathNameA
28#else
29 #include <unistd.h>
30#endif
31
32#include <stdlib.h>
33
34using namespace std;
35
36string to_upper(string s)
37{
38 string temp = s;
39 transform(temp.begin(), temp.end(), temp.begin(), ::toupper);
40 return temp;
41}
42
43string real_path(const char* path)
44{
45 char* temp = NULL;
46 #if defined(_WIN32)
47 char temp2[MAX_PATH];
48 if (GetFullPathNameA(path, MAX_PATH, temp2, NULL)) {
49 temp = temp2;
50 }
51 #else
52 temp = realpath(path, NULL);
53 #endif
54 if (temp == NULL)
55 throw runtime_error("realpath failed");
56 string result(temp);
57 #if !defined(_WIN32)
58 free(temp);
59 #endif
60 return result;
61}
62
63string replace_backslashes(string s)
64{
65 string temp = s;
66 for (string::iterator it = temp.begin(); it != temp.end(); ++it)
67 if (*it == '\\')
68 *it = '/';
69 return temp;
70}
int toupper(int c)
Definition: utclib.c:881
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI GetFullPathNameA(IN LPCSTR lpFileName, IN DWORD nBufferLength, OUT LPSTR lpBuffer, OUT LPSTR *lpFilePart)
Definition: path.c:993
GLdouble s
Definition: gl.h:2039
GLuint GLenum GLenum transform
Definition: glext.h:9407
GLuint64EXT * result
Definition: glext.h:11304
Definition: features.h:417
static calc_node_t temp
Definition: rpn_ieee.c:38
string real_path(const char *path)
Definition: utils.cpp:43
string replace_backslashes(string s)
Definition: utils.cpp:63
string to_upper(string s)
Definition: utils.cpp:36