Cleanup include dependencies a bit
This commit is contained in:
parent
da6d7f4530
commit
12856066b1
|
@ -4,6 +4,8 @@
|
|||
#include "event_manager.hh"
|
||||
#include "file.hh"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define st_mtim st_mtimespec
|
||||
#endif
|
||||
|
@ -128,7 +130,7 @@ Buffer* create_fifo_buffer(String name, int fd, bool scroll)
|
|||
ssize_t count = 0;
|
||||
do
|
||||
{
|
||||
count = read(fifo, data, buffer_size);
|
||||
count = ::read(fifo, data, buffer_size);
|
||||
auto pos = buffer->back_coord();
|
||||
|
||||
const bool prevent_scrolling = pos == BufferCoord{0,0} and not scroll;
|
||||
|
@ -165,8 +167,8 @@ void write_to_debug_buffer(StringView str)
|
|||
{
|
||||
if (not BufferManager::has_instance())
|
||||
{
|
||||
write_stderr(str);
|
||||
write_stderr("\n");
|
||||
write(2, str);
|
||||
write(2, "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "register_manager.hh"
|
||||
#include "insert_completer.hh"
|
||||
#include "remote.hh"
|
||||
#include "regex.hh"
|
||||
#include "shell_manager.hh"
|
||||
#include "string.hh"
|
||||
#include "window.hh"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "completion.hh"
|
||||
#include "file.hh"
|
||||
#include "context.hh"
|
||||
#include "regex.hh"
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
|
28
src/file.cc
28
src/file.cc
|
@ -2,10 +2,11 @@
|
|||
|
||||
#include "assert.hh"
|
||||
#include "buffer.hh"
|
||||
#include "unicode.hh"
|
||||
#include "exception.hh"
|
||||
#include "ranked_match.hh"
|
||||
#include "regex.hh"
|
||||
#include "string.hh"
|
||||
#include "unicode.hh"
|
||||
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
|
@ -33,6 +34,14 @@
|
|||
namespace Kakoune
|
||||
{
|
||||
|
||||
struct file_access_error : runtime_error
|
||||
{
|
||||
public:
|
||||
file_access_error(StringView filename,
|
||||
StringView error_desc)
|
||||
: runtime_error(format("{}: {}", filename, error_desc)) {}
|
||||
};
|
||||
|
||||
String parse_filename(StringView filename)
|
||||
{
|
||||
if (filename.length() >= 1 and filename[0_byte] == '~' and
|
||||
|
@ -168,14 +177,9 @@ String read_file(StringView filename, bool text)
|
|||
{
|
||||
int fd = open(parse_filename(filename).c_str(), O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
throw file_not_found(filename);
|
||||
|
||||
throw file_access_error(filename, strerror(errno));
|
||||
}
|
||||
auto close_fd = on_scope_end([fd]{ close(fd); });
|
||||
|
||||
auto close_fd = on_scope_end([fd]{ close(fd); });
|
||||
return read_fd(fd, text);
|
||||
}
|
||||
|
||||
|
@ -185,12 +189,7 @@ MappedFile::MappedFile(StringView filename)
|
|||
|
||||
fd = open(real_filename.c_str(), O_RDONLY | O_NONBLOCK);
|
||||
if (fd == -1)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
throw file_not_found{real_filename};
|
||||
|
||||
throw file_access_error(real_filename, strerror(errno));
|
||||
}
|
||||
|
||||
fstat(fd, &st);
|
||||
if (S_ISDIR(st.st_mode))
|
||||
|
@ -208,6 +207,11 @@ MappedFile::~MappedFile()
|
|||
}
|
||||
}
|
||||
|
||||
MappedFile::operator StringView() const
|
||||
{
|
||||
return { data, (int)st.st_size };
|
||||
}
|
||||
|
||||
bool file_exists(StringView filename)
|
||||
{
|
||||
String real_filename = real_path(parse_filename(filename));
|
||||
|
|
27
src/file.hh
27
src/file.hh
|
@ -2,10 +2,9 @@
|
|||
#define file_hh_INCLUDED
|
||||
|
||||
#include "array_view.hh"
|
||||
#include "completion.hh"
|
||||
#include "exception.hh"
|
||||
#include "regex.hh"
|
||||
#include "flags.hh"
|
||||
#include "units.hh"
|
||||
#include "vector.hh"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -13,23 +12,12 @@
|
|||
namespace Kakoune
|
||||
{
|
||||
|
||||
struct file_access_error : runtime_error
|
||||
{
|
||||
public:
|
||||
file_access_error(StringView filename,
|
||||
StringView error_desc)
|
||||
: runtime_error(format("{}: {}", filename, error_desc)) {}
|
||||
};
|
||||
|
||||
struct file_not_found : file_access_error
|
||||
{
|
||||
file_not_found(StringView filename)
|
||||
: file_access_error(filename, "file not found") {}
|
||||
};
|
||||
|
||||
class Buffer;
|
||||
class String;
|
||||
class StringView;
|
||||
class Regex;
|
||||
|
||||
using CandidateList = Vector<String, MemoryDomain::Completion>;
|
||||
|
||||
// parse ~/ and $env values in filename and returns the translated filename
|
||||
String parse_filename(StringView filename);
|
||||
|
@ -45,16 +33,13 @@ bool fd_readable(int fd);
|
|||
String read_fd(int fd, bool text = false);
|
||||
String read_file(StringView filename, bool text = false);
|
||||
void write(int fd, StringView data);
|
||||
inline void write_stdout(StringView str) { write(1, str); }
|
||||
inline void write_stderr(StringView str) { write(2, str); }
|
||||
|
||||
|
||||
struct MappedFile
|
||||
{
|
||||
MappedFile(StringView filename);
|
||||
~MappedFile();
|
||||
|
||||
operator StringView() const { return { data, (int)st.st_size }; }
|
||||
operator StringView() const;
|
||||
|
||||
int fd;
|
||||
const char* data;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "containers.hh"
|
||||
#include "display_buffer.hh"
|
||||
#include "exception.hh"
|
||||
#include "keys.hh"
|
||||
#include "file.hh"
|
||||
#include "event_manager.hh"
|
||||
|
@ -159,7 +160,7 @@ void rpc_call(StringView method, Args&&... args)
|
|||
auto q = format(R"(\{ "jsonrpc": "2.0", "method": "{}", "params": [{}] }{})",
|
||||
method, concat(std::forward<Args>(args)...), "\n");
|
||||
|
||||
write_stdout(q);
|
||||
write(1, q);
|
||||
}
|
||||
|
||||
JsonUI::JsonUI()
|
||||
|
@ -424,7 +425,7 @@ void JsonUI::parse_requests(EventMode mode)
|
|||
}
|
||||
catch (runtime_error& error)
|
||||
{
|
||||
write_stderr(format("error while handling requests '{}': '{}'",
|
||||
write(2, format("error while handling requests '{}': '{}'",
|
||||
m_requests, error.what()));
|
||||
// try to salvage request by dropping its first line
|
||||
pos = std::min(m_requests.end(), find(m_requests, '\n')+1);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "parameters_parser.hh"
|
||||
#include "register_manager.hh"
|
||||
#include "remote.hh"
|
||||
#include "regex.hh"
|
||||
#include "scope.hh"
|
||||
#include "shell_manager.hh"
|
||||
#include "string.hh"
|
||||
|
@ -38,6 +39,9 @@ struct startup_error : Kakoune::runtime_error
|
|||
using Kakoune::runtime_error::runtime_error;
|
||||
};
|
||||
|
||||
inline void write_stdout(StringView str) { write(1, str); }
|
||||
inline void write_stderr(StringView str) { write(2, str); }
|
||||
|
||||
String runtime_directory()
|
||||
{
|
||||
char relpath[PATH_MAX+1];
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
#include "ranked_match.hh"
|
||||
|
||||
#include "utf8_iterator.hh"
|
||||
#include "flags.hh"
|
||||
#include "unit_tests.hh"
|
||||
#include "utf8_iterator.hh"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
template<> struct WithBitOps<RankedMatch::Flags> : std::true_type {};
|
||||
|
||||
UsedLetters used_letters(StringView str)
|
||||
{
|
||||
UsedLetters res = 0;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define ranked_match_hh_INCLUDED
|
||||
|
||||
#include "string.hh"
|
||||
#include "flags.hh"
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
@ -51,8 +50,6 @@ private:
|
|||
int m_max_index = 0;
|
||||
};
|
||||
|
||||
template<> struct WithBitOps<RankedMatch::Flags> : std::true_type {};
|
||||
|
||||
}
|
||||
|
||||
#endif // ranked_match_hh_INCLUDED
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
#include "shell_manager.hh"
|
||||
|
||||
#include "buffer_utils.hh"
|
||||
#include "clock.hh"
|
||||
#include "context.hh"
|
||||
#include "buffer_utils.hh"
|
||||
#include "event_manager.hh"
|
||||
#include "file.hh"
|
||||
#include "face_registry.hh"
|
||||
#include "display_buffer.hh"
|
||||
#include "event_manager.hh"
|
||||
#include "face_registry.hh"
|
||||
#include "file.hh"
|
||||
#include "regex.hh"
|
||||
|
||||
#include <cstring>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -114,7 +114,7 @@ public:
|
|||
explicit String(Codepoint cp, ColumnCount count)
|
||||
{
|
||||
kak_assert(count % codepoint_width(cp) == 0);
|
||||
int cp_count = (int)count / codepoint_width(cp);
|
||||
int cp_count = (int)(count / codepoint_width(cp));
|
||||
reserve(utf8::codepoint_size(cp) * cp_count);
|
||||
while (cp_count-- > 0)
|
||||
utf8::dump(std::back_inserter(*this), cp);
|
||||
|
@ -289,7 +289,7 @@ inline String& operator+=(String& lhs, StringView rhs)
|
|||
inline String operator+(StringView lhs, StringView rhs)
|
||||
{
|
||||
String res;
|
||||
res.reserve((int)(lhs.length() + rhs.length()));
|
||||
res.reserve(lhs.length() + rhs.length());
|
||||
res.append(lhs.data(), lhs.length());
|
||||
res.append(rhs.data(), rhs.length());
|
||||
return res;
|
||||
|
@ -312,6 +312,11 @@ inline bool operator<(const StringView& lhs, const StringView& rhs)
|
|||
rhs.begin(), rhs.end());
|
||||
}
|
||||
|
||||
inline String operator"" _str(const char* str, size_t)
|
||||
{
|
||||
return String(str);
|
||||
}
|
||||
|
||||
Vector<String> split(StringView str, char separator, char escape);
|
||||
Vector<StringView> split(StringView str, char separator);
|
||||
|
||||
|
@ -335,11 +340,17 @@ String join(const Container& container, char joiner, bool esc_joiner = true)
|
|||
return res;
|
||||
}
|
||||
|
||||
inline String operator"" _str(const char* str, size_t)
|
||||
inline bool prefix_match(StringView str, StringView prefix)
|
||||
{
|
||||
return String(str);
|
||||
return str.substr(0_byte, prefix.length()) == prefix;
|
||||
}
|
||||
|
||||
bool subsequence_match(StringView str, StringView subseq);
|
||||
|
||||
String expand_tabs(StringView line, ColumnCount tabstop, ColumnCount col = 0);
|
||||
|
||||
Vector<StringView> wrap_lines(StringView text, ColumnCount max_width);
|
||||
|
||||
int str_to_int(StringView str); // throws on error
|
||||
Optional<int> str_to_int_ifp(StringView str);
|
||||
|
||||
|
@ -377,17 +388,6 @@ to_string(const StronglyTypedNumber<RealType, ValueType>& val)
|
|||
return to_string((ValueType)val);
|
||||
}
|
||||
|
||||
inline bool prefix_match(StringView str, StringView prefix)
|
||||
{
|
||||
return str.substr(0_byte, prefix.length()) == prefix;
|
||||
}
|
||||
|
||||
bool subsequence_match(StringView str, StringView subseq);
|
||||
|
||||
String expand_tabs(StringView line, ColumnCount tabstop, ColumnCount col = 0);
|
||||
|
||||
Vector<StringView> wrap_lines(StringView text, ColumnCount max_width);
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include <wchar.h>
|
||||
#include <locale>
|
||||
|
||||
#include "units.hh"
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
|
@ -49,7 +51,7 @@ inline bool is_basic_alpha(Codepoint c)
|
|||
return (c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z');
|
||||
}
|
||||
|
||||
inline size_t codepoint_width(Codepoint c)
|
||||
inline ColumnCount codepoint_width(Codepoint c)
|
||||
{
|
||||
return c == '\n' ? 1 : wcwidth((wchar_t)c);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user