2015-08-11 13:37:36 +00:00
|
|
|
|
|
|
|
// This file is part of hhpcomp, a free HTML Help Project (*.hhp) compiler.
|
|
|
|
// Copyright (C) 2015 Benedikt Freisen
|
2021-06-11 12:29:21 +00:00
|
|
|
//
|
2015-08-11 13:37:36 +00:00
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License, or (at your option) any later version.
|
2021-06-11 12:29:21 +00:00
|
|
|
//
|
2015-08-11 13:37:36 +00:00
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
2021-06-11 12:29:21 +00:00
|
|
|
//
|
2015-08-11 13:37:36 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2015-08-11 20:19:58 +00:00
|
|
|
#if defined(_WIN32)
|
2015-08-11 21:06:37 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2020-05-16 16:19:31 +00:00
|
|
|
#include <intrin.h>
|
2021-06-11 12:29:21 +00:00
|
|
|
#include <windows.h> // for GetFullPathNameA
|
2015-08-11 20:19:58 +00:00
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2015-08-11 13:37:36 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
string to_upper(string s)
|
|
|
|
{
|
|
|
|
string temp = s;
|
|
|
|
transform(temp.begin(), temp.end(), temp.begin(), ::toupper);
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
2015-08-11 20:19:58 +00:00
|
|
|
string real_path(const char* path)
|
2015-08-11 13:37:36 +00:00
|
|
|
{
|
2015-08-11 20:19:58 +00:00
|
|
|
char* temp = NULL;
|
|
|
|
#if defined(_WIN32)
|
|
|
|
char temp2[MAX_PATH];
|
|
|
|
if (GetFullPathNameA(path, MAX_PATH, temp2, NULL)) {
|
|
|
|
temp = temp2;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
temp = realpath(path, NULL);
|
|
|
|
#endif
|
2015-08-11 13:37:36 +00:00
|
|
|
if (temp == NULL)
|
|
|
|
throw runtime_error("realpath failed");
|
|
|
|
string result(temp);
|
2015-08-11 20:19:58 +00:00
|
|
|
#if !defined(_WIN32)
|
|
|
|
free(temp);
|
|
|
|
#endif
|
2015-08-11 13:37:36 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
string replace_backslashes(string s)
|
|
|
|
{
|
|
|
|
string temp = s;
|
|
|
|
for (string::iterator it = temp.begin(); it != temp.end(); ++it)
|
|
|
|
if (*it == '\\')
|
|
|
|
*it = '/';
|
|
|
|
return temp;
|
|
|
|
}
|