diff options
46 files changed, 3268 insertions, 3106 deletions
diff --git a/Makefile.in b/Makefile.in index 6acd957a..cc713aab 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,7 +1,7 @@ -CC = gcc -O3 $(ARCHOPTS) -CCSLOW = gcc -O0 -CFLAGS = -fPIC -pipe -Wall -g $(GTK_CFLAGS) $(GLADE_CFLAGS) $(SOUP_CFLAGS) -I. +CC = gcc $(ARCHOPTS) +CCSLOW = gcc -O0 +CFLAGS = -fPIC -pipe -Wall $(GTK_CFLAGS) $(GLADE_CFLAGS) $(SOUP_CFLAGS) -I. # ---------------------------------------------------------------------------- diff --git a/arch/common/display.h b/arch/common/display.h index b4fe643e..d7cf2ae6 100644 --- a/arch/common/display.h +++ b/arch/common/display.h @@ -82,10 +82,10 @@ get_x11_info(DisplayInfo *di) if (g_str_has_prefix(tmp[0], "number of extensions")) { int n; - di->extensions = ""; + di->extensions = g_strdup(""); for (n = atoi(tmp[1]); n; n--) { - di->extensions = g_strconcat(di->extensions, + di->extensions = h_strconcat(di->extensions, g_strstrip(*(++output_lines)), "=\n", NULL); @@ -108,14 +108,14 @@ get_x11_info(DisplayInfo *di) gint n_monitors = gdk_screen_get_n_monitors(screen); gint i; - di->monitors = ""; + di->monitors = NULL; for (i = 0; i < n_monitors; i++) { GdkRectangle rect; gdk_screen_get_monitor_geometry(screen, i, &rect); - di->monitors = g_strdup_printf("%sMonitor %d=%dx%d pixels\n", - di->monitors, i, rect.width, rect.height); + di->monitors = h_strdup_cprintf("Monitor %d=%dx%d pixels\n", + di->monitors, i, rect.width, rect.height); } } else { di->monitors = ""; diff --git a/arch/common/languages.h b/arch/common/languages.h index 786b829f..efc100fb 100644 --- a/arch/common/languages.h +++ b/arch/common/languages.h @@ -20,7 +20,7 @@ void scan_languages(OperatingSystem * os) { FILE *locale; - gchar buf[512], *retval = ""; + gchar buf[512], *retval = NULL; locale = popen("locale -va", "r"); if (!locale) @@ -64,7 +64,7 @@ scan_languages(OperatingSystem * os) } else { gchar *currlocale; - retval = g_strdup_printf("%s$%s$%s=%s\n", retval, name, name, title); + retval = h_strdup_cprintf("$%s$%s=%s\n", retval, name, name, title); #define FIELD(f) f ? f : "(Unknown)" currlocale = g_strdup_printf("[Locale Information]\n" diff --git a/arch/common/printers.h b/arch/common/printers.h index 3daf28e6..43ddda0a 100644 --- a/arch/common/printers.h +++ b/arch/common/printers.h @@ -70,12 +70,16 @@ __scan_printers(void) if (noprinters > 0) { printer_list = g_strdup_printf("[Printers (CUPS)]\n"); for (i = 0; i < noprinters; i++) { - printer_list = g_strconcat(printer_list, printers[i], - g_str_equal(default_printer, printers[i]) ? - "=<i>(Default)</i>\n" : "=\n", - NULL); + printer_list = h_strdup_cprintf("\n$PRN%d$%s=%s\n", + printer_list, + i, + printers[i], + g_str_equal(default_printer, printers[i]) ? + "<i>(Default)</i>" : ""); g_free(printers[i]); } + + g_free(printers); } else { printer_list = g_strdup("[Printers]\n" "No printers found=\n"); diff --git a/arch/common/users.h b/arch/common/users.h index 84cec9d9..fd8f7834 100644 --- a/arch/common/users.h +++ b/arch/common/users.h @@ -4,14 +4,7 @@ static gchar *sys_users = NULL, static gboolean remove_users(gpointer key, gpointer value, gpointer data) { - if (!strncmp((gchar *) key, "USER", 4)) { - /* - * g_free((gchar *) key); - * g_free((GtkTreeIter *) value); - */ - return TRUE; - } - return FALSE; + return g_str_has_prefix(key, "USER"); } static void @@ -52,9 +45,9 @@ scan_users_do(void) uid = atoi(tmp[2]); strend(tmp[4], ','); if (uid >= 1000 && uid <= 65530) { - human_users = g_strdup_printf("%s$%s$%s=%s\n", human_users, key, tmp[0], tmp[4]); + human_users = h_strdup_cprintf("$%s$%s=%s\n", human_users, key, tmp[0], tmp[4]); } else { - sys_users = g_strdup_printf("%s$%s$%s=%s\n", sys_users, key, tmp[0], tmp[4]); + sys_users = h_strdup_cprintf("$%s$%s=%s\n", sys_users, key, tmp[0], tmp[4]); } g_strfreev(tmp); diff --git a/arch/linux/common/battery.h b/arch/linux/common/battery.h index 20979e48..4a38b842 100644 --- a/arch/linux/common/battery.h +++ b/arch/linux/common/battery.h @@ -92,7 +92,7 @@ __scan_battery_acpi(void) if (g_str_equal(present, "yes")) { charge_rate = atof(remaining) / atof(capacity); - battery_list = g_strdup_printf("%s\n[Battery: %s]\n" + battery_list = h_strdup_cprintf("\n[Battery: %s]\n" "State=%s (load: %s)\n" "Capacity=%s / %s (%.2f%%)\n" "Battery Technology=%s (%s)\n" @@ -174,7 +174,7 @@ __scan_battery_apm(void) } if (stotal && sremaining) { - battery_list = g_strdup_printf("%s\n[Battery (APM)]\n" + battery_list = h_strdup_cprintf("\n[Battery (APM)]\n" "Charge=%d%%\n" "Remaining Charge=%s of %s\n" "Using=%s\n" @@ -186,7 +186,7 @@ __scan_battery_apm(void) ac_status[ac_bat], apm_drv_ver, apm_bios_ver); } else { - battery_list = g_strdup_printf("%s\n[Battery (APM)]\n" + battery_list = h_strdup_cprintf("\n[Battery (APM)]\n" "Charge=%d%%\n" "Using=%s\n" "APM driver version=%s\n" @@ -209,4 +209,11 @@ __scan_battery(void) __scan_battery_acpi(); __scan_battery_apm(); + + if (*battery_list == '\0') { + g_free(battery_list); + + battery_list = g_strdup("[No batteries]\n" + "No batteries found on this system=\n"); + } } diff --git a/arch/linux/common/boots.h b/arch/linux/common/boots.h index c95ba321..d3428ea9 100644 --- a/arch/linux/common/boots.h +++ b/arch/linux/common/boots.h @@ -25,7 +25,7 @@ scan_boots_real(void) scan_os(FALSE); if (!computer->os->boots) - computer->os->boots = "[Boots]\n"; + computer->os->boots = g_strdup("[Boots]\n"); else return; @@ -48,7 +48,7 @@ scan_boots_real(void) } tmp = g_strsplit(buffer, " ", 5); - computer->os->boots = g_strdup_printf("%s\n%s=Kernel %s", + computer->os->boots = h_strdup_cprintf("\n%s=Kernel %s", computer->os->boots, tmp[4], tmp[3]); diff --git a/arch/linux/common/devmemory.h b/arch/linux/common/devmemory.h index 780ab12f..5eafe599 100644 --- a/arch/linux/common/devmemory.h +++ b/arch/linux/common/devmemory.h @@ -27,8 +27,9 @@ static void __scan_memory() if (offset == -1) { /* gah. linux 2.4 adds three lines of data we don't need in /proc/meminfo */ - offset = strstr(idle_free(module_call_method("computer::getOSKernel")), - "Linux 2.4") ? 3 : 0; + gchar *os_kernel = module_call_method("computer::getOSKernel"); + offset = strstr(os_kernel, "Linux 2.4") ? 3 : 0; + g_free(os_kernel); } g_file_get_contents("/proc/meminfo", &meminfo, NULL, NULL); diff --git a/arch/linux/common/filesystem.h b/arch/linux/common/filesystem.h index 8300f278..d8166fc3 100644 --- a/arch/linux/common/filesystem.h +++ b/arch/linux/common/filesystem.h @@ -23,15 +23,23 @@ static gchar *fs_list = NULL; +static gboolean +remove_filesystem_entries(gpointer key, gpointer value, gpointer data) +{ + return g_str_has_prefix(key, "FS"); +} + static void scan_filesystems(void) { FILE *mtab; gchar buf[1024]; struct statfs sfs; + int count = 0; g_free(fs_list); fs_list = g_strdup(""); + g_hash_table_foreach_remove(moreinfo, remove_filesystem_entries, NULL); mtab = fopen("/etc/mtab", "r"); if (!mtab) @@ -71,11 +79,11 @@ scan_filesystems(void) strstr(tmp[3], "rw") ? "Read-Write" : "Read-Only", tmp[1], strsize, strused, stravail); - g_hash_table_insert(moreinfo, g_strdup(tmp[0]), strhash); + g_hash_table_insert(moreinfo, g_strdup_printf("FS%d", ++count), strhash); - fs_list = g_strdup_printf("%s$%s$%s=%s total, %s free\n", + fs_list = h_strdup_cprintf("$FS%d$%s=%s total, %s free\n", fs_list, - tmp[0], tmp[0], strsize, stravail); + count, tmp[0], strsize, stravail); g_free(strsize); g_free(stravail); diff --git a/arch/linux/common/inputdevices.h b/arch/linux/common/inputdevices.h index 1a5baff8..8d2d8427 100644 --- a/arch/linux/common/inputdevices.h +++ b/arch/linux/common/inputdevices.h @@ -21,11 +21,7 @@ static gchar *input_icons = NULL; static gboolean remove_input_devices(gpointer key, gpointer value, gpointer data) { - if (!strncmp((gchar *) key, "INP", 3)) { - return TRUE; - } - - return FALSE; + return g_str_has_prefix(key, "INP"); } static struct { @@ -91,10 +87,10 @@ __scan_input_devices(void) } tmp = g_strdup_printf("INP%d", ++n); - input_list = g_strdup_printf("%s$%s$%s=\n", + input_list = h_strdup_cprintf("$%s$%s=\n", input_list, tmp, name); - input_icons = g_strdup_printf("%sIcon$%s$%s=%s\n", + input_icons = h_strdup_cprintf("Icon$%s$%s=%s\n", input_icons, tmp, name, input_devices[d].icon); @@ -108,20 +104,17 @@ __scan_input_devices(void) const gchar *url = vendor_get_url(name); if (url) { - strhash = g_strdup_printf("%s" - "Vendor=%s (%s)\n", + strhash = h_strdup_cprintf("Vendor=%s (%s)\n", strhash, vendor_get_name(name), url); } else { - strhash = g_strdup_printf("%s" - "Vendor=%x\n", + strhash = h_strdup_cprintf("Vendor=%x\n", strhash, vendor); } - strhash = g_strdup_printf("%s" - "Product=0x%x\n" + strhash = h_strdup_cprintf("Product=0x%x\n" "Version=0x%x\n" "Connected to=%s\n", strhash, product, version, phys); diff --git a/arch/linux/common/modules.h b/arch/linux/common/modules.h index 9b895ee8..6fbe13bd 100644 --- a/arch/linux/common/modules.h +++ b/arch/linux/common/modules.h @@ -26,12 +26,7 @@ static gboolean remove_module_devices(gpointer key, gpointer value, gpointer data) { - if (!strncmp((gchar *) key, "MOD", 3)) { - g_free((gchar *) key); - g_free((GtkTreeIter *) value); - return TRUE; - } - return FALSE; + return g_str_has_prefix(key, "MOD"); } static void @@ -42,9 +37,9 @@ scan_modules_do(void) if (module_list) { g_free(module_list); - module_list = NULL; } - + + module_list = NULL; g_hash_table_foreach_remove(moreinfo, remove_module_devices, NULL); lsmod = popen("/sbin/lsmod", "r"); @@ -103,8 +98,8 @@ scan_modules_do(void) } /* append this module to the list of modules */ - module_list = g_strdup_printf("%s$%s$%s=%s\n", - module_list ? module_list : "", + module_list = h_strdup_cprintf("$%s$%s=%s\n", + module_list, hashkey, modname, description ? description : ""); @@ -134,7 +129,7 @@ scan_modules_do(void) if (deps && strlen(deps)) { gchar **tmp = g_strsplit(deps, ",", 0); - strmodule = g_strconcat(strmodule, + strmodule = h_strconcat(strmodule, "\n[Dependencies]\n", g_strjoinv("=\n", tmp), "=\n", NULL); diff --git a/arch/linux/common/net.h b/arch/linux/common/net.h index cd8b8706..527da1df 100644 --- a/arch/linux/common/net.h +++ b/arch/linux/common/net.h @@ -16,7 +16,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -static gchar *network_interfaces = NULL; +static gchar *network_interfaces = NULL, + *network_icons = NULL; #include <sys/ioctl.h> #include <net/if.h> @@ -100,26 +101,27 @@ void get_net_info(char *if_name, NetInfo *netinfo) static struct { char *type; char *label; + char *icon; } netdev2type[] = { - { "eth", "Ethernet" }, - { "lo", "Loopback" }, - { "ppp", "Point-to-Point" }, - { "ath", "Wireless" }, - { "wlan", "Wireless" }, - { "tun", "Virtual Point-to-Point (TUN)" }, - { "tap", "Ethernet (TAP)" }, - { "plip", "Parallel Line Internet Protocol" }, - { "irlan", "Infrared" }, - { "slip", "Serial Line Internet Protocol" }, - { "isdn", "Integrated Services Digital Network" }, - { "sit", "IPv6-over-IPv4 Tunnel" }, - { "vmnet8", "VMWare Virtual Network Interface (NAT)" }, - { "vmnet", "VMWare Virtual Network Interface" }, - { NULL, "Unknown" }, + { "eth", "Ethernet", "network" }, + { "lo", "Loopback", "network-generic" }, + { "ppp", "Point-to-Point", "modem" }, + { "ath", "Wireless", "wireless" }, + { "wlan", "Wireless", "wireless" }, + { "tun", "Virtual Point-to-Point (TUN)", "network-generic" }, + { "tap", "Ethernet (TAP)", "network-generic" }, + { "plip", "Parallel Line Internet Protocol", "network" }, + { "irlan", "Infrared", "network-generic" }, + { "slip", "Serial Line Internet Protocol", "network-generic" }, + { "isdn", "Integrated Services Digital Network", "modem" }, + { "sit", "IPv6-over-IPv4 Tunnel", "network-generic" }, + { "vmnet8", "VMWare Virtual Network Interface (NAT)", "computer" }, + { "vmnet", "VMWare Virtual Network Interface", "computer"}, + { NULL, "Unknown", "network-generic" }, }; -static const gchar * -net_get_iface_type(gchar *name) +static void +net_get_iface_type(gchar *name, gchar **type, gchar **icon) { int i; @@ -128,18 +130,14 @@ net_get_iface_type(gchar *name) break; } - return netdev2type[i].label; + *type = netdev2type[i].label; + *icon = netdev2type[i].icon; } static gboolean remove_net_devices(gpointer key, gpointer value, gpointer data) { - if (!strncmp((gchar *) key, "NET", 4)) { - g_free((gchar *) key); - g_free((GtkTreeIter *) value); - return TRUE; - } - return FALSE; + return g_str_has_prefix(key, "NET"); } static void @@ -171,7 +169,12 @@ scan_net_interfaces_24(void) g_free(network_interfaces); } + if (network_icons) { + g_free(network_icons); + } + network_interfaces = g_strdup("[Network Interfaces]\n"); + network_icons = g_strdup(""); proc_net = fopen("/proc/net/dev", "r"); while (fgets(buffer, 256, proc_net)) { @@ -179,6 +182,7 @@ scan_net_interfaces_24(void) gint trash; gchar ifacename[16]; gchar *buf = buffer; + gchar *iface_type, *iface_icon, *ip; gint i; buf = g_strstrip(buf); @@ -204,14 +208,21 @@ scan_net_interfaces_24(void) get_net_info(ifacename, &ni); devid = g_strdup_printf("NET%s", ifacename); - network_interfaces = g_strdup_printf("%s$%s$%s=Sent %.2fMiB, received %.2fMiB%s\n", + + ip = g_strdup_printf(" (%s)", ni.ip); + network_interfaces = h_strdup_cprintf("$%s$%s=Sent %.2fMiB, received %.2fMiB%s\n", network_interfaces, devid, ifacename, trans_mb, recv_mb, - ni.ip[0] ? - (gchar*)idle_free(g_strdup_printf(" (%s)", ni.ip)) : ""); + ni.ip[0] ? ip: ""); + g_free(ip); + + net_get_iface_type(ifacename, &iface_type, &iface_icon); + network_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", + network_icons, devid, + ifacename, iface_icon); detailed = g_strdup_printf("[Network Adapter Properties]\n" "Interface Type=%s\n" @@ -220,7 +231,7 @@ scan_net_interfaces_24(void) "[Transfer Details]\n" "Bytes Received=%ld (%.2fMiB)\n" "Bytes Sent=%ld (%.2fMiB)\n", - net_get_iface_type(ifacename), + iface_type, ni.mac[0], ni.mac[1], ni.mac[2], ni.mac[3], ni.mac[4], ni.mac[5], @@ -229,8 +240,7 @@ scan_net_interfaces_24(void) trans_bytes, trans_mb); if (ni.ip[0] || ni.mask[0] || ni.broadcast[0]) { - detailed = g_strdup_printf("%s\n" - "[Internet Protocol (IPv4)]\n" + detailed = h_strdup_cprintf("\n[Internet Protocol (IPv4)]\n" "IP Address=%s\n" "Mask=%s\n" "Broadcast Address=%s\n", diff --git a/arch/linux/common/os.h b/arch/linux/common/os.h index d30146ef..0fe06709 100644 --- a/arch/linux/common/os.h +++ b/arch/linux/common/os.h @@ -162,8 +162,6 @@ computer_get_os(void) } if (g_file_test(distro_db[i].file, G_FILE_TEST_EXISTS)) { - - FILE *distro_ver; char buf[128]; diff --git a/arch/linux/common/pci.h b/arch/linux/common/pci.h index e50691d0..554c3dca 100644 --- a/arch/linux/common/pci.h +++ b/arch/linux/common/pci.h @@ -24,14 +24,8 @@ __scan_pci(void) gchar *category = NULL, *name = NULL; gint n = 0; - //if (g_file_test("/usr/bin/gksudo", G_FILE_TEST_EXISTS)) { - // lspci = popen("gksudo '/bin/lspci -v'", "r"); - //} else { - lspci = popen(LSPCI, "r"); - //} - - if (!lspci) { - return; + if (!(lspci = popen(LSPCI, "r"))) { + goto pci_error; } gchar *icon; @@ -66,32 +60,24 @@ __scan_pci(void) g_strfreev(list); if (irq) - strdevice = g_strdup_printf("%sIRQ=%d\n", strdevice, irq); + strdevice = h_strdup_cprintf("IRQ=%d\n", strdevice, irq); if (freq) - strdevice = - g_strdup_printf("%sFrequency=%dMHz\n", strdevice, - freq); + strdevice = h_strdup_cprintf("Frequency=%dMHz\n", strdevice, freq); if (latency) - strdevice = - g_strdup_printf("%sLatency=%d\n", strdevice, latency); + strdevice = h_strdup_cprintf("Latency=%d\n", strdevice, latency); - strdevice = - g_strdup_printf("%sBus Master=%s\n", strdevice, - bus_master ? "Yes" : "No"); + strdevice = h_strdup_cprintf("Bus Master=%s\n", strdevice, bus_master ? "Yes" : "No"); } else if (!strncmp(buf, "Subsystem", 9)) { WALK_UNTIL(' '); buf++; - strdevice = - g_strdup_printf("%sOEM Vendor=%s\n", strdevice, buf); + strdevice = h_strdup_cprintf("OEM Vendor=%s\n", strdevice, buf); } else if (!strncmp(buf, "Capabilities", 12) && !strstr(buf, "only to root") && !strstr(buf, "access denied")) { WALK_UNTIL(' '); WALK_UNTIL(']'); buf++; - strdevice = - g_strdup_printf("%sCapability#%d=%s\n", strdevice, ++x, - buf); + strdevice = h_strdup_cprintf("Capability#%d=%s\n", strdevice, ++x, buf); } else if (!strncmp(buf, "Memory at", 9) && strstr(buf, "[size=")) { gint mem; gchar unit; @@ -104,7 +90,7 @@ __scan_pci(void) WALK_UNTIL('['); sscanf(buf, "[size=%d%c", &mem, &unit); - strdevice = g_strdup_printf("%sMemory#%d=%d%cB (%s%s)\n", + strdevice = h_strdup_cprintf("Memory#%d=%d%cB (%s%s)\n", strdevice, ++x, mem, (unit == ']') ? ' ' : unit, @@ -118,7 +104,7 @@ __scan_pci(void) sscanf(buf, "I/O ports at %x [size=%d]", &io_addr, &io_size); strdevice = - g_strdup_printf("%sI/O ports at#%d=0x%x - 0x%x\n", + h_strdup_cprintf("I/O ports at#%d=0x%x - 0x%x\n", strdevice, ++x, io_addr, io_addr + io_size); } else if ((buf[0] >= '0' && buf[0] <= '9') && (buf[4] == ':' || buf[2] == ':')) { @@ -174,22 +160,21 @@ __scan_pci(void) const gchar *url = vendor_get_url(name); if (url) { - strdevice = g_strdup_printf("%s" - "Vendor=%s (%s)\n", + strdevice = h_strdup_cprintf("Vendor=%s (%s)\n", strdevice, vendor_get_name(name), url); } - pci_list = g_strdup_printf("%s$PCI%d$%s=%s\n", pci_list, n, category, - name); + pci_list = h_strdup_cprintf("$PCI%d$%s=%s\n", pci_list, n, category, name); n++; } } if (pclose(lspci)) { +pci_error: /* error (no pci, perhaps?) */ pci_list = g_strconcat(pci_list, "No PCI devices found=\n", NULL); } else if (strhash) { diff --git a/arch/linux/common/sensors.h b/arch/linux/common/sensors.h index 3303d5d2..bc84014b 100644 --- a/arch/linux/common/sensors.h +++ b/arch/linux/common/sensors.h @@ -147,8 +147,7 @@ static void read_sensors_hwmon(void) gchar *path_hwmon, *path_sensor, *tmp, *driver, *name, *mon; hwmon = 0; - path_hwmon = - g_strdup_printf("/sys/class/hwmon/hwmon%d/device/", hwmon); + path_hwmon = g_strdup_printf("/sys/class/hwmon/hwmon%d/device/", hwmon); while (g_file_test(path_hwmon, G_FILE_TEST_EXISTS)) { tmp = g_strdup_printf("%sdriver", path_hwmon); driver = g_file_read_link(tmp, NULL); @@ -162,9 +161,6 @@ static void read_sensors_hwmon(void) read_sensor_labels(driver); } - sensors = g_strdup_printf("%s[Driver Info]\n" - "Name=%s\n", sensors, driver); - sensors = g_strconcat(sensors, "[Cooling Fans]\n", NULL); for (count = 1;; count++) { path_sensor = @@ -177,7 +173,7 @@ static void read_sensors_hwmon(void) mon = g_strdup_printf("fan%d", count); name = get_sensor_label(mon); if (!g_str_equal(name, "ignore")) { - sensors = g_strdup_printf("%s%s=%.0fRPM\n", + sensors = h_strdup_cprintf("%s=%.0fRPM\n", sensors, name, adjust_sensor(mon, atof(tmp))); } @@ -200,7 +196,7 @@ static void read_sensors_hwmon(void) mon = g_strdup_printf("temp%d", count); name = get_sensor_label(mon); if (!g_str_equal(name, "ignore")) { - sensors = g_strdup_printf("%s%s=%.2f\302\260C\n", + sensors = h_strdup_cprintf("%s=%.2f\302\260C\n", sensors, name, adjust_sensor(mon, atof(tmp) / @@ -226,7 +222,7 @@ static void read_sensors_hwmon(void) mon = g_strdup_printf("in%d", count); name = get_sensor_label(mon); if (!g_str_equal(name, "ignore")) { - sensors = g_strdup_printf("%s%s=%.3fV\n", + sensors = h_strdup_cprintf("%s=%.3fV\n", sensors, name, adjust_sensor(mon, atof(tmp) / @@ -258,9 +254,8 @@ static void read_sensors_acpi(void) if ((tz = g_dir_open(path_tz, 0, NULL))) { const gchar *entry; + gchar *temp = ""; - sensors = - g_strdup_printf("%s\n[ACPI Thermal Zone]\n", sensors); while ((entry = g_dir_read_name(tz))) { gchar *path = @@ -272,13 +267,18 @@ static void read_sensors_acpi(void) sscanf(contents, "temperature: %d C", &temperature); - sensors = g_strdup_printf("%s\n%s=%d\302\260C\n", - sensors, entry, temperature); + temp = h_strdup_cprintf("\n%s=%d\302\260C\n", + temp, entry, temperature); g_free(contents); } } + if (*temp != '\0') + sensors = + h_strdup_cprintf("\n[ACPI Thermal Zone]\n%s", + sensors, temp); + g_dir_close(tz); } } @@ -295,7 +295,7 @@ static void read_sensors_omnibook(void) sscanf(contents, "CPU temperature: %d C", &temperature); - sensors = g_strdup_printf("%s\n[Omnibook]\n" + sensors = h_strdup_cprintf("\n[Omnibook]\n" "CPU temperature=%d\302\260C\n", sensors, temperature); @@ -334,8 +334,7 @@ static void read_sensors_hddtemp(void) * 2 -> 41 * 3 -> C */ - old = g_strdup_printf("%s\n" - "%s (%s)=%s\302\260%s\n", + old = h_strdup_cprintf("\n%s (%s)=%s\302\260%s\n", old, fields[1], fields[0], fields[2], fields[3]); diff --git a/arch/linux/common/storage.h b/arch/linux/common/storage.h index 836ba7ea..6700984b 100644 --- a/arch/linux/common/storage.h +++ b/arch/linux/common/storage.h @@ -16,15 +16,12 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -static gchar *storage_icons = ""; +static gchar *storage_icons = NULL; static gboolean remove_scsi_devices(gpointer key, gpointer value, gpointer data) { - if (!strncmp((gchar *) key, "SCSI", 4)) { - return TRUE; - } - return FALSE; + return g_str_has_prefix(key, "SCSI"); } /* SCSI support by Pascal F.Martin <pascalmartin@earthlink.net> */ @@ -113,8 +110,8 @@ __scan_scsi_devices(void) } gchar *devid = g_strdup_printf("SCSI%d", n); - storage_list = g_strdup_printf("%s$%s$%s=\n", storage_list, devid, model); - storage_icons = g_strdup_printf("%sIcon$%s$%s=%s.png\n", storage_icons, devid, model, icon); + storage_list = h_strdup_cprintf("$%s$%s=\n", storage_list, devid, model); + storage_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", storage_icons, devid, model, icon); gchar *strhash = g_strdup_printf("[Device Information]\n" "Model=%s\n" @@ -147,10 +144,7 @@ __scan_scsi_devices(void) static gboolean remove_ide_devices(gpointer key, gpointer value, gpointer data) { - if (!strncmp((gchar *) key, "IDE", 3)) { - return TRUE; - } - return FALSE; + return g_str_has_prefix(key, "IDE"); } void @@ -165,7 +159,7 @@ __scan_ide_devices(void) /* remove old devices from global device table */ g_hash_table_foreach_remove(moreinfo, remove_ide_devices, NULL); - storage_list = g_strdup_printf("%s\n[IDE Disks]\n", storage_list); + storage_list = g_strconcat(storage_list, "\n[IDE Disks]\n", NULL); iface = 'a'; for (i = 0; i <= 16; i++) { @@ -211,26 +205,26 @@ __scan_ide_devices(void) gchar *media_type = g_strstrip(strstr(buf, "Does ")); gchar **ttmp = g_strsplit(media_type, " ", 0); - capab = g_strdup_printf("%s\nCan %s#%d=%s\n", - capab ? capab : "", + capab = h_strdup_cprintf("\nCan %s#%d=%s\n", + capab, ttmp[1], ++nn, ttmp[2]); g_strfreev(ttmp); } else if (strstr(buf, "Buffer-Underrun-Free")) { - capab = g_strdup_printf("%s\nSupports BurnProof=%s\n", - capab ? capab : "", + capab = h_strdup_cprintf("\nSupports BurnProof=%s\n", + capab, strstr(buf, "Does not") ? "No" : "Yes"); } else if (strstr(buf, "multi-session")) { - capab = g_strdup_printf("%s\nCan read multi-session CDs=%s\n", - capab ? capab : "", + capab = h_strdup_cprintf("\nCan read multi-session CDs=%s\n", + capab, strstr(buf, "Does not") ? "No" : "Yes"); } else if (strstr(buf, "audio CDs")) { - capab = g_strdup_printf("%s\nCan play audio CDs=%s\n", - capab ? capab : "", + capab = h_strdup_cprintf("\nCan play audio CDs=%s\n", + capab, strstr(buf, "Does not") ? "No" : "Yes"); } else if (strstr(buf, "PREVENT/ALLOW")) { - capab = g_strdup_printf("%s\nCan lock media=%s\n", - capab ? capab : "", + capab = h_strdup_cprintf("\nCan lock media=%s\n", + capab, strstr(buf, "Does not") ? "No" : "Yes"); } } else if ((strstr(buf, "read") || strstr(buf, "write")) && strstr(buf, "kB/s")) { @@ -248,7 +242,6 @@ __scan_ide_devices(void) g_free(tmp); } - g_free(device); device = g_strdup_printf("/proc/ide/hd%c/cache", iface); @@ -288,9 +281,9 @@ __scan_ide_devices(void) gchar *devid = g_strdup_printf("IDE%d", n); - storage_list = g_strdup_printf("%s$%s$%s=\n", storage_list, + storage_list = h_strdup_cprintf("$%s$%s=\n", storage_list, devid, model); - storage_icons = g_strdup_printf("%sIcon$%s$%s=%s.png\n", storage_icons, devid, + storage_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", storage_icons, devid, model, g_str_equal(media, "cdrom") ? \ "cdrom" : "hdd"); @@ -307,14 +300,14 @@ __scan_ide_devices(void) media, cache); if (driver) { - strhash = g_strdup_printf("%s%s\n", strhash, driver); + strhash = h_strdup_cprintf("%s\n", strhash, driver); g_free(driver); driver = NULL; } if (pgeometry && lgeometry) { - strhash = g_strdup_printf("%s[Geometry]\n" + strhash = h_strdup_cprintf("[Geometry]\n" "Physical=%s\n" "Logical=%s\n", strhash, pgeometry, lgeometry); @@ -326,14 +319,14 @@ __scan_ide_devices(void) } if (capab) { - strhash = g_strdup_printf("%s[Capabilities]\n%s", strhash, capab); + strhash = h_strdup_cprintf("[Capabilities]\n%s", strhash, capab); g_free(capab); capab = NULL; } if (speed) { - strhash = g_strdup_printf("%s[Speeds]\n%s", strhash, speed); + strhash = h_strdup_cprintf("[Speeds]\n%s", strhash, speed); g_free(speed); speed = NULL; diff --git a/arch/linux/common/usb.h b/arch/linux/common/usb.h index d59f5f01..f2592648 100644 --- a/arch/linux/common/usb.h +++ b/arch/linux/common/usb.h @@ -19,10 +19,7 @@ static gboolean remove_usb_devices(gpointer key, gpointer value, gpointer data) { - if (!strncmp((gchar *) key, "USB", 3)) { - return TRUE; - } - return FALSE; + return g_str_has_prefix(key, "USB"); } static gchar *usb_list = NULL; @@ -89,10 +86,10 @@ __scan_usb(void) if (classid == 9) { /* hub */ - usb_list = g_strdup_printf("%s[%s#%d]\n", + usb_list = h_strdup_cprintf("[%s#%d]\n", usb_list, product, n); } else { /* everything else */ - usb_list = g_strdup_printf("%s$%s$%s=\n", + usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product); const gchar *url = vendor_get_url(manuf); diff --git a/arch/linux/x86/processor.h b/arch/linux/x86/processor.h index 918bac7c..fd8711af 100644 --- a/arch/linux/x86/processor.h +++ b/arch/linux/x86/processor.h @@ -264,7 +264,7 @@ gchar *processor_get_capabilities_from_flags(gchar * strflags) * - Use binary search or something faster than this O(n) cruft */ gchar **flags, **old; - gchar *tmp = ""; + gchar *tmp = NULL; gint i, j = 0; flags = g_strsplit(strflags, " ", 0); @@ -279,7 +279,7 @@ gchar *processor_get_capabilities_from_flags(gchar * strflags) } } - tmp = g_strdup_printf("%s%s=%s\n", tmp, flags[j], meaning); + tmp = h_strdup_cprintf("%s=%s\n", tmp, flags[j], meaning); j++; } diff --git a/autopackage/default.apspec b/autopackage/default.apspec index f12960c1..9042d252 100644 --- a/autopackage/default.apspec +++ b/autopackage/default.apspec @@ -2,7 +2,7 @@ # Generated by mkapspec 0.2 [Meta] ShortName: hardinfo -SoftwareVersion: 0.4.2.1 +SoftwareVersion: 0.4.2.2 DisplayName: HardInfo $SOFTWAREVERSION RootName: @tia.mat.br/hardinfo:$SOFTWAREVERSION Summary: System profiler and benchmark tool diff --git a/benchmark.c b/benchmark.c index 7f5025de..3c6f0f1f 100644 --- a/benchmark.c +++ b/benchmark.c @@ -22,6 +22,9 @@ #include <config.h> #include <syncmanager.h> +#include <sys/time.h> +#include <sys/resource.h> + enum { BENCHMARK_ZLIB, BENCHMARK_FIB, @@ -53,7 +56,7 @@ static ModuleEntry entries[] = { {"CPU SHA1", "module.png", callback_sha1, scan_sha1}, {"CPU Blowfish", "blowfish.png", callback_bfsh, scan_bfsh}, {"FPU Raytracing", "raytrace.png", callback_raytr, scan_raytr}, - { NULL } + {NULL} }; static gchar *__benchmark_include_results(gdouble result, @@ -62,24 +65,29 @@ static gchar *__benchmark_include_results(gdouble result, { GKeyFile *conf; gchar **machines; - gchar *path, *results = ""; + gchar *path, *results = g_strdup(""); int i; conf = g_key_file_new(); - - path = g_build_filename(g_get_home_dir(), ".hardinfo", "benchmark.conf", NULL); + + path = + g_build_filename(g_get_home_dir(), ".hardinfo", "benchmark.conf", + NULL); if (!g_file_test(path, G_FILE_TEST_EXISTS)) { - DEBUG("local benchmark.conf not found, trying system-wide"); - g_free(path); - path = g_build_filename(params.path_data, "benchmark.conf", NULL); + DEBUG("local benchmark.conf not found, trying system-wide"); + g_free(path); + path = g_build_filename(params.path_data, "benchmark.conf", NULL); } g_key_file_load_from_file(conf, path, 0, NULL); machines = g_key_file_get_keys(conf, benchmark, NULL, NULL); for (i = 0; machines && machines[i]; i++) { - gchar *value = g_key_file_get_value(conf, benchmark, machines[i], NULL); + gchar *value; + + value = g_key_file_get_value(conf, benchmark, machines[i], NULL); results = g_strconcat(results, machines[i], "=", value, "\n", NULL); + g_free(value); } @@ -123,73 +131,87 @@ static gdouble bench_results[BENCHMARK_N_ENTRIES]; gchar *callback_zlib() { - return benchmark_include_results_reverse(bench_results[BENCHMARK_ZLIB], "CPU ZLib"); + return benchmark_include_results_reverse(bench_results[BENCHMARK_ZLIB], + "CPU ZLib"); } gchar *callback_raytr() { - return benchmark_include_results(bench_results[BENCHMARK_RAYTRACE], "FPU Raytracing"); + return benchmark_include_results(bench_results[BENCHMARK_RAYTRACE], + "FPU Raytracing"); } gchar *callback_bfsh() { - return benchmark_include_results(bench_results[BENCHMARK_BLOWFISH], "CPU Blowfish"); + return benchmark_include_results(bench_results[BENCHMARK_BLOWFISH], + "CPU Blowfish"); } gchar *callback_md5() { - return benchmark_include_results_reverse(bench_results[BENCHMARK_MD5], "CPU MD5"); + return benchmark_include_results_reverse(bench_results[BENCHMARK_MD5], + "CPU MD5"); } gchar *callback_fib() { - return benchmark_include_results(bench_results[BENCHMARK_FIB], "CPU Fibonacci"); + return benchmark_include_results(bench_results[BENCHMARK_FIB], + "CPU Fibonacci"); } gchar *callback_sha1() { - return benchmark_include_results_reverse(bench_results[BENCHMARK_SHA1], "CPU SHA1"); + return benchmark_include_results_reverse(bench_results[BENCHMARK_SHA1], + "CPU SHA1"); } +#define RUN_WITH_HIGH_PRIORITY(fn) \ + do { \ + int old_priority = getpriority(PRIO_PROCESS, 0); \ + setpriority(PRIO_PROCESS, 0, -20); \ + fn(); \ + setpriority(PRIO_PROCESS, 0, old_priority); \ + } while (0); + void scan_zlib(gboolean reload) { SCAN_START(); - benchmark_zlib(); + RUN_WITH_HIGH_PRIORITY(benchmark_zlib); SCAN_END(); } void scan_raytr(gboolean reload) { SCAN_START(); - benchmark_raytrace(); + RUN_WITH_HIGH_PRIORITY(benchmark_raytrace); SCAN_END(); } void scan_bfsh(gboolean reload) { SCAN_START(); - benchmark_fish(); + RUN_WITH_HIGH_PRIORITY(benchmark_fish); SCAN_END(); } void scan_md5(gboolean reload) { SCAN_START(); - benchmark_md5(); + RUN_WITH_HIGH_PRIORITY(benchmark_md5); SCAN_END(); } void scan_fib(gboolean reload) { SCAN_START(); - benchmark_fib(); + RUN_WITH_HIGH_PRIORITY(benchmark_fib); SCAN_END(); } void scan_sha1(gboolean reload) { SCAN_START(); - benchmark_sha1(); + RUN_WITH_HIGH_PRIORITY(benchmark_sha1); SCAN_END(); } @@ -198,7 +220,7 @@ const gchar *hi_note_func(gint entry) switch (entry) { case BENCHMARK_ZLIB: return "Results in KiB/second. Higher is better."; - + case BENCHMARK_MD5: case BENCHMARK_SHA1: return "Results in MiB/second. Higher is better."; @@ -227,73 +249,64 @@ ModuleEntry *hi_module_get_entries(void) return entries; } -ModuleAbout * -hi_module_get_about(void) +ModuleAbout *hi_module_get_about(void) { static ModuleAbout ma[] = { - { - .author = "Leandro A. F. Pereira", - .description = "Perform tasks and compare with other systems", - .version = VERSION, - .license = "GNU GPL version 2" - } + { + .author = "Leandro A. F. Pereira", + .description = "Perform tasks and compare with other systems", + .version = VERSION, + .license = "GNU GPL version 2"} }; - + return ma; } static gchar *get_benchmark_results() { - void (*scan_callback)(gboolean rescan); - + void (*scan_callback) (gboolean rescan); + gint i = G_N_ELEMENTS(entries) - 1; gchar *machine = module_call_method("devices::getProcessorName"); gchar *param = g_strdup_printf("[param]\n" - "machine=%s\n" - "nbenchmarks=%d\n", - machine, i); + "machine=%s\n" "nbenchmarks=%d\n", + machine, i); gchar *result = param; - + for (; i >= 0; i--) { - if ((scan_callback = entries[i].scan_callback)) { - scan_callback(FALSE); - - result = g_strdup_printf("%s\n" - "[bench%d]\n" - "name=%s\n" - "value=%f\n", - result, - i, - entries[i].name, - bench_results[i]); - } + if ((scan_callback = entries[i].scan_callback)) { + scan_callback(FALSE); + + result = g_strdup_printf("%s\n" + "[bench%d]\n" + "name=%s\n" + "value=%f\n", + result, + i, entries[i].name, bench_results[i]); + } } - + g_free(machine); g_free(param); - + return result; } -void -hi_module_init(void) +void hi_module_init(void) { static SyncEntry se[] = { - { - .fancy_name = "Send Benchmark Results", - .name = "SendBenchmarkResults", - .save_to = NULL, - .get_data = get_benchmark_results - }, - { - .fancy_name = "Receive Benchmark Results", - .name = "RecvBenchmarkResults", - .save_to = "benchmark.conf", - .get_data = NULL - } + { + .fancy_name = "Send Benchmark Results", + .name = "SendBenchmarkResults", + .save_to = NULL, + .get_data = get_benchmark_results}, + { + .fancy_name = "Receive Benchmark Results", + .name = "RecvBenchmarkResults", + .save_to = "benchmark.conf", + .get_data = NULL} }; - + sync_manager_add_entry(&se[0]); sync_manager_add_entry(&se[1]); } - @@ -23,247 +23,245 @@ #include "binreloc.h" G_BEGIN_DECLS - - /** @internal * Find the canonical filename of the executable. Returns the filename * (which must be freed) or NULL on error. If the parameter 'error' is * not NULL, the error code will be stored there, if an error occured. */ -static char * -_br_find_exe (GbrInitError *error) +static char *_br_find_exe(GbrInitError * error) { - char *path, *path2, *line, *result; - size_t buf_size; - ssize_t size; - struct stat stat_buf; - FILE *f; - - /* Read from /proc/self/exe (symlink) */ - if (sizeof (path) > SSIZE_MAX) - buf_size = SSIZE_MAX - 1; - else - buf_size = PATH_MAX - 1; - path = (char *) g_try_malloc (buf_size); - if (path == NULL) { - /* Cannot allocate memory. */ - if (error) - *error = GBR_INIT_ERROR_NOMEM; - return NULL; + char *path, *path2, *line, *result; + size_t buf_size; + ssize_t size; + struct stat stat_buf; + FILE *f; + + /* Read from /proc/self/exe (symlink) */ + if (sizeof(path) > SSIZE_MAX) + buf_size = SSIZE_MAX - 1; + else + buf_size = PATH_MAX - 1; + path = (char *) g_try_malloc(buf_size); + if (path == NULL) { + /* Cannot allocate memory. */ + if (error) + *error = GBR_INIT_ERROR_NOMEM; + return NULL; + } + path2 = (char *) g_try_malloc(buf_size); + if (path2 == NULL) { + /* Cannot allocate memory. */ + if (error) + *error = GBR_INIT_ERROR_NOMEM; + g_free(path); + return NULL; + } + + strncpy(path2, "/proc/self/exe", buf_size - 1); + + while (1) { + int i; + + size = readlink(path2, path, buf_size - 1); + if (size == -1) { + /* Error. */ + g_free(path2); + break; } - path2 = (char *) g_try_malloc (buf_size); - if (path2 == NULL) { - /* Cannot allocate memory. */ - if (error) - *error = GBR_INIT_ERROR_NOMEM; - g_free (path); - return NULL; + + /* readlink() success. */ + path[size] = '\0'; + + /* Check whether the symlink's target is also a symlink. + * We want to get the final target. */ + i = stat(path, &stat_buf); + if (i == -1) { + /* Error. */ + g_free(path2); + break; } - strncpy (path2, "/proc/self/exe", buf_size - 1); - - while (1) { - int i; - - size = readlink (path2, path, buf_size - 1); - if (size == -1) { - /* Error. */ - g_free (path2); - break; - } - - /* readlink() success. */ - path[size] = '\0'; - - /* Check whether the symlink's target is also a symlink. - * We want to get the final target. */ - i = stat (path, &stat_buf); - if (i == -1) { - /* Error. */ - g_free (path2); - break; - } - - /* stat() success. */ - if (!S_ISLNK (stat_buf.st_mode)) { - /* path is not a symlink. Done. */ - g_free (path2); - return path; - } - - /* path is a symlink. Continue loop and resolve this. */ - strncpy (path, path2, buf_size - 1); + /* stat() success. */ + if (!S_ISLNK(stat_buf.st_mode)) { + /* path is not a symlink. Done. */ + g_free(path2); + return path; } + /* path is a symlink. Continue loop and resolve this. */ + strncpy(path, path2, buf_size - 1); + } + + + /* readlink() or stat() failed; this can happen when the program is + * running in Valgrind 2.2. Read from /proc/self/maps as fallback. */ + + buf_size = PATH_MAX + 128; + line = (char *) g_try_realloc(path, buf_size); + if (line == NULL) { + /* Cannot allocate memory. */ + g_free(path); + if (error) + *error = GBR_INIT_ERROR_NOMEM; + return NULL; + } + + f = fopen("/proc/self/maps", "r"); + if (f == NULL) { + g_free(line); + if (error) + *error = GBR_INIT_ERROR_OPEN_MAPS; + return NULL; + } + + /* The first entry should be the executable name. */ + result = fgets(line, (int) buf_size, f); + if (result == NULL) { + fclose(f); + g_free(line); + if (error) + *error = GBR_INIT_ERROR_READ_MAPS; + return NULL; + } + + /* Get rid of newline character. */ + buf_size = strlen(line); + if (buf_size <= 0) { + /* Huh? An empty string? */ + fclose(f); + g_free(line); + if (error) + *error = GBR_INIT_ERROR_INVALID_MAPS; + return NULL; + } + if (line[buf_size - 1] == 10) + line[buf_size - 1] = 0; + + /* Extract the filename; it is always an absolute path. */ + path = strchr(line, '/'); + + /* Sanity check. */ + if (strstr(line, " r-xp ") == NULL || path == NULL) { + fclose(f); + g_free(line); + if (error) + *error = GBR_INIT_ERROR_INVALID_MAPS; + return NULL; + } + + path = g_strdup(path); + g_free(line); + fclose(f); + return path; +} - /* readlink() or stat() failed; this can happen when the program is - * running in Valgrind 2.2. Read from /proc/self/maps as fallback. */ - buf_size = PATH_MAX + 128; - line = (char *) g_try_realloc (path, buf_size); - if (line == NULL) { - /* Cannot allocate memory. */ - g_free (path); - if (error) - *error = GBR_INIT_ERROR_NOMEM; - return NULL; - } +/** @internal + * Find the canonical filename of the executable which owns symbol. + * Returns a filename which must be freed, or NULL on error. + */ +static char *_br_find_exe_for_symbol(const void *symbol, + GbrInitError * error) +{ +#define SIZE PATH_MAX + 100 + FILE *f; + size_t address_string_len; + char *address_string, line[SIZE], *found; - f = fopen ("/proc/self/maps", "r"); - if (f == NULL) { - g_free (line); - if (error) - *error = GBR_INIT_ERROR_OPEN_MAPS; - return NULL; - } + if (symbol == NULL) + return (char *) NULL; - /* The first entry should be the executable name. */ - result = fgets (line, (int) buf_size, f); - if (result == NULL) { - fclose (f); - g_free (line); - if (error) - *error = GBR_INIT_ERROR_READ_MAPS; - return NULL; - } + f = fopen("/proc/self/maps", "r"); + if (f == NULL) + return (char *) NULL; - /* Get rid of newline character. */ - buf_size = strlen (line); - if (buf_size <= 0) { - /* Huh? An empty string? */ - fclose (f); - g_free (line); - if (error) - *error = GBR_INIT_ERROR_INVALID_MAPS; - return NULL; - } - if (line[buf_size - 1] == 10) - line[buf_size - 1] = 0; + address_string_len = 4; + address_string = (char *) g_try_malloc(address_string_len); + found = (char *) NULL; + + while (!feof(f)) { + char *start_addr, *end_addr, *end_addr_end, *file; + void *start_addr_p, *end_addr_p; + size_t len; - /* Extract the filename; it is always an absolute path. */ - path = strchr (line, '/'); + if (fgets(line, SIZE, f) == NULL) + break; /* Sanity check. */ - if (strstr (line, " r-xp ") == NULL || path == NULL) { - fclose (f); - g_free (line); - if (error) - *error = GBR_INIT_ERROR_INVALID_MAPS; - return NULL; + if (strstr(line, " r-xp ") == NULL || strchr(line, '/') == NULL) + continue; + + /* Parse line. */ + start_addr = line; + end_addr = strchr(line, '-'); + file = strchr(line, '/'); + + /* More sanity check. */ + if (!(file > end_addr && end_addr != NULL && end_addr[0] == '-')) + continue; + + end_addr[0] = '\0'; + end_addr++; + end_addr_end = strchr(end_addr, ' '); + if (end_addr_end == NULL) + continue; + + end_addr_end[0] = '\0'; + len = strlen(file); + if (len == 0) + continue; + if (file[len - 1] == '\n') + file[len - 1] = '\0'; + + /* Get rid of "(deleted)" from the filename. */ + len = strlen(file); + if (len > 10 && strcmp(file + len - 10, " (deleted)") == 0) + file[len - 10] = '\0'; + + /* I don't know whether this can happen but better safe than sorry. */ + len = strlen(start_addr); + if (len != strlen(end_addr)) + continue; + + + /* Transform the addresses into a string in the form of 0xdeadbeef, + * then transform that into a pointer. */ + if (address_string_len < len + 3) { + address_string_len = len + 3; + address_string = + (char *) g_try_realloc(address_string, address_string_len); } - path = g_strdup (path); - g_free (line); - fclose (f); - return path; -} + memcpy(address_string, "0x", 2); + memcpy(address_string + 2, start_addr, len); + address_string[2 + len] = '\0'; + sscanf(address_string, "%p", &start_addr_p); + memcpy(address_string, "0x", 2); + memcpy(address_string + 2, end_addr, len); + address_string[2 + len] = '\0'; + sscanf(address_string, "%p", &end_addr_p); -/** @internal - * Find the canonical filename of the executable which owns symbol. - * Returns a filename which must be freed, or NULL on error. - */ -static char * -_br_find_exe_for_symbol (const void *symbol, GbrInitError *error) -{ - #define SIZE PATH_MAX + 100 - FILE *f; - size_t address_string_len; - char *address_string, line[SIZE], *found; - - if (symbol == NULL) - return (char *) NULL; - - f = fopen ("/proc/self/maps", "r"); - if (f == NULL) - return (char *) NULL; - - address_string_len = 4; - address_string = (char *) g_try_malloc (address_string_len); - found = (char *) NULL; - - while (!feof (f)) { - char *start_addr, *end_addr, *end_addr_end, *file; - void *start_addr_p, *end_addr_p; - size_t len; - - if (fgets (line, SIZE, f) == NULL) - break; - - /* Sanity check. */ - if (strstr (line, " r-xp ") == NULL || strchr (line, '/') == NULL) - continue; - - /* Parse line. */ - start_addr = line; - end_addr = strchr (line, '-'); - file = strchr (line, '/'); - - /* More sanity check. */ - if (!(file > end_addr && end_addr != NULL && end_addr[0] == '-')) - continue; - - end_addr[0] = '\0'; - end_addr++; - end_addr_end = strchr (end_addr, ' '); - if (end_addr_end == NULL) - continue; - - end_addr_end[0] = '\0'; - len = strlen (file); - if (len == 0) - continue; - if (file[len - 1] == '\n') - file[len - 1] = '\0'; - - /* Get rid of "(deleted)" from the filename. */ - len = strlen (file); - if (len > 10 && strcmp (file + len - 10, " (deleted)") == 0) - file[len - 10] = '\0'; - - /* I don't know whether this can happen but better safe than sorry. */ - len = strlen (start_addr); - if (len != strlen (end_addr)) - continue; - - - /* Transform the addresses into a string in the form of 0xdeadbeef, - * then transform that into a pointer. */ - if (address_string_len < len + 3) { - address_string_len = len + 3; - address_string = (char *) g_try_realloc (address_string, address_string_len); - } - - memcpy (address_string, "0x", 2); - memcpy (address_string + 2, start_addr, len); - address_string[2 + len] = '\0'; - sscanf (address_string, "%p", &start_addr_p); - - memcpy (address_string, "0x", 2); - memcpy (address_string + 2, end_addr, len); - address_string[2 + len] = '\0'; - sscanf (address_string, "%p", &end_addr_p); - - - if (symbol >= start_addr_p && symbol < end_addr_p) { - found = file; - break; - } + + if (symbol >= start_addr_p && symbol < end_addr_p) { + found = file; + break; } + } - g_free (address_string); - fclose (f); + g_free(address_string); + fclose(f); - if (found == NULL) - return (char *) NULL; - else - return g_strdup (found); + if (found == NULL) + return (char *) NULL; + else + return g_strdup(found); } static gchar *exe = NULL; -static void set_gerror (GError **error, GbrInitError errcode); +static void set_gerror(GError ** error, GbrInitError errcode); /** Initialize the BinReloc library (for applications). @@ -281,21 +279,20 @@ static void set_gerror (GError **error, GbrInitError errcode); * * @returns TRUE on success, FALSE if BinReloc failed to initialize. */ -gboolean -gbr_init (GError **error) +gboolean gbr_init(GError ** error) { - GbrInitError errcode = 0; - - /* Locate the application's filename. */ - exe = _br_find_exe (&errcode); - if (exe != NULL) - /* Success! */ - return TRUE; - else { - /* Failed :-( */ - set_gerror (error, errcode); - return FALSE; - } + GbrInitError errcode = 0; + + /* Locate the application's filename. */ + exe = _br_find_exe(&errcode); + if (exe != NULL) + /* Success! */ + return TRUE; + else { + /* Failed :-( */ + set_gerror(error, errcode); + return FALSE; + } } @@ -309,53 +306,51 @@ gbr_init (GError **error) * * @returns TRUE on success, FALSE if a filename cannot be found. */ -gboolean -gbr_init_lib (GError **error) +gboolean gbr_init_lib(GError ** error) { - GbrInitError errcode = 0; - - exe = _br_find_exe_for_symbol ((const void *) "", &errcode); - if (exe != NULL) - /* Success! */ - return TRUE; - else { - /* Failed :-( */ - set_gerror (error, errcode); - return exe != NULL; - } + GbrInitError errcode = 0; + + exe = _br_find_exe_for_symbol((const void *) "", &errcode); + if (exe != NULL) + /* Success! */ + return TRUE; + else { + /* Failed :-( */ + set_gerror(error, errcode); + return exe != NULL; + } } -static void -set_gerror (GError **error, GbrInitError errcode) +static void set_gerror(GError ** error, GbrInitError errcode) { - gchar *error_message; - - if (error == NULL) - return; - - switch (errcode) { - case GBR_INIT_ERROR_NOMEM: - error_message = "Cannot allocate memory."; - break; - case GBR_INIT_ERROR_OPEN_MAPS: - error_message = "Unable to open /proc/self/maps for reading."; - break; - case GBR_INIT_ERROR_READ_MAPS: - error_message = "Unable to read from /proc/self/maps."; - break; - case GBR_INIT_ERROR_INVALID_MAPS: - error_message = "The file format of /proc/self/maps is invalid."; - break; - case GBR_INIT_ERROR_DISABLED: - error_message = "Binary relocation support is disabled."; - break; - default: - error_message = "Unknown error."; - break; - }; - g_set_error (error, g_quark_from_static_string ("GBinReloc"), - errcode, "%s", error_message); + gchar *error_message; + + if (error == NULL) + return; + + switch (errcode) { + case GBR_INIT_ERROR_NOMEM: + error_message = "Cannot allocate memory."; + break; + case GBR_INIT_ERROR_OPEN_MAPS: + error_message = "Unable to open /proc/self/maps for reading."; + break; + case GBR_INIT_ERROR_READ_MAPS: + error_message = "Unable to read from /proc/self/maps."; + break; + case GBR_INIT_ERROR_INVALID_MAPS: + error_message = "The file format of /proc/self/maps is invalid."; + break; + case GBR_INIT_ERROR_DISABLED: + error_message = "Binary relocation support is disabled."; + break; + default: + error_message = "Unknown error."; + break; + }; + g_set_error(error, g_quark_from_static_string("GBinReloc"), + errcode, "%s", error_message); } @@ -368,17 +363,16 @@ set_gerror (GError **error, GbrInitError errcode) * then a copy of default_exe will be returned. If default_exe * is NULL, then NULL will be returned. */ -gchar * -gbr_find_exe (const gchar *default_exe) +gchar *gbr_find_exe(const gchar * default_exe) { - if (exe == NULL) { - /* BinReloc is not initialized. */ - if (default_exe != NULL) - return g_strdup (default_exe); - else - return NULL; - } - return g_strdup (exe); + if (exe == NULL) { + /* BinReloc is not initialized. */ + if (default_exe != NULL) + return g_strdup(default_exe); + else + return NULL; + } + return g_strdup(exe); } @@ -396,18 +390,17 @@ gbr_find_exe (const gchar *default_exe) * will be returned. If default_dir is NULL, then NULL will be * returned. */ -gchar * -gbr_find_exe_dir (const gchar *default_dir) +gchar *gbr_find_exe_dir(const gchar * default_dir) { - if (exe == NULL) { - /* BinReloc not initialized. */ - if (default_dir != NULL) - return g_strdup (default_dir); - else - return NULL; - } + if (exe == NULL) { + /* BinReloc not initialized. */ + if (default_dir != NULL) + return g_strdup(default_dir); + else + return NULL; + } - return g_path_get_dirname (exe); + return g_path_get_dirname(exe); } @@ -425,23 +418,22 @@ gbr_find_exe_dir (const gchar *default_dir) * will be returned. If default_prefix is NULL, then NULL will be * returned. */ -gchar * -gbr_find_prefix (const gchar *default_prefix) +gchar *gbr_find_prefix(const gchar * default_prefix) { - gchar *dir1, *dir2; - - if (exe == NULL) { - /* BinReloc not initialized. */ - if (default_prefix != NULL) - return g_strdup (default_prefix); - else - return NULL; - } + gchar *dir1, *dir2; - dir1 = g_path_get_dirname (exe); - dir2 = g_path_get_dirname (dir1); - g_free (dir1); - return dir2; + if (exe == NULL) { + /* BinReloc not initialized. */ + if (default_prefix != NULL) + return g_strdup(default_prefix); + else + return NULL; + } + + dir1 = g_path_get_dirname(exe); + dir2 = g_path_get_dirname(dir1); + g_free(dir1); + return dir2; } @@ -458,23 +450,22 @@ gbr_find_prefix (const gchar *default_prefix) * initialization function failed, then a copy of default_bin_dir will * be returned. If default_bin_dir is NULL, then NULL will be returned. */ -gchar * -gbr_find_bin_dir (const gchar *default_bin_dir) +gchar *gbr_find_bin_dir(const gchar * default_bin_dir) { - gchar *prefix, *dir; - - prefix = gbr_find_prefix (NULL); - if (prefix == NULL) { - /* BinReloc not initialized. */ - if (default_bin_dir != NULL) - return g_strdup (default_bin_dir); - else - return NULL; - } + gchar *prefix, *dir; + + prefix = gbr_find_prefix(NULL); + if (prefix == NULL) { + /* BinReloc not initialized. */ + if (default_bin_dir != NULL) + return g_strdup(default_bin_dir); + else + return NULL; + } - dir = g_build_filename (prefix, "bin", NULL); - g_free (prefix); - return dir; + dir = g_build_filename(prefix, "bin", NULL); + g_free(prefix); + return dir; } @@ -491,23 +482,22 @@ gbr_find_bin_dir (const gchar *default_bin_dir) * initialization function failed, then a copy of default_sbin_dir will * be returned. If default_bin_dir is NULL, then NULL will be returned. */ -gchar * -gbr_find_sbin_dir (const gchar *default_sbin_dir) +gchar *gbr_find_sbin_dir(const gchar * default_sbin_dir) { - gchar *prefix, *dir; - - prefix = gbr_find_prefix (NULL); - if (prefix == NULL) { - /* BinReloc not initialized. */ - if (default_sbin_dir != NULL) - return g_strdup (default_sbin_dir); - else - return NULL; - } + gchar *prefix, *dir; + + prefix = gbr_find_prefix(NULL); + if (prefix == NULL) { + /* BinReloc not initialized. */ + if (default_sbin_dir != NULL) + return g_strdup(default_sbin_dir); + else + return NULL; + } - dir = g_build_filename (prefix, "sbin", NULL); - g_free (prefix); - return dir; + dir = g_build_filename(prefix, "sbin", NULL); + g_free(prefix); + return dir; } @@ -525,23 +515,22 @@ gbr_find_sbin_dir (const gchar *default_sbin_dir) * will be returned. If default_data_dir is NULL, then NULL will be * returned. */ -gchar * -gbr_find_data_dir (const gchar *default_data_dir) +gchar *gbr_find_data_dir(const gchar * default_data_dir) { - gchar *prefix, *dir; - - prefix = gbr_find_prefix (NULL); - if (prefix == NULL) { - /* BinReloc not initialized. */ - if (default_data_dir != NULL) - return g_strdup (default_data_dir); - else - return NULL; - } + gchar *prefix, *dir; + + prefix = gbr_find_prefix(NULL); + if (prefix == NULL) { + /* BinReloc not initialized. */ + if (default_data_dir != NULL) + return g_strdup(default_data_dir); + else + return NULL; + } - dir = g_build_filename (prefix, "share", NULL); - g_free (prefix); - return dir; + dir = g_build_filename(prefix, "share", NULL); + g_free(prefix); + return dir; } @@ -558,23 +547,22 @@ gbr_find_data_dir (const gchar *default_data_dir) * initialization function failed, then a copy of default_locale_dir will be returned. * If default_locale_dir is NULL, then NULL will be returned. */ -gchar * -gbr_find_locale_dir (const gchar *default_locale_dir) +gchar *gbr_find_locale_dir(const gchar * default_locale_dir) { - gchar *data_dir, *dir; - - data_dir = gbr_find_data_dir (NULL); - if (data_dir == NULL) { - /* BinReloc not initialized. */ - if (default_locale_dir != NULL) - return g_strdup (default_locale_dir); - else - return NULL; - } + gchar *data_dir, *dir; + + data_dir = gbr_find_data_dir(NULL); + if (data_dir == NULL) { + /* BinReloc not initialized. */ + if (default_locale_dir != NULL) + return g_strdup(default_locale_dir); + else + return NULL; + } - dir = g_build_filename (data_dir, "locale", NULL); - g_free (data_dir); - return dir; + dir = g_build_filename(data_dir, "locale", NULL); + g_free(data_dir); + return dir; } @@ -591,23 +579,22 @@ gbr_find_locale_dir (const gchar *default_locale_dir) * initialization function failed, then a copy of default_lib_dir will be returned. * If default_lib_dir is NULL, then NULL will be returned. */ -gchar * -gbr_find_lib_dir (const gchar *default_lib_dir) +gchar *gbr_find_lib_dir(const gchar * default_lib_dir) { - gchar *prefix, *dir; - - prefix = gbr_find_prefix (NULL); - if (prefix == NULL) { - /* BinReloc not initialized. */ - if (default_lib_dir != NULL) - return g_strdup (default_lib_dir); - else - return NULL; - } + gchar *prefix, *dir; - dir = g_build_filename (prefix, "lib", NULL); - g_free (prefix); - return dir; + prefix = gbr_find_prefix(NULL); + if (prefix == NULL) { + /* BinReloc not initialized. */ + if (default_lib_dir != NULL) + return g_strdup(default_lib_dir); + else + return NULL; + } + + dir = g_build_filename(prefix, "lib", NULL); + g_free(prefix); + return dir; } @@ -624,23 +611,22 @@ gbr_find_lib_dir (const gchar *default_lib_dir) * function failed, then a copy of default_libexec_dir will be returned. * If default_libexec_dir is NULL, then NULL will be returned. */ -gchar * -gbr_find_libexec_dir (const gchar *default_libexec_dir) +gchar *gbr_find_libexec_dir(const gchar * default_libexec_dir) { - gchar *prefix, *dir; - - prefix = gbr_find_prefix (NULL); - if (prefix == NULL) { - /* BinReloc not initialized. */ - if (default_libexec_dir != NULL) - return g_strdup (default_libexec_dir); - else - return NULL; - } + gchar *prefix, *dir; - dir = g_build_filename (prefix, "libexec", NULL); - g_free (prefix); - return dir; + prefix = gbr_find_prefix(NULL); + if (prefix == NULL) { + /* BinReloc not initialized. */ + if (default_libexec_dir != NULL) + return g_strdup(default_libexec_dir); + else + return NULL; + } + + dir = g_build_filename(prefix, "libexec", NULL); + g_free(prefix); + return dir; } @@ -657,26 +643,24 @@ gbr_find_libexec_dir (const gchar *default_libexec_dir) * function failed, then a copy of default_etc_dir will be returned. * If default_etc_dir is NULL, then NULL will be returned. */ -gchar * -gbr_find_etc_dir (const gchar *default_etc_dir) +gchar *gbr_find_etc_dir(const gchar * default_etc_dir) { - gchar *prefix, *dir; - - prefix = gbr_find_prefix (NULL); - if (prefix == NULL) { - /* BinReloc not initialized. */ - if (default_etc_dir != NULL) - return g_strdup (default_etc_dir); - else - return NULL; - } + gchar *prefix, *dir; - dir = g_build_filename (prefix, "etc", NULL); - g_free (prefix); - return dir; + prefix = gbr_find_prefix(NULL); + if (prefix == NULL) { + /* BinReloc not initialized. */ + if (default_etc_dir != NULL) + return g_strdup(default_etc_dir); + else + return NULL; + } + + dir = g_build_filename(prefix, "etc", NULL); + g_free(prefix); + return dir; } G_END_DECLS - -#endif /* __BINRELOC_C__ */ +#endif /* __BINRELOC_C__ */ @@ -53,399 +53,435 @@ can be located using your favorite search engine.) Unfortunately, I do not have time to provide unpaid support for everyone who uses this code.
-- Paul Kocher
-*/
-
-
+*/
+
#include "blowfish.h"
-
+
#define N 16
-
-static const unsigned long ORIG_P[16 + 2] = {
- 0x243F6A88L, 0x85A308D3L, 0x13198A2EL, 0x03707344L,
- 0xA4093822L, 0x299F31D0L, 0x082EFA98L, 0xEC4E6C89L,
- 0x452821E6L, 0x38D01377L, 0xBE5466CFL, 0x34E90C6CL,
- 0xC0AC29B7L, 0xC97C50DDL, 0x3F84D5B5L, 0xB5470917L,
- 0x9216D5D9L, 0x8979FB1BL
-};
-
-static const unsigned long ORIG_S[4][256] = {
- { 0xD1310BA6L, 0x98DFB5ACL, 0x2FFD72DBL, 0xD01ADFB7L,
- 0xB8E1AFEDL, 0x6A267E96L, 0xBA7C9045L, 0xF12C7F99L,
- 0x24A19947L, 0xB3916CF7L, 0x0801F2E2L, 0x858EFC16L,
- 0x636920D8L, 0x71574E69L, 0xA458FEA3L, 0xF4933D7EL,
- 0x0D95748FL, 0x728EB658L, 0x718BCD58L, 0x82154AEEL,
- 0x7B54A41DL, 0xC25A59B5L, 0x9C30D539L, 0x2AF26013L,
- 0xC5D1B023L, 0x286085F0L, 0xCA417918L, 0xB8DB38EFL,
- 0x8E79DCB0L, 0x603A180EL, 0x6C9E0E8BL, 0xB01E8A3EL,
- 0xD71577C1L, 0xBD314B27L, 0x78AF2FDAL, 0x55605C60L,
- 0xE65525F3L, 0xAA55AB94L, 0x57489862L, 0x63E81440L,
- 0x55CA396AL, 0x2AAB10B6L, 0xB4CC5C34L, 0x1141E8CEL,
- 0xA15486AFL, 0x7C72E993L, 0xB3EE1411L, 0x636FBC2AL,
- 0x2BA9C55DL, 0x741831F6L, 0xCE5C3E16L, 0x9B87931EL,
- 0xAFD6BA33L, 0x6C24CF5CL, 0x7A325381L, 0x28958677L,
- 0x3B8F4898L, 0x6B4BB9AFL, 0xC4BFE81BL, 0x66282193L,
- 0x61D809CCL, 0xFB21A991L, 0x487CAC60L, 0x5DEC8032L,
- 0xEF845D5DL, 0xE98575B1L, 0xDC262302L, 0xEB651B88L,
- 0x23893E81L, 0xD396ACC5L, 0x0F6D6FF3L, 0x83F44239L,
- 0x2E0B4482L, 0xA4842004L, 0x69C8F04AL, 0x9E1F9B5EL,
- 0x21C66842L, 0xF6E96C9AL, 0x670C9C61L, 0xABD388F0L,
- 0x6A51A0D2L, 0xD8542F68L, 0x960FA728L, 0xAB5133A3L,
- 0x6EEF0B6CL, 0x137A3BE4L, 0xBA3BF050L, 0x7EFB2A98L,
- 0xA1F1651DL, 0x39AF0176L, 0x66CA593EL, 0x82430E88L,
- 0x8CEE8619L, 0x456F9FB4L, 0x7D84A5C3L, 0x3B8B5EBEL,
- 0xE06F75D8L, 0x85C12073L, 0x401A449FL, 0x56C16AA6L,
- 0x4ED3AA62L, 0x363F7706L, 0x1BFEDF72L, 0x429B023DL,
- 0x37D0D724L, 0xD00A1248L, 0xDB0FEAD3L, 0x49F1C09BL,
- 0x075372C9L, 0x80991B7BL, 0x25D479D8L, 0xF6E8DEF7L,
- 0xE3FE501AL, 0xB6794C3BL, 0x976CE0BDL, 0x04C006BAL,
- 0xC1A94FB6L, 0x409F60C4L, 0x5E5C9EC2L, 0x196A2463L,
- 0x68FB6FAFL, 0x3E6C53B5L, 0x1339B2EBL, 0x3B52EC6FL,
- 0x6DFC511FL, 0x9B30952CL, 0xCC814544L, 0xAF5EBD09L,
- 0xBEE3D004L, 0xDE334AFDL, 0x660F2807L, 0x192E4BB3L,
- 0xC0CBA857L, 0x45C8740FL, 0xD20B5F39L, 0xB9D3FBDBL,
- 0x5579C0BDL, 0x1A60320AL, 0xD6A100C6L, 0x402C7279L,
- 0x679F25FEL, 0xFB1FA3CCL, 0x8EA5E9F8L, 0xDB3222F8L,
- 0x3C7516DFL, 0xFD616B15L, 0x2F501EC8L, 0xAD0552ABL,
- 0x323DB5FAL, 0xFD238760L, 0x53317B48L, 0x3E00DF82L,
- 0x9E5C57BBL, 0xCA6F8CA0L, 0x1A87562EL, 0xDF1769DBL,
- 0xD542A8F6L, 0x287EFFC3L, 0xAC6732C6L, 0x8C4F5573L,
- 0x695B27B0L, 0xBBCA58C8L, 0xE1FFA35DL, 0xB8F011A0L,
- 0x10FA3D98L, 0xFD2183B8L, 0x4AFCB56CL, 0x2DD1D35BL,
- 0x9A53E479L, 0xB6F84565L, 0xD28E49BCL, 0x4BFB9790L,
- 0xE1DDF2DAL, 0xA4CB7E33L, 0x62FB1341L, 0xCEE4C6E8L,
- 0xEF20CADAL, 0x36774C01L, 0xD07E9EFEL, 0x2BF11FB4L,
- 0x95DBDA4DL, 0xAE909198L, 0xEAAD8E71L, 0x6B93D5A0L,
- 0xD08ED1D0L, 0xAFC725E0L, 0x8E3C5B2FL, 0x8E7594B7L,
- 0x8FF6E2FBL, 0xF2122B64L, 0x8888B812L, 0x900DF01CL,
- 0x4FAD5EA0L, 0x688FC31CL, 0xD1CFF191L, 0xB3A8C1ADL,
- 0x2F2F2218L, 0xBE0E1777L, 0xEA752DFEL, 0x8B021FA1L,
- 0xE5A0CC0FL, 0xB56F74E8L, 0x18ACF3D6L, 0xCE89E299L,
- 0xB4A84FE0L, 0xFD13E0B7L, 0x7CC43B81L, 0xD2ADA8D9L,
- 0x165FA266L, 0x80957705L, 0x93CC7314L, 0x211A1477L,
- 0xE6AD2065L, 0x77B5FA86L, 0xC75442F5L, 0xFB9D35CFL,
- 0xEBCDAF0CL, 0x7B3E89A0L, 0xD6411BD3L, 0xAE1E7E49L,
- 0x00250E2DL, 0x2071B35EL, 0x226800BBL, 0x57B8E0AFL,
- 0x2464369BL, 0xF009B91EL, 0x5563911DL, 0x59DFA6AAL,
- 0x78C14389L, 0xD95A537FL, 0x207D5BA2L, 0x02E5B9C5L,
- 0x83260376L, 0x6295CFA9L, 0x11C81968L, 0x4E734A41L,
- 0xB3472DCAL, 0x7B14A94AL, 0x1B510052L, 0x9A532915L,
- 0xD60F573FL, 0xBC9BC6E4L, 0x2B60A476L, 0x81E67400L,
- 0x08BA6FB5L, 0x571BE91FL, 0xF296EC6BL, 0x2A0DD915L,
- 0xB6636521L, 0xE7B9F9B6L, 0xFF34052EL, 0xC5855664L,
- 0x53B02D5DL, 0xA99F8FA1L, 0x08BA4799L, 0x6E85076AL },
- { 0x4B7A70E9L, 0xB5B32944L, 0xDB75092EL, 0xC4192623L,
- 0xAD6EA6B0L, 0x49A7DF7DL, 0x9CEE60B8L, 0x8FEDB266L,
- 0xECAA8C71L, 0x699A17FFL, 0x5664526CL, 0xC2B19EE1L,
- 0x193602A5L, 0x75094C29L, 0xA0591340L, 0xE4183A3EL,
- 0x3F54989AL, 0x5B429D65L, 0x6B8FE4D6L, 0x99F73FD6L,
- 0xA1D29C07L, 0xEFE830F5L, 0x4D2D38E6L, 0xF0255DC1L,
- 0x4CDD2086L, 0x8470EB26L, 0x6382E9C6L, 0x021ECC5EL,
- 0x09686B3FL, 0x3EBAEFC9L, 0x3C971814L, 0x6B6A70A1L,
- 0x687F3584L, 0x52A0E286L, 0xB79C5305L, 0xAA500737L,
- 0x3E07841CL, 0x7FDEAE5CL, 0x8E7D44ECL, 0x5716F2B8L,
- 0xB03ADA37L, 0xF0500C0DL, 0xF01C1F04L, 0x0200B3FFL,
- 0xAE0CF51AL, 0x3CB574B2L, 0x25837A58L, 0xDC0921BDL,
- 0xD19113F9L, 0x7CA92FF6L, 0x94324773L, 0x22F54701L,
- 0x3AE5E581L, 0x37C2DADCL, 0xC8B57634L, 0x9AF3DDA7L,
- 0xA9446146L, 0x0FD0030EL, 0xECC8C73EL, 0xA4751E41L,
- 0xE238CD99L, 0x3BEA0E2FL, 0x3280BBA1L, 0x183EB331L,
- 0x4E548B38L, 0x4F6DB908L, 0x6F420D03L, 0xF60A04BFL,
- 0x2CB81290L, 0x24977C79L, 0x5679B072L, 0xBCAF89AFL,
- 0xDE9A771FL, 0xD9930810L, 0xB38BAE12L, 0xDCCF3F2EL,
- 0x5512721FL, 0x2E6B7124L, 0x501ADDE6L, 0x9F84CD87L,
- 0x7A584718L, 0x7408DA17L, 0xBC9F9ABCL, 0xE94B7D8CL,
- 0xEC7AEC3AL, 0xDB851DFAL, 0x63094366L, 0xC464C3D2L,
- 0xEF1C1847L, 0x3215D908L, 0xDD433B37L, 0x24C2BA16L,
- 0x12A14D43L, 0x2A65C451L, 0x50940002L, 0x133AE4DDL,
- 0x71DFF89EL, 0x10314E55L, 0x81AC77D6L, 0x5F11199BL,
- 0x043556F1L, 0xD7A3C76BL, 0x3C11183BL, 0x5924A509L,
- 0xF28FE6EDL, 0x97F1FBFAL, 0x9EBABF2CL, 0x1E153C6EL,
- 0x86E34570L, 0xEAE96FB1L, 0x860E5E0AL, 0x5A3E2AB3L,
- 0x771FE71CL, 0x4E3D06FAL, 0x2965DCB9L, 0x99E71D0FL,
- 0x803E89D6L, 0x5266C825L, 0x2E4CC978L, 0x9C10B36AL,
- 0xC6150EBAL, 0x94E2EA78L, 0xA5FC3C53L, 0x1E0A2DF4L,
- 0xF2F74EA7L, 0x361D2B3DL, 0x1939260FL, 0x19C27960L,
- 0x5223A708L, 0xF71312B6L, 0xEBADFE6EL, 0xEAC31F66L,
- 0xE3BC4595L, 0xA67BC883L, 0xB17F37D1L, 0x018CFF28L,
- 0xC332DDEFL, 0xBE6C5AA5L, 0x65582185L, 0x68AB9802L,
- 0xEECEA50FL, 0xDB2F953BL, 0x2AEF7DADL, 0x5B6E2F84L,
- 0x1521B628L, 0x29076170L, 0xECDD4775L, 0x619F1510L,
- 0x13CCA830L, 0xEB61BD96L, 0x0334FE1EL, 0xAA0363CFL,
- 0xB5735C90L, 0x4C70A239L, 0xD59E9E0BL, 0xCBAADE14L,
- 0xEECC86BCL, 0x60622CA7L, 0x9CAB5CABL, 0xB2F3846EL,
- 0x648B1EAFL, 0x19BDF0CAL, 0xA02369B9L, 0x655ABB50L,
- 0x40685A32L, 0x3C2AB4B3L, 0x319EE9D5L, 0xC021B8F7L,
- 0x9B540B19L, 0x875FA099L, 0x95F7997EL, 0x623D7DA8L,
- 0xF837889AL, 0x97E32D77L, 0x11ED935FL, 0x16681281L,
- 0x0E358829L, 0xC7E61FD6L, 0x96DEDFA1L, 0x7858BA99L,
- 0x57F584A5L, 0x1B227263L, 0x9B83C3FFL, 0x1AC24696L,
- 0xCDB30AEBL, 0x532E3054L, 0x8FD948E4L, 0x6DBC3128L,
- 0x58EBF2EFL, 0x34C6FFEAL, 0xFE28ED61L, 0xEE7C3C73L,
- 0x5D4A14D9L, 0xE864B7E3L, 0x42105D14L, 0x203E13E0L,
- 0x45EEE2B6L, 0xA3AAABEAL, 0xDB6C4F15L, 0xFACB4FD0L,
- 0xC742F442L, 0xEF6ABBB5L, 0x654F3B1DL, 0x41CD2105L,
- 0xD81E799EL, 0x86854DC7L, 0xE44B476AL, 0x3D816250L,
- 0xCF62A1F2L, 0x5B8D2646L, 0xFC8883A0L, 0xC1C7B6A3L,
- 0x7F1524C3L, 0x69CB7492L, 0x47848A0BL, 0x5692B285L,
- 0x095BBF00L, 0xAD19489DL, 0x1462B174L, 0x23820E00L,
- 0x58428D2AL, 0x0C55F5EAL, 0x1DADF43EL, 0x233F7061L,
- 0x3372F092L, 0x8D937E41L, 0xD65FECF1L, 0x6C223BDBL,
- 0x7CDE3759L, 0xCBEE7460L, 0x4085F2A7L, 0xCE77326EL,
- 0xA6078084L, 0x19F8509EL, 0xE8EFD855L, 0x61D99735L,
- 0xA969A7AAL, 0xC50C06C2L, 0x5A04ABFCL, 0x800BCADCL,
- 0x9E447A2EL, 0xC3453484L, 0xFDD56705L, 0x0E1E9EC9L,
- 0xDB73DBD3L, 0x105588CDL, 0x675FDA79L, 0xE3674340L,
- 0xC5C43465L, 0x713E38D8L, 0x3D28F89EL, 0xF16DFF20L,
- 0x153E21E7L, 0x8FB03D4AL, 0xE6E39F2BL, 0xDB83ADF7L },
- { 0xE93D5A68L, 0x948140F7L, 0xF64C261CL, 0x94692934L,
- 0x411520F7L, 0x7602D4F7L, 0xBCF46B2EL, 0xD4A20068L,
- 0xD4082471L, 0x3320F46AL, 0x43B7D4B7L, 0x500061AFL,
- 0x1E39F62EL, 0x97244546L, 0x14214F74L, 0xBF8B8840L,
- 0x4D95FC1DL, 0x96B591AFL, 0x70F4DDD3L, 0x66A02F45L,
- 0xBFBC09ECL, 0x03BD9785L, 0x7FAC6DD0L, 0x31CB8504L,
- 0x96EB27B3L, 0x55FD3941L, 0xDA2547E6L, 0xABCA0A9AL,
- 0x28507825L, 0x530429F4L, 0x0A2C86DAL, 0xE9B66DFBL,
- 0x68DC1462L, 0xD7486900L, 0x680EC0A4L, 0x27A18DEEL,
- 0x4F3FFEA2L, 0xE887AD8CL, 0xB58CE006L, 0x7AF4D6B6L,
- 0xAACE1E7CL, 0xD3375FECL, 0xCE78A399L, 0x406B2A42L,
- 0x20FE9E35L, 0xD9F385B9L, 0xEE39D7ABL, 0x3B124E8BL,
- 0x1DC9FAF7L, 0x4B6D1856L, 0x26A36631L, 0xEAE397B2L,
- 0x3A6EFA74L, 0xDD5B4332L, 0x6841E7F7L, 0xCA7820FBL,
- 0xFB0AF54EL, 0xD8FEB397L, 0x454056ACL, 0xBA489527L,
- 0x55533A3AL, 0x20838D87L, 0xFE6BA9B7L, 0xD096954BL,
- 0x55A867BCL, 0xA1159A58L, 0xCCA92963L, 0x99E1DB33L,
- 0xA62A4A56L, 0x3F3125F9L, 0x5EF47E1CL, 0x9029317CL,
- 0xFDF8E802L, 0x04272F70L, 0x80BB155CL, 0x05282CE3L,
- 0x95C11548L, 0xE4C66D22L, 0x48C1133FL, 0xC70F86DCL,
- 0x07F9C9EEL, 0x41041F0FL, 0x404779A4L, 0x5D886E17L,
- 0x325F51EBL, 0xD59BC0D1L, 0xF2BCC18FL, 0x41113564L,
- 0x257B7834L, 0x602A9C60L, 0xDFF8E8A3L, 0x1F636C1BL,
- 0x0E12B4C2L, 0x02E1329EL, 0xAF664FD1L, 0xCAD18115L,
- 0x6B2395E0L, 0x333E92E1L, 0x3B240B62L, 0xEEBEB922L,
- 0x85B2A20EL, 0xE6BA0D99L, 0xDE720C8CL, 0x2DA2F728L,
- 0xD0127845L, 0x95B794FDL, 0x647D0862L, 0xE7CCF5F0L,
- 0x5449A36FL, 0x877D48FAL, 0xC39DFD27L, 0xF33E8D1EL,
- 0x0A476341L, 0x992EFF74L, 0x3A6F6EABL, 0xF4F8FD37L,
- 0xA812DC60L, 0xA1EBDDF8L, 0x991BE14CL, 0xDB6E6B0DL,
- 0xC67B5510L, 0x6D672C37L, 0x2765D43BL, 0xDCD0E804L,
- 0xF1290DC7L, 0xCC00FFA3L, 0xB5390F92L, 0x690FED0BL,
- 0x667B9FFBL, 0xCEDB7D9CL, 0xA091CF0BL, 0xD9155EA3L,
- 0xBB132F88L, 0x515BAD24L, 0x7B9479BFL, 0x763BD6EBL,
- 0x37392EB3L, 0xCC115979L, 0x8026E297L, 0xF42E312DL,
- 0x6842ADA7L, 0xC66A2B3BL, 0x12754CCCL, 0x782EF11CL,
- 0x6A124237L, 0xB79251E7L, 0x06A1BBE6L, 0x4BFB6350L,
- 0x1A6B1018L, 0x11CAEDFAL, 0x3D25BDD8L, 0xE2E1C3C9L,
- 0x44421659L, 0x0A121386L, 0xD90CEC6EL, 0xD5ABEA2AL,
- 0x64AF674EL, 0xDA86A85FL, 0xBEBFE988L, 0x64E4C3FEL,
- 0x9DBC8057L, 0xF0F7C086L, 0x60787BF8L, 0x6003604DL,
- 0xD1FD8346L, 0xF6381FB0L, 0x7745AE04L, 0xD736FCCCL,
- 0x83426B33L, 0xF01EAB71L, 0xB0804187L, 0x3C005E5FL,
- 0x77A057BEL, 0xBDE8AE24L, 0x55464299L, 0xBF582E61L,
- 0x4E58F48FL, 0xF2DDFDA2L, 0xF474EF38L, 0x8789BDC2L,
- 0x5366F9C3L, 0xC8B38E74L, 0xB475F255L, 0x46FCD9B9L,
- 0x7AEB2661L, 0x8B1DDF84L, 0x846A0E79L, 0x915F95E2L,
- 0x466E598EL, 0x20B45770L, 0x8CD55591L, 0xC902DE4CL,
- 0xB90BACE1L, 0xBB8205D0L, 0x11A86248L, 0x7574A99EL,
- 0xB77F19B6L, 0xE0A9DC09L, 0x662D09A1L, 0xC4324633L,
- 0xE85A1F02L, 0x09F0BE8CL, 0x4A99A025L, 0x1D6EFE10L,
- 0x1AB93D1DL, 0x0BA5A4DFL, 0xA186F20FL, 0x2868F169L,
- 0xDCB7DA83L, 0x573906FEL, 0xA1E2CE9BL, 0x4FCD7F52L,
- 0x50115E01L, 0xA70683FAL, 0xA002B5C4L, 0x0DE6D027L,
- 0x9AF88C27L, 0x773F8641L, 0xC3604C06L, 0x61A806B5L,
- 0xF0177A28L, 0xC0F586E0L, 0x006058AAL, 0x30DC7D62L,
- 0x11E69ED7L, 0x2338EA63L, 0x53C2DD94L, 0xC2C21634L,
- 0xBBCBEE56L, 0x90BCB6DEL, 0xEBFC7DA1L, 0xCE591D76L,
- 0x6F05E409L, 0x4B7C0188L, 0x39720A3DL, 0x7C927C24L,
- 0x86E3725FL, 0x724D9DB9L, 0x1AC15BB4L, 0xD39EB8FCL,
- 0xED545578L, 0x08FCA5B5L, 0xD83D7CD3L, 0x4DAD0FC4L,
- 0x1E50EF5EL, 0xB161E6F8L, 0xA28514D9L, 0x6C51133CL,
- 0x6FD5C7E7L, 0x56E14EC4L, 0x362ABFCEL, 0xDDC6C837L,
- 0xD79A3234L, 0x92638212L, 0x670EFA8EL, 0x406000E0L },
- { 0x3A39CE37L, 0xD3FAF5CFL, 0xABC27737L, 0x5AC52D1BL,
- 0x5CB0679EL, 0x4FA33742L, 0xD3822740L, 0x99BC9BBEL,
- 0xD5118E9DL, 0xBF0F7315L, 0xD62D1C7EL, 0xC700C47BL,
- 0xB78C1B6BL, 0x21A19045L, 0xB26EB1BEL, 0x6A366EB4L,
- 0x5748AB2FL, 0xBC946E79L, 0xC6A376D2L, 0x6549C2C8L,
- 0x530FF8EEL, 0x468DDE7DL, 0xD5730A1DL, 0x4CD04DC6L,
- 0x2939BBDBL, 0xA9BA4650L, 0xAC9526E8L, 0xBE5EE304L,
- 0xA1FAD5F0L, 0x6A2D519AL, 0x63EF8CE2L, 0x9A86EE22L,
- 0xC089C2B8L, 0x43242EF6L, 0xA51E03AAL, 0x9CF2D0A4L,
- 0x83C061BAL, 0x9BE96A4DL, 0x8FE51550L, 0xBA645BD6L,
- 0x2826A2F9L, 0xA73A3AE1L, 0x4BA99586L, 0xEF5562E9L,
- 0xC72FEFD3L, 0xF752F7DAL, 0x3F046F69L, 0x77FA0A59L,
- 0x80E4A915L, 0x87B08601L, 0x9B09E6ADL, 0x3B3EE593L,
- 0xE990FD5AL, 0x9E34D797L, 0x2CF0B7D9L, 0x022B8B51L,
- 0x96D5AC3AL, 0x017DA67DL, 0xD1CF3ED6L, 0x7C7D2D28L,
- 0x1F9F25CFL, 0xADF2B89BL, 0x5AD6B472L, 0x5A88F54CL,
- 0xE029AC71L, 0xE019A5E6L, 0x47B0ACFDL, 0xED93FA9BL,
- 0xE8D3C48DL, 0x283B57CCL, 0xF8D56629L, 0x79132E28L,
- 0x785F0191L, 0xED756055L, 0xF7960E44L, 0xE3D35E8CL,
- 0x15056DD4L, 0x88F46DBAL, 0x03A16125L, 0x0564F0BDL,
- 0xC3EB9E15L, 0x3C9057A2L, 0x97271AECL, 0xA93A072AL,
- 0x1B3F6D9BL, 0x1E6321F5L, 0xF59C66FBL, 0x26DCF319L,
- 0x7533D928L, 0xB155FDF5L, 0x03563482L, 0x8ABA3CBBL,
- 0x28517711L, 0xC20AD9F8L, 0xABCC5167L, 0xCCAD925FL,
- 0x4DE81751L, 0x3830DC8EL, 0x379D5862L, 0x9320F991L,
- 0xEA7A90C2L, 0xFB3E7BCEL, 0x5121CE64L, 0x774FBE32L,
- 0xA8B6E37EL, 0xC3293D46L, 0x48DE5369L, 0x6413E680L,
- 0xA2AE0810L, 0xDD6DB224L, 0x69852DFDL, 0x09072166L,
- 0xB39A460AL, 0x6445C0DDL, 0x586CDECFL, 0x1C20C8AEL,
- 0x5BBEF7DDL, 0x1B588D40L, 0xCCD2017FL, 0x6BB4E3BBL,
- 0xDDA26A7EL, 0x3A59FF45L, 0x3E350A44L, 0xBCB4CDD5L,
- 0x72EACEA8L, 0xFA6484BBL, 0x8D6612AEL, 0xBF3C6F47L,
- 0xD29BE463L, 0x542F5D9EL, 0xAEC2771BL, 0xF64E6370L,
- 0x740E0D8DL, 0xE75B1357L, 0xF8721671L, 0xAF537D5DL,
- 0x4040CB08L, 0x4EB4E2CCL, 0x34D2466AL, 0x0115AF84L,
- 0xE1B00428L, 0x95983A1DL, 0x06B89FB4L, 0xCE6EA048L,
- 0x6F3F3B82L, 0x3520AB82L, 0x011A1D4BL, 0x277227F8L,
- 0x611560B1L, 0xE7933FDCL, 0xBB3A792BL, 0x344525BDL,
- 0xA08839E1L, 0x51CE794BL, 0x2F32C9B7L, 0xA01FBAC9L,
- 0xE01CC87EL, 0xBCC7D1F6L, 0xCF0111C3L, 0xA1E8AAC7L,
- 0x1A908749L, 0xD44FBD9AL, 0xD0DADECBL, 0xD50ADA38L,
- 0x0339C32AL, 0xC6913667L, 0x8DF9317CL, 0xE0B12B4FL,
- 0xF79E59B7L, 0x43F5BB3AL, 0xF2D519FFL, 0x27D9459CL,
- 0xBF97222CL, 0x15E6FC2AL, 0x0F91FC71L, 0x9B941525L,
- 0xFAE59361L, 0xCEB69CEBL, 0xC2A86459L, 0x12BAA8D1L,
- 0xB6C1075EL, 0xE3056A0CL, 0x10D25065L, 0xCB03A442L,
- 0xE0EC6E0EL, 0x1698DB3BL, 0x4C98A0BEL, 0x3278E964L,
- 0x9F1F9532L, 0xE0D392DFL, 0xD3A0342BL, 0x8971F21EL,
- 0x1B0A7441L, 0x4BA3348CL, 0xC5BE7120L, 0xC37632D8L,
- 0xDF359F8DL, 0x9B992F2EL, 0xE60B6F47L, 0x0FE3F11DL,
- 0xE54CDA54L, 0x1EDAD891L, 0xCE6279CFL, 0xCD3E7E6FL,
- 0x1618B166L, 0xFD2C1D05L, 0x848FD2C5L, 0xF6FB2299L,
- 0xF523F357L, 0xA6327623L, 0x93A83531L, 0x56CCCD02L,
- 0xACF08162L, 0x5A75EBB5L, 0x6E163697L, 0x88D273CCL,
- 0xDE966292L, 0x81B949D0L, 0x4C50901BL, 0x71C65614L,
- 0xE6C6C7BDL, 0x327A140AL, 0x45E1D006L, 0xC3F27B9AL,
- 0xC9AA53FDL, 0x62A80F00L, 0xBB25BFE2L, 0x35BDD2F6L,
- 0x71126905L, 0xB2040222L, 0xB6CBCF7CL, 0xCD769C2BL,
- 0x53113EC0L, 0x1640E3D3L, 0x38ABBD60L, 0x2547ADF0L,
- 0xBA38209CL, 0xF746CE76L, 0x77AFA1C5L, 0x20756060L,
- 0x85CBFE4EL, 0x8AE88DD8L, 0x7AAAF9B0L, 0x4CF9AA7EL,
- 0x1948C25CL, 0x02FB8A8CL, 0x01C36AE4L, 0xD6EBE1F9L,
- 0x90D4F869L, 0xA65CDEA0L, 0x3F09252DL, 0xC208E69FL,
- 0xB74E6132L, 0xCE77E25BL, 0x578FDFE3L, 0x3AC372E6L }
-};
-
-
-static unsigned long F(BLOWFISH_CTX *ctx, unsigned long x) {
- unsigned short a, b, c, d;
- unsigned long y;
-
- d = (unsigned short)(x & 0xFF);
- x >>= 8;
- c = (unsigned short)(x & 0xFF);
- x >>= 8;
- b = (unsigned short)(x & 0xFF);
- x >>= 8;
- a = (unsigned short)(x & 0xFF);
- y = ctx->S[0][a] + ctx->S[1][b];
- y = y ^ ctx->S[2][c];
- y = y + ctx->S[3][d];
-
- return y;
-}
-
-
-void Blowfish_Encrypt(BLOWFISH_CTX *ctx, unsigned long *xl, unsigned long *xr){
- unsigned long Xl;
- unsigned long Xr;
- unsigned long temp;
- short i;
-
- Xl = *xl;
- Xr = *xr;
-
- for (i = 0; i < N; ++i) {
- Xl = Xl ^ ctx->P[i];
- Xr = F(ctx, Xl) ^ Xr;
-
- temp = Xl;
- Xl = Xr;
- Xr = temp;
- }
-
- temp = Xl;
- Xl = Xr;
- Xr = temp;
-
- Xr = Xr ^ ctx->P[N];
- Xl = Xl ^ ctx->P[N + 1];
-
- *xl = Xl;
- *xr = Xr;
-}
-
-
-void Blowfish_Decrypt(BLOWFISH_CTX *ctx, unsigned long *xl, unsigned long *xr){
- unsigned long Xl;
- unsigned long Xr;
- unsigned long temp;
- short i;
-
- Xl = *xl;
- Xr = *xr;
-
- for (i = N + 1; i > 1; --i) {
- Xl = Xl ^ ctx->P[i];
- Xr = F(ctx, Xl) ^ Xr;
-
- /* Exchange Xl and Xr */
- temp = Xl;
- Xl = Xr;
- Xr = temp;
- }
-
- /* Exchange Xl and Xr */
- temp = Xl;
- Xl = Xr;
- Xr = temp;
-
- Xr = Xr ^ ctx->P[1];
- Xl = Xl ^ ctx->P[0];
-
- *xl = Xl;
- *xr = Xr;
-}
-
-
-void Blowfish_Init(BLOWFISH_CTX *ctx, unsigned char *key, int keyLen) {
- int i, j, k;
- unsigned long data, datal, datar;
-
- for (i = 0; i < 4; i++) {
- for (j = 0; j < 256; j++)
- ctx->S[i][j] = ORIG_S[i][j];
- }
-
- j = 0;
- for (i = 0; i < N + 2; ++i) {
- data = 0x00000000;
- for (k = 0; k < 4; ++k) {
- data = (data << 8) | key[j];
- j = j + 1;
- if (j >= keyLen)
- j = 0;
- }
- ctx->P[i] = ORIG_P[i] ^ data;
- }
-
- datal = 0x00000000;
- datar = 0x00000000;
-
- for (i = 0; i < N + 2; i += 2) {
- Blowfish_Encrypt(ctx, &datal, &datar);
- ctx->P[i] = datal;
- ctx->P[i + 1] = datar;
- }
-
- for (i = 0; i < 4; ++i) {
- for (j = 0; j < 256; j += 2) {
- Blowfish_Encrypt(ctx, &datal, &datar);
- ctx->S[i][j] = datal;
- ctx->S[i][j + 1] = datar;
- }
- }
-}
-
-
+
static const unsigned long ORIG_P[16 + 2] = + {
0x243F6A88L, 0x85A308D3L, 0x13198A2EL, 0x03707344L,
0xA4093822L, +0x299F31D0L, 0x082EFA98L, 0xEC4E6C89L,
0x452821E6L, 0x38D01377L, 0xBE5466CFL, 0x34E90C6CL,
0xC0AC29B7L, +0xC97C50DDL, 0x3F84D5B5L, 0xB5470917L,
0x9216D5D9L, 0x8979FB1BL
+}; +
static const unsigned long ORIG_S[4][256] = {
+ {0xD1310BA6L, 0x98DFB5ACL, 0x2FFD72DBL, 0xD01ADFB7L,
0xB8E1AFEDL, + 0x6A267E96L, 0xBA7C9045L, 0xF12C7F99L,
0x24A19947L, 0xB3916CF7L, + 0x0801F2E2L, 0x858EFC16L,
0x636920D8L, 0x71574E69L, 0xA458FEA3L, + 0xF4933D7EL,
0x0D95748FL, 0x728EB658L, 0x718BCD58L, 0x82154AEEL, +
0x7B54A41DL, 0xC25A59B5L, 0x9C30D539L, 0x2AF26013L,
0xC5D1B023L, + 0x286085F0L, 0xCA417918L, 0xB8DB38EFL,
0x8E79DCB0L, 0x603A180EL, + 0x6C9E0E8BL, 0xB01E8A3EL,
0xD71577C1L, 0xBD314B27L, 0x78AF2FDAL, + 0x55605C60L,
0xE65525F3L, 0xAA55AB94L, 0x57489862L, 0x63E81440L, +
0x55CA396AL, 0x2AAB10B6L, 0xB4CC5C34L, 0x1141E8CEL,
0xA15486AFL, + 0x7C72E993L, 0xB3EE1411L, 0x636FBC2AL,
0x2BA9C55DL, 0x741831F6L, + 0xCE5C3E16L, 0x9B87931EL,
0xAFD6BA33L, 0x6C24CF5CL, 0x7A325381L, + 0x28958677L,
0x3B8F4898L, 0x6B4BB9AFL, 0xC4BFE81BL, 0x66282193L, +
0x61D809CCL, 0xFB21A991L, 0x487CAC60L, 0x5DEC8032L,
0xEF845D5DL, + 0xE98575B1L, 0xDC262302L, 0xEB651B88L,
0x23893E81L, 0xD396ACC5L, + 0x0F6D6FF3L, 0x83F44239L,
0x2E0B4482L, 0xA4842004L, 0x69C8F04AL, + 0x9E1F9B5EL,
0x21C66842L, 0xF6E96C9AL, 0x670C9C61L, 0xABD388F0L, +
0x6A51A0D2L, 0xD8542F68L, 0x960FA728L, 0xAB5133A3L,
0x6EEF0B6CL, + 0x137A3BE4L, 0xBA3BF050L, 0x7EFB2A98L,
0xA1F1651DL, 0x39AF0176L, + 0x66CA593EL, 0x82430E88L,
0x8CEE8619L, 0x456F9FB4L, 0x7D84A5C3L, + 0x3B8B5EBEL,
0xE06F75D8L, 0x85C12073L, 0x401A449FL, 0x56C16AA6L, +
0x4ED3AA62L, 0x363F7706L, 0x1BFEDF72L, 0x429B023DL,
0x37D0D724L, + 0xD00A1248L, 0xDB0FEAD3L, 0x49F1C09BL,
0x075372C9L, 0x80991B7BL, + 0x25D479D8L, 0xF6E8DEF7L,
0xE3FE501AL, 0xB6794C3BL, 0x976CE0BDL, + 0x04C006BAL,
0xC1A94FB6L, 0x409F60C4L, 0x5E5C9EC2L, 0x196A2463L, +
0x68FB6FAFL, 0x3E6C53B5L, 0x1339B2EBL, 0x3B52EC6FL,
0x6DFC511FL, + 0x9B30952CL, 0xCC814544L, 0xAF5EBD09L,
0xBEE3D004L, 0xDE334AFDL, + 0x660F2807L, 0x192E4BB3L,
0xC0CBA857L, 0x45C8740FL, 0xD20B5F39L, + 0xB9D3FBDBL,
0x5579C0BDL, 0x1A60320AL, 0xD6A100C6L, 0x402C7279L, +
0x679F25FEL, 0xFB1FA3CCL, 0x8EA5E9F8L, 0xDB3222F8L,
0x3C7516DFL, + 0xFD616B15L, 0x2F501EC8L, 0xAD0552ABL,
0x323DB5FAL, 0xFD238760L, + 0x53317B48L, 0x3E00DF82L,
0x9E5C57BBL, 0xCA6F8CA0L, 0x1A87562EL, + 0xDF1769DBL,
0xD542A8F6L, 0x287EFFC3L, 0xAC6732C6L, 0x8C4F5573L, +
0x695B27B0L, 0xBBCA58C8L, 0xE1FFA35DL, 0xB8F011A0L,
0x10FA3D98L, + 0xFD2183B8L, 0x4AFCB56CL, 0x2DD1D35BL,
0x9A53E479L, 0xB6F84565L, + 0xD28E49BCL, 0x4BFB9790L,
0xE1DDF2DAL, 0xA4CB7E33L, 0x62FB1341L, + 0xCEE4C6E8L,
0xEF20CADAL, 0x36774C01L, 0xD07E9EFEL, 0x2BF11FB4L, +
0x95DBDA4DL, 0xAE909198L, 0xEAAD8E71L, 0x6B93D5A0L,
0xD08ED1D0L, + 0xAFC725E0L, 0x8E3C5B2FL, 0x8E7594B7L,
0x8FF6E2FBL, 0xF2122B64L, + 0x8888B812L, 0x900DF01CL,
0x4FAD5EA0L, 0x688FC31CL, 0xD1CFF191L, + 0xB3A8C1ADL,
0x2F2F2218L, 0xBE0E1777L, 0xEA752DFEL, 0x8B021FA1L, +
0xE5A0CC0FL, 0xB56F74E8L, 0x18ACF3D6L, 0xCE89E299L,
0xB4A84FE0L, + 0xFD13E0B7L, 0x7CC43B81L, 0xD2ADA8D9L,
0x165FA266L, 0x80957705L, + 0x93CC7314L, 0x211A1477L,
0xE6AD2065L, 0x77B5FA86L, 0xC75442F5L, + 0xFB9D35CFL,
0xEBCDAF0CL, 0x7B3E89A0L, 0xD6411BD3L, 0xAE1E7E49L, +
0x00250E2DL, 0x2071B35EL, 0x226800BBL, 0x57B8E0AFL,
0x2464369BL, + 0xF009B91EL, 0x5563911DL, 0x59DFA6AAL,
0x78C14389L, 0xD95A537FL, + 0x207D5BA2L, 0x02E5B9C5L,
0x83260376L, 0x6295CFA9L, 0x11C81968L, + 0x4E734A41L,
0xB3472DCAL, 0x7B14A94AL, 0x1B510052L, 0x9A532915L, +
0xD60F573FL, 0xBC9BC6E4L, 0x2B60A476L, 0x81E67400L,
0x08BA6FB5L, + 0x571BE91FL, 0xF296EC6BL, 0x2A0DD915L,
0xB6636521L, 0xE7B9F9B6L, + 0xFF34052EL, 0xC5855664L,
0x53B02D5DL, 0xA99F8FA1L, 0x08BA4799L, + 0x6E85076AL},
{0x4B7A70E9L, 0xB5B32944L, 0xDB75092EL, + 0xC4192623L,
0xAD6EA6B0L, 0x49A7DF7DL, + 0x9CEE60B8L, 0x8FEDB266L,
0xECAA8C71L, + 0x699A17FFL, 0x5664526CL, 0xC2B19EE1L, +
0x193602A5L, 0x75094C29L, 0xA0591340L, + 0xE4183A3EL,
0x3F54989AL, 0x5B429D65L, + 0x6B8FE4D6L, 0x99F73FD6L,
0xA1D29C07L, + 0xEFE830F5L, 0x4D2D38E6L, 0xF0255DC1L, +
0x4CDD2086L, 0x8470EB26L, 0x6382E9C6L, + 0x021ECC5EL,
0x09686B3FL, 0x3EBAEFC9L, + 0x3C971814L, 0x6B6A70A1L,
0x687F3584L, + 0x52A0E286L, 0xB79C5305L, 0xAA500737L, +
0x3E07841CL, 0x7FDEAE5CL, 0x8E7D44ECL, + 0x5716F2B8L,
0xB03ADA37L, 0xF0500C0DL, + 0xF01C1F04L, 0x0200B3FFL,
0xAE0CF51AL, + 0x3CB574B2L, 0x25837A58L, 0xDC0921BDL, +
0xD19113F9L, 0x7CA92FF6L, 0x94324773L, + 0x22F54701L,
0x3AE5E581L, 0x37C2DADCL, + 0xC8B57634L, 0x9AF3DDA7L,
0xA9446146L, + 0x0FD0030EL, 0xECC8C73EL, 0xA4751E41L, +
0xE238CD99L, 0x3BEA0E2FL, 0x3280BBA1L, + 0x183EB331L,
0x4E548B38L, 0x4F6DB908L, + 0x6F420D03L, 0xF60A04BFL,
0x2CB81290L, + 0x24977C79L, 0x5679B072L, 0xBCAF89AFL, +
0xDE9A771FL, 0xD9930810L, 0xB38BAE12L, + 0xDCCF3F2EL,
0x5512721FL, 0x2E6B7124L, + 0x501ADDE6L, 0x9F84CD87L,
0x7A584718L, + 0x7408DA17L, 0xBC9F9ABCL, 0xE94B7D8CL, +
0xEC7AEC3AL, 0xDB851DFAL, 0x63094366L, + 0xC464C3D2L,
0xEF1C1847L, 0x3215D908L, + 0xDD433B37L, 0x24C2BA16L,
0x12A14D43L, + 0x2A65C451L, 0x50940002L, 0x133AE4DDL, +
0x71DFF89EL, 0x10314E55L, 0x81AC77D6L, + 0x5F11199BL,
0x043556F1L, 0xD7A3C76BL, + 0x3C11183BL, 0x5924A509L,
0xF28FE6EDL, + 0x97F1FBFAL, 0x9EBABF2CL, 0x1E153C6EL, +
0x86E34570L, 0xEAE96FB1L, 0x860E5E0AL, + 0x5A3E2AB3L,
0x771FE71CL, 0x4E3D06FAL, + 0x2965DCB9L, 0x99E71D0FL,
0x803E89D6L, + 0x5266C825L, 0x2E4CC978L, 0x9C10B36AL, +
0xC6150EBAL, 0x94E2EA78L, 0xA5FC3C53L, + 0x1E0A2DF4L,
0xF2F74EA7L, 0x361D2B3DL, + 0x1939260FL, 0x19C27960L,
0x5223A708L, + 0xF71312B6L, 0xEBADFE6EL, 0xEAC31F66L, +
0xE3BC4595L, 0xA67BC883L, 0xB17F37D1L, + 0x018CFF28L,
0xC332DDEFL, 0xBE6C5AA5L, + 0x65582185L, 0x68AB9802L,
0xEECEA50FL, + 0xDB2F953BL, 0x2AEF7DADL, 0x5B6E2F84L, +
0x1521B628L, 0x29076170L, 0xECDD4775L, + 0x619F1510L,
0x13CCA830L, 0xEB61BD96L, + 0x0334FE1EL, 0xAA0363CFL,
0xB5735C90L, + 0x4C70A239L, 0xD59E9E0BL, 0xCBAADE14L, +
0xEECC86BCL, 0x60622CA7L, 0x9CAB5CABL, + 0xB2F3846EL,
0x648B1EAFL, 0x19BDF0CAL, + 0xA02369B9L, 0x655ABB50L,
0x40685A32L, + 0x3C2AB4B3L, 0x319EE9D5L, 0xC021B8F7L, +
0x9B540B19L, 0x875FA099L, 0x95F7997EL, + 0x623D7DA8L,
0xF837889AL, 0x97E32D77L, + 0x11ED935FL, 0x16681281L,
0x0E358829L, + 0xC7E61FD6L, 0x96DEDFA1L, 0x7858BA99L, +
0x57F584A5L, 0x1B227263L, 0x9B83C3FFL, + 0x1AC24696L,
0xCDB30AEBL, 0x532E3054L, + 0x8FD948E4L, 0x6DBC3128L,
0x58EBF2EFL, + 0x34C6FFEAL, 0xFE28ED61L, 0xEE7C3C73L, +
0x5D4A14D9L, 0xE864B7E3L, 0x42105D14L, + 0x203E13E0L,
0x45EEE2B6L, 0xA3AAABEAL, + 0xDB6C4F15L, 0xFACB4FD0L,
0xC742F442L, + 0xEF6ABBB5L, 0x654F3B1DL, 0x41CD2105L, +
0xD81E799EL, 0x86854DC7L, 0xE44B476AL, + 0x3D816250L,
0xCF62A1F2L, 0x5B8D2646L, + 0xFC8883A0L, 0xC1C7B6A3L,
0x7F1524C3L, + 0x69CB7492L, 0x47848A0BL, 0x5692B285L, +
0x095BBF00L, 0xAD19489DL, 0x1462B174L, + 0x23820E00L,
0x58428D2AL, 0x0C55F5EAL, + 0x1DADF43EL, 0x233F7061L,
0x3372F092L, + 0x8D937E41L, 0xD65FECF1L, 0x6C223BDBL, +
0x7CDE3759L, 0xCBEE7460L, 0x4085F2A7L, + 0xCE77326EL,
0xA6078084L, 0x19F8509EL, + 0xE8EFD855L, 0x61D99735L,
0xA969A7AAL, + 0xC50C06C2L, 0x5A04ABFCL, 0x800BCADCL, +
0x9E447A2EL, 0xC3453484L, 0xFDD56705L, + 0x0E1E9EC9L,
0xDB73DBD3L, 0x105588CDL, + 0x675FDA79L, 0xE3674340L,
0xC5C43465L, + 0x713E38D8L, 0x3D28F89EL, 0xF16DFF20L, +
0x153E21E7L, 0x8FB03D4AL, 0xE6E39F2BL, + 0xDB83ADF7L},
{0xE93D5A68L, 0x948140F7L, + 0xF64C261CL, 0x94692934L, +
0x411520F7L, 0x7602D4F7L, + 0xBCF46B2EL, 0xD4A20068L, +
0xD4082471L, 0x3320F46AL, + 0x43B7D4B7L, 0x500061AFL, +
0x1E39F62EL, 0x97244546L, + 0x14214F74L, 0xBF8B8840L, +
0x4D95FC1DL, 0x96B591AFL, + 0x70F4DDD3L, 0x66A02F45L, +
0xBFBC09ECL, 0x03BD9785L, + 0x7FAC6DD0L, 0x31CB8504L, +
0x96EB27B3L, 0x55FD3941L, + 0xDA2547E6L, 0xABCA0A9AL, +
0x28507825L, 0x530429F4L, + 0x0A2C86DAL, 0xE9B66DFBL, +
0x68DC1462L, 0xD7486900L, + 0x680EC0A4L, 0x27A18DEEL, +
0x4F3FFEA2L, 0xE887AD8CL, + 0xB58CE006L, 0x7AF4D6B6L, +
0xAACE1E7CL, 0xD3375FECL, + 0xCE78A399L, 0x406B2A42L, +
0x20FE9E35L, 0xD9F385B9L, + 0xEE39D7ABL, 0x3B124E8BL, +
0x1DC9FAF7L, 0x4B6D1856L, + 0x26A36631L, 0xEAE397B2L, +
0x3A6EFA74L, 0xDD5B4332L, + 0x6841E7F7L, 0xCA7820FBL, +
0xFB0AF54EL, 0xD8FEB397L, + 0x454056ACL, 0xBA489527L, +
0x55533A3AL, 0x20838D87L, + 0xFE6BA9B7L, 0xD096954BL, +
0x55A867BCL, 0xA1159A58L, + 0xCCA92963L, 0x99E1DB33L, +
0xA62A4A56L, 0x3F3125F9L, + 0x5EF47E1CL, 0x9029317CL, +
0xFDF8E802L, 0x04272F70L, + 0x80BB155CL, 0x05282CE3L, +
0x95C11548L, 0xE4C66D22L, + 0x48C1133FL, 0xC70F86DCL, +
0x07F9C9EEL, 0x41041F0FL, + 0x404779A4L, 0x5D886E17L, +
0x325F51EBL, 0xD59BC0D1L, + 0xF2BCC18FL, 0x41113564L, +
0x257B7834L, 0x602A9C60L, + 0xDFF8E8A3L, 0x1F636C1BL, +
0x0E12B4C2L, 0x02E1329EL, + 0xAF664FD1L, 0xCAD18115L, +
0x6B2395E0L, 0x333E92E1L, + 0x3B240B62L, 0xEEBEB922L, +
0x85B2A20EL, 0xE6BA0D99L, + 0xDE720C8CL, 0x2DA2F728L, +
0xD0127845L, 0x95B794FDL, + 0x647D0862L, 0xE7CCF5F0L, +
0x5449A36FL, 0x877D48FAL, + 0xC39DFD27L, 0xF33E8D1EL, +
0x0A476341L, 0x992EFF74L, + 0x3A6F6EABL, 0xF4F8FD37L, +
0xA812DC60L, 0xA1EBDDF8L, + 0x991BE14CL, 0xDB6E6B0DL, +
0xC67B5510L, 0x6D672C37L, + 0x2765D43BL, 0xDCD0E804L, +
0xF1290DC7L, 0xCC00FFA3L, + 0xB5390F92L, 0x690FED0BL, +
0x667B9FFBL, 0xCEDB7D9CL, + 0xA091CF0BL, 0xD9155EA3L, +
0xBB132F88L, 0x515BAD24L, + 0x7B9479BFL, 0x763BD6EBL, +
0x37392EB3L, 0xCC115979L, + 0x8026E297L, 0xF42E312DL, +
0x6842ADA7L, 0xC66A2B3BL, + 0x12754CCCL, 0x782EF11CL, +
0x6A124237L, 0xB79251E7L, + 0x06A1BBE6L, 0x4BFB6350L, +
0x1A6B1018L, 0x11CAEDFAL, + 0x3D25BDD8L, 0xE2E1C3C9L, +
0x44421659L, 0x0A121386L, + 0xD90CEC6EL, 0xD5ABEA2AL, +
0x64AF674EL, 0xDA86A85FL, + 0xBEBFE988L, 0x64E4C3FEL, +
0x9DBC8057L, 0xF0F7C086L, + 0x60787BF8L, 0x6003604DL, +
0xD1FD8346L, 0xF6381FB0L, + 0x7745AE04L, 0xD736FCCCL, +
0x83426B33L, 0xF01EAB71L, + 0xB0804187L, 0x3C005E5FL, +
0x77A057BEL, 0xBDE8AE24L, + 0x55464299L, 0xBF582E61L, +
0x4E58F48FL, 0xF2DDFDA2L, + 0xF474EF38L, 0x8789BDC2L, +
0x5366F9C3L, 0xC8B38E74L, + 0xB475F255L, 0x46FCD9B9L, +
0x7AEB2661L, 0x8B1DDF84L, + 0x846A0E79L, 0x915F95E2L, +
0x466E598EL, 0x20B45770L, + 0x8CD55591L, 0xC902DE4CL, +
0xB90BACE1L, 0xBB8205D0L, + 0x11A86248L, 0x7574A99EL, +
0xB77F19B6L, 0xE0A9DC09L, + 0x662D09A1L, 0xC4324633L, +
0xE85A1F02L, 0x09F0BE8CL, + 0x4A99A025L, 0x1D6EFE10L, +
0x1AB93D1DL, 0x0BA5A4DFL, + 0xA186F20FL, 0x2868F169L, +
0xDCB7DA83L, 0x573906FEL, + 0xA1E2CE9BL, 0x4FCD7F52L, +
0x50115E01L, 0xA70683FAL, + 0xA002B5C4L, 0x0DE6D027L, +
0x9AF88C27L, 0x773F8641L, + 0xC3604C06L, 0x61A806B5L, +
0xF0177A28L, 0xC0F586E0L, + 0x006058AAL, 0x30DC7D62L, +
0x11E69ED7L, 0x2338EA63L, + 0x53C2DD94L, 0xC2C21634L, +
0xBBCBEE56L, 0x90BCB6DEL, + 0xEBFC7DA1L, 0xCE591D76L, +
0x6F05E409L, 0x4B7C0188L, + 0x39720A3DL, 0x7C927C24L, +
0x86E3725FL, 0x724D9DB9L, + 0x1AC15BB4L, 0xD39EB8FCL, +
0xED545578L, 0x08FCA5B5L, + 0xD83D7CD3L, 0x4DAD0FC4L, +
0x1E50EF5EL, 0xB161E6F8L, + 0xA28514D9L, 0x6C51133CL, +
0x6FD5C7E7L, 0x56E14EC4L, + 0x362ABFCEL, 0xDDC6C837L, +
0xD79A3234L, 0x92638212L, + 0x670EFA8EL, 0x406000E0L}, +
{0x3A39CE37L, 0xD3FAF5CFL, 0xABC27737L, 0x5AC52D1BL,
0x5CB0679EL, + 0x4FA33742L, 0xD3822740L, 0x99BC9BBEL,
0xD5118E9DL, 0xBF0F7315L, + 0xD62D1C7EL, 0xC700C47BL,
0xB78C1B6BL, 0x21A19045L, 0xB26EB1BEL, + 0x6A366EB4L,
0x5748AB2FL, 0xBC946E79L, 0xC6A376D2L, 0x6549C2C8L, +
0x530FF8EEL, 0x468DDE7DL, 0xD5730A1DL, 0x4CD04DC6L,
0x2939BBDBL, + 0xA9BA4650L, 0xAC9526E8L, 0xBE5EE304L,
0xA1FAD5F0L, 0x6A2D519AL, + 0x63EF8CE2L, 0x9A86EE22L,
0xC089C2B8L, 0x43242EF6L, 0xA51E03AAL, + 0x9CF2D0A4L,
0x83C061BAL, 0x9BE96A4DL, 0x8FE51550L, 0xBA645BD6L, +
0x2826A2F9L, 0xA73A3AE1L, 0x4BA99586L, 0xEF5562E9L,
0xC72FEFD3L, + 0xF752F7DAL, 0x3F046F69L, 0x77FA0A59L,
0x80E4A915L, 0x87B08601L, + 0x9B09E6ADL, 0x3B3EE593L,
0xE990FD5AL, 0x9E34D797L, 0x2CF0B7D9L, + 0x022B8B51L,
0x96D5AC3AL, 0x017DA67DL, 0xD1CF3ED6L, 0x7C7D2D28L, +
0x1F9F25CFL, 0xADF2B89BL, 0x5AD6B472L, 0x5A88F54CL,
0xE029AC71L, + 0xE019A5E6L, 0x47B0ACFDL, 0xED93FA9BL,
0xE8D3C48DL, 0x283B57CCL, + 0xF8D56629L, 0x79132E28L,
0x785F0191L, 0xED756055L, 0xF7960E44L, + 0xE3D35E8CL,
0x15056DD4L, 0x88F46DBAL, 0x03A16125L, 0x0564F0BDL, +
0xC3EB9E15L, 0x3C9057A2L, 0x97271AECL, 0xA93A072AL,
0x1B3F6D9BL, + 0x1E6321F5L, 0xF59C66FBL, 0x26DCF319L,
0x7533D928L, 0xB155FDF5L, + 0x03563482L, 0x8ABA3CBBL,
0x28517711L, 0xC20AD9F8L, 0xABCC5167L, + 0xCCAD925FL,
0x4DE81751L, 0x3830DC8EL, 0x379D5862L, 0x9320F991L, +
0xEA7A90C2L, 0xFB3E7BCEL, 0x5121CE64L, 0x774FBE32L,
0xA8B6E37EL, + 0xC3293D46L, 0x48DE5369L, 0x6413E680L,
0xA2AE0810L, 0xDD6DB224L, + 0x69852DFDL, 0x09072166L,
0xB39A460AL, 0x6445C0DDL, 0x586CDECFL, + 0x1C20C8AEL,
0x5BBEF7DDL, 0x1B588D40L, 0xCCD2017FL, 0x6BB4E3BBL, +
0xDDA26A7EL, 0x3A59FF45L, 0x3E350A44L, 0xBCB4CDD5L,
0x72EACEA8L, + 0xFA6484BBL, 0x8D6612AEL, 0xBF3C6F47L,
0xD29BE463L, 0x542F5D9EL, + 0xAEC2771BL, 0xF64E6370L,
0x740E0D8DL, 0xE75B1357L, 0xF8721671L, + 0xAF537D5DL,
0x4040CB08L, 0x4EB4E2CCL, 0x34D2466AL, 0x0115AF84L, +
0xE1B00428L, 0x95983A1DL, 0x06B89FB4L, 0xCE6EA048L,
0x6F3F3B82L, + 0x3520AB82L, 0x011A1D4BL, 0x277227F8L,
0x611560B1L, 0xE7933FDCL, + 0xBB3A792BL, 0x344525BDL,
0xA08839E1L, 0x51CE794BL, 0x2F32C9B7L, + 0xA01FBAC9L,
0xE01CC87EL, 0xBCC7D1F6L, 0xCF0111C3L, 0xA1E8AAC7L, +
0x1A908749L, 0xD44FBD9AL, 0xD0DADECBL, 0xD50ADA38L,
0x0339C32AL, + 0xC6913667L, 0x8DF9317CL, 0xE0B12B4FL,
0xF79E59B7L, 0x43F5BB3AL, + 0xF2D519FFL, 0x27D9459CL,
0xBF97222CL, 0x15E6FC2AL, 0x0F91FC71L, + 0x9B941525L,
0xFAE59361L, 0xCEB69CEBL, 0xC2A86459L, 0x12BAA8D1L, +
0xB6C1075EL, 0xE3056A0CL, 0x10D25065L, 0xCB03A442L,
0xE0EC6E0EL, + 0x1698DB3BL, 0x4C98A0BEL, 0x3278E964L,
0x9F1F9532L, 0xE0D392DFL, + 0xD3A0342BL, 0x8971F21EL,
0x1B0A7441L, 0x4BA3348CL, 0xC5BE7120L, + 0xC37632D8L,
0xDF359F8DL, 0x9B992F2EL, 0xE60B6F47L, 0x0FE3F11DL, +
0xE54CDA54L, 0x1EDAD891L, 0xCE6279CFL, 0xCD3E7E6FL,
0x1618B166L, + 0xFD2C1D05L, 0x848FD2C5L, 0xF6FB2299L,
0xF523F357L, 0xA6327623L, + 0x93A83531L, 0x56CCCD02L,
0xACF08162L, 0x5A75EBB5L, 0x6E163697L, + 0x88D273CCL,
0xDE966292L, 0x81B949D0L, 0x4C50901BL, 0x71C65614L, +
0xE6C6C7BDL, 0x327A140AL, 0x45E1D006L, 0xC3F27B9AL,
0xC9AA53FDL, + 0x62A80F00L, 0xBB25BFE2L, 0x35BDD2F6L,
0x71126905L, 0xB2040222L, + 0xB6CBCF7CL, 0xCD769C2BL,
0x53113EC0L, 0x1640E3D3L, 0x38ABBD60L, + 0x2547ADF0L,
0xBA38209CL, 0xF746CE76L, 0x77AFA1C5L, 0x20756060L, +
0x85CBFE4EL, 0x8AE88DD8L, 0x7AAAF9B0L, 0x4CF9AA7EL,
0x1948C25CL, + 0x02FB8A8CL, 0x01C36AE4L, 0xD6EBE1F9L,
0x90D4F869L, 0xA65CDEA0L, + 0x3F09252DL, 0xC208E69FL,
0xB74E6132L, 0xCE77E25BL, 0x578FDFE3L, + 0x3AC372E6L}
+}; +
static unsigned long F(BLOWFISH_CTX * ctx, unsigned long x) +{ +
unsigned short a, b, c, d; +
unsigned long y; +
d = (unsigned short) (x & 0xFF); +
x >>= 8; +
c = (unsigned short) (x & 0xFF); +
x >>= 8; +
b = (unsigned short) (x & 0xFF); +
x >>= 8; +
a = (unsigned short) (x & 0xFF); +
y = ctx->S[0][a] + ctx->S[1][b]; +
y = y ^ ctx->S[2][c]; +
y = y + ctx->S[3][d]; +
return y; +
} +
void Blowfish_Encrypt(BLOWFISH_CTX * ctx, unsigned long *xl, + unsigned long *xr) +{ +
unsigned long Xl; +
unsigned long Xr; +
unsigned long temp; +
short i; +
Xl = *xl; +
Xr = *xr; +
for (i = 0; i < N; ++i) { +
Xl = Xl ^ ctx->P[i]; +
Xr = F(ctx, Xl) ^ Xr; +
temp = Xl; +
Xl = Xr; +
Xr = temp; +
} +
temp = Xl; +
Xl = Xr; +
Xr = temp; +
Xr = Xr ^ ctx->P[N]; +
Xl = Xl ^ ctx->P[N + 1]; +
*xl = Xl; +
*xr = Xr; +
} +
void Blowfish_Decrypt(BLOWFISH_CTX * ctx, unsigned long *xl, + unsigned long *xr) +{ +
unsigned long Xl; +
unsigned long Xr; +
unsigned long temp; +
short i; +
Xl = *xl; +
Xr = *xr; +
for (i = N + 1; i > 1; --i) { +
Xl = Xl ^ ctx->P[i]; +
Xr = F(ctx, Xl) ^ Xr; +
+ /* Exchange Xl and Xr */
+ temp = Xl; +
Xl = Xr; +
Xr = temp; +
} +
+ /* Exchange Xl and Xr */
+ temp = Xl; +
Xl = Xr; +
Xr = temp; +
Xr = Xr ^ ctx->P[1]; +
Xl = Xl ^ ctx->P[0]; +
*xl = Xl; +
*xr = Xr; +
} +
void Blowfish_Init(BLOWFISH_CTX * ctx, unsigned char *key, int keyLen) +{ +
int i, j, k; +
unsigned long data, datal, datar; +
for (i = 0; i < 4; i++) { +
for (j = 0; j < 256; j++) +
ctx->S[i][j] = ORIG_S[i][j]; +
} +
j = 0; +
for (i = 0; i < N + 2; ++i) { +
data = 0x00000000; +
for (k = 0; k < 4; ++k) { +
data = (data << 8) | key[j]; +
j = j + 1; +
if (j >= keyLen) +
j = 0; +
} +
ctx->P[i] = ORIG_P[i] ^ data; +
} +
datal = 0x00000000; +
datar = 0x00000000; +
for (i = 0; i < N + 2; i += 2) { +
Blowfish_Encrypt(ctx, &datal, &datar); +
ctx->P[i] = datal; +
ctx->P[i + 1] = datar; +
} +
for (i = 0; i < 4; ++i) { +
for (j = 0; j < 256; j += 2) { +
Blowfish_Encrypt(ctx, &datal, &datar); +
ctx->S[i][j] = datal; +
ctx->S[i][j + 1] = datar; +
} +
} +
} + +
diff --git a/callbacks.c b/callbacks.c index ac47d089..6a84de79 100644 --- a/callbacks.c +++ b/callbacks.c @@ -36,36 +36,37 @@ void cb_sync_manager() void cb_save_graphic() { - Shell *shell = shell_get_main_shell(); - GtkWidget *dialog; - gchar *filename; + Shell *shell = shell_get_main_shell(); + GtkWidget *dialog; + gchar *filename; /* save the pixbuf to a png file */ dialog = gtk_file_chooser_dialog_new("Save Image", - NULL, - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - + NULL, + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, + GTK_RESPONSE_ACCEPT, NULL); + filename = g_strconcat(shell->selected->name, ".png", NULL); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename); g_free(filename); - - if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - gtk_widget_destroy(dialog); - - shell_status_update("Saving image..."); - - tree_view_save_image(filename); - - shell_status_update("Done."); - g_free(filename); - - return; + + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + gtk_widget_destroy(dialog); + + shell_status_update("Saving image..."); + + tree_view_save_image(filename); + + shell_status_update("Done."); + g_free(filename); + + return; } - + gtk_widget_destroy(dialog); } @@ -97,29 +98,30 @@ void cb_refresh() void cb_copy_to_clipboard() { ShellModuleEntry *entry = shell_get_main_shell()->selected; - + if (entry) { - gchar *data = module_entry_function(entry); - GtkClipboard *clip = gtk_clipboard_get(gdk_atom_intern("CLIPBOARD", FALSE)); - ReportContext *ctx = report_context_text_new(NULL); + gchar *data = module_entry_function(entry); + GtkClipboard *clip = + gtk_clipboard_get(gdk_atom_intern("CLIPBOARD", FALSE)); + ReportContext *ctx = report_context_text_new(NULL); + + ctx->entry = entry; - ctx->entry = entry; + report_header(ctx); + report_table(ctx, data); + report_footer(ctx); - report_header(ctx); - report_table(ctx, data); - report_footer(ctx); - - gtk_clipboard_set_text(clip, ctx->output, -1); + gtk_clipboard_set_text(clip, ctx->output, -1); - g_free(data); - report_context_free(ctx); + g_free(data); + report_context_free(ctx); } } void cb_side_pane() { gboolean visible; - + visible = shell_action_get_active("SidePaneAction"); shell_set_side_pane_visible(visible); } @@ -127,53 +129,60 @@ void cb_side_pane() void cb_toolbar() { gboolean visible; - + visible = shell_action_get_active("ToolbarAction"); shell_ui_manager_set_visible("/MainMenuBarAction", visible); } -void cb_about_module(GtkAction *action) +void cb_about_module(GtkAction * action) { Shell *shell = shell_get_main_shell(); GSList *modules = shell->tree->modules; ModuleAbout *ma; gchar *name; - + g_object_get(G_OBJECT(action), "tooltip", &name, NULL); - + for (; modules; modules = modules->next) { - ShellModule *sm = (ShellModule *)modules->data; - - if (!g_str_equal(sm->name, name)) - continue; - - if ((ma = module_get_about(sm))) { - GtkWidget *about; - - about = gtk_about_dialog_new(); - gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about), - idle_free(g_strdup_printf("%s Module", sm->name))); - gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about), ma->version); - gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about), - idle_free(g_strdup_printf("Written by %s\n" - "Licensed under %s", - ma->author, - ma->license))); - - if (ma->description) - gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about), - ma->description); - - gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(about), sm->icon); - gtk_dialog_run(GTK_DIALOG(about)); - gtk_widget_destroy(about); - } else { - g_warning("No about information is associated with the %s module.", name); - } - - break; + ShellModule *sm = (ShellModule *) modules->data; + + if (!g_str_equal(sm->name, name)) + continue; + + if ((ma = module_get_about(sm))) { + GtkWidget *about; + gchar *text; + + about = gtk_about_dialog_new(); + + text = g_strdup_printf("%s Module", sm->name); + gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about), text); + g_free(text); + + gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about), + ma->version); + + text = g_strdup_printf("Written by %s\nLicensed under %s", + ma->author, ma->license); + gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about), text); + g_free(text); + + if (ma->description) + gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about), + ma->description); + + gtk_about_dialog_set_logo(GTK_ABOUT_DIALOG(about), sm->icon); + gtk_dialog_run(GTK_DIALOG(about)); + gtk_widget_destroy(about); + } else { + g_warning + ("No about information is associated with the %s module.", + name); + } + + break; } - + g_free(name); } @@ -181,33 +190,33 @@ void cb_about() { GtkWidget *about; const gchar *authors[] = { - "Author:", - "Leandro A. F. Pereira", - "", - "Contributors:", - "Agney Lopes Roth Ferraz", - "SCSI support by Pascal F. Martin", - "", - "Based on work by:", - "MD5 implementation by Colin Plumb (see md5.c for details)", - "SHA1 implementation by Steve Raid (see sha1.c for details)", - "Blowfish implementation by Paul Kocher (see blowfich.c for details)", - "Raytracing benchmark by John Walker (see fbench.c for details)", - "Some code partly based on x86cpucaps by Osamu Kayasono", - "Vendor list based on GtkSysInfo by Pissens Sebastien", - NULL + "Author:", + "Leandro A. F. Pereira", + "", + "Contributors:", + "Agney Lopes Roth Ferraz", + "SCSI support by Pascal F. Martin", + "", + "Based on work by:", + "MD5 implementation by Colin Plumb (see md5.c for details)", + "SHA1 implementation by Steve Raid (see sha1.c for details)", + "Blowfish implementation by Paul Kocher (see blowfich.c for details)", + "Raytracing benchmark by John Walker (see fbench.c for details)", + "Some code partly based on x86cpucaps by Osamu Kayasono", + "Vendor list based on GtkSysInfo by Pissens Sebastien", + NULL }; const gchar *artists[] = { - "The GNOME Project", - "Tango Project", - NULL + "The GNOME Project", + "Tango Project", + NULL }; about = gtk_about_dialog_new(); gtk_about_dialog_set_name(GTK_ABOUT_DIALOG(about), "HardInfo"); gtk_about_dialog_set_version(GTK_ABOUT_DIALOG(about), VERSION); gtk_about_dialog_set_copyright(GTK_ABOUT_DIALOG(about), - "Copyright \302\251 2003-2007 " + "Copyright \302\251 2003-2007 " "Leandro A. F. Pereira"); gtk_about_dialog_set_comments(GTK_ABOUT_DIALOG(about), "System information and benchmark tool"); @@ -215,20 +224,20 @@ void cb_about() icon_cache_get_pixbuf("logo.png")); gtk_about_dialog_set_license(GTK_ABOUT_DIALOG(about), - "HardInfo 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, version 2.\n\n" - "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.\n\n" - "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"); + "HardInfo 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, version 2.\n\n" + "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.\n\n" + "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"); #if GTK_CHECK_VERSION(2,8,0) gtk_about_dialog_set_wrap_license(GTK_ABOUT_DIALOG(about), TRUE); #endif - + gtk_about_dialog_set_authors(GTK_ABOUT_DIALOG(about), authors); gtk_about_dialog_set_artists(GTK_ABOUT_DIALOG(about), artists); @@ -240,10 +249,10 @@ void cb_generate_report() { Shell *shell = shell_get_main_shell(); gboolean btn_refresh = shell_action_get_enabled("RefreshAction"); - gboolean btn_copy = shell_action_get_enabled("CopyAction"); + gboolean btn_copy = shell_action_get_enabled("CopyAction"); report_dialog_show(shell->tree->model, shell->window); - + shell_action_set_enabled("RefreshAction", btn_refresh); shell_action_set_enabled("CopyAction", btn_copy); } @@ -251,6 +260,6 @@ void cb_generate_report() void cb_quit(void) { do { - gtk_main_quit(); + gtk_main_quit(); } while (gtk_main_level() > 1); } @@ -69,17 +69,17 @@ void scan_network(gboolean reload); void scan_users(gboolean reload); static ModuleEntry entries[] = { - { "Summary", "summary.png", callback_summary, scan_summary }, - { "Operating System", "os.png", callback_os, scan_os }, - { "Kernel Modules", "module.png", callback_modules, scan_modules }, - { "Boots", "boot.png", callback_boots, scan_boots }, - { "Languages", "language.png", callback_locales, scan_locales }, - { "Filesystems", "dev_removable.png", callback_fs, scan_fs }, - { "Shared Directories", "shares.png", callback_shares, scan_shares }, - { "Display", "monitor.png", callback_display, scan_display }, - { "Network Interfaces", "network.png", callback_network, scan_network }, - { "Users", "users.png", callback_users, scan_users }, - { NULL }, + {"Summary", "summary.png", callback_summary, scan_summary}, + {"Operating System", "os.png", callback_os, scan_os}, + {"Kernel Modules", "module.png", callback_modules, scan_modules}, + {"Boots", "boot.png", callback_boots, scan_boots}, + {"Languages", "language.png", callback_locales, scan_locales}, + {"Filesystems", "dev_removable.png", callback_fs, scan_fs}, + {"Shared Directories", "shares.png", callback_shares, scan_shares}, + {"Display", "monitor.png", callback_display, scan_display}, + {"Network Interfaces", "network.png", callback_network, scan_network}, + {"Users", "users.png", callback_users, scan_users}, + {NULL}, }; #include "computer.h" @@ -103,8 +103,7 @@ static Computer *computer = NULL; #include <arch/common/users.h> #include <arch/this/boots.h> -gchar * -hi_more_info(gchar * entry) +gchar *hi_more_info(gchar * entry) { gchar *info = (gchar *) g_hash_table_lookup(moreinfo, entry); @@ -114,14 +113,14 @@ hi_more_info(gchar * entry) return g_strdup_printf("[%s]", entry); } -gchar * -hi_get_field(gchar * field) +gchar *hi_get_field(gchar * field) { gchar *tmp; if (g_str_equal(field, "Memory")) { - MemoryInfo *mi = idle_free(computer_get_memory()); + MemoryInfo *mi = computer_get_memory(); tmp = g_strdup_printf("%dMB (%dMB used)", mi->total, mi->used); + g_free(mi); } else if (g_str_equal(field, "Uptime")) { tmp = computer_get_formatted_uptime(); } else if (g_str_equal(field, "Date/Time")) { @@ -213,75 +212,86 @@ void scan_users(gboolean reload) gchar *callback_summary() { - return g_strdup_printf("[$ShellParam$]\n" - "UpdateInterval$Memory=1000\n" - "UpdateInterval$Date/Time=1000\n" - "#ReloadInterval=5000\n" - "[Computer]\n" - "Processor=%s\n" - "Memory=...\n" - "Operating System=%s\n" - "User Name=%s\n" - "Date/Time=...\n" - "[Display]\n" - "Resolution=%dx%d pixels\n" - "OpenGL Renderer=%s\n" - "X11 Vendor=%s\n" - "[Multimedia]\n" - "\n%s\n" - "[Input Devices]\n%s\n" - "\n%s\n" - "\n%s\n", - (gchar*)idle_free(module_call_method("devices::getProcessorName")), - computer->os->distro, - computer->os->username, - computer->display->width, - computer->display->height, - computer->display->ogl_renderer, - computer->display->vendor, - (gchar*)idle_free(computer_get_alsacards(computer)), - (gchar*)idle_free(module_call_method("devices::getInputDevices")), - (gchar*)idle_free(module_call_method("devices::getPrinters")), - (gchar*)idle_free(module_call_method("devices::getStorageDevices"))); + gchar *processor_name, *alsa_cards, *input_devices, *printers, *storage_devices, *summary; + + processor_name = module_call_method("devices::getProcessorName"); + alsa_cards = computer_get_alsacards(computer); + input_devices = module_call_method("devices::getInputDevices"); + printers = module_call_method("devices::getPrinters"); + storage_devices = module_call_method("devices::getStorageDevices"); + + summary = g_strdup_printf("[$ShellParam$]\n" + "UpdateInterval$Memory=1000\n" + "UpdateInterval$Date/Time=1000\n" + "#ReloadInterval=5000\n" + "[Computer]\n" + "Processor=%s\n" + "Memory=...\n" + "Operating System=%s\n" + "User Name=%s\n" + "Date/Time=...\n" + "[Display]\n" + "Resolution=%dx%d pixels\n" + "OpenGL Renderer=%s\n" + "X11 Vendor=%s\n" + "[Multimedia]\n" + "\n%s\n" + "[Input Devices]\n%s\n" + "\n%s\n" + "\n%s\n", + processor_name, + computer->os->distro, + computer->os->username, + computer->display->width, + computer->display->height, + computer->display->ogl_renderer, + computer->display->vendor, + alsa_cards, + input_devices, printers, storage_devices); + + g_free(processor_name); + g_free(alsa_cards); + g_free(input_devices); + g_free(printers); + g_free(storage_devices); + + return summary; } gchar *callback_os() { return g_strdup_printf("[$ShellParam$]\n" - "UpdateInterval$Uptime=10000\n" - "UpdateInterval$Load Average=1000\n" - "[Version]\n" - "Kernel=%s\n" - "Compiled=%s\n" - "C Library=%s\n" - "Distribution=%s\n" - "[Current Session]\n" - "Computer Name=%s\n" - "User Name=%s\n" - "#Language=%s\n" - "Home Directory=%s\n" - "Desktop Environment=%s\n" - "[Misc]\n" - "Uptime=...\n" - "Load Average=...", - computer->os->kernel, - computer->os->compiled_date, - computer->os->libc, - computer->os->distro, - computer->os->hostname, - computer->os->username, - computer->os->language, - computer->os->homedir, - computer->os->desktop); + "UpdateInterval$Uptime=10000\n" + "UpdateInterval$Load Average=1000\n" + "[Version]\n" + "Kernel=%s\n" + "Compiled=%s\n" + "C Library=%s\n" + "Distribution=%s\n" + "[Current Session]\n" + "Computer Name=%s\n" + "User Name=%s\n" + "#Language=%s\n" + "Home Directory=%s\n" + "Desktop Environment=%s\n" + "[Misc]\n" + "Uptime=...\n" + "Load Average=...", + computer->os->kernel, + computer->os->compiled_date, + computer->os->libc, + computer->os->distro, + computer->os->hostname, + computer->os->username, + computer->os->language, + computer->os->homedir, computer->os->desktop); } gchar *callback_modules() { return g_strdup_printf("[Loaded Modules]\n" - "%s" - "[$ShellParam$]\n" - "ViewType=1", - module_list); + "%s" + "[$ShellParam$]\n" "ViewType=1", module_list); } gchar *callback_boots() @@ -292,71 +302,72 @@ gchar *callback_boots() gchar *callback_locales() { return g_strdup_printf("[$ShellParam$]\n" - "ViewType=1\n" - "[Available Languages]\n" - "%s", computer->os->languages); + "ViewType=1\n" + "[Available Languages]\n" + "%s", computer->os->languages); } gchar *callback_fs() { return g_strdup_printf("[$ShellParam$]\n" - "ViewType=1\n" - "ReloadInterval=5000\n" - "[Mounted File Systems]\n%s\n", fs_list); + "ViewType=1\n" + "ReloadInterval=5000\n" + "[Mounted File Systems]\n%s\n", fs_list); } gchar *callback_shares() { return g_strdup_printf("[SAMBA]\n" - "%s\n" - "[NFS]\n" - "%s", smb_shares_list, nfs_shares_list); + "%s\n" + "[NFS]\n" + "%s", smb_shares_list, nfs_shares_list); } gchar *callback_display() { return g_strdup_printf("[Display]\n" - "Resolution=%dx%d pixels\n" - "Vendor=%s\n" - "Version=%s\n" - "[Monitors]\n" - "%s" - "[Extensions]\n" - "%s" - "[OpenGL]\n" - "Vendor=%s\n" - "Renderer=%s\n" - "Version=%s\n" - "Direct Rendering=%s\n", - computer->display->width, - computer->display->height, - computer->display->vendor, - computer->display->version, - computer->display->monitors, - computer->display->extensions, - computer->display->ogl_vendor, - computer->display->ogl_renderer, - computer->display->ogl_version, - computer->display->dri ? "Yes" : "No"); + "Resolution=%dx%d pixels\n" + "Vendor=%s\n" + "Version=%s\n" + "[Monitors]\n" + "%s" + "[Extensions]\n" + "%s" + "[OpenGL]\n" + "Vendor=%s\n" + "Renderer=%s\n" + "Version=%s\n" + "Direct Rendering=%s\n", + computer->display->width, + computer->display->height, + computer->display->vendor, + computer->display->version, + computer->display->monitors, + computer->display->extensions, + computer->display->ogl_vendor, + computer->display->ogl_renderer, + computer->display->ogl_version, + computer->display->dri ? "Yes" : "No"); } gchar *callback_network() { - return g_strdup_printf("[$ShellParam$]\n" - "ReloadInterval=3000\n" - "ViewType=1\n" - "%s", network_interfaces); + return g_strdup_printf("%s\n" + "[$ShellParam$]\n" + "ReloadInterval=3000\n" + "ViewType=1\n" + "%s", network_interfaces, network_icons); } gchar *callback_users() { return g_strdup_printf("[$ShellParam$]\n" - "ReloadInterval=10000\n" - "ViewType=1\n" - "[Human Users]\n" - "%s\n" - "[System Users]\n" - "%s\n", human_users, sys_users); + "ReloadInterval=10000\n" + "ViewType=1\n" + "[Human Users]\n" + "%s\n" + "[System Users]\n" + "%s\n", human_users, sys_users); } gchar *get_os_kernel(void) @@ -365,61 +376,54 @@ gchar *get_os_kernel(void) return computer->os->kernel; } -ShellModuleMethod* -hi_exported_methods(void) +ShellModuleMethod *hi_exported_methods(void) { static ShellModuleMethod m[] = { - { "getOSKernel", get_os_kernel }, - { NULL } + {"getOSKernel", get_os_kernel}, + {NULL} }; - + return m; } -ModuleEntry * -hi_module_get_entries(void) +ModuleEntry *hi_module_get_entries(void) { return entries; } -gchar * -hi_module_get_name(void) +gchar *hi_module_get_name(void) { return g_strdup("Computer"); } -guchar -hi_module_get_weight(void) +guchar hi_module_get_weight(void) { return 80; } -gchar ** -hi_module_get_dependencies(void) +gchar **hi_module_get_dependencies(void) { static gchar *deps[] = { "devices.so", NULL }; - + return deps; } -void -hi_module_init(void) +void hi_module_init(void) { computer = g_new0(Computer, 1); - moreinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + moreinfo = + g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); } -ModuleAbout * -hi_module_get_about(void) +ModuleAbout *hi_module_get_about(void) { static ModuleAbout ma[] = { - { - .author = "Leandro A. F. Pereira", - .description = "Gathers high-level computer information", - .version = VERSION, - .license = "GNU GPL version 2" - } + { + .author = "Leandro A. F. Pereira", + .description = "Gathers high-level computer information", + .version = VERSION, + .license = "GNU GPL version 2"} }; - + return ma; } @@ -167,11 +167,7 @@ done # -------------------------------------------------------------------------- if [ $SOUP -eq -1 ]; then - echo -e "\nYou need the libsoup library, including the development stuff." - echo "If you're using Debian, running the command as root:" - echo -e "\n\taptitude install libsoup2.2-dev\n" - echo "Will do the trick." - exit 1 + echo "Disabling libsoup support. (Network Manager won't be available.)" fi # -------------------------------------------------------------------------- @@ -193,6 +189,10 @@ echo "#define HOSTNAME \"`hostname`\"" >> config.h echo "#define PREFIX \"/usr/share/hardinfo/\"" >> config.h echo "#define LIBPREFIX \"/usr/lib/hardinfo/\"" >> config.h +if [ "$SOUP" == "1" ]; then + echo "#define HAS_LIBSOUP" >> config.h +fi + if [ "$RELEASE" == "1" ]; then echo "#define DEBUG(...)" >> config.h else @@ -60,22 +60,22 @@ void scan_input(gboolean reload); void scan_usb(gboolean reload); static ModuleEntry entries[] = { - {"Processor", "processor.png", callback_processors, scan_processors}, - {"Memory", "memory.png", callback_memory, scan_memory}, - {"PCI Devices", "devices.png", callback_pci, scan_pci}, - {"USB Devices", "usb.png", callback_usb, scan_usb}, - {"Printers", "printer.png", callback_printers, scan_printers,}, - {"Battery", "battery.png", callback_battery, scan_battery}, - {"Sensors", "therm.png", callback_sensors, scan_sensors}, - {"Input Devices", "inputdevices.png", callback_input, scan_input}, - {"Storage", "hdd.png", callback_storage, scan_storage}, - { NULL } + {"Processor", "processor.png", callback_processors, scan_processors}, + {"Memory", "memory.png", callback_memory, scan_memory}, + {"PCI Devices", "devices.png", callback_pci, scan_pci}, + {"USB Devices", "usb.png", callback_usb, scan_usb}, + {"Printers", "printer.png", callback_printers, scan_printers,}, + {"Battery", "battery.png", callback_battery, scan_battery}, + {"Sensors", "therm.png", callback_sensors, scan_sensors}, + {"Input Devices", "inputdevices.png", callback_input, scan_input}, + {"Storage", "hdd.png", callback_storage, scan_storage}, + {NULL} }; static GHashTable *moreinfo = NULL; static GSList *processors = NULL; static gchar *printer_list = NULL; -static gchar *pci_list = ""; +static gchar *pci_list = NULL; static gchar *input_list = NULL; static gchar *storage_list = NULL; static gchar *battery_list = NULL; @@ -111,7 +111,7 @@ static gchar *meminfo = NULL, *lginterval = NULL; #include <vendor.h> -typedef struct _Processor Processor; +typedef struct _Processor Processor; #include <arch/this/processor.h> #include <arch/this/pci.h> @@ -123,62 +123,56 @@ typedef struct _Processor Processor; #include <arch/this/sensors.h> #include <arch/this/devmemory.h> -gchar * -get_processor_name(void) +gchar *get_processor_name(void) { scan_processors(FALSE); - + Processor *p = (Processor *) processors->data; if (g_slist_length(processors) > 1) { - return idle_free(g_strdup_printf("%dx %s", - g_slist_length(processors), - p->model_name)); + return idle_free(g_strdup_printf("%dx %s", + g_slist_length(processors), + p->model_name)); } else { - return p->model_name; + return p->model_name; } } -gchar * -get_storage_devices(void) +gchar *get_storage_devices(void) { scan_storage(FALSE); - + return storage_list; } -gchar * -get_printers(void) +gchar *get_printers(void) { scan_printers(FALSE); - + return printer_list; } -gchar * -get_input_devices(void) +gchar *get_input_devices(void) { scan_input(FALSE); - + return input_list; } -ShellModuleMethod* -hi_exported_methods(void) +ShellModuleMethod *hi_exported_methods(void) { static ShellModuleMethod m[] = { - { "getProcessorName", get_processor_name }, - { "getStorageDevices", get_storage_devices }, - { "getPrinters", get_printers }, - { "getInputDevices", get_input_devices }, - { NULL } + {"getProcessorName", get_processor_name}, + {"getStorageDevices", get_storage_devices}, + {"getPrinters", get_printers}, + {"getInputDevices", get_input_devices}, + {NULL} }; - + return m; } -gchar * -hi_more_info(gchar * entry) +gchar *hi_more_info(gchar * entry) { gchar *info = (gchar *) g_hash_table_lookup(moreinfo, entry); @@ -188,8 +182,7 @@ hi_more_info(gchar * entry) return g_strdup("?"); } -gchar * -hi_get_field(gchar * field) +gchar *hi_get_field(gchar * field) { gchar *info = (gchar *) g_hash_table_lookup(moreinfo, field); @@ -199,211 +192,181 @@ hi_get_field(gchar * field) return g_strdup(field); } -void -scan_processors(gboolean reload) +void scan_processors(gboolean reload) { SCAN_START(); if (!processors) - processors = __scan_processors(); + processors = __scan_processors(); SCAN_END(); } -void -scan_memory(gboolean reload) +void scan_memory(gboolean reload) { SCAN_START(); __scan_memory(); SCAN_END(); } -void -scan_battery(gboolean reload) +void scan_battery(gboolean reload) { SCAN_START(); __scan_battery(); SCAN_END(); } -void -scan_pci(gboolean reload) +void scan_pci(gboolean reload) { SCAN_START(); __scan_pci(); SCAN_END(); } -void -scan_sensors(gboolean reload) +void scan_sensors(gboolean reload) { SCAN_START(); __scan_sensors(); SCAN_END(); } -void -scan_printers(gboolean reload) +void scan_printers(gboolean reload) { SCAN_START(); __scan_printers(); SCAN_END(); } -void -scan_storage(gboolean reload) +void scan_storage(gboolean reload) { SCAN_START(); g_free(storage_list); storage_list = g_strdup(""); - + __scan_ide_devices(); __scan_scsi_devices(); SCAN_END(); } -void -scan_input(gboolean reload) +void scan_input(gboolean reload) { SCAN_START(); __scan_input_devices(); SCAN_END(); } -void -scan_usb(gboolean reload) +void scan_usb(gboolean reload) { SCAN_START(); __scan_usb(); SCAN_END(); } -gchar * -callback_processors() +gchar *callback_processors() { return processor_get_info(processors); } -gchar * -callback_memory() +gchar *callback_memory() { return g_strdup_printf("[Memory]\n" - "%s\n" - "[$ShellParam$]\n" - "ViewType=2\n" - "LoadGraphSuffix= kB\n" - "RescanInterval=2000\n" - "%s\n", - meminfo, - lginterval); + "%s\n" + "[$ShellParam$]\n" + "ViewType=2\n" + "LoadGraphSuffix= kB\n" + "RescanInterval=2000\n" + "%s\n", meminfo, lginterval); } -gchar * -callback_battery() +gchar *callback_battery() { return g_strdup_printf("%s\n" - "[$ShellParam$]\n" - "ReloadInterval=4000\n", battery_list); + "[$ShellParam$]\n" + "ReloadInterval=4000\n", battery_list); } -gchar * -callback_pci() +gchar *callback_pci() { return g_strdup_printf("[PCI Devices]\n" - "%s" - "[$ShellParam$]\n" - "ViewType=1\n", - pci_list); + "%s" + "[$ShellParam$]\n" "ViewType=1\n", pci_list); } -gchar * -callback_sensors() +gchar *callback_sensors() { return g_strdup_printf("[$ShellParam$]\n" - "ReloadInterval=5000\n" - "%s", sensors); + "ReloadInterval=5000\n" "%s", sensors); } -gchar * -callback_printers() +gchar *callback_printers() { return g_strdup_printf("%s\n" - "[$ShellParam$]\n" - "ReloadInterval=5000", printer_list); + "[$ShellParam$]\n" + "ReloadInterval=5000", printer_list); } -gchar * -callback_storage() +gchar *callback_storage() { return g_strdup_printf("%s\n" - "[$ShellParam$]\n" - "ReloadInterval=5000\n" - "ViewType=1\n%s", storage_list, storage_icons); + "[$ShellParam$]\n" + "ReloadInterval=5000\n" + "ViewType=1\n%s", storage_list, storage_icons); } -gchar * -callback_input() +gchar *callback_input() { return g_strdup_printf("[Input Devices]\n" - "%s" - "[$ShellParam$]\n" - "ViewType=1\n" - "ReloadInterval=5000\n%s", input_list, input_icons); + "%s" + "[$ShellParam$]\n" + "ViewType=1\n" + "ReloadInterval=5000\n%s", input_list, + input_icons); } -gchar * -callback_usb() +gchar *callback_usb() { return g_strdup_printf("%s" - "[$ShellParam$]\n" - "ViewType=1\n" - "ReloadInterval=5000\n", - usb_list); + "[$ShellParam$]\n" + "ViewType=1\n" + "ReloadInterval=5000\n", usb_list); } -ModuleEntry * -hi_module_get_entries(void) +ModuleEntry *hi_module_get_entries(void) { return entries; } -gchar * -hi_module_get_name(void) +gchar *hi_module_get_name(void) { return g_strdup("Devices"); } -guchar -hi_module_get_weight(void) +guchar hi_module_get_weight(void) { return 160; } -void -hi_module_init(void) +void hi_module_init(void) { - moreinfo = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + moreinfo = + g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); __init_memory_labels(); } -ModuleAbout * -hi_module_get_about(void) +ModuleAbout *hi_module_get_about(void) { static ModuleAbout ma[] = { - { - .author = "Leandro A. F. Pereira", - .description = "Gathers information about hardware devices", - .version = VERSION, - .license = "GNU GPL version 2" - } + { + .author = "Leandro A. F. Pereira", + .description = "Gathers information about hardware devices", + .version = VERSION, + .license = "GNU GPL version 2"} }; - + return ma; } -gchar ** -hi_module_get_dependencies(void) +gchar **hi_module_get_dependencies(void) { static gchar *deps[] = { "computer.so", NULL }; - + return deps; } - @@ -14,7 +14,7 @@ * 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 - */ + */ /* * This is only used to compute sensor values, hence the only variable supported is '@'. * The '`' operator (ln(x)) is not available, nor multi-line formulas. @@ -71,11 +71,11 @@ static inline gint priority(char operation) case '(': return 0; } - + return 0; } -GSList *math_infix_to_postfix(GSList *infix) +GSList *math_infix_to_postfix(GSList * infix) { MathToken *stack[500]; gint t_sp = 0; @@ -89,7 +89,8 @@ GSList *math_infix_to_postfix(GSList *infix) if (t->type == TOKEN_OPERATOR && t->val.op == '(') { stack[++t_sp] = t; } else if (t->type == TOKEN_OPERATOR && t->val.op == ')') { - for (top = stack[t_sp]; t_sp != 0 && top->val.op != '('; top = stack[t_sp]) + for (top = stack[t_sp]; t_sp != 0 && top->val.op != '('; + top = stack[t_sp]) postfix = g_slist_append(postfix, stack[t_sp--]); t_sp--; } else if (t->type != TOKEN_OPERATOR) { @@ -97,7 +98,8 @@ GSList *math_infix_to_postfix(GSList *infix) } else if (t_sp == 0) { stack[++t_sp] = t; } else { - while (t_sp != 0 && priority(t->val.op) <= priority(stack[t_sp]->val.op)) + while (t_sp != 0 + && priority(t->val.op) <= priority(stack[t_sp]->val.op)) postfix = g_slist_append(postfix, stack[t_sp--]); stack[++t_sp] = t; } @@ -113,7 +115,7 @@ static inline gfloat __result(gfloat op1, gfloat op2, gchar operation) { switch (operation) { case '^': - return powf(op1, op2); + return powf(op1, op2); case '+': return op1 + op2; case '-': @@ -123,18 +125,18 @@ static inline gfloat __result(gfloat op1, gfloat op2, gchar operation) case '*': return op1 * op2; } - + return 0; } -gfloat math_postfix_eval(GSList *postfix, gfloat at_value) +gfloat math_postfix_eval(GSList * postfix, gfloat at_value) { GSList *p; gfloat stack[500]; gint sp = 0; - + memset(stack, 0, sizeof(gfloat) * 500); - + for (p = postfix; p; p = p->next) { MathToken *t = (MathToken *) p->data; @@ -155,7 +157,7 @@ gfloat math_postfix_eval(GSList *postfix, gfloat at_value) return stack[sp]; } -GSList *math_string_to_infix(gchar *string) +GSList *math_string_to_infix(gchar * string) { GSList *infix = NULL; gchar *expr = string; @@ -168,12 +170,7 @@ GSList *math_string_to_infix(gchar *string) } else if (strchr("-.1234567890", *expr)) { gfloat value; - sscanf(expr, "%f", &value); - - while (*expr && strchr(".1234567890", *expr)) - expr++; - expr--; - + expr += sscanf(expr, "%f", &value); infix = g_slist_append(infix, new_value(value)); } else if (!isspace(*expr)) { g_print("Invalid token: [%c][%d]\n", *expr, *expr); @@ -185,43 +182,43 @@ GSList *math_string_to_infix(gchar *string) return infix; } -void math_infix_free(GSList *infix, gboolean free_tokens) +void math_infix_free(GSList * infix, gboolean free_tokens) { GSList *p; - + if (!free_tokens) - for (p = infix; p; p = g_slist_delete_link(p, p)); - else - for (p = infix; p; p = g_slist_delete_link(p, p)) { - MathToken *t = (MathToken *)p->data; - g_free(t); - } + for (p = infix; p; p = g_slist_delete_link(p, p)); + else + for (p = infix; p; p = g_slist_delete_link(p, p)) { + MathToken *t = (MathToken *) p->data; + g_free(t); + } } -GSList *math_string_to_postfix(gchar *string) +GSList *math_string_to_postfix(gchar * string) { GSList *infix; GSList *postfix; - + infix = math_string_to_infix(string); if (!infix) - return NULL; - + return NULL; + postfix = math_infix_to_postfix(infix); math_infix_free(infix, FALSE); - + return postfix; } -gfloat math_string_eval(gchar *string, gfloat at_value) +gfloat math_string_eval(gchar * string, gfloat at_value) { GSList *postfix; gfloat val; - + postfix = math_string_to_postfix(string); val = math_postfix_eval(postfix, at_value); math_postfix_free(postfix, TRUE); - + return val; } @@ -229,14 +226,14 @@ gfloat math_string_eval(gchar *string, gfloat at_value) int main(void) { GSList *postfix; - + gchar *expr = "0.9*(@+(5.2*0.923+3*(2.0)))"; postfix = math_string_to_postfix(expr); g_print("%s = %f (must be 18.71964)\n", expr, - math_postfix_eval(postfix, 10)); + math_postfix_eval(postfix, 10)); math_postfix_free(postfix, TRUE); - + return 0; } #endif @@ -269,7 +269,7 @@ static double spectral_line[9]; static double s[max_surfaces][5]; static double od_sa[2][2]; -/*static char outarr[8][80];*/ /* Computed output of program goes here */ + /*static char outarr[8][80];*//* Computed output of program goes here */ int itercount; /* The iteration counter for the main loop in the program is made global so that @@ -736,9 +736,10 @@ void fbench() } #ifdef __FBENCH_TEST__ -int main(void) { - fbench(); +int main(void) +{ + fbench(); - return 0; + return 0; } #endif @@ -28,110 +28,111 @@ ProgramParameters params = { 0 }; -int -main(int argc, char **argv) +int main(int argc, char **argv) { GSList *modules; - + DEBUG("HardInfo version " VERSION ". Debug version."); +#ifdef HAS_LIBSOUP DEBUG("g_thread_init()"); if (!g_thread_supported()) - g_thread_init (NULL); - + g_thread_init(NULL); +#endif /* HAS_LIBSOUP */ + /* parse all command line parameters */ parameters_init(&argc, &argv, ¶ms); - + /* show version information and quit */ if (params.show_version) { - g_print("HardInfo version " VERSION "\n"); - g_print("Copyright (C) 2003-2007 Leandro A. F. Pereira. See COPYING for details.\n\n"); - - g_print("Compile-time options:\n" - " Release version: %s (%s)\n" - " BinReloc enabled: %s\n" - " Data prefix: %s\n" - " Library prefix: %s\n" - " Compiled on: %s %s (%s)\n", - RELEASE ? "Yes" : "No (" VERSION ")", ARCH, - ENABLE_BINRELOC ? "Yes" : "No", - PREFIX, - LIBPREFIX, - PLATFORM, KERNEL, HOSTNAME); - - DEBUG(" Debugging is enabled."); - - /* show also available modules */ - params.list_modules = TRUE; + g_print("HardInfo version " VERSION "\n"); + g_print + ("Copyright (C) 2003-2007 Leandro A. F. Pereira. See COPYING for details.\n\n"); + + g_print("Compile-time options:\n" + " Release version: %s (%s)\n" + " BinReloc enabled: %s\n" + " Data prefix: %s\n" + " Library prefix: %s\n" + " Compiled on: %s %s (%s)\n", + RELEASE ? "Yes" : "No (" VERSION ")", ARCH, + ENABLE_BINRELOC ? "Yes" : "No", + PREFIX, LIBPREFIX, PLATFORM, KERNEL, HOSTNAME); + + DEBUG(" Debugging is enabled."); + + /* show also available modules */ + params.list_modules = TRUE; } /* initialize the binreloc library, so we can load program data */ if (!binreloc_init(FALSE)) - g_error("Failed to find runtime data.\n\n" - "\342\200\242 Is HardInfo correctly installed?\n" - "\342\200\242 See if %s and %s exists and you have read permision.", - PREFIX, LIBPREFIX); - + g_error("Failed to find runtime data.\n\n" + "\342\200\242 Is HardInfo correctly installed?\n" + "\342\200\242 See if %s and %s exists and you have read permision.", + PREFIX, LIBPREFIX); + /* list all module names */ if (params.list_modules) { - g_print("Modules:\n" - "%-20s%-15s%-12s\n", "File Name", "Name", "Version"); - - for (modules = modules_load_all(); modules; modules = modules->next) { - ShellModule *module = (ShellModule *) modules->data; - ModuleAbout *ma = module_get_about(module); - gchar *name = g_path_get_basename(g_module_name(module->dll)); - - g_print("%-20s%-15s%-12s\n", - name, module->name, ma->version); - - g_free(name); - } - - return 0; + g_print("Modules:\n" + "%-20s%-15s%-12s\n", "File Name", "Name", "Version"); + + for (modules = modules_load_all(); modules; + modules = modules->next) { + ShellModule *module = (ShellModule *) modules->data; + ModuleAbout *ma = module_get_about(module); + gchar *name = g_path_get_basename(g_module_name(module->dll)); + + g_print("%-20s%-15s%-12s\n", name, module->name, ma->version); + + g_free(name); + } + + return 0; } if (!params.create_report) { - /* we only try to open the UI if the user didn't asked for a - report. */ - params.gui_running = ui_init(&argc, &argv); - - /* as a fallback, if GTK+ initialization failed, run in report - generation mode. */ - if (!params.gui_running) - params.create_report = TRUE; + /* we only try to open the UI if the user didn't asked for a + report. */ + params.gui_running = ui_init(&argc, &argv); + + /* as a fallback, if GTK+ initialization failed, run in report + generation mode. */ + if (!params.gui_running) + params.create_report = TRUE; } if (params.use_modules) { - /* load only selected modules */ - DEBUG("loading user-selected modules"); - modules = modules_load_selected(); + /* load only selected modules */ + DEBUG("loading user-selected modules"); + modules = modules_load_selected(); } else { - /* load all modules */ - DEBUG("loading all modules"); - modules = modules_load_all(); + /* load all modules */ + DEBUG("loading all modules"); + modules = modules_load_all(); } if (params.gui_running) { - /* initialize gui and start gtk+ main loop */ - icon_cache_init(); - stock_icons_init(); - - shell_init(modules); - - DEBUG("entering gtk+ main loop"); - gtk_main(); + /* initialize gui and start gtk+ main loop */ + icon_cache_init(); + stock_icons_init(); + + shell_init(modules); + + DEBUG("entering gtk+ main loop"); + gtk_main(); } else if (params.create_report) { - /* generate report */ - gchar *report; - - DEBUG("generating report"); - - report = report_create_from_module_list_format(modules, - params.report_format); - g_print("%s", report); - - g_free(report); + /* generate report */ + gchar *report; + + DEBUG("generating report"); + + report = report_create_from_module_list_format(modules, + params. + report_format); + g_print("%s", report); + + g_free(report); } DEBUG("finished"); @@ -81,7 +81,13 @@ gchar *file_chooser_build_filename(GtkWidget *chooser, gchar *extension); gpointer file_types_get_data_by_name(FileTypes *file_types, gchar *name); /* Misc utility functions */ -gpointer idle_free(gpointer ptr); +#if RELEASE == 1 +gpointer idle_free(gpointer ptr); +#else +gpointer __idle_free(gpointer ptr, gchar *f, gint l); +#define idle_free(p) __idle_free(p, __FILE__, __LINE__) +#endif /* RELEASE == 1 */ + inline gchar *size_human_readable(gfloat size); void nonblock_sleep(guint msec); void open_url(gchar *url); @@ -90,6 +96,9 @@ GSList *modules_load_all(void); ModuleAbout *module_get_about(ShellModule *module); gchar *seconds_to_string(unsigned int seconds); +gchar *h_strdup_cprintf(const gchar *format, gchar *source, ...); +gchar *h_strconcat(gchar *string1, ...); + void module_entry_scan_all_except(ModuleEntry *entries, gint except_entry); void module_entry_scan_all(ModuleEntry *entries); void module_entry_reload(ShellModuleEntry *module_entry); diff --git a/hardinfo.xml b/hardinfo.xml new file mode 100644 index 00000000..82b3ac26 --- /dev/null +++ b/hardinfo.xml @@ -0,0 +1,34 @@ +<?xml version="1.0" ?> +<!DOCTYPE luau-repository SYSTEM + "http://luau.sourceforge.net/luau-repository-1.2.dtd"> + +<luau-repository interface="1.2"> + + <program-info id="@tia.mat.br/hardinfo"> + + <shortname>hardinfo</shortname> + <fullname>HardInfo 0.4.2.2</fullname> + <desc>System profiler and benchmark tool</desc> + <url></url> + + </program-info> + + <software version="0.4.2.2"> + <date>2007-07-20</date> + <interface version="0.0" /> + <keyword>UNSTABLE</keyword> + + <short>Short declarative statement(s) about release for language en.</short> + <long> + Paragraphs describing the release for language en. + </long> + + <package type="autopackage" + version="1" + size="9255" + md5="70a39bcef7d5175feff7fb1fdfe805b5"> + /HardInfo%200.4.2.2%200.4.2.2.package + </package> + </software> + +</luau-repository> diff --git a/iconcache.c b/iconcache.c index fbd0dd84..49325e39 100644 --- a/iconcache.c +++ b/iconcache.c @@ -39,12 +39,13 @@ GdkPixbuf *icon_cache_get_pixbuf(const gchar * file) icon = g_hash_table_lookup(cache, file); if (!icon) { - icon = - gdk_pixbuf_new_from_file(idle_free - (g_build_filename - (params.path_data, "pixmaps", file, - NULL)), NULL); + gchar *path; + + path = g_build_filename(params.path_data, "pixmaps", file, NULL); + icon = gdk_pixbuf_new_from_file(path, NULL); g_hash_table_insert(cache, g_strdup(file), icon); + + g_free(path); } g_object_ref(icon); @@ -71,13 +72,13 @@ GdkPixbuf *icon_cache_get_pixbuf_at_size(const gchar * file, gint wid, icon = g_hash_table_lookup(cache, file); if (!icon) { - icon = - gdk_pixbuf_new_from_file_at_size(idle_free - (g_build_filename - (params.path_data, "pixmaps", - file, NULL)), wid, hei, - NULL); + gchar *path; + + path = g_build_filename(params.path_data, "pixmaps", file, NULL); + icon = gdk_pixbuf_new_from_file_at_size(path, wid, hei, NULL); g_hash_table_insert(cache, g_strdup(file), icon); + + g_free(path); } g_object_ref(icon); diff --git a/loadgraph.c b/loadgraph.c index 5f61fca3..3a535f5b 100644 --- a/loadgraph.c +++ b/loadgraph.c @@ -25,80 +25,80 @@ #include "loadgraph.h" -static void _draw(LoadGraph *lg); +static void _draw(LoadGraph * lg); LoadGraph *load_graph_new(gint size) { LoadGraph *lg; - + lg = g_new0(LoadGraph, 1); - + size++; - + lg->suffix = g_strdup(""); lg->area = gtk_drawing_area_new(); lg->size = size; lg->data = g_new0(gint, size); lg->scale = 1.0; - - lg->width = size * 4; + + lg->width = size * 4; lg->height = size * 2; - + lg->max_value = 1; lg->remax_count = 0; - lg->layout = pango_layout_new(gtk_widget_get_pango_context (lg->area)); - + lg->layout = pango_layout_new(gtk_widget_get_pango_context(lg->area)); + gtk_widget_set_size_request(lg->area, lg->width, lg->height); gtk_widget_show(lg->area); - + return lg; } -void load_graph_set_data_suffix(LoadGraph *lg, gchar *suffix) +void load_graph_set_data_suffix(LoadGraph * lg, gchar * suffix) { g_free(lg->suffix); lg->suffix = g_strdup(suffix); } -gchar *load_graph_get_data_suffix(LoadGraph *lg) +gchar *load_graph_get_data_suffix(LoadGraph * lg) { return lg->suffix; } -GtkWidget *load_graph_get_framed(LoadGraph *lg) +GtkWidget *load_graph_get_framed(LoadGraph * lg) { GtkWidget *align, *frame; - + align = gtk_alignment_new(0.5, 0.5, 0, 0); gtk_widget_show(align); - + frame = gtk_frame_new(NULL); gtk_widget_show(frame); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); - + gtk_container_add(GTK_CONTAINER(align), frame); gtk_container_add(GTK_CONTAINER(frame), lg->area); - + return align; } -void load_graph_clear(LoadGraph *lg) +void load_graph_clear(LoadGraph * lg) { gint i; - + for (i = 0; i < lg->size; i++) - lg->data[i] = 0; + lg->data[i] = 0; lg->scale = 1.0; lg->max_value = 1; lg->remax_count = 0; - + _draw(lg); } -void load_graph_set_color(LoadGraph *lg, LoadGraphColor color) +void load_graph_set_color(LoadGraph * lg, LoadGraphColor color) { lg->color = color; gdk_rgb_gc_set_foreground(lg->trace, lg->color); @@ -106,7 +106,7 @@ void load_graph_set_color(LoadGraph *lg, LoadGraphColor color) gdk_rgb_gc_set_foreground(lg->grid, lg->color - 0x404040); } -void load_graph_destroy(LoadGraph *lg) +void load_graph_destroy(LoadGraph * lg) { g_free(lg->data); gtk_widget_destroy(lg->area); @@ -118,22 +118,19 @@ void load_graph_destroy(LoadGraph *lg) g_free(lg); } -static gboolean _expose(GtkWidget *widget, GdkEventExpose *event, - gpointer user_data) +static gboolean _expose(GtkWidget * widget, GdkEventExpose * event, + gpointer user_data) { - LoadGraph *lg = (LoadGraph *)user_data; + LoadGraph *lg = (LoadGraph *) user_data; GdkDrawable *draw = GDK_DRAWABLE(lg->buf); gdk_draw_drawable(lg->area->window, - lg->area->style->white_gc, - draw, - 0, 0, - 0, 0, - lg->width, lg->height); + lg->area->style->white_gc, + draw, 0, 0, 0, 0, lg->width, lg->height); return FALSE; -} +} -void load_graph_configure_expose(LoadGraph *lg) +void load_graph_configure_expose(LoadGraph * lg) { /* creates the backing store pixmap */ gtk_widget_realize(lg->area); @@ -148,152 +145,151 @@ void load_graph_configure_expose(LoadGraph *lg) load_graph_set_color(lg, LG_COLOR_GREEN); /* init graphic contexts */ - gdk_gc_set_line_attributes(lg->grid, - 1, GDK_LINE_ON_OFF_DASH, - GDK_CAP_NOT_LAST, - GDK_JOIN_ROUND); -#if 0 /* old-style grid */ + gdk_gc_set_line_attributes(lg->grid, + 1, GDK_LINE_ON_OFF_DASH, + GDK_CAP_NOT_LAST, GDK_JOIN_ROUND); +#if 0 /* old-style grid */ gdk_rgb_gc_set_foreground(lg->grid, 0x707070); #endif - gdk_gc_set_line_attributes(lg->trace, - 1, GDK_LINE_SOLID, - GDK_CAP_PROJECTING, - GDK_JOIN_ROUND); + gdk_gc_set_line_attributes(lg->trace, + 1, GDK_LINE_SOLID, + GDK_CAP_PROJECTING, GDK_JOIN_ROUND); -#if 0 /* old-style fill */ - gdk_gc_set_line_attributes(lg->fill, - 1, GDK_LINE_SOLID, - GDK_CAP_BUTT, - GDK_JOIN_BEVEL); +#if 0 /* old-style fill */ + gdk_gc_set_line_attributes(lg->fill, + 1, GDK_LINE_SOLID, + GDK_CAP_BUTT, GDK_JOIN_BEVEL); #endif /* configures the expose event */ - g_signal_connect(G_OBJECT(lg->area), "expose-event", - (GCallback) _expose, lg); + g_signal_connect(G_OBJECT(lg->area), "expose-event", + (GCallback) _expose, lg); } -static void -_draw_label_and_line(LoadGraph *lg, gint position, gint value) +static void _draw_label_and_line(LoadGraph * lg, gint position, gint value) { gchar *tmp; - + /* draw lines */ if (position > 0) - gdk_draw_line(GDK_DRAWABLE(lg->buf), lg->grid, 0, position, lg->width, position); + gdk_draw_line(GDK_DRAWABLE(lg->buf), lg->grid, 0, position, + lg->width, position); else - position = -1 * position; - + position = -1 * position; + /* draw label */ - tmp = g_strdup_printf("<span size=\"x-small\">%d%s</span>", value, lg->suffix); + tmp = + g_strdup_printf("<span size=\"x-small\">%d%s</span>", value, + lg->suffix); pango_layout_set_markup(lg->layout, tmp, -1); - pango_layout_set_width(lg->layout, lg->area->allocation.width * PANGO_SCALE); - gdk_draw_layout(GDK_DRAWABLE(lg->buf), lg->trace, 2, position, lg->layout); + pango_layout_set_width(lg->layout, + lg->area->allocation.width * PANGO_SCALE); + gdk_draw_layout(GDK_DRAWABLE(lg->buf), lg->trace, 2, position, + lg->layout); g_free(tmp); } -static void -_draw(LoadGraph *lg) +static void _draw(LoadGraph * lg) { GdkDrawable *draw = GDK_DRAWABLE(lg->buf); gint i, d; - + /* clears the drawing area */ gdk_draw_rectangle(draw, lg->area->style->black_gc, - TRUE, 0, 0, lg->width, lg->height); - + TRUE, 0, 0, lg->width, lg->height); + /* the graph */ GdkPoint *points = g_new0(GdkPoint, lg->size + 1); - + for (i = 0; i < lg->size; i++) { - points[i].x = i * 4; - points[i].y = lg->height - lg->data[i] * lg->scale; + points[i].x = i * 4; + points[i].y = lg->height - lg->data[i] * lg->scale; } - + points[0].x = points[1].x = 0; points[0].y = points[i].y = lg->height; - points[i].x = points[i-1].x = lg->width; - + points[i].x = points[i - 1].x = lg->width; + gdk_draw_polygon(draw, lg->fill, TRUE, points, lg->size + 1); gdk_draw_polygon(draw, lg->trace, FALSE, points, lg->size + 1); - + g_free(points); /* vertical bars */ for (i = lg->width, d = 0; i > 1; i--, d++) - if ((d % 45) == 0 && d) - gdk_draw_line(draw, lg->grid, i, 0, i, lg->height); + if ((d % 45) == 0 && d) + gdk_draw_line(draw, lg->grid, i, 0, i, lg->height); - /* horizontal bars and labels; 25%, 50% and 75% */ - _draw_label_and_line(lg, -1, lg->max_value); - _draw_label_and_line(lg, lg->height / 4, 3 * (lg->max_value / 4)); - _draw_label_and_line(lg, lg->height / 2, lg->max_value / 2); + /* horizontal bars and labels; 25%, 50% and 75% */ + _draw_label_and_line(lg, -1, lg->max_value); + _draw_label_and_line(lg, lg->height / 4, 3 * (lg->max_value / 4)); + _draw_label_and_line(lg, lg->height / 2, lg->max_value / 2); _draw_label_and_line(lg, 3 * (lg->height / 4), lg->max_value / 4); - -#if 0 /* old-style drawing */ - for (i = 0; i < lg->size; i++) { - gint this = lg->height - lg->data[i] * lg->scale; - gint next = lg->height - lg->data[i+1] * lg->scale; - gint i4 = i * 4; - - gdk_draw_line(draw, lg->fill, i4, this, i4, lg->height); - gdk_draw_line(draw, lg->fill, i4 + 2, this, i4 + 2, lg->height); + +#if 0 /* old-style drawing */ + for (i = 0; i < lg->size; i++) { + gint this = lg->height - lg->data[i] * lg->scale; + gint next = lg->height - lg->data[i + 1] * lg->scale; + gint i4 = i * 4; + + gdk_draw_line(draw, lg->fill, i4, this, i4, lg->height); + gdk_draw_line(draw, lg->fill, i4 + 2, this, i4 + 2, lg->height); } - for (i = 0; i < lg->size; i++) { - gint this = lg->height - lg->data[i] * lg->scale; - gint next = lg->height - lg->data[i+1] * lg->scale; - gint i4 = i * 4; - - gdk_draw_line(draw, lg->trace, i4, this, i4 + 2, - (this + next) / 2); - gdk_draw_line(draw, lg->trace, i4 + 2, (this + next) / 2, - i4 + 4, next); + for (i = 0; i < lg->size; i++) { + gint this = lg->height - lg->data[i] * lg->scale; + gint next = lg->height - lg->data[i + 1] * lg->scale; + gint i4 = i * 4; + + gdk_draw_line(draw, lg->trace, i4, this, i4 + 2, + (this + next) / 2); + gdk_draw_line(draw, lg->trace, i4 + 2, (this + next) / 2, + i4 + 4, next); } #endif gtk_widget_queue_draw(lg->area); } -void -load_graph_update(LoadGraph *lg, gint value) +void load_graph_update(LoadGraph * lg, gint value) { gint i; - + if (value < 0) - return; - + return; + /* shift-right our data */ for (i = 0; i < lg->size; i++) { - lg->data[i] = lg->data[i+1]; + lg->data[i] = lg->data[i + 1]; } - + /* insert the updated value */ lg->data[i] = value; - + /* calculates the maximum value */ if (lg->remax_count++ > 20) { - /* only finds the maximum amongst the data every 20 times */ - lg->remax_count = 0; - - gint max = lg->data[0]; - for (i = 1; i < lg->size; i++) { - if (lg->data[i] > max) - max = lg->data[i]; - } - - lg->max_value = max; + /* only finds the maximum amongst the data every 20 times */ + lg->remax_count = 0; + + gint max = lg->data[0]; + for (i = 1; i < lg->size; i++) { + if (lg->data[i] > max) + max = lg->data[i]; + } + + lg->max_value = max; } else { - /* otherwise, select the maximum between the current maximum - and the supplied value */ - lg->max_value = MAX(value, lg->max_value); + /* otherwise, select the maximum between the current maximum + and the supplied value */ + lg->max_value = MAX(value, lg->max_value); } /* recalculates the scale; always use 90% of it */ - lg->scale = 0.90 * ((gfloat)lg->height / (gfloat)lg->max_value); + lg->scale = 0.90 * ((gfloat) lg->height / (gfloat) lg->max_value); /* redraw */ _draw(lg); @@ -302,22 +298,24 @@ load_graph_update(LoadGraph *lg, gint value) #ifdef LOADGRAPH_UNIT_TEST gboolean lg_update(gpointer d) { - LoadGraph *lg = (LoadGraph *)d; - + LoadGraph *lg = (LoadGraph *) d; + static int i = 0; static int j = 1; - + if (i > 150) { - j = -1; + j = -1; } else if (i < 0) { - j = 1; + j = 1; } i += j; - if (rand() % 10 > 8) i*= 2; - if (rand() % 10 < 2) i/= 2; + if (rand() % 10 > 8) + i *= 2; + if (rand() % 10 < 2) + i /= 2; load_graph_update(lg, i + rand() % 50); - + return TRUE; } @@ -325,23 +323,23 @@ int main(int argc, char **argv) { LoadGraph *lg; GtkWidget *window; - + gtk_init(&argc, &argv); - + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_show(window); - + lg = load_graph_new(50); gtk_container_add(GTK_CONTAINER(window), load_graph_get_framed(lg)); gtk_container_set_border_width(GTK_CONTAINER(window), 20); load_graph_configure_expose(lg); - + lg_update(lg); - + g_timeout_add(100, lg_update, lg); - + gtk_main(); - + return 0; } #endif @@ -315,7 +315,3 @@ int main(int argc, char **argv) return 0; } #endif /* TEST */ - - - -
\ No newline at end of file @@ -30,142 +30,143 @@ #include "uidefs.h" -static GtkActionEntry entries[] = -{ - { "InformationMenuAction", NULL, "_Information" }, /* name, stock id, label */ - { "ViewMenuAction", NULL, "_View" }, - { "HelpMenuAction", NULL, "_Help" }, - { "HelpMenuModulesAction", HI_STOCK_ABOUT_MODULES, "About _Modules" }, - { "MainMenuBarAction", NULL, "" }, - - { "ReportAction", HI_STOCK_REPORT, /* name, stock id */ - "Generate _Report", "<control>R", /* label, accelerator */ - NULL, /* tooltip */ - G_CALLBACK(cb_generate_report) }, - - { "SyncManagerAction", HI_STOCK_SYNC_MENU, - "_Network Updater...", NULL, - NULL, - G_CALLBACK(cb_sync_manager) }, - - { "CopyAction", GTK_STOCK_COPY, - "_Copy to Clipboard", "<control>C", - NULL, - G_CALLBACK(cb_copy_to_clipboard) }, - - { "SaveGraphAction", GTK_STOCK_SAVE_AS, - "_Save image as...", "<control>S", - NULL, - G_CALLBACK(cb_save_graphic) }, - - { "RefreshAction", GTK_STOCK_REFRESH, - "_Refresh", "F5", - NULL, - G_CALLBACK(cb_refresh) }, - - { "OnlineDocsAction", GTK_STOCK_HELP, - "Contents (online)", "F1", - NULL, - G_CALLBACK(cb_open_online_docs) }, - - { "HomePageAction", HI_STOCK_INTERNET, - "_Open HardInfo Web Site", NULL, - NULL, - G_CALLBACK(cb_open_web_page) }, - - { "ReportBugAction", HI_STOCK_INTERNET, - "_Report bug", NULL, - NULL, - G_CALLBACK(cb_report_bug) }, - - { "DonateAction", HI_STOCK_DONATE, - "_Donate to the project", NULL, - NULL, - G_CALLBACK(cb_donate) }, - - { "AboutAction", GTK_STOCK_ABOUT, - "_About HardInfo", NULL, - "Displays program version information", - G_CALLBACK(cb_about) }, - - { "QuitAction", GTK_STOCK_QUIT, - "_Quit", "<control>Q", - NULL, - G_CALLBACK(cb_quit) } +static GtkActionEntry entries[] = { + {"InformationMenuAction", NULL, "_Information"}, /* name, stock id, label */ + {"ViewMenuAction", NULL, "_View"}, + {"HelpMenuAction", NULL, "_Help"}, + {"HelpMenuModulesAction", HI_STOCK_ABOUT_MODULES, "About _Modules"}, + {"MainMenuBarAction", NULL, ""}, + + {"ReportAction", HI_STOCK_REPORT, /* name, stock id */ + "Generate _Report", "<control>R", /* label, accelerator */ + NULL, /* tooltip */ + G_CALLBACK(cb_generate_report)}, + + {"SyncManagerAction", HI_STOCK_SYNC_MENU, + "_Network Updater...", NULL, + NULL, + G_CALLBACK(cb_sync_manager)}, + + {"CopyAction", GTK_STOCK_COPY, + "_Copy to Clipboard", "<control>C", + NULL, + G_CALLBACK(cb_copy_to_clipboard)}, + + {"SaveGraphAction", GTK_STOCK_SAVE_AS, + "_Save image as...", "<control>S", + NULL, + G_CALLBACK(cb_save_graphic)}, + + {"RefreshAction", GTK_STOCK_REFRESH, + "_Refresh", "F5", + NULL, + G_CALLBACK(cb_refresh)}, + + {"OnlineDocsAction", GTK_STOCK_HELP, + "Contents (online)", "F1", + NULL, + G_CALLBACK(cb_open_online_docs)}, + + {"HomePageAction", HI_STOCK_INTERNET, + "_Open HardInfo Web Site", NULL, + NULL, + G_CALLBACK(cb_open_web_page)}, + + {"ReportBugAction", HI_STOCK_INTERNET, + "_Report bug", NULL, + NULL, + G_CALLBACK(cb_report_bug)}, + + {"DonateAction", HI_STOCK_DONATE, + "_Donate to the project", NULL, + NULL, + G_CALLBACK(cb_donate)}, + + {"AboutAction", GTK_STOCK_ABOUT, + "_About HardInfo", NULL, + "Displays program version information", + G_CALLBACK(cb_about)}, + + {"QuitAction", GTK_STOCK_QUIT, + "_Quit", "<control>Q", + NULL, + G_CALLBACK(cb_quit)} }; -static GtkToggleActionEntry toggle_entries[] = -{ - { "SidePaneAction", NULL, - "_Side Pane", NULL, - "Toggles side pane visibility", - G_CALLBACK(cb_side_pane) }, - { "ToolbarAction", NULL, - "_Toolbar", NULL, - NULL, - G_CALLBACK(cb_toolbar) }, +static GtkToggleActionEntry toggle_entries[] = { + {"SidePaneAction", NULL, + "_Side Pane", NULL, + "Toggles side pane visibility", + G_CALLBACK(cb_side_pane)}, + {"ToolbarAction", NULL, + "_Toolbar", NULL, + NULL, + G_CALLBACK(cb_toolbar)}, }; /* Implement a handler for GtkUIManager's "add_widget" signal. The UI manager * will emit this signal whenever it needs you to place a new widget it has. */ static void -menu_add_widget(GtkUIManager *ui, GtkWidget *widget, GtkContainer *container) +menu_add_widget(GtkUIManager * ui, GtkWidget * widget, + GtkContainer * container) { gtk_box_pack_start(GTK_BOX(container), widget, FALSE, FALSE, 0); gtk_widget_show(widget); } -void menu_init(Shell *shell) +void menu_init(Shell * shell) { - GtkWidget *menu_box; /* Packing box for the menu and toolbars */ - GtkActionGroup *action_group; /* Packing group for our Actions */ - GtkUIManager *menu_manager; /* The magic widget! */ - GError *error; /* For reporting exceptions or errors */ - GtkAccelGroup *accel_group; - + GtkWidget *menu_box; /* Packing box for the menu and toolbars */ + GtkActionGroup *action_group; /* Packing group for our Actions */ + GtkUIManager *menu_manager; /* The magic widget! */ + GError *error; /* For reporting exceptions or errors */ + GtkAccelGroup *accel_group; + /* Create our objects */ menu_box = shell->vbox; action_group = gtk_action_group_new("HardInfo"); menu_manager = gtk_ui_manager_new(); - + shell->action_group = action_group; - shell->ui_manager = menu_manager; - + shell->ui_manager = menu_manager; + /* Pack up our objects: * menu_box -> window * actions -> action_group * action_group -> menu_manager */ - gtk_action_group_add_actions(action_group, entries, G_N_ELEMENTS(entries), - NULL); + gtk_action_group_add_actions(action_group, entries, + G_N_ELEMENTS(entries), NULL); gtk_action_group_add_toggle_actions(action_group, toggle_entries, - G_N_ELEMENTS(toggle_entries), NULL); + G_N_ELEMENTS(toggle_entries), + NULL); gtk_ui_manager_insert_action_group(menu_manager, action_group, 0); - + /* Read in the UI from our XML file */ error = NULL; - gtk_ui_manager_add_ui_from_string(menu_manager, uidefs_str, -1, &error); - + gtk_ui_manager_add_ui_from_string(menu_manager, uidefs_str, -1, + &error); + if (error) { - g_error("Building menus failed: %s", error->message); - g_error_free(error); - return; + g_error("Building menus failed: %s", error->message); + g_error_free(error); + return; } - + /* Enable menu accelerators */ accel_group = gtk_ui_manager_get_accel_group(menu_manager); gtk_window_add_accel_group(GTK_WINDOW(shell->window), accel_group); - + /* Connect up important signals */ /* This signal is necessary in order to place widgets from the UI manager * into the menu_box */ - g_signal_connect(menu_manager, "add_widget", - G_CALLBACK(menu_add_widget), - menu_box); - + g_signal_connect(menu_manager, "add_widget", + G_CALLBACK(menu_add_widget), menu_box); + /* Show the window and run the main loop, we're done! */ gtk_widget_show(menu_box); - gtk_toolbar_set_style(GTK_TOOLBAR(gtk_ui_manager_get_widget(shell->ui_manager, "/MainMenuBarAction")), - GTK_TOOLBAR_BOTH_HORIZ); + gtk_toolbar_set_style(GTK_TOOLBAR + (gtk_ui_manager_get_widget + (shell->ui_manager, "/MainMenuBarAction")), + GTK_TOOLBAR_BOTH_HORIZ); } - diff --git a/pixmaps/network-generic.png b/pixmaps/network-generic.png Binary files differnew file mode 100644 index 00000000..caebd989 --- /dev/null +++ b/pixmaps/network-generic.png diff --git a/pixmaps/wireless.png b/pixmaps/wireless.png Binary files differnew file mode 100644 index 00000000..2d7851fa --- /dev/null +++ b/pixmaps/wireless.png @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - + #include <report.h> #include <stdio.h> #include <string.h> @@ -24,130 +24,127 @@ #include <hardinfo.h> #include <config.h> -static ReportDialog *report_dialog_new(GtkTreeModel *model, GtkWidget *parent); -static void set_all_active(ReportDialog *rd, gboolean setting); +static ReportDialog *report_dialog_new(GtkTreeModel * model, + GtkWidget * parent); +static void set_all_active(ReportDialog * rd, gboolean setting); static FileTypes file_types[] = { - { "HTML (*.html)", "text/html", ".html", report_context_html_new }, - { "Plain Text (*.txt)", "text/plain", ".txt", report_context_text_new }, - { NULL, NULL, NULL, NULL } + {"HTML (*.html)", "text/html", ".html", report_context_html_new}, + {"Plain Text (*.txt)", "text/plain", ".txt", report_context_text_new}, + {NULL, NULL, NULL, NULL} }; -void -report_header(ReportContext *ctx) +void report_header(ReportContext * ctx) { ctx->header(ctx); } -void -report_footer(ReportContext *ctx) +void report_footer(ReportContext * ctx) { ctx->footer(ctx); } -void -report_title(ReportContext *ctx, gchar *text) +void report_title(ReportContext * ctx, gchar * text) { ctx->title(ctx, text); } -void -report_subtitle(ReportContext *ctx, gchar *text) +void report_subtitle(ReportContext * ctx, gchar * text) { ctx->subtitle(ctx, text); } -void -report_subsubtitle(ReportContext *ctx, gchar *text) +void report_subsubtitle(ReportContext * ctx, gchar * text) { ctx->subsubtitle(ctx, text); } -void -report_key_value(ReportContext *ctx, gchar *key, gchar *value) +void report_key_value(ReportContext * ctx, gchar * key, gchar * value) { ctx->keyvalue(ctx, key, value); } -void -report_context_configure(ReportContext *ctx, GKeyFile *keyfile) +void report_context_configure(ReportContext * ctx, GKeyFile * keyfile) { /* FIXME: sometime in the future we'll save images in the report. this - flag will be set if we should support that. - - so i don't forget how to encode the images inside the html files: - http://en.wikipedia.org/wiki/Data:_URI_scheme */ - + flag will be set if we should support that. + + so i don't forget how to encode the images inside the html files: + http://en.wikipedia.org/wiki/Data:_URI_scheme */ + ctx->is_image_enabled = (g_key_file_get_boolean(keyfile, - "$ShellParam$", - "ViewType", - NULL) == SHELL_VIEW_PROGRESS); + "$ShellParam$", + "ViewType", + NULL) == + SHELL_VIEW_PROGRESS); } -void -report_table(ReportContext *ctx, gchar *text) +void report_table(ReportContext * ctx, gchar * text) { - GKeyFile *key_file = g_key_file_new(); - gchar **groups; - gint i; + GKeyFile *key_file = g_key_file_new(); + gchar **groups; + gint i; g_key_file_load_from_data(key_file, text, strlen(text), 0, NULL); groups = g_key_file_get_groups(key_file, NULL); - + for (i = 0; groups[i]; i++) { - gchar *group, *tmpgroup; + gchar *group, *tmpgroup; gchar **keys; - gint j; - + gint j; + if (groups[i][0] == '$') { report_context_configure(ctx, key_file); continue; - } - - group = groups[i]; + } + + group = groups[i]; - tmpgroup = g_strdup(group); - strend(group, '#'); + tmpgroup = g_strdup(group); + strend(group, '#'); + + report_subsubtitle(ctx, group); - report_subsubtitle(ctx, group); - #if 0 - if (ctx->is_image_enabled) { - report_embed_image(ctx, key_file, group); - } else { -#endif - keys = g_key_file_get_keys(key_file, tmpgroup, NULL, NULL); - for (j = 0; keys[j]; j++) { - gchar *key = keys[j]; - gchar *value; - - value = g_key_file_get_value(key_file, tmpgroup, key, NULL); - - if (g_utf8_validate(key, -1, NULL) && g_utf8_validate(value, -1, NULL)) { - strend(key, '#'); - - if (g_str_equal(value, "...")) { - g_free(value); - if (!(value = ctx->entry->fieldfunc(key))) { - value = g_strdup("..."); - } - } - - if (*key == '$') { - report_key_value(ctx, strchr(key + 1, '$') + 1, value); - } else { - report_key_value(ctx, key, value); - } - - } - - g_free(value); - } - - g_strfreev(keys); + if (ctx->is_image_enabled) { + report_embed_image(ctx, key_file, group); + } else { +#endif + keys = g_key_file_get_keys(key_file, tmpgroup, NULL, NULL); + for (j = 0; keys[j]; j++) { + gchar *key = keys[j]; + gchar *value; + + value = + g_key_file_get_value(key_file, tmpgroup, key, NULL); + + if (g_utf8_validate(key, -1, NULL) + && g_utf8_validate(value, -1, NULL)) { + strend(key, '#'); + + if (g_str_equal(value, "...")) { + g_free(value); + if (!(value = ctx->entry->fieldfunc(key))) { + value = g_strdup("..."); + } + } + + if (*key == '$') { + report_key_value(ctx, strchr(key + 1, '$') + 1, + value); + } else { + report_key_value(ctx, key, value); + } + + } + + g_free(value); + } + + g_strfreev(keys); #if 0 - } -#endif + } +#endif g_free(tmpgroup); } @@ -155,397 +152,381 @@ report_table(ReportContext *ctx, gchar *text) g_key_file_free(key_file); } -static void -report_html_header(ReportContext *ctx) +static void report_html_header(ReportContext * ctx) { if (ctx->output) - g_free(ctx->output); - - ctx->output = g_strdup_printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Final//EN\">\n" \ - "<html><head>\n" \ - "<title>HardInfo (%s) System Report</title>\n" \ - "<style>\n" \ - " body { background: #fff }\n" \ - " .title { font: bold 130%% serif; color: #0066FF; padding: 30px 0 10px 0 }\n" \ - " .stitle { font: bold 100%% sans-serif; color: #0044DD; padding: 30px 0 10px 0 }\n" \ - " .sstitle{ font: bold 80%% serif; color: #000000; background: #efefef }\n" \ - " .field { font: 80%% sans-serif; color: #000000; padding: 2px; padding-left: 50px }\n" \ - " .value { font: 80%% sans-serif; color: #505050 }\n" \ - "</style>\n" \ - "</head><body>\n" \ - "<table width=\"100%%\"><tbody>", VERSION); + g_free(ctx->output); + + ctx->output = + g_strdup_printf + ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Final//EN\">\n" + "<html><head>\n" "<title>HardInfo (%s) System Report</title>\n" + "<style>\n" " body { background: #fff }\n" + " .title { font: bold 130%% serif; color: #0066FF; padding: 30px 0 10px 0 }\n" + " .stitle { font: bold 100%% sans-serif; color: #0044DD; padding: 30px 0 10px 0 }\n" + " .sstitle{ font: bold 80%% serif; color: #000000; background: #efefef }\n" + " .field { font: 80%% sans-serif; color: #000000; padding: 2px; padding-left: 50px }\n" + " .value { font: 80%% sans-serif; color: #505050 }\n" + "</style>\n" "</head><body>\n" "<table width=\"100%%\"><tbody>", + VERSION); } -static void -report_html_footer(ReportContext *ctx) +static void report_html_footer(ReportContext * ctx) { ctx->output = g_strconcat(ctx->output, - "</tbody></table></body></html>", - NULL); + "</tbody></table></body></html>", NULL); } -static void -report_html_title(ReportContext *ctx, gchar *text) +static void report_html_title(ReportContext * ctx, gchar * text) { - ctx->output = g_strdup_printf("%s" \ - "<tr><td colspan=\"2\" class=\"titl" \ - "e\">%s</td></tr>\n", - ctx->output, text); + ctx->output = g_strdup_printf("%s" + "<tr><td colspan=\"2\" class=\"titl" + "e\">%s</td></tr>\n", ctx->output, text); } -static void -report_html_subtitle(ReportContext *ctx, gchar *text) +static void report_html_subtitle(ReportContext * ctx, gchar * text) { - ctx->output = g_strdup_printf("%s" \ - "<tr><td colspan=\"2\" class=\"stit" \ - "le\">%s</td></tr>\n", - ctx->output, text); + ctx->output = g_strdup_printf("%s" + "<tr><td colspan=\"2\" class=\"stit" + "le\">%s</td></tr>\n", + ctx->output, text); } -static void -report_html_subsubtitle(ReportContext *ctx, gchar *text) +static void report_html_subsubtitle(ReportContext * ctx, gchar * text) { - ctx->output = g_strdup_printf("%s" \ - "<tr><td colspan=\"2\" class=\"ssti" \ - "tle\">%s</td></tr>\n", - ctx->output, text); + ctx->output = g_strdup_printf("%s" + "<tr><td colspan=\"2\" class=\"ssti" + "tle\">%s</td></tr>\n", + ctx->output, text); } static void -report_html_key_value(ReportContext *ctx, gchar *key, gchar *value) +report_html_key_value(ReportContext * ctx, gchar * key, gchar * value) { - ctx->output = g_strdup_printf("%s" \ - "<tr><td class=\"field\">%s</td>" \ - "<td class=\"value\">%s</td></tr>\n", - ctx->output, key, value); + ctx->output = g_strdup_printf("%s" + "<tr><td class=\"field\">%s</td>" + "<td class=\"value\">%s</td></tr>\n", + ctx->output, key, value); } -static void -report_text_header(ReportContext *ctx) +static void report_text_header(ReportContext * ctx) { if (ctx->output) - g_free(ctx->output); - + g_free(ctx->output); + ctx->output = g_strdup(""); } -static void -report_text_footer(ReportContext *ctx) +static void report_text_footer(ReportContext * ctx) { } -static void -report_text_title(ReportContext *ctx, gchar *text) +static void report_text_title(ReportContext * ctx, gchar * text) { - gchar *str = (gchar*)ctx->output; + gchar *str = (gchar *) ctx->output; int i = strlen(text); - + str = g_strdup_printf("%s\n%s\n", str, text); for (; i; i--) - str = g_strconcat(str, "*", NULL); - + str = g_strconcat(str, "*", NULL); + str = g_strconcat(str, "\n\n", NULL); ctx->output = str; } -static void -report_text_subtitle(ReportContext *ctx, gchar *text) +static void report_text_subtitle(ReportContext * ctx, gchar * text) { gchar *str = ctx->output; int i = strlen(text); - + str = g_strdup_printf("%s\n%s\n", str, text); for (; i; i--) - str = g_strconcat(str, "-", NULL); - + str = g_strconcat(str, "-", NULL); + str = g_strconcat(str, "\n\n", NULL); ctx->output = str; } -static void -report_text_subsubtitle(ReportContext *ctx, gchar *text) +static void report_text_subsubtitle(ReportContext * ctx, gchar * text) { ctx->output = g_strdup_printf("%s-%s-\n", ctx->output, text); } static void -report_text_key_value(ReportContext *ctx, gchar *key, gchar *value) +report_text_key_value(ReportContext * ctx, gchar * key, gchar * value) { if (strlen(value)) - ctx->output = g_strdup_printf("%s%s\t\t: %s\n", ctx->output, key, value); + ctx->output = + g_strdup_printf("%s%s\t\t: %s\n", ctx->output, key, value); else - ctx->output = g_strdup_printf("%s%s\n", ctx->output, key); + ctx->output = g_strdup_printf("%s%s\n", ctx->output, key); } -static GSList * -report_create_module_list_from_dialog(ReportDialog *rd) +static GSList *report_create_module_list_from_dialog(ReportDialog * rd) { - ShellModule *module; - GSList *modules = NULL; + ShellModule *module; + GSList *modules = NULL; GtkTreeModel *model = rd->model; - GtkTreeIter iter; + GtkTreeIter iter; gtk_tree_model_get_iter_first(model, &iter); do { - gboolean selected; - gchar *name; - - gtk_tree_model_get(model, &iter, TREE_COL_SEL, &selected, -1); - if (!selected) - continue; - - module = g_new0(ShellModule, 1); - - gtk_tree_model_get(model, &iter, TREE_COL_NAME, &name, -1); - module->name = name; - module->entries = NULL; - - if (gtk_tree_model_iter_has_child(model, &iter)) { - ShellModuleEntry *entry; - - gint children = gtk_tree_model_iter_n_children(model, &iter); - gint i; - - for (i = 0; i < children; i++) { - GtkTreeIter child; - - gtk_tree_model_iter_nth_child(model, &child, &iter, i); - - gtk_tree_model_get(model, &child, TREE_COL_SEL, &selected, -1); - if (!selected) - continue; - - gtk_tree_model_get(model, &child, TREE_COL_DATA, &entry, -1); - module->entries = g_slist_append(module->entries, entry); - } - } - - modules = g_slist_append(modules, module); + gboolean selected; + gchar *name; + + gtk_tree_model_get(model, &iter, TREE_COL_SEL, &selected, -1); + if (!selected) + continue; + + module = g_new0(ShellModule, 1); + + gtk_tree_model_get(model, &iter, TREE_COL_NAME, &name, -1); + module->name = name; + module->entries = NULL; + + if (gtk_tree_model_iter_has_child(model, &iter)) { + ShellModuleEntry *entry; + + gint children = gtk_tree_model_iter_n_children(model, &iter); + gint i; + + for (i = 0; i < children; i++) { + GtkTreeIter child; + + gtk_tree_model_iter_nth_child(model, &child, &iter, i); + + gtk_tree_model_get(model, &child, TREE_COL_SEL, &selected, + -1); + if (!selected) + continue; + + gtk_tree_model_get(model, &child, TREE_COL_DATA, &entry, + -1); + module->entries = g_slist_append(module->entries, entry); + } + } + + modules = g_slist_append(modules, module); } while (gtk_tree_model_iter_next(rd->model, &iter)); - + return modules; } static void -report_create_inner_from_module_list(ReportContext *ctx, GSList *modules) +report_create_inner_from_module_list(ReportContext * ctx, GSList * modules) { for (; modules; modules = modules->next) { - ShellModule *module = (ShellModule *) modules->data; - GSList *entries; - - if (!params.gui_running) - fprintf(stderr, "\033[40;32m%s\033[0m\n", module->name); - - report_title(ctx, module->name); - - for (entries = module->entries; entries; entries = entries->next) { - ShellModuleEntry *entry = (ShellModuleEntry *) entries->data; - - if (!params.gui_running) - fprintf(stderr, "\033[2K\033[40;32;1m %s\033[0m\n", entry->name); - - ctx->entry = entry; - report_subtitle(ctx, entry->name); - module_entry_scan(entry); - report_table(ctx, module_entry_function(entry)); - } + ShellModule *module = (ShellModule *) modules->data; + GSList *entries; + + if (!params.gui_running) + fprintf(stderr, "\033[40;32m%s\033[0m\n", module->name); + + report_title(ctx, module->name); + + for (entries = module->entries; entries; entries = entries->next) { + ShellModuleEntry *entry = (ShellModuleEntry *) entries->data; + + if (!params.gui_running) + fprintf(stderr, "\033[2K\033[40;32;1m %s\033[0m\n", + entry->name); + + ctx->entry = entry; + report_subtitle(ctx, entry->name); + module_entry_scan(entry); + report_table(ctx, module_entry_function(entry)); + } } } -void report_module_list_free(GSList *modules) +void report_module_list_free(GSList * modules) { GSList *m; - + for (m = modules; m; m = m->next) { - ShellModule *module = (ShellModule *) m->data; - - g_slist_free(module->entries); + ShellModule *module = (ShellModule *) m->data; + + g_slist_free(module->entries); } - + g_slist_free(modules); } -static gchar * -report_get_filename(void) +static gchar *report_get_filename(void) { GtkWidget *dialog; gchar *filename = NULL; dialog = gtk_file_chooser_dialog_new("Save File", - NULL, - GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, - NULL); - - gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "hardinfo report"); - + NULL, + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, + GTK_RESPONSE_ACCEPT, NULL); + + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), + "hardinfo report"); + file_chooser_add_filters(dialog, file_types); file_chooser_open_expander(dialog); - - if (gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { - gchar *ext = file_chooser_get_extension(dialog, file_types); - filename = file_chooser_build_filename(dialog, ext); - } - gtk_widget_destroy (dialog); + + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { + gchar *ext = file_chooser_get_extension(dialog, file_types); + filename = file_chooser_build_filename(dialog, ext); + } + gtk_widget_destroy(dialog); return filename; } -ReportContext* -report_context_html_new() +ReportContext *report_context_html_new() { ReportContext *ctx; - + ctx = g_new0(ReportContext, 1); - ctx->header = report_html_header; - ctx->footer = report_html_footer; - ctx->title = report_html_title; - ctx->subtitle = report_html_subtitle; + ctx->header = report_html_header; + ctx->footer = report_html_footer; + ctx->title = report_html_title; + ctx->subtitle = report_html_subtitle; ctx->subsubtitle = report_html_subsubtitle; - ctx->keyvalue = report_html_key_value; - + ctx->keyvalue = report_html_key_value; + ctx->output = g_strdup(""); ctx->format = REPORT_FORMAT_HTML; - + return ctx; } -ReportContext* -report_context_text_new() +ReportContext *report_context_text_new() { ReportContext *ctx; - + ctx = g_new0(ReportContext, 1); - ctx->header = report_text_header; - ctx->footer = report_text_footer; - ctx->title = report_text_title; - ctx->subtitle = report_text_subtitle; + ctx->header = report_text_header; + ctx->footer = report_text_footer; + ctx->title = report_text_title; + ctx->subtitle = report_text_subtitle; ctx->subsubtitle = report_text_subsubtitle; - ctx->keyvalue = report_text_key_value; - + ctx->keyvalue = report_text_key_value; + ctx->output = g_strdup(""); ctx->format = REPORT_FORMAT_TEXT; - + return ctx; } -void -report_context_free(ReportContext *ctx) +void report_context_free(ReportContext * ctx) { g_free(ctx->output); g_free(ctx); } -void -report_create_from_module_list(ReportContext *ctx, GSList *modules) +void report_create_from_module_list(ReportContext * ctx, GSList * modules) { report_header(ctx); - + report_create_inner_from_module_list(ctx, modules); report_module_list_free(modules); report_footer(ctx); } -gchar * -report_create_from_module_list_format(GSList *modules, ReportFormat format) +gchar *report_create_from_module_list_format(GSList * modules, + ReportFormat format) { - ReportContext *(*create_context)(); - ReportContext *ctx; - gchar *retval; - + ReportContext *(*create_context) (); + ReportContext *ctx; + gchar *retval; + if (format >= N_REPORT_FORMAT) - return NULL; - + return NULL; + create_context = file_types[format].data; if (!create_context) - return NULL; - + return NULL; + ctx = create_context(); report_create_from_module_list(ctx, modules); retval = g_strdup(ctx->output); - + report_context_free(ctx); - + return retval; } -static gboolean -report_generate(ReportDialog *rd) +static gboolean report_generate(ReportDialog * rd) { - GSList *modules; - ReportContext *ctx; - ReportContext *(*create_context)(); - gchar *file; - FILE *stream; - + GSList *modules; + ReportContext *ctx; + ReportContext *(*create_context) (); + gchar *file; + FILE *stream; + if (!(file = report_get_filename())) - return FALSE; + return FALSE; if (!(stream = fopen(file, "w+"))) { - g_free(file); - return FALSE; + g_free(file); + return FALSE; } - + create_context = file_types_get_data_by_name(file_types, file); - + if (!create_context) { - g_warning("Cannot create ReportContext. Programming bug?"); - g_free(file); - return FALSE; + g_warning("Cannot create ReportContext. Programming bug?"); + g_free(file); + return FALSE; } ctx = create_context(); modules = report_create_module_list_from_dialog(rd); - + report_create_from_module_list(ctx, modules); fputs(ctx->output, stream); fclose(stream); - + if (ctx->format == REPORT_FORMAT_HTML) { - GtkWidget *dialog; - dialog = gtk_message_dialog_new(NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_NONE, - "Open the report with your web browser?"); + GtkWidget *dialog; + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + "Open the report with your web browser?"); gtk_dialog_add_buttons(GTK_DIALOG(dialog), GTK_STOCK_NO, GTK_RESPONSE_REJECT, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) open_url(file); gtk_widget_destroy(dialog); } - + report_context_free(ctx); g_free(file); - + return TRUE; } -void -report_dialog_show(GtkTreeModel *model, GtkWidget *parent) +void report_dialog_show(GtkTreeModel * model, GtkWidget * parent) { gboolean success; ReportDialog *rd = report_dialog_new(model, parent); if (gtk_dialog_run(GTK_DIALOG(rd->dialog)) == GTK_RESPONSE_ACCEPT) { shell_status_update("Generating report..."); - gtk_widget_hide(rd->dialog); - shell_view_set_enabled(FALSE); - shell_status_set_enabled(TRUE); + gtk_widget_hide(rd->dialog); + shell_view_set_enabled(FALSE); + shell_status_set_enabled(TRUE); success = report_generate(rd); - shell_status_set_enabled(FALSE); - - if (success) - shell_status_update("Report saved."); - else - shell_status_update("Error while creating the report."); + shell_status_set_enabled(FALSE); + + if (success) + shell_status_update("Report saved."); + else + shell_status_update("Error while creating the report."); } set_all_active(rd, FALSE); @@ -554,69 +535,69 @@ report_dialog_show(GtkTreeModel *model, GtkWidget *parent) } static void -set_children_active(GtkTreeModel *model, GtkTreeIter *iter, gboolean setting) +set_children_active(GtkTreeModel * model, GtkTreeIter * iter, + gboolean setting) { if (gtk_tree_model_iter_has_child(model, iter)) { - gint children = gtk_tree_model_iter_n_children(model, iter); - - gtk_tree_store_set(GTK_TREE_STORE(model), iter, TREE_COL_SEL, setting, -1); - - for (children--; children >= 0; children--) { - GtkTreeIter child; - - gtk_tree_model_iter_nth_child(model, &child, iter, children); - gtk_tree_store_set(GTK_TREE_STORE(model), &child, TREE_COL_SEL, setting, -1); - } + gint children = gtk_tree_model_iter_n_children(model, iter); + + gtk_tree_store_set(GTK_TREE_STORE(model), iter, TREE_COL_SEL, + setting, -1); + + for (children--; children >= 0; children--) { + GtkTreeIter child; + + gtk_tree_model_iter_nth_child(model, &child, iter, children); + gtk_tree_store_set(GTK_TREE_STORE(model), &child, TREE_COL_SEL, + setting, -1); + } } } -static void -set_all_active(ReportDialog *rd, gboolean setting) +static void set_all_active(ReportDialog * rd, gboolean setting) { GtkTreeIter iter; GtkTreeModel *model = rd->model; - + gtk_tree_model_get_iter_first(model, &iter); - + do { - set_children_active(model, &iter, setting); + set_children_active(model, &iter, setting); } while (gtk_tree_model_iter_next(model, &iter)); } -static void -report_dialog_sel_none(GtkWidget *widget, ReportDialog *rd) +static void report_dialog_sel_none(GtkWidget * widget, ReportDialog * rd) { set_all_active(rd, FALSE); } -static void -report_dialog_sel_all(GtkWidget *widget, ReportDialog *rd) +static void report_dialog_sel_all(GtkWidget * widget, ReportDialog * rd) { set_all_active(rd, TRUE); } static void -report_dialog_sel_toggle(GtkCellRendererToggle *cellrenderertoggle, - gchar *path_str, - ReportDialog *rd) +report_dialog_sel_toggle(GtkCellRendererToggle * cellrenderertoggle, + gchar * path_str, ReportDialog * rd) { GtkTreeModel *model = rd->model; - GtkTreeIter iter; + GtkTreeIter iter; GtkTreePath *path = gtk_tree_path_new_from_string(path_str); gboolean active; - + gtk_tree_model_get_iter(model, &iter, path); gtk_tree_model_get(model, &iter, TREE_COL_SEL, &active, -1); - + active = !active; - gtk_tree_store_set(GTK_TREE_STORE(model), &iter, TREE_COL_SEL, active, -1); + gtk_tree_store_set(GTK_TREE_STORE(model), &iter, TREE_COL_SEL, active, + -1); set_children_active(model, &iter, active); gtk_tree_path_free(path); } static ReportDialog -*report_dialog_new(GtkTreeModel *model, GtkWidget *parent) + * report_dialog_new(GtkTreeModel * model, GtkWidget * parent) { ReportDialog *rd; GtkWidget *dialog; @@ -631,10 +612,10 @@ static ReportDialog GtkWidget *button7; GtkWidget *label; GtkWidget *hbox; - + GtkTreeViewColumn *column; - GtkCellRenderer *cr_text, *cr_pbuf, *cr_toggle; - + GtkCellRenderer *cr_text, *cr_pbuf, *cr_toggle; + rd = g_new0(ReportDialog, 1); dialog = gtk_dialog_new(); @@ -642,7 +623,8 @@ static ReportDialog gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); gtk_window_set_default_size(GTK_WINDOW(dialog), 420, 260); gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent)); - gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT); + gtk_window_set_position(GTK_WINDOW(dialog), + GTK_WIN_POS_CENTER_ON_PARENT); gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG); @@ -650,26 +632,27 @@ static ReportDialog gtk_box_set_spacing(GTK_BOX(dialog1_vbox), 5); gtk_container_set_border_width(GTK_CONTAINER(dialog1_vbox), 4); gtk_widget_show(dialog1_vbox); - + hbox = gtk_hbox_new(FALSE, 5); gtk_box_pack_start(GTK_BOX(dialog1_vbox), hbox, FALSE, FALSE, 0); - - label = gtk_label_new("<big><b>Generate Report</b></big>\n" \ - "Please choose the information that you wish " \ - "to view in your report:"); + + label = gtk_label_new("<big><b>Generate Report</b></big>\n" + "Please choose the information that you wish " + "to view in your report:"); gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); gtk_label_set_use_markup(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - + gtk_box_pack_start(GTK_BOX(hbox), - icon_cache_get_image("report-large.png"), - FALSE, FALSE, 0); + icon_cache_get_image("report-large.png"), + FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0); gtk_widget_show_all(hbox); - + scrolledwindow2 = gtk_scrolled_window_new(NULL, NULL); gtk_widget_show(scrolledwindow2); - gtk_box_pack_start(GTK_BOX(dialog1_vbox), scrolledwindow2, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(dialog1_vbox), scrolledwindow2, TRUE, TRUE, + 0); gtk_widget_set_size_request(scrolledwindow2, -1, 200); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow2), GTK_POLICY_AUTOMATIC, @@ -681,13 +664,14 @@ static ReportDialog gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview2), FALSE); gtk_widget_show(treeview2); gtk_container_add(GTK_CONTAINER(scrolledwindow2), treeview2); - + column = gtk_tree_view_column_new(); gtk_tree_view_append_column(GTK_TREE_VIEW(treeview2), column); cr_toggle = gtk_cell_renderer_toggle_new(); gtk_tree_view_column_pack_start(column, cr_toggle, FALSE); - g_signal_connect(cr_toggle, "toggled", G_CALLBACK(report_dialog_sel_toggle), rd); + g_signal_connect(cr_toggle, "toggled", + G_CALLBACK(report_dialog_sel_toggle), rd); gtk_tree_view_column_add_attribute(column, cr_toggle, "active", TREE_COL_SEL); @@ -700,7 +684,7 @@ static ReportDialog gtk_tree_view_column_pack_start(column, cr_text, TRUE); gtk_tree_view_column_add_attribute(column, cr_text, "markup", TREE_COL_NAME); - + hbuttonbox3 = gtk_hbutton_box_new(); gtk_widget_show(hbuttonbox3); gtk_box_pack_start(GTK_BOX(dialog1_vbox), hbuttonbox3, FALSE, TRUE, 0); @@ -711,13 +695,15 @@ static ReportDialog gtk_widget_show(button3); gtk_container_add(GTK_CONTAINER(hbuttonbox3), button3); GTK_WIDGET_SET_FLAGS(button3, GTK_CAN_DEFAULT); - g_signal_connect(button3, "clicked", G_CALLBACK(report_dialog_sel_none), rd); + g_signal_connect(button3, "clicked", + G_CALLBACK(report_dialog_sel_none), rd); button6 = gtk_button_new_with_mnemonic("Select _All"); gtk_widget_show(button6); gtk_container_add(GTK_CONTAINER(hbuttonbox3), button6); GTK_WIDGET_SET_FLAGS(button6, GTK_CAN_DEFAULT); - g_signal_connect(button6, "clicked", G_CALLBACK(report_dialog_sel_all), rd); + g_signal_connect(button6, "clicked", G_CALLBACK(report_dialog_sel_all), + rd); dialog1_action_area = GTK_DIALOG(dialog)->action_area; gtk_widget_show(dialog1_action_area); @@ -736,13 +722,13 @@ static ReportDialog GTK_RESPONSE_ACCEPT); GTK_WIDGET_SET_FLAGS(button7, GTK_CAN_DEFAULT); - rd->dialog = dialog; - rd->btn_cancel = button8; - rd->btn_generate = button7; - rd->btn_sel_all = button6; - rd->btn_sel_none = button3; - rd->treeview = treeview2; - rd->model = model; + rd->dialog = dialog; + rd->btn_cancel = button8; + rd->btn_generate = button7; + rd->btn_sel_all = button6; + rd->btn_sel_none = button3; + rd->treeview = treeview2; + rd->model = model; gtk_tree_view_collapse_all(GTK_TREE_VIEW(treeview2)); set_all_active(rd, TRUE); @@ -176,7 +176,7 @@ void SHA1Init(SHA1_CTX * context) /* Run your data through this. */ -void SHA1Update(SHA1_CTX * context, guchar *data, guint32 len) +void SHA1Update(SHA1_CTX * context, guchar * data, guint32 len) { guint32 i, j; @@ -206,7 +206,7 @@ void SHA1Final(guchar digest[20], SHA1_CTX * context) for (i = 0; i < 8; i++) { finalcount[i] = (guchar) ((context->count[(i >= 4 ? 0 : 1)] - >> ((3 - (i & 3)) * 8)) & 255); /* Endian independent */ + >> ((3 - (i & 3)) * 8)) & 255); /* Endian independent */ } SHA1Update(context, (guchar *) "\200", 1); while ((context->count[0] & 504) != 448) { @@ -236,8 +236,8 @@ void g_assert(int a) /* Bah, who needs testing anyway... ;) */ } -static void base32_encode_exactly(guchar *buf, gint len, - guchar *encbuf, gint enclen) +static void base32_encode_exactly(guchar * buf, gint len, + guchar * encbuf, gint enclen) { gint i = 0; guchar *ip = buf + len; @@ -252,26 +252,26 @@ static void base32_encode_exactly(guchar *buf, gint len, i >>= 5; /* upper <234>, input #4 */ /* FALLTHROUGH */ case 4: - i |= ((guint32) *--ip) << 3; /* had 3 bits in `i' */ + i |= ((guint32) * --ip) << 3; /* had 3 bits in `i' */ *--op = b32_alphabet[i & 0x1f]; /* Output #6 */ i >>= 5; /* upper <401234>, input #3 */ *--op = b32_alphabet[i & 0x1f]; /* Output #5 */ i >>= 5; /* upper <4>, input #3 */ /* FALLTHROUGH */ case 3: - i |= ((guint32) *--ip) << 1; /* had 1 bits in `i' */ + i |= ((guint32) * --ip) << 1; /* had 1 bits in `i' */ *--op = b32_alphabet[i & 0x1f]; /* Output #4 */ i >>= 5; /* upper <1234>, input #2 */ /* FALLTHROUGH */ case 2: - i |= ((guint32) *--ip) << 4; /* had 4 bits in `i' */ + i |= ((guint32) * --ip) << 4; /* had 4 bits in `i' */ *--op = b32_alphabet[i & 0x1f]; /* Output #3 */ i >>= 5; /* upper <3401234>, input #1 */ *--op = b32_alphabet[i & 0x1f]; /* Output #2 */ i >>= 5; /* upper <34>, input #1 */ /* FALLTHROUGH */ case 1: - i |= ((guint32) *--ip) << 2; /* had 2 bits in `i' */ + i |= ((guint32) * --ip) << 2; /* had 2 bits in `i' */ *--op = b32_alphabet[i & 0x1f]; /* Output #1 */ i >>= 5; /* upper <01234>, input #0 */ *--op = b32_alphabet[i & 0x1f]; /* Output #0 */ @@ -51,9 +51,9 @@ static gboolean update_field(gpointer data); * Globals ******************************************************************** */ -static Shell *shell = NULL; +static Shell *shell = NULL; static GHashTable *update_tbl = NULL; -static GSList *update_sfusrc = NULL; +static GSList *update_sfusrc = NULL; /* * Code :) ******************************************************************** @@ -251,7 +251,10 @@ void shell_view_set_enabled(gboolean setting) shell_action_set_enabled("RefreshAction", setting); shell_action_set_enabled("CopyAction", setting); shell_action_set_enabled("ReportAction", setting); - shell_action_set_enabled("SaveGraphAction", setting ? shell->view_type == SHELL_VIEW_PROGRESS : FALSE); + shell_action_set_enabled("SyncManagerAction", setting); + shell_action_set_enabled("SaveGraphAction", + setting ? shell->view_type == + SHELL_VIEW_PROGRESS : FALSE); } void shell_status_set_enabled(gboolean setting) @@ -264,7 +267,7 @@ void shell_status_set_enabled(gboolean setting) else { gtk_widget_hide(shell->progress); shell_view_set_enabled(TRUE); - + shell_status_update("Done."); } } @@ -279,7 +282,7 @@ void shell_do_reload(void) shell_action_set_enabled("ReportAction", FALSE); shell_status_set_enabled(TRUE); - + module_entry_reload(shell->selected); module_selected(NULL); @@ -305,7 +308,7 @@ static void destroy_me(void) cb_quit(); } -static void close_note(GtkWidget *widget, gpointer user_data) +static void close_note(GtkWidget * widget, gpointer user_data) { gtk_widget_hide(shell->note->frame); } @@ -314,29 +317,30 @@ static ShellNote *note_new(void) { ShellNote *note; GtkWidget *hbox, *icon, *button; - + note = g_new0(ShellNote, 1); note->label = gtk_label_new(""); note->frame = gtk_frame_new(NULL); button = gtk_button_new(); - + icon = icon_cache_get_image("close.png"); gtk_widget_show(icon); gtk_container_add(GTK_CONTAINER(button), icon); gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); - g_signal_connect(G_OBJECT(button), "clicked", (GCallback) close_note, NULL); - + g_signal_connect(G_OBJECT(button), "clicked", (GCallback) close_note, + NULL); + hbox = gtk_hbox_new(FALSE, 3); icon = icon_cache_get_image("dialog-information.png"); - + gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), note->label, FALSE, FALSE, 0); gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); - + gtk_container_set_border_width(GTK_CONTAINER(hbox), 5); gtk_container_add(GTK_CONTAINER(note->frame), hbox); gtk_widget_show_all(hbox); - + return note; } @@ -365,14 +369,14 @@ static void create_window(void) gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 3); shell->progress = gtk_progress_bar_new(); - gtk_widget_set_size_request(shell->progress, 70, 10); + gtk_widget_set_size_request(shell->progress, 80, 10); gtk_widget_hide(shell->progress); - gtk_box_pack_end(GTK_BOX(hbox), shell->progress, FALSE, FALSE, 0); + gtk_box_pack_end(GTK_BOX(hbox), shell->progress, FALSE, FALSE, 5); shell->status = gtk_label_new(""); gtk_misc_set_alignment(GTK_MISC(shell->status), 0.0, 0.5); gtk_widget_show(shell->status); - gtk_box_pack_start(GTK_BOX(hbox), shell->status, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(hbox), shell->status, FALSE, FALSE, 5); shell->hpaned = gtk_hpaned_new(); gtk_widget_show(shell->hpaned); @@ -382,17 +386,17 @@ static void create_window(void) vbox = gtk_vbox_new(FALSE, 5); gtk_widget_show(vbox); gtk_paned_add2(GTK_PANED(shell->hpaned), vbox); - + shell->note = note_new(); gtk_box_pack_end(GTK_BOX(vbox), shell->note->frame, FALSE, FALSE, 0); shell->vpaned = gtk_vpaned_new(); gtk_box_pack_start(GTK_BOX(vbox), shell->vpaned, TRUE, TRUE, 0); gtk_widget_show(shell->vpaned); - + shell->notebook = gtk_notebook_new(); gtk_paned_add2(GTK_PANED(shell->vpaned), shell->notebook); - + gtk_widget_show(shell->window); while (gtk_events_pending()) gtk_main_iteration(); @@ -419,20 +423,20 @@ static void add_module_to_menu(gchar * name, GdkPixbuf * pixbuf) GtkActionEntry entries[] = { { - name, /* name */ - name, /* stockid */ - name, /* label */ - NULL, /* accelerator */ - NULL, /* tooltip */ - NULL, /* callback */ + name, /* name */ + name, /* stockid */ + name, /* label */ + NULL, /* accelerator */ + NULL, /* tooltip */ + NULL, /* callback */ }, - { - about_module, - name, - name, - NULL, - name, - (GCallback) cb_about_module, + { + about_module, + name, + name, + NULL, + name, + (GCallback) cb_about_module, }, }; @@ -442,11 +446,12 @@ static void add_module_to_menu(gchar * name, GdkPixbuf * pixbuf) gtk_ui_manager_new_merge_id(shell->ui_manager), "/menubar/ViewMenu/LastSep", name, name, GTK_UI_MANAGER_MENU, TRUE); - + gtk_ui_manager_add_ui(shell->ui_manager, gtk_ui_manager_new_merge_id(shell->ui_manager), "/menubar/HelpMenu/HelpMenuModules/LastSep", - about_module, about_module, GTK_UI_MANAGER_AUTO, TRUE); + about_module, about_module, GTK_UI_MANAGER_AUTO, + TRUE); } static void @@ -457,12 +462,12 @@ add_module_entry_to_view_menu(gchar * module, gchar * name, GtkActionEntry entries[] = { { - name, /* name */ - name, /* stockid */ - name, /* label */ - NULL, /* accelerator */ - NULL, /* tooltip */ - (GCallback) view_menu_select_entry, /* callback */ + name, /* name */ + name, /* stockid */ + name, /* label */ + NULL, /* accelerator */ + NULL, /* tooltip */ + (GCallback) view_menu_select_entry, /* callback */ }, }; @@ -582,39 +587,39 @@ static gboolean update_field(gpointer data) { ShellFieldUpdate *fu = (ShellFieldUpdate *) data; GtkTreeIter *iter = g_hash_table_lookup(update_tbl, fu->field_name); - + /* if the entry is still selected, update it */ if (iter && fu->entry->selected && fu->entry->fieldfunc) { - GtkTreeStore *store = GTK_TREE_STORE(shell->info->model); - gchar *value = fu->entry->fieldfunc(fu->field_name); - - /* - * this function is also used to feed the load graph when ViewType - * is SHELL_VIEW_LOAD_GRAPH - */ - if (shell->view_type == SHELL_VIEW_LOAD_GRAPH && - gtk_tree_selection_iter_is_selected(shell->info->selection, - iter)) { - load_graph_update(shell->loadgraph, atoi(value)); - } - - gtk_tree_store_set(store, iter, INFO_TREE_COL_VALUE, value, -1); - - g_free(value); - return TRUE; + GtkTreeStore *store = GTK_TREE_STORE(shell->info->model); + gchar *value = fu->entry->fieldfunc(fu->field_name); + + /* + * this function is also used to feed the load graph when ViewType + * is SHELL_VIEW_LOAD_GRAPH + */ + if (shell->view_type == SHELL_VIEW_LOAD_GRAPH && + gtk_tree_selection_iter_is_selected(shell->info->selection, + iter)) { + load_graph_update(shell->loadgraph, atoi(value)); + } + + gtk_tree_store_set(store, iter, INFO_TREE_COL_VALUE, value, -1); + + g_free(value); + return TRUE; } - + if (update_sfusrc) { - GSList *sfu; - - for (sfu = update_sfusrc; sfu; sfu = sfu->next) { - g_free(sfu->data); - } - - g_slist_free(update_sfusrc); - update_sfusrc = NULL; + GSList *sfu; + + for (sfu = update_sfusrc; sfu; sfu = sfu->next) { + g_free(sfu->data); + } + + g_slist_free(update_sfusrc); + update_sfusrc = NULL; } - + DEBUG("destroying ShellFieldUpdate for field %s", fu->field_name); /* otherwise, cleanup and destroy the timeout */ @@ -665,9 +670,8 @@ static gboolean rescan_section(gpointer data) gint info_tree_compare_val_func(GtkTreeModel * model, - GtkTreeIter * a, - GtkTreeIter * b, - gpointer userdata) + GtkTreeIter * a, + GtkTreeIter * b, gpointer userdata) { gint ret = 0; gchar *col1, *col2; @@ -682,7 +686,7 @@ info_tree_compare_val_func(GtkTreeModel * model, ret = (col1 == NULL) ? -1 : 1; } else { ret = shell->_order_type ? (atof(col1) < atof(col2)) : - (atof(col1) > atof(col2)); + (atof(col1) > atof(col2)); } g_free(col1); @@ -695,7 +699,7 @@ static void set_view_type(ShellViewType viewtype) { /* reset to the default model */ gtk_tree_view_set_model(GTK_TREE_VIEW(shell->info->view), - shell->info->model); + shell->info->model); /* reset to the default view columns */ gtk_tree_view_column_set_visible(shell->info->col_progress, FALSE); @@ -709,10 +713,10 @@ static void set_view_type(ShellViewType viewtype) if (viewtype == shell->view_type) return; - + if (viewtype < SHELL_VIEW_NORMAL || viewtype >= SHELL_VIEW_N_VIEWS) - viewtype = SHELL_VIEW_NORMAL; - + viewtype = SHELL_VIEW_NORMAL; + shell->view_type = viewtype; switch (viewtype) { @@ -734,7 +738,7 @@ static void set_view_type(ShellViewType viewtype) shell->loadgraph->height - 16); break; case SHELL_VIEW_PROGRESS: - shell_action_set_enabled("SaveGraphAction", TRUE); + shell_action_set_enabled("SaveGraphAction", TRUE); gtk_tree_view_column_set_visible(shell->info->col_progress, TRUE); gtk_tree_view_column_set_visible(shell->info->col_value, FALSE); gtk_widget_hide(shell->notebook); @@ -753,8 +757,8 @@ group_handle_special(GKeyFile * key_file, ShellModuleEntry * entry, gchar *key = keys[i]; if (g_str_has_prefix(key, "UpdateInterval")) { - ShellFieldUpdate *fu = g_new0(ShellFieldUpdate, 1); - ShellFieldUpdateSource *sfutbl; + ShellFieldUpdate *fu = g_new0(ShellFieldUpdate, 1); + ShellFieldUpdateSource *sfutbl; gint ms; ms = g_key_file_get_integer(key_file, group, key, NULL); @@ -762,13 +766,14 @@ group_handle_special(GKeyFile * key_file, ShellModuleEntry * entry, fu->field_name = g_strdup(strchr(key, '$') + 1); fu->entry = entry; - sfutbl = g_new0(ShellFieldUpdateSource, 1); - sfutbl->source_id = g_timeout_add(ms, update_field, fu); - sfutbl->sfu = fu; - + sfutbl = g_new0(ShellFieldUpdateSource, 1); + sfutbl->source_id = g_timeout_add(ms, update_field, fu); + sfutbl->sfu = fu; + update_sfusrc = g_slist_prepend(update_sfusrc, sfutbl); } else if (g_str_equal(key, "LoadGraphSuffix")) { - gchar *suffix = g_key_file_get_value(key_file, group, key, NULL); + gchar *suffix = + g_key_file_get_value(key_file, group, key, NULL); load_graph_set_data_suffix(shell->loadgraph, suffix); g_free(suffix); } else if (g_str_equal(key, "ReloadInterval")) { @@ -785,8 +790,8 @@ group_handle_special(GKeyFile * key_file, ShellModuleEntry * entry, g_timeout_add(ms, rescan_section, entry); } else if (g_str_equal(key, "OrderType")) { shell->_order_type = g_key_file_get_integer(key_file, - group, - key, NULL); + group, + key, NULL); } else if (g_str_equal(key, "ViewType")) { set_view_type(g_key_file_get_integer(key_file, group, key, NULL)); @@ -814,7 +819,7 @@ group_handle_special(GKeyFile * key_file, ShellModuleEntry * entry, } } } else { - g_warning("Unknown parameter group '%s'", group); + g_warning("Unknown parameter group: ``%s''", group); } } @@ -841,19 +846,21 @@ group_handle_normal(GKeyFile * key_file, ShellModuleEntry * entry, GtkTreeIter child; value = g_key_file_get_value(key_file, group, key, NULL); - if (g_str_equal(value, "...") && entry->fieldfunc) { + if (entry->fieldfunc && value && g_str_equal(value, "...")) { g_free(value); value = entry->fieldfunc(key); } - if (g_utf8_validate(key, -1, NULL) + if ((key && value) && + g_utf8_validate(key, -1, NULL) && g_utf8_validate(value, -1, NULL)) { if (ngroups == 1) { gtk_tree_store_append(store, &child, NULL); } else { gtk_tree_store_append(store, &child, &parent); } - gtk_tree_store_set(store, &child, INFO_TREE_COL_VALUE, value, -1); + gtk_tree_store_set(store, &child, INFO_TREE_COL_VALUE, value, + -1); strend(key, '#'); @@ -922,7 +929,7 @@ static void update_progress() gdouble maxv = 0, maxp = 0, cur; gtk_tree_model_get_iter_first(model, &fiter); - + /* finds the maximum value */ iter = fiter; do { @@ -936,27 +943,28 @@ static void update_progress() /* calculates the relative percentage and finds the maximum percentage */ if (shell->_order_type == SHELL_ORDER_ASCENDING) { - iter = fiter; - do { - gtk_tree_model_get(model, &iter, INFO_TREE_COL_VALUE, &tmp, -1); + iter = fiter; + do { + gtk_tree_model_get(model, &iter, INFO_TREE_COL_VALUE, &tmp, + -1); - cur = 100 - 100 * atof(tmp) / maxv; - maxp = MAX(cur, maxp); + cur = 100 - 100 * atof(tmp) / maxv; + maxp = MAX(cur, maxp); - g_free(tmp); - } while (gtk_tree_model_iter_next(model, &iter)); + g_free(tmp); + } while (gtk_tree_model_iter_next(model, &iter)); - maxp = 100 - maxp; + maxp = 100 - maxp; } - + /* fix the maximum relative percentage */ iter = fiter; do { gtk_tree_model_get(model, &iter, INFO_TREE_COL_VALUE, &tmp, -1); - cur = 100 * atof(tmp) / maxv; - if (shell->_order_type == SHELL_ORDER_ASCENDING) - cur = 100 - cur + maxp; + cur = 100 * atof(tmp) / maxv; + if (shell->_order_type == SHELL_ORDER_ASCENDING) + cur = 100 - cur + maxp; gtk_tree_store_set(store, &iter, INFO_TREE_COL_PROGRESS, cur, -1); g_free(tmp); @@ -966,27 +974,27 @@ static void update_progress() GtkTreeSortable *sortable = GTK_TREE_SORTABLE(shell->info->model); gtk_tree_sortable_set_sort_func(sortable, INFO_TREE_COL_VALUE, - info_tree_compare_val_func, 0, NULL); + info_tree_compare_val_func, 0, NULL); gtk_tree_sortable_set_sort_column_id(sortable, - INFO_TREE_COL_VALUE, - GTK_SORT_DESCENDING); + INFO_TREE_COL_VALUE, + GTK_SORT_DESCENDING); gtk_tree_view_set_model(GTK_TREE_VIEW(shell->info->view), - GTK_TREE_MODEL(sortable)); + GTK_TREE_MODEL(sortable)); } -void shell_set_note_from_entry(ShellModuleEntry *entry) +void shell_set_note_from_entry(ShellModuleEntry * entry) { if (entry->notefunc) { - const gchar *note = module_entry_get_note(entry); - - if (note) { - gtk_label_set_markup(GTK_LABEL(shell->note->label), note); - gtk_widget_show(shell->note->frame); - } else { - gtk_widget_hide(shell->note->frame); - } + const gchar *note = module_entry_get_note(entry); + + if (note) { + gtk_label_set_markup(GTK_LABEL(shell->note->label), note); + gtk_widget_show(shell->note->frame); + } else { + gtk_widget_hide(shell->note->frame); + } } else { - gtk_widget_hide(shell->note->frame); + gtk_widget_hide(shell->note->frame); } } @@ -1008,28 +1016,31 @@ module_selected_show_info(ShellModuleEntry * entry, gboolean reload) /* recreate the iter hash table */ if (!reload) { - if (update_tbl) { - g_hash_table_foreach_remove(update_tbl, (GHRFunc) gtk_true, NULL); - } else { - update_tbl = - g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - } + if (update_tbl) { + g_hash_table_foreach_remove(update_tbl, (GHRFunc) gtk_true, + NULL); + } else { + update_tbl = + g_hash_table_new_full(g_str_hash, g_str_equal, g_free, + g_free); + } } - + if (update_sfusrc) { - GSList *sfusrc; - - for (sfusrc = update_sfusrc; sfusrc; sfusrc = sfusrc->next) { - ShellFieldUpdateSource *src = (ShellFieldUpdateSource *)sfusrc->data; - - g_source_remove(src->source_id); - g_free(src->sfu->field_name); - g_free(src->sfu); - g_free(src); - } - - g_slist_free(update_sfusrc); - update_sfusrc = NULL; + GSList *sfusrc; + + for (sfusrc = update_sfusrc; sfusrc; sfusrc = sfusrc->next) { + ShellFieldUpdateSource *src = + (ShellFieldUpdateSource *) sfusrc->data; + + g_source_remove(src->source_id); + g_free(src->sfu->field_name); + g_free(src->sfu); + g_free(src); + } + + g_slist_free(update_sfusrc); + update_sfusrc = NULL; } store = GTK_TREE_STORE(shell->info->model); @@ -1038,9 +1049,10 @@ module_selected_show_info(ShellModuleEntry * entry, gboolean reload) g_key_file_load_from_data(key_file, key_data, strlen(key_data), 0, NULL); groups = g_key_file_get_groups(key_file, &ngroups); - + for (i = 0; groups[i]; i++) - if (groups[i][0] == '$') ngroups--; + if (groups[i][0] == '$') + ngroups--; for (i = 0; groups[i]; i++) { gchar *group = groups[i]; @@ -1051,7 +1063,7 @@ module_selected_show_info(ShellModuleEntry * entry, gboolean reload) } else { group_handle_normal(key_file, entry, group, keys, ngroups); } - + g_strfreev(keys); } @@ -1060,7 +1072,7 @@ module_selected_show_info(ShellModuleEntry * entry, gboolean reload) if (shell->view_type == SHELL_VIEW_PROGRESS) { update_progress(); } - + shell_set_note_from_entry(entry); g_strfreev(groups); @@ -1120,7 +1132,8 @@ static void module_selected(gpointer data) /* Gets the currently selected item on the left-side TreeView; if there is no selection, silently return */ - if (!gtk_tree_selection_get_selected(shelltree->selection, &model, &parent)) + if (!gtk_tree_selection_get_selected + (shelltree->selection, &model, &parent)) return; /* Mark the currently selected module as "unselected"; this is used to kill the @@ -1131,6 +1144,8 @@ static void module_selected(gpointer data) /* Get the current selection and shows its related info */ gtk_tree_model_get(model, &parent, TREE_COL_DATA, &entry, -1); if (entry && !entry->selected) { + gchar *title; + shell_status_set_enabled(TRUE); shell_status_update("Updating..."); @@ -1158,8 +1173,9 @@ static void module_selected(gpointer data) shell_status_update("Done."); shell_status_set_enabled(FALSE); - gtk_window_set_title(GTK_WINDOW(shell->window), - idle_free(g_strdup_printf("%s - System Information", entry->name))); + title = g_strdup_printf("%s - System Information", entry->name); + gtk_window_set_title(GTK_WINDOW(shell->window), title); + g_free(title); shell_action_set_enabled("RefreshAction", TRUE); shell_action_set_enabled("CopyAction", TRUE); @@ -1255,7 +1271,7 @@ static ShellInfoTree *info_tree_new(gboolean extra) if (!extra) g_signal_connect(G_OBJECT(sel), "changed", (GCallback) info_selected, info); - + gtk_container_add(GTK_CONTAINER(scroll), treeview); info->scroll = scroll; @@ -43,7 +43,9 @@ Socket *sock_connect(gchar * host, gint port) server.sin_addr.s_addr = inet_addr(host); server.sin_port = htons(port); - if (connect(sock, (struct sockaddr *) (void *) &server, sizeof(server)) < 0) { + if (connect + (sock, (struct sockaddr *) (void *) &server, + sizeof(server)) < 0) { return NULL; } @@ -25,17 +25,17 @@ static struct { gchar *filename; gchar *stock_id; } stock_icons[] = { - { "report.png", HI_STOCK_REPORT }, - { "internet.png", HI_STOCK_INTERNET }, - { "module.png", HI_STOCK_MODULE }, - { "about-modules.png", HI_STOCK_ABOUT_MODULES }, - { "syncmanager-small.png", HI_STOCK_SYNC_MENU }, - { "face-grin.png", HI_STOCK_DONATE }, -}; + { + "report.png", HI_STOCK_REPORT}, { + "internet.png", HI_STOCK_INTERNET}, { + "module.png", HI_STOCK_MODULE}, { + "about-modules.png", HI_STOCK_ABOUT_MODULES}, { + "syncmanager-small.png", HI_STOCK_SYNC_MENU}, { +"face-grin.png", HI_STOCK_DONATE},}; static GtkIconFactory *icon_factory; -void stock_icon_register(gchar *filename, gchar *stock_id) +void stock_icon_register(gchar * filename, gchar * stock_id) { GtkIconSet *icon_set; GtkIconSource *icon_source; @@ -43,7 +43,8 @@ void stock_icon_register(gchar *filename, gchar *stock_id) icon_set = gtk_icon_set_new(); icon_source = gtk_icon_source_new(); - gtk_icon_source_set_pixbuf(icon_source, icon_cache_get_pixbuf(filename)); + gtk_icon_source_set_pixbuf(icon_source, + icon_cache_get_pixbuf(filename)); gtk_icon_set_add_source(icon_set, icon_source); gtk_icon_source_free(icon_source); @@ -52,7 +53,7 @@ void stock_icon_register(gchar *filename, gchar *stock_id) gtk_icon_set_unref(icon_set); } -void stock_icon_register_pixbuf(GdkPixbuf *pixbuf, gchar *stock_id) +void stock_icon_register_pixbuf(GdkPixbuf * pixbuf, gchar * stock_id) { GtkIconSet *icon_set; GtkIconSource *icon_source; @@ -79,7 +80,8 @@ void stock_icons_init(void) icon_factory = gtk_icon_factory_new(); for (i = 0; i < n_stock_icons; i++) { - stock_icon_register(stock_icons[i].filename, stock_icons[i].stock_id); + stock_icon_register(stock_icons[i].filename, + stock_icons[i].stock_id); } gtk_icon_factory_add_default(icon_factory); diff --git a/syncmanager.c b/syncmanager.c index 7646990f..599804eb 100644 --- a/syncmanager.c +++ b/syncmanager.c @@ -21,6 +21,7 @@ #include "hardinfo.h" #include "config.h" +#ifdef HAS_LIBSOUP #include <libsoup/soup.h> #include <libsoup/soup-xmlrpc-message.h> #include <libsoup/soup-xmlrpc-response.h> @@ -28,41 +29,41 @@ #include <stdarg.h> #include <string.h> -typedef struct _SyncDialog SyncDialog; -typedef struct _SyncNetArea SyncNetArea; -typedef struct _SyncNetAction SyncNetAction; +typedef struct _SyncDialog SyncDialog; +typedef struct _SyncNetArea SyncNetArea; +typedef struct _SyncNetAction SyncNetAction; struct _SyncNetArea { GtkWidget *vbox; }; struct _SyncNetAction { - gchar *name; - gboolean (*do_action)(SyncDialog *sd, gpointer sna); - - SyncEntry *entry; - GError *error; + gchar *name; + gboolean(*do_action) (SyncDialog * sd, gpointer sna); + + SyncEntry *entry; + GError *error; }; struct _SyncDialog { - GtkWidget *dialog; - GtkWidget *label; - - GtkWidget *button_sync; - GtkWidget *button_cancel; - GtkWidget *button_close; - - GtkWidget *scroll_box; - - SyncNetArea *sna; - - gboolean flag_cancel : 1; + GtkWidget *dialog; + GtkWidget *label; + + GtkWidget *button_sync; + GtkWidget *button_cancel; + GtkWidget *button_close; + + GtkWidget *scroll_box; + + SyncNetArea *sna; + + gboolean flag_cancel:1; }; -static GSList *entries = NULL; -static SoupSession *session = NULL; -static GMainLoop *loop; -static GQuark err_quark; +static GSList *entries = NULL; +static SoupSession *session = NULL; +static GMainLoop *loop; +static GQuark err_quark; #define XMLRPC_SERVER_URI "http://hardinfo.berlios.de/xmlrpc/" #define XMLRPC_SERVER_API_VERSION 1 @@ -73,307 +74,328 @@ static GQuark err_quark; #define LABEL_SYNC_SYNCING "<big><b>Synchronizing</b></big>\n" \ "This may take some time." -static SyncDialog *sync_dialog_new(void); -static void sync_dialog_destroy(SyncDialog *sd); -static void sync_dialog_start_sync(SyncDialog *sd); +static SyncDialog *sync_dialog_new(void); +static void sync_dialog_destroy(SyncDialog * sd); +static void sync_dialog_start_sync(SyncDialog * sd); -static SyncNetArea *sync_dialog_netarea_new(void); -static void sync_dialog_netarea_destroy(SyncNetArea *sna); -static void sync_dialog_netarea_show(SyncDialog *sd); +static SyncNetArea *sync_dialog_netarea_new(void); +static void sync_dialog_netarea_destroy(SyncNetArea * sna); +static void sync_dialog_netarea_show(SyncDialog * sd); #if 0 -static void sync_dialog_netarea_hide(SyncDialog *sd); +static void sync_dialog_netarea_hide(SyncDialog * sd); #endif -static void sync_dialog_netarea_start_actions(SyncDialog *sd, SyncNetAction *sna, - gint n); +static void sync_dialog_netarea_start_actions(SyncDialog * sd, + SyncNetAction * sna, gint n); #define SNA_ERROR(code,message,...) if (!sna->error) { \ sna->error = g_error_new(err_quark, code, message, \ ##__VA_ARGS__); \ } +#endif /* HAS_LIBSOUP */ -void sync_manager_add_entry(SyncEntry *entry) +void sync_manager_add_entry(SyncEntry * entry) { +#ifdef HAS_LIBSOUP DEBUG("registering syncmanager entry ''%s''", entry->fancy_name); entry->selected = TRUE; entries = g_slist_prepend(entries, entry); +#else + DEBUG("libsoup support is disabled."); +#endif /* HAS_LIBSOUP */ } void sync_manager_show(void) { +#ifndef HAS_LIBSOUP + g_warning + ("HardInfo was compiled without libsoup support. (Network Manager requires it.)"); +#else /* !HAS_LIBSOUP */ SyncDialog *sd = sync_dialog_new(); - + err_quark = g_quark_from_static_string("syncmanager"); if (gtk_dialog_run(GTK_DIALOG(sd->dialog)) == GTK_RESPONSE_ACCEPT) { - shell_view_set_enabled(FALSE); - shell_status_set_enabled(TRUE); - - sync_dialog_start_sync(sd); - - shell_status_set_enabled(FALSE); - shell_view_set_enabled(TRUE); - } + shell_view_set_enabled(FALSE); + shell_status_set_enabled(TRUE); + + sync_dialog_start_sync(sd); + + shell_status_set_enabled(FALSE); + shell_view_set_enabled(TRUE); + } sync_dialog_destroy(sd); +#endif /* HAS_LIBSOUP */ } -static SoupXmlrpcValue *_soup_get_xmlrpc_value(SoupMessage *msg, SyncNetAction *sna) +#ifdef HAS_LIBSOUP +static SoupXmlrpcValue *_soup_get_xmlrpc_value(SoupMessage * msg, + SyncNetAction * sna) { SoupXmlrpcResponse *response = NULL; SoupXmlrpcValue *value = NULL; - + sna->error = NULL; - + if (!SOUP_STATUS_IS_SUCCESSFUL(msg->status_code)) { - SNA_ERROR(1, "%s (error #%d)", msg->reason_phrase, msg->status_code); - goto bad; + SNA_ERROR(1, "%s (error #%d)", msg->reason_phrase, + msg->status_code); + goto bad; } - response = soup_xmlrpc_message_parse_response(SOUP_XMLRPC_MESSAGE(msg)); + response = + soup_xmlrpc_message_parse_response(SOUP_XMLRPC_MESSAGE(msg)); if (!response) { - SNA_ERROR(2, "Could not parse XML-RPC response"); - goto bad; + SNA_ERROR(2, "Could not parse XML-RPC response"); + goto bad; } - + value = soup_xmlrpc_response_get_value(response); if (!value) { - SNA_ERROR(3, "No response value in XML-RPC response"); + SNA_ERROR(3, "No response value in XML-RPC response"); } - - /* g_object_unref(response); */ -bad: + + /*g_object_unref(response); */ + bad: return value; } -static long _soup_get_xmlrpc_value_int(SoupMessage *msg, SyncNetAction *sna) +static long _soup_get_xmlrpc_value_int(SoupMessage * msg, + SyncNetAction * sna) { SoupXmlrpcValue *value; long int_value = -1; - + value = _soup_get_xmlrpc_value(msg, sna); if (!value) { - SNA_ERROR(4, "Could not extract result from XML-RPC response"); - goto bad; + SNA_ERROR(4, "Could not extract result from XML-RPC response"); + goto bad; } if (!soup_xmlrpc_value_get_int(value, &int_value)) { - SNA_ERROR(4, "Could not extract result from XML-RPC response"); + SNA_ERROR(4, "Could not extract result from XML-RPC response"); } -bad: + bad: return int_value; } -static gchar* _soup_get_xmlrpc_value_string(SoupMessage *msg, SyncNetAction *sna) +static gchar *_soup_get_xmlrpc_value_string(SoupMessage * msg, + SyncNetAction * sna) { SoupXmlrpcValue *value; gchar *string = NULL; - + value = _soup_get_xmlrpc_value(msg, sna); if (!value) { - SNA_ERROR(4, "Could not extract result from XML-RPC response"); - goto bad; + SNA_ERROR(4, "Could not extract result from XML-RPC response"); + goto bad; } if (!soup_xmlrpc_value_get_string(value, &string)) { - SNA_ERROR(4, "Could not extract result from XML-RPC response"); + SNA_ERROR(4, "Could not extract result from XML-RPC response"); } -bad: + bad: return string; } -static gboolean _soup_xmlrpc_call(gchar *method, SyncNetAction *sna, - SoupMessageCallbackFn callback) +static gboolean _soup_xmlrpc_call(gchar * method, SyncNetAction * sna, + SoupMessageCallbackFn callback) { SoupXmlrpcMessage *msg; - + sna->error = NULL; - + msg = soup_xmlrpc_message_new(XMLRPC_SERVER_URI); if (!msg) - return FALSE; - + return FALSE; + DEBUG("calling xmlrpc method %s", method); soup_xmlrpc_message_start_call(msg, method); soup_xmlrpc_message_end_call(msg); - + soup_xmlrpc_message_persist(msg); - - soup_session_queue_message(session, SOUP_MESSAGE(msg), - callback, sna); + + soup_session_queue_message(session, SOUP_MESSAGE(msg), callback, sna); g_main_run(loop); - + return TRUE; } -static gboolean _soup_xmlrpc_call_with_parameters(gchar *method, SyncNetAction *sna, - SoupMessageCallbackFn callback, - ...) +static gboolean _soup_xmlrpc_call_with_parameters(gchar * method, + SyncNetAction * sna, + SoupMessageCallbackFn + callback, ...) { SoupXmlrpcMessage *msg; gchar *argument; va_list ap; - + sna->error = NULL; - + msg = soup_xmlrpc_message_new(XMLRPC_SERVER_URI); if (!msg) - return FALSE; - + return FALSE; + DEBUG("calling xmlrpc method %s", method); soup_xmlrpc_message_start_call(msg, method); - + va_start(ap, callback); while ((argument = va_arg(ap, gchar *))) { - soup_xmlrpc_message_start_param(msg); - soup_xmlrpc_message_write_string(msg, argument); - soup_xmlrpc_message_end_param(msg); - - DEBUG("with parameter: %s", argument); + soup_xmlrpc_message_start_param(msg); + soup_xmlrpc_message_write_string(msg, argument); + soup_xmlrpc_message_end_param(msg); + + DEBUG("with parameter: %s", argument); } va_end(ap); - + soup_xmlrpc_message_end_call(msg); soup_xmlrpc_message_persist(msg); - + soup_session_queue_message(session, SOUP_MESSAGE(msg), callback, sna); g_main_run(loop); - + return TRUE; } -static void _action_check_api_version_got_response(SoupMessage *msg, gpointer user_data) +static void _action_check_api_version_got_response(SoupMessage * msg, + gpointer user_data) { SyncNetAction *sna = (SyncNetAction *) user_data; long version = _soup_get_xmlrpc_value_int(msg, sna); - + if (version != XMLRPC_SERVER_API_VERSION) { - SNA_ERROR(5, "Server says it supports API version %ld, but " \ - "this version of HardInfo only supports API " \ - "version %d.", version, XMLRPC_SERVER_API_VERSION); + SNA_ERROR(5, "Server says it supports API version %ld, but " + "this version of HardInfo only supports API " + "version %d.", version, XMLRPC_SERVER_API_VERSION); } g_main_quit(loop); } -static gboolean _action_check_api_version(SyncDialog *sd, gpointer user_data) +static gboolean _action_check_api_version(SyncDialog * sd, + gpointer user_data) { SyncNetAction *sna = (SyncNetAction *) user_data; if (!_soup_xmlrpc_call("server.getAPIVersion", sna, - _action_check_api_version_got_response)) - return FALSE; - + _action_check_api_version_got_response)) + return FALSE; + return sna->error ? FALSE : TRUE; } -static void _action_call_function_got_response(SoupMessage *msg, gpointer user_data) +static void _action_call_function_got_response(SoupMessage * msg, + gpointer user_data) { SyncNetAction *sna = (SyncNetAction *) user_data; gchar *string; - - string = _soup_get_xmlrpc_value_string(msg, sna); - DEBUG("received string: %s\n", string); - - if (sna->entry->save_to) { - gchar *filename = g_build_filename(g_get_home_dir(), ".hardinfo", - sna->entry->save_to, NULL); - - DEBUG("saving to %s", filename); + + if ((string = _soup_get_xmlrpc_value_string(msg, sna)) && + sna->entry->save_to) { + DEBUG("received string: %s\n", string); + gchar *filename = g_build_filename(g_get_home_dir(), ".hardinfo", + sna->entry->save_to, NULL); + + DEBUG("saving to %s", filename); #ifdef g_file_set_contents - g_file_set_contents(filename, string, -1, NULL); + g_file_set_contents(filename, string, -1, NULL); #else - { - FILE *f; - - f = fopen(filename, "w+"); - if (f) { - fwrite(string, 1, strlen(string), f); - fclose(f); - } - } + { + FILE *f; + + f = fopen(filename, "w+"); + if (f) { + fwrite(string, 1, strlen(string), f); + fclose(f); + } + } #endif - g_free(filename); + g_free(filename); } - + if (sna->entry->callback) { - sna->entry->callback(sna->entry, string); + sna->entry->callback(sna->entry, string); } g_free(string); g_main_quit(loop); } -static gboolean _action_call_function(SyncDialog *sd, gpointer user_data) +static gboolean _action_call_function(SyncDialog * sd, gpointer user_data) { SyncNetAction *sna = (SyncNetAction *) user_data; - + if (sna->entry) { - gchar *str_data = NULL; - - if (sna->entry->get_data) - str_data = sna->entry->get_data(); - - if (!_soup_xmlrpc_call_with_parameters("sync.callFunction", sna, - _action_call_function_got_response, - VERSION, ARCH, - sna->entry->name, - str_data, NULL)) { - if (str_data) - g_free(str_data); - - return FALSE; - } - - if (str_data) - g_free(str_data); + gchar *str_data = NULL; + + if (sna->entry->get_data) + str_data = sna->entry->get_data(); + + if (!_soup_xmlrpc_call_with_parameters("sync.callFunction", sna, + _action_call_function_got_response, + VERSION, ARCH, + sna->entry->name, + str_data, NULL)) { + if (str_data) + g_free(str_data); + + return FALSE; + } + + if (str_data) + g_free(str_data); } - + return sna->error ? FALSE : TRUE; } -static gboolean _cancel_sync(GtkWidget *widget, gpointer data) +static gboolean _cancel_sync(GtkWidget * widget, gpointer data) { SyncDialog *sd = (SyncDialog *) data; - + if (session) { - soup_session_abort(session); + soup_session_abort(session); } - + sd->flag_cancel = TRUE; g_main_quit(loop); - + gtk_widget_set_sensitive(widget, FALSE); - + return FALSE; } -static SyncNetAction *sync_manager_get_selected_actions(gint *n) +static SyncNetAction *sync_manager_get_selected_actions(gint * n) { gint i; GSList *entry; SyncNetAction *actions; - SyncNetAction action_check_api = { "Contacting HardInfo Central Database", - _action_check_api_version }, - action_clean_up = { "Cleaning up", NULL }; - + SyncNetAction action_check_api = + { "Contacting HardInfo Central Database", + _action_check_api_version + }, action_clean_up = { + "Cleaning up", NULL}; + actions = g_new0(SyncNetAction, 2 + g_slist_length(entries)); - + for (entry = entries, i = 1; entry; entry = entry->next) { - SyncEntry *e = (SyncEntry *) entry->data; - - if (e->selected) { - SyncNetAction sna = { e->fancy_name, _action_call_function, e }; - - actions[i++] = sna; - } + SyncEntry *e = (SyncEntry *) entry->data; + + if (e->selected) { + SyncNetAction sna = + { e->fancy_name, _action_call_function, e }; + + actions[i++] = sna; + } } - actions[0] = action_check_api; + actions[0] = action_check_api; actions[i++] = action_clean_up; *n = i; @@ -383,137 +405,150 @@ static SyncNetAction *sync_manager_get_selected_actions(gint *n) static SoupUri *sync_manager_get_proxy(void) { const gchar *conf; - + if (!(conf = g_getenv("HTTP_PROXY"))) { - if (!(conf = g_getenv("http_proxy"))) { - return NULL; - } + if (!(conf = g_getenv("http_proxy"))) { + return NULL; + } } - + return soup_uri_new(conf); } -static void sync_dialog_start_sync(SyncDialog *sd) +static void sync_dialog_start_sync(SyncDialog * sd) { - gint nactions; + gint nactions; SyncNetAction *actions; - + if (!session) { - SoupUri *proxy = sync_manager_get_proxy(); - - session = soup_session_async_new_with_options(SOUP_SESSION_TIMEOUT, 10, - SOUP_SESSION_PROXY_URI, proxy, NULL); - /* Crashes if we unref the proxy? O_o - if (proxy) - g_object_unref(proxy); - */ + SoupUri *proxy = sync_manager_get_proxy(); + + session = + soup_session_async_new_with_options(SOUP_SESSION_TIMEOUT, 10, + SOUP_SESSION_PROXY_URI, + proxy, NULL); + /* Crashes if we unref the proxy? O_o */ + /*if (proxy) + g_object_unref(proxy); */ } - + loop = g_main_loop_new(NULL, TRUE); gtk_widget_hide(sd->button_sync); sync_dialog_netarea_show(sd); g_signal_connect(G_OBJECT(sd->button_cancel), "clicked", - (GCallback)_cancel_sync, sd); + (GCallback) _cancel_sync, sd); actions = sync_manager_get_selected_actions(&nactions); sync_dialog_netarea_start_actions(sd, actions, nactions); g_free(actions); - + if (sd->flag_cancel) { - gtk_widget_hide(sd->button_cancel); - gtk_widget_show(sd->button_close); + gtk_widget_hide(sd->button_cancel); + gtk_widget_show(sd->button_close); - /* wait for the user to close the dialog */ - g_main_run(loop); + /* wait for the user to close the dialog */ + g_main_run(loop); } - + g_main_loop_unref(loop); } -static void sync_dialog_netarea_start_actions(SyncDialog *sd, SyncNetAction sna[], gint n) +static void sync_dialog_netarea_start_actions(SyncDialog * sd, + SyncNetAction sna[], gint n) { gint i; GtkWidget **labels; GtkWidget **icons; GdkPixbuf *done_icon = icon_cache_get_pixbuf("status-done.png"); GdkPixbuf *curr_icon = icon_cache_get_pixbuf("status-curr.png"); - + labels = g_new0(GtkWidget *, n); - icons = g_new0(GtkWidget *, n); - + icons = g_new0(GtkWidget *, n); + for (i = 0; i < n; i++) { - GtkWidget *hbox; - - hbox = gtk_hbox_new(FALSE, 5); - - labels[i] = gtk_label_new(sna[i].name); - icons[i] = gtk_image_new(); - - gtk_widget_set_size_request(icons[i], - gdk_pixbuf_get_width(done_icon), - gdk_pixbuf_get_height(done_icon)); - - gtk_label_set_use_markup(GTK_LABEL(labels[i]), TRUE); - gtk_misc_set_alignment(GTK_MISC(labels[i]), 0.0, 0.5); - - gtk_box_pack_start(GTK_BOX(hbox), icons[i], FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(hbox), labels[i], TRUE, TRUE, 0); - gtk_box_pack_start(GTK_BOX(sd->sna->vbox), hbox, FALSE, FALSE, 3); - - gtk_widget_show_all(hbox); + GtkWidget *hbox; + + hbox = gtk_hbox_new(FALSE, 5); + + labels[i] = gtk_label_new(sna[i].name); + icons[i] = gtk_image_new(); + + gtk_widget_set_size_request(icons[i], + gdk_pixbuf_get_width(done_icon), + gdk_pixbuf_get_height(done_icon)); + + gtk_label_set_use_markup(GTK_LABEL(labels[i]), TRUE); + gtk_misc_set_alignment(GTK_MISC(labels[i]), 0.0, 0.5); + + gtk_box_pack_start(GTK_BOX(hbox), icons[i], FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(hbox), labels[i], TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(sd->sna->vbox), hbox, FALSE, FALSE, 3); + + gtk_widget_show_all(hbox); } - + while (gtk_events_pending()) - gtk_main_iteration(); - + gtk_main_iteration(); + for (i = 0; i < n; i++) { - gchar *markup; - - if (sd->flag_cancel) { - markup = g_strdup_printf("<s>%s</s> <i>(canceled)</i>", sna[i].name); - gtk_label_set_markup(GTK_LABEL(labels[i]), markup); - g_free(markup); - - gtk_image_set_from_pixbuf(GTK_IMAGE(icons[i]), - icon_cache_get_pixbuf("dialog-error.png")); - break; - } - - markup = g_strdup_printf("<b>%s</b>", sna[i].name); - gtk_label_set_markup(GTK_LABEL(labels[i]), markup); - g_free(markup); - - gtk_image_set_from_pixbuf(GTK_IMAGE(icons[i]), curr_icon); - - if (sna[i].do_action && !sna[i].do_action(sd, &sna[i])) { - markup = g_strdup_printf("<b><s>%s</s></b> <i>(failed)</i>", sna[i].name); - gtk_label_set_markup(GTK_LABEL(labels[i]), markup); - g_free(markup); - - sd->flag_cancel = TRUE; - - gtk_image_set_from_pixbuf(GTK_IMAGE(icons[i]), - icon_cache_get_pixbuf("dialog-error.png")); - if (sna[i].error) { - g_warning("Failed while performing \"%s\". Please file a bug report " \ - "if this problem persists. (Use the Help\342\206\222Report" \ - " bug option.)\n\nDetails: %s", - sna[i].name, sna[i].error->message); - - g_error_free(sna[i].error); - } else { - g_warning("Failed while performing \"%s\". Please file a bug report " \ - "if this problem persists. (Use the Help\342\206\222Report" \ - " bug option.)", sna[i].name); - } - break; - } - - gtk_image_set_from_pixbuf(GTK_IMAGE(icons[i]), done_icon); - gtk_label_set_markup(GTK_LABEL(labels[i]), sna[i].name); + gchar *markup; + + if (sd->flag_cancel) { + markup = + g_strdup_printf("<s>%s</s> <i>(canceled)</i>", + sna[i].name); + gtk_label_set_markup(GTK_LABEL(labels[i]), markup); + g_free(markup); + + gtk_image_set_from_pixbuf(GTK_IMAGE(icons[i]), + icon_cache_get_pixbuf + ("dialog-error.png")); + break; + } + + markup = g_strdup_printf("<b>%s</b>", sna[i].name); + gtk_label_set_markup(GTK_LABEL(labels[i]), markup); + g_free(markup); + + gtk_image_set_from_pixbuf(GTK_IMAGE(icons[i]), curr_icon); + + if (sna[i].do_action && !sna[i].do_action(sd, &sna[i])) { + markup = + g_strdup_printf("<b><s>%s</s></b> <i>(failed)</i>", + sna[i].name); + gtk_label_set_markup(GTK_LABEL(labels[i]), markup); + g_free(markup); + + sd->flag_cancel = TRUE; + + gtk_image_set_from_pixbuf(GTK_IMAGE(icons[i]), + icon_cache_get_pixbuf + ("dialog-error.png")); + if (sna[i].error) { + if (sna[i].error->code != 1) { + /* the user has not cancelled something... */ + g_warning + ("Failed while performing \"%s\". Please file a bug report " + "if this problem persists. (Use the Help\342\206\222Report" + " bug option.)\n\nDetails: %s", sna[i].name, + sna[i].error->message); + } + + g_error_free(sna[i].error); + } else { + g_warning + ("Failed while performing \"%s\". Please file a bug report " + "if this problem persists. (Use the Help\342\206\222Report" + " bug option.)", sna[i].name); + } + break; + } + + gtk_image_set_from_pixbuf(GTK_IMAGE(icons[i]), done_icon); + gtk_label_set_markup(GTK_LABEL(labels[i]), sna[i].name); } - + g_free(labels); g_free(icons); } @@ -521,41 +556,41 @@ static void sync_dialog_netarea_start_actions(SyncDialog *sd, SyncNetAction sna[ static SyncNetArea *sync_dialog_netarea_new(void) { SyncNetArea *sna = g_new0(SyncNetArea, 1); - + sna->vbox = gtk_vbox_new(FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(sna->vbox), 10); gtk_widget_show_all(sna->vbox); gtk_widget_hide(sna->vbox); - + return sna; } -static void sync_dialog_netarea_destroy(SyncNetArea *sna) +static void sync_dialog_netarea_destroy(SyncNetArea * sna) { g_return_if_fail(sna != NULL); g_free(sna); } -static void sync_dialog_netarea_show(SyncDialog *sd) +static void sync_dialog_netarea_show(SyncDialog * sd) { g_return_if_fail(sd && sd->sna); - + gtk_widget_hide(GTK_WIDGET(sd->scroll_box)); gtk_widget_show(GTK_WIDGET(sd->sna->vbox)); - + gtk_label_set_markup(GTK_LABEL(sd->label), LABEL_SYNC_SYNCING); gtk_window_set_default_size(GTK_WINDOW(sd->dialog), 0, 0); gtk_window_reshow_with_initial_size(GTK_WINDOW(sd->dialog)); } #if 0 -static void sync_dialog_netarea_hide(SyncDialog *sd) +static void sync_dialog_netarea_hide(SyncDialog * sd) { g_return_if_fail(sd && sd->sna); - + gtk_widget_show(GTK_WIDGET(sd->scroll_box)); gtk_widget_hide(GTK_WIDGET(sd->sna->vbox)); @@ -564,40 +599,40 @@ static void sync_dialog_netarea_hide(SyncDialog *sd) } #endif -static void populate_store(GtkListStore *store) +static void populate_store(GtkListStore * store) { GSList *entry; SyncEntry *e; - + gtk_list_store_clear(store); - + for (entry = entries; entry; entry = entry->next) { - GtkTreeIter iter; - - e = (SyncEntry *) entry->data; + GtkTreeIter iter; + + e = (SyncEntry *) entry->data; - e->selected = TRUE; + e->selected = TRUE; - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, 0, TRUE, 1, e->fancy_name, 2, e, -1); + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, TRUE, 1, e->fancy_name, 2, e, + -1); } } static void -sel_toggle(GtkCellRendererToggle *cellrenderertoggle, - gchar *path_str, - GtkTreeModel *model) +sel_toggle(GtkCellRendererToggle * cellrenderertoggle, + gchar * path_str, GtkTreeModel * model) { - GtkTreeIter iter; + GtkTreeIter iter; GtkTreePath *path = gtk_tree_path_new_from_string(path_str); SyncEntry *se; gboolean active; - + gtk_tree_model_get_iter(model, &iter, path); gtk_tree_model_get(model, &iter, 0, &active, 2, &se, -1); - + se->selected = !active; - + gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, se->selected, -1); gtk_tree_path_free(path); } @@ -620,48 +655,55 @@ static SyncDialog *sync_dialog_new(void) GtkWidget *button6; GtkWidget *label; GtkWidget *hbox; - + GtkTreeViewColumn *column; GtkTreeModel *model; GtkListStore *store; - GtkCellRenderer *cr_text, *cr_toggle; - + GtkCellRenderer *cr_text, *cr_toggle; + sd = g_new0(SyncDialog, 1); sd->sna = sync_dialog_netarea_new(); dialog = gtk_dialog_new(); gtk_window_set_title(GTK_WINDOW(dialog), "Network Updater"); - gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); + gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); + gtk_window_set_icon(GTK_WINDOW(dialog), + icon_cache_get_pixbuf("syncmanager.png")); gtk_window_set_default_size(GTK_WINDOW(dialog), 420, 260); - gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT); + gtk_window_set_position(GTK_WINDOW(dialog), + GTK_WIN_POS_CENTER_ON_PARENT); gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG); + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); + dialog1_vbox = GTK_DIALOG(dialog)->vbox; gtk_box_set_spacing(GTK_BOX(dialog1_vbox), 5); gtk_container_set_border_width(GTK_CONTAINER(dialog1_vbox), 4); gtk_widget_show(dialog1_vbox); - + hbox = gtk_hbox_new(FALSE, 5); gtk_box_pack_start(GTK_BOX(dialog1_vbox), hbox, FALSE, FALSE, 0); - + label = gtk_label_new(LABEL_SYNC_DEFAULT); gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); gtk_label_set_use_markup(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - + gtk_box_pack_start(GTK_BOX(hbox), - icon_cache_get_image("syncmanager.png"), - FALSE, FALSE, 0); + icon_cache_get_image("syncmanager.png"), + FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, TRUE, 0); gtk_widget_show_all(hbox); - - gtk_box_pack_start(GTK_BOX(dialog1_vbox), sd->sna->vbox, TRUE, TRUE, 0); + + gtk_box_pack_start(GTK_BOX(dialog1_vbox), sd->sna->vbox, TRUE, TRUE, + 0); scrolledwindow2 = gtk_scrolled_window_new(NULL, NULL); gtk_widget_show(scrolledwindow2); - gtk_box_pack_start(GTK_BOX(dialog1_vbox), scrolledwindow2, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(dialog1_vbox), scrolledwindow2, TRUE, TRUE, + 0); gtk_widget_set_size_request(scrolledwindow2, -1, 200); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwindow2), GTK_POLICY_AUTOMATIC, @@ -669,14 +711,16 @@ static SyncDialog *sync_dialog_new(void) gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_SHADOW_IN); - store = gtk_list_store_new(3, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_POINTER); + store = + gtk_list_store_new(3, G_TYPE_BOOLEAN, G_TYPE_STRING, + G_TYPE_POINTER); model = GTK_TREE_MODEL(store); treeview2 = gtk_tree_view_new_with_model(model); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview2), FALSE); gtk_widget_show(treeview2); gtk_container_add(GTK_CONTAINER(scrolledwindow2), treeview2); - + column = gtk_tree_view_column_new(); gtk_tree_view_append_column(GTK_TREE_VIEW(treeview2), column); @@ -688,7 +732,7 @@ static SyncDialog *sync_dialog_new(void) cr_text = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(column, cr_text, TRUE); gtk_tree_view_column_add_attribute(column, cr_text, "markup", 1); - + populate_store(store); dialog1_action_area = GTK_DIALOG(dialog)->action_area; @@ -709,12 +753,13 @@ static SyncDialog *sync_dialog_new(void) GTK_WIDGET_SET_FLAGS(button7, GTK_CAN_DEFAULT); button6 = gtk_button_new_from_stock(GTK_STOCK_CLOSE); - g_signal_connect(G_OBJECT(button6), "clicked", (GCallback)close_clicked, NULL); + g_signal_connect(G_OBJECT(button6), "clicked", + (GCallback) close_clicked, NULL); gtk_dialog_add_action_widget(GTK_DIALOG(dialog), button6, GTK_RESPONSE_ACCEPT); GTK_WIDGET_SET_FLAGS(button6, GTK_CAN_DEFAULT); - sd->dialog = dialog; + sd->dialog = dialog; sd->button_sync = button7; sd->button_cancel = button8; sd->button_close = button6; @@ -724,9 +769,10 @@ static SyncDialog *sync_dialog_new(void) return sd; } -static void sync_dialog_destroy(SyncDialog *sd) +static void sync_dialog_destroy(SyncDialog * sd) { gtk_widget_destroy(sd->dialog); sync_dialog_netarea_destroy(sd->sna); g_free(sd); } +#endif /* HAS_LIBSOUP */ @@ -2,49 +2,50 @@ #define __UIDEFS_H__ char *uidefs_str = "<ui>" \ -"<menubar>" \ -"<menu name=\"InformationMenu\" action=\"InformationMenuAction\">" \ -"<menuitem name=\"Report\" action=\"ReportAction\" />" \ -"<separator/>" \ -"<menuitem name=\"Copy\" action=\"CopyAction\" />" \ -"<menuitem name=\"SaveGraph\" action=\"SaveGraphAction\" />" \ -"<separator/>" \ -"<menuitem name=\"SyncManager\" action=\"SyncManagerAction\" />" \ -"<separator/>" \ -"<menuitem name=\"Quit\" action=\"QuitAction\" />" \ -"</menu>" \ -"<menu name=\"ViewMenu\" action=\"ViewMenuAction\">" \ -"<menuitem name=\"SidePane\" action=\"SidePaneAction\"/>" \ -"<menuitem name=\"Toolbar\" action=\"ToolbarAction\"/>" \ -"<separator/>" \ -"<menuitem name=\"Refresh\" action=\"RefreshAction\"/>" \ -"<separator/>" \ -"<separator name=\"LastSep\"/>" \ -"</menu>" \ -"<menu name=\"HelpMenu\" action=\"HelpMenuAction\">" \ -"<menuitem name=\"OnlineDocs\" action=\"OnlineDocsAction\"/>" \ -"<separator/>" \ -"<menuitem name=\"WebPage\" action=\"HomePageAction\"/>" \ -"<menuitem name=\"ReportBug\" action=\"ReportBugAction\"/>" \ -"<separator/>" \ -"<menuitem name=\"Donate\" action=\"DonateAction\"/>" \ -"<separator/>" \ -"<menu name=\"HelpMenuModules\" action=\"HelpMenuModulesAction\">" \ -"<separator name=\"LastSep\"/>" \ -"</menu>" \ -"<menuitem name=\"About\" action=\"AboutAction\"/>" \ -"</menu>" \ -"</menubar>" \ -"" \ -"<toolbar action=\"MainMenuBar\" action=\"MainMenuBarAction\">" \ -"<placeholder name=\"ToolItems\">" \ -"<toolitem name=\"Refresh\" action=\"RefreshAction\"/>" \ -"<separator/>" \ -"<toolitem name=\"Copy\" action=\"CopyAction\"/>" \ -"<toolitem name=\"Report\" action=\"ReportAction\"/>" \ -"</placeholder>" \ -"</toolbar>" \ -"</ui>" \ -""; +" <menubar>" \ +" <menu name=\"InformationMenu\" action=\"InformationMenuAction\">" \ +" <menuitem name=\"Report\" action=\"ReportAction\" />" \ +/*" <separator/>" \ */ +" <menuitem name=\"Copy\" action=\"CopyAction\" />" \ +/* + * Save Image is not ready for prime time. Yet. + * "<menuitem name=\"SaveGraph\" action=\"SaveGraphAction\" />" \ + */ +" <separator/>" \ +" <menuitem name=\"SyncManager\" action=\"SyncManagerAction\" />" \ +" <separator/>" \ +" <menuitem name=\"Quit\" action=\"QuitAction\" />" \ +" </menu>" \ +" <menu name=\"ViewMenu\" action=\"ViewMenuAction\">" \ +" <menuitem name=\"SidePane\" action=\"SidePaneAction\"/>" \ +" <menuitem name=\"Toolbar\" action=\"ToolbarAction\"/>" \ +" <separator/>" \ +" <menuitem name=\"Refresh\" action=\"RefreshAction\"/>" \ +" <separator/>" \ +" <separator name=\"LastSep\"/>" \ +" </menu>" \ +" <menu name=\"HelpMenu\" action=\"HelpMenuAction\">" \ +" <menuitem name=\"OnlineDocs\" action=\"OnlineDocsAction\"/>" \ +" <separator/>" \ +" <menuitem name=\"WebPage\" action=\"HomePageAction\"/>" \ +" <menuitem name=\"ReportBug\" action=\"ReportBugAction\"/>" \ +" <separator/>" \ +" <menuitem name=\"Donate\" action=\"DonateAction\"/>" \ +" <separator/>" \ +" <menu name=\"HelpMenuModules\" action=\"HelpMenuModulesAction\">" \ +" <separator name=\"LastSep\"/>" \ +" </menu>" \ +" <menuitem name=\"About\" action=\"AboutAction\"/>" \ +" </menu>" \ +" </menubar>" \ +" <toolbar action=\"MainMenuBar\" action=\"MainMenuBarAction\">" \ +" <placeholder name=\"ToolItems\">" \ +" <toolitem name=\"Refresh\" action=\"RefreshAction\"/>" \ +" <separator/>" \ +" <toolitem name=\"Copy\" action=\"CopyAction\"/>" \ +" <toolitem name=\"Report\" action=\"ReportAction\"/>" \ +" </placeholder>" \ +" </toolbar>" \ +"</ui>"; #endif /* __UIDEFS_H__ */ @@ -15,6 +15,18 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ + +/* + * Functions h_strdup_cprintf and h_strconcat are based on GLib version 2.4.6 + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + */ + #include <config.h> #include <report.h> @@ -37,30 +49,29 @@ gchar *seconds_to_string(unsigned int seconds) { unsigned int hours, minutes, days; - minutes = seconds / 60; - hours = minutes / 60; + minutes = seconds / 60; + hours = minutes / 60; minutes %= 60; - days = hours / 24; - hours %= 24; + days = hours / 24; + hours %= 24; #define plural(x) ((x > 1) ? "s" : "") - + if (days < 1) { - if (hours < 1) { - return g_strdup_printf("%d minute%s", minutes, - plural(minutes)); - } else { - return g_strdup_printf("%d hour%s, %d minute%s", - hours, - plural(hours), minutes, - plural(minutes)); - } - } - + if (hours < 1) { + return g_strdup_printf("%d minute%s", minutes, + plural(minutes)); + } else { + return g_strdup_printf("%d hour%s, %d minute%s", + hours, + plural(hours), minutes, + plural(minutes)); + } + } + return g_strdup_printf("%d day%s, %d hour%s and %d minute%s", - days, plural(days), hours, - plural(hours), minutes, - plural(minutes)); + days, plural(days), hours, + plural(hours), minutes, plural(minutes)); } inline gchar *size_human_readable(gfloat size) @@ -154,8 +165,7 @@ void file_chooser_add_filters(GtkWidget * chooser, FileTypes * filters) } } -gchar * -file_chooser_get_extension(GtkWidget * chooser, FileTypes * filters) +gchar *file_chooser_get_extension(GtkWidget * chooser, FileTypes * filters) { GtkFileFilter *filter; const gchar *filter_name; @@ -185,7 +195,7 @@ gpointer file_types_get_data_by_name(FileTypes * filters, gchar * filename) return NULL; } -gchar * file_chooser_build_filename(GtkWidget * chooser, gchar * extension) +gchar *file_chooser_build_filename(GtkWidget * chooser, gchar * extension) { gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)); @@ -207,11 +217,11 @@ gboolean binreloc_init(gboolean try_hardcoded) gchar *tmp; DEBUG("initializing binreloc (hardcoded = %d)", try_hardcoded); - + /* If the runtime data directories we previously found, don't even try to find them again. */ if (params.path_data && params.path_lib) { - DEBUG("data and lib path already found."); + DEBUG("data and lib path already found."); return TRUE; } @@ -223,13 +233,14 @@ gboolean binreloc_init(gboolean try_hardcoded) if (error) { g_error_free(error); } - - DEBUG("%strying hardcoded paths.", try_hardcoded ? "" : "binreloc init failed. "); + + DEBUG("%strying hardcoded paths.", + try_hardcoded ? "" : "binreloc init failed. "); } else { /* If we were able to initialize BinReloc, build the default data and library paths. */ - DEBUG("done, trying to use binreloc paths."); - + DEBUG("done, trying to use binreloc paths."); + tmp = gbr_find_data_dir(PREFIX); params.path_data = g_build_filename(tmp, "hardinfo", NULL); g_free(tmp); @@ -247,23 +258,23 @@ gboolean binreloc_init(gboolean try_hardcoded) definitive test, but it should do okay for most situations. */ tmp = g_build_filename(params.path_data, "benchmark.data", NULL); if (!g_file_test(tmp, G_FILE_TEST_EXISTS)) { - DEBUG("runtime data not found"); - + DEBUG("runtime data not found"); + g_free(params.path_data); g_free(params.path_lib); g_free(tmp); params.path_data = params.path_lib = NULL; - + if (try_hardcoded) { /* We tried the hardcoded paths, but still was unable to find the runtime data. Give up. */ - DEBUG("giving up"); + DEBUG("giving up"); return FALSE; } else { /* Even though BinReloc worked OK, the runtime data was not found. Try the hardcoded paths. */ - DEBUG("trying to find elsewhere"); + DEBUG("trying to find elsewhere"); return binreloc_init(TRUE); } } @@ -307,91 +318,84 @@ log_handler(const gchar * log_domain, void parameters_init(int *argc, char ***argv, ProgramParameters * param) { - static gboolean create_report = FALSE; - static gboolean show_version = FALSE; - static gboolean list_modules = FALSE; - static gboolean autoload_deps = FALSE; - static gchar *report_format = NULL; - static gchar **use_modules = NULL; + static gboolean create_report = FALSE; + static gboolean show_version = FALSE; + static gboolean list_modules = FALSE; + static gboolean autoload_deps = FALSE; + static gchar *report_format = NULL; + static gchar **use_modules = NULL; static GOptionEntry options[] = { { - .long_name = "generate-report", - .short_name = 'r', - .arg = G_OPTION_ARG_NONE, - .arg_data = &create_report, - .description = "creates a report and prints to standard output" - }, + .long_name = "generate-report", + .short_name = 'r', + .arg = G_OPTION_ARG_NONE, + .arg_data = &create_report, + .description = "creates a report and prints to standard output"}, { - .long_name = "report-format", - .short_name = 'f', - .arg = G_OPTION_ARG_STRING, - .arg_data = &report_format, - .description = "chooses a report format (text, html)" - }, + .long_name = "report-format", + .short_name = 'f', + .arg = G_OPTION_ARG_STRING, + .arg_data = &report_format, + .description = "chooses a report format (text, html)"}, { - .long_name = "list-modules", - .short_name = 'l', - .arg = G_OPTION_ARG_NONE, - .arg_data = &list_modules, - .description = "lists modules" - }, + .long_name = "list-modules", + .short_name = 'l', + .arg = G_OPTION_ARG_NONE, + .arg_data = &list_modules, + .description = "lists modules"}, { - .long_name = "load-module", - .short_name = 'm', - .arg = G_OPTION_ARG_STRING_ARRAY, - .arg_data = &use_modules, - .description = "specify module to load" - }, + .long_name = "load-module", + .short_name = 'm', + .arg = G_OPTION_ARG_STRING_ARRAY, + .arg_data = &use_modules, + .description = "specify module to load"}, { - .long_name = "autoload-deps", - .short_name = 'a', - .arg = G_OPTION_ARG_NONE, - .arg_data = &autoload_deps, - .description = "automatically load module dependencies" - }, + .long_name = "autoload-deps", + .short_name = 'a', + .arg = G_OPTION_ARG_NONE, + .arg_data = &autoload_deps, + .description = "automatically load module dependencies"}, { - .long_name = "version", - .short_name = 'v', - .arg = G_OPTION_ARG_NONE, - .arg_data = &show_version, - .description = "shows program version and quit" - }, - { NULL } + .long_name = "version", + .short_name = 'v', + .arg = G_OPTION_ARG_NONE, + .arg_data = &show_version, + .description = "shows program version and quit"}, + {NULL} }; GOptionContext *ctx; ctx = g_option_context_new("- System Profiler and Benchmark tool"); g_option_context_set_ignore_unknown_options(ctx, FALSE); g_option_context_set_help_enabled(ctx, TRUE); - + g_option_context_add_main_entries(ctx, options, *(argv)[0]); g_option_context_parse(ctx, argc, argv, NULL); - + g_option_context_free(ctx); if (*argc >= 2) { - g_print("Unrecognized arguments.\n" - "Try ``%s --help'' for more information.\n", - *(argv)[0]); - exit(1); + g_print("Unrecognized arguments.\n" + "Try ``%s --help'' for more information.\n", *(argv)[0]); + exit(1); } param->create_report = create_report; param->report_format = REPORT_FORMAT_TEXT; - param->show_version = show_version; - param->list_modules = list_modules; - param->use_modules = use_modules; + param->show_version = show_version; + param->list_modules = list_modules; + param->use_modules = use_modules; param->autoload_deps = autoload_deps; - + if (report_format && g_str_equal(report_format, "html")) - param->report_format = REPORT_FORMAT_HTML; - + param->report_format = REPORT_FORMAT_HTML; + gchar *confdir = g_build_filename(g_get_home_dir(), ".hardinfo", NULL); if (!g_file_test(confdir, G_FILE_TEST_EXISTS)) { - mkdir(confdir, 0744); + mkdir(confdir, 0744); } - g_free(confdir); + g_free(confdir); } gboolean ui_init(int *argc, char ***argv) @@ -409,11 +413,11 @@ gboolean ui_init(int *argc, char ***argv) void open_url(gchar * url) { const gchar *browsers[] = { - "xdg-open", "gnome-open", "kfmclient openURL", - "sensible-browser", "firefox", "epiphany", - "iceweasel", "seamonkey", "galeon", "mozilla", - "opera", "konqueror", "netscape", "links -g", - NULL + "xdg-open", "gnome-open", "kfmclient openURL", + "sensible-browser", "firefox", "epiphany", + "iceweasel", "seamonkey", "galeon", "mozilla", + "opera", "konqueror", "netscape", "links -g", + NULL }; gint i; @@ -444,309 +448,323 @@ gchar *strreplace(gchar * string, gchar * replace, gchar new_char) static GHashTable *__module_methods = NULL; -static void module_register_methods(ShellModule *module) +static void module_register_methods(ShellModule * module) { ShellModuleMethod *(*get_methods) (void); gchar *method_name; if (__module_methods == NULL) { - __module_methods = g_hash_table_new(g_str_hash, g_str_equal); + __module_methods = g_hash_table_new(g_str_hash, g_str_equal); } - if (g_module_symbol(module->dll, "hi_exported_methods", (gpointer) &get_methods)) { - ShellModuleMethod *methods = get_methods(); - - while (TRUE) { - ShellModuleMethod method = *methods; - gchar *name = g_path_get_basename(g_module_name(module->dll)); - - strend(name, '.'); - - method_name = g_strdup_printf("%s::%s", name, method.name); - g_hash_table_insert(__module_methods, method_name, method.function); - g_free(name); - - if (!(*(++methods)).name) - break; - } + if (g_module_symbol + (module->dll, "hi_exported_methods", (gpointer) & get_methods)) { + ShellModuleMethod *methods = get_methods(); + + while (TRUE) { + ShellModuleMethod method = *methods; + gchar *name = g_path_get_basename(g_module_name(module->dll)); + + strend(name, '.'); + + method_name = g_strdup_printf("%s::%s", name, method.name); + g_hash_table_insert(__module_methods, method_name, + method.function); + g_free(name); + + if (!(*(++methods)).name) + break; + } } } -gchar *module_call_method(gchar *method) +gchar *module_call_method(gchar * method) { gchar *(*function) (void); - + if (__module_methods == NULL) { - return NULL; + return NULL; } - + function = g_hash_table_lookup(__module_methods, method); return function ? g_strdup(function()) : - g_strdup_printf("{Unknown method: \"%s\"}", method); + g_strdup_printf("{Unknown method: \"%s\"}", method); } -static ShellModule *module_load(gchar *filename) +static ShellModule *module_load(gchar * filename) { ShellModule *module; gchar *tmp; - + module = g_new0(ShellModule, 1); - + if (params.gui_running) { - gchar *tmpicon; - - tmpicon = g_strdup(filename); - gchar *dot = g_strrstr(tmpicon, "." G_MODULE_SUFFIX); - - *dot = '\0'; - - tmp = g_strdup_printf("%s.png", tmpicon); - module->icon = icon_cache_get_pixbuf(tmp); - - g_free(tmp); - g_free(tmpicon); + gchar *tmpicon; + + tmpicon = g_strdup(filename); + gchar *dot = g_strrstr(tmpicon, "." G_MODULE_SUFFIX); + + *dot = '\0'; + + tmp = g_strdup_printf("%s.png", tmpicon); + module->icon = icon_cache_get_pixbuf(tmp); + + g_free(tmp); + g_free(tmpicon); } tmp = g_build_filename(params.path_lib, "modules", filename, NULL); module->dll = g_module_open(tmp, G_MODULE_BIND_LAZY); g_free(tmp); - + if (module->dll) { - void (*init) (void); - ModuleEntry *(*get_module_entries) (void); - gint (*weight_func) (void); - gchar *(*name_func) (void); - ModuleEntry *entries; - gint i = 0; - - if (!g_module_symbol(module->dll, "hi_module_get_entries", (gpointer) & get_module_entries) || - !g_module_symbol(module->dll, "hi_module_get_name", (gpointer) & name_func)) { - goto failed; - } - - if (g_module_symbol(module->dll, "hi_module_init", (gpointer) & init)) { - init(); - } - - g_module_symbol(module->dll, "hi_module_get_weight", (gpointer) & weight_func); - - module->weight = weight_func ? weight_func() : 0; - module->name = name_func(); - - entries = get_module_entries(); - while (entries[i].name) { - ShellModuleEntry *entry = g_new0(ShellModuleEntry, 1); - - if (params.gui_running) { - entry->icon = icon_cache_get_pixbuf(entries[i].icon); - } - - g_module_symbol(module->dll, "hi_more_info", - (gpointer) & (entry->morefunc)); - g_module_symbol(module->dll, "hi_get_field", - (gpointer) & (entry->fieldfunc)); - g_module_symbol(module->dll, "hi_note_func", - (gpointer) & (entry->notefunc)); - - entry->name = entries[i].name; - entry->scan_func = entries[i].scan_callback; - entry->func = entries[i].callback; - entry->number = i; - - module->entries = g_slist_append(module->entries, entry); - - i++; - } - - module_register_methods(module); + void (*init) (void); + ModuleEntry *(*get_module_entries) (void); + gint(*weight_func) (void); + gchar *(*name_func) (void); + ModuleEntry *entries; + gint i = 0; + + if (!g_module_symbol + (module->dll, "hi_module_get_entries", + (gpointer) & get_module_entries) + || !g_module_symbol(module->dll, "hi_module_get_name", + (gpointer) & name_func)) { + goto failed; + } + + if (g_module_symbol + (module->dll, "hi_module_init", (gpointer) & init)) { + init(); + } + + g_module_symbol(module->dll, "hi_module_get_weight", + (gpointer) & weight_func); + + module->weight = weight_func ? weight_func() : 0; + module->name = name_func(); + + entries = get_module_entries(); + while (entries[i].name) { + ShellModuleEntry *entry = g_new0(ShellModuleEntry, 1); + + if (params.gui_running) { + entry->icon = icon_cache_get_pixbuf(entries[i].icon); + } + + g_module_symbol(module->dll, "hi_more_info", + (gpointer) & (entry->morefunc)); + g_module_symbol(module->dll, "hi_get_field", + (gpointer) & (entry->fieldfunc)); + g_module_symbol(module->dll, "hi_note_func", + (gpointer) & (entry->notefunc)); + + entry->name = entries[i].name; + entry->scan_func = entries[i].scan_callback; + entry->func = entries[i].callback; + entry->number = i; + + module->entries = g_slist_append(module->entries, entry); + + i++; + } + + module_register_methods(module); } else { failed: - DEBUG("loading module %s failed", filename); - - g_free(module->name); - g_free(module); - module = NULL; + DEBUG("loading module %s failed", filename); + + g_free(module->name); + g_free(module); + module = NULL; } - + return module; } -static gboolean module_in_module_list(gchar *module, gchar **module_list) +static gboolean module_in_module_list(gchar * module, gchar ** module_list) { int i = 0; - + if (!module_list) - return TRUE; - + return TRUE; + for (; module_list[i]; i++) { - if (g_str_equal(module_list[i], module)) - return TRUE; + if (g_str_equal(module_list[i], module)) + return TRUE; } - + return FALSE; } static gint module_cmp(gconstpointer m1, gconstpointer m2) { - ShellModule *a = (ShellModule *)m1; - ShellModule *b = (ShellModule *)m2; - + ShellModule *a = (ShellModule *) m1; + ShellModule *b = (ShellModule *) m2; + return a->weight - b->weight; } static void module_entry_free(gpointer data, gpointer user_data) { - ShellModuleEntry *entry = (ShellModuleEntry *)data; + ShellModuleEntry *entry = (ShellModuleEntry *) data; if (entry) { - /*g_free(entry->name);*/ - g_object_unref(entry->icon); + g_free(entry->name); + g_object_unref(entry->icon); - g_free(entry); + g_free(entry); } } -static void module_free(ShellModule *module) +static void module_free(ShellModule * module) { g_free(module->name); g_object_unref(module->icon); - /*g_module_close(module->dll);*/ + g_module_close(module->dll); DEBUG("module_free: module->entries, %p\n", module->entries); - g_slist_foreach(module->entries, (GFunc)module_entry_free, NULL); + g_slist_foreach(module->entries, (GFunc) module_entry_free, NULL); g_slist_free(module->entries); g_free(module); } -ModuleAbout *module_get_about(ShellModule *module) +ModuleAbout *module_get_about(ShellModule * module) { - ModuleAbout *(*get_about)(void); - + ModuleAbout *(*get_about) (void); + if (g_module_symbol(module->dll, "hi_module_get_about", - (gpointer) &get_about)) { - return get_about(); + (gpointer) & get_about)) { + return get_about(); } - + return NULL; } -static GSList *modules_check_deps(GSList *modules) +static GSList *modules_check_deps(GSList * modules) { - GSList *mm; + GSList *mm; ShellModule *module; - + for (mm = modules; mm; mm = mm->next) { - gchar **(*get_deps)(void); - gchar **deps; - gint i; - - module = (ShellModule *) mm->data; - - if (g_module_symbol(module->dll, "hi_module_get_dependencies", - (gpointer) & get_deps)) { - for (i = 0, deps = get_deps(); deps[i]; i++) { - GSList *l; - ShellModule *m; - gboolean found = FALSE; - - for (l = modules; l; l = l->next) { - m = (ShellModule *)l->data; - gchar *name = g_path_get_basename(g_module_name(m->dll)); - - if (g_str_equal(name, deps[i])) { - found = TRUE; - break; - } - - g_free(name); - } - - if (!found) { - if (params.autoload_deps) { - ShellModule *mod = module_load(deps[i]); - - if (mod) - modules = g_slist_append(modules, mod); - modules = modules_check_deps(modules); /* re-check dependencies */ - - break; - } - - if (params.gui_running) { - GtkWidget *dialog; - - dialog = gtk_message_dialog_new(NULL, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_QUESTION, - GTK_BUTTONS_NONE, - "Module \"%s\" depends on module \"%s\", load it?", - module->name, deps[i]); - gtk_dialog_add_buttons(GTK_DIALOG(dialog), - GTK_STOCK_NO, GTK_RESPONSE_REJECT, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - - if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { - ShellModule *mod = module_load(deps[i]); - - if (mod) - modules = g_slist_append(modules, mod); - modules = modules_check_deps(modules); /* re-check dependencies */ - } else { - modules = g_slist_remove(modules, module); - module_free(module); - } - - gtk_widget_destroy(dialog); - } else { - g_error("Module \"%s\" depends on module \"%s\".", module->name, deps[i]); - } - } - } - } - } - + gchar **(*get_deps) (void); + gchar **deps; + gint i; + + module = (ShellModule *) mm->data; + + if (g_module_symbol(module->dll, "hi_module_get_dependencies", + (gpointer) & get_deps)) { + for (i = 0, deps = get_deps(); deps[i]; i++) { + GSList *l; + ShellModule *m; + gboolean found = FALSE; + + for (l = modules; l; l = l->next) { + m = (ShellModule *) l->data; + gchar *name = + g_path_get_basename(g_module_name(m->dll)); + + if (g_str_equal(name, deps[i])) { + found = TRUE; + break; + } + + g_free(name); + } + + if (!found) { + if (params.autoload_deps) { + ShellModule *mod = module_load(deps[i]); + + if (mod) + modules = g_slist_append(modules, mod); + modules = modules_check_deps(modules); /* re-check dependencies */ + + break; + } + + if (params.gui_running) { + GtkWidget *dialog; + + dialog = gtk_message_dialog_new(NULL, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, + "Module \"%s\" depends on module \"%s\", load it?", + module->name, + deps[i]); + gtk_dialog_add_buttons(GTK_DIALOG(dialog), + GTK_STOCK_NO, + GTK_RESPONSE_REJECT, + GTK_STOCK_OPEN, + GTK_RESPONSE_ACCEPT, NULL); + + if (gtk_dialog_run(GTK_DIALOG(dialog)) == + GTK_RESPONSE_ACCEPT) { + ShellModule *mod = module_load(deps[i]); + + if (mod) + modules = g_slist_append(modules, mod); + modules = modules_check_deps(modules); /* re-check dependencies */ + } else { + modules = g_slist_remove(modules, module); + module_free(module); + } + + gtk_widget_destroy(dialog); + } else { + g_error("Module \"%s\" depends on module \"%s\".", + module->name, deps[i]); + } + } + } + } + } + return modules; } -static GSList *modules_load(gchar **module_list) +static GSList *modules_load(gchar ** module_list) { GDir *dir; GSList *modules = NULL; ShellModule *module; gchar *filename; - + filename = g_build_filename(params.path_lib, "modules", NULL); dir = g_dir_open(filename, 0, NULL); g_free(filename); - + if (dir) { - while ((filename = (gchar*)g_dir_read_name(dir))) { - if (g_strrstr(filename, "." G_MODULE_SUFFIX) && - module_in_module_list(filename, module_list) && - ((module = module_load(filename)))) { - modules = g_slist_append(modules, module); - } - } + while ((filename = (gchar *) g_dir_read_name(dir))) { + if (g_strrstr(filename, "." G_MODULE_SUFFIX) && + module_in_module_list(filename, module_list) && + ((module = module_load(filename)))) { + modules = g_slist_append(modules, module); + } + } - g_dir_close(dir); + g_dir_close(dir); } modules = modules_check_deps(modules); if (g_slist_length(modules) == 0) { - if (params.use_modules == NULL) { - g_error("No module could be loaded. Check permissions on \"%s\" and try again.", - params.path_lib); - } else { - g_error("No module could be loaded. Please use hardinfo -l to list all avai" - "lable modules and try again with a valid module list."); - - } - } - + if (params.use_modules == NULL) { + g_error + ("No module could be loaded. Check permissions on \"%s\" and try again.", + params.path_lib); + } else { + g_error + ("No module could be loaded. Please use hardinfo -l to list all avai" + "lable modules and try again with a valid module list."); + + } + } + return g_slist_sort(modules, module_cmp); } @@ -760,204 +778,266 @@ GSList *modules_load_all(void) return modules_load(NULL); } -gint tree_view_get_visible_height(GtkTreeView *tv) +gint tree_view_get_visible_height(GtkTreeView * tv) { - GtkTreePath *path; - GdkRectangle rect; - GtkTreeIter iter; + GtkTreePath *path; + GdkRectangle rect; + GtkTreeIter iter; GtkTreeModel *model = gtk_tree_view_get_model(tv); - gint nrows = 1; + gint nrows = 1; path = gtk_tree_path_new_first(); - gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), - path, NULL, &rect); + gtk_tree_view_get_cell_area(GTK_TREE_VIEW(tv), path, NULL, &rect); /* FIXME: isn't there any easier way to tell the number of rows? */ gtk_tree_model_get_iter_first(model, &iter); do { - nrows++; + nrows++; } while (gtk_tree_model_iter_next(model, &iter)); - + gtk_tree_path_free(path); - + return nrows * rect.height; } -void tree_view_save_image(gchar *filename) +void tree_view_save_image(gchar * filename) { /* this is ridiculously complicated :/ why in the hell gtk+ makes this kind of thing so difficult? */ - + /* FIXME: this does not work if the window (or part of it) isn't visible. does - anyone know how to fix this? :/ */ - Shell *shell = shell_get_main_shell(); - GtkWidget *widget = shell->info->view; + anyone know how to fix this? :/ */ + Shell *shell = shell_get_main_shell(); + GtkWidget *widget = shell->info->view; + + PangoLayout *layout; + PangoContext *context; + PangoRectangle rect; - PangoLayout *layout; - PangoContext *context; - PangoRectangle rect; + GdkPixmap *pm; + GdkPixbuf *pb; + GdkGC *gc; + GdkColor black = { 0, 0, 0, 0 }; + GdkColor white = { 0, 65535, 65535, 65535 }; - GdkPixmap *pm; - GdkPixbuf *pb; - GdkGC *gc; - GdkColor black = { 0, 0, 0, 0 }; - GdkColor white = { 0, 65535, 65535, 65535 }; + gint w, h, visible_height; + gchar *tmp; - gint w, h, visible_height; - gchar *tmp; - - gboolean tv_enabled; + gboolean tv_enabled; /* present the window */ gtk_window_present(GTK_WINDOW(shell->window)); - + /* if the treeview is disabled, we need to enable it so we get the correct colors when saving. we make it insensitive later on if it - was this way before entering this function */ + was this way before entering this function */ tv_enabled = GTK_WIDGET_IS_SENSITIVE(widget); gtk_widget_set_sensitive(widget, TRUE); - + gtk_widget_queue_draw(widget); /* unselect things in the information treeview */ gtk_range_set_value(GTK_RANGE - (GTK_SCROLLED_WINDOW(shell->info->scroll)-> - vscrollbar), 0.0); - gtk_tree_selection_unselect_all( - gtk_tree_view_get_selection(GTK_TREE_VIEW(widget))); + (GTK_SCROLLED_WINDOW(shell->info->scroll)-> + vscrollbar), 0.0); + gtk_tree_selection_unselect_all(gtk_tree_view_get_selection + (GTK_TREE_VIEW(widget))); while (gtk_events_pending()) - gtk_main_iteration(); + gtk_main_iteration(); /* initialize stuff */ gc = gdk_gc_new(widget->window); gdk_gc_set_background(gc, &black); gdk_gc_set_foreground(gc, &white); - - context = gtk_widget_get_pango_context (widget); + + context = gtk_widget_get_pango_context(widget); layout = pango_layout_new(context); - + visible_height = tree_view_get_visible_height(GTK_TREE_VIEW(widget)); - - /* draw the title */ + + /* draw the title */ tmp = g_strdup_printf("<b><big>%s</big></b>\n<small>%s</small>", - shell->selected->name, - shell->selected->notefunc(shell->selected->number)); + shell->selected->name, + shell->selected->notefunc(shell->selected-> + number)); pango_layout_set_markup(layout, tmp, -1); pango_layout_set_width(layout, widget->allocation.width * PANGO_SCALE); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_get_pixel_extents(layout, NULL, &rect); - + w = widget->allocation.width; h = visible_height + rect.height; - + pm = gdk_pixmap_new(widget->window, w, rect.height, -1); gdk_draw_rectangle(GDK_DRAWABLE(pm), gc, TRUE, 0, 0, w, rect.height); - gdk_draw_layout_with_colors (GDK_DRAWABLE(pm), gc, 0, 0, layout, - &white, &black); - + gdk_draw_layout_with_colors(GDK_DRAWABLE(pm), gc, 0, 0, layout, + &white, &black); + /* copy the pixmap from the treeview and from the title */ pb = gdk_pixbuf_get_from_drawable(NULL, - widget->window, + widget->window, + NULL, 0, 0, 0, 0, w, h); + pb = gdk_pixbuf_get_from_drawable(pb, + pm, NULL, 0, 0, - 0, 0, - w, h); - pb = gdk_pixbuf_get_from_drawable(pb, - pm, - NULL, - 0, 0, - 0, visible_height, - w, rect.height); + 0, visible_height, w, rect.height); /* save the pixbuf to a png file */ gdk_pixbuf_save(pb, filename, "png", NULL, - "compression", "9", - "tEXt::hardinfo::version", VERSION, - "tEXt::hardinfo::arch", ARCH, - NULL); - + "compression", "9", + "tEXt::hardinfo::version", VERSION, + "tEXt::hardinfo::arch", ARCH, NULL); + /* unref */ g_object_unref(pb); g_object_unref(layout); g_object_unref(pm); g_object_unref(gc); g_free(tmp); - + gtk_widget_set_sensitive(widget, tv_enabled); } - static gboolean __idle_free_do(gpointer ptr) { + DEBUG("bla %p", ptr); + if (ptr) { - g_free(ptr); + g_free(ptr); } return FALSE; } +#if RELEASE == 1 gpointer idle_free(gpointer ptr) +#else +gpointer __idle_free(gpointer ptr, gchar * f, gint l) +#endif { + DEBUG("file: %s, line: %d, ptr %p", f, l, ptr); + if (ptr) { - g_timeout_add(10000, __idle_free_do, ptr); + g_timeout_add(10000, __idle_free_do, ptr); } - + return ptr; } -void module_entry_scan_all_except(ModuleEntry *entries, gint except_entry) +void module_entry_scan_all_except(ModuleEntry * entries, gint except_entry) { ModuleEntry entry; - gint i = 0; - void (*scan_callback)(gboolean reload); - + gint i = 0; + void (*scan_callback) (gboolean reload); + gchar *text; + shell_view_set_enabled(FALSE); for (entry = entries[0]; entry.name; entry = entries[++i]) { - if (i == except_entry) - continue; - - shell_status_update(idle_free(g_strdup_printf("Scanning: %s...", entry.name))); - - if ((scan_callback = entry.scan_callback)) { - scan_callback(FALSE); - } - } - + if (i == except_entry) + continue; + + text = g_strdup_printf("Scanning: %s...", entry.name); + shell_status_update(text); + g_free(text); + + if ((scan_callback = entry.scan_callback)) { + scan_callback(FALSE); + } + } + shell_view_set_enabled(TRUE); shell_status_update("Done."); } -void module_entry_scan_all(ModuleEntry *entries) +void module_entry_scan_all(ModuleEntry * entries) { module_entry_scan_all_except(entries, -1); } -void module_entry_reload(ShellModuleEntry *module_entry) +void module_entry_reload(ShellModuleEntry * module_entry) { if (module_entry->scan_func) { - module_entry->scan_func(TRUE); + module_entry->scan_func(TRUE); } } -void module_entry_scan(ShellModuleEntry *module_entry) +void module_entry_scan(ShellModuleEntry * module_entry) { if (module_entry->scan_func) { - module_entry->scan_func(FALSE); + module_entry->scan_func(FALSE); } } -gchar *module_entry_function(ShellModuleEntry *module_entry) +gchar *module_entry_function(ShellModuleEntry * module_entry) { if (module_entry->func) { - return g_strdup(module_entry->func()); + return g_strdup(module_entry->func()); } - - return g_strdup("[Error]\n" - "Invalid module="); + + return g_strdup("[Error]\n" "Invalid module="); } -const gchar *module_entry_get_note(ShellModuleEntry *module_entry) +const gchar *module_entry_get_note(ShellModuleEntry * module_entry) { return module_entry->notefunc(module_entry->number); } + +gchar *h_strdup_cprintf(const gchar * format, gchar * source, ...) +{ + gchar *buffer, *retn; + va_list args; + + va_start(args, source); + buffer = g_strdup_vprintf(format, args); + va_end(args); + + if (source) { + retn = g_strconcat(source, buffer, NULL); + g_free(buffer); + g_free(source); + } else { + retn = buffer; + } + + + return retn; +} + +gchar *h_strconcat(gchar * string1, ...) +{ + gsize l; + va_list args; + gchar *s; + gchar *concat; + gchar *ptr; + + if (!string1) + return NULL; + + l = 1 + strlen(string1); + va_start(args, string1); + s = va_arg(args, gchar *); + while (s) { + l += strlen(s); + s = va_arg(args, gchar *); + } + va_end(args); + + concat = g_new(gchar, l); + ptr = concat; + + ptr = g_stpcpy(ptr, string1); + va_start(args, string1); + s = va_arg(args, gchar *); + while (s) { + ptr = g_stpcpy(ptr, s); + s = va_arg(args, gchar *); + } + va_end(args); + + g_free(string1); + + return concat; +} @@ -23,64 +23,63 @@ #include "vendor.h" static const Vendor vendors[] = { - { "ATI", "ATI Technologies, Inc.","www.ati.com" }, - { "nVidia", "NVIDIA Corporation", "www.nvidia.com" }, - { "3Com", "3Com", "www.3com.com" }, - { "Intel" , "Intel Corp.", "www.intel.com" }, - { "Cirrus Logic", "Cirrus Logic", "www.cirrus.com" }, - { "VIA Technologies", "VIA Technologies", "www.via.com.tw" }, - { "VIA", "VIA Technologies", "www.via.com.tw" }, - { "hp", "Hewlett-Packard", "www.hp.com" }, - { "NEC Corporation", "NEC Coporation", "www.nec.com" }, - { "MAXTOR", "MAXTOR", "www.maxtor.com" }, - { "SAMSUNG", "SAMSUNG", "www.samsung.com" }, - { "PIONEER", "PIONEER", "www.pioneer-eur.com" }, - { "PLEXTOR", "PLEXTOR", "www.plextor.be" }, - { "Realtek Semiconductor", "Realtek", "www.realtek.com.tw" }, - { "TOSHIBA", "TOSHIBA", "www.toshiba.com" }, - { "LITE-ON", "LITE-ON", "www.liteonit.com" }, - { "WDC", "Western Digital", "www.wdc.com" }, - { "HL-DT-ST", "LG Electronics", "www.lge.com" }, - { "ST", "SEAGATE", "www.seagate.com" }, - { "Lexmark", "Lexmark", "www.lexmark.com" }, - { "_NEC", "NEC Corporation", "www.nec.com" }, - { "Creative Labs", "Creative Labs", "www.creative.com" }, - { "Brooktree", "Conexant", "www.brooktree.com" }, - { "Atheros", "Atheros Communications","www.atheros.com" }, - { "MATSHITA", "Panasonic", "www.panasonic.com" }, - { "Silicon Image", "Silicon Image, Inc.", "www.siliconimage.com" }, - { "KYE", "KYE Systems Corp.", "www.genius-kye.com" }, - { "Broadcom", "Broadcom Corp.", "www.broadcom.com" }, - { "Apple", "Apple Computer, Inc.", "www.apple.com" }, - { "IBM", "IBM Corp.", "www.ibm.com" }, - { "Dell", "Dell Computer Corp.", "www.dell.com" }, - { "Logitech", "Logitech International SA", "www.logitech.com" }, - { "FUJITSU", "Fujitsu", "www.fujitsu.com" }, - { "CDU", "Sony", "www.sony.com" }, - { NULL, NULL, NULL }, + {"ATI", "ATI Technologies, Inc.", "www.ati.com"}, + {"nVidia", "NVIDIA Corporation", "www.nvidia.com"}, + {"3Com", "3Com", "www.3com.com"}, + {"Intel", "Intel Corp.", "www.intel.com"}, + {"Cirrus Logic", "Cirrus Logic", "www.cirrus.com"}, + {"VIA Technologies", "VIA Technologies", "www.via.com.tw"}, + {"VIA", "VIA Technologies", "www.via.com.tw"}, + {"hp", "Hewlett-Packard", "www.hp.com"}, + {"NEC Corporation", "NEC Coporation", "www.nec.com"}, + {"MAXTOR", "MAXTOR", "www.maxtor.com"}, + {"SAMSUNG", "SAMSUNG", "www.samsung.com"}, + {"PIONEER", "PIONEER", "www.pioneer-eur.com"}, + {"PLEXTOR", "PLEXTOR", "www.plextor.be"}, + {"Realtek Semiconductor", "Realtek", "www.realtek.com.tw"}, + {"TOSHIBA", "TOSHIBA", "www.toshiba.com"}, + {"LITE-ON", "LITE-ON", "www.liteonit.com"}, + {"WDC", "Western Digital", "www.wdc.com"}, + {"HL-DT-ST", "LG Electronics", "www.lge.com"}, + {"ST", "SEAGATE", "www.seagate.com"}, + {"Lexmark", "Lexmark", "www.lexmark.com"}, + {"_NEC", "NEC Corporation", "www.nec.com"}, + {"Creative Labs", "Creative Labs", "www.creative.com"}, + {"Brooktree", "Conexant", "www.brooktree.com"}, + {"Atheros", "Atheros Communications", "www.atheros.com"}, + {"MATSHITA", "Panasonic", "www.panasonic.com"}, + {"Silicon Image", "Silicon Image, Inc.", "www.siliconimage.com"}, + {"KYE", "KYE Systems Corp.", "www.genius-kye.com"}, + {"Broadcom", "Broadcom Corp.", "www.broadcom.com"}, + {"Apple", "Apple Computer, Inc.", "www.apple.com"}, + {"IBM", "IBM Corp.", "www.ibm.com"}, + {"Dell", "Dell Computer Corp.", "www.dell.com"}, + {"Logitech", "Logitech International SA", "www.logitech.com"}, + {"FUJITSU", "Fujitsu", "www.fujitsu.com"}, + {"CDU", "Sony", "www.sony.com"}, + {NULL, NULL, NULL}, }; -const gchar *vendor_get_name(const gchar *id) +const gchar *vendor_get_name(const gchar * id) { - int i; - - for (i = 0; vendors[i].id; i++) { - if (strstr(id, vendors[i].id)) - return vendors[i].name; - } - - return id; + int i; + + for (i = 0; vendors[i].id; i++) { + if (strstr(id, vendors[i].id)) + return vendors[i].name; + } + + return id; } -const gchar *vendor_get_url(const gchar *id) +const gchar *vendor_get_url(const gchar * id) { - int i; - - for (i = 0; vendors[i].id; i++) { - if (strstr(id, vendors[i].id)) - return vendors[i].url; - } - - return NULL; -} + int i; + for (i = 0; vendors[i].id; i++) { + if (strstr(id, vendors[i].id)) + return vendors[i].url; + } + + return NULL; +} |