📄 xfilter.c
字号:
/**** xfilter.c ****//*********************************************************************** Copyright (c) 1991, 1992 Iris Computing Laboratories.** This software is provided for demonstration purposes only. As* freely-distributed, modifiable source code, this software carries* absolutely no warranty. Iris Computing Laboratories disclaims* all warranties for this software, including any implied warranties* of merchantability and fitness, and shall not be liable for* damages of any type resulting from its use.* Permission to use, copy, modify, and distribute this source code* for any purpose and without fee is hereby granted, provided that* the above copyright and this permission notice appear in all copies* and supporting documentation, and provided that Iris Computing* Laboratories not be named in advertising or publicity pertaining* to the redistribution of this software without specific, written* prior permission.**********************************************************************//********************************************************************`xfilter' implements a simple UNIX filter application where inputand output are X-related data repositories. It is composed of thefollowing modules: `xfilter.c' -- widget creation for the top-level interface, plus callbacks and support functions. `xfilter.sel.c' -- the ICCCM-based selection and filter routines. `xfilter.hlp.t' -- a module for providing help system text. `help.c' -- a generalized help system. `motif.c' -- OSF/Motif miscellaneous functions.See these modules for more details.`xfilter' allows you to specify an X-related source and targetfor traditional UNIX filter operations such as `grep', `sed',`spell', `tr', etc. Rather than choose the filter from a menu,`xfilter' asks you to type the filter's name into the text-editwindow labeled "Filter:". This approach is more general in boththe range of filters that you can use and the potential forspecifying options. If the filter area is null/empty, a simpledata exchange is performed from the input area to the output area.Although `xfilter' includes support for files, it makes no effortto optimize file-related special conditions. All file-relatedoperations take place via temporary storage in dynamic memory.`xfilter' is NOT a GUI alternative to cp(1) for copying files.********************************************************************//*NOTE: The XmNmargin{Width,Height} resources that are hard-codedbelow could be moved to a resource file, or included in thefallback resources, but it's unlikely that anyone would everwant to change them.*/#include "xfilter.h"#include "xfilter.sel.h"#include "help.h"#include "motif.h"#include "xfilter.hlp.t" /* the help text *//*Private functions:*/static void print_help_info();static void initialize_shell_icons();static void handle_close_buttons();static void create_main_window();static Widget create_menu_bar();static void create_dialogs();static void dispatch_filter_operation();/*Private callbacks:*/static void Dismiss(), FileDismiss(), Filter(), SetFile();static void SetInputOption(), SetOutputOption();static void OverwriteOK(), OverwriteCancel();static void Close(), UnmanageWindow(), UnmapWindow();/*Private globals:*/static Pixmap icon_pixmap;static int input_type = xfilter_PRIMARY;static int output_type = xfilter_TEXTWIN;static Widget topLevel, fileShell, messageDialog, overwriteDialog;static Widget filterText, textWindowText, fileInputText, fileOutputText;static String fallback_resources[] = {/* "*optionBox.marginWidth: 5", "*filterBox.marginWidth: 5", "*filterBox.marginHeight: 5", "*inputOption.marginWidth: 0", "*fileDismissButton.marginWidth: 0",*******/ "*textWindowText.rows: 8", "*textWindowText.columns: 60", NULL};/*Public globals (shared with `xfilter.sel.c'):*/XmStringCharSet char_set = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;/*main() creates a main top-level window, plus secondary windows forspecifying filenames, pop-up dialogs, etc., by calling severalsecondary functions.*/void main(argc, argv)int argc;char *argv[];{ XtAppContext app; if (argc == 2 && strcmp(argv[1], "-help") == 0) { print_help_info(); exit(0); } topLevel = XtAppInitialize(&app, xfilter_APP_CLASS, (XrmOptionDescList) NULL, 0, &argc, argv, fallback_resources, (ArgList) NULL, 0); create_main_window(); create_dialogs(); help_create_dialog(topLevel, xfilter_APP_CLASS, xfilter_help_rows, xfilter_help_columns, char_set); initialize_shell_icons(); XtRealizeWidget(topLevel); XtRealizeWidget(fileShell); help_realize(); initialize_selection_structures(topLevel); handle_close_buttons();#ifdef SCREEN_SHOT while (True) { XEvent event; XtAppNextEvent(app, &event); if (event.type == ButtonPress && event.xbutton.button == 2) { XUngrabPointer(XtDisplay(topLevel), CurrentTime); XUngrabKeyboard(XtDisplay(topLevel), CurrentTime); } XtDispatchEvent(&event); }#else XtAppMainLoop(app);#endif} /* main *//*Private callback functions:*//*Dismiss() terminates the application after freeing dynamic resources.*//*ARGSUSED*/static void Dismiss(w, client_data, call_data)Widget w;XtPointer client_data;XtPointer call_data;{ free_selection_structures(); XFreePixmap(XtDisplay(w), icon_pixmap); exit(0);} /* Dismiss *//*Close(), at present, is similar to Dismiss().*//*ARGSUSED*/static void Close(w, client_data, call_data)Widget w;XtPointer client_data;XtPointer call_data;{ free_selection_structures(); XFreePixmap(XtDisplay(topLevel), icon_pixmap); exit(0);} /* Close *//*FileDismiss() simply removes the dialog box for filename entry.*//*ARGSUSED*/static void FileDismiss(w, client_data, call_data)Widget w;XtPointer client_data;XtPointer call_data;{ XtPopdown(fileShell);/* XtUnmapWidget(fileShell); ** for XtAppCreateShell() **/} /* FileDismiss *//*Filter() simply calls the top-level dispatcher.*//*ARGSUSED*/static void Filter(w, client_data, call_data)Widget w;XtPointer client_data;XmAnyCallbackStruct *call_data;{ if (output_type == xfilter_FILE) { char *file_spec = XmTextGetString(fileOutputText); if (!*file_spec) user_message("No output file specified."); else if (file_size(file_spec) != -1) XtManageChild(overwriteDialog); else dispatch_filter_operation(w); XtFree(file_spec); } else dispatch_filter_operation(w);} /* Filter *//*SetFile() simply maps the dialog box for filename entry.*//*ARGSUSED*/static void SetFile(w, client_data, call_data)Widget w;XtPointer client_data;XtPointer call_data;{ XtPopup(fileShell, XtGrabNone);/* XtMapWidget(fileShell); ** for XtAppCreateShell() **/} /* SetFile *//*SetInputOption() records user selections for input.*//*ARGSUSED*/static void SetInputOption(w, client_data, call_data)Widget w;XtPointer client_data;XtPointer call_data;{ input_type = (int) client_data;} /* SetInputOption *//*SetOutputOption() records user selections for input.*//*ARGSUSED*/static void SetOutputOption(w, client_data, call_data)Widget w;XtPointer client_data;XtPointer call_data;{ output_type = (int) client_data;} /* SetOutputOption *//*OverwriteOK() handles the appropriate action if a userchooses the "OK" button during a "Filter" operationthat leads to the file-overwrite warning.*//*ARGSUSED*/static void OverwriteOK(w, client_data, call_data)Widget w;XtPointer client_data;XmAnyCallbackStruct *call_data;{ dispatch_filter_operation(w);} /* OverwriteOK *//*OverwriteCancel() handles the appropriate action if a userchooses the "Cancel" button during a "Filter" operationthat leads to the file-overwrite warning.*//*ARGSUSED*/static void OverwriteCancel(w, client_data, call_data)Widget w;XtPointer client_data;XtPointer call_data;{ /* do nothing */} /* OverwriteCancel *//*UnmapWindow() provides "Close" button functionality for shells.*//*ARGSUSED*/static void UnmapWindow(w, client_data, call_data)Widget w;XtPointer client_data;XtPointer call_data;{ XtUnmapWidget((Widget) client_data);} /* UnmapWindow *//*UnmanageWindow() provides "Close" button functionality for dialog shells.*//*ARGSUSED*/static void UnmanageWindow(w, client_data, call_data)Widget w;XtPointer client_data;XtPointer call_data;{ XtUnmanageChild((Widget) client_data);} /* UnmanageWindow *//*Public functions:*//*user_message() sets the message dialog box to have thespecified message and then maps the dialog box.*/void user_message(msg)char *msg;{ Arg args[1]; XmString string; string = XmStringCreateLtoR(msg, char_set); XtSetArg(args[0], XmNmessageString, string); XtSetValues(messageDialog, args, 1); XmStringFree(string); XtManageChild(messageDialog);} /* user_message *//*Without further commenting, the following functionsreturn the state of selected variables:*/int get_input_type(){ return input_type;} /* get_input_type */int get_output_type(){ return output_type;} /* get_output_type */Widget get_input_text_widget(){ return fileInputText;} /* get_input_text_widget */Widget get_output_text_widget(){ return fileOutputText;} /* get_output_text_widget */Widget get_filter_text_widget(){ return filterText;} /* get_filter_text_widget */Widget get_text_win_widget(){ return textWindowText;} /* get_text_win_widget *//*Support functions:*//*create_main_window() delegates menu bar creation to subordinateroutines; otherwise, most widgets are created directly.*/static void create_main_window(){ static menu_entry input_menu[] = { {menu_ENTRY, "Primary selection", "inputPrimary", SetInputOption, (XtPointer) xfilter_PRIMARY, NULL, NULL}, {menu_ENTRY, "Cut-buffer 0", "inputCutBuffer", SetInputOption, (XtPointer) xfilter_CUT_BUFFER, NULL, NULL}, {menu_ENTRY, "X clipboard", "inputXClipboard", SetInputOption, (XtPointer) xfilter_XCLIPBOARD, NULL, NULL}, {menu_ENTRY, "From file", "inputFile", SetInputOption, (XtPointer) xfilter_FILE, NULL, NULL}, {menu_END, NULL, NULL, NULL, NULL, NULL, NULL}, }; static menu_entry output_menu[] = { {menu_ENTRY, "Cut-buffer 0", "outputCutBuffer", SetOutputOption, (XtPointer) xfilter_CUT_BUFFER, NULL, NULL}, {menu_ENTRY, "X clipboard", "outputXClipboard", SetOutputOption, (XtPointer) xfilter_XCLIPBOARD, NULL, NULL}, {menu_ENTRY, "Text window", "outputTextWindow", SetOutputOption, (XtPointer) xfilter_TEXTWIN, NULL, NULL}, {menu_ENTRY, "To file", "outputFile", SetOutputOption,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -