mirror of
https://gitlab.com/niansa/commsyfuse.git
synced 2025-03-06 20:48:31 +01:00
Fixed compiler warning and increased codestyle
This commit is contained in:
parent
5f6b8f1aba
commit
ff9a8acd67
1 changed files with 60 additions and 47 deletions
107
main.cpp
107
main.cpp
|
@ -158,7 +158,7 @@ static std::string gumbo_cleantext(GumboNode* node) {
|
||||||
std::string contents = "";
|
std::string contents = "";
|
||||||
GumboVector* children = &node->v.element.children;
|
GumboVector* children = &node->v.element.children;
|
||||||
for (unsigned int i = 0; i < children->length; ++i) {
|
for (unsigned int i = 0; i < children->length; ++i) {
|
||||||
const std::string text = gumbo_cleantext((GumboNode*) children->data[i]);
|
const std::string text = gumbo_cleantext(reinterpret_cast<GumboNode*> (children->data[i]));
|
||||||
if (i != 0 && !text.empty()) {
|
if (i != 0 && !text.empty()) {
|
||||||
contents.append(" ");
|
contents.append(" ");
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ std::vector<std::string> gumbo_get_attr(GumboNode *node, std::string attrkey, Gu
|
||||||
}
|
}
|
||||||
// Iterate through child nodes
|
// Iterate through child nodes
|
||||||
for (unsigned int it = 0; it < children->length; ++it) {
|
for (unsigned int it = 0; it < children->length; ++it) {
|
||||||
childnode = (GumboNode*) children->data[it];
|
childnode = reinterpret_cast<GumboNode*> (children->data[it]);
|
||||||
if (childnode->v.element.tag == expected_tag) { // If node is the expected tag; use it
|
if (childnode->v.element.tag == expected_tag) { // If node is the expected tag; use it
|
||||||
attrvals.push_back(gumbo_get_attribute(&childnode->v.element.attributes, attrkey.c_str())->value);
|
attrvals.push_back(gumbo_get_attribute(&childnode->v.element.attributes, attrkey.c_str())->value);
|
||||||
} else if (childnode->type == GUMBO_NODE_ELEMENT) { // Else; iterate through its child nodes
|
} else if (childnode->type == GUMBO_NODE_ELEMENT) { // Else; iterate through its child nodes
|
||||||
|
@ -203,7 +203,7 @@ std::string gumbo_find_text_by_tag(GumboNode *node, GumboTag searchtag) {
|
||||||
GumboVector* children = &node->v.element.children;
|
GumboVector* children = &node->v.element.children;
|
||||||
// Iterate through childs
|
// Iterate through childs
|
||||||
for (unsigned int it = 0; it < children->length; ++it) {
|
for (unsigned int it = 0; it < children->length; ++it) {
|
||||||
childnode = (GumboNode*) children->data[it];
|
childnode = reinterpret_cast<GumboNode*> (children->data[it]);
|
||||||
if (childnode->v.element.tag == searchtag) { // If node is the expected tag; check content
|
if (childnode->v.element.tag == searchtag) { // If node is the expected tag; check content
|
||||||
return trim(gumbo_cleantext(childnode));
|
return trim(gumbo_cleantext(childnode));
|
||||||
}
|
}
|
||||||
|
@ -314,6 +314,60 @@ std::string get_rss_url(GumboNode *node) { // Currently unused
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int mode_cli(char *argv[], unsigned long numposts, std::vector<std::string> postsmap_numname, std::vector<std::string> postsmap_nummeta,
|
||||||
|
std::vector<std::string> postsmap_numurl, std::vector<std::string> postsmap_numdesc,
|
||||||
|
std::vector<std::vector<std::string>> postsmap_numfileurls, std::vector<std::vector<std::string>> postsmap_numfilenames) {
|
||||||
|
// Show overview
|
||||||
|
for (unsigned long it = 0; it != numposts; it++) {
|
||||||
|
std::cout << it << ") " << postsmap_numname[it] << " – " << postsmap_nummeta[it] << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << "r) Refresh" << std::endl;
|
||||||
|
// Start CLI loop
|
||||||
|
std::string userinstr;
|
||||||
|
unsigned long userin;
|
||||||
|
while (true) {
|
||||||
|
// Await user input
|
||||||
|
std::cout << "? " << std::flush;
|
||||||
|
if (!std::getline(std::cin, userinstr)) {
|
||||||
|
// On EOF
|
||||||
|
std::cout << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Check string input options first
|
||||||
|
if (userinstr == "") {
|
||||||
|
continue;
|
||||||
|
} else if (userinstr == "r") {
|
||||||
|
execve(argv[0], argv, nullptr);
|
||||||
|
}
|
||||||
|
// Try to convert input to unsigned long
|
||||||
|
try {
|
||||||
|
userin = std::stoul(userinstr,nullptr,0);
|
||||||
|
} catch (const std::invalid_argument &) {
|
||||||
|
std::cerr << "Invalid input" << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Check if givenn number is valid
|
||||||
|
if (userin >= numposts) {
|
||||||
|
std::cerr << "No such post" << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// If required; get posts description and cache it
|
||||||
|
// Print description
|
||||||
|
std::cout << std::endl << std::endl << postsmap_numdesc[userin] << std::endl;
|
||||||
|
// Print informations
|
||||||
|
std::cout << "Post name: " << postsmap_numname[userin] << std::endl;
|
||||||
|
std::cout << "Post URL: " << server_url << postsmap_numurl[userin] << std::endl;
|
||||||
|
if (postsmap_numfilenames[userin].size() != 0) {
|
||||||
|
std::cout << "Post files:" << std::endl;
|
||||||
|
for (unsigned long it = 0; it < postsmap_numfilenames[userin].size(); it++) {
|
||||||
|
std::cout << " – " << postsmap_numfilenames[userin][it] << ": " << server_url << postsmap_numfileurls[userin][it] << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
// Catch SIGSEGV
|
// Catch SIGSEGV
|
||||||
signal(SIGSEGV, sigsegv_panic);
|
signal(SIGSEGV, sigsegv_panic);
|
||||||
|
@ -334,7 +388,6 @@ int main(int argc, char *argv[]) {
|
||||||
server_sid = argv[1];
|
server_sid = argv[1];
|
||||||
room = argv[2];
|
room = argv[2];
|
||||||
std::stringstream httpcontent;
|
std::stringstream httpcontent;
|
||||||
std::string rss_url;
|
|
||||||
std::vector<std::string> postsmap_numname;
|
std::vector<std::string> postsmap_numname;
|
||||||
std::vector<std::string> postsmap_nummeta;
|
std::vector<std::string> postsmap_nummeta;
|
||||||
std::vector<std::string> postsmap_numurl;
|
std::vector<std::string> postsmap_numurl;
|
||||||
|
@ -381,49 +434,9 @@ int main(int argc, char *argv[]) {
|
||||||
postsmap_numfileurls[numposts].push_back(pair.second);
|
postsmap_numfileurls[numposts].push_back(pair.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Show overview
|
|
||||||
std::cout << numposts << ") " << postsmap_numname[numposts] << " – " << postsmap_nummeta[numposts] << std::endl;
|
|
||||||
numposts++;
|
numposts++;
|
||||||
}
|
}
|
||||||
std::cout << "r) Refresh" << std::endl;
|
// Start CLI
|
||||||
// Debug CLI
|
return mode_cli(argv, numposts, postsmap_numname, postsmap_nummeta,postsmap_numurl,
|
||||||
std::string userinstr;
|
postsmap_numdesc, postsmap_numfileurls, postsmap_numfilenames);
|
||||||
unsigned long userin;
|
|
||||||
while (true) {
|
|
||||||
// Await user input
|
|
||||||
std::cout << "? " << std::flush;
|
|
||||||
std::getline (std::cin,userinstr);
|
|
||||||
// Check string input options first
|
|
||||||
if (userinstr == "") {
|
|
||||||
continue;
|
|
||||||
} else if (userinstr == "r") {
|
|
||||||
execve(argv[0], argv, nullptr);
|
|
||||||
}
|
|
||||||
// Try to convert input to unsigned long
|
|
||||||
try {
|
|
||||||
userin = std::stoul(userinstr,nullptr,0);
|
|
||||||
} catch (const std::invalid_argument &) {
|
|
||||||
std::cerr << "Invalid input" << std::endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Check if givenn number is valid
|
|
||||||
if (userin >= numposts) {
|
|
||||||
std::cerr << "No such post" << std::endl;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// If required; get posts description and cache it
|
|
||||||
// Print description
|
|
||||||
std::cout << std::endl << std::endl << postsmap_numdesc[userin] << std::endl;
|
|
||||||
// Print informations
|
|
||||||
std::cout << "Post name: " << postsmap_numname[userin] << std::endl;
|
|
||||||
std::cout << "Post URL: " << server_url << postsmap_numurl[userin] << std::endl;
|
|
||||||
if (postsmap_numfilenames[userin].size() != 0) {
|
|
||||||
std::cout << "Post files:" << std::endl;
|
|
||||||
for (unsigned long it = 0; it < postsmap_numfilenames[userin].size(); it++) {
|
|
||||||
std::cout << " – " << postsmap_numfilenames[userin][it] << ": " << server_url << postsmap_numfileurls[userin][it] << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue