has_info.c 1.8 KB

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