first version of the client command parser
This commit is contained in:
parent
897c8150a5
commit
757e231d8f
2 changed files with 68 additions and 5 deletions
|
@ -1,5 +1,4 @@
|
|||
#include "client.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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 <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;
|
||||
}
|
||||
|
|
|
@ -8,5 +8,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MAX_VALUE_LENGTH 100
|
||||
|
||||
int send_message(unsigned int sender, unsigned int receiver);
|
||||
#endif // !CLIENT_H
|
||||
|
|
Loading…
Reference in a new issue