Skip to content

Commit

Permalink
Set 2-space indent in main file
Browse files Browse the repository at this point in the history
  • Loading branch information
sergei-mironov committed Jul 22, 2019
1 parent c4bf5a2 commit 23643e3
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 110 deletions.
10 changes: 10 additions & 0 deletions localrc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
" Set the identation size
function! Ident(ident_spaces)
let &expandtab=1
let &shiftwidth=a:ident_spaces
let &tabstop=a:ident_spaces
let &cinoptions="'g0,(".a:ident_spaces
let &softtabstop=a:ident_spaces
endfunction

call Ident(2)
220 changes: 110 additions & 110 deletions src/XKbSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,129 +31,129 @@ using namespace kb;

void usage()
{
cerr << "Usage: xkb-switch -s ARG Sets current layout group to ARG" << endl;
cerr << " xkb-switch -l|--list Displays all layout groups" << endl;
cerr << " xkb-switch -h|--help Displays this message" << endl;
cerr << " xkb-switch -v|--version Shows version number" << endl;
cerr << " xkb-switch -w|--wait [-p] Waits for group change" << endl;
cerr << " xkb-switch -W Infinitely waits for group change, prints group names to stdout" << endl;
cerr << " xkb-switch -n|--next Switch to the next layout group" << endl;
cerr << " xkb-switch [-p] Displays current layout group" << endl;
cerr << "Usage: xkb-switch -s ARG Sets current layout group to ARG" << endl;
cerr << " xkb-switch -l|--list Displays all layout groups" << endl;
cerr << " xkb-switch -h|--help Displays this message" << endl;
cerr << " xkb-switch -v|--version Shows version number" << endl;
cerr << " xkb-switch -w|--wait [-p] Waits for group change" << endl;
cerr << " xkb-switch -W Infinitely waits for group change, prints group names to stdout" << endl;
cerr << " xkb-switch -n|--next Switch to the next layout group" << endl;
cerr << " xkb-switch [-p] Displays current layout group" << endl;
}

string print_layouts(const string_vector& sv)
{
ostringstream oss;
bool fst = true;

oss << "[";
for(string_vector::const_iterator i=sv.begin(); i!=sv.end(); i++) {
if(!fst) oss << " ";
oss << *i;
fst = false;
}
oss << "]";
return oss.str();
ostringstream oss;
bool fst = true;

oss << "[";
for(string_vector::const_iterator i=sv.begin(); i!=sv.end(); i++) {
if(!fst) oss << " ";
oss << *i;
fst = false;
}
oss << "]";
return oss.str();
}

int main( int argc, char* argv[] )
{
string_vector syms;

using namespace std;
try {
int m_cnt = 0;
int m_wait = 0;
int m_lwait = 0;
int m_print = 0;
int m_next = 0;
int m_list = 0;
string newgrp;

for(int i=1; i<argc; i) {
string arg(argv[i++]);
if(arg == "-s") {
CHECK_MSG(i<argc, "Argument expected");
newgrp=argv[i++];
m_cnt++;
}
else if(arg == "-l" || arg == "--list") {
m_list = 1;
m_cnt++;
}
else if(arg == "-v" || arg=="--version") {
cerr << "xkb-switch " << XKBSWITCH_VERSION << endl;
return 0;
}
else if(arg == "-w" || arg == "--wait") {
m_wait = 1;
m_cnt++;
}
else if(arg == "-W" || arg == "--longwait") {
m_lwait = 1;
m_cnt++;
}
else if(arg == "-p" || arg == "--print") {
m_print = 1;
m_cnt++;
}
else if(arg == "-n" || arg == "--next") {
m_next = 1;
m_cnt++;
}
else if(arg == "-h" || arg == "--help") {
usage();
return 1;
}
else {
THROW_MSG("Invalid argument: '" << arg << "'. Check --help.");
}
}

if(m_list || m_lwait || !newgrp.empty())
CHECK_MSG(m_cnt==1, "Invalid flag combination. Try --help.");

// Default action
if(m_cnt==0)
m_print = 1;

XKeyboard xkb;
try {
int m_cnt = 0;
int m_wait = 0;
int m_lwait = 0;
int m_print = 0;
int m_next = 0;
int m_list = 0;
string newgrp;

for(int i=1; i<argc; i) {
string arg(argv[i++]);
if(arg == "-s") {
CHECK_MSG(i<argc, "Argument expected");
newgrp=argv[i++];
m_cnt++;
}
else if(arg == "-l" || arg == "--list") {
m_list = 1;
m_cnt++;
}
else if(arg == "-v" || arg=="--version") {
cerr << "xkb-switch " << XKBSWITCH_VERSION << endl;
return 0;
}
else if(arg == "-w" || arg == "--wait") {
m_wait = 1;
m_cnt++;
}
else if(arg == "-W" || arg == "--longwait") {
m_lwait = 1;
m_cnt++;
}
else if(arg == "-p" || arg == "--print") {
m_print = 1;
m_cnt++;
}
else if(arg == "-n" || arg == "--next") {
m_next = 1;
m_cnt++;
}
else if(arg == "-h" || arg == "--help") {
usage();
return 1;
}
else {
THROW_MSG("Invalid argument: '" << arg << "'. Check --help.");
}
}

if(m_list || m_lwait || !newgrp.empty())
CHECK_MSG(m_cnt==1, "Invalid flag combination. Try --help.");

// Default action
if(m_cnt==0)
m_print = 1;

XKeyboard xkb;
xkb.open_display();

if(m_wait) {
xkb.wait_event();
}

if(m_lwait) {
while(true) {
xkb.wait_event();
xkb.build_layout(syms);
cout << syms.at(xkb.get_group()) << endl;
}
}

if (m_lwait)
syms.clear();

xkb.build_layout(syms);

if (m_next) {
CHECK_MSG(!syms.empty(), "No layout groups configured");
const string nextgrp = syms.at(xkb.get_group());
string_vector::iterator i = find(syms.begin(), syms.end(), nextgrp);
if (++i == syms.end()) i = syms.begin();
xkb.set_group(i - syms.begin());
}
else if(!newgrp.empty()) {
string_vector::iterator i = find(syms.begin(), syms.end(), newgrp);
CHECK_MSG(i!=syms.end(),
"Group '" << newgrp << "' is not supported by current layout. Try xkb-switch -l.");
xkb.set_group(i-syms.begin());
}

if(m_print) {
cout << syms.at(xkb.get_group()) << endl;
}
if(m_wait) {
xkb.wait_event();
}

if(m_lwait) {
while(true) {
xkb.wait_event();
xkb.build_layout(syms);
cout << syms.at(xkb.get_group()) << endl;
}
}

if (m_lwait)
syms.clear();

xkb.build_layout(syms);

if (m_next) {
CHECK_MSG(!syms.empty(), "No layout groups configured");
const string nextgrp = syms.at(xkb.get_group());
string_vector::iterator i = find(syms.begin(), syms.end(), nextgrp);
if (++i == syms.end()) i = syms.begin();
xkb.set_group(i - syms.begin());
}
else if(!newgrp.empty()) {
string_vector::iterator i = find(syms.begin(), syms.end(), newgrp);
CHECK_MSG(i!=syms.end(),
"Group '" << newgrp << "' is not supported by current layout. Try xkb-switch -l.");
xkb.set_group(i-syms.begin());
}

if(m_print) {
cout << syms.at(xkb.get_group()) << endl;
}

if(m_list) {
for(int i=0; i<syms.size(); i++) {
Expand Down

0 comments on commit 23643e3

Please sign in to comment.