Root/
Source at commit 1322 created 12 years 7 months ago. By meklort, Add doxygen to utils folder | |
---|---|
1 | /******************************************************************************␊ |
2 | *␊ |
3 | * $Id: instdox.cpp,v 1.16 2001/03/19 19:27:40 root Exp $␊ |
4 | *␊ |
5 | * Copyright (C) 1997-2011 by Dimitri van Heesch.␊ |
6 | *␊ |
7 | * Permission to use, copy, modify, and distribute this software and its␊ |
8 | * documentation under the terms of the GNU General Public License is hereby ␊ |
9 | * granted. No representations are made about the suitability of this software ␊ |
10 | * for any purpose. It is provided "as is" without express or implied warranty.␊ |
11 | * See the GNU General Public License for more details.␊ |
12 | *␊ |
13 | * Documents produced by Doxygen are derivative works derived from the␊ |
14 | * input used in their production; they are not affected by this license.␊ |
15 | *␊ |
16 | */␊ |
17 | ␊ |
18 | #include <sys/types.h>␊ |
19 | #include <sys/stat.h>␊ |
20 | ␊ |
21 | #include "qtbc.h"␊ |
22 | #include <qfile.h>␊ |
23 | #include <qfileinfo.h>␊ |
24 | ␊ |
25 | #include "instdox.h"␊ |
26 | #include "doxygen.h"␊ |
27 | #include "config.h"␊ |
28 | #include "message.h"␊ |
29 | ␊ |
30 | void writeInstallScript()␊ |
31 | {␊ |
32 | QCString fileName=Config_getString("HTML_OUTPUT")+"/installdox";␊ |
33 | QFile f(fileName);␊ |
34 | if (f.open(IO_WriteOnly))␊ |
35 | {␊ |
36 | FTextStream t(&f);␊ |
37 | t << "#!" << Config_getString("PERL_PATH") << endl << endl << "%subst = ( ";␊ |
38 | ␊ |
39 | char *s=Config_getList("TAGFILES").first();␊ |
40 | while (s)␊ |
41 | {␊ |
42 | QCString tagLine=s;␊ |
43 | QCString fileName;␊ |
44 | int eqPos = tagLine.find('=');␊ |
45 | if (eqPos!=-1) // strip destination part␊ |
46 | {␊ |
47 | fileName = tagLine.left(eqPos).stripWhiteSpace();␊ |
48 | }␊ |
49 | else␊ |
50 | {␊ |
51 | fileName = tagLine;␊ |
52 | }␊ |
53 | QFileInfo fi(fileName);␊ |
54 | t << "\"" << fi.fileName() << "\", \"\"";␊ |
55 | s=Config_getList("TAGFILES").next();␊ |
56 | if (s) t << ", ";␊ |
57 | }␊ |
58 | ␊ |
59 | t << ");\n";␊ |
60 | t << "$quiet = 0;\n";␊ |
61 | t << "\n";␊ |
62 | t << "while ( @ARGV ) {\n";␊ |
63 | t << " $_ = shift @ARGV;\n";␊ |
64 | t << " if ( s/^-// ) {\n";␊ |
65 | t << " if ( /^l(.*)/ ) {\n";␊ |
66 | t << " $v = ($1 eq \"\") ? shift @ARGV : $1;\n";␊ |
67 | t << " ($v =~ /\\/$/) || ($v .= \"/\");\n";␊ |
68 | t << " $_ = $v;\n";␊ |
69 | t << " if ( /(.+)\\@(.+)/ ) {\n";␊ |
70 | t << " if ( exists $subst{$1} ) {\n";␊ |
71 | t << " $subst{$1} = $2;\n";␊ |
72 | t << " } else {\n";␊ |
73 | t << " print STDERR \"Unknown tag file $1 given with option -l\\n\";\n";␊ |
74 | t << " &usage();\n";␊ |
75 | t << " }\n";␊ |
76 | t << " } else {\n";␊ |
77 | t << " print STDERR \"Argument $_ is invalid for option -l\\n\";\n";␊ |
78 | t << " &usage();\n";␊ |
79 | t << " }\n";␊ |
80 | t << " }\n";␊ |
81 | t << " elsif ( /^q/ ) {\n";␊ |
82 | t << " $quiet = 1;\n";␊ |
83 | t << " }\n";␊ |
84 | t << " elsif ( /^\\?|^h/ ) {\n";␊ |
85 | t << " &usage();\n";␊ |
86 | t << " }\n";␊ |
87 | t << " else {\n";␊ |
88 | t << " print STDERR \"Illegal option -$_\\n\";\n";␊ |
89 | t << " &usage();\n";␊ |
90 | t << " }\n";␊ |
91 | t << " }\n";␊ |
92 | t << " else {\n";␊ |
93 | t << " push (@files, $_ );\n";␊ |
94 | t << " }\n";␊ |
95 | t << "}\n";␊ |
96 | t << "\n";␊ |
97 | t << "foreach $sub (keys %subst)\n";␊ |
98 | t << "{\n";␊ |
99 | t << " if ( $subst{$sub} eq \"\" ) \n";␊ |
100 | t << " {\n";␊ |
101 | t << " print STDERR \"No substitute given for tag file `$sub'\\n\";\n";␊ |
102 | t << " &usage();\n";␊ |
103 | t << " }\n";␊ |
104 | t << " elsif ( ! $quiet && $sub ne \"_doc\" && $sub ne \"_cgi\" )\n";␊ |
105 | t << " {\n";␊ |
106 | t << " print \"Substituting $subst{$sub} for each occurrence of tag file $sub\\n\"; \n";␊ |
107 | t << " }\n";␊ |
108 | t << "}\n";␊ |
109 | t << "\n";␊ |
110 | t << "if ( ! @files ) {\n";␊ |
111 | t << " if (opendir(D,\".\")) {\n";␊ |
112 | t << " foreach $file ( readdir(D) ) {\n";␊ |
113 | t << " $match = \"" << Config_getString("HTML_FILE_EXTENSION") << "\";\n";␊ |
114 | t << " next if ( $file =~ /^\\.\\.?$/ );\n";␊ |
115 | t << " ($file =~ /$match/) && (push @files, $file);\n";␊ |
116 | t << " ($file =~ /\\.svg/) && (push @files, $file);\n";␊ |
117 | t << " ($file =~ \"navtree.js\") && (push @files, $file);\n";␊ |
118 | t << " }\n";␊ |
119 | t << " closedir(D);\n";␊ |
120 | t << " }\n";␊ |
121 | t << "}\n";␊ |
122 | t << "\n";␊ |
123 | t << "if ( ! @files ) {\n";␊ |
124 | t << " print STDERR \"Warning: No input files given and none found!\\n\";\n";␊ |
125 | t << "}\n";␊ |
126 | t << "\n";␊ |
127 | t << "foreach $f (@files)\n";␊ |
128 | t << "{\n";␊ |
129 | t << " if ( ! $quiet ) {\n";␊ |
130 | t << " print \"Editing: $f...\\n\";\n";␊ |
131 | t << " }\n";␊ |
132 | t << " $oldf = $f;\n";␊ |
133 | t << " $f .= \".bak\";\n";␊ |
134 | t << " unless (rename $oldf,$f) {\n";␊ |
135 | t << " print STDERR \"Error: cannot rename file $oldf\\n\";\n";␊ |
136 | t << " exit 1;\n";␊ |
137 | t << " }\n";␊ |
138 | t << " if (open(F,\"<$f\")) {\n";␊ |
139 | t << " unless (open(G,\">$oldf\")) {\n";␊ |
140 | t << " print STDERR \"Error: opening file $oldf for writing\\n\";\n";␊ |
141 | t << " exit 1;\n";␊ |
142 | t << " }\n";␊ |
143 | t << " if ($oldf ne \"tree.js\") {\n";␊ |
144 | t << " while (<F>) {\n";␊ |
145 | t << " s/doxygen\\=\\\"([^ \\\"\\:\\t\\>\\<]*)\\:([^ \\\"\\t\\>\\<]*)\\\" (xlink:href|href|src)=\\\"\\2/doxygen\\=\\\"$1:$subst{$1}\\\" \\3=\\\"$subst{$1}/g;\n";␊ |
146 | t << " print G \"$_\";\n";␊ |
147 | t << " }\n";␊ |
148 | t << " }\n";␊ |
149 | t << " else {\n";␊ |
150 | t << " while (<F>) {\n";␊ |
151 | t << " s/\\\"([^ \\\"\\:\\t\\>\\<]*)\\:([^ \\\"\\t\\>\\<]*)\\\", \\\"\\2/\\\"$1:$subst{$1}\\\" ,\\\"$subst{$1}/g;\n";␊ |
152 | t << " print G \"$_\";\n";␊ |
153 | t << " }\n";␊ |
154 | t << " }\n";␊ |
155 | t << " } \n";␊ |
156 | t << " else {\n";␊ |
157 | t << " print STDERR \"Warning file $f does not exist\\n\";\n";␊ |
158 | t << " }\n";␊ |
159 | t << " unlink $f;\n";␊ |
160 | t << "}\n";␊ |
161 | t << "\n";␊ |
162 | t << "sub usage {\n";␊ |
163 | t << " print STDERR \"Usage: installdox [options] [html-file [html-file ...]]\\n\";\n";␊ |
164 | t << " print STDERR \"Options:\\n\";\n";␊ |
165 | t << " print STDERR \" -l tagfile\\@linkName tag file + URL or directory \\n\";\n";␊ |
166 | t << " print STDERR \" -q Quiet mode\\n\\n\";\n";␊ |
167 | t << " exit 1;\n";␊ |
168 | t << "}\n";␊ |
169 | }␊ |
170 | else␊ |
171 | {␊ |
172 | err("Error: Cannot open file %s for writing\n",fileName.data());␊ |
173 | }␊ |
174 | f.close();␊ |
175 | struct stat stat_struct;␊ |
176 | stat(fileName,&stat_struct);␊ |
177 | #if !defined(_WIN32)␊ |
178 | chmod(fileName,stat_struct.st_mode|S_IXUSR|S_IXGRP|S_IXOTH);␊ |
179 | #endif␊ |
180 | }␊ |
181 |