]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/no_info.c
d641003c05b728aacb8dd603c701e34d9c859b08
[ccan] / tools / ccanlint / no_info.c
1 #include "ccanlint.h"
2 #include <sys/types.h>
3 #include <sys/stat.h>
4 #include <fcntl.h>
5 #include <unistd.h>
6 #include <limits.h>
7 #include <errno.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <err.h>
11 #include <string.h>
12 #include <ccan/noerr/noerr.h>
13
14 static void *check_no_info(struct manifest *m)
15 {
16         if (m->info_file)
17                 return NULL;
18         return m;
19 }
20
21 static const char *describe_no_info(struct manifest *m, void *check_result)
22 {
23         return "You have no _info.c file.\n\n"
24         "The file _info.c contains the metadata for a ccan package: things\n"
25         "like the dependencies, the documentation for the package as a whole\n"
26         "and license information.\n";
27 }
28
29 static const char template[] = 
30         "#include <string.h>\n"
31         "#include \"config.h\"\n"
32         "\n"
33         "/**\n"
34         " * %s - YOUR-ONE-LINE-DESCRIPTION-HERE\n"
35         " *\n"
36         " * This code ... YOUR-BRIEF-SUMMARY-HERE\n"
37         " *\n"
38         " * Example:\n"
39         " *     FULLY-COMPILABLE-INDENTED-TRIVIAL-BUT-USEFUL-EXAMPLE-HERE\n"
40         " */\n"
41         "int main(int argc, char *argv[])\n"
42         "{\n"
43         "       /* Expect exactly one argument\n"
44         "       if (argc != 2)\n"
45         "               return 1;\n"
46         "\n"
47         "       if (strcmp(argv[1], \"depends\") == 0) {\n"
48         "               PRINTF-CCAN-PACKAGES-YOU-NEED-ONE-PER-LINE-IF-ANY\n"
49         "               return 0;\n"
50         "       }\n"
51         "\n"
52         "       return 1;\n"
53         "}\n";
54
55 static void create_info_template(struct manifest *m, void *check_result)
56 {
57         FILE *info;
58
59         if (!ask("Should I create a template _info.c file for you?"))
60                 return;
61
62         info = fopen("_info.c", "w");
63         if (!info)
64                 err(1, "Trying to create a template _info.c");
65
66         if (fprintf(info, template, m->basename) < 0) {
67                 unlink_noerr("_info.c");
68                 err(1, "Writing template into _info.c");
69         }
70         fclose(info);
71 }
72
73 struct ccanlint no_info = {
74         .name = "No _info.c file",
75         .check = check_no_info,
76         .describe = describe_no_info,
77         .handle = create_info_template,
78 };