ccanlint.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #ifndef CCAN_LINT_H
  2. #define CCAN_LINT_H
  3. #include <ccan/list/list.h>
  4. #include <stdbool.h>
  5. #include "../doc_extract.h"
  6. struct manifest {
  7. char *basename;
  8. struct ccan_file *info_file;
  9. struct list_head c_files;
  10. struct list_head h_files;
  11. struct list_head run_tests;
  12. struct list_head api_tests;
  13. struct list_head compile_ok_tests;
  14. struct list_head compile_fail_tests;
  15. struct list_head other_test_files;
  16. struct list_head other_files;
  17. };
  18. struct manifest *get_manifest(void);
  19. struct ccanlint {
  20. struct list_node list;
  21. /* Unique name of test */
  22. const char *name;
  23. /* Total score that this test is worth. 0 means compulsory tests. */
  24. unsigned int total_score;
  25. /* If this returns non-NULL, it means the check failed. */
  26. void *(*check)(struct manifest *m);
  27. /* The non-NULL return from check is passed to one of these: */
  28. /* So, what did this get out of the total_score? (NULL means 0). */
  29. unsigned int (*score)(struct manifest *m, void *check_result);
  30. /* Verbose description of what was wrong. */
  31. const char *(*describe)(struct manifest *m, void *check_result);
  32. /* Can we do something about it? (NULL if not) */
  33. void (*handle)(struct manifest *m, void *check_result);
  34. };
  35. /* Ask the user a yes/no question: the answer is NO if there's an error. */
  36. bool ask(const char *question);
  37. struct ccan_file {
  38. struct list_node list;
  39. char *name;
  40. unsigned int num_lines;
  41. char **lines;
  42. struct list_head *doc_sections;
  43. };
  44. /* Use this rather than accessing f->lines directly: loads on demand. */
  45. char **get_ccan_file_lines(struct ccan_file *f);
  46. /* Similarly for ->doc_sections */
  47. struct list_head *get_ccan_file_docs(struct ccan_file *f);
  48. /* Call the reporting on every line in the file. sofar contains
  49. * previous results. */
  50. char *report_on_lines(struct list_head *files,
  51. char *(*report)(const char *),
  52. char *sofar);
  53. /* The critical tests which mean fail if they don't pass. */
  54. extern struct ccanlint no_info;
  55. extern struct ccanlint has_main_header;
  56. /* Normal tests. */
  57. extern struct ccanlint trailing_whitespace;
  58. #endif /* CCAN_LINT_H */