doc_extract.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* This merely extracts, doesn't do XML or anything. */
  2. #include <err.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <fcntl.h>
  10. #include <stdbool.h>
  11. #include "talloc/talloc.h"
  12. #include "string/string.h"
  13. int main(int argc, char *argv[])
  14. {
  15. unsigned int i, j;
  16. for (i = 1; i < argc; i++) {
  17. char *file;
  18. char **lines;
  19. bool printing = false, printed = false;
  20. file = grab_file(NULL, argv[i]);
  21. if (!file)
  22. err(1, "Reading file %s", argv[i]);
  23. lines = strsplit(file, file, "\n", NULL);
  24. for (j = 0; lines[j]; j++) {
  25. if (streq(lines[j], "/**")) {
  26. printing = true;
  27. if (printed++)
  28. puts("\n");
  29. } else if (streq(lines[j], " */"))
  30. printing = false;
  31. else if (printing) {
  32. if (strstarts(lines[j], " * "))
  33. puts(lines[j] + 3);
  34. else if (strstarts(lines[j], " *"))
  35. puts(lines[j] + 2);
  36. else
  37. errx(1, "Malformed line %s:%u",
  38. argv[i], j);
  39. }
  40. }
  41. talloc_free(file);
  42. }
  43. return 0;
  44. }