Commit 755445ef authored by Victor Yacovlev's avatar Victor Yacovlev

Implemented compiler (and fixed on Win32 runner) russian/english usage

message
parent 5bd67f08
...@@ -105,7 +105,7 @@ void KumirBytecodeCompilerPlugin::start() ...@@ -105,7 +105,7 @@ void KumirBytecodeCompilerPlugin::start()
ots << modJs; ots << modJs;
ff.close();; ff.close();;
} }
QTextCodec * cp866 = QTextCodec::codecForName("CP866");
for (int i=0; i<errors.size(); i++) { for (int i=0; i<errors.size(); i++) {
Shared::Error e = errors[i]; Shared::Error e = errors[i];
QString errorMessage = trUtf8("Ошибка: ") + QString errorMessage = trUtf8("Ошибка: ") +
...@@ -119,7 +119,13 @@ void KumirBytecodeCompilerPlugin::start() ...@@ -119,7 +119,13 @@ void KumirBytecodeCompilerPlugin::start()
// ":" << e.start+1 << "-" << e.start+e.len << // ":" << e.start+1 << "-" << e.start+e.len <<
// ": " << e.code.toLocal8Bit().data() << std::endl; // ": " << e.code.toLocal8Bit().data() << std::endl;
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
std::cerr << cp866->fromUnicode(errorMessage).data(); QTextCodec * cp866 = QTextCodec::codecForName("CP866");
if (!qApp->arguments().contains("-ansi")) {
std::cerr << cp866->fromUnicode(errorMessage).data();
}
else {
std::cerr << errorMessage.toLocal8Bit().data();
}
#else #else
std::cerr << errorMessage.toLocal8Bit().data(); std::cerr << errorMessage.toLocal8Bit().data();
#endif #endif
...@@ -170,13 +176,46 @@ void KumirBytecodeCompilerPlugin::start() ...@@ -170,13 +176,46 @@ void KumirBytecodeCompilerPlugin::start()
} }
} }
else { else {
std::cerr << "Usage:" << std::endl; bool russianLanguage = false;
std::cerr << "\t" << qApp->argv()[0] << " [-J] [-S] [-o=OUTFILE.kod] FILENAME.kum" << std::endl; #if defined(WIN32) || defined(_WIN32)
std::cerr << std::endl; russianLanguage = true;
std::cerr << "\t-J\t\tIf present, generates internal AST in JSON file" << std::endl; #else
std::cerr << "\t-S\t\tIf present, generates human-readable form of code" << std::endl; char * env = getenv("LANG");
std::cerr << "\t-o OUTFILE.kod\tOutput file name (default: FILENAME.kod)" << std::endl; if (env) {
std::cerr << "\tFILENAME.kum\tKumir program input file name" << std::endl; std::string LANG(env);
russianLanguage = LANG.find("ru")!=std::string::npos;
}
#endif
QString message;
if (russianLanguage) {
message = QString::fromUtf8("Вызов:\n");
message += QString::fromAscii("\t") + qApp->argv()[0]+
QString::fromUtf8(" [-ansi] [-o=ИМЯПРОГРАММЫ.kod] [--encoding=КОДИРОВКА] ИМЯФАЙЛА.kum\n\n");
message += QString::fromUtf8("\t-ansi\t\tИспользовть кодировку 1251 вместо 866 в терминале (только для Windows)\n");
message += QString::fromUtf8("\t--encoding=КОДИРОВКА\tИспользовать заданную кодировку входного файла\n");
message += QString::fromUtf8("\t-o=ИМЯПРОГРАММЫ.kod\tИмя файла результата (по умолчанию: ИМЯФАЙЛА.kod)\n");
message += QString::fromUtf8("\tИМЯПРОГРАММЫ.kum\tИмя файла с Кумир-программой\n");
}
else {
message = QString::fromUtf8("Usage:\n");
message += QString::fromAscii("\t") + qApp->argv()[0]+
QString::fromUtf8(" [-ansi] [-o=PROGRAMNAME.kod] [--encoding=SOURCECODING] FILENAME.kum\n\n");
message += QString::fromUtf8("\t-ansi\t\tUse codepage 1251 instead of 866 in console (Windows only)\n");
message += QString::fromUtf8("\t--encoding=SOURCECODING\tForce source file encoding usage\n");
message += QString::fromUtf8("\t-o=PROGRAMNAME.kod\tOutput file name (default: FILENAME.kod)\n");
message += QString::fromUtf8("\tFILENAME.kum\tKumir input file name\n");
}
#ifdef Q_OS_WIN32
QTextCodec * cp866 = QTextCodec::codecForName("CP866");
if (!qApp->arguments().contains("-ansi")) {
std::cerr << cp866->fromUnicode(message).data();
}
else {
std::cerr << message.toLocal8Bit().data();
}
#else
std::cerr << message.toLocal8Bit().data();
#endif
qApp->setProperty("returnCode", 127); qApp->setProperty("returnCode", 127);
} }
} }
......
...@@ -15,7 +15,7 @@ int usage(const char * programName) ...@@ -15,7 +15,7 @@ int usage(const char * programName)
#if defined(WIN32) || defined(_WIN32) #if defined(WIN32) || defined(_WIN32)
russianLanguage = true; russianLanguage = true;
Char _n = Char('\r\n'); Char _n = Char('\n');
#else #else
char * env = getenv("LANG"); char * env = getenv("LANG");
if (env) { if (env) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment