From c35774ef36aa0c066f3dce0454fad2b8f7d5f7b9 Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sun, 20 Feb 2011 18:52:23 +0100 Subject: [PATCH] Everything is nice and tidy --- apres.c => C_Language/apres.c | 0 C_Language/chrono.c | 52 ++++++++++++++++ eko.c => C_Language/eko.c | 0 eko2.c => C_Language/eko2.c | 0 C_Language/environmentvariable.c | 14 +++++ exoPointeurs.c => C_Language/exoPointeurs.c | 0 function.c => C_Language/function.c | 0 matrice1.c => C_Language/matrice1.c | 0 matrice2.c => C_Language/matrice2.c | 0 mini_shell.c => C_Language/mini_shell.c | 0 minmax.c => C_Language/minmax.c | 0 monswap.c => C_Language/monswap.c | 0 .../morceau_miroir.c | 0 C_Language/multiChrono.c | 61 +++++++++++++++++++ squeeze.c => C_Language/squeeze.c | 0 C_Language/strdup.c | 20 ++++++ strdup2.c => C_Language/strdup2.c | 0 supprime.c => C_Language/supprime.c | 0 swapp.c => C_Language/swapp.c | 0 C_Language/test.c | 27 ++++++++ testargs.c => C_Language/testargs.c | 0 tout.c => C_Language/tout.c | 0 C_Language/voir.c | 59 ++++++++++++++++++ wordcount.c => C_Language/wordcount.c | 0 chrono.pl => PERL_Language/chrono.pl | 0 daemon.pl => PERL_Language/daemon.pl | 0 .../enMajuscule.pl | 0 getpwent.pl => PERL_Language/getpwent.pl | 0 getpwent2.pl => PERL_Language/getpwent2.pl | 0 humanornot.pl => PERL_Language/humanornot.pl | 0 .../humanornot2.pl | 0 lePlusGros.pl => PERL_Language/lePlusGros.pl | 0 max.pl => PERL_Language/max.pl | 0 maxcourt.pl => PERL_Language/maxcourt.pl | 0 .../multi_chrono.pl | 0 nbmots.pl => PERL_Language/nbmots.pl | 0 silent_cmp.pl => PERL_Language/silent_cmp.pl | 0 tube.pl => PERL_Language/tube.pl | 0 wc.pl => PERL_Language/wc.pl | 0 39 files changed, 233 insertions(+) rename apres.c => C_Language/apres.c (100%) create mode 100644 C_Language/chrono.c rename eko.c => C_Language/eko.c (100%) rename eko2.c => C_Language/eko2.c (100%) create mode 100644 C_Language/environmentvariable.c rename exoPointeurs.c => C_Language/exoPointeurs.c (100%) rename function.c => C_Language/function.c (100%) rename matrice1.c => C_Language/matrice1.c (100%) rename matrice2.c => C_Language/matrice2.c (100%) rename mini_shell.c => C_Language/mini_shell.c (100%) rename minmax.c => C_Language/minmax.c (100%) rename monswap.c => C_Language/monswap.c (100%) rename morceau_miroir.c => C_Language/morceau_miroir.c (100%) create mode 100644 C_Language/multiChrono.c rename squeeze.c => C_Language/squeeze.c (100%) create mode 100644 C_Language/strdup.c rename strdup2.c => C_Language/strdup2.c (100%) rename supprime.c => C_Language/supprime.c (100%) rename swapp.c => C_Language/swapp.c (100%) create mode 100644 C_Language/test.c rename testargs.c => C_Language/testargs.c (100%) rename tout.c => C_Language/tout.c (100%) create mode 100644 C_Language/voir.c rename wordcount.c => C_Language/wordcount.c (100%) rename chrono.pl => PERL_Language/chrono.pl (100%) rename daemon.pl => PERL_Language/daemon.pl (100%) rename enMajuscule.pl => PERL_Language/enMajuscule.pl (100%) rename getpwent.pl => PERL_Language/getpwent.pl (100%) rename getpwent2.pl => PERL_Language/getpwent2.pl (100%) rename humanornot.pl => PERL_Language/humanornot.pl (100%) rename humanornot2.pl => PERL_Language/humanornot2.pl (100%) rename lePlusGros.pl => PERL_Language/lePlusGros.pl (100%) rename max.pl => PERL_Language/max.pl (100%) rename maxcourt.pl => PERL_Language/maxcourt.pl (100%) rename multi_chrono.pl => PERL_Language/multi_chrono.pl (100%) rename nbmots.pl => PERL_Language/nbmots.pl (100%) rename silent_cmp.pl => PERL_Language/silent_cmp.pl (100%) rename tube.pl => PERL_Language/tube.pl (100%) rename wc.pl => PERL_Language/wc.pl (100%) diff --git a/apres.c b/C_Language/apres.c similarity index 100% rename from apres.c rename to C_Language/apres.c diff --git a/C_Language/chrono.c b/C_Language/chrono.c new file mode 100644 index 0000000..7fa5cda --- /dev/null +++ b/C_Language/chrono.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +// creation d'un processus chrono qui compte les secondes +// sur le signal SIGINT le processus affiche la valeur du compteur +// sur le signal SIGQUIT le processus affiche le compteur et quitte. +// +// lancer le programme dans une fenetre et tester depuis une autre +// kill -2 pid display the timer +// kill -3 pid display the timer and stop the process + + +int nsec = 0 ; // Nombre de secondes + + +void seconde() +{ + print "coucou\n"; + alarm(1); // on repositionne l'evenement SIGALRM + $nsec = $nsec + 1; +} + +void inter() +{ +// affiche la valeur du compteur + print "\n" , $nsec, " secondes ecoulees \n"; +} + +void arret() +{ +// affiche la valeur du compteur et quitte + print "\n" , $nsec, " secondes ecoulees \n"; + print "Fin du chronometre!"; + exit(0); +} + + +// debut du programme + +$SIG {"ALRM"} = "seconde"; //#on associe la fct handler au signal SIGALRM(14) +$SIG {"INT"} = "inter"; //# idem pour le signal SIGINT (2) +$SIG{"QUIT"} = "arret"; //# idem pour le signal SIGQUIT (3) + +alarm(1) ; // on initialise le processus + +print("\ndebut (%d) \n", ); // on affiche le pid et on boucle + +while (1) { + getc() +} diff --git a/eko.c b/C_Language/eko.c similarity index 100% rename from eko.c rename to C_Language/eko.c diff --git a/eko2.c b/C_Language/eko2.c similarity index 100% rename from eko2.c rename to C_Language/eko2.c diff --git a/C_Language/environmentvariable.c b/C_Language/environmentvariable.c new file mode 100644 index 0000000..7f525cf --- /dev/null +++ b/C_Language/environmentvariable.c @@ -0,0 +1,14 @@ +#include +#include +#include + +int main( int argc, char **argv, char **envp) +{ + // I will display all the environment variables + while(*envp != NULL) + { + printf("%s\n", *envp); + *envp++; + } +} + diff --git a/exoPointeurs.c b/C_Language/exoPointeurs.c similarity index 100% rename from exoPointeurs.c rename to C_Language/exoPointeurs.c diff --git a/function.c b/C_Language/function.c similarity index 100% rename from function.c rename to C_Language/function.c diff --git a/matrice1.c b/C_Language/matrice1.c similarity index 100% rename from matrice1.c rename to C_Language/matrice1.c diff --git a/matrice2.c b/C_Language/matrice2.c similarity index 100% rename from matrice2.c rename to C_Language/matrice2.c diff --git a/mini_shell.c b/C_Language/mini_shell.c similarity index 100% rename from mini_shell.c rename to C_Language/mini_shell.c diff --git a/minmax.c b/C_Language/minmax.c similarity index 100% rename from minmax.c rename to C_Language/minmax.c diff --git a/monswap.c b/C_Language/monswap.c similarity index 100% rename from monswap.c rename to C_Language/monswap.c diff --git a/morceau_miroir.c b/C_Language/morceau_miroir.c similarity index 100% rename from morceau_miroir.c rename to C_Language/morceau_miroir.c diff --git a/C_Language/multiChrono.c b/C_Language/multiChrono.c new file mode 100644 index 0000000..3a97de3 --- /dev/null +++ b/C_Language/multiChrono.c @@ -0,0 +1,61 @@ +#!/usr/bin/perl -w + +# creation d'un programme "multiChrono.pl" qui va creer un nouveau processus chrono +# à chaque fois qu'il recoit le signal SIGTERM +# sur le signal SIGINT le processus "multiChrono" envoie ce signal à tous ses fils qui +# affichent à leur tour la valeur du compteur +# sur le signal SIGQUIT le processus renvoie ce signal à tous ses fils qui +# affichent la valeur de leur compteur et quittent. +# + +@tab; # liste des fils crées + +sub nouveau +{ + # creation d'un processus + $pid=fork(); + + if($pid == 0 ) + { + exec "chrono.pl"; + exit(255); + } + else + { + $tab[$#tab + 1] = $pid; # on ajoute le nouveau fils + print "nouveau chrono cree ( $pid)\n "; + print "liste des fils @tab \n"; + } +} + + +sub inter +{ +# affiche la valeur du compteur +# on transmet ce signal à tous les fils + + print "\n on transmet le signal SIGINT a tous les chronometres fils \n"; + kill 2, @tab; +} + +sub arret +{ + print "\n on transmet le signal SIGQUIT a tous les chronometres fils \n"; + kill 3, @tab; + $tab=(); # on vide le tableau + wait à faire + exit(0); +} + + +# debut du programme +# print "\ndebut \n" + +$SIG {"TERM"} = "nouveau"; #on cree un nouveau chrono +$SIG {"INT"} = "inter"; # signal SIGINT (2) +$SIG{"QUIT"} = "arret"; # SIGQUIT (3) + +print "\nInitialisation - programme principal = $$ \n"; # on affiche le pid et on boucle + +while (1) { + getc +} diff --git a/squeeze.c b/C_Language/squeeze.c similarity index 100% rename from squeeze.c rename to C_Language/squeeze.c diff --git a/C_Language/strdup.c b/C_Language/strdup.c new file mode 100644 index 0000000..76747af --- /dev/null +++ b/C_Language/strdup.c @@ -0,0 +1,20 @@ +#include +#include +#include + +char * strdup2(char *); +int main(int argc, char **argv) +{ + char * chaine1 = "Coucou c'est moi"; + char * copie = strdup2(chaine1); + printf("Chaîne originale : %s \nChaîne copie : %s\n", chaine1, copie); + exit(0); +} +char * strdup2(char * t) +{ + char *s, *save; + save = s = malloc((strlen(t) + 1)* sizeof(char)); + while(*s++ = *t++); + + return save; +} diff --git a/strdup2.c b/C_Language/strdup2.c similarity index 100% rename from strdup2.c rename to C_Language/strdup2.c diff --git a/supprime.c b/C_Language/supprime.c similarity index 100% rename from supprime.c rename to C_Language/supprime.c diff --git a/swapp.c b/C_Language/swapp.c similarity index 100% rename from swapp.c rename to C_Language/swapp.c diff --git a/C_Language/test.c b/C_Language/test.c new file mode 100644 index 0000000..d5267b7 --- /dev/null +++ b/C_Language/test.c @@ -0,0 +1,27 @@ +#include +#include +#include +#include + +void changeDirectory(char * path); +void erreur(char *s); + +int main(int argc, char **argv) +{ + changeDirectory(""); + char * wd = (char *) get_current_dir_name(); + printf("Répertoire courant : %s\n", wd); +} + +void changeDirectory(char * path) +{ + if(strcmp(path, "") == 0) + chdir(getenv("HOME")); + else if(chdir(path) != 0 ) + erreur("Impossible de changer de répertoire"); +} +void erreur(char *s) +{ + perror(s); + exit(-2); +} diff --git a/testargs.c b/C_Language/testargs.c similarity index 100% rename from testargs.c rename to C_Language/testargs.c diff --git a/tout.c b/C_Language/tout.c similarity index 100% rename from tout.c rename to C_Language/tout.c diff --git a/C_Language/voir.c b/C_Language/voir.c new file mode 100644 index 0000000..b76f444 --- /dev/null +++ b/C_Language/voir.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include + +// utilise tube, fork, redirection E/S + +// commande : voir enchainant l'execution d'une cde avec more +// exemple : ./voir ls -lR $HOME + +int main(int argc, char **argv) +{ +int p[2],pid; + +if(argc < 2) +{ + perror("erreur argument"); + exit(-1); +} + +if(pipe(p) == -1) +{ + perror("erreur creation tube "); + exit(-2); +} + +pid=fork(); // creation du proc. fils + +switch(pid ) +{ + case -1: + perror("fork1"); + exit(-3); + break; + + case 0 : // le fils traite la commande + + close(1); + dup(p[1]); // on recupere forcement le desc. 1 (+ petit possible) + close(p[0]); + close(p[1]); + execvp(argv[1],argv+1); + printf("\n*** erreur exec. impossible!"); + exit(-4); + + default: // le pere fait le "more" + + close(0); // on ferme entree standard + dup(p[0]); // on connecte l'entree standard au tube + close(p[0]); // pour blocage en lecture + close(p[1]); + execlp("more","more",0); // si on saisit More par exemple -> message erreur + printf("\nerreur execution more \n"); + exit(-5); +} +exit(0); // on ne vient jamais ici +} + diff --git a/wordcount.c b/C_Language/wordcount.c similarity index 100% rename from wordcount.c rename to C_Language/wordcount.c diff --git a/chrono.pl b/PERL_Language/chrono.pl similarity index 100% rename from chrono.pl rename to PERL_Language/chrono.pl diff --git a/daemon.pl b/PERL_Language/daemon.pl similarity index 100% rename from daemon.pl rename to PERL_Language/daemon.pl diff --git a/enMajuscule.pl b/PERL_Language/enMajuscule.pl similarity index 100% rename from enMajuscule.pl rename to PERL_Language/enMajuscule.pl diff --git a/getpwent.pl b/PERL_Language/getpwent.pl similarity index 100% rename from getpwent.pl rename to PERL_Language/getpwent.pl diff --git a/getpwent2.pl b/PERL_Language/getpwent2.pl similarity index 100% rename from getpwent2.pl rename to PERL_Language/getpwent2.pl diff --git a/humanornot.pl b/PERL_Language/humanornot.pl similarity index 100% rename from humanornot.pl rename to PERL_Language/humanornot.pl diff --git a/humanornot2.pl b/PERL_Language/humanornot2.pl similarity index 100% rename from humanornot2.pl rename to PERL_Language/humanornot2.pl diff --git a/lePlusGros.pl b/PERL_Language/lePlusGros.pl similarity index 100% rename from lePlusGros.pl rename to PERL_Language/lePlusGros.pl diff --git a/max.pl b/PERL_Language/max.pl similarity index 100% rename from max.pl rename to PERL_Language/max.pl diff --git a/maxcourt.pl b/PERL_Language/maxcourt.pl similarity index 100% rename from maxcourt.pl rename to PERL_Language/maxcourt.pl diff --git a/multi_chrono.pl b/PERL_Language/multi_chrono.pl similarity index 100% rename from multi_chrono.pl rename to PERL_Language/multi_chrono.pl diff --git a/nbmots.pl b/PERL_Language/nbmots.pl similarity index 100% rename from nbmots.pl rename to PERL_Language/nbmots.pl diff --git a/silent_cmp.pl b/PERL_Language/silent_cmp.pl similarity index 100% rename from silent_cmp.pl rename to PERL_Language/silent_cmp.pl diff --git a/tube.pl b/PERL_Language/tube.pl similarity index 100% rename from tube.pl rename to PERL_Language/tube.pl diff --git a/wc.pl b/PERL_Language/wc.pl similarity index 100% rename from wc.pl rename to PERL_Language/wc.pl