-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
67 lines (56 loc) · 1.33 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include "hashtbl.h"
static void usage()
{
printf("Usage: wordcount DICO [FILE]...\n\n"
"DICO is a single-word-per-line dictionnary file.\n"
"If no FILE is given, the standard input is used instead.\n\n");
}
static void parse_dico(FILE *file)
{
/* FIXME: parse & hashtbl init
'#' comment or empty line are ignored. */
}
static void parse_files(FILE *dico, FILE **filelst)
{
/* FIXME: parse & job */
}
static void parse_input(FILE *dico)
{
/* FIXME: parse stdin & job */
}
int main(int argc, char **argv)
{
if (argc < 2) {
usage();
return -EINVAL;
}
FILE *dico = fopen(argv[1], "r");
if (!dico) {
perror(argv[1]);
return -ENOENT;
}
argc -= 2;
printf("%d", argc);
if (argc > 0) {
FILE **filelst = malloc(sizeof(FILE *) * argc);
if (!filelst) {
perror("error");
return -ENOMEM;
}
for (int i = 0; i < argc; ++i) {
filelst[i] = fopen(argv[i + 2], "r");
if (!filelst[i]) {
perror(argv[i + 1]);
return -ENOENT;
}
}
parse_files(dico, filelst);
} else {
parse_input(dico);
}
/* Streams are flushed and freed on exit */
return 0;
}