Skip to content

Commit

Permalink
the bas_ext() method is now auto-generated
Browse files Browse the repository at this point in the history
from <storage><fileextension> tags


git-svn-id: http://svn.php.net/repository/pear/packages/CodeGen_MySQL_Plugin/trunk@235008 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Hartmut Holzgraefe committed May 5, 2007
1 parent 2958171 commit bc7be68
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
33 changes: 29 additions & 4 deletions MySQL/Plugin/Element/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ function __construct()
protected $functions = array();


protected $requiredFunctions = array("bas_ext",
"open",
protected $requiredFunctions = array("open",
"close",
"rnd_init",
"rnd_next",
Expand All @@ -72,6 +71,24 @@ function __construct()
"store_lock"
);

protected $fileExtensions = array();

function addFileExtension($param)
{
// TODO check valid fs name chars

$ext = strtoupper($param);
if ($ext{0} !== '.') {
$ext = '.' . $ext;
}

if (isset($this->fileExtensions[$ext])) {
return PEAR::raiseError("file extension '$ext' ($param) already defined");
}

$this->fileExtensions[$ext] = $ext;
}

/**
* Handler flags
*
Expand Down Expand Up @@ -236,6 +253,16 @@ function getPluginCode()
$code.= $function["head"].$function["body"]."}\n\n";
}

$code.= "static const char *ha_{$lowname}_exts[] = {\n";
foreach ($this->fileExtensions as $fileExtension) {
$code.= ' "'.$fileExtension.'",'."\n";
}
$code.= " NullS\n};\n\n";
$code.= "const char **ha_{$lowname}::bas_ext() const\n";
$code.= "{\n";
$code.= " return ha_{$lowname}_exts;\n";
$code.= "}\n";

$code.= parent::getPluginCode()."\n";

$code.= "struct st_mysql_storage_engine {$lowname}_descriptor=\n";
Expand Down Expand Up @@ -297,8 +324,6 @@ function getFunctionHead($name)
$classname = "ha_".strtolower($name);

switch ($name) {
case "bas_ext":
return "const char **{$classname}::bas_ext() const\n{\n";
case "open":
return "int {$classname}::open(const char *name, int mode, uint test_if_locked)\n{\n";
case "close":
Expand Down
10 changes: 10 additions & 0 deletions MySQL/Plugin/ExtensionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,16 @@ function tagend_storage_function($attr, $data)
$this->helper->setFunction($attr["name"], $data);
}

function tagstart_storage_fileextension($attr, $data)
{
$err = $this->checkAttributes($attr, array(), array("name"));
if (PEAR::isError($err)) {
return $err;
}

$this->helper->addFileExtension($attr["name"]);
}

// ___ __ ____ _
// |_ _|_ __ / _| ___ / ___| ___| |__ ___ _ __ ___ __ _
// | || '_ \| |_ / _ \ \___ \ / __| '_ \ / _ \ '_ ` _ \ / _` |
Expand Down

0 comments on commit bc7be68

Please sign in to comment.