/***************************************************************************** Gestionnaire de terminal Unix: clock.c (c) Pierre Adriaans 1994 Prevu pour fonctionner soit par sigaction() soit par signal(). *****************************************************************************/ #include #include #include #include #include #include "clock.h" #include "screen.h" int ClockLig,ClockCol,ClockType; char ClockAttr; unsigned int ClockRemains,ClockTicks; #ifdef SIGACT struct sigaction ClockNewAlrm,ClockOldAlrm,ClockDummy; #else void (*ClockAlrmFct)(int); #endif /***************************************************************************** ClockIntFct() ------------------------------------------------------------------------------ Input,Output: / Process: fonction d'interruption de l'horloge *****************************************************************************/ void ClockIntFct(int sig) { DisplayTime(); #ifdef SIGACT sigaction(SIGALRM,&ClockNewAlrm,&ClockDummy); #else signal(SIGALRM,ClockIntFct); #endif alarm(ClockTicks); } /***************************************************************************** InitClock() ------------------------------------------------------------------------------ Input: Lig: ligne d'affichage Col: colonne d'affichage Attr: attribut d'affichage Type: HOUR_MIN_SEC ou HOUR_MIN Process: initialisation de l'horloge et affichage de l'heure une fois Output: / *****************************************************************************/ void InitClock(int Lig,int Col,char Attr,int Type) { ClockLig = Lig; ClockCol = Col; ClockAttr = Attr; ClockType = Type; if(Type == HOUR_MIN_SEC) ClockTicks = 1; else ClockTicks = 60; DisplayTime(); #ifdef SIGACT ClockNewAlrm.sa_handler = ClockIntFct; sigemptyset(&ClockNewAlrm.sa_mask); ClockNewAlrm.sa_flags = 0; sigaction(SIGALRM,&ClockNewAlrm,&ClockOldAlrm); #else ClockAlrmFct = signal(SIGALRM,ClockIntFct); #endif ClockRemains = alarm(ClockTicks); } /***************************************************************************** CancelClock() ------------------------------------------------------------------------------ Input,Output: / Process: retablissement de l'ancienne interruption d'horloge. Permet d'interrompre momentanement l'affichage de l'heure en conservant les parametres de fonctionnement initialises *****************************************************************************/ void CancelClock(void) { #ifdef SIGACT sigaction(SIGALRM,&ClockOldAlrm,&ClockDummy); if(ClockOldAlrm.sa_handler != SIG_IGN) alarm(ClockRemains); #else signal(SIGALRM,ClockAlrmFct); if(ClockAlrmFct != SIG_IGN) alarm(ClockRemains); #endif } /***************************************************************************** ResumeClock() ------------------------------------------------------------------------------ Input,Output: / Process: retablit l'affichage de l'heure avec les parametres de fonctionnement actuels *****************************************************************************/ void ResumeClock(void) { ClockIntFct(SIGALRM); } /***************************************************************************** DisplayTime() ------------------------------------------------------------------------------ Input,Output: / Process: affichage de l'heure suivant les parametres globaux *****************************************************************************/ void DisplayTime(void) { time_t t; char Buffer[25]; int X,Y; char Att; time(&t); sprintf(Buffer,"%s",ctime(&t)); if(ClockType == HOUR_MIN_SEC) Buffer[20] = 0; else Buffer[16] = 0; GetXY(&Y,&X); Att = GetCurrentAtt(); MoveCurs(ClockLig,ClockCol); if(ClockAttr != Att) SetAtt(ClockAttr); printf("%s",Buffer+11); if(ClockAttr != Att) SetAtt(Att); MoveCurs(Y,X); fflush(stdout); }