From: hama Date: Wed, 2 Dec 2015 22:04:01 +0000 (+0100) Subject: ReProgArgs works, I18N::s2b() added X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=ab444c620c0d90fae903fe492630b77490601a1b;p=reqt ReProgArgs works, I18N::s2b() added --- diff --git a/appl/labor/mainwindow.cpp b/appl/labor/mainwindow.cpp index bbaf91e..08f8c17 100644 --- a/appl/labor/mainwindow.cpp +++ b/appl/labor/mainwindow.cpp @@ -14,108 +14,108 @@ #include "ui_mainwindow.h" enum { - COL_NO, - COL_TYPE, - COL_CONTENT + COL_NO, + COL_TYPE, + COL_CONTENT }; MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow), - m_dropNo(0) + QMainWindow(parent), + ui(new Ui::MainWindow), + m_dropNo(0) { - ui->setupUi(this); - ui->tableWidgetDragInfo->setMainWindow(this); - connect(ui->comboBoxMimeType, SIGNAL(currentIndexChanged(const QString&)), - this, SLOT(currentIndexChanged(const QString&))); + ui->setupUi(this); + ui->tableWidgetDragInfo->setMainWindow(this); + connect(ui->comboBoxMimeType, SIGNAL(currentIndexChanged(const QString&)), + this, SLOT(currentIndexChanged(const QString&))); } MainWindow::~MainWindow() { - delete ui; + delete ui; } void MainWindow::log(const QString& type, const QString& data) { - ui->tableWidgetDragInfo->insertRow(0); - ui->tableWidgetDragInfo->setItem(0, COL_NO, new QTableWidgetItem(QString::number(m_dropNo))); - ui->tableWidgetDragInfo->setItem(0, COL_TYPE, new QTableWidgetItem(type)); - ui->tableWidgetDragInfo->setItem(0, COL_CONTENT, new QTableWidgetItem(data)); + ui->tableWidgetDragInfo->insertRow(0); + ui->tableWidgetDragInfo->setItem(0, COL_NO, new QTableWidgetItem(QString::number(m_dropNo))); + ui->tableWidgetDragInfo->setItem(0, COL_TYPE, new QTableWidgetItem(type)); + ui->tableWidgetDragInfo->setItem(0, COL_CONTENT, new QTableWidgetItem(data)); } bool MainWindow::isBinary(const QByteArray& data) { - bool rc = false; - for (int ix = 0; ix < data.length(); ix++){ - if (data.at(ix) == 0){ - rc = true; - break; - } - } - return rc; + bool rc = false; + for (int ix = 0; ix < data.length(); ix++){ + if (data.at(ix) == 0){ + rc = true; + break; + } + } + return rc; } double MainWindow::fontWidth(){ - QFont myFont; - QString str("0005: 61 62 63 64 65 66 67 68 69 6a|abcdefghijk"); + QFont myFont; + QString str("0005: 61 62 63 64 65 66 67 68 69 6a|abcdefghijk"); - QFontMetrics fm(myFont); - double width = fm.width(str) / str.length(); - return width; + QFontMetrics fm(myFont); + double width = fm.width(str) / str.length(); + return width; } inline char toHex(int value){ - return value < 10 ? '0' + value : 'a' + (value - 10); + return value < 10 ? '0' + value : 'a' + (value - 10); } void MainWindow::setData(const char* data, int dataSize, int lineLength) { - if (lineLength < 0) - lineLength = int (ui->plainTextEdit->width() / fontWidth()) - 1; - int offsetWidth = dataSize >= 1000*1000 ? 10 : dataSize > 10000 ? 6 : 4; - int charPerLine = (lineLength - offsetWidth - 1) / 4; - int countLines = (dataSize + charPerLine - 1) / charPerLine; - int restLength = dataSize; - char formatOffset[10]; - snprintf(formatOffset, sizeof formatOffset, "%%0%dd:", offsetWidth); - const unsigned char* ptr = reinterpret_cast(data); - QByteArray buffer; - buffer.reserve(countLines * (charPerLine + 1) + 100); - char lineNo[32]; - int offset = 0; - while (restLength > 0){ - snprintf(lineNo, sizeof lineNo, formatOffset, offset); - buffer.append(lineNo); - for (int ix = 0; ix < charPerLine; ix++){ - if (ix >= restLength) - buffer.append(" "); - else - buffer.append(toHex(ptr[ix]/16)).append(toHex(ptr[ix]%16)).append(' '); - } - buffer[buffer.length() - 1] = '|'; - for (int ix = 0; ix < charPerLine; ix++){ - if (ix >= restLength) - buffer.append(" "); - else if (ptr[ix] > 0x7f || ptr[ix] < ' ') - buffer.append('.'); - else - buffer.append((char) ptr[ix]); - } - buffer.append('\n'); - restLength -= charPerLine; - ptr += charPerLine; - offset += charPerLine; - } - ui->plainTextEdit->setPlainText(QString::fromUtf8(buffer)); + if (lineLength < 0) + lineLength = int (ui->plainTextEdit->width() / fontWidth()) - 1; + int offsetWidth = dataSize >= 1000*1000 ? 10 : dataSize > 10000 ? 6 : 4; + int charPerLine = (lineLength - offsetWidth - 1) / 4; + int countLines = (dataSize + charPerLine - 1) / charPerLine; + int restLength = dataSize; + char formatOffset[10]; + snprintf(formatOffset, sizeof formatOffset, "%%0%dd:", offsetWidth); + const unsigned char* ptr = reinterpret_cast(data); + QByteArray buffer; + buffer.reserve(countLines * (charPerLine + 1) + 100); + char lineNo[32]; + int offset = 0; + while (restLength > 0){ + snprintf(lineNo, sizeof lineNo, formatOffset, offset); + buffer.append(lineNo); + for (int ix = 0; ix < charPerLine; ix++){ + if (ix >= restLength) + buffer.append(" "); + else + buffer.append(toHex(ptr[ix]/16)).append(toHex(ptr[ix]%16)).append(' '); + } + buffer[buffer.length() - 1] = '|'; + for (int ix = 0; ix < charPerLine; ix++){ + if (ix >= restLength) + buffer.append(" "); + else if (ptr[ix] > 0x7f || ptr[ix] < ' ') + buffer.append('.'); + else + buffer.append((char) ptr[ix]); + } + buffer.append('\n'); + restLength -= charPerLine; + ptr += charPerLine; + offset += charPerLine; + } + ui->plainTextEdit->setPlainText(QString::fromUtf8(buffer)); } QByteArray urlAsBytes(const QList& urls){ - QByteArray rc; - rc.reserve(urls.length() * 80); - QList::const_iterator it; - for (it = urls.begin(); it != urls.end(); ++it){ - rc.append(it->path()).append('\n'); - } - return rc; + QByteArray rc; + rc.reserve(urls.length() * 80); + QList::const_iterator it; + for (it = urls.begin(); it != urls.end(); ++it){ + rc.append(it->path()).append('\n'); + } + return rc; } void MainWindow::setMimeData(const QMimeData* mime){ @@ -124,26 +124,26 @@ void MainWindow::setMimeData(const QMimeData* mime){ ui->comboBoxMimeType->clear(); ui->comboBoxMimeType->addItems(formats); for (int ix = 0; ix < formats.length(); ix++){ - QString name = formats.at(ix); - if (name.indexOf("html") >= 0) - m_mimeData[name] = mime->html().toUtf8(); - else if (name.indexOf("text") >= 0) - m_mimeData[name] = mime->text().toUtf8(); - else if (name.indexOf("image") >= 0) - m_mimeData[name] = mime->imageData().toByteArray(); - else if (name.indexOf("uri-list") >= 0) - m_mimeData[name] = urlAsBytes(mime->urls()); - else - m_mimeData[name] = mime->data(name); + QString name = formats.at(ix); + if (name.indexOf("html") >= 0) + m_mimeData[name] = I18N::s2b(mime->html()); + else if (name.indexOf("text") >= 0) + m_mimeData[name] = I18N::s2b(mime->text()); + else if (name.indexOf("image") >= 0) + m_mimeData[name] = mime->imageData().toByteArray(); + else if (name.indexOf("uri-list") >= 0) + m_mimeData[name] = urlAsBytes(mime->urls()); + else + m_mimeData[name] = mime->data(name); } } void MainWindow::currentIndexChanged(const QString& text) { - QByteArray data = m_mimeData[text]; - if (isBinary(data)){ - setData(data.constData(), data.length()); - } else { - ui->plainTextEdit->setPlainText(QString::fromUtf8(data.constData())); - } + QByteArray data = m_mimeData[text]; + if (isBinary(data)){ + setData(data.constData(), data.length()); + } else { + ui->plainTextEdit->setPlainText(QString::fromUtf8(data.constData())); + } } diff --git a/appl/refind/mainwindow.cpp b/appl/refind/mainwindow.cpp index 2308aea..f21234a 100644 --- a/appl/refind/mainwindow.cpp +++ b/appl/refind/mainwindow.cpp @@ -281,7 +281,7 @@ void MainWindow::exportFiles(){ comboText(ui->comboBoxFooter); if (ui->radioButtonFile->isChecked()){ QString fn = ui->comboBoxExportFile->currentText(); - FILE* fp = fopen(fn.toUtf8(), "w"); + FILE* fp = fopen( I18N::s2b(fn), "w"); if (fp == NULL) guiError(ui->comboBoxExportFile, tr("not a valid file: ") + fn); else{ @@ -811,8 +811,8 @@ else{ / CLOCKS_PER_SEC; QString msg; msg.sprintf( - QObject::tr( - "Found: %d dir(s) and %d file(s) with %.6f MByte. Duration of the search: %.3f sec").toUtf8(), + I18N::s2b(QObject::tr( + "Found: %d dir(s) and %d file(s) with %.6f MByte. Duration of the search: %.3f sec")), m_statistics.m_dirs, m_statistics.m_files, m_statistics.m_bytes / 1000000.0, m_statistics.m_runtimeSeconds); say(LOG_INFO, msg); diff --git a/appl/refind/utils.cpp b/appl/refind/utils.cpp index 87ed346..b04e151 100644 --- a/appl/refind/utils.cpp +++ b/appl/refind/utils.cpp @@ -181,10 +181,10 @@ void ContextHandlerList::restore(ReStateStorage& storage){ handler->m_text = cols.at(0); handler->m_program = cols.at(1); handler->m_arguments = cols.at(2); - const char* sValue = cols.at(3).toUtf8().constData(); - handler->m_fileType = ContextHandler::FileType(atol(sValue)); - sValue = cols.at(4).toUtf8().constData(); - handler->m_directoryMode = ContextHandler::DirMode(atol(sValue)); + long int lValue = atol(cols.at(3).toLatin1().constData()); + handler->m_fileType = ContextHandler::FileType(lValue); + lValue = atol(cols.at(4).toLatin1().constData()); + handler->m_directoryMode = ContextHandler::DirMode(atol(lValue)); m_list.append(handler); } if (m_list.size() == 0){ diff --git a/appl/reide/mainwindow.cpp b/appl/reide/mainwindow.cpp index 9ec5186..37eb3b1 100644 --- a/appl/reide/mainwindow.cpp +++ b/appl/reide/mainwindow.cpp @@ -24,7 +24,7 @@ MainWindow::MainWindow(const char* workspace, const char* project, m_delayedStorage(NULL){ setLayout(new QVBoxLayout); if (workspace == NULL) - workspace = QDir::homePath().toUtf8(); + workspace = I18N::s2b(QDir::homePath()); changeWorkspace(workspace == NULL ? QDir::homePath() : workspace); QString proj(project == NULL ? "" : project); diff --git a/appl/reimgconvert/converter.cpp b/appl/reimgconvert/converter.cpp index c30c7e0..bf6803f 100644 --- a/appl/reimgconvert/converter.cpp +++ b/appl/reimgconvert/converter.cpp @@ -123,25 +123,25 @@ Converter::Converter(const QString& directory, const QString& targetDirectory, const QString& sourcePattern, const QString& targetType, int landscapeX, int landscapeY, int portraitX, int portraitY, int squareX, int quality, MainWindow* mainWindow) : - m_dir(directory), - m_targetDir( - targetDirectory.indexOf(QDir::separator()) >= 0 ? - targetDirectory : - directory + QDir::separator() + targetDirectory), - m_sourcePattern(sourcePattern), - m_targetType(targetType), - m_landscapeWidth(landscapeX), - m_landscapeHeight(landscapeY), - m_portraitWidth(portraitX), - m_portraitHeight(portraitY), - m_squareWidth(squareX), - m_quality(targetType == "jpg" ? quality : 0), - m_mainWindows(mainWindow), - m_shouldStop(false), - m_imageInfo( - new QRegularExpression(" (PNG|GIF|JPEG) (\\d+)x(\\d+) ")), - m_groupWidth(2), - m_groupHeight(3){ + m_dir(directory), + m_targetDir( + targetDirectory.indexOf(QDir::separator()) >= 0 ? + targetDirectory : + directory + QDir::separator() + targetDirectory), + m_sourcePattern(sourcePattern), + m_targetType(targetType), + m_landscapeWidth(landscapeX), + m_landscapeHeight(landscapeY), + m_portraitWidth(portraitX), + m_portraitHeight(portraitY), + m_squareWidth(squareX), + m_quality(targetType == "jpg" ? quality : 0), + m_mainWindows(mainWindow), + m_shouldStop(false), + m_imageInfo( + new QRegularExpression(" (PNG|GIF|JPEG) (\\d+)x(\\d+) ")), + m_groupWidth(2), + m_groupHeight(3){ } /** @@ -192,19 +192,19 @@ void Converter::convert(const QString& source, const QString& target, int width, args << "-size" << QString::number(width) + "x" + QString::number(height); args << source; if (quality > 0) - args << "-quality" << QString::number(quality); + args << "-quality" << QString::number(quality); args << "-resize" - << QString::number(widthNew) + "x" + QString::number(heightNew); + << QString::number(widthNew) + "x" + QString::number(heightNew); args << target; QProcess process; process.start("/usr/bin/convert", args); QByteArray output; while (process.waitForReadyRead()){ - output = process.readAll(); + output = process.readAll(); } output = process.readAllStandardError(); if (!output.isEmpty()) - error(output); + error(output); process.close(); } @@ -222,49 +222,49 @@ void Converter::convertOneFile(const QString& source, const QString& target, QString info; clock_t start = clock(); if (readProperties(source, width, height, info)){ - bool doConvert = false; - int widthNew, heightNew; - if (abs(width - height) < 5){ - // Square format: - doConvert = width > m_squareWidth; - if (doConvert) - widthNew = heightNew = m_squareWidth; - }else if (width > height){ - // Landscape: - doConvert = width > m_landscapeWidth || height > m_landscapeHeight; - if (doConvert){ - if (width > m_landscapeWidth && m_landscapeWidth > 0){ - widthNew = m_landscapeWidth; - heightNew = height * m_landscapeWidth / width; - }else{ - heightNew = m_landscapeHeight; - widthNew = width * m_landscapeHeight / height; - } - } - }else{ - // Portrait - doConvert = width > m_portraitWidth || height > m_portraitHeight; - if (doConvert){ - if (width > m_portraitWidth && m_portraitWidth > 0){ - widthNew = m_portraitWidth; - heightNew = height * m_portraitWidth / width; - }else{ - heightNew = m_portraitHeight; - widthNew = width * m_portraitHeight / height; - } - } - } - log( - source + " " + info + " " + sizeToString(size) - + QString(" -> %1x%2 ").arg(widthNew).arg(heightNew)); - convert(source, target, width, height, widthNew, heightNew, m_quality); - struct stat info; - if (stat(target.toUtf8().constData(), &info) == 0) - m_mainWindows->logAppendLast(sizeToString(info.st_size) + " "); + bool doConvert = false; + int widthNew, heightNew; + if (abs(width - height) < 5){ + // Square format: + doConvert = width > m_squareWidth; + if (doConvert) + widthNew = heightNew = m_squareWidth; + }else if (width > height){ + // Landscape: + doConvert = width > m_landscapeWidth || height > m_landscapeHeight; + if (doConvert){ + if (width > m_landscapeWidth && m_landscapeWidth > 0){ + widthNew = m_landscapeWidth; + heightNew = height * m_landscapeWidth / width; + }else{ + heightNew = m_landscapeHeight; + widthNew = width * m_landscapeHeight / height; + } + } + }else{ + // Portrait + doConvert = width > m_portraitWidth || height > m_portraitHeight; + if (doConvert){ + if (width > m_portraitWidth && m_portraitWidth > 0){ + widthNew = m_portraitWidth; + heightNew = height * m_portraitWidth / width; + }else{ + heightNew = m_portraitHeight; + widthNew = width * m_portraitHeight / height; + } + } + } + log( + source + " " + info + " " + sizeToString(size) + + QString(" -> %1x%2 ").arg(widthNew).arg(heightNew)); + convert(source, target, width, height, widthNew, heightNew, m_quality); + struct stat info; + if (stat(I18N::s2b(target).constData(), &info) == 0) + m_mainWindows->logAppendLast(sizeToString(info.st_size) + " "); } m_mainWindows->logAppendLast( - QString("").sprintf("%.3f sec", - double(clock() - start) / CLOCKS_PER_SEC)); + QString("").sprintf("%.3f sec", + double(clock() - start) / CLOCKS_PER_SEC)); } /** @@ -287,7 +287,7 @@ bool Converter::error(const QString& message){ * @return true */ bool Converter::log(const QString& message){ - printf("%s\n", message.toUtf8().constData()); + printf("%s\n", I18N::s2b(message).constData()); m_mainWindows->log(message); return true; } @@ -311,24 +311,24 @@ bool Converter::readProperties(const QString& name, int& width, int& height, QByteArray output; bool rc = false; while (process.waitForReadyRead()){ - output = process.readAll(); - QRegularExpressionMatch match = m_imageInfo->match(output); - if (!match.hasMatch()) - error( - QObject::tr("I am confused (wrong image data):\n%1\nExpected: %2").arg( - output.constData()).arg(m_imageInfo->pattern())); - else{ - width = match.captured(m_groupWidth).toInt(); - height = match.captured(m_groupHeight).toInt(); - rc = true; - info = QString("%1x%2").arg(width).arg(height); - break; - } + output = process.readAll(); + QRegularExpressionMatch match = m_imageInfo->match(output); + if (!match.hasMatch()) + error( + QObject::tr("I am confused (wrong image data):\n%1\nExpected: %2").arg( + output.constData()).arg(m_imageInfo->pattern())); + else{ + width = match.captured(m_groupWidth).toInt(); + height = match.captured(m_groupHeight).toInt(); + rc = true; + info = QString("%1x%2").arg(width).arg(height); + break; + } } output = process.readAll(); output = process.readAllStandardError(); if (!output.isEmpty()) - error(output); + error(output); process.close(); return rc; } @@ -345,49 +345,49 @@ void Converter::run(){ QString msg; int no = 0; try{ - if (!m_dir.exists()) - error( - QObject::tr("Directory does not exist: ") + m_dir.absolutePath()); - if (!m_targetDir.exists()){ - QString parentName = m_targetDir.path(); - QString subdir = m_targetDir.dirName(); - QDir parent(m_targetDir.path()); - parent.cdUp(); - parent.mkdir(subdir); - } - if (!m_targetDir.exists()){ - error( - QObject::tr("Cannot create the target directory: ") - + m_targetDir.absolutePath()); - } - changeState(Converter::STATE_STARTING, ""); - m_shouldStop = false; - QDirIterator it(m_dir.absolutePath()); - QRegExp regExpr(m_sourcePattern, Qt::CaseInsensitive, QRegExp::Wildcard); - while (it.hasNext()){ - if (m_shouldStop){ - log(QObject::tr("Canceled by the user")); - break; - } - it.next(); - if (it.fileInfo().isDir()) - continue; - QString node = it.fileName(); - if (regExpr.indexIn(node) >= 0){ - no++; - QString path = m_dir.absoluteFilePath(node); - qint64 length = it.fileInfo().size(); - QString nodeTarget = ReQStringUtil::replaceExtension(node, - "." + m_targetType); - QString target = m_targetDir.absoluteFilePath(nodeTarget); - convertOneFile(path, target, length); - } - } - changeState(Converter::STATE_SUB_TASK_STOPPED, msg); + if (!m_dir.exists()) + error( + QObject::tr("Directory does not exist: ") + m_dir.absolutePath()); + if (!m_targetDir.exists()){ + QString parentName = m_targetDir.path(); + QString subdir = m_targetDir.dirName(); + QDir parent(m_targetDir.path()); + parent.cdUp(); + parent.mkdir(subdir); + } + if (!m_targetDir.exists()){ + error( + QObject::tr("Cannot create the target directory: ") + + m_targetDir.absolutePath()); + } + changeState(Converter::STATE_STARTING, ""); + m_shouldStop = false; + QDirIterator it(m_dir.absolutePath()); + QRegExp regExpr(m_sourcePattern, Qt::CaseInsensitive, QRegExp::Wildcard); + while (it.hasNext()){ + if (m_shouldStop){ + log(QObject::tr("Canceled by the user")); + break; + } + it.next(); + if (it.fileInfo().isDir()) + continue; + QString node = it.fileName(); + if (regExpr.indexIn(node) >= 0){ + no++; + QString path = m_dir.absoluteFilePath(node); + qint64 length = it.fileInfo().size(); + QString nodeTarget = ReQStringUtil::replaceExtension(node, + "." + m_targetType); + QString target = m_targetDir.absoluteFilePath(nodeTarget); + convertOneFile(path, target, length); + } + } + changeState(Converter::STATE_SUB_TASK_STOPPED, msg); } catch (ConverterException exc){ - log( - QObject::tr("Execution stopped because of error(s): ") - + exc.message()); + log( + QObject::tr("Execution stopped because of error(s): ") + + exc.message()); } msg = QObject::tr("%1 file(s) converted").arg(no); changeState(Converter::STATE_READY, msg); @@ -404,16 +404,16 @@ QString findScript(const QString& node){ static QString rc; if (rc.isEmpty()){ - QDir dir = QDir::current(); - QFile scriptFile(dir.filePath(node)); - if (!scriptFile.exists()){ - extern char** g_argv; - dir.setPath(g_argv[0]); - dir.cdUp(); - scriptFile.setFileName(dir.filePath(node)); - } - if (scriptFile.exists()) - rc = scriptFile.fileName(); + QDir dir = QDir::current(); + QFile scriptFile(dir.filePath(node)); + if (!scriptFile.exists()){ + extern char** g_argv; + dir.setPath(g_argv[0]); + dir.cdUp(); + scriptFile.setFileName(dir.filePath(node)); + } + if (scriptFile.exists()) + rc = scriptFile.fileName(); } return rc; } @@ -426,13 +426,13 @@ QString findScript(const QString& node){ QString sizeToString(qint64 size){ QString rc; if (size < 10 * 1024) - rc.sprintf("%d Bytes", (int) size); + rc.sprintf("%d Bytes", (int) size); else if (size < qint64(10 * 1024 * 1024)) - rc.sprintf("%d KiBytes", (int) (size / 1024)); + rc.sprintf("%d KiBytes", (int) (size / 1024)); else if (size < qint64(10 * 1024 * 1024) * 1024) - rc.sprintf("%d MiBytes", (int) (size / 1024 / 1024)); + rc.sprintf("%d MiBytes", (int) (size / 1024 / 1024)); else - rc.sprintf("%d GiBytes", (int) (size / 1024 / 1024 / 1024)); + rc.sprintf("%d GiBytes", (int) (size / 1024 / 1024 / 1024)); return rc; } diff --git a/appl/reprime/Prime.cpp b/appl/reprime/Prime.cpp index 781b48d..75b23e2 100644 --- a/appl/reprime/Prime.cpp +++ b/appl/reprime/Prime.cpp @@ -34,7 +34,7 @@ Prime::~Prime() { void toFile(const char* prefix, int64_t* primes, int count){ QByteArray fn = QByteArray(prefix) + "." + QDateTime::currentDateTime().toLocalTime() - .toString("yyyy.MM.dd_hh_mm_ss").toUtf8() + ".txt"; + .toString("yyyy.MM.dd_hh_mm_ss").toLatin1() + ".txt"; FILE* fp = fopen(fn.constData(), "w"); if (fp != NULL){ fprintf(stderr, "Result in %s\n", fn.constData()); diff --git a/base/ReByteStorage.cpp b/base/ReByteStorage.cpp index d15f2f8..b8d990f 100644 --- a/base/ReByteStorage.cpp +++ b/base/ReByteStorage.cpp @@ -43,12 +43,12 @@ * @param bufferSize the size of one buffer */ ReByteStorage::ReByteStorage(int bufferSize) : - m_bufferSize(bufferSize), - m_buffer(NULL), - m_rest(0), - m_freePosition(NULL), - m_summarySize(0), - m_buffers(0) { + m_bufferSize(bufferSize), + m_buffer(NULL), + m_rest(0), + m_freePosition(NULL), + m_summarySize(0), + m_buffers(0) { } /** @@ -79,8 +79,8 @@ ReByteStorage::~ReByteStorage() { */ char* ReByteStorage::allocBuffer(int size) { m_rest = - size + sizeof(uint8_t*) <= (size_t) m_bufferSize ? - m_bufferSize : size + sizeof(uint8_t*); + size + sizeof(uint8_t*) <= (size_t) m_bufferSize ? + m_bufferSize : size + sizeof(uint8_t*); m_summarySize += m_rest; m_buffers++; uint8_t* rc = new uint8_t[m_rest]; @@ -119,7 +119,7 @@ const char* ReByteStorage::allocateChars(const char* source, int size) { * @return a copy of the source string. The copy ends always with '\0' */ const char* ReByteStorage::allocUtf8(const ReString& source) { - const char* rc = allocateChars(source.toUtf8().constData()); + const char* rc = allocateChars(I18N::s2b(source).constData()); return rc; } @@ -132,8 +132,8 @@ const char* ReByteStorage::allocUtf8(const ReString& source) { */ uint8_t* ReByteStorage::allocateBytes(int size) { uint8_t* rc = - size <= m_rest ? - m_freePosition : reinterpret_cast(allocBuffer(size)); + size <= m_rest ? + m_freePosition : reinterpret_cast(allocBuffer(size)); m_freePosition += size; m_rest -= size; return rc; diff --git a/base/ReFile.cpp b/base/ReFile.cpp index 42be77b..2a3dc31 100644 --- a/base/ReFile.cpp +++ b/base/ReFile.cpp @@ -50,8 +50,8 @@ int memicmp(const void* str1, const void* str2, size_t length) { * Constructor. */ ReLines::ReLines() : - QStringList(), - m_empty() { + QStringList(), + m_empty() { } /** * Destructor. @@ -107,8 +107,8 @@ bool ReFile::deleteTree(const QString& path, bool withBase, ReLogger* logger) { if (dir.exists(path)) { QFileInfo info; QStringList names = dir.entryList( - QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs - | QDir::Files); + QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs + | QDir::Files); QStringList::const_iterator it; for (it = names.constBegin(); it != names.constEnd(); ++it) { QString full(path); @@ -117,28 +117,28 @@ bool ReFile::deleteTree(const QString& path, bool withBase, ReLogger* logger) { if (info.isDir()) { if (!deleteTree(full, true, logger)) rc = false; - else if (rmdir(full.toUtf8()) != 0) { + else if (rmdir(I18N::s2b(full)) != 0) { rc = false; if (logger != NULL) logger->logv(LOG_ERROR, LOC_DELETE_TREE_1, - "cannot delete directory (%d): %s", errno, - full.toUtf8().constData()); + "cannot delete directory (%d): %s", errno, + I18N::s2b(full).constData()); } } else { if (!QFile::remove(full)) { rc = false; if (logger != NULL) logger->logv(LOG_ERROR, LOC_DELETE_TREE_2, - "cannot delete file (%d): %s", errno, - full.toUtf8().constData()); + "cannot delete file (%d): %s", errno, + I18N::s2b(full).constData()); } } } } - if (withBase && (rmdir(path.toUtf8())) != 0) { + if (withBase && (rmdir(I18N::s2b(path))) != 0) { rc = false; logger->logv(LOG_ERROR, LOC_DELETE_TREE_3, - "cannot delete directory (%d): %s", errno, path.toUtf8().constData()); + "cannot delete directory (%d): %s", errno, I18N::s2b(path).constData()); } return rc; } @@ -194,7 +194,7 @@ void ReLines::insertLines(int lineNo, const QString& text, bool withUndo) { * false: undo is impossible */ void ReLines::insertPart(int lineNo, int col, const QString& text, - bool withUndo) { + bool withUndo) { if (lineNo >= 0 && lineNo < lineCount() && col >= 0) { if (withUndo) storeInsertPart(lineNo, col, text.length()); @@ -235,7 +235,7 @@ void ReLines::insertText(int lineNo, int col, const QString& text) { if (lastEoLn != endOfLine) { int oldCount = lineCount(); insertLines(lineNo + 1, - text.mid(endOfLine + 1, lastEoLn - endOfLine), true); + text.mid(endOfLine + 1, lastEoLn - endOfLine), true); newLines = lineCount() - oldCount; } if (lastEoLn != text.length() - 1) { @@ -408,26 +408,26 @@ void ReLines::undo(int& lineNo, int& col) { * @param logger the logger */ ReFile::ReFile(const QString& filename, bool readOnly, ReLogger* logger) : - ReLineSource(), - ReLines(), - m_endOfLine(), - m_filename(filename), - m_file(filename), - m_block(NULL), - // in 32-bit address space we allocate only 10 MByte, in 64-bit environments 100 GByte - m_blocksize( - sizeof(void*) <= 4 ? - 10 * 1024 * 1024ll : 0x100ll * 0x10000 * 0x10000), - m_blockOffset(0), - m_filesize(0), - m_startOfLine(NULL), - m_lineLength(0), - m_lineOffset(0), - m_currentLineNo(0), - m_maxLineLength(0x10000), - m_content(), - m_readOnly(readOnly), - m_logger(logger) { + ReLineSource(), + ReLines(), + m_endOfLine(), + m_filename(filename), + m_file(filename), + m_block(NULL), + // in 32-bit address space we allocate only 10 MByte, in 64-bit environments 100 GByte + m_blocksize( + sizeof(void*) <= 4 ? + 10 * 1024 * 1024ll : 0x100ll * 0x10000 * 0x10000), + m_blockOffset(0), + m_filesize(0), + m_startOfLine(NULL), + m_lineLength(0), + m_lineOffset(0), + m_currentLineNo(0), + m_maxLineLength(0x10000), + m_content(), + m_readOnly(readOnly), + m_logger(logger) { #if defined __linux__ setEndOfLine("\n"); #elif defined __WIN32__ @@ -484,7 +484,7 @@ QString ReFile::filename() const { * false: a line has not been found */ bool ReFile::findLine(const char* toFind, bool ignoreCase, int& lineNo, - QString* line) { + QString* line) { bool rc = false; int length; int sourceLength = strlen(toFind); @@ -495,14 +495,14 @@ bool ReFile::findLine(const char* toFind, bool ignoreCase, int& lineNo, const char* ptr = start; int restLength = length - sourceLength + 1; while (restLength > 0 - && (ptr = reinterpret_cast( - ignoreCase ? - memchr(start, first, restLength) : - memichr(start, first, restLength))) != NULL) { + && (ptr = reinterpret_cast( + ignoreCase ? + memchr(start, first, restLength) : + memichr(start, first, restLength))) != NULL) { if (( - ignoreCase ? - _memicmp(ptr, toFind, sourceLength) : - memcmp(ptr, toFind, sourceLength)) == 0) { + ignoreCase ? + _memicmp(ptr, toFind, sourceLength) : + memcmp(ptr, toFind, sourceLength)) == 0) { rc = true; lineNo = m_currentLineNo; QByteArray buffer(m_startOfLine, m_lineLength); @@ -532,8 +532,8 @@ bool ReFile::findLine(const char* toFind, bool ignoreCase, int& lineNo, * false: a line has not been found */ bool ReFile::findLine(const QString& includePattern, bool includeIsRegExpr, - bool includeIgnoreCase, const QString& excludePattern, - bool excludeIsRegExpr, bool excludeIgnoreCase, int& lineNo, QString* line) { + bool includeIgnoreCase, const QString& excludePattern, + bool excludeIsRegExpr, bool excludeIgnoreCase, int& lineNo, QString* line) { bool rc = false; if (line != NULL) *line = ""; @@ -579,9 +579,9 @@ char* ReFile::nextLine(int& length) { if (m_currentLineNo == 65639) m_currentLineNo += 0; rc = m_startOfLine = remap(m_lineOffset += m_lineLength, - m_maxLineLength, lineLength); + m_maxLineLength, lineLength); const char* ptr = reinterpret_cast(memchr(rc, '\n', - lineLength)); + lineLength)); if (ptr != NULL) lineLength = ptr - rc + 1; length = m_lineLength = lineLength; @@ -703,7 +703,7 @@ char* ReFile::remap(int64_t offset, int size, int& length) { size = m_filesize - offset; // Note: size <= m_blocksize if (m_block != NULL && offset >= m_blockOffset - && offset + size <= m_blockOffset + m_blocksize) { + && offset + size <= m_blockOffset + m_blocksize) { // new block is inside the internal block: // no remapping needed rc = m_block + (offset - m_blockOffset); @@ -718,7 +718,7 @@ char* ReFile::remap(int64_t offset, int size, int& length) { if (m_block != NULL) m_file.unmap(reinterpret_cast(m_block)); m_block = reinterpret_cast(m_file.map(m_blockOffset, - m_blocksize)); + m_blocksize)); rc = m_block + (offset - m_blockOffset); length = m_blocksize - (rc - m_block); if (length > size) @@ -769,7 +769,7 @@ void ReFile::setFilename(const QString &filename) { * @return the name of an existing directory */ QByteArray ReFile::tempDir(const char* node, const char* parent, - bool withSeparator) { + bool withSeparator) { #if defined __linux__ QByteArray temp("/tmp"); static const char* firstVar = "TMP"; @@ -816,7 +816,7 @@ QByteArray ReFile::tempDir(const char* node, const char* parent, * @return the full name of a temporary file */ QByteArray ReFile::tempFile(const char* node, const char* parent, - bool deleteIfExists) { + bool deleteIfExists) { QByteArray rc(tempDir(parent)); if (!rc.endsWith('/')) rc += '/'; @@ -843,7 +843,7 @@ bool ReFile::write(const QString& filename) { int maxIx = length() - 1; for (int ix = 0; ix <= maxIx; ix++) { const QString& line = at(ix); - buffer = line.toUtf8(); + buffer = I18N::s2b(line); outputFile.write(buffer.constData(), buffer.length()); outputFile.write(m_endOfLine.constData(), m_endOfLine.length()); } @@ -864,7 +864,7 @@ bool ReFile::write(const QString& filename) { * @param mode file write mode: "w" (write) or "a" (append) */ void ReFile::writeToFile(const char* filename, const char* content, - size_t contentLength, const char* mode) { + size_t contentLength, const char* mode) { FILE* fp = fopen(filename, mode); if (fp != NULL) { if (contentLength == (size_t) - 1) @@ -878,12 +878,12 @@ void ReFile::writeToFile(const char* filename, const char* content, * Constructor. */ ReUndoList::ReUndoList() : - m_list(), - m_current(NULL), - m_lastLine(-1), - m_lastPosition(-1), - m_maxUndoSize(10 * 1024 * 1024), - m_currentUndoSize(0) { + m_list(), + m_current(NULL), + m_lastLine(-1), + m_lastPosition(-1), + m_maxUndoSize(10 * 1024 * 1024), + m_currentUndoSize(0) { } /** @@ -1022,7 +1022,7 @@ void ReUndoList::storeSplit(int lineNo, int col) { * @param list the list containing the lines for extracting the line content */ void ReUndoList::storeRemoveLines(int lineNo, int count, - const QStringList& list) { + const QStringList& list) { qint64 size = 0; // Calculate the additional space for (int ii = lineNo + count - 1; ii >= lineNo; ii--) diff --git a/base/ReFileUtils.cpp b/base/ReFileUtils.cpp index ed04c23..6d99c1e 100644 --- a/base/ReFileUtils.cpp +++ b/base/ReFileUtils.cpp @@ -100,12 +100,12 @@ bool ReFileUtils::deleteTree(const QString& path, bool withBase, if (info.isDir()) { if (!deleteTree(full, false, logger)) rc = false; - else if (rmdir(full.toUtf8()) != 0) { + else if (rmdir(I18N::s2b(full)) != 0) { rc = false; if (logger != NULL) logger->logv(LOG_ERROR, LOC_DELETE_TREE_1, "cannot delete directory (%d): %s", errno, - full.toUtf8().constData()); + I18N::s2b(full).constData()); } } else { if (!QFile::remove(full)) { @@ -113,15 +113,15 @@ bool ReFileUtils::deleteTree(const QString& path, bool withBase, if (logger != NULL) logger->logv(LOG_ERROR, LOC_DELETE_TREE_2, "cannot delete file (%d): %s", errno, - full.toUtf8().constData()); + I18N::s2b(full).constData()); } } } } - if (withBase && (rmdir(path.toUtf8())) != 0) { + if (withBase && (rmdir(I18N::s2b(path))) != 0) { rc = false; logger->logv(LOG_ERROR, LOC_DELETE_TREE_3, - "cannot delete directory (%d): %s", errno, path.toUtf8().constData()); + "cannot delete directory (%d): %s", errno, I18N::s2b(path).constData()); } return rc; } @@ -377,7 +377,7 @@ QByteArray ReFileUtils::cleanPath(const char* path) { * @return the path without duplicated separators and "." and ".." */ QString ReFileUtils::cleanPath(const QString& path) { - return (QString) cleanPath(path.toUtf8().constData()); + return (QString) cleanPath(I18N::s2b(path).constData()); } /** diff --git a/base/ReLogger.cpp b/base/ReLogger.cpp index fb794e5..697eba6 100644 --- a/base/ReLogger.cpp +++ b/base/ReLogger.cpp @@ -302,7 +302,7 @@ bool ReLogger::log(ReLoggerLevel level, int location, * @return true: for chaining */ bool ReLogger::log(ReLoggerLevel level, int location, const ReString& message) { - return log(level, location, message.toUtf8().data()); + return log(level, location, I18N::s2b(message).data()); } /** diff --git a/base/ReProgramArgs.cpp b/base/ReProgramArgs.cpp index 81ec08d..d978337 100644 --- a/base/ReProgramArgs.cpp +++ b/base/ReProgramArgs.cpp @@ -41,7 +41,7 @@ ReOptionException::ReOptionException(ReProgramArgs* caller, const char* format, ReOptionException::ReOptionException(ReProgramArgs* caller, const QString& message) : ReException() { - m_message = message.toUtf8(); + m_message = I18N::s2b(message); if (caller != NULL) caller->setLastError(m_message); } @@ -471,11 +471,11 @@ const char* ReProgramArgs::getString(const char* name, QByteArray& buffer) { */ void ReProgramArgs::help(const char* message, bool issueLastError, QByteArrayList& lines) const { - lines.append(m_usage); + lines = m_usage; lines.append(""); if (m_options.size() > 0) { - lines.append(QObject::tr(":").toUtf8()); + lines.append(QObject::tr(":").toLatin1()); } QByteArray line; QByteArray param; @@ -485,27 +485,27 @@ void ReProgramArgs::help(const char* message, bool issueLastError, param.resize(0); switch (opt->m_type) { case DT_INT: - param.append(QObject::tr("")); + param = I18N::s2b(QObject::tr("")); break; case DT_STRING: - param.append(QObject::tr("")); + param = I18N::s2b(QObject::tr("")); break; case DT_STRING_EMPTY: - param.append(QObject::tr("[]")); + param = I18N::s2b(QObject::tr("[]")); break; default: break; } - if (opt->m_shortName != HIDDEN_SHORT_NAME) { + if (opt->m_shortName != UNDEF_SHORT_NAME) { line.append("-").append(opt->m_shortName); - line.append(param).append(' ').append(QObject::tr(" or ").toUtf8()); + line.append(param).append(' ').append(I18N::s2b(QObject::tr(" or "))); } line.append("--").append(opt->m_longName); if (param.length() > 0) { line.append("=", -1).append(param.constData(), -1); if (opt->m_type != DT_STRING || ! opt->m_defaultValue.isEmpty()) { - line.append(QObject::tr(" Default value: ").toUtf8()); + line.append(I18N::s2b(QObject::tr(" Default value: "))); if (opt->m_type == DT_STRING) line.append('\''); line.append(opt->m_defaultValue); @@ -517,9 +517,10 @@ void ReProgramArgs::help(const char* message, bool issueLastError, line.resize(0); line.append(PREFIX_LINE_OPTION).append(opt->m_description); lines.append(line.constData()); + line.resize(0); } if (m_examples.count() > 0) { - lines.append(QObject::tr("Example(s):").toUtf8()); + lines.append(I18N::s2b(QObject::tr("Example(s):"))); lines.append(m_examples); } if (issueLastError && m_lastError.length() > 0) { diff --git a/base/ReProgramArgs.hpp b/base/ReProgramArgs.hpp index ce5da5e..ba70310 100644 --- a/base/ReProgramArgs.hpp +++ b/base/ReProgramArgs.hpp @@ -46,14 +46,14 @@ class ReProgramArgs { static QByteArray UNDEFINED_STRING; public: enum DataType { - DT_UNDEF = 0, - DT_INT = 'i', - DT_BOOL = 'b', - DT_STRING = 's', - DT_STRING_EMPTY = 'S' + DT_UNDEF, + DT_INT, + DT_BOOL, + DT_STRING, + DT_STRING_EMPTY }; enum { - HIDDEN_SHORT_NAME = 2 + UNDEF_SHORT_NAME = 0 }; public: ReProgramArgs(const char* usageList[], const char* examples[] = NULL); diff --git a/base/ReQStringUtils.cpp b/base/ReQStringUtils.cpp index 1f6e4f1..8c2c6be 100644 --- a/base/ReQStringUtils.cpp +++ b/base/ReQStringUtils.cpp @@ -10,6 +10,8 @@ */ #include "base/rebase.hpp" +I18N::CharSet I18N::m_standardCharSet = I18N::SYSTEM; + const QStringList ReQStringUtils::m_emptyList; const QString ReQStringUtils::m_empty; diff --git a/base/ReQStringUtils.hpp b/base/ReQStringUtils.hpp index ed13d7a..ff14a59 100644 --- a/base/ReQStringUtils.hpp +++ b/base/ReQStringUtils.hpp @@ -11,6 +11,29 @@ #ifndef REQSTRINGUTILS_HPP #define REQSTRINGUTILS_HPP +/** + * A pure static class for internationalization. + */ +class I18N { +public: + enum CharSet { SYSTEM, UTF8, LATIN }; +public: + /** Converts a QString into a QByteArray. + * The character set is a global setting: m_standardCharSet. + * @param source the string to convert + * @return the converted string + */ + inline static QByteArray s2b(const QString& source){ + if (m_standardCharSet == UTF8) + return source.toUtf8(); + else if (m_standardCharSet == LATIN) + return source.toLatin1(); + else + return source.toLocal8Bit(); + } +public: + static CharSet m_standardCharSet; +}; /** * Some useful static functions handling QString instances. diff --git a/base/ReTest.cpp b/base/ReTest.cpp index ab5007c..be68737 100644 --- a/base/ReTest.cpp +++ b/base/ReTest.cpp @@ -132,7 +132,7 @@ bool ReTest::assertEquals(qreal expected, qreal current, const char* file, */ bool ReTest::assertEquals(const char* expected, const ReString& current, const char* file, int lineNo) { - bool equal = assertEquals(expected, current.toUtf8().constData(), file, + bool equal = assertEquals(expected, I18N::s2b(current).constData(), file, lineNo); return equal; } @@ -150,8 +150,8 @@ bool ReTest::assertEquals(const char* expected, const ReString& current, */ bool ReTest::assertEquals(const ReString& expected, const ReString& current, const char* file, int lineNo) { - bool equal = assertEquals(expected.toUtf8().constData(), - current.toUtf8().constData(), file, lineNo); + bool equal = assertEquals(I18N::s2b(expected).constData(), + I18N::s2b(current).constData(), file, lineNo); return equal; } diff --git a/cunit/cuReFileSystem.cpp b/cunit/cuReFileSystem.cpp index 41d027d..1ac0312 100644 --- a/cunit/cuReFileSystem.cpp +++ b/cunit/cuReFileSystem.cpp @@ -31,9 +31,9 @@ protected: QString node; for (int ix = 1; ix <= 7; ix++) { node.sprintf("test%d.txt", ix); - QByteArray fn = ReFileUtils::tempFile(node.toUtf8().constData(), + QByteArray fn = ReFileUtils::tempFile(I18N::s2b(node).constData(), "refilesystem", false); - ReFileUtils::writeToFile(fn.constData(), node.toUtf8().constData()); + ReFileUtils::writeToFile(fn.constData(), I18N::s2b(node).constData()); fn = m_subDir1; fn.append("text").append(QByteArray::number(ix)); ReFileUtils::writeToFile(fn.constData(), fn.constData()); @@ -183,7 +183,7 @@ protected: QString path = fsTarget.fullName(metaSource.m_node); checkT(path.indexOf("dir.01")); struct stat info; - checkEqu(0, stat(path.toUtf8().constData(), &info)); + checkEqu(0, stat(I18N::s2b(path).constData(), &info)); } void testReOSPermissions(){ ReOSPermissions p1; diff --git a/cunit/cuReProgArgs.cpp b/cunit/cuReProgArgs.cpp new file mode 100644 index 0000000..c337dbc --- /dev/null +++ b/cunit/cuReProgArgs.cpp @@ -0,0 +1,184 @@ +/* + * cuReProgArguments.cpp + * + * License: Public Domain + * You can use and modify this file without any restriction. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib + */ + +/** @file + * @brief Unit test of the QByteArray tools. + */ +#include "base/rebase.hpp" +/** + * @brief Unit test for ReProgArguments. + */ +class TestReProgArgs: public ReTest { +public: + TestReProgArgs() : + ReTest("ReProgArgs") { + doIt(); + } + +public: + void testBase(){ + ReProgramArgs args("usage: example prog", "example -a"); + args.addBool("boolArg", "a bool arg", 'b', "bool-arg", false); + args.addInt("intArg", "integer arg", 'i', "int-arg", 99); + args.addString("stringArg", "string argument", 's', "string-arg", true, ""); + const char* arguments[] = { "example" }; + args.init(1, arguments); + checkF(args.getBool("boolArg")); + checkEqu(99, args.getInt("intArg")); + QByteArray buffer = "123"; + checkEqu("", args.getString("stringArg", buffer)); + checkEqu("", buffer); + } + + void testBool(){ + ReProgramArgs args("usage: example prog", "example -a"); + args.addBool("trueArg", "a bool arg", 't', "true-arg", false); + args.addBool("falseArg", "a bool arg", 'f', "false-arg", true); + args.addBool("trueArg2", "a bool arg", 0, "true-arg2", false); + args.addBool("falseArg2", "a bool arg", 0, "false-arg2", true); + args.addBool("trueArg3", "a bool arg", 0, "true-arg3", false); + args.addBool("falseArg3", "a bool arg", 0, "false-arg3", true); + args.addBool("trueArg4", "a bool arg", 0, "true-arg4", false); + args.addBool("falseArg4", "a bool arg", 0, "false-arg4", true); + const char* arguments[] = { + "example", + "--true-arg4=n", "--false-arg3=y", + "--true-arg3=y", "--false-arg3=n", + "--true-arg2", "--false-arg2", + "-t", "-f", + NULL + }; + args.init(9, arguments); + checkT(args.getBool("trueArg")); + checkF(args.getBool("falseArg")); + checkT(args.getBool("trueArg2")); + checkF(args.getBool("falseArg2")); + checkT(args.getBool("trueArg3")); + checkF(args.getBool("falseArg3")); + checkF(args.getBool("trueArg4")); + checkT(args.getBool("falseArg4")); + } + void testInt(){ + ReProgramArgs args("usage: example prog", "example -a"); + args.addInt("intArg", "an int arg", 'i', "arg", 4711); + args.addInt("intArg2", "an int arg", 0, "arg2", 4712); + const char* arguments[] = { + "example", + "-i", "2244", + "--arg2=3355", + NULL + }; + args.init(4, arguments); + checkEqu(2244, args.getInt("intArg")); + checkEqu(3355, args.getInt("intArg2")); + + ReProgramArgs args2("usage: example prog", "example -a"); + args2.addInt("intArg", "an int arg", 'i', "arg2", 4711); + const char* arguments2[] = { + "example", + "--arg2", + NULL + }; + try { + args2.init(2, arguments2); + error("exception expected: missing parameter"); + } catch(ReOptionException e){ + checkT(e.getMessage().indexOf("arg2") > 0); + } + } + void testString(){ + ReProgramArgs args("usage: example prog", "example -a"); + args.addString("stringArg", "a string arg", 's', "arg", false, "abc"); + args.addString("stringArg2", "a string arg", 0, "arg2", true, "bcd"); + args.addString("stringArg3", "a string arg", 0, "arg3", true, "def"); + const char* arguments[] = { + "example", + "-s", "wow", + "--arg2=1 2 3", + "--arg3=", + NULL + }; + args.init(5, arguments); + QByteArray buffer; + checkEqu("wow", args.getString("stringArg", buffer)); + checkEqu("1 2 3", args.getString("stringArg2", buffer)); + checkEqu("", args.getString("stringArg3", buffer)); + + ReProgramArgs args2("usage: example prog", "example -a"); + args2.addString("stringArg", "a string arg", 'i', "arg2", false, "king"); + const char* arguments2[] = { + "example", + "--arg2", + NULL + }; + try { + args2.init(2, arguments2); + error("exception expected: missing parameter"); + } catch(ReOptionException e){ + checkT(e.getMessage().indexOf("arg2") > 0); + } + ReProgramArgs args3("usage: example prog", "example -a"); + args3.addString("stringArg", "a string arg", 0, "arg", true, NULL); + args3.addString("stringArg2", "a string arg", 'i', "arg2", false, "king"); + const char* arguments3[] = { + "example", + "--arg=", + "--arg2=", + NULL + }; + try { + args3.init(3, arguments3); + error("exception expected: empty string is not allowed"); + } catch(ReOptionException e){ + checkT(e.getMessage().indexOf("arg2") > 0); + } + } + void testHelp(){ + ReProgramArgs args("usage: example prog", "example -a"); + args.addBool("boolArg", "a bool arg", 'b', "bool-arg", false); + args.addInt("intArg", "integer arg", 'i', "int-arg", 99); + args.addString("stringArg", "string argument", 's', "string-arg", true, ""); + const char* arguments[] = { "example" }; + QByteArrayList list; + args.help("dummy error", false, list); + QByteArray expected = "usage: example prog\n" + "\n" + ":\n" + "-b or --bool-arg\n" + " a bool arg\n" + "-i or --int-arg= Default value: 99\n" + " integer arg\n" + "-s[] or --string-arg=[] Default value: \n" + " string argument\n" + "Example(s):\n" + "example -a\n" + "+++ dummy error\n"; + checkEqu(expected, list.join('\n')); + } + virtual void run() { + try { + testHelp(); + testString(); + testInt(); + testBool(); + testBase(); + } catch (ReOptionException e){ + error(e.getMessage()); + } + log("ready"); + } +}; + + +void testReProgArgs() { + TestReProgArgs test; +} + diff --git a/expr/ReASTree.cpp b/expr/ReASTree.cpp index f30e785..f2e6ad7 100644 --- a/expr/ReASTree.cpp +++ b/expr/ReASTree.cpp @@ -65,9 +65,9 @@ enum { unsigned int ReASItem::m_nextId = 1; #define DEFINE_TABS(indent) \ - char tabs[32]; \ - memset(tabs, '\t', sizeof tabs); \ - tabs[(unsigned) indent < sizeof tabs ? indent : sizeof tabs - 1] = '\0' + char tabs[32]; \ + memset(tabs, '\t', sizeof tabs); \ + tabs[(unsigned) indent < sizeof tabs ? indent : sizeof tabs - 1] = '\0' /** * @brief Writes a map into a file. @@ -91,7 +91,7 @@ void dumpMap(ReWriter& writer, ReASMapOfVariants& map, bool withEndOfLine) { for (it2 = sorted.begin(); it2 != sorted.end(); it2++) { ReASVariant* value = map[*it2]; writer.format("%c'%s':%s", first ? '{' : ',', (*it2).constData(), - value->toString().constData()); + value->toString().constData()); first = false; } if (first) @@ -114,10 +114,10 @@ void dumpMap(ReWriter& writer, ReASMapOfVariants& map, bool withEndOfLine) { * @param varList the values for the placeholders in the format. */ void ReASException::build(const ReSourcePosition* position, const char* format, - va_list varList) { + va_list varList) { char buffer[64000]; if (position != NULL) { - m_message = position->toString().toUtf8(); + m_message = I18N::s2b(position->toString()); m_message += ": "; } qvsnprintf(buffer, sizeof buffer, format, varList); @@ -132,8 +132,8 @@ void ReASException::build(const ReSourcePosition* position, const char* format, * @param ... the values for the placeholders in the format. */ ReASException::ReASException(const ReSourcePosition* position, - const char* format, ...) : - ReException("") { + const char* format, ...) : + ReException("") { va_list ap; va_start(ap, format); build(position, format, ap); @@ -144,7 +144,7 @@ ReASException::ReASException(const ReSourcePosition* position, * @brief Constructor. */ ReASException::ReASException() : - ReException("") { + ReException("") { } /** @class ReASVariant ReASTree.hpp "expr/ReASTree.hpp" @@ -158,10 +158,10 @@ ReASException::ReASException() : * @brief Constructor. */ ReASVariant::ReASVariant() : - m_variantType(VT_UNDEF), - m_flags(VF_UNDEF), - // m_value(), - m_class(NULL) { + m_variantType(VT_UNDEF), + m_flags(VF_UNDEF), + // m_value(), + m_class(NULL) { } /** * @brief Destructor. @@ -176,10 +176,10 @@ ReASVariant::~ReASVariant() { * @param source the source to copy */ ReASVariant::ReASVariant(const ReASVariant& source) : - m_variantType(source.m_variantType), - m_flags(source.m_flags), - // m_value - m_class(source.m_class) { + m_variantType(source.m_variantType), + m_flags(source.m_flags), + // m_value + m_class(source.m_class) { copyValue(source); } @@ -301,7 +301,7 @@ const ReASClass* ReASVariant::getClass() const { qreal ReASVariant::asFloat() const { if (m_variantType != VT_FLOAT) throw ReException("ReASVariant::asNumber: not a number: %d", - m_variantType); + m_variantType); return m_value.m_float; } /** @@ -314,7 +314,7 @@ qreal ReASVariant::asFloat() const { int ReASVariant::asInt() const { if (m_variantType != VT_INTEGER) throw ReException("ReASVariant::asInt: not an integer: %d", - m_variantType); + m_variantType); return m_value.m_int; } @@ -328,7 +328,7 @@ int ReASVariant::asInt() const { bool ReASVariant::asBool() const { if (m_variantType != VT_BOOL) throw ReException("ReASVariant::asBool: not a boolean: %d", - m_variantType); + m_variantType); return m_value.m_bool; } @@ -343,7 +343,7 @@ bool ReASVariant::asBool() const { void* ReASVariant::asObject(const ReASClass** clazz) const { if (m_variantType != VT_OBJECT) throw ReException("ReASVariant::asObject: not an object: %d", - m_variantType); + m_variantType); if (clazz != NULL) *clazz = m_class; return m_value.m_object; @@ -361,7 +361,7 @@ const QByteArray* ReASVariant::asString() const { if (clazz != ReASString::m_instance) { const QByteArray& name = clazz->name(); throw ReException("ReASVariant::asString: not a string: %s", - name.constData()); + name.constData()); } return rc; } @@ -469,10 +469,10 @@ void ReASVariant::setObject(void* object, const ReASClass* clazz) { * @param type the type of the instance */ ReASItem::ReASItem(ReASItemType type) : - m_id(m_nextId++), - m_nodeType(type), - m_flags(0), - m_position(NULL) { + m_id(m_nextId++), + m_nodeType(type), + m_flags(0), + m_position(NULL) { } /** * @brief Destructor. @@ -491,7 +491,7 @@ ReASItem::~ReASItem() { * false: otherwise */ bool ReASItem::checkAsCalculable(const char* description, - ReASClass* expectedClass, ReParser& parser) { + ReASClass* expectedClass, ReParser& parser) { RE_UNUSED(expectedClass); bool rc = true; if (!check(parser)) @@ -500,11 +500,11 @@ bool ReASItem::checkAsCalculable(const char* description, ReASCalculable* expr = dynamic_cast(this); if (expr == NULL) rc = error(LOC_ITEM_AS_INT_1, parser, "%s not calculable: %s", - description, nameOfItemType()); + description, nameOfItemType()); else if (expr->clazz() != ReASInteger::m_instance) rc = error(LOC_ITEM_AS_INT_2, parser, - "%s: wrong type %s instead of integer", description, - expr->clazz()->name().constData()); + "%s: wrong type %s instead of integer", description, + expr->clazz()->name().constData()); } return rc; } @@ -562,7 +562,7 @@ void ReASItem::error(ReLogger* logger, int location, const char* format, ...) { char buffer[1024]; int halfBufferSize = (sizeof buffer) / 2; qsnprintf(buffer, halfBufferSize, "id: %d [%s]:", m_id, - positionStr(buffer + halfBufferSize, halfBufferSize)); + positionStr(buffer + halfBufferSize, halfBufferSize)); int length = strlen(buffer); va_list ap; va_start(ap, format); @@ -622,11 +622,11 @@ bool ReASItem::checkStatementList(ReASItem* list, ReParser& parser) { rc = false; if (dynamic_cast(list) == NULL) rc = list->error(LOC_ITEM_STATEM_LIST_1, parser, - "not a statement: %s", list->nameOfItemType()); + "not a statement: %s", list->nameOfItemType()); ReASNode1* node = dynamic_cast(list); if (node == NULL) { list->error(LOC_ITEM_STATEM_LIST_1, parser, "not a node: %s", - list->nameOfItemType()); + list->nameOfItemType()); list = NULL; } else { list = node->child(); @@ -781,7 +781,7 @@ bool ReASItem::error(int location, ReParser& parser, const char* format, ...) { va_list varList; va_start(varList, format); parser.addMessage(ReParser::LT_ERROR, location, m_position, format, - varList); + varList); va_end(varList); return false; } @@ -799,7 +799,7 @@ bool ReASItem::error(int location, ReParser& parser, const char* format, ...) { bool ReASItem::ensureError(ReParser& parser, const char* info) { if (parser.errors() == 0) error(LOC_ITEM_FORCE_ERROR_1, parser, "lost error (internal error): %s", - info); + info); return false; } @@ -812,7 +812,7 @@ bool ReASItem::ensureError(ReParser& parser, const char* info) { * @brief Constructor. */ ReASCalculable::ReASCalculable() : - m_class(NULL) { + m_class(NULL) { } /** * @brief Returns the class of the node @@ -847,8 +847,8 @@ void ReASCalculable::setClass(ReASClass* clazz) { * */ ReASConstant::ReASConstant() : - ReASItem(AST_CONSTANT), - m_value() { + ReASItem(AST_CONSTANT), + m_value() { } /** @@ -881,7 +881,7 @@ bool ReASConstant::check(ReParser& parser) { void ReASConstant::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "const id: %d value: %s %s", m_id, - m_value.toString().constData(), positionStr(buffer, sizeof buffer)); + m_value.toString().constData(), positionStr(buffer, sizeof buffer)); } /** @@ -908,10 +908,10 @@ ReASVariant& ReASConstant::value() { * @brief Constructor. */ ReASListConstant::ReASListConstant() : - ReASNode1(AST_LIST_CONSTANT), - ReASCalculable() { + ReASNode1(AST_LIST_CONSTANT), + ReASCalculable() { m_value.setObject(ReASList::m_instance->newValueInstance(), - ReASList::m_instance); + ReASList::m_instance); } /** * @brief Returns the list. @@ -920,7 +920,7 @@ ReASListConstant::ReASListConstant() : */ ReASListOfVariants* ReASListConstant::list() { ReASListOfVariants* rc = static_cast(m_value.asObject( - NULL)); + NULL)); return rc; } @@ -954,7 +954,7 @@ bool ReASListConstant::check(ReParser& parser) { void ReASListConstant::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "listConst id: %d %s", m_id, - positionStr(buffer, sizeof buffer)); + positionStr(buffer, sizeof buffer)); QByteArray sValue = m_value.toString(8092); writer.writeIndented(indent + 1, sValue.constData()); @@ -983,9 +983,9 @@ ReASVariant& ReASListConstant::value() { * @brief ReASMapConstant::ReASMapConstant */ ReASMapConstant::ReASMapConstant() : - ReASNode1(AST_MAP_CONSTANT), - ReASCalculable(), - m_value() { + ReASNode1(AST_MAP_CONSTANT), + ReASCalculable(), + m_value() { m_value.setObject(new ReASMapOfVariants, ReASMap::m_instance); } @@ -1018,7 +1018,7 @@ bool ReASMapConstant::check(ReParser& parser) { void ReASMapConstant::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "mapConst id: %d %s", m_id, - positionStr(buffer, sizeof buffer)); + positionStr(buffer, sizeof buffer)); writer.indent(indent); dumpMap(writer, *map(), true); } @@ -1039,7 +1039,7 @@ ReASVariant& ReASMapConstant::value() { */ ReASMapOfVariants* ReASMapConstant::map() { ReASMapOfVariants* rc = static_cast(m_value.asObject( - NULL)); + NULL)); return rc; } @@ -1057,12 +1057,12 @@ ReASMapOfVariants* ReASMapConstant::map() { * @param attributes the attributes of the variable */ ReASNamedValue::ReASNamedValue(ReASClass* clazz, ReSymbolSpace* space, - const QByteArray& name, int attributes) : - ReASItem(AST_NAMED_VALUE), - m_name(name), - m_attributes(attributes), - m_symbolSpace(space), - m_variableNo(-1) { + const QByteArray& name, int attributes) : + ReASItem(AST_NAMED_VALUE), + m_name(name), + m_attributes(attributes), + m_symbolSpace(space), + m_variableNo(-1) { m_class = clazz; } @@ -1093,7 +1093,7 @@ void ReASNamedValue::calc(ReVMThread& thread) { thread.valueToTop(m_symbolSpace, m_variableNo); if (thread.tracing()) thread.vm()->traceWriter()->format("nVal %s=%.80s", m_name.constData(), - thread.topOfValues().toString().constData()); + thread.topOfValues().toString().constData()); } /** @@ -1116,8 +1116,8 @@ bool ReASNamedValue::check(ReParser& parser) { void ReASNamedValue::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "namedValue %s id: %d attr: 0x%x %s", - m_name.constData(), m_id, m_attributes, - positionStr(buffer, sizeof buffer)); + m_name.constData(), m_id, m_attributes, + positionStr(buffer, sizeof buffer)); } /** @@ -1158,8 +1158,8 @@ int ReASNamedValue::variableNo() const { * @param expression the expression to convert */ ReASConversion::ReASConversion(ReASItem* expression) : - ReASNode1(AST_CONVERSION), - m_conversion(C_UNDEF) { + ReASNode1(AST_CONVERSION), + m_conversion(C_UNDEF) { m_child = expression; m_position = expression->position(); } @@ -1194,7 +1194,7 @@ void ReASConversion::calc(ReVMThread& thread) { } if (thread.tracing()) thread.vm()->traceWriter()->format("(%s): %s", - m_class->name().constData(), value.toString().constData()); + m_class->name().constData(), value.toString().constData()); } /** @@ -1207,7 +1207,7 @@ void ReASConversion::calc(ReVMThread& thread) { * otherwise: the conversion type */ ReASConversion::Conversion ReASConversion::findConversion(ReASClass* from, - ReASClass* to) { + ReASClass* to) { Conversion rc = C_UNDEF; if (from == ReASFloat::m_instance) { if (to == ReASInteger::m_instance) @@ -1245,8 +1245,8 @@ bool ReASConversion::check(ReParser& parser) { rc = true; else parser.error(LOC_CONV_CHECK_1, - "invalid data type conversion: %s -> %s", - from->name().constData(), m_class->name().constData()); + "invalid data type conversion: %s -> %s", + from->name().constData(), m_class->name().constData()); } return rc; } @@ -1260,8 +1260,8 @@ bool ReASConversion::check(ReParser& parser) { void ReASConversion::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "conversion %s id: %d expr: %d %s", - m_class->name().constData(), m_id, m_child->id(), - positionStr(buffer, sizeof buffer)); + m_class->name().constData(), m_id, m_child->id(), + positionStr(buffer, sizeof buffer)); } /** @@ -1281,7 +1281,7 @@ void ReASConversion::dump(ReWriter& writer, int indent) { * otherwise: a converter to the given type */ ReASConversion* ReASConversion::tryConversion(ReASClass* expected, - ReASItem* expr, ReParser& parser, bool& isCorrect) { + ReASItem* expr, ReParser& parser, bool& isCorrect) { ReASConversion* rc = NULL; if (!expr->check(parser)) isCorrect = false; @@ -1291,9 +1291,9 @@ ReASConversion* ReASConversion::tryConversion(ReASClass* expected, Conversion type = findConversion(expr2->clazz(), expected); if (type == C_UNDEF) { isCorrect = parser.error(LOC_CONV_TRY_1, - "invalid data type conversion: %s -> %s", - expr2->clazz()->name().constData(), - expected->name().constData()); + "invalid data type conversion: %s -> %s", + expr2->clazz()->name().constData(), + expected->name().constData()); } else if (expr2->clazz() != expected) { rc = new ReASConversion(expr); rc->m_conversion = type; @@ -1312,7 +1312,7 @@ ReASConversion* ReASConversion::tryConversion(ReASClass* expected, * m_child2: the index expression */ ReASIndexedValue::ReASIndexedValue() : - ReASNode2(AST_INDEXED_VALUE) { + ReASNode2(AST_INDEXED_VALUE) { } /** @@ -1333,7 +1333,7 @@ void ReASIndexedValue::calc(ReVMThread& thread) { //@ToDo: access to the lists element: assignment or to stack if (thread.tracing()) thread.vm()->traceWriter()->format("[%d]: %.80s", ix, - thread.topOfValues().toString().constData()); + thread.topOfValues().toString().constData()); } /** @@ -1352,7 +1352,7 @@ bool ReASIndexedValue::check(ReParser& parser) { // index value: // tryConversion() calls m_child2->check()! ReASConversion* converter = ReASConversion::tryConversion( - ReASInteger::m_instance, m_child2, parser, rc); + ReASInteger::m_instance, m_child2, parser, rc); if (rc && converter != NULL) m_child = converter; if (rc) { @@ -1373,8 +1373,8 @@ bool ReASIndexedValue::check(ReParser& parser) { void ReASIndexedValue::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "indexedValue id: %d index: %d parent: %d %s", - m_id, m_child2->id(), m_child->id(), - positionStr(buffer, sizeof buffer)); + m_id, m_child2->id(), m_child->id(), + positionStr(buffer, sizeof buffer)); m_child2->dump(writer, indent + 1); m_child->dump(writer, indent + 1); } @@ -1392,9 +1392,9 @@ void ReASIndexedValue::dump(ReWriter& writer, int indent) { * @brief Constructor. */ ReASVarDefinition::ReASVarDefinition() : - ReASNode3(AST_VAR_DEFINITION), - ReASStatement(), - m_endOfScope(0) { + ReASNode3(AST_VAR_DEFINITION), + ReASStatement(), + m_endOfScope(0) { m_flags |= NF_STATEMENT; } @@ -1413,12 +1413,12 @@ void ReASVarDefinition::dump(ReWriter& writer, int indent) { qsnprintf(endOfScope, sizeof endOfScope, "-%d:0", m_endOfScope); char buffer[256]; writer.formatIndented(indent, - "varDef %s %s id: %d namedValue: %d value: %d succ: %d %s%s", - clazz() == NULL ? "?" : clazz()->name().constData(), name.constData(), - m_id, m_child2 == NULL ? 0 : m_child2->id(), - m_child3 == NULL ? 0 : m_child3->id(), - m_child == NULL ? 0 : m_child->id(), positionStr(buffer, sizeof buffer), - endOfScope); + "varDef %s %s id: %d namedValue: %d value: %d succ: %d %s%s", + clazz() == NULL ? "?" : clazz()->name().constData(), name.constData(), + m_id, m_child2 == NULL ? 0 : m_child2->id(), + m_child3 == NULL ? 0 : m_child3->id(), + m_child == NULL ? 0 : m_child->id(), positionStr(buffer, sizeof buffer), + endOfScope); if (m_child2 != NULL) m_child2->dump(writer, indent + 1); if (m_child3 != NULL) @@ -1485,14 +1485,14 @@ bool ReASVarDefinition::check(ReParser& parser) { ReASCalculable* expr = dynamic_cast(m_child3); if (expr == NULL) rc = error(LOC_VARDEF_CHECK_1, parser, - "Not a calculable expression: %s", - m_child3->nameOfItemType()); + "Not a calculable expression: %s", + m_child3->nameOfItemType()); else if (!typeCheck(var->clazz(), expr->clazz())) rc = error(LOC_VARDEF_CHECK_2, parser, - "data types are not compatible: %s/%s", - var->clazz()->name().constData(), - expr->clazz() == NULL ? - "?" : expr->clazz()->name().constData()); + "data types are not compatible: %s/%s", + var->clazz()->name().constData(), + expr->clazz() == NULL ? + "?" : expr->clazz()->name().constData()); } } return rc; @@ -1511,11 +1511,11 @@ int ReASVarDefinition::execute(ReVMThread& thread) { expr->calc(thread); ReASVariant& value = thread.popValue(); ReASVariant& destination = thread.valueOfVariable(var->m_symbolSpace, - var->m_variableNo); + var->m_variableNo); if (thread.tracing()) thread.vm()->traceWriter()->format("%s = %.80s [%.80s]", - var->m_name.constData(), value.toString().constData(), - destination.toString().constData()); + var->m_name.constData(), value.toString().constData(), + destination.toString().constData()); destination.copyValue(value); } return 0; @@ -1533,8 +1533,8 @@ int ReASVarDefinition::execute(ReVMThread& thread) { * @brief Constructor. */ ReASExprStatement::ReASExprStatement() : - ReASNode2(AST_EXPR_STATEMENT), - ReASStatement() { + ReASNode2(AST_EXPR_STATEMENT), + ReASStatement() { m_flags |= NF_STATEMENT; } @@ -1565,7 +1565,7 @@ int ReASExprStatement::execute(ReVMThread& thread) { ReASVariant& value = thread.popValue(); if (thread.tracing()) thread.vm()->traceWriter()->format("expr: %s", - value.toString().constData()); + value.toString().constData()); value.destroyValue(); return 0; } @@ -1582,9 +1582,9 @@ void ReASExprStatement::dump(ReWriter& writer, int indent) { if (m_id == 40) m_id = 40; writer.formatIndented(indent, "Expr id: %d expr: %d succ: %d %s", m_id, - m_child2 == NULL ? 0 : m_child2->id(), - m_child == NULL ? 0 : m_child->id(), - positionStr(buffer, sizeof buffer)); + m_child2 == NULL ? 0 : m_child2->id(), + m_child == NULL ? 0 : m_child->id(), + positionStr(buffer, sizeof buffer)); if (m_child2 != NULL) m_child2->dump(writer, indent + 1); } @@ -1601,8 +1601,8 @@ void ReASExprStatement::dump(ReWriter& writer, int indent) { * @param type */ ReASNode1::ReASNode1(ReASItemType type) : - ReASItem(type), - m_child(NULL) { + ReASItem(type), + m_child(NULL) { } /** @@ -1635,7 +1635,7 @@ void ReASNode1::setChild(ReASItem* child) { * @param statements the chain of statements to dump */ void ReASNode1::dumpStatements(ReWriter& writer, int indent, - ReASItem* statements) { + ReASItem* statements) { ReASNode1* chain = dynamic_cast(statements); while (chain != NULL) { chain->dump(writer, indent); @@ -1655,8 +1655,8 @@ void ReASNode1::dumpStatements(ReWriter& writer, int indent, * @param type */ ReASNode2::ReASNode2(ReASItemType type) : - ReASNode1(type), - m_child2(NULL) { + ReASNode1(type), + m_child2(NULL) { } /** @@ -1686,8 +1686,8 @@ void ReASNode2::setChild2(ReASItem* child2) { * @param type */ ReASNode3::ReASNode3(ReASItemType type) : - ReASNode2(type), - m_child3(NULL) { + ReASNode2(type), + m_child3(NULL) { } /** @@ -1727,8 +1727,8 @@ void ReASNode3::setChild3(ReASItem* child3) { * @param type */ ReASNode4::ReASNode4(ReASItemType type) : - ReASNode3(type), - m_child4(NULL) { + ReASNode3(type), + m_child4(NULL) { } /** @@ -1769,8 +1769,8 @@ void ReASNode4::setChild4(ReASItem* child4) { * @param type */ ReASNode5::ReASNode5(ReASItemType type) : - ReASNode4(type), - m_child5(NULL) { + ReASNode4(type), + m_child5(NULL) { } /** @@ -1811,8 +1811,8 @@ void ReASNode5::setChild5(ReASItem* child5) { * @param type */ ReASNode6::ReASNode6(ReASItemType type) : - ReASNode5(type), - m_child6(NULL) { + ReASNode5(type), + m_child6(NULL) { } /** @@ -1857,8 +1857,8 @@ void ReASNode6::setChild6(ReASItem* child6) { * @param type the node type */ ReASUnaryOp::ReASUnaryOp(UnaryOp op, ReASItemType type) : - ReASNode1(type), - m_operator(op) { + ReASNode1(type), + m_operator(op) { } /** @@ -1887,12 +1887,12 @@ void ReASUnaryOp::calc(ReVMThread& thread) { case UOP_INC: default: error(thread.logger(), LOC_UNOP_CALC_1, "unknown operator: %d", - m_operator); + m_operator); break; } if (thread.tracing()) thread.vm()->traceWriter()->format("unary %s: %s", nameOfOp(m_operator), - value.toString().constData()); + value.toString().constData()); } /** @@ -1913,30 +1913,30 @@ bool ReASUnaryOp::check(ReParser& parser) { switch (m_operator) { case UOP_PLUS: if (clazz != ReASInteger::m_instance - && clazz != ReASFloat::m_instance) + && clazz != ReASFloat::m_instance) rc = error(LOC_UNARY_CHECK_1, parser, - "wrong data type for unary operator '+': %s", - clazz->name().constData()); + "wrong data type for unary operator '+': %s", + clazz->name().constData()); break; case UOP_MINUS_INT: if (clazz != ReASFloat::m_instance) m_operator = UOP_MINUS_FLOAT; else if (clazz != ReASInteger::m_instance) rc = error(LOC_UNARY_CHECK_2, parser, - "wrong data type for unary operator '-': %s", - clazz->name().constData()); + "wrong data type for unary operator '-': %s", + clazz->name().constData()); break; case UOP_NOT_BOOL: if (clazz != ReASBoolean::m_instance) rc = error(LOC_UNARY_CHECK_3, parser, - "wrong data type for unary operator '!': %s", - clazz->name().constData()); + "wrong data type for unary operator '!': %s", + clazz->name().constData()); break; case UOP_NOT_INT: if (clazz != ReASInteger::m_instance) rc = error(LOC_UNARY_CHECK_4, parser, - "wrong data type for unary operator '!': %s", - clazz->name().constData()); + "wrong data type for unary operator '!': %s", + clazz->name().constData()); break; case UOP_DEC: break; @@ -1944,7 +1944,7 @@ bool ReASUnaryOp::check(ReParser& parser) { break; default: throw ReASException(position(), "unknown operator: %d", - m_operator); + m_operator); break; } } @@ -1970,8 +1970,8 @@ int ReASUnaryOp::getOperator() const { void ReASUnaryOp::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "Unary %d op: %s (%d) expr: %d %s", m_id, - nameOfOp(m_operator), m_operator, m_child == NULL ? 0 : m_child->id(), - positionStr(buffer, sizeof buffer)); + nameOfOp(m_operator), m_operator, m_child == NULL ? 0 : m_child->id(), + positionStr(buffer, sizeof buffer)); if (m_child != NULL) m_child->dump(writer, indent + 1); } @@ -2056,7 +2056,7 @@ int ReASStatement::executeStatementList(ReASItem* list, ReVMThread& thread) { */ ReASIf::ReASIf() : - ReASNode4(AST_IF) { + ReASNode4(AST_IF) { m_flags |= NF_STATEMENT; } @@ -2072,7 +2072,7 @@ bool ReASIf::check(ReParser& parser) { if (m_child2 == NULL) rc = ensureError(parser, "'if' misses condition"); else if (m_child2->checkAsCalculable("condition", ReASBoolean::m_instance, - parser)) + parser)) rc = false; if (m_child3 != NULL && !checkStatementList(m_child3, parser)) rc = false; @@ -2093,7 +2093,7 @@ int ReASIf::execute(ReVMThread& thread) { bool condition = calcAsBoolean(m_child2, thread); if (thread.tracing()) thread.vm()->traceWriter()->format("if %s", - condition ? "true" : "false"); + condition ? "true" : "false"); ReASItem* list = condition ? m_child3 : m_child4; if (list != NULL) { @@ -2116,12 +2116,12 @@ int ReASIf::execute(ReVMThread& thread) { void ReASIf::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, - "If id: %d condition: %d then: %d else: %d succ: %d%s", m_id, - m_child2 == NULL ? 0 : m_child2->id(), - m_child3 == NULL ? 0 : m_child3->id(), - m_child4 == NULL ? 0 : m_child4->id(), - m_child == NULL ? 0 : m_child->id(), - positionStr(buffer, sizeof buffer)); + "If id: %d condition: %d then: %d else: %d succ: %d%s", m_id, + m_child2 == NULL ? 0 : m_child2->id(), + m_child3 == NULL ? 0 : m_child3->id(), + m_child4 == NULL ? 0 : m_child4->id(), + m_child == NULL ? 0 : m_child->id(), + positionStr(buffer, sizeof buffer)); m_child2->dump(writer, indent + 1); if (m_child3 != NULL) m_child3->dump(writer, indent + 1); @@ -2151,8 +2151,8 @@ void ReASIf::dump(ReWriter& writer, int indent) { * @param variable NULL or the iterator variable */ ReASForIterated::ReASForIterated(ReASVarDefinition* variable) : - ReASNode4(AST_ITERATED_FOR), - ReASStatement() { + ReASNode4(AST_ITERATED_FOR), + ReASStatement() { m_flags |= NF_STATEMENT; m_child2 = variable; } @@ -2190,12 +2190,12 @@ int ReASForIterated::execute(ReVMThread& thread) { void ReASForIterated::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, - "forIt id: %d var: %d set: %d body: %d succ: %d %s", m_id, - m_child3 == NULL ? 0 : m_child3->id(), - m_child4 == NULL ? 0 : m_child4->id(), - m_child2 == NULL ? 0 : m_child2->id(), - m_child == NULL ? 0 : m_child->id(), - positionStr(buffer, sizeof buffer)); + "forIt id: %d var: %d set: %d body: %d succ: %d %s", m_id, + m_child3 == NULL ? 0 : m_child3->id(), + m_child4 == NULL ? 0 : m_child4->id(), + m_child2 == NULL ? 0 : m_child2->id(), + m_child == NULL ? 0 : m_child->id(), + positionStr(buffer, sizeof buffer)); if (m_child3 != NULL) m_child3->dump(writer, indent + 1); if (m_child4 != NULL) @@ -2228,8 +2228,8 @@ void ReASForIterated::dump(ReWriter& writer, int indent) { * @param variable NULL or the counter variable */ ReASForCounted::ReASForCounted(ReASVarDefinition* variable) : - ReASNode6(AST_ITERATED_FOR), - ReASStatement() { + ReASNode6(AST_ITERATED_FOR), + ReASStatement() { m_flags |= NF_STATEMENT; m_child3 = variable; } @@ -2250,19 +2250,19 @@ bool ReASForCounted::check(ReParser& parser) { rc = false; if (var == NULL) rc = error(LOC_FORC_CHECK_1, parser, "not a variable: %s", - m_child3->nameOfItemType()); + m_child3->nameOfItemType()); } if (m_child4 != NULL - && !m_child4->checkAsCalculable("start value", ReASInteger::m_instance, - parser)) + && !m_child4->checkAsCalculable("start value", ReASInteger::m_instance, + parser)) rc = false; if (m_child5 != NULL - && !m_child5->checkAsCalculable("end value", ReASInteger::m_instance, - parser)) + && !m_child5->checkAsCalculable("end value", ReASInteger::m_instance, + parser)) rc = false; if (m_child6 != NULL - && !m_child6->checkAsCalculable("step value", ReASInteger::m_instance, - parser)) + && !m_child6->checkAsCalculable("step value", ReASInteger::m_instance, + parser)) rc = false; if (m_child2 != NULL && !checkStatementList(m_child2, parser)) rc = false; @@ -2281,16 +2281,16 @@ int ReASForCounted::execute(ReVMThread& thread) { ReASStatement* body = dynamic_cast(m_child2); if (body == NULL) throw ReASException( - m_child2 == NULL ? m_position : m_child2->position(), - "forc statement: body is not a statement"); + m_child2 == NULL ? m_position : m_child2->position(), + "forc statement: body is not a statement"); int start = m_child4 == NULL ? 1 : calcAsInteger(m_child4, thread); int end = m_child5 == NULL ? 0 : calcAsInteger(m_child5, thread); int step = m_child6 == NULL ? 1 : calcAsInteger(m_child6, thread); ReASNamedValue* var = - m_child3 == NULL ? NULL : dynamic_cast(m_child3); + m_child3 == NULL ? NULL : dynamic_cast(m_child3); if (thread.tracing()) thread.vm()->traceWriter()->format("for %s from %d to %d step %d", - var == NULL ? "?" : var->name().constData(), start, end, step); + var == NULL ? "?" : var->name().constData(), start, end, step); for (int ii = start; ii <= end; ii += step) { //@ToDo: assign to the variable @@ -2321,14 +2321,14 @@ int ReASForCounted::execute(ReVMThread& thread) { void ReASForCounted::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, - "forC id: %d var: %d from: %d to: %d step: %d body: %d succ: %d %s", - m_id, m_child3 == NULL ? 0 : m_child3->id(), - m_child4 == NULL ? 0 : m_child4->id(), - m_child5 == NULL ? 0 : m_child5->id(), - m_child6 == NULL ? 0 : m_child6->id(), - m_child2 == NULL ? 0 : m_child2->id(), - m_child == NULL ? 0 : m_child->id(), - positionStr(buffer, sizeof buffer)); + "forC id: %d var: %d from: %d to: %d step: %d body: %d succ: %d %s", + m_id, m_child3 == NULL ? 0 : m_child3->id(), + m_child4 == NULL ? 0 : m_child4->id(), + m_child5 == NULL ? 0 : m_child5->id(), + m_child6 == NULL ? 0 : m_child6->id(), + m_child2 == NULL ? 0 : m_child2->id(), + m_child == NULL ? 0 : m_child->id(), + positionStr(buffer, sizeof buffer)); if (m_child3 != NULL) m_child3->dump(writer, indent + 1); if (m_child4 != NULL) @@ -2353,8 +2353,8 @@ void ReASForCounted::dump(ReWriter& writer, int indent) { */ ReASWhile::ReASWhile() : - ReASNode3(AST_WHILE), - ReASStatement() { + ReASNode3(AST_WHILE), + ReASStatement() { m_flags |= NF_STATEMENT; } @@ -2371,7 +2371,7 @@ bool ReASWhile::check(ReParser& parser) { ensureError(parser, "missing condition for 'while''"); else rc = m_child2->checkAsCalculable("condition", ReASBoolean::m_instance, - parser); + parser); if (m_child3 != NULL && !checkStatementList(m_child3, parser)) rc = false; return rc; @@ -2418,11 +2418,11 @@ void ReASWhile::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, - "while id: %d condition: %d body: %d succ: %d %s", m_id, - m_child2 == NULL ? 0 : m_child2->id(), - m_child3 == NULL ? 0 : m_child3->id(), - m_child == NULL ? 0 : m_child->id(), - positionStr(buffer, sizeof buffer)); + "while id: %d condition: %d body: %d succ: %d %s", m_id, + m_child2 == NULL ? 0 : m_child2->id(), + m_child3 == NULL ? 0 : m_child3->id(), + m_child == NULL ? 0 : m_child->id(), + positionStr(buffer, sizeof buffer)); if (m_child2 != NULL) m_child2->dump(writer, indent + 1); dumpStatements(writer, indent + 1, m_child3); @@ -2441,8 +2441,8 @@ void ReASWhile::dump(ReWriter& writer, int indent) { */ ReASRepeat::ReASRepeat() : - ReASNode3(AST_REPEAT), - ReASStatement() { + ReASNode3(AST_REPEAT), + ReASStatement() { m_flags |= NF_STATEMENT; } @@ -2460,7 +2460,7 @@ bool ReASRepeat::check(ReParser& parser) { if (m_child2 == NULL) ensureError(parser, "missing condition for 'repeat''"); else if (!m_child2->checkAsCalculable("condition", ReASBoolean::m_instance, - parser)) + parser)) rc = false; return rc; } @@ -2505,11 +2505,11 @@ int ReASRepeat::execute(ReVMThread& thread) { void ReASRepeat::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, - "repeat id: %d condition: %d body: %d succ: %d %s", m_id, - m_child2 == NULL ? 0 : m_child2->id(), - m_child3 == NULL ? 0 : m_child3->id(), - m_child == NULL ? 0 : m_child->id(), - positionStr(buffer, sizeof buffer)); + "repeat id: %d condition: %d body: %d succ: %d %s", m_id, + m_child2 == NULL ? 0 : m_child2->id(), + m_child3 == NULL ? 0 : m_child3->id(), + m_child == NULL ? 0 : m_child->id(), + positionStr(buffer, sizeof buffer)); if (m_child2 != NULL) m_child2->dump(writer, indent + 1); dumpStatements(writer, indent + 1, m_child3); @@ -2525,10 +2525,10 @@ void ReASRepeat::dump(ReWriter& writer, int indent) { * @brief Constructor. */ ReASClass::ReASClass(const QByteArray& name, ReASTree& tree) : - m_name(name), - m_symbols(NULL), - m_superClass(NULL), - m_tree(tree) { + m_name(name), + m_symbols(NULL), + m_superClass(NULL), + m_tree(tree) { } /** @@ -2558,7 +2558,7 @@ const QByteArray& ReASClass::name() const { */ void ReASClass::dump(ReWriter& writer, int indent) { writer.formatIndented(indent, "class %s super: %s", m_name.constData(), - m_superClass == NULL ? "" : m_superClass->name().constData()); + m_superClass == NULL ? "" : m_superClass->name().constData()); m_symbols->dump(writer, indent); } @@ -2580,11 +2580,11 @@ void ReASClass::setSymbols() { * @brief Constructor. */ ReASTree::ReASTree() : - m_global(NULL), - m_modules(), - m_symbolSpaces(), - m_currentSpace(NULL), - m_store(128 * 1024) { + m_global(NULL), + m_modules(), + m_symbolSpaces(), + m_currentSpace(NULL), + m_store(128 * 1024) { init(); } @@ -2637,7 +2637,7 @@ bool ReASTree::startModule(ReSourceUnitName name) { if (!rc) { // freed in ~ReASTree() ReSymbolSpace* space = new ReSymbolSpace(ReSymbolSpace::SST_MODULE, - name, m_global); + name, m_global); m_symbolSpaceHeap[name] = space; m_modules[name] = space; m_symbolSpaces.append(space); @@ -2665,7 +2665,7 @@ void ReASTree::finishModule(ReSourceUnitName name) { ReSymbolSpace* top = m_symbolSpaces.at(m_symbolSpaces.size() - 1); if (top->name() != name) throw ReException("ReASTree::finishModule(): module is not top: %s", - name); + name); else { m_symbolSpaces.removeLast(); // "global" is always the bottom: @@ -2680,7 +2680,7 @@ void ReASTree::finishModule(ReSourceUnitName name) { * @return the new symbol space */ ReSymbolSpace* ReASTree::startClassOrMethod(const QByteArray& name, - ReSymbolSpace::SymbolSpaceType type) { + ReSymbolSpace::SymbolSpaceType type) { // the stack m_modules is never empty because of "global" and modules. ReSymbolSpace* parent = m_symbolSpaces[m_symbolSpaces.size() - 1]; QByteArray fullName = parent->name() + "." + name; @@ -2701,7 +2701,7 @@ void ReASTree::finishClassOrMethod(const QByteArray& name) { ReSymbolSpace* top = m_symbolSpaces.at(m_symbolSpaces.size() - 1); if (!top->name().endsWith("." + name)) throw ReException("ReASTree::finishModule(): class is not top: %s", - name.constData()); + name.constData()); else { m_symbolSpaces.removeLast(); // "global" is the bottom always! @@ -2785,10 +2785,10 @@ void ReASTree::dump(const char* filename, int flags, const char* header) { */ ReASMethodCall::ReASMethodCall(const QByteArray& name, ReASItem* parent) : - ReASNode3(AST_METHOD_CALL), - ReASStatement(), - m_name(name), - m_method(NULL) { + ReASNode3(AST_METHOD_CALL), + ReASStatement(), + m_name(name), + m_method(NULL) { m_flags |= NF_STATEMENT; m_child3 = parent; } @@ -2806,25 +2806,25 @@ bool ReASMethodCall::check(ReParser& parser) { int argCount = 0; ReASMethod* method = m_method; ReASVarDefinition* params = - dynamic_cast(method->child2()); + dynamic_cast(method->child2()); while (args != NULL && params != NULL) { argCount++; ReASCalculable* argExpr = dynamic_cast(args->child2()); if (argExpr == NULL) rc = error(LOC_METHOD_CALL_CHECK_1, parser, - "argument %d misses expr", argCount); + "argument %d misses expr", argCount); else { ReASNamedValue* var; ReASItem* param = params->child2(); if (param == NULL - || (var = dynamic_cast(param)) == NULL) + || (var = dynamic_cast(param)) == NULL) rc = error(LOC_MEHTOD_CALL_CHECK_2, parser, - "parameter %d misses named value: %s", argCount, - param == NULL ? "" : param->nameOfItemType()); + "parameter %d misses named value: %s", argCount, + param == NULL ? "" : param->nameOfItemType()); else { // tryConversion() calls args->args->child2()->check()! ReASConversion* converter = ReASConversion::tryConversion( - var->clazz(), args->child2(), parser, rc); + var->clazz(), args->child2(), parser, rc); if (rc && converter != NULL) args->setChild2(converter); @@ -2835,10 +2835,10 @@ bool ReASMethodCall::check(ReParser& parser) { } if (args != NULL && params == NULL) rc = error(LOC_MEHTOD_CALL_CHECK_3, parser, - "too many arguments: %d are enough", argCount); + "too many arguments: %d are enough", argCount); else if (args == NULL && params != NULL && params->child3() != NULL) rc = error(LOC_MEHTOD_CALL_CHECK_4, parser, - "too few arguments: %d are not enough", argCount); + "too few arguments: %d are not enough", argCount); return rc; } @@ -2851,11 +2851,11 @@ bool ReASMethodCall::check(ReParser& parser) { void ReASMethodCall::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, - "call %s Id: %d args: %d parent: %d succ: %d %s", m_name.constData(), - m_id, m_child2 == NULL ? 0 : m_child2->id(), - m_child3 == NULL ? 0 : m_child3->id(), - m_child == NULL ? 0 : m_child->id(), - positionStr(buffer, sizeof buffer)); + "call %s Id: %d args: %d parent: %d succ: %d %s", m_name.constData(), + m_id, m_child2 == NULL ? 0 : m_child2->id(), + m_child3 == NULL ? 0 : m_child3->id(), + m_child == NULL ? 0 : m_child->id(), + positionStr(buffer, sizeof buffer)); if (m_child2 != NULL) m_child2->dump(writer, indent + 1); if (m_child3 != NULL) @@ -2925,8 +2925,8 @@ ReASExprStatement* ReASMethodCall::arg1() const { * @brief Constructor. */ ReASBinaryOp::ReASBinaryOp() : - ReASNode2(AST_BINARY_OP), - m_operator(BOP_UNDEF) { + ReASNode2(AST_BINARY_OP), + m_operator(BOP_UNDEF) { } /** @@ -2942,8 +2942,8 @@ void ReASBinaryOp::calc(ReVMThread& thread) { ReASCalculable* op2 = dynamic_cast(m_child2); if (op1 == NULL || op2 == NULL) error(thread.logger(), LOC_BINOP_CALC_1, "operand is null: %d / %d", - m_child == NULL ? 0 : m_child->id(), - m_child2 == NULL ? 0 : m_child2->id()); + m_child == NULL ? 0 : m_child->id(), + m_child2 == NULL ? 0 : m_child2->id()); else { op1->calc(thread); op2->calc(thread); @@ -2962,7 +2962,7 @@ void ReASBinaryOp::calc(ReVMThread& thread) { //if (val1.getClass() == ReASString::m_instance) default: error(thread.logger(), LOC_BINOP_CALC_2, - "invalid type for '+': %s", val1.nameOfType()); + "invalid type for '+': %s", val1.nameOfType()); break; } break; @@ -2976,7 +2976,7 @@ void ReASBinaryOp::calc(ReVMThread& thread) { break; default: error(thread.logger(), LOC_BINOP_CALC_3, - "invalid type for '-': %s", val1.nameOfType()); + "invalid type for '-': %s", val1.nameOfType()); break; } break; @@ -2990,7 +2990,7 @@ void ReASBinaryOp::calc(ReVMThread& thread) { break; default: error(thread.logger(), LOC_BINOP_CALC_4, - "invalid type for '*': %s", val1.nameOfType()); + "invalid type for '*': %s", val1.nameOfType()); break; } break; @@ -3004,7 +3004,7 @@ void ReASBinaryOp::calc(ReVMThread& thread) { break; default: error(thread.logger(), LOC_BINOP_CALC_5, - "invalid type for '/': %s", val1.nameOfType()); + "invalid type for '/': %s", val1.nameOfType()); break; } break; @@ -3018,7 +3018,7 @@ void ReASBinaryOp::calc(ReVMThread& thread) { break; default: error(thread.logger(), LOC_BINOP_CALC_6, - "invalid type for '%': %s", val1.nameOfType()); + "invalid type for '%': %s", val1.nameOfType()); break; } break; @@ -3029,7 +3029,7 @@ void ReASBinaryOp::calc(ReVMThread& thread) { break; default: error(thread.logger(), LOC_BINOP_CALC_7, - "invalid type for '**': %s", val1.nameOfType()); + "invalid type for '**': %s", val1.nameOfType()); break; } break; @@ -3040,7 +3040,7 @@ void ReASBinaryOp::calc(ReVMThread& thread) { break; default: error(thread.logger(), LOC_BINOP_CALC_8, - "invalid type for '||': %s", val1.nameOfType()); + "invalid type for '||': %s", val1.nameOfType()); break; } break; @@ -3051,7 +3051,7 @@ void ReASBinaryOp::calc(ReVMThread& thread) { break; default: error(thread.logger(), LOC_BINOP_CALC_9, - "invalid type for '&&': %s", val1.nameOfType()); + "invalid type for '&&': %s", val1.nameOfType()); break; } break; @@ -3062,7 +3062,7 @@ void ReASBinaryOp::calc(ReVMThread& thread) { break; default: error(thread.logger(), LOC_BINOP_CALC_9, - "invalid type for '^^': %s", val1.nameOfType()); + "invalid type for '^^': %s", val1.nameOfType()); break; } break; @@ -3073,7 +3073,7 @@ void ReASBinaryOp::calc(ReVMThread& thread) { break; default: error(thread.logger(), LOC_BINOP_CALC_10, - "invalid type for '|': %s", val1.nameOfType()); + "invalid type for '|': %s", val1.nameOfType()); break; } break; @@ -3084,7 +3084,7 @@ void ReASBinaryOp::calc(ReVMThread& thread) { break; default: error(thread.logger(), LOC_BINOP_CALC_11, - "invalid type for '&': %s", val1.nameOfType()); + "invalid type for '&': %s", val1.nameOfType()); break; } break; @@ -3095,7 +3095,7 @@ void ReASBinaryOp::calc(ReVMThread& thread) { break; default: error(thread.logger(), LOC_BINOP_CALC_12, - "invalid type for '^': %s", val1.nameOfType()); + "invalid type for '^': %s", val1.nameOfType()); break; } break; @@ -3147,10 +3147,10 @@ void ReASBinaryOp::dump(ReWriter& writer, int indent) { const QByteArray& opName = nameOfOp(m_operator); char buffer[256]; writer.formatIndented(indent, - "BinOp id: %d op: %s (%d) left: %d right: %d %s", m_id, - opName.constData(), m_operator, m_child == NULL ? 0 : m_child->id(), - m_child2 == NULL ? 0 : m_child2->id(), - positionStr(buffer, sizeof buffer)); + "BinOp id: %d op: %s (%d) left: %d right: %d %s", m_id, + opName.constData(), m_operator, m_child == NULL ? 0 : m_child->id(), + m_child2 == NULL ? 0 : m_child2->id(), + positionStr(buffer, sizeof buffer)); if (indent < 32 && m_child != NULL) m_child->dump(writer, indent + 1); if (indent < 32 && m_child2 != NULL) @@ -3167,7 +3167,7 @@ void ReASBinaryOp::assign(ReVMThread& thread) { ReASCalculable* expr = dynamic_cast(m_child2); if (expr == NULL) error(thread.logger(), LOC_BINOP_1, "not a calculable: id: %d", - m_child2 == NULL ? 0 : m_child2->id()); + m_child2 == NULL ? 0 : m_child2->id()); else { ReASVariant& value = thread.popValue(); switch (m_operator) { @@ -3339,13 +3339,13 @@ const char* ReASBinaryOp::nameOfOp(ReASBinaryOp::BinOperator op) { * @param tree the abstract syntax tree */ ReASMethod::ReASMethod(const QByteArray& name, ReASTree& tree) : - ReASNode2(AST_METHOD), - m_name(name), - m_resultType(NULL), - m_symbols(NULL), - m_sibling(NULL), - m_tree(tree), - firstParamWithDefault(-1) { + ReASNode2(AST_METHOD), + m_name(name), + m_resultType(NULL), + m_symbols(NULL), + m_sibling(NULL), + m_tree(tree), + firstParamWithDefault(-1) { } /** @@ -3381,13 +3381,13 @@ void ReASMethod::dump(ReWriter& writer, int indent) { char buffer[256]; writer.indent(indent); writer.format("Method %s %s(", - m_resultType == NULL ? "" : m_resultType->name().constData(), - m_name.constData()); + m_resultType == NULL ? "" : m_resultType->name().constData(), + m_name.constData()); ReSymbolSpace* parent = m_symbols->parent(); writer.formatLine(") id: %d parent: %s args: %d body: %d %s", m_id, - parent == NULL ? "" : parent->name().constData(), - m_child2 == NULL ? 0 : m_child2->id(), m_child->id(), - positionStr(buffer, sizeof buffer)); + parent == NULL ? "" : parent->name().constData(), + m_child2 == NULL ? 0 : m_child2->id(), m_child->id(), + positionStr(buffer, sizeof buffer)); if (m_child2 != NULL) m_child2->dump(writer, indent + 1); dumpStatements(writer, indent + 1, m_child); @@ -3427,16 +3427,16 @@ bool ReASMethod::equalSignature(ReASMethod& other) const { bool rc = true; ReASExprStatement* args = dynamic_cast(m_child2); ReASExprStatement* otherArgs = - dynamic_cast(other.child2()); + dynamic_cast(other.child2()); while (rc && (args != NULL || otherArgs != NULL)) { if (args == NULL || otherArgs == NULL) rc = false; else { ReASVarDefinition* def = dynamic_cast(args - ->child2()); + ->child2()); ReASVarDefinition* defOther = - dynamic_cast(otherArgs->child2()); + dynamic_cast(otherArgs->child2()); if (def->clazz() != defOther->clazz()) rc = false; } @@ -3491,8 +3491,8 @@ void ReASMethod::setFirstParamWithDefault(int value) { * @param name name of the field */ ReASField::ReASField(const QByteArray& name) : - ReASNode1(AST_FIELD), - m_name(name) { + ReASNode1(AST_FIELD), + m_name(name) { } /** @@ -3516,8 +3516,8 @@ bool ReASField::check(ReParser& parser) { void ReASField::dump(ReWriter& writer, int indent) { char buffer[256]; writer.formatIndented(indent, "field %s id: %d parent: %d succ: %s", - m_name.constData(), m_id, m_child == NULL ? 0 : m_child->id(), - positionStr(buffer, sizeof buffer)); + m_name.constData(), m_id, m_child == NULL ? 0 : m_child->id(), + positionStr(buffer, sizeof buffer)); m_child->dump(writer, indent + 1); } diff --git a/expr/ReLexer.cpp b/expr/ReLexer.cpp index 5dd5a8b..8220780 100644 --- a/expr/ReLexer.cpp +++ b/expr/ReLexer.cpp @@ -37,7 +37,7 @@ ReLexException::ReLexException(const ReSourcePosition& position, const char* format, ...) : ReException("") { char buffer[64000]; - m_message = position.toString().toUtf8(); + m_message = I18N::s2b(position.toString()); va_list ap; va_start(ap, format); qvsnprintf(buffer, sizeof buffer, format, ap); diff --git a/gui/ReSettings.cpp b/gui/ReSettings.cpp index 946f3ad..7913575 100644 --- a/gui/ReSettings.cpp +++ b/gui/ReSettings.cpp @@ -209,7 +209,7 @@ void ReSettings::changeValue(const char* name, const QString& value) { else if (!property->isValid(value, &error)) m_logger->logv(LOG_ERROR, LOC_CHANGE_VALUE_2, "invalid value for %s: %s\n+++ %s", name, - value.toUtf8().constData(), error.toUtf8().constData()); + I18N::s2b(value).constData(), I18N::s2b(error).constData()); else property->m_value = value; } @@ -293,7 +293,7 @@ void ReSettings::readSettings() { QFile file(m_fileSettings); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_1, "cannot open (%d): ", - errno, m_fileSettings.toUtf8().constData()); + errno, I18N::s2b(m_fileSettings).constData()); else { QTextStream input(&file); int lineNo = 0; @@ -304,23 +304,23 @@ void ReSettings::readSettings() { if (ix < 0) m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_2, "missing '=': %s-%d: %s", - m_fileSettings.toUtf8().constData(), lineNo, - line.mid(0, 20).toUtf8().constData()); + I18N::s2b(m_fileSettings).constData(), lineNo, + I18N::s2b(line.mid(0, 20)).constData()); else if (ix == 0 || (ix == 1 && line.at(0) == '!')) m_logger->logv(LOG_ERROR, LOC_READ_SETTINGS_3, "line starts with '=': %s-%d: %s", - m_fileSettings.toUtf8().constData(), lineNo, - line.mid(0, 20).toUtf8().constData()); + I18N::s2b(m_fileSettings).constData(), lineNo, + I18N::s2b(line.mid(0, 20)).constData()); else { QByteArray name; QString value; if (line.at(ix - 1) == '!') { - name = line.left(ix - 1).toUtf8(); + name = I18N::s2b(line.left(ix - 1)); value = line.mid(ix + 1); value.replace("\\\\", "\01").replace("\\n", "\n").replace( "\\r", "\r").replace('\01', '\\'); } else { - name = line.left(ix).toUtf8(); + name = I18N::s2b(line.left(ix)); value = line.mid(ix + 1); } ReProperty* property = m_settings.value(name, NULL); @@ -387,7 +387,7 @@ void ReSettings::writeSettings() { QFile file(m_fileSettings); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) m_logger->logv(LOG_ERROR, LOC_WRITE_SETTINGS_1, "cannot open (%d): ", - errno, m_fileSettings.toUtf8().constData()); + errno, I18N::s2b(m_fileSettings).constData()); else { QTextStream out(&file); QMap::const_iterator it; diff --git a/gui/ReStateStorage.cpp b/gui/ReStateStorage.cpp index 5c1c08d..a55668d 100644 --- a/gui/ReStateStorage.cpp +++ b/gui/ReStateStorage.cpp @@ -152,10 +152,10 @@ QByteArray ReStateStorage::fullname(const char* name) { */ bool ReStateStorage::initForRead() { if (m_fp == NULL) - if ((m_fp = fopen(m_filename.toUtf8().constData(), "rb")) == NULL) { + if ((m_fp = fopen(I18N::s2b(m_filename).constData(), "rb")) == NULL) { if (m_logger != NULL) m_logger->logv(LOG_ERROR, LOC_INIT_FOR_READ_1, - "cannot open %s: %d", m_filename.toUtf8().constData(), + "cannot open %s: %d", I18N::s2b(m_filename).constData(), errno); } if (m_fp != NULL && m_stream == NULL) { @@ -168,7 +168,7 @@ bool ReStateStorage::initForRead() { int ixAssignment = line.indexOf('='); if (ixAssignment > 0) { value = line.mid(ixAssignment + 1); - QByteArray key = line.left(ixAssignment).toUtf8(); + QByteArray key = I18N::s2b(line.left(ixAssignment)); m_map.insert(key, value); } } @@ -180,11 +180,11 @@ bool ReStateStorage::initForRead() { */ bool ReStateStorage::initForWrite() { if (m_fp == NULL) - m_fp = fopen(m_filename.toUtf8().constData(), "wb"); + m_fp = fopen(I18N::s2b(m_filename).constData(), "wb"); if (m_fp == NULL) { if (m_logger != NULL) m_logger->logv(LOG_ERROR, LOC_INIT_FOR_WRITE_1, - "cannot open %s: %d", m_filename.toUtf8().constData(), errno); + "cannot open %s: %d", I18N::s2b(m_filename).constData(), errno); } else m_stream = new QTextStream(m_fp, QIODevice::ReadWrite); return m_stream != NULL; diff --git a/net/ReTCPPeer.cpp b/net/ReTCPPeer.cpp index ed473a9..603fa17 100644 --- a/net/ReTCPPeer.cpp +++ b/net/ReTCPPeer.cpp @@ -56,7 +56,7 @@ static int s_dummy = 0; * @return an instance of ReTCPPeer */ ReTCPPeer* ReTCPPeer::createPeer(ReConfigurator& configurator, QThread* thread, - ReTerminator* terminator, ReLogger* logger) { + ReTerminator* terminator, ReLogger* logger) { return new ReTCPPeer(configurator, thread, terminator, logger); } @@ -70,21 +70,21 @@ ReTCPPeer* ReTCPPeer::createPeer(ReConfigurator& configurator, QThread* thread, * @param logger logger. If Null the global logger will be taken (not thread safe!) */ ReTCPPeer::ReTCPPeer(ReConfigurator& configurator, QThread* thread, - ReTerminator* terminator, bool isServer, ReLogger* logger) : - m_socket(NULL), - m_logger(logger == NULL ? ReLogger::globalLogger() : logger), - m_thread(thread), - m_random(), - m_timeout(isServer ? 0 : configurator.asInt("connection.timeout", 60)), - m_terminator(terminator), - m_configurator(configurator), - m_isServer(isServer), - m_dataLocker(QMutex::NonRecursive), - m_waitForData() { + ReTerminator* terminator, bool isServer, ReLogger* logger) : + m_socket(NULL), + m_logger(logger == NULL ? ReLogger::globalLogger() : logger), + m_thread(thread), + m_random(), + m_timeout(isServer ? 0 : configurator.asInt("connection.timeout", 60)), + m_terminator(terminator), + m_configurator(configurator), + m_isServer(isServer), + m_dataLocker(QMutex::NonRecursive), + m_waitForData() { // Simulate a true random with time, and addresses from stack and code segment: m_random.setSeed( - time(NULL) + ((int64_t) this << 8) + ((int64_t) &s_dummy << 16) - + ((int64_t) &createPeer << 24)); + time(NULL) + ((int64_t) this << 8) + ((int64_t) &s_dummy << 16) + + ((int64_t) &createPeer << 24)); } /** @@ -108,7 +108,7 @@ bool ReTCPPeer::send(qint8 flags, const char* command, const QByteArray& data) { QByteArray header; QByteArray data2 = ReStringUtil::toCString(data.constData(), 20); m_logger->logv(LOG_INFO, LOC_SEND_1, "send: flags: %x %s %s (%d)", flags, - command, data2.constData(), data.length()); + command, data2.constData(), data.length()); header.reserve(16); header.append((char) flags); if (flags & FLAG_ENCRYPT) { @@ -140,16 +140,16 @@ bool ReTCPPeer::send(qint8 flags, const char* command, const QByteArray& data) { m_thread->msleep(1); if (++count % 20 == 0) { if (m_terminator == NULL || m_terminator->isStopped() - || time(NULL) > endTime) + || time(NULL) > endTime) break; } } } if (m_logger->isActive(LOG_DEBUG)) m_logger->logv(LOG_DEBUG, LOC_SEND_1, "send %s: %s len=%d loops=%d %s", - m_address.constData(), command, data.length(), count, - ReStringUtil::hexDump((const void*) data.constData(), 16, 16) - .constData()); + m_address.constData(), command, data.length(), count, + ReStringUtil::hexDump((const void*) data.constData(), 16, 16) + .constData()); return rc; } @@ -180,7 +180,7 @@ QByteArray ReTCPPeer::readBytes(int bytes, time_t maxTime, int& loops) { if (++loops % divider == 0 && !m_isServer) { if (time(NULL) > maxTime) { m_logger->logv(LOG_ERROR, LOC_READ_BYTES_1, - "receive: timeout (%d)", m_timeout); + "receive: timeout (%d)", m_timeout); success = false; break; } @@ -193,13 +193,13 @@ QByteArray ReTCPPeer::readBytes(int bytes, time_t maxTime, int& loops) { } available = socket->bytesAvailable(); m_logger->logv(LOG_DEBUG, LOC_READ_BYTES_4, - "readBytes(): available: %ld/%ld", available, bytes); + "readBytes(): available: %ld/%ld", available, bytes); QByteArray rc; if (success) { rc = socket->read(bytes); if (rc.length() != bytes) { m_logger->logv(LOG_ERROR, LOC_READ_BYTES_3, - "receive: too few bytes: %d of %d", rc.length(), bytes); + "receive: too few bytes: %d of %d", rc.length(), bytes); } } return rc; @@ -241,7 +241,7 @@ bool ReTCPPeer::receive(QByteArray& command, QByteArray& data) { headerSize += 4; if (headerSize != minHeaderSize) { QByteArray restHeader = readBytes(headerSize - minHeaderSize, - maxTime, loops); + maxTime, loops); if (restHeader.length() == 0) header.clear(); else @@ -273,7 +273,7 @@ bool ReTCPPeer::receive(QByteArray& command, QByteArray& data) { * false: error occurred */ bool ReTCPPeer::sendAndReceive(uint8_t flags, char command[4], QByteArray* data, - QByteArray& answer, QByteArray& answerData) { + QByteArray& answer, QByteArray& answerData) { answer.clear(); answerData.clear(); bool rc = send(flags, command, data == NULL ? QByteArray("") : *data); @@ -307,7 +307,7 @@ void ReTCPPeer::readTcpData() { */ void ReTCPPeer::handleError(QTcpSocket::SocketError socketError) { m_logger->logv(LOG_ERROR, LOC_HANDLE_ERROR_1, "Network error %d", - socketError); + socketError); } /** @@ -319,7 +319,7 @@ QByteArray ReTCPPeer::getPeerAddress() { if (m_socket == NULL) rc = ""; else - rc = m_socket->peerAddress().toString().toUtf8(); + rc = m_socket->peerAddress().toString().toLatin1(); return rc; } diff --git a/os/ReCryptFileSystem.cpp b/os/ReCryptFileSystem.cpp index f70a1e1..a2418e9 100644 --- a/os/ReCryptFileSystem.cpp +++ b/os/ReCryptFileSystem.cpp @@ -224,8 +224,8 @@ ReFileSystem::ErrorCode ReCryptFileSystem::makeDir(const QString& node) { ErrorCode rc2 = m_host.makeDir(hostName); if (rc2 != EC_SUCCESS){ m_logger2->logv(LOG_ERROR, LOC_MAKE_DIR_1, "cannot create hosted directory %s: %s", - hostName.toUtf8().constData(), - errorMessage(rc2).toUtf8().constData()); + I18N::s2b(hostName).constData(), + I18N::s2b(errorMessage(rc2)).constData()); rc = EC_REMOTE_MKDIR; } else { m_list.append(ReFileMetaData(node, now, now, m_osPermissions.m_user, @@ -468,7 +468,7 @@ bool ReCryptDirectory::removeEntry(const QString& node) const ReFileMetaData* entry = find(node); if (entry == NULL) rc = ! m_logger->logv(LOG_ERROR, LOC_REMOVE_ENTRY_1, "cannot remove file %s: not found", - node.toUtf8().constData()); + I18N::s2b(node).constData()); else { ReFileMetaData& entry2 = *(ReFileMetaData*) entry; //@ToDo: @@ -495,7 +495,7 @@ bool ReCryptDirectory::readMetaFile() m_list.clear(); QString fnMetaFile = m_parentFS->host().directory() + ReCryptFileSystem::NODE_META_DIR; - FILE* fp = fopen(fnMetaFile.toUtf8().constData(), "rb"); + FILE* fp = fopen(I18N::s2b(fnMetaFile).constData(), "rb"); m_maxFileId = 0; if (fp != NULL){ QByteArray header; @@ -504,7 +504,7 @@ bool ReCryptDirectory::readMetaFile() if (nRead != META_DIR_HEADER_LENGTH){ rc = ! m_logger->logv(LOG_ERROR, LOC_READ_META_FILE_1, "header of %s too small: %d/%d", - fnMetaFile.toUtf8().constData(), nRead, META_DIR_HEADER_LENGTH); + I18N::s2b(fnMetaFile).constData(), nRead, META_DIR_HEADER_LENGTH); } else { QByteArray info; rc = initFromHeader(0, MARKER_LENGTH, META_INFO_LENGTH, 0, &header, info); @@ -529,7 +529,7 @@ bool ReCryptDirectory::readMetaFile() if (sumLength != meta->m_size){ m_logger->logv(LOG_ERROR, LOC_READ_META_FILE_2, "file %s too small: %d/%d", - fnMetaFile.toUtf8().constData(), + I18N::s2b(fnMetaFile).constData(), sumLength, meta->m_size); } } @@ -555,20 +555,20 @@ bool ReCryptDirectory::writeMetaFile() meta2->m_size = meta2->m_countFiles * sizeof(FileEntry_t); ReFileMetaDataList::const_iterator it; for (it = m_list.cbegin(); it != m_list.cend(); ++it){ - int length = it->m_node.toUtf8().length(); + int length = I18N::s2b(it->m_node).length(); meta2->m_size += length + (length < 256 ? 0 : 1); } TRACE2("count: %d size: %d\n", meta2->m_countFiles, meta2->m_size); initHeader(0, MARKER_LENGTH, META_INFO_LENGTH, 0, meta); QByteArray node; for (it = m_list.cbegin(); it != m_list.cend(); ++it){ - node = it->m_node.toUtf8(); + node = I18N::s2b(it->m_node); int length = node.length(); meta2->m_size += length + (length < 256 ? 0 : 1); } QString fnMetaFile = m_parentFS->host().directory() + ReCryptFileSystem::NODE_META_DIR; - FILE* fp = fopen(fnMetaFile.toUtf8().constData(), "wb"); + FILE* fp = fopen(I18N::s2b(fnMetaFile).constData(), "wb"); if (fp == NULL){ m_logger->logv(LOG_ERROR, LOC_WRITE_META_1, "cannot write (%d): %s", errno, fnMetaFile.constData()); @@ -588,7 +588,7 @@ bool ReCryptDirectory::writeMetaFile() trg.m_size = file.m_size; trg.m_mode = file.m_mode; trg.m_id = file.m_id; - node = file.m_node.toUtf8(); + node = I18N::s2b(file.m_node); int length = node.length(); trg.m_nodeLength = length < 256 ? length : 0; m_fileBuffer.append(reinterpret_cast(&trg), sizeof trg); @@ -739,8 +739,8 @@ ReFileSystem::ErrorCode ReCryptDirectory::writeFileBlock(const QString& target, ReCryptLeafFile::ReCryptLeafFile(const ReFileMetaData& metadata, const QString& fullName, ReCryptDirectory& directory, ReLogger* logger) : ReLeafFile(metadata, fullName, logger), - m_fullHostedName((directory.parentFS()->host().directory() - + directory.parentFS()->buildHostedNode(metadata.m_id)).toUtf8()), + m_fullHostedName(I18N::s2b(directory.parentFS()->host().directory() + + directory.parentFS()->buildHostedNode(metadata.m_id))), m_fileHeader(), m_dataSum(0x7b644ac5d1187d25L, 0x6b85115d6064365bL), m_sumOfEncrypted(0x7b644ac5d1187d25L, 0x6b85115d6064365bL), diff --git a/os/ReFileSystem.cpp b/os/ReFileSystem.cpp index 28bd748..01e2a93 100644 --- a/os/ReFileSystem.cpp +++ b/os/ReFileSystem.cpp @@ -361,7 +361,7 @@ void ReFileSystem::synchronize(ReIncludeExcludeMatcher& fileMatcher, ReFileMetaData metaTarget; QByteArray dir; if (verboseLevel > V_SILENT) - dir = directory().toUtf8(); + dir = I18N::s2b(directory()); if (source.listInfos(fileMatcher, sourceList, LO_FILES) > 0){ QString sourceDir = source.directory(); QString targetDir = directory(); @@ -374,12 +374,12 @@ void ReFileSystem::synchronize(ReIncludeExcludeMatcher& fileMatcher, > metaTarget.m_modified.currentMSecsSinceEpoch()){ if (verboseLevel > V_SILENT) printf("%c%s%s\n", alreadyExists ? '<' : '+', - dir.constData(), it->m_node.toUtf8().constData()); + dir.constData(), I18N::s2b(it->m_node).constData()); copy(*it, source); } else if (verboseLevel > V_IMPORTANT){ printf("%c%s%s\n", it->m_modified == metaTarget.m_modified ? '=' : '>', - dir.constData(), it->m_node.toUtf8().constData()); + dir.constData(), I18N::s2b(it->m_node).constData()); } } } @@ -392,14 +392,14 @@ void ReFileSystem::synchronize(ReIncludeExcludeMatcher& fileMatcher, if (! alreadyExists && S_ISDIR(metaTarget.m_mode)){ if (verboseLevel > V_SILENT) printf("-%s%s\n", dir.constData(), - it->m_node.toUtf8().constData()); + I18N::s2b(it->m_node).constData()); remove(metaTarget); alreadyExists = exists(it->m_node, &metaTarget); } if (! alreadyExists){ if (verboseLevel > V_SILENT) printf("&%s%s\n", dir.constData(), - it->m_node.toUtf8().constData()); + I18N::s2b(it->m_node).constData()); if (makeDir(it->m_node) != EC_SUCCESS) continue; } @@ -509,7 +509,7 @@ int ReLocalFileSystem::listInfos(const ReIncludeExcludeMatcher& matcher, ! earlyMatching || patterns.size() == 0 ? m_dir.entryList() : m_dir.entryList(patterns); QStringList::const_iterator it; - QByteArray full = m_directory.toUtf8(); + QByteArray full = I18N::s2b(m_directory); int pathLength = full.length(); struct stat info; const ReListMatcher& excludeMatcher = matcher.excludes(); @@ -522,7 +522,7 @@ int ReLocalFileSystem::listInfos(const ReIncludeExcludeMatcher& matcher, continue; } full.resize(pathLength); - full.append(node.toUtf8()); + full.append(I18N::s2b(node)); if (stat(full.constData(), &info) == 0) { bool isDir = S_ISDIR(info.st_mode); if ((isDir && ! withDirs) || (! isDir && ! withFiles)) @@ -737,7 +737,7 @@ ReFileSystem::ErrorCode ReLocalFileSystem::setProperties( name = fullNameAsUTF8(target.m_node); m_logger->logv(LOG_ERROR, LOC_SET_PROPERTIES_3, "renaming impossible: %s -> %s", - source.m_node.toUtf8().constData(), name.constData()); + I18N::s2b(source.m_node).constData(), name.constData()); break; } else { name.resize(0); @@ -933,11 +933,11 @@ ReLocalLeafFile::~ReLocalLeafFile(){ */ ReFileSystem::ErrorCode ReLocalLeafFile::open(bool writeable){ ReFileSystem::ErrorCode rc = ReFileSystem::EC_SUCCESS; - if ( (m_fp = fopen(m_fullName.toUtf8().constData(), + if ( (m_fp = fopen(I18N::s2b(m_fullName).constData(), writeable ?"wb" : "rb")) == NULL){ rc = ReFileSystem::EC_NOT_EXISTS; m_logger->logv(LOG_ERROR, LOC_OPEN_1, "cannot open: %s", - m_fullName.toUtf8().constData()); + I18N::s2b(m_fullName).constData()); } return rc; } @@ -974,7 +974,7 @@ ReFileSystem::ErrorCode ReLocalLeafFile::read(int maxSize, if ( (nRead = fread(buffer.data(), 1, maxSize, m_fp)) != maxSize){ rc = ReFileSystem::EC_READ; m_logger->logv(LOG_ERROR, LOC_READ_1, "cannnot read %s (%d): %d/%d", - m_fullName.toUtf8().constData(), errno, nRead, maxSize); + I18N::s2b(m_fullName).constData(), errno, nRead, maxSize); } } return rc; @@ -996,7 +996,7 @@ ReFileSystem::ErrorCode ReLocalLeafFile::write(const QByteArray& buffer){ if ( (nWritten = fwrite(buffer.constData(), 1, nToWrite, m_fp)) != nToWrite){ rc = ReFileSystem::EC_WRITE; m_logger->logv(LOG_ERROR, LOC_WRITE_1, "cannnot read %s (%d): %d/%d", - m_fullName.toUtf8().constData(), errno, nWritten, nToWrite); + I18N::s2b(m_fullName).constData(), errno, nWritten, nToWrite); } } return rc;