usbtree.c (usbview-2.0) | : | usbtree.c (usbview-2.1) | ||
---|---|---|---|---|
/************************************************************************* | // SPDX-License-Identifier: GPL-2.0-only | |||
** usbtree.c for USBView - a USB device viewer | /* | |||
** Copyright (c) 1999, 2000 by Greg Kroah-Hartman, <greg@kroah.com> | * usbtree.c for USBView - a USB device viewer | |||
** | * Copyright (c) 1999, 2000, 2021 by Greg Kroah-Hartman, <greg@kroah.com> | |||
** 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 of the License. | ||||
** | ||||
** 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. | ||||
** | ||||
** (See the included file COPYING) | ||||
*************************************************************************/ | ||||
#ifdef HAVE_CONFIG_H | #ifdef HAVE_CONFIG_H | |||
#include <config.h> | #include <config.h> | |||
#endif | #endif | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <stdlib.h> | #include <stdlib.h> | |||
#include <string.h> | #include <string.h> | |||
#include <ctype.h> | #include <ctype.h> | |||
#include <sys/stat.h> | #include <sys/stat.h> | |||
#include <unistd.h> | #include <unistd.h> | |||
skipping to change at line 104 | skipping to change at line 93 | |||
/* add the serial number if we have one */ | /* add the serial number if we have one */ | |||
if (device->serialNumber != NULL) { | if (device->serialNumber != NULL) { | |||
sprintf (string, "\nSerial Number: %s", device->serialNumber); | sprintf (string, "\nSerial Number: %s", device->serialNumber); | |||
gtk_text_buffer_insert_at_cursor(textDescriptionBuffer, string,st rlen(string)); | gtk_text_buffer_insert_at_cursor(textDescriptionBuffer, string,st rlen(string)); | |||
} | } | |||
/* add speed */ | /* add speed */ | |||
switch (device->speed) { | switch (device->speed) { | |||
case 1 : tempString = "1.5Mb/s (low)"; break; | case 1 : tempString = "1.5Mb/s (low)"; break; | |||
case 12 : tempString = "12Mb/s (full)"; break; | case 12 : tempString = "12Mb/s (full)"; break; | |||
case 480 : tempString = "480Mb/s (high)"; break; / | case 480 : tempString = "480Mb/s (high)"; break; | |||
* planning ahead... */ | case 5000 : tempString = "5Gb/s (super)"; break; | |||
case 10000 : tempString = "10Gb/s (super+)"; break; | ||||
default : tempString = "unknown"; break; | default : tempString = "unknown"; break; | |||
} | } | |||
sprintf (string, "\nSpeed: %s", tempString); | sprintf (string, "\nSpeed: %s", tempString); | |||
gtk_text_buffer_insert_at_cursor(textDescriptionBuffer, string,strlen(str ing)); | gtk_text_buffer_insert_at_cursor(textDescriptionBuffer, string,strlen(str ing)); | |||
/* Add Bus number */ | ||||
sprintf (string, "\nBus:%4d", busNumber); | ||||
gtk_text_buffer_insert_at_cursor(textDescriptionBuffer, string,strlen(str | ||||
ing)); | ||||
/* Add device address */ | ||||
sprintf (string, "\nAddress:%4d", deviceNumber); | ||||
gtk_text_buffer_insert_at_cursor(textDescriptionBuffer, string,strlen(str | ||||
ing)); | ||||
/* add ports if available */ | /* add ports if available */ | |||
if (device->maxChildren) { | if (device->maxChildren) { | |||
sprintf (string, "\nNumber of Ports: %i", device->maxChildren); | sprintf (string, "\nNumber of Ports: %i", device->maxChildren); | |||
gtk_text_buffer_insert_at_cursor(textDescriptionBuffer, string,st rlen(string)); | gtk_text_buffer_insert_at_cursor(textDescriptionBuffer, string,st rlen(string)); | |||
} | } | |||
/* add the bandwidth info if available */ | /* add the bandwidth info if available */ | |||
if (device->bandwidth != NULL) { | if (device->bandwidth != NULL) { | |||
sprintf (string, "\nBandwidth allocated: %i / %i (%i%%)", device- >bandwidth->allocated, device->bandwidth->total, device->bandwidth->percent); | sprintf (string, "\nBandwidth allocated: %i / %i (%i%%)", device- >bandwidth->allocated, device->bandwidth->total, device->bandwidth->percent); | |||
gtk_text_buffer_insert_at_cursor(textDescriptionBuffer, string,st rlen(string)); | gtk_text_buffer_insert_at_cursor(textDescriptionBuffer, string,st rlen(string)); | |||
skipping to change at line 203 | skipping to change at line 202 | |||
/* thaw the display */ | /* thaw the display */ | |||
gtk_widget_thaw_child_notify(textDescriptionView); | gtk_widget_thaw_child_notify(textDescriptionView); | |||
/* clean up our string */ | /* clean up our string */ | |||
g_free (string); | g_free (string); | |||
return; | return; | |||
} | } | |||
void SelectItem (GtkTreeSelection *selection, gpointer userData) | static void SelectItem (GtkTreeSelection *selection, gpointer userData) | |||
{ | { | |||
GtkTreeIter iter; | GtkTreeIter iter; | |||
GtkTreeModel *model; | GtkTreeModel *model; | |||
gint deviceAddr; | gint deviceAddr; | |||
if (gtk_tree_selection_get_selected (selection, &model, &iter)) { | if (gtk_tree_selection_get_selected (selection, &model, &iter)) { | |||
gtk_tree_model_get (model, &iter, | gtk_tree_model_get (model, &iter, | |||
DEVICE_ADDR_COLUMN, &deviceAddr, | DEVICE_ADDR_COLUMN, &deviceAddr, | |||
-1); | -1); | |||
PopulateListBox (deviceAddr); | PopulateListBox (deviceAddr); | |||
skipping to change at line 325 | skipping to change at line 324 | |||
strcpy (previousDevicesFile, devicesFile); | strcpy (previousDevicesFile, devicesFile); | |||
return 1; | return 1; | |||
} | } | |||
} | } | |||
void LoadUSBTree (int refresh) | void LoadUSBTree (int refresh) | |||
{ | { | |||
static gboolean signal_connected = FALSE; | static gboolean signal_connected = FALSE; | |||
FILE *usbFile; | FILE *usbFile; | |||
char *dataLine; | char *dataLine; | |||
int finished; | ||||
int i; | int i; | |||
/* if refresh is selected, then always do a refresh, otherwise look at th e file first */ | /* if refresh is selected, then always do a refresh, otherwise look at th e file first */ | |||
if (!refresh) { | if (!refresh) { | |||
if (!FileHasChanged()) { | if (!FileHasChanged()) { | |||
return; | return; | |||
} | } | |||
} | } | |||
usbFile = fopen (devicesFile, "r"); | usbFile = fopen (devicesFile, "r"); | |||
if (usbFile == NULL) { | if (usbFile == NULL) { | |||
FileError(); | FileError(); | |||
return; | return; | |||
} | } | |||
finished = 0; | ||||
Init(); | Init(); | |||
usb_initialize_list (); | usb_initialize_list (); | |||
dataLine = (char *)g_malloc (MAX_LINE_SIZE); | dataLine = (char *)g_malloc (MAX_LINE_SIZE); | |||
while (!finished) { | /* read and parse lines from the file one by one */ | |||
/* read the line in from the file */ | while (!feof (usbFile) | |||
fgets (dataLine, MAX_LINE_SIZE-1, usbFile); | && fgets (dataLine, MAX_LINE_SIZE-1, usbFile) != NULL | |||
&& dataLine[strlen(dataLine)-1] == '\n') { | ||||
if (dataLine[strlen(dataLine)-1] == '\n') | usb_parse_line (dataLine); | |||
usb_parse_line (dataLine); | ||||
if (feof (usbFile)) | ||||
finished = 1; | ||||
} | } | |||
fclose (usbFile); | fclose (usbFile); | |||
g_free (dataLine); | g_free (dataLine); | |||
usb_name_devices (); | usb_name_devices (); | |||
/* build our tree */ | /* build our tree */ | |||
for (i = 0; i < rootDevice->maxChildren; ++i) { | for (i = 0; i < rootDevice->maxChildren; ++i) { | |||
DisplayDevice (rootDevice, rootDevice->child[i]); | DisplayDevice (rootDevice, rootDevice->child[i]); | |||
End of changes. 7 change blocks. | ||||
30 lines changed or deleted | 24 lines changed or added |