Appends text to the buffer after the current address line. If the current address is zero, the entered text is placed at the beginning of the buffer. Text is entered in input mode. The current address is set to the address of the last line entered or, if there were none, the current address is not changed.
Deletes the addressed lines from the buffer. The current address is set to the new address of the line after the last line deleted; if the lines deleted were originally at the end of the buffer, the current address is set to the address of the new last line; if no lines remain in the buffer, the current address is set to zero.
Inserts text in the buffer before the current addressed line. If the current address is zero, the entered text is placed at the beginning of the buffer. Text is entered in input mode. The current address is set to the address of the last line entered or, if there were none, the current address is not changed.
Number command. Prints the addressed lines, preceding each line by its line number and a \ ('\t'). The current address is set to the address of the last line printed. Specially, 1,$n prints all lines in the buffer.
Quits ed unconditionally. Unwritten changes are discarded.
无条件退出。放弃未写入的更改
w file
Writes all lines to file and prints the number of bytes written to the file. Print an error if no filename is specified. The current address is unchanged.
将所有行写入文件并打印写入文件的字节数。如果未指定文件名,则打印错误。当前地址不变。
?
Null command. An address alone prints the addressed line. The current address is set to the address of the printed line.
cmd> a It's input mode now. Quit with a line with a single dot(.) #include <iostream>
int main() { } . cmd> 1,$n 1 #include <iostream> 2 3 int main() 4 { 5 } cmd> 3 int main() cmd> i It's input mode now. Quit with a line with a single dot(.) using namespace std;
#includ . cmd> 1,$n 1 #include <iostream> 2 3 using namespace std; 4 5 #includ 6 int main() 7 { 8 } cmd> 4,5d cmd> 1,$n 1 #include <iostream> 2 3 using namespace std; 4 int main() 5 { 6 } cmd> 1,3c ? Bad/Unknown command cmd> 1,5n 1 #include <iostream> 2 3 using namespace std; 4 int main() 5 { cmd> a It's input mode now. Quit with a line with a single dot(.) cout << "Hello my editor" << endl; return 0; . cmd> 1,$n 1 #include <iostream> 2 3 using namespace std; 4 int main() 5 { 6 cout << "Hello my editor" << endl; 7 8 return 0; 9 } cmd> write ? Bad/Unknown command cmd> 1,999n ? Line number out of range cmd> 9,1n ? Number range error cmd> 4,2d ? Delete range error cmd> 2019 ? Line number out of range cmd> w hello.cc 114 byte(s) written cmd> Q
voidEditor::run() { string cmd; while (true) { cout << "cmd> "; cout.flush(); getline(cin, cmd); if (cmd == "Q") break; try { dispatchCmd(cmd); } catch (constchar *e) { cout << "? " << e << endl; } catch (const out_of_range &oor) { cout << "? " << oor.what() << endl; } catch (const range_error &re) { cout << "? " << re.what() << endl; } } } voidEditor::cmdAppend() { //it's function: //Appends text to the buffer after the current address line. If the current address is zero, //the entered text is placed at the beginning of the buffer. Text is entered in input mode. //The current address is set to the address of the last line entered or, if there were none, //the current address is not changed. cout << "It's input mode now. Quit with a line with a single dot(.)" << endl; // TODO: finish cmdAppend.
voidEditor::cmdDelete(int start, int end) { if(end<start) throw"Delete range error"; if(start<=0||end>buffer->list->currentLength) throw"Line number out of range"; bool flag= true; bool anot= true; if(end==buffer->list->currentLength) flag=false;
voidEditor::cmdNull(int line) { if(line<=0||line>buffer->list->currentLength) throw"Line number out of range"; cout << buffer->moveToLine(line) << endl; currentLine=line; }
voidEditor::cmdNumber(int start, int end) { if(end<start) throw"Number range error"; if(start<=0||end>buffer->list->currentLength) throw"Line number out of range"; buffer->showLines(start, end); currentLine=end; }
cmd> a It's input mode now. Quit with a line with a single dot(.) #include <iostream>
int main() { } . cmd> 1,$n 1 #include <iostream> 2 3 int main() 4 { 5 } cmd> 3 int main() cmd> i It's input mode now. Quit with a line with a single dot(.) using namespace std;
#includ . cmd> 1,$n 1 #include <iostream> 2 3 using namespace std; 4 5 #includ 6 int main() 7 { 8 } cmd> 4,5d cmd> 1,$n 1 #include <iostream> 2 3 using namespace std; 4 int main() 5 { 6 } cmd> 1,3c ? Bad/Unknown command cmd> 1,5n 1 #include <iostream> 2 3 using namespace std; 4 int main() 5 { cmd> a It's input mode now. Quit with a line with a single dot(.) cout << "Hello my editor" << endl;
return 0; . cmd> 1,$n 1 #include <iostream> 2 3 using namespace std; 4 int main() 5 { 6 cout << "Hello my editor" << endl; 7 8 return 0; 9 } cmd> write ? Bad/Unknown command cmd> 1,999n ? Line number out of range cmd> 9,1n ? Number range error cmd> 4,2d ? Delete range error cmd> 2019 ? Line number out of range cmd> w hello.cc 111 byte(s) written cmd> Q