Skip to content
Snippets Groups Projects
Commit 207cfcb5 authored by poulpe's avatar poulpe
Browse files

First commit

parents
No related branches found
No related tags found
No related merge requests found
*.o
Exe
tests
Makefile 0 → 100644
CC = gcc
CFLAGS = -std=c11 -Wall -Wextra -Wpedantic -Wwrite-strings -Walloc-zero -Wparentheses -Wlarger-than=10000 -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -fsanitize=address
CFLAGS += -g -pedantic -fsanitize=address -fsanitize=leak -fsanitize=undefined
LDFLAGS = -lm
OBJECTS = $(patsubst %.c, %.o, $(wildcard *.c))
OBJECTS_TEST = $(patsubst %.c, %.o, $(wildcard tests/*.c))
OBJECTS_MUNIT = $(patsubst %.c, %.o, $(filter-out example.c , tests/munit/*.c))
OBJECTS_SRC := $(patsubst %.c, %.o, $(filter-out main.c, $(wildcard *.c)))
############# COMMAND HELP #############
# $(wildcard *.o) // Find all .o files
# $(SOURCES:.c=.o) // Compile with implicit compilation rules all .c
# $(patsubst %.c, %.o, $(wildcard *.o)) // Find all .c and compil with rules to .o
# pat(tern) subst(itution)
# $^ = all element
# $< = first element
# $@ = name of rules
########################################
PROG = Exe
TEST = test
all: $(PROG) $(TEST)
$(PROG): $(OBJECTS)
$(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
$(TEST): $(OBJECTS_SRC) $(OBJECTS_TEST) $(OBJECTS_MUNIT)
$(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
@./$(TEST)
main.o : main.c # Specifie rules main.o
tree.o : tree.h
# PHONY for function with no file generated
.PHONY: clean
clean :
rm -f *.o $(PROG) $(TEST)
rebuild : clean $(PROG) $(TEST)
\ No newline at end of file
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--..
\ No newline at end of file
main.c 0 → 100644
#include <stdio.h>
#include "morse.h"
int main(int argc, char** argv) {
arbre tree = arbre_build("code-morse.txt");
exit(0);
// print(tree,1); // impression de l'arbre
// if (2 == argc) {
// decoder_fichier(argv[1],tree);
// printf("\n");
// }
// char alphabet_morse[26][6];
// table_build("code-morse.txt",26,6,alphabet_morse);
// if (3 == argc) {
// encoder_fichier(argv[2],26,6,alphabet_morse);
// printf("\n");
// }
return 0;
}
\ No newline at end of file
morse.c 0 → 100644
#include "morse.h"
typedef struct node
{
char lettre;
struct node *child[2]; //0 pour le trait, 1 pour le point
} node;
//----------------------------------------------------------
// procedure imprimant l'arbre verticalement de mani�re --
// selon un parcours DRG (trait - racine - point) --
//----------------------------------------------------------
void print(arbre tree, int niv)
{
}
//----------------------------------------------------------
// procedure traduisant un code morse en lettre --
//----------------------------------------------------------
char decoder(char *code, arbre tree)
{
arbre tmp = tree;
uint32_t len = strlen(code);
for (uint32_t i = 0; i < len; i += 1)
{
tmp = tmp->child[(code[i] == '.') ? 0 : 1];
}
return tmp->lettre;
}
//-----------------------------------------------------------
// lit un fichier encod� avec le code et imprime � l'�cran --
// le texte d�cod� --
//-----------------------------------------------------------
void decoder_fichier(char *filename, arbre tree)
{
// lecture d'un mot de caract�res dans 'A'..'Z'
FILE *fp = fopen(filename, "r");
assert(NULL != fp);
int lg = 0;
char code[6];
while (!feof(fp))
{
char ch = (char)fgetc(fp);
switch (ch)
{
//� compl�ter
}
}
fclose(fp);
}
//-----------------------------------------------------------
// lit un fichier encod� avec le code et imprime � l'�cran --
// le texte d�cod� --
//-----------------------------------------------------------
void encoder_fichier(char *filename, int n, int m, char alphabet_morse[n][m])
{
// lecture d'un mot de caract�res dans 'A'..'Z'
FILE *fp = fopen(filename, "r");
assert(NULL != fp);
int lg = 0;
char code[6];
while (!feof(fp))
{
char ch = (char)fgetc(fp);
switch (ch)
{
//� compl�ter
}
}
fclose(fp);
}
//------------------------------------------------------------------
// procedure ins�rant une lettre d�finie par son code morse dans --
// l'arbre. L'arbre est construit au fur et � mesure des besoins. --
//------------------------------------------------------------------
void placer(char *chaine, arbre *tree)
{
arbre tmp = *tree;
int length = strlen(chaine);
// � compl�ter
tmp->lettre = chaine[0];
}
//----------------------------------------------------------
// procedure lisant le fichier code-morse.txt et cr�ant --
// le tableau � deux dimensions correspondant --
//----------------------------------------------------------
void table_build(char *filename, int n, int m, char alphabet_morse[n][m])
{
FILE *fp = fopen(filename, "r");
assert(NULL != fp);
// � compl�ter
fclose(fp);
}
//----------------------------------------------------------
// procedure lisant le fichier code-morse.txt et cr�ant --
// l'arbre binaire correspondant --
//----------------------------------------------------------
arbre arbre_build(char *filename)
{
arbre tree = calloc(1, sizeof(node));
tree->lettre = '?';
FILE *fp = fopen(filename, "r");
assert(NULL != fp);
char line[100];
while (!feof(fp))
{
arbre tmp_ptr = tree;
fgets(line, 100, fp);
char cur_char = line[0];
char *morse = calloc(strlen(line), sizeof(char));
sprintf(morse, "%s", line + 1);
printf("%c : %s : %d\n", cur_char, morse,strlen(morse));
for(uint32_t i=0;i<strlen(morse)-1;i+=1)
{
uint8_t pos = (morse[i] == '-')?1:0;
if(tmp_ptr->child[pos] == NULL)
{
tmp_ptr->child[pos] = calloc(1, sizeof(node));
tmp_ptr = tmp_ptr->child[pos];
tmp_ptr->lettre = '?';
}
else
{
tmp_ptr = tmp_ptr->child[pos];
}
}
printf("Save value : '%c' in addr : %p\n",cur_char,tmp_ptr->lettre);
tmp_ptr->lettre = cur_char;
free(morse);
}
fclose(fp);
return tree;
}
// arbre arbre_build(char *filename)
// {
// arbre tree = calloc(1, sizeof(node));
// tree->lettre = '?';
// FILE *fp = fopen(filename, "r");
// assert(NULL != fp);
// char current_letter = fgetc(fp);
// char debug_str[10];
// uint8_t i = 0;
// arbre tmp_ptr = tree;
// while (!feof(fp))
// {
// char tmp_c = fgetc(fp);
// debug_str[i] = tmp_c;
// if (tmp_c == '\n')
// {
// tmp_ptr->lettre = current_letter;
// printf("Current letr : %c\n", tmp_ptr->lettre);
// printf("Pattern morse : %s\n", debug_str);
// i = 0;
// tmp_ptr = tree;
// current_letter = fgetc(fp);
// tmp_c = fgetc(fp);
// }
// uint8_t pos = (tmp_c == '-') ? true : false;
// tmp_ptr->child[pos] = calloc(1, sizeof(node));
// tmp_ptr->lettre = '?';
// tmp_ptr = tmp_ptr->child[pos];
// i += 1;
// }
// fclose(fp);
// return tree;
// }
morse.h 0 → 100644
#ifndef _HEADER_MORSE
#define _HEADER_MORSE
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
struct node;
typedef struct node* arbre;
arbre arbre_build(char* filename);
void print(arbre tree,int niv);
//----------------------------------------------------------
// procedure traduisant un code morse en lettre --
//----------------------------------------------------------
char decoder(char* code,arbre tree);
//-----------------------------------------------------------
// lit un fichier encod� avec le code et imprime � l'�cran --
// le texte d�cod� --
//-----------------------------------------------------------
void decoder_fichier(char* filename,arbre tree);
//-----------------------------------------------------------
// lit un fichier encod� avec le code et imprime � l'�cran --
// le texte d�cod� --
//-----------------------------------------------------------
void encoder_fichier(char* filename,int n,int m,char alphabet_morse[n][m]);
//------------------------------------------------------------------
// procedure ins�rant une lettre d�finie par son code morse dans --
// l'arbre. L'arbre est construit au fur et � mesure des besoins. --
//------------------------------------------------------------------
void placer(char* chaine,arbre* tree);
//----------------------------------------------------------
// procedure lisant le fichier code-morse.txt et cr�ant --
// le tableau � deux dimensions correspondant --
//----------------------------------------------------------
void table_build(char* filename,int n,int m,char alphabet_morse[n][m]);
#endif
\ No newline at end of file
. -. /.. -. ..-. --- .-. -- .- - .. --.- ..- . /..- -. /.- .-. -... .-. . /-... .. -. .- .. .-. . /. ... - /..- -. . /... - .-. ..- -.-. - ..- .-. . /-.. . /-.. --- -. -. . . ... /--.- ..- .. /.--. . ..- - /... . /.-. . .--. .-. . ... . -. - . .-. /... --- ..- ... /.-.. .- /..-. --- .-. -- . /-.. /..- -. . /.... .. . .-. .- .-. -.-. .... .. . /-.. --- -. - /-.-. .... .- --.- ..- . /. .-.. . -- . -. - /. ... - /.- .--. .--. . .-.. . /-. --- . ..- -.. /.-.. . /-. --- . ..- -.. /.. -. .. - .. .- .-.. /. - .- -. - /.- .--. .--. . .-.. . /.-. .- -.-. .. -. . /
-.. .- -. ... /..- -. /.- .-. -... .-. . /-... .. -. .- .. .-. . /-.-. .... .- --.- ..- . /. .-.. . -- . -. - /.--. --- ... ... . -.. . /.- ..- /.--. .-.. ..- ... /-.. . ..- -..- /. .-.. . -- . -. - ... /..-. .. .-.. ... /.- ..- /-. .. ...- . .- ..- /.. -. ..-. . .-. .. . ..- .-. /.... .- -... .. - ..- . .-.. .-.. . -- . -. - /.- .--. .--. . .-.. . ... /--. .- ..- -.-. .... . /. - /-.. .-. --- .. - /
-.. ..- /.--. --- .. -. - /-.. . /...- ..- . /-.. . /-.-. . ... /. .-.. . -- . -. - ... /..-. .. .-.. ... /.-.. /. .-.. . -- . -. - /-.. --- -. - /.. .-.. ... /... --- -. - /.. ... ... ..- ... /.- ..- /-. .. ...- . .- ..- /... ..- .--. . .-. .. . ..- .-. /. ... - /.- .--. .--. . .-.. . /.--. . .-. . /
.- ..- /-. .. ...- . .- ..- /.-.. . /.--. .-.. ..- ... /. .-.. . ...- . /.. .-.. /-.-- /.- /-.. --- -. -.-. /..- -. /-. --- . ..- -.. /.-. .- -.-. .. -. . /
.- ..- /-. .. ...- . .- ..- /-.. .. .-. . -.-. - . -- . -. - /.. -. ..-. . .-. .. . ..- .-. /.. .-.. /-.-- /.- /.- ..- /.--. .-.. ..- ... /-.. . ..- -..- /-. --- . ..- -.. ... /..-. .. .-.. ... /
. -. /-.-. --- -. - .. -. ..- .- -. - /.- /-.. . ... -.-. . -. -.. .-. . /.- ..- -..- /-. .. ...- . .- ..- -..- /.. -. ..-. . .-. .. . ..- .-. ... /--- -. /.--. . ..- - /. -. /.- ...- --- .. .-. /--.- ..- .- - .-. . /.--. ..- .. ... /.... ..- .. - /... . .. --.. . /. - -.-. /-.-. /. ... - /.- /-.. .. .-. . /.-.. .- /... ..- .. - . /-.. . ... /.--. ..- .. ... ... .- -. -.-. . ... /-.. . /-.. . ..- -..- /
..- -. /-. --- . ..- -.. /-. /.- -.-- .- -. - /.- ..- -.-. ..- -. /..-. .. .-.. ... /. ... - /.- .--. .--. . .-.. . /..-. . ..- .. .-.. .-.. . /
.-.. . /-. --- -- -... .-. . /-.. . /-. .. ...- . .- ..- -..- /- --- - .- .-.. /.- ..- - .-. . -- . -. - /-.. .. - /.-.. .- /-.. .. ... - .- -. -.-. . /. -. - .-. . /.-.. .- /..-. . ..- .. .-.. .-.. . /.-.. .- /.--. .-.. ..- ... /. .-.. --- .. --. -. . . /. - /.-.. .- /.-. .- -.-. .. -. . /. ... - /.- .--. .--. . .-.. . . /.... .- ..- - . ..- .-. /-.. . /.-.. /.- .-. -... .-. . /
.-.. . /-. .. ...- . .- ..- /-.. /..- -. /-. --- . ..- -.. /. ... - /.- .--. .--. . .-.. . /.--. .-. --- ..-. --- -. -.. . ..- .-. /
.-.. . ... /.- .-. -... .-. . ... /-... .. -. .- .. .-. . ... /.--. . ..- ...- . -. - /-. --- - .- -- -- . -. - /. - .-. . /..- - .. .-.. .. ... . ... /. -. /- .- -. - /--.- /.- .-. -... .-. . /-... .. -. .- .. .-. . /-.. . /.-. . -.-. .... . .-. -.-. .... . /--- ..- /. -. /- .- -. - /--.- ..- . /- .- ... /-... .. -. .- .. .-. . /
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment