📄 main.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 */#ifdef HAVE_CONFIG_H# include <config.h>#endif#define MAIN_SOURCE_FILE#include "commonheader.h"#include "build_table.h"#include "build_tree.h"#include "kudzu-support.h"#include "interface.h"#include "refresh_table.h"#include "refresh_tree.h"#include "support.h"#include "tree.h"// function prototypesvoid do_init();void signal_handler();void init_handler();void quit();// define global variablesgint context_id = 0;gint selected_row = NOT_SELECTED; // global row variableGtkCTree* g_tree = NULL; // global treeGtkWidget* g_window = NULL; // global windowGtkWidget* g_statusbar = NULL; // global status barGtkWidget* g_table = NULL; // global tableGtkCTreeNode* g_node = NULL; // global tree nodepci_tree_node* g_pci_node = NULL; // global pci tree nodeint dev_hpc = 0; // device nodeioctl_data stuff; // structure used in ioctl callsstruct sigaction sact; // signal handler variablestruct sigaction osact; // signal handler variablesem_t critical; // semaphore variablevoid do_init(){ sem_init(&critical, 0, 1); if ((dev_hpc = open("/dev/compaq/cpqphpc", O_RDONLY)) < 0) { fprintf(stderr, "WARNING: Cannot open /dev/compaq/cpqphpc.\n"); fprintf(stderr, " Hot Plug Controller may not be installed.\n"); exit(1); }}void signal_handler(){ message sig_msg; read(dev_hpc, &sig_msg, sizeof(message)); // re-build the tree/table if message id > 0, otherwise refresh the tree/table if (sig_msg.message_id > 0) build_tree_from_slot(g_tree, sig_msg.message_id); else if (sig_msg.message_id < 0) { refresh_tree(g_tree); if (g_node) { gtk_ctree_select(g_tree, g_node); // set focus on selected node build_table(g_table, g_node); } else { gtk_ctree_select(g_tree, root_nodes[(-sig_msg.message_id) - 1]); // set focus on parent refresh_table(g_table, root_nodes[(-sig_msg.message_id) - 1]); } }}void init_handler(){ int rt; sigemptyset(&sact.sa_mask); sigaddset(&sact.sa_mask, SIGIO); sact.sa_handler = (__sighandler_t)signal_handler; sact.sa_flags = 0; if (sigaction(SIGIO, &sact, &osact) < 0) { fprintf( stderr, "SIGIO signal error\n"); } fcntl(dev_hpc, F_SETOWN, getpid()); rt = fcntl(dev_hpc, F_GETFL); fcntl(dev_hpc, F_SETFL, rt | FASYNC);}// exit the applicationvoid quit(){ close(dev_hpc); pciFreeDrivers(); gtk_exit(0);}int main (int argc, char *argv[]){ GtkWidget *window; #ifdef ENABLE_NLS bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR); textdomain (PACKAGE); #endif gnome_init ("cpqphpgui", VERSION, argc, argv); if (pciReadDrivers(NULL) < 0) { fprintf(stderr, "Error reading pcitable!\n"); } do_init(); init_handler(); window = create_window (); // build the tree and table with global structures build_table(g_table, g_node); build_tree(g_tree); gtk_widget_show (window); // connect exit signal gtk_signal_connect (GTK_OBJECT (window), "destroy", GTK_SIGNAL_FUNC (quit), NULL); gtk_main (); return 0;}#undef MAIN_SOURCE_FILE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -