Advertisement
jargon

SEQ File IO

Dec 17th, 2022
2,680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.     Declare Sub SEQ_DB_To_File( DB() as SEQ_Database, Filename as string )
  4.  
  5.     Declare Sub SEQ_DB_From_File( DB() as SEQ_Database, Filename as string )
  6.  
  7.     Declare Sub SEQ_DB_From_Raw( DB() AS SEQ_Database, Buffer As String )
  8.  
  9.     Declare Function SEQ_DB_To_Raw( DB() AS SEQ_Database ) As String
  10.  
  11.     Declare Sub SEQ_Raw_To_File( Buffer As String, Filename As String )
  12.  
  13.     Declare Function SEQ_Raw_From_File( Filename as string ) As String
  14.  
  15.     Sub SEQ_DB_To_File( DB() as SEQ_Database, Filename as string )
  16.  
  17.         Dim As String Buffer
  18.  
  19.         Buffer = ""
  20.  
  21.         Buffer = SEQ_DB_To_Raw( DB() )
  22.  
  23.         SEQ_Raw_To_File( Buffer, Filename )
  24.  
  25.     end sub
  26.  
  27.     Sub SEQ_DB_From_File( DB() as SEQ_Database, Filename as string )
  28.  
  29.         Dim As String Buffer
  30.  
  31.         Buffer = ""
  32.  
  33.         Buffer = SEQ_Raw_From_File( Filename )
  34.  
  35.         SEQ_DB_From_Raw( DB(), Buffer )
  36.  
  37.     end sub
  38.  
  39.     Sub SEQ_Raw_To_File( Buffer As String, Filename as string )
  40.  
  41.         if is_file(Filename) then
  42.  
  43.             kill Filename
  44.  
  45.         end if
  46.  
  47.         dim as long filemode = freefile
  48.  
  49.         if open(Filename for binary as #filemode) then
  50.  
  51.             close #filemode
  52.  
  53.             exit sub
  54.  
  55.         end if
  56.  
  57.         put #filemode, lof( filemode ) + 1, Buffer
  58.  
  59.         close #Filemode
  60.  
  61.     end sub
  62.  
  63.     Function SEQ_Raw_From_File( Filename as string ) As String
  64.  
  65.         dim as long filemode=freefile
  66.  
  67.         Dim As String Buffer
  68.        
  69.         Buffer = ""
  70.        
  71.         if is_file(Filename) then
  72.  
  73.             if open(Filename for binary as #filemode) then
  74.  
  75.                 close #filemode
  76.                
  77.                 Return Buffer
  78.  
  79.             end if
  80.  
  81.             Buffer = String( lof( filemode ), Chr(0) )
  82.  
  83.             If LOF( filemode ) > 0 Then
  84.  
  85.                 get #filemode, 1, Buffer
  86.  
  87.             End If
  88.  
  89.             close #filemode
  90.  
  91.         end if
  92.        
  93.         Return Buffer
  94.  
  95.     End Function
  96.  
  97.     Sub SEQ_DB_From_Raw( DB() AS SEQ_Database, Buffer As String )
  98.  
  99.         Dim As SEQ_Database Intermediary
  100.  
  101.         Dim As Long Iterator = 0
  102.            
  103.         Dim As String SEQ_LineBuffer, SEQ_ReserveBuffer
  104.        
  105.         SEQ_LineBuffer = ""
  106.        
  107.         SEQ_ReserveBuffer = Buffer
  108.        
  109.         Do While Len( SEQ_ReserveBuffer ) > 0
  110.            
  111.             SEQ_LineBuffer = Prefix( CRLF, SEQ_ReserveBuffer )
  112.            
  113.             SEQ_ReserveBuffer = Suffix( CRLF, SEQ_ReserveBuffer )
  114.            
  115.             If Len( SEQ_LineBuffer ) = 0 Then Exit Do
  116.            
  117.             With Intermediary
  118.  
  119.                 .Label = Prefix( EQ, SEQ_LineBuffer )
  120.  
  121.                 .Value = Suffix( EQ, SEQ_LineBuffer )
  122.  
  123.                 .Iterator = -1
  124.  
  125.             End With
  126.  
  127.             If Len( Intermediary.Label ) > 0 And Len( Intermediary.Value ) > 0 Then
  128.  
  129.                 SEQ_Inc_Capacity( DB(), 1 )
  130.  
  131.                 Iterator = UBound( DB, 1 )
  132.  
  133.                 With DB( Iterator )
  134.  
  135.                     .Label = Intermediary.Label
  136.  
  137.                     .Value = Intermediary.Value
  138.  
  139.                     .Iterator = -1
  140.  
  141.                 End With
  142.  
  143.             End If
  144.  
  145.         Loop
  146.  
  147.         SEQ_Bubble_Sort( DB() )
  148.  
  149.     End Sub
  150.  
  151.     Function SEQ_DB_To_Raw( DB() AS SEQ_Database ) As String
  152.  
  153.         SEQ_Bubble_Sort( DB() )
  154.  
  155.         Dim As String Buffer
  156.  
  157.         Buffer = ""
  158.  
  159.         If LBound( DB, 1 ) = 0 And UBound( DB, 1 ) = -1 Then
  160.  
  161.             Return Buffer
  162.  
  163.         End if
  164.  
  165.         For Iterator As Long = LBound( DB, 1 ) To UBound( DB, 1 ) Step 1
  166.  
  167.             With DB( Iterator )
  168.  
  169.                 IF Len( .Label ) > 0 and Len( .Value ) > 0 Then
  170.  
  171.                     Buffer = PackText ( Buffer, .Label & EQ & .Value )
  172.  
  173.                 End If
  174.  
  175.             End With
  176.  
  177.         Next Iterator
  178.  
  179.         Return Buffer
  180.  
  181.     End Function
  182.  
  183.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement