You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.9KB

  1. //
  2. // "$Id: doxystar.cxx 7514 2010-04-16 14:25:20Z AlbrechtS $"
  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; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. #include <stdio.h>
  28. #include <string.h>
  29. char linebuf[1024];
  30. int main(int argc, char **argv) {
  31. if (argc!=1) {
  32. puts("Add stars (*) in front of multi-line doxygen comments");
  33. puts("to protect comment indentation from code beautifiers.");
  34. puts("usage: cat file | doxystar");
  35. return 0;
  36. }
  37. int state = 0;
  38. char *commentStart;
  39. int i, commentCol;
  40. for (;;) {
  41. if (!fgets(linebuf, 1020, stdin)) break; // EOF or error
  42. switch (state) {
  43. case 0: // line start is source code
  44. commentStart = strstr(linebuf, "/*");
  45. if (commentStart) {
  46. // check if this comment spans multiple lines
  47. if (strstr(commentStart, "*/")==0) {
  48. if ((commentStart[2]=='*' || commentStart[2]=='!') && commentStart[3]!='*') {
  49. state = 2; // Doxygen multiline comment
  50. commentCol = commentStart - linebuf;
  51. } else {
  52. state = 1; // regular multiline comment
  53. }
  54. } else {
  55. // single line comment, do nothing
  56. }
  57. }
  58. fputs(linebuf, stdout);
  59. break;
  60. case 1: // line start is inside a regular multiline comment
  61. if (strstr(linebuf, "*/")) {
  62. state = 0;
  63. } else {
  64. // still inside comment
  65. }
  66. fputs(linebuf, stdout);
  67. break;
  68. case 2: // line start is inside a doxygen multiline comment
  69. for (i=0; i<commentCol; i++) fputc(' ', stdout);
  70. fputs(" *", stdout);
  71. if (strstr(linebuf, "*/")) {
  72. state = 0;
  73. } else {
  74. // still inside comment
  75. }
  76. for (i=0; i<commentCol+1; i++)
  77. if (linebuf[i]!=' ')
  78. break;
  79. if (linebuf[i]=='*') {
  80. if (linebuf[i+1]==' ') {
  81. i+=2;
  82. } else {
  83. i+=1;
  84. }
  85. }
  86. fputs(linebuf+i, stdout);
  87. break;
  88. }
  89. }
  90. return 0;
  91. }
  92. //
  93. // End of "$Id: doxystar.cxx 7514 2010-04-16 14:25:20Z AlbrechtS $".
  94. //