home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PCBOARD / PCBM102.ZIP / SOURCES.ZIP / SYSTEM.C < prev    next >
C/C++ Source or Header  |  1994-01-22  |  3KB  |  100 lines

  1. /*
  2.  ┌────────────────────────────────────────────────────────────────────────┐
  3.  │                                                                        │
  4.  │    ▒▒▒▒▒▒▄ ▒▒▒▒▒▒▄ ▒▒▒▒▒▒▒▄ ▒▒▒▒▒▒▒▒▄ ▒▒▒▒▒▒▄ ▒▒▄      ▒▒▄ ▒▒▒▒▒▒▄     │
  5.  │    ▒▒█▀▒▒█ ▒▒█▀▀▀▀  ▒▒█▀▒▒█ ▒▒█▒▒█▒▒█ ▒▒█▀▒▒█  ▒▒█    ▒▒█▀ ▒▒█▀▀▀▀     │
  6.  │    ▒▒▒▒▒▒█ ▒▒█      ▒▒▒▒▒█▀ ▒▒█▒▒█▒▒█ ▒▒█ ▒▒█   ▒▒█  ▒▒█▀  ▒▒▒▒▄       │
  7.  │    ▒▒█▀▀▀▀ ▒▒█      ▒▒█▀▒▒█ ▒▒█ ▀▀▒▒█ ▒▒█ ▒▒█    ▒▒█▒▒█▀   ▒▒█▀▀       │
  8.  │    ▒▒█     ▒▒▒▒▒▒▄ ▒▒▒▒▒▒▒█ ▒▒█   ▒▒█ ▒▒▒▒▒▒█     ▒▒▒█▀    ▒▒▒▒▒▒▄     │
  9.  │     ▀▀      ▀▀▀▀▀▀  ▀▀▀▀▀▀▀  ▀▀    ▀▀  ▀▀▀▀▀▀      ▀▀▀      ▀▀▀▀▀▀     │
  10.  │                                                                        │
  11.  │      Module   :     SYSTEM.C                                           │
  12.  │                                                                        │
  13.  │      Fonction :     Gestion bas niveau diverses fonctions spécifiques  │
  14.  │                     au système ou à la machine.                        │
  15.  │                                                                        │
  16.  └────────────────────────────────────────────────────────────────────────┘
  17. */
  18.  
  19. #include <io.h>
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <time.h>
  24. #include "pcbmove.h"
  25. #include "strings.h"
  26. #include "system.h"
  27.  
  28. /* ------------------------------------------------------------------------
  29.  *  FRTIME : retourne un pointeur sur une chaine statique contenant
  30.  *           la date en ascii et en Francais.
  31.  *
  32.  * SFRTIME : Idem mais plus court.  (sans system.c)
  33.  */
  34.  
  35. char *frtime( long t )
  36. {
  37.  
  38.      struct tm *tm;
  39.  
  40.      tm = localtime( &t );
  41.  
  42.      sprintf(tampon,"%s %02d %s %d , %02d H %02d mn %02d s",
  43.              _days_[tm->tm_wday], tm->tm_mday,
  44.              _months_[tm->tm_mon],tm->tm_year + 1900,
  45.              tm->tm_hour, tm->tm_min, tm->tm_sec );
  46.  
  47.   return (tampon);
  48. }
  49.  
  50. /* ------------------------------------------------------------------------ */
  51.  
  52. char *sfrtime( long t )
  53. {
  54.  
  55.      struct tm *tm;
  56.  
  57.      tm = localtime ( &t );
  58.  
  59.      sprintf(tampon,"%02d %s %02d  %02d:%02d",
  60.               tm->tm_mday,
  61.              _months_[tm->tm_mon],tm->tm_year ,
  62.              tm->tm_hour, tm->tm_min );
  63.  
  64.   return (tampon);
  65. }
  66.  
  67. /*-------------------------------------------------------------------------*/
  68. /*
  69.  
  70.       Calcul du crc:extrait de la documentation de Chuck Forsberg
  71.  
  72.          Figure 8.  Example of CRC Calculation written in C
  73.  
  74.  
  75.     This function calculates the CRC used by the XMODEM/CRC Protocol
  76.     The first argument is a pointer to the message block.
  77.     The second argument is the number of bytes in the message block.
  78.     The function returns an integer which contains the CRC.
  79.     The low order 16 bits are the coefficients of the CRC.
  80. */
  81.  
  82.    int calcrc(char *ptr, int count)
  83.    {
  84.        int crc, i;
  85.  
  86.        crc = 0;
  87.        while(--count >= 0)
  88.            {
  89.            crc = crc ^ (int)*ptr++ << 8;
  90.            for(i = 0; i < 8; ++i)
  91.                if(crc & 0x8000)
  92.                    crc = crc << 1 ^ 0x1021;
  93.                else
  94.                    crc = crc << 1;
  95.            }
  96.        return (crc & 0xFFFF);
  97.    }
  98.  
  99. /*--------------------------------------------------------------------------*/
  100.