⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 build_table.c

📁 HP PCI热插拔代码GUI HP内部珍贵资料!
💻 C
字号:
/* *    Compaq Hot Plug Controller Graphical User Interface  *    Copyright 2000, 2001 Compaq Computer Corporation *    All rights reserved. * *    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; either version 2 of the License, or *    (at your option) any later version. * *    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, GOOD TITLE or *    NON INFRINGEMENT.  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., 675 Mass Ave, Cambridge, MA 02139, USA. * *    Please send all questions or concerns to linuxhotplug@compaq.com */#include "commonheader.h"#include "build_table.h"#include "style.h"#include "tree.h"#define MAXTABLECOLUMN	2int g_table_size = 0;char g_table_array[MAXTABLEROW * MAXLEN];GtkStyle* g_style_array[MAXTABLEROW][MAXTABLECOLUMN];// build the table based on the data stored in the global table data structure (g_table_array)void build_table(GtkWidget* table, GtkCTreeNode* node){	int i;	char* widgetrow[2]; 	if (node) {		pci_tree_node* p_node = ctree_partner(g_tree, node, slot_based); 		(*(p_node->build_table_data))(table, p_node);	}		gtk_clist_freeze(GTK_CLIST(table));	gtk_clist_set_row_height(GTK_CLIST(table), 30);		gtk_clist_clear(GTK_CLIST(table));	for (i=0; i < g_table_size; i++) {		widgetrow[0] = &(g_table_array[i*MAXLEN]);		widgetrow[1] = &(g_table_array[i*MAXLEN + MAXLEN/4]);		gtk_clist_append(GTK_CLIST(table), widgetrow);		gtk_clist_set_cell_style(GTK_CLIST(table), i, 0, g_style_array[i][0]);		gtk_clist_set_cell_style(GTK_CLIST(table), i, 1, g_style_array[i][1]);		gtk_clist_set_selectable(GTK_CLIST(table), i, FALSE);	}	gtk_clist_thaw(GTK_CLIST(table));}// print information about the busvoid build_table_data_bus_helper(char* table_array, GtkStyle** style_array, pci_tree_node* node, int* table_size){	char* cell;	if (node->type == 0) {		public_slot_info* slot = (public_slot_info*) node->node_info;		public_bus_info* bus = (public_bus_info*) slot->bus;		GdkFont* font1 = gdk_font_load ("-adobe-helvetica-bold-r-normal-*-*-180-*-*-p-*-iso8859-1");		GdkFont* font2 = gdk_font_load ("-adobe-helvetica-medium-r-normal-*-*-140-*-*-p-*-iso8859-1");				cell = &(table_array[(*table_size)*MAXLEN]);		sprintf(cell, "Bus Number:");		style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);				cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);		sprintf(cell, "%d", bus->bus_number);		style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);		(*table_size)++;//		cell = &(table_array[(*table_size)*MAXLEN]);//		sprintf(cell, "Current Speed:");//		style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);////		cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);//		//if (bus->current_speed)//		//	sprintf(cell, "66 MHz");//		//else//		//	sprintf(cell, "No");//		style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);//		(*table_size)++;//		//		cell = &(table_array[(*table_size)*MAXLEN]);//		sprintf(cell, "Supported Speed:");//		style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);////		cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);//		//if (bus->current_speed)//			sprintf(cell, "66 MHz");//		//else//		//	sprintf(cell, "No");//		style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);//		(*table_size)++;	}}// print information about the slotvoid build_table_data_slot_helper(char* table_array, GtkStyle** style_array, pci_tree_node* node, int* table_size){	char* cell;	if (node->type == 0) {	// slot		public_slot_info* slot = (public_slot_info*) node->node_info;		GdkFont* font1 = gdk_font_load ("-adobe-helvetica-bold-r-normal-*-*-180-*-*-p-*-iso8859-1");		GdkFont* font2 = gdk_font_load ("-adobe-helvetica-medium-r-normal-*-*-140-*-*-p-*-iso8859-1");		// slot number				cell = &(table_array[(*table_size)*MAXLEN]);		sprintf(cell, "Slot:");		style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);		cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);		sprintf(cell, "%d", slot->slot_number);		style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);		(*table_size)++;				// hotpluggable?				cell = &(table_array[(*table_size)*MAXLEN]);		sprintf(cell, "HotPluggable:");		style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);		cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);		if (slot->is_hotpluggable)			sprintf(cell, "Yes");		else			sprintf(cell, "No");		style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);		(*table_size)++;		// power status				cell = &(table_array[(*table_size)*MAXLEN]);		sprintf(cell, "Power:");		style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);		cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);		if (slot->power)			sprintf(cell, "On");		else			sprintf(cell, "Off");		style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);		(*table_size)++;		if (slot->is_hotpluggable) 		{			// attention status			cell = &(table_array[(*table_size)*MAXLEN]);			sprintf(cell, "Attention Status:");			style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);				cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);			if (slot->attention_status)				sprintf(cell, "On");			else				sprintf(cell, "Off");			style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);			(*table_size)++;			// latch status			cell = &(table_array[(*table_size)*MAXLEN]);			sprintf(cell, "Latch Status:");			style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);				cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);			if (slot->latch_status)				sprintf(cell, "Closed");			else				sprintf(cell, "Open");			style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);			(*table_size)++;		}		// adapter presence		cell = &(table_array[(*table_size)*MAXLEN]);		sprintf(cell, "Adapter Present:");		style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);		cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);		if (slot->adapter_presence)			sprintf(cell, "Yes");		else			sprintf(cell, "No");		style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);		(*table_size)++;		// 32/64 bit mode		cell = &(table_array[(*table_size)*MAXLEN]);		sprintf(cell, "Bit mode:");		style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);		cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);		if (slot->bit_mode)			sprintf(cell, "64-bit");		else			sprintf(cell, "32-bit");		style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);		(*table_size)++;	}}// print information about the functionvoid build_table_data_function_helper(char* table_array, GtkStyle** style_array, pci_tree_node* node, int* table_size, int is_adapter){	char* cell;	GdkFont *font1, *font2;	public_function_info* function = NULL;	if (is_adapter) {		public_adapter_info* tmp_adapter = (public_adapter_info*) node->node_info;		function = tmp_adapter->function;	} else {		function = (public_function_info*) node->node_info;	}	if (!function)		return;			font1 = gdk_font_load ("-adobe-helvetica-bold-r-normal-*-*-180-*-*-p-*-iso8859-1");	font2 = gdk_font_load ("-adobe-helvetica-medium-r-normal-*-*-140-*-*-p-*-iso8859-1");		// bridge ?	cell = &(table_array[(*table_size)*MAXLEN]);	sprintf(cell, "Bridge:");	style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);	cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);	if (function->is_bridge)		sprintf(cell, "Yes");	else		sprintf(cell, "No");	style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);	(*table_size)++;	if (!function->is_bridge) { 			// driver loaded ?		cell = &(table_array[(*table_size)*MAXLEN]);		sprintf(cell, "Driver Loaded:");		style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);		cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);		if (function->is_driverloaded)			sprintf(cell, "Yes");		else			sprintf(cell, "No");		style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);		(*table_size)++;	}//	cell = &(table_array[(*table_size)*MAXLEN]);//	sprintf(cell, "Supp. Speed Mode:");//	style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);////	cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);//	if (function->power)//		sprintf(cell, "66 MHz/PCI");//	else//		sprintf(cell, "Off");//	style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);//	(*table_size)++;		if (!function->is_bridge) { 		// device name		cell = &(table_array[(*table_size)*MAXLEN]);		sprintf(cell, "Device Name:");		style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);		cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);		if (function->device_name)			sprintf(cell, function->device_name);		else			sprintf(cell, "unknown");		style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);		(*table_size)++;		// driver name		cell = &(table_array[(*table_size)*MAXLEN]);		sprintf(cell, "Driver Name:");		style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);		cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);		if (function->driver_name)			sprintf(cell, function->driver_name);		else			sprintf(cell, "unknown");		style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);		(*table_size)++;	}	// vendor id	cell = &(table_array[(*table_size)*MAXLEN]);	sprintf(cell, "Vendor ID:");	style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);	cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);	sprintf(cell, "0x%4.4X", function->vendor_id);	style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);	(*table_size)++;	// device id	cell = &(table_array[(*table_size)*MAXLEN]);	sprintf(cell, "Device ID:");	style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);	cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);	sprintf(cell, "0x%4.4X", function->device_id);	style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);	(*table_size)++;	// subsystem vendor id	cell = &(table_array[(*table_size)*MAXLEN]);	sprintf(cell, "Sub. Vendor ID:");	style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);	cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);	sprintf(cell, "0x%4.4X", function->subvendor_id);	style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);	(*table_size)++;	// subsystem id	cell = &(table_array[(*table_size)*MAXLEN]);	sprintf(cell, "Subsystem ID:");	style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);	cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);	sprintf(cell, "0x%4.4X", function->subdevice_id);	style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);	(*table_size)++;	// bus number 	cell = &(table_array[(*table_size)*MAXLEN]);	sprintf(cell, "Bus:");	style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);	cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);	sprintf(cell, "%d", function->bus_number);	style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);	(*table_size)++;	// device number 	cell = &(table_array[(*table_size)*MAXLEN]);	sprintf(cell, "Device:");	style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);	cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);	sprintf(cell, "%d", function->device_number);	style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);	(*table_size)++;	// function number 	cell = &(table_array[(*table_size)*MAXLEN]);	sprintf(cell, "Function:");	style_array[(*table_size)*MAXTABLECOLUMN] = make_style(black, white, font1);	cell = &(table_array[(*table_size)*MAXLEN + MAXLEN/4]);	sprintf(cell, "%d", function->function_number);		style_array[(*table_size)*MAXTABLECOLUMN+1] = make_style(black, white, font2);	(*table_size)++;}// print slot and bus information (since no bus nodes are visible)void build_table_data_from_slot(GtkWidget* table, pci_tree_node* p_node){	g_table_size = 0;		build_table_data_slot_helper((char*) g_table_array, (GtkStyle**) g_style_array, p_node, &g_table_size);	build_table_data_bus_helper((char*) g_table_array, (GtkStyle**) g_style_array, p_node, &g_table_size);}// print adapter information (adapter-specific fields located in the function helper)void build_table_data_from_adapter(GtkWidget* table, pci_tree_node* p_node){	pci_tree_node* tmp_node = p_node;	g_table_size = 0;	// single function wins over bridge 	tmp_node = ctree_partner_ex(g_tree, p_node->node, function_based, 0);	if (tmp_node->type == 2)		build_table_data_function_helper((char*) g_table_array, (GtkStyle**) g_style_array, tmp_node, &g_table_size, 0);	else  // adapter		build_table_data_function_helper((char*) g_table_array, (GtkStyle**) g_style_array, tmp_node, &g_table_size, 1);}// print function informationvoid build_table_data_from_function(GtkWidget* table, pci_tree_node* p_node){	pci_tree_node* tmp_node = p_node;		g_table_size = 0;	tmp_node = ctree_partner_ex(g_tree, p_node->node, function_based, 0);	if (tmp_node->type == 2)		build_table_data_function_helper((char*) g_table_array, (GtkStyle**) g_style_array, tmp_node, &g_table_size, 0);		// need to handle case of nested bridges??	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -