Changeset 880 for trunk/includes/dbc.php
- Timestamp:
- Apr 7, 2020, 10:15:48 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/dbc.php
r815 r880 35 35 36 36 $this->ColumnFormat = $ColumnFormat; 37 if ($this->ReadUint() != DBC_SIGNATURE) die(NOT_DBC_FILE);37 if ($this->ReadUint() != DBC_SIGNATURE) die(NOT_DBC_FILE); 38 38 39 39 $this->RecordCount = $this->ReadUint(); … … 43 43 44 44 $this->GenerateOffsetTable(); 45 if ($this->EndOffset != $this->RecordSize)45 if ($this->EndOffset != $this->RecordSize) 46 46 die(RECORD_SIZE_NOT_MATCH.$this->EndOffset.' <> '.$this->RecordSize); 47 47 } … … 71 71 { 72 72 // Preallocate array 73 if ($this->FieldCount > 0) $this->Offsets = array_fill(0, $this->FieldCount, 0);73 if ($this->FieldCount > 0) $this->Offsets = array_fill(0, $this->FieldCount, 0); 74 74 else $this->Offsets = array(); 75 75 76 76 $Offset = 0; 77 77 $I = 0; 78 while ($I < $this->FieldCount)78 while ($I < $this->FieldCount) 79 79 { 80 80 $this->Offsets[$I] = $Offset; 81 if (array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];81 if (array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I]; 82 82 else $Format = FORMAT_UINT32; 83 switch ($Format)83 switch ($Format) 84 84 { 85 85 case FORMAT_BYTE: … … 100 100 private function CellPos($Row, $Column) 101 101 { 102 return ($this->HeaderSize + $Row * $this->RecordSize + $this->Offsets[$Column]);102 return $this->HeaderSize + $Row * $this->RecordSize + $this->Offsets[$Column]; 103 103 } 104 104 … … 106 106 { 107 107 $this->SetPosition($this->CellPos($Row, $Column)); 108 return ($this->ReadByte());108 return $this->ReadByte(); 109 109 } 110 110 … … 112 112 { 113 113 $this->SetPosition($this->CellPos($Row, $Column)); 114 return ($this->ReadUint());114 return $this->ReadUint(); 115 115 } 116 116 … … 118 118 { 119 119 $this->SetPosition($this->CellPos($Row, $Column)); 120 return ($this->ReadInt());120 return $this->ReadInt(); 121 121 } 122 122 … … 124 124 { 125 125 $this->SetPosition($this->CellPos($Row, $Column)); 126 return ($this->ReadFloat());126 return $this->ReadFloat(); 127 127 } 128 128 … … 156 156 157 157 $Position = $this->HeaderSize + $this->RecordCount * $this->RecordSize + $Offset; 158 if ($Position >= $this->GetSize()) return('');158 if ($Position >= $this->GetSize()) return ''; 159 159 $this->SetPosition($Position); 160 160 161 161 $String = ''; 162 while (($Char = $this->ReadChar()) != "\0")162 while (($Char = $this->ReadChar()) != "\0") 163 163 { 164 164 $String .= $Char; 165 165 } 166 return ($String);166 return $String; 167 167 } 168 168 169 169 public function SetString($Row, $Column, $Value) 170 170 { 171 if (in_array($Value, $this->StringList))171 if (in_array($Value, $this->StringList)) 172 172 { 173 173 $this->SetUint($Row, $Column, $this->StringListOffset[array_search($Value, $this->StringList)]); … … 192 192 $this->SetPosition($this->HeaderSize + $this->RecordCount * $this->RecordSize); 193 193 $this->WriteByte(0); 194 foreach ($this->StringList as $Index => $Item)194 foreach ($this->StringList as $Index => $Item) 195 195 { 196 196 $this->WriteString($Item."\0"); … … 206 206 207 207 // Preallocate array 208 if ($this->FieldCount > 0) $Line = array_fill(0, $this->FieldCount, 0);208 if ($this->FieldCount > 0) $Line = array_fill(0, $this->FieldCount, 0); 209 209 else $Line = array(); 210 for ($I = 0; $I < $this->FieldCount; $I++)211 { 212 if (array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];210 for ($I = 0; $I < $this->FieldCount; $I++) 211 { 212 if (array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I]; 213 213 else $Format = FORMAT_UINT32; 214 214 $Record->SetPosition($this->Offsets[$I]); 215 switch ($Format)215 switch ($Format) 216 216 { 217 217 case FORMAT_BYTE: … … 231 231 232 232 $Position = $this->HeaderSize + $this->RecordCount * $this->RecordSize + $Offset; 233 if ($Position >= $this->GetSize()) $String = '';233 if ($Position >= $this->GetSize()) $String = ''; 234 234 else 235 235 { 236 236 $this->SetPosition($Position); 237 237 $String = ''; 238 while (($Char = $this->ReadChar()) != "\0")238 while (($Char = $this->ReadChar()) != "\0") 239 239 $String .= $Char; 240 240 } … … 245 245 } 246 246 } 247 return ($Line);247 return $Line; 248 248 } 249 249 … … 253 253 $Record = new MemoryStream(); 254 254 255 for ($I = 0; $I < $this->FieldCount; $I++)256 { 257 if (array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I];255 for ($I = 0; $I < $this->FieldCount; $I++) 256 { 257 if (array_key_exists($I, $this->ColumnFormat)) $Format = $this->ColumnFormat[$I]; 258 258 else $Format = FORMAT_UINT32; 259 259 $Record->SetPosition($this->Offsets[$I]); 260 switch ($Format)260 switch ($Format) 261 261 { 262 262 case FORMAT_BYTE: … … 273 273 break; 274 274 case FORMAT_STRING: 275 if (in_array($Line[$I], $this->StringList))275 if (in_array($Line[$I], $this->StringList)) 276 276 { 277 277 $Record->WriteUint($this->StringListOffset[array_search($Line[$I], $this->StringList)]); … … 291 291 $this->SetPosition($this->CellPos($Row, 0)); 292 292 $this->WriteBlock($Record->Data, $this->RecordSize); 293 return ($Line);293 return $Line; 294 294 } 295 295 296 296 public function GetRecordCount() 297 297 { 298 return ($this->RecordCount);298 return $this->RecordCount; 299 299 } 300 300 … … 306 306 public function GetFieldCount() 307 307 { 308 return ($this->FieldCount);308 return $this->FieldCount; 309 309 } 310 310
Note:
See TracChangeset
for help on using the changeset viewer.