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: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
extra_link_args = ["-lstdc++fs"]

setup(name="ccscript",
version="1.338",
version="1.339",
description="ccscript",
url="http://starmen.net/pkhack/ccscript",
ext_modules=[
Expand Down
35 changes: 32 additions & 3 deletions src/ccc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@
#include <vector>
#include <string>
#include <sstream>
#include <codecvt>
#include <iterator>
#include <signal.h>

#include <experimental/filesystem>
namespace fs = std::experimental::filesystem::v1;

#include "ccc.h"
#include "compiler.h"
#include "module.h"
#include "util.h"

using std::vector;
using std::string;
Expand All @@ -32,7 +36,7 @@ string getbasepath(const char* p)

void printversion()
{
cout << "ccc version 1.337 Duck Tape Edition" << endl;
cout << "ccc version 1.339 Duck Tape Edition" << endl;
}

void printusage()
Expand Down Expand Up @@ -64,9 +68,34 @@ void printusage()
<< " put the resulting compiled text at $F20000 in the ROM Earthbound.smc" << endl;
}

int main(int argc, char* argv[])
#ifdef _WIN32
int wmain(int argc, wchar_t* argv[])
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;

// Convert the utf-16 args to utf-8
std::vector<std::string> utf8Args;
for(int i = 0; i < argc; ++i) {
auto utf8Arg = converter.to_bytes(argv[i]);
utf8Args.push_back(utf8Arg);
}

// Expose the std::strings as a vector of const char*s
std::vector<const char*> utf8Argv;
std::transform(utf8Args.begin(), utf8Args.end(), std::back_inserter(utf8Argv),
[](const std::string& s){ return s.c_str(); } );

return run(argc, utf8Argv.data());
}
#else
int main(int argc, const char* argv[])
{
return run(argc, argv);
}
#endif

int run(int argc, const char* argv[])
{
//
// Get the default libs path
//
Expand Down Expand Up @@ -269,7 +298,7 @@ int main(int argc, char* argv[])
if(!summaryfile.empty())
{
std::fstream file;
file.open(summaryfile.c_str(), std::ios_base::out|std::ios_base::trunc);
file.open(ConvertToNativeString(summaryfile), std::ios_base::out|std::ios_base::trunc);
if(file.fail())
{
std::cerr << "Couldn't open " << summaryfile << " to write summary file." << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion src/ccc.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
int main(int argc, char* argv[]);
int run(int argc, const char* argv[]);
9 changes: 5 additions & 4 deletions src/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace fs = std::experimental::filesystem::v1;
#include "module.h"
#include "symboltable.h"
#include "exception.h"
#include "util.h"

using namespace std;

Expand Down Expand Up @@ -60,7 +61,7 @@ Compiler::Compiler(const string& romfile, unsigned int adr, unsigned int endadr)
nostdlibs = false;

// Open the file
ifstream file(filename.c_str(), ifstream::binary);
ifstream file(ConvertToNativeString(filename), ifstream::binary);

if(file.fail()) {
Error("failed to open file " + filename + " for reading.");
Expand Down Expand Up @@ -130,7 +131,7 @@ Compiler::~Compiler()
void Compiler::WriteOutput()
{
if(failed) return;
ofstream file(filename.c_str(), ofstream::binary);
ofstream file(ConvertToNativeString(filename), ofstream::binary);

if(file.fail()) {
Error("failed to open file " + filename + " for writing.");
Expand Down Expand Up @@ -576,7 +577,7 @@ void Compiler::DoDelayedWrites()
*/
void Compiler::WriteResetInfo(const std::string &filename)
{
ofstream file(filename.c_str());
ofstream file(ConvertToNativeString(filename));

if(file.fail())
throw Exception("couldn't create info file '" + filename + "'");
Expand Down Expand Up @@ -621,7 +622,7 @@ void Compiler::WriteResetInfo(const std::string &filename)

void Compiler::ApplyResetInfo(const std::string& filename)
{
ifstream file(filename.c_str());
ifstream file(ConvertToNativeString(filename));

if(file.fail())
return;
Expand Down
4 changes: 2 additions & 2 deletions src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "symboltable.h"
#include "bytechunk.h"
#include "exception.h"
#include "util.h"

using namespace std;

Expand Down Expand Up @@ -68,9 +69,8 @@ void Module::Load(const string& filename)
failed = true;
return;
}
ifstream in(filename.c_str());


ifstream in(ConvertToNativeString(filename));
if(in.fail())
{
parent->Error("couldn't open " + filename);
Expand Down
4 changes: 2 additions & 2 deletions src/pythonlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static PyObject* ccc(PyObject* self, PyObject* args) {
return nullptr;
}

std::vector<char*> argv;
std::vector<const char*> argv;
argv.reserve(argc+1);
argv.push_back(CCC_BASENAME);
for (int i = 0; i < argc; ++i) {
Expand All @@ -39,7 +39,7 @@ static PyObject* ccc(PyObject* self, PyObject* args) {
std::stringstream buffer;
std::streambuf* old_cout = std::cout.rdbuf(buffer.rdbuf());
std::streambuf* old_cerr = std::cerr.rdbuf(buffer.rdbuf());
int return_value = main(argc + 1, &argv[0]);
int return_value = run(argc + 1, argv.data());
std::cout.rdbuf(old_cout);
std::cerr.rdbuf(old_cerr);

Expand Down
16 changes: 16 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <string>
#include <codecvt>

#ifdef _WIN32
inline std::wstring ConvertToNativeString(const std::string str) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring wstr = converter.from_bytes(str);
return wstr;
}
#else
inline std::string ConvertToNativeString(const std::string str) {
return str;
}
#endif