StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
writeIndex.cc
1 /***************************************************************************
2  *
3  * $Id: writeIndex.cc,v 1.1 1999/02/17 12:38:49 ullrich Exp $
4  *
5  * Author: Thomas Ullrich, August 1998
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * $Log: writeIndex.cc,v $
13  * Revision 1.1 1999/02/17 12:38:49 ullrich
14  * Initial Revision
15  *
16  **************************************************************************/
17 #include <string>
18 #include <fstream.h>
19 #include <cstdlib>
20 #include <unistd.h>
21 #include <stdio.h>
22 #include <utility>
23 #include <list>
24 #include <vector>
25 #include <map>
26 #include <stdexcept>
27 #include <time.h>
28 #include <assert.h>
29 #include <algorithm>
30 
31 // #define DEBUG
32 #define PR(x) cout << #x << " = " << (x) << endl;
33 
34 typedef map<string, string, less<string> > keywordMap_type;
35 typedef keywordMap_type::value_type keyword_type;
36 
37 template<class A, class B>
38 ostream& operator<<(ostream& out, const pair<A,B> &p)
39 {
40  out << p.first << " is defined in " << p.second;
41  return out;
42 }
43 
44 int main(int argc, char* argv[])
45 {
46  if (argc < 2) {
47  cerr << "Usage: " << argv[0] << " file ..." << endl;
48  return 2;
49  }
50 
51  //
52  // Prepare new list of keywords and filenames
53  // If there are no keywords available we use the
54  // name of the header file directly (without extensions)
55  //
56  keywordMap_type keywordMap;
57  string htmlFile, keywordFile, baseName, line;
58  size_t pos, nkeys;
59  ifstream ifs;
60  int i, j, k;
61  for (i=1; i<argc; i++) {
62  htmlFile = keywordFile = baseName = argv[i];
63  pos = htmlFile.find(".html");
64  if (pos == string::npos) {
65  cerr << argv[0] << ": error, file must have extension '.html': "
66  << htmlFile << endl;
67  continue;
68  }
69  keywordFile.replace(pos, 5, ".keywords");
70  baseName.erase(pos, 5);
71  pos = baseName.rfind(".");
72  if (pos != string::npos) baseName.erase(pos, line.size()-pos);
73  ifs.open(keywordFile.c_str());
74  if (!ifs) {
75  keywordMap.insert(keyword_type(baseName, htmlFile));
76  }
77  else {
78  nkeys = 0;
79  while (ifs.good()) {
80  getline(ifs, line, '\n');
81  if (ifs.eof()) break;
82  if (line.empty()) continue;
83  nkeys++;
84  keywordMap.insert(keyword_type(line, htmlFile));
85  }
86  if (nkeys == 0) keywordMap.insert(keyword_type(baseName, htmlFile));
87  }
88  ifs.close();
89  }
90 #ifdef DEBUG
91  copy(keywordMap.begin(), keywordMap.end(), ostream_iterator<keyword_type>(cout, "\n"));
92 #endif
93  //
94  // Write the index file
95  //
96  const string indexName = "index.html";
97  ofstream ofs(indexName.c_str());
98  if (!ofs) {
99  cerr << argv[0] << ": error, cannot create file " << indexName << endl;
100  return 1;
101  }
102  cout << "writing index to " << indexName << " .";
103  ofs << "<html>" << endl;
104  ofs << "<!-- This code is generated automatically. Dont' modify it! -->" << endl;
105  ofs << "<head>" << endl;
106  ofs << "<title>StarClassLibrary: Class Browser</title>" << endl;
107  ofs << "</head>" << endl;
108  ofs << "<body bgcolor=#ffffff text=#000000>" << endl;
109  ofs << "<table border=0 width=110% cellpadding=0>" << endl;
110  ofs << "<tr bgcolor=darkblue>" << endl;
111  ofs << "<td align=left valign=top>" << endl;
112  ofs << "<ul>" << endl;
113  ofs << "<h4><br></h4>" << endl;
114  ofs << "<h1><font color=white>StarClassLibrary: </font><font color=red>"
115  << "Class Browser Index</font></h1>" << endl;
116  ofs << "</ul>" << endl;
117  ofs << "</td>" << endl;
118  ofs << "</tr>" << endl;
119  ofs << "</table>" << endl;
120  ofs << "<p>" << endl;
121  ofs << "<table border=0 width=100% cellpadding=15>" << endl;
122  ofs << "<tr>" << endl;
123  ofs << "<td bgcolor=#eeeeee align=left valign=top>" << endl;
124  ofs << "<ul>" << endl;
125  keywordMap_type::const_iterator iter;
126  for (iter = keywordMap.begin(); iter != keywordMap.end(); iter++) {
127  cout << '.'; cout.flush();
128  ofs << "<li><a href=" << iter->second << ">"
129  << iter->first << "</a></li>" << endl;
130  }
131  ofs << "</ul>" << endl;
132  ofs << "</td>" << endl;
133  ofs << "<td align=left valign=top>" << endl;
134  ofs << "<p>This reference guide is an alphabetical
135 listing of all of the classes, algorithms, and function
136 objects provided by <i>this</i> release of the Star C++
137 Class Library. For each class, the reference begins with
138 a synopsis, which indicates the header file(s) and the
139 signature of a class object. It continues with
140 the C++ code that describes the <i>public</i> interface.
141 Please note, that the interface is displayed in its pure
142 ANSI form. In a few rare cases and depending on your platform
143 the actual code might differ slightly. </p>
144 <p>This guide only shows the interfaces, i.e., the prototypes
145 of the classes and function objects. For a more detailed description see the
146 <font color=green><i>Star C++ Class Library User Guide and
147 Reference Manual </i></font> which is available as a
148 PostScript document. It contains information concerning the
149 various platforms, installation procedures and a complete
150 description of all classes including many example programs.
151 Developers should also inspect the corrseponding header files.</p>
152 This index and all other HTML pages referenced were
153 generated automatically." << endl;
154  ofs << "</td>" << endl;
155  ofs << "</tr>" << endl;
156  ofs << "</table>" << endl;
157  time_t now = time(0);
158  ofs << "<hr noshade=noshade>" << endl;
159  ofs << "Index generated on " << ctime(&now);
160  ofs << "</body>" << endl;
161  ofs << "</html>" << endl;
162 
163  ofs.close();
164  cout << ". done" << endl;
165  return 0;
166 }