home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
epmsmp.zip
/
LOGERROR.E
< prev
next >
Wrap
Text File
|
1996-02-27
|
4KB
|
96 lines
; This file provides some sample routines for logging data by appending it
; to a disk file. Much more efficient than loading the file, adding stuff
; to the end, and saving it. The "guts" of this are 2 messages:
; EPM_EDIT_LOGERROR - writes a timestamp, followed by the data given,
; to the indicated file.
; EPM_EDIT_LOGAPPEND - writes the data given to the indicated file.
; Note that neither call adds a CR/LF to the data provided, and so are
; suitable for building a single line from multiple logging calls.
; Use EPM_EDIT_LOGERROR for the first part of the line and EPM_EDIT_LOGAPPEND
; for subsequent pieces, providing a CR/LF on the last call for that line,
; if a timestamp is desired, or all EPM_EDIT_LOGAPPEND calls if no timestamp
; is desired. (Note that EPM 6 writes a "neater" timestamp.)
; This works for both EPM 6 and (the outdated) EPM 5.51.
; Larry Margolis
compile if not defined(EPM32) -- Make sure the constants we need are defined.
include 'stdconst.e'
compile endif
const
compile if EPM32
EPM_EDIT_LOGERROR = 5495
EPM_EDIT_LOGAPPEND = 5496
compile else
EPM_EDIT_LOGERROR = 5452
EPM_EDIT_LOGAPPEND = 5453
compile endif
; Here are a few front-end procedures to make sending the EPM_EDIT_LOGxxxx
; messages a bit easier. LogError takes a message and optional filename
; and writes the message (prefixed with a timestamp) to the file, followed
; by ASCII CR/LF.
defproc logerror(errormsg)
if arg(2)='' then -- If no second argument is provided
logfile = 'epm.log'\0 -- default to epm.log as the log file
else -- otherwise
logfile = arg(2)\0 -- use the log file specified.
endif
errormsg = errormsg\r\n\0 -- Suffix the message with CR/LF/NUL
call windowmessage(1, getpminfo(EPMINFO_EDITFRAME),
EPM_EDIT_LOGERROR,
ltoa(offset(logfile) || selector(logfile), 10),
ltoa(offset(errormsg) || selector(errormsg), 10) )
; LogError2 is just like LogError, but it doesn't append the CR/LF.
defproc logerror2(errormsg)
if arg(2)='' then -- If no second argument is provided
logfile = 'epm.log'\0 -- default to epm.log as the log file
else -- otherwise
logfile = arg(2)\0 -- use the log file specified.
endif
errormsg = errormsg\0 -- Null-terminate the string.
call windowmessage(1, getpminfo(EPMINFO_EDITFRAME),
EPM_EDIT_LOGERROR,
ltoa(offset(logfile) || selector(logfile), 10),
ltoa(offset(errormsg) || selector(errormsg), 10) )
; LogAppend writes just the data provided; no timestamp, and no CR/LF.
defproc logappend(errormsg)
if arg(2)='' then -- If no second argument is provided
logfile = 'epm.log'\0 -- default to epm.log as the log file
else -- otherwise
logfile = arg(2)\0 -- use the log file specified.
endif
errormsg = errormsg\0 -- Null-terminate the string.
call windowmessage(1, getpminfo(EPMINFO_EDITFRAME),
EPM_EDIT_LOGAPPEND,
ltoa(offset(logfile) || selector(logfile), 10),
ltoa(offset(errormsg) || selector(errormsg), 10) )
; Here are a couple of example commands, both of which time-stamp the log.
; The first one takes whatever argument you provide and writes it to the
; log file:
defc try =
if arg(1) then
call logerror(arg(1))
else
sayerror 'Provide a string to be written to the log file, epm.log'
endif
; The second one provides an example of using multiple calls to write a
; single line.
defc try2 =
call logerror2('Error message from macros...')
call logappend(' ...in multiple calls...')
call logappend(' succeeded!!!'\r\n)