]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/compulsory_tests/has_info.c
compiler: shorten names of attributes, add UNUSED
[ccan] / tools / ccanlint / compulsory_tests / has_info.c
1 #include <tools/ccanlint/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 #include <ccan/talloc/talloc.h>
14
15 static void *check_has_info(struct manifest *m,
16                             bool keep,
17                             unsigned int *timeleft)
18 {
19         if (m->info_file)
20                 return NULL;
21         return m;
22 }
23
24 static const char *describe_has_info(struct manifest *m, void *check_result)
25 {
26         return "You have no _info file.\n\n"
27         "The file _info contains the metadata for a ccan package: things\n"
28         "like the dependencies, the documentation for the package as a whole\n"
29         "and license information.\n";
30 }
31
32 static const char template[] = 
33         "#include <string.h>\n"
34         "#include \"config.h\"\n"
35         "\n"
36         "/**\n"
37         " * %s - YOUR-ONE-LINE-DESCRIPTION-HERE\n"
38         " *\n"
39         " * This code ... YOUR-BRIEF-SUMMARY-HERE\n"
40         " *\n"
41         " * Example:\n"
42         " *     FULLY-COMPILABLE-INDENTED-TRIVIAL-BUT-USEFUL-EXAMPLE-HERE\n"
43         " */\n"
44         "int main(int argc, char *argv[])\n"
45         "{\n"
46         "       /* Expect exactly one argument */\n"
47         "       if (argc != 2)\n"
48         "               return 1;\n"
49         "\n"
50         "       if (strcmp(argv[1], \"depends\") == 0) {\n"
51         "               PRINTF-CCAN-PACKAGES-YOU-NEED-ONE-PER-LINE-IF-ANY\n"
52         "               return 0;\n"
53         "       }\n"
54         "\n"
55         "       return 1;\n"
56         "}\n";
57
58 static void create_info_template(struct manifest *m, void *check_result)
59 {
60         FILE *info;
61         const char *filename;
62
63         if (!ask("Should I create a template _info file for you?"))
64                 return;
65
66         filename = talloc_asprintf(m, "%s/%s", m->dir, "_info");
67         info = fopen(filename, "w");
68         if (!info)
69                 err(1, "Trying to create a template _info in %s", filename);
70
71         if (fprintf(info, template, m->basename) < 0) {
72                 unlink_noerr(filename);
73                 err(1, "Writing template into %s", filename);
74         }
75         fclose(info);
76 }
77
78 struct ccanlint has_info = {
79         .key = "info",
80         .name = "Module has _info file",
81         .check = check_has_info,
82         .describe = describe_has_info,
83         .handle = create_info_template,
84 };
85
86 REGISTER_TEST(has_info, NULL);