source: trunk/geant4/interfaces/html/G4VUIshell_8cc-source.html @ 571

Last change on this file since 571 was 571, checked in by garnier, 17 years ago

r581@mac-90108: laurentgarnier | 2007-08-17 17:30:26 +0200
deplacement de frame

  • Property svn:mime-type set to text/html
File size: 22.0 KB
Line 
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>G4VUIshell.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&nbsp;Page</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div>
8<h1>G4VUIshell.cc</h1><a href="G4VUIshell_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">//</span>
900002 <span class="comment">// ********************************************************************</span>
1000003 <span class="comment">// * License and Disclaimer                                           *</span>
1100004 <span class="comment">// *                                                                  *</span>
1200005 <span class="comment">// * The  Geant4 software  is  copyright of the Copyright Holders  of *</span>
1300006 <span class="comment">// * the Geant4 Collaboration.  It is provided  under  the terms  and *</span>
1400007 <span class="comment">// * conditions of the Geant4 Software License,  included in the file *</span>
1500008 <span class="comment">// * LICENSE and available at  http://cern.ch/geant4/license .  These *</span>
1600009 <span class="comment">// * include a list of copyright holders.                             *</span>
1700010 <span class="comment">// *                                                                  *</span>
1800011 <span class="comment">// * Neither the authors of this software system, nor their employing *</span>
1900012 <span class="comment">// * institutes,nor the agencies providing financial support for this *</span>
2000013 <span class="comment">// * work  make  any representation or  warranty, express or implied, *</span>
2100014 <span class="comment">// * regarding  this  software system or assume any liability for its *</span>
2200015 <span class="comment">// * use.  Please see the license in the file  LICENSE  and URL above *</span>
2300016 <span class="comment">// * for the full disclaimer and the limitation of liability.         *</span>
2400017 <span class="comment">// *                                                                  *</span>
2500018 <span class="comment">// * This  code  implementation is the result of  the  scientific and *</span>
2600019 <span class="comment">// * technical work of the GEANT4 collaboration.                      *</span>
2700020 <span class="comment">// * By using,  copying,  modifying or  distributing the software (or *</span>
2800021 <span class="comment">// * any work based  on the software)  you  agree  to acknowledge its *</span>
2900022 <span class="comment">// * use  in  resulting  scientific  publications,  and indicate your *</span>
3000023 <span class="comment">// * acceptance of all terms of the Geant4 Software license.          *</span>
3100024 <span class="comment">// ********************************************************************</span>
3200025 <span class="comment">//</span>
3300026 <span class="comment">//</span>
3400027 <span class="comment">// $Id: G4VUIshell.cc,v 1.9 2006/06/29 19:09:59 gunter Exp $</span>
3500028 <span class="comment">// GEANT4 tag $Name: geant4-08-01-patch-01 $</span>
3600029 <span class="comment">//</span>
3700030
3800031 <span class="preprocessor">#include "G4UImanager.hh"</span>
3900032 <span class="preprocessor">#include "G4UIcommand.hh"</span>
4000033 <span class="preprocessor">#include "G4UIcommandTree.hh"</span>
4100034 <span class="preprocessor">#include "G4StateManager.hh"</span>
4200035 <span class="preprocessor">#include "G4UIcommandStatus.hh"</span>
4300036 <span class="preprocessor">#include "<a class="code" href="G4VUIshell_8hh.html">G4VUIshell.hh</a>"</span>
4400037 <span class="preprocessor">#include "<a class="code" href="G4UIArrayString_8hh.html">G4UIArrayString.hh</a>"</span>
4500038
4600039 <span class="comment">// terminal color string</span>
47<a name="l00040"></a><a class="code" href="G4VUIshell_8cc.html#a0">00040</a> <span class="keyword">static</span> <span class="keyword">const</span> G4String <a class="code" href="G4VUIshell_8cc.html#a0">strESC</a>= <span class="charliteral">'\033'</span>;
48<a name="l00041"></a><a class="code" href="G4VUIshell_8cc.html#a1">00041</a> <span class="keyword">static</span> <span class="keyword">const</span> G4String <a class="code" href="G4VUIshell_8cc.html#a1">TermColorString</a>[8] ={
4900042   <a class="code" href="G4VUIshell_8cc.html#a0">strESC</a>+<span class="stringliteral">"[30m"</span>, <a class="code" href="G4VUIshell_8cc.html#a0">strESC</a>+<span class="stringliteral">"[31m"</span>, <a class="code" href="G4VUIshell_8cc.html#a0">strESC</a>+<span class="stringliteral">"[32m"</span>, <a class="code" href="G4VUIshell_8cc.html#a0">strESC</a>+<span class="stringliteral">"[33m"</span>,
5000043   <a class="code" href="G4VUIshell_8cc.html#a0">strESC</a>+<span class="stringliteral">"[34m"</span>, <a class="code" href="G4VUIshell_8cc.html#a0">strESC</a>+<span class="stringliteral">"[35m"</span>, <a class="code" href="G4VUIshell_8cc.html#a0">strESC</a>+<span class="stringliteral">"[36m"</span>, <a class="code" href="G4VUIshell_8cc.html#a0">strESC</a>+<span class="stringliteral">"[37m"</span>
5100044 };
5200045
53<a name="l00047"></a><a class="code" href="classG4VUIshell.html#a0">00047</a> <a class="code" href="classG4VUIshell.html#a0">G4VUIshell::G4VUIshell</a>(<span class="keyword">const</span> G4String&amp; prompt)
5400048   : promptSetting(prompt), promptString(""), nColumn(80), 
5500049     lsColorFlag(FALSE), directoryColor(<a class="code" href="G4VUIshell_8hh.html#a8a0">BLACK</a>), commandColor(<a class="code" href="G4VUIshell_8hh.html#a8a0">BLACK</a>),
5600050     currentCommandDir("/")
5700052 {
5800053 }
5900054
60<a name="l00056"></a><a class="code" href="classG4VUIshell.html#a1">00056</a> <a class="code" href="classG4VUIshell.html#a1">G4VUIshell::~G4VUIshell</a>()
6100058 {
6200059 }
6300060
64<a name="l00062"></a><a class="code" href="classG4VUIshell.html#b0">00062</a> <span class="keywordtype">void</span> <a class="code" href="classG4VUIshell.html#b0">G4VUIshell::MakePrompt</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* msg)
6500063
6600064 {
6700065   <span class="keywordflow">if</span>(<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>.length()&lt;=1) {
6800066     <a class="code" href="classG4VUIshell.html#p1">promptString</a>= <a class="code" href="classG4VUIshell.html#p0">promptSetting</a>;
6900067     <span class="keywordflow">return</span>;
7000068   }
7100069
7200070   <a class="code" href="classG4VUIshell.html#p1">promptString</a>=<span class="stringliteral">""</span>;
7300071   G4int i;
7400072   <span class="keywordflow">for</span>(i=0; i&lt;G4int(<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>.length())-1; i++){
7500073     <span class="keywordflow">if</span>(<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>[(size_t)i]==<span class="charliteral">'%'</span>){
7600074       <span class="keywordflow">switch</span> (<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>[(size_t)(i+1)]) {
7700075       <span class="keywordflow">case</span> <span class="charliteral">'s'</span><span class="comment">// current application status</span>
7800076         {
7900077            G4String stateStr;
8000078            <span class="keywordflow">if</span>(msg)
8100079            { stateStr = msg; }
8200080            <span class="keywordflow">else</span>
8300081            {
8400082              G4StateManager* statM= G4StateManager::GetStateManager();
8500083              stateStr= statM-&gt; GetStateString(statM-&gt;GetCurrentState());
8600084            }
8700085            <a class="code" href="classG4VUIshell.html#p1">promptString</a>.append(stateStr);
8800086            i++;
8900087         }
9000088         <span class="keywordflow">break</span>;
9100089       <span class="keywordflow">case</span> <span class="charliteral">'/'</span><span class="comment">// current working directory</span>
9200090         <a class="code" href="classG4VUIshell.html#p1">promptString</a>.append(<a class="code" href="classG4VUIshell.html#p6">currentCommandDir</a>);
9300091         i++;
9400092         <span class="keywordflow">break</span>;
9500093       <span class="keywordflow">default</span>:
9600094         <a class="code" href="classG4VUIshell.html#p1">promptString</a>.append(G4String(<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>[(size_t)i]));
9700095         <span class="keywordflow">break</span>;
9800096       }           
9900097     } <span class="keywordflow">else</span> {
10000098       <a class="code" href="classG4VUIshell.html#p1">promptString</a>.append(G4String(<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>[(size_t)i]));
10100099     }
10200100   }
10300101
10400102   <span class="comment">// append last chaacter</span>
10500103   <span class="keywordflow">if</span>(i == G4int(<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>.length())-1)
10600104     <a class="code" href="classG4VUIshell.html#p1">promptString</a>.append(G4String(<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>[(size_t)i]));
10700105 }
10800106
10900107
11000108 <span class="comment">// --------------------------------------------------------------------</span>
11100109 <span class="comment">//      G4command operations</span>
11200110 <span class="comment">// --------------------------------------------------------------------</span>
113<a name="l00112"></a><a class="code" href="classG4VUIshell.html#b1">00112</a> <span class="comment"></span>G4UIcommandTree* <a class="code" href="classG4VUIshell.html#b1">G4VUIshell::GetCommandTree</a>(<span class="keyword">const</span> G4String&amp; input) <span class="keyword">const</span>
11400114 {
11500115   G4UImanager* UI= G4UImanager::GetUIpointer();
11600116
11700117   G4UIcommandTree* cmdTree= UI-&gt; GetTree();  <span class="comment">// root tree</span>
11800118
11900119   G4String absPath= input; <span class="comment">// G4String::strip() CONST !!</span>
12000120   absPath= GetAbsCommandDirPath(absPath.strip(G4String::both));
12100121
12200122   <span class="comment">// parsing absolute path ...</span>
12300123   <span class="keywordflow">if</span>(absPath.length()==0) <span class="keywordflow">return</span> NULL;
12400124   <span class="keywordflow">if</span>(absPath[absPath.length()-1] != <span class="charliteral">'/'</span>) <span class="keywordflow">return</span> NULL; <span class="comment">// error??</span>
12500125   <span class="keywordflow">if</span>(absPath==<span class="stringliteral">"/"</span>) <span class="keywordflow">return</span> cmdTree;
12600126
12700127   <span class="keywordflow">for</span>(G4int indx=1; indx&lt;G4int(absPath.length())-1; ) {
12800128     G4int jslash= absPath.index(<span class="stringliteral">"/"</span>, indx);  <span class="comment">// search index begin with "/" </span>
12900129     <span class="keywordflow">if</span>(jslash != G4int(G4String::npos)) {
13000130       <span class="keywordflow">if</span>(cmdTree != NULL)
13100131         cmdTree= cmdTree-&gt; GetTree(G4String(absPath(0,jslash+1)));
13200132     }
13300133     indx= jslash+1;
13400134   }
13500135
13600136   <span class="keywordflow">if</span>(cmdTree == NULL) <span class="keywordflow">return</span> NULL;
13700137   <span class="keywordflow">else</span> <span class="keywordflow">return</span> cmdTree;
13800138 }
13900139
140<a name="l00141"></a><a class="code" href="classG4VUIshell.html#b2">00141</a> G4String <a class="code" href="classG4VUIshell.html#b2">G4VUIshell::GetAbsCommandDirPath</a>(<span class="keyword">const</span> G4String&amp; apath) <span class="keyword">const</span>
14100143 {
14200144   <span class="keywordflow">if</span>(apath.empty()) <span class="keywordflow">return</span> apath;  <span class="comment">// null string</span>
14300145
14400146   <span class="comment">// if "apath" does not start with "/", </span>
14500147   <span class="comment">//   then it is treared as relative path</span>
14600148   G4String bpath= apath;
14700149   <span class="keywordflow">if</span>(apath[(size_t)0] != <span class="charliteral">'/'</span>) bpath= currentCommandDir + apath;
14800150
14900151   <span class="comment">// parsing...</span>
15000152   G4String absPath= <span class="stringliteral">"/"</span>;
15100153   <span class="keywordflow">for</span>(G4int indx=1; indx&lt;=G4int(bpath.length())-1; ) {
15200154     G4int jslash= bpath.index(<span class="stringliteral">"/"</span>, indx);  <span class="comment">// search index begin with "/"</span>
15300155     <span class="keywordflow">if</span>(jslash != G4int(G4String::npos)) {
15400156       <span class="keywordflow">if</span>(bpath(indx,jslash-indx) == <span class="stringliteral">".."</span>){  <span class="comment">// directory up</span>
15500157         <span class="keywordflow">if</span>(absPath.length() &gt;=1) {
15600158           absPath.remove(absPath.length()-1);  <span class="comment">// remove last  "/"</span>
15700159           G4int jpre= absPath.last(<span class="charliteral">'/'</span>);
15800160           <span class="keywordflow">if</span>(jpre != G4int(G4String::npos)) absPath.remove(jpre+1);
15900161         }
16000162       } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(bpath(indx,jslash-indx) == <span class="stringliteral">"."</span>){  <span class="comment">// nothing to do</span>
16100163       } <span class="keywordflow">else</span> { <span class="comment">// add</span>
16200164         <span class="keywordflow">if</span>( !(jslash==indx &amp;&amp; bpath(indx)==<span class="charliteral">'/'</span>) ) <span class="comment">// truncate "////"</span>
16300165           absPath+= bpath(indx, jslash-indx+1);
16400166           <span class="comment">// better to be check directory existence. (it costs!)</span>
16500167       }
16600168     } <span class="keywordflow">else</span> { <span class="comment">// directory ONLY (ignore non-"/" terminated string)</span>
16700169     }
16800170     indx= jslash+1;
16900171   }
17000172   <span class="keywordflow">return</span>  absPath;
17100173 }
17200174
17300175
174<a name="l00177"></a><a class="code" href="classG4VUIshell.html#b3">00177</a> G4String <a class="code" href="classG4VUIshell.html#b3">G4VUIshell::GetCommandPathTail</a>(<span class="keyword">const</span> G4String&amp; apath) <span class="keyword">const</span>
17500179 {   <span class="comment">// xxx/xxx/zzz -&gt; zzz, trancate /// -&gt; /</span>
17600180   <span class="keywordflow">if</span>(apath.empty()) <span class="keywordflow">return</span> apath;
17700181
17800182   G4int lstr= apath.length();
17900183
18000184   <span class="comment">// for trancating "/"</span>
18100185   G4bool Qsla= FALSE;
18200186   <span class="keywordflow">if</span>(apath[(size_t)(lstr-1)]==<span class="charliteral">'/'</span>) Qsla= TRUE;
18300187
18400188   <span class="comment">// searching last '/' from tail</span>
18500189   G4int indx= -1;
18600190   <span class="keywordflow">for</span>(G4int i=lstr-1; i&gt;=0; i--) {
18700191     <span class="keywordflow">if</span>(Qsla &amp;&amp; apath[(size_t)i]!=<span class="charliteral">'/'</span>) Qsla= FALSE; <span class="comment">// break "/" flag!!</span>
18800192     <span class="keywordflow">if</span>(apath[(size_t)i]==<span class="charliteral">'/'</span> &amp;&amp; !Qsla) {
18900193       indx= i;
19000194       <span class="keywordflow">break</span>;
19100195     }
19200196   }
19300197
19400198   <span class="keywordflow">if</span>(indx==-1) <span class="keywordflow">return</span> apath;  <span class="comment">// not found</span>
19500199
19600200   <span class="keywordflow">if</span>(indx==0  &amp;&amp; lstr==1) { <span class="comment">// "/"</span>
19700201     G4String nullStr;
19800202     <span class="keywordflow">return</span> nullStr;
19900203   } <span class="keywordflow">else</span> { 
20000204     <span class="comment">//G4String newPath= apath(indx+1,lstr-indx-1); </span>
20100205     G4String newPath= apath;
20200206     newPath= newPath(indx+1,lstr-indx-1);
20300207     <span class="keywordflow">return</span> newPath;
20400208   }
20500209 }
20600210
20700211 <span class="comment">// --------------------------------------------------------------------</span>
20800212 <span class="comment">//      shell commands</span>
20900213 <span class="comment">// --------------------------------------------------------------------</span>
210<a name="l00215"></a><a class="code" href="classG4VUIshell.html#a6">00215</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="classG4VUIshell.html#a6">G4VUIshell::ListCommand</a>(<span class="keyword">const</span> G4String&amp; dir,
21100216                              <span class="keyword">const</span> G4String&amp; candidate) <span class="keyword">const</span>
21200218 {
21300219   <span class="comment">// specified directpry</span>
21400220   G4String input= dir; <span class="comment">// ...</span>
21500221   input= input.strip(G4String::both);
21600222
21700223   <span class="comment">// command tree of "user specified directory"</span>
21800224   G4String vpath= currentCommandDir;
21900225   G4String vcmd;
22000226
22100227   G4int len= input.length();
22200228   <span class="keywordflow">if</span>(! input.empty()) {
22300229     G4int indx= -1;
22400230     <span class="keywordflow">for</span>(G4int i=len-1; i&gt;=0; i--) { <span class="comment">// search last '/'</span>
22500231       <span class="keywordflow">if</span>(input[(size_t)i]==<span class="charliteral">'/'</span>) {
22600232         indx= i;
22700233         <span class="keywordflow">break</span>;
22800234       }   
22900235     }
23000236     <span class="comment">// get abs. path</span>
23100237     <span class="keywordflow">if</span>(indx != -1) vpath= GetAbsCommandDirPath(input(0,indx+1));
23200238     <span class="keywordflow">if</span>(!(indx==0  &amp;&amp; len==1)) vcmd= input(indx+1,len-indx-1); <span class="comment">// care for "/"</span>
23300239   }
23400240
23500241   <span class="comment">// check "vcmd" is directory?</span>
23600242   G4String inputpath= vpath+vcmd;
23700243   <span class="keywordflow">if</span>(! vcmd.empty()){
23800244     G4String tmpstr= inputpath + <span class="stringliteral">"/"</span>;
23900245     <span class="keywordflow">if</span>(GetCommandTree(tmpstr) != NULL) {
24000246       vpath= tmpstr;
24100247       vcmd= <span class="stringliteral">""</span>;
24200248     }
24300249   }
24400250       
24500251   <span class="comment">// check "vpath" directory exists?</span>
24600252   G4UIcommandTree* atree= GetCommandTree(vpath); 
24700253   <span class="keywordflow">if</span>(atree == NULL) {
24800254     G4cout &lt;&lt; <span class="stringliteral">"&lt;"</span> &lt;&lt; input &lt;&lt; <span class="stringliteral">"&gt;: No such directory"</span> &lt;&lt; G4endl;
24900255     <span class="keywordflow">return</span>;
25000256   }
25100257
25200258   <span class="comment">// list matched directories/commands</span>
25300259   G4String stream;
25400260   G4bool isMatch= FALSE;
25500261
25600262   G4int Ndir= atree-&gt; GetTreeEntry();
25700263   G4int Ncmd= atree-&gt; GetCommandEntry();
25800264   <span class="keywordflow">if</span>(Ndir==0 &amp;&amp; Ncmd==0) <span class="keywordflow">return</span><span class="comment">// no contents</span>
25900265   
26000266   <span class="comment">// directory ...</span>
26100267   <span class="keywordflow">for</span>(G4int idir=1; idir&lt;=Ndir; idir++) {
26200268     <span class="keywordflow">if</span>(idir==1 &amp;&amp; lsColorFlag) stream+= <a class="code" href="G4VUIshell_8cc.html#a1">TermColorString</a>[directoryColor];
26300269     G4String fpdir= atree-&gt; GetTree(idir)-&gt; GetPathName();
26400270     <span class="comment">// matching test</span>
26500271     <span class="keywordflow">if</span>(candidate.empty()) { <span class="comment">// list all</span>
26600272       <span class="keywordflow">if</span>(vcmd==<span class="stringliteral">""</span> || fpdir==inputpath) {
26700273         stream+= GetCommandPathTail(fpdir); stream+= <span class="stringliteral">"  "</span>;
26800274         isMatch= TRUE;
26900275       }
27000276     } <span class="keywordflow">else</span> { <span class="comment">// list only matched with candidate</span>
27100277       <span class="keywordflow">if</span>( fpdir.index(candidate, 0) == 0) {
27200278         stream+= GetCommandPathTail(fpdir); stream+= <span class="stringliteral">"  "</span>;
27300279       }
27400280     }
27500281   }
27600282   
27700283   <span class="comment">// command ...</span>
27800284   <span class="keywordflow">for</span>(G4int icmd=1; icmd&lt;=Ncmd; icmd++){
27900285     <span class="keywordflow">if</span>(icmd==1 &amp;&amp; lsColorFlag) stream+= <a class="code" href="G4VUIshell_8cc.html#a1">TermColorString</a>[commandColor];
28000286     G4String fpcmd= atree-&gt; GetPathName() +
28100287              atree-&gt; GetCommand(icmd) -&gt; GetCommandName();
28200288     <span class="comment">// matching test</span>
28300289     <span class="keywordflow">if</span>(candidate.empty()) { <span class="comment">// list all</span>
28400290       <span class="keywordflow">if</span>(vcmd==<span class="stringliteral">""</span> || fpcmd==inputpath) {
28500291         stream+= GetCommandPathTail(fpcmd); stream+= <span class="stringliteral">"*  "</span>;
28600292         isMatch= TRUE;
28700293       }
28800294     } <span class="keywordflow">else</span> {  <span class="comment">// list only matched with candidate</span>
28900295       <span class="keywordflow">if</span>( fpcmd.index(candidate, 0) == 0) {
29000296         stream+= GetCommandPathTail(fpcmd); stream+= <span class="stringliteral">"*  "</span>;
29100297       }
29200298     }
29300299   }
29400300   
29500301   <span class="comment">// waring : not matched</span>
29600302   <span class="keywordflow">if</span>(!isMatch &amp;&amp; candidate.empty())
29700303     G4cout &lt;&lt; <span class="stringliteral">"&lt;"</span> &lt;&lt; input
29800304            &lt;&lt; <span class="stringliteral">"&gt;: No such directory or command"</span> &lt;&lt; std::flush;
29900305
30000306   <span class="comment">// display</span>
30100307   <a class="code" href="classG4UIArrayString.html">G4UIArrayString</a> arrayString(stream);
30200308   arrayString.<a class="code" href="classG4UIArrayString.html#a2">Show</a>(nColumn);
30300309 }
304</pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Jun 22 11:07:02 2007 by
305<a href="http://www.doxygen.org/index.html">
306<img src="doxygen.png" alt="doxygen" align="middle" border=0 > 
307</a>1.3.4 </small></address>
308</body>
309</html>
Note: See TracBrowser for help on using the repository browser.