Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
Basic-Shell-Design/shell.h at main · Dominickc-m/Basic-Shell-Design · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
Dominickc-m
Basic-Shell-Design
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
Basic-Shell-Design
/
shell.h
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
193 lines (179 loc) · 6.03 KB
main
Breadcrumbs
Basic-Shell-Design
/
shell.h
Copy path
Top
File metadata and controls
Code
Blame
193 lines (179 loc) · 6.03 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#ifndef
_SHELL_H_
#define
_SHELL_H_
#include
<stdbool.h>
#define
SUCCESS
0
#define
ERROR
-1
#define
EXIT
1
#define
DEBUG
0
#define
MAX_ARG_LEN
100
typedef
struct
{
int
argc
;
// total number of arguments
char
*
*
argv
;
// argument values (must malloc)
}
command_t
;
/* ------------------------------------------------------------------------------
*
* YOU NEED TO COMPLETE THIS FUNCTION.
*
* Allocate memory for the command. The last element in `p_cmd->argv` should be
* NULL.
*
* The length of `p_cmd->argv` should be `argc+1`: the first `argc` slots are
* used to store the arguments and the last one is set to NULL.
*
* Arguments:
* p_cmd : pointer to the command need to allocate memory.
* argc : the number of arguments.
*
* Return:
* None
*/
void
alloc_mem_for_command
(
command_t
*
p_cmd
,
int
argc
);
/* ------------------------------------------------------------------------------
*
* YOU NEED TO COMPLETE THIS FUNCTION.
*
* This function is used to free memory that may be malloc'd for the name and
* argv fields in the command_t structure. To be safe, you should also set the
* pointer values to NULL.
*
* HINT(s): See man page for more information about free function
*
* Arguments:
* p_cmd : pointer to a command_t structure
* Return:
* None
*
*/
void
cleanup
(
command_t
*
p_cmd
);
/* ------------------------------------------------------------------------------
*
* YOU NEED TO COMPLETE THIS FUNCTION.
*
* This function will parse the command (cmd for short) and its arguments
* specified by the user.
*
* HINT(s): This function is "essentially" an exercise in string parsing.
*
* EXAMPLE#1, if the user enters
*
* cd /mnt/cdrom
*
* at the shell prompt, line would contain "cd /mnt/cdrom".
* Using the space character as the delimiter, the fields in
* the command struct would be:
*
* - argc = 2
* - argv = {"cd", "/mnt/cdrom", NULL}
*
* EXAMPLE#2, if the user enters
*
* ls -la
*
* at the shell prompt, line would contain "ls -la". Using the
* space character as the delimiter, the fields in the command
* struct would be:
*
* - argc = 2
* - argv = {"ls", "-la", NULL}
*
* EXAMPLE#3, if the user enters nothing at the shell prompt (i.e.
* simply hits the return key), line would NULL, and the fields in
* the command struct would be:
*
* - argc = 0
* - argv = {NULL}
*
* Arguments:
* line: pointer to the string contains the cmd.
* p_cmd: pointer to the command_t structure
*
* Return:
* N/A
*
*/
void
parse
(
char
*
line
,
command_t
*
p_cmd
);
/* ------------------------------------------------------------------------------
*
* YOU NEED TO COMPLETE THIS FUNCTION.
*
* This function is used determine if the named command (cmd for short) entered
* by the user in the shell can be found in one of the folders defined in the
* PATH environment (env or short) variable. If the file exists, then the name
* of the executable at argv[0] is replaced with the location (fully qualified
* path) of the executable.
*
* For example,
*
* if command_t.argv[0] is "ls", and "ls" is in the "/usr/bin" folder,
* then command_t.argv[0] would be changed to "/usr/bin/ls"
*
* HINT(s): Use getenv() system function to retrieve the folders defined in the
* PATH variable. An small code segment is shown below that
* demonstrates how to retrieve folders defined in your PATH.
*
* char* path_env_variable;
* path_env_variable = getenv( "PATH" );
* printf("PATH = %s\n", path_env_variable );
*
* The format of the PATH is very simple, the ':' character is
* delimiter, i.e. used to mark the beginning and end of a folder defined in the
* path.
*
* Write a loop that parses each folder defined in the path,
* then uses this folder along with the stat function (see "File/Directory
* Status" section in the assignment PDF).
*
* Arguments:
* p_cmd: pointer to the command_t structure
* Return:
* true: if cmd is in the PATH
* false: if not in the PATH.
*
*/
bool
find_fullpath
(
command_t
*
p_cmd
);
/* ------------------------------------------------------------------------------
*
* YOU NEED TO COMPLETE THIS FUNCTION.
*
* This function will execute commands (cmd for short).
*
*
* Arguments:
* p_cmd: pointer to the command_t structure.
*
* Return:
* SUCCESS: successfully execute the command.
* ERROR: error occurred.
*
*/
int
execute
(
command_t
*
p_cmd
);
/* ------------------------------------------------------------------------------
*
* This function will determine if command (cmd for short) entered in the shell
* by the user is a valid builtin command.
*
* HINT(s): Use valid_builtin_commands array defined in shell.c
*
* Arguments:
* p_cmd: pointer to the command_t structure
* Return:
* true: the cmd is in array `valid_builtin_commands`.
* false: not in array `valid_builtin_commands`.
*
*/
bool
is_builtin
(
command_t
*
p_cmd
);
/* ------------------------------------------------------------------------------
*
* This function is used execute built-in commands such as change directory (cd)
*
* HINT(s): See man page for more information about chdir function
*
* Arguments:
* p_cmd: pointer to the command_t structure
* Return:
* SUCCESS: no error occurred during chdir operation.
* ERROR: an error occured during chdir operation.
*
*/
int
do_builtin
(
command_t
*
p_cmd
);
#endif
// _SHELL_H_
You can’t perform that action at this time.