home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / LOGERROR.E < prev    next >
Text File  |  1996-02-27  |  4KB  |  96 lines

  1. ; This file provides some sample routines for logging data by appending it
  2. ; to a disk file.  Much more efficient than loading the file, adding stuff
  3. ; to the end, and saving it.  The "guts" of this are 2 messages:
  4. ; EPM_EDIT_LOGERROR - writes a timestamp, followed by the data given,
  5. ;                     to the indicated file.
  6. ; EPM_EDIT_LOGAPPEND - writes the data given to the indicated file.
  7.  
  8. ; Note that neither call adds a CR/LF to the data provided, and so are
  9. ; suitable for building a single line from multiple logging calls.
  10. ; Use EPM_EDIT_LOGERROR for the first part of the line and EPM_EDIT_LOGAPPEND
  11. ; for subsequent pieces, providing a CR/LF on the last call for that line,
  12. ; if a timestamp is desired, or all EPM_EDIT_LOGAPPEND calls if no timestamp
  13. ; is desired.  (Note that EPM 6 writes a "neater" timestamp.)
  14.  
  15. ; This works for both EPM 6 and (the outdated) EPM 5.51.
  16. ;                           Larry Margolis
  17.  
  18. compile if not defined(EPM32)  -- Make sure the constants we need are defined.
  19. include 'stdconst.e'
  20. compile endif
  21.  
  22. const
  23. compile if EPM32
  24.    EPM_EDIT_LOGERROR  = 5495
  25.    EPM_EDIT_LOGAPPEND = 5496
  26. compile else
  27.    EPM_EDIT_LOGERROR  = 5452
  28.    EPM_EDIT_LOGAPPEND = 5453
  29. compile endif
  30.  
  31. ; Here are a few front-end procedures to make sending the EPM_EDIT_LOGxxxx
  32. ; messages a bit easier.  LogError takes a message and optional filename
  33. ; and writes the message (prefixed with a timestamp) to the file, followed
  34. ; by ASCII CR/LF.
  35.  
  36. defproc logerror(errormsg)
  37.    if arg(2)='' then                -- If no second argument is provided
  38.       logfile = 'epm.log'\0         -- default to epm.log as the log file
  39.    else                             -- otherwise
  40.       logfile = arg(2)\0            -- use the log file specified.
  41.    endif
  42.    errormsg = errormsg\r\n\0        -- Suffix the message with CR/LF/NUL
  43.    call windowmessage(1,  getpminfo(EPMINFO_EDITFRAME),
  44.                       EPM_EDIT_LOGERROR,
  45.                       ltoa(offset(logfile) || selector(logfile), 10),
  46.                       ltoa(offset(errormsg) || selector(errormsg), 10) )
  47.  
  48. ; LogError2 is just like LogError, but it doesn't append the CR/LF.
  49.  
  50. defproc logerror2(errormsg)
  51.    if arg(2)='' then                -- If no second argument is provided
  52.       logfile = 'epm.log'\0         -- default to epm.log as the log file
  53.    else                             -- otherwise
  54.       logfile = arg(2)\0            -- use the log file specified.
  55.    endif
  56.    errormsg = errormsg\0            -- Null-terminate the string.
  57.    call windowmessage(1,  getpminfo(EPMINFO_EDITFRAME),
  58.                       EPM_EDIT_LOGERROR,
  59.                       ltoa(offset(logfile) || selector(logfile), 10),
  60.                       ltoa(offset(errormsg) || selector(errormsg), 10) )
  61.  
  62. ; LogAppend writes just the data provided; no timestamp, and no CR/LF.
  63.  
  64. defproc logappend(errormsg)
  65.    if arg(2)='' then                -- If no second argument is provided
  66.       logfile = 'epm.log'\0         -- default to epm.log as the log file
  67.    else                             -- otherwise
  68.       logfile = arg(2)\0            -- use the log file specified.
  69.    endif
  70.    errormsg = errormsg\0            -- Null-terminate the string.
  71.    call windowmessage(1,  getpminfo(EPMINFO_EDITFRAME),
  72.                       EPM_EDIT_LOGAPPEND,
  73.                       ltoa(offset(logfile) || selector(logfile), 10),
  74.                       ltoa(offset(errormsg) || selector(errormsg), 10) )
  75.  
  76. ; Here are a couple of example commands, both of which time-stamp the log.
  77.  
  78. ; The first one takes whatever argument you provide and writes it to the
  79. ; log file:
  80.  
  81. defc try =
  82.    if arg(1) then
  83.       call logerror(arg(1))
  84.    else
  85.       sayerror 'Provide a string to be written to the log file, epm.log'
  86.    endif
  87.  
  88. ; The second one provides an example of using multiple calls to write a
  89. ; single line.
  90.  
  91. defc try2 =
  92.    call logerror2('Error message from macros...')
  93.    call logappend(' ...in multiple calls...')
  94.    call logappend(' succeeded!!!'\r\n)
  95.  
  96.