[emt] r235 committed - Changing the parse_dir() function to be able to take an...

0 views
Skip to first unread message

e...@googlecode.com

unread,
Mar 23, 2012, 7:31:04 PM3/23/12
to emt...@googlegroups.com
Revision: 235
Author: kwayman
Date: Fri Mar 23 16:30:01 2012
Log: Changing the parse_dir() function to be able to take an
extra_config_dir parameter with multiple directories.
The directories are colon delimeted.
E.g. /tivo/etc/emt.d:/home/tivo/etc/emt.d

http://code.google.com/p/emt/source/detail?r=235

Modified:
/trunk/base/config_file.php

=======================================
--- /trunk/base/config_file.php Mon Feb 6 13:38:39 2012
+++ /trunk/base/config_file.php Fri Mar 23 16:30:01 2012
@@ -27,16 +27,17 @@
$config = array();
$module_instances = array();

-
-function parse_dir($extra_config_dir = "/etc/emt.d/")
-{
- if (is_dir($extra_config_dir))
- {
- if ($dir = opendir($extra_config_dir))
- {
- while (($file = readdir($dir)) !== FALSE)
- {
- parse_single_config_file($extra_config_dir . '/' . $file);
+function parse_dir($extra_config_path = "/etc/emt.d")
+{
+ foreach (preg_split("/:/", $extra_config_path) as $config_dir) {
+ if (is_dir($config_dir))
+ {
+ if ($dir = opendir($config_dir))
+ {
+ while (($file = readdir($dir)) !== FALSE)
+ {
+ parse_single_config_file($config_dir . '/' . $file);
+ }
}
}
}
@@ -54,25 +55,25 @@
{
if (!trim($line) || preg_match('/^\s*#/', $line))
continue;
-
+
$line = trim($line);
-
+
//trim single line comments
$line = preg_replace('/#.*/', '', $line);
-
+
//parse out heading
if (preg_match('/^\s*\[(.*)\]/', $line, $matches))
{
$cur_heading = $matches[1];
-
+
if (isset($config[$cur_heading]) &&
$cur_heading != 'emt_gather')
{
$error = "Duplicate heading $cur_heading in config file.";
break;
}
-
-
- //The heading supports multiple instances. Colon denotes a
instance identifier
+
+
+ //The heading supports multiple instances. Colon denotes a
instance identifier
if (strstr($cur_heading, ':'))
{
list($module_name, $instance_name) = preg_split('/:/',
$cur_heading);
@@ -95,26 +96,26 @@

continue;
}
-
+
//key = value option
if (preg_match('/=/', $line))
{
$matches = preg_split('/=/', $line);
-
+
if (count($matches) > 2)
{
$error = "Invalid configuration value ($line) under
heading ($cur_heading)";
break;
}
-
+
$key = trim($matches[0]);
$value = trim($matches[1]);
-
+
if (isset($config[$cur_heading][$key]))
{
if (!is_array($config[$cur_heading][$key]))
$config[$cur_heading][$key] =
array($config[$cur_heading][$key]);
-
+
$config[$cur_heading][$key][] = $value;
}
else

Reply all
Reply to author
Forward
0 new messages