From ad9e7cd5117c965222aae708f660e56d537914fc Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Mon, 6 Oct 2025 00:48:48 +0300 Subject: imported all of my Github gists from https://gist.github.com/rhaberkorn --- tests/bait.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ tests/mouse-test.c | 50 +++++++++++++++++++++++++++++++++++ tests/relocatability-test.c | 28 ++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 tests/bait.c create mode 100644 tests/mouse-test.c create mode 100644 tests/relocatability-test.c (limited to 'tests') diff --git a/tests/bait.c b/tests/bait.c new file mode 100644 index 0000000..fd6081b --- /dev/null +++ b/tests/bait.c @@ -0,0 +1,63 @@ +// Scintilla "Bait" example to demonstrate various problems with folding +#include + +#include +//#include +#define PLAT_GTK 1 +#include + +static int exit_app(GtkWidget*w, GdkEventAny*e, gpointer p) { + gtk_main_quit(); + return w||e||p||1; // Avoid warnings +} + +int main(int argc, char **argv) { + GtkWidget *app; + GtkWidget *editor; + ScintillaObject *sci; + + gtk_init(&argc, &argv); + app = gtk_window_new(GTK_WINDOW_TOPLEVEL); + editor = scintilla_new(); + sci = SCINTILLA(editor); + + gtk_container_add(GTK_CONTAINER(app), editor); + g_signal_connect(app, "delete_event", G_CALLBACK(exit_app), 0); + + scintilla_set_id(sci, 0); + //gtk_widget_set_usize(editor, 500, 300); + +#define SSM(m, w, l) scintilla_send_message(sci, m, w, l) + + SSM(SCI_STYLESETBACK, STYLE_DEFAULT, 0x000000); + SSM(SCI_STYLESETFORE, STYLE_DEFAULT, 0xFFFFFF); + SSM(SCI_STYLECLEARALL, 0, 0); + + SSM(SCI_INSERTTEXT, 0, (sptr_t) + "int main(int argc, char **argv) {\n" + " // Start up the gnome\n" + " gnome_init(\"stest\", \"1.0\", argc, argv);\n}" + ); + + /* + * FIXME: Should enable automatic folding by clicking on the margin. + */ + SSM(SCI_SETAUTOMATICFOLD, SC_AUTOMATICFOLD_CLICK | SC_AUTOMATICFOLD_SHOW | SC_AUTOMATICFOLD_CHANGE, 0); + + SSM(SCI_SETMARGINWIDTHN, 2, SSM(SCI_TEXTWIDTH, 33, (sptr_t)"XX")); + SSM(SCI_SETMARGINMASKN, 2, (1 << SC_MARKNUM_FOLDER) | (1 << SC_MARKNUM_FOLDEROPEN)); + /* + * FIXME: Should inherit background color from STYLE_DEFAULT? + */ + SSM(SCI_SETMARGINTYPEN, 2, SC_MARGIN_BACK); + + SSM(SCI_SETFOLDLEVEL, 0, (SC_FOLDLEVELBASE) | SC_FOLDLEVELHEADERFLAG); + SSM(SCI_SETFOLDLEVEL, 1, (SC_FOLDLEVELBASE + 1)); + //SSM(SCI_TOGGLEFOLD, 0, 0); + + gtk_widget_show_all(app); + gtk_widget_grab_focus(GTK_WIDGET(editor)); + gtk_main(); + + return 0; +} diff --git a/tests/mouse-test.c b/tests/mouse-test.c new file mode 100644 index 0000000..c7d3e57 --- /dev/null +++ b/tests/mouse-test.c @@ -0,0 +1,50 @@ +// Test the ncurses mouse API +//gcc -o mouse-test mouse-test.c -I~/working-copies/ncurses-snapshots/include ~/working-copies/ncurses-snapshots/lib/libncursesw.a +#include + +#include +#include + +#define BUTTON_NUM(X) \ + (BUTTON##X##_PRESSED | BUTTON##X##_RELEASED | \ + BUTTON##X##_CLICKED | BUTTON##X##_DOUBLE_CLICKED | BUTTON##X##_TRIPLE_CLICKED) +#define BUTTON_EVENT(X) \ + (BUTTON1_##X | BUTTON2_##X | BUTTON3_##X | BUTTON4_##X | BUTTON5_##X) + +int main(void) +{ + initscr(); + raw(); + noecho(); + scrollok(stdscr, TRUE); + + keypad(stdscr, TRUE); + mouseinterval(0); + mousemask(BUTTON_EVENT(PRESSED) | BUTTON_EVENT(RELEASED) /*| REPORT_MOUSE_POSITION*/, NULL); +// mousemask(ALL_MOUSE_EVENTS, NULL); + + for (;;) { + MEVENT event; + int c = wgetch(stdscr); + + if (c == '\e') + break; + if (c != KEY_MOUSE) + continue; + + while (getmouse(&event) == OK) { + printw("EVENT: 0x%016X == %02d [%c%c%c%c%c%c]\n", + event.bstate, ffs(event.bstate)-1, + event.bstate & BUTTON_NUM(4) ? 'U' : ' ', + event.bstate & BUTTON_NUM(5) ? 'D' : ' ', + event.bstate & BUTTON_EVENT(PRESSED) ? 'P' : ' ', + event.bstate & BUTTON_EVENT(RELEASED) ? 'R' : ' ', + event.bstate & BUTTON_EVENT(CLICKED) ? 'C' : ' ', + event.bstate & REPORT_MOUSE_POSITION ? 'M' : ' '); + } + } + + endwin(); + + return 0; +} diff --git a/tests/relocatability-test.c b/tests/relocatability-test.c new file mode 100644 index 0000000..ef970bc --- /dev/null +++ b/tests/relocatability-test.c @@ -0,0 +1,28 @@ +/* + * This prints the location of the current binary as + * reported by the dynamic linker. + * It does not work on all UNIX-like platforms. + * For instance, it doesn't on Linux. + * + * Link with: cc -o relocatability-test relocatability-test.c -ldl + */ +#define _GNU_SOURCE +#include +#include + +int +main(int argc, char **argv) +{ + Dl_info info; + + printf("argv[0] = %s\n", argv[0]); + + if (!dladdr(main, &info)) { + fprintf(stderr, "Cannot query executable's path: %s\n", + dlerror()); + return 1; + } + + printf("dli_fname = %s\n", info.dli_fname); + return 0; +} -- cgit v1.2.3