diff --git a/src/client/client.c b/src/client/client.c index 0332483..7952575 100644 --- a/src/client/client.c +++ b/src/client/client.c @@ -1,5 +1,4 @@ #include "client.h" -#include int send_message(unsigned int sender, unsigned int receiver) { int pipe_to_child[2]; @@ -57,10 +56,72 @@ int send_message(unsigned int sender, unsigned int receiver) { return 0; } -int main() { +// Function to print usage information +void printUsage() { + printf("Usage: message_cli [options]\n"); + printf("Options:\n"); + printf(" -h, --help Display this help message\n"); + printf(" -g, --group Send message to a group\n"); + printf(" -s, --sync Send message synchronously\n"); + printf(" -u, --uid Specify the UID of the receiver\n"); +} + +int main(int argc, char *argv[]) { // TODO: Client parsing to be done - unsigned int sender = getuid(); - unsigned int receiver = 1000; - send_message(sender, receiver); + + int groupFlag = 0; + int syncFlag = 0; + char receiverUid[MAX_VALUE_LENGTH]; + + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { + printUsage(); + exit(0); + } else if (strcmp(argv[i], "-g") == 0 || strcmp(argv[i], "--group") == 0) { + groupFlag = 1; + if (i + 1 < argc && argv[i + 1][0] != '-') { + strncpy(receiverUid, argv[i + 1], MAX_VALUE_LENGTH); + i++; // Skip the next argument since it's the value + } + } else if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--sync") == 0) { + syncFlag = 1; + if (i + 1 < argc && argv[i + 1][0] != '-') { + strncpy(receiverUid, argv[i + 1], MAX_VALUE_LENGTH); + i++; // Skip the next argument since it's the value + } + } else if (strcmp(argv[i], "-u") == 0 || strcmp(argv[i], "--uid") == 0) { + if (i + 1 < argc && argv[i + 1][0] != '-') { + strncpy(receiverUid, argv[i + 1], MAX_VALUE_LENGTH); + i++; // Skip the next argument since it's the value + } else { + fprintf(stderr, "Error: No value provided for option %s\n", argv[i]); + printUsage(); + exit(1); + } + } else { + fprintf(stderr, "Error: Unknown option %s\n", argv[i]); + printUsage(); + exit(1); + } + } + + if (groupFlag) { + if (syncFlag) { + // send to group synchronously + } else { + // send to group asynchronously + } + } else { + if (syncFlag) { + // send to user synchronously + } else { + // send to user asynchronously + } + } + + // unsigned int sender = getuid(); + // unsigned int receiver = 1000; + // send_message(sender, receiver); + return 0; } diff --git a/src/client/client.h b/src/client/client.h index 4d190be..ef668d5 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -8,5 +8,7 @@ #include #include +#define MAX_VALUE_LENGTH 100 + int send_message(unsigned int sender, unsigned int receiver); #endif // !CLIENT_H