VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "File"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
''+-------------------------------------+
''| ICI style I/O PO file access module |
''+-------------------------------------+
''|     Made by Jure Sah of MesonAI     |
''+-------------------------------------+
''
''DO NOT MODIFY WITHOUT MY PREMITION!!!
''
''Mailto: jure.sah@guest.arnes.si
''
''Feel free to use this module in your
''programs and share it with your friends.
''
''
''You will probably need it if you are
''building apps for the ICI Console.

Public Sub xDeleteEntry(xFile As String)
On Error Resume Next
Randomize Timer
Dim Copy_now As Boolean, Already_got_an_entry As Boolean, xSwapFile As String

Copy_now = False
Already_got_an_entry = False
''Name a temporary file and make sure it doesn't already exist
2 inst = inst + 1
xSwapFile = xTemporaryPath + "\tmp" + Hex$(inst) + ".SWP"
If Dir(xSwapFile) <> "" Then GoTo 2

Open xFile For Input As #1
Open xSwapFile For Output As #2
Do
    Line Input #1, a$
    If Left$(a$, 3) = "---" Then
        If Already_got_an_entry Then Copy_now = True
        Already_got_an_entry = True
    End If
    ''When past the first entry, copy to swap file
    If Copy_now Then Print #2, a$
Loop Until EOF(1)
Close #1, #2
''Swap swap file with original
Kill xFile
Name xSwapFile As xFile
End Sub

Public Function xReadAll(xFile As String) As String
Open xFile For Input As #1
Do
Line Input #1, a$
b$ = b$ + a$ + vbCrLf
Loop Until EOF(1)
Close #1
xReadAll = b$
End Function

Public Function xReadEntry(xFile As String) As String
On Error Resume Next
Dim OK_to_quit  As Boolean, Already_got_an_entry As Boolean

OK_to_quit = False
Already_got_an_entry = False

Open xFile For Input As #1
Do
    Line Input #1, a$
    If Left$(a$, 3) = "---" Then
        If Already_got_an_entry Then OK_to_quit = True
        Already_got_an_entry = True
        Else
        xReadEntry = xReadEntry + a$ + vbCrLf
    End If
Loop Until EOF(1) Or OK_to_quit
Close #1
End Function

Public Sub xWriteEntry(xFile As String, xEntryText As String)
Open xFile For Append As #1
Print #1, "--- Entry " + Hex$(Timer * 100)
Print #1, xEntryText
Close #1
End Sub

Public Function xTrim(xS As String) As String
''Strip trailing CR and linefeed
If Right$(xS, 2) = vbCrLf Then xS = Mid$(xS, 1, Len(xS) - 2)
''Strip leading and trailing spaces
xTrim = Trim$(xS)
End Function
