g_ui_gtk.c
来自「Non-Networked File System在几个非网络的(或慢网络的)U」· C语言 代码 · 共 1,262 行 · 第 1/3 页
C
1,262 行
format_function, 0, "dangerous" ) ; gtk_box_pack_start(GTK_BOX(vbox), format_button, 0,0,0) ; /* configure_button = frame_label_button ("Configure NNFS2" , "If you press this button, " "you will be teleported on configuration page.\n" "You can come back here later." , "Configure NNFS2" , configure_function, 0 ) ; gtk_box_pack_start(GTK_BOX(vbox), configure_button, 0,0,0) ; */ gtk_widget_show(table) ; pages[i].table = table ; return(vbox) ;}/* * */GtkWidget *preprocessing_page(int i){ GtkWidget *table ; table = gtk_table_new (4, 10, 0) ; gtk_container_border_width( GTK_CONTAINER(table), 5) ; return(table) ;}/* * */GtkWidget *welcome_page(int i){ GtkWidget *label ; char *c ; c = g_Formatted_Strings("% %", /* the space should be here */ "NNFS: Non-Networked File System.\n" NNFS_VERSION "\n" "Copyright (C) 1995-2002 Thierry EXCOFFIER (exco@ligim.univ-lyon1.fr)\n" "\n" "This program is free software; you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" "the Free Software Foundation; either version 2 of the License, or\n" "(at your option) any later version.\n" "\n" , "This program is distributed in the hope that it will be useful,\n" "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" "GNU General Public License for more details.\n" "\n" "You should have received a copy of the GNU General Public License\n" "along with this program; if not, write to the Free Software\n" "Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA." ) ; label = gtk_label_new(c) ; g_Free(c) ; return(label) ;}/* * *//* * */static gint button_press (GtkWidget *widget, GdkEvent *event){ if (event->type == GDK_BUTTON_PRESS) { GdkEventButton *bevent = (GdkEventButton *) event; gtk_menu_popup (GTK_MENU(widget), NULL, NULL, NULL, NULL, bevent->button, bevent->time); /* Tell calling code that we have handled this event; the buck * stops here. */ return TRUE; } /* Tell calling code that we have not handled this event; pass it on. */ return FALSE;}void set_config_widget(char *named) ;void load_config(/*GtkWidget *widget, */gpointer data){ set_config_widget(data) ;}void realize_text (GtkWidget *text, gpointer data){ gtk_text_freeze (GTK_TEXT (text)); gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, data, -1) ; gtk_text_set_point(GTK_TEXT(text), 0) ; gtk_text_thaw (GTK_TEXT (text));}GtkWidget* create_texts(char *t[10][2]){ GtkWidget *menu, *item ; int k ; menu = gtk_menu_new(); for(k=0;t[k][0][0];k++) { item = gtk_menu_item_new_with_label(t[k][1]); gtk_menu_append(GTK_MENU (menu), item); gtk_widget_show(item); } return(menu) ;}void fill_a_case(GtkWidget *table, GtkWidget *w, int line, int column, const char *tip){ gtk_tooltips_set_tip(tips, w, tip, NULL) ; gtk_table_attach(GTK_TABLE(table), w , column , column+1 , line , line+1 ,(GtkAttachOptions)(GTK_FILL |( (column==7)?GTK_EXPAND:0)) ,VO,0,0 ) ; gtk_object_set_data(GTK_OBJECT(w), "nnfs2_l", (gpointer)line) ; gtk_object_set_data(GTK_OBJECT(w), "nnfs2_c", (gpointer)column) ; gtk_widget_show(w) ;}GtkWidget* output_filter(char *t){ GtkWidget *table ; g_Filter *f, *a ; int i, j, line ; GtkWidget *w, *menu, *label ; char buf[G_LINE_CHUNK] ; guint width4 = 32 ; char *c ; static char *ar[][2] = { {"+", "+"}, {"-", "-"}, {""} } ; char *tmp_t ; char *types[g_Is_Any][2] ; static char *lab[] = { "what", "perm", "+perm", "-perm", "size <", "size >", "File Type", "Regex to compare to the full file name", NULL} ; static g_Type_Of_File tf[] = { g_Is_A_Directory, g_Is_A_Link, g_Is_A_File, g_Is_A_FIFO, g_Is_Any } ; for(i=0;i<sizeof(tf)/sizeof(tf[0]);i++) { types[i][0] = types[i][1] = g_Type_To_String(tf[i]) ; } types[i][0] = "" ; G_MALLOC(tmp_t, strlen(t) + 10) ; sprintf(tmp_t, "%s%s-\n-\n-\n", t, t[strlen(t)-1]=='\n' ? "" : "\n") ; f = g_Compile_Filter(tmp_t) ; g_Free(tmp_t) ; table = gtk_table_new(6,10,0) ; for(i=0;lab[i];i++) { label = gtk_label_new(lab[i]) ; gtk_widget_show(label) ; gtk_table_attach(GTK_TABLE(table), label, i,i+1, 0,1,VO,VO,4,0) ; } for( a=f, line=1 ; a ; a=a->next, line++) { w = gtk_option_menu_new() ; gtk_option_menu_set_menu(GTK_OPTION_MENU(w), create_texts(ar)); gtk_option_menu_set_history(GTK_OPTION_MENU(w), a->what) ; c = g_Formatted_Strings("% %", /* the space should be here */ "The lines are evaluated from first to last. " "On the first line all the files should be saved on medium." "\n" "The '-' indicates that the files verifying the conditions in " "the line should not be saved on medium." "\n" , "The '+' indicates that the files verifying the conditions in " "the line should be saved on medium." "\n" "The same file could be removed by a test on a line but " "reinserted by a following line. In the default configuration, " "executable file bigger than 50Kb are not saved but the next line " "indicates that files named 'configure' should be saved." ) ; fill_a_case(table, w, line, 0, c) ; g_Free(c) ; w = gtk_entry_new() ; if ( a->perm == -1 ) buf[0] = '\0' ; else sprintf(buf, "%04o", a->perm) ; gtk_entry_set_text (GTK_ENTRY (w), buf) ; gtk_widget_set_usize (w, width4, -1) ; gtk_entry_set_max_length(GTK_ENTRY(w),4) ; fill_a_case(table, w, line, 1, "The condition is verified if the file mode is " "exactly equal to the value indicated in octal" ) ; w = gtk_entry_new() ; if ( a->plus_perm != ~0 ) sprintf(buf, "%04o", a->plus_perm) ; else buf[0] = '\0' ; gtk_entry_set_text (GTK_ENTRY (w), buf) ; gtk_widget_set_usize (w, width4, -1) ; gtk_entry_set_max_length(GTK_ENTRY(w),4) ; fill_a_case(table, w, line, 2, "The condition is verified if any bit indicated in octal " "are in the file mode. If you indicate 0111 the file mode " "0100, 0111, 0750 are verified." ) ; w = gtk_entry_new() ; if ( a->minus_perm != 0 ) sprintf(buf, "%04o", a->minus_perm) ; else buf[0] = '\0' ; gtk_entry_set_text (GTK_ENTRY (w), buf) ; gtk_widget_set_usize (w, width4, -1) ; gtk_entry_set_max_length(GTK_ENTRY(w),4) ; fill_a_case(table, w, line, 3, "The condition is verified if all the bits indicated " "in octal are in the file mode. If you indicate 0111 " "the file mode 0755 is verified but not 0750." ) ; w = gtk_entry_new() ; if ( a->t_minus_size ) sprintf(buf, "%s", a->t_minus_size) ; else buf[0] = '\0' ; gtk_entry_set_text (GTK_ENTRY (w), buf) ; gtk_widget_set_usize (w, width4, -1) ; gtk_entry_set_max_length(GTK_ENTRY(w),5) ; fill_a_case(table, w, line, 4, "The condition is verified if the file size is smaller " "than the size indicated. The prefixes may be 'k' ou 'm' " "to indicate kilo and mega bytes." ) ; w = gtk_entry_new() ; if ( a->t_plus_size ) sprintf(buf, "%s", a->t_plus_size) ; else buf[0] = '\0' ; gtk_entry_set_text (GTK_ENTRY (w), buf) ; gtk_widget_set_usize (w, width4, -1) ; gtk_entry_set_max_length(GTK_ENTRY(w),5) ; fill_a_case(table, w, line, 5, "The condition is verified if the file size is bigger " "than the size indicated. The prefixes may be 'k' ou 'm' " "to indicate kilo and mega bytes." ) ; w = gtk_option_menu_new() ; menu = create_texts(types) ; gtk_option_menu_set_menu(GTK_OPTION_MENU(w), menu); for(j=0; tf[j]!= a->type ; j++) { } gtk_option_menu_set_history(GTK_OPTION_MENU(w), j) ; fill_a_case(table, w, line, 6, "Choose a file type") ; w = gtk_entry_new() ; if ( strcmp(a->regex,".*") != 0 ) sprintf(buf, "%s", a->regex) ; else buf[0] = '\0' ; gtk_widget_set_name(w, "program") ; gtk_entry_set_text (GTK_ENTRY (w), buf) ; gtk_entry_set_position(GTK_ENTRY(w), 0) ; fill_a_case (table, w, line, 7, "The condition is verified if the regular expression is verified.\n" "File names start by ./" ) ; } g_Free_Filter(f) ; return(table) ;}void retrieve_filter_values(GtkWidget *w, char *m[100][8]){ int line, column ; char *s ; line = (int)gtk_object_get_data(GTK_OBJECT(w), "nnfs2_l") ; if ( line < 1 ) return ; column = (int)gtk_object_get_data(GTK_OBJECT(w), "nnfs2_c") ; if ( GTK_IS_EDITABLE(w) ) { s = gtk_editable_get_chars(GTK_EDITABLE(w), 0, -1) ; m[line-1][column] = g_Save_String(s) ; g_free(s) ; return ; } if ( GTK_IS_OPTION_MENU(w) ) { gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), &s) ; m[line-1][column] = g_Save_String(s) ; return ; } g_Printf("Abort\n") ; abort() ;}void retrieve_values(GtkWidget *w, void *unused){ int m ; g_Nnfsrc_Var *v ; int i ; char *s ; m = (int)gtk_object_get_data(GTK_OBJECT(w), "nnfs2") - 1 ; if ( m < 0 ) return ; v = g_Nnfsrc_Var_Table() ; switch( v[m].type ) { case g_Var_Big_String: case g_Var_String: case g_Var_Integer: g_Free(v[m].content) ; s = gtk_editable_get_chars(GTK_EDITABLE(w), 0, -1) ; v[m].content = g_Save_String(s) ; g_free(s) ; break ; case g_Var_Choice: case g_Var_Boolean: g_Free(v[m].content) ; gtk_label_get(GTK_LABEL(GTK_BIN(w)->child), &v[m].content) ; for(i=0; v[m].choices[i][0][0]; i++) if ( strcmp(v[m].choices[i][1], v[m].content) == 0 ) { v[m].content = g_Save_String(v[m].choices[i][0]) ; break ; } if ( v[m].choices[i][0][0] == '\0' ) { abort() ; } break ; case g_Var_Filter: { char *t[100][8] ; int j, n ; char *pc ; memset(t, 0, sizeof(t)) ; gtk_container_foreach (GTK_CONTAINER (w), (GtkCallback) retrieve_filter_values, (gpointer)t); n = 0 ; for(i=0;i<100;i++) for(j=0;j<8;j++) if ( t[i][j] ) { n += strlen(t[i][j]) + 10 ; } G_REALLOC(v[m].content, n) ; pc = v[m].content ; for(i=0;t[i][0];i++) { if ( t[i][1][0]||t[i][2][0]||t[i][3][0]||t[i][4][0]||t[i][5][0] || t[i][7][0] ) { *pc++ = t[i][0][0] ; if ( t[i][1][0] ) pc += sprintf(pc, " perm=%s", t[i][1]) ; if ( t[i][2][0] ) pc += sprintf(pc, " perm=+%s", t[i][2]) ; if ( t[i][3][0] ) pc += sprintf(pc, " perm=-%s", t[i][3]) ; if ( t[i][4][0] ) pc += sprintf(pc, " size=-%s", t[i][4]) ; if ( t[i][5][0] ) pc += sprintf(pc, " size=+%s", t[i][5]) ; switch( g_String_To_Type(t[i][6]) ) { case g_Is_A_Directory:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?