; --------------------------------------------------------------------------------------
;
; This source file is part of PureBasic
; For the latest info, see http://www.purebasic.com/
; 
; Copyright (c) 1998-2006 Fantaisie Software
;
; This program is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version 2
; of the License, or (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
;
; --------------------------------------------------------------------------------------
;
; PB IDE Common functions.

Statement SendMessage{ID.l}
  SHARED  EditorMessage, *CompilerPort, *EditorPort

  EditorMessage\mn_Length = ID

  CNIF #LoadCompiler
    PutMsg_   *CompilerPort, &EditorMessage
    WaitPort_ *EditorPort
    GetMsg_   *EditorPort
  CEND
End Statement
;----------------------------------------------------

Function.l WaitForMessage{}
  SHARED  *EditorPort
  CNIF #LoadCompiler
    WaitPort_ *EditorPort
    Function Return GetMsg_(*EditorPort)
  CEND
End Function

;---------------------------------------------------------------------------
Statement CutPath{FileName.s}
  SHARED  PathPart.s, FilePart.s

  c.s = FileName
  *P.l=PathPart_(&FileName)
  If *P
    Poke.b *P,0
    PathPart.s = Peek.s(&FileName)
    *P = FilePart_(&c)
    FilePart.s = Peek.s(*P)
  Else
    PathPart.s = ""
    FilePart.s = ""
  EndIf

End Statement


;---------------------------------------------------------------------------
Function.w MessageBox{Title.s, Text.s, a.l, N.s}
  SHARED  *MainWin

  DEFTYPE .EasyStruct IDE_MBox

  IDE_MBox\es_StructSize   = SizeOf .EasyStruct
  IDE_MBox\es_Flags        = 0
  IDE_MBox\es_Title        = &Title
  IDE_MBox\es_TextFormat   = &Text
  IDE_MBox\es_GadgetFormat = &N

  a = EasyRequestArgs_(*MainWin, &IDE_MBox, 0, 0)

  Function Return a
End Function

;---------------------------------------------------------------------------
Function.l NRun{Command.s, Stack.l}
  SHARED   *TagList

  NResetTagList #SYS_Asynch  , 1
        NAddTag #SYS_Input   , 0
        NAddTag #SYS_Output  , 0
        NAddTag #NP_Error    , 0
        NAddTag #NP_StackSize, Stack
  Error.l = SystemTagList_(&Command, *TagList)

  Function Return Error
End Function


;---------------------------------------------------------------------------

Function.s PeekNL{mem.l}
 fr.s=""
 memlen.l=0
 If mem
  Runerrsoff
  GetReg a0,mem
  MOVEQ #0,d0
  MOVEA.l a0,a1
peeknl_loop:
  MOVE.b (a0)+,d0
  BEQ.s end_peeknl
  CMP.b #10,d0
  BNE.s peeknl_loop
end_peeknl:
  SUBA.l a1,a0
  MOVE.l a0,d0
  SUBQ.l #1,d0
  memlen=PutD0

  Runerrson
  !DPrint{5,"Strlen>"+Str$(memlen)}
  If memlen>0
    fr.s=PeekS(mem,memlen)
  EndIf

 Else
  !DPrint{1, "PeekNL: given null pointer!"}
 EndIf
 Function Return fr
End Function

