00001 /****************************************************************************** 00002 * 00003 * $Id: instdox.cpp,v 1.16 2001/03/19 19:27:40 root Exp $ 00004 * 00005 * Copyright (C) 1997-2008 by Dimitri van Heesch. 00006 * 00007 * Permission to use, copy, modify, and distribute this software and its 00008 * documentation under the terms of the GNU General Public License is hereby 00009 * granted. No representations are made about the suitability of this software 00010 * for any purpose. It is provided "as is" without express or implied warranty. 00011 * See the GNU General Public License for more details. 00012 * 00013 * Documents produced by Doxygen are derivative works derived from the 00014 * input used in their production; they are not affected by this license. 00015 * 00016 */ 00017 00018 #include <sys/types.h> 00019 #include <sys/stat.h> 00020 00021 #include "qtbc.h" 00022 #include <qfile.h> 00023 #include <qfileinfo.h> 00024 #include <qtextstream.h> 00025 00026 #include "instdox.h" 00027 #include "doxygen.h" 00028 #include "config.h" 00029 #include "message.h" 00030 00031 void writeInstallScript() 00032 { 00033 QCString fileName=Config_getString("HTML_OUTPUT")+"/installdox"; 00034 QFile f(fileName); 00035 if (f.open(IO_WriteOnly)) 00036 { 00037 QTextStream t(&f); 00038 t << "#!" << Config_getString("PERL_PATH") << endl << endl << "%subst = ( "; 00039 00040 char *s=Config_getList("TAGFILES").first(); 00041 while (s) 00042 { 00043 QCString tagLine=s; 00044 QCString fileName; 00045 int eqPos = tagLine.find('='); 00046 if (eqPos!=-1) // strip destination part 00047 { 00048 fileName = tagLine.left(eqPos).stripWhiteSpace(); 00049 } 00050 else 00051 { 00052 fileName = tagLine; 00053 } 00054 QFileInfo fi(fileName); 00055 t << "\"" << fi.fileName() << "\", \"\""; 00056 s=Config_getList("TAGFILES").next(); 00057 if (s) t << ", "; 00058 } 00059 00060 t << ");\n"; 00061 t << "$quiet = 0;\n"; 00062 t << "\n"; 00063 t << "if (open(F,\"search.cfg\"))\n"; 00064 t << "{\n"; 00065 t << " $_=<F> ; s/[ \\t\\n]*$//g ; $subst{\"_doc\"} = $_;\n"; 00066 t << " $_=<F> ; s/[ \\t\\n]*$//g ; $subst{\"_cgi\"} = $_;\n"; 00067 t << "}\n"; 00068 t << "\n"; 00069 t << "while ( @ARGV ) {\n"; 00070 t << " $_ = shift @ARGV;\n"; 00071 t << " if ( s/^-// ) {\n"; 00072 t << " if ( /^l(.*)/ ) {\n"; 00073 t << " $v = ($1 eq \"\") ? shift @ARGV : $1;\n"; 00074 t << " ($v =~ /\\/$/) || ($v .= \"/\");\n"; 00075 t << " $_ = $v;\n"; 00076 t << " if ( /(.+)\\@(.+)/ ) {\n"; 00077 t << " if ( exists $subst{$1} ) {\n"; 00078 t << " $subst{$1} = $2;\n"; 00079 t << " } else {\n"; 00080 t << " print STDERR \"Unknown tag file $1 given with option -l\\n\";\n"; 00081 t << " &usage();\n"; 00082 t << " }\n"; 00083 t << " } else {\n"; 00084 t << " print STDERR \"Argument $_ is invalid for option -l\\n\";\n"; 00085 t << " &usage();\n"; 00086 t << " }\n"; 00087 t << " }\n"; 00088 t << " elsif ( /^q/ ) {\n"; 00089 t << " $quiet = 1;\n"; 00090 t << " }\n"; 00091 t << " elsif ( /^\\?|^h/ ) {\n"; 00092 t << " &usage();\n"; 00093 t << " }\n"; 00094 t << " else {\n"; 00095 t << " print STDERR \"Illegal option -$_\\n\";\n"; 00096 t << " &usage();\n"; 00097 t << " }\n"; 00098 t << " }\n"; 00099 t << " else {\n"; 00100 t << " push (@files, $_ );\n"; 00101 t << " }\n"; 00102 t << "}\n"; 00103 t << "\n"; 00104 t << "foreach $sub (keys %subst)\n"; 00105 t << "{\n"; 00106 t << " if ( $subst{$sub} eq \"\" ) \n"; 00107 t << " {\n"; 00108 t << " print STDERR \"No substitute given for tag file `$sub'\\n\";\n"; 00109 t << " &usage();\n"; 00110 t << " }\n"; 00111 t << " elsif ( ! $quiet && $sub ne \"_doc\" && $sub ne \"_cgi\" )\n"; 00112 t << " {\n"; 00113 t << " print \"Substituting $subst{$sub} for each occurence of tag file $sub\\n\"; \n"; 00114 t << " }\n"; 00115 t << "}\n"; 00116 t << "\n"; 00117 t << "if ( ! @files ) {\n"; 00118 t << " if (opendir(D,\".\")) {\n"; 00119 t << " foreach $file ( readdir(D) ) {\n"; 00120 t << " $match = \"" << Config_getString("HTML_FILE_EXTENSION") << "\";\n"; 00121 t << " next if ( $file =~ /^\\.\\.?$/ );\n"; 00122 t << " ($file =~ /$match/) && (push @files, $file);\n"; 00123 t << " ($file =~ \"tree.js\") && (push @files, $file);\n"; 00124 t << " }\n"; 00125 t << " closedir(D);\n"; 00126 t << " }\n"; 00127 t << "}\n"; 00128 t << "\n"; 00129 t << "if ( ! @files ) {\n"; 00130 t << " print STDERR \"Warning: No input files given and none found!\\n\";\n"; 00131 t << "}\n"; 00132 t << "\n"; 00133 t << "foreach $f (@files)\n"; 00134 t << "{\n"; 00135 t << " if ( ! $quiet ) {\n"; 00136 t << " print \"Editing: $f...\\n\";\n"; 00137 t << " }\n"; 00138 t << " $oldf = $f;\n"; 00139 t << " $f .= \".bak\";\n"; 00140 t << " unless (rename $oldf,$f) {\n"; 00141 t << " print STDERR \"Error: cannot rename file $oldf\\n\";\n"; 00142 t << " exit 1;\n"; 00143 t << " }\n"; 00144 t << " if (open(F,\"<$f\")) {\n"; 00145 t << " unless (open(G,\">$oldf\")) {\n"; 00146 t << " print STDERR \"Error: opening file $oldf for writing\\n\";\n"; 00147 t << " exit 1;\n"; 00148 t << " }\n"; 00149 t << " if ($oldf ne \"tree.js\") {\n"; 00150 t << " while (<F>) {\n"; 00151 t << " s/doxygen\\=\\\"([^ \\\"\\:\\t\\>\\<]*)\\:([^ \\\"\\t\\>\\<]*)\\\" (href|src)=\\\"\\2/doxygen\\=\\\"$1:$subst{$1}\\\" \\3=\\\"$subst{$1}/g;\n"; 00152 t << " print G \"$_\";\n"; 00153 t << " }\n"; 00154 t << " }\n"; 00155 t << " else {\n"; 00156 t << " while (<F>) {\n"; 00157 t << " s/\\\"([^ \\\"\\:\\t\\>\\<]*)\\:([^ \\\"\\t\\>\\<]*)\\\", \\\"\\2/\\\"$1:$subst{$1}\\\" ,\\\"$subst{$1}/g;\n"; 00158 t << " print G \"$_\";\n"; 00159 t << " }\n"; 00160 t << " }\n"; 00161 t << " } \n"; 00162 t << " else {\n"; 00163 t << " print STDERR \"Warning file $f does not exist\\n\";\n"; 00164 t << " }\n"; 00165 t << " unlink $f;\n"; 00166 t << "}\n"; 00167 t << "\n"; 00168 t << "sub usage {\n"; 00169 t << " print STDERR \"Usage: installdox [options] [html-file [html-file ...]]\\n\";\n"; 00170 t << " print STDERR \"Options:\\n\";\n"; 00171 t << " print STDERR \" -l tagfile\\@linkName tag file + URL or directory \\n\";\n"; 00172 t << " print STDERR \" -q Quiet mode\\n\\n\";\n"; 00173 t << " exit 1;\n"; 00174 t << "}\n"; 00175 } 00176 else 00177 { 00178 err("Error: Cannot open file %s for writing\n",fileName.data()); 00179 } 00180 f.close(); 00181 struct stat stat_struct; 00182 stat(fileName,&stat_struct); 00183 #if !defined(_WIN32) 00184 chmod(fileName,stat_struct.st_mode|S_IXUSR|S_IXGRP|S_IXOTH); 00185 #endif 00186 }