MODULE T5;


IMPORT termios, FIO, SYSTEM, STextIO, NumberIO;

TYPE
    termiosType =   RECORD
                        c_iflag     : BITSET;		
                        c_oflag     : BITSET;
                        c_cflag     : BITSET;
                        c_lflag     : BITSET;
                        c_line      : SYSTEM.BITSET8;	
                        c_cc        : SYSTEM.BITSET8;
                        c_ispeed    : BITSET;
                        c_ospeed    : BITSET;	
                    END;

VAR
    thetermios : termios.TERMIOS;
    result : INTEGER;
    tempFlags : BITSET;
    iflag, c_oflag, cflag, lflag : BITSET;
    tt : termiosType;
    ttPointer : POINTER TO termiosType;
    size :  CARDINAL;

    PROCEDURE PrintBitset( x : BITSET);

        VAR
            i : CARDINAL;

        BEGIN
            FOR i := 0 TO (SYSTEM.TSIZE(BITSET) * 8) -1 DO
                IF (i MOD 8) = 0 THEN 
                    STextIO.WriteString(" |") 
                END;
                IF i IN x THEN 
                    STextIO.WriteString(" 1") 
                ELSE 
                     STextIO.WriteString(" 0")  
                END;         
            END;
        END PrintBitset;


BEGIN
    thetermios := termios.InitTermios();
    result := termios.tcgetattr(FIO.StdIn, thetermios);
    ttPointer := thetermios;
    (* PROCEDURE TBITSIZE (<type>) : CARDINAL ; *)
    size := SYSTEM.TSIZE(INTEGER);
    STextIO.WriteString(" taille de INTEGER ici : ");
    NumberIO.WriteCard(size,5);
    STextIO.WriteLn;
    size := SYSTEM.TSIZE(CARDINAL);
    STextIO.WriteString(" taille de CARDINAL ici : ");
    NumberIO.WriteCard(size,5);
    STextIO.WriteLn;
    size := SYSTEM.TSIZE(BITSET);
    STextIO.WriteString(" taille de BITSET ici : ");
    NumberIO.WriteCard(size,5);
    STextIO.WriteLn;
    STextIO.WriteString(" Valeur de licanon :");
    NumberIO.WriteInt(termios.licanon, 5);
    STextIO.WriteString(" Valeur de opost :");
    NumberIO.WriteInt(termios.opost, 5);
    STextIO.WriteLn;
    IF (CARDINAL(termios.licanon) MOD 8) IN ttPointer^.c_iflag THEN
        STextIO.WriteString("yes, it's here !!")
    ELSE
        STextIO.WriteString("no, it's not :( here !!")
    END;
    STextIO.WriteLn;
    NumberIO.WriteCard(INTEGER(ttPointer^.c_iflag),5);
    STextIO.WriteLn;
    PrintBitset(ttPointer^.c_iflag);
    STextIO.WriteLn;
END T5.