From a1957e1b3d0ee4d67bec56ec4349b0f0cb3fa1f2 Mon Sep 17 00:00:00 2001 From: Peter Gerwinski <peter.gerwinski@hs-bochum.de> Date: Thu, 2 Nov 2023 16:51:50 +0100 Subject: [PATCH] Beispiele und Screenshots 2.11.2023 --- 20231102/Makefile | 8 ++++++ 20231102/answer.c | 6 ++++ 20231102/answer.h | 1 + 20231102/bc-01.txt | 19 +++++++++++++ 20231102/bc-02.txt | 24 ++++++++++++++++ 20231102/bit-ops-01.c | 7 +++++ 20231102/bit-ops-02.c | 7 +++++ 20231102/blink-0.c | 9 ++++++ 20231102/blink-0.hex | 10 +++++++ 20231102/download.sh | 3 ++ 20231102/gtk-01.c | 17 +++++++++++ 20231102/gtk-01.txt | 52 ++++++++++++++++++++++++++++++++++ 20231102/gtk-01a.c | 10 +++++++ 20231102/gtk-01b.c | 19 +++++++++++++ 20231102/gtk-01c.c | 22 +++++++++++++++ 20231102/gtk-02.c | 27 ++++++++++++++++++ 20231102/gtk-03.c | 26 +++++++++++++++++ 20231102/gtk-04.c | 20 +++++++++++++ 20231102/gtk-05.c | 35 +++++++++++++++++++++++ 20231102/gtk-06.c | 53 ++++++++++++++++++++++++++++++++++ 20231102/gtk-06a.c | 55 ++++++++++++++++++++++++++++++++++++ 20231102/hp-20231102.txt | 35 +++++++++++++++++++++++ 20231102/inttypes-01.c | 9 ++++++ 20231102/inttypes-02.c | 9 ++++++ 20231102/inttypes-03.c | 10 +++++++ 20231102/libraries-01.txt | 10 +++++++ 20231102/number-systems-01.c | 9 ++++++ 20231102/number-systems-02.c | 12 ++++++++ 20231102/philosophy.c | 8 ++++++ 29 files changed, 532 insertions(+) create mode 100644 20231102/Makefile create mode 100644 20231102/answer.c create mode 100644 20231102/answer.h create mode 100644 20231102/bc-01.txt create mode 100644 20231102/bc-02.txt create mode 100644 20231102/bit-ops-01.c create mode 100644 20231102/bit-ops-02.c create mode 100644 20231102/blink-0.c create mode 100644 20231102/blink-0.hex create mode 100755 20231102/download.sh create mode 100644 20231102/gtk-01.c create mode 100644 20231102/gtk-01.txt create mode 100644 20231102/gtk-01a.c create mode 100644 20231102/gtk-01b.c create mode 100644 20231102/gtk-01c.c create mode 100644 20231102/gtk-02.c create mode 100644 20231102/gtk-03.c create mode 100644 20231102/gtk-04.c create mode 100644 20231102/gtk-05.c create mode 100644 20231102/gtk-06.c create mode 100644 20231102/gtk-06a.c create mode 100644 20231102/hp-20231102.txt create mode 100644 20231102/inttypes-01.c create mode 100644 20231102/inttypes-02.c create mode 100644 20231102/inttypes-03.c create mode 100644 20231102/libraries-01.txt create mode 100644 20231102/number-systems-01.c create mode 100644 20231102/number-systems-02.c create mode 100644 20231102/philosophy.c diff --git a/20231102/Makefile b/20231102/Makefile new file mode 100644 index 0000000..7ae33df --- /dev/null +++ b/20231102/Makefile @@ -0,0 +1,8 @@ +%.elf: %.c + avr-gcc -Wall -Os -mmcu=atmega328p $< -o $@ + +%.hex: %.elf + avr-objcopy -O ihex $< $@ + +download: + ./download.sh diff --git a/20231102/answer.c b/20231102/answer.c new file mode 100644 index 0000000..65a1dc2 --- /dev/null +++ b/20231102/answer.c @@ -0,0 +1,6 @@ +#include "answer.h" + +int answer (void) +{ + return 23; +} diff --git a/20231102/answer.h b/20231102/answer.h new file mode 100644 index 0000000..b6777e8 --- /dev/null +++ b/20231102/answer.h @@ -0,0 +1 @@ +extern int answer (void); diff --git a/20231102/bc-01.txt b/20231102/bc-01.txt new file mode 100644 index 0000000..95ddcc5 --- /dev/null +++ b/20231102/bc-01.txt @@ -0,0 +1,19 @@ +cassini/home/peter/bo/2023ws/hp/20231102> bc +bc 1.07.1 +Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc. +This is free software with ABSOLUTELY NO WARRANTY. +For details type `warranty'. +obase=13 +6 * 9 +42 +obase=A +6 * 9 +54 +obase=13 +6 * 9 +42 +obase=1+1+1+1+1+1+1+1+1+1 +6 * 9 +54 + +cassini/home/peter/bo/2023ws/hp/20231102> diff --git a/20231102/bc-02.txt b/20231102/bc-02.txt new file mode 100644 index 0000000..8d284a3 --- /dev/null +++ b/20231102/bc-02.txt @@ -0,0 +1,24 @@ +cassini/home/peter/bo/2023ws/hp/20231102> bc +bc 1.07.1 +Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc. +This is free software with ABSOLUTELY NO WARRANTY. +For details type `warranty'. +obase=16 +42 +2A +ibase=16 +B747 + A380 +15AC7 +obase=10 +5 + 5 +A +A + A +14 +18 + 18 +30 +ibase=1+1+1+1+1+1+1+1+1+1 +obase=10 +5 + 5 +10 + +cassini/home/peter/bo/2023ws/hp/20231102> diff --git a/20231102/bit-ops-01.c b/20231102/bit-ops-01.c new file mode 100644 index 0000000..c4c79cf --- /dev/null +++ b/20231102/bit-ops-01.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("2 & 2 = %d\n", 2 & 2); + return 0; +} diff --git a/20231102/bit-ops-02.c b/20231102/bit-ops-02.c new file mode 100644 index 0000000..8c910ae --- /dev/null +++ b/20231102/bit-ops-02.c @@ -0,0 +1,7 @@ +#include <stdio.h> + +int main (void) +{ + printf ("2^8 = %d\n", 2^8); + return 0; +} diff --git a/20231102/blink-0.c b/20231102/blink-0.c new file mode 100644 index 0000000..b0022c6 --- /dev/null +++ b/20231102/blink-0.c @@ -0,0 +1,9 @@ +#include <avr/io.h> + +int main (void) +{ + DDRD = 0x40; /* binär: 0100 0000 */ + PORTD = 0x40; /* binär: 0100 0000 */ + while (1); + return 0; +} diff --git a/20231102/blink-0.hex b/20231102/blink-0.hex new file mode 100644 index 0000000..6a05b7d --- /dev/null +++ b/20231102/blink-0.hex @@ -0,0 +1,10 @@ +:100000000C9434000C943E000C943E000C943E0082 +:100010000C943E000C943E000C943E000C943E0068 +:100020000C943E000C943E000C943E000C943E0058 +:100030000C943E000C943E000C943E000C943E0048 +:100040000C943E000C943E000C943E000C943E0038 +:100050000C943E000C943E000C943E000C943E0028 +:100060000C943E000C943E0011241FBECFEFD8E04C +:10007000DEBFCDBF0E9440000C9444000C940000F1 +:0C00800080E48AB98BB9FFCFF894FFCF61 +:00000001FF diff --git a/20231102/download.sh b/20231102/download.sh new file mode 100755 index 0000000..770c3b5 --- /dev/null +++ b/20231102/download.sh @@ -0,0 +1,3 @@ +port=$(ls -rt /dev/ttyACM* | tail -1) +echo avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1) +avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1) 2>/dev/null diff --git a/20231102/gtk-01.c b/20231102/gtk-01.c new file mode 100644 index 0000000..2cd0d60 --- /dev/null +++ b/20231102/gtk-01.c @@ -0,0 +1,17 @@ +#include <gtk/gtk.h> + +static void activate (GtkApplication *app, gpointer user_data) +{ + GtkWidget *window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "Hello"); + gtk_window_present (GTK_WINDOW (window)); +} + +int main (int argc, char **argv) +{ + GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.gtk-01", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + int status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + return status; +} diff --git a/20231102/gtk-01.txt b/20231102/gtk-01.txt new file mode 100644 index 0000000..4b08500 --- /dev/null +++ b/20231102/gtk-01.txt @@ -0,0 +1,52 @@ +cassini/home/peter/bo/2023ws/hp/20231102> gcc -Wall -O gtk-01.c -o gtk-01 +gtk-01.c:1:10: fatal error: gtk/gtk.h: Datei oder Verzeichnis nicht gefunden + 1 | #include <gtk/gtk.h> + | ^~~~~~~~~~~ +compilation terminated. +cassini/home/peter/bo/2023ws/hp/20231102> locate gtk/gtk.h +/usr/include/gtk-2.0/gtk/gtk.h +/usr/include/gtk-3.0/gtk/gtk.h +/usr/include/gtk-4.0/gtk/gtk.h +cassini/home/peter/bo/2023ws/hp/20231102> gcc -Wall -I /usr/include/gtk-4.0 -O gtk-01.c -o gtk-01 +In file included from /usr/include/gtk-4.0/gtk/gtk.h:30, + from gtk-01.c:1: +/usr/include/gtk-4.0/gtk/css/gtkcss.h:30:10: fatal error: glib.h: Datei oder Verzeichnis nicht gefunden + 30 | #include <glib.h> + | ^~~~~~~~ +compilation terminated. +cassini/home/peter/bo/2023ws/hp/20231102> locate glib.h +/home/peter/bo/2012ws/rtech/material/usbstick/fdos/source/command/command/suppl/msglib.h +/usr/include/jpeglib.h +/usr/include/dbus-1.0/dbus/dbus-glib.h +/usr/include/glib-2.0/glib.h +/usr/include/harfbuzz/hb-glib.h +cassini/home/peter/bo/2023ws/hp/20231102> gcc -Wall -I /usr/include/gtk-4.0 -I /usr/include/glib-2.0 -O gtk-01.c -o gtk-01 +In file included from /usr/include/glib-2.0/glib/galloca.h:34, + from /usr/include/glib-2.0/glib.h:32, + from /usr/include/gtk-4.0/gtk/css/gtkcss.h:30, + from /usr/include/gtk-4.0/gtk/gtk.h:30, + from gtk-01.c:1: +/usr/include/glib-2.0/glib/gtypes.h:34:10: fatal error: glibconfig.h: Datei oder Verzeichnis nicht gefunden + 34 | #include <glibconfig.h> + | ^~~~~~~~~~~~~~ +compilation terminated. +cassini/home/peter/bo/2023ws/hp/20231102> pkg-config --cflags --libs gtk4 +-I/usr/include/gtk-4.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/graphene-1.0 -I/usr/lib/x86_64-linux-gnu/graphene-1.0/include -mfpmath=sse -msse -msse2 -pthread -lgtk-4 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lgdk_pixbuf-2.0 -lcairo-gobject -lcairo -lgraphene-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 +cassini/home/peter/bo/2023ws/hp/20231102> gcc -Wall -O -I/usr/include/gtk-4.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/graphene-1.0 -I/usr/lib/x86_64-linux-gnu/graphene-1.0/include -mfpmath=sse -msse -msse2 -pthread -lgtk-4 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lgdk_pixbuf-2.0 -lcairo-gobject -lcairo -lgraphene-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 gtk-01.c -o gtk-01 +/usr/bin/ld: /tmp/cc6S8nDW.o: in function `activate': +gtk-01.c:(.text+0x7): undefined reference to `gtk_application_window_new' +/usr/bin/ld: gtk-01.c:(.text+0xf): undefined reference to `gtk_window_get_type' +/usr/bin/ld: gtk-01.c:(.text+0x1d): undefined reference to `g_type_check_instance_cast' +/usr/bin/ld: gtk-01.c:(.text+0x2c): undefined reference to `gtk_window_set_title' +/usr/bin/ld: gtk-01.c:(.text+0x37): undefined reference to `g_type_check_instance_cast' +/usr/bin/ld: gtk-01.c:(.text+0x3f): undefined reference to `gtk_window_present' +/usr/bin/ld: /tmp/cc6S8nDW.o: in function `main': +gtk-01.c:(.text+0x60): undefined reference to `gtk_application_new' +/usr/bin/ld: gtk-01.c:(.text+0x8a): undefined reference to `g_signal_connect_data' +/usr/bin/ld: gtk-01.c:(.text+0x8f): undefined reference to `g_application_get_type' +/usr/bin/ld: gtk-01.c:(.text+0x9a): undefined reference to `g_type_check_instance_cast' +/usr/bin/ld: gtk-01.c:(.text+0xa7): undefined reference to `g_application_run' +/usr/bin/ld: gtk-01.c:(.text+0xb1): undefined reference to `g_object_unref' +collect2: error: ld returned 1 exit status +cassini/home/peter/bo/2023ws/hp/20231102> gcc -Wall -O gtk-01.c -I/usr/include/gtk-4.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/graphene-1.0 -I/usr/lib/x86_64-linux-gnu/graphene-1.0/include -mfpmath=sse -msse -msse2 -pthread -lgtk-4 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lgdk_pixbuf-2.0 -lcairo-gobject -lcairo -lgraphene-1.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -o gtk-01 +cassini/home/peter/bo/2023ws/hp/20231102> diff --git a/20231102/gtk-01a.c b/20231102/gtk-01a.c new file mode 100644 index 0000000..d703f0e --- /dev/null +++ b/20231102/gtk-01a.c @@ -0,0 +1,10 @@ +#include <gtk/gtk.h> + +int main (int argc, char **argv) +{ + GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.gtk-01", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + int status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + return status; +} diff --git a/20231102/gtk-01b.c b/20231102/gtk-01b.c new file mode 100644 index 0000000..92cc3d6 --- /dev/null +++ b/20231102/gtk-01b.c @@ -0,0 +1,19 @@ +#include <gtk/gtk.h> +#include <stdio.h> + +static void activate (GtkApplication *app, gpointer user_data) +{ + printf ("activate()\n"); + GtkWidget *window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "Hello"); + gtk_window_present (GTK_WINDOW (window)); +} + +int main (int argc, char **argv) +{ + GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.gtk-01", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + int status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + return status; +} diff --git a/20231102/gtk-01c.c b/20231102/gtk-01c.c new file mode 100644 index 0000000..51961e4 --- /dev/null +++ b/20231102/gtk-01c.c @@ -0,0 +1,22 @@ +#include <gtk/gtk.h> +#include <stdio.h> + +static void activate (GtkApplication *app, gpointer user_data) +{ + printf ("activate()\n"); + GtkWidget *window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "Hello"); + gtk_window_present (GTK_WINDOW (window)); +} + +int main (int argc, char **argv) +{ + GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.gtk-01", G_APPLICATION_DEFAULT_FLAGS); + printf ("vor g_signal_connect()\n"); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + printf ("vor g_application_run()\n"); + int status = g_application_run (G_APPLICATION (app), argc, argv); + printf ("nach g_application_run()\n"); + g_object_unref (app); + return status; +} diff --git a/20231102/gtk-02.c b/20231102/gtk-02.c new file mode 100644 index 0000000..1ab3c19 --- /dev/null +++ b/20231102/gtk-02.c @@ -0,0 +1,27 @@ +#include <gtk/gtk.h> +#include <stdio.h> + +static void hello (GtkWidget *this, gpointer user_data) +{ + char *world = user_data; + printf ("Hello, %s!\n", world); +} + +static void activate (GtkApplication *app, gpointer user_data) +{ + GtkWidget *window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "Hello"); + GtkWidget *button = gtk_button_new_with_label ("Hello, world!"); + g_signal_connect (button, "clicked", G_CALLBACK (hello), "world"); + gtk_window_set_child (GTK_WINDOW (window), button); + gtk_window_present (GTK_WINDOW (window)); +} + +int main (int argc, char **argv) +{ + GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.gtk-02", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + int status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + return status; +} diff --git a/20231102/gtk-03.c b/20231102/gtk-03.c new file mode 100644 index 0000000..4fe3a03 --- /dev/null +++ b/20231102/gtk-03.c @@ -0,0 +1,26 @@ +#include <gtk/gtk.h> + +static void close_window (GtkWidget *this, gpointer user_data) +{ + GtkWindow *window = user_data; + gtk_window_destroy (window); +} + +static void activate (GtkApplication *app, gpointer user_data) +{ + GtkWidget *window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "Hello"); + GtkWidget *button = gtk_button_new_with_label ("Quit"); + g_signal_connect (button, "clicked", G_CALLBACK (close_window), window); + gtk_window_set_child (GTK_WINDOW (window), button); + gtk_window_present (GTK_WINDOW (window)); +} + +int main (int argc, char **argv) +{ + GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + int status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + return status; +} diff --git a/20231102/gtk-04.c b/20231102/gtk-04.c new file mode 100644 index 0000000..6ae0e7d --- /dev/null +++ b/20231102/gtk-04.c @@ -0,0 +1,20 @@ +#include <gtk/gtk.h> + +static void activate (GtkApplication *app, gpointer user_data) +{ + GtkWidget *window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "Hello"); + GtkWidget *button = gtk_button_new_with_label ("Quit"); + g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_window_destroy), window); + gtk_window_set_child (GTK_WINDOW (window), button); + gtk_window_present (GTK_WINDOW (window)); +} + +int main (int argc, char **argv) +{ + GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + int status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + return status; +} diff --git a/20231102/gtk-05.c b/20231102/gtk-05.c new file mode 100644 index 0000000..a7394ee --- /dev/null +++ b/20231102/gtk-05.c @@ -0,0 +1,35 @@ +#include <gtk/gtk.h> + +static void hello (GtkWidget *this, gpointer user_data) +{ + char *world = user_data; + printf ("Hello, %s!\n", world); +} + +static void activate (GtkApplication *app, gpointer user_data) +{ + GtkWidget *window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "Hello"); + + GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); + gtk_window_set_child (GTK_WINDOW (window), vbox); + + GtkWidget *hello_button = gtk_button_new_with_label ("Hello, world!"); + g_signal_connect (hello_button, "clicked", G_CALLBACK (hello), "world"); + gtk_box_append (GTK_BOX (vbox), hello_button); + + GtkWidget *quit_button = gtk_button_new_with_label ("Quit"); + g_signal_connect_swapped (quit_button, "clicked", G_CALLBACK (gtk_window_destroy), window); + gtk_box_append (GTK_BOX (vbox), quit_button); + + gtk_window_present (GTK_WINDOW (window)); +} + +int main (int argc, char **argv) +{ + GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + int status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + return status; +} diff --git a/20231102/gtk-06.c b/20231102/gtk-06.c new file mode 100644 index 0000000..64687de --- /dev/null +++ b/20231102/gtk-06.c @@ -0,0 +1,53 @@ +#include <gtk/gtk.h> + +static void draw (GtkDrawingArea *drawing_area, cairo_t *c, + int width, int height, gpointer user_data) +{ + GdkRGBA red = { 1.0, 0.0, 0.0, 0.8 }; + GdkRGBA yellow = { 1.0, 1.0, 0.0, 0.6 }; + GdkRGBA blue = { 0.0, 0.5, 1.0, 0.4 }; + + gdk_cairo_set_source_rgba (c, &red); + cairo_rectangle (c, 10, 10, 60, 40); + cairo_fill (c); + + gdk_cairo_set_source_rgba (c, &yellow); + cairo_arc (c, 65, 50, 30, 0, 2 * G_PI); + cairo_fill (c); + + gdk_cairo_set_source_rgba (c, &blue); + cairo_move_to (c, 10, 70); + cairo_line_to (c, 70, 70); + cairo_line_to (c, 40, 18); + cairo_close_path (c); + cairo_fill (c); +} + +static void activate (GtkApplication *app, gpointer user_data) +{ + GtkWidget *window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "Hello"); + + GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); + gtk_window_set_child (GTK_WINDOW (window), vbox); + + GtkWidget *drawing_area = gtk_drawing_area_new (); + gtk_widget_set_size_request (drawing_area, 100, 100); + gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (drawing_area), draw, NULL, NULL); + gtk_box_append (GTK_BOX (vbox), drawing_area); + + GtkWidget *quit_button = gtk_button_new_with_label ("Quit"); + g_signal_connect_swapped (quit_button, "clicked", G_CALLBACK (gtk_window_destroy), window); + gtk_box_append (GTK_BOX (vbox), quit_button); + + gtk_window_present (GTK_WINDOW (window)); +} + +int main (int argc, char **argv) +{ + GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + int status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + return status; +} diff --git a/20231102/gtk-06a.c b/20231102/gtk-06a.c new file mode 100644 index 0000000..46e02a5 --- /dev/null +++ b/20231102/gtk-06a.c @@ -0,0 +1,55 @@ +#include <gtk/gtk.h> + +static void draw (GtkDrawingArea *drawing_area, cairo_t *c, + int width, int height, gpointer user_data) +{ + printf ("draw()\n"); + + GdkRGBA red = { 1.0, 0.0, 0.0, 0.8 }; + GdkRGBA yellow = { 1.0, 1.0, 0.0, 0.6 }; + GdkRGBA blue = { 0.0, 0.5, 1.0, 0.4 }; + + gdk_cairo_set_source_rgba (c, &red); + cairo_rectangle (c, 10, 10, 60, 40); + cairo_fill (c); + + gdk_cairo_set_source_rgba (c, &yellow); + cairo_arc (c, 65, 50, 30, 0, 2 * G_PI); + cairo_fill (c); + + gdk_cairo_set_source_rgba (c, &blue); + cairo_move_to (c, 10, 70); + cairo_line_to (c, 70, 70); + cairo_line_to (c, 40, 18); + cairo_close_path (c); + cairo_fill (c); +} + +static void activate (GtkApplication *app, gpointer user_data) +{ + GtkWidget *window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "Hello"); + + GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5); + gtk_window_set_child (GTK_WINDOW (window), vbox); + + GtkWidget *drawing_area = gtk_drawing_area_new (); + gtk_widget_set_size_request (drawing_area, 100, 100); + gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (drawing_area), draw, NULL, NULL); + gtk_box_append (GTK_BOX (vbox), drawing_area); + + GtkWidget *quit_button = gtk_button_new_with_label ("Quit"); + g_signal_connect_swapped (quit_button, "clicked", G_CALLBACK (gtk_window_destroy), window); + gtk_box_append (GTK_BOX (vbox), quit_button); + + gtk_window_present (GTK_WINDOW (window)); +} + +int main (int argc, char **argv) +{ + GtkApplication *app = gtk_application_new ("de.hs-bochum.cvh.hp.hello-gtk", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); + int status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + return status; +} diff --git a/20231102/hp-20231102.txt b/20231102/hp-20231102.txt new file mode 100644 index 0000000..7b7825a --- /dev/null +++ b/20231102/hp-20231102.txt @@ -0,0 +1,35 @@ +"Output" +~~~~~~~~ +AND + 10101100 A + & 11111011 Bit gezielt löschen & B "Maske" + -------- --- + 10101000 A, außer dort, wo B Nullen hat + Dort sind es Nullen. +OR + 10101100 A + | 00000010 Bit gezielt setzen & B "Maske" + -------- --- + 10101110 A, außer dort, wo B Einsen hat + Dort sind es Einsen. +XOR + 10101100 A + ^ 00000010 Bit gezielt umklappen & B "Maske" + -------- --- + 10101110 A, außer dort, wo B Einsen hat + Dort wird A umgeklappt. + 00000010 + ^ 00001000 + -------- + 00001010 + +"Input" +~~~~~~~ +AND + 10101100 + & 00000100 + -------- + 00000100 <-- ungleich 0: Bit war gesetzt + + Achtung: Das Ergebnis ist nicht gleich 1! + (sondern: gleich 4) diff --git a/20231102/inttypes-01.c b/20231102/inttypes-01.c new file mode 100644 index 0000000..199cc8c --- /dev/null +++ b/20231102/inttypes-01.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + uint64_t a = 2^14; + printf ("a = %d\n", a); + return 0; +} diff --git a/20231102/inttypes-02.c b/20231102/inttypes-02.c new file mode 100644 index 0000000..db5f57a --- /dev/null +++ b/20231102/inttypes-02.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + uint64_t a = 2^14; + printf ("a = %ld\n", a); + return 0; +} diff --git a/20231102/inttypes-03.c b/20231102/inttypes-03.c new file mode 100644 index 0000000..7510627 --- /dev/null +++ b/20231102/inttypes-03.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <stdint.h> +#include <inttypes.h> + +int main (void) +{ + uint64_t a = 2^14; + printf ("a = %" PRIu64 "\n", a); + return 0; +} diff --git a/20231102/libraries-01.txt b/20231102/libraries-01.txt new file mode 100644 index 0000000..a62d99c --- /dev/null +++ b/20231102/libraries-01.txt @@ -0,0 +1,10 @@ +cassini/home/peter/bo/2023ws/hp/20231102> ar rs libanswer.a answer.o +ar: creating libanswer.a +cassini/home/peter/bo/2023ws/hp/20231102> ls -l libanswer.a +-rw-r--r-- 1 peter peter 1232 2. Nov 14:45 libanswer.a +cassini/home/peter/bo/2023ws/hp/20231102> gcc -Wall -O philosophy.c -lanswer -o philosophy /usr/bin/ld: cannot find -lanswer: Datei oder Verzeichnis nicht gefunden +collect2: error: ld returned 1 exit status +cassini/home/peter/bo/2023ws/hp/20231102> gcc -L . -Wall -O philosophy.c -lanswer -o philosophy +cassini/home/peter/bo/2023ws/hp/20231102> ./philosophy +The answer is 23. +cassini/home/peter/bo/2023ws/hp/20231102> diff --git a/20231102/number-systems-01.c b/20231102/number-systems-01.c new file mode 100644 index 0000000..791b2f4 --- /dev/null +++ b/20231102/number-systems-01.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main (void) +{ + int number[] = { 01, 02, 03, 04, 05, 06, 07, 08, 09, 10 }; // Achtung: Oktalzahlen! + for (int i = 0; i < 10; i++) + printf ("%d\n", number[i]); + return 0; +} diff --git a/20231102/number-systems-02.c b/20231102/number-systems-02.c new file mode 100644 index 0000000..958ef95 --- /dev/null +++ b/20231102/number-systems-02.c @@ -0,0 +1,12 @@ +#include <stdio.h> + +int main (void) +{ + int number[] = { 023, 025, 027, // Achtung: Oktalzahlen! + 033, 035, 037, + 123, 125, 127, + 133, 135, 137 }; + for (int i = 0; i < 12; i++) + printf ("%d\n", number[i]); + return 0; +} diff --git a/20231102/philosophy.c b/20231102/philosophy.c new file mode 100644 index 0000000..e9f508a --- /dev/null +++ b/20231102/philosophy.c @@ -0,0 +1,8 @@ +#include <stdio.h> +#include "answer.h" + +int main (void) +{ + printf ("The answer is %d.\n", answer ()); + return 0; +} -- GitLab