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; }
static int print_ram (int announce, char* format) { unsigned long long mem_total; unsigned long long mem_free; unsigned long long swap_total; unsigned long long swap_free; char string[bsize]; if (xs_parse_meminfo (&mem_total, &mem_free, 0) == 1) { hexchat_printf (ph, "%s\tERROR in parse_meminfo!", name); return HEXCHAT_EAT_ALL; } if (xs_parse_meminfo (&swap_total, &swap_free, 1) == 1) { hexchat_printf (ph, "%s\tERROR in parse_meminfo!", name); return HEXCHAT_EAT_ALL; } snprintf (string, bsize, "%s - %s", pretty_freespace ("Physical", &mem_free, &mem_total), pretty_freespace ("Swap", &swap_free, &swap_total)); format_output ("RAM", string, format); if (announce) { hexchat_commandf (ph, "SAY %s", string); } else { hexchat_printf (ph, "%s", string); } return HEXCHAT_EAT_ALL; }
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]; 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, "%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) { hexchat_printf (ph, "%s\tERROR in parse_meminfo!", name); return HEXCHAT_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)) { 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; }