Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .devzone/build/files

This file was deleted.

54 changes: 0 additions & 54 deletions .devzone/build/grfcodec.spec

This file was deleted.

1 change: 0 additions & 1 deletion .devzone/build/nightlies/cleanup_days

This file was deleted.

1 change: 0 additions & 1 deletion .devzone/build/nightlies/cleanup_releases

This file was deleted.

1 change: 0 additions & 1 deletion .devzone/build/nightlies/enable

This file was deleted.

1 change: 0 additions & 1 deletion .devzone/build/type

This file was deleted.

9 changes: 2 additions & 7 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

echo "::group::Install dependencies"
sudo apt-get install -y --no-install-recommends \
libboost-dev \
libpng-dev \
# EOF
echo "::endgroup::"
env:
Expand Down Expand Up @@ -93,9 +93,7 @@ jobs:
- name: Prepare vcpkg
run: |
./vcpkg/vcpkg install --triplet=${{ matrix.arch }}-osx \
boost-bimap \
boost-date-time \
boost-foreach \
libpng \
# EOF

- name: Install GCC problem matcher
Expand Down Expand Up @@ -151,9 +149,6 @@ jobs:
shell: bash
run: |
./vcpkg/vcpkg install --triplet=${{ matrix.arch }}-windows-static \
boost-bimap \
boost-date-time \
boost-foreach \
libpng \
# EOF

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ jobs:
shell: bash
run: |
./vcpkg/vcpkg install --triplet=${{ matrix.arch }}-windows-static \
boost-bimap \
boost-date-time \
boost-foreach \
libpng \
# EOF

Expand Down
46 changes: 0 additions & 46 deletions 0compile.txt

This file was deleted.

3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ endif()


find_package(PNG)
find_package(Boost CONFIG REQUIRED)


include(CheckCXXSymbolExists)
Expand Down Expand Up @@ -120,13 +119,11 @@ add_dependencies(grfstrip version_header)
# Create nforenum
add_executable(nforenum)
add_dependencies(nforenum palettes_header version_header)
target_link_libraries(nforenum Boost::boost)


# Create grfcodec
add_executable(grfcodec)
add_dependencies(grfcodec palettes_header version_header)
target_link_libraries(grfcodec Boost::boost)
if(PNG_FOUND)
set_target_properties(grfcodec PROPERTIES COMPILE_FLAGS -DWITH_PNG)
target_link_libraries(grfcodec PNG::PNG)
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ target_sources(nforenum PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/messages.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nforenum.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pseudo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/pseudo_seq.cpp
${CMAKE_CURRENT_SOURCE_DIR}/rangedint.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sanity.cpp
${CMAKE_CURRENT_SOURCE_DIR}/strings.cpp
Expand Down
26 changes: 14 additions & 12 deletions src/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ int makeint(U8 low, S8 high)

void read_file(std::istream&in,int infover,int grfcontversion,AllocArray<Sprite>&sprites);

nfe_map nfo_escapes;

inforeader::inforeader(char *fn, int grfcontversion)
{
std::ifstream f;
Expand Down Expand Up @@ -66,7 +64,9 @@ inforeader::inforeader(char *fn, int grfcontversion)
if(str == "=") byte--;
else if (str[0] == '@')
byte = strtol(str.c_str()+1, NULL, 16);
else nfo_escapes.insert(nfe_pair(str, byte++));
else {
InsertEscape(str, byte++);
}
}
}
getline(f, buffer); // Try again to skip "format: " line
Expand Down Expand Up @@ -153,25 +153,27 @@ infowriter::infowriter(FILE *info, int maxboxes, int useplaintext, const char *d
fprintf(info,"// (Info version %d)", _useexts ? 32 : 6);
if(_useexts) {
// (re)insert default escapes
foreach(const esc& e, escapes)
nfo_escapes.insert(nfe_pair(e.str+1, e.byte));
for (const esc &e : escapes) {
InsertEscape(e.str + 1, e.byte);
}
fputs("\n// Escapes:", info);
int oldbyte = -1;

for (int act = 0; act < 255; act++) {
foreach (const nfe_rpair& p, nfo_escapes.right) {
if (p.second[0] != act) continue;
for (const auto &p : nfo_escapes) {
if (p.first[0] != act) continue;

if (p.first == oldbyte) {
if (p.second == oldbyte) {
fprintf(info, " =");
--oldbyte;
} else if (p.first < oldbyte) {
} else if (p.second < oldbyte) {
fputs("\n// Escapes:", info);
oldbyte = -1;
}
while (++oldbyte != p.first)
fprintf(info," %s", nfo_escapes.right.begin()->second.c_str());
fprintf(info, " %s", p.second.c_str());
while (++oldbyte != p.second) {
fprintf(info," %s", nfo_escapes[0].first.c_str());
}
fprintf(info, " %s", p.first.c_str());
}
}
}
Expand Down
71 changes: 50 additions & 21 deletions src/mapescapes.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* mapescapes.cpp
* Helper functions for using boost::bimapped escapes
* Helper functions for using escapes
*
* Copyright 2009 by Dale McCoy.
*
Expand All @@ -19,6 +19,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <algorithm>
#include <string>


Expand All @@ -27,37 +28,65 @@
#include "messages.h"
#include "mapescapes.h"

nfe_map nfo_escapes;

void InsertEscape(const std::string &key, int byte) {
auto new_pair = std::make_pair(key, byte);
auto it = std::find(nfo_escapes.begin(), nfo_escapes.end(), new_pair);
if (it == nfo_escapes.end()) {
nfo_escapes.push_back(new_pair);
}
}

void RemoveEscape(const std::string &key) {
auto it = std::remove_if(nfo_escapes.begin(), nfo_escapes.end(), [key](const auto &p) {
return p.first == key;
});
nfo_escapes.erase(it, nfo_escapes.end());
}

std::string FindEscape(char action, int byte) {
// Look for a custom escape
foreach(const nfe_rpair& p, nfo_escapes.right.equal_range(byte))
if (p.second[0] == action)
return " \\" + p.second;
auto it = std::find_if(nfo_escapes.begin(), nfo_escapes.end(), [action, byte](const auto &p) {
return p.first[0] == action && p.second == byte;
});
if (it != nfo_escapes.end()) {
return " \\" + it->first;
}

// Look for a built-in escape
foreach(const esc& e, escapes)
if (e.action==ctoi(action) && e.byte==byte)
return ' ' + std::string(e.str);
for (const esc &e : escapes) {
if (e.action==ctoi(action) && e.byte==byte) return ' ' + std::string(e.str);
}
return "";
}

std::string FindEscape(char action, int byte, uint offset) {
// This time, look for a built-in escape first
foreach(const esc& e, escapes)
if (e.action==ctoi(action) && e.byte==byte && e.pos==offset)
return ' ' + std::string(e.str);
for (const esc &e : escapes) {
if (e.action==ctoi(action) && e.byte==byte && e.pos==offset) return ' ' + std::string(e.str);
}
// Look for a custom escape
foreach(const nfe_rpair& p, nfo_escapes.right.equal_range(byte))
if (p.second[0] == action)
return " \\" + p.second;
auto it = std::find_if(nfo_escapes.begin(), nfo_escapes.end(), [action, byte](const auto &p) {
return p.first[0] == action && p.second == byte;
});
if (it != nfo_escapes.end()) {
return " \\" + it->first;
}
return "";
}

int FindEscape(std::string str) {
foreach(esc e, escapes)
if(str == e.str+1)
return e.byte;
nfe_left_iter ret = nfo_escapes.left.find(str);
if(ret == nfo_escapes.left.end())
return -1;
return ret->second;
int FindEscape(const std::string &str) {
for (const esc &e : escapes) {
if(str == e.str+1) return e.byte;
}

const auto &it = std::find_if(nfo_escapes.begin(), nfo_escapes.end(), [str](const auto &p) {
return p.first == str;
});
if (it != nfo_escapes.end()) {
return it->second;
}

return -1;
}
27 changes: 9 additions & 18 deletions src/mapescapes.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* mapescapes.h
* Helper definitions for using boost::bimap
* Helper definitions for using NFO escapes
*
* Copyright 2009 by Dale McCoy.
*
Expand All @@ -19,25 +19,16 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/* If your compiler errors on the following lines, boost is not
* properly installed, or your version of boost is too old.
* Get boost from http://www.boost.org */
#include <boost/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/foreach.hpp>
#include <vector>

using namespace boost::bimaps;

#define foreach BOOST_FOREACH

typedef unsigned char U8;
#include "escapes.h"

typedef bimap<std::string, multiset_of<int> > nfe_map;
typedef nfe_map::value_type nfe_pair;
typedef nfe_map::left_value_type nfe_lpair;
typedef nfe_map::right_value_type nfe_rpair;
typedef nfe_map::left_iterator nfe_left_iter;
typedef nfe_map::right_iterator nfe_right_iter;
using nfe_map = std::vector<std::pair<std::string, int>>;

void InsertEscape(const std::string &key, int val);
void RemoveEscape(const std::string &key);
std::string FindEscape(char action, int byte);
std::string FindEscape(char action, int byte, uint offset);
int FindEscape(const std::string &str);

extern nfe_map nfo_escapes;
Loading