diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..1c6283f8e4841cd471b0ed9fc11985f052ab6e73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.o +cacoclient +cacoserver \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..15d2058c259e061e11d6c399bc29865f90345fee --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +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* diff --git a/Protocol.cpp b/Protocol.cpp new file mode 100644 index 0000000000000000000000000000000000000000..146b712f302a1343e162fa56aad749db12eb3daf --- /dev/null +++ b/Protocol.cpp @@ -0,0 +1,14 @@ +#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 diff --git a/Protocol.h b/Protocol.h new file mode 100644 index 0000000000000000000000000000000000000000..e361922f0e2f21ab896e7b90b6d3738fa6be00f1 --- /dev/null +++ b/Protocol.h @@ -0,0 +1,17 @@ +#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 diff --git a/client.cpp b/client.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b9d4906f9d4c750d2c7f8bb101911dbfb2ba81a --- /dev/null +++ b/client.cpp @@ -0,0 +1,29 @@ +#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 diff --git a/definitions.h b/definitions.h new file mode 100644 index 0000000000000000000000000000000000000000..6bfad53abd1f2146da7d0b9b8da37c14439c0455 --- /dev/null +++ b/definitions.h @@ -0,0 +1,18 @@ +#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 diff --git a/dirFunctions.cpp b/dirFunctions.cpp new file mode 100644 index 0000000000000000000000000000000000000000..078e39c86c8e4134e08d493d9a79043593ddaba9 --- /dev/null +++ b/dirFunctions.cpp @@ -0,0 +1,28 @@ +#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 diff --git a/dirFunctions.h b/dirFunctions.h new file mode 100644 index 0000000000000000000000000000000000000000..1cb22424a70c1b679ffde53db571a39f89c614b8 --- /dev/null +++ b/dirFunctions.h @@ -0,0 +1,12 @@ +#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