/*
* PHP csv2cht encoder
* Copyright (C) 2005 emuWorks
* by John David Ratliff
* Licensed under the GNU GPL
* See http://www.gnu.org for more information
*/
/*
* Revision History
* 1.1 - Fixed bug in cht_encode routine
* Changed name padding from spaces to NUL characters
* 1.0 - Initial Public Release
*/
// the following two lines are not necessary if posting this
// script to another site. They are solely to frame the page within
// emuWorks layout
$page_title = "CSV 2 CHT Converter";
include ("../includes/header.inc");
function cht_encode($code, $name) {
$dec = hexdec($code);
$cht = "";
$cht .= chr(0);
$cht .= chr($dec & 0xFF);
$cht .= chr(($dec >> 8) & 0xFF);
$cht .= chr(($dec >> 16) & 0xFF);
$cht .= chr(($dec >> 24) & 0xFF);
$cht .= chr(0);
$cht .= chr(254);
$cht .= chr(252);
$cht .= $name;
$cht .= chr(0);
$cht .= chr(0);
return $cht;
}
?>
CSV 2 CHT Converter
Copyright © 2005 emuWorks
$action = $_POST['action'];
if ($action == "encode") {
$codes = $_POST['codes'];
$codes = preg_split("/\n/", $codes);
$count = count($codes);
$dark = true;
$txtdir = "/chtdecoder/php/txt/";
$wwwpath = $_SERVER['DOCUMENT_ROOT'] . $txtdir;
$filename = tempnam($wwwpath, "cht") . ".cht";
preg_match("/\/([A-Za-z0-9]*)\.cht\$/", $filename, $matches);
$chtpath = $txtdir . $matches[1] . ".cht";
$fd = fopen($filename, "wb");
?>
|
Name
|
Code
|
for ($i = 0; $i < $count; $i++) {
if (preg_match("/([A-Fa-f0-9]{1,6}),([A-Fa-f0-9]{1,2}),(.{1,18})/", $codes[$i], $match)) {
$code = str_pad($match[1], 6, "0", STR_PAD_LEFT) . str_pad($match[2], 2, "0", STR_PAD_LEFT);
$name = str_pad($match[3], 18, chr(0));
$chtdata = cht_encode($code, $name);
fwrite($fd, $chtdata);
if ($dark) {
$bgcolor = "#CDCDCD";
} else {
$bgcolor = "#DEDEDE";
}
$dark = !$dark;
?>
|
= $name; ?>
|
= $code; ?>
|
}
}
fclose($fd);
?>
|
Download .CHT File
|
}
?>
// this include is not necessary if this script is used on another
// website. It is solely to frame the page within emuWorks layout.
include ("../includes/footer.inc");
?>