From: Jocelyn Turcotte Date: Mon, 14 Aug 2017 12:32:11 +0000 (+0200) Subject: Use .cpp for existing csync .cc files X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~701^2~144 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=39e9938cad6abca59ca6a1d9e6ee0abca2353f8a;p=nextcloud-desktop.git Use .cpp for existing csync .cc files Make this consistent with the rest of the client code. --- diff --git a/src/csync/CMakeLists.txt b/src/csync/CMakeLists.txt index db99a88d0..2bd60e572 100644 --- a/src/csync/CMakeLists.txt +++ b/src/csync/CMakeLists.txt @@ -73,7 +73,7 @@ set(csync_SRCS csync_update.c csync_reconcile.c - csync_rename.cc + csync_rename.cpp vio/csync_vio.c vio/csync_vio_file_stat.c diff --git a/src/csync/csync_rename.cc b/src/csync/csync_rename.cc deleted file mode 100644 index 5cc43ce22..000000000 --- a/src/csync/csync_rename.cc +++ /dev/null @@ -1,102 +0,0 @@ -/* - * libcsync -- a library to sync a directory with another - * - * Copyright (c) 2012 by Olivier Goffart - * - * This library 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. - * - * This library 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 this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -extern "C" { -#include "csync_private.h" -#include "csync_rename.h" -} - -#include -#include -#include -#include - -static std::string _parentDir(const std::string &path) { - int len = path.length(); - while(len > 0 && path[len-1]!='/') len--; - while(len > 0 && path[len-1]=='/') len--; - return path.substr(0, len); -} - -struct csync_rename_s { - static csync_rename_s *get(CSYNC *ctx) { - if (!ctx->rename_info) { - ctx->rename_info = new csync_rename_s; - } - return reinterpret_cast(ctx->rename_info); - } - - std::map folder_renamed_to; // map from->to - std::map folder_renamed_from; // map to->from - - struct renameop { - csync_file_stat_t *st; - bool operator<(const renameop &other) const { - return strlen(st->destpath) < strlen(other.st->destpath); - } - }; - std::vector todo; -}; - -extern "C" { -void csync_rename_destroy(CSYNC* ctx) -{ - delete reinterpret_cast(ctx->rename_info); - ctx->rename_info = 0; -} - -void csync_rename_record(CSYNC* ctx, const char* from, const char* to) -{ - csync_rename_s::get(ctx)->folder_renamed_to[from] = to; - csync_rename_s::get(ctx)->folder_renamed_from[to] = from; -} - -char* csync_rename_adjust_path(CSYNC* ctx, const char* path) -{ - csync_rename_s* d = csync_rename_s::get(ctx); - for (std::string p = _parentDir(path); !p.empty(); p = _parentDir(p)) { - std::map< std::string, std::string >::iterator it = d->folder_renamed_to.find(p); - if (it != d->folder_renamed_to.end()) { - std::string rep = it->second + (path + p.length()); - return c_strdup(rep.c_str()); - } - } - return c_strdup(path); -} - -char* csync_rename_adjust_path_source(CSYNC* ctx, const char* path) -{ - csync_rename_s* d = csync_rename_s::get(ctx); - for (std::string p = _parentDir(path); !p.empty(); p = _parentDir(p)) { - std::map< std::string, std::string >::iterator it = d->folder_renamed_from.find(p); - if (it != d->folder_renamed_from.end()) { - std::string rep = it->second + (path + p.length()); - return c_strdup(rep.c_str()); - } - } - return c_strdup(path); -} - -bool csync_rename_count(CSYNC *ctx) { - csync_rename_s* d = csync_rename_s::get(ctx); - return d->folder_renamed_from.size(); -} - -} diff --git a/src/csync/csync_rename.cpp b/src/csync/csync_rename.cpp new file mode 100644 index 000000000..5cc43ce22 --- /dev/null +++ b/src/csync/csync_rename.cpp @@ -0,0 +1,102 @@ +/* + * libcsync -- a library to sync a directory with another + * + * Copyright (c) 2012 by Olivier Goffart + * + * This library 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. + * + * This library 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 this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +extern "C" { +#include "csync_private.h" +#include "csync_rename.h" +} + +#include +#include +#include +#include + +static std::string _parentDir(const std::string &path) { + int len = path.length(); + while(len > 0 && path[len-1]!='/') len--; + while(len > 0 && path[len-1]=='/') len--; + return path.substr(0, len); +} + +struct csync_rename_s { + static csync_rename_s *get(CSYNC *ctx) { + if (!ctx->rename_info) { + ctx->rename_info = new csync_rename_s; + } + return reinterpret_cast(ctx->rename_info); + } + + std::map folder_renamed_to; // map from->to + std::map folder_renamed_from; // map to->from + + struct renameop { + csync_file_stat_t *st; + bool operator<(const renameop &other) const { + return strlen(st->destpath) < strlen(other.st->destpath); + } + }; + std::vector todo; +}; + +extern "C" { +void csync_rename_destroy(CSYNC* ctx) +{ + delete reinterpret_cast(ctx->rename_info); + ctx->rename_info = 0; +} + +void csync_rename_record(CSYNC* ctx, const char* from, const char* to) +{ + csync_rename_s::get(ctx)->folder_renamed_to[from] = to; + csync_rename_s::get(ctx)->folder_renamed_from[to] = from; +} + +char* csync_rename_adjust_path(CSYNC* ctx, const char* path) +{ + csync_rename_s* d = csync_rename_s::get(ctx); + for (std::string p = _parentDir(path); !p.empty(); p = _parentDir(p)) { + std::map< std::string, std::string >::iterator it = d->folder_renamed_to.find(p); + if (it != d->folder_renamed_to.end()) { + std::string rep = it->second + (path + p.length()); + return c_strdup(rep.c_str()); + } + } + return c_strdup(path); +} + +char* csync_rename_adjust_path_source(CSYNC* ctx, const char* path) +{ + csync_rename_s* d = csync_rename_s::get(ctx); + for (std::string p = _parentDir(path); !p.empty(); p = _parentDir(p)) { + std::map< std::string, std::string >::iterator it = d->folder_renamed_from.find(p); + if (it != d->folder_renamed_from.end()) { + std::string rep = it->second + (path + p.length()); + return c_strdup(rep.c_str()); + } + } + return c_strdup(path); +} + +bool csync_rename_count(CSYNC *ctx) { + csync_rename_s* d = csync_rename_s::get(ctx); + return d->folder_renamed_from.size(); +} + +} diff --git a/src/csync/std/CMakeLists.txt b/src/csync/std/CMakeLists.txt index 519cada86..8cfd48531 100644 --- a/src/csync/std/CMakeLists.txt +++ b/src/csync/std/CMakeLists.txt @@ -20,7 +20,7 @@ set(cstdlib_SRCS c_rbtree.c c_string.c c_time.c - c_utf8.cc + c_utf8.cpp ) if(NOT HAVE_ASPRINTF AND NOT HAVE___MINGW_ASPRINTF) diff --git a/src/csync/std/c_utf8.cc b/src/csync/std/c_utf8.cc deleted file mode 100644 index 4bd5d75ac..000000000 --- a/src/csync/std/c_utf8.cc +++ /dev/null @@ -1,104 +0,0 @@ -/* - * cynapses libc functions - * - * Copyright (c) 2008-2013 by Andreas Schneider - * Copyright (c) 2012-2013 by Klaas Freitag - * - * This library 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. - * - * This library 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 this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "config_csync.h" - -#ifdef _WIN32 -#include -#include -#include -#include -#include -#include -#include -#else -#include -#include -#endif - -extern "C" { -#include "c_alloc.h" -#include "c_string.h" - -/* Convert a locale String to UTF8 */ -char* c_utf8_from_locale(const mbchar_t *wstr) -{ - if (wstr == NULL) { - return NULL; - } - -#ifdef _WIN32 - char *dst = NULL; - char *mdst = NULL; - int size_needed; - size_t len; - len = wcslen(wstr); - /* Call once to get the required size. */ - size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr, len, NULL, 0, NULL, NULL); - if (size_needed > 0) { - mdst = (char*)c_malloc(size_needed + 1); - - memset(mdst, 0, size_needed + 1); - WideCharToMultiByte(CP_UTF8, 0, wstr, len, mdst, size_needed, NULL, NULL); - dst = mdst; - } - return dst; -#else - QTextDecoder dec(QTextCodec::codecForLocale()); - QString s = dec.toUnicode(wstr, qstrlen(wstr)); - if (s.isEmpty() || dec.hasFailure()) { - /* Conversion error: since we can't report error from this function, just return the original - string. We take care of invalid utf-8 in SyncEngine::treewalkFile */ - return c_strdup(wstr); - } -#ifdef __APPLE__ - s = s.normalized(QString::NormalizationForm_C); -#endif - return c_strdup(std::move(s).toUtf8().constData()); -#endif -} - -/* Convert a an UTF8 string to locale */ -mbchar_t* c_utf8_string_to_locale(const char *str) -{ - if (str == NULL ) { - return NULL; - } -#ifdef _WIN32 - mbchar_t *dst = NULL; - size_t len; - int size_needed; - - len = strlen(str); - size_needed = MultiByteToWideChar(CP_UTF8, 0, str, len, NULL, 0); - if (size_needed > 0) { - int size_char = (size_needed + 1) * sizeof(mbchar_t); - dst = (mbchar_t*)c_malloc(size_char); - memset((void*)dst, 0, size_char); - MultiByteToWideChar(CP_UTF8, 0, str, -1, dst, size_needed); - } - return dst; -#else - return c_strdup(QFile::encodeName(QString::fromUtf8(str))); -#endif -} - -} diff --git a/src/csync/std/c_utf8.cpp b/src/csync/std/c_utf8.cpp new file mode 100644 index 000000000..4bd5d75ac --- /dev/null +++ b/src/csync/std/c_utf8.cpp @@ -0,0 +1,104 @@ +/* + * cynapses libc functions + * + * Copyright (c) 2008-2013 by Andreas Schneider + * Copyright (c) 2012-2013 by Klaas Freitag + * + * This library 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. + * + * This library 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 this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config_csync.h" + +#ifdef _WIN32 +#include +#include +#include +#include +#include +#include +#include +#else +#include +#include +#endif + +extern "C" { +#include "c_alloc.h" +#include "c_string.h" + +/* Convert a locale String to UTF8 */ +char* c_utf8_from_locale(const mbchar_t *wstr) +{ + if (wstr == NULL) { + return NULL; + } + +#ifdef _WIN32 + char *dst = NULL; + char *mdst = NULL; + int size_needed; + size_t len; + len = wcslen(wstr); + /* Call once to get the required size. */ + size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr, len, NULL, 0, NULL, NULL); + if (size_needed > 0) { + mdst = (char*)c_malloc(size_needed + 1); + + memset(mdst, 0, size_needed + 1); + WideCharToMultiByte(CP_UTF8, 0, wstr, len, mdst, size_needed, NULL, NULL); + dst = mdst; + } + return dst; +#else + QTextDecoder dec(QTextCodec::codecForLocale()); + QString s = dec.toUnicode(wstr, qstrlen(wstr)); + if (s.isEmpty() || dec.hasFailure()) { + /* Conversion error: since we can't report error from this function, just return the original + string. We take care of invalid utf-8 in SyncEngine::treewalkFile */ + return c_strdup(wstr); + } +#ifdef __APPLE__ + s = s.normalized(QString::NormalizationForm_C); +#endif + return c_strdup(std::move(s).toUtf8().constData()); +#endif +} + +/* Convert a an UTF8 string to locale */ +mbchar_t* c_utf8_string_to_locale(const char *str) +{ + if (str == NULL ) { + return NULL; + } +#ifdef _WIN32 + mbchar_t *dst = NULL; + size_t len; + int size_needed; + + len = strlen(str); + size_needed = MultiByteToWideChar(CP_UTF8, 0, str, len, NULL, 0); + if (size_needed > 0) { + int size_char = (size_needed + 1) * sizeof(mbchar_t); + dst = (mbchar_t*)c_malloc(size_char); + memset((void*)dst, 0, size_char); + MultiByteToWideChar(CP_UTF8, 0, str, -1, dst, size_needed); + } + return dst; +#else + return c_strdup(QFile::encodeName(QString::fromUtf8(str))); +#endif +} + +}