Browse Source

Various minor commenting / indenting / reordering changes in the zoo.

- removed obsolete autoloader and get_temp_dir() functions
- indenting/bracing style mostly PSR1-style.
Frederic G. MARAND 12 years ago
parent
commit
cbc433477a
3 changed files with 79 additions and 108 deletions
  1. 14 22
      misc/boxed_scalars.php
  2. 35 46
      misc/misc.php
  3. 30 40
      misc/u_date_code.php

+ 14 - 22
misc/boxed_scalars.php

@@ -1,17 +1,10 @@
 <?php
 /**
  *
- * Boxed scalar values, usable with classes implementing Comparable_Interface
- * based on an OSInet Finite_State_Machine (fsm).
- *
- * This version relies on OSInet FSM >= 1.6
+ * Boxed scalar values, usable with classes implementing Comparable_Interface.
  *
  * @copyright  (c) 2007 OSI
  * @license    Licensed under the CeCILL 2.0
- * @version    CVS: $Id: boxed_scalars.php,v 1.3 2007-06-10 19:39:54 marand Exp $
- * @link       http://wiki.audean.com/fsm/fsm
- * @since      Not applicable yet
- * @package    default
  */
 
 
@@ -19,27 +12,26 @@
  * This class enables use of scalar values with classes implementing Comparable_Interface
  * @package default
  */
-class boxed_int implements Comparable_Interface
-  {
+class boxed_int implements Comparable_Interface {
   protected $value;
 
-  function __construct($n)
-    {
+  function __construct($n) {
     $this->value = $n;
-    }
+  }
 
-  function cmp(Comparable_Interface $other)
-    {
-    if ($this->value < $other->value)
+  function cmp(Comparable_Interface $other) {
+    if ($this->value < $other->value) {
       return -1;
-    elseif ($this->value > $other->value)
+    }
+    elseif ($this->value > $other->value) {
       return 1;
-    else
+    }
+    else {
       return 0;
     }
+  }
 
-  function as_int()
-    {
+  function as_int() {
     return $this->value;
-    }
-  }
+  }
+}

+ 35 - 46
misc/misc.php

@@ -1,89 +1,78 @@
 <?php
 /**
- * The Zoo
+ * The OSInet Zoo.
+ *
+ * Miscellaneous functions of dubious value, mostly used in PHP-GTK code < 2008.
+ *
+ * WARNING: including this files turns on output buffering. Useful in PHP-GTK
+ * apps, possibly troublesome elsewhere.
  *
  * @copyright  (c) 2007 OSI
  * @author     Frédéric G. MARAND
  * @license    Licensed under the CeCILL 2.0
- * @version    CVS: $Id: misc.php,v 1.4 2007-06-10 19:39:54 marand Exp $
  * @link       http://drupal.org/project/offload
- * @since      Not applicable yet
- * @package    default
  */
 
 /**
- * Interface used by function providing non-standard comparisons
- * @package default
+ * Interface used by function providing non-standard comparisons.
  */
-interface Comparable_Interface
-  {
+interface Comparable_Interface {
   /**
    * Compare the current instance
    *
    * @param Comparable_Interface $other
+   *
    * @return int
    */
   public function cmp(Comparable_Interface $other);
-  }
+}
 
-function _debug($msg)
-  {
+/**
+ * Echo message depending on global $_debug_active value.
+ *
+ * @param mixed $msg
+ */
+function _debug($msg) {
   global $_debug_active ;
 
   if ($_debug_active)
     echo $msg;
-  }
-
-/**
- * Old school autoloader.
- */
-/*
-function __autoload($name)
-  {
-  _debug("Autoloading $name\n");
-  require_once("$name.php");
-  }
-*/
-
-function get_temp_dir()
-  {
-  return 'e:/src/OsinetOffice/tmp';
-  }
+}
 
 /**
+ * Convert encoding to IBM850 for PHP-GTK apps on Windows.
+ *
  * @link http://blog.riff.org/2006_11_19_console_encoding_in_php_gtk_apps
  *
  * @param string $s
+ *
  * @return string
  */
-function output_encoder($s)
-  {
+function output_encoder($s) {
   return iconv('UTF-8', 'IBM850', $s);
-  }
-
-// Activate the OB handler:
-ob_start("output_encoder", 2);
+}
 
 /**
- * automatically find the glade file for a class file
- *
+ * Automatically find the glade file for a PHP-GTK class file.
  */
-function load_glade()
-  {
-  return new GladeXML(basename($_SERVER['PHP_SELF'], 'php') . 'glade');
-  }
+function load_glade() {
+  return new GladeXML(basename(__FILE__, 'php') . 'glade');
+}
 
 /**
- * returns the name of the invoking function/method
- * if it's a method, it is prefixed by the class name
+ * Returns the name of the invoking function/method. If it's a method, it is
+ * prefixed by the class name.
  *
  * @return string
  */
-function func_name($level = 1)
-  {
+function func_name($level = 1) {
   $trace = debug_backtrace();
   $func = $trace[$level]['function'];
-  if (isset($trace[$level]['class']))
+  if (isset($trace[$level]['class'])) {
     $func = $trace[$level]['class'] . '::' . $func;
+  }
   return $func;
-  }
+}
+
+// Activate the OB handler:
+ob_start("output_encoder", 2);

+ 30 - 40
misc/u_date_code.php

@@ -1,39 +1,30 @@
 <?php
 /**
- * Handle standard OSInet date code strings, uppercase
- * format: [y]ymdd
+ * Handle standard OSInet date code strings, uppercase format: [y]ymdd
+ *
  * 4-characters until 2009-12-31, 5 afterwards
  *
  * @copyright  (c) 2007 OSI
  * @author     Frédéric G. MARAND
  * @license    Licensed under the CeCILL 2.0
- * @version    CVS: $Id: u_date_code.php,v 1.5 2007-06-10 19:39:54 marand Exp $
- * @link
- * @since      Not applicable yet
- * @package    default
  */
 
 /**
- * needed to sign-compare ints
+ * Needed to sign-compare ints
  */
 require_once('boxed_scalars.php');
 
 /**
  * OSInet-format date codes like 07F09 to 2007-06-09
- *
- * @package default
- *
  */
-class osinet_date_code implements Comparable_Interface
-  {
+class osinet_date_code implements Comparable_Interface {
   private $f_value;
 
   /**
    * Implements Comparable_Interface restrictively, only comparing to other osinet_date_code objects, not to any other class implementing Comparable_Interface
    * @return int
    */
-  public function cmp(Comparable_Interface $other)
-    {
+  public function cmp(Comparable_Interface $other) {
     if (!($other instanceof osinet_date_code))
       throw new Exception('osinet_date_code only compares to other osinet_date_code objects');
 
@@ -69,31 +60,29 @@ class osinet_date_code implements Comparable_Interface
    * @param string $date_code
    * @return array ['mday', 'mon', 'year']
    */
-  public function to_mkdate()
-    {
+  public function to_mkdate() {
     $date_code = strtoupper($this->f_value);
     $matches = array();
     preg_match('/^([0-9]*)([A-Z])([0-9]?.*$)/', $date_code, $matches);
-    if (count($matches) <> 4)
-      {
+    if (count($matches) <> 4) {
       throw new Exception("Incorrect date code $date_code");
-      }
+    }
     $ret = array(
       'mday' => $matches[3],
       'mon'  => ord($matches[2]) - ord('@'),
       'year' => 2000 + $matches[1],
-      );
+    );
     return $ret;
-    }
+  }
 
   /**
    * @param int $time
    */
-  public function __construct($time = null)
-    {
+  public function __construct($time = null) {
     date_default_timezone_set('Europe/Paris');
-    if (!$time)
+    if (!$time) {
       $time = time();
+    }
     $date = getdate();
     $day   = $date['mday'];
     $month = $date['mon'];
@@ -102,47 +91,48 @@ class osinet_date_code implements Comparable_Interface
     $month = chr(ord('@') + $month);
 
     $this->f_value = sprintf('%d%s%02d', $year, $month, $day);
-    }
+  }
 
   /**
    * @param string $date_code
    */
-  private function set_value($date_code)
-    {
+  private function set_value($date_code) {
     $date_code = strtoupper($date_code);
     $matches = array();
     preg_match('/^([0-9]*)([A-Z])([0-9]?.*$)/', $date_code, $matches);
-    if (count($matches) <> 4)
-      {
+    if (count($matches) <> 4) {
       throw new Exception("Incorrect date code $date_code");
-      }
-    else
+    }
+    else {
       $this->f_value = $date_code;
     }
+  }
 
   /**
    * @param string $nm
+   *
    * @return mixed
    */
-  protected function __get($nm)
-    {
+  protected function __get($nm) {
     // echo "osinet_date_code::__get($nm)\n";
-    if ($nm <> 'value')
+    if ($nm <> 'value') {
       throw new Exception("$nm: undefined property for " . get_class($this));
+    }
 
     return $this->f_value;
-    }
+  }
 
   /**
    * @param string $nm
    * @param mixed $val
+   *
    * @return void
    */
- protected function __set($nm, $val)
-    {
-    if ($nm <> 'value')
+ protected function __set($nm, $val) {
+    if ($nm <> 'value') {
       throw new Exception("$nm: undefined property for " . get_class($this));
+    }
 
     $this->set_value($val);
-    }
-  }
+  }
+}