Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cs283
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joey Le
Cs283
Commits
e9cab772
Commit
e9cab772
authored
9 months ago
by
Joey Le
Browse files
Options
Downloads
Patches
Plain Diff
HOPEFULLY THE BUGS ARE FIXED
parent
0e5f2a1f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Assignment-03/dshlib.c
+8
-38
8 additions, 38 deletions
Assignment-03/dshlib.c
with
8 additions
and
38 deletions
Assignment-03/dshlib.c
+
8
−
38
View file @
e9cab772
...
...
@@ -33,15 +33,14 @@
* memset(), strcmp(), strcpy(), strtok(), strlen(), strchr()
*/
int
build_cmd_list
(
char
*
cmd_line
,
command_list_t
*
clist
)
{
int
build_cmd_list
(
char
*
cmd_line
,
command_list_t
*
clist
)
{
if
(
cmd_line
==
NULL
)
{
return
ERR_CMD_OR_ARGS_TOO_BIG
;
}
//
This code here is for trimming the lin
es
//
Trim leading and trailing spac
es
char
*
trimmed_line
=
strdup
(
cmd_line
);
if
(
trimmed_line
==
NULL
)
{
return
ERR_CMD_OR_ARGS_TOO_BIG
;
}
...
...
@@ -52,67 +51,38 @@ int build_cmd_list(char *cmd_line, command_list_t *clist)
trimmed_line
[
--
len
]
=
'\0'
;
}
clist
->
commands
=
(
command_t
*
)
malloc
(
CMD_MAX
*
sizeof
(
command_t
));
if
(
clist
->
commands
==
NULL
)
{
free
(
trimmed_line
);
return
ERR_CMD_OR_ARGS_TOO_BIG
;
}
int
command_count
=
0
;
char
*
command
=
strtok
(
trimmed_line
,
PIPE_STRING
);
//STEPS
//Split the command into even more parts
//The first one will be the exectuble
//and if they're more than they will be the arguements
//Populate it using strcpy()
while
(
command
!=
NULL
&&
command_count
<
CMD_MAX
)
{
memset
(
&
clist
->
commands
[
command_count
],
0
,
sizeof
(
command_t
));
char
*
command_and_arguments
=
strtok
(
command
,
SPACE_CHAR
);
if
(
command_and_arguments
!=
NULL
)
{
if
(
strlen
(
command_and_arguments
)
>=
EXE_MAX
)
{
free
(
trimmed_line
);
free
(
clist
->
commands
);
return
ERR_CMD_OR_ARGS_TOO_BIG
;
}
strcpy
(
clist
->
commands
[
command_count
].
exe
,
command_and_arguments
);
int
argument_count
=
0
;
while
((
command_and_arguments
=
strtok
(
NULL
,
SPACE_CHAR
))
!=
NULL
)
{
if
(
strlen
(
command_and_arguments
)
>=
ARG_MAX
)
{
free
(
trimmed_line
);
free
(
clist
->
commands
);
return
ERR_CMD_OR_ARGS_TOO_BIG
;
}
// Copy the argument
strcpy
(
clist
->
commands
[
command_count
].
args
[
argument_count
],
command_and_arguments
);
argument_count
++
;
}
// Null-terminate the arguments list
clist
->
commands
[
command_count
].
args
[
argument_count
]
=
NULL
;
clist
->
commands
[
command_count
].
args
[
argument_count
]
=
NULL
;
// Terminate arguments list
}
// Move to the next command
command_count
++
;
command
=
strtok
(
NULL
,
PIPE_STRING
);
}
if
(
command
!=
NULL
)
{
free
(
trimmed_line
);
free
(
clist
->
commands
);
return
ERR_TOO_MANY_COMMANDS
;
}
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment