_info 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include "config.h"
  4. /**
  5. * ccan_tokenizer - A full-text lexer for C source files
  6. *
  7. * ccan_tokenizer generates a list of tokens given the contents of a C source
  8. * or header file.
  9. *
  10. * Example:
  11. *
  12. * #include <ccan/ccan_tokenizer/ccan_tokenizer.h>
  13. * #include <ccan/grab_file/grab_file.h>
  14. * #include <err.h>
  15. *
  16. * void token_list_stats(const struct token_list *tl) {
  17. * size_t comment=0, white=0, stray=0, code=0, total=0;
  18. * size_t count = 0;
  19. * const struct token *i;
  20. *
  21. * for (i=tl->first; i; i=i->next) {
  22. * size_t size = i->orig_size;
  23. * total += size;
  24. * count++;
  25. *
  26. * if (token_type_is_comment(i->type))
  27. * comment += size;
  28. * else if (i->type == TOK_WHITE)
  29. * white += size;
  30. * else if (i->type == TOK_STRAY)
  31. * stray += size;
  32. * else
  33. * code += size;
  34. * }
  35. *
  36. * printf("Code: %.02f%%\n"
  37. * "White space: %.02f%%\n"
  38. * "Comments: %.02f%%\n",
  39. * (double)code * 100.0 / (double)total,
  40. * (double)white * 100.0 / (double)total,
  41. * (double)comment * 100.0 / (double)total);
  42. * if (stray)
  43. * printf("Stray: %.02f%%\n",
  44. * (double)stray * 100.0 / (double)total);
  45. * printf("Total size: %zu bytes with %zu tokens\n",
  46. * total, count);
  47. * }
  48. *
  49. * int main(int argc, char *argv[]) {
  50. * size_t len;
  51. * char *file;
  52. * struct token_list *tl;
  53. * tok_message_queue mq;
  54. * queue_init(mq, NULL);
  55. *
  56. * //grab the file
  57. * if (argc != 2) {
  58. * fprintf(stderr, "Usage: %s source_file\n", argv[0]);
  59. * return 1;
  60. * }
  61. * file = grab_file(NULL, argv[1], &len);
  62. * if (!file)
  63. * err(1, "Could not read file %s", argv[1]);
  64. *
  65. * //tokenize the contents
  66. * tl = tokenize(file, len, &mq);
  67. *
  68. * //print warnings, errors, etc.
  69. * while (queue_count(mq)) {
  70. * struct tok_message msg = dequeue(mq);
  71. * tok_message_print(&msg, tl);
  72. * }
  73. *
  74. * //do neat stuff with the token list
  75. * token_list_stats(tl);
  76. *
  77. * //free stuff
  78. * talloc_free(file); //implicitly frees tl
  79. * queue_free(mq);
  80. *
  81. * return 0;
  82. * }
  83. */
  84. int main(int argc, char *argv[])
  85. {
  86. /* Expect exactly one argument */
  87. if (argc != 2)
  88. return 1;
  89. if (strcmp(argv[1], "depends") == 0) {
  90. printf("ccan/array\n");
  91. return 0;
  92. }
  93. return 1;
  94. }