
'---------------------
'exo2 o2 compiler maker
'=====================

'Charles Pegge
'21 June 2010
'18:22 27/06/2011
'12:24 04/04/2013
'11:31 21/09/2014
'11:19 02/03/2017
'18:20 26/08/2018
'10:54 02/06/2019



  #include "xo2.inc"
  '
  '
  'ATTEMPT TO GET FILE
  '===================
  '
  open s for binary access read as 2
  le=lof(2)
  t=string(le,chr(0))
  get #2,,t
  close 2
  '
  if t="" then
    pri "error 3: file empty or not found: "+s
    goto finish
  end if
  '
  u=""
  '
  if swc then
    'if bfname="" then
      bfname=mnm+".exe"
    'end if
    select case swc
    case &h63     : cf="uses RTL32"
    case &h33     : cf="uses RTL32"
    case &h36     : cf="uses RTL64"
    end select
    u+="$filename "+qu+bfname+qu+cr+cf+cr
  endif
  '  
  '
  if len(u) then
    t=u+"uses "+s+cr
  endif
  '
  p=strptr(t)
  '
  '
  '
  'NORMAL COMPILE
  '==============


  o2_mode(0) 'read/return null terminated ascii strings
  '
  select case swa
  case &h61   : prs = *o2_prep(p)  '-a
  case &h69   : prs = *o2_abst(p)  '-i
  case &h62   : prs = *o2_view(p)  '-b
  case else   :        o2_basic(p) 'compile string
  end select
  '
  er=o2_error()
  '
  if len(*er) then
    pri cr+ *er
    goto finish
  else
    if swc=0 then
      o2_exec(0)
    else
      pri cr+"Okay"
    end if
    goto finish
  end if

  finish:
  '------

  dim as sys ho,lew
  if len(prs) then
    if swm=0 then
      messagebox 0,prs,"o2",0
    else
      ho=GetStdHandle( STD_OUTPUT_HANDLE ) 'do this before AttachConsole
      AttachConsole(-1) 'attach to console of parent process
      WriteConsole( ho, prs, len(prs)+1, varptr(lew), 0 )
    end if
  end if

