remove nasty compiler warnings
[nedit-bw.git] / timer_macros.patch
blobcc2e1407bdddc89b96e45c8088511ae36870bce5
1 Subject: timer_add()/timer_remove() macros
3 This adds two new macro subroutines for handling timeouts.
5 **timer_add( func_name, timeout [, "global"] )**
6 Install a new timer that call the macro routine ~func_name~ after ~timeout~
7 milli seconds. The function is only called if the top window is the same as
8 the window from which ~timer_add()~ was called, this can be overriden with the
9 optional ~"global"~ parameter. The macro returns a timer ID which can be used
10 to remove a timer before expiration with ~timer_remove()~.
12 **timer_remove( timer_ID )**
13 Removes the timer with ID ~timer_ID~.
15 There can be a problem on LP64 architectures, the nedit macro language have
16 only int support but the XtIntervalId is defined as unsigned long, so there
17 can be domain error, I try to catch this error.
19 ---
21 doc/help.etx | 10 ++
22 source/highlightData.c | 2
23 source/macro.c | 168 +++++++++++++++++++++++++++++++++++++++++++++++++
24 3 files changed, 179 insertions(+), 1 deletion(-)
26 diff --quilt old/source/macro.c new/source/macro.c
27 --- old/source/macro.c
28 +++ new/source/macro.c
29 @@ -462,6 +462,11 @@ static int toLineMS(WindowInfo *window,
30 static int toColumnMS(WindowInfo *window, DataValue *argList, int nArgs,
31 DataValue *result, char **errMsg);
33 +static int timerAddMS(WindowInfo *window, DataValue *argList,
34 + int nArgs, DataValue *result, char **errMsg);
35 +static int timerRemoveMS(WindowInfo *window, DataValue *argList,
36 + int nArgs, DataValue *result, char **errMsg);
38 /* Built-in subroutines and variables for the macro language */
39 static const BuiltInSubrName MacroSubrs[] = {
40 { "args", argsMS },
41 @@ -535,6 +540,8 @@ static const BuiltInSubrName MacroSubrs[
42 { "to_line", toLineMS },
43 { "to_column", toColumnMS },
44 { "set_window_title", setWindowTitleMS },
45 + { "timer_add", timerAddMS },
46 + { "timer_remove", timerRemoveMS },
47 { NULL, NULL } /* sentinel */
50 @@ -3869,6 +3876,167 @@ static int setWindowTitleMS(WindowInfo *
51 return True;
54 +typedef struct _TimerProcData {
55 + struct _TimerProcData *next;
56 + XtIntervalId id;
57 + WindowInfo *window;
58 + int global;
59 + char name[1];
60 +} TimerProcData;
62 +static TimerProcData *allTimerProcData;
64 +static void macroTimerProc(XtPointer clientData, XtIntervalId *id)
66 + TimerProcData *data = clientData, **s;
67 + WindowInfo *win;
69 + s = &allTimerProcData;
70 + while (*s) {
71 + if ((*s)->id == data->id) {
72 + *s = data->next;
73 + break;
74 + }
75 + s = &(*s)->next;
76 + }
78 + /* check if window is still there, but don't trust the pointer */
79 + for (win = WindowList; win; win = win->next) {
80 + if (win == data->window) {
81 + break;
82 + }
83 + }
84 + if (win != data->window) {
85 + goto out;
86 + }
88 + if (*id != data->id) {
89 + goto out;
90 + }
92 + /* don't call macro if its not a global timer and current top-window is
93 + different from timer_add() window */
94 + if (!data->global && !IsTopDocument(data->window)) {
95 + goto out;
96 + }
98 + MacroApplyHook(data->window, data->name, 0, NULL, NULL);
100 +out:
101 + XtFree((char *)data);
105 + * timer_ID = timer_add(macro_name, timeout[, "global"])
106 + */
107 +static int timerAddMS(WindowInfo *window, DataValue *argList, int nArgs,
108 + DataValue *result, char **errMsg)
110 + int timeout;
111 + char stringStorage[2][TYPE_INT_STR_SIZE(int)];
112 + char *name = NULL;
113 + int is_global = 0;
114 + char *global;
115 + TimerProcData *data;
117 + if (nArgs < 2 || nArgs > 3) {
118 + return wrongNArgsErr(errMsg);
120 + if (!readStringArg(argList[0], &name, stringStorage[0], errMsg)) {
121 + return False;
123 + if (!readIntArg(argList[1], &timeout, errMsg)) {
124 + return False;
126 + if (nArgs >= 3) {
127 + if(!readStringArg(argList[2], &global, stringStorage[1], errMsg)) {
128 + return False;
130 + if (!strcmp(global, "global")) {
131 + is_global = 1;
132 + } else {
133 + *errMsg = "unknown argument for subroutine %s";
134 + return False;
138 + if (timeout < 100) {
139 + *errMsg = "timeout too small";
140 + return False;
143 + /* terminating NIL is already in struct */
144 + data = (TimerProcData *)XtMalloc(sizeof(*data) +
145 + (strlen(name) * sizeof(char)));
146 + if (!data) {
147 + *errMsg = "internal error";
148 + return False;
151 + data->window = window;
152 + data->global = is_global;
153 + strcpy(data->name, name);
155 + data->next = allTimerProcData;
156 + allTimerProcData = data;
158 + data->id = XtAppAddTimeOut(XtWidgetToApplicationContext(window->shell),
159 + timeout, macroTimerProc, data);
161 + result->tag = INT_TAG;
162 + if (data->id != (XtIntervalId)(int)data->id) {
163 + *errMsg = "warning: can't convert from XtIntervalId to int, timer not removable";
164 + result->val.n = 0;
165 + } else {
166 + result->val.n = data->id;
169 + return True;
173 + * timer_remove(timer_ID)
174 + */
175 +static int timerRemoveMS(WindowInfo *window, DataValue *argList, int nArgs,
176 + DataValue *result, char **errMsg)
178 + int timerid;
179 + XtIntervalId id;
180 + TimerProcData *data, **s;
182 + if (nArgs != 1) {
183 + return wrongNArgsErr(errMsg);
185 + if (!readIntArg(argList[0], &timerid, errMsg)) {
186 + return False;
189 + if (0 == timerid) {
190 + /* we return 0 as timerid when we can't convert the id to int
191 + the timer can therefore not removed and the TimerProcData is freed
192 + when the timer is fired
193 + */
194 + return True;
197 + id = timerid;
199 + XtRemoveTimeOut(id);
201 + s = &allTimerProcData;
202 + while (*s) {
203 + if ((*s)->id == id) {
204 + data = *s;
205 + *s = data->next;
206 + XtFree((char *)data);
207 + break;
209 + s = &(*s)->next;
212 + return True;
215 /* T Balinski */
216 static int listDialogMS(WindowInfo *window, DataValue *argList, int nArgs,
217 DataValue *result, char **errMsg)
218 diff --quilt old/source/highlightData.c new/source/highlightData.c
219 --- old/source/highlightData.c
220 +++ new/source/highlightData.c
221 @@ -551,7 +551,7 @@ static char *DefaultPatternSets[] = {
222 Built-in Misc Vars:\"(?<!\\Y)\\$(?:active_pane|args|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\
223 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\
224 Built-in Special Vars:\"(?<!\\Y)\\$(?:[1-9]|list_dialog_button|n_args|read_status|search_end|shell_cmd_status|string_dialog_button|sub_sep)>\":::String1::\n\
225 - Built-in Subrs:\"<(?:args|append_file|beep|call|calltip|clipboard_to_string|define|dialog|filename_dialog|dict_(?:insert|complete|save|append|is_element)|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|to_(?:column|line|pos)|tolower|toupper|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
226 + Built-in Subrs:\"<(?:args|append_file|beep|call|calltip|clipboard_to_string|define|dialog|filename_dialog|dict_(?:insert|complete|save|append|is_element)|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\
227 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\
228 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|deselect-all|deselect_all|focusIn|focusOut|process-return|process_return|process-tab|process_tab|insert-string|insert_string|mouse_pan)(?=\\s*\\()\":::Subroutine::\n\
229 Macro Hooks:\"<(?:(?:pre|post)_(?:open|save)|cursor_moved|modified|(?:losing_)?focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
230 diff --quilt old/doc/help.etx new/doc/help.etx
231 --- old/doc/help.etx
232 +++ new/doc/help.etx
233 @@ -2908,6 +2908,16 @@ Macro Subroutines
234 **t_print( string1, string2, ... )**
235 Writes strings to the terminal (stdout) from which NEdit was started.
237 +**timer_add( func_name, timeout [, "global"] )**
238 + Install a new timer that call the macro routine ~func_name~ after ~timeout~
239 + milli seconds. The function is only called if the top window is the same as
240 + the window from which ~timer_add()~ was called, this can be overriden with the
241 + optional ~"global"~ parameter. The macro returns a timer ID which can be used
242 + to remove a timer before expiration with ~timer_remove()~.
244 +**timer_remove( timer_ID )**
245 + Removes the timer with ID ~timer_ID~.
247 **to_column( position )**
248 Convert given position to column number in current window.