| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,9 @@ | ||
| libdir = $(hexchatlibdir) | ||
|
|
||
| lib_LTLIBRARIES = python.la | ||
| python_la_SOURCES = python.c | ||
| python_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module | ||
| python_la_LIBADD = $(PYTHON_LIBS) $(GLIB_LIBS) | ||
| python_la_CPPFLAGS = $(PYTHON_CPPFLAGS) | ||
| python_la_CFLAGS = $(GLIB_CFLAGS) -I$(top_srcdir)/src/common | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| libdir = $(hexchatlibdir) | ||
|
|
||
| sources = sysinfo.c format.c shared/df.c | ||
|
|
||
| if PLATFORM_OSX | ||
| sources += osx/backend.m | ||
| else | ||
| sources += unix/backend.c unix/match.c unix/parse.c unix/pci.c | ||
| endif | ||
|
|
||
| EXTRA_DIST = osx unix win32 shared format.h sysinfo.h sysinfo-backend.h | ||
|
|
||
| lib_LTLIBRARIES = sysinfo.la | ||
| sysinfo_la_SOURCES = $(sources) | ||
| sysinfo_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module | ||
| sysinfo_la_LIBADD = $(LIBPCI_LIBS) $(GLIB_LIBS) | ||
| AM_CPPFLAGS = $(LIBPCI_CFLAGS) $(GLIB_CFLAGS) -I$(top_srcdir)/src/common -I$(srcdir)/shared |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * SysInfo - sysinfo plugin for HexChat | ||
| * Copyright (c) 2015 Patrick Griffis. | ||
| * | ||
| * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
| */ | ||
|
|
||
| #include <glib.h> | ||
|
|
||
| char * | ||
| sysinfo_format_uptime (gint64 uptime) | ||
| { | ||
| char buffer[128]; | ||
|
|
||
| gint64 weeks = uptime / 604800; | ||
| int days = (uptime / 86400) % 7; | ||
| int hours = (uptime / 3600) % 24; | ||
| int minutes = (uptime / 60) % 60; | ||
| int seconds = uptime % 60; | ||
|
|
||
| if (weeks != 0) | ||
| { | ||
| g_snprintf (buffer, sizeof(buffer), "%" G_GINT64_FORMAT "w %dd %dh %dm %ds", weeks, days, hours, minutes, seconds); | ||
| } | ||
| else if (days != 0) | ||
| { | ||
| g_snprintf (buffer, sizeof(buffer), "%dd %dh %dm %ds", days, hours, minutes, seconds); | ||
| } | ||
| else if (hours != 0) | ||
| { | ||
| g_snprintf (buffer, sizeof(buffer), "%dh %dm %ds", hours, minutes, seconds); | ||
| } | ||
| else if (minutes != 0) | ||
| { | ||
| g_snprintf (buffer, sizeof(buffer), "%dm %ds", minutes, seconds); | ||
| } | ||
| else | ||
| { | ||
| g_snprintf (buffer, sizeof(buffer), "%ds", seconds); | ||
| } | ||
|
|
||
| return g_strdup (buffer); | ||
| } | ||
|
|
||
| char * | ||
| sysinfo_format_memory (guint64 totalmem, guint64 freemem) | ||
| { | ||
| char *total_fmt, *free_fmt, *ret; | ||
|
|
||
| total_fmt = g_format_size_full (totalmem, G_FORMAT_SIZE_IEC_UNITS); | ||
| free_fmt = g_format_size_full (freemem, G_FORMAT_SIZE_IEC_UNITS); | ||
| ret = g_strdup_printf ("%s Total (%s Free)", total_fmt, free_fmt); | ||
|
|
||
| g_free (total_fmt); | ||
| g_free (free_fmt); | ||
| return ret; | ||
| } | ||
|
|
||
| char * | ||
| sysinfo_format_disk (guint64 total, guint64 free) | ||
| { | ||
| char *total_fmt, *free_fmt, *used_fmt, *ret; | ||
| GFormatSizeFlags format_flags = G_FORMAT_SIZE_DEFAULT; | ||
|
|
||
| #ifdef WIN32 /* Windows uses IEC size (with SI format) */ | ||
| format_flags = G_FORMAT_SIZE_IEC_UNITS; | ||
| #endif | ||
|
|
||
| total_fmt = g_format_size_full (total, format_flags); | ||
| free_fmt = g_format_size_full (free, format_flags); | ||
| used_fmt = g_format_size_full (total - free, format_flags); | ||
| ret = g_strdup_printf ("%s / %s (%s Free)", used_fmt, total_fmt, free_fmt); | ||
|
|
||
| g_free (total_fmt); | ||
| g_free (free_fmt); | ||
| g_free (used_fmt); | ||
| return ret; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,263 @@ | ||
| /* | ||
| * SysInfo - sysinfo plugin for HexChat | ||
| * Copyright (c) 2015 Patrick Griffis. | ||
| * | ||
| * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
| */ | ||
|
|
||
| /* | ||
| * Some snippets based upon Textual's System Profiler plugin. | ||
| * https://github.com/Codeux-Software/Textual | ||
| */ | ||
|
|
||
| #import <Cocoa/Cocoa.h> | ||
|
|
||
| #include <sys/sysctl.h> | ||
| #include <mach/mach.h> | ||
| #include <mach/mach_host.h> | ||
| #include <mach/host_info.h> | ||
| #include <mach/mach_vm.h> | ||
|
|
||
| #include <glib.h> | ||
|
|
||
| #include "format.h" | ||
| #include "df.h" | ||
|
|
||
| static char * | ||
| get_os (void) | ||
| { | ||
| NSDictionary *systemversion = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; | ||
| NSString *build = [systemversion objectForKey:@"ProductBuildVersion"]; | ||
| if (!build) | ||
| return NULL; | ||
| NSString *version = [systemversion objectForKey:@"ProductUserVisibleVersion"]; | ||
| if (!version) | ||
| { | ||
| [build release]; | ||
| return NULL; | ||
| } | ||
|
|
||
| NSDictionary *profiler = [NSDictionary dictionaryWithContentsOfFile:[@"~/Library/Preferences/com.apple.SystemProfiler.plist" stringByExpandingTildeInPath]]; | ||
| NSDictionary *names = [profiler objectForKey:@"OS Names"]; | ||
| NSString *os_name = nil; | ||
|
|
||
| for (NSString *name in names) | ||
| { | ||
| if ([name hasPrefix:build]) | ||
| { | ||
| os_name = [names objectForKey:name]; | ||
| break; | ||
| } | ||
| } | ||
| [build release]; | ||
|
|
||
| if (!os_name) | ||
| { | ||
| [version release]; | ||
| return NULL; | ||
| } | ||
|
|
||
| char *ret = g_strdup_printf ("%s %s", [os_name UTF8String], [version UTF8String]); | ||
| [version release]; | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| static char * | ||
| get_os_fallback (void) | ||
| { | ||
| NSProcessInfo *info = [NSProcessInfo processInfo]; | ||
| NSOperatingSystemVersion version = [info operatingSystemVersion]; | ||
|
|
||
| return g_strdup_printf ("OS X %ld.%ld.%ld", version.majorVersion, version.minorVersion, version.patchVersion); | ||
| } | ||
| char * | ||
| sysinfo_backend_get_os(void) | ||
| { | ||
| static char *os_str = NULL; | ||
| if (!os_str) | ||
| { | ||
| os_str = get_os(); | ||
| if (!os_str) | ||
| os_str = get_os_fallback(); | ||
| } | ||
| return g_strdup (os_str); | ||
| } | ||
|
|
||
| char * | ||
| sysinfo_backend_get_disk(void) | ||
| { | ||
| gint64 total, free_space; | ||
|
|
||
| if (xs_parse_df (&total, &free_space)) | ||
| { | ||
| return NULL; | ||
| } | ||
|
|
||
| return sysinfo_format_disk (total, free_space); | ||
| } | ||
|
|
||
| static guint64 | ||
| get_free_memory (void) | ||
| { | ||
| mach_msg_type_number_t infoCount = (sizeof(vm_statistics_data_t) / sizeof(natural_t)); | ||
|
|
||
| vm_size_t pagesize; | ||
| vm_statistics_data_t vm_stat; | ||
|
|
||
| host_page_size(mach_host_self(), &pagesize); | ||
|
|
||
| if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_stat, &infoCount) == KERN_SUCCESS) | ||
| return ((vm_stat.inactive_count + vm_stat.free_count) * pagesize); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| char * | ||
| sysinfo_backend_get_memory(void) | ||
| { | ||
| NSProcessInfo *info = [NSProcessInfo processInfo]; | ||
| guint64 totalmem, freemem; | ||
|
|
||
| totalmem = [info physicalMemory]; | ||
|
|
||
| if ((freemem = get_free_memory()) == 0) | ||
| return NULL; | ||
|
|
||
| return sysinfo_format_memory (totalmem, freemem); | ||
| } | ||
|
|
||
| char * | ||
| sysinfo_backend_get_cpu(void) | ||
| { | ||
| guint64 cpu_clock_uint = 0; | ||
| double cpu_clock; | ||
| char cpu_string[256]; | ||
| gsize len; | ||
| gboolean giga = FALSE; | ||
|
|
||
| len = sizeof(cpu_string); | ||
| if (sysctlbyname ("machdep.cpu.brand_string", cpu_string, &len, NULL, 0) != 0) | ||
| return NULL; | ||
| cpu_string[sizeof(cpu_string) - 1] = '\0'; | ||
|
|
||
| len = sizeof(cpu_clock_uint); | ||
| if (sysctlbyname("hw.cpufrequency", &cpu_clock_uint, &len, NULL, 0) < 0) | ||
| return NULL; | ||
|
|
||
| cpu_clock = cpu_clock_uint / 1000000; | ||
| if (cpu_clock > 1000) | ||
| { | ||
| cpu_clock /= 1000; | ||
| giga = TRUE; | ||
| } | ||
|
|
||
| if (giga) | ||
| return g_strdup_printf ("%s (%.2fGHz)", cpu_string, cpu_clock); | ||
| else | ||
| return g_strdup_printf ("%s (%.0fMHz)", cpu_string, cpu_clock); | ||
| } | ||
|
|
||
| static char * | ||
| get_gpu(void) | ||
| { | ||
| CFMutableDictionaryRef pciDevices = IOServiceMatching("IOPCIDevice"); | ||
| io_iterator_t entry_iterator, serviceObject; | ||
|
|
||
| if (IOServiceGetMatchingServices(kIOMasterPortDefault, pciDevices, &entry_iterator) != kIOReturnSuccess) | ||
| return NULL; | ||
|
|
||
| GString *gpu_list = g_string_new(NULL); | ||
| while ((serviceObject = IOIteratorNext(entry_iterator))) | ||
| { | ||
| CFMutableDictionaryRef serviceDictionary; | ||
|
|
||
| kern_return_t status = IORegistryEntryCreateCFProperties(serviceObject, &serviceDictionary, | ||
| kCFAllocatorDefault, kNilOptions); | ||
|
|
||
| if (status != kIOReturnSuccess) | ||
| { | ||
| IOObjectRelease(serviceObject); | ||
| continue; | ||
| } | ||
|
|
||
| const void *class = CFDictionaryGetValue(serviceDictionary, @"class-code"); | ||
| if (!class || *(guint32*)CFDataGetBytePtr(class) != 0x30000) /* DISPLAY_VGA */ | ||
| { | ||
| CFRelease(serviceDictionary); | ||
| continue; | ||
| } | ||
|
|
||
| const void *model = CFDictionaryGetValue(serviceDictionary, @"model"); | ||
| if (model) | ||
| { | ||
| if (CFGetTypeID(model) == CFDataGetTypeID() && CFDataGetLength(model) > 1) | ||
| { | ||
| if (gpu_list->len != 0) | ||
| g_string_append (gpu_list, ", "); | ||
| g_string_append_len (gpu_list, (const char*)CFDataGetBytePtr(model), CFDataGetLength(model) - 1); | ||
| } | ||
| } | ||
|
|
||
| CFRelease(serviceDictionary); | ||
| } | ||
|
|
||
| if (gpu_list->len == 0) | ||
| { | ||
| g_string_free (gpu_list, TRUE); | ||
| return NULL; | ||
| } | ||
|
|
||
| /* The string may contain nul-chars we must replace */ | ||
| int i; | ||
| for (i = 0; i < gpu_list->len; i++) | ||
| { | ||
| if (gpu_list->str[i] == '\0') | ||
| gpu_list->str[i] = ' '; | ||
| } | ||
|
|
||
| return g_string_free (gpu_list, FALSE); | ||
| } | ||
|
|
||
| char * | ||
| sysinfo_backend_get_gpu(void) | ||
| { | ||
| static char *gpu_str = NULL; | ||
| if (!gpu_str) | ||
| gpu_str = get_gpu(); | ||
|
|
||
| return g_strdup (gpu_str); | ||
| } | ||
|
|
||
| char * | ||
| sysinfo_backend_get_sound(void) | ||
| { | ||
| return NULL; | ||
| } | ||
|
|
||
| char * | ||
| sysinfo_backend_get_uptime(void) | ||
| { | ||
| NSProcessInfo *info = [NSProcessInfo processInfo]; | ||
| double uptime = [info systemUptime]; | ||
|
|
||
| return sysinfo_format_uptime ((gint64)uptime); | ||
| } | ||
|
|
||
| char * | ||
| sysinfo_backend_get_network(void) | ||
| { | ||
| return NULL; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
| */ | ||
|
|
||
| #include <stdlib.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <glib.h> | ||
|
|
||
| #include "sysinfo.h" | ||
|
|
||
| int xs_parse_df(gint64 *out_total, gint64 *out_free) | ||
| { | ||
| FILE *pipe; | ||
| char buffer[bsize]; | ||
|
|
||
| pipe = popen("df -k -l -P", "r"); | ||
| if(pipe==NULL) | ||
| return 1; | ||
|
|
||
| *out_total = *out_free = 0; | ||
|
|
||
| while(fgets(buffer, bsize, pipe) != NULL) | ||
| { | ||
| long long int avail, total; | ||
|
|
||
| /* Filesystem 1024-blocks Used Available Capacity Mounted-on */ | ||
| if (sscanf (buffer, "%*s %lld %*s %lld %*s %*s", &total, &avail) == 2) | ||
| { | ||
| *out_total += total; | ||
| *out_free += avail; | ||
| } | ||
| } | ||
|
|
||
| /* Convert to bytes */ | ||
| *out_total *= 1000; | ||
| *out_free *= 1000; | ||
|
|
||
| pclose(pipe); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * SysInfo - sysinfo plugin for HexChat | ||
| * Copyright (c) 2015 Patrick Griffis. | ||
| * | ||
| * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
| */ | ||
|
|
||
|
|
||
| #ifndef SYSINFO_BACKEND_H | ||
| #define SYSINFO_BACKEND_H | ||
|
|
||
| char *sysinfo_backend_get_os(void); | ||
| char *sysinfo_backend_get_disk(void); | ||
| char *sysinfo_backend_get_memory(void); | ||
| char *sysinfo_backend_get_cpu(void); | ||
| char *sysinfo_backend_get_gpu(void); | ||
| char *sysinfo_backend_get_sound(void); | ||
| char *sysinfo_backend_get_uptime(void); | ||
| char *sysinfo_backend_get_network(void); | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,277 @@ | ||
| /* | ||
| * SysInfo - sysinfo plugin for HexChat | ||
| * Copyright (c) 2012 Berke Viktor. | ||
| * | ||
| * xsys.c - main functions for X-Sys 2 | ||
| * by mikeshoup | ||
| * Copyright (C) 2003, 2004, 2005 Michael Shoup | ||
| * Copyright (C) 2005, 2006, 2007 Tony Vroon | ||
| * | ||
| * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
| */ | ||
|
|
||
| #include "config.h" | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <glib.h> | ||
|
|
||
| #include "hexchat-plugin.h" | ||
| #include "sysinfo-backend.h" | ||
| #include "sysinfo.h" | ||
|
|
||
| #define _(x) hexchat_gettext(ph,x) | ||
| #define DEFAULT_ANNOUNCE TRUE | ||
|
|
||
| static hexchat_plugin *ph; | ||
|
|
||
| static char name[] = "Sysinfo"; | ||
| static char desc[] = "Display info about your hardware and OS"; | ||
| static char version[] = "1.0"; | ||
| static char sysinfo_help[] = "SysInfo Usage:\n /SYSINFO [-e|-o] [CLIENT|OS|CPU|RAM|DISK|VGA|SOUND|ETHERNET|UPTIME], print various details about your system or print a summary without arguments\n /SYSINFO SET <variable>\n"; | ||
|
|
||
| typedef struct | ||
| { | ||
| const char *name; /* Lower case name used for prefs */ | ||
| const char *title; /* Used for the end formatting */ | ||
| char *(*callback) (void); | ||
| gboolean def; /* Hide by default? */ | ||
| } hwinfo; | ||
|
|
||
| static char * | ||
| get_client (void) | ||
| { | ||
| return g_strdup_printf ("HexChat %s", hexchat_get_info(ph, "version")); | ||
| } | ||
|
|
||
| static hwinfo hwinfos[] = { | ||
| {"client", "Client", get_client}, | ||
| {"os", "OS", sysinfo_backend_get_os}, | ||
| {"cpu", "CPU", sysinfo_backend_get_cpu}, | ||
| {"memory", "Memory", sysinfo_backend_get_memory}, | ||
| {"storage", "Storage", sysinfo_backend_get_disk}, | ||
| {"vga", "VGA", sysinfo_backend_get_gpu}, | ||
| {"sound", "Sound", sysinfo_backend_get_sound, TRUE}, | ||
| {"ethernet", "Ethernet", sysinfo_backend_get_network, TRUE}, | ||
| {"uptime", "Uptime", sysinfo_backend_get_uptime}, | ||
| {NULL, NULL}, | ||
| }; | ||
|
|
||
| static gboolean sysinfo_get_bool_pref (const char *pref, gboolean def); | ||
|
|
||
| static gboolean | ||
| should_show_info (hwinfo info) | ||
| { | ||
| char hide_pref[32]; | ||
|
|
||
| g_snprintf (hide_pref, sizeof(hide_pref), "hide_%s", info.name); | ||
| return !sysinfo_get_bool_pref (hide_pref, info.def); | ||
| } | ||
|
|
||
| static void | ||
| print_summary (gboolean announce) | ||
| { | ||
| char **strings = g_new0 (char*, G_N_ELEMENTS(hwinfos)); | ||
| int i, x; | ||
| char *output; | ||
|
|
||
| for (i = 0, x = 0; hwinfos[i].name != NULL; i++) | ||
| { | ||
| if (should_show_info (hwinfos[i])) | ||
| { | ||
| char *str = hwinfos[i].callback(); | ||
| if (str) | ||
| { | ||
| strings[x++] = g_strdup_printf ("\002%s\002: %s", hwinfos[i].title, str); | ||
| g_free (str); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| output = g_strjoinv (" \002\342\200\242\002 ", strings); | ||
| hexchat_commandf (ph, "%s %s", announce ? "SAY" : "ECHO", output); | ||
|
|
||
| g_strfreev (strings); | ||
| g_free (output); | ||
| } | ||
|
|
||
| static void | ||
| print_info (char *info, gboolean announce) | ||
| { | ||
| int i; | ||
|
|
||
| for (i = 0; hwinfos[i].name != NULL; i++) | ||
| { | ||
| if (!g_ascii_strcasecmp (info, hwinfos[i].name)) | ||
| { | ||
| char *str = hwinfos[i].callback(); | ||
| if (str) | ||
| { | ||
| hexchat_commandf (ph, "%s \002%s\002: %s", announce ? "SAY" : "ECHO", | ||
| hwinfos[i].title, str); | ||
| g_free (str); | ||
| } | ||
| else | ||
| hexchat_print (ph, _("Sysinfo: Failed to get info. Either not supported or error.")); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| hexchat_print (ph, _("Sysinfo: No info by that name\n")); | ||
| } | ||
|
|
||
| /* | ||
| * Simple wrapper for backend specific options. | ||
| * Ensure dest >= 512. | ||
| */ | ||
| int | ||
| sysinfo_get_str_pref (const char *pref, char *dest) | ||
| { | ||
| return hexchat_pluginpref_get_str (ph, pref, dest); | ||
| } | ||
|
|
||
| static gboolean | ||
| sysinfo_get_bool_pref (const char *pref, gboolean def) | ||
| { | ||
| int value = hexchat_pluginpref_get_int (ph, pref); | ||
|
|
||
| if (value != -1) | ||
| return value; | ||
|
|
||
| return def; | ||
| } | ||
|
|
||
| static void | ||
| sysinfo_set_pref_real (const char *pref, char *value, gboolean def) | ||
| { | ||
| if (value && value[0]) | ||
| { | ||
| guint64 i = g_ascii_strtoull (value, NULL, 0); | ||
| hexchat_pluginpref_set_int (ph, pref, i != 0); | ||
| hexchat_printf (ph, _("Sysinfo: %s is set to: %d\n"), pref, i != 0); | ||
| } | ||
| else | ||
| { | ||
| hexchat_printf (ph, _("Sysinfo: %s is set to: %d\n"), pref, | ||
| sysinfo_get_bool_pref(pref, def)); | ||
| } | ||
| } | ||
|
|
||
| static void | ||
| sysinfo_set_pref (char *key, char *value) | ||
| { | ||
| if (!key || !key[0]) | ||
| { | ||
| hexchat_print (ph, _("Sysinfo: Valid settings are: announce and hide_* for each piece of information. e.g. hide_os. Without a value it will show current (or default) setting.\n")); | ||
| return; | ||
| } | ||
|
|
||
| if (!strcmp (key, "announce")) | ||
| { | ||
| sysinfo_set_pref_real (key, value, DEFAULT_ANNOUNCE); | ||
| return; | ||
| } | ||
| #ifdef HAVE_LIBPCI | ||
| else if (!strcmp (key, "pciids")) | ||
| { | ||
| if (value && value[0]) | ||
| { | ||
| hexchat_pluginpref_set_str (ph, "pciids", value); | ||
| hexchat_printf (ph, _("Sysinfo: pciids is set to: %s\n"), value); | ||
| } | ||
| else | ||
| { | ||
| char buf[512]; | ||
| if (hexchat_pluginpref_get_str (ph, "pciids", buf) == 0) | ||
| strcpy (buf, DEFAULT_PCIIDS); | ||
| hexchat_printf (ph, _("Sysinfo: pciids is set to: %s\n"), buf); | ||
| } | ||
| return; | ||
| } | ||
| #endif | ||
| else if (g_str_has_prefix (key, "hide_")) | ||
| { | ||
| int i; | ||
| for (i = 0; hwinfos[i].name != NULL; i++) | ||
| { | ||
| if (!strcmp (key + 5, hwinfos[i].name)) | ||
| { | ||
| sysinfo_set_pref_real (key, value, hwinfos[i].def); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| hexchat_print (ph, _("Sysinfo: Invalid variable name\n")); | ||
| } | ||
|
|
||
| static int | ||
| sysinfo_cb (char *word[], char *word_eol[], void *userdata) | ||
| { | ||
| gboolean announce = sysinfo_get_bool_pref("announce", DEFAULT_ANNOUNCE); | ||
| int offset = 0, channel_type; | ||
| char *cmd; | ||
|
|
||
| /* Allow overriding global announce setting */ | ||
| if (!strcmp ("-e", word[2])) | ||
| { | ||
| announce = FALSE; | ||
| offset++; | ||
| } | ||
| else if (!strcmp ("-o", word[2])) | ||
| { | ||
| announce = TRUE; | ||
| offset++; | ||
| } | ||
|
|
||
| /* Cannot send to server tab */ | ||
| channel_type = hexchat_list_int (ph, NULL, "type"); | ||
| if (channel_type != 2 /* SESS_CHANNEL */ && channel_type != 3 /* SESS_DIALOG */) | ||
| announce = FALSE; | ||
|
|
||
| cmd = word[2+offset]; | ||
| if (!g_ascii_strcasecmp ("SET", cmd)) | ||
| sysinfo_set_pref (word[3+offset], word_eol[4+offset]); | ||
| else if (!cmd || !cmd[0]) | ||
| print_summary (announce); | ||
| else | ||
| print_info (cmd, announce); | ||
|
|
||
| return HEXCHAT_EAT_ALL; | ||
| } | ||
|
|
||
| int | ||
| hexchat_plugin_init (hexchat_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; | ||
|
|
||
| hexchat_hook_command (ph, "SYSINFO", HEXCHAT_PRI_NORM, sysinfo_cb, sysinfo_help, NULL); | ||
|
|
||
| hexchat_command (ph, "MENU ADD \"Window/Send System Info\" \"SYSINFO\""); | ||
| hexchat_printf (ph, _("%s plugin loaded\n"), name); | ||
| return 1; | ||
| } | ||
|
|
||
| int | ||
| hexchat_plugin_deinit (void) | ||
| { | ||
| hexchat_command (ph, "MENU DEL \"Window/Display System Info\""); | ||
| hexchat_printf (ph, _("%s plugin unloaded\n"), name); | ||
| return 1; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,170 @@ | ||
| /* | ||
| * SysInfo - sysinfo plugin for HexChat | ||
| * Copyright (c) 2015 Patrick Griffis. | ||
| * | ||
| * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
| */ | ||
|
|
||
| #include <glib.h> | ||
| #include "parse.h" | ||
| #include "match.h" | ||
| #include "sysinfo.h" | ||
| #include "format.h" | ||
| #include "df.h" | ||
|
|
||
| char *sysinfo_backend_get_os(void) | ||
| { | ||
| char name[bsize]; | ||
|
|
||
| if (xs_parse_distro (name) != 0) | ||
| { | ||
| return NULL; | ||
| } | ||
|
|
||
| return g_strdup(name); | ||
| } | ||
|
|
||
| char *sysinfo_backend_get_disk(void) | ||
| { | ||
| gint64 total, free; | ||
|
|
||
| if (xs_parse_df (&total, &free)) | ||
| { | ||
| return NULL; | ||
| } | ||
|
|
||
| return sysinfo_format_disk (total, free); | ||
| } | ||
|
|
||
| char *sysinfo_backend_get_memory(void) | ||
| { | ||
| unsigned long long mem_total; | ||
| unsigned long long mem_free; | ||
| unsigned long long swap_total; | ||
| unsigned long long swap_free; | ||
| char *swap_fmt = NULL, *mem_fmt, *ret; | ||
|
|
||
| if (xs_parse_meminfo (&mem_total, &mem_free, 0) == 1) | ||
| { | ||
| return NULL; | ||
| } | ||
| if (xs_parse_meminfo (&swap_total, &swap_free, 1) != 1) | ||
| { | ||
| swap_fmt = sysinfo_format_memory (swap_total, swap_free); | ||
| } | ||
|
|
||
| mem_fmt = sysinfo_format_memory (mem_total, mem_free); | ||
|
|
||
| if (swap_fmt) | ||
| { | ||
| ret = g_strdup_printf ("Physical: %s Swap: %s", mem_fmt, swap_fmt); | ||
| g_free (mem_fmt); | ||
| g_free (swap_fmt); | ||
| } | ||
| else | ||
| ret = mem_fmt; | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| char *sysinfo_backend_get_cpu(void) | ||
| { | ||
| char model[bsize]; | ||
| char vendor[bsize]; | ||
| char buffer[bsize]; | ||
| double freq; | ||
| int giga = 0; | ||
|
|
||
| if (xs_parse_cpu (model, vendor, &freq) != 0) | ||
| { | ||
| return NULL; | ||
| } | ||
|
|
||
| if (freq > 1000) | ||
| { | ||
| freq /= 1000; | ||
| giga = 1; | ||
| } | ||
|
|
||
| if (giga) | ||
| { | ||
| g_snprintf (buffer, bsize, "%s (%.2fGHz)", model, freq); | ||
| } | ||
| else | ||
| { | ||
| g_snprintf (buffer, bsize, "%s (%.0fMHz)", model, freq); | ||
| } | ||
|
|
||
| return g_strdup (buffer); | ||
| } | ||
|
|
||
| char *sysinfo_backend_get_gpu(void) | ||
| { | ||
| char vid_card[bsize]; | ||
| char agp_bridge[bsize]; | ||
| char buffer[bsize]; | ||
| int ret; | ||
|
|
||
| if ((ret = xs_parse_video (vid_card)) != 0) | ||
| { | ||
| return NULL; | ||
| } | ||
|
|
||
| if (xs_parse_agpbridge (agp_bridge) != 0) | ||
| { | ||
| g_snprintf (buffer, bsize, "%s", vid_card); | ||
| } | ||
| else | ||
| { | ||
| g_snprintf (buffer, bsize, "%s @ %s", vid_card, agp_bridge); | ||
| } | ||
|
|
||
| return g_strdup (buffer); | ||
| } | ||
|
|
||
| char *sysinfo_backend_get_sound(void) | ||
| { | ||
| char sound[bsize]; | ||
|
|
||
| if (xs_parse_sound (sound) != 0) | ||
| { | ||
| return NULL; | ||
| } | ||
| return g_strdup (sound); | ||
| } | ||
|
|
||
| char *sysinfo_backend_get_uptime(void) | ||
| { | ||
| gint64 uptime; | ||
|
|
||
| if ((uptime = xs_parse_uptime ()) == 0) | ||
| { | ||
| return NULL; | ||
| } | ||
|
|
||
| return sysinfo_format_uptime (uptime); | ||
| } | ||
|
|
||
| char *sysinfo_backend_get_network(void) | ||
| { | ||
| char ethernet_card[bsize]; | ||
|
|
||
| if (xs_parse_ether (ethernet_card)) | ||
| { | ||
| g_strlcpy (ethernet_card, "None found", bsize); | ||
| } | ||
|
|
||
| return g_strdup (ethernet_card); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * match.c - matching functions for X-Sys | ||
| * Copyright (C) 2005, 2006, 2007 Tony Vroon | ||
| * | ||
| * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
| */ | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <glib.h> | ||
| #include "sysinfo.h" | ||
|
|
||
| #define delims ":=" | ||
|
|
||
| void find_match_char(char *buffer, char *match, char *result) | ||
| { | ||
| char *position; | ||
| g_strchug(buffer); | ||
| if(strstr(buffer, match) == strstr(buffer, buffer)) | ||
| { | ||
| position = strpbrk(buffer, delims); | ||
| if (position != NULL) | ||
| { | ||
| position += 1; | ||
| strcpy(result, position); | ||
| position = strstr(result, "\n"); | ||
| *(position) = '\0'; | ||
| g_strchug(result); | ||
| } | ||
| else | ||
| strcpy(result, "\0"); | ||
| } | ||
| } | ||
|
|
||
| void find_match_double(char *buffer, char *match, double *result) | ||
| { | ||
| char *position; | ||
| g_strchug(buffer); | ||
| if(strstr(buffer, match) == strstr(buffer, buffer)) | ||
| { | ||
| position = strpbrk(buffer, delims); | ||
| if (position != NULL) | ||
| { | ||
| position += 1; | ||
| *result = strtod(position, NULL); | ||
| } | ||
| else | ||
| *result = 0; | ||
| } | ||
| } | ||
|
|
||
| void find_match_double_hex(char *buffer, char *match, double *result) | ||
| { | ||
| char *position; | ||
| g_strchug(buffer); | ||
| if(strstr(buffer, match) == strstr(buffer, buffer)) | ||
| { | ||
| position = strpbrk(buffer, delims); | ||
| if (position != NULL) | ||
| { | ||
| memcpy(position,"0x",2); | ||
| *result = strtod(position,NULL); | ||
| } | ||
| else | ||
| *result = 0; | ||
| } | ||
| } | ||
|
|
||
| void find_match_ll(char *buffer, char *match, unsigned long long *result) | ||
| { | ||
| char *position; | ||
| g_strchug(buffer); | ||
| if(strstr(buffer, match) == strstr(buffer, buffer)) | ||
| { | ||
| position = strpbrk(buffer, delims); | ||
| if (position != NULL) | ||
| { | ||
| position += 1; | ||
| *result = strtoll(position, NULL, 10); | ||
| } | ||
| else | ||
| *result = 0; | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,315 @@ | ||
| /* | ||
| * parse.c - parsing functions for X-Sys | ||
| * by mike9010 | ||
| * Copyright (C) 2003, 2004, 2005 Michael Shoup | ||
| * Copyright (C) 2005, 2006, 2007 Tony Vroon | ||
| * | ||
| * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
| */ | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <ctype.h> | ||
| #include <pci/header.h> | ||
| #include <glib.h> | ||
|
|
||
| #ifdef __sparc__ | ||
| #include <dirent.h> | ||
| #endif | ||
|
|
||
| #include "pci.h" | ||
| #include "match.h" | ||
| #include "parse.h" | ||
| #include "sysinfo.h" | ||
|
|
||
| int xs_parse_cpu(char *model, char *vendor, double *freq) | ||
| { | ||
| #if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || defined(__alpha__) || defined(__ia64__) || defined(__parisc__) || defined(__sparc__) | ||
| char buffer[bsize]; | ||
| #endif | ||
| FILE *fp; | ||
|
|
||
| fp = fopen("/proc/cpuinfo", "r"); | ||
| if(fp == NULL) | ||
| return 1; | ||
|
|
||
| #if defined(__i386__) || defined(__x86_64__) | ||
|
|
||
| while(fgets(buffer, bsize, fp) != NULL) | ||
| { | ||
| find_match_char(buffer, "model name", model); | ||
| find_match_char(buffer, "vendor_id", vendor); | ||
| find_match_double(buffer, "cpu MHz", freq); | ||
| } | ||
|
|
||
| #elif defined(__powerpc__) | ||
| { | ||
| char *pos; | ||
|
|
||
| while(fgets(buffer, bsize, fp) != NULL) | ||
| { | ||
| find_match_char(buffer, "cpu", model); | ||
| find_match_char(buffer, "machine", vendor); | ||
| find_match_double(buffer, "clock", freq); | ||
| } | ||
| pos = strstr(model, ","); | ||
| if (pos != NULL) | ||
| *pos = '\0'; | ||
| } | ||
| #elif defined( __alpha__) | ||
|
|
||
| while(fgets(buffer, bsize, fp) != NULL) | ||
| { | ||
| find_match_char(buffer, "cpu model", model); | ||
| find_match_char(buffer, "system type", vendor); | ||
| find_match_double(buffer, "cycle frequency [Hz]", freq); | ||
| } | ||
| *freq = *freq / 1000000; | ||
|
|
||
| #elif defined(__ia64__) | ||
|
|
||
| while(fgets(buffer, bsize, fp) != NULL) | ||
| { | ||
| find_match_char(buffer, "model", model); | ||
| find_match_char(buffer, "vendor", vendor); | ||
| find_match_double(buffer, "cpu MHz", freq); | ||
| } | ||
|
|
||
| #elif defined(__parisc__) | ||
|
|
||
| while(fgets(buffer, bsize, fp) != NULL) | ||
| { | ||
| find_match_char(buffer, "cpu ", model); | ||
| find_match_char(buffer, "cpu family", vendor); | ||
| find_match_double(buffer, "cpu MHz", freq); | ||
| } | ||
|
|
||
| #elif defined(__sparc__) | ||
| { | ||
| DIR *dir; | ||
| struct dirent *entry; | ||
| FILE *fp2; | ||
|
|
||
| while(fgets(buffer, bsize, fp) != NULL) | ||
| { | ||
| find_match_char(buffer, "cpu ", model); | ||
| find_match_char(buffer, "type ", vendor); | ||
| find_match_double_hex(buffer, "Cpu0ClkTck", freq); | ||
| } | ||
| *freq = *freq / 1000000; | ||
| } | ||
| #else | ||
|
|
||
| fclose(fp); | ||
| return 1; /* Unsupported */ | ||
|
|
||
| #endif | ||
|
|
||
| fclose(fp); | ||
| return 0; | ||
| } | ||
|
|
||
| gint64 xs_parse_uptime(void) | ||
| { | ||
| char buffer[bsize]; | ||
| gint64 uptime = 0; | ||
| FILE *fp = fopen("/proc/uptime", "r"); | ||
| if(fp == NULL) | ||
| return 0; | ||
|
|
||
| if(fgets(buffer, bsize, fp) != NULL) | ||
| uptime = g_ascii_strtoll(buffer, NULL, 0); | ||
|
|
||
| fclose(fp); | ||
|
|
||
| return uptime; | ||
| } | ||
|
|
||
| int xs_parse_sound(char *snd_card) | ||
| { | ||
| char buffer[bsize], cards[bsize] = "\0", vendor[7] = "\0", device[7] = "\0", *pos; | ||
| u16 class = PCI_CLASS_MULTIMEDIA_AUDIO; | ||
|
|
||
| FILE *fp = NULL; | ||
| if((fp = fopen("/proc/asound/cards", "r"))== NULL) | ||
| { | ||
| if (pci_find_by_class(&class, vendor, device) == 0) | ||
| { | ||
| pci_find_fullname(snd_card, vendor, device); | ||
| return 0; | ||
| } | ||
| else | ||
| return 1; | ||
| } | ||
|
|
||
|
|
||
| while(fgets(buffer, bsize, fp) != NULL) | ||
| { | ||
| if(isdigit(buffer[0]) || isdigit(buffer[1])) | ||
| { | ||
| char card_buf[bsize]; | ||
| gint64 card_id = 0; | ||
| pos = strstr(buffer, ":"); | ||
| card_id = g_ascii_strtoll(buffer, NULL, 0); | ||
| if (card_id == 0) | ||
| g_snprintf(card_buf, bsize, "%s", pos+2); | ||
| else | ||
| g_snprintf(card_buf, bsize, "%"G_GINT64_FORMAT": %s", card_id, pos+2); | ||
| pos = strstr(card_buf, "\n"); | ||
| *pos = '\0'; | ||
| strcat(cards, card_buf); | ||
| } | ||
| } | ||
|
|
||
| strcpy(snd_card, cards); | ||
|
|
||
| fclose(fp); | ||
| return 0; | ||
| } | ||
|
|
||
| int xs_parse_video(char *vid_card) | ||
| { | ||
| char vendor[7] = "\0", device[7] = "\0"; | ||
| u16 class = PCI_CLASS_DISPLAY_VGA; | ||
| if (pci_find_by_class(&class, vendor, device)) | ||
| return 1; | ||
| else | ||
| pci_find_fullname(vid_card, vendor, device); | ||
| return 0; | ||
| } | ||
|
|
||
| int xs_parse_ether(char *ethernet_card) | ||
| { | ||
| char vendor[7] = "\0", device[7] = "\0"; | ||
| u16 class = PCI_CLASS_NETWORK_ETHERNET; | ||
| if (pci_find_by_class(&class, vendor, device)) | ||
| return 1; | ||
| else | ||
| pci_find_fullname(ethernet_card, vendor, device); | ||
| return 0; | ||
| } | ||
|
|
||
| int xs_parse_agpbridge(char *agp_bridge) | ||
| { | ||
| char vendor[7] = "\0", device[7] = "\0"; | ||
| u16 class = PCI_CLASS_BRIDGE_HOST; | ||
| if (pci_find_by_class(&class, vendor, device)) | ||
| return 1; | ||
| else | ||
| pci_find_fullname(agp_bridge, vendor, device); | ||
| return 0; | ||
| } | ||
|
|
||
| int xs_parse_meminfo(unsigned long long *mem_tot, unsigned long long *mem_free, int swap) | ||
| { | ||
| FILE *fp; | ||
| char buffer[bsize]; | ||
| unsigned long long freemem = 0, buffers = 0, cache = 0; | ||
| *mem_tot = 0; | ||
| *mem_free = 0; | ||
|
|
||
| if((fp = fopen("/proc/meminfo", "r")) == NULL) | ||
| return 1; | ||
|
|
||
| while(fgets(buffer, bsize, fp) != NULL) | ||
| { | ||
| if(!swap) | ||
| { | ||
| find_match_ll(buffer, "MemTotal:", mem_tot); | ||
| find_match_ll(buffer, "MemFree:", &freemem); | ||
| find_match_ll(buffer, "Buffers:", &buffers); | ||
| find_match_ll(buffer, "Cached:", &cache); | ||
| } | ||
| else | ||
| { | ||
| find_match_ll(buffer, "SwapTotal:", mem_tot); | ||
| find_match_ll(buffer, "SwapFree:", mem_free); | ||
| } | ||
| } | ||
| if (!swap) | ||
| { | ||
| *mem_free = freemem + buffers + cache; | ||
| } | ||
| fclose(fp); | ||
|
|
||
| /* Convert to bytes */ | ||
| *mem_free *= 1000; | ||
| *mem_tot *= 1000; | ||
| return 0; | ||
| } | ||
|
|
||
| int xs_parse_distro(char *name) | ||
| { | ||
| FILE *fp = NULL; | ||
| char buffer[bsize], *pos = NULL; | ||
|
|
||
| if((fp = fopen("/etc/portage/make.conf", "r")) != NULL || | ||
| (fp = fopen("/etc/make.conf", "r")) != NULL) | ||
| { | ||
| char keywords[bsize]; | ||
| while(fgets(buffer, bsize, fp) != NULL) | ||
| find_match_char(buffer, "ACCEPT_KEYWORDS", keywords); | ||
| /* cppcheck-suppress uninitvar */ | ||
| if (strstr(keywords, "\"") == NULL) | ||
| g_snprintf(buffer, bsize, "Gentoo Linux (stable)"); | ||
| else | ||
| g_snprintf(buffer, bsize, "Gentoo Linux %s", keywords); | ||
| } | ||
| else if((fp = fopen("/etc/redhat-release", "r")) != NULL) | ||
| fgets(buffer, bsize, fp); | ||
| else if((fp = fopen("/etc/mageia-release", "r")) != NULL) | ||
| fgets(buffer, bsize, fp); | ||
| else if((fp = fopen("/etc/slackware-version", "r")) != NULL) | ||
| fgets(buffer, bsize, fp); | ||
| else if((fp = fopen("/etc/mandrake-release", "r")) != NULL) | ||
| fgets(buffer, bsize, fp); | ||
| else if((fp = fopen("/etc/SuSE-release", "r")) != NULL) | ||
| fgets(buffer, bsize, fp); | ||
| else if((fp = fopen("/etc/turbolinux-release", "r")) != NULL) | ||
| fgets(buffer, bsize, fp); | ||
| else if((fp = fopen("/etc/arch-release", "r")) != NULL) | ||
| g_snprintf(buffer, bsize, "ArchLinux"); | ||
| else if((fp = fopen("/etc/lsb-release", "r")) != NULL) | ||
| { | ||
| char id[bsize], codename[bsize], release[bsize]; | ||
| strcpy(id, "?"); | ||
| strcpy(codename, "?"); | ||
| strcpy(release, "?"); | ||
| while(fgets(buffer, bsize, fp) != NULL) | ||
| { | ||
| find_match_char(buffer, "DISTRIB_ID", id); | ||
| find_match_char(buffer, "DISTRIB_CODENAME", codename); | ||
| find_match_char(buffer, "DISTRIB_RELEASE", release); | ||
| } | ||
| g_snprintf(buffer, bsize, "%s \"%s\" %s", id, codename, release); | ||
| } | ||
| else if((fp = fopen("/etc/debian_version", "r")) != NULL) | ||
| { | ||
| char release[bsize]; | ||
| fgets(release, bsize, fp); | ||
| g_snprintf(buffer, bsize, "Debian %s", release); | ||
| } | ||
| else | ||
| g_snprintf(buffer, bsize, "Unknown Distro"); | ||
| if(fp != NULL) | ||
| fclose(fp); | ||
|
|
||
| pos=strchr(buffer, '\n'); | ||
| if(pos != NULL) | ||
| *pos = '\0'; | ||
| strcpy(name, buffer); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| /* | ||
| * pci.c - PCI functions for X-Sys | ||
| * Copyright (C) 1997-1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz> [PCI routines from lspci] | ||
| * Copyright (C) 2000 Tom Rini <trini@kernel.crashing.org> [XorgAutoConfig pci.c, based on lspci] | ||
| * Copyright (C) 2005, 2006 Tony Vroon | ||
| * | ||
| * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA | ||
| */ | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <ctype.h> | ||
| #include <pci/pci.h> | ||
| #include <glib.h> | ||
|
|
||
| #include "sysinfo.h" | ||
|
|
||
| static struct pci_filter filter; /* Device filter */ | ||
| static struct pci_access *pacc; | ||
| int bus, dev, func; /* Location of the card */ | ||
|
|
||
| struct device { | ||
| struct device *next; | ||
| struct pci_dev *dev; | ||
| unsigned int config_cnt; | ||
| u8 config[256]; | ||
| }; | ||
|
|
||
| static struct device *first_dev; | ||
|
|
||
| static struct device *scan_device(struct pci_dev *p) | ||
| { | ||
| int how_much = 64; | ||
| struct device *d; | ||
|
|
||
| if (!pci_filter_match(&filter, p)) | ||
| return NULL; | ||
| d = g_new0 (struct device, 1); | ||
| d->dev = p; | ||
| if (!pci_read_block(p, 0, d->config, how_much)) | ||
| exit(1); | ||
| if (how_much < 128 && (d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS) | ||
| { | ||
| /* For cardbus bridges, we need to fetch 64 bytes more to get the full standard header... */ | ||
| if (!pci_read_block(p, 64, d->config+64, 64)) | ||
| exit(1); | ||
| how_much = 128; | ||
| } | ||
| d->config_cnt = how_much; | ||
| pci_setup_cache(p, d->config, d->config_cnt); | ||
| pci_fill_info(p, PCI_FILL_IDENT); | ||
| return d; | ||
| } | ||
|
|
||
| static void scan_devices(void) | ||
| { | ||
| struct device *d; | ||
| struct pci_dev *p; | ||
|
|
||
| pci_scan_bus(pacc); | ||
| for(p=pacc->devices; p; p=p->next) | ||
| { | ||
| if ((d = scan_device(p))) | ||
| { | ||
| d->next = first_dev; | ||
| first_dev = d; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static u16 get_conf_word(struct device *d, unsigned int pos) | ||
| { | ||
| return d->config[pos] | (d->config[pos+1] << 8); | ||
| } | ||
|
|
||
| int pci_find_by_class(u16 *class, char *vendor, char *device) | ||
| { | ||
| struct device *d; | ||
| struct pci_dev *p; | ||
| int nomatch = 1; | ||
|
|
||
| pacc = pci_alloc(); | ||
| pci_filter_init(pacc, &filter); | ||
| pci_init(pacc); | ||
| scan_devices(); | ||
|
|
||
| for(d=first_dev; d; d=d->next) | ||
| { | ||
| p = d->dev; | ||
| /* Acquire vendor & device ID if the class matches */ | ||
| if(get_conf_word(d, PCI_CLASS_DEVICE) == *class) | ||
| { | ||
| nomatch = 0; | ||
| g_snprintf(vendor,7,"%04x",p->vendor_id); | ||
| g_snprintf(device,7,"%04x",p->device_id); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| pci_cleanup(pacc); | ||
| return nomatch; | ||
| } | ||
|
|
||
| void pci_find_fullname(char *fullname, char *vendor, char *device) | ||
| { | ||
| char buffer[bsize]; | ||
| char vendorname[bsize/2] = ""; | ||
| char devicename[bsize/2] = ""; | ||
| char *position; | ||
| int cardfound = 0; | ||
| FILE *fp; | ||
|
|
||
| if (!sysinfo_get_str_pref ("pciids", buffer)) | ||
| strcpy (buffer, DEFAULT_PCIIDS); | ||
|
|
||
| fp = fopen (buffer, "r"); | ||
| if(fp == NULL) | ||
| { | ||
| g_snprintf(fullname, bsize, "%s:%s", vendor, device); | ||
| //sysinfo_print_error ("pci.ids file not found! You might want to adjust your pciids setting with /SYSINFO SET pciids (you can query its current value with /SYSINFO LIST).\n"); | ||
| return; | ||
| } | ||
|
|
||
| while(fgets(buffer, bsize, fp) != NULL) | ||
| { | ||
| if (!isspace(buffer[0]) && strstr(buffer, vendor) != NULL) | ||
| { | ||
| position = strstr(buffer, vendor); | ||
| position += 6; | ||
| strncpy(vendorname, position, bsize/2); | ||
| position = strstr(vendorname, "\n"); | ||
| *(position) = '\0'; | ||
| break; | ||
| } | ||
| } | ||
| while(fgets(buffer, bsize, fp) != NULL) | ||
| { | ||
| if(strstr(buffer, device) != NULL) | ||
| { | ||
| position = strstr(buffer, device); | ||
| position += 6; | ||
| strncpy(devicename, position, bsize/2); | ||
| position = strstr(devicename, " ("); | ||
| if (position == NULL) | ||
| position = strstr(devicename, "\n"); | ||
| *(position) = '\0'; | ||
| cardfound = 1; | ||
| break; | ||
| } | ||
| } | ||
| if (cardfound == 1) | ||
| g_snprintf(fullname, bsize, "%s %s", vendorname, devicename); | ||
| else | ||
| g_snprintf(fullname, bsize, "%s:%s", vendor, device); | ||
| fclose(fp); | ||
| } |