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

📄 utils.c

📁 linux下可以连接并查看交换机当前运行情况的东东
💻 C
字号:
/* gwcc/src/utils.c * * Copyright (C) 2000, 2001, 2002 by Brent D. Ely * * 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.  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. */#ifdef HAVE_CONFIG_H#  include <config.h>#endif/*--- Include Libraries ---*/#include <gtk/gtk.h>#include <gnome.h>#include "interface.h"#include "support.h"#include "utils.h"/*--- Global Variables ---*/char timestamp_str[80];   // Global Preference Variables   extern int  file_save_flag;   extern int  timestamp_saved_file;   extern int  toolbar_setting_int;   extern GtkWidget * app1;              // The Main Application Window   extern GtkWidget * dialog_save_as;    // Dialog  - "Save As..."   extern GtkWidget * dialog_print;      // Dialog  - "Print"// ------------------------------------------------------------------------- //// -------------------->      Timestamp Function     <---------------------- //// ------------------------------------------------------------------------- //char *get_timestamp (){    // Declare local variables    time_t      rawtime;    struct tm * timeinfo;    time(&rawtime);    timeinfo = localtime(&rawtime);    sprintf(timestamp_str, "\n--> %s", asctime(timeinfo));    return timestamp_str;}// ------------------------------------------------------------------------- //// --------------------->      Set Toolbar Style     <---------------------- //// ------------------------------------------------------------------------- //voidset_current_toolbar_style (gpointer user_data) {    // Get pointers to window widgets and declare local variables.    GtkWidget * toolbar1 = lookup_widget(app1, "toolbar1");    GtkWidget * dock1    = lookup_widget(app1, "dock1");    // Apply Toolbar Settings to Main Application Window    if (toolbar_setting_int == 0) {        gtk_toolbar_set_style(GTK_TOOLBAR(toolbar1), GTK_TOOLBAR_BOTH);    }    else if (toolbar_setting_int == 1) {        gtk_toolbar_set_style(GTK_TOOLBAR(toolbar1), GTK_TOOLBAR_ICONS);    }    else if (toolbar_setting_int == 2) {        gtk_toolbar_set_style(GTK_TOOLBAR(toolbar1), GTK_TOOLBAR_TEXT);    }    // Need to resize the GtkToolbar after toolbar changes    gtk_widget_queue_resize(GTK_WIDGET(dock1));}// ------------------------------------------------------------------------- //// -------------------->    File Saving Function    <----------------------- //// ------------------------------------------------------------------------- //intperform_file_save (char *operation, gpointer user_data){    // Get pointers to window widgets and declare local variables.    GtkWidget * notebook1         = lookup_widget(app1, "notebook1");    GtkWidget * text_wsutils      = lookup_widget(app1, "text_wsutils");    GtkWidget * text_grep         = lookup_widget(app1, "text_grep");    GtkWidget * text_network      = lookup_widget(app1, "text_network");    FILE      * save_file_ptr;    FILE      * pipein_fp;    gchar       cmdline[80];    gchar     * save_string       = "";    gchar     * textbox_text      = "";    char      * env_homedir       = "";    char      * fopen_flag        = "";    char        file_name[80]     = "";    char        timestamp_str[80] = "";    char        readbuf[80]       = "";    int         notebook_page_num = 0;    int         fileseq_increment = 0;//    time_t      rawtime;//    struct tm * timeinfo;    // Get users $HOME directory    env_homedir = getenv("HOME");    // Set file_name var based on "Save", or "Save As...", or "temp" instruction    if (strcmp(operation, "saveas") == 0) {        // Read location/filename from "Save As..." Dialog        save_string = gtk_file_selection_get_filename(GTK_FILE_SELECTION(user_data));        // Close "Save As..." Dialog        gtk_widget_destroy(GTK_WIDGET(user_data));        strncpy(file_name, save_string, strlen(save_string));        // NOTE: If GNOME file select dialog is in /foo/bar, and user just hits <RETUNRN>        // (no text), then save_string will be "/foo/bar/" - thus we check for '/' below.        if (file_name[strlen(file_name)-1] == '/') {            return(-2);        }    }    else if (strcmp(operation, "home") == 0) {        if (env_homedir == NULL) {            strcpy(env_homedir, "/tmp");        }        strcpy(file_name, env_homedir);        strcat(file_name, "/gwcc_out01.txt");    }    else if (strcmp(operation, "temp") == 0) {        // BRENT! - 10/01 - this needs to be made multi-user/session safe,        // use something like "gwcc_<timestamp>.txt instead!        // NOTE: the on_button_print_okay_clicked() function expects the name below!        strcat(file_name, "/tmp/gwcc_out.txt");    }    // Get the number (int) of current notebook page (0...n-1),    // then pick appropriate textbox to 'Select All' text from.    notebook_page_num = gtk_notebook_get_current_page((GtkNotebook*)notebook1);    if (notebook_page_num == 0) {        textbox_text = gtk_editable_get_chars((GtkEditable*)text_wsutils, 0, -1);    }    else if (notebook_page_num == 1) {        textbox_text = gtk_editable_get_chars((GtkEditable*)text_grep,    0, -1);    }    else if (notebook_page_num == 2) {        textbox_text = gtk_editable_get_chars((GtkEditable*)text_network, 0, -1);    }    // PREFS: File Saving Options (Overwrite/Append/Sequence)    if (file_save_flag == 0) {        fopen_flag = "w";    }    else if (file_save_flag == 1) {        fopen_flag = "a";    }    else if (file_save_flag == 2) {        fopen_flag = "w";        // Get current sequence number        sprintf(cmdline, "ls %s/gwcc_out??.txt | awk '{print substr($0,%d,2)}' | tail -l",                         env_homedir, strlen(env_homedir)+10);        if ((pipein_fp = popen(cmdline, "r")) == NULL) { perror("popen"); exit(1); }        while (fgets(readbuf, 80, pipein_fp) != NULL) {        }        pclose(pipein_fp);        fileseq_increment = atoi(readbuf);        // Compose new file_name using incremented sequence value        if (fileseq_increment == 0) {            strcpy(file_name, env_homedir);            sprintf(file_name, "%s/gwcc_out01.txt", env_homedir);        }        else if (fileseq_increment <= 8) {            fileseq_increment += 1;            sprintf(file_name, "%s/gwcc_out0%d.txt", env_homedir, fileseq_increment);        }        else {            fileseq_increment += 1;            // Prevent sequential value > 99 .. Cheap Way Out(tm)            if (fileseq_increment > 99) { fileseq_increment = 99; }            sprintf(file_name, "%s/gwcc_out%d.txt", env_homedir, fileseq_increment);        }    }    // Save file to users choice of location/filename    if (strlen(textbox_text) > 0) {        save_file_ptr = fopen(file_name, fopen_flag);        if (save_file_ptr != NULL) {            fputs(textbox_text, save_file_ptr);            // PREFS: Timestamp File (T/F)            if (timestamp_saved_file) {                fputs("---------------------------- \n", save_file_ptr);                strcpy(timestamp_str, get_timestamp());                fputs(timestamp_str, save_file_ptr);                fputs("============================ \n", save_file_ptr);            }        }        fclose(save_file_ptr);    }    else {        return(-1);    }    // We're Done, return 0 (success)    return(0);}

⌨️ 快捷键说明

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