Implemented display of IP address, minor code cleanup

(Old svn revision: 337)
master
Bernhard Walle 2005-02-04 18:12:01 +00:00
parent e71c9f3ddb
commit 65af5a9649
7 changed files with 307 additions and 193 deletions

View File

@ -1,32 +1,25 @@
/* XFce 4 - Netload Plugin
* Copyright (c) 2003 Bernhard Walle <bernhard.walle@gmx.de>
/*
* Id: $Id: commandline.c,v 1.2 2005/02/04 18:12:01 bwalle Exp $
* -------------------------------------------------------------------------------------------------
*
* Id: $Id: commandline.c,v 1.1 2003/08/31 12:45:25 bwalle Exp $
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; You may only use
* version 2 of the License, you have no option to use any other version.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program; if
* not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* -------------------------------------------------------------------------------------------------
*/
/*
* This is just a command-line wrapper for the operating-system specific code in wormulon/.
* I wrote it because with this I'm able to test on systems with no GUI. Since I'm only running
* Linux but develop for other Operating systems this is important!
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@ -43,12 +36,15 @@
netdata data;
/* ---------------------------------------------------------------------------------------------- */
void sig_end_handler (int sig)
{
close_netload(&data);
exit(0);
}
/* ---------------------------------------------------------------------------------------------- */
int main(int argc, char* argv[])
{
unsigned long in, out, tot;
@ -80,7 +76,8 @@ int main (int argc, char* argv[])
format_with_thousandssep(bufIn, 20, (double)in, 2);
format_with_thousandssep(bufOut, 20, (double)in, 2);
format_with_thousandssep(bufTot, 20, (double)in, 2);
printf("Current netload:\nIN : %s\nOUT: %s\nTOT: %s\n", bufIn, bufOut, bufTot);
printf("Current netload:\nIN : %s\nOUT: %s\nTOT: %s\nIP: %s\n",
bufIn, bufOut, bufTot, get_ip_address(&data));
sleep(1);
}

View File

@ -1,25 +1,21 @@
/* XFce 4 - Netload Plugin
* Copyright (c) 2003 Bernhard Walle <bernhard.walle@gmx.de>
/*
* Id: $Id: net.c,v 1.7 2005/02/04 18:12:01 bwalle Exp $
* -------------------------------------------------------------------------------------------------
*
* Id: $Id: net.c,v 1.6 2003/09/13 12:30:49 bwalle Exp $
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; You may only use
* version 2 of the License, you have no option to use any other version.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program; if
* not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* -------------------------------------------------------------------------------------------------
*/
/*
* This is just a wrapper between the netload-plugin and the wormulon source.
* Wormulon is a small command-line util which displays the netload. You can find it
@ -29,8 +25,6 @@
* number of operating systems quickly without a library! Without him only
* Linux and FreeBSD (with foreign code from IceWM) would be supported.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@ -41,6 +35,9 @@
#include "wormulon.h"
#include "slurm.h" /* slurm structs */
#include <sys/types.h>
#ifdef __HPUX__
# include "wormulon/hpux.h"
# include "wormulon/hpux.c"
@ -68,6 +65,7 @@
#endif
/* ---------------------------------------------------------------------------------------------- */
int init_netload(netdata* data, const char* device)
{
memset( data, 0, sizeof(netdata) );
@ -77,11 +75,14 @@ int init_netload(netdata* data, const char* device)
return TRUE;
}
strncpy( data->ifdata.if_name, device, 9 );
data->ifdata.if_name[9] = '\0';
strncpy( data->ifdata.if_name, device, INTERFACE_NAME_LENGTH);
data->ifdata.if_name[INTERFACE_NAME_LENGTH] = '\0';
init_osspecific( data );
data->ip_address[0] = 0;
data->ip_update_count = 0;
if (checkinterface(data) != TRUE)
{
data->correct_interface = FALSE;
@ -103,12 +104,7 @@ int init_netload(netdata* data, const char* device)
}
/**
* Gets the current netload.
* @param in Will be filled with the "in"-load.
* @param out Will be filled with the "out"-load.
* @param tot Will be filled with the "total"-load.
*/
/* ---------------------------------------------------------------------------------------------- */
void get_current_netload(netdata* data, unsigned long *in, unsigned long *out, unsigned long *tot)
{
struct timeval curr_time;
@ -163,6 +159,58 @@ void get_current_netload(netdata* data, unsigned long *in, unsigned long *out, u
data->prev_time.tv_usec = curr_time.tv_usec;
}
/* ---------------------------------------------------------------------------------------------- */
char* get_name(netdata* data)
{
return data->ifdata.if_name;
}
/* ---------------------------------------------------------------------------------------------- */
char* get_ip_address(netdata* data)
{
int sockfd;
struct ifreq ifr;
struct sockaddr_in *p_sa;
/* use cached value if possible and if the update count is non-zero */
if (data->ip_address && data->ip_update_count > 0)
{
data->ip_update_count--;
return data->ip_address;
}
/* get the value from the operating system */
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("Error in socket");
return NULL;
}
snprintf(ifr.ifr_name, IF_NAMESIZE, data->ifdata.if_name);
if (ioctl(sockfd, SIOCGIFADDR, &ifr) != 0)
{
perror("Error in ictl(sockfd)");
return NULL;
}
p_sa = (struct sockaddr_in*) &ifr.ifr_addr;
if (!inet_ntop(AF_INET, &p_sa->sin_addr, data->ip_address, IP_ADDRESS_LENGTH))
{
perror("Error in inet_ntop");
return NULL;
}
/* now updated */
data->ip_update_count = IP_UPDATE_INTERVAL;
return data->ip_address;
}
/* ---------------------------------------------------------------------------------------------- */
void close_netload(netdata* data)
{
/* We need not code here */

View File

@ -1,60 +1,53 @@
/* XFce 4 - Netload Plugin
* Copyright (c) 2003 Bernhard Walle <bernhard.walle@gmx.de>
/*
* Id: $Id: net.h,v 1.8 2005/02/04 18:12:01 bwalle Exp $
* -------------------------------------------------------------------------------------------------
*
* Id: $Id: net.h,v 1.7 2003/09/13 12:30:49 bwalle Exp $
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; You may only use
* version 2 of the License, you have no option to use any other version.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program; if
* not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* -------------------------------------------------------------------------------------------------
*/
#ifndef NET_H
#define NET_H
/* ----------------------- Some defines here ------------------------------- */
#if defined (__sun__)
#define __Solaris__ 1
#endif
#include "os.h"
#include "slurm.h"
#define MSGSIZE 1024
#define IP_UPDATE_INTERVAL 20
#define IP_ADDRESS_LENGTH 64
#define INTERFACE_NAME_LENGTH 9
#ifndef gettext_noop
#define gettext_noop(String) String
#endif
/** errorcodes */
typedef enum {
UNKNOWN_ERROR, /* 0 */
PROC_DEVICE_NOT_FOUND, /* 1 */
INTERFACE_NOT_FOUND /* 2 */
typedef enum
{
UNKNOWN_ERROR,
PROC_DEVICE_NOT_FOUND,
INTERFACE_NOT_FOUND
} errorcode_t;
/*
/**
* We need this because we cannot use static variables. Using of static variables allows
* us not to use several instances of the plugin.
* I know that this change makes it a bit incompatible with wormulon, but that's the
* price to pay ...
*/
typedef struct
{
char old_interface[9];
char old_interface[INTERFACE_NAME_LENGTH];
double backup_in;
errorcode_t errorcode;
double backup_out;
@ -63,6 +56,8 @@ typedef struct
struct timeval prev_time;
int correct_interface; /* treated as boolean */
IfData ifdata;
char ip_address[IP_ADDRESS_LENGTH];
int ip_update_count;
DataStats stats;
#ifdef __HPUX__
int wait_pcks_counter;
@ -111,6 +106,21 @@ int init_netload(netdata* data, const char* device);
*/
void get_current_netload(netdata* data, unsigned long *in, unsigned long *out, unsigned long *tot);
/**
* Returns the name of the network interface.
* @param data object
* @return The name. String resides in data and you don't have to free the string.
* On error, returns NULL.
*/
char* get_name(netdata* data);
/**
* Returns the IP address of the network interface
* @param data object
* @return the IP address as string, NULL on error.
*/
char* get_ip_address(netdata* data);
/**
* Should be called to do cleanup work.
*/

View File

@ -1,23 +1,20 @@
/* XFce 4 - Netload Plugin
* Copyright (c) 2003 Bernhard Walle <bernhard.walle@gmx.de>
/*
* Id: $Id: netload.c,v 1.12 2005/02/04 18:12:01 bwalle Exp $
* -------------------------------------------------------------------------------------------------
*
* Id: $Id: netload.c,v 1.11 2005/01/10 13:43:01 bwalle Exp $
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; You may only use
* version 2 of the License, you have no option to use any other version.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program; if
* not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* -------------------------------------------------------------------------------------------------
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@ -133,7 +130,7 @@ typedef struct
} t_global_monitor;
/* ---------------------------------------------------------------------------------------------- */
static gboolean update_monitors(t_global_monitor *global)
{
char buffer[SUM+1][BUFSIZ];
@ -204,7 +201,6 @@ static gboolean update_monitors(t_global_monitor *global)
}
#endif /* DEBUG */
temp = (double)display[i] / global->monitor->net_max[i];
if (temp > 1)
{
@ -221,17 +217,23 @@ static gboolean update_monitors(t_global_monitor *global)
format_with_thousandssep( buffer[TOT], BUFSIZ, (display[IN]+display[OUT]) / 1024.0, 2 );
{
char* ip = get_ip_address(&(global->monitor->data));
g_snprintf(caption, sizeof(caption),
_("Average of last %d measures:\n"
_("<< %s >> (%s)\nAverage of last %d measures:\n"
"Incoming: %s kByte/s\nOutgoing: %s kByte/s\nTotal: %s kByte/s"),
get_name(&(global->monitor->data)), ip ? ip : _("no IP address"),
HISTSIZE_CALCULATE, buffer[IN], buffer[OUT], buffer[TOT]);
gtk_tooltips_set_tip(tooltips, GTK_WIDGET(global->monitor->ebox), caption, NULL);
}
XFCE_PANEL_UNLOCK();
return TRUE;
}
/* ---------------------------------------------------------------------------------------------- */
static void run_update (t_global_monitor *global)
{
if (global->timeout_id > 0)
@ -247,6 +249,8 @@ static void run_update (t_global_monitor *global)
}
}
/* ---------------------------------------------------------------------------------------------- */
static t_global_monitor * monitor_new(void)
{
t_global_monitor *global;
@ -339,6 +343,8 @@ static t_global_monitor * monitor_new(void)
return global;
}
/* ---------------------------------------------------------------------------------------------- */
static void monitor_set_orientation (Control * ctrl, int orientation)
{
t_global_monitor *global = ctrl->data;
@ -432,6 +438,8 @@ static void monitor_set_orientation (Control * ctrl, int orientation)
run_update( global );
}
/* ---------------------------------------------------------------------------------------------- */
static gboolean monitor_control_new(Control *ctrl)
{
t_global_monitor *global;
@ -451,6 +459,7 @@ static gboolean monitor_control_new(Control *ctrl)
}
/* ---------------------------------------------------------------------------------------------- */
static void monitor_free(Control *ctrl)
{
t_global_monitor *global;
@ -474,6 +483,8 @@ static void monitor_free(Control *ctrl)
close_netload( &(global->monitor->data) );
}
/* ---------------------------------------------------------------------------------------------- */
static void setup_monitor(t_global_monitor *global, gboolean supress_warnings)
{
GtkRcStyle *rc;
@ -542,6 +553,8 @@ static void setup_monitor(t_global_monitor *global, gboolean supress_warnings)
}
/* ---------------------------------------------------------------------------------------------- */
static void monitor_read_config(Control *ctrl, xmlNodePtr node)
{
xmlChar *value;
@ -621,6 +634,7 @@ static void monitor_read_config(Control *ctrl, xmlNodePtr node)
}
/* ---------------------------------------------------------------------------------------------- */
static void monitor_write_config(Control *ctrl, xmlNodePtr parent)
{
xmlNodePtr root;
@ -674,6 +688,8 @@ static void monitor_write_config(Control *ctrl, xmlNodePtr parent)
root = xmlNewTextChild(parent, NULL, MONITOR_ROOT, NULL);
}
/* ---------------------------------------------------------------------------------------------- */
static void monitor_attach_callback(Control *ctrl, const gchar *signal, GCallback cb, gpointer data)
{
t_global_monitor *global;
@ -683,6 +699,7 @@ static void monitor_attach_callback(Control *ctrl, const gchar *signal, GCallbac
}
/* ---------------------------------------------------------------------------------------------- */
static void monitor_set_size(Control *ctrl, int size)
{
/* do the resize */
@ -712,6 +729,7 @@ static void monitor_set_size(Control *ctrl, int size)
}
/* ---------------------------------------------------------------------------------------------- */
static void monitor_apply_options_cb(GtkWidget *button, t_global_monitor *global)
{
gint i;
@ -752,6 +770,7 @@ static void monitor_apply_options_cb(GtkWidget *button, t_global_monitor *global
}
/* ---------------------------------------------------------------------------------------------- */
static void label_changed(GtkWidget *button, t_global_monitor *global)
{
if (global->monitor->options.label_text)
@ -769,6 +788,7 @@ static void label_changed(GtkWidget *button, t_global_monitor *global)
}
/* ---------------------------------------------------------------------------------------------- */
static void max_label_changed(GtkWidget *button, t_global_monitor *global)
{
gint i;
@ -786,6 +806,7 @@ static void max_label_changed(GtkWidget *button, t_global_monitor *global)
}
/* ---------------------------------------------------------------------------------------------- */
static void network_changed(GtkWidget *button, t_global_monitor *global)
{
if (global->monitor->options.network_device)
@ -803,6 +824,7 @@ static void network_changed(GtkWidget *button, t_global_monitor *global)
}
/* ---------------------------------------------------------------------------------------------- */
static void label_toggled(GtkWidget *check_button, t_global_monitor *global)
{
global->monitor->options.use_label =
@ -818,6 +840,8 @@ static void label_toggled(GtkWidget *check_button, t_global_monitor *global)
#endif
}
/* ---------------------------------------------------------------------------------------------- */
static void max_label_toggled(GtkWidget *check_button, t_global_monitor *global)
{
gint i;
@ -843,6 +867,7 @@ static void max_label_toggled(GtkWidget *check_button, t_global_monitor *global)
}
/* ---------------------------------------------------------------------------------------------- */
static gboolean expose_event_cb(GtkWidget *widget, GdkEventExpose *event)
{
if (widget->window)
@ -862,6 +887,7 @@ static gboolean expose_event_cb(GtkWidget *widget, GdkEventExpose *event)
}
/* ---------------------------------------------------------------------------------------------- */
static void change_color(GtkWidget *button, t_global_monitor *global, gint type)
{
GtkWidget *dialog;
@ -896,18 +922,21 @@ static void change_color(GtkWidget *button, t_global_monitor *global, gint type)
}
/* ---------------------------------------------------------------------------------------------- */
static void change_color_in(GtkWidget *button, t_global_monitor *global)
{
change_color(button, global, IN);
}
/* ---------------------------------------------------------------------------------------------- */
static void change_color_out(GtkWidget *button, t_global_monitor *global)
{
change_color(button, global, OUT);
}
/* ---------------------------------------------------------------------------------------------- */
static void monitor_create_options(Control *control, GtkContainer *container, GtkWidget *done)
{
t_global_monitor *global;
@ -1148,6 +1177,7 @@ static void monitor_create_options(Control *control, GtkContainer *container, Gt
}
/* ---------------------------------------------------------------------------------------------- */
G_MODULE_EXPORT void xfce_control_class_init(ControlClass *cc)
{
xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");

View File

@ -1,13 +1,20 @@
/******************************************************************************
/*
* Id: $Id: os.h,v 1.4 2005/02/04 18:12:01 bwalle Exp $
* -------------------------------------------------------------------------------------------------
*
* os.h
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; You may only use
* version 2 of the License, you have no option to use any other version.
*
* include OS-dependent headers
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
******************************************************************************
* This file is from Wormulon. Id: os.h,v 1.3 2003/08/14 10:58:30 hscholz Exp
*****************************************************************************/
* You should have received a copy of the GNU General Public License along with this program; if
* not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* -------------------------------------------------------------------------------------------------
*/
#ifndef _OS_H
#define _OS_H
@ -39,32 +46,32 @@
#include <sys/mib.h>
#include <arpa/inet.h>
#include <net/if.h>
+#elif __APPLE__ /* Mac OS X */
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <string.h>
+#include <time.h>
+#include <ctype.h>
+#include <signal.h>
+#include <curses.h>
+#include <ifaddrs.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/wait.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <netinet/in.h>
+#include <net/route.h>
+#include <net/if_dl.h>
+#include <net/if.h>
+#include <net/if_media.h>
+#include <net/if_mib.h>
+#include <arpa/inet.h>
#elif __APPLE__ /* Mac OS X */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <signal.h>
#include <curses.h>
#include <ifaddrs.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <net/route.h>
#include <net/if_dl.h>
#include <net/if.h>
#include <net/if_media.h>
#include <net/if_mib.h>
#include <arpa/inet.h>
#elif __FreeBSD__ /* F R E E B S D */
#include <stdio.h>
#include <stdlib.h>

View File

@ -1,22 +1,20 @@
/* XFce 4 - Netload Plugin
* Copyright (c) 2003 Bernhard Walle <bernhard.walle@gmx.de>
/*
* Id: $Id: utils.c,v 1.3 2005/02/04 18:12:01 bwalle Exp $
* -------------------------------------------------------------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; You may only use
* version 2 of the License, you have no option to use any other version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* You should have received a copy of the GNU General Public License along with this program; if
* not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* -------------------------------------------------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include <limits.h>
@ -30,6 +28,7 @@
#define BUFSIZ 512
#endif
/* ---------------------------------------------------------------------------------------------- */
unsigned long min_array( unsigned long array[], int size )
{
int i;
@ -46,6 +45,7 @@ unsigned long min_array( unsigned long array[], int size )
}
/* ---------------------------------------------------------------------------------------------- */
unsigned long max_array( unsigned long array[], int size )
{
int i;
@ -58,9 +58,12 @@ unsigned long max_array( unsigned long array[], int size )
max = array[i];
}
}
return max;
}
/* ---------------------------------------------------------------------------------------------- */
char* format_with_thousandssep(char* string, int stringsize, double number, int digits)
{
char* str = string;
@ -104,6 +107,7 @@ char* format_with_thousandssep( char* string, int stringsize, double number, int
*str++ = localeinfo->thousands_sep[i];
}
}
*str++ = *bufptr++;
count--;
}
@ -119,3 +123,4 @@ char* format_with_thousandssep( char* string, int stringsize, double number, int
return string;
}

View File

@ -1,4 +1,21 @@
/* XFce 4 - Netload Plugin
* Copyright (c) 2003 Bernhard Walle <bernhard.walle@gmx.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* -------------------------------------------------------------------------------------------------
*/
#ifndef UTILS_H
#define UTILS_H