7 source/Makefile.common | 4
8 source/Makefile.dependencies | 11
9 source/highlightData.c | 13
13 source/patternMatch.c | 2202 ++++++++++++
14 source/patternMatch.h | 170
15 source/patternMatchData.c | 7780 +++++++++++++++++++++++++++++++++++++++++++
16 source/patternMatchData.h | 24
17 source/preferences.c | 170
18 source/preferences.h | 4
19 source/search.c | 231 -
20 source/smartIndent.c | 7
22 16 files changed, 10773 insertions(+), 297 deletions(-)
24 diff --quilt old/doc/help.etx new/doc/help.etx
27 @@ -867,12 +867,13 @@ Programming with NEdit
28 ----------------------
30 Though general in appearance, NEdit has many features intended specifically
31 for programmers. Major programming-related topics are listed in separate
32 sections under the heading: "Features for Programming": Syntax_Highlighting_,
33 - Tabs/Emulated_Tabs_, Finding_Declarations_(ctags)_, Calltips_, and
34 - Auto/Smart_Indent_. Minor topics related to programming are discussed below:
35 + Tabs/Emulated_Tabs_, Matching_Parentheses_, Finding_Declarations_(ctags)_,
36 + Calltips_, and Auto/Smart_Indent_. Minor topics related to programming are
41 When NEdit initially reads a file, it attempts to determine whether the file
42 is in one of the computer languages that it knows about. Knowing what language
43 @@ -926,30 +927,10 @@ Programming with NEdit
44 Search menu and enter a line number and a column number separated by a
45 comma. (e.g. Enter "100,12" for line 100 column 12.) If you want to go to
46 a column on the current line just leave out the line number. (e.g. Enter
47 ",45" to go the column 45 on the current line.)
49 -3>Matching Parentheses
51 - To help you inspect nested parentheses, brackets, braces, quotes, and other
52 - characters, NEdit has both an automatic parenthesis matching mode, and a Goto
53 - Matching command. Automatic parenthesis matching is activated when you type,
54 - or move the insertion cursor after a parenthesis, bracket, or brace. It
55 - momentarily highlights either the opposite character ('Delimiter') or the
56 - entire expression ('Range') when the opposite character is visible in the
57 - window. To find a matching character anywhere in the file, select it or
58 - position the cursor after it, and choose Goto Matching from the Search menu.
59 - If the character matches itself, such as a quote or slash, select the first
60 - character of the pair. NEdit will match {, (, [, <, ", ', `, /, and \.
61 - Holding the Shift key while typing the accelerator key (Shift+Ctrl+M, by
62 - default), will select all of the text between the matching characters.
64 - When syntax highlighting is enabled, the matching routines can optionally
65 - make use of the syntax information for improved accuracy. In that case,
66 - a brace inside a highlighted string will not match a brace inside a comment,
69 3>Opening Included Files
71 The Open Selected command in the File menu understands the C preprocessor's
72 #include syntax, so selecting an #include line and invoking Open Selected will
73 generally find the file referred to, unless doing so depends on the settings of
74 @@ -1223,10 +1204,43 @@ Syntax Highlighting
75 is scrolled in to view. Depending on your system, and the highlight patterns
76 you are using, this may or may not be noticeable. A typing delay is also
77 possible, but unlikely if you are only using the built-in patterns.
78 ----------------------------------------------------------------------
83 +3>Matching Parentheses (Patterns)
85 + To help you inspect nested parentheses (e.g. brackets, braces, quotes
86 + etc.) or nested constructs (e.g. "begin" .. "end"), NEdit has both an
87 + automatic parenthesis matching mode, and a Goto Matching command.
89 + A matching pattern can be a single character (like '(', ')'), a literal
90 + string (like '#ifdef', '#endif') or a regular expression (like
93 + Automatic parenthesis matching is activated when you type, or move the
94 + insertion cursor after a parenthesis, bracket, or brace. It momentarily
95 + highlights either the opposite pattern ('Delimiter') or the entire expression
96 + ('Range') when the opposite pattern is visible in the window. To find a
97 + matching pattern anywhere in the file, select it or position the cursor after
98 + it, and choose Goto Matching from the Search menu. If the pattern matches
99 + itself, such as a quote or slash, select the first pattern of the pair.
100 + Holding the Shift key while typing the accelerator key (Shift+Ctrl+M, by
101 + default), will select all of the text between the matching patterns.
103 + When syntax highlighting is enabled, the matching routines can optionally
104 + make use of the syntax information for improved accuracy. In that case,
105 + a brace inside a highlighted string will not match a brace inside a comment,
108 + Matching patterns are language dependent. Matching patterns can be
109 + configured by the user. If no matching patterns are available for the
110 + language that you want to use, you can create new patterns relatively quickly.
111 + The Help section "Matching_Patterns_" under "Customizing", has details.
113 Finding Declarations (ctags)
114 ----------------------------
116 NEdit can process tags files generated using the Unix _ctags command or the
117 Exuberant Ctags program. Ctags creates index files correlating names of
118 @@ -2581,13 +2595,10 @@ Macro Subroutines
121 Contains the current preference for showing matching pairs,
122 such as "[]" and "{}" pairs. Can be "off", "delimiter", or "range".
124 -**$match_syntax_based**
125 - Whether pair matching should use syntax information, if available.
128 Has a value of 1 if the statistics line is shown, otherwise 0.
131 Contains the value of the array sub-script separation string.
132 @@ -2699,10 +2710,19 @@ Macro Subroutines
134 **get_character( position )**
135 Returns the single character at the position indicated by the first argument
136 to the routine from the current window.
138 +**get_matching( position )**
139 + Find a matching pattern string related to the given position.
140 + Returns info about matching pattern within an array. The array has
141 + the following keys: **pos** (position of the first character of the
142 + matching pattern), **len** (length of the matching pattern), **direction**
143 + (direction where the matching pattern was found: ~0~ = forward;
144 + ~1~ = backward). If no matching pattern was found, then array element
145 + of **pos** holds ~-1~, **len** holds ~0~ and **direction** holds ~-1~.
147 **get_range( start, end )**
148 Returns the text between a starting and ending position from the current
152 @@ -3408,13 +3428,10 @@ Action Routines
153 If no parameters are supplied the option is toggled.
155 **set_show_matching( "off" | "delimiter" | "range" )**
156 Set show matching (...) mode for the current window.
158 -**set_match_syntax_based( [0 | 1] )**
159 - Set whether matching should be syntax based for the current window.
161 **set_statistics_line( [0 | 1] )**
162 Show or hide the statistics line for the current window.
163 A value of 0 turns it off and a value of 1 turns it on.
164 If no parameters are supplied the option is toggled.
166 @@ -3937,14 +3954,10 @@ Preferences
167 range between them, when one of these characters is typed, or when the
168 insertion cursor is positioned after it. Delimiter only highlights the
169 matching delimiter, while Range highlights the whole range of text between
170 the matching delimiters.
172 - Optionally, the matching can make use of syntax information if syntax
173 - highlighting is enabled. Alternatively, the matching is purely character
174 - based. In general, syntax based matching results in fewer false matches.
177 In overtype mode, new characters entered replace the characters in front of
178 the insertion cursor, rather than being inserted before them.
181 @@ -5047,10 +5060,189 @@ Smart Indent Macros
182 before the character is inserted into the buffer. You can do just about
183 anything here, but keep in mind that this macro is executed for every
184 keystroke typed, so if you try to get too fancy, you may degrade performance.
185 ----------------------------------------------------------------------
190 +3>Writing Matching Pattern Sets
192 + Matching Patterns Sets are groups of single characters (like '(', ')'),
193 + literal strings (like '#ifdef', '#endif') or a regular expressions (like
194 + '\</.*\>'), which match to each other.
196 + Examples: An open bracket '(' belongs a closing one ')'.
197 + Or: '#ifdef'(start), '#ifndef'(alternative start), '#ifndef' (another
198 + alternative start),'#elif' (optional), '#else' (optional), '#endif' (end)
199 + define a "#ifdef statement matching pattern".
201 + "Opposite pattern highlighting" or "Goto Matching" features are implemented
202 + in NEdit using this matching pattern sets (see Matching_Parentheses_ under
203 + the heading of Features for Programming).
205 + During definition of a new language mode a standard matching pattern set
206 + is assigned to this new language mode.
208 + To modify a matching pattern set, select "Matching Patterns ..." from
209 + "Show Matching (..)" sub-section of the "Default Settings" sub-menu
210 + of the "Preferences" menu.
212 + A matching pattern set is a collection of matching patterns.
214 + A matching pattern usually consists out of string patterns.
216 + The name of a matching pattern set needs to be defined within field "Matching
219 +4>Attributes of matching pattern
221 + A matching pattern holds two types of attributes:
223 +* "Matching Pattern Type" and
224 +* "Global Attributes"
226 + The matching pattern type specifies the kind of the matching pattern
233 + Each matching pattern can be defined as "Individual" or as "Sub-pattern".
234 + A "Sub-pattern" belongs to a context group. A context group is simply a
235 + collection of sub-patterns.
237 + During search for a corresponding pattern, an "Individual" matching pattern
238 + does not care about nesting of other matching patterns.
240 + If a matching pattern out of a "Context group" is searched, then all
241 + sub-pattern sets defined in this group are taken into account during the
244 + In fact, "Individual" matching pattern search is faster than "Context group" /
245 + "Sub-pattern" search. "Context group" / "Sub-pattern" search results in fewer
248 + To define a context group, set "Matching Pattern Type" to "Context group".
249 + Select out of "Sub-Pattern Name" pop-up field all sub-patterns, which
250 + should be placed into this group. **Note**: all "Sub-pattern" used by a context
251 + group must be defined **before** the context group itself.
253 + "Global Attributes" of a matching pattern are
255 +* "Skip content between start / end pattern"
256 +* "Flash matching pattern"
259 + If "Skip content between start / end pattern" is checked, then all text
260 + between the first / last string pattern of the related matching pattern is
261 + not scanned for other string patterns. This is useful for specifying comments.
263 + "Flash matching pattern" indicates, if the string patterns are flashed during
264 + typing. If not checked, then only the "Goto Matching" feature works for the
265 + related matching pattern. Note: if lots of "Flash matching pattern" are
266 + specified, then this may slow down the performance of NEdit: after each
267 + character typed all "Flash matching pattern" are scanned for being
270 + "Syntax based" defines, if the matching pattern can make use of syntax
271 + information if syntax highlighting is enabled. Alternatively, the matching is
272 + purely character based. In general, syntax based matching results in fewer
275 +4>Content of matching pattern
277 + An "Individual" pattern or a "Sub-pattern" may consist out of only one string
278 + pattern (e.g. double quotes '"'). Such a pattern is called "mono pattern".
279 + You can imagine, that a match for a mono pattern is hard to find. A matching
280 + mono pattern search is always started in forward direction. If no match is
281 + found in forward direction, a backward search is started. If the "Global
282 + Attribute" "Syntax based" is selected for a mono pattern, then the character
283 + before / after the match is checked to have the same highlighting style than
284 + the pattern itself. This may help to determine the correct match for a mono
287 + Usually a matching pattern holds two string patterns (e.g. 'begin' and
288 + 'end'). One ('begin') is the start pattern. The other one ('end') is the
289 + end pattern. If the cursor is located behind the start pattern, then a
290 + corresponding end pattern is searched (in forward direction). If the
291 + cursor is located behind the end pattern, then a start pattern is search
292 + (in backward direction):
294 +! +--> start ---> end --+
295 +! +-----------<---------+
297 + Alternative start / end patterns can be defined. In this case one of the
298 + start / end patterns must be in front of the cursor to detect one of the
299 + related end / start patterns:
301 +! +-> start1 -+ +-> end1 -+
302 +! +-+-> start2 -+---+ +--+
303 +! + +-> start3 -+ +-> end2 -+ |
304 +! +---------------<-------------+
306 + At least also "middle" patterns can be defined (e.g. middle patterns
307 + 'elif' or 'else'). If the cursor is located behind a middle pattern then a
308 + next middle pattern or the end pattern is searched in forward direction:
311 +! +--> start -+-> middle -+-> end --+
312 +! +-----------<---------------------+
316 + A string pattern holds three attributes:
318 +* "String Pattern Type"
320 +* "String Attributes"
322 + String Pattern Type specifies if the related string pattern is
323 + a "start", middle, or "end" pattern (see above).
325 + Word boundary defines, if before / after a string pattern a delimiter must be
326 + located ("Both" = pattern is framed by delimiters. "Left" = before pattern
327 + must be a delimiter. "Right" = after pattern must be a delimiter. "None" =
328 + there must be no delimiter before or after pattern).
330 + There are two "String Attributes":
333 +* "Regular Expression"
335 + If "Case Sensitive" is checked (= default), then the matching pattern search
336 + concerning this string pattern differs between upper / lower case of the
337 + characters. If "Case Sensitive" is not set, then the case of the checked
338 + characters is not considered.
340 + "Regular Expression" indicates, that string pattern is treated as
341 + regular expression (if "Regular Expression" is checked) or as literal
342 + string (if "Regular Expression" is not checked).
344 +4>Regular Expression String Pattern
346 + Syntax of regular expression is described by NEdit Help menu item
347 + Regular_Expressions_. Following deviations from this syntax are
348 + existing concerning string patterns:
350 +5>Capturing Parentheses
352 + Capturing Parentheses inside string patterns are of the form `(*n<regex>)',
353 + where n = 1 .. 9. Standard "capturing parentheses" of form `(<regex>)' are
354 + treated as "non-capturing parentheses" by the matching pattern feature.
355 + "n" defines the **global** backreference number, which can be used inside any string
356 + pattern of the same matching pattern (= set of string patterns). So
357 + matching patterns like "\<(*1[^/>])\>" (start string pattern) and "\</\1\>"
358 + (end string pattern) are possible. This matching pattern will match e.g.
359 + <body> .. </body> but will not match <body> .. </head>.
361 +5>Non-Capturing Parentheses
363 + As described above: parentheses constructs like (<regex>) are treated
364 + as `(?:<regex>)' (non-capturing parentheses) by the matching pattern feature.
369 .. ? help !!#ifndef VMS
370 **nedit** [-**read**] [-**create**] [-**line** n | +n] [-**server**]
371 @@ -6077,10 +6269,11 @@ Problems/Defects
372 .. Menu: Features for Programming # features
373 .. Menu: Programming with NEdit # programmer
374 .. Menu: Tabs/Emulated Tabs # tabs
375 .. Menu: Auto/Smart Indent # indent
376 .. Menu: Syntax Highlighting # syntax
377 +.. Menu: Matching Parentheses # pattern_matching
378 .. Menu: Finding Declarations (ctags) # tags
379 .. Menu: Calltips # calltips
381 .. Menu: Regular Expressions # regex
382 .. Menu: Basic Regular Expression Syntax # basicSyntax
383 @@ -6104,10 +6297,11 @@ Problems/Defects
384 .. Menu: Preferences # preferences
385 .. Menu: X Resources # resources
386 .. Menu: Key Binding # binding
387 .. Menu: Highlighting Patterns # patterns
388 .. Menu: Smart Indent Macros # smart_indent
389 +.. Menu: Matching Patterns # matching_patterns
391 .. Menu: NEdit Command Line # command_line
392 .. Menu: Client/Server Mode # server
393 .. Menu: Cr_a_sh Recovery # recovery
394 .. Menu: ---------------------------------- # separator1
395 diff --quilt old/source/Makefile.common new/source/Makefile.common
396 --- old/source/Makefile.common
397 +++ new/source/Makefile.common
398 @@ -7,10 +7,11 @@ OBJS = nedit.o file.o menu.o window.o se
399 help.o preferences.o tags.o userCmds.o shell.o regularExp.o macro.o \
400 text.o textSel.o textDisp.o textBuf.o textDrag.o server.o highlight.o \
401 highlightData.o interpret.o parse.o smartIndent.o regexConvert.o \
402 rbTree.o windowTitle.o calltips.o server_common.o rangeset.o
404 +OBJS += patternMatch.o patternMatchData.o
406 XLTLIB = ../Xlt/libXlt.a
407 XMLLIB = ../Microline/XmL/libXmL.a
410 @@ -36,10 +37,13 @@ smartIndent.o: smartIndent.c
411 $(CC) $(CFLAGS) $(BIGGER_STRINGS) -c smartIndent.c -o $@
413 highlightData.o: highlightData.c
414 $(CC) $(CFLAGS) $(BIGGER_STRINGS) -c highlightData.c -o $@
416 +patternMatchData.o: patternMatchData.c
417 + $(CC) $(CFLAGS) $(BIGGER_STRINGS) -c patternMatchData.c -o $@
419 help_topic.h help_data.h: ../doc/help.etx
420 (cd ..; $(MAKE) docs)
423 rm -f $(OBJS) nedit nc nc.o parse.c linkdate.o
424 diff --quilt old/source/Makefile.dependencies new/source/Makefile.dependencies
425 --- old/source/Makefile.dependencies
426 +++ new/source/Makefile.dependencies
427 @@ -84,5 +84,16 @@ window.o: window.c window.h nedit.h text
428 ../util/fileUtils.h ../util/utils.h
429 windowTitle.o: windowTitle.c windowTitle.h nedit.h textBuf.h \
430 preferences.h help.h help_topic.h ../util/prefFile.h ../util/misc.h \
431 ../util/DialogF.h ../util/utils.h ../util/fileUtils.h \
433 +patternMatch.o: patternMatch.c regularExp.h \
434 + textBuf.h search.h window.h preferences.h highlight.h\
435 + patternMatch.h patternMatchData.h
436 +patternMatchData.o: patternMatchData.c ../util/DialogF.h ../util/misc.h \
437 + ../util/managedList.h regularExp.h textBuf.h nedit.h window.h \
438 + preferences.h help.h file.h textP.h patternMatch.h patternMatchData.h
439 +macro.o: patternMatch.h regularExp.h
440 +menu.o: patternMatchData.h
441 +preferences.o: patternMatchData.h
442 +search.o: patternMatch.h
443 +window.o: patternMatchData.h
444 diff --quilt old/source/highlightData.c new/source/highlightData.c
445 --- old/source/highlightData.c
446 +++ new/source/highlightData.c
447 @@ -549,11 +549,11 @@ static char *DefaultPatternSets[] = {
448 README:\"NEdit Macro syntax highlighting patterns, version 2.6, maintainer Thorsten Haude, nedit at thorstenhau.de\":::Flag::D\n\
449 Comment:\"#\":\"$\"::Comment::\n\
450 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\
451 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\
452 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\
453 - Built-in Subrs:\"<(?:append_file|beep|call|calltip|clipboard_to_string|dialog|filename_dialog|focus_window|get_character|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|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|shell_command|split|string_compare|string_dialog|string_to_clipboard|substring|t_print|tolower|toupper|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
454 + Built-in Subrs:\"<(?:append_file|beep|call|calltip|clipboard_to_string|dialog|filename_dialog|focus_window|get_character|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|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|get_matching|set_transient|shell_command|split|string_compare|string_dialog|string_to_clipboard|substring|t_print|tolower|toupper|valid_number|write_file)(?=\\s*\\()\":::Subroutine::\n\
455 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\
456 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\
457 Macro Hooks:\"<(?:post_open|pre_open|post_save|cursor_moved|modified|focus|losing_focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
458 Keyword:\"<(?:break|continue|define|delete|else|for|if|in|return|while)>\":::Keyword::\n\
459 Braces:\"[{}\\[\\]]\":::Keyword::\n\
460 @@ -2342,12 +2342,13 @@ void EditHighlightPatterns(WindowInfo *w
462 XmNrightAttachment, XmATTACH_POSITION,
463 XmNrightPosition, 99,
466 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
467 HighlightDialog.lmPulldown = CreateLanguageModeMenu(lmForm, langModeCB,
471 XtSetArg(args[n], XmNspacing, 0); n++;
472 XtSetArg(args[n], XmNmarginWidth, 0); n++;
473 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
474 XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
475 @@ -2877,12 +2878,13 @@ void UpdateLanguageModeMenu(void)
477 if (HighlightDialog.shell == NULL)
480 oldMenu = HighlightDialog.lmPulldown;
481 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
482 HighlightDialog.lmPulldown = CreateLanguageModeMenu(
483 - XtParent(XtParent(oldMenu)), langModeCB, NULL);
484 + XtParent(XtParent(oldMenu)), langModeCB, NULL, FALSE);
485 XtVaSetValues(XmOptionButtonGadget(HighlightDialog.lmOptMenu),
486 XmNsubMenuId, HighlightDialog.lmPulldown, NULL);
487 SetLangModeMenu(HighlightDialog.lmOptMenu, HighlightDialog.langModeName);
489 XtDestroyWidget(oldMenu);
490 @@ -2937,10 +2939,13 @@ static void langModeCB(Widget w, XtPoint
491 "Discard Changes", "Cancel", HighlightDialog.langModeName);
494 SetLangModeMenu(HighlightDialog.lmOptMenu,
495 HighlightDialog.langModeName);
497 + freePatternSet(newPatSet);
504 @@ -3036,10 +3041,12 @@ static void restoreCB(Widget w, XtPointe
505 "Are you sure you want to discard\n"
506 "all changes to syntax highlighting\n"
507 "patterns for language mode %s?", "Discard", "Cancel",
508 HighlightDialog.langModeName) == 2)
510 + freePatternSet(defaultPatSet);
515 /* if a stored version of the pattern set exists, replace it, if it
516 doesn't, add a new one */
517 diff --quilt old/source/macro.c new/source/macro.c
518 --- old/source/macro.c
519 +++ new/source/macro.c
520 @@ -37,13 +37,15 @@ static const char CVSID[] = "$Id: macro.
521 #include "highlight.h"
522 #include "interpret.h"
526 +#include "patternMatch.h"
527 #include "preferences.h"
528 #include "rangeset.h"
530 +#include "regularExp.h"
532 #include "selection.h"
535 #include "smartIndent.h"
536 @@ -296,12 +298,10 @@ static int makeBackupCopyMV(WindowInfo *
537 DataValue *result, char **errMsg);
538 static int incBackupMV(WindowInfo *window, DataValue *argList, int nArgs,
539 DataValue *result, char **errMsg);
540 static int showMatchingMV(WindowInfo *window, DataValue *argList, int nArgs,
541 DataValue *result, char **errMsg);
542 -static int matchSyntaxBasedMV(WindowInfo *window, DataValue *argList, int nArgs,
543 - DataValue *result, char **errMsg);
544 static int overTypeModeMV(WindowInfo *window, DataValue *argList, int nArgs,
545 DataValue *result, char **errMsg);
546 static int readOnlyMV(WindowInfo *window, DataValue *argList, int nArgs,
547 DataValue *result, char **errMsg);
548 static int lockedMV(WindowInfo *window, DataValue *argList, int nArgs,
549 @@ -413,10 +413,14 @@ static int getStyleAtPosMS(WindowInfo *w
550 static int filenameDialogMS(WindowInfo* window, DataValue* argList, int nArgs,
551 DataValue* result, char** errMsg);
552 static int callMS(WindowInfo *window, DataValue *argList,
553 int nArgs, DataValue *result, char **errMsg);
555 +/* Pattern Match Feature */
556 +static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs,
557 + DataValue *result, char **errMsg);
559 /* Built-in subroutines and variables for the macro language */
560 static const BuiltInSubrName MacroSubrs[] = {
561 { "length", lengthMS },
562 { "get_range", getRangeMS },
563 { "t_print", tPrintMS },
564 @@ -473,10 +477,11 @@ static const BuiltInSubrName MacroSubrs[
565 { "get_pattern_at_pos", getPatternAtPosMS },
566 { "get_style_by_name", getStyleByNameMS },
567 { "get_style_at_pos", getStyleAtPosMS },
568 { "filename_dialog", filenameDialogMS },
570 + { "get_matching", getMatchingMS },
571 { NULL, NULL } /* sentinel */
574 static const BuiltInSubrName SpecialVars[] = {
575 { "$cursor", cursorMV },
576 @@ -502,11 +507,10 @@ static const BuiltInSubrName SpecialVars
577 { "$wrap_text", wrapTextMV },
578 { "$highlight_syntax", highlightSyntaxMV },
579 { "$make_backup_copy", makeBackupCopyMV },
580 { "$incremental_backup", incBackupMV },
581 { "$show_matching", showMatchingMV },
582 - { "$match_syntax_based", matchSyntaxBasedMV },
583 { "$overtype_mode", overTypeModeMV },
584 { "$read_only", readOnlyMV },
585 { "$locked", lockedMV },
586 { "$file_format", fileFormatMV },
587 { "$font_name", fontNameMV },
588 @@ -4553,20 +4557,10 @@ static int showMatchingMV(WindowInfo *wi
589 result->val.str.rep = res;
590 result->val.str.len = strlen(res);
594 -static int matchSyntaxBasedMV(WindowInfo *window, DataValue *argList, int nArgs,
595 - DataValue *result, char **errMsg)
597 - result->tag = INT_TAG;
598 - result->val.n = window->matchSyntaxBased ? 1 : 0;
604 static int overTypeModeMV(WindowInfo *window, DataValue *argList, int nArgs,
605 DataValue *result, char **errMsg)
607 result->tag = INT_TAG;
608 result->val.n = window->overstrike ? 1 : 0;
609 @@ -5966,10 +5960,97 @@ static int getPatternAtPosMS(WindowInfo
610 return fillPatternResult(result, errMsg, window,
611 HighlightNameOfCode(window, patCode), False, True,
612 HighlightStyleOfCode(window, patCode), bufferPos);
616 +** Pattern Match Feature:
617 +** Find a matching pattern string related to the given position.
620 +** get_matching(position)
622 +** Returns info about matching pattern within an array. The array has
623 +** the following keys: "pos" (position of the first character of the
624 +** matching pattern), "len" (length of the matching pattern), "direction"
625 +** (direction where the matching pattern was found: "0" = forward;
626 +** "1" = backward). If no matching pattern was found, then array element
627 +** of "pos" holds "-1", "len" holds "0" and "direction" holds "-1".
630 +static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs,
631 + DataValue *result, char **errMsg)
634 + int matchPos, matchLen;
636 + textBuffer *buf = window->buffer;
640 + * Perform syntax & semantic check
643 + return wrongNArgsErr(errMsg);
645 + if (!readIntArg(argList[0], &startPos, errMsg))
651 + * do the search; provide default values, if search fails
653 + if (!FindMatchingString(window, MT_MACRO, &startPos, 0, buf->length,
654 + &matchPos, &matchLen, &direction))
662 + * initialize array holding info about matching string
664 + result->tag = ARRAY_TAG;
665 + result->val.arrayPtr = ArrayNew();
668 + * the following array entries will be integers
673 + * insert match position
675 + dv.val.n = matchPos;
676 + if (!ArrayInsert(result, PERM_ALLOC_STR("pos"), &dv))
678 + M_ARRAY_INSERT_FAILURE();
682 + * insert length of matching pattern
684 + dv.val.n = matchLen;
685 + if (!ArrayInsert(result, PERM_ALLOC_STR("len"), &dv))
687 + M_ARRAY_INSERT_FAILURE();
691 + * insert direction where the matching pattern was found
693 + dv.val.n = direction;
694 + if (!ArrayInsert(result, PERM_ALLOC_STR("direction"), &dv))
696 + M_ARRAY_INSERT_FAILURE();
702 static int wrongNArgsErr(char **errMsg)
704 *errMsg = "Wrong number of arguments to function %s";
707 diff --quilt old/source/menu.c new/source/menu.c
708 --- old/source/menu.c
709 +++ new/source/menu.c
710 @@ -47,10 +47,11 @@ static const char CVSID[] = "$Id: menu.c
711 #include "userCmds.h"
714 #include "highlight.h"
715 #include "highlightData.h"
716 +#include "patternMatchData.h"
717 #include "interpret.h"
718 #include "smartIndent.h"
719 #include "windowTitle.h"
720 #include "regularExp.h"
721 #include "../util/getfiles.h"
722 @@ -131,11 +132,10 @@ static void fontCB(Widget w, WindowInfo
723 static void tabsCB(Widget w, WindowInfo *window, caddr_t callData);
724 static void backlightCharsCB(Widget w, WindowInfo *window, caddr_t callData);
725 static void showMatchingOffCB(Widget w, WindowInfo *window, caddr_t callData);
726 static void showMatchingDelimitCB(Widget w, WindowInfo *window, caddr_t callData);
727 static void showMatchingRangeCB(Widget w, WindowInfo *window, caddr_t callData);
728 -static void matchSyntaxBasedCB(Widget w, WindowInfo *window, caddr_t callData);
729 static void statsCB(Widget w, WindowInfo *window, caddr_t callData);
730 static void autoIndentOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
731 static void autoIndentDefCB(Widget w, WindowInfo *window, caddr_t callData);
732 static void smartIndentDefCB(Widget w, WindowInfo *window, caddr_t callData);
733 static void autoSaveDefCB(Widget w, WindowInfo *window, caddr_t callData);
734 @@ -158,13 +158,13 @@ static void pathInWindowsMenuDefCB(Widge
735 static void customizeTitleDefCB(Widget w, WindowInfo *window, caddr_t callData);
736 static void tabsDefCB(Widget w, WindowInfo *window, caddr_t callData);
737 static void showMatchingOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
738 static void showMatchingDelimitDefCB(Widget w, WindowInfo *window, caddr_t callData);
739 static void showMatchingRangeDefCB(Widget w, WindowInfo *window, caddr_t callData);
740 -static void matchSyntaxBasedDefCB(Widget w, WindowInfo *window, caddr_t callData);
741 static void highlightOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
742 static void highlightDefCB(Widget w, WindowInfo *window, caddr_t callData);
743 +static void matchPatternsDefCB(Widget w, WindowInfo *window, caddr_t callData);
744 static void backlightCharsDefCB(Widget w, WindowInfo *window, caddr_t callData);
745 static void fontDefCB(Widget w, WindowInfo *window, caddr_t callData);
746 static void colorDefCB(Widget w, WindowInfo *window, caddr_t callData);
747 static void smartTagsDefCB(Widget parent, XtPointer client_data, XtPointer call_data);
748 static void showAllTagsDefCB(Widget parent, XtPointer client_data, XtPointer call_data);
749 @@ -408,12 +408,10 @@ static void setMakeBackupCopyAP(Widget w
751 static void setIncrementalBackupAP(Widget w, XEvent *event, String *args,
753 static void setShowMatchingAP(Widget w, XEvent *event, String *args,
755 -static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
757 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
759 static void setLockedAP(Widget w, XEvent *event, String *args,
761 static void setTransientAP(Widget text, XEvent* event, String* args,
762 @@ -583,11 +581,10 @@ static XtActionsRec Actions[] = {
764 {"set_make_backup_copy", setMakeBackupCopyAP},
766 {"set_incremental_backup", setIncrementalBackupAP},
767 {"set_show_matching", setShowMatchingAP},
768 - {"set_match_syntax_based", setMatchSyntaxBasedAP},
769 {"set_overtype_mode", setOvertypeModeAP},
770 {"set_locked", setLockedAP},
771 {"set_transient", setTransientAP},
772 {"set_tab_dist", setTabDistAP},
773 {"set_em_tab_dist", setEmTabDistAP},
774 @@ -1030,14 +1027,13 @@ Widget CreateMenuBar(Widget parent, Wind
775 "delimiter", "Delimiter", 'D', showMatchingDelimitDefCB, window,
776 GetPrefShowMatching() == FLASH_DELIMIT, SHORT);
777 window->showMatchingRangeDefItem = createMenuRadioToggle(subSubPane,
778 "range", "Range", 'R', showMatchingRangeDefCB, window,
779 GetPrefShowMatching() == FLASH_RANGE, SHORT);
780 - createMenuSeparator(subSubPane, "sep", SHORT);
781 - window->matchSyntaxBasedDefItem = createMenuToggle(subSubPane,
782 - "matchSyntax", "Syntax Based", 'S', matchSyntaxBasedDefCB, window,
783 - GetPrefMatchSyntaxBased(), SHORT);
784 + createMenuSeparator(subSubPane, "sep1", SHORT);
785 + createMenuItem(subSubPane, "matchPatterns", "Matching Patterns...",
786 + 'M', matchPatternsDefCB, window, FULL);
788 /* Show Hidden Files */
789 window->showHiddenFilesItem = createMenuToggle(subPane,
790 "showHiddenFilesItem", "Show hidden Files", 'y', showHiddenFilesCB,
791 NULL, GetPrefShowHiddenFiles(), FULL);
792 @@ -1160,14 +1156,10 @@ Widget CreateMenuBar(Widget parent, Wind
793 "delimiter", "Delimiter", 'D', showMatchingDelimitCB, window,
794 window->showMatchingStyle == FLASH_DELIMIT, SHORT);
795 window->showMatchingRangeItem = createMenuRadioToggle(subPane, "range",
796 "Range", 'R', showMatchingRangeCB, window,
797 window->showMatchingStyle == FLASH_RANGE, SHORT);
798 - createMenuSeparator(subPane, "sep", SHORT);
799 - window->matchSyntaxBasedItem = createMenuToggle(subPane, "matchSyntax",
800 - "Syntax Based", 'S', matchSyntaxBasedCB, window,
801 - window->matchSyntaxBased, SHORT);
804 createMenuSeparator(menuPane, "sep2", SHORT);
805 window->overtypeModeItem = createMenuToggle(menuPane, "overtype", "Overtype", 'O',
806 doActionCB, "set_overtype_mode", False, SHORT);
807 @@ -1695,28 +1687,10 @@ static void showMatchingRangeCB(Widget w
808 ((XmAnyCallbackStruct *)callData)->event);
809 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_show_matching",
810 ((XmAnyCallbackStruct *)callData)->event, params, 1);
813 -static void matchSyntaxBasedCB(Widget w, WindowInfo *window, caddr_t callData)
815 - Widget menu = MENU_WIDGET(w);
817 - window = WidgetToWindow(menu);
820 - if (shortPrefAskDefault(window->shell, w, "Match Syntax Based")) {
821 - matchSyntaxBasedDefCB(w, window, callData);
822 - SaveNEditPrefs(window->shell, GetPrefShortMenus());
825 - HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
826 - ((XmAnyCallbackStruct *)callData)->event);
827 - XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_match_syntax_based",
828 - ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
831 static void fontCB(Widget w, WindowInfo *window, caddr_t callData)
833 ChooseFonts(WidgetToWindow(MENU_WIDGET(w)), True);
836 @@ -2041,22 +2015,18 @@ static void showMatchingRangeDefCB(Widge
837 XmToggleButtonSetState(win->showMatchingDelimitDefItem, False, False);
838 XmToggleButtonSetState(win->showMatchingRangeDefItem, True, False);
842 -static void matchSyntaxBasedDefCB(Widget w, WindowInfo *window, caddr_t callData)
843 +static void matchPatternsDefCB(Widget w, WindowInfo *window, caddr_t callData)
847 - int state = XmToggleButtonGetState(w);
848 + Widget menu = MENU_WIDGET(w);
849 + WindowInfo *activeWindow = WidgetToWindow(menu);
851 - /* Set the preference and make the other windows' menus agree */
852 - SetPrefMatchSyntaxBased(state);
853 - for (win=WindowList; win!=NULL; win=win->next) {
854 - if (IsTopDocument(win))
855 - XmToggleButtonSetState(win->matchSyntaxBasedDefItem, state, False);
857 + HidePointerOnKeyedEvent(activeWindow->lastFocus,
858 + ((XmAnyCallbackStruct *)callData)->event);
859 + EditMatchPatterns(activeWindow);
862 static void backlightCharsDefCB(Widget w, WindowInfo *window, caddr_t callData)
865 @@ -4297,23 +4267,10 @@ static void setShowMatchingAP(Widget w,
867 fprintf(stderr, "nedit: set_show_matching requires argument\n");
871 -static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
874 - WindowInfo *window = WidgetToWindow(w);
877 - ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->matchSyntaxBased, "set_match_syntax_based");
879 - if (IsTopDocument(window))
880 - XmToggleButtonSetState(window->matchSyntaxBasedItem, newState, False);
881 - window->matchSyntaxBased = newState;
884 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
887 WindowInfo *window = WidgetToWindow(w);
889 diff --quilt old/source/nedit.h new/source/nedit.h
890 --- old/source/nedit.h
891 +++ new/source/nedit.h
892 @@ -364,11 +364,10 @@ typedef struct _WindowInfo {
893 Widget iSearchLineItem;
895 Widget showMatchingOffItem;
896 Widget showMatchingDelimitItem;
897 Widget showMatchingRangeItem;
898 - Widget matchSyntaxBasedItem;
899 Widget overtypeModeItem;
900 Widget highlightItem;
901 Widget windowMenuPane;
902 Widget shellMenuPane;
903 Widget macroMenuPane;
904 @@ -390,11 +389,10 @@ typedef struct _WindowInfo {
905 Widget newlineWrapDefItem;
906 Widget contWrapDefItem;
907 Widget showMatchingOffDefItem;
908 Widget showMatchingDelimitDefItem;
909 Widget showMatchingRangeDefItem;
910 - Widget matchSyntaxBasedDefItem;
911 Widget highlightOffDefItem;
912 Widget highlightDefItem;
913 Widget backlightCharsItem;
914 Widget backlightCharsDefItem;
915 Widget searchDlogsDefItem;
916 @@ -510,11 +508,10 @@ typedef struct _WindowInfo {
917 ALWAYS, ON-WRAP as enums */
918 Boolean overstrike; /* is overstrike mode turned on ? */
919 char showMatchingStyle; /* How to show matching parens:
920 NO_FLASH, FLASH_DELIMIT, or
922 - char matchSyntaxBased; /* Use syntax info to show matching */
923 Boolean showStats; /* is stats line supposed to be shown */
924 Boolean showISearchLine; /* is incr. search line to be shown */
925 Boolean showLineNumbers; /* is the line number display shown */
926 Boolean highlightSyntax; /* is syntax highlighting turned on? */
927 Boolean backlightChars; /* is char backlighting turned on? */
928 @@ -556,10 +553,13 @@ typedef struct _WindowInfo {
929 incremental search bar */
930 Bool iSearchLastLiteralCase; /* idem, for literal mode */
931 Bool findLastRegexCase; /* idem, for regex mode in find dialog */
932 Bool findLastLiteralCase; /* idem, for literal mode */
934 + /* Pattern Match Feature */
935 + void *stringMatchTable; /* match pattern info related to this window */
938 int replaceScope; /* Current scope for replace dialog */
939 Widget replaceScopeWinToggle; /* Scope for replace = window */
940 Widget replaceScopeSelToggle; /* Scope for replace = selection */
941 Widget replaceScopeMultiToggle;/* Scope for replace = multiple files */
942 diff --quilt /dev/null new/source/patternMatch.c
944 +++ new/source/patternMatch.c
946 +static const char CVSID[] = "$Id: patternMatch.c,v 1.4 2003/10/27 21:59:14 uleh Exp $";
947 +/*******************************************************************************
949 +* patternMatch.c -- Nirvana Editor pattern matching functions *
951 +* Copyright (C) 2003-2004, Uwe Lehnert *
953 +* This is free software; you can redistribute it and/or modify it under the *
954 +* terms of the GNU General Public License as published by the Free Software *
955 +* Foundation; either version 2 of the License, or (at your option) any later *
956 +* version. In addition, you may distribute versions of this program linked to *
957 +* Motif or Open Motif. See README for details. *
959 +* This software is distributed in the hope that it will be useful, but WITHOUT *
960 +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
961 +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
962 +* for more details. *
964 +* You should have received a copy of the GNU General Public License along with *
965 +* software; if not, write to the Free Software Foundation, Inc., 59 Temple *
966 +* Place, Suite 330, Boston, MA 02111-1307 USA *
968 +* Nirvana Text Editor *
969 +* October 27, 2004 *
971 +* Written by Uwe Lehnert *
973 +*******************************************************************************/
975 +#ifdef HAVE_CONFIG_H
976 +#include "../config.h"
986 +#include "../util/VMSparam.h"
989 +#include <sys/param.h>
993 +#include "regularExp.h"
994 +#include "textBuf.h"
997 +#include "preferences.h"
998 +#include "highlight.h"
1000 +#include "patternMatch.h"
1001 +#include "patternMatchData.h"
1003 +#ifdef HAVE_DEBUG_H
1004 +#include "../debug.h"
1007 +#define MAX_NESTED_PATTERNS 100
1009 +#define IGNORE_HIGHLIGHT_CODE -1
1011 +typedef struct _SearchRegionInfo {
1012 + WindowInfo *sriWindow;
1016 + int sriStartOfTextPos;
1017 +} SearchRegionInfo;
1019 +typedef struct _FoundStringInfo {
1020 + char *fsiStartPtr;
1025 + const char *fsiDelimiters;
1028 +typedef struct _BackRefInfo {
1030 + int briCaseInsensitive;
1031 + char *briStartPtr[MAX_GLOBAL_BACK_REF_ID];
1032 + char *briEndPtr[MAX_GLOBAL_BACK_REF_ID];
1035 +typedef struct _MatchingElementInfo {
1036 + MatchPatternTableElement *meiElement;
1037 + PatternReference meiPatRef;
1039 + int meiHighLightCode;
1040 + int meiAbsStartPos;
1042 + BackRefInfo meiBackRefInfo;
1043 +} MatchingElementInfo;
1045 +typedef struct _PatternStackElement {
1046 + PatternReference psePatRef;
1047 + int pseHighLightCode;
1048 + BackRefInfo pseBackRefInfo;
1049 +} PatternStackElement;
1052 + * Prototypes of local functions
1054 +void adaptPatternPositions(
1055 + MatchingType matchingType,
1058 + int startPatternLength,
1060 + int matchedPatternLength);
1062 +static int findMatchingStringElement(
1063 + StringMatchTable *smTable,
1064 + SearchRegionInfo *searchRegion,
1065 + MatchingElementInfo *matchInfo,
1067 + const char *delimiters);
1069 +static PatternElementMonoInfo determineMonoPatInfo(
1070 + WindowInfo *window,
1071 + int patHighLightCode,
1074 + PatternElementKind *patElementKind);
1076 +static void assignBackRefInfo(
1077 + StringPattern *strPat,
1078 + BackRefInfo *backRefInfo);
1079 +static int doesBackRefInfoMatch(
1080 + BackRefInfo *backRefInfo1,
1081 + BackRefInfo *backRefInfo2);
1082 +static int compareBackRef(
1087 + int caseInsensitive);
1089 +static int doesPatternElementMatch(
1090 + PatternElement *patElement,
1091 + FoundStringInfo *foundStringInfo,
1092 + BackRefInfo *backRefInfo);
1093 +static int doesMPTableElementMatch(
1094 + MatchPatternTableElement *element,
1095 + FoundStringInfo *foundStringInfo,
1096 + PatternElementKind *patternElementKind,
1097 + int *patternElementIdx,
1098 + BackRefInfo *backRefInfo);
1099 +static int getPatternInfo(
1100 + MatchPatternTable *table,
1101 + FoundStringInfo *foundStringInfo,
1102 + PatternReference *patRef,
1103 + BackRefInfo *backRefInfo);
1105 +static int isPartOfPattern(
1106 + MatchPatternTable *table,
1107 + int parentElementIdx,
1108 + int childElementIdx,
1109 + PatternElementKind patElementKind);
1110 +static int isPartOfPatternElementSet(
1111 + PatternElementSet *patElementSet,
1112 + int patternElementIdx);
1113 +static int isPartOfMiddlePatternElementSet(
1114 + PatternElementSet *patElementSet,
1115 + int patternElementIdx);
1116 +static void considerNextPatternReference(
1117 + MatchPatternTable *table,
1118 + PatternReference *startPatRef,
1119 + PatternReference nxtPatRef,
1122 +static int searchPatternForward(
1123 + MatchPatternTable *table,
1124 + regexp *compiledRE,
1125 + SearchRegionInfo *searchRegion,
1126 + const char *delimiters,
1129 + PatternReference *patRef,
1130 + int *highLightCode,
1131 + BackRefInfo *backRefInfo);
1132 +static int searchPatternBackward(
1133 + MatchPatternTable *table,
1134 + regexp *compiledRE,
1135 + SearchRegionInfo *searchRegion,
1136 + const char *delimiters,
1138 + PatternReference *patRef,
1139 + int *highLightCode,
1140 + int *matchedPatternLength,
1141 + BackRefInfo *backRefInfo);
1143 +static int parseStringElementForward(
1144 + MatchingElementInfo *matchInfo,
1145 + SearchRegionInfo *searchRegion,
1148 + int *matchedPatternLength,
1149 + const char *delimiters);
1150 +static int findRelatedForwardPattern(
1151 + StringMatchTable *table,
1152 + SearchRegionInfo *searchRegion,
1153 + const char *delimiters,
1154 + PatternReference beginPatRef,
1155 + int beginPatHighLightCode,
1156 + BackRefInfo *beginPatBackRefInfo,
1158 + int *matchEndPos);
1160 +static int parseStringElementBackward(
1161 + MatchingElementInfo *matchInfo,
1162 + SearchRegionInfo *searchRegion,
1165 + int *matchedPatternLength,
1166 + const char *delimiters);
1167 +static int findRelatedStartPattern(
1168 + StringMatchTable *table,
1169 + SearchRegionInfo *searchRegion,
1170 + const char *delimiters,
1171 + PatternReference beginPatRef,
1172 + int beginPatHighLightCode,
1173 + BackRefInfo *beginPatBackRefInfo,
1175 + int *matchedPatternLength);
1176 +static void considerStackPatReference(
1177 + PatternElementSet *patSet,
1178 + int stackElementIdx,
1179 + int *foundElementIdx);
1181 +static int getPatternLocatedAtPos(
1182 + regexp *usedPatRE,
1183 + MatchPatternTable *table,
1184 + SearchRegionInfo *searchRegion,
1186 + MatchingElementInfo *matchInfo,
1187 + const char *delimiters);
1188 +static int getMatchedElementInfo(
1189 + WindowInfo *window,
1190 + MatchPatternTable *table,
1191 + FoundStringInfo *foundStringInfo,
1192 + MatchingElementInfo *matchInfo);
1194 +static PatternElement *getPatternOfReference(
1195 + MatchPatternTable *table,
1196 + PatternReference patRef);
1199 +static char *getPatternForDebug(
1200 + MatchPatternTable *table,
1201 + PatternReference patRef );
1202 +static char *patElemKindToString(
1203 + PatternElementKind patElemKind);
1204 +static void printFoundStringForDebug(
1205 + WindowInfo *window,
1211 +** Try to find a matching pattern string related to the given "charPos"
1212 +** inside the given range (defined by startLimit & endLimit).
1213 +** Determine the matching position & the match pattern length (depending
1214 +** on given matchingType), if a matching pattern was found.
1215 +** Returns true, if a matching pattern string was found.
1217 +int FindMatchingString(
1218 + WindowInfo *window,
1219 + MatchingType matchingType,
1224 + int *matchedPatternLength,
1227 + StringMatchTable *smTable = (StringMatchTable *)window->stringMatchTable;
1228 + const char *delimiters;
1229 + SearchRegionInfo searchRegion;
1230 + MatchingElementInfo matchInfo;
1231 + int matchingPatternFound = FALSE;
1234 + if (smTable == NULL || smTable->smtAllPatRE == NULL)
1237 + * No match pattern table available:
1243 + * Get delimiters related to window
1245 + delimiters = GetWindowDelimiters(window);
1246 + if (delimiters == NULL)
1247 + delimiters = GetPrefDelimiters();
1250 + * Select the start pattern reg. exp. to use
1252 + if (matchingType == MT_FLASH_RANGE ||
1253 + matchingType == MT_FLASH_DELIMIT)
1255 + smTable->smtUsedPatRE = smTable->smtFlashPatRE;
1259 + smTable->smtUsedPatRE = smTable->smtAllPatRE;
1263 + * Get a copy of the text buffer area to parse
1265 + searchRegion.sriWindow = window;
1266 + searchRegion.sriText = BufGetRange(window->buffer, startLimit, endLimit);
1267 + searchRegion.sriPrevChar = BufGetCharacter(window->buffer, startLimit - 1);
1268 + searchRegion.sriSuccChar = BufGetCharacter(window->buffer, endLimit);
1269 + searchRegion.sriStartOfTextPos = startLimit;
1271 + relCharPos = *charPos - startLimit;
1274 + * Try to find a matching pattern string using string match table
1277 + if (findMatchingStringElement(
1285 + printf("--- Start at : ");
1286 + printFoundStringForDebug(
1288 + matchInfo.meiAbsStartPos,
1289 + matchInfo.meiLength);
1292 + if (matchInfo.meiDirection == SEARCH_FORWARD)
1294 + matchingPatternFound =
1295 + parseStringElementForward(
1300 + matchedPatternLength,
1305 + matchingPatternFound =
1306 + parseStringElementBackward(
1311 + matchedPatternLength,
1315 + if (matchingPatternFound)
1318 + * Calc. abs. start char pos. (may have been changed if
1319 + * cursor was located inside a string pattern). Adapt
1320 + * pattern positions depending on matchingType.
1322 + *charPos = relCharPos + startLimit;
1323 + *direction = matchInfo.meiDirection;
1325 + adaptPatternPositions(
1327 + matchInfo.meiDirection,
1329 + matchInfo.meiLength,
1331 + *matchedPatternLength);
1335 + XtFree(searchRegion.sriText);
1337 + return matchingPatternFound;
1341 +** Adapt match pattern position / start position depending on the
1342 +** given matching type.
1344 +void adaptPatternPositions(
1345 + MatchingType matchingType,
1348 + int startPatternLength,
1350 + int matchedPatternLength)
1352 + switch (matchingType)
1354 + case MT_FLASH_DELIMIT:
1356 + if (direction == SEARCH_FORWARD)
1358 + (*matchPos) -= matchedPatternLength - 1;
1362 + case MT_FLASH_RANGE:
1364 + if (direction == SEARCH_FORWARD)
1366 + (*charPos) -= startPatternLength;
1375 + if (direction == SEARCH_FORWARD)
1381 + (*matchPos) += matchedPatternLength;
1388 +** Try to find a string pattern at given buffer position 'charPos'.
1389 +** A string pattern is found, if pattern is located before 'charPos' or
1390 +** 'charPos' is located within a pattern.
1391 +** If a string pattern is found, then search direction and string pattern
1392 +** reference / properties are determined.
1393 +** Returns true, if a string pattern was found.
1395 +static int findMatchingStringElement(
1396 + StringMatchTable *smTable,
1397 + SearchRegionInfo *searchRegion,
1398 + MatchingElementInfo *matchInfo,
1400 + const char *delimiters)
1402 + if (getPatternLocatedAtPos(
1403 + smTable->smtUsedPatRE,
1404 + smTable->smtAllPatterns,
1411 + * Pattern found -> define search direction:
1412 + * - START & MIDDLE pattern: matching pattern is searched in
1413 + * forward direction
1414 + * - END pattern: matching pattern is searched in backward
1417 + if (matchInfo->meiPatRef.prKind == PEK_END)
1418 + matchInfo->meiDirection = SEARCH_BACKWARD;
1420 + matchInfo->meiDirection = SEARCH_FORWARD;
1429 +** Return mono pattern info depending on highlight codes
1430 +** of left / right side of string pattern. Update pattern
1431 +** kind if applicable.
1433 +static PatternElementMonoInfo determineMonoPatInfo(
1434 + WindowInfo *window,
1435 + int patHighLightCode,
1438 + PatternElementKind *patElementKind)
1440 + int leftSideHasSameHC;
1441 + int rightSideHasSameHC;
1444 + * Determine, if left side holds same highlight code than
1445 + * found string pattern
1448 + leftSideHasSameHC =
1449 + (HighlightCodeOfPos(window, leftPos) == patHighLightCode);
1451 + leftSideHasSameHC = FALSE;
1454 + * Determine, if right side holds same highlight code than
1455 + * found string pattern
1457 + if (rightPos < window->buffer->length)
1458 + rightSideHasSameHC =
1459 + (HighlightCodeOfPos(window, rightPos) == patHighLightCode);
1461 + rightSideHasSameHC = FALSE;
1463 + if ((rightSideHasSameHC && leftSideHasSameHC) ||
1464 + (!rightSideHasSameHC && !leftSideHasSameHC))
1466 + return PEMI_MONO_AMBIGUOUS_SYNTAX;
1468 + else if (leftSideHasSameHC)
1470 + *patElementKind = PEK_END;
1471 + return PEMI_MONO_DEFINITE_SYNTAX;
1475 + *patElementKind = PEK_START;
1476 + return PEMI_MONO_DEFINITE_SYNTAX;
1481 +** Get backref info out of found string pattern and
1482 +** put it into given backRefInfo.
1484 +static void assignBackRefInfo(
1485 + StringPattern *strPat,
1486 + BackRefInfo *backRefInfo)
1490 + regexp *patRE = strPat->spTextRE;
1492 + backRefInfo->briAvailable = FALSE;
1493 + backRefInfo->briCaseInsensitive = strPat->spCaseInsensitive;
1495 + for (i=0; i<MAX_GLOBAL_BACK_REF_ID; i++)
1497 + localId = strPat->spGlobalToLocalBackRef[i];
1499 + if (localId != NO_LOCAL_BACK_REF_ID)
1501 + backRefInfo->briAvailable = TRUE;
1503 + backRefInfo->briStartPtr[i] = patRE->startp[localId];
1504 + backRefInfo->briEndPtr[i] = patRE->endp[localId];
1508 + backRefInfo->briStartPtr[i] = NULL;
1509 + backRefInfo->briEndPtr[i] = NULL;
1515 +** Check, if given backref infos match.
1516 +** Returns true, if backref infos match.
1518 +static int doesBackRefInfoMatch(
1519 + BackRefInfo *backRefInfo1,
1520 + BackRefInfo *backRefInfo2)
1525 + * if min. one string pattern doesn't hold backref info, then nothing
1526 + * could be compared -> both string pattern are matching.
1528 + if (!backRefInfo1->briAvailable || !backRefInfo2->briAvailable)
1531 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
1533 + if (!compareBackRef(
1534 + backRefInfo1->briStartPtr[i],
1535 + backRefInfo1->briEndPtr[i],
1536 + backRefInfo2->briStartPtr[i],
1537 + backRefInfo2->briEndPtr[i],
1538 + backRefInfo1->briCaseInsensitive || backRefInfo2->briCaseInsensitive))
1548 +** Compares two backref content.
1549 +** Returns true, if backref contents match.
1551 +static int compareBackRef(
1556 + int caseInsensitive)
1561 + if (startPtr1 == NULL && startPtr2 == NULL)
1564 + if (startPtr1 == NULL || startPtr2 == NULL)
1567 + if ((endPtr1 - startPtr1) != (endPtr2 - startPtr2))
1573 + if (caseInsensitive)
1575 + while (s1 != endPtr1)
1577 + if (tolower((unsigned char)*s1++) != tolower((unsigned char)*s2++))
1583 + while (s1 != endPtr1)
1585 + if (*s1++ != *s2++)
1593 +** Verify if given pattern element is located between given
1594 +** start / end pointer of "foundStringInfo". Assign backreference
1595 +** information, if pattern element matches.
1596 +** Returns true, if given pattern element matches.
1598 +static int doesPatternElementMatch(
1599 + PatternElement *patElement,
1600 + FoundStringInfo *foundStringInfo,
1601 + BackRefInfo *backRefInfo)
1605 + StringPattern *strPat;
1608 + switch (patElement->peType)
1611 + strPat = &patElement->peVal.peuSingle;
1613 + case PET_MULTIPLE:
1614 + strPat = &patElement->peVal.peuMulti.mpStringPattern;
1620 + if (strPat->spRegularExpression)
1623 + * check reg. expression:
1628 + foundStringInfo->fsiStartPtr,
1629 + foundStringInfo->fsiEndPtr,
1631 + foundStringInfo->fsiPrevChar,
1632 + foundStringInfo->fsiSuccChar,
1633 + foundStringInfo->fsiDelimiters,
1638 + assignBackRefInfo(strPat, backRefInfo);
1640 + return elementMatch;
1644 + backRefInfo->briAvailable = FALSE;
1647 + * check literal string:
1649 + p = strPat->spText;
1652 + * if length of found string is different from length of
1653 + * given string pattern, then there is no match.
1655 + if (strPat->spLength != foundStringInfo->fsiLength)
1658 + s = foundStringInfo->fsiStartPtr;
1660 + if (strPat->spCaseInsensitive)
1662 + while (s != foundStringInfo->fsiEndPtr)
1664 + if (tolower((unsigned char)*s++) != *p++)
1670 + while (s != foundStringInfo->fsiEndPtr)
1682 +** Verify if a pattern element of given MatchPatternTableElement is
1683 +** located between given start / end pointer of "foundStringInfo".
1684 +** Returns true, if so.
1686 +static int doesMPTableElementMatch(
1687 + MatchPatternTableElement *element,
1688 + FoundStringInfo *foundStringInfo,
1689 + PatternElementKind *patternElementKind,
1690 + int *patternElementIdx,
1691 + BackRefInfo *backRefInfo)
1695 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
1697 + if (doesPatternElementMatch(
1698 + element->mpteAll.pesPattern[i],
1702 + *patternElementKind = element->mpteAll.pesPattern[i]->peKind;
1703 + *patternElementIdx = i;
1713 +** Determine the pattern element of given MatchPatternTable, which is
1714 +** located between given start / end pointer of "foundStringInfo".
1715 +** Setup related pattern element reference.
1716 +** Returns true, if a pattern element was found.
1718 +static int getPatternInfo(
1719 + MatchPatternTable *table,
1720 + FoundStringInfo *foundStringInfo,
1721 + PatternReference *patRef,
1722 + BackRefInfo *backRefInfo)
1726 + for (i=0; i<table->mptNumberOfElements; i++)
1728 + if (doesMPTableElementMatch(
1729 + table->mptElements[i],
1732 + &patRef->prPatternIdx,
1735 + patRef->prElementIdx = i;
1742 + * Should never been reached !
1744 + patRef->prElementIdx = NO_ELEMENT_IDX;
1745 + patRef->prKind = PEK_UNKNOWN;
1746 + patRef->prPatternIdx = NO_PATTERN_IDX;
1752 +** Check, if given child pattern element is part of given
1753 +** parent pattern element.
1754 +** Returns true, if child is part of parent.
1756 +static int isPartOfPattern(
1757 + MatchPatternTable *table,
1758 + int parentElementIdx,
1759 + int childElementIdx,
1760 + PatternElementKind patElementKind)
1762 + MatchPatternTableElement *parent = table->mptElements[parentElementIdx];
1763 + MatchPatternTableElement *child = table->mptElements[childElementIdx];
1765 + if (childElementIdx == parentElementIdx)
1768 + if (patElementKind == PEK_START)
1770 + if (isPartOfPatternElementSet(&parent->mpteStart, childElementIdx))
1773 + return( isPartOfPatternElementSet(&child->mpteStart, parentElementIdx) );
1775 + else if (patElementKind == PEK_END)
1777 + if (isPartOfPatternElementSet(&parent->mpteEnd, childElementIdx))
1780 + return( isPartOfPatternElementSet(&child->mpteEnd, parentElementIdx) );
1785 + * Given child pattern element is middle pattern: the given pattern element
1786 + * is part of parent pattern, if it's a reference of a middle pattern
1788 + if (isPartOfMiddlePatternElementSet(&parent->mpteMiddle, childElementIdx))
1791 + return( isPartOfMiddlePatternElementSet(&child->mpteMiddle, parentElementIdx) );
1796 +** Check, if given pattern element is part of given pattern element set.
1797 +** Returns true, if so.
1799 +static int isPartOfPatternElementSet(
1800 + PatternElementSet *patElementSet,
1801 + int patternElementIdx)
1803 + PatternElement *patElement;
1806 + for (i=0; i<patElementSet->pesNumberOfPattern; i++)
1808 + if (patElementSet->pesPattern[i]->peType == PET_REFERENCE)
1810 + patElement = patElementSet->pesPattern[i];
1812 + if (patElement->peVal.peuRef.prElementIdx == patternElementIdx)
1823 +** Verify, if given pattern element is part of middle pattern set.
1824 +** That's the case, if an element of the pattern set is reference
1825 +** of a middle pattern, which fits to given pattern element.
1826 +** Returns true, if pattern element is part of middle pattern set.
1828 +static int isPartOfMiddlePatternElementSet(
1829 + PatternElementSet *patElementSet,
1830 + int patternElementIdx)
1832 + PatternElement *patElement;
1835 + for (i=0; i<patElementSet->pesNumberOfPattern; i++)
1837 + if (patElementSet->pesPattern[i]->peType == PET_REFERENCE)
1839 + patElement = patElementSet->pesPattern[i];
1841 + if (patElement->peVal.peuRef.prElementIdx == patternElementIdx &&
1842 + patElement->peKind == PEK_MIDDLE)
1853 +** Update start pattern reference depending on next pattern located
1854 +** after start pattern.
1856 +static void considerNextPatternReference(
1857 + MatchPatternTable *table,
1858 + PatternReference *startPatRef,
1859 + PatternReference nxtPatRef,
1862 + MatchPatternTableElement *tabElement;
1863 + PatternElement *startPat;
1864 + MultiPattern *multiStartPat;
1865 + PatternReference patRef;
1869 + * startPatRef needs no adaption, if element index of start pattern
1870 + * and next pattern are equal (i.e. start and next pattern belong
1871 + * to same pattern element).
1873 + if (startPatRef->prElementIdx == nxtPatRef.prElementIdx)
1877 + * Verify, if start pattern belongs to multiple pattern elements
1878 + * (like "ELSE .. FI" & "ELSE .. ESAC").
1880 + startPat = getPatternOfReference( table, *startPatRef );
1882 + if (startPat->peType == PET_MULTIPLE)
1885 + * Check, if next pattern fits to one of the references of
1886 + * the start multi pattern. If so: adapt start pattern reference.
1888 + multiStartPat = &startPat->peVal.peuMulti;
1890 + for (i=0; i<multiStartPat->mpNumberOfReferences; i ++)
1892 + patRef = multiStartPat->mpRefList[i];
1893 + tabElement = table->mptElements[patRef.prElementIdx];
1895 + if (nxtPatRef.prElementIdx == patRef.prElementIdx &&
1896 + tabElement->mpteGroup == groupIdx)
1898 + *startPatRef = patRef;
1906 +** Search for a string pattern in forward direction, starting at
1907 +** given beginPos. Determine related pattern reference of a found
1909 +** Returns true, if a next string pattern was found.
1911 +static int searchPatternForward(
1912 + MatchPatternTable *table,
1913 + regexp *compiledRE,
1914 + SearchRegionInfo *searchRegion,
1915 + const char *delimiters,
1918 + PatternReference *patRef,
1919 + int *highLightCode,
1920 + BackRefInfo *backRefInfo)
1922 + FoundStringInfo foundStringInfo;
1923 + int matchStartPos;
1924 + int absMatchStartPos;
1925 + MatchPatternTableElement *matchedElement;
1927 + *matchEndPos = -1;
1929 + patRef->prElementIdx = NO_ELEMENT_IDX;
1930 + patRef->prKind = PEK_UNKNOWN;
1931 + patRef->prPatternIdx = NO_PATTERN_IDX;
1933 + *highLightCode = IGNORE_HIGHLIGHT_CODE;
1937 + searchRegion->sriText + beginPos,
1940 + beginPos==0 ? searchRegion->sriPrevChar : searchRegion->sriText[beginPos-1],
1941 + searchRegion->sriSuccChar,
1943 + searchRegion->sriText,
1946 + foundStringInfo.fsiStartPtr = compiledRE->startp[0];
1947 + foundStringInfo.fsiEndPtr = compiledRE->endp[0];
1948 + foundStringInfo.fsiLength =
1949 + foundStringInfo.fsiEndPtr - foundStringInfo.fsiStartPtr;
1951 + foundStringInfo.fsiPrevChar =
1952 + foundStringInfo.fsiStartPtr == searchRegion->sriText ?
1953 + searchRegion->sriPrevChar : *(foundStringInfo.fsiStartPtr - 1);
1955 + foundStringInfo.fsiSuccChar =
1956 + *(foundStringInfo.fsiEndPtr) == '\0' ?
1957 + searchRegion->sriSuccChar : *(foundStringInfo.fsiEndPtr);
1959 + foundStringInfo.fsiDelimiters = delimiters;
1961 + if (getPatternInfo(
1968 + * Next string pattern was found in forward direction and
1969 + * a pattern reference could be assigned to: calculate
1970 + * relative & absolute match positions.
1972 + matchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
1973 + *matchEndPos = foundStringInfo.fsiEndPtr - searchRegion->sriText;
1975 + absMatchStartPos = matchStartPos + searchRegion->sriStartOfTextPos;
1977 + matchedElement = table->mptElements[patRef->prElementIdx];
1980 + * get highlight code of found string pattern, if applicable
1982 + if (!matchedElement->mpteIgnoreHighLightInfo)
1985 + HighlightCodeOfPos(searchRegion->sriWindow, absMatchStartPos);
1989 + * setup mono pattern info of found string pattern
1991 + if (matchedElement->mpteIsMonoPattern)
1993 + if (matchedElement->mpteIgnoreHighLightInfo)
1995 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
2000 + * determine mono pattern info depending on highLightCodes
2001 + * before / after found string pattern.
2003 + patRef->prMonoInfo =
2004 + determineMonoPatInfo(
2005 + searchRegion->sriWindow,
2007 + absMatchStartPos - 1,
2008 + *matchEndPos + searchRegion->sriStartOfTextPos,
2014 + patRef->prMonoInfo = PEMI_NOT_MONO;
2017 + return matchStartPos;
2022 + * Found string can't be assigned to a pattern element
2023 + * (should never occur).
2031 + * No next string pattern is found in forward direction.
2038 +** Search for a string pattern in backward direction, starting at
2039 +** given beginPos. Determine related pattern reference of a found
2041 +** Returns true, if a next string pattern was found.
2043 +static int searchPatternBackward(
2044 + MatchPatternTable *table,
2045 + regexp *compiledRE,
2046 + SearchRegionInfo *searchRegion,
2047 + const char *delimiters,
2049 + PatternReference *patRef,
2050 + int *highLightCode,
2051 + int *matchedPatternLength,
2052 + BackRefInfo *backRefInfo)
2054 + FoundStringInfo foundStringInfo;
2055 + int matchStartPos;
2056 + int absMatchStartPos;
2057 + MatchPatternTableElement *matchedElement;
2059 + patRef->prElementIdx = NO_ELEMENT_IDX;
2060 + patRef->prKind = PEK_UNKNOWN;
2061 + patRef->prPatternIdx = NO_PATTERN_IDX;
2063 + *highLightCode = IGNORE_HIGHLIGHT_CODE;
2067 + searchRegion->sriText,
2068 + searchRegion->sriText + beginPos,
2070 + searchRegion->sriPrevChar,
2071 + searchRegion->sriText[beginPos] == '\0' ?
2072 + searchRegion->sriSuccChar : searchRegion->sriText[beginPos + 1],
2074 + searchRegion->sriText,
2077 + foundStringInfo.fsiStartPtr = compiledRE->startp[0];
2078 + foundStringInfo.fsiEndPtr = compiledRE->endp[0];
2079 + foundStringInfo.fsiLength =
2080 + foundStringInfo.fsiEndPtr - foundStringInfo.fsiStartPtr;
2082 + foundStringInfo.fsiPrevChar =
2083 + foundStringInfo.fsiStartPtr == searchRegion->sriText ?
2084 + searchRegion->sriPrevChar : *(foundStringInfo.fsiStartPtr - 1);
2086 + foundStringInfo.fsiSuccChar =
2087 + *(foundStringInfo.fsiEndPtr) == '\0' ?
2088 + searchRegion->sriSuccChar : *(foundStringInfo.fsiEndPtr);
2090 + foundStringInfo.fsiDelimiters = delimiters;
2092 + if (getPatternInfo(
2099 + * Next string pattern was found in backward direction and
2100 + * a pattern reference could be assigned to: calculate
2101 + * relative & absolute match positions.
2103 + matchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
2104 + *matchedPatternLength = foundStringInfo.fsiLength;
2106 + absMatchStartPos = matchStartPos + searchRegion->sriStartOfTextPos;
2108 + matchedElement = table->mptElements[patRef->prElementIdx];
2111 + * get highlight code of found string pattern, if applicable
2113 + if (!matchedElement->mpteIgnoreHighLightInfo)
2116 + HighlightCodeOfPos(searchRegion->sriWindow, absMatchStartPos);
2120 + * setup mono pattern info of found string pattern
2122 + if (matchedElement->mpteIsMonoPattern)
2124 + if (matchedElement->mpteIgnoreHighLightInfo)
2126 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
2131 + * determine mono pattern info depending on highLightCodes
2132 + * before / after found string pattern.
2134 + patRef->prMonoInfo =
2135 + determineMonoPatInfo(
2136 + searchRegion->sriWindow,
2138 + absMatchStartPos - 1,
2139 + absMatchStartPos + *matchedPatternLength,
2145 + patRef->prMonoInfo = PEMI_NOT_MONO;
2148 + return matchStartPos;
2153 + * Found string can't be assigned to a pattern element
2154 + * (should never occur).
2162 + * No next string pattern is found in backward direction.
2169 +** Find matching pattern related to given pattern (stored in
2170 +** 'matchInfo') in forward direction by considering the rules stored in
2171 +** string match table of given window. Determine match position (= abs.
2172 +** pos. of last character of matching string) and length of matching
2173 +** string. If a mono matching pattern couldn't be found in forward
2174 +** direction, then try finding it in backward direction (if found in
2175 +** backward direction, then match position indicates the 1st char. of
2176 +** matching string).
2177 +** Returns true, if a matching pattern was found.
2179 +static int parseStringElementForward(
2180 + MatchingElementInfo *matchInfo,
2181 + SearchRegionInfo *searchRegion,
2184 + int *matchedPatternLength,
2185 + const char *delimiters)
2187 + StringMatchTable *smTable =
2188 + (StringMatchTable *)searchRegion->sriWindow->stringMatchTable;
2189 + MatchPatternTableElement *matchElement = matchInfo->meiElement;
2190 + int beginPos = relCharPos;
2192 + int startStartPos;
2194 + int matchingPatternFound = FALSE;
2197 + * Find matching pattern within text buffer area to parse in
2198 + * forward direction.
2201 + findRelatedForwardPattern(
2205 + matchInfo->meiPatRef,
2206 + matchInfo->meiHighLightCode,
2207 + &matchInfo->meiBackRefInfo,
2211 + if (endEndPos != -1)
2213 + *matchPos = endEndPos - 1 + searchRegion->sriStartOfTextPos;
2214 + *matchedPatternLength = endEndPos - endStartPos;
2216 + matchingPatternFound = TRUE;
2218 + else if (matchElement->mpteIsMonoPattern)
2221 + * mono pattern: forward find fails -> try backward direction.
2222 + * Calc. relative position of 1st char. before found string pattern.
2224 + beginPos = beginPos - matchInfo->meiLength - 1;
2229 + findRelatedStartPattern(
2233 + matchInfo->meiPatRef,
2234 + matchInfo->meiHighLightCode,
2235 + &matchInfo->meiBackRefInfo,
2237 + matchedPatternLength);
2239 + if (startStartPos != -1)
2241 + matchInfo->meiDirection = SEARCH_BACKWARD;
2243 + *matchPos = startStartPos + searchRegion->sriStartOfTextPos;
2245 + matchingPatternFound = TRUE;
2250 + return matchingPatternFound;
2254 +** Find matching pattern related to given begin pattern reference
2255 +** in forward direction by considering the rules stored in given
2256 +** string match table. Determine match position (= relative
2257 +** pos. of last character of matching string).
2258 +** Returns -1, if no matching pattern was found. Else the relative
2259 +** position of 1st char. of matching string is returned.
2261 +static int findRelatedForwardPattern(
2262 + StringMatchTable *table,
2263 + SearchRegionInfo *searchRegion,
2264 + const char *delimiters,
2265 + PatternReference beginPatRef,
2266 + int beginPatHighLightCode,
2267 + BackRefInfo *beginPatBackRefInfo,
2271 + MatchPatternTable *patTable = table->smtAllPatterns;
2272 + int startPos = beginPos;
2273 + int nxtPatStartPos = 0;
2274 + int nxtPatEndPos = 0;
2275 + PatternReference nxtPatRef;
2276 + int nxtPatHighLightCode;
2277 + BackRefInfo nxtPatBackRefInfo;
2278 + PatternStackElement stack[MAX_NESTED_PATTERNS];
2280 + PatternReference startPatRef;
2281 + MatchPatternTableElement *currentElement;
2283 + regexp *groupPatRE;
2284 + regexp *currentPatRE;
2285 + int skipToEnd = FALSE;
2286 + int beginPatternIsMono;
2289 + printf("Forward Start Pos: %d K: %s EI: %d PI: %d HC: %d <%s>\n",
2291 + patElemKindToString(beginPatRef.prKind),
2292 + beginPatRef.prElementIdx,
2293 + beginPatRef.prPatternIdx,
2294 + beginPatHighLightCode,
2295 + getPatternForDebug(patTable, beginPatRef) );
2299 + * put begin pattern info on stack
2301 + stack[stackIdx].psePatRef = beginPatRef;
2302 + stack[stackIdx].pseHighLightCode = beginPatHighLightCode;
2303 + stack[stackIdx].pseBackRefInfo = *beginPatBackRefInfo;
2306 + currentElement = patTable->mptElements[beginPatRef.prElementIdx];
2308 + beginPatternIsMono = currentElement->mpteIsMonoPattern;
2310 + groupIdx = currentElement->mpteGroup;
2313 + * no next pattern can be found, if there is no group assigned
2314 + * to begin pattern (should never occur)
2316 + if (groupIdx == NO_GROUP_IDX)
2318 + *matchEndPos = -1;
2324 + * Remember pattern (= keywords) regular expression of context
2325 + * group related to begin pattern. Use it for forward search.
2327 + groupPatRE = table->smtGroups[groupIdx]->mpgeKeywordRE;
2328 + currentPatRE = groupPatRE;
2331 + * Use start / end pattern regular expression if skip to end is
2332 + * set for begin pattern.
2334 + if (currentElement->mpteSkipBtwnStartEnd)
2336 + currentPatRE = currentElement->mpteStartEndRE;
2340 + while (stackIdx > 0 && nxtPatStartPos != -1)
2343 + * Search for next string pattern in forward direction.
2346 + searchPatternForward(
2354 + &nxtPatHighLightCode,
2355 + &nxtPatBackRefInfo );
2357 + startPatRef = stack[stackIdx-1].psePatRef;
2359 + if (nxtPatStartPos == -1)
2362 + * no next pattern found -> leave loop
2365 + printf(" SI: %d [start K: %s EI: %d PI %d] Pos: %d --> no next pat. found\n",
2367 + patElemKindToString(startPatRef.prKind),
2368 + startPatRef.prElementIdx,
2369 + startPatRef.prPatternIdx,
2376 + * Update start pattern reference depending on next pattern
2377 + * located after start pattern.
2379 + considerNextPatternReference(
2386 + * If current found match pattern table element is a mono pattern and
2387 + * skip to start pattern is active, then the found pattern string is
2388 + * a END one in case of ambiguous or no syntax was detected.
2391 + (nxtPatRef.prMonoInfo == PEMI_MONO_AMBIGUOUS_SYNTAX ||
2392 + nxtPatRef.prMonoInfo == PEMI_MONO_NOT_SYNTAX_BASED))
2394 + nxtPatRef.prKind = PEK_END;
2398 + printf(" SI: %d [start K: %s EI: %d PI %d] Pos: %d-%d K: %s EI: %d PI: %d HC: %d f=<%s> ",
2400 + patElemKindToString(startPatRef.prKind),
2401 + startPatRef.prElementIdx,
2402 + startPatRef.prPatternIdx,
2405 + patElemKindToString(nxtPatRef.prKind),
2406 + nxtPatRef.prElementIdx,
2407 + nxtPatRef.prPatternIdx,
2408 + nxtPatHighLightCode,
2409 + getPatternForDebug(patTable, nxtPatRef) );
2410 + printFoundStringForDebug(
2411 + searchRegion->sriWindow,
2412 + nxtPatStartPos + searchRegion->sriStartOfTextPos,
2413 + nxtPatEndPos - nxtPatStartPos);
2417 + if (nxtPatRef.prKind == PEK_START)
2419 + if (stackIdx >= MAX_NESTED_PATTERNS)
2422 + printf("FORWARD: MAX. NESTED PATTERN DEPTH REACHED !\n");
2424 + nxtPatStartPos = -1;
2425 + nxtPatEndPos = -1;
2427 + else if (!skipToEnd)
2430 + * Put next pattern on stack, if contents between start /
2431 + * end shouldn't be skipped (if "skipToEnd" is set,
2432 + * a (usually illegal) start pattern to skip inside the
2433 + * skipped one is found (e.g. \* \* ..)
2435 + stack[stackIdx].psePatRef = nxtPatRef;
2436 + stack[stackIdx].pseHighLightCode = nxtPatHighLightCode;
2437 + stack[stackIdx].pseBackRefInfo = nxtPatBackRefInfo;
2440 + currentElement = patTable->mptElements[nxtPatRef.prElementIdx];
2443 + * Use start / end pattern regular expression if skip to
2444 + * end is set for found start pattern.
2446 + if (currentElement->mpteSkipBtwnStartEnd)
2448 + currentPatRE = currentElement->mpteStartEndRE;
2452 + else if (beginPatternIsMono)
2455 + * skip to end is set and a mono pattern start is reached:
2456 + * trigger backward search by returning "not found"
2459 + printf(" ---> mono pattern (re-)start -> trigger backward search\n");
2461 + nxtPatStartPos = -1;
2462 + nxtPatEndPos = -1;
2467 + printf(" ---> skip to end: illegal (re-)start pattern !\n");
2471 + else if (nxtPatRef.prKind == PEK_END)
2474 + * ignore current found pattern, if it doesn't fit to the prev.
2477 + if (isPartOfPattern(
2479 + nxtPatRef.prElementIdx,
2480 + startPatRef.prElementIdx,
2482 + (stack[stackIdx - 1].pseHighLightCode == nxtPatHighLightCode ||
2483 + stack[stackIdx - 1].pseHighLightCode == IGNORE_HIGHLIGHT_CODE ||
2484 + nxtPatHighLightCode == IGNORE_HIGHLIGHT_CODE) &&
2485 + doesBackRefInfoMatch(
2486 + &stack[stackIdx - 1].pseBackRefInfo,
2487 + &nxtPatBackRefInfo))
2490 + * use context group pattern again, if end pattern to skip
2495 + currentPatRE = groupPatRE;
2496 + skipToEnd = FALSE;
2500 + * pop. related start pattern from stack.
2505 + else if (!skipToEnd)
2508 + * middle pattern was found: ignore it, if found middle pattern
2509 + * doesn't belong to begin pattern.
2511 + if (stackIdx == 1 &&
2514 + startPatRef.prElementIdx,
2515 + nxtPatRef.prElementIdx,
2516 + nxtPatRef.prKind) &&
2517 + (beginPatHighLightCode == nxtPatHighLightCode ||
2518 + beginPatHighLightCode == IGNORE_HIGHLIGHT_CODE ||
2519 + nxtPatHighLightCode == IGNORE_HIGHLIGHT_CODE) &&
2520 + doesBackRefInfoMatch(
2521 + beginPatBackRefInfo,
2522 + &nxtPatBackRefInfo))
2529 + startPos = nxtPatEndPos;
2532 + *matchEndPos = nxtPatEndPos;
2534 + return nxtPatStartPos;
2538 +** Find matching pattern related to given pattern (stored in
2539 +** 'matchInfo') in backward direction by considering the rules stored in
2540 +** string match table of given window. Determine match position (= abs.
2541 +** pos. of 1st character of matching string) and length of matching
2543 +** Returns true, if a matching pattern was found.
2545 +static int parseStringElementBackward(
2546 + MatchingElementInfo *matchInfo,
2547 + SearchRegionInfo *searchRegion,
2550 + int *matchedPatternLength,
2551 + const char *delimiters)
2553 + StringMatchTable *smTable =
2554 + (StringMatchTable *)searchRegion->sriWindow->stringMatchTable;
2556 + int startStartPos;
2557 + int matchingPatternFound = FALSE;
2560 + * determine begin of search in string buffer (= relative position
2561 + * of 1st char. before found string pattern.)
2563 + beginPos = relCharPos - matchInfo->meiLength - 1;
2569 + * Find matching pattern within text buffer area to parse in
2570 + * backward direction.
2573 + findRelatedStartPattern(
2577 + matchInfo->meiPatRef,
2578 + matchInfo->meiHighLightCode,
2579 + &matchInfo->meiBackRefInfo,
2581 + matchedPatternLength);
2583 + if (startStartPos != -1)
2585 + *matchPos = startStartPos + searchRegion->sriStartOfTextPos;
2586 + matchingPatternFound = TRUE;
2589 + return matchingPatternFound;
2593 +** Find matching pattern related to given begin pattern reference
2594 +** in backward direction by considering the rules stored in given
2595 +** string match table. Determine match position (= relative
2596 +** pos. of 1st character of matching string).
2597 +** Returns -1, if no matching pattern was found. Else the relative
2598 +** position of 1st char. of matching string is returned.
2600 +static int findRelatedStartPattern(
2601 + StringMatchTable *table,
2602 + SearchRegionInfo *searchRegion,
2603 + const char *delimiters,
2604 + PatternReference beginPatRef,
2605 + int beginPatHighLightCode,
2606 + BackRefInfo *beginPatBackRefInfo,
2608 + int *matchedPatternLength)
2610 + MatchPatternTable *patTable = table->smtAllPatterns;
2611 + int startPos = beginPos;
2612 + int prevStartPos = 0;
2613 + PatternReference prevPatRef;
2614 + int prevPatHighLightCode;
2615 + BackRefInfo prevPatBackRefInfo;
2616 + PatternStackElement stack[MAX_NESTED_PATTERNS];
2618 + MatchPatternTableElement *currentElement;
2620 + regexp *groupPatRE;
2621 + regexp *currentPatRE;
2622 + int skipToStart = FALSE;
2625 + * put begin pattern info on stack
2627 + stack[stackIdx].psePatRef = beginPatRef;
2628 + stack[stackIdx].pseHighLightCode = beginPatHighLightCode;
2629 + stack[stackIdx].pseBackRefInfo = *beginPatBackRefInfo;
2632 + currentElement = patTable->mptElements[beginPatRef.prElementIdx];
2635 + printf("Backward Start Pos: %d K: %s EI: %d PI: %d HC: %d <%s>\n",
2637 + patElemKindToString(beginPatRef.prKind),
2638 + beginPatRef.prElementIdx,
2639 + beginPatRef.prPatternIdx,
2640 + beginPatHighLightCode,
2641 + getPatternForDebug(patTable, beginPatRef) );
2644 + groupIdx = currentElement->mpteGroup;
2647 + * no start pattern can be found, if there is no group assigned
2648 + * to begin pattern (should never occur)
2650 + if (groupIdx == NO_GROUP_IDX)
2656 + * Remember pattern (= keywords) regular expression of context
2657 + * group related to begin pattern. Use it for backward search.
2659 + groupPatRE = table->smtGroups[groupIdx]->mpgeKeywordRE;
2660 + currentPatRE = groupPatRE;
2663 + * Use start / end pattern regular expression if skip to start is
2664 + * set for begin pattern.
2666 + if (currentElement->mpteSkipBtwnStartEnd)
2668 + currentPatRE = currentElement->mpteStartEndRE;
2669 + skipToStart = TRUE;
2672 + while (stackIdx > 0 && prevStartPos != -1)
2675 + * Search for previous string pattern in backward direction.
2678 + searchPatternBackward(
2685 + &prevPatHighLightCode,
2686 + matchedPatternLength,
2687 + &prevPatBackRefInfo );
2689 + if (prevStartPos == -1)
2692 + * no previous pattern found -> leave loop
2695 + printf(" SI: %d [K: %s start EI: %d PI %d] Pos: %d --> no next pat. found\n",
2697 + patElemKindToString(stack[stackIdx -1].psePatRef.prKind),
2698 + stack[stackIdx -1].psePatRef.prElementIdx,
2699 + stack[stackIdx -1].psePatRef.prPatternIdx,
2706 + * Update previous pattern reference depending on last stack
2707 + * pattern, which is located in text puffer after previous
2710 + considerNextPatternReference(
2713 + stack[stackIdx - 1].psePatRef,
2717 + * If current found match pattern table element is a mono pattern and
2718 + * skip to start pattern is active, then the found pattern string is
2719 + * a START one in case of ambiguous or no syntax was detected.
2721 + if (skipToStart &&
2722 + (prevPatRef.prMonoInfo == PEMI_MONO_AMBIGUOUS_SYNTAX ||
2723 + prevPatRef.prMonoInfo == PEMI_MONO_NOT_SYNTAX_BASED))
2725 + prevPatRef.prKind = PEK_START;
2729 + printf(" SI: %d [K: %s start EI: %d PI %d] Pos: %d K: %s EI: %d PI: %d HC: %d f=<%s> ",
2731 + patElemKindToString(stack[stackIdx -1].psePatRef.prKind),
2732 + stack[stackIdx -1].psePatRef.prElementIdx,
2733 + stack[stackIdx -1].psePatRef.prPatternIdx,
2735 + patElemKindToString(prevPatRef.prKind),
2736 + prevPatRef.prElementIdx,
2737 + prevPatRef.prPatternIdx,
2738 + prevPatHighLightCode,
2739 + getPatternForDebug(patTable, prevPatRef) );
2740 + printFoundStringForDebug(
2741 + searchRegion->sriWindow,
2742 + prevStartPos + searchRegion->sriStartOfTextPos,
2743 + *matchedPatternLength);
2747 + if (prevPatRef.prKind == PEK_START)
2750 + * If the end pattern of the previous pattern set is a reference,
2751 + * then the prev. element index is the one of the ref. (due to this
2752 + * string was found before and was stored on stack)
2754 + if (patTable->mptElements[prevPatRef.prElementIdx]->mpteGroup == groupIdx)
2756 + considerStackPatReference(
2757 + &patTable->mptElements[prevPatRef.prElementIdx]->mpteEnd,
2758 + stack[stackIdx - 1].psePatRef.prElementIdx,
2759 + &prevPatRef.prElementIdx);
2763 + * Ignore current found pattern, if it doesn't fit to the prev.
2766 + if (stack[stackIdx - 1].psePatRef.prElementIdx == prevPatRef.prElementIdx &&
2767 + (stack[stackIdx - 1].pseHighLightCode == prevPatHighLightCode ||
2768 + stack[stackIdx - 1].pseHighLightCode == IGNORE_HIGHLIGHT_CODE ||
2769 + prevPatHighLightCode == IGNORE_HIGHLIGHT_CODE) &&
2770 + doesBackRefInfoMatch(
2771 + &stack[stackIdx - 1].pseBackRefInfo,
2772 + &prevPatBackRefInfo))
2775 + * use context group pattern again, if start pattern
2776 + * to skip to was found.
2780 + currentPatRE = groupPatRE;
2781 + skipToStart = FALSE;
2785 + * pop. related end pattern from stack.
2790 + else if (prevPatRef.prKind == PEK_END)
2792 + if (stackIdx >= MAX_NESTED_PATTERNS)
2795 + printf("BACKWARD: MAX. NESTED PATTERN DEPTH REACHED !\n");
2797 + prevStartPos = -1;
2799 + else if (!skipToStart)
2802 + * Put prev. pattern on stack, if contents between start /
2803 + * end shouldn't be skipped (if "skipToStart" is set,
2804 + * a (usually illegal) end pattern to skip inside the
2805 + * skipped one is found (e.g. *\ *\ ..)
2807 + stack[stackIdx].psePatRef = prevPatRef;
2808 + stack[stackIdx].pseHighLightCode = prevPatHighLightCode;
2809 + stack[stackIdx].pseBackRefInfo = prevPatBackRefInfo;
2813 + patTable->mptElements[prevPatRef.prElementIdx];
2816 + * Use start / end pattern regular expression if skip to
2817 + * end is set for found end pattern.
2819 + if (currentElement->mpteSkipBtwnStartEnd)
2821 + currentPatRE = currentElement->mpteStartEndRE;
2822 + skipToStart = TRUE;
2826 + startPos = prevStartPos - 1;
2829 + return prevStartPos;
2833 +** Adapt found pattern element index depending on
2834 +** the info stored on (last) stack element and
2835 +** a given pattern set (belonging to the found pattern).
2837 +static void considerStackPatReference(
2838 + PatternElementSet *patSet,
2839 + int stackElementIdx,
2840 + int *foundElementIdx)
2842 + PatternElement *patElement;
2846 + * If found pattern index already indicates, that found pattern
2847 + * belongs to pattern set stored on stack, then no adaption is needed
2849 + if (*foundElementIdx == stackElementIdx)
2853 + * Check all elements of given pattern element set:
2855 + for (i=0; i < patSet->pesNumberOfPattern; i++)
2857 + patElement = patSet->pesPattern[i];
2860 + * If this set element is a reference and this reference fits
2861 + * to the element stored on stack, then adapt found element index:
2862 + * indicate, that found pattern belongs to pattern set stored on stack
2864 + if (patElement->peType == PET_REFERENCE &&
2865 + patElement->peVal.peuRef.prElementIdx == stackElementIdx)
2867 + *foundElementIdx = stackElementIdx;
2875 +** Determines, if a string pattern is located at the given position
2876 +** "relBeginPos" in the given "searchRegion". A string pattern is
2877 +** found, if the pattern is located just before given position
2878 +** "relBeginPos" OR if "relBeginPos" is located within a string pattern.
2880 +** Returns true, if the given "pattern" is located at
2881 +** "relBeginPos". "matchInfo" holds all info needed about matched
2882 +** "start" string pattern.
2884 +static int getPatternLocatedAtPos(
2885 + regexp *usedPatRE,
2886 + MatchPatternTable *table,
2887 + SearchRegionInfo *searchRegion,
2889 + MatchingElementInfo *matchInfo,
2890 + const char *delimiters)
2892 + int searchStartPos = *relBeginPos;
2893 + PatternReference *patRef = &matchInfo->meiPatRef;
2894 + FoundStringInfo foundStringInfo;
2895 + int relMatchStartPos;
2896 + int relMatchEndPos;
2898 + patRef->prElementIdx = NO_ELEMENT_IDX;
2899 + patRef->prKind = PEK_UNKNOWN;
2900 + patRef->prPatternIdx = NO_PATTERN_IDX;
2902 + matchInfo->meiHighLightCode = IGNORE_HIGHLIGHT_CODE;
2903 + matchInfo->meiAbsStartPos = -1;
2904 + matchInfo->meiLength = 0;
2907 + * No backward search possible, if we are at beginning of
2910 + if (searchStartPos == 0)
2914 + * Search in backward direction for 1st occurance of a string pattern
2915 + * starting one char before "searchStartPos".
2919 + searchRegion->sriText,
2920 + searchRegion->sriText + searchStartPos - 1,
2922 + searchRegion->sriPrevChar,
2923 + searchRegion->sriText[searchStartPos],
2925 + searchRegion->sriText,
2929 + * String pattern was found:
2931 + foundStringInfo.fsiStartPtr = usedPatRE->startp[0];
2932 + foundStringInfo.fsiEndPtr = usedPatRE->endp[0];
2933 + foundStringInfo.fsiLength =
2934 + foundStringInfo.fsiEndPtr - foundStringInfo.fsiStartPtr;
2936 + relMatchEndPos = foundStringInfo.fsiEndPtr - searchRegion->sriText;
2937 + relMatchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
2940 + * Is found pattern located exactly one char before "relBeginPos" OR
2941 + * is "relBeginPos" located within found string pattern ?
2942 + * Note: "relMatchEndPos" indicates 1st pos. in "sriText"
2943 + * which does *not* belong to found string anymore.
2945 + if ((*relBeginPos == relMatchEndPos) ||
2946 + (*relBeginPos >= relMatchStartPos &&
2947 + *relBeginPos < relMatchEndPos))
2949 + *relBeginPos = relMatchEndPos;
2952 + * Determine match element info related to found string.
2954 + matchInfo->meiAbsStartPos =
2955 + foundStringInfo.fsiStartPtr - searchRegion->sriText +
2956 + searchRegion->sriStartOfTextPos;
2957 + matchInfo->meiLength = foundStringInfo.fsiLength;
2959 + foundStringInfo.fsiPrevChar =
2960 + foundStringInfo.fsiStartPtr == searchRegion->sriText ?
2961 + searchRegion->sriPrevChar : *(foundStringInfo.fsiStartPtr - 1);
2963 + foundStringInfo.fsiSuccChar =
2964 + *(foundStringInfo.fsiEndPtr) == '\0' ?
2965 + searchRegion->sriSuccChar : *(foundStringInfo.fsiEndPtr);
2967 + foundStringInfo.fsiDelimiters = delimiters;
2970 + getMatchedElementInfo(
2971 + searchRegion->sriWindow,
2982 +** Get all needed info related to matched "start" string pattern
2983 +** (given by parameter "foundStringInfo").
2985 +** Returns true, if info was determined successfully.
2987 +static int getMatchedElementInfo(
2988 + WindowInfo *window,
2989 + MatchPatternTable *table,
2990 + FoundStringInfo *foundStringInfo,
2991 + MatchingElementInfo *matchInfo)
2993 + PatternReference *patRef = &matchInfo->meiPatRef;
2994 + int absMatchStartPos = matchInfo->meiAbsStartPos;
2995 + MatchPatternTableElement *matchedElement;
2997 + if (getPatternInfo(
3001 + &matchInfo->meiBackRefInfo))
3004 + * A pattern reference could be assigned to found string:
3006 + matchedElement = table->mptElements[patRef->prElementIdx];
3008 + matchInfo->meiElement = matchedElement;
3011 + * get highlight code of found string pattern, if applicable
3013 + if (!matchedElement->mpteIgnoreHighLightInfo)
3015 + matchInfo->meiHighLightCode =
3016 + HighlightCodeOfPos(window, absMatchStartPos);
3020 + * setup mono pattern info of found string pattern
3022 + if (matchedElement->mpteIsMonoPattern)
3024 + if (matchedElement->mpteIgnoreHighLightInfo)
3026 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
3031 + * determine mono pattern info depending on highLightCodes
3032 + * before / after found string pattern.
3034 + patRef->prMonoInfo =
3035 + determineMonoPatInfo(
3037 + matchInfo->meiHighLightCode,
3038 + absMatchStartPos - 1,
3039 + absMatchStartPos + matchInfo->meiLength,
3045 + patRef->prMonoInfo = PEMI_NOT_MONO;
3053 + * Found string can't be assigned to a pattern element
3054 + * (should never occur).
3061 +** Returns string pattern of given pattern element.
3063 +StringPattern *GetStringPattern(
3064 + MatchPatternTable *table,
3065 + PatternElement *pattern )
3067 + switch (pattern->peType)
3070 + return &pattern->peVal.peuSingle;
3073 + case PET_MULTIPLE:
3074 + return &pattern->peVal.peuMulti.mpStringPattern;
3077 + case PET_REFERENCE:
3078 + return GetStringPattern(
3080 + getPatternOfReference(table, pattern->peVal.peuRef));
3085 + * never reached; just to make compiler happy
3091 +** Returns pattern element of given pattern reference.
3093 +static PatternElement *getPatternOfReference(
3094 + MatchPatternTable *table,
3095 + PatternReference patRef)
3097 + MatchPatternTableElement **element = table->mptElements;
3099 + return element[ patRef.prElementIdx ]->mpteAll.pesPattern[patRef.prPatternIdx];
3103 +static char *getPatternForDebug(
3104 + MatchPatternTable *table,
3105 + PatternReference patRef )
3107 + if (patRef.prElementIdx < 0)
3115 + getPatternOfReference(table, patRef))->spText;
3118 +static char *patElemKindToString(
3119 + PatternElementKind patElemKind)
3121 + if (patElemKind == PEK_START)
3123 + else if (patElemKind == PEK_MIDDLE)
3125 + else if (patElemKind == PEK_END)
3131 +static void printFoundStringForDebug(
3132 + WindowInfo *window,
3137 + BufGetRange( window->buffer, absStartPos, absStartPos + length);
3139 + printf("%d (abs.) <%s>",
3148 diff --quilt /dev/null new/source/patternMatch.h
3150 +++ new/source/patternMatch.h
3152 +/* $Id: patternMatch.h,v 1.2 2003/10/11 16:45:25 uleh Exp $ */
3154 +#ifndef NEDIT_PATTERNMATCH_H_INCLUDED
3155 +#define NEDIT_PATTERNMATCH_H_INCLUDED
3157 +#include "regularExp.h"
3159 +#define NO_GROUP_IDX -1
3160 +#define NO_ELEMENT_IDX -1
3161 +#define NO_PATTERN_IDX -1
3163 +#define MAX_GLOBAL_BACK_REF_ID 9
3164 +#define NO_LOCAL_BACK_REF_ID -1
3171 +} PatternElementKind;
3175 + PEMI_MONO_NOT_SYNTAX_BASED,
3176 + PEMI_MONO_AMBIGUOUS_SYNTAX,
3177 + PEMI_MONO_DEFINITE_SYNTAX
3178 +} PatternElementMonoInfo;
3180 +typedef struct _PatternReference {
3181 + PatternElementKind prKind;
3182 + PatternElementMonoInfo prMonoInfo;
3185 +} PatternReference;
3191 +} MatchPatternType;
3193 +typedef struct _MatchPatternSequenceElement {
3195 + MatchPatternType mpseType;
3197 +} MatchPatternSequenceElement;
3199 +typedef struct _MatchPatternGroupElement {
3201 + int mpgeNumberOfSubPatterns;
3202 + char **mpgeSubPatternIds;
3203 + regexp *mpgeKeywordRE;
3204 +} MatchPatternGroupElement;
3211 +} PatternWordBoundary;
3213 +typedef struct _StrPatBackRefElement{
3214 + int spbreLocalBackRefID;
3215 + char *spbreRegExpText;
3216 +} StrPatBackRefElement;
3218 +typedef struct _StringPattern {
3221 + PatternWordBoundary spWordBoundary;
3222 + int spCaseInsensitive;
3223 + int spRegularExpression;
3226 + int spBackRefParsed;
3227 + int spBackRefResolved;
3228 + StrPatBackRefElement spOwnGlobalBackRef[MAX_GLOBAL_BACK_REF_ID];
3229 + int spGlobalToLocalBackRef[MAX_GLOBAL_BACK_REF_ID];
3232 +typedef struct _MultiPattern {
3233 + StringPattern mpStringPattern;
3234 + int mpNumberOfReferences;
3235 + PatternReference *mpRefList;
3242 +} PatternElementType;
3244 +typedef struct _PatternElement {
3246 + PatternElementKind peKind;
3247 + PatternElementType peType;
3249 + StringPattern peuSingle;
3250 + MultiPattern peuMulti;
3251 + PatternReference peuRef;
3255 +typedef struct _PatternElementSet {
3256 + int pesNumberOfPattern;
3257 + PatternElement **pesPattern;
3258 +} PatternElementSet;
3260 +typedef struct _GlobalBackRefElement{
3261 + StringPattern *gbreDefByStrPat;
3262 + char *gbreRegExpText;
3263 +} GlobalBackRefElement;
3265 +typedef struct _MatchPatternTableElement {
3268 + MatchPatternType mpteType;
3270 + PatternElementSet mpteAll;
3271 + PatternElementSet mpteStart;
3272 + PatternElementSet mpteMiddle;
3273 + PatternElementSet mpteEnd;
3275 + int mpteIsMonoPattern;
3276 + int mpteSkipBtwnStartEnd;
3277 + int mpteIgnoreHighLightInfo;
3278 + regexp *mpteStartEndRE;
3279 + GlobalBackRefElement mpteGlobalBackRef[MAX_GLOBAL_BACK_REF_ID];
3280 +} MatchPatternTableElement;
3282 +typedef struct _MatchPatternTable {
3283 + int mptNumberOfElements;
3284 + MatchPatternTableElement **mptElements;
3285 +} MatchPatternTable;
3287 +typedef struct _StringMatchTable {
3288 + char *smtLanguageMode;
3289 + MatchPatternTable *smtAllPatterns;
3290 + regexp *smtAllPatRE;
3291 + regexp *smtFlashPatRE;
3292 + regexp *smtUsedPatRE;
3293 + int smtNumberOfGroups;
3294 + MatchPatternGroupElement **smtGroups;
3295 + int smtNumberOfSeqElements;
3296 + MatchPatternSequenceElement **smtSequence;
3297 +} StringMatchTable;
3307 +int FindMatchingString(
3308 + WindowInfo *window,
3309 + MatchingType matchingType,
3317 +StringPattern *GetStringPattern(
3318 + MatchPatternTable *table,
3319 + PatternElement *pattern);
3321 +#endif /* NEDIT_PATTERNMATCH_H_INCLUDED */
3322 diff --quilt /dev/null new/source/patternMatchData.c
3324 +++ new/source/patternMatchData.c
3326 +static const char CVSID[] = "$Id: patternMatchData.c,v 1.4 2004/10/27 21:57:12 uleh Exp $";
3327 +/*******************************************************************************
3329 +* patternMatchData.c -- Maintain and allow user to edit a matching pattern list*
3330 +* used for pattern matching *
3332 +* Copyright (C) 2003-2004, Uwe Lehnert *
3334 +* This is free software; you can redistribute it and/or modify it under the *
3335 +* terms of the GNU General Public License as published by the Free Software *
3336 +* Foundation; either version 2 of the License, or (at your option) any later *
3337 +* version. In addition, you may distribute versions of this program linked to *
3338 +* Motif or Open Motif. See README for details. *
3340 +* This software is distributed in the hope that it will be useful, but WITHOUT *
3341 +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
3342 +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
3343 +* for more details. *
3345 +* You should have received a copy of the GNU General Public License along with *
3346 +* software; if not, write to the Free Software Foundation, Inc., 59 Temple *
3347 +* Place, Suite 330, Boston, MA 02111-1307 USA *
3349 +* Nirvana Text Editor *
3350 +* October 27, 2004 *
3352 +* Written by Uwe Lehnert *
3354 +*******************************************************************************/
3355 +#ifdef HAVE_CONFIG_H
3356 +#include "../config.h"
3359 +#include <stdlib.h>
3361 +#include <limits.h>
3362 +#include <string.h>
3366 +#include "../util/VMSparam.h"
3369 +#include <sys/param.h>
3374 +#include <Xm/Form.h>
3375 +#include <Xm/Frame.h>
3376 +#include <Xm/Text.h>
3377 +#include <Xm/LabelG.h>
3378 +#include <Xm/PushB.h>
3379 +#include <Xm/PushBG.h>
3380 +#include <Xm/ToggleB.h>
3381 +#include <Xm/RowColumn.h>
3382 +#include <Xm/SeparatoG.h>
3384 +#include "../util/misc.h"
3385 +#include "../util/DialogF.h"
3386 +#include "../util/managedList.h"
3388 +#include "regularExp.h"
3389 +#include "textBuf.h"
3391 +#include "window.h"
3392 +#include "preferences.h"
3397 +#include "patternMatch.h"
3398 +#include "patternMatchData.h"
3400 +#ifdef HAVE_DEBUG_H
3401 +#include "../debug.h"
3407 +#define MAX_LOCAL_BACK_REF_ID 9
3408 +#define LOCAL_BACK_REF_ID_USED -2
3410 +#define MAX_NUMBER_MIDDLE_PATTERN 10
3411 +#define MAX_STRING_PATTERNS 30
3412 +#define MAX_NBR_MATCH_PATTERNS 50
3413 +#define MAX_NBR_MATCH_PATTERN_GROUPS 50
3414 +#define MAX_NBR_SEQ_ELEMENTS MAX_NBR_MATCH_PATTERNS + MAX_NBR_MATCH_PATTERN_GROUPS
3416 +#define MATCH_PAT_NAME_LBL_TXT "Matching Pattern Name"
3417 +#define STRING_PATTERNS_LBL_TXT "String Patterns"
3420 +#define LIST_RIGHT 41
3421 +#define PLAIN_LM_STRING "PLAIN"
3423 +#define SPNM_NONE_SELECTED "none selected"
3425 +#define KEEP_LANGUAGE_MODE True
3426 +#define DISCARD_LANGUAGE_MODE False
3428 +#define STRING_PATTERN_DIALOG True
3429 +#define CONTEXT_GROUP_DIALOG False
3432 + * local data definitions
3434 +typedef struct _ErrorInfo {
3436 + char *eiLanguageMode;
3437 + char *eiMPTabElementName;
3438 + char *eiStringPatText;
3439 + char *eiRegExpCompileMsg;
3443 +typedef struct _BackRefBracketInfo {
3445 + char *brbiContentStart;
3446 + int brbiNestingLevel;
3447 +} BackRefBracketInfo;
3449 +typedef struct _RegExpStringInfo {
3450 + int resiNbrOfAddedMultiPat;
3451 + PatternReference **resiAddedMultiPat;
3452 + char *resiNoneWBRegExpString;
3453 + char *resiLeftWBRegExpString;
3454 + char *resiRightWBRegExpString;
3455 + char *resiBothWBRegExpString;
3456 + int resiLocalBackRefID;
3457 +} RegExpStringInfo;
3459 +typedef struct _ReadMatchPatternInfo {
3460 + int rmpiNbrOfElements;
3461 + MatchPatternTableElement *rmpiElement[MAX_NBR_MATCH_PATTERNS];
3462 + int rmpiNbrOfGroups;
3463 + MatchPatternGroupElement *rmpiGroup[MAX_NBR_MATCH_PATTERN_GROUPS];
3464 + int rmpiNbrOfSeqElements;
3465 + MatchPatternSequenceElement *rmpiSequence[MAX_NBR_SEQ_ELEMENTS];
3466 + regexp *rmpiAllPatRE;
3467 + regexp *rmpiFlashPatRE;
3468 +} ReadMatchPatternInfo;
3470 +typedef struct _DialogStringPatternElement {
3472 + PatternElementKind dspeKind;
3473 + PatternWordBoundary dspeWordBoundary;
3474 + int dspeCaseInsensitive;
3475 + int dspeRegularExpression;
3476 +} DialogStringPatternElement;
3478 +typedef struct _DialogStringPatterns {
3479 + int dspNumberOfPatterns;
3480 + DialogStringPatternElement *dspElements[MAX_STRING_PATTERNS];
3481 +} DialogStringPatterns;
3483 +typedef struct _DialogMatchPatternTableElement {
3485 + MatchPatternType dmpteType;
3486 + DialogStringPatterns dmptePatterns;
3487 + int dmpteSkipBtwnStartEnd;
3488 + int dmpteIgnoreHighLightInfo;
3490 +} DialogMatchPatternTableElement;
3492 +typedef struct _DialogMatchPatternGroupElement {
3494 + int dmpgeNumberOfSubPatterns;
3495 + char *dmpgeSubPatternIds[MAX_NBR_MATCH_PATTERNS];
3496 +} DialogMatchPatternGroupElement;
3498 +typedef struct _DialogMatchPatternSequenceElement {
3500 + MatchPatternType dmpseType;
3503 +} DialogMatchPatternSequenceElement;
3505 +typedef struct _DialogMatchPatternInfo {
3506 + int dmpiNbrOfSeqElements;
3507 + DialogMatchPatternSequenceElement *dmpiSequence[MAX_NBR_SEQ_ELEMENTS];
3508 +} DialogMatchPatternInfo;
3514 +} DMPTranslationResult;
3516 +typedef struct _NameList {
3518 + char *nlId[MAX_NBR_SEQ_ELEMENTS + 1];
3522 + * prototypes of local functions
3524 +static void treatDuplicatedPattern(
3525 + MatchPatternTable *table,
3526 + PatternElement *prevPattern,
3527 + PatternReference prevPatRef,
3528 + PatternElement *lastPattern,
3529 + PatternReference lastPatRef);
3530 +static void treatDuplicatedPatternElements(
3531 + MatchPatternTable *table,
3532 + MatchPatternTableElement *prevElement,
3533 + int prevElementIdx,
3534 + PatternElement *lastPattern,
3535 + PatternReference lastPatRef);
3536 +static void treatDuplicatedMTElements(
3537 + MatchPatternTable *table,
3538 + MatchPatternTableElement *prevElement,
3539 + int prevElementIdx,
3540 + MatchPatternTableElement *lastElement,
3541 + int lastElementIdx);
3542 +static void treatDuplicatedMTEntries(
3543 + MatchPatternTableElement **element,
3544 + int nbrOfElements);
3546 +static int createStrPatRegExpOfElement(
3547 + ReadMatchPatternInfo *readPatInfo,
3548 + MatchPatternTableElement *element,
3549 + ErrorInfo *errInfo);
3550 +static int createStrPatRegExp(
3551 + StringPattern *strPat,
3552 + ErrorInfo *errInfo);
3553 +static void adaptCompileMsg(
3555 + int *globalToLocalBackRef);
3556 +static int localToGlobalBackRef(
3557 + int *globalToLocalBackRef,
3559 +static int createStartEndRegExp(
3560 + ReadMatchPatternInfo *readMatchPatternInfo,
3561 + MatchPatternTableElement *element,
3562 + ErrorInfo *errInfo);
3563 +static int createGroupRegExp(
3564 + ReadMatchPatternInfo *readPatInfo,
3565 + MatchPatternGroupElement *group,
3566 + ErrorInfo *errInfo);
3567 +static void setupRegExpStringBuffers(
3568 + ReadMatchPatternInfo *readMatchPatternInfo,
3569 + RegExpStringInfo *regExpStringInfo);
3570 +static void addSMTRegExpString(
3573 + const char *postfix);
3574 +static void composeStartEndRegExpString(
3575 + ReadMatchPatternInfo *readMatchPatternInfo,
3576 + MatchPatternTableElement *element,
3577 + char **regExpString);
3578 +static void addElementToRegExpString(
3579 + MatchPatternTableElement *element,
3580 + ReadMatchPatternInfo *readMatchPatternInfo,
3581 + RegExpStringInfo *regExpStringInfo);
3582 +static void addUniquePatternToRegExpString(
3583 + PatternElement *patElement,
3584 + PatternReference *patElementReference,
3585 + ReadMatchPatternInfo *readMatchPatternInfo,
3586 + RegExpStringInfo *regExpStringInfo);
3587 +static void addPatternToRegExpString(
3588 + StringPattern *pattern,
3589 + RegExpStringInfo *regExpStringInfo);
3590 +static char *adaptLocalBackRefs(
3592 + int *commonLocalId);
3593 +static void scanForLocalBackRefs(
3595 + int *localBackRefList);
3596 +static int isMultiPatternNotAdded(
3597 + RegExpStringInfo *regExpStringInfo,
3598 + PatternReference *toBeAddedPR);
3599 +static void catSMTRegExpStrings(
3600 + RegExpStringInfo *regExpStringInfo,
3601 + char **regExpString);
3602 +static void freeRegExpStringInfo(
3603 + RegExpStringInfo *regExpStringInfo);
3604 +static int totalKeywordOfTableLen(
3605 + ReadMatchPatternInfo *info,
3606 + int *nbrOfMultiPatterns);
3607 +static int totalMatchPatternTableElementLen(
3608 + ReadMatchPatternInfo *info,
3609 + MatchPatternTableElement *element,
3610 + int *nbrOfMultiPatterns);
3611 +static int patternElementLen(
3612 + ReadMatchPatternInfo *info,
3613 + PatternElement *patElement,
3614 + int *nbrOfMultiPatterns);
3616 +static void parseMatchingPatternSetError(
3617 + const char *stringStart,
3618 + const char *stoppedAt,
3619 + ErrorInfo *errInfo);
3620 +static void dialogMatchingPatternSetError(
3622 + ErrorInfo *errInfo);
3624 +static char *createMatchPatternsString(
3625 + StringMatchTable *table,
3627 +static char *createPatternElementString(
3628 + MatchPatternTable *table,
3629 + PatternElement *pat);
3631 +static StringMatchTable *readDefaultStringMatchTable(const char *langModeName);
3632 +static int isDefaultMatchPatternTable(StringMatchTable *table);
3634 +static void freeReadMatchPatternInfo( ReadMatchPatternInfo *readPatInfo );
3635 +static void freeStringMatchTable( StringMatchTable *table );
3636 +static void freeMatchPatternTableElement( MatchPatternTableElement *element );
3637 +static void freePatternElement( PatternElement *element );
3638 +static void freeStringPattern( StringPattern *strPat );
3639 +static void freeMatchPatternGroupElement( MatchPatternGroupElement *group );
3640 +static void freeMatchPatternSequenceElement( MatchPatternSequenceElement *sequence );
3642 +static StringMatchTable *readMatchPatternSet(char **inPtr);
3643 +static StringMatchTable *readMatchPatternSetContent(
3645 + char *stringStart,
3646 + char *languageMode);
3647 +static int createRegExpOfPatterns(
3648 + ReadMatchPatternInfo *readPatInfo,
3649 + ErrorInfo *errInfo);
3650 +static int createRegExpOfAllPatterns(
3651 + ReadMatchPatternInfo *readPatInfo,
3652 + ErrorInfo *errInfo);
3653 +static int createRegExpOfStrPatterns(
3654 + ReadMatchPatternInfo *readPatInfo,
3655 + ErrorInfo *errInfo);
3656 +static StringMatchTable *createStringMatchTable(
3657 + ReadMatchPatternInfo *readPatInfo,
3658 + char *languageMode);
3659 +static int readMatchPatternEntry(
3661 + ErrorInfo *errInfo,
3662 + ReadMatchPatternInfo *info);
3663 +static void recordPatternSequence(
3664 + ReadMatchPatternInfo *info,
3666 + MatchPatternType type,
3668 +static int assignIndividualGroup(
3669 + ReadMatchPatternInfo *info,
3671 + MatchPatternTableElement *element);
3672 +static MatchPatternTableElement *getPatternOfName(
3673 + ReadMatchPatternInfo *info,
3674 + char *subPatToSearch);
3675 +static MatchPatternGroupElement *readMatchPatternGroup(
3677 + ErrorInfo *errInfo,
3679 + ReadMatchPatternInfo *info);
3680 +static int readPatternElement(
3683 + PatternElement **pattern);
3684 +static PatternElement *createPatternElement(
3685 + char *patternText,
3686 + PatternElementKind patternKind,
3687 + PatternWordBoundary wordBoundary,
3688 + int caseInsensitive,
3689 + int regularExpression);
3691 +static int createGlobalBackRefList(
3692 + ReadMatchPatternInfo *readPatInfo,
3693 + MatchPatternTableElement *element,
3694 + ErrorInfo *errInfo);
3695 +StringPattern *getReadStringPattern(
3696 + ReadMatchPatternInfo *readPatInfo,
3697 + PatternElement *pattern );
3698 +static PatternElement *getReadPatternOfReference(
3699 + ReadMatchPatternInfo *readPatInfo,
3700 + PatternReference *patRef);
3701 +static char *replaceCapturingParentheses(
3702 + const char *source);
3703 +static int parseGlobalBackRefs(
3704 + StringPattern *strPat,
3705 + GlobalBackRefElement *backRefList,
3706 + ErrorInfo *errInfo);
3707 +static int updateGlobalBackRefs(
3708 + StringPattern *strPat,
3709 + GlobalBackRefElement *backRefList,
3710 + ErrorInfo *errInfo);
3711 +static char *createBackRefRegExpText(
3712 + const char *start,
3714 +static int resolveGlobalBackRefs(
3715 + ReadMatchPatternInfo *readPatInfo,
3716 + MatchPatternTableElement *element,
3717 + ErrorInfo *errInfo);
3718 +static int resolveGlobalBackRefsOfStrPat(
3719 + StringPattern *strPat,
3720 + GlobalBackRefElement *backRefList,
3721 + ErrorInfo *errInfo);
3722 +static char *substituteGlobalBackRef(
3723 + StringPattern *strPat,
3727 + GlobalBackRefElement *backRefList,
3728 + ErrorInfo *errInfo);
3729 +static char *replaceBackRefIdByRegExp(
3730 + StringPattern *strPat,
3731 + char *replaceStartPtr,
3733 +static char *convertGlobalToLocalBackRef(
3734 + StringPattern *strPat,
3735 + char *convertPtr);
3737 +static MatchPatternTableElement *readMatchPatternTableElement(
3741 + MatchPatternType type);
3742 +static int sortReadPatternElementSet(
3743 + PatternElementSet *allPat,
3745 + MatchPatternTableElement *result);
3746 +static void countPatternElementKind(
3747 + PatternElementSet *allPat,
3748 + MatchPatternTableElement *result);
3749 +static void sortPatternElementSet(
3750 + PatternElementSet *allPat,
3751 + MatchPatternTableElement *result);
3752 +static void copyPatternSet(
3753 + PatternElementSet *sourcePS,
3754 + PatternElementSet *destPS);
3756 +static int getMPSName(
3758 + ErrorInfo *errInfo,
3760 +static int getMPSTypeAttribute(
3762 + ErrorInfo *errInfo,
3763 + MatchPatternType *type);
3764 +static int getMPSGlobalAttribute(
3767 + int *isMonoPattern,
3770 + int *ignoreHighLightInfo);
3771 +static int getMPSPatternAttribute(
3774 + PatternElementKind *patternKind,
3775 + PatternWordBoundary *wordBoundary,
3776 + int *caseInsensitive,
3777 + int *regularExpression);
3779 +static void copyStringMatchTableForDialog(
3780 + StringMatchTable *sourceTable,
3781 + DialogMatchPatternInfo *dialogTable );
3782 +static void *copyMatchPatternElementForDialog(
3783 + MatchPatternTable *table,
3784 + int sourceElementIdx);
3785 +static void copyPatternForDialog(
3786 + MatchPatternTable *table,
3787 + PatternElement *sourcePattern,
3788 + DialogStringPatternElement **dialogPattern );
3789 +static void *copyGroupElementForDialog(
3790 + MatchPatternGroupElement *sourceGroup);
3791 +static void copySequenceElementForDialog(
3792 + StringMatchTable *sourceTable,
3793 + MatchPatternSequenceElement *sourceSeqElement,
3794 + DialogMatchPatternSequenceElement **dialogSeqElement );
3795 +static DialogMatchPatternSequenceElement *copyDialogSequenceElement(
3796 + DialogMatchPatternSequenceElement *sourceSeq);
3797 +static void freeDialogMatchPatternElement(
3798 + DialogMatchPatternTableElement *dialogElement );
3799 +static void freeDialogStringPatternElement(
3800 + DialogStringPatternElement *element);
3801 +static void freeDialogGroupElement(
3802 + DialogMatchPatternGroupElement *dialogGroup );
3803 +static void freeDialogSequenceElement(
3804 + DialogMatchPatternSequenceElement *dialogSeq );
3806 +static void copyDialogStringPatternsFromTable(
3807 + DialogMatchPatternTableElement *tableElement,
3808 + DialogStringPatterns *destPatterns);
3809 +static void copyDialogStringPatterns(
3810 + DialogStringPatterns *sourcePatterns,
3811 + DialogStringPatterns *destPatterns);
3812 +static void freeDialogStringPatterns(
3813 + DialogStringPatterns *patterns);
3815 +static DialogStringPatternElement *copyDialogStringPatternElement(
3816 + DialogStringPatternElement *sourceElement);
3818 +static void copyDialogPatternNamesFromGroup(
3819 + DialogMatchPatternGroupElement *group,
3820 + DialogStringPatterns *destPatterns);
3821 +static DialogStringPatternElement *copyDialogPatternName(
3822 + char *sourcePatternId);
3823 +static void copyDialogPatternNamesToGroup(
3824 + DialogStringPatterns *sourceNames,
3825 + DialogMatchPatternGroupElement *destGroup);
3827 +static void setDialogType(int dialogShowsStringPattern);
3828 +static void setSensitiveWordBoundaryBox(int enable);
3830 +static void *getStringPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
3832 +static void setStringPatternDisplayedCB(void *item, void *cbArg);
3833 +static void freeStringPatternItemCB(void *item);
3835 +static void *getMatchPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
3837 +static void setMatchPatternDisplayedCB(void *item, void *cbArg);
3838 +static void freeMatchPatternItemCB(void *item);
3839 +static int deleteMatchPatternItemCB(int itemIndex, void *cbArg);
3841 +static void matchPatternLangModeCB(Widget w, XtPointer clientData, XtPointer callData);
3842 +static void pmLanguageModeDialogCB(Widget w, XtPointer clientData, XtPointer callData);
3844 +static void destroyCB(Widget w, XtPointer clientData, XtPointer callData);
3845 +static void okCB(Widget w, XtPointer clientData, XtPointer callData);
3846 +static void applyCB(Widget w, XtPointer clientData, XtPointer callData);
3847 +static void checkCB(Widget w, XtPointer clientData, XtPointer callData);
3848 +static void restoreCB(Widget w, XtPointer clientData, XtPointer callData);
3849 +static void deleteCB(Widget w, XtPointer clientData, XtPointer callData);
3850 +static void closeCB(Widget w, XtPointer clientData, XtPointer callData);
3851 +static void helpCB(Widget w, XtPointer clientData, XtPointer callData);
3853 +static void matchPatTypeCB(Widget w, XtPointer clientData, XtPointer callData);
3854 +static void strPatRegExpressionCB(Widget w, XtPointer clientData, XtPointer callData);
3855 +static void changeExistingSubPattern(char *warnTitle);
3856 +static void changeStringPatternToGroup(void);
3857 +static void changeGroupToStringPattern(char *warnTitle);
3859 +static Widget createSubPatternNameMenu(
3861 + char *currentSubPatName,
3862 + int allSubPatterns);
3863 +static void setupSubPatternNameList(
3864 + char *currentSubPatName,
3865 + int allSubPatterns,
3866 + NameList *nameList);
3867 +static void createSubPatNameMenuEntry(
3869 + char *subPatName);
3870 +static void setSubPatternNameMenu(
3871 + const char *subPatName);
3872 +static void updateSubPatternNameMenu(
3873 + char *currentSubPatName,
3874 + int allSubPatterns);
3875 +static char *getSelectedSubPatternName(void);
3876 +static int isSubPatternNameInCurStrPat(
3877 + char *subPatName);
3879 +static DialogMatchPatternSequenceElement *readMatchPatternFields(int silent);
3880 +static int isStartPatternElementAvailable(
3881 + DialogStringPatterns *dialogPatterns);
3882 +static DialogStringPatternElement *readStringPatternFrameFields(int silent);
3884 +static int matchPatternDialogEmpty(void);
3885 +static int stringPatternFrameEmpty(void);
3886 +static int stringPatternFieldsEmpty(
3887 + int strPatIsRelatedToGroup);
3889 +static int getAndUpdateStringMatchTable(void);
3890 +static void updateStringMatchTable(
3891 + StringMatchTable *newTable);
3893 +static StringMatchTable *getDialogStringMatchTable(
3894 + DMPTranslationResult *result);
3895 +static StringMatchTable *translateDialogStringMatchTable(
3896 + DialogMatchPatternInfo *dialogTable,
3897 + DMPTranslationResult *result);
3898 +static MatchPatternTableElement *translateDialogMatchPatternTableElement(
3899 + DialogMatchPatternTableElement *dialogElement);
3900 +static void translateDialogPatterns(
3901 + DialogStringPatterns *dialogPatterns,
3902 + MatchPatternTableElement *newElement);
3903 +static MatchPatternGroupElement *translateDialogMatchPatternGroupElement(
3904 + ReadMatchPatternInfo *info,
3905 + DialogMatchPatternGroupElement *dialogGroup);
3906 +static void sortDialogPatternElementSet(
3907 + PatternElementSet *allPat,
3908 + MatchPatternTableElement *result);
3910 +static int stringMatchTableDiffer(
3911 + StringMatchTable *oldTable,
3912 + StringMatchTable *newTable);
3914 +static int patternElementDiffer(
3915 + PatternElement *oldPE,
3916 + MatchPatternTable *oldTab,
3917 + PatternElement *newPE,
3918 + MatchPatternTable *newTab);
3920 +static DialogMatchPatternGroupElement *getDialogGroupUsingMatchPattern(
3921 + char *matchPatternName);
3922 +static void removeMatchPatternFromGroup(
3923 + char *matchPatternName,
3924 + DialogMatchPatternGroupElement *group);
3925 +static void removeMatchPatternFromAllGroups(
3926 + char *matchPatternName);
3927 +static void renameMatchPatternInGroup(
3928 + char *oldMatchPatternName,
3929 + char *newMatchPatternName,
3930 + DialogMatchPatternGroupElement *group);
3931 +static void renameMatchPatternInAllGroups(
3932 + char *oldMatchPatternName,
3933 + char *newMatchPatternName);
3935 +static void freeVariableDialogData(
3936 + int keepLanguageModeName);
3938 +static void initGlobalBackRefList(
3939 + GlobalBackRefElement *list);
3940 +static void initStrPatBackRefList(
3941 + StringPattern *strPat);
3943 +StringPattern *getUniqueStringPattern(
3944 + PatternElement *pattern );
3946 +static void initErrorInfo(
3947 + ErrorInfo *errInfo);
3948 +static void freeErrorInfo(
3949 + ErrorInfo *errInfo);
3951 +static void freeXtPtr(void **ptr);
3952 +static void freePtr(void **ptr);
3955 + * matching pattern dialog information
3959 + Widget mpdLmOptMenu;
3960 + Widget mpdLmPulldown;
3961 + Widget mpdMatchPatternNamesListW;
3962 + Widget mpdMatchPatternNameLbl;
3963 + Widget mpdMatchPatternNameW;
3964 + Widget mptbIndividualW;
3965 + Widget mptbSubPatternW;
3966 + Widget mptbContextGroupW;
3967 + Widget mpdGlobalAttributesLbl;
3968 + Widget gabSkipBtwStartEndW;
3970 + Widget gabSyntaxBasedW;
3971 + Widget mpdStringPatternsLbl;
3972 + Widget mpdStringPatternsListW;
3973 + Widget mpdStringPatternTypeLbl;
3975 + Widget sptMiddleW;
3977 + Widget mpdWordBoundaryLbl;
3982 + Widget mpdStringAttributesLbl;
3983 + Widget sabCaseSensitiveW;
3984 + Widget sabRegularExpressionW;
3985 + Widget mpdStringPatternLbl;
3986 + Widget mpdStringPatternW;
3987 + Widget mpdSubPatNamesLbl;
3988 + Widget mpdSubPatNamesOptMenu;
3989 + Widget mpdSubPatNamesPulldown;
3990 + char *mpdLangModeName;
3991 + DialogMatchPatternSequenceElement *currentDmptSeqElement;
3992 + DialogMatchPatternTableElement *currentDmptElement;
3993 + DialogMatchPatternGroupElement *currentDmptGroup;
3994 + DialogStringPatterns currentStringPatterns;
3995 + DialogMatchPatternInfo mpdTable;
3996 + int mpdStringPatternIsDisplayed;
3997 +} MatchPatternDialog =
3998 + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
3999 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
4000 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
4001 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
4002 + NULL, NULL, NULL, NULL,
4009 + * Matching pattern sources loaded from the nedit resources file or set
4012 +static int NbrMatchTables = 0;
4013 +static StringMatchTable *MatchTables[MAX_LANGUAGE_MODES];
4017 + * LanguagePatternSet ::=
4018 + * LanguageName{PatternStatement..}
4020 + * PatternStatement ::=
4021 + * name:[s]:[c][f][m][p][u]:([s|m|e][w|l|r][i]:"pattern":)..)\n)|
4022 + * name:g:"sub-pattern name":..\n..
4025 + * s : sub-pattern (pattern is only matched, if part of a pattern group).
4026 + * g : pattern (context) group (i.e. a sequence of sub-patterns).
4027 + * default: individual pattern (pattern is matched individually).
4028 + * GlobalAttribute:
4029 + * c : the content between start and end pattern is skipped
4030 + * during parsing (e.g. pattern encloses a comment).
4031 + * f : flash matching pattern (if not set, then only jump
4032 + * to matching pattern is supported).
4033 + * m : mono pattern - set exist out of only one single pattern
4034 + * (start pattern = end pattern; e.g. quotes like ")
4035 + * p : ignore highlight info code of single patterns of this set
4037 + * StringPatternKind:
4038 + * s : start string pattern.
4039 + * m : middle string pattern.
4040 + * e : end string pattern.
4041 + * WordBoundaryAttribute:
4042 + * w : pattern is word (i.e. before and after pattern
4043 + * there must be a delimiter).
4044 + * l : before pattern must be a delimiter (left side).
4045 + * r : after pattern must be a delimiter (right side).
4046 + * default: neither before nor after pattern must be a delimiter.
4047 + * StringAttribute:
4048 + * i : pattern is case insensitive (if not set: pattern is
4049 + * case sensitive).
4050 + * x : pattern is regular expression (if not set: pattern is
4051 + * literal string).
4053 + * \n : end of pattern
4056 +static char *DefaultStringMatchTable[] = {
4058 + "Round braces::fp:s:\"(\":e:\")\":\n"
4059 + "Curly braces::fp:s:\"{\":e:\"}\":\n"
4060 + "Squared braces::fp:s:\"[\":e:\"]\":\n"
4061 + "Sharp braces::fp:s:\"<\":e:\">\":\n}",
4063 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4064 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4065 + "Single Quotes:s:cmf:s:\"'\":\n"
4066 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4067 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4068 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4069 + "#ifdef statement:s:f:sx:\"#\\s*ifdef\":sx:\"#\\s*ifndef\":sx:\"#\\s*if\":mx:\"#\\s*elif\":mx:\"#\\s*else\":ex:\"#\\s*endif\":\n"
4070 + "#if group:g:Comment:Double Quotes:Single Quotes:#ifdef statement:\n"
4071 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4073 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4074 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4075 + "Single Quotes:s:cmf:s:\"'\":\n"
4076 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4077 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4078 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4079 + "#ifdef statement:s:f:sx:\"#\\s*ifdef\":sx:\"#\\s*ifndef\":sx:\"#\\s*if\":mx:\"#\\s*elif\":mx:\"#\\s*else\":ex:\"#\\s*endif\":\n"
4080 + "#if group:g:Comment:Double Quotes:Single Quotes:#ifdef statement:\n"
4081 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4083 + "comment:s:cf:s:\"/*\":e:\"*/\":\n"
4084 + "curly braces:s:f:s:\"{\":e:\"}\":\n"
4085 + "round braces:s:f:s:\"(\":e:\")\":\n"
4086 + "double quotes:s:cfm:s:\"\"\"\":\n"
4087 + "single quotes:s:cfm:s:\"'\":\n"
4088 + "braces:g:comment:single quotes:double quotes:curly braces:round braces:\n}",
4090 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4091 + "Single Quotes:s:cmf:s:\"'\":\n"
4092 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4093 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4094 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4095 + "if statement:s:f:sw:\"if\":mw:\"else\":ew:\"endif\":\n"
4096 + "switch statement:s:f:sw:\"switch\":mw:\"case\":mw:\"default\":ew:\"endsw\":\n"
4097 + "foreach statement:s:f:sw:\"for\":ew:\"end\":\n"
4098 + "while statement:s:f:sw:\"while\":ew:\"end\":\n"
4099 + "statement group:g:Double Quotes:Single Quotes:if statement:switch statement:foreach statement:while statement:\n"
4100 + "Braces:g:Double Quotes:Single Quotes:Squared braces:Round braces:Curly braces:\n}",
4102 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4103 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4104 + "Single Quotes:s:cmf:s:\"'\":\n"
4105 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4106 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4107 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4108 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4110 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4111 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4112 + "Single Quotes:s:cmf:s:\"'\":\n"
4113 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4114 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4115 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4116 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4118 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4119 + "Single Quotes:s:cmf:s:\"'\":\n"
4120 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4121 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4122 + "Braces:g:Double Quotes:Single Quotes:Curly braces:Round braces:\n}",
4124 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4125 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4126 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4127 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4128 + "Braces:g:Double Quotes:Curly braces:Round braces:Squared braces:\n}",
4130 + "Single Quotes:s:cmf:s:\"'\":\n"
4131 + "Comment1:s:cf:s:\"(*\":e:\"*)\":\n"
4132 + "Comment2:s:cf:s:\"{\":e:\"}\":\n"
4133 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4134 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4135 + "Block:s:f:swi:\"begin\":ewi:\"end\":\n"
4136 + "Case:s:fp:swi:\"case\":ewi:\"end\":\n"
4137 + "Record:s:f:swi:\"record\":ewi:\"end\":\n"
4138 + "Statement:g:Comment1:Comment2:Single Quotes:Block:Case:Record:\n"
4139 + "Braces:g:Comment1:Comment2:Single Quotes:Round braces:Squared braces:\n}",
4141 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4142 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4143 + "Single Quotes:s:cmf:s:\"'\":\n"
4144 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4145 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4146 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4147 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4149 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4150 + "Single Quotes:s:cmf:s:\"'\":\n"
4151 + "Sharp braces:s:f:s:\"<\":e:\">\":\n"
4152 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4153 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4154 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4155 + "Braces:g:Double Quotes:Single Quotes:Sharp braces:Curly braces:Round braces:Squared braces:\n}",
4157 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4158 + "Single Quotes:s:cmf:s:\"'\":\n"
4159 + "Back Quotes:s:cfm:s:\"`\":\n"
4160 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4161 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4162 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4163 + "if statement:s:f:sw:\"if\":mw:\"elif\":mw:\"else\":ew:\"fi\":\n"
4164 + "case statement:s:f:sw:\"case\":ew:\"esac\":\n"
4165 + "for statement:s:f:sw:\"for\":mw:\"do\":ew:\"done\":\n"
4166 + "while statement:s:f:sw:\"while\":mw:\"do\":ew:\"done\":\n"
4167 + "statement group:g:Double Quotes:Single Quotes:if statement:case statement:for statement:while statement:\n"
4168 + "Braces:g:Double Quotes:Single Quotes:Back Quotes:Squared braces:Round braces:Curly braces:\n}",
4170 + "round braces:s:f:s:\"(\":e:\")\":\n"
4171 + "comment:s:cf:s:\"<!--\":e:\"-->\":\n"
4172 + "cdata + ignore:s:cf:sx:\"\\<!\\[((?icdata)|(\\s*IGNORE\\s*))\\[\":ex:\"\\]\\]\\>\":\n"
4173 + "short element:s:cf:sx:\"(?n\\<[\\l_][^@$%/\"\"';!>\\s]*(?=[^>]*/\\>))\":ex:\"/\\>\":\n"
4174 + "element pair:s:f:sx:\"(?n\\<(*1[\\l|_][^@$%/\"\"';!>\\s]*)\\>)\":sx:\"(?n\\<(*1[\\l|_][^@$%/\"\"';!>\\s]*)(?=[^>]*[^/]\\>))\":eix:\"\\</\\1\\>\":\n"
4175 + "processing instruction:s:f:sx:\"\\<\\?\\S+\":ex:\"\\?\\>\":\n"
4176 + "double quotes:s:cmf:s:\"\"\"\":\n"
4177 + "single quotes:s:cmf:s:\"'\":\n"
4178 + "tags:g:comment:double quotes:single quotes:round braces:cdata + ignore:element pair:short element:processing instruction:\n}",
4181 +static char *StandardStringMatchTable =
4182 + "{Round braces::fp:s:\"(\":e:\")\":\n"
4183 + "Curly braces::fp:s:\"{\":e:\"}\":\n"
4184 + "Squared braces::fp:s:\"[\":e:\"]\":\n}";
4187 +** Return string match table related to given language mode name.
4188 +** Return NULL, if no table is found.
4190 +void *FindStringMatchTable(const char *langModeName)
4192 + const char *nameToSearch;
4195 + if (langModeName == NULL)
4196 + nameToSearch = PLAIN_LM_STRING;
4198 + nameToSearch = langModeName;
4200 + for (i=0; i<NbrMatchTables; i++)
4201 + if (!strcmp(nameToSearch, MatchTables[i]->smtLanguageMode))
4202 + return (void *)MatchTables[i];
4207 +** Change the language mode name of string match tables for language
4208 +** "oldName" to "newName" in both the stored tables, and the table
4209 +** currently being edited in the dialog.
4211 +void RenameStringMatchTable(const char *oldName, const char *newName)
4215 + for (i=0; i<NbrMatchTables; i++)
4217 + if (!strcmp(oldName, MatchTables[i]->smtLanguageMode))
4219 + XtFree(MatchTables[i]->smtLanguageMode);
4220 + MatchTables[i]->smtLanguageMode = XtNewString(newName);
4223 + if (MatchPatternDialog.mpdShell != NULL)
4225 + if (!strcmp(MatchPatternDialog.mpdLangModeName, oldName))
4227 + XtFree(MatchPatternDialog.mpdLangModeName);
4228 + MatchPatternDialog.mpdLangModeName = XtNewString(newName);
4234 +** Delete string match table related to given language mode name.
4236 +void DeleteStringMatchTable(const char *langModeName)
4240 + for (i=0; i<NbrMatchTables; i++)
4242 + if (!strcmp(langModeName, MatchTables[i]->smtLanguageMode))
4245 + * free (delete) existing matching pattern
4247 + freeStringMatchTable(MatchTables[i]);
4250 + &MatchTables[i+1],
4251 + (NbrMatchTables-1 - i) * sizeof(StringMatchTable *));
4259 +** Assign a standard string match table to a given new language mode.
4261 +void AssignStandardStringMatchTable(const char *langModeName)
4264 + StringMatchTable *newTable;
4267 + * assign standard table for new language mode
4268 + * add table to end
4270 + list = StandardStringMatchTable;
4272 + readMatchPatternSetContent(&list, list, XtNewString(langModeName));
4275 + * add table to end
4277 + MatchTables[NbrMatchTables++] = newTable;
4281 +** Returns True if there is a string match table, or potential table
4282 +** not yet committed in the match pattern dialog for a language mode,
4284 +int LMHasStringMatchTable(const char *languageMode)
4286 + StringMatchTable *table = FindStringMatchTable(languageMode);
4288 + if (table != NULL && table->smtNumberOfSeqElements != 0)
4290 + return MatchPatternDialog.mpdShell != NULL &&
4291 + !strcmp(MatchPatternDialog.mpdLangModeName, languageMode) &&
4292 + MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements != 0;
4296 +** Read a string representing string matching pattern sets and add them
4297 +** to the StringMatchTable list of loaded string match patterns.
4298 +** Returns true, if read of string was successful.
4300 +int LoadMatchPatternString(char *inString)
4302 + char *inPtr = inString;
4303 + StringMatchTable *table;
4309 + * read each matching pattern set
4311 + table = readMatchPatternSet(&inPtr);
4313 + if (table != NULL)
4316 + * add/change the pattern set in the list
4318 + for (i=0; i<NbrMatchTables; i++)
4320 + if (!strcmp(MatchTables[i]->smtLanguageMode, table->smtLanguageMode))
4322 + freeStringMatchTable(MatchTables[i]);
4323 + MatchTables[i] = table;
4327 + if (i == NbrMatchTables)
4329 + MatchTables[NbrMatchTables++] = table;
4330 + if (NbrMatchTables > MAX_LANGUAGE_MODES)
4338 + * find end of this pattern. if the string ends here, we're done
4340 + inPtr = strstr(inPtr, "\n");
4341 + if (inPtr == NULL)
4347 + * skip newline, tabs & spaces in front of next pattern.
4348 + * if the string ends here, we're done
4350 + inPtr += strspn(inPtr, " \t\n");
4351 + if (*inPtr == '\0')
4359 +** Create a string in the correct format for the matchPatterns resource,
4360 +** containing all of the matching pattern information from the stored
4361 +** matching pattern sets for this NEdit session.
4363 +char *WriteMatchPatternString(void)
4365 + char *outStr, *str, *escapedStr;
4366 + textBuffer *outBuf;
4367 + int i, written = False;
4368 + StringMatchTable *table;
4370 + outBuf = BufCreate();
4372 + for (i=0; i<NbrMatchTables; i++)
4374 + table = MatchTables[i];
4378 + BufInsert(outBuf, outBuf->length, table->smtLanguageMode);
4379 + BufInsert(outBuf, outBuf->length, ":");
4381 + if (isDefaultMatchPatternTable(table))
4383 + BufInsert(outBuf, outBuf->length, "Default\n\t");
4387 + BufInsert(outBuf, outBuf->length, "{\n");
4388 + BufInsert(outBuf, outBuf->length,
4389 + str = createMatchPatternsString(table, "\t\t"));
4391 + BufInsert(outBuf, outBuf->length, "\t}\n\t");
4396 + * Get the output string, and lop off the trailing newline and tab
4398 + outStr = BufGetRange(outBuf, 0, outBuf->length - (written?2:0));
4402 + * Protect newlines and backslashes from translation by the resource
4405 + escapedStr = EscapeSensitiveChars(outStr);
4409 + return escapedStr;
4413 +** Check, if last pattern is a duplicate of a previous pattern.
4414 +** Convert last pattern to a reference, if so.
4416 +static void treatDuplicatedPattern(
4417 + MatchPatternTable *table,
4418 + PatternElement *prevPattern,
4419 + PatternReference prevPatRef,
4420 + PatternElement *lastPattern,
4421 + PatternReference lastPatRef)
4423 + StringPattern *prevStringPat;
4424 + StringPattern *lastStringPat;
4425 + StringPattern *stringPat;
4426 + PatternReference *oldList;
4430 + * No duplicate check needed, if previous pattern is a reference,
4431 + * due to the related multi pattern element is checked before.
4433 + if (prevPattern->peType == PET_REFERENCE)
4436 + prevStringPat = GetStringPattern(table, prevPattern);
4437 + lastStringPat = GetStringPattern(table, lastPattern);
4439 + if (!AllocatedStringsDiffer(prevStringPat->spText, lastStringPat->spText) &&
4440 + !AllocatedStringsDiffer(prevStringPat->spOrigText, lastStringPat->spOrigText) &&
4441 + prevStringPat->spWordBoundary == lastStringPat->spWordBoundary &&
4442 + prevStringPat->spCaseInsensitive == lastStringPat->spCaseInsensitive &&
4443 + prevStringPat->spRegularExpression == lastStringPat->spRegularExpression)
4446 + * Patterns are identical: Is prevPattern already a multi pattern ?
4448 + if (prevPattern->peType == PET_MULTIPLE)
4451 + * just add ref. to "lastPattern" to the ref. list
4453 + (prevPattern->peVal.peuMulti.mpNumberOfReferences) ++;
4454 + nbrOfRef = prevPattern->peVal.peuMulti.mpNumberOfReferences;
4455 + oldList = prevPattern->peVal.peuMulti.mpRefList;
4456 + prevPattern->peVal.peuMulti.mpRefList =
4457 + (PatternReference *)XtMalloc( nbrOfRef * sizeof(PatternReference) );
4459 + prevPattern->peVal.peuMulti.mpRefList,
4461 + (nbrOfRef-1) * sizeof(PatternReference) );
4462 + prevPattern->peVal.peuMulti.mpRefList[nbrOfRef-1] = lastPatRef;
4463 + XtFree( (char *)oldList );
4468 + * convert prev. single pattern to multi pattern
4470 + stringPat = &prevPattern->peVal.peuSingle;
4471 + prevPattern->peType = PET_MULTIPLE;
4472 + prevPattern->peVal.peuMulti.mpStringPattern = *stringPat;
4473 + prevPattern->peVal.peuMulti.mpNumberOfReferences = 1;
4474 + prevPattern->peVal.peuMulti.mpRefList =
4475 + (PatternReference *)XtMalloc( sizeof(PatternReference) );
4476 + prevPattern->peVal.peuMulti.mpRefList[0] = lastPatRef;
4480 + * convert last single pattern to reference
4482 + freeStringPattern( &(lastPattern->peVal.peuSingle) );
4483 + lastPattern->peType = PET_REFERENCE;
4484 + lastPattern->peVal.peuRef = prevPatRef;
4489 +** Check, if last pattern is a duplicate of a pattern stored within a
4490 +** previous match pattern table element.
4491 +** Convert last pattern to a reference, if so.
4493 +static void treatDuplicatedPatternElements(
4494 + MatchPatternTable *table,
4495 + MatchPatternTableElement *prevElement,
4496 + int prevElementIdx,
4497 + PatternElement *lastPattern,
4498 + PatternReference lastPatRef)
4501 + PatternReference prevPatRef;
4503 + prevPatRef.prElementIdx = prevElementIdx;
4505 + for (i=0; i<prevElement->mpteAll.pesNumberOfPattern; i++)
4507 + prevPatRef.prPatternIdx = i;
4508 + treatDuplicatedPattern(
4510 + prevElement->mpteAll.pesPattern[i],
4518 +** Check, if a pattern of last match pattern table element is a
4519 +** duplicate of a pattern stored within a previous match pattern table
4521 +** Convert duplicated last patterns to references, if so.
4523 +static void treatDuplicatedMTElements(
4524 + MatchPatternTable *table,
4525 + MatchPatternTableElement *prevElement,
4526 + int prevElementIdx,
4527 + MatchPatternTableElement *lastElement,
4528 + int lastElementIdx)
4531 + PatternReference lastPatRef;
4533 + lastPatRef.prElementIdx = lastElementIdx;
4535 + for (i=0; i<lastElement->mpteAll.pesNumberOfPattern; i++)
4537 + lastPatRef.prPatternIdx = i;
4538 + treatDuplicatedPatternElements(
4542 + lastElement->mpteAll.pesPattern[i],
4548 +** Convert all duplicated patterns of given match pattern table to
4551 +static void treatDuplicatedMTEntries(
4552 + MatchPatternTableElement **element,
4553 + int nbrOfElements)
4556 + MatchPatternTableElement *lastElement;
4557 + int lastElementIdx;
4558 + MatchPatternTable table;
4560 + if (nbrOfElements < 2)
4563 + lastElementIdx = nbrOfElements - 1;
4564 + lastElement = element[lastElementIdx];
4566 + table.mptElements = element;
4567 + table.mptNumberOfElements = nbrOfElements;
4569 + for (i=0; i<nbrOfElements-1; i ++)
4571 + treatDuplicatedMTElements( &table, element[i], i, lastElement, lastElementIdx );
4576 +** Compile regular expressions of all string patterns of given
4577 +** match pattern table element.
4578 +** Returns true, if compilation fails.
4580 +static int createStrPatRegExpOfElement(
4581 + ReadMatchPatternInfo *readPatInfo,
4582 + MatchPatternTableElement *element,
4583 + ErrorInfo *errInfo)
4586 + StringPattern *strPat;
4588 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
4590 + strPat = getReadStringPattern(readPatInfo, element->mpteAll.pesPattern[i]);
4593 + * if current string pattern holds a regular expression, then
4596 + if (strPat->spRegularExpression)
4598 + if (createStrPatRegExp(strPat, errInfo))
4601 + * compilation was not successful
4603 + errInfo->eiMPTabElementName = XtNewString(element->mpteName);
4613 +** Compile regular expressions of given string pattern.
4614 +** Returns true, if compilation fails.
4616 +static int createStrPatRegExp(
4617 + StringPattern *strPat,
4618 + ErrorInfo *errInfo)
4620 + char *regExpString;
4624 + * compose regular expression for start string pattern.
4626 + if( strPat->spCaseInsensitive)
4629 + * Add '(?i .. )' to given text for case insensitive search.
4630 + * Allocate buffer to hold 5 more char than text length
4631 + * (4 char '(?i)' + \0 char.
4633 + regExpString = XtMalloc(strPat->spLength + 5);
4634 + strcpy(regExpString, "(?i");
4635 + strcat(regExpString, strPat->spText);
4636 + strcat(regExpString, ")");
4640 + regExpString = strPat->spText;
4644 + * compile regular expression & free allocated string buffer,
4647 + strPat->spTextRE =
4648 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
4650 + if (strPat->spTextRE == NULL)
4653 + * compilation was not successful: adapt error reason by
4654 + * converting local backrefs to global ones.
4656 + adaptCompileMsg(compileMsg, strPat->spGlobalToLocalBackRef);
4658 + errInfo->eiRegExpCompileMsg = compileMsg;
4659 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
4662 + if (strPat->spCaseInsensitive)
4663 + XtFree( regExpString );
4665 + return (strPat->spTextRE == NULL);
4669 +** adapt regular expression compilation message by converting local
4670 +** backrefs to global ones.
4672 +static void adaptCompileMsg(
4674 + int *globalToLocalBackRef)
4678 + char *s = compileMsg;
4680 + while (*s != '\0')
4684 + if (isdigit((unsigned char)*(s+1)))
4687 + * \n (n=1..9) found: substitute local by global back ref.
4692 + (int)((unsigned char)*s - (unsigned char)'0');
4694 + globalId = localToGlobalBackRef(globalToLocalBackRef, localId);
4696 + *s = (char)((int)('0') + globalId);
4698 + else if (*(s+1) != '\0')
4706 +** translate given local backref to global backref by using
4707 +** given globalToLocalBackRef list.
4709 +static int localToGlobalBackRef(
4710 + int *globalToLocalBackRef,
4715 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
4717 + if (globalToLocalBackRef[i] == localId)
4725 +** Create a regular expression holding keywords of given start & end
4727 +** Returns true, if creation of regular expression has failed.
4729 +static int createStartEndRegExp(
4730 + ReadMatchPatternInfo *readMatchPatternInfo,
4731 + MatchPatternTableElement *element,
4732 + ErrorInfo *errInfo)
4734 + char *regExpString;
4738 + * compose regular expression for start / end pattern.
4740 + composeStartEndRegExpString(
4741 + readMatchPatternInfo,
4746 + * compile regular expression & free allocated string buffer.
4748 + element->mpteStartEndRE =
4749 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
4751 + XtFree( regExpString );
4753 + if( element->mpteStartEndRE == NULL)
4755 + errInfo->eiRegExpCompileMsg = compileMsg;
4756 + errInfo->eiDetail = "Error compiling start / end reg. exp.";
4759 + return (element->mpteStartEndRE == NULL);
4763 +** Create a regular expression holding keywords of given group element.
4764 +** Returns true, if creation of regular expression has failed.
4766 +static int createGroupRegExp(
4767 + ReadMatchPatternInfo *readPatInfo,
4768 + MatchPatternGroupElement *group,
4769 + ErrorInfo *errInfo)
4772 + MatchPatternTableElement *element;
4773 + RegExpStringInfo regExpStringInfo;
4774 + char *regExpString;
4775 + regexp *keywordRE;
4779 + * Allocate buffers for keyword regular expression of this group.
4781 + setupRegExpStringBuffers(
4783 + ®ExpStringInfo);
4785 + for (i=0; i<group->mpgeNumberOfSubPatterns; i++)
4787 + element = getPatternOfName(readPatInfo, group->mpgeSubPatternIds[i]);
4789 + * Add the keywords of the sub pattern to the keyword regular
4790 + * expression string buffer of new group.
4792 + addElementToRegExpString(
4795 + ®ExpStringInfo);
4799 + * Assemble and compile the resulting keyword regular expression string.
4801 + catSMTRegExpStrings(
4802 + ®ExpStringInfo,
4805 + keywordRE = CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
4807 + XtFree( regExpString );
4809 + if (keywordRE == NULL)
4811 + errInfo->eiMPTabElementName = XtNewString(group->mpgeName);
4812 + errInfo->eiRegExpCompileMsg = compileMsg;
4813 + errInfo->eiDetail = "Group: Compile reg. exp. error";
4816 + group->mpgeKeywordRE = keywordRE;
4818 + return (keywordRE == NULL);
4822 +** Allocate memory for regular expression strings to be
4823 +** created out of read match pattern info.
4825 +static void setupRegExpStringBuffers(
4826 + ReadMatchPatternInfo *readMatchPatternInfo,
4827 + RegExpStringInfo *regExpStringInfo)
4830 + int nbrOfMultiPatterns;
4831 + int sizeOfPatRefs;
4834 + * determine total length of pattern characters to determine
4835 + * the size of a string buffer for the regular expression to
4836 + * compose. Count number of total multi patterns, too.
4839 + totalKeywordOfTableLen( readMatchPatternInfo, &nbrOfMultiPatterns );
4842 + * allocate memory to store added multi pattern references (to avoid
4843 + * duplicated keywords strings later on).
4845 + sizeOfPatRefs = sizeof(PatternReference *) * nbrOfMultiPatterns;
4847 + regExpStringInfo->resiAddedMultiPat =
4848 + (PatternReference **)XtMalloc( sizeOfPatRefs );
4850 + regExpStringInfo->resiNbrOfAddedMultiPat = 0;
4853 + * init. ID of capturing local backrefs
4855 + regExpStringInfo->resiLocalBackRefID = 1;
4858 + * allocate & init. string buffers for regular expression:
4859 + * 3 times the size + x of all pattern characters (due to
4860 + * a.) each char may need to be escaped
4861 + * b.) '<(?:', ')>', ')' and '|' need to be added.
4863 + regExpStringInfo->resiNoneWBRegExpString = XtMalloc( 3 * totalLen );
4864 + regExpStringInfo->resiLeftWBRegExpString = XtMalloc( 3 * totalLen + 5 );
4865 + regExpStringInfo->resiRightWBRegExpString = XtMalloc( 3 * totalLen + 5 );
4866 + regExpStringInfo->resiBothWBRegExpString = XtMalloc( 3 * totalLen + 6 );
4868 + strcpy( regExpStringInfo->resiNoneWBRegExpString, "" );
4869 + strcpy( regExpStringInfo->resiLeftWBRegExpString, "" );
4870 + strcpy( regExpStringInfo->resiRightWBRegExpString, "" );
4871 + strcpy( regExpStringInfo->resiBothWBRegExpString, "" );
4875 +** Concatenate given 'partToAdd' string to result string, separated
4876 +** by an OR ('|'). Add 'postfix' at end of result string.
4878 +static void addSMTRegExpString(
4881 + const char *postfix)
4883 + if (strlen(partToAdd) != 0)
4885 + if (strlen(result) != 0)
4887 + strcat( result, "|" );
4890 + strcat( result, partToAdd );
4892 + strcat( result, postfix );
4898 +** Return a string representing given string match table.
4900 +static char *createMatchPatternsString(
4901 + StringMatchTable *table,
4904 + char *outStr, *str;
4905 + textBuffer *outBuf;
4907 + MatchPatternSequenceElement *seq;
4908 + MatchPatternTableElement *element;
4909 + MatchPatternGroupElement *group;
4911 + outBuf = BufCreate();
4913 + for (i=0; i<table->smtNumberOfSeqElements; i++)
4915 + seq = table->smtSequence[i];
4917 + BufInsert(outBuf, outBuf->length, indentStr);
4918 + BufInsert(outBuf, outBuf->length, seq->mpseName);
4919 + BufInsert(outBuf, outBuf->length, ":");
4921 + if (seq->mpseType == MPT_GROUP)
4923 + BufInsert(outBuf, outBuf->length, "g:");
4925 + group = table->smtGroups[seq->mpseIndex];
4927 + for (j=0; j < group->mpgeNumberOfSubPatterns; j ++)
4929 + BufInsert(outBuf, outBuf->length, group->mpgeSubPatternIds[j]);
4930 + BufInsert(outBuf, outBuf->length, ":");
4935 + if (seq->mpseType == MPT_SUB)
4937 + BufInsert(outBuf, outBuf->length, "s");
4939 + BufInsert(outBuf, outBuf->length, ":");
4941 + element = table->smtAllPatterns->mptElements[seq->mpseIndex];
4944 + * write global attributes
4946 + if (element->mpteSkipBtwnStartEnd)
4947 + BufInsert(outBuf, outBuf->length, "c");
4948 + if (element->mpteFlash)
4949 + BufInsert(outBuf, outBuf->length, "f");
4950 + if (element->mpteIsMonoPattern)
4951 + BufInsert(outBuf, outBuf->length, "m");
4952 + if (element->mpteIgnoreHighLightInfo)
4953 + BufInsert(outBuf, outBuf->length, "p");
4954 + BufInsert(outBuf, outBuf->length, ":");
4957 + * write string patterns
4959 + for (j=0; j < element->mpteAll.pesNumberOfPattern; j ++)
4965 + createPatternElementString(
4966 + table->smtAllPatterns,
4967 + element->mpteAll.pesPattern[j]));
4972 + BufInsert(outBuf, outBuf->length, "\n");
4975 + outStr = BufGetAll(outBuf);
4982 +** Return a string representing given pattern element.
4984 +static char *createPatternElementString(
4985 + MatchPatternTable *table,
4986 + PatternElement *pat)
4988 + char *outStr, *str;
4989 + textBuffer *outBuf;
4990 + StringPattern *strPat;
4992 + outBuf = BufCreate();
4994 + strPat = GetStringPattern(table, pat);
4997 + * write string pattern kind
4999 + if (pat->peKind == PEK_START)
5000 + BufInsert(outBuf, outBuf->length, "s");
5001 + else if (pat->peKind == PEK_MIDDLE)
5002 + BufInsert(outBuf, outBuf->length, "m");
5003 + else if (pat->peKind == PEK_END)
5004 + BufInsert(outBuf, outBuf->length, "e");
5007 + * write word boundary
5009 + if (strPat->spWordBoundary == PWB_BOTH)
5010 + BufInsert(outBuf, outBuf->length, "w");
5011 + else if (strPat->spWordBoundary == PWB_LEFT)
5012 + BufInsert(outBuf, outBuf->length, "l");
5013 + else if (strPat->spWordBoundary == PWB_RIGHT)
5014 + BufInsert(outBuf, outBuf->length, "r");
5017 + * write case insensitive flag
5019 + if (strPat->spCaseInsensitive)
5020 + BufInsert(outBuf, outBuf->length, "i");
5023 + * write regular expression flag
5025 + if (strPat->spRegularExpression)
5026 + BufInsert(outBuf, outBuf->length, "x");
5028 + BufInsert(outBuf, outBuf->length, ":");
5031 + * write pattern string
5033 + if( strPat->spOrigText != NULL)
5037 + str = MakeQuotedString(strPat->spOrigText));
5042 + str = MakeQuotedString(strPat->spText));
5045 + BufInsert(outBuf, outBuf->length, ":");
5047 + outStr = BufGetAll(outBuf);
5054 +** Given a language mode name, determine if there is a default (built-in)
5055 +** string match table available for that language mode, and if so, read it and
5056 +** return a new allocated copy of it. The returned pattern set should be
5057 +** freed by the caller with freeStringMatchTable().
5059 +static StringMatchTable *readDefaultStringMatchTable(const char *langModeName)
5061 + int i, modeNameLen;
5064 + modeNameLen = strlen(langModeName);
5066 + for (i=0; i<(int)XtNumber(DefaultStringMatchTable); i++)
5068 + if (!strncmp(langModeName, DefaultStringMatchTable[i], modeNameLen) &&
5069 + DefaultStringMatchTable[i][modeNameLen] == '{')
5071 + list = DefaultStringMatchTable[i];
5072 + return readMatchPatternSet(&list);
5076 + list = StandardStringMatchTable;
5077 + return readMatchPatternSetContent(&list, list, XtNewString(langModeName));
5081 +** Return true, if table exactly matches one of the default matching
5084 +static int isDefaultMatchPatternTable(StringMatchTable *table)
5086 + StringMatchTable *defaultTable;
5089 + defaultTable = readDefaultStringMatchTable(table->smtLanguageMode);
5091 + if (defaultTable == NULL)
5094 + retVal = !stringMatchTableDiffer(table, defaultTable);
5096 + freeStringMatchTable(defaultTable);
5102 +** Read in a string match pattern table character string,
5103 +** and advance *inPtr beyond it.
5104 +** Returns NULL and outputs an error to stderr on failure.
5106 +static StringMatchTable *readMatchPatternSet(char **inPtr)
5108 + char *languageMode;
5109 + StringMatchTable *table = NULL;
5110 + char *stringStart = *inPtr;
5111 + ErrorInfo errInfo;
5113 + initErrorInfo(&errInfo);
5116 + * remove leading whitespace
5118 + *inPtr += strspn(*inPtr, " \t\n");
5121 + * read language mode field
5123 + languageMode = ReadSymbolicField(inPtr);
5126 + * look for initial brace
5128 + if (**inPtr == ':')
5132 + * look for "Default" keyword, and if it's there, return the default
5135 + if (!strncmp(*inPtr, "Default", 7))
5138 + table = readDefaultStringMatchTable(languageMode);
5139 + XtFree(languageMode);
5145 + table = readMatchPatternSetContent(inPtr, stringStart, languageMode);
5147 + if (table == NULL)
5148 + XtFree(languageMode);
5154 +** Read in a content string ("{..}") of match pattern table,
5155 +** and advance *inPtr beyond it.
5156 +** Returns NULL and outputs an error to stderr on failure.
5158 +static StringMatchTable *readMatchPatternSetContent(
5160 + char *stringStart,
5161 + char *languageMode)
5163 + ReadMatchPatternInfo readPatInfo;
5164 + StringMatchTable *table = NULL;
5165 + ErrorInfo errInfo;
5166 + int successful = True;
5167 + int endOfPatternSet = False;
5169 + initErrorInfo(&errInfo);
5172 + * look for initial brace
5174 + if (**inPtr != '{')
5176 + errInfo.eiLanguageMode = XtNewString(languageMode);
5177 + errInfo.eiDetail = "pattern list must begin with \"{\"";
5178 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo );
5185 + readPatInfo.rmpiNbrOfElements = 0;
5186 + readPatInfo.rmpiNbrOfGroups = 0;
5187 + readPatInfo.rmpiNbrOfSeqElements = 0;
5188 + readPatInfo.rmpiAllPatRE = NULL;
5189 + readPatInfo.rmpiFlashPatRE = NULL;
5192 + * parse each pattern in the list
5194 + while (successful && !endOfPatternSet)
5196 + *inPtr += strspn(*inPtr, " \t\n");
5197 + if (**inPtr == '\0')
5199 + errInfo.eiLanguageMode = XtNewString(languageMode);
5200 + errInfo.eiDetail = "end of pattern list not found";
5201 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5202 + successful = False;
5204 + else if (**inPtr == '}')
5207 + endOfPatternSet = True;
5211 + if (!readMatchPatternEntry(inPtr, &errInfo, &readPatInfo))
5213 + errInfo.eiLanguageMode = XtNewString(languageMode);
5214 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5215 + successful = False;
5223 + * compile regular expressions of read patterns
5225 + if (createRegExpOfPatterns(&readPatInfo, &errInfo))
5227 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5228 + successful = False;
5234 + return createStringMatchTable(&readPatInfo, languageMode);
5239 + * free memory of already read patterns
5241 + freeReadMatchPatternInfo(&readPatInfo);
5250 +** Create a reg. exp. of all patterns contained
5251 +** in given read match pattern info.
5253 +static int createRegExpOfPatterns(
5254 + ReadMatchPatternInfo *readPatInfo,
5255 + ErrorInfo *errInfo)
5257 + if (createRegExpOfStrPatterns(readPatInfo, errInfo))
5260 + if (createRegExpOfAllPatterns(readPatInfo, errInfo))
5267 +** Create a "total pattern reg. exp." of all patterns / flash patterns
5268 +** contained in given read match pattern info.
5269 +** Returns true, if create of reg. exp. has failed.
5271 +static int createRegExpOfAllPatterns(
5272 + ReadMatchPatternInfo *readPatInfo,
5273 + ErrorInfo *errInfo)
5276 + RegExpStringInfo allPatRegExpSI;
5277 + RegExpStringInfo flashPatRegExpSI;
5278 + MatchPatternTableElement *element;
5279 + char *regExpString;
5283 + * Allocate buffers for keyword regular expressions.
5285 + setupRegExpStringBuffers(readPatInfo, &allPatRegExpSI);
5286 + setupRegExpStringBuffers(readPatInfo, &flashPatRegExpSI);
5288 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5290 + element = readPatInfo->rmpiElement[i];
5293 + * Add the keywords of the matching pattern to the keyword
5294 + * regular expression string buffer of all patterns.
5296 + addElementToRegExpString(
5302 + * If flash attribute is set, then add the keywords of the
5303 + * matching pattern also to the keyword regular expression
5304 + * string buffer of flash patterns.
5306 + if (element->mpteFlash)
5308 + addElementToRegExpString(
5311 + &flashPatRegExpSI);
5316 + * Assemble and compile the resulting all keywords reg. exp. string.
5318 + catSMTRegExpStrings(
5322 + readPatInfo->rmpiAllPatRE =
5323 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
5325 + XtFree( regExpString );
5327 + if (readPatInfo->rmpiAllPatRE == NULL)
5329 + errInfo->eiRegExpCompileMsg = compileMsg;
5330 + errInfo->eiDetail = "All patterns: compile reg. exp. error";
5335 + * Assemble and compile the resulting flash keywords reg. exp. string.
5337 + catSMTRegExpStrings(
5338 + &flashPatRegExpSI,
5341 + readPatInfo->rmpiFlashPatRE =
5342 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
5344 + XtFree( regExpString );
5346 + if (readPatInfo->rmpiFlashPatRE == NULL)
5348 + errInfo->eiRegExpCompileMsg = compileMsg;
5349 + errInfo->eiDetail = "Flash patterns: compile reg. exp. error";
5354 + * Pattern reg. exp. successful created:
5360 +** Create reg. exp. of single patterns contained in given
5361 +** read match pattern info.
5362 +** Returns true, if create of reg. exp. has failed.
5364 +static int createRegExpOfStrPatterns(
5365 + ReadMatchPatternInfo *readPatInfo,
5366 + ErrorInfo *errInfo)
5369 + MatchPatternTableElement *element;
5370 + MatchPatternGroupElement *group;
5373 + * create global backref list of all elements of read info
5375 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5377 + element = readPatInfo->rmpiElement[i];
5379 + if (!createGlobalBackRefList(readPatInfo, element, errInfo))
5384 + * resolve global backrefs of all elements of read info
5386 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5388 + element = readPatInfo->rmpiElement[i];
5390 + if (!resolveGlobalBackRefs(readPatInfo, element, errInfo))
5395 + * compile reg. exp. of all elements of read info
5397 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5399 + element = readPatInfo->rmpiElement[i];
5401 + if (createStrPatRegExpOfElement(readPatInfo, element, errInfo))
5405 + * create start / end reg. exp. if applicable.
5407 + if (element->mpteSkipBtwnStartEnd)
5409 + if (createStartEndRegExp(readPatInfo, element, errInfo))
5415 + * compile reg. exp. of all groups of read info
5417 + for (i=0; i < readPatInfo->rmpiNbrOfGroups; i ++)
5419 + group = readPatInfo->rmpiGroup[i];
5421 + if (createGroupRegExp(readPatInfo, group, errInfo))
5431 +** Create a string match table out of read match pattern info.
5433 +static StringMatchTable *createStringMatchTable(
5434 + ReadMatchPatternInfo *readPatInfo,
5435 + char *languageMode)
5437 + StringMatchTable *table;
5438 + MatchPatternTable *patTable;
5439 + int sizeOfElements;
5441 + table = (StringMatchTable *)XtMalloc(sizeof(StringMatchTable));
5442 + table->smtLanguageMode = languageMode;
5445 + * allocate a more appropriately sized list to return matching patterns
5447 + patTable = (MatchPatternTable *)XtMalloc(sizeof(MatchPatternTable));
5448 + patTable->mptNumberOfElements = readPatInfo->rmpiNbrOfElements;
5450 + if (readPatInfo->rmpiNbrOfElements > 0)
5453 + sizeof(MatchPatternTableElement *) * readPatInfo->rmpiNbrOfElements;
5454 + patTable->mptElements =
5455 + (MatchPatternTableElement **)XtMalloc(sizeOfElements);
5456 + memcpy(patTable->mptElements, readPatInfo->rmpiElement, sizeOfElements);
5460 + patTable->mptElements = NULL;
5463 + table->smtAllPatterns = patTable;
5465 + table->smtAllPatRE = readPatInfo->rmpiAllPatRE;
5466 + table->smtFlashPatRE = readPatInfo->rmpiFlashPatRE;
5467 + table->smtUsedPatRE = NULL;
5470 + * allocate a more appropriately sized list to return matching pattern groups
5472 + table->smtNumberOfGroups = readPatInfo->rmpiNbrOfGroups;
5473 + if (readPatInfo->rmpiNbrOfGroups > 0)
5476 + sizeof(MatchPatternGroupElement *) * readPatInfo->rmpiNbrOfGroups;
5477 + table->smtGroups =
5478 + (MatchPatternGroupElement **)XtMalloc(sizeOfElements);
5479 + memcpy(table->smtGroups, readPatInfo->rmpiGroup, sizeOfElements);
5483 + table->smtGroups = NULL;
5486 + * allocate a more appropriately sized list to return matching pattern sequence
5488 + table->smtNumberOfSeqElements = readPatInfo->rmpiNbrOfSeqElements;
5489 + if (readPatInfo->rmpiNbrOfSeqElements > 0)
5492 + sizeof(MatchPatternSequenceElement *) * readPatInfo->rmpiNbrOfSeqElements;
5493 + table->smtSequence =
5494 + (MatchPatternSequenceElement **)XtMalloc(sizeOfElements);
5495 + memcpy(table->smtSequence, readPatInfo->rmpiSequence, sizeOfElements);
5499 + table->smtSequence = NULL;
5506 +** Read one match pattern entry of a match pattern string.
5507 +** Returns true, if read was successful.
5509 +static int readMatchPatternEntry(
5511 + ErrorInfo *errInfo,
5512 + ReadMatchPatternInfo *info)
5515 + MatchPatternType type;
5516 + MatchPatternGroupElement *readGroup;
5517 + MatchPatternTableElement *readElement;
5519 + if (!getMPSName( inPtr, errInfo, &name ))
5524 + if (!getMPSTypeAttribute( inPtr, errInfo, &type ))
5526 + errInfo->eiMPTabElementName = XtNewString(name);
5530 + if (type == MPT_GROUP)
5532 + if (info->rmpiNbrOfGroups >= MAX_NBR_MATCH_PATTERN_GROUPS)
5534 + errInfo->eiMPTabElementName = XtNewString(name);
5535 + errInfo->eiDetail = "max number of match pattern groups exceeded";
5539 + readGroup = readMatchPatternGroup( inPtr, errInfo, name, info );
5541 + if (readGroup == NULL)
5543 + errInfo->eiMPTabElementName = XtNewString(name);
5548 + info->rmpiGroup[info->rmpiNbrOfGroups ++] = readGroup;
5550 + recordPatternSequence( info, name, type, info->rmpiNbrOfGroups-1 );
5553 + return (readGroup != NULL);
5557 + if (info->rmpiNbrOfElements >= MAX_NBR_MATCH_PATTERNS)
5559 + errInfo->eiMPTabElementName = XtNewString(name);
5560 + errInfo->eiDetail = "max number of match patterns exceeded";
5566 + readMatchPatternTableElement( inPtr, &errInfo->eiDetail, name, type );
5568 + if (readElement == NULL)
5570 + errInfo->eiMPTabElementName = XtNewString(name);
5575 + readElement->mpteIndex = info->rmpiNbrOfElements;
5577 + info->rmpiElement[info->rmpiNbrOfElements ++] = readElement;
5579 + if (type == MPT_INDIVIDUAL)
5581 + if (!assignIndividualGroup( info, &errInfo->eiDetail, readElement ))
5583 + errInfo->eiMPTabElementName = XtNewString(name);
5588 + treatDuplicatedMTEntries(
5589 + info->rmpiElement, info->rmpiNbrOfElements );
5591 + recordPatternSequence( info, name, type, info->rmpiNbrOfElements-1 );
5594 + return (readElement != NULL);
5599 +** Record match pattern sequence for display of match pattern dialog.
5601 +static void recordPatternSequence(
5602 + ReadMatchPatternInfo *info,
5604 + MatchPatternType type,
5607 + MatchPatternSequenceElement *sequence;
5610 + (MatchPatternSequenceElement *)XtMalloc( sizeof(MatchPatternSequenceElement) );
5612 + sequence->mpseName = XtNewString(name);
5613 + sequence->mpseType = type;
5614 + sequence->mpseIndex = index;
5616 + info->rmpiSequence[info->rmpiNbrOfSeqElements ++] = sequence;
5620 +** Assign a new group to an individual match pattern.
5621 +** Returns true, if assignment was successful.
5623 +static int assignIndividualGroup(
5624 + ReadMatchPatternInfo *info,
5626 + MatchPatternTableElement *element)
5628 + MatchPatternGroupElement *group = NULL;
5630 + if (info->rmpiNbrOfGroups >= MAX_NBR_MATCH_PATTERN_GROUPS)
5632 + *errMsg = "max. number of matching pattern groups exceeded\n";
5637 + * Assign the index of new group to the individual matching pattern
5639 + element->mpteGroup = info->rmpiNbrOfGroups;
5642 + * Allocate memory for the matching pattern group and copy the
5643 + * info into this group element.
5646 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
5648 + group->mpgeName = NULL;
5649 + group->mpgeKeywordRE = NULL;
5652 + * remember name of match pattern table element, which is
5653 + * represented by this group.
5655 + group->mpgeNumberOfSubPatterns = 1;
5656 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeof(char *) );
5657 + group->mpgeSubPatternIds[0] = XtNewString(element->mpteName);
5659 + info->rmpiGroup[info->rmpiNbrOfGroups ++] = group;
5665 +** Get the match pattern table element of given 'patToSearch'
5667 +** Returns NULL, if no element was found.
5669 +static MatchPatternTableElement *getPatternOfName(
5670 + ReadMatchPatternInfo *info,
5671 + char *patToSearch)
5674 + MatchPatternTableElement *element;
5676 + for (i=0; i<info->rmpiNbrOfElements; i ++)
5678 + element = info->rmpiElement[i];
5680 + if (strcmp( element->mpteName, patToSearch ) == 0)
5683 + * Related sub-pattern found:
5690 + * No sub-pattern found:
5696 +** Read match pattern group of given match pattern string.
5697 +** Returns NULL, if read fails.
5699 +static MatchPatternGroupElement *readMatchPatternGroup(
5701 + ErrorInfo *errInfo,
5703 + ReadMatchPatternInfo *info)
5706 + int error = False;
5707 + char *patNameInPtr;
5709 + MatchPatternTableElement *subPatElement;
5710 + int numberOfRelatedSubPattern = 0;
5711 + char *relatedSubPatternId[MAX_NBR_MATCH_PATTERNS];
5713 + MatchPatternGroupElement *group = NULL;
5716 + * Read sub-matching patterns of this group.
5718 + while (**inPtr != '\n' && !error)
5721 + * Read next pattern name from inPtr.
5723 + patNameInPtr = *inPtr;
5724 + subPatName = ReadSymbolicField(inPtr);
5726 + if (subPatName == NULL)
5728 + errInfo->eiDetail = "Sub-Matching Pattern Name expected";
5734 + * Get matching pattern related to sub-matching pattern name.
5737 + getPatternOfName( info, subPatName );
5739 + if (subPatElement == NULL)
5741 + errInfo->eiStringPatText = XtNewString(subPatName);
5742 + errInfo->eiDetail = "Sub-Matching Pattern not defined before";
5745 + else if (numberOfRelatedSubPattern >= MAX_NBR_MATCH_PATTERNS)
5747 + errInfo->eiDetail = "Group holds too many Sub-Matching Patterns";
5750 + else if (subPatElement->mpteType != MPT_SUB)
5752 + errInfo->eiStringPatText = XtNewString(subPatName);
5753 + errInfo->eiDetail = "Not a Sub-Matching Pattern";
5759 + * Remember sub-matching pattern ID
5761 + relatedSubPatternId[numberOfRelatedSubPattern ++] = subPatName;
5764 + * Assign the index of this group to the sub-matching pattern
5765 + * if no group index was assigned before.
5767 + if (subPatElement->mpteGroup == NO_GROUP_IDX)
5769 + subPatElement->mpteGroup = info->rmpiNbrOfGroups;
5774 + * Skip to the start of the next matching pattern name.
5776 + if (!error && !SkipDelimiter(inPtr, &errInfo->eiDetail))
5785 + for (i=0; i < numberOfRelatedSubPattern; i++)
5787 + XtFree( relatedSubPatternId[i] );
5795 + * Allocate memory for the matching pattern group and copy the
5796 + * info into this group element.
5799 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
5801 + group->mpgeName = name;
5802 + group->mpgeKeywordRE = NULL;
5805 + * Allocate memory for the sub-matching pattern IDs & copy
5806 + * related sub-matching pattern into the group element.
5808 + sizeOfIds = sizeof(char *) * numberOfRelatedSubPattern;
5809 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeOfIds );
5811 + memcpy(group->mpgeSubPatternIds, relatedSubPatternId, sizeOfIds);
5813 + group->mpgeNumberOfSubPatterns = numberOfRelatedSubPattern;
5820 +** Read one match pattern element from given match pattern string.
5821 +** Returns true, if read was successful.
5823 +static int readPatternElement(
5826 + PatternElement **pattern)
5828 + PatternElementKind patternKind;
5829 + PatternWordBoundary wordBoundary;
5830 + int caseInsensitive;
5831 + int regularExpression;
5834 + if (!getMPSPatternAttribute(
5840 + ®ularExpression ))
5845 + if (!ReadQuotedString(inPtr, errMsg, &string))
5850 + if (!SkipDelimiter(inPtr, errMsg))
5857 + createPatternElement(
5862 + regularExpression);
5868 +** Create a pattern element.
5870 +static PatternElement *createPatternElement(
5871 + char *patternText,
5872 + PatternElementKind patternKind,
5873 + PatternWordBoundary wordBoundary,
5874 + int caseInsensitive,
5875 + int regularExpression)
5877 + PatternElement *pattern;
5881 + * Convert pattern text to lower case, if case insensitive
5882 + * attribute is set.
5884 + if (caseInsensitive)
5886 + for (s = patternText; *s != '\0'; s ++)
5893 + * Allocate memory for the new pattern element and init. / copy
5894 + * related info into this pattern element.
5896 + pattern = (PatternElement *)XtMalloc( sizeof(PatternElement) );
5898 + initStrPatBackRefList(&pattern->peVal.peuSingle);
5900 + pattern->peKind = patternKind;
5901 + pattern->peIndex = NO_PATTERN_IDX;
5902 + pattern->peType = PET_SINGLE;
5904 + pattern->peVal.peuSingle.spLength = strlen(patternText);
5905 + pattern->peVal.peuSingle.spBackRefParsed = False;
5906 + pattern->peVal.peuSingle.spBackRefResolved = False;
5908 + pattern->peVal.peuSingle.spCaseInsensitive = caseInsensitive;
5909 + pattern->peVal.peuSingle.spRegularExpression = regularExpression;
5910 + pattern->peVal.peuSingle.spTextRE = NULL;
5913 + * Store original string of regular expression patterns due to
5914 + * it may be later adapted (e.g. due to global backrefs etc.).
5916 + if (regularExpression)
5918 + pattern->peVal.peuSingle.spOrigText = patternText;
5919 + pattern->peVal.peuSingle.spText = NULL;
5920 + pattern->peVal.peuSingle.spWordBoundary = PWB_NONE;
5924 + pattern->peVal.peuSingle.spOrigText = NULL;
5925 + pattern->peVal.peuSingle.spText = patternText;
5926 + pattern->peVal.peuSingle.spWordBoundary = wordBoundary;
5933 +** Create a list holding all global backref definitions of given
5934 +** match pattern table element. The list is stored in this given
5936 +** Returns true, if list was successfully created.
5938 +static int createGlobalBackRefList(
5939 + ReadMatchPatternInfo *readPatInfo,
5940 + MatchPatternTableElement *element,
5941 + ErrorInfo *errInfo)
5944 + StringPattern *strPat;
5946 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
5948 + strPat = getReadStringPattern(readPatInfo, element->mpteAll.pesPattern[i]);
5950 + if (strPat->spRegularExpression)
5952 + if (strPat->spBackRefParsed)
5955 + * Global backrefs or this string pattern already parsed:
5956 + * just merge string pattern list with elements one.
5958 + if (!updateGlobalBackRefs(
5960 + element->mpteGlobalBackRef,
5969 + * parse string pattern for global backrefs and
5970 + * merge string pattern list with elements one.
5972 + if (!parseGlobalBackRefs(
5974 + element->mpteGlobalBackRef,
5987 +** Returns read string pattern of given pattern element.
5989 +StringPattern *getReadStringPattern(
5990 + ReadMatchPatternInfo *readPatInfo,
5991 + PatternElement *pattern )
5993 + switch (pattern->peType)
5996 + return &pattern->peVal.peuSingle;
5999 + case PET_MULTIPLE:
6000 + return &pattern->peVal.peuMulti.mpStringPattern;
6003 + case PET_REFERENCE:
6004 + return getReadStringPattern(
6006 + getReadPatternOfReference(readPatInfo, &pattern->peVal.peuRef));
6011 + * never reached; just to make compiler happy
6017 +** Returns read pattern element of given pattern reference.
6019 +static PatternElement *getReadPatternOfReference(
6020 + ReadMatchPatternInfo *readPatInfo,
6021 + PatternReference *patRef)
6023 + MatchPatternTableElement **element = readPatInfo->rmpiElement;
6025 + return element[ patRef->prElementIdx ]->mpteAll.pesPattern[patRef->prPatternIdx];
6029 +** Allocate a new copy of given string and substitute each capturing
6030 +** parentheses inside given string by a non-capturing one.
6031 +** Returns resulting string.
6033 +static char *replaceCapturingParentheses(
6034 + const char *source)
6036 + char *destination;
6039 + int nbrOfOpenBraces = 0;
6044 + * count number of open braces
6046 + while (*s != '\0')
6049 + nbrOfOpenBraces ++;
6053 + * allocate memory for substitued reg. exp. text
6055 + destination = XtMalloc(strlen(source) + 2*nbrOfOpenBraces);
6058 + * substitute each capturing open brace by a non-capturing one
6063 + while (*s != '\0')
6072 + else if (*s == '(')
6076 + if (*s != '?' && *s != '*')
6090 + return destination;
6094 +** Parse given string pattern for global backrefs definitions
6095 +** (syntax: "(*n", where n=1..9). Add found global backrefs to
6096 +** given backRefList.
6097 +** Returns false, if parse fails.
6099 +static int parseGlobalBackRefs(
6100 + StringPattern *strPat,
6101 + GlobalBackRefElement *backRefList,
6102 + ErrorInfo *errInfo)
6105 + char *backRefContent;
6106 + int nestingLevel = 0;
6107 + int stackIdx = -1;
6108 + BackRefBracketInfo backRefInfo[MAX_GLOBAL_BACK_REF_ID+1];
6109 + StrPatBackRefElement *curStrPatBRE;
6111 + strPat->spText = replaceCapturingParentheses(strPat->spOrigText);
6112 + strPat->spLength = strlen(strPat->spText);
6113 + strPat->spBackRefParsed = True;
6115 + s = strPat->spText;
6117 + while (*s != '\0')
6122 + * Ignore escaped characters
6124 + if (*(s+1) != '\0')
6127 + else if (*s == '(')
6129 + if (*(s+1) == '*')
6131 + if (isdigit((unsigned char)*(s+2)))
6134 + * Global backref. definition start found:
6138 + backRefInfo[stackIdx].brbiGlobalId =
6139 + (int)((unsigned char)*(s+2) - (unsigned char)'0') - 1;
6141 + if(backRefInfo[stackIdx].brbiGlobalId < 0)
6143 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6144 + errInfo->eiDetail = "Backref '0' not allowed";
6148 + backRefInfo[stackIdx].brbiContentStart = s+3;
6149 + backRefInfo[stackIdx].brbiNestingLevel = nestingLevel;
6156 + else if (*s == ')')
6159 + if (stackIdx != -1 &&
6160 + backRefInfo[stackIdx].brbiNestingLevel == nestingLevel)
6163 + * Global backref. definition end found: add it to
6164 + * backref. list of string pattern.
6167 + &strPat->spOwnGlobalBackRef[backRefInfo[stackIdx].brbiGlobalId];
6170 + createBackRefRegExpText(
6171 + backRefInfo[stackIdx].brbiContentStart,
6174 + if (curStrPatBRE->spbreRegExpText != NULL)
6176 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6177 + errInfo->eiBackRefNbr = backRefInfo[stackIdx].brbiGlobalId + 1;
6178 + errInfo->eiDetail = "already defined before";
6179 + XtFree(backRefContent);
6184 + curStrPatBRE->spbreRegExpText = backRefContent;
6194 + * Merge global backref. list of string pattern with given backRefList.
6196 + return updateGlobalBackRefs(
6203 +** Merge global backref. list of given string pattern with given backRefList.
6204 +** Returns false, if merge fails.
6206 +static int updateGlobalBackRefs(
6207 + StringPattern *strPat,
6208 + GlobalBackRefElement *backRefList,
6209 + ErrorInfo *errInfo)
6212 + StrPatBackRefElement *curStrPatBRE;
6213 + GlobalBackRefElement *curGlobalBRE;
6215 + for (i=0;i < MAX_GLOBAL_BACK_REF_ID; i ++)
6217 + curStrPatBRE = &strPat->spOwnGlobalBackRef[i];
6219 + if (curStrPatBRE->spbreRegExpText != NULL)
6221 + curGlobalBRE = &backRefList[i];
6223 + if (curGlobalBRE->gbreDefByStrPat != NULL)
6225 + if (strcmp(curGlobalBRE->gbreRegExpText, curStrPatBRE->spbreRegExpText) != 0)
6227 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6228 + errInfo->eiBackRefNbr = i+1;
6229 + errInfo->eiDetail = "already defined before";
6236 + curGlobalBRE->gbreDefByStrPat = strPat;
6237 + curGlobalBRE->gbreRegExpText = curStrPatBRE->spbreRegExpText;
6246 +** Allocate and return a new string holding content of
6247 +** global backref. definition.
6249 +static char *createBackRefRegExpText(
6250 + const char *start,
6253 + int len = end - start;
6254 + char *regExpText = XtMalloc( len+1 );
6256 + memcpy( regExpText, start, len );
6258 + regExpText[len] = '\0';
6260 + return regExpText;
6264 +** Resolve all global backrefs of given match pattern table element.
6265 +** Returns false, if resolve fails.
6267 +static int resolveGlobalBackRefs(
6268 + ReadMatchPatternInfo *readPatInfo,
6269 + MatchPatternTableElement *element,
6270 + ErrorInfo *errInfo)
6273 + StringPattern *strPat;
6275 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
6277 + strPat = getReadStringPattern(readPatInfo, element->mpteAll.pesPattern[i]);
6279 + if (strPat->spRegularExpression && !strPat->spBackRefResolved)
6281 + if (!resolveGlobalBackRefsOfStrPat(strPat, element->mpteGlobalBackRef, errInfo))
6284 + strPat->spBackRefResolved = True;
6292 +** Resolve global backrefs of given string pattern.
6293 +** Returns false, if resolve fails.
6295 +static int resolveGlobalBackRefsOfStrPat(
6296 + StringPattern *strPat,
6297 + GlobalBackRefElement *backRefList,
6298 + ErrorInfo *errInfo)
6304 + s = strPat->spText;
6306 + while (*s != '\0')
6310 + if (isdigit((unsigned char)*(s+1)))
6313 + * \n (n=1..9) found: substitute global backref.
6316 + (int)((unsigned char)*(s+1) - (unsigned char)'0') - 1;
6320 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6321 + errInfo->eiDetail = "backref '\\0' not allowed";
6325 + s = substituteGlobalBackRef(strPat, s, globalId, &localId, backRefList, errInfo);
6330 + else if (*(s+1) != '\0')
6333 + else if (*s == '(')
6335 + if (*(s+1) == '*')
6337 + if (isdigit((unsigned char)*(s+2)))
6340 + * "(*n" (n=1..9) found: substitute global backref. definition.
6343 + (int)((unsigned char)*(s+2) - (unsigned char)'0') - 1;
6345 + strPat->spOwnGlobalBackRef[globalId].spbreLocalBackRefID = localId;
6346 + strPat->spGlobalToLocalBackRef[globalId] = localId;
6350 + s = convertGlobalToLocalBackRef(strPat, s);
6365 +** Substitute global backref (\n, n=1..9) located at given "subsPtr"
6366 +** by its definition or by a local backref.
6368 +** - NULL, if substitute fails or
6369 +** - substituted string pointer, where scan shall continue with.
6371 +static char *substituteGlobalBackRef(
6372 + StringPattern *strPat,
6376 + GlobalBackRefElement *backRefList,
6377 + ErrorInfo *errInfo)
6379 + StrPatBackRefElement *strPatBackRef = &strPat->spOwnGlobalBackRef[globalId];
6382 + if (strPatBackRef->spbreRegExpText == NULL)
6385 + * given global backref definition is not located in given
6386 + * string pattern -> replace backref ID by backref reg. exp.
6388 + if (backRefList[globalId].gbreRegExpText == NULL)
6390 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6391 + errInfo->eiBackRefNbr = globalId + 1;
6392 + errInfo->eiDetail = "not defined within any string pattern";
6396 + if (strPat->spGlobalToLocalBackRef[globalId] == NO_LOCAL_BACK_REF_ID)
6399 + * 1st occurence of global backref ID in this pattern ->
6400 + * replace global backref ID by backref reg. exp.
6402 + s = replaceBackRefIdByRegExp(strPat, subsPtr, backRefList[globalId].gbreRegExpText);
6404 + strPat->spGlobalToLocalBackRef[globalId] = *localId;
6410 + * next occurence of global backref ID in this pattern ->
6411 + * replace global backref ID by local one
6414 + *s = (char)((int)('0') + strPat->spGlobalToLocalBackRef[globalId]);
6420 + * given global backref definition is located in given string pattern
6422 + if (strPatBackRef->spbreLocalBackRefID == NO_LOCAL_BACK_REF_ID)
6424 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6425 + errInfo->eiBackRefNbr = globalId + 1;
6426 + errInfo->eiDetail = "not defined before";
6431 + * replace global backref ID by local one
6434 + *s = (char)((int)('0') + strPatBackRef->spbreLocalBackRefID);
6441 +** Replace global backref ID ("\n", n=1..9), located at given
6442 +** replaceStartPtr, by its definition (given by regExp parameter).
6443 +** Returns string pointer, where scan shall continue with
6445 +static char *replaceBackRefIdByRegExp(
6446 + StringPattern *strPat,
6447 + char *replaceStartPtr,
6450 + char *oldText = strPat->spText;
6453 + char *continueScanPtr;
6454 + int oldLen = strlen(oldText);
6455 + int regExpLen = strlen(regExp);
6456 + int replacePos = replaceStartPtr - oldText;
6457 + int remainingLen = oldLen-replacePos-2;
6460 + * replace "\n" - located at replaceStartPtr - by "(regExp)"
6462 + newText = XtMalloc(oldLen + regExpLen + 3);
6464 + memcpy(newText, oldText, replacePos);
6465 + n = newText + replacePos;
6467 + continueScanPtr = n;
6469 + memcpy(n, regExp, regExpLen);
6473 + memcpy(n, replaceStartPtr+2, remainingLen);
6474 + *(n + remainingLen) = '\0';
6478 + strPat->spText = newText;
6479 + strPat->spLength = strlen(newText);
6481 + return continueScanPtr;
6485 +** Convert global backref definition ("(*n", n=1..9), located at given
6486 +** convertPtr, by capturing parentheses "(".
6487 +** Returns string pointer, where scan shall continue with
6489 +static char *convertGlobalToLocalBackRef(
6490 + StringPattern *strPat,
6493 + char *oldText = strPat->spText;
6495 + int oldLen = strlen(oldText);
6496 + int convertPos = convertPtr - oldText;
6499 + * replace "(*n" - located at convertPtr - by "("
6501 + newText = XtMalloc(oldLen - 1);
6503 + memcpy(newText, oldText, convertPos+1);
6504 + memcpy(newText+convertPos+1, convertPtr+3, oldLen-convertPos-3);
6506 + *(newText + oldLen - 2) = '\0';
6510 + strPat->spText = newText;
6511 + strPat->spLength = strlen(newText);
6513 + return newText + convertPos;
6517 +** Read a match pattern table element from given input string.
6518 +** Return NULL, if read fails.
6520 +static MatchPatternTableElement *readMatchPatternTableElement(
6524 + MatchPatternType type)
6526 + int error = False;
6527 + PatternElement *pattern;
6528 + PatternElement *allPat[MAX_STRING_PATTERNS];
6531 + MatchPatternTableElement *result;
6532 + int isMonoPattern;
6533 + int skipBtwStartEnd;
6535 + int ignoreHighLightInfo;
6538 + if (!getMPSGlobalAttribute(
6544 + &ignoreHighLightInfo ))
6550 + * read all patterns
6552 + while (**inPtr != '\n' && !error)
6554 + if (!readPatternElement( inPtr, errMsg, &pattern ))
6558 + else if (nbrOfPat >= MAX_STRING_PATTERNS)
6560 + *errMsg = "max. number of string patterns exceeded";
6565 + pattern->peIndex = nbrOfPat;
6567 + allPat[nbrOfPat ++] = pattern;
6573 + for (i=0; i < nbrOfPat; i ++)
6574 + freePatternElement( allPat[i] );
6579 + if (nbrOfPat == 0)
6581 + *errMsg = "min. one string pattern needed";
6586 + * allocate & init. MatchPatternTableElement
6589 + (MatchPatternTableElement *)XtMalloc(sizeof(MatchPatternTableElement));
6591 + result->mpteName = name;
6592 + result->mpteIndex = NO_ELEMENT_IDX;
6593 + result->mpteType = type;
6594 + result->mpteGroup = NO_GROUP_IDX;
6596 + sizeOfPat = sizeof(PatternElement *) * nbrOfPat;
6597 + result->mpteAll.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6599 + memcpy(result->mpteAll.pesPattern, allPat, sizeOfPat);
6601 + result->mpteAll.pesNumberOfPattern = nbrOfPat;
6603 + result->mpteIsMonoPattern = isMonoPattern;
6604 + result->mpteSkipBtwnStartEnd = skipBtwStartEnd;
6605 + result->mpteFlash = flash;
6606 + result->mpteIgnoreHighLightInfo = ignoreHighLightInfo;
6608 + result->mpteStartEndRE = NULL;
6610 + initGlobalBackRefList( result->mpteGlobalBackRef );
6613 + * sort start / end / middle pattern
6615 + error = !sortReadPatternElementSet( &result->mpteAll, errMsg, result );
6619 + freeMatchPatternTableElement( result );
6629 + * Sort read pattern element set into start, middle & end arrays.
6630 + * Validate "monopattern" attribute.
6631 + * Returns true, if validation was successful.
6633 +static int sortReadPatternElementSet(
6634 + PatternElementSet *allPat,
6636 + MatchPatternTableElement *result)
6639 + int isMonoPattern = result->mpteIsMonoPattern;
6642 + * count number of start, middle & end pattern elements.
6644 + countPatternElementKind( allPat, result );
6647 + * validate and allocate pattern elements.
6649 + if (result->mpteStart.pesNumberOfPattern != 0)
6651 + sizeOfPat = sizeof(PatternElement *) * result->mpteStart.pesNumberOfPattern;
6652 + result->mpteStart.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6656 + *errMsg = "min. one start pattern needed";
6660 + if (isMonoPattern &&
6661 + (result->mpteMiddle.pesNumberOfPattern != 0 ||
6662 + result->mpteEnd.pesNumberOfPattern !=0))
6664 + *errMsg = "mono pattern: only start pattern(s) allowed due to attribute [m]";
6668 + if (result->mpteMiddle.pesNumberOfPattern != 0)
6670 + sizeOfPat = sizeof(PatternElement *) * result->mpteMiddle.pesNumberOfPattern;
6671 + result->mpteMiddle.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6674 + if (result->mpteEnd.pesNumberOfPattern != 0)
6676 + sizeOfPat = sizeof(PatternElement *) * result->mpteEnd.pesNumberOfPattern;
6677 + result->mpteEnd.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6681 + if (!isMonoPattern)
6683 + *errMsg = "min. one end pattern needed";
6689 + * sort pattern elements into start, middle & end arrays.
6691 + sortPatternElementSet( allPat, result );
6693 + if (isMonoPattern)
6695 + copyPatternSet( &result->mpteStart, &result->mpteEnd );
6702 + * Count number of start, middle & end patterns stored in "allPat".
6704 +static void countPatternElementKind(
6705 + PatternElementSet *allPat,
6706 + MatchPatternTableElement *result)
6710 + result->mpteStart.pesNumberOfPattern = 0;
6711 + result->mpteEnd.pesNumberOfPattern = 0;
6712 + result->mpteMiddle.pesNumberOfPattern = 0;
6714 + result->mpteStart.pesPattern = NULL;
6715 + result->mpteEnd.pesPattern = NULL;
6716 + result->mpteMiddle.pesPattern = NULL;
6718 + for (i=0; i < allPat->pesNumberOfPattern; i ++)
6720 + switch (allPat->pesPattern[i]->peKind)
6723 + result->mpteStart.pesNumberOfPattern ++;
6726 + result->mpteMiddle.pesNumberOfPattern ++;
6729 + result->mpteEnd.pesNumberOfPattern ++;
6737 + * Sort start, middle & end pattern elements into related arrays.
6739 +static void sortPatternElementSet(
6740 + PatternElementSet *allPat,
6741 + MatchPatternTableElement *result)
6746 + for (i=0, s=0, m=0, e=0; i < allPat->pesNumberOfPattern; i ++)
6748 + switch (allPat->pesPattern[i]->peKind)
6751 + result->mpteStart.pesPattern[s ++] = allPat->pesPattern[i];
6754 + result->mpteMiddle.pesPattern[m ++] = allPat->pesPattern[i];
6757 + result->mpteEnd.pesPattern[e ++] = allPat->pesPattern[i];
6764 +static void copyPatternSet(
6765 + PatternElementSet *sourcePS,
6766 + PatternElementSet *destPS)
6770 + destPS->pesNumberOfPattern = sourcePS->pesNumberOfPattern;
6772 + sizeOfPat = sizeof(PatternElement *) * destPS->pesNumberOfPattern;
6773 + destPS->pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6775 + memcpy(destPS->pesPattern, sourcePS->pesPattern, sizeOfPat);
6779 +** Free the allocated memory contained in a ReadMatchPatternInfo data structure
6781 +static void freeReadMatchPatternInfo( ReadMatchPatternInfo *readPatInfo )
6785 + for (i=0; i<readPatInfo->rmpiNbrOfElements; i++)
6786 + freeMatchPatternTableElement(readPatInfo->rmpiElement[i]);
6788 + for (i=0; i<readPatInfo->rmpiNbrOfGroups; i++)
6789 + freeMatchPatternGroupElement(readPatInfo->rmpiGroup[i]);
6791 + for (i=0; i<readPatInfo->rmpiNbrOfSeqElements; i++)
6792 + freeMatchPatternSequenceElement(readPatInfo->rmpiSequence[i]);
6794 + freePtr((void **)&readPatInfo->rmpiAllPatRE);
6796 + freePtr((void **)&readPatInfo->rmpiFlashPatRE);
6800 +** Free the allocated memory contained in a StringMatchTable data structure
6802 +static void freeStringMatchTable( StringMatchTable *table )
6804 + MatchPatternTable *patTable;
6807 + if (table == NULL)
6810 + XtFree(table->smtLanguageMode);
6813 + * Free all matching patterns
6815 + patTable = table->smtAllPatterns;
6817 + for (i=0; i<patTable->mptNumberOfElements; i++)
6818 + freeMatchPatternTableElement(patTable->mptElements[i]);
6820 + XtFree((char *)patTable);
6823 + * Free matching pattern group elements
6825 + for (i=0; i<table->smtNumberOfGroups; i++)
6826 + freeMatchPatternGroupElement(table->smtGroups[i]);
6829 + * Free matching pattern sequence elements
6831 + for (i=0; i<table->smtNumberOfSeqElements; i++)
6832 + freeMatchPatternSequenceElement(table->smtSequence[i]);
6835 + * Free keyword reg. expressions
6837 + freePtr((void **)&table->smtAllPatRE);
6839 + freePtr((void **)&table->smtFlashPatRE);
6841 + XtFree((char *)table);
6845 +** Free the allocated memory contained in a MatchPatternTableElement data structure
6847 +static void freeMatchPatternTableElement( MatchPatternTableElement *element )
6851 + XtFree(element->mpteName);
6853 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
6855 + freePatternElement(element->mpteAll.pesPattern[i]);
6858 + freePtr((void **)&element->mpteStartEndRE);
6860 + freeXtPtr((void **)&element->mpteStart.pesPattern);
6862 + freeXtPtr((void **)&element->mpteMiddle.pesPattern);
6864 + freeXtPtr((void **)&element->mpteEnd.pesPattern);
6866 + XtFree((char *)element);
6870 +** Free the allocated memory contained in a PatternElement data structure
6872 +static void freePatternElement( PatternElement *element )
6874 + if (element->peType == PET_SINGLE)
6875 + freeStringPattern( &(element->peVal.peuSingle) );
6876 + else if (element->peType == PET_MULTIPLE)
6878 + freeStringPattern( &(element->peVal.peuMulti.mpStringPattern) );
6879 + XtFree( (char *)element->peVal.peuMulti.mpRefList );
6882 + XtFree( (char *)element );
6886 +** Free the allocated memory contained in a StringPattern data structure
6888 +static void freeStringPattern( StringPattern *strPat )
6892 + freeXtPtr((void **)&strPat->spText);
6893 + freeXtPtr((void **)&strPat->spOrigText);
6895 + freePtr((void **)&strPat->spTextRE);
6897 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
6898 + freeXtPtr((void **)&strPat->spOwnGlobalBackRef[i].spbreRegExpText);
6902 +** Free the allocated memory contained in a MatchPatternGroupElement data structure
6904 +static void freeMatchPatternGroupElement( MatchPatternGroupElement *group )
6908 + freeXtPtr((void **)&group->mpgeName);
6910 + freePtr((void **)&group->mpgeKeywordRE);
6912 + if (group->mpgeSubPatternIds != NULL)
6914 + for (i=0; i < group->mpgeNumberOfSubPatterns; i++)
6916 + XtFree(group->mpgeSubPatternIds[i]);
6918 + XtFree((char *)group->mpgeSubPatternIds);
6921 + XtFree((char *)group);
6925 +** Free the allocated memory contained in a MatchPatternSequenceElement data structure
6927 +static void freeMatchPatternSequenceElement( MatchPatternSequenceElement *sequence )
6929 + XtFree( sequence->mpseName );
6931 + XtFree( (char *)sequence );
6936 +** Format a matching pattern set parse error.
6938 +static void parseMatchingPatternSetError(
6939 + const char *stringStart,
6940 + const char *stoppedAt,
6941 + ErrorInfo *errInfo)
6943 + char *message = "";
6945 + char *errorInForm = "matching pattern of \"%s\"";
6948 + if (errInfo->eiLanguageMode == NULL)
6950 + errorIn = "matching pattern";
6954 + errorIn = XtMalloc(strlen(errorInForm) + strlen(errInfo->eiLanguageMode)+1);
6955 + sprintf(errorIn, "matching pattern of \"%s\"", errInfo->eiLanguageMode);
6958 + if (errInfo->eiRegExpCompileMsg != NULL)
6961 + * Error message of form:
6962 + * "MP \"eiMPTabElementName\", SP \"eiStringPatText\": eiRegExpCompileMsg" or
6963 + * "MP \"eiMPTabElementName\" - eiDetail: eiRegExpCompileMsg"
6966 + msgLen = strlen(errInfo->eiRegExpCompileMsg) + 1;
6968 + if (errInfo->eiMPTabElementName != NULL)
6969 + msgLen += strlen(errInfo->eiMPTabElementName) + 10;
6971 + if (errInfo->eiDetail != NULL)
6973 + msgLen += strlen(errInfo->eiDetail + 2);
6977 + if (errInfo->eiStringPatText != NULL)
6978 + msgLen += strlen(errInfo->eiStringPatText) + 9;
6981 + message = XtMalloc(msgLen);
6983 + strcpy(message, "");
6985 + if (errInfo->eiMPTabElementName != NULL)
6986 + sprintf( message, "MP \"%s\"", errInfo->eiMPTabElementName);
6988 + if (errInfo->eiDetail == NULL)
6990 + if (errInfo->eiStringPatText != NULL)
6991 + sprintf( message, "%s, SP \"%s\"", message, errInfo->eiStringPatText);
6995 + if (strlen(message) != 0)
6996 + strcat(message, " - ");
6998 + strcat(message, errInfo->eiDetail);
7001 + if (strlen(message) != 0)
7002 + strcat(message, ": ");
7004 + strcat(message, errInfo->eiRegExpCompileMsg);
7006 + else if (errInfo->eiDetail != NULL)
7009 + * Error message of form:
7010 + * "MP \"eiMPTabElementName\", SP \"eiStringPatText\": Backref %d eiDetail
7012 + msgLen = strlen(errInfo->eiDetail) + 1;
7014 + if (errInfo->eiMPTabElementName != NULL)
7015 + msgLen += strlen(errInfo->eiMPTabElementName) + 7;
7016 + if (errInfo->eiStringPatText != NULL)
7017 + msgLen += strlen(errInfo->eiStringPatText) + 9;
7018 + if (errInfo->eiBackRefNbr != 0)
7021 + message = XtMalloc(msgLen);
7023 + strcpy(message, "");
7025 + if (errInfo->eiMPTabElementName != NULL)
7026 + sprintf( message, "MP \"%s\"", errInfo->eiMPTabElementName);
7027 + if (errInfo->eiStringPatText != NULL)
7028 + sprintf( message, "%s, SP \"%s\"", message, errInfo->eiStringPatText);
7030 + if (strlen(message) != 0)
7031 + strcat(message, ": ");
7033 + if (errInfo->eiBackRefNbr != 0)
7034 + sprintf( message, "%s Backref %d ", message, errInfo->eiBackRefNbr);
7036 + strcat(message, errInfo->eiDetail);
7039 + ParseError(NULL, stringStart, stoppedAt, errorIn, message);
7041 + if (errInfo->eiRegExpCompileMsg != NULL || errInfo->eiDetail != NULL)
7046 + if (errInfo->eiLanguageMode != NULL)
7051 + freeErrorInfo(errInfo);
7052 + initErrorInfo(errInfo);
7056 + * Pop-up a warning dialog showing a matching pattern set error.
7058 +static void dialogMatchingPatternSetError(
7060 + ErrorInfo *errInfo)
7066 + * Error message of form:
7067 + * "Name : \"eiMPTabElementName\"\n
7068 + * "String: \"eiStringPatText\"\n
7070 + * eiRegExpCompileMsg\n"
7073 + if (errInfo->eiMPTabElementName != NULL)
7074 + msgLen += strlen(errInfo->eiMPTabElementName) + 15;
7075 + if (errInfo->eiStringPatText != NULL)
7076 + msgLen += strlen(errInfo->eiStringPatText) + 15;
7077 + if (errInfo->eiDetail != NULL)
7078 + msgLen += strlen(errInfo->eiDetail) + 15;
7079 + if (errInfo->eiBackRefNbr != 0)
7081 + if (errInfo->eiRegExpCompileMsg != NULL)
7082 + msgLen += strlen(errInfo->eiRegExpCompileMsg) + 15;
7084 + message = XtMalloc(msgLen);
7086 + strcpy(message, "");
7088 + if (errInfo->eiMPTabElementName != NULL)
7089 + sprintf( message, "%sName : \"%s\"\n", message, errInfo->eiMPTabElementName);
7090 + if (errInfo->eiStringPatText != NULL)
7091 + sprintf( message, "%sPattern: \"%s\"\n", message, errInfo->eiStringPatText);
7092 + if (errInfo->eiBackRefNbr != 0)
7093 + sprintf( message, "%sBackref %d ", message, errInfo->eiBackRefNbr);
7094 + if (errInfo->eiDetail != NULL)
7095 + sprintf( message, "%s%s\n", message, errInfo->eiDetail);
7096 + if (errInfo->eiRegExpCompileMsg != NULL)
7097 + sprintf( message, "%s%s\n", message, errInfo->eiRegExpCompileMsg);
7100 + DF_WARN, MatchPatternDialog.mpdShell, 1,
7102 + "%s(language mode '%s')",
7105 + errInfo->eiLanguageMode);
7109 + freeErrorInfo(errInfo);
7110 + initErrorInfo(errInfo);
7114 +** Get matching pattern set name.
7116 +** patternName ::= "name:"
7117 +** Returns true, if get was successful.
7119 +static int getMPSName(
7121 + ErrorInfo *errInfo,
7125 + char *field = ReadSymbolicField(inPtr);
7127 + if (field == NULL)
7129 + errInfo->eiDetail = "matching pattern name missing";
7133 + if (!SkipDelimiter(inPtr, &dummy))
7135 + errInfo->eiMPTabElementName = XtNewString(field);
7136 + errInfo->eiDetail = "':' missing after matching pattern name";
7147 +** Get matching pattern set type attribute.
7148 +** TypeAttribute ::=
7151 +** s : sub-pattern (pattern is only matched, if part of a pattern group).
7152 +** g : pattern (context) group (i.e. a sequence of sub-patterns).
7153 +** default: individual pattern (pattern is not part of a group and is
7154 +** matched individually.
7155 +** Returns true, if get was successful.
7157 +static int getMPSTypeAttribute(
7159 + ErrorInfo *errInfo,
7160 + MatchPatternType *type)
7162 + char *field = ReadSymbolicField(inPtr);
7163 + int successful = True;
7165 + *type = MPT_INDIVIDUAL;
7167 + if (field != NULL)
7172 + *type = MPT_GROUP;
7178 + errInfo->eiDetail = "unknown matching pattern type attribute";
7179 + successful = False;
7185 + if (!SkipDelimiter(inPtr, &errInfo->eiDetail))
7187 + successful = False;
7191 + freeXtPtr((void **)&field);
7193 + return successful;
7199 +** GlobalAttribute ::=
7200 +** [c][f][m][p][u]:
7202 +** c : the content between start and end pattern is skipped
7203 +** during parsing (e.g. pattern encloses a comment).
7204 +** f : flash matching pattern (if not set, then only jump
7205 +** to matching pattern is supported).
7206 +** m : mono pattern - set exist out of only one single pattern
7207 +** (start pattern = end pattern; e.g. quotes like ")
7208 +** p : ignore highlight info code of single patterns of this set
7211 +** Returns TRUE, if global attribute was successful read.
7213 +static int getMPSGlobalAttribute(
7216 + int *isMonoPattern,
7219 + int *ignoreHighLightInfo)
7221 + char *field = ReadSymbolicField(inPtr);
7223 + int successful = True;
7225 + *isMonoPattern = False;
7228 + *ignoreHighLightInfo = False;
7230 + if (field != NULL)
7232 + attribute = field;
7233 + while (*attribute != '\0' && successful)
7235 + switch (*attribute)
7244 + *isMonoPattern = True;
7247 + *ignoreHighLightInfo = True;
7250 + *errMsg = "unknown global attribute";
7251 + successful = False;
7259 + if (!SkipDelimiter(inPtr, errMsg))
7261 + successful = False;
7265 + freeXtPtr((void **)&field);
7267 + return successful;
7271 +** Get matching pattern set attribute.
7275 +** patternAttribute ::=
7276 +** [s|m|e][w|l|r][i]:
7278 +** StringPatternKind:
7279 +** s : start string pattern.
7280 +** m : middle string pattern.
7281 +** e : end string pattern.
7282 +** WordBoundaryAttribute:
7283 +** w : pattern is word (i.e. before and after pattern
7284 +** there must be a delimiter).
7285 +** l : before pattern must be a delimiter (left side).
7286 +** r : after pattern must be a delimiter (right side).
7287 +** default: neither before nor after pattern must be a delimiter.
7288 +** StringAttribute:
7289 +** i : pattern is case insensitive (if not set: pattern is
7290 +** case sensitive).
7291 +** x : pattern is regular expression (if not set: pattern is
7292 +** literal string).
7294 +** Returns TRUE, if pattern attribute was successful read.
7296 +static int getMPSPatternAttribute(
7299 + PatternElementKind *patternKind,
7300 + PatternWordBoundary *wordBoundary,
7301 + int *caseInsensitive,
7302 + int *regularExpression)
7304 + char *field = ReadSymbolicField(inPtr);
7306 + int successful = True;
7308 + *patternKind = PEK_UNKNOWN;
7309 + *wordBoundary = PWB_NONE;
7310 + *caseInsensitive = False;
7311 + *regularExpression = False;
7313 + if (field != NULL)
7315 + attribute = field;
7316 + while (*attribute != '\0' && successful)
7318 + switch (*attribute)
7321 + *patternKind = PEK_END;
7324 + *caseInsensitive = True;
7327 + *wordBoundary = PWB_LEFT;
7330 + *patternKind = PEK_MIDDLE;
7333 + *wordBoundary = PWB_RIGHT;
7336 + *patternKind = PEK_START;
7339 + *wordBoundary = PWB_BOTH;
7342 + *regularExpression = True;
7345 + *errMsg = "unknown string pattern attribute";
7346 + successful = False;
7354 + if (!SkipDelimiter(inPtr, errMsg))
7356 + successful = False;
7360 + freeXtPtr((void **)&field);
7362 + return successful;
7366 +** Returns the (to be reserved) reg. ex. length of an pattern element.
7367 +** Update total number of multi patterns, too.
7369 +static int patternElementLen(
7370 + ReadMatchPatternInfo *info,
7371 + PatternElement *patElement,
7372 + int *nbrOfMultiPatterns)
7374 + PatternElement *referredElement;
7375 + StringPattern *strPat = NULL;
7376 + int patElementLen;
7378 + switch (patElement->peType)
7381 + strPat = &patElement->peVal.peuSingle;
7384 + case PET_MULTIPLE:
7385 + strPat = &patElement->peVal.peuMulti.mpStringPattern;
7387 + (*nbrOfMultiPatterns) ++;
7391 + case PET_REFERENCE:
7393 + info->rmpiElement[patElement->peVal.peuRef.prElementIdx]->
7394 + mpteAll.pesPattern[patElement->peVal.peuRef.prPatternIdx];
7396 + strPat = &referredElement->peVal.peuMulti.mpStringPattern;
7401 + * reserve additional 4 characters ("(?i)") for case insensitive search
7403 + if (strPat->spCaseInsensitive)
7404 + patElementLen = strPat->spLength + 4;
7406 + patElementLen = strPat->spLength;
7409 + * reserve additional 4 characters ("(?:)") for regular expression
7411 + if (strPat->spRegularExpression)
7412 + patElementLen += 4;
7414 + return patElementLen;
7418 +** Returns the (to be reserved) total reg. ex. length of given
7419 +** MatchPatternTableElement. Update total number of multi patterns, too.
7421 +static int totalMatchPatternTableElementLen(
7422 + ReadMatchPatternInfo *info,
7423 + MatchPatternTableElement *element,
7424 + int *nbrOfMultiPatterns)
7429 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
7432 + patternElementLen(
7434 + element->mpteAll.pesPattern[i],
7435 + nbrOfMultiPatterns );
7442 +** Returns the (to be reserved) total reg. ex. length of given
7443 +** read match pattern info. Counts total number of multi patterns, too.
7445 +static int totalKeywordOfTableLen(
7446 + ReadMatchPatternInfo *info,
7447 + int *nbrOfMultiPatterns)
7452 + *nbrOfMultiPatterns = 0;
7454 + for (i=0; i<info->rmpiNbrOfElements; i ++)
7457 + totalMatchPatternTableElementLen(
7459 + info->rmpiElement[i],
7460 + nbrOfMultiPatterns);
7467 +** Add given StringPattern to given reg. ex. strings
7469 +static void addPatternToRegExpString(
7470 + StringPattern *pattern,
7471 + RegExpStringInfo *regExpStringInfo)
7473 + char *r = NULL, *s;
7474 + char *adaptedRegExpText = NULL;
7478 + * Select the buffer, where the pattern needs to be added
7479 + * to (depending on its word boundary). Prepare the buffer
7480 + * by evtl. adding a prefix, if related buffer is empty.
7482 + switch (pattern->spWordBoundary)
7485 + prevLen = strlen( regExpStringInfo->resiNoneWBRegExpString );
7487 + r = regExpStringInfo->resiNoneWBRegExpString + strlen( regExpStringInfo->resiNoneWBRegExpString );
7490 + prevLen = strlen( regExpStringInfo->resiLeftWBRegExpString );
7493 + strcpy( regExpStringInfo->resiLeftWBRegExpString, "<(?:" );
7495 + r = regExpStringInfo->resiLeftWBRegExpString + strlen( regExpStringInfo->resiLeftWBRegExpString );
7498 + prevLen = strlen( regExpStringInfo->resiRightWBRegExpString );
7501 + strcpy( regExpStringInfo->resiRightWBRegExpString, "(?:" );
7503 + r = regExpStringInfo->resiRightWBRegExpString + strlen( regExpStringInfo->resiRightWBRegExpString );
7506 + prevLen = strlen( regExpStringInfo->resiBothWBRegExpString );
7509 + strcpy( regExpStringInfo->resiBothWBRegExpString, "<(?:" );
7511 + r = regExpStringInfo->resiBothWBRegExpString + strlen( regExpStringInfo->resiBothWBRegExpString );
7516 + * add an "or" if there is already a pattern in the buffer
7524 + * add "(?i" to order case insensitive search
7526 + if (pattern->spCaseInsensitive)
7534 + * add "(?:" to group this regular expression
7536 + if (pattern->spRegularExpression)
7542 + adaptedRegExpText =
7543 + adaptLocalBackRefs(
7545 + ®ExpStringInfo->resiLocalBackRefID);
7547 + s = adaptedRegExpText;
7551 + s = pattern->spText;
7555 + * add the pattern characters - evtl. escaped, if special
7556 + * regular expression symbols & pattern is no reg. exp. -
7560 + while (*s != '\0')
7562 + if (!pattern->spRegularExpression)
7593 + * close "reg. exp. group" bracket
7595 + if (pattern->spRegularExpression)
7599 + XtFree(adaptedRegExpText);
7603 + * close case insensitive search bracket
7605 + if (pattern->spCaseInsensitive)
7611 + * terminate added string
7617 +** Adapt local backrefs inside given regExpText by common local IDs.
7618 +** Returns new allocated reg. exp. string holding common local backrefs.
7620 +static char *adaptLocalBackRefs(
7622 + int *commonLocalId)
7625 + int ownLocalId = 0;
7626 + char *s = regExpText;
7627 + char *newRegExpText = XtMalloc(strlen(regExpText)*3);
7628 + char *n = newRegExpText;
7629 + int localBackRefList[MAX_LOCAL_BACK_REF_ID];
7632 + * put all local backrefs into "localBackRefList".
7634 + scanForLocalBackRefs(regExpText, localBackRefList);
7636 + while (*s != '\0')
7644 + if (isdigit((unsigned char)*s))
7647 + * \n (n=1..9) found: replace local backref.
7648 + * by "common local ID"
7651 + (int)((unsigned char)*s - (unsigned char)'0') - 1;
7653 + if (localBackRefList[id] != NO_LOCAL_BACK_REF_ID &&
7654 + localBackRefList[id] != LOCAL_BACK_REF_ID_USED)
7656 + *n++ = (char)((int)('0') + localBackRefList[id]);
7665 + else if (*s != '\0')
7668 + * copy escaped character
7673 + else if (*s == '(')
7680 + * non capturing parentheses found -> just copy it
7687 + * capturing parentheses found:
7689 + if (localBackRefList[ownLocalId] == LOCAL_BACK_REF_ID_USED)
7692 + * backref used within given reg. exp. text:
7693 + * remember common local id for replacement later on
7695 + localBackRefList[ownLocalId] = *commonLocalId;
7696 + (*commonLocalId) ++;
7702 + * backref not used within given reg. exp. text:
7703 + * replace capturing parentheses by non capturing one
7717 + * terminate adapted string
7721 + return newRegExpText;
7725 +** Get all local backrefs of given regExpText and put them into
7726 +** given localBackRefList.
7728 +static void scanForLocalBackRefs(
7730 + int *localBackRefList)
7734 + char *s = regExpText;
7736 + for (i=0; i<MAX_LOCAL_BACK_REF_ID; i++)
7738 + localBackRefList[i] = NO_LOCAL_BACK_REF_ID;
7741 + while (*s != '\0')
7745 + if (isdigit((unsigned char)*(s+1)))
7748 + * \n (n=1..9) found: flag usage in local backref list
7751 + (int)((unsigned char)*(s+1) - (unsigned char)'0') - 1;
7753 + localBackRefList[localId] = LOCAL_BACK_REF_ID_USED;
7757 + else if (*(s+1) != '\0')
7765 +** Returns true, if string of given multi pattern reference was
7766 +** not added to regExpStringInfo.
7768 +static int isMultiPatternNotAdded(
7769 + RegExpStringInfo *regExpStringInfo,
7770 + PatternReference *toBeAddedPR)
7773 + PatternReference *addedPR;
7774 + PatternReference *newPR;
7776 + for (i=0; i < regExpStringInfo->resiNbrOfAddedMultiPat; i++)
7778 + addedPR = regExpStringInfo->resiAddedMultiPat[i];
7780 + if (addedPR->prElementIdx == toBeAddedPR->prElementIdx &&
7781 + addedPR->prPatternIdx == toBeAddedPR->prPatternIdx)
7787 + newPR = (PatternReference *)XtMalloc(sizeof(PatternReference));
7789 + *newPR = *toBeAddedPR;
7791 + regExpStringInfo->resiAddedMultiPat[regExpStringInfo->resiNbrOfAddedMultiPat ++] = newPR;
7797 +** add given PatternElement to given reg. exp. strings
7799 +static void addUniquePatternToRegExpString(
7800 + PatternElement *patElement,
7801 + PatternReference *patElementReference,
7802 + ReadMatchPatternInfo *readMatchPatternInfo,
7803 + RegExpStringInfo *regExpStringInfo)
7805 + PatternElement *referredElement;
7806 + PatternReference referredPatReference;
7808 + switch (patElement->peType)
7811 + addPatternToRegExpString(
7812 + &(patElement->peVal.peuSingle),
7813 + regExpStringInfo);
7816 + case PET_MULTIPLE:
7818 + * add element to reg. exp. string only, if it was
7819 + * not added before.
7821 + if (isMultiPatternNotAdded(regExpStringInfo, patElementReference))
7823 + addPatternToRegExpString(
7824 + &(patElement->peVal.peuMulti.mpStringPattern),
7825 + regExpStringInfo);
7829 + case PET_REFERENCE:
7831 + * add referred element to reg. exp. string only, if related
7832 + * multi pattern was not added before.
7834 + referredPatReference = patElement->peVal.peuRef;
7837 + readMatchPatternInfo->rmpiElement[referredPatReference.prElementIdx]->
7838 + mpteAll.pesPattern[referredPatReference.prPatternIdx];
7840 + if (isMultiPatternNotAdded(regExpStringInfo, &referredPatReference))
7842 + addPatternToRegExpString(
7843 + &(referredElement->peVal.peuMulti.mpStringPattern),
7844 + regExpStringInfo);
7851 +** add given MatchPatternTableElement to given reg. ex. strings
7853 +static void addElementToRegExpString(
7854 + MatchPatternTableElement *element,
7855 + ReadMatchPatternInfo *readMatchPatternInfo,
7856 + RegExpStringInfo *regExpStringInfo)
7859 + PatternReference elementRef;
7861 + elementRef.prElementIdx = element->mpteIndex;
7863 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
7865 + elementRef.prPatternIdx = i;
7867 + addUniquePatternToRegExpString(
7868 + element->mpteAll.pesPattern[i],
7870 + readMatchPatternInfo,
7871 + regExpStringInfo);
7876 +** Concatenate strings stored by regExpStringInfo.
7877 +** Free given regExpStringInfo afterwards.
7878 +** Returns resulting string.
7880 +static void catSMTRegExpStrings(
7881 + RegExpStringInfo *regExpStringInfo,
7882 + char **regExpString)
7887 + * allocate & init. a buffer for the resulting regular expression
7890 + strlen( regExpStringInfo->resiNoneWBRegExpString ) +
7891 + strlen( regExpStringInfo->resiLeftWBRegExpString ) +
7892 + strlen( regExpStringInfo->resiRightWBRegExpString ) +
7893 + strlen( regExpStringInfo->resiBothWBRegExpString ) + 5;
7895 + *regExpString = XtMalloc( resultingLen );
7897 + strcpy( *regExpString, "" );
7900 + * add the single parts to the resulting regular expression
7901 + * (= cat of parts separated by an "or")
7903 + addSMTRegExpString( *regExpString, regExpStringInfo->resiNoneWBRegExpString, "" );
7904 + addSMTRegExpString( *regExpString, regExpStringInfo->resiLeftWBRegExpString, ")" );
7905 + addSMTRegExpString( *regExpString, regExpStringInfo->resiRightWBRegExpString, ")>" );
7906 + addSMTRegExpString( *regExpString, regExpStringInfo->resiBothWBRegExpString, ")>" );
7911 + freeRegExpStringInfo( regExpStringInfo );
7915 +** Free the allocated memory contained in a RegExpStringInfo data structure
7917 +static void freeRegExpStringInfo(
7918 + RegExpStringInfo *regExpStringInfo)
7922 + XtFree( regExpStringInfo->resiNoneWBRegExpString );
7923 + XtFree( regExpStringInfo->resiLeftWBRegExpString );
7924 + XtFree( regExpStringInfo->resiRightWBRegExpString );
7925 + XtFree( regExpStringInfo->resiBothWBRegExpString );
7927 + for (i=0; i < regExpStringInfo->resiNbrOfAddedMultiPat; i ++)
7928 + XtFree( (char *)regExpStringInfo->resiAddedMultiPat[i] );
7930 + XtFree( (char *)regExpStringInfo->resiAddedMultiPat);
7934 +** Compose regular expression for start / end pattern.
7936 +static void composeStartEndRegExpString(
7937 + ReadMatchPatternInfo *readMatchPatternInfo,
7938 + MatchPatternTableElement *element,
7939 + char **regExpString)
7942 + RegExpStringInfo regExpStringInfo;
7943 + PatternReference elementRef;
7944 + PatternElementSet startPat = element->mpteStart;
7945 + PatternElementSet endPat = element->mpteEnd;
7948 + * Allocate buffers for keyword regular expression.
7950 + setupRegExpStringBuffers(
7951 + readMatchPatternInfo,
7952 + ®ExpStringInfo);
7955 + * Treat start / end element of MatchPatternTableElement
7958 + elementRef.prElementIdx = element->mpteIndex;
7960 + for (i=0; i < startPat.pesNumberOfPattern; i ++)
7962 + elementRef.prPatternIdx = startPat.pesPattern[i]->peIndex;
7964 + addUniquePatternToRegExpString(
7965 + startPat.pesPattern[i],
7967 + readMatchPatternInfo,
7968 + ®ExpStringInfo);
7971 + for (i=0; i < endPat.pesNumberOfPattern; i ++)
7973 + elementRef.prPatternIdx = endPat.pesPattern[i]->peIndex;
7975 + addUniquePatternToRegExpString(
7976 + endPat.pesPattern[i],
7978 + readMatchPatternInfo,
7979 + ®ExpStringInfo);
7983 + * Assemble the resulting regular expression
7985 + catSMTRegExpStrings(
7986 + ®ExpStringInfo,
7990 +static void copyStringMatchTableForDialog(
7991 + StringMatchTable *sourceTable,
7992 + DialogMatchPatternInfo *dialogTable )
7997 + * if no source table exist (yet), then set nbr. of elements / groups to 0
7999 + if (sourceTable == NULL)
8001 + dialogTable->dmpiNbrOfSeqElements = 0;
8007 + * copy matching pattern sequence
8009 + dialogTable->dmpiNbrOfSeqElements = sourceTable->smtNumberOfSeqElements;
8011 + for (i=0; i < sourceTable->smtNumberOfSeqElements; i ++)
8013 + copySequenceElementForDialog(
8015 + sourceTable->smtSequence[i],
8016 + &dialogTable->dmpiSequence[i] );
8020 +static void *copyMatchPatternElementForDialog(
8021 + MatchPatternTable *table,
8022 + int sourceElementIdx)
8026 + MatchPatternTableElement *sourceElement;
8027 + DialogMatchPatternTableElement *destination;
8029 + sourceElement = table->mptElements[sourceElementIdx];
8032 + (DialogMatchPatternTableElement *)XtMalloc( sizeof(DialogMatchPatternTableElement) );
8034 + destination->dmpteName = XtNewString(sourceElement->mpteName);
8035 + destination->dmpteType = sourceElement->mpteType;
8036 + destination->dmpteSkipBtwnStartEnd = sourceElement->mpteSkipBtwnStartEnd;
8037 + destination->dmpteIgnoreHighLightInfo = sourceElement->mpteIgnoreHighLightInfo;
8038 + destination->dmpteFlash = sourceElement->mpteFlash;
8040 + for (i=0; i<sourceElement->mpteAll.pesNumberOfPattern; i++)
8042 + copyPatternForDialog(
8044 + sourceElement->mpteAll.pesPattern[i],
8045 + &destination->dmptePatterns.dspElements[patIdx ++]);
8048 + destination->dmptePatterns.dspNumberOfPatterns = patIdx;
8050 + return (void *)destination;
8053 +static void copyPatternForDialog(
8054 + MatchPatternTable *table,
8055 + PatternElement *sourcePattern,
8056 + DialogStringPatternElement **dialogPattern )
8058 + DialogStringPatternElement *newPat;
8059 + StringPattern *strSourcePat = GetStringPattern( table, sourcePattern );
8061 + newPat = (DialogStringPatternElement *)XtMalloc(sizeof(DialogStringPatternElement));
8062 + *dialogPattern = newPat;
8064 + if( strSourcePat->spOrigText != NULL)
8065 + newPat->dspeText = XtNewString(strSourcePat->spOrigText);
8067 + newPat->dspeText = XtNewString(strSourcePat->spText);
8069 + newPat->dspeKind = sourcePattern->peKind;
8070 + newPat->dspeWordBoundary = strSourcePat->spWordBoundary;
8071 + newPat->dspeCaseInsensitive = strSourcePat->spCaseInsensitive;
8072 + newPat->dspeRegularExpression = strSourcePat->spRegularExpression;
8075 +static void *copyGroupElementForDialog(
8076 + MatchPatternGroupElement *sourceGroup)
8079 + DialogMatchPatternGroupElement *destination;
8082 + (DialogMatchPatternGroupElement *)XtMalloc( sizeof(DialogMatchPatternGroupElement) );
8084 + destination->dmpgeName = XtNewString(sourceGroup->mpgeName);
8085 + destination->dmpgeNumberOfSubPatterns = sourceGroup->mpgeNumberOfSubPatterns;
8087 + for ( i=0; i<destination->dmpgeNumberOfSubPatterns; i ++)
8089 + destination->dmpgeSubPatternIds[i] =
8090 + XtNewString(sourceGroup->mpgeSubPatternIds[i]);
8093 + return destination;
8096 +static void copySequenceElementForDialog(
8097 + StringMatchTable *sourceTable,
8098 + MatchPatternSequenceElement *sourceSeqElement,
8099 + DialogMatchPatternSequenceElement **dialogSeqElement )
8101 + DialogMatchPatternSequenceElement *destSeqElement;
8104 + (DialogMatchPatternSequenceElement *)XtMalloc( sizeof(DialogMatchPatternSequenceElement) );
8106 + *dialogSeqElement = destSeqElement;
8108 + destSeqElement->dmpseName = XtNewString(sourceSeqElement->mpseName);
8109 + destSeqElement->dmpseType = sourceSeqElement->mpseType;
8110 + destSeqElement->dmpseValid = True;
8112 + if (destSeqElement->dmpseType == MPT_GROUP)
8114 + destSeqElement->dmpsePtr =
8115 + copyGroupElementForDialog(
8116 + sourceTable->smtGroups[sourceSeqElement->mpseIndex]);
8120 + destSeqElement->dmpsePtr =
8121 + copyMatchPatternElementForDialog(
8122 + sourceTable->smtAllPatterns,
8123 + sourceSeqElement->mpseIndex);
8127 +static DialogMatchPatternSequenceElement *copyDialogSequenceElement(
8128 + DialogMatchPatternSequenceElement *sourceSeq)
8130 + DialogMatchPatternSequenceElement *destSeq;
8133 + (DialogMatchPatternSequenceElement *)XtMalloc(sizeof(DialogMatchPatternSequenceElement));
8135 + destSeq->dmpseName = XtNewString(sourceSeq->dmpseName);
8136 + destSeq->dmpseType = sourceSeq->dmpseType;
8137 + destSeq->dmpseValid = True;
8139 + destSeq->dmpsePtr = sourceSeq->dmpsePtr;
8144 +static void freeDialogMatchPatternElement(
8145 + DialogMatchPatternTableElement *dialogElement )
8149 + for (i=0; i<dialogElement->dmptePatterns.dspNumberOfPatterns; i ++)
8151 + freeDialogStringPatternElement(
8152 + dialogElement->dmptePatterns.dspElements[i]);
8155 + freeXtPtr((void **)&dialogElement->dmpteName);
8157 + freeXtPtr((void **)&dialogElement);
8160 +static void freeDialogStringPatternElement(
8161 + DialogStringPatternElement *element)
8163 + freeXtPtr((void **)&element->dspeText);
8165 + freeXtPtr((void **)&element);
8168 +static void freeDialogGroupElement(
8169 + DialogMatchPatternGroupElement *dialogGroup )
8173 + for (i=0; i<dialogGroup->dmpgeNumberOfSubPatterns; i ++)
8175 + freeXtPtr((void **)&dialogGroup->dmpgeSubPatternIds[i]);
8178 + freeXtPtr((void **)&dialogGroup->dmpgeName);
8180 + freeXtPtr((void **)&dialogGroup);
8183 +static void freeDialogSequenceElement(
8184 + DialogMatchPatternSequenceElement *dialogSeq )
8186 + freeXtPtr((void **)&dialogSeq->dmpseName);
8188 + if (dialogSeq->dmpseType == MPT_GROUP)
8190 + freeDialogGroupElement(
8191 + (DialogMatchPatternGroupElement *)dialogSeq->dmpsePtr );
8195 + freeDialogMatchPatternElement(
8196 + (DialogMatchPatternTableElement *)dialogSeq->dmpsePtr );
8199 + freeXtPtr((void **)&dialogSeq);
8202 +static void copyDialogStringPatternsFromTable(
8203 + DialogMatchPatternTableElement *tableElement,
8204 + DialogStringPatterns *destPatterns)
8208 + destPatterns->dspNumberOfPatterns =
8209 + tableElement->dmptePatterns.dspNumberOfPatterns;
8211 + for (i=0; i<destPatterns->dspNumberOfPatterns; i++)
8213 + destPatterns->dspElements[i] =
8214 + copyDialogStringPatternElement(
8215 + tableElement->dmptePatterns.dspElements[i] );
8219 +static void copyDialogStringPatterns(
8220 + DialogStringPatterns *sourcePatterns,
8221 + DialogStringPatterns *destPatterns)
8225 + destPatterns->dspNumberOfPatterns =
8226 + sourcePatterns->dspNumberOfPatterns;
8228 + for (i=0; i<destPatterns->dspNumberOfPatterns; i++)
8230 + destPatterns->dspElements[i] =
8231 + copyDialogStringPatternElement(
8232 + sourcePatterns->dspElements[i] );
8236 +static void freeDialogStringPatterns(
8237 + DialogStringPatterns *patterns)
8241 + for (i=0; i<patterns->dspNumberOfPatterns; i++)
8243 + freeDialogStringPatternElement(patterns->dspElements[i]);
8246 + patterns->dspNumberOfPatterns = 0;
8249 +static DialogStringPatternElement *copyDialogStringPatternElement(
8250 + DialogStringPatternElement *sourceElement)
8252 + DialogStringPatternElement *newPatElement;
8254 + newPatElement = (DialogStringPatternElement *)XtMalloc(sizeof(DialogStringPatternElement));
8256 + newPatElement->dspeText = XtNewString(sourceElement->dspeText);
8257 + newPatElement->dspeKind = sourceElement->dspeKind;
8258 + newPatElement->dspeWordBoundary = sourceElement->dspeWordBoundary;
8259 + newPatElement->dspeCaseInsensitive = sourceElement->dspeCaseInsensitive;
8260 + newPatElement->dspeRegularExpression = sourceElement->dspeRegularExpression;
8262 + return newPatElement;
8265 +static void copyDialogPatternNamesFromGroup(
8266 + DialogMatchPatternGroupElement *group,
8267 + DialogStringPatterns *destPatterns)
8271 + destPatterns->dspNumberOfPatterns =
8272 + group->dmpgeNumberOfSubPatterns;
8274 + for (i=0; i<destPatterns->dspNumberOfPatterns; i++)
8276 + destPatterns->dspElements[i] =
8277 + copyDialogPatternName(
8278 + group->dmpgeSubPatternIds[i] );
8282 +static DialogStringPatternElement *copyDialogPatternName(
8283 + char *sourcePatternId)
8285 + DialogStringPatternElement *newPatElement;
8287 + newPatElement = (DialogStringPatternElement *)XtMalloc(sizeof(DialogStringPatternElement));
8289 + newPatElement->dspeText = XtNewString(sourcePatternId);
8290 + newPatElement->dspeKind = PEK_START;
8291 + newPatElement->dspeWordBoundary = PWB_NONE;
8292 + newPatElement->dspeCaseInsensitive = False;
8293 + newPatElement->dspeRegularExpression = False;
8295 + return newPatElement;
8298 +static void copyDialogPatternNamesToGroup(
8299 + DialogStringPatterns *sourceNames,
8300 + DialogMatchPatternGroupElement *destGroup)
8304 + destGroup->dmpgeNumberOfSubPatterns =
8305 + sourceNames->dspNumberOfPatterns;
8307 + for (i=0; i<destGroup->dmpgeNumberOfSubPatterns; i++)
8309 + destGroup->dmpgeSubPatternIds[i] =
8311 + sourceNames->dspElements[i]->dspeText);
8317 +** Present a dialog for editing matching pattern information
8319 +void EditMatchPatterns(WindowInfo *window)
8321 + Widget form, lmOptMenu;
8323 + Widget okBtn, applyBtn, checkBtn, deleteBtn, closeBtn, helpBtn;
8324 + Widget restoreBtn, lmBtn;
8325 + Widget matchPatternsForm, matchPatternsFrame, matchPatternsLbl;
8326 + Widget matchPatternTypeBox, matchPatternTypeLbl;
8327 + Widget globalAttributesBox;
8328 + Widget stringPatternsFrame, stringPatternsForm;
8329 + Widget stringPatternTypeBox;
8330 + Widget wordBoundaryBox;
8331 + Widget stringAttributesBox;
8332 + StringMatchTable *table;
8338 + * if the dialog is already displayed, just pop it to the top and return
8340 + if (MatchPatternDialog.mpdShell != NULL)
8342 + RaiseDialogWindow(MatchPatternDialog.mpdShell);
8347 + * decide on an initial language mode
8349 + MatchPatternDialog.mpdLangModeName =
8351 + window->languageMode == PLAIN_LANGUAGE_MODE ?
8352 + PLAIN_LM_STRING : LanguageModeName(window->languageMode));
8355 + * find the associated matching pattern table to edit
8357 + table = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
8360 + * copy the list of patterns to one that the user can freely edit
8362 + copyStringMatchTableForDialog( table, &MatchPatternDialog.mpdTable );
8365 + * init. status information of dialog
8367 + MatchPatternDialog.currentDmptSeqElement = NULL;
8368 + MatchPatternDialog.currentDmptElement = NULL;
8369 + MatchPatternDialog.currentDmptGroup = NULL;
8371 + MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns = 0;
8372 + MatchPatternDialog.mpdStringPatternIsDisplayed = True;
8375 + * Create a form widget in an application shell
8378 + XtSetArg(args[n], XmNdeleteResponse, XmDO_NOTHING); n++;
8379 + XtSetArg(args[n], XmNiconName, "Matching Patterns"); n++;
8380 + XtSetArg(args[n], XmNtitle, "Matching (Parenthesis) Patterns"); n++;
8381 + MatchPatternDialog.mpdShell = CreateShellWithBestVis(APP_NAME, APP_CLASS,
8382 + applicationShellWidgetClass, TheDisplay, args, n);
8383 + AddSmallIcon(MatchPatternDialog.mpdShell);
8384 + form = XtVaCreateManagedWidget("editMatchPatterns", xmFormWidgetClass,
8385 + MatchPatternDialog.mpdShell, XmNautoUnmanage, False,
8386 + XmNresizePolicy, XmRESIZE_NONE, NULL);
8387 + XtAddCallback(form, XmNdestroyCallback, destroyCB, NULL);
8388 + AddMotifCloseCallback(MatchPatternDialog.mpdShell, closeCB, NULL);
8390 + lmForm = XtVaCreateManagedWidget("lmForm", xmFormWidgetClass,
8392 + XmNleftAttachment, XmATTACH_POSITION,
8393 + XmNleftPosition, 1,
8394 + XmNtopAttachment, XmATTACH_POSITION,
8395 + XmNtopPosition, 1,
8396 + XmNrightAttachment, XmATTACH_POSITION,
8397 + XmNrightPosition, 99, NULL);
8399 + MatchPatternDialog.mpdLmPulldown =
8400 + CreateLanguageModeMenu(lmForm, matchPatternLangModeCB, NULL, True);
8403 + XtSetArg(args[n], XmNspacing, 0); n++;
8404 + XtSetArg(args[n], XmNmarginWidth, 0); n++;
8405 + XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
8406 + XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
8407 + XtSetArg(args[n], XmNleftPosition, 50); n++;
8408 + XtSetArg(args[n], XmNsubMenuId, MatchPatternDialog.mpdLmPulldown); n++;
8409 + lmOptMenu = XmCreateOptionMenu(lmForm, "langModeOptMenu", args, n);
8410 + XtManageChild(lmOptMenu);
8411 + MatchPatternDialog.mpdLmOptMenu = lmOptMenu;
8413 + XtVaCreateManagedWidget("lmLbl", xmLabelGadgetClass, lmForm,
8414 + XmNlabelString, s1=XmStringCreateSimple("Language Mode:"),
8416 + XmNuserData, XtParent(MatchPatternDialog.mpdLmOptMenu),
8417 + XmNalignment, XmALIGNMENT_END,
8418 + XmNrightAttachment, XmATTACH_POSITION,
8419 + XmNrightPosition, 50,
8420 + XmNtopAttachment, XmATTACH_FORM,
8421 + XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
8422 + XmNbottomWidget, lmOptMenu, NULL);
8425 + lmBtn = XtVaCreateManagedWidget("lmBtn", xmPushButtonWidgetClass, lmForm,
8426 + XmNlabelString, s1=MKSTRING("Add / Modify\nLanguage Mode..."),
8428 + XmNrightAttachment, XmATTACH_FORM,
8429 + XmNtopAttachment, XmATTACH_FORM, NULL);
8430 + XtAddCallback(lmBtn, XmNactivateCallback, pmLanguageModeDialogCB, NULL);
8433 + okBtn = XtVaCreateManagedWidget("ok", xmPushButtonWidgetClass, form,
8434 + XmNlabelString, s1=XmStringCreateSimple("OK"),
8435 + XmNleftAttachment, XmATTACH_POSITION,
8436 + XmNleftPosition, 1,
8437 + XmNrightAttachment, XmATTACH_POSITION,
8438 + XmNrightPosition, 13,
8439 + XmNbottomAttachment, XmATTACH_FORM,
8440 + XmNbottomOffset, BORDER, NULL);
8441 + XtAddCallback(okBtn, XmNactivateCallback, okCB, NULL);
8444 + applyBtn = XtVaCreateManagedWidget("apply", xmPushButtonWidgetClass, form,
8445 + XmNlabelString, s1=XmStringCreateSimple("Apply"),
8447 + XmNleftAttachment, XmATTACH_POSITION,
8448 + XmNleftPosition, 13,
8449 + XmNrightAttachment, XmATTACH_POSITION,
8450 + XmNrightPosition, 26,
8451 + XmNbottomAttachment, XmATTACH_FORM,
8452 + XmNbottomOffset, BORDER, NULL);
8453 + XtAddCallback(applyBtn, XmNactivateCallback, applyCB, NULL);
8456 + checkBtn = XtVaCreateManagedWidget("check", xmPushButtonWidgetClass, form,
8457 + XmNlabelString, s1=XmStringCreateSimple("Check"),
8459 + XmNleftAttachment, XmATTACH_POSITION,
8460 + XmNleftPosition, 26,
8461 + XmNrightAttachment, XmATTACH_POSITION,
8462 + XmNrightPosition, 39,
8463 + XmNbottomAttachment, XmATTACH_FORM,
8464 + XmNbottomOffset, BORDER, NULL);
8465 + XtAddCallback(checkBtn, XmNactivateCallback, checkCB, NULL);
8468 + deleteBtn = XtVaCreateManagedWidget("delete", xmPushButtonWidgetClass, form,
8469 + XmNlabelString, s1=XmStringCreateSimple("Delete"),
8471 + XmNleftAttachment, XmATTACH_POSITION,
8472 + XmNleftPosition, 39,
8473 + XmNrightAttachment, XmATTACH_POSITION,
8474 + XmNrightPosition, 52,
8475 + XmNbottomAttachment, XmATTACH_FORM,
8476 + XmNbottomOffset, BORDER, NULL);
8477 + XtAddCallback(deleteBtn, XmNactivateCallback, deleteCB, NULL);
8480 + restoreBtn = XtVaCreateManagedWidget("restore", xmPushButtonWidgetClass, form,
8481 + XmNlabelString, s1=XmStringCreateSimple("Restore Defaults"),
8483 + XmNleftAttachment, XmATTACH_POSITION,
8484 + XmNleftPosition, 52,
8485 + XmNrightAttachment, XmATTACH_POSITION,
8486 + XmNrightPosition, 73,
8487 + XmNbottomAttachment, XmATTACH_FORM,
8488 + XmNbottomOffset, BORDER, NULL);
8489 + XtAddCallback(restoreBtn, XmNactivateCallback, restoreCB, NULL);
8492 + closeBtn = XtVaCreateManagedWidget("close", xmPushButtonWidgetClass,
8494 + XmNlabelString, s1=XmStringCreateSimple("Close"),
8495 + XmNleftAttachment, XmATTACH_POSITION,
8496 + XmNleftPosition, 73,
8497 + XmNrightAttachment, XmATTACH_POSITION,
8498 + XmNrightPosition, 86,
8499 + XmNbottomAttachment, XmATTACH_FORM,
8500 + XmNbottomOffset, BORDER, NULL);
8501 + XtAddCallback(closeBtn, XmNactivateCallback, closeCB, NULL);
8504 + helpBtn = XtVaCreateManagedWidget("help", xmPushButtonWidgetClass,
8506 + XmNlabelString, s1=XmStringCreateSimple("Help"),
8508 + XmNleftAttachment, XmATTACH_POSITION,
8509 + XmNleftPosition, 86,
8510 + XmNrightAttachment, XmATTACH_POSITION,
8511 + XmNrightPosition, 99,
8512 + XmNbottomAttachment, XmATTACH_FORM,
8513 + XmNbottomOffset, BORDER, NULL);
8514 + XtAddCallback(helpBtn, XmNactivateCallback, helpCB, NULL);
8517 + stringPatternsFrame = XtVaCreateManagedWidget("stringPatternsFrame", xmFrameWidgetClass,
8519 + XmNleftAttachment, XmATTACH_POSITION,
8520 + XmNleftPosition, 1,
8521 + XmNrightAttachment, XmATTACH_POSITION,
8522 + XmNrightPosition, 99,
8523 + XmNbottomAttachment, XmATTACH_WIDGET,
8524 + XmNbottomWidget, okBtn,
8525 + XmNbottomOffset, BORDER, NULL);
8526 + stringPatternsForm = XtVaCreateManagedWidget("stringPatternsForm", xmFormWidgetClass,
8527 + stringPatternsFrame, NULL);
8528 + MatchPatternDialog.mpdStringPatternsLbl = XtVaCreateManagedWidget("mpdStringPatternsLbl", xmLabelGadgetClass,
8529 + stringPatternsFrame,
8530 + XmNlabelString, s1=XmStringCreateSimple(STRING_PATTERNS_LBL_TXT),
8531 + XmNmarginHeight, 0,
8532 + XmNchildType, XmFRAME_TITLE_CHILD, NULL);
8536 + XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
8537 + XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
8538 + XtSetArg(args[n], XmNleftPosition, 1); n++;
8539 + XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
8540 + XtSetArg(args[n], XmNrightPosition, LIST_RIGHT-1); n++;
8541 + XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
8542 + XtSetArg(args[n], XmNbottomOffset, BORDER); n++;
8543 + MatchPatternDialog.mpdStringPatternsListW =
8544 + CreateManagedList(stringPatternsForm, "stringPatternsList", args,
8545 + n, (void **)MatchPatternDialog.currentStringPatterns.dspElements,
8546 + &MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns,
8547 + MAX_STRING_PATTERNS, 18,
8548 + getStringPatternDisplayedCB, NULL,
8549 + setStringPatternDisplayedCB, NULL,
8550 + freeStringPatternItemCB);
8551 + XtVaSetValues(MatchPatternDialog.mpdStringPatternsLbl, XmNuserData, MatchPatternDialog.mpdStringPatternsListW, NULL);
8553 + MatchPatternDialog.mpdStringPatternTypeLbl = XtVaCreateManagedWidget("mpdStringPatternTypeLbl", xmLabelGadgetClass,
8554 + stringPatternsForm,
8555 + XmNlabelString, s1=XmStringCreateSimple("String Pattern Type:"),
8556 + XmNmarginHeight, 0,
8557 + XmNalignment, XmALIGNMENT_BEGINNING,
8558 + XmNleftAttachment, XmATTACH_POSITION,
8559 + XmNleftPosition, LIST_RIGHT,
8560 + XmNtopAttachment, XmATTACH_FORM, NULL);
8563 + stringPatternTypeBox = XtVaCreateManagedWidget("stringPatternTypeBox", xmRowColumnWidgetClass,
8564 + stringPatternsForm,
8565 + XmNorientation, XmHORIZONTAL,
8566 + XmNpacking, XmPACK_TIGHT,
8567 + XmNradioBehavior, True,
8568 + XmNleftAttachment, XmATTACH_POSITION,
8569 + XmNleftPosition, LIST_RIGHT,
8570 + XmNtopAttachment, XmATTACH_WIDGET,
8571 + XmNtopWidget, MatchPatternDialog.mpdStringPatternTypeLbl, NULL);
8572 + MatchPatternDialog.sptStartW = XtVaCreateManagedWidget("sptStartW",
8573 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8575 + XmNmarginHeight, 0,
8576 + XmNlabelString, s1=XmStringCreateSimple(
8580 + MatchPatternDialog.sptMiddleW = XtVaCreateManagedWidget("sptMiddleW",
8581 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8582 + XmNmarginHeight, 0,
8583 + XmNlabelString, s1=XmStringCreateSimple(
8587 + MatchPatternDialog.sptEndW = XtVaCreateManagedWidget("sptEndW",
8588 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8589 + XmNmarginHeight, 0,
8590 + XmNlabelString, s1=XmStringCreateSimple(
8595 + MatchPatternDialog.mpdWordBoundaryLbl = XtVaCreateManagedWidget("mpdWordBoundaryLbl", xmLabelGadgetClass,
8596 + stringPatternsForm,
8597 + XmNlabelString, s1=XmStringCreateSimple("Word boundary:"),
8598 + XmNmarginHeight, 0,
8599 + XmNalignment, XmALIGNMENT_BEGINNING,
8600 + XmNleftAttachment, XmATTACH_POSITION,
8601 + XmNleftPosition, LIST_RIGHT,
8602 + XmNtopAttachment, XmATTACH_WIDGET,
8603 + XmNtopWidget, stringPatternTypeBox,
8607 + wordBoundaryBox = XtVaCreateManagedWidget("wordBoundaryBox", xmRowColumnWidgetClass,
8608 + stringPatternsForm,
8609 + XmNorientation, XmHORIZONTAL,
8610 + XmNpacking, XmPACK_TIGHT,
8611 + XmNradioBehavior, True,
8612 + XmNleftAttachment, XmATTACH_POSITION,
8613 + XmNleftPosition, LIST_RIGHT,
8614 + XmNtopAttachment, XmATTACH_WIDGET,
8615 + XmNtopWidget, MatchPatternDialog.mpdWordBoundaryLbl, NULL);
8616 + MatchPatternDialog.wbbBothW = XtVaCreateManagedWidget("wbbBothW",
8617 + xmToggleButtonWidgetClass, wordBoundaryBox,
8619 + XmNmarginHeight, 0,
8620 + XmNlabelString, s1=XmStringCreateSimple(
8621 + "Both (pattern is word)"),
8624 + MatchPatternDialog.wbbLeftW = XtVaCreateManagedWidget("wbbLeftW",
8625 + xmToggleButtonWidgetClass, wordBoundaryBox,
8626 + XmNmarginHeight, 0,
8627 + XmNlabelString, s1=XmStringCreateSimple(
8631 + MatchPatternDialog.wbbRightW = XtVaCreateManagedWidget("wbbRightW",
8632 + xmToggleButtonWidgetClass, wordBoundaryBox,
8633 + XmNmarginHeight, 0,
8634 + XmNlabelString, s1=XmStringCreateSimple(
8638 + MatchPatternDialog.wbbNoneW = XtVaCreateManagedWidget("wbbNoneW",
8639 + xmToggleButtonWidgetClass, wordBoundaryBox,
8640 + XmNmarginHeight, 0,
8641 + XmNlabelString, s1=XmStringCreateSimple(
8646 + MatchPatternDialog.mpdStringAttributesLbl = XtVaCreateManagedWidget("mpdStringAttributesLbl", xmLabelGadgetClass,
8647 + stringPatternsForm,
8648 + XmNlabelString, s1=XmStringCreateSimple("String Attributes:"),
8649 + XmNmarginHeight, 0,
8650 + XmNalignment, XmALIGNMENT_BEGINNING,
8651 + XmNleftAttachment, XmATTACH_POSITION,
8652 + XmNleftPosition, LIST_RIGHT,
8653 + XmNtopAttachment, XmATTACH_WIDGET,
8654 + XmNtopWidget, wordBoundaryBox, NULL);
8657 + stringAttributesBox = XtVaCreateManagedWidget("stringAttributesBox", xmRowColumnWidgetClass,
8658 + stringPatternsForm,
8659 + XmNorientation, XmHORIZONTAL,
8660 + XmNpacking, XmPACK_TIGHT,
8661 + XmNleftAttachment, XmATTACH_POSITION,
8662 + XmNleftPosition, LIST_RIGHT,
8663 + XmNtopAttachment, XmATTACH_WIDGET,
8664 + XmNtopWidget, MatchPatternDialog.mpdStringAttributesLbl, NULL);
8665 + MatchPatternDialog.sabRegularExpressionW = XtVaCreateManagedWidget("sabRegularExpressionW",
8666 + xmToggleButtonWidgetClass, stringAttributesBox,
8668 + XmNmarginHeight, 0,
8669 + XmNlabelString, s1=XmStringCreateSimple(
8670 + "Regular Expression"),
8673 + XtAddCallback(MatchPatternDialog.sabRegularExpressionW, XmNvalueChangedCallback,
8674 + strPatRegExpressionCB, NULL);
8675 + MatchPatternDialog.sabCaseSensitiveW = XtVaCreateManagedWidget("sabCaseSensitiveW",
8676 + xmToggleButtonWidgetClass, stringAttributesBox,
8678 + XmNmarginHeight, 0,
8679 + XmNlabelString, s1=XmStringCreateSimple(
8680 + "Case Sensitive"),
8684 + MatchPatternDialog.mpdStringPatternLbl = XtVaCreateManagedWidget("mpdStringPatternLbl", xmLabelGadgetClass,
8685 + stringPatternsForm,
8686 + XmNlabelString, s1=XmStringCreateSimple("String Pattern"),
8688 + XmNalignment, XmALIGNMENT_BEGINNING,
8689 + XmNleftAttachment, XmATTACH_POSITION,
8690 + XmNleftPosition, LIST_RIGHT,
8691 + XmNtopAttachment, XmATTACH_WIDGET,
8692 + XmNtopWidget, stringAttributesBox,
8693 + XmNtopOffset, BORDER,
8697 + MatchPatternDialog.mpdStringPatternW = XtVaCreateManagedWidget("mpdStringPatternW", xmTextWidgetClass,
8698 + stringPatternsForm,
8699 + XmNleftAttachment, XmATTACH_POSITION,
8700 + XmNleftPosition, LIST_RIGHT,
8701 + XmNtopAttachment, XmATTACH_WIDGET,
8702 + XmNtopWidget, MatchPatternDialog.mpdStringPatternLbl,
8703 + XmNrightAttachment, XmATTACH_FORM,
8704 + XmNrightOffset, BORDER,
8706 + RemapDeleteKey(MatchPatternDialog.mpdStringPatternW);
8707 + XtVaSetValues(MatchPatternDialog.mpdStringPatternLbl, XmNuserData, MatchPatternDialog.mpdStringPatternW, NULL);
8709 + MatchPatternDialog.mpdSubPatNamesLbl = XtVaCreateManagedWidget("mpdSubPatNamesLbl", xmLabelGadgetClass,
8710 + stringPatternsForm,
8711 + XmNlabelString, s1=XmStringCreateSimple("Sub-Pattern Name"),
8713 + XmNalignment, XmALIGNMENT_BEGINNING,
8714 + XmNleftAttachment, XmATTACH_POSITION,
8715 + XmNleftPosition, LIST_RIGHT,
8716 + XmNtopAttachment, XmATTACH_WIDGET,
8717 + XmNtopWidget, MatchPatternDialog.mpdStringPatternW,
8718 + XmNtopOffset, BORDER,
8722 + MatchPatternDialog.mpdSubPatNamesPulldown =
8723 + createSubPatternNameMenu(stringPatternsForm, NULL, False);
8726 + XtSetArg(args[n], XmNspacing, 0); n++;
8727 + XtSetArg(args[n], XmNmarginWidth, 0); n++;
8728 + XtSetArg(args[n], XmNresizeWidth, True); n++;
8729 + XtSetArg(args[n], XmNresizeHeight, True); n++;
8730 + XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;
8731 + XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
8732 + XtSetArg(args[n], XmNtopWidget, MatchPatternDialog.mpdSubPatNamesLbl); n++;
8733 + XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
8734 + XtSetArg(args[n], XmNleftPosition, LIST_RIGHT); n++;
8735 + XtSetArg(args[n], XmNsubMenuId, MatchPatternDialog.mpdSubPatNamesPulldown); n++;
8736 + MatchPatternDialog.mpdSubPatNamesOptMenu =
8737 + XmCreateOptionMenu(stringPatternsForm, "subPatNamesOptMenu", args, n);
8738 + XtManageChild(MatchPatternDialog.mpdSubPatNamesOptMenu);
8741 + MatchPatternDialog.mpdSubPatNamesLbl,
8742 + XmNuserData, XtParent(MatchPatternDialog.mpdSubPatNamesOptMenu),
8745 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesLbl, False);
8746 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesOptMenu, False);
8748 + matchPatternsFrame = XtVaCreateManagedWidget("matchPatternsFrame", xmFrameWidgetClass,
8750 + XmNleftAttachment, XmATTACH_POSITION,
8751 + XmNleftPosition, 1,
8752 + XmNtopAttachment, XmATTACH_WIDGET,
8753 + XmNtopWidget, lmForm,
8754 + XmNrightAttachment, XmATTACH_POSITION,
8755 + XmNrightPosition, 99,
8756 + XmNbottomAttachment, XmATTACH_WIDGET,
8757 + XmNbottomWidget, stringPatternsFrame,
8758 + XmNbottomOffset, BORDER, NULL);
8759 + matchPatternsForm = XtVaCreateManagedWidget("matchPatternsForm", xmFormWidgetClass,
8760 + matchPatternsFrame, NULL);
8761 + matchPatternsLbl = XtVaCreateManagedWidget("matchPatternsLbl", xmLabelGadgetClass,
8762 + matchPatternsFrame,
8763 + XmNlabelString, s1=XmStringCreateSimple("Matching Patterns"),
8765 + XmNmarginHeight, 0,
8766 + XmNchildType, XmFRAME_TITLE_CHILD, NULL);
8769 + matchPatternTypeLbl = XtVaCreateManagedWidget("matchPatternTypeLbl", xmLabelGadgetClass,
8770 + matchPatternsForm,
8771 + XmNlabelString, s1=XmStringCreateSimple("Matching Pattern Type:"),
8772 + XmNmarginHeight, 0,
8773 + XmNalignment, XmALIGNMENT_BEGINNING,
8774 + XmNleftAttachment, XmATTACH_POSITION,
8775 + XmNleftPosition, LIST_RIGHT,
8776 + XmNtopAttachment, XmATTACH_FORM, NULL);
8779 + matchPatternTypeBox = XtVaCreateManagedWidget("matchPatternTypeBox", xmRowColumnWidgetClass,
8780 + matchPatternsForm,
8781 + XmNpacking, XmPACK_COLUMN,
8782 + XmNradioBehavior, True,
8783 + XmNleftAttachment, XmATTACH_POSITION,
8784 + XmNleftPosition, LIST_RIGHT,
8785 + XmNtopAttachment, XmATTACH_WIDGET,
8786 + XmNtopWidget, matchPatternTypeLbl, NULL);
8787 + MatchPatternDialog.mptbIndividualW = XtVaCreateManagedWidget("mptbIndividualW",
8788 + xmToggleButtonWidgetClass, matchPatternTypeBox,
8790 + XmNmarginHeight, 0,
8791 + XmNlabelString, s1=XmStringCreateSimple(
8793 + XmNmnemonic, 'I', NULL);
8795 + XtAddCallback(MatchPatternDialog.mptbIndividualW, XmNvalueChangedCallback,
8796 + matchPatTypeCB, NULL);
8797 + MatchPatternDialog.mptbSubPatternW = XtVaCreateManagedWidget("mptbSubPatternW",
8798 + xmToggleButtonWidgetClass, matchPatternTypeBox,
8799 + XmNmarginHeight, 0,
8800 + XmNlabelString, s1=XmStringCreateSimple(
8801 + "Sub-pattern (belongs to context group)"),
8802 + XmNmnemonic, 'u', NULL);
8804 + XtAddCallback(MatchPatternDialog.mptbSubPatternW, XmNvalueChangedCallback,
8805 + matchPatTypeCB, NULL);
8806 + MatchPatternDialog.mptbContextGroupW = XtVaCreateManagedWidget("mptbContextGroupW",
8807 + xmToggleButtonWidgetClass, matchPatternTypeBox,
8808 + XmNmarginHeight, 0,
8809 + XmNlabelString, s1=XmStringCreateSimple(
8811 + XmNmnemonic, 'g', NULL);
8813 + XtAddCallback(MatchPatternDialog.mptbContextGroupW, XmNvalueChangedCallback,
8814 + matchPatTypeCB, NULL);
8816 + MatchPatternDialog.mpdGlobalAttributesLbl = XtVaCreateManagedWidget("mpdGlobalAttributesLbl",
8817 + xmLabelGadgetClass, matchPatternsForm,
8818 + XmNlabelString, s1=XmStringCreateSimple("Global Attributes:"),
8819 + XmNmarginHeight, 0,
8820 + XmNalignment, XmALIGNMENT_BEGINNING,
8821 + XmNleftAttachment, XmATTACH_POSITION,
8822 + XmNleftPosition, LIST_RIGHT,
8823 + XmNtopAttachment, XmATTACH_WIDGET,
8824 + XmNtopOffset, BORDER,
8825 + XmNtopWidget, matchPatternTypeBox, NULL);
8828 + globalAttributesBox = XtVaCreateManagedWidget("globalAttributesBox", xmRowColumnWidgetClass,
8829 + matchPatternsForm,
8830 + XmNpacking, XmPACK_COLUMN,
8831 + XmNleftAttachment, XmATTACH_POSITION,
8832 + XmNleftPosition, LIST_RIGHT,
8833 + XmNtopAttachment, XmATTACH_WIDGET,
8834 + XmNtopWidget, MatchPatternDialog.mpdGlobalAttributesLbl, NULL);
8835 + MatchPatternDialog.gabSkipBtwStartEndW = XtVaCreateManagedWidget("gabSkipBtwStartEndW",
8836 + xmToggleButtonWidgetClass, globalAttributesBox,
8837 + XmNmarginHeight, 0,
8838 + XmNlabelString, s1=XmStringCreateSimple(
8839 + "Skip content between start / end pattern"),
8840 + XmNmnemonic, 'c', NULL);
8842 + MatchPatternDialog.gabFlashW = XtVaCreateManagedWidget("gabFlashW",
8843 + xmToggleButtonWidgetClass, globalAttributesBox,
8845 + XmNmarginHeight, 0,
8846 + XmNlabelString, s1=XmStringCreateSimple(
8847 + "Flash matching pattern"),
8848 + XmNmnemonic, 'l', NULL);
8850 + MatchPatternDialog.gabSyntaxBasedW = XtVaCreateManagedWidget("gabSyntaxBasedW",
8851 + xmToggleButtonWidgetClass, globalAttributesBox,
8853 + XmNmarginHeight, 0,
8854 + XmNlabelString, s1=XmStringCreateSimple(
8856 + XmNmnemonic, 'b', NULL);
8859 + MatchPatternDialog.mpdMatchPatternNameLbl = XtVaCreateManagedWidget("mpdMatchPatternNameLbl", xmLabelGadgetClass,
8860 + matchPatternsForm,
8861 + XmNlabelString, s1=XmStringCreateSimple(MATCH_PAT_NAME_LBL_TXT),
8863 + XmNalignment, XmALIGNMENT_BEGINNING,
8864 + XmNleftAttachment, XmATTACH_POSITION,
8865 + XmNleftPosition, LIST_RIGHT,
8866 + XmNtopAttachment, XmATTACH_WIDGET,
8867 + XmNtopWidget, globalAttributesBox,
8868 + XmNtopOffset, BORDER, NULL);
8871 + MatchPatternDialog.mpdMatchPatternNameW = XtVaCreateManagedWidget("mpdMatchPatternNameW", xmTextWidgetClass,
8872 + matchPatternsForm,
8873 + XmNleftAttachment, XmATTACH_POSITION,
8874 + XmNleftPosition, LIST_RIGHT,
8875 + XmNtopAttachment, XmATTACH_WIDGET,
8876 + XmNtopWidget, MatchPatternDialog.mpdMatchPatternNameLbl,
8877 + XmNrightAttachment, XmATTACH_FORM,
8878 + XmNrightOffset, BORDER,
8879 + XmNbottomAttachment, XmATTACH_FORM,
8880 + XmNbottomOffset, BORDER,
8882 + RemapDeleteKey(MatchPatternDialog.mpdMatchPatternNameW);
8883 + XtVaSetValues(MatchPatternDialog.mpdMatchPatternNameLbl, XmNuserData, MatchPatternDialog.mpdMatchPatternNameW, NULL);
8886 + XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
8887 + XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
8888 + XtSetArg(args[n], XmNleftPosition, 1); n++;
8889 + XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
8890 + XtSetArg(args[n], XmNrightPosition, LIST_RIGHT-1); n++;
8891 + XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
8893 + XtSetArg(args[n], XmNbottomOffset, BORDER); n++;
8894 + MatchPatternDialog.mpdMatchPatternNamesListW =
8895 + CreateManagedList(
8896 + matchPatternsForm, "mpdMatchPatternNamesListW",
8898 + (void **)MatchPatternDialog.mpdTable.dmpiSequence, &MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements,
8899 + MAX_NBR_MATCH_PATTERNS, 18,
8900 + getMatchPatternDisplayedCB, NULL,
8901 + setMatchPatternDisplayedCB, NULL,
8902 + freeMatchPatternItemCB);
8903 + AddDeleteConfirmCB(MatchPatternDialog.mpdMatchPatternNamesListW, deleteMatchPatternItemCB, NULL);
8905 + XtVaSetValues(matchPatternsLbl, XmNuserData, MatchPatternDialog.mpdMatchPatternNamesListW, NULL);
8908 + * set initial default button
8910 + XtVaSetValues(form, XmNdefaultButton, okBtn, NULL);
8911 + XtVaSetValues(form, XmNcancelButton, closeBtn, NULL);
8914 + * handle mnemonic selection of buttons and focus to dialog
8916 + AddDialogMnemonicHandler(form, False);
8919 + * fill in the dialog information for the selected language mode
8921 + SetLangModeMenu(MatchPatternDialog.mpdLmOptMenu, MatchPatternDialog.mpdLangModeName);
8924 + * realize all of the widgets in the new dialog
8926 + RealizeWithoutForcingPosition(MatchPatternDialog.mpdShell);
8930 +** Modify match pattern dialog depending on showing a string pattern
8931 +** or a context group.
8933 +static void setDialogType(int dialogShowsStringPattern)
8935 + char *matchPatternNameText;
8936 + char *strPatCxtGrpListText;
8938 + int regularExpression =
8939 + XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
8942 + * check, if dialog mode needs to be switched
8944 + if (MatchPatternDialog.mpdStringPatternIsDisplayed == dialogShowsStringPattern)
8949 + if (dialogShowsStringPattern)
8951 + matchPatternNameText = MATCH_PAT_NAME_LBL_TXT;
8952 + strPatCxtGrpListText = STRING_PATTERNS_LBL_TXT;
8956 + matchPatternNameText = "Context Group Name";
8957 + strPatCxtGrpListText = "Related Sub-Patterns";
8960 + XtSetSensitive(MatchPatternDialog.mpdGlobalAttributesLbl, dialogShowsStringPattern);
8961 + XtSetSensitive(MatchPatternDialog.gabSkipBtwStartEndW, dialogShowsStringPattern);
8962 + XtSetSensitive(MatchPatternDialog.gabFlashW, dialogShowsStringPattern);
8963 + XtSetSensitive(MatchPatternDialog.gabSyntaxBasedW, dialogShowsStringPattern);
8965 + XtSetSensitive(MatchPatternDialog.mpdStringPatternTypeLbl, dialogShowsStringPattern);
8966 + XtSetSensitive(MatchPatternDialog.sptStartW, dialogShowsStringPattern);
8967 + XtSetSensitive(MatchPatternDialog.sptMiddleW, dialogShowsStringPattern);
8968 + XtSetSensitive(MatchPatternDialog.sptEndW, dialogShowsStringPattern);
8970 + setSensitiveWordBoundaryBox( dialogShowsStringPattern && !regularExpression );
8972 + XtSetSensitive(MatchPatternDialog.mpdStringAttributesLbl, dialogShowsStringPattern);
8973 + XtSetSensitive(MatchPatternDialog.sabCaseSensitiveW, dialogShowsStringPattern);
8974 + XtSetSensitive(MatchPatternDialog.sabRegularExpressionW, dialogShowsStringPattern);
8976 + XtSetSensitive(MatchPatternDialog.mpdStringPatternLbl, dialogShowsStringPattern);
8977 + XtSetSensitive(MatchPatternDialog.mpdStringPatternW, dialogShowsStringPattern);
8979 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesLbl, !dialogShowsStringPattern);
8980 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesOptMenu, !dialogShowsStringPattern);
8983 + MatchPatternDialog.mpdMatchPatternNameLbl,
8984 + XmNlabelString, s1=XmStringCreateSimple(matchPatternNameText),
8989 + MatchPatternDialog.mpdStringPatternsLbl,
8990 + XmNlabelString, s1=XmStringCreateSimple(strPatCxtGrpListText),
8994 + MatchPatternDialog.mpdStringPatternIsDisplayed = dialogShowsStringPattern;
8997 +static void setSensitiveWordBoundaryBox(int enable)
8999 + XtSetSensitive(MatchPatternDialog.mpdWordBoundaryLbl, enable);
9000 + XtSetSensitive(MatchPatternDialog.wbbBothW , enable);
9001 + XtSetSensitive(MatchPatternDialog.wbbLeftW , enable);
9002 + XtSetSensitive(MatchPatternDialog.wbbRightW, enable);
9003 + XtSetSensitive(MatchPatternDialog.wbbNoneW , enable);
9006 +static void matchPatternLangModeCB(Widget w, XtPointer clientData, XtPointer callData)
9009 + StringMatchTable *oldTable, *newTable;
9010 + StringMatchTable emptyTable = {"", NULL, NULL, NULL, NULL, 0, NULL, 0, NULL};
9011 + StringMatchTable *table;
9012 + DMPTranslationResult translResult;
9016 + * Get the newly selected mode name. If it's the same, do nothing
9018 + XtVaGetValues(w, XmNuserData, &modeName, NULL);
9019 + if (!strcmp(modeName, MatchPatternDialog.mpdLangModeName))
9023 + * Look up the original version of the patterns being edited
9025 + oldTable = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
9026 + if (oldTable == NULL)
9027 + oldTable = &emptyTable;
9030 + * Get the current information displayed by the dialog. If it's bad,
9031 + * give the user the chance to throw it out or go back and fix it. If
9032 + * it has changed, give the user the chance to apply discard or cancel.
9034 + newTable = getDialogStringMatchTable(&translResult);
9036 + if (translResult == DMPTR_EMPTY)
9038 + newTable = &emptyTable;
9041 + if (newTable == NULL)
9044 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9045 + "Incomplete Matching Patterns for Language Mode",
9046 + "Discard incomplete entry for language mode '%s'?",
9047 + "Keep", "Discard",
9048 + MatchPatternDialog.mpdLangModeName) == 1)
9051 + MatchPatternDialog.mpdLmOptMenu,
9052 + MatchPatternDialog.mpdLangModeName);
9057 + else if (stringMatchTableDiffer(oldTable, newTable))
9059 + if (newTable == &emptyTable)
9064 + DF_WARN, MatchPatternDialog.mpdShell, 3,
9065 + "Change Language Mode",
9066 + "Apply changes for language mode '%s'?",
9067 + "Apply Changes", "Discard Changes", "Cancel",
9068 + MatchPatternDialog.mpdLangModeName);
9073 + MatchPatternDialog.mpdLmOptMenu,
9074 + MatchPatternDialog.mpdLangModeName);
9076 + freeStringMatchTable( newTable );
9080 + else if (resp == 1)
9082 + updateStringMatchTable( newTable );
9085 + * Don't free the new table due to it's stored in MatchTables now
9091 + if (newTable != NULL && newTable != &emptyTable)
9092 + freeStringMatchTable(newTable);
9095 + * Free the old dialog information
9097 + freeVariableDialogData(DISCARD_LANGUAGE_MODE);
9100 + * Fill the dialog with the new language mode information
9102 + MatchPatternDialog.mpdLangModeName = XtNewString(modeName);
9105 + * Find the associated matching pattern table to edit
9107 + table = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
9110 + * Copy the list of patterns to one that the user can freely edit
9112 + copyStringMatchTableForDialog( table, &MatchPatternDialog.mpdTable );
9115 + * Update dialog fields
9117 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9118 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9121 +static void pmLanguageModeDialogCB(Widget w, XtPointer clientData, XtPointer callData)
9123 + EditLanguageModes();
9127 +** If a matching pattern dialog is up, ask to have the option menu for
9128 +** chosing language mode updated (via a call to CreateLanguageModeMenu)
9130 +void UpdateLanguageModeMenuMatchPattern(void)
9134 + if (MatchPatternDialog.mpdShell == NULL)
9137 + oldMenu = MatchPatternDialog.mpdLmPulldown;
9139 + * don't include "PLAIN" (4th parameter) in LM menu
9141 + MatchPatternDialog.mpdLmPulldown = CreateLanguageModeMenu(
9142 + XtParent(XtParent(oldMenu)), matchPatternLangModeCB, NULL, False);
9143 + XtVaSetValues(XmOptionButtonGadget(MatchPatternDialog.mpdLmOptMenu),
9144 + XmNsubMenuId, MatchPatternDialog.mpdLmPulldown, NULL);
9145 + SetLangModeMenu(MatchPatternDialog.mpdLmOptMenu, MatchPatternDialog.mpdLangModeName);
9147 + XtDestroyWidget(oldMenu);
9150 +static void *getMatchPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
9153 + DialogMatchPatternSequenceElement *newSeq;
9156 + * If the dialog is currently displaying the "new" entry and the
9157 + * fields are empty, that's just fine
9159 + if (oldItem == NULL && matchPatternDialogEmpty())
9163 + * Read string patterns / sub-pattern names area first
9165 + UpdateManagedList(MatchPatternDialog.mpdStringPatternsListW, True);
9168 + * If there are no problems reading the data, just return it
9170 + newSeq = readMatchPatternFields(True);
9171 + if (newSeq != NULL)
9172 + return (void *)newSeq;
9175 + * If there are problems, and the user didn't ask for the fields to be
9176 + * read, give more warning
9178 + if (!explicitRequest)
9181 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9182 + "Discard Matching Pattern Entry",
9183 + "Discard incomplete entry\nfor current matching pattern?",
9184 + "Keep", "Discard") == 2)
9186 + return oldItem == NULL
9188 + : (void *)copyDialogSequenceElement(
9189 + (DialogMatchPatternSequenceElement *)oldItem);
9194 + * read data again without "silent" mode to display warning
9196 + newSeq = readMatchPatternFields(False);
9202 +static void setMatchPatternDisplayedCB(void *item, void *cbArg)
9204 + DialogMatchPatternSequenceElement *seqElement;
9205 + DialogMatchPatternTableElement *element;
9206 + DialogMatchPatternGroupElement *group;
9209 + seqElement = (DialogMatchPatternSequenceElement *)item;
9211 + MatchPatternDialog.currentDmptSeqElement = seqElement;
9215 + MatchPatternDialog.currentDmptElement = NULL;
9216 + MatchPatternDialog.currentDmptGroup = NULL;
9218 + XmTextSetString(MatchPatternDialog.mpdMatchPatternNameW, "");
9219 + RadioButtonChangeState(MatchPatternDialog.mptbIndividualW, True, True);
9220 + RadioButtonChangeState(MatchPatternDialog.gabSkipBtwStartEndW, False, False);
9221 + RadioButtonChangeState(MatchPatternDialog.gabFlashW, True, False);
9222 + RadioButtonChangeState(MatchPatternDialog.gabSyntaxBasedW, True, False);
9224 + freeDialogStringPatterns(
9225 + &MatchPatternDialog.currentStringPatterns);
9227 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9229 + setDialogType( STRING_PATTERN_DIALOG );
9233 + isGroup = (seqElement->dmpseType == MPT_GROUP);
9235 + XmTextSetString(MatchPatternDialog.mpdMatchPatternNameW, seqElement->dmpseName);
9237 + if (seqElement->dmpseType == MPT_INDIVIDUAL)
9238 + RadioButtonChangeState(MatchPatternDialog.mptbIndividualW, True, True);
9239 + else if (seqElement->dmpseType == MPT_SUB)
9240 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9242 + RadioButtonChangeState(MatchPatternDialog.mptbContextGroupW, True, True);
9244 + freeDialogStringPatterns(
9245 + &MatchPatternDialog.currentStringPatterns);
9249 + group = (DialogMatchPatternGroupElement *)seqElement->dmpsePtr;
9250 + MatchPatternDialog.currentDmptElement = NULL;
9251 + MatchPatternDialog.currentDmptGroup = group;
9253 + copyDialogPatternNamesFromGroup(
9255 + &MatchPatternDialog.currentStringPatterns);
9259 + element = (DialogMatchPatternTableElement *)seqElement->dmpsePtr;
9260 + MatchPatternDialog.currentDmptElement = element;
9261 + MatchPatternDialog.currentDmptGroup = NULL;
9263 + RadioButtonChangeState(
9264 + MatchPatternDialog.gabSkipBtwStartEndW,
9265 + element->dmpteSkipBtwnStartEnd,
9267 + RadioButtonChangeState(
9268 + MatchPatternDialog.gabFlashW,
9269 + element->dmpteFlash,
9271 + RadioButtonChangeState(
9272 + MatchPatternDialog.gabSyntaxBasedW,
9273 + !element->dmpteIgnoreHighLightInfo,
9276 + copyDialogStringPatternsFromTable(
9278 + &MatchPatternDialog.currentStringPatterns);
9281 + setDialogType( !isGroup );
9283 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9287 +static void freeMatchPatternItemCB(void *item)
9289 + freeDialogSequenceElement((DialogMatchPatternSequenceElement *)item);
9293 +** Use "delete confirm" to delete matching pattern name from
9294 +** any group of this matching pattern set, in case of sub-pattern.
9295 +** Always confirm the delete.
9297 +static int deleteMatchPatternItemCB(int itemIndex, void *cbArg)
9299 + DialogMatchPatternSequenceElement *seqElement;
9301 + seqElement = MatchPatternDialog.mpdTable.dmpiSequence[itemIndex];
9303 + if (seqElement->dmpseType == MPT_SUB)
9305 + removeMatchPatternFromAllGroups( seqElement->dmpseName );
9311 +static void *getStringPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
9314 + DialogStringPatternElement *newPat;
9315 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9318 + * If the string pattern frame is currently displaying the "new" entry and the
9319 + * fields are empty, that's just fine
9321 + if (oldItem == NULL && stringPatternFieldsEmpty(isRelatedToGroup))
9325 + * If there are no problems reading the data, just return it
9327 + newPat = readStringPatternFrameFields(True);
9328 + if (newPat != NULL)
9329 + return (void *)newPat;
9332 + * If there are problems, and the user didn't ask for the fields to be
9333 + * read, give more warning
9336 + if (!explicitRequest)
9339 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9340 + "Discard String Pattern Entry",
9341 + "Discard incomplete entry\nfor current string pattern?",
9342 + "Keep", "Discard") == 2)
9344 + return oldItem == NULL
9346 + : (void *)copyDialogStringPatternElement(
9347 + (DialogStringPatternElement *)oldItem);
9352 + * read data again without "silent" mode to display warning
9354 + newPat = readStringPatternFrameFields(False);
9360 +static void setStringPatternDisplayedCB(void *item, void *cbArg)
9362 + DialogStringPatternElement *element = (DialogStringPatternElement *)item;
9363 + PatternElementKind peKind;
9364 + PatternWordBoundary wordBoundary;
9365 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9369 + if (isRelatedToGroup)
9371 + updateSubPatternNameMenu(NULL, False);
9375 + XmTextSetString(MatchPatternDialog.mpdStringPatternW, "");
9377 + setSensitiveWordBoundaryBox( True );
9379 + RadioButtonChangeState(MatchPatternDialog.wbbBothW, True, True);
9382 + * type of "new" string pattern:
9383 + * preset "start", if no string pattern exists at all;
9384 + * else select "end"
9386 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
9387 + RadioButtonChangeState(MatchPatternDialog.sptStartW, True, True);
9389 + RadioButtonChangeState(MatchPatternDialog.sptEndW, True, True);
9391 + RadioButtonChangeState(MatchPatternDialog.sabCaseSensitiveW, True, False);
9392 + RadioButtonChangeState(MatchPatternDialog.sabRegularExpressionW, False, False);
9397 + if (isRelatedToGroup)
9399 + updateSubPatternNameMenu(element->dspeText, False);
9403 + XmTextSetString(MatchPatternDialog.mpdStringPatternW, element->dspeText);
9405 + peKind = element->dspeKind;
9406 + wordBoundary = element->dspeWordBoundary;
9408 + if (peKind == PEK_START)
9409 + RadioButtonChangeState(MatchPatternDialog.sptStartW, True, True);
9410 + else if (peKind == PEK_MIDDLE)
9411 + RadioButtonChangeState(MatchPatternDialog.sptMiddleW, True, True);
9413 + RadioButtonChangeState(MatchPatternDialog.sptEndW, True, True);
9415 + if (wordBoundary == PWB_BOTH)
9416 + RadioButtonChangeState(MatchPatternDialog.wbbBothW, True, True);
9417 + else if (wordBoundary == PWB_LEFT)
9418 + RadioButtonChangeState(MatchPatternDialog.wbbLeftW, True, True);
9419 + else if (wordBoundary == PWB_RIGHT)
9420 + RadioButtonChangeState(MatchPatternDialog.wbbRightW, True, True);
9422 + RadioButtonChangeState(MatchPatternDialog.wbbNoneW, True, True);
9424 + RadioButtonChangeState(
9425 + MatchPatternDialog.sabCaseSensitiveW,
9426 + !element->dspeCaseInsensitive,
9429 + RadioButtonChangeState(
9430 + MatchPatternDialog.sabRegularExpressionW,
9431 + element->dspeRegularExpression,
9434 + setSensitiveWordBoundaryBox( !element->dspeRegularExpression );
9439 +static void freeStringPatternItemCB(void *item)
9441 + DialogStringPatternElement *patElement;
9443 + patElement = (DialogStringPatternElement *)item;
9445 + freeDialogStringPatternElement(patElement);
9448 +static void destroyCB(Widget w, XtPointer clientData, XtPointer callData)
9450 + freeVariableDialogData(DISCARD_LANGUAGE_MODE);
9452 + MatchPatternDialog.mpdShell = NULL;
9455 +static void okCB(Widget w, XtPointer clientData, XtPointer callData)
9458 + * change the matching pattern
9460 + if (!getAndUpdateStringMatchTable())
9464 + * pop down and destroy the dialog
9466 + XtDestroyWidget(MatchPatternDialog.mpdShell);
9469 +static void applyCB(Widget w, XtPointer clientData, XtPointer callData)
9472 + * change the matching pattern
9474 + getAndUpdateStringMatchTable();
9477 +static void checkCB(Widget w, XtPointer clientData, XtPointer callData)
9479 + StringMatchTable *newTable;
9480 + DMPTranslationResult translResult;
9483 + * Get the current information displayed by the dialog.
9484 + * If a new table is available, then the test is passed successfully.
9486 + newTable = getDialogStringMatchTable(&translResult);
9488 + if (newTable != NULL)
9491 + DF_INF, MatchPatternDialog.mpdShell, 1,
9492 + "Matching Patterns Checked",
9493 + "Matching Patterns checked without error",
9496 + freeStringMatchTable(newTable);
9500 +static void restoreCB(Widget w, XtPointer clientData, XtPointer callData)
9502 + StringMatchTable *defaultTable;
9504 + defaultTable = readDefaultStringMatchTable(MatchPatternDialog.mpdLangModeName);
9506 + if (defaultTable == NULL)
9509 + DF_WARN, MatchPatternDialog.mpdShell, 1,
9510 + "No Default Matching Pattern",
9511 + "There is no default matching pattern set\nfor language mode %s",
9513 + MatchPatternDialog.mpdLangModeName);
9519 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9520 + "Discard Changes",
9521 + "Are you sure you want to discard\n"
9522 + "all changes to matching patterns\n"
9523 + "for language mode %s?",
9524 + "Discard", "Cancel",
9525 + MatchPatternDialog.mpdLangModeName) == 2)
9527 + freeStringMatchTable(defaultTable);
9533 + * if a stored version of the matching pattern set exists, replace it.
9534 + * if it doesn't, add a new one.
9536 + updateStringMatchTable( defaultTable );
9539 + * free the old dialog information
9541 + freeVariableDialogData(KEEP_LANGUAGE_MODE);
9544 + * update the dialog
9546 + copyStringMatchTableForDialog( defaultTable, &MatchPatternDialog.mpdTable );
9548 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9549 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9552 +static void deleteCB(Widget w, XtPointer clientData, XtPointer callData)
9555 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9556 + "Delete Matching Patterns",
9557 + "Are you sure you want to delete\n"
9558 + "all matching patterns for\n"
9559 + "language mode %s?",
9560 + "Yes, Delete", "Cancel",
9561 + MatchPatternDialog.mpdLangModeName) == 2)
9567 + * if a stored version of the matching pattern exists, delete it from the list
9569 + DeleteStringMatchTable(MatchPatternDialog.mpdLangModeName);
9572 + * free the old dialog information
9574 + freeVariableDialogData(KEEP_LANGUAGE_MODE);
9577 + * clear out the dialog
9579 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9580 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9583 +static void closeCB(Widget w, XtPointer clientData, XtPointer callData)
9586 + * pop down and destroy the dialog
9588 + XtDestroyWidget(MatchPatternDialog.mpdShell);
9591 +static void helpCB(Widget w, XtPointer clientData, XtPointer callData)
9594 + Help(HELP_MATCHING_PATTERNS);
9598 +static void strPatRegExpressionCB(Widget w, XtPointer clientData, XtPointer callData)
9600 + int regularExpression =
9601 + XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
9603 + setSensitiveWordBoundaryBox( !regularExpression );
9605 + if (regularExpression)
9606 + RadioButtonChangeState(MatchPatternDialog.sabCaseSensitiveW, True, False);
9609 +static void matchPatTypeCB(Widget w, XtPointer clientData, XtPointer callData)
9611 + if (MatchPatternDialog.currentDmptSeqElement != NULL)
9613 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW))
9615 + if (MatchPatternDialog.currentDmptSeqElement->dmpseType == MPT_SUB)
9617 + changeExistingSubPattern("Change to Context Group");
9620 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW) &&
9621 + MatchPatternDialog.currentDmptSeqElement->dmpseType != MPT_GROUP)
9623 + changeStringPatternToGroup();
9626 + else if (XmToggleButtonGetState(MatchPatternDialog.mptbIndividualW))
9628 + if (MatchPatternDialog.currentDmptSeqElement->dmpseType == MPT_SUB)
9630 + changeExistingSubPattern("Change to Individual Matching Pattern");
9632 + else if (MatchPatternDialog.currentDmptSeqElement->dmpseType == MPT_GROUP)
9634 + changeGroupToStringPattern("Change to Individual Matching Pattern");
9637 + else if (XmToggleButtonGetState(MatchPatternDialog.mptbSubPatternW))
9639 + if (MatchPatternDialog.currentDmptSeqElement->dmpseType == MPT_GROUP)
9641 + changeGroupToStringPattern("Change to Sub-Matching Pattern");
9647 + * if context group button is (still) selected, then update labels etc.
9649 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW))
9651 + setDialogType(CONTEXT_GROUP_DIALOG);
9655 + setDialogType(STRING_PATTERN_DIALOG);
9659 + * if a "new" entry is selected in matching patterns names list, then provide a
9660 + * list of all sub-pattern names
9662 + if (MatchPatternDialog.currentDmptSeqElement == NULL)
9664 + updateSubPatternNameMenu(NULL, True);
9668 +static void changeExistingSubPattern(
9671 + DialogMatchPatternGroupElement *group;
9675 + getDialogGroupUsingMatchPattern(
9676 + MatchPatternDialog.currentDmptElement->dmpteName );
9678 + while ( group != NULL )
9682 + DF_WARN, MatchPatternDialog.mpdShell, 3,
9684 + "Sub-pattern '%s' is used at least\n"
9685 + "by context group '%s'.\n\n"
9686 + "Remove this sub-pattern from this resp. all context group(s) ?",
9687 + "No, Keep", "Yes, Remove", "Yes, Remove All",
9688 + MatchPatternDialog.currentDmptElement->dmpteName,
9689 + group->dmpgeName);
9693 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9697 + else if (resp == 2)
9699 + removeMatchPatternFromGroup(
9700 + MatchPatternDialog.currentDmptElement->dmpteName,
9704 + * look for evtl. next context group holding this matching pattern
9707 + getDialogGroupUsingMatchPattern(
9708 + MatchPatternDialog.currentDmptElement->dmpteName );
9713 + * remove this matching pattern form all context groups
9715 + removeMatchPatternFromAllGroups(
9716 + MatchPatternDialog.currentDmptElement->dmpteName);
9723 +static void changeStringPatternToGroup(void)
9728 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns != 0)
9732 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9733 + "Change to Context Group",
9734 + "All string patterns of '%s'\n"
9735 + "need to be discarded.\n\n"
9736 + "Discard related string patterns ?",
9737 + "No, Keep", "Yes, Discard",
9738 + MatchPatternDialog.currentDmptElement->dmpteName);
9742 + isSubPattern = (MatchPatternDialog.currentDmptElement->dmpteType == MPT_SUB);
9745 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9747 + RadioButtonChangeState(MatchPatternDialog.mptbIndividualW, True, True);
9753 + * remove string patterns & update dialog fields
9755 + freeDialogStringPatterns(&MatchPatternDialog.currentStringPatterns);
9757 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9761 + * invalidate this sub-/individual pattern
9763 + MatchPatternDialog.currentDmptSeqElement->dmpseValid = False;
9766 + * update sub-pattern menu due to change to context group
9768 + updateSubPatternNameMenu(NULL, True);
9771 +static void changeGroupToStringPattern(
9776 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
9781 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9783 + "Content of context group '%s'\n"
9784 + "needs to be discarded.\n\n"
9785 + "Discard content ?",
9786 + "No, Keep", "Yes, Discard",
9787 + MatchPatternDialog.currentDmptGroup->dmpgeName);
9791 + RadioButtonChangeState(MatchPatternDialog.mptbContextGroupW, True, True);
9796 + * remove string patterns & update dialog fields
9798 + freeDialogStringPatterns(&MatchPatternDialog.currentStringPatterns);
9800 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9805 +** Create a pulldown menu pane with the names of the sub-patterns of
9806 +** the current matching pattern set.
9808 +static Widget createSubPatternNameMenu(
9810 + char *currentSubPatName,
9811 + int allSubPatterns)
9813 + NameList nameList;
9817 + setupSubPatternNameList(currentSubPatName, allSubPatterns, &nameList);
9819 + menu = CreatePulldownMenu(parent, "subPatternNames", NULL, 0);
9821 + for (i=0; i<nameList.nlNumber; i++)
9823 + createSubPatNameMenuEntry(menu, nameList.nlId[i]);
9829 +static void setupSubPatternNameList(
9830 + char *currentSubPatName,
9831 + int allSubPatterns,
9832 + NameList *nameList)
9836 + DialogMatchPatternSequenceElement *seq;
9837 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9839 + if (isRelatedToGroup || allSubPatterns)
9842 + * add "none selected" (default) item
9844 + nameList->nlId[n ++] = SPNM_NONE_SELECTED;
9847 + * add one item for each (not assigned) sub-pattern name
9849 + for (i=0; i<MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i++)
9851 + seq = MatchPatternDialog.mpdTable.dmpiSequence[i];
9853 + if (seq->dmpseType == MPT_SUB &&
9854 + seq->dmpseValid &&
9855 + (allSubPatterns ||
9856 + (!isSubPatternNameInCurStrPat(seq->dmpseName) ||
9857 + (currentSubPatName != NULL &&
9858 + (strcmp(seq->dmpseName, currentSubPatName) == 0))) ))
9860 + nameList->nlId[n ++] = seq->dmpseName;
9866 + nameList->nlId[n ++] = "none available ";
9869 + nameList->nlNumber = n;
9873 +** Create a menu entry with the names of one sub-pattern.
9874 +** XmNuserData of this item contains the sub-pattern name.
9876 +static void createSubPatNameMenuEntry(
9883 + btn = XtVaCreateManagedWidget("subPattern", xmPushButtonGadgetClass,
9885 + XmNlabelString, s1=XmStringCreateSimple(subPatName),
9886 + XmNmarginHeight, 0,
9887 + XmNuserData, (void *)subPatName, NULL);
9892 +** Set the sub-patterns menu to show a particular sub-pattern name
9894 +static void setSubPatternNameMenu(
9895 + const char *subPatName)
9900 + Widget pulldown, selectedItem;
9903 + XtVaGetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNsubMenuId, &pulldown, NULL);
9904 + XtVaGetValues(pulldown, XmNchildren, &items, XmNnumChildren, &nItems, NULL);
9909 + selectedItem = items[0];
9912 + * if no subPatName is given, then select first item of option menu
9914 + if (subPatName != NULL)
9916 + for (i=0; i<(int)nItems; i++)
9918 + if (items[i] != NULL && !items[i]->core.being_destroyed)
9920 + XtVaGetValues(items[i], XmNuserData, &itemName, NULL);
9921 + if (!strcmp(itemName, subPatName))
9923 + selectedItem = items[i];
9930 + XtVaSetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNmenuHistory, selectedItem, NULL);
9934 +** Update sub-pattern names menu, e.g. when a new sub-pattern is defined
9936 +static void updateSubPatternNameMenu(
9937 + char *currentSubPatName,
9938 + int allSubPatterns)
9940 + NameList nameList;
9946 + setupSubPatternNameList(currentSubPatName, allSubPatterns, &nameList);
9949 + * Go thru all of the items in the sub-pattern names menu
9950 + * and rename them to match the current sub-patterns.
9951 + * Delete any extras.
9954 + MatchPatternDialog.mpdSubPatNamesPulldown,
9955 + XmNchildren, &items,
9956 + XmNnumChildren, &nItems,
9959 + for (n=0; n<(int)nItems; n++)
9961 + if (n >= nameList.nlNumber)
9964 + * unmanaging before destroying stops parent from displaying
9966 + XtUnmanageChild(items[n]);
9967 + XtDestroyWidget(items[n]);
9971 + if (items[n] == NULL || items[n]->core.being_destroyed)
9974 + * create a new entry (widget) if this one is not existing or
9975 + * if it is marked as to be destroyed
9977 + createSubPatNameMenuEntry(
9978 + MatchPatternDialog.mpdSubPatNamesPulldown, nameList.nlId[n]);
9984 + XmNlabelString, st1=XmStringCreateSimple(nameList.nlId[n]),
9985 + XmNuserData, (void *)nameList.nlId[n],
9988 + XmStringFree(st1);
9994 + * add new items for remaining sub-patterns names
9996 + for (n=(int)nItems; n<nameList.nlNumber; n++)
9998 + createSubPatNameMenuEntry(
9999 + MatchPatternDialog.mpdSubPatNamesPulldown, nameList.nlId[n]);
10003 + * select entry shown in sub-pattern name option menu
10005 + setSubPatternNameMenu(currentSubPatName);
10008 +static char *getSelectedSubPatternName(void)
10010 + Widget selectedItem;
10013 + XtVaGetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNmenuHistory, &selectedItem, NULL);
10014 + XtVaGetValues(selectedItem, XmNuserData, &itemName, NULL);
10019 +static int isSubPatternNameInCurStrPat(
10020 + char *subPatName)
10023 + DialogStringPatterns *curPatNames = &MatchPatternDialog.currentStringPatterns;
10025 + for (i=0; i<curPatNames->dspNumberOfPatterns; i++)
10027 + if (strcmp(curPatNames->dspElements[i]->dspeText, subPatName) == 0)
10035 +** Read the matching pattern fields of the matching pattern dialog and produce an
10036 +** allocated DialogMatchPatternSequenceElement structure reflecting the contents.
10037 +** Pop up dialogs telling the user what's wrong (Passing "silent" as True,
10038 +** suppresses these dialogs).
10039 +** Returns NULL on error.
10041 +static DialogMatchPatternSequenceElement *readMatchPatternFields(int silent)
10047 + char *contentTitle;
10048 + char *contentWarningText;
10049 + DialogMatchPatternSequenceElement *newSeq;
10050 + DialogMatchPatternTableElement *newElement;
10051 + DialogMatchPatternGroupElement *newGroup;
10053 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW))
10055 + nameLabel = "context group name";
10056 + nameTitle = "Context Group Name";
10057 + contentTitle = "Context Group Content";
10058 + contentWarningText = "Please assign min. 1\nsub-pattern";
10063 + nameLabel = "matching pattern name";
10064 + nameTitle = "Matching Pattern Name";
10065 + contentTitle = "Matching Pattern Content";
10066 + contentWarningText = "Please specify min. 1\nstring pattern";
10071 + ReadSymbolicFieldTextWidget(
10072 + MatchPatternDialog.mpdMatchPatternNameW,
10076 + if (name == NULL)
10080 + else if (*name == '\0')
10085 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10087 + "Please specify a valid name",
10089 + XmProcessTraversal(MatchPatternDialog.mpdMatchPatternNameW, XmTRAVERSE_CURRENT);
10095 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
10100 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10102 + contentWarningText,
10111 + !isStartPatternElementAvailable(&MatchPatternDialog.currentStringPatterns))
10116 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10118 + "Please specify min. 1 string pattern\nof type 'start'",
10126 + if (MatchPatternDialog.currentDmptElement != NULL &&
10127 + MatchPatternDialog.currentDmptElement->dmpteType == MPT_SUB &&
10128 + strcmp(MatchPatternDialog.currentDmptElement->dmpteName, name) != 0)
10130 + renameMatchPatternInAllGroups(
10131 + MatchPatternDialog.currentDmptElement->dmpteName,
10136 + (DialogMatchPatternSequenceElement *)XtMalloc(sizeof(DialogMatchPatternSequenceElement));
10138 + newSeq->dmpseName = name;
10139 + newSeq->dmpseValid = True;
10143 + newSeq->dmpseType = MPT_GROUP;
10146 + (DialogMatchPatternGroupElement *)XtMalloc(sizeof(DialogMatchPatternGroupElement));
10148 + newGroup->dmpgeName = XtNewString(name);
10150 + copyDialogPatternNamesToGroup(
10151 + &MatchPatternDialog.currentStringPatterns,
10154 + newSeq->dmpsePtr = (void *)newGroup;
10158 + if (XmToggleButtonGetState(MatchPatternDialog.mptbIndividualW))
10159 + newSeq->dmpseType = MPT_INDIVIDUAL;
10161 + newSeq->dmpseType = MPT_SUB;
10164 + (DialogMatchPatternTableElement *)XtMalloc(sizeof(DialogMatchPatternTableElement));
10166 + newElement->dmpteName = XtNewString(name);
10167 + newElement->dmpteType = newSeq->dmpseType;
10169 + newElement->dmpteSkipBtwnStartEnd =
10170 + XmToggleButtonGetState(MatchPatternDialog.gabSkipBtwStartEndW);
10172 + newElement->dmpteFlash =
10173 + XmToggleButtonGetState(MatchPatternDialog.gabFlashW);
10175 + newElement->dmpteIgnoreHighLightInfo =
10176 + !XmToggleButtonGetState(MatchPatternDialog.gabSyntaxBasedW);
10178 + copyDialogStringPatterns(
10179 + &MatchPatternDialog.currentStringPatterns,
10180 + &newElement->dmptePatterns);
10182 + newSeq->dmpsePtr = (void *)newElement;
10189 +** Check, if min. 1 string pattern of type 'start' is
10190 +** available within dialog.
10191 +** Returns True, if min. 1 start string pattern is
10192 +** populated in dialog.
10194 +static int isStartPatternElementAvailable(
10195 + DialogStringPatterns *dialogPatterns)
10199 + for (i=0; i < dialogPatterns->dspNumberOfPatterns; i++)
10201 + if (dialogPatterns->dspElements[i]->dspeKind == PEK_START)
10209 +** Read the string pattern fields of the string pattern frame and produce an
10210 +** allocated DialogStringPatternElement structure reflecting the contents.
10211 +** Pop up dialogs telling the user what's wrong (Passing "silent" as True,
10212 +** suppresses these dialogs).
10213 +** Returns NULL on error.
10215 +static DialogStringPatternElement *readStringPatternFrameFields(int silent)
10217 + char *stringPatText;
10218 + DialogStringPatternElement *newPatElement;
10219 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
10221 + if (isRelatedToGroup)
10223 + stringPatText = getSelectedSubPatternName();
10224 + if (strcmp(stringPatText, SPNM_NONE_SELECTED) == 0)
10229 + stringPatText = XtNewString(stringPatText);
10234 + XmTextGetString(MatchPatternDialog.mpdStringPatternW);
10236 + if (stringPatText == NULL)
10240 + else if (*stringPatText == '\0')
10245 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10246 + "String Pattern",
10247 + "Please specify string\npattern content",
10249 + XmProcessTraversal(MatchPatternDialog.mpdStringPatternW, XmTRAVERSE_CURRENT);
10251 + XtFree(stringPatText);
10256 + newPatElement = (DialogStringPatternElement *)XtMalloc(sizeof(DialogStringPatternElement));
10258 + newPatElement->dspeText = stringPatText;
10260 + if (isRelatedToGroup)
10262 + newPatElement->dspeKind = PEK_START;
10263 + newPatElement->dspeWordBoundary = PWB_NONE;
10264 + newPatElement->dspeCaseInsensitive = False;
10265 + newPatElement->dspeRegularExpression = False;
10269 + newPatElement->dspeRegularExpression =
10270 + XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
10272 + if (XmToggleButtonGetState(MatchPatternDialog.sptStartW))
10273 + newPatElement->dspeKind = PEK_START;
10274 + else if (XmToggleButtonGetState(MatchPatternDialog.sptMiddleW))
10275 + newPatElement->dspeKind = PEK_MIDDLE;
10277 + newPatElement->dspeKind = PEK_END;
10279 + if (newPatElement->dspeRegularExpression)
10280 + newPatElement->dspeWordBoundary = PWB_NONE;
10281 + else if (XmToggleButtonGetState(MatchPatternDialog.wbbBothW))
10282 + newPatElement->dspeWordBoundary = PWB_BOTH;
10283 + else if (XmToggleButtonGetState(MatchPatternDialog.wbbLeftW))
10284 + newPatElement->dspeWordBoundary = PWB_LEFT;
10285 + else if (XmToggleButtonGetState(MatchPatternDialog.wbbRightW))
10286 + newPatElement->dspeWordBoundary = PWB_RIGHT;
10288 + newPatElement->dspeWordBoundary = PWB_NONE;
10290 + newPatElement->dspeCaseInsensitive =
10291 + !XmToggleButtonGetState(MatchPatternDialog.sabCaseSensitiveW);
10294 + return newPatElement;
10298 +** Returns true if the pattern fields of the matching pattern dialog are set to
10299 +** the default ("New" pattern) state.
10301 +static int matchPatternDialogEmpty(void)
10304 + TextWidgetIsBlank(MatchPatternDialog.mpdMatchPatternNameW) &&
10305 + XmToggleButtonGetState(MatchPatternDialog.mptbIndividualW) &&
10306 + XmToggleButtonGetState(MatchPatternDialog.gabFlashW) &&
10307 + XmToggleButtonGetState(MatchPatternDialog.gabSyntaxBasedW) &&
10308 + stringPatternFrameEmpty();
10312 +** Returns true if the string pattern frame of the matching pattern dialog is set to
10313 +** the default state.
10315 +static int stringPatternFrameEmpty(void)
10318 + stringPatternFieldsEmpty(False) &&
10319 + MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0;
10323 +** Returns true if the string pattern fields of the string pattern frame are set to
10324 +** the default state.
10326 +static int stringPatternFieldsEmpty(
10327 + int strPatIsRelatedToGroup)
10329 + if (strPatIsRelatedToGroup)
10332 + strcmp( getSelectedSubPatternName(), SPNM_NONE_SELECTED ) == 0);
10337 + TextWidgetIsBlank(MatchPatternDialog.mpdStringPatternW) &&
10338 + XmToggleButtonGetState(MatchPatternDialog.wbbBothW) &&
10339 + XmToggleButtonGetState(MatchPatternDialog.sabCaseSensitiveW) &&
10340 + !XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
10345 +** Get the current content of the matching pattern dialog.
10346 +** If the matching pattern is o.k., then update & apply it
10347 +** to any window which is currently using the matching pattern.
10348 +** If it's bad, then only report it.
10350 +static int getAndUpdateStringMatchTable(void)
10352 + StringMatchTable *newTable;
10353 + DMPTranslationResult translResult;
10356 + * Get the current information displayed by the dialog. If it's bad,
10357 + * report it to the user & return.
10359 + newTable = getDialogStringMatchTable(&translResult);
10361 + if (newTable == NULL && translResult != DMPTR_EMPTY)
10364 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10365 + "Incomplete Matching Patterns for Language Mode",
10366 + "Incomplete matching patterns for language mode '%s'.\n"
10367 + "Please complete them first",
10369 + MatchPatternDialog.mpdLangModeName);
10375 + * change the matching pattern
10377 + updateStringMatchTable( newTable );
10383 +** Update the matching pattern set being edited in the matching pattern dialog
10384 +** with the information that the dialog is currently displaying, and
10385 +** apply changes to any window which is currently using the matching pattern.
10387 +static void updateStringMatchTable(
10388 + StringMatchTable *newTable)
10390 + WindowInfo *window;
10394 + * Find the matching pattern being modified
10396 + for (i=0; i<NbrMatchTables; i++)
10398 + if (!strcmp(MatchPatternDialog.mpdLangModeName, MatchTables[i]->smtLanguageMode))
10401 + * replace existing matching pattern
10403 + freeStringMatchTable(MatchTables[i]);
10404 + MatchTables[i] = newTable;
10409 + if (i == NbrMatchTables)
10412 + * new match table for language mode -> add it to end
10414 + MatchTables[NbrMatchTables++] = newTable;
10418 + * Find windows that are currently using this matching pattern set and
10419 + * update this windows
10421 + for (window=WindowList; window!=NULL; window=window->next)
10423 + if ((window->languageMode == PLAIN_LANGUAGE_MODE &&
10424 + !strcmp(PLAIN_LM_STRING, newTable->smtLanguageMode)) ||
10425 + (window->languageMode != PLAIN_LANGUAGE_MODE &&
10426 + !strcmp(LanguageModeName(window->languageMode), newTable->smtLanguageMode)))
10428 + window->stringMatchTable = newTable;
10433 + * Note that preferences have been changed
10435 + MarkPrefsChanged();
10438 +static StringMatchTable *getDialogStringMatchTable(
10439 + DMPTranslationResult *result)
10441 + int matchPatListIdx =
10442 + ManagedListSelectedIndex(MatchPatternDialog.mpdMatchPatternNamesListW);
10443 + int stringPatListIdx =
10444 + ManagedListSelectedIndex(MatchPatternDialog.mpdStringPatternsListW);
10447 + * Get the current content of the matching pattern dialog fields
10449 + if (!UpdateManagedList(MatchPatternDialog.mpdStringPatternsListW, True))
10451 + *result = DMPTR_INCOMPLETE;
10456 + if (!UpdateManagedList(MatchPatternDialog.mpdMatchPatternNamesListW, True))
10458 + *result = DMPTR_INCOMPLETE;
10463 + SelectManagedListItem(MatchPatternDialog.mpdMatchPatternNamesListW, matchPatListIdx);
10464 + SelectManagedListItem(MatchPatternDialog.mpdStringPatternsListW, stringPatListIdx);
10467 + * Translate dialog match table to string match table
10469 + return translateDialogStringMatchTable(&MatchPatternDialog.mpdTable, result);
10472 +static StringMatchTable *translateDialogStringMatchTable(
10473 + DialogMatchPatternInfo *dialogTable,
10474 + DMPTranslationResult *result)
10476 + ReadMatchPatternInfo readPatInfo;
10477 + DialogMatchPatternSequenceElement *seq;
10478 + MatchPatternTableElement *newPatElement;
10479 + MatchPatternGroupElement *newGroupElement;
10481 + ErrorInfo errInfo;
10484 + initErrorInfo(&errInfo);
10486 + readPatInfo.rmpiNbrOfElements = 0;
10487 + readPatInfo.rmpiNbrOfGroups = 0;
10488 + readPatInfo.rmpiNbrOfSeqElements = 0;
10489 + readPatInfo.rmpiAllPatRE = NULL;
10490 + readPatInfo.rmpiFlashPatRE = NULL;
10493 + * if no dialog patterns are defined, return "empty" table
10495 + if (dialogTable->dmpiNbrOfSeqElements == 0)
10497 + *result = DMPTR_EMPTY;
10499 + return createStringMatchTable(
10501 + XtNewString(MatchPatternDialog.mpdLangModeName));
10505 + * translate dialog matching pattern elements
10507 + for (i=0; i < dialogTable->dmpiNbrOfSeqElements; i++)
10509 + seq = dialogTable->dmpiSequence[i];
10511 + if (seq->dmpseType == MPT_GROUP)
10513 + newGroupElement =
10514 + translateDialogMatchPatternGroupElement(
10516 + (DialogMatchPatternGroupElement *)seq->dmpsePtr);
10518 + if (newGroupElement == NULL)
10520 + freeReadMatchPatternInfo(&readPatInfo);
10522 + *result = DMPTR_INCOMPLETE;
10527 + readPatInfo.rmpiGroup[readPatInfo.rmpiNbrOfGroups ++] =
10530 + recordPatternSequence(
10534 + readPatInfo.rmpiNbrOfGroups-1 );
10539 + translateDialogMatchPatternTableElement(
10540 + (DialogMatchPatternTableElement *)seq->dmpsePtr);
10542 + newPatElement->mpteIndex = readPatInfo.rmpiNbrOfElements;
10544 + readPatInfo.rmpiElement[readPatInfo.rmpiNbrOfElements ++] =
10547 + if (newPatElement->mpteType == MPT_INDIVIDUAL)
10549 + if (!assignIndividualGroup(&readPatInfo, &errMsg, newPatElement))
10552 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10553 + "Assign reg. exp.",
10554 + "%s\n(Pattern: '%s')",
10557 + newPatElement->mpteName);
10559 + freeReadMatchPatternInfo(&readPatInfo);
10561 + *result = DMPTR_INCOMPLETE;
10567 + treatDuplicatedMTEntries(readPatInfo.rmpiElement, readPatInfo.rmpiNbrOfElements);
10569 + recordPatternSequence(
10573 + newPatElement->mpteIndex );
10578 + * compile reg. expressions of "read" patterns
10580 + if (createRegExpOfPatterns( &readPatInfo, &errInfo ))
10582 + errInfo.eiLanguageMode = XtNewString(MatchPatternDialog.mpdLangModeName);
10583 + dialogMatchingPatternSetError(
10584 + "Assign all patterns reg. exp.",
10587 + freeReadMatchPatternInfo(&readPatInfo);
10589 + *result = DMPTR_INCOMPLETE;
10594 + *result = DMPTR_OK;
10596 + return createStringMatchTable(
10598 + XtNewString(MatchPatternDialog.mpdLangModeName));
10601 +static MatchPatternTableElement *translateDialogMatchPatternTableElement(
10602 + DialogMatchPatternTableElement *dialogElement)
10604 + MatchPatternTableElement *newElement;
10607 + (MatchPatternTableElement *)XtMalloc(sizeof(MatchPatternTableElement));
10609 + newElement->mpteName = XtNewString(dialogElement->dmpteName);
10610 + newElement->mpteIndex = NO_ELEMENT_IDX;
10611 + newElement->mpteType = dialogElement->dmpteType;
10612 + newElement->mpteGroup = NO_GROUP_IDX;
10614 + translateDialogPatterns(&dialogElement->dmptePatterns, newElement);
10616 + newElement->mpteSkipBtwnStartEnd = dialogElement->dmpteSkipBtwnStartEnd;
10617 + newElement->mpteFlash = dialogElement->dmpteFlash;
10618 + newElement->mpteIgnoreHighLightInfo = dialogElement->dmpteIgnoreHighLightInfo;
10619 + newElement->mpteStartEndRE = NULL;
10621 + initGlobalBackRefList( newElement->mpteGlobalBackRef );
10623 + return newElement;
10626 +static void translateDialogPatterns(
10627 + DialogStringPatterns *dialogPatterns,
10628 + MatchPatternTableElement *newElement)
10634 + * allocate memory for patterns
10636 + newElement->mpteAll.pesNumberOfPattern = dialogPatterns->dspNumberOfPatterns;
10639 + sizeof(PatternElement *) * dialogPatterns->dspNumberOfPatterns;
10641 + newElement->mpteAll.pesPattern = (PatternElement **)XtMalloc(sizeOfPat);
10644 + * assign dialog patterns to patterns of MatchPatternTableElement
10646 + for (i=0; i < dialogPatterns->dspNumberOfPatterns; i++)
10648 + newElement->mpteAll.pesPattern[i] =
10649 + createPatternElement(
10650 + XtNewString(dialogPatterns->dspElements[i]->dspeText),
10651 + dialogPatterns->dspElements[i]->dspeKind,
10652 + dialogPatterns->dspElements[i]->dspeWordBoundary,
10653 + dialogPatterns->dspElements[i]->dspeCaseInsensitive,
10654 + dialogPatterns->dspElements[i]->dspeRegularExpression);
10656 + newElement->mpteAll.pesPattern[i]->peIndex = i;
10660 + * sort pattern elements into start, middle & end arrays
10662 + sortDialogPatternElementSet( &newElement->mpteAll, newElement );
10665 + * determine mono pattern
10667 + if (newElement->mpteEnd.pesNumberOfPattern == 0)
10669 + newElement->mpteIsMonoPattern = True;
10671 + copyPatternSet( &newElement->mpteStart, &newElement->mpteEnd );
10675 + newElement->mpteIsMonoPattern = False;
10680 + * Sort dialog pattern element set into start, middle & end arrays.
10682 +static void sortDialogPatternElementSet(
10683 + PatternElementSet *allPat,
10684 + MatchPatternTableElement *result)
10689 + * count number of start, middle & end pattern elements
10691 + countPatternElementKind( allPat, result );
10694 + * allocate pattern elements
10696 + sizeOfPat = sizeof(PatternElement *) * result->mpteStart.pesNumberOfPattern;
10697 + result->mpteStart.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
10699 + if (result->mpteMiddle.pesNumberOfPattern != 0)
10701 + sizeOfPat = sizeof(PatternElement *) * result->mpteMiddle.pesNumberOfPattern;
10702 + result->mpteMiddle.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
10705 + if (result->mpteEnd.pesNumberOfPattern != 0)
10707 + sizeOfPat = sizeof(PatternElement *) * result->mpteEnd.pesNumberOfPattern;
10708 + result->mpteEnd.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
10712 + * sort pattern elements into start, middle & end arrays
10714 + sortPatternElementSet( allPat, result );
10717 +static MatchPatternGroupElement *translateDialogMatchPatternGroupElement(
10718 + ReadMatchPatternInfo *info,
10719 + DialogMatchPatternGroupElement *dialogGroup)
10722 + int error = False;
10723 + MatchPatternTableElement *subPatElement;
10725 + MatchPatternGroupElement *group;
10728 + * Allocate memory for the matching pattern group. Copy name & number of
10732 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
10734 + group->mpgeName = XtNewString(dialogGroup->dmpgeName);
10735 + group->mpgeNumberOfSubPatterns = dialogGroup->dmpgeNumberOfSubPatterns;
10736 + group->mpgeKeywordRE = NULL;
10739 + * Allocate memory for the sub-matching pattern IDs
10741 + sizeOfIds = sizeof(char *) * group->mpgeNumberOfSubPatterns;
10742 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeOfIds );
10744 + for (i=0; i < group->mpgeNumberOfSubPatterns; i ++)
10747 + * Remember sub-matching pattern ID
10749 + group->mpgeSubPatternIds[i] = XtNewString(dialogGroup->dmpgeSubPatternIds[i]);
10752 + * Assign the index of this group to the sub-matching pattern
10753 + * if no group index was assigned before.
10756 + getPatternOfName( info, dialogGroup->dmpgeSubPatternIds[i]);
10758 + if (subPatElement == NULL)
10761 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10762 + "Group Compilation",
10763 + "Group '%s':\nsub-matching pattern '%s' not defined before",
10766 + dialogGroup->dmpgeSubPatternIds[i]);
10772 + if (subPatElement->mpteGroup == NO_GROUP_IDX)
10774 + subPatElement->mpteGroup = info->rmpiNbrOfGroups;
10781 + freeMatchPatternGroupElement(group);
10789 +static int stringMatchTableDiffer(
10790 + StringMatchTable *oldTable,
10791 + StringMatchTable *newTable)
10794 + MatchPatternTable *oldPatTab = oldTable->smtAllPatterns;
10795 + MatchPatternTable *newPatTab = newTable->smtAllPatterns;
10796 + MatchPatternTableElement *oldPat;
10797 + MatchPatternTableElement *newPat;
10798 + MatchPatternGroupElement *oldGroup;
10799 + MatchPatternGroupElement *newGroup;
10800 + MatchPatternSequenceElement *oldSeq;
10801 + MatchPatternSequenceElement *newSeq;
10803 + if (oldTable->smtNumberOfSeqElements != newTable->smtNumberOfSeqElements)
10806 + for (i=0; i < oldTable->smtNumberOfSeqElements; i++)
10808 + oldSeq = oldTable->smtSequence[i];
10809 + newSeq = newTable->smtSequence[i];
10811 + if (AllocatedStringsDiffer(oldSeq->mpseName, newSeq->mpseName))
10813 + if (oldSeq->mpseType != newSeq->mpseType)
10816 + if (oldSeq->mpseType == MPT_GROUP)
10818 + oldGroup = oldTable->smtGroups[oldSeq->mpseIndex];
10819 + newGroup = newTable->smtGroups[newSeq->mpseIndex];
10821 + if (AllocatedStringsDiffer(oldGroup->mpgeName, newGroup->mpgeName))
10824 + if (oldGroup->mpgeNumberOfSubPatterns != newGroup->mpgeNumberOfSubPatterns)
10827 + for (j=0; j < oldGroup->mpgeNumberOfSubPatterns; j++)
10829 + if (AllocatedStringsDiffer(
10830 + oldGroup->mpgeSubPatternIds[j],
10831 + newGroup->mpgeSubPatternIds[j]))
10837 + oldPat = oldPatTab->mptElements[oldSeq->mpseIndex];
10838 + newPat = newPatTab->mptElements[newSeq->mpseIndex];
10840 + if (AllocatedStringsDiffer(oldPat->mpteName, newPat->mpteName))
10843 + if (oldPat->mpteType != newPat->mpteType)
10846 + if (oldPat->mpteGroup != newPat->mpteGroup)
10849 + if (oldPat->mpteAll.pesNumberOfPattern != newPat->mpteAll.pesNumberOfPattern)
10852 + for (j=0; j < oldPat->mpteAll.pesNumberOfPattern; j ++)
10854 + if (patternElementDiffer(
10855 + oldPat->mpteAll.pesPattern[j], oldPatTab,
10856 + newPat->mpteAll.pesPattern[j], newPatTab ) )
10860 + if (oldPat->mpteIsMonoPattern != newPat->mpteIsMonoPattern)
10863 + if (oldPat->mpteSkipBtwnStartEnd != newPat->mpteSkipBtwnStartEnd)
10866 + if (oldPat->mpteIgnoreHighLightInfo != newPat->mpteIgnoreHighLightInfo)
10869 + if (oldPat->mpteFlash != newPat->mpteFlash)
10877 +static int patternElementDiffer(
10878 + PatternElement *oldPE,
10879 + MatchPatternTable *oldTab,
10880 + PatternElement *newPE,
10881 + MatchPatternTable *newTab)
10883 + StringPattern *oldSP;
10884 + StringPattern *newSP;
10886 + oldSP = GetStringPattern(oldTab, oldPE);
10887 + newSP = GetStringPattern(newTab, newPE);
10889 + if (AllocatedStringsDiffer(oldSP->spText, newSP->spText))
10891 + if (AllocatedStringsDiffer(oldSP->spOrigText, newSP->spOrigText))
10893 + if (oldPE->peKind != newPE->peKind)
10895 + if (oldSP->spWordBoundary != newSP->spWordBoundary)
10897 + if (oldSP->spCaseInsensitive != newSP->spCaseInsensitive)
10899 + if (oldSP->spRegularExpression != newSP->spRegularExpression)
10905 +static DialogMatchPatternGroupElement *getDialogGroupUsingMatchPattern(
10906 + char *matchPatternName)
10908 + DialogMatchPatternSequenceElement *seq;
10909 + DialogMatchPatternGroupElement *group;
10912 + for (i=0; i < MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i ++)
10914 + seq = MatchPatternDialog.mpdTable.dmpiSequence[i];
10916 + if (seq->dmpseType == MPT_GROUP)
10918 + group = (DialogMatchPatternGroupElement *)seq->dmpsePtr;
10920 + for (j=0; j < group->dmpgeNumberOfSubPatterns; j ++)
10922 + if (strcmp(group->dmpgeSubPatternIds[j], matchPatternName) == 0)
10931 +static void removeMatchPatternFromGroup(
10932 + char *matchPatternName,
10933 + DialogMatchPatternGroupElement *group)
10937 + for (i=0; i < group->dmpgeNumberOfSubPatterns; i ++)
10939 + if (strcmp(group->dmpgeSubPatternIds[i], matchPatternName) == 0)
10942 + * remove existing matching pattern name from sub-pattern list
10944 + freeXtPtr((void **)&group->dmpgeSubPatternIds[i]);
10946 + &group->dmpgeSubPatternIds[i],
10947 + &group->dmpgeSubPatternIds[i+1],
10948 + (group->dmpgeNumberOfSubPatterns-1 - i) * sizeof(char *));
10949 + group->dmpgeNumberOfSubPatterns --;
10956 +static void removeMatchPatternFromAllGroups(
10957 + char *matchPatternName)
10959 + DialogMatchPatternSequenceElement *seq;
10960 + DialogMatchPatternGroupElement *group;
10963 + for (i=0; i < MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i ++)
10965 + seq = MatchPatternDialog.mpdTable.dmpiSequence[i];
10967 + if (seq->dmpseType == MPT_GROUP)
10969 + group = (DialogMatchPatternGroupElement *)seq->dmpsePtr;
10971 + removeMatchPatternFromGroup(matchPatternName, group);
10976 +static void renameMatchPatternInGroup(
10977 + char *oldMatchPatternName,
10978 + char *newMatchPatternName,
10979 + DialogMatchPatternGroupElement *group)
10983 + for (i=0; i < group->dmpgeNumberOfSubPatterns; i ++)
10985 + if (strcmp(group->dmpgeSubPatternIds[i], oldMatchPatternName) == 0)
10988 + * rename existing matching pattern name in sub-pattern list
10990 + freeXtPtr((void **)&group->dmpgeSubPatternIds[i]);
10992 + group->dmpgeSubPatternIds[i] =
10993 + XtNewString(newMatchPatternName);
11000 +static void renameMatchPatternInAllGroups(
11001 + char *oldMatchPatternName,
11002 + char *newMatchPatternName)
11004 + DialogMatchPatternSequenceElement *seq;
11005 + DialogMatchPatternGroupElement *group;
11008 + for (i=0; i < MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i ++)
11010 + seq = MatchPatternDialog.mpdTable.dmpiSequence[i];
11012 + if (seq->dmpseType == MPT_GROUP)
11014 + group = (DialogMatchPatternGroupElement *)seq->dmpsePtr;
11016 + renameMatchPatternInGroup(
11017 + oldMatchPatternName,
11018 + newMatchPatternName,
11024 +static void freeVariableDialogData(
11025 + int keepLanguageModeName)
11029 + if (!keepLanguageModeName)
11030 + freeXtPtr((void **)&MatchPatternDialog.mpdLangModeName);
11032 + for (i=0; i < MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i ++)
11034 + freeDialogSequenceElement(
11035 + MatchPatternDialog.mpdTable.dmpiSequence[i] );
11038 + MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements = 0;
11040 + freeDialogStringPatterns(
11041 + &MatchPatternDialog.currentStringPatterns);
11044 +static void initGlobalBackRefList(
11045 + GlobalBackRefElement *list)
11049 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
11051 + list[i].gbreDefByStrPat = NULL;
11052 + list[i].gbreRegExpText = NULL;
11056 +static void initStrPatBackRefList(
11057 + StringPattern *strPat)
11061 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
11063 + strPat->spOwnGlobalBackRef[i].spbreRegExpText = NULL;
11064 + strPat->spOwnGlobalBackRef[i].spbreLocalBackRefID = NO_LOCAL_BACK_REF_ID;
11066 + strPat->spGlobalToLocalBackRef[i] = NO_LOCAL_BACK_REF_ID;
11070 +static void initErrorInfo(
11071 + ErrorInfo *errInfo)
11073 + errInfo->eiDetail = NULL;
11074 + errInfo->eiLanguageMode = NULL;
11075 + errInfo->eiMPTabElementName = NULL;
11076 + errInfo->eiStringPatText = NULL;
11077 + errInfo->eiRegExpCompileMsg = NULL;
11078 + errInfo->eiBackRefNbr = 0;
11081 +static void freeErrorInfo(
11082 + ErrorInfo *errInfo)
11084 + freeXtPtr((void **)&errInfo->eiLanguageMode);
11085 + freeXtPtr((void **)&errInfo->eiMPTabElementName);
11086 + freeXtPtr((void **)&errInfo->eiStringPatText);
11089 +static void freeXtPtr(void **ptr)
11091 + if (*ptr != NULL)
11093 + XtFree((char *)*ptr);
11098 +static void freePtr(void **ptr)
11100 + if (*ptr != NULL)
11102 + free((char *)*ptr);
11106 diff --quilt /dev/null new/source/patternMatchData.h
11108 +++ new/source/patternMatchData.h
11110 +/* $Id: patternMatchData.h,v 1.3 2003/12/12 16:45:25 uleh Exp $ */
11112 +#ifndef NEDIT_PATTERNMATCHDATA_H_INCLUDED
11113 +#define NEDIT_PATTERNMATCHDATA_H_INCLUDED
11115 +void *FindStringMatchTable(const char *langModeName);
11117 +void RenameStringMatchTable(const char *oldName, const char *newName);
11119 +void DeleteStringMatchTable(const char *langModeName);
11121 +void AssignStandardStringMatchTable(const char *langModeName);
11123 +int LMHasStringMatchTable(const char *languageMode);
11125 +int LoadMatchPatternString(char *inString);
11127 +char *WriteMatchPatternString(void);
11129 +void EditMatchPatterns(WindowInfo *window);
11131 +void UpdateLanguageModeMenuMatchPattern(void);
11133 +#endif /* NEDIT_PATTERNMATCHDATA_H_INCLUDED */
11134 diff --quilt old/source/preferences.c new/source/preferences.c
11135 --- old/source/preferences.c
11136 +++ new/source/preferences.c
11137 @@ -45,10 +45,14 @@ static const char CVSID[] = "$Id: prefer
11138 #include "regularExp.h"
11139 #include "smartIndent.h"
11140 #include "windowTitle.h"
11141 #include "server.h"
11144 +/* Pattern Match Feature */
11145 +#include "patternMatchData.h"
11147 #include "../util/prefFile.h"
11148 #include "../util/misc.h"
11149 #include "../util/DialogF.h"
11150 #include "../util/managedList.h"
11151 #include "../util/fontsel.h"
11152 @@ -277,11 +281,10 @@ static struct prefData {
11153 int textCols; /* initial window width in characters */
11154 int tabDist; /* number of characters between tab stops */
11155 int emTabDist; /* non-zero tab dist. if emulated tabs are on */
11156 int insertTabs; /* whether to use tabs for padding */
11157 int showMatchingStyle; /* how to flash matching parenthesis */
11158 - int matchSyntaxBased; /* use syntax info to match parenthesis */
11159 int highlightSyntax; /* whether to highlight syntax by default */
11160 int smartTags; /* look for tag in current window first */
11161 int alwaysCheckRelativeTagsSpecs; /* for every new opened file of session */
11162 int stickyCaseSenseBtn; /* whether Case Word Btn is sticky to Regex Btn */
11163 int prefFileRead; /* detects whether a .nedit existed */
11164 @@ -348,10 +351,11 @@ static struct {
11168 char *smartIndentCommon;
11170 + char *matchPattern;
11173 /* preference descriptions for SavePreferences and RestorePreferences. */
11174 static PrefDescripRec PrefDescrip[] = {
11175 {"fileVersion", "FileVersion" , PREF_STRING, "", PrefData.fileVersion,
11176 @@ -853,10 +857,76 @@ static PrefDescripRec PrefDescrip[] = {
11179 Matlab:Default", &TempStringPrefs.smartIndent, NULL, True},
11180 {"smartIndentInitCommon", "SmartIndentInitCommon", PREF_ALLOC_STRING,
11181 "Default", &TempStringPrefs.smartIndentCommon, NULL, True},
11182 +/* Pattern Match Feature: matchPatterns resource added */
11184 +/* The VAX compiler can't compile Java-Script's definition in highlightData.c */
11185 + {"matchPatterns", "MatchPatterns", PREF_ALLOC_STRING,
11186 + "PLAIN:Default\n\
11193 + Fortran:Default\n\
11197 + Makefile:Default\n\
11198 + Matlab:Default\n\
11199 + NEdit Macro:Default\n\
11200 + Pascal:Default\n\
11202 + PostScript:Default\n\
11203 + Python:Default\n\
11205 + SGML HTML:Default\n\
11207 + Sh Ksh Bash:Default\n\
11210 + Verilog:Default\n\
11212 + X Resources:Default\n\
11214 + &TempStringPrefs.matchPattern, NULL, True},
11216 + {"matchPatterns", "MatchPatterns", PREF_ALLOC_STRING,
11217 + "PLAIN:Default\n\
11224 + Fortran:Default\n\
11226 + JavaScript:Default\n\
11229 + Makefile:Default\n\
11230 + Matlab:Default\n\
11231 + NEdit Macro:Default\n\
11232 + Pascal:Default\n\
11234 + PostScript:Default\n\
11235 + Python:Default\n\
11237 + SGML HTML:Default\n\
11239 + Sh Ksh Bash:Default\n\
11242 + Verilog:Default\n\
11244 + X Resources:Default\n\
11246 + &TempStringPrefs.matchPattern, NULL, True},
11248 {"autoWrap", "AutoWrap", PREF_ENUM, "Continuous",
11249 &PrefData.wrapStyle, AutoWrapTypes, True},
11250 {"wrapMargin", "WrapMargin", PREF_INT, "0",
11251 &PrefData.wrapMargin, NULL, True},
11252 {"showWrapMargin", "ShowWrapMargin", PREF_ENUM, "Never",
11253 @@ -869,12 +939,10 @@ static PrefDescripRec PrefDescrip[] = {
11254 &PrefData.openInTab, NULL, True},
11255 {"saveOldVersion", "SaveOldVersion", PREF_BOOLEAN, "False",
11256 &PrefData.saveOldVersion, NULL, True},
11257 {"showMatching", "ShowMatching", PREF_ENUM, "Delimiter",
11258 &PrefData.showMatchingStyle, ShowMatchingTypes, True},
11259 - {"matchSyntaxBased", "MatchSyntaxBased", PREF_BOOLEAN, "True",
11260 - &PrefData.matchSyntaxBased, NULL, True},
11261 {"highlightSyntax", "HighlightSyntax", PREF_BOOLEAN, "True",
11262 &PrefData.highlightSyntax, NULL, True},
11263 {"backlightChars", "BacklightChars", PREF_BOOLEAN, "False",
11264 &PrefData.backlightChars, NULL, True},
11265 {"backlightCharTypes", "BacklightCharTypes", PREF_ALLOC_STRING,
11266 @@ -1245,10 +1313,11 @@ static void lmDestroyCB(Widget w, XtPoin
11267 static void lmOkCB(Widget w, XtPointer clientData, XtPointer callData);
11268 static void lmApplyCB(Widget w, XtPointer clientData, XtPointer callData);
11269 static void lmCloseCB(Widget w, XtPointer clientData, XtPointer callData);
11270 static int lmDeleteConfirmCB(int itemIndex, void *cbArg);
11271 static int updateLMList(void);
11272 +static int isOldLanguageMode(const char *lmDialogName, const char *oldModeName);
11273 static languageModeRec *copyLanguageModeRec(languageModeRec *lm);
11274 static void *lmGetDisplayedCB(void *oldItem, int explicitRequest, int *abort,
11276 static void lmSetDisplayedCB(void *item, void *cbArg);
11277 static languageModeRec *readLMDialogFields(int silent);
11278 @@ -1432,10 +1501,15 @@ static void translatePrefFormats(int con
11279 if (TempStringPrefs.smartIndentCommon != NULL) {
11280 LoadSmartIndentCommonString(TempStringPrefs.smartIndentCommon);
11281 XtFree(TempStringPrefs.smartIndentCommon);
11282 TempStringPrefs.smartIndentCommon = NULL;
11284 + if (TempStringPrefs.matchPattern != NULL) {
11285 + LoadMatchPatternString(TempStringPrefs.matchPattern);
11286 + XtFree(TempStringPrefs.matchPattern);
11287 + TempStringPrefs.matchPattern = NULL;
11290 /* translate the font names into fontLists suitable for the text widget */
11291 font = XLoadQueryFont(TheDisplay, PrefData.fontString);
11292 PrefData.fontList = font==NULL ? NULL :
11293 XmFontListCreate(font, XmSTRING_DEFAULT_CHARSET);
11294 @@ -1511,10 +1585,11 @@ void SaveNEditPrefs(Widget parent, int q
11295 TempStringPrefs.highlight = WriteHighlightString();
11296 TempStringPrefs.language = writeLanguageModesString();
11297 TempStringPrefs.styles = WriteStylesString();
11298 TempStringPrefs.smartIndent = WriteSmartIndentString();
11299 TempStringPrefs.smartIndentCommon = WriteSmartIndentCommonString();
11300 + TempStringPrefs.matchPattern = WriteMatchPatternString();
11301 strcpy(PrefData.fileVersion, PREF_FILE_VERSION);
11303 if (!SavePreferences(XtDisplay(parent), prefFileName, HeaderText,
11304 PrefDescrip, XtNumber(PrefDescrip)))
11306 @@ -1530,10 +1605,11 @@ void SaveNEditPrefs(Widget parent, int q
11307 XtFree(TempStringPrefs.highlight);
11308 XtFree(TempStringPrefs.language);
11309 XtFree(TempStringPrefs.styles);
11310 XtFree(TempStringPrefs.smartIndent);
11311 XtFree(TempStringPrefs.smartIndentCommon);
11312 + XtFree(TempStringPrefs.matchPattern);
11314 PrefsHaveChanged = False;
11318 @@ -1926,20 +2002,10 @@ int GetPrefShowMatching(void)
11319 if (PrefData.showMatchingStyle >= N_SHOW_MATCHING_STYLES)
11320 PrefData.showMatchingStyle -= N_SHOW_MATCHING_STYLES;
11321 return PrefData.showMatchingStyle;
11324 -void SetPrefMatchSyntaxBased(int state)
11326 - setIntPref(&PrefData.matchSyntaxBased, state);
11329 -int GetPrefMatchSyntaxBased(void)
11331 - return PrefData.matchSyntaxBased;
11334 void SetPrefHighlightSyntax(Boolean state)
11336 setIntPref(&PrefData.highlightSyntax, state);
11339 @@ -3496,10 +3562,25 @@ static int lmDeleteConfirmCB(int itemInd
11340 "Auto Indent -> Program Smart Indent,\n"
11341 "before proceeding here.", "OK");
11345 + /* Pattern Match Feature: don't allow deletion if data will be lost */
11346 + if (LMHasStringMatchTable(LMDialog.languageModeList[itemIndex]->name))
11348 + DialogF(DF_WARN, LMDialog.shell, 1, "Matching Patterns exist",
11349 + "This language mode has matching patterns\n"
11350 + "defined. Please delete the patterns first,\n"
11351 + "in Preferences -> Default Settings ->\n"
11352 + "Show Matching (..) -> Matching Patterns ..,\n"
11353 + "before proceeding here.", "Dismiss");
11357 + /* delete "empty" string match table related to language mode to be deleted */
11358 + DeleteStringMatchTable(LMDialog.languageModeList[itemIndex]->name);
11364 ** Apply the changes that the user has made in the language modes dialog to the
11365 @@ -3516,19 +3597,19 @@ static int updateLMList(void)
11366 /* Get the current contents of the dialog fields */
11367 if (!UpdateManagedList(LMDialog.managedListW, True))
11370 /* Fix up language mode indices in all open windows (which may change
11371 - if the currently selected mode is deleted or has changed position),
11372 - and update word delimiters */
11373 + if the currently selected mode is renamed, deleted or has changed
11374 + position), and update word delimiters */
11375 for (window=WindowList; window!=NULL; window=window->next) {
11376 if (window->languageMode != PLAIN_LANGUAGE_MODE) {
11377 oldLanguageMode = window->languageMode;
11378 oldModeName = LanguageModes[window->languageMode]->name;
11379 window->languageMode = PLAIN_LANGUAGE_MODE;
11380 for (i=0; i<LMDialog.nLanguageModes; i++) {
11381 - if (!strcmp(oldModeName, LMDialog.languageModeList[i]->name)) {
11382 + if (isOldLanguageMode(LMDialog.languageModeList[i]->name, oldModeName)) {
11383 newDelimiters = LMDialog.languageModeList[i]->delimiters;
11384 if (newDelimiters == NULL)
11385 newDelimiters = GetPrefDelimiters();
11386 XtVaSetValues(window->textArea, textNwordDelimiters,
11387 newDelimiters, NULL);
11388 @@ -3554,10 +3635,11 @@ static int updateLMList(void)
11389 if (strchr(LMDialog.languageModeList[i]->name, ':') != NULL) {
11390 char *newName = strrchr(LMDialog.languageModeList[i]->name, ':')+1;
11391 *strchr(LMDialog.languageModeList[i]->name, ':') = '\0';
11392 RenameHighlightPattern(LMDialog.languageModeList[i]->name, newName);
11393 RenameSmartIndentMacros(LMDialog.languageModeList[i]->name, newName);
11394 + RenameStringMatchTable(LMDialog.languageModeList[i]->name, newName);
11395 memmove(LMDialog.languageModeList[i]->name, newName,
11396 strlen(newName) + 1);
11397 ChangeManagedListData(LMDialog.managedListW);
11400 @@ -3571,31 +3653,62 @@ static int updateLMList(void)
11402 /* Update user menu info to update language mode dependencies of
11404 UpdateUserMenuInfo();
11406 + /* Pattern Match Feature: assign standard string match table to new
11407 + language modes */
11408 + for (i=0; i<NLanguageModes; i++) {
11409 + if (FindStringMatchTable(LanguageModeName(i)) == NULL)
11410 + AssignStandardStringMatchTable(LanguageModeName(i));
11413 /* Update the menus in the window menu bars and load any needed
11414 - calltips files */
11415 + calltips files and reassign string match tables */
11416 for (window=WindowList; window!=NULL; window=window->next) {
11417 updateLanguageModeSubmenu(window);
11418 if (window->languageMode != PLAIN_LANGUAGE_MODE &&
11419 LanguageModes[window->languageMode]->defTipsFile != NULL)
11420 AddTagsFile(LanguageModes[window->languageMode]->defTipsFile, TIP);
11422 + window->stringMatchTable =
11423 + FindStringMatchTable(LanguageModeName(window->languageMode));
11425 /* cache user menus: Rebuild all user menus of this window */
11426 RebuildAllMenus(window);
11429 /* If a syntax highlighting dialog is up, update its menu */
11430 UpdateLanguageModeMenu();
11431 /* The same for the smart indent macro dialog */
11432 UpdateLangModeMenuSmartIndent();
11433 + /* The same for the match pattern dialog */
11434 + UpdateLanguageModeMenuMatchPattern();
11435 /* Note that preferences have been changed */
11436 MarkPrefsChanged();
11442 +** Returns true, if the given old language mode name matches the
11443 +** given (new) language mode dialog name.
11445 +static int isOldLanguageMode(const char *lmDialogName, const char *oldModeName)
11447 + char *c = strchr(lmDialogName, ':');
11448 + int isOldMode = !strcmp(oldModeName, lmDialogName);
11450 + if (!isOldMode && c != NULL) {
11452 + isOldMode = !strcmp(lmDialogName, oldModeName);
11456 + return isOldMode;
11459 static void *lmGetDisplayedCB(void *oldItem, int explicitRequest, int *abort,
11462 languageModeRec *lm, *oldLM = (languageModeRec *)oldItem;
11464 @@ -4585,10 +4698,14 @@ static void reapplyLanguageMode(WindowIn
11465 /* Decref oldMode's default calltips file if needed */
11466 if (oldMode != PLAIN_LANGUAGE_MODE && LanguageModes[oldMode]->defTipsFile) {
11467 DeleteTagsFile( LanguageModes[oldMode]->defTipsFile, TIP, False );
11470 + /* Pattern Match Feature: Assign the match pattern related to
11471 + the language mode */
11472 + window->stringMatchTable = FindStringMatchTable(LanguageModeName(mode));
11474 /* Set delimiters for all text widgets */
11475 if (mode == PLAIN_LANGUAGE_MODE || LanguageModes[mode]->delimiters == NULL)
11476 delimiters = GetPrefDelimiters();
11478 delimiters = LanguageModes[mode]->delimiters;
11479 @@ -5202,18 +5319,35 @@ char *ReadSymbolicFieldTextWidget(Widget
11483 ** Create a pulldown menu pane with the names of the current language modes.
11484 ** XmNuserData for each item contains the language mode name.
11485 +** Pattern Match Feature: if "includePlain" is set, then 1st menu entry
11488 -Widget CreateLanguageModeMenu(Widget parent, XtCallbackProc cbProc, void *cbArg)
11489 +Widget CreateLanguageModeMenu(
11491 + XtCallbackProc cbProc,
11493 + int includePlain)
11499 menu = CreatePulldownMenu(parent, "languageModes", NULL, 0);
11501 + if (includePlain) {
11502 + btn = XtVaCreateManagedWidget("languageMode", xmPushButtonGadgetClass,
11504 + XmNlabelString, s1=XmStringCreateSimple("PLAIN"),
11505 + XmNmarginHeight, 0,
11506 + XmNuserData, (void *)"PLAIN", NULL);
11507 + XmStringFree(s1);
11508 + XtAddCallback(btn, XmNactivateCallback, cbProc, cbArg);
11511 for (i=0; i<NLanguageModes; i++) {
11512 btn = XtVaCreateManagedWidget("languageMode", xmPushButtonGadgetClass,
11514 XmNlabelString, s1=XmStringCreateSimple(LanguageModes[i]->name),
11515 XmNmarginHeight, 0,
11516 diff --quilt old/source/preferences.h new/source/preferences.h
11517 --- old/source/preferences.h
11518 +++ new/source/preferences.h
11519 @@ -109,12 +109,10 @@ void SetPrefEmTabDist(int tabDist);
11520 int GetPrefEmTabDist(int langMode);
11521 void SetPrefInsertTabs(int state);
11522 int GetPrefInsertTabs(void);
11523 void SetPrefShowMatching(int state);
11524 int GetPrefShowMatching(void);
11525 -void SetPrefMatchSyntaxBased(int state);
11526 -int GetPrefMatchSyntaxBased(void);
11527 void SetPrefHighlightSyntax(Boolean state);
11528 Boolean GetPrefHighlightSyntax(void);
11529 void SetPrefBacklightChars(int state);
11530 int GetPrefBacklightChars(void);
11531 void SetPrefBacklightCharTypes(char *types);
11532 @@ -189,11 +187,11 @@ int AllocatedStringsDiffer(const char *s
11533 void SetLanguageMode(WindowInfo *window, int mode, int forceNewDefaults);
11534 int FindLanguageMode(const char *languageName);
11535 void UnloadLanguageModeTipsFile(WindowInfo *window);
11536 void DetermineLanguageMode(WindowInfo *window, int forceNewDefaults);
11537 Widget CreateLanguageModeMenu(Widget parent, XtCallbackProc cbProc,
11539 + void *cbArg, int includePlain);
11540 void SetLangModeMenu(Widget optMenu, const char *modeName);
11541 void CreateLanguageModeSubMenu(WindowInfo* window, const Widget parent,
11542 const char* name, const char* label, const char mnemonic);
11543 void SetPrefFindReplaceUsesSelection(int state);
11544 int GetPrefFindReplaceUsesSelection(void);
11545 diff --quilt old/source/search.c new/source/search.c
11546 --- old/source/search.c
11547 +++ new/source/search.c
11548 @@ -83,10 +83,11 @@ static const char CVSID[] = "$Id: search
11550 #ifdef HAVE_DEBUG_H
11551 #include "../debug.h"
11554 +#include "patternMatch.h"
11558 typedef struct _SelectionInfo {
11560 @@ -171,10 +172,11 @@ static void freeWritableWindowsCB(Widget
11561 XmAnyCallbackStruct *callData);
11562 static void checkMultiReplaceListForDoomedW(WindowInfo* window,
11563 WindowInfo* doomedWindow);
11564 static void removeDoomedWindowFromList(WindowInfo* window, int index);
11565 static void unmanageReplaceDialogs(const WindowInfo *window);
11566 +static int getPosForMatchingCharacter(WindowInfo *window);
11567 static void flashTimeoutProc(XtPointer clientData, XtIntervalId *id);
11568 static void eraseFlash(WindowInfo *window);
11569 static int getReplaceDlogInfo(WindowInfo *window, int *direction,
11570 char *searchString, char *replaceString, int *searchType);
11571 static int getFindDlogInfo(WindowInfo *window, int *direction,
11572 @@ -211,13 +213,10 @@ static void downCaseString(char *outStri
11573 static void resetFindTabGroup(WindowInfo *window);
11574 static void resetReplaceTabGroup(WindowInfo *window);
11575 static int searchMatchesSelection(WindowInfo *window, const char *searchString,
11576 int searchType, int *left, int *right, int *searchExtentBW,
11577 int *searchExtentFW);
11578 -static int findMatchingChar(WindowInfo *window, char toMatch,
11579 - void *toMatchStyle, int charPos, int startLimit, int endLimit,
11581 static Boolean replaceUsingRE(const char* searchStr, const char* replaceStr,
11582 const char* sourceStr, int beginPos, char* destStr, int maxDestLen,
11583 int prevChar, const char* delimiters, int defaultFlags);
11584 static void saveSearchHistory(const char *searchString,
11585 const char *replaceString, int searchType, int isIncremental);
11586 @@ -251,28 +250,10 @@ typedef struct _charMatchTable {
11592 -#define N_MATCH_CHARS 13
11593 -#define N_FLASH_CHARS 6
11594 -static charMatchTable MatchingChars[N_MATCH_CHARS] = {
11595 - {'{', '}', SEARCH_FORWARD},
11596 - {'}', '{', SEARCH_BACKWARD},
11597 - {'(', ')', SEARCH_FORWARD},
11598 - {')', '(', SEARCH_BACKWARD},
11599 - {'[', ']', SEARCH_FORWARD},
11600 - {']', '[', SEARCH_BACKWARD},
11601 - {'<', '>', SEARCH_FORWARD},
11602 - {'>', '<', SEARCH_BACKWARD},
11603 - {'/', '/', SEARCH_FORWARD},
11604 - {'"', '"', SEARCH_FORWARD},
11605 - {'\'', '\'', SEARCH_FORWARD},
11606 - {'`', '`', SEARCH_FORWARD},
11607 - {'\\', '\\', SEARCH_FORWARD},
11611 ** Definitions for the search method strings, used as arguments for
11612 ** macro search subroutines and search action routines
11614 static char *searchTypeStrings[] = {
11615 @@ -3345,22 +3326,22 @@ static void iSearchTextKeyEH(Widget w, W
11616 XmTextSetInsertionPosition(window->iSearchText,
11617 XmTextGetLastPosition(window->iSearchText));
11621 -** Check the character before the insertion cursor of textW and flash
11622 -** matching parenthesis, brackets, or braces, by temporarily highlighting
11623 -** the matching character (a timer procedure is scheduled for removing the
11625 +** Check the characters before the insertion cursor of textW and flash
11626 +** matching patterns (parenthesis e.g. brackets, braces ..) by temporarily
11627 +** highlighting matching characters (a timer procedure is scheduled for
11628 +** removing the highlights)
11630 void FlashMatching(WindowInfo *window, Widget textW)
11634 - int pos, matchIndex;
11635 - int startPos, endPos, searchPos, matchPos;
11638 + int startPos, endPos, matchPos, matchLen;
11640 + MatchingType matchingType;
11642 /* if a marker is already drawn, erase it and cancel the timeout */
11643 if (window->flashTimeoutID != 0) {
11644 eraseFlash(window);
11645 XtRemoveTimeOut(window->flashTimeoutID);
11646 @@ -3374,52 +3355,47 @@ void FlashMatching(WindowInfo *window, W
11648 /* don't flash matching characters if there's a selection */
11649 if (window->buffer->primary.selected)
11652 - /* get the character to match and the position to start from */
11653 - pos = TextGetCursorPos(textW) - 1;
11654 + /* get the position to start from */
11655 + pos = TextGetCursorPos(textW);
11658 - c = BufGetCharacter(window->buffer, pos);
11659 - style = GetHighlightInfo(window, pos);
11661 - /* is the character one we want to flash? */
11662 - for (matchIndex = 0; matchIndex<N_FLASH_CHARS; matchIndex++) {
11663 - if (MatchingChars[matchIndex].c == c)
11666 - if (matchIndex == N_FLASH_CHARS)
11669 /* constrain the search to visible text only when in single-pane mode
11670 AND using delimiter flashing (otherwise search the whole buffer) */
11671 constrain = ((window->nPanes == 0) &&
11672 (window->showMatchingStyle == FLASH_DELIMIT));
11674 - if (MatchingChars[matchIndex].direction == SEARCH_BACKWARD) {
11675 startPos = constrain ? TextFirstVisiblePos(textW) : 0;
11677 - searchPos = endPos;
11680 endPos = constrain ? TextLastVisiblePos(textW) :
11681 window->buffer->length;
11682 - searchPos = startPos;
11684 + /* cursor pos. must be between start / end pos. */
11685 + if (pos < startPos || pos > endPos)
11688 + /* Pattern Match Feature: determine matching type
11689 + (here: flash delimiter or range) */
11690 + if (window->showMatchingStyle == FLASH_DELIMIT) {
11691 + matchingType = MT_FLASH_DELIMIT;
11693 + matchingType = MT_FLASH_RANGE;
11696 - /* do the search */
11697 - if (!findMatchingChar(window, c, style, searchPos, startPos, endPos,
11699 + /* Pattern Match Feature: do the search */
11700 + if (!FindMatchingString(window, matchingType, &pos, startPos, endPos,
11701 + &matchPos, &matchLen, &direction))
11704 if (window->showMatchingStyle == FLASH_DELIMIT) {
11705 - /* Highlight either the matching character ... */
11706 - BufHighlight(window->buffer, matchPos, matchPos+1);
11707 + /* Highlight either the matching characters ... */
11708 + BufHighlight(window->buffer, matchPos, matchPos + matchLen);
11710 /* ... or the whole range. */
11711 - if (MatchingChars[matchIndex].direction == SEARCH_BACKWARD) {
11712 + if (direction == SEARCH_BACKWARD) {
11713 BufHighlight(window->buffer, matchPos, pos+1);
11715 BufHighlight(window->buffer, matchPos+1, pos);
11718 @@ -3429,159 +3405,86 @@ void FlashMatching(WindowInfo *window, W
11719 XtWidgetToApplicationContext(window->shell), 1500,
11720 flashTimeoutProc, window);
11721 window->flashPos = matchPos;
11724 -void SelectToMatchingCharacter(WindowInfo *window)
11726 +** Pattern Match Feature:
11727 +** get position of the character to match from the selection, or
11728 +** the character before the insert point if nothing is selected.
11731 +static int getPosForMatchingCharacter(WindowInfo *window)
11734 int selStart, selEnd;
11735 - int startPos, endPos, matchPos;
11736 textBuffer *buf = window->buffer;
11738 - /* get the character to match and its position from the selection, or
11739 - the character before the insert point if nothing is selected.
11740 - Give up if too many characters are selected */
11741 - if (!GetSimpleSelection(buf, &selStart, &selEnd)) {
11742 - selEnd = TextGetCursorPos(window->lastFocus);
11743 - if (window->overstrike)
11745 - selStart = selEnd - 1;
11746 - if (selStart < 0) {
11747 - XBell(TheDisplay, 0);
11750 + if (GetSimpleSelection(buf, &selStart, &selEnd)) {
11753 - if ((selEnd - selStart) != 1) {
11754 - XBell(TheDisplay, 0);
11757 + pos = TextGetCursorPos(window->lastFocus);
11764 +void SelectToMatchingCharacter(WindowInfo *window)
11767 + int startPos, endPos, matchPos, matchLen;
11769 + textBuffer *buf = window->buffer;
11771 + /* Pattern Match Feature: get position of the character to match */
11772 + pos = getPosForMatchingCharacter( window );
11774 /* Search for it in the buffer */
11775 - if (!findMatchingChar(window, BufGetCharacter(buf, selStart),
11776 - GetHighlightInfo(window, selStart), selStart, 0, buf->length, &matchPos)) {
11777 + if (!FindMatchingString(window, MT_SELECT, &pos, 0,
11778 + buf->length, &matchPos, &matchLen, &direction)) {
11779 XBell(TheDisplay, 0);
11782 - startPos = (matchPos > selStart) ? selStart : matchPos;
11783 - endPos = (matchPos > selStart) ? matchPos : selStart;
11784 + startPos = (matchPos > pos) ? pos : matchPos;
11785 + endPos = (matchPos > pos) ? matchPos : pos;
11787 /* select the text between the matching characters */
11788 XtVaSetValues(window->lastFocus, textNautoShowInsertPos, False, NULL);
11789 BufSelect(buf, startPos, endPos+1);
11790 MakeSelectionVisible(window, window->lastFocus);
11791 XtVaSetValues(window->lastFocus, textNautoShowInsertPos, True, NULL);
11794 void GotoMatchingCharacter(WindowInfo *window)
11796 - int selStart, selEnd;
11799 + int matchPos, matchLen;
11801 textBuffer *buf = window->buffer;
11803 - /* get the character to match and its position from the selection, or
11804 - the character before the insert point if nothing is selected.
11805 - Give up if too many characters are selected */
11806 - if (!GetSimpleSelection(buf, &selStart, &selEnd)) {
11807 - selEnd = TextGetCursorPos(window->lastFocus);
11808 - if (window->overstrike)
11810 - selStart = selEnd - 1;
11811 - if (selStart < 0) {
11812 - XBell(TheDisplay, 0);
11816 - if ((selEnd - selStart) != 1) {
11817 - XBell(TheDisplay, 0);
11820 + /* Pattern Match Feature: get position of the character to match */
11821 + pos = getPosForMatchingCharacter( window );
11823 /* Search for it in the buffer */
11824 - if (!findMatchingChar(window, BufGetCharacter(buf, selStart),
11825 - GetHighlightInfo(window, selStart), selStart, 0,
11826 - buf->length, &matchPos)) {
11827 + if (!FindMatchingString(window, MT_GOTO, &pos, 0,
11828 + buf->length, &matchPos, &matchLen, &direction)) {
11829 XBell(TheDisplay, 0);
11833 /* temporarily shut off autoShowInsertPos before setting the cursor
11834 position so MakeSelectionVisible gets a chance to place the cursor
11835 string at a pleasing position on the screen (otherwise, the cursor would
11836 be automatically scrolled on screen and MakeSelectionVisible would do
11838 XtVaSetValues(window->lastFocus, textNautoShowInsertPos, False, NULL);
11839 - TextSetCursorPos(window->lastFocus, matchPos+1);
11840 + TextSetCursorPos(window->lastFocus, matchPos);
11841 MakeSelectionVisible(window, window->lastFocus);
11842 XtVaSetValues(window->lastFocus, textNautoShowInsertPos, True, NULL);
11845 -static int findMatchingChar(WindowInfo *window, char toMatch,
11846 - void* styleToMatch, int charPos, int startLimit, int endLimit,
11849 - int nestDepth, matchIndex, direction, beginPos, pos;
11850 - char matchChar, c;
11851 - void *style = NULL;
11852 - textBuffer *buf = window->buffer;
11853 - int matchSyntaxBased = window->matchSyntaxBased;
11855 - /* If we don't match syntax based, fake a matching style. */
11856 - if (!matchSyntaxBased) style = styleToMatch;
11858 - /* Look up the matching character and match direction */
11859 - for (matchIndex = 0; matchIndex<N_MATCH_CHARS; matchIndex++) {
11860 - if (MatchingChars[matchIndex].c == toMatch)
11863 - if (matchIndex == N_MATCH_CHARS)
11865 - matchChar = MatchingChars[matchIndex].match;
11866 - direction = MatchingChars[matchIndex].direction;
11868 - /* find it in the buffer */
11869 - beginPos = (direction==SEARCH_FORWARD) ? charPos+1 : charPos-1;
11871 - if (direction == SEARCH_FORWARD) {
11872 - for (pos=beginPos; pos<endLimit; pos++) {
11873 - c=BufGetCharacter(buf, pos);
11874 - if (c == matchChar) {
11875 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11876 - if (style == styleToMatch) {
11878 - if (nestDepth == 0) {
11883 - } else if (c == toMatch) {
11884 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11885 - if (style == styleToMatch)
11889 - } else { /* SEARCH_BACKWARD */
11890 - for (pos=beginPos; pos>=startLimit; pos--) {
11891 - c=BufGetCharacter(buf, pos);
11892 - if (c == matchChar) {
11893 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11894 - if (style == styleToMatch) {
11896 - if (nestDepth == 0) {
11901 - } else if (c == toMatch) {
11902 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11903 - if (style == styleToMatch)
11912 ** Xt timer procedure for erasing the matching parenthesis marker.
11914 static void flashTimeoutProc(XtPointer clientData, XtIntervalId *id)
11916 diff --quilt old/source/smartIndent.c new/source/smartIndent.c
11917 --- old/source/smartIndent.c
11918 +++ new/source/smartIndent.c
11919 @@ -978,13 +978,13 @@ void EditSmartIndentMacros(WindowInfo *w
11920 XmNleftPosition, 1,
11921 XmNtopAttachment, XmATTACH_POSITION,
11923 XmNrightAttachment, XmATTACH_POSITION,
11924 XmNrightPosition, 99, NULL);
11926 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
11927 SmartIndentDialog.lmPulldown = CreateLanguageModeMenu(lmForm, langModeCB,
11931 XtSetArg(args[n], XmNspacing, 0); n++;
11932 XtSetArg(args[n], XmNmarginWidth, 0); n++;
11933 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
11934 XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
11935 @@ -2150,12 +2150,13 @@ void UpdateLangModeMenuSmartIndent(void)
11937 if (SmartIndentDialog.shell == NULL)
11940 oldMenu = SmartIndentDialog.lmPulldown;
11941 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
11942 SmartIndentDialog.lmPulldown = CreateLanguageModeMenu(
11943 - XtParent(XtParent(oldMenu)), langModeCB, NULL);
11944 + XtParent(XtParent(oldMenu)), langModeCB, NULL, FALSE);
11945 XtVaSetValues(XmOptionButtonGadget(SmartIndentDialog.lmOptMenu),
11946 XmNsubMenuId, SmartIndentDialog.lmPulldown, NULL);
11947 SetLangModeMenu(SmartIndentDialog.lmOptMenu, SmartIndentDialog.langModeName);
11949 XtDestroyWidget(oldMenu);
11950 diff --quilt old/source/window.c new/source/window.c
11951 --- old/source/window.c
11952 +++ new/source/window.c
11953 @@ -53,10 +53,11 @@ static const char CVSID[] = "$Id: window
11954 #include "nedit.bm"
11956 #include "windowTitle.h"
11957 #include "interpret.h"
11958 #include "rangeset.h"
11959 +#include "patternMatchData.h"
11960 #include "../util/clearcase.h"
11961 #include "../util/misc.h"
11962 #include "../util/fileUtils.h"
11963 #include "../util/utils.h"
11964 #include "../util/fileUtils.h"
11965 @@ -273,11 +274,10 @@ WindowInfo *CreateWindow(const char *nam
11966 window->saveOldVersion = GetPrefSaveOldVersion();
11967 window->wrapMode = GetPrefWrap(PLAIN_LANGUAGE_MODE);
11968 window->showWrapMargin = GetPrefShowWrapMargin();
11969 window->overstrike = False;
11970 window->showMatchingStyle = GetPrefShowMatching();
11971 - window->matchSyntaxBased = GetPrefMatchSyntaxBased();
11972 window->showStats = GetPrefStatsLine();
11973 window->showISearchLine = GetPrefISearchLine();
11974 window->showLineNumbers = GetPrefLineNums();
11975 window->highlightSyntax = GetPrefHighlightSyntax();
11976 window->backlightCharTypes = NULL;
11977 @@ -312,10 +312,14 @@ WindowInfo *CreateWindow(const char *nam
11978 window->highlightData = NULL;
11979 window->shellCmdData = NULL;
11980 window->macroCmdData = NULL;
11981 window->smartIndentData = NULL;
11982 window->languageMode = PLAIN_LANGUAGE_MODE;
11984 + /* Pattern Match Feature: assign "PLAIN" string match table*/
11985 + window->stringMatchTable = FindStringMatchTable(NULL);
11987 window->iSearchHistIndex = 0;
11988 window->iSearchStartPos = -1;
11989 window->replaceLastRegexCase = TRUE;
11990 window->replaceLastLiteralCase = FALSE;
11991 window->iSearchLastRegexCase = TRUE;
11992 @@ -3436,11 +3440,10 @@ WindowInfo* CreateDocument(WindowInfo* s
11993 window->saveOldVersion = GetPrefSaveOldVersion();
11994 window->wrapMode = GetPrefWrap(PLAIN_LANGUAGE_MODE);
11995 window->showWrapMargin = GetPrefShowWrapMargin();
11996 window->overstrike = False;
11997 window->showMatchingStyle = GetPrefShowMatching();
11998 - window->matchSyntaxBased = GetPrefMatchSyntaxBased();
11999 window->highlightSyntax = GetPrefHighlightSyntax();
12000 window->backlightCharTypes = NULL;
12001 window->backlightChars = GetPrefBacklightChars();
12002 if (window->backlightChars) {
12003 char *cTypes = GetPrefBacklightCharTypes();
12004 @@ -3471,10 +3474,16 @@ WindowInfo* CreateDocument(WindowInfo* s
12005 window->highlightData = NULL;
12006 window->shellCmdData = NULL;
12007 window->macroCmdData = NULL;
12008 window->smartIndentData = NULL;
12009 window->languageMode = PLAIN_LANGUAGE_MODE;
12012 + * Pattern Match Feature:
12014 + window->stringMatchTable = FindStringMatchTable(NULL);
12016 window->iSearchHistIndex = 0;
12017 window->iSearchStartPos = -1;
12018 window->replaceLastRegexCase = TRUE;
12019 window->replaceLastLiteralCase = FALSE;
12020 window->iSearchLastRegexCase = TRUE;
12021 @@ -3863,11 +3872,10 @@ void RefreshMenuToggleStates(WindowInfo
12023 XmToggleButtonSetState(window->saveLastItem, window->saveOldVersion, False);
12025 XmToggleButtonSetState(window->autoSaveItem, window->autoSave, False);
12026 XmToggleButtonSetState(window->overtypeModeItem, window->overstrike, False);
12027 - XmToggleButtonSetState(window->matchSyntaxBasedItem, window->matchSyntaxBased, False);
12028 XmToggleButtonSetState(window->readOnlyItem, IS_USER_LOCKED(window->lockReasons), False);
12029 XmToggleButtonSetState(window->transientItem, window->transient, False);
12031 XtSetSensitive(window->smartIndentItem,
12032 SmartIndentMacrosAvailable(LanguageModeName(window->languageMode)));
12033 @@ -4427,10 +4435,13 @@ static void cloneDocument(WindowInfo *wi
12034 window->languageMode = orgWin->languageMode;
12035 window->highlightSyntax = orgWin->highlightSyntax;
12036 if (window->highlightSyntax)
12037 StartHighlighting(window, False);
12039 + /* recycle the pattern match data */
12040 + window->stringMatchTable = orgWin->stringMatchTable;
12042 /* copy states of original document */
12043 window->filenameSet = orgWin->filenameSet;
12044 window->fileFormat = orgWin->fileFormat;
12045 window->lastModTime = orgWin->lastModTime;
12046 window->fileChanged = orgWin->fileChanged;
12047 @@ -4444,11 +4455,10 @@ static void cloneDocument(WindowInfo *wi
12048 window->autoSave = orgWin->autoSave;
12049 window->saveOldVersion = orgWin->saveOldVersion;
12050 window->wrapMode = orgWin->wrapMode;
12051 SetOverstrike(window, orgWin->overstrike);
12052 window->showMatchingStyle = orgWin->showMatchingStyle;
12053 - window->matchSyntaxBased = orgWin->matchSyntaxBased;
12055 window->showStats = orgWin->showStats;
12056 window->showISearchLine = orgWin->showISearchLine;
12057 window->showLineNumbers = orgWin->showLineNumbers;
12058 window->modeMessageDisplayed = orgWin->modeMessageDisplayed;