* support/regression/tests/wchar.c.in: bugfix
[sdcc.git] / sdcc-web / dbg.php
blobbae1774e2c84113bb53dcf05b6c6aedd6c0b08ab
1 <?php
2 /*-------------------------------------------------------------------------
3 dbg.php - Dbg class implementation
5 Copyright (C) 2012 Borut Razem <borut.razem AT gmail.com>
7 This program is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this library; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
20 MA 02110-1301, USA.
21 -------------------------------------------------------------------------*/
23 class Dbg {
24 private $debug;
25 private $fh;
26 private $begin_time;
28 private function d($s)
30 if (false) {
31 echo($s . "<br />\n");
35 public function __construct($fname = null, $do_append = false, $do_debug = true)
37 $this->d(__METHOD__);
39 if ($fname !== null) {
40 if ($do_append) {
41 $mode = 'a';
43 else {
44 $mode = 'w';
46 if (!($this->fh = fopen($fname, $mode))) {
47 echo('Can\'t create ' . $fname . "\n");
50 $this->debug = $do_debug;
52 $this->begin_time = time();
54 $this->dbg('--- Begin ' . date('Y-m-d H:i:s', $this->begin_time) . ' ---');
57 public function set_debug($val)
59 $this->d(__METHOD__);
61 $this->debug = $val;
64 public function dbg($s)
66 $this->d(__METHOD__);
68 if ($this->debug) {
69 if ($this->fh) {
70 fwrite($this->fh, $s . "\n");
72 else {
73 echo($s . "<br />\n");
78 public function dbg_r($s)
80 $this->d(__METHOD__);
82 if ($this->debug) {
83 if ($this->fh) {
84 fwrite($this->fh, print_r($s, true) . "\n");
86 else {
87 print_r($s);
88 echo("<br />\n");
93 public function __destruct()
95 $this->d(__METHOD__);
97 $end_time = time();
98 $this->dbg('--- End: ' . date('Y-m-d H:i:s', $end_time) .
99 ', Duration: ' . ($end_time - $this->begin_time) . 's ---');
101 if ($this->fh) {
102 fclose($this->fh);