-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
59 lines (46 loc) · 1.28 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include "menu.h"
#include "user.h"
#include "budget.h"
int load(NODE **users, NODE **budgets, NODE **queue){
/* load program from files */
load_users(users);
load_budgets(budgets);
load_queue(*budgets, queue);
// If user file was empty, populate with root
if(length(*users) == 0){
USER root = {"root","root","root",admin};
USER *data = (USER*) malloc(sizeof (USER));
if(data != NULL){
*data = root;
add_user(users,data);
save_users(*users);
}
}
}
int main() {
int res = 0;
NODE *users = NULL;
NODE *budgets = NULL;
NODE *queue = NULL;
USER *auth = NULL;
load(&users, &budgets, &queue);
/*
* while res == -4, it will keep in a loop
* res == -4, means that user has selected 'sign out' on the menu
*/
do {
/*
* Enters the auth menu aka login menu.
* returning -1 means that the user wants to exit the program.
*/
if (initial_menu(users, &auth) == -1) return 0;
if(auth->role == admin){
res = admin_menu(*auth, &users, &budgets, &queue);
}else{
res = user_menu(*auth,&budgets,&queue);
}
}while(res == -4);
printf("Exiting...");
return 0;
}