openssl libraries错误:stray' @'在程序中

时间:2017-10-28 16:23:38

标签: c++ openssl duplicates

尝试测试使用boost和openssl库的重复删除程序。用openssl导致这里的问题。附在代码块中的是我认为相关的代码。 opensslconf.h文件是大多数错误的地方,而且所有的流浪都是@'程序回复来自。

DupRemoval.cpp

#include <cstdint>
#include <cmath>
#include <iostream>
#include <fstream>
#include <map>
#include <unordered_map>
#include <array>

#include <openssl/sha.h>
#include <boost/filesystem.hpp>

namespace fs = boost::filesystem;
using namespace std;

const int hashlen = SHA_DIGEST_LENGTH;
using digest = array<unsigned char, hashlen>;
namespace std { template <> struct hash<digest> {
    size_t operator()(const digest& x) const { // hash sha to int
        size_t seed = 0;
        for(char c:x) seed^=c;
        return seed;
    }
};}

digest sha1(string path, uint64_t maxlen) {
    char buf[8192];
    SHA_CTX sc;
    ifstream f(path);
    SHA1_Init(&sc);
    uint64_t read = 0;
    while(read < maxlen) {
        f.read(buf, sizeof buf);
        size_t len = f.gcount(); read+=len;
        if (len == 0) break;
        SHA1_Update(&sc, buf, len);
    }
    f.close();
    digest dig;
    SHA1_Final(&dig.front(), &sc);
    return dig;
}

uint64_t minsize = 1; // ignore files smaller than x bytes
uint64_t firsthash_size = 1<<16; // size to do the initial checksumming

class file_info {
    digest _firsthash, _fullhash;
    bool got_size=false, got_firsthash=false, got_fullhash=false;
    public:
        string path;
        uint64_t size;
        file_info(): path(""), size(0) {}
        file_info(string path, uint64_t size) : path(path), size(size) {}
        digest fullhash() {
            if(firsthash_size>=size) return firsthash();
            if(!got_fullhash++) _fullhash = sha1(path, size);
            return _fullhash;
        }
        /** hash of the first segment of the file */
        digest firsthash() {
            if(!got_firsthash++) _firsthash = sha1(path, min(firsthash_size,size));
            return _firsthash;
        }
};

int main(int argc, char *argv[]) {
    if(argc < 3) {
        cout << "Usage: dupefind <directory> <minfilesize>" << endl;
        return 0;
    }
    string dir = argv[1];
    minsize = max(stoi(argv[2]),1);
    multimap<int,file_info> map;
    for(fs::recursive_directory_iterator end, file(dir); file!=end; ++file) {
        if(file->status().type()!=fs::regular_file) continue;
        uint64_t size = fs::file_size(*file);
        if(size < minsize) continue;
        map.insert(make_pair(size,file_info(file->path().string(),size)));
    }
    cerr<<"Found "<<map.size()<<" files, comparing"<<endl;

    for(auto it = map.begin(); it != map.end();) {
        if(map.count(it->first) < 2) map.erase(it++);
        else ++it;
    }
    cerr<<map.size()<<" files after size-filtering"<<endl;

    unordered_multimap<digest,file_info> samesizeset;
    uint64_t i = 0, dupes = 0, lastsize=0;
    for(auto& entry:map) {
        if(i++%100==0) cerr << "\rComparing... " << i << "/" << map.size();
        if(entry.second.size < minsize) continue;
        if(entry.second.size == lastsize) {
            auto equals = samesizeset.equal_range(entry.second.firsthash());
            for(auto it=equals.first; it!=equals.second; ++it) {
                auto other = it->second;
                if(other.fullhash() == entry.second.fullhash()) {
                    cout << endl << other.path << endl
                        << entry.second.path << endl;
                    dupes++;
                }
            }
        } else {
            samesizeset.clear();
            lastsize = entry.second.size;
        }
        samesizeset.insert(make_pair(entry.second.firsthash(),entry.second));
    }
    cerr << endl << "Done, found " << dupes << " duplicates." << endl;
}

opensslconf.h

/*
 * {- join("\n * ", @autowarntext) -}
 *
 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
 *
 * Licensed under the OpenSSL license (the "License").  You may not use
 * this file except in compliance with the License.  You can obtain a copy
 * in the file LICENSE in the source distribution or at
 * https://www.openssl.org/source/license.html
 */

#ifdef  __cplusplus
extern "C" {
#endif

#ifdef OPENSSL_ALGORITHM_DEFINES
# error OPENSSL_ALGORITHM_DEFINES no longer supported
#endif

/*
 * OpenSSL was configured with the following options:
 */

{- if (@{$config{openssl_sys_defines}}) {
      foreach (@{$config{openssl_sys_defines}}) {
    $OUT .= "#ifndef $_\n";
    $OUT .= "# define $_ 1\n";
    $OUT .= "#endif\n";
      }
    }
    foreach (@{$config{openssl_api_defines}}) {
        (my $macro, my $value) = $_ =~ /^(.*?)=(.*?)$/;
        $OUT .= "#define OPENSSL_MIN_API $value\n";
    }
    if (@{$config{openssl_algorithm_defines}}) {
      foreach (@{$config{openssl_algorithm_defines}}) {
    $OUT .= "#ifndef $_\n";
    $OUT .= "# define $_\n";
    $OUT .= "#endif\n";
      }
    }
    if (@{$config{openssl_thread_defines}}) {
      foreach (@{$config{openssl_thread_defines}}) {
    $OUT .= "#ifndef $_\n";
    $OUT .= "# define $_\n";
    $OUT .= "#endif\n";
      }
    }
    if (@{$config{openssl_other_defines}}) {
      foreach (@{$config{openssl_other_defines}}) {
    $OUT .= "#ifndef $_\n";
    $OUT .= "# define $_\n";
    $OUT .= "#endif\n";
      }
    }
    "";
-}

/*
 * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers
 * don't like that.  This will hopefully silence them.
 */
#define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy;

/*
 * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the
 * declarations of functions deprecated in or before <version>. Otherwise, they
 * still won't see them if the library has been built to disable deprecated
 * functions.
 */
#if defined(OPENSSL_NO_DEPRECATED)
# define DECLARE_DEPRECATED(f)
#elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
# define DECLARE_DEPRECATED(f)    f __attribute__ ((deprecated));
#else
# define DECLARE_DEPRECATED(f)   f;
#endif

#ifndef OPENSSL_FILE
# ifdef OPENSSL_NO_FILENAMES
#  define OPENSSL_FILE ""
#  define OPENSSL_LINE 0
# else
#  define OPENSSL_FILE __FILE__
#  define OPENSSL_LINE __LINE__
# endif
#endif

#ifndef OPENSSL_MIN_API
# define OPENSSL_MIN_API 0
#endif

#if !defined(OPENSSL_API_COMPAT) || OPENSSL_API_COMPAT < OPENSSL_MIN_API
# undef OPENSSL_API_COMPAT
# define OPENSSL_API_COMPAT OPENSSL_MIN_API
#endif

#if OPENSSL_API_COMPAT < 0x10100000L
# define DEPRECATEDIN_1_1_0(f)   DECLARE_DEPRECATED(f)
#else
# define DEPRECATEDIN_1_1_0(f)
#endif

#if OPENSSL_API_COMPAT < 0x10000000L
# define DEPRECATEDIN_1_0_0(f)   DECLARE_DEPRECATED(f)
#else
# define DEPRECATEDIN_1_0_0(f)
#endif

#if OPENSSL_API_COMPAT < 0x00908000L
# define DEPRECATEDIN_0_9_8(f)   DECLARE_DEPRECATED(f)
#else
# define DEPRECATEDIN_0_9_8(f)
#endif

{- $target{cpuid_obj} ne "mem_clr.o" ? "#define OPENSSL_CPUID_OBJ" : "" -}

/* Generate 80386 code? */
{- $config{processor} eq "386" ? "#define" : "#undef" -} I386_ONLY

#undef OPENSSL_UNISTD
#define OPENSSL_UNISTD {- $target{unistd} -}

{- $config{export_var_as_fn} ? "#define" : "#undef" -} OPENSSL_EXPORT_VAR_AS_FUNCTION

/*
 * The following are cipher-specific, but are part of the public API.
 */
#if !defined(OPENSSL_SYS_UEFI)
{- $config{bn_ll} ? "# define" : "# undef" -} BN_LLONG
/* Only one for the following should be defined */
{- $config{b64l} ? "# define" : "# undef" -} SIXTY_FOUR_BIT_LONG
{- $config{b64}  ? "# define" : "# undef" -} SIXTY_FOUR_BIT
{- $config{b32}  ? "# define" : "# undef" -} THIRTY_TWO_BIT
#endif

#define RC4_INT {- $config{rc4_int} -}

#ifdef  __cplusplus
}
#endif

错误:

In file included from C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/e_os2.h:13:0,
                 from C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/sha.h:13,
                 from ..\dupRemoval22.cpp:27:
C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/opensslconf.h:24:8: error: stray '@' in program
 {- if (@{$config{openssl_sys_defines}}) {
        ^
C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/opensslconf.h:25:16: error: stray '@' in program
       foreach (@{$config{openssl_sys_defines}}) {
                ^
C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/opensslconf.h:31:14: error: stray '@' in program
     foreach (@{$config{openssl_api_defines}}) {
              ^
C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/opensslconf.h:35:9: error: stray '@' in program
     if (@{$config{openssl_algorithm_defines}}) {
         ^
C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/opensslconf.h:36:16: error: stray '@' in program
       foreach (@{$config{openssl_algorithm_defines}}) {
                ^
C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/opensslconf.h:42:9: error: stray '@' in program
     if (@{$config{openssl_thread_defines}}) {
         ^
C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/opensslconf.h:43:16: error: stray '@' in program
       foreach (@{$config{openssl_thread_defines}}) {
                ^
C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/opensslconf.h:49:9: error: stray '@' in program
     if (@{$config{openssl_other_defines}}) {
         ^
C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/opensslconf.h:50:16: error: stray '@' in program
       foreach (@{$config{openssl_other_defines}}) {
                ^
In file included from C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/e_os2.h:13:0,
                 from C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/sha.h:13,
                 from ..\dupRemoval22.cpp:27:
C:\Program Files\openSSL\openssl-1.1.0f\include/openssl/opensslconf.h:24:1: error: expected unqualified-id before '{' token
 {- if (@{$config{openssl_sys_defines}}) {
 ^
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\functional:53:0,
                 from C:\Program Files\boost\boost_1_65_1/boost/system/error_code.hpp:22,
                 from C:\Program Files\boost\boost_1_65_1/boost/filesystem/path_traits.hpp:23,
                 from C:\Program Files\boost\boost_1_65_1/boost/filesystem/path.hpp:25,
                 from C:\Program Files\boost\boost_1_65_1/boost/filesystem.hpp:16,
                 from ..\dupRemoval22.cpp:28:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\typeinfo:39:37: error: expected '}' before end of line
 #pragma GCC visibility push(default)
                                     ^
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\typeinfo:39:37: error: expected declaration before end of line

12:05:52 Build Finished (took 716ms)

我担心&#34;流浪&#39; @&#39;在节目&#34;错误,有人可以澄清在这种情况下出了什么问题,以及我遇到的任何其他错误吗?

0 个答案:

没有答案