|
1 /****************************************************************************** |
|
2 * |
|
3 * |
|
4 * |
|
5 * Copyright (C) 1997-2008 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 #include <qtextstream.h> |
|
25 |
|
26 #include "instdox.h" |
|
27 #include "doxygen.h" |
|
28 #include "config.h" |
|
29 #include "message.h" |
|
30 |
|
31 void writeInstallScript() |
|
32 { |
|
33 QCString fileName=Config_getString("HTML_OUTPUT")+"/installdox"; |
|
34 QFile f(fileName); |
|
35 if (f.open(IO_WriteOnly)) |
|
36 { |
|
37 QTextStream t(&f); |
|
38 t << "#!" << Config_getString("PERL_PATH") << endl << endl << "%subst = ( "; |
|
39 |
|
40 char *s=Config_getList("TAGFILES").first(); |
|
41 while (s) |
|
42 { |
|
43 QCString tagLine=s; |
|
44 QCString fileName; |
|
45 int eqPos = tagLine.find('='); |
|
46 if (eqPos!=-1) // strip destination part |
|
47 { |
|
48 fileName = tagLine.left(eqPos).stripWhiteSpace(); |
|
49 } |
|
50 else |
|
51 { |
|
52 fileName = tagLine; |
|
53 } |
|
54 QFileInfo fi(fileName); |
|
55 t << "\"" << fi.fileName() << "\", \"\""; |
|
56 s=Config_getList("TAGFILES").next(); |
|
57 if (s) t << ", "; |
|
58 } |
|
59 |
|
60 t << ");\n"; |
|
61 t << "$quiet = 0;\n"; |
|
62 t << "\n"; |
|
63 t << "if (open(F,\"search.cfg\"))\n"; |
|
64 t << "{\n"; |
|
65 t << " $_=<F> ; s/[ \\t\\n]*$//g ; $subst{\"_doc\"} = $_;\n"; |
|
66 t << " $_=<F> ; s/[ \\t\\n]*$//g ; $subst{\"_cgi\"} = $_;\n"; |
|
67 t << "}\n"; |
|
68 t << "\n"; |
|
69 t << "while ( @ARGV ) {\n"; |
|
70 t << " $_ = shift @ARGV;\n"; |
|
71 t << " if ( s/^-// ) {\n"; |
|
72 t << " if ( /^l(.*)/ ) {\n"; |
|
73 t << " $v = ($1 eq \"\") ? shift @ARGV : $1;\n"; |
|
74 t << " ($v =~ /\\/$/) || ($v .= \"/\");\n"; |
|
75 t << " $_ = $v;\n"; |
|
76 t << " if ( /(.+)\\@(.+)/ ) {\n"; |
|
77 t << " if ( exists $subst{$1} ) {\n"; |
|
78 t << " $subst{$1} = $2;\n"; |
|
79 t << " } else {\n"; |
|
80 t << " print STDERR \"Unknown tag file $1 given with option -l\\n\";\n"; |
|
81 t << " &usage();\n"; |
|
82 t << " }\n"; |
|
83 t << " } else {\n"; |
|
84 t << " print STDERR \"Argument $_ is invalid for option -l\\n\";\n"; |
|
85 t << " &usage();\n"; |
|
86 t << " }\n"; |
|
87 t << " }\n"; |
|
88 t << " elsif ( /^q/ ) {\n"; |
|
89 t << " $quiet = 1;\n"; |
|
90 t << " }\n"; |
|
91 t << " elsif ( /^\\?|^h/ ) {\n"; |
|
92 t << " &usage();\n"; |
|
93 t << " }\n"; |
|
94 t << " else {\n"; |
|
95 t << " print STDERR \"Illegal option -$_\\n\";\n"; |
|
96 t << " &usage();\n"; |
|
97 t << " }\n"; |
|
98 t << " }\n"; |
|
99 t << " else {\n"; |
|
100 t << " push (@files, $_ );\n"; |
|
101 t << " }\n"; |
|
102 t << "}\n"; |
|
103 t << "\n"; |
|
104 t << "foreach $sub (keys %subst)\n"; |
|
105 t << "{\n"; |
|
106 t << " if ( $subst{$sub} eq \"\" ) \n"; |
|
107 t << " {\n"; |
|
108 t << " print STDERR \"No substitute given for tag file `$sub'\\n\";\n"; |
|
109 t << " &usage();\n"; |
|
110 t << " }\n"; |
|
111 t << " elsif ( ! $quiet && $sub ne \"_doc\" && $sub ne \"_cgi\" )\n"; |
|
112 t << " {\n"; |
|
113 t << " print \"Substituting $subst{$sub} for each occurence of tag file $sub\\n\"; \n"; |
|
114 t << " }\n"; |
|
115 t << "}\n"; |
|
116 t << "\n"; |
|
117 t << "if ( ! @files ) {\n"; |
|
118 t << " if (opendir(D,\".\")) {\n"; |
|
119 t << " foreach $file ( readdir(D) ) {\n"; |
|
120 t << " $match = \"" << Config_getString("HTML_FILE_EXTENSION") << "\";\n"; |
|
121 t << " next if ( $file =~ /^\\.\\.?$/ );\n"; |
|
122 t << " ($file =~ /$match/) && (push @files, $file);\n"; |
|
123 t << " ($file =~ \"tree.js\") && (push @files, $file);\n"; |
|
124 t << " }\n"; |
|
125 t << " closedir(D);\n"; |
|
126 t << " }\n"; |
|
127 t << "}\n"; |
|
128 t << "\n"; |
|
129 t << "if ( ! @files ) {\n"; |
|
130 t << " print STDERR \"Warning: No input files given and none found!\\n\";\n"; |
|
131 t << "}\n"; |
|
132 t << "\n"; |
|
133 t << "foreach $f (@files)\n"; |
|
134 t << "{\n"; |
|
135 t << " if ( ! $quiet ) {\n"; |
|
136 t << " print \"Editing: $f...\\n\";\n"; |
|
137 t << " }\n"; |
|
138 t << " $oldf = $f;\n"; |
|
139 t << " $f .= \".bak\";\n"; |
|
140 t << " unless (rename $oldf,$f) {\n"; |
|
141 t << " print STDERR \"Error: cannot rename file $oldf\\n\";\n"; |
|
142 t << " exit 1;\n"; |
|
143 t << " }\n"; |
|
144 t << " if (open(F,\"<$f\")) {\n"; |
|
145 t << " unless (open(G,\">$oldf\")) {\n"; |
|
146 t << " print STDERR \"Error: opening file $oldf for writing\\n\";\n"; |
|
147 t << " exit 1;\n"; |
|
148 t << " }\n"; |
|
149 t << " if ($oldf ne \"tree.js\") {\n"; |
|
150 t << " while (<F>) {\n"; |
|
151 t << " s/doxygen\\=\\\"([^ \\\"\\:\\t\\>\\<]*)\\:([^ \\\"\\t\\>\\<]*)\\\" (href|src)=\\\"\\2/doxygen\\=\\\"$1:$subst{$1}\\\" \\3=\\\"$subst{$1}/g;\n"; |
|
152 t << " print G \"$_\";\n"; |
|
153 t << " }\n"; |
|
154 t << " }\n"; |
|
155 t << " else {\n"; |
|
156 t << " while (<F>) {\n"; |
|
157 t << " s/\\\"([^ \\\"\\:\\t\\>\\<]*)\\:([^ \\\"\\t\\>\\<]*)\\\", \\\"\\2/\\\"$1:$subst{$1}\\\" ,\\\"$subst{$1}/g;\n"; |
|
158 t << " print G \"$_\";\n"; |
|
159 t << " }\n"; |
|
160 t << " }\n"; |
|
161 t << " } \n"; |
|
162 t << " else {\n"; |
|
163 t << " print STDERR \"Warning file $f does not exist\\n\";\n"; |
|
164 t << " }\n"; |
|
165 t << " unlink $f;\n"; |
|
166 t << "}\n"; |
|
167 t << "\n"; |
|
168 t << "sub usage {\n"; |
|
169 t << " print STDERR \"Usage: installdox [options] [html-file [html-file ...]]\\n\";\n"; |
|
170 t << " print STDERR \"Options:\\n\";\n"; |
|
171 t << " print STDERR \" -l tagfile\\@linkName tag file + URL or directory \\n\";\n"; |
|
172 t << " print STDERR \" -q Quiet mode\\n\\n\";\n"; |
|
173 t << " exit 1;\n"; |
|
174 t << "}\n"; |
|
175 } |
|
176 else |
|
177 { |
|
178 err("Error: Cannot open file %s for writing\n",fileName.data()); |
|
179 } |
|
180 f.close(); |
|
181 struct stat stat_struct; |
|
182 stat(fileName,&stat_struct); |
|
183 #if !defined(_WIN32) |
|
184 chmod(fileName,stat_struct.st_mode|S_IXUSR|S_IXGRP|S_IXOTH); |
|
185 #endif |
|
186 } |