doxystar.cxx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // "$Id: doxystar.cxx 8864 2011-07-19 04:49:30Z greg.ercolano $"
  3. //
  4. // Doxygen pre-formatting program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 2010 by Matthias Melcher.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. #include <stdio.h>
  19. #include <string.h>
  20. char linebuf[1024];
  21. int main(int argc, char **argv) {
  22. if (argc!=1) {
  23. puts("Add stars (*) in front of multi-line doxygen comments");
  24. puts("to protect comment indentation from code beautifiers.");
  25. puts("usage: cat file | doxystar");
  26. return 0;
  27. }
  28. int state = 0;
  29. char *commentStart;
  30. int i, commentCol;
  31. for (;;) {
  32. if (!fgets(linebuf, 1020, stdin)) break; // EOF or error
  33. switch (state) {
  34. case 0: // line start is source code
  35. commentStart = strstr(linebuf, "/*");
  36. if (commentStart) {
  37. // check if this comment spans multiple lines
  38. if (strstr(commentStart, "*/")==0) {
  39. if ((commentStart[2]=='*' || commentStart[2]=='!') && commentStart[3]!='*') {
  40. state = 2; // Doxygen multiline comment
  41. commentCol = commentStart - linebuf;
  42. } else {
  43. state = 1; // regular multiline comment
  44. }
  45. } else {
  46. // single line comment, do nothing
  47. }
  48. }
  49. fputs(linebuf, stdout);
  50. break;
  51. case 1: // line start is inside a regular multiline comment
  52. if (strstr(linebuf, "*/")) {
  53. state = 0;
  54. } else {
  55. // still inside comment
  56. }
  57. fputs(linebuf, stdout);
  58. break;
  59. case 2: // line start is inside a doxygen multiline comment
  60. for (i=0; i<commentCol; i++) fputc(' ', stdout);
  61. fputs(" *", stdout);
  62. if (strstr(linebuf, "*/")) {
  63. state = 0;
  64. } else {
  65. // still inside comment
  66. }
  67. for (i=0; i<commentCol+1; i++)
  68. if (linebuf[i]!=' ')
  69. break;
  70. if (linebuf[i]=='*') {
  71. if (linebuf[i+1]==' ') {
  72. i+=2;
  73. } else {
  74. i+=1;
  75. }
  76. }
  77. fputs(linebuf+i, stdout);
  78. break;
  79. }
  80. }
  81. return 0;
  82. }
  83. //
  84. // End of "$Id: doxystar.cxx 8864 2011-07-19 04:49:30Z greg.ercolano $".
  85. //