Skip to content
Snippets Groups Projects
Commit 2b354dad authored by Israel Barreto Sant'Anna's avatar Israel Barreto Sant'Anna
Browse files

Implemented local cd and ls. Created Protocol class.

parent 89c87cb8
No related branches found
No related tags found
No related merge requests found
*.o
cacoclient
cacoserver
\ No newline at end of file
Makefile 0 → 100644
CFLAGS= -g -Wall -O2
CC=g++
OBJ=Protocol.o
%.o: %.cpp
$(CC) $(CFLAGS) $^ -c -o $@
cacoclient: client.cpp $(OBJ)
$(CC) $(CFLAGS) $^ -o $@
# cacoserver: $(OBJ) client.cpp
# $(CC) $(CFLAGS) $^ -o $@
clean:
rm -f *.o caco*
#include "Protocol.h"
#include "definitions.h"
Message Protocol::getMessage(){
return message;
}
void Protocol::setMessage(Message message){
this->message = message;
}
Protocol::Protocol(){
message.begin = 0x7E;
}
\ No newline at end of file
#ifndef __PROTOCOL__
#define __PROTOCOL__
#include "definitions.h"
class Protocol{
private:
Message message;
vector<char> data;
public:
Message getMessage();
void setMessage(Message message);
Protocol();
};
#endif
\ No newline at end of file
#include "definitions.h"
#include "dirFunctions.h"
int main(){
while(true){
string command, path;
cout << endl << "Entre com o comando:" << endl;
cin >> command;
if(command == "quit"){
break;
}
cin >> path;
if(command == "cd"){
cd(path);
}else if(command == "ls"){
ls(path);
}else if(command == "cdr"){
//TODO
}else if(command == "lsr"){
//TODO
}else if(command == "put"){
//TODO
}else if(command == "get"){
//TODO
}
}
return 0;
}
\ No newline at end of file
#ifndef __DEFINITIONS__
#define __DEFINITIONS__
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;
typedef struct {
int begin : 8,
size : 6,
sequence: 6,
type : 4,
parity : 8;
}Message;
#endif
\ No newline at end of file
#include <iostream>
#include <errno.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
using namespace std;
void cd(string path){
if(chdir(path.c_str()) != 0){
cout << "Error: could not change directory." << endl;
cerr << strerror(errno) << endl;
}
}
void ls(string path){
//TODO: #1
struct dirent *entry;
DIR *dir = opendir(path.c_str());
if(dir != NULL){
while((entry=readdir(dir)) != NULL){
cout << entry->d_name << endl;
}
closedir(dir);
}else{
cout<<"Error: could not open directory."<<endl;
}
}
\ No newline at end of file
#ifndef __DIRFUNCTIONS__
#define __DIRFUNCTIONS__
#include "dirFunctions.cpp"
#include <string.h>
using namespace std;
void cd(string path);
void ls(string path);
#endif
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment