Bump version.
[ntk.git] / misc / doxystar.cxx
blob36e13e02dd07dd3e2b61019f06f98fc913c3efb5
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.
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.
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.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 #include <stdio.h>
29 #include <string.h>
31 char linebuf[1024];
35 int main(int argc, char **argv) {
36 if (argc!=1) {
37 puts("Add stars (*) in front of multi-line doxygen comments");
38 puts("to protect comment indentation from code beautifiers.");
39 puts("usage: cat file | doxystar");
40 return 0;
43 int state = 0;
44 char *commentStart;
45 int i, commentCol;
46 for (;;) {
47 if (!fgets(linebuf, 1020, stdin)) break; // EOF or error
48 switch (state) {
49 case 0: // line start is source code
50 commentStart = strstr(linebuf, "/*");
51 if (commentStart) {
52 // check if this comment spans multiple lines
53 if (strstr(commentStart, "*/")==0) {
54 if ((commentStart[2]=='*' || commentStart[2]=='!') && commentStart[3]!='*') {
55 state = 2; // Doxygen multiline comment
56 commentCol = commentStart - linebuf;
57 } else {
58 state = 1; // regular multiline comment
60 } else {
61 // single line comment, do nothing
64 fputs(linebuf, stdout);
65 break;
66 case 1: // line start is inside a regular multiline comment
67 if (strstr(linebuf, "*/")) {
68 state = 0;
69 } else {
70 // still inside comment
72 fputs(linebuf, stdout);
73 break;
74 case 2: // line start is inside a doxygen multiline comment
75 for (i=0; i<commentCol; i++) fputc(' ', stdout);
76 fputs(" *", stdout);
77 if (strstr(linebuf, "*/")) {
78 state = 0;
79 } else {
80 // still inside comment
82 for (i=0; i<commentCol+1; i++)
83 if (linebuf[i]!=' ')
84 break;
85 if (linebuf[i]=='*') {
86 if (linebuf[i+1]==' ') {
87 i+=2;
88 } else {
89 i+=1;
92 fputs(linebuf+i, stdout);
93 break;
97 return 0;
101 // End of "$Id: doxystar.cxx 7514 2010-04-16 14:25:20Z AlbrechtS $".