First bunch of fixes to SysInfo-Unix, now it works - barely

This commit is contained in:
Berke Viktor 2012-10-21 09:56:09 +02:00
parent 62c9375bc9
commit 3d01c78248
4 changed files with 601 additions and 535 deletions

View File

@ -24,8 +24,6 @@
#include <unistd.h> #include <unistd.h>
#include "xsys.h" #include "xsys.h"
extern int percentages;
float percentage(unsigned long long *free, unsigned long long *total) float percentage(unsigned long long *free, unsigned long long *total)
{ {
unsigned long long result = (*free) * (unsigned long long)1000 / (*total); unsigned long long result = (*free) * (unsigned long long)1000 / (*total);
@ -56,7 +54,7 @@ char *pretty_freespace(const char *desc, unsigned long long *free_k, unsigned lo
free_space = free_space / 1024; free_space = free_space / 1024;
total_space = total_space / 1024; total_space = total_space / 1024;
} }
if (percentages != 0) if (sysinfo_get_percentages () != 0)
snprintf(result, bsize, "%s: %.1f%s, %.1f%% free", snprintf(result, bsize, "%s: %.1f%s, %.1f%% free",
desc, total_space, bytesize, desc, total_space, bytesize,
percentage(free_k, total_k)); percentage(free_k, total_k));

View File

@ -27,8 +27,6 @@
#include <pci/pci.h> #include <pci/pci.h>
#include "xsys.h" #include "xsys.h"
#define PCIIDS "/usr/share/misc/pci.ids"
static struct pci_filter filter; /* Device filter */ static struct pci_filter filter; /* Device filter */
static struct pci_access *pacc; static struct pci_access *pacc;
int bus, dev, func; /* Location of the card */ int bus, dev, func; /* Location of the card */
@ -112,9 +110,15 @@ int pci_find_by_class(u16 *class, char *vendor, char *device)
void pci_find_fullname(char *fullname, char *vendor, char *device) void pci_find_fullname(char *fullname, char *vendor, char *device)
{ {
char buffer[bsize], vendorname[bsize/2] = "", devicename[bsize/2] = "", *position; char buffer[bsize];
char vendorname[bsize/2] = "";
char devicename[bsize/2] = "";
char *position;
int cardfound = 0; int cardfound = 0;
FILE *fp = fopen(PCIIDS, "r");
sysinfo_get_pciids (buffer);
FILE *fp = fopen (buffer, "r");
if(fp == NULL) { if(fp == NULL) {
snprintf(fullname, bsize, "%s:%s", vendor, device); snprintf(fullname, bsize, "%s:%s", vendor, device);
return; return;

View File

@ -29,249 +29,24 @@
#include "match.h" #include "match.h"
#include "xsys.h" #include "xsys.h"
#define DEFAULT_FORMAT "%B%1:%B %2 **"
#define DEFAULT_PERCENTAGES 1
#define DEFAULT_PCIIDS "/usr/share/hwdata/pci.ids"
static xchat_plugin *ph; static xchat_plugin *ph;
static char name[] = "SysInfo"; static char name[] = "SysInfo";
static char desc[] = "Display info about your hardware and OS"; static char desc[] = "Display info about your hardware and OS";
static char version[] = "2.2"; static char version[] = "2.2";
static char format[bsize] = "%B%1%B[%2]";
unsigned int percentages = 1;
static void load_config(); static int
static void save_config(); cpuinfo_cb (char *word[], char *word_eol[], void *userdata)
static int format_cb (char *word[], char *word_eol[], void *userdata);
static int percentages_cb (char *word[], char *word_eol[], void *userdata);
static int sysinfo_cb (char *word[], char *word_eol[], void *userdata);
static int xsys_cb (char *word[], char *word_eol[], void *userdata);
static int cpuinfo_cb (char *word[], char *word_eol[], void *userdata);
static int uptime_cb (char *word[], char *word_eol[], void *userdata);
static int osinfo_cb (char *word[], char *word_eol[], void *userdata);
static int sound_cb (char *word[], char *word_eol[], void *userdata);
static int netdata_cb (char *word[], char *word_eol[], void *userdata);
static int netstream_cb (char *word[], char *word_eol[], void *userdata);
static int disk_cb (char *word[], char *word_eol[], void *userdata);
static int mem_cb (char *word[], char *word_eol[], void *userdata);
static int video_cb (char *word[], char *word_eol[], void *userdata);
static int ether_cb (char *word[], char *word_eol[], void *userdata);
static int distro_cb (char *word[], char *word_eol[], void *userdata);
#if 0
static int hwmon_cb (char *word[], char *word_eol[], void *userdata);
#endif
int xchat_plugin_init(xchat_plugin *plugin_handle, char **plugin_name,
char **plugin_desc, char **plugin_version, char *arg)
{ {
ph = plugin_handle; char model[bsize];
*plugin_name = name; char vendor[bsize];
*plugin_desc = desc; char cache[bsize];
*plugin_version = version;
xchat_hook_command(ph, "XSYS2FORMAT",XCHAT_PRI_NORM, format_cb, NULL, NULL);
xchat_hook_command(ph, "PERCENTAGES",XCHAT_PRI_NORM, percentages_cb, NULL, NULL);
xchat_hook_command(ph, "SYSINFO", XCHAT_PRI_NORM, sysinfo_cb, NULL, (void *) 0);
xchat_hook_command(ph, "ESYSINFO", XCHAT_PRI_NORM, sysinfo_cb, NULL, (void *) 1);
xchat_hook_command(ph, "XSYS", XCHAT_PRI_NORM, xsys_cb, NULL, (void *) 0);
xchat_hook_command(ph, "EXSYS", XCHAT_PRI_NORM, xsys_cb, NULL, (void *) 1);
xchat_hook_command(ph, "CPUINFO", XCHAT_PRI_NORM, cpuinfo_cb, NULL, (void *) 0);
xchat_hook_command(ph, "ECPUINFO", XCHAT_PRI_NORM, cpuinfo_cb, NULL, (void *) 1);
xchat_hook_command(ph, "SYSUPTIME", XCHAT_PRI_NORM, uptime_cb, NULL, (void *) 0);
xchat_hook_command(ph, "ESYSUPTIME", XCHAT_PRI_NORM, uptime_cb, NULL, (void *) 1);
xchat_hook_command(ph, "OSINFO", XCHAT_PRI_NORM, osinfo_cb, NULL, (void *) 0);
xchat_hook_command(ph, "EOSINFO", XCHAT_PRI_NORM, osinfo_cb, NULL, (void *) 1);
xchat_hook_command(ph, "SOUND", XCHAT_PRI_NORM, sound_cb, NULL, (void *) 0);
xchat_hook_command(ph, "ESOUND", XCHAT_PRI_NORM, sound_cb, NULL, (void *) 1);
xchat_hook_command(ph, "NETDATA", XCHAT_PRI_NORM, netdata_cb, NULL, (void *) 0);
xchat_hook_command(ph, "ENETDATA", XCHAT_PRI_NORM, netdata_cb, NULL, (void *) 1);
xchat_hook_command(ph, "NETSTREAM", XCHAT_PRI_NORM, netstream_cb, NULL, (void *) 0);
xchat_hook_command(ph, "ENETSTREAM", XCHAT_PRI_NORM, netstream_cb, NULL, (void *) 1);
xchat_hook_command(ph, "DISKINFO", XCHAT_PRI_NORM, disk_cb, NULL, (void *) 0);
xchat_hook_command(ph, "EDISKINFO", XCHAT_PRI_NORM, disk_cb, NULL, (void *) 1);
xchat_hook_command(ph, "MEMINFO", XCHAT_PRI_NORM, mem_cb, NULL, (void *) 0);
xchat_hook_command(ph, "EMEMINFO", XCHAT_PRI_NORM, mem_cb, NULL, (void *) 1);
xchat_hook_command(ph, "VIDEO", XCHAT_PRI_NORM, video_cb, NULL, (void *) 0);
xchat_hook_command(ph, "EVIDEO", XCHAT_PRI_NORM, video_cb, NULL, (void *) 1);
xchat_hook_command(ph, "ETHER", XCHAT_PRI_NORM, ether_cb, NULL, (void *) 0);
xchat_hook_command(ph, "EETHER", XCHAT_PRI_NORM, ether_cb, NULL, (void *) 1);
xchat_hook_command(ph, "DISTRO", XCHAT_PRI_NORM, distro_cb, NULL, (void *) 0);
xchat_hook_command(ph, "EDISTRO", XCHAT_PRI_NORM, distro_cb, NULL, (void *) 1);
#if 0
xchat_hook_command(ph, "HWMON", XCHAT_PRI_NORM, hwmon_cb, NULL, (void *) 0);
xchat_hook_command(ph, "EHWMON", XCHAT_PRI_NORM, hwmon_cb, NULL, (void *) 1);
#endif
load_config();
xchat_printf (ph, "%s plugin loaded\n", name);
return 1;
}
static void save_config()
{
FILE *fp;
char buffer[bsize]; char buffer[bsize];
snprintf(buffer, bsize, "%s/xsys2.conf", xchat_get_info(ph, "xchatdirfs")); char format[bsize];
fp = fopen(buffer, "w");
if(fp == NULL)
{
printf("ERROR writing xsys2.conf");
return;
}
fprintf(fp, "format: %s\n", format);
fprintf(fp, "percentages: %i\n", percentages);
fclose(fp);
return;
}
static void load_config()
{
FILE *fp;
char buffer[bsize];
snprintf(buffer, bsize, "%s/xsys2.conf", xchat_get_info(ph, "xchatdirfs"));
fp = fopen(buffer, "r");
if(fp == NULL)
save_config();
while(fgets(buffer, bsize, fp) != NULL)
{
find_match_char(buffer, "format", format);
find_match_int(buffer, "percentages", &percentages);
}
fclose(fp);
}
static int format_cb(char *word[], char *word_eol[], void *userdata)
{
if(*(word[2]) == '\0')
xchat_printf(ph, "Current format string:\n%s", format);
else
{
strncpy(format, word_eol[2], bsize);
save_config();
}
return XCHAT_EAT_ALL;
}
static int percentages_cb(char *word[], char *word_eol[], void *userdata)
{
if(*(word[2]) == '\0')
if (percentages != 0)
xchat_printf(ph, "Percentages currently enabled");
else
xchat_printf(ph, "Percentages currently disabled");
else
{
percentages = atoi(word[2]);
save_config();
}
return XCHAT_EAT_ALL;
}
static int sysinfo_cb(char *word[], char *word_eol[], void *userdata)
{
char sysinfo[bsize], buffer[bsize], cpu_model[bsize], cpu_cache[bsize], cpu_vendor[bsize];
char os_host[bsize], os_user[bsize], os_kernel[bsize];
unsigned long long mem_total, mem_free;
unsigned int count;
double cpu_freq;
int giga = 0;
sysinfo[0] = '\0';
// BEGIN OS PARSING
if(xs_parse_os(os_user, os_host, os_kernel) != 0)
{
xchat_printf(ph, "ERROR in parse_os()");
return XCHAT_EAT_ALL;
}
snprintf(buffer, bsize, "%s", os_kernel);
format_output("os", buffer, format);
strncat(sysinfo, buffer, bsize-strlen(sysinfo));
// BEGIN DISTRO PARSING
if(xs_parse_distro(buffer) != 0)
strncpy(buffer, "Unknown", bsize);
format_output("distro", buffer, format);
strcat(sysinfo, "\017 ");
strncat(sysinfo, buffer, bsize-strlen(sysinfo));
// BEGIN CPU PARSING
if(xs_parse_cpu(cpu_model, cpu_vendor, &cpu_freq, cpu_cache, &count) != 0)
{
xchat_printf(ph, "ERROR in parse_cpu()");
return XCHAT_EAT_ALL;
}
if(cpu_freq > 1000)
{
cpu_freq /= 1000;
giga = 1;
}
if(giga) snprintf(buffer, bsize, "%d x %s (%s) @ %.2fGHz", count, cpu_model, cpu_vendor, cpu_freq);
else snprintf(buffer, bsize, "%d x %s (%s) @ %.0fMHz", count, cpu_model, cpu_vendor, cpu_freq);
format_output("cpu", buffer, format);
strcat(sysinfo, "\017 ");
strncat(sysinfo, buffer, bsize-strlen(sysinfo));
// BEGIN MEMORY PARSING
if(xs_parse_meminfo(&mem_total, &mem_free, 0) == 1)
{
xchat_printf(ph, "ERROR in parse_meminfo!");
return XCHAT_EAT_ALL;
}
snprintf(buffer, bsize, "%s", pretty_freespace("Physical", &mem_free, &mem_total));
format_output("mem", buffer, format);
strcat(sysinfo, "\017 ");
strncat(sysinfo, buffer, bsize-strlen(sysinfo));
// BEGIN DISK PARSING
if(xs_parse_df(NULL, buffer))
{
xchat_printf(ph, "ERROR in parse_df");
return XCHAT_EAT_ALL;
}
format_output("disk", buffer, format);
strcat(sysinfo, "\017 ");
strncat(sysinfo, buffer, bsize-strlen(buffer));
//BEGIN VIDEO PARSING
if(xs_parse_video(buffer))
{
xchat_printf(ph, "ERROR in parse_video");
return XCHAT_EAT_ALL;
}
format_output("video", buffer, format);
strcat(sysinfo, "\017 ");
strncat(sysinfo, buffer, bsize-strlen(buffer));
//BEGIN SOUND PARSING
if(xs_parse_sound(buffer))
strncpy(buffer, "Not present", bsize);
format_output("sound", buffer, format);
strcat(sysinfo, "\017 ");
strncat(sysinfo, buffer, bsize-strlen(buffer));
if((long)userdata)
xchat_printf(ph, "%s", sysinfo);
else
xchat_commandf(ph, "say %s", sysinfo);
return XCHAT_EAT_ALL;
}
static int xsys_cb(char *word[], char *word_eol[], void *userdata)
{
if((long)userdata)
xchat_printf(ph, "You are using %s v%s (http://dev.gentoo.org/~chainsaw/xsys)", name, version);
else
xchat_commandf(ph, "me is using %s v%s (http://dev.gentoo.org/~chainsaw/xsys)", name, version);
return XCHAT_EAT_ALL;
}
static int cpuinfo_cb(char *word[], char *word_eol[], void *userdata)
{
char model[bsize], vendor[bsize], cache[bsize], buffer[bsize];
unsigned int count; unsigned int count;
double freq; double freq;
int giga = 0; int giga = 0;
@ -288,23 +63,40 @@ static int cpuinfo_cb(char *word[], char *word_eol[], void *userdata)
giga = 1; giga = 1;
} }
if(giga) snprintf(buffer, bsize, "%d x %s (%s) @ %.2fGHz w/ %s L2 Cache", count, model, vendor, freq, cache); if (giga)
else snprintf(buffer, bsize, "%d x %s (%s) @ %.0fMHz w/ %s L2 Cache", count, model, vendor, freq, cache); {
snprintf (buffer, bsize, "%d x %s (%s) @ %.2fGHz w/ %s L2 Cache", count, model, vendor, freq, cache);
}
else
{
snprintf (buffer, bsize, "%d x %s (%s) @ %.0fMHz w/ %s L2 Cache", count, model, vendor, freq, cache);
}
format_output("cpu", buffer, format); xchat_pluginpref_get_str (ph, "format", format);
format_output ("CPU", buffer, format);
if ((long)userdata) if ((long)userdata)
{
xchat_printf (ph, "%s", buffer); xchat_printf (ph, "%s", buffer);
}
else else
{
xchat_commandf (ph, "say %s", buffer); xchat_commandf (ph, "say %s", buffer);
}
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
static int uptime_cb(char *word[], char *word_eol[], void *userdata) static int
uptime_cb (char *word[], char *word_eol[], void *userdata)
{ {
char buffer[bsize]; char buffer[bsize];
int weeks, days, hours, minutes, seconds; char format[bsize];
int weeks;
int days;
int hours;
int minutes;
int seconds;
if (xs_parse_uptime (&weeks, &days, &hours, &minutes, &seconds)) if (xs_parse_uptime (&weeks, &days, &hours, &minutes, &seconds))
{ {
@ -320,19 +112,16 @@ static int uptime_cb(char *word[], char *word_eol[], void *userdata)
{ {
if (weeks != 0) if (weeks != 0)
{ {
snprintf( buffer, bsize, "%dw %dd %dh %dm %ds", snprintf (buffer, bsize, "%dw %dd %dh %dm %ds", weeks, days, hours, minutes, seconds);
weeks, days, hours, minutes, seconds );
} }
else else
{ {
snprintf( buffer, bsize, "%dd %dh %dm %ds", snprintf (buffer, bsize, "%dd %dh %dm %ds", days, hours, minutes, seconds);
days, hours, minutes, seconds );
} }
} }
else else
{ {
snprintf( buffer, bsize, "%dh %dm %ds", snprintf (buffer, bsize, "%dh %dm %ds", hours, minutes, seconds);
hours, minutes, seconds );
} }
} }
else else
@ -341,19 +130,28 @@ static int uptime_cb(char *word[], char *word_eol[], void *userdata)
} }
} }
format_output("uptime", buffer, format); format_output ("Uptime", buffer, format);
if ((long)userdata) if ((long)userdata)
{
xchat_printf (ph, "%s", buffer); xchat_printf (ph, "%s", buffer);
}
else else
{
xchat_commandf (ph, "say %s", buffer); xchat_commandf (ph, "say %s", buffer);
}
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
static int osinfo_cb(char *word[], char *word_eol[], void *userdata) static int
osinfo_cb (char *word[], char *word_eol[], void *userdata)
{ {
char buffer[bsize], user[bsize], host[bsize], kernel[bsize]; char buffer[bsize];
char user[bsize];
char host[bsize];
char kernel[bsize];
char format[bsize];
if (xs_parse_os (user, host, kernel) != 0) if (xs_parse_os (user, host, kernel) != 0)
{ {
@ -362,56 +160,81 @@ static int osinfo_cb(char *word[], char *word_eol[], void *userdata)
} }
snprintf (buffer, bsize, "%s@%s, %s", user, host, kernel); snprintf (buffer, bsize, "%s@%s, %s", user, host, kernel);
format_output("os", buffer, format); xchat_pluginpref_get_str (ph, "format", format);
format_output ("OS", buffer, format);
if ((long)userdata) if ((long)userdata)
{
xchat_printf (ph, "%s", buffer); xchat_printf (ph, "%s", buffer);
}
else else
{
xchat_commandf (ph, "say %s", buffer); xchat_commandf (ph, "say %s", buffer);
}
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
static int sound_cb(char *word[], char *world_eol[], void *userdata) static int
sound_cb (char *word[], char *world_eol[], void *userdata)
{ {
char sound[bsize]; char sound[bsize];
char format[bsize];
if (xs_parse_sound (sound) != 0) if (xs_parse_sound (sound) != 0)
{ {
xchat_printf (ph, "ERROR in parse_asound()!"); xchat_printf (ph, "ERROR in parse_asound()!");
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
format_output("sound", sound, format); xchat_pluginpref_get_str (ph, "format", format);
format_output ("Sound", sound, format);
if ((long)userdata) if ((long)userdata)
{
xchat_printf (ph, "%s", sound); xchat_printf (ph, "%s", sound);
}
else else
{
xchat_commandf (ph, "say %s", sound); xchat_commandf (ph, "say %s", sound);
}
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
static int distro_cb(char *word[], char *word_eol[], void *userdata) static int
distro_cb (char *word[], char *word_eol[], void *userdata)
{ {
char name[bsize]; char name[bsize];
char format[bsize];
if (xs_parse_distro (name) != 0) if (xs_parse_distro (name) != 0)
{ {
xchat_printf (ph, "ERROR in parse_distro()!"); xchat_printf (ph, "ERROR in parse_distro()!");
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
format_output("distro", name, format); xchat_pluginpref_get_str (ph, "format", format);
format_output("Distro", name, format);
if ((long)userdata) if ((long)userdata)
{
xchat_printf (ph, "%s", name); xchat_printf (ph, "%s", name);
}
else else
{
xchat_commandf (ph, "say %s", name); xchat_commandf (ph, "say %s", name);
}
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
static int netdata_cb(char *word[], char *word_eol[], void *userdata) static int
netdata_cb (char *word[], char *word_eol[], void *userdata)
{ {
char netdata[bsize]; char netdata[bsize];
unsigned long long bytes_recv, bytes_sent; char format[bsize];
unsigned long long bytes_recv;
unsigned long long bytes_sent;
if (*word[2] == '\0') if (*word[2] == '\0')
{ {
@ -429,21 +252,34 @@ static int netdata_cb(char *word[], char *word_eol[], void *userdata)
bytes_sent /= 1024; bytes_sent /= 1024;
snprintf (netdata, bsize, "%s: %.1f MB Recieved, %.1f MB Sent", word[2], (double)bytes_recv/1024.0, (double)bytes_sent/1024.0); snprintf (netdata, bsize, "%s: %.1f MB Recieved, %.1f MB Sent", word[2], (double)bytes_recv/1024.0, (double)bytes_sent/1024.0);
format_output("netdata", netdata, format); xchat_pluginpref_get_str (ph, "format", format);
format_output ("Netdata", netdata, format);
if ((long)userdata) if ((long)userdata)
{
xchat_printf (ph, "%s", netdata); xchat_printf (ph, "%s", netdata);
}
else else
{
xchat_commandf (ph, "say %s", netdata); xchat_commandf (ph, "say %s", netdata);
}
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
static int netstream_cb(char *word[], char *word_eol[], void *userdata) static int
netstream_cb (char *word[], char *word_eol[], void *userdata)
{ {
char netstream[bsize], mag_r[3], mag_s[5]; char netstream[bsize];
unsigned long long bytes_recv, bytes_sent, bytes_recv_p, bytes_sent_p; char mag_r[3];
struct timespec ts = {1, 0}; char mag_s[5];
char format[bsize];
unsigned long long bytes_recv;
unsigned long long bytes_sent;
unsigned long long bytes_recv_p;
unsigned long long bytes_sent_p;
struct timespec ts = {1, 0};
if (*word[2] == '\0') if (*word[2] == '\0')
{ {
@ -473,28 +309,42 @@ static int netstream_cb(char *word[], char *word_eol[], void *userdata)
bytes_recv /= 1024; bytes_recv /= 1024;
snprintf (mag_r, 5, "KB/s"); snprintf (mag_r, 5, "KB/s");
} }
else snprintf(mag_r, 5, "B/s"); else
{
snprintf (mag_r, 5, "B/s");
}
if (bytes_sent > 1024) if (bytes_sent > 1024)
{ {
bytes_sent /= 1024; bytes_sent /= 1024;
snprintf (mag_s, 5, "KB/s"); snprintf (mag_s, 5, "KB/s");
} }
else snprintf(mag_s, 5, "B/s"); else
{
snprintf (mag_s, 5, "B/s");
}
snprintf (netstream, bsize, "%s: Receiving %llu %s, Sending %llu %s", word[2], bytes_recv, mag_r, bytes_sent, mag_s); snprintf (netstream, bsize, "%s: Receiving %llu %s, Sending %llu %s", word[2], bytes_recv, mag_r, bytes_sent, mag_s);
format_output("netstream", netstream, format); xchat_pluginpref_get_str (ph, "format", format);
format_output ("Netstream", netstream, format);
if ((long)userdata) if ((long)userdata)
{
xchat_printf (ph, "%s", netstream); xchat_printf (ph, "%s", netstream);
}
else else
{
xchat_commandf (ph, "say %s", netstream); xchat_commandf (ph, "say %s", netstream);
}
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
static int disk_cb(char *word[], char *word_eol[], void *userdata) static int
disk_cb (char *word[], char *word_eol[], void *userdata)
{ {
char string[bsize] = {0,}; char string[bsize] = {0,};
char format[bsize];
if (*word[2] == '\0') if (*word[2] == '\0')
{ {
@ -513,20 +363,30 @@ static int disk_cb(char *word[], char *word_eol[], void *userdata)
} }
} }
format_output("disk", string, format); xchat_pluginpref_get_str (ph, "format", format);
format_output ("Disk", string, format);
if ((long)userdata) if ((long)userdata)
{
xchat_printf(ph, "%s", string); xchat_printf(ph, "%s", string);
}
else else
{
xchat_commandf(ph, "say %s", string); xchat_commandf(ph, "say %s", string);
}
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
static int mem_cb(char *word[], char *word_eol[], void *userdata) static int
mem_cb (char *word[], char *word_eol[], void *userdata)
{ {
unsigned long long mem_total, mem_free, swap_total, swap_free; unsigned long long mem_total;
unsigned long long mem_free;
unsigned long long swap_total;
unsigned long long swap_free;
char string[bsize]; char string[bsize];
char format[bsize];
if (xs_parse_meminfo (&mem_total, &mem_free, 0) == 1) if (xs_parse_meminfo (&mem_total, &mem_free, 0) == 1)
{ {
@ -539,22 +399,31 @@ static int mem_cb(char *word[], char *word_eol[], void *userdata)
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
snprintf(string, bsize, "%s - %s", pretty_freespace("Physical", &mem_free, &mem_total), snprintf (string, bsize, "%s - %s", pretty_freespace ("Physical", &mem_free, &mem_total), pretty_freespace ("Swap", &swap_free, &swap_total));
pretty_freespace("Swap", &swap_free, &swap_total)); xchat_pluginpref_get_str (ph, "format", format);
format_output("mem", string, format); format_output ("RAM", string, format);
if ((long)userdata) if ((long)userdata)
{
xchat_printf (ph, "%s", string); xchat_printf (ph, "%s", string);
}
else else
{
xchat_commandf (ph, "say %s", string); xchat_commandf (ph, "say %s", string);
}
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
static int video_cb(char *word[], char *word_eol[], void *userdata) static int
video_cb (char *word[], char *word_eol[], void *userdata)
{ {
char vid_card[bsize], agp_bridge[bsize], buffer[bsize]; char vid_card[bsize];
char agp_bridge[bsize];
char buffer[bsize];
char format[bsize];
int ret; int ret;
if ((ret = xs_parse_video (vid_card)) != 0) if ((ret = xs_parse_video (vid_card)) != 0)
{ {
xchat_printf (ph, "ERROR in parse_video! %d", ret); xchat_printf (ph, "ERROR in parse_video! %d", ret);
@ -562,55 +431,247 @@ static int video_cb(char *word[], char *word_eol[], void *userdata)
} }
if (xs_parse_agpbridge (agp_bridge) != 0) if (xs_parse_agpbridge (agp_bridge) != 0)
{
snprintf (buffer, bsize, "%s", vid_card); snprintf (buffer, bsize, "%s", vid_card);
}
else else
{
snprintf (buffer, bsize, "%s @ %s", vid_card, agp_bridge); snprintf (buffer, bsize, "%s @ %s", vid_card, agp_bridge);
}
format_output("video", buffer, format); xchat_pluginpref_get_str (ph, "format", format);
format_output ("VGA", buffer, format);
if ((long)userdata) if ((long)userdata)
{
xchat_printf (ph, "%s", buffer); xchat_printf (ph, "%s", buffer);
}
else else
{
xchat_commandf (ph, "say %s", buffer); xchat_commandf (ph, "say %s", buffer);
}
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
static int ether_cb(char *word[], char *word_eol[], void *userdata) static int
ether_cb (char *word[], char *word_eol[], void *userdata)
{ {
char ethernet_card[bsize]; char ethernet_card[bsize];
char format[bsize];
if (xs_parse_ether (ethernet_card)) if (xs_parse_ether (ethernet_card))
{
strncpy (ethernet_card, "None found", bsize); strncpy (ethernet_card, "None found", bsize);
format_output("ether", ethernet_card, format); }
xchat_pluginpref_get_str (ph, "format", format);
format_output ("Ethernet", ethernet_card, format);
if ((long)userdata) if ((long)userdata)
{
xchat_printf(ph, "%s", ethernet_card); xchat_printf(ph, "%s", ethernet_card);
}
else else
{
xchat_commandf(ph, "say %s", ethernet_card); xchat_commandf(ph, "say %s", ethernet_card);
}
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
#if 0 int
static int hwmon_cb(char *word[], char *word_eol[], void *userdata) sysinfo_get_percentages ()
{ {
char chip[bsize], buffer[bsize]; return xchat_pluginpref_get_int (ph, "percentages");
}
if(xs_parse_hwmon_chip(chip)) void
sysinfo_get_pciids (char* dest)
{ {
xchat_printf(ph, "ERROR No hardware monitoring support found"); xchat_pluginpref_get_str (ph, "pciids", dest);
}
static int
sysinfo_cb (char *word[], char *word_eol[], void *userdata)
{
char sysinfo[bsize];
char buffer[bsize];
char cpu_model[bsize];
char cpu_cache[bsize];
char cpu_vendor[bsize];
char os_host[bsize];
char os_user[bsize];
char os_kernel[bsize];
char format[bsize];
unsigned long long mem_total;
unsigned long long mem_free;
unsigned int count;
double cpu_freq;
int giga = 0;
sysinfo[0] = '\0';
xchat_pluginpref_get_str (ph, "format", format);
/* BEGIN OS PARSING */
if (xs_parse_os (os_user, os_host, os_kernel) != 0)
{
xchat_printf (ph, "ERROR in parse_os()");
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
format_output("sensor", chip, format);
strcat(chip, "\017 ");
xs_parse_hwmon_temp(buffer, 1); snprintf (buffer, bsize, "%s", os_kernel);
format_output("temp1", buffer, format); format_output ("OS", buffer, format);
strncat(chip, buffer, bsize); strncat (sysinfo, buffer, bsize - strlen (sysinfo));
/* BEGIN DISTRO PARSING */
if (xs_parse_distro (buffer) != 0)
{
strncpy (buffer, "Unknown", bsize);
}
format_output ("Distro", buffer, format);
strcat (sysinfo, "\017 ");
strncat (sysinfo, buffer, bsize - strlen (sysinfo));
/* BEGIN CPU PARSING */
if (xs_parse_cpu (cpu_model, cpu_vendor, &cpu_freq, cpu_cache, &count) != 0)
{
xchat_printf (ph, "ERROR in parse_cpu()");
return XCHAT_EAT_ALL;
}
if (cpu_freq > 1000)
{
cpu_freq /= 1000;
giga = 1;
}
if (giga)
{
snprintf (buffer, bsize, "%d x %s (%s) @ %.2fGHz", count, cpu_model, cpu_vendor, cpu_freq);
}
else
{
snprintf (buffer, bsize, "%d x %s (%s) @ %.0fMHz", count, cpu_model, cpu_vendor, cpu_freq);
}
format_output ("CPU", buffer, format);
strcat (sysinfo, "\017 ");
strncat (sysinfo, buffer, bsize - strlen (sysinfo));
/* BEGIN MEMORY PARSING */
if (xs_parse_meminfo (&mem_total, &mem_free, 0) == 1)
{
xchat_printf (ph, "ERROR in parse_meminfo!");
return XCHAT_EAT_ALL;
}
snprintf (buffer, bsize, "%s", pretty_freespace ("Physical", &mem_free, &mem_total));
format_output ("RAM", buffer, format);
strcat (sysinfo, "\017 ");
strncat (sysinfo, buffer, bsize - strlen (sysinfo));
/* BEGIN DISK PARSING */
if (xs_parse_df (NULL, buffer))
{
xchat_printf (ph, "ERROR in parse_df");
return XCHAT_EAT_ALL;
}
format_output ("Disk", buffer, format);
strcat (sysinfo, "\017 ");
strncat (sysinfo, buffer, bsize - strlen (buffer));
/* BEGIN VIDEO PARSING */
if (xs_parse_video (buffer))
{
xchat_printf (ph, "ERROR in parse_video");
return XCHAT_EAT_ALL;
}
format_output ("VGA", buffer, format);
strcat (sysinfo, "\017 ");
strncat (sysinfo, buffer, bsize - strlen (buffer));
/* BEGIN SOUND PARSING */
if (xs_parse_sound (buffer))
{
strncpy (buffer, "Not present", bsize);
}
format_output ("Sound", buffer, format);
strcat (sysinfo, "\017 ");
strncat (sysinfo, buffer, bsize - strlen (buffer));
if ((long)userdata) if ((long)userdata)
xchat_printf(ph, "%s", chip); {
xchat_printf (ph, "%s", sysinfo);
}
else else
xchat_commandf(ph, "say %s", chip); {
xchat_commandf (ph, "say %s", sysinfo);
}
return XCHAT_EAT_ALL; return XCHAT_EAT_ALL;
} }
#endif
int
xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg)
{
ph = plugin_handle;
*plugin_name = name;
*plugin_desc = desc;
*plugin_version = version;
char buffer[bsize];
xchat_hook_command (ph, "SYSINFO", XCHAT_PRI_NORM, sysinfo_cb, NULL, (void *) 0);
xchat_hook_command (ph, "ESYSINFO", XCHAT_PRI_NORM, sysinfo_cb, NULL, (void *) 1);
xchat_hook_command (ph, "CPUINFO", XCHAT_PRI_NORM, cpuinfo_cb, NULL, (void *) 0);
xchat_hook_command (ph, "ECPUINFO", XCHAT_PRI_NORM, cpuinfo_cb, NULL, (void *) 1);
xchat_hook_command (ph, "SYSUPTIME", XCHAT_PRI_NORM, uptime_cb, NULL, (void *) 0);
xchat_hook_command (ph, "ESYSUPTIME", XCHAT_PRI_NORM, uptime_cb, NULL, (void *) 1);
xchat_hook_command (ph, "OSINFO", XCHAT_PRI_NORM, osinfo_cb, NULL, (void *) 0);
xchat_hook_command (ph, "EOSINFO", XCHAT_PRI_NORM, osinfo_cb, NULL, (void *) 1);
xchat_hook_command (ph, "SOUND", XCHAT_PRI_NORM, sound_cb, NULL, (void *) 0);
xchat_hook_command (ph, "ESOUND", XCHAT_PRI_NORM, sound_cb, NULL, (void *) 1);
xchat_hook_command (ph, "NETDATA", XCHAT_PRI_NORM, netdata_cb, NULL, (void *) 0);
xchat_hook_command (ph, "ENETDATA", XCHAT_PRI_NORM, netdata_cb, NULL, (void *) 1);
xchat_hook_command (ph, "NETSTREAM", XCHAT_PRI_NORM, netstream_cb, NULL, (void *) 0);
xchat_hook_command (ph, "ENETSTREAM", XCHAT_PRI_NORM, netstream_cb, NULL, (void *) 1);
xchat_hook_command (ph, "DISKINFO", XCHAT_PRI_NORM, disk_cb, NULL, (void *) 0);
xchat_hook_command (ph, "EDISKINFO", XCHAT_PRI_NORM, disk_cb, NULL, (void *) 1);
xchat_hook_command (ph, "MEMINFO", XCHAT_PRI_NORM, mem_cb, NULL, (void *) 0);
xchat_hook_command (ph, "EMEMINFO", XCHAT_PRI_NORM, mem_cb, NULL, (void *) 1);
xchat_hook_command (ph, "VIDEO", XCHAT_PRI_NORM, video_cb, NULL, (void *) 0);
xchat_hook_command (ph, "EVIDEO", XCHAT_PRI_NORM, video_cb, NULL, (void *) 1);
xchat_hook_command (ph, "ETHER", XCHAT_PRI_NORM, ether_cb, NULL, (void *) 0);
xchat_hook_command (ph, "EETHER", XCHAT_PRI_NORM, ether_cb, NULL, (void *) 1);
xchat_hook_command (ph, "DISTRO", XCHAT_PRI_NORM, distro_cb, NULL, (void *) 0);
xchat_hook_command (ph, "EDISTRO", XCHAT_PRI_NORM, distro_cb, NULL, (void *) 1);
/* this is required for the very first run */
if (xchat_pluginpref_get_str (ph, "pciids", buffer) == 0)
{
xchat_pluginpref_set_str (ph, "pciids", DEFAULT_PCIIDS);
}
if (xchat_pluginpref_get_str (ph, "format", buffer) == 0)
{
xchat_pluginpref_set_str (ph, "format", DEFAULT_FORMAT);
}
if (xchat_pluginpref_get_int (ph, "percentages") == -1)
{
xchat_pluginpref_set_int (ph, "percentages", DEFAULT_PERCENTAGES);
}
xchat_printf (ph, "%s plugin loaded\n", name);
return 1;
}
int
xchat_plugin_deinit (void)
{
xchat_printf (ph, "%s plugin unloaded\n", name);
return 1;
}

View File

@ -25,4 +25,7 @@
#define bsize 1024 #define bsize 1024
#define delims ":=" #define delims ":="
int sysinfo_get_percentages ();
void sysinfo_get_pciids (char *dest);
#endif #endif