| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|---|
| 2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
|
|---|
| 3 | <title>G4VBasicShell.cc Source File</title>
|
|---|
| 4 | <link href="doxygen.css" rel="stylesheet" type="text/css">
|
|---|
| 5 | </head><body>
|
|---|
| 6 | <!-- Generated by Doxygen 1.3.4 -->
|
|---|
| 7 | <div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a></div>
|
|---|
| 8 | <h1>G4VBasicShell.cc</h1><a href="G4VBasicShell_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">//</span>
|
|---|
| 9 | 00002 <span class="comment">// ********************************************************************</span>
|
|---|
| 10 | 00003 <span class="comment">// * License and Disclaimer *</span>
|
|---|
| 11 | 00004 <span class="comment">// * *</span>
|
|---|
| 12 | 00005 <span class="comment">// * The Geant4 software is copyright of the Copyright Holders of *</span>
|
|---|
| 13 | 00006 <span class="comment">// * the Geant4 Collaboration. It is provided under the terms and *</span>
|
|---|
| 14 | 00007 <span class="comment">// * conditions of the Geant4 Software License, included in the file *</span>
|
|---|
| 15 | 00008 <span class="comment">// * LICENSE and available at http://cern.ch/geant4/license . These *</span>
|
|---|
| 16 | 00009 <span class="comment">// * include a list of copyright holders. *</span>
|
|---|
| 17 | 00010 <span class="comment">// * *</span>
|
|---|
| 18 | 00011 <span class="comment">// * Neither the authors of this software system, nor their employing *</span>
|
|---|
| 19 | 00012 <span class="comment">// * institutes,nor the agencies providing financial support for this *</span>
|
|---|
| 20 | 00013 <span class="comment">// * work make any representation or warranty, express or implied, *</span>
|
|---|
| 21 | 00014 <span class="comment">// * regarding this software system or assume any liability for its *</span>
|
|---|
| 22 | 00015 <span class="comment">// * use. Please see the license in the file LICENSE and URL above *</span>
|
|---|
| 23 | 00016 <span class="comment">// * for the full disclaimer and the limitation of liability. *</span>
|
|---|
| 24 | 00017 <span class="comment">// * *</span>
|
|---|
| 25 | 00018 <span class="comment">// * This code implementation is the result of the scientific and *</span>
|
|---|
| 26 | 00019 <span class="comment">// * technical work of the GEANT4 collaboration. *</span>
|
|---|
| 27 | 00020 <span class="comment">// * By using, copying, modifying or distributing the software (or *</span>
|
|---|
| 28 | 00021 <span class="comment">// * any work based on the software) you agree to acknowledge its *</span>
|
|---|
| 29 | 00022 <span class="comment">// * use in resulting scientific publications, and indicate your *</span>
|
|---|
| 30 | 00023 <span class="comment">// * acceptance of all terms of the Geant4 Software license. *</span>
|
|---|
| 31 | 00024 <span class="comment">// ********************************************************************</span>
|
|---|
| 32 | 00025 <span class="comment">//</span>
|
|---|
| 33 | 00026 <span class="comment">//</span>
|
|---|
| 34 | 00027 <span class="comment">// $Id: G4VBasicShell.cc,v 1.12 2006/06/29 19:10:20 gunter Exp $</span>
|
|---|
| 35 | 00028 <span class="comment">// GEANT4 tag $Name: geant4-08-01-patch-01 $</span>
|
|---|
| 36 | 00029 <span class="comment">//</span>
|
|---|
| 37 | 00030
|
|---|
| 38 | 00031 <span class="preprocessor">#include "<a class="code" href="G4VBasicShell_8hh.html">G4VBasicShell.hh</a>"</span>
|
|---|
| 39 | 00032 <span class="preprocessor">#include "G4StateManager.hh"</span>
|
|---|
| 40 | 00033 <span class="preprocessor">#include "G4UIcommandTree.hh"</span>
|
|---|
| 41 | 00034 <span class="preprocessor">#include "G4UIcommand.hh"</span>
|
|---|
| 42 | 00035 <span class="preprocessor">#include "G4UIcommandStatus.hh"</span>
|
|---|
| 43 | 00036 <span class="preprocessor">#include "G4UImanager.hh"</span>
|
|---|
| 44 | 00037 <span class="preprocessor">#include <vector></span>
|
|---|
| 45 | 00038 <span class="preprocessor">#include <sstream></span>
|
|---|
| 46 | 00039
|
|---|
| 47 | <a name="l00040"></a><a class="code" href="classG4VBasicShell.html#a0">00040</a> <a class="code" href="classG4VBasicShell.html#a0">G4VBasicShell::G4VBasicShell</a>()
|
|---|
| 48 | 00041 :currentDirectory("/")
|
|---|
| 49 | 00042 {
|
|---|
| 50 | 00043 }
|
|---|
| 51 | 00044
|
|---|
| 52 | <a name="l00045"></a><a class="code" href="classG4VBasicShell.html#a1">00045</a> <a class="code" href="classG4VBasicShell.html#a1">G4VBasicShell::~G4VBasicShell</a>()
|
|---|
| 53 | 00046 {;}
|
|---|
| 54 | 00047
|
|---|
| 55 | <a name="l00048"></a><a class="code" href="classG4VBasicShell.html#b0">00048</a> G4String <a class="code" href="classG4VBasicShell.html#b0">G4VBasicShell::ModifyToFullPathCommand</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* aCommandLine)
|
|---|
| 56 | 00049 {
|
|---|
| 57 | 00050 G4String rawCommandLine = (G4String)aCommandLine;
|
|---|
| 58 | 00051 <span class="keywordflow">if</span>(rawCommandLine.isNull()||rawCommandLine(0)==<span class="charliteral">'\0'</span>) <span class="keywordflow">return</span> rawCommandLine;
|
|---|
| 59 | 00052 G4String commandLine = (G4String)rawCommandLine.strip(G4String::both);
|
|---|
| 60 | 00053 G4String commandString;
|
|---|
| 61 | 00054 G4String parameterString;
|
|---|
| 62 | 00055 size_t i = commandLine.index(<span class="stringliteral">" "</span>);
|
|---|
| 63 | 00056 <span class="keywordflow">if</span>( i != std::string::npos )
|
|---|
| 64 | 00057 {
|
|---|
| 65 | 00058 commandString = (G4String)commandLine(0,i);
|
|---|
| 66 | 00059 parameterString = <span class="stringliteral">" "</span>;
|
|---|
| 67 | 00060 parameterString += (G4String)commandLine(i+1,commandLine.length()-(i+1));
|
|---|
| 68 | 00061 }
|
|---|
| 69 | 00062 <span class="keywordflow">else</span>
|
|---|
| 70 | 00063 { commandString = commandLine; }
|
|---|
| 71 | 00064
|
|---|
| 72 | 00065 G4String fullPathCommandLine
|
|---|
| 73 | 00066 = <a class="code" href="classG4VBasicShell.html#d0">ModifyPath</a>( commandString )+parameterString;
|
|---|
| 74 | 00067 <span class="keywordflow">return</span> fullPathCommandLine;
|
|---|
| 75 | 00068 }
|
|---|
| 76 | 00069
|
|---|
| 77 | <a name="l00070"></a><a class="code" href="classG4VBasicShell.html#b1">00070</a> G4String <a class="code" href="classG4VBasicShell.html#b1">G4VBasicShell::GetCurrentWorkingDirectory</a>()
|
|---|
| 78 | 00071 {
|
|---|
| 79 | 00072 <span class="keywordflow">return</span> <a class="code" href="classG4VBasicShell.html#r0">currentDirectory</a>;
|
|---|
| 80 | 00073 }
|
|---|
| 81 | 00074
|
|---|
| 82 | <a name="l00075"></a><a class="code" href="classG4VBasicShell.html#b2">00075</a> G4bool <a class="code" href="classG4VBasicShell.html#b2">G4VBasicShell::ChangeDirectory</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* newDir)
|
|---|
| 83 | 00076 {
|
|---|
| 84 | 00077 G4String aNewPrefix = (G4String)newDir;
|
|---|
| 85 | 00078 G4String newPrefix = (G4String)aNewPrefix.strip(G4String::both);
|
|---|
| 86 | 00079 G4String newDirectory = <a class="code" href="classG4VBasicShell.html#d0">ModifyPath</a>( newPrefix );
|
|---|
| 87 | 00080 <span class="keywordflow">if</span>( newDirectory( newDirectory.length() - 1 ) != <span class="charliteral">'/'</span> )
|
|---|
| 88 | 00081 { newDirectory += <span class="stringliteral">"/"</span>; }
|
|---|
| 89 | 00082 <span class="keywordflow">if</span>( <a class="code" href="classG4VBasicShell.html#b3">FindDirectory</a>( (<span class="keyword">const</span> <span class="keywordtype">char</span>*)newDirectory ) == NULL )
|
|---|
| 90 | 00083 { <span class="keywordflow">return</span> <span class="keyword">false</span>; }
|
|---|
| 91 | 00084 <a class="code" href="classG4VBasicShell.html#r0">currentDirectory</a> = newDirectory;
|
|---|
| 92 | 00085 <span class="keywordflow">return</span> <span class="keyword">true</span>;
|
|---|
| 93 | 00086 }
|
|---|
| 94 | 00087
|
|---|
| 95 | <a name="l00088"></a><a class="code" href="classG4VBasicShell.html#b3">00088</a> G4UIcommandTree* <a class="code" href="classG4VBasicShell.html#b3">G4VBasicShell::FindDirectory</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* dirName)
|
|---|
| 96 | 00089 {
|
|---|
| 97 | 00090 G4String aDirName = (G4String)dirName;
|
|---|
| 98 | 00091 G4String theDir = (G4String)aDirName.strip(G4String::both);
|
|---|
| 99 | 00092 G4String targetDir = <a class="code" href="classG4VBasicShell.html#d0">ModifyPath</a>( theDir );
|
|---|
| 100 | 00093 <span class="keywordflow">if</span>( targetDir( targetDir.length()-1 ) != <span class="charliteral">'/'</span> )
|
|---|
| 101 | 00094 { targetDir += <span class="stringliteral">"/"</span>; }
|
|---|
| 102 | 00095 G4UIcommandTree* comTree = G4UImanager::GetUIpointer()->GetTree();
|
|---|
| 103 | 00096 <span class="keywordflow">if</span>( targetDir == <span class="stringliteral">"/"</span> )
|
|---|
| 104 | 00097 { <span class="keywordflow">return</span> comTree; }
|
|---|
| 105 | 00098 size_t idx = 1;
|
|---|
| 106 | 00099 <span class="keywordflow">while</span>( idx < targetDir.length()-1 )
|
|---|
| 107 | 00100 {
|
|---|
| 108 | 00101 size_t i = targetDir.index(<span class="stringliteral">"/"</span>,idx);
|
|---|
| 109 | 00102 comTree = comTree->GetTree((G4String)targetDir(0,i+1));
|
|---|
| 110 | 00103 <span class="keywordflow">if</span>( comTree == NULL )
|
|---|
| 111 | 00104 { <span class="keywordflow">return</span> NULL; }
|
|---|
| 112 | 00105 idx = i+1;
|
|---|
| 113 | 00106 }
|
|---|
| 114 | 00107 <span class="keywordflow">return</span> comTree;
|
|---|
| 115 | 00108 }
|
|---|
| 116 | 00109
|
|---|
| 117 | <a name="l00110"></a><a class="code" href="classG4VBasicShell.html#b4">00110</a> G4UIcommand* <a class="code" href="classG4VBasicShell.html#b4">G4VBasicShell::FindCommand</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* commandName)
|
|---|
| 118 | 00111 {
|
|---|
| 119 | 00112 G4String rawCommandLine = (G4String)commandName;
|
|---|
| 120 | 00113 G4String commandLine = (G4String)rawCommandLine.strip(G4String::both);
|
|---|
| 121 | 00114 G4String commandString;
|
|---|
| 122 | 00115 size_t i = commandLine.index(<span class="stringliteral">" "</span>);
|
|---|
| 123 | 00116 <span class="keywordflow">if</span>( i != std::string::npos )
|
|---|
| 124 | 00117 { commandString = (G4String)commandLine(0,i); }
|
|---|
| 125 | 00118 <span class="keywordflow">else</span>
|
|---|
| 126 | 00119 { commandString = commandLine; }
|
|---|
| 127 | 00120
|
|---|
| 128 | 00121 G4String targetCom = <a class="code" href="classG4VBasicShell.html#d0">ModifyPath</a>(commandString);
|
|---|
| 129 | 00122 <span class="keywordflow">return</span> G4UImanager::GetUIpointer()->GetTree()->FindPath(targetCom);
|
|---|
| 130 | 00123 }
|
|---|
| 131 | 00124
|
|---|
| 132 | <a name="l00125"></a><a class="code" href="classG4VBasicShell.html#d0">00125</a> G4String <a class="code" href="classG4VBasicShell.html#d0">G4VBasicShell::ModifyPath</a>(G4String tempPath)
|
|---|
| 133 | 00126 {
|
|---|
| 134 | 00127 G4String newPath = <a class="code" href="classG4VBasicShell.html#r0">currentDirectory</a>;
|
|---|
| 135 | 00128
|
|---|
| 136 | 00129 <span class="keywordflow">if</span>( tempPath.length()>0 )
|
|---|
| 137 | 00130 {
|
|---|
| 138 | 00131
|
|---|
| 139 | 00132 <span class="keywordflow">if</span>( tempPath(0) == <span class="charliteral">'/'</span> ) <span class="comment">// full path is given</span>
|
|---|
| 140 | 00133 { newPath = tempPath; }
|
|---|
| 141 | 00134 <span class="keywordflow">else</span> <span class="keywordflow">if</span>( tempPath(0) != <span class="charliteral">'.'</span> ) <span class="comment">// add current prefix</span>
|
|---|
| 142 | 00135 { newPath += tempPath; }
|
|---|
| 143 | 00136 <span class="keywordflow">else</span> <span class="keywordflow">if</span>( tempPath(0,2) == <span class="stringliteral">"./"</span> ) <span class="comment">// add current prefix</span>
|
|---|
| 144 | 00137 { newPath += (G4String)tempPath(2,tempPath.length()-2); }
|
|---|
| 145 | 00138 <span class="keywordflow">else</span> <span class="comment">// swim up with ".."</span>
|
|---|
| 146 | 00139 {
|
|---|
| 147 | 00140 <span class="keywordflow">while</span>( 1 )
|
|---|
| 148 | 00141 {
|
|---|
| 149 | 00142 <span class="keywordflow">if</span>( tempPath(0,2) == <span class="stringliteral">".."</span> )
|
|---|
| 150 | 00143 {
|
|---|
| 151 | 00144 <span class="keywordflow">if</span>( newPath != <span class="stringliteral">"/"</span> )
|
|---|
| 152 | 00145 {
|
|---|
| 153 | 00146 G4String tmpString = (G4String)newPath(0,newPath.length()-1);
|
|---|
| 154 | 00147 newPath = (G4String)newPath(0,tmpString.last(<span class="charliteral">'/'</span>)+1);
|
|---|
| 155 | 00148 }
|
|---|
| 156 | 00149 <span class="keywordflow">if</span>( tempPath == <span class="stringliteral">".."</span> || tempPath == <span class="stringliteral">"../"</span> )
|
|---|
| 157 | 00150 { <span class="keywordflow">break</span>; }
|
|---|
| 158 | 00151 tempPath = (G4String)tempPath(3,tempPath.length()-3);
|
|---|
| 159 | 00152 }
|
|---|
| 160 | 00153 <span class="keywordflow">else</span>
|
|---|
| 161 | 00154 {
|
|---|
| 162 | 00155 newPath += tempPath;
|
|---|
| 163 | 00156 <span class="keywordflow">break</span>;
|
|---|
| 164 | 00157 }
|
|---|
| 165 | 00158 }
|
|---|
| 166 | 00159 }
|
|---|
| 167 | 00160
|
|---|
| 168 | 00161 }
|
|---|
| 169 | 00162
|
|---|
| 170 | 00163 <span class="keywordflow">return</span> newPath;
|
|---|
| 171 | 00164 }
|
|---|
| 172 | 00166 <span class="comment">// Method used for command completion //////</span>
|
|---|
| 173 | <a name="l00168"></a><a class="code" href="classG4VBasicShell.html#b5">00168</a> <span class="comment"></span>G4String <a class="code" href="classG4VBasicShell.html#b5">G4VBasicShell::Complete</a>(G4String commandName)
|
|---|
| 174 | 00169 {
|
|---|
| 175 | 00170 G4String rawCommandLine = commandName;
|
|---|
| 176 | 00171 G4String commandLine = rawCommandLine.strip(G4String::both);
|
|---|
| 177 | 00172 size_t i = commandLine.index(<span class="stringliteral">" "</span>);
|
|---|
| 178 | 00173 <span class="keywordflow">if</span>( i != std::string::npos ) <span class="keywordflow">return</span> rawCommandLine; <span class="comment">// Already entering parameters, </span>
|
|---|
| 179 | 00174 <span class="comment">// assume command path is correct.</span>
|
|---|
| 180 | 00175 G4String commandString = commandLine;
|
|---|
| 181 | 00176 G4String targetCom = <a class="code" href="classG4VBasicShell.html#d0">ModifyPath</a>(commandString);
|
|---|
| 182 | 00177 G4UIcommandTree* tree = G4UImanager::GetUIpointer()->GetTree();
|
|---|
| 183 | 00178 G4String value = <a class="code" href="classG4VBasicShell.html#b6">FindMatchingPath</a>(tree,targetCom);
|
|---|
| 184 | 00179 <span class="keywordflow">if</span>(value==<span class="stringliteral">""</span>) <span class="keywordflow">return</span> rawCommandLine;
|
|---|
| 185 | 00180 <span class="keywordflow">return</span> value;
|
|---|
| 186 | 00181 }
|
|---|
| 187 | <a name="l00182"></a><a class="code" href="classG4VBasicShell.html#b6">00182</a> G4String <a class="code" href="classG4VBasicShell.html#b6">G4VBasicShell::FindMatchingPath</a>(
|
|---|
| 188 | 00183 G4UIcommandTree* aTree
|
|---|
| 189 | 00184 ,G4String aCommandPath
|
|---|
| 190 | 00185 )
|
|---|
| 191 | 00186 <span class="comment">// From intercoms/src/G4UIcommandTree::FindPath.</span>
|
|---|
| 192 | 00187 {
|
|---|
| 193 | 00188 G4String empty = <span class="stringliteral">""</span>;
|
|---|
| 194 | 00189 <span class="keywordflow">if</span>(aTree==NULL) <span class="keywordflow">return</span> empty;
|
|---|
| 195 | 00190 G4String pathName = aTree->GetPathName();
|
|---|
| 196 | 00191 <span class="keywordflow">if</span>( aCommandPath.index( pathName ) == std::string::npos ) <span class="keywordflow">return</span> empty;
|
|---|
| 197 | 00192 G4String remainingPath = aCommandPath;
|
|---|
| 198 | 00193 remainingPath.remove(0,pathName.length());
|
|---|
| 199 | 00194 size_t i = remainingPath.first(<span class="charliteral">'/'</span>);
|
|---|
| 200 | 00195 <span class="keywordflow">if</span>( i == std::string::npos ) {
|
|---|
| 201 | 00196 <span class="comment">// Look for number of matching commands :</span>
|
|---|
| 202 | 00197 std::vector<G4UIcommand*> commands;
|
|---|
| 203 | 00198 G4int n_commandEntry = aTree->GetCommandEntry();
|
|---|
| 204 | 00199 <span class="keywordflow">for</span>( G4int i_thCommand = 1; i_thCommand <= n_commandEntry; i_thCommand++ ) {
|
|---|
| 205 | 00200 G4UIcommand* cmd = aTree->GetCommand(i_thCommand);
|
|---|
| 206 | 00201 G4String ss = cmd->GetCommandName();
|
|---|
| 207 | 00202 ss.resize(remainingPath.length());
|
|---|
| 208 | 00203 <span class="keywordflow">if</span>( remainingPath == ss ) commands.push_back(cmd);
|
|---|
| 209 | 00204 }
|
|---|
| 210 | 00205 n_commandEntry = commands.size();
|
|---|
| 211 | 00206 <span class="keywordflow">if</span>(n_commandEntry==1) {
|
|---|
| 212 | 00207 <span class="keywordflow">return</span> (pathName + commands[0]->GetCommandName());
|
|---|
| 213 | 00208 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (n_commandEntry>=2) {
|
|---|
| 214 | 00209 G4cout << <span class="stringliteral">"Matching commands :"</span> << G4endl;
|
|---|
| 215 | 00210 <span class="keywordflow">for</span>( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ ) {
|
|---|
| 216 | 00211 G4UIcommand* cmd = commands[i_thCommand];
|
|---|
| 217 | 00212 G4cout << cmd->GetCommandName() << G4endl;
|
|---|
| 218 | 00213 }
|
|---|
| 219 | 00214 <span class="keywordflow">return</span> empty;
|
|---|
| 220 | 00215 }
|
|---|
| 221 | 00216 <span class="comment">// Look for sub tree :</span>
|
|---|
| 222 | 00217 std::vector<G4UIcommandTree*> trees;
|
|---|
| 223 | 00218 G4String nextPath = pathName;
|
|---|
| 224 | 00219 nextPath.append(remainingPath);
|
|---|
| 225 | 00220 G4int n_treeEntry = aTree->GetTreeEntry();
|
|---|
| 226 | 00221 <span class="keywordflow">for</span>( G4int i_thTree = 1; i_thTree <= n_treeEntry; i_thTree++ ) {
|
|---|
| 227 | 00222 G4UIcommandTree* tree = aTree->GetTree(i_thTree);
|
|---|
| 228 | 00223 G4String ss = tree->GetPathName();
|
|---|
| 229 | 00224 ss.resize(nextPath.length());
|
|---|
| 230 | 00225 <span class="keywordflow">if</span>( nextPath == ss ) trees.push_back(tree);
|
|---|
| 231 | 00226 }
|
|---|
| 232 | 00227 n_treeEntry = trees.size();
|
|---|
| 233 | 00228 <span class="keywordflow">if</span>(n_treeEntry==1) {
|
|---|
| 234 | 00229 <span class="keywordflow">return</span> trees[0]->GetPathName();
|
|---|
| 235 | 00230 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (n_treeEntry>=2) {
|
|---|
| 236 | 00231 G4cout << <span class="stringliteral">"Matching directories :"</span> << G4endl;
|
|---|
| 237 | 00232 <span class="keywordflow">for</span>( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ ) {
|
|---|
| 238 | 00233 G4UIcommandTree* tree = trees[i_thTree];
|
|---|
| 239 | 00234 G4cout << tree->GetPathName() << G4endl;
|
|---|
| 240 | 00235 }
|
|---|
| 241 | 00236 <span class="keywordflow">return</span> empty;
|
|---|
| 242 | 00237 } <span class="keywordflow">else</span> {
|
|---|
| 243 | 00238 <span class="keywordflow">return</span> empty; <span class="comment">// No match.</span>
|
|---|
| 244 | 00239 }
|
|---|
| 245 | 00240 } <span class="keywordflow">else</span> {
|
|---|
| 246 | 00241 <span class="comment">// Find path</span>
|
|---|
| 247 | 00242 G4String nextPath = pathName;
|
|---|
| 248 | 00243 nextPath.append(remainingPath(0,i+1));
|
|---|
| 249 | 00244 G4int n_treeEntry = aTree->GetTreeEntry();
|
|---|
| 250 | 00245 <span class="keywordflow">for</span>( G4int i_thTree = 1; i_thTree <= n_treeEntry; i_thTree++ ) {
|
|---|
| 251 | 00246 G4UIcommandTree* tree = aTree->GetTree(i_thTree);
|
|---|
| 252 | 00247 <span class="keywordflow">if</span>( nextPath == tree->GetPathName() ) {
|
|---|
| 253 | 00248 <span class="keywordflow">return</span> <a class="code" href="classG4VBasicShell.html#b6">FindMatchingPath</a>(tree,aCommandPath );
|
|---|
| 254 | 00249 }
|
|---|
| 255 | 00250 }
|
|---|
| 256 | 00251 }
|
|---|
| 257 | 00252 <span class="keywordflow">return</span> empty;
|
|---|
| 258 | 00253 }
|
|---|
| 259 | 00255 <span class="comment">// Method involving an interactive G4cout //</span>
|
|---|
| 260 | 00257 <span class="comment"></span><span class="comment">/***************************************************************************/</span>
|
|---|
| 261 | <a name="l00258"></a><a class="code" href="classG4VBasicShell.html#b7">00258</a> <span class="keywordtype">void</span> <a class="code" href="classG4VBasicShell.html#b7">G4VBasicShell::ExecuteCommand</a> (
|
|---|
| 262 | 00259 G4String aCommand
|
|---|
| 263 | 00260 )
|
|---|
| 264 | 00261 <span class="comment">/***************************************************************************/</span>
|
|---|
| 265 | 00262 <span class="comment">// Should be put in G4VBasicShell.</span>
|
|---|
| 266 | 00264 <span class="comment"></span>{
|
|---|
| 267 | 00265 <span class="keywordflow">if</span>(aCommand.length()<2) <span class="keywordflow">return</span>;
|
|---|
| 268 | 00266 G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 269 | 00267 <span class="keywordflow">if</span>(UI==NULL) <span class="keywordflow">return</span>;
|
|---|
| 270 | 00268 G4int commandStatus = UI->ApplyCommand(aCommand);
|
|---|
| 271 | 00269 <span class="keywordflow">switch</span>(commandStatus) {
|
|---|
| 272 | 00270 <span class="keywordflow">case</span> fCommandSucceeded:
|
|---|
| 273 | 00271 <span class="keywordflow">break</span>;
|
|---|
| 274 | 00272 <span class="keywordflow">case</span> fCommandNotFound:
|
|---|
| 275 | 00273 G4cerr << <span class="stringliteral">"command not found"</span> << G4endl;
|
|---|
| 276 | 00274 <span class="keywordflow">break</span>;
|
|---|
| 277 | 00275 <span class="keywordflow">case</span> fIllegalApplicationState:
|
|---|
| 278 | 00276 G4cerr << <span class="stringliteral">"illegal application state -- command refused"</span> << G4endl;
|
|---|
| 279 | 00277 <span class="keywordflow">break</span>;
|
|---|
| 280 | 00278 <span class="keywordflow">case</span> fParameterOutOfRange:
|
|---|
| 281 | 00279 <span class="keywordflow">case</span> fParameterUnreadable:
|
|---|
| 282 | 00280 <span class="keywordflow">case</span> fParameterOutOfCandidates:
|
|---|
| 283 | 00281 <span class="keywordflow">default</span>:
|
|---|
| 284 | 00282 G4cerr << <span class="stringliteral">"command refused ("</span> << commandStatus << <span class="stringliteral">")"</span> << G4endl;
|
|---|
| 285 | 00283 }
|
|---|
| 286 | 00284 }
|
|---|
| 287 | 00285 <span class="comment">/***************************************************************************/</span>
|
|---|
| 288 | <a name="l00286"></a><a class="code" href="classG4VBasicShell.html#b10">00286</a> <span class="keywordtype">void</span> <a class="code" href="classG4VBasicShell.html#b10">G4VBasicShell::ApplyShellCommand</a> (
|
|---|
| 289 | 00287 G4String a_string
|
|---|
| 290 | 00288 ,G4bool& exitSession
|
|---|
| 291 | 00289 ,G4bool& exitPause
|
|---|
| 292 | 00290 )
|
|---|
| 293 | 00291 <span class="comment">/***************************************************************************/</span>
|
|---|
| 294 | 00293 {
|
|---|
| 295 | 00294 G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 296 | 00295 <span class="keywordflow">if</span>(UI==NULL) <span class="keywordflow">return</span>;
|
|---|
| 297 | 00296
|
|---|
| 298 | 00297 G4String command = a_string.strip(G4String::leading);
|
|---|
| 299 | 00298 <span class="keywordflow">if</span>( command(0) == <span class="charliteral">'#'</span> ) {
|
|---|
| 300 | 00299
|
|---|
| 301 | 00300 G4cout << command << G4endl;
|
|---|
| 302 | 00301
|
|---|
| 303 | 00302 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( command == <span class="stringliteral">"ls"</span> || command(0,3) == <span class="stringliteral">"ls "</span> ) {
|
|---|
| 304 | 00303
|
|---|
| 305 | 00304 <a class="code" href="classG4VBasicShell.html#b13">ListDirectory</a>( command );
|
|---|
| 306 | 00305
|
|---|
| 307 | 00306 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( command == <span class="stringliteral">"pwd"</span> ) {
|
|---|
| 308 | 00307
|
|---|
| 309 | 00308 G4cout << <span class="stringliteral">"Current Working Directory : "</span>
|
|---|
| 310 | 00309 << <a class="code" href="classG4VBasicShell.html#b1">GetCurrentWorkingDirectory</a>() << G4endl;
|
|---|
| 311 | 00310
|
|---|
| 312 | 00311 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( command(0,2) == <span class="stringliteral">"cd"</span> ) {
|
|---|
| 313 | 00312
|
|---|
| 314 | 00313 <a class="code" href="classG4VBasicShell.html#b12">ChangeDirectoryCommand</a> ( command );
|
|---|
| 315 | 00314
|
|---|
| 316 | 00315 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( command(0,4) == <span class="stringliteral">"help"</span> ) {
|
|---|
| 317 | 00316
|
|---|
| 318 | 00317 <a class="code" href="classG4VBasicShell.html#b14">TerminalHelp</a>( command );
|
|---|
| 319 | 00318
|
|---|
| 320 | 00319 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( command(0) == <span class="charliteral">'?'</span> ) {
|
|---|
| 321 | 00320
|
|---|
| 322 | 00321 <a class="code" href="classG4VBasicShell.html#b11">ShowCurrent</a>( command );
|
|---|
| 323 | 00322
|
|---|
| 324 | 00323 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( command(0,4) == <span class="stringliteral">"hist"</span> ) {
|
|---|
| 325 | 00324
|
|---|
| 326 | 00325 G4int nh = UI->GetNumberOfHistory();
|
|---|
| 327 | 00326 <span class="keywordflow">for</span>(G4int i=0;i<nh;i++) {
|
|---|
| 328 | 00327 G4cout << i << <span class="stringliteral">": "</span> << UI->GetPreviousCommand(i) << G4endl;
|
|---|
| 329 | 00328 }
|
|---|
| 330 | 00329
|
|---|
| 331 | 00330 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( command(0) == <span class="charliteral">'!'</span> ) {
|
|---|
| 332 | 00331
|
|---|
| 333 | 00332 G4String ss = command(1,command.length()-1);
|
|---|
| 334 | 00333 G4int vl;
|
|---|
| 335 | 00334 <span class="keyword">const</span> <span class="keywordtype">char</span>* tt = ss;
|
|---|
| 336 | 00335 std::istringstream is(tt);
|
|---|
| 337 | 00336 is >> vl;
|
|---|
| 338 | 00337 G4int nh = UI->GetNumberOfHistory();
|
|---|
| 339 | 00338 <span class="keywordflow">if</span>(vl>=0 && vl<nh) {
|
|---|
| 340 | 00339 G4String prev = UI->GetPreviousCommand(vl);
|
|---|
| 341 | 00340 G4cout << prev << G4endl;
|
|---|
| 342 | 00341 <a class="code" href="classG4VBasicShell.html#b7">ExecuteCommand</a> (<a class="code" href="classG4VBasicShell.html#b0">ModifyToFullPathCommand</a>(prev));
|
|---|
| 343 | 00342 } <span class="keywordflow">else</span> {
|
|---|
| 344 | 00343 G4cerr << <span class="stringliteral">"history "</span> << vl << <span class="stringliteral">" is not found."</span> << G4endl;
|
|---|
| 345 | 00344 }
|
|---|
| 346 | 00345
|
|---|
| 347 | 00346 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( command(0,4) == <span class="stringliteral">"exit"</span> ) {
|
|---|
| 348 | 00347
|
|---|
| 349 | 00348 <span class="keywordflow">if</span>( exitPause == <span class="keyword">false</span>) { <span class="comment">//In a secondary loop.</span>
|
|---|
| 350 | 00349 G4cout << <span class="stringliteral">"You are now processing RUN."</span> << G4endl;
|
|---|
| 351 | 00350 G4cout << <span class="stringliteral">"Please abort it using \"/run/abort\" command first"</span> << G4endl;
|
|---|
| 352 | 00351 G4cout << <span class="stringliteral">" and use \"continue\" command until the application"</span> << G4endl;
|
|---|
| 353 | 00352 G4cout << <span class="stringliteral">" becomes to Idle."</span> << G4endl;
|
|---|
| 354 | 00353 } <span class="keywordflow">else</span> {
|
|---|
| 355 | 00354 exitSession = <span class="keyword">true</span>;
|
|---|
| 356 | 00355 }
|
|---|
| 357 | 00356
|
|---|
| 358 | 00357 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( command(0,4) == <span class="stringliteral">"cont"</span> ) {
|
|---|
| 359 | 00358
|
|---|
| 360 | 00359 exitPause = <span class="keyword">true</span>;
|
|---|
| 361 | 00360
|
|---|
| 362 | 00361 } <span class="keywordflow">else</span> {
|
|---|
| 363 | 00362
|
|---|
| 364 | 00363 <a class="code" href="classG4VBasicShell.html#b7">ExecuteCommand</a> (<a class="code" href="classG4VBasicShell.html#b0">ModifyToFullPathCommand</a>(a_string));
|
|---|
| 365 | 00364
|
|---|
| 366 | 00365 }
|
|---|
| 367 | 00366 }
|
|---|
| 368 | <a name="l00367"></a><a class="code" href="classG4VBasicShell.html#b11">00367</a> <span class="keywordtype">void</span> <a class="code" href="classG4VBasicShell.html#b11">G4VBasicShell::ShowCurrent</a>(G4String newCommand)
|
|---|
| 369 | 00368 {
|
|---|
| 370 | 00369 G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 371 | 00370 <span class="keywordflow">if</span>(UI==NULL) <span class="keywordflow">return</span>;
|
|---|
| 372 | 00371 G4String comString = newCommand(1,newCommand.length()-1);
|
|---|
| 373 | 00372 G4String theCommand = <a class="code" href="classG4VBasicShell.html#b0">ModifyToFullPathCommand</a>(comString);
|
|---|
| 374 | 00373 G4String curV = UI->GetCurrentValues(theCommand);
|
|---|
| 375 | 00374 <span class="keywordflow">if</span>( ! curV.isNull() ) {
|
|---|
| 376 | 00375 G4cout << <span class="stringliteral">"Current value(s) of the parameter(s) : "</span> << curV << G4endl;
|
|---|
| 377 | 00376 }
|
|---|
| 378 | 00377 }
|
|---|
| 379 | <a name="l00378"></a><a class="code" href="classG4VBasicShell.html#b12">00378</a> <span class="keywordtype">void</span> <a class="code" href="classG4VBasicShell.html#b12">G4VBasicShell::ChangeDirectoryCommand</a>(G4String newCommand)
|
|---|
| 380 | 00379 {
|
|---|
| 381 | 00380 G4String prefix;
|
|---|
| 382 | 00381 <span class="keywordflow">if</span>( newCommand.length() <= 3 ) {
|
|---|
| 383 | 00382 prefix = <span class="stringliteral">"/"</span>;
|
|---|
| 384 | 00383 } <span class="keywordflow">else</span> {
|
|---|
| 385 | 00384 G4String aNewPrefix = newCommand(3,newCommand.length()-3);
|
|---|
| 386 | 00385 prefix = aNewPrefix.strip(G4String::both);
|
|---|
| 387 | 00386 }
|
|---|
| 388 | 00387 <span class="keywordflow">if</span>(!<a class="code" href="classG4VBasicShell.html#b2">ChangeDirectory</a>(prefix)) {
|
|---|
| 389 | 00388 G4cout << <span class="stringliteral">"directory <"</span> << prefix << <span class="stringliteral">"> not found."</span> << G4endl;
|
|---|
| 390 | 00389 }
|
|---|
| 391 | 00390 }
|
|---|
| 392 | <a name="l00391"></a><a class="code" href="classG4VBasicShell.html#b13">00391</a> <span class="keywordtype">void</span> <a class="code" href="classG4VBasicShell.html#b13">G4VBasicShell::ListDirectory</a>(G4String newCommand)
|
|---|
| 393 | 00392 {
|
|---|
| 394 | 00393 G4String targetDir;
|
|---|
| 395 | 00394 <span class="keywordflow">if</span>( newCommand.length() <= 3 ) {
|
|---|
| 396 | 00395 targetDir = <a class="code" href="classG4VBasicShell.html#b1">GetCurrentWorkingDirectory</a>();
|
|---|
| 397 | 00396 } <span class="keywordflow">else</span> {
|
|---|
| 398 | 00397 G4String newPrefix = newCommand(3,newCommand.length()-3);
|
|---|
| 399 | 00398 targetDir = newPrefix.strip(G4String::both);
|
|---|
| 400 | 00399 }
|
|---|
| 401 | 00400 G4UIcommandTree* commandTree = <a class="code" href="classG4VBasicShell.html#b3">FindDirectory</a>( targetDir );
|
|---|
| 402 | 00401 <span class="keywordflow">if</span>( commandTree == NULL ) {
|
|---|
| 403 | 00402 G4cout << <span class="stringliteral">"Directory <"</span> << targetDir << <span class="stringliteral">"> is not found."</span> << G4endl;
|
|---|
| 404 | 00403 } <span class="keywordflow">else</span> {
|
|---|
| 405 | 00404 commandTree->ListCurrent();
|
|---|
| 406 | 00405 }
|
|---|
| 407 | 00406 }
|
|---|
| 408 | <a name="l00407"></a><a class="code" href="classG4VBasicShell.html#b14">00407</a> <span class="keywordtype">void</span> <a class="code" href="classG4VBasicShell.html#b14">G4VBasicShell::TerminalHelp</a>(G4String newCommand)
|
|---|
| 409 | 00408 {
|
|---|
| 410 | 00409 G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 411 | 00410 <span class="keywordflow">if</span>(UI==NULL) <span class="keywordflow">return</span>;
|
|---|
| 412 | 00411 G4UIcommandTree * treeTop = UI->GetTree();
|
|---|
| 413 | 00412 size_t i = newCommand.index(<span class="stringliteral">" "</span>);
|
|---|
| 414 | 00413 <span class="keywordflow">if</span>( i != std::string::npos )
|
|---|
| 415 | 00414 {
|
|---|
| 416 | 00415 G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
|
|---|
| 417 | 00416 newValue.strip(G4String::both);
|
|---|
| 418 | 00417 G4String targetCom = <a class="code" href="classG4VBasicShell.html#b0">ModifyToFullPathCommand</a>( newValue );
|
|---|
| 419 | 00418 G4UIcommand* theCommand = treeTop->FindPath( targetCom );
|
|---|
| 420 | 00419 <span class="keywordflow">if</span>( theCommand != NULL )
|
|---|
| 421 | 00420 {
|
|---|
| 422 | 00421 theCommand->List();
|
|---|
| 423 | 00422 <span class="keywordflow">return</span>;
|
|---|
| 424 | 00423 }
|
|---|
| 425 | 00424 <span class="keywordflow">else</span>
|
|---|
| 426 | 00425 {
|
|---|
| 427 | 00426 G4cout << <span class="stringliteral">"Command <"</span> << newValue << <span class="stringliteral">" is not found."</span> << G4endl;
|
|---|
| 428 | 00427 <span class="keywordflow">return</span>;
|
|---|
| 429 | 00428 }
|
|---|
| 430 | 00429 }
|
|---|
| 431 | 00430
|
|---|
| 432 | 00431 G4UIcommandTree * floor[10];
|
|---|
| 433 | 00432 floor[0] = treeTop;
|
|---|
| 434 | 00433 G4int iFloor = 0;
|
|---|
| 435 | 00434 size_t prefixIndex = 1;
|
|---|
| 436 | 00435 G4String prefix = <a class="code" href="classG4VBasicShell.html#b1">GetCurrentWorkingDirectory</a>();
|
|---|
| 437 | 00436 <span class="keywordflow">while</span>( prefixIndex < prefix.length()-1 )
|
|---|
| 438 | 00437 {
|
|---|
| 439 | 00438 size_t ii = prefix.index(<span class="stringliteral">"/"</span>,prefixIndex);
|
|---|
| 440 | 00439 floor[iFloor+1] =
|
|---|
| 441 | 00440 floor[iFloor]->GetTree(G4String(prefix(0,ii+1)));
|
|---|
| 442 | 00441 prefixIndex = ii+1;
|
|---|
| 443 | 00442 iFloor++;
|
|---|
| 444 | 00443 }
|
|---|
| 445 | 00444 floor[iFloor]->ListCurrentWithNum();
|
|---|
| 446 | 00445 <span class="comment">// 1998 Oct 2 non-number input</span>
|
|---|
| 447 | 00446 <span class="keywordflow">while</span>(1){
|
|---|
| 448 | 00447 <span class="comment">//G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<std::flush;</span>
|
|---|
| 449 | 00448 G4cout << G4endl << <span class="stringliteral">"Type the number ( 0:end, -n:n level back ) : "</span><<G4endl;
|
|---|
| 450 | 00449 G4int i;
|
|---|
| 451 | 00450 <span class="keywordflow">if</span>(!<a class="code" href="classG4VBasicShell.html#b8">GetHelpChoice</a>(i)){
|
|---|
| 452 | 00451 G4cout << G4endl << <span class="stringliteral">"Not a number, once more"</span> << G4endl;
|
|---|
| 453 | 00452 <span class="keywordflow">continue</span>;
|
|---|
| 454 | 00453 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( i < 0 ){
|
|---|
| 455 | 00454 iFloor += i;
|
|---|
| 456 | 00455 <span class="keywordflow">if</span>( iFloor < 0 ) iFloor = 0;
|
|---|
| 457 | 00456 floor[iFloor]->ListCurrentWithNum();
|
|---|
| 458 | 00457 <span class="keywordflow">continue</span>;
|
|---|
| 459 | 00458 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(i == 0) {
|
|---|
| 460 | 00459 <span class="keywordflow">break</span>;
|
|---|
| 461 | 00460 } <span class="keywordflow">else</span> <span class="keywordflow">if</span>( i > 0 ) {
|
|---|
| 462 | 00461 G4int n_tree = floor[iFloor]->GetTreeEntry();
|
|---|
| 463 | 00462 <span class="keywordflow">if</span>( i > n_tree )
|
|---|
| 464 | 00463 {
|
|---|
| 465 | 00464 <span class="keywordflow">if</span>( i <= n_tree + floor[iFloor]->GetCommandEntry() )
|
|---|
| 466 | 00465 {
|
|---|
| 467 | 00466 floor[iFloor]->GetCommand(i-n_tree)->List();
|
|---|
| 468 | 00467 }
|
|---|
| 469 | 00468 }
|
|---|
| 470 | 00469 <span class="keywordflow">else</span>
|
|---|
| 471 | 00470 {
|
|---|
| 472 | 00471 floor[iFloor+1] = floor[iFloor]->GetTree(i);
|
|---|
| 473 | 00472 iFloor++;
|
|---|
| 474 | 00473 floor[iFloor]->ListCurrentWithNum();
|
|---|
| 475 | 00474 }
|
|---|
| 476 | 00475 }
|
|---|
| 477 | 00476 }
|
|---|
| 478 | 00477 G4cout << <span class="stringliteral">"Exit from HELP."</span> << G4endl << G4endl;
|
|---|
| 479 | 00478 <span class="comment">//G4cout << G4endl;</span>
|
|---|
| 480 | 00479 <a class="code" href="classG4VBasicShell.html#b9">ExitHelp</a>();
|
|---|
| 481 | 00480 }
|
|---|
| 482 | 00481
|
|---|
| 483 | 00482
|
|---|
| 484 | 00483
|
|---|
| 485 | 00484
|
|---|
| 486 | 00485
|
|---|
| 487 | 00486
|
|---|
| 488 | 00487
|
|---|
| 489 | 00488
|
|---|
| 490 | 00489
|
|---|
| 491 | 00490
|
|---|
| 492 | 00491
|
|---|
| 493 | 00492
|
|---|
| 494 | </pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Jun 22 11:07:02 2007 by
|
|---|
| 495 | <a href="http://www.doxygen.org/index.html">
|
|---|
| 496 | <img src="doxygen.png" alt="doxygen" align="middle" border=0 >
|
|---|
| 497 | </a>1.3.4 </small></address>
|
|---|
| 498 | </body>
|
|---|
| 499 | </html>
|
|---|