From 51968d1f87d2a385b72576869d97157608764c54 Mon Sep 17 00:00:00 2001 From: Inventor Xtreme Date: Mon, 13 Apr 2026 22:57:53 -0400 Subject: [PATCH 1/2] before stack --- Makefile | 10 +- src/curlwrap.cpp | 44 ---- src/curlwrap.hpp | 21 -- src/images.cpp | 67 ----- src/images.h | 11 - src/main.cpp | 570 +++++++++++++++++++++++------------------ src/summarymanager.cpp | 45 ---- src/summarymanager.hpp | 18 -- 8 files changed, 328 insertions(+), 458 deletions(-) delete mode 100644 src/curlwrap.cpp delete mode 100644 src/curlwrap.hpp delete mode 100644 src/images.cpp delete mode 100644 src/images.h delete mode 100644 src/summarymanager.cpp delete mode 100644 src/summarymanager.hpp diff --git a/Makefile b/Makefile index 49715ae..aef1076 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ CC = gcc CXX = g++ -CPPFLAGS = -g #-O3 -ffast-math -CFLAGS = -g #-O3 -ffast-math -LDFLAGS = -g #-O3 -ffast-math -LDLIBS = -lfltk -lcurl -lfltk_images +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 = SRC_DIR = src @@ -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 deleted file mode 100644 index 3a4f615..0000000 --- a/src/curlwrap.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include "curlwrap.hpp" - -#include -#include -#include - - -size_t writeback(char * ptr, size_t size, size_t nmemb, void * data) { - std::string* us = (std::string*) data; - - us->append(ptr, nmemb); - - return nmemb; -} - - -Curl::Curl() { - handle = curl_easy_init(); -} - -Curl::~Curl() { - if (handle) { - curl_easy_cleanup(handle); - } -} - -void Curl::seturl(std::string url) { - data = ""; - curl_easy_setopt(handle, CURLOPT_URL, url.c_str()); - curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writeback); - curl_easy_setopt(handle, CURLOPT_WRITEDATA, &data); -} - -std::string Curl::get() { - curl_easy_perform(handle); - return data; -} - - - - - - diff --git a/src/curlwrap.hpp b/src/curlwrap.hpp deleted file mode 100644 index 1522c43..0000000 --- a/src/curlwrap.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef CURLWRAP_HEADER -#define CURLWRAP_HEADER - - -#include -#include - - -struct Curl { - CURL * handle; - std::string data; - Curl(); - ~Curl(); - - void seturl(std::string url); - - std::string get(); - -}; - -#endif diff --git a/src/images.cpp b/src/images.cpp deleted file mode 100644 index c6b2418..0000000 --- a/src/images.cpp +++ /dev/null @@ -1,67 +0,0 @@ -unsigned char icon_inspect_file_png[] = { - 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, - 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, - 0x08, 0x03, 0x00, 0x00, 0x00, 0x60, 0xdc, 0x09, 0xb5, 0x00, 0x00, 0x00, - 0x04, 0x67, 0x41, 0x4d, 0x41, 0x00, 0x00, 0xb1, 0x8f, 0x0b, 0xfc, 0x61, - 0x05, 0x00, 0x00, 0x00, 0x20, 0x63, 0x48, 0x52, 0x4d, 0x00, 0x00, 0x7a, - 0x26, 0x00, 0x00, 0x80, 0x84, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 0x80, - 0xe8, 0x00, 0x00, 0x75, 0x30, 0x00, 0x00, 0xea, 0x60, 0x00, 0x00, 0x3a, - 0x98, 0x00, 0x00, 0x17, 0x70, 0x9c, 0xba, 0x51, 0x3c, 0x00, 0x00, 0x00, - 0x75, 0x50, 0x4c, 0x54, 0x45, 0x00, 0x00, 0x00, 0x77, 0x77, 0x77, 0x86, - 0x86, 0x86, 0xff, 0xfb, 0xf0, 0x99, 0x99, 0x99, 0x55, 0x55, 0x55, 0xea, - 0xea, 0xea, 0xcc, 0xcc, 0xcc, 0xd7, 0xd7, 0xd7, 0xe7, 0xe7, 0xd6, 0x99, - 0xcc, 0xff, 0x99, 0x99, 0xcc, 0x5f, 0x5f, 0x5f, 0x99, 0xff, 0xff, 0xc0, - 0xc0, 0xc0, 0xcc, 0xff, 0xff, 0xcc, 0xff, 0xcc, 0x66, 0xff, 0xff, 0x33, - 0xff, 0xff, 0x4d, 0x4d, 0x4d, 0x33, 0x33, 0x33, 0xcc, 0xec, 0xff, 0x00, - 0xff, 0xff, 0x11, 0x11, 0x11, 0x66, 0x66, 0x66, 0x1c, 0x1c, 0x1c, 0x22, - 0x22, 0x22, 0xb2, 0xb2, 0xb2, 0x00, 0x66, 0xff, 0x00, 0x33, 0x99, 0x00, - 0xcc, 0xff, 0x00, 0x99, 0xff, 0x00, 0x66, 0x99, 0x00, 0x33, 0xcc, 0x00, - 0x00, 0x80, 0x00, 0x00, 0x66, 0x00, 0x00, 0xff, 0x00, 0x33, 0x66, 0xff, - 0xff, 0xff, 0x1d, 0x20, 0xae, 0x06, 0x00, 0x00, 0x00, 0x01, 0x74, 0x52, - 0x4e, 0x53, 0x00, 0x40, 0xe6, 0xd8, 0x66, 0x00, 0x00, 0x00, 0x01, 0x62, - 0x4b, 0x47, 0x44, 0x26, 0x5a, 0x08, 0x98, 0xb5, 0x00, 0x00, 0x00, 0x07, - 0x74, 0x49, 0x4d, 0x45, 0x07, 0xe2, 0x06, 0x1a, 0x00, 0x32, 0x12, 0x39, - 0x75, 0x77, 0x4b, 0x00, 0x00, 0x01, 0x74, 0x49, 0x44, 0x41, 0x54, 0x48, - 0xc7, 0xed, 0xd4, 0xcb, 0x56, 0x83, 0x30, 0x14, 0x05, 0xd0, 0x86, 0xbc, - 0x9a, 0x94, 0x90, 0x04, 0x0a, 0x56, 0x05, 0x5b, 0xad, 0xfe, 0xff, 0x2f, - 0x7a, 0x6f, 0x12, 0xa4, 0xba, 0xc2, 0xa3, 0x13, 0x97, 0x03, 0xcf, 0xa4, - 0x0c, 0xd8, 0xdc, 0x93, 0x90, 0xb2, 0xdb, 0xfd, 0xe7, 0x4f, 0x86, 0x14, - 0x3f, 0xb2, 0x0a, 0xe8, 0xf7, 0x30, 0x7e, 0x2f, 0x58, 0x13, 0x44, 0x40, - 0x6e, 0x81, 0x5c, 0x12, 0x24, 0x66, 0x2f, 0xd4, 0x04, 0xd4, 0xbc, 0x20, - 0x44, 0x63, 0x0e, 0x84, 0x97, 0xfb, 0xaf, 0x29, 0x8c, 0xce, 0x0a, 0xa2, - 0x4d, 0xa5, 0xac, 0x71, 0xd6, 0xeb, 0xb2, 0x94, 0xe3, 0x10, 0x46, 0xe7, - 0x04, 0xd1, 0xd6, 0x02, 0xb0, 0x35, 0x44, 0x97, 0x5c, 0x4a, 0xa5, 0xd0, - 0xf0, 0xe6, 0x88, 0xc9, 0x01, 0xab, 0x00, 0x38, 0xcb, 0x30, 0x30, 0x83, - 0xc3, 0x0f, 0x00, 0x21, 0x2b, 0xc6, 0x08, 0xcf, 0x0f, 0xa0, 0x38, 0xc1, - 0x8a, 0xd6, 0xfb, 0x4e, 0x97, 0x4c, 0xc6, 0x75, 0x04, 0x91, 0x03, 0x86, - 0x0a, 0x04, 0xae, 0x0e, 0xd1, 0x1c, 0x40, 0x5c, 0x05, 0x8a, 0x3c, 0xa0, - 0x61, 0x42, 0xa8, 0xc4, 0x24, 0x4c, 0x50, 0x31, 0x28, 0xf2, 0x00, 0x2b, - 0x39, 0x6b, 0x5b, 0x67, 0x3c, 0x6c, 0x14, 0x67, 0x29, 0x38, 0x23, 0x0b, - 0x84, 0x15, 0xe3, 0x2e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 0x09, 0x81, 0xc5, 0x1c, 0x78, 0xc0, - 0x82, 0x16, 0xc0, 0x00, 0x00, 0x00, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64, - 0x61, 0x74, 0x65, 0x3a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x00, 0x32, - 0x30, 0x31, 0x38, 0x2d, 0x30, 0x36, 0x2d, 0x32, 0x36, 0x54, 0x30, 0x30, - 0x3a, 0x35, 0x30, 0x3a, 0x31, 0x38, 0x2d, 0x30, 0x34, 0x3a, 0x30, 0x30, - 0x0e, 0x62, 0x1d, 0x0e, 0x00, 0x00, 0x00, 0x25, 0x74, 0x45, 0x58, 0x74, - 0x64, 0x61, 0x74, 0x65, 0x3a, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x00, - 0x32, 0x30, 0x31, 0x38, 0x2d, 0x30, 0x36, 0x2d, 0x32, 0x36, 0x54, 0x30, - 0x30, 0x3a, 0x35, 0x30, 0x3a, 0x31, 0x38, 0x2d, 0x30, 0x34, 0x3a, 0x30, - 0x30, 0x7f, 0x3f, 0xa5, 0xb2, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, - 0x44, 0xae, 0x42, 0x60, 0x82 -}; -unsigned int icon_inspect_file_png_len = 761; diff --git a/src/images.h b/src/images.h deleted file mode 100644 index 5e52cd1..0000000 --- a/src/images.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef IMAGES_H -#define IMAGES_H - -#include - -extern unsigned char icon_inspect_file_png[]; -extern size_t icon_inspect_file_png_len; - - - -#endif diff --git a/src/main.cpp b/src/main.cpp index 6c22e51..d39e306 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,289 +1,365 @@ -#include -#include -#include -#include +#include #include - -#include "curlwrap.hpp" -#include "images.h" -#include "summarymanager.hpp" -#include "testcpp.hpp" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include +#include +#include +#include #include -using namespace std; +struct Data { + virtual ~Data() {} +}; -struct Person { - std::string year; - std::string name; +struct SelfEval : Data { + virtual ~SelfEval() {} +}; - Person(std::string &y, std::string &n) : year(y), name(n) {} - std::string toString() const { - return "{(Person): " + year + ", " + name + "}"; +struct Applyable : Data { + virtual ~Applyable() {} +}; + +struct Cell { + Data *d; + size_t cdr = 0; +}; + +struct Env { + std::unordered_set builtin; + std::unordered_map userdef; +}; + +struct Symbol : Data{ + std::string data; + std::string Get() { + return data; } }; -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) + "%}"; +struct String : SelfEval { + std::string data; + std::string Get() { + return data; } }; -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) {} +struct Number : SelfEval { + int data; + int Get() { + return data; + } }; -void show_callback(Fl_Widget *w, void *data) { - Selected *rdata = (Selected *)data; +struct Fork : Data { + size_t data; + size_t Get() { + return data; + } +}; - auto s = rdata->browser.size() + 1; +struct Lambda : Data { + Env env; + Cell args; + Cell f; +}; - for (size_t i = 0; i < s; i++) { - if (rdata->browser.selected(i)) { - fl_alert("%s", rdata->browser.text(i)); +struct Registers { + std::variant A; + std::variant B; + std::variant C; + Env E; +}; + +struct Machine { + size_t maxCells; + size_t freepos = 1; + std::vector mem; + + std::vector stack; + + Registers reg; + + Machine(size_t max) : mem(max) { + maxCells = max; + reg.E.builtin.insert("+"); + reg.E.builtin.insert("-"); + reg.E.builtin.insert("lambda"); + reg.E.builtin.insert("set"); + } + + size_t Apply(Data * d, size_t cdr) { + if (Symbol * fname = dynamic_cast(d)) { + if (reg.E.builtin.contains(fname->data)) { + return ApplyBuiltin(fname->data, cdr); + } else { //defined symbol. + return 0; //TODO + } + + } else if (Lambda * f = dynamic_cast(d)) { + reg.A = f->args; + reg.A = ((Fork *) (std::get(reg.A)).d)->data; + + reg.B = cdr; + auto tmp = reg.E; + //reg.E = f->env; + reg.E.userdef.merge(f->env.userdef); + while (std::get(reg.A) != 0) { + reg.E.userdef[ ((Symbol *) mem[std::get(reg.A)].d )->data] = std::get(reg.B); + reg.A = mem[std::get(reg.A)].cdr; + reg.B = mem[std::get(reg.B)].cdr; + } + + auto ret = Eval(f->f.d); + reg.E = tmp; + return newCell(ret); + + } else { + return 0; + } + } + + + size_t ApplyBuiltin(std::string fname, size_t cdr) { + if (fname == "+") { + int base = 0; + while (cdr != 0) { + Number *a = dynamic_cast(mem[cdr].d); + base += a->data; + cdr = mem[cdr].cdr; + } + Number *n = new Number; + n->data = base; + return newCell(n); + + } else if (fname == "-") { + Number *s = dynamic_cast(mem[cdr].d); + int base = s->data; + + cdr = mem[cdr].cdr; + if (cdr == 0) { + Number *n = new Number; + n->data = -base; + return newCell(n); + } else { + while (cdr != 0) { + Number *a = dynamic_cast(mem[cdr].d); + base -= a->data; + cdr = mem[cdr].cdr; + } + Number *n = new Number; + n->data = base; + return newCell(n); + } + } else if (fname == "lambda") { + Fork * args = dynamic_cast(mem[cdr].d); + Fork * f = dynamic_cast(mem[mem[cdr].cdr].d); + + Lambda * l = new Lambda; + l->env = reg.E; + l->args = mem[cdr]; //mem[args->data]; + l->f = mem[mem[cdr].cdr]; //mem[f->data]; + //std::cout <<"got lambd" << std::endl; + return newCell(l); + + } + return 0; + } + + size_t newCell() { + if (freepos >= maxCells) { + exit(1); + } + auto nc = freepos; + freepos += 1; + return nc; + } + + size_t newCell(Data *d) { + auto t = newCell(); + mem[t].d = d; + return t; + } + + Data *Eval(Data *d) { + // std::cout << "Eval top" << std::endl; + if (SelfEval *h = dynamic_cast(d)) { + return h; + } else if (Symbol *h = dynamic_cast(d)) { + if (reg.E.builtin.contains(h->data)) return h; + return mem[reg.E.userdef[h->data]].d; + } else if (Fork *h = dynamic_cast(d)) { + // std::cout << "Eval callllled" << std::endl; + // Symbol *car = dynamic_cast(mem[h->data].d); + //new car: + auto car = mem[h->data].d; + + // if (!car) { + // throw(100); + // } + size_t front = 0; + size_t current = 0; + size_t firstargleft = mem[h->data].cdr; + + // std::cout << "Farg " << firstargleft << std::endl; + + while (firstargleft != 0) { + if (auto c = dynamic_cast(car)) { + if(c->data == "lambda") { + front = mem[h->data].cdr; + break; + } + } + + if (front == 0) { + front = newCell(); + current = front; + } else { + auto temp = newCell(); + mem[current].cdr = temp; + current = temp; + } + + // std::cout << "here" << std::endl; + mem[current].d = Eval(mem[firstargleft].d); + + // std::cout << "there" << std::endl; + firstargleft = mem[firstargleft].cdr; + } + + return mem[Apply(Eval(car), front)].d; + } else { + throw("err"); + } + return NULL; + } + + void ListPrint(Cell c) { + while (true) { + if (typeid(*(c.d)) == typeid(Number)) { + auto p = dynamic_cast(c.d); + std::cout << p->Get() << " "; + } else if (typeid(*(c.d)) == typeid(Symbol)) { + auto p = dynamic_cast(c.d); + std::cout << p->Get() << " "; + } else if (typeid(*(c.d)) == typeid(String)) { + auto p = dynamic_cast(c.d); + std::cout << "@\"" << p->Get() << "\"@ "; + } else if (typeid(*(c.d)) == typeid(Fork)) { + std::cout << "("; + auto p = dynamic_cast(c.d); + ListPrint(mem[p->Get()]); + std::cout << ")"; + } + if (c.cdr == 0) + break; + c = mem[c.cdr]; } } -} -std::vector MakeEntires(std::string filename) { + Cell read_atom(std::istream &in) { + bool isnum = true; - std::vector out; + std::string pass = ""; + char ch; - std::ifstream matches(filename); + if (in.peek() == '"') { + in.get(ch); + while (true) { + in.get(ch); + if (ch == '\\') { + in.get(ch); + pass += ch; + } else if (ch == '"') { + break; + } else { + pass += ch; + } + } + Cell c; + c.cdr = 0; + auto n = new String; + n->data = pass; + c.d = n; + return c; + } - if (!matches.is_open()) { - std::cout << "Err reading " << filename << std::endl; - exit(1); + while (in.get(ch) && ch != '(' && ch != ' ' && ch != ')') { + if (ch != '0' && ch != '1' && ch != '2' && ch != '3' && ch != '4' && ch != '5' && + ch != '6' && ch != '7' && ch != '8' && ch != '9') { + isnum = false; + } + pass += ch; + } + in.unget(); + + Cell c; + c.cdr = 0; + if (isnum) { + auto n = new Number; + n->data = std::stoi(pass); + c.d = n; + } else { + auto s = new Symbol; + s->data = pass; + c.d = s; + } + + return c; } - std::string line; + size_t read_expr(std::istream &in) { + size_t front = 0; + size_t current = 0; - std::string line1; - std::string line2; + char ch; + while (in.get(ch)) { + if (!std::isspace(ch)) { + if (ch == '(') { + auto temp = newCell(); + mem[current].cdr = temp; + current = temp; + if (front == 0) { + front = current; + } + auto x = new Fork; + mem[current].d = x; + x->data = read_expr(in); - size_t linenum = 1; // One indexed like devtools - while (std::getline(matches, line)) { - if (linenum < 15) { - - } else { - if ((linenum - 15) % 3 == 0) { - line1 = line; - if (line == "" || line == "") + } else if (ch == ')') { break; - } else if ((linenum - 15) % 3 == 1) { - line2 = line; + } else { + auto temp = newCell(); + mem[current].cdr = temp; + current = temp; + if (front == 0) { + front = current; + } - // std::cout << "Debug: L1: " << line1 << std::endl; - // std::cout << "Debug: L2: " << line2 << std::endl; + in.unget(); - auto firstquote = line1.find("\""); - // printf("fq: %ld\n", firstquote); - auto secondquote = line1.find("\"", firstquote + 1); - // printf("sq: %ld\n", secondquote); - auto matchlink = line1.substr(firstquote + 1, secondquote - (firstquote + 1)); - - auto firstslash = line1.find("/", secondquote + 1); - auto secondslash = line1.find("/", firstslash + 1); - auto thirdslash = line1.find("/", secondslash + 1); - - auto firstpar = line1.find("(", thirdslash + 1); - auto secondpar = line1.find(")", firstpar + 1); - - auto p1class = line1.substr(firstslash + 1, secondslash - firstslash - 1); - auto p1name = line1.substr(secondslash + 1, thirdslash - secondslash - 1); - - auto p1match = line1.substr(firstpar + 1, secondpar - firstpar - 2); - - std::cout << p1match << std::endl; - - firstquote = line2.find("\""); - secondquote = line2.find("\"", firstquote + 1); - firstslash = line2.find("/", secondquote + 1); - secondslash = line2.find("/", firstslash + 1); - thirdslash = line2.find("/", secondslash + 1); - firstpar = line2.find("(", thirdslash + 1); - secondpar = line2.find(")", firstpar + 1); - - auto p2class = line2.substr(firstslash + 1, secondslash - (firstslash + 1)); - auto p2name = line2.substr(secondslash + 1, thirdslash - (secondslash + 1)); - - auto p2match = line2.substr(firstpar + 1, secondpar - firstpar - 2); - std::cout << p2match << std::endl; - - auto p1 = Person(p1class, p1name); - - auto p2 = Person(p2class, p2name); - - BasicEntry finent = {.A = p1, - .B = p2, - .matchlink = matchlink, - .Apercent = std::stoi(p1match), - .Bpercent = std::stoi(p2match)}; - - out.push_back(finent); + mem[current] = read_atom(in); + } } } - linenum++; - } - return out; -} -struct State { - std::vector entries; -}; - -void changelayout(Fl_Widget *w, void *meow) { - std::pair *in = (std::pair *)meow; - in->second.show(); - // in->second.parent()->redraw(); - // in->first.window()->redraw(); - // in->first.init_sizes(); - in->first.layout(); - in->second.redraw(); - // in->first.redraw(); -} - -struct Topbar : Fl_Group { - - Fl_PNG_Image inspectIcon; - - Fl_Box *titleText; - Fl_Button *inspect; - - Topbar(int x, int y, int w, int h) - : Fl_Group(x, y, w, h), - inspectIcon("Inspect", icon_inspect_file_png, icon_inspect_file_png_len) { - - titleText = new Fl_Box(0, 0, 100, 50, "MossMan"); - titleText->labelsize(36); - titleText->labelfont(FL_TIMES | FL_BOLD); - titleText->align(FL_ALIGN_INSIDE | FL_ALIGN_TOP_LEFT); - inspect = new Fl_Button(950, 0, 50, 50); - resizable(titleText); - - inspect->image(inspectIcon); - inspect->tooltip("Inspect Entr(ies)"); - - end(); + return front; } }; -struct MainGui : Fl_Window { - Topbar *topbar; +int main() { + auto m = Machine(1000); - Fl_Tile *tilebox; - Fl_Multi_Browser *list; - SummaryManager *summaryEditor; - MainGui() : Fl_Window(0, 0, 1000, 750, "MossMan :3") { - topbar = new Topbar(0, 0, 1000, 50); + auto exp = m.read_expr(std::cin); - 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); + m.ListPrint(m.mem[exp]); + std::cout << std::endl; - tilebox->end(); + Cell c; + c.d = m.Eval(m.mem[exp].d); - end(); + m.ListPrint(c); + std::cout << std::endl; - resizable(tilebox); - } -}; -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(); - - // window->resizable(*group); - // window->end(); - - // MainGui x; - - // Selected callbackdata(*browser); - - // button->callback(show_callback, (void*) &callbackdata); - - // window->show(); - - MainGui x; - x.show(); - - return Fl::run(); + return 0; } diff --git a/src/summarymanager.cpp b/src/summarymanager.cpp deleted file mode 100644 index 6a4ae35..0000000 --- a/src/summarymanager.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "summarymanager.hpp" -#include -#include -#include -#include -#include -#include - -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"); - { - Fl_Window *win1 = new Fl_Window(x, y + 30, w, h - 30, "Tab1W"); - std::cout << "here" << std::endl; - { - auto butt = new Fl_Button(0, 0, 100, 200, "test"); - } - win1->end(); - auto butt = new Fl_Button(0, 30, 100, 200, "nyaaa"); - } - grp1->end(); - // Fl_Group *grp2 = new Fl_Group(20, 30, 280, 170, "Tab2"); - // { - // } - // grp2->end(); - // Fl_Group *grp3 = new Fl_Group(20, 30, 280, 170, "Tab3"); - // { - // } - // grp3->end(); - // Fl_Group *grp4 = new Fl_Group(20, 30, 280, 170, "Tab4"); - // { - // } - // grp4->end(); - // Fl_Group *grp5 = new Fl_Group(20, 30, 280, 170, "Tab5"); - // { - // } - // grp5->end(); - tabs.end(); - tabs.handle_overflow(Fl_Tabs::OVERFLOW_DRAG); - - tabs.resizable(grp1); - - end(); -} diff --git a/src/summarymanager.hpp b/src/summarymanager.hpp deleted file mode 100644 index c0672d4..0000000 --- a/src/summarymanager.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef SUMMARYMANAGER_HEADER -#define SUMMARYMANAGER_HEADER - -#include -#include -#include -#include -#include - - -struct SummaryManager : Fl_Group { - SummaryManager(int x, int y, int w, int h); - Fl_Tabs tabs; - std::vector items; - -}; - -#endif From 41930a28e0dfdc78d05a6421371028ed6a937921 Mon Sep 17 00:00:00 2001 From: InventorX Date: Mon, 13 Apr 2026 22:59:49 -0400 Subject: [PATCH 2/2] revert 51968d1f87d2a385b72576869d97157608764c54 revert before stack --- Makefile | 10 +- src/curlwrap.cpp | 44 +++ src/curlwrap.hpp | 21 ++ src/images.cpp | 67 +++++ src/images.h | 11 + src/main.cpp | 634 ++++++++++++++++++----------------------- src/summarymanager.cpp | 45 +++ src/summarymanager.hpp | 18 ++ 8 files changed, 490 insertions(+), 360 deletions(-) create mode 100644 src/curlwrap.cpp create mode 100644 src/curlwrap.hpp create mode 100644 src/images.cpp create mode 100644 src/images.h create mode 100644 src/summarymanager.cpp create mode 100644 src/summarymanager.hpp diff --git a/Makefile b/Makefile index aef1076..49715ae 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ CC = gcc CXX = g++ -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 = +CPPFLAGS = -g #-O3 -ffast-math +CFLAGS = -g #-O3 -ffast-math +LDFLAGS = -g #-O3 -ffast-math +LDLIBS = -lfltk -lcurl -lfltk_images SRC_DIR = src @@ -33,7 +33,7 @@ $(EXE): $(OBJ) | $(BIN_DIR) $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR) - $(CC) $(CFLAGS) -c $< -o $@ + $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR) diff --git a/src/curlwrap.cpp b/src/curlwrap.cpp new file mode 100644 index 0000000..3a4f615 --- /dev/null +++ b/src/curlwrap.cpp @@ -0,0 +1,44 @@ +#include +#include "curlwrap.hpp" + +#include +#include +#include + + +size_t writeback(char * ptr, size_t size, size_t nmemb, void * data) { + std::string* us = (std::string*) data; + + us->append(ptr, nmemb); + + return nmemb; +} + + +Curl::Curl() { + handle = curl_easy_init(); +} + +Curl::~Curl() { + if (handle) { + curl_easy_cleanup(handle); + } +} + +void Curl::seturl(std::string url) { + data = ""; + curl_easy_setopt(handle, CURLOPT_URL, url.c_str()); + curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writeback); + curl_easy_setopt(handle, CURLOPT_WRITEDATA, &data); +} + +std::string Curl::get() { + curl_easy_perform(handle); + return data; +} + + + + + + diff --git a/src/curlwrap.hpp b/src/curlwrap.hpp new file mode 100644 index 0000000..1522c43 --- /dev/null +++ b/src/curlwrap.hpp @@ -0,0 +1,21 @@ +#ifndef CURLWRAP_HEADER +#define CURLWRAP_HEADER + + +#include +#include + + +struct Curl { + CURL * handle; + std::string data; + Curl(); + ~Curl(); + + void seturl(std::string url); + + std::string get(); + +}; + +#endif diff --git a/src/images.cpp b/src/images.cpp new file mode 100644 index 0000000..c6b2418 --- /dev/null +++ b/src/images.cpp @@ -0,0 +1,67 @@ +unsigned char icon_inspect_file_png[] = { + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, + 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, + 0x08, 0x03, 0x00, 0x00, 0x00, 0x60, 0xdc, 0x09, 0xb5, 0x00, 0x00, 0x00, + 0x04, 0x67, 0x41, 0x4d, 0x41, 0x00, 0x00, 0xb1, 0x8f, 0x0b, 0xfc, 0x61, + 0x05, 0x00, 0x00, 0x00, 0x20, 0x63, 0x48, 0x52, 0x4d, 0x00, 0x00, 0x7a, + 0x26, 0x00, 0x00, 0x80, 0x84, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 0x80, + 0xe8, 0x00, 0x00, 0x75, 0x30, 0x00, 0x00, 0xea, 0x60, 0x00, 0x00, 0x3a, + 0x98, 0x00, 0x00, 0x17, 0x70, 0x9c, 0xba, 0x51, 0x3c, 0x00, 0x00, 0x00, + 0x75, 0x50, 0x4c, 0x54, 0x45, 0x00, 0x00, 0x00, 0x77, 0x77, 0x77, 0x86, + 0x86, 0x86, 0xff, 0xfb, 0xf0, 0x99, 0x99, 0x99, 0x55, 0x55, 0x55, 0xea, + 0xea, 0xea, 0xcc, 0xcc, 0xcc, 0xd7, 0xd7, 0xd7, 0xe7, 0xe7, 0xd6, 0x99, + 0xcc, 0xff, 0x99, 0x99, 0xcc, 0x5f, 0x5f, 0x5f, 0x99, 0xff, 0xff, 0xc0, + 0xc0, 0xc0, 0xcc, 0xff, 0xff, 0xcc, 0xff, 0xcc, 0x66, 0xff, 0xff, 0x33, + 0xff, 0xff, 0x4d, 0x4d, 0x4d, 0x33, 0x33, 0x33, 0xcc, 0xec, 0xff, 0x00, + 0xff, 0xff, 0x11, 0x11, 0x11, 0x66, 0x66, 0x66, 0x1c, 0x1c, 0x1c, 0x22, + 0x22, 0x22, 0xb2, 0xb2, 0xb2, 0x00, 0x66, 0xff, 0x00, 0x33, 0x99, 0x00, + 0xcc, 0xff, 0x00, 0x99, 0xff, 0x00, 0x66, 0x99, 0x00, 0x33, 0xcc, 0x00, + 0x00, 0x80, 0x00, 0x00, 0x66, 0x00, 0x00, 0xff, 0x00, 0x33, 0x66, 0xff, + 0xff, 0xff, 0x1d, 0x20, 0xae, 0x06, 0x00, 0x00, 0x00, 0x01, 0x74, 0x52, + 0x4e, 0x53, 0x00, 0x40, 0xe6, 0xd8, 0x66, 0x00, 0x00, 0x00, 0x01, 0x62, + 0x4b, 0x47, 0x44, 0x26, 0x5a, 0x08, 0x98, 0xb5, 0x00, 0x00, 0x00, 0x07, + 0x74, 0x49, 0x4d, 0x45, 0x07, 0xe2, 0x06, 0x1a, 0x00, 0x32, 0x12, 0x39, + 0x75, 0x77, 0x4b, 0x00, 0x00, 0x01, 0x74, 0x49, 0x44, 0x41, 0x54, 0x48, + 0xc7, 0xed, 0xd4, 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xc5, 0x1c, 0x78, 0xc0, + 0x82, 0x16, 0xc0, 0x00, 0x00, 0x00, 0x25, 0x74, 0x45, 0x58, 0x74, 0x64, + 0x61, 0x74, 0x65, 0x3a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x00, 0x32, + 0x30, 0x31, 0x38, 0x2d, 0x30, 0x36, 0x2d, 0x32, 0x36, 0x54, 0x30, 0x30, + 0x3a, 0x35, 0x30, 0x3a, 0x31, 0x38, 0x2d, 0x30, 0x34, 0x3a, 0x30, 0x30, + 0x0e, 0x62, 0x1d, 0x0e, 0x00, 0x00, 0x00, 0x25, 0x74, 0x45, 0x58, 0x74, + 0x64, 0x61, 0x74, 0x65, 0x3a, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x00, + 0x32, 0x30, 0x31, 0x38, 0x2d, 0x30, 0x36, 0x2d, 0x32, 0x36, 0x54, 0x30, + 0x30, 0x3a, 0x35, 0x30, 0x3a, 0x31, 0x38, 0x2d, 0x30, 0x34, 0x3a, 0x30, + 0x30, 0x7f, 0x3f, 0xa5, 0xb2, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, + 0x44, 0xae, 0x42, 0x60, 0x82 +}; +unsigned int icon_inspect_file_png_len = 761; diff --git a/src/images.h b/src/images.h new file mode 100644 index 0000000..5e52cd1 --- /dev/null +++ b/src/images.h @@ -0,0 +1,11 @@ +#ifndef IMAGES_H +#define IMAGES_H + +#include + +extern unsigned char icon_inspect_file_png[]; +extern size_t icon_inspect_file_png_len; + + + +#endif diff --git a/src/main.cpp b/src/main.cpp index d39e306..6c22e51 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,365 +1,289 @@ -#include +#include +#include +#include +#include #include -#include + +#include "curlwrap.hpp" +#include "images.h" +#include "summarymanager.hpp" +#include "testcpp.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include #include -struct Data { - virtual ~Data() {} -}; +using namespace std; -struct SelfEval : Data { - virtual ~SelfEval() {} -}; +struct Person { + std::string year; + std::string name; -struct Applyable : Data { - virtual ~Applyable() {} -}; - -struct Cell { - Data *d; - size_t cdr = 0; -}; - -struct Env { - std::unordered_set builtin; - std::unordered_map userdef; -}; - -struct Symbol : Data{ - std::string data; - std::string Get() { - return data; + Person(std::string &y, std::string &n) : year(y), name(n) {} + std::string toString() const { + return "{(Person): " + year + ", " + name + "}"; } }; -struct String : SelfEval { - std::string data; - std::string Get() { - return data; - } -}; - -struct Number : SelfEval { - int data; - int Get() { - return data; - } -}; - -struct Fork : Data { - size_t data; - size_t Get() { - return data; - } -}; - -struct Lambda : Data { - Env env; - Cell args; - Cell f; -}; - -struct Registers { - std::variant A; - std::variant B; - std::variant C; - Env E; -}; - -struct Machine { - size_t maxCells; - size_t freepos = 1; - std::vector mem; - - std::vector stack; - - Registers reg; - - Machine(size_t max) : mem(max) { - maxCells = max; - reg.E.builtin.insert("+"); - reg.E.builtin.insert("-"); - reg.E.builtin.insert("lambda"); - reg.E.builtin.insert("set"); - } - - size_t Apply(Data * d, size_t cdr) { - if (Symbol * fname = dynamic_cast(d)) { - if (reg.E.builtin.contains(fname->data)) { - return ApplyBuiltin(fname->data, cdr); - } else { //defined symbol. - return 0; //TODO - } - - } else if (Lambda * f = dynamic_cast(d)) { - reg.A = f->args; - reg.A = ((Fork *) (std::get(reg.A)).d)->data; - - reg.B = cdr; - auto tmp = reg.E; - //reg.E = f->env; - reg.E.userdef.merge(f->env.userdef); - while (std::get(reg.A) != 0) { - reg.E.userdef[ ((Symbol *) mem[std::get(reg.A)].d )->data] = std::get(reg.B); - reg.A = mem[std::get(reg.A)].cdr; - reg.B = mem[std::get(reg.B)].cdr; - } - - auto ret = Eval(f->f.d); - reg.E = tmp; - return newCell(ret); - - } else { - return 0; - } - } - - - size_t ApplyBuiltin(std::string fname, size_t cdr) { - if (fname == "+") { - int base = 0; - while (cdr != 0) { - Number *a = dynamic_cast(mem[cdr].d); - base += a->data; - cdr = mem[cdr].cdr; - } - Number *n = new Number; - n->data = base; - return newCell(n); - - } else if (fname == "-") { - Number *s = dynamic_cast(mem[cdr].d); - int base = s->data; - - cdr = mem[cdr].cdr; - if (cdr == 0) { - Number *n = new Number; - n->data = -base; - return newCell(n); - } else { - while (cdr != 0) { - Number *a = dynamic_cast(mem[cdr].d); - base -= a->data; - cdr = mem[cdr].cdr; - } - Number *n = new Number; - n->data = base; - return newCell(n); - } - } else if (fname == "lambda") { - Fork * args = dynamic_cast(mem[cdr].d); - Fork * f = dynamic_cast(mem[mem[cdr].cdr].d); - - Lambda * l = new Lambda; - l->env = reg.E; - l->args = mem[cdr]; //mem[args->data]; - l->f = mem[mem[cdr].cdr]; //mem[f->data]; - //std::cout <<"got lambd" << std::endl; - return newCell(l); - - } - return 0; - } - - size_t newCell() { - if (freepos >= maxCells) { - exit(1); - } - auto nc = freepos; - freepos += 1; - return nc; - } - - size_t newCell(Data *d) { - auto t = newCell(); - mem[t].d = d; - return t; - } - - Data *Eval(Data *d) { - // std::cout << "Eval top" << std::endl; - if (SelfEval *h = dynamic_cast(d)) { - return h; - } else if (Symbol *h = dynamic_cast(d)) { - if (reg.E.builtin.contains(h->data)) return h; - return mem[reg.E.userdef[h->data]].d; - } else if (Fork *h = dynamic_cast(d)) { - // std::cout << "Eval callllled" << std::endl; - // Symbol *car = dynamic_cast(mem[h->data].d); - //new car: - auto car = mem[h->data].d; - - // if (!car) { - // throw(100); - // } - size_t front = 0; - size_t current = 0; - size_t firstargleft = mem[h->data].cdr; - - // std::cout << "Farg " << firstargleft << std::endl; - - while (firstargleft != 0) { - if (auto c = dynamic_cast(car)) { - if(c->data == "lambda") { - front = mem[h->data].cdr; - break; - } - } - - if (front == 0) { - front = newCell(); - current = front; - } else { - auto temp = newCell(); - mem[current].cdr = temp; - current = temp; - } - - // std::cout << "here" << std::endl; - mem[current].d = Eval(mem[firstargleft].d); - - // std::cout << "there" << std::endl; - firstargleft = mem[firstargleft].cdr; - } - - return mem[Apply(Eval(car), front)].d; - } else { - throw("err"); - } - return NULL; - } - - void ListPrint(Cell c) { - while (true) { - if (typeid(*(c.d)) == typeid(Number)) { - auto p = dynamic_cast(c.d); - std::cout << p->Get() << " "; - } else if (typeid(*(c.d)) == typeid(Symbol)) { - auto p = dynamic_cast(c.d); - std::cout << p->Get() << " "; - } else if (typeid(*(c.d)) == typeid(String)) { - auto p = dynamic_cast(c.d); - std::cout << "@\"" << p->Get() << "\"@ "; - } else if (typeid(*(c.d)) == typeid(Fork)) { - std::cout << "("; - auto p = dynamic_cast(c.d); - ListPrint(mem[p->Get()]); - std::cout << ")"; - } - if (c.cdr == 0) - break; - c = mem[c.cdr]; - } - } - - Cell read_atom(std::istream &in) { - bool isnum = true; - - std::string pass = ""; - char ch; - - if (in.peek() == '"') { - in.get(ch); - while (true) { - in.get(ch); - if (ch == '\\') { - in.get(ch); - pass += ch; - } else if (ch == '"') { - break; - } else { - pass += ch; - } - } - Cell c; - c.cdr = 0; - auto n = new String; - n->data = pass; - c.d = n; - return c; - } - - while (in.get(ch) && ch != '(' && ch != ' ' && ch != ')') { - if (ch != '0' && ch != '1' && ch != '2' && ch != '3' && ch != '4' && ch != '5' && - ch != '6' && ch != '7' && ch != '8' && ch != '9') { - isnum = false; - } - pass += ch; - } - in.unget(); - - Cell c; - c.cdr = 0; - if (isnum) { - auto n = new Number; - n->data = std::stoi(pass); - c.d = n; - } else { - auto s = new Symbol; - s->data = pass; - c.d = s; - } - - return c; - } - - size_t read_expr(std::istream &in) { - size_t front = 0; - size_t current = 0; - - char ch; - while (in.get(ch)) { - if (!std::isspace(ch)) { - if (ch == '(') { - auto temp = newCell(); - mem[current].cdr = temp; - current = temp; - if (front == 0) { - front = current; - } - auto x = new Fork; - mem[current].d = x; - x->data = read_expr(in); - - } else if (ch == ')') { - break; - } else { - auto temp = newCell(); - mem[current].cdr = temp; - current = temp; - if (front == 0) { - front = current; - } - - in.unget(); - - mem[current] = read_atom(in); - } - } - } - - return front; - } -}; - -int main() { - auto m = Machine(1000); - - auto exp = m.read_expr(std::cin); - - m.ListPrint(m.mem[exp]); - std::cout << std::endl; - - Cell c; - c.d = m.Eval(m.mem[exp].d); - - m.ListPrint(c); - std::cout << std::endl; - - - return 0; +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; + + 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) { + + std::vector out; + + std::ifstream matches(filename); + + if (!matches.is_open()) { + std::cout << "Err reading " << filename << std::endl; + exit(1); + } + + std::string line; + + std::string line1; + std::string line2; + + size_t linenum = 1; // One indexed like devtools + while (std::getline(matches, line)) { + if (linenum < 15) { + + } else { + if ((linenum - 15) % 3 == 0) { + line1 = line; + if (line == "" || line == "") + break; + } else if ((linenum - 15) % 3 == 1) { + line2 = line; + + // std::cout << "Debug: L1: " << line1 << std::endl; + // std::cout << "Debug: L2: " << line2 << std::endl; + + auto firstquote = line1.find("\""); + // printf("fq: %ld\n", firstquote); + auto secondquote = line1.find("\"", firstquote + 1); + // printf("sq: %ld\n", secondquote); + auto matchlink = line1.substr(firstquote + 1, secondquote - (firstquote + 1)); + + auto firstslash = line1.find("/", secondquote + 1); + auto secondslash = line1.find("/", firstslash + 1); + auto thirdslash = line1.find("/", secondslash + 1); + + auto firstpar = line1.find("(", thirdslash + 1); + auto secondpar = line1.find(")", firstpar + 1); + + auto p1class = line1.substr(firstslash + 1, secondslash - firstslash - 1); + auto p1name = line1.substr(secondslash + 1, thirdslash - secondslash - 1); + + auto p1match = line1.substr(firstpar + 1, secondpar - firstpar - 2); + + std::cout << p1match << std::endl; + + firstquote = line2.find("\""); + secondquote = line2.find("\"", firstquote + 1); + firstslash = line2.find("/", secondquote + 1); + secondslash = line2.find("/", firstslash + 1); + thirdslash = line2.find("/", secondslash + 1); + firstpar = line2.find("(", thirdslash + 1); + secondpar = line2.find(")", firstpar + 1); + + auto p2class = line2.substr(firstslash + 1, secondslash - (firstslash + 1)); + auto p2name = line2.substr(secondslash + 1, thirdslash - (secondslash + 1)); + + auto p2match = line2.substr(firstpar + 1, secondpar - firstpar - 2); + std::cout << p2match << std::endl; + + auto p1 = Person(p1class, p1name); + + auto p2 = Person(p2class, p2name); + + BasicEntry finent = {.A = p1, + .B = p2, + .matchlink = matchlink, + .Apercent = std::stoi(p1match), + .Bpercent = std::stoi(p2match)}; + + out.push_back(finent); + } + } + linenum++; + } + return out; +} + +struct State { + std::vector entries; +}; + +void changelayout(Fl_Widget *w, void *meow) { + std::pair *in = (std::pair *)meow; + in->second.show(); + // in->second.parent()->redraw(); + // in->first.window()->redraw(); + // in->first.init_sizes(); + in->first.layout(); + in->second.redraw(); + // in->first.redraw(); +} + +struct Topbar : Fl_Group { + + Fl_PNG_Image inspectIcon; + + Fl_Box *titleText; + Fl_Button *inspect; + + Topbar(int x, int y, int w, int h) + : Fl_Group(x, y, w, h), + inspectIcon("Inspect", icon_inspect_file_png, icon_inspect_file_png_len) { + + titleText = new Fl_Box(0, 0, 100, 50, "MossMan"); + titleText->labelsize(36); + titleText->labelfont(FL_TIMES | FL_BOLD); + titleText->align(FL_ALIGN_INSIDE | FL_ALIGN_TOP_LEFT); + inspect = new Fl_Button(950, 0, 50, 50); + resizable(titleText); + + inspect->image(inspectIcon); + inspect->tooltip("Inspect Entr(ies)"); + + end(); + } +}; + +struct MainGui : Fl_Window { + Topbar *topbar; + + Fl_Tile *tilebox; + Fl_Multi_Browser *list; + SummaryManager *summaryEditor; + 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); + + tilebox->end(); + + end(); + + resizable(tilebox); + } +}; + +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(); + + // window->resizable(*group); + // window->end(); + + // MainGui x; + + // Selected callbackdata(*browser); + + // button->callback(show_callback, (void*) &callbackdata); + + // window->show(); + + MainGui x; + x.show(); + + return Fl::run(); } diff --git a/src/summarymanager.cpp b/src/summarymanager.cpp new file mode 100644 index 0000000..6a4ae35 --- /dev/null +++ b/src/summarymanager.cpp @@ -0,0 +1,45 @@ +#include "summarymanager.hpp" +#include +#include +#include +#include +#include +#include + +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"); + { + Fl_Window *win1 = new Fl_Window(x, y + 30, w, h - 30, "Tab1W"); + std::cout << "here" << std::endl; + { + auto butt = new Fl_Button(0, 0, 100, 200, "test"); + } + win1->end(); + auto butt = new Fl_Button(0, 30, 100, 200, "nyaaa"); + } + grp1->end(); + // Fl_Group *grp2 = new Fl_Group(20, 30, 280, 170, "Tab2"); + // { + // } + // grp2->end(); + // Fl_Group *grp3 = new Fl_Group(20, 30, 280, 170, "Tab3"); + // { + // } + // grp3->end(); + // Fl_Group *grp4 = new Fl_Group(20, 30, 280, 170, "Tab4"); + // { + // } + // grp4->end(); + // Fl_Group *grp5 = new Fl_Group(20, 30, 280, 170, "Tab5"); + // { + // } + // grp5->end(); + tabs.end(); + tabs.handle_overflow(Fl_Tabs::OVERFLOW_DRAG); + + tabs.resizable(grp1); + + end(); +} diff --git a/src/summarymanager.hpp b/src/summarymanager.hpp new file mode 100644 index 0000000..c0672d4 --- /dev/null +++ b/src/summarymanager.hpp @@ -0,0 +1,18 @@ +#ifndef SUMMARYMANAGER_HEADER +#define SUMMARYMANAGER_HEADER + +#include +#include +#include +#include +#include + + +struct SummaryManager : Fl_Group { + SummaryManager(int x, int y, int w, int h); + Fl_Tabs tabs; + std::vector items; + +}; + +#endif