| 1 |
<html> |
| 2 |
<head> |
| 3 |
<title>AMB library</title> |
| 4 |
<meta name="author" content="Mateusz Viste"> |
| 5 |
<meta name="robots" content="index, follow"> |
| 6 |
<meta charset="UTF-8"> |
| 7 |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
| 8 |
<link rel="stylesheet" href="style.css"> |
| 9 |
</head> |
| 10 |
|
| 11 |
<body> |
| 12 |
|
| 13 |
<h1>AMB library</h1> |
| 14 |
<p class="copyr">a selection of free/gratis AMB books</p> |
| 15 |
|
| 16 |
<?php |
| 17 |
|
| 18 |
function getamafile($ambfname, $amafname) { |
| 19 |
if (! is_file($ambfname)) return(FALSE); |
| 20 |
$fd = fopen($ambfname, "rb"); |
| 21 |
if ($fd === FALSE) return(FALSE); |
| 22 |
// read header (AMB1) |
| 23 |
if (fread($fd, 4) !== 'AMB1') return(FALSE); |
| 24 |
// read number of ama files inside |
| 25 |
$fcount = reset(unpack('v', fread($fd, 2))); |
| 26 |
if ($fcount === FALSE) return(FALSE); |
| 27 |
// read index until AMA file is found |
| 28 |
$offset = 0; |
| 29 |
$amalen = 0; |
| 30 |
$amafile = ''; |
| 31 |
for ($i = 0; $i < $fcount; $i++) { |
| 32 |
$amafile = rtrim(fread($fd, 12), "\0"); |
| 33 |
$offset = reset(unpack('V', fread($fd, 4))); |
| 34 |
$amalen = reset(unpack('v', fread($fd, 2))); |
| 35 |
$bsum = reset(unpack('v', fread($fd, 2))); |
| 36 |
if (strcasecmp($amafile, $amafname) == 0) break; |
| 37 |
} |
| 38 |
if ($i >= $fcount) return(FALSE); // not found |
| 39 |
// jump to offset and read file |
| 40 |
fseek($fd, $offset); |
| 41 |
$result = fread($fd, $amalen); |
| 42 |
fclose($fd); |
| 43 |
return($result); |
| 44 |
} |
| 45 |
|
| 46 |
function codepageprocess($s) { |
| 47 |
$res = ''; |
| 48 |
$ss = str_split($s); |
| 49 |
foreach ($ss as $c) { |
| 50 |
if (ord($c) < 128) { |
| 51 |
$res .= $c; |
| 52 |
} else if (ord($c) == 158) { |
| 53 |
$res .= '��'; |
| 54 |
} else { |
| 55 |
$res .= '[' . ord($c) . ']'; |
| 56 |
} |
| 57 |
} |
| 58 |
return($res); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
$flist = glob("lib/*.amb"); |
| 63 |
|
| 64 |
?> |
| 65 |
|
| 66 |
<table> |
| 67 |
|
| 68 |
<?php |
| 69 |
foreach ($flist as $f) { |
| 70 |
$title = trim(getamafile($f, 'title')); |
| 71 |
if ($title === FALSE) $title = basename($f, '.amb'); |
| 72 |
$title = codepageprocess($title); |
| 73 |
echo "<tr><td>{$title}</td><td style=\"text-align: right;\"><a href=\"{$f}\">download</a> or <a href=\"phpamb.php?fname={$f}\">read online</a></td></tr>\n"; |
| 74 |
} |
| 75 |
|
| 76 |
?> |
| 77 |
|
| 78 |
</table> |
| 79 |
|
| 80 |
<p><< <a href="..">Back to the home page</a></p> |
| 81 |
|
| 82 |
</body> |
| 83 |
</html> |