; ---------------------------------------------------------------------------
; export_itm_csv.cmm
; ---------------------------------------------------------------------------
  PMACRO.EXPLICIT

  ; show path and name of this script (present practice file)
  ECHO ""
  ECHO %COLOR.BLUE "### " OS.PPF() " ###"

  PRIVATE &file_user_export &file_export &appdata

; ---------------------------------------------------------------------------
; read default path and name of export file
  &appdata=OS.ENV("APPDATA")
  &file_user_export="&appdata\TRACE32\user-export.txt"

  GOSUB File_Read "&file_user_export"
  RETURNVALUES &file_export

  IF "&file_export"==""
  (
    &file_export="~~/trace.csv"
  )

; ---------------------------------------------------------------------------
; select path and name of export file
  DIALOG.File.SELECT "&file_export"
  ENTRY %LINE &file_export

; ---------------------------------------------------------------------------
; save selected export file as default
  GOSUB File_Write "&file_user_export" "&file_export"

; ---------------------------------------------------------------------------
; export trace data
  PRinTer.EXPORT.CSV "&file_export"
  WinPrint.Trace.List %LEN 70 %TimeFixed Time.Ref Time.Zero DEFault /Track

  ENDDO


; ---------------------------------------------------------------------------
;
File_Read:
(
  PRIVATE &fread &inputline
  PARAMETERS &fread

  &inputline=""
  IF FILE.EXIST("&fread")
  (
    OPEN #1 "&fread" /Read
    READ #1 %LINE &inputline
    CLOSE #1
  )
  RETURN "&inputline"
)

; ---------------------------------------------------------------------------
;
File_Write:
(
  PARAMETERS &fwrite &outputline

  IF "&outputline"!=""
  (
    OPEN #2 "&fwrite" /Write /Create
    WRITE #2 "&outputline"
    CLOSE #2
  )
  RETURN
)
