-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtester.cpp
78 lines (65 loc) · 2.03 KB
/
tester.cpp
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
/* Name: Ziting Shen & Rachel Xu
* Exercise: Final Project
* Date: 04/14/2016
* Purpose: Tester program for CS246 final project: parsecmd
*/
#include "rachel.h"
#include "ziting.h"
#include <iomanip>
// static: means these functions cannot be called from outside this file
static void print_cmd_args(char* cmdline, vector<string> argv);
static void print_bg(bool bg) ;
/******************************************************************/
int main( ){
bool bg;
char* cmdline;
string argv;
vector<string> args;
map<string, string> aliases;
map<string, string> variables;
// int i;
rl_bind_key('\t', rl_complete);
printf("Enter quit to stop\n");
while(1) {
// (1) print the shell prompt
cout << "enter a cmd line> ";
// (2) read in the next command
cmdline = readline("shell> ");
bg = false;
args = parse(cmdline, bg, variables, aliases);
if(!args.empty()) {
print_cmd_args(cmdline, args);
print_bg(bg);
if (args[0] == "quit") {
return 0;
}
}
}
return 0;
}
/*******************************************************************/
// This function prints out a message based on the value of bg
// indicating if the command is run in the background or not
void print_bg(bool bg) {
if(bg) {
cout << "run in the background is true\n";
} else {
cout << "run in the background is false\n";
}
}
/*******************************************************************/
// This function prints out the cmdline and argv list
// cmdline: the command line string
// argv: the argv list of command line arguments string
//
void print_cmd_args(char* cmdline, vector<string> argv ){
unsigned int i = 0;
cout << "\nCommand line: " << cmdline << "\n";
while (i < argv.size()) {
// note: I'm printing out each argv string between # chars
// so that I can see if I have left any space or other
// invisible characters in an argv[i] string (I shouldn't)
cout << setw(3) << i << " #" << argv[i] << "#\n";
i++;
}
}