
//   Incl: Redefinitions generales 

#ifndef _DEFINITIONS_H
#define _DEFINITIONS_H

                                  /* ------ Fichiers */
#include <stdio.h>
typedef FILE* Filetext;

#include <string.h>
typedef       char*  Cstring;

#define EOS    '\0'
#define EOL    '\n'
#define CHVIDE ""
                                  /* ------ Operateurs   */
#define  MODULO %
#define  OR  ||
#define  AND &&
#define  NOT !

#define  Procedure void
#define  Global    static
#define  Or  ||
#define  And &&
#define  Not !

#define  Modulo(i,j) ((i) % (j))
#define  Integer(x) ((int) (x))
#define  Cequals(ch1,ch2)  !strcmp(ch1,ch2)

#define  Repeat(i,n) for (int i=0; i<n; i++)

#define  Cestvide(ch)       !ch[0]
#define  Cestnonvide(ch)     ch[0]

#define  Displayr(v) printf (" ... " #v " = %g\n", v)
#define  Displayi(v) printf (" ... " #v " = %d\n", v)
#define  Displays(v) printf (" ... " #v " = %s\n", v)

#ifdef __cplusplus

#include <iostream>
using namespace std;
#define Display(v) cout << " ... " #v " = " << v << endl
#define Print(mess)   cout <<  mess << endl

//================================================== ReadString
inline int ReadString (Cstring buffer, Cstring question="", int lgmax=127)
{
   printf (question);
   fgets (buffer, lgmax+1, stdin);

   int lg = strlen (buffer);
   if (lg==0) return 0;

   if (buffer [lg-1] == '\n') 
       buffer [lg-1] = '\0';
   return lg-1;
}
 
//================================================== NewString
inline Cstring NewString(Cstring original)
{
   int lg = strlen (original);
   Cstring copie = new char [lg+1];
   strcpy (copie, original);

   return copie;
}
//================================================== ReadInteger
inline int ReadInteger(Cstring question="")
{
   const int size_buf = 16;
   char reponse[size_buf+1];

   while (1)
         {
         int lg = ReadString (reponse, question, size_buf);
         if (lg>0)
            {
            int value;
            sscanf (reponse, "%d", &value);
            return value;
            }
         }
}
//================================================== ReadReal
inline float ReadReal(Cstring question="")
{
   const int size_buf = 16;
   char reponse[size_buf+1];

   while (1)
         {
         int lg = ReadString (reponse, question, size_buf);
         if (lg>0)
            {
            float value;
            sscanf (reponse, "%g", &value);
            return value;
            }
         }
}
#endif

#endif
