Repository navigation
Expand file tree
/
Copy pathhfsh26.cpp.save
More file actions
105 lines (85 loc) · 2.53 KB
/
Copy pathhfsh26.cpp.save
File metadata and controls
105 lines (85 loc) · 2.53 KB
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
//*********************************************************
//
// PUT YOUR NAME HERE!!!!
// Operating Systems
// Writing Your Own Shell: hfsh26
//
//*********************************************************
//*********************************************************
//
// Includes and Defines
//
//*********************************************************
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define STR_EXIT "exit"
//*********************************************************
//
// Extern Declarations
//
//*********************************************************
// Buffer state. This is used to parse string in memory...
// Leave this alone.
extern "C"{
extern char **gettoks();
typedef struct yy_buffer_state * YY_BUFFER_STATE;
extern YY_BUFFER_STATE yy_scan_string(const char * str);
extern YY_BUFFER_STATE yy_scan_buffer(char *, size_t);
extern void yy_delete_buffer(YY_BUFFER_STATE buffer);
extern void yy_switch_to_buffer(YY_BUFFER_STATE buffer);
}
//*********************************************************
//
// Namespace
//
// If you are new to C++, uncommment the `using namespace std` line.
// It will make your life a little easier. However, all true
// C++ developers will leave this commented. ;^)
//
//*********************************************************
// using namespace std;
//*********************************************************
//
// Function Prototypes
//
//*********************************************************
//*********************************************************
//
// Main Function
//
//*********************************************************
int main(int argc, char *argv[])
{
/* local variables */
int ii;
char **toks;
int retval;
char linestr[256];
YY_BUFFER_STATE buffer;
/* initialize local variables */
ii = 0;
toks = NULL;
retval = 0;
/* main loop */
while(fgets(linestr, 256, stdin)){
// make sure line has a '\n' at the end of it
if(!strstr(linestr, "\n"))
strcat(linestr, "\n");
/* get arguments */
buffer = yy_scan_string(linestr);
yy_switch_to_buffer(buffer);
toks = gettoks();
yy_delete_buffer(buffer);
if(toks[0] != NULL){
/* simple loop to echo all arguments */
for(ii=0; toks[ii] != NULL; ii++){
printf( "Argument %d: %s\n", ii, toks[ii] );
}
if(!strcmp(toks[0], STR_EXIT))
break;
}
}
/* return to calling environment */
return( retval );
}