-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcppMaker.main.cpp
More file actions
94 lines (80 loc) · 2.01 KB
/
cppMaker.main.cpp
File metadata and controls
94 lines (80 loc) · 2.01 KB
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
#include "cppMaker.main.hpp"
volatile std::sig_atomic_t g_interrupted = 0;
void on_sigint(int)
{
g_interrupted = 1;
}
void setSignals(void)
{
struct sigaction sa{};
sa.sa_handler = on_sigint;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGINT, &sa, nullptr);
}
void createMenus(ListOfMenu &listOfMenus)
{
// CREATE THE SUBMENUS
listOfMenus.addMenu("MainMenu");
listOfMenus.addMenu(MAKEFILE);
listOfMenus.addMenu(MAIN);
listOfMenus.addMenu(CLASS);
listOfMenus.addMenu(CPP);
// INIT THE SUBMENUS INPUT TYPES
int i = 0;
MenuList *main = listOfMenus.getMenu(i);
main->addItemBasic(MAKEFILE);
main->getItem(i++)->setInputType(tMAKEFILE);
main->addItemBasic(MAIN);
main->getItem(i++)->setInputType(tMAIN_HPP);
main->addItemBasic(CLASS);
main->getItem(i++)->setInputType(tCLASS_HPP);
main->addItemBasic(CPP);
main->getItem(i++)->setInputType(tCPP);
// INIT THE MAKEFILE LINKED FUNCTION
MenuList *makeFile = listOfMenus.getMenu(1);
makeFile->function = makefileMaker;
MenuList *ptrMain = listOfMenus.getMenu(2);
ptrMain->function = mainMaker;
MenuList *ptrClass = listOfMenus.getMenu(3);
ptrClass->function = classMaker;
MenuList *ptrCpp = listOfMenus.getMenu(4);
ptrCpp->function = dotCppMaker;
}
int main()
{
setSignals();
int index = -1;
ListOfMenu ListOfMenus;
MenuItem *item;
MenuList *subMenu;
MenuList *mainMenu;
createMenus(ListOfMenus);
std::cout << "listOfMenus of menu " << ListOfMenus.getSize() << std::endl;
try
{
while (index == -1)
{
mainMenu = ListOfMenus.getMenu(0);
printMenu(*mainMenu, "Exit", MenuField::Name);
index = handleIndexInput("index", mainMenu->getSize(), getIndex);
if (index == 0)
return (0);
item = mainMenu->getItem(index - 1);
subMenu = ListOfMenus.getMenu(index);
if (!item || !subMenu || !mainMenu || !subMenu->function)
{
std::cerr << "error main" << std::endl;
return (1);
}
if (subMenu->function(item, subMenu))
return (12);
index = -1;
}
}
catch (const std::exception &e)
{
return (1);
}
return (0);
}