Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Caco
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vytor Calixto
Caco
Commits
53c7bbd5
Commit
53c7bbd5
authored
9 years ago
by
Israel Barreto Sant'Anna
Browse files
Options
Downloads
Patches
Plain Diff
Optimized command arguments reading
Signed-off-by:
Israel Barreto Sant'Anna
<
ibsa14@inf.ufpr.br
>
parent
27546ff4
Branches
Branches containing commit
No related tags found
1 merge request
!1
Lento
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
client.cpp
+33
-40
33 additions, 40 deletions
client.cpp
dirFunctions.cpp
+3
-9
3 additions, 9 deletions
dirFunctions.cpp
with
36 additions
and
49 deletions
client.cpp
+
33
−
40
View file @
53c7bbd5
#include
<s
stream
>
#include
<s
tdexcept
>
#include
"definitions.h"
#include
"definitions.h"
#include
"dirFunctions.h"
#include
"dirFunctions.h"
#include
"ConexaoRawSocket.c"
#include
"ConexaoRawSocket.c"
void
printCommandsList
();
void
printCommandsList
();
vector
<
string
>
getArgs
();
int
main
(){
int
main
(){
int
sockt
=
ConexaoRawSocket
(
DEVICE
);
int
pos
,
sockt
=
ConexaoRawSocket
(
DEVICE
);
vector
<
string
>
args
;
string
line
,
command
,
args
;
printCommandsList
();
printCommandsList
();
while
(
true
){
while
(
true
){
cout
<<
endl
<<
"Entre com o comando:"
<<
endl
;
cout
<<
endl
<<
"Entre com o comando:"
<<
endl
;
args
=
getArgs
();
getline
(
cin
,
line
);
if
(
args
[
0
]
==
"quit"
){
pos
=
line
.
find_first_of
(
" "
);
break
;
if
(
pos
==
string
::
npos
){
pos
=
line
.
size
();
}
}
if
(
args
[
0
]
==
"cd"
){
command
=
line
.
substr
(
0
,
pos
);
cd
(
args
[
1
]);
}
else
if
(
args
[
0
]
==
"ls"
){
try
{
try
{
cout
<<
ls
(
args
);
if
(
command
==
"quit"
){
}
catch
(
char
const
*
strException
){
break
;
cerr
<<
"Error: "
<<
strException
<<
endl
;
}
}
}
else
if
(
args
[
0
]
==
"cdr"
){
if
(
command
==
"cd"
){
args
=
line
.
substr
(
pos
+
1
,
line
.
size
());
cd
(
args
);
}
else
if
(
command
==
"ls"
){
cout
<<
ls
(
line
);
}
else
if
(
command
==
"cdr"
){
//TODO
//TODO
}
else
if
(
args
[
0
]
==
"lsr"
){
}
else
if
(
command
==
"lsr"
){
//TODO
//TODO
}
else
if
(
args
[
0
]
==
"put"
){
}
else
if
(
command
==
"put"
){
//TODO
//TODO
}
else
if
(
args
[
0
]
==
"get"
){
}
else
if
(
command
==
"get"
){
}
else
if
(
args
[
0
]
==
"help"
){
}
else
if
(
command
==
"help"
){
printCommandsList
();
printCommandsList
();
}
else
{
}
else
{
cout
<<
"Comando inexistente."
<<
endl
;
cout
<<
"Comando inexistente."
<<
endl
;
printCommandsList
();
printCommandsList
();
}
}
catch
(
char
const
*
strException
){
cerr
<<
"Error: "
<<
strException
<<
endl
;
}
catch
(
out_of_range
e
){
cerr
<<
"Error: Esse comando requer argumentos."
<<
endl
;
}
}
}
}
return
0
;
return
0
;
...
@@ -54,16 +60,3 @@ void printCommandsList(){
...
@@ -54,16 +60,3 @@ void printCommandsList(){
cout
<<
"help - Lista de comandos"
<<
endl
;
cout
<<
"help - Lista de comandos"
<<
endl
;
cout
<<
"quit - Sair"
<<
endl
;
cout
<<
"quit - Sair"
<<
endl
;
}
}
vector
<
string
>
getArgs
(){
string
line
,
arg
;
getline
(
cin
,
line
);
stringstream
ss
(
line
);
vector
<
string
>
args
;
while
(
getline
(
ss
,
arg
,
' '
)){
if
(
!
arg
.
empty
()){
args
.
push_back
(
arg
);
}
}
return
args
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
dirFunctions.cpp
+
3
−
9
View file @
53c7bbd5
...
@@ -9,12 +9,6 @@
...
@@ -9,12 +9,6 @@
using
namespace
std
;
using
namespace
std
;
string
concatStringVector
(
vector
<
string
>
vs
){
ostringstream
oss
;
copy
(
vs
.
begin
(),
vs
.
end
(),
ostream_iterator
<
string
>
(
oss
,
" "
));
return
oss
.
str
();
}
void
cd
(
string
path
){
void
cd
(
string
path
){
if
(
chdir
(
path
.
c_str
())
!=
0
){
if
(
chdir
(
path
.
c_str
())
!=
0
){
cout
<<
"Error: could not change directory."
<<
endl
;
cout
<<
"Error: could not change directory."
<<
endl
;
...
@@ -22,9 +16,9 @@ void cd(string path){
...
@@ -22,9 +16,9 @@ void cd(string path){
}
}
}
}
string
ls
(
vector
<
string
>
args
){
string
ls
(
string
args
){
string
output
,
command
=
concatStringVector
(
args
)
;
string
output
;
FILE
*
lsOut
=
popen
(
command
.
c_str
(),
"r"
);
FILE
*
lsOut
=
popen
(
args
.
c_str
(),
"r"
);
if
(
!
lsOut
){
if
(
!
lsOut
){
throw
"Couldn't execute ls"
;
throw
"Couldn't execute ls"
;
}
}
...
...
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
register
or
sign in
to comment