diff options
Diffstat (limited to 'hardinfo2/arch/common')
| -rw-r--r-- | hardinfo2/arch/common/display.h | 137 | ||||
| -rw-r--r-- | hardinfo2/arch/common/fib.h | 50 | ||||
| -rw-r--r-- | hardinfo2/arch/common/languages.h | 99 | ||||
| -rw-r--r-- | hardinfo2/arch/common/md5.h | 62 | ||||
| -rw-r--r-- | hardinfo2/arch/common/printers.h | 67 | ||||
| -rw-r--r-- | hardinfo2/arch/common/sha1.h | 61 | ||||
| -rw-r--r-- | hardinfo2/arch/common/zlib.h | 81 | 
7 files changed, 557 insertions, 0 deletions
| diff --git a/hardinfo2/arch/common/display.h b/hardinfo2/arch/common/display.h new file mode 100644 index 00000000..6731e3e3 --- /dev/null +++ b/hardinfo2/arch/common/display.h @@ -0,0 +1,137 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static void +get_glx_info(DisplayInfo *di) +{ +    gchar *output; +    if (g_spawn_command_line_sync("glxinfo", &output, NULL, NULL, NULL)) { +	gchar **output_lines, **old; + +	output_lines = g_strsplit(output, "\n", 0); +	g_free(output); + +	old = output_lines; +	while (*(++output_lines)) { +	    if (strstr(*output_lines, "OpenGL")) { +		gchar **tmp = g_strsplit(*output_lines, ":", 0); + +		tmp[1] = g_strchug(tmp[1]); + +		get_str("OpenGL vendor str", di->ogl_vendor); +		get_str("OpenGL renderer str", di->ogl_renderer); +		get_str("OpenGL version str", di->ogl_version); + +		g_strfreev(tmp); +	    } +	} + +	g_strfreev(old); + +	if (!di->ogl_vendor) +	    di->ogl_vendor = "Unknown"; +	if (!di->ogl_renderer) +	    di->ogl_renderer = "Unknown"; +	if (!di->ogl_version) +	    di->ogl_version = "Unknown"; +    } else { +	di->ogl_vendor = di->ogl_renderer = di->ogl_version = "Unknown"; +    } + +} + +static void +get_x11_info(DisplayInfo *di) +{ +    gchar *output; +     +    if (g_spawn_command_line_sync("xdpyinfo", &output, NULL, NULL, NULL)) { +	gchar **output_lines, **old; + +	output_lines = g_strsplit(output, "\n", 0); +	g_free(output); + +	old = output_lines; +	while (*(output_lines++)) { +            gchar **tmp = g_strsplit(*output_lines, ":", 0); + +            if (tmp[1] && tmp[0]) { +              tmp[1] = g_strchug(tmp[1]); + +              get_str("vendor string", di->vendor); +              get_str("X.Org version", di->version); +              get_str("XFree86 version", di->version); + +              if (g_str_has_prefix(tmp[0], "number of extensions")) { +                int n; +                 +                di->extensions = ""; +                 +                for (n = atoi(tmp[1]); n; n--) { +                  di->extensions = g_strconcat(di->extensions,  +                                               g_strstrip(*(++output_lines)), +                                               "=\n", +                                               NULL); +                } +                g_strfreev(tmp); +                 +                break; +              } +            } + +            g_strfreev(tmp); +	} + +	g_strfreev(old); +    } +     +    GdkScreen *screen = gdk_screen_get_default(); +     +    if (screen && GDK_IS_SCREEN(screen)) { +        gint n_monitors = gdk_screen_get_n_monitors(screen); +        gint i; +         +        di->monitors = ""; +        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); +        } +      } else { +          di->monitors = ""; +      } +} + +static DisplayInfo * +computer_get_display(void) +{ +    DisplayInfo *di = g_new0(DisplayInfo, 1); +     +    GdkScreen *screen = gdk_screen_get_default(); + +    di->width = gdk_screen_get_width(screen); +    di->height = gdk_screen_get_height(screen); + +    get_glx_info(di); +    get_x11_info(di); + +    return di; +} diff --git a/hardinfo2/arch/common/fib.h b/hardinfo2/arch/common/fib.h new file mode 100644 index 00000000..493cfd0f --- /dev/null +++ b/hardinfo2/arch/common/fib.h @@ -0,0 +1,50 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static unsigned long long +fib(unsigned long long n) +{ +    if (n == 0) +        return 0; +    else if (n == 1 || n == 2) +        return 1; +    return fib(n - 1) + fib(n - 2); +} + +static gchar * +benchmark_fib(void) +{ +    GTimer *timer = g_timer_new(); +    gdouble elapsed = 0; +     +    shell_view_set_enabled(FALSE); +    shell_status_update("Calculating the 42<sup>th</sup> Fibonacci number..."); +     +    g_timer_start(timer); +    fib(42);		/* the answer? :) */ +    g_timer_stop(timer); + +    elapsed = g_timer_elapsed(timer, NULL); +     +    g_timer_destroy(timer); + +    gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n" +                           "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); +    return benchmark_include_results(retval, "Fibonacci"); +} + diff --git a/hardinfo2/arch/common/languages.h b/hardinfo2/arch/common/languages.h new file mode 100644 index 00000000..9e1439d1 --- /dev/null +++ b/hardinfo2/arch/common/languages.h @@ -0,0 +1,99 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ +void +scan_languages(OperatingSystem * os) +{ +    FILE *locale; +    gchar buf[128], *retval = ""; + +    locale = popen("locale -va", "r"); +    if (!locale) +	return; + +    gchar name[32]; +    gchar *title = NULL, +          *source = NULL, +	  *address = NULL, +	  *email = NULL, +	  *language = NULL, +	  *territory = NULL, +	  *revision = NULL, +	  *date = NULL, +	  *codeset = NULL; + +    while (fgets(buf, 128, locale)) { +	if (!strncmp(buf, "locale:", 7)) { +	    sscanf(buf, "locale: %s", name); +	    fgets(buf, 128, locale); +	} else if (strchr(buf, '|')) { +	    gchar **tmp = g_strsplit(buf, "|", 2); + +	    tmp[0] = g_strstrip(tmp[0]); + +	    if (tmp[1]) { +		tmp[1] = g_strstrip(tmp[1]); + +		get_str("title", title); +		get_str("source", source); +		get_str("address", address); +		get_str("email", email); +		get_str("language", language); +		get_str("territory", territory); +		get_str("revision", revision); +		get_str("date", date); +		get_str("codeset", codeset); +	    } + +	    g_strfreev(tmp); +	} else { +	    gchar *currlocale; + +	    retval = g_strdup_printf("%s$%s$%s=\n", retval, name, name); + +	    currlocale = g_strdup_printf("[Locale Information]\n" +					 "Name=%s (%s)\n" +					 "Source=%s\n" +					 "Address=%s\n" +					 "Email=%s\n" +					 "Language=%s\n" +					 "Territory=%s\n" +					 "Revision=%s\n" +					 "Date=%s\n" +					 "Codeset=%s\n", name, title, +					 source, address, email, language, +					 territory, revision, date, +					 codeset); + +	    g_hash_table_insert(moreinfo, g_strdup(name), currlocale); + +	    g_free(title); +	    g_free(source); +	    g_free(address); +	    g_free(email); +	    g_free(language); +	    g_free(territory); +	    g_free(revision); +	    g_free(date); +	    g_free(codeset); +	} +    } + +    fclose(locale); + +    os->languages = retval; +} diff --git a/hardinfo2/arch/common/md5.h b/hardinfo2/arch/common/md5.h new file mode 100644 index 00000000..f61aef0f --- /dev/null +++ b/hardinfo2/arch/common/md5.h @@ -0,0 +1,62 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +#include <md5.h> + +gchar * +benchmark_md5(void) +{ +    struct MD5Context ctx; +    guchar checksum[16]; +    int i; +    GTimer *timer = g_timer_new(); +    gdouble elapsed = 0; +    gchar src[65536], *tmpsrc; +    glong srclen = 65536; + +    tmpsrc = src; + +    if (!g_file_get_contents(PREFIX "benchmark.data", +                             &tmpsrc, NULL, NULL)) { +        return g_strdup("[Error]\n" +                        PREFIX "benchmark.data not found=\n"); +    }      +     +    shell_view_set_enabled(FALSE); +    shell_status_update("Generating MD5 sum for 312MiB of data..."); +     +    for (i = 0; i <= 5000; i++) {  +        g_timer_start(timer); + +        MD5Init(&ctx); +        MD5Update(&ctx, (guchar*)tmpsrc, srclen); +        MD5Final(checksum, &ctx); +         +        g_timer_stop(timer); +        elapsed += g_timer_elapsed(timer, NULL); +         +        shell_status_set_percentage(i/50); +    } +     +    g_timer_destroy(timer); + +    gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n" +                           "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); +    return benchmark_include_results(retval, "MD5"); +} + diff --git a/hardinfo2/arch/common/printers.h b/hardinfo2/arch/common/printers.h new file mode 100644 index 00000000..8632ea18 --- /dev/null +++ b/hardinfo2/arch/common/printers.h @@ -0,0 +1,67 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +void +scan_printers(void) +{ +    GModule *cups; +    static int (*cupsGetPrinters) (char ***printers) = NULL; +    static char *(*cupsGetDefault) (void) = NULL; + +    if (printer_list) +	g_free(printer_list); + +    if (!(cupsGetPrinters && cupsGetDefault)) { +	cups = g_module_open("libcups", G_MODULE_BIND_LAZY); +	if (!cups) { +	    printer_list = g_strdup("[Printers]\n" +				    "CUPS libraries cannot be found="); +	    return; +	} + +	if (!g_module_symbol(cups, "cupsGetPrinters", (gpointer) & cupsGetPrinters) +	    || !g_module_symbol(cups, "cupsGetDefault", +				(gpointer) & cupsGetDefault)) { +	    printer_list = +		g_strdup("[Printers]\n" "No suitable CUPS library found="); +            g_module_close(cups); +	    return; +	} +    } + +    gchar **printers; +    int noprinters, i; +    const char *default_printer; + +    noprinters = cupsGetPrinters(&printers); +    default_printer = cupsGetDefault(); + +    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], +				       !strcmp(default_printer, +					       printers[i]) ? +				       "=<i>(Default)</i>\n" : "=\n", +				       NULL); +	    g_free(printers[i]); +	} +    } else { +	printer_list = g_strdup("[Printers]\n" "No printers found"); +    } +} diff --git a/hardinfo2/arch/common/sha1.h b/hardinfo2/arch/common/sha1.h new file mode 100644 index 00000000..521cbcae --- /dev/null +++ b/hardinfo2/arch/common/sha1.h @@ -0,0 +1,61 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ +#include <sha1.h> + +gchar * +benchmark_sha1(void) +{ +    SHA1_CTX ctx; +    guchar checksum[20]; +    int i; +    GTimer *timer = g_timer_new(); +    gdouble elapsed = 0; +    gchar src[65536], *tmpsrc; +    glong srclen = 65536; +     +    tmpsrc = src; + +    if (!g_file_get_contents(PREFIX "benchmark.data", +                             &tmpsrc, NULL, NULL)) { +        return g_strdup("[Error]\n" +                        PREFIX "benchmark.data not found=\n"); +    }      +     +    shell_view_set_enabled(FALSE); +    shell_status_update("Generating SHA1 sum for 312MiB of data..."); +     +    for (i = 0; i <= 5000; i++) {  +        g_timer_start(timer); + +        SHA1Init(&ctx); +        SHA1Update(&ctx, (guchar*)tmpsrc, srclen); +        SHA1Final(checksum, &ctx); +         +        g_timer_stop(timer); +        elapsed += g_timer_elapsed(timer, NULL); +         +        shell_status_set_percentage(i/50); +    } +     +    g_timer_destroy(timer); + +    gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n" +                           "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); +    return benchmark_include_results(retval, "SHA1"); +} + diff --git a/hardinfo2/arch/common/zlib.h b/hardinfo2/arch/common/zlib.h new file mode 100644 index 00000000..74145cae --- /dev/null +++ b/hardinfo2/arch/common/zlib.h @@ -0,0 +1,81 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@linuxmag.com.br> + * + *    This program is free software; you can redistribute it and/or modify + *    it under the terms of the GNU General Public License as published by + *    the Free Software Foundation, version 2. + * + *    This program is distributed in the hope that it will be useful, + *    but WITHOUT ANY WARRANTY; without even the implied warranty of + *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + *    GNU General Public License for more details. + * + *    You should have received a copy of the GNU General Public License + *    along with this program; if not, write to the Free Software + *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA + */ + +static gchar * +benchmark_zlib(void) +{ +    GModule *libz; +    static gulong (*compressBound) (glong srclen) = NULL; +    static gint (*compress) (gchar *dst, glong *dstlen, +                             const gchar *src, glong srclen) = NULL; + +    if (!(compress && compressBound)) { +	libz = g_module_open("libz", G_MODULE_BIND_LAZY); +	if (!libz) { +	    return g_strdup("[Error]\n" +                   "ZLib not found="); +	} + +	if (!g_module_symbol(libz, "compress", (gpointer) & compress) +	    || !g_module_symbol(libz, "compressBound", (gpointer) & compressBound)) { +	     +            g_module_close(libz); +	    return g_strdup("[Error]\n" +	           "Invalid Z-Lib found="); +	} +    } + +    shell_view_set_enabled(FALSE); + +    int i; +    GTimer *timer = g_timer_new(); +    gdouble elapsed = 0; +    gchar src[65536], *tmpsrc; +    glong srclen = 65536; + +    if (!g_file_get_contents(PREFIX "benchmark.data", +                             &tmpsrc, NULL, NULL)) { +        return g_strdup("[Error]\n" +                        PREFIX "benchmark.data not found=\n"); +    }      +     +    shell_status_update("Compressing 64MB with default options..."); +     +    for (i = 0; i <= 1000; i++) {  +        g_timer_start(timer); +         +        gchar *dst; +        glong dstlen = compressBound(srclen); +         +        dst = g_new0(gchar, dstlen); +        compress(dst, &dstlen, src, srclen); + +        g_timer_stop(timer); +        elapsed += g_timer_elapsed(timer, NULL); +        g_free(dst); +         +        shell_status_set_percentage(i/10); +    } +     +    g_timer_destroy(timer); + +    gchar *retval = g_strdup_printf("[Results <i>(in seconds; lower is better)</i>]\n" +                           "<b>This Machine</b>=<b>%.2f</b>\n", elapsed); +    return benchmark_include_results(retval, "ZLib"); +} + | 
