| 77 | | 1 # Definition des commandes |
| 78 | | 2 CC = gcc |
| 79 | | 3 AR = ar |
| 80 | | 4 RM = rm |
| 81 | | 5 INDENT = indent |
| 82 | | 6 |
| 83 | | 7 # Definition des parametres |
| 84 | | 8 LDFLAGS = -p |
| 85 | | 9 CFLAGS = -g -p -Wall -ansi -Werror |
| 86 | | 10 ARFLAGS = -r |
| 87 | | 11 IDFLAGS = -gnu -bli0 -npsl -l90 |
| 88 | | 12 |
| 89 | | 13 # Definition de la liste des librairies necesaires a l'edition de lien |
| 90 | | 14 LDLIBS = -L. -lhte |
| 91 | | 15 |
| 92 | | 16 .PHONY: all clean realclean |
| 93 | | 17 |
| 94 | | 18 stat : main.o count.o libhte.a |
| 95 | | 19 $(CC) $(LDFLAGS) main.o count.o -o stat $(LDLIBS) |
| 96 | | 20 |
| 97 | | 21 libhte.a : hte.o dico.o dejavu.o namealloc.o |
| 98 | | 22 $(AR) $(ARFLAGS) libhte.a hte.o dico.o dejavu.o namealloc.o |
| 99 | | 23 |
| 100 | | 24 main.o: |
| 101 | | 25 count.o: |
| 102 | | 26 hte.o: |
| 103 | | 27 dejavu.o: |
| 104 | | 28 namealloc.o: |
| 105 | | 29 |
| 106 | | 30 all: clean stat |
| 107 | | 31 |
| 108 | | 32 clean: |
| 109 | | 33 $(RM) *.o *.a *.out *~ 2> /dev/null || true |
| 110 | | 34 |
| 111 | | 35 realclean: clean |
| 112 | | 36 $(RM) stat 2> /dev/null || true |
| 113 | | 37 |
| 114 | | 38 indent: |
| 115 | | 39 $(INDENT) $(IDFLAGS) *.c *.h |
| | 77 | # Definition des commandes |
| | 78 | CC = gcc |
| | 79 | AR = ar |
| | 80 | RM = rm |
| | 81 | INDENT = indent |
| | 82 | |
| | 83 | # Definition des parametres |
| | 84 | LDFLAGS = -p |
| | 85 | CFLAGS = -g -p -Wall -ansi -Werror |
| | 86 | ARFLAGS = -r |
| | 87 | IDFLAGS = -gnu -bli0 -npsl -l90 |
| | 88 | |
| | 89 | # Definition de la liste des librairies necesaires a l'edition de lien |
| | 90 | LDLIBS = -L. -lhte |
| | 91 | }}} |
| | 92 | {{{ |
| | 93 | .PHONY: all clean realclean |
| | 94 | |
| | 95 | stat : main.o count.o libhte.a |
| | 96 | $(CC) $(LDFLAGS) main.o count.o -o stat $(LDLIBS) |
| | 97 | |
| | 98 | libhte.a : hte.o dico.o dejavu.o namealloc.o |
| | 99 | $(AR) $(ARFLAGS) libhte.a hte.o dico.o dejavu.o namealloc.o |
| | 100 | |
| | 101 | main.o: |
| | 102 | count.o: |
| | 103 | hte.o: |
| | 104 | dejavu.o: |
| | 105 | namealloc.o: |
| | 106 | |
| | 107 | all: clean stat |
| | 108 | |
| | 109 | clean: |
| | 110 | $(RM) *.o *.a *.out *~ 2> /dev/null || true |
| | 111 | |
| | 112 | realclean: clean |
| | 113 | $(RM) stat 2> /dev/null || true |
| | 114 | |
| | 115 | indent: |
| | 116 | $(INDENT) $(IDFLAGS) *.c *.h |
| 157 | | 1 #include <stdlib.h> |
| 158 | | 2 #include <stdio.h> |
| 159 | | 3 #include <getopt.h> |
| 160 | | 4 #include "main.h" |
| 161 | | 5 #include "count.h" |
| 162 | | 6 #include "hte.h" |
| 163 | | 7 |
| 164 | | 8 struct mainarg_s MAINARG; |
| 165 | | 9 |
| 166 | | 10 void usage (char *command) |
| 167 | | 11 { |
| 168 | | 12 printf ("\nStatistique Diverses\n"); |
| 169 | | 13 printf ("Usage : %s |
| 170 | | 14 [-v] [-o OutFile] InFile\n", command); |
| 171 | | 15 printf ("-v verbose mode\n"); |
| 172 | | 16 printf ("-o OutFile output file (stdout by default)\n\n"); |
| 173 | | 17 exit (EXIT_FAILURE); |
| 174 | | 18 } |
| 175 | | 19 |
| 176 | | 20 void getarg (int argc, char **argv) |
| 177 | | 21 { |
| 178 | | 22 extern char *optarg; |
| 179 | | 23 extern int optind; |
| 180 | | 24 char option; |
| 181 | | 25 |
| 182 | | 26 MAINARG.OUTPUTFILE = NULL; |
| 183 | | 27 while ((option = getopt (argc, argv, "vo:")) != EOF) |
| 184 | | 28 switch (option) |
| 185 | | 29 { |
| 186 | | 30 case 'v': |
| 187 | | 31 MAINARG.VERBOSE = 1; |
| 188 | | 32 fprintf (stderr, "Verbose mode\n"); |
| 189 | | 33 break; |
| 190 | | 34 |
| 191 | | 35 case 'o': |
| 192 | | 36 if (MAINARG.VERBOSE) |
| 193 | | 37 fprintf (stderr, "Fichier de sortie : %s\n", optarg); |
| 194 | | 38 |
| 195 | | 39 MAINARG.OUTPUTFILE = fopen (optarg, "w"); |
| 196 | | 40 if (MAINARG.OUTPUTFILE == NULL) |
| 197 | | 41 { |
| 198 | | 42 fprintf (stderr, "%s: %s: \n", argv[0], optarg); |
| 199 | | 43 perror ("fopen"); |
| 200 | | 44 exit (EXIT_FAILURE); |
| 201 | | 45 } |
| 202 | | 46 break; |
| 203 | | 47 |
| 204 | | 48 case '?': |
| 205 | | 49 default: |
| 206 | | 50 usage (argv[0]); |
| 207 | | 51 } |
| 208 | | 52 if ((optind + 1) != argc) |
| 209 | | 53 { |
| 210 | | 54 usage (argv[0]); |
| 211 | | 55 } |
| 212 | | 56 else |
| 213 | | 57 { |
| 214 | | 58 if (MAINARG.VERBOSE) |
| 215 | | 59 fprintf (stderr, "Fichier d'entrée : %s\n", argv[optind]); |
| 216 | | 60 |
| 217 | | 61 MAINARG.INFILE = fopen (argv[optind], "r"); |
| 218 | | 62 if (MAINARG.INFILE == NULL) |
| 219 | | 63 { |
| 220 | | 64 fprintf (stderr, "%s: %s ", argv[0], argv[optind]); |
| 221 | | 65 perror ("fopen"); |
| 222 | | 66 exit (EXIT_FAILURE); |
| 223 | | 67 } |
| 224 | | 68 if (MAINARG.OUTPUTFILE == NULL) |
| 225 | | 69 MAINARG.OUTPUTFILE = stdout; |
| 226 | | 70 } |
| 227 | | 71 } |
| 228 | | 72 |
| 229 | | 73 int main (int argc, char **argv) |
| 230 | | 74 { |
| 231 | | 75 getarg (argc, argv); |
| 232 | | 76 count (MAINARG.INFILE); |
| 233 | | 77 fclose (MAINARG.OUTPUTFILE); |
| 234 | | 78 return EXIT_SUCCESS; |
| 235 | | 79 } |
| | 158 | include <stdlib.h> |
| | 159 | #include <stdio.h> |
| | 160 | #include <getopt.h> |
| | 161 | #include "main.h" |
| | 162 | #include "count.h" |
| | 163 | #include "hte.h" |
| | 164 | }}} |
| | 165 | {{{ |
| | 166 | struct mainarg_s MAINARG; |
| | 167 | }}} |
| | 168 | {{{ |
| | 169 | void usage (char *command) |
| | 170 | { |
| | 171 | printf ("\nStatistique Diverses\n"); |
| | 172 | printf ("Usage : %s |
| | 173 | [-v] [-o OutFile] InFile\n", command); |
| | 174 | printf ("-v verbose mode\n"); |
| | 175 | printf ("-o OutFile output file (stdout by default)\n\n"); |
| | 176 | exit (EXIT_FAILURE); |
| | 177 | } |
| | 178 | }}} |
| | 179 | {{{ |
| | 180 | void getarg (int argc, char **argv) |
| | 181 | { |
| | 182 | extern char *optarg; |
| | 183 | extern int optind; |
| | 184 | char option; |
| | 185 | |
| | 186 | MAINARG.OUTPUTFILE = NULL; |
| | 187 | while ((option = getopt (argc, argv, "vo:")) != EOF) |
| | 188 | switch (option) |
| | 189 | { |
| | 190 | case 'v': |
| | 191 | MAINARG.VERBOSE = 1; |
| | 192 | fprintf (stderr, "Verbose mode\n"); |
| | 193 | break; |
| | 194 | |
| | 195 | case 'o': |
| | 196 | if (MAINARG.VERBOSE) |
| | 197 | fprintf (stderr, "Fichier de sortie : %s\n", optarg); |
| | 198 | |
| | 199 | MAINARG.OUTPUTFILE = fopen (optarg, "w"); |
| | 200 | if (MAINARG.OUTPUTFILE == NULL) |
| | 201 | { |
| | 202 | fprintf (stderr, "%s: %s: \n", argv[0], optarg); |
| | 203 | perror ("fopen"); |
| | 204 | exit (EXIT_FAILURE); |
| | 205 | } |
| | 206 | break; |
| | 207 | |
| | 208 | case '?': |
| | 209 | default: |
| | 210 | usage (argv[0]); |
| | 211 | } |
| | 212 | if ((optind + 1) != argc) |
| | 213 | { |
| | 214 | usage (argv[0]); |
| | 215 | } |
| | 216 | else |
| | 217 | { |
| | 218 | if (MAINARG.VERBOSE) |
| | 219 | fprintf (stderr, "Fichier d'entrée : %s\n", argv[optind]); |
| | 220 | |
| | 221 | MAINARG.INFILE = fopen (argv[optind], "r"); |
| | 222 | if (MAINARG.INFILE == NULL) |
| | 223 | { |
| | 224 | fprintf (stderr, "%s: %s ", argv[0], argv[optind]); |
| | 225 | perror ("fopen"); |
| | 226 | exit (EXIT_FAILURE); |
| | 227 | } |
| | 228 | if (MAINARG.OUTPUTFILE == NULL) |
| | 229 | MAINARG.OUTPUTFILE = stdout; |
| | 230 | } |
| | 231 | } |
| | 232 | }}} |
| | 233 | {{{ |
| | 234 | int main (int argc, char **argv) |
| | 235 | { |
| | 236 | getarg (argc, argv); |
| | 237 | count (MAINARG.INFILE); |
| | 238 | fclose (MAINARG.OUTPUTFILE); |
| | 239 | return EXIT_SUCCESS; |
| | 240 | } |