diff --git a/.gitignore b/.gitignore index d75b877..282f7d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,14 @@ __pycache__/ *.tar *.class +*.toc +*.synctex.gz +*.snm +*.out +*.aux +*.fbd_latexmk +*.fls +*.log +*.nav +*.fdb_latexmk +a.out diff --git a/bac2/latex/beamer-umons b/bac2/latex/beamer-umons new file mode 160000 index 0000000..4eda91b --- /dev/null +++ b/bac2/latex/beamer-umons @@ -0,0 +1 @@ +Subproject commit 4eda91b63722ddfc928d4f88a2e913d0f2fcdcd1 diff --git a/bac2/latex/beamercolorthemeUMONS.sty b/bac2/latex/beamercolorthemeUMONS.sty new file mode 100644 index 0000000..0782b2d --- /dev/null +++ b/bac2/latex/beamercolorthemeUMONS.sty @@ -0,0 +1,49 @@ +% Copyright 2009 by C. Troestler +% This file is under GNU GPL v3 or later. + +\mode + +\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 + diff --git a/bac2/latex/beamerouterthemeUMONS.sty b/bac2/latex/beamerouterthemeUMONS.sty new file mode 100644 index 0000000..442502a --- /dev/null +++ b/bac2/latex/beamerouterthemeUMONS.sty @@ -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 + +\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 + diff --git a/bac2/latex/beamerthemeUMONS.sty b/bac2/latex/beamerthemeUMONS.sty new file mode 100644 index 0000000..232e082 --- /dev/null +++ b/bac2/latex/beamerthemeUMONS.sty @@ -0,0 +1,30 @@ +% Copyright 2009 by C. Troestler +% This file is under GNU GPL v3 or later. + +\mode + +% 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 diff --git a/bac2/latex/lesson3.pdf b/bac2/latex/lesson3.pdf new file mode 100644 index 0000000..f54be71 Binary files /dev/null and b/bac2/latex/lesson3.pdf differ diff --git a/bac2/latex/lesson3.tex b/bac2/latex/lesson3.tex new file mode 100644 index 0000000..bf8f0df --- /dev/null +++ b/bac2/latex/lesson3.tex @@ -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} diff --git a/bac2/os/chap1/build.sh b/bac2/os/chap1/build.sh index 1344de8..edb99b6 100755 --- a/bac2/os/chap1/build.sh +++ b/bac2/os/chap1/build.sh @@ -1,5 +1,7 @@ #!/bin/sh +set -xe + for i in $(ls *.c); do gcc $i -o $(echo $i | cut -d '.' -f 1) done diff --git a/bac2/os/chapitre1-evenements.pdf b/bac2/os/chap1/chapitre1-evenements.pdf similarity index 100% rename from bac2/os/chapitre1-evenements.pdf rename to bac2/os/chap1/chapitre1-evenements.pdf diff --git a/bac2/os/chap1/ex1.c b/bac2/os/chap1/ex1.c index 00f3996..2f634e1 100644 --- a/bac2/os/chap1/ex1.c +++ b/bac2/os/chap1/ex1.c @@ -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; } diff --git a/bac2/os/chap1/ex2.c b/bac2/os/chap1/ex2.c new file mode 100644 index 0000000..dd3bed2 --- /dev/null +++ b/bac2/os/chap1/ex2.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include + +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; +} diff --git a/bac2/os/chap1/ex3.c b/bac2/os/chap1/ex3.c new file mode 100644 index 0000000..bb9ad46 --- /dev/null +++ b/bac2/os/chap1/ex3.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include + +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; +} + diff --git a/bac2/os/chap1/ex4.c b/bac2/os/chap1/ex4.c new file mode 100644 index 0000000..f620a17 --- /dev/null +++ b/bac2/os/chap1/ex4.c @@ -0,0 +1,26 @@ +#include +#include + +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; +} diff --git a/bac2/os/chap1/ex5.c b/bac2/os/chap1/ex5.c new file mode 100644 index 0000000..dc668d4 --- /dev/null +++ b/bac2/os/chap1/ex5.c @@ -0,0 +1,19 @@ +#include +#include +#include + +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; +} diff --git a/bac2/os/chap1/ex6.c b/bac2/os/chap1/ex6.c new file mode 100644 index 0000000..654c41a --- /dev/null +++ b/bac2/os/chap1/ex6.c @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +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; +} diff --git a/bac2/os/chap1/group.c b/bac2/os/chap1/group.c new file mode 100644 index 0000000..6dbf53a --- /dev/null +++ b/bac2/os/chap1/group.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +#include +#include + +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); +} diff --git a/bac2/os/chap2/Makefile b/bac2/os/chap2/Makefile new file mode 100644 index 0000000..ac91e76 --- /dev/null +++ b/bac2/os/chap2/Makefile @@ -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 diff --git a/bac2/os/chap2/chapitre2-memoire.pdf b/bac2/os/chap2/chapitre2-memoire.pdf new file mode 100644 index 0000000..3437f4b Binary files /dev/null and b/bac2/os/chap2/chapitre2-memoire.pdf differ diff --git a/bac2/os/chap2/ex1.c b/bac2/os/chap2/ex1.c new file mode 100644 index 0000000..264c362 --- /dev/null +++ b/bac2/os/chap2/ex1.c @@ -0,0 +1,14 @@ +#include +#include + +#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); +} diff --git a/bac2/os/chap2/ex2.c b/bac2/os/chap2/ex2.c new file mode 100644 index 0000000..f21b525 --- /dev/null +++ b/bac2/os/chap2/ex2.c @@ -0,0 +1,34 @@ +#include +#include +#include + +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; +} diff --git a/bac2/os/chap2/ex3 b/bac2/os/chap2/ex3 new file mode 100755 index 0000000..991d893 Binary files /dev/null and b/bac2/os/chap2/ex3 differ diff --git a/bac2/os/chap2/ex3.c b/bac2/os/chap2/ex3.c new file mode 100644 index 0000000..1efc76c --- /dev/null +++ b/bac2/os/chap2/ex3.c @@ -0,0 +1,62 @@ +#include +#include + +#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; +} diff --git a/bac2/os/chap2/ex3.o b/bac2/os/chap2/ex3.o new file mode 100644 index 0000000..862d2e5 Binary files /dev/null and b/bac2/os/chap2/ex3.o differ diff --git a/bac2/os/chap2/ex4 b/bac2/os/chap2/ex4 new file mode 100755 index 0000000..b21e0f0 Binary files /dev/null and b/bac2/os/chap2/ex4 differ diff --git a/bac2/os/chap2/ex4.c b/bac2/os/chap2/ex4.c new file mode 100644 index 0000000..333c2e8 --- /dev/null +++ b/bac2/os/chap2/ex4.c @@ -0,0 +1,61 @@ +#include +#include +#include + +#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; +} diff --git a/bac2/os/chap2/ex4.o b/bac2/os/chap2/ex4.o new file mode 100644 index 0000000..49a8fc0 Binary files /dev/null and b/bac2/os/chap2/ex4.o differ diff --git a/bac2/os/chap1/a.out b/bac2/os/chap2/ex5 similarity index 51% rename from bac2/os/chap1/a.out rename to bac2/os/chap2/ex5 index a290bf0..f130853 100755 Binary files a/bac2/os/chap1/a.out and b/bac2/os/chap2/ex5 differ diff --git a/bac2/os/chap2/ex5.c b/bac2/os/chap2/ex5.c new file mode 100644 index 0000000..06af55c --- /dev/null +++ b/bac2/os/chap2/ex5.c @@ -0,0 +1,41 @@ +#include +#include + +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; +} diff --git a/bac2/os/chap2/ex5.o b/bac2/os/chap2/ex5.o new file mode 100644 index 0000000..77ac7fe Binary files /dev/null and b/bac2/os/chap2/ex5.o differ