Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS503
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
Vanshika Mohan Bongade
CS503
Commits
13f880f1
Commit
13f880f1
authored
7 months ago
by
Vanshika Mohan Bongade
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
0fbf1a4f
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
WEEK-5/dshlib.c
+58
-0
58 additions, 0 deletions
WEEK-5/dshlib.c
with
58 additions
and
0 deletions
WEEK-5/dshlib.c
0 → 100644
+
58
−
0
View file @
13f880f1
#include
<stdlib.h>
#include
<stdio.h>
#include
<string.h>
#include
<ctype.h>
#include
"dshlib.h"
int
build_cmd_list
(
char
*
cmd_line
,
command_list_t
*
clist
)
{
if
(
strlen
(
cmd_line
)
==
0
)
{
return
WARN_NO_CMDS
;
// Empty input
}
// Initialize command list
clist
->
num
=
0
;
memset
(
clist
->
commands
,
0
,
sizeof
(
clist
->
commands
));
char
*
saveptr
;
// For strtok_r (reentrant version of strtok)
char
*
token
=
strtok_r
(
cmd_line
,
PIPE_STRING
,
&
saveptr
);
while
(
token
!=
NULL
)
{
if
(
clist
->
num
>=
CMD_MAX
)
{
return
ERR_TOO_MANY_COMMANDS
;
// Too many commands
}
// Trim leading spaces
while
(
isspace
((
unsigned
char
)
*
token
))
token
++
;
// Trim trailing spaces
char
*
end
=
token
+
strlen
(
token
)
-
1
;
while
(
end
>
token
&&
isspace
((
unsigned
char
)
*
end
))
end
--
;
*
(
end
+
1
)
=
'\0'
;
// Extract command and arguments separately
char
*
cmd_name
=
strtok
(
token
,
" "
);
// First word is the command
char
*
cmd_args
=
strtok
(
NULL
,
""
);
// Rest are arguments
if
(
cmd_name
!=
NULL
)
{
strncpy
(
clist
->
commands
[
clist
->
num
].
exe
,
cmd_name
,
EXE_MAX
-
1
);
if
(
cmd_args
!=
NULL
)
{
strncpy
(
clist
->
commands
[
clist
->
num
].
args
,
cmd_args
,
ARG_MAX
-
1
);
}
clist
->
num
++
;
}
token
=
strtok_r
(
NULL
,
PIPE_STRING
,
&
saveptr
);
// Move to next command
}
return
OK
;
}
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