Portability
Chargement...
Recherche...
Aucune correspondance
portability.h
Aller à la documentation de ce fichier.
1/* ***************************************************************************
2 * Cette bibliothèque de fonctions est distribuée librement par l'iTeam !
3 *
4 * Son but est de fournir un moyen simple pour compiler les codes enseignés
5 * à l'ECE (qui ne marchent correctement que sous Windows).
6 * Nous vous invitons à l'utiliser et l'améliorer. La dernière version
7 * est disponible sur https://github.com/iTeam-Projects/PortabilityCode
8 *
9 *
10 * iTeam - association de Promotion du Logiciel Libre
11 * ***************************************************************************
12 * Fonctions non-portables gérées :
13 * system("PAUSE");
14 * system("CLS");
15 * fflush(stdin);
16 * kbhit();
17 * sleep();
18 * fonction couleurs dans la console
19 * Fonctions non-portables en attente :
20 * getch();
21 */
22
23#ifndef PORTABILITY_H_INCLUDED
24#define PORTABILITY_H_INCLUDED
25
26
71/* Remarques pour les développeurs de ce fichier:
72 * - Les valeurs de retour des fonctions sont conservés pour compatibilités
73 * - Les fonctions usuelles non-portable de Windows sont prises en référence
74 * - Toute nouvelle fonction doit être testée sous les 3 OS
75 * - Les résultats des tests doivent apparaître dans le wiki GitHub
76 */
77
78// Quelques bibliothèques standards utiles
79#include <stdio.h>
80#include <stdlib.h>
81#include <string.h>
82#include <ctype.h>
83#include <strings.h>
84#include <errno.h>
85
86#ifdef _WIN32 // Si l'on est sous Windows
87 #include <conio.h>
88 #include <windows.h>
89#else // Si l'on est sous Linux ou Mac
90 #include <termios.h>
91 #include <unistd.h>
92 #include <sys/types.h>
93 #include <sys/time.h>
94#endif
95
100typedef enum
101{
110 COLOR_GRAY = 37
112
113
114
120
126
127
133
138
139
140/* Remove existing aliases */
141#ifdef gotoligcol
142# undef gotoligcol
143#endif
144#ifdef kbhit
145# undef kbhit
146#endif
147#ifdef Sleep
148# undef Sleep
149#endif
150#ifdef system
151# undef system
152#endif
153#ifdef fflush
154# undef fflush
155#endif
156
179#define gotoligcol(x, y) portability_gotoligcol(x, y)
180
191#define kbhit() portability_kbhit()
192
201#define Sleep(time) portability_sleep(time)
202
220#define system(arg) portability_system_call(arg)
221
232#define fflush(arg) portability_clear_buffer(arg)
233
234// http://msdn.microsoft.com/en-us/library/e0z9k731(v=vs.90).aspx
251#define strcasecmp(str1, str2) _stricmp(str1, str2)
252
253#ifndef _WIN32
254# undef strcasecmp
255#endif
256
257#ifdef ERROR
258# undef ERROR
259#endif
260
280#define ERROR(message, ...) \
281 fprintf(stderr, "*** [%s:%i] "msg"\n", __func__, __LINE__, ## __VA_ARGS__)
282
285/* Compatibility functions */
286void portability_gotoligcol(int poslig, int poscol);
287int portability_kbhit(void);
288void portability_clear_buffer(FILE *f);
289void portability_sleep(unsigned int time);
290int portability_system_call(const char *cmd);
291
292#endif // PORTABILITY_H_INCLUDED
293
void portability_text_color_set(Color color)
void portability_background_color_set(Color color)
void portability_init(void)
Color
Definition: portability.h:101
void portability_shutdown(void)
@ COLOR_DEFAULT
Definition: portability.h:102
@ COLOR_BLUE
Definition: portability.h:107
@ COLOR_BLACK
Definition: portability.h:103
@ COLOR_GRAY
Definition: portability.h:110
@ COLOR_MAGENTA
Definition: portability.h:108
@ COLOR_RED
Definition: portability.h:104
@ COLOR_CYAN
Definition: portability.h:109
@ COLOR_YELLOW
Definition: portability.h:106
@ COLOR_GREEN
Definition: portability.h:105