diff --git a/FrameWorkCode/AppResources.qrc b/FrameWorkCode/AppResources.qrc index bf78277f..1547b297 100755 --- a/FrameWorkCode/AppResources.qrc +++ b/FrameWorkCode/AppResources.qrc @@ -51,6 +51,41 @@ Resources/logonew.png Resources/Old Icons/rotate.png Resources/voice.png + Resources/backfinal.png + Resources/forfinal.png + Resources/user_login.png + Resources/windows-modified.png + Resources/voice_typing-modified.png + Resources/user-guide-modified.png + Resources/update-modified.png + Resources/tutorial-modified.png + Resources/table-modified.png + Resources/tab-modified.png + Resources/sync_from_cloud-modified.png + Resources/select_all-modified.png + Resources/save_to_cloud-modified.png + Resources/resize-modified.png + Resources/numbered_list-modified.png + Resources/linux-modified.png + Resources/link-modified.png + Resources/keyboard_shortcuts-modified.png + Resources/increase_size-modified.png + Resources/import-modified.png + Resources/image-modified.png + Resources/exit-modified.png + Resources/equation-modified.png + Resources/download-modified.png + Resources/delete-modified.png + Resources/decrease_size-modified.png + Resources/date-modified.png + Resources/close_project-modified.png + Resources/bulleted_list-modified.png + Resources/about-modified.png + Resources/outdent-modified.png + Resources/indent-modified.png + Resources/paste(1)-modified.png + Resources/copy-modified.png + Resources/cut-modified.png wordlists/english.txt diff --git a/FrameWorkCode/Project.cpp b/FrameWorkCode/Project.cpp index a06f7a93..d72fed11 100755 --- a/FrameWorkCode/Project.cpp +++ b/FrameWorkCode/Project.cpp @@ -15,6 +15,8 @@ #include #include #include "lg2_common.h" +#include "qnetworkaccessmanager.h" +#include "qnetworkreply.h" #include #include #include @@ -447,9 +449,9 @@ TreeModel * Project::getModel() * \return git_repository_init_options */ git_repository_init_options make_opts(bool bare, const char * templ, - uint32_t shared, - const char * gitdir, - const char * dir) + uint32_t shared, + const char * gitdir, + const char * dir) { git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; @@ -566,7 +568,7 @@ static bool is_cred_cached = false; * \return */ int credentials_cb(git_cred ** out, const char *url, const char *username_from_url, - unsigned int allowed_types, void *payload) + unsigned int allowed_types, void *payload) { int error; @@ -578,23 +580,39 @@ int credentials_cb(git_cred ** out, const char *url, const char *username_from_u if (!is_cred_cached) { } - QProcess process; - process.execute("curl -d -X -k -POST --header " - "\"Content-type:application/x-www-form-urlencoded\" https://udaaniitb.aicte-india.org/udaan/email/ -o gitToken.json"); - - QFile jsonFile("gitToken.json"); - jsonFile.open(QIODevice::ReadOnly | QIODevice::Text); - QByteArray data = jsonFile.readAll(); - - QJsonParseError errorPtr; - QJsonDocument document = QJsonDocument::fromJson(data, &errorPtr); - QJsonObject mainObj = document.object(); - jsonFile.close(); - QString git_token = mainObj.value("github_token").toString(); - QString git_username = mainObj.value("github_username").toString(); - QFile::remove("gitToken.json"); - user = git_username.toStdString(); - pass = git_token.toStdString(); + QNetworkAccessManager* manager = new QNetworkAccessManager(); + QUrl url_("https://udaaniitb.aicte-india.org/udaan/email/"); + + QByteArray postData; + postData.append("username=username&password=password"); + + QNetworkRequest request(url_); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + + // Disable SSL certificate verification + QSslConfiguration sslConfig = request.sslConfiguration(); + sslConfig.setPeerVerifyMode(QSslSocket::VerifyNone); + request.setSslConfiguration(sslConfig); + QNetworkReply* reply = manager->post(request, postData); + QEventLoop loop; + QObject::connect(reply, &QNetworkReply::finished, [=, &loop]() { + if (reply->error() == QNetworkReply::NoError) { + QByteArray data = reply->readAll(); + QJsonParseError errorPtr; + QJsonDocument document = QJsonDocument::fromJson(data, &errorPtr); + QJsonObject mainObj = document.object(); + QString git_token = mainObj.value("github_token").toString(); + QString git_username = mainObj.value("github_username").toString(); + // use git_token and git_username here + user = git_username.toStdString(); + pass = git_token.toStdString(); + loop.quit(); + } else { + qDebug() << "Error:" << reply->errorString(); + } + reply->deleteLater(); + }); + loop.exec(); return git_cred_userpass_plaintext_new(out, user.c_str(), pass.c_str()); } @@ -765,7 +783,7 @@ bool Project::push(QString gDirTwoLevelUp) { if (!error) { error = (git_annotated_commit_from_ref(heads, repo, theirs_ref) != GIT_OK) - || (git_merge(repo, (const git_annotated_commit **)heads, 1, &merge_opts, &checkout_opts) != GIT_OK); + || (git_merge(repo, (const git_annotated_commit **)heads, 1, &merge_opts, &checkout_opts) != GIT_OK); if(error){ std::cout<<2<message << std::endl; + } else { + std::cout << "Unknown error occurred" << std::endl; + } return false; + } /* Finding the last commit on current repo and saves the entry in commit history table * Email | Commit_no @@ -837,17 +863,6 @@ bool Project::push(QString gDirTwoLevelUp) { */ char fullsha[42] = {0}; git_oid_tostr(fullsha, 41, &id); - QString sha = QString::fromStdString(fullsha); - //qDebug()<<"Last commit full hash :"<local_objects > 0) { -// ck = snprintf(buffer, 200, "Received %u/%u objects in %zu bytes (used %u local objects)", -// stats->indexed_objects, stats->total_objects, stats->received_bytes, stats->local_objects); -// } else { -// ck = snprintf(buffer, 200, "Received %u/%u objects in %zu bytes\n", -// stats->indexed_objects, stats->total_objects, stats->received_bytes); -// } -// if (ck >= 0 && ck < 200) { -// qDebug() << QString::fromLocal8Bit(buffer); -// } + // stats = git_remote_stats(remote); + // char buffer[200]; + // int ck; + + // if (stats->local_objects > 0) { + // ck = snprintf(buffer, 200, "Received %u/%u objects in %zu bytes (used %u local objects)", + // stats->indexed_objects, stats->total_objects, stats->received_bytes, stats->local_objects); + // } else { + // ck = snprintf(buffer, 200, "Received %u/%u objects in %zu bytes\n", + // stats->indexed_objects, stats->total_objects, stats->received_bytes); + // } + // if (ck >= 0 && ck < 200) { + // qDebug() << QString::fromLocal8Bit(buffer); + // } /** * 1. Check if the repository is already up to date (Don't perform git reset) @@ -992,42 +1007,46 @@ int Project::fetch() } git_revwalk_free(walker); qDebug() << "Final count = " << count; - if (count > 0) { - // perform git reset - QFile fetchHeadFile("../.git/refs/remotes/origin/HEAD"); - if (!fetchHeadFile.open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug() << "cannot open file: " << QFileInfo(fetchHeadFile).absoluteFilePath(); - goto cleanup; + //find local branch name + QString branchName; + QString gDir = gDirTwoLevelUp+"/.git/config"; + QFile f(gDir); + f.open(QIODevice::ReadOnly); + while(!f.atEnd()) { + QString line = f.readLine(); + if(line.contains("branch")){ + QStringList l = line.split(" "); + l[1] = l[1].remove("\""); + branchName = l[1].remove("]").simplified(); + break; + } } - - QString text = fetchHeadFile.readAll(); - QString nameOfFileStoresCommitID = text.remove("ref: ").remove("\n"); - fetchHeadFile.close(); - - nameOfFileStoresCommitID = "../.git/" + nameOfFileStoresCommitID; - QFile fileStoresCommitID(nameOfFileStoresCommitID); - if (!fileStoresCommitID.open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug() << "Cannot open file: " << QFileInfo(fileStoresCommitID).absoluteFilePath(); + f.close(); + // perform git merge + git_reference *local_branch_ref = NULL; + error = git_branch_lookup(&local_branch_ref, repo, branchName.toUtf8().constData(), GIT_BRANCH_LOCAL); + if (error < 0) { + qDebug() << "Cannot find local branch"; goto cleanup; } - QString commit_id = fileStoresCommitID.readAll(); - fileStoresCommitID.close(); - const char *sha = commit_id.toLocal8Bit(); - git_oid oid; - error = git_oid_fromstr(&oid, sha); + git_annotated_commit *remote_commit = NULL; + error = git_annotated_commit_lookup(&remote_commit, repo, &oid); if (error < 0) { + qDebug() << "Cannot find remote commit"; goto cleanup; } - git_object *obj; - error = git_object_lookup(&obj, repo, &oid, GIT_OBJECT_ANY); + + git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT; + error = git_merge(repo, (const git_annotated_commit **) &remote_commit, 1, &merge_opts, NULL); if (error < 0) { + qDebug() << "Cannot merge changes from remote branch"; goto cleanup; } - git_reset(repo, obj, GIT_RESET_HARD, NULL); - git_object_free(obj); + git_reference_free(local_branch_ref); + git_annotated_commit_free(remote_commit); } cleanup: @@ -1056,9 +1075,9 @@ bool Project::commit(std::string message) //check_lg2(git_signature_default(&sig, repo),"Unable to create a commit signature.","Perhaps 'user.name' and 'user.email' are not set"); int klass = lg2.check_lg2(git_signature_now(&sig, mName.c_str(), mEmail.c_str()),"Could not create signature",""); if (klass > 0) { -// if(sig) -// git_signature_free(sig); - return 0; + // if(sig) + // git_signature_free(sig); + return 0; } klass = lg2.check_lg2(git_revparse_ext(&parent, &ref, repo, "HEAD"),"Head not found",""); @@ -1120,17 +1139,37 @@ bool Project::commit(std::string message) char fullsha[42] = {0}; git_oid_tostr(fullsha, 41, &commit_id); QString sha = QString::fromStdString(fullsha); -// qDebug()<<"Last commit full hash :"<post(request, postData); + QEventLoop loop; + QObject::connect(reply, &QNetworkReply::finished, [=, &loop]() { + if (reply->error() == QNetworkReply::NoError) { + QByteArray data = reply->readAll(); + loop.quit(); + } else { + qDebug() << "Error:" << reply->errorString(); + } + reply->deleteLater(); + }); + loop.exec(); /** Clean up so we don't leak memory. */ git_tree_free(tree); @@ -1167,8 +1206,8 @@ bool Project::add_config() { //add username bool ok = false; QString quser = QInputDialog::getText(nullptr, QWidget::tr("Enter name:"), - QWidget::tr("Username:"), QLineEdit::Normal, - " ", &ok); + QWidget::tr("Username:"), QLineEdit::Normal, + " ", &ok); str = quser.toStdString(); error = git_config_set_string(sys_cfg, "user.name", (char*)str.c_str()); @@ -1189,8 +1228,8 @@ bool Project::add_config() { //add username bool ok = false; QString quser = QInputDialog::getText(nullptr, QWidget::tr("Enter email:"), - QWidget::tr("Email:"), QLineEdit::Normal, - " ", &ok); + QWidget::tr("Email:"), QLineEdit::Normal, + " ", &ok); std::string str = quser.toStdString(); error = git_config_set_string(sys_cfg, "user.email", (char*)str.c_str()); lg2.check_lg2(error, "Could not set user.email", ""); @@ -1212,45 +1251,45 @@ bool Project::add_config() { bool Project::add_git_config() { bool ret = true; - mName = "anujadumada8"; - mEmail = "anujadumada08@gmail.com"; - user = "anujadumada8"; - email = "anujadumada08@gmail.com"; -// QSettings appSettings("IIT-B", "OpenOCRCorrect"); -// appSettings.beginGroup("GitConfig"); -// QString username = appSettings.value("user", "").toString(); -// QString email = appSettings.value("email", "").toString(); -// if (username == "" || email == "") { -// // Take input from user and set the git config -//// bool ok = false; -// QString quser = "anujadumada8"; //QInputDialog::getText(nullptr, QWidget::tr("Enter username:"), QWidget::tr("Username:"), QLineEdit::Normal, "", &ok); -//// if (!ok) { -//// ret = ok; -//// goto exit; -//// } -// QString qemail = "anujadumada08@gmail.com";//QInputDialog::getText(nullptr, QWidget::tr("Enter email:"), QWidget::tr("Email:"), QLineEdit::Normal, "", &ok); -//// if (!ok) { -//// ret = ok; -//// goto exit; -//// } - -//// if (quser.trimmed() == "" || qemail.trimmed() == "" || !qemail.contains("@")) { -//// ret = false; -//// goto exit; -//// } - -// appSettings.setValue("user", quser); -// appSettings.setValue("email", qemail); - -// mName = quser.toStdString(); -// mEmail = qemail.toStdString(); -// } else { -// mName = username.toStdString(); -// mEmail = email.toStdString(); -// } - -//exit: -// appSettings.endGroup(); + mName = "anujadumada8"; + mEmail = "anujadumada08@gmail.com"; + user = "anujadumada8"; + email = "anujadumada08@gmail.com"; + // QSettings appSettings("IIT-B", "OpenOCRCorrect"); + // appSettings.beginGroup("GitConfig"); + // QString username = appSettings.value("user", "").toString(); + // QString email = appSettings.value("email", "").toString(); + // if (username == "" || email == "") { + // // Take input from user and set the git config + //// bool ok = false; + // QString quser = "anujadumada8"; //QInputDialog::getText(nullptr, QWidget::tr("Enter username:"), QWidget::tr("Username:"), QLineEdit::Normal, "", &ok); + //// if (!ok) { + //// ret = ok; + //// goto exit; + //// } + // QString qemail = "anujadumada08@gmail.com";//QInputDialog::getText(nullptr, QWidget::tr("Enter email:"), QWidget::tr("Email:"), QLineEdit::Normal, "", &ok); + //// if (!ok) { + //// ret = ok; + //// goto exit; + //// } + + //// if (quser.trimmed() == "" || qemail.trimmed() == "" || !qemail.contains("@")) { + //// ret = false; + //// goto exit; + //// } + + // appSettings.setValue("user", quser); + // appSettings.setValue("email", qemail); + + // mName = quser.toStdString(); + // mEmail = qemail.toStdString(); + // } else { + // mName = username.toStdString(); + // mEmail = email.toStdString(); + // } + + //exit: + // appSettings.endGroup(); return ret; } @@ -1437,13 +1476,13 @@ void Project::open_git_repo() if (gitdir.exists()) { lg2.check_lg2(git_repository_open(&repo, dir.c_str()), "Failed to Open", ""); -// add_config(); + // add_config(); add_git_config(); } else { lg2.check_lg2(git_repository_init(&repo, dir.c_str(),0), "Failed to Open", ""); -// add_config(); + // add_config(); add_git_config(); lg2_add(); create_initial_commit(repo); @@ -1569,6 +1608,139 @@ int Project::clone(QString url_, QString path) return error; } +bool Project::fetch_n_merge(QString gDirTwoLevelUp, QString mRole) { + int error = 0; + git_remote *remote = NULL; + git_reference *local_branch_ref = NULL; + git_annotated_commit *remote_commit = NULL; + git_revwalk *walker = NULL; + + git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT; + fetch_opts.callbacks.credentials = credentials_cb; + + git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT; + QString branchName; + QString gDir = gDirTwoLevelUp+"/.git/config"; + QFile f(gDir);QString folderPath; + if(mRole =="Verifier") + folderPath = gDirTwoLevelUp + "/CorrectorOutput/"; // specify the folder path + else if(mRole == "Corrector") + folderPath = gDirTwoLevelUp + "/VerifierOutput/"; // specify the folder path + QDir dir(folderPath); + QFileInfoList fileList = dir.entryInfoList(QDir::Files); + + // Check if 'origin' remote exists, if not create an anonymous remote + error = git_remote_lookup(&remote, repo, "origin"); + if (error < 0) { + error = git_remote_create_anonymous(&remote, repo, "origin"); + if (error < 0) { + qDebug() << "Error in git_remote"; + goto cleanup; + } + } + + // Perform the fetch with the configured refspecs from the config + error = git_remote_fetch(remote, NULL, &fetch_opts, "pull"); + if (error < 0) { + qDebug() << "Error in fetch"; + goto cleanup; + } + + // Check if the repository is already up to date + git_oid local_oid, remote_oid; + error = git_reference_name_to_id(&local_oid, repo, "HEAD"); + if (error < 0) { + qDebug() << "Error getting local OID"; + goto cleanup; + } + error = git_reference_name_to_id(&remote_oid, repo, "refs/remotes/origin/HEAD"); + if (error < 0) { + qDebug() << "Error getting remote OID"; + goto cleanup; + } + + if (git_oid_equal(&local_oid, &remote_oid)) { + qDebug() << "Repository is already up to date"; + git_reference_free(local_branch_ref); + git_annotated_commit_free(remote_commit); + git_remote_free(remote); + return true; + } + + // update the local branch to the latest commit + + f.open(QIODevice::ReadOnly); + while(!f.atEnd()) { + QString line = f.readLine(); + if(line.contains("branch")){ + QStringList l = line.split(" "); + l[1] = l[1].remove("\""); + branchName = l[1].remove("]").simplified(); + break; + } + } + f.close(); + + error = git_branch_lookup(&local_branch_ref, repo, branchName.toUtf8().constData(), GIT_BRANCH_LOCAL); + if (error < 0) { + qDebug() << "Cannot find local branch"; + goto cleanup; + } + + error = git_annotated_commit_lookup(&remote_commit, repo, &remote_oid); + if (error < 0) { + qDebug() << "Cannot find remote commit"; + goto cleanup; + } + + if(error<0){ + // An error occurred, print the error message + const git_error* err = giterr_last(); + if (err) { + std::cout << "Error: " << err->message << std::endl; + } else { + std::cout << "Unknown error occurred" << std::endl; + } + } + // change permissions of files + + for (const QFileInfo& fileInfo : fileList) { + QString filePath = fileInfo.filePath(); + // Set the file's permissions to both read and write mode + QFile::setPermissions(filePath, QFile::WriteOwner | QFile::WriteGroup | QFile::WriteOther | + QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther); + } + error = git_merge(repo, (const git_annotated_commit **)&remote_commit, 1, &merge_opts, NULL); + for (const QFileInfo& fileInfo : fileList) { + QString filePath = fileInfo.filePath(); + // Set the file's permissions to read only + QFile::setPermissions(filePath, QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther); + } + if (error < 0) { + qDebug() << "Cannot merge changes from remote branch"; + // An error occurred, print the error message + const git_error* err = giterr_last(); + if (err) { + std::cout << "Error: " << err->message << std::endl; + } else { + std::cout << "Unknown error occurred" << std::endl; + } + goto cleanup; + } + + qDebug() << "Changes merged successfully"; + git_reference_free(local_branch_ref); + git_annotated_commit_free(remote_commit); + git_remote_free(remote); + return true; + +cleanup: + git_reference_free(local_branch_ref); + git_annotated_commit_free(remote_commit); + git_remote_free(remote); + return false; +} + #ifdef _WIN32 /*! @@ -1584,7 +1756,7 @@ int Project::findNumberOfFilesInDirectory(std::string path) int file_count; replace(path.begin(), path.end(), '/', '\\'); - // std::string command = R"(dir /b /a-s-d ")" + path + R"(" | find /c /v "")"; // non-recursive count -> files in sub-directories will not be counted + // std::string command = R"(dir /b /a-s-d ")" + path + R"(" | find /c /v "")"; // non-recursive count -> files in sub-directories will not be counted std::string command = R"(dir /b /s /a-s-d ")" + path + R"(" | find /c /v "")"; // recursive count fp = _popen(command.c_str(), "r"); if (!fp) { @@ -1612,7 +1784,7 @@ int Project::findNumberOfFilesInDirectory(std::string path) FILE* fp; int file_count; -// std::string command = R"(find ")" + path + R"(" -maxdepth 1 -not -path '*/\.*' -type f | wc -l)"; // non-recursive count -> files in sub-directories will not be counted + // std::string command = R"(find ")" + path + R"(" -maxdepth 1 -not -path '*/\.*' -type f | wc -l)"; // non-recursive count -> files in sub-directories will not be counted std::string command = R"(find ")" + path + R"(" -not -path '*/\.*' -type f | wc -l)"; // recursive count fp = popen(command.c_str(), "r"); diff --git a/FrameWorkCode/Project.h b/FrameWorkCode/Project.h index 9a93a2cf..c4369e52 100755 --- a/FrameWorkCode/Project.h +++ b/FrameWorkCode/Project.h @@ -31,7 +31,7 @@ class Project { bool push(QString branchName); bool add_config(); bool add_git_config(); // New function which does not looks up the git configurations (regardless of any level) - int fetch(); + int fetch(QString); bool enable_push(bool increment); void AddTemp(Filter * f, QFile &pFile,QString prefix); int findNumberOfFilesInDirectory(std::string); @@ -72,6 +72,7 @@ class Project { void setProjectOpen(bool open) { m_isOpen = open; } + bool fetch_n_merge(QString gDirTwoLevelUp, QString mRole); private: bool m_isOpen = false; QVector mFiles; diff --git a/FrameWorkCode/Resources/about-modified.png b/FrameWorkCode/Resources/about-modified.png new file mode 100644 index 00000000..18545be6 Binary files /dev/null and b/FrameWorkCode/Resources/about-modified.png differ diff --git a/FrameWorkCode/Resources/backfinal.png b/FrameWorkCode/Resources/backfinal.png new file mode 100644 index 00000000..ce0ff83e Binary files /dev/null and b/FrameWorkCode/Resources/backfinal.png differ diff --git a/FrameWorkCode/Resources/bulleted_list-modified.png b/FrameWorkCode/Resources/bulleted_list-modified.png new file mode 100644 index 00000000..6685094f Binary files /dev/null and b/FrameWorkCode/Resources/bulleted_list-modified.png differ diff --git a/FrameWorkCode/Resources/close_project-modified.png b/FrameWorkCode/Resources/close_project-modified.png new file mode 100644 index 00000000..1958ac29 Binary files /dev/null and b/FrameWorkCode/Resources/close_project-modified.png differ diff --git a/FrameWorkCode/Resources/copy-modified.png b/FrameWorkCode/Resources/copy-modified.png new file mode 100644 index 00000000..7c93d4ee Binary files /dev/null and b/FrameWorkCode/Resources/copy-modified.png differ diff --git a/FrameWorkCode/Resources/cut-modified.png b/FrameWorkCode/Resources/cut-modified.png new file mode 100644 index 00000000..06046bd6 Binary files /dev/null and b/FrameWorkCode/Resources/cut-modified.png differ diff --git a/FrameWorkCode/Resources/date-modified.png b/FrameWorkCode/Resources/date-modified.png new file mode 100644 index 00000000..ba9bd821 Binary files /dev/null and b/FrameWorkCode/Resources/date-modified.png differ diff --git a/FrameWorkCode/Resources/decrease_size-modified.png b/FrameWorkCode/Resources/decrease_size-modified.png new file mode 100644 index 00000000..e9e3d3e8 Binary files /dev/null and b/FrameWorkCode/Resources/decrease_size-modified.png differ diff --git a/FrameWorkCode/Resources/delete-modified.png b/FrameWorkCode/Resources/delete-modified.png new file mode 100644 index 00000000..860b80b4 Binary files /dev/null and b/FrameWorkCode/Resources/delete-modified.png differ diff --git a/FrameWorkCode/Resources/download-modified.png b/FrameWorkCode/Resources/download-modified.png new file mode 100644 index 00000000..500925f6 Binary files /dev/null and b/FrameWorkCode/Resources/download-modified.png differ diff --git a/FrameWorkCode/Resources/equation-modified.png b/FrameWorkCode/Resources/equation-modified.png new file mode 100644 index 00000000..79faeb9c Binary files /dev/null and b/FrameWorkCode/Resources/equation-modified.png differ diff --git a/FrameWorkCode/Resources/exit-modified.png b/FrameWorkCode/Resources/exit-modified.png new file mode 100644 index 00000000..6a8c8040 Binary files /dev/null and b/FrameWorkCode/Resources/exit-modified.png differ diff --git a/FrameWorkCode/Resources/forfinal.png b/FrameWorkCode/Resources/forfinal.png new file mode 100644 index 00000000..e82911ae Binary files /dev/null and b/FrameWorkCode/Resources/forfinal.png differ diff --git a/FrameWorkCode/Resources/image-modified.png b/FrameWorkCode/Resources/image-modified.png new file mode 100644 index 00000000..8d0a04dd Binary files /dev/null and b/FrameWorkCode/Resources/image-modified.png differ diff --git a/FrameWorkCode/Resources/import-modified.png b/FrameWorkCode/Resources/import-modified.png new file mode 100644 index 00000000..704d841d Binary files /dev/null and b/FrameWorkCode/Resources/import-modified.png differ diff --git a/FrameWorkCode/Resources/increase_size-modified.png b/FrameWorkCode/Resources/increase_size-modified.png new file mode 100644 index 00000000..2cd87521 Binary files /dev/null and b/FrameWorkCode/Resources/increase_size-modified.png differ diff --git a/FrameWorkCode/Resources/indent-modified.png b/FrameWorkCode/Resources/indent-modified.png new file mode 100644 index 00000000..d601f3d8 Binary files /dev/null and b/FrameWorkCode/Resources/indent-modified.png differ diff --git a/FrameWorkCode/Resources/keyboard_shortcuts-modified.png b/FrameWorkCode/Resources/keyboard_shortcuts-modified.png new file mode 100644 index 00000000..d91f3ed1 Binary files /dev/null and b/FrameWorkCode/Resources/keyboard_shortcuts-modified.png differ diff --git a/FrameWorkCode/Resources/link-modified.png b/FrameWorkCode/Resources/link-modified.png new file mode 100644 index 00000000..2cfa26cf Binary files /dev/null and b/FrameWorkCode/Resources/link-modified.png differ diff --git a/FrameWorkCode/Resources/linux-modified.png b/FrameWorkCode/Resources/linux-modified.png new file mode 100644 index 00000000..56239219 Binary files /dev/null and b/FrameWorkCode/Resources/linux-modified.png differ diff --git a/FrameWorkCode/Resources/numbered_list-modified.png b/FrameWorkCode/Resources/numbered_list-modified.png new file mode 100644 index 00000000..ca070f48 Binary files /dev/null and b/FrameWorkCode/Resources/numbered_list-modified.png differ diff --git a/FrameWorkCode/Resources/outdent-modified.png b/FrameWorkCode/Resources/outdent-modified.png new file mode 100644 index 00000000..8378a719 Binary files /dev/null and b/FrameWorkCode/Resources/outdent-modified.png differ diff --git a/FrameWorkCode/Resources/paste(1)-modified.png b/FrameWorkCode/Resources/paste(1)-modified.png new file mode 100644 index 00000000..25932f15 Binary files /dev/null and b/FrameWorkCode/Resources/paste(1)-modified.png differ diff --git a/FrameWorkCode/Resources/resize-modified.png b/FrameWorkCode/Resources/resize-modified.png new file mode 100644 index 00000000..d7097850 Binary files /dev/null and b/FrameWorkCode/Resources/resize-modified.png differ diff --git a/FrameWorkCode/Resources/save_to_cloud-modified.png b/FrameWorkCode/Resources/save_to_cloud-modified.png new file mode 100644 index 00000000..9e843c89 Binary files /dev/null and b/FrameWorkCode/Resources/save_to_cloud-modified.png differ diff --git a/FrameWorkCode/Resources/select_all-modified.png b/FrameWorkCode/Resources/select_all-modified.png new file mode 100644 index 00000000..be3438bb Binary files /dev/null and b/FrameWorkCode/Resources/select_all-modified.png differ diff --git a/FrameWorkCode/Resources/sync_from_cloud-modified.png b/FrameWorkCode/Resources/sync_from_cloud-modified.png new file mode 100644 index 00000000..3357c186 Binary files /dev/null and b/FrameWorkCode/Resources/sync_from_cloud-modified.png differ diff --git a/FrameWorkCode/Resources/tab-modified.png b/FrameWorkCode/Resources/tab-modified.png new file mode 100644 index 00000000..b83e0315 Binary files /dev/null and b/FrameWorkCode/Resources/tab-modified.png differ diff --git a/FrameWorkCode/Resources/table-modified.png b/FrameWorkCode/Resources/table-modified.png new file mode 100644 index 00000000..da8e27e9 Binary files /dev/null and b/FrameWorkCode/Resources/table-modified.png differ diff --git a/FrameWorkCode/Resources/tutorial-modified.png b/FrameWorkCode/Resources/tutorial-modified.png new file mode 100644 index 00000000..e85126ca Binary files /dev/null and b/FrameWorkCode/Resources/tutorial-modified.png differ diff --git a/FrameWorkCode/Resources/update-modified.png b/FrameWorkCode/Resources/update-modified.png new file mode 100644 index 00000000..b8de8361 Binary files /dev/null and b/FrameWorkCode/Resources/update-modified.png differ diff --git a/FrameWorkCode/Resources/user-guide-modified.png b/FrameWorkCode/Resources/user-guide-modified.png new file mode 100644 index 00000000..4e9ab837 Binary files /dev/null and b/FrameWorkCode/Resources/user-guide-modified.png differ diff --git a/FrameWorkCode/Resources/user_login.png b/FrameWorkCode/Resources/user_login.png new file mode 100644 index 00000000..f821a0f1 Binary files /dev/null and b/FrameWorkCode/Resources/user_login.png differ diff --git a/FrameWorkCode/Resources/voice_typing-modified.png b/FrameWorkCode/Resources/voice_typing-modified.png new file mode 100644 index 00000000..af4ff388 Binary files /dev/null and b/FrameWorkCode/Resources/voice_typing-modified.png differ diff --git a/FrameWorkCode/Resources/windows-modified.png b/FrameWorkCode/Resources/windows-modified.png new file mode 100644 index 00000000..904bb505 Binary files /dev/null and b/FrameWorkCode/Resources/windows-modified.png differ diff --git a/FrameWorkCode/Symbols.cpp b/FrameWorkCode/Symbols.cpp index 52809dbe..60032613 100644 --- a/FrameWorkCode/Symbols.cpp +++ b/FrameWorkCode/Symbols.cpp @@ -10,6 +10,7 @@ * */ #include "Symbols.h" +#include "qclipboard.h" #include "ui_Symbols.h" SymbolsView *SymbolsView::symbolsView = 0; @@ -21,11 +22,12 @@ SymbolsView *SymbolsView::symbolsView = 0; * \param ui(new Ui::SymbolsView) * \brief sets the text for above 3 tabs and sets current tab as Diacritics */ -SymbolsView::SymbolsView(QWidget *parent) : QDialog(parent, Qt::WindowCloseButtonHint), ui(new Ui::SymbolsView) +SymbolsView::SymbolsView(QWidget *parent, CustomTextBrowser *curr_brow) : QDialog(parent, Qt::WindowCloseButtonHint), ui(new Ui::SymbolsView) { ui->setupUi(this); + this->cust_brow = curr_brow; ui->MathematicalSymbols->setText( - R"(𝑥 𝑦 𝑧 x̄ ȳ z̄ + R"(𝑥 𝑦 𝑧 x̄ ȳ z̄ ∀ ∁ ∂ ∃ ∄ ∅ ∆ ∇ ∈ ∉ ∊ ∋ ∌ ∍ ∎ ∏ ∐ ∑ − ± ∓ ∔ ∕ ∖ ∗ ∘ ∙ √ ∛ ∜ ∝ ∞ ∟ ∠ ∡ ∢ ∣ ∤ ∥ ∦ ∧ ∨ ∩ ∪ ∫ ∬ ∭ ∮ ∯ ∰ @@ -58,7 +60,7 @@ SymbolsView::SymbolsView(QWidget *parent) : QDialog(parent, Qt::WindowCloseButto A᳒ B᳒ C᳒ D᳒ E᳒ F᳒ G᳒ H᳒ I᳒ J᳒ K᳒ L᳒ M᳒ N᳒ O᳒ P᳒ Q᳒ R᳒ S᳒ T᳒ U᳒ V᳒ W᳒ X᳒ Y᳒ Z᳒ A᳙ B᳙ C᳙ D᳙ E᳙ F᳙ G᳙ H᳙ I᳙ J᳙ K᳙ L᳙ M᳙ N᳙ O᳙ P᳙ Q᳙ R᳙ S᳙ T᳙ U᳙ V᳙ W᳙ X᳙ Y᳙ Z᳙ • ⊙ ◉ ○ ◌ ● ⦿ ◆ ◇ ★ □ ✓ ✦ ➢ ➣ ➤ ▶ ▷ ⬛ ◼ ◾ ♦ ⚫ . ~ ` ! @ # $ % -^ & * ( ) - = + _ { [ ] } \ | / : ; ' " < , > . ?)"); +^ & * ( ) - = + _ { [ ] } \ | / : ; ' " < , > . ? ₹)"); setWindowTitle("Special Symbols"); ui->Diacritics->setText( R"(A @@ -184,7 +186,10 @@ SymbolsView::~SymbolsView() */ void SymbolsView::on_copyButton_clicked() { - currentTab->copy(); + QClipboard *clipboard = QApplication::clipboard(); + currentTab->copy(); + QString copiedText = clipboard->text(); + cust_brow->textCursor().insertText(copiedText); } /*! @@ -192,13 +197,14 @@ void SymbolsView::on_copyButton_clicked() * \brief Opens the symbol table whenever 𝛺 button is clicked on the tool menu * \param parent */ -SymbolsView* SymbolsView::openSymbolTable(QWidget *parent) +SymbolsView* SymbolsView::openSymbolTable(QWidget *parent, CustomTextBrowser *curr_brow) { if (symbolsView) { return symbolsView; } - - symbolsView = new SymbolsView(parent); + symbolsView = new SymbolsView(parent, curr_brow); + //<currentTab = symbolsView->ui->SpecialCharacters; return symbolsView; } diff --git a/FrameWorkCode/Symbols.h b/FrameWorkCode/Symbols.h index 9560e94f..20a0ff5f 100755 --- a/FrameWorkCode/Symbols.h +++ b/FrameWorkCode/Symbols.h @@ -1,6 +1,7 @@ #ifndef SymbolsView_H #define SymbolsView_H +#include "customtextbrowser.h" #include #include @@ -14,7 +15,7 @@ class SymbolsView : public QDialog public: ~SymbolsView(); - static SymbolsView* openSymbolTable(QWidget *); + static SymbolsView* openSymbolTable(QWidget *, CustomTextBrowser *); public slots: void on_copyButton_clicked(); @@ -27,7 +28,8 @@ private slots: Ui::SymbolsView *ui; QTextEdit *currentTab; static SymbolsView *symbolsView; - explicit SymbolsView(QWidget *parent = 0); + explicit SymbolsView(QWidget *parent = 0, CustomTextBrowser *curr_brow=0); + CustomTextBrowser *cust_brow; }; diff --git a/FrameWorkCode/Symbols.ui b/FrameWorkCode/Symbols.ui index d8d88c7a..1bd0da8c 100755 --- a/FrameWorkCode/Symbols.ui +++ b/FrameWorkCode/Symbols.ui @@ -25,7 +25,7 @@ background-color: rgb(32, 33, 72); } QPushButton:checked{background-color: rgb(136, 138, 133);} QPushButton:pressed {background-color: rgb(136, 138, 133);} - Copy + Insert Symbol diff --git a/FrameWorkCode/TreeModel.cpp b/FrameWorkCode/TreeModel.cpp index 10c18c9a..8e964566 100755 --- a/FrameWorkCode/TreeModel.cpp +++ b/FrameWorkCode/TreeModel.cpp @@ -46,7 +46,7 @@ Qt::ItemFlags TreeModel::flags(const QModelIndex & pIndex) const if (!pIndex.isValid()) { return Qt::NoItemFlags; } - return QAbstractItemModel::flags(pIndex); + return QAbstractItemModel::flags(pIndex); } /*! @@ -90,6 +90,7 @@ QModelIndex TreeModel::index(int pRow, int pColumn, const QModelIndex & pParent) //!Creates a new index on the given row if it doesn't exists TreeItem * childItem = parentItem->child(pRow); + if (childItem) { return createIndex(pRow, pColumn,childItem); } diff --git a/FrameWorkCode/about.cpp b/FrameWorkCode/about.cpp new file mode 100644 index 00000000..5cce547f --- /dev/null +++ b/FrameWorkCode/about.cpp @@ -0,0 +1,47 @@ +#include "about.h" +#include "ui_about.h" +#include +#include +#include +#include +#include + +about::about(QWidget *parent) : + QDialog(parent), + ui(new Ui::about) +{ + ui->setupUi(this); + this->setWindowTitle("About Udaan PE Tool"); + QString version = qApp->applicationVersion(); + ui->label->setTextFormat(Qt::RichText); + QString date ="Date: No info available."; + ui->label->setText("Udaan Post Editing Tool "+version+""); + QUrl url("https://api.github.com/repos/UDAAN-LEAP/leap-pe-tool/releases"); + QNetworkRequest request(url); //requesting url over the network + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + QNetworkAccessManager nam; //sending network request + QNetworkReply * reply = nam.get(request); + while(true){ + qApp->processEvents(); + if(reply->isFinished()) break; + } + + if(reply->isFinished()){ + QByteArray response_data = reply->readAll(); + QJsonDocument json = QJsonDocument::fromJson(response_data); + date = json[0]["published_at"].toString(); + } + ui->label_3->setText("Build released on: "+(!date.isEmpty()?date:"No info available")); + ui->label_2->setOpenExternalLinks(true); +} + +about::~about() +{ + delete ui; +} + +void about::on_pushButton_clicked() +{ + this->close(); +} + diff --git a/FrameWorkCode/about.h b/FrameWorkCode/about.h new file mode 100644 index 00000000..32899094 --- /dev/null +++ b/FrameWorkCode/about.h @@ -0,0 +1,25 @@ +#ifndef ABOUT_H +#define ABOUT_H + +#include + +namespace Ui { +class about; +} + +class about : public QDialog +{ + Q_OBJECT + +public: + explicit about(QWidget *parent = nullptr); + ~about(); + +private slots: + void on_pushButton_clicked(); + +private: + Ui::about *ui; +}; + +#endif // ABOUT_H diff --git a/FrameWorkCode/about.ui b/FrameWorkCode/about.ui new file mode 100644 index 00000000..e6678f9d --- /dev/null +++ b/FrameWorkCode/about.ui @@ -0,0 +1,90 @@ + + + about + + + + 0 + 0 + 619 + 337 + + + + Dialog + + + + + 10 + 30 + 71 + 61 + + + + image: url(:/Images/Resources/logonew.png); + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + 90 + 10 + 241 + 21 + + + + <html><head/><body><p><span style=" font-size:12pt; font-weight:700;">Udaan Post Editing Tool 3.5.10</span></p></body></html> + + + + + + 90 + 40 + 471 + 241 + + + + <html><head/><body><p>Based on Qt 5.15.2<br/>From revision <a href="https://github.com/UDAAN-LEAP/leap-pe-tool/commits/master"><span style=" text-decoration: underline; color:#0000ff;">visit logs</span></a><br/>Copyright 2019-2023 The Project Udaan, IIT Bombay.<br/><br/>The program is provided AS IS with NO WARRANTY OF ANY KIND,<br/>INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND <br/>FITNESS FOR A PARTICULAR PURPOSE.<br/><br/>The application logo is registered trademark of The <a href="https://udaanproject.org/"><span style=" text-decoration: underline; color:#0000ff;">Project Udaan</span></a>,<br/>IIT Bombay.</p><p>Contact us at: <a href="mailto:udaanprojectiitb@gmail.com"><span style=" text-decoration: underline; color:#0000ff;">udaanprojectiitb@gmail.com</span></a></p><p>To share your feedback, <a href="https://udaanproject.org/"><span style=" text-decoration: underline; color:#0000ff;">fill this form</span></a></p></body></html> + + + + + + 90 + 290 + 341 + 16 + + + + <html><head/><body><p><span style=" color:#241f31;">Build released on 23/03/2023</span></p></body></html> + + + + + + 510 + 300 + 89 + 25 + + + + Close + + + + + + diff --git a/FrameWorkCode/addkeyboardshortcut.cpp b/FrameWorkCode/addkeyboardshortcut.cpp new file mode 100644 index 00000000..af0d3049 --- /dev/null +++ b/FrameWorkCode/addkeyboardshortcut.cpp @@ -0,0 +1,46 @@ +#include "addkeyboardshortcut.h" + +addKeyboardShortcut::addKeyboardShortcut(QObject *parent) + : QAbstractItemModel(parent) +{ +} + +QVariant addKeyboardShortcut::headerData(int section, Qt::Orientation orientation, int role) const +{ + // FIXME: Implement me! +} + +QModelIndex addKeyboardShortcut::index(int row, int column, const QModelIndex &parent) const +{ + // FIXME: Implement me! +} + +QModelIndex addKeyboardShortcut::parent(const QModelIndex &index) const +{ + // FIXME: Implement me! +} + +int addKeyboardShortcut::rowCount(const QModelIndex &parent) const +{ + if (!parent.isValid()) + return 0; + + // FIXME: Implement me! +} + +int addKeyboardShortcut::columnCount(const QModelIndex &parent) const +{ + if (!parent.isValid()) + return 0; + + // FIXME: Implement me! +} + +QVariant addKeyboardShortcut::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + // FIXME: Implement me! + return QVariant(); +} diff --git a/FrameWorkCode/addkeyboardshortcut.h b/FrameWorkCode/addkeyboardshortcut.h new file mode 100644 index 00000000..6c7183e7 --- /dev/null +++ b/FrameWorkCode/addkeyboardshortcut.h @@ -0,0 +1,29 @@ +#ifndef ADDKEYBOARDSHORTCUT_H +#define ADDKEYBOARDSHORTCUT_H + +#include + +class addKeyboardShortcut : public QAbstractItemModel +{ + Q_OBJECT + +public: + explicit addKeyboardShortcut(QObject *parent = nullptr); + + // Header: + QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; + + // Basic functionality: + QModelIndex index(int row, int column, + const QModelIndex &parent = QModelIndex()) const override; + QModelIndex parent(const QModelIndex &index) const override; + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + int columnCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + +private: +}; + +#endif // ADDKEYBOARDSHORTCUT_H diff --git a/FrameWorkCode/addkeyshortcut.h b/FrameWorkCode/addkeyshortcut.h new file mode 100644 index 00000000..d99f07ad --- /dev/null +++ b/FrameWorkCode/addkeyshortcut.h @@ -0,0 +1,26 @@ +#ifndef ADDKEYSHORTCUT_H +#define ADDKEYSHORTCUT_H + +#include + +namespace Ui { +class addKeyShortcut; +} + +class addKeyShortcut : public QDialog +{ + Q_OBJECT + +public: + explicit addKeyShortcut( QString * s, QWidget *parent = nullptr); + ~addKeyShortcut(); + +private slots: + void on_buttonBox_accepted(); + +private: + Ui::addKeyShortcut *ui; + QString * s; +}; + +#endif // ADDKEYSHORTCUT_H diff --git a/FrameWorkCode/addshortcut.h b/FrameWorkCode/addshortcut.h new file mode 100644 index 00000000..e4f4ed52 --- /dev/null +++ b/FrameWorkCode/addshortcut.h @@ -0,0 +1,22 @@ +#ifndef ADDSHORTCUT_H +#define ADDSHORTCUT_H + +#include + +namespace Ui { +class addShortcut; +} + +class addShortcut : public QDialog +{ + Q_OBJECT + +public: + explicit addShortcut(QWidget *parent = nullptr); + ~addShortcut(); + +private: + Ui::addShortcut *ui; +}; + +#endif // ADDSHORTCUT_H diff --git a/FrameWorkCode/customtextbrowser.cpp b/FrameWorkCode/customtextbrowser.cpp index 09ccece9..f5b021c0 100644 --- a/FrameWorkCode/customtextbrowser.cpp +++ b/FrameWorkCode/customtextbrowser.cpp @@ -21,7 +21,23 @@ CustomTextBrowser::CustomTextBrowser(QWidget *parent): QTextBrowser(parent) { this->setReadOnly(false); c = new QCompleter((CustomTextBrowser *)this); - this->setCompleter(c); + this->setCompleter(c); + this->setPlaceholderText("How to Open a Project:\n" + "―――――――――――――――――――――――――――――――――――――\n" + "If your project is in a zip folder:\n" + " ⚫ Extract the project to a location of your choice,\n" + " ⚫ File > Open Project ('Ctrl + o'),\n" + " ⚫ Browse to the location where you extracted your project, and select it,\n" + " ⚫ Click 'Open'.\n" + "If you want to download a project:\n" + " ⚫ File > Import Project > Import.\n" + "If you want to download & open a project:\n" + " ⚫ File > Import Project > Import and Open.\n" + "User dashboard: Enter project ID, click 'Import Project' button, browse and select location to import project.\n" + "To open a recent project:\n" + " ⚫ File > Recent Project,\n" + " ⚫ Select the project you want to open from the list of recent projects.\n" + "For detailed instructions, you can refer to the User Guide under the 'Help' menu."); if(modelFlag == 0){ engModel = modelFromFile(":/WordList/wordlists/english.txt"); diff --git a/FrameWorkCode/dashboard.cpp b/FrameWorkCode/dashboard.cpp index e99997b2..ffc37a26 100755 --- a/FrameWorkCode/dashboard.cpp +++ b/FrameWorkCode/dashboard.cpp @@ -33,17 +33,42 @@ * \param max * \param repoMap */ -dashboard::dashboard(QWidget *parent, QString s, int max, QMap repoMap) : +dashboard::dashboard(QWidget *parent, QString s, int max, QMap repoMap, QString *p, bool * open) : QDialog(parent), ui(new Ui::dashboard) { ui->setupUi(this); + this->presentId.clear(); + this->btnMap.clear(); + + ui->Import_btn->setStyleSheet("color : rgb(20,52,167); text-align : centre; background-color :rgb(229,228,226); border-radius :5px;"); + ui->Import_Open_btn->setStyleSheet("color : rgb(20,52,167); text-align : centre; background-color :rgb(229,228,226); border-radius :5px;"); + qInstallMessageHandler(crashlog::myMessageHandler); setWindowTitle("User Dashboard"); this->repoMap = repoMap; - ui->textBrowser->setHtml(s); - ui->spinBox->setRange(0,max); + ui->scrollArea->setWidget(ui->verticalLayout->widget()); + ui->verticalLayout->setAlignment(Qt::AlignLeft); + + int index = 0; + QMapIteratori(repoMap); + while(i.hasNext()){ + i.next(); + index = i.key(); + auto btn = new QPushButton(); + + btn->setText(i.value()); + btn->setFixedHeight(50); + btn->setMinimumWidth(ui->scrollArea->width()); + btn->setStyleSheet("color : black; text-align : left; padding : 10px;background-color :rgb(229,228,226); border-radius :5px;"); + connect(btn, &QPushButton::clicked , [this, index] {clicked(index);}); + this->btnMap[index] = btn; + ui->verticalLayout->addWidget(btn); + } + + this->p = p; + this->toOpen = open; } /*! @@ -70,20 +95,24 @@ dashboard::~dashboard() */ void dashboard::on_pushButton_clicked() { - int id = ui->spinBox->value(); + QMapIteratori(presentId); QString path, url_; bool ok; int ret; - if(id == 0){ - QMessageBox::information(this, "Enter Project id", "Project id can't be zero", QMessageBox::Ok, QMessageBox::Ok); - return; - } - path = QFileDialog::getExistingDirectory(this, tr("Open Directory for importing project"), "/home", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + path = QFileDialog::getExistingDirectory(this, tr("Open Directory for importing all projects"), "/home", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); if (path == "") { qDebug() << "User cancelled import #1"; return; } + + + int id = 0; + while(i.hasNext()){ + i.next(); + if(i.value() == 1) id = i.key(); + } + url_ = "https://github.com/UdaanContentForLogging/"+repoMap[id]; if (url_.startsWith("git@github.com")) { qDebug() << "Not prepared to import using SSH. Please provide HTTPS URL"; @@ -96,18 +125,21 @@ void dashboard::on_pushButton_clicked() QFuture t1 = QtConcurrent::run(Project::clone, QString(url_), QString(path)); watcher.setFuture(t1); + QString s = "Importing "+repoMap[id] + "..."; spinner = new LoadingSpinner(this); - spinner->SetMessage("Importing Set...", "Importing..."); + spinner->SetMessage("Importing Set...", s); spinner->setModal(false); spinner->exec(); if ((ret = t1.result()) != 0) { - QMessageBox::information(this, "Error", "The project is already downloaded", QMessageBox::Ok, QMessageBox::Ok); + QMessageBox::information(this, "Error", ("The project is already downloaded\n" + repoMap[id]), QMessageBox::Ok, QMessageBox::Ok); qDebug()<<"Exited with return code"<deleteLater(); } +/*! + * \fn dashboard::clicked + * \brief This function sets index for each button's onClick slot + * \param integer index of button +*/ +void dashboard::clicked(int index){ + QPushButton* btn = this->btnMap[index]; + if(this->presentId[index] == 0){ + this->presentId[index] = 1; + this->totalClickedBooks++; + btn->setStyleSheet("color : black; text-align : left; padding : 10px;background-color :rgb(137,207,240); border-radius :5px;"); + } + else{ + this->presentId[index] = 0; + this->totalClickedBooks--; + btn->setStyleSheet("color : black; text-align : left; padding : 10px;background-color :rgb(229,228,226); border-radius :5px;"); + } +} + +/*! + * \fn dashboard::on_pushButton_2_clicked + * \brief This function will give info while clicking 'i' button +*/ +void dashboard::on_pushButton_2_clicked() +{ + QMessageBox * msg = new QMessageBox(); + + msg->setText("* All your books will appear here.\n* You can save changes to cloud to these books only.\n* Click on book name to import it locally."); + msg->exec(); +} + + +void dashboard::on_Import_Open_btn_clicked() +{ + if(this->totalClickedBooks == 1){ + on_pushButton_clicked(); + * (this->toOpen) = true; + } + else{ + QMessageBox * errMsg = new QMessageBox(); + errMsg->setText("Please select any one book"); + errMsg->exec(); + } +} + + +void dashboard::on_Import_btn_clicked() +{ + if(this->totalClickedBooks == 1){ + on_pushButton_clicked(); + } + else{ + QMessageBox * errMsg = new QMessageBox(); + errMsg->setText("Please select any one book"); + errMsg->exec(); + } +} + diff --git a/FrameWorkCode/dashboard.h b/FrameWorkCode/dashboard.h index df14d1c7..6b7e47de 100644 --- a/FrameWorkCode/dashboard.h +++ b/FrameWorkCode/dashboard.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace Ui { class dashboard; @@ -14,17 +15,31 @@ class dashboard : public QDialog Q_OBJECT public: - explicit dashboard(QWidget *parent, QString s, int max, QMap repoMap); + explicit dashboard(QWidget *parent, QString s, int max, QMap repoMap, QString *p, bool* open); ~dashboard(); private slots: void on_pushButton_clicked(); void stopSpinning(); + void clicked(int id); + + void on_pushButton_2_clicked(); + + void on_Import_Open_btn_clicked(); + + void on_Import_btn_clicked(); private: Ui::dashboard *ui; QMap repoMap; LoadingSpinner *spinner; + QString *p; + QMap presentId; + QMapbtnMap; + int selectedBooks = -1; + int totalClickedBooks = 0; + bool* toOpen; + }; #endif // DASHBOARD_H diff --git a/FrameWorkCode/dashboard.ui b/FrameWorkCode/dashboard.ui index 18a29830..700a2d1e 100644 --- a/FrameWorkCode/dashboard.ui +++ b/FrameWorkCode/dashboard.ui @@ -6,8 +6,8 @@ 0 0 - 791 - 488 + 589 + 574 @@ -22,46 +22,13 @@ - - - - -15 - 11 - 801 - 441 - - - - font: 16pt "Shobhika"; -background-color: rgb(238, 238, 236); -color: rgb(0, 0, 0); -margin-left: 25%; - - - - - - 670 - 460 - 111 - 25 - - - - QPushButton{background-color:rgb(227, 228, 228);border:0px; color: rgb(32, 33, 72); height:26.96px; width: 113.5px; padding-top:1px; border-radius:4.8px; padding-left:1.3px; selection-color: rgb(32, 33, 72); selection-background-color: rgb(136, 138, 133); -} QPushButton:checked{background-color: rgb(136, 138, 133);} QPushButton:pressed {background-color: rgb(136, 138, 133);} - - - Import Project - - - 10 - 450 + 9 + 9 31 - 31 + 32 @@ -82,34 +49,80 @@ margin-top:5px; - + - 490 - 460 - 67 - 21 + 9 + 47 + 569 + 469 - - + + + 551 + 451 + + + + + + 9 + 9 + 551 + 451 + + + + + 551 + 451 + + + + true + + + + + 0 + 0 + 549 + 449 + + + + + + + + + + + + + + 350 + 530 + 131 + 31 + - Project ID + Import And Open - + - 560 - 460 - 101 - 26 + 490 + 530 + 81 + 31 - - QSpinBox{background-color:rgb(227, 228, 228);border:0px; color: rgb(32, 33, 72); height:26.96px; width: 113.5px; padding-top:1px; border-radius:4.8px; padding-left:1.3px; selection-color: rgb(32, 33, 72); selection-background-color: rgb(136, 138, 133); -} QSpinBox:checked{background-color: rgb(136, 138, 133);} QSpinBox:pressed {background-color: rgb(136, 138, 133);} + + Import diff --git a/FrameWorkCode/equationeditor.cpp b/FrameWorkCode/equationeditor.cpp index ff3483ef..84ed4bd6 100644 --- a/FrameWorkCode/equationeditor.cpp +++ b/FrameWorkCode/equationeditor.cpp @@ -411,12 +411,12 @@ void equationeditor::enclosedMathBranButton(QString l, QString r){ */ void equationeditor::on_actionInsert_Equation_triggered() { - if(!QDir(gDirTwoLevelUp+"/Equations_").exists()) - QDir().mkdir(gDirTwoLevelUp+"/Equations_"); + if(!QDir("../Equations_").exists()) + QDir().mkdir("../Equations_"); - QDir dir(gDirTwoLevelUp+"/Equations_"); + QDir dir("../Equations_"); QString count = QString::number((dir.count()-1)/3 +1); - QString file_name = gDirTwoLevelUp+"/Equations_/"+count+".png"; + QString file_name = "../Equations_/"+count+".png"; typeset_edit.copyPng(2); QImage img = QGuiApplication::clipboard()->image(); img.save(file_name); @@ -424,7 +424,7 @@ void equationeditor::on_actionInsert_Equation_triggered() QString math_bran = typeset_edit.selectedMathBran(); if(!math_bran.isEmpty()) QGuiApplication::clipboard()->setText(MathBran::toLatex(math_bran)); // QString cnt = QString::number((dir.count()-1)/2 +1); - QFile file(gDirTwoLevelUp+"/Equations_/"+count+".tex"); + QFile file("../Equations_/"+count+".tex"); file.open(QIODevice::WriteOnly); QTextStream in(&file); in.setCodec("UTF-8"); @@ -432,7 +432,7 @@ void equationeditor::on_actionInsert_Equation_triggered() file.flush(); file.close(); //Save Mathbran notation file which will be useful in editing equations - QFile f(gDirTwoLevelUp+"/Equations_/"+count+".txt"); + QFile f("../Equations_/"+count+".txt"); if(!f.open(QIODevice::WriteOnly | QIODevice::Text)){ qDebug()<<"Can't open the file to save Mathbran notation!"; @@ -446,11 +446,10 @@ void equationeditor::on_actionInsert_Equation_triggered() f.close(); //Insert equation png at cursor position - QString filename = gDirTwoLevelUp+"/Equations_/"+count+".png"; + QString filename = "../Equations_/"+count+".png"; QString html = ""; QTextCursor cursor = curr_browser->textCursor(); cursor.insertHtml(html); - equationeditor::close(); } diff --git a/FrameWorkCode/fileName b/FrameWorkCode/fileName new file mode 100644 index 00000000..e69de29b diff --git a/FrameWorkCode/fonts/Jameel Noori Nastaleeq Regular/readme.html b/FrameWorkCode/fonts/Jameel Noori Nastaleeq Regular/readme.html new file mode 100644 index 00000000..1b3416bc --- /dev/null +++ b/FrameWorkCode/fonts/Jameel Noori Nastaleeq Regular/readme.html @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + + +
+

Jameel Noori Nastaleeq Regular

+

This font was downloaded from . You can visit for hundreds of free fonts.

+

View Charmap and other information Browse other free fonts

+

You will be shortly redirected to

+
+
+ + +
+ + + + diff --git a/FrameWorkCode/globalreplaceworker.cpp b/FrameWorkCode/globalreplaceworker.cpp index 797f095e..cfd4bac7 100644 --- a/FrameWorkCode/globalreplaceworker.cpp +++ b/FrameWorkCode/globalreplaceworker.cpp @@ -133,11 +133,15 @@ int GlobalReplaceWorker::writeGlobalCPairsToFiles(QString file_path, QMap"; text = ""; inputText.replace(text,html); diff --git a/FrameWorkCode/indentoptions.cpp b/FrameWorkCode/indentoptions.cpp new file mode 100644 index 00000000..aeb4e13f --- /dev/null +++ b/FrameWorkCode/indentoptions.cpp @@ -0,0 +1,28 @@ +#include "indentoptions.h" +#include "ui_indentoptions.h" + +indentOptions::indentOptions(QWidget *parent, int* left, int* right) : + QDialog(parent), + ui(new Ui::indentOptions) +{ + ui->setupUi(this); + this->left = left; + this->right = right; +} + +indentOptions::~indentOptions() +{ + delete ui; +} + +void indentOptions::on_buttonBox_accepted() +{ + int l = ui->textEdit_left->toPlainText().toInt(); + int r = ui->textEdit_right->toPlainText().toInt(); + + *left = l; + *right = r; + this->close(); + +} + diff --git a/FrameWorkCode/indentoptions.h b/FrameWorkCode/indentoptions.h new file mode 100644 index 00000000..2b08a8c8 --- /dev/null +++ b/FrameWorkCode/indentoptions.h @@ -0,0 +1,27 @@ +#ifndef INDENTOPTIONS_H +#define INDENTOPTIONS_H + +#include + +namespace Ui { +class indentOptions; +} + +class indentOptions : public QDialog +{ + Q_OBJECT + +public: + explicit indentOptions(QWidget *parent = nullptr, int * left = nullptr, int * right = nullptr); + ~indentOptions(); + +private slots: + void on_buttonBox_accepted(); + +private: + Ui::indentOptions *ui; + int * left; + int * right; +}; + +#endif // INDENTOPTIONS_H diff --git a/FrameWorkCode/indentoptions.ui b/FrameWorkCode/indentoptions.ui new file mode 100644 index 00000000..be88c252 --- /dev/null +++ b/FrameWorkCode/indentoptions.ui @@ -0,0 +1,100 @@ + + + indentOptions + + + + 0 + 0 + 370 + 247 + + + + Dialog + + + + + 71 + 19 + 271 + 41 + + + + font: 700 14pt "Ubuntu"; + + + <html><head/><body><p><span style=" font-size:12pt;">Set Indentation (in cm)</span></p></body></html> + + + + + + 41 + 99 + 81 + 16 + + + + font: 15pt "Ubuntu"; + + + <html><head/><body><p><span style=" font-size:12pt;">Left</span></p></body></html> + + + + + + 170 + 150 + 171 + 31 + + + + + + + 40 + 140 + 71 + 31 + + + + font: 15pt "Ubuntu"; + + + <html><head/><body><p><span style=" font-size:12pt;">Right</span></p></body></html> + + + + + + 170 + 90 + 171 + 31 + + + + + + + 170 + 210 + 166 + 25 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + diff --git a/FrameWorkCode/leap-pe-tool b/FrameWorkCode/leap-pe-tool new file mode 160000 index 00000000..781f1038 --- /dev/null +++ b/FrameWorkCode/leap-pe-tool @@ -0,0 +1 @@ +Subproject commit 781f1038f6e92c6a7dc6b8feaa35790152555880 diff --git a/FrameWorkCode/loadingspinner.ui b/FrameWorkCode/loadingspinner.ui index da5157b7..bc6e3c21 100644 --- a/FrameWorkCode/loadingspinner.ui +++ b/FrameWorkCode/loadingspinner.ui @@ -6,8 +6,8 @@ 0 0 - 248 - 88 + 293 + 158
@@ -46,14 +46,20 @@ 120 - 40 - 111 - 31 + 50 + 151 + 91 Loading... + + false + + + true + diff --git a/FrameWorkCode/logs/corrected_page.txt b/FrameWorkCode/logs/corrected_page.txt new file mode 100644 index 00000000..e69de29b diff --git a/FrameWorkCode/logs/marked_for_review_page.txt b/FrameWorkCode/logs/marked_for_review_page.txt new file mode 100644 index 00000000..e69de29b diff --git a/FrameWorkCode/logs/verified_page.txt b/FrameWorkCode/logs/verified_page.txt new file mode 100644 index 00000000..e69de29b diff --git a/FrameWorkCode/main.cpp b/FrameWorkCode/main.cpp index 7b97f61f..e1db679e 100755 --- a/FrameWorkCode/main.cpp +++ b/FrameWorkCode/main.cpp @@ -88,11 +88,13 @@ int main(int argc, char *argv[]) //!Setting Icons and stylesheet QApplication a(argc, argv); +#ifdef __unix__ QIcon windowIcon(":/Images/Resources/logonew.png"); a.setWindowIcon(windowIcon); //Sets icon of the GUI window. +#endif a.setStyleSheet("QMessageBox{font: 15px \"Work Sans\"; background:rgb(32, 33, 72);} QMessageBox QLabel{color:white;} QMessageBox QPushButton{background-color:rgb(227, 228, 228);border:0px; color: rgb(32, 33, 72); height:26.96px; width: 113.5px; padding-top:1px; border-radius:4.8px; padding-left:1.3px; selection-color: rgb(32, 33, 72); selection-background-color: rgb(136, 138, 133);} QMessageBox QPushButton:checked{background-color: rgb(136, 138, 133);} QMessageBox QPushButton:pressed {background-color: rgb(136, 138, 133);}"); a.setApplicationName( QStringLiteral( "Udaan Editing Tool" ) ); - a.setApplicationVersion("v3.5.9"); + a.setApplicationVersion("v4.0"); a.setAttribute(Qt::AA_EnableHighDpiScaling); //! Writing Log Files diff --git a/FrameWorkCode/mainwindow.cpp b/FrameWorkCode/mainwindow.cpp index 61c20921..d6523bfe 100644 --- a/FrameWorkCode/mainwindow.cpp +++ b/FrameWorkCode/mainwindow.cpp @@ -1,6 +1,9 @@ #include "mainwindow.h" #include "dashboard.h" +#include "indentoptions.h" #include "qobjectdefs.h" +#include "qtablewidget.h" +#include "threadingpush.h" #include "ui_mainwindow.h" #include "averageaccuracies.h" #include "eddis.h" @@ -69,8 +72,6 @@ #include "globalreplaceworker.h" #include "customtextbrowser.h" #include "pdfrangedialog.h" -#include -#include #include #include "printworker.h" #include @@ -83,6 +84,14 @@ #include #include #include +#include +#include +#ifdef Q_OS_WIN +#include +#include +#endif + + map LSTM; map Dict, GBook, IBook, PWords, PWordsP,ConfPmap,ConfPmapFont,CPairRight; @@ -114,6 +123,7 @@ int openedFileWords; bool gSaveTriggered = 0; bool LoadDataFlag = 1; bool uploadReplaceFlag = 0; + map filestructure_fw; QMap mapOfReplacements; @@ -139,6 +149,11 @@ QMap globallyReplacedWords; QList filesChangedUsingGlobalReplace; +QString defaultStyle; +QList selectedItems; +QTableWidget *m_table; +QDialog *tableDialog; + /*! * \fn MainWindow::MainWindow @@ -148,11 +163,43 @@ QList filesChangedUsingGlobalReplace; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),ui(new Ui::MainWindow) { ui->setupUi(this); + QMenuBar *menubar = this->menuBar(); + QIcon icon = QIcon(":/Images/Resources/user_login.png"); + ui->pushButton_5->setIcon(icon); + menubar->setCornerWidget(ui->pushButton_5, Qt::TopRightCorner); CustomTextBrowser *customtextbrowser = new CustomTextBrowser(); customtextbrowser->setStyleSheet("background-color:white; color:black;"); ui->splitter->replaceWidget(1,customtextbrowser); customtextbrowser->show(); + + customtextbrowser->setStyleSheet("padding-top: 100%; padding-left: 40%; color: #1c1c1c; background-color: white;"); + connect(customtextbrowser, &QTextBrowser::textChanged, this, [=]() { + if(!QString::compare(QString(), customtextbrowser->toPlainText())) { + customtextbrowser->setStyleSheet("padding-top: 100%; padding-left: 40%; color: #1c1c1c; background-color: white;"); + customtextbrowser->setPlaceholderText("How to Open a Project:\n" + "―――――――――――――――――――――――――――――――――――――\n" + "If your project is in a zip folder:\n" + " ⚫ Extract the project to a location of your choice,\n" + " ⚫ File > Open Project ('Ctrl + o'),\n" + " ⚫ Browse to the location where you extracted your project, and select it,\n" + " ⚫ Click 'Open'.\n" + "If you want to download a project:\n" + " ⚫ File > Import Project > Import.\n" + "If you want to download & open a project:\n" + " ⚫ File > Import Project > Import and Open.\n" + "User dashboard: Enter project ID, click 'Import Project' button, browse and select location to import project.\n" + "To open a recent project:\n" + " ⚫ File > Recent Project,\n" + " ⚫ Select the project you want to open from the list of recent projects.\n" + "For detailed instructions, you can refer to the User Guide under the 'Help' menu."); + } else { + customtextbrowser->setStyleSheet("padding-top: 0; padding-left: 0; color: black; background-color: white;"); + customtextbrowser->setPlaceholderText("hello"); + } + }); + + ui->splitter->setStyleSheet("background-color:white;color:black;"); ui->splitter_2->setStyleSheet("background-color:rgb(32, 33, 72);color:black;"); @@ -169,8 +216,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),ui(new Ui::MainWin ui->lineEdit->setReadOnly(true); ui->lineEdit_2->setReadOnly(true); ui->lineEdit_3->setReadOnly(true); + ui->forward_Button->setVisible(false); + ui->pushButton_6->setVisible(false); + ui->actionFetch_2->setVisible(false); - // googleAuth(); QSettings settings("IIT-B", "OpenOCRCorrect"); settings.beginGroup("cloudSave"); settings.remove(""); @@ -201,16 +250,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),ui(new Ui::MainWin if(value != "dna" && value != "loggedIn"){ login(); } - //show login/logout options - settings.endGroup(); - if(value != "loggedIn"){ - this->ui->actionLogin->setVisible(true); - this->ui->actionLogout->setVisible(false); - } - else{ - this->ui->actionLogin->setVisible(false); - this->ui->actionLogout->setVisible(true); - } QString common = "डॉ - xZ,, अ - a,, आ/ ा - A,, इ/ ि - i,, ई/ ी - I,, उ/ ु - u,, ऊ/ ू - U,, ऋ/ ृ - f,, ए/ े - e,, ऐ/ ै - E,, ओ/ ो - o,, औ/ ौ - O,, ं - M,, ः - H,, ँ - ~,, ज्ञ - jYa,, त्र - tra,, श्र - Sra,, क्ष्/क्ष - kz/kza,, द्य्/द्य - dy/dya,, क्/क - k/ka,, ख्/ख - K/Ka,, ग्/ग - g/ga,, घ्/घ - G/Ga,, ङ्/ङ - N/Na,, च्/च - c/ca,, छ्/छ - C/Ca,, ज्/ज - j/ja,, झ्/झ - J/Ja,, ञ्/ञ - Y/Ya,, ट्/ट - w/wa,, ठ्/ठ - W/Wa,, ड्/ड - q/qa,, ढ्/ढ - Q/Qa,, ण्/ण - R/Ra,, त्/त - t/ta,, थ्/थ - T/Ta,, द्/द - d/da,, ध्/ध - D/Da,, न्/न - n/na,, प्/प - p/pa,, फ्/फ - P/Pa,, ब्/ब - b/ba,, भ्/भ - B/Ba,, म्/म - m/ma,, य्/य - y/ya,, र्/र - r/ra,, ल्/ल - l/la,, व्/व - v/va,, श्/श - S/Sa,, ष्/ष - z/za,, स्/स - s/sa,, ह्/ह - h/ha,, ळ्/ळ - L/La,, १ - 1,, २ - 2,, ३ - 3,, ४ - 4,, ५ - 5,, ६ - 6,, ७ - 7,, ८ - 8,, ९ - 9,, ० - 0,, । - |,, ॥ - ||"; gSanskrit = "SLP1 Sanskrit Guide:"; @@ -260,101 +299,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),ui(new Ui::MainWin QFontDatabase::addApplicationFont(":/Fonts/fonts/brhkndrn/brhkndrn.ttf"); QFontDatabase::addApplicationFont(":/Fonts/fonts/Nudi 1/Nudi 01 e Regular.ttf"); QFontDatabase::addApplicationFont(":/Fonts/fonts/Chanakya Regular/Chanakya Regular.ttf"); - - if (!isVerifier) - { - ui->actionHighlight->setEnabled(false); - } + // QFontDatabase::addApplicationFont(":/Fonts/fonts/Jameel Noori Nastaleeq Regular/Jameel Noori Nastaleeq Regular.ttf"); // Hiding options - - ui->actionLoadDict->setVisible(false); - ui->actionLoadOCRWords->setVisible(false); - ui->actionLoadDomain->setVisible(false); - ui->actionLoadSubPS->setVisible(false); - ui->actionLoadConfusions->setVisible(false); - ui->actionLoadGDocPage->setVisible(false); - ui->menuSelectLanguage->setTitle(""); - ui->menuCreateReports->setTitle(""); - //compare options ui->viewComments->setVisible(false); ui->compareCorrectorOutput->setVisible(false); ui->compareVerifierOutput->setVisible(false); - // ui->pushButton_2->setVisible(false); - - // Disabling some buttons while opening the tool - - // File Menu - ui->actionSave->setEnabled(false); - ui->actionSave_As->setEnabled(false); - ui->actionSpell_Check->setEnabled(false); - ui->actionLoad_Prev_Page->setEnabled(false); - ui->actionLoad_Next_Page->setEnabled(false); - ui->actionToDevanagari->setEnabled(false); - ui->actionToSlp1->setEnabled(false); - ui->actionLoadGDocPage->setEnabled(false); - ui->actionLoadData->setEnabled(false); - ui->actionLoadDict->setEnabled(false); - ui->actionLoadOCRWords->setEnabled(false); - ui->actionLoadDomain->setEnabled(false); - ui->actionLoadSubPS->setEnabled(false); - ui->actionLoadConfusions->setEnabled(false); - ui->actionSugg->setVisible(false); - - // Edit Menu - ui->actionUndo->setEnabled(false); - ui->actionRedo->setEnabled(false); - ui->actionFind_and_Replace->setEnabled(false); - ui->actionUndo_Global_Replace->setEnabled(false); - ui->actionUpload->setEnabled(false); - - // Language Menu - ui->actionSanskrit_2->setEnabled(false); - ui->actionEnglish->setEnabled(false); - ui->actionHindi->setEnabled(false); - - // Reports Menu - ui->actionAccuracyLog->setEnabled(false); - ui->actionViewAverageAccuracies->setEnabled(false); - - // View Menu - ui->actionAllFontProperties->setEnabled(false); - ui->actionBold->setEnabled(false); - ui->actionItalic->setEnabled(false); - ui->actionHighlight->setEnabled(false); // Already disabled in Corrector mode - ui->actionLeftAlign->setEnabled(false); - ui->actionRightAlign->setEnabled(false); - ui->actionCentreAlign->setEnabled(false); - ui->actionJusitfiedAlign->setEnabled(false); - ui->actionSuperscript->setEnabled(false); - ui->actionSubscript->setEnabled(false); - ui->actionInsert_Horizontal_Line->setEnabled(false); - ui->actionFontBlack->setEnabled(false); - ui->actionInsert_Tab_Space->setEnabled(false); - ui->actionPDF_Preview->setEnabled(false); - - // Table Menu inside View Menu - ui->actionInsert_Table_2->setEnabled(false); - ui->actionInsert_Columnleft->setEnabled(false); - ui->actionInsert_Columnright->setEnabled(false); - ui->actionInsert_Rowabove->setEnabled(false); - ui->actionInsert_Rowbelow->setEnabled(false); - ui->actionRemove_Column->setEnabled(false); - ui->actionRemove_Row->setEnabled(false); - - // Versions Menu - ui->actionFetch_2->setEnabled(false); - ui->actionTurn_In->setEnabled(false); - ui->actionVerifier_Turn_In->setEnabled(false); - - // Download Menu - ui->actionas_PDF->setEnabled(false); - - ui->actionSymbols->setEnabled(false); - ui->actionZoom_In->setEnabled(false); - ui->actionZoom_Out->setEnabled(false); - ui->actionUnderline->setDisabled(true); - ui->actionJusitfiedAlign->setEnabled(false); + //to set default tab to project widget ui->tabWidget->setCurrentWidget(ui->tab_2); //recording @@ -367,13 +318,29 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),ui(new Ui::MainWin ui->comboBox->addItem(QStringLiteral("Bengali"), QVariant("bn-IN")); ui->comboBox->addItem(QStringLiteral("Gujarati"), QVariant("gu-IN")); ui->comboBox->addItem(QStringLiteral("Hindi"), QVariant("hi-IN")); - ui->comboBox->addItem(QStringLiteral("Kannada"), QVariant("ka-IN")); + ui->comboBox->addItem(QStringLiteral("Kannada"), QVariant("kn-IN")); ui->comboBox->addItem(QStringLiteral("Malayalam"), QVariant("ml-IN")); ui->comboBox->addItem(QStringLiteral("Marathi"), QVariant("mr-IN")); ui->comboBox->addItem(QStringLiteral("Tamil"), QVariant("ta-IN")); ui->comboBox->addItem(QStringLiteral("Telugu"), QVariant("te-IN")); ui->comboBox->addItem(QStringLiteral("Urdu"), QVariant("ur-IN")); ui->comboBox->addItem(QStringLiteral("Punjabi"), QVariant("pa-Guru-IN")); + + //disable features + e_d_features(false); + + + ui->corrected->setVisible(false); + ui->verified->setVisible(false); + ui->mark_review->setVisible(false); + ui->status->setVisible(false); + + ui->corrected->setEnabled(false); + ui->verified->setEnabled(false); + ui->mark_review->setEnabled(false); + + //saves current path - useful for auto upgrade feature + m_update_path = QDir().currentPath(); } /*! @@ -387,11 +354,31 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),ui(new Ui::MainWin bool MainWindow::setRole(QString role) { this->mRole = role; + QSettings settings("IIT-B", "OpenOCRCorrect"); + settings.beginGroup("prev-version"); + QString link; + link = settings.value("link").toString(); + qDebug() << "path: " << link; + if (!link.isEmpty()) { + qDebug() << "removed :" << link; + QDir folderDir(link); + + // Remove the folder and its contents recursively + if (folderDir.exists() && folderDir.removeRecursively()) { + qDebug() << link << "Folder removed successfully!"; + settings.remove(""); + } + else { + qDebug() << link << "Failed to remove folder!"; + } + + } + settings.endGroup(); //! Checking role if(mRole == "Admin") { - QSettings settings("IIT-B", "OpenOCRCorrect"); + settings.beginGroup("SetRole"); QString role; role = settings.value("role").toString(); @@ -464,11 +451,17 @@ bool MainWindow::setRole(QString role) {"VerifierOutput","VerifierOutput" } }; isVerifier = 1; - ui->actionTurn_In->setVisible(false); //set false to its visibility; now shown - ui->actionTurn_In->setEnabled(false); //disable the option + + + + //ui->actionTurn_In->setVisible(false); //set false to its visibility; now shown + //ui->actionTurn_In->setEnabled(false); //disable the option + + this->setWindowTitle("Udaan Editing Tool-Verifier"); + } else if(mRole == "Corrector") { @@ -481,14 +474,13 @@ bool MainWindow::setRole(QString role) ui->compareVerifierOutput->setVisible(false); ui->compareVerifierOutput->setEnabled(false); - ui->actionVerifier_Turn_In->setVisible(false); - ui->actionVerifier_Turn_In->setEnabled(false); - ui->viewComments->setVisible(false); ui->viewComments->setEnabled(false); + + isVerifier = 0; - this->setWindowTitle("Udaan Editing Tool-Corrector"); + this->setWindowTitle("Udaan PE Tool-Corrector"); } else { @@ -546,102 +538,6 @@ void writeJsonFile(QString filepath, QJsonObject mainObj) jsonFile.close(); } -/*! - * \fn MainWindow::authenticate - * \brief It starts the authentication process of the user. - */ -void MainWindow::authenticate() { - this->google->grant(); -} - -/*! - * \fn MainWindow::googleAuth - * \brief Opens a browser where user has to sign in through his/her google account to authenticate - */ -void MainWindow::googleAuth() -{ - google = new QOAuth2AuthorizationCodeFlow; - google->setScope("email"); - connect(google, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, - &QDesktopServices::openUrl); - - QProcess process; - process.execute("curl -d -X -k -POST --header " - "\"Content-type:application/x-www-form-urlencoded\" https://udaaniitb.aicte-india.org/udaan/email/ -o client.json"); - - QFile jsonFile("client.json"); - jsonFile.open(QIODevice::ReadOnly | QIODevice::Text); - QByteArray data = jsonFile.readAll(); - - QJsonParseError errorPtr; - QJsonDocument document = QJsonDocument::fromJson(data, &errorPtr); - QJsonObject mainObj = document.object(); - jsonFile.close(); - QString id = mainObj.value("client_id").toString(); - QString secret = mainObj.value("client_secret").toString(); - QFile::remove("client.json"); - QByteArray array = id.toLocal8Bit(); - const auto clientId = array.data(); - const QUrl authUri("https://accounts.google.com/o/oauth2/auth"); - const QUrl tokenUri("https://oauth2.googleapis.com/token"); - array = secret.toLocal8Bit(); - const auto clientSecret = array.data(); - const auto port = 8080; - - google->setAuthorizationUrl(authUri); - google->setClientIdentifier(clientId); - google->setAccessTokenUrl(tokenUri); - google->setClientIdentifierSharedKey(clientSecret); - - google->setModifyParametersFunction([](QAbstractOAuth::Stage stage, QVariantMap* parameters) { - // Percent-decode the "code" parameter so Google can match it - if (stage == QAbstractOAuth::Stage::RequestingAccessToken) { - QByteArray code = parameters->value("code").toByteArray(); - (*parameters)["code"] = QUrl::fromPercentEncoding(code); - } - }); - - QOAuthHttpServerReplyHandler* replyHandler = new QOAuthHttpServerReplyHandler(port, this); - google->setReplyHandler(replyHandler); - connect(this->google, &QOAuth2AuthorizationCodeFlow::granted, [=](){ - const QString token = this->google->token(); - emit gotToken(token); - - auto reply = this->google->get(QUrl("https://www.googleapis.com/oauth2/v2/userinfo?access_token="+token)); - connect(reply, &QNetworkReply::finished, [reply, token, this](){ - const auto objectDetails = (QString)reply->readAll(); - QJsonDocument jsonResponse = QJsonDocument::fromJson(objectDetails.toUtf8()); - QJsonObject jsonObject = jsonResponse.object(); - QString email = jsonObject["email"].toString(); - QString id = jsonObject["id"].toString(); - // const QByteArray data = email.toUtf8(); - // qDebug()<<"hash"<ui->actionLogin->setVisible(false); - this->ui->actionLogout->setVisible(true); - }); - }); - -} QString file = ""; bool fileFlag = 0; QElapsedTimer myTimer; @@ -1205,6 +1101,8 @@ void MainWindow::on_actionEnglish_triggered() */ void MainWindow::on_actionOpen_Project_triggered() { //Version Based //QString ProjFile; + + int totalFileCountInDir = 0; QMap fileCountInDir; //to choose between recent three files @@ -1220,7 +1118,7 @@ void MainWindow::on_actionOpen_Project_triggered() { //Version Based { ProjFile = RecentProjFile3; } - else{ + else if(!import_flag){ ProjFile = QFileDialog::getOpenFileName(this, "Open Project", "./", tr("Project(*.xml)")); //Opens only if the file name is Project.xml } @@ -1228,6 +1126,9 @@ void MainWindow::on_actionOpen_Project_triggered() { //Version Based return; isRecentProjclick = false; + // Set the file's permissions to readonly + qDebug()<status->setVisible(true); + + if(mRole == "Corrector"){ + ui->corrected->setVisible(true); + ui->corrected->setEnabled(true); + } + + if(mRole == "Verifier"){ + ui->verified->setVisible(true); + ui->mark_review->setVisible(true); + ui->verified->setEnabled(true); + ui->mark_review->setEnabled(true); + } + + if (result != 0) { QMessageBox::warning(0, "Project XML file Error", "Project XML File is corrupted \n\nError "+ QString::fromStdString(std::to_string(verifySetObj.getErrorCode()))+": " + verifySetObj.getErrorString()+"\n\nPlease Report this to your administrator"); return; @@ -1399,6 +1319,8 @@ void MainWindow::on_actionOpen_Project_triggered() { //Version Based } QString projectWindowStylesheet = ui->treeView->styleSheet(); + + int indexOfScrollBarProp = projectWindowStylesheet.indexOf("QScrollBar::handle:vertical"); int heightProp = projectWindowStylesheet.indexOf("height:", indexOfScrollBarProp); @@ -1414,6 +1336,7 @@ void MainWindow::on_actionOpen_Project_triggered() { //Version Based int insertHeightProp = projectWindowStylesheet.indexOf("{", indexOfScrollBarProp) + 1; projectWindowStylesheet.insert(insertHeightProp, "height:" + heightValue); } + ui->treeView->setStyleSheet(projectWindowStylesheet); UpdateFileBrekadown(); //Reset the current file and dir levels @@ -1482,79 +1405,19 @@ void MainWindow::on_actionOpen_Project_triggered() { //Version Based RecentPageInfo(); } - // Enabling the buttons again after a project is opened - // File Menu - ui->actionSave->setEnabled(true); - ui->actionSave_As->setEnabled(true); - ui->actionSpell_Check->setEnabled(true); - ui->actionLoad_Prev_Page->setEnabled(true); - ui->actionLoad_Next_Page->setEnabled(true); - ui->actionToDevanagari->setEnabled(true); - ui->actionToSlp1->setEnabled(true); - ui->actionLoadGDocPage->setEnabled(true); - ui->actionLoadData->setEnabled(true); - ui->actionLoadDict->setEnabled(true); - ui->actionLoadOCRWords->setEnabled(true); - ui->actionLoadDomain->setEnabled(true); - ui->actionLoadSubPS->setEnabled(true); - ui->actionLoadConfusions->setEnabled(true); - ui->actionSugg->setEnabled(true); - - // Edit Menu - ui->actionUndo->setEnabled(true); - ui->actionRedo->setEnabled(true); - ui->actionFind_and_Replace->setEnabled(true); - ui->actionUndo_Global_Replace->setEnabled(true); - ui->actionUpload->setEnabled(true); - - // Language Menu - ui->actionSanskrit_2->setEnabled(true); - ui->actionEnglish->setEnabled(true); - ui->actionHindi->setEnabled(true); - - // Reports Menu - ui->actionAccuracyLog->setEnabled(true); - ui->actionViewAverageAccuracies->setEnabled(true); - - // View Menu - ui->actionAllFontProperties->setEnabled(true); - ui->actionBold->setEnabled(true); - ui->actionItalic->setEnabled(true); - ui->actionLeftAlign->setEnabled(true); - ui->actionRightAlign->setEnabled(true); - ui->actionCentreAlign->setEnabled(true); - ui->actionJusitfiedAlign->setEnabled(true); - ui->actionSuperscript->setEnabled(true); - ui->actionSubscript->setEnabled(true); - ui->actionInsert_Horizontal_Line->setEnabled(true); - ui->actionFontBlack->setEnabled(true); - ui->actionInsert_Tab_Space->setEnabled(true); - ui->actionPDF_Preview->setEnabled(true); - ui->actionUnderline->setDisabled(false); - ui->actionJusitfiedAlign->setEnabled(true); - // if (isVerifier) - ui->actionHighlight->setEnabled(true); - - // Table Menu inside View Menu - ui->actionInsert_Table_2->setEnabled(true); - ui->actionInsert_Columnleft->setEnabled(true); - ui->actionInsert_Columnright->setEnabled(true); - ui->actionInsert_Rowabove->setEnabled(true); - ui->actionInsert_Rowbelow->setEnabled(true); - ui->actionRemove_Column->setEnabled(true); - ui->actionRemove_Row->setEnabled(true); - - // Versions Menu - ui->actionFetch_2->setEnabled(true); - ui->actionTurn_In->setEnabled(true); - ui->actionVerifier_Turn_In->setEnabled(true); + read_recorrected_pages(); + read_review_pages(); + read_corrected_pages(); + read_verified_pages(); + + //<<<<<actionas_PDF->setEnabled(true); - ui->actionSymbols->setEnabled(true); - ui->actionZoom_In->setEnabled(true); - ui->actionZoom_Out->setEnabled(true); + + + // Enabling the buttons again after a project is opened + e_d_features(true); //Reset loadData flag LoadDataFlag = 1; //reset data @@ -1582,6 +1445,7 @@ void MainWindow::on_actionOpen_Project_triggered() { //Version Based ui->viewComments->setDisabled(false); ui->compareCorrectorOutput->setDisabled(false); ui->groupBox->setDisabled(false); + } /*! * \fn MainWindow::AddRecentProjects @@ -1620,6 +1484,11 @@ void MainWindow::AddRecentProjects() ui->menuRecent_Project->addAction(FileAction); connect(FileAction, &QAction::triggered, this , &MainWindow::on_action3_triggered); } + + QAction *FileAction = new QAction(this); + FileAction->setIconText("Clear Menu"); + ui->menuRecent_Project->addAction(FileAction); + connect(FileAction, &QAction::triggered, this , &MainWindow::on_actionClear_Menu_triggered); } @@ -1729,6 +1598,8 @@ void MainWindow::SaveFile_GUI_Postprocessing() int lindex = img_.find("png"); string str = img_.substr(ind, lindex-ind); QString path = QString::fromStdString(str) + "tex"; + QStringList imgpath = path.split("/"); + path = "../"+imgpath[imgpath.size()-2]+"/"+imgpath[imgpath.size()-1]; QFile f(path); if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "Cannot open file"< object. -// QVector s; -// if (plain != NULL) -// { -// while(std::getline(ss,to,'\n')) -// { -// QString qstr = QString::fromStdString(to); -// s.append(qstr); -// } -// } + // QTextDocumentFragment qtextdocfragment; + // QString plain = qtextdocfragment.fromHtml(output).toPlainText(); + + // std::stringstream ss(plain.toStdString()); + // std::string to; + // //! Appending the plain text in QVector object. + // QVector s; + // if (plain != NULL) + // { + // while(std::getline(ss,to,'\n')) + // { + // QString qstr = QString::fromStdString(to); + // s.append(qstr); + // } + // } -// //! Inserting string values in \a qjsonobj. -// QJsonObject qjsonobj; -// for(int i = 0;i < s.size(); i++) -// { -// QString z = QString::number(i); -// qjsonobj.insert(z, QJsonValue(s[i])); -// } -// int len = qjsonobj.length(); + // //! Inserting string values in \a qjsonobj. + // QJsonObject qjsonobj; + // for(int i = 0;i < s.size(); i++) + // { + // QString z = QString::number(i); + // qjsonobj.insert(z, QJsonValue(s[i])); + // } + // int len = qjsonobj.length(); -// localFilename.replace(".html",".json"); //!Replacing extension of file from .html to .json -// QFile sFile2(localFilename); + // localFilename.replace(".html",".json"); //!Replacing extension of file from .html to .json + // QFile sFile2(localFilename); -// //! Sets codec value and then adding values in file -// if(sFile2.open(QIODevice::WriteOnly | QIODevice::Text)) -// { -// QTextStream out(&sFile2); -// out.setCodec("UTF-8"); -// out << "{\n"; -// for(int x = 0; x changedWords; - changedWords = ed.editDistance(s1, s2); // Update CPair by editdistance - QString currentDirAbsolutePath = gDirTwoLevelUp + "/" + gCurrentDirName; - runGlobalReplace(currentDirAbsolutePath, changedWords); - ConvertSlpDevFlag =0; + changedWords += ed.editDistance(s1, s2); + if(changedWords.size() > 0 ) + { + QString str = ui->pushButton_6->text(); + str = "Global Replace[" + QString::number(changedWords.size()) + "]"; + ui->pushButton_6->setText(str); + ui->pushButton_6->setVisible(true); + } + } /*! @@ -2978,7 +2853,7 @@ void MainWindow::on_actionHighlight_triggered() { format.setBackground(Qt::darkYellow); -// LogHighlights(text); // Add log to HighlightsLog file if word is highlighted + // LogHighlights(text); // Add log to HighlightsLog file if word is highlighted } curr_browser->textCursor().mergeCharFormat(format); //Correctors are only allowed to remove highlights. } @@ -3043,6 +2918,7 @@ void MainWindow::on_actionLeftAlign_triggered() // Get the table format and set the alignment to center QTextTableFormat tableFormat = selectedTable->format(); + tableFormat.setAlignment(Qt::AlignLeft); selectedTable->setFormat(tableFormat); } @@ -3056,6 +2932,8 @@ void MainWindow::on_actionRightAlign_triggered() if(!curr_browser || curr_browser->isReadOnly()) return; curr_browser->setAlignment(Qt::AlignRight); + + QTextCursor cursor = curr_browser->textCursor(); QTextTable *selectedTable = cursor.currentTable(); @@ -3064,8 +2942,13 @@ void MainWindow::on_actionRightAlign_triggered() return; } - // Get the table format and set the alignment to center + // Get the table format and set the alignment to right QTextTableFormat tableFormat = selectedTable->format(); + + // Setting RightMargin = { Content RightMargin + border width } + QMargins margin = curr_browser->contentsMargins(); + tableFormat.setRightMargin(margin.right()* 72 + tableFormat.border()); + tableFormat.setAlignment(Qt::AlignRight); selectedTable->setFormat(tableFormat); } @@ -3090,6 +2973,11 @@ void MainWindow::on_actionCentreAlign_triggered() // Get the table format and set the alignment to center QTextTableFormat tableFormat = selectedTable->format(); + + // Setting RightMargin = { Content RightMargin + border width } + QMargins margin = curr_browser->contentsMargins(); + tableFormat.setRightMargin(margin.right()* 72 + tableFormat.border()); + tableFormat.setAlignment(Qt::AlignCenter); selectedTable->setFormat(tableFormat); } @@ -3211,41 +3099,37 @@ void MainWindow::on_actionInsert_Tab_Space_triggered() * \brief Inserts table at text cursor * Creates a dialog to insert the numbr of rows and columns. */ -void MainWindow::on_actionInsert_Table_2_triggered() -{ - if(!curr_browser || curr_browser->isReadOnly()) - return; - QDialog dialog(this); - QFormLayout form(&dialog); // Use a layout allowing to have a label next to each field - form.addRow(new QLabel("Insert Table", this)); // Create a dialog for asking table dimensions +void MainWindow::createTable(){ + if (selectedItems.isEmpty()) { - //! Add the lineEdits with their respective labels - QLineEdit *rows = new QLineEdit(&dialog); - QLineEdit *columns = new QLineEdit(&dialog); // Add lineEdits to get Rows - form.addRow("Rows", rows); // Add lineEdits to get Columns - form.addRow("Columns", columns); + QMessageBox::information(0,"Insert Table", "Please select at least one cell."); + return; + } + QSetselectedRows; + QSetselectedColumns; + int rw,col; + foreach(QTableWidgetItem *items,selectedItems){ + rw=items->row(); + col=items->column(); + selectedRows.insert(rw); + selectedColumns.insert(col); + } + int rows,columns; + rows=selectedRows.size(); + columns=selectedColumns.size(); - //! Add some standard buttons (Cancel/Ok) at the bottom of the dialog - QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog); // Add some standard buttons (Cancel/Ok) at the bottom of the dialog - form.addRow(&buttonBox); - QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept())); - QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject())); + QTextTableFormat tf; + tf.setBorderBrush(Qt::black); + tf.setCellSpacing(0); + tf.setCellPadding(7); - //! Show the dialog as modal - if (dialog.exec() == QDialog::Accepted) - { + QTextCursor cursor = curr_browser->textCursor(); + cursor.insertTable(rows,columns,tf); - QTextTableFormat tf; - tf.setBorderBrush(Qt::black); - tf.setCellSpacing(0); - tf.setCellPadding(7); - // tf.setAlignment(Qt::AlignCenter); - QTextCursor cursor = curr_browser->textCursor(); - cursor.insertTable(rows->text().toInt(),columns->text().toInt(),tf); - } + tableDialog->close(); + selectedItems.clear(); } - /*! * \fn MainWindow::on_actionInsert_Columnleft_triggered * \brief Inserts Column to the left of table @@ -3373,73 +3257,53 @@ void MainWindow::on_actionFetch_2_triggered() QString email = settings.value("email").toString(); QString token = settings.value("token").toString(); settings.endGroup(); - QProcess process; - process.execute("curl -d -X -k -POST --header " - "\"Content-type:application/x-www-form-urlencoded\" https://udaaniitb.aicte-india.org/udaan/email/ -d \"email="+email+"&password="+token+"\" -o validate.json"); - - //to find the repo name from .git/congig file - QString repo = ""; - QString gDir = gDirTwoLevelUp+"/.git/config"; - QFile f(gDir); - f.open(QIODevice::ReadOnly); - while(!f.atEnd()) { - QString line = f.readLine(); - if(line.contains("https://github.com")){ - QStringList l = line.split("/"); - repo = l[l.size()-1].remove("\n"); - break; - } - } - f.close(); - QJsonObject mainObj = readJsonFile("validate.json"); - QJsonArray repos = mainObj.value("repo_list").toArray(); - QJsonArray::iterator itr; int flag = 0; - for(itr = repos.begin(); itr != repos.end(); itr++){ - - if(itr->toString() == repo){ - flag = 1; - break; + if(check_access()){ + QString repo = ""; + QString gDir = gDirTwoLevelUp+"/.git/config"; + QFile f(gDir); + f.open(QIODevice::ReadOnly); + while(!f.atEnd()) { + QString line = f.readLine(); + if(line.contains("https://github.com")){ + QStringList l = line.split("/"); + repo = l[l.size()-1].remove("\n"); + break; + } } - } - QFile::remove("validate.json"); - if(repos.size() == 0 || flag == 0){ - QMessageBox msg; - msg.setText("You don't have access to this project on cloud."); - msg.exec(); - return; - } + f.close(); - QString stage = mProject.get_stage(); - QString prvs_stage = (stage=="Verifier")?"Verifier":"Corrector"; - QString prvs_output_dir = prvs_stage + "Output"; //"VerifierOutput" or "CorrectorOutput" + QString stage = mProject.get_stage(); + QString prvs_stage = (stage=="Verifier")?"Verifier":"Corrector"; + QString prvs_output_dir = prvs_stage + "Output"; //"VerifierOutput" or "CorrectorOutput" - QMessageBox forPullBox; - forPullBox.setWindowTitle("Pull ?"); - forPullBox.setIcon(QMessageBox::Question); - forPullBox.setInformativeText("This will overwrite files in " + prvs_output_dir + " directory. Do you want to Continue?"); - QPushButton *okButton = forPullBox.addButton(QMessageBox::StandardButton::Yes); - QPushButton *noButton = forPullBox.addButton(QMessageBox::StandardButton::No); - forPullBox.exec(); + QMessageBox forPullBox; + forPullBox.setWindowTitle("Sync ?"); + forPullBox.setIcon(QMessageBox::Question); + forPullBox.setInformativeText("This will overwrite files in " + prvs_output_dir + " directory. Do you want to Continue?"); + QPushButton *okButton = forPullBox.addButton(QMessageBox::StandardButton::Yes); + QPushButton *noButton = forPullBox.addButton(QMessageBox::StandardButton::No); + forPullBox.exec(); - int error; - if (forPullBox.clickedButton() == okButton) - { - if ((error = mProject.fetch()) != 0) { - qDebug() << "Fetch failed with error code " << error; - } - if(mProject.get_version().toInt()) + int error; + if (forPullBox.clickedButton() == okButton) { - QMessageBox::information(0, "Sync Success", "Synced Succesfully"); + if ((error = mProject.fetch(gDirTwoLevelUp)) != 0) { + qDebug() << "Fetch failed with error code " << error; + } + if(mProject.get_version().toInt()) + { + QMessageBox::information(0, "Sync Success", "Synced Succesfully"); + } + else + { + QMessageBox::information(0, "Sync Error", "Cloud Sync Un-successful, Please Check Your Internet Connection"); + } + + ui->lineEdit_2->setText("Version " + mProject.get_version()); } else - { - QMessageBox::information(0, "Sync Error", "Cloud Sync Un-successful, Please Check Your Internet Connection"); - } - - ui->lineEdit_2->setText("Version " + mProject.get_version()); + return; } - else - return; } /*! @@ -3450,6 +3314,13 @@ void MainWindow::on_actionFetch_2_triggered() */ void MainWindow::on_actionTurn_In_triggered() { + //Save to cloud after writing the pages to files + write_verified_pages(); + write_corrected_pages(); + write_review_pages(); + write_recorrected_pages(); + + //! Checking if the files are saved or not. if (checkUnsavedWork()) { @@ -3496,11 +3367,7 @@ void MainWindow::on_actionTurn_In_triggered() msg.exec(); return; } - if(!check_access()){ - QMessageBox msg; - msg.setText("You don't have access to this project on cloud."); - msg.exec(); return; } @@ -3534,296 +3401,296 @@ void MainWindow::on_actionTurn_In_triggered() * \note This function turn-in files for verifiers not correctors. * \sa checkUnsavedWork(), saveAllWork(), get_version(), get_stage(), readJsonFile(), writeJsonFile(),set_stage_verifier() and enable_push. */ -void MainWindow::on_actionVerifier_Turn_In_triggered() -{ - if (checkUnsavedWork()) - { - QMessageBox checkUnsavedBox2; - checkUnsavedBox2.setWindowTitle("Unsaved Work"); - checkUnsavedBox2.setIcon(QMessageBox::Question); - checkUnsavedBox2.setInformativeText("You have unsaved files. Save it before turn-in.\n"); - QPushButton *cancelButton2 = checkUnsavedBox2.addButton(QMessageBox::Cancel); - QPushButton *saveButton2 = checkUnsavedBox2.addButton(QMessageBox::Save); - checkUnsavedBox2.exec(); +//void MainWindow::on_actionVerifier_Turn_In_triggered() +//{ +// if (checkUnsavedWork()) +// { +// QMessageBox checkUnsavedBox2; +// checkUnsavedBox2.setWindowTitle("Unsaved Work"); +// checkUnsavedBox2.setIcon(QMessageBox::Question); +// checkUnsavedBox2.setInformativeText("You have unsaved files. Save it before turn-in.\n"); +// QPushButton *cancelButton2 = checkUnsavedBox2.addButton(QMessageBox::Cancel); +// QPushButton *saveButton2 = checkUnsavedBox2.addButton(QMessageBox::Save); +// checkUnsavedBox2.exec(); - if (checkUnsavedBox2.clickedButton() == cancelButton2) - { - QMessageBox::information(0, "Turn In", "Turn In Cancelled"); - return; - } - else - { - saveAllWork(); - } - } +// if (checkUnsavedBox2.clickedButton() == cancelButton2) +// { +// QMessageBox::information(0, "Turn In", "Turn In Cancelled"); +// return; +// } +// else +// { +// saveAllWork(); +// } +// } - /* - * \description - * Checks whether user is logged in or not - */ - QSettings settings("IIT-B", "OpenOCRCorrect"); - qDebug() << settings.fileName(); - settings.beginGroup("loginConsent"); - QString value = settings.value("consent").toString(); - settings.endGroup(); - if(value != "loggedIn"){ - QMessageBox msg; - msg.setText("Please login to save your changes on cloud"); - int cnt = 2; - //showing the message box for 2 seconds only. - QTimer cntDown; - QObject::connect(&cntDown, &QTimer::timeout, [&msg,&cnt, &cntDown]()->void{ - if(--cnt < 0){ - cntDown.stop(); - msg.close(); - } - }); - cntDown.start(1000); - msg.exec(); - return; - } - if(!check_access()){ - QMessageBox msg; - msg.setText("You don't have access to this project on cloud."); - msg.exec(); - return; - } +// /* +// * \description +// * Checks whether user is logged in or not +// */ +// QSettings settings("IIT-B", "OpenOCRCorrect"); +// qDebug() << settings.fileName(); +// settings.beginGroup("loginConsent"); +// QString value = settings.value("consent").toString(); +// settings.endGroup(); +// if(value != "loggedIn"){ +// QMessageBox msg; +// msg.setText("Please login to save your changes on cloud"); +// int cnt = 2; +// //showing the message box for 2 seconds only. +// QTimer cntDown; +// QObject::connect(&cntDown, &QTimer::timeout, [&msg,&cnt, &cntDown]()->void{ +// if(--cnt < 0){ +// cntDown.stop(); +// msg.close(); +// } +// }); +// cntDown.start(1000); +// msg.exec(); +// return; +// } +// if(!check_access()){ +// QMessageBox msg; +// msg.setText("You don't have access to this project on cloud."); +// msg.exec(); +// return; +// } - /* - * \description - * 1. Checks if any project is opened or not. - * 2. Reads the comments.json file in Comments folder in the opened project. - * 3. Calculates AverageCharAccuracy. - * 4. mRoleCheck - * 5. Sets the rating and formatting. - */ +// /* +// * \description +// * 1. Checks if any project is opened or not. +// * 2. Reads the comments.json file in Comments folder in the opened project. +// * 3. Calculates AverageCharAccuracy. +// * 4. mRoleCheck +// * 5. Sets the rating and formatting. +// */ - if(mProject.get_version().toInt()) - { +// if(mProject.get_version().toInt()) +// { - int ver = mProject.get_version().toInt(); - QString commit_msg; +// int ver = mProject.get_version().toInt(); +// QString commit_msg; - /*QString commentFilename = gDirTwoLevelUp + "/Comments/comments.json"; - float avgcharacc = 0; - bool formatting = false; - int rating = 0; +// /*QString commentFilename = gDirTwoLevelUp + "/Comments/comments.json"; +// float avgcharacc = 0; +// bool formatting = false; +// int rating = 0; - QJsonObject mainObj = readJsonFile(commentFilename); +// QJsonObject mainObj = readJsonFile(commentFilename); - avgcharacc = mainObj["AverageCharAccuracy"].toDouble(); +// avgcharacc = mainObj["AverageCharAccuracy"].toDouble(); - //! Calcuates the rating for the current set. - if(mProject.get_stage() != mRole) - rating = mainObj["Rating-V"+ QString::number(mProject.get_version().toInt() - 1)].toInt(); - else - rating = mainObj["Rating-V"+ mProject.get_version()].toInt(); - if(((!mainObj["Formatting"].isNull())) || (! mainObj["Formatting"].isUndefined())) - formatting = mainObj["Formatting"].toBool(); +// //! Calcuates the rating for the current set. +// if(mProject.get_stage() != mRole) +// rating = mainObj["Rating-V"+ QString::number(mProject.get_version().toInt() - 1)].toInt(); +// else +// rating = mainObj["Rating-V"+ mProject.get_version()].toInt(); +// if(((!mainObj["Formatting"].isNull())) || (! mainObj["Formatting"].isUndefined())) +// formatting = mainObj["Formatting"].toBool(); - /* - * \description - * 1. Check formatting dialog box will be opened - * 2. Dialog box will show the current rating out of 4 and a checkbox. - */ - /*QDialog dialog(this); - dialog.setWindowTitle("Check Formatting"); +// /* +// * \description +// * 1. Check formatting dialog box will be opened +// * 2. Dialog box will show the current rating out of 4 and a checkbox. +// */ +// /*QDialog dialog(this); +// dialog.setWindowTitle("Check Formatting"); - QFormLayout form(&dialog); - form.addRow(new QLabel("Average Rating of Current Set : " + QString::number(rating) + " out of 4")); +// QFormLayout form(&dialog); +// form.addRow(new QLabel("Average Rating of Current Set : " + QString::number(rating) + " out of 4")); - QCheckBox *cb = new QCheckBox("Perfect Formatting?" ,&dialog); - cb->setChecked(formatting); - form.addRow(cb); +// QCheckBox *cb = new QCheckBox("Perfect Formatting?" ,&dialog); +// cb->setChecked(formatting); +// form.addRow(cb); - QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, - Qt::Horizontal, &dialog); - form.addRow(&buttonBox); +// QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, +// Qt::Horizontal, &dialog); +// form.addRow(&buttonBox); - //! Checking which signal has been passed i.e. accept or reject. - QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept())); //when ok is pressed. - QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject())); //when cancel is pressed. +// //! Checking which signal has been passed i.e. accept or reject. +// QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept())); //when ok is pressed. +// QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject())); //when cancel is pressed. - if (dialog.exec() == QDialog::Accepted) - { - formatting = cb->isChecked(); - - //! If the checkbox is checked, increment rating by 1 else decrement the rating value by 1. - if(rating == 4 && formatting) - rating = 5; - else if(rating == 5 && (!formatting)) - rating = 4; - } - else - { - QMessageBox::information(0, "Turn In", "Turn In Cancelled"); - return; - } - - //! Updating the formatting and rating parameters value in the comments.json file, if any - mainObj["Formatting"] = formatting; - - //! Calcuates the rating for the current set. - if(mProject.get_stage() != mRole) - mainObj["Rating-V"+ QString::number(mProject.get_version().toInt() - 1)] = rating; - else - mainObj["Rating-V"+ mProject.get_version()] = rating; +// if (dialog.exec() == QDialog::Accepted) +// { +// formatting = cb->isChecked(); - writeJsonFile(commentFilename, mainObj); +// //! If the checkbox is checked, increment rating by 1 else decrement the rating value by 1. +// if(rating == 4 && formatting) +// rating = 5; +// else if(rating == 5 && (!formatting)) +// rating = 4; +// } +// else +// { +// QMessageBox::information(0, "Turn In", "Turn In Cancelled"); +// return; +// } - QMessageBox messageBox(this); - QString msg1 = QString( - "Rating for Current Version Based on the Formatting Input: " + QString::number(rating) + " out of 5" +// //! Updating the formatting and rating parameters value in the comments.json file, if any +// mainObj["Formatting"] = formatting; - + "\n\nDo you want to Return the Set to the Corrector or Finalise the set?" +// //! Calcuates the rating for the current set. +// if(mProject.get_stage() != mRole) +// mainObj["Rating-V"+ QString::number(mProject.get_version().toInt() - 1)] = rating; +// else +// mainObj["Rating-V"+ mProject.get_version()] = rating; - + "\n\nClick \"Return Set\" to Increment the Version from " - + QString::number(ver) +" to "+QString::number(ver + 1) +// writeJsonFile(commentFilename, mainObj); - + "\nClick \"Finalise\" to Approve the set as the Final Version" - ); +// QMessageBox messageBox(this); +// QString msg1 = QString( +// "Rating for Current Version Based on the Formatting Input: " + QString::number(rating) + " out of 5" - QString msg2 = QString( - "Rating for Current Version Based on the Formatting Input: " + QString::number(rating) + " out of 5" +// + "\n\nDo you want to Return the Set to the Corrector or Finalise the set?" - + "\n\nDo you want to Return or Resubmit or Finalise the set?" +// + "\n\nClick \"Return Set\" to Increment the Version from " +// + QString::number(ver) +" to "+QString::number(ver + 1) - + "\n\nClick \"Return Set\" to Turnin and Increment the Version from " - + QString::number(ver) +" to "+QString::number(ver + 1) +// + "\nClick \"Finalise\" to Approve the set as the Final Version" +// ); - + " \nClick \"Resubmit\" to Turn In without Incrementing Version." +// QString msg2 = QString( +// "Rating for Current Version Based on the Formatting Input: " + QString::number(rating) + " out of 5" - + "\nClick \"Finalise\" to Approve the set as the Final Version" - ); +// + "\n\nDo you want to Return or Resubmit or Finalise the set?" - messageBox.setWindowTitle("Turn In"); - QAbstractButton *resubmitButton = - messageBox.addButton(tr("Resubmit"), QMessageBox::ActionRole); - QAbstractButton *returnSetButton = - messageBox.addButton(tr("Return Set"), QMessageBox::ActionRole); - QAbstractButton *finaliseButton = - messageBox.addButton(tr("Finalise"), QMessageBox::ActionRole); - QAbstractButton *cancelButton = - messageBox.addButton(tr("Cancel"), QMessageBox::RejectRole); - - /* - * \description - * 1.Checks if the project content is added to the staging area or not - * 2. If no, display \a msg1 and remove the resubmit button. - * 3. If yes, display \a msg2. - */ - /*if(mRole != mProject.get_stage()) - { - messageBox.setText(msg1); - messageBox.removeButton(resubmitButton); - } - else - { - messageBox.setText(msg2); - } +// + "\n\nClick \"Return Set\" to Turnin and Increment the Version from " +// + QString::number(ver) +" to "+QString::number(ver + 1) - messageBox.exec(); +// + " \nClick \"Resubmit\" to Turn In without Incrementing Version." - /*! - * \enum class SubmissionType - * - * This enum describes the type of submission type. - * - * \value resubmit To turn in without incrementing version. - * \value return_set To turn-in and increment the version. - * \value finalise To approve the set as the final version. - */ - /*enum class SubmissionType {resubmit, return_set, finalise}; - SubmissionType s ; - - /* - * Checking the condition: CorrectorOutputFiles != 2*IndsFiles - * If true, then \a s and \a commit_msg are updated. - */ - /*if (messageBox.clickedButton() == resubmitButton) - { - s = SubmissionType::resubmit; - commit_msg = "Verifier Resubmitted Version:" + mProject.get_version(); - } +// + "\nClick \"Finalise\" to Approve the set as the Final Version" +// ); - //! \a s and \a commit_msg are updated - else if (messageBox.clickedButton() == returnSetButton) - { - //mProject.enable_push( true ); //Increment = true - s = SubmissionType::return_set; - commit_msg = "Verifier has Turned in the Next Version:" + mProject.get_version(); - } +// messageBox.setWindowTitle("Turn In"); +// QAbstractButton *resubmitButton = +// messageBox.addButton(tr("Resubmit"), QMessageBox::ActionRole); +// QAbstractButton *returnSetButton = +// messageBox.addButton(tr("Return Set"), QMessageBox::ActionRole); +// QAbstractButton *finaliseButton = +// messageBox.addButton(tr("Finalise"), QMessageBox::ActionRole); +// QAbstractButton *cancelButton = +// messageBox.addButton(tr("Cancel"), QMessageBox::RejectRole); - /* - * Checking the condition: CorrectorOutputFiles != 2*IndsFiles - * If true, a message box of \value Couldn't Turn in will be displayed, - * else \a s and \a commit_msg are updated. - */ - /*else if (messageBox.clickedButton() == finaliseButton) - { - s = SubmissionType::finalise; - commit_msg = "Verifier Finalised Version:" + mProject.get_version(); - } - else - { - QMessageBox::critical(0, "Turn In", "Turn In Cancelled"); - return; - }*/ +// /* +// * \description +// * 1.Checks if the project content is added to the staging area or not +// * 2. If no, display \a msg1 and remove the resubmit button. +// * 3. If yes, display \a msg2. +// */ +// /*if(mRole != mProject.get_stage()) +// { +// messageBox.setText(msg1); +// messageBox.removeButton(resubmitButton); +// } +// else +// { +// messageBox.setText(msg2); +// } - QMessageBox submitBox2; - submitBox2.setWindowTitle("Submit ?"); - submitBox2.setIcon(QMessageBox::Question); - submitBox2.setInformativeText("Are you ready to submit your changes?"); - QPushButton *yButton2 = submitBox2.addButton(QMessageBox::StandardButton::Yes); - QPushButton *nButton2 = submitBox2.addButton(QMessageBox::StandardButton::No); - submitBox2.exec(); +// messageBox.exec(); + +// /*! +// * \enum class SubmissionType +// * +// * This enum describes the type of submission type. +// * +// * \value resubmit To turn in without incrementing version. +// * \value return_set To turn-in and increment the version. +// * \value finalise To approve the set as the final version. +// */ +// /*enum class SubmissionType {resubmit, return_set, finalise}; +// SubmissionType s ; + +// /* +// * Checking the condition: CorrectorOutputFiles != 2*IndsFiles +// * If true, then \a s and \a commit_msg are updated. +// */ +// /*if (messageBox.clickedButton() == resubmitButton) +// { +// s = SubmissionType::resubmit; +// commit_msg = "Verifier Resubmitted Version:" + mProject.get_version(); +// } - if (submitBox2.clickedButton() == yButton2) - { - // bool ok; - // // user entered something and pressed OK - // if(s == SubmissionType::return_set) //If yes button is clicked and submission type is return_set then enable push - // { - mProject.enable_push( true ); - // } - // else if (s == SubmissionType::resubmit) //If yes button is clicked and submission type is resubmit then enable push - // { - // mProject.enable_push( false ); - // } - if(!verifier_save()) return; - // if(s == SubmissionType::return_set) - // { - // mProject.set_version( mProject.get_version().toInt() - 1 ); - // } - mProject.set_verifier(); - } - else - { - QMessageBox::critical(0, "Cloud sync", "Sync failed"); - return; - } +// //! \a s and \a commit_msg are updated +// else if (messageBox.clickedButton() == returnSetButton) +// { +// //mProject.enable_push( true ); //Increment = true +// s = SubmissionType::return_set; +// commit_msg = "Verifier has Turned in the Next Version:" + mProject.get_version(); +// } - //! Sending email with the following information - /*QString emailText = "Book ID: " + mProject.get_bookId() - + "\nSet ID: " + mProject.get_setId() - + "\nRating Provided: " + QString::number(rating) - + "\n" + commit_msg ;*/ +// /* +// * Checking the condition: CorrectorOutputFiles != 2*IndsFiles +// * If true, a message box of \value Couldn't Turn in will be displayed, +// * else \a s and \a commit_msg are updated. +// */ +// /*else if (messageBox.clickedButton() == finaliseButton) +// { +// s = SubmissionType::finalise; +// commit_msg = "Verifier Finalised Version:" + mProject.get_version(); +// } +// else +// { +// QMessageBox::critical(0, "Turn In", "Turn In Cancelled"); +// return; +// }*/ + +// QMessageBox submitBox2; +// submitBox2.setWindowTitle("Submit ?"); +// submitBox2.setIcon(QMessageBox::Question); +// submitBox2.setInformativeText("Are you ready to submit your changes?"); +// QPushButton *yButton2 = submitBox2.addButton(QMessageBox::StandardButton::Yes); +// QPushButton *nButton2 = submitBox2.addButton(QMessageBox::StandardButton::No); +// submitBox2.exec(); + +// if (submitBox2.clickedButton() == yButton2) +// { +// // bool ok; +// // // user entered something and pressed OK +// // if(s == SubmissionType::return_set) //If yes button is clicked and submission type is return_set then enable push +// // { +// mProject.enable_push( true ); +// // } +// // else if (s == SubmissionType::resubmit) //If yes button is clicked and submission type is resubmit then enable push +// // { +// // mProject.enable_push( false ); +// // } +// if(!verifier_save()) return; +// // if(s == SubmissionType::return_set) +// // { +// // mProject.set_version( mProject.get_version().toInt() - 1 ); +// // } +// mProject.set_verifier(); +// } +// else +// { +// QMessageBox::critical(0, "Cloud sync", "Sync failed"); +// return; +// } - //! Updating the Project Version - ui->lineEdit_2->setText("Version " + mProject.get_version()); - QMessageBox::information(0, "Cloud sync", "Cloud save successful!"); - QSettings settings("IIT-B", "OpenOCRCorrect"); - settings.beginGroup("cloudSave"); - settings.setValue("save","success" ); - settings.endGroup(); - } - else - { - QMessageBox::critical(0, "Cloud sync Error", "Please Open Project Before syncing"); - } -} +// //! Sending email with the following information +// /*QString emailText = "Book ID: " + mProject.get_bookId() +// + "\nSet ID: " + mProject.get_setId() +// + "\nRating Provided: " + QString::number(rating) +// + "\n" + commit_msg ;*/ + +// //! Updating the Project Version +// ui->lineEdit_2->setText("Version " + mProject.get_version()); +// QMessageBox::information(0, "Cloud sync", "Cloud save successful!"); +// QSettings settings("IIT-B", "OpenOCRCorrect"); +// settings.beginGroup("cloudSave"); +// settings.setValue("save","success" ); +// settings.endGroup(); +// } +// else +// { +// QMessageBox::critical(0, "Cloud sync Error", "Please Open Project Before syncing"); +// } +//} /*! * \fn MainWindow::on_actionSymbols_triggered @@ -3832,8 +3699,10 @@ void MainWindow::on_actionVerifier_Turn_In_triggered() */ void MainWindow::on_actionSymbols_triggered() { - SymbolsView *dialog = SymbolsView::openSymbolTable(this); - dialog->show(); + if(curr_browser){ + SymbolsView *dialog = SymbolsView::openSymbolTable(this, curr_browser); + dialog->show(); + } } /*! @@ -4004,6 +3873,16 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) QString bboxf = currentTabPageName; QFile bbox_file(gDirTwoLevelUp + "/bboxf/"+bboxf.replace(".html", ".bbox")); //! When user moves his mouse the system will ask user to download new update. + if(event->type() == QEvent::MouseMove){ + if(ui->tabWidget->width() == 0 && flag_tab != 1){ + ui->backward_Button->setVisible(false); + ui->forward_Button->setVisible(true); + ui->tabWidget->setVisible(false); + flag_tab = 1; + } + else if(ui->tabWidget->width() > 0 && flag_tab == 1) + flag_tab = 0; + } if(event->type() == QEvent::MouseButtonPress) { @@ -4016,6 +3895,51 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) } } } + if(event->type() == QEvent::MouseButtonDblClick && !selectedItems.isEmpty()){ + createTable(); + selectedItems.clear(); + } + if(event->type() == QEvent::MouseMove && !selectedItems.isEmpty()){ + QSetselectedRows; + QSetselectedColumns; + int rw,col; + foreach(QTableWidgetItem *items,selectedItems){ + rw=items->row(); + col=items->column(); + selectedRows.insert(rw); + selectedColumns.insert(col); + } + int rows,columns; + rows=selectedRows.size(); + columns=selectedColumns.size(); + if(rows==m_table->rowCount()-1){ + QTableWidgetItem *itm; + m_table->insertRow(m_table->rowCount()); + for(int i=m_table->rowCount()-1;irowCount();i++){ + for(int j=0;jcolumnCount();j++){ + itm = new QTableWidgetItem(); + itm->setData(Qt::DisplayRole,QString(".")); + itm->setForeground(QBrush(QColor(255,255,255))); + m_table->setItem(i,j,itm); + } + } + tableDialog->resize(tableDialog->size()+QSize(0,35)); + } + if(columns == m_table->columnCount()-1){ + QTableWidgetItem *itm; + m_table->insertColumn(m_table->columnCount()); + m_table->setColumnWidth(m_table->columnCount()-1,1); + for(int i=0;irowCount();i++){ + for(int j=m_table->columnCount()-1;jcolumnCount();j++){ + itm = new QTableWidgetItem(); + itm->setData(Qt::DisplayRole,QString(".")); + itm->setForeground(QBrush(QColor(255,255,255))); + m_table->setItem(i,j,itm); + } + } + tableDialog->resize(tableDialog->size()+QSize(55,0)); + } + } //! When the user moves the cursor over unedited html file text, it shows a rectangle box with some text value. if (event->type() == QEvent::ToolTip) @@ -4843,6 +4767,9 @@ int MainWindow::writeGlobalCPairsToFiles(QString file_path, QMap MainWindow::getGlobalReplacementMapFromChecklistDialog(Q QDir directory(gDirTwoLevelUp); QString setName=directory.dirName(); if(!QDir(gDirTwoLevelUp+"/logs").exists()) - QDir().mkdir(gDirTwoLevelUp+"/logs"); + QDir().mkdir(gDirTwoLevelUp+"/logs"); QString filename = gDirTwoLevelUp+"/logs/"+mRole+"_"+setName+"_logs.csv"; QFile csvFile(filename); if(!csvFile.exists()) //for first time creation @@ -5051,7 +4978,7 @@ QMap MainWindow::getGlobalReplacementMapFromChecklistDialog(Q QDir directory(gDirTwoLevelUp); QString setName=directory.dirName(); if(!QDir(gDirTwoLevelUp+"/logs").exists()) - QDir().mkdir(gDirTwoLevelUp+"/logs"); + QDir().mkdir(gDirTwoLevelUp+"/logs"); QString filename = gDirTwoLevelUp+"/logs/"+mRole+"_"+setName+"_logs.csv"; QFile csvFile(filename); if(!csvFile.exists()) @@ -5913,7 +5840,7 @@ void MainWindow::on_actionResize_Image_triggered() */ void MainWindow::on_actionPush_triggered() { - mProject.push(branchName); + //mProject.push(branchName); } /*! @@ -6140,7 +6067,7 @@ void MainWindow::LoadDocument(QFile * f, QString ext, QString name) // loadHtmlInDoc(f); if(!QDir(gDirTwoLevelUp+"/logs").exists()) - QDir().mkdir(gDirTwoLevelUp+"/logs"); + QDir().mkdir(gDirTwoLevelUp+"/logs"); QString loc = gDirTwoLevelUp + "/logs/."+mRole+"_dan.log"; QFile sFile(loc); if(!sFile.open(QIODevice::ReadOnly)) {qDebug()<<"can't read the dan logs";} @@ -6171,6 +6098,7 @@ void MainWindow::LoadDocument(QFile * f, QString ext, QString name) b->setUndoRedoEnabled(true); // curr_browser = (CustomTextBrowser*)ui->splitter->widget(1); + defaultStyle = curr_browser->styleSheet(); curr_browser->setDocument(b->document()->clone(curr_browser)); curr_browser->document()->clearUndoRedoStacks(); @@ -6241,6 +6169,7 @@ void MainWindow::LoadDocument(QFile * f, QString ext, QString name) //! Enabling Selection in treeView ui->treeView->selectionModel()->clearSelection(); + QModelIndex currentTreeItemIndex = ui->treeView->selectionModel()->currentIndex(); QModelIndex parentIndex = currentTreeItemIndex.parent(); auto model = ui->treeView->model(); @@ -6250,10 +6179,12 @@ void MainWindow::LoadDocument(QFile * f, QString ext, QString name) for (int i = 0; i < rowCount; i++) { QModelIndex index = model->index(i, 0, parentIndex); + treeItemLabel = index.data(Qt::DisplayRole).toString(); if (index.isValid()) { + if (treeItemLabel == currentTabPageName) { ui->treeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select); @@ -6286,6 +6217,8 @@ void MainWindow::LoadDocument(QFile * f, QString ext, QString name) if (!isVerifier && (current_folder == "Inds" || current_folder == "VerifierOutput")) { curr_browser->setReadOnly(true); } + changedWords.clear(); + ui->pushButton_6->setVisible(false); } /*! @@ -6351,12 +6284,26 @@ void MainWindow::file_click(const QModelIndex & indx) return; auto file = item->GetFile(); QString fileName = file->fileName(); //gets filename + // Set the file's permissions to readonly + if(fileName.contains("CorrectorOutput") && mRole == "Verifier"){ + QFile::setPermissions(fileName, QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther); + } + else if(fileName.contains("VerifierOutput") && mRole == "Corrector"){ + QFile::setPermissions(fileName, QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther); + } + else{ + // Set the file's permissions to both read and write mode + QFile::setPermissions(fileName, QFile::WriteOwner | QFile::WriteGroup | QFile::WriteOther | + QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther); + + } NodeType type = item->GetNodeType(); switch (type) { case NodeType::_FILETYPE: { QFileInfo f(*file); QString suff = f.completeSuffix(); + if (suff == "txt" || suff == "html") { LoadDocument(file,suff,qvar); //loads not image files } @@ -6365,12 +6312,21 @@ void MainWindow::file_click(const QModelIndex & indx) { LoadImageFromFile(file); //loads image files } + + + currentFile = gCurrentPageName; + + if(currentFile != ""){ + pageStatusHandler(); + } + break; } default: break; } + } /*! @@ -6768,6 +6724,19 @@ void MainWindow::closeEvent (QCloseEvent *event) event->accept(); } } + + + write_verified_pages(); + write_corrected_pages(); + write_review_pages(); + write_recorrected_pages(); + + correct.clear(); + verify.clear(); + markForReview.clear(); + recorrect.clear(); + + autoSave(); } @@ -6945,7 +6914,8 @@ void MainWindow::on_actionas_PDF_triggered() //! Read the file mainHtml=stream.readAll(); -// mainHtml.remove("background-color:"); + mainHtml.replace("background-color:","Background-colour:"); + // mainHtml.remove("background-color:"); // mainHtml.remove("background-color:#ffff00"); // //! Changing the text background to white by setting the background to #fffff // while (true){ @@ -7224,22 +7194,9 @@ void MainWindow::on_actionUndo_Global_Replace_triggered() int files = 0; reverseGlobalReplacedWordsMap(); - if ( globallyReplacedWords.size() == 1 ) - { - QString oldWord = globallyReplacedWords.firstKey(); - QString newWord = globallyReplacedWords.value(oldWord); - oldWord=oldWord.trimmed(); - newWord=newWord.trimmed(); - bool replace = undoGlobalReplace_Single_Word(oldWord, newWord); - if ( replace ) - undoGRMap.insert(oldWord, newWord); - } - else if ( globallyReplacedWords.size() > 1 ) - { - //qDebug() << "For Multiple Words"; - undoGRMap = getUndoGlobalReplaceMap_Multiple_Words(globallyReplacedWords); - } + undoGRMap = getUndoGlobalReplaceMap_Multiple_Words(globallyReplacedWords); + QString currentDirAbsolutePath = gDirTwoLevelUp + "/" + gCurrentDirName; QDirIterator dirIterator(currentDirAbsolutePath, QDirIterator::Subdirectories); @@ -7264,7 +7221,7 @@ void MainWindow::on_actionUndo_Global_Replace_triggered() QDir directory(gDirTwoLevelUp); QString setName=directory.dirName(); if(!QDir(gDirTwoLevelUp+"/logs").exists()) - QDir().mkdir(gDirTwoLevelUp+"/logs"); + QDir().mkdir(gDirTwoLevelUp+"/logs"); QString filename = gDirTwoLevelUp+"/logs/"+mRole+"_"+setName+"_logs.csv"; //qDebug()< MainWindow::getUndoGlobalReplaceMap_Multiple_Words(QMap undoGRMap; - UndoGlobalReplace ugrWindow(GRMap, this); + UndoGlobalReplace ugrWindow(GRMap, this,mRole,gDirTwoLevelUp); ugrWindow.setModal(true); ugrWindow.exec(); if ( ugrWindow.on_applyButton_clicked() ) undoGRMap = ugrWindow.getFinalUndoMap(); - return GRMap; + return undoGRMap; } /*! @@ -7635,7 +7592,7 @@ void MainWindow::writeSettings() QFile::remove(f); } if(!QDir(gDirTwoLevelUp+"/logs").exists()) - QDir().mkdir(gDirTwoLevelUp+"/logs"); + QDir().mkdir(gDirTwoLevelUp+"/logs"); QString filename = gDirTwoLevelUp + "/logs/."+mRole+"_cursor.txt"; QFile myFile (filename); myFile.open(QIODevice::ReadWrite); @@ -7672,7 +7629,7 @@ void MainWindow::readSettings() int pos1; if(!QDir(gDirTwoLevelUp+"/logs").exists()) - QDir().mkdir(gDirTwoLevelUp+"/logs"); + QDir().mkdir(gDirTwoLevelUp+"/logs"); QString filename = gDirTwoLevelUp + "/logs/."+mRole+"_cursor.txt"; QFile myFile (filename); myFile.open(QIODevice::ReadOnly); @@ -7702,6 +7659,7 @@ void MainWindow::on_action1_triggered() { proj_flag = '0'; isRecentProjclick = true; + on_actionOpen_Project_triggered(); } @@ -7713,6 +7671,7 @@ void MainWindow::on_action2_triggered() { proj_flag = '1'; isRecentProjclick = true; + on_actionOpen_Project_triggered(); } @@ -7724,6 +7683,7 @@ void MainWindow::on_action3_triggered() { proj_flag = '2'; isRecentProjclick = true; + on_actionOpen_Project_triggered(); } @@ -7825,22 +7785,40 @@ void MainWindow::on_actionCheck_for_Updates_triggered() if(curr_version==latestVersion) { QMessageBox box; - box.setText("Software is already on the latest version"); + box.setText("There are currently no updates available"); box.exec(); } else{ QMessageBox msg; msg.setWindowTitle("Update Available"); msg.setIcon(QMessageBox::Information); - msg.setText("A New Version of Udaan Editing Tool is Available!!\n\nUdaan Editing Tool "+latestVersion+"\nTo Download the latest version of this software click 'Go to Download Page' button below\nWhat's New:-\n\n" + newFeatures); - QAbstractButton *download = msg.addButton(tr("Go to Download Page"), QMessageBox::ActionRole); - download->setMinimumWidth(160); + msg.setText("A New Version of Udaan Editing Tool is Available!!\n\nUdaan Editing Tool "+latestVersion+"\nTo Download the latest version of this software click 'Update' button below"); + QAbstractButton *rml = msg.addButton(tr("Later"), QMessageBox::RejectRole); - rml->setMaximumWidth(80); + rml->setMaximumWidth(60); + QAbstractButton *features = msg.addButton(tr("What's New?"), QMessageBox::ApplyRole); + features->setMinimumWidth(80); + QAbstractButton *download = msg.addButton(tr("Update"), QMessageBox::ActionRole); + download->setMinimumWidth(60); + msg.exec(); + if(msg.clickedButton() == features){ + QDialog new_features(this); + QFormLayout form(&new_features); + form.addRow(new QLabel("What's new in "+latestVersion + "\n" + newFeatures,this)); + + QDialogButtonBox buttonbox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,Qt::Horizontal,&new_features); + buttonbox.button(QDialogButtonBox::Ok)->setText("Update"); + form.addRow(&buttonbox); + + QObject::connect(&buttonbox,SIGNAL(accepted()),&new_features,SLOT(accept())); + QObject::connect(&buttonbox,SIGNAL(rejected()),&new_features,SLOT(reject())); + if(new_features.exec() ==QDialog::Accepted) + update_tool(latestVersion); + } if(msg.clickedButton() == download){ - QDesktopServices::openUrl(QUrl("https://drive.google.com/drive/folders/1DZn72n6gH0r459hTGsL2f7qhoZnHQPEI")); + update_tool(latestVersion); } else { msg.close(); @@ -7893,6 +7871,7 @@ void MainWindow::on_find_clicked() void MainWindow::on_actionPDF_Preview_triggered() { QPrinter printer(QPrinter::PrinterResolution); + QPrintPreviewDialog preview(&printer,this); preview.setMinimumHeight(800); preview.setMinimumWidth(800); @@ -7942,7 +7921,7 @@ void MainWindow::print(QPrinter *printer) // mainHtml.replace(stIndex, 6, whiteColor); // Here, 6 is used because length of whiteColor is 6 // startFrom = stIndex + 6; // } -// mainHtml.remove("background-color:"); + // mainHtml.remove("background-color:"); mainHtml.replace("background-color:","Background-colour:"); // mainHtml.remove("background-color:#ffff00"); //latex to png mapping @@ -8277,48 +8256,57 @@ void MainWindow::insertImageAction() imgFileName = imgFileInfo.fileName(); QString imgFilePath = imgFileInfo.filePath(); - QString copiedImgFilePath(gDirTwoLevelUp + "/Inserted_Images/"+imgFileName); - if(!QDir(gDirTwoLevelUp + "/Inserted_Images").exists()) - QDir().mkdir(gDirTwoLevelUp + "/Inserted_Images"); - QFile::copy(imgFilePath,copiedImgFilePath); - qDebug()<text().toInt(); - width=width_textLine->text().toInt(); - } + // form.addRow(new QLabel("Insert Height and Width",this)); + // QLineEdit *height_textLine= new QLineEdit(&dialog); + // QLineEdit *width_textLine= new QLineEdit(&dialog); + // form.addRow("Height",height_textLine); + // form.addRow("Width",width_textLine); - //setting width - // int n = QInputDialog::getInt(this, "Set Width","Width",width,-2147483647,2147483647,1); - // //!setting height - // int n1 = QInputDialog::getInt(this, "Set Height","height",height,-2147483647,2147483647,1); + // QDialogButtonBox buttonbox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,Qt::Horizontal,&dialog); + // form.addRow(&buttonbox); + // QObject::connect(&buttonbox,SIGNAL(accepted()),&dialog,SLOT(accept())); + // QObject::connect(&buttonbox,SIGNAL(rejected()),&dialog,SLOT(reject())); + // if(dialog.exec() ==QDialog::Accepted){ + // height=height_textLine->text().toInt(); + // width=width_textLine->text().toInt(); + // } - QString html = QString("\n ").arg(copiedImgFilePath).arg(width).arg(height); + QString html = QString("\n ").arg(copiedImgFilePath); auto cursor = curr_browser->textCursor(); cursor.insertHtml(html); - } @@ -8376,50 +8364,16 @@ void MainWindow::blockCountChanged(int numOfBlocks) blockCount = numOfBlocks; } - -/*! - * \fn MainWindow::on_actionLogin_triggered - * \brief authenticate function is called. User is redirected to Google login page - */ -void MainWindow::on_actionLogin_triggered() -{ - // authenticate(); - login(); -} - -/*! - * \fn MainWindow::on_actionLogout_triggered - * \brief Function is executed when user logouts. - * \details - * 1. Logout button is not visible - * 2. login button is previewed so that user can login. - */ -void MainWindow::on_actionLogout_triggered() -{ - QSettings settings("IIT-B", "OpenOCRCorrect"); - ui->actionLogout->setVisible(false); - ui->actionLogin->setVisible(true); - settings.beginGroup("loginConsent"); - settings.remove(""); - settings.endGroup(); - settings.beginGroup("login"); - settings.remove(""); - settings.endGroup(); - QMessageBox::information(0,"Logout","Logged out successfully :("); -} - - /*! - * \fn MainWindow::on_actionClone_Repository_triggered + * \fn MainWindow::on_actionImport_triggered * \brief This function helps user to clone repositories from their account. * \details * Checks if user is already logined or not. If not then user is made to login * POST request is send to udaaniitb.aicte-india.org to get the files. * Json Object File is read and converted to Json Array. - * "validate.json" is removed from output * Table is formed to preview how many file does user have in their repository */ -void MainWindow::on_actionClone_Repository_triggered() +void MainWindow::on_actionClone_Repository() { /* * \description @@ -8445,39 +8399,68 @@ void MainWindow::on_actionClone_Repository_triggered() msg.exec(); return; } - // //retrieve details from database and check if user has access to push into this repo settings.beginGroup("login"); QString email = settings.value("email").toString(); QString token = settings.value("token").toString(); settings.endGroup(); - QProcess process; - process.execute("curl -d -X -k -POST --header " - "\"Content-type:application/x-www-form-urlencoded\" https://udaaniitb.aicte-india.org/udaan/email/ -d \"email="+email+"&password="+token+"\" -o validate.json"); - - QJsonObject mainObj = readJsonFile("validate.json"); - QJsonArray repos = mainObj.value("repo_list").toArray(); - QFile::remove("validate.json"); - if(repos.size() == 0){ - QMessageBox msg; - msg.setText("There is nothing to show on dashboard"); - msg.exec(); - return; - } - QJsonArray::iterator itr; int flag = 0; - int lineindex = 0; - QString importHtml=""; - QStandardItemModel *model = new QStandardItemModel; - QMap repoMap; - for(itr = repos.begin(); itr != repos.end(); itr++){ - lineindex++; - repoMap[lineindex] = itr->toString(); - QString num = QString::number(lineindex); - importHtml += QString::fromStdString(""; - } - importHtml += "
#Project ID#Project name
")+num+""+itr->toString()+"
"; - dashboard d(this, importHtml, repos.size(), repoMap); - d.exec(); + QNetworkAccessManager *manager = new QNetworkAccessManager(this); + QUrl url("https://udaaniitb.aicte-india.org/udaan/email/"); + QUrlQuery params; + params.addQueryItem("email", email); + params.addQueryItem("password", token); + QNetworkRequest request(url); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + // Disable SSL certificate verification + QSslConfiguration sslConfig = request.sslConfiguration(); + sslConfig.setPeerVerifyMode(QSslSocket::VerifyNone); + request.setSslConfiguration(sslConfig); + manager->post(request, params.toString(QUrl::FullyEncoded).toUtf8()); + connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { + QSettings settings("IIT-B", "OpenOCRCorrect"); + if (reply->error() == QNetworkReply::NoError) { + m_data = reply->readAll(); + QJsonParseError errorPtr; + QJsonDocument document = QJsonDocument::fromJson(m_data, &errorPtr); + QJsonObject mainObj = document.object(); + QJsonArray repos = mainObj.value("repo_list").toArray(); + if(repos.size() == 0){ + QMessageBox msg; + msg.setText("There is nothing to show on dashboard"); + msg.exec(); + return; + } + QJsonArray::iterator itr; int flag = 0; + int lineindex = 0; + QString importHtml=""; + QStandardItemModel *model = new QStandardItemModel; + QMap repoMap; + for(itr = repos.begin(); itr != repos.end(); itr++){ + lineindex++; + repoMap[lineindex] = itr->toString(); + QString num = QString::number(lineindex); + importHtml += QString::fromStdString("errorString()+"\nThere was an error in the network request. Please try again later or switch your network."); + return; + } + reply->deleteLater(); + }); } @@ -8493,99 +8476,49 @@ void MainWindow::on_actionClone_Repository_triggered() */ void MainWindow::on_actionClose_project_triggered() { + AddRecentProjects(); + + + write_verified_pages(); + write_corrected_pages(); + write_review_pages(); + write_recorrected_pages(); + + + correct.clear(); + verify.clear(); + markForReview.clear(); + recorrect.clear(); + + ui->corrected->setVisible(false); + ui->verified->setVisible(false); + ui->mark_review->setVisible(false); + ui->status->setVisible(false); + + ui->corrected->setEnabled(false); + ui->verified->setEnabled(false); + ui->mark_review->setEnabled(false); + + ui->corrected->setChecked(false); + ui->verified->setChecked(false); + ui->mark_review->setChecked(false); + ui->status->setText("Status - None"); + + if(!mProject.isProjectOpen()){ // QMessageBox::critical(this,"Error","Project Not Opened"); return; //checking if the project is already // opened or not } mProject.setProjectOpen(false); - ui->actionLoadDict->setVisible(false); - ui->actionLoadOCRWords->setVisible(false); - ui->actionLoadDomain->setVisible(false); - ui->actionLoadSubPS->setVisible(false); - ui->actionLoadConfusions->setVisible(false); - ui->actionLoadGDocPage->setVisible(false); - ui->menuSelectLanguage->setTitle(""); - ui->menuCreateReports->setTitle(""); - //disableing the buttons after project is closed - // File Menu - ui->actionSave->setEnabled(false); - ui->actionSave_As->setEnabled(false); - ui->actionSpell_Check->setEnabled(false); - ui->actionLoad_Prev_Page->setEnabled(false); - ui->actionLoad_Next_Page->setEnabled(false); - ui->actionToDevanagari->setEnabled(false); - ui->actionToSlp1->setEnabled(false); - ui->actionLoadGDocPage->setEnabled(false); - ui->actionLoadData->setEnabled(false); - ui->actionLoadDict->setEnabled(false); - ui->actionLoadOCRWords->setEnabled(false); - ui->actionLoadDomain->setEnabled(false); - ui->actionLoadSubPS->setEnabled(false); - ui->actionLoadConfusions->setEnabled(false); - ui->actionSugg->setEnabled(false); - - // Edit Menu - ui->actionUndo->setEnabled(false); - ui->actionRedo->setEnabled(false); - ui->actionFind_and_Replace->setEnabled(false); - ui->actionUndo_Global_Replace->setEnabled(false); - ui->actionUpload->setEnabled(false); - - // Language Menu - ui->actionSanskrit_2->setEnabled(false); - ui->actionEnglish->setEnabled(false); - ui->actionHindi->setEnabled(false); - - // Reports Menu - ui->actionAccuracyLog->setEnabled(false); - ui->actionViewAverageAccuracies->setEnabled(false); - - // View Menu - ui->actionAllFontProperties->setEnabled(false); - ui->actionBold->setEnabled(false); - ui->actionItalic->setEnabled(false); - ui->actionLeftAlign->setEnabled(false); - ui->actionRightAlign->setEnabled(false); - ui->actionCentreAlign->setEnabled(false); - ui->actionJusitfiedAlign->setEnabled(false); - ui->actionSuperscript->setEnabled(false); - ui->actionSubscript->setEnabled(false); - ui->actionInsert_Horizontal_Line->setEnabled(false); - ui->actionFontBlack->setEnabled(false); - ui->actionInsert_Tab_Space->setEnabled(false); - ui->actionPDF_Preview->setEnabled(false); - // if (isVerifier) - ui->actionHighlight->setEnabled(false); - - // Table Menu inside View Menu - ui->actionInsert_Table_2->setEnabled(false); - ui->actionInsert_Columnleft->setEnabled(false); - ui->actionInsert_Columnright->setEnabled(false); - ui->actionInsert_Rowabove->setEnabled(false); - ui->actionInsert_Rowbelow->setEnabled(false); - ui->actionRemove_Column->setEnabled(false); - ui->actionRemove_Row->setEnabled(false); - - // Versions Menu - ui->actionFetch_2->setEnabled(false); - ui->actionTurn_In->setEnabled(false); - ui->actionVerifier_Turn_In->setEnabled(false); - - // Download Menu - ui->actionas_PDF->setEnabled(false); - - ui->actionSymbols->setEnabled(false); - ui->actionZoom_In->setEnabled(false); - ui->actionZoom_Out->setEnabled(false); - ui->actionUnderline->setDisabled(true); - ui->actionJusitfiedAlign->setEnabled(false); + e_d_features(false); //Reset loadData flag LoadDataFlag = 1; //reset data mFilename.clear(); mFilename1.clear(); + // mFile.clear(); LSTM.clear(); CPairs.clear(); @@ -8606,18 +8539,13 @@ void MainWindow::on_actionClose_project_triggered() if(ui->lineEdit_3->text()!="" && ui->lineEdit_3->text()!="Words 0" && ui->lineEdit_3->text()!="0 Words"){ curr_browser->clear(); + curr_browser->setStyleSheet(defaultStyle); } ui->treeView->setModel(nullptr); ui->graphicsView->setScene(nullptr); ui->lineEdit_2->clear(); ui->lineEdit->clear(); ui->lineEdit_3->clear(); - ui->pushButton->setDisabled(true); - ui->pushButton_2->setDisabled(true); - ui->viewComments->setDisabled(true); - ui->compareCorrectorOutput->setDisabled(true); - ui->groupBox->setDisabled(true); - // QMessageBox::information(this,"Success","Project Closed Successfully"); curr_browser=0; } @@ -8856,6 +8784,18 @@ void MainWindow::on_actionEdit_Equation_triggered() */ void MainWindow::on_actionExit_triggered() { + + write_verified_pages(); + write_corrected_pages(); + write_review_pages(); + write_recorrected_pages(); + + markForReview.clear(); + correct.clear(); + verify.clear(); + recorrect.clear(); + + autoSave(); QCoreApplication::quit(); } @@ -8865,7 +8805,7 @@ void MainWindow::on_actionExit_triggered() * \brief Login using email and password * \details Asks user for email and password, then these credentials are verified witrh database and user is logged in if the details submitted by user are correct. * \details User enail is stored in cache for later usage. - * \details curl is used to send post request to server. + * \details QNetwork module is used to send post request to server. */ void MainWindow::login(){ QDialog login(this); @@ -8903,41 +8843,47 @@ void MainWindow::login(){ user_email = email->text(); user_pass = password->text(); if(!user_email.isEmpty() && !user_pass.isEmpty()){ - QProcess process; - process.execute("curl -d -X -k -POST --header " - "\"Content-type:application/x-www-form-urlencoded\" https://udaaniitb.aicte-india.org/udaan/email/ -d \"email="+user_email+"&password="+user_pass+"\" -o client.json"); - - QFile jsonFile("client.json"); - if(!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)){ - QMessageBox::information(0,"Error","Uh-Oh! we are unable to connect to the server at the moment. Try switching your network or contact your administrator."); - return; - } - QByteArray data = jsonFile.readAll(); - QJsonParseError errorPtr; - QJsonDocument document = QJsonDocument::fromJson(data, &errorPtr); - QJsonObject mainObj = document.object(); - jsonFile.close(); - auto status = mainObj.value("status").toBool(); - QFile::remove("client.json"); - - if(status == true){ - //save details in QSettings - settings.beginGroup("login"); - settings.setValue("email",user_email); - settings.setValue("token",user_pass); - settings.endGroup(); - settings.beginGroup("loginConsent"); - settings.setValue("consent","loggedIn"); - settings.endGroup(); - ui->actionLogin->setVisible(false); - ui->actionLogout->setVisible(true); - QMessageBox::information(this,"Login success","Logged in successfully."); - qDebug()<post(request, params.toString(QUrl::FullyEncoded).toUtf8()); + connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { + QSettings settings("IIT-B", "OpenOCRCorrect"); + if (reply->error() == QNetworkReply::NoError) { + m_data = reply->readAll(); + QJsonParseError errorPtr; + QJsonDocument document = QJsonDocument::fromJson(m_data, &errorPtr); + QJsonObject mainObj = document.object(); + auto status = mainObj.value("status").toBool(); + if(status == true){ + //save details in QSettings + settings.beginGroup("login"); + settings.setValue("email",user_email); + settings.setValue("token",user_pass); + settings.endGroup(); + settings.beginGroup("loginConsent"); + settings.setValue("consent","loggedIn"); + settings.endGroup(); + QMessageBox::information(this,"Login success","Logged in successfully."); + } + else{ + QMessageBox::information(this,"Login error","Wrong email or password, please try again."); + this->login(); + } + } else { + QMessageBox::information(this,"Network error",reply->errorString()+"\nThere was an error in the network request. Please try again later or switch your network."); + return; + } + reply->deleteLater(); + }); } else{ QMessageBox::information(this,"Required!","Please fill all the fields"); @@ -8985,7 +8931,7 @@ void MainWindow::on_actionTwo_Column_triggered() { QTextCursor cursor = curr_browser->textCursor(); if(!cursor.hasSelection()) - {; + { QString column1 = curr_browser->toHtml(); curr_browser->clear(); QString html = "
#Project ID#Project name
")+num+""+itr->toString()+"
"+column1+"Paste Column 2 data here
"; @@ -9038,12 +8984,12 @@ void MainWindow::autoSave(){ qDebug()<<"You don't have access to this set."; return; } - if(mRole == "Corrector") - cloud_save(); - else if(mRole == "Verifier"){ - if(verifier_save()) - QMessageBox::information(0, "Cloud sync", "Cloud save successful!"); - } + // if(mRole == "Corrector") + cloud_save(); + // else if(mRole == "Verifier"){ + // if(verifier_save()) + // QMessageBox::information(0, "Cloud sync", "Cloud save successful!"); + // } } else qDebug()<<"Internet unavailable!"; @@ -9063,38 +9009,67 @@ bool MainWindow::check_access() QString email = settings.value("email").toString(); QString token = settings.value("token").toString(); settings.endGroup(); - QProcess process; - process.execute("curl -d -X -k -POST --header " - "\"Content-type:application/x-www-form-urlencoded\" https://udaaniitb.aicte-india.org/udaan/email/ -d \"email="+email+"&password="+token+"\" -o validate.json"); - - //to find the repo name from .git/congig file - QString repo = ""; - QString gDir = gDirTwoLevelUp+"/.git/config"; - QFile f(gDir); - f.open(QIODevice::ReadOnly); - while(!f.atEnd()) { - QString line = f.readLine(); - if(line.contains("https://github.com")){ - QStringList l = line.split("/"); - repo = l[l.size()-1].remove("\n"); - break; - } - } - f.close(); - QJsonObject mainObj = readJsonFile("validate.json"); - QJsonArray repos = mainObj.value("repo_list").toArray(); - QJsonArray::iterator itr; int flag = 0; - for(itr = repos.begin(); itr != repos.end(); itr++){ - if(itr->toString() == repo){ - flag = 1; - break; + QNetworkAccessManager *manager = new QNetworkAccessManager(this); + QUrl url("https://udaaniitb.aicte-india.org/udaan/email/"); + QUrlQuery params; + params.addQueryItem("email", email); + params.addQueryItem("password", token); + QNetworkRequest request(url); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + // Disable SSL certificate verification + QSslConfiguration sslConfig = request.sslConfiguration(); + sslConfig.setPeerVerifyMode(QSslSocket::VerifyNone); + request.setSslConfiguration(sslConfig); + manager->post(request, params.toString(QUrl::FullyEncoded).toUtf8()); + QEventLoop loop; + bool result = false; // initialize the result to false + connect(manager, &QNetworkAccessManager::finished, this, [=, &loop, &result](QNetworkReply *reply) { + if (reply->error() == QNetworkReply::NoError) { + m_data = reply->readAll(); + QString repo = ""; + QString gDir = gDirTwoLevelUp+"/.git/config"; + QFile f(gDir); + f.open(QIODevice::ReadOnly); + while(!f.atEnd()) { + QString line = f.readLine(); + if(line.contains("https://github.com")){ + QStringList l = line.split("/"); + repo = l[l.size()-1].remove("\n"); + break; + } + } + f.close(); + QJsonParseError errors; + QJsonDocument doc = QJsonDocument::fromJson(m_data, &errors); + QJsonObject obj = doc.object(); + QJsonArray repos = obj.value("repo_list").toArray(); + QJsonArray::iterator itr; int flag = 0; + for(itr = repos.begin(); itr != repos.end(); itr++){ + if(itr->toString() == repo){ + flag = 1; + break; + } + } + if(repos.size() == 0 || flag == 0){ + loop.quit(); // exit the event loop + result = false; // set the result to false + QMessageBox msg; + msg.setText("You don't have access to this project on cloud."); + msg.exec(); + } + else{ + loop.quit(); // exit the event loop + result = true; // set the result to true + } + } else { + QMessageBox::information(this,"Network error",reply->errorString()+"\nThere was an error in the network request. Please try again later or switch your network."); + loop.quit(); // exit the event loop + result = false; // set the result to false } - } - QFile::remove("validate.json"); - if(repos.size() == 0 || flag == 0){ - return false; - } - return true; + reply->deleteLater(); + }); + loop.exec(); // start the event loop + return result; // return the result after the event loop has finished } /*! @@ -9123,116 +9098,128 @@ void MainWindow::messageTimer(){ * \details Saves the cloud save success message using QSettings. */ void MainWindow::cloud_save(){ + messageTimer(); QString date = QDate::currentDate().toString(); QString corrected_count = gDirTwoLevelUp + "/Comments/"+mRole+"_count.json"; QJsonObject mainObj, parObj; parObj = readJsonFile(corrected_count); mainObj = parObj[date].toObject(); -// QString Verifier = mainObj["Verifier"].toString(); - mainObj.insert("Corrector", gCurrentPageName); -// mainObj.insert("Verifier", Verifier); + // QString Verifier = mainObj["Verifier"].toString(); + mainObj.insert(mRole, gCurrentPageName); + // mainObj.insert("Verifier", Verifier); parObj.insert(date, mainObj); writeJsonFile(corrected_count, parObj); - //sending credentials - // QProcess process; - // process.execute("curl -d -X -k -POST --header " - // "\"Content-type:application/x-www-form-urlencoded\" https://udaaniitb.aicte-india.org/udaan/email/ -o gitToken.json"); + QNetworkAccessManager* manager = new QNetworkAccessManager(); + QUrl url_("https://udaaniitb.aicte-india.org/udaan/email/"); + + QByteArray postData; + postData.append("username=username&password=password"); + + QNetworkRequest request(url_); + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); + + // Disable SSL certificate verification + QSslConfiguration sslConfig = request.sslConfiguration(); + sslConfig.setPeerVerifyMode(QSslSocket::VerifyNone); + request.setSslConfiguration(sslConfig); + QNetworkReply* reply = manager->post(request, postData); + QEventLoop loop; + QObject::connect(reply, &QNetworkReply::finished, [=, &loop]() { + if (reply->error() == QNetworkReply::NoError) { + QByteArray data = reply->readAll(); + QJsonParseError errorPtr; + QJsonDocument document = QJsonDocument::fromJson(data, &errorPtr); + QJsonObject mainObj = document.object(); + QString git_token = mainObj.value("github_token").toString(); + QString git_username = mainObj.value("github_username").toString(); + // use git_token and git_username here + m_user = git_username.toStdString(); + m_pass = git_token.toStdString(); + loop.quit(); + } else { + qDebug() << "Error:" << reply->errorString(); + } + reply->deleteLater(); + }); + loop.exec(); - // QFile jsonFile("gitToken.json"); - // jsonFile.open(QIODevice::ReadOnly | QIODevice::Text); - // QByteArray data = jsonFile.readAll(); + QString commit_msg = gCurrentPageName + " completed by "+ mRole; // append current version - // QJsonParseError errorPtr; - // QJsonDocument document = QJsonDocument::fromJson(data, &errorPtr); - // QJsonObject mainObj = document.object(); - // jsonFile.close(); - // QString git_token = mainObj.value("github_token").toString(); - // QString git_username = mainObj.value("github_username").toString(); - // QFile::remove("gitToken.json"); - // std::string user = git_username.toStdString(); - // std::string pass = git_token.toStdString(); + //! commits and pushes the file. commit() and push() from Project.cpp creates a commit and pushes the file to git repo + if(mProject.commit(commit_msg.toStdString())) + { + if(mProject.fetch_n_merge(gDirTwoLevelUp, mRole)){ + // threadingPush *tp = new threadingPush(nullptr, mProject.repo, m_user, m_pass, gDirTwoLevelUp); + // QThread *thread = new QThread; + + // connect(thread, SIGNAL(started()), tp, SLOT(ControlPush())); + // connect(tp, SIGNAL(finishedPush()), thread, SLOT(quit())); + // connect(tp, SIGNAL(finishedPush()), tp, SLOT(deleteLater())); + // connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + // connect(tp, SIGNAL(finishedPush()), this, SLOT(stopSpinning())); + // tp->moveToThread(thread); + // thread->start(); + + // spinner = new LoadingSpinner(this); + // spinner->SetMessage("Cloud sync...", "Syncing..."); + // spinner->setModal(false); + // spinner->exec(); + // if (tp->error != 0) { + // mProject.enable_push(false); + // QMessageBox::information(0, "Cloud sync", "Cloud save failed!"); + // return; + // } + // else{ + // QMessageBox::information(0, "Cloud sync", "Cloud sync successful!"); + // QSettings settings("IIT-B", "OpenOCRCorrect"); + // settings.beginGroup("cloudSave"); + // settings.setValue("save","success" ); + // settings.endGroup(); + // } + if(!mProject.push(gDirTwoLevelUp)){ + mProject.enable_push(false); + QMessageBox::information(0, "Cloud sync", "Cloud save failed!"); + return; + } + QMessageBox::information(0, "Cloud sync", "Cloud save successful!"); + QSettings settings("IIT-B", "OpenOCRCorrect"); + settings.beginGroup("cloudSave"); + settings.setValue("save","success" ); + settings.endGroup(); - QString commit_msg = gCurrentPageName+" updated by corrector"; // append current version + //<<<<<moveToThread(thread); - // thread->start(); - - // spinner = new LoadingSpinner(this); - // spinner->SetMessage("Saving to cloud...", "Saving..."); - // spinner->setModal(false); - // spinner->exec(); - // if (tp->error != 0) { + } + // if(mProject.commit(commit_msg.toStdString())){ + // if(!mProject.push(gDirTwoLevelUp)){ // mProject.enable_push(false); // QMessageBox::information(0, "Cloud sync", "Cloud save failed!"); // return; // } - // } - if(mProject.commit(commit_msg.toStdString())){ - if(!mProject.push(gDirTwoLevelUp)){ - mProject.enable_push(false); - QMessageBox::information(0, "Cloud sync", "Cloud save failed!"); - return; - } - mProject.set_corrector(); - - ui->lineEdit_2->setText("Version " + mProject.get_version()); //Update the version of file on ui. - - // QString emailText = "Book ID: " + mProject.get_bookId() - // + "\nSet ID: " + mProject.get_setId() - // + "\n" + commit_msg ; //Send an email if turn-in failed - QMessageBox::information(0, "Cloud sync", "Cloud save successful!"); - QSettings settings("IIT-B", "OpenOCRCorrect"); - settings.beginGroup("cloudSave"); - settings.setValue("save","success" ); - settings.endGroup(); - } -} -/*! - * \brief MainWindow::verifier_save - * \param commit_msg - * \details This function is called in verifier mode when tool is closed. - * \details Calls commit and push functions - * \return Returns true if pushed successfully or false if failed. - */ -bool MainWindow::verifier_save() -{ - messageTimer(); - QString date = QDate::currentDate().toString(); - QString corrected_count = gDirTwoLevelUp + "/Comments/"+mRole+"_count.json"; - QJsonObject mainObj, parObj; - parObj = readJsonFile(corrected_count); - mainObj = parObj[date].toObject(); -// QString Corrector = mainObj["Corrector"].toString(); -// mainObj.insert("Corrector", Corrector); - mainObj.insert("Verifier", gCurrentPageName); - parObj.insert(date, mainObj); - writeJsonFile(corrected_count, parObj); + // ui->lineEdit_2->setText("Version " + mProject.get_version()); //Update the version of file on ui. - QString commit_msg = gCurrentPageName+" verified by verifier"; - if(mProject.commit(commit_msg.toStdString())) - { - if(!mProject.push(gDirTwoLevelUp)){ - mProject.enable_push(false); - QMessageBox::information(0, "Cloud sync", "Cloud save failed!"); - return false; - } - } - return true; + // // QString emailText = "Book ID: " + mProject.get_bookId() + // // + "\nSet ID: " + mProject.get_setId() + // // + "\n" + commit_msg ; //Send an email if turn-in failed + // QMessageBox::information(0, "Cloud sync", "Cloud save successful!"); + // QSettings settings("IIT-B", "OpenOCRCorrect"); + // settings.beginGroup("cloudSave"); + // settings.setValue("save","success" ); + // settings.endGroup(); + // } } /*! @@ -9243,7 +9230,7 @@ bool MainWindow::verifier_save() */ void MainWindow::preprocessing(){ if(!QDir(gDirTwoLevelUp+"/logs").exists()) - QDir().mkdir(gDirTwoLevelUp+"/logs"); + QDir().mkdir(gDirTwoLevelUp+"/logs"); QString loc = gDirTwoLevelUp + "/logs/."+mRole+"_dan.log"; QFile sFile(loc); slpNPatternDict slnp; @@ -9432,6 +9419,11 @@ void MainWindow::speechToTextCall() QJsonObject object=responseJson.object(); QString ResponseText=object["results"].toArray()[0].toObject() ["alternatives"].toArray()[0].toObject()["transcript"].toString(); + QString ResponseTextAlt=object["results"].toArray()[1].toObject() + ["alternatives"].toArray()[0].toObject()["transcript"].toString(); + if(!ResponseTextAlt.isEmpty()){ + ResponseText += " " + ResponseTextAlt; + } QTextCursor cur = curr_browser->textCursor(); cur.insertText(ResponseText); } @@ -9448,12 +9440,13 @@ void MainWindow::speechToTextCall() * \details "Speech to text" status means user can start recording. "Stop ?" means audio recording is in progress and user can stop it by clicking the "Stop ?" button. * \details "Processing ..." means the user input is in process and the requested audio will be converted into text and pasted at cursor position. Text is inserted at cursor position * \details and status of button is changed back to "Speech to text". + * \author Sadam */ void MainWindow::on_pushButton_4_clicked() { if(!isProjectOpen) return; + QString fileName = QDir::currentPath() + "/audio.wav"; if (m_audioRecorder->state() == QMediaRecorder::StoppedState) { - QString fileName = QDir::currentPath() + "/audio.wav"; m_audioRecorder->setOutputLocation(QUrl::fromLocalFile(fileName)); qDebug()<<"Recording your audio!!"; ui->pushButton_4->setText("Stop ?"); @@ -9477,9 +9470,17 @@ void MainWindow::on_pushButton_4_clicked() ui->pushButton_4->setText("Processing ..."); m_audioRecorder->stop(); speechToTextCall(); + QFile::remove(fileName); } } +/*! + * \brief MainWindow::on_actionFill_Table_triggered + * \details When shade Table is clicked, this function is called. It checked if the selected text is table or not. + * \details If the selection doesn't contain table, control returns back, else it highlights selected cells of the + * \details current table with the user selected color. + * \author Sadam + */ void MainWindow::on_actionFill_Table_triggered() { QTextCursor cursor = curr_browser->textCursor(); @@ -9492,13 +9493,6 @@ void MainWindow::on_actionFill_Table_triggered() // Get the table format and set the alignment to center QTextTableFormat tableFormat = selectedTable->format(); - - // Open a color picker dialog to get the user's chosen color -// QColorDialog colorDialog(curr_browser); -// colorDialog.setWindowTitle("Select Table Background Color"); -// if (colorDialog.exec() != QDialog::Accepted) { -// return; -// } QColor color = QColorDialog::getColor(); // Set the background color for each selected cell in the table @@ -9507,3 +9501,1195 @@ void MainWindow::on_actionFill_Table_triggered() curr_browser->textCursor().setBlockCharFormat(cellFormat); } + +void MainWindow::on_backward_Button_clicked() +{ + ui->tabWidget->setVisible(false); + ui->backward_Button->hide(); + ui->forward_Button->show(); +} + + +void MainWindow::on_forward_Button_clicked() +{ + ui->tabWidget->setVisible(true); + ui->forward_Button->hide(); + ui->backward_Button->show(); +} + +/*! + * Project is opened after importing + */ +void MainWindow::on_actionImport_and_Open_triggered() +{ + on_actionOpen_Project_triggered(); + import_flag = false; +} + +void MainWindow::on_actionImport_triggered() +{ + on_actionClone_Repository(); + import_flag = false; +} + + + +void MainWindow::on_actionEnter_manauly_triggered() +{ + if(!curr_browser || curr_browser->isReadOnly()) + return; + + QDialog dialog(this); + QFormLayout form(&dialog); // Use a layout allowing to have a label next to each field + form.addRow(new QLabel("Enter number of rows & columns", this)); // Create a dialog for asking table dimensions + + //! Add the lineEdits with their respective labels + QSpinBox *rows = new QSpinBox(&dialog); + QSpinBox *columns = new QSpinBox(&dialog); // Add lineEdits to get Rows + form.addRow("Rows", rows); // Add lineEdits to get Columns + form.addRow("Columns", columns); + + //! Add some standard buttons (Cancel/Ok) at the bottom of the dialog + QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog); // Add some standard buttons (Cancel/Ok) at the bottom of the dialog + form.addRow(&buttonBox); + QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept())); + QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject())); + + //! Show the dialog as modal + if (dialog.exec() == QDialog::Accepted) + { + + QTextTableFormat tf; + tf.setBorderBrush(Qt::black); + tf.setCellSpacing(0); + tf.setCellPadding(7); + // tf.setAlignment(Qt::AlignCenter); + QTextCursor cursor = curr_browser->textCursor(); + cursor.insertTable(rows->text().toInt(),columns->text().toInt(),tf); + } + tableDialog->close(); +} + +/*! + * \fn MainWindow::on_pushButton_5_clicked + * \brief Function is executed when user clicks on top right corner user icon. + * \details If user is not logged in, login dialog prompts. + * \details Else logout dialog prompts. + * \details If the user clicks on 'sign out' button, user is signed out of the Udaan PE tool. + */ +void MainWindow::on_pushButton_5_clicked() +{ + QSettings settings("IIT-B", "OpenOCRCorrect"); + settings.beginGroup("login"); + QString email = settings.value("email").toString(); + settings.endGroup(); + if(email.isEmpty()){ + login(); + } + else{ + QDialog logout(this); + QFormLayout form(&logout); + form.addRow(new QLabel("You are signed in as\n"+email+"\n",this)); + QDialogButtonBox buttonbox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,Qt::Horizontal,&logout); + buttonbox.button(QDialogButtonBox::Ok)->setText("Sign Out"); + buttonbox.button(QDialogButtonBox::Cancel)->setText("Close"); + form.addRow(&buttonbox); + + QObject::connect(&buttonbox,SIGNAL(accepted()),&logout,SLOT(accept())); + QObject::connect(&buttonbox,SIGNAL(rejected()),&logout,SLOT(reject())); + if(logout.exec() ==QDialog::Accepted){ + QSettings settings("IIT-B", "OpenOCRCorrect"); + ui->actionLogout->setVisible(false); + ui->actionLogin->setVisible(true); + settings.beginGroup("loginConsent"); + settings.remove(""); + settings.endGroup(); + settings.beginGroup("login"); + settings.remove(""); + settings.endGroup(); + QMessageBox::information(0,"Logout","Logged out successfully :("); + } + + } + +} + +void MainWindow::e_d_features(bool value) +{ + ui->actionSave->setEnabled(value); + ui->actionLoad_Prev_Page->setEnabled(value); + ui->actionLoad_Next_Page->setEnabled(value); + ui->actionClose_project->setEnabled(value); + ui->actionPDF_Preview->setEnabled(value); + ui->actionas_PDF->setEnabled(value); + ui->mainToolBar->setEnabled(value); + ui->pushButton->setEnabled(value); + ui->pushButton_2->setEnabled(value); + ui->pushButton_4->setEnabled(value); + ui->comboBox->setEnabled(value); + ui->pushButton_3->setEnabled(value); + ui->menuEdit->setEnabled(value); + ui->menuInsert->setEnabled(value); + ui->menuFormat->setEnabled(value); + ui->menuTool->setEnabled(value); + ui->menuGit->setEnabled(value); + ui->comboBox->setEnabled(value); + ui->zoom_In_Button->setEnabled(value); + ui->zoom_Out_Button->setEnabled(value); + ui->horizontalSlider->setEnabled(value); + + ui->actionFetch_2->setEnabled(true); + +} + + + +void MainWindow::on_actionImport_2_triggered() +{ + on_actionClone_Repository(); + import_flag = false; +} + +void MainWindow::on_actionTable_2_triggered() +{ + if(!curr_browser || curr_browser->isReadOnly()) + return; + tableDialog=new QDialog(); + tableDialog->setWindowTitle("Insert Table"); + QVBoxLayout *layout = new QVBoxLayout(tableDialog); + QLabel *label = new QLabel("Use mouse to select cells\nDouble click to insert table."); + layout->addWidget(label); + m_table = new QTableWidget(5, 5,this); + m_table->setSelectionMode(QAbstractItemView::MultiSelection); + layout->addWidget(m_table); + QPushButton *button = new QPushButton("Insert table manually..."); + button->setStyleSheet("border: 1px solid #efefef;text-align:left; margin-top: 10px;"); + QObject::connect(button, &QPushButton::clicked, this, &MainWindow::on_actionEnter_manauly_triggered); + + layout->addWidget(button); + QTableWidgetItem *itm; + for(int i=0;i<5;i++){ + for(int j=0;j<5;j++){ + itm = new QTableWidgetItem(); + itm->setData(Qt::DisplayRole,QString(".")); + itm->setForeground(QBrush(QColor(255,255,255))); + m_table->setItem(i,j,itm); + m_table->setColumnWidth(i,1); + } + } + + QObject::connect(m_table,&QTableWidget::itemSelectionChanged,this,[=](){ + selectedItems=m_table->selectedItems(); + }); + + tableDialog->setLayout(layout); + tableDialog->setSizeGripEnabled(true); + tableDialog->resize(QSize(320,280)); + tableDialog->exec(); +} + +void MainWindow::on_actionCut_triggered() +{ + curr_browser->cut(); +} + +void MainWindow::on_actionCopy_triggered() +{ + curr_browser->copy(); +} + + +void MainWindow::on_actionPaste_triggered() +{ + curr_browser->paste(); +} + + +void MainWindow::on_actionSelect_All_triggered() +{ + curr_browser->selectAll(); +} + + +void MainWindow::on_actionDelete_triggered() +{ + QTextCursor cursor = curr_browser->textCursor(); + if(cursor.hasSelection()) { + cursor.removeSelectedText(); + } +} + + +void MainWindow::on_actionDate_triggered() +{ + QDate date; + QCalendarWidget *calendar = new QCalendarWidget(this); + calendar->setGeometry(100, 100, 400, 400); + calendar->show(); + + connect(calendar, &QCalendarWidget::selectionChanged, this, [=](){ + getDate(date, calendar); + }); +} + +void MainWindow::getDate(QDate date, QCalendarWidget *calendar) { + date = calendar->selectedDate(); + QTextCursor cursor = curr_browser->textCursor(); + cursor.insertText(date.toString("dd/MMMM/yyyy")); + calendar->deleteLater(); +} + + +void MainWindow::on_actionLink_triggered() +{ + QDialog dialog(this); + QFormLayout form(&dialog); // Use a layout allowing to have a label next to each field + form.addRow(new QLabel("Enter the url and the placeholder", this)); + + //! Add the lineEdits with their respective labels + QLineEdit *link = new QLineEdit(&dialog); + QLineEdit *text = new QLineEdit(&dialog); + form.addRow("url", link); + form.addRow("title", text); + + //! Add some standard buttons (Cancel/Ok) at the bottom of the dialog + QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog); + form.addRow(&buttonBox); + QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept())); + QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject())); + + //! Show the dialog as modal + if (dialog.exec() == QDialog::Accepted) + { + QTextCursor cursor = curr_browser->textCursor(); + cursor.insertHtml("text() + "\">" + text->text() + ""); + } +} + +/*! + * \fn MainWindow::on_actionUnderline_2_triggered() + * \brief This function underlines the selected text + */ +void MainWindow::on_actionUnderline_2_triggered() +{ + on_actionUnderline_triggered(); +} + +/*! + * \fn MainWindow::on_actionIncrease_size_triggered() + * \brief This function increases the font size of selected text + */ +void MainWindow::on_actionIncrease_size_triggered() +{ + on_actionZoom_In_triggered(); +} + +/*! + * \fn MainWindow::on_actionDecrease_Size_triggered() + * \brief This function descreases the font size of selected text + */ +void MainWindow::on_actionDecrease_Size_triggered() +{ + on_actionZoom_Out_triggered(); +} + +/*! + * \fn MainWindow::on_actionlower_case_triggered() + * \brief This function displays the letter in lower case + */ +void MainWindow::on_actionlower_case_triggered() +{ + if(!curr_browser || curr_browser->isReadOnly()) + return; + QTextCursor cursor = curr_browser->textCursor(); + QTextCharFormat fmt; + fmt.setFontCapitalization(QFont::AllLowercase); + cursor.mergeCharFormat(fmt); + curr_browser->mergeCurrentCharFormat(fmt); +} + +/*! + * \fn MainWindow::on_actionUPPER_CASE_triggered() + * \brief This function displays the letter in upper case + */ +void MainWindow::on_actionUPPER_CASE_triggered() +{ + if(!curr_browser || curr_browser->isReadOnly()) + return; + QTextCursor cursor = curr_browser->textCursor(); + QTextCharFormat fmt; + fmt.setFontCapitalization(QFont::AllUppercase); + cursor.mergeCharFormat(fmt); + curr_browser->mergeCurrentCharFormat(fmt); +} + +/*! + * \fn MainWindow::on_actionTitle_Case_triggered() + * \brief This function changes the case of a word where first letter is upper and rest is lower + */ +void MainWindow::on_actionTitle_Case_triggered() +{ + if(!curr_browser || curr_browser->isReadOnly()) + return; + QTextCursor cursor = curr_browser->textCursor(); + QTextCharFormat fmt; + fmt.setFontCapitalization(QFont::Capitalize); + cursor.mergeCharFormat(fmt); + curr_browser->mergeCurrentCharFormat(fmt); +} + +void MainWindow::on_actionDelete_Table_triggered() +{ + if(!curr_browser || curr_browser->isReadOnly()) + return; + if(curr_browser->textCursor().currentTable()) + { + QTextCursor cursor = curr_browser->textCursor(); + if(cursor.currentTable() != nullptr) { + cursor.setPosition(cursor.currentTable()->cellAt(0, 0).firstCursorPosition().position()); + QTextTable *table = cursor.currentTable(); + int numRows = table->rows(); + table->removeRows(0, numRows); + } + } +} + +void MainWindow::on_actionClear_Formatting_triggered() +{ + QTextCursor cursor = curr_browser->textCursor(); + cursor.setCharFormat(QTextCharFormat()); +} + +void MainWindow::on_actionImage_triggered() +{ + insertImageAction(); +} + + +void MainWindow::on_actionAbout_Udaan_PE_triggered() +{ + about ab; + ab.exec(); +} +/*! + * \fn MainWindow::on_actionIncrease_Indent_triggered + * \brief Adding Indentation upto 14.65 {i.e. touched right margin} {in cm} +*/ +void MainWindow::on_actionIncrease_Indent_triggered(int left, int right) +{ + if(!curr_browser || curr_browser->isReadOnly()) + return; + QMargins margin = curr_browser->contentsMargins(); + QTextCursor cursor = curr_browser->textCursor(); + + QTextBlock block = cursor.block(); + QTextBlockFormat blockFormat = block.blockFormat(); + + int presentIndent = blockFormat.indent(); + + + int indent = 1+presentIndent; + + if(left != 0) indent = left; + if(indent > 14) return; + + if(right == 0)blockFormat.setRightMargin(margin.right()); + else blockFormat.setRightMargin(right); + blockFormat.setIndent(indent); + + // qDebug()<<"Increase Indent ->"<isReadOnly()) + return; + QMargins margin = curr_browser->contentsMargins(); + QTextCursor cursor = curr_browser->textCursor(); + + QTextBlock block = cursor.block(); + QTextBlockFormat blockFormat = block.blockFormat(); + + int presentIndent = blockFormat.indent(); + + int indent = presentIndent-1; + + if(indent < 0) return; + + blockFormat.setLeftMargin(margin.left()); + blockFormat.setIndent(presentIndent - 1); + + // qDebug()<<"Decrease Indent ->"< 14){ + return; + } + + on_actionIncrease_Indent_triggered(left,right); +} + +/*! + * \fn MainWindow::on_actionSpecial_Characters_triggered() + * \brief This function displays the special symbol dialog + */ +void MainWindow::on_actionSpecial_Characters_triggered() +{ + on_actionSymbols_triggered(); +} + +/*! + * \fn MainWindow::on_actionResize_Image_2_triggered() + * \brief This function resize image by inserting width and height + */ +void MainWindow::on_actionResize_Image_2_triggered() +{ + on_actionResize_Image_triggered(); +} + +/*! + * \fn MainWindow::on_actionWord_Count_triggered() + * \brief This function displays word count in current page ,total number of pages and total number of words in all pages + */ +void MainWindow::on_actionWord_Count_triggered() +{ + if(curr_browser){ + QString extText = curr_browser->toPlainText(); + //!Removes these symbol while counting + extText.remove("?"); + extText.remove("|"); + extText.remove("`"); + extText.remove("["); + extText.remove("]"); + extText.remove("'"); + extText.remove(","); + + int wordcnt = extText.split(QRegExp("(\\s|\\n|\\r)+"), QString::SkipEmptyParts).count(); + QString str = QString::number(wordcnt); + QString currentDirAbsolutePath; + if(mRole=="Verifier") + currentDirAbsolutePath = gDirTwoLevelUp + "/VerifierOutput/"; + else if (mRole=="Corrector") { + currentDirAbsolutePath = gDirTwoLevelUp + "/CorrectorOutput/"; + } + + + //! We then open this directory and set sorting preferences. + QDir dir(currentDirAbsolutePath); + dir.setSorting(QDir::SortFlag::DirsFirst | QDir::SortFlag::Name); + QDirIterator dirIterator(dir,QDirIterator::NoIteratorFlags); + qDebug()<setText(str); + page->setText(str1); + total_words->setText(str3); + page->setReadOnly(true); + c_page->setReadOnly(true); + total_words->setReadOnly(true); + form.addRow("Current Page", c_page); + form.addRow("Total Pages", page); + form.addRow("Total Words",total_words); + dialog.exec(); + } +} + +/*! + * \fn MainWindow::on_actionVoice_Typing_triggered() + * \brief This function starts recording the voice + */ +void MainWindow::on_actionVoice_Typing_triggered() +{ + on_pushButton_4_clicked(); +} + + + + +void MainWindow::on_actionTable_Border_Color_triggered() +{ + if(!curr_browser || curr_browser->isReadOnly()) + return; + if(curr_browser->textCursor().currentTable()) { + QColor color = QColorDialog::getColor(Qt::black, this, tr("Select color")); + if(color.isValid()) { + QTextCursor cursor = curr_browser->textCursor(); + QTextTable *table = cursor.currentTable(); + QTextTableFormat format = table->format(); + format.setBorderBrush(color); + table->setFormat(format); + } + + } +} + +void MainWindow::on_corrected_clicked() +{ + QString fileName = currentFile; + + if(ui->corrected->checkState() == Qt::Checked && markForReview[fileName] != 0){ + correct[fileName] = 1; + recorrect[fileName] = 1; + ui->corrected->setChecked(true); + ui->status->setText("Corrected"); + } + else if(ui->corrected->checkState() == Qt::Checked ){ + correct[fileName] = 1; + recorrect[fileName] = 0; + ui->corrected->setChecked(true); + ui->status->setText("Corrected"); + } + else if(markForReview[fileName] != 0){ + ui->status->setText("Marked For Review"); + recorrect[fileName] = 0; + correct[fileName] = 0; + ui->corrected->setEnabled(true); + ui->corrected->setChecked(false); + } + else{ + correct[fileName] = 0; + recorrect[fileName] = 0; + ui->corrected->setChecked(false); + ui->status->setText("Status - None"); + } +} + + +void MainWindow::on_verified_clicked() +{ + QString fileName = currentFile; + + if(ui->mark_review->checkState() == Qt::Checked){ + ui->verified->setEnabled(false); + ui->verified->setChecked(false); + ui->status->setText("Marked For Review"); + return; + } + + if(ui->verified->checkState() == Qt::Checked && correct[currentFile] != 0){ + verify[fileName] = 1; + + ui->verified->setChecked(true); + ui->corrected->setChecked(true); + ui->mark_review->setEnabled(false); + ui->status->setText("Verified"); + } + else if(correct[currentFile] != 0){ + verify[fileName] = 0; + ui->status->setText("Corrected"); + ui->verified->setEnabled(true); + ui->mark_review->setEnabled(true); + } + else{ + verify[fileName] = 0; + ui->verified->setChecked(false); + ui->mark_review->setEnabled(true); + ui->status->setText("Status - None"); + } +} + + + +void MainWindow::on_actionCell_Padding_triggered() +{ + if(!curr_browser || curr_browser->isReadOnly()) + return; + QDialog dialog(this); + QFormLayout form(&dialog); + form.addRow(new QLabel("Enter the amount of padding to be applied", this)); + + QSpinBox *inp = new QSpinBox(&dialog); + inp->setRange(0, 10); + form.addRow("Padding", inp); + + //! Add some standard buttons (Cancel/Ok) at the bottom of the dialog + QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog); + form.addRow(&buttonBox); + QObject::connect(&buttonBox, SIGNAL(accepted()), &dialog, SLOT(accept())); + QObject::connect(&buttonBox, SIGNAL(rejected()), &dialog, SLOT(reject())); + int padding; + if (dialog.exec() == QDialog::Accepted) + { + padding = inp->value(); + if(curr_browser->textCursor().currentTable()) + { + QTextCursor cursor = curr_browser->textCursor(); + if(cursor.currentTable() != nullptr) { + cursor.setPosition(cursor.currentTable()->cellAt(0, 0).firstCursorPosition().position()); + QTextTable *table = cursor.currentTable(); + QTextTableFormat format = table->format(); + format.setCellPadding(padding); + table->setFormat(format); + } + } + } +} + +void MainWindow::update_tool(QString latestVersion){ +#ifdef Q_OS_WIN + QUrl downloadUrl("https://www.cse.iitb.ac.in/~ayusham/Udaan-Windows-"+latestVersion+".zip"); + QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/"+latestVersion+".zip"; +#else + QUrl downloadUrl("https://www.cse.iitb.ac.in/~ayusham/Udaan-Linux-"+latestVersion+".tar.xz"); + QString path = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + "/"+latestVersion+".tar.xz"; +#endif + QDialog dialog(this); + QFormLayout form(&dialog); + QProgressBar pb(&dialog); + QLabel *label = new QLabel(&dialog); + QLabel *labelProgress = new QLabel(&dialog); + labelProgress->setText(""); + label->setText("Update in progress..."); + form.addRow(label); + form.addWidget(&pb); + form.addRow(labelProgress); + dialog.show(); + QNetworkAccessManager *manager = new QNetworkAccessManager(this); + QNetworkRequest request(downloadUrl); + QNetworkReply *reply = manager->get(request); + QFile *file = new QFile(path); + file->open(QIODevice::WriteOnly); + + QString currentDirectory = m_update_path; + QDir directory(currentDirectory); + QString m_t_path = directory.absolutePath(); + directory.cdUp(); + directory.cdUp(); + QString output = directory.absolutePath(); + + connect(reply, &QNetworkReply::readyRead, this, [=]() { + file->write(reply->readAll()); + //file->close(); + }); + connect(reply, &QNetworkReply::finished, this, [&]() { + file->close(); +#ifdef Q_OS_WIN + QuaZip zip(path); + if (!zip.open(QuaZip::mdUnzip)) { + qDebug() << "Failed to open ZIP file:" << zip.getZipError(); + QMessageBox::warning(this, "Update error", "We were unable to find the zip file\nSource: "+path, QMessageBox::Ok); + return; + } + + QuaZipFile file(&zip); + + QuaZipFileInfo info; + + for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) { + if (!zip.getCurrentFileInfo(&info)) break; + + QString name = info.name; + QDir().mkdir(output + "Udaan-" + latestVersion + "/"); + QString outputFilePath = output + "Udaan-" + latestVersion + "/" + name; + qDebug() << "This is the path" << outputFilePath; + if (!file.open(QIODevice::ReadOnly)) break; + QByteArray data = file.readAll(); + file.close(); + QFile outputFile(outputFilePath); + QString temp = outputFilePath; + QStringList list = outputFilePath.split("/"); + temp.remove(list[list.size() - 1]); + QFile tempFile(temp); + if (!tempFile.exists()) { + QDir().mkdir(temp); + } + if (!outputFile.open(QIODevice::WriteOnly)) { + qDebug() << "Failed to open output file:" << outputFile.errorString() << outputFile.fileName(); + continue; + } + outputFile.write(data); + outputFile.close(); + } + zip.close(); + + QMessageBox::StandardButton reply_d; + reply_d = QMessageBox::question(this, "Restart Application", + "qpadfinal has been successfully updated to latest version\nAre you sure you want to restart the application to use the updated version?", + QMessageBox::Yes | QMessageBox::No); + QSettings settings("IIT-B", "OpenOCRCorrect"); + if (reply_d == QMessageBox::Yes) { + // Quit the application + QProcess process; + QStringList arguments; + QString command = "start " + output + "Udaan-" + latestVersion + "/" + latestVersion + "/qpadfinal.exe"; + arguments << "/c" << command; + process.startDetached("cmd.exe", arguments); + process.waitForFinished(); + + qDebug() << "saved " << m_t_path; + settings.beginGroup("prev-version"); + settings.setValue("link", m_t_path); + settings.endGroup(); + qApp->quit(); + } + + qDebug() << "saved " << m_t_path; + settings.beginGroup("prev-version"); + settings.setValue("link", m_t_path); + settings.endGroup(); + +#else + QProcess* process = new QProcess(this); + QString command = "tar -xJf " + path + " -C " + output; + process->start("/bin/sh", QStringList() << "-c" << command); + qDebug() << process->arguments(); + process->waitForFinished(100000000); + + if (process->exitCode() != QProcess::NormalExit || process->exitStatus() != QProcess::NormalExit) { + qDebug() << process->readAllStandardError(); + } + + QMessageBox::information(this, "Update status", "Extraction of the Udaan pe tool udpate file is successfully completed." + "\nTo rebuild the application, run these following commands in order - " + "\n⚫ make clean" + "\n⚫ qmake qpadfinal.pro" + "\n⚫ make", QMessageBox::Button::Ok); +#endif + QFile::remove(path); + reply->deleteLater(); +}); + connect(reply, &QNetworkReply::downloadProgress, this, [&](qint64 bytesReceived, qint64 bytesTotal) { + processProgress(bytesReceived, bytesTotal, &pb, labelProgress); + }); + + QEventLoop loop; + connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); + loop.exec(); +} +void MainWindow::processProgress(qint64 bytesReceived, qint64 bytesTotal, QProgressBar *pb, QLabel *labelProgress) { + qDebug()<setValue((bytesReceived * 100) / bytesTotal); + labelProgress->setText(QString::number(bytesReceived/1000000) + "MB/" + QString::number(bytesTotal/1000000) +"MB"); +} + +/*! + * \fn MainWindow::on_pushButton_6_clicked() + * \brief This function replaces all the changed words globally + */ +void MainWindow::on_pushButton_6_clicked() +{ + QString currentDirAbsolutePath = gDirTwoLevelUp + "/" + gCurrentDirName; + runGlobalReplace(currentDirAbsolutePath, changedWords); + ConvertSlpDevFlag =0; + changedWords.clear(); + ui->pushButton_6->setVisible(false); +} + + +void MainWindow::on_mark_review_clicked() +{ + QString fileName = currentFile; + + if(ui->verified->checkState() == Qt::Checked) { + ui->mark_review->setChecked(false); + ui->mark_review->setEnabled(false); + ui->status->setText("Verified"); + return; + } + + if(ui->mark_review->checkState() == Qt::Checked && correct[currentFile] != 0){ + markForReview[currentFile] = 1; + ui->mark_review->setChecked(true); + ui->verified->setEnabled(false); + ui->status->setText("Marked For Review"); + } + else if(correct[currentFile] != 0){ + markForReview[fileName] = 0; + ui->status->setText("Corrected"); + ui->verified->setEnabled(true); + ui->mark_review->setEnabled(true); + } + else{ + markForReview[fileName] = 0; + ui->verified->setChecked(false); + ui->verified->setEnabled(false); + ui->mark_review->setEnabled(false); + ui->status->setText("Status - None"); + } +} + + +void MainWindow::write_corrected_pages(){ + QString directory = mProject.GetDir().absolutePath(); + + //Logs folder + QString folder = directory + "/logs"; + + if(!QDir(folder).exists()){ + QDir(gDirTwoLevelUp).mkdir("logs"); + } + + QString file = folder + "/corrected_page.txt"; + + QFile f(file); + f.remove(); + + if(f.open(QIODevice::WriteOnly)){ + QTextStream outputStream(&f); + QString string; + QMapIteratori(correct); + while(i.hasNext()){ + i.next(); + string = i.key(); + + if(i.value() != 0){ + outputStream << string << endl; + } + } + f.close(); + } +} + +void MainWindow::read_corrected_pages(){ + QString fstring = mProject.GetDir().absolutePath() + "/logs/corrected_page.txt"; + QFile f(fstring); + if(!f.open(QIODevice::ReadOnly)) + return; + + QTextStream in(&f); + while(!in.atEnd()) { + QString line = in.readLine(); + if(!line.contains(".html"))continue; + + correct[line] = 1; + } + f.close(); + + +} + +void MainWindow::write_verified_pages(){ + QString directory = mProject.GetDir().absolutePath(); + + //Logs folder + QString folder = directory + "/logs"; + + if(!QDir(folder).exists()){ + QDir(gDirTwoLevelUp).mkdir("logs"); + } + + QString file = folder + "/verified_page.txt"; + + QFile f(file); + f.remove(); + + if(f.open(QIODevice::WriteOnly)){ + QTextStream outputStream(&f); + QString string; + QMapIteratori(verify); + while(i.hasNext()){ + i.next(); + string = i.key(); + if(i.value() != 0){ + outputStream << string << endl; + } + + } + f.close(); + } +} + +void MainWindow::read_verified_pages(){ + QString fstring = mProject.GetDir().absolutePath() + "/logs/verified_page.txt"; + QFile f(fstring); + if(!f.open(QIODevice::ReadOnly)) + return; + + QTextStream in(&f); + while(!in.atEnd()) { + QString line = in.readLine(); + if(!line.contains(".html"))continue; + verify[line] = 1; + } + f.close(); +} + +void MainWindow::read_review_pages(){ + QString fstring = mProject.GetDir().absolutePath() + "/logs/marked_for_review_page.txt"; + QFile f(fstring); + if(!f.open(QIODevice::ReadOnly)) + return; + + QTextStream in(&f); + while(!in.atEnd()) { + QString line = in.readLine(); + if(!line.contains(".html"))continue; + markForReview[line] = 1; + + } + f.close(); +} + +void MainWindow::write_review_pages(){ + QString directory = mProject.GetDir().absolutePath(); + + //Logs folder + QString folder = directory + "/logs"; + + if(!QDir(folder).exists()){ + QDir(gDirTwoLevelUp).mkdir("logs"); + } + + QString file = folder + "/marked_for_review_page.txt"; + + QFile f(file); + + /* if (mRole == "Corrector") { + if(f.open(QIODevice::WriteOnly)){ + QTextStream outputStream(&f); + QString string; + QMapIteratori(markForReview); + while(i.hasNext()){ + i.next(); + string = i.key(); + + if(i.value() != 0){ + outputStream << string << endl; + } + } + f.close(); + } + }*/ + if(mRole == "Verifier"){ + if(f.open(QIODevice::ReadWrite)){ + QTextStream in(&f); + QString line = ""; + while(!in.atEnd()) { + line = in.readAll(); + } + + QTextStream outputStream(&f); + QString string; + QMapIteratori(markForReview); + outputStream << line << endl; qDebug() << line; + while(i.hasNext()){ + i.next(); + string = i.key(); + if(mRole == "Verifier")correct[string] = 0; + if(i.value() != 0){ + outputStream << string << endl; + } + } + f.close(); + } + } +} + +void MainWindow::read_recorrected_pages(){ + QString fstring = mProject.GetDir().absolutePath() + "/logs/recorrected_page.txt"; + QFile f(fstring); + if(!f.open(QIODevice::ReadOnly)) + return; + + QTextStream in(&f); + while(!in.atEnd()) { + QString line = in.readLine(); + if(!line.contains(".html"))continue; + recorrect[line] = 1; + } + f.close(); +} + +void MainWindow::write_recorrected_pages(){ + QString directory = mProject.GetDir().absolutePath(); + + //Logs folder + QString folder = directory + "/logs"; + + if(!QDir(folder).exists()){ + QDir(gDirTwoLevelUp).mkdir("logs"); + } + + QString file = folder + "/recorrected_page.txt"; + + QFile f(file); + f.remove(); + + if(f.open(QIODevice::WriteOnly)){ + QTextStream outputStream(&f); + QString string; + QMapIteratori(recorrect); + while(i.hasNext()){ + i.next(); + string = i.key(); + + if(i.value() != 0){ + outputStream << string << endl; + } + } + f.close(); + } +} + +void MainWindow::on_actionClear_Menu_triggered() +{ + + QSettings settings("IIT-B", "OpenOCRCorrect"); + settings.beginGroup("RecentProjects"); + if(mProject.isProjectOpen()) settings.setValue("Project", RecentProjFile); + else settings.setValue("Project", ""); + settings.setValue("Project2",""); + settings.setValue("Project3",""); + ui->menuRecent_Project->clear(); + isRecentProjclick = false; + settings.endGroup(); +} + +void MainWindow::on_actionJustified_triggered() +{ + on_actionJusitfiedAlign_triggered(); +} + +void MainWindow::pageStatusHandler(){ + if(mRole == "Corrector"){ + ui->corrected->setEnabled(true); + if(verify[gCurrentPageName] != 0){ + ui->status->setText("Verified"); + ui->corrected->setChecked(true); + ui->corrected->setEnabled(false); + if(curr_browser) curr_browser->setReadOnly(true); + } + else { + if(recorrect[gCurrentPageName] != 0){ + ui->status->setText("Corrected"); + ui->corrected->setChecked(true); + } + else if(markForReview[gCurrentPageName] != 0){ + ui->status->setText("Marked For Review"); + ui->corrected->setChecked(false); + } + else if(correct[gCurrentPageName] != 0){ + ui->status->setText("Corrected"); + ui->corrected->setChecked(true); + } + else{ + ui->status->setText("Status - None"); + ui->corrected->setChecked(false); + } + if(curr_browser) curr_browser->setReadOnly(false); + } + } + if(mRole == "Verifier"){ + if(correct[gCurrentPageName] != 0){ + ui->verified->setEnabled(true); + ui->mark_review->setEnabled(true); + + if(verify[gCurrentPageName] != 0){ + ui->status->setText("Verified"); + ui->verified->setChecked(true); + ui->mark_review->setChecked(false); + ui->mark_review->setEnabled(false); + } + else if(recorrect[gCurrentPageName] != 0){ + ui->status->setText("Corrected"); + ui->mark_review->setChecked(true); + ui->verified->setChecked(false); + ui->verified->setEnabled(false); + } + else if(markForReview[gCurrentPageName] != 0){ + ui->status->setText("Marked For Review"); + ui->mark_review->setChecked(true); + ui->verified->setChecked(false); + ui->mark_review->setEnabled(true); + ui->verified->setEnabled(false); + } + else if(correct[gCurrentPageName] != 0){ + ui->status->setText("Corrected"); + ui->mark_review->setChecked(false); + ui->verified->setChecked(false); + } + } + else if(markForReview[gCurrentPageName] != 0){ + ui->status->setText("Marked For Review"); + ui->mark_review->setChecked(true); + ui->mark_review->setEnabled(true); + ui->verified->setEnabled(false); + ui->verified->setChecked(false); + } + else{ + ui->status->setText("Status - None"); + ui->mark_review->setEnabled(false); + ui->verified->setEnabled(false); + ui->mark_review->setChecked(false); + ui->verified->setChecked(false); + } + + } + +} diff --git a/FrameWorkCode/mainwindow.h b/FrameWorkCode/mainwindow.h index b4e9f350..afc47708 100755 --- a/FrameWorkCode/mainwindow.h +++ b/FrameWorkCode/mainwindow.h @@ -41,7 +41,6 @@ #include "loadingspinner.h" #include "progressbardialog.h" #include -#include #include #include #include @@ -51,6 +50,11 @@ #include "customtextbrowser.h" #include "handlebbox.h" #include +#include + +#include + + using namespace std; class AudioLevel; @@ -186,8 +190,6 @@ private slots: void on_actionFetch_2_triggered(); - void on_actionVerifier_Turn_In_triggered(); - void directoryChanged(const QString &path); void on_actionAccuracyLog_triggered(); @@ -228,8 +230,6 @@ private slots: void on_actionRedo_triggered(); - void on_actionInsert_Table_2_triggered(); - void closeEvent (QCloseEvent *event); QJsonObject getAverageAccuracies(QJsonObject mainObj); @@ -378,11 +378,7 @@ private slots: void insertImageAction(); - void on_actionLogin_triggered(); - - void on_actionLogout_triggered(); - - void on_actionClone_Repository_triggered(); + void on_actionClone_Repository(); void on_actionClose_project_triggered(); @@ -424,6 +420,110 @@ private slots: void on_actionFill_Table_triggered(); + void on_backward_Button_clicked(); + + void on_forward_Button_clicked(); + + void on_actionImport_and_Open_triggered(); + + void on_actionImport_triggered(); + + void on_actionEnter_manauly_triggered(); + + + + void on_actionImport_2_triggered(); + + + void on_pushButton_5_clicked(); + + void on_actionTable_2_triggered(); + + void on_actionCut_triggered(); + + void on_actionCopy_triggered(); + + void on_actionPaste_triggered(); + + void on_actionSelect_All_triggered(); + + void on_actionDelete_triggered(); + + void on_actionDate_triggered(); + + void on_actionLink_triggered(); + + void on_actionUnderline_2_triggered(); + + void on_actionIncrease_size_triggered(); + + void on_actionDecrease_Size_triggered(); + + void on_actionlower_case_triggered(); + + void on_actionUPPER_CASE_triggered(); + + void on_actionTitle_Case_triggered(); + + void on_actionDelete_Table_triggered(); + + void on_actionClear_Formatting_triggered(); + + void on_actionImage_triggered(); + + void on_actionAbout_Udaan_PE_triggered(); + + void on_actionIncrease_Indent_triggered(int left = 0, int right = 0); + + void on_actionDecrease_Indent_triggered(); + + void on_actionIndentation_Options_triggered(); + void on_actionSpecial_Characters_triggered(); + void on_actionResize_Image_2_triggered(); + + + void on_actionWord_Count_triggered(); + + void on_actionVoice_Typing_triggered(); + + void getDate(QDate date, QCalendarWidget *calendar); + + + + void on_actionTable_Border_Color_triggered(); + + void on_actionCell_Padding_triggered(); + + void processProgress(qint64 bytesReceived, qint64 bytesTotal, QProgressBar *pb, QLabel *labelProgress); + + void on_pushButton_6_clicked(); + + + void on_corrected_clicked(); + + void on_verified_clicked(); + + void write_corrected_pages(); + + void write_verified_pages(); + + void read_corrected_pages(); + + void read_verified_pages(); + + void on_mark_review_clicked(); + + void read_review_pages(); + + void write_review_pages(); + void read_recorrected_pages(); + void write_recorrected_pages(); + void pageStatusHandler(); + + void on_actionClear_Menu_triggered(); + + void on_actionJustified_triggered(); + public slots: void on_actionLoad_Next_Page_triggered(); @@ -437,9 +537,14 @@ public slots: void blockCountChanged(int); - void authenticate(); void login(); + void createTable(); + + void e_d_features(bool value); + + void update_tool(QString latestVersion); + private: bool mExitStatus = false; QString mRole; @@ -486,13 +591,10 @@ public slots: QVector > bboxes; int blockCount = -1; GlobalReplaceDialog *currentGlobalReplaceDialog = nullptr; - QOAuth2AuthorizationCodeFlow * google; - void googleAuth(); QSet dict_set1; //! Keep it available globally so that we need not to parse dictionary file at the time of saving logs. bool check(); bool check_access(); void cloud_save(); - bool verifier_save(); int saved = 0; void autoSave(); void messageTimer(); @@ -501,6 +603,25 @@ public slots: QAudioProbe *m_probe = nullptr; QList m_audioLevels; void speechToTextCall(); + bool import_flag = false; + int flag_tab = 0; + + QVector changedWords; + QByteArray m_data; + std::string m_user, m_pass; + + + + + //Storing the status of the pages :-> Corrected || Verified + QMapcorrect; + QMapverify; + QMaprecorrect; + QString currentFile = ""; + QMapmarkForReview; + QString m_update_path = ""; + + }; #endif // MAINWINDOW_H diff --git a/FrameWorkCode/mainwindow.ui b/FrameWorkCode/mainwindow.ui index 3bcc56d5..c04b274d 100755 --- a/FrameWorkCode/mainwindow.ui +++ b/FrameWorkCode/mainwindow.ui @@ -6,7 +6,7 @@ 0 0 - 1366 + 1928 1190
@@ -37,6 +37,42 @@ color:white; + + + + color: rgb(0, 0, 0); +image: url(:/Images/Resources/forfinal.png); +background-color: #BCBDBD; height:26.96px; width:30.03px; border:0px; padding:0px 3.6px;border-radius:6px; + + + + + + + + + + color: rgb(0, 0, 0); +image: url(:/Images/Resources/backfinal.png); +background-color: #BCBDBD; height:26.96px; width:30.03px; border:0px; padding:0px 3.6px;border-radius:6px; + + + + + + + + + + QPushButton{background-color:rgb(227, 228, 228);border:0px; color: rgb(32, 33, 72); height:30px; width:30px;padding-top:1px; border-radius:3px; padding-left:1.3px; selection-color: rgb(32, 33, 72); selection-background-color: rgb(136, 138, 133); +margin-top:10px; +} QPushButton:checked{background-color: rgb(136, 138, 133);} QPushButton:pressed {background-color: rgb(136, 138, 133);} + + + + + + @@ -50,6 +86,77 @@ color:white; + + + + QPushButton{border:0px; color: rgb(32, 33, 72); height:26.96px; width: 136.5px; padding-top:1px; border-radius:4.8px; padding-left:1.3px; selection-color: rgb(32, 33, 72); selection-background-color: rgb(136, 138, 133); background-color: #ffff00; +} QPushButton:checked{background-color: #ffff02;} QPushButton:pressed {background-color: #ffff04;} + + + Replace Globally [0] + + + + + + + QPushButton{background-color:rgb(227, 228, 228);border:0px; color: rgb(32, 33, 72); height:26.96px; width: 140px; padding-top:1px; border-radius:4.8px; padding-left:1.3px; selection-color: rgb(32, 33, 72); selection-background-color: rgb(136, 138, 133); +} + + + + Status - None + + + + + + + QCheckBox{background-color:rgb(227, 228, 228);border:0px; color: rgb(32, 33, 72); height:26.96px; padding-top:1px; border-radius:4.8px; padding-left:1.3px; +width: 80px;} +QCheckBox::indicator:checked{ +color: rgb(121,255, 121); +} + + + Corrected + + + + + + + QCheckBox{background-color:rgb(227, 228, 228);border:0px; color: rgb(32, 33, 72); height:26.96px; padding-top:1px; border-radius:4.8px; padding-left:1.3px; +width: 80px;} +QCheckBox::indicator:checked{ +color: rgb(121,255, 121); +} + + + Verified + + + + + + + + 101 + 0 + + + + QCheckBox{background-color:rgb(227, 228, 228);border:0px; color: rgb(32, 33, 72); height:26.96px; padding-top:1px; border-radius:4.8px; padding-left:1.3px; +width: 120px;} +QCheckBox::indicator:checked{ +color: rgb(121,255, 121); +} + + + Mark For Review + + + @@ -162,6 +269,7 @@ color:white; QTabBar::tab { + background-color: rgb(38, 162, 105); border-radius: 0px; padding: 5px 15px; color: #1F2046; @@ -193,7 +301,7 @@ QTabWidget::pane { - 2 + 1 @@ -815,9 +923,10 @@ color: rgb(0, 0, 0); height:37.39px; border:0px; width:184.8px; padding-left:7.8 - color: rgb(0, 0, 0); + QPushButton{color: rgb(0, 0, 0); image: url(:/Images/Resources/Old Icons/rotate.png); -background-color: rgb(255, 255, 255); height:37.39px; width:32.73px; border:0px; padding:0px 3.6px; +background-color: rgb(255, 255, 255); height:37.39px; width:32.73px; border:0px; padding:0px 3.6px;} +QPushButton:checked{background-color: rgb(136, 138, 133);} QPushButton:pressed {background-color: rgb(136, 138, 133);} @@ -986,17 +1095,17 @@ background: grey; 0 0 - 1366 - 50 + 1928 + 46 QMenuBar{ -font-size:17px; +font-size:16px; } QMenuBar::item{ /* spacing between menu bar items */ -padding: 15px 15px 15px 15px; +padding: 14px 14px 14px 14px; background: transparent; } QMenuBar::item:selected{ @@ -1004,7 +1113,7 @@ QMenuBar::item:selected{ } QMenu::item { spacing: 2px; /* spacing between menu bar items */ - padding: 10px 85px 10px 20px; + padding: 10px 20px 10px 20px; background: transparent; } QMenu::item:selected{ @@ -1013,125 +1122,21 @@ QMenu::item:selected{ border-left:none; border-bottom:none; border-left:3px solid #EEF0F2; -} - - - - - - +} - - - font-size: 17px; - - - Reports - - - - - - - font-size: 17px; - - - View - - - - font-size: 17px; - - - Tables - - - - - - - - - - - - - - Layout - - - - - - Format Painter - - - - - - - - - - - - - - - - - - - - - - - - - font-size: 17px; + font-size: 16px; Sync - - - - font-size: 17px; - - - Edit - - - - - - - - - - - - - - - - - - font-size: 17px; - - - Download - - - - font-size: 17px; + font-size: 16px; Help @@ -1150,23 +1155,17 @@ QMenu::item:selected{ + + - - - - font-size: 17px; - - - Language - - - - + + + - font-size: 17px; + font-size: 16px; @@ -1186,65 +1185,191 @@ QMenu::item:selected{ + - + - - + + + - font-size: 17px; + font-size: 16px; Tools + + + + - - - - - - - - - - - -1 - + + + font-size: 16px; + + + Format + + + + Text + + + + Size + + + + + + + Capitalisation + + + + + + + + + + + + + + + + + Table + + + + Table Properties + + + + + + + + + + + + + + + + + + + + + + Bullets and Numbering + + + + + + + Align and Indent + + + + + + + + + + + + + Columns + + + + + + + + + + + + + + + + + + + + + font-size: 16px; + + + Insert + + + + + + + + + + + - font-size: 17px; + font-size: 16px; - Setting + Edit - - + + + + + + + + + + + + + + + + + + + + - - - - - @@ -1483,7 +1608,7 @@ background-color: #EEF0F2; :/Images/Resources/tospl.png:/Images/Resources/tospl.png - To Slp1 + To Slp Ctrl+G @@ -1574,7 +1699,7 @@ background-color: #EEF0F2; :/Images/AllFont.png:/Images/Resources/all font properties 2.png - All Font Properties + Font Properties All Font Properties @@ -1619,7 +1744,7 @@ background-color: #EEF0F2; :/Images/AlignLeft.png:/Images/Resources/allign left.png - Left Align + Left @@ -1629,7 +1754,7 @@ background-color: #EEF0F2; :/Images/AlignCenter.png:/Images/Resources/align right.png - Right Align + Right @@ -1639,7 +1764,7 @@ background-color: #EEF0F2; :/Images/AlignCenter.png:/Images/Resources/align center.png - Centre Align + Centre @@ -1663,8 +1788,12 @@ background-color: #EEF0F2; + + + :/Images/Resources/sync_from_cloud-modified.png:/Images/Resources/sync_from_cloud-modified.png + - Save to Cloud + Cloud Sync @@ -1847,8 +1976,12 @@ background-color: #EEF0F2; + + + :/Images/Resources/tab-modified.png:/Images/Resources/tab-modified.png + - Insert Tab Space + Tab space Insert Tab Space (Ctrl+T) @@ -1901,24 +2034,19 @@ background-color: #EEF0F2; false - - - Insert Table - - - Insert Column at Left + Insert Column Left - Insert Column at Right + Insert Column Right - Insert Row above + Insert Row Above @@ -1928,12 +2056,12 @@ background-color: #EEF0F2; - Remove Column + Delete Column - Remove Row + Delete Row @@ -1971,8 +2099,12 @@ background-color: #EEF0F2; + + + :/Images/Resources/download-modified.png:/Images/Resources/download-modified.png + - as PDF + Download PDF @@ -1983,18 +2115,33 @@ background-color: #EEF0F2; Get Help + + F1 + + + + :/Images/Resources/tutorial-modified.png:/Images/Resources/tutorial-modified.png + Tutorial + + + :/Images/Resources/linux-modified.png:/Images/Resources/linux-modified.png + Linux + + + :/Images/Resources/windows-modified.png:/Images/Resources/windows-modified.png + Windows @@ -2023,8 +2170,12 @@ background-color: #EEF0F2; + + + :/Images/Resources/keyboard_shortcuts-modified.png:/Images/Resources/keyboard_shortcuts-modified.png + - Shortcut Guide + Keyboard Shortcuts @@ -2082,6 +2233,10 @@ background-color: #EEF0F2; + + + :/Images/Resources/update-modified.png:/Images/Resources/update-modified.png + Check for Updates @@ -2123,12 +2278,11 @@ background-color: #EEF0F2; Logout - - - Import Project - - + + + :/Images/Resources/close_project-modified.png:/Images/Resources/close_project-modified.png + Close project @@ -2144,26 +2298,42 @@ background-color: #EEF0F2; + + + :/Images/Resources/bulleted_list-modified.png:/Images/Resources/bulleted_list-modified.png + - Insert Bulleted List + Bulleted List Menu + + + :/Images/Resources/numbered_list-modified.png:/Images/Resources/numbered_list-modified.png + - Insert Numbered List + Numbered List Menu + + + :/Images/Resources/equation-modified.png:/Images/Resources/equation-modified.png + - Insert Equation + Equation Ctrl+E + + + :/Images/Resources/equation-modified.png:/Images/Resources/equation-modified.png + - Edit Equation + Equation Ctrl+Shift+E @@ -2171,8 +2341,8 @@ background-color: #EEF0F2; - - .. + + Resources/exit-modified.pngResources/exit-modified.png Exit @@ -2183,10 +2353,14 @@ background-color: #EEF0F2; - Two Column + Two + + + :/Images/Resources/user-guide-modified.png:/Images/Resources/user-guide-modified.png + User Guide @@ -2229,7 +2403,304 @@ background-color: #EEF0F2; - Shade Table + Cell Background Color + + + + + Import and Open + + + This will import and open project in tool. + + + + + Import + + + This will download the project. + + + + + Enter Manually + + + + + Use Grid + + + + + PDF Preview + + + + + Download PDF + + + + + + :/Images/Resources/resize-modified.png:/Images/Resources/resize-modified.png + + + Resize Image + + + + + Clear Formatting + + + + + Delete Table + + + + + Unmerge Cells + + + + + Table Border Color + + + + + Cell Padding + + + + + + :/Images/Resources/cut-modified.png:/Images/Resources/cut-modified.png + + + Cut + + + + + + :/Images/Resources/copy-modified.png:/Images/Resources/copy-modified.png + + + Copy + + + + + + :/Images/Resources/paste(1)-modified.png:/Images/Resources/paste(1)-modified.png + + + Paste + + + + + + :/Images/Resources/select_all-modified.png:/Images/Resources/select_all-modified.png + + + Select All + + + + + + :/Images/Resources/delete-modified.png:/Images/Resources/delete-modified.png + + + Delete + + + + + + :/Images/Resources/image-modified.png:/Images/Resources/image-modified.png + + + Image + + + + + + :/Images/Resources/table-modified.png:/Images/Resources/table-modified.png + + + Table + + + + + + :/Images/Resources/date-modified.png:/Images/Resources/date-modified.png + + + Date + + + + + + :/Images/Resources/spl symbol.png:/Images/Resources/spl symbol.png + + + Special Characters + + + + + + :/Images/Resources/link-modified.png:/Images/Resources/link-modified.png + + + Link + + + + + Tabspace + + + + + + :/Images/Resources/voice_typing-modified.png:/Images/Resources/voice_typing-modified.png + + + Voice Typing + + + + + Word Count + + + + + Keyboard Shortcuts + + + + + Contact Us + + + + + Share Feedback + + + + + + :/Images/Resources/about-modified.png:/Images/Resources/about-modified.png + + + About Udaan-PE + + + + + + :/Images/Resources/underline 1.png:/Images/Resources/underline 1.png + + + Underline + + + Ctrl+U + + + + + + :/Images/Resources/increase_size-modified.png:/Images/Resources/increase_size-modified.png + + + Increase size + + + + + + :/Images/Resources/decrease_size-modified.png:/Images/Resources/decrease_size-modified.png + + + Decrease Size + + + + + + :/Images/Resources/align para.png:/Images/Resources/align para.png + + + Justified + + + + + + :/Images/Resources/indent-modified.png:/Images/Resources/indent-modified.png + + + Increase Indent + + + + + + :/Images/Resources/outdent-modified.png:/Images/Resources/outdent-modified.png + + + Decrease Indent + + + + + Indentation Options + + + + + false + + + + :/Images/Resources/import-modified.png:/Images/Resources/import-modified.png + + + Import Project + + + + + lower case + + + + + UPPER CASE + + + + + Title Case + + + + + Clear Menu diff --git a/FrameWorkCode/qpadfinal.pri b/FrameWorkCode/qpadfinal.pri index 0a4445f8..9eac6bdb 100755 --- a/FrameWorkCode/qpadfinal.pri +++ b/FrameWorkCode/qpadfinal.pri @@ -3,6 +3,7 @@ # ------------------------------------------------------ HEADERS += ./Filters.h \ + $$PWD/about.h \ $$PWD/crashlog.h \ $$PWD/customtextbrowser.h \ $$PWD/dashboard.h \ @@ -10,6 +11,7 @@ HEADERS += ./Filters.h \ $$PWD/equationeditor.h \ $$PWD/globalreplaceworker.h \ $$PWD/handlebbox.h \ + $$PWD/indentoptions.h \ $$PWD/loaddataworker.h \ $$PWD/loadingspinner.h \ $$PWD/markRegion.h \ @@ -53,6 +55,7 @@ HEADERS += ./Filters.h \ $$PWD/globalreplacepreview.h \ $$PWD/globalreplaceinformation.h SOURCES += ./DiffView.cpp \ + $$PWD/about.cpp \ $$PWD/crashlog.cpp \ $$PWD/customtextbrowser.cpp \ $$PWD/dashboard.cpp \ @@ -61,6 +64,7 @@ SOURCES += ./DiffView.cpp \ $$PWD/equationeditor.cpp \ $$PWD/globalreplaceworker.cpp \ $$PWD/handlebbox.cpp \ + $$PWD/indentoptions.cpp \ $$PWD/loaddataworker.cpp \ $$PWD/loadingspinner.cpp \ $$PWD/markRegion.cpp \ @@ -100,8 +104,10 @@ SOURCES += ./DiffView.cpp \ $$PWD/globalreplacepreview.cpp \ $$PWD/globalreplaceinformation.cpp FORMS += ./DiffView.ui \ + $$PWD/about.ui \ $$PWD/dashboard.ui \ $$PWD/equationeditor.ui \ + $$PWD/indentoptions.ui \ $$PWD/loadingspinner.ui \ $$PWD/pdfrangedialog.ui \ $$PWD/progressbardialog.ui \ diff --git a/FrameWorkCode/qpadfinal.pro b/FrameWorkCode/qpadfinal.pro index ee2c1c3e..459614f0 100755 --- a/FrameWorkCode/qpadfinal.pro +++ b/FrameWorkCode/qpadfinal.pro @@ -29,12 +29,6 @@ RESOURCES += \ CONFIG += c++11 -FORMS += - -HEADERS += - -SOURCES += - QMAKE_CXXFLAGS += -w # Windows icon @@ -64,3 +58,9 @@ win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../lib/release else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../lib/debug/libYAWYSIWYGEE.a else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../lib/release/YAWYSIWYGEE.lib else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../lib/debug/YAWYSIWYGEE.lib + + +win32: LIBS += -L$$PWD/../lib/ -lquazip + +INCLUDEPATH += $$PWD/../include +DEPENDPATH += $$PWD/../include diff --git a/FrameWorkCode/shortcutguidedialog.cpp b/FrameWorkCode/shortcutguidedialog.cpp index a12fcfe2..bf481a50 100644 --- a/FrameWorkCode/shortcutguidedialog.cpp +++ b/FrameWorkCode/shortcutguidedialog.cpp @@ -5,6 +5,7 @@ */ #include "shortcutguidedialog.h" #include "ui_shortcutguidedialog.h" +#include"addkeyshortcut.h" /*! @@ -19,7 +20,7 @@ ShortcutGuideDialog::ShortcutGuideDialog(QWidget *parent) : ui(new Ui::ShortcutGuideDialog) { ui->setupUi(this); - ui->textBrowser->setTextInteractionFlags(Qt::NoTextInteraction); + ui->textBrowser->setMarkdown(this->list); } /*! diff --git a/FrameWorkCode/shortcutguidedialog.h b/FrameWorkCode/shortcutguidedialog.h index 21662c66..296fc3ad 100644 --- a/FrameWorkCode/shortcutguidedialog.h +++ b/FrameWorkCode/shortcutguidedialog.h @@ -17,6 +17,44 @@ class ShortcutGuideDialog : public QDialog private: Ui::ShortcutGuideDialog *ui; + QString list = "# Udaan PE Tool - Shortcut Guide\n" + "----\n" + "#### 1. Open a project\n" + "- Press **Ctrl + O** and select the project.xml file from the project folder to open the project.\n" + "#### 2. Save a File\n" + "- Press **Ctrl + S** to save the file.\n" + "#### 3. Open a new tab\n" + "- Press **Ctrl + N** to open a new tab in the window.\n" + "#### 4. Save As\n" + "- Press **Ctrl + Shift + S** to save the file as a different copy with a different name and/or different location.\n" + "#### 5. Navigate between pages\n" + "- Press **Ctrl + Shift + R** to navigate through the next page, **Ctrl + Shift + L** to navigate to the previous page.\n" + "#### 6. Undo & Redo\n" + "- Press **Ctrl + Z** to undo the changes and **Ctrl + Shift + Z** to redo the changes.\n" + "#### 7. Find & Replace\n" + "- Press **Ctrl + F** to find and/or replace text.\n" + "#### 8. Highlight\n" + "- Press **Ctrl + H** to highlight the selected text.\n" + "#### 9. Spell Check\n" + "- Press **Ctrl + C** to perform Spell Check.\n" + "#### 10. Convert text to Devanagari\n" + "- Press **Ctrl + D** to convert selected text to devanagari format.\n" + "#### 11. Text Formatting\n" + "- Bold: Press **Ctrl + B** to make selected text **Bold**\n" + "- Italic: Press **Ctrl + I** to make text *Italic*\n" + "- Subscript: Press **Ctrl + \`** to make text subscripted\n" + "- Superscript: Press **Ctrl + Shift + \`** to make text superscript\n" + "- Tab Space: Press **Ctrl + T** to add tab space\n" + "#### 12. Devanagari to SLP\n" + "- Press **Ctrl + G** to Convert devanagari to roman letters as mapped in SLP Guide\n" + "#### 13. Font Properties\n" + "- Press **Ctrl + Shift + A** to see current Font properties\n" + "#### 14. Equation\n" + "- Press **Ctrl + E** to open equation editor to write an equation\n" + "#### 15. Edit Equation\n" + "- Press **Ctrl + Shift + E** to edit teh selected Equation\n" + "#### 16. Exit\n" + "- Press **Ctrl + Q** to exit the Udaan PE Tool\n"; }; #endif // SHORTCUTGUIDEDIALOG_H diff --git a/FrameWorkCode/shortcutguidedialog.ui b/FrameWorkCode/shortcutguidedialog.ui index 016c50f5..973b73b0 100644 --- a/FrameWorkCode/shortcutguidedialog.ui +++ b/FrameWorkCode/shortcutguidedialog.ui @@ -7,7 +7,7 @@ 0 0 760 - 444 + 461 @@ -16,16 +16,22 @@ font: 11pt "Work Sans"; - - + + font: 11pt "Work Sans"; + + true + <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> -<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +<html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css"> p, li { white-space: pre-wrap; } +hr { height: 1px; border-width: 0; } +li.unchecked::marker { content: "\2610"; } +li.checked::marker { content: "\2612"; } </style></head><body style=" font-family:'Work Sans'; font-size:11pt; font-weight:400; font-style:normal;"> <p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a name="docs-internal-guid-207f323b-7fff-f7c8-e38e-64c168e8249e"></a><span style=" font-family:'Arial'; font-size:24pt; color:#000000; background-color:transparent;">O</span><span style=" font-family:'Arial'; font-size:24pt; color:#000000; background-color:transparent;">penOCRCorrect - Shortcut Guide</span></p> <p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Arial'; font-size:24pt; color:#000000;"><br /></p> diff --git a/FrameWorkCode/threadingpush.cpp b/FrameWorkCode/threadingpush.cpp index 4452afd1..91cc4f65 100644 --- a/FrameWorkCode/threadingpush.cpp +++ b/FrameWorkCode/threadingpush.cpp @@ -11,6 +11,7 @@ #include #include #include + std::string user_,pass_; QString gDir; @@ -56,14 +57,14 @@ int credentials_cb_func(git_cred ** out, const char *url, const char *username_f /*! * \fn threadingPush::ControlPush - * \brief + * \brief * This function helps in pushing the changes to the cloud in a thread. - * The branch Name is Store as an QByte Array + * The branch Name is stored as a QByte Array * This function first looks for the repo where changes are to be pushed. - * Then fetch options are initialized - * Then are commit is successful, The changes are pushed. + * Then fetch options are initialized + * Then the changes are pushed. * This function is being called in mainwindow.cpp file where with the help of threads this function is called so that in - * large sets the changes are successfully pushed. + * large sets the changes are successfully pushed. */ void threadingPush::ControlPush() { @@ -106,8 +107,8 @@ void threadingPush::ControlPush() // Store remote info from repo error = git_remote_lookup(&remote, repo, "origin"); - if(error){ - std::cout<<0< reversedGRMap, QWidget *parent) : +UndoGlobalReplace::UndoGlobalReplace(QMap reversedGRMap, QWidget *parent,QString mRole,QString path) : QDialog(parent), ui(new Ui::UndoGlobalReplace) { ui->setupUi(this); + this->mRole = mRole; + this->path = path; qInstallMessageHandler(crashlog::myMessageHandler); setWindowTitle("Undo Globally Replace Words"); displayListForUndoOperation(reversedGRMap); @@ -117,3 +119,31 @@ QMap UndoGlobalReplace::getFinalUndoMap() { return this->finalUndoMap; } + +void UndoGlobalReplace::on_pushButton_clicked() +{ + QMap new_cpair; + + QString filename = path + "/Dicts/" + mRole +"_CPair"; + QFile file(filename); + QStringList split1; + + if(file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QTextStream out1(&file); + out1.setCodec("UTF-8"); + QString text; + while(!out1.atEnd()) + { + text = out1.readLine(); + split1 = text.split('\t'); + // CPairs = {split1[0],split1[1]}; + new_cpair[split1[1]]= split1[0]; + } + file.close(); + } + + displayListForUndoOperation(new_cpair); + +} + diff --git a/FrameWorkCode/undoglobalreplace.h b/FrameWorkCode/undoglobalreplace.h index 3e500b2a..da514ca2 100644 --- a/FrameWorkCode/undoglobalreplace.h +++ b/FrameWorkCode/undoglobalreplace.h @@ -13,7 +13,7 @@ class UndoGlobalReplace : public QDialog Q_OBJECT public: - explicit UndoGlobalReplace(QMap reversedGRMap, QWidget *parent = nullptr); + explicit UndoGlobalReplace(QMap reversedGRMap, QWidget *parent = nullptr,QString mRole="", QString path=""); ~UndoGlobalReplace(); private slots: @@ -21,6 +21,8 @@ private slots: void on_cancelButton_clicked(); + void on_pushButton_clicked(); + public slots: void highlightChecked(QListWidgetItem*); @@ -31,6 +33,8 @@ public slots: private: Ui::UndoGlobalReplace *ui; QMap finalUndoMap; + QString mRole; + QString path; }; #endif // UNDOGLOBALREPLACE_H diff --git a/FrameWorkCode/undoglobalreplace.ui b/FrameWorkCode/undoglobalreplace.ui index f18d07ae..6bc79422 100644 --- a/FrameWorkCode/undoglobalreplace.ui +++ b/FrameWorkCode/undoglobalreplace.ui @@ -46,6 +46,17 @@ + + + + QPushButton{background-color:rgb(227, 228, 228);border:0px; color: rgb(32, 33, 72); height:26.96px; width: 113.5px; padding-top:1px; border-radius:4.8px; padding-left:1.3px; selection-color: rgb(32, 33, 72); selection-background-color: rgb(136, 138, 133); +} QPushButton:checked{background-color: rgb(136, 138, 133);} QPushButton:pressed {background-color: rgb(136, 138, 133);} + + + Load History ? + + + diff --git a/FrameWorkCode/v3.5.9.tar.xz b/FrameWorkCode/v3.5.9.tar.xz new file mode 100644 index 00000000..e69de29b diff --git a/FrameWorkCode/validate b/FrameWorkCode/validate new file mode 100644 index 00000000..ce89702c --- /dev/null +++ b/FrameWorkCode/validate @@ -0,0 +1 @@ +{"status": true, "repo_list": [], "client_id": "489554623731-h13ul7h58bvidicaqv4a8f4d4c3p1huv.apps.googleusercontent.com", "client_secret": "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", "github_username": "pranitaharpale", "github_token": "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"} \ No newline at end of file diff --git a/include/JlCompress.h b/include/JlCompress.h new file mode 100644 index 00000000..49c50865 --- /dev/null +++ b/include/JlCompress.h @@ -0,0 +1,197 @@ +#ifndef JLCOMPRESSFOLDER_H_ +#define JLCOMPRESSFOLDER_H_ + +/* +Copyright (C) 2010 Roberto Pompermaier +Copyright (C) 2005-2016 Sergey A. Tachenov + +This file is part of QuaZIP. + +QuaZIP is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +QuaZIP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with QuaZIP. If not, see . + +See COPYING file for the full LGPL text. + +Original ZIP package is copyrighted by Gilles Vollant and contributors, +see quazip/(un)zip.h files for details. Basically it's the zlib license. +*/ + +#include "quazip.h" +#include "quazipfile.h" +#include "quazipfileinfo.h" +#include +#include +#include +#include + +/// Utility class for typical operations. +/** + This class contains a number of useful static functions to perform + simple operations, such as mass ZIP packing or extraction. + */ +class QUAZIP_EXPORT JlCompress { +private: + static QStringList extractDir(QuaZip &zip, const QString &dir); + static QStringList getFileList(QuaZip *zip); + static QString extractFile(QuaZip &zip, QString fileName, QString fileDest); + static QStringList extractFiles(QuaZip &zip, const QStringList &files, const QString &dir); + /// Compress a single file. + /** + \param zip Opened zip to compress the file to. + \param fileName The full path to the source file. + \param fileDest The full name of the file inside the archive. + \return true if success, false otherwise. + */ + static bool compressFile(QuaZip* zip, QString fileName, QString fileDest); + /// Compress a subdirectory. + /** + \param parentZip Opened zip containing the parent directory. + \param dir The full path to the directory to pack. + \param parentDir The full path to the directory corresponding to + the root of the ZIP. + \param recursive Whether to pack sub-directories as well or only + files. + \return true if success, false otherwise. + */ + static bool compressSubDir(QuaZip* parentZip, QString dir, QString parentDir, bool recursive, + QDir::Filters filters); + /// Extract a single file. + /** + \param zip The opened zip archive to extract from. + \param fileName The full name of the file to extract. + \param fileDest The full path to the destination file. + \return true if success, false otherwise. + */ + static bool extractFile(QuaZip* zip, QString fileName, QString fileDest); + /// Remove some files. + /** + \param listFile The list of files to remove. + \return true if success, false otherwise. + */ + static bool removeFile(QStringList listFile); + +public: + /// Compress a single file. + /** + \param fileCompressed The name of the archive. + \param file The file to compress. + \return true if success, false otherwise. + */ + static bool compressFile(QString fileCompressed, QString file); + /// Compress a list of files. + /** + \param fileCompressed The name of the archive. + \param files The file list to compress. + \return true if success, false otherwise. + */ + static bool compressFiles(QString fileCompressed, QStringList files); + /// Compress a whole directory. + /** + Does not compress hidden files. See compressDir(QString, QString, bool, QDir::Filters). + + \param fileCompressed The name of the archive. + \param dir The directory to compress. + \param recursive Whether to pack the subdirectories as well, or + just regular files. + \return true if success, false otherwise. + */ + static bool compressDir(QString fileCompressed, QString dir = QString(), bool recursive = true); + /** + * @brief Compress a whole directory. + * + * Unless filters are specified explicitly, packs + * only regular non-hidden files (and subdirs, if @c recursive is true). + * If filters are specified, they are OR-combined with + * %QDir::AllDirs|%QDir::NoDotAndDotDot when searching for dirs + * and with QDir::Files when searching for files. + * + * @param fileCompressed path to the resulting archive + * @param dir path to the directory being compressed + * @param recursive if true, then the subdirectories are packed as well + * @param filters what to pack, filters are applied both when searching + * for subdirs (if packing recursively) and when looking for files to pack + * @return true on success, false otherwise + */ + static bool compressDir(QString fileCompressed, QString dir, + bool recursive, QDir::Filters filters); + +public: + /// Extract a single file. + /** + \param fileCompressed The name of the archive. + \param fileName The file to extract. + \param fileDest The destination file, assumed to be identical to + \a file if left empty. + \return The list of the full paths of the files extracted, empty on failure. + */ + static QString extractFile(QString fileCompressed, QString fileName, QString fileDest = QString()); + /// Extract a list of files. + /** + \param fileCompressed The name of the archive. + \param files The file list to extract. + \param dir The directory to put the files to, the current + directory if left empty. + \return The list of the full paths of the files extracted, empty on failure. + */ + static QStringList extractFiles(QString fileCompressed, QStringList files, QString dir = QString()); + /// Extract a whole archive. + /** + \param fileCompressed The name of the archive. + \param dir The directory to extract to, the current directory if + left empty. + \return The list of the full paths of the files extracted, empty on failure. + */ + static QStringList extractDir(QString fileCompressed, QString dir = QString()); + /// Get the file list. + /** + \return The list of the files in the archive, or, more precisely, the + list of the entries, including both files and directories if they + are present separately. + */ + static QStringList getFileList(QString fileCompressed); + /// Extract a single file. + /** + \param ioDevice pointer to device with compressed data. + \param fileName The file to extract. + \param fileDest The destination file, assumed to be identical to + \a file if left empty. + \return The list of the full paths of the files extracted, empty on failure. + */ + static QString extractFile(QIODevice *ioDevice, QString fileName, QString fileDest = QString()); + /// Extract a list of files. + /** + \param ioDevice pointer to device with compressed data. + \param files The file list to extract. + \param dir The directory to put the files to, the current + directory if left empty. + \return The list of the full paths of the files extracted, empty on failure. + */ + static QStringList extractFiles(QIODevice *ioDevice, QStringList files, QString dir = QString()); + /// Extract a whole archive. + /** + \param ioDevice pointer to device with compressed data. + \param dir The directory to extract to, the current directory if + left empty. + \return The list of the full paths of the files extracted, empty on failure. + */ + static QStringList extractDir(QIODevice *ioDevice, QString dir = QString()); + /// Get the file list. + /** + \return The list of the files in the archive, or, more precisely, the + list of the entries, including both files and directories if they + are present separately. + */ + static QStringList getFileList(QIODevice *ioDevice); +}; + +#endif /* JLCOMPRESSFOLDER_H_ */ diff --git a/include/QMathBran.h b/include/QMathBran.h index 44a07d80..744debd8 100644 --- a/include/QMathBran.h +++ b/include/QMathBran.h @@ -1,187 +1,187 @@ -#ifndef QMATHBRAN -#define QMATHBRAN - -#include "QMathBran_Macros.h" -#include - -namespace MathBran{ - -inline QString& applyEscapes(QString& str){ - return str.replace(MB_CONSTRUCT_SYMBOL, MB_ESCAPED_CONSTRUCT_SYMBOL) - .replace(MB_OPEN, MB_ESCAPED_OPEN) - .replace(MB_CLOSE, MB_CLOSE); -} - -inline QString& removeEscapes(QString& str){ - return str.replace(MB_ESCAPED_CONSTRUCT_SYMBOL, MB_CONSTRUCT_SYMBOL) - .replace(MB_ESCAPED_OPEN, MB_OPEN) - .replace(MB_CLOSE, MB_CLOSE); -} - -inline bool containsConstruct(const QString& source){ - for(QString::size_type curr = 0; curr < source.size()-1; curr++){ - if(source[curr] == MB_CONSTRUCT_SYMBOL){ - switch (source[++curr].unicode()) { - case MB_USHORT_CONSTRUCT_SYMBOL: - case MB_USHORT_OPEN: - case MB_USHORT_CLOSE: - break; - default: - return true; - } - } - } - - return false; -} - -static bool testInvalidConstruct(const QString& source, QString::size_type& curr); - -static bool testInvalidSubphrase(const QString& source, QString::size_type& curr){ - if(++curr == source.size()) return true; - if(source[curr] != MB_OPEN) return true; - - while(++curr != source.size()){ - switch (source[curr].unicode()) { - case MB_USHORT_CONSTRUCT_SYMBOL: - if(testInvalidConstruct(source, curr)) return true; - break; - case MB_USHORT_OPEN: - case '\n': //No newlines in nested phrases - return true; - case MB_USHORT_CLOSE: - return false; - } - } - - return true; -} - -static bool testInvalidOptionalSubphrase(const QString& source, QString::size_type& curr){ - return curr+1 < source.size() && - source[curr+1] == MB_OPEN && - testInvalidSubphrase(source, curr); -} - -static bool testInvalidCases(const QString& source, QString::size_type& curr){ - do - if(testInvalidSubphrase(source, curr) || testInvalidSubphrase(source, curr)) return true; - while(curr+1 < source.size() && source[curr+1] == MB_OPEN); - - return false; -} - -static bool testInvalidMatrix(const QString& source, QString::size_type& curr){ - if(++curr == source.size()) return true; - if(source[curr] != MB_OPEN) return true; - QString::size_type dim_start = ++curr; - while(++curr < source.size() && source[curr] != MB_CLOSE); - if(curr == source.size()) return true; - bool success; - ushort rows = source.midRef(dim_start, curr - dim_start).toUShort(&success); - if(!success || rows==0 || rows > 255) return true; - - if(++curr == source.size()) return true; - if(source[curr] != MB_OPEN) return true; - dim_start = ++curr; - while(++curr < source.size() && source[curr] != MB_CLOSE); - if(curr == source.size()) return true; - ushort cols = source.midRef(dim_start, curr - dim_start).toUShort(&success); - if(!success || cols==0 || cols > 255) return true; - - if(curr+1 == source.size() || source[curr+1] != MB_OPEN) return false; //Elements are optional - - for(ushort i = rows*cols; i > 0; i--) - if(testInvalidSubphrase(source, curr)) return true; - - return false; -} - -static bool testInvalidConstruct(const QString& source, QString::size_type& curr){ - if(++curr == source.size()) return true; - - switch(source[curr].unicode()){ - //Escaped characters - case MB_USHORT_CONSTRUCT_SYMBOL: - case MB_USHORT_OPEN: - case MB_USHORT_CLOSE: - return false; - - //Unary constructs - case MB_USHORT_ACCENT_ARROW: - case MB_USHORT_ACCENT_BAR: - case MB_USHORT_ACCENT_BREVE: - case MB_USHORT_ACCENT_DOT: - case MB_USHORT_ACCENT_DOUBLE_DOTS: - case MB_USHORT_ACCENT_TRIPLE_DOTS: - case MB_USHORT_ACCENT_HAT: - case MB_USHORT_ACCENT_TILDE: - case MB_USHORT_GROUPING_BARS: - case MB_USHORT_GROUPING_DOUBLE_BARS: - case MB_USHORT_GROUPING_BRACKETS: - case MB_USHORT_GROUPING_CEIL: - case MB_USHORT_GROUPING_FLOOR: - case MB_USHORT_GROUPING_PARENTHESIS: - case MB_USHORT_SUBSCRIPT: - case MB_USHORT_SUPERSCRIPT: - case MB_USHORT_UNDERSCRIPTED_INF: - case MB_USHORT_UNDERSCRIPTED_MAX: - case MB_USHORT_UNDERSCRIPTED_MIN: - case MB_USHORT_UNDERSCRIPTED_SUP: - return testInvalidSubphrase(source, curr); - - //Binary constructs - case MB_USHORT_BINOMIAL_COEFFICIENTS: - case MB_USHORT_DUALSCRIPT: - case MB_USHORT_EVALSCRIPT: - case MB_USHORT_FRACTION: - case MB_USHORT_LIMIT: - return testInvalidSubphrase(source, curr) || testInvalidSubphrase(source, curr); - - //Optional unary constructs - case MB_USHORT_DOUBLE_INTEGRAL: - case MB_USHORT_TRIPLE_INTEGRAL: - case MB_USHORT_CLOSED_SURFACE_INTEGRAL: - case MB_USHORT_CLOSED_VOLUME_INTEGRAL: - return testInvalidOptionalSubphrase(source, curr); - - //Distinctly optional binary constructs - case MB_USHORT_SUMMATION: - case MB_USHORT_PRODUCT: - case MB_USHORT_COPRODUCT: - case MB_USHORT_INTERSECTION: - case MB_USHORT_UNION: - case MB_USHORT_UNION_PLUS: - case MB_USHORT_INTEGRAL: - case MB_USHORT_CONTOUR_INTEGRAL: - return testInvalidOptionalSubphrase(source, curr) || testInvalidOptionalSubphrase(source, curr); - - //Unique constructs - case MB_USHORT_ROOT: return testInvalidSubphrase(source, curr) || - testInvalidOptionalSubphrase(source, curr); - case MB_USHORT_CASES: return testInvalidCases(source, curr); - case MB_USHORT_MATRIX: return testInvalidMatrix(source, curr); - - //Unrecognized construct code - default: return true; - } -} - -inline bool isWellFormed(const QString& source){ - for(QString::size_type curr = 0; curr < source.size(); curr++){ - switch (source[curr].unicode()) { - case MB_USHORT_CONSTRUCT_SYMBOL: - if(testInvalidConstruct(source, curr)) return false; - break; - case MB_USHORT_OPEN: - case MB_USHORT_CLOSE: - return false; - } - } - - return true; -} - -}; - -#endif +#ifndef QMATHBRAN +#define QMATHBRAN + +#include "QMathBran_Macros.h" +#include + +namespace MathBran{ + +inline QString& applyEscapes(QString& str){ + return str.replace(MB_CONSTRUCT_SYMBOL, MB_ESCAPED_CONSTRUCT_SYMBOL) + .replace(MB_OPEN, MB_ESCAPED_OPEN) + .replace(MB_CLOSE, MB_CLOSE); +} + +inline QString& removeEscapes(QString& str){ + return str.replace(MB_ESCAPED_CONSTRUCT_SYMBOL, MB_CONSTRUCT_SYMBOL) + .replace(MB_ESCAPED_OPEN, MB_OPEN) + .replace(MB_CLOSE, MB_CLOSE); +} + +inline bool containsConstruct(const QString& source){ + for(QString::size_type curr = 0; curr < source.size()-1; curr++){ + if(source[curr] == MB_CONSTRUCT_SYMBOL){ + switch (source[++curr].unicode()) { + case MB_USHORT_CONSTRUCT_SYMBOL: + case MB_USHORT_OPEN: + case MB_USHORT_CLOSE: + break; + default: + return true; + } + } + } + + return false; +} + +static bool testInvalidConstruct(const QString& source, QString::size_type& curr); + +static bool testInvalidSubphrase(const QString& source, QString::size_type& curr){ + if(++curr == source.size()) return true; + if(source[curr] != MB_OPEN) return true; + + while(++curr != source.size()){ + switch (source[curr].unicode()) { + case MB_USHORT_CONSTRUCT_SYMBOL: + if(testInvalidConstruct(source, curr)) return true; + break; + case MB_USHORT_OPEN: + case '\n': //No newlines in nested phrases + return true; + case MB_USHORT_CLOSE: + return false; + } + } + + return true; +} + +static bool testInvalidOptionalSubphrase(const QString& source, QString::size_type& curr){ + return curr+1 < source.size() && + source[curr+1] == MB_OPEN && + testInvalidSubphrase(source, curr); +} + +static bool testInvalidCases(const QString& source, QString::size_type& curr){ + do + if(testInvalidSubphrase(source, curr) || testInvalidSubphrase(source, curr)) return true; + while(curr+1 < source.size() && source[curr+1] == MB_OPEN); + + return false; +} + +static bool testInvalidMatrix(const QString& source, QString::size_type& curr){ + if(++curr == source.size()) return true; + if(source[curr] != MB_OPEN) return true; + QString::size_type dim_start = ++curr; + while(++curr < source.size() && source[curr] != MB_CLOSE); + if(curr == source.size()) return true; + bool success; + ushort rows = source.midRef(dim_start, curr - dim_start).toUShort(&success); + if(!success || rows==0 || rows > 255) return true; + + if(++curr == source.size()) return true; + if(source[curr] != MB_OPEN) return true; + dim_start = ++curr; + while(++curr < source.size() && source[curr] != MB_CLOSE); + if(curr == source.size()) return true; + ushort cols = source.midRef(dim_start, curr - dim_start).toUShort(&success); + if(!success || cols==0 || cols > 255) return true; + + if(curr+1 == source.size() || source[curr+1] != MB_OPEN) return false; //Elements are optional + + for(ushort i = rows*cols; i > 0; i--) + if(testInvalidSubphrase(source, curr)) return true; + + return false; +} + +static bool testInvalidConstruct(const QString& source, QString::size_type& curr){ + if(++curr == source.size()) return true; + + switch(source[curr].unicode()){ + //Escaped characters + case MB_USHORT_CONSTRUCT_SYMBOL: + case MB_USHORT_OPEN: + case MB_USHORT_CLOSE: + return false; + + //Unary constructs + case MB_USHORT_ACCENT_ARROW: + case MB_USHORT_ACCENT_BAR: + case MB_USHORT_ACCENT_BREVE: + case MB_USHORT_ACCENT_DOT: + case MB_USHORT_ACCENT_DOUBLE_DOTS: + case MB_USHORT_ACCENT_TRIPLE_DOTS: + case MB_USHORT_ACCENT_HAT: + case MB_USHORT_ACCENT_TILDE: + case MB_USHORT_GROUPING_BARS: + case MB_USHORT_GROUPING_DOUBLE_BARS: + case MB_USHORT_GROUPING_BRACKETS: + case MB_USHORT_GROUPING_CEIL: + case MB_USHORT_GROUPING_FLOOR: + case MB_USHORT_GROUPING_PARENTHESIS: + case MB_USHORT_SUBSCRIPT: + case MB_USHORT_SUPERSCRIPT: + case MB_USHORT_UNDERSCRIPTED_INF: + case MB_USHORT_UNDERSCRIPTED_MAX: + case MB_USHORT_UNDERSCRIPTED_MIN: + case MB_USHORT_UNDERSCRIPTED_SUP: + return testInvalidSubphrase(source, curr); + + //Binary constructs + case MB_USHORT_BINOMIAL_COEFFICIENTS: + case MB_USHORT_DUALSCRIPT: + case MB_USHORT_EVALSCRIPT: + case MB_USHORT_FRACTION: + case MB_USHORT_LIMIT: + return testInvalidSubphrase(source, curr) || testInvalidSubphrase(source, curr); + + //Optional unary constructs + case MB_USHORT_DOUBLE_INTEGRAL: + case MB_USHORT_TRIPLE_INTEGRAL: + case MB_USHORT_CLOSED_SURFACE_INTEGRAL: + case MB_USHORT_CLOSED_VOLUME_INTEGRAL: + return testInvalidOptionalSubphrase(source, curr); + + //Distinctly optional binary constructs + case MB_USHORT_SUMMATION: + case MB_USHORT_PRODUCT: + case MB_USHORT_COPRODUCT: + case MB_USHORT_INTERSECTION: + case MB_USHORT_UNION: + case MB_USHORT_UNION_PLUS: + case MB_USHORT_INTEGRAL: + case MB_USHORT_CONTOUR_INTEGRAL: + return testInvalidOptionalSubphrase(source, curr) || testInvalidOptionalSubphrase(source, curr); + + //Unique constructs + case MB_USHORT_ROOT: return testInvalidSubphrase(source, curr) || + testInvalidOptionalSubphrase(source, curr); + case MB_USHORT_CASES: return testInvalidCases(source, curr); + case MB_USHORT_MATRIX: return testInvalidMatrix(source, curr); + + //Unrecognized construct code + default: return true; + } +} + +inline bool isWellFormed(const QString& source){ + for(QString::size_type curr = 0; curr < source.size(); curr++){ + switch (source[curr].unicode()) { + case MB_USHORT_CONSTRUCT_SYMBOL: + if(testInvalidConstruct(source, curr)) return false; + break; + case MB_USHORT_OPEN: + case MB_USHORT_CLOSE: + return false; + } + } + + return true; +} + +}; + +#endif diff --git a/include/QMathBranLatex_Macros.h b/include/QMathBranLatex_Macros.h index 6638cc6f..233a7bc3 100644 --- a/include/QMathBranLatex_Macros.h +++ b/include/QMathBranLatex_Macros.h @@ -1,1191 +1,1191 @@ -//CODE-GEN FILE -//This file is generated from subfolder "meta". -//Changes to this file must be made in the meta project. - -#define MATHBRAN_LATEX_KEYWORD_LOOKUP_DEFINITION \ -static void searchKeyword(const QString& source, QString::size_type& curr, QTextStream& out){ \ - QString::size_type start = curr-1; \ - while(curr < source.size() && isLetter(source[curr])) curr++; \ -\ - int range = curr-start; \ - QStringRef str = source.midRef(start, range); \ - if(range >= 2 && range <= 6){ \ - uint8_t hash = 1; \ - for(int i = 0; i < range; i++) hash += source[start+i].unicode()*(i+75); \ -\ - switch(hash){ \ - case 102: if(str=="arccos") out << '\\'; break; \ - case 220: if(str=="arcsin") out << '\\'; break; \ - case 178: if(str=="arctan") out << '\\'; break; \ - case 63: if(str=="arg") out << '\\'; break; \ - case 141: if(str=="cos") out << '\\'; break; \ - case 61: if(str=="cosh") out << '\\'; break; \ - case 218: if(str=="cot") out << '\\'; break; \ - case 138: if(str=="coth") out << '\\'; break; \ - case 237: if(str=="csc") out << '\\'; break; \ - case 68: if(str=="deg") out << '\\'; break; \ - case 45: if(str=="det") out << '\\'; break; \ - case 66: if(str=="dim") out << '\\'; break; \ - case 232: if(str=="exp") out << '\\'; break; \ - case 166: if(str=="gcd") out << '\\'; break; \ - case 54: if(str=="hom") out << '\\'; break; \ - case 26: if(str=="inf") out << '\\'; break; \ - case 160: if(str=="ker") out << '\\'; break; \ - case 57: if(str=="lg") out << '\\'; break; \ - case 154: if(str=="lim") out << '\\'; break; \ - case 106: if(str=="liminf") out << '\\'; break; \ - case 191: if(str=="limsup") out << '\\'; break; \ - case 77: if(str=="ln") out << '\\'; break; \ - case 148: if(str=="log") out << '\\'; break; \ - case 212: if(str=="max") out << '\\'; break; \ - case 50: if(str=="min") out << '\\'; break; \ - case 73: if(str=="Pr") out << '\\'; break; \ - case 117: if(str=="sec") out << '\\'; break; \ - case 244: if(str=="sin") out << '\\'; break; \ - case 164: if(str=="sinh") out << '\\'; break; \ - case 30: if(str=="sup") out << '\\'; break; \ - case 223: if(str=="tan") out << '\\'; break; \ - case 143: if(str=="tanh") out << '\\'; break; \ - } \ - } \ -\ - out << str; \ -} - -#define MATHBRAN_LATEX_SYMBOLS \ - case 123:\ - out << "\\{";\ - break;\ - case 125:\ - out << "\\}";\ - break;\ - case 38:\ - out << "\\&";\ - break;\ - case 35:\ - out << "\\#";\ - break;\ - case 37:\ - out << "\\%";\ - break;\ - case 8214:\ - out << "\\|";\ - break;\ - case 36:\ - out << "\\$";\ - break;\ - case 8944:\ - out << "\\adots";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8501:\ - out << "\\aleph";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 945:\ - out << "\\alpha";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 913:\ - out << "\\Alpha";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8736:\ - out << "\\angle";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8776:\ - out << "\\approx";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8727:\ - out << "\\ast";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 92:\ - out << "\\backslash";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8959:\ - out << "\\bagmember";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8757:\ - out << "\\because";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 946:\ - out << "\\beta";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 914:\ - out << "\\Beta";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8502:\ - out << "\\beth";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9632:\ - out << "\\blacksquare";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8227:\ - out << "\\blacktriangleright";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8869:\ - out << "\\bot";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8904:\ - out << "\\bowtie";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9633:\ - out << "\\box";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8783:\ - out << "\\bumpeq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8745:\ - out << "\\cap";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8901:\ - out << "\\cdot";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8943:\ - out << "\\cdots";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 162:\ - out << "\\cent";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10003:\ - out << "\\checkmark";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 967:\ - out << "\\chi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 935:\ - out << "\\Chi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8728:\ - out << "\\circ";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8759:\ - out << "\\Colon";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8705:\ - out << "\\complement";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8773:\ - out << "\\cong";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8720:\ - out << "\\coprod";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 169:\ - out << "\\copyright";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8746:\ - out << "\\cup";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8845:\ - out << "\\cupdot";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8224:\ - out << "\\dagger";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8504:\ - out << "\\daleth";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8225:\ - out << "\\ddagger";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8945:\ - out << "\\ddots";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 948:\ - out << "\\delta";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 916:\ - out << "\\Delta";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8960:\ - out << "\\diameter";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9856:\ - out << "\\dicei";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9857:\ - out << "\\diceii";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9858:\ - out << "\\diceiii";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9859:\ - out << "\\diceiv";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9860:\ - out << "\\dicev";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9861:\ - out << "\\dicevi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 989:\ - out << "\\digamma";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 988:\ - out << "\\Digamma";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 247:\ - out << "\\div";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8784:\ - out << "\\doteq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 11034:\ - out << "\\dottedsquare";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8595:\ - out << "\\downarrow";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9834:\ - out << "\\eightnote";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8709:\ - out << "\\emptyset";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 1013:\ - out << "\\epsilon";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 917:\ - out << "\\Epsilon";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8761:\ - out << "\\eqcolon";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8797:\ - out << "\\eqdef";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8801:\ - out << "\\equiv";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8803:\ - out << "\\Equiv";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10734:\ - out << "\\errbarsquare";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 951:\ - out << "\\eta";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 919:\ - out << "\\Eta";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8455:\ - out << "\\Euler";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8364:\ - out << "\\euro";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8252:\ - out << "\\Exclam";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8707:\ - out << "\\exists";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9837:\ - out << "\\flat";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8704:\ - out << "\\forall";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8279:\ - out << "\\fourth";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9785:\ - out << "\\frownie";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 947:\ - out << "\\gamma";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 915:\ - out << "\\Gamma";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8805:\ - out << "\\geq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8807:\ - out << "\\geqq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8811:\ - out << "\\gg";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8921:\ - out << "\\ggg";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8503:\ - out << "\\gimel";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 94:\ - out << "\\hat{}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8749:\ - out << "\\iiint";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8748:\ - out << "\\iint";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8465:\ - out << "\\Im";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8520:\ - out << "\\imath";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8712:\ - out << "\\in";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8710:\ - out << "\\increment";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8734:\ - out << "\\infty";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8747:\ - out << "\\int";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 953:\ - out << "\\iota";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 921:\ - out << "\\Iota";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8521:\ - out << "\\jmath";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 954:\ - out << "\\kappa";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 922:\ - out << "\\Kappa";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 955:\ - out << "\\lambda";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 923:\ - out << "\\Lambda";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10216:\ - out << "\\langle";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8968:\ - out << "\\lceil";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8592:\ - out << "\\leftarrow";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8656:\ - out << "\\Leftarrow";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8596:\ - out << "\\leftrightarrow";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8660:\ - out << "\\Leftrightarrow";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8804:\ - out << "\\leq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8806:\ - out << "\\leqq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8810:\ - out << "\\ll";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10218:\ - out << "\\llangle";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10214:\ - out << "\\llbracket";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8920:\ - out << "\\lll";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8905:\ - out << "\\ltimes";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10016:\ - out << "\\maltese";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8614:\ - out << "\\mapsto";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8450:\ - out << "\\mathbb{C}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8518:\ - out << "\\mathbb{d}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8495:\ - out << "\\mathbb{e}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8461:\ - out << "\\mathbb{H}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8469:\ - out << "\\mathbb{N}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8473:\ - out << "\\mathbb{P}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8474:\ - out << "\\mathbb{Q}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8477:\ - out << "\\mathbb{R}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8484:\ - out << "\\mathbb{Z}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8459:\ - out << "\\mathscr{H}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8466:\ - out << "\\mathscr{L}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 163:\ - out << "\\mathsterling";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 165:\ - out << "\\mathyen";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8737:\ - out << "\\measuredangle";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8487:\ - out << "\\mho";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8723:\ - out << "\\mp";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 956:\ - out << "\\mu";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 924:\ - out << "\\Mu";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8711:\ - out << "\\nabla";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8777:\ - out << "\\napprox";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9838:\ - out << "\\natural";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8775:\ - out << "\\ncong";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 172:\ - out << "\\neg";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8800:\ - out << "\\neq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8802:\ - out << "\\nequiv";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8708:\ - out << "\\nexists";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8815:\ - out << "\\ngtr";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8715:\ - out << "\\ni";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8814:\ - out << "\\nless";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8740:\ - out << "\\nmid";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8716:\ - out << "\\nni";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8713:\ - out << "\\notin";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8836:\ - out << "\\nsubset";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8840:\ - out << "\\nsubseteq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8837:\ - out << "\\nsupset";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8841:\ - out << "\\nsupseteq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 957:\ - out << "\\nu";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 925:\ - out << "\\Nu";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10752:\ - out << "\\odot";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8752:\ - out << "\\oiiint";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8751:\ - out << "\\oiint";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8750:\ - out << "\\oint";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 969:\ - out << "\\omega";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 937:\ - out << "\\Omega";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 959:\ - out << "\\omicron";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 927:\ - out << "\\Omicron";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8854:\ - out << "\\ominus";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8853:\ - out << "\\oplus";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8856:\ - out << "\\oslash";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8855:\ - out << "\\otimes";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 182:\ - out << "\\P";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8706:\ - out << "\\partial";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 981:\ - out << "\\phi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 934:\ - out << "\\Phi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 960:\ - out << "\\pi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 928:\ - out << "\\Pi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8462:\ - out << "\\Planckconst";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 177:\ - out << "\\pm";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8826:\ - out << "\\prec";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8242:\ - out << "\\prime";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8719:\ - out << "\\prod";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8733:\ - out << "\\propto";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 968:\ - out << "\\psi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 936:\ - out << "\\Psi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 985:\ - out << "\\qoppa";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 984:\ - out << "\\Qoppa";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9833:\ - out << "\\quarternote";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8799:\ - out << "\\questeq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10217:\ - out << "\\rangle";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8969:\ - out << "\\rceil";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8476:\ - out << "\\Re";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8971:\ - out << "\\rfloor";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 961:\ - out << "\\rho";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 929:\ - out << "\\Rho";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8735:\ - out << "\\rightangle";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8594:\ - out << "\\rightarrow";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8658:\ - out << "\\Rightarrow";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8644:\ - out << "\\rightleftarrows";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10219:\ - out << "\\rrangle";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10215:\ - out << "\\rrbracket";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8906:\ - out << "\\rtimes";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8243:\ - out << "\\second";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9839:\ - out << "\\sharp";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10722:\ - out << "\\shuffle";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 963:\ - out << "\\sigma";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 931:\ - out << "\\Sigma";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 126:\ - out << "\\sim";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8767:\ - out << "\\sinewave";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8738:\ - out << "\\sphericalangle";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8851:\ - out << "\\sqcap";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8852:\ - out << "\\sqcup";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8847:\ - out << "\\sqsubset";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8849:\ - out << "\\sqsubseteq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8848:\ - out << "\\sqsupset";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8850:\ - out << "\\sqsupseteq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8834:\ - out << "\\subset";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8912:\ - out << "\\Subset";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10179:\ - out << "\\subsetcirc";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8838:\ - out << "\\subseteq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8827:\ - out << "\\succ";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8721:\ - out << "\\sum";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8835:\ - out << "\\supset";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10180:\ - out << "\\supsetcirc";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8839:\ - out << "\\supseteq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 964:\ - out << "\\tau";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 932:\ - out << "\\Tau";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 174:\ - out << "\\textregistered";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8482:\ - out << "\\textsuperscript{TM}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8756:\ - out << "\\therefore";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 10727:\ - out << "\\thermod";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 952:\ - out << "\\theta";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 920:\ - out << "\\Theta";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8244:\ - out << "\\third";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 215:\ - out << "\\times";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8868:\ - out << "\\top";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9669:\ - out << "\\triangleleft";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8796:\ - out << "\\triangleq";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9659:\ - out << "\\triangleright";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9835:\ - out << "\\twonotes";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 95:\ - out << "\\underline";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8593:\ - out << "\\uparrow";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8597:\ - out << "\\updownarrow";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8846:\ - out << "\\uplus";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 965:\ - out << "\\upsilon";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 933:\ - out << "\\Upsilon";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 949:\ - out << "\\varepsilon";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 1008:\ - out << "\\varkappa";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 966:\ - out << "\\varphi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 982:\ - out << "\\varpi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 1009:\ - out << "\\varrho";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 962:\ - out << "\\varsigma";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 977:\ - out << "\\vartheta";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 1012:\ - out << "\\varTheta";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8788:\ - out << "\\vcentcolon=";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8866:\ - out << "\\vdash";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8871:\ - out << "\\vDash";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8942:\ - out << "\\vdots";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8744:\ - out << "\\vee";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8891:\ - out << "\\veebar";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 9888:\ - out << "\\warning";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8743:\ - out << "\\wedge";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8472:\ - out << "\\wp";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 8768:\ - out << "\\wr";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 958:\ - out << "\\xi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 926:\ - out << "\\Xi";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 437:\ - out << "\\Zbar";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 950:\ - out << "\\zeta";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 918:\ - out << "\\Zeta";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - -#define MATHBRAN_LATEX_SYMBOLS_32BIT \ - case 57304:\ - out << "\\mathbb{0}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 57305:\ - out << "\\mathbb{1}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 57306:\ - out << "\\mathbb{2}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 57307:\ - out << "\\mathbb{3}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 57308:\ - out << "\\mathbb{4}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 57309:\ - out << "\\mathbb{5}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 57310:\ - out << "\\mathbb{6}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 57311:\ - out << "\\mathbb{7}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 57312:\ - out << "\\mathbb{8}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 57313:\ - out << "\\mathbb{9}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 56633:\ - out << "\\mathbb{B}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 56635:\ - out << "\\mathbb{D}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 56636:\ - out << "\\mathbb{E}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 56637:\ - out << "\\mathbb{F}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 56641:\ - out << "\\mathbb{J}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 56646:\ - out << "\\mathbb{O}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 56650:\ - out << "\\mathbb{S}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 56651:\ - out << "\\mathbb{T}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 56652:\ - out << "\\mathbb{U}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - case 56608:\ - out << "\\mathfrak{c}";\ - if(curr < source.size() && isLetter(source[curr])) out << "{}";\ - break;\ - +//CODE-GEN FILE +//This file is generated from subfolder "meta". +//Changes to this file must be made in the meta project. + +#define MATHBRAN_LATEX_KEYWORD_LOOKUP_DEFINITION \ +static void searchKeyword(const QString& source, QString::size_type& curr, QTextStream& out){ \ + QString::size_type start = curr-1; \ + while(curr < source.size() && isLetter(source[curr])) curr++; \ +\ + int range = curr-start; \ + QStringRef str = source.midRef(start, range); \ + if(range >= 2 && range <= 6){ \ + uint8_t hash = 1; \ + for(int i = 0; i < range; i++) hash += source[start+i].unicode()*(i+75); \ +\ + switch(hash){ \ + case 102: if(str=="arccos") out << '\\'; break; \ + case 220: if(str=="arcsin") out << '\\'; break; \ + case 178: if(str=="arctan") out << '\\'; break; \ + case 63: if(str=="arg") out << '\\'; break; \ + case 141: if(str=="cos") out << '\\'; break; \ + case 61: if(str=="cosh") out << '\\'; break; \ + case 218: if(str=="cot") out << '\\'; break; \ + case 138: if(str=="coth") out << '\\'; break; \ + case 237: if(str=="csc") out << '\\'; break; \ + case 68: if(str=="deg") out << '\\'; break; \ + case 45: if(str=="det") out << '\\'; break; \ + case 66: if(str=="dim") out << '\\'; break; \ + case 232: if(str=="exp") out << '\\'; break; \ + case 166: if(str=="gcd") out << '\\'; break; \ + case 54: if(str=="hom") out << '\\'; break; \ + case 26: if(str=="inf") out << '\\'; break; \ + case 160: if(str=="ker") out << '\\'; break; \ + case 57: if(str=="lg") out << '\\'; break; \ + case 154: if(str=="lim") out << '\\'; break; \ + case 106: if(str=="liminf") out << '\\'; break; \ + case 191: if(str=="limsup") out << '\\'; break; \ + case 77: if(str=="ln") out << '\\'; break; \ + case 148: if(str=="log") out << '\\'; break; \ + case 212: if(str=="max") out << '\\'; break; \ + case 50: if(str=="min") out << '\\'; break; \ + case 73: if(str=="Pr") out << '\\'; break; \ + case 117: if(str=="sec") out << '\\'; break; \ + case 244: if(str=="sin") out << '\\'; break; \ + case 164: if(str=="sinh") out << '\\'; break; \ + case 30: if(str=="sup") out << '\\'; break; \ + case 223: if(str=="tan") out << '\\'; break; \ + case 143: if(str=="tanh") out << '\\'; break; \ + } \ + } \ +\ + out << str; \ +} + +#define MATHBRAN_LATEX_SYMBOLS \ + case 123:\ + out << "\\{";\ + break;\ + case 125:\ + out << "\\}";\ + break;\ + case 38:\ + out << "\\&";\ + break;\ + case 35:\ + out << "\\#";\ + break;\ + case 37:\ + out << "\\%";\ + break;\ + case 8214:\ + out << "\\|";\ + break;\ + case 36:\ + out << "\\$";\ + break;\ + case 8944:\ + out << "\\adots";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8501:\ + out << "\\aleph";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 945:\ + out << "\\alpha";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 913:\ + out << "\\Alpha";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8736:\ + out << "\\angle";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8776:\ + out << "\\approx";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8727:\ + out << "\\ast";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 92:\ + out << "\\backslash";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8959:\ + out << "\\bagmember";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8757:\ + out << "\\because";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 946:\ + out << "\\beta";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 914:\ + out << "\\Beta";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8502:\ + out << "\\beth";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9632:\ + out << "\\blacksquare";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8227:\ + out << "\\blacktriangleright";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8869:\ + out << "\\bot";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8904:\ + out << "\\bowtie";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9633:\ + out << "\\box";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8783:\ + out << "\\bumpeq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8745:\ + out << "\\cap";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8901:\ + out << "\\cdot";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8943:\ + out << "\\cdots";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 162:\ + out << "\\cent";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10003:\ + out << "\\checkmark";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 967:\ + out << "\\chi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 935:\ + out << "\\Chi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8728:\ + out << "\\circ";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8759:\ + out << "\\Colon";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8705:\ + out << "\\complement";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8773:\ + out << "\\cong";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8720:\ + out << "\\coprod";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 169:\ + out << "\\copyright";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8746:\ + out << "\\cup";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8845:\ + out << "\\cupdot";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8224:\ + out << "\\dagger";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8504:\ + out << "\\daleth";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8225:\ + out << "\\ddagger";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8945:\ + out << "\\ddots";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 948:\ + out << "\\delta";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 916:\ + out << "\\Delta";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8960:\ + out << "\\diameter";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9856:\ + out << "\\dicei";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9857:\ + out << "\\diceii";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9858:\ + out << "\\diceiii";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9859:\ + out << "\\diceiv";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9860:\ + out << "\\dicev";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9861:\ + out << "\\dicevi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 989:\ + out << "\\digamma";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 988:\ + out << "\\Digamma";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 247:\ + out << "\\div";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8784:\ + out << "\\doteq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 11034:\ + out << "\\dottedsquare";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8595:\ + out << "\\downarrow";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9834:\ + out << "\\eightnote";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8709:\ + out << "\\emptyset";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 1013:\ + out << "\\epsilon";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 917:\ + out << "\\Epsilon";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8761:\ + out << "\\eqcolon";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8797:\ + out << "\\eqdef";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8801:\ + out << "\\equiv";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8803:\ + out << "\\Equiv";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10734:\ + out << "\\errbarsquare";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 951:\ + out << "\\eta";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 919:\ + out << "\\Eta";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8455:\ + out << "\\Euler";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8364:\ + out << "\\euro";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8252:\ + out << "\\Exclam";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8707:\ + out << "\\exists";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9837:\ + out << "\\flat";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8704:\ + out << "\\forall";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8279:\ + out << "\\fourth";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9785:\ + out << "\\frownie";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 947:\ + out << "\\gamma";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 915:\ + out << "\\Gamma";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8805:\ + out << "\\geq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8807:\ + out << "\\geqq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8811:\ + out << "\\gg";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8921:\ + out << "\\ggg";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8503:\ + out << "\\gimel";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 94:\ + out << "\\hat{}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8749:\ + out << "\\iiint";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8748:\ + out << "\\iint";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8465:\ + out << "\\Im";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8520:\ + out << "\\imath";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8712:\ + out << "\\in";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8710:\ + out << "\\increment";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8734:\ + out << "\\infty";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8747:\ + out << "\\int";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 953:\ + out << "\\iota";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 921:\ + out << "\\Iota";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8521:\ + out << "\\jmath";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 954:\ + out << "\\kappa";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 922:\ + out << "\\Kappa";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 955:\ + out << "\\lambda";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 923:\ + out << "\\Lambda";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10216:\ + out << "\\langle";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8968:\ + out << "\\lceil";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8592:\ + out << "\\leftarrow";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8656:\ + out << "\\Leftarrow";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8596:\ + out << "\\leftrightarrow";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8660:\ + out << "\\Leftrightarrow";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8804:\ + out << "\\leq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8806:\ + out << "\\leqq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8810:\ + out << "\\ll";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10218:\ + out << "\\llangle";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10214:\ + out << "\\llbracket";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8920:\ + out << "\\lll";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8905:\ + out << "\\ltimes";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10016:\ + out << "\\maltese";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8614:\ + out << "\\mapsto";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8450:\ + out << "\\mathbb{C}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8518:\ + out << "\\mathbb{d}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8495:\ + out << "\\mathbb{e}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8461:\ + out << "\\mathbb{H}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8469:\ + out << "\\mathbb{N}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8473:\ + out << "\\mathbb{P}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8474:\ + out << "\\mathbb{Q}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8477:\ + out << "\\mathbb{R}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8484:\ + out << "\\mathbb{Z}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8459:\ + out << "\\mathscr{H}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8466:\ + out << "\\mathscr{L}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 163:\ + out << "\\mathsterling";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 165:\ + out << "\\mathyen";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8737:\ + out << "\\measuredangle";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8487:\ + out << "\\mho";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8723:\ + out << "\\mp";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 956:\ + out << "\\mu";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 924:\ + out << "\\Mu";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8711:\ + out << "\\nabla";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8777:\ + out << "\\napprox";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9838:\ + out << "\\natural";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8775:\ + out << "\\ncong";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 172:\ + out << "\\neg";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8800:\ + out << "\\neq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8802:\ + out << "\\nequiv";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8708:\ + out << "\\nexists";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8815:\ + out << "\\ngtr";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8715:\ + out << "\\ni";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8814:\ + out << "\\nless";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8740:\ + out << "\\nmid";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8716:\ + out << "\\nni";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8713:\ + out << "\\notin";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8836:\ + out << "\\nsubset";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8840:\ + out << "\\nsubseteq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8837:\ + out << "\\nsupset";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8841:\ + out << "\\nsupseteq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 957:\ + out << "\\nu";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 925:\ + out << "\\Nu";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10752:\ + out << "\\odot";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8752:\ + out << "\\oiiint";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8751:\ + out << "\\oiint";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8750:\ + out << "\\oint";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 969:\ + out << "\\omega";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 937:\ + out << "\\Omega";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 959:\ + out << "\\omicron";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 927:\ + out << "\\Omicron";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8854:\ + out << "\\ominus";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8853:\ + out << "\\oplus";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8856:\ + out << "\\oslash";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8855:\ + out << "\\otimes";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 182:\ + out << "\\P";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8706:\ + out << "\\partial";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 981:\ + out << "\\phi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 934:\ + out << "\\Phi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 960:\ + out << "\\pi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 928:\ + out << "\\Pi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8462:\ + out << "\\Planckconst";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 177:\ + out << "\\pm";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8826:\ + out << "\\prec";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8242:\ + out << "\\prime";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8719:\ + out << "\\prod";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8733:\ + out << "\\propto";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 968:\ + out << "\\psi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 936:\ + out << "\\Psi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 985:\ + out << "\\qoppa";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 984:\ + out << "\\Qoppa";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9833:\ + out << "\\quarternote";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8799:\ + out << "\\questeq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10217:\ + out << "\\rangle";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8969:\ + out << "\\rceil";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8476:\ + out << "\\Re";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8971:\ + out << "\\rfloor";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 961:\ + out << "\\rho";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 929:\ + out << "\\Rho";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8735:\ + out << "\\rightangle";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8594:\ + out << "\\rightarrow";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8658:\ + out << "\\Rightarrow";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8644:\ + out << "\\rightleftarrows";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10219:\ + out << "\\rrangle";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10215:\ + out << "\\rrbracket";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8906:\ + out << "\\rtimes";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8243:\ + out << "\\second";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9839:\ + out << "\\sharp";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10722:\ + out << "\\shuffle";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 963:\ + out << "\\sigma";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 931:\ + out << "\\Sigma";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 126:\ + out << "\\sim";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8767:\ + out << "\\sinewave";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8738:\ + out << "\\sphericalangle";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8851:\ + out << "\\sqcap";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8852:\ + out << "\\sqcup";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8847:\ + out << "\\sqsubset";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8849:\ + out << "\\sqsubseteq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8848:\ + out << "\\sqsupset";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8850:\ + out << "\\sqsupseteq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8834:\ + out << "\\subset";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8912:\ + out << "\\Subset";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10179:\ + out << "\\subsetcirc";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8838:\ + out << "\\subseteq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8827:\ + out << "\\succ";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8721:\ + out << "\\sum";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8835:\ + out << "\\supset";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10180:\ + out << "\\supsetcirc";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8839:\ + out << "\\supseteq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 964:\ + out << "\\tau";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 932:\ + out << "\\Tau";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 174:\ + out << "\\textregistered";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8482:\ + out << "\\textsuperscript{TM}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8756:\ + out << "\\therefore";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 10727:\ + out << "\\thermod";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 952:\ + out << "\\theta";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 920:\ + out << "\\Theta";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8244:\ + out << "\\third";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 215:\ + out << "\\times";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8868:\ + out << "\\top";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9669:\ + out << "\\triangleleft";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8796:\ + out << "\\triangleq";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9659:\ + out << "\\triangleright";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9835:\ + out << "\\twonotes";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 95:\ + out << "\\underline";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8593:\ + out << "\\uparrow";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8597:\ + out << "\\updownarrow";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8846:\ + out << "\\uplus";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 965:\ + out << "\\upsilon";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 933:\ + out << "\\Upsilon";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 949:\ + out << "\\varepsilon";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 1008:\ + out << "\\varkappa";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 966:\ + out << "\\varphi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 982:\ + out << "\\varpi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 1009:\ + out << "\\varrho";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 962:\ + out << "\\varsigma";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 977:\ + out << "\\vartheta";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 1012:\ + out << "\\varTheta";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8788:\ + out << "\\vcentcolon=";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8866:\ + out << "\\vdash";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8871:\ + out << "\\vDash";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8942:\ + out << "\\vdots";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8744:\ + out << "\\vee";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8891:\ + out << "\\veebar";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 9888:\ + out << "\\warning";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8743:\ + out << "\\wedge";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8472:\ + out << "\\wp";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 8768:\ + out << "\\wr";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 958:\ + out << "\\xi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 926:\ + out << "\\Xi";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 437:\ + out << "\\Zbar";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 950:\ + out << "\\zeta";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 918:\ + out << "\\Zeta";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + +#define MATHBRAN_LATEX_SYMBOLS_32BIT \ + case 57304:\ + out << "\\mathbb{0}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 57305:\ + out << "\\mathbb{1}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 57306:\ + out << "\\mathbb{2}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 57307:\ + out << "\\mathbb{3}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 57308:\ + out << "\\mathbb{4}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 57309:\ + out << "\\mathbb{5}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 57310:\ + out << "\\mathbb{6}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 57311:\ + out << "\\mathbb{7}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 57312:\ + out << "\\mathbb{8}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 57313:\ + out << "\\mathbb{9}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 56633:\ + out << "\\mathbb{B}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 56635:\ + out << "\\mathbb{D}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 56636:\ + out << "\\mathbb{E}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 56637:\ + out << "\\mathbb{F}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 56641:\ + out << "\\mathbb{J}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 56646:\ + out << "\\mathbb{O}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 56650:\ + out << "\\mathbb{S}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 56651:\ + out << "\\mathbb{T}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 56652:\ + out << "\\mathbb{U}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + case 56608:\ + out << "\\mathfrak{c}";\ + if(curr < source.size() && isLetter(source[curr])) out << "{}";\ + break;\ + diff --git a/include/QMathBranUnicode.h b/include/QMathBranUnicode.h index c46e7c3f..a397244b 100644 --- a/include/QMathBranUnicode.h +++ b/include/QMathBranUnicode.h @@ -1,299 +1,299 @@ -#ifndef QMATHBRANUNICODE_H -#define QMATHBRANUNICODE_H - -#include "QMathBran.h" -#include "QMathBranUnicode_Macros.h" -#include - -namespace MathBran { - -static bool validateSubscript(const QString& source, int& curr){ - if(source[curr] == MB_CLOSE) return false; - while(source[curr] != MB_CLOSE){ - switch (source[curr++].unicode()) { - MATHBRAN_SUBSCRIPT_ALLOWED_CASES - case ' ': - break; - default: return false; - } - } - curr++; - - return true; -} - -static bool validateSuperscript(const QString& source, int& curr){ - if(source[curr] == MB_CLOSE) return false; - while(source[curr] != MB_CLOSE){ - switch (source[curr++].unicode()) { - MATHBRAN_SUPERSCRIPT_ALLOWED_CASES - case ' ': - break; - case MB_USHORT_CONSTRUCT_SYMBOL: - if(source[curr++] == MB_INTEGRAL && source[curr] != MB_OPEN) break; - else return false; - default: return false; - } - } - curr++; - - return true; -} - -inline bool validateAccent(const QString& source, int& curr){ - if(source[curr] == MB_CLOSE) return false; - if(source[curr++] == MB_CONSTRUCT_SYMBOL){ - switch (source[curr++].unicode()) { - case MB_USHORT_ACCENT_ARROW: - case MB_USHORT_ACCENT_BAR: - case MB_USHORT_ACCENT_BREVE: - case MB_USHORT_ACCENT_DOT: - case MB_USHORT_ACCENT_DOUBLE_DOTS: - case MB_USHORT_ACCENT_HAT: - case MB_USHORT_ACCENT_TILDE: - if(validateAccent(source,++curr)) break; - return false; - default: - return false; - } - if(source[curr] != MB_CLOSE) return false; - } - curr++; - - return true; -} - -inline bool validateExtendableAccent(const QString& source, int& curr){ - if(source[curr] == MB_CLOSE){ - return false; - }else if(source[curr] == MB_CONSTRUCT_SYMBOL){ - return validateAccent(source, curr); - }else{ - while(source[curr] != MB_CLOSE) - if(source[curr++] == MB_CONSTRUCT_SYMBOL) return false; - curr++; - - return true; - } -} - -inline bool canConvertToUnicode(const QString& source){ - Q_ASSERT(isWellFormed(source)); - - int curr = 0; - while(curr < source.size()){ - if(source[curr++] == MB_CONSTRUCT_SYMBOL){ - switch (source[curr++].unicode()) { - case MB_USHORT_GROUPING_BARS: - case MB_USHORT_GROUPING_CEIL: - case MB_USHORT_GROUPING_FLOOR: - case MB_USHORT_GROUPING_BRACKETS: - case MB_USHORT_GROUPING_DOUBLE_BARS: - case MB_USHORT_GROUPING_PARENTHESIS: - curr++; - break; - case MB_USHORT_SUBSCRIPT: - if(validateSubscript(source,++curr)) break; - return false; - case MB_USHORT_SUPERSCRIPT: - if(validateSuperscript(source,++curr)) break; - return false; - case MB_USHORT_ACCENT_BAR: - if(validateExtendableAccent(source,++curr)) break; - return false; - case MB_USHORT_ACCENT_ARROW: - case MB_USHORT_ACCENT_BREVE: - case MB_USHORT_ACCENT_DOT: - case MB_USHORT_ACCENT_DOUBLE_DOTS: - case MB_USHORT_ACCENT_HAT: - case MB_USHORT_ACCENT_TILDE: - if(validateAccent(source,++curr)) break; - return false; - case MB_USHORT_INTEGRAL: - case MB_USHORT_DOUBLE_INTEGRAL: - case MB_USHORT_TRIPLE_INTEGRAL: - case MB_USHORT_CONTOUR_INTEGRAL: - case MB_USHORT_CLOSED_SURFACE_INTEGRAL: - case MB_USHORT_CLOSED_VOLUME_INTEGRAL: - case MB_USHORT_SUMMATION: - case MB_USHORT_PRODUCT: - case MB_USHORT_COPRODUCT: - case MB_USHORT_INTERSECTION: - case MB_USHORT_UNION: - case MB_USHORT_UNION_PLUS: - if(source[curr] == MB_OPEN && !validateSubscript(source, ++curr)) return false; - if(source[curr] == MB_OPEN) return false; - break; - - default: return false; - } - } - } - - return true; -} - -static void writeSubscript(const QString& source, int& curr, QTextStream& out){ - while(source[curr] != MB_CLOSE){ - switch (source[curr++].unicode()) { - MATHBRAN_SYMBOL_TO_SUBSCRIPT_MAP - case ' ': out << ' '; break; - } - } - curr++; -} - -static void writeSuperscript(const QString& source, int& curr, QTextStream& out){ - while(source[curr] != MB_CLOSE){ - switch (source[curr++].unicode()) { - MATHBRAN_SYMBOL_TO_SUPERSCRIPT_MAP - case ' ': out << ' '; break; - case MB_USHORT_CONSTRUCT_SYMBOL: - curr++; - out << QChar(7604); - break; - } - } - curr++; -} - -static void writeAccent(const QString& source, int& curr, QTextStream& out, const QChar& diacritic){ - if(source[curr] == MB_CONSTRUCT_SYMBOL){ - curr++; - switch (source[curr++].unicode()) { - case MB_USHORT_ACCENT_ARROW: writeAccent(source, ++curr, out, QChar(8407)); break; - case MB_USHORT_ACCENT_BAR: writeAccent(source, ++curr, out, QChar(773)); break; - case MB_USHORT_ACCENT_BREVE: writeAccent(source, ++curr, out, QChar(774)); break; - case MB_USHORT_ACCENT_DOT: writeAccent(source, ++curr, out, QChar(775)); break; - case MB_USHORT_ACCENT_DOUBLE_DOTS: writeAccent(source, ++curr, out, QChar(776)); break; - case MB_USHORT_ACCENT_HAT: writeAccent(source, ++curr, out, QChar(770)); break; - case MB_USHORT_ACCENT_TILDE: writeAccent(source, ++curr, out, QChar(771)); break; - } - }else{ - out << source[curr++]; - } - out << diacritic; - curr++; -} - -static void writeOverbar(const QString& source, int& curr, QTextStream& out){ - if(source[curr] == MB_CONSTRUCT_SYMBOL){ - writeAccent(source, curr, out, QChar(773)); - }else{ - while(source[curr] != MB_CLOSE) - out << source[curr++] << QChar(773); - curr++; - } -} - -static void writeGrouping(const QString& source, int& curr, QTextStream& out, const QChar& closer){ - QString::size_type start = curr; - while(source[curr] != MB_CLOSE){ - if(source[curr++] == MB_CONSTRUCT_SYMBOL){ - out << source.midRef(start, curr-start-1); - switch (source[curr++].unicode()) { - case MB_USHORT_GROUPING_BARS: - out << '|'; writeGrouping(source, ++curr, out, '|'); break; - case MB_USHORT_GROUPING_CEIL: - out << QChar(8968); writeGrouping(source, ++curr, out, QChar(8969)); break; - case MB_USHORT_GROUPING_FLOOR: - out << QChar(8970); writeGrouping(source, ++curr, out, QChar(8971)); break; - case MB_USHORT_GROUPING_BRACKETS: - out << '['; writeGrouping(source, ++curr, out, ']'); break; - case MB_USHORT_GROUPING_DOUBLE_BARS: - out << QChar(8214); writeGrouping(source, ++curr, out, QChar(8214)); break; - case MB_USHORT_GROUPING_PARENTHESIS: - out << '('; writeGrouping(source, ++curr, out, ')'); break; - case MB_USHORT_SUBSCRIPT: writeSubscript(source, ++curr, out); break; - case MB_USHORT_SUPERSCRIPT: writeSuperscript(source, ++curr, out); break; - case MB_USHORT_ACCENT_BAR: writeOverbar(source, ++curr, out); break; - case MB_USHORT_ACCENT_ARROW: writeAccent(source, ++curr, out, QChar(8407)); break; - case MB_USHORT_ACCENT_BREVE: writeAccent(source, ++curr, out, QChar(774)); break; - case MB_USHORT_ACCENT_DOT: writeAccent(source, ++curr, out, QChar(775)); break; - case MB_USHORT_ACCENT_DOUBLE_DOTS: writeAccent(source, ++curr, out, QChar(776)); break; - case MB_USHORT_ACCENT_HAT: writeAccent(source, ++curr, out, QChar(770)); break; - case MB_USHORT_ACCENT_TILDE: writeAccent(source, ++curr, out, QChar(771)); break; - - case MB_USHORT_INTEGRAL: - case MB_USHORT_DOUBLE_INTEGRAL: - case MB_USHORT_TRIPLE_INTEGRAL: - case MB_USHORT_CONTOUR_INTEGRAL: - case MB_USHORT_CLOSED_SURFACE_INTEGRAL: - case MB_USHORT_CLOSED_VOLUME_INTEGRAL: - case MB_USHORT_SUMMATION: - case MB_USHORT_PRODUCT: - case MB_USHORT_COPRODUCT: - case MB_USHORT_INTERSECTION: - case MB_USHORT_UNION: - case MB_USHORT_UNION_PLUS: - out << source[curr-1]; - if(source[curr] == MB_OPEN) writeSubscript(source, ++curr, out); - break; - } - start = curr; - } - } - out << source.midRef(start, curr-start) << closer; - curr++; -} - -inline QString toUnicode(const QString& source){ - Q_ASSERT(canConvertToUnicode(source)); - - QString unicode; - QTextStream out(&unicode); - QString::size_type start = 0; - QString::size_type curr = 0; - while(curr < source.size()){ - if(source[curr++] == MB_CONSTRUCT_SYMBOL){ - out << source.midRef(start, curr-start-1); - switch (source[curr++].unicode()) { - case MB_USHORT_GROUPING_BARS: - out << '|'; writeGrouping(source, ++curr, out, '|'); break; - case MB_USHORT_GROUPING_CEIL: - out << QChar(8968); writeGrouping(source, ++curr, out, QChar(8969)); break; - case MB_USHORT_GROUPING_FLOOR: - out << QChar(8970); writeGrouping(source, ++curr, out, QChar(8971)); break; - case MB_USHORT_GROUPING_BRACKETS: - out << '['; writeGrouping(source, ++curr, out, ']'); break; - case MB_USHORT_GROUPING_DOUBLE_BARS: - out << QChar(8214); writeGrouping(source, ++curr, out, QChar(8214)); break; - case MB_USHORT_GROUPING_PARENTHESIS: - out << '('; writeGrouping(source, ++curr, out, ')'); break; - case MB_USHORT_SUBSCRIPT: writeSubscript(source, ++curr, out); break; - case MB_USHORT_SUPERSCRIPT: writeSuperscript(source, ++curr, out); break; - case MB_USHORT_ACCENT_BAR: writeOverbar(source, ++curr, out); break; - case MB_USHORT_ACCENT_ARROW: writeAccent(source, ++curr, out, QChar(8407)); break; - case MB_USHORT_ACCENT_BREVE: writeAccent(source, ++curr, out, QChar(774)); break; - case MB_USHORT_ACCENT_DOT: writeAccent(source, ++curr, out, QChar(775)); break; - case MB_USHORT_ACCENT_DOUBLE_DOTS: writeAccent(source, ++curr, out, QChar(776)); break; - case MB_USHORT_ACCENT_HAT: writeAccent(source, ++curr, out, QChar(770)); break; - case MB_USHORT_ACCENT_TILDE: writeAccent(source, ++curr, out, QChar(771)); break; - - case MB_USHORT_INTEGRAL: - case MB_USHORT_DOUBLE_INTEGRAL: - case MB_USHORT_TRIPLE_INTEGRAL: - case MB_USHORT_CONTOUR_INTEGRAL: - case MB_USHORT_CLOSED_SURFACE_INTEGRAL: - case MB_USHORT_CLOSED_VOLUME_INTEGRAL: - case MB_USHORT_SUMMATION: - case MB_USHORT_PRODUCT: - case MB_USHORT_COPRODUCT: - case MB_USHORT_INTERSECTION: - case MB_USHORT_UNION: - case MB_USHORT_UNION_PLUS: - out << source[curr-1]; - if(source[curr] == MB_OPEN) writeSubscript(source, ++curr, out); - break; - } - start = curr; - } - } - out << source.midRef(start, curr-start); - - return unicode; -} - -} - -#endif // QMATHBRANUNICODE_H +#ifndef QMATHBRANUNICODE_H +#define QMATHBRANUNICODE_H + +#include "QMathBran.h" +#include "QMathBranUnicode_Macros.h" +#include + +namespace MathBran { + +static bool validateSubscript(const QString& source, int& curr){ + if(source[curr] == MB_CLOSE) return false; + while(source[curr] != MB_CLOSE){ + switch (source[curr++].unicode()) { + MATHBRAN_SUBSCRIPT_ALLOWED_CASES + case ' ': + break; + default: return false; + } + } + curr++; + + return true; +} + +static bool validateSuperscript(const QString& source, int& curr){ + if(source[curr] == MB_CLOSE) return false; + while(source[curr] != MB_CLOSE){ + switch (source[curr++].unicode()) { + MATHBRAN_SUPERSCRIPT_ALLOWED_CASES + case ' ': + break; + case MB_USHORT_CONSTRUCT_SYMBOL: + if(source[curr++] == MB_INTEGRAL && source[curr] != MB_OPEN) break; + else return false; + default: return false; + } + } + curr++; + + return true; +} + +inline bool validateAccent(const QString& source, int& curr){ + if(source[curr] == MB_CLOSE) return false; + if(source[curr++] == MB_CONSTRUCT_SYMBOL){ + switch (source[curr++].unicode()) { + case MB_USHORT_ACCENT_ARROW: + case MB_USHORT_ACCENT_BAR: + case MB_USHORT_ACCENT_BREVE: + case MB_USHORT_ACCENT_DOT: + case MB_USHORT_ACCENT_DOUBLE_DOTS: + case MB_USHORT_ACCENT_HAT: + case MB_USHORT_ACCENT_TILDE: + if(validateAccent(source,++curr)) break; + return false; + default: + return false; + } + if(source[curr] != MB_CLOSE) return false; + } + curr++; + + return true; +} + +inline bool validateExtendableAccent(const QString& source, int& curr){ + if(source[curr] == MB_CLOSE){ + return false; + }else if(source[curr] == MB_CONSTRUCT_SYMBOL){ + return validateAccent(source, curr); + }else{ + while(source[curr] != MB_CLOSE) + if(source[curr++] == MB_CONSTRUCT_SYMBOL) return false; + curr++; + + return true; + } +} + +inline bool canConvertToUnicode(const QString& source){ + Q_ASSERT(isWellFormed(source)); + + int curr = 0; + while(curr < source.size()){ + if(source[curr++] == MB_CONSTRUCT_SYMBOL){ + switch (source[curr++].unicode()) { + case MB_USHORT_GROUPING_BARS: + case MB_USHORT_GROUPING_CEIL: + case MB_USHORT_GROUPING_FLOOR: + case MB_USHORT_GROUPING_BRACKETS: + case MB_USHORT_GROUPING_DOUBLE_BARS: + case MB_USHORT_GROUPING_PARENTHESIS: + curr++; + break; + case MB_USHORT_SUBSCRIPT: + if(validateSubscript(source,++curr)) break; + return false; + case MB_USHORT_SUPERSCRIPT: + if(validateSuperscript(source,++curr)) break; + return false; + case MB_USHORT_ACCENT_BAR: + if(validateExtendableAccent(source,++curr)) break; + return false; + case MB_USHORT_ACCENT_ARROW: + case MB_USHORT_ACCENT_BREVE: + case MB_USHORT_ACCENT_DOT: + case MB_USHORT_ACCENT_DOUBLE_DOTS: + case MB_USHORT_ACCENT_HAT: + case MB_USHORT_ACCENT_TILDE: + if(validateAccent(source,++curr)) break; + return false; + case MB_USHORT_INTEGRAL: + case MB_USHORT_DOUBLE_INTEGRAL: + case MB_USHORT_TRIPLE_INTEGRAL: + case MB_USHORT_CONTOUR_INTEGRAL: + case MB_USHORT_CLOSED_SURFACE_INTEGRAL: + case MB_USHORT_CLOSED_VOLUME_INTEGRAL: + case MB_USHORT_SUMMATION: + case MB_USHORT_PRODUCT: + case MB_USHORT_COPRODUCT: + case MB_USHORT_INTERSECTION: + case MB_USHORT_UNION: + case MB_USHORT_UNION_PLUS: + if(source[curr] == MB_OPEN && !validateSubscript(source, ++curr)) return false; + if(source[curr] == MB_OPEN) return false; + break; + + default: return false; + } + } + } + + return true; +} + +static void writeSubscript(const QString& source, int& curr, QTextStream& out){ + while(source[curr] != MB_CLOSE){ + switch (source[curr++].unicode()) { + MATHBRAN_SYMBOL_TO_SUBSCRIPT_MAP + case ' ': out << ' '; break; + } + } + curr++; +} + +static void writeSuperscript(const QString& source, int& curr, QTextStream& out){ + while(source[curr] != MB_CLOSE){ + switch (source[curr++].unicode()) { + MATHBRAN_SYMBOL_TO_SUPERSCRIPT_MAP + case ' ': out << ' '; break; + case MB_USHORT_CONSTRUCT_SYMBOL: + curr++; + out << QChar(7604); + break; + } + } + curr++; +} + +static void writeAccent(const QString& source, int& curr, QTextStream& out, const QChar& diacritic){ + if(source[curr] == MB_CONSTRUCT_SYMBOL){ + curr++; + switch (source[curr++].unicode()) { + case MB_USHORT_ACCENT_ARROW: writeAccent(source, ++curr, out, QChar(8407)); break; + case MB_USHORT_ACCENT_BAR: writeAccent(source, ++curr, out, QChar(773)); break; + case MB_USHORT_ACCENT_BREVE: writeAccent(source, ++curr, out, QChar(774)); break; + case MB_USHORT_ACCENT_DOT: writeAccent(source, ++curr, out, QChar(775)); break; + case MB_USHORT_ACCENT_DOUBLE_DOTS: writeAccent(source, ++curr, out, QChar(776)); break; + case MB_USHORT_ACCENT_HAT: writeAccent(source, ++curr, out, QChar(770)); break; + case MB_USHORT_ACCENT_TILDE: writeAccent(source, ++curr, out, QChar(771)); break; + } + }else{ + out << source[curr++]; + } + out << diacritic; + curr++; +} + +static void writeOverbar(const QString& source, int& curr, QTextStream& out){ + if(source[curr] == MB_CONSTRUCT_SYMBOL){ + writeAccent(source, curr, out, QChar(773)); + }else{ + while(source[curr] != MB_CLOSE) + out << source[curr++] << QChar(773); + curr++; + } +} + +static void writeGrouping(const QString& source, int& curr, QTextStream& out, const QChar& closer){ + QString::size_type start = curr; + while(source[curr] != MB_CLOSE){ + if(source[curr++] == MB_CONSTRUCT_SYMBOL){ + out << source.midRef(start, curr-start-1); + switch (source[curr++].unicode()) { + case MB_USHORT_GROUPING_BARS: + out << '|'; writeGrouping(source, ++curr, out, '|'); break; + case MB_USHORT_GROUPING_CEIL: + out << QChar(8968); writeGrouping(source, ++curr, out, QChar(8969)); break; + case MB_USHORT_GROUPING_FLOOR: + out << QChar(8970); writeGrouping(source, ++curr, out, QChar(8971)); break; + case MB_USHORT_GROUPING_BRACKETS: + out << '['; writeGrouping(source, ++curr, out, ']'); break; + case MB_USHORT_GROUPING_DOUBLE_BARS: + out << QChar(8214); writeGrouping(source, ++curr, out, QChar(8214)); break; + case MB_USHORT_GROUPING_PARENTHESIS: + out << '('; writeGrouping(source, ++curr, out, ')'); break; + case MB_USHORT_SUBSCRIPT: writeSubscript(source, ++curr, out); break; + case MB_USHORT_SUPERSCRIPT: writeSuperscript(source, ++curr, out); break; + case MB_USHORT_ACCENT_BAR: writeOverbar(source, ++curr, out); break; + case MB_USHORT_ACCENT_ARROW: writeAccent(source, ++curr, out, QChar(8407)); break; + case MB_USHORT_ACCENT_BREVE: writeAccent(source, ++curr, out, QChar(774)); break; + case MB_USHORT_ACCENT_DOT: writeAccent(source, ++curr, out, QChar(775)); break; + case MB_USHORT_ACCENT_DOUBLE_DOTS: writeAccent(source, ++curr, out, QChar(776)); break; + case MB_USHORT_ACCENT_HAT: writeAccent(source, ++curr, out, QChar(770)); break; + case MB_USHORT_ACCENT_TILDE: writeAccent(source, ++curr, out, QChar(771)); break; + + case MB_USHORT_INTEGRAL: + case MB_USHORT_DOUBLE_INTEGRAL: + case MB_USHORT_TRIPLE_INTEGRAL: + case MB_USHORT_CONTOUR_INTEGRAL: + case MB_USHORT_CLOSED_SURFACE_INTEGRAL: + case MB_USHORT_CLOSED_VOLUME_INTEGRAL: + case MB_USHORT_SUMMATION: + case MB_USHORT_PRODUCT: + case MB_USHORT_COPRODUCT: + case MB_USHORT_INTERSECTION: + case MB_USHORT_UNION: + case MB_USHORT_UNION_PLUS: + out << source[curr-1]; + if(source[curr] == MB_OPEN) writeSubscript(source, ++curr, out); + break; + } + start = curr; + } + } + out << source.midRef(start, curr-start) << closer; + curr++; +} + +inline QString toUnicode(const QString& source){ + Q_ASSERT(canConvertToUnicode(source)); + + QString unicode; + QTextStream out(&unicode); + QString::size_type start = 0; + QString::size_type curr = 0; + while(curr < source.size()){ + if(source[curr++] == MB_CONSTRUCT_SYMBOL){ + out << source.midRef(start, curr-start-1); + switch (source[curr++].unicode()) { + case MB_USHORT_GROUPING_BARS: + out << '|'; writeGrouping(source, ++curr, out, '|'); break; + case MB_USHORT_GROUPING_CEIL: + out << QChar(8968); writeGrouping(source, ++curr, out, QChar(8969)); break; + case MB_USHORT_GROUPING_FLOOR: + out << QChar(8970); writeGrouping(source, ++curr, out, QChar(8971)); break; + case MB_USHORT_GROUPING_BRACKETS: + out << '['; writeGrouping(source, ++curr, out, ']'); break; + case MB_USHORT_GROUPING_DOUBLE_BARS: + out << QChar(8214); writeGrouping(source, ++curr, out, QChar(8214)); break; + case MB_USHORT_GROUPING_PARENTHESIS: + out << '('; writeGrouping(source, ++curr, out, ')'); break; + case MB_USHORT_SUBSCRIPT: writeSubscript(source, ++curr, out); break; + case MB_USHORT_SUPERSCRIPT: writeSuperscript(source, ++curr, out); break; + case MB_USHORT_ACCENT_BAR: writeOverbar(source, ++curr, out); break; + case MB_USHORT_ACCENT_ARROW: writeAccent(source, ++curr, out, QChar(8407)); break; + case MB_USHORT_ACCENT_BREVE: writeAccent(source, ++curr, out, QChar(774)); break; + case MB_USHORT_ACCENT_DOT: writeAccent(source, ++curr, out, QChar(775)); break; + case MB_USHORT_ACCENT_DOUBLE_DOTS: writeAccent(source, ++curr, out, QChar(776)); break; + case MB_USHORT_ACCENT_HAT: writeAccent(source, ++curr, out, QChar(770)); break; + case MB_USHORT_ACCENT_TILDE: writeAccent(source, ++curr, out, QChar(771)); break; + + case MB_USHORT_INTEGRAL: + case MB_USHORT_DOUBLE_INTEGRAL: + case MB_USHORT_TRIPLE_INTEGRAL: + case MB_USHORT_CONTOUR_INTEGRAL: + case MB_USHORT_CLOSED_SURFACE_INTEGRAL: + case MB_USHORT_CLOSED_VOLUME_INTEGRAL: + case MB_USHORT_SUMMATION: + case MB_USHORT_PRODUCT: + case MB_USHORT_COPRODUCT: + case MB_USHORT_INTERSECTION: + case MB_USHORT_UNION: + case MB_USHORT_UNION_PLUS: + out << source[curr-1]; + if(source[curr] == MB_OPEN) writeSubscript(source, ++curr, out); + break; + } + start = curr; + } + } + out << source.midRef(start, curr-start); + + return unicode; +} + +} + +#endif // QMATHBRANUNICODE_H diff --git a/include/QMathBranUnicode_Macros.h b/include/QMathBranUnicode_Macros.h index 0b6062b4..4b2b481e 100644 --- a/include/QMathBranUnicode_Macros.h +++ b/include/QMathBranUnicode_Macros.h @@ -1,230 +1,230 @@ -//CODE-GEN FILE -//This file defines macros to make use of the MathBran serialization format. -//The list of definitions is generated from a spreadsheet in the MathBran project. - -#ifndef QMATHBRANUNICODE_MACROS -#define QMATHBRANUNICODE_MACROS - -#define MATHBRAN_SUBSCRIPT_ALLOWED_CASES \ - case 48: \ - case 49: \ - case 50: \ - case 51: \ - case 52: \ - case 53: \ - case 54: \ - case 55: \ - case 56: \ - case 57: \ - case 43: \ - case 45: \ - case 61: \ - case 40: \ - case 41: \ - case 97: \ - case 101: \ - case 104: \ - case 105: \ - case 106: \ - case 107: \ - case 108: \ - case 109: \ - case 110: \ - case 111: \ - case 112: \ - case 114: \ - case 115: \ - case 116: \ - case 117: \ - case 118: \ - case 120: \ - case 946: \ - case 947: \ - case 961: \ - case 966: \ - case 967: - -#define MATHBRAN_SYMBOL_TO_SUBSCRIPT_MAP \ - case 48: out << QChar(8320); break; \ - case 49: out << QChar(8321); break; \ - case 50: out << QChar(8322); break; \ - case 51: out << QChar(8323); break; \ - case 52: out << QChar(8324); break; \ - case 53: out << QChar(8325); break; \ - case 54: out << QChar(8326); break; \ - case 55: out << QChar(8327); break; \ - case 56: out << QChar(8328); break; \ - case 57: out << QChar(8329); break; \ - case 43: out << QChar(8330); break; \ - case 45: out << QChar(8331); break; \ - case 61: out << QChar(8332); break; \ - case 40: out << QChar(8333); break; \ - case 41: out << QChar(8334); break; \ - case 97: out << QChar(8336); break; \ - case 101: out << QChar(8337); break; \ - case 104: out << QChar(8341); break; \ - case 105: out << QChar(7522); break; \ - case 106: out << QChar(11388); break; \ - case 107: out << QChar(8342); break; \ - case 108: out << QChar(8343); break; \ - case 109: out << QChar(8344); break; \ - case 110: out << QChar(8345); break; \ - case 111: out << QChar(8338); break; \ - case 112: out << QChar(8346); break; \ - case 114: out << QChar(7523); break; \ - case 115: out << QChar(8347); break; \ - case 116: out << QChar(8348); break; \ - case 117: out << QChar(7524); break; \ - case 118: out << QChar(7525); break; \ - case 120: out << QChar(8339); break; \ - case 946: out << QChar(7526); break; \ - case 947: out << QChar(7527); break; \ - case 961: out << QChar(7528); break; \ - case 966: out << QChar(7529); break; \ - case 967: out << QChar(7530); break; - -#define MATHBRAN_SUPERSCRIPT_ALLOWED_CASES \ - case 48: \ - case 49: \ - case 50: \ - case 51: \ - case 52: \ - case 53: \ - case 54: \ - case 55: \ - case 56: \ - case 57: \ - case 43: \ - case 45: \ - case 61: \ - case 40: \ - case 41: \ - case 65: \ - case 66: \ - case 68: \ - case 69: \ - case 71: \ - case 72: \ - case 73: \ - case 74: \ - case 75: \ - case 76: \ - case 77: \ - case 78: \ - case 79: \ - case 80: \ - case 82: \ - case 84: \ - case 85: \ - case 86: \ - case 87: \ - case 97: \ - case 98: \ - case 99: \ - case 100: \ - case 101: \ - case 102: \ - case 103: \ - case 104: \ - case 105: \ - case 106: \ - case 107: \ - case 108: \ - case 109: \ - case 110: \ - case 111: \ - case 112: \ - case 114: \ - case 115: \ - case 116: \ - case 117: \ - case 118: \ - case 119: \ - case 120: \ - case 121: \ - case 122: \ - case 946: \ - case 947: \ - case 948: \ - case 1013: \ - case 952: \ - case 953: \ - case 957: \ - case 966: \ - case 967: \ - case 8747: \ - case 632: - -#define MATHBRAN_SYMBOL_TO_SUPERSCRIPT_MAP \ - case 48: out << QChar(8304); break; \ - case 49: out << QChar(185); break; \ - case 50: out << QChar(178); break; \ - case 51: out << QChar(179); break; \ - case 52: out << QChar(8308); break; \ - case 53: out << QChar(8309); break; \ - case 54: out << QChar(8310); break; \ - case 55: out << QChar(8311); break; \ - case 56: out << QChar(8312); break; \ - case 57: out << QChar(8313); break; \ - case 43: out << QChar(8314); break; \ - case 45: out << QChar(8315); break; \ - case 61: out << QChar(8316); break; \ - case 40: out << QChar(8317); break; \ - case 41: out << QChar(8318); break; \ - case 65: out << QChar(7468); break; \ - case 66: out << QChar(7470); break; \ - case 68: out << QChar(7472); break; \ - case 69: out << QChar(7473); break; \ - case 71: out << QChar(7475); break; \ - case 72: out << QChar(7476); break; \ - case 73: out << QChar(7477); break; \ - case 74: out << QChar(7478); break; \ - case 75: out << QChar(7479); break; \ - case 76: out << QChar(7480); break; \ - case 77: out << QChar(7481); break; \ - case 78: out << QChar(7482); break; \ - case 79: out << QChar(7484); break; \ - case 80: out << QChar(7486); break; \ - case 82: out << QChar(7487); break; \ - case 84: out << QChar(7488); break; \ - case 85: out << QChar(7489); break; \ - case 86: out << QChar(11389); break; \ - case 87: out << QChar(7490); break; \ - case 97: out << QChar(7491); break; \ - case 98: out << QChar(7495); break; \ - case 99: out << QChar(7580); break; \ - case 100: out << QChar(7496); break; \ - case 101: out << QChar(7497); break; \ - case 102: out << QChar(7584); break; \ - case 103: out << QChar(7501); break; \ - case 104: out << QChar(688); break; \ - case 105: out << QChar(8305); break; \ - case 106: out << QChar(690); break; \ - case 107: out << QChar(7503); break; \ - case 108: out << QChar(737); break; \ - case 109: out << QChar(7504); break; \ - case 110: out << QChar(8319); break; \ - case 111: out << QChar(7506); break; \ - case 112: out << QChar(7510); break; \ - case 114: out << QChar(691); break; \ - case 115: out << QChar(738); break; \ - case 116: out << QChar(7511); break; \ - case 117: out << QChar(7512); break; \ - case 118: out << QChar(7515); break; \ - case 119: out << QChar(695); break; \ - case 120: out << QChar(739); break; \ - case 121: out << QChar(696); break; \ - case 122: out << QChar(7611); break; \ - case 946: out << QChar(7517); break; \ - case 947: out << QChar(7518); break; \ - case 948: out << QChar(7519); break; \ - case 1013: out << QChar(7499); break; \ - case 952: out << QChar(7615); break; \ - case 953: out << QChar(7589); break; \ - case 957: out << QChar(7609); break; \ - case 966: out << QChar(7520); break; \ - case 967: out << QChar(7521); break; \ - case 8747: out << QChar(7604); break; \ - case 632: out << QChar(7602); break; - -#endif +//CODE-GEN FILE +//This file defines macros to make use of the MathBran serialization format. +//The list of definitions is generated from a spreadsheet in the MathBran project. + +#ifndef QMATHBRANUNICODE_MACROS +#define QMATHBRANUNICODE_MACROS + +#define MATHBRAN_SUBSCRIPT_ALLOWED_CASES \ + case 48: \ + case 49: \ + case 50: \ + case 51: \ + case 52: \ + case 53: \ + case 54: \ + case 55: \ + case 56: \ + case 57: \ + case 43: \ + case 45: \ + case 61: \ + case 40: \ + case 41: \ + case 97: \ + case 101: \ + case 104: \ + case 105: \ + case 106: \ + case 107: \ + case 108: \ + case 109: \ + case 110: \ + case 111: \ + case 112: \ + case 114: \ + case 115: \ + case 116: \ + case 117: \ + case 118: \ + case 120: \ + case 946: \ + case 947: \ + case 961: \ + case 966: \ + case 967: + +#define MATHBRAN_SYMBOL_TO_SUBSCRIPT_MAP \ + case 48: out << QChar(8320); break; \ + case 49: out << QChar(8321); break; \ + case 50: out << QChar(8322); break; \ + case 51: out << QChar(8323); break; \ + case 52: out << QChar(8324); break; \ + case 53: out << QChar(8325); break; \ + case 54: out << QChar(8326); break; \ + case 55: out << QChar(8327); break; \ + case 56: out << QChar(8328); break; \ + case 57: out << QChar(8329); break; \ + case 43: out << QChar(8330); break; \ + case 45: out << QChar(8331); break; \ + case 61: out << QChar(8332); break; \ + case 40: out << QChar(8333); break; \ + case 41: out << QChar(8334); break; \ + case 97: out << QChar(8336); break; \ + case 101: out << QChar(8337); break; \ + case 104: out << QChar(8341); break; \ + case 105: out << QChar(7522); break; \ + case 106: out << QChar(11388); break; \ + case 107: out << QChar(8342); break; \ + case 108: out << QChar(8343); break; \ + case 109: out << QChar(8344); break; \ + case 110: out << QChar(8345); break; \ + case 111: out << QChar(8338); break; \ + case 112: out << QChar(8346); break; \ + case 114: out << QChar(7523); break; \ + case 115: out << QChar(8347); break; \ + case 116: out << QChar(8348); break; \ + case 117: out << QChar(7524); break; \ + case 118: out << QChar(7525); break; \ + case 120: out << QChar(8339); break; \ + case 946: out << QChar(7526); break; \ + case 947: out << QChar(7527); break; \ + case 961: out << QChar(7528); break; \ + case 966: out << QChar(7529); break; \ + case 967: out << QChar(7530); break; + +#define MATHBRAN_SUPERSCRIPT_ALLOWED_CASES \ + case 48: \ + case 49: \ + case 50: \ + case 51: \ + case 52: \ + case 53: \ + case 54: \ + case 55: \ + case 56: \ + case 57: \ + case 43: \ + case 45: \ + case 61: \ + case 40: \ + case 41: \ + case 65: \ + case 66: \ + case 68: \ + case 69: \ + case 71: \ + case 72: \ + case 73: \ + case 74: \ + case 75: \ + case 76: \ + case 77: \ + case 78: \ + case 79: \ + case 80: \ + case 82: \ + case 84: \ + case 85: \ + case 86: \ + case 87: \ + case 97: \ + case 98: \ + case 99: \ + case 100: \ + case 101: \ + case 102: \ + case 103: \ + case 104: \ + case 105: \ + case 106: \ + case 107: \ + case 108: \ + case 109: \ + case 110: \ + case 111: \ + case 112: \ + case 114: \ + case 115: \ + case 116: \ + case 117: \ + case 118: \ + case 119: \ + case 120: \ + case 121: \ + case 122: \ + case 946: \ + case 947: \ + case 948: \ + case 1013: \ + case 952: \ + case 953: \ + case 957: \ + case 966: \ + case 967: \ + case 8747: \ + case 632: + +#define MATHBRAN_SYMBOL_TO_SUPERSCRIPT_MAP \ + case 48: out << QChar(8304); break; \ + case 49: out << QChar(185); break; \ + case 50: out << QChar(178); break; \ + case 51: out << QChar(179); break; \ + case 52: out << QChar(8308); break; \ + case 53: out << QChar(8309); break; \ + case 54: out << QChar(8310); break; \ + case 55: out << QChar(8311); break; \ + case 56: out << QChar(8312); break; \ + case 57: out << QChar(8313); break; \ + case 43: out << QChar(8314); break; \ + case 45: out << QChar(8315); break; \ + case 61: out << QChar(8316); break; \ + case 40: out << QChar(8317); break; \ + case 41: out << QChar(8318); break; \ + case 65: out << QChar(7468); break; \ + case 66: out << QChar(7470); break; \ + case 68: out << QChar(7472); break; \ + case 69: out << QChar(7473); break; \ + case 71: out << QChar(7475); break; \ + case 72: out << QChar(7476); break; \ + case 73: out << QChar(7477); break; \ + case 74: out << QChar(7478); break; \ + case 75: out << QChar(7479); break; \ + case 76: out << QChar(7480); break; \ + case 77: out << QChar(7481); break; \ + case 78: out << QChar(7482); break; \ + case 79: out << QChar(7484); break; \ + case 80: out << QChar(7486); break; \ + case 82: out << QChar(7487); break; \ + case 84: out << QChar(7488); break; \ + case 85: out << QChar(7489); break; \ + case 86: out << QChar(11389); break; \ + case 87: out << QChar(7490); break; \ + case 97: out << QChar(7491); break; \ + case 98: out << QChar(7495); break; \ + case 99: out << QChar(7580); break; \ + case 100: out << QChar(7496); break; \ + case 101: out << QChar(7497); break; \ + case 102: out << QChar(7584); break; \ + case 103: out << QChar(7501); break; \ + case 104: out << QChar(688); break; \ + case 105: out << QChar(8305); break; \ + case 106: out << QChar(690); break; \ + case 107: out << QChar(7503); break; \ + case 108: out << QChar(737); break; \ + case 109: out << QChar(7504); break; \ + case 110: out << QChar(8319); break; \ + case 111: out << QChar(7506); break; \ + case 112: out << QChar(7510); break; \ + case 114: out << QChar(691); break; \ + case 115: out << QChar(738); break; \ + case 116: out << QChar(7511); break; \ + case 117: out << QChar(7512); break; \ + case 118: out << QChar(7515); break; \ + case 119: out << QChar(695); break; \ + case 120: out << QChar(739); break; \ + case 121: out << QChar(696); break; \ + case 122: out << QChar(7611); break; \ + case 946: out << QChar(7517); break; \ + case 947: out << QChar(7518); break; \ + case 948: out << QChar(7519); break; \ + case 1013: out << QChar(7499); break; \ + case 952: out << QChar(7615); break; \ + case 953: out << QChar(7589); break; \ + case 957: out << QChar(7609); break; \ + case 966: out << QChar(7520); break; \ + case 967: out << QChar(7521); break; \ + case 8747: out << QChar(7604); break; \ + case 632: out << QChar(7602); break; + +#endif diff --git a/include/QMathBran_Macros.h b/include/QMathBran_Macros.h index 6a825ef9..b8b36f37 100644 --- a/include/QMathBran_Macros.h +++ b/include/QMathBran_Macros.h @@ -1,100 +1,100 @@ -//CODE-GEN FILE -//This file defines macros to make use of the MathBran serialization format. -//The list of definitions is generated from a spreadsheet in the MathBran project. - -#ifndef QMATHBRAN_MACROS -#define QMATHBRAN_MACROS - -#define MB_USHORT_CONSTRUCT_SYMBOL 8284 //⁜ -#define MB_USHORT_OPEN 9204 //⏴ -#define MB_USHORT_CLOSE 9205 //⏵ -#define MB_USHORT_ACCENT_ARROW 8594 //→ -#define MB_USHORT_ACCENT_BAR 257 //ā -#define MB_USHORT_ACCENT_BREVE 259 //ă -#define MB_USHORT_ACCENT_DOT 551 //ȧ -#define MB_USHORT_ACCENT_DOUBLE_DOTS 228 //ä -#define MB_USHORT_ACCENT_TRIPLE_DOTS 8943 //⋯ -#define MB_USHORT_ACCENT_HAT 226 //â -#define MB_USHORT_ACCENT_TILDE 227 //ã -#define MB_USHORT_SUMMATION 8721 //∑ -#define MB_USHORT_PRODUCT 8719 //∏ -#define MB_USHORT_COPRODUCT 8720 //∐ -#define MB_USHORT_INTERSECTION 8898 //⋂ -#define MB_USHORT_UNION 8899 //⋃ -#define MB_USHORT_UNION_PLUS 10756 //⨄ -#define MB_USHORT_BINOMIAL_COEFFICIENTS 98 //b -#define MB_USHORT_CASES 99 //c -#define MB_USHORT_FRACTION 102 //f -#define MB_USHORT_GROUPING_PARENTHESIS 40 //( -#define MB_USHORT_GROUPING_BRACKETS 91 //[ -#define MB_USHORT_GROUPING_CEIL 8968 //⌈ -#define MB_USHORT_GROUPING_FLOOR 8970 //⌊ -#define MB_USHORT_GROUPING_BARS 124 //| -#define MB_USHORT_GROUPING_DOUBLE_BARS 8214 //‖ -#define MB_USHORT_INTEGRAL 8747 //∫ -#define MB_USHORT_DOUBLE_INTEGRAL 8748 //∬ -#define MB_USHORT_TRIPLE_INTEGRAL 8749 //∭ -#define MB_USHORT_CONTOUR_INTEGRAL 8750 //∮ -#define MB_USHORT_CLOSED_SURFACE_INTEGRAL 8751 //∯ -#define MB_USHORT_CLOSED_VOLUME_INTEGRAL 8752 //∰ -#define MB_USHORT_MATRIX 8862 //⊞ -#define MB_USHORT_ROOT 8730 //√ -#define MB_USHORT_SUBSCRIPT 95 //_ -#define MB_USHORT_SUPERSCRIPT 94 //^ -#define MB_USHORT_DUALSCRIPT 916 //Δ -#define MB_USHORT_EVALSCRIPT 9482 //┊ -#define MB_USHORT_LIMIT 108 //l -#define MB_USHORT_UNDERSCRIPTED_MAX 8593 //↑ -#define MB_USHORT_UNDERSCRIPTED_MIN 8595 //↓ -#define MB_USHORT_UNDERSCRIPTED_SUP 8599 //↗ -#define MB_USHORT_UNDERSCRIPTED_INF 8600 //↘ - -#define MB_CONSTRUCT_SYMBOL QChar(MB_USHORT_CONSTRUCT_SYMBOL) //⁜ -#define MB_OPEN QChar(MB_USHORT_OPEN) //⏴ -#define MB_CLOSE QChar(MB_USHORT_CLOSE) //⏵ -#define MB_ACCENT_ARROW QChar(MB_USHORT_ACCENT_ARROW) //→ -#define MB_ACCENT_BAR QChar(MB_USHORT_ACCENT_BAR) //ā -#define MB_ACCENT_BREVE QChar(MB_USHORT_ACCENT_BREVE) //ă -#define MB_ACCENT_DOT QChar(MB_USHORT_ACCENT_DOT) //ȧ -#define MB_ACCENT_DOUBLE_DOTS QChar(MB_USHORT_ACCENT_DOUBLE_DOTS) //ä -#define MB_ACCENT_TRIPLE_DOTS QChar(MB_USHORT_ACCENT_TRIPLE_DOTS) //⋯ -#define MB_ACCENT_HAT QChar(MB_USHORT_ACCENT_HAT) //â -#define MB_ACCENT_TILDE QChar(MB_USHORT_ACCENT_TILDE) //ã -#define MB_SUMMATION QChar(MB_USHORT_SUMMATION) //∑ -#define MB_PRODUCT QChar(MB_USHORT_PRODUCT) //∏ -#define MB_COPRODUCT QChar(MB_USHORT_COPRODUCT) //∐ -#define MB_INTERSECTION QChar(MB_USHORT_INTERSECTION) //⋂ -#define MB_UNION QChar(MB_USHORT_UNION) //⋃ -#define MB_UNION_PLUS QChar(MB_USHORT_UNION_PLUS) //⨄ -#define MB_BINOMIAL_COEFFICIENTS QChar(MB_USHORT_BINOMIAL_COEFFICIENTS) //b -#define MB_CASES QChar(MB_USHORT_CASES) //c -#define MB_FRACTION QChar(MB_USHORT_FRACTION) //f -#define MB_GROUPING_PARENTHESIS QChar(MB_USHORT_GROUPING_PARENTHESIS) //( -#define MB_GROUPING_BRACKETS QChar(MB_USHORT_GROUPING_BRACKETS) //[ -#define MB_GROUPING_CEIL QChar(MB_USHORT_GROUPING_CEIL) //⌈ -#define MB_GROUPING_FLOOR QChar(MB_USHORT_GROUPING_FLOOR) //⌊ -#define MB_GROUPING_BARS QChar(MB_USHORT_GROUPING_BARS) //| -#define MB_GROUPING_DOUBLE_BARS QChar(MB_USHORT_GROUPING_DOUBLE_BARS) //‖ -#define MB_INTEGRAL QChar(MB_USHORT_INTEGRAL) //∫ -#define MB_DOUBLE_INTEGRAL QChar(MB_USHORT_DOUBLE_INTEGRAL) //∬ -#define MB_TRIPLE_INTEGRAL QChar(MB_USHORT_TRIPLE_INTEGRAL) //∭ -#define MB_CONTOUR_INTEGRAL QChar(MB_USHORT_CONTOUR_INTEGRAL) //∮ -#define MB_CLOSED_SURFACE_INTEGRAL QChar(MB_USHORT_CLOSED_SURFACE_INTEGRAL) //∯ -#define MB_CLOSED_VOLUME_INTEGRAL QChar(MB_USHORT_CLOSED_VOLUME_INTEGRAL) //∰ -#define MB_MATRIX QChar(MB_USHORT_MATRIX) //⊞ -#define MB_ROOT QChar(MB_USHORT_ROOT) //√ -#define MB_SUBSCRIPT QChar(MB_USHORT_SUBSCRIPT) //_ -#define MB_SUPERSCRIPT QChar(MB_USHORT_SUPERSCRIPT) //^ -#define MB_DUALSCRIPT QChar(MB_USHORT_DUALSCRIPT) //Δ -#define MB_EVALSCRIPT QChar(MB_USHORT_EVALSCRIPT) //┊ -#define MB_LIMIT QChar(MB_USHORT_LIMIT) //l -#define MB_UNDERSCRIPTED_MAX QChar(MB_USHORT_UNDERSCRIPTED_MAX) //↑ -#define MB_UNDERSCRIPTED_MIN QChar(MB_USHORT_UNDERSCRIPTED_MIN) //↓ -#define MB_UNDERSCRIPTED_SUP QChar(MB_USHORT_UNDERSCRIPTED_SUP) //↗ -#define MB_UNDERSCRIPTED_INF QChar(MB_USHORT_UNDERSCRIPTED_INF) //↘ - -#define MB_ESCAPED_CONSTRUCT_SYMBOL "⁜⁜" -#define MB_ESCAPED_OPEN "⁜⏴" -#define MB_ESCAPED_CLOSE "⁜⏵" - -#endif +//CODE-GEN FILE +//This file defines macros to make use of the MathBran serialization format. +//The list of definitions is generated from a spreadsheet in the MathBran project. + +#ifndef QMATHBRAN_MACROS +#define QMATHBRAN_MACROS + +#define MB_USHORT_CONSTRUCT_SYMBOL 8284 //⁜ +#define MB_USHORT_OPEN 9204 //⏴ +#define MB_USHORT_CLOSE 9205 //⏵ +#define MB_USHORT_ACCENT_ARROW 8594 //→ +#define MB_USHORT_ACCENT_BAR 257 //ā +#define MB_USHORT_ACCENT_BREVE 259 //ă +#define MB_USHORT_ACCENT_DOT 551 //ȧ +#define MB_USHORT_ACCENT_DOUBLE_DOTS 228 //ä +#define MB_USHORT_ACCENT_TRIPLE_DOTS 8943 //⋯ +#define MB_USHORT_ACCENT_HAT 226 //â +#define MB_USHORT_ACCENT_TILDE 227 //ã +#define MB_USHORT_SUMMATION 8721 //∑ +#define MB_USHORT_PRODUCT 8719 //∏ +#define MB_USHORT_COPRODUCT 8720 //∐ +#define MB_USHORT_INTERSECTION 8898 //⋂ +#define MB_USHORT_UNION 8899 //⋃ +#define MB_USHORT_UNION_PLUS 10756 //⨄ +#define MB_USHORT_BINOMIAL_COEFFICIENTS 98 //b +#define MB_USHORT_CASES 99 //c +#define MB_USHORT_FRACTION 102 //f +#define MB_USHORT_GROUPING_PARENTHESIS 40 //( +#define MB_USHORT_GROUPING_BRACKETS 91 //[ +#define MB_USHORT_GROUPING_CEIL 8968 //⌈ +#define MB_USHORT_GROUPING_FLOOR 8970 //⌊ +#define MB_USHORT_GROUPING_BARS 124 //| +#define MB_USHORT_GROUPING_DOUBLE_BARS 8214 //‖ +#define MB_USHORT_INTEGRAL 8747 //∫ +#define MB_USHORT_DOUBLE_INTEGRAL 8748 //∬ +#define MB_USHORT_TRIPLE_INTEGRAL 8749 //∭ +#define MB_USHORT_CONTOUR_INTEGRAL 8750 //∮ +#define MB_USHORT_CLOSED_SURFACE_INTEGRAL 8751 //∯ +#define MB_USHORT_CLOSED_VOLUME_INTEGRAL 8752 //∰ +#define MB_USHORT_MATRIX 8862 //⊞ +#define MB_USHORT_ROOT 8730 //√ +#define MB_USHORT_SUBSCRIPT 95 //_ +#define MB_USHORT_SUPERSCRIPT 94 //^ +#define MB_USHORT_DUALSCRIPT 916 //Δ +#define MB_USHORT_EVALSCRIPT 9482 //┊ +#define MB_USHORT_LIMIT 108 //l +#define MB_USHORT_UNDERSCRIPTED_MAX 8593 //↑ +#define MB_USHORT_UNDERSCRIPTED_MIN 8595 //↓ +#define MB_USHORT_UNDERSCRIPTED_SUP 8599 //↗ +#define MB_USHORT_UNDERSCRIPTED_INF 8600 //↘ + +#define MB_CONSTRUCT_SYMBOL QChar(MB_USHORT_CONSTRUCT_SYMBOL) //⁜ +#define MB_OPEN QChar(MB_USHORT_OPEN) //⏴ +#define MB_CLOSE QChar(MB_USHORT_CLOSE) //⏵ +#define MB_ACCENT_ARROW QChar(MB_USHORT_ACCENT_ARROW) //→ +#define MB_ACCENT_BAR QChar(MB_USHORT_ACCENT_BAR) //ā +#define MB_ACCENT_BREVE QChar(MB_USHORT_ACCENT_BREVE) //ă +#define MB_ACCENT_DOT QChar(MB_USHORT_ACCENT_DOT) //ȧ +#define MB_ACCENT_DOUBLE_DOTS QChar(MB_USHORT_ACCENT_DOUBLE_DOTS) //ä +#define MB_ACCENT_TRIPLE_DOTS QChar(MB_USHORT_ACCENT_TRIPLE_DOTS) //⋯ +#define MB_ACCENT_HAT QChar(MB_USHORT_ACCENT_HAT) //â +#define MB_ACCENT_TILDE QChar(MB_USHORT_ACCENT_TILDE) //ã +#define MB_SUMMATION QChar(MB_USHORT_SUMMATION) //∑ +#define MB_PRODUCT QChar(MB_USHORT_PRODUCT) //∏ +#define MB_COPRODUCT QChar(MB_USHORT_COPRODUCT) //∐ +#define MB_INTERSECTION QChar(MB_USHORT_INTERSECTION) //⋂ +#define MB_UNION QChar(MB_USHORT_UNION) //⋃ +#define MB_UNION_PLUS QChar(MB_USHORT_UNION_PLUS) //⨄ +#define MB_BINOMIAL_COEFFICIENTS QChar(MB_USHORT_BINOMIAL_COEFFICIENTS) //b +#define MB_CASES QChar(MB_USHORT_CASES) //c +#define MB_FRACTION QChar(MB_USHORT_FRACTION) //f +#define MB_GROUPING_PARENTHESIS QChar(MB_USHORT_GROUPING_PARENTHESIS) //( +#define MB_GROUPING_BRACKETS QChar(MB_USHORT_GROUPING_BRACKETS) //[ +#define MB_GROUPING_CEIL QChar(MB_USHORT_GROUPING_CEIL) //⌈ +#define MB_GROUPING_FLOOR QChar(MB_USHORT_GROUPING_FLOOR) //⌊ +#define MB_GROUPING_BARS QChar(MB_USHORT_GROUPING_BARS) //| +#define MB_GROUPING_DOUBLE_BARS QChar(MB_USHORT_GROUPING_DOUBLE_BARS) //‖ +#define MB_INTEGRAL QChar(MB_USHORT_INTEGRAL) //∫ +#define MB_DOUBLE_INTEGRAL QChar(MB_USHORT_DOUBLE_INTEGRAL) //∬ +#define MB_TRIPLE_INTEGRAL QChar(MB_USHORT_TRIPLE_INTEGRAL) //∭ +#define MB_CONTOUR_INTEGRAL QChar(MB_USHORT_CONTOUR_INTEGRAL) //∮ +#define MB_CLOSED_SURFACE_INTEGRAL QChar(MB_USHORT_CLOSED_SURFACE_INTEGRAL) //∯ +#define MB_CLOSED_VOLUME_INTEGRAL QChar(MB_USHORT_CLOSED_VOLUME_INTEGRAL) //∰ +#define MB_MATRIX QChar(MB_USHORT_MATRIX) //⊞ +#define MB_ROOT QChar(MB_USHORT_ROOT) //√ +#define MB_SUBSCRIPT QChar(MB_USHORT_SUBSCRIPT) //_ +#define MB_SUPERSCRIPT QChar(MB_USHORT_SUPERSCRIPT) //^ +#define MB_DUALSCRIPT QChar(MB_USHORT_DUALSCRIPT) //Δ +#define MB_EVALSCRIPT QChar(MB_USHORT_EVALSCRIPT) //┊ +#define MB_LIMIT QChar(MB_USHORT_LIMIT) //l +#define MB_UNDERSCRIPTED_MAX QChar(MB_USHORT_UNDERSCRIPTED_MAX) //↑ +#define MB_UNDERSCRIPTED_MIN QChar(MB_USHORT_UNDERSCRIPTED_MIN) //↓ +#define MB_UNDERSCRIPTED_SUP QChar(MB_USHORT_UNDERSCRIPTED_SUP) //↗ +#define MB_UNDERSCRIPTED_INF QChar(MB_USHORT_UNDERSCRIPTED_INF) //↘ + +#define MB_ESCAPED_CONSTRUCT_SYMBOL "⁜⁜" +#define MB_ESCAPED_OPEN "⁜⏴" +#define MB_ESCAPED_CLOSE "⁜⏵" + +#endif diff --git a/include/YAWYSIWYGEE_keywords.h b/include/YAWYSIWYGEE_keywords.h index a217f878..89532168 100644 --- a/include/YAWYSIWYGEE_keywords.h +++ b/include/YAWYSIWYGEE_keywords.h @@ -1,553 +1,553 @@ -//CODE-GEN FILE -//This file is generated from subfolder "meta". -//Changes to this file must be made in the meta project. - -#define YAWYSIWYGEE_KEYWORDS {\ - { "0" , "𝟘" },\ - { "1" , "𝟙" },\ - { "2" , "𝟚" },\ - { "3" , "𝟛" },\ - { "4" , "𝟜" },\ - { "5" , "𝟝" },\ - { "6" , "𝟞" },\ - { "7" , "𝟟" },\ - { "8" , "𝟠" },\ - { "9" , "𝟡" },\ - { "|" , "‖" },\ - { "adots" , "⋰" },\ - { "aleph" , "ℵ" },\ - { "alpha" , "α" },\ - { "Alpha" , "Α" },\ - { "angle" , "∠" },\ - { "approx" , "≈" },\ - { "ast" , "∗" },\ - { "B" , "𝔹" },\ - { "bagmember" , "⋿" },\ - { "because" , "∵" },\ - { "beta" , "β" },\ - { "Beta" , "Β" },\ - { "beth" , "ℶ" },\ - { "bot" , "⊥" },\ - { "bowtie" , "⋈" },\ - { "box" , "□" },\ - { "bumpeq" , "≏" },\ - { "C" , "ℂ" },\ - { "cap" , "∩" },\ - { "cdot" , "⋅" },\ - { "cdots" , "⋯" },\ - { "cent" , "¢" },\ - { "ceqdef" , "≔" },\ - { "checkmark" , "✓" },\ - { "chi" , "χ" },\ - { "Chi" , "Χ" },\ - { "circ" , "∘" },\ - { "Colon" , "∷" },\ - { "complement" , "∁" },\ - { "cong" , "≅" },\ - { "copyright" , "©" },\ - { "cup" , "∪" },\ - { "cupdot" , "⊍" },\ - { "d" , "ⅆ" },\ - { "D" , "𝔻" },\ - { "dagger" , "†" },\ - { "daleth" , "ℸ " },\ - { "ddagger" , "‡" },\ - { "ddots" , "⋱" },\ - { "delta" , "δ" },\ - { "Delta" , "Δ" },\ - { "diameter" , "⌀" },\ - { "digamma" , "ϝ" },\ - { "Digamma" , "Ϝ" },\ - { "div" , "÷" },\ - { "doteq" , "≐" },\ - { "downarrow" , "↓" },\ - { "e" , "ℯ" },\ - { "E" , "𝔼" },\ - { "eightnote" , "♪" },\ - { "emptyset" , "∅" },\ - { "epsilon" , "ϵ" },\ - { "Epsilon" , "Ε" },\ - { "eqcolon" , "∹" },\ - { "eqdef" , "≝" },\ - { "equiv" , "≡" },\ - { "Equiv" , "≣" },\ - { "errbar" , "⧮" },\ - { "eta" , "η" },\ - { "Eta" , "Η" },\ - { "Euler" , "ℇ" },\ - { "euro" , "€" },\ - { "Exclam" , "‼" },\ - { "exists" , "∃" },\ - { "F" , "𝔽" },\ - { "flat" , "♭" },\ - { "forall" , "∀" },\ - { "fourth" , "⁗" },\ - { "frownie" , "☹" },\ - { "gamma" , "γ" },\ - { "Gamma" , "Γ" },\ - { "geq" , "≥" },\ - { "geqq" , "≧" },\ - { "gg" , "≫" },\ - { "ggg" , "⋙" },\ - { "gimel" , "ℷ " },\ - { "H" , "ℍ" },\ - { "ham" , "ℋ" },\ - { "Im" , "ℑ" },\ - { "imath" , "ⅈ" },\ - { "implies" , "⇒" },\ - { "in" , "∈" },\ - { "incr" , "∆" },\ - { "infty" , "∞" },\ - { "iota" , "ι" },\ - { "Iota" , "Ι" },\ - { "J" , "𝕁" },\ - { "jmath" , "ⅉ" },\ - { "kappa" , "κ" },\ - { "Kappa" , "Κ" },\ - { "lag" , "ℒ" },\ - { "lambda" , "λ" },\ - { "Lambda" , "Λ" },\ - { "land" , "∧" },\ - { "langle" , "⟨" },\ - { "lceil" , "⌈" },\ - { "leftarrow" , "←" },\ - { "Leftarrow" , "⇐" },\ - { "leftrightarrow" , "↔" },\ - { "Leftrightarrow" , "⇔" },\ - { "leq" , "≤" },\ - { "leqq" , "≦" },\ - { "lfloor" , "⌊" },\ - { "ll" , "≪" },\ - { "llangle" , "⟪" },\ - { "llbracket" , "⟦" },\ - { "lll" , "⋘" },\ - { "lor" , "∨" },\ - { "ltimes" , "⋉" },\ - { "maltese" , "✠" },\ - { "mapsto" , "↦" },\ - { "mathsterling" , "£" },\ - { "mathyen" , "¥" },\ - { "measuredangle" , "∡" },\ - { "mho" , "℧" },\ - { "mp" , "∓" },\ - { "mu" , "μ" },\ - { "Mu" , "Μ" },\ - { "N" , "ℕ" },\ - { "nabla" , "∇" },\ - { "napprox" , "≉" },\ - { "natural" , "♮" },\ - { "ncong" , "≇ " },\ - { "ne" , "≠" },\ - { "neg" , "¬" },\ - { "neq" , "≠" },\ - { "nequiv" , "≢" },\ - { "nexists" , "∄" },\ - { "ngtr" , "≯" },\ - { "ni" , "∋" },\ - { "nless" , "≮" },\ - { "nmid" , "∤" },\ - { "nni" , "∌" },\ - { "notin" , "∉" },\ - { "nsubset" , "⊄" },\ - { "nsubseteq" , "⊈" },\ - { "nsupset" , "⊅" },\ - { "nsupseteq" , "⊉" },\ - { "nu" , "ν" },\ - { "Nu" , "Ν" },\ - { "O" , "𝕆" },\ - { "odot" , "⨀" },\ - { "omega" , "ω" },\ - { "Omega" , "Ω" },\ - { "omicron" , "ο" },\ - { "Omicron" , "Ο" },\ - { "ominus" , "⊖" },\ - { "oplus" , "⊕" },\ - { "oslash" , "⊘" },\ - { "otimes" , "⊗" },\ - { "P" , "ℙ" },\ - { "partial" , "∂" },\ - { "perp" , "⊥" },\ - { "phi" , "ϕ" },\ - { "Phi" , "Φ" },\ - { "pi" , "π" },\ - { "Pi" , "Π" },\ - { "Planckconst" , "ℎ" },\ - { "pm" , "±" },\ - { "prec" , "≺" },\ - { "prime" , "′" },\ - { "propto" , "∝" },\ - { "psi" , "ψ" },\ - { "Psi" , "Ψ" },\ - { "Q" , "ℚ" },\ - { "QED" , "■" },\ - { "qoppa" , "ϙ" },\ - { "Qoppa" , "Ϙ" },\ - { "quarternote" , "♩" },\ - { "questeq" , "≟" },\ - { "R" , "ℝ" },\ - { "rangle" , "⟩" },\ - { "rceil" , "⌉" },\ - { "Re" , "ℜ" },\ - { "registered" , "®" },\ - { "rfloor" , "⌋" },\ - { "rho" , "ρ" },\ - { "Rho" , "Ρ" },\ - { "rightangle" , "∟" },\ - { "rightarrow" , "→" },\ - { "Rightarrow" , "⇒" },\ - { "rightleftarrows" , "⇄" },\ - { "rrangle" , "⟫" },\ - { "rrbracket" , "⟧" },\ - { "rtimes" , "⋊" },\ - { "S" , "𝕊" },\ - { "second" , "″" },\ - { "sharp" , "♯" },\ - { "shuffle" , "⧢" },\ - { "sigma" , "σ" },\ - { "Sigma" , "Σ" },\ - { "sinewave" , "∿" },\ - { "sphericalangle" , "∢" },\ - { "sqcap" , "⊓" },\ - { "sqcup" , "⊔ " },\ - { "sqsubset" , "⊏ " },\ - { "sqsubseteq" , "⊑" },\ - { "sqsupset" , "⊐" },\ - { "sqsupseteq" , "⊒" },\ - { "subset" , "⊂" },\ - { "Subset" , "⋐ " },\ - { "subsetcirc" , "⟃" },\ - { "subseteq" , "⊆" },\ - { "succ" , "≻" },\ - { "supset" , "⊃" },\ - { "supsetcirc" , "⟄" },\ - { "supseteq" , "⊇" },\ - { "T" , "𝕋" },\ - { "tau" , "τ" },\ - { "Tau" , "Τ" },\ - { "therefore" , "∴" },\ - { "thermod" , "⧧" },\ - { "theta" , "θ" },\ - { "Theta" , "Θ" },\ - { "third" , "‴" },\ - { "times" , "×" },\ - { "to" , "→" },\ - { "top" , "⊤" },\ - { "triangleleft" , "◅" },\ - { "triangleq" , "≜" },\ - { "triangleright" , "▻" },\ - { "twonotes" , "♫" },\ - { "U" , "𝕌" },\ - { "uparrow" , "↑" },\ - { "updownarrow" , "↕" },\ - { "uplus" , "⊎" },\ - { "upsilon" , "υ" },\ - { "Upsilon" , "Υ" },\ - { "varepsilon" , "ε" },\ - { "varkappa" , "ϰ" },\ - { "varphi" , "φ" },\ - { "varpi" , "ϖ" },\ - { "varrho" , "ϱ" },\ - { "varsigma" , "ς" },\ - { "vartheta" , "ϑ" },\ - { "varTheta" , "ϴ" },\ - { "vdash" , "⊢" },\ - { "vDash" , "⊧" },\ - { "vdots" , "⋮" },\ - { "vee" , "∨" },\ - { "veebar" , "⊻" },\ - { "warning" , "⚠" },\ - { "wedge" , "∧" },\ - { "wp" , "℘" },\ - { "wr" , "≀" },\ - { "xi" , "ξ" },\ - { "Xi" , "Ξ" },\ - { "Z" , "ℤ" },\ - { "Zbar" , "Ƶ" },\ - { "zeta" , "ζ" },\ - { "Zeta" , "Ζ" },\ -} - -#define YAWYSIWYGEE_NUM_KEYWORDS 262 - -#include - -namespace Keywords { - -QString lookup(const QString& key){ - if(key.isEmpty()) return QString(); - - uint8_t n = 0; - for(QChar c : key) n += static_cast(c.unicode()); - - uint32_t hash = static_cast(key.size()) + - static_cast(key.front().unicode()) + - (key.size()>1 ? (static_cast(key[1].unicode()) << 11) : 0) + - (static_cast(n) << 18); - switch(hash){ - case 12583681: return key=="0" ? "𝟘" : QString(); - case 12845841: return key=="1" ? "𝟙" : QString(); - case 13108001: return key=="2" ? "𝟚" : QString(); - case 13370161: return key=="3" ? "𝟛" : QString(); - case 13632321: return key=="4" ? "𝟜" : QString(); - case 13894481: return key=="5" ? "𝟝" : QString(); - case 14156641: return key=="6" ? "𝟞" : QString(); - case 14418801: return key=="7" ? "𝟟" : QString(); - case 14680961: return key=="8" ? "𝟠" : QString(); - case 14943121: return key=="9" ? "𝟡" : QString(); - case 32507841: return key=="|" ? "‖" : QString(); - case 7284245: return key=="adots" ? "⋰" : QString(); - case 2844181: return key=="aleph" ? "ℵ" : QString(); - case 1795605: return key=="alpha" ? "α" : QString(); - case 60515349: return key=="Alpha" ? "Α" : QString(); - case 2061845: return key=="angle" ? "∠" : QString(); - case 40601110: return key=="approx" ? "≈" : QString(); - case 19111443: return key=="ast" ? "∗" : QString(); - case 17302561: return key=="B" ? "𝔹" : QString(); - case 42667561: return key=="bagmember" ? "⋿" : QString(); - case 56831527: return key=="because" ? "∵" : QString(); - case 41102884: return key=="beta" ? "β" : QString(); - case 32713764: return key=="Beta" ? "Β" : QString(); - case 42937892: return key=="beth" ? "ℶ" : QString(); - case 18316835: return key=="bot" ? "⊥" : QString(); - case 36404774: return key=="bowtie" ? "⋈" : QString(); - case 19365411: return key=="box" ? "□" : QString(); - case 36417062: return key=="bumpeq" ? "≏" : QString(); - case 17564721: return key=="C" ? "ℂ" : QString(); - case 13831731: return key=="cap" ? "∩" : QString(); - case 44770868: return key=="cdot" ? "⋅" : QString(); - case 7808565: return key=="cdots" ? "⋯" : QString(); - case 44772916: return key=="cent" ? "¢" : QString(); - case 27471414: return key=="ceqdef" ? "≔" : QString(); - case 44516921: return key=="checkmark" ? "✓" : QString(); - case 13846067: return key=="chi" ? "χ" : QString(); - case 5456947: return key=="Chi" ? "Χ" : QString(); - case 42421812: return key=="circ" ? "∘" : QString(); - case 66026549: return key=="Colon" ? "∷" : QString(); - case 13860410: return key=="complement" ? "∁" : QString(); - case 44006964: return key=="cong" ? "≅" : QString(); - case 57114169: return key=="copyright" ? "©" : QString(); - case 19115571: return key=="cup" ? "∪" : QString(); - case 37727798: return key=="cupdot" ? "⊍" : QString(); - case 26216001: return key=="d" ? "ⅆ" : QString(); - case 17826881: return key=="D" ? "𝔻" : QString(); - case 27987526: return key=="dagger" ? "†" : QString(); - case 30084678: return key=="daleth" ? "ℸ " : QString(); - case 54208071: return key=="ddagger" ? "‡" : QString(); - case 8070725: return key=="ddots" ? "⋱" : QString(); - case 2829893: return key=="delta" ? "δ" : QString(); - case 61549637: return key=="Delta" ? "Δ" : QString(); - case 19877448: return key=="diameter" ? "⌀" : QString(); - case 54742599: return key=="digamma" ? "ϝ" : QString(); - case 46353479: return key=="Digamma" ? "Ϝ" : QString(); - case 17780291: return key=="div" ? "÷" : QString(); - case 7831109: return key=="doteq" ? "≐" : QString(); - case 59735625: return key=="downarrow" ? "↓" : QString(); - case 26478161: return key=="e" ? "ℯ" : QString(); - case 18089041: return key=="E" ? "𝔼" : QString(); - case 52383321: return key=="eightnote" ? "♪" : QString(); - case 32468568: return key=="emptyset" ? "∅" : QString(); - case 65766999: return key=="epsilon" ? "ϵ" : QString(); - case 57377879: return key=="Epsilon" ? "Ε" : QString(); - case 63409751: return key=="eqcolon" ? "∹" : QString(); - case 1543765: return key=="eqdef" ? "≝" : QString(); - case 11243093: return key=="equiv" ? "≡" : QString(); - case 2853973: return key=="Equiv" ? "≣" : QString(); - case 33265238: return key=="errbar" ? "⧮" : QString(); - case 15443539: return key=="eta" ? "η" : QString(); - case 7054419: return key=="Eta" ? "Η" : QString(); - case 66563157: return key=="Euler" ? "ℇ" : QString(); - case 49262164: return key=="euro" ? "€" : QString(); - case 23839830: return key=="Exclam" ? "‼" : QString(); - case 42190422: return key=="exists" ? "∃" : QString(); - case 18351201: return key=="F" ? "𝔽" : QString(); - case 44000868: return key=="flat" ? "♭" : QString(); - case 33783398: return key=="forall" ? "∀" : QString(); - case 40074854: return key=="fourth" ? "⁗" : QString(); - case 65771111: return key=="frownie" ? "☹" : QString(); - case 986741: return key=="gamma" ? "γ" : QString(); - case 59706485: return key=="Gamma" ? "Γ" : QString(); - case 16199283: return key=="geq" ? "≥" : QString(); - case 45821556: return key=="geqq" ? "≧" : QString(); - case 54214258: return key=="gg" ? "≫" : QString(); - case 14106227: return key=="ggg" ? "⋙" : QString(); - case 3886709: return key=="gimel" ? "ℷ " : QString(); - case 18875521: return key=="H" ? "ℍ" : QString(); - case 14356099: return key=="ham" ? "ℋ" : QString(); - case 47934610: return key=="Im" ? "ℑ" : QString(); - case 5205653: return key=="imath" ? "ⅈ" : QString(); - case 63925911: return key=="implies" ? "⇒" : QString(); - case 56587922: return key=="in" ? "∈" : QString(); - case 45315732: return key=="incr" ? "∆" : QString(); - case 11237013: return key=="infty" ? "∞" : QString(); - case 45579924: return key=="iota" ? "ι" : QString(); - case 37190804: return key=="Iota" ? "Ι" : QString(); - case 19399841: return key=="J" ? "𝕁" : QString(); - case 5467813: return key=="jmath" ? "ⅉ" : QString(); - case 3608245: return key=="kappa" ? "κ" : QString(); - case 62327989: return key=="Kappa" ? "Κ" : QString(); - case 13831875: return key=="lag" ? "ℒ" : QString(); - case 25628358: return key=="lambda" ? "λ" : QString(); - case 17239238: return key=="Lambda" ? "Λ" : QString(); - case 41881284: return key=="land" ? "∧" : QString(); - case 30346950: return key=="langle" ? "⟨" : QString(); - case 2563781: return key=="lceil" ? "⌈" : QString(); - case 56307401: return key=="leftarrow" ? "←" : QString(); - case 47918281: return key=="Leftarrow" ? "⇐" : QString(); - case 64171726: return key=="leftrightarrow" ? "↔" : QString(); - case 55782606: return key=="Leftrightarrow" ? "⇔" : QString(); - case 17510083: return key=="leq" ? "≤" : QString(); - case 47132356: return key=="leqq" ? "≦" : QString(); - case 37435078: return key=="lfloor" ? "⌊" : QString(); - case 56846018: return key=="ll" ? "≪" : QString(); - case 58681031: return key=="llangle" ? "⟪" : QString(); - case 47408841: return key=="llbracket" ? "⟦" : QString(); - case 18048707: return key=="lll" ? "⋘" : QString(); - case 20414147: return key=="lor" ? "∨" : QString(); - case 37463750: return key=="ltimes" ? "⋉" : QString(); - case 61804247: return key=="maltese" ? "✠" : QString(); - case 38997718: return key=="mapsto" ? "↦" : QString(); - case 4919004: return key=="mathsterling" ? "£" : QString(); - case 64687831: return key=="mathyen" ? "¥" : QString(); - case 24587997: return key=="measuredangle" ? "∡" : QString(); - case 18040531: return key=="mho" ? "℧" : QString(); - case 58164946: return key=="mp" ? "∓" : QString(); - case 59485906: return key=="mu" ? "μ" : QString(); - case 51096786: return key=="Mu" ? "Μ" : QString(); - case 20448481: return key=="N" ? "ℕ" : QString(); - case 66784997: return key=="nabla" ? "∇" : QString(); - case 2297575: return key=="napprox" ? "≉" : QString(); - case 64949991: return key=="natural" ? "♮" : QString(); - case 5709541: return key=="ncong" ? "≇ " : QString(); - case 55520994: return key=="ne" ? "≠" : QString(); - case 15412963: return key=="neg" ? "¬" : QString(); - case 18034403: return key=="neq" ? "≠" : QString(); - case 40054502: return key=="nequiv" ? "≢" : QString(); - case 3878631: return key=="nexists" ? "∄" : QString(); - case 49233636: return key=="ngtr" ? "≯" : QString(); - case 56577762: return key=="ni" ? "∋" : QString(); - case 9922277: return key=="nless" ? "≮" : QString(); - case 44265188: return key=="nmid" ? "∤" : QString(); - case 18314979: return key=="nni" ? "∌" : QString(); - case 10714853: return key=="notin" ? "∉" : QString(); - case 1285863: return key=="nsubset" ? "⊄" : QString(); - case 57384681: return key=="nsubseteq" ? "⊈" : QString(); - case 4955879: return key=="nsupset" ? "⊅" : QString(); - case 61054697: return key=="nsupseteq" ? "⊉" : QString(); - case 59748066: return key=="nu" ? "ν" : QString(); - case 51358946: return key=="Nu" ? "Ν" : QString(); - case 20710641: return key=="O" ? "𝕆" : QString(); - case 47916788: return key=="odot" ? "⨀" : QString(); - case 2584309: return key=="omega" ? "ω" : QString(); - case 61304053: return key=="Omega" ? "Ω" : QString(); - case 64974583: return key=="omicron" ? "ο" : QString(); - case 56585463: return key=="Omicron" ? "Ο" : QString(); - case 40857334: return key=="ominus" ? "⊖" : QString(); - case 13600501: return key=="oplus" ? "⊕" : QString(); - case 36413174: return key=="oslash" ? "⊘" : QString(); - case 38250230: return key=="otimes" ? "⊗" : QString(); - case 20972801: return key=="P" ? "ℙ" : QString(); - case 62328583: return key=="partial" ? "∂" : QString(); - case 48180996: return key=="perp" ? "⊥" : QString(); - case 17254147: return key=="phi" ? "ϕ" : QString(); - case 8865027: return key=="Phi" ? "Φ" : QString(); - case 57102082: return key=="pi" ? "π" : QString(); - case 48712962: return key=="Pi" ? "Π" : QString(); - case 33776907: return key=="Planckconst" ? "ℎ" : QString(); - case 58158850: return key=="pm" ? "±" : QString(); - case 44799748: return key=="prec" ? "≺" : QString(); - case 7837445: return key=="prime" ? "′" : QString(); - case 43226886: return key=="propto" ? "∝" : QString(); - case 20160259: return key=="psi" ? "ψ" : QString(); - case 11771139: return key=="Psi" ? "Ψ" : QString(); - case 21234961: return key=="Q" ? "ℚ" : QString(); - case 57290003: return key=="QED" ? "■" : QString(); - case 8879893: return key=="qoppa" ? "ϙ" : QString(); - case 490773: return key=="Qoppa" ? "Ϙ" : QString(); - case 49000219: return key=="quarternote" ? "♩" : QString(); - case 2338583: return key=="questeq" ? "≟" : QString(); - case 21497121: return key=="R" ? "ℝ" : QString(); - case 31919910: return key=="rangle" ? "⟩" : QString(); - case 4136741: return key=="rceil" ? "⌉" : QString(); - case 48180514: return key=="Re" ? "ℜ" : QString(); - case 12267306: return key=="registered" ? "®" : QString(); - case 39008038: return key=="rfloor" ? "⌋" : QString(); - case 19351331: return key=="rho" ? "ρ" : QString(); - case 10962211: return key=="Rho" ? "Ρ" : QString(); - case 9916202: return key=="rightangle" ? "∟" : QString(); - case 19353386: return key=="rightarrow" ? "→" : QString(); - case 10964266: return key=="Rightarrow" ? "⇒" : QString(); - case 27217711: return key=="rightleftarrows" ? "⇄" : QString(); - case 61839143: return key=="rrangle" ? "⟫" : QString(); - case 50566953: return key=="rrbracket" ? "⟧" : QString(); - case 39036710: return key=="rtimes" ? "⋊" : QString(); - case 21759281: return key=="S" ? "𝕊" : QString(); - case 32714550: return key=="second" ? "″" : QString(); - case 8079157: return key=="sharp" ? "♯" : QString(); - case 62342967: return key=="shuffle" ? "⧢" : QString(); - case 4673333: return key=="sigma" ? "σ" : QString(); - case 63393077: return key=="Sigma" ? "Σ" : QString(); - case 25907000: return key=="sinewave" ? "∿" : QString(); - case 51087166: return key=="sphericalangle" ? "∢" : QString(); - case 6524725: return key=="sqcap" ? "⊓" : QString(); - case 11767605: return key=="sqcup" ? "⊔ " : QString(); - case 32214840: return key=="sqsubset" ? "⊏ " : QString(); - case 21204794: return key=="sqsubseteq" ? "⊑" : QString(); - case 35884856: return key=="sqsupset" ? "⊐" : QString(); - case 24874810: return key=="sqsupseteq" ? "⊒" : QString(); - case 39563062: return key=="subset" ? "⊂" : QString(); - case 31173942: return key=="Subset" ? "⋐ " : QString(); - case 14659386: return key=="subsetcirc" ? "⟃" : QString(); - case 28553016: return key=="subseteq" ? "⊆" : QString(); - case 45854516: return key=="succ" ? "≻" : QString(); - case 43233078: return key=="supset" ? "⊃" : QString(); - case 18329402: return key=="supsetcirc" ? "⟄" : QString(); - case 32223032: return key=="supseteq" ? "⊇" : QString(); - case 22021441: return key=="T" ? "𝕋" : QString(); - case 19599171: return key=="tau" ? "τ" : QString(); - case 11210051: return key=="Tau" ? "Τ" : QString(); - case 51595081: return key=="therefore" ? "∴" : QString(); - case 63915847: return key=="thermod" ? "⧧" : QString(); - case 5982021: return key=="theta" ? "θ" : QString(); - case 64701765: return key=="Theta" ? "Θ" : QString(); - case 7292741: return key=="third" ? "‴" : QString(); - case 9129797: return key=="times" ? "×" : QString(); - case 59735874: return key=="to" ? "→" : QString(); - case 21987139: return key=="top" ? "⊤" : QString(); - case 497484: return key=="triangleleft" ? "◅" : QString(); - case 52401993: return key=="triangleq" ? "≜" : QString(); - case 30644045: return key=="triangleright" ? "▻" : QString(); - case 34586440: return key=="twonotes" ? "♫" : QString(); - case 22283601: return key=="U" ? "𝕌" : QString(); - case 4425559: return key=="uparrow" ? "↑" : QString(); - case 52660059: return key=="updownarrow" ? "↕" : QString(); - case 15173461: return key=="uplus" ? "⊎" : QString(); - case 2852695: return key=="upsilon" ? "υ" : QString(); - case 61572439: return key=="Upsilon" ? "Υ" : QString(); - case 17764202: return key=="varepsilon" ? "ε" : QString(); - case 22744936: return key=="varkappa" ? "ϰ" : QString(); - case 36376422: return key=="varphi" ? "φ" : QString(); - case 9113445: return key=="varpi" ? "ϖ" : QString(); - case 38473574: return key=="varrho" ? "ϱ" : QString(); - case 23793512: return key=="varsigma" ? "ς" : QString(); - case 25104232: return key=="vartheta" ? "ϑ" : QString(); - case 16715624: return key=="varTheta" ? "ϴ" : QString(); - case 5973861: return key=="vdash" ? "⊢" : QString(); - case 64628581: return key=="vDash" ? "⊧" : QString(); - case 12789605: return key=="vdots" ? "⋮" : QString(); - case 16985955: return key=="vee" ? "∨" : QString(); - case 30879590: return key=="veebar" ? "⊻" : QString(); - case 64687991: return key=="warning" ? "⚠" : QString(); - case 3354485: return key=="wedge" ? "∧" : QString(); - case 60786546: return key=="wp" ? "℘" : QString(); - case 61314930: return key=="wr" ? "≀" : QString(); - case 59199362: return key=="xi" ? "ξ" : QString(); - case 50810242: return key=="Xi" ? "Ξ" : QString(); - case 23594401: return key=="Z" ? "ℤ" : QString(); - case 37688740: return key=="Zbar" ? "Ƶ" : QString(); - case 47394724: return key=="zeta" ? "ζ" : QString(); - case 39005604: return key=="Zeta" ? "Ζ" : QString(); - default: return QString(); - } -} - -}; +//CODE-GEN FILE +//This file is generated from subfolder "meta". +//Changes to this file must be made in the meta project. + +#define YAWYSIWYGEE_KEYWORDS {\ + { "0" , "𝟘" },\ + { "1" , "𝟙" },\ + { "2" , "𝟚" },\ + { "3" , "𝟛" },\ + { "4" , "𝟜" },\ + { "5" , "𝟝" },\ + { "6" , "𝟞" },\ + { "7" , "𝟟" },\ + { "8" , "𝟠" },\ + { "9" , "𝟡" },\ + { "|" , "‖" },\ + { "adots" , "⋰" },\ + { "aleph" , "ℵ" },\ + { "alpha" , "α" },\ + { "Alpha" , "Α" },\ + { "angle" , "∠" },\ + { "approx" , "≈" },\ + { "ast" , "∗" },\ + { "B" , "𝔹" },\ + { "bagmember" , "⋿" },\ + { "because" , "∵" },\ + { "beta" , "β" },\ + { "Beta" , "Β" },\ + { "beth" , "ℶ" },\ + { "bot" , "⊥" },\ + { "bowtie" , "⋈" },\ + { "box" , "□" },\ + { "bumpeq" , "≏" },\ + { "C" , "ℂ" },\ + { "cap" , "∩" },\ + { "cdot" , "⋅" },\ + { "cdots" , "⋯" },\ + { "cent" , "¢" },\ + { "ceqdef" , "≔" },\ + { "checkmark" , "✓" },\ + { "chi" , "χ" },\ + { "Chi" , "Χ" },\ + { "circ" , "∘" },\ + { "Colon" , "∷" },\ + { "complement" , "∁" },\ + { "cong" , "≅" },\ + { "copyright" , "©" },\ + { "cup" , "∪" },\ + { "cupdot" , "⊍" },\ + { "d" , "ⅆ" },\ + { "D" , "𝔻" },\ + { "dagger" , "†" },\ + { "daleth" , "ℸ " },\ + { "ddagger" , "‡" },\ + { "ddots" , "⋱" },\ + { "delta" , "δ" },\ + { "Delta" , "Δ" },\ + { "diameter" , "⌀" },\ + { "digamma" , "ϝ" },\ + { "Digamma" , "Ϝ" },\ + { "div" , "÷" },\ + { "doteq" , "≐" },\ + { "downarrow" , "↓" },\ + { "e" , "ℯ" },\ + { "E" , "𝔼" },\ + { "eightnote" , "♪" },\ + { "emptyset" , "∅" },\ + { "epsilon" , "ϵ" },\ + { "Epsilon" , "Ε" },\ + { "eqcolon" , "∹" },\ + { "eqdef" , "≝" },\ + { "equiv" , "≡" },\ + { "Equiv" , "≣" },\ + { "errbar" , "⧮" },\ + { "eta" , "η" },\ + { "Eta" , "Η" },\ + { "Euler" , "ℇ" },\ + { "euro" , "€" },\ + { "Exclam" , "‼" },\ + { "exists" , "∃" },\ + { "F" , "𝔽" },\ + { "flat" , "♭" },\ + { "forall" , "∀" },\ + { "fourth" , "⁗" },\ + { "frownie" , "☹" },\ + { "gamma" , "γ" },\ + { "Gamma" , "Γ" },\ + { "geq" , "≥" },\ + { "geqq" , "≧" },\ + { "gg" , "≫" },\ + { "ggg" , "⋙" },\ + { "gimel" , "ℷ " },\ + { "H" , "ℍ" },\ + { "ham" , "ℋ" },\ + { "Im" , "ℑ" },\ + { "imath" , "ⅈ" },\ + { "implies" , "⇒" },\ + { "in" , "∈" },\ + { "incr" , "∆" },\ + { "infty" , "∞" },\ + { "iota" , "ι" },\ + { "Iota" , "Ι" },\ + { "J" , "𝕁" },\ + { "jmath" , "ⅉ" },\ + { "kappa" , "κ" },\ + { "Kappa" , "Κ" },\ + { "lag" , "ℒ" },\ + { "lambda" , "λ" },\ + { "Lambda" , "Λ" },\ + { "land" , "∧" },\ + { "langle" , "⟨" },\ + { "lceil" , "⌈" },\ + { "leftarrow" , "←" },\ + { "Leftarrow" , "⇐" },\ + { "leftrightarrow" , "↔" },\ + { "Leftrightarrow" , "⇔" },\ + { "leq" , "≤" },\ + { "leqq" , "≦" },\ + { "lfloor" , "⌊" },\ + { "ll" , "≪" },\ + { "llangle" , "⟪" },\ + { "llbracket" , "⟦" },\ + { "lll" , "⋘" },\ + { "lor" , "∨" },\ + { "ltimes" , "⋉" },\ + { "maltese" , "✠" },\ + { "mapsto" , "↦" },\ + { "mathsterling" , "£" },\ + { "mathyen" , "¥" },\ + { "measuredangle" , "∡" },\ + { "mho" , "℧" },\ + { "mp" , "∓" },\ + { "mu" , "μ" },\ + { "Mu" , "Μ" },\ + { "N" , "ℕ" },\ + { "nabla" , "∇" },\ + { "napprox" , "≉" },\ + { "natural" , "♮" },\ + { "ncong" , "≇ " },\ + { "ne" , "≠" },\ + { "neg" , "¬" },\ + { "neq" , "≠" },\ + { "nequiv" , "≢" },\ + { "nexists" , "∄" },\ + { "ngtr" , "≯" },\ + { "ni" , "∋" },\ + { "nless" , "≮" },\ + { "nmid" , "∤" },\ + { "nni" , "∌" },\ + { "notin" , "∉" },\ + { "nsubset" , "⊄" },\ + { "nsubseteq" , "⊈" },\ + { "nsupset" , "⊅" },\ + { "nsupseteq" , "⊉" },\ + { "nu" , "ν" },\ + { "Nu" , "Ν" },\ + { "O" , "𝕆" },\ + { "odot" , "⨀" },\ + { "omega" , "ω" },\ + { "Omega" , "Ω" },\ + { "omicron" , "ο" },\ + { "Omicron" , "Ο" },\ + { "ominus" , "⊖" },\ + { "oplus" , "⊕" },\ + { "oslash" , "⊘" },\ + { "otimes" , "⊗" },\ + { "P" , "ℙ" },\ + { "partial" , "∂" },\ + { "perp" , "⊥" },\ + { "phi" , "ϕ" },\ + { "Phi" , "Φ" },\ + { "pi" , "π" },\ + { "Pi" , "Π" },\ + { "Planckconst" , "ℎ" },\ + { "pm" , "±" },\ + { "prec" , "≺" },\ + { "prime" , "′" },\ + { "propto" , "∝" },\ + { "psi" , "ψ" },\ + { "Psi" , "Ψ" },\ + { "Q" , "ℚ" },\ + { "QED" , "■" },\ + { "qoppa" , "ϙ" },\ + { "Qoppa" , "Ϙ" },\ + { "quarternote" , "♩" },\ + { "questeq" , "≟" },\ + { "R" , "ℝ" },\ + { "rangle" , "⟩" },\ + { "rceil" , "⌉" },\ + { "Re" , "ℜ" },\ + { "registered" , "®" },\ + { "rfloor" , "⌋" },\ + { "rho" , "ρ" },\ + { "Rho" , "Ρ" },\ + { "rightangle" , "∟" },\ + { "rightarrow" , "→" },\ + { "Rightarrow" , "⇒" },\ + { "rightleftarrows" , "⇄" },\ + { "rrangle" , "⟫" },\ + { "rrbracket" , "⟧" },\ + { "rtimes" , "⋊" },\ + { "S" , "𝕊" },\ + { "second" , "″" },\ + { "sharp" , "♯" },\ + { "shuffle" , "⧢" },\ + { "sigma" , "σ" },\ + { "Sigma" , "Σ" },\ + { "sinewave" , "∿" },\ + { "sphericalangle" , "∢" },\ + { "sqcap" , "⊓" },\ + { "sqcup" , "⊔ " },\ + { "sqsubset" , "⊏ " },\ + { "sqsubseteq" , "⊑" },\ + { "sqsupset" , "⊐" },\ + { "sqsupseteq" , "⊒" },\ + { "subset" , "⊂" },\ + { "Subset" , "⋐ " },\ + { "subsetcirc" , "⟃" },\ + { "subseteq" , "⊆" },\ + { "succ" , "≻" },\ + { "supset" , "⊃" },\ + { "supsetcirc" , "⟄" },\ + { "supseteq" , "⊇" },\ + { "T" , "𝕋" },\ + { "tau" , "τ" },\ + { "Tau" , "Τ" },\ + { "therefore" , "∴" },\ + { "thermod" , "⧧" },\ + { "theta" , "θ" },\ + { "Theta" , "Θ" },\ + { "third" , "‴" },\ + { "times" , "×" },\ + { "to" , "→" },\ + { "top" , "⊤" },\ + { "triangleleft" , "◅" },\ + { "triangleq" , "≜" },\ + { "triangleright" , "▻" },\ + { "twonotes" , "♫" },\ + { "U" , "𝕌" },\ + { "uparrow" , "↑" },\ + { "updownarrow" , "↕" },\ + { "uplus" , "⊎" },\ + { "upsilon" , "υ" },\ + { "Upsilon" , "Υ" },\ + { "varepsilon" , "ε" },\ + { "varkappa" , "ϰ" },\ + { "varphi" , "φ" },\ + { "varpi" , "ϖ" },\ + { "varrho" , "ϱ" },\ + { "varsigma" , "ς" },\ + { "vartheta" , "ϑ" },\ + { "varTheta" , "ϴ" },\ + { "vdash" , "⊢" },\ + { "vDash" , "⊧" },\ + { "vdots" , "⋮" },\ + { "vee" , "∨" },\ + { "veebar" , "⊻" },\ + { "warning" , "⚠" },\ + { "wedge" , "∧" },\ + { "wp" , "℘" },\ + { "wr" , "≀" },\ + { "xi" , "ξ" },\ + { "Xi" , "Ξ" },\ + { "Z" , "ℤ" },\ + { "Zbar" , "Ƶ" },\ + { "zeta" , "ζ" },\ + { "Zeta" , "Ζ" },\ +} + +#define YAWYSIWYGEE_NUM_KEYWORDS 262 + +#include + +namespace Keywords { + +QString lookup(const QString& key){ + if(key.isEmpty()) return QString(); + + uint8_t n = 0; + for(QChar c : key) n += static_cast(c.unicode()); + + uint32_t hash = static_cast(key.size()) + + static_cast(key.front().unicode()) + + (key.size()>1 ? (static_cast(key[1].unicode()) << 11) : 0) + + (static_cast(n) << 18); + switch(hash){ + case 12583681: return key=="0" ? "𝟘" : QString(); + case 12845841: return key=="1" ? "𝟙" : QString(); + case 13108001: return key=="2" ? "𝟚" : QString(); + case 13370161: return key=="3" ? "𝟛" : QString(); + case 13632321: return key=="4" ? "𝟜" : QString(); + case 13894481: return key=="5" ? "𝟝" : QString(); + case 14156641: return key=="6" ? "𝟞" : QString(); + case 14418801: return key=="7" ? "𝟟" : QString(); + case 14680961: return key=="8" ? "𝟠" : QString(); + case 14943121: return key=="9" ? "𝟡" : QString(); + case 32507841: return key=="|" ? "‖" : QString(); + case 7284245: return key=="adots" ? "⋰" : QString(); + case 2844181: return key=="aleph" ? "ℵ" : QString(); + case 1795605: return key=="alpha" ? "α" : QString(); + case 60515349: return key=="Alpha" ? "Α" : QString(); + case 2061845: return key=="angle" ? "∠" : QString(); + case 40601110: return key=="approx" ? "≈" : QString(); + case 19111443: return key=="ast" ? "∗" : QString(); + case 17302561: return key=="B" ? "𝔹" : QString(); + case 42667561: return key=="bagmember" ? "⋿" : QString(); + case 56831527: return key=="because" ? "∵" : QString(); + case 41102884: return key=="beta" ? "β" : QString(); + case 32713764: return key=="Beta" ? "Β" : QString(); + case 42937892: return key=="beth" ? "ℶ" : QString(); + case 18316835: return key=="bot" ? "⊥" : QString(); + case 36404774: return key=="bowtie" ? "⋈" : QString(); + case 19365411: return key=="box" ? "□" : QString(); + case 36417062: return key=="bumpeq" ? "≏" : QString(); + case 17564721: return key=="C" ? "ℂ" : QString(); + case 13831731: return key=="cap" ? "∩" : QString(); + case 44770868: return key=="cdot" ? "⋅" : QString(); + case 7808565: return key=="cdots" ? "⋯" : QString(); + case 44772916: return key=="cent" ? "¢" : QString(); + case 27471414: return key=="ceqdef" ? "≔" : QString(); + case 44516921: return key=="checkmark" ? "✓" : QString(); + case 13846067: return key=="chi" ? "χ" : QString(); + case 5456947: return key=="Chi" ? "Χ" : QString(); + case 42421812: return key=="circ" ? "∘" : QString(); + case 66026549: return key=="Colon" ? "∷" : QString(); + case 13860410: return key=="complement" ? "∁" : QString(); + case 44006964: return key=="cong" ? "≅" : QString(); + case 57114169: return key=="copyright" ? "©" : QString(); + case 19115571: return key=="cup" ? "∪" : QString(); + case 37727798: return key=="cupdot" ? "⊍" : QString(); + case 26216001: return key=="d" ? "ⅆ" : QString(); + case 17826881: return key=="D" ? "𝔻" : QString(); + case 27987526: return key=="dagger" ? "†" : QString(); + case 30084678: return key=="daleth" ? "ℸ " : QString(); + case 54208071: return key=="ddagger" ? "‡" : QString(); + case 8070725: return key=="ddots" ? "⋱" : QString(); + case 2829893: return key=="delta" ? "δ" : QString(); + case 61549637: return key=="Delta" ? "Δ" : QString(); + case 19877448: return key=="diameter" ? "⌀" : QString(); + case 54742599: return key=="digamma" ? "ϝ" : QString(); + case 46353479: return key=="Digamma" ? "Ϝ" : QString(); + case 17780291: return key=="div" ? "÷" : QString(); + case 7831109: return key=="doteq" ? "≐" : QString(); + case 59735625: return key=="downarrow" ? "↓" : QString(); + case 26478161: return key=="e" ? "ℯ" : QString(); + case 18089041: return key=="E" ? "𝔼" : QString(); + case 52383321: return key=="eightnote" ? "♪" : QString(); + case 32468568: return key=="emptyset" ? "∅" : QString(); + case 65766999: return key=="epsilon" ? "ϵ" : QString(); + case 57377879: return key=="Epsilon" ? "Ε" : QString(); + case 63409751: return key=="eqcolon" ? "∹" : QString(); + case 1543765: return key=="eqdef" ? "≝" : QString(); + case 11243093: return key=="equiv" ? "≡" : QString(); + case 2853973: return key=="Equiv" ? "≣" : QString(); + case 33265238: return key=="errbar" ? "⧮" : QString(); + case 15443539: return key=="eta" ? "η" : QString(); + case 7054419: return key=="Eta" ? "Η" : QString(); + case 66563157: return key=="Euler" ? "ℇ" : QString(); + case 49262164: return key=="euro" ? "€" : QString(); + case 23839830: return key=="Exclam" ? "‼" : QString(); + case 42190422: return key=="exists" ? "∃" : QString(); + case 18351201: return key=="F" ? "𝔽" : QString(); + case 44000868: return key=="flat" ? "♭" : QString(); + case 33783398: return key=="forall" ? "∀" : QString(); + case 40074854: return key=="fourth" ? "⁗" : QString(); + case 65771111: return key=="frownie" ? "☹" : QString(); + case 986741: return key=="gamma" ? "γ" : QString(); + case 59706485: return key=="Gamma" ? "Γ" : QString(); + case 16199283: return key=="geq" ? "≥" : QString(); + case 45821556: return key=="geqq" ? "≧" : QString(); + case 54214258: return key=="gg" ? "≫" : QString(); + case 14106227: return key=="ggg" ? "⋙" : QString(); + case 3886709: return key=="gimel" ? "ℷ " : QString(); + case 18875521: return key=="H" ? "ℍ" : QString(); + case 14356099: return key=="ham" ? "ℋ" : QString(); + case 47934610: return key=="Im" ? "ℑ" : QString(); + case 5205653: return key=="imath" ? "ⅈ" : QString(); + case 63925911: return key=="implies" ? "⇒" : QString(); + case 56587922: return key=="in" ? "∈" : QString(); + case 45315732: return key=="incr" ? "∆" : QString(); + case 11237013: return key=="infty" ? "∞" : QString(); + case 45579924: return key=="iota" ? "ι" : QString(); + case 37190804: return key=="Iota" ? "Ι" : QString(); + case 19399841: return key=="J" ? "𝕁" : QString(); + case 5467813: return key=="jmath" ? "ⅉ" : QString(); + case 3608245: return key=="kappa" ? "κ" : QString(); + case 62327989: return key=="Kappa" ? "Κ" : QString(); + case 13831875: return key=="lag" ? "ℒ" : QString(); + case 25628358: return key=="lambda" ? "λ" : QString(); + case 17239238: return key=="Lambda" ? "Λ" : QString(); + case 41881284: return key=="land" ? "∧" : QString(); + case 30346950: return key=="langle" ? "⟨" : QString(); + case 2563781: return key=="lceil" ? "⌈" : QString(); + case 56307401: return key=="leftarrow" ? "←" : QString(); + case 47918281: return key=="Leftarrow" ? "⇐" : QString(); + case 64171726: return key=="leftrightarrow" ? "↔" : QString(); + case 55782606: return key=="Leftrightarrow" ? "⇔" : QString(); + case 17510083: return key=="leq" ? "≤" : QString(); + case 47132356: return key=="leqq" ? "≦" : QString(); + case 37435078: return key=="lfloor" ? "⌊" : QString(); + case 56846018: return key=="ll" ? "≪" : QString(); + case 58681031: return key=="llangle" ? "⟪" : QString(); + case 47408841: return key=="llbracket" ? "⟦" : QString(); + case 18048707: return key=="lll" ? "⋘" : QString(); + case 20414147: return key=="lor" ? "∨" : QString(); + case 37463750: return key=="ltimes" ? "⋉" : QString(); + case 61804247: return key=="maltese" ? "✠" : QString(); + case 38997718: return key=="mapsto" ? "↦" : QString(); + case 4919004: return key=="mathsterling" ? "£" : QString(); + case 64687831: return key=="mathyen" ? "¥" : QString(); + case 24587997: return key=="measuredangle" ? "∡" : QString(); + case 18040531: return key=="mho" ? "℧" : QString(); + case 58164946: return key=="mp" ? "∓" : QString(); + case 59485906: return key=="mu" ? "μ" : QString(); + case 51096786: return key=="Mu" ? "Μ" : QString(); + case 20448481: return key=="N" ? "ℕ" : QString(); + case 66784997: return key=="nabla" ? "∇" : QString(); + case 2297575: return key=="napprox" ? "≉" : QString(); + case 64949991: return key=="natural" ? "♮" : QString(); + case 5709541: return key=="ncong" ? "≇ " : QString(); + case 55520994: return key=="ne" ? "≠" : QString(); + case 15412963: return key=="neg" ? "¬" : QString(); + case 18034403: return key=="neq" ? "≠" : QString(); + case 40054502: return key=="nequiv" ? "≢" : QString(); + case 3878631: return key=="nexists" ? "∄" : QString(); + case 49233636: return key=="ngtr" ? "≯" : QString(); + case 56577762: return key=="ni" ? "∋" : QString(); + case 9922277: return key=="nless" ? "≮" : QString(); + case 44265188: return key=="nmid" ? "∤" : QString(); + case 18314979: return key=="nni" ? "∌" : QString(); + case 10714853: return key=="notin" ? "∉" : QString(); + case 1285863: return key=="nsubset" ? "⊄" : QString(); + case 57384681: return key=="nsubseteq" ? "⊈" : QString(); + case 4955879: return key=="nsupset" ? "⊅" : QString(); + case 61054697: return key=="nsupseteq" ? "⊉" : QString(); + case 59748066: return key=="nu" ? "ν" : QString(); + case 51358946: return key=="Nu" ? "Ν" : QString(); + case 20710641: return key=="O" ? "𝕆" : QString(); + case 47916788: return key=="odot" ? "⨀" : QString(); + case 2584309: return key=="omega" ? "ω" : QString(); + case 61304053: return key=="Omega" ? "Ω" : QString(); + case 64974583: return key=="omicron" ? "ο" : QString(); + case 56585463: return key=="Omicron" ? "Ο" : QString(); + case 40857334: return key=="ominus" ? "⊖" : QString(); + case 13600501: return key=="oplus" ? "⊕" : QString(); + case 36413174: return key=="oslash" ? "⊘" : QString(); + case 38250230: return key=="otimes" ? "⊗" : QString(); + case 20972801: return key=="P" ? "ℙ" : QString(); + case 62328583: return key=="partial" ? "∂" : QString(); + case 48180996: return key=="perp" ? "⊥" : QString(); + case 17254147: return key=="phi" ? "ϕ" : QString(); + case 8865027: return key=="Phi" ? "Φ" : QString(); + case 57102082: return key=="pi" ? "π" : QString(); + case 48712962: return key=="Pi" ? "Π" : QString(); + case 33776907: return key=="Planckconst" ? "ℎ" : QString(); + case 58158850: return key=="pm" ? "±" : QString(); + case 44799748: return key=="prec" ? "≺" : QString(); + case 7837445: return key=="prime" ? "′" : QString(); + case 43226886: return key=="propto" ? "∝" : QString(); + case 20160259: return key=="psi" ? "ψ" : QString(); + case 11771139: return key=="Psi" ? "Ψ" : QString(); + case 21234961: return key=="Q" ? "ℚ" : QString(); + case 57290003: return key=="QED" ? "■" : QString(); + case 8879893: return key=="qoppa" ? "ϙ" : QString(); + case 490773: return key=="Qoppa" ? "Ϙ" : QString(); + case 49000219: return key=="quarternote" ? "♩" : QString(); + case 2338583: return key=="questeq" ? "≟" : QString(); + case 21497121: return key=="R" ? "ℝ" : QString(); + case 31919910: return key=="rangle" ? "⟩" : QString(); + case 4136741: return key=="rceil" ? "⌉" : QString(); + case 48180514: return key=="Re" ? "ℜ" : QString(); + case 12267306: return key=="registered" ? "®" : QString(); + case 39008038: return key=="rfloor" ? "⌋" : QString(); + case 19351331: return key=="rho" ? "ρ" : QString(); + case 10962211: return key=="Rho" ? "Ρ" : QString(); + case 9916202: return key=="rightangle" ? "∟" : QString(); + case 19353386: return key=="rightarrow" ? "→" : QString(); + case 10964266: return key=="Rightarrow" ? "⇒" : QString(); + case 27217711: return key=="rightleftarrows" ? "⇄" : QString(); + case 61839143: return key=="rrangle" ? "⟫" : QString(); + case 50566953: return key=="rrbracket" ? "⟧" : QString(); + case 39036710: return key=="rtimes" ? "⋊" : QString(); + case 21759281: return key=="S" ? "𝕊" : QString(); + case 32714550: return key=="second" ? "″" : QString(); + case 8079157: return key=="sharp" ? "♯" : QString(); + case 62342967: return key=="shuffle" ? "⧢" : QString(); + case 4673333: return key=="sigma" ? "σ" : QString(); + case 63393077: return key=="Sigma" ? "Σ" : QString(); + case 25907000: return key=="sinewave" ? "∿" : QString(); + case 51087166: return key=="sphericalangle" ? "∢" : QString(); + case 6524725: return key=="sqcap" ? "⊓" : QString(); + case 11767605: return key=="sqcup" ? "⊔ " : QString(); + case 32214840: return key=="sqsubset" ? "⊏ " : QString(); + case 21204794: return key=="sqsubseteq" ? "⊑" : QString(); + case 35884856: return key=="sqsupset" ? "⊐" : QString(); + case 24874810: return key=="sqsupseteq" ? "⊒" : QString(); + case 39563062: return key=="subset" ? "⊂" : QString(); + case 31173942: return key=="Subset" ? "⋐ " : QString(); + case 14659386: return key=="subsetcirc" ? "⟃" : QString(); + case 28553016: return key=="subseteq" ? "⊆" : QString(); + case 45854516: return key=="succ" ? "≻" : QString(); + case 43233078: return key=="supset" ? "⊃" : QString(); + case 18329402: return key=="supsetcirc" ? "⟄" : QString(); + case 32223032: return key=="supseteq" ? "⊇" : QString(); + case 22021441: return key=="T" ? "𝕋" : QString(); + case 19599171: return key=="tau" ? "τ" : QString(); + case 11210051: return key=="Tau" ? "Τ" : QString(); + case 51595081: return key=="therefore" ? "∴" : QString(); + case 63915847: return key=="thermod" ? "⧧" : QString(); + case 5982021: return key=="theta" ? "θ" : QString(); + case 64701765: return key=="Theta" ? "Θ" : QString(); + case 7292741: return key=="third" ? "‴" : QString(); + case 9129797: return key=="times" ? "×" : QString(); + case 59735874: return key=="to" ? "→" : QString(); + case 21987139: return key=="top" ? "⊤" : QString(); + case 497484: return key=="triangleleft" ? "◅" : QString(); + case 52401993: return key=="triangleq" ? "≜" : QString(); + case 30644045: return key=="triangleright" ? "▻" : QString(); + case 34586440: return key=="twonotes" ? "♫" : QString(); + case 22283601: return key=="U" ? "𝕌" : QString(); + case 4425559: return key=="uparrow" ? "↑" : QString(); + case 52660059: return key=="updownarrow" ? "↕" : QString(); + case 15173461: return key=="uplus" ? "⊎" : QString(); + case 2852695: return key=="upsilon" ? "υ" : QString(); + case 61572439: return key=="Upsilon" ? "Υ" : QString(); + case 17764202: return key=="varepsilon" ? "ε" : QString(); + case 22744936: return key=="varkappa" ? "ϰ" : QString(); + case 36376422: return key=="varphi" ? "φ" : QString(); + case 9113445: return key=="varpi" ? "ϖ" : QString(); + case 38473574: return key=="varrho" ? "ϱ" : QString(); + case 23793512: return key=="varsigma" ? "ς" : QString(); + case 25104232: return key=="vartheta" ? "ϑ" : QString(); + case 16715624: return key=="varTheta" ? "ϴ" : QString(); + case 5973861: return key=="vdash" ? "⊢" : QString(); + case 64628581: return key=="vDash" ? "⊧" : QString(); + case 12789605: return key=="vdots" ? "⋮" : QString(); + case 16985955: return key=="vee" ? "∨" : QString(); + case 30879590: return key=="veebar" ? "⊻" : QString(); + case 64687991: return key=="warning" ? "⚠" : QString(); + case 3354485: return key=="wedge" ? "∧" : QString(); + case 60786546: return key=="wp" ? "℘" : QString(); + case 61314930: return key=="wr" ? "≀" : QString(); + case 59199362: return key=="xi" ? "ξ" : QString(); + case 50810242: return key=="Xi" ? "Ξ" : QString(); + case 23594401: return key=="Z" ? "ℤ" : QString(); + case 37688740: return key=="Zbar" ? "Ƶ" : QString(); + case 47394724: return key=="zeta" ? "ζ" : QString(); + case 39005604: return key=="Zeta" ? "Ζ" : QString(); + default: return QString(); + } +} + +}; diff --git a/include/crypt.h b/include/crypt.h new file mode 100644 index 00000000..ddee28e7 --- /dev/null +++ b/include/crypt.h @@ -0,0 +1,135 @@ +/* crypt.h -- base code for crypt/uncrypt ZIPfile + + + Version 1.01e, February 12th, 2005 + + Copyright (C) 1998-2005 Gilles Vollant + + This code is a modified version of crypting code in Infozip distribution + + The encryption/decryption parts of this source code (as opposed to the + non-echoing password parts) were originally written in Europe. The + whole source package can be freely distributed, including from the USA. + (Prior to January 2000, re-export from the US was a violation of US law.) + + This encryption code is a direct transcription of the algorithm from + Roger Schlafly, described by Phil Katz in the file appnote.txt. This + file (appnote.txt) is distributed with the PKZIP program (even in the + version without encryption capabilities). + + If you don't need crypting in your application, just define symbols + NOCRYPT and NOUNCRYPT. + + This code support the "Traditional PKWARE Encryption". + + The new AES encryption added on Zip format by Winzip (see the page + http://www.winzip.com/aes_info.htm ) and PKWare PKZip 5.x Strong + Encryption is not supported. +*/ + +#include "quazip_global.h" + +#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) + +/*********************************************************************** + * Return the next byte in the pseudo-random sequence + */ +static int decrypt_byte(unsigned long* pkeys, const z_crc_t FAR * pcrc_32_tab UNUSED) +{ + //(void) pcrc_32_tab; /* avoid "unused parameter" warning */ + unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an + * unpredictable manner on 16-bit systems; not a problem + * with any known compiler so far, though */ + + temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; + return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); +} + +/*********************************************************************** + * Update the encryption keys with the next byte of plain text + */ +static int update_keys(unsigned long* pkeys,const z_crc_t FAR * pcrc_32_tab,int c) +{ + (*(pkeys+0)) = CRC32((*(pkeys+0)), c); + (*(pkeys+1)) += (*(pkeys+0)) & 0xff; + (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; + { + register int keyshift = (int)((*(pkeys+1)) >> 24); + (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); + } + return c; +} + + +/*********************************************************************** + * Initialize the encryption keys and the random header according to + * the given password. + */ +static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t FAR * pcrc_32_tab) +{ + *(pkeys+0) = 305419896L; + *(pkeys+1) = 591751049L; + *(pkeys+2) = 878082192L; + while (*passwd != '\0') { + update_keys(pkeys,pcrc_32_tab,(int)*passwd); + passwd++; + } +} + +#define zdecode(pkeys,pcrc_32_tab,c) \ + (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) + +#define zencode(pkeys,pcrc_32_tab,c,t) \ + (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) + +#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED + +#define RAND_HEAD_LEN 12 + /* "last resort" source for second part of crypt seed pattern */ +# ifndef ZCR_SEED2 +# define ZCR_SEED2 3141592654UL /* use PI as default pattern */ +# endif + +static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting) + const char *passwd; /* password string */ + unsigned char *buf; /* where to write header */ + int bufSize; + unsigned long* pkeys; + const z_crc_t FAR * pcrc_32_tab; + unsigned long crcForCrypting; +{ + int n; /* index in random header */ + int t; /* temporary */ + int c; /* random byte */ + unsigned char header[RAND_HEAD_LEN-2]; /* random header */ + static unsigned calls = 0; /* ensure different random header each time */ + + if (bufSize> 7) & 0xff; + header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); + } + /* Encrypt random header (last two bytes is high word of crc) */ + init_keys(passwd, pkeys, pcrc_32_tab); + for (n = 0; n < RAND_HEAD_LEN-2; n++) + { + buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); + } + buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); + buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); + return n; +} + +#endif diff --git a/include/ioapi.h b/include/ioapi.h new file mode 100644 index 00000000..bbb94c8c --- /dev/null +++ b/include/ioapi.h @@ -0,0 +1,207 @@ +/* ioapi.h -- IO base function header for compress/uncompress .zip + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + Modified by Sergey A. Tachenov to allow QIODevice API usage. + + For more info read MiniZip_info.txt + + Changes + + Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this) + Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. + More if/def section may be needed to support other platforms + Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. + (but you should use iowin32.c for windows instead) + +*/ + +#ifndef _ZLIBIOAPI64_H +#define _ZLIBIOAPI64_H + +#if (!defined(_WIN32)) && (!defined(WIN32)) + + // Linux needs this to support file operation on files larger then 4+GB + // But might need better if/def to select just the platforms that needs them. + + #ifndef __USE_FILE_OFFSET64 + #define __USE_FILE_OFFSET64 + #endif + #ifndef __USE_LARGEFILE64 + #define __USE_LARGEFILE64 + #endif + #ifndef _LARGEFILE64_SOURCE + #define _LARGEFILE64_SOURCE + #endif + #ifndef _FILE_OFFSET_BIT + #define _FILE_OFFSET_BIT 64 + #endif +#endif + +#include +#include +#include "zlib.h" + +#if defined(USE_FILE32API) +#define fopen64 fopen +#define ftello64 ftell +#define fseeko64 fseek +#else +#ifdef _MSC_VER + #define fopen64 fopen + #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) + #define ftello64 _ftelli64 + #define fseeko64 _fseeki64 + #else // old MSC + #define ftello64 ftell + #define fseeko64 fseek + #endif +#endif +#endif + +/* +#ifndef ZPOS64_T + #ifdef _WIN32 + #define ZPOS64_T fpos_t + #else + #include + #define ZPOS64_T uint64_t + #endif +#endif +*/ + +#ifdef HAVE_MINIZIP64_CONF_H +#include "mz64conf.h" +#endif + +/* a type choosen by DEFINE */ +#ifdef HAVE_64BIT_INT_CUSTOM +typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; +#else +#ifdef HAS_STDINT_H +#include "stdint.h" +typedef uint64_t ZPOS64_T; +#else + + +#if defined(_MSC_VER) || defined(__BORLANDC__) +typedef unsigned __int64 ZPOS64_T; +#else +typedef unsigned long long int ZPOS64_T; +#endif +#endif +#endif + + + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef OF +#define OF _Z_OF +#endif + +#define ZLIB_FILEFUNC_SEEK_CUR (1) +#define ZLIB_FILEFUNC_SEEK_END (2) +#define ZLIB_FILEFUNC_SEEK_SET (0) + +#define ZLIB_FILEFUNC_MODE_READ (1) +#define ZLIB_FILEFUNC_MODE_WRITE (2) +#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) + +#define ZLIB_FILEFUNC_MODE_EXISTING (4) +#define ZLIB_FILEFUNC_MODE_CREATE (8) + + +#ifndef ZCALLBACK + #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) + #define ZCALLBACK CALLBACK + #else + #define ZCALLBACK + #endif +#endif + + + + +typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, voidpf file, int mode)); +typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); +typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); +typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); +typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); + +typedef uLong (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); +typedef int (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); + + +/* here is the "old" 32 bits structure structure */ +typedef struct zlib_filefunc_def_s +{ + open_file_func zopen_file; + read_file_func zread_file; + write_file_func zwrite_file; + tell_file_func ztell_file; + seek_file_func zseek_file; + close_file_func zclose_file; + testerror_file_func zerror_file; + voidpf opaque; +} zlib_filefunc_def; + +typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); +typedef int (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); +typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, voidpf file, int mode)); + +typedef struct zlib_filefunc64_def_s +{ + open64_file_func zopen64_file; + read_file_func zread_file; + write_file_func zwrite_file; + tell64_file_func ztell64_file; + seek64_file_func zseek64_file; + close_file_func zclose_file; + testerror_file_func zerror_file; + voidpf opaque; + close_file_func zfakeclose_file; // for no-auto-close flag +} zlib_filefunc64_def; + +void fill_qiodevice64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); +void fill_qiodevice_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); + +/* now internal definition, only for zip.c and unzip.h */ +typedef struct zlib_filefunc64_32_def_s +{ + zlib_filefunc64_def zfile_func64; + open_file_func zopen32_file; + tell_file_func ztell32_file; + seek_file_func zseek32_file; +} zlib_filefunc64_32_def; + + +#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) +#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) +//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) +//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) +#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) +#define ZFAKECLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zfakeclose_file)) ((filefunc).zfile_func64.opaque,filestream)) +#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) + +voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mode)); +int call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); +ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); + +void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); + +#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) +#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) +#define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/quaadler32.h b/include/quaadler32.h new file mode 100644 index 00000000..e8847f40 --- /dev/null +++ b/include/quaadler32.h @@ -0,0 +1,54 @@ +#ifndef QUAADLER32_H +#define QUAADLER32_H + +/* +Copyright (C) 2010 Adam Walczak +Copyright (C) 2005-2014 Sergey A. Tachenov + +This file is part of QuaZIP. + +QuaZIP is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +QuaZIP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with QuaZIP. If not, see . + +See COPYING file for the full LGPL text. + +Original ZIP package is copyrighted by Gilles Vollant and contributors, +see quazip/(un)zip.h files for details. Basically it's the zlib license. +*/ + +#include + +#include "quachecksum32.h" + +/// Adler32 checksum +/** \class QuaAdler32 quaadler32.h + * This class wrappers the adler32 function with the QuaChecksum32 interface. + * See QuaChecksum32 for more info. + */ +class QUAZIP_EXPORT QuaAdler32 : public QuaChecksum32 +{ + +public: + QuaAdler32(); + + quint32 calculate(const QByteArray &data); + + void reset(); + void update(const QByteArray &buf); + quint32 value(); + +private: + quint32 checksum; +}; + +#endif //QUAADLER32_H diff --git a/include/quachecksum32.h b/include/quachecksum32.h new file mode 100644 index 00000000..40ff451f --- /dev/null +++ b/include/quachecksum32.h @@ -0,0 +1,78 @@ +#ifndef QUACHECKSUM32_H +#define QUACHECKSUM32_H + +/* +Copyright (C) 2005-2014 Sergey A. Tachenov + +This file is part of QuaZIP. + +QuaZIP is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +QuaZIP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with QuaZIP. If not, see . + +See COPYING file for the full LGPL text. + +Original ZIP package is copyrighted by Gilles Vollant and contributors, +see quazip/(un)zip.h files for details. Basically it's the zlib license. +*/ + +#include +#include "quazip_global.h" + +/// Checksum interface. +/** \class QuaChecksum32 quachecksum32.h + * This is an interface for 32 bit checksums. + * Classes implementing this interface can calcunate a certin + * checksum in a single step: + * \code + * QChecksum32 *crc32 = new QuaCrc32(); + * rasoult = crc32->calculate(data); + * \endcode + * or by streaming the data: + * \code + * QChecksum32 *crc32 = new QuaCrc32(); + * while(!fileA.atEnd()) + * crc32->update(fileA.read(bufSize)); + * resoultA = crc32->value(); + * crc32->reset(); + * while(!fileB.atEnd()) + * crc32->update(fileB.read(bufSize)); + * resoultB = crc32->value(); + * \endcode + */ +class QUAZIP_EXPORT QuaChecksum32 +{ + +public: + ///Calculates the checksum for data. + /** \a data source data + * \return data checksum + * + * This function has no efect on the value returned by value(). + */ + virtual quint32 calculate(const QByteArray &data) = 0; + + ///Resets the calculation on a checksun for a stream. + virtual void reset() = 0; + + ///Updates the calculated checksum for the stream + /** \a buf next portion of data from the stream + */ + virtual void update(const QByteArray &buf) = 0; + + ///Value of the checksum calculated for the stream passed throw update(). + /** \return checksum + */ + virtual quint32 value() = 0; +}; + +#endif //QUACHECKSUM32_H diff --git a/include/quacrc32.h b/include/quacrc32.h new file mode 100644 index 00000000..af7703b2 --- /dev/null +++ b/include/quacrc32.h @@ -0,0 +1,50 @@ +#ifndef QUACRC32_H +#define QUACRC32_H + +/* +Copyright (C) 2005-2014 Sergey A. Tachenov + +This file is part of QuaZIP. + +QuaZIP is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +QuaZIP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with QuaZIP. If not, see . + +See COPYING file for the full LGPL text. + +Original ZIP package is copyrighted by Gilles Vollant and contributors, +see quazip/(un)zip.h files for details. Basically it's the zlib license. +*/ + +#include "quachecksum32.h" + +///CRC32 checksum +/** \class QuaCrc32 quacrc32.h +* This class wrappers the crc32 function with the QuaChecksum32 interface. +* See QuaChecksum32 for more info. +*/ +class QUAZIP_EXPORT QuaCrc32 : public QuaChecksum32 { + +public: + QuaCrc32(); + + quint32 calculate(const QByteArray &data); + + void reset(); + void update(const QByteArray &buf); + quint32 value(); + +private: + quint32 checksum; +}; + +#endif //QUACRC32_H diff --git a/include/quagzipfile.h b/include/quagzipfile.h new file mode 100644 index 00000000..e2f9d973 --- /dev/null +++ b/include/quagzipfile.h @@ -0,0 +1,108 @@ +#ifndef QUAZIP_QUAGZIPFILE_H +#define QUAZIP_QUAGZIPFILE_H + +/* +Copyright (C) 2005-2014 Sergey A. Tachenov + +This file is part of QuaZIP. + +QuaZIP is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +QuaZIP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with QuaZIP. If not, see . + +See COPYING file for the full LGPL text. + +Original ZIP package is copyrighted by Gilles Vollant and contributors, +see quazip/(un)zip.h files for details. Basically it's the zlib license. +*/ + +#include +#include "quazip_global.h" + +#include + +class QuaGzipFilePrivate; + +/// GZIP file +/** + This class is a wrapper around GZIP file access functions in zlib. Unlike QuaZip classes, it doesn't allow reading from a GZIP file opened as QIODevice, for example, if your GZIP file is in QBuffer. It only provides QIODevice access to a GZIP file contents, but the GZIP file itself must be identified by its name on disk or by descriptor id. + */ +class QUAZIP_EXPORT QuaGzipFile: public QIODevice { + Q_OBJECT +public: + /// Empty constructor. + /** + Must call setFileName() before trying to open. + */ + QuaGzipFile(); + /// Empty constructor with a parent. + /** + Must call setFileName() before trying to open. + \param parent The parent object, as per QObject logic. + */ + QuaGzipFile(QObject *parent); + /// Constructor. + /** + \param fileName The name of the GZIP file. + \param parent The parent object, as per QObject logic. + */ + QuaGzipFile(const QString &fileName, QObject *parent = NULL); + /// Destructor. + virtual ~QuaGzipFile(); + /// Sets the name of the GZIP file to be opened. + void setFileName(const QString& fileName); + /// Returns the name of the GZIP file. + QString getFileName() const; + /// Returns true. + /** + Strictly speaking, zlib supports seeking for GZIP files, but it is + poorly implemented, because there is no way to implement it + properly. For reading, seeking backwards is very slow, and for + writing, it is downright impossible. Therefore, QuaGzipFile does not + support seeking at all. + */ + virtual bool isSequential() const; + /// Opens the file. + /** + \param mode Can be either QIODevice::Write or QIODevice::Read. + ReadWrite and Append aren't supported. + */ + virtual bool open(QIODevice::OpenMode mode); + /// Opens the file. + /** + \overload + \param fd The file descriptor to read/write the GZIP file from/to. + \param mode Can be either QIODevice::Write or QIODevice::Read. + ReadWrite and Append aren't supported. + */ + virtual bool open(int fd, QIODevice::OpenMode mode); + /// Flushes data to file. + /** + The data is written using Z_SYNC_FLUSH mode. Doesn't make any sense + when reading. + */ + virtual bool flush(); + /// Closes the file. + virtual void close(); +protected: + /// Implementation of QIODevice::readData(). + virtual qint64 readData(char *data, qint64 maxSize); + /// Implementation of QIODevice::writeData(). + virtual qint64 writeData(const char *data, qint64 maxSize); +private: + // not implemented by design to disable copy + QuaGzipFile(const QuaGzipFile &that); + QuaGzipFile& operator=(const QuaGzipFile &that); + QuaGzipFilePrivate *d; +}; + +#endif // QUAZIP_QUAGZIPFILE_H diff --git a/include/quaziodevice.h b/include/quaziodevice.h new file mode 100644 index 00000000..63499c32 --- /dev/null +++ b/include/quaziodevice.h @@ -0,0 +1,102 @@ +#ifndef QUAZIP_QUAZIODEVICE_H +#define QUAZIP_QUAZIODEVICE_H + +/* +Copyright (C) 2005-2014 Sergey A. Tachenov + +This file is part of QuaZIP. + +QuaZIP is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +QuaZIP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with QuaZIP. If not, see . + +See COPYING file for the full LGPL text. + +Original ZIP package is copyrighted by Gilles Vollant and contributors, +see quazip/(un)zip.h files for details. Basically it's the zlib license. +*/ + +#include +#include "quazip_global.h" + +#include + +class QuaZIODevicePrivate; + +/// A class to compress/decompress QIODevice. +/** + This class can be used to compress any data written to QIODevice or + decompress it back. Compressing data sent over a QTcpSocket is a good + example. + */ +class QUAZIP_EXPORT QuaZIODevice: public QIODevice { + Q_OBJECT +public: + /// Constructor. + /** + \param io The QIODevice to read/write. + \param parent The parent object, as per QObject logic. + */ + QuaZIODevice(QIODevice *io, QObject *parent = NULL); + /// Destructor. + ~QuaZIODevice(); + /// Flushes data waiting to be written. + /** + Unfortunately, as QIODevice doesn't support flush() by itself, the + only thing this method does is write the compressed data into the + device using Z_SYNC_FLUSH mode. If you need the compressed data to + actually be flushed from the buffer of the underlying QIODevice, you + need to call its flush() method as well, providing it supports it + (like QTcpSocket does). Example: + \code + QuaZIODevice dev(&sock); + dev.open(QIODevice::Write); + dev.write(yourDataGoesHere); + dev.flush(); + sock->flush(); // this actually sends data to network + \endcode + + This may change in the future versions of QuaZIP by implementing an + ugly hack: trying to cast the QIODevice using qobject_cast to known + flush()-supporting subclasses, and calling flush if the resulting + pointer is not zero. + */ + virtual bool flush(); + /// Opens the device. + /** + \param mode Neither QIODevice::ReadWrite nor QIODevice::Append are + not supported. + */ + virtual bool open(QIODevice::OpenMode mode); + /// Closes this device, but not the underlying one. + /** + The underlying QIODevice is not closed in case you want to write + something else to it. + */ + virtual void close(); + /// Returns the underlying device. + QIODevice *getIoDevice() const; + /// Returns true. + virtual bool isSequential() const; + /// Returns true iff the end of the compressed stream is reached. + virtual bool atEnd() const; + /// Returns the number of the bytes buffered. + virtual qint64 bytesAvailable() const; +protected: + /// Implementation of QIODevice::readData(). + virtual qint64 readData(char *data, qint64 maxSize); + /// Implementation of QIODevice::writeData(). + virtual qint64 writeData(const char *data, qint64 maxSize); +private: + QuaZIODevicePrivate *d; +}; +#endif // QUAZIP_QUAZIODEVICE_H diff --git a/include/quazip.h b/include/quazip.h new file mode 100644 index 00000000..ae2c8f49 --- /dev/null +++ b/include/quazip.h @@ -0,0 +1,571 @@ +#ifndef QUA_ZIP_H +#define QUA_ZIP_H + +/* +Copyright (C) 2005-2014 Sergey A. Tachenov + +This file is part of QuaZIP. + +QuaZIP is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +QuaZIP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with QuaZIP. If not, see . + +See COPYING file for the full LGPL text. + +Original ZIP package is copyrighted by Gilles Vollant, see +quazip/(un)zip.h files for details, basically it's zlib license. + **/ + +#include +#include +#include + +#include "zip.h" +#include "unzip.h" + +#include "quazip_global.h" +#include "quazipfileinfo.h" + +// just in case it will be defined in the later versions of the ZIP/UNZIP +#ifndef UNZ_OPENERROR +// define additional error code +#define UNZ_OPENERROR -1000 +#endif + +class QuaZipPrivate; + +/// ZIP archive. +/** \class QuaZip quazip.h + * This class implements basic interface to the ZIP archive. It can be + * used to read table contents of the ZIP archive and retreiving + * information about the files inside it. + * + * You can also use this class to open files inside archive by passing + * pointer to the instance of this class to the constructor of the + * QuaZipFile class. But see QuaZipFile::QuaZipFile(QuaZip*, QObject*) + * for the possible pitfalls. + * + * This class is indended to provide interface to the ZIP subpackage of + * the ZIP/UNZIP package as well as to the UNZIP subpackage. But + * currently it supports only UNZIP. + * + * The use of this class is simple - just create instance using + * constructor, then set ZIP archive file name using setFile() function + * (if you did not passed the name to the constructor), then open() and + * then use different functions to work with it! Well, if you are + * paranoid, you may also wish to call close before destructing the + * instance, to check for errors on close. + * + * You may also use getUnzFile() and getZipFile() functions to get the + * ZIP archive handle and use it with ZIP/UNZIP package API directly. + * + * This class supports localized file names inside ZIP archive, but you + * have to set up proper codec with setCodec() function. By default, + * locale codec will be used, which is probably ok for UNIX systems, but + * will almost certainly fail with ZIP archives created in Windows. This + * is because Windows ZIP programs have strange habit of using DOS + * encoding for file names in ZIP archives. For example, ZIP archive + * with cyrillic names created in Windows will have file names in \c + * IBM866 encoding instead of \c WINDOWS-1251. I think that calling one + * function is not much trouble, but for true platform independency it + * would be nice to have some mechanism for file name encoding auto + * detection using locale information. Does anyone know a good way to do + * it? + **/ +class QUAZIP_EXPORT QuaZip { + friend class QuaZipPrivate; + public: + /// Useful constants. + enum Constants { + MAX_FILE_NAME_LENGTH=256 /**< Maximum file name length. Taken from + \c UNZ_MAXFILENAMEINZIP constant in + unzip.c. */ + }; + /// Open mode of the ZIP file. + enum Mode { + mdNotOpen, ///< ZIP file is not open. This is the initial mode. + mdUnzip, ///< ZIP file is open for reading files inside it. + mdCreate, ///< ZIP file was created with open() call. + mdAppend, /**< ZIP file was opened in append mode. This refers to + * \c APPEND_STATUS_CREATEAFTER mode in ZIP/UNZIP package + * and means that zip is appended to some existing file + * what is useful when that file contains + * self-extractor code. This is obviously \em not what + * you whant to use to add files to the existing ZIP + * archive. + **/ + mdAdd ///< ZIP file was opened for adding files in the archive. + }; + /// Case sensitivity for the file names. + /** This is what you specify when accessing files in the archive. + * Works perfectly fine with any characters thanks to Qt's great + * unicode support. This is different from ZIP/UNZIP API, where + * only US-ASCII characters was supported. + **/ + enum CaseSensitivity { + csDefault=0, ///< Default for platform. Case sensitive for UNIX, not for Windows. + csSensitive=1, ///< Case sensitive. + csInsensitive=2 ///< Case insensitive. + }; + /// Returns the actual case sensitivity for the specified QuaZIP one. + /** + \param cs The value to convert. + \returns If CaseSensitivity::csDefault, then returns the default + file name case sensitivity for the platform. Otherwise, just + returns the appropriate value from the Qt::CaseSensitivity enum. + */ + static Qt::CaseSensitivity convertCaseSensitivity( + CaseSensitivity cs); + private: + QuaZipPrivate *p; + // not (and will not be) implemented + QuaZip(const QuaZip& that); + // not (and will not be) implemented + QuaZip& operator=(const QuaZip& that); + public: + /// Constructs QuaZip object. + /** Call setName() before opening constructed object. */ + QuaZip(); + /// Constructs QuaZip object associated with ZIP file \a zipName. + QuaZip(const QString& zipName); + /// Constructs QuaZip object associated with ZIP file represented by \a ioDevice. + /** The IO device must be seekable, otherwise an error will occur when opening. */ + QuaZip(QIODevice *ioDevice); + /// Destroys QuaZip object. + /** Calls close() if necessary. */ + ~QuaZip(); + /// Opens ZIP file. + /** + * Argument \a mode specifies open mode of the ZIP archive. See Mode + * for details. Note that there is zipOpen2() function in the + * ZIP/UNZIP API which accepts \a globalcomment argument, but it + * does not use it anywhere, so this open() function does not have this + * argument. See setComment() if you need to set global comment. + * + * If the ZIP file is accessed via explicitly set QIODevice, then + * this device is opened in the necessary mode. If the device was + * already opened by some other means, then QuaZIP checks if the + * open mode is compatible to the mode needed for the requested operation. + * If necessary, seeking is performed to position the device properly. + * + * \return \c true if successful, \c false otherwise. + * + * \note ZIP/UNZIP API open calls do not return error code - they + * just return \c NULL indicating an error. But to make things + * easier, quazip.h header defines additional error code \c + * UNZ_ERROROPEN and getZipError() will return it if the open call + * of the ZIP/UNZIP API returns \c NULL. + * + * Argument \a ioApi specifies IO function set for ZIP/UNZIP + * package to use. See unzip.h, zip.h and ioapi.h for details. Note + * that IO API for QuaZip is different from the original package. + * The file path argument was changed to be of type \c voidpf, and + * QuaZip passes a QIODevice pointer there. This QIODevice is either + * set explicitly via setIoDevice() or the QuaZip(QIODevice*) + * constructor, or it is created internally when opening the archive + * by its file name. The default API (qioapi.cpp) just delegates + * everything to the QIODevice API. Not only this allows to use a + * QIODevice instead of file name, but also has a nice side effect + * of raising the file size limit from 2G to 4G (in non-zip64 archives). + * + * \note If the zip64 support is needed, the ioApi argument \em must be NULL + * because due to the backwards compatibility issues it can be used to + * provide a 32-bit API only. + * + * \note If the \ref QuaZip::setAutoClose() "no-auto-close" feature is used, + * then the \a ioApi argument \em should be NULL because the old API + * doesn't support the 'fake close' operation, causing slight memory leaks + * and other possible troubles (like closing the output device in case + * when an error occurs during opening). + * + * In short: just forget about the \a ioApi argument and you'll be + * fine. + **/ + bool open(Mode mode, zlib_filefunc_def *ioApi =NULL); + /// Closes ZIP file. + /** Call getZipError() to determine if the close was successful. + * + * If the file was opened by name, then the underlying QIODevice is closed + * and deleted. + * + * If the underlying QIODevice was set explicitly using setIoDevice() or + * the appropriate constructor, then it is closed if the auto-close flag + * is set (which it is by default). Call setAutoClose() to clear the + * auto-close flag if this behavior is undesirable. + * + * Since Qt 5.1, the QSaveFile was introduced. It breaks the QIODevice API + * by making close() private and crashing the application if it is called + * from the base class where it is public. It is an excellent example + * of poor design that illustrates why you should never ever break + * an is-a relationship between the base class and a subclass. QuaZIP + * works around this bug by checking if the QIODevice is an instance + * of QSaveFile, using qobject_cast<>, and if it is, calls + * QSaveFile::commit() instead of close(). It is a really ugly hack, + * but at least it makes your programs work instead of crashing. Note that + * if the auto-close flag is cleared, then this is a non-issue, and + * commit() isn't called. + */ + void close(); + /// Sets the codec used to encode/decode file names inside archive. + /** This is necessary to access files in the ZIP archive created + * under Windows with non-latin characters in file names. For + * example, file names with cyrillic letters will be in \c IBM866 + * encoding. + **/ + void setFileNameCodec(QTextCodec *fileNameCodec); + /// Sets the codec used to encode/decode file names inside archive. + /** \overload + * Equivalent to calling setFileNameCodec(QTextCodec::codecForName(codecName)); + **/ + void setFileNameCodec(const char *fileNameCodecName); + /// Returns the codec used to encode/decode comments inside archive. + QTextCodec* getFileNameCodec() const; + /// Sets the codec used to encode/decode comments inside archive. + /** This codec defaults to locale codec, which is probably ok. + **/ + void setCommentCodec(QTextCodec *commentCodec); + /// Sets the codec used to encode/decode comments inside archive. + /** \overload + * Equivalent to calling setCommentCodec(QTextCodec::codecForName(codecName)); + **/ + void setCommentCodec(const char *commentCodecName); + /// Returns the codec used to encode/decode comments inside archive. + QTextCodec* getCommentCodec() const; + /// Returns the name of the ZIP file. + /** Returns null string if no ZIP file name has been set, for + * example when the QuaZip instance is set up to use a QIODevice + * instead. + * \sa setZipName(), setIoDevice(), getIoDevice() + **/ + QString getZipName() const; + /// Sets the name of the ZIP file. + /** Does nothing if the ZIP file is open. + * + * Does not reset error code returned by getZipError(). + * \sa setIoDevice(), getIoDevice(), getZipName() + **/ + void setZipName(const QString& zipName); + /// Returns the device representing this ZIP file. + /** Returns null string if no device has been set explicitly, for + * example when opening a ZIP file by name. + * \sa setIoDevice(), getZipName(), setZipName() + **/ + QIODevice *getIoDevice() const; + /// Sets the device representing the ZIP file. + /** Does nothing if the ZIP file is open. + * + * Does not reset error code returned by getZipError(). + * \sa getIoDevice(), getZipName(), setZipName() + **/ + void setIoDevice(QIODevice *ioDevice); + /// Returns the mode in which ZIP file was opened. + Mode getMode() const; + /// Returns \c true if ZIP file is open, \c false otherwise. + bool isOpen() const; + /// Returns the error code of the last operation. + /** Returns \c UNZ_OK if the last operation was successful. + * + * Error code resets to \c UNZ_OK every time you call any function + * that accesses something inside ZIP archive, even if it is \c + * const (like getEntriesCount()). open() and close() calls reset + * error code too. See documentation for the specific functions for + * details on error detection. + **/ + int getZipError() const; + /// Returns number of the entries in the ZIP central directory. + /** Returns negative error code in the case of error. The same error + * code will be returned by subsequent getZipError() call. + **/ + int getEntriesCount() const; + /// Returns global comment in the ZIP file. + QString getComment() const; + /// Sets the global comment in the ZIP file. + /** The comment will be written to the archive on close operation. + * QuaZip makes a distinction between a null QByteArray() comment + * and an empty "" comment in the QuaZip::mdAdd mode. + * A null comment is the default and it means "don't change + * the comment". An empty comment removes the original comment. + * + * \sa open() + **/ + void setComment(const QString& comment); + /// Sets the current file to the first file in the archive. + /** Returns \c true on success, \c false otherwise. Call + * getZipError() to get the error code. + **/ + bool goToFirstFile(); + /// Sets the current file to the next file in the archive. + /** Returns \c true on success, \c false otherwise. Call + * getZipError() to determine if there was an error. + * + * Should be used only in QuaZip::mdUnzip mode. + * + * \note If the end of file was reached, getZipError() will return + * \c UNZ_OK instead of \c UNZ_END_OF_LIST_OF_FILE. This is to make + * things like this easier: + * \code + * for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) { + * // do something + * } + * if(zip.getZipError()==UNZ_OK) { + * // ok, there was no error + * } + * \endcode + **/ + bool goToNextFile(); + /// Sets current file by its name. + /** Returns \c true if successful, \c false otherwise. Argument \a + * cs specifies case sensitivity of the file name. Call + * getZipError() in the case of a failure to get error code. + * + * This is not a wrapper to unzLocateFile() function. That is + * because I had to implement locale-specific case-insensitive + * comparison. + * + * Here are the differences from the original implementation: + * + * - If the file was not found, error code is \c UNZ_OK, not \c + * UNZ_END_OF_LIST_OF_FILE (see also goToNextFile()). + * - If this function fails, it unsets the current file rather than + * resetting it back to what it was before the call. + * + * If \a fileName is null string then this function unsets the + * current file and return \c true. Note that you should close the + * file first if it is open! See + * QuaZipFile::QuaZipFile(QuaZip*,QObject*) for the details. + * + * Should be used only in QuaZip::mdUnzip mode. + * + * \sa setFileNameCodec(), CaseSensitivity + **/ + bool setCurrentFile(const QString& fileName, CaseSensitivity cs =csDefault); + /// Returns \c true if the current file has been set. + bool hasCurrentFile() const; + /// Retrieves information about the current file. + /** Fills the structure pointed by \a info. Returns \c true on + * success, \c false otherwise. In the latter case structure pointed + * by \a info remains untouched. If there was an error, + * getZipError() returns error code. + * + * Should be used only in QuaZip::mdUnzip mode. + * + * Does nothing and returns \c false in any of the following cases. + * - ZIP is not open; + * - ZIP does not have current file. + * + * In both cases getZipError() returns \c UNZ_OK since there + * is no ZIP/UNZIP API call. + * + * This overload doesn't support zip64, but will work OK on zip64 archives + * except that if one of the sizes (compressed or uncompressed) is greater + * than 0xFFFFFFFFu, it will be set to exactly 0xFFFFFFFFu. + * + * \sa getCurrentFileInfo(QuaZipFileInfo64* info)const + * \sa QuaZipFileInfo64::toQuaZipFileInfo(QuaZipFileInfo&)const + **/ + bool getCurrentFileInfo(QuaZipFileInfo* info)const; + /// Retrieves information about the current file. + /** \overload + * + * This function supports zip64. If the archive doesn't use zip64, it is + * completely equivalent to getCurrentFileInfo(QuaZipFileInfo* info) + * except for the argument type. + * + * \sa + **/ + bool getCurrentFileInfo(QuaZipFileInfo64* info)const; + /// Returns the current file name. + /** Equivalent to calling getCurrentFileInfo() and then getting \c + * name field of the QuaZipFileInfo structure, but faster and more + * convenient. + * + * Should be used only in QuaZip::mdUnzip mode. + **/ + QString getCurrentFileName()const; + /// Returns \c unzFile handle. + /** You can use this handle to directly call UNZIP part of the + * ZIP/UNZIP package functions (see unzip.h). + * + * \warning When using the handle returned by this function, please + * keep in mind that QuaZip class is unable to detect any changes + * you make in the ZIP file state (e. g. changing current file, or + * closing the handle). So please do not do anything with this + * handle that is possible to do with the functions of this class. + * Or at least return the handle in the original state before + * calling some another function of this class (including implicit + * destructor calls and calls from the QuaZipFile objects that refer + * to this QuaZip instance!). So if you have changed the current + * file in the ZIP archive - then change it back or you may + * experience some strange behavior or even crashes. + **/ + unzFile getUnzFile(); + /// Returns \c zipFile handle. + /** You can use this handle to directly call ZIP part of the + * ZIP/UNZIP package functions (see zip.h). Warnings about the + * getUnzFile() function also apply to this function. + **/ + zipFile getZipFile(); + /// Changes the data descriptor writing mode. + /** + According to the ZIP format specification, a file inside archive + may have a data descriptor immediately following the file + data. This is reflected by a special flag in the local file header + and in the central directory. By default, QuaZIP sets this flag + and writes the data descriptor unless both method and level were + set to 0, in which case it operates in 1.0-compatible mode and + never writes data descriptors. + + By setting this flag to false, it is possible to disable data + descriptor writing, thus increasing compatibility with archive + readers that don't understand this feature of the ZIP file format. + + Setting this flag affects all the QuaZipFile instances that are + opened after this flag is set. + + The data descriptor writing mode is enabled by default. + + Note that if the ZIP archive is written into a QIODevice for which + QIODevice::isSequential() returns \c true, then the data descriptor + is mandatory and will be written even if this flag is set to false. + + \param enabled If \c true, enable local descriptor writing, + disable it otherwise. + + \sa QuaZipFile::isDataDescriptorWritingEnabled() + */ + void setDataDescriptorWritingEnabled(bool enabled); + /// Returns the data descriptor default writing mode. + /** + \sa setDataDescriptorWritingEnabled() + */ + bool isDataDescriptorWritingEnabled() const; + /// Returns a list of files inside the archive. + /** + \return A list of file names or an empty list if there + was an error or if the archive is empty (call getZipError() to + figure out which). + \sa getFileInfoList() + */ + QStringList getFileNameList() const; + /// Returns information list about all files inside the archive. + /** + \return A list of QuaZipFileInfo objects or an empty list if there + was an error or if the archive is empty (call getZipError() to + figure out which). + + This function doesn't support zip64, but will still work with zip64 + archives, converting results using QuaZipFileInfo64::toQuaZipFileInfo(). + If all file sizes are below 4 GB, it will work just fine. + + \sa getFileNameList() + \sa getFileInfoList64() + */ + QList getFileInfoList() const; + /// Returns information list about all files inside the archive. + /** + \overload + + This function supports zip64. + + \sa getFileNameList() + \sa getFileInfoList() + */ + QList getFileInfoList64() const; + /// Enables the zip64 mode. + /** + * @param zip64 If \c true, the zip64 mode is enabled, disabled otherwise. + * + * Once this is enabled, all new files (until the mode is disabled again) + * will be created in the zip64 mode, thus enabling the ability to write + * files larger than 4 GB. By default, the zip64 mode is off due to + * compatibility reasons. + * + * Note that this does not affect the ability to read zip64 archives in any + * way. + * + * \sa isZip64Enabled() + */ + void setZip64Enabled(bool zip64); + /// Returns whether the zip64 mode is enabled. + /** + * @return \c true if and only if the zip64 mode is enabled. + * + * \sa setZip64Enabled() + */ + bool isZip64Enabled() const; + /// Returns the auto-close flag. + /** + @sa setAutoClose() + */ + bool isAutoClose() const; + /// Sets or unsets the auto-close flag. + /** + By default, QuaZIP opens the underlying QIODevice when open() is called, + and closes it when close() is called. In some cases, when the device + is set explicitly using setIoDevice(), it may be desirable to + leave the device open. If the auto-close flag is unset using this method, + then the device isn't closed automatically if it was set explicitly. + + If it is needed to clear this flag, it is recommended to do so before + opening the archive because otherwise QuaZIP may close the device + during the open() call if an error is encountered after the device + is opened. + + If the device was not set explicitly, but rather the setZipName() or + the appropriate constructor was used to set the ZIP file name instead, + then the auto-close flag has no effect, and the internal device + is closed nevertheless because there is no other way to close it. + + @sa isAutoClose() + @sa setIoDevice() + */ + void setAutoClose(bool autoClose) const; + /// Sets the default file name codec to use. + /** + * The default codec is used by the constructors, so calling this function + * won't affect the QuaZip instances already created at that moment. + * + * The codec specified here can be overriden by calling setFileNameCodec(). + * If neither function is called, QTextCodec::codecForLocale() will be used + * to decode or encode file names. Use this function with caution if + * the application uses other libraries that depend on QuaZIP. Those + * libraries can either call this function by themselves, thus overriding + * your setting or can rely on the default encoding, thus failing + * mysteriously if you change it. For these reasons, it isn't recommended + * to use this function if you are developing a library, not an application. + * Instead, ask your library users to call it in case they need specific + * encoding. + * + * In most cases, using setFileNameCodec() instead is the right choice. + * However, if you depend on third-party code that uses QuaZIP, then the + * reasons stated above can actually become a reason to use this function + * in case the third-party code in question fails because it doesn't + * understand the encoding you need and doesn't provide a way to specify it. + * This applies to the JlCompress class as well, as it was contributed and + * doesn't support explicit encoding parameters. + * + * In short: use setFileNameCodec() when you can, resort to + * setDefaultFileNameCodec() when you don't have access to the QuaZip + * instance. + * + * @param codec The codec to use by default. If NULL, resets to default. + */ + static void setDefaultFileNameCodec(QTextCodec *codec); + /** + * @overload + * Equivalent to calling + * setDefltFileNameCodec(QTextCodec::codecForName(codecName)). + */ + static void setDefaultFileNameCodec(const char *codecName); +}; + +#endif diff --git a/include/quazip_global.h b/include/quazip_global.h new file mode 100644 index 00000000..7e3798af --- /dev/null +++ b/include/quazip_global.h @@ -0,0 +1,59 @@ +#ifndef QUAZIP_GLOBAL_H +#define QUAZIP_GLOBAL_H + +/* +Copyright (C) 2005-2014 Sergey A. Tachenov + +This file is part of QuaZIP. + +QuaZIP is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +QuaZIP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with QuaZIP. If not, see . + +See COPYING file for the full LGPL text. + +Original ZIP package is copyrighted by Gilles Vollant and contributors, +see quazip/(un)zip.h files for details. Basically it's the zlib license. +*/ + +#include + +/** + This is automatically defined when building a static library, but when + including QuaZip sources directly into a project, QUAZIP_STATIC should + be defined explicitly to avoid possible troubles with unnecessary + importing/exporting. + */ +#ifdef QUAZIP_STATIC +#define QUAZIP_EXPORT +#else +/** + * When building a DLL with MSVC, QUAZIP_BUILD must be defined. + * qglobal.h takes care of defining Q_DECL_* correctly for msvc/gcc. + */ +#if defined(QUAZIP_BUILD) + #define QUAZIP_EXPORT Q_DECL_EXPORT +#else + #define QUAZIP_EXPORT Q_DECL_IMPORT +#endif +#endif // QUAZIP_STATIC + +#ifdef __GNUC__ +#define UNUSED __attribute__((__unused__)) +#else +#define UNUSED +#endif + +#define QUAZIP_EXTRA_NTFS_MAGIC 0x000Au +#define QUAZIP_EXTRA_NTFS_TIME_MAGIC 0x0001u + +#endif // QUAZIP_GLOBAL_H diff --git a/include/quazipdir.h b/include/quazipdir.h new file mode 100644 index 00000000..4626b171 --- /dev/null +++ b/include/quazipdir.h @@ -0,0 +1,223 @@ +#ifndef QUAZIP_QUAZIPDIR_H +#define QUAZIP_QUAZIPDIR_H + +/* +Copyright (C) 2005-2014 Sergey A. Tachenov + +This file is part of QuaZIP. + +QuaZIP is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +QuaZIP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with QuaZIP. If not, see . + +See COPYING file for the full LGPL text. + +Original ZIP package is copyrighted by Gilles Vollant and contributors, +see quazip/(un)zip.h files for details. Basically it's the zlib license. +*/ + +class QuaZipDirPrivate; + +#include "quazip.h" +#include "quazipfileinfo.h" +#include +#include +#include + +/// Provides ZIP archive navigation. +/** +* This class is modelled after QDir, and is designed to provide similar +* features for ZIP archives. +* +* The only significant difference from QDir is that the root path is not +* '/', but an empty string since that's how the file paths are stored in +* the archive. However, QuaZipDir understands the paths starting with +* '/'. It is important in a few places: +* +* - In the cd() function. +* - In the constructor. +* - In the exists() function. +* - In the relativePath() function. +* +* Note that since ZIP uses '/' on all platforms, the '\' separator is +* not supported. +*/ +class QUAZIP_EXPORT QuaZipDir { +private: + QSharedDataPointer d; +public: + /// The copy constructor. + QuaZipDir(const QuaZipDir &that); + /// Constructs a QuaZipDir instance pointing to the specified directory. + /** + If \a dir is not specified, points to the root of the archive. + The same happens if the \a dir is "/". + */ + QuaZipDir(QuaZip *zip, const QString &dir = QString()); + /// Destructor. + ~QuaZipDir(); + /// The assignment operator. + bool operator==(const QuaZipDir &that); + /// operator!= + /** + \return \c true if either this and \a that use different QuaZip + instances or if they point to different directories. + */ + inline bool operator!=(const QuaZipDir &that) {return !operator==(that);} + /// operator== + /** + \return \c true if both this and \a that use the same QuaZip + instance and point to the same directory. + */ + QuaZipDir& operator=(const QuaZipDir &that); + /// Returns the name of the entry at the specified position. + QString operator[](int pos) const; + /// Returns the current case sensitivity mode. + QuaZip::CaseSensitivity caseSensitivity() const; + /// Changes the 'current' directory. + /** + * If the path starts with '/', it is interpreted as an absolute + * path from the root of the archive. Otherwise, it is interpreted + * as a path relative to the current directory as was set by the + * previous cd() or the constructor. + * + * Note that the subsequent path() call will not return a path + * starting with '/' in all cases. + */ + bool cd(const QString &dirName); + /// Goes up. + bool cdUp(); + /// Returns the number of entries in the directory. + uint count() const; + /// Returns the current directory name. + /** + The name doesn't include the path. + */ + QString dirName() const; + /// Returns the list of the entries in the directory. + /** + \param nameFilters The list of file patterns to list, uses the same + syntax as QDir. + \param filters The entry type filters, only Files and Dirs are + accepted. + \param sort Sorting mode. + */ + QList entryInfoList(const QStringList &nameFilters, + QDir::Filters filters = QDir::NoFilter, + QDir::SortFlags sort = QDir::NoSort) const; + /// Returns the list of the entries in the directory. + /** + \overload + + The same as entryInfoList(QStringList(), filters, sort). + */ + QList entryInfoList(QDir::Filters filters = QDir::NoFilter, + QDir::SortFlags sort = QDir::NoSort) const; + /// Returns the list of the entries in the directory with zip64 support. + /** + \param nameFilters The list of file patterns to list, uses the same + syntax as QDir. + \param filters The entry type filters, only Files and Dirs are + accepted. + \param sort Sorting mode. + */ + QList entryInfoList64(const QStringList &nameFilters, + QDir::Filters filters = QDir::NoFilter, + QDir::SortFlags sort = QDir::NoSort) const; + /// Returns the list of the entries in the directory with zip64 support. + /** + \overload + + The same as entryInfoList64(QStringList(), filters, sort). + */ + QList entryInfoList64(QDir::Filters filters = QDir::NoFilter, + QDir::SortFlags sort = QDir::NoSort) const; + /// Returns the list of the entry names in the directory. + /** + The same as entryInfoList(nameFilters, filters, sort), but only + returns entry names. + */ + QStringList entryList(const QStringList &nameFilters, + QDir::Filters filters = QDir::NoFilter, + QDir::SortFlags sort = QDir::NoSort) const; + /// Returns the list of the entry names in the directory. + /** + \overload + + The same as entryList(QStringList(), filters, sort). + */ + QStringList entryList(QDir::Filters filters = QDir::NoFilter, + QDir::SortFlags sort = QDir::NoSort) const; + /// Returns \c true if the entry with the specified name exists. + /** + The ".." is considered to exist if the current directory + is not root. The "." and "/" are considered to + always exist. Paths starting with "/" are relative to + the archive root, other paths are relative to the current dir. + */ + bool exists(const QString &fileName) const; + /// Return \c true if the directory pointed by this QuaZipDir exists. + bool exists() const; + /// Returns the full path to the specified file. + /** + Doesn't check if the file actually exists. + */ + QString filePath(const QString &fileName) const; + /// Returns the default filter. + QDir::Filters filter(); + /// Returns if the QuaZipDir points to the root of the archive. + /** + Not that the root path is the empty string, not '/'. + */ + bool isRoot() const; + /// Return the default name filter. + QStringList nameFilters() const; + /// Returns the path to the current dir. + /** + The path never starts with '/', and the root path is an empty + string. + */ + QString path() const; + /// Returns the path to the specified file relative to the current dir. + /** + * This function is mostly useless, provided only for the sake of + * completeness. + * + * @param fileName The path to the file, should start with "/" + * if relative to the archive root. + * @return Path relative to the current dir. + */ + QString relativeFilePath(const QString &fileName) const; + /// Sets the default case sensitivity mode. + void setCaseSensitivity(QuaZip::CaseSensitivity caseSensitivity); + /// Sets the default filter. + void setFilter(QDir::Filters filters); + /// Sets the default name filter. + void setNameFilters(const QStringList &nameFilters); + /// Goes to the specified path. + /** + The difference from cd() is that this function never checks if the + path actually exists and doesn't use relative paths, so it's + possible to go to the root directory with setPath(""). + + Note that this function still chops the trailing and/or leading + '/' and treats a single '/' as the root path (path() will still + return an empty string). + */ + void setPath(const QString &path); + /// Sets the default sorting mode. + void setSorting(QDir::SortFlags sort); + /// Returns the default sorting mode. + QDir::SortFlags sorting() const; +}; + +#endif // QUAZIP_QUAZIPDIR_H diff --git a/include/quazipfile.h b/include/quazipfile.h new file mode 100644 index 00000000..e27b7a4a --- /dev/null +++ b/include/quazipfile.h @@ -0,0 +1,456 @@ +#ifndef QUA_ZIPFILE_H +#define QUA_ZIPFILE_H + +/* +Copyright (C) 2005-2014 Sergey A. Tachenov + +This file is part of QuaZIP. + +QuaZIP is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +QuaZIP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with QuaZIP. If not, see . + +See COPYING file for the full LGPL text. + +Original ZIP package is copyrighted by Gilles Vollant, see +quazip/(un)zip.h files for details, basically it's zlib license. + **/ + +#include + +#include "quazip_global.h" +#include "quazip.h" +#include "quazipnewinfo.h" + +class QuaZipFilePrivate; + +/// A file inside ZIP archive. +/** \class QuaZipFile quazipfile.h + * This is the most interesting class. Not only it provides C++ + * interface to the ZIP/UNZIP package, but also integrates it with Qt by + * subclassing QIODevice. This makes possible to access files inside ZIP + * archive using QTextStream or QDataStream, for example. Actually, this + * is the main purpose of the whole QuaZIP library. + * + * You can either use existing QuaZip instance to create instance of + * this class or pass ZIP archive file name to this class, in which case + * it will create internal QuaZip object. See constructors' descriptions + * for details. Writing is only possible with the existing instance. + * + * Note that due to the underlying library's limitation it is not + * possible to use multiple QuaZipFile instances to open several files + * in the same archive at the same time. If you need to write to + * multiple files in parallel, then you should write to temporary files + * first, then pack them all at once when you have finished writing. If + * you need to read multiple files inside the same archive in parallel, + * you should extract them all into a temporary directory first. + * + * \section quazipfile-sequential Sequential or random-access? + * + * At the first thought, QuaZipFile has fixed size, the start and the + * end and should be therefore considered random-access device. But + * there is one major obstacle to making it random-access: ZIP/UNZIP API + * does not support seek() operation and the only way to implement it is + * through reopening the file and re-reading to the required position, + * but this is prohibitively slow. + * + * Therefore, QuaZipFile is considered to be a sequential device. This + * has advantage of availability of the ungetChar() operation (QIODevice + * does not implement it properly for non-sequential devices unless they + * support seek()). Disadvantage is a somewhat strange behaviour of the + * size() and pos() functions. This should be kept in mind while using + * this class. + * + **/ +class QUAZIP_EXPORT QuaZipFile: public QIODevice { + friend class QuaZipFilePrivate; + Q_OBJECT + private: + QuaZipFilePrivate *p; + // these are not supported nor implemented + QuaZipFile(const QuaZipFile& that); + QuaZipFile& operator=(const QuaZipFile& that); + protected: + /// Implementation of the QIODevice::readData(). + qint64 readData(char *data, qint64 maxSize); + /// Implementation of the QIODevice::writeData(). + qint64 writeData(const char *data, qint64 maxSize); + public: + /// Constructs a QuaZipFile instance. + /** You should use setZipName() and setFileName() or setZip() before + * trying to call open() on the constructed object. + **/ + QuaZipFile(); + /// Constructs a QuaZipFile instance. + /** \a parent argument specifies this object's parent object. + * + * You should use setZipName() and setFileName() or setZip() before + * trying to call open() on the constructed object. + **/ + QuaZipFile(QObject *parent); + /// Constructs a QuaZipFile instance. + /** \a parent argument specifies this object's parent object and \a + * zipName specifies ZIP archive file name. + * + * You should use setFileName() before trying to call open() on the + * constructed object. + * + * QuaZipFile constructed by this constructor can be used for read + * only access. Use QuaZipFile(QuaZip*,QObject*) for writing. + **/ + QuaZipFile(const QString& zipName, QObject *parent =NULL); + /// Constructs a QuaZipFile instance. + /** \a parent argument specifies this object's parent object, \a + * zipName specifies ZIP archive file name and \a fileName and \a cs + * specify a name of the file to open inside archive. + * + * QuaZipFile constructed by this constructor can be used for read + * only access. Use QuaZipFile(QuaZip*,QObject*) for writing. + * + * \sa QuaZip::setCurrentFile() + **/ + QuaZipFile(const QString& zipName, const QString& fileName, + QuaZip::CaseSensitivity cs =QuaZip::csDefault, QObject *parent =NULL); + /// Constructs a QuaZipFile instance. + /** \a parent argument specifies this object's parent object. + * + * \a zip is the pointer to the existing QuaZip object. This + * QuaZipFile object then can be used to read current file in the + * \a zip or to write to the file inside it. + * + * \warning Using this constructor for reading current file can be + * tricky. Let's take the following example: + * \code + * QuaZip zip("archive.zip"); + * zip.open(QuaZip::mdUnzip); + * zip.setCurrentFile("file-in-archive"); + * QuaZipFile file(&zip); + * file.open(QIODevice::ReadOnly); + * // ok, now we can read from the file + * file.read(somewhere, some); + * zip.setCurrentFile("another-file-in-archive"); // oops... + * QuaZipFile anotherFile(&zip); + * anotherFile.open(QIODevice::ReadOnly); + * anotherFile.read(somewhere, some); // this is still ok... + * file.read(somewhere, some); // and this is NOT + * \endcode + * So, what exactly happens here? When we change current file in the + * \c zip archive, \c file that references it becomes invalid + * (actually, as far as I understand ZIP/UNZIP sources, it becomes + * closed, but QuaZipFile has no means to detect it). + * + * Summary: do not close \c zip object or change its current file as + * long as QuaZipFile is open. Even better - use another constructors + * which create internal QuaZip instances, one per object, and + * therefore do not cause unnecessary trouble. This constructor may + * be useful, though, if you already have a QuaZip instance and do + * not want to access several files at once. Good example: + * \code + * QuaZip zip("archive.zip"); + * zip.open(QuaZip::mdUnzip); + * // first, we need some information about archive itself + * QByteArray comment=zip.getComment(); + * // and now we are going to access files inside it + * QuaZipFile file(&zip); + * for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) { + * file.open(QIODevice::ReadOnly); + * // do something cool with file here + * file.close(); // do not forget to close! + * } + * zip.close(); + * \endcode + **/ + QuaZipFile(QuaZip *zip, QObject *parent =NULL); + /// Destroys a QuaZipFile instance. + /** Closes file if open, destructs internal QuaZip object (if it + * exists and \em is internal, of course). + **/ + virtual ~QuaZipFile(); + /// Returns the ZIP archive file name. + /** If this object was created by passing QuaZip pointer to the + * constructor, this function will return that QuaZip's file name + * (or null string if that object does not have file name yet). + * + * Otherwise, returns associated ZIP archive file name or null + * string if there are no name set yet. + * + * \sa setZipName() getFileName() + **/ + QString getZipName()const; + /// Returns a pointer to the associated QuaZip object. + /** Returns \c NULL if there is no associated QuaZip or it is + * internal (so you will not mess with it). + **/ + QuaZip* getZip()const; + /// Returns file name. + /** This function returns file name you passed to this object either + * by using + * QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*) + * or by calling setFileName(). Real name of the file may differ in + * case if you used case-insensitivity. + * + * Returns null string if there is no file name set yet. This is the + * case when this QuaZipFile operates on the existing QuaZip object + * (constructor QuaZipFile(QuaZip*,QObject*) or setZip() was used). + * + * \sa getActualFileName + **/ + QString getFileName() const; + /// Returns case sensitivity of the file name. + /** This function returns case sensitivity argument you passed to + * this object either by using + * QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*) + * or by calling setFileName(). + * + * Returns unpredictable value if getFileName() returns null string + * (this is the case when you did not used setFileName() or + * constructor above). + * + * \sa getFileName + **/ + QuaZip::CaseSensitivity getCaseSensitivity() const; + /// Returns the actual file name in the archive. + /** This is \em not a ZIP archive file name, but a name of file inside + * archive. It is not necessary the same name that you have passed + * to the + * QuaZipFile(const QString&,const QString&,QuaZip::CaseSensitivity,QObject*), + * setFileName() or QuaZip::setCurrentFile() - this is the real file + * name inside archive, so it may differ in case if the file name + * search was case-insensitive. + * + * Equivalent to calling getCurrentFileName() on the associated + * QuaZip object. Returns null string if there is no associated + * QuaZip object or if it does not have a current file yet. And this + * is the case if you called setFileName() but did not open the + * file yet. So this is perfectly fine: + * \code + * QuaZipFile file("somezip.zip"); + * file.setFileName("somefile"); + * QString name=file.getName(); // name=="somefile" + * QString actual=file.getActualFileName(); // actual is null string + * file.open(QIODevice::ReadOnly); + * QString actual=file.getActualFileName(); // actual can be "SoMeFiLe" on Windows + * \endcode + * + * \sa getZipName(), getFileName(), QuaZip::CaseSensitivity + **/ + QString getActualFileName()const; + /// Sets the ZIP archive file name. + /** Automatically creates internal QuaZip object and destroys + * previously created internal QuaZip object, if any. + * + * Will do nothing if this file is already open. You must close() it + * first. + **/ + void setZipName(const QString& zipName); + /// Returns \c true if the file was opened in raw mode. + /** If the file is not open, the returned value is undefined. + * + * \sa open(OpenMode,int*,int*,bool,const char*) + **/ + bool isRaw() const; + /// Binds to the existing QuaZip instance. + /** This function destroys internal QuaZip object, if any, and makes + * this QuaZipFile to use current file in the \a zip object for any + * further operations. See QuaZipFile(QuaZip*,QObject*) for the + * possible pitfalls. + * + * Will do nothing if the file is currently open. You must close() + * it first. + **/ + void setZip(QuaZip *zip); + /// Sets the file name. + /** Will do nothing if at least one of the following conditions is + * met: + * - ZIP name has not been set yet (getZipName() returns null + * string). + * - This QuaZipFile is associated with external QuaZip. In this + * case you should call that QuaZip's setCurrentFile() function + * instead! + * - File is already open so setting the name is meaningless. + * + * \sa QuaZip::setCurrentFile + **/ + void setFileName(const QString& fileName, QuaZip::CaseSensitivity cs =QuaZip::csDefault); + /// Opens a file for reading. + /** Returns \c true on success, \c false otherwise. + * Call getZipError() to get error code. + * + * \note Since ZIP/UNZIP API provides buffered reading only, + * QuaZipFile does not support unbuffered reading. So do not pass + * QIODevice::Unbuffered flag in \a mode, or open will fail. + **/ + virtual bool open(OpenMode mode); + /// Opens a file for reading. + /** \overload + * Argument \a password specifies a password to decrypt the file. If + * it is NULL then this function behaves just like open(OpenMode). + **/ + inline bool open(OpenMode mode, const char *password) + {return open(mode, NULL, NULL, false, password);} + /// Opens a file for reading. + /** \overload + * Argument \a password specifies a password to decrypt the file. + * + * An integers pointed by \a method and \a level will receive codes + * of the compression method and level used. See unzip.h. + * + * If raw is \c true then no decompression is performed. + * + * \a method should not be \c NULL. \a level can be \c NULL if you + * don't want to know the compression level. + **/ + bool open(OpenMode mode, int *method, int *level, bool raw, const char *password =NULL); + /// Opens a file for writing. + /** \a info argument specifies information about file. It should at + * least specify a correct file name. Also, it is a good idea to + * specify correct timestamp (by default, current time will be + * used). See QuaZipNewInfo. + * + * The \a password argument specifies the password for crypting. Pass NULL + * if you don't need any crypting. The \a crc argument was supposed + * to be used for crypting too, but then it turned out that it's + * false information, so you need to set it to 0 unless you want to + * use the raw mode (see below). + * + * Arguments \a method and \a level specify compression method and + * level. The only method supported is Z_DEFLATED, but you may also + * specify 0 for no compression. If all of the files in the archive + * use both method 0 and either level 0 is explicitly specified or + * data descriptor writing is disabled with + * QuaZip::setDataDescriptorWritingEnabled(), then the + * resulting archive is supposed to be compatible with the 1.0 ZIP + * format version, should you need that. Except for this, \a level + * has no other effects with method 0. + * + * If \a raw is \c true, no compression is performed. In this case, + * \a crc and uncompressedSize field of the \a info are required. + * + * Arguments \a windowBits, \a memLevel, \a strategy provide zlib + * algorithms tuning. See deflateInit2() in zlib. + **/ + bool open(OpenMode mode, const QuaZipNewInfo& info, + const char *password =NULL, quint32 crc =0, + int method =Z_DEFLATED, int level =Z_DEFAULT_COMPRESSION, bool raw =false, + int windowBits =-MAX_WBITS, int memLevel =DEF_MEM_LEVEL, int strategy =Z_DEFAULT_STRATEGY); + /// Returns \c true, but \ref quazipfile-sequential "beware"! + virtual bool isSequential()const; + /// Returns current position in the file. + /** Implementation of the QIODevice::pos(). When reading, this + * function is a wrapper to the ZIP/UNZIP unztell(), therefore it is + * unable to keep track of the ungetChar() calls (which is + * non-virtual and therefore is dangerous to reimplement). So if you + * are using ungetChar() feature of the QIODevice, this function + * reports incorrect value until you get back characters which you + * ungot. + * + * When writing, pos() returns number of bytes already written + * (uncompressed unless you use raw mode). + * + * \note Although + * \ref quazipfile-sequential "QuaZipFile is a sequential device" + * and therefore pos() should always return zero, it does not, + * because it would be misguiding. Keep this in mind. + * + * This function returns -1 if the file or archive is not open. + * + * Error code returned by getZipError() is not affected by this + * function call. + **/ + virtual qint64 pos()const; + /// Returns \c true if the end of file was reached. + /** This function returns \c false in the case of error. This means + * that you called this function on either not open file, or a file + * in the not open archive or even on a QuaZipFile instance that + * does not even have QuaZip instance associated. Do not do that + * because there is no means to determine whether \c false is + * returned because of error or because end of file was reached. + * Well, on the other side you may interpret \c false return value + * as "there is no file open to check for end of file and there is + * no end of file therefore". + * + * When writing, this function always returns \c true (because you + * are always writing to the end of file). + * + * Error code returned by getZipError() is not affected by this + * function call. + **/ + virtual bool atEnd()const; + /// Returns file size. + /** This function returns csize() if the file is open for reading in + * raw mode, usize() if it is open for reading in normal mode and + * pos() if it is open for writing. + * + * Returns -1 on error, call getZipError() to get error code. + * + * \note This function returns file size despite that + * \ref quazipfile-sequential "QuaZipFile is considered to be sequential device", + * for which size() should return bytesAvailable() instead. But its + * name would be very misguiding otherwise, so just keep in mind + * this inconsistence. + **/ + virtual qint64 size()const; + /// Returns compressed file size. + /** Equivalent to calling getFileInfo() and then getting + * compressedSize field, but more convenient and faster. + * + * File must be open for reading before calling this function. + * + * Returns -1 on error, call getZipError() to get error code. + **/ + qint64 csize()const; + /// Returns uncompressed file size. + /** Equivalent to calling getFileInfo() and then getting + * uncompressedSize field, but more convenient and faster. See + * getFileInfo() for a warning. + * + * File must be open for reading before calling this function. + * + * Returns -1 on error, call getZipError() to get error code. + **/ + qint64 usize()const; + /// Gets information about current file. + /** This function does the same thing as calling + * QuaZip::getCurrentFileInfo() on the associated QuaZip object, + * but you can not call getCurrentFileInfo() if the associated + * QuaZip is internal (because you do not have access to it), while + * you still can call this function in that case. + * + * File must be open for reading before calling this function. + * + * \return \c false in the case of an error. + * + * This function doesn't support zip64, but will still work fine on zip64 + * archives if file sizes are below 4 GB, otherwise the values will be set + * as if converted using QuaZipFileInfo64::toQuaZipFileInfo(). + * + * \sa getFileInfo(QuaZipFileInfo64*) + **/ + bool getFileInfo(QuaZipFileInfo *info); + /// Gets information about current file with zip64 support. + /** + * @overload + * + * \sa getFileInfo(QuaZipFileInfo*) + */ + bool getFileInfo(QuaZipFileInfo64 *info); + /// Closes the file. + /** Call getZipError() to determine if the close was successful. + **/ + virtual void close(); + /// Returns the error code returned by the last ZIP/UNZIP API call. + int getZipError() const; + /// Returns the number of bytes available for reading. + virtual qint64 bytesAvailable() const; +}; + +#endif diff --git a/include/quazipfileinfo.h b/include/quazipfileinfo.h new file mode 100644 index 00000000..4e142a4e --- /dev/null +++ b/include/quazipfileinfo.h @@ -0,0 +1,178 @@ +#ifndef QUA_ZIPFILEINFO_H +#define QUA_ZIPFILEINFO_H + +/* +Copyright (C) 2005-2014 Sergey A. Tachenov + +This file is part of QuaZIP. + +QuaZIP is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +QuaZIP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with QuaZIP. If not, see . + +See COPYING file for the full LGPL text. + +Original ZIP package is copyrighted by Gilles Vollant and contributors, +see quazip/(un)zip.h files for details. Basically it's the zlib license. +*/ + +#include +#include +#include + +#include "quazip_global.h" + +/// Information about a file inside archive. +/** + * \deprecated Use QuaZipFileInfo64 instead. Not only it supports large files, + * but also more convenience methods as well. + * + * Call QuaZip::getCurrentFileInfo() or QuaZipFile::getFileInfo() to + * fill this structure. */ +struct QUAZIP_EXPORT QuaZipFileInfo { + /// File name. + QString name; + /// Version created by. + quint16 versionCreated; + /// Version needed to extract. + quint16 versionNeeded; + /// General purpose flags. + quint16 flags; + /// Compression method. + quint16 method; + /// Last modification date and time. + QDateTime dateTime; + /// CRC. + quint32 crc; + /// Compressed file size. + quint32 compressedSize; + /// Uncompressed file size. + quint32 uncompressedSize; + /// Disk number start. + quint16 diskNumberStart; + /// Internal file attributes. + quint16 internalAttr; + /// External file attributes. + quint32 externalAttr; + /// Comment. + QString comment; + /// Extra field. + QByteArray extra; + /// Get the file permissions. + /** + Returns the high 16 bits of external attributes converted to + QFile::Permissions. + */ + QFile::Permissions getPermissions() const; +}; + +/// Information about a file inside archive (with zip64 support). +/** Call QuaZip::getCurrentFileInfo() or QuaZipFile::getFileInfo() to + * fill this structure. */ +struct QUAZIP_EXPORT QuaZipFileInfo64 { + /// File name. + QString name; + /// Version created by. + quint16 versionCreated; + /// Version needed to extract. + quint16 versionNeeded; + /// General purpose flags. + quint16 flags; + /// Compression method. + quint16 method; + /// Last modification date and time. + /** + * This is the time stored in the standard ZIP header. This format only allows + * to store time with 2-second precision, so the seconds will always be even + * and the milliseconds will always be zero. If you need more precise + * date and time, you can try to call the getNTFSmTime() function or + * its siblings, provided that the archive itself contains these NTFS times. + */ + QDateTime dateTime; + /// CRC. + quint32 crc; + /// Compressed file size. + quint64 compressedSize; + /// Uncompressed file size. + quint64 uncompressedSize; + /// Disk number start. + quint16 diskNumberStart; + /// Internal file attributes. + quint16 internalAttr; + /// External file attributes. + quint32 externalAttr; + /// Comment. + QString comment; + /// Extra field. + QByteArray extra; + /// Get the file permissions. + /** + Returns the high 16 bits of external attributes converted to + QFile::Permissions. + */ + QFile::Permissions getPermissions() const; + /// Converts to QuaZipFileInfo + /** + If any of the fields are greater than 0xFFFFFFFFu, they are set to + 0xFFFFFFFFu exactly, not just truncated. This function should be mainly used + for compatibility with the old code expecting QuaZipFileInfo, in the cases + when it's impossible or otherwise unadvisable (due to ABI compatibility + reasons, for example) to modify that old code to use QuaZipFileInfo64. + + \return \c true if all fields converted correctly, \c false if an overflow + occured. + */ + bool toQuaZipFileInfo(QuaZipFileInfo &info) const; + /// Returns the NTFS modification time + /** + * The getNTFS*Time() functions only work if there is an NTFS extra field + * present. Otherwise, they all return invalid null timestamps. + * @param fineTicks If not NULL, the fractional part of milliseconds returned + * there, measured in 100-nanosecond ticks. Will be set to + * zero if there is no NTFS extra field. + * @sa dateTime + * @sa getNTFSaTime() + * @sa getNTFScTime() + * @return The NTFS modification time, UTC + */ + QDateTime getNTFSmTime(int *fineTicks = NULL) const; + /// Returns the NTFS access time + /** + * The getNTFS*Time() functions only work if there is an NTFS extra field + * present. Otherwise, they all return invalid null timestamps. + * @param fineTicks If not NULL, the fractional part of milliseconds returned + * there, measured in 100-nanosecond ticks. Will be set to + * zero if there is no NTFS extra field. + * @sa dateTime + * @sa getNTFSmTime() + * @sa getNTFScTime() + * @return The NTFS access time, UTC + */ + QDateTime getNTFSaTime(int *fineTicks = NULL) const; + /// Returns the NTFS creation time + /** + * The getNTFS*Time() functions only work if there is an NTFS extra field + * present. Otherwise, they all return invalid null timestamps. + * @param fineTicks If not NULL, the fractional part of milliseconds returned + * there, measured in 100-nanosecond ticks. Will be set to + * zero if there is no NTFS extra field. + * @sa dateTime + * @sa getNTFSmTime() + * @sa getNTFSaTime() + * @return The NTFS creation time, UTC + */ + QDateTime getNTFScTime(int *fineTicks = NULL) const; + /// Checks whether the file is encrypted. + bool isEncrypted() const {return (flags & 1) != 0;} +}; + +#endif diff --git a/include/quazipnewinfo.h b/include/quazipnewinfo.h new file mode 100644 index 00000000..bfd49868 --- /dev/null +++ b/include/quazipnewinfo.h @@ -0,0 +1,207 @@ +#ifndef QUA_ZIPNEWINFO_H +#define QUA_ZIPNEWINFO_H + +/* +Copyright (C) 2005-2014 Sergey A. Tachenov + +This file is part of QuaZIP. + +QuaZIP is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2.1 of the License, or +(at your option) any later version. + +QuaZIP is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with QuaZIP. If not, see . + +See COPYING file for the full LGPL text. + +Original ZIP package is copyrighted by Gilles Vollant, see +quazip/(un)zip.h files for details, basically it's zlib license. + **/ + +#include +#include +#include + +#include "quazip_global.h" + +#include "quazipfileinfo.h" + +/// Information about a file to be created. +/** This structure holds information about a file to be created inside + * ZIP archive. At least name should be set to something correct before + * passing this structure to + * QuaZipFile::open(OpenMode,const QuaZipNewInfo&,int,int,bool). + * + * Zip64 support of this structure is slightly limited: in the raw mode (when + * a pre-compressed file is written into a ZIP file as-is), it is necessary + * to specify the uncompressed file size and the appropriate field is 32 bit. + * Since the raw mode is used extremely rare, there is no real need to have + * a separate QuaZipNewInfo64 structure like QuaZipFileInfo64. It may be added + * in the future though, if there is a demand for the raw mode with zip64 + * archives. + **/ +struct QUAZIP_EXPORT QuaZipNewInfo { + /// File name. + /** This field holds file name inside archive, including path relative + * to archive root. + **/ + QString name; + /// File timestamp. + /** This is the last file modification date and time. Will be stored + * in the archive central directory. It is a good practice to set it + * to the source file timestamp instead of archive creating time. Use + * setFileDateTime() or QuaZipNewInfo(const QString&, const QString&). + **/ + QDateTime dateTime; + /// File internal attributes. + quint16 internalAttr; + /// File external attributes. + /** + The highest 16 bits contain Unix file permissions and type (dir or + file). The constructor QuaZipNewInfo(const QString&, const QString&) + takes permissions from the provided file. + */ + quint32 externalAttr; + /// File comment. + /** Will be encoded using QuaZip::getCommentCodec(). + **/ + QString comment; + /// File local extra field. + QByteArray extraLocal; + /// File global extra field. + QByteArray extraGlobal; + /// Uncompressed file size. + /** This is only needed if you are using raw file zipping mode, i. e. + * adding precompressed file in the zip archive. + **/ + ulong uncompressedSize; + /// Constructs QuaZipNewInfo instance. + /** Initializes name with \a name, dateTime with current date and + * time. Attributes are initialized with zeros, comment and extra + * field with null values. + **/ + QuaZipNewInfo(const QString& name); + /// Constructs QuaZipNewInfo instance. + /** Initializes name with \a name. Timestamp and permissions are taken + * from the specified file. If the \a file does not exists or its timestamp + * is inaccessible (e. g. you do not have read permission for the + * directory file in), uses current time and zero permissions. Other attributes are + * initialized with zeros, comment and extra field with null values. + * + * \sa setFileDateTime() + **/ + QuaZipNewInfo(const QString& name, const QString& file); + /// Initializes the new instance from existing file info. + /** Mainly used when copying files between archives. + * + * Both extra fields are initialized to existing.extra. + * @brief QuaZipNewInfo + * @param existing + */ + QuaZipNewInfo(const QuaZipFileInfo &existing); + /// Initializes the new instance from existing file info. + /** Mainly used when copying files between archives. + * + * Both extra fields are initialized to existing.extra. + * @brief QuaZipNewInfo + * @param existing + */ + QuaZipNewInfo(const QuaZipFileInfo64 &existing); + /// Sets the file timestamp from the existing file. + /** Use this function to set the file timestamp from the existing + * file. Use it like this: + * \code + * QuaZipFile zipFile(&zip); + * QFile file("file-to-add"); + * file.open(QIODevice::ReadOnly); + * QuaZipNewInfo info("file-name-in-archive"); + * info.setFileDateTime("file-to-add"); // take the timestamp from file + * zipFile.open(QIODevice::WriteOnly, info); + * \endcode + * + * This function does not change dateTime if some error occured (e. g. + * file is inaccessible). + **/ + void setFileDateTime(const QString& file); + /// Sets the file permissions from the existing file. + /** + Takes permissions from the file and sets the high 16 bits of + external attributes. Uses QFileInfo to get permissions on all + platforms. + */ + void setFilePermissions(const QString &file); + /// Sets the file permissions. + /** + Modifies the highest 16 bits of external attributes. The type part + is set to dir if the name ends with a slash, and to regular file + otherwise. + */ + void setPermissions(QFile::Permissions permissions); + /// Sets the NTFS times from an existing file. + /** + * If the file doesn't exist, a warning is printed to the stderr and nothing + * is done. Otherwise, all three times, as reported by + * QFileInfo::lastModified(), QFileInfo::lastRead() and QFileInfo::created(), + * are written to the NTFS extra field record. + * + * The NTFS record is written to + * both the local and the global extra fields, updating the existing record + * if there is one, or creating a new one and appending it to the end + * of each extra field. + * + * The microseconds will be zero, as they aren't reported by QFileInfo. + * @param fileName + */ + void setFileNTFSTimes(const QString &fileName); + /// Sets the NTFS modification time. + /** + * The time is written into the NTFS record in + * both the local and the global extra fields, updating the existing record + * if there is one, or creating a new one and appending it to the end + * of each extra field. When updating an existing record, all other fields + * are left intact. + * @param mTime The new modification time. + * @param fineTicks The fractional part of milliseconds, in 100-nanosecond + * ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than + * 9999 will add milliseconds or even seconds, but this can be + * confusing and therefore is discouraged. + */ + void setFileNTFSmTime(const QDateTime &mTime, int fineTicks = 0); + /// Sets the NTFS access time. + /** + * The time is written into the NTFS record in + * both the local and the global extra fields, updating the existing record + * if there is one, or creating a new one and appending it to the end + * of each extra field. When updating an existing record, all other fields + * are left intact. + * @param aTime The new access time. + * @param fineTicks The fractional part of milliseconds, in 100-nanosecond + * ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than + * 9999 will add milliseconds or even seconds, but this can be + * confusing and therefore is discouraged. + */ + void setFileNTFSaTime(const QDateTime &aTime, int fineTicks = 0); + /// Sets the NTFS creation time. + /** + * The time is written into the NTFS record in + * both the local and the global extra fields, updating the existing record + * if there is one, or creating a new one and appending it to the end + * of each extra field. When updating an existing record, all other fields + * are left intact. + * @param cTime The new creation time. + * @param fineTicks The fractional part of milliseconds, in 100-nanosecond + * ticks (i. e. 9999 ticks = 999.9 microsecond). Values greater than + * 9999 will add milliseconds or even seconds, but this can be + * confusing and therefore is discouraged. + */ + void setFileNTFScTime(const QDateTime &cTime, int fineTicks = 0); +}; + +#endif diff --git a/include/unzip.h b/include/unzip.h new file mode 100644 index 00000000..da7b0628 --- /dev/null +++ b/include/unzip.h @@ -0,0 +1,458 @@ +/* unzip.h -- IO for uncompress .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications of Unzip for Zip64 + Copyright (C) 2007-2008 Even Rouault + + Modifications for Zip64 support on both zip and unzip + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + --------------------------------------------------------------------------------- + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + --------------------------------------------------------------------------------- + + Changes + + See header of unzip64.c + + --------------------------------------------------------------------------- + + As per the requirement above, this file is plainly marked as modified + by Sergey A. Tachenov. Most modifications include the I/O API redesign + to support QIODevice interface. Some improvements and small fixes were also made. +*/ + +#ifndef _unz64_H +#define _unz64_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#ifndef _ZLIBIOAPI_H +#include "ioapi.h" +#endif + +#ifdef HAVE_BZIP2 +#include "bzlib.h" +#endif + +#define Z_BZIP2ED 12 + +#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagunzFile__ { int unused; } unzFile__; +typedef unzFile__ *unzFile; +#else +typedef voidp unzFile; +#endif + + +#define UNZ_OK (0) +#define UNZ_END_OF_LIST_OF_FILE (-100) +#define UNZ_ERRNO (Z_ERRNO) +#define UNZ_EOF (0) +#define UNZ_PARAMERROR (-102) +#define UNZ_BADZIPFILE (-103) +#define UNZ_INTERNALERROR (-104) +#define UNZ_CRCERROR (-105) + +#define UNZ_AUTO_CLOSE 0x01u +#define UNZ_DEFAULT_FLAGS UNZ_AUTO_CLOSE + +/* tm_unz contain date/time info */ +typedef struct tm_unz_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_unz; + +/* unz_global_info structure contain global data about the ZIPfile + These data comes from the end of central dir */ +typedef struct unz_global_info64_s +{ + ZPOS64_T number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info64; + +typedef struct unz_global_info_s +{ + uLong number_entry; /* total number of entries in + the central dir on this disk */ + uLong size_comment; /* size of the global comment of the zipfile */ +} unz_global_info; + +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_info64_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + ZPOS64_T compressed_size; /* compressed size 8 bytes */ + ZPOS64_T uncompressed_size; /* uncompressed size 8 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info64; + +typedef struct unz_file_info_s +{ + uLong version; /* version made by 2 bytes */ + uLong version_needed; /* version needed to extract 2 bytes */ + uLong flag; /* general purpose bit flag 2 bytes */ + uLong compression_method; /* compression method 2 bytes */ + uLong dosDate; /* last mod file date in Dos fmt 4 bytes */ + uLong crc; /* crc-32 4 bytes */ + uLong compressed_size; /* compressed size 4 bytes */ + uLong uncompressed_size; /* uncompressed size 4 bytes */ + uLong size_filename; /* filename length 2 bytes */ + uLong size_file_extra; /* extra field length 2 bytes */ + uLong size_file_comment; /* file comment length 2 bytes */ + + uLong disk_num_start; /* disk number start 2 bytes */ + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ + + tm_unz tmu_date; +} unz_file_info; + +extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1, + const char* fileName2, + int iCaseSensitivity)); +/* + Compare two filename (fileName1,fileName2). + If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) + If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi + or strcasecmp) + If iCaseSenisivity = 0, case sensitivity is defaut of your operating system + (like 1 on Unix, 2 on Windows) +*/ + + +extern unzFile ZEXPORT unzOpen OF((voidpf file)); +extern unzFile ZEXPORT unzOpen64 OF((voidpf file)); +/* + Open a Zip file. path contain the full pathname (by example, + on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer + "zlib/zlib113.zip". + If the zipfile cannot be opened (file don't exist or in not valid), the + return value is NULL. + Else, the return value is a unzFile Handle, usable with other function + of this unzip package. + the "64" function take a const void* pointer, because the path is just the + value passed to the open64_file_func callback. + Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path + is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char* + does not describe the reality +*/ + + +extern unzFile ZEXPORT unzOpen2 OF((voidpf file, + zlib_filefunc_def* pzlib_filefunc_def)); +/* + Open a Zip file, like unzOpen, but provide a set of file low level API + for read/write the zip file (see ioapi.h) +*/ + +extern unzFile ZEXPORT unzOpen2_64 OF((voidpf file, + zlib_filefunc64_def* pzlib_filefunc_def)); +/* + Open a Zip file, like unz64Open, but provide a set of file low level API + for read/write the zip file (see ioapi.h) +*/ + + +/* + * Exported by Sergey A. Tachenov to implement some QuaZIP features. This + * function MAY change signature in order to implement even more features. + * You have been warned! + * */ +extern unzFile unzOpenInternal (voidpf file, + zlib_filefunc64_32_def* pzlib_filefunc64_32_def, + int is64bitOpenFunction, unsigned flags); + + + +extern int ZEXPORT unzClose OF((unzFile file)); +/* + Close a ZipFile opened with unzipOpen. + If there is files inside the .Zip opened with unzOpenCurrentFile (see later), + these files MUST be closed with unzipCloseCurrentFile before call unzipClose. + return UNZ_OK if there is no problem. */ + +extern int ZEXPORT unzGetGlobalInfo OF((unzFile file, + unz_global_info *pglobal_info)); + +extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file, + unz_global_info64 *pglobal_info)); +/* + Write info about the ZipFile in the *pglobal_info structure. + No preparation of the structure is needed + return UNZ_OK if there is no problem. */ + + +extern int ZEXPORT unzGetGlobalComment OF((unzFile file, + char *szComment, + uLong uSizeBuf)); +/* + Get the global comment string of the ZipFile, in the szComment buffer. + uSizeBuf is the size of the szComment buffer. + return the number of byte copied or an error code <0 +*/ + + +/***************************************************************************/ +/* Unzip package allow you browse the directory of the zipfile */ + +extern int ZEXPORT unzGoToFirstFile OF((unzFile file)); +/* + Set the current file of the zipfile to the first file. + return UNZ_OK if there is no problem +*/ + +extern int ZEXPORT unzGoToNextFile OF((unzFile file)); +/* + Set the current file of the zipfile to the next file. + return UNZ_OK if there is no problem + return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. +*/ + +extern int ZEXPORT unzLocateFile OF((unzFile file, + const char *szFileName, + int iCaseSensitivity)); +/* + Try locate the file szFileName in the zipfile. + For the iCaseSensitivity signification, see unzStringFileNameCompare + + return value : + UNZ_OK if the file is found. It becomes the current file. + UNZ_END_OF_LIST_OF_FILE if the file is not found +*/ + + +/* ****************************************** */ +/* Ryan supplied functions */ +/* unz_file_info contain information about a file in the zipfile */ +typedef struct unz_file_pos_s +{ + uLong pos_in_zip_directory; /* offset in zip file directory */ + uLong num_of_file; /* # of file */ +} unz_file_pos; + +extern int ZEXPORT unzGetFilePos( + unzFile file, + unz_file_pos* file_pos); + +extern int ZEXPORT unzGoToFilePos( + unzFile file, + unz_file_pos* file_pos); + +typedef struct unz64_file_pos_s +{ + ZPOS64_T pos_in_zip_directory; /* offset in zip file directory */ + ZPOS64_T num_of_file; /* # of file */ +} unz64_file_pos; + +extern int ZEXPORT unzGetFilePos64( + unzFile file, + unz64_file_pos* file_pos); + +extern int ZEXPORT unzGoToFilePos64( + unzFile file, + const unz64_file_pos* file_pos); + +/* ****************************************** */ + +extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file, + unz_file_info64 *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); + +extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file, + unz_file_info *pfile_info, + char *szFileName, + uLong fileNameBufferSize, + void *extraField, + uLong extraFieldBufferSize, + char *szComment, + uLong commentBufferSize)); +/* + Get Info about the current file + if pfile_info!=NULL, the *pfile_info structure will contain somes info about + the current file + if szFileName!=NULL, the filemane string will be copied in szFileName + (fileNameBufferSize is the size of the buffer) + if extraField!=NULL, the extra field information will be copied in extraField + (extraFieldBufferSize is the size of the buffer). + This is the Central-header version of the extra field + if szComment!=NULL, the comment string of the file will be copied in szComment + (commentBufferSize is the size of the buffer) +*/ + + +/** Addition for GDAL : START */ + +extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file)); + +/** Addition for GDAL : END */ + + +/***************************************************************************/ +/* for reading the content of the current zipfile, you can open it, read data + from it, and close it (you can close it before reading all the file) + */ + +extern int ZEXPORT unzOpenCurrentFile OF((unzFile file)); +/* + Open for reading data the current file in the zipfile. + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file, + const char* password)); +/* + Open for reading data the current file in the zipfile. + password is a crypting password + If there is no error, the return value is UNZ_OK. +*/ + +extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file, + int* method, + int* level, + int raw)); +/* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL +*/ + +extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file, + int* method, + int* level, + int raw, + const char* password)); +/* + Same than unzOpenCurrentFile, but open for read raw the file (not uncompress) + if raw==1 + *method will receive method of compression, *level will receive level of + compression + note : you can set level parameter as NULL (if you did not want known level, + but you CANNOT set method parameter as NULL +*/ + + +extern int ZEXPORT unzCloseCurrentFile OF((unzFile file)); +/* + Close the file in zip opened with unzOpenCurrentFile + Return UNZ_CRCERROR if all the file was read but the CRC is not good +*/ + +extern int ZEXPORT unzReadCurrentFile OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read bytes from the current file (opened by unzOpenCurrentFile) + buf contain buffer where data must be copied + len the size of buf. + + return the number of byte copied if somes bytes are copied + return 0 if the end of file was reached + return <0 with error code if there is an error + (UNZ_ERRNO for IO error, or zLib error for uncompress error) +*/ + +extern z_off_t ZEXPORT unztell OF((unzFile file)); + +extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file)); +/* + Give the current position in uncompressed data +*/ + +extern int ZEXPORT unzeof OF((unzFile file)); +/* + return 1 if the end of file was reached, 0 elsewhere +*/ + +extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, + voidp buf, + unsigned len)); +/* + Read extra field from the current file (opened by unzOpenCurrentFile) + This is the local-header version of the extra field (sometimes, there is + more info in the local-header version than in the central-header) + + if buf==NULL, it return the size of the local extra field + + if buf!=NULL, len is the size of the buffer, the extra header is copied in + buf. + the return value is the number of bytes copied in buf, or (if <0) + the error code +*/ + +/***************************************************************************/ + +/* Get the current file offset */ +extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file); +extern uLong ZEXPORT unzGetOffset (unzFile file); + +/* Set the current file offset */ +extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos); +extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); + +extern int ZEXPORT unzSetFlags(unzFile file, unsigned flags); +extern int ZEXPORT unzClearFlags(unzFile file, unsigned flags); + +#ifdef __cplusplus +} +#endif + +#endif /* _unz64_H */ diff --git a/include/zconf.h b/include/zconf.h new file mode 100644 index 00000000..352f552b --- /dev/null +++ b/include/zconf.h @@ -0,0 +1,536 @@ +/* zconf.h -- configuration of the zlib compression library + * Copyright (C) 1995-2016 Jean-loup Gailly, Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +/* @(#) $Id$ */ + +#ifndef ZCONF_H +#define ZCONF_H +/* #undef Z_PREFIX */ +/* #undef Z_HAVE_UNISTD_H */ + +/* + * If you *really* need a unique prefix for all types and library functions, + * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. + * Even better than compiling with -DZ_PREFIX would be to use configure to set + * this permanently in zconf.h using "./configure --zprefix". + */ +#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */ +# define Z_PREFIX_SET + +/* all linked symbols and init macros */ +# define _dist_code z__dist_code +# define _length_code z__length_code +# define _tr_align z__tr_align +# define _tr_flush_bits z__tr_flush_bits +# define _tr_flush_block z__tr_flush_block +# define _tr_init z__tr_init +# define _tr_stored_block z__tr_stored_block +# define _tr_tally z__tr_tally +# define adler32 z_adler32 +# define adler32_combine z_adler32_combine +# define adler32_combine64 z_adler32_combine64 +# define adler32_z z_adler32_z +# ifndef Z_SOLO +# define compress z_compress +# define compress2 z_compress2 +# define compressBound z_compressBound +# endif +# define crc32 z_crc32 +# define crc32_combine z_crc32_combine +# define crc32_combine64 z_crc32_combine64 +# define crc32_z z_crc32_z +# define deflate z_deflate +# define deflateBound z_deflateBound +# define deflateCopy z_deflateCopy +# define deflateEnd z_deflateEnd +# define deflateGetDictionary z_deflateGetDictionary +# define deflateInit z_deflateInit +# define deflateInit2 z_deflateInit2 +# define deflateInit2_ z_deflateInit2_ +# define deflateInit_ z_deflateInit_ +# define deflateParams z_deflateParams +# define deflatePending z_deflatePending +# define deflatePrime z_deflatePrime +# define deflateReset z_deflateReset +# define deflateResetKeep z_deflateResetKeep +# define deflateSetDictionary z_deflateSetDictionary +# define deflateSetHeader z_deflateSetHeader +# define deflateTune z_deflateTune +# define deflate_copyright z_deflate_copyright +# define get_crc_table z_get_crc_table +# ifndef Z_SOLO +# define gz_error z_gz_error +# define gz_intmax z_gz_intmax +# define gz_strwinerror z_gz_strwinerror +# define gzbuffer z_gzbuffer +# define gzclearerr z_gzclearerr +# define gzclose z_gzclose +# define gzclose_r z_gzclose_r +# define gzclose_w z_gzclose_w +# define gzdirect z_gzdirect +# define gzdopen z_gzdopen +# define gzeof z_gzeof +# define gzerror z_gzerror +# define gzflush z_gzflush +# define gzfread z_gzfread +# define gzfwrite z_gzfwrite +# define gzgetc z_gzgetc +# define gzgetc_ z_gzgetc_ +# define gzgets z_gzgets +# define gzoffset z_gzoffset +# define gzoffset64 z_gzoffset64 +# define gzopen z_gzopen +# define gzopen64 z_gzopen64 +# ifdef _WIN32 +# define gzopen_w z_gzopen_w +# endif +# define gzprintf z_gzprintf +# define gzputc z_gzputc +# define gzputs z_gzputs +# define gzread z_gzread +# define gzrewind z_gzrewind +# define gzseek z_gzseek +# define gzseek64 z_gzseek64 +# define gzsetparams z_gzsetparams +# define gztell z_gztell +# define gztell64 z_gztell64 +# define gzungetc z_gzungetc +# define gzvprintf z_gzvprintf +# define gzwrite z_gzwrite +# endif +# define inflate z_inflate +# define inflateBack z_inflateBack +# define inflateBackEnd z_inflateBackEnd +# define inflateBackInit z_inflateBackInit +# define inflateBackInit_ z_inflateBackInit_ +# define inflateCodesUsed z_inflateCodesUsed +# define inflateCopy z_inflateCopy +# define inflateEnd z_inflateEnd +# define inflateGetDictionary z_inflateGetDictionary +# define inflateGetHeader z_inflateGetHeader +# define inflateInit z_inflateInit +# define inflateInit2 z_inflateInit2 +# define inflateInit2_ z_inflateInit2_ +# define inflateInit_ z_inflateInit_ +# define inflateMark z_inflateMark +# define inflatePrime z_inflatePrime +# define inflateReset z_inflateReset +# define inflateReset2 z_inflateReset2 +# define inflateResetKeep z_inflateResetKeep +# define inflateSetDictionary z_inflateSetDictionary +# define inflateSync z_inflateSync +# define inflateSyncPoint z_inflateSyncPoint +# define inflateUndermine z_inflateUndermine +# define inflateValidate z_inflateValidate +# define inflate_copyright z_inflate_copyright +# define inflate_fast z_inflate_fast +# define inflate_table z_inflate_table +# ifndef Z_SOLO +# define uncompress z_uncompress +# define uncompress2 z_uncompress2 +# endif +# define zError z_zError +# ifndef Z_SOLO +# define zcalloc z_zcalloc +# define zcfree z_zcfree +# endif +# define zlibCompileFlags z_zlibCompileFlags +# define zlibVersion z_zlibVersion + +/* all zlib typedefs in zlib.h and zconf.h */ +# define Byte z_Byte +# define Bytef z_Bytef +# define alloc_func z_alloc_func +# define charf z_charf +# define free_func z_free_func +# ifndef Z_SOLO +# define gzFile z_gzFile +# endif +# define gz_header z_gz_header +# define gz_headerp z_gz_headerp +# define in_func z_in_func +# define intf z_intf +# define out_func z_out_func +# define uInt z_uInt +# define uIntf z_uIntf +# define uLong z_uLong +# define uLongf z_uLongf +# define voidp z_voidp +# define voidpc z_voidpc +# define voidpf z_voidpf + +/* all zlib structs in zlib.h and zconf.h */ +# define gz_header_s z_gz_header_s +# define internal_state z_internal_state + +#endif + +#if defined(__MSDOS__) && !defined(MSDOS) +# define MSDOS +#endif +#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2) +# define OS2 +#endif +#if defined(_WINDOWS) && !defined(WINDOWS) +# define WINDOWS +#endif +#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__) +# ifndef WIN32 +# define WIN32 +# endif +#endif +#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32) +# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__) +# ifndef SYS16BIT +# define SYS16BIT +# endif +# endif +#endif + +/* + * Compile with -DMAXSEG_64K if the alloc function cannot allocate more + * than 64k bytes at a time (needed on systems with 16-bit int). + */ +#ifdef SYS16BIT +# define MAXSEG_64K +#endif +#ifdef MSDOS +# define UNALIGNED_OK +#endif + +#ifdef __STDC_VERSION__ +# ifndef STDC +# define STDC +# endif +# if __STDC_VERSION__ >= 199901L +# ifndef STDC99 +# define STDC99 +# endif +# endif +#endif +#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus)) +# define STDC +#endif +#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__)) +# define STDC +#endif +#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32)) +# define STDC +#endif +#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__)) +# define STDC +#endif + +#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */ +# define STDC +#endif + +#ifndef STDC +# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */ +# define const /* note: need a more gentle solution here */ +# endif +#endif + +#if defined(ZLIB_CONST) && !defined(z_const) +# define z_const const +#else +# define z_const +#endif + +#ifdef Z_SOLO + typedef unsigned long z_size_t; +#else +# define z_longlong long long +# if defined(NO_SIZE_T) + typedef unsigned NO_SIZE_T z_size_t; +# elif defined(STDC) +# include + typedef size_t z_size_t; +# else + typedef unsigned long z_size_t; +# endif +# undef z_longlong +#endif + +/* Maximum value for memLevel in deflateInit2 */ +#ifndef MAX_MEM_LEVEL +# ifdef MAXSEG_64K +# define MAX_MEM_LEVEL 8 +# else +# define MAX_MEM_LEVEL 9 +# endif +#endif + +/* Maximum value for windowBits in deflateInit2 and inflateInit2. + * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files + * created by gzip. (Files created by minigzip can still be extracted by + * gzip.) + */ +#ifndef MAX_WBITS +# define MAX_WBITS 15 /* 32K LZ77 window */ +#endif + +/* The memory requirements for deflate are (in bytes): + (1 << (windowBits+2)) + (1 << (memLevel+9)) + that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values) + plus a few kilobytes for small objects. For example, if you want to reduce + the default memory requirements from 256K to 128K, compile with + make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7" + Of course this will generally degrade compression (there's no free lunch). + + The memory requirements for inflate are (in bytes) 1 << windowBits + that is, 32K for windowBits=15 (default value) plus about 7 kilobytes + for small objects. +*/ + + /* Type declarations */ + +#ifndef OF /* function prototypes */ +# ifdef STDC +# define OF(args) args +# else +# define OF(args) () +# endif +#endif + +#ifndef Z_ARG /* function prototypes for stdarg */ +# if defined(STDC) || defined(Z_HAVE_STDARG_H) +# define Z_ARG(args) args +# else +# define Z_ARG(args) () +# endif +#endif + +/* The following definitions for FAR are needed only for MSDOS mixed + * model programming (small or medium model with some far allocations). + * This was tested only with MSC; for other MSDOS compilers you may have + * to define NO_MEMCPY in zutil.h. If you don't need the mixed model, + * just define FAR to be empty. + */ +#ifdef SYS16BIT +# if defined(M_I86SM) || defined(M_I86MM) + /* MSC small or medium model */ +# define SMALL_MEDIUM +# ifdef _MSC_VER +# define FAR _far +# else +# define FAR far +# endif +# endif +# if (defined(__SMALL__) || defined(__MEDIUM__)) + /* Turbo C small or medium model */ +# define SMALL_MEDIUM +# ifdef __BORLANDC__ +# define FAR _far +# else +# define FAR far +# endif +# endif +#endif + +#if defined(WINDOWS) || defined(WIN32) + /* If building or using zlib as a DLL, define ZLIB_DLL. + * This is not mandatory, but it offers a little performance increase. + */ +# ifdef ZLIB_DLL +# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500)) +# ifdef ZLIB_INTERNAL +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +# endif +# endif /* ZLIB_DLL */ + /* If building or using zlib with the WINAPI/WINAPIV calling convention, + * define ZLIB_WINAPI. + * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI. + */ +# ifdef ZLIB_WINAPI +# ifdef FAR +# undef FAR +# endif +# include + /* No need for _export, use ZLIB.DEF instead. */ + /* For complete Windows compatibility, use WINAPI, not __stdcall. */ +# define ZEXPORT WINAPI +# ifdef WIN32 +# define ZEXPORTVA WINAPIV +# else +# define ZEXPORTVA FAR CDECL +# endif +# endif +#endif + +#if defined (__BEOS__) +# ifdef ZLIB_DLL +# ifdef ZLIB_INTERNAL +# define ZEXPORT __declspec(dllexport) +# define ZEXPORTVA __declspec(dllexport) +# else +# define ZEXPORT __declspec(dllimport) +# define ZEXPORTVA __declspec(dllimport) +# endif +# endif +#endif + +#ifndef ZEXTERN +# define ZEXTERN extern +#endif +#ifndef ZEXPORT +# define ZEXPORT +#endif +#ifndef ZEXPORTVA +# define ZEXPORTVA +#endif + +#ifndef FAR +# define FAR +#endif + +#if !defined(__MACTYPES__) +typedef unsigned char Byte; /* 8 bits */ +#endif +typedef unsigned int uInt; /* 16 bits or more */ +typedef unsigned long uLong; /* 32 bits or more */ + +#ifdef SMALL_MEDIUM + /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */ +# define Bytef Byte FAR +#else + typedef Byte FAR Bytef; +#endif +typedef char FAR charf; +typedef int FAR intf; +typedef uInt FAR uIntf; +typedef uLong FAR uLongf; + +#ifdef STDC + typedef void const *voidpc; + typedef void FAR *voidpf; + typedef void *voidp; +#else + typedef Byte const *voidpc; + typedef Byte FAR *voidpf; + typedef Byte *voidp; +#endif + +#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC) +# include +# if (UINT_MAX == 0xffffffffUL) +# define Z_U4 unsigned +# elif (ULONG_MAX == 0xffffffffUL) +# define Z_U4 unsigned long +# elif (USHRT_MAX == 0xffffffffUL) +# define Z_U4 unsigned short +# endif +#endif + +#ifdef Z_U4 + typedef Z_U4 z_crc_t; +#else + typedef unsigned long z_crc_t; +#endif + +#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_UNISTD_H +#endif + +#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */ +# define Z_HAVE_STDARG_H +#endif + +#ifdef STDC +# ifndef Z_SOLO +# include /* for off_t */ +# endif +#endif + +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifndef Z_SOLO +# include /* for va_list */ +# endif +#endif + +#ifdef _WIN32 +# ifndef Z_SOLO +# include /* for wchar_t */ +# endif +#endif + +/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and + * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even + * though the former does not conform to the LFS document), but considering + * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as + * equivalently requesting no 64-bit operations + */ +#if defined(_LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1 +# undef _LARGEFILE64_SOURCE +#endif + +#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H) +# define Z_HAVE_UNISTD_H +#endif +#ifndef Z_SOLO +# if defined(Z_HAVE_UNISTD_H) || defined(_LARGEFILE64_SOURCE) +# include /* for SEEK_*, off_t, and _LFS64_LARGEFILE */ +# ifdef VMS +# include /* for off_t */ +# endif +# ifndef z_off_t +# define z_off_t off_t +# endif +# endif +#endif + +#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0 +# define Z_LFS64 +#endif + +#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64) +# define Z_LARGE64 +#endif + +#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64) +# define Z_WANT64 +#endif + +#if !defined(SEEK_SET) && !defined(Z_SOLO) +# define SEEK_SET 0 /* Seek from beginning of file. */ +# define SEEK_CUR 1 /* Seek from current position. */ +# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */ +#endif + +#ifndef z_off_t +# define z_off_t long +#endif + +#if !defined(_WIN32) && defined(Z_LARGE64) +# define z_off64_t off64_t +#else +# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO) +# define z_off64_t __int64 +# else +# define z_off64_t z_off_t +# endif +#endif + +/* MVS linker does not support external names larger than 8 bytes */ +#if defined(__MVS__) + #pragma map(deflateInit_,"DEIN") + #pragma map(deflateInit2_,"DEIN2") + #pragma map(deflateEnd,"DEEND") + #pragma map(deflateBound,"DEBND") + #pragma map(inflateInit_,"ININ") + #pragma map(inflateInit2_,"ININ2") + #pragma map(inflateEnd,"INEND") + #pragma map(inflateSync,"INSY") + #pragma map(inflateSetDictionary,"INSEDI") + #pragma map(compressBound,"CMBND") + #pragma map(inflate_table,"INTABL") + #pragma map(inflate_fast,"INFA") + #pragma map(inflate_copyright,"INCOPY") +#endif + +#endif /* ZCONF_H */ diff --git a/include/zip.h b/include/zip.h new file mode 100644 index 00000000..a6617add --- /dev/null +++ b/include/zip.h @@ -0,0 +1,390 @@ +/* zip.h -- IO on .zip files using zlib + Version 1.1, February 14h, 2010 + part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications for Zip64 support + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) + + For more info read MiniZip_info.txt + + --------------------------------------------------------------------------- + + Condition of use and distribution are the same than zlib : + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + --------------------------------------------------------------------------- + + Changes + + See header of zip.h + + --------------------------------------------------------------------------- + + As per the requirement above, this file is plainly marked as modified + by Sergey A. Tachenov. Most modifications include the I/O API redesign + to support QIODevice interface. Some improvements and small fixes were also made. + +*/ + +#ifndef _zip12_H +#define _zip12_H + +#ifdef __cplusplus +extern "C" { +#endif + +//#define HAVE_BZIP2 + +#ifndef _ZLIB_H +#include "zlib.h" +#endif + +#ifndef _ZLIBIOAPI_H +#include "ioapi.h" +#endif + +#ifdef HAVE_BZIP2 +#include "bzlib.h" +#endif + +#define Z_BZIP2ED 12 + +#if defined(STRICTZIP) || defined(STRICTZIPUNZIP) +/* like the STRICT of WIN32, we define a pointer that cannot be converted + from (void*) without cast */ +typedef struct TagzipFile__ { int unused; } zipFile__; +typedef zipFile__ *zipFile; +#else +typedef voidp zipFile; +#endif + +#define ZIP_OK (0) +#define ZIP_EOF (0) +#define ZIP_ERRNO (Z_ERRNO) +#define ZIP_PARAMERROR (-102) +#define ZIP_BADZIPFILE (-103) +#define ZIP_INTERNALERROR (-104) + +#define ZIP_WRITE_DATA_DESCRIPTOR 0x8u +#define ZIP_AUTO_CLOSE 0x1u +#define ZIP_SEQUENTIAL 0x2u +#define ZIP_DEFAULT_FLAGS (ZIP_AUTO_CLOSE | ZIP_WRITE_DATA_DESCRIPTOR) + +#ifndef DEF_MEM_LEVEL +# if MAX_MEM_LEVEL >= 8 +# define DEF_MEM_LEVEL 8 +# else +# define DEF_MEM_LEVEL MAX_MEM_LEVEL +# endif +#endif +/* default memLevel */ + +/* tm_zip contain date/time info */ +typedef struct tm_zip_s +{ + uInt tm_sec; /* seconds after the minute - [0,59] */ + uInt tm_min; /* minutes after the hour - [0,59] */ + uInt tm_hour; /* hours since midnight - [0,23] */ + uInt tm_mday; /* day of the month - [1,31] */ + uInt tm_mon; /* months since January - [0,11] */ + uInt tm_year; /* years - [1980..2044] */ +} tm_zip; + +typedef struct +{ + tm_zip tmz_date; /* date in understandable format */ + uLong dosDate; /* if dos_date == 0, tmu_date is used */ +/* uLong flag; */ /* general purpose bit flag 2 bytes */ + + uLong internal_fa; /* internal file attributes 2 bytes */ + uLong external_fa; /* external file attributes 4 bytes */ +} zip_fileinfo; + +typedef const char* zipcharpc; + + +#define APPEND_STATUS_CREATE (0) +#define APPEND_STATUS_CREATEAFTER (1) +#define APPEND_STATUS_ADDINZIP (2) + +extern zipFile ZEXPORT zipOpen OF((voidpf file, int append)); +extern zipFile ZEXPORT zipOpen64 OF((voidpf file, int append)); +/* + Create a zipfile. + the file argument depends on the API used, for QuaZIP it's a QIODevice + pointer. + if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip + will be created at the end of the file. + (useful if the file contain a self extractor code) + if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will + add files in existing zip (be sure you don't add file that doesn't exist) + If the zipfile cannot be opened, the return value is NULL. + Else, the return value is a zipFile Handle, usable with other function + of this zip package. +*/ + +/* Note : there is no delete function into a zipfile. + If you want delete file into a zipfile, you must open a zipfile, and create another + Of couse, you can use RAW reading and writing to copy the file you did not want delte +*/ + +extern zipFile ZEXPORT zipOpen2 OF((voidpf file, + int append, + zipcharpc* globalcomment, + zlib_filefunc_def* pzlib_filefunc_def)); + +extern zipFile ZEXPORT zipOpen2_64 OF((voidpf file, + int append, + zipcharpc* globalcomment, + zlib_filefunc64_def* pzlib_filefunc_def)); + +/* + * Exported by Sergey A. Tachenov to suit the needs of QuaZIP. + * Note that this function MAY change signature in order to + * provide new QuaZIP features. You have been warned! + * */ +extern zipFile ZEXPORT zipOpen3 (voidpf file, + int append, + zipcharpc* globalcomment, + zlib_filefunc64_32_def* pzlib_filefunc64_32_def, + unsigned flags); + +extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level)); + +extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int zip64)); + +/* + Open a file in the ZIP for writing. + filename : the filename in zip (if NULL, '-' without quote will be used + *zipfi contain supplemental information + if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local + contains the extrafield data the the local header + if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global + contains the extrafield data the the local header + if comment != NULL, comment contain the comment string + method contain the compression method (0 for store, Z_DEFLATED for deflate) + level contain the level of compression (can be Z_DEFAULT_COMPRESSION) + zip64 is set to 1 if a zip64 extended information block should be added to the local file header. + this MUST be '1' if the uncompressed size is >= 0xffffffff. + +*/ + + +extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw)); + + +extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int zip64)); +/* + Same than zipOpenNewFileInZip, except if raw=1, we write raw file + */ + +extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting)); + +extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting, + int zip64 + )); + +/* + Same than zipOpenNewFileInZip2, except + windowBits,memLevel,,strategy : see parameter strategy in deflateInit2 + password : crypting password (NULL for no crypting) + crcForCrypting : crc of file to compress (needed for crypting) + */ + +extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting, + uLong versionMadeBy, + uLong flagBase + )); + + +extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file, + const char* filename, + const zip_fileinfo* zipfi, + const void* extrafield_local, + uInt size_extrafield_local, + const void* extrafield_global, + uInt size_extrafield_global, + const char* comment, + int method, + int level, + int raw, + int windowBits, + int memLevel, + int strategy, + const char* password, + uLong crcForCrypting, + uLong versionMadeBy, + uLong flagBase, + int zip64 + )); +/* + Same than zipOpenNewFileInZip4, except + versionMadeBy : value for Version made by field + flag : value for flag field (compression level info will be added) + */ + + +extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, + const void* buf, + unsigned len)); +/* + Write data in the zipfile +*/ + +extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); +/* + Close the current file in the zipfile +*/ + +extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, + uLong uncompressed_size, + uLong crc32)); + +extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file, + ZPOS64_T uncompressed_size, + uLong crc32)); + +/* + Close the current file in the zipfile, for file opened with + parameter raw=1 in zipOpenNewFileInZip2 + uncompressed_size and crc32 are value for the uncompressed size +*/ + +extern int ZEXPORT zipClose OF((zipFile file, + const char* global_comment)); +/* + Close the zipfile +*/ + + +extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader)); +/* + zipRemoveExtraInfoBlock - Added by Mathias Svensson + + Remove extra information block from a extra information data for the local file header or central directory header + + It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode. + + 0x0001 is the signature header for the ZIP64 extra information blocks + + usage. + Remove ZIP64 Extra information from a central director extra field data + zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001); + + Remove ZIP64 Extra information from a Local File Header extra field data + zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001); +*/ + +/* + Added by Sergey A. Tachenov to tweak zipping behaviour. +*/ +extern int ZEXPORT zipSetFlags(zipFile file, unsigned flags); +extern int ZEXPORT zipClearFlags(zipFile file, unsigned flags); + +#ifdef __cplusplus +} +#endif + +#endif /* _zip64_H */ diff --git a/include/zlib.h b/include/zlib.h new file mode 100644 index 00000000..f09cdaf1 --- /dev/null +++ b/include/zlib.h @@ -0,0 +1,1912 @@ +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.11, January 15th, 2017 + + Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 + (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). +*/ + +#ifndef ZLIB_H +#define ZLIB_H + +#include "zconf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define ZLIB_VERSION "1.2.11" +#define ZLIB_VERNUM 0x12b0 +#define ZLIB_VER_MAJOR 1 +#define ZLIB_VER_MINOR 2 +#define ZLIB_VER_REVISION 11 +#define ZLIB_VER_SUBREVISION 0 + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed data. + This version of the library supports only one compression method (deflation) + but other algorithms will be added later and will have the same stream + interface. + + Compression can be done in a single step if the buffers are large enough, + or can be done by repeated calls of the compression function. In the latter + case, the application must provide more input and/or consume the output + (providing more output space) before each call. + + The compressed data format used by default by the in-memory functions is + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped + around a deflate stream, which is itself documented in RFC 1951. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio using the functions that start + with "gz". The gzip format is different from the zlib format. gzip is a + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. + + This library can optionally read and write gzip and raw deflate streams in + memory as well. + + The zlib format was designed to be compact and fast for use in memory + and on communications channels. The gzip format was designed for single- + file compression on file systems, has a larger header than zlib to maintain + directory information, and uses a different, slower check method than zlib. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never crash + even in the case of corrupted input. +*/ + +typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); +typedef void (*free_func) OF((voidpf opaque, voidpf address)); + +struct internal_state; + +typedef struct z_stream_s { + z_const Bytef *next_in; /* next input byte */ + uInt avail_in; /* number of bytes available at next_in */ + uLong total_in; /* total number of input bytes read so far */ + + Bytef *next_out; /* next output byte will go here */ + uInt avail_out; /* remaining free space at next_out */ + uLong total_out; /* total number of bytes output so far */ + + z_const char *msg; /* last error message, NULL if no error */ + struct internal_state FAR *state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + voidpf opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text + for deflate, or the decoding state for inflate */ + uLong adler; /* Adler-32 or CRC-32 value of the uncompressed data */ + uLong reserved; /* reserved for future use */ +} z_stream; + +typedef z_stream FAR *z_streamp; + +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +typedef struct gz_header_s { + int text; /* true if compressed data believed to be text */ + uLong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + Bytef *extra; /* pointer to extra field or Z_NULL if none */ + uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ + uInt extra_max; /* space at extra (only when reading header) */ + Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ + uInt name_max; /* space at name (only when reading header) */ + Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ + uInt comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} gz_header; + +typedef gz_header FAR *gz_headerp; + +/* + The application must update next_in and avail_in when avail_in has dropped + to zero. It must update next_out and avail_out when avail_out has dropped + to zero. The application must initialize zalloc, zfree and opaque before + calling the init function. All other fields are set by the compression + library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. In that case, zlib is thread-safe. When zalloc and zfree are + Z_NULL on entry to the initialization function, they are set to internal + routines that use the standard library functions malloc() and free(). + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this if + the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers + returned by zalloc for objects of exactly 65536 bytes *must* have their + offset normalized to zero. The default allocation function provided by this + library ensures this (see zutil.c). To reduce memory requirements and avoid + any allocation of 64K objects, at the expense of compression ratio, compile + the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or progress + reports. After compression, total_in holds the total size of the + uncompressed data and may be saved for use by the decompressor (particularly + if the decompressor wants to decompress everything in a single step). +*/ + + /* constants */ + +#define Z_NO_FLUSH 0 +#define Z_PARTIAL_FLUSH 1 +#define Z_SYNC_FLUSH 2 +#define Z_FULL_FLUSH 3 +#define Z_FINISH 4 +#define Z_BLOCK 5 +#define Z_TREES 6 +/* Allowed flush values; see deflate() and inflate() below for details */ + +#define Z_OK 0 +#define Z_STREAM_END 1 +#define Z_NEED_DICT 2 +#define Z_ERRNO (-1) +#define Z_STREAM_ERROR (-2) +#define Z_DATA_ERROR (-3) +#define Z_MEM_ERROR (-4) +#define Z_BUF_ERROR (-5) +#define Z_VERSION_ERROR (-6) +/* Return codes for the compression/decompression functions. Negative values + * are errors, positive values are used for special but normal events. + */ + +#define Z_NO_COMPRESSION 0 +#define Z_BEST_SPEED 1 +#define Z_BEST_COMPRESSION 9 +#define Z_DEFAULT_COMPRESSION (-1) +/* compression levels */ + +#define Z_FILTERED 1 +#define Z_HUFFMAN_ONLY 2 +#define Z_RLE 3 +#define Z_FIXED 4 +#define Z_DEFAULT_STRATEGY 0 +/* compression strategy; see deflateInit2() below for details */ + +#define Z_BINARY 0 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ +#define Z_UNKNOWN 2 +/* Possible values of the data_type field for deflate() */ + +#define Z_DEFLATED 8 +/* The deflate compression method (the only one supported in this version) */ + +#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ + +#define zlib_version zlibVersion() +/* for compatibility with versions < 1.0.2 */ + + + /* basic functions */ + +ZEXTERN const char * ZEXPORT zlibVersion OF((void)); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is not + compatible with the zlib.h header file used by the application. This check + is automatically made by deflateInit and inflateInit. + */ + +/* +ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); + + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. If + zalloc and zfree are set to Z_NULL, deflateInit updates them to use default + allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at all + (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION + requests a default compromise between speed and compression (currently + equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if level is not a valid compression level, or + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). msg is set to null + if there is no error message. deflateInit does not perform any compression: + this will be done by deflate(). +*/ + + +ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Generate more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary. Some output may be provided even if + flush is zero. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating avail_in or avail_out accordingly; avail_out should + never be zero before the call. The application can consume the compressed + output when it wants, for example when the output buffer is full (avail_out + == 0), or after each call of deflate(). If deflate returns Z_OK and with + zero avail_out, it must be called again after making room in the output + buffer because there might be more output pending. See deflatePending(), + which can be used if desired to determine whether or not there is more ouput + in that case. + + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumulate before producing output, in order to + maximize compression. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In + particular avail_in is zero after the call if enough output space has been + provided before the call.) Flushing may degrade compression for some + compression algorithms and so it should be used only when necessary. This + completes the current deflate block and follows it with an empty stored block + that is three bits plus filler bits to the next byte, followed by four bytes + (00 00 ff ff). + + If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the + output buffer, but the output is not aligned to a byte boundary. All of the + input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. + This completes the current deflate block and follows it with an empty fixed + codes block that is 10 bits long. This assures that enough bytes are output + in order for the decompressor to finish the block before the empty fixed + codes block. + + If flush is set to Z_BLOCK, a deflate block is completed and emitted, as + for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to + seven bits of the current block are held to be written as the next byte after + the next deflate block is completed. In this case, the decompressor may not + be provided enough bits at this point in order to complete decompression of + the data provided so far to the compressor. It may need to wait for the next + block to be emitted. This is for advanced applications that need to control + the emission of deflate blocks. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out is greater than six to avoid repeated flush markers due to + avail_out == 0 on return. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there was + enough output space. If deflate returns with Z_OK or Z_BUF_ERROR, this + function must be called again with Z_FINISH and more output space (updated + avail_out) but no more input data, until it returns with Z_STREAM_END or an + error. After deflate has returned Z_STREAM_END, the only possible operations + on the stream are deflateReset or deflateEnd. + + Z_FINISH can be used in the first deflate call after deflateInit if all the + compression is to be done in a single step. In order to complete in one + call, avail_out must be at least the value returned by deflateBound (see + below). Then deflate is guaranteed to return Z_STREAM_END. If not enough + output space is provided, deflate will not return Z_STREAM_END, and it must + be called again as described above. + + deflate() sets strm->adler to the Adler-32 checksum of all input read + so far (that is, total_in bytes). If a gzip stream is being generated, then + strm->adler will be the CRC-32 checksum of the input read so far. (See + deflateInit2 below.) + + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). If in doubt, the data is + considered binary. This field is only for information purposes and does not + affect the compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was Z_NULL or the state was inadvertently written over + by the application), or Z_BUF_ERROR if no progress is possible (for example + avail_in or avail_out was zero). Note that Z_BUF_ERROR is not fatal, and + deflate() can be called again with more input and more output space to + continue compressing. +*/ + + +ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, msg + may be set but then points to a static string (which must not be + deallocated). +*/ + + +/* +ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); + + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. In the current version of inflate, the provided input is not + read or consumed. The allocation of a sliding window will be deferred to + the first call of inflate (if the decompression does not complete on the + first call). If zalloc and zfree are set to Z_NULL, inflateInit updates + them to use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit does not perform any decompression. + Actual decompression will be done by inflate(). So next_in, and avail_in, + next_out, and avail_out are unused and unchanged. The current + implementation of inflateInit() does not process any header information -- + that is deferred until inflate() is called. +*/ + + +ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), then next_in and avail_in are updated + accordingly, and processing will resume at this point for the next call of + inflate(). + + - Generate more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there is + no more input data or no more space in the output buffer (see below about + the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating the next_* and avail_* values accordingly. If the + caller of inflate() does not provide both available input and available + output space, it is possible that there will be no progress made. The + application can consume the uncompressed output when it wants, for example + when the output buffer is full (avail_out == 0), or after each call of + inflate(). If inflate returns Z_OK and with zero avail_out, it must be + called again after making room in the output buffer because there might be + more output pending. + + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, + Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() + stop if and when it gets to the next deflate block boundary. When decoding + the zlib or gzip format, this will cause inflate() to return immediately + after the header and before the first block. When doing a raw inflate, + inflate() will go ahead and process the first block, and will return when it + gets to the end of that block, or when it runs out of data. + + The Z_BLOCK option assists in appending to or combining deflate streams. + To assist in this, on return inflate() always sets strm->data_type to the + number of unused bits in the last byte taken from strm->next_in, plus 64 if + inflate() is currently decoding the last block in the deflate stream, plus + 128 if inflate() returned immediately after decoding an end-of-block code or + decoding the complete header up to just before the first byte of the deflate + stream. The end-of-block will not be indicated until all of the uncompressed + data from that block has been written to strm->next_out. The number of + unused bits may in general be greater than seven, except when bit 7 of + data_type is set, in which case the number of unused bits will be less than + eight. data_type is set as noted here every time inflate() returns for all + flush options, and so can be used to determine the amount of currently + consumed input in bits. + + The Z_TREES option behaves as Z_BLOCK does, but it also returns when the + end of each deflate block header is reached, before any actual data in that + block is decoded. This allows the caller to determine the length of the + deflate block header for later use in random access within a deflate block. + 256 is added to the value of strm->data_type when inflate() returns + immediately after reaching the end of the deflate block header. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step (a + single call of inflate), the parameter flush should be set to Z_FINISH. In + this case all pending input is processed and all pending output is flushed; + avail_out must be large enough to hold all of the uncompressed data for the + operation to complete. (The size of the uncompressed data may have been + saved by the compressor for this purpose.) The use of Z_FINISH is not + required to perform an inflation in one step. However it may be used to + inform inflate that a faster approach can be used for the single inflate() + call. Z_FINISH also informs inflate to not maintain a sliding window if the + stream completes, which reduces inflate's memory footprint. If the stream + does not complete, either because not all of the stream is provided or not + enough output space is provided, then a sliding window will be allocated and + inflate() can be called again to continue the operation as if Z_NO_FLUSH had + been used. + + In this implementation, inflate() always flushes as much output as + possible to the output buffer, and always uses the faster approach on the + first call. So the effects of the flush parameter in this implementation are + on the return value of inflate() as noted below, when inflate() returns early + when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of + memory for a sliding window when Z_FINISH is used. + + If a preset dictionary is needed after this call (see inflateSetDictionary + below), inflate sets strm->adler to the Adler-32 checksum of the dictionary + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets + strm->adler to the Adler-32 checksum of all output produced so far (that is, + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described + below. At the end of the stream, inflate() checks that its computed Adler-32 + checksum is equal to that saved by the compressor and returns Z_STREAM_END + only if the checksum is correct. + + inflate() can decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically, if requested when + initializing with inflateInit2(). Any information contained in the gzip + header is not retained unless inflateGetHeader() is used. When processing + gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output + produced so far. The CRC-32 is checked against the gzip trailer, as is the + uncompressed length, modulo 2^32. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect check + value, in which case strm->msg points to a string with a more specific + error), Z_STREAM_ERROR if the stream structure was inconsistent (for example + next_in or next_out was Z_NULL, or the state was inadvertently written over + by the application), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR + if no progress was possible or if there was not enough room in the output + buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + inflate() can be called again with more input and more output space to + continue decompressing. If Z_DATA_ERROR is returned, the application may + then call inflateSync() to look for a good compression block if a partial + recovery of the data is to be attempted. +*/ + + +ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + inflateEnd returns Z_OK if success, or Z_STREAM_ERROR if the stream state + was inconsistent. +*/ + + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +/* +ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy)); + + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by the + caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8..15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + For the current implementation of deflate(), a windowBits value of 8 (a + window size of 256 bytes) is not supported. As a result, a request for 8 + will result in 9 (a 512-byte window). In that case, providing 8 to + inflateInit2() will result in an error when the zlib header with 9 is + checked against the initialization of inflate(). The remedy is to not use 8 + with deflateInit2() with this initialization, or at least in that case use 9 + with inflateInit2(). + + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data + with no zlib header or trailer, and will not compute a check value. + + windowBits can also be greater than 15 for optional gzip encoding. Add + 16 to windowBits to write a simple gzip header and trailer around the + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), no + header crc, and the operating system will be set to the appropriate value, + if the operating system was determined at compile time. If a gzip stream is + being written, strm->adler is a CRC-32 instead of an Adler-32. + + For raw deflate or gzip encoding, a request for a 256-byte window is + rejected as invalid, since only the zlib header provides a means of + transmitting the window size to the decompressor. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but is + slow and reduces compression ratio; memLevel=9 uses maximum memory for + optimal speed. The default value is 8. See zconf.h for total memory usage + as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match), or Z_RLE to limit match distances to one (run-length + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman + coding and less string matching; it is somewhat intermediate between + Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as + fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The + strategy parameter only affects the compression ratio but not the + correctness of the compressed output even if it is not set appropriately. + Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler + decoder for special applications. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid + method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is + incompatible with the version assumed by the caller (ZLIB_VERSION). msg is + set to null if there is no error message. deflateInit2 does not perform any + compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. When using the zlib format, this + function must be called immediately after deflateInit, deflateInit2 or + deflateReset, and before any call of deflate. When doing raw deflate, this + function must be called either before any call of deflate, or immediately + after the completion of a deflate block, i.e. after all input has been + consumed and all output has been delivered when using any of the flush + options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The + compressor and decompressor must use exactly the same dictionary (see + inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size + provided in deflateInit or deflateInit2. Thus the strings most likely to be + useful should be put at the end of the dictionary, not at the front. In + addition, the current implementation of deflate will use at most the window + size minus 262 bytes of the provided dictionary. + + Upon return of this function, strm->adler is set to the Adler-32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The Adler-32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) If a raw deflate was requested, then the + Adler-32 value is not computed and strm->adler is not set. + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if not at a block boundary for raw deflate). deflateSetDictionary does + not perform any compression: this will be done by deflate(). +*/ + +ZEXTERN int ZEXPORT deflateGetDictionary OF((z_streamp strm, + Bytef *dictionary, + uInt *dictLength)); +/* + Returns the sliding dictionary being maintained by deflate. dictLength is + set to the number of bytes in the dictionary, and that many bytes are copied + to dictionary. dictionary must have enough space, where 32768 bytes is + always enough. If deflateGetDictionary() is called with dictionary equal to + Z_NULL, then only the dictionary length is returned, and nothing is copied. + Similary, if dictLength is Z_NULL, then it is not set. + + deflateGetDictionary() may return a length less than the window size, even + when more than the window size in input has been provided. It may return up + to 258 bytes less in that case, due to how zlib's implementation of deflate + manages the sliding window and lookahead for matches, where matches can be + up to 258 bytes long. If the application needs the last window-size bytes of + input, then that would need to be saved by the application outside of zlib. + + deflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the + stream state is inconsistent. +*/ + +ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and can + consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); +/* + This function is equivalent to deflateEnd followed by deflateInit, but + does not free and reallocate the internal compression state. The stream + will leave the compression level and any other attributes that may have been + set unchanged. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, + int level, + int strategy)); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2(). This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different strategy. + If the compression approach (which is a function of the level) or the + strategy is changed, and if any input has been consumed in a previous + deflate() call, then the input available so far is compressed with the old + level and strategy using deflate(strm, Z_BLOCK). There are three approaches + for the compression levels 0, 1..3, and 4..9 respectively. The new level + and strategy will take effect at the next call of deflate(). + + If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does + not have enough output space to complete, then the parameter change will not + take effect. In this case, deflateParams() can be called again with the + same parameters and more output space to try again. + + In order to assure a change in the parameters on the first try, the + deflate stream should be flushed using deflate() with Z_BLOCK or other flush + request until strm.avail_out is not zero, before calling deflateParams(). + Then no more input data should be provided before the deflateParams() call. + If this is done, the old level and strategy will be applied to the data + compressed before deflateParams(), and the new level and strategy will be + applied to the the data compressed after deflateParams(). + + deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream + state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if + there was not enough output space to complete the compression of the + available input data before a change in the strategy or approach. Note that + in the case of a Z_BUF_ERROR, the parameters are not changed. A return + value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be + retried with more output space. +*/ + +ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, + int good_length, + int max_lazy, + int nice_length, + int max_chain)); +/* + Fine tune deflate's internal compression parameters. This should only be + used by someone who understands the algorithm used by zlib's deflate for + searching for the best matching string, and even then only by the most + fanatic optimizer trying to squeeze out the last compressed bit for their + specific input data. Read the deflate.c source code for the meaning of the + max_lazy, good_length, nice_length, and max_chain parameters. + + deflateTune() can be called after deflateInit() or deflateInit2(), and + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. + */ + +ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, + uLong sourceLen)); +/* + deflateBound() returns an upper bound on the compressed size after + deflation of sourceLen bytes. It must be called after deflateInit() or + deflateInit2(), and after deflateSetHeader(), if used. This would be used + to allocate an output buffer for deflation in a single pass, and so would be + called before deflate(). If that first deflate() call is provided the + sourceLen input bytes, an output buffer allocated to the size returned by + deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed + to return Z_STREAM_END. Note that it is possible for the compressed size to + be larger than the value returned by deflateBound() if flush options other + than Z_FINISH or Z_NO_FLUSH are used. +*/ + +ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm, + unsigned *pending, + int *bits)); +/* + deflatePending() returns the number of bytes and bits of output that have + been generated, but not yet provided in the available output. The bytes not + provided would be due to the available output space having being consumed. + The number of bits of output not provided are between 0 and 7, where they + await more bits to join them in order to fill out a full byte. If pending + or bits are Z_NULL, then those values are not set. + + deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. + */ + +ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + deflatePrime() inserts bits in the deflate output stream. The intent + is that this function is used to start off the deflate output with the bits + leftover from a previous deflate stream when appending to it. As such, this + function can only be used for raw deflate, and must be used before the first + deflate() call after a deflateInit2() or deflateReset(). bits must be less + than or equal to 16, and that many of the least significant bits of value + will be inserted in the output. + + deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough + room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, + gz_headerp head)); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, + int windowBits)); + + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8..15 for + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value + provided to deflateInit2() while compressing, or it must be equal to 15 if + deflateInit2() was not used. If a compressed stream with a larger window + size is given as input, inflate() will return with the error code + Z_DATA_ERROR instead of trying to allocate a larger window. + + windowBits can also be zero to request that inflate use the window size in + the zlib header of the compressed stream. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, + not looking for a zlib or gzip header, not generating a check value, and not + looking for any check values for comparison at the end of the stream. This + is for use with other formats that use the deflate compressed data format + such as zip. Those formats provide their own check values. If a custom + format is developed using the raw deflate format for compressed data, it is + recommended that a check value such as an Adler-32 or a CRC-32 be applied to + the uncompressed data as is done in the zlib, gzip, and zip formats. For + most applications, the zlib format should be used as is. Note that comments + above on the use in deflateInit2() applies to the magnitude of windowBits. + + windowBits can also be greater than 15 for optional gzip decoding. Add + 32 to windowBits to enable zlib and gzip decoding with automatic header + detection, or add 16 to decode only the gzip format (the zlib format will + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a + CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see + below), inflate() will not automatically decode concatenated gzip streams. + inflate() will return Z_STREAM_END at the end of the gzip stream. The state + would need to be reset to continue decoding a subsequent gzip stream. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit2 does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit2() does not process any header information -- that is + deferred until inflate() is called. +*/ + +ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, + const Bytef *dictionary, + uInt dictLength)); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the Adler-32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called at any + time to set the dictionary. If the provided dictionary is smaller than the + window and there is already data in the window, then the provided dictionary + will amend what's there. The application must insure that the dictionary + that was used for compression is provided. + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect Adler-32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +ZEXTERN int ZEXPORT inflateGetDictionary OF((z_streamp strm, + Bytef *dictionary, + uInt *dictLength)); +/* + Returns the sliding dictionary being maintained by inflate. dictLength is + set to the number of bytes in the dictionary, and that many bytes are copied + to dictionary. dictionary must have enough space, where 32768 bytes is + always enough. If inflateGetDictionary() is called with dictionary equal to + Z_NULL, then only the dictionary length is returned, and nothing is copied. + Similary, if dictLength is Z_NULL, then it is not set. + + inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the + stream state is inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); +/* + Skips invalid compressed data until a possible full flush point (see above + for the description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync searches for a 00 00 FF FF pattern in the compressed data. + All full flush points have this pattern, but not all occurrences of this + pattern are full flush points. + + inflateSync returns Z_OK if a possible full flush point has been found, + Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point + has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. + In the success case, the application may save the current current value of + total_in which indicates where valid compressed data was found. In the + error case, the application may repeatedly call inflateSync, providing more + input each time, until success or end of the input data. +*/ + +ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, + z_streamp source)); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when randomly accessing a large stream. The + first pass through the stream can periodically record the inflate state, + allowing restarting inflate at those points when randomly accessing the + stream. + + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate the internal decompression state. The + stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, + int windowBits)); +/* + This function is the same as inflateReset, but it also permits changing + the wrap and window size requests. The windowBits parameter is interpreted + the same as it is for inflateInit2. If the window size is changed, then the + memory allocated for the window is freed, and the window will be reallocated + by inflate() if needed. + + inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL), or if + the windowBits parameter is invalid. +*/ + +ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, + int bits, + int value)); +/* + This function inserts bits in the inflate input stream. The intent is + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. + + If bits is negative, then the input stream bit buffer is emptied. Then + inflatePrime() can be called again to put bits in the buffer. This is used + to clear out bits leftover after feeding inflate a block description prior + to feeding inflate codes. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); +/* + This function returns two values, one in the lower 16 bits of the return + value, and the other in the remaining upper bits, obtained by shifting the + return value down 16 bits. If the upper value is -1 and the lower value is + zero, then inflate() is currently decoding information outside of a block. + If the upper value is -1 and the lower value is non-zero, then inflate is in + the middle of a stored block, with the lower value equaling the number of + bytes from the input remaining to copy. If the upper value is not -1, then + it is the number of bits back from the current bit position in the input of + the code (literal or length/distance pair) currently being processed. In + that case the lower value is the number of bytes already emitted for that + code. + + A code is being processed if inflate is waiting for more input to complete + decoding of the code, or if it has completed decoding but is waiting for + more output space to write the literal or match data. + + inflateMark() is used to mark locations in the input data for random + access, which may be at bit positions, and to note those cases where the + output of a code may span boundaries of random access blocks. The current + location in the input stream can be determined from avail_in and data_type + as noted in the description for the Z_BLOCK flush parameter for inflate. + + inflateMark returns the value noted above, or -65536 if the provided + source stream state was inconsistent. +*/ + +ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, + gz_headerp head)); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be + used to force inflate() to return immediately after header processing is + complete and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When any + of extra, name, or comment are not Z_NULL and the respective field is not + present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +/* +ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, + unsigned char FAR *window)); + + Initialize the internal stream state for decompression using inflateBack() + calls. The fields zalloc, zfree and opaque in strm must be initialized + before the call. If zalloc and zfree are Z_NULL, then the default library- + derived memory allocation routines are used. windowBits is the base two + logarithm of the window size, in the range 8..15. window is a caller + supplied buffer of that size. Except for special applications where it is + assured that deflate was used with small window sizes, windowBits must be 15 + and a 32K byte window must be supplied to be able to decompress general + deflate streams. + + See inflateBack() for the usage of these routines. + + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of + the parameters are invalid, Z_MEM_ERROR if the internal state could not be + allocated, or Z_VERSION_ERROR if the version of the library does not match + the version of the header file. +*/ + +typedef unsigned (*in_func) OF((void FAR *, + z_const unsigned char FAR * FAR *)); +typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); + +ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, + in_func in, void FAR *in_desc, + out_func out, void FAR *out_desc)); +/* + inflateBack() does a raw inflate with a single call using a call-back + interface for input and output. This is potentially more efficient than + inflate() for file i/o applications, in that it avoids copying between the + output and the sliding window by simply making the window itself the output + buffer. inflate() can be faster on modern CPUs when used with large + buffers. inflateBack() trusts the application to not change the output + buffer passed by the output function, at least until inflateBack() returns. + + inflateBackInit() must be called first to allocate the internal state + and to initialize the state with the user-provided window buffer. + inflateBack() may then be used multiple times to inflate a complete, raw + deflate stream with each call. inflateBackEnd() is then called to free the + allocated state. + + A raw deflate stream is one with no zlib or gzip header or trailer. + This routine would normally be used in a utility that reads zip or gzip + files and writes out uncompressed files. The utility would decode the + header and process the trailer on its own, hence this routine expects only + the raw deflate stream to decompress. This is different from the default + behavior of inflate(), which expects a zlib header and trailer around the + deflate stream. + + inflateBack() uses two subroutines supplied by the caller that are then + called by inflateBack() for input and output. inflateBack() calls those + routines until it reads a complete deflate stream and writes out all of the + uncompressed data, or until it encounters an error. The function's + parameters and return types are defined above in the in_func and out_func + typedefs. inflateBack() will call in(in_desc, &buf) which should return the + number of bytes of provided input, and a pointer to that input in buf. If + there is no input available, in() must return zero -- buf is ignored in that + case -- and inflateBack() will return a buffer error. inflateBack() will + call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. + out() should return zero on success, or non-zero on failure. If out() + returns non-zero, inflateBack() will return with an error. Neither in() nor + out() are permitted to change the contents of the window provided to + inflateBackInit(), which is also the buffer that out() uses to write from. + The length written by out() will be at most the window size. Any non-zero + amount of input may be provided by in(). + + For convenience, inflateBack() can be provided input on the first call by + setting strm->next_in and strm->avail_in. If that input is exhausted, then + in() will be called. Therefore strm->next_in must be initialized before + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in + must also be initialized, and then if strm->avail_in is not zero, input will + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + + The in_desc and out_desc parameters of inflateBack() is passed as the + first parameter of in() and out() respectively when they are called. These + descriptors can be optionally used to pass any information that the caller- + supplied in() and out() functions need to do their job. + + On return, inflateBack() will set strm->next_in and strm->avail_in to + pass back any unused input that was provided by the last in() call. The + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR + if in() or out() returned an error, Z_DATA_ERROR if there was a format error + in the deflate stream (in which case strm->msg is set to indicate the nature + of the error), or Z_STREAM_ERROR if the stream was not properly initialized. + In the case of Z_BUF_ERROR, an input or output error can be distinguished + using strm->next_in which will be Z_NULL only if in() returned an error. If + strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning + non-zero. (in() will always be called before out(), so strm->next_in is + assured to be defined if out() returns non-zero.) Note that inflateBack() + cannot return Z_OK. +*/ + +ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); +/* + All memory allocated by inflateBackInit() is freed. + + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream + state was inconsistent. +*/ + +ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); +/* Return flags indicating compile-time options. + + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: + 1.0: size of uInt + 3.2: size of uLong + 5.4: size of voidpf (pointer) + 7.6: size of z_off_t + + Compiler, assembler, and debug options: + 8: ZLIB_DEBUG + 9: ASMV or ASMINF -- use ASM code + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention + 11: 0 (reserved) + + One-time table building (smaller code, but not thread-safe if true): + 12: BUILDFIXED -- build static block decoding tables when needed + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed + 14,15: 0 (reserved) + + Library content (indicates missing functionality): + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking + deflate code when not needed) + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect + and decode gzip streams (to avoid linking crc code) + 18-19: 0 (reserved) + + Operation variations (changes in library functionality): + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate + 21: FASTEST -- deflate algorithm with only one, lowest compression level + 22,23: 0 (reserved) + + The sprintf variant used by gzprintf (zero is best): + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned + + Remainder: + 27-31: 0 (reserved) + */ + +#ifndef Z_SOLO + + /* utility functions */ + +/* + The following utility functions are implemented on top of the basic + stream-oriented functions. To simplify the interface, some default options + are assumed (compression level and memory usage, standard memory allocation + functions). The source code of these utility functions can be modified if + you need special options. +*/ + +ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed data. compress() is equivalent to compress2() with a level + parameter of Z_DEFAULT_COMPRESSION. + + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen, + int level)); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed data. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); +/* + compressBound() returns an upper bound on the compressed size after + compress() or compress2() on sourceLen bytes. It would be used before a + compress() or compress2() call to allocate the destination buffer. +*/ + +ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong sourceLen)); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, destLen + is the actual size of the uncompressed data. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In + the case where there is not enough room, uncompress() will fill the output + buffer with the uncompressed data up to that point. +*/ + +ZEXTERN int ZEXPORT uncompress2 OF((Bytef *dest, uLongf *destLen, + const Bytef *source, uLong *sourceLen)); +/* + Same as uncompress, except that sourceLen is a pointer, where the + length of the source is *sourceLen. On return, *sourceLen is the number of + source bytes consumed. +*/ + + /* gzip file access functions */ + +/* + This library supports reading and writing files in gzip (.gz) format with + an interface similar to that of stdio, using the functions that start with + "gz". The gzip format is different from the zlib format. gzip is a gzip + wrapper, documented in RFC 1952, wrapped around a deflate stream. +*/ + +typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */ + +/* +ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); + + Opens a gzip (.gz) file for reading or writing. The mode parameter is as + in fopen ("rb" or "wb") but can also include a compression level ("wb9") or + a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only + compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' + for fixed code compression as in "wb9F". (See the description of + deflateInit2 for more information about the strategy parameter.) 'T' will + request transparent writing or appending with no compression and not using + the gzip format. + + "a" can be used instead of "w" to request that the gzip stream that will + be written be appended to the file. "+" will result in an error, since + reading and writing to the same gzip file is not supported. The addition of + "x" when writing will create the file exclusively, which fails if the file + already exists. On systems that support it, the addition of "e" when + reading or writing will set the flag to close the file on an execve() call. + + These functions, as well as gzip, will read and decode a sequence of gzip + streams in a file. The append function of gzopen() can be used to create + such a file. (Also see gzflush() for another way to do this.) When + appending, gzopen does not test whether the file begins with a gzip stream, + nor does it look for the end of the gzip streams to begin appending. gzopen + will simply append a gzip stream to the existing file. + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. When + reading, this will be detected automatically by looking for the magic two- + byte gzip header. + + gzopen returns NULL if the file could not be opened, if there was + insufficient memory to allocate the gzFile state, or if an invalid mode was + specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). + errno can be checked to determine if the reason gzopen failed was that the + file could not be opened. +*/ + +ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); +/* + gzdopen associates a gzFile with the file descriptor fd. File descriptors + are obtained from calls like open, dup, creat, pipe or fileno (if the file + has been previously opened with fopen). The mode parameter is as in gzopen. + + The next call of gzclose on the returned gzFile will also close the file + descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor + fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, + mode);. The duplicated descriptor should be saved to avoid a leak, since + gzdopen does not close fd if it fails. If you are using fileno() to get the + file descriptor from a FILE *, then you will have to use dup() to avoid + double-close()ing the file descriptor. Both gzclose() and fclose() will + close the associated file descriptor, so they need to have different file + descriptors. + + gzdopen returns NULL if there was insufficient memory to allocate the + gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not + provided, or '+' was provided), or if fd is -1. The file descriptor is not + used until the next gz* read, write, seek, or close operation, so gzdopen + will not detect if fd is invalid (unless fd is -1). +*/ + +ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); +/* + Set the internal buffer size used by this library's functions. The + default buffer size is 8192 bytes. This function must be called after + gzopen() or gzdopen(), and before any other calls that read or write the + file. The buffer memory allocation is always deferred to the first read or + write. Three times that size in buffer space is allocated. A larger buffer + size of, for example, 64K or 128K bytes will noticeably increase the speed + of decompression (reading). + + The new buffer size also affects the maximum length for gzprintf(). + + gzbuffer() returns 0 on success, or -1 on failure, such as being called + too late. +*/ + +ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. Previously provided + data is flushed before the parameter change. + + gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not + opened for writing, Z_ERRNO if there is an error writing the flushed data, + or Z_MEM_ERROR if there is a memory allocation error. +*/ + +ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); +/* + Reads the given number of uncompressed bytes from the compressed file. If + the input file is not in gzip format, gzread copies the given number of + bytes into the buffer directly from the file. + + After reaching the end of a gzip stream in the input, gzread will continue + to read, looking for another gzip stream. Any number of gzip streams may be + concatenated in the input file, and will all be decompressed by gzread(). + If something other than a gzip stream is encountered after a gzip stream, + that remaining trailing garbage is ignored (and no error is returned). + + gzread can be used to read a gzip file that is being concurrently written. + Upon reaching the end of the input, gzread will return with the available + data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then + gzclearerr can be used to clear the end of file indicator in order to permit + gzread to be tried again. Z_OK indicates that a gzip stream was completed + on the last gzread. Z_BUF_ERROR indicates that the input file ended in the + middle of a gzip stream. Note that gzread does not return -1 in the event + of an incomplete gzip stream. This error is deferred until gzclose(), which + will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip + stream. Alternatively, gzerror can be used before gzclose to detect this + case. + + gzread returns the number of uncompressed bytes actually read, less than + len for end of file, or -1 for error. If len is too large to fit in an int, + then nothing is read, -1 is returned, and the error state is set to + Z_STREAM_ERROR. +*/ + +ZEXTERN z_size_t ZEXPORT gzfread OF((voidp buf, z_size_t size, z_size_t nitems, + gzFile file)); +/* + Read up to nitems items of size size from file to buf, otherwise operating + as gzread() does. This duplicates the interface of stdio's fread(), with + size_t request and return types. If the library defines size_t, then + z_size_t is identical to size_t. If not, then z_size_t is an unsigned + integer type that can contain a pointer. + + gzfread() returns the number of full items read of size size, or zero if + the end of the file was reached and a full item could not be read, or if + there was an error. gzerror() must be consulted if zero is returned in + order to determine if there was an error. If the multiplication of size and + nitems overflows, i.e. the product does not fit in a z_size_t, then nothing + is read, zero is returned, and the error state is set to Z_STREAM_ERROR. + + In the event that the end of file is reached and only a partial item is + available at the end, i.e. the remaining uncompressed data length is not a + multiple of size, then the final partial item is nevetheless read into buf + and the end-of-file flag is set. The length of the partial item read is not + provided, but could be inferred from the result of gztell(). This behavior + is the same as the behavior of fread() implementations in common libraries, + but it prevents the direct use of gzfread() to read a concurrently written + file, reseting and retrying on end-of-file, when size is not 1. +*/ + +ZEXTERN int ZEXPORT gzwrite OF((gzFile file, + voidpc buf, unsigned len)); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes written or 0 in case of + error. +*/ + +ZEXTERN z_size_t ZEXPORT gzfwrite OF((voidpc buf, z_size_t size, + z_size_t nitems, gzFile file)); +/* + gzfwrite() writes nitems items of size size from buf to file, duplicating + the interface of stdio's fwrite(), with size_t request and return types. If + the library defines size_t, then z_size_t is identical to size_t. If not, + then z_size_t is an unsigned integer type that can contain a pointer. + + gzfwrite() returns the number of full items written of size size, or zero + if there was an error. If the multiplication of size and nitems overflows, + i.e. the product does not fit in a z_size_t, then nothing is written, zero + is returned, and the error state is set to Z_STREAM_ERROR. +*/ + +ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...)); +/* + Converts, formats, and writes the arguments to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written, or a negative zlib error code in case + of error. The number of uncompressed bytes written is limited to 8191, or + one less than the buffer size given to gzbuffer(). The caller should assure + that this limit is not exceeded. If it is exceeded, then gzprintf() will + return an error (0) with nothing written. In this case, there may also be a + buffer overflow with unpredictable consequences, which is possible only if + zlib was compiled with the insecure functions sprintf() or vsprintf() + because the secure snprintf() or vsnprintf() functions were not available. + This can be determined using zlibCompileFlags(). +*/ + +ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + + gzputs returns the number of characters written, or -1 in case of error. +*/ + +ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); +/* + Reads bytes from the compressed file until len-1 characters are read, or a + newline character is read and transferred to buf, or an end-of-file + condition is encountered. If any characters are read or if len == 1, the + string is terminated with a null character. If no characters are read due + to an end-of-file or len < 1, then the buffer is left untouched. + + gzgets returns buf which is a null-terminated string, or it returns NULL + for end-of-file or in case of error. If there was an error, the contents at + buf are indeterminate. +*/ + +ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); +/* + Writes c, converted to an unsigned char, into the compressed file. gzputc + returns the value that was written, or -1 in case of error. +*/ + +ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); +/* + Reads one byte from the compressed file. gzgetc returns this byte or -1 + in case of end of file or error. This is implemented as a macro for speed. + As such, it does not do all of the checking the other functions do. I.e. + it does not check to see if file is NULL, nor whether the structure file + points to has been clobbered or not. +*/ + +ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); +/* + Push one character back onto the stream to be read as the first character + on the next read. At least one character of push-back is allowed. + gzungetc() returns the character pushed, or -1 on failure. gzungetc() will + fail if c is -1, and may fail if a character has been pushed but not read + yet. If gzungetc is used immediately after gzopen or gzdopen, at least the + output buffer size of pushed characters is allowed. (See gzbuffer above.) + The pushed character will be discarded if the stream is repositioned with + gzseek() or gzrewind(). +*/ + +ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); +/* + Flushes all pending output into the compressed file. The parameter flush + is as in the deflate() function. The return value is the zlib error number + (see function gzerror below). gzflush is only permitted when writing. + + If the flush parameter is Z_FINISH, the remaining data is written and the + gzip stream is completed in the output. If gzwrite() is called again, a new + gzip stream will be started in the output. gzread() is able to read such + concatenated gzip streams. + + gzflush should be called only when strictly necessary because it will + degrade compression if called too often. +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, + z_off_t offset, int whence)); + + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); + + Returns the starting position for the next gzread or gzwrite on the given + compressed file. This position represents a number of bytes in the + uncompressed data stream, and is zero when starting, even if appending or + reading a gzip stream from the middle of a file using gzdopen(). + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +/* +ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); + + Returns the current offset in the file being read or written. This offset + includes the count of bytes that precede the gzip stream, for example when + appending or when using gzdopen() for reading. When reading, the offset + does not include as yet unused buffered input. This information can be used + for a progress indicator. On error, gzoffset() returns -1. +*/ + +ZEXTERN int ZEXPORT gzeof OF((gzFile file)); +/* + Returns true (1) if the end-of-file indicator has been set while reading, + false (0) otherwise. Note that the end-of-file indicator is set only if the + read tried to go past the end of the input, but came up short. Therefore, + just like feof(), gzeof() may return false even if there is no more data to + read, in the event that the last read request was for the exact number of + bytes remaining in the input file. This will happen if the input file size + is an exact multiple of the buffer size. + + If gzeof() returns true, then the read functions will return no more data, + unless the end-of-file indicator is reset by gzclearerr() and the input file + has grown since the previous end of file was detected. +*/ + +ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); +/* + Returns true (1) if file is being copied directly while reading, or false + (0) if file is a gzip stream being decompressed. + + If the input file is empty, gzdirect() will return true, since the input + does not contain a gzip stream. + + If gzdirect() is used immediately after gzopen() or gzdopen() it will + cause buffers to be allocated to allow reading the file to determine if it + is a gzip file. Therefore if gzbuffer() is used, it should be called before + gzdirect(). + + When writing, gzdirect() returns true (1) if transparent writing was + requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: + gzdirect() is not needed when writing. Transparent writing must be + explicitly requested, so the application already knows the answer. When + linking statically, using gzdirect() will include all of the zlib code for + gzip file reading and decompression, which may not be desired.) +*/ + +ZEXTERN int ZEXPORT gzclose OF((gzFile file)); +/* + Flushes all pending output if necessary, closes the compressed file and + deallocates the (de)compression state. Note that once file is closed, you + cannot call gzerror with file, since its structures have been deallocated. + gzclose must not be called more than once on the same file, just as free + must not be called more than once on the same allocation. + + gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a + file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the + last read ended in the middle of a gzip stream, or Z_OK on success. +*/ + +ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); +ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); +/* + Same as gzclose(), but gzclose_r() is only for use when reading, and + gzclose_w() is only for use when writing or appending. The advantage to + using these instead of gzclose() is that they avoid linking in zlib + compression or decompression code that is not used when only reading or only + writing respectively. If gzclose() is used, then both compression and + decompression code will be included the application when linking to a static + zlib library. +*/ + +ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); +/* + Returns the error message for the last error which occurred on the given + compressed file. errnum is set to zlib error number. If an error occurred + in the file system and not in the compression library, errnum is set to + Z_ERRNO and the application may consult errno to get the exact error code. + + The application must not modify the returned string. Future calls to + this function may invalidate the previously returned string. If file is + closed, then the string previously returned by gzerror will no longer be + available. + + gzerror() should be used to distinguish errors from end-of-file for those + functions above that do not distinguish those cases in their return values. +*/ + +ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); +/* + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip + file that is being written concurrently. +*/ + +#endif /* !Z_SOLO */ + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the compression + library. +*/ + +ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); +/* + Update a running Adler-32 checksum with the bytes buf[0..len-1] and + return the updated checksum. If buf is Z_NULL, this function returns the + required initial value for the checksum. + + An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed + much faster. + + Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + adler = adler32(adler, buffer, length); + } + if (adler != original_adler) error(); +*/ + +ZEXTERN uLong ZEXPORT adler32_z OF((uLong adler, const Bytef *buf, + z_size_t len)); +/* + Same as adler32(), but with a size_t length. +*/ + +/* +ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, + z_off_t len2)); + + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note + that the z_off_t type (like off_t) is a signed integer. If len2 is + negative, the result has no meaning or utility. +*/ + +ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); +/* + Update a running CRC-32 with the bytes buf[0..len-1] and return the + updated CRC-32. If buf is Z_NULL, this function returns the required + initial value for the crc. Pre- and post-conditioning (one's complement) is + performed within this function so it shouldn't be done by the application. + + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) { + crc = crc32(crc, buffer, length); + } + if (crc != original_crc) error(); +*/ + +ZEXTERN uLong ZEXPORT crc32_z OF((uLong adler, const Bytef *buf, + z_size_t len)); +/* + Same as crc32(), but with a size_t length. +*/ + +/* +ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); + + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, + int windowBits, int memLevel, + int strategy, const char *version, + int stream_size)); +ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, + const char *version, int stream_size)); +ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, + unsigned char FAR *window, + const char *version, + int stream_size)); +#ifdef Z_PREFIX_SET +# define z_deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) +# define z_inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) +# define z_deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) +# define z_inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ + (int)sizeof(z_stream)) +# define z_inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, (int)sizeof(z_stream)) +#else +# define deflateInit(strm, level) \ + deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream)) +# define inflateInit(strm) \ + inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream)) +# define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ + deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ + (strategy), ZLIB_VERSION, (int)sizeof(z_stream)) +# define inflateInit2(strm, windowBits) \ + inflateInit2_((strm), (windowBits), ZLIB_VERSION, \ + (int)sizeof(z_stream)) +# define inflateBackInit(strm, windowBits, window) \ + inflateBackInit_((strm), (windowBits), (window), \ + ZLIB_VERSION, (int)sizeof(z_stream)) +#endif + +#ifndef Z_SOLO + +/* gzgetc() macro and its supporting function and exposed data structure. Note + * that the real internal state is much larger than the exposed structure. + * This abbreviated structure exposes just enough for the gzgetc() macro. The + * user should not mess with these exposed elements, since their names or + * behavior could change in the future, perhaps even capriciously. They can + * only be used by the gzgetc() macro. You have been warned. + */ +struct gzFile_s { + unsigned have; + unsigned char *next; + z_off64_t pos; +}; +ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */ +#ifdef Z_PREFIX_SET +# undef z_gzgetc +# define z_gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) +#else +# define gzgetc(g) \ + ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g)) +#endif + +/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or + * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if + * both are true, the application gets the *64 functions, and the regular + * functions are changed to 64 bits) -- in case these are set on systems + * without large file support, _LFS64_LARGEFILE must also be true + */ +#ifdef Z_LARGE64 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); + ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); +#endif + +#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64) +# ifdef Z_PREFIX_SET +# define z_gzopen z_gzopen64 +# define z_gzseek z_gzseek64 +# define z_gztell z_gztell64 +# define z_gzoffset z_gzoffset64 +# define z_adler32_combine z_adler32_combine64 +# define z_crc32_combine z_crc32_combine64 +# else +# define gzopen gzopen64 +# define gzseek gzseek64 +# define gztell gztell64 +# define gzoffset gzoffset64 +# define adler32_combine adler32_combine64 +# define crc32_combine crc32_combine64 +# endif +# ifndef Z_LARGE64 + ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); +# endif +#else + ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); + ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); + ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); + ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); +#endif + +#else /* Z_SOLO */ + + ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); + ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); + +#endif /* !Z_SOLO */ + +/* undocumented functions */ +ZEXTERN const char * ZEXPORT zError OF((int)); +ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); +ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void)); +ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); +ZEXTERN int ZEXPORT inflateValidate OF((z_streamp, int)); +ZEXTERN unsigned long ZEXPORT inflateCodesUsed OF ((z_streamp)); +ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp)); +ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp)); +#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(Z_SOLO) +ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path, + const char *mode)); +#endif +#if defined(STDC) || defined(Z_HAVE_STDARG_H) +# ifndef Z_SOLO +ZEXTERN int ZEXPORTVA gzvprintf Z_ARG((gzFile file, + const char *format, + va_list va)); +# endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* ZLIB_H */ diff --git a/lib/quazip.lib b/lib/quazip.lib new file mode 100644 index 00000000..82e88dea Binary files /dev/null and b/lib/quazip.lib differ