diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2012-11-18 16:30:30 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2012-11-18 16:30:30 -0800 |
commit | 9992b8eb0e3366ff8a3948aa0b66a19c3c12c737 (patch) | |
tree | 6dda0fef85812016fbba9ea067c9d586092b506d /kill.cpp | |
parent | bab69f26724028d16054a3daf5c78aad7c67bb2d (diff) |
Apply new indentation, brace, and whitespace style
Diffstat (limited to 'kill.cpp')
-rw-r--r-- | kill.cpp | 162 |
1 files changed, 85 insertions, 77 deletions
@@ -36,7 +36,7 @@ */ #define KILL_MAX 8192 - /** Last kill string */ +/** Last kill string */ //static ll_node_t *kill_last=0; /** Current kill string */ @@ -57,76 +57,78 @@ static wchar_t *cut_buffer=0; */ static int has_xsel() { - static int res=-1; - if (res < 0) { - res = !! path_get_path(L"xsel", NULL); + static int res=-1; + if (res < 0) + { + res = !! path_get_path(L"xsel", NULL); } - return res; + return res; } -void kill_add( const wcstring &str ) +void kill_add(const wcstring &str) { ASSERT_IS_MAIN_THREAD(); if (str.empty()) return; - wcstring cmd; + wcstring cmd; wchar_t *escaped_str = NULL; - kill_list.push_front(str); + kill_list.push_front(str); - /* - Check to see if user has set the FISH_CLIPBOARD_CMD variable, - and, if so, use it instead of checking the display, etc. + /* + Check to see if user has set the FISH_CLIPBOARD_CMD variable, + and, if so, use it instead of checking the display, etc. - I couldn't think of a safe way to allow overide of the echo - command too, so, the command used must accept the input via stdin. - */ + I couldn't think of a safe way to allow overide of the echo + command too, so, the command used must accept the input via stdin. + */ - const env_var_t clipboard_wstr = env_get_string(L"FISH_CLIPBOARD_CMD"); - if( !clipboard_wstr.missing() ) - { - escaped_str = escape( str.c_str(), 1 ); + const env_var_t clipboard_wstr = env_get_string(L"FISH_CLIPBOARD_CMD"); + if (!clipboard_wstr.missing()) + { + escaped_str = escape(str.c_str(), 1); cmd.assign(L"echo -n "); cmd.append(escaped_str); cmd.append(clipboard_wstr); - } - else - { - /* This is for sending the kill to the X copy-and-paste buffer */ - if( !has_xsel() ) { - return; } - - const env_var_t disp_wstr = env_get_string( L"DISPLAY" ); - if( !disp_wstr.missing() ) - { - escaped_str = escape( str.c_str(), 1 ); + else + { + /* This is for sending the kill to the X copy-and-paste buffer */ + if (!has_xsel()) + { + return; + } + + const env_var_t disp_wstr = env_get_string(L"DISPLAY"); + if (!disp_wstr.missing()) + { + escaped_str = escape(str.c_str(), 1); cmd.assign(L"echo "); cmd.append(escaped_str); - cmd.append(L"|xsel -b" ); + cmd.append(L"|xsel -b"); + } } - } - if (! cmd.empty()) - { - if( exec_subshell(cmd) == -1 ) + if (! cmd.empty()) { - /* - Do nothing on failiure - */ - } + if (exec_subshell(cmd) == -1) + { + /* + Do nothing on failiure + */ + } - free( cut_buffer ); + free(cut_buffer); - cut_buffer = escaped_str; - } + cut_buffer = escaped_str; + } } /** Remove first match for specified string from circular list */ -static void kill_remove( const wcstring &s ) +static void kill_remove(const wcstring &s) { ASSERT_IS_MAIN_THREAD(); kill_list_t::iterator iter = std::find(kill_list.begin(), kill_list.end(), s); @@ -136,19 +138,22 @@ static void kill_remove( const wcstring &s ) -void kill_replace( const wcstring &old, const wcstring &newv ) +void kill_replace(const wcstring &old, const wcstring &newv) { - kill_remove( old ); - kill_add( newv ); + kill_remove(old); + kill_add(newv); } const wchar_t *kill_yank_rotate() { ASSERT_IS_MAIN_THREAD(); // Move the first element to the end - if (kill_list.empty()) { + if (kill_list.empty()) + { return NULL; - } else { + } + else + { kill_list.splice(kill_list.end(), kill_list, kill_list.begin()); return kill_list.front().c_str(); } @@ -160,52 +165,55 @@ const wchar_t *kill_yank_rotate() */ static void kill_check_x_buffer() { - if( !has_xsel() ) - return; - - const env_var_t disp = env_get_string(L"DISPLAY"); - if( ! disp.missing()) - { - size_t i; - wcstring cmd = L"xsel -t 500 -b"; - wcstring new_cut_buffer=L""; - wcstring_list_t list; - if( exec_subshell( cmd, list ) != -1 ) + if (!has_xsel()) + return; + + const env_var_t disp = env_get_string(L"DISPLAY"); + if (! disp.missing()) { + size_t i; + wcstring cmd = L"xsel -t 500 -b"; + wcstring new_cut_buffer=L""; + wcstring_list_t list; + if (exec_subshell(cmd, list) != -1) + { - for( i=0; i<list.size(); i++ ) - { - wcstring next_line = escape_string( list.at(i), 0 ); + for (i=0; i<list.size(); i++) + { + wcstring next_line = escape_string(list.at(i), 0); if (i > 0) new_cut_buffer += L"\\n"; new_cut_buffer += next_line; - } + } - if( new_cut_buffer.size() > 0 ) - { - /* - The buffer is inserted with backslash escapes, - since we don't really like tabs, newlines, - etc. anyway. - */ + if (new_cut_buffer.size() > 0) + { + /* + The buffer is inserted with backslash escapes, + since we don't really like tabs, newlines, + etc. anyway. + */ if (cut_buffer == NULL || cut_buffer != new_cut_buffer) { free(cut_buffer); cut_buffer = wcsdup(new_cut_buffer.c_str()); - kill_list.push_front( new_cut_buffer ); + kill_list.push_front(new_cut_buffer); } - } + } + } } - } } const wchar_t *kill_yank() { - kill_check_x_buffer(); - if (kill_list.empty()) { + kill_check_x_buffer(); + if (kill_list.empty()) + { return L""; - } else { + } + else + { return kill_list.front().c_str(); } } @@ -220,7 +228,7 @@ void kill_init() void kill_destroy() { - if( cut_buffer ) - free( cut_buffer ); + if (cut_buffer) + free(cut_buffer); } |