1 /**
2  * Copyright (c) 2020, Timothy Stack
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * * Neither the name of Timothy Stack nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * @file file_format.hh
30  */
31 
32 #ifndef lnav_file_format_hh
33 #define lnav_file_format_hh
34 
35 #include "fmt/format.h"
36 #include "ghc/filesystem.hpp"
37 
38 enum class file_format_t {
39     FF_UNKNOWN,
40     FF_SQLITE_DB,
41     FF_ARCHIVE,
42     FF_REMOTE,
43 };
44 
45 file_format_t detect_file_format(const ghc::filesystem::path& filename);
46 
47 namespace fmt {
48 template<>
49 struct formatter<file_format_t> : formatter<string_view> {
50     template<typename FormatContext>
formatfmt::formatter51     auto format(file_format_t ff, FormatContext &ctx)
52     {
53         string_view name = "unknown";
54         switch (ff) {
55             case file_format_t::FF_SQLITE_DB:
56                 name = "\U0001F5C2  SQLite DB";
57                 break;
58             case file_format_t::FF_ARCHIVE:
59                 name = "\U0001F5C4  Archive";
60                 break;
61             case file_format_t::FF_REMOTE:
62                 name = "\U0001F5A5  Remote";
63                 break;
64             default:
65                 break;
66         }
67         return formatter<string_view>::format(name, ctx);
68     }
69 };
70 }
71 
72 
73 #endif
74