This commit is contained in:
Debucquoy 2023-10-18 20:27:40 +02:00
parent 4de4dcf2c2
commit b0f02b0d5d
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
29 changed files with 700 additions and 2 deletions

11
.gitignore vendored
View File

@ -1,3 +1,14 @@
__pycache__/
*.tar
*.class
*.toc
*.synctex.gz
*.snm
*.out
*.aux
*.fbd_latexmk
*.fls
*.log
*.nav
*.fdb_latexmk
a.out

@ -0,0 +1 @@
Subproject commit 4eda91b63722ddfc928d4f88a2e913d0f2fcdcd1

View File

@ -0,0 +1,49 @@
% Copyright 2009 by C. Troestler <Christophe.Troestler@umons.ac.be>
% This file is under GNU GPL v3 or later.
\mode<presentation>
\definecolor{umons-red}{RGB}{168, 0, 57}
\definecolor{umons-turquoise}{RGB}{0, 171, 204}
\definecolor{umons-gray}{RGB}{150, 150, 150}
\setbeamercolor{alerted text}{fg=umons-red}
\setbeamercolor*{palette primary}{fg=black, bg=umons-turquoise}
\setbeamercolor*{palette secondary}{fg=black, bg=umons-turquoise}
\setbeamercolor*{palette tertiary}{fg=umons-gray!30, bg=umons-red!80!black}
\setbeamercolor*{palette quaternary}{fg=black, bg=umons-gray!15}
\setbeamercolor*{upper separation line head left}{parent=palette tertiary}
\setbeamercolor*{upper separation line head right}{parent=palette primary}
\setbeamercolor{title}{fg=umons-red}
%\setbeamercolor*{titlelike}{fg=umons-red}
\setbeamercolor{frametitle}{fg=umons-red, bg=white}
\setbeamercolor{frametitle right}{bg=yellow!60!orange}
\setbeamercolor{structure}{fg=umons-turquoise}
\setbeamercolor{block title}{fg=umons-turquoise, bg=umons-gray!30}
\setbeamercolor{block body}{fg=black, bg=umons-gray!15}
\setbeamercolor{block title example}{fg=black, bg=umons-gray!30}
\setbeamercolor{block body example}{fg=black, bg=umons-gray!15}
\setbeamercolor{block title alerted}{fg=white, bg=umons-red}
\setbeamercolor{block body alerted}{fg=black, bg=umons-red!10}
\setbeamercolor{itemize subitem}{fg=umons-gray}
\setbeamercolor*{separation line}{}
\setbeamercolor*{fine separation line}{}
\setbeamercolor*{sidebar}{fg=umons-red,bg=orange!75!white}
\setbeamercolor*{sidebar}{fg=umons-red,bg=orange!75!white}
\setbeamercolor*{palette sidebar primary}{fg=umons-red!10!black}
\setbeamercolor*{palette sidebar secondary}{fg=white}
\setbeamercolor*{palette sidebar tertiary}{fg=umons-red!50!black}
\setbeamercolor*{palette sidebar quaternary}{fg=yellow!10!orange}
\mode
<all>

View File

@ -0,0 +1,91 @@
% Based on the "infolines" outer theme.
\newif\ifbeamer@UMONS@navigation
\beamer@UMONS@navigationfalse
\DeclareOptionBeamer{navigation}[true]{%
\csname beamer@UMONS@navigation#1\endcsname}
\newif\ifbeamer@UMONS@nosubsection
\beamer@UMONS@nosubsectionfalse
\DeclareOptionBeamer{no-subsection}[true]{%
\csname beamer@UMONS@nosubsection#1\endcsname}
\newif\ifbeamer@UMONS@nototalframenumber
\beamer@UMONS@nototalframenumberfalse
\DeclareOptionBeamer{no-totalframenumber}[true]{%
\csname beamer@UMONS@nototalframenumber#1\endcsname}
\ProcessOptionsBeamer
\mode<presentation>
\setbeamercolor*{author in head/foot}{parent=palette tertiary}
\setbeamercolor*{title in head/foot}{parent=palette secondary}
\setbeamercolor*{date in head/foot}{parent=palette primary}
\setbeamercolor*{section in head/foot}{parent=palette quaternary}
\setbeamercolor*{subsection in head/foot}{parent=palette primary}
\defbeamertemplate*{footline}{UMONS theme}
{
\leavevmode%
\hbox{%
% Left box (author and institute)
\begin{beamercolorbox}[wd=.25\paperwidth,ht=2.25ex,dp=1ex,center]{%
author in head/foot}%
\usebeamerfont{author in head/foot}%
\insertshortauthor
\beamer@ifempty{\insertshortinstitute}{}{~~\insertshortinstitute}%
\end{beamercolorbox}%
% Central box (presentation title)
\begin{beamercolorbox}[wd=.52\paperwidth,ht=2.25ex,dp=1ex,center]{%
title in head/foot}%
\usebeamerfont{title in head/foot}\insertshorttitle
\end{beamercolorbox}%
% Right box (date and pages)
\begin{beamercolorbox}[wd=.23\paperwidth,ht=2.25ex,dp=1ex,right]{%
date in head/foot}%
\usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
\insertframenumber
\ifbeamer@UMONS@nototalframenumber\else ~/~\inserttotalframenumber\fi
\hspace*{2ex}
\end{beamercolorbox}}%
\vskip0pt%
}
\defbeamertemplate*{headline}{UMONS theme}
{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=.25\paperwidth,ht=1ex,dp=0ex]{%
upper separation line head left}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.75\paperwidth,ht=1ex,dp=0ex]{%
upper separation line head right}%
\end{beamercolorbox}}%
\vskip0pt
\ifbeamer@UMONS@navigation
\begin{beamercolorbox}[colsep=1.5pt]{upper separation line head}
\end{beamercolorbox}%
% Box for section titles and possibly subtitles (for fast navigation)
\begin{beamercolorbox}{section in head/foot}
\ifbeamer@UMONS@nosubsection
\insertsectionnavigationhorizontal{\paperwidth}{%
\vspace*{2pt}}{\vspace*{2pt}}%
\else
\vspace*{2pt}\insertnavigation{\paperwidth}\vspace*{2pt}%
\fi
\end{beamercolorbox}%
\begin{beamercolorbox}[colsep=1.5pt]{lower separation line head}
\end{beamercolorbox}%
\fi
}
\setbeamertemplate{mini frames}[box]
\setbeamersize{text margin left=1em,text margin right=1em}
\mode
<all>

View File

@ -0,0 +1,30 @@
% Copyright 2009 by C. Troestler <Christophe.Troestler@umons.ac.be>
% This file is under GNU GPL v3 or later.
\mode<presentation>
% Display a navigation bar
\def\beamer@themeUMONS@navigation{false}
\DeclareOptionBeamer{navigation}[true]{%
\def\beamer@themeUMONS@navigation{#1}}
% Do not display "boxes" to go to subsections in the navigation bar.
\def\beamer@themeUMONS@nosubsection{false}
\DeclareOptionBeamer{no-subsection}[true]{%
\def\beamer@themeUMONS@nosubsection{#1}}
% Do not display the total number of pages.
\def\beamer@themeUMONS@nototalframenumber{false}
\DeclareOptionBeamer{no-totalframenumber}[true]{%
\def\beamer@themeUMONS@nototalframenumber{#1}}
\ProcessOptionsBeamer
\useinnertheme{rectangles}
\usecolortheme{UMONS}
\useoutertheme[navigation=\beamer@themeUMONS@navigation,
no-subsection=\beamer@themeUMONS@nosubsection,
no-totalframenumber=\beamer@themeUMONS@nototalframenumber]{UMONS}
\mode<all>

BIN
bac2/latex/lesson3.pdf Normal file

Binary file not shown.

81
bac2/latex/lesson3.tex Normal file
View File

@ -0,0 +1,81 @@
\documentclass{beamer}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{amsmath, amsfonts, amssymb, amsthm}
\usetheme{Umons}
\title{Un petit exemple de Beamer}
\author{Debucquoy Anthony}
\institute{Universit\'e de Mons}
\section{Figure}
\section{Formules math\'ematiques disponibles}
\section{Sur deux colonnes}
\begin{document}
\begin{frame}[t]
\maketitle
\end{frame}
\begin{frame}[t]
\frametitle{Table des mati\'eres}
\tableofcontents
\end{frame}
\begin{frame}[t]
\frametitle{Pentagone}
\framesubtitle{Un pentagone est un polygone \`a cinq sommets et cinq cot\'es.}
\begin{block}{Pentagone r\'egulier}
Un pentagone r\'egulier est un pentagone dont tous les cot\'es sont de m\^eme longeur et dont tous les angles internes valent 108 degr\'es.
\end{block}
\begin{block}{Construction d'un pentagone r\'egulier avec Tikz}
On demande:
\begin{itemize}
\item que les cot\'es du pentagone mesurent 1.5 centim\`etre
\item Que le pentagone soit colori\'e en gris
\begin{center}
\begin{tikzpicture}[scale=1, transform shape]
\fill[gray] (0*360/5:1) -- (1*360/5:1) -- (2*360/5:1) -- (3*360/5:1) -- (4*360/5:1) -- cycle;
\draw (0*360/5:1) -- (1*360/5:1) -- (2*360/5:1) -- (3*360/5:1) -- (4*360/5:1) -- cycle;
\end{tikzpicture}
\end{center}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}[t]
\frametitle{Formules math\'ematiques disponibles dans TikZ}
Les op\'erations
\begin{itemize}
\item Operations de base : $ x + y, x - y, x * y, x / y, x^y$
\item Modulo, maxmum, minimum: $\mod(x,y), \max(x,y) \min(x,y)$
\end{itemize}
Les fonctions
\begin{enumerate}
\item $abs(x), exp(x), ln(x), sqrt(x)$
\item Arrondi, partie enti\'ere, partie enti\'ere sup\'erieure : round(x), floor(x), ceil(x).
\end{enumerate}
\begin{itemize}
\item sin(x), cos(x), tan(x), cot(x), sec(x), cosec(x)
\end{itemize}
\end{frame}
\begin{frame}[t]
\frametitle{Une int\'egrale}
On a que
\[ \int^2_1 \frac{1}{x} dx = \ln2 \]
La valeur $\ln2$ repr\'esente donc l'aire gris\'ee sur le graphe suivant.
\begin{center}
\begin{tikzpicture}[scale=1, transform shape]
\plot{ln x}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}

View File

@ -1,5 +1,7 @@
#!/bin/sh
set -xe
for i in $(ls *.c); do
gcc $i -o $(echo $i | cut -d '.' -f 1)
done

View File

@ -19,9 +19,16 @@ void handler(int sig, siginfo_t* info, void* context) {
}
int main(int argc, char *argv[]){
SIGS context = {.sa_flags = SA_SIGINFO, .sa_sigaction = handler};
while(1)
pause();
sigaction(SIGUSR1, &context, NULL);
sigaction(SIGUSR2, &context, NULL);
while(1){
printf("The program is running...\n");
sleep(1);
}
return 0;
}

33
bac2/os/chap1/ex2.c Normal file
View File

@ -0,0 +1,33 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
typedef struct sigaction SIGS;
uint8_t kill_counter = 0;
const char* sentences[] = {
"Just give me a moment.",
"I said I need a moment!",
"Fine. I'm out of here....",
};
void handler(int sig, siginfo_t* info, void* context) {
printf("%s\n", sentences[kill_counter++]);
if(kill_counter >= 3)
abort();
}
int main(int argc, char *argv[])
{
SIGS event = {
.sa_sigaction = handler,
.sa_flags = SA_SIGINFO
};
sigaction(SIGINT, &event, NULL);
while(1)
pause();
return 0;
}

38
bac2/os/chap1/ex3.c Normal file
View File

@ -0,0 +1,38 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
int counter=1;
void handler(int sig){
if(sig == SIGINT){
printf("Early ending. the current ammount of application is : %d\n", counter);
exit(0);
}
}
int collatz(int n){
sleep(1);
if (n % 2 == 0)
return n / 2;
return 3 * n + 1;
}
int main(int argc, char *argv[])
{
signal(SIGINT, handler);
if (argc != 2)
exit(1);
int test = atoi(argv[1]);
printf("%d\n", test);
while(test != 1){
counter++;
test = collatz(test);
printf("%d\n", test);
}
printf("---\n%d\n", counter);
return 0;
}

26
bac2/os/chap1/ex4.c Normal file
View File

@ -0,0 +1,26 @@
#include <signal.h>
#include <stdio.h>
typedef struct sigaction SIGS;
void handler(int sig, siginfo_t* info, void* context){
if(sig == SIGFPE){
printf("Division par zero... rip in peperoni...\n");
exit(1);
}
}
int main(int argc, char *argv[])
{
SIGS event = {
.sa_flags = SA_SIGINFO,
.sa_sigaction = handler
};
sigaction(SIGFPE, &event, NULL);
printf("I want to break free... \n");
printf("%d\n", 1/0);
return 0;
}

19
bac2/os/chap1/ex5.c Normal file
View File

@ -0,0 +1,19 @@
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
void handler(int sig){
if(sig == SIGINT)
while(1)
printf("I cannot DIE !!!!\n");
}
int main(int argc, char *argv[])
{
signal(SIGINT, handler);
signal(SIGQUIT, handler);
signal(SIGTERM, handler);
while(1)
pause();
return 0;
}

22
bac2/os/chap1/ex6.c Normal file
View File

@ -0,0 +1,22 @@
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
void handler(int sig){
printf("test");
exit(0);
}
int main(int argc, char *argv[])
{
signal(SIGALRM, handler);
alarm(5);
getchar();
printf("finished without a thing");
return 0;
}

50
bac2/os/chap1/group.c Normal file
View File

@ -0,0 +1,50 @@
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <assert.h>
#include <string.h>
struct {
int index;
char tab[1024];
} buf = {0};
struct termios term, previous; // the previous state has to be restored... if not the term stay in that mode
void handler(int sig){
switch (sig) {
case SIGALRM:
for (int i = 0; i < buf.index; ++i) {
if(!buf.tab[i])
continue;
printf("%c", buf.tab[i] + 'A' - 'a');
}
alarm(5);
break;
default:
tcsetattr(STDIN_FILENO, TCSANOW, &previous);
raise(sig);
assert(1);
break;
}
}
int main(int argc, char *argv[])
{
signal(SIGALRM, handler);
signal(SIGINT, handler);
tcgetattr(STDIN_FILENO, &previous);
memcpy(&term, &previous, sizeof(struct termios));
term.c_lflag &= ~ICANON;
tcsetattr(STDIN_FILENO, TCSANOW, &term);
alarm(5);
while(1){
buf.tab[buf.index++] = getchar();
}
assert(1);
}

26
bac2/os/chap2/Makefile Normal file
View File

@ -0,0 +1,26 @@
.PHONY: clean, mrproper
CC = gcc
CFLAGS = -g -Wall
all: ex3 ex4
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
ex3: ex3.o
$(CC) $(CFLAGS) -o $@ $+
ex4: ex4.o
$(CC) $(CFLAGS) -o $@ $+
ex5: ex5.o
$(CC) $(CFLAGS) -o $@ $+
clean:
rm -f *.o core.*
mrproper: clean
rm -f ex3 ex4 ex5
run: ex5
./ex5

Binary file not shown.

14
bac2/os/chap2/ex1.c Normal file
View File

@ -0,0 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
#define TEST_SIZE 100
int main(void)
{
char* blop[TEST_SIZE];
for (int i = 0; i < TEST_SIZE; ++i) {
blop[i] = malloc(sizeof(char));
printf("%p\n", blop[i]);
}
while(1);
}

34
bac2/os/chap2/ex2.c Normal file
View File

@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* expand_tabs(const char* string);
int main(void)
{
const char* str = "This is a text This is another one. ' ' <- space; ' ' <-tab";
printf("%s - %d\n", str, (int)strlen(str));
printf("%s - %d\n", expand_tabs(str),(int) strlen(expand_tabs(str)));
}
char* expand_tabs(const char* string){
int tab_count = 0, letter_count = 0;
for(int i = 0; string[i] != '\0'; i++){
letter_count++;
if(string[i] == '\t')
tab_count++;
}
char* ret = malloc(sizeof(char) * letter_count + 3*tab_count);
char* filler = ret;
for(int i = 0; string[i] != '\0'; i++){
if(string[i] == '\t'){
for (int j = 0; j < 4; ++j) {
*(filler++) = ' ';
}
}else{
*(filler++) = string[i];
}
}
return ret;
}

BIN
bac2/os/chap2/ex3 Executable file

Binary file not shown.

62
bac2/os/chap2/ex3.c Normal file
View File

@ -0,0 +1,62 @@
#include <stdlib.h>
#include <stdio.h>
#define print_vec(vec) for (int i = 0; i < (vec)->size; ++i) { printf("%d, ", (vec)->data[i]); } printf("\n")
struct vec {
int size;
int *data;
};
struct vec* new(unsigned int n);
struct vec* add(const struct vec *v, const struct vec *w);
struct vec* smul(double s, const struct vec *v);
int main(void)
{
struct vec *v = new(4);
v->data[0] = 1;
v->data[1] = 2;
v->data[2] = 3;
v->data[3] = 4;
print_vec(v);
struct vec *w = new(4);
w->data[0] = 5;
w->data[1] = 6;
w->data[2] = 7;
w->data[3] = 8;
print_vec(w);
struct vec *added = add(v, w);
print_vec(added);
struct vec *multiplied = smul(3, v);
print_vec(multiplied);
}
struct vec* new(unsigned int n){
struct vec* ret = malloc(sizeof(struct vec));
ret->size = n;
ret->data = malloc(sizeof(int) * n);
return ret;
}
struct vec* add(const struct vec *v, const struct vec *w){
if(v->size != w->size)
return NULL;
struct vec *ret = new(v->size);
for (int i = 0; i < v->size; ++i) {
ret->data[i] = v->data[i] + w->data[i];
}
return ret;
}
struct vec* smul(double s, const struct vec *v){
struct vec *ret = new(v->size);
for (int i = 0; i < v->size; ++i) {
ret->data[i] = v->data[i] * s;
}
return ret;
}

BIN
bac2/os/chap2/ex3.o Normal file

Binary file not shown.

BIN
bac2/os/chap2/ex4 Executable file

Binary file not shown.

61
bac2/os/chap2/ex4.c Normal file
View File

@ -0,0 +1,61 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#define AT(mat, x, y) ((mat)->data[((x)-1) + ( ((y)-1) * ((mat)->w) )])
#define PRINT_MAT(mat) for (int i = 1; i <= (mat)->h; ++i) { for (int j = 1; j <= (mat)->w; ++j) { printf("%d,", AT((mat),(j), (i))); } printf("\n"); } printf("\n");
typedef struct {
uint8_t w, h;
int *data;
} MAT;
MAT *new(uint8_t, uint8_t);
MAT *mul(MAT*, MAT*);
int main(void)
{
MAT* a = new(3, 2);
MAT* b = new(3, 3);
MAT* mult;
AT(a, 1, 1) = 0; AT(a, 2, 1) = 1; AT(a, 3, 1) = 2;
AT(a, 1, 2) = 3; AT(a, 2, 2) = 4; AT(a, 3, 2) = 5;
/* AT(a, 1, 3) = 6; AT(a, 2, 3) = 7; AT(a, 3, 3) = 8; */
PRINT_MAT(a);
AT(b, 1, 1) = 1; AT(b, 2, 1) = 0; AT(b, 3, 1) = 0;
AT(b, 1, 2) = 0; AT(b, 2, 2) = 1; AT(b, 3, 2) = 0;
AT(b, 1, 3) = 0; AT(b, 2, 3) = 0; AT(b, 3, 3) = 1;
PRINT_MAT(b);
mult = mul(a,b);
PRINT_MAT(mult);
}
MAT *new(uint8_t w, uint8_t h){
MAT* ret = malloc(sizeof(MAT));
ret->w = w;
ret->h = h;
ret->data = malloc(sizeof(int) * w * h);
return ret;
}
MAT *mul(MAT *a, MAT *b){
if(a->w != b->h)
return NULL;
MAT* ret = new(b->w, a->h);
for (int i = 1; i <= a->h; ++i) {
for (int j = 1; j <= b->w; ++j) {
int tmp = 0;
for (int k = 1; k <= a->w; ++k) {
tmp += AT(a, k, i) * AT(b, j, k);
}
AT(ret, j, i) = tmp;
}
}
return ret;
}

BIN
bac2/os/chap2/ex4.o Normal file

Binary file not shown.

41
bac2/os/chap2/ex5.c Normal file
View File

@ -0,0 +1,41 @@
#include <stdlib.h>
#include <stdio.h>
struct node{
struct node* prev;
void* data;
};
typedef struct node* LIFO;
LIFO* mklifo ();
void push(LIFO* lst , void*);
void* pop(LIFO* lst);
int main(void)
{
char* t = "test";
LIFO* lifo = mklifo();
push(lifo, t);
printf("%s", (char *)pop(lifo));
}
LIFO *mklifo (){
LIFO* ret = malloc(sizeof(struct node));
return ret;
}
void push(LIFO *lst , void *el){
LIFO* next = mklifo();
(*lst)->data = el;
(*next)->prev = *lst;
lst = next;
}
void *pop(LIFO *lst){
void* el;
(*lst)->data = el;
*lst = (*lst)->prev;
return el;
}

BIN
bac2/os/chap2/ex5.o Normal file

Binary file not shown.