home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / logfile.prg < prev    next >
Text File  |  1993-10-14  |  3KB  |  105 lines

  1. /*
  2.  * File......: LOGFILE.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_LOGFILE()
  24.  *  $CATEGORY$
  25.  *      General
  26.  *  $ONELINER$
  27.  *      Maintain a text log file
  28.  *  $SYNTAX$
  29.  *      GT_LogFile( cText , cFile , lTimeStamp )
  30.  *  $ARGUMENTS$
  31.  *      cText      - Text to add to log file
  32.  *      cFile      - File to update
  33.  *      lTimeStamp - If .T. add a time stamp
  34.  *  $RETURNS$
  35.  *      NIL
  36.  *  $DESCRIPTION$
  37.  *      Adds the given text to a text log file.  If lTimeStamp is .T.,
  38.  *      a date and time stamp is added before the text.
  39.  *      If cFile does not exist, it is created.
  40.  *  $EXAMPLES$
  41.  *
  42.  *  $SEEALSO$
  43.  *
  44.  *  $INCLUDE$
  45.  *      GT_LIB.CH
  46.  *  $END$
  47.  */
  48. *
  49. #include "GT_LIB.ch"
  50.  
  51. FUNCTION GT_LogUpdate( cText , cFile, lTimeStamp )
  52.  
  53. /*****************************************************************************
  54.  Purpose - Output the given text to the log file, together with date and
  55.            time stamps
  56.  Returns - None
  57.  Author  - Martin Colloby
  58.  Created - 13/11/91
  59. ******************************************************************************
  60.  Parameters - cText      - Text to be written to file
  61.               cFile      - File to be writtem to
  62.               lTimeStamp - If true append date and time to logfile entry
  63.  Locals     - nHandle - Handle of text file
  64.  Externals  - None
  65. *****************************************************************************/
  66.  
  67. LOCAL nHandle := 0
  68.  
  69. DEFAULT lTimeStamp TO .T.
  70.  
  71. * Check to see if the file exists
  72. IF !FILE( cFile )
  73.     * File doesn't exist, so create it
  74.     nHandle := FCREATE( cFile )
  75.     IF nHandle == -1
  76.         GT_Warning( { "FATAL ERROR :" , ;
  77.                       "Cannot create log file " + cFile } )
  78.         QUIT
  79.     ENDIF
  80. ELSE
  81.     * File exists, so open it
  82.     nHandle := FOPEN( cFile , FO_WRITE )
  83.     IF nHandle == -1
  84.         GT_Warning( { "FATAL ERROR :" , ;
  85.                       "Cannot open log file " + cFile } )
  86.         QUIT
  87.     ENDIF
  88. ENDIF
  89.  
  90. * Find the end of the file
  91. FSEEK( nHandle , 0 , FS_END )
  92.  
  93. * Write the new text to the file
  94. IF lTimeStamp
  95.     FWRITE( nHandle , DTOC( DATE() ) + "," + TIME() + "," + cText + K_CRLF )
  96. ELSE
  97.     FWRITE( nHandle , cText + K_CRLF )
  98. ENDIF
  99.  
  100. * Close the file
  101. FCLOSE( nHandle )
  102.  
  103. RETURN NIL
  104. *
  105.