parallax 1.0
command-line based task/todo manager
Loading...
Searching...
No Matches
main.c
1#include <stdlib.h>
2#include <stdio.h>
3
4#include "argparse.h"
5#include "hashmap.h"
6#include "task.h"
7#include "test.h"
8
9#define FLAG_INDEX 1
10#define FIRST_CONTENT_INDEX 2
11#define SECOND_CONTENT_INDEX 3
12#define DEFAULT_CLASS "def"
13
14
15int main(int argc, char* argv[])
16{
17 const int NUM_OF_ARGS = argc - 1;
18
19 if (NUM_OF_ARGS < 2)
20 {
21 printf("Error: Expected 2 or more arguments, got %d\n", NUM_OF_ARGS);
22 printf("Usage: prlx [FLAGS] [CONTENT/IDENTIFIER] [CONTENT]\n");
23 return -1;
24 }
25
26 // test entrypoint
27 if ( strcmp(argv[FLAG_INDEX], "-t") == 0 )
28 {
29 if ( argparse_test() != 1 )
30 {
31 return EXIT_FAILURE;
32 }
33 else if ( task_test() != 1 )
34 {
35 return EXIT_FAILURE;
36 }
37 return EXIT_SUCCESS;
38 }
39
40 const char* content = get_content_arg(argv[FIRST_CONTENT_INDEX]);
41 char* class = NULL;
42
43 FLAG_TYPE flag = get_flag(argv[FLAG_INDEX]);
44 switch (flag)
45 {
46 case FLAG_CREATE: // 1: content 2: class if necessary
47 if (NUM_OF_ARGS == 2)
48 {
49 class = "def";
50 } else
51 {
52 class = get_content_arg(argv[SECOND_CONTENT_INDEX]);
53 }
54 break;
55 case FLAG_REMOVE:
56 printf("Remove flag detected\n");
57 break;
58 case FLAG_MODIFY:
59 printf("Modify flag detected\n");
60 break;
61 case FLAG_LIST:
62 printf("List flag detected\n");
63 break;
64 case FLAG_INVALID:
65 printf("Flag error: %s is not a valid flag.\nConsult 'prlx --help' for info on flags.\n", argv[FLAG_INDEX]);
66 break;
67 }
68
69
70 return EXIT_SUCCESS;
71}
Contains functions for extracting content from the argument vector.
FLAG_TYPE
Possible flag types.
Definition argparse.h:15
@ FLAG_CREATE
Definition argparse.h:16
Contains the structures and procedures for hashmap-related operations.
Contains structures and functions for handling task-related operations.
int argparse_test()
Definition test.c:25