1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
//zmg, 03.01.01
//this file needs a better description!
//
//
// ***** history_setHistory() *****
//IN: rptr.INPUT = the input from the command line
//DO: store the current input from the command line in the history buffer,
// if the history buffer becomes full, the oldest command in the buffer is
// tossed, and all of the other commands are "slid back" to make room
// for the new one.
//OUT: updated history buffer
function history_setHistory() {
var r = eval("_root.r" + _root.active_router); //'r' is a "pointer" to the active router object
var vr = eval("_root.r" + _root.VISIBLE_ROUTER); //'r' is a "pointer" to the visible router object
var history; // a pointer to the history object
//this if-statement points the 'history' ptr to the correct
//history buffer to store the command history into
if ((r.MODE == "user") || (r.MODE == "enable")) {
//we are in either "user" or "enable" mode, so the 'history'
//ptr should point to the user mode's history buffer.
//C history = r.userHistory;
history = _root.devCmdHist[routerUsedForThisStep[_root.stepnum]].userHistory;
} else {
//we're in "config" mode, so the 'history' ptr should
//point to the config mode's history buffer.
//C history = r.configHistory;
history = _root.devCmdHist[routerUsedForThisStep[_root.stepnum]].configHistory;
}
//if the last entry in the history buffer is different than what
//was just entered on the command line, this if-statement will
//execute to save this command in the history buffer
if (history[history.length-1] != vr.INPUT) {
//store this most recent command from the command line in
//the last position of the history buffer (array)
history[history.length] = vr.INPUT;
//if the buffer is over the declared length, remove the
//oldest command in the buffer and "shift" every command
//up one slot in the history buffer.
if (history.length > _root.devCmdHist[routerUsedForThisStep[_root.stepnum]].historyBufferLength) {
history.shift();
}
}
//update the current length counter of the history buffer
//in the router object
if ((r.MODE == "user") || (r.MODE == "enable"))
{
//r.userHistIndex = history.length;
_root.devCmdHist[routerUsedForThisStep[_root.stepnum]].userHistIndex = history.length;
}
else
{
//r.configHistIndex = history.length;
_root.devCmdHist[routerUsedForThisStep[_root.stepnum]].configHistIndex = history.length;
}
}
// ***** history_historyBackward() *****
//IN: <none>
//DO: print the previous input command from the history buffer to the
// current command line--called when the user is scrolling "backward"
// through the history of commands.
//OUT: console is updated to show the previous command in the history
function history_historyBackward() {
// pointer to the active router object
var r = eval("_root.r" + _root.active_router);
// pointer to the visible router object
var vr = eval("_root.r" + _root.VISIBLE_ROUTER);
var history; //"pointer" to the history object
var histIndex; //tmp.var, index into the history object
//this if-statement points the 'history' ptr to the correct
//history buffer to read the command history from
if ((r.MODE == "user") || (r.MODE == "enable")) {
//we are in either "user" or "enable" mode, so the 'history'
//ptr should point to the user mode's history buffer.
history = _root.devCmdHist[routerUsedForThisStep[_root.stepnum]].userHistory;
//point 'histIndex' to the current element
//in the history buffer
histIndex = _root.devCmdHist[routerUsedForThisStep[_root.stepnum]].userHistIndex;
} else {
//we're in "config" mode, so the 'history' ptr should
//point to the config mode's history buffer.
history = _root.devCmdHist[routerUsedForThisStep[_root.stepnum]].configHistory;
//point 'histIndex' to the current element
//in the history buffer
histIndex = _root.devCmdHist[routerUsedForThisStep[_root.stepnum]].configHistIndex;
}
//this if-statement executes if there are commands left
//in the history buffer (before the current one) to display.
//if not, then this function simply returns.
if (histIndex > 0) {
//"back up" the current history buffer ptr to the previous command
histIndex--;
//"back up" the current history buffer index to the previous
//command in the appropriate router area as well.
if ((r.MODE == "user") || (r.MODE == "enable")) {
_root.devCmdHist[routerUsedForThisStep[_root.stepnum]].userHistIndex--;
} else {
_root.devCmdHist[routerUsedForThisStep[_root.stepnum]].configHistIndex--;
}
//replace the last line w/a prompt: remove all characters
//displayed on the last line, except for the prompt, and leave
//the cursor right after the prompt
r.line[r.lastLine] = r.line[r.lastLine].substring(0,r.PROMPT.length);
//fill the current router's input buffer (rptr.INPUT) with
//the previous command from the history buffer...
vr.INPUT = history[histIndex];
//...and print it to the Hyperterminal console.
r.lineIndexCounter = r.INPUT.length;
output_write(vr.INPUT);
}
}
// ***** history_historyForward() *****
//IN: <none>
//DO: print the next input command from the history buffer to the
// current command line--called when the user is scrolling "forward"
// through the history of commands.
//OUT: console is updated to show the next command in the history
function history_historyForward() {
var r = eval("_root.r" + _root.active_router); //'rptr' is a "pointer" to the active router object
var vr = eval("_root.r" + _root.VISIBLE_ROUTER); //'rptr' is a "pointer" to the visible router object
var history; //"pointer" to the history object
var histIndex; //tmp.var, index into the history object
//this if-statement points the 'history' ptr to the correct
//history buffer to read the command history from
if ((r.MODE == "user") || (r.MODE == "enable")) {
//we are in either "user" or "enable" mode, so the 'history'
//ptr should point to the user mode's history buffer.
history = _root.devCmdHist[routerUsedForThisStep[_root.stepnum]].userHistory;
//point 'histIndex' to the current element
//in the history buffer
histIndex = _root.devCmdHist[routerUsedForThisStep[_root.stepnum]].userHistIndex;
} else {
//we're in "config" mode, so the 'history' ptr should
//point to the config mode's history buffer.
history = _root.devCmdHist[routerUsedForThisStep[_root.stepnum]].configHistory;
//point 'histIndex' to the current element
//in the history buffer
histIndex = _root.devCmdHist[routerUsedForThisStep[_root.stepnum]].configHistIndex;
}
//this if-statement executes if there are commands left
//in the history buffer (after the current one) to display.
//if not, then this function simply returns.
if (histIndex < history.length) {
//"advance" the current history buffer ptr to the previous command
histIndex++;
//"back up" the current history buffer index to the previous
//command in the appropriate router area as well.
if ((r.MODE == "user") || (r.MODE == "enable")) {
_root.devCmdHist[routerUsedForThisStep[_root.stepnum]].userHistIndex++;
} else {
_root.devCmdHist[routerUsedForThisStep[_root.stepnum]].configHistIndex++;
}
//replace the last line w/a prompt: remove all characters
//displayed on the last line, except for the prompt, and leave
//the cursor right after the prompt
r.line[r.lastLine] = r.line[r.lastLine].substring(0,r.PROMPT.length);
if (histIndex != history.length) {
//there are more commands following this one in the
//history buffer, so fill the current router's input
//buffer (rptr.INPUT) with the next command from the
//history buffer...
vr.INPUT = history[histIndex];
} else {
//there are no more commands, print nothing to
//the command line
vr.INPUT = "";
}
//...print the router object command line input buffer
//(set by the if-statement above) to the Hyperterminal
//console...
r.lineIndexCounter = vr.INPUT.length;
output_write(vr.INPUT);
}
}
|