/* * 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 #include #include #include #include "hexchat-plugin.h" #include "parse.h" #include "match.h" #include "xsys.h" #define DEFAULT_FORMAT "%B%1:%B %2 **" #define DEFAULT_PERCENT 1 #define DEFAULT_ANNOUNCE 1 #define DEFAULT_PCIIDS "/usr/share/hwdata/pci.ids" static hexchat_plugin *ph; /* plugin handle */ static int error_printed = 0; /* semaphore, make sure not to print the same error more than once during one execution */ static char name[] = "SysInfo"; static char desc[] = "Display info about your hardware and OS"; static char version[] = "3.0"; static char sysinfo_help[] = "SysInfo Usage:\n /SYSINFO [-e|-o] [OS|DISTRO|CPU|RAM|DISK|VGA|SOUND|ETHERNET|UPTIME], print various details about your system or print a summary without arguments\n /SYSINFO LIST, print current settings\n /SYSINFO SET , update given setting\n /SYSINFO RESET, reset settings to defaults\n /NETDATA , show transmitted data on given interface\n /NETSTREAM , show current bandwidth on given interface\n"; void sysinfo_get_pciids (char* dest) { hexchat_pluginpref_get_str (ph, "pciids", dest); } int sysinfo_get_percent () { return hexchat_pluginpref_get_int (ph, "percent"); } int sysinfo_get_announce () { return hexchat_pluginpref_get_int (ph, "announce"); } void sysinfo_print_error (const char* msg) { if (!error_printed) { hexchat_printf (ph, "%s\t%s", name, msg); } error_printed++; } static int print_summary (int announce, char* format) { 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 *free_space; unsigned long long mem_total; unsigned long long mem_free; unsigned int count; double cpu_freq; int giga = 0; int weeks; int days; int hours; int minutes; int seconds; sysinfo[0] = '\0'; snprintf (buffer, bsize, "%s", hexchat_get_info (ph, "version")); format_output ("HexChat", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); /* BEGIN OS PARSING */ if (xs_parse_os (os_user, os_host, os_kernel) != 0) { hexchat_printf (ph, "%s\tERROR in parse_os()", name); return HEXCHAT_EAT_ALL; } snprintf (buffer, bsize, "%s", os_kernel); format_output ("OS", buffer, format); strcat (sysinfo, "\017 "); 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) { hexchat_printf (ph, "%s\tERROR in parse_cpu()", name); return HEXCHAT_EAT_ALL; } if (cpu_freq > 1000) { cpu_freq /= 1000; giga = 1; } if (giga) { snprintf (buffer, bsize, "%u x %s (%s) @ %.2fGHz", count, cpu_model, cpu_vendor, cpu_freq); } else { snprintf (buffer, bsize, "%u 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) { hexchat_printf (ph, "%s\tERROR in parse_meminfo!", name); return HEXCHAT_EAT_ALL; } free_space = pretty_freespace ("Physical", &mem_free, &mem_total); snprintf (buffer, bsize, "%s", free_space); free (free_space); format_output ("RAM", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); /* BEGIN DISK PARSING */ if (xs_parse_df (NULL, buffer)) { hexchat_printf (ph, "%s\tERROR in parse_df", name); return HEXCHAT_EAT_ALL; } format_output ("Disk", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); /* BEGIN VIDEO PARSING */ if (xs_parse_video (buffer)) { hexchat_printf (ph, "%s\tERROR in parse_video", name); return HEXCHAT_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)); /* BEGIN ETHERNET PARSING */ if (xs_parse_ether (buffer)) { strncpy (buffer, "None found", bsize); } format_output ("Ethernet", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); /* BEGIN UPTIME PARSING */ if (xs_parse_uptime (&weeks, &days, &hours, &minutes, &seconds)) { hexchat_printf (ph, "%s\tERROR in parse_uptime()", name); return HEXCHAT_EAT_ALL; } if (minutes != 0 || hours != 0 || days != 0 || weeks != 0) { if (hours != 0 || days != 0 || weeks != 0) { if (days !=0 || weeks != 0) { if (weeks != 0) { snprintf (buffer, bsize, "%dw %dd %dh %dm %ds", weeks, days, hours, minutes, seconds); } else { snprintf (buffer, bsize, "%dd %dh %dm %ds", days, hours, minutes, seconds); } } else { snprintf (buffer, bsize, "%dh %dm %ds", hours, minutes, seconds); } } else { snprintf (buffer, bsize, "%dm %ds", minutes, seconds); } } format_output ("Uptime", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); if (announce) { hexchat_commandf (ph, "SAY %s", sysinfo); } else { hexchat_printf (ph, "%s", sysinfo); } return HEXCHAT_EAT_ALL; } static int print_os (int announce, char* format) { char buffer[bsize]; char user[bsize]; char host[bsize]; char kernel[bsize]; if (xs_parse_os (user, host, kernel) != 0) { hexchat_printf (ph, "%s\tERROR in parse_os()", name); return HEXCHAT_EAT_ALL; } snprintf (buffer, bsize, "%s@%s, %s", user, h
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{3786FA8C-3E76-45E3-984E-FCCFF44729C9}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>dns</RootNamespace>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>MultiByte</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>MultiByte</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    <Import Project="..\..\win32\hexchat.props" />
  </ImportGroup>
  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    <Import Project="..\..\win32\hexchat.props" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
    <TargetName>hcdns</TargetName>
    <OutDir>$(HexChatBin)</OutDir>
    <IntDir>$(HexChatObj)$(ProjectName)\</IntDir>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
    <TargetName>hcdns</TargetName>
    <OutDir>$(HexChatBin)</OutDir>
    <IntDir>$(HexChatObj)$(ProjectName)\</IntDir>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;DNS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>..\..\src\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <MultiProcessorCompilation>true</MultiProcessorCompilation>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <AdditionalLibraryDirectories>$(DepsRoot)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
      <AdditionalDependencies>$(DepLibs);%(AdditionalDependencies)</AdditionalDependencies>
      <ModuleDefinitionFile>dns.def</ModuleDefinitionFile>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;_WIN64;_AMD64_;NDEBUG;_WINDOWS;_USRDLL;DNS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>..\..\src\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <MultiProcessorCompilation>true</MultiProcessorCompilation>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <AdditionalLibraryDirectories>$(DepsRoot)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
      <AdditionalDependencies>$(DepLibs);%(AdditionalDependencies)</AdditionalDependencies>
      <ModuleDefinitionFile>dns.def</ModuleDefinitionFile>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <None Include="dns.def" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="dns.c" />
    <ClCompile Include="thread.c" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="thread.h" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>
plugin_desc = desc; *plugin_version = version; hexchat_hook_command (ph, "SYSINFO", HEXCHAT_PRI_NORM, sysinfo_cb, sysinfo_help, NULL); hexchat_hook_command (ph, "NETDATA", HEXCHAT_PRI_NORM, netdata_cb, NULL, NULL); hexchat_hook_command (ph, "NETSTREAM", HEXCHAT_PRI_NORM, netstream_cb, NULL, NULL); /* this is required for the very first run */ if (hexchat_pluginpref_get_str (ph, "pciids", buffer) == 0) { hexchat_pluginpref_set_str (ph, "pciids", DEFAULT_PCIIDS); } if (hexchat_pluginpref_get_str (ph, "format", buffer) == 0) { hexchat_pluginpref_set_str (ph, "format", DEFAULT_FORMAT); } if (hexchat_pluginpref_get_int (ph, "percent") == -1) { hexchat_pluginpref_set_int (ph, "percent", DEFAULT_PERCENT); } if (hexchat_pluginpref_get_int (ph, "announce") == -1) { hexchat_pluginpref_set_int (ph, "announce", DEFAULT_ANNOUNCE); } 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; }