re-fresh
[nedit-bw.git] / macro_backtrace.patch
blob37252e1294faf80ae6231cb8038fee4b624790fb
1 ---
3 source/built-ins.h | 1
4 source/highlightData.c | 2
5 source/interpret.c | 118 ++++++++++++++++++++++++++++++++++++++++---------
6 source/interpret.h | 2
7 source/macro.c | 6 ++
8 5 files changed, 107 insertions(+), 22 deletions(-)
10 diff --quilt old/source/interpret.c new/source/interpret.c
11 --- old/source/interpret.c
12 +++ new/source/interpret.c
13 @@ -85,6 +85,7 @@ static RestartData *setContext(RestartDa
14 static int returnValOrNone(int valOnStack);
15 static int branchIf(Boolean trueOrFalse);
16 static int namedArg1orN(Boolean isFirst);
17 +static int getArgArray(DataValue *fp, DataValue **argArray, char **errMsg);
19 static int callSubroutineFromSymbol(Symbol *sym, int nArgs);
20 static int concatenateNwithSep(int nVals, const char *sep, char **result,
21 @@ -1617,32 +1618,16 @@ static int pushArgCount(void)
23 static int pushArgArray(void)
25 - int nArgs, argNum;
26 - DataValue argVal, *argArray;
27 - Boolean needArgCopy = False;
28 + DataValue *argArray;
29 + char *errMsg;
31 STACKDUMP(0, 3);
33 - nArgs = FP_GET_ARG_COUNT(FrameP);
34 - argArray = &FP_GET_ARG_ARRAY(FrameP);
35 - if (argArray->tag != ARRAY_TAG) {
36 - /* we require a real array in the argArray position */
37 - argArray->tag = ARRAY_TAG;
38 - argArray->val.arrayPtr = ArrayNew();
39 - needArgCopy = True;
40 - }
41 + if (!getArgArray(FrameP, &argArray, &errMsg))
42 + EXEC_ERROR(errMsg, NULL);
44 - if (needArgCopy || (nArgs && !ArrayGet(argArray, (char *)"1", &argVal))) {
45 - /* load arguments from positional arg list if not already done */
46 - for (argNum = 0; argNum < nArgs; ++argNum) {
47 - argVal = FP_GET_ARG_N(FrameP, argNum);
48 - if (!ArrayInsert(argArray, AllocStringOfNumber(argNum + 1),
49 - &argVal)) {
50 - EXEC_ERROR("argument array insertion failure", NULL);
51 - }
52 - }
53 - }
54 PUSH(*argArray);
56 return STAT_OK;
59 @@ -5137,3 +5122,94 @@ static void stackdump(RestartData *conte
61 #endif /* ifdef DEBUG_STACK */
63 +static int getArgArray(DataValue *fp, DataValue **argArray, char **errMsg)
65 + int nArgs, argNum;
66 + DataValue argVal;
67 + Boolean needArgCopy = False;
69 + nArgs = FP_GET_ARG_COUNT(fp);
70 + *argArray = &FP_GET_ARG_ARRAY(fp);
71 + if ((*argArray)->tag != ARRAY_TAG) {
72 + /* we require a real array in the argArray position */
73 + (*argArray)->tag = ARRAY_TAG;
74 + (*argArray)->val.arrayPtr = ArrayNew();
75 + needArgCopy = True;
76 + }
78 + if (needArgCopy || (nArgs && !ArrayGet(*argArray, (char *)"1", &argVal))) {
79 + /* load arguments from positional arg list if not already done */
80 + for (argNum = 0; argNum < nArgs; ++argNum) {
81 + argVal = FP_GET_ARG_N(fp, argNum);
82 + if (!ArrayInsert(*argArray, AllocStringOfNumber(argNum + 1),
83 + &argVal)) {
84 + *errMsg = "argument array insertion failure";
85 + return False;
86 + }
87 + }
88 + }
89 + return True;
92 +int GetBacktrace(DataValue *bt, char **errMsg)
94 + DataValue *fp = FrameP;
95 + Inst *pc;
96 + int i = 0;
98 + bt->tag = ARRAY_TAG;
99 + bt->val.arrayPtr = ArrayNew();
101 + do {
102 + int nArgs = FP_GET_ARG_COUNT(fp);
103 + DataValue btVal;
104 + DataValue valueVal = {NO_TAG, {0}};
105 + DataValue *argArray;
107 + btVal.tag = ARRAY_TAG;
108 + btVal.val.arrayPtr = ArrayNew();
110 + valueVal.tag = STRING_TAG;
111 + if (!AllocNStringNCpy(&valueVal.val.str,
112 + FP_GET_NAME(fp).rep, FP_GET_NAME(fp).len)) {
113 + *errMsg = "backtrace array insertion failure";
114 + return False;
116 + if (!ArrayInsert(&btVal, PERM_ALLOC_STR("name"), &valueVal)) {
117 + *errMsg = "backtrace array insertion failure";
118 + return False;
121 + valueVal.tag = INT_TAG;
122 + valueVal.val.n = nArgs;
123 + if (!ArrayInsert(&btVal, PERM_ALLOC_STR("n_args"), &valueVal)) {
124 + *errMsg = "backtrace array insertion failure";
125 + return False;
128 + if (!getArgArray(fp, &argArray, errMsg)) {
129 + return False;
131 + if (STAT_OK != ArrayCopy(&valueVal, argArray)) {
132 + *errMsg = "backtrace array copy failure";
133 + return False;
135 + if (!ArrayInsert(&btVal, PERM_ALLOC_STR("args"), &valueVal)) {
136 + *errMsg = "backtrace array insertion failure";
137 + return False;
140 + /* future: add source code location information */
142 + if (!ArrayInsert(bt, AllocStringOfNumber(i), &btVal)) {
143 + *errMsg = "backtrace array insertion failure";
144 + return False;
147 + pc = FP_GET_RET_PC(fp);
148 + fp = FP_GET_OLD_FP(fp);
149 + i++;
150 + } while (pc);
152 + return True;
154 diff --quilt old/source/interpret.h new/source/interpret.h
155 --- old/source/interpret.h
156 +++ new/source/interpret.h
157 @@ -220,5 +220,7 @@ int StringToNumEnd(const char *string, c
158 const char *longAsStr(long val);
159 int lenLongAsStr(long val);
161 +int GetBacktrace(DataValue *bt, char **errMsg);
163 #endif /* NEDIT_INTERPRET_H_INCLUDED */
165 diff --quilt old/source/macro.c new/source/macro.c
166 --- old/source/macro.c
167 +++ new/source/macro.c
168 @@ -7210,6 +7210,12 @@ static int toColumnMS(WindowInfo *window
169 return True;
172 +static int macroBacktraceMV(WindowInfo *window, DataValue *argList,
173 + int nArgs, DataValue *result, char **errMsg)
175 + return GetBacktrace(result, errMsg);
178 static int wrongNArgsErr(char **errMsg)
180 *errMsg = "Wrong number of arguments to function %s";
181 diff --quilt old/source/built-ins.h new/source/built-ins.h
182 --- old/source/built-ins.h
183 +++ new/source/built-ins.h
184 @@ -133,3 +133,4 @@ MV(rangeset_list, rangesetList)
185 MV(VERSION, version)
186 MV(NEDIT_HOME, neditHome)
187 MV(transient, transient)
188 +MV(macro_backtrace, macroBacktrace)
189 diff --quilt old/source/highlightData.c new/source/highlightData.c
190 --- old/source/highlightData.c
191 +++ new/source/highlightData.c
192 @@ -553,7 +553,7 @@ static char *DefaultPatternSets[] = {
193 Comment:\"#\":\"$\"::Comment::\n\
194 Built-in Misc Vars:\"(?<!\\Y)\\$(?:active_pane|calltip_ID|column|cursor|display_width|empty_array|file_name|file_path|language_mode|line|locked|max_font_width|min_font_width|modified|n_display_lines|n_panes|rangeset_list|read_only|selection_(?:start|end|left|right)|server_name|text_length|top_line|transient|VERSION|NEDIT_HOME)>\":::Identifier::\n\
195 Built-in Pref Vars:\"(?<!\\Y)\\$(?:auto_indent|em_tab_dist|file_format|font_name|font_name_bold|font_name_bold_italic|font_name_italic|highlight_syntax|incremental_backup|incremental_search_line|make_backup_copy|match_syntax_based|overtype_mode|show_line_numbers|show_matching|statistics_line|tab_dist|use_tabs|wrap_margin|wrap_text)>\":::Identifier2::\n\
196 - Built-in Special Vars:\"(?<!\\Y)\\$(?:args|[1-9]|list_dialog_button|macro_name|n_args|read_status|search_end|shell_cmd_status|string_dialog_button|sub_sep)>\":::String1::\n\
197 + Built-in Special Vars:\"(?<!\\Y)\\$(?:args|[1-9]|list_dialog_button|macro_name|n_args|read_status|search_end|shell_cmd_status|string_dialog_button|sub_sep|macro_backtrace)>\":::String1::\n\
198 Built-in Subrs:\"<(?:args|append_file|beep|call|calltip|clipboard_to_string|define|dialog|eval|filename_dialog|dict_(?:insert|complete|save|append|is_element)|e_print|escape_literal|focus_window|get_character|get_matching|get_pattern_(by_name|at_pos)|get_range|get_selection|get_style_(by_name|at_pos)|getenv|highlight_calltip_line|kill_calltip|length|list_dialog|max|min|n_args|rangeset_(?:add|create|destroy|get_by_name|includes|info|invert|range|set_color|set_mode|set_name|subtract)|read_file|replace_in_string|replace_range|replace_selection|replace_substring|search|search_string|select|select_rectangle|set_cursor_pos|set_transient|set_window_title|shell_command|split|string_compare|string_dialog|string_to_clipboard|substring|t_print|timer_(?:add|remove)|to_(?:column|line|pos)|tolower|toupper|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
199 Menu Actions:\"<(?:new(?:_tab|_opposite)?|open|open-dialog|open_dialog|open-selected|open_selected|close|save|save-as|save_as|save-as-dialog|save_as_dialog|revert-to-saved|revert_to_saved|revert_to_saved_dialog|include-file|include_file|include-file-dialog|include_file_dialog|load-macro-file|load_macro_file|load-macro-file-dialog|load_macro_file_dialog|load-tags-file|load_tags_file|load-tags-file-dialog|load_tags_file_dialog|unload_tags_file|load_tips_file|load_tips_file_dialog|unload_tips_file|print|print-selection|print_selection|exit|undo|redo|delete|select-all|select_all|shift-left|shift_left|shift-left-by-tab|shift_left_by_tab|shift-right|shift_right|shift-right-by-tab|shift_right_by_tab|find|find-dialog|find_dialog|find-again|find_again|find-selection|find_selection|find_incremental|start_incremental_find|replace|replace-dialog|replace_dialog|replace-all|replace_all|replace-in-selection|replace_in_selection|replace-again|replace_again|replace_find|replace_find_same|replace_find_again|goto-line-number|goto_line_number|goto-line-number-dialog|goto_line_number_dialog|goto-selected|goto_selected|mark|mark-dialog|mark_dialog|goto-mark|goto_mark|goto-mark-dialog|goto_mark_dialog|match|select_to_matching|goto_matching|find-definition|find_definition|show_tip|split-pane|split_pane|close-pane|close_pane|detach_document(?:_dialog)?|move_document_dialog|(?:next|previous|last)_document|uppercase|lowercase|fill-paragraph|fill_paragraph|control-code-dialog|control_code_dialog|filter-selection-dialog|filter_selection_dialog|filter-selection|filter_selection|execute-command|execute_command|execute-command-dialog|execute_command_dialog|execute-command-line|execute_command_line|shell-menu-command|shell_menu_command|macro-menu-command|macro_menu_command|bg_menu_command|post_window_bg_menu|post_tab_context_menu|beginning-of-selection|beginning_of_selection|end-of-selection|end_of_selection|repeat_macro|repeat_dialog|raise_window|focus_pane|set_statistics_line|set_incremental_search_line|set_show_line_numbers|set_auto_indent|set_wrap_text|set_wrap_margin|set_highlight_syntax|set_make_backup_copy|set_incremental_backup|set_show_matching|set_match_syntax_based|set_overtype_mode|set_locked|set_tab_dist|set_em_tab_dist|set_use_tabs|set_fonts|set_language_mode)(?=\\s*\\()\":::Subroutine::\n\
200 Text Actions:\"<(?:self-insert|self_insert|grab-focus|grab_focus|extend-adjust|extend_adjust|extend-start|extend_start|extend-end|extend_end|secondary-adjust|secondary_adjust|secondary-or-drag-adjust|secondary_or_drag_adjust|secondary-start|secondary_start|secondary-or-drag-start|secondary_or_drag_start|process-bdrag|process_bdrag|move-destination|move_destination|move-to|move_to|move-to-or-end-drag|move_to_or_end_drag|end_drag|copy-to|copy_to|copy-to-or-end-drag|copy_to_or_end_drag|exchange|process-cancel|process_cancel|paste-clipboard|paste_clipboard|copy-clipboard|copy_clipboard|cut-clipboard|cut_clipboard|copy-primary|copy_primary|cut-primary|cut_primary|newline|newline-and-indent|newline_and_indent|newline-no-indent|newline_no_indent|delete-selection|delete_selection|delete-previous-character|delete_previous_character|delete-next-character|delete_next_character|delete-previous-word|delete_previous_word|delete-next-word|delete_next_word|delete-to-start-of-line|delete_to_start_of_line|delete-to-end-of-line|delete_to_end_of_line|forward-character|forward_character|backward-character|backward_character|key-select|key_select|process-up|process_up|process-down|process_down|process-shift-up|process_shift_up|process-shift-down|process_shift_down|process-home|process_home|forward-word|forward_word|backward-word|backward_word|forward-paragraph|forward_paragraph|backward-paragraph|backward_paragraph|beginning-of-line|beginning_of_line|end-of-line|end_of_line|beginning-of-file|beginning_of_file|end-of-file|end_of_file|next-page|next_page|previous-page|previous_page|page-left|page_left|page-right|page_right|toggle-overstrike|toggle_overstrike|scroll-up|scroll_up|scroll-down|scroll_down|scroll_left|scroll_right|scroll-to-line|scroll_to_line|select-all|select_all|select_word|deselect-all|deselect_all|focusIn|focusOut|process-return|process_return|process-tab|process_tab|insert-string|insert_string|mouse_pan)(?=\\s*\\()\":::Subroutine::\n\