Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
treefrogframework committed Apr 14, 2024
1 parent 6829322 commit b761242
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
9 changes: 6 additions & 3 deletions compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ int Compiler::compileAndExecute(const QString &cc, const QStringList &options, c
while (!exe.waitForFinished(50)) {
auto exeout = exe.readAll();
if (!exeout.isEmpty()) {
print() << exeout << flush;
// stdout raw data
std::cout << exeout.data() << std::flush;
}

#ifdef Q_OS_WIN
Expand All @@ -219,7 +220,8 @@ int Compiler::compileAndExecute(const QString &cc, const QStringList &options, c
}
qApp->processEvents();
}
print() << exe.readAll() << flush;
// stdout raw data
std::cout << exe.readAll().data() << std::flush;
}

QFile::remove(aoutName());
Expand All @@ -244,9 +246,10 @@ int Compiler::compileFileAndExecute(const QString &path)
}

QTextStream ts(&srcFile);
ts.setEncoding(QStringConverter::System);
QString src = ts.readLine().trimmed(); // read first line

if (src.startsWith("#!")) {
if (src.startsWith("#!")) { // check shebang
src = ts.readAll();
} else {
src += "\n";
Expand Down
27 changes: 11 additions & 16 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,9 @@ static void showHelp()

static void showConfigs(const QSettings &conf)
{
QStringList confkeys;
confkeys << "CXX"
<< "CXXFLAGS"
<< "LDFLAGS"
<< "COMMON_INCLUDES";

QStringList configs = conf.allKeys();
for (QStringListIterator it(conf.allKeys()); it.hasNext();) {
const QString &key = it.next();
const QStringList confkeys {"CXX", "CXXFLAGS", "LDFLAGS", "COMMON_INCLUDES"};

for (auto &key : conf.allKeys()) {
if (confkeys.contains(key))
printf("%s=%s\n", qPrintable(key), qPrintable(conf.value(key).toString()));
}
Expand Down Expand Up @@ -274,7 +268,8 @@ static QString readLine()
std::string s;

if (std::getline(std::cin, s)) {
line = QString::fromStdString(s);
// Countermeasure for garbled characters in windows
line = QString::fromLocal8Bit(QByteArray::fromStdString(s));
}
return line;
}
Expand All @@ -287,9 +282,9 @@ static int interpreter()
print() << "Loaded INI file: " << conf->fileName() << endl;
print().flush();

QStringList includes = conf->value("COMMON_INCLUDES").toString().split(" ", SkipEmptyParts);
for (QStringListIterator i(includes); i.hasNext();) {
QString s = i.next().trimmed();
const QStringList includes = conf->value("COMMON_INCLUDES").toString().split(" ", SkipEmptyParts);
for (auto s : includes) {
s = s.trimmed();
if (!s.isEmpty()) {
if (s.startsWith("<") || s.startsWith('"')) {
headers << QString("#include ") + s;
Expand Down Expand Up @@ -340,11 +335,10 @@ static int interpreter()
if (line.startsWith(".del ") || line.startsWith(".rm ")) { // Deletes code
int n = line.indexOf(' ');
line.remove(0, n + 1);
QStringList list = line.split(QRegularExpression("[,\\s]"), SkipEmptyParts);
const QStringList list = line.split(QRegularExpression("[,\\s]"), SkipEmptyParts);

std::list<int> numbers; // line-numbers
for (QStringListIterator it(list); it.hasNext();) {
const QString &s = it.next();
for (auto &s : list) {
bool ok;
int n = s.toInt(&ok);
if (ok && n > 0)
Expand Down Expand Up @@ -444,6 +438,7 @@ int main(int argv, char *argc[])
} else if (QCoreApplication::arguments().contains("-")) { // Check pipe option
QString src;
QTextStream tsstdin(stdin);
tsstdin.setEncoding(QStringConverter::System);
while (!tsstdin.atEnd()) {
src += tsstdin.readAll();
}
Expand Down
1 change: 1 addition & 0 deletions print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Print &Print::globalInstance()
{
static Print global;
global.setEncoding(QStringConverter::System);
global.flush();
return global;
}
Expand Down

0 comments on commit b761242

Please sign in to comment.