cvs: embed /php-irssi php-irssi-obj.c /php-irssi/examples rotator.php sysinfo.php

From: Date: Wed, 17 Mar 2004 21:32:13 +0000
Subject: cvs: embed /php-irssi php-irssi-obj.c /php-irssi/examples rotator.php sysinfo.php
Groups: php.embed.cvs 
Request: Send a blank email to [email protected] to get a copy of this message
bs		Wed Mar 17 16:32:13 2004 EDT

  Modified files:              
    /embed/php-irssi	php-irssi-obj.c 
    /embed/php-irssi/examples	rotator.php sysinfo.php 
  Log:
  - made php-irssi compile again
  - fixed examples/rotator.php and examples/sysinfo.php
  
  


http://cvs.php.net/diff.php/embed/php-irssi/php-irssi-obj.c?r1=1.12&r2=1.13&ty=u Index: embed/php-irssi/php-irssi-obj.c diff -u embed/php-irssi/php-irssi-obj.c:1.12 embed/php-irssi/php-irssi-obj.c:1.13 --- embed/php-irssi/php-irssi-obj.c:1.12 Mon Jul 14 16:47:35 2003 +++ embed/php-irssi/php-irssi-obj.c Wed Mar 17 16:32:12 2004 @@ -14,7 +14,7 @@ +----------------------------------------------------------------------+ | Author: Wez Furlong <[email protected]> | +----------------------------------------------------------------------+ - $Id: php-irssi-obj.c,v 1.12 2003/07/14 20:47:35 wez Exp $ + $Id: php-irssi-obj.c,v 1.13 2004/03/17 21:32:12 bs Exp $ */ #include "php-irssi.h" #include "php-irssi-obj-defs.h" @@ -193,26 +193,27 @@ } #endif -zend_object_handlers php_irssi_handlers = { +static zend_object_handlers php_irssi_handlers = { ZEND_OBJECTS_STORE_HANDLERS, - - pih_read_prop, - pih_write_prop, - NULL, - NULL, - NULL, + pih_read_prop, /* prop read */ + pih_write_prop, /* prop write */ + NULL, /* read dim */ + NULL, /* write dim */ NULL, - NULL, - NULL, - pih_has_prop, - NULL, /* can't unset props */ - pih_get_properties, - pih_get_method, - NULL, - pih_get_ctor, - pih_get_class, - pih_get_class_name, - + NULL, /* get */ + NULL, /* set */ + pih_has_prop, /* has prop */ + NULL, /* unset prop (unable to) */ + NULL, /* has dim */ + NULL, /* unset dim */ + pih_get_properties, /* props get */ + pih_get_method, /* method get */ + NULL, /* call */ + pih_get_ctor, /* get ctor */ + pih_get_class, /* get_ce */ + pih_get_class_name, /* get class name */ + NULL, /* compare */ + NULL /* cast */ }; static void clone_object(struct php_irssi_obj_ref *object, struct php_irssi_obj_ref **object_clone TSRMLS_DC) @@ -255,7 +256,7 @@ } } - retval.handle = zend_objects_store_put(*ref, (zend_objects_store_dtor_t)destroy_object, (zend_objects_store_clone_t)clone_object TSRMLS_CC); + retval.handle = zend_objects_store_put(*ref, (zend_objects_store_dtor_t)destroy_object, NULL, (zend_objects_store_clone_t)clone_object TSRMLS_CC); retval.handlers = &php_irssi_handlers; if (zobj) { http://cvs.php.net/diff.php/embed/php-irssi/examples/rotator.php?r1=1.4&r2=1.5&ty=u Index: embed/php-irssi/examples/rotator.php diff -u embed/php-irssi/examples/rotator.php:1.4 embed/php-irssi/examples/rotator.php:1.5 --- embed/php-irssi/examples/rotator.php:1.4 Mon Jul 14 16:47:35 2003 +++ embed/php-irssi/examples/rotator.php Wed Mar 17 16:32:13 2004 @@ -1,5 +1,5 @@ <?php -/* $Id: rotator.php,v 1.4 2003/07/14 20:47:35 wez Exp $ +/* $Id: rotator.php,v 1.5 2004/03/17 21:32:13 bs Exp $ * Rotator displays a small statusbar item to show that irssi is still running. * * Usage: @@ -7,7 +7,8 @@ * /statusbar window add -align right php_rotator */ -class SampleRotator { +class sampleRotator +{ var $pos = 0; var $display = ''; var $width = 10; @@ -18,15 +19,14 @@ function scroll() { - $this->pos++; - if ($this->pos > strlen($this->charset)) { + if (++$this->pos > strlen($this->charset)) $this->pos = 0; - } + $this->display = substr($this->charset, $this->pos, $this->width); irssi_statusbar_items_redraw('php_rotator'); } - function draw_bar($item, $get_size_only) + function drawBar($item, $get_size_only) { $item->min_size = $this->width; $item->max_size = $this->width; @@ -35,16 +35,10 @@ function __construct() { - irssi_statusbar_item_register('php_rotator', '$0', array($this, 'draw_bar')); + irssi_statusbar_item_register('php_rotator', '$0', array($this, 'drawBar')); irssi_timeout_add($this->update_speed, array($this, 'scroll')); } } -function SampleRotator_init() -{ - new SampleRotator; -} - -SampleRotator_init(); - +new sampleRotator(); ?> http://cvs.php.net/diff.php/embed/php-irssi/examples/sysinfo.php?r1=1.1&r2=1.2&ty=u Index: embed/php-irssi/examples/sysinfo.php diff -u embed/php-irssi/examples/sysinfo.php:1.1 embed/php-irssi/examples/sysinfo.php:1.2 --- embed/php-irssi/examples/sysinfo.php:1.1 Thu Apr 3 15:31:43 2003 +++ embed/php-irssi/examples/sysinfo.php Wed Mar 17 16:32:13 2004 @@ -1,5 +1,5 @@ <?php -/* $Id: sysinfo.php,v 1.1 2003/04/03 20:31:43 bs Exp $ +/* $Id: sysinfo.php,v 1.2 2004/03/17 21:32:13 bs Exp $ * * loadavg * puts an item containing the systems loadaverage in the statusbar @@ -27,135 +27,131 @@ * /set netact_devices eth0(,eth1,..) * * Author: Benjamin Schulz <[email protected]> */ - -namespace samples { - class sysinfo { +class sampleSysinfo { - var $_loadavg_refresh = 10; - var $_loadavg_refresh_tag = false; - var $_netact_refresh = 60; - var $_netact_devices = array(); - var $_netact_refresh_tag = false; - - function __construct() - { - irssi_settings_add_str('loadavg', 'loadavg_refresh', $this->_loadavg_refresh); - irssi_settings_add_str('netact', 'netact_refresh', $this->_netact_refresh); - irssi_settings_add_str('netact', 'netact_devices', 'eth0'); - - $this->init_loadavg(); - $this->init_netact(); - - irssi_signal_add('setup changed', array($this, 'init_loadavg'), IRSSI_SIGNAL_PRIORITY_LOW); - irssi_signal_add('setup changed', array($this, 'init_netact'), IRSSI_SIGNAL_PRIORITY_LOW); - } - - function init_loadavg() - { - $refresh = irssi_settings_get_str('loadavg_refresh'); - - if (false !== $this->_loadavg_refresh_tag) - irssi_timeout_remove($this->_loadavg_refresh_tag); - - $this->_loadavg_refresh = $refresh; - $this->_loadavg_refresh_tag = irssi_timeout_add($refresh * 1000, array($this, 'refresh_loadavg') ); + var $_loadavg_refresh = 10; + var $_loadavg_refresh_tag = false; + var $_netact_refresh = 60; + var $_netact_devices = array(); + var $_netact_refresh_tag = false; + + function __construct() + { + irssi_settings_add_str('loadavg', 'loadavg_refresh', $this->_loadavg_refresh); + irssi_settings_add_str('netact', 'netact_refresh', $this->_netact_refresh); + irssi_settings_add_str('netact', 'netact_devices', 'eth0'); - irssi_statusbar_item_register('loadavg', '$0', array($this, 'draw_loadavg')); - } - - function _get_loadavg() - { - $str = @file_get_contents('/proc/loadavg'); - if ($str === false) - return 'unable to read /proc/loadavg'; - return trim($str); - } - - function refresh_loadavg() - { - irssi_statusbar_items_redraw('loadavg'); - } - - function draw_loadavg($item, $get_size_only) - { - $item->default_handler($get_size_only, '{sb Load: '.$this->_get_loadavg().'}', '', true); - return; - } - - - function init_netact() - { - $refresh = irssi_settings_get_str('netact_refresh'); - $devices = irssi_settings_get_str('netact_devices'); - - if (false !== $this->_netact_refresh_tag) - irssi_timeout_remove($this->_netact_refresh_tag); - - $this->_netact_refresh = $refresh; - $this->_netact_devices = explode(',',$devices); + $this->init_loadavg(); + $this->init_netact(); - $this->_netact_refresh_tag = irssi_timeout_add($refresh * 1000, array($this, 'refresh_netact') ); + irssi_signal_add('setup changed', array($this, 'init_loadavg'), IRSSI_SIGNAL_PRIORITY_LOW); + irssi_signal_add('setup changed', array($this, 'init_netact'), IRSSI_SIGNAL_PRIORITY_LOW); + } + + function init_loadavg() + { + $refresh = irssi_settings_get_str('loadavg_refresh'); + + if (false !== $this->_loadavg_refresh_tag) + irssi_timeout_remove($this->_loadavg_refresh_tag); + + $this->_loadavg_refresh = $refresh; + $this->_loadavg_refresh_tag = irssi_timeout_add($refresh * 1000, array($this, 'refresh_loadavg') ); - irssi_statusbar_item_register('netact', '$0', array($this, 'draw_netact')); - } - - function _get_netact() - { - $return = ''; - $results = array(); - - if (!$fd = @fopen('/proc/net/dev', 'r')) - return 'unable to read /proc/net/dev'; - - while ($buf = fgets($fd, 4096)) { - if (!preg_match('/:/', $buf)) - continue; - - list($dev, $stats_list) = preg_split('/:/', $buf, 2); - $dev = trim($dev); - if (!in_array($dev, $this->_netact_devices)) - continue; - $stats = preg_split('/\s+/', trim($stats_list)); - $results[] .= sprintf('%s: %s %s %s', - $dev, - $this->_format_bytes($stats[0] / 1024), // received - $this->_format_bytes($stats[8] / 1024), // sent - $this->_format_bytes($stats[2] + $stats[10]) // errors - - ); - } - - return implode(' ', $results); - } + irssi_statusbar_item_register('loadavg', '$0', array($this, 'draw_loadavg')); + } + + function _get_loadavg() + { + $str = @file_get_contents('/proc/loadavg'); + if ($str === false) + return 'unable to read /proc/loadavg'; + return trim($str); + } + + function refresh_loadavg() + { + irssi_statusbar_items_redraw('loadavg'); + } + + function draw_loadavg($item, $get_size_only) + { + $item->default_handler($get_size_only, '{sb Load: '.$this->_get_loadavg().'}', '', true); + return; + } + + + function init_netact() + { + $refresh = irssi_settings_get_str('netact_refresh'); + $devices = irssi_settings_get_str('netact_devices'); - function _format_bytes ($kbytes) { - $spacer = ' '; - if ($kbytes > 1048576) - $result = sprintf('%.2fG', $kbytes / 1048576); - elseif ($kbytes > 1024) - $result = sprintf('%.2fM', $kbytes / 1024); - else - $result = sprintf('%.2fK', $kbytes); + if (false !== $this->_netact_refresh_tag) + irssi_timeout_remove($this->_netact_refresh_tag); + + $this->_netact_refresh = $refresh; + $this->_netact_devices = explode(',',$devices); + + $this->_netact_refresh_tag = irssi_timeout_add($refresh * 1000, array($this, 'refresh_netact') ); - return $result; + irssi_statusbar_item_register('netact', '$0', array($this, 'draw_netact')); + } + + function _get_netact() + { + $return = ''; + $results = array(); + + if (!$fd = @fopen('/proc/net/dev', 'r')) + return 'unable to read /proc/net/dev'; + + while ($buf = fgets($fd, 4096)) { + if (!preg_match('/:/', $buf)) + continue; + + list($dev, $stats_list) = preg_split('/:/', $buf, 2); + $dev = trim($dev); + if (!in_array($dev, $this->_netact_devices)) + continue; + $stats = preg_split('/\s+/', trim($stats_list)); + $results[] .= sprintf('%s: %s %s %s', + $dev, + $this->_format_bytes($stats[0] / 1024), // received + $this->_format_bytes($stats[8] / 1024), // sent + $this->_format_bytes($stats[2] + $stats[10]) // errors + + ); } - - function refresh_netact() - { - irssi_statusbar_items_redraw('netact'); - } - - function draw_netact($item, $get_size_only) - { - $item->default_handler($get_size_only, '{sb '.$this->_get_netact().'}', '', true); - return; - } + + return implode(' ', $results); + } + + function _format_bytes ($kbytes) { + $spacer = ' '; + if ($kbytes > 1048576) + $result = sprintf('%.2fG', $kbytes / 1048576); + elseif ($kbytes > 1024) + $result = sprintf('%.2fM', $kbytes / 1024); + else + $result = sprintf('%.2fK', $kbytes); + return $result; } + function refresh_netact() + { + irssi_statusbar_items_redraw('netact'); + } + + function draw_netact($item, $get_size_only) + { + $item->default_handler($get_size_only, '{sb '.$this->_get_netact().'}', '', true); + return; + } + } -new samples::sysinfo; +new sampleSysinfo; -?> \ No newline at end of file +?>

Thread (1 message)

  • Benjamin Schulz
« previous php.embed.cvs (#90) next »