| 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>G4UItcsh.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>G4UItcsh.cc</h1><a href="G4UItcsh_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: G4UItcsh.cc,v 1.12 2006/06/29 19:09:54 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">#ifndef WIN32</span>
|
|---|
| 39 | 00032 <span class="preprocessor"></span>
|
|---|
| 40 | 00033 <span class="preprocessor">#include "G4Types.hh"</span>
|
|---|
| 41 | 00034 <span class="preprocessor">#include "G4StateManager.hh"</span>
|
|---|
| 42 | 00035 <span class="preprocessor">#include "G4UIcommandStatus.hh"</span>
|
|---|
| 43 | 00036 <span class="preprocessor">#include "<a class="code" href="G4UItcsh_8hh.html">G4UItcsh.hh</a>"</span>
|
|---|
| 44 | 00037 <span class="preprocessor">#include <ctype.h></span>
|
|---|
| 45 | 00038 <span class="preprocessor">#include <sstream></span>
|
|---|
| 46 | 00039
|
|---|
| 47 | 00040 <span class="comment">// ASCII character code</span>
|
|---|
| 48 | <a name="l00041"></a><a class="code" href="G4UItcsh_8cc.html#a0">00041</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a0">AsciiCtrA</a> = <span class="charliteral">'\001'</span>;
|
|---|
| 49 | <a name="l00042"></a><a class="code" href="G4UItcsh_8cc.html#a1">00042</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a1">AsciiCtrB</a> = <span class="charliteral">'\002'</span>;
|
|---|
| 50 | <a name="l00043"></a><a class="code" href="G4UItcsh_8cc.html#a2">00043</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a2">AsciiCtrC</a> = <span class="charliteral">'\003'</span>;
|
|---|
| 51 | <a name="l00044"></a><a class="code" href="G4UItcsh_8cc.html#a3">00044</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a3">AsciiCtrD</a> = <span class="charliteral">'\004'</span>;
|
|---|
| 52 | <a name="l00045"></a><a class="code" href="G4UItcsh_8cc.html#a4">00045</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a4">AsciiCtrE</a> = <span class="charliteral">'\005'</span>;
|
|---|
| 53 | <a name="l00046"></a><a class="code" href="G4UItcsh_8cc.html#a5">00046</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a5">AsciiCtrF</a> = <span class="charliteral">'\006'</span>;
|
|---|
| 54 | <a name="l00047"></a><a class="code" href="G4UItcsh_8cc.html#a6">00047</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a6">AsciiCtrK</a> = <span class="charliteral">'\013'</span>;
|
|---|
| 55 | <a name="l00048"></a><a class="code" href="G4UItcsh_8cc.html#a7">00048</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a7">AsciiCtrL</a> = <span class="charliteral">'\014'</span>;
|
|---|
| 56 | <a name="l00049"></a><a class="code" href="G4UItcsh_8cc.html#a8">00049</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a8">AsciiCtrN</a> = <span class="charliteral">'\016'</span>;
|
|---|
| 57 | <a name="l00050"></a><a class="code" href="G4UItcsh_8cc.html#a9">00050</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a9">AsciiCtrP</a> = <span class="charliteral">'\020'</span>;
|
|---|
| 58 | <a name="l00051"></a><a class="code" href="G4UItcsh_8cc.html#a10">00051</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a10">AsciiCtrQ</a> = <span class="charliteral">'\021'</span>;
|
|---|
| 59 | <a name="l00052"></a><a class="code" href="G4UItcsh_8cc.html#a11">00052</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a11">AsciiCtrS</a> = <span class="charliteral">'\023'</span>;
|
|---|
| 60 | <a name="l00053"></a><a class="code" href="G4UItcsh_8cc.html#a12">00053</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a12">AsciiCtrZ</a> = <span class="charliteral">'\032'</span>;
|
|---|
| 61 | <a name="l00054"></a><a class="code" href="G4UItcsh_8cc.html#a13">00054</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a13">AsciiTAB</a> = <span class="charliteral">'\011'</span>;
|
|---|
| 62 | <a name="l00055"></a><a class="code" href="G4UItcsh_8cc.html#a14">00055</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a> = <span class="charliteral">'\010'</span>;
|
|---|
| 63 | <a name="l00056"></a><a class="code" href="G4UItcsh_8cc.html#a15">00056</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a15">AsciiDEL</a> = '\177';
|
|---|
| 64 | <a name="l00057"></a><a class="code" href="G4UItcsh_8cc.html#a16">00057</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> <a class="code" href="G4UItcsh_8cc.html#a16">AsciiESC</a> = <span class="charliteral">'\033'</span>;
|
|---|
| 65 | 00058
|
|---|
| 66 | <a name="l00059"></a><a class="code" href="G4UItcsh_8cc.html#a17">00059</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="G4UItcsh_8cc.html#a17">AsciiPrintableMin</a> = 32;
|
|---|
| 67 | 00060
|
|---|
| 68 | <a name="l00062"></a><a class="code" href="classG4UItcsh.html#a0">00062</a> <a class="code" href="classG4UItcsh.html#a0">G4UItcsh::G4UItcsh</a>(<span class="keyword">const</span> G4String& prompt, G4int maxhist)
|
|---|
| 69 | 00063 : <a class="code" href="classG4VUIshell.html">G4VUIshell</a>(prompt),
|
|---|
| 70 | 00064 commandLine(""), cursorPosition(1),
|
|---|
| 71 | 00065 commandHistory(maxhist), maxHistory(maxhist),
|
|---|
| 72 | 00066 currentHistoryNo(1), relativeHistoryIndex(0)
|
|---|
| 73 | 00068 {
|
|---|
| 74 | 00069 <span class="comment">// get current terminal mode</span>
|
|---|
| 75 | 00070 tcgetattr(0, &<a class="code" href="classG4UItcsh.html#p7">tios</a>);
|
|---|
| 76 | 00071 }
|
|---|
| 77 | 00072
|
|---|
| 78 | <a name="l00074"></a><a class="code" href="classG4UItcsh.html#a1">00074</a> <a class="code" href="classG4UItcsh.html#a1">G4UItcsh::~G4UItcsh</a>()
|
|---|
| 79 | 00076 {
|
|---|
| 80 | 00077 }
|
|---|
| 81 | 00078
|
|---|
| 82 | <a name="l00080"></a><a class="code" href="classG4UItcsh.html#b0">00080</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b0">G4UItcsh::MakePrompt</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* msg)
|
|---|
| 83 | 00082 {
|
|---|
| 84 | 00083 <span class="keywordflow">if</span>(<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>.length()<=1) {
|
|---|
| 85 | 00084 <a class="code" href="classG4VUIshell.html#p1">promptString</a>= <a class="code" href="classG4VUIshell.html#p0">promptSetting</a>;
|
|---|
| 86 | 00085 <span class="keywordflow">return</span>;
|
|---|
| 87 | 00086 }
|
|---|
| 88 | 00087
|
|---|
| 89 | 00088 <a class="code" href="classG4VUIshell.html#p1">promptString</a>=<span class="stringliteral">""</span>;
|
|---|
| 90 | 00089 size_t i;
|
|---|
| 91 | 00090 <span class="keywordflow">for</span>(i=0; i<<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>.length()-1; i++){
|
|---|
| 92 | 00091 <span class="keywordflow">if</span>(<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>[i]==<span class="charliteral">'%'</span>){
|
|---|
| 93 | 00092 <span class="keywordflow">switch</span> (<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>[i+1]) {
|
|---|
| 94 | 00093 <span class="keywordflow">case</span> <span class="charliteral">'s'</span>: <span class="comment">// current application status</span>
|
|---|
| 95 | 00094 {
|
|---|
| 96 | 00095 G4String stateStr;
|
|---|
| 97 | 00096 <span class="keywordflow">if</span>(msg)
|
|---|
| 98 | 00097 { stateStr = msg; }
|
|---|
| 99 | 00098 <span class="keywordflow">else</span>
|
|---|
| 100 | 00099 {
|
|---|
| 101 | 00100 G4StateManager* statM= G4StateManager::GetStateManager();
|
|---|
| 102 | 00101 stateStr= statM-> GetStateString(statM->GetCurrentState());
|
|---|
| 103 | 00102 }
|
|---|
| 104 | 00103 <a class="code" href="classG4VUIshell.html#p1">promptString</a>.append(stateStr);
|
|---|
| 105 | 00104 i++;
|
|---|
| 106 | 00105 }
|
|---|
| 107 | 00106 <span class="keywordflow">break</span>;
|
|---|
| 108 | 00107 <span class="keywordflow">case</span> <span class="charliteral">'/'</span>: <span class="comment">// current working directory</span>
|
|---|
| 109 | 00108 <a class="code" href="classG4VUIshell.html#p1">promptString</a>.append(<a class="code" href="classG4VUIshell.html#p6">currentCommandDir</a>);
|
|---|
| 110 | 00109 i++;
|
|---|
| 111 | 00110 <span class="keywordflow">break</span>;
|
|---|
| 112 | 00111 <span class="keywordflow">case</span> <span class="charliteral">'h'</span>: <span class="comment">// history#</span>
|
|---|
| 113 | 00112 {
|
|---|
| 114 | 00113 std::ostringstream os;
|
|---|
| 115 | 00114 os << <a class="code" href="classG4UItcsh.html#p5">currentHistoryNo</a>;
|
|---|
| 116 | 00115 <a class="code" href="classG4VUIshell.html#p1">promptString</a>.append(os.str());
|
|---|
| 117 | 00116 i++;
|
|---|
| 118 | 00117 }
|
|---|
| 119 | 00118 <span class="keywordflow">break</span>;
|
|---|
| 120 | 00119 <span class="keywordflow">default</span>:
|
|---|
| 121 | 00120 <span class="keywordflow">break</span>;
|
|---|
| 122 | 00121 }
|
|---|
| 123 | 00122 } <span class="keywordflow">else</span> {
|
|---|
| 124 | 00123 <a class="code" href="classG4VUIshell.html#p1">promptString</a>.append(G4String(<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>[i]));
|
|---|
| 125 | 00124 }
|
|---|
| 126 | 00125 }
|
|---|
| 127 | 00126
|
|---|
| 128 | 00127 <span class="comment">// append last chaacter</span>
|
|---|
| 129 | 00128 <span class="keywordflow">if</span>(i == <a class="code" href="classG4VUIshell.html#p0">promptSetting</a>.length()-1)
|
|---|
| 130 | 00129 <a class="code" href="classG4VUIshell.html#p1">promptString</a>.append(G4String(<a class="code" href="classG4VUIshell.html#p0">promptSetting</a>[i]));
|
|---|
| 131 | 00130 }
|
|---|
| 132 | 00131
|
|---|
| 133 | 00132 <span class="comment">// --------------------------------------------------------------------</span>
|
|---|
| 134 | 00133 <span class="comment">// commad line operations</span>
|
|---|
| 135 | 00134 <span class="comment">// --------------------------------------------------------------------</span>
|
|---|
| 136 | <a name="l00136"></a><a class="code" href="classG4UItcsh.html#b2">00136</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b2">G4UItcsh::InitializeCommandLine</a>()
|
|---|
| 137 | 00138 {
|
|---|
| 138 | 00139 <a class="code" href="classG4UItcsh.html#p0">commandLine</a>= <span class="stringliteral">""</span>;
|
|---|
| 139 | 00140 <a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>= 1;
|
|---|
| 140 | 00141 }
|
|---|
| 141 | 00142
|
|---|
| 142 | <a name="l00144"></a><a class="code" href="classG4UItcsh.html#b4">00144</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b4">G4UItcsh::InsertCharacter</a>(<span class="keywordtype">char</span> cc)
|
|---|
| 143 | 00146 {
|
|---|
| 144 | 00147 <span class="keywordflow">if</span>( ! (cc >= <a class="code" href="G4UItcsh_8cc.html#a17">AsciiPrintableMin</a> && isprint(cc)) ) <span class="keywordflow">return</span>;
|
|---|
| 145 | 00148
|
|---|
| 146 | 00149 <span class="comment">// display...</span>
|
|---|
| 147 | 00150 G4cout << cc;
|
|---|
| 148 | 00151 size_t i;
|
|---|
| 149 | 00152 <span class="keywordflow">for</span>(i=<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>-1; i<<a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length() ;i++)
|
|---|
| 150 | 00153 G4cout << <a class="code" href="classG4UItcsh.html#p0">commandLine</a>[i];
|
|---|
| 151 | 00154 <span class="keywordflow">for</span>(i=<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>-1; i<commandLine.length() ;i++)
|
|---|
| 152 | 00155 G4cout << <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a>;
|
|---|
| 153 | 00156 G4cout << std::flush;
|
|---|
| 154 | 00157
|
|---|
| 155 | 00158 <span class="comment">// command line string...</span>
|
|---|
| 156 | 00159 <span class="keywordflow">if</span>(<a class="code" href="classG4UItcsh.html#b1">IsCursorLast</a>()) { <span class="comment">// add</span>
|
|---|
| 157 | 00160 commandLine+= cc;
|
|---|
| 158 | 00161 } <span class="keywordflow">else</span> { <span class="comment">// insert</span>
|
|---|
| 159 | 00162 commandLine.insert(<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>-1, G4String(cc));
|
|---|
| 160 | 00163 }
|
|---|
| 161 | 00164 <a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>++;
|
|---|
| 162 | 00165 }
|
|---|
| 163 | 00166
|
|---|
| 164 | <a name="l00168"></a><a class="code" href="classG4UItcsh.html#b5">00168</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b5">G4UItcsh::BackspaceCharacter</a>()
|
|---|
| 165 | 00170 {
|
|---|
| 166 | 00171 <span class="keywordflow">if</span>(<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>==1) <span class="keywordflow">return</span>;
|
|---|
| 167 | 00172
|
|---|
| 168 | 00173 <span class="comment">// display...</span>
|
|---|
| 169 | 00174 <span class="keywordflow">if</span>(<a class="code" href="classG4UItcsh.html#b1">IsCursorLast</a>()) {
|
|---|
| 170 | 00175 G4cout << <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a> << <span class="charliteral">' '</span> << <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a> << std::flush;
|
|---|
| 171 | 00176 } <span class="keywordflow">else</span> {
|
|---|
| 172 | 00177 G4cout << <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a>;
|
|---|
| 173 | 00178 size_t i;
|
|---|
| 174 | 00179 <span class="keywordflow">for</span>(i=<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>-2; i< <a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length()-1 ;i++){
|
|---|
| 175 | 00180 G4cout << <a class="code" href="classG4UItcsh.html#p0">commandLine</a>[i+1];
|
|---|
| 176 | 00181 }
|
|---|
| 177 | 00182 G4cout << <span class="charliteral">' '</span>;
|
|---|
| 178 | 00183 <span class="keywordflow">for</span>(i=<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>-2; i< <a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length() ;i++){
|
|---|
| 179 | 00184 G4cout << <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a>;
|
|---|
| 180 | 00185 }
|
|---|
| 181 | 00186 G4cout << std::flush;
|
|---|
| 182 | 00187 }
|
|---|
| 183 | 00188
|
|---|
| 184 | 00189 <span class="comment">// command line string...</span>
|
|---|
| 185 | 00190 <a class="code" href="classG4UItcsh.html#p0">commandLine</a>.erase(<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>-2, 1);
|
|---|
| 186 | 00191
|
|---|
| 187 | 00192 <a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>--;
|
|---|
| 188 | 00193 }
|
|---|
| 189 | 00194
|
|---|
| 190 | <a name="l00196"></a><a class="code" href="classG4UItcsh.html#b6">00196</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b6">G4UItcsh::DeleteCharacter</a>()
|
|---|
| 191 | 00198 {
|
|---|
| 192 | 00199 <span class="keywordflow">if</span>(<a class="code" href="classG4UItcsh.html#b1">IsCursorLast</a>()) <span class="keywordflow">return</span>;
|
|---|
| 193 | 00200
|
|---|
| 194 | 00201 <span class="comment">// display...</span>
|
|---|
| 195 | 00202 size_t i;
|
|---|
| 196 | 00203 <span class="keywordflow">for</span>(i=<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>-1; i< <a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length()-1 ;i++){
|
|---|
| 197 | 00204 G4cout << <a class="code" href="classG4UItcsh.html#p0">commandLine</a>[i+1];
|
|---|
| 198 | 00205 }
|
|---|
| 199 | 00206 G4cout << <span class="charliteral">' '</span>;
|
|---|
| 200 | 00207 <span class="keywordflow">for</span>(i=<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>-1; i< <a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length() ;i++){
|
|---|
| 201 | 00208 G4cout << <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a>;
|
|---|
| 202 | 00209 }
|
|---|
| 203 | 00210 G4cout << std::flush;
|
|---|
| 204 | 00211
|
|---|
| 205 | 00212 <span class="comment">// command lin string...</span>
|
|---|
| 206 | 00213 <a class="code" href="classG4UItcsh.html#p0">commandLine</a>.erase(<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>-1, 1);
|
|---|
| 207 | 00214 }
|
|---|
| 208 | 00215
|
|---|
| 209 | <a name="l00217"></a><a class="code" href="classG4UItcsh.html#b7">00217</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b7">G4UItcsh::ClearLine</a>()
|
|---|
| 210 | 00219 {
|
|---|
| 211 | 00220 <span class="comment">// display...</span>
|
|---|
| 212 | 00221 G4int i;
|
|---|
| 213 | 00222 <span class="keywordflow">for</span>(i= <a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>; i>=2; i--) G4cout << <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a>;
|
|---|
| 214 | 00223 <span class="keywordflow">for</span>(i=1; i<=G4int(<a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length()); i++) G4cout << <span class="charliteral">' '</span>;
|
|---|
| 215 | 00224 <span class="keywordflow">for</span>(i=1; i<=G4int(<a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length()); i++) G4cout << <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a>;
|
|---|
| 216 | 00225 G4cout << std::flush;
|
|---|
| 217 | 00226
|
|---|
| 218 | 00227 <span class="comment">// command line string...</span>
|
|---|
| 219 | 00228 <a class="code" href="classG4UItcsh.html#p0">commandLine</a>.erase();
|
|---|
| 220 | 00229 cursorPosition= 1;
|
|---|
| 221 | 00230 }
|
|---|
| 222 | 00231
|
|---|
| 223 | <a name="l00233"></a><a class="code" href="classG4UItcsh.html#b8">00233</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b8">G4UItcsh::ClearAfterCursor</a>()
|
|---|
| 224 | 00235 {
|
|---|
| 225 | 00236 <span class="keywordflow">if</span>(<a class="code" href="classG4UItcsh.html#b1">IsCursorLast</a>()) <span class="keywordflow">return</span>;
|
|---|
| 226 | 00237
|
|---|
| 227 | 00238 <span class="comment">// display...</span>
|
|---|
| 228 | 00239 G4int i;
|
|---|
| 229 | 00240 <span class="keywordflow">for</span>(i=<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>; i<=G4int(<a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length()); i++) G4cout << <span class="charliteral">' '</span>;
|
|---|
| 230 | 00241 <span class="keywordflow">for</span>(i=<a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length(); i>=cursorPosition; i--) G4cout << <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a>;
|
|---|
| 231 | 00242 G4cout << std::flush;
|
|---|
| 232 | 00243
|
|---|
| 233 | 00244 <span class="comment">// command line string...</span>
|
|---|
| 234 | 00245 <a class="code" href="classG4UItcsh.html#p0">commandLine</a>.erase(cursorPosition-1,
|
|---|
| 235 | 00246 <a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length()-cursorPosition+1);
|
|---|
| 236 | 00247 }
|
|---|
| 237 | 00248
|
|---|
| 238 | <a name="l00250"></a><a class="code" href="classG4UItcsh.html#b9">00250</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b9">G4UItcsh::ClearScreen</a>()
|
|---|
| 239 | 00252 {
|
|---|
| 240 | 00253 <span class="keywordflow">if</span>(! <a class="code" href="classG4UItcsh.html#p8">clearString</a>.empty() ) {
|
|---|
| 241 | 00254 G4cout << <a class="code" href="classG4UItcsh.html#p8">clearString</a>;
|
|---|
| 242 | 00255
|
|---|
| 243 | 00256 G4cout << <a class="code" href="classG4VUIshell.html#p1">promptString</a> << <a class="code" href="classG4UItcsh.html#p0">commandLine</a> << std::flush;
|
|---|
| 244 | 00257 <span class="comment">// reset cursur position</span>
|
|---|
| 245 | 00258 <span class="keywordflow">for</span>(G4int i=<a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length()+1; i>=<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>+1; i--)
|
|---|
| 246 | 00259 G4cout << <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a> << std::flush;
|
|---|
| 247 | 00260 }
|
|---|
| 248 | 00261 }
|
|---|
| 249 | 00262
|
|---|
| 250 | <a name="l00264"></a><a class="code" href="classG4UItcsh.html#b10">00264</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b10">G4UItcsh::ForwardCursor</a>()
|
|---|
| 251 | 00266 {
|
|---|
| 252 | 00267 <span class="keywordflow">if</span>(<a class="code" href="classG4UItcsh.html#b1">IsCursorLast</a>()) <span class="keywordflow">return</span>;
|
|---|
| 253 | 00268
|
|---|
| 254 | 00269 G4cout << <a class="code" href="classG4UItcsh.html#p0">commandLine</a>[(size_t)(<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>-1)] << std::flush;
|
|---|
| 255 | 00270 <a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>++;
|
|---|
| 256 | 00271 }
|
|---|
| 257 | 00272
|
|---|
| 258 | <a name="l00274"></a><a class="code" href="classG4UItcsh.html#b11">00274</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b11">G4UItcsh::BackwardCursor</a>()
|
|---|
| 259 | 00276 {
|
|---|
| 260 | 00277 <span class="keywordflow">if</span>(<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>==1) <span class="keywordflow">return</span>;
|
|---|
| 261 | 00278
|
|---|
| 262 | 00279 <a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>--;
|
|---|
| 263 | 00280 G4cout << <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a> << std::flush;
|
|---|
| 264 | 00281 }
|
|---|
| 265 | 00282
|
|---|
| 266 | <a name="l00284"></a><a class="code" href="classG4UItcsh.html#b12">00284</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b12">G4UItcsh::MoveCursorTop</a>()
|
|---|
| 267 | 00286 {
|
|---|
| 268 | 00287 <span class="keywordflow">for</span>(G4int i=<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>; i>1; i--){
|
|---|
| 269 | 00288 G4cout << <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a>;
|
|---|
| 270 | 00289 }
|
|---|
| 271 | 00290 G4cout << std::flush;
|
|---|
| 272 | 00291 cursorPosition=1;
|
|---|
| 273 | 00292 }
|
|---|
| 274 | 00293
|
|---|
| 275 | <a name="l00295"></a><a class="code" href="classG4UItcsh.html#b13">00295</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b13">G4UItcsh::MoveCursorEnd</a>()
|
|---|
| 276 | 00297 {
|
|---|
| 277 | 00298 <span class="keywordflow">for</span>(size_t i=<a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>-1; i<<a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length(); i++){
|
|---|
| 278 | 00299 G4cout << <a class="code" href="classG4UItcsh.html#p0">commandLine</a>[i];
|
|---|
| 279 | 00300 }
|
|---|
| 280 | 00301 G4cout << std::flush;
|
|---|
| 281 | 00302 <a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>=<a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length()+1;
|
|---|
| 282 | 00303 }
|
|---|
| 283 | 00304
|
|---|
| 284 | <a name="l00306"></a><a class="code" href="classG4UItcsh.html#b15">00306</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b15">G4UItcsh::PreviousCommand</a>()
|
|---|
| 285 | 00308 {
|
|---|
| 286 | 00309 G4int nhmax= <a class="code" href="classG4UItcsh.html#p5">currentHistoryNo</a>-1 >= <a class="code" href="classG4UItcsh.html#p4">maxHistory</a> ?
|
|---|
| 287 | 00310 <a class="code" href="classG4UItcsh.html#p4">maxHistory</a> : <a class="code" href="classG4UItcsh.html#p5">currentHistoryNo</a>-1;
|
|---|
| 288 | 00311
|
|---|
| 289 | 00312 <span class="comment">// retain current input</span>
|
|---|
| 290 | 00313 <span class="keywordflow">if</span>(<a class="code" href="classG4UItcsh.html#p6">relativeHistoryIndex</a>==0) <a class="code" href="classG4UItcsh.html#p2">commandLineBuf</a>= <a class="code" href="classG4UItcsh.html#p0">commandLine</a>;
|
|---|
| 291 | 00314
|
|---|
| 292 | 00315 <span class="keywordflow">if</span>(<a class="code" href="classG4UItcsh.html#p6">relativeHistoryIndex</a>>=-nhmax+1 && <a class="code" href="classG4UItcsh.html#p6">relativeHistoryIndex</a><=0) {
|
|---|
| 293 | 00316 <a class="code" href="classG4UItcsh.html#b7">ClearLine</a>();
|
|---|
| 294 | 00317 <a class="code" href="classG4UItcsh.html#p6">relativeHistoryIndex</a>--;
|
|---|
| 295 | 00318 commandLine= <a class="code" href="classG4UItcsh.html#b20">RestoreHistory</a>(<a class="code" href="classG4UItcsh.html#p5">currentHistoryNo</a>+<a class="code" href="classG4UItcsh.html#p6">relativeHistoryIndex</a>);
|
|---|
| 296 | 00319
|
|---|
| 297 | 00320 G4cout << commandLine << std::flush;
|
|---|
| 298 | 00321 <a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>= commandLine.length()+1;
|
|---|
| 299 | 00322 }
|
|---|
| 300 | 00323 }
|
|---|
| 301 | 00324
|
|---|
| 302 | <a name="l00326"></a><a class="code" href="classG4UItcsh.html#b14">00326</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b14">G4UItcsh::NextCommand</a>()
|
|---|
| 303 | 00328 {
|
|---|
| 304 | 00329 G4int nhmax= <a class="code" href="classG4UItcsh.html#p5">currentHistoryNo</a>-1 >= <a class="code" href="classG4UItcsh.html#p4">maxHistory</a> ?
|
|---|
| 305 | 00330 <a class="code" href="classG4UItcsh.html#p4">maxHistory</a> : <a class="code" href="classG4UItcsh.html#p5">currentHistoryNo</a>-1;
|
|---|
| 306 | 00331
|
|---|
| 307 | 00332 <span class="keywordflow">if</span>(<a class="code" href="classG4UItcsh.html#p6">relativeHistoryIndex</a>>=-nhmax && <a class="code" href="classG4UItcsh.html#p6">relativeHistoryIndex</a><=-1) {
|
|---|
| 308 | 00333 <a class="code" href="classG4UItcsh.html#b7">ClearLine</a>();
|
|---|
| 309 | 00334 relativeHistoryIndex++;
|
|---|
| 310 | 00335
|
|---|
| 311 | 00336 <span class="keywordflow">if</span>(relativeHistoryIndex==0) <a class="code" href="classG4UItcsh.html#p0">commandLine</a>= <a class="code" href="classG4UItcsh.html#p2">commandLineBuf</a>;
|
|---|
| 312 | 00337 <span class="keywordflow">else</span> <a class="code" href="classG4UItcsh.html#p0">commandLine</a>= <a class="code" href="classG4UItcsh.html#b20">RestoreHistory</a>(<a class="code" href="classG4UItcsh.html#p5">currentHistoryNo</a>+relativeHistoryIndex);
|
|---|
| 313 | 00338
|
|---|
| 314 | 00339 G4cout << <a class="code" href="classG4UItcsh.html#p0">commandLine</a> << std::flush;
|
|---|
| 315 | 00340 <a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>= <a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length()+1;
|
|---|
| 316 | 00341 }
|
|---|
| 317 | 00342 }
|
|---|
| 318 | 00343
|
|---|
| 319 | 00344
|
|---|
| 320 | <a name="l00346"></a><a class="code" href="classG4UItcsh.html#b16">00346</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b16">G4UItcsh::ListMatchedCommand</a>()
|
|---|
| 321 | 00348 {
|
|---|
| 322 | 00349 G4cout << G4endl;
|
|---|
| 323 | 00350
|
|---|
| 324 | 00351 <span class="comment">// input string</span>
|
|---|
| 325 | 00352 G4String input= G4String(<a class="code" href="classG4UItcsh.html#p0">commandLine</a>).strip(G4String::leading);
|
|---|
| 326 | 00353 <span class="comment">// target token is last token</span>
|
|---|
| 327 | 00354 G4int jhead= input.last(<span class="charliteral">' '</span>);
|
|---|
| 328 | 00355 <span class="keywordflow">if</span>(jhead != G4int(G4String::npos)) {
|
|---|
| 329 | 00356 input.remove(0, jhead);
|
|---|
| 330 | 00357 input= input.strip(G4String::leading);
|
|---|
| 331 | 00358 }
|
|---|
| 332 | 00359
|
|---|
| 333 | 00360 <span class="comment">// command tree of "user specified directory"</span>
|
|---|
| 334 | 00361 G4String vpath= <a class="code" href="classG4VUIshell.html#p6">currentCommandDir</a>;
|
|---|
| 335 | 00362 G4String vcmd;
|
|---|
| 336 | 00363
|
|---|
| 337 | 00364 <span class="keywordflow">if</span>( !input.empty() ) {
|
|---|
| 338 | 00365 G4int len= input.length();
|
|---|
| 339 | 00366 G4int indx=-1;
|
|---|
| 340 | 00367 <span class="keywordflow">for</span>(G4int i=len-1; i>=0; i--) {
|
|---|
| 341 | 00368 <span class="keywordflow">if</span>(input[(size_t)i]==<span class="charliteral">'/'</span>) {
|
|---|
| 342 | 00369 indx= i;
|
|---|
| 343 | 00370 <span class="keywordflow">break</span>;
|
|---|
| 344 | 00371 }
|
|---|
| 345 | 00372 }
|
|---|
| 346 | 00373 <span class="comment">// get abs. path</span>
|
|---|
| 347 | 00374 <span class="keywordflow">if</span>(indx != -1) vpath= <a class="code" href="classG4VUIshell.html#b2">GetAbsCommandDirPath</a>(input(0,indx+1));
|
|---|
| 348 | 00375 <span class="keywordflow">if</span>(!(indx==0 && len==1)) vcmd= input(indx+1,len-indx-1); <span class="comment">// care for "/"</span>
|
|---|
| 349 | 00376 }
|
|---|
| 350 | 00377
|
|---|
| 351 | 00378 <span class="comment">// list matched dirs/commands</span>
|
|---|
| 352 | 00379 <a class="code" href="classG4VUIshell.html#a6">ListCommand</a>(vpath, vpath+vcmd);
|
|---|
| 353 | 00380
|
|---|
| 354 | 00381 G4cout << <a class="code" href="classG4VUIshell.html#p1">promptString</a> << <a class="code" href="classG4UItcsh.html#p0">commandLine</a> << std::flush;
|
|---|
| 355 | 00382 }
|
|---|
| 356 | 00383
|
|---|
| 357 | <a name="l00385"></a><a class="code" href="classG4UItcsh.html#b17">00385</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b17">G4UItcsh::CompleteCommand</a>()
|
|---|
| 358 | 00387 {
|
|---|
| 359 | 00388 <span class="comment">// inputting string</span>
|
|---|
| 360 | 00389 G4String input= G4String(<a class="code" href="classG4UItcsh.html#p0">commandLine</a>).strip(G4String::leading);
|
|---|
| 361 | 00390 <span class="comment">// target token is last token</span>
|
|---|
| 362 | 00391 G4int jhead= input.last(<span class="charliteral">' '</span>);
|
|---|
| 363 | 00392 <span class="keywordflow">if</span>(jhead != G4int(G4String::npos)) {
|
|---|
| 364 | 00393 input.remove(0, jhead);
|
|---|
| 365 | 00394 input= input.strip(G4String::leading);
|
|---|
| 366 | 00395 }
|
|---|
| 367 | 00396
|
|---|
| 368 | 00397 <span class="comment">// command tree of "user specified directory" </span>
|
|---|
| 369 | 00398 G4String vpath= <a class="code" href="classG4VUIshell.html#p6">currentCommandDir</a>;
|
|---|
| 370 | 00399 G4String vcmd;
|
|---|
| 371 | 00400
|
|---|
| 372 | 00401 G4int len= input.length();
|
|---|
| 373 | 00402 <span class="keywordflow">if</span>(!input.empty()) {
|
|---|
| 374 | 00403 G4int indx= -1;
|
|---|
| 375 | 00404 <span class="keywordflow">for</span>(G4int i=len-1; i>=0; i--) {
|
|---|
| 376 | 00405 <span class="keywordflow">if</span>(input(i)==<span class="charliteral">'/'</span>) {
|
|---|
| 377 | 00406 indx= i;
|
|---|
| 378 | 00407 <span class="keywordflow">break</span>;
|
|---|
| 379 | 00408 }
|
|---|
| 380 | 00409 }
|
|---|
| 381 | 00410 <span class="comment">// get abs. path</span>
|
|---|
| 382 | 00411 <span class="keywordflow">if</span>(indx != -1) vpath= <a class="code" href="classG4VUIshell.html#b2">GetAbsCommandDirPath</a>(input(0,indx+1));
|
|---|
| 383 | 00412 <span class="keywordflow">if</span>(!(indx==0 && len==1)) vcmd= input(indx+1,len-indx-1); <span class="comment">// care for "/"</span>
|
|---|
| 384 | 00413 }
|
|---|
| 385 | 00414
|
|---|
| 386 | 00415 G4UIcommandTree* atree= <a class="code" href="classG4VUIshell.html#b1">GetCommandTree</a>(vpath); <span class="comment">// get command tree</span>
|
|---|
| 387 | 00416 <span class="keywordflow">if</span>(atree == NULL) <span class="keywordflow">return</span>;
|
|---|
| 388 | 00417
|
|---|
| 389 | 00418 <span class="comment">// list matched directories/commands</span>
|
|---|
| 390 | 00419 G4String stream, strtmp;
|
|---|
| 391 | 00420 G4String inputpath= vpath+vcmd;
|
|---|
| 392 | 00421 G4int nMatch= 0;
|
|---|
| 393 | 00422
|
|---|
| 394 | 00423 <span class="keywordtype">int</span> Ndir= atree-> GetTreeEntry();
|
|---|
| 395 | 00424 <span class="keywordtype">int</span> Ncmd= atree-> GetCommandEntry();
|
|---|
| 396 | 00425
|
|---|
| 397 | 00426 <span class="comment">// directory ...</span>
|
|---|
| 398 | 00427 <span class="keywordflow">for</span>(G4int idir=1; idir<=Ndir; idir++) {
|
|---|
| 399 | 00428 G4String fpdir= atree-> GetTree(idir)-> GetPathName();
|
|---|
| 400 | 00429 <span class="comment">// matching test</span>
|
|---|
| 401 | 00430 <span class="keywordflow">if</span>( fpdir.index(inputpath, 0) == 0) {
|
|---|
| 402 | 00431 <span class="keywordflow">if</span>(nMatch==0) {
|
|---|
| 403 | 00432 stream= <a class="code" href="classG4VUIshell.html#b3">GetCommandPathTail</a>(fpdir);
|
|---|
| 404 | 00433 } <span class="keywordflow">else</span> {
|
|---|
| 405 | 00434 strtmp= <a class="code" href="classG4VUIshell.html#b3">GetCommandPathTail</a>(fpdir);
|
|---|
| 406 | 00435 stream= <a class="code" href="classG4UItcsh.html#b18">GetFirstMatchedString</a>(stream, strtmp);
|
|---|
| 407 | 00436 }
|
|---|
| 408 | 00437 nMatch++;
|
|---|
| 409 | 00438 }
|
|---|
| 410 | 00439 }
|
|---|
| 411 | 00440
|
|---|
| 412 | 00441 <span class="comment">// command ...</span>
|
|---|
| 413 | 00442 <span class="keywordflow">for</span>(G4int icmd=1; icmd<=Ncmd; icmd++){
|
|---|
| 414 | 00443 G4String fpcmd= atree-> GetPathName() +
|
|---|
| 415 | 00444 atree-> GetCommand(icmd) -> GetCommandName();
|
|---|
| 416 | 00445 <span class="comment">// matching test</span>
|
|---|
| 417 | 00446 <span class="keywordflow">if</span>( fpcmd.index(inputpath, 0) ==0) {
|
|---|
| 418 | 00447 <span class="keywordflow">if</span>(nMatch==0) {
|
|---|
| 419 | 00448 stream= <a class="code" href="classG4VUIshell.html#b3">GetCommandPathTail</a>(fpcmd) + <span class="stringliteral">" "</span>;
|
|---|
| 420 | 00449 } <span class="keywordflow">else</span> {
|
|---|
| 421 | 00450 strtmp= <a class="code" href="classG4VUIshell.html#b3">GetCommandPathTail</a>(fpcmd) + <span class="stringliteral">" "</span>;
|
|---|
| 422 | 00451 stream= <a class="code" href="classG4UItcsh.html#b18">GetFirstMatchedString</a>(stream, strtmp);
|
|---|
| 423 | 00452 }
|
|---|
| 424 | 00453 nMatch++;
|
|---|
| 425 | 00454 }
|
|---|
| 426 | 00455 }
|
|---|
| 427 | 00456
|
|---|
| 428 | 00457 <span class="keywordflow">if</span>(nMatch==0) <span class="keywordflow">return</span>; <span class="comment">// no matched</span>
|
|---|
| 429 | 00458
|
|---|
| 430 | 00459 <span class="comment">// display...</span>
|
|---|
| 431 | 00460 input= <a class="code" href="classG4UItcsh.html#p0">commandLine</a>;
|
|---|
| 432 | 00461 <span class="comment">// target token is last token</span>
|
|---|
| 433 | 00462 jhead= input.last(<span class="charliteral">' '</span>);
|
|---|
| 434 | 00463 <span class="keywordflow">if</span>(jhead == G4int(G4String::npos)) jhead=0;
|
|---|
| 435 | 00464 <span class="keywordflow">else</span> jhead++;
|
|---|
| 436 | 00465
|
|---|
| 437 | 00466 G4int jt= input.find_last_of(<span class="charliteral">'/'</span>);
|
|---|
| 438 | 00467 <span class="keywordflow">if</span>(jt<jhead) jt=G4String::npos;
|
|---|
| 439 | 00468
|
|---|
| 440 | 00469 <span class="keywordflow">if</span>(jt==G4int(G4String::npos)) jt= jhead;
|
|---|
| 441 | 00470 <span class="keywordflow">else</span> jt++;
|
|---|
| 442 | 00471
|
|---|
| 443 | 00472 G4String dspstr;
|
|---|
| 444 | 00473 G4int i;
|
|---|
| 445 | 00474 <span class="keywordflow">for</span>(i=jt; i<=G4int(input.length())-1; i++) dspstr+= G4String(<a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a>); <span class="comment">// cleanup</span>
|
|---|
| 446 | 00475 <span class="keywordflow">for</span>(i=jt; i<=G4int(input.length())-1; i++) dspstr+= G4String(<span class="charliteral">' '</span>);
|
|---|
| 447 | 00476 <span class="keywordflow">for</span>(i=jt; i<=G4int(input.length())-1; i++) dspstr+= G4String(<a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a>);
|
|---|
| 448 | 00477
|
|---|
| 449 | 00478 dspstr+= stream;
|
|---|
| 450 | 00479 G4cout << dspstr << std::flush;
|
|---|
| 451 | 00480
|
|---|
| 452 | 00481 <span class="comment">// command line string</span>
|
|---|
| 453 | 00482 input.remove(jt);
|
|---|
| 454 | 00483 input+= stream;
|
|---|
| 455 | 00484
|
|---|
| 456 | 00485 commandLine= input;
|
|---|
| 457 | 00486 <a class="code" href="classG4UItcsh.html#p1">cursorPosition</a>= commandLine.length()+1;
|
|---|
| 458 | 00487 }
|
|---|
| 459 | 00488
|
|---|
| 460 | 00489
|
|---|
| 461 | 00490 <span class="comment">// --------------------------------------------------------------------</span>
|
|---|
| 462 | 00491 <span class="comment">// commad line</span>
|
|---|
| 463 | 00492 <span class="comment">// --------------------------------------------------------------------</span>
|
|---|
| 464 | <a name="l00494"></a><a class="code" href="classG4UItcsh.html#b3">00494</a> <span class="comment"></span>G4String <a class="code" href="classG4UItcsh.html#b3">G4UItcsh::ReadLine</a>()
|
|---|
| 465 | 00496 {
|
|---|
| 466 | 00497 <a class="code" href="classG4UItcsh.html#b2">InitializeCommandLine</a>();
|
|---|
| 467 | 00498
|
|---|
| 468 | 00499 <span class="keywordtype">char</span> cc;
|
|---|
| 469 | 00500 <span class="keywordflow">do</span>{ <span class="comment">// input loop</span>
|
|---|
| 470 | 00501 G4cin.get(cc);
|
|---|
| 471 | 00502
|
|---|
| 472 | 00503 <span class="comment">// treatment for special character</span>
|
|---|
| 473 | 00504 <span class="keywordflow">switch</span>(cc){
|
|---|
| 474 | 00505 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a0">AsciiCtrA</a>: <span class="comment">// ... move cursor to the top</span>
|
|---|
| 475 | 00506 <a class="code" href="classG4UItcsh.html#b12">MoveCursorTop</a>();
|
|---|
| 476 | 00507 <span class="keywordflow">break</span>;
|
|---|
| 477 | 00508 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a1">AsciiCtrB</a>: <span class="comment">// ... backward cursor</span>
|
|---|
| 478 | 00509 <a class="code" href="classG4UItcsh.html#b11">BackwardCursor</a>();
|
|---|
| 479 | 00510 <span class="keywordflow">break</span>;
|
|---|
| 480 | 00511 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a3">AsciiCtrD</a>: <span class="comment">// ... delete/exit/show matched list</span>
|
|---|
| 481 | 00512 <span class="keywordflow">if</span>(<a class="code" href="classG4UItcsh.html#p0">commandLine</a>.length()!=0 && <a class="code" href="classG4UItcsh.html#b1">IsCursorLast</a>()) <a class="code" href="classG4UItcsh.html#b16">ListMatchedCommand</a>();
|
|---|
| 482 | 00513 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="classG4UItcsh.html#p0">commandLine</a>.empty()) {
|
|---|
| 483 | 00514 G4cout << G4endl;
|
|---|
| 484 | 00515 exit(0);
|
|---|
| 485 | 00516 } <span class="keywordflow">else</span> <a class="code" href="classG4UItcsh.html#b6">DeleteCharacter</a>();
|
|---|
| 486 | 00517 <span class="keywordflow">break</span>;
|
|---|
| 487 | 00518 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a4">AsciiCtrE</a>: <span class="comment">// ... move cursor to the end</span>
|
|---|
| 488 | 00519 <a class="code" href="classG4UItcsh.html#b13">MoveCursorEnd</a>();
|
|---|
| 489 | 00520 <span class="keywordflow">break</span>;
|
|---|
| 490 | 00521 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a5">AsciiCtrF</a>: <span class="comment">// ... forward cursor</span>
|
|---|
| 491 | 00522 <a class="code" href="classG4UItcsh.html#b10">ForwardCursor</a>();
|
|---|
| 492 | 00523 <span class="keywordflow">break</span>;
|
|---|
| 493 | 00524 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a6">AsciiCtrK</a>: <span class="comment">// ... clear after the cursor</span>
|
|---|
| 494 | 00525 <a class="code" href="classG4UItcsh.html#b8">ClearAfterCursor</a>();
|
|---|
| 495 | 00526 <span class="keywordflow">break</span>;
|
|---|
| 496 | 00527 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a7">AsciiCtrL</a>: <span class="comment">// ... clear screen</span>
|
|---|
| 497 | 00528 <span class="comment">// ClearScreen();</span>
|
|---|
| 498 | 00529 <span class="keywordflow">break</span>;
|
|---|
| 499 | 00530 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a8">AsciiCtrN</a>: <span class="comment">// ... next command</span>
|
|---|
| 500 | 00531 <a class="code" href="classG4UItcsh.html#b14">NextCommand</a>();
|
|---|
| 501 | 00532 <span class="keywordflow">break</span>;
|
|---|
| 502 | 00533 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a9">AsciiCtrP</a>: <span class="comment">// ... previous command</span>
|
|---|
| 503 | 00534 <a class="code" href="classG4UItcsh.html#b15">PreviousCommand</a>();
|
|---|
| 504 | 00535 <span class="keywordflow">break</span>;
|
|---|
| 505 | 00536 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a13">AsciiTAB</a>: <span class="comment">// ... command completion</span>
|
|---|
| 506 | 00537 <span class="keywordflow">if</span>( (!<a class="code" href="classG4UItcsh.html#p0">commandLine</a>.empty()) && <a class="code" href="classG4UItcsh.html#b1">IsCursorLast</a>()) <a class="code" href="classG4UItcsh.html#b17">CompleteCommand</a>();
|
|---|
| 507 | 00538 <span class="keywordflow">break</span>;
|
|---|
| 508 | 00539 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a15">AsciiDEL</a>: <span class="comment">// ... backspace</span>
|
|---|
| 509 | 00540 <a class="code" href="classG4UItcsh.html#b5">BackspaceCharacter</a>();
|
|---|
| 510 | 00541 <span class="keywordflow">break</span>;
|
|---|
| 511 | 00542 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a14">AsciiBS</a>: <span class="comment">// ... backspace</span>
|
|---|
| 512 | 00543 <a class="code" href="classG4UItcsh.html#b5">BackspaceCharacter</a>();
|
|---|
| 513 | 00544 <span class="keywordflow">break</span>;
|
|---|
| 514 | 00545 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a2">AsciiCtrC</a>: <span class="comment">// ... kill prompt</span>
|
|---|
| 515 | 00546 <span class="keywordflow">break</span>;
|
|---|
| 516 | 00547 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a10">AsciiCtrQ</a>: <span class="comment">// ... restarts suspeded output</span>
|
|---|
| 517 | 00548 <span class="keywordflow">break</span>;
|
|---|
| 518 | 00549 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a11">AsciiCtrS</a>: <span class="comment">// ... suspend output</span>
|
|---|
| 519 | 00550 <span class="keywordflow">break</span>;
|
|---|
| 520 | 00551 <span class="keywordflow">case</span> <a class="code" href="G4UItcsh_8cc.html#a12">AsciiCtrZ</a>: <span class="comment">// ... suspend</span>
|
|---|
| 521 | 00552 <span class="keywordflow">break</span>;
|
|---|
| 522 | 00553 <span class="keywordflow">default</span>:
|
|---|
| 523 | 00554 <span class="keywordflow">break</span>;
|
|---|
| 524 | 00555 }
|
|---|
| 525 | 00556
|
|---|
| 526 | 00557 <span class="comment">// treatment for ESC. character</span>
|
|---|
| 527 | 00558 <span class="keywordflow">if</span>( cc == <a class="code" href="G4UItcsh_8cc.html#a16">AsciiESC</a>) { <span class="comment">// ESC</span>
|
|---|
| 528 | 00559 G4cin.get(cc);
|
|---|
| 529 | 00560 <span class="keywordflow">if</span> (cc == <span class="charliteral">'['</span> || <span class="charliteral">'O'</span>) { <span class="comment">// care for another termcap, such as konsole</span>
|
|---|
| 530 | 00561 G4cin.get(cc);
|
|---|
| 531 | 00562 <span class="keywordflow">switch</span>(cc) {
|
|---|
| 532 | 00563 <span class="keywordflow">case</span> <span class="charliteral">'A'</span>: <span class="comment">// [UP]</span>
|
|---|
| 533 | 00564 cc = <span class="charliteral">'P'</span> - <span class="charliteral">'@'</span>;
|
|---|
| 534 | 00565 <a class="code" href="classG4UItcsh.html#b15">PreviousCommand</a>(); <span class="comment">// ... show previous commad</span>
|
|---|
| 535 | 00566 <span class="keywordflow">break</span>;
|
|---|
| 536 | 00567 <span class="keywordflow">case</span> <span class="charliteral">'B'</span>: <span class="comment">// [DOWN]</span>
|
|---|
| 537 | 00568 cc = <span class="charliteral">'N'</span> - <span class="charliteral">'@'</span>;
|
|---|
| 538 | 00569 <a class="code" href="classG4UItcsh.html#b14">NextCommand</a>(); <span class="comment">// ... show next commad</span>
|
|---|
| 539 | 00570 <span class="keywordflow">break</span>;
|
|---|
| 540 | 00571 <span class="keywordflow">case</span> <span class="charliteral">'C'</span>: <span class="comment">// [RIGHT]</span>
|
|---|
| 541 | 00572 cc = <span class="charliteral">'F'</span> - <span class="charliteral">'@'</span>;
|
|---|
| 542 | 00573 <a class="code" href="classG4UItcsh.html#b10">ForwardCursor</a>(); <span class="comment">// ... forward cursor</span>
|
|---|
| 543 | 00574 <span class="keywordflow">break</span>;
|
|---|
| 544 | 00575 <span class="keywordflow">case</span> <span class="charliteral">'D'</span>: <span class="comment">// [LEFT]</span>
|
|---|
| 545 | 00576 cc = <span class="charliteral">'B'</span> - <span class="charliteral">'@'</span>;
|
|---|
| 546 | 00577 <a class="code" href="classG4UItcsh.html#b11">BackwardCursor</a>(); <span class="comment">// ... backward cursor</span>
|
|---|
| 547 | 00578 <span class="keywordflow">break</span>;
|
|---|
| 548 | 00579 <span class="keywordflow">default</span>: <span class="comment">// who knows !?</span>
|
|---|
| 549 | 00580 cc = 0;
|
|---|
| 550 | 00581 <span class="keywordflow">break</span>;
|
|---|
| 551 | 00582 }
|
|---|
| 552 | 00583 }
|
|---|
| 553 | 00584 }
|
|---|
| 554 | 00585
|
|---|
| 555 | 00586 <span class="comment">// insert character to command line and display</span>
|
|---|
| 556 | 00587 <a class="code" href="classG4UItcsh.html#b4">InsertCharacter</a>(cc);
|
|---|
| 557 | 00588
|
|---|
| 558 | 00589 } <span class="keywordflow">while</span>( cc != <span class="charliteral">'\n'</span>);
|
|---|
| 559 | 00590
|
|---|
| 560 | 00591 <span class="keywordflow">return</span> <a class="code" href="classG4UItcsh.html#p0">commandLine</a>;
|
|---|
| 561 | 00592 }
|
|---|
| 562 | 00593
|
|---|
| 563 | <a name="l00595"></a><a class="code" href="classG4UItcsh.html#a3">00595</a> G4String <a class="code" href="classG4UItcsh.html#a3">G4UItcsh::GetCommandLine</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* msg)
|
|---|
| 564 | 00597 {
|
|---|
| 565 | 00598 <a class="code" href="classG4UItcsh.html#b21">SetTermToInputMode</a>();
|
|---|
| 566 | 00599
|
|---|
| 567 | 00600 <a class="code" href="classG4UItcsh.html#b0">MakePrompt</a>(msg); <span class="comment">// update</span>
|
|---|
| 568 | 00601 <a class="code" href="classG4UItcsh.html#p6">relativeHistoryIndex</a>= 0;
|
|---|
| 569 | 00602
|
|---|
| 570 | 00603 G4cout << <a class="code" href="classG4VUIshell.html#p1">promptString</a> << std::flush;
|
|---|
| 571 | 00604
|
|---|
| 572 | 00605 G4String newCommand= <a class="code" href="classG4UItcsh.html#b3">ReadLine</a>(); <span class="comment">// read line...</span>
|
|---|
| 573 | 00606 <span class="comment">// multi-line</span>
|
|---|
| 574 | 00607 <span class="keywordflow">while</span>( (newCommand.length() > 0) &&
|
|---|
| 575 | 00608 ( newCommand[newCommand.length()-1] == <span class="charliteral">'_'</span>) ) {
|
|---|
| 576 | 00609 newCommand.remove(newCommand.length()-1);
|
|---|
| 577 | 00610 G4cout << G4endl;
|
|---|
| 578 | 00611 <a class="code" href="classG4VUIshell.html#p1">promptString</a>= <span class="stringliteral">"? "</span>;
|
|---|
| 579 | 00612 G4cout << <a class="code" href="classG4VUIshell.html#p1">promptString</a> << std::flush;
|
|---|
| 580 | 00613 G4String newLine= <a class="code" href="classG4UItcsh.html#b3">ReadLine</a>();
|
|---|
| 581 | 00614 newCommand.append(newLine);
|
|---|
| 582 | 00615 }
|
|---|
| 583 | 00616
|
|---|
| 584 | 00617 <span class="comment">// update history...</span>
|
|---|
| 585 | 00618 G4bool isMeaningfull= FALSE; <span class="comment">// check NULL command</span>
|
|---|
| 586 | 00619 <span class="keywordflow">for</span> (size_t i=0; i<newCommand.length(); i++) {
|
|---|
| 587 | 00620 <span class="keywordflow">if</span>(newCommand[i] != <span class="charliteral">' '</span>) {
|
|---|
| 588 | 00621 isMeaningfull= TRUE;
|
|---|
| 589 | 00622 <span class="keywordflow">break</span>;
|
|---|
| 590 | 00623 }
|
|---|
| 591 | 00624 }
|
|---|
| 592 | 00625 <span class="keywordflow">if</span>( !newCommand.empty() && isMeaningfull) <a class="code" href="classG4UItcsh.html#b19">StoreHistory</a>(newCommand);
|
|---|
| 593 | 00626
|
|---|
| 594 | 00627 <span class="comment">// reset terminal</span>
|
|---|
| 595 | 00628 <a class="code" href="classG4UItcsh.html#b22">RestoreTerm</a>();
|
|---|
| 596 | 00629
|
|---|
| 597 | 00630 G4cout << G4endl;
|
|---|
| 598 | 00631 <span class="keywordflow">return</span> newCommand;
|
|---|
| 599 | 00632 }
|
|---|
| 600 | 00633
|
|---|
| 601 | <a name="l00635"></a><a class="code" href="classG4UItcsh.html#b18">00635</a> G4String <a class="code" href="classG4UItcsh.html#b18">G4UItcsh::GetFirstMatchedString</a>(<span class="keyword">const</span> G4String& str1,
|
|---|
| 602 | 00636 <span class="keyword">const</span> G4String& str2) <span class="keyword">const</span>
|
|---|
| 603 | 00638 {
|
|---|
| 604 | 00639 <span class="keywordtype">int</span> nlen1= str1.length();
|
|---|
| 605 | 00640 <span class="keywordtype">int</span> nlen2= str2.length();
|
|---|
| 606 | 00641
|
|---|
| 607 | 00642 <span class="keywordtype">int</span> nmin = nlen1<nlen2 ? nlen1 : nlen2;
|
|---|
| 608 | 00643
|
|---|
| 609 | 00644 G4String strMatched;
|
|---|
| 610 | 00645 <span class="keywordflow">for</span>(size_t i=0; G4int(i)<nmin; i++){
|
|---|
| 611 | 00646 <span class="keywordflow">if</span>(str1[i]==str2[i]) {
|
|---|
| 612 | 00647 strMatched+= str1[i];
|
|---|
| 613 | 00648 } <span class="keywordflow">else</span> {
|
|---|
| 614 | 00649 <span class="keywordflow">break</span>;
|
|---|
| 615 | 00650 }
|
|---|
| 616 | 00651 }
|
|---|
| 617 | 00652
|
|---|
| 618 | 00653 <span class="keywordflow">return</span> strMatched;
|
|---|
| 619 | 00654 }
|
|---|
| 620 | 00655
|
|---|
| 621 | 00656 <span class="comment">// --------------------------------------------------------------------</span>
|
|---|
| 622 | 00657 <span class="comment">// history</span>
|
|---|
| 623 | 00658 <span class="comment">// --------------------------------------------------------------------</span>
|
|---|
| 624 | <a name="l00660"></a><a class="code" href="classG4UItcsh.html#b19">00660</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b19">G4UItcsh::StoreHistory</a>(G4String aCommand)
|
|---|
| 625 | 00662 {
|
|---|
| 626 | 00663 G4int i= <a class="code" href="classG4UItcsh.html#p5">currentHistoryNo</a>%<a class="code" href="classG4UItcsh.html#p4">maxHistory</a>;
|
|---|
| 627 | 00664 <span class="keywordflow">if</span>(i==0) i=<a class="code" href="classG4UItcsh.html#p4">maxHistory</a>;
|
|---|
| 628 | 00665
|
|---|
| 629 | 00666 <a class="code" href="classG4UItcsh.html#p3">commandHistory</a>[i-1]= aCommand; <span class="comment">// 0-offset</span>
|
|---|
| 630 | 00667 <a class="code" href="classG4UItcsh.html#p5">currentHistoryNo</a>++;
|
|---|
| 631 | 00668 }
|
|---|
| 632 | 00669
|
|---|
| 633 | <a name="l00671"></a><a class="code" href="classG4UItcsh.html#b20">00671</a> G4String <a class="code" href="classG4UItcsh.html#b20">G4UItcsh::RestoreHistory</a>(G4int histNo)
|
|---|
| 634 | 00673 {
|
|---|
| 635 | 00674 <span class="keywordflow">if</span>(histNo>= <a class="code" href="classG4UItcsh.html#p5">currentHistoryNo</a>) <span class="keywordflow">return</span> <span class="stringliteral">""</span>;
|
|---|
| 636 | 00675
|
|---|
| 637 | 00676 G4int index= histNo%<a class="code" href="classG4UItcsh.html#p4">maxHistory</a>;
|
|---|
| 638 | 00677 <span class="keywordflow">if</span>(index==0) index= <a class="code" href="classG4UItcsh.html#p4">maxHistory</a>;
|
|---|
| 639 | 00678
|
|---|
| 640 | 00679 <span class="keywordflow">return</span> <a class="code" href="classG4UItcsh.html#p3">commandHistory</a>[index-1]; <span class="comment">// 0-offset</span>
|
|---|
| 641 | 00680 }
|
|---|
| 642 | 00681
|
|---|
| 643 | 00682 <span class="comment">// --------------------------------------------------------------------</span>
|
|---|
| 644 | 00683 <span class="comment">// terminal mode</span>
|
|---|
| 645 | 00684 <span class="comment">// --------------------------------------------------------------------</span>
|
|---|
| 646 | <a name="l00686"></a><a class="code" href="classG4UItcsh.html#b21">00686</a> <span class="comment"></span><span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b21">G4UItcsh::SetTermToInputMode</a>()
|
|---|
| 647 | 00688 {
|
|---|
| 648 | 00689 termios tiosbuf= <a class="code" href="classG4UItcsh.html#p7">tios</a>;
|
|---|
| 649 | 00690
|
|---|
| 650 | 00691 tiosbuf.c_iflag &= ~(BRKINT | ISTRIP);
|
|---|
| 651 | 00692 tiosbuf.c_iflag |= (IGNBRK | IGNPAR);
|
|---|
| 652 | 00693 tiosbuf.c_lflag &= ~(ICANON | IEXTEN | ECHO);
|
|---|
| 653 | 00694 tiosbuf.c_cc[VMIN] = 1;
|
|---|
| 654 | 00695 tiosbuf.c_cc[VTIME] = 0;
|
|---|
| 655 | 00696
|
|---|
| 656 | 00697 tcsetattr(0, TCSAFLUSH, &tiosbuf);
|
|---|
| 657 | 00698 }
|
|---|
| 658 | 00699
|
|---|
| 659 | 00700
|
|---|
| 660 | <a name="l00702"></a><a class="code" href="classG4UItcsh.html#b22">00702</a> <span class="keywordtype">void</span> <a class="code" href="classG4UItcsh.html#b22">G4UItcsh::RestoreTerm</a>()
|
|---|
| 661 | 00704 {
|
|---|
| 662 | 00705 tcsetattr(0, TCSAFLUSH, &<a class="code" href="classG4UItcsh.html#p7">tios</a>);
|
|---|
| 663 | 00706 }
|
|---|
| 664 | 00707
|
|---|
| 665 | 00708 <span class="preprocessor">#endif</span>
|
|---|
| 666 | 00709 <span class="preprocessor"></span>
|
|---|
| 667 | </pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Jun 22 11:07:02 2007 by
|
|---|
| 668 | <a href="http://www.doxygen.org/index.html">
|
|---|
| 669 | <img src="doxygen.png" alt="doxygen" align="middle" border=0 >
|
|---|
| 670 | </a>1.3.4 </small></address>
|
|---|
| 671 | </body>
|
|---|
| 672 | </html>
|
|---|