patch for kcminfo..
Alex Zepeda
zipzippy at sonic.net
Sat Oct 19 21:58:11 BST 2002
Unfortunately since it actually implements somewhat sane error handling,
and fills in some previously missing functionality on the fbsd side of
kcminfo.. it introduces new i18n strings.
I know it's bad, awful, horrible, etc. However, I think it would be even
more unprofessional to leave it as-is.
Attached is the patch.
- alex
-------------- next part --------------
Index: info_fbsd.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/info/info_fbsd.cpp,v
retrieving revision 1.21
diff -b -d -u -1 -r1.21 info_fbsd.cpp
--- info_fbsd.cpp 2001/09/26 01:29:38 1.21
+++ info_fbsd.cpp 2002/10/19 20:54:19
@@ -1,3 +1,3 @@
/*
- * $Id: info_fbsd.cpp,v 1.21 2001/09/26 01:29:38 mueller Exp $
+ * $Id$
*
@@ -6,2 +6,6 @@
* it's running on.
+ *
+ * All of the devinfo bits were blatantly stolen from the devinfo utility
+ * provided with FreeBSD 5.0 (and later). No gross hacks were harmed
+ * during the creation of info_fbsd.cpp. Thanks Mike.
*/
@@ -11,3 +15,3 @@
#define INFO_DMA_AVAILABLE
-//#define INFO_PCI_AVAILABLE
+#define INFO_PCI_AVAILABLE
#define INFO_IOPORTS_AVAILABLE
@@ -26,14 +30,26 @@
+#ifdef HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
#include <sys/types.h>
+#include <sys/param.h>
#include <sys/sysctl.h>
-#include <fstab.h>
-#include <stdio.h>
-#include <stdlib.h>
+#if __FreeBSD_version >= 500042
+ //#define HAVE_DEVINFO_H
+#endif
-#include <iostream.h>
+#ifdef HAVE_DEVINFO_H
+ extern "C" {
+ #include <devinfo.h>
+ }
+#endif
+#include <errno.h>
+#include <fstab.h>
+#include <string.h>
+
#include <qdict.h>
#include <qfile.h>
-#include <qfontmetrics.h>
#include <qptrlist.h>
@@ -42,4 +58,2 @@
-#include <kdebug.h>
-
class Device {
@@ -55,2 +69,11 @@
+#ifdef HAVE_DEVINFO_H
+extern "C" {
+ int print_irq(struct devinfo_rman *rman, void *arg);
+ int print_dma(struct devinfo_rman *rman, void *arg);
+ int print_ioports(struct devinfo_rman *rman, void *arg);
+ int print_resource(struct devinfo_res *res, void *arg);
+}
+#endif
+
bool GetInfo_CPU (QListView *lBox)
@@ -69,2 +92,3 @@
char *buf;
+ int i_buf;
@@ -75,3 +99,9 @@
+ // get the TSC speed if we can
+ len = sizeof(i_buf);
+ if (sysctlbyname("machdep.tsc_freq", &i_buf, &len, NULL, 0) != -1) {
+ cpustring = i18n("CPU %1: %2, %3 MHz").arg(i).arg(buf).arg(i_buf/1000000);
+ } else {
cpustring = i18n("CPU %1: %2, unknown speed").arg(i).arg(buf);
+ }
@@ -87,4 +117,5 @@
-bool GetInfo_IRQ (QListView *)
+bool GetInfo_IRQ (QListView *lbox)
{
+#ifdef HAVE_DEVINFO_H
/* systat lists the interrupts assigned to devices as well as how many were
@@ -93,13 +124,36 @@
Too bad it's not very well commented */
+ /* Oh neat, current now has a neat little utility called devinfo */
+ if (devinfo_init())
+ return false;
+ devinfo_foreach_rman(print_irq, lbox);
+ return true;
+#else
return false;
+#endif
}
-bool GetInfo_DMA (QListView *)
+bool GetInfo_DMA (QListView *lbox)
{
+#ifdef HAVE_DEVINFO_H
+ /* Oh neat, current now has a neat little utility called devinfo */
+ if (devinfo_init())
+ return false;
+ devinfo_foreach_rman(print_dma, lbox);
+ return true;
+#else
return false;
+#endif
}
-bool GetInfo_IO_Ports (QListView *)
+bool GetInfo_IO_Ports (QListView *lbox)
{
+#ifdef HAVE_DEVINFO_H
+ /* Oh neat, current now has a neat little utility called devinfo */
+ if (devinfo_init())
return false;
+ devinfo_foreach_rman(print_ioports, lbox);
+ return true;
+#else
+ return false;
+#endif
}
@@ -111,18 +165,13 @@
QString s;
-
- if (!sndstat->exists()) {
- delete sndstat;
- return false;
- }
+ QListViewItem *olditem = 0;
- if (!sndstat->open(IO_ReadOnly)) {
- delete sndstat;
- return false;
- }
+ if (!sndstat->exists() || !sndstat->open(IO_ReadOnly)) {
+ s = i18n("Your sound system could not be queried. /dev/sndstat does not exist or is not readable.");
+ olditem = new QListViewItem(lbox, olditem, s);
+ } else {
t = new QTextStream(sndstat);
-
- QListViewItem* olditem = 0;
- while ((s=t->readLine()) != QString::null)
+ while ((s=t->readLine()) != QString::null) {
olditem = new QListViewItem(lbox, olditem, s);
+ }
@@ -130,2 +179,4 @@
sndstat->close();
+ }
+
delete sndstat;
@@ -140,9 +191,11 @@
QString s;
+ QListViewItem *olditem = 0;
if (!camcontrol->exists()) {
- kdDebug() << "camcontrol doesn't exist" << endl;
-
- delete camcontrol;
- return false;
- }
+ s = i18n ("SCSI subsystem could not be queried: /sbin/camcontrol could not be found");
+ olditem = new QListViewItem(lbox, olditem, s);
+ } else if ((pipe = popen("/sbin/camcontrol devlist 2>&1", "r")) == NULL) {
+ s = i18n ("SCSI subsystem could not be queried: /sbin/camcontrol could not be executed");
+ olditem = new QListViewItem(lbox, olditem, s);
+ } else {
@@ -150,12 +203,67 @@
parse it as opposed to schlepping it into a listbox */
- if ((pipe = popen("/sbin/camcontrol devlist", "r")) == NULL) {
- kdDebug() << "popen failed" << endl;
+
+ t = new QTextStream(pipe, IO_ReadOnly);
+
+ while (true) {
+ s = t->readLine();
+ if ( s.isEmpty() )
+ break;
+ olditem = new QListViewItem(lbox, olditem, s);
+ }
+
+ delete t;
+ pclose(pipe);
+ }
+
delete camcontrol;
+
+ if (!lbox->childCount())
return false;
- }
- t = new QTextStream(pipe, IO_ReadOnly);
+ return true;
+}
+bool GetInfo_PCI (QListView *lbox)
+{
+ FILE *pipe;
+ QFile *pcicontrol;
+ QTextStream *t;
+ QString s, cmd;
QListViewItem *olditem = 0;
+ pcicontrol = new QFile("/usr/X11R6/bin/scanpci");
+
+ if (!pcicontrol->exists()) {
+ delete pcicontrol;
+ pcicontrol = new QFile("/usr/X11R6/bin/pcitweak");
+ if (!pcicontrol->exists()) {
+ delete pcicontrol;
+ pcicontrol = new QFile("/usr/sbin/pciconf");
+ if (!pcicontrol->exists()) {
+ QString s;
+ s = i18n("Could not find any programs with which to query your system's PCI information");
+ (void) new QListViewItem(lbox, 0, s);
+ delete pcicontrol;
+ return true;
+ } else {
+ cmd = "/usr/sbin/pciconf -l";
+ }
+ } else {
+ cmd = "/usr/X11R6/bin/pcitweak -l 2>&1";
+ }
+ } else {
+ cmd = "/usr/X11R6/bin/scanpci";
+ }
+ delete pcicontrol;
+
+ if ((pipe = popen(cmd.latin1(), "r")) == NULL) {
+ s = i18n ("PCI subsystem could not be queried: %1 could not be executed").arg(cmd);
+ olditem = new QListViewItem(lbox, olditem, s);
+ } else {
+
+ /* This prints out a list of all the pci devies, perhaps eventually we could
+ parse it as opposed to schlepping it into a listbox */
+
+ t = new QTextStream(pipe, IO_ReadOnly);
+
while (true) {
@@ -167,6 +275,11 @@
- delete t; delete camcontrol; pclose(pipe);
+ delete t;
+ pclose(pipe);
+ }
- if (!lbox->childCount())
+ if (!lbox->childCount()) {
+ s = i18n("The PCI subsystem could not be queried, this may need root privileges.");
+ olditem = new QListViewItem(lbox, olditem, s);
return false;
+ }
@@ -180,6 +293,8 @@
if (setfsent() != 1) /* Try to open fstab */ {
- kdError() << "Ahh couldn't open fstab!" << endl;
- return false;
- }
-
+ int s_err = errno;
+ QString s;
+ s = i18n("Could not check filesystem info: ");
+ s += strerror(s_err);
+ (void)new QListViewItem(lbox, 0, s);
+ } else {
lbox->addColumn(i18n("Device"));
@@ -189,3 +304,2 @@
-
while ((fstab_ent=getfsent())!=NULL) {
@@ -200,2 +314,3 @@
endfsent(); /* Close fstab */
+ }
return true;
@@ -270,6 +385,8 @@
{
- Device *dev = new Device;
- if (line.find(":") == -1)
+ Device *dev;
+ int colon = line.find(":");
+ if (colon == -1)
return 0;
- dev->name = line.mid(0, line.find(":"));
+ dev = new Device;
+ dev->name = line.mid(0, colon);
dev->description = line.mid(line.find("<")+1, line.length());
@@ -278 +395,74 @@
}
+
+#ifdef HAVE_DEVINFO_H
+
+int print_irq(struct devinfo_rman *rman, void *arg)
+{
+ QListView *lbox = (QListView *)arg;
+ if (strcmp(rman->dm_desc, "Interrupt request lines")==0) {
+ (void)new QListViewItem(lbox, 0, rman->dm_desc);
+ devinfo_foreach_rman_resource(rman, print_resource, arg);
+ }
+ return(0);
+}
+
+int print_dma(struct devinfo_rman *rman, void *arg)
+{
+ QListView *lbox = (QListView *)arg;
+ if (strcmp(rman->dm_desc, "DMA request lines")==0) {
+ (void)new QListViewItem(lbox, lbox->lastItem(), rman->dm_desc);
+ devinfo_foreach_rman_resource(rman, print_resource, arg);
+ }
+ return(0);
+}
+
+int print_ioports(struct devinfo_rman *rman, void *arg)
+{
+ QListView *lbox = (QListView *)arg;
+
+ if (strcmp(rman->dm_desc, "I/O ports")==0) {
+ (void)new QListViewItem(lbox, lbox->lastItem(), rman->dm_desc);
+ devinfo_foreach_rman_resource(rman, print_resource, arg);
+ }
+ else if (strcmp(rman->dm_desc, "I/O memory addresses")==0) {
+ (void)new QListViewItem(lbox, lbox->lastItem(), rman->dm_desc);
+ devinfo_foreach_rman_resource(rman, print_resource, arg);
+ }
+ return(0);
+}
+
+int print_resource(struct devinfo_res *res, void *arg)
+{
+ struct devinfo_dev *dev;
+ struct devinfo_rman *rman;
+ int hexmode;
+
+ QListView *lbox;
+
+ lbox = (QListView *)arg;
+
+ QString s, tmp;
+
+ rman = devinfo_handle_to_rman(res->dr_rman);
+ hexmode = (rman->dm_size > 100) || (rman->dm_size == 0);
+ tmp.sprintf(hexmode ? "0x%lx" : "%lu", res->dr_start);
+ s += tmp;
+ if (res->dr_size > 1) {
+ tmp.sprintf(hexmode ? "-0x%lx" : "-%lu",
+ res->dr_start + res->dr_size - 1);
+ s += tmp;
+ }
+
+ dev = devinfo_handle_to_device(res->dr_device);
+ if ((dev != NULL) && (dev->dd_name[0] != 0)) {
+ tmp.sprintf(" (%s)", dev->dd_name);
+ } else {
+ tmp.sprintf(" ----");
+ }
+ s += tmp;
+
+ (void)new QListViewItem(lbox, lbox->lastItem(), s);
+ return(0);
+}
+
+#endif
More information about the kde-core-devel
mailing list