From 854753d9cb55ace0a367c2d2eb9ed31f69b2a051 Mon Sep 17 00:00:00 2001
From: Peter Gerwinski <peter.gerwinski@hs-bochum.de>
Date: Tue, 30 May 2023 12:31:08 +0200
Subject: [PATCH] =?UTF-8?q?C-Programme=20f=C3=BCr=20Morse-Tabellen,=2030.5?=
 =?UTF-8?q?.2023?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 20230530/morse-02.c | 99 +++++++++++++++++++++++++++++++++++++++++++++
 20230530/morse-03.c | 53 ++++++++++++++++++++++++
 20230530/morse-04.c | 62 ++++++++++++++++++++++++++++
 3 files changed, 214 insertions(+)
 create mode 100644 20230530/morse-02.c
 create mode 100644 20230530/morse-03.c
 create mode 100644 20230530/morse-04.c

diff --git a/20230530/morse-02.c b/20230530/morse-02.c
new file mode 100644
index 0000000..85fb671
--- /dev/null
+++ b/20230530/morse-02.c
@@ -0,0 +1,99 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+
+static const char *morse[256] = {
+  ['0'] = "-----",
+  ['1'] = ".----",
+  ['2'] = "..---",
+  ['3'] = "...--",
+  ['4'] = "....-",
+  ['5'] = ".....",
+  ['6'] = "-....",
+  ['7'] = "--...",
+  ['8'] = "---..",
+  ['9'] = "----.",
+  ['A'] = ".-",
+  ['B'] = "-...",
+  ['C'] = "-.-.",
+  ['D'] = "-..",
+  ['E'] = ".",
+  ['F'] = "..-.",
+  ['G'] = "--.",
+  ['H'] = "....",
+  ['I'] = "..",
+  ['J'] = ".---",
+  ['K'] = "-.-",
+  ['L'] = ".-..",
+  ['M'] = "--",
+  ['N'] = "-.",
+  ['O'] = "---",
+  ['P'] = ".--.",
+  ['Q'] = "--.-",
+  ['R'] = ".-.",
+  ['S'] = "...",
+  ['T'] = "-",
+  ['U'] = "..-",
+  ['V'] = "...-",
+  ['W'] = ".--",
+  ['X'] = "-..-",
+  ['Y'] = "-.--",
+  ['Z'] = "--..",
+  ['a'] = ".-",
+  ['b'] = "-...",
+  ['c'] = "-.-.",
+  ['d'] = "-..",
+  ['e'] = ".",
+  ['f'] = "..-.",
+  ['g'] = "--.",
+  ['h'] = "....",
+  ['i'] = "..",
+  ['j'] = ".---",
+  ['k'] = "-.-",
+  ['l'] = ".-..",
+  ['m'] = "--",
+  ['n'] = "-.",
+  ['o'] = "---",
+  ['p'] = ".--.",
+  ['q'] = "--.-",
+  ['r'] = ".-.",
+  ['s'] = "...",
+  ['t'] = "-",
+  ['u'] = "..-",
+  ['v'] = "...-",
+  ['w'] = ".--",
+  ['x'] = "-..-",
+  ['y'] = "-.--",
+  ['z'] = "--.."
+};
+
+int main (void)
+{
+  for (int c = 0; c < 128; c++)
+    {
+      uint8_t bits = 0;
+      uint8_t mask = 1;
+      const char *p = morse[c];
+      if (p)
+        {
+          while (*p)
+            {
+              if (*p == '-')
+                bits |= mask;
+              mask <<= 1;
+              p++;
+            }
+        }
+      printf (" 0x%02x,", bits);
+    }
+  printf ("\n");
+  for (int c = 0; c < 128; c++)
+    {
+      const char *p = morse[c];
+      if (p)
+        printf (" %zu,", strlen (p));
+      else
+        printf (" 0,");
+    }
+  printf ("\n");
+}
diff --git a/20230530/morse-03.c b/20230530/morse-03.c
new file mode 100644
index 0000000..e19e076
--- /dev/null
+++ b/20230530/morse-03.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <stdint.h>
+
+uint8_t morse_bits[128] =
+{
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x1f, 0x1e, 0x1c, 0x18, 0x10, 0x00, 0x01, 0x03,
+  0x07, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x02, 0x01, 0x05, 0x01, 0x00, 0x04, 0x03,
+  0x00, 0x00, 0x0e, 0x05, 0x02, 0x03, 0x01, 0x07,
+  0x06, 0x0b, 0x02, 0x00, 0x01, 0x04, 0x08, 0x06,
+  0x09, 0x0d, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
+  0x00, 0x02, 0x01, 0x05, 0x01, 0x00, 0x04, 0x03,
+  0x00, 0x00, 0x0e, 0x05, 0x02, 0x03, 0x01, 0x07,
+  0x06, 0x0b, 0x02, 0x00, 0x01, 0x04, 0x08, 0x06,
+  0x09, 0x0d, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+uint8_t morse_length[128] =
+{
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+  5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0,
+  0, 2, 4, 4, 3, 1, 4, 3, 4, 2, 4, 3, 4, 2, 2, 3,
+  4, 4, 3, 3, 1, 3, 4, 3, 4, 4, 4, 0, 0, 0, 0, 0,
+  0, 2, 4, 4, 3, 1, 4, 3, 4, 2, 4, 3, 4, 2, 2, 3,
+  4, 4, 3, 3, 1, 3, 4, 3, 4, 4, 4, 0, 0, 0, 0, 0
+};
+
+int main (void)
+{
+  for (int c = 0; c < 128; c++)
+    if (morse_length[c])
+      {
+        printf ("  ['%c'] = \"", c);
+        uint8_t bits = morse_bits[c];
+        uint8_t mask = 1;
+        int l = morse_length[c];
+        for (int i = 0; i < l; i++)
+          if (bits & mask)
+            printf ("-");
+          else
+            printf (".");
+        printf ("\",\n");
+      }
+  return 0;
+}
diff --git a/20230530/morse-04.c b/20230530/morse-04.c
new file mode 100644
index 0000000..a6a7345
--- /dev/null
+++ b/20230530/morse-04.c
@@ -0,0 +1,62 @@
+  ['0'] = "-----",
+  ['1'] = ".....",
+  ['2'] = ".....",
+  ['3'] = ".....",
+  ['4'] = ".....",
+  ['5'] = ".....",
+  ['6'] = "-----",
+  ['7'] = "-----",
+  ['8'] = "-----",
+  ['9'] = "-----",
+  ['A'] = "..",
+  ['B'] = "----",
+  ['C'] = "----",
+  ['D'] = "---",
+  ['E'] = ".",
+  ['F'] = "....",
+  ['G'] = "---",
+  ['H'] = "....",
+  ['I'] = "..",
+  ['J'] = "....",
+  ['K'] = "---",
+  ['L'] = "....",
+  ['M'] = "--",
+  ['N'] = "--",
+  ['O'] = "---",
+  ['P'] = "....",
+  ['Q'] = "----",
+  ['R'] = "...",
+  ['S'] = "...",
+  ['T'] = "-",
+  ['U'] = "...",
+  ['V'] = "....",
+  ['W'] = "...",
+  ['X'] = "----",
+  ['Y'] = "----",
+  ['Z'] = "----",
+  ['a'] = "..",
+  ['b'] = "----",
+  ['c'] = "----",
+  ['d'] = "---",
+  ['e'] = ".",
+  ['f'] = "....",
+  ['g'] = "---",
+  ['h'] = "....",
+  ['i'] = "..",
+  ['j'] = "....",
+  ['k'] = "---",
+  ['l'] = "....",
+  ['m'] = "--",
+  ['n'] = "--",
+  ['o'] = "---",
+  ['p'] = "....",
+  ['q'] = "----",
+  ['r'] = "...",
+  ['s'] = "...",
+  ['t'] = "-",
+  ['u'] = "...",
+  ['v'] = "....",
+  ['w'] = "...",
+  ['x'] = "----",
+  ['y'] = "----",
+  ['z'] = "----",
-- 
GitLab