From 10927a226f351c0a12a82e3ea0906793e612a42c Mon Sep 17 00:00:00 2001 From: Inventor Xtreme Date: Thu, 7 May 2026 23:10:32 -0400 Subject: [PATCH] sync --- Makefile | 8 +-- src/curlwrap.cpp | 6 +- src/curlwrap.hpp | 2 +- src/custom_types.cpp | 65 +++++++++++++++++++++ src/custom_types.hpp | 57 +++++++++++++++++++ src/main.cpp | 126 ++++++++++++++--------------------------- src/summarymanager.cpp | 66 ++++++++++++++++++++- src/summarymanager.hpp | 17 +++++- 8 files changed, 252 insertions(+), 95 deletions(-) create mode 100644 src/custom_types.cpp create mode 100644 src/custom_types.hpp diff --git a/Makefile b/Makefile index 49715ae..05348bd 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ CC = gcc CXX = g++ -CPPFLAGS = -g #-O3 -ffast-math -CFLAGS = -g #-O3 -ffast-math -LDFLAGS = -g #-O3 -ffast-math +CPPFLAGS = -std=c++20 -g -Wall -Wextra -Wpedantic #-O3 -ffast-math +CFLAGS = -g -Wall -Wextra -Wpedantic #-O3 -ffast-math +LDFLAGS = -g -Wall -Wextra -Wpedantic #-O3 -ffast-math LDLIBS = -lfltk -lcurl -lfltk_images @@ -33,7 +33,7 @@ $(EXE): $(OBJ) | $(BIN_DIR) $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR) - $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) -c $< -o $@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR) diff --git a/src/curlwrap.cpp b/src/curlwrap.cpp index 3a4f615..e2bcb0c 100644 --- a/src/curlwrap.cpp +++ b/src/curlwrap.cpp @@ -32,9 +32,8 @@ void Curl::seturl(std::string url) { curl_easy_setopt(handle, CURLOPT_WRITEDATA, &data); } -std::string Curl::get() { - curl_easy_perform(handle); - return data; +CURLcode Curl::get() { + return curl_easy_perform(handle); } @@ -42,3 +41,4 @@ std::string Curl::get() { + diff --git a/src/curlwrap.hpp b/src/curlwrap.hpp index 1522c43..2c36662 100644 --- a/src/curlwrap.hpp +++ b/src/curlwrap.hpp @@ -14,7 +14,7 @@ struct Curl { void seturl(std::string url); - std::string get(); + CURLcode get(); }; diff --git a/src/custom_types.cpp b/src/custom_types.cpp new file mode 100644 index 0000000..0620a71 --- /dev/null +++ b/src/custom_types.cpp @@ -0,0 +1,65 @@ +#include "custom_types.hpp" +#include "curlwrap.hpp" + + + +Person::Person(std::string &y, std::string &n) : year(y), name(n) {} + +std::string Person::toString() const { + return "{(Person): " + year + ", " + name + "}"; + +} + + +std::ostream &operator<<(std::ostream &os, const Person &e) { + // os << "{(Person): " << e.year << ", " << e.name << "}"; + os << e.toString(); + return os; +} + + + +std::string BasicEntry::toString() const { + return "{(BasicEntry): " + A.toString() + ", " + B.toString() + ", " + matchlink + +", " + + std::to_string(Apercent) + "%, " + std::to_string(Bpercent) + "%}"; + +} + +std::ostream &operator<<(std::ostream &os, const BasicEntry &e) { + // os << "{(BasicEntry): " << e.A << ", " << e.B << ", " << e.matchlink << "}"; + os << e.toString(); + return os; +} + + + + + +ComplexEntry::ComplexEntry(BasicEntry basic) : basic(basic) { + Curl net; + auto downbase = basic.matchlink; + auto Adown = downbase.substr(0, downbase.length() - 5) + "-0.html"; + auto Bdown = downbase.substr(0, downbase.length() - 5) + "-1.html"; + net.seturl(Adown); + auto ACODE = net.get(); + if (ACODE != CURLE_OK) { + throw("A_NET_ERR"); + } else { + A_buf = net.data; + } + net.seturl(Bdown); + auto BCODE = net.get(); + if (BCODE != CURLE_OK) { + throw("B_NET_ERR"); + } else { + B_buf = net.data; + } + + + + + +} + + + diff --git a/src/custom_types.hpp b/src/custom_types.hpp new file mode 100644 index 0000000..d560abf --- /dev/null +++ b/src/custom_types.hpp @@ -0,0 +1,57 @@ +#ifndef CUSTOM_TYPES_HEADER +#define CUSTOM_TYPES_HEADER + +#include "curlwrap.hpp" +#include + + + +struct Person { + std::string year; + std::string name; + + Person(std::string &y, std::string &n); + std::string toString() const; + + friend std::ostream& operator<<(std::ostream &os, const Person &e); +}; +std::ostream& operator<<(std::ostream &os, const Person &e); + +struct BasicEntry { + Person A; + Person B; + + std::string matchlink; + + int Apercent; + int Bpercent; + + std::string toString() const; + + friend std::ostream &operator<<(std::ostream &os, const BasicEntry &e); +}; +std::ostream &operator<<(std::ostream &os, const BasicEntry &e); + + +struct ComplexEntry { //TODO: Keep track of match regions + BasicEntry basic; + + std::string A_buf; + + std::string B_buf; + + + ComplexEntry(BasicEntry basic); + + + + + +}; + + + + +#endif + + diff --git a/src/main.cpp b/src/main.cpp index 6c22e51..c8a7b5d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ #include "images.h" #include "summarymanager.hpp" #include "testcpp.hpp" +#include "custom_types.hpp" #include #include @@ -22,60 +23,16 @@ #include #include -using namespace std; -struct Person { - std::string year; - std::string name; - Person(std::string &y, std::string &n) : year(y), name(n) {} - std::string toString() const { - return "{(Person): " + year + ", " + name + "}"; - } -}; - -std::ostream &operator<<(std::ostream &os, const Person &e) { - // os << "{(Person): " << e.year << ", " << e.name << "}"; - os << e.toString(); - return os; -} - -struct BasicEntry { - Person A; - Person B; - - std::string matchlink; - - int Apercent; - int Bpercent; - - std::string toString() const { - return "{(BasicEntry): " + A.toString() + ", " + B.toString() + ", " + matchlink + +", " + - std::to_string(Apercent) + "%, " + std::to_string(Bpercent) + "%}"; - } -}; -std::ostream &operator<<(std::ostream &os, const BasicEntry &e) { - // os << "{(BasicEntry): " << e.A << ", " << e.B << ", " << e.matchlink << "}"; - os << e.toString(); - return os; -} struct Selected { Fl_Multi_Browser &browser; Selected(Fl_Multi_Browser &browser_in) : browser(browser_in) {} }; -void show_callback(Fl_Widget *w, void *data) { - Selected *rdata = (Selected *)data; +void show_callback(Fl_Widget *w, void * data); - auto s = rdata->browser.size() + 1; - - for (size_t i = 0; i < s; i++) { - if (rdata->browser.selected(i)) { - fl_alert("%s", rdata->browser.text(i)); - } - } -} std::vector MakeEntires(std::string filename) { @@ -206,12 +163,14 @@ struct MainGui : Fl_Window { Fl_Tile *tilebox; Fl_Multi_Browser *list; SummaryManager *summaryEditor; + State s; MainGui() : Fl_Window(0, 0, 1000, 750, "MossMan :3") { topbar = new Topbar(0, 0, 1000, 50); tilebox = new Fl_Tile(0, 50, 1000, 700); // parent is maingui, will be freed at decon - list = new Fl_Multi_Browser(0, 50, 150, 700); - summaryEditor = new SummaryManager(150, 50, 850, 700); + list = new Fl_Multi_Browser(0, 50, 250, 700); + summaryEditor = new SummaryManager(250, 50, 750, 700); + topbar->inspect->callback(show_callback, this); tilebox->end(); @@ -219,54 +178,50 @@ struct MainGui : Fl_Window { resizable(tilebox); } + + + void updateList(std::string filename) { + s.entries = MakeEntires(filename); + for (auto e : s.entries) { + std::cout << e << std::endl; + } + + + for (size_t i = 0; i < s.entries.size(); i++) { + auto e = s.entries[i]; + auto h = ((e.A.year + "/" + e.A.name) + " and " + (e.B.year + "/" + e.B.name) + " (" + + std::to_string(e.Apercent) + "%, " + std::to_string(e.Bpercent) + "%)"); + list->add(h.c_str(), (void *) i); + } + } }; +void show_callback(Fl_Widget *w, void *data) { + MainGui *rdata = (MainGui *)data; + + auto s = rdata->list->size() + 1; + + for (size_t i = 0; i < s; i++) { + if (rdata->list->selected(i)) { + fl_alert("%s", rdata->list->text(i)); + auto c = ComplexEntry(rdata->s.entries[ (size_t) rdata->list->data(i)]); + rdata->summaryEditor->addComplex(c); + } + } +} + + + + int main(int argc, char **argv) { if (argc < 2) { std::cout << "Not enough args" << std::endl; exit(1); } - State s; - s.entries = MakeEntires(argv[1]); - - for (auto e : s.entries) { - std::cout << e << std::endl; - } + Fl::scheme("base"); - // auto window = std::make_unique(300, 300, 300, 300, "MossMan :D"); - - // auto group = std::make_unique(0,0,300,300); - // auto group2 = std::make_unique(0, 0, 300, 50); - // auto box = std::make_unique(0,0,100,50,"MossMan"); - // box->labelsize(36); - // box->labelfont(FL_TIMES | FL_BOLD); - // box->align(FL_ALIGN_INSIDE | FL_ALIGN_TOP_LEFT); - // auto button = std::make_unique(250, 0, 50, 50); - // auto button2 = std::make_unique(200,0, 50, 50); - // group2->resizable(*box); - // group2->end(); - - // auto group3 = std::make_unique(0,51,300, 250, Fl_Flex::HORIZONTAL); - // // auto browser = std::make_unique(0,51,300,250); - // // auto browser2 = std::make_unique(0,51,300,250); - // auto browser = std::make_unique(0,0,0,0); - // auto tabs = std::make_unique(0,0,300,300); - // //auto browser2 = std::make_unique(0,0,0,0); - // tabs->hide(); - // group3->end(); - // std::pair saved(*group3, *tabs); - // button2->callback(changelayout,&saved); - - // auto icon = std::make_unique("Inspect", icon_inspect_file_png, - // icon_inspect_file_png_len); button->image(*icon); button->tooltip("Inspect Entr(ies)"); - - // for (auto e : s.entries) { - // auto h = ((e.A.year + "/" + e.A.name) + " and " + (e.B.year + "/" + e.B.name) + " (" + - // std::to_string(e.Apercent) + "%, " + std::to_string(e.Bpercent) + "%)"); - // browser->add(h.c_str()); - // } // group->resizable(*group3); // group->end(); @@ -283,6 +238,7 @@ int main(int argc, char **argv) { // window->show(); MainGui x; + x.updateList(argv[1]); x.show(); return Fl::run(); diff --git a/src/summarymanager.cpp b/src/summarymanager.cpp index 6a4ae35..c094297 100644 --- a/src/summarymanager.cpp +++ b/src/summarymanager.cpp @@ -1,15 +1,39 @@ #include "summarymanager.hpp" +#include "custom_types.hpp" +#include #include #include +#include #include +#include +#include #include #include #include +#include + + +Fl_Text_Display::Style_Table_Entry table[] { + { FL_BLACK, FL_COURIER, FL_NORMAL_SIZE }, + { FL_RED, FL_COURIER, FL_NORMAL_SIZE }, +}; + + + +void SummaryCallback(Fl_Widget * w, void * data) { + auto sum = (Summary *) w; + if (Fl::callback_reason() == FL_REASON_CLOSED) { + std::cout << "CLOSED " << sum->title << std::endl; + } + Fl::delete_widget(w); + w->parent()->redraw(); +} + SummaryManager::SummaryManager(int x, int y, int w, int h) : Fl_Group(x, y, w, h), tabs(x, y, w, h) { - Fl_Group *grp1 = new Fl_Group(x, y + 30, w, h - 30, "Tab1"); + grp1->when(FL_WHEN_CLOSED); { Fl_Window *win1 = new Fl_Window(x, y + 30, w, h - 30, "Tab1W"); std::cout << "here" << std::endl; @@ -42,4 +66,44 @@ SummaryManager::SummaryManager(int x, int y, int w, int h) tabs.resizable(grp1); end(); + box(FL_FLAT_BOX); +} + +void style_unfinn_cb(int, void* a) {} + +Summary::Summary(ComplexEntry c, int x, int y, int w, int h) : Fl_Group(x, y, w, h, "Loading...") { + title = c.basic.A.name + "+" + c.basic.B.name + "(" + std::to_string(c.basic.Apercent) + "%," + std::to_string(c.basic.Bpercent) + "%)"; + this->label(title.c_str()); + this->when(FL_WHEN_CLOSED); + Fl_Window * win = new Fl_Window(x, y, w, h); + + Fl_Group * text_boxes = new Fl_Group(0,0,w,h); + + Fl_Text_Display * s1 = new Fl_Text_Display(0, 0, w/2, h); + Fl_Text_Buffer * s1buff = new Fl_Text_Buffer(); + Fl_Text_Buffer * s1style_buff = new Fl_Text_Buffer(); + s1style_buff->insert(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); + s1->highlight_data(s1style_buff, table , 2, 'A', style_unfinn_cb, 0); + s1->buffer(s1buff); + std::cout << c.A_buf.c_str() << std::endl; + s1->insert(c.A_buf.c_str()); + Fl_Text_Display * s2 = new Fl_Text_Display(w/2, 0, w/2, h); + Fl_Text_Buffer * s2buff = new Fl_Text_Buffer(); + s2->buffer(s2buff); + s2->buffer()->insert(0, c.B_buf.c_str()); + text_boxes->end(); + win->end(); + this->end(); + this->resizable(win); + win->resizable(text_boxes); + + this->callback(SummaryCallback); + +} + + +void SummaryManager::addComplex(ComplexEntry& c) { + tabs.add(new Summary(c, this->x(), this->y() +30, this->w(), this->h() - 30)); + + } diff --git a/src/summarymanager.hpp b/src/summarymanager.hpp index c0672d4..91a22f7 100644 --- a/src/summarymanager.hpp +++ b/src/summarymanager.hpp @@ -1,17 +1,32 @@ #ifndef SUMMARYMANAGER_HEADER #define SUMMARYMANAGER_HEADER +#include "custom_types.hpp" +#include +#include #include #include #include +#include +#include + #include #include +void SummaryCallback(Fl_Widget * w, void * data); + +struct Summary : Fl_Group { + std::string title; + Summary(ComplexEntry c, int x, int y, int w, int h); +}; + struct SummaryManager : Fl_Group { SummaryManager(int x, int y, int w, int h); Fl_Tabs tabs; - std::vector items; + std::vector items; + + void addComplex(ComplexEntry& c); };