-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
146 lines (118 loc) · 4.77 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "MessageDB.h"
#include "MessageBox.h"
#include <sys/ioctl.h> /* ioctl, TIOCGWINSZ */
extern FILE * FileDebug;
extern FILE * FileOutput;
extern FILE * FileError;
#ifdef NO_TIMEINTERVAL
#define SLEEP_BETWEEN_TWO_BOXES 0
#else
#define SLEEP_BETWEEN_TWO_BOXES 2
#endif
const char REALISEPAR[] = "Realise par les V\x1b[2mieux\x1b[0mC\x1b[2mons\x1b[0mA\x1b[2migris\x1b[0m2010 <ThxCathCass@gmail.com>";
const char MERCI[] = "Merci cathcass !";
const char MESSAGESPAR[] = "Messages par les eleves de l'Ensimag";
void verifyTerminalSize(void);
void verifyTerminalSize(void)
{
setScreenHeight(MIN_LINESIZE);
setScreenWidth(MIN_COLUMNSIZE);
if (FileOutput)
{
struct winsize ws;
int FileOutputFD = fileno(FileOutput);
if (ioctl(FileOutputFD, TIOCGWINSZ, &ws) < 0)
{
fprintf(FileOutput, "La taille de votre terminal "
"doit faire au moins [%dx%d] et n'a pas pu etre determinee\n"
"Agrandissez maintenant la fenetre et appuyez sur ENTREE\n",
MIN_COLUMNSIZE, MIN_LINESIZE);
fflush(stdin);
getchar();
fflush(stdin);
setScreenHeight(MIN_LINESIZE);
setScreenWidth(MIN_COLUMNSIZE);
}
else
{
fprintf(FileOutput, "La taille de votre terminal "
"doit faire au moins [%dx%d] et fait actuellement [%dx%d]\n"
"Agrandissez maintenant la fenetre et appuyez sur ENTREE\n",
MIN_COLUMNSIZE, MIN_LINESIZE,
ws.ws_col, ws.ws_row);
fflush(stdin);
getchar();
fflush(stdin);
ioctl(FileOutputFD, TIOCGWINSZ, &ws);
setScreenHeight(ws.ws_row);
setScreenWidth(ws.ws_col);
fprintf(FileOutput, "La taille de votre terminal "
"enregistrée est : [%dx%d].\nLancement dans 1 seconde...\n",
getScreenWidth(), getScreenHeight());
sleep(1);
}
}
}
int main()
{
/* Local Variables */
int l_iResult = 0;
unsigned int l_uiMesgNb = 0;
#ifdef DEBUG
#ifdef ONLYERRORS
FileDebug = NULL;
#else
FileDebug = stderr;
#endif
FileOutput = stdout;
FileError = stderr;
#else
FileDebug = NULL;
FileOutput = stdout;
FileError = NULL;
#endif
/* Verify Window size */
verifyTerminalSize();
/* Clear output screen */
if (FileOutput) fprintf(FileOutput, "\x1b[0m\x1b[2J");
/* Shuffle Messages */
melange();
/* Printing all messages */
for (l_uiMesgNb = 0; l_uiMesgNb < NBMESSAGES; l_uiMesgNb++)
{
#ifdef DEBUG
if (FileDebug)
{
fprintf(FileDebug, "Msg (%d)\n", g_auiOrdre[l_uiMesgNb]);
}
#endif
l_iResult = CreateMessageBox(MESSAGES[g_auiOrdre[l_uiMesgNb]]);
#ifdef DEBUG
if (FileDebug)
{
fprintf(FileDebug, "CreateMessageBox returned %d\n", l_iResult);
}
#endif
sleep(SLEEP_BETWEEN_TWO_BOXES);
}
if (FileOutput) fprintf(FileOutput, "Appuyez sur ENTREE pour quitter... \n");
/* Wait for input */
fflush(stdin);
getchar();
fflush(stdin);
/* Last message */
if (FileOutput)
{
fflush(FileOutput);
fprintf(FileOutput, "\x1b[0m\x1b[2J");
fprintf(FileOutput, "\x1b[%d;%df%s", getScreenHeight()/2, (getScreenWidth() - (unsigned int) sizeof(MERCI)) /2, MERCI);
fprintf(FileOutput, "\x1b[%d;%df%s", getScreenHeight()-1, (getScreenWidth() - (unsigned int) (sizeof(REALISEPAR)-6*4)) /2, REALISEPAR);
fprintf(FileOutput, "\x1b[%d;%df%s", getScreenHeight()-2, (getScreenWidth() - (unsigned int) sizeof(MESSAGESPAR))/2, MESSAGESPAR);
fprintf(FileOutput, "\x1b[%d;1f",getScreenHeight());
fflush(FileOutput);
}
return l_iResult;
}