home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / settime.c < prev    next >
C/C++ Source or Header  |  1993-10-14  |  4KB  |  120 lines

  1. /*
  2.  * File......: SETTIME.C
  3.  * Author....: Dave Pearson
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Dave Pearson
  7.  * Date......: $Date$
  8.  * Revision..: $Revision$
  9.  * Log file..: $Logfile$
  10.  *
  11.  * This is an original work by Dave Pearson and is placed in the public
  12.  * domain.
  13.  *
  14.  * Modification history:
  15.  * ---------------------
  16.  *
  17.  * $Log$
  18.  *
  19.  */
  20.  
  21. // NOTE: This code has been written for and compiled with Borland C++
  22. //       Version 3.1
  23. //
  24.  
  25. #include <extend.h>
  26. #include "internal.h"
  27.  
  28. Boolean ValidTime(char *, int);
  29. Boolean SetDosTime(char, char, char);
  30.  
  31. /*  $DOC$
  32.  *  $FUNCNAME$
  33.  *      GT_SETTIME()
  34.  *  $CATEGORY$
  35.  *      Date
  36.  *  $ONELINER$
  37.  *      Set the DOS system time.
  38.  *  $SYNTAX$
  39.  *      GT_SetTime(<cTime>) --> lSetOk
  40.  *  $ARGUMENTS$
  41.  *      <cTime> is a string parameter that is a time in the same format
  42.  *      as that returned by the Clipper Time() function.
  43.  *  $RETURNS$
  44.  *      If the time was set ok, GT_SetTime() returns true (.T.), if not
  45.  *      it returns false (.F.).
  46.  *  $DESCRIPTION$
  47.  *      GT_SetTime() can be used to set the DOS system time to a new
  48.  *      value.
  49.  *  $EXAMPLES$
  50.  *      // Set the DOS system time to midday.
  51.  *
  52.  *      ? GT_SetTime("12:00:00")
  53.  *  $SEEALSO$
  54.  *      GT_SETDATE()
  55.  *  $END$
  56.  */
  57.  
  58. CLIPPER GT_SetTime()
  59. {
  60.         char    *Time;
  61.         Boolean Result = FALSE;
  62.  
  63.         if (PCOUNT == 1 && ISCHAR(1))
  64.         {
  65.                 Time = _parc(1);
  66.                 if (ValidTime(Time,_parclen(1)))
  67.                 {
  68.                         Result = SetDosTime((char) _GT_Internal_StringAsInt(Time,0,1),
  69.                                             (char) _GT_Internal_StringAsInt(Time,3,4),
  70.                                             (char) _GT_Internal_StringAsInt(Time,6,7));
  71.                 }
  72.         }
  73.         _retl(Result);
  74. }
  75.  
  76. /*****************************************************************************
  77. * Function: ValidTime()                                                      *
  78. * Syntax..: Boolean ValidTime(char *Time, int Length)                        *
  79. * Usage...: Internal function to check that a time string is valid.          *
  80. * By......: David A Pearson                                                  *
  81. *****************************************************************************/
  82.  
  83. static Boolean ValidTime(char *Time, int Length)
  84. {
  85.         Boolean  TimeIsValid = FALSE;
  86.         unsigned Hours;
  87.         unsigned Mins;
  88.         unsigned Secs;
  89.  
  90.         if (Length == 8)
  91.         {
  92.                 if (Time[2] == ':' && Time[5] == ':')
  93.                 {
  94.                         Hours = (unsigned) _GT_Internal_StringAsInt(Time,0,1);
  95.                         Mins  = (unsigned) _GT_Internal_StringAsInt(Time,3,4);
  96.                         Secs  = (unsigned) _GT_Internal_StringAsInt(Time,6,7);
  97.                         TimeIsValid = (Hours < 24 && Mins < 60 && Secs < 60);
  98.                 }
  99.         }
  100.         return(TimeIsValid);
  101. }
  102.  
  103. /*****************************************************************************
  104. * Function: SetDosTime()                                                     *
  105. * Syntax..: Boolean SetDosTime(char Hours, char Mins, char Secs)             *
  106. * Usage...: Internal function to call the DOS set time function.             *
  107. * By......: David A Pearson                                                  *
  108. *****************************************************************************/
  109.  
  110. static Boolean SetDosTime(char Hours, char Mins, char Secs)
  111. {
  112.         asm     Mov     AH,0x2D
  113.         asm     Mov     CH,Hours
  114.         asm     Mov     CL,Mins
  115.         asm     Mov     DH,Secs
  116.         asm     Mov     DL,0
  117.         asm     Int     0x21
  118.         return(_AL != 0xFF);
  119. }
  120.