Switch to unified view

a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp
...
...
36
#include <list>
36
#include <list>
37
#include <iostream>
37
#include <iostream>
38
#include <sstream>
38
#include <sstream>
39
#include <cstdlib>
39
#include <cstdlib>
40
#include <cstring>
40
#include <cstring>
41
#include <unordered_map>
41
42
42
#include "cstr.h"
43
#include "cstr.h"
43
#include "pathut.h"
44
#include "pathut.h"
44
#include "rclutil.h"
45
#include "rclutil.h"
45
#include "rclconfig.h"
46
#include "rclconfig.h"
...
...
67
68
68
bool o_uptodate_test_use_mtime = false;
69
bool o_uptodate_test_use_mtime = false;
69
70
70
string RclConfig::o_localecharset; 
71
string RclConfig::o_localecharset; 
71
string RclConfig::o_origcwd; 
72
string RclConfig::o_origcwd; 
73
74
// We build this once. Used to ensure that the suffix used for a temp
75
// file of a given MIME type is the FIRST one from the mimemap config
76
// file. Previously it was the first in alphabetic (map) order, with
77
// sometimes strange results.
78
static unordered_map<string, string> mime_suffixes;
72
79
73
// Compute the difference of 1st to 2nd sets and return as plus/minus
80
// Compute the difference of 1st to 2nd sets and return as plus/minus
74
// sets. Some args are std::set and some others stringToString()
81
// sets. Some args are std::set and some others stringToString()
75
// strings for convenience
82
// strings for convenience
76
void RclConfig::setPlusMinus(const string& sbase, const set<string>& upd,
83
void RclConfig::setPlusMinus(const string& sbase, const set<string>& upd,
...
...
314
    mimemap = new ConfStack<ConfTree>("mimemap", m_cdirs, true);
321
    mimemap = new ConfStack<ConfTree>("mimemap", m_cdirs, true);
315
    if (mimemap == 0 || !mimemap->ok()) {
322
    if (mimemap == 0 || !mimemap->ok()) {
316
    m_reason = string("No or bad mimemap file in: ") + cnferrloc;
323
    m_reason = string("No or bad mimemap file in: ") + cnferrloc;
317
    return;
324
    return;
318
    }
325
    }
326
327
    // Maybe create the MIME to suffix association reverse map. Do it
328
    // in file order so that we can control what suffix is used when
329
    // there are several. This only uses the distributed file, not any
330
    // local customization (too complicated).
331
    if (mime_suffixes.empty()) {
332
        ConfSimple mm(
333
            path_cat(path_cat(m_datadir, "examples"), "mimemap").c_str());
334
        vector<ConfLine> order = mm.getlines();
335
        for (const auto& entry: order) {
336
            if (entry.m_kind == ConfLine::CFL_VAR) {
337
                LOGDEB1("CONFIG: " << entry.m_data << " -> " << entry.m_value <<
338
                        endl);
339
                // Remember: insert() only does anything for new keys,
340
                // so we only have the first value in the map
341
                mime_suffixes.insert(
342
                    pair<string,string>(entry.m_value, entry.m_data));
343
            }
344
        }
345
    }
346
319
    mimeconf = new ConfStack<ConfSimple>("mimeconf", m_cdirs, true);
347
    mimeconf = new ConfStack<ConfSimple>("mimeconf", m_cdirs, true);
320
    if (mimeconf == 0 || !mimeconf->ok()) {
348
    if (mimeconf == 0 || !mimeconf->ok()) {
321
    m_reason = string("No/bad mimeconf in: ") + cnferrloc;
349
    m_reason = string("No/bad mimeconf in: ") + cnferrloc;
322
    return;
350
    return;
323
    }
351
    }
...
...
751
    return mtype;
779
    return mtype;
752
}
780
}
753
781
754
string RclConfig::getSuffixFromMimeType(const string &mt) const
782
string RclConfig::getSuffixFromMimeType(const string &mt) const
755
{
783
{
756
    string suffix;
784
    // First try from standard data, ensuring that we can control the value
785
    // from the order in the configuration file.
786
    auto rclsuff = mime_suffixes.find(mt);
787
    if (rclsuff != mime_suffixes.end()) {
788
        return rclsuff->second;
789
    }
790
    // Try again from local data. The map is in the wrong direction,
791
    // have to walk it.
757
    vector<string>sfs = mimemap->getNames(cstr_null);
792
    vector<string> sfs = mimemap->getNames(cstr_null);
793
    for (const auto& suff : sfs) {
758
    string mt1;
794
        string mt1;
759
    for (vector<string>::const_iterator it = sfs.begin(); 
795
  if (mimemap->get(suff, mt1, cstr_null) && !stringicmp(mt, mt1)) {
760
   it != sfs.end(); it++) {
796
            return suff;
761
  if (mimemap->get(*it, mt1, cstr_null))
797
        }
762
      if (!stringicmp(mt, mt1))
763
      return *it;
764
    }
798
    }
765
    return cstr_null;
799
    return cstr_null;
766
}
800
}
767
801
768
/** Get list of file categories from mimeconf */
802
/** Get list of file categories from mimeconf */