From 3247e18798557b8eef9a8d149d34d731b222a3cc Mon Sep 17 00:00:00 2001 From: balhau Date: Sun, 12 Dec 2021 15:00:30 +0000 Subject: [PATCH] Missing files --- include/cpu/atomic.hpp | 3 ++ include/misc/memory/util.h | 21 ++++++++++++ src/gui/gui1.cpp | 64 +++++++++++++++++++++++++++++++++++++ src/misc/dec/CMakeLists.txt | 2 ++ src/misc/dec/ex1.cpp | 28 ++++++++++++++++ src/misc/dec/ex2.cpp | 7 ++++ src/misc/memory/cautofree.c | 26 +++++++++++++++ src/misc/memory/cmem.c | 53 ++++++++++++++++++++++++++++++ 8 files changed, 204 insertions(+) create mode 100644 include/cpu/atomic.hpp create mode 100644 include/misc/memory/util.h create mode 100644 src/gui/gui1.cpp create mode 100644 src/misc/dec/CMakeLists.txt create mode 100644 src/misc/dec/ex1.cpp create mode 100644 src/misc/dec/ex2.cpp create mode 100644 src/misc/memory/cautofree.c create mode 100644 src/misc/memory/cmem.c diff --git a/include/cpu/atomic.hpp b/include/cpu/atomic.hpp new file mode 100644 index 0000000..7b22c47 --- /dev/null +++ b/include/cpu/atomic.hpp @@ -0,0 +1,3 @@ +int cmp_swap(int* old_int,int new_int){ + +} \ No newline at end of file diff --git a/include/misc/memory/util.h b/include/misc/memory/util.h new file mode 100644 index 0000000..dfb69e9 --- /dev/null +++ b/include/misc/memory/util.h @@ -0,0 +1,21 @@ +#include + +#pragma once + +#define COLOR(color) "\e["color"m" + +#define COL_BLACK COLOR("0;30") +#define COL_BLUE COLOR("0;34") +#define COL_GREEN COLOR("0;32") +#define COL_RED COLOR("0;31") +#define COL_NONE COLOR("0;0") + +void p_mem(const char *label, void *pointer) +{ + printf("%s:\t%p\t%ld\n", label, pointer, (long)pointer); +} + +void p_diff(const char *label,void *p1, void *p2){ + printf("%s:\tp1:%p\tp2:%p\tdiff:\t%ld\n",label,p1,p2,(long)(p2-p1)); +} + diff --git a/src/gui/gui1.cpp b/src/gui/gui1.cpp new file mode 100644 index 0000000..3b97857 --- /dev/null +++ b/src/gui/gui1.cpp @@ -0,0 +1,64 @@ +// For compilers that support precompilation, includes "wx/wx.h". +#include +#ifndef WX_PRECOMP + #include +#endif + +class MyApp : public wxApp +{ +public: + virtual bool OnInit(); +}; +class MyFrame : public wxFrame +{ +public: + MyFrame(); +private: + void OnHello(wxCommandEvent& event); + void OnExit(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); +}; +enum +{ + ID_Hello = 1 +}; +wxIMPLEMENT_APP(MyApp); +bool MyApp::OnInit() +{ + MyFrame *frame = new MyFrame(); + frame->Show(true); + return true; +} +MyFrame::MyFrame() + : wxFrame(NULL, wxID_ANY, "Hello World") +{ + wxMenu *menuFile = new wxMenu; + menuFile->Append(ID_Hello, "&Hello...\tCtrl-H", + "Help string shown in status bar for this menu item"); + menuFile->AppendSeparator(); + menuFile->Append(wxID_EXIT); + wxMenu *menuHelp = new wxMenu; + menuHelp->Append(wxID_ABOUT); + wxMenuBar *menuBar = new wxMenuBar; + menuBar->Append(menuFile, "&File"); + menuBar->Append(menuHelp, "&Help"); + SetMenuBar( menuBar ); + CreateStatusBar(); + SetStatusText("Welcome to wxWidgets!"); + Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello); + Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT); + Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT); +} +void MyFrame::OnExit(wxCommandEvent& event) +{ + Close(true); +} +void MyFrame::OnAbout(wxCommandEvent& event) +{ + wxMessageBox("This is a wxWidgets Hello World example", + "About Hello World", wxOK | wxICON_INFORMATION); +} +void MyFrame::OnHello(wxCommandEvent& event) +{ + wxLogMessage("Hello world from wxWidgets!"); +} \ No newline at end of file diff --git a/src/misc/dec/CMakeLists.txt b/src/misc/dec/CMakeLists.txt new file mode 100644 index 0000000..4dcc6f4 --- /dev/null +++ b/src/misc/dec/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(dec_ex1 ex1.cpp) +add_executable(dec_ex2 ex2.cpp) diff --git a/src/misc/dec/ex1.cpp b/src/misc/dec/ex1.cpp new file mode 100644 index 0000000..091949e --- /dev/null +++ b/src/misc/dec/ex1.cpp @@ -0,0 +1,28 @@ +#include + +static const char* license="x31lfkssfaskfs"; + +void showMessageError(){ + std::cout << "Exiting program " << std::endl; +} + +void continueProgram(){ + std::cout << "Continuing program " << std::endl; +} + +void checkLicence(){ + std::string input; + std::cout << "Enter licence key" << std::endl; + std::cin >> input; + std::string licenceString = license; + if(licenceString==input){ + continueProgram(); + } + else{ + showMessageError(); + } +} + +int main(void){ + checkLicence(); +} \ No newline at end of file diff --git a/src/misc/dec/ex2.cpp b/src/misc/dec/ex2.cpp new file mode 100644 index 0000000..749e0b8 --- /dev/null +++ b/src/misc/dec/ex2.cpp @@ -0,0 +1,7 @@ +#include + +int main(void){ + std::string hello = "Hello world"; + std::cout << hello; + return 5; +} \ No newline at end of file diff --git a/src/misc/memory/cautofree.c b/src/misc/memory/cautofree.c new file mode 100644 index 0000000..3798a79 --- /dev/null +++ b/src/misc/memory/cautofree.c @@ -0,0 +1,26 @@ +#include +#include +#include "../../../include/misc/memory/util.h" + +#define AUTO_FREE __attribute__((cleanup(scoped_free))) + +typedef struct Point +{ + int x; + int y; +} Point; + +void scoped_free(void *pointer) +{ + printf("Scoped free invoked %p\n",pointer); + void **pp = (void**)pointer; + free(*pp); +} + +int main(int argc, char **argv) +{ + AUTO_FREE Point *p1 = (Point *)malloc(sizeof(Point)); + p_mem("P1",p1); + AUTO_FREE Point *p2 = (Point *)malloc(sizeof(Point)); + p_mem("P2",p2); +} \ No newline at end of file diff --git a/src/misc/memory/cmem.c b/src/misc/memory/cmem.c new file mode 100644 index 0000000..4e20fcd --- /dev/null +++ b/src/misc/memory/cmem.c @@ -0,0 +1,53 @@ +#include +#include +#include "../../../include/misc/memory/util.h" + +void stack_frame2(void) +{ + int b = 2; + + p_mem("b", &b); +} + +void stack_frame1(void) +{ + int a = 1; + p_mem("a", &a); + stack_frame2(); +} + +int main(int argc, char **argv) +{ + /* + { + int a = 12; p_mem("a", &a); + int b = 24; p_mem("b", &b); + int c = 48; p_mem("c", &c); + + p_diff("b-a",&a,&b); + p_diff("c-b",&b,&c); + p_diff("c-a",&a,&c); + } + { + int x = 21; p_mem("x", &x); + int y = 42; p_mem("y", &y); + int z = 84; p_mem("z", &z); + + p_diff("y-x",&x,&y); + p_diff("z-y",&y,&z); + p_diff("z-x",&x,&z); + } + */ + + + stack_frame1(); + + //int *p_int=(int*)malloc(sizeof(int)); + //*p_int=12; + + //printf("%d\n",*p_int); + //p_mem("p_int",p_int); + + //free(p_int); + return getchar(); +} \ No newline at end of file