macro.c

来自「nedit 是一款linux下的开发源码的功能强大的编辑器」· C语言 代码 · 共 1,752 行 · 第 1/5 页

C
1,752
字号
static int rangesetAddMS(WindowInfo *window, DataValue *argList, int nArgs,      DataValue *result, char **errMsg);static int rangesetSubtractMS(WindowInfo *window, DataValue *argList, int nArgs,      DataValue *result, char **errMsg);static int rangesetInvertMS(WindowInfo *window, DataValue *argList, int nArgs,      DataValue *result, char **errMsg);static int rangesetInfoMS(WindowInfo *window, DataValue *argList, int nArgs,      DataValue *result, char **errMsg);static int rangesetRangeMS(WindowInfo *window, DataValue *argList, int nArgs,      DataValue *result, char **errMsg);static int rangesetIncludesPosMS(WindowInfo *window, DataValue *argList,      int nArgs, DataValue *result, char **errMsg);static int rangesetSetColorMS(WindowInfo *window, DataValue *argList,      int nArgs, DataValue *result, char **errMsg);static int rangesetSetNameMS(WindowInfo *window, DataValue *argList,      int nArgs, DataValue *result, char **errMsg);static int rangesetSetModeMS(WindowInfo *window, DataValue *argList,      int nArgs, DataValue *result, char **errMsg);static int fillPatternResult(DataValue *result, char **errMsg, WindowInfo *window,        char *patternName, Boolean preallocatedPatternName, Boolean includeName,        char *styleName, int bufferPos);static int getPatternByNameMS(WindowInfo *window, DataValue *argList, int nArgs,        DataValue *result, char **errMsg);static int getPatternAtPosMS(WindowInfo *window, DataValue *argList, int nArgs,        DataValue *result, char **errMsg);static int fillStyleResult(DataValue *result, char **errMsg,        WindowInfo *window, char *styleName, Boolean preallocatedStyleName,        Boolean includeName, int patCode, int bufferPos);static int getStyleByNameMS(WindowInfo *window, DataValue *argList, int nArgs,        DataValue *result, char **errMsg);static int getStyleAtPosMS(WindowInfo *window, DataValue *argList, int nArgs,        DataValue *result, char **errMsg);/* Built-in subroutines and variables for the macro language */static BuiltInSubr MacroSubrs[] = {lengthMS, getRangeMS, tPrintMS,        dialogMS, stringDialogMS, replaceRangeMS, replaceSelectionMS,        setCursorPosMS, getCharacterMS, minMS, maxMS, searchMS,        searchStringMS, substringMS, replaceSubstringMS, readFileMS,        writeFileMS, appendFileMS, beepMS, getSelectionMS, validNumberMS,        replaceInStringMS, selectMS, selectRectangleMS, focusWindowMS,        shellCmdMS, stringToClipboardMS, clipboardToStringMS, toupperMS,        tolowerMS, listDialogMS, getenvMS,        stringCompareMS, splitMS, calltipMS, killCalltipMS,/* DISABLED for 5.4        setBacklightStringMS,*/        rangesetCreateMS, rangesetDestroyMS,        rangesetAddMS, rangesetSubtractMS, rangesetInvertMS,         rangesetInfoMS, rangesetRangeMS, rangesetIncludesPosMS,         rangesetSetColorMS, rangesetSetNameMS, rangesetSetModeMS,        rangesetGetByNameMS,        getPatternByNameMS, getPatternAtPosMS,        getStyleByNameMS, getStyleAtPosMS    };#define N_MACRO_SUBRS (sizeof MacroSubrs/sizeof *MacroSubrs)static const char *MacroSubrNames[N_MACRO_SUBRS] = {"length", "get_range", "t_print",        "dialog", "string_dialog", "replace_range", "replace_selection",        "set_cursor_pos", "get_character", "min", "max", "search",        "search_string", "substring", "replace_substring", "read_file",        "write_file", "append_file", "beep", "get_selection", "valid_number",        "replace_in_string", "select", "select_rectangle", "focus_window",        "shell_command", "string_to_clipboard", "clipboard_to_string",        "toupper", "tolower", "list_dialog", "getenv",        "string_compare", "split", "calltip", "kill_calltip",/* DISABLED for 5.4        "set_backlight_string", */        "rangeset_create", "rangeset_destroy",        "rangeset_add", "rangeset_subtract", "rangeset_invert",         "rangeset_info", "rangeset_range", "rangeset_includes",        "rangeset_set_color", "rangeset_set_name", "rangeset_set_mode",        "rangeset_get_by_name",        "get_pattern_by_name", "get_pattern_at_pos",        "get_style_by_name", "get_style_at_pos"    };static BuiltInSubr SpecialVars[] = {cursorMV, lineMV, columnMV,        fileNameMV, filePathMV, lengthMV, selectionStartMV, selectionEndMV,        selectionLeftMV, selectionRightMV, wrapMarginMV, tabDistMV,        emTabDistMV, useTabsMV, languageModeMV, modifiedMV,        statisticsLineMV, incSearchLineMV, showLineNumbersMV,        autoIndentMV, wrapTextMV, highlightSyntaxMV,        makeBackupCopyMV, incBackupMV, showMatchingMV,        overTypeModeMV, readOnlyMV, lockedMV, fileFormatMV,        fontNameMV, fontNameItalicMV,        fontNameBoldMV, fontNameBoldItalicMV, subscriptSepMV,        minFontWidthMV, maxFontWidthMV, topLineMV, numDisplayLinesMV,        displayWidthMV, activePaneMV, nPanesMV, emptyArrayMV,        serverNameMV, calltipIDMV,/* DISABLED for 5.4        backlightStringMV, */	rangesetListMV    };#define N_SPECIAL_VARS (sizeof SpecialVars/sizeof *SpecialVars)static const char *SpecialVarNames[N_SPECIAL_VARS] = {"$cursor", "$line", "$column",        "$file_name", "$file_path", "$text_length", "$selection_start",        "$selection_end", "$selection_left", "$selection_right",        "$wrap_margin", "$tab_dist", "$em_tab_dist", "$use_tabs",        "$language_mode", "$modified",        "$statistics_line", "$incremental_search_line", "$show_line_numbers",        "$auto_indent", "$wrap_text", "$highlight_syntax",        "$make_backup_copy", "$incremental_backup", "$show_matching",        "$overtype_mode", "$read_only", "$locked", "$file_format",        "$font_name", "$font_name_italic",        "$font_name_bold", "$font_name_bold_italic", "$sub_sep",        "$min_font_width", "$max_font_width", "$top_line", "$n_display_lines",        "$display_width", "$active_pane", "$n_panes", "$empty_array",        "$server_name", "$calltip_ID",/* DISABLED for 5.4       "$backlight_string", */        "$rangeset_list"    };/* Global symbols for returning values from built-in functions */#define N_RETURN_GLOBALS 5enum retGlobalSyms {STRING_DIALOG_BUTTON, SEARCH_END, READ_STATUS,	SHELL_CMD_STATUS, LIST_DIALOG_BUTTON};static const char *ReturnGlobalNames[N_RETURN_GLOBALS] = {"$string_dialog_button",    	"$search_end", "$read_status", "$shell_cmd_status",	"$list_dialog_button"};static Symbol *ReturnGlobals[N_RETURN_GLOBALS];/* List of actions not useful when learning a macro sequence (also see below) */static char* IgnoredActions[] = {"focusIn", "focusOut"};/* List of actions intended to be attached to mouse buttons, which the user   must be warned can't be recorded in a learn/replay sequence */static const char* MouseActions[] = {"grab_focus", "extend_adjust", "extend_start",	"extend_end", "secondary_or_drag_adjust", "secondary_adjust",	"secondary_or_drag_start", "secondary_start", "move_destination",	"move_to", "move_to_or_end_drag", "copy_to", "copy_to_or_end_drag",	"exchange", "process_bdrag", "mouse_pan"};/* List of actions to not record because they    generate further actions, more suitable for recording */static const char* RedundantActions[] = {"open_dialog", "save_as_dialog",    "revert_to_saved_dialog", "include_file_dialog", "load_macro_file_dialog",    "load_tags_file_dialog", "find_dialog", "replace_dialog",    "goto_line_number_dialog", "mark_dialog", "goto_mark_dialog",    "control_code_dialog", "filter_selection_dialog", "execute_command_dialog",    "repeat_dialog", "start_incremental_find"};/* The last command executed (used by the Repeat command) */static char *LastCommand = NULL;/* The current macro to execute on Replay command */static char *ReplayMacro = NULL;/* Buffer where macro commands are recorded in Learn mode */static textBuffer *MacroRecordBuf = NULL;/* Action Hook id for recording actions for Learn mode */static XtActionHookId MacroRecordActionHook = 0;/* Window where macro recording is taking place */static WindowInfo *MacroRecordWindow = NULL;/* Arrays for translating escape characters in escapeStringChars */static char ReplaceChars[] = "\\\"ntbrfav";static char EscapeChars[] = "\\\"\n\t\b\r\f\a\v";/*** Install built-in macro subroutines and special variables for accessing** editor information*/void RegisterMacroSubroutines(void){    static DataValue subrPtr = {NO_TAG, {0}}, noValue = {NO_TAG, {0}};    unsigned i;        /* Install symbols for built-in routines and variables, with pointers       to the appropriate c routines to do the work */    for (i=0; i<N_MACRO_SUBRS; i++) {    	subrPtr.val.subr = MacroSubrs[i];    	InstallSymbol(MacroSubrNames[i], C_FUNCTION_SYM, subrPtr);    }    for (i=0; i<N_SPECIAL_VARS; i++) {    	subrPtr.val.subr = SpecialVars[i];    	InstallSymbol(SpecialVarNames[i], PROC_VALUE_SYM, subrPtr);    }        /* Define global variables used for return values, remember their       locations so they can be set without a LookupSymbol call */    for (i=0; i<N_RETURN_GLOBALS; i++)    	ReturnGlobals[i] = InstallSymbol(ReturnGlobalNames[i], GLOBAL_SYM,    	    	noValue);}#define MAX_LEARN_MSG_LEN ((2 * MAX_ACCEL_LEN) + 60)void BeginLearn(WindowInfo *window){    WindowInfo *win;    XmString s;    XmString xmFinish;    XmString xmCancel;    char *cFinish;    char *cCancel;    char message[MAX_LEARN_MSG_LEN];        /* If we're already in learn mode, return */    if (MacroRecordActionHook != 0)    	return;        /* dim the inappropriate menus and items, and undim finish and cancel */    for (win=WindowList; win!=NULL; win=win->next)	XtSetSensitive(win->learnItem, False);    XtSetSensitive(window->finishLearnItem, True);    XtVaSetValues(window->cancelMacroItem, XmNlabelString,    	    s=XmStringCreateSimple("Cancel Learn"), NULL);    XmStringFree(s);    XtSetSensitive(window->cancelMacroItem, True);        /* Mark the window where learn mode is happening */    MacroRecordWindow = window;        /* Allocate a text buffer for accumulating the macro strings */    MacroRecordBuf = BufCreate();        /* Add the action hook for recording the actions */    MacroRecordActionHook =    	    XtAppAddActionHook(XtWidgetToApplicationContext(window->shell),    	    learnActionHook, window);    /* Extract accelerator texts from menu PushButtons */    XtVaGetValues(window->finishLearnItem, XmNacceleratorText, &xmFinish, NULL);    XtVaGetValues(window->cancelMacroItem, XmNacceleratorText, &xmCancel, NULL);    /* Translate Motif strings to char* */    cFinish = GetXmStringText(xmFinish);    cCancel = GetXmStringText(xmCancel);    /* Free Motif Strings */    XmStringFree(xmFinish);    XmStringFree(xmCancel);    /* Create message */    if (cFinish[0] == '\0') {        if (cCancel[0] == '\0') {            strncpy(message, "Learn Mode -- Use menu to finish or cancel",                MAX_LEARN_MSG_LEN);            message[MAX_LEARN_MSG_LEN - 1] = '\0';        }        else {            sprintf(message,                "Learn Mode -- Use menu to finish, press %s to cancel",                cCancel);        }    }    else {        if (cCancel[0] == '\0') {            sprintf(message,                "Learn Mode -- Press %s to finish, use menu to cancel",                cFinish);        }        else {            sprintf(message,                "Learn Mode -- Press %s to finish, %s to cancel",                cFinish,                cCancel);        }    }    /* Free C-strings */    XtFree(cFinish);    XtFree(cCancel);    /* Put up the learn-mode banner */    SetModeMessage(window, message);    }void AddLastCommandActionHook(XtAppContext context){    XtAppAddActionHook(context, lastActionHook, NULL);}void FinishLearn(void){    WindowInfo *win;        /* If we're not in learn mode, return */    if (MacroRecordActionHook == 0)    	return;        /* Remove the action hook */    XtRemoveActionHook(MacroRecordActionHook);    MacroRecordActionHook = 0;        /* Free the old learn/replay sequence */    if (ReplayMacro != NULL)    	XtFree(ReplayMacro);        /* Store the finished action for the replay menu item */    ReplayMacro = BufGetAll(MacroRecordBuf);        /* Free the buffer used to accumulate the macro sequence */    BufFree(MacroRecordBuf);        /* Undim the menu items dimmed during learn */    for (win=WindowList; win!=NULL; win=win->next)	XtSetSensitive(win->learnItem, True);    XtSetSensitive(MacroRecordWindow->finishLearnItem, False);    XtSetSensitive(MacroRecordWindow->cancelMacroItem, False);        /* Undim the replay and paste-macro buttons */    for (win=WindowList; win!=NULL; win=win->next)    	XtSetSensitive(win->replayItem, True);    DimPasteReplayBtns(True);        /* Clear learn-mode banner */    ClearModeMessage(MacroRecordWindow);}/*** Cancel Learn mode, or macro execution (they're bound to the same menu item)*/void CancelMacroOrLearn(WindowInfo *window){    if (MacroRecordActionHook != 0)    	cancelLearn();    else if (window->macroCmdData != NULL)    	AbortMacroCommand(window);}static void cancelLearn(void){    WindowInfo *win;        /* If we're not in learn mode, return */    if (MacroRecordActionHook == 0)    	return;    /* Remove the action hook */    XtRemoveActionHook(MacroRecordActionHook);    MacroRecordActionHook = 0;        /* Free the macro under construction */    BufFree(MacroRecordBuf);        /* Undim the menu items dimmed during learn */    for (win=WindowList; win!=NULL; win=win->next)	XtSetSensitive(win->learnItem, True);    XtSetSensitive(MacroRecordWindow->finishLearnItem, False);    XtSetSensitive(MacroRecordWindow->cancelMacroItem, False);        /* Clear learn-mode banner */    ClearModeMessage(MacroRecordWindow);}/*** Execute the learn/replay sequence stored in "window"*/void Replay(WindowInfo *window){    Program *prog;    char *errMsg, *stoppedAt;

⌨️ 快捷键说明

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