Encode text messages into Morse code and decode them using a binary search tree (AVL tree) structure. It supports customizable encoding options, including separators and prosigns, to facilitate Morse code transmission and decoding.
- Initialize and destroy Morse code binary trees.
- Encode strings into Morse code with configurable options.
- Support for Morse separators (spaces between characters and words).
- Support for prosigns such as "
SK", "AR", and "CT" for special transmission signals. - Uses an AVL tree for efficient character lookup and encoding based on Morse priority.
morse_tree_td. An AVL binary search tree representing Morse code characters and their encoding.
Create a new Morse code tree:
morse_tree_td *morse_tree = morse_init();
if (morse_tree == NULL) {
/* Handle error */
}
Encode an ASCII string into Morse code:
char encoded[MORSE_MESSAGE_MAX_LENGTH];
const char *inpupt = "Hello, World";
if (morse_encode(morse_tree, morse_message, input,
MORSE_USE_SEPARATORS | MORSE_USE_PROSIGNS) != 0) {
fprintf(stderr, "Encoding failed\n");
morse_destroy(morse_tree);
return -1;
}
printf("Encoded: %s\n", encoded);
Decode a Morse code string into ASCII:
char decoded[MORSE_MESSAGE_MAX_LENGTH + 1] = {'\0'};
const char *input = "... --- ... .- .-."; /* "SOS AR" */
if (morse_decode(morse_tree, decoded, input, MORSE_USE_SEPARATORS) != 0) {
fprintf(stderr, "Decoding failed\n");
morse_destroy(morse_tree);
return -1;
}
printf("Decoded: '%s'\n", decoded);
MORSE_NO_FLAGS. No special features.MORSE_USE_SEPARATORS. Use spaces to separate characters and words.MORSE_USE_PROSIGNS. Include prosigns like "AR", "SK", "CT" at start and end.
Destroy the Morse tree when done:
morse_destroy(morse_tree);
MORSE_MAX_NODES. Maximum number of nodes in the Morse tree.MORSE_MESSAGE_MAX_LENGTH. Maximum length of the Morse message.MORSE_DIT/MORSE_DAH. Representations of dot ("dit") and dash ("dah").- Separator constants. Define spacing between characters and words.
- Prosigns. Special Morse signals such as "
AR", "SK", "CT".
- The Morse tree is organized according to Morse code priority, stored as an AVL tree for efficient encoding.
- Supports encoding of alphabetic characters, digits, and some punctuation.
- Punctuation characters are ignored in tree construction but influence insertion order.
- ISC License
- Copyright (c) 2025, J. A. Corbal
- Read the file
LICENSEfor more details