-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.c
106 lines (91 loc) · 3.37 KB
/
commands.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdio.h>
#include <stdlib.h>
#include "datastructs.h"
#include "visual.h"
#include "utility.h"
#include "export.h"
#include "commands.h"
/* Dialog with user post algorithm. Allows user to print and export in various ways */
void show_commands(Group *grps, int groupCount, DataSet data, int debug) {
do {
char option;
/* Ask user about what they wanna do next */
set_color(GREEN, BLACK);
printf("\nWhat do you want to do now?\n");
reset_color();
/* Print options */
printf("(a) Inspect final groups.\n");
printf("(b) Toggle debug flag. Currently %s.\n", debug?"ON":"OFF");
printf("(c) Export groups plain.\n");
printf("(d) Export groups CSV.\n");
printf("(e) See specific group.\n");
printf("(f) See specific person.\n");
printf("(q) Quit program.\n");
/* Scan for input */
scanf(" %c", &option);
clear_screen();
/* Switch over options */
switch (option) {
case 'a': print_all_groups(grps, groupCount, data.allCriteria, data.criteriaCount, debug); break;
case 'b': debug = !debug; break;
case 'c': export_plain(grps, groupCount); break;
case 'd': export_to_csv(grps, groupCount); break;
case 'e': see_group(grps, groupCount, data.criteriaCount, debug); break;
case 'f': see_person(grps, groupCount, data.criteriaCount, debug); break;
case 'q': return;
}
} while (1);
}
/* Prints an error message if options is not implemented yet */
void print_not_implemented() {
set_color(COLOR_ERROR, BLACK);
printf("Not implemented yet :(\n");
reset_color();
}
/*prints a requested group*/
void see_group(Group *grps, int groupCount, int criteriaCount, int debug) {
int groupID;
do {
printf("There is %d groups present. Type the group number you wish to inspect: ", groupCount );
/* if an int is not input, terminate program, however if "f" or "q" is used, program switches in function-dialogue */
if (scanf(" %d", &groupID) != 1) {
printf("Input not recognised as an integer.\n");
return;
}
/* checks if the input is a valid group ID */
} while ( groupID <= 0 || groupID > groupCount );
groupID--;
/* print requested group */
printf("\n");
print_group(&(grps[groupID]), criteriaCount, debug);
printf("\n");
}
/* prints the group, which a person is in */
void see_person(Group *grps, int groupCount, int criteriaCount, int debug) {
int i, j, match = -1;
char needle[40];
printf("Which person do you want to search for?\n");
scanf(" %[^\n]s", needle);
/* searches all groups */
for (i=0; i<groupCount; i++) {
/* searches all members' names in the groups */
for (j=0; j<grps[i].memberCount; j++) {
/* if the person is found, save the location as match */
if (strequal(grps[i].members[j].name, needle)) {
match = i;
break;
}
}
if (strequal(grps[i].members[j].name, needle)) {
break;
}
}
/* if a match is found, print group */
if (match != -1) {
printf("\n\"%s\" found in group %d \n",needle, i + 1);
reset_color();
print_group(&(grps[i]), criteriaCount, debug);
printf("\n");
}
else printf("\nPerson not found \n\n");
}