1 /*
2  *  cHelpManager.cc
3  *  Avida
4  *
5  *  Called "help_manager.cc" prior to 12/7/05.
6  *  Copyright 1999-2011 Michigan State University. All rights reserved.
7  *  Copyright 1993-2003 California Institute of Technology.
8  *
9  *
10  *  This file is part of Avida.
11  *
12  *  Avida is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
13  *  as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
14  *
15  *  Avida is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public License along with Avida.
19  *  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #include "cHelpManager.h"
24 
25 #include "apto/core/FileSystem.h"
26 
27 #include "cHelpType.h"
28 #include "cInitFile.h"
29 #include "cString.h"
30 #include "tList.h"
31 
32 #include <iostream>
33 
34 using namespace std;
35 
36 
GetType(const cString type_name)37 cHelpType* cHelpManager::GetType(const cString type_name)
38 {
39   // See if we can find this type in the already existant list...
40   tListIterator<cHelpType> type_it(type_list);
41   while (type_it.Next() != NULL) {
42     if (type_it.Get()->GetName() == type_name) return type_it.Get();
43   }
44 
45   // Otherwise, create it.
46   if (verbose == true) {
47     cout << "  Creating help type \"" << type_name << "\"." << endl;
48   }
49   cHelpType * type = new cHelpType(type_name, this);
50   type_list.Push(type);
51   return type;
52 }
53 
LoadFile(const cString & filename)54 void cHelpManager::LoadFile(const cString & filename)
55 {
56   cInitFile help_file(filename, cString(Apto::FileSystem::GetCWD()));
57 
58   cHelpType * type = NULL;
59   cString keyword;
60 
61   for (int line_id = 0; line_id < help_file.GetNumLines(); line_id++) {
62     cString cur_string = help_file.GetLine(line_id);
63     cString command = cur_string.PopWord();
64     command.ToLower();
65 
66     if (command == "type:") {
67       type = GetType(cur_string);
68     }
69     else if (command == "keyword:") {
70       keyword = cur_string;
71     }
72     else if (command == "desc:") {
73       if (type == NULL) type = GetType("None"); // Make sure we have a type.
74       if (keyword == "") {
75 	if (verbose == true) {
76 	  cerr << "  Help description set without keyword;"
77 	       << " setting keyword to \"None\"." << endl;
78 	}
79 	keyword = "None";
80       }
81       last_entry = type->AddEntry(keyword, cur_string);
82     }
83     else if (command == "alias:") {
84       if (last_entry == NULL) {
85 	cerr << "  Warning: Setting aliases \"" << cur_string
86 	     << "\" to incomplete entry!" << endl;
87       }
88       while (cur_string.GetSize() > 0) {
89 	type->AddAlias(cur_string.PopWord(), last_entry);
90       }
91     }
92     else if (verbose == true) {
93       cerr << "Warning: Unknown command \"" << command
94 	   << "\" in file " << filename << endl;
95     }
96   }
97 
98 }
99 
100 
PrintHTML()101 void cHelpManager::PrintHTML()
102 {
103   tListIterator<cHelpType> type_it(type_list);
104   while (type_it.Next() != NULL) {
105     type_it.Get()->PrintHTML();
106   }
107 }
108