873335e54ef2f40995177937c91a92c8de4adbc6
[cascardo/declara.git] / declara.c
1 /*
2  *  Copyright (C) 2015  Thadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License along
15  *  with this program; if not, write to the Free Software Foundation, Inc.,
16  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <errno.h>
23 #include <fcntl.h>
24 #include <unistd.h>
25
26 #include "declaracao.h"
27
28 static int process(char *filename)
29 {
30         int r = 0;
31         int fd;
32         struct declaracao *dec;
33         dec = declaracao_new(-1);
34         if (!dec)
35                 return -errno;
36         fd = open(filename, O_RDONLY);
37         if (fd < 0) {
38                 r = -errno;
39                 goto out_open;
40         }
41         close(fd);
42 out_open:
43         declaracao_free(dec);
44         return r;
45 }
46
47 static void usage(void)
48 {
49         fprintf(stderr, "declara <filename>\n");
50         exit(1);
51 }
52
53 int main(int argc, char **argv)
54 {
55         char *filename;
56         int r;
57         if (argc < 2)
58                 usage();
59         filename = argv[1];
60         r = process(filename);
61         if (r)
62                 return 1;
63         return 0;
64 }