7 source/Makefile.common | 6
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 @@ -864,12 +864,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 @@ -923,30 +924,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 @@ -1220,10 +1201,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 @@ -2578,13 +2592,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 @@ -2696,10 +2707,19 @@ Macro Subroutines
134 **get_character( position )**
135 Returns the single character at the position
136 indicated by the first argument 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 @@ -3405,13 +3425,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 @@ -3939,14 +3956,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 @@ -5048,10 +5061,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 @@ -6078,10 +6270,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 @@ -6105,10 +6298,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
400 OBJS = nedit.o file.o menu.o window.o selection.o search.o undo.o shift.o \
401 help.o preferences.o tags.o userCmds.o shell.o regularExp.o macro.o \
402 text.o textSel.o textDisp.o textBuf.o textDrag.o server.o highlight.o \
403 highlightData.o interpret.o parse.o smartIndent.o regexConvert.o \
404 - rbTree.o windowTitle.o calltips.o server_common.o rangeset.o
405 + rbTree.o windowTitle.o calltips.o server_common.o rangeset.o \
406 + patternMatch.o patternMatchData.o
408 XLTLIB = ../Xlt/libXlt.a
409 XMLLIB = ../Microline/XmL/libXmL.a
412 @@ -35,10 +36,13 @@ smartIndent.o: smartIndent.c
413 $(CC) $(CFLAGS) $(BIGGER_STRINGS) -c smartIndent.c -o $@
415 highlightData.o: highlightData.c
416 $(CC) $(CFLAGS) $(BIGGER_STRINGS) -c highlightData.c -o $@
418 +patternMatchData.o: patternMatchData.c
419 + $(CC) $(CFLAGS) $(BIGGER_STRINGS) -c patternMatchData.c -o $@
421 help_topic.h help_data.h: ../doc/help.etx
422 (cd ..; $(MAKE) docs)
425 rm -f $(OBJS) nedit nc nc.o parse.c linkdate.o
426 diff --quilt old/source/Makefile.dependencies new/source/Makefile.dependencies
427 --- old/source/Makefile.dependencies
428 +++ new/source/Makefile.dependencies
429 @@ -84,5 +84,16 @@ window.o: window.c window.h nedit.h text
430 ../util/fileUtils.h ../util/utils.h
431 windowTitle.o: windowTitle.c windowTitle.h nedit.h textBuf.h \
432 preferences.h help.h help_topic.h ../util/prefFile.h ../util/misc.h \
433 ../util/DialogF.h ../util/utils.h ../util/fileUtils.h \
435 +patternMatch.o: patternMatch.c regularExp.h \
436 + textBuf.h search.h window.h preferences.h highlight.h\
437 + patternMatch.h patternMatchData.h
438 +patternMatchData.o: patternMatchData.c ../util/DialogF.h ../util/misc.h \
439 + ../util/managedList.h regularExp.h textBuf.h nedit.h window.h \
440 + preferences.h help.h file.h textP.h patternMatch.h patternMatchData.h
441 +macro.o: patternMatch.h regularExp.h
442 +menu.o: patternMatchData.h
443 +preferences.o: patternMatchData.h
444 +search.o: patternMatch.h
445 +window.o: patternMatchData.h
446 diff --quilt old/source/highlightData.c new/source/highlightData.c
447 --- old/source/highlightData.c
448 +++ new/source/highlightData.c
449 @@ -549,11 +549,11 @@ static char *DefaultPatternSets[] = {
450 README:\"NEdit Macro syntax highlighting patterns, version 2.6, maintainer Thorsten Haude, nedit at thorstenhau.de\":::Flag::D\n\
451 Comment:\"#\":\"$\"::Comment::\n\
452 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\
453 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\
454 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\
455 - 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\
456 + Built-in Subrs:\"<(?:append_file|beep|call|calltip|clipboard_to_string|dialog|filename_dialog|focus_window|get_character|get_matching|get_pattern_(by_name|at_pos)|get_range|get_selection|get_style_(by_name|at_pos)|getenv|highlight_calltip_line|kill_calltip|length|list_dialog|max|min|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\
457 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\
458 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\
459 Macro Hooks:\"<(?:(?:pre|post)_(?open|save)|cursor_moved|modified|(?:losing_)?focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
460 Keyword:\"<(?:break|continue|define|delete|else|for|if|in|return|while)>\":::Keyword::\n\
461 Braces:\"[{}\\[\\]]\":::Keyword::\n\
462 @@ -2344,12 +2344,13 @@ void EditHighlightPatterns(WindowInfo *w
464 XmNrightAttachment, XmATTACH_POSITION,
465 XmNrightPosition, 99,
468 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
469 HighlightDialog.lmPulldown = CreateLanguageModeMenu(lmForm, langModeCB,
473 XtSetArg(args[n], XmNspacing, 0); n++;
474 XtSetArg(args[n], XmNmarginWidth, 0); n++;
475 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
476 XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
477 @@ -2879,12 +2880,13 @@ void UpdateLanguageModeMenu(void)
479 if (HighlightDialog.shell == NULL)
482 oldMenu = HighlightDialog.lmPulldown;
483 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
484 HighlightDialog.lmPulldown = CreateLanguageModeMenu(
485 - XtParent(XtParent(oldMenu)), langModeCB, NULL);
486 + XtParent(XtParent(oldMenu)), langModeCB, NULL, FALSE);
487 XtVaSetValues(XmOptionButtonGadget(HighlightDialog.lmOptMenu),
488 XmNsubMenuId, HighlightDialog.lmPulldown, NULL);
489 SetLangModeMenu(HighlightDialog.lmOptMenu, HighlightDialog.langModeName);
491 XtDestroyWidget(oldMenu);
492 @@ -2939,10 +2941,13 @@ static void langModeCB(Widget w, XtPoint
493 "Discard Changes", "Cancel", HighlightDialog.langModeName);
496 SetLangModeMenu(HighlightDialog.lmOptMenu,
497 HighlightDialog.langModeName);
499 + freePatternSet(newPatSet);
506 @@ -3038,10 +3043,12 @@ static void restoreCB(Widget w, XtPointe
507 "Are you sure you want to discard\n"
508 "all changes to syntax highlighting\n"
509 "patterns for language mode %s?", "Discard", "Cancel",
510 HighlightDialog.langModeName) == 2)
512 + freePatternSet(defaultPatSet);
517 /* if a stored version of the pattern set exists, replace it, if it
518 doesn't, add a new one */
519 diff --quilt old/source/macro.c new/source/macro.c
520 --- old/source/macro.c
521 +++ new/source/macro.c
522 @@ -55,10 +55,12 @@ static const char CVSID[] = "$Id: macro.
523 #include "../util/utils.h"
524 #include "../util/getfiles.h"
525 #include "highlight.h"
526 #include "highlightData.h"
527 #include "rangeset.h"
528 +#include "patternMatch.h"
529 +#include "regularExp.h"
535 @@ -295,12 +297,10 @@ static int makeBackupCopyMV(WindowInfo *
536 DataValue *result, char **errMsg);
537 static int incBackupMV(WindowInfo *window, DataValue *argList, int nArgs,
538 DataValue *result, char **errMsg);
539 static int showMatchingMV(WindowInfo *window, DataValue *argList, int nArgs,
540 DataValue *result, char **errMsg);
541 -static int matchSyntaxBasedMV(WindowInfo *window, DataValue *argList, int nArgs,
542 - DataValue *result, char **errMsg);
543 static int overTypeModeMV(WindowInfo *window, DataValue *argList, int nArgs,
544 DataValue *result, char **errMsg);
545 static int readOnlyMV(WindowInfo *window, DataValue *argList, int nArgs,
546 DataValue *result, char **errMsg);
547 static int lockedMV(WindowInfo *window, DataValue *argList, int nArgs,
548 @@ -412,10 +412,14 @@ static int getStyleAtPosMS(WindowInfo *w
549 static int filenameDialogMS(WindowInfo* window, DataValue* argList, int nArgs,
550 DataValue* result, char** errMsg);
551 static int callMS(WindowInfo *window, DataValue *argList,
552 int nArgs, DataValue *result, char **errMsg);
554 +/* Pattern Match Feature */
555 +static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs,
556 + DataValue *result, char **errMsg);
558 /* Built-in subroutines and variables for the macro language */
559 static const BuiltInSubrName MacroSubrs[] = {
560 { "length", lengthMS },
561 { "get_range", getRangeMS },
562 { "t_print", tPrintMS },
563 @@ -472,10 +476,11 @@ static const BuiltInSubrName MacroSubrs[
564 { "get_pattern_at_pos", getPatternAtPosMS },
565 { "get_style_by_name", getStyleByNameMS },
566 { "get_style_at_pos", getStyleAtPosMS },
567 { "filename_dialog", filenameDialogMS },
569 + { "get_matching", getMatchingMS },
570 { NULL, NULL } /* sentinel */
573 static const BuiltInSubrName SpecialVars[] = {
574 { "$cursor", cursorMV },
575 @@ -501,11 +506,10 @@ static const BuiltInSubrName SpecialVars
576 { "$wrap_text", wrapTextMV },
577 { "$highlight_syntax", highlightSyntaxMV },
578 { "$make_backup_copy", makeBackupCopyMV },
579 { "$incremental_backup", incBackupMV },
580 { "$show_matching", showMatchingMV },
581 - { "$match_syntax_based", matchSyntaxBasedMV },
582 { "$overtype_mode", overTypeModeMV },
583 { "$read_only", readOnlyMV },
584 { "$locked", lockedMV },
585 { "$file_format", fileFormatMV },
586 { "$font_name", fontNameMV },
587 @@ -4532,20 +4536,10 @@ static int showMatchingMV(WindowInfo *wi
588 result->val.str.rep = res;
589 result->val.str.len = strlen(res);
593 -static int matchSyntaxBasedMV(WindowInfo *window, DataValue *argList, int nArgs,
594 - DataValue *result, char **errMsg)
596 - result->tag = INT_TAG;
597 - result->val.n = window->matchSyntaxBased ? 1 : 0;
603 static int overTypeModeMV(WindowInfo *window, DataValue *argList, int nArgs,
604 DataValue *result, char **errMsg)
606 result->tag = INT_TAG;
607 result->val.n = window->overstrike ? 1 : 0;
608 @@ -5949,10 +5943,97 @@ static int getPatternAtPosMS(WindowInfo
609 return fillPatternResult(result, errMsg, window,
610 HighlightNameOfCode(window, patCode), False, True,
611 HighlightStyleOfCode(window, patCode), bufferPos);
615 +** Pattern Match Feature:
616 +** Find a matching pattern string related to the given position.
619 +** get_matching(position)
621 +** Returns info about matching pattern within an array. The array has
622 +** the following keys: "pos" (position of the first character of the
623 +** matching pattern), "len" (length of the matching pattern), "direction"
624 +** (direction where the matching pattern was found: "0" = forward;
625 +** "1" = backward). If no matching pattern was found, then array element
626 +** of "pos" holds "-1", "len" holds "0" and "direction" holds "-1".
629 +static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs,
630 + DataValue *result, char **errMsg)
633 + int matchPos, matchLen;
635 + textBuffer *buf = window->buffer;
639 + * Perform syntax & semantic check
642 + return wrongNArgsErr(errMsg);
644 + if (!readIntArg(argList[0], &startPos, errMsg))
650 + * do the search; provide default values, if search fails
652 + if (!FindMatchingString(window, MT_MACRO, &startPos, 0, buf->length,
653 + &matchPos, &matchLen, &direction))
661 + * initialize array holding info about matching string
663 + result->tag = ARRAY_TAG;
664 + result->val.arrayPtr = ArrayNew();
667 + * the following array entries will be integers
672 + * insert match position
674 + dv.val.n = matchPos;
675 + if (!ArrayInsert(result, PERM_ALLOC_STR("pos"), &dv))
677 + M_ARRAY_INSERT_FAILURE();
681 + * insert length of matching pattern
683 + dv.val.n = matchLen;
684 + if (!ArrayInsert(result, PERM_ALLOC_STR("len"), &dv))
686 + M_ARRAY_INSERT_FAILURE();
690 + * insert direction where the matching pattern was found
692 + dv.val.n = direction;
693 + if (!ArrayInsert(result, PERM_ALLOC_STR("direction"), &dv))
695 + M_ARRAY_INSERT_FAILURE();
701 static int wrongNArgsErr(char **errMsg)
703 *errMsg = "Wrong number of arguments to function %s";
706 diff --quilt old/source/menu.c new/source/menu.c
707 --- old/source/menu.c
708 +++ new/source/menu.c
709 @@ -47,10 +47,11 @@ static const char CVSID[] = "$Id: menu.c
710 #include "userCmds.h"
713 #include "highlight.h"
714 #include "highlightData.h"
715 +#include "patternMatchData.h"
716 #include "interpret.h"
717 #include "smartIndent.h"
718 #include "windowTitle.h"
719 #include "regularExp.h"
720 #include "../util/getfiles.h"
721 @@ -131,11 +132,10 @@ static void fontCB(Widget w, WindowInfo
722 static void tabsCB(Widget w, WindowInfo *window, caddr_t callData);
723 static void backlightCharsCB(Widget w, WindowInfo *window, caddr_t callData);
724 static void showMatchingOffCB(Widget w, WindowInfo *window, caddr_t callData);
725 static void showMatchingDelimitCB(Widget w, WindowInfo *window, caddr_t callData);
726 static void showMatchingRangeCB(Widget w, WindowInfo *window, caddr_t callData);
727 -static void matchSyntaxBasedCB(Widget w, WindowInfo *window, caddr_t callData);
728 static void statsCB(Widget w, WindowInfo *window, caddr_t callData);
729 static void autoIndentOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
730 static void autoIndentDefCB(Widget w, WindowInfo *window, caddr_t callData);
731 static void smartIndentDefCB(Widget w, WindowInfo *window, caddr_t callData);
732 static void autoSaveDefCB(Widget w, WindowInfo *window, caddr_t callData);
733 @@ -158,13 +158,13 @@ static void pathInWindowsMenuDefCB(Widge
734 static void customizeTitleDefCB(Widget w, WindowInfo *window, caddr_t callData);
735 static void tabsDefCB(Widget w, WindowInfo *window, caddr_t callData);
736 static void showMatchingOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
737 static void showMatchingDelimitDefCB(Widget w, WindowInfo *window, caddr_t callData);
738 static void showMatchingRangeDefCB(Widget w, WindowInfo *window, caddr_t callData);
739 -static void matchSyntaxBasedDefCB(Widget w, WindowInfo *window, caddr_t callData);
740 static void highlightOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
741 static void highlightDefCB(Widget w, WindowInfo *window, caddr_t callData);
742 +static void matchPatternsDefCB(Widget w, WindowInfo *window, caddr_t callData);
743 static void backlightCharsDefCB(Widget w, WindowInfo *window, caddr_t callData);
744 static void fontDefCB(Widget w, WindowInfo *window, caddr_t callData);
745 static void colorDefCB(Widget w, WindowInfo *window, caddr_t callData);
746 static void smartTagsDefCB(Widget parent, XtPointer client_data, XtPointer call_data);
747 static void showAllTagsDefCB(Widget parent, XtPointer client_data, XtPointer call_data);
748 @@ -407,12 +407,10 @@ static void setMakeBackupCopyAP(Widget w
750 static void setIncrementalBackupAP(Widget w, XEvent *event, String *args,
752 static void setShowMatchingAP(Widget w, XEvent *event, String *args,
754 -static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
756 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
758 static void setLockedAP(Widget w, XEvent *event, String *args,
760 static void setTransientAP(Widget text, XEvent *event, String *args,
761 @@ -582,11 +580,10 @@ static XtActionsRec Actions[] = {
763 {"set_make_backup_copy", setMakeBackupCopyAP},
765 {"set_incremental_backup", setIncrementalBackupAP},
766 {"set_show_matching", setShowMatchingAP},
767 - {"set_match_syntax_based", setMatchSyntaxBasedAP},
768 {"set_overtype_mode", setOvertypeModeAP},
769 {"set_locked", setLockedAP},
770 {"set_transient", setTransientAP},
771 {"set_tab_dist", setTabDistAP},
772 {"set_em_tab_dist", setEmTabDistAP},
773 @@ -1028,13 +1025,12 @@ Widget CreateMenuBar(Widget parent, Wind
774 GetPrefShowMatching() == FLASH_DELIMIT, SHORT);
775 window->showMatchingRangeDefItem = createMenuRadioToggle(subSubPane,
776 "range", "Range", 'R', showMatchingRangeDefCB, window,
777 GetPrefShowMatching() == FLASH_RANGE, SHORT);
778 createMenuSeparator(subSubPane, "sep", SHORT);
779 - window->matchSyntaxBasedDefItem = createMenuToggle(subSubPane,
780 - "matchSyntax", "Syntax Based", 'S', matchSyntaxBasedDefCB, window,
781 - GetPrefMatchSyntaxBased(), SHORT);
782 + createMenuItem(subSubPane, "matchPatterns", "Matching Patterns...",
783 + 'M', matchPatternsDefCB, window, FULL);
785 /* Show Cursorline */
786 window->showCursorlineItem = createMenuToggle(subPane,
787 "showCursorlineItem", "Show Cursorline", 'x', showCursorlineCB,
788 NULL, GetPrefShowCursorline(), FULL);
789 @@ -1152,14 +1148,10 @@ Widget CreateMenuBar(Widget parent, Wind
790 "delimiter", "Delimiter", 'D', showMatchingDelimitCB, window,
791 window->showMatchingStyle == FLASH_DELIMIT, SHORT);
792 window->showMatchingRangeItem = createMenuRadioToggle(subPane, "range",
793 "Range", 'R', showMatchingRangeCB, window,
794 window->showMatchingStyle == FLASH_RANGE, SHORT);
795 - createMenuSeparator(subPane, "sep", SHORT);
796 - window->matchSyntaxBasedItem = createMenuToggle(subPane, "matchSyntax",
797 - "Syntax Based", 'S', matchSyntaxBasedCB, window,
798 - window->matchSyntaxBased, SHORT);
801 createMenuSeparator(menuPane, "sep2", SHORT);
802 window->overtypeModeItem = createMenuToggle(menuPane, "overtype", "Overtype", 'O',
803 doActionCB, "set_overtype_mode", False, SHORT);
804 @@ -1687,28 +1679,10 @@ static void showMatchingRangeCB(Widget w
805 ((XmAnyCallbackStruct *)callData)->event);
806 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_show_matching",
807 ((XmAnyCallbackStruct *)callData)->event, params, 1);
810 -static void matchSyntaxBasedCB(Widget w, WindowInfo *window, caddr_t callData)
812 - Widget menu = MENU_WIDGET(w);
814 - window = WidgetToWindow(menu);
817 - if (shortPrefAskDefault(window->shell, w, "Match Syntax Based")) {
818 - matchSyntaxBasedDefCB(w, window, callData);
819 - SaveNEditPrefs(window->shell, GetPrefShortMenus());
822 - HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
823 - ((XmAnyCallbackStruct *)callData)->event);
824 - XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_match_syntax_based",
825 - ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
828 static void fontCB(Widget w, WindowInfo *window, caddr_t callData)
830 ChooseFonts(WidgetToWindow(MENU_WIDGET(w)), True);
833 @@ -2032,22 +2006,18 @@ static void showMatchingRangeDefCB(Widge
834 XmToggleButtonSetState(win->showMatchingDelimitDefItem, False, False);
835 XmToggleButtonSetState(win->showMatchingRangeDefItem, True, False);
839 -static void matchSyntaxBasedDefCB(Widget w, WindowInfo *window, caddr_t callData)
840 +static void matchPatternsDefCB(Widget w, WindowInfo *window, caddr_t callData)
844 - int state = XmToggleButtonGetState(w);
845 + Widget menu = MENU_WIDGET(w);
846 + WindowInfo *activeWindow = WidgetToWindow(menu);
848 - /* Set the preference and make the other windows' menus agree */
849 - SetPrefMatchSyntaxBased(state);
850 - for (win=WindowList; win!=NULL; win=win->next) {
851 - if (IsTopDocument(win))
852 - XmToggleButtonSetState(win->matchSyntaxBasedDefItem, state, False);
854 + HidePointerOnKeyedEvent(activeWindow->lastFocus,
855 + ((XmAnyCallbackStruct *)callData)->event);
856 + EditMatchPatterns(activeWindow);
859 static void backlightCharsDefCB(Widget w, WindowInfo *window, caddr_t callData)
862 @@ -4286,23 +4256,10 @@ static void setShowMatchingAP(Widget w,
864 fprintf(stderr, "nedit: set_show_matching requires argument\n");
868 -static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
871 - WindowInfo *window = WidgetToWindow(w);
874 - ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->matchSyntaxBased, "set_match_syntax_based");
876 - if (IsTopDocument(window))
877 - XmToggleButtonSetState(window->matchSyntaxBasedItem, newState, False);
878 - window->matchSyntaxBased = newState;
881 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
884 WindowInfo *window = WidgetToWindow(w);
886 diff --quilt old/source/nedit.h new/source/nedit.h
887 --- old/source/nedit.h
888 +++ new/source/nedit.h
889 @@ -364,11 +364,10 @@ typedef struct _WindowInfo {
890 Widget iSearchLineItem;
892 Widget showMatchingOffItem;
893 Widget showMatchingDelimitItem;
894 Widget showMatchingRangeItem;
895 - Widget matchSyntaxBasedItem;
896 Widget overtypeModeItem;
897 Widget highlightItem;
898 Widget windowMenuPane;
899 Widget shellMenuPane;
900 Widget macroMenuPane;
901 @@ -390,11 +389,10 @@ typedef struct _WindowInfo {
902 Widget newlineWrapDefItem;
903 Widget contWrapDefItem;
904 Widget showMatchingOffDefItem;
905 Widget showMatchingDelimitDefItem;
906 Widget showMatchingRangeDefItem;
907 - Widget matchSyntaxBasedDefItem;
908 Widget highlightOffDefItem;
909 Widget highlightDefItem;
910 Widget backlightCharsItem;
911 Widget backlightCharsDefItem;
912 Widget searchDlogsDefItem;
913 @@ -510,11 +508,10 @@ typedef struct _WindowInfo {
914 ALWAYS, ON-WRAP as enums */
915 Boolean overstrike; /* is overstrike mode turned on ? */
916 char showMatchingStyle; /* How to show matching parens:
917 NO_FLASH, FLASH_DELIMIT, or
919 - char matchSyntaxBased; /* Use syntax info to show matching */
920 Boolean showStats; /* is stats line supposed to be shown */
921 Boolean showISearchLine; /* is incr. search line to be shown */
922 Boolean showLineNumbers; /* is the line number display shown */
923 Boolean highlightSyntax; /* is syntax highlighting turned on? */
924 Boolean backlightChars; /* is char backlighting turned on? */
925 @@ -556,10 +553,13 @@ typedef struct _WindowInfo {
926 incremental search bar */
927 Bool iSearchLastLiteralCase; /* idem, for literal mode */
928 Bool findLastRegexCase; /* idem, for regex mode in find dialog */
929 Bool findLastLiteralCase; /* idem, for literal mode */
931 + /* Pattern Match Feature */
932 + void *stringMatchTable; /* match pattern info related to this window */
935 int replaceScope; /* Current scope for replace dialog */
936 Widget replaceScopeWinToggle; /* Scope for replace = window */
937 Widget replaceScopeSelToggle; /* Scope for replace = selection */
938 Widget replaceScopeMultiToggle;/* Scope for replace = multiple files */
939 diff --quilt /dev/null new/source/patternMatch.c
941 +++ new/source/patternMatch.c
943 +static const char CVSID[] = "$Id: patternMatch.c,v 1.4 2003/10/27 21:59:14 uleh Exp $";
944 +/*******************************************************************************
946 +* patternMatch.c -- Nirvana Editor pattern matching functions *
948 +* Copyright (C) 2003-2004, Uwe Lehnert *
950 +* This is free software; you can redistribute it and/or modify it under the *
951 +* terms of the GNU General Public License as published by the Free Software *
952 +* Foundation; either version 2 of the License, or (at your option) any later *
953 +* version. In addition, you may distribute versions of this program linked to *
954 +* Motif or Open Motif. See README for details. *
956 +* This software is distributed in the hope that it will be useful, but WITHOUT *
957 +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
958 +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
959 +* for more details. *
961 +* You should have received a copy of the GNU General Public License along with *
962 +* software; if not, write to the Free Software Foundation, Inc., 59 Temple *
963 +* Place, Suite 330, Boston, MA 02111-1307 USA *
965 +* Nirvana Text Editor *
966 +* October 27, 2004 *
968 +* Written by Uwe Lehnert *
970 +*******************************************************************************/
972 +#ifdef HAVE_CONFIG_H
973 +#include "../config.h"
983 +#include "../util/VMSparam.h"
986 +#include <sys/param.h>
990 +#include "regularExp.h"
991 +#include "textBuf.h"
994 +#include "preferences.h"
995 +#include "highlight.h"
997 +#include "patternMatch.h"
998 +#include "patternMatchData.h"
1000 +#ifdef HAVE_DEBUG_H
1001 +#include "../debug.h"
1004 +#define MAX_NESTED_PATTERNS 100
1006 +#define IGNORE_HIGHLIGHT_CODE -1
1008 +typedef struct _SearchRegionInfo {
1009 + WindowInfo *sriWindow;
1013 + int sriStartOfTextPos;
1014 +} SearchRegionInfo;
1016 +typedef struct _FoundStringInfo {
1017 + char *fsiStartPtr;
1022 + const char *fsiDelimiters;
1025 +typedef struct _BackRefInfo {
1027 + int briCaseInsensitive;
1028 + char *briStartPtr[MAX_GLOBAL_BACK_REF_ID];
1029 + char *briEndPtr[MAX_GLOBAL_BACK_REF_ID];
1032 +typedef struct _MatchingElementInfo {
1033 + MatchPatternTableElement *meiElement;
1034 + PatternReference meiPatRef;
1036 + int meiHighLightCode;
1037 + int meiAbsStartPos;
1039 + BackRefInfo meiBackRefInfo;
1040 +} MatchingElementInfo;
1042 +typedef struct _PatternStackElement {
1043 + PatternReference psePatRef;
1044 + int pseHighLightCode;
1045 + BackRefInfo pseBackRefInfo;
1046 +} PatternStackElement;
1049 + * Prototypes of local functions
1051 +void adaptPatternPositions(
1052 + MatchingType matchingType,
1055 + int startPatternLength,
1057 + int matchedPatternLength);
1059 +static int findMatchingStringElement(
1060 + StringMatchTable *smTable,
1061 + SearchRegionInfo *searchRegion,
1062 + MatchingElementInfo *matchInfo,
1064 + const char *delimiters);
1066 +static PatternElementMonoInfo determineMonoPatInfo(
1067 + WindowInfo *window,
1068 + int patHighLightCode,
1071 + PatternElementKind *patElementKind);
1073 +static void assignBackRefInfo(
1074 + StringPattern *strPat,
1075 + BackRefInfo *backRefInfo);
1076 +static int doesBackRefInfoMatch(
1077 + BackRefInfo *backRefInfo1,
1078 + BackRefInfo *backRefInfo2);
1079 +static int compareBackRef(
1084 + int caseInsensitive);
1086 +static int doesPatternElementMatch(
1087 + PatternElement *patElement,
1088 + FoundStringInfo *foundStringInfo,
1089 + BackRefInfo *backRefInfo);
1090 +static int doesMPTableElementMatch(
1091 + MatchPatternTableElement *element,
1092 + FoundStringInfo *foundStringInfo,
1093 + PatternElementKind *patternElementKind,
1094 + int *patternElementIdx,
1095 + BackRefInfo *backRefInfo);
1096 +static int getPatternInfo(
1097 + MatchPatternTable *table,
1098 + FoundStringInfo *foundStringInfo,
1099 + PatternReference *patRef,
1100 + BackRefInfo *backRefInfo);
1102 +static int isPartOfPattern(
1103 + MatchPatternTable *table,
1104 + int parentElementIdx,
1105 + int childElementIdx,
1106 + PatternElementKind patElementKind);
1107 +static int isPartOfPatternElementSet(
1108 + PatternElementSet *patElementSet,
1109 + int patternElementIdx);
1110 +static int isPartOfMiddlePatternElementSet(
1111 + PatternElementSet *patElementSet,
1112 + int patternElementIdx);
1113 +static void considerNextPatternReference(
1114 + MatchPatternTable *table,
1115 + PatternReference *startPatRef,
1116 + PatternReference nxtPatRef,
1119 +static int searchPatternForward(
1120 + MatchPatternTable *table,
1121 + regexp *compiledRE,
1122 + SearchRegionInfo *searchRegion,
1123 + const char *delimiters,
1126 + PatternReference *patRef,
1127 + int *highLightCode,
1128 + BackRefInfo *backRefInfo);
1129 +static int searchPatternBackward(
1130 + MatchPatternTable *table,
1131 + regexp *compiledRE,
1132 + SearchRegionInfo *searchRegion,
1133 + const char *delimiters,
1135 + PatternReference *patRef,
1136 + int *highLightCode,
1137 + int *matchedPatternLength,
1138 + BackRefInfo *backRefInfo);
1140 +static int parseStringElementForward(
1141 + MatchingElementInfo *matchInfo,
1142 + SearchRegionInfo *searchRegion,
1145 + int *matchedPatternLength,
1146 + const char *delimiters);
1147 +static int findRelatedForwardPattern(
1148 + StringMatchTable *table,
1149 + SearchRegionInfo *searchRegion,
1150 + const char *delimiters,
1151 + PatternReference beginPatRef,
1152 + int beginPatHighLightCode,
1153 + BackRefInfo *beginPatBackRefInfo,
1155 + int *matchEndPos);
1157 +static int parseStringElementBackward(
1158 + MatchingElementInfo *matchInfo,
1159 + SearchRegionInfo *searchRegion,
1162 + int *matchedPatternLength,
1163 + const char *delimiters);
1164 +static int findRelatedStartPattern(
1165 + StringMatchTable *table,
1166 + SearchRegionInfo *searchRegion,
1167 + const char *delimiters,
1168 + PatternReference beginPatRef,
1169 + int beginPatHighLightCode,
1170 + BackRefInfo *beginPatBackRefInfo,
1172 + int *matchedPatternLength);
1173 +static void considerStackPatReference(
1174 + PatternElementSet *patSet,
1175 + int stackElementIdx,
1176 + int *foundElementIdx);
1178 +static int getPatternLocatedAtPos(
1179 + regexp *usedPatRE,
1180 + MatchPatternTable *table,
1181 + SearchRegionInfo *searchRegion,
1183 + MatchingElementInfo *matchInfo,
1184 + const char *delimiters);
1185 +static int getMatchedElementInfo(
1186 + WindowInfo *window,
1187 + MatchPatternTable *table,
1188 + FoundStringInfo *foundStringInfo,
1189 + MatchingElementInfo *matchInfo);
1191 +static PatternElement *getPatternOfReference(
1192 + MatchPatternTable *table,
1193 + PatternReference patRef);
1196 +static char *getPatternForDebug(
1197 + MatchPatternTable *table,
1198 + PatternReference patRef );
1199 +static char *patElemKindToString(
1200 + PatternElementKind patElemKind);
1201 +static void printFoundStringForDebug(
1202 + WindowInfo *window,
1208 +** Try to find a matching pattern string related to the given "charPos"
1209 +** inside the given range (defined by startLimit & endLimit).
1210 +** Determine the matching position & the match pattern length (depending
1211 +** on given matchingType), if a matching pattern was found.
1212 +** Returns true, if a matching pattern string was found.
1214 +int FindMatchingString(
1215 + WindowInfo *window,
1216 + MatchingType matchingType,
1221 + int *matchedPatternLength,
1224 + StringMatchTable *smTable = (StringMatchTable *)window->stringMatchTable;
1225 + const char *delimiters;
1226 + SearchRegionInfo searchRegion;
1227 + MatchingElementInfo matchInfo;
1228 + int matchingPatternFound = FALSE;
1231 + if (smTable == NULL || smTable->smtAllPatRE == NULL)
1234 + * No match pattern table available:
1240 + * Get delimiters related to window
1242 + delimiters = GetWindowDelimiters(window);
1243 + if (delimiters == NULL)
1244 + delimiters = GetPrefDelimiters();
1247 + * Select the start pattern reg. exp. to use
1249 + if (matchingType == MT_FLASH_RANGE ||
1250 + matchingType == MT_FLASH_DELIMIT)
1252 + smTable->smtUsedPatRE = smTable->smtFlashPatRE;
1256 + smTable->smtUsedPatRE = smTable->smtAllPatRE;
1260 + * Get a copy of the text buffer area to parse
1262 + searchRegion.sriWindow = window;
1263 + searchRegion.sriText = BufGetRange(window->buffer, startLimit, endLimit);
1264 + searchRegion.sriPrevChar = BufGetCharacter(window->buffer, startLimit - 1);
1265 + searchRegion.sriSuccChar = BufGetCharacter(window->buffer, endLimit);
1266 + searchRegion.sriStartOfTextPos = startLimit;
1268 + relCharPos = *charPos - startLimit;
1271 + * Try to find a matching pattern string using string match table
1274 + if (findMatchingStringElement(
1282 + printf("--- Start at : ");
1283 + printFoundStringForDebug(
1285 + matchInfo.meiAbsStartPos,
1286 + matchInfo.meiLength);
1289 + if (matchInfo.meiDirection == SEARCH_FORWARD)
1291 + matchingPatternFound =
1292 + parseStringElementForward(
1297 + matchedPatternLength,
1302 + matchingPatternFound =
1303 + parseStringElementBackward(
1308 + matchedPatternLength,
1312 + if (matchingPatternFound)
1315 + * Calc. abs. start char pos. (may have been changed if
1316 + * cursor was located inside a string pattern). Adapt
1317 + * pattern positions depending on matchingType.
1319 + *charPos = relCharPos + startLimit;
1320 + *direction = matchInfo.meiDirection;
1322 + adaptPatternPositions(
1324 + matchInfo.meiDirection,
1326 + matchInfo.meiLength,
1328 + *matchedPatternLength);
1332 + XtFree(searchRegion.sriText);
1334 + return matchingPatternFound;
1338 +** Adapt match pattern position / start position depending on the
1339 +** given matching type.
1341 +void adaptPatternPositions(
1342 + MatchingType matchingType,
1345 + int startPatternLength,
1347 + int matchedPatternLength)
1349 + switch (matchingType)
1351 + case MT_FLASH_DELIMIT:
1353 + if (direction == SEARCH_FORWARD)
1355 + (*matchPos) -= matchedPatternLength - 1;
1359 + case MT_FLASH_RANGE:
1361 + if (direction == SEARCH_FORWARD)
1363 + (*charPos) -= startPatternLength;
1372 + if (direction == SEARCH_FORWARD)
1378 + (*matchPos) += matchedPatternLength;
1385 +** Try to find a string pattern at given buffer position 'charPos'.
1386 +** A string pattern is found, if pattern is located before 'charPos' or
1387 +** 'charPos' is located within a pattern.
1388 +** If a string pattern is found, then search direction and string pattern
1389 +** reference / properties are determined.
1390 +** Returns true, if a string pattern was found.
1392 +static int findMatchingStringElement(
1393 + StringMatchTable *smTable,
1394 + SearchRegionInfo *searchRegion,
1395 + MatchingElementInfo *matchInfo,
1397 + const char *delimiters)
1399 + if (getPatternLocatedAtPos(
1400 + smTable->smtUsedPatRE,
1401 + smTable->smtAllPatterns,
1408 + * Pattern found -> define search direction:
1409 + * - START & MIDDLE pattern: matching pattern is searched in
1410 + * forward direction
1411 + * - END pattern: matching pattern is searched in backward
1414 + if (matchInfo->meiPatRef.prKind == PEK_END)
1415 + matchInfo->meiDirection = SEARCH_BACKWARD;
1417 + matchInfo->meiDirection = SEARCH_FORWARD;
1426 +** Return mono pattern info depending on highlight codes
1427 +** of left / right side of string pattern. Update pattern
1428 +** kind if applicable.
1430 +static PatternElementMonoInfo determineMonoPatInfo(
1431 + WindowInfo *window,
1432 + int patHighLightCode,
1435 + PatternElementKind *patElementKind)
1437 + int leftSideHasSameHC;
1438 + int rightSideHasSameHC;
1441 + * Determine, if left side holds same highlight code than
1442 + * found string pattern
1445 + leftSideHasSameHC =
1446 + (HighlightCodeOfPos(window, leftPos) == patHighLightCode);
1448 + leftSideHasSameHC = FALSE;
1451 + * Determine, if right side holds same highlight code than
1452 + * found string pattern
1454 + if (rightPos < window->buffer->length)
1455 + rightSideHasSameHC =
1456 + (HighlightCodeOfPos(window, rightPos) == patHighLightCode);
1458 + rightSideHasSameHC = FALSE;
1460 + if ((rightSideHasSameHC && leftSideHasSameHC) ||
1461 + (!rightSideHasSameHC && !leftSideHasSameHC))
1463 + return PEMI_MONO_AMBIGUOUS_SYNTAX;
1465 + else if (leftSideHasSameHC)
1467 + *patElementKind = PEK_END;
1468 + return PEMI_MONO_DEFINITE_SYNTAX;
1472 + *patElementKind = PEK_START;
1473 + return PEMI_MONO_DEFINITE_SYNTAX;
1478 +** Get backref info out of found string pattern and
1479 +** put it into given backRefInfo.
1481 +static void assignBackRefInfo(
1482 + StringPattern *strPat,
1483 + BackRefInfo *backRefInfo)
1487 + regexp *patRE = strPat->spTextRE;
1489 + backRefInfo->briAvailable = FALSE;
1490 + backRefInfo->briCaseInsensitive = strPat->spCaseInsensitive;
1492 + for (i=0; i<MAX_GLOBAL_BACK_REF_ID; i++)
1494 + localId = strPat->spGlobalToLocalBackRef[i];
1496 + if (localId != NO_LOCAL_BACK_REF_ID)
1498 + backRefInfo->briAvailable = TRUE;
1500 + backRefInfo->briStartPtr[i] = patRE->startp[localId];
1501 + backRefInfo->briEndPtr[i] = patRE->endp[localId];
1505 + backRefInfo->briStartPtr[i] = NULL;
1506 + backRefInfo->briEndPtr[i] = NULL;
1512 +** Check, if given backref infos match.
1513 +** Returns true, if backref infos match.
1515 +static int doesBackRefInfoMatch(
1516 + BackRefInfo *backRefInfo1,
1517 + BackRefInfo *backRefInfo2)
1522 + * if min. one string pattern doesn't hold backref info, then nothing
1523 + * could be compared -> both string pattern are matching.
1525 + if (!backRefInfo1->briAvailable || !backRefInfo2->briAvailable)
1528 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
1530 + if (!compareBackRef(
1531 + backRefInfo1->briStartPtr[i],
1532 + backRefInfo1->briEndPtr[i],
1533 + backRefInfo2->briStartPtr[i],
1534 + backRefInfo2->briEndPtr[i],
1535 + backRefInfo1->briCaseInsensitive || backRefInfo2->briCaseInsensitive))
1545 +** Compares two backref content.
1546 +** Returns true, if backref contents match.
1548 +static int compareBackRef(
1553 + int caseInsensitive)
1558 + if (startPtr1 == NULL && startPtr2 == NULL)
1561 + if (startPtr1 == NULL || startPtr2 == NULL)
1564 + if ((endPtr1 - startPtr1) != (endPtr2 - startPtr2))
1570 + if (caseInsensitive)
1572 + while (s1 != endPtr1)
1574 + if (tolower((unsigned char)*s1++) != tolower((unsigned char)*s2++))
1580 + while (s1 != endPtr1)
1582 + if (*s1++ != *s2++)
1590 +** Verify if given pattern element is located between given
1591 +** start / end pointer of "foundStringInfo". Assign backreference
1592 +** information, if pattern element matches.
1593 +** Returns true, if given pattern element matches.
1595 +static int doesPatternElementMatch(
1596 + PatternElement *patElement,
1597 + FoundStringInfo *foundStringInfo,
1598 + BackRefInfo *backRefInfo)
1602 + StringPattern *strPat;
1605 + switch (patElement->peType)
1608 + strPat = &patElement->peVal.peuSingle;
1610 + case PET_MULTIPLE:
1611 + strPat = &patElement->peVal.peuMulti.mpStringPattern;
1617 + if (strPat->spRegularExpression)
1620 + * check reg. expression:
1625 + foundStringInfo->fsiStartPtr,
1626 + foundStringInfo->fsiEndPtr,
1628 + foundStringInfo->fsiPrevChar,
1629 + foundStringInfo->fsiSuccChar,
1630 + foundStringInfo->fsiDelimiters,
1635 + assignBackRefInfo(strPat, backRefInfo);
1637 + return elementMatch;
1641 + backRefInfo->briAvailable = FALSE;
1644 + * check literal string:
1646 + p = strPat->spText;
1649 + * if length of found string is different from length of
1650 + * given string pattern, then there is no match.
1652 + if (strPat->spLength != foundStringInfo->fsiLength)
1655 + s = foundStringInfo->fsiStartPtr;
1657 + if (strPat->spCaseInsensitive)
1659 + while (s != foundStringInfo->fsiEndPtr)
1661 + if (tolower((unsigned char)*s++) != *p++)
1667 + while (s != foundStringInfo->fsiEndPtr)
1679 +** Verify if a pattern element of given MatchPatternTableElement is
1680 +** located between given start / end pointer of "foundStringInfo".
1681 +** Returns true, if so.
1683 +static int doesMPTableElementMatch(
1684 + MatchPatternTableElement *element,
1685 + FoundStringInfo *foundStringInfo,
1686 + PatternElementKind *patternElementKind,
1687 + int *patternElementIdx,
1688 + BackRefInfo *backRefInfo)
1692 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
1694 + if (doesPatternElementMatch(
1695 + element->mpteAll.pesPattern[i],
1699 + *patternElementKind = element->mpteAll.pesPattern[i]->peKind;
1700 + *patternElementIdx = i;
1710 +** Determine the pattern element of given MatchPatternTable, which is
1711 +** located between given start / end pointer of "foundStringInfo".
1712 +** Setup related pattern element reference.
1713 +** Returns true, if a pattern element was found.
1715 +static int getPatternInfo(
1716 + MatchPatternTable *table,
1717 + FoundStringInfo *foundStringInfo,
1718 + PatternReference *patRef,
1719 + BackRefInfo *backRefInfo)
1723 + for (i=0; i<table->mptNumberOfElements; i++)
1725 + if (doesMPTableElementMatch(
1726 + table->mptElements[i],
1729 + &patRef->prPatternIdx,
1732 + patRef->prElementIdx = i;
1739 + * Should never been reached !
1741 + patRef->prElementIdx = NO_ELEMENT_IDX;
1742 + patRef->prKind = PEK_UNKNOWN;
1743 + patRef->prPatternIdx = NO_PATTERN_IDX;
1749 +** Check, if given child pattern element is part of given
1750 +** parent pattern element.
1751 +** Returns true, if child is part of parent.
1753 +static int isPartOfPattern(
1754 + MatchPatternTable *table,
1755 + int parentElementIdx,
1756 + int childElementIdx,
1757 + PatternElementKind patElementKind)
1759 + MatchPatternTableElement *parent = table->mptElements[parentElementIdx];
1760 + MatchPatternTableElement *child = table->mptElements[childElementIdx];
1762 + if (childElementIdx == parentElementIdx)
1765 + if (patElementKind == PEK_START)
1767 + if (isPartOfPatternElementSet(&parent->mpteStart, childElementIdx))
1770 + return( isPartOfPatternElementSet(&child->mpteStart, parentElementIdx) );
1772 + else if (patElementKind == PEK_END)
1774 + if (isPartOfPatternElementSet(&parent->mpteEnd, childElementIdx))
1777 + return( isPartOfPatternElementSet(&child->mpteEnd, parentElementIdx) );
1782 + * Given child pattern element is middle pattern: the given pattern element
1783 + * is part of parent pattern, if it's a reference of a middle pattern
1785 + if (isPartOfMiddlePatternElementSet(&parent->mpteMiddle, childElementIdx))
1788 + return( isPartOfMiddlePatternElementSet(&child->mpteMiddle, parentElementIdx) );
1793 +** Check, if given pattern element is part of given pattern element set.
1794 +** Returns true, if so.
1796 +static int isPartOfPatternElementSet(
1797 + PatternElementSet *patElementSet,
1798 + int patternElementIdx)
1800 + PatternElement *patElement;
1803 + for (i=0; i<patElementSet->pesNumberOfPattern; i++)
1805 + if (patElementSet->pesPattern[i]->peType == PET_REFERENCE)
1807 + patElement = patElementSet->pesPattern[i];
1809 + if (patElement->peVal.peuRef.prElementIdx == patternElementIdx)
1820 +** Verify, if given pattern element is part of middle pattern set.
1821 +** That's the case, if an element of the pattern set is reference
1822 +** of a middle pattern, which fits to given pattern element.
1823 +** Returns true, if pattern element is part of middle pattern set.
1825 +static int isPartOfMiddlePatternElementSet(
1826 + PatternElementSet *patElementSet,
1827 + int patternElementIdx)
1829 + PatternElement *patElement;
1832 + for (i=0; i<patElementSet->pesNumberOfPattern; i++)
1834 + if (patElementSet->pesPattern[i]->peType == PET_REFERENCE)
1836 + patElement = patElementSet->pesPattern[i];
1838 + if (patElement->peVal.peuRef.prElementIdx == patternElementIdx &&
1839 + patElement->peKind == PEK_MIDDLE)
1850 +** Update start pattern reference depending on next pattern located
1851 +** after start pattern.
1853 +static void considerNextPatternReference(
1854 + MatchPatternTable *table,
1855 + PatternReference *startPatRef,
1856 + PatternReference nxtPatRef,
1859 + MatchPatternTableElement *tabElement;
1860 + PatternElement *startPat;
1861 + MultiPattern *multiStartPat;
1862 + PatternReference patRef;
1866 + * startPatRef needs no adaption, if element index of start pattern
1867 + * and next pattern are equal (i.e. start and next pattern belong
1868 + * to same pattern element).
1870 + if (startPatRef->prElementIdx == nxtPatRef.prElementIdx)
1874 + * Verify, if start pattern belongs to multiple pattern elements
1875 + * (like "ELSE .. FI" & "ELSE .. ESAC").
1877 + startPat = getPatternOfReference( table, *startPatRef );
1879 + if (startPat->peType == PET_MULTIPLE)
1882 + * Check, if next pattern fits to one of the references of
1883 + * the start multi pattern. If so: adapt start pattern reference.
1885 + multiStartPat = &startPat->peVal.peuMulti;
1887 + for (i=0; i<multiStartPat->mpNumberOfReferences; i ++)
1889 + patRef = multiStartPat->mpRefList[i];
1890 + tabElement = table->mptElements[patRef.prElementIdx];
1892 + if (nxtPatRef.prElementIdx == patRef.prElementIdx &&
1893 + tabElement->mpteGroup == groupIdx)
1895 + *startPatRef = patRef;
1903 +** Search for a string pattern in forward direction, starting at
1904 +** given beginPos. Determine related pattern reference of a found
1906 +** Returns true, if a next string pattern was found.
1908 +static int searchPatternForward(
1909 + MatchPatternTable *table,
1910 + regexp *compiledRE,
1911 + SearchRegionInfo *searchRegion,
1912 + const char *delimiters,
1915 + PatternReference *patRef,
1916 + int *highLightCode,
1917 + BackRefInfo *backRefInfo)
1919 + FoundStringInfo foundStringInfo;
1920 + int matchStartPos;
1921 + int absMatchStartPos;
1922 + MatchPatternTableElement *matchedElement;
1924 + *matchEndPos = -1;
1926 + patRef->prElementIdx = NO_ELEMENT_IDX;
1927 + patRef->prKind = PEK_UNKNOWN;
1928 + patRef->prPatternIdx = NO_PATTERN_IDX;
1930 + *highLightCode = IGNORE_HIGHLIGHT_CODE;
1934 + searchRegion->sriText + beginPos,
1937 + beginPos==0 ? searchRegion->sriPrevChar : searchRegion->sriText[beginPos-1],
1938 + searchRegion->sriSuccChar,
1940 + searchRegion->sriText,
1943 + foundStringInfo.fsiStartPtr = compiledRE->startp[0];
1944 + foundStringInfo.fsiEndPtr = compiledRE->endp[0];
1945 + foundStringInfo.fsiLength =
1946 + foundStringInfo.fsiEndPtr - foundStringInfo.fsiStartPtr;
1948 + foundStringInfo.fsiPrevChar =
1949 + foundStringInfo.fsiStartPtr == searchRegion->sriText ?
1950 + searchRegion->sriPrevChar : *(foundStringInfo.fsiStartPtr - 1);
1952 + foundStringInfo.fsiSuccChar =
1953 + *(foundStringInfo.fsiEndPtr) == '\0' ?
1954 + searchRegion->sriSuccChar : *(foundStringInfo.fsiEndPtr);
1956 + foundStringInfo.fsiDelimiters = delimiters;
1958 + if (getPatternInfo(
1965 + * Next string pattern was found in forward direction and
1966 + * a pattern reference could be assigned to: calculate
1967 + * relative & absolute match positions.
1969 + matchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
1970 + *matchEndPos = foundStringInfo.fsiEndPtr - searchRegion->sriText;
1972 + absMatchStartPos = matchStartPos + searchRegion->sriStartOfTextPos;
1974 + matchedElement = table->mptElements[patRef->prElementIdx];
1977 + * get highlight code of found string pattern, if applicable
1979 + if (!matchedElement->mpteIgnoreHighLightInfo)
1982 + HighlightCodeOfPos(searchRegion->sriWindow, absMatchStartPos);
1986 + * setup mono pattern info of found string pattern
1988 + if (matchedElement->mpteIsMonoPattern)
1990 + if (matchedElement->mpteIgnoreHighLightInfo)
1992 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
1997 + * determine mono pattern info depending on highLightCodes
1998 + * before / after found string pattern.
2000 + patRef->prMonoInfo =
2001 + determineMonoPatInfo(
2002 + searchRegion->sriWindow,
2004 + absMatchStartPos - 1,
2005 + *matchEndPos + searchRegion->sriStartOfTextPos,
2011 + patRef->prMonoInfo = PEMI_NOT_MONO;
2014 + return matchStartPos;
2019 + * Found string can't be assigned to a pattern element
2020 + * (should never occur).
2028 + * No next string pattern is found in forward direction.
2035 +** Search for a string pattern in backward direction, starting at
2036 +** given beginPos. Determine related pattern reference of a found
2038 +** Returns true, if a next string pattern was found.
2040 +static int searchPatternBackward(
2041 + MatchPatternTable *table,
2042 + regexp *compiledRE,
2043 + SearchRegionInfo *searchRegion,
2044 + const char *delimiters,
2046 + PatternReference *patRef,
2047 + int *highLightCode,
2048 + int *matchedPatternLength,
2049 + BackRefInfo *backRefInfo)
2051 + FoundStringInfo foundStringInfo;
2052 + int matchStartPos;
2053 + int absMatchStartPos;
2054 + MatchPatternTableElement *matchedElement;
2056 + patRef->prElementIdx = NO_ELEMENT_IDX;
2057 + patRef->prKind = PEK_UNKNOWN;
2058 + patRef->prPatternIdx = NO_PATTERN_IDX;
2060 + *highLightCode = IGNORE_HIGHLIGHT_CODE;
2064 + searchRegion->sriText,
2065 + searchRegion->sriText + beginPos,
2067 + searchRegion->sriPrevChar,
2068 + searchRegion->sriText[beginPos] == '\0' ?
2069 + searchRegion->sriSuccChar : searchRegion->sriText[beginPos + 1],
2071 + searchRegion->sriText,
2074 + foundStringInfo.fsiStartPtr = compiledRE->startp[0];
2075 + foundStringInfo.fsiEndPtr = compiledRE->endp[0];
2076 + foundStringInfo.fsiLength =
2077 + foundStringInfo.fsiEndPtr - foundStringInfo.fsiStartPtr;
2079 + foundStringInfo.fsiPrevChar =
2080 + foundStringInfo.fsiStartPtr == searchRegion->sriText ?
2081 + searchRegion->sriPrevChar : *(foundStringInfo.fsiStartPtr - 1);
2083 + foundStringInfo.fsiSuccChar =
2084 + *(foundStringInfo.fsiEndPtr) == '\0' ?
2085 + searchRegion->sriSuccChar : *(foundStringInfo.fsiEndPtr);
2087 + foundStringInfo.fsiDelimiters = delimiters;
2089 + if (getPatternInfo(
2096 + * Next string pattern was found in backward direction and
2097 + * a pattern reference could be assigned to: calculate
2098 + * relative & absolute match positions.
2100 + matchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
2101 + *matchedPatternLength = foundStringInfo.fsiLength;
2103 + absMatchStartPos = matchStartPos + searchRegion->sriStartOfTextPos;
2105 + matchedElement = table->mptElements[patRef->prElementIdx];
2108 + * get highlight code of found string pattern, if applicable
2110 + if (!matchedElement->mpteIgnoreHighLightInfo)
2113 + HighlightCodeOfPos(searchRegion->sriWindow, absMatchStartPos);
2117 + * setup mono pattern info of found string pattern
2119 + if (matchedElement->mpteIsMonoPattern)
2121 + if (matchedElement->mpteIgnoreHighLightInfo)
2123 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
2128 + * determine mono pattern info depending on highLightCodes
2129 + * before / after found string pattern.
2131 + patRef->prMonoInfo =
2132 + determineMonoPatInfo(
2133 + searchRegion->sriWindow,
2135 + absMatchStartPos - 1,
2136 + absMatchStartPos + *matchedPatternLength,
2142 + patRef->prMonoInfo = PEMI_NOT_MONO;
2145 + return matchStartPos;
2150 + * Found string can't be assigned to a pattern element
2151 + * (should never occur).
2159 + * No next string pattern is found in backward direction.
2166 +** Find matching pattern related to given pattern (stored in
2167 +** 'matchInfo') in forward direction by considering the rules stored in
2168 +** string match table of given window. Determine match position (= abs.
2169 +** pos. of last character of matching string) and length of matching
2170 +** string. If a mono matching pattern couldn't be found in forward
2171 +** direction, then try finding it in backward direction (if found in
2172 +** backward direction, then match position indicates the 1st char. of
2173 +** matching string).
2174 +** Returns true, if a matching pattern was found.
2176 +static int parseStringElementForward(
2177 + MatchingElementInfo *matchInfo,
2178 + SearchRegionInfo *searchRegion,
2181 + int *matchedPatternLength,
2182 + const char *delimiters)
2184 + StringMatchTable *smTable =
2185 + (StringMatchTable *)searchRegion->sriWindow->stringMatchTable;
2186 + MatchPatternTableElement *matchElement = matchInfo->meiElement;
2187 + int beginPos = relCharPos;
2189 + int startStartPos;
2191 + int matchingPatternFound = FALSE;
2194 + * Find matching pattern within text buffer area to parse in
2195 + * forward direction.
2198 + findRelatedForwardPattern(
2202 + matchInfo->meiPatRef,
2203 + matchInfo->meiHighLightCode,
2204 + &matchInfo->meiBackRefInfo,
2208 + if (endEndPos != -1)
2210 + *matchPos = endEndPos - 1 + searchRegion->sriStartOfTextPos;
2211 + *matchedPatternLength = endEndPos - endStartPos;
2213 + matchingPatternFound = TRUE;
2215 + else if (matchElement->mpteIsMonoPattern)
2218 + * mono pattern: forward find fails -> try backward direction.
2219 + * Calc. relative position of 1st char. before found string pattern.
2221 + beginPos = beginPos - matchInfo->meiLength - 1;
2226 + findRelatedStartPattern(
2230 + matchInfo->meiPatRef,
2231 + matchInfo->meiHighLightCode,
2232 + &matchInfo->meiBackRefInfo,
2234 + matchedPatternLength);
2236 + if (startStartPos != -1)
2238 + matchInfo->meiDirection = SEARCH_BACKWARD;
2240 + *matchPos = startStartPos + searchRegion->sriStartOfTextPos;
2242 + matchingPatternFound = TRUE;
2247 + return matchingPatternFound;
2251 +** Find matching pattern related to given begin pattern reference
2252 +** in forward direction by considering the rules stored in given
2253 +** string match table. Determine match position (= relative
2254 +** pos. of last character of matching string).
2255 +** Returns -1, if no matching pattern was found. Else the relative
2256 +** position of 1st char. of matching string is returned.
2258 +static int findRelatedForwardPattern(
2259 + StringMatchTable *table,
2260 + SearchRegionInfo *searchRegion,
2261 + const char *delimiters,
2262 + PatternReference beginPatRef,
2263 + int beginPatHighLightCode,
2264 + BackRefInfo *beginPatBackRefInfo,
2268 + MatchPatternTable *patTable = table->smtAllPatterns;
2269 + int startPos = beginPos;
2270 + int nxtPatStartPos = 0;
2271 + int nxtPatEndPos = 0;
2272 + PatternReference nxtPatRef;
2273 + int nxtPatHighLightCode;
2274 + BackRefInfo nxtPatBackRefInfo;
2275 + PatternStackElement stack[MAX_NESTED_PATTERNS];
2277 + PatternReference startPatRef;
2278 + MatchPatternTableElement *currentElement;
2280 + regexp *groupPatRE;
2281 + regexp *currentPatRE;
2282 + int skipToEnd = FALSE;
2283 + int beginPatternIsMono;
2286 + printf("Forward Start Pos: %d K: %s EI: %d PI: %d HC: %d <%s>\n",
2288 + patElemKindToString(beginPatRef.prKind),
2289 + beginPatRef.prElementIdx,
2290 + beginPatRef.prPatternIdx,
2291 + beginPatHighLightCode,
2292 + getPatternForDebug(patTable, beginPatRef) );
2296 + * put begin pattern info on stack
2298 + stack[stackIdx].psePatRef = beginPatRef;
2299 + stack[stackIdx].pseHighLightCode = beginPatHighLightCode;
2300 + stack[stackIdx].pseBackRefInfo = *beginPatBackRefInfo;
2303 + currentElement = patTable->mptElements[beginPatRef.prElementIdx];
2305 + beginPatternIsMono = currentElement->mpteIsMonoPattern;
2307 + groupIdx = currentElement->mpteGroup;
2310 + * no next pattern can be found, if there is no group assigned
2311 + * to begin pattern (should never occur)
2313 + if (groupIdx == NO_GROUP_IDX)
2315 + *matchEndPos = -1;
2321 + * Remember pattern (= keywords) regular expression of context
2322 + * group related to begin pattern. Use it for forward search.
2324 + groupPatRE = table->smtGroups[groupIdx]->mpgeKeywordRE;
2325 + currentPatRE = groupPatRE;
2328 + * Use start / end pattern regular expression if skip to end is
2329 + * set for begin pattern.
2331 + if (currentElement->mpteSkipBtwnStartEnd)
2333 + currentPatRE = currentElement->mpteStartEndRE;
2337 + while (stackIdx > 0 && nxtPatStartPos != -1)
2340 + * Search for next string pattern in forward direction.
2343 + searchPatternForward(
2351 + &nxtPatHighLightCode,
2352 + &nxtPatBackRefInfo );
2354 + startPatRef = stack[stackIdx-1].psePatRef;
2356 + if (nxtPatStartPos == -1)
2359 + * no next pattern found -> leave loop
2362 + printf(" SI: %d [start K: %s EI: %d PI %d] Pos: %d --> no next pat. found\n",
2364 + patElemKindToString(startPatRef.prKind),
2365 + startPatRef.prElementIdx,
2366 + startPatRef.prPatternIdx,
2373 + * Update start pattern reference depending on next pattern
2374 + * located after start pattern.
2376 + considerNextPatternReference(
2383 + * If current found match pattern table element is a mono pattern and
2384 + * skip to start pattern is active, then the found pattern string is
2385 + * a END one in case of ambiguous or no syntax was detected.
2388 + (nxtPatRef.prMonoInfo == PEMI_MONO_AMBIGUOUS_SYNTAX ||
2389 + nxtPatRef.prMonoInfo == PEMI_MONO_NOT_SYNTAX_BASED))
2391 + nxtPatRef.prKind = PEK_END;
2395 + printf(" SI: %d [start K: %s EI: %d PI %d] Pos: %d-%d K: %s EI: %d PI: %d HC: %d f=<%s> ",
2397 + patElemKindToString(startPatRef.prKind),
2398 + startPatRef.prElementIdx,
2399 + startPatRef.prPatternIdx,
2402 + patElemKindToString(nxtPatRef.prKind),
2403 + nxtPatRef.prElementIdx,
2404 + nxtPatRef.prPatternIdx,
2405 + nxtPatHighLightCode,
2406 + getPatternForDebug(patTable, nxtPatRef) );
2407 + printFoundStringForDebug(
2408 + searchRegion->sriWindow,
2409 + nxtPatStartPos + searchRegion->sriStartOfTextPos,
2410 + nxtPatEndPos - nxtPatStartPos);
2414 + if (nxtPatRef.prKind == PEK_START)
2416 + if (stackIdx >= MAX_NESTED_PATTERNS)
2419 + printf("FORWARD: MAX. NESTED PATTERN DEPTH REACHED !\n");
2421 + nxtPatStartPos = -1;
2422 + nxtPatEndPos = -1;
2424 + else if (!skipToEnd)
2427 + * Put next pattern on stack, if contents between start /
2428 + * end shouldn't be skipped (if "skipToEnd" is set,
2429 + * a (usually illegal) start pattern to skip inside the
2430 + * skipped one is found (e.g. \* \* ..)
2432 + stack[stackIdx].psePatRef = nxtPatRef;
2433 + stack[stackIdx].pseHighLightCode = nxtPatHighLightCode;
2434 + stack[stackIdx].pseBackRefInfo = nxtPatBackRefInfo;
2437 + currentElement = patTable->mptElements[nxtPatRef.prElementIdx];
2440 + * Use start / end pattern regular expression if skip to
2441 + * end is set for found start pattern.
2443 + if (currentElement->mpteSkipBtwnStartEnd)
2445 + currentPatRE = currentElement->mpteStartEndRE;
2449 + else if (beginPatternIsMono)
2452 + * skip to end is set and a mono pattern start is reached:
2453 + * trigger backward search by returning "not found"
2456 + printf(" ---> mono pattern (re-)start -> trigger backward search\n");
2458 + nxtPatStartPos = -1;
2459 + nxtPatEndPos = -1;
2464 + printf(" ---> skip to end: illegal (re-)start pattern !\n");
2468 + else if (nxtPatRef.prKind == PEK_END)
2471 + * ignore current found pattern, if it doesn't fit to the prev.
2474 + if (isPartOfPattern(
2476 + nxtPatRef.prElementIdx,
2477 + startPatRef.prElementIdx,
2479 + (stack[stackIdx - 1].pseHighLightCode == nxtPatHighLightCode ||
2480 + stack[stackIdx - 1].pseHighLightCode == IGNORE_HIGHLIGHT_CODE ||
2481 + nxtPatHighLightCode == IGNORE_HIGHLIGHT_CODE) &&
2482 + doesBackRefInfoMatch(
2483 + &stack[stackIdx - 1].pseBackRefInfo,
2484 + &nxtPatBackRefInfo))
2487 + * use context group pattern again, if end pattern to skip
2492 + currentPatRE = groupPatRE;
2493 + skipToEnd = FALSE;
2497 + * pop. related start pattern from stack.
2502 + else if (!skipToEnd)
2505 + * middle pattern was found: ignore it, if found middle pattern
2506 + * doesn't belong to begin pattern.
2508 + if (stackIdx == 1 &&
2511 + startPatRef.prElementIdx,
2512 + nxtPatRef.prElementIdx,
2513 + nxtPatRef.prKind) &&
2514 + (beginPatHighLightCode == nxtPatHighLightCode ||
2515 + beginPatHighLightCode == IGNORE_HIGHLIGHT_CODE ||
2516 + nxtPatHighLightCode == IGNORE_HIGHLIGHT_CODE) &&
2517 + doesBackRefInfoMatch(
2518 + beginPatBackRefInfo,
2519 + &nxtPatBackRefInfo))
2526 + startPos = nxtPatEndPos;
2529 + *matchEndPos = nxtPatEndPos;
2531 + return nxtPatStartPos;
2535 +** Find matching pattern related to given pattern (stored in
2536 +** 'matchInfo') in backward direction by considering the rules stored in
2537 +** string match table of given window. Determine match position (= abs.
2538 +** pos. of 1st character of matching string) and length of matching
2540 +** Returns true, if a matching pattern was found.
2542 +static int parseStringElementBackward(
2543 + MatchingElementInfo *matchInfo,
2544 + SearchRegionInfo *searchRegion,
2547 + int *matchedPatternLength,
2548 + const char *delimiters)
2550 + StringMatchTable *smTable =
2551 + (StringMatchTable *)searchRegion->sriWindow->stringMatchTable;
2553 + int startStartPos;
2554 + int matchingPatternFound = FALSE;
2557 + * determine begin of search in string buffer (= relative position
2558 + * of 1st char. before found string pattern.)
2560 + beginPos = relCharPos - matchInfo->meiLength - 1;
2566 + * Find matching pattern within text buffer area to parse in
2567 + * backward direction.
2570 + findRelatedStartPattern(
2574 + matchInfo->meiPatRef,
2575 + matchInfo->meiHighLightCode,
2576 + &matchInfo->meiBackRefInfo,
2578 + matchedPatternLength);
2580 + if (startStartPos != -1)
2582 + *matchPos = startStartPos + searchRegion->sriStartOfTextPos;
2583 + matchingPatternFound = TRUE;
2586 + return matchingPatternFound;
2590 +** Find matching pattern related to given begin pattern reference
2591 +** in backward direction by considering the rules stored in given
2592 +** string match table. Determine match position (= relative
2593 +** pos. of 1st character of matching string).
2594 +** Returns -1, if no matching pattern was found. Else the relative
2595 +** position of 1st char. of matching string is returned.
2597 +static int findRelatedStartPattern(
2598 + StringMatchTable *table,
2599 + SearchRegionInfo *searchRegion,
2600 + const char *delimiters,
2601 + PatternReference beginPatRef,
2602 + int beginPatHighLightCode,
2603 + BackRefInfo *beginPatBackRefInfo,
2605 + int *matchedPatternLength)
2607 + MatchPatternTable *patTable = table->smtAllPatterns;
2608 + int startPos = beginPos;
2609 + int prevStartPos = 0;
2610 + PatternReference prevPatRef;
2611 + int prevPatHighLightCode;
2612 + BackRefInfo prevPatBackRefInfo;
2613 + PatternStackElement stack[MAX_NESTED_PATTERNS];
2615 + MatchPatternTableElement *currentElement;
2617 + regexp *groupPatRE;
2618 + regexp *currentPatRE;
2619 + int skipToStart = FALSE;
2622 + * put begin pattern info on stack
2624 + stack[stackIdx].psePatRef = beginPatRef;
2625 + stack[stackIdx].pseHighLightCode = beginPatHighLightCode;
2626 + stack[stackIdx].pseBackRefInfo = *beginPatBackRefInfo;
2629 + currentElement = patTable->mptElements[beginPatRef.prElementIdx];
2632 + printf("Backward Start Pos: %d K: %s EI: %d PI: %d HC: %d <%s>\n",
2634 + patElemKindToString(beginPatRef.prKind),
2635 + beginPatRef.prElementIdx,
2636 + beginPatRef.prPatternIdx,
2637 + beginPatHighLightCode,
2638 + getPatternForDebug(patTable, beginPatRef) );
2641 + groupIdx = currentElement->mpteGroup;
2644 + * no start pattern can be found, if there is no group assigned
2645 + * to begin pattern (should never occur)
2647 + if (groupIdx == NO_GROUP_IDX)
2653 + * Remember pattern (= keywords) regular expression of context
2654 + * group related to begin pattern. Use it for backward search.
2656 + groupPatRE = table->smtGroups[groupIdx]->mpgeKeywordRE;
2657 + currentPatRE = groupPatRE;
2660 + * Use start / end pattern regular expression if skip to start is
2661 + * set for begin pattern.
2663 + if (currentElement->mpteSkipBtwnStartEnd)
2665 + currentPatRE = currentElement->mpteStartEndRE;
2666 + skipToStart = TRUE;
2669 + while (stackIdx > 0 && prevStartPos != -1)
2672 + * Search for previous string pattern in backward direction.
2675 + searchPatternBackward(
2682 + &prevPatHighLightCode,
2683 + matchedPatternLength,
2684 + &prevPatBackRefInfo );
2686 + if (prevStartPos == -1)
2689 + * no previous pattern found -> leave loop
2692 + printf(" SI: %d [K: %s start EI: %d PI %d] Pos: %d --> no next pat. found\n",
2694 + patElemKindToString(stack[stackIdx -1].psePatRef.prKind),
2695 + stack[stackIdx -1].psePatRef.prElementIdx,
2696 + stack[stackIdx -1].psePatRef.prPatternIdx,
2703 + * Update previous pattern reference depending on last stack
2704 + * pattern, which is located in text puffer after previous
2707 + considerNextPatternReference(
2710 + stack[stackIdx - 1].psePatRef,
2714 + * If current found match pattern table element is a mono pattern and
2715 + * skip to start pattern is active, then the found pattern string is
2716 + * a START one in case of ambiguous or no syntax was detected.
2718 + if (skipToStart &&
2719 + (prevPatRef.prMonoInfo == PEMI_MONO_AMBIGUOUS_SYNTAX ||
2720 + prevPatRef.prMonoInfo == PEMI_MONO_NOT_SYNTAX_BASED))
2722 + prevPatRef.prKind = PEK_START;
2726 + printf(" SI: %d [K: %s start EI: %d PI %d] Pos: %d K: %s EI: %d PI: %d HC: %d f=<%s> ",
2728 + patElemKindToString(stack[stackIdx -1].psePatRef.prKind),
2729 + stack[stackIdx -1].psePatRef.prElementIdx,
2730 + stack[stackIdx -1].psePatRef.prPatternIdx,
2732 + patElemKindToString(prevPatRef.prKind),
2733 + prevPatRef.prElementIdx,
2734 + prevPatRef.prPatternIdx,
2735 + prevPatHighLightCode,
2736 + getPatternForDebug(patTable, prevPatRef) );
2737 + printFoundStringForDebug(
2738 + searchRegion->sriWindow,
2739 + prevStartPos + searchRegion->sriStartOfTextPos,
2740 + *matchedPatternLength);
2744 + if (prevPatRef.prKind == PEK_START)
2747 + * If the end pattern of the previous pattern set is a reference,
2748 + * then the prev. element index is the one of the ref. (due to this
2749 + * string was found before and was stored on stack)
2751 + if (patTable->mptElements[prevPatRef.prElementIdx]->mpteGroup == groupIdx)
2753 + considerStackPatReference(
2754 + &patTable->mptElements[prevPatRef.prElementIdx]->mpteEnd,
2755 + stack[stackIdx - 1].psePatRef.prElementIdx,
2756 + &prevPatRef.prElementIdx);
2760 + * Ignore current found pattern, if it doesn't fit to the prev.
2763 + if (stack[stackIdx - 1].psePatRef.prElementIdx == prevPatRef.prElementIdx &&
2764 + (stack[stackIdx - 1].pseHighLightCode == prevPatHighLightCode ||
2765 + stack[stackIdx - 1].pseHighLightCode == IGNORE_HIGHLIGHT_CODE ||
2766 + prevPatHighLightCode == IGNORE_HIGHLIGHT_CODE) &&
2767 + doesBackRefInfoMatch(
2768 + &stack[stackIdx - 1].pseBackRefInfo,
2769 + &prevPatBackRefInfo))
2772 + * use context group pattern again, if start pattern
2773 + * to skip to was found.
2777 + currentPatRE = groupPatRE;
2778 + skipToStart = FALSE;
2782 + * pop. related end pattern from stack.
2787 + else if (prevPatRef.prKind == PEK_END)
2789 + if (stackIdx >= MAX_NESTED_PATTERNS)
2792 + printf("BACKWARD: MAX. NESTED PATTERN DEPTH REACHED !\n");
2794 + prevStartPos = -1;
2796 + else if (!skipToStart)
2799 + * Put prev. pattern on stack, if contents between start /
2800 + * end shouldn't be skipped (if "skipToStart" is set,
2801 + * a (usually illegal) end pattern to skip inside the
2802 + * skipped one is found (e.g. *\ *\ ..)
2804 + stack[stackIdx].psePatRef = prevPatRef;
2805 + stack[stackIdx].pseHighLightCode = prevPatHighLightCode;
2806 + stack[stackIdx].pseBackRefInfo = prevPatBackRefInfo;
2810 + patTable->mptElements[prevPatRef.prElementIdx];
2813 + * Use start / end pattern regular expression if skip to
2814 + * end is set for found end pattern.
2816 + if (currentElement->mpteSkipBtwnStartEnd)
2818 + currentPatRE = currentElement->mpteStartEndRE;
2819 + skipToStart = TRUE;
2823 + startPos = prevStartPos - 1;
2826 + return prevStartPos;
2830 +** Adapt found pattern element index depending on
2831 +** the info stored on (last) stack element and
2832 +** a given pattern set (belonging to the found pattern).
2834 +static void considerStackPatReference(
2835 + PatternElementSet *patSet,
2836 + int stackElementIdx,
2837 + int *foundElementIdx)
2839 + PatternElement *patElement;
2843 + * If found pattern index already indicates, that found pattern
2844 + * belongs to pattern set stored on stack, then no adaption is needed
2846 + if (*foundElementIdx == stackElementIdx)
2850 + * Check all elements of given pattern element set:
2852 + for (i=0; i < patSet->pesNumberOfPattern; i++)
2854 + patElement = patSet->pesPattern[i];
2857 + * If this set element is a reference and this reference fits
2858 + * to the element stored on stack, then adapt found element index:
2859 + * indicate, that found pattern belongs to pattern set stored on stack
2861 + if (patElement->peType == PET_REFERENCE &&
2862 + patElement->peVal.peuRef.prElementIdx == stackElementIdx)
2864 + *foundElementIdx = stackElementIdx;
2872 +** Determines, if a string pattern is located at the given position
2873 +** "relBeginPos" in the given "searchRegion". A string pattern is
2874 +** found, if the pattern is located just before given position
2875 +** "relBeginPos" OR if "relBeginPos" is located within a string pattern.
2877 +** Returns true, if the given "pattern" is located at
2878 +** "relBeginPos". "matchInfo" holds all info needed about matched
2879 +** "start" string pattern.
2881 +static int getPatternLocatedAtPos(
2882 + regexp *usedPatRE,
2883 + MatchPatternTable *table,
2884 + SearchRegionInfo *searchRegion,
2886 + MatchingElementInfo *matchInfo,
2887 + const char *delimiters)
2889 + int searchStartPos = *relBeginPos;
2890 + PatternReference *patRef = &matchInfo->meiPatRef;
2891 + FoundStringInfo foundStringInfo;
2892 + int relMatchStartPos;
2893 + int relMatchEndPos;
2895 + patRef->prElementIdx = NO_ELEMENT_IDX;
2896 + patRef->prKind = PEK_UNKNOWN;
2897 + patRef->prPatternIdx = NO_PATTERN_IDX;
2899 + matchInfo->meiHighLightCode = IGNORE_HIGHLIGHT_CODE;
2900 + matchInfo->meiAbsStartPos = -1;
2901 + matchInfo->meiLength = 0;
2904 + * No backward search possible, if we are at beginning of
2907 + if (searchStartPos == 0)
2911 + * Search in backward direction for 1st occurance of a string pattern
2912 + * starting one char before "searchStartPos".
2916 + searchRegion->sriText,
2917 + searchRegion->sriText + searchStartPos - 1,
2919 + searchRegion->sriPrevChar,
2920 + searchRegion->sriText[searchStartPos],
2922 + searchRegion->sriText,
2926 + * String pattern was found:
2928 + foundStringInfo.fsiStartPtr = usedPatRE->startp[0];
2929 + foundStringInfo.fsiEndPtr = usedPatRE->endp[0];
2930 + foundStringInfo.fsiLength =
2931 + foundStringInfo.fsiEndPtr - foundStringInfo.fsiStartPtr;
2933 + relMatchEndPos = foundStringInfo.fsiEndPtr - searchRegion->sriText;
2934 + relMatchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
2937 + * Is found pattern located exactly one char before "relBeginPos" OR
2938 + * is "relBeginPos" located within found string pattern ?
2939 + * Note: "relMatchEndPos" indicates 1st pos. in "sriText"
2940 + * which does *not* belong to found string anymore.
2942 + if ((*relBeginPos == relMatchEndPos) ||
2943 + (*relBeginPos >= relMatchStartPos &&
2944 + *relBeginPos < relMatchEndPos))
2946 + *relBeginPos = relMatchEndPos;
2949 + * Determine match element info related to found string.
2951 + matchInfo->meiAbsStartPos =
2952 + foundStringInfo.fsiStartPtr - searchRegion->sriText +
2953 + searchRegion->sriStartOfTextPos;
2954 + matchInfo->meiLength = foundStringInfo.fsiLength;
2956 + foundStringInfo.fsiPrevChar =
2957 + foundStringInfo.fsiStartPtr == searchRegion->sriText ?
2958 + searchRegion->sriPrevChar : *(foundStringInfo.fsiStartPtr - 1);
2960 + foundStringInfo.fsiSuccChar =
2961 + *(foundStringInfo.fsiEndPtr) == '\0' ?
2962 + searchRegion->sriSuccChar : *(foundStringInfo.fsiEndPtr);
2964 + foundStringInfo.fsiDelimiters = delimiters;
2967 + getMatchedElementInfo(
2968 + searchRegion->sriWindow,
2979 +** Get all needed info related to matched "start" string pattern
2980 +** (given by parameter "foundStringInfo").
2982 +** Returns true, if info was determined successfully.
2984 +static int getMatchedElementInfo(
2985 + WindowInfo *window,
2986 + MatchPatternTable *table,
2987 + FoundStringInfo *foundStringInfo,
2988 + MatchingElementInfo *matchInfo)
2990 + PatternReference *patRef = &matchInfo->meiPatRef;
2991 + int absMatchStartPos = matchInfo->meiAbsStartPos;
2992 + MatchPatternTableElement *matchedElement;
2994 + if (getPatternInfo(
2998 + &matchInfo->meiBackRefInfo))
3001 + * A pattern reference could be assigned to found string:
3003 + matchedElement = table->mptElements[patRef->prElementIdx];
3005 + matchInfo->meiElement = matchedElement;
3008 + * get highlight code of found string pattern, if applicable
3010 + if (!matchedElement->mpteIgnoreHighLightInfo)
3012 + matchInfo->meiHighLightCode =
3013 + HighlightCodeOfPos(window, absMatchStartPos);
3017 + * setup mono pattern info of found string pattern
3019 + if (matchedElement->mpteIsMonoPattern)
3021 + if (matchedElement->mpteIgnoreHighLightInfo)
3023 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
3028 + * determine mono pattern info depending on highLightCodes
3029 + * before / after found string pattern.
3031 + patRef->prMonoInfo =
3032 + determineMonoPatInfo(
3034 + matchInfo->meiHighLightCode,
3035 + absMatchStartPos - 1,
3036 + absMatchStartPos + matchInfo->meiLength,
3042 + patRef->prMonoInfo = PEMI_NOT_MONO;
3050 + * Found string can't be assigned to a pattern element
3051 + * (should never occur).
3058 +** Returns string pattern of given pattern element.
3060 +StringPattern *GetStringPattern(
3061 + MatchPatternTable *table,
3062 + PatternElement *pattern )
3064 + switch (pattern->peType)
3067 + return &pattern->peVal.peuSingle;
3070 + case PET_MULTIPLE:
3071 + return &pattern->peVal.peuMulti.mpStringPattern;
3074 + case PET_REFERENCE:
3075 + return GetStringPattern(
3077 + getPatternOfReference(table, pattern->peVal.peuRef));
3082 + * never reached; just to make compiler happy
3088 +** Returns pattern element of given pattern reference.
3090 +static PatternElement *getPatternOfReference(
3091 + MatchPatternTable *table,
3092 + PatternReference patRef)
3094 + MatchPatternTableElement **element = table->mptElements;
3096 + return element[ patRef.prElementIdx ]->mpteAll.pesPattern[patRef.prPatternIdx];
3100 +static char *getPatternForDebug(
3101 + MatchPatternTable *table,
3102 + PatternReference patRef )
3104 + if (patRef.prElementIdx < 0)
3112 + getPatternOfReference(table, patRef))->spText;
3115 +static char *patElemKindToString(
3116 + PatternElementKind patElemKind)
3118 + if (patElemKind == PEK_START)
3120 + else if (patElemKind == PEK_MIDDLE)
3122 + else if (patElemKind == PEK_END)
3128 +static void printFoundStringForDebug(
3129 + WindowInfo *window,
3134 + BufGetRange( window->buffer, absStartPos, absStartPos + length);
3136 + printf("%d (abs.) <%s>",
3145 diff --quilt /dev/null new/source/patternMatch.h
3147 +++ new/source/patternMatch.h
3149 +/* $Id: patternMatch.h,v 1.2 2003/10/11 16:45:25 uleh Exp $ */
3151 +#ifndef NEDIT_PATTERNMATCH_H_INCLUDED
3152 +#define NEDIT_PATTERNMATCH_H_INCLUDED
3154 +#include "regularExp.h"
3156 +#define NO_GROUP_IDX -1
3157 +#define NO_ELEMENT_IDX -1
3158 +#define NO_PATTERN_IDX -1
3160 +#define MAX_GLOBAL_BACK_REF_ID 9
3161 +#define NO_LOCAL_BACK_REF_ID -1
3168 +} PatternElementKind;
3172 + PEMI_MONO_NOT_SYNTAX_BASED,
3173 + PEMI_MONO_AMBIGUOUS_SYNTAX,
3174 + PEMI_MONO_DEFINITE_SYNTAX
3175 +} PatternElementMonoInfo;
3177 +typedef struct _PatternReference {
3178 + PatternElementKind prKind;
3179 + PatternElementMonoInfo prMonoInfo;
3182 +} PatternReference;
3188 +} MatchPatternType;
3190 +typedef struct _MatchPatternSequenceElement {
3192 + MatchPatternType mpseType;
3194 +} MatchPatternSequenceElement;
3196 +typedef struct _MatchPatternGroupElement {
3198 + int mpgeNumberOfSubPatterns;
3199 + char **mpgeSubPatternIds;
3200 + regexp *mpgeKeywordRE;
3201 +} MatchPatternGroupElement;
3208 +} PatternWordBoundary;
3210 +typedef struct _StrPatBackRefElement{
3211 + int spbreLocalBackRefID;
3212 + char *spbreRegExpText;
3213 +} StrPatBackRefElement;
3215 +typedef struct _StringPattern {
3218 + PatternWordBoundary spWordBoundary;
3219 + int spCaseInsensitive;
3220 + int spRegularExpression;
3223 + int spBackRefParsed;
3224 + int spBackRefResolved;
3225 + StrPatBackRefElement spOwnGlobalBackRef[MAX_GLOBAL_BACK_REF_ID];
3226 + int spGlobalToLocalBackRef[MAX_GLOBAL_BACK_REF_ID];
3229 +typedef struct _MultiPattern {
3230 + StringPattern mpStringPattern;
3231 + int mpNumberOfReferences;
3232 + PatternReference *mpRefList;
3239 +} PatternElementType;
3241 +typedef struct _PatternElement {
3243 + PatternElementKind peKind;
3244 + PatternElementType peType;
3246 + StringPattern peuSingle;
3247 + MultiPattern peuMulti;
3248 + PatternReference peuRef;
3252 +typedef struct _PatternElementSet {
3253 + int pesNumberOfPattern;
3254 + PatternElement **pesPattern;
3255 +} PatternElementSet;
3257 +typedef struct _GlobalBackRefElement{
3258 + StringPattern *gbreDefByStrPat;
3259 + char *gbreRegExpText;
3260 +} GlobalBackRefElement;
3262 +typedef struct _MatchPatternTableElement {
3265 + MatchPatternType mpteType;
3267 + PatternElementSet mpteAll;
3268 + PatternElementSet mpteStart;
3269 + PatternElementSet mpteMiddle;
3270 + PatternElementSet mpteEnd;
3272 + int mpteIsMonoPattern;
3273 + int mpteSkipBtwnStartEnd;
3274 + int mpteIgnoreHighLightInfo;
3275 + regexp *mpteStartEndRE;
3276 + GlobalBackRefElement mpteGlobalBackRef[MAX_GLOBAL_BACK_REF_ID];
3277 +} MatchPatternTableElement;
3279 +typedef struct _MatchPatternTable {
3280 + int mptNumberOfElements;
3281 + MatchPatternTableElement **mptElements;
3282 +} MatchPatternTable;
3284 +typedef struct _StringMatchTable {
3285 + char *smtLanguageMode;
3286 + MatchPatternTable *smtAllPatterns;
3287 + regexp *smtAllPatRE;
3288 + regexp *smtFlashPatRE;
3289 + regexp *smtUsedPatRE;
3290 + int smtNumberOfGroups;
3291 + MatchPatternGroupElement **smtGroups;
3292 + int smtNumberOfSeqElements;
3293 + MatchPatternSequenceElement **smtSequence;
3294 +} StringMatchTable;
3304 +int FindMatchingString(
3305 + WindowInfo *window,
3306 + MatchingType matchingType,
3314 +StringPattern *GetStringPattern(
3315 + MatchPatternTable *table,
3316 + PatternElement *pattern);
3318 +#endif /* NEDIT_PATTERNMATCH_H_INCLUDED */
3319 diff --quilt /dev/null new/source/patternMatchData.c
3321 +++ new/source/patternMatchData.c
3323 +static const char CVSID[] = "$Id: patternMatchData.c,v 1.4 2004/10/27 21:57:12 uleh Exp $";
3324 +/*******************************************************************************
3326 +* patternMatchData.c -- Maintain and allow user to edit a matching pattern list*
3327 +* used for pattern matching *
3329 +* Copyright (C) 2003-2004, Uwe Lehnert *
3331 +* This is free software; you can redistribute it and/or modify it under the *
3332 +* terms of the GNU General Public License as published by the Free Software *
3333 +* Foundation; either version 2 of the License, or (at your option) any later *
3334 +* version. In addition, you may distribute versions of this program linked to *
3335 +* Motif or Open Motif. See README for details. *
3337 +* This software is distributed in the hope that it will be useful, but WITHOUT *
3338 +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
3339 +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
3340 +* for more details. *
3342 +* You should have received a copy of the GNU General Public License along with *
3343 +* software; if not, write to the Free Software Foundation, Inc., 59 Temple *
3344 +* Place, Suite 330, Boston, MA 02111-1307 USA *
3346 +* Nirvana Text Editor *
3347 +* October 27, 2004 *
3349 +* Written by Uwe Lehnert *
3351 +*******************************************************************************/
3352 +#ifdef HAVE_CONFIG_H
3353 +#include "../config.h"
3356 +#include <stdlib.h>
3358 +#include <limits.h>
3359 +#include <string.h>
3363 +#include "../util/VMSparam.h"
3366 +#include <sys/param.h>
3371 +#include <Xm/Form.h>
3372 +#include <Xm/Frame.h>
3373 +#include <Xm/Text.h>
3374 +#include <Xm/LabelG.h>
3375 +#include <Xm/PushB.h>
3376 +#include <Xm/PushBG.h>
3377 +#include <Xm/ToggleB.h>
3378 +#include <Xm/RowColumn.h>
3379 +#include <Xm/SeparatoG.h>
3381 +#include "../util/misc.h"
3382 +#include "../util/DialogF.h"
3383 +#include "../util/managedList.h"
3385 +#include "regularExp.h"
3386 +#include "textBuf.h"
3388 +#include "window.h"
3389 +#include "preferences.h"
3394 +#include "patternMatch.h"
3395 +#include "patternMatchData.h"
3397 +#ifdef HAVE_DEBUG_H
3398 +#include "../debug.h"
3404 +#define MAX_LOCAL_BACK_REF_ID 9
3405 +#define LOCAL_BACK_REF_ID_USED -2
3407 +#define MAX_NUMBER_MIDDLE_PATTERN 10
3408 +#define MAX_STRING_PATTERNS 30
3409 +#define MAX_NBR_MATCH_PATTERNS 50
3410 +#define MAX_NBR_MATCH_PATTERN_GROUPS 50
3411 +#define MAX_NBR_SEQ_ELEMENTS MAX_NBR_MATCH_PATTERNS + MAX_NBR_MATCH_PATTERN_GROUPS
3413 +#define MATCH_PAT_NAME_LBL_TXT "Matching Pattern Name"
3414 +#define STRING_PATTERNS_LBL_TXT "String Patterns"
3417 +#define LIST_RIGHT 41
3418 +#define PLAIN_LM_STRING "PLAIN"
3420 +#define SPNM_NONE_SELECTED "none selected"
3422 +#define KEEP_LANGUAGE_MODE True
3423 +#define DISCARD_LANGUAGE_MODE False
3425 +#define STRING_PATTERN_DIALOG True
3426 +#define CONTEXT_GROUP_DIALOG False
3429 + * local data definitions
3431 +typedef struct _ErrorInfo {
3433 + char *eiLanguageMode;
3434 + char *eiMPTabElementName;
3435 + char *eiStringPatText;
3436 + char *eiRegExpCompileMsg;
3440 +typedef struct _BackRefBracketInfo {
3442 + char *brbiContentStart;
3443 + int brbiNestingLevel;
3444 +} BackRefBracketInfo;
3446 +typedef struct _RegExpStringInfo {
3447 + int resiNbrOfAddedMultiPat;
3448 + PatternReference **resiAddedMultiPat;
3449 + char *resiNoneWBRegExpString;
3450 + char *resiLeftWBRegExpString;
3451 + char *resiRightWBRegExpString;
3452 + char *resiBothWBRegExpString;
3453 + int resiLocalBackRefID;
3454 +} RegExpStringInfo;
3456 +typedef struct _ReadMatchPatternInfo {
3457 + int rmpiNbrOfElements;
3458 + MatchPatternTableElement *rmpiElement[MAX_NBR_MATCH_PATTERNS];
3459 + int rmpiNbrOfGroups;
3460 + MatchPatternGroupElement *rmpiGroup[MAX_NBR_MATCH_PATTERN_GROUPS];
3461 + int rmpiNbrOfSeqElements;
3462 + MatchPatternSequenceElement *rmpiSequence[MAX_NBR_SEQ_ELEMENTS];
3463 + regexp *rmpiAllPatRE;
3464 + regexp *rmpiFlashPatRE;
3465 +} ReadMatchPatternInfo;
3467 +typedef struct _DialogStringPatternElement {
3469 + PatternElementKind dspeKind;
3470 + PatternWordBoundary dspeWordBoundary;
3471 + int dspeCaseInsensitive;
3472 + int dspeRegularExpression;
3473 +} DialogStringPatternElement;
3475 +typedef struct _DialogStringPatterns {
3476 + int dspNumberOfPatterns;
3477 + DialogStringPatternElement *dspElements[MAX_STRING_PATTERNS];
3478 +} DialogStringPatterns;
3480 +typedef struct _DialogMatchPatternTableElement {
3482 + MatchPatternType dmpteType;
3483 + DialogStringPatterns dmptePatterns;
3484 + int dmpteSkipBtwnStartEnd;
3485 + int dmpteIgnoreHighLightInfo;
3487 +} DialogMatchPatternTableElement;
3489 +typedef struct _DialogMatchPatternGroupElement {
3491 + int dmpgeNumberOfSubPatterns;
3492 + char *dmpgeSubPatternIds[MAX_NBR_MATCH_PATTERNS];
3493 +} DialogMatchPatternGroupElement;
3495 +typedef struct _DialogMatchPatternSequenceElement {
3497 + MatchPatternType dmpseType;
3500 +} DialogMatchPatternSequenceElement;
3502 +typedef struct _DialogMatchPatternInfo {
3503 + int dmpiNbrOfSeqElements;
3504 + DialogMatchPatternSequenceElement *dmpiSequence[MAX_NBR_SEQ_ELEMENTS];
3505 +} DialogMatchPatternInfo;
3511 +} DMPTranslationResult;
3513 +typedef struct _NameList {
3515 + char *nlId[MAX_NBR_SEQ_ELEMENTS + 1];
3519 + * prototypes of local functions
3521 +static void treatDuplicatedPattern(
3522 + MatchPatternTable *table,
3523 + PatternElement *prevPattern,
3524 + PatternReference prevPatRef,
3525 + PatternElement *lastPattern,
3526 + PatternReference lastPatRef);
3527 +static void treatDuplicatedPatternElements(
3528 + MatchPatternTable *table,
3529 + MatchPatternTableElement *prevElement,
3530 + int prevElementIdx,
3531 + PatternElement *lastPattern,
3532 + PatternReference lastPatRef);
3533 +static void treatDuplicatedMTElements(
3534 + MatchPatternTable *table,
3535 + MatchPatternTableElement *prevElement,
3536 + int prevElementIdx,
3537 + MatchPatternTableElement *lastElement,
3538 + int lastElementIdx);
3539 +static void treatDuplicatedMTEntries(
3540 + MatchPatternTableElement **element,
3541 + int nbrOfElements);
3543 +static int createStrPatRegExpOfElement(
3544 + ReadMatchPatternInfo *readPatInfo,
3545 + MatchPatternTableElement *element,
3546 + ErrorInfo *errInfo);
3547 +static int createStrPatRegExp(
3548 + StringPattern *strPat,
3549 + ErrorInfo *errInfo);
3550 +static void adaptCompileMsg(
3552 + int *globalToLocalBackRef);
3553 +static int localToGlobalBackRef(
3554 + int *globalToLocalBackRef,
3556 +static int createStartEndRegExp(
3557 + ReadMatchPatternInfo *readMatchPatternInfo,
3558 + MatchPatternTableElement *element,
3559 + ErrorInfo *errInfo);
3560 +static int createGroupRegExp(
3561 + ReadMatchPatternInfo *readPatInfo,
3562 + MatchPatternGroupElement *group,
3563 + ErrorInfo *errInfo);
3564 +static void setupRegExpStringBuffers(
3565 + ReadMatchPatternInfo *readMatchPatternInfo,
3566 + RegExpStringInfo *regExpStringInfo);
3567 +static void addSMTRegExpString(
3570 + const char *postfix);
3571 +static void composeStartEndRegExpString(
3572 + ReadMatchPatternInfo *readMatchPatternInfo,
3573 + MatchPatternTableElement *element,
3574 + char **regExpString);
3575 +static void addElementToRegExpString(
3576 + MatchPatternTableElement *element,
3577 + ReadMatchPatternInfo *readMatchPatternInfo,
3578 + RegExpStringInfo *regExpStringInfo);
3579 +static void addUniquePatternToRegExpString(
3580 + PatternElement *patElement,
3581 + PatternReference *patElementReference,
3582 + ReadMatchPatternInfo *readMatchPatternInfo,
3583 + RegExpStringInfo *regExpStringInfo);
3584 +static void addPatternToRegExpString(
3585 + StringPattern *pattern,
3586 + RegExpStringInfo *regExpStringInfo);
3587 +static char *adaptLocalBackRefs(
3589 + int *commonLocalId);
3590 +static void scanForLocalBackRefs(
3592 + int *localBackRefList);
3593 +static int isMultiPatternNotAdded(
3594 + RegExpStringInfo *regExpStringInfo,
3595 + PatternReference *toBeAddedPR);
3596 +static void catSMTRegExpStrings(
3597 + RegExpStringInfo *regExpStringInfo,
3598 + char **regExpString);
3599 +static void freeRegExpStringInfo(
3600 + RegExpStringInfo *regExpStringInfo);
3601 +static int totalKeywordOfTableLen(
3602 + ReadMatchPatternInfo *info,
3603 + int *nbrOfMultiPatterns);
3604 +static int totalMatchPatternTableElementLen(
3605 + ReadMatchPatternInfo *info,
3606 + MatchPatternTableElement *element,
3607 + int *nbrOfMultiPatterns);
3608 +static int patternElementLen(
3609 + ReadMatchPatternInfo *info,
3610 + PatternElement *patElement,
3611 + int *nbrOfMultiPatterns);
3613 +static void parseMatchingPatternSetError(
3614 + const char *stringStart,
3615 + const char *stoppedAt,
3616 + ErrorInfo *errInfo);
3617 +static void dialogMatchingPatternSetError(
3619 + ErrorInfo *errInfo);
3621 +static char *createMatchPatternsString(
3622 + StringMatchTable *table,
3624 +static char *createPatternElementString(
3625 + MatchPatternTable *table,
3626 + PatternElement *pat);
3628 +static StringMatchTable *readDefaultStringMatchTable(const char *langModeName);
3629 +static int isDefaultMatchPatternTable(StringMatchTable *table);
3631 +static void freeReadMatchPatternInfo( ReadMatchPatternInfo *readPatInfo );
3632 +static void freeStringMatchTable( StringMatchTable *table );
3633 +static void freeMatchPatternTableElement( MatchPatternTableElement *element );
3634 +static void freePatternElement( PatternElement *element );
3635 +static void freeStringPattern( StringPattern *strPat );
3636 +static void freeMatchPatternGroupElement( MatchPatternGroupElement *group );
3637 +static void freeMatchPatternSequenceElement( MatchPatternSequenceElement *sequence );
3639 +static StringMatchTable *readMatchPatternSet(char **inPtr);
3640 +static StringMatchTable *readMatchPatternSetContent(
3642 + char *stringStart,
3643 + char *languageMode);
3644 +static int createRegExpOfPatterns(
3645 + ReadMatchPatternInfo *readPatInfo,
3646 + ErrorInfo *errInfo);
3647 +static int createRegExpOfAllPatterns(
3648 + ReadMatchPatternInfo *readPatInfo,
3649 + ErrorInfo *errInfo);
3650 +static int createRegExpOfStrPatterns(
3651 + ReadMatchPatternInfo *readPatInfo,
3652 + ErrorInfo *errInfo);
3653 +static StringMatchTable *createStringMatchTable(
3654 + ReadMatchPatternInfo *readPatInfo,
3655 + char *languageMode);
3656 +static int readMatchPatternEntry(
3658 + ErrorInfo *errInfo,
3659 + ReadMatchPatternInfo *info);
3660 +static void recordPatternSequence(
3661 + ReadMatchPatternInfo *info,
3663 + MatchPatternType type,
3665 +static int assignIndividualGroup(
3666 + ReadMatchPatternInfo *info,
3668 + MatchPatternTableElement *element);
3669 +static MatchPatternTableElement *getPatternOfName(
3670 + ReadMatchPatternInfo *info,
3671 + char *subPatToSearch);
3672 +static MatchPatternGroupElement *readMatchPatternGroup(
3674 + ErrorInfo *errInfo,
3676 + ReadMatchPatternInfo *info);
3677 +static int readPatternElement(
3680 + PatternElement **pattern);
3681 +static PatternElement *createPatternElement(
3682 + char *patternText,
3683 + PatternElementKind patternKind,
3684 + PatternWordBoundary wordBoundary,
3685 + int caseInsensitive,
3686 + int regularExpression);
3688 +static int createGlobalBackRefList(
3689 + ReadMatchPatternInfo *readPatInfo,
3690 + MatchPatternTableElement *element,
3691 + ErrorInfo *errInfo);
3692 +StringPattern *getReadStringPattern(
3693 + ReadMatchPatternInfo *readPatInfo,
3694 + PatternElement *pattern );
3695 +static PatternElement *getReadPatternOfReference(
3696 + ReadMatchPatternInfo *readPatInfo,
3697 + PatternReference *patRef);
3698 +static char *replaceCapturingParentheses(
3699 + const char *source);
3700 +static int parseGlobalBackRefs(
3701 + StringPattern *strPat,
3702 + GlobalBackRefElement *backRefList,
3703 + ErrorInfo *errInfo);
3704 +static int updateGlobalBackRefs(
3705 + StringPattern *strPat,
3706 + GlobalBackRefElement *backRefList,
3707 + ErrorInfo *errInfo);
3708 +static char *createBackRefRegExpText(
3709 + const char *start,
3711 +static int resolveGlobalBackRefs(
3712 + ReadMatchPatternInfo *readPatInfo,
3713 + MatchPatternTableElement *element,
3714 + ErrorInfo *errInfo);
3715 +static int resolveGlobalBackRefsOfStrPat(
3716 + StringPattern *strPat,
3717 + GlobalBackRefElement *backRefList,
3718 + ErrorInfo *errInfo);
3719 +static char *substituteGlobalBackRef(
3720 + StringPattern *strPat,
3724 + GlobalBackRefElement *backRefList,
3725 + ErrorInfo *errInfo);
3726 +static char *replaceBackRefIdByRegExp(
3727 + StringPattern *strPat,
3728 + char *replaceStartPtr,
3730 +static char *convertGlobalToLocalBackRef(
3731 + StringPattern *strPat,
3732 + char *convertPtr);
3734 +static MatchPatternTableElement *readMatchPatternTableElement(
3738 + MatchPatternType type);
3739 +static int sortReadPatternElementSet(
3740 + PatternElementSet *allPat,
3742 + MatchPatternTableElement *result);
3743 +static void countPatternElementKind(
3744 + PatternElementSet *allPat,
3745 + MatchPatternTableElement *result);
3746 +static void sortPatternElementSet(
3747 + PatternElementSet *allPat,
3748 + MatchPatternTableElement *result);
3749 +static void copyPatternSet(
3750 + PatternElementSet *sourcePS,
3751 + PatternElementSet *destPS);
3753 +static int getMPSName(
3755 + ErrorInfo *errInfo,
3757 +static int getMPSTypeAttribute(
3759 + ErrorInfo *errInfo,
3760 + MatchPatternType *type);
3761 +static int getMPSGlobalAttribute(
3764 + int *isMonoPattern,
3767 + int *ignoreHighLightInfo);
3768 +static int getMPSPatternAttribute(
3771 + PatternElementKind *patternKind,
3772 + PatternWordBoundary *wordBoundary,
3773 + int *caseInsensitive,
3774 + int *regularExpression);
3776 +static void copyStringMatchTableForDialog(
3777 + StringMatchTable *sourceTable,
3778 + DialogMatchPatternInfo *dialogTable );
3779 +static void *copyMatchPatternElementForDialog(
3780 + MatchPatternTable *table,
3781 + int sourceElementIdx);
3782 +static void copyPatternForDialog(
3783 + MatchPatternTable *table,
3784 + PatternElement *sourcePattern,
3785 + DialogStringPatternElement **dialogPattern );
3786 +static void *copyGroupElementForDialog(
3787 + MatchPatternGroupElement *sourceGroup);
3788 +static void copySequenceElementForDialog(
3789 + StringMatchTable *sourceTable,
3790 + MatchPatternSequenceElement *sourceSeqElement,
3791 + DialogMatchPatternSequenceElement **dialogSeqElement );
3792 +static DialogMatchPatternSequenceElement *copyDialogSequenceElement(
3793 + DialogMatchPatternSequenceElement *sourceSeq);
3794 +static void freeDialogMatchPatternElement(
3795 + DialogMatchPatternTableElement *dialogElement );
3796 +static void freeDialogStringPatternElement(
3797 + DialogStringPatternElement *element);
3798 +static void freeDialogGroupElement(
3799 + DialogMatchPatternGroupElement *dialogGroup );
3800 +static void freeDialogSequenceElement(
3801 + DialogMatchPatternSequenceElement *dialogSeq );
3803 +static void copyDialogStringPatternsFromTable(
3804 + DialogMatchPatternTableElement *tableElement,
3805 + DialogStringPatterns *destPatterns);
3806 +static void copyDialogStringPatterns(
3807 + DialogStringPatterns *sourcePatterns,
3808 + DialogStringPatterns *destPatterns);
3809 +static void freeDialogStringPatterns(
3810 + DialogStringPatterns *patterns);
3812 +static DialogStringPatternElement *copyDialogStringPatternElement(
3813 + DialogStringPatternElement *sourceElement);
3815 +static void copyDialogPatternNamesFromGroup(
3816 + DialogMatchPatternGroupElement *group,
3817 + DialogStringPatterns *destPatterns);
3818 +static DialogStringPatternElement *copyDialogPatternName(
3819 + char *sourcePatternId);
3820 +static void copyDialogPatternNamesToGroup(
3821 + DialogStringPatterns *sourceNames,
3822 + DialogMatchPatternGroupElement *destGroup);
3824 +static void setDialogType(int dialogShowsStringPattern);
3825 +static void setSensitiveWordBoundaryBox(int enable);
3827 +static void *getStringPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
3829 +static void setStringPatternDisplayedCB(void *item, void *cbArg);
3830 +static void freeStringPatternItemCB(void *item);
3832 +static void *getMatchPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
3834 +static void setMatchPatternDisplayedCB(void *item, void *cbArg);
3835 +static void freeMatchPatternItemCB(void *item);
3836 +static int deleteMatchPatternItemCB(int itemIndex, void *cbArg);
3838 +static void matchPatternLangModeCB(Widget w, XtPointer clientData, XtPointer callData);
3839 +static void pmLanguageModeDialogCB(Widget w, XtPointer clientData, XtPointer callData);
3841 +static void destroyCB(Widget w, XtPointer clientData, XtPointer callData);
3842 +static void okCB(Widget w, XtPointer clientData, XtPointer callData);
3843 +static void applyCB(Widget w, XtPointer clientData, XtPointer callData);
3844 +static void checkCB(Widget w, XtPointer clientData, XtPointer callData);
3845 +static void restoreCB(Widget w, XtPointer clientData, XtPointer callData);
3846 +static void deleteCB(Widget w, XtPointer clientData, XtPointer callData);
3847 +static void closeCB(Widget w, XtPointer clientData, XtPointer callData);
3848 +static void helpCB(Widget w, XtPointer clientData, XtPointer callData);
3850 +static void matchPatTypeCB(Widget w, XtPointer clientData, XtPointer callData);
3851 +static void strPatRegExpressionCB(Widget w, XtPointer clientData, XtPointer callData);
3852 +static void changeExistingSubPattern(char *warnTitle);
3853 +static void changeStringPatternToGroup(void);
3854 +static void changeGroupToStringPattern(char *warnTitle);
3856 +static Widget createSubPatternNameMenu(
3858 + char *currentSubPatName,
3859 + int allSubPatterns);
3860 +static void setupSubPatternNameList(
3861 + char *currentSubPatName,
3862 + int allSubPatterns,
3863 + NameList *nameList);
3864 +static void createSubPatNameMenuEntry(
3866 + char *subPatName);
3867 +static void setSubPatternNameMenu(
3868 + const char *subPatName);
3869 +static void updateSubPatternNameMenu(
3870 + char *currentSubPatName,
3871 + int allSubPatterns);
3872 +static char *getSelectedSubPatternName(void);
3873 +static int isSubPatternNameInCurStrPat(
3874 + char *subPatName);
3876 +static DialogMatchPatternSequenceElement *readMatchPatternFields(int silent);
3877 +static int isStartPatternElementAvailable(
3878 + DialogStringPatterns *dialogPatterns);
3879 +static DialogStringPatternElement *readStringPatternFrameFields(int silent);
3881 +static int matchPatternDialogEmpty(void);
3882 +static int stringPatternFrameEmpty(void);
3883 +static int stringPatternFieldsEmpty(
3884 + int strPatIsRelatedToGroup);
3886 +static int getAndUpdateStringMatchTable(void);
3887 +static void updateStringMatchTable(
3888 + StringMatchTable *newTable);
3890 +static StringMatchTable *getDialogStringMatchTable(
3891 + DMPTranslationResult *result);
3892 +static StringMatchTable *translateDialogStringMatchTable(
3893 + DialogMatchPatternInfo *dialogTable,
3894 + DMPTranslationResult *result);
3895 +static MatchPatternTableElement *translateDialogMatchPatternTableElement(
3896 + DialogMatchPatternTableElement *dialogElement);
3897 +static void translateDialogPatterns(
3898 + DialogStringPatterns *dialogPatterns,
3899 + MatchPatternTableElement *newElement);
3900 +static MatchPatternGroupElement *translateDialogMatchPatternGroupElement(
3901 + ReadMatchPatternInfo *info,
3902 + DialogMatchPatternGroupElement *dialogGroup);
3903 +static void sortDialogPatternElementSet(
3904 + PatternElementSet *allPat,
3905 + MatchPatternTableElement *result);
3907 +static int stringMatchTableDiffer(
3908 + StringMatchTable *oldTable,
3909 + StringMatchTable *newTable);
3911 +static int patternElementDiffer(
3912 + PatternElement *oldPE,
3913 + MatchPatternTable *oldTab,
3914 + PatternElement *newPE,
3915 + MatchPatternTable *newTab);
3917 +static DialogMatchPatternGroupElement *getDialogGroupUsingMatchPattern(
3918 + char *matchPatternName);
3919 +static void removeMatchPatternFromGroup(
3920 + char *matchPatternName,
3921 + DialogMatchPatternGroupElement *group);
3922 +static void removeMatchPatternFromAllGroups(
3923 + char *matchPatternName);
3924 +static void renameMatchPatternInGroup(
3925 + char *oldMatchPatternName,
3926 + char *newMatchPatternName,
3927 + DialogMatchPatternGroupElement *group);
3928 +static void renameMatchPatternInAllGroups(
3929 + char *oldMatchPatternName,
3930 + char *newMatchPatternName);
3932 +static void freeVariableDialogData(
3933 + int keepLanguageModeName);
3935 +static void initGlobalBackRefList(
3936 + GlobalBackRefElement *list);
3937 +static void initStrPatBackRefList(
3938 + StringPattern *strPat);
3940 +StringPattern *getUniqueStringPattern(
3941 + PatternElement *pattern );
3943 +static void initErrorInfo(
3944 + ErrorInfo *errInfo);
3945 +static void freeErrorInfo(
3946 + ErrorInfo *errInfo);
3948 +static void freeXtPtr(void **ptr);
3949 +static void freePtr(void **ptr);
3952 + * matching pattern dialog information
3956 + Widget mpdLmOptMenu;
3957 + Widget mpdLmPulldown;
3958 + Widget mpdMatchPatternNamesListW;
3959 + Widget mpdMatchPatternNameLbl;
3960 + Widget mpdMatchPatternNameW;
3961 + Widget mptbIndividualW;
3962 + Widget mptbSubPatternW;
3963 + Widget mptbContextGroupW;
3964 + Widget mpdGlobalAttributesLbl;
3965 + Widget gabSkipBtwStartEndW;
3967 + Widget gabSyntaxBasedW;
3968 + Widget mpdStringPatternsLbl;
3969 + Widget mpdStringPatternsListW;
3970 + Widget mpdStringPatternTypeLbl;
3972 + Widget sptMiddleW;
3974 + Widget mpdWordBoundaryLbl;
3979 + Widget mpdStringAttributesLbl;
3980 + Widget sabCaseSensitiveW;
3981 + Widget sabRegularExpressionW;
3982 + Widget mpdStringPatternLbl;
3983 + Widget mpdStringPatternW;
3984 + Widget mpdSubPatNamesLbl;
3985 + Widget mpdSubPatNamesOptMenu;
3986 + Widget mpdSubPatNamesPulldown;
3987 + char *mpdLangModeName;
3988 + DialogMatchPatternSequenceElement *currentDmptSeqElement;
3989 + DialogMatchPatternTableElement *currentDmptElement;
3990 + DialogMatchPatternGroupElement *currentDmptGroup;
3991 + DialogStringPatterns currentStringPatterns;
3992 + DialogMatchPatternInfo mpdTable;
3993 + int mpdStringPatternIsDisplayed;
3994 +} MatchPatternDialog =
3995 + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
3996 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
3997 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
3998 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
3999 + NULL, NULL, NULL, NULL,
4006 + * Matching pattern sources loaded from the nedit resources file or set
4009 +static int NbrMatchTables = 0;
4010 +static StringMatchTable *MatchTables[MAX_LANGUAGE_MODES];
4014 + * LanguagePatternSet ::=
4015 + * LanguageName{PatternStatement..}
4017 + * PatternStatement ::=
4018 + * name:[s]:[c][f][m][p][u]:([s|m|e][w|l|r][i]:"pattern":)..)\n)|
4019 + * name:g:"sub-pattern name":..\n..
4022 + * s : sub-pattern (pattern is only matched, if part of a pattern group).
4023 + * g : pattern (context) group (i.e. a sequence of sub-patterns).
4024 + * default: individual pattern (pattern is matched individually).
4025 + * GlobalAttribute:
4026 + * c : the content between start and end pattern is skipped
4027 + * during parsing (e.g. pattern encloses a comment).
4028 + * f : flash matching pattern (if not set, then only jump
4029 + * to matching pattern is supported).
4030 + * m : mono pattern - set exist out of only one single pattern
4031 + * (start pattern = end pattern; e.g. quotes like ")
4032 + * p : ignore highlight info code of single patterns of this set
4034 + * StringPatternKind:
4035 + * s : start string pattern.
4036 + * m : middle string pattern.
4037 + * e : end string pattern.
4038 + * WordBoundaryAttribute:
4039 + * w : pattern is word (i.e. before and after pattern
4040 + * there must be a delimiter).
4041 + * l : before pattern must be a delimiter (left side).
4042 + * r : after pattern must be a delimiter (right side).
4043 + * default: neither before nor after pattern must be a delimiter.
4044 + * StringAttribute:
4045 + * i : pattern is case insensitive (if not set: pattern is
4046 + * case sensitive).
4047 + * x : pattern is regular expression (if not set: pattern is
4048 + * literal string).
4050 + * \n : end of pattern
4053 +static char *DefaultStringMatchTable[] = {
4055 + "Round braces::fp:s:\"(\":e:\")\":\n"
4056 + "Curly braces::fp:s:\"{\":e:\"}\":\n"
4057 + "Squared braces::fp:s:\"[\":e:\"]\":\n"
4058 + "Sharp braces::fp:s:\"<\":e:\">\":\n}",
4060 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4061 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4062 + "Single Quotes:s:cmf:s:\"'\":\n"
4063 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4064 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4065 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4066 + "#ifdef statement:s:f:sx:\"#\\s*ifdef\":sx:\"#\\s*ifndef\":sx:\"#\\s*if\":mx:\"#\\s*elif\":mx:\"#\\s*else\":ex:\"#\\s*endif\":\n"
4067 + "#if group:g:Comment:Double Quotes:Single Quotes:#ifdef statement:\n"
4068 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4070 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4071 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4072 + "Single Quotes:s:cmf:s:\"'\":\n"
4073 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4074 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4075 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4076 + "#ifdef statement:s:f:sx:\"#\\s*ifdef\":sx:\"#\\s*ifndef\":sx:\"#\\s*if\":mx:\"#\\s*elif\":mx:\"#\\s*else\":ex:\"#\\s*endif\":\n"
4077 + "#if group:g:Comment:Double Quotes:Single Quotes:#ifdef statement:\n"
4078 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4080 + "comment:s:cf:s:\"/*\":e:\"*/\":\n"
4081 + "curly braces:s:f:s:\"{\":e:\"}\":\n"
4082 + "round braces:s:f:s:\"(\":e:\")\":\n"
4083 + "double quotes:s:cfm:s:\"\"\"\":\n"
4084 + "single quotes:s:cfm:s:\"'\":\n"
4085 + "braces:g:comment:single quotes:double quotes:curly braces:round braces:\n}",
4087 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4088 + "Single Quotes:s:cmf:s:\"'\":\n"
4089 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4090 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4091 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4092 + "if statement:s:f:sw:\"if\":mw:\"else\":ew:\"endif\":\n"
4093 + "switch statement:s:f:sw:\"switch\":mw:\"case\":mw:\"default\":ew:\"endsw\":\n"
4094 + "foreach statement:s:f:sw:\"for\":ew:\"end\":\n"
4095 + "while statement:s:f:sw:\"while\":ew:\"end\":\n"
4096 + "statement group:g:Double Quotes:Single Quotes:if statement:switch statement:foreach statement:while statement:\n"
4097 + "Braces:g:Double Quotes:Single Quotes:Squared braces:Round braces:Curly braces:\n}",
4099 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4100 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4101 + "Single Quotes:s:cmf:s:\"'\":\n"
4102 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4103 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4104 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4105 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4107 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4108 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4109 + "Single Quotes:s:cmf:s:\"'\":\n"
4110 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4111 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4112 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4113 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4115 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4116 + "Single Quotes:s:cmf:s:\"'\":\n"
4117 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4118 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4119 + "Braces:g:Double Quotes:Single Quotes:Curly braces:Round braces:\n}",
4121 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4122 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4123 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4124 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4125 + "Braces:g:Double Quotes:Curly braces:Round braces:Squared braces:\n}",
4127 + "Single Quotes:s:cmf:s:\"'\":\n"
4128 + "Comment1:s:cf:s:\"(*\":e:\"*)\":\n"
4129 + "Comment2:s:cf:s:\"{\":e:\"}\":\n"
4130 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4131 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4132 + "Block:s:f:swi:\"begin\":ewi:\"end\":\n"
4133 + "Case:s:fp:swi:\"case\":ewi:\"end\":\n"
4134 + "Record:s:f:swi:\"record\":ewi:\"end\":\n"
4135 + "Statement:g:Comment1:Comment2:Single Quotes:Block:Case:Record:\n"
4136 + "Braces:g:Comment1:Comment2:Single Quotes:Round braces:Squared braces:\n}",
4138 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4139 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4140 + "Single Quotes:s:cmf:s:\"'\":\n"
4141 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4142 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4143 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4144 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4146 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4147 + "Single Quotes:s:cmf:s:\"'\":\n"
4148 + "Sharp braces:s:f:s:\"<\":e:\">\":\n"
4149 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4150 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4151 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4152 + "Braces:g:Double Quotes:Single Quotes:Sharp braces:Curly braces:Round braces:Squared braces:\n}",
4154 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4155 + "Single Quotes:s:cmf:s:\"'\":\n"
4156 + "Back Quotes:s:cfm:s:\"`\":\n"
4157 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4158 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4159 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4160 + "if statement:s:f:sw:\"if\":mw:\"elif\":mw:\"else\":ew:\"fi\":\n"
4161 + "case statement:s:f:sw:\"case\":ew:\"esac\":\n"
4162 + "for statement:s:f:sw:\"for\":mw:\"do\":ew:\"done\":\n"
4163 + "while statement:s:f:sw:\"while\":mw:\"do\":ew:\"done\":\n"
4164 + "statement group:g:Double Quotes:Single Quotes:if statement:case statement:for statement:while statement:\n"
4165 + "Braces:g:Double Quotes:Single Quotes:Back Quotes:Squared braces:Round braces:Curly braces:\n}",
4167 + "round braces:s:f:s:\"(\":e:\")\":\n"
4168 + "comment:s:cf:s:\"<!--\":e:\"-->\":\n"
4169 + "cdata + ignore:s:cf:sx:\"\\<!\\[((?icdata)|(\\s*IGNORE\\s*))\\[\":ex:\"\\]\\]\\>\":\n"
4170 + "short element:s:cf:sx:\"(?n\\<[\\l_][^@$%/\"\"';!>\\s]*(?=[^>]*/\\>))\":ex:\"/\\>\":\n"
4171 + "element pair:s:f:sx:\"(?n\\<(*1[\\l|_][^@$%/\"\"';!>\\s]*)\\>)\":sx:\"(?n\\<(*1[\\l|_][^@$%/\"\"';!>\\s]*)(?=[^>]*[^/]\\>))\":eix:\"\\</\\1\\>\":\n"
4172 + "processing instruction:s:f:sx:\"\\<\\?\\S+\":ex:\"\\?\\>\":\n"
4173 + "double quotes:s:cmf:s:\"\"\"\":\n"
4174 + "single quotes:s:cmf:s:\"'\":\n"
4175 + "tags:g:comment:double quotes:single quotes:round braces:cdata + ignore:element pair:short element:processing instruction:\n}",
4178 +static char *StandardStringMatchTable =
4179 + "{Round braces::fp:s:\"(\":e:\")\":\n"
4180 + "Curly braces::fp:s:\"{\":e:\"}\":\n"
4181 + "Squared braces::fp:s:\"[\":e:\"]\":\n}";
4184 +** Return string match table related to given language mode name.
4185 +** Return NULL, if no table is found.
4187 +void *FindStringMatchTable(const char *langModeName)
4189 + const char *nameToSearch;
4192 + if (langModeName == NULL)
4193 + nameToSearch = PLAIN_LM_STRING;
4195 + nameToSearch = langModeName;
4197 + for (i=0; i<NbrMatchTables; i++)
4198 + if (!strcmp(nameToSearch, MatchTables[i]->smtLanguageMode))
4199 + return (void *)MatchTables[i];
4204 +** Change the language mode name of string match tables for language
4205 +** "oldName" to "newName" in both the stored tables, and the table
4206 +** currently being edited in the dialog.
4208 +void RenameStringMatchTable(const char *oldName, const char *newName)
4212 + for (i=0; i<NbrMatchTables; i++)
4214 + if (!strcmp(oldName, MatchTables[i]->smtLanguageMode))
4216 + XtFree(MatchTables[i]->smtLanguageMode);
4217 + MatchTables[i]->smtLanguageMode = XtNewString(newName);
4220 + if (MatchPatternDialog.mpdShell != NULL)
4222 + if (!strcmp(MatchPatternDialog.mpdLangModeName, oldName))
4224 + XtFree(MatchPatternDialog.mpdLangModeName);
4225 + MatchPatternDialog.mpdLangModeName = XtNewString(newName);
4231 +** Delete string match table related to given language mode name.
4233 +void DeleteStringMatchTable(const char *langModeName)
4237 + for (i=0; i<NbrMatchTables; i++)
4239 + if (!strcmp(langModeName, MatchTables[i]->smtLanguageMode))
4242 + * free (delete) existing matching pattern
4244 + freeStringMatchTable(MatchTables[i]);
4247 + &MatchTables[i+1],
4248 + (NbrMatchTables-1 - i) * sizeof(StringMatchTable *));
4256 +** Assign a standard string match table to a given new language mode.
4258 +void AssignStandardStringMatchTable(const char *langModeName)
4261 + StringMatchTable *newTable;
4264 + * assign standard table for new language mode
4265 + * add table to end
4267 + list = StandardStringMatchTable;
4269 + readMatchPatternSetContent(&list, list, XtNewString(langModeName));
4272 + * add table to end
4274 + MatchTables[NbrMatchTables++] = newTable;
4278 +** Returns True if there is a string match table, or potential table
4279 +** not yet committed in the match pattern dialog for a language mode,
4281 +int LMHasStringMatchTable(const char *languageMode)
4283 + StringMatchTable *table = FindStringMatchTable(languageMode);
4285 + if (table != NULL && table->smtNumberOfSeqElements != 0)
4287 + return MatchPatternDialog.mpdShell != NULL &&
4288 + !strcmp(MatchPatternDialog.mpdLangModeName, languageMode) &&
4289 + MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements != 0;
4293 +** Read a string representing string matching pattern sets and add them
4294 +** to the StringMatchTable list of loaded string match patterns.
4295 +** Returns true, if read of string was successful.
4297 +int LoadMatchPatternString(char *inString)
4299 + char *inPtr = inString;
4300 + StringMatchTable *table;
4306 + * read each matching pattern set
4308 + table = readMatchPatternSet(&inPtr);
4310 + if (table != NULL)
4313 + * add/change the pattern set in the list
4315 + for (i=0; i<NbrMatchTables; i++)
4317 + if (!strcmp(MatchTables[i]->smtLanguageMode, table->smtLanguageMode))
4319 + freeStringMatchTable(MatchTables[i]);
4320 + MatchTables[i] = table;
4324 + if (i == NbrMatchTables)
4326 + MatchTables[NbrMatchTables++] = table;
4327 + if (NbrMatchTables > MAX_LANGUAGE_MODES)
4335 + * find end of this pattern. if the string ends here, we're done
4337 + inPtr = strstr(inPtr, "\n");
4338 + if (inPtr == NULL)
4344 + * skip newline, tabs & spaces in front of next pattern.
4345 + * if the string ends here, we're done
4347 + inPtr += strspn(inPtr, " \t\n");
4348 + if (*inPtr == '\0')
4356 +** Create a string in the correct format for the matchPatterns resource,
4357 +** containing all of the matching pattern information from the stored
4358 +** matching pattern sets for this NEdit session.
4360 +char *WriteMatchPatternString(void)
4362 + char *outStr, *str, *escapedStr;
4363 + textBuffer *outBuf;
4364 + int i, written = False;
4365 + StringMatchTable *table;
4367 + outBuf = BufCreate();
4369 + for (i=0; i<NbrMatchTables; i++)
4371 + table = MatchTables[i];
4375 + BufInsert(outBuf, outBuf->length, table->smtLanguageMode);
4376 + BufInsert(outBuf, outBuf->length, ":");
4378 + if (isDefaultMatchPatternTable(table))
4380 + BufInsert(outBuf, outBuf->length, "Default\n\t");
4384 + BufInsert(outBuf, outBuf->length, "{\n");
4385 + BufInsert(outBuf, outBuf->length,
4386 + str = createMatchPatternsString(table, "\t\t"));
4388 + BufInsert(outBuf, outBuf->length, "\t}\n\t");
4393 + * Get the output string, and lop off the trailing newline and tab
4395 + outStr = BufGetRange(outBuf, 0, outBuf->length - (written?2:0));
4399 + * Protect newlines and backslashes from translation by the resource
4402 + escapedStr = EscapeSensitiveChars(outStr);
4406 + return escapedStr;
4410 +** Check, if last pattern is a duplicate of a previous pattern.
4411 +** Convert last pattern to a reference, if so.
4413 +static void treatDuplicatedPattern(
4414 + MatchPatternTable *table,
4415 + PatternElement *prevPattern,
4416 + PatternReference prevPatRef,
4417 + PatternElement *lastPattern,
4418 + PatternReference lastPatRef)
4420 + StringPattern *prevStringPat;
4421 + StringPattern *lastStringPat;
4422 + StringPattern *stringPat;
4423 + PatternReference *oldList;
4427 + * No duplicate check needed, if previous pattern is a reference,
4428 + * due to the related multi pattern element is checked before.
4430 + if (prevPattern->peType == PET_REFERENCE)
4433 + prevStringPat = GetStringPattern(table, prevPattern);
4434 + lastStringPat = GetStringPattern(table, lastPattern);
4436 + if (!AllocatedStringsDiffer(prevStringPat->spText, lastStringPat->spText) &&
4437 + !AllocatedStringsDiffer(prevStringPat->spOrigText, lastStringPat->spOrigText) &&
4438 + prevStringPat->spWordBoundary == lastStringPat->spWordBoundary &&
4439 + prevStringPat->spCaseInsensitive == lastStringPat->spCaseInsensitive &&
4440 + prevStringPat->spRegularExpression == lastStringPat->spRegularExpression)
4443 + * Patterns are identical: Is prevPattern already a multi pattern ?
4445 + if (prevPattern->peType == PET_MULTIPLE)
4448 + * just add ref. to "lastPattern" to the ref. list
4450 + (prevPattern->peVal.peuMulti.mpNumberOfReferences) ++;
4451 + nbrOfRef = prevPattern->peVal.peuMulti.mpNumberOfReferences;
4452 + oldList = prevPattern->peVal.peuMulti.mpRefList;
4453 + prevPattern->peVal.peuMulti.mpRefList =
4454 + (PatternReference *)XtMalloc( nbrOfRef * sizeof(PatternReference) );
4456 + prevPattern->peVal.peuMulti.mpRefList,
4458 + (nbrOfRef-1) * sizeof(PatternReference) );
4459 + prevPattern->peVal.peuMulti.mpRefList[nbrOfRef-1] = lastPatRef;
4460 + XtFree( (char *)oldList );
4465 + * convert prev. single pattern to multi pattern
4467 + stringPat = &prevPattern->peVal.peuSingle;
4468 + prevPattern->peType = PET_MULTIPLE;
4469 + prevPattern->peVal.peuMulti.mpStringPattern = *stringPat;
4470 + prevPattern->peVal.peuMulti.mpNumberOfReferences = 1;
4471 + prevPattern->peVal.peuMulti.mpRefList =
4472 + (PatternReference *)XtMalloc( sizeof(PatternReference) );
4473 + prevPattern->peVal.peuMulti.mpRefList[0] = lastPatRef;
4477 + * convert last single pattern to reference
4479 + freeStringPattern( &(lastPattern->peVal.peuSingle) );
4480 + lastPattern->peType = PET_REFERENCE;
4481 + lastPattern->peVal.peuRef = prevPatRef;
4486 +** Check, if last pattern is a duplicate of a pattern stored within a
4487 +** previous match pattern table element.
4488 +** Convert last pattern to a reference, if so.
4490 +static void treatDuplicatedPatternElements(
4491 + MatchPatternTable *table,
4492 + MatchPatternTableElement *prevElement,
4493 + int prevElementIdx,
4494 + PatternElement *lastPattern,
4495 + PatternReference lastPatRef)
4498 + PatternReference prevPatRef;
4500 + prevPatRef.prElementIdx = prevElementIdx;
4502 + for (i=0; i<prevElement->mpteAll.pesNumberOfPattern; i++)
4504 + prevPatRef.prPatternIdx = i;
4505 + treatDuplicatedPattern(
4507 + prevElement->mpteAll.pesPattern[i],
4515 +** Check, if a pattern of last match pattern table element is a
4516 +** duplicate of a pattern stored within a previous match pattern table
4518 +** Convert duplicated last patterns to references, if so.
4520 +static void treatDuplicatedMTElements(
4521 + MatchPatternTable *table,
4522 + MatchPatternTableElement *prevElement,
4523 + int prevElementIdx,
4524 + MatchPatternTableElement *lastElement,
4525 + int lastElementIdx)
4528 + PatternReference lastPatRef;
4530 + lastPatRef.prElementIdx = lastElementIdx;
4532 + for (i=0; i<lastElement->mpteAll.pesNumberOfPattern; i++)
4534 + lastPatRef.prPatternIdx = i;
4535 + treatDuplicatedPatternElements(
4539 + lastElement->mpteAll.pesPattern[i],
4545 +** Convert all duplicated patterns of given match pattern table to
4548 +static void treatDuplicatedMTEntries(
4549 + MatchPatternTableElement **element,
4550 + int nbrOfElements)
4553 + MatchPatternTableElement *lastElement;
4554 + int lastElementIdx;
4555 + MatchPatternTable table;
4557 + if (nbrOfElements < 2)
4560 + lastElementIdx = nbrOfElements - 1;
4561 + lastElement = element[lastElementIdx];
4563 + table.mptElements = element;
4564 + table.mptNumberOfElements = nbrOfElements;
4566 + for (i=0; i<nbrOfElements-1; i ++)
4568 + treatDuplicatedMTElements( &table, element[i], i, lastElement, lastElementIdx );
4573 +** Compile regular expressions of all string patterns of given
4574 +** match pattern table element.
4575 +** Returns true, if compilation fails.
4577 +static int createStrPatRegExpOfElement(
4578 + ReadMatchPatternInfo *readPatInfo,
4579 + MatchPatternTableElement *element,
4580 + ErrorInfo *errInfo)
4583 + StringPattern *strPat;
4585 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
4587 + strPat = getReadStringPattern(readPatInfo, element->mpteAll.pesPattern[i]);
4590 + * if current string pattern holds a regular expression, then
4593 + if (strPat->spRegularExpression)
4595 + if (createStrPatRegExp(strPat, errInfo))
4598 + * compilation was not successful
4600 + errInfo->eiMPTabElementName = XtNewString(element->mpteName);
4610 +** Compile regular expressions of given string pattern.
4611 +** Returns true, if compilation fails.
4613 +static int createStrPatRegExp(
4614 + StringPattern *strPat,
4615 + ErrorInfo *errInfo)
4617 + char *regExpString;
4621 + * compose regular expression for start string pattern.
4623 + if( strPat->spCaseInsensitive)
4626 + * Add '(?i .. )' to given text for case insensitive search.
4627 + * Allocate buffer to hold 5 more char than text length
4628 + * (4 char '(?i)' + \0 char.
4630 + regExpString = XtMalloc(strPat->spLength + 5);
4631 + strcpy(regExpString, "(?i");
4632 + strcat(regExpString, strPat->spText);
4633 + strcat(regExpString, ")");
4637 + regExpString = strPat->spText;
4641 + * compile regular expression & free allocated string buffer,
4644 + strPat->spTextRE =
4645 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
4647 + if (strPat->spTextRE == NULL)
4650 + * compilation was not successful: adapt error reason by
4651 + * converting local backrefs to global ones.
4653 + adaptCompileMsg(compileMsg, strPat->spGlobalToLocalBackRef);
4655 + errInfo->eiRegExpCompileMsg = compileMsg;
4656 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
4659 + if (strPat->spCaseInsensitive)
4660 + XtFree( regExpString );
4662 + return (strPat->spTextRE == NULL);
4666 +** adapt regular expression compilation message by converting local
4667 +** backrefs to global ones.
4669 +static void adaptCompileMsg(
4671 + int *globalToLocalBackRef)
4675 + char *s = compileMsg;
4677 + while (*s != '\0')
4681 + if (isdigit((unsigned char)*(s+1)))
4684 + * \n (n=1..9) found: substitute local by global back ref.
4689 + (int)((unsigned char)*s - (unsigned char)'0');
4691 + globalId = localToGlobalBackRef(globalToLocalBackRef, localId);
4693 + *s = (char)((int)('0') + globalId);
4695 + else if (*(s+1) != '\0')
4703 +** translate given local backref to global backref by using
4704 +** given globalToLocalBackRef list.
4706 +static int localToGlobalBackRef(
4707 + int *globalToLocalBackRef,
4712 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
4714 + if (globalToLocalBackRef[i] == localId)
4722 +** Create a regular expression holding keywords of given start & end
4724 +** Returns true, if creation of regular expression has failed.
4726 +static int createStartEndRegExp(
4727 + ReadMatchPatternInfo *readMatchPatternInfo,
4728 + MatchPatternTableElement *element,
4729 + ErrorInfo *errInfo)
4731 + char *regExpString;
4735 + * compose regular expression for start / end pattern.
4737 + composeStartEndRegExpString(
4738 + readMatchPatternInfo,
4743 + * compile regular expression & free allocated string buffer.
4745 + element->mpteStartEndRE =
4746 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
4748 + XtFree( regExpString );
4750 + if( element->mpteStartEndRE == NULL)
4752 + errInfo->eiRegExpCompileMsg = compileMsg;
4753 + errInfo->eiDetail = "Error compiling start / end reg. exp.";
4756 + return (element->mpteStartEndRE == NULL);
4760 +** Create a regular expression holding keywords of given group element.
4761 +** Returns true, if creation of regular expression has failed.
4763 +static int createGroupRegExp(
4764 + ReadMatchPatternInfo *readPatInfo,
4765 + MatchPatternGroupElement *group,
4766 + ErrorInfo *errInfo)
4769 + MatchPatternTableElement *element;
4770 + RegExpStringInfo regExpStringInfo;
4771 + char *regExpString;
4772 + regexp *keywordRE;
4776 + * Allocate buffers for keyword regular expression of this group.
4778 + setupRegExpStringBuffers(
4780 + ®ExpStringInfo);
4782 + for (i=0; i<group->mpgeNumberOfSubPatterns; i++)
4784 + element = getPatternOfName(readPatInfo, group->mpgeSubPatternIds[i]);
4786 + * Add the keywords of the sub pattern to the keyword regular
4787 + * expression string buffer of new group.
4789 + addElementToRegExpString(
4792 + ®ExpStringInfo);
4796 + * Assemble and compile the resulting keyword regular expression string.
4798 + catSMTRegExpStrings(
4799 + ®ExpStringInfo,
4802 + keywordRE = CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
4804 + XtFree( regExpString );
4806 + if (keywordRE == NULL)
4808 + errInfo->eiMPTabElementName = XtNewString(group->mpgeName);
4809 + errInfo->eiRegExpCompileMsg = compileMsg;
4810 + errInfo->eiDetail = "Group: Compile reg. exp. error";
4813 + group->mpgeKeywordRE = keywordRE;
4815 + return (keywordRE == NULL);
4819 +** Allocate memory for regular expression strings to be
4820 +** created out of read match pattern info.
4822 +static void setupRegExpStringBuffers(
4823 + ReadMatchPatternInfo *readMatchPatternInfo,
4824 + RegExpStringInfo *regExpStringInfo)
4827 + int nbrOfMultiPatterns;
4828 + int sizeOfPatRefs;
4831 + * determine total length of pattern characters to determine
4832 + * the size of a string buffer for the regular expression to
4833 + * compose. Count number of total multi patterns, too.
4836 + totalKeywordOfTableLen( readMatchPatternInfo, &nbrOfMultiPatterns );
4839 + * allocate memory to store added multi pattern references (to avoid
4840 + * duplicated keywords strings later on).
4842 + sizeOfPatRefs = sizeof(PatternReference *) * nbrOfMultiPatterns;
4844 + regExpStringInfo->resiAddedMultiPat =
4845 + (PatternReference **)XtMalloc( sizeOfPatRefs );
4847 + regExpStringInfo->resiNbrOfAddedMultiPat = 0;
4850 + * init. ID of capturing local backrefs
4852 + regExpStringInfo->resiLocalBackRefID = 1;
4855 + * allocate & init. string buffers for regular expression:
4856 + * 3 times the size + x of all pattern characters (due to
4857 + * a.) each char may need to be escaped
4858 + * b.) '<(?:', ')>', ')' and '|' need to be added.
4860 + regExpStringInfo->resiNoneWBRegExpString = XtMalloc( 3 * totalLen );
4861 + regExpStringInfo->resiLeftWBRegExpString = XtMalloc( 3 * totalLen + 5 );
4862 + regExpStringInfo->resiRightWBRegExpString = XtMalloc( 3 * totalLen + 5 );
4863 + regExpStringInfo->resiBothWBRegExpString = XtMalloc( 3 * totalLen + 6 );
4865 + strcpy( regExpStringInfo->resiNoneWBRegExpString, "" );
4866 + strcpy( regExpStringInfo->resiLeftWBRegExpString, "" );
4867 + strcpy( regExpStringInfo->resiRightWBRegExpString, "" );
4868 + strcpy( regExpStringInfo->resiBothWBRegExpString, "" );
4872 +** Concatenate given 'partToAdd' string to result string, separated
4873 +** by an OR ('|'). Add 'postfix' at end of result string.
4875 +static void addSMTRegExpString(
4878 + const char *postfix)
4880 + if (strlen(partToAdd) != 0)
4882 + if (strlen(result) != 0)
4884 + strcat( result, "|" );
4887 + strcat( result, partToAdd );
4889 + strcat( result, postfix );
4895 +** Return a string representing given string match table.
4897 +static char *createMatchPatternsString(
4898 + StringMatchTable *table,
4901 + char *outStr, *str;
4902 + textBuffer *outBuf;
4904 + MatchPatternSequenceElement *seq;
4905 + MatchPatternTableElement *element;
4906 + MatchPatternGroupElement *group;
4908 + outBuf = BufCreate();
4910 + for (i=0; i<table->smtNumberOfSeqElements; i++)
4912 + seq = table->smtSequence[i];
4914 + BufInsert(outBuf, outBuf->length, indentStr);
4915 + BufInsert(outBuf, outBuf->length, seq->mpseName);
4916 + BufInsert(outBuf, outBuf->length, ":");
4918 + if (seq->mpseType == MPT_GROUP)
4920 + BufInsert(outBuf, outBuf->length, "g:");
4922 + group = table->smtGroups[seq->mpseIndex];
4924 + for (j=0; j < group->mpgeNumberOfSubPatterns; j ++)
4926 + BufInsert(outBuf, outBuf->length, group->mpgeSubPatternIds[j]);
4927 + BufInsert(outBuf, outBuf->length, ":");
4932 + if (seq->mpseType == MPT_SUB)
4934 + BufInsert(outBuf, outBuf->length, "s");
4936 + BufInsert(outBuf, outBuf->length, ":");
4938 + element = table->smtAllPatterns->mptElements[seq->mpseIndex];
4941 + * write global attributes
4943 + if (element->mpteSkipBtwnStartEnd)
4944 + BufInsert(outBuf, outBuf->length, "c");
4945 + if (element->mpteFlash)
4946 + BufInsert(outBuf, outBuf->length, "f");
4947 + if (element->mpteIsMonoPattern)
4948 + BufInsert(outBuf, outBuf->length, "m");
4949 + if (element->mpteIgnoreHighLightInfo)
4950 + BufInsert(outBuf, outBuf->length, "p");
4951 + BufInsert(outBuf, outBuf->length, ":");
4954 + * write string patterns
4956 + for (j=0; j < element->mpteAll.pesNumberOfPattern; j ++)
4962 + createPatternElementString(
4963 + table->smtAllPatterns,
4964 + element->mpteAll.pesPattern[j]));
4969 + BufInsert(outBuf, outBuf->length, "\n");
4972 + outStr = BufGetAll(outBuf);
4979 +** Return a string representing given pattern element.
4981 +static char *createPatternElementString(
4982 + MatchPatternTable *table,
4983 + PatternElement *pat)
4985 + char *outStr, *str;
4986 + textBuffer *outBuf;
4987 + StringPattern *strPat;
4989 + outBuf = BufCreate();
4991 + strPat = GetStringPattern(table, pat);
4994 + * write string pattern kind
4996 + if (pat->peKind == PEK_START)
4997 + BufInsert(outBuf, outBuf->length, "s");
4998 + else if (pat->peKind == PEK_MIDDLE)
4999 + BufInsert(outBuf, outBuf->length, "m");
5000 + else if (pat->peKind == PEK_END)
5001 + BufInsert(outBuf, outBuf->length, "e");
5004 + * write word boundary
5006 + if (strPat->spWordBoundary == PWB_BOTH)
5007 + BufInsert(outBuf, outBuf->length, "w");
5008 + else if (strPat->spWordBoundary == PWB_LEFT)
5009 + BufInsert(outBuf, outBuf->length, "l");
5010 + else if (strPat->spWordBoundary == PWB_RIGHT)
5011 + BufInsert(outBuf, outBuf->length, "r");
5014 + * write case insensitive flag
5016 + if (strPat->spCaseInsensitive)
5017 + BufInsert(outBuf, outBuf->length, "i");
5020 + * write regular expression flag
5022 + if (strPat->spRegularExpression)
5023 + BufInsert(outBuf, outBuf->length, "x");
5025 + BufInsert(outBuf, outBuf->length, ":");
5028 + * write pattern string
5030 + if( strPat->spOrigText != NULL)
5034 + str = MakeQuotedString(strPat->spOrigText));
5039 + str = MakeQuotedString(strPat->spText));
5042 + BufInsert(outBuf, outBuf->length, ":");
5044 + outStr = BufGetAll(outBuf);
5051 +** Given a language mode name, determine if there is a default (built-in)
5052 +** string match table available for that language mode, and if so, read it and
5053 +** return a new allocated copy of it. The returned pattern set should be
5054 +** freed by the caller with freeStringMatchTable().
5056 +static StringMatchTable *readDefaultStringMatchTable(const char *langModeName)
5058 + int i, modeNameLen;
5061 + modeNameLen = strlen(langModeName);
5063 + for (i=0; i<(int)XtNumber(DefaultStringMatchTable); i++)
5065 + if (!strncmp(langModeName, DefaultStringMatchTable[i], modeNameLen) &&
5066 + DefaultStringMatchTable[i][modeNameLen] == '{')
5068 + list = DefaultStringMatchTable[i];
5069 + return readMatchPatternSet(&list);
5073 + list = StandardStringMatchTable;
5074 + return readMatchPatternSetContent(&list, list, XtNewString(langModeName));
5078 +** Return true, if table exactly matches one of the default matching
5081 +static int isDefaultMatchPatternTable(StringMatchTable *table)
5083 + StringMatchTable *defaultTable;
5086 + defaultTable = readDefaultStringMatchTable(table->smtLanguageMode);
5088 + if (defaultTable == NULL)
5091 + retVal = !stringMatchTableDiffer(table, defaultTable);
5093 + freeStringMatchTable(defaultTable);
5099 +** Read in a string match pattern table character string,
5100 +** and advance *inPtr beyond it.
5101 +** Returns NULL and outputs an error to stderr on failure.
5103 +static StringMatchTable *readMatchPatternSet(char **inPtr)
5105 + char *languageMode;
5106 + StringMatchTable *table = NULL;
5107 + char *stringStart = *inPtr;
5108 + ErrorInfo errInfo;
5110 + initErrorInfo(&errInfo);
5113 + * remove leading whitespace
5115 + *inPtr += strspn(*inPtr, " \t\n");
5118 + * read language mode field
5120 + languageMode = ReadSymbolicField(inPtr);
5123 + * look for initial brace
5125 + if (**inPtr == ':')
5129 + * look for "Default" keyword, and if it's there, return the default
5132 + if (!strncmp(*inPtr, "Default", 7))
5135 + table = readDefaultStringMatchTable(languageMode);
5136 + XtFree(languageMode);
5142 + table = readMatchPatternSetContent(inPtr, stringStart, languageMode);
5144 + if (table == NULL)
5145 + XtFree(languageMode);
5151 +** Read in a content string ("{..}") of match pattern table,
5152 +** and advance *inPtr beyond it.
5153 +** Returns NULL and outputs an error to stderr on failure.
5155 +static StringMatchTable *readMatchPatternSetContent(
5157 + char *stringStart,
5158 + char *languageMode)
5160 + ReadMatchPatternInfo readPatInfo;
5161 + StringMatchTable *table = NULL;
5162 + ErrorInfo errInfo;
5163 + int successful = True;
5164 + int endOfPatternSet = False;
5166 + initErrorInfo(&errInfo);
5169 + * look for initial brace
5171 + if (**inPtr != '{')
5173 + errInfo.eiLanguageMode = XtNewString(languageMode);
5174 + errInfo.eiDetail = "pattern list must begin with \"{\"";
5175 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo );
5182 + readPatInfo.rmpiNbrOfElements = 0;
5183 + readPatInfo.rmpiNbrOfGroups = 0;
5184 + readPatInfo.rmpiNbrOfSeqElements = 0;
5185 + readPatInfo.rmpiAllPatRE = NULL;
5186 + readPatInfo.rmpiFlashPatRE = NULL;
5189 + * parse each pattern in the list
5191 + while (successful && !endOfPatternSet)
5193 + *inPtr += strspn(*inPtr, " \t\n");
5194 + if (**inPtr == '\0')
5196 + errInfo.eiLanguageMode = XtNewString(languageMode);
5197 + errInfo.eiDetail = "end of pattern list not found";
5198 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5199 + successful = False;
5201 + else if (**inPtr == '}')
5204 + endOfPatternSet = True;
5208 + if (!readMatchPatternEntry(inPtr, &errInfo, &readPatInfo))
5210 + errInfo.eiLanguageMode = XtNewString(languageMode);
5211 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5212 + successful = False;
5220 + * compile regular expressions of read patterns
5222 + if (createRegExpOfPatterns(&readPatInfo, &errInfo))
5224 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5225 + successful = False;
5231 + return createStringMatchTable(&readPatInfo, languageMode);
5236 + * free memory of already read patterns
5238 + freeReadMatchPatternInfo(&readPatInfo);
5247 +** Create a reg. exp. of all patterns contained
5248 +** in given read match pattern info.
5250 +static int createRegExpOfPatterns(
5251 + ReadMatchPatternInfo *readPatInfo,
5252 + ErrorInfo *errInfo)
5254 + if (createRegExpOfStrPatterns(readPatInfo, errInfo))
5257 + if (createRegExpOfAllPatterns(readPatInfo, errInfo))
5264 +** Create a "total pattern reg. exp." of all patterns / flash patterns
5265 +** contained in given read match pattern info.
5266 +** Returns true, if create of reg. exp. has failed.
5268 +static int createRegExpOfAllPatterns(
5269 + ReadMatchPatternInfo *readPatInfo,
5270 + ErrorInfo *errInfo)
5273 + RegExpStringInfo allPatRegExpSI;
5274 + RegExpStringInfo flashPatRegExpSI;
5275 + MatchPatternTableElement *element;
5276 + char *regExpString;
5280 + * Allocate buffers for keyword regular expressions.
5282 + setupRegExpStringBuffers(readPatInfo, &allPatRegExpSI);
5283 + setupRegExpStringBuffers(readPatInfo, &flashPatRegExpSI);
5285 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5287 + element = readPatInfo->rmpiElement[i];
5290 + * Add the keywords of the matching pattern to the keyword
5291 + * regular expression string buffer of all patterns.
5293 + addElementToRegExpString(
5299 + * If flash attribute is set, then add the keywords of the
5300 + * matching pattern also to the keyword regular expression
5301 + * string buffer of flash patterns.
5303 + if (element->mpteFlash)
5305 + addElementToRegExpString(
5308 + &flashPatRegExpSI);
5313 + * Assemble and compile the resulting all keywords reg. exp. string.
5315 + catSMTRegExpStrings(
5319 + readPatInfo->rmpiAllPatRE =
5320 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
5322 + XtFree( regExpString );
5324 + if (readPatInfo->rmpiAllPatRE == NULL)
5326 + errInfo->eiRegExpCompileMsg = compileMsg;
5327 + errInfo->eiDetail = "All patterns: compile reg. exp. error";
5332 + * Assemble and compile the resulting flash keywords reg. exp. string.
5334 + catSMTRegExpStrings(
5335 + &flashPatRegExpSI,
5338 + readPatInfo->rmpiFlashPatRE =
5339 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
5341 + XtFree( regExpString );
5343 + if (readPatInfo->rmpiFlashPatRE == NULL)
5345 + errInfo->eiRegExpCompileMsg = compileMsg;
5346 + errInfo->eiDetail = "Flash patterns: compile reg. exp. error";
5351 + * Pattern reg. exp. successful created:
5357 +** Create reg. exp. of single patterns contained in given
5358 +** read match pattern info.
5359 +** Returns true, if create of reg. exp. has failed.
5361 +static int createRegExpOfStrPatterns(
5362 + ReadMatchPatternInfo *readPatInfo,
5363 + ErrorInfo *errInfo)
5366 + MatchPatternTableElement *element;
5367 + MatchPatternGroupElement *group;
5370 + * create global backref list of all elements of read info
5372 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5374 + element = readPatInfo->rmpiElement[i];
5376 + if (!createGlobalBackRefList(readPatInfo, element, errInfo))
5381 + * resolve global backrefs of all elements of read info
5383 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5385 + element = readPatInfo->rmpiElement[i];
5387 + if (!resolveGlobalBackRefs(readPatInfo, element, errInfo))
5392 + * compile reg. exp. of all elements of read info
5394 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5396 + element = readPatInfo->rmpiElement[i];
5398 + if (createStrPatRegExpOfElement(readPatInfo, element, errInfo))
5402 + * create start / end reg. exp. if applicable.
5404 + if (element->mpteSkipBtwnStartEnd)
5406 + if (createStartEndRegExp(readPatInfo, element, errInfo))
5412 + * compile reg. exp. of all groups of read info
5414 + for (i=0; i < readPatInfo->rmpiNbrOfGroups; i ++)
5416 + group = readPatInfo->rmpiGroup[i];
5418 + if (createGroupRegExp(readPatInfo, group, errInfo))
5428 +** Create a string match table out of read match pattern info.
5430 +static StringMatchTable *createStringMatchTable(
5431 + ReadMatchPatternInfo *readPatInfo,
5432 + char *languageMode)
5434 + StringMatchTable *table;
5435 + MatchPatternTable *patTable;
5436 + int sizeOfElements;
5438 + table = (StringMatchTable *)XtMalloc(sizeof(StringMatchTable));
5439 + table->smtLanguageMode = languageMode;
5442 + * allocate a more appropriately sized list to return matching patterns
5444 + patTable = (MatchPatternTable *)XtMalloc(sizeof(MatchPatternTable));
5445 + patTable->mptNumberOfElements = readPatInfo->rmpiNbrOfElements;
5447 + if (readPatInfo->rmpiNbrOfElements > 0)
5450 + sizeof(MatchPatternTableElement *) * readPatInfo->rmpiNbrOfElements;
5451 + patTable->mptElements =
5452 + (MatchPatternTableElement **)XtMalloc(sizeOfElements);
5453 + memcpy(patTable->mptElements, readPatInfo->rmpiElement, sizeOfElements);
5457 + patTable->mptElements = NULL;
5460 + table->smtAllPatterns = patTable;
5462 + table->smtAllPatRE = readPatInfo->rmpiAllPatRE;
5463 + table->smtFlashPatRE = readPatInfo->rmpiFlashPatRE;
5464 + table->smtUsedPatRE = NULL;
5467 + * allocate a more appropriately sized list to return matching pattern groups
5469 + table->smtNumberOfGroups = readPatInfo->rmpiNbrOfGroups;
5470 + if (readPatInfo->rmpiNbrOfGroups > 0)
5473 + sizeof(MatchPatternGroupElement *) * readPatInfo->rmpiNbrOfGroups;
5474 + table->smtGroups =
5475 + (MatchPatternGroupElement **)XtMalloc(sizeOfElements);
5476 + memcpy(table->smtGroups, readPatInfo->rmpiGroup, sizeOfElements);
5480 + table->smtGroups = NULL;
5483 + * allocate a more appropriately sized list to return matching pattern sequence
5485 + table->smtNumberOfSeqElements = readPatInfo->rmpiNbrOfSeqElements;
5486 + if (readPatInfo->rmpiNbrOfSeqElements > 0)
5489 + sizeof(MatchPatternSequenceElement *) * readPatInfo->rmpiNbrOfSeqElements;
5490 + table->smtSequence =
5491 + (MatchPatternSequenceElement **)XtMalloc(sizeOfElements);
5492 + memcpy(table->smtSequence, readPatInfo->rmpiSequence, sizeOfElements);
5496 + table->smtSequence = NULL;
5503 +** Read one match pattern entry of a match pattern string.
5504 +** Returns true, if read was successful.
5506 +static int readMatchPatternEntry(
5508 + ErrorInfo *errInfo,
5509 + ReadMatchPatternInfo *info)
5512 + MatchPatternType type;
5513 + MatchPatternGroupElement *readGroup;
5514 + MatchPatternTableElement *readElement;
5516 + if (!getMPSName( inPtr, errInfo, &name ))
5521 + if (!getMPSTypeAttribute( inPtr, errInfo, &type ))
5523 + errInfo->eiMPTabElementName = XtNewString(name);
5527 + if (type == MPT_GROUP)
5529 + if (info->rmpiNbrOfGroups >= MAX_NBR_MATCH_PATTERN_GROUPS)
5531 + errInfo->eiMPTabElementName = XtNewString(name);
5532 + errInfo->eiDetail = "max number of match pattern groups exceeded";
5536 + readGroup = readMatchPatternGroup( inPtr, errInfo, name, info );
5538 + if (readGroup == NULL)
5540 + errInfo->eiMPTabElementName = XtNewString(name);
5545 + info->rmpiGroup[info->rmpiNbrOfGroups ++] = readGroup;
5547 + recordPatternSequence( info, name, type, info->rmpiNbrOfGroups-1 );
5550 + return (readGroup != NULL);
5554 + if (info->rmpiNbrOfElements >= MAX_NBR_MATCH_PATTERNS)
5556 + errInfo->eiMPTabElementName = XtNewString(name);
5557 + errInfo->eiDetail = "max number of match patterns exceeded";
5563 + readMatchPatternTableElement( inPtr, &errInfo->eiDetail, name, type );
5565 + if (readElement == NULL)
5567 + errInfo->eiMPTabElementName = XtNewString(name);
5572 + readElement->mpteIndex = info->rmpiNbrOfElements;
5574 + info->rmpiElement[info->rmpiNbrOfElements ++] = readElement;
5576 + if (type == MPT_INDIVIDUAL)
5578 + if (!assignIndividualGroup( info, &errInfo->eiDetail, readElement ))
5580 + errInfo->eiMPTabElementName = XtNewString(name);
5585 + treatDuplicatedMTEntries(
5586 + info->rmpiElement, info->rmpiNbrOfElements );
5588 + recordPatternSequence( info, name, type, info->rmpiNbrOfElements-1 );
5591 + return (readElement != NULL);
5596 +** Record match pattern sequence for display of match pattern dialog.
5598 +static void recordPatternSequence(
5599 + ReadMatchPatternInfo *info,
5601 + MatchPatternType type,
5604 + MatchPatternSequenceElement *sequence;
5607 + (MatchPatternSequenceElement *)XtMalloc( sizeof(MatchPatternSequenceElement) );
5609 + sequence->mpseName = XtNewString(name);
5610 + sequence->mpseType = type;
5611 + sequence->mpseIndex = index;
5613 + info->rmpiSequence[info->rmpiNbrOfSeqElements ++] = sequence;
5617 +** Assign a new group to an individual match pattern.
5618 +** Returns true, if assignment was successful.
5620 +static int assignIndividualGroup(
5621 + ReadMatchPatternInfo *info,
5623 + MatchPatternTableElement *element)
5625 + MatchPatternGroupElement *group = NULL;
5627 + if (info->rmpiNbrOfGroups >= MAX_NBR_MATCH_PATTERN_GROUPS)
5629 + *errMsg = "max. number of matching pattern groups exceeded\n";
5634 + * Assign the index of new group to the individual matching pattern
5636 + element->mpteGroup = info->rmpiNbrOfGroups;
5639 + * Allocate memory for the matching pattern group and copy the
5640 + * info into this group element.
5643 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
5645 + group->mpgeName = NULL;
5646 + group->mpgeKeywordRE = NULL;
5649 + * remember name of match pattern table element, which is
5650 + * represented by this group.
5652 + group->mpgeNumberOfSubPatterns = 1;
5653 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeof(char *) );
5654 + group->mpgeSubPatternIds[0] = XtNewString(element->mpteName);
5656 + info->rmpiGroup[info->rmpiNbrOfGroups ++] = group;
5662 +** Get the match pattern table element of given 'patToSearch'
5664 +** Returns NULL, if no element was found.
5666 +static MatchPatternTableElement *getPatternOfName(
5667 + ReadMatchPatternInfo *info,
5668 + char *patToSearch)
5671 + MatchPatternTableElement *element;
5673 + for (i=0; i<info->rmpiNbrOfElements; i ++)
5675 + element = info->rmpiElement[i];
5677 + if (strcmp( element->mpteName, patToSearch ) == 0)
5680 + * Related sub-pattern found:
5687 + * No sub-pattern found:
5693 +** Read match pattern group of given match pattern string.
5694 +** Returns NULL, if read fails.
5696 +static MatchPatternGroupElement *readMatchPatternGroup(
5698 + ErrorInfo *errInfo,
5700 + ReadMatchPatternInfo *info)
5703 + int error = False;
5704 + char *patNameInPtr;
5706 + MatchPatternTableElement *subPatElement;
5707 + int numberOfRelatedSubPattern = 0;
5708 + char *relatedSubPatternId[MAX_NBR_MATCH_PATTERNS];
5710 + MatchPatternGroupElement *group = NULL;
5713 + * Read sub-matching patterns of this group.
5715 + while (**inPtr != '\n' && !error)
5718 + * Read next pattern name from inPtr.
5720 + patNameInPtr = *inPtr;
5721 + subPatName = ReadSymbolicField(inPtr);
5723 + if (subPatName == NULL)
5725 + errInfo->eiDetail = "Sub-Matching Pattern Name expected";
5731 + * Get matching pattern related to sub-matching pattern name.
5734 + getPatternOfName( info, subPatName );
5736 + if (subPatElement == NULL)
5738 + errInfo->eiStringPatText = XtNewString(subPatName);
5739 + errInfo->eiDetail = "Sub-Matching Pattern not defined before";
5742 + else if (numberOfRelatedSubPattern >= MAX_NBR_MATCH_PATTERNS)
5744 + errInfo->eiDetail = "Group holds too many Sub-Matching Patterns";
5747 + else if (subPatElement->mpteType != MPT_SUB)
5749 + errInfo->eiStringPatText = XtNewString(subPatName);
5750 + errInfo->eiDetail = "Not a Sub-Matching Pattern";
5756 + * Remember sub-matching pattern ID
5758 + relatedSubPatternId[numberOfRelatedSubPattern ++] = subPatName;
5761 + * Assign the index of this group to the sub-matching pattern
5762 + * if no group index was assigned before.
5764 + if (subPatElement->mpteGroup == NO_GROUP_IDX)
5766 + subPatElement->mpteGroup = info->rmpiNbrOfGroups;
5771 + * Skip to the start of the next matching pattern name.
5773 + if (!error && !SkipDelimiter(inPtr, &errInfo->eiDetail))
5782 + for (i=0; i < numberOfRelatedSubPattern; i++)
5784 + XtFree( relatedSubPatternId[i] );
5792 + * Allocate memory for the matching pattern group and copy the
5793 + * info into this group element.
5796 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
5798 + group->mpgeName = name;
5799 + group->mpgeKeywordRE = NULL;
5802 + * Allocate memory for the sub-matching pattern IDs & copy
5803 + * related sub-matching pattern into the group element.
5805 + sizeOfIds = sizeof(char *) * numberOfRelatedSubPattern;
5806 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeOfIds );
5808 + memcpy(group->mpgeSubPatternIds, relatedSubPatternId, sizeOfIds);
5810 + group->mpgeNumberOfSubPatterns = numberOfRelatedSubPattern;
5817 +** Read one match pattern element from given match pattern string.
5818 +** Returns true, if read was successful.
5820 +static int readPatternElement(
5823 + PatternElement **pattern)
5825 + PatternElementKind patternKind;
5826 + PatternWordBoundary wordBoundary;
5827 + int caseInsensitive;
5828 + int regularExpression;
5831 + if (!getMPSPatternAttribute(
5837 + ®ularExpression ))
5842 + if (!ReadQuotedString(inPtr, errMsg, &string))
5847 + if (!SkipDelimiter(inPtr, errMsg))
5854 + createPatternElement(
5859 + regularExpression);
5865 +** Create a pattern element.
5867 +static PatternElement *createPatternElement(
5868 + char *patternText,
5869 + PatternElementKind patternKind,
5870 + PatternWordBoundary wordBoundary,
5871 + int caseInsensitive,
5872 + int regularExpression)
5874 + PatternElement *pattern;
5878 + * Convert pattern text to lower case, if case insensitive
5879 + * attribute is set.
5881 + if (caseInsensitive)
5883 + for (s = patternText; *s != '\0'; s ++)
5890 + * Allocate memory for the new pattern element and init. / copy
5891 + * related info into this pattern element.
5893 + pattern = (PatternElement *)XtMalloc( sizeof(PatternElement) );
5895 + initStrPatBackRefList(&pattern->peVal.peuSingle);
5897 + pattern->peKind = patternKind;
5898 + pattern->peIndex = NO_PATTERN_IDX;
5899 + pattern->peType = PET_SINGLE;
5901 + pattern->peVal.peuSingle.spLength = strlen(patternText);
5902 + pattern->peVal.peuSingle.spBackRefParsed = False;
5903 + pattern->peVal.peuSingle.spBackRefResolved = False;
5905 + pattern->peVal.peuSingle.spCaseInsensitive = caseInsensitive;
5906 + pattern->peVal.peuSingle.spRegularExpression = regularExpression;
5907 + pattern->peVal.peuSingle.spTextRE = NULL;
5910 + * Store original string of regular expression patterns due to
5911 + * it may be later adapted (e.g. due to global backrefs etc.).
5913 + if (regularExpression)
5915 + pattern->peVal.peuSingle.spOrigText = patternText;
5916 + pattern->peVal.peuSingle.spText = NULL;
5917 + pattern->peVal.peuSingle.spWordBoundary = PWB_NONE;
5921 + pattern->peVal.peuSingle.spOrigText = NULL;
5922 + pattern->peVal.peuSingle.spText = patternText;
5923 + pattern->peVal.peuSingle.spWordBoundary = wordBoundary;
5930 +** Create a list holding all global backref definitions of given
5931 +** match pattern table element. The list is stored in this given
5933 +** Returns true, if list was successfully created.
5935 +static int createGlobalBackRefList(
5936 + ReadMatchPatternInfo *readPatInfo,
5937 + MatchPatternTableElement *element,
5938 + ErrorInfo *errInfo)
5941 + StringPattern *strPat;
5943 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
5945 + strPat = getReadStringPattern(readPatInfo, element->mpteAll.pesPattern[i]);
5947 + if (strPat->spRegularExpression)
5949 + if (strPat->spBackRefParsed)
5952 + * Global backrefs or this string pattern already parsed:
5953 + * just merge string pattern list with elements one.
5955 + if (!updateGlobalBackRefs(
5957 + element->mpteGlobalBackRef,
5966 + * parse string pattern for global backrefs and
5967 + * merge string pattern list with elements one.
5969 + if (!parseGlobalBackRefs(
5971 + element->mpteGlobalBackRef,
5984 +** Returns read string pattern of given pattern element.
5986 +StringPattern *getReadStringPattern(
5987 + ReadMatchPatternInfo *readPatInfo,
5988 + PatternElement *pattern )
5990 + switch (pattern->peType)
5993 + return &pattern->peVal.peuSingle;
5996 + case PET_MULTIPLE:
5997 + return &pattern->peVal.peuMulti.mpStringPattern;
6000 + case PET_REFERENCE:
6001 + return getReadStringPattern(
6003 + getReadPatternOfReference(readPatInfo, &pattern->peVal.peuRef));
6008 + * never reached; just to make compiler happy
6014 +** Returns read pattern element of given pattern reference.
6016 +static PatternElement *getReadPatternOfReference(
6017 + ReadMatchPatternInfo *readPatInfo,
6018 + PatternReference *patRef)
6020 + MatchPatternTableElement **element = readPatInfo->rmpiElement;
6022 + return element[ patRef->prElementIdx ]->mpteAll.pesPattern[patRef->prPatternIdx];
6026 +** Allocate a new copy of given string and substitute each capturing
6027 +** parentheses inside given string by a non-capturing one.
6028 +** Returns resulting string.
6030 +static char *replaceCapturingParentheses(
6031 + const char *source)
6033 + char *destination;
6036 + int nbrOfOpenBraces = 0;
6041 + * count number of open braces
6043 + while (*s != '\0')
6046 + nbrOfOpenBraces ++;
6050 + * allocate memory for substitued reg. exp. text
6052 + destination = XtMalloc(strlen(source) + 2*nbrOfOpenBraces);
6055 + * substitute each capturing open brace by a non-capturing one
6060 + while (*s != '\0')
6069 + else if (*s == '(')
6073 + if (*s != '?' && *s != '*')
6087 + return destination;
6091 +** Parse given string pattern for global backrefs definitions
6092 +** (syntax: "(*n", where n=1..9). Add found global backrefs to
6093 +** given backRefList.
6094 +** Returns false, if parse fails.
6096 +static int parseGlobalBackRefs(
6097 + StringPattern *strPat,
6098 + GlobalBackRefElement *backRefList,
6099 + ErrorInfo *errInfo)
6102 + char *backRefContent;
6103 + int nestingLevel = 0;
6104 + int stackIdx = -1;
6105 + BackRefBracketInfo backRefInfo[MAX_GLOBAL_BACK_REF_ID+1];
6106 + StrPatBackRefElement *curStrPatBRE;
6108 + strPat->spText = replaceCapturingParentheses(strPat->spOrigText);
6109 + strPat->spLength = strlen(strPat->spText);
6110 + strPat->spBackRefParsed = True;
6112 + s = strPat->spText;
6114 + while (*s != '\0')
6119 + * Ignore escaped characters
6121 + if (*(s+1) != '\0')
6124 + else if (*s == '(')
6126 + if (*(s+1) == '*')
6128 + if (isdigit((unsigned char)*(s+2)))
6131 + * Global backref. definition start found:
6135 + backRefInfo[stackIdx].brbiGlobalId =
6136 + (int)((unsigned char)*(s+2) - (unsigned char)'0') - 1;
6138 + if(backRefInfo[stackIdx].brbiGlobalId < 0)
6140 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6141 + errInfo->eiDetail = "Backref '0' not allowed";
6145 + backRefInfo[stackIdx].brbiContentStart = s+3;
6146 + backRefInfo[stackIdx].brbiNestingLevel = nestingLevel;
6153 + else if (*s == ')')
6156 + if (stackIdx != -1 &&
6157 + backRefInfo[stackIdx].brbiNestingLevel == nestingLevel)
6160 + * Global backref. definition end found: add it to
6161 + * backref. list of string pattern.
6164 + &strPat->spOwnGlobalBackRef[backRefInfo[stackIdx].brbiGlobalId];
6167 + createBackRefRegExpText(
6168 + backRefInfo[stackIdx].brbiContentStart,
6171 + if (curStrPatBRE->spbreRegExpText != NULL)
6173 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6174 + errInfo->eiBackRefNbr = backRefInfo[stackIdx].brbiGlobalId + 1;
6175 + errInfo->eiDetail = "already defined before";
6176 + XtFree(backRefContent);
6181 + curStrPatBRE->spbreRegExpText = backRefContent;
6191 + * Merge global backref. list of string pattern with given backRefList.
6193 + return updateGlobalBackRefs(
6200 +** Merge global backref. list of given string pattern with given backRefList.
6201 +** Returns false, if merge fails.
6203 +static int updateGlobalBackRefs(
6204 + StringPattern *strPat,
6205 + GlobalBackRefElement *backRefList,
6206 + ErrorInfo *errInfo)
6209 + StrPatBackRefElement *curStrPatBRE;
6210 + GlobalBackRefElement *curGlobalBRE;
6212 + for (i=0;i < MAX_GLOBAL_BACK_REF_ID; i ++)
6214 + curStrPatBRE = &strPat->spOwnGlobalBackRef[i];
6216 + if (curStrPatBRE->spbreRegExpText != NULL)
6218 + curGlobalBRE = &backRefList[i];
6220 + if (curGlobalBRE->gbreDefByStrPat != NULL)
6222 + if (strcmp(curGlobalBRE->gbreRegExpText, curStrPatBRE->spbreRegExpText) != 0)
6224 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6225 + errInfo->eiBackRefNbr = i+1;
6226 + errInfo->eiDetail = "already defined before";
6233 + curGlobalBRE->gbreDefByStrPat = strPat;
6234 + curGlobalBRE->gbreRegExpText = curStrPatBRE->spbreRegExpText;
6243 +** Allocate and return a new string holding content of
6244 +** global backref. definition.
6246 +static char *createBackRefRegExpText(
6247 + const char *start,
6250 + int len = end - start;
6251 + char *regExpText = XtMalloc( len+1 );
6253 + memcpy( regExpText, start, len );
6255 + regExpText[len] = '\0';
6257 + return regExpText;
6261 +** Resolve all global backrefs of given match pattern table element.
6262 +** Returns false, if resolve fails.
6264 +static int resolveGlobalBackRefs(
6265 + ReadMatchPatternInfo *readPatInfo,
6266 + MatchPatternTableElement *element,
6267 + ErrorInfo *errInfo)
6270 + StringPattern *strPat;
6272 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
6274 + strPat = getReadStringPattern(readPatInfo, element->mpteAll.pesPattern[i]);
6276 + if (strPat->spRegularExpression && !strPat->spBackRefResolved)
6278 + if (!resolveGlobalBackRefsOfStrPat(strPat, element->mpteGlobalBackRef, errInfo))
6281 + strPat->spBackRefResolved = True;
6289 +** Resolve global backrefs of given string pattern.
6290 +** Returns false, if resolve fails.
6292 +static int resolveGlobalBackRefsOfStrPat(
6293 + StringPattern *strPat,
6294 + GlobalBackRefElement *backRefList,
6295 + ErrorInfo *errInfo)
6301 + s = strPat->spText;
6303 + while (*s != '\0')
6307 + if (isdigit((unsigned char)*(s+1)))
6310 + * \n (n=1..9) found: substitute global backref.
6313 + (int)((unsigned char)*(s+1) - (unsigned char)'0') - 1;
6317 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6318 + errInfo->eiDetail = "backref '\\0' not allowed";
6322 + s = substituteGlobalBackRef(strPat, s, globalId, &localId, backRefList, errInfo);
6327 + else if (*(s+1) != '\0')
6330 + else if (*s == '(')
6332 + if (*(s+1) == '*')
6334 + if (isdigit((unsigned char)*(s+2)))
6337 + * "(*n" (n=1..9) found: substitute global backref. definition.
6340 + (int)((unsigned char)*(s+2) - (unsigned char)'0') - 1;
6342 + strPat->spOwnGlobalBackRef[globalId].spbreLocalBackRefID = localId;
6343 + strPat->spGlobalToLocalBackRef[globalId] = localId;
6347 + s = convertGlobalToLocalBackRef(strPat, s);
6362 +** Substitute global backref (\n, n=1..9) located at given "subsPtr"
6363 +** by its definition or by a local backref.
6365 +** - NULL, if substitute fails or
6366 +** - substituted string pointer, where scan shall continue with.
6368 +static char *substituteGlobalBackRef(
6369 + StringPattern *strPat,
6373 + GlobalBackRefElement *backRefList,
6374 + ErrorInfo *errInfo)
6376 + StrPatBackRefElement *strPatBackRef = &strPat->spOwnGlobalBackRef[globalId];
6379 + if (strPatBackRef->spbreRegExpText == NULL)
6382 + * given global backref definition is not located in given
6383 + * string pattern -> replace backref ID by backref reg. exp.
6385 + if (backRefList[globalId].gbreRegExpText == NULL)
6387 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6388 + errInfo->eiBackRefNbr = globalId + 1;
6389 + errInfo->eiDetail = "not defined within any string pattern";
6393 + if (strPat->spGlobalToLocalBackRef[globalId] == NO_LOCAL_BACK_REF_ID)
6396 + * 1st occurence of global backref ID in this pattern ->
6397 + * replace global backref ID by backref reg. exp.
6399 + s = replaceBackRefIdByRegExp(strPat, subsPtr, backRefList[globalId].gbreRegExpText);
6401 + strPat->spGlobalToLocalBackRef[globalId] = *localId;
6407 + * next occurence of global backref ID in this pattern ->
6408 + * replace global backref ID by local one
6411 + *s = (char)((int)('0') + strPat->spGlobalToLocalBackRef[globalId]);
6417 + * given global backref definition is located in given string pattern
6419 + if (strPatBackRef->spbreLocalBackRefID == NO_LOCAL_BACK_REF_ID)
6421 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6422 + errInfo->eiBackRefNbr = globalId + 1;
6423 + errInfo->eiDetail = "not defined before";
6428 + * replace global backref ID by local one
6431 + *s = (char)((int)('0') + strPatBackRef->spbreLocalBackRefID);
6438 +** Replace global backref ID ("\n", n=1..9), located at given
6439 +** replaceStartPtr, by its definition (given by regExp parameter).
6440 +** Returns string pointer, where scan shall continue with
6442 +static char *replaceBackRefIdByRegExp(
6443 + StringPattern *strPat,
6444 + char *replaceStartPtr,
6447 + char *oldText = strPat->spText;
6450 + char *continueScanPtr;
6451 + int oldLen = strlen(oldText);
6452 + int regExpLen = strlen(regExp);
6453 + int replacePos = replaceStartPtr - oldText;
6454 + int remainingLen = oldLen-replacePos-2;
6457 + * replace "\n" - located at replaceStartPtr - by "(regExp)"
6459 + newText = XtMalloc(oldLen + regExpLen + 3);
6461 + memcpy(newText, oldText, replacePos);
6462 + n = newText + replacePos;
6464 + continueScanPtr = n;
6466 + memcpy(n, regExp, regExpLen);
6470 + memcpy(n, replaceStartPtr+2, remainingLen);
6471 + *(n + remainingLen) = '\0';
6475 + strPat->spText = newText;
6476 + strPat->spLength = strlen(newText);
6478 + return continueScanPtr;
6482 +** Convert global backref definition ("(*n", n=1..9), located at given
6483 +** convertPtr, by capturing parentheses "(".
6484 +** Returns string pointer, where scan shall continue with
6486 +static char *convertGlobalToLocalBackRef(
6487 + StringPattern *strPat,
6490 + char *oldText = strPat->spText;
6492 + int oldLen = strlen(oldText);
6493 + int convertPos = convertPtr - oldText;
6496 + * replace "(*n" - located at convertPtr - by "("
6498 + newText = XtMalloc(oldLen - 1);
6500 + memcpy(newText, oldText, convertPos+1);
6501 + memcpy(newText+convertPos+1, convertPtr+3, oldLen-convertPos-3);
6503 + *(newText + oldLen - 2) = '\0';
6507 + strPat->spText = newText;
6508 + strPat->spLength = strlen(newText);
6510 + return newText + convertPos;
6514 +** Read a match pattern table element from given input string.
6515 +** Return NULL, if read fails.
6517 +static MatchPatternTableElement *readMatchPatternTableElement(
6521 + MatchPatternType type)
6523 + int error = False;
6524 + PatternElement *pattern;
6525 + PatternElement *allPat[MAX_STRING_PATTERNS];
6528 + MatchPatternTableElement *result;
6529 + int isMonoPattern;
6530 + int skipBtwStartEnd;
6532 + int ignoreHighLightInfo;
6535 + if (!getMPSGlobalAttribute(
6541 + &ignoreHighLightInfo ))
6547 + * read all patterns
6549 + while (**inPtr != '\n' && !error)
6551 + if (!readPatternElement( inPtr, errMsg, &pattern ))
6555 + else if (nbrOfPat >= MAX_STRING_PATTERNS)
6557 + *errMsg = "max. number of string patterns exceeded";
6562 + pattern->peIndex = nbrOfPat;
6564 + allPat[nbrOfPat ++] = pattern;
6570 + for (i=0; i < nbrOfPat; i ++)
6571 + freePatternElement( allPat[i] );
6576 + if (nbrOfPat == 0)
6578 + *errMsg = "min. one string pattern needed";
6583 + * allocate & init. MatchPatternTableElement
6586 + (MatchPatternTableElement *)XtMalloc(sizeof(MatchPatternTableElement));
6588 + result->mpteName = name;
6589 + result->mpteIndex = NO_ELEMENT_IDX;
6590 + result->mpteType = type;
6591 + result->mpteGroup = NO_GROUP_IDX;
6593 + sizeOfPat = sizeof(PatternElement *) * nbrOfPat;
6594 + result->mpteAll.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6596 + memcpy(result->mpteAll.pesPattern, allPat, sizeOfPat);
6598 + result->mpteAll.pesNumberOfPattern = nbrOfPat;
6600 + result->mpteIsMonoPattern = isMonoPattern;
6601 + result->mpteSkipBtwnStartEnd = skipBtwStartEnd;
6602 + result->mpteFlash = flash;
6603 + result->mpteIgnoreHighLightInfo = ignoreHighLightInfo;
6605 + result->mpteStartEndRE = NULL;
6607 + initGlobalBackRefList( result->mpteGlobalBackRef );
6610 + * sort start / end / middle pattern
6612 + error = !sortReadPatternElementSet( &result->mpteAll, errMsg, result );
6616 + freeMatchPatternTableElement( result );
6626 + * Sort read pattern element set into start, middle & end arrays.
6627 + * Validate "monopattern" attribute.
6628 + * Returns true, if validation was successful.
6630 +static int sortReadPatternElementSet(
6631 + PatternElementSet *allPat,
6633 + MatchPatternTableElement *result)
6636 + int isMonoPattern = result->mpteIsMonoPattern;
6639 + * count number of start, middle & end pattern elements.
6641 + countPatternElementKind( allPat, result );
6644 + * validate and allocate pattern elements.
6646 + if (result->mpteStart.pesNumberOfPattern != 0)
6648 + sizeOfPat = sizeof(PatternElement *) * result->mpteStart.pesNumberOfPattern;
6649 + result->mpteStart.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6653 + *errMsg = "min. one start pattern needed";
6657 + if (isMonoPattern &&
6658 + (result->mpteMiddle.pesNumberOfPattern != 0 ||
6659 + result->mpteEnd.pesNumberOfPattern !=0))
6661 + *errMsg = "mono pattern: only start pattern(s) allowed due to attribute [m]";
6665 + if (result->mpteMiddle.pesNumberOfPattern != 0)
6667 + sizeOfPat = sizeof(PatternElement *) * result->mpteMiddle.pesNumberOfPattern;
6668 + result->mpteMiddle.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6671 + if (result->mpteEnd.pesNumberOfPattern != 0)
6673 + sizeOfPat = sizeof(PatternElement *) * result->mpteEnd.pesNumberOfPattern;
6674 + result->mpteEnd.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6678 + if (!isMonoPattern)
6680 + *errMsg = "min. one end pattern needed";
6686 + * sort pattern elements into start, middle & end arrays.
6688 + sortPatternElementSet( allPat, result );
6690 + if (isMonoPattern)
6692 + copyPatternSet( &result->mpteStart, &result->mpteEnd );
6699 + * Count number of start, middle & end patterns stored in "allPat".
6701 +static void countPatternElementKind(
6702 + PatternElementSet *allPat,
6703 + MatchPatternTableElement *result)
6707 + result->mpteStart.pesNumberOfPattern = 0;
6708 + result->mpteEnd.pesNumberOfPattern = 0;
6709 + result->mpteMiddle.pesNumberOfPattern = 0;
6711 + result->mpteStart.pesPattern = NULL;
6712 + result->mpteEnd.pesPattern = NULL;
6713 + result->mpteMiddle.pesPattern = NULL;
6715 + for (i=0; i < allPat->pesNumberOfPattern; i ++)
6717 + switch (allPat->pesPattern[i]->peKind)
6720 + result->mpteStart.pesNumberOfPattern ++;
6723 + result->mpteMiddle.pesNumberOfPattern ++;
6726 + result->mpteEnd.pesNumberOfPattern ++;
6734 + * Sort start, middle & end pattern elements into related arrays.
6736 +static void sortPatternElementSet(
6737 + PatternElementSet *allPat,
6738 + MatchPatternTableElement *result)
6743 + for (i=0, s=0, m=0, e=0; i < allPat->pesNumberOfPattern; i ++)
6745 + switch (allPat->pesPattern[i]->peKind)
6748 + result->mpteStart.pesPattern[s ++] = allPat->pesPattern[i];
6751 + result->mpteMiddle.pesPattern[m ++] = allPat->pesPattern[i];
6754 + result->mpteEnd.pesPattern[e ++] = allPat->pesPattern[i];
6761 +static void copyPatternSet(
6762 + PatternElementSet *sourcePS,
6763 + PatternElementSet *destPS)
6767 + destPS->pesNumberOfPattern = sourcePS->pesNumberOfPattern;
6769 + sizeOfPat = sizeof(PatternElement *) * destPS->pesNumberOfPattern;
6770 + destPS->pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6772 + memcpy(destPS->pesPattern, sourcePS->pesPattern, sizeOfPat);
6776 +** Free the allocated memory contained in a ReadMatchPatternInfo data structure
6778 +static void freeReadMatchPatternInfo( ReadMatchPatternInfo *readPatInfo )
6782 + for (i=0; i<readPatInfo->rmpiNbrOfElements; i++)
6783 + freeMatchPatternTableElement(readPatInfo->rmpiElement[i]);
6785 + for (i=0; i<readPatInfo->rmpiNbrOfGroups; i++)
6786 + freeMatchPatternGroupElement(readPatInfo->rmpiGroup[i]);
6788 + for (i=0; i<readPatInfo->rmpiNbrOfSeqElements; i++)
6789 + freeMatchPatternSequenceElement(readPatInfo->rmpiSequence[i]);
6791 + freePtr((void **)&readPatInfo->rmpiAllPatRE);
6793 + freePtr((void **)&readPatInfo->rmpiFlashPatRE);
6797 +** Free the allocated memory contained in a StringMatchTable data structure
6799 +static void freeStringMatchTable( StringMatchTable *table )
6801 + MatchPatternTable *patTable;
6804 + if (table == NULL)
6807 + XtFree(table->smtLanguageMode);
6810 + * Free all matching patterns
6812 + patTable = table->smtAllPatterns;
6814 + for (i=0; i<patTable->mptNumberOfElements; i++)
6815 + freeMatchPatternTableElement(patTable->mptElements[i]);
6817 + XtFree((char *)patTable);
6820 + * Free matching pattern group elements
6822 + for (i=0; i<table->smtNumberOfGroups; i++)
6823 + freeMatchPatternGroupElement(table->smtGroups[i]);
6826 + * Free matching pattern sequence elements
6828 + for (i=0; i<table->smtNumberOfSeqElements; i++)
6829 + freeMatchPatternSequenceElement(table->smtSequence[i]);
6832 + * Free keyword reg. expressions
6834 + freePtr((void **)&table->smtAllPatRE);
6836 + freePtr((void **)&table->smtFlashPatRE);
6838 + XtFree((char *)table);
6842 +** Free the allocated memory contained in a MatchPatternTableElement data structure
6844 +static void freeMatchPatternTableElement( MatchPatternTableElement *element )
6848 + XtFree(element->mpteName);
6850 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
6852 + freePatternElement(element->mpteAll.pesPattern[i]);
6855 + freePtr((void **)&element->mpteStartEndRE);
6857 + freeXtPtr((void **)&element->mpteStart.pesPattern);
6859 + freeXtPtr((void **)&element->mpteMiddle.pesPattern);
6861 + freeXtPtr((void **)&element->mpteEnd.pesPattern);
6863 + XtFree((char *)element);
6867 +** Free the allocated memory contained in a PatternElement data structure
6869 +static void freePatternElement( PatternElement *element )
6871 + if (element->peType == PET_SINGLE)
6872 + freeStringPattern( &(element->peVal.peuSingle) );
6873 + else if (element->peType == PET_MULTIPLE)
6875 + freeStringPattern( &(element->peVal.peuMulti.mpStringPattern) );
6876 + XtFree( (char *)element->peVal.peuMulti.mpRefList );
6879 + XtFree( (char *)element );
6883 +** Free the allocated memory contained in a StringPattern data structure
6885 +static void freeStringPattern( StringPattern *strPat )
6889 + freeXtPtr((void **)&strPat->spText);
6890 + freeXtPtr((void **)&strPat->spOrigText);
6892 + freePtr((void **)&strPat->spTextRE);
6894 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
6895 + freeXtPtr((void **)&strPat->spOwnGlobalBackRef[i].spbreRegExpText);
6899 +** Free the allocated memory contained in a MatchPatternGroupElement data structure
6901 +static void freeMatchPatternGroupElement( MatchPatternGroupElement *group )
6905 + freeXtPtr((void **)&group->mpgeName);
6907 + freePtr((void **)&group->mpgeKeywordRE);
6909 + if (group->mpgeSubPatternIds != NULL)
6911 + for (i=0; i < group->mpgeNumberOfSubPatterns; i++)
6913 + XtFree(group->mpgeSubPatternIds[i]);
6915 + XtFree((char *)group->mpgeSubPatternIds);
6918 + XtFree((char *)group);
6922 +** Free the allocated memory contained in a MatchPatternSequenceElement data structure
6924 +static void freeMatchPatternSequenceElement( MatchPatternSequenceElement *sequence )
6926 + XtFree( sequence->mpseName );
6928 + XtFree( (char *)sequence );
6933 +** Format a matching pattern set parse error.
6935 +static void parseMatchingPatternSetError(
6936 + const char *stringStart,
6937 + const char *stoppedAt,
6938 + ErrorInfo *errInfo)
6940 + char *message = "";
6942 + char *errorInForm = "matching pattern of \"%s\"";
6945 + if (errInfo->eiLanguageMode == NULL)
6947 + errorIn = "matching pattern";
6951 + errorIn = XtMalloc(strlen(errorInForm) + strlen(errInfo->eiLanguageMode)+1);
6952 + sprintf(errorIn, "matching pattern of \"%s\"", errInfo->eiLanguageMode);
6955 + if (errInfo->eiRegExpCompileMsg != NULL)
6958 + * Error message of form:
6959 + * "MP \"eiMPTabElementName\", SP \"eiStringPatText\": eiRegExpCompileMsg" or
6960 + * "MP \"eiMPTabElementName\" - eiDetail: eiRegExpCompileMsg"
6963 + msgLen = strlen(errInfo->eiRegExpCompileMsg) + 1;
6965 + if (errInfo->eiMPTabElementName != NULL)
6966 + msgLen += strlen(errInfo->eiMPTabElementName) + 10;
6968 + if (errInfo->eiDetail != NULL)
6970 + msgLen += strlen(errInfo->eiDetail + 2);
6974 + if (errInfo->eiStringPatText != NULL)
6975 + msgLen += strlen(errInfo->eiStringPatText) + 9;
6978 + message = XtMalloc(msgLen);
6980 + strcpy(message, "");
6982 + if (errInfo->eiMPTabElementName != NULL)
6983 + sprintf( message, "MP \"%s\"", errInfo->eiMPTabElementName);
6985 + if (errInfo->eiDetail == NULL)
6987 + if (errInfo->eiStringPatText != NULL)
6988 + sprintf( message, "%s, SP \"%s\"", message, errInfo->eiStringPatText);
6992 + if (strlen(message) != 0)
6993 + strcat(message, " - ");
6995 + strcat(message, errInfo->eiDetail);
6998 + if (strlen(message) != 0)
6999 + strcat(message, ": ");
7001 + strcat(message, errInfo->eiRegExpCompileMsg);
7003 + else if (errInfo->eiDetail != NULL)
7006 + * Error message of form:
7007 + * "MP \"eiMPTabElementName\", SP \"eiStringPatText\": Backref %d eiDetail
7009 + msgLen = strlen(errInfo->eiDetail) + 1;
7011 + if (errInfo->eiMPTabElementName != NULL)
7012 + msgLen += strlen(errInfo->eiMPTabElementName) + 7;
7013 + if (errInfo->eiStringPatText != NULL)
7014 + msgLen += strlen(errInfo->eiStringPatText) + 9;
7015 + if (errInfo->eiBackRefNbr != 0)
7018 + message = XtMalloc(msgLen);
7020 + strcpy(message, "");
7022 + if (errInfo->eiMPTabElementName != NULL)
7023 + sprintf( message, "MP \"%s\"", errInfo->eiMPTabElementName);
7024 + if (errInfo->eiStringPatText != NULL)
7025 + sprintf( message, "%s, SP \"%s\"", message, errInfo->eiStringPatText);
7027 + if (strlen(message) != 0)
7028 + strcat(message, ": ");
7030 + if (errInfo->eiBackRefNbr != 0)
7031 + sprintf( message, "%s Backref %d ", message, errInfo->eiBackRefNbr);
7033 + strcat(message, errInfo->eiDetail);
7036 + ParseError(NULL, stringStart, stoppedAt, errorIn, message);
7038 + if (errInfo->eiRegExpCompileMsg != NULL || errInfo->eiDetail != NULL)
7043 + if (errInfo->eiLanguageMode != NULL)
7048 + freeErrorInfo(errInfo);
7049 + initErrorInfo(errInfo);
7053 + * Pop-up a warning dialog showing a matching pattern set error.
7055 +static void dialogMatchingPatternSetError(
7057 + ErrorInfo *errInfo)
7063 + * Error message of form:
7064 + * "Name : \"eiMPTabElementName\"\n
7065 + * "String: \"eiStringPatText\"\n
7067 + * eiRegExpCompileMsg\n"
7070 + if (errInfo->eiMPTabElementName != NULL)
7071 + msgLen += strlen(errInfo->eiMPTabElementName) + 15;
7072 + if (errInfo->eiStringPatText != NULL)
7073 + msgLen += strlen(errInfo->eiStringPatText) + 15;
7074 + if (errInfo->eiDetail != NULL)
7075 + msgLen += strlen(errInfo->eiDetail) + 15;
7076 + if (errInfo->eiBackRefNbr != 0)
7078 + if (errInfo->eiRegExpCompileMsg != NULL)
7079 + msgLen += strlen(errInfo->eiRegExpCompileMsg) + 15;
7081 + message = XtMalloc(msgLen);
7083 + strcpy(message, "");
7085 + if (errInfo->eiMPTabElementName != NULL)
7086 + sprintf( message, "%sName : \"%s\"\n", message, errInfo->eiMPTabElementName);
7087 + if (errInfo->eiStringPatText != NULL)
7088 + sprintf( message, "%sPattern: \"%s\"\n", message, errInfo->eiStringPatText);
7089 + if (errInfo->eiBackRefNbr != 0)
7090 + sprintf( message, "%sBackref %d ", message, errInfo->eiBackRefNbr);
7091 + if (errInfo->eiDetail != NULL)
7092 + sprintf( message, "%s%s\n", message, errInfo->eiDetail);
7093 + if (errInfo->eiRegExpCompileMsg != NULL)
7094 + sprintf( message, "%s%s\n", message, errInfo->eiRegExpCompileMsg);
7097 + DF_WARN, MatchPatternDialog.mpdShell, 1,
7099 + "%s(language mode '%s')",
7102 + errInfo->eiLanguageMode);
7106 + freeErrorInfo(errInfo);
7107 + initErrorInfo(errInfo);
7111 +** Get matching pattern set name.
7113 +** patternName ::= "name:"
7114 +** Returns true, if get was successful.
7116 +static int getMPSName(
7118 + ErrorInfo *errInfo,
7122 + char *field = ReadSymbolicField(inPtr);
7124 + if (field == NULL)
7126 + errInfo->eiDetail = "matching pattern name missing";
7130 + if (!SkipDelimiter(inPtr, &dummy))
7132 + errInfo->eiMPTabElementName = XtNewString(field);
7133 + errInfo->eiDetail = "':' missing after matching pattern name";
7144 +** Get matching pattern set type attribute.
7145 +** TypeAttribute ::=
7148 +** s : sub-pattern (pattern is only matched, if part of a pattern group).
7149 +** g : pattern (context) group (i.e. a sequence of sub-patterns).
7150 +** default: individual pattern (pattern is not part of a group and is
7151 +** matched individually.
7152 +** Returns true, if get was successful.
7154 +static int getMPSTypeAttribute(
7156 + ErrorInfo *errInfo,
7157 + MatchPatternType *type)
7159 + char *field = ReadSymbolicField(inPtr);
7160 + int successful = True;
7162 + *type = MPT_INDIVIDUAL;
7164 + if (field != NULL)
7169 + *type = MPT_GROUP;
7175 + errInfo->eiDetail = "unknown matching pattern type attribute";
7176 + successful = False;
7182 + if (!SkipDelimiter(inPtr, &errInfo->eiDetail))
7184 + successful = False;
7188 + freeXtPtr((void **)&field);
7190 + return successful;
7196 +** GlobalAttribute ::=
7197 +** [c][f][m][p][u]:
7199 +** c : the content between start and end pattern is skipped
7200 +** during parsing (e.g. pattern encloses a comment).
7201 +** f : flash matching pattern (if not set, then only jump
7202 +** to matching pattern is supported).
7203 +** m : mono pattern - set exist out of only one single pattern
7204 +** (start pattern = end pattern; e.g. quotes like ")
7205 +** p : ignore highlight info code of single patterns of this set
7208 +** Returns TRUE, if global attribute was successful read.
7210 +static int getMPSGlobalAttribute(
7213 + int *isMonoPattern,
7216 + int *ignoreHighLightInfo)
7218 + char *field = ReadSymbolicField(inPtr);
7220 + int successful = True;
7222 + *isMonoPattern = False;
7225 + *ignoreHighLightInfo = False;
7227 + if (field != NULL)
7229 + attribute = field;
7230 + while (*attribute != '\0' && successful)
7232 + switch (*attribute)
7241 + *isMonoPattern = True;
7244 + *ignoreHighLightInfo = True;
7247 + *errMsg = "unknown global attribute";
7248 + successful = False;
7256 + if (!SkipDelimiter(inPtr, errMsg))
7258 + successful = False;
7262 + freeXtPtr((void **)&field);
7264 + return successful;
7268 +** Get matching pattern set attribute.
7272 +** patternAttribute ::=
7273 +** [s|m|e][w|l|r][i]:
7275 +** StringPatternKind:
7276 +** s : start string pattern.
7277 +** m : middle string pattern.
7278 +** e : end string pattern.
7279 +** WordBoundaryAttribute:
7280 +** w : pattern is word (i.e. before and after pattern
7281 +** there must be a delimiter).
7282 +** l : before pattern must be a delimiter (left side).
7283 +** r : after pattern must be a delimiter (right side).
7284 +** default: neither before nor after pattern must be a delimiter.
7285 +** StringAttribute:
7286 +** i : pattern is case insensitive (if not set: pattern is
7287 +** case sensitive).
7288 +** x : pattern is regular expression (if not set: pattern is
7289 +** literal string).
7291 +** Returns TRUE, if pattern attribute was successful read.
7293 +static int getMPSPatternAttribute(
7296 + PatternElementKind *patternKind,
7297 + PatternWordBoundary *wordBoundary,
7298 + int *caseInsensitive,
7299 + int *regularExpression)
7301 + char *field = ReadSymbolicField(inPtr);
7303 + int successful = True;
7305 + *patternKind = PEK_UNKNOWN;
7306 + *wordBoundary = PWB_NONE;
7307 + *caseInsensitive = False;
7308 + *regularExpression = False;
7310 + if (field != NULL)
7312 + attribute = field;
7313 + while (*attribute != '\0' && successful)
7315 + switch (*attribute)
7318 + *patternKind = PEK_END;
7321 + *caseInsensitive = True;
7324 + *wordBoundary = PWB_LEFT;
7327 + *patternKind = PEK_MIDDLE;
7330 + *wordBoundary = PWB_RIGHT;
7333 + *patternKind = PEK_START;
7336 + *wordBoundary = PWB_BOTH;
7339 + *regularExpression = True;
7342 + *errMsg = "unknown string pattern attribute";
7343 + successful = False;
7351 + if (!SkipDelimiter(inPtr, errMsg))
7353 + successful = False;
7357 + freeXtPtr((void **)&field);
7359 + return successful;
7363 +** Returns the (to be reserved) reg. ex. length of an pattern element.
7364 +** Update total number of multi patterns, too.
7366 +static int patternElementLen(
7367 + ReadMatchPatternInfo *info,
7368 + PatternElement *patElement,
7369 + int *nbrOfMultiPatterns)
7371 + PatternElement *referredElement;
7372 + StringPattern *strPat = NULL;
7373 + int patElementLen;
7375 + switch (patElement->peType)
7378 + strPat = &patElement->peVal.peuSingle;
7381 + case PET_MULTIPLE:
7382 + strPat = &patElement->peVal.peuMulti.mpStringPattern;
7384 + (*nbrOfMultiPatterns) ++;
7388 + case PET_REFERENCE:
7390 + info->rmpiElement[patElement->peVal.peuRef.prElementIdx]->
7391 + mpteAll.pesPattern[patElement->peVal.peuRef.prPatternIdx];
7393 + strPat = &referredElement->peVal.peuMulti.mpStringPattern;
7398 + * reserve additional 4 characters ("(?i)") for case insensitive search
7400 + if (strPat->spCaseInsensitive)
7401 + patElementLen = strPat->spLength + 4;
7403 + patElementLen = strPat->spLength;
7406 + * reserve additional 4 characters ("(?:)") for regular expression
7408 + if (strPat->spRegularExpression)
7409 + patElementLen += 4;
7411 + return patElementLen;
7415 +** Returns the (to be reserved) total reg. ex. length of given
7416 +** MatchPatternTableElement. Update total number of multi patterns, too.
7418 +static int totalMatchPatternTableElementLen(
7419 + ReadMatchPatternInfo *info,
7420 + MatchPatternTableElement *element,
7421 + int *nbrOfMultiPatterns)
7426 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
7429 + patternElementLen(
7431 + element->mpteAll.pesPattern[i],
7432 + nbrOfMultiPatterns );
7439 +** Returns the (to be reserved) total reg. ex. length of given
7440 +** read match pattern info. Counts total number of multi patterns, too.
7442 +static int totalKeywordOfTableLen(
7443 + ReadMatchPatternInfo *info,
7444 + int *nbrOfMultiPatterns)
7449 + *nbrOfMultiPatterns = 0;
7451 + for (i=0; i<info->rmpiNbrOfElements; i ++)
7454 + totalMatchPatternTableElementLen(
7456 + info->rmpiElement[i],
7457 + nbrOfMultiPatterns);
7464 +** Add given StringPattern to given reg. ex. strings
7466 +static void addPatternToRegExpString(
7467 + StringPattern *pattern,
7468 + RegExpStringInfo *regExpStringInfo)
7470 + char *r = NULL, *s;
7471 + char *adaptedRegExpText = NULL;
7475 + * Select the buffer, where the pattern needs to be added
7476 + * to (depending on its word boundary). Prepare the buffer
7477 + * by evtl. adding a prefix, if related buffer is empty.
7479 + switch (pattern->spWordBoundary)
7482 + prevLen = strlen( regExpStringInfo->resiNoneWBRegExpString );
7484 + r = regExpStringInfo->resiNoneWBRegExpString + strlen( regExpStringInfo->resiNoneWBRegExpString );
7487 + prevLen = strlen( regExpStringInfo->resiLeftWBRegExpString );
7490 + strcpy( regExpStringInfo->resiLeftWBRegExpString, "<(?:" );
7492 + r = regExpStringInfo->resiLeftWBRegExpString + strlen( regExpStringInfo->resiLeftWBRegExpString );
7495 + prevLen = strlen( regExpStringInfo->resiRightWBRegExpString );
7498 + strcpy( regExpStringInfo->resiRightWBRegExpString, "(?:" );
7500 + r = regExpStringInfo->resiRightWBRegExpString + strlen( regExpStringInfo->resiRightWBRegExpString );
7503 + prevLen = strlen( regExpStringInfo->resiBothWBRegExpString );
7506 + strcpy( regExpStringInfo->resiBothWBRegExpString, "<(?:" );
7508 + r = regExpStringInfo->resiBothWBRegExpString + strlen( regExpStringInfo->resiBothWBRegExpString );
7513 + * add an "or" if there is already a pattern in the buffer
7521 + * add "(?i" to order case insensitive search
7523 + if (pattern->spCaseInsensitive)
7531 + * add "(?:" to group this regular expression
7533 + if (pattern->spRegularExpression)
7539 + adaptedRegExpText =
7540 + adaptLocalBackRefs(
7542 + ®ExpStringInfo->resiLocalBackRefID);
7544 + s = adaptedRegExpText;
7548 + s = pattern->spText;
7552 + * add the pattern characters - evtl. escaped, if special
7553 + * regular expression symbols & pattern is no reg. exp. -
7557 + while (*s != '\0')
7559 + if (!pattern->spRegularExpression)
7590 + * close "reg. exp. group" bracket
7592 + if (pattern->spRegularExpression)
7596 + XtFree(adaptedRegExpText);
7600 + * close case insensitive search bracket
7602 + if (pattern->spCaseInsensitive)
7608 + * terminate added string
7614 +** Adapt local backrefs inside given regExpText by common local IDs.
7615 +** Returns new allocated reg. exp. string holding common local backrefs.
7617 +static char *adaptLocalBackRefs(
7619 + int *commonLocalId)
7622 + int ownLocalId = 0;
7623 + char *s = regExpText;
7624 + char *newRegExpText = XtMalloc(strlen(regExpText)*3);
7625 + char *n = newRegExpText;
7626 + int localBackRefList[MAX_LOCAL_BACK_REF_ID];
7629 + * put all local backrefs into "localBackRefList".
7631 + scanForLocalBackRefs(regExpText, localBackRefList);
7633 + while (*s != '\0')
7641 + if (isdigit((unsigned char)*s))
7644 + * \n (n=1..9) found: replace local backref.
7645 + * by "common local ID"
7648 + (int)((unsigned char)*s - (unsigned char)'0') - 1;
7650 + if (localBackRefList[id] != NO_LOCAL_BACK_REF_ID &&
7651 + localBackRefList[id] != LOCAL_BACK_REF_ID_USED)
7653 + *n++ = (char)((int)('0') + localBackRefList[id]);
7662 + else if (*s != '\0')
7665 + * copy escaped character
7670 + else if (*s == '(')
7677 + * non capturing parentheses found -> just copy it
7684 + * capturing parentheses found:
7686 + if (localBackRefList[ownLocalId] == LOCAL_BACK_REF_ID_USED)
7689 + * backref used within given reg. exp. text:
7690 + * remember common local id for replacement later on
7692 + localBackRefList[ownLocalId] = *commonLocalId;
7693 + (*commonLocalId) ++;
7699 + * backref not used within given reg. exp. text:
7700 + * replace capturing parentheses by non capturing one
7714 + * terminate adapted string
7718 + return newRegExpText;
7722 +** Get all local backrefs of given regExpText and put them into
7723 +** given localBackRefList.
7725 +static void scanForLocalBackRefs(
7727 + int *localBackRefList)
7731 + char *s = regExpText;
7733 + for (i=0; i<MAX_LOCAL_BACK_REF_ID; i++)
7735 + localBackRefList[i] = NO_LOCAL_BACK_REF_ID;
7738 + while (*s != '\0')
7742 + if (isdigit((unsigned char)*(s+1)))
7745 + * \n (n=1..9) found: flag usage in local backref list
7748 + (int)((unsigned char)*(s+1) - (unsigned char)'0') - 1;
7750 + localBackRefList[localId] = LOCAL_BACK_REF_ID_USED;
7754 + else if (*(s+1) != '\0')
7762 +** Returns true, if string of given multi pattern reference was
7763 +** not added to regExpStringInfo.
7765 +static int isMultiPatternNotAdded(
7766 + RegExpStringInfo *regExpStringInfo,
7767 + PatternReference *toBeAddedPR)
7770 + PatternReference *addedPR;
7771 + PatternReference *newPR;
7773 + for (i=0; i < regExpStringInfo->resiNbrOfAddedMultiPat; i++)
7775 + addedPR = regExpStringInfo->resiAddedMultiPat[i];
7777 + if (addedPR->prElementIdx == toBeAddedPR->prElementIdx &&
7778 + addedPR->prPatternIdx == toBeAddedPR->prPatternIdx)
7784 + newPR = (PatternReference *)XtMalloc(sizeof(PatternReference));
7786 + *newPR = *toBeAddedPR;
7788 + regExpStringInfo->resiAddedMultiPat[regExpStringInfo->resiNbrOfAddedMultiPat ++] = newPR;
7794 +** add given PatternElement to given reg. exp. strings
7796 +static void addUniquePatternToRegExpString(
7797 + PatternElement *patElement,
7798 + PatternReference *patElementReference,
7799 + ReadMatchPatternInfo *readMatchPatternInfo,
7800 + RegExpStringInfo *regExpStringInfo)
7802 + PatternElement *referredElement;
7803 + PatternReference referredPatReference;
7805 + switch (patElement->peType)
7808 + addPatternToRegExpString(
7809 + &(patElement->peVal.peuSingle),
7810 + regExpStringInfo);
7813 + case PET_MULTIPLE:
7815 + * add element to reg. exp. string only, if it was
7816 + * not added before.
7818 + if (isMultiPatternNotAdded(regExpStringInfo, patElementReference))
7820 + addPatternToRegExpString(
7821 + &(patElement->peVal.peuMulti.mpStringPattern),
7822 + regExpStringInfo);
7826 + case PET_REFERENCE:
7828 + * add referred element to reg. exp. string only, if related
7829 + * multi pattern was not added before.
7831 + referredPatReference = patElement->peVal.peuRef;
7834 + readMatchPatternInfo->rmpiElement[referredPatReference.prElementIdx]->
7835 + mpteAll.pesPattern[referredPatReference.prPatternIdx];
7837 + if (isMultiPatternNotAdded(regExpStringInfo, &referredPatReference))
7839 + addPatternToRegExpString(
7840 + &(referredElement->peVal.peuMulti.mpStringPattern),
7841 + regExpStringInfo);
7848 +** add given MatchPatternTableElement to given reg. ex. strings
7850 +static void addElementToRegExpString(
7851 + MatchPatternTableElement *element,
7852 + ReadMatchPatternInfo *readMatchPatternInfo,
7853 + RegExpStringInfo *regExpStringInfo)
7856 + PatternReference elementRef;
7858 + elementRef.prElementIdx = element->mpteIndex;
7860 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
7862 + elementRef.prPatternIdx = i;
7864 + addUniquePatternToRegExpString(
7865 + element->mpteAll.pesPattern[i],
7867 + readMatchPatternInfo,
7868 + regExpStringInfo);
7873 +** Concatenate strings stored by regExpStringInfo.
7874 +** Free given regExpStringInfo afterwards.
7875 +** Returns resulting string.
7877 +static void catSMTRegExpStrings(
7878 + RegExpStringInfo *regExpStringInfo,
7879 + char **regExpString)
7884 + * allocate & init. a buffer for the resulting regular expression
7887 + strlen( regExpStringInfo->resiNoneWBRegExpString ) +
7888 + strlen( regExpStringInfo->resiLeftWBRegExpString ) +
7889 + strlen( regExpStringInfo->resiRightWBRegExpString ) +
7890 + strlen( regExpStringInfo->resiBothWBRegExpString ) + 5;
7892 + *regExpString = XtMalloc( resultingLen );
7894 + strcpy( *regExpString, "" );
7897 + * add the single parts to the resulting regular expression
7898 + * (= cat of parts separated by an "or")
7900 + addSMTRegExpString( *regExpString, regExpStringInfo->resiNoneWBRegExpString, "" );
7901 + addSMTRegExpString( *regExpString, regExpStringInfo->resiLeftWBRegExpString, ")" );
7902 + addSMTRegExpString( *regExpString, regExpStringInfo->resiRightWBRegExpString, ")>" );
7903 + addSMTRegExpString( *regExpString, regExpStringInfo->resiBothWBRegExpString, ")>" );
7908 + freeRegExpStringInfo( regExpStringInfo );
7912 +** Free the allocated memory contained in a RegExpStringInfo data structure
7914 +static void freeRegExpStringInfo(
7915 + RegExpStringInfo *regExpStringInfo)
7919 + XtFree( regExpStringInfo->resiNoneWBRegExpString );
7920 + XtFree( regExpStringInfo->resiLeftWBRegExpString );
7921 + XtFree( regExpStringInfo->resiRightWBRegExpString );
7922 + XtFree( regExpStringInfo->resiBothWBRegExpString );
7924 + for (i=0; i < regExpStringInfo->resiNbrOfAddedMultiPat; i ++)
7925 + XtFree( (char *)regExpStringInfo->resiAddedMultiPat[i] );
7927 + XtFree( (char *)regExpStringInfo->resiAddedMultiPat);
7931 +** Compose regular expression for start / end pattern.
7933 +static void composeStartEndRegExpString(
7934 + ReadMatchPatternInfo *readMatchPatternInfo,
7935 + MatchPatternTableElement *element,
7936 + char **regExpString)
7939 + RegExpStringInfo regExpStringInfo;
7940 + PatternReference elementRef;
7941 + PatternElementSet startPat = element->mpteStart;
7942 + PatternElementSet endPat = element->mpteEnd;
7945 + * Allocate buffers for keyword regular expression.
7947 + setupRegExpStringBuffers(
7948 + readMatchPatternInfo,
7949 + ®ExpStringInfo);
7952 + * Treat start / end element of MatchPatternTableElement
7955 + elementRef.prElementIdx = element->mpteIndex;
7957 + for (i=0; i < startPat.pesNumberOfPattern; i ++)
7959 + elementRef.prPatternIdx = startPat.pesPattern[i]->peIndex;
7961 + addUniquePatternToRegExpString(
7962 + startPat.pesPattern[i],
7964 + readMatchPatternInfo,
7965 + ®ExpStringInfo);
7968 + for (i=0; i < endPat.pesNumberOfPattern; i ++)
7970 + elementRef.prPatternIdx = endPat.pesPattern[i]->peIndex;
7972 + addUniquePatternToRegExpString(
7973 + endPat.pesPattern[i],
7975 + readMatchPatternInfo,
7976 + ®ExpStringInfo);
7980 + * Assemble the resulting regular expression
7982 + catSMTRegExpStrings(
7983 + ®ExpStringInfo,
7987 +static void copyStringMatchTableForDialog(
7988 + StringMatchTable *sourceTable,
7989 + DialogMatchPatternInfo *dialogTable )
7994 + * if no source table exist (yet), then set nbr. of elements / groups to 0
7996 + if (sourceTable == NULL)
7998 + dialogTable->dmpiNbrOfSeqElements = 0;
8004 + * copy matching pattern sequence
8006 + dialogTable->dmpiNbrOfSeqElements = sourceTable->smtNumberOfSeqElements;
8008 + for (i=0; i < sourceTable->smtNumberOfSeqElements; i ++)
8010 + copySequenceElementForDialog(
8012 + sourceTable->smtSequence[i],
8013 + &dialogTable->dmpiSequence[i] );
8017 +static void *copyMatchPatternElementForDialog(
8018 + MatchPatternTable *table,
8019 + int sourceElementIdx)
8023 + MatchPatternTableElement *sourceElement;
8024 + DialogMatchPatternTableElement *destination;
8026 + sourceElement = table->mptElements[sourceElementIdx];
8029 + (DialogMatchPatternTableElement *)XtMalloc( sizeof(DialogMatchPatternTableElement) );
8031 + destination->dmpteName = XtNewString(sourceElement->mpteName);
8032 + destination->dmpteType = sourceElement->mpteType;
8033 + destination->dmpteSkipBtwnStartEnd = sourceElement->mpteSkipBtwnStartEnd;
8034 + destination->dmpteIgnoreHighLightInfo = sourceElement->mpteIgnoreHighLightInfo;
8035 + destination->dmpteFlash = sourceElement->mpteFlash;
8037 + for (i=0; i<sourceElement->mpteAll.pesNumberOfPattern; i++)
8039 + copyPatternForDialog(
8041 + sourceElement->mpteAll.pesPattern[i],
8042 + &destination->dmptePatterns.dspElements[patIdx ++]);
8045 + destination->dmptePatterns.dspNumberOfPatterns = patIdx;
8047 + return (void *)destination;
8050 +static void copyPatternForDialog(
8051 + MatchPatternTable *table,
8052 + PatternElement *sourcePattern,
8053 + DialogStringPatternElement **dialogPattern )
8055 + DialogStringPatternElement *newPat;
8056 + StringPattern *strSourcePat = GetStringPattern( table, sourcePattern );
8058 + newPat = (DialogStringPatternElement *)XtMalloc(sizeof(DialogStringPatternElement));
8059 + *dialogPattern = newPat;
8061 + if( strSourcePat->spOrigText != NULL)
8062 + newPat->dspeText = XtNewString(strSourcePat->spOrigText);
8064 + newPat->dspeText = XtNewString(strSourcePat->spText);
8066 + newPat->dspeKind = sourcePattern->peKind;
8067 + newPat->dspeWordBoundary = strSourcePat->spWordBoundary;
8068 + newPat->dspeCaseInsensitive = strSourcePat->spCaseInsensitive;
8069 + newPat->dspeRegularExpression = strSourcePat->spRegularExpression;
8072 +static void *copyGroupElementForDialog(
8073 + MatchPatternGroupElement *sourceGroup)
8076 + DialogMatchPatternGroupElement *destination;
8079 + (DialogMatchPatternGroupElement *)XtMalloc( sizeof(DialogMatchPatternGroupElement) );
8081 + destination->dmpgeName = XtNewString(sourceGroup->mpgeName);
8082 + destination->dmpgeNumberOfSubPatterns = sourceGroup->mpgeNumberOfSubPatterns;
8084 + for ( i=0; i<destination->dmpgeNumberOfSubPatterns; i ++)
8086 + destination->dmpgeSubPatternIds[i] =
8087 + XtNewString(sourceGroup->mpgeSubPatternIds[i]);
8090 + return destination;
8093 +static void copySequenceElementForDialog(
8094 + StringMatchTable *sourceTable,
8095 + MatchPatternSequenceElement *sourceSeqElement,
8096 + DialogMatchPatternSequenceElement **dialogSeqElement )
8098 + DialogMatchPatternSequenceElement *destSeqElement;
8101 + (DialogMatchPatternSequenceElement *)XtMalloc( sizeof(DialogMatchPatternSequenceElement) );
8103 + *dialogSeqElement = destSeqElement;
8105 + destSeqElement->dmpseName = XtNewString(sourceSeqElement->mpseName);
8106 + destSeqElement->dmpseType = sourceSeqElement->mpseType;
8107 + destSeqElement->dmpseValid = True;
8109 + if (destSeqElement->dmpseType == MPT_GROUP)
8111 + destSeqElement->dmpsePtr =
8112 + copyGroupElementForDialog(
8113 + sourceTable->smtGroups[sourceSeqElement->mpseIndex]);
8117 + destSeqElement->dmpsePtr =
8118 + copyMatchPatternElementForDialog(
8119 + sourceTable->smtAllPatterns,
8120 + sourceSeqElement->mpseIndex);
8124 +static DialogMatchPatternSequenceElement *copyDialogSequenceElement(
8125 + DialogMatchPatternSequenceElement *sourceSeq)
8127 + DialogMatchPatternSequenceElement *destSeq;
8130 + (DialogMatchPatternSequenceElement *)XtMalloc(sizeof(DialogMatchPatternSequenceElement));
8132 + destSeq->dmpseName = XtNewString(sourceSeq->dmpseName);
8133 + destSeq->dmpseType = sourceSeq->dmpseType;
8134 + destSeq->dmpseValid = True;
8136 + destSeq->dmpsePtr = sourceSeq->dmpsePtr;
8141 +static void freeDialogMatchPatternElement(
8142 + DialogMatchPatternTableElement *dialogElement )
8146 + for (i=0; i<dialogElement->dmptePatterns.dspNumberOfPatterns; i ++)
8148 + freeDialogStringPatternElement(
8149 + dialogElement->dmptePatterns.dspElements[i]);
8152 + freeXtPtr((void **)&dialogElement->dmpteName);
8154 + freeXtPtr((void **)&dialogElement);
8157 +static void freeDialogStringPatternElement(
8158 + DialogStringPatternElement *element)
8160 + freeXtPtr((void **)&element->dspeText);
8162 + freeXtPtr((void **)&element);
8165 +static void freeDialogGroupElement(
8166 + DialogMatchPatternGroupElement *dialogGroup )
8170 + for (i=0; i<dialogGroup->dmpgeNumberOfSubPatterns; i ++)
8172 + freeXtPtr((void **)&dialogGroup->dmpgeSubPatternIds[i]);
8175 + freeXtPtr((void **)&dialogGroup->dmpgeName);
8177 + freeXtPtr((void **)&dialogGroup);
8180 +static void freeDialogSequenceElement(
8181 + DialogMatchPatternSequenceElement *dialogSeq )
8183 + freeXtPtr((void **)&dialogSeq->dmpseName);
8185 + if (dialogSeq->dmpseType == MPT_GROUP)
8187 + freeDialogGroupElement(
8188 + (DialogMatchPatternGroupElement *)dialogSeq->dmpsePtr );
8192 + freeDialogMatchPatternElement(
8193 + (DialogMatchPatternTableElement *)dialogSeq->dmpsePtr );
8196 + freeXtPtr((void **)&dialogSeq);
8199 +static void copyDialogStringPatternsFromTable(
8200 + DialogMatchPatternTableElement *tableElement,
8201 + DialogStringPatterns *destPatterns)
8205 + destPatterns->dspNumberOfPatterns =
8206 + tableElement->dmptePatterns.dspNumberOfPatterns;
8208 + for (i=0; i<destPatterns->dspNumberOfPatterns; i++)
8210 + destPatterns->dspElements[i] =
8211 + copyDialogStringPatternElement(
8212 + tableElement->dmptePatterns.dspElements[i] );
8216 +static void copyDialogStringPatterns(
8217 + DialogStringPatterns *sourcePatterns,
8218 + DialogStringPatterns *destPatterns)
8222 + destPatterns->dspNumberOfPatterns =
8223 + sourcePatterns->dspNumberOfPatterns;
8225 + for (i=0; i<destPatterns->dspNumberOfPatterns; i++)
8227 + destPatterns->dspElements[i] =
8228 + copyDialogStringPatternElement(
8229 + sourcePatterns->dspElements[i] );
8233 +static void freeDialogStringPatterns(
8234 + DialogStringPatterns *patterns)
8238 + for (i=0; i<patterns->dspNumberOfPatterns; i++)
8240 + freeDialogStringPatternElement(patterns->dspElements[i]);
8243 + patterns->dspNumberOfPatterns = 0;
8246 +static DialogStringPatternElement *copyDialogStringPatternElement(
8247 + DialogStringPatternElement *sourceElement)
8249 + DialogStringPatternElement *newPatElement;
8251 + newPatElement = (DialogStringPatternElement *)XtMalloc(sizeof(DialogStringPatternElement));
8253 + newPatElement->dspeText = XtNewString(sourceElement->dspeText);
8254 + newPatElement->dspeKind = sourceElement->dspeKind;
8255 + newPatElement->dspeWordBoundary = sourceElement->dspeWordBoundary;
8256 + newPatElement->dspeCaseInsensitive = sourceElement->dspeCaseInsensitive;
8257 + newPatElement->dspeRegularExpression = sourceElement->dspeRegularExpression;
8259 + return newPatElement;
8262 +static void copyDialogPatternNamesFromGroup(
8263 + DialogMatchPatternGroupElement *group,
8264 + DialogStringPatterns *destPatterns)
8268 + destPatterns->dspNumberOfPatterns =
8269 + group->dmpgeNumberOfSubPatterns;
8271 + for (i=0; i<destPatterns->dspNumberOfPatterns; i++)
8273 + destPatterns->dspElements[i] =
8274 + copyDialogPatternName(
8275 + group->dmpgeSubPatternIds[i] );
8279 +static DialogStringPatternElement *copyDialogPatternName(
8280 + char *sourcePatternId)
8282 + DialogStringPatternElement *newPatElement;
8284 + newPatElement = (DialogStringPatternElement *)XtMalloc(sizeof(DialogStringPatternElement));
8286 + newPatElement->dspeText = XtNewString(sourcePatternId);
8287 + newPatElement->dspeKind = PEK_START;
8288 + newPatElement->dspeWordBoundary = PWB_NONE;
8289 + newPatElement->dspeCaseInsensitive = False;
8290 + newPatElement->dspeRegularExpression = False;
8292 + return newPatElement;
8295 +static void copyDialogPatternNamesToGroup(
8296 + DialogStringPatterns *sourceNames,
8297 + DialogMatchPatternGroupElement *destGroup)
8301 + destGroup->dmpgeNumberOfSubPatterns =
8302 + sourceNames->dspNumberOfPatterns;
8304 + for (i=0; i<destGroup->dmpgeNumberOfSubPatterns; i++)
8306 + destGroup->dmpgeSubPatternIds[i] =
8308 + sourceNames->dspElements[i]->dspeText);
8314 +** Present a dialog for editing matching pattern information
8316 +void EditMatchPatterns(WindowInfo *window)
8318 + Widget form, lmOptMenu;
8320 + Widget okBtn, applyBtn, checkBtn, deleteBtn, closeBtn, helpBtn;
8321 + Widget restoreBtn, lmBtn;
8322 + Widget matchPatternsForm, matchPatternsFrame, matchPatternsLbl;
8323 + Widget matchPatternTypeBox, matchPatternTypeLbl;
8324 + Widget globalAttributesBox;
8325 + Widget stringPatternsFrame, stringPatternsForm;
8326 + Widget stringPatternTypeBox;
8327 + Widget wordBoundaryBox;
8328 + Widget stringAttributesBox;
8329 + StringMatchTable *table;
8335 + * if the dialog is already displayed, just pop it to the top and return
8337 + if (MatchPatternDialog.mpdShell != NULL)
8339 + RaiseDialogWindow(MatchPatternDialog.mpdShell);
8344 + * decide on an initial language mode
8346 + MatchPatternDialog.mpdLangModeName =
8348 + window->languageMode == PLAIN_LANGUAGE_MODE ?
8349 + PLAIN_LM_STRING : LanguageModeName(window->languageMode));
8352 + * find the associated matching pattern table to edit
8354 + table = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
8357 + * copy the list of patterns to one that the user can freely edit
8359 + copyStringMatchTableForDialog( table, &MatchPatternDialog.mpdTable );
8362 + * init. status information of dialog
8364 + MatchPatternDialog.currentDmptSeqElement = NULL;
8365 + MatchPatternDialog.currentDmptElement = NULL;
8366 + MatchPatternDialog.currentDmptGroup = NULL;
8368 + MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns = 0;
8369 + MatchPatternDialog.mpdStringPatternIsDisplayed = True;
8372 + * Create a form widget in an application shell
8375 + XtSetArg(args[n], XmNdeleteResponse, XmDO_NOTHING); n++;
8376 + XtSetArg(args[n], XmNiconName, "Matching Patterns"); n++;
8377 + XtSetArg(args[n], XmNtitle, "Matching (Parenthesis) Patterns"); n++;
8378 + MatchPatternDialog.mpdShell = CreateShellWithBestVis(APP_NAME, APP_CLASS,
8379 + applicationShellWidgetClass, TheDisplay, args, n);
8380 + AddSmallIcon(MatchPatternDialog.mpdShell);
8381 + form = XtVaCreateManagedWidget("editMatchPatterns", xmFormWidgetClass,
8382 + MatchPatternDialog.mpdShell, XmNautoUnmanage, False,
8383 + XmNresizePolicy, XmRESIZE_NONE, NULL);
8384 + XtAddCallback(form, XmNdestroyCallback, destroyCB, NULL);
8385 + AddMotifCloseCallback(MatchPatternDialog.mpdShell, closeCB, NULL);
8387 + lmForm = XtVaCreateManagedWidget("lmForm", xmFormWidgetClass,
8389 + XmNleftAttachment, XmATTACH_POSITION,
8390 + XmNleftPosition, 1,
8391 + XmNtopAttachment, XmATTACH_POSITION,
8392 + XmNtopPosition, 1,
8393 + XmNrightAttachment, XmATTACH_POSITION,
8394 + XmNrightPosition, 99, NULL);
8396 + MatchPatternDialog.mpdLmPulldown =
8397 + CreateLanguageModeMenu(lmForm, matchPatternLangModeCB, NULL, True);
8400 + XtSetArg(args[n], XmNspacing, 0); n++;
8401 + XtSetArg(args[n], XmNmarginWidth, 0); n++;
8402 + XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
8403 + XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
8404 + XtSetArg(args[n], XmNleftPosition, 50); n++;
8405 + XtSetArg(args[n], XmNsubMenuId, MatchPatternDialog.mpdLmPulldown); n++;
8406 + lmOptMenu = XmCreateOptionMenu(lmForm, "langModeOptMenu", args, n);
8407 + XtManageChild(lmOptMenu);
8408 + MatchPatternDialog.mpdLmOptMenu = lmOptMenu;
8410 + XtVaCreateManagedWidget("lmLbl", xmLabelGadgetClass, lmForm,
8411 + XmNlabelString, s1=XmStringCreateSimple("Language Mode:"),
8413 + XmNuserData, XtParent(MatchPatternDialog.mpdLmOptMenu),
8414 + XmNalignment, XmALIGNMENT_END,
8415 + XmNrightAttachment, XmATTACH_POSITION,
8416 + XmNrightPosition, 50,
8417 + XmNtopAttachment, XmATTACH_FORM,
8418 + XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
8419 + XmNbottomWidget, lmOptMenu, NULL);
8422 + lmBtn = XtVaCreateManagedWidget("lmBtn", xmPushButtonWidgetClass, lmForm,
8423 + XmNlabelString, s1=MKSTRING("Add / Modify\nLanguage Mode..."),
8425 + XmNrightAttachment, XmATTACH_FORM,
8426 + XmNtopAttachment, XmATTACH_FORM, NULL);
8427 + XtAddCallback(lmBtn, XmNactivateCallback, pmLanguageModeDialogCB, NULL);
8430 + okBtn = XtVaCreateManagedWidget("ok", xmPushButtonWidgetClass, form,
8431 + XmNlabelString, s1=XmStringCreateSimple("OK"),
8432 + XmNleftAttachment, XmATTACH_POSITION,
8433 + XmNleftPosition, 1,
8434 + XmNrightAttachment, XmATTACH_POSITION,
8435 + XmNrightPosition, 13,
8436 + XmNbottomAttachment, XmATTACH_FORM,
8437 + XmNbottomOffset, BORDER, NULL);
8438 + XtAddCallback(okBtn, XmNactivateCallback, okCB, NULL);
8441 + applyBtn = XtVaCreateManagedWidget("apply", xmPushButtonWidgetClass, form,
8442 + XmNlabelString, s1=XmStringCreateSimple("Apply"),
8444 + XmNleftAttachment, XmATTACH_POSITION,
8445 + XmNleftPosition, 13,
8446 + XmNrightAttachment, XmATTACH_POSITION,
8447 + XmNrightPosition, 26,
8448 + XmNbottomAttachment, XmATTACH_FORM,
8449 + XmNbottomOffset, BORDER, NULL);
8450 + XtAddCallback(applyBtn, XmNactivateCallback, applyCB, NULL);
8453 + checkBtn = XtVaCreateManagedWidget("check", xmPushButtonWidgetClass, form,
8454 + XmNlabelString, s1=XmStringCreateSimple("Check"),
8456 + XmNleftAttachment, XmATTACH_POSITION,
8457 + XmNleftPosition, 26,
8458 + XmNrightAttachment, XmATTACH_POSITION,
8459 + XmNrightPosition, 39,
8460 + XmNbottomAttachment, XmATTACH_FORM,
8461 + XmNbottomOffset, BORDER, NULL);
8462 + XtAddCallback(checkBtn, XmNactivateCallback, checkCB, NULL);
8465 + deleteBtn = XtVaCreateManagedWidget("delete", xmPushButtonWidgetClass, form,
8466 + XmNlabelString, s1=XmStringCreateSimple("Delete"),
8468 + XmNleftAttachment, XmATTACH_POSITION,
8469 + XmNleftPosition, 39,
8470 + XmNrightAttachment, XmATTACH_POSITION,
8471 + XmNrightPosition, 52,
8472 + XmNbottomAttachment, XmATTACH_FORM,
8473 + XmNbottomOffset, BORDER, NULL);
8474 + XtAddCallback(deleteBtn, XmNactivateCallback, deleteCB, NULL);
8477 + restoreBtn = XtVaCreateManagedWidget("restore", xmPushButtonWidgetClass, form,
8478 + XmNlabelString, s1=XmStringCreateSimple("Restore Defaults"),
8480 + XmNleftAttachment, XmATTACH_POSITION,
8481 + XmNleftPosition, 52,
8482 + XmNrightAttachment, XmATTACH_POSITION,
8483 + XmNrightPosition, 73,
8484 + XmNbottomAttachment, XmATTACH_FORM,
8485 + XmNbottomOffset, BORDER, NULL);
8486 + XtAddCallback(restoreBtn, XmNactivateCallback, restoreCB, NULL);
8489 + closeBtn = XtVaCreateManagedWidget("close", xmPushButtonWidgetClass,
8491 + XmNlabelString, s1=XmStringCreateSimple("Close"),
8492 + XmNleftAttachment, XmATTACH_POSITION,
8493 + XmNleftPosition, 73,
8494 + XmNrightAttachment, XmATTACH_POSITION,
8495 + XmNrightPosition, 86,
8496 + XmNbottomAttachment, XmATTACH_FORM,
8497 + XmNbottomOffset, BORDER, NULL);
8498 + XtAddCallback(closeBtn, XmNactivateCallback, closeCB, NULL);
8501 + helpBtn = XtVaCreateManagedWidget("help", xmPushButtonWidgetClass,
8503 + XmNlabelString, s1=XmStringCreateSimple("Help"),
8505 + XmNleftAttachment, XmATTACH_POSITION,
8506 + XmNleftPosition, 86,
8507 + XmNrightAttachment, XmATTACH_POSITION,
8508 + XmNrightPosition, 99,
8509 + XmNbottomAttachment, XmATTACH_FORM,
8510 + XmNbottomOffset, BORDER, NULL);
8511 + XtAddCallback(helpBtn, XmNactivateCallback, helpCB, NULL);
8514 + stringPatternsFrame = XtVaCreateManagedWidget("stringPatternsFrame", xmFrameWidgetClass,
8516 + XmNleftAttachment, XmATTACH_POSITION,
8517 + XmNleftPosition, 1,
8518 + XmNrightAttachment, XmATTACH_POSITION,
8519 + XmNrightPosition, 99,
8520 + XmNbottomAttachment, XmATTACH_WIDGET,
8521 + XmNbottomWidget, okBtn,
8522 + XmNbottomOffset, BORDER, NULL);
8523 + stringPatternsForm = XtVaCreateManagedWidget("stringPatternsForm", xmFormWidgetClass,
8524 + stringPatternsFrame, NULL);
8525 + MatchPatternDialog.mpdStringPatternsLbl = XtVaCreateManagedWidget("mpdStringPatternsLbl", xmLabelGadgetClass,
8526 + stringPatternsFrame,
8527 + XmNlabelString, s1=XmStringCreateSimple(STRING_PATTERNS_LBL_TXT),
8528 + XmNmarginHeight, 0,
8529 + XmNchildType, XmFRAME_TITLE_CHILD, NULL);
8533 + XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
8534 + XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
8535 + XtSetArg(args[n], XmNleftPosition, 1); n++;
8536 + XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
8537 + XtSetArg(args[n], XmNrightPosition, LIST_RIGHT-1); n++;
8538 + XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
8539 + XtSetArg(args[n], XmNbottomOffset, BORDER); n++;
8540 + MatchPatternDialog.mpdStringPatternsListW =
8541 + CreateManagedList(stringPatternsForm, "stringPatternsList", args,
8542 + n, (void **)MatchPatternDialog.currentStringPatterns.dspElements,
8543 + &MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns,
8544 + MAX_STRING_PATTERNS, 18,
8545 + getStringPatternDisplayedCB, NULL,
8546 + setStringPatternDisplayedCB, NULL,
8547 + freeStringPatternItemCB);
8548 + XtVaSetValues(MatchPatternDialog.mpdStringPatternsLbl, XmNuserData, MatchPatternDialog.mpdStringPatternsListW, NULL);
8550 + MatchPatternDialog.mpdStringPatternTypeLbl = XtVaCreateManagedWidget("mpdStringPatternTypeLbl", xmLabelGadgetClass,
8551 + stringPatternsForm,
8552 + XmNlabelString, s1=XmStringCreateSimple("String Pattern Type:"),
8553 + XmNmarginHeight, 0,
8554 + XmNalignment, XmALIGNMENT_BEGINNING,
8555 + XmNleftAttachment, XmATTACH_POSITION,
8556 + XmNleftPosition, LIST_RIGHT,
8557 + XmNtopAttachment, XmATTACH_FORM, NULL);
8560 + stringPatternTypeBox = XtVaCreateManagedWidget("stringPatternTypeBox", xmRowColumnWidgetClass,
8561 + stringPatternsForm,
8562 + XmNorientation, XmHORIZONTAL,
8563 + XmNpacking, XmPACK_TIGHT,
8564 + XmNradioBehavior, True,
8565 + XmNleftAttachment, XmATTACH_POSITION,
8566 + XmNleftPosition, LIST_RIGHT,
8567 + XmNtopAttachment, XmATTACH_WIDGET,
8568 + XmNtopWidget, MatchPatternDialog.mpdStringPatternTypeLbl, NULL);
8569 + MatchPatternDialog.sptStartW = XtVaCreateManagedWidget("sptStartW",
8570 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8572 + XmNmarginHeight, 0,
8573 + XmNlabelString, s1=XmStringCreateSimple(
8577 + MatchPatternDialog.sptMiddleW = XtVaCreateManagedWidget("sptMiddleW",
8578 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8579 + XmNmarginHeight, 0,
8580 + XmNlabelString, s1=XmStringCreateSimple(
8584 + MatchPatternDialog.sptEndW = XtVaCreateManagedWidget("sptEndW",
8585 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8586 + XmNmarginHeight, 0,
8587 + XmNlabelString, s1=XmStringCreateSimple(
8592 + MatchPatternDialog.mpdWordBoundaryLbl = XtVaCreateManagedWidget("mpdWordBoundaryLbl", xmLabelGadgetClass,
8593 + stringPatternsForm,
8594 + XmNlabelString, s1=XmStringCreateSimple("Word boundary:"),
8595 + XmNmarginHeight, 0,
8596 + XmNalignment, XmALIGNMENT_BEGINNING,
8597 + XmNleftAttachment, XmATTACH_POSITION,
8598 + XmNleftPosition, LIST_RIGHT,
8599 + XmNtopAttachment, XmATTACH_WIDGET,
8600 + XmNtopWidget, stringPatternTypeBox,
8604 + wordBoundaryBox = XtVaCreateManagedWidget("wordBoundaryBox", xmRowColumnWidgetClass,
8605 + stringPatternsForm,
8606 + XmNorientation, XmHORIZONTAL,
8607 + XmNpacking, XmPACK_TIGHT,
8608 + XmNradioBehavior, True,
8609 + XmNleftAttachment, XmATTACH_POSITION,
8610 + XmNleftPosition, LIST_RIGHT,
8611 + XmNtopAttachment, XmATTACH_WIDGET,
8612 + XmNtopWidget, MatchPatternDialog.mpdWordBoundaryLbl, NULL);
8613 + MatchPatternDialog.wbbBothW = XtVaCreateManagedWidget("wbbBothW",
8614 + xmToggleButtonWidgetClass, wordBoundaryBox,
8616 + XmNmarginHeight, 0,
8617 + XmNlabelString, s1=XmStringCreateSimple(
8618 + "Both (pattern is word)"),
8621 + MatchPatternDialog.wbbLeftW = XtVaCreateManagedWidget("wbbLeftW",
8622 + xmToggleButtonWidgetClass, wordBoundaryBox,
8623 + XmNmarginHeight, 0,
8624 + XmNlabelString, s1=XmStringCreateSimple(
8628 + MatchPatternDialog.wbbRightW = XtVaCreateManagedWidget("wbbRightW",
8629 + xmToggleButtonWidgetClass, wordBoundaryBox,
8630 + XmNmarginHeight, 0,
8631 + XmNlabelString, s1=XmStringCreateSimple(
8635 + MatchPatternDialog.wbbNoneW = XtVaCreateManagedWidget("wbbNoneW",
8636 + xmToggleButtonWidgetClass, wordBoundaryBox,
8637 + XmNmarginHeight, 0,
8638 + XmNlabelString, s1=XmStringCreateSimple(
8643 + MatchPatternDialog.mpdStringAttributesLbl = XtVaCreateManagedWidget("mpdStringAttributesLbl", xmLabelGadgetClass,
8644 + stringPatternsForm,
8645 + XmNlabelString, s1=XmStringCreateSimple("String Attributes:"),
8646 + XmNmarginHeight, 0,
8647 + XmNalignment, XmALIGNMENT_BEGINNING,
8648 + XmNleftAttachment, XmATTACH_POSITION,
8649 + XmNleftPosition, LIST_RIGHT,
8650 + XmNtopAttachment, XmATTACH_WIDGET,
8651 + XmNtopWidget, wordBoundaryBox, NULL);
8654 + stringAttributesBox = XtVaCreateManagedWidget("stringAttributesBox", xmRowColumnWidgetClass,
8655 + stringPatternsForm,
8656 + XmNorientation, XmHORIZONTAL,
8657 + XmNpacking, XmPACK_TIGHT,
8658 + XmNleftAttachment, XmATTACH_POSITION,
8659 + XmNleftPosition, LIST_RIGHT,
8660 + XmNtopAttachment, XmATTACH_WIDGET,
8661 + XmNtopWidget, MatchPatternDialog.mpdStringAttributesLbl, NULL);
8662 + MatchPatternDialog.sabRegularExpressionW = XtVaCreateManagedWidget("sabRegularExpressionW",
8663 + xmToggleButtonWidgetClass, stringAttributesBox,
8665 + XmNmarginHeight, 0,
8666 + XmNlabelString, s1=XmStringCreateSimple(
8667 + "Regular Expression"),
8670 + XtAddCallback(MatchPatternDialog.sabRegularExpressionW, XmNvalueChangedCallback,
8671 + strPatRegExpressionCB, NULL);
8672 + MatchPatternDialog.sabCaseSensitiveW = XtVaCreateManagedWidget("sabCaseSensitiveW",
8673 + xmToggleButtonWidgetClass, stringAttributesBox,
8675 + XmNmarginHeight, 0,
8676 + XmNlabelString, s1=XmStringCreateSimple(
8677 + "Case Sensitive"),
8681 + MatchPatternDialog.mpdStringPatternLbl = XtVaCreateManagedWidget("mpdStringPatternLbl", xmLabelGadgetClass,
8682 + stringPatternsForm,
8683 + XmNlabelString, s1=XmStringCreateSimple("String Pattern"),
8685 + XmNalignment, XmALIGNMENT_BEGINNING,
8686 + XmNleftAttachment, XmATTACH_POSITION,
8687 + XmNleftPosition, LIST_RIGHT,
8688 + XmNtopAttachment, XmATTACH_WIDGET,
8689 + XmNtopWidget, stringAttributesBox,
8690 + XmNtopOffset, BORDER,
8694 + MatchPatternDialog.mpdStringPatternW = XtVaCreateManagedWidget("mpdStringPatternW", xmTextWidgetClass,
8695 + stringPatternsForm,
8696 + XmNleftAttachment, XmATTACH_POSITION,
8697 + XmNleftPosition, LIST_RIGHT,
8698 + XmNtopAttachment, XmATTACH_WIDGET,
8699 + XmNtopWidget, MatchPatternDialog.mpdStringPatternLbl,
8700 + XmNrightAttachment, XmATTACH_FORM,
8701 + XmNrightOffset, BORDER,
8703 + RemapDeleteKey(MatchPatternDialog.mpdStringPatternW);
8704 + XtVaSetValues(MatchPatternDialog.mpdStringPatternLbl, XmNuserData, MatchPatternDialog.mpdStringPatternW, NULL);
8706 + MatchPatternDialog.mpdSubPatNamesLbl = XtVaCreateManagedWidget("mpdSubPatNamesLbl", xmLabelGadgetClass,
8707 + stringPatternsForm,
8708 + XmNlabelString, s1=XmStringCreateSimple("Sub-Pattern Name"),
8710 + XmNalignment, XmALIGNMENT_BEGINNING,
8711 + XmNleftAttachment, XmATTACH_POSITION,
8712 + XmNleftPosition, LIST_RIGHT,
8713 + XmNtopAttachment, XmATTACH_WIDGET,
8714 + XmNtopWidget, MatchPatternDialog.mpdStringPatternW,
8715 + XmNtopOffset, BORDER,
8719 + MatchPatternDialog.mpdSubPatNamesPulldown =
8720 + createSubPatternNameMenu(stringPatternsForm, NULL, False);
8723 + XtSetArg(args[n], XmNspacing, 0); n++;
8724 + XtSetArg(args[n], XmNmarginWidth, 0); n++;
8725 + XtSetArg(args[n], XmNresizeWidth, True); n++;
8726 + XtSetArg(args[n], XmNresizeHeight, True); n++;
8727 + XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;
8728 + XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
8729 + XtSetArg(args[n], XmNtopWidget, MatchPatternDialog.mpdSubPatNamesLbl); n++;
8730 + XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
8731 + XtSetArg(args[n], XmNleftPosition, LIST_RIGHT); n++;
8732 + XtSetArg(args[n], XmNsubMenuId, MatchPatternDialog.mpdSubPatNamesPulldown); n++;
8733 + MatchPatternDialog.mpdSubPatNamesOptMenu =
8734 + XmCreateOptionMenu(stringPatternsForm, "subPatNamesOptMenu", args, n);
8735 + XtManageChild(MatchPatternDialog.mpdSubPatNamesOptMenu);
8738 + MatchPatternDialog.mpdSubPatNamesLbl,
8739 + XmNuserData, XtParent(MatchPatternDialog.mpdSubPatNamesOptMenu),
8742 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesLbl, False);
8743 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesOptMenu, False);
8745 + matchPatternsFrame = XtVaCreateManagedWidget("matchPatternsFrame", xmFrameWidgetClass,
8747 + XmNleftAttachment, XmATTACH_POSITION,
8748 + XmNleftPosition, 1,
8749 + XmNtopAttachment, XmATTACH_WIDGET,
8750 + XmNtopWidget, lmForm,
8751 + XmNrightAttachment, XmATTACH_POSITION,
8752 + XmNrightPosition, 99,
8753 + XmNbottomAttachment, XmATTACH_WIDGET,
8754 + XmNbottomWidget, stringPatternsFrame,
8755 + XmNbottomOffset, BORDER, NULL);
8756 + matchPatternsForm = XtVaCreateManagedWidget("matchPatternsForm", xmFormWidgetClass,
8757 + matchPatternsFrame, NULL);
8758 + matchPatternsLbl = XtVaCreateManagedWidget("matchPatternsLbl", xmLabelGadgetClass,
8759 + matchPatternsFrame,
8760 + XmNlabelString, s1=XmStringCreateSimple("Matching Patterns"),
8762 + XmNmarginHeight, 0,
8763 + XmNchildType, XmFRAME_TITLE_CHILD, NULL);
8766 + matchPatternTypeLbl = XtVaCreateManagedWidget("matchPatternTypeLbl", xmLabelGadgetClass,
8767 + matchPatternsForm,
8768 + XmNlabelString, s1=XmStringCreateSimple("Matching Pattern Type:"),
8769 + XmNmarginHeight, 0,
8770 + XmNalignment, XmALIGNMENT_BEGINNING,
8771 + XmNleftAttachment, XmATTACH_POSITION,
8772 + XmNleftPosition, LIST_RIGHT,
8773 + XmNtopAttachment, XmATTACH_FORM, NULL);
8776 + matchPatternTypeBox = XtVaCreateManagedWidget("matchPatternTypeBox", xmRowColumnWidgetClass,
8777 + matchPatternsForm,
8778 + XmNpacking, XmPACK_COLUMN,
8779 + XmNradioBehavior, True,
8780 + XmNleftAttachment, XmATTACH_POSITION,
8781 + XmNleftPosition, LIST_RIGHT,
8782 + XmNtopAttachment, XmATTACH_WIDGET,
8783 + XmNtopWidget, matchPatternTypeLbl, NULL);
8784 + MatchPatternDialog.mptbIndividualW = XtVaCreateManagedWidget("mptbIndividualW",
8785 + xmToggleButtonWidgetClass, matchPatternTypeBox,
8787 + XmNmarginHeight, 0,
8788 + XmNlabelString, s1=XmStringCreateSimple(
8790 + XmNmnemonic, 'I', NULL);
8792 + XtAddCallback(MatchPatternDialog.mptbIndividualW, XmNvalueChangedCallback,
8793 + matchPatTypeCB, NULL);
8794 + MatchPatternDialog.mptbSubPatternW = XtVaCreateManagedWidget("mptbSubPatternW",
8795 + xmToggleButtonWidgetClass, matchPatternTypeBox,
8796 + XmNmarginHeight, 0,
8797 + XmNlabelString, s1=XmStringCreateSimple(
8798 + "Sub-pattern (belongs to context group)"),
8799 + XmNmnemonic, 'u', NULL);
8801 + XtAddCallback(MatchPatternDialog.mptbSubPatternW, XmNvalueChangedCallback,
8802 + matchPatTypeCB, NULL);
8803 + MatchPatternDialog.mptbContextGroupW = XtVaCreateManagedWidget("mptbContextGroupW",
8804 + xmToggleButtonWidgetClass, matchPatternTypeBox,
8805 + XmNmarginHeight, 0,
8806 + XmNlabelString, s1=XmStringCreateSimple(
8808 + XmNmnemonic, 'g', NULL);
8810 + XtAddCallback(MatchPatternDialog.mptbContextGroupW, XmNvalueChangedCallback,
8811 + matchPatTypeCB, NULL);
8813 + MatchPatternDialog.mpdGlobalAttributesLbl = XtVaCreateManagedWidget("mpdGlobalAttributesLbl",
8814 + xmLabelGadgetClass, matchPatternsForm,
8815 + XmNlabelString, s1=XmStringCreateSimple("Global Attributes:"),
8816 + XmNmarginHeight, 0,
8817 + XmNalignment, XmALIGNMENT_BEGINNING,
8818 + XmNleftAttachment, XmATTACH_POSITION,
8819 + XmNleftPosition, LIST_RIGHT,
8820 + XmNtopAttachment, XmATTACH_WIDGET,
8821 + XmNtopOffset, BORDER,
8822 + XmNtopWidget, matchPatternTypeBox, NULL);
8825 + globalAttributesBox = XtVaCreateManagedWidget("globalAttributesBox", xmRowColumnWidgetClass,
8826 + matchPatternsForm,
8827 + XmNpacking, XmPACK_COLUMN,
8828 + XmNleftAttachment, XmATTACH_POSITION,
8829 + XmNleftPosition, LIST_RIGHT,
8830 + XmNtopAttachment, XmATTACH_WIDGET,
8831 + XmNtopWidget, MatchPatternDialog.mpdGlobalAttributesLbl, NULL);
8832 + MatchPatternDialog.gabSkipBtwStartEndW = XtVaCreateManagedWidget("gabSkipBtwStartEndW",
8833 + xmToggleButtonWidgetClass, globalAttributesBox,
8834 + XmNmarginHeight, 0,
8835 + XmNlabelString, s1=XmStringCreateSimple(
8836 + "Skip content between start / end pattern"),
8837 + XmNmnemonic, 'c', NULL);
8839 + MatchPatternDialog.gabFlashW = XtVaCreateManagedWidget("gabFlashW",
8840 + xmToggleButtonWidgetClass, globalAttributesBox,
8842 + XmNmarginHeight, 0,
8843 + XmNlabelString, s1=XmStringCreateSimple(
8844 + "Flash matching pattern"),
8845 + XmNmnemonic, 'l', NULL);
8847 + MatchPatternDialog.gabSyntaxBasedW = XtVaCreateManagedWidget("gabSyntaxBasedW",
8848 + xmToggleButtonWidgetClass, globalAttributesBox,
8850 + XmNmarginHeight, 0,
8851 + XmNlabelString, s1=XmStringCreateSimple(
8853 + XmNmnemonic, 'b', NULL);
8856 + MatchPatternDialog.mpdMatchPatternNameLbl = XtVaCreateManagedWidget("mpdMatchPatternNameLbl", xmLabelGadgetClass,
8857 + matchPatternsForm,
8858 + XmNlabelString, s1=XmStringCreateSimple(MATCH_PAT_NAME_LBL_TXT),
8860 + XmNalignment, XmALIGNMENT_BEGINNING,
8861 + XmNleftAttachment, XmATTACH_POSITION,
8862 + XmNleftPosition, LIST_RIGHT,
8863 + XmNtopAttachment, XmATTACH_WIDGET,
8864 + XmNtopWidget, globalAttributesBox,
8865 + XmNtopOffset, BORDER, NULL);
8868 + MatchPatternDialog.mpdMatchPatternNameW = XtVaCreateManagedWidget("mpdMatchPatternNameW", xmTextWidgetClass,
8869 + matchPatternsForm,
8870 + XmNleftAttachment, XmATTACH_POSITION,
8871 + XmNleftPosition, LIST_RIGHT,
8872 + XmNtopAttachment, XmATTACH_WIDGET,
8873 + XmNtopWidget, MatchPatternDialog.mpdMatchPatternNameLbl,
8874 + XmNrightAttachment, XmATTACH_FORM,
8875 + XmNrightOffset, BORDER,
8876 + XmNbottomAttachment, XmATTACH_FORM,
8877 + XmNbottomOffset, BORDER,
8879 + RemapDeleteKey(MatchPatternDialog.mpdMatchPatternNameW);
8880 + XtVaSetValues(MatchPatternDialog.mpdMatchPatternNameLbl, XmNuserData, MatchPatternDialog.mpdMatchPatternNameW, NULL);
8883 + XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
8884 + XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
8885 + XtSetArg(args[n], XmNleftPosition, 1); n++;
8886 + XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
8887 + XtSetArg(args[n], XmNrightPosition, LIST_RIGHT-1); n++;
8888 + XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
8890 + XtSetArg(args[n], XmNbottomOffset, BORDER); n++;
8891 + MatchPatternDialog.mpdMatchPatternNamesListW =
8892 + CreateManagedList(
8893 + matchPatternsForm, "mpdMatchPatternNamesListW",
8895 + (void **)MatchPatternDialog.mpdTable.dmpiSequence, &MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements,
8896 + MAX_NBR_MATCH_PATTERNS, 18,
8897 + getMatchPatternDisplayedCB, NULL,
8898 + setMatchPatternDisplayedCB, NULL,
8899 + freeMatchPatternItemCB);
8900 + AddDeleteConfirmCB(MatchPatternDialog.mpdMatchPatternNamesListW, deleteMatchPatternItemCB, NULL);
8902 + XtVaSetValues(matchPatternsLbl, XmNuserData, MatchPatternDialog.mpdMatchPatternNamesListW, NULL);
8905 + * set initial default button
8907 + XtVaSetValues(form, XmNdefaultButton, okBtn, NULL);
8908 + XtVaSetValues(form, XmNcancelButton, closeBtn, NULL);
8911 + * handle mnemonic selection of buttons and focus to dialog
8913 + AddDialogMnemonicHandler(form, False);
8916 + * fill in the dialog information for the selected language mode
8918 + SetLangModeMenu(MatchPatternDialog.mpdLmOptMenu, MatchPatternDialog.mpdLangModeName);
8921 + * realize all of the widgets in the new dialog
8923 + RealizeWithoutForcingPosition(MatchPatternDialog.mpdShell);
8927 +** Modify match pattern dialog depending on showing a string pattern
8928 +** or a context group.
8930 +static void setDialogType(int dialogShowsStringPattern)
8932 + char *matchPatternNameText;
8933 + char *strPatCxtGrpListText;
8935 + int regularExpression =
8936 + XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
8939 + * check, if dialog mode needs to be switched
8941 + if (MatchPatternDialog.mpdStringPatternIsDisplayed == dialogShowsStringPattern)
8946 + if (dialogShowsStringPattern)
8948 + matchPatternNameText = MATCH_PAT_NAME_LBL_TXT;
8949 + strPatCxtGrpListText = STRING_PATTERNS_LBL_TXT;
8953 + matchPatternNameText = "Context Group Name";
8954 + strPatCxtGrpListText = "Related Sub-Patterns";
8957 + XtSetSensitive(MatchPatternDialog.mpdGlobalAttributesLbl, dialogShowsStringPattern);
8958 + XtSetSensitive(MatchPatternDialog.gabSkipBtwStartEndW, dialogShowsStringPattern);
8959 + XtSetSensitive(MatchPatternDialog.gabFlashW, dialogShowsStringPattern);
8960 + XtSetSensitive(MatchPatternDialog.gabSyntaxBasedW, dialogShowsStringPattern);
8962 + XtSetSensitive(MatchPatternDialog.mpdStringPatternTypeLbl, dialogShowsStringPattern);
8963 + XtSetSensitive(MatchPatternDialog.sptStartW, dialogShowsStringPattern);
8964 + XtSetSensitive(MatchPatternDialog.sptMiddleW, dialogShowsStringPattern);
8965 + XtSetSensitive(MatchPatternDialog.sptEndW, dialogShowsStringPattern);
8967 + setSensitiveWordBoundaryBox( dialogShowsStringPattern && !regularExpression );
8969 + XtSetSensitive(MatchPatternDialog.mpdStringAttributesLbl, dialogShowsStringPattern);
8970 + XtSetSensitive(MatchPatternDialog.sabCaseSensitiveW, dialogShowsStringPattern);
8971 + XtSetSensitive(MatchPatternDialog.sabRegularExpressionW, dialogShowsStringPattern);
8973 + XtSetSensitive(MatchPatternDialog.mpdStringPatternLbl, dialogShowsStringPattern);
8974 + XtSetSensitive(MatchPatternDialog.mpdStringPatternW, dialogShowsStringPattern);
8976 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesLbl, !dialogShowsStringPattern);
8977 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesOptMenu, !dialogShowsStringPattern);
8980 + MatchPatternDialog.mpdMatchPatternNameLbl,
8981 + XmNlabelString, s1=XmStringCreateSimple(matchPatternNameText),
8986 + MatchPatternDialog.mpdStringPatternsLbl,
8987 + XmNlabelString, s1=XmStringCreateSimple(strPatCxtGrpListText),
8991 + MatchPatternDialog.mpdStringPatternIsDisplayed = dialogShowsStringPattern;
8994 +static void setSensitiveWordBoundaryBox(int enable)
8996 + XtSetSensitive(MatchPatternDialog.mpdWordBoundaryLbl, enable);
8997 + XtSetSensitive(MatchPatternDialog.wbbBothW , enable);
8998 + XtSetSensitive(MatchPatternDialog.wbbLeftW , enable);
8999 + XtSetSensitive(MatchPatternDialog.wbbRightW, enable);
9000 + XtSetSensitive(MatchPatternDialog.wbbNoneW , enable);
9003 +static void matchPatternLangModeCB(Widget w, XtPointer clientData, XtPointer callData)
9006 + StringMatchTable *oldTable, *newTable;
9007 + StringMatchTable emptyTable = {"", NULL, NULL, NULL, NULL, 0, NULL, 0, NULL};
9008 + StringMatchTable *table;
9009 + DMPTranslationResult translResult;
9013 + * Get the newly selected mode name. If it's the same, do nothing
9015 + XtVaGetValues(w, XmNuserData, &modeName, NULL);
9016 + if (!strcmp(modeName, MatchPatternDialog.mpdLangModeName))
9020 + * Look up the original version of the patterns being edited
9022 + oldTable = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
9023 + if (oldTable == NULL)
9024 + oldTable = &emptyTable;
9027 + * Get the current information displayed by the dialog. If it's bad,
9028 + * give the user the chance to throw it out or go back and fix it. If
9029 + * it has changed, give the user the chance to apply discard or cancel.
9031 + newTable = getDialogStringMatchTable(&translResult);
9033 + if (translResult == DMPTR_EMPTY)
9035 + newTable = &emptyTable;
9038 + if (newTable == NULL)
9041 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9042 + "Incomplete Matching Patterns for Language Mode",
9043 + "Discard incomplete entry for language mode '%s'?",
9044 + "Keep", "Discard",
9045 + MatchPatternDialog.mpdLangModeName) == 1)
9048 + MatchPatternDialog.mpdLmOptMenu,
9049 + MatchPatternDialog.mpdLangModeName);
9054 + else if (stringMatchTableDiffer(oldTable, newTable))
9056 + if (newTable == &emptyTable)
9061 + DF_WARN, MatchPatternDialog.mpdShell, 3,
9062 + "Change Language Mode",
9063 + "Apply changes for language mode '%s'?",
9064 + "Apply Changes", "Discard Changes", "Cancel",
9065 + MatchPatternDialog.mpdLangModeName);
9070 + MatchPatternDialog.mpdLmOptMenu,
9071 + MatchPatternDialog.mpdLangModeName);
9073 + freeStringMatchTable( newTable );
9077 + else if (resp == 1)
9079 + updateStringMatchTable( newTable );
9082 + * Don't free the new table due to it's stored in MatchTables now
9088 + if (newTable != NULL && newTable != &emptyTable)
9089 + freeStringMatchTable(newTable);
9092 + * Free the old dialog information
9094 + freeVariableDialogData(DISCARD_LANGUAGE_MODE);
9097 + * Fill the dialog with the new language mode information
9099 + MatchPatternDialog.mpdLangModeName = XtNewString(modeName);
9102 + * Find the associated matching pattern table to edit
9104 + table = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
9107 + * Copy the list of patterns to one that the user can freely edit
9109 + copyStringMatchTableForDialog( table, &MatchPatternDialog.mpdTable );
9112 + * Update dialog fields
9114 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9115 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9118 +static void pmLanguageModeDialogCB(Widget w, XtPointer clientData, XtPointer callData)
9120 + EditLanguageModes();
9124 +** If a matching pattern dialog is up, ask to have the option menu for
9125 +** chosing language mode updated (via a call to CreateLanguageModeMenu)
9127 +void UpdateLanguageModeMenuMatchPattern(void)
9131 + if (MatchPatternDialog.mpdShell == NULL)
9134 + oldMenu = MatchPatternDialog.mpdLmPulldown;
9136 + * don't include "PLAIN" (4th parameter) in LM menu
9138 + MatchPatternDialog.mpdLmPulldown = CreateLanguageModeMenu(
9139 + XtParent(XtParent(oldMenu)), matchPatternLangModeCB, NULL, False);
9140 + XtVaSetValues(XmOptionButtonGadget(MatchPatternDialog.mpdLmOptMenu),
9141 + XmNsubMenuId, MatchPatternDialog.mpdLmPulldown, NULL);
9142 + SetLangModeMenu(MatchPatternDialog.mpdLmOptMenu, MatchPatternDialog.mpdLangModeName);
9144 + XtDestroyWidget(oldMenu);
9147 +static void *getMatchPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
9150 + DialogMatchPatternSequenceElement *newSeq;
9153 + * If the dialog is currently displaying the "new" entry and the
9154 + * fields are empty, that's just fine
9156 + if (oldItem == NULL && matchPatternDialogEmpty())
9160 + * Read string patterns / sub-pattern names area first
9162 + UpdateManagedList(MatchPatternDialog.mpdStringPatternsListW, True);
9165 + * If there are no problems reading the data, just return it
9167 + newSeq = readMatchPatternFields(True);
9168 + if (newSeq != NULL)
9169 + return (void *)newSeq;
9172 + * If there are problems, and the user didn't ask for the fields to be
9173 + * read, give more warning
9175 + if (!explicitRequest)
9178 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9179 + "Discard Matching Pattern Entry",
9180 + "Discard incomplete entry\nfor current matching pattern?",
9181 + "Keep", "Discard") == 2)
9183 + return oldItem == NULL
9185 + : (void *)copyDialogSequenceElement(
9186 + (DialogMatchPatternSequenceElement *)oldItem);
9191 + * read data again without "silent" mode to display warning
9193 + newSeq = readMatchPatternFields(False);
9199 +static void setMatchPatternDisplayedCB(void *item, void *cbArg)
9201 + DialogMatchPatternSequenceElement *seqElement;
9202 + DialogMatchPatternTableElement *element;
9203 + DialogMatchPatternGroupElement *group;
9206 + seqElement = (DialogMatchPatternSequenceElement *)item;
9208 + MatchPatternDialog.currentDmptSeqElement = seqElement;
9212 + MatchPatternDialog.currentDmptElement = NULL;
9213 + MatchPatternDialog.currentDmptGroup = NULL;
9215 + XmTextSetString(MatchPatternDialog.mpdMatchPatternNameW, "");
9216 + RadioButtonChangeState(MatchPatternDialog.mptbIndividualW, True, True);
9217 + RadioButtonChangeState(MatchPatternDialog.gabSkipBtwStartEndW, False, False);
9218 + RadioButtonChangeState(MatchPatternDialog.gabFlashW, True, False);
9219 + RadioButtonChangeState(MatchPatternDialog.gabSyntaxBasedW, True, False);
9221 + freeDialogStringPatterns(
9222 + &MatchPatternDialog.currentStringPatterns);
9224 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9226 + setDialogType( STRING_PATTERN_DIALOG );
9230 + isGroup = (seqElement->dmpseType == MPT_GROUP);
9232 + XmTextSetString(MatchPatternDialog.mpdMatchPatternNameW, seqElement->dmpseName);
9234 + if (seqElement->dmpseType == MPT_INDIVIDUAL)
9235 + RadioButtonChangeState(MatchPatternDialog.mptbIndividualW, True, True);
9236 + else if (seqElement->dmpseType == MPT_SUB)
9237 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9239 + RadioButtonChangeState(MatchPatternDialog.mptbContextGroupW, True, True);
9241 + freeDialogStringPatterns(
9242 + &MatchPatternDialog.currentStringPatterns);
9246 + group = (DialogMatchPatternGroupElement *)seqElement->dmpsePtr;
9247 + MatchPatternDialog.currentDmptElement = NULL;
9248 + MatchPatternDialog.currentDmptGroup = group;
9250 + copyDialogPatternNamesFromGroup(
9252 + &MatchPatternDialog.currentStringPatterns);
9256 + element = (DialogMatchPatternTableElement *)seqElement->dmpsePtr;
9257 + MatchPatternDialog.currentDmptElement = element;
9258 + MatchPatternDialog.currentDmptGroup = NULL;
9260 + RadioButtonChangeState(
9261 + MatchPatternDialog.gabSkipBtwStartEndW,
9262 + element->dmpteSkipBtwnStartEnd,
9264 + RadioButtonChangeState(
9265 + MatchPatternDialog.gabFlashW,
9266 + element->dmpteFlash,
9268 + RadioButtonChangeState(
9269 + MatchPatternDialog.gabSyntaxBasedW,
9270 + !element->dmpteIgnoreHighLightInfo,
9273 + copyDialogStringPatternsFromTable(
9275 + &MatchPatternDialog.currentStringPatterns);
9278 + setDialogType( !isGroup );
9280 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9284 +static void freeMatchPatternItemCB(void *item)
9286 + freeDialogSequenceElement((DialogMatchPatternSequenceElement *)item);
9290 +** Use "delete confirm" to delete matching pattern name from
9291 +** any group of this matching pattern set, in case of sub-pattern.
9292 +** Always confirm the delete.
9294 +static int deleteMatchPatternItemCB(int itemIndex, void *cbArg)
9296 + DialogMatchPatternSequenceElement *seqElement;
9298 + seqElement = MatchPatternDialog.mpdTable.dmpiSequence[itemIndex];
9300 + if (seqElement->dmpseType == MPT_SUB)
9302 + removeMatchPatternFromAllGroups( seqElement->dmpseName );
9308 +static void *getStringPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
9311 + DialogStringPatternElement *newPat;
9312 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9315 + * If the string pattern frame is currently displaying the "new" entry and the
9316 + * fields are empty, that's just fine
9318 + if (oldItem == NULL && stringPatternFieldsEmpty(isRelatedToGroup))
9322 + * If there are no problems reading the data, just return it
9324 + newPat = readStringPatternFrameFields(True);
9325 + if (newPat != NULL)
9326 + return (void *)newPat;
9329 + * If there are problems, and the user didn't ask for the fields to be
9330 + * read, give more warning
9333 + if (!explicitRequest)
9336 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9337 + "Discard String Pattern Entry",
9338 + "Discard incomplete entry\nfor current string pattern?",
9339 + "Keep", "Discard") == 2)
9341 + return oldItem == NULL
9343 + : (void *)copyDialogStringPatternElement(
9344 + (DialogStringPatternElement *)oldItem);
9349 + * read data again without "silent" mode to display warning
9351 + newPat = readStringPatternFrameFields(False);
9357 +static void setStringPatternDisplayedCB(void *item, void *cbArg)
9359 + DialogStringPatternElement *element = (DialogStringPatternElement *)item;
9360 + PatternElementKind peKind;
9361 + PatternWordBoundary wordBoundary;
9362 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9366 + if (isRelatedToGroup)
9368 + updateSubPatternNameMenu(NULL, False);
9372 + XmTextSetString(MatchPatternDialog.mpdStringPatternW, "");
9374 + setSensitiveWordBoundaryBox( True );
9376 + RadioButtonChangeState(MatchPatternDialog.wbbBothW, True, True);
9379 + * type of "new" string pattern:
9380 + * preset "start", if no string pattern exists at all;
9381 + * else select "end"
9383 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
9384 + RadioButtonChangeState(MatchPatternDialog.sptStartW, True, True);
9386 + RadioButtonChangeState(MatchPatternDialog.sptEndW, True, True);
9388 + RadioButtonChangeState(MatchPatternDialog.sabCaseSensitiveW, True, False);
9389 + RadioButtonChangeState(MatchPatternDialog.sabRegularExpressionW, False, False);
9394 + if (isRelatedToGroup)
9396 + updateSubPatternNameMenu(element->dspeText, False);
9400 + XmTextSetString(MatchPatternDialog.mpdStringPatternW, element->dspeText);
9402 + peKind = element->dspeKind;
9403 + wordBoundary = element->dspeWordBoundary;
9405 + if (peKind == PEK_START)
9406 + RadioButtonChangeState(MatchPatternDialog.sptStartW, True, True);
9407 + else if (peKind == PEK_MIDDLE)
9408 + RadioButtonChangeState(MatchPatternDialog.sptMiddleW, True, True);
9410 + RadioButtonChangeState(MatchPatternDialog.sptEndW, True, True);
9412 + if (wordBoundary == PWB_BOTH)
9413 + RadioButtonChangeState(MatchPatternDialog.wbbBothW, True, True);
9414 + else if (wordBoundary == PWB_LEFT)
9415 + RadioButtonChangeState(MatchPatternDialog.wbbLeftW, True, True);
9416 + else if (wordBoundary == PWB_RIGHT)
9417 + RadioButtonChangeState(MatchPatternDialog.wbbRightW, True, True);
9419 + RadioButtonChangeState(MatchPatternDialog.wbbNoneW, True, True);
9421 + RadioButtonChangeState(
9422 + MatchPatternDialog.sabCaseSensitiveW,
9423 + !element->dspeCaseInsensitive,
9426 + RadioButtonChangeState(
9427 + MatchPatternDialog.sabRegularExpressionW,
9428 + element->dspeRegularExpression,
9431 + setSensitiveWordBoundaryBox( !element->dspeRegularExpression );
9436 +static void freeStringPatternItemCB(void *item)
9438 + DialogStringPatternElement *patElement;
9440 + patElement = (DialogStringPatternElement *)item;
9442 + freeDialogStringPatternElement(patElement);
9445 +static void destroyCB(Widget w, XtPointer clientData, XtPointer callData)
9447 + freeVariableDialogData(DISCARD_LANGUAGE_MODE);
9449 + MatchPatternDialog.mpdShell = NULL;
9452 +static void okCB(Widget w, XtPointer clientData, XtPointer callData)
9455 + * change the matching pattern
9457 + if (!getAndUpdateStringMatchTable())
9461 + * pop down and destroy the dialog
9463 + XtDestroyWidget(MatchPatternDialog.mpdShell);
9466 +static void applyCB(Widget w, XtPointer clientData, XtPointer callData)
9469 + * change the matching pattern
9471 + getAndUpdateStringMatchTable();
9474 +static void checkCB(Widget w, XtPointer clientData, XtPointer callData)
9476 + StringMatchTable *newTable;
9477 + DMPTranslationResult translResult;
9480 + * Get the current information displayed by the dialog.
9481 + * If a new table is available, then the test is passed successfully.
9483 + newTable = getDialogStringMatchTable(&translResult);
9485 + if (newTable != NULL)
9488 + DF_INF, MatchPatternDialog.mpdShell, 1,
9489 + "Matching Patterns Checked",
9490 + "Matching Patterns checked without error",
9493 + freeStringMatchTable(newTable);
9497 +static void restoreCB(Widget w, XtPointer clientData, XtPointer callData)
9499 + StringMatchTable *defaultTable;
9501 + defaultTable = readDefaultStringMatchTable(MatchPatternDialog.mpdLangModeName);
9503 + if (defaultTable == NULL)
9506 + DF_WARN, MatchPatternDialog.mpdShell, 1,
9507 + "No Default Matching Pattern",
9508 + "There is no default matching pattern set\nfor language mode %s",
9510 + MatchPatternDialog.mpdLangModeName);
9516 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9517 + "Discard Changes",
9518 + "Are you sure you want to discard\n"
9519 + "all changes to matching patterns\n"
9520 + "for language mode %s?",
9521 + "Discard", "Cancel",
9522 + MatchPatternDialog.mpdLangModeName) == 2)
9524 + freeStringMatchTable(defaultTable);
9530 + * if a stored version of the matching pattern set exists, replace it.
9531 + * if it doesn't, add a new one.
9533 + updateStringMatchTable( defaultTable );
9536 + * free the old dialog information
9538 + freeVariableDialogData(KEEP_LANGUAGE_MODE);
9541 + * update the dialog
9543 + copyStringMatchTableForDialog( defaultTable, &MatchPatternDialog.mpdTable );
9545 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9546 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9549 +static void deleteCB(Widget w, XtPointer clientData, XtPointer callData)
9552 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9553 + "Delete Matching Patterns",
9554 + "Are you sure you want to delete\n"
9555 + "all matching patterns for\n"
9556 + "language mode %s?",
9557 + "Yes, Delete", "Cancel",
9558 + MatchPatternDialog.mpdLangModeName) == 2)
9564 + * if a stored version of the matching pattern exists, delete it from the list
9566 + DeleteStringMatchTable(MatchPatternDialog.mpdLangModeName);
9569 + * free the old dialog information
9571 + freeVariableDialogData(KEEP_LANGUAGE_MODE);
9574 + * clear out the dialog
9576 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9577 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9580 +static void closeCB(Widget w, XtPointer clientData, XtPointer callData)
9583 + * pop down and destroy the dialog
9585 + XtDestroyWidget(MatchPatternDialog.mpdShell);
9588 +static void helpCB(Widget w, XtPointer clientData, XtPointer callData)
9591 + Help(HELP_MATCHING_PATTERNS);
9595 +static void strPatRegExpressionCB(Widget w, XtPointer clientData, XtPointer callData)
9597 + int regularExpression =
9598 + XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
9600 + setSensitiveWordBoundaryBox( !regularExpression );
9602 + if (regularExpression)
9603 + RadioButtonChangeState(MatchPatternDialog.sabCaseSensitiveW, True, False);
9606 +static void matchPatTypeCB(Widget w, XtPointer clientData, XtPointer callData)
9608 + if (MatchPatternDialog.currentDmptSeqElement != NULL)
9610 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW))
9612 + if (MatchPatternDialog.currentDmptSeqElement->dmpseType == MPT_SUB)
9614 + changeExistingSubPattern("Change to Context Group");
9617 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW) &&
9618 + MatchPatternDialog.currentDmptSeqElement->dmpseType != MPT_GROUP)
9620 + changeStringPatternToGroup();
9623 + else if (XmToggleButtonGetState(MatchPatternDialog.mptbIndividualW))
9625 + if (MatchPatternDialog.currentDmptSeqElement->dmpseType == MPT_SUB)
9627 + changeExistingSubPattern("Change to Individual Matching Pattern");
9629 + else if (MatchPatternDialog.currentDmptSeqElement->dmpseType == MPT_GROUP)
9631 + changeGroupToStringPattern("Change to Individual Matching Pattern");
9634 + else if (XmToggleButtonGetState(MatchPatternDialog.mptbSubPatternW))
9636 + if (MatchPatternDialog.currentDmptSeqElement->dmpseType == MPT_GROUP)
9638 + changeGroupToStringPattern("Change to Sub-Matching Pattern");
9644 + * if context group button is (still) selected, then update labels etc.
9646 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW))
9648 + setDialogType(CONTEXT_GROUP_DIALOG);
9652 + setDialogType(STRING_PATTERN_DIALOG);
9656 + * if a "new" entry is selected in matching patterns names list, then provide a
9657 + * list of all sub-pattern names
9659 + if (MatchPatternDialog.currentDmptSeqElement == NULL)
9661 + updateSubPatternNameMenu(NULL, True);
9665 +static void changeExistingSubPattern(
9668 + DialogMatchPatternGroupElement *group;
9672 + getDialogGroupUsingMatchPattern(
9673 + MatchPatternDialog.currentDmptElement->dmpteName );
9675 + while ( group != NULL )
9679 + DF_WARN, MatchPatternDialog.mpdShell, 3,
9681 + "Sub-pattern '%s' is used at least\n"
9682 + "by context group '%s'.\n\n"
9683 + "Remove this sub-pattern from this resp. all context group(s) ?",
9684 + "No, Keep", "Yes, Remove", "Yes, Remove All",
9685 + MatchPatternDialog.currentDmptElement->dmpteName,
9686 + group->dmpgeName);
9690 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9694 + else if (resp == 2)
9696 + removeMatchPatternFromGroup(
9697 + MatchPatternDialog.currentDmptElement->dmpteName,
9701 + * look for evtl. next context group holding this matching pattern
9704 + getDialogGroupUsingMatchPattern(
9705 + MatchPatternDialog.currentDmptElement->dmpteName );
9710 + * remove this matching pattern form all context groups
9712 + removeMatchPatternFromAllGroups(
9713 + MatchPatternDialog.currentDmptElement->dmpteName);
9720 +static void changeStringPatternToGroup(void)
9725 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns != 0)
9729 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9730 + "Change to Context Group",
9731 + "All string patterns of '%s'\n"
9732 + "need to be discarded.\n\n"
9733 + "Discard related string patterns ?",
9734 + "No, Keep", "Yes, Discard",
9735 + MatchPatternDialog.currentDmptElement->dmpteName);
9739 + isSubPattern = (MatchPatternDialog.currentDmptElement->dmpteType == MPT_SUB);
9742 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9744 + RadioButtonChangeState(MatchPatternDialog.mptbIndividualW, True, True);
9750 + * remove string patterns & update dialog fields
9752 + freeDialogStringPatterns(&MatchPatternDialog.currentStringPatterns);
9754 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9758 + * invalidate this sub-/individual pattern
9760 + MatchPatternDialog.currentDmptSeqElement->dmpseValid = False;
9763 + * update sub-pattern menu due to change to context group
9765 + updateSubPatternNameMenu(NULL, True);
9768 +static void changeGroupToStringPattern(
9773 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
9778 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9780 + "Content of context group '%s'\n"
9781 + "needs to be discarded.\n\n"
9782 + "Discard content ?",
9783 + "No, Keep", "Yes, Discard",
9784 + MatchPatternDialog.currentDmptGroup->dmpgeName);
9788 + RadioButtonChangeState(MatchPatternDialog.mptbContextGroupW, True, True);
9793 + * remove string patterns & update dialog fields
9795 + freeDialogStringPatterns(&MatchPatternDialog.currentStringPatterns);
9797 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9802 +** Create a pulldown menu pane with the names of the sub-patterns of
9803 +** the current matching pattern set.
9805 +static Widget createSubPatternNameMenu(
9807 + char *currentSubPatName,
9808 + int allSubPatterns)
9810 + NameList nameList;
9814 + setupSubPatternNameList(currentSubPatName, allSubPatterns, &nameList);
9816 + menu = CreatePulldownMenu(parent, "subPatternNames", NULL, 0);
9818 + for (i=0; i<nameList.nlNumber; i++)
9820 + createSubPatNameMenuEntry(menu, nameList.nlId[i]);
9826 +static void setupSubPatternNameList(
9827 + char *currentSubPatName,
9828 + int allSubPatterns,
9829 + NameList *nameList)
9833 + DialogMatchPatternSequenceElement *seq;
9834 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9836 + if (isRelatedToGroup || allSubPatterns)
9839 + * add "none selected" (default) item
9841 + nameList->nlId[n ++] = SPNM_NONE_SELECTED;
9844 + * add one item for each (not assigned) sub-pattern name
9846 + for (i=0; i<MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i++)
9848 + seq = MatchPatternDialog.mpdTable.dmpiSequence[i];
9850 + if (seq->dmpseType == MPT_SUB &&
9851 + seq->dmpseValid &&
9852 + (allSubPatterns ||
9853 + (!isSubPatternNameInCurStrPat(seq->dmpseName) ||
9854 + (currentSubPatName != NULL &&
9855 + (strcmp(seq->dmpseName, currentSubPatName) == 0))) ))
9857 + nameList->nlId[n ++] = seq->dmpseName;
9863 + nameList->nlId[n ++] = "none available ";
9866 + nameList->nlNumber = n;
9870 +** Create a menu entry with the names of one sub-pattern.
9871 +** XmNuserData of this item contains the sub-pattern name.
9873 +static void createSubPatNameMenuEntry(
9880 + btn = XtVaCreateManagedWidget("subPattern", xmPushButtonGadgetClass,
9882 + XmNlabelString, s1=XmStringCreateSimple(subPatName),
9883 + XmNmarginHeight, 0,
9884 + XmNuserData, (void *)subPatName, NULL);
9889 +** Set the sub-patterns menu to show a particular sub-pattern name
9891 +static void setSubPatternNameMenu(
9892 + const char *subPatName)
9897 + Widget pulldown, selectedItem;
9900 + XtVaGetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNsubMenuId, &pulldown, NULL);
9901 + XtVaGetValues(pulldown, XmNchildren, &items, XmNnumChildren, &nItems, NULL);
9906 + selectedItem = items[0];
9909 + * if no subPatName is given, then select first item of option menu
9911 + if (subPatName != NULL)
9913 + for (i=0; i<(int)nItems; i++)
9915 + if (items[i] != NULL && !items[i]->core.being_destroyed)
9917 + XtVaGetValues(items[i], XmNuserData, &itemName, NULL);
9918 + if (!strcmp(itemName, subPatName))
9920 + selectedItem = items[i];
9927 + XtVaSetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNmenuHistory, selectedItem, NULL);
9931 +** Update sub-pattern names menu, e.g. when a new sub-pattern is defined
9933 +static void updateSubPatternNameMenu(
9934 + char *currentSubPatName,
9935 + int allSubPatterns)
9937 + NameList nameList;
9943 + setupSubPatternNameList(currentSubPatName, allSubPatterns, &nameList);
9946 + * Go thru all of the items in the sub-pattern names menu
9947 + * and rename them to match the current sub-patterns.
9948 + * Delete any extras.
9951 + MatchPatternDialog.mpdSubPatNamesPulldown,
9952 + XmNchildren, &items,
9953 + XmNnumChildren, &nItems,
9956 + for (n=0; n<(int)nItems; n++)
9958 + if (n >= nameList.nlNumber)
9961 + * unmanaging before destroying stops parent from displaying
9963 + XtUnmanageChild(items[n]);
9964 + XtDestroyWidget(items[n]);
9968 + if (items[n] == NULL || items[n]->core.being_destroyed)
9971 + * create a new entry (widget) if this one is not existing or
9972 + * if it is marked as to be destroyed
9974 + createSubPatNameMenuEntry(
9975 + MatchPatternDialog.mpdSubPatNamesPulldown, nameList.nlId[n]);
9981 + XmNlabelString, st1=XmStringCreateSimple(nameList.nlId[n]),
9982 + XmNuserData, (void *)nameList.nlId[n],
9985 + XmStringFree(st1);
9991 + * add new items for remaining sub-patterns names
9993 + for (n=(int)nItems; n<nameList.nlNumber; n++)
9995 + createSubPatNameMenuEntry(
9996 + MatchPatternDialog.mpdSubPatNamesPulldown, nameList.nlId[n]);
10000 + * select entry shown in sub-pattern name option menu
10002 + setSubPatternNameMenu(currentSubPatName);
10005 +static char *getSelectedSubPatternName(void)
10007 + Widget selectedItem;
10010 + XtVaGetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNmenuHistory, &selectedItem, NULL);
10011 + XtVaGetValues(selectedItem, XmNuserData, &itemName, NULL);
10016 +static int isSubPatternNameInCurStrPat(
10017 + char *subPatName)
10020 + DialogStringPatterns *curPatNames = &MatchPatternDialog.currentStringPatterns;
10022 + for (i=0; i<curPatNames->dspNumberOfPatterns; i++)
10024 + if (strcmp(curPatNames->dspElements[i]->dspeText, subPatName) == 0)
10032 +** Read the matching pattern fields of the matching pattern dialog and produce an
10033 +** allocated DialogMatchPatternSequenceElement structure reflecting the contents.
10034 +** Pop up dialogs telling the user what's wrong (Passing "silent" as True,
10035 +** suppresses these dialogs).
10036 +** Returns NULL on error.
10038 +static DialogMatchPatternSequenceElement *readMatchPatternFields(int silent)
10044 + char *contentTitle;
10045 + char *contentWarningText;
10046 + DialogMatchPatternSequenceElement *newSeq;
10047 + DialogMatchPatternTableElement *newElement;
10048 + DialogMatchPatternGroupElement *newGroup;
10050 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW))
10052 + nameLabel = "context group name";
10053 + nameTitle = "Context Group Name";
10054 + contentTitle = "Context Group Content";
10055 + contentWarningText = "Please assign min. 1\nsub-pattern";
10060 + nameLabel = "matching pattern name";
10061 + nameTitle = "Matching Pattern Name";
10062 + contentTitle = "Matching Pattern Content";
10063 + contentWarningText = "Please specify min. 1\nstring pattern";
10068 + ReadSymbolicFieldTextWidget(
10069 + MatchPatternDialog.mpdMatchPatternNameW,
10073 + if (name == NULL)
10077 + else if (*name == '\0')
10082 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10084 + "Please specify a valid name",
10086 + XmProcessTraversal(MatchPatternDialog.mpdMatchPatternNameW, XmTRAVERSE_CURRENT);
10092 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
10097 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10099 + contentWarningText,
10108 + !isStartPatternElementAvailable(&MatchPatternDialog.currentStringPatterns))
10113 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10115 + "Please specify min. 1 string pattern\nof type 'start'",
10123 + if (MatchPatternDialog.currentDmptElement != NULL &&
10124 + MatchPatternDialog.currentDmptElement->dmpteType == MPT_SUB &&
10125 + strcmp(MatchPatternDialog.currentDmptElement->dmpteName, name) != 0)
10127 + renameMatchPatternInAllGroups(
10128 + MatchPatternDialog.currentDmptElement->dmpteName,
10133 + (DialogMatchPatternSequenceElement *)XtMalloc(sizeof(DialogMatchPatternSequenceElement));
10135 + newSeq->dmpseName = name;
10136 + newSeq->dmpseValid = True;
10140 + newSeq->dmpseType = MPT_GROUP;
10143 + (DialogMatchPatternGroupElement *)XtMalloc(sizeof(DialogMatchPatternGroupElement));
10145 + newGroup->dmpgeName = XtNewString(name);
10147 + copyDialogPatternNamesToGroup(
10148 + &MatchPatternDialog.currentStringPatterns,
10151 + newSeq->dmpsePtr = (void *)newGroup;
10155 + if (XmToggleButtonGetState(MatchPatternDialog.mptbIndividualW))
10156 + newSeq->dmpseType = MPT_INDIVIDUAL;
10158 + newSeq->dmpseType = MPT_SUB;
10161 + (DialogMatchPatternTableElement *)XtMalloc(sizeof(DialogMatchPatternTableElement));
10163 + newElement->dmpteName = XtNewString(name);
10164 + newElement->dmpteType = newSeq->dmpseType;
10166 + newElement->dmpteSkipBtwnStartEnd =
10167 + XmToggleButtonGetState(MatchPatternDialog.gabSkipBtwStartEndW);
10169 + newElement->dmpteFlash =
10170 + XmToggleButtonGetState(MatchPatternDialog.gabFlashW);
10172 + newElement->dmpteIgnoreHighLightInfo =
10173 + !XmToggleButtonGetState(MatchPatternDialog.gabSyntaxBasedW);
10175 + copyDialogStringPatterns(
10176 + &MatchPatternDialog.currentStringPatterns,
10177 + &newElement->dmptePatterns);
10179 + newSeq->dmpsePtr = (void *)newElement;
10186 +** Check, if min. 1 string pattern of type 'start' is
10187 +** available within dialog.
10188 +** Returns True, if min. 1 start string pattern is
10189 +** populated in dialog.
10191 +static int isStartPatternElementAvailable(
10192 + DialogStringPatterns *dialogPatterns)
10196 + for (i=0; i < dialogPatterns->dspNumberOfPatterns; i++)
10198 + if (dialogPatterns->dspElements[i]->dspeKind == PEK_START)
10206 +** Read the string pattern fields of the string pattern frame and produce an
10207 +** allocated DialogStringPatternElement structure reflecting the contents.
10208 +** Pop up dialogs telling the user what's wrong (Passing "silent" as True,
10209 +** suppresses these dialogs).
10210 +** Returns NULL on error.
10212 +static DialogStringPatternElement *readStringPatternFrameFields(int silent)
10214 + char *stringPatText;
10215 + DialogStringPatternElement *newPatElement;
10216 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
10218 + if (isRelatedToGroup)
10220 + stringPatText = getSelectedSubPatternName();
10221 + if (strcmp(stringPatText, SPNM_NONE_SELECTED) == 0)
10226 + stringPatText = XtNewString(stringPatText);
10231 + XmTextGetString(MatchPatternDialog.mpdStringPatternW);
10233 + if (stringPatText == NULL)
10237 + else if (*stringPatText == '\0')
10242 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10243 + "String Pattern",
10244 + "Please specify string\npattern content",
10246 + XmProcessTraversal(MatchPatternDialog.mpdStringPatternW, XmTRAVERSE_CURRENT);
10248 + XtFree(stringPatText);
10253 + newPatElement = (DialogStringPatternElement *)XtMalloc(sizeof(DialogStringPatternElement));
10255 + newPatElement->dspeText = stringPatText;
10257 + if (isRelatedToGroup)
10259 + newPatElement->dspeKind = PEK_START;
10260 + newPatElement->dspeWordBoundary = PWB_NONE;
10261 + newPatElement->dspeCaseInsensitive = False;
10262 + newPatElement->dspeRegularExpression = False;
10266 + newPatElement->dspeRegularExpression =
10267 + XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
10269 + if (XmToggleButtonGetState(MatchPatternDialog.sptStartW))
10270 + newPatElement->dspeKind = PEK_START;
10271 + else if (XmToggleButtonGetState(MatchPatternDialog.sptMiddleW))
10272 + newPatElement->dspeKind = PEK_MIDDLE;
10274 + newPatElement->dspeKind = PEK_END;
10276 + if (newPatElement->dspeRegularExpression)
10277 + newPatElement->dspeWordBoundary = PWB_NONE;
10278 + else if (XmToggleButtonGetState(MatchPatternDialog.wbbBothW))
10279 + newPatElement->dspeWordBoundary = PWB_BOTH;
10280 + else if (XmToggleButtonGetState(MatchPatternDialog.wbbLeftW))
10281 + newPatElement->dspeWordBoundary = PWB_LEFT;
10282 + else if (XmToggleButtonGetState(MatchPatternDialog.wbbRightW))
10283 + newPatElement->dspeWordBoundary = PWB_RIGHT;
10285 + newPatElement->dspeWordBoundary = PWB_NONE;
10287 + newPatElement->dspeCaseInsensitive =
10288 + !XmToggleButtonGetState(MatchPatternDialog.sabCaseSensitiveW);
10291 + return newPatElement;
10295 +** Returns true if the pattern fields of the matching pattern dialog are set to
10296 +** the default ("New" pattern) state.
10298 +static int matchPatternDialogEmpty(void)
10301 + TextWidgetIsBlank(MatchPatternDialog.mpdMatchPatternNameW) &&
10302 + XmToggleButtonGetState(MatchPatternDialog.mptbIndividualW) &&
10303 + XmToggleButtonGetState(MatchPatternDialog.gabFlashW) &&
10304 + XmToggleButtonGetState(MatchPatternDialog.gabSyntaxBasedW) &&
10305 + stringPatternFrameEmpty();
10309 +** Returns true if the string pattern frame of the matching pattern dialog is set to
10310 +** the default state.
10312 +static int stringPatternFrameEmpty(void)
10315 + stringPatternFieldsEmpty(False) &&
10316 + MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0;
10320 +** Returns true if the string pattern fields of the string pattern frame are set to
10321 +** the default state.
10323 +static int stringPatternFieldsEmpty(
10324 + int strPatIsRelatedToGroup)
10326 + if (strPatIsRelatedToGroup)
10329 + strcmp( getSelectedSubPatternName(), SPNM_NONE_SELECTED ) == 0);
10334 + TextWidgetIsBlank(MatchPatternDialog.mpdStringPatternW) &&
10335 + XmToggleButtonGetState(MatchPatternDialog.wbbBothW) &&
10336 + XmToggleButtonGetState(MatchPatternDialog.sabCaseSensitiveW) &&
10337 + !XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
10342 +** Get the current content of the matching pattern dialog.
10343 +** If the matching pattern is o.k., then update & apply it
10344 +** to any window which is currently using the matching pattern.
10345 +** If it's bad, then only report it.
10347 +static int getAndUpdateStringMatchTable(void)
10349 + StringMatchTable *newTable;
10350 + DMPTranslationResult translResult;
10353 + * Get the current information displayed by the dialog. If it's bad,
10354 + * report it to the user & return.
10356 + newTable = getDialogStringMatchTable(&translResult);
10358 + if (newTable == NULL && translResult != DMPTR_EMPTY)
10361 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10362 + "Incomplete Matching Patterns for Language Mode",
10363 + "Incomplete matching patterns for language mode '%s'.\n"
10364 + "Please complete them first",
10366 + MatchPatternDialog.mpdLangModeName);
10372 + * change the matching pattern
10374 + updateStringMatchTable( newTable );
10380 +** Update the matching pattern set being edited in the matching pattern dialog
10381 +** with the information that the dialog is currently displaying, and
10382 +** apply changes to any window which is currently using the matching pattern.
10384 +static void updateStringMatchTable(
10385 + StringMatchTable *newTable)
10387 + WindowInfo *window;
10391 + * Find the matching pattern being modified
10393 + for (i=0; i<NbrMatchTables; i++)
10395 + if (!strcmp(MatchPatternDialog.mpdLangModeName, MatchTables[i]->smtLanguageMode))
10398 + * replace existing matching pattern
10400 + freeStringMatchTable(MatchTables[i]);
10401 + MatchTables[i] = newTable;
10406 + if (i == NbrMatchTables)
10409 + * new match table for language mode -> add it to end
10411 + MatchTables[NbrMatchTables++] = newTable;
10415 + * Find windows that are currently using this matching pattern set and
10416 + * update this windows
10418 + for (window=WindowList; window!=NULL; window=window->next)
10420 + if ((window->languageMode == PLAIN_LANGUAGE_MODE &&
10421 + !strcmp(PLAIN_LM_STRING, newTable->smtLanguageMode)) ||
10422 + (window->languageMode != PLAIN_LANGUAGE_MODE &&
10423 + !strcmp(LanguageModeName(window->languageMode), newTable->smtLanguageMode)))
10425 + window->stringMatchTable = newTable;
10430 + * Note that preferences have been changed
10432 + MarkPrefsChanged();
10435 +static StringMatchTable *getDialogStringMatchTable(
10436 + DMPTranslationResult *result)
10438 + int matchPatListIdx =
10439 + ManagedListSelectedIndex(MatchPatternDialog.mpdMatchPatternNamesListW);
10440 + int stringPatListIdx =
10441 + ManagedListSelectedIndex(MatchPatternDialog.mpdStringPatternsListW);
10444 + * Get the current content of the matching pattern dialog fields
10446 + if (!UpdateManagedList(MatchPatternDialog.mpdStringPatternsListW, True))
10448 + *result = DMPTR_INCOMPLETE;
10453 + if (!UpdateManagedList(MatchPatternDialog.mpdMatchPatternNamesListW, True))
10455 + *result = DMPTR_INCOMPLETE;
10460 + SelectManagedListItem(MatchPatternDialog.mpdMatchPatternNamesListW, matchPatListIdx);
10461 + SelectManagedListItem(MatchPatternDialog.mpdStringPatternsListW, stringPatListIdx);
10464 + * Translate dialog match table to string match table
10466 + return translateDialogStringMatchTable(&MatchPatternDialog.mpdTable, result);
10469 +static StringMatchTable *translateDialogStringMatchTable(
10470 + DialogMatchPatternInfo *dialogTable,
10471 + DMPTranslationResult *result)
10473 + ReadMatchPatternInfo readPatInfo;
10474 + DialogMatchPatternSequenceElement *seq;
10475 + MatchPatternTableElement *newPatElement;
10476 + MatchPatternGroupElement *newGroupElement;
10478 + ErrorInfo errInfo;
10481 + initErrorInfo(&errInfo);
10483 + readPatInfo.rmpiNbrOfElements = 0;
10484 + readPatInfo.rmpiNbrOfGroups = 0;
10485 + readPatInfo.rmpiNbrOfSeqElements = 0;
10486 + readPatInfo.rmpiAllPatRE = NULL;
10487 + readPatInfo.rmpiFlashPatRE = NULL;
10490 + * if no dialog patterns are defined, return "empty" table
10492 + if (dialogTable->dmpiNbrOfSeqElements == 0)
10494 + *result = DMPTR_EMPTY;
10496 + return createStringMatchTable(
10498 + XtNewString(MatchPatternDialog.mpdLangModeName));
10502 + * translate dialog matching pattern elements
10504 + for (i=0; i < dialogTable->dmpiNbrOfSeqElements; i++)
10506 + seq = dialogTable->dmpiSequence[i];
10508 + if (seq->dmpseType == MPT_GROUP)
10510 + newGroupElement =
10511 + translateDialogMatchPatternGroupElement(
10513 + (DialogMatchPatternGroupElement *)seq->dmpsePtr);
10515 + if (newGroupElement == NULL)
10517 + freeReadMatchPatternInfo(&readPatInfo);
10519 + *result = DMPTR_INCOMPLETE;
10524 + readPatInfo.rmpiGroup[readPatInfo.rmpiNbrOfGroups ++] =
10527 + recordPatternSequence(
10531 + readPatInfo.rmpiNbrOfGroups-1 );
10536 + translateDialogMatchPatternTableElement(
10537 + (DialogMatchPatternTableElement *)seq->dmpsePtr);
10539 + newPatElement->mpteIndex = readPatInfo.rmpiNbrOfElements;
10541 + readPatInfo.rmpiElement[readPatInfo.rmpiNbrOfElements ++] =
10544 + if (newPatElement->mpteType == MPT_INDIVIDUAL)
10546 + if (!assignIndividualGroup(&readPatInfo, &errMsg, newPatElement))
10549 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10550 + "Assign reg. exp.",
10551 + "%s\n(Pattern: '%s')",
10554 + newPatElement->mpteName);
10556 + freeReadMatchPatternInfo(&readPatInfo);
10558 + *result = DMPTR_INCOMPLETE;
10564 + treatDuplicatedMTEntries(readPatInfo.rmpiElement, readPatInfo.rmpiNbrOfElements);
10566 + recordPatternSequence(
10570 + newPatElement->mpteIndex );
10575 + * compile reg. expressions of "read" patterns
10577 + if (createRegExpOfPatterns( &readPatInfo, &errInfo ))
10579 + errInfo.eiLanguageMode = XtNewString(MatchPatternDialog.mpdLangModeName);
10580 + dialogMatchingPatternSetError(
10581 + "Assign all patterns reg. exp.",
10584 + freeReadMatchPatternInfo(&readPatInfo);
10586 + *result = DMPTR_INCOMPLETE;
10591 + *result = DMPTR_OK;
10593 + return createStringMatchTable(
10595 + XtNewString(MatchPatternDialog.mpdLangModeName));
10598 +static MatchPatternTableElement *translateDialogMatchPatternTableElement(
10599 + DialogMatchPatternTableElement *dialogElement)
10601 + MatchPatternTableElement *newElement;
10604 + (MatchPatternTableElement *)XtMalloc(sizeof(MatchPatternTableElement));
10606 + newElement->mpteName = XtNewString(dialogElement->dmpteName);
10607 + newElement->mpteIndex = NO_ELEMENT_IDX;
10608 + newElement->mpteType = dialogElement->dmpteType;
10609 + newElement->mpteGroup = NO_GROUP_IDX;
10611 + translateDialogPatterns(&dialogElement->dmptePatterns, newElement);
10613 + newElement->mpteSkipBtwnStartEnd = dialogElement->dmpteSkipBtwnStartEnd;
10614 + newElement->mpteFlash = dialogElement->dmpteFlash;
10615 + newElement->mpteIgnoreHighLightInfo = dialogElement->dmpteIgnoreHighLightInfo;
10616 + newElement->mpteStartEndRE = NULL;
10618 + initGlobalBackRefList( newElement->mpteGlobalBackRef );
10620 + return newElement;
10623 +static void translateDialogPatterns(
10624 + DialogStringPatterns *dialogPatterns,
10625 + MatchPatternTableElement *newElement)
10631 + * allocate memory for patterns
10633 + newElement->mpteAll.pesNumberOfPattern = dialogPatterns->dspNumberOfPatterns;
10636 + sizeof(PatternElement *) * dialogPatterns->dspNumberOfPatterns;
10638 + newElement->mpteAll.pesPattern = (PatternElement **)XtMalloc(sizeOfPat);
10641 + * assign dialog patterns to patterns of MatchPatternTableElement
10643 + for (i=0; i < dialogPatterns->dspNumberOfPatterns; i++)
10645 + newElement->mpteAll.pesPattern[i] =
10646 + createPatternElement(
10647 + XtNewString(dialogPatterns->dspElements[i]->dspeText),
10648 + dialogPatterns->dspElements[i]->dspeKind,
10649 + dialogPatterns->dspElements[i]->dspeWordBoundary,
10650 + dialogPatterns->dspElements[i]->dspeCaseInsensitive,
10651 + dialogPatterns->dspElements[i]->dspeRegularExpression);
10653 + newElement->mpteAll.pesPattern[i]->peIndex = i;
10657 + * sort pattern elements into start, middle & end arrays
10659 + sortDialogPatternElementSet( &newElement->mpteAll, newElement );
10662 + * determine mono pattern
10664 + if (newElement->mpteEnd.pesNumberOfPattern == 0)
10666 + newElement->mpteIsMonoPattern = True;
10668 + copyPatternSet( &newElement->mpteStart, &newElement->mpteEnd );
10672 + newElement->mpteIsMonoPattern = False;
10677 + * Sort dialog pattern element set into start, middle & end arrays.
10679 +static void sortDialogPatternElementSet(
10680 + PatternElementSet *allPat,
10681 + MatchPatternTableElement *result)
10686 + * count number of start, middle & end pattern elements
10688 + countPatternElementKind( allPat, result );
10691 + * allocate pattern elements
10693 + sizeOfPat = sizeof(PatternElement *) * result->mpteStart.pesNumberOfPattern;
10694 + result->mpteStart.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
10696 + if (result->mpteMiddle.pesNumberOfPattern != 0)
10698 + sizeOfPat = sizeof(PatternElement *) * result->mpteMiddle.pesNumberOfPattern;
10699 + result->mpteMiddle.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
10702 + if (result->mpteEnd.pesNumberOfPattern != 0)
10704 + sizeOfPat = sizeof(PatternElement *) * result->mpteEnd.pesNumberOfPattern;
10705 + result->mpteEnd.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
10709 + * sort pattern elements into start, middle & end arrays
10711 + sortPatternElementSet( allPat, result );
10714 +static MatchPatternGroupElement *translateDialogMatchPatternGroupElement(
10715 + ReadMatchPatternInfo *info,
10716 + DialogMatchPatternGroupElement *dialogGroup)
10719 + int error = False;
10720 + MatchPatternTableElement *subPatElement;
10722 + MatchPatternGroupElement *group;
10725 + * Allocate memory for the matching pattern group. Copy name & number of
10729 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
10731 + group->mpgeName = XtNewString(dialogGroup->dmpgeName);
10732 + group->mpgeNumberOfSubPatterns = dialogGroup->dmpgeNumberOfSubPatterns;
10733 + group->mpgeKeywordRE = NULL;
10736 + * Allocate memory for the sub-matching pattern IDs
10738 + sizeOfIds = sizeof(char *) * group->mpgeNumberOfSubPatterns;
10739 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeOfIds );
10741 + for (i=0; i < group->mpgeNumberOfSubPatterns; i ++)
10744 + * Remember sub-matching pattern ID
10746 + group->mpgeSubPatternIds[i] = XtNewString(dialogGroup->dmpgeSubPatternIds[i]);
10749 + * Assign the index of this group to the sub-matching pattern
10750 + * if no group index was assigned before.
10753 + getPatternOfName( info, dialogGroup->dmpgeSubPatternIds[i]);
10755 + if (subPatElement == NULL)
10758 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10759 + "Group Compilation",
10760 + "Group '%s':\nsub-matching pattern '%s' not defined before",
10763 + dialogGroup->dmpgeSubPatternIds[i]);
10769 + if (subPatElement->mpteGroup == NO_GROUP_IDX)
10771 + subPatElement->mpteGroup = info->rmpiNbrOfGroups;
10778 + freeMatchPatternGroupElement(group);
10786 +static int stringMatchTableDiffer(
10787 + StringMatchTable *oldTable,
10788 + StringMatchTable *newTable)
10791 + MatchPatternTable *oldPatTab = oldTable->smtAllPatterns;
10792 + MatchPatternTable *newPatTab = newTable->smtAllPatterns;
10793 + MatchPatternTableElement *oldPat;
10794 + MatchPatternTableElement *newPat;
10795 + MatchPatternGroupElement *oldGroup;
10796 + MatchPatternGroupElement *newGroup;
10797 + MatchPatternSequenceElement *oldSeq;
10798 + MatchPatternSequenceElement *newSeq;
10800 + if (oldTable->smtNumberOfSeqElements != newTable->smtNumberOfSeqElements)
10803 + for (i=0; i < oldTable->smtNumberOfSeqElements; i++)
10805 + oldSeq = oldTable->smtSequence[i];
10806 + newSeq = newTable->smtSequence[i];
10808 + if (AllocatedStringsDiffer(oldSeq->mpseName, newSeq->mpseName))
10810 + if (oldSeq->mpseType != newSeq->mpseType)
10813 + if (oldSeq->mpseType == MPT_GROUP)
10815 + oldGroup = oldTable->smtGroups[oldSeq->mpseIndex];
10816 + newGroup = newTable->smtGroups[newSeq->mpseIndex];
10818 + if (AllocatedStringsDiffer(oldGroup->mpgeName, newGroup->mpgeName))
10821 + if (oldGroup->mpgeNumberOfSubPatterns != newGroup->mpgeNumberOfSubPatterns)
10824 + for (j=0; j < oldGroup->mpgeNumberOfSubPatterns; j++)
10826 + if (AllocatedStringsDiffer(
10827 + oldGroup->mpgeSubPatternIds[j],
10828 + newGroup->mpgeSubPatternIds[j]))
10834 + oldPat = oldPatTab->mptElements[oldSeq->mpseIndex];
10835 + newPat = newPatTab->mptElements[newSeq->mpseIndex];
10837 + if (AllocatedStringsDiffer(oldPat->mpteName, newPat->mpteName))
10840 + if (oldPat->mpteType != newPat->mpteType)
10843 + if (oldPat->mpteGroup != newPat->mpteGroup)
10846 + if (oldPat->mpteAll.pesNumberOfPattern != newPat->mpteAll.pesNumberOfPattern)
10849 + for (j=0; j < oldPat->mpteAll.pesNumberOfPattern; j ++)
10851 + if (patternElementDiffer(
10852 + oldPat->mpteAll.pesPattern[j], oldPatTab,
10853 + newPat->mpteAll.pesPattern[j], newPatTab ) )
10857 + if (oldPat->mpteIsMonoPattern != newPat->mpteIsMonoPattern)
10860 + if (oldPat->mpteSkipBtwnStartEnd != newPat->mpteSkipBtwnStartEnd)
10863 + if (oldPat->mpteIgnoreHighLightInfo != newPat->mpteIgnoreHighLightInfo)
10866 + if (oldPat->mpteFlash != newPat->mpteFlash)
10874 +static int patternElementDiffer(
10875 + PatternElement *oldPE,
10876 + MatchPatternTable *oldTab,
10877 + PatternElement *newPE,
10878 + MatchPatternTable *newTab)
10880 + StringPattern *oldSP;
10881 + StringPattern *newSP;
10883 + oldSP = GetStringPattern(oldTab, oldPE);
10884 + newSP = GetStringPattern(newTab, newPE);
10886 + if (AllocatedStringsDiffer(oldSP->spText, newSP->spText))
10888 + if (AllocatedStringsDiffer(oldSP->spOrigText, newSP->spOrigText))
10890 + if (oldPE->peKind != newPE->peKind)
10892 + if (oldSP->spWordBoundary != newSP->spWordBoundary)
10894 + if (oldSP->spCaseInsensitive != newSP->spCaseInsensitive)
10896 + if (oldSP->spRegularExpression != newSP->spRegularExpression)
10902 +static DialogMatchPatternGroupElement *getDialogGroupUsingMatchPattern(
10903 + char *matchPatternName)
10905 + DialogMatchPatternSequenceElement *seq;
10906 + DialogMatchPatternGroupElement *group;
10909 + for (i=0; i < MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i ++)
10911 + seq = MatchPatternDialog.mpdTable.dmpiSequence[i];
10913 + if (seq->dmpseType == MPT_GROUP)
10915 + group = (DialogMatchPatternGroupElement *)seq->dmpsePtr;
10917 + for (j=0; j < group->dmpgeNumberOfSubPatterns; j ++)
10919 + if (strcmp(group->dmpgeSubPatternIds[j], matchPatternName) == 0)
10928 +static void removeMatchPatternFromGroup(
10929 + char *matchPatternName,
10930 + DialogMatchPatternGroupElement *group)
10934 + for (i=0; i < group->dmpgeNumberOfSubPatterns; i ++)
10936 + if (strcmp(group->dmpgeSubPatternIds[i], matchPatternName) == 0)
10939 + * remove existing matching pattern name from sub-pattern list
10941 + freeXtPtr((void **)&group->dmpgeSubPatternIds[i]);
10943 + &group->dmpgeSubPatternIds[i],
10944 + &group->dmpgeSubPatternIds[i+1],
10945 + (group->dmpgeNumberOfSubPatterns-1 - i) * sizeof(char *));
10946 + group->dmpgeNumberOfSubPatterns --;
10953 +static void removeMatchPatternFromAllGroups(
10954 + char *matchPatternName)
10956 + DialogMatchPatternSequenceElement *seq;
10957 + DialogMatchPatternGroupElement *group;
10960 + for (i=0; i < MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i ++)
10962 + seq = MatchPatternDialog.mpdTable.dmpiSequence[i];
10964 + if (seq->dmpseType == MPT_GROUP)
10966 + group = (DialogMatchPatternGroupElement *)seq->dmpsePtr;
10968 + removeMatchPatternFromGroup(matchPatternName, group);
10973 +static void renameMatchPatternInGroup(
10974 + char *oldMatchPatternName,
10975 + char *newMatchPatternName,
10976 + DialogMatchPatternGroupElement *group)
10980 + for (i=0; i < group->dmpgeNumberOfSubPatterns; i ++)
10982 + if (strcmp(group->dmpgeSubPatternIds[i], oldMatchPatternName) == 0)
10985 + * rename existing matching pattern name in sub-pattern list
10987 + freeXtPtr((void **)&group->dmpgeSubPatternIds[i]);
10989 + group->dmpgeSubPatternIds[i] =
10990 + XtNewString(newMatchPatternName);
10997 +static void renameMatchPatternInAllGroups(
10998 + char *oldMatchPatternName,
10999 + char *newMatchPatternName)
11001 + DialogMatchPatternSequenceElement *seq;
11002 + DialogMatchPatternGroupElement *group;
11005 + for (i=0; i < MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i ++)
11007 + seq = MatchPatternDialog.mpdTable.dmpiSequence[i];
11009 + if (seq->dmpseType == MPT_GROUP)
11011 + group = (DialogMatchPatternGroupElement *)seq->dmpsePtr;
11013 + renameMatchPatternInGroup(
11014 + oldMatchPatternName,
11015 + newMatchPatternName,
11021 +static void freeVariableDialogData(
11022 + int keepLanguageModeName)
11026 + if (!keepLanguageModeName)
11027 + freeXtPtr((void **)&MatchPatternDialog.mpdLangModeName);
11029 + for (i=0; i < MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i ++)
11031 + freeDialogSequenceElement(
11032 + MatchPatternDialog.mpdTable.dmpiSequence[i] );
11035 + MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements = 0;
11037 + freeDialogStringPatterns(
11038 + &MatchPatternDialog.currentStringPatterns);
11041 +static void initGlobalBackRefList(
11042 + GlobalBackRefElement *list)
11046 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
11048 + list[i].gbreDefByStrPat = NULL;
11049 + list[i].gbreRegExpText = NULL;
11053 +static void initStrPatBackRefList(
11054 + StringPattern *strPat)
11058 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
11060 + strPat->spOwnGlobalBackRef[i].spbreRegExpText = NULL;
11061 + strPat->spOwnGlobalBackRef[i].spbreLocalBackRefID = NO_LOCAL_BACK_REF_ID;
11063 + strPat->spGlobalToLocalBackRef[i] = NO_LOCAL_BACK_REF_ID;
11067 +static void initErrorInfo(
11068 + ErrorInfo *errInfo)
11070 + errInfo->eiDetail = NULL;
11071 + errInfo->eiLanguageMode = NULL;
11072 + errInfo->eiMPTabElementName = NULL;
11073 + errInfo->eiStringPatText = NULL;
11074 + errInfo->eiRegExpCompileMsg = NULL;
11075 + errInfo->eiBackRefNbr = 0;
11078 +static void freeErrorInfo(
11079 + ErrorInfo *errInfo)
11081 + freeXtPtr((void **)&errInfo->eiLanguageMode);
11082 + freeXtPtr((void **)&errInfo->eiMPTabElementName);
11083 + freeXtPtr((void **)&errInfo->eiStringPatText);
11086 +static void freeXtPtr(void **ptr)
11088 + if (*ptr != NULL)
11090 + XtFree((char *)*ptr);
11095 +static void freePtr(void **ptr)
11097 + if (*ptr != NULL)
11099 + free((char *)*ptr);
11103 diff --quilt /dev/null new/source/patternMatchData.h
11105 +++ new/source/patternMatchData.h
11107 +/* $Id: patternMatchData.h,v 1.3 2003/12/12 16:45:25 uleh Exp $ */
11109 +#ifndef NEDIT_PATTERNMATCHDATA_H_INCLUDED
11110 +#define NEDIT_PATTERNMATCHDATA_H_INCLUDED
11112 +void *FindStringMatchTable(const char *langModeName);
11114 +void RenameStringMatchTable(const char *oldName, const char *newName);
11116 +void DeleteStringMatchTable(const char *langModeName);
11118 +void AssignStandardStringMatchTable(const char *langModeName);
11120 +int LMHasStringMatchTable(const char *languageMode);
11122 +int LoadMatchPatternString(char *inString);
11124 +char *WriteMatchPatternString(void);
11126 +void EditMatchPatterns(WindowInfo *window);
11128 +void UpdateLanguageModeMenuMatchPattern(void);
11130 +#endif /* NEDIT_PATTERNMATCHDATA_H_INCLUDED */
11131 diff --quilt old/source/preferences.c new/source/preferences.c
11132 --- old/source/preferences.c
11133 +++ new/source/preferences.c
11134 @@ -45,10 +45,14 @@ static const char CVSID[] = "$Id: prefer
11135 #include "regularExp.h"
11136 #include "smartIndent.h"
11137 #include "windowTitle.h"
11138 #include "server.h"
11141 +/* Pattern Match Feature */
11142 +#include "patternMatchData.h"
11144 #include "../util/prefFile.h"
11145 #include "../util/misc.h"
11146 #include "../util/DialogF.h"
11147 #include "../util/managedList.h"
11148 #include "../util/fontsel.h"
11149 @@ -278,11 +282,10 @@ static struct prefData {
11150 int textCols; /* initial window width in characters */
11151 int tabDist; /* number of characters between tab stops */
11152 int emTabDist; /* non-zero tab dist. if emulated tabs are on */
11153 int insertTabs; /* whether to use tabs for padding */
11154 int showMatchingStyle; /* how to flash matching parenthesis */
11155 - int matchSyntaxBased; /* use syntax info to match parenthesis */
11156 int highlightSyntax; /* whether to highlight syntax by default */
11157 int smartTags; /* look for tag in current window first */
11158 int alwaysCheckRelativeTagsSpecs; /* for every new opened file of session */
11159 int stickyCaseSenseBtn; /* whether Case Word Btn is sticky to Regex Btn */
11160 int prefFileRead; /* detects whether a .nedit existed */
11161 @@ -348,10 +351,11 @@ static struct {
11165 char *smartIndentCommon;
11167 + char *matchPattern;
11170 /* preference descriptions for SavePreferences and RestorePreferences. */
11171 static PrefDescripRec PrefDescrip[] = {
11172 {"fileVersion", "FileVersion" , PREF_STRING, "", PrefData.fileVersion,
11173 @@ -853,10 +857,76 @@ static PrefDescripRec PrefDescrip[] = {
11176 Matlab:Default", &TempStringPrefs.smartIndent, NULL, True},
11177 {"smartIndentInitCommon", "SmartIndentInitCommon", PREF_ALLOC_STRING,
11178 "Default", &TempStringPrefs.smartIndentCommon, NULL, True},
11179 +/* Pattern Match Feature: matchPatterns resource added */
11181 +/* The VAX compiler can't compile Java-Script's definition in highlightData.c */
11182 + {"matchPatterns", "MatchPatterns", PREF_ALLOC_STRING,
11183 + "PLAIN:Default\n\
11190 + Fortran:Default\n\
11194 + Makefile:Default\n\
11195 + Matlab:Default\n\
11196 + NEdit Macro:Default\n\
11197 + Pascal:Default\n\
11199 + PostScript:Default\n\
11200 + Python:Default\n\
11202 + SGML HTML:Default\n\
11204 + Sh Ksh Bash:Default\n\
11207 + Verilog:Default\n\
11209 + X Resources:Default\n\
11211 + &TempStringPrefs.matchPattern, NULL, True},
11213 + {"matchPatterns", "MatchPatterns", PREF_ALLOC_STRING,
11214 + "PLAIN:Default\n\
11221 + Fortran:Default\n\
11223 + JavaScript:Default\n\
11226 + Makefile:Default\n\
11227 + Matlab:Default\n\
11228 + NEdit Macro:Default\n\
11229 + Pascal:Default\n\
11231 + PostScript:Default\n\
11232 + Python:Default\n\
11234 + SGML HTML:Default\n\
11236 + Sh Ksh Bash:Default\n\
11239 + Verilog:Default\n\
11241 + X Resources:Default\n\
11243 + &TempStringPrefs.matchPattern, NULL, True},
11245 {"autoWrap", "AutoWrap", PREF_ENUM, "Continuous",
11246 &PrefData.wrapStyle, AutoWrapTypes, True},
11247 {"wrapMargin", "WrapMargin", PREF_INT, "0",
11248 &PrefData.wrapMargin, NULL, True},
11249 {"showWrapMargin", "ShowWrapMargin", PREF_ENUM, "Never",
11250 @@ -869,12 +939,10 @@ static PrefDescripRec PrefDescrip[] = {
11251 &PrefData.openInTab, NULL, True},
11252 {"saveOldVersion", "SaveOldVersion", PREF_BOOLEAN, "False",
11253 &PrefData.saveOldVersion, NULL, True},
11254 {"showMatching", "ShowMatching", PREF_ENUM, "Delimiter",
11255 &PrefData.showMatchingStyle, ShowMatchingTypes, True},
11256 - {"matchSyntaxBased", "MatchSyntaxBased", PREF_BOOLEAN, "True",
11257 - &PrefData.matchSyntaxBased, NULL, True},
11258 {"highlightSyntax", "HighlightSyntax", PREF_BOOLEAN, "True",
11259 &PrefData.highlightSyntax, NULL, True},
11260 {"backlightChars", "BacklightChars", PREF_BOOLEAN, "False",
11261 &PrefData.backlightChars, NULL, True},
11262 {"backlightCharTypes", "BacklightCharTypes", PREF_ALLOC_STRING,
11263 @@ -1243,10 +1311,11 @@ static void lmDestroyCB(Widget w, XtPoin
11264 static void lmOkCB(Widget w, XtPointer clientData, XtPointer callData);
11265 static void lmApplyCB(Widget w, XtPointer clientData, XtPointer callData);
11266 static void lmCloseCB(Widget w, XtPointer clientData, XtPointer callData);
11267 static int lmDeleteConfirmCB(int itemIndex, void *cbArg);
11268 static int updateLMList(void);
11269 +static int isOldLanguageMode(const char *lmDialogName, const char *oldModeName);
11270 static languageModeRec *copyLanguageModeRec(languageModeRec *lm);
11271 static void *lmGetDisplayedCB(void *oldItem, int explicitRequest, int *abort,
11273 static void lmSetDisplayedCB(void *item, void *cbArg);
11274 static languageModeRec *readLMDialogFields(int silent);
11275 @@ -1426,10 +1495,15 @@ static void translatePrefFormats(int con
11276 if (TempStringPrefs.smartIndentCommon != NULL) {
11277 LoadSmartIndentCommonString(TempStringPrefs.smartIndentCommon);
11278 XtFree(TempStringPrefs.smartIndentCommon);
11279 TempStringPrefs.smartIndentCommon = NULL;
11281 + if (TempStringPrefs.matchPattern != NULL) {
11282 + LoadMatchPatternString(TempStringPrefs.matchPattern);
11283 + XtFree(TempStringPrefs.matchPattern);
11284 + TempStringPrefs.matchPattern = NULL;
11287 /* translate the font names into fontLists suitable for the text widget */
11288 font = XLoadQueryFont(TheDisplay, PrefData.fontString);
11289 PrefData.fontList = font==NULL ? NULL :
11290 XmFontListCreate(font, XmSTRING_DEFAULT_CHARSET);
11291 @@ -1505,10 +1579,11 @@ void SaveNEditPrefs(Widget parent, int q
11292 TempStringPrefs.highlight = WriteHighlightString();
11293 TempStringPrefs.language = writeLanguageModesString();
11294 TempStringPrefs.styles = WriteStylesString();
11295 TempStringPrefs.smartIndent = WriteSmartIndentString();
11296 TempStringPrefs.smartIndentCommon = WriteSmartIndentCommonString();
11297 + TempStringPrefs.matchPattern = WriteMatchPatternString();
11298 strcpy(PrefData.fileVersion, PREF_FILE_VERSION);
11300 if (!SavePreferences(XtDisplay(parent), prefFileName, HeaderText,
11301 PrefDescrip, XtNumber(PrefDescrip)))
11303 @@ -1524,10 +1599,11 @@ void SaveNEditPrefs(Widget parent, int q
11304 XtFree(TempStringPrefs.highlight);
11305 XtFree(TempStringPrefs.language);
11306 XtFree(TempStringPrefs.styles);
11307 XtFree(TempStringPrefs.smartIndent);
11308 XtFree(TempStringPrefs.smartIndentCommon);
11309 + XtFree(TempStringPrefs.matchPattern);
11311 PrefsHaveChanged = False;
11315 @@ -1920,20 +1996,10 @@ int GetPrefShowMatching(void)
11316 if (PrefData.showMatchingStyle >= N_SHOW_MATCHING_STYLES)
11317 PrefData.showMatchingStyle -= N_SHOW_MATCHING_STYLES;
11318 return PrefData.showMatchingStyle;
11321 -void SetPrefMatchSyntaxBased(int state)
11323 - setIntPref(&PrefData.matchSyntaxBased, state);
11326 -int GetPrefMatchSyntaxBased(void)
11328 - return PrefData.matchSyntaxBased;
11331 void SetPrefHighlightSyntax(Boolean state)
11333 setIntPref(&PrefData.highlightSyntax, state);
11336 @@ -3479,10 +3545,25 @@ static int lmDeleteConfirmCB(int itemInd
11337 "Auto Indent -> Program Smart Indent,\n"
11338 "before proceeding here.", "OK");
11342 + /* Pattern Match Feature: don't allow deletion if data will be lost */
11343 + if (LMHasStringMatchTable(LMDialog.languageModeList[itemIndex]->name))
11345 + DialogF(DF_WARN, LMDialog.shell, 1, "Matching Patterns exist",
11346 + "This language mode has matching patterns\n"
11347 + "defined. Please delete the patterns first,\n"
11348 + "in Preferences -> Default Settings ->\n"
11349 + "Show Matching (..) -> Matching Patterns ..,\n"
11350 + "before proceeding here.", "Dismiss");
11354 + /* delete "empty" string match table related to language mode to be deleted */
11355 + DeleteStringMatchTable(LMDialog.languageModeList[itemIndex]->name);
11361 ** Apply the changes that the user has made in the language modes dialog to the
11362 @@ -3499,19 +3580,19 @@ static int updateLMList(void)
11363 /* Get the current contents of the dialog fields */
11364 if (!UpdateManagedList(LMDialog.managedListW, True))
11367 /* Fix up language mode indices in all open windows (which may change
11368 - if the currently selected mode is deleted or has changed position),
11369 - and update word delimiters */
11370 + if the currently selected mode is renamed, deleted or has changed
11371 + position), and update word delimiters */
11372 for (window=WindowList; window!=NULL; window=window->next) {
11373 if (window->languageMode != PLAIN_LANGUAGE_MODE) {
11374 oldLanguageMode = window->languageMode;
11375 oldModeName = LanguageModes[window->languageMode]->name;
11376 window->languageMode = PLAIN_LANGUAGE_MODE;
11377 for (i=0; i<LMDialog.nLanguageModes; i++) {
11378 - if (!strcmp(oldModeName, LMDialog.languageModeList[i]->name)) {
11379 + if (isOldLanguageMode(LMDialog.languageModeList[i]->name, oldModeName)) {
11380 newDelimiters = LMDialog.languageModeList[i]->delimiters;
11381 if (newDelimiters == NULL)
11382 newDelimiters = GetPrefDelimiters();
11383 XtVaSetValues(window->textArea, textNwordDelimiters,
11384 newDelimiters, NULL);
11385 @@ -3537,10 +3618,11 @@ static int updateLMList(void)
11386 if (strchr(LMDialog.languageModeList[i]->name, ':') != NULL) {
11387 char *newName = strrchr(LMDialog.languageModeList[i]->name, ':')+1;
11388 *strchr(LMDialog.languageModeList[i]->name, ':') = '\0';
11389 RenameHighlightPattern(LMDialog.languageModeList[i]->name, newName);
11390 RenameSmartIndentMacros(LMDialog.languageModeList[i]->name, newName);
11391 + RenameStringMatchTable(LMDialog.languageModeList[i]->name, newName);
11392 memmove(LMDialog.languageModeList[i]->name, newName,
11393 strlen(newName) + 1);
11394 ChangeManagedListData(LMDialog.managedListW);
11397 @@ -3554,31 +3636,62 @@ static int updateLMList(void)
11399 /* Update user menu info to update language mode dependencies of
11401 UpdateUserMenuInfo();
11403 + /* Pattern Match Feature: assign standard string match table to new
11404 + language modes */
11405 + for (i=0; i<NLanguageModes; i++) {
11406 + if (FindStringMatchTable(LanguageModeName(i)) == NULL)
11407 + AssignStandardStringMatchTable(LanguageModeName(i));
11410 /* Update the menus in the window menu bars and load any needed
11411 - calltips files */
11412 + calltips files and reassign string match tables */
11413 for (window=WindowList; window!=NULL; window=window->next) {
11414 updateLanguageModeSubmenu(window);
11415 if (window->languageMode != PLAIN_LANGUAGE_MODE &&
11416 LanguageModes[window->languageMode]->defTipsFile != NULL)
11417 AddTagsFile(LanguageModes[window->languageMode]->defTipsFile, TIP);
11419 + window->stringMatchTable =
11420 + FindStringMatchTable(LanguageModeName(window->languageMode));
11422 /* cache user menus: Rebuild all user menus of this window */
11423 RebuildAllMenus(window);
11426 /* If a syntax highlighting dialog is up, update its menu */
11427 UpdateLanguageModeMenu();
11428 /* The same for the smart indent macro dialog */
11429 UpdateLangModeMenuSmartIndent();
11430 + /* The same for the match pattern dialog */
11431 + UpdateLanguageModeMenuMatchPattern();
11432 /* Note that preferences have been changed */
11433 MarkPrefsChanged();
11439 +** Returns true, if the given old language mode name matches the
11440 +** given (new) language mode dialog name.
11442 +static int isOldLanguageMode(const char *lmDialogName, const char *oldModeName)
11444 + char *c = strchr(lmDialogName, ':');
11445 + int isOldMode = !strcmp(oldModeName, lmDialogName);
11447 + if (!isOldMode && c != NULL) {
11449 + isOldMode = !strcmp(lmDialogName, oldModeName);
11453 + return isOldMode;
11456 static void *lmGetDisplayedCB(void *oldItem, int explicitRequest, int *abort,
11459 languageModeRec *lm, *oldLM = (languageModeRec *)oldItem;
11461 @@ -4568,10 +4681,14 @@ static void reapplyLanguageMode(WindowIn
11462 /* Decref oldMode's default calltips file if needed */
11463 if (oldMode != PLAIN_LANGUAGE_MODE && LanguageModes[oldMode]->defTipsFile) {
11464 DeleteTagsFile( LanguageModes[oldMode]->defTipsFile, TIP, False );
11467 + /* Pattern Match Feature: Assign the match pattern related to
11468 + the language mode */
11469 + window->stringMatchTable = FindStringMatchTable(LanguageModeName(mode));
11471 /* Set delimiters for all text widgets */
11472 if (mode == PLAIN_LANGUAGE_MODE || LanguageModes[mode]->delimiters == NULL)
11473 delimiters = GetPrefDelimiters();
11475 delimiters = LanguageModes[mode]->delimiters;
11476 @@ -5185,18 +5302,35 @@ char *ReadSymbolicFieldTextWidget(Widget
11480 ** Create a pulldown menu pane with the names of the current language modes.
11481 ** XmNuserData for each item contains the language mode name.
11482 +** Pattern Match Feature: if "includePlain" is set, then 1st menu entry
11485 -Widget CreateLanguageModeMenu(Widget parent, XtCallbackProc cbProc, void *cbArg)
11486 +Widget CreateLanguageModeMenu(
11488 + XtCallbackProc cbProc,
11490 + int includePlain)
11496 menu = CreatePulldownMenu(parent, "languageModes", NULL, 0);
11498 + if (includePlain) {
11499 + btn = XtVaCreateManagedWidget("languageMode", xmPushButtonGadgetClass,
11501 + XmNlabelString, s1=XmStringCreateSimple("PLAIN"),
11502 + XmNmarginHeight, 0,
11503 + XmNuserData, (void *)"PLAIN", NULL);
11504 + XmStringFree(s1);
11505 + XtAddCallback(btn, XmNactivateCallback, cbProc, cbArg);
11508 for (i=0; i<NLanguageModes; i++) {
11509 btn = XtVaCreateManagedWidget("languageMode", xmPushButtonGadgetClass,
11511 XmNlabelString, s1=XmStringCreateSimple(LanguageModes[i]->name),
11512 XmNmarginHeight, 0,
11513 diff --quilt old/source/preferences.h new/source/preferences.h
11514 --- old/source/preferences.h
11515 +++ new/source/preferences.h
11516 @@ -109,12 +109,10 @@ void SetPrefEmTabDist(int tabDist);
11517 int GetPrefEmTabDist(int langMode);
11518 void SetPrefInsertTabs(int state);
11519 int GetPrefInsertTabs(void);
11520 void SetPrefShowMatching(int state);
11521 int GetPrefShowMatching(void);
11522 -void SetPrefMatchSyntaxBased(int state);
11523 -int GetPrefMatchSyntaxBased(void);
11524 void SetPrefHighlightSyntax(Boolean state);
11525 Boolean GetPrefHighlightSyntax(void);
11526 void SetPrefBacklightChars(int state);
11527 int GetPrefBacklightChars(void);
11528 void SetPrefBacklightCharTypes(char *types);
11529 @@ -189,11 +187,11 @@ int AllocatedStringsDiffer(const char *s
11530 void SetLanguageMode(WindowInfo *window, int mode, int forceNewDefaults);
11531 int FindLanguageMode(const char *languageName);
11532 void UnloadLanguageModeTipsFile(WindowInfo *window);
11533 void DetermineLanguageMode(WindowInfo *window, int forceNewDefaults);
11534 Widget CreateLanguageModeMenu(Widget parent, XtCallbackProc cbProc,
11536 + void *cbArg, int includePlain);
11537 void SetLangModeMenu(Widget optMenu, const char *modeName);
11538 void CreateLanguageModeSubMenu(WindowInfo* window, const Widget parent,
11539 const char* name, const char* label, const char mnemonic);
11540 void SetPrefFindReplaceUsesSelection(int state);
11541 int GetPrefFindReplaceUsesSelection(void);
11542 diff --quilt old/source/search.c new/source/search.c
11543 --- old/source/search.c
11544 +++ new/source/search.c
11545 @@ -83,10 +83,11 @@ static const char CVSID[] = "$Id: search
11547 #ifdef HAVE_DEBUG_H
11548 #include "../debug.h"
11551 +#include "patternMatch.h"
11555 typedef struct _SelectionInfo {
11557 @@ -171,10 +172,11 @@ static void freeWritableWindowsCB(Widget
11558 XmAnyCallbackStruct *callData);
11559 static void checkMultiReplaceListForDoomedW(WindowInfo* window,
11560 WindowInfo* doomedWindow);
11561 static void removeDoomedWindowFromList(WindowInfo* window, int index);
11562 static void unmanageReplaceDialogs(const WindowInfo *window);
11563 +static int getPosForMatchingCharacter(WindowInfo *window);
11564 static void flashTimeoutProc(XtPointer clientData, XtIntervalId *id);
11565 static void eraseFlash(WindowInfo *window);
11566 static int getReplaceDlogInfo(WindowInfo *window, int *direction,
11567 char *searchString, char *replaceString, int *searchType);
11568 static int getFindDlogInfo(WindowInfo *window, int *direction,
11569 @@ -211,13 +213,10 @@ static void downCaseString(char *outStri
11570 static void resetFindTabGroup(WindowInfo *window);
11571 static void resetReplaceTabGroup(WindowInfo *window);
11572 static int searchMatchesSelection(WindowInfo *window, const char *searchString,
11573 int searchType, int *left, int *right, int *searchExtentBW,
11574 int *searchExtentFW);
11575 -static int findMatchingChar(WindowInfo *window, char toMatch,
11576 - void *toMatchStyle, int charPos, int startLimit, int endLimit,
11578 static Boolean replaceUsingRE(const char* searchStr, const char* replaceStr,
11579 const char* sourceStr, int beginPos, char* destStr, int maxDestLen,
11580 int prevChar, const char* delimiters, int defaultFlags);
11581 static void saveSearchHistory(const char *searchString,
11582 const char *replaceString, int searchType, int isIncremental);
11583 @@ -251,28 +250,10 @@ typedef struct _charMatchTable {
11589 -#define N_MATCH_CHARS 13
11590 -#define N_FLASH_CHARS 6
11591 -static charMatchTable MatchingChars[N_MATCH_CHARS] = {
11592 - {'{', '}', SEARCH_FORWARD},
11593 - {'}', '{', SEARCH_BACKWARD},
11594 - {'(', ')', SEARCH_FORWARD},
11595 - {')', '(', SEARCH_BACKWARD},
11596 - {'[', ']', SEARCH_FORWARD},
11597 - {']', '[', SEARCH_BACKWARD},
11598 - {'<', '>', SEARCH_FORWARD},
11599 - {'>', '<', SEARCH_BACKWARD},
11600 - {'/', '/', SEARCH_FORWARD},
11601 - {'"', '"', SEARCH_FORWARD},
11602 - {'\'', '\'', SEARCH_FORWARD},
11603 - {'`', '`', SEARCH_FORWARD},
11604 - {'\\', '\\', SEARCH_FORWARD},
11608 ** Definitions for the search method strings, used as arguments for
11609 ** macro search subroutines and search action routines
11611 static char *searchTypeStrings[] = {
11612 @@ -3336,22 +3317,22 @@ static void iSearchTextKeyEH(Widget w, W
11613 XmTextSetInsertionPosition(window->iSearchText,
11614 XmTextGetLastPosition(window->iSearchText));
11618 -** Check the character before the insertion cursor of textW and flash
11619 -** matching parenthesis, brackets, or braces, by temporarily highlighting
11620 -** the matching character (a timer procedure is scheduled for removing the
11622 +** Check the characters before the insertion cursor of textW and flash
11623 +** matching patterns (parenthesis e.g. brackets, braces ..) by temporarily
11624 +** highlighting matching characters (a timer procedure is scheduled for
11625 +** removing the highlights)
11627 void FlashMatching(WindowInfo *window, Widget textW)
11631 - int pos, matchIndex;
11632 - int startPos, endPos, searchPos, matchPos;
11635 + int startPos, endPos, matchPos, matchLen;
11637 + MatchingType matchingType;
11639 /* if a marker is already drawn, erase it and cancel the timeout */
11640 if (window->flashTimeoutID != 0) {
11641 eraseFlash(window);
11642 XtRemoveTimeOut(window->flashTimeoutID);
11643 @@ -3365,52 +3346,47 @@ void FlashMatching(WindowInfo *window, W
11645 /* don't flash matching characters if there's a selection */
11646 if (window->buffer->primary.selected)
11649 - /* get the character to match and the position to start from */
11650 - pos = TextGetCursorPos(textW) - 1;
11651 + /* get the position to start from */
11652 + pos = TextGetCursorPos(textW);
11655 - c = BufGetCharacter(window->buffer, pos);
11656 - style = GetHighlightInfo(window, pos);
11658 - /* is the character one we want to flash? */
11659 - for (matchIndex = 0; matchIndex<N_FLASH_CHARS; matchIndex++) {
11660 - if (MatchingChars[matchIndex].c == c)
11663 - if (matchIndex == N_FLASH_CHARS)
11666 /* constrain the search to visible text only when in single-pane mode
11667 AND using delimiter flashing (otherwise search the whole buffer) */
11668 constrain = ((window->nPanes == 0) &&
11669 (window->showMatchingStyle == FLASH_DELIMIT));
11671 - if (MatchingChars[matchIndex].direction == SEARCH_BACKWARD) {
11672 startPos = constrain ? TextFirstVisiblePos(textW) : 0;
11674 - searchPos = endPos;
11677 endPos = constrain ? TextLastVisiblePos(textW) :
11678 window->buffer->length;
11679 - searchPos = startPos;
11681 + /* cursor pos. must be between start / end pos. */
11682 + if (pos < startPos || pos > endPos)
11685 + /* Pattern Match Feature: determine matching type
11686 + (here: flash delimiter or range) */
11687 + if (window->showMatchingStyle == FLASH_DELIMIT) {
11688 + matchingType = MT_FLASH_DELIMIT;
11690 + matchingType = MT_FLASH_RANGE;
11693 - /* do the search */
11694 - if (!findMatchingChar(window, c, style, searchPos, startPos, endPos,
11696 + /* Pattern Match Feature: do the search */
11697 + if (!FindMatchingString(window, matchingType, &pos, startPos, endPos,
11698 + &matchPos, &matchLen, &direction))
11701 if (window->showMatchingStyle == FLASH_DELIMIT) {
11702 - /* Highlight either the matching character ... */
11703 - BufHighlight(window->buffer, matchPos, matchPos+1);
11704 + /* Highlight either the matching characters ... */
11705 + BufHighlight(window->buffer, matchPos, matchPos + matchLen);
11707 /* ... or the whole range. */
11708 - if (MatchingChars[matchIndex].direction == SEARCH_BACKWARD) {
11709 + if (direction == SEARCH_BACKWARD) {
11710 BufHighlight(window->buffer, matchPos, pos+1);
11712 BufHighlight(window->buffer, matchPos+1, pos);
11715 @@ -3420,159 +3396,86 @@ void FlashMatching(WindowInfo *window, W
11716 XtWidgetToApplicationContext(window->shell), 1500,
11717 flashTimeoutProc, window);
11718 window->flashPos = matchPos;
11721 -void SelectToMatchingCharacter(WindowInfo *window)
11723 +** Pattern Match Feature:
11724 +** get position of the character to match from the selection, or
11725 +** the character before the insert point if nothing is selected.
11728 +static int getPosForMatchingCharacter(WindowInfo *window)
11731 int selStart, selEnd;
11732 - int startPos, endPos, matchPos;
11733 textBuffer *buf = window->buffer;
11735 - /* get the character to match and its position from the selection, or
11736 - the character before the insert point if nothing is selected.
11737 - Give up if too many characters are selected */
11738 - if (!GetSimpleSelection(buf, &selStart, &selEnd)) {
11739 - selEnd = TextGetCursorPos(window->lastFocus);
11740 - if (window->overstrike)
11742 - selStart = selEnd - 1;
11743 - if (selStart < 0) {
11744 - XBell(TheDisplay, 0);
11747 + if (GetSimpleSelection(buf, &selStart, &selEnd)) {
11750 - if ((selEnd - selStart) != 1) {
11751 - XBell(TheDisplay, 0);
11754 + pos = TextGetCursorPos(window->lastFocus);
11761 +void SelectToMatchingCharacter(WindowInfo *window)
11764 + int startPos, endPos, matchPos, matchLen;
11766 + textBuffer *buf = window->buffer;
11768 + /* Pattern Match Feature: get position of the character to match */
11769 + pos = getPosForMatchingCharacter( window );
11771 /* Search for it in the buffer */
11772 - if (!findMatchingChar(window, BufGetCharacter(buf, selStart),
11773 - GetHighlightInfo(window, selStart), selStart, 0, buf->length, &matchPos)) {
11774 + if (!FindMatchingString(window, MT_SELECT, &pos, 0,
11775 + buf->length, &matchPos, &matchLen, &direction)) {
11776 XBell(TheDisplay, 0);
11779 - startPos = (matchPos > selStart) ? selStart : matchPos;
11780 - endPos = (matchPos > selStart) ? matchPos : selStart;
11781 + startPos = (matchPos > pos) ? pos : matchPos;
11782 + endPos = (matchPos > pos) ? matchPos : pos;
11784 /* select the text between the matching characters */
11785 XtVaSetValues(window->lastFocus, textNautoShowInsertPos, False, NULL);
11786 BufSelect(buf, startPos, endPos+1);
11787 MakeSelectionVisible(window, window->lastFocus);
11788 XtVaSetValues(window->lastFocus, textNautoShowInsertPos, True, NULL);
11791 void GotoMatchingCharacter(WindowInfo *window)
11793 - int selStart, selEnd;
11796 + int matchPos, matchLen;
11798 textBuffer *buf = window->buffer;
11800 - /* get the character to match and its position from the selection, or
11801 - the character before the insert point if nothing is selected.
11802 - Give up if too many characters are selected */
11803 - if (!GetSimpleSelection(buf, &selStart, &selEnd)) {
11804 - selEnd = TextGetCursorPos(window->lastFocus);
11805 - if (window->overstrike)
11807 - selStart = selEnd - 1;
11808 - if (selStart < 0) {
11809 - XBell(TheDisplay, 0);
11813 - if ((selEnd - selStart) != 1) {
11814 - XBell(TheDisplay, 0);
11817 + /* Pattern Match Feature: get position of the character to match */
11818 + pos = getPosForMatchingCharacter( window );
11820 /* Search for it in the buffer */
11821 - if (!findMatchingChar(window, BufGetCharacter(buf, selStart),
11822 - GetHighlightInfo(window, selStart), selStart, 0,
11823 - buf->length, &matchPos)) {
11824 + if (!FindMatchingString(window, MT_GOTO, &pos, 0,
11825 + buf->length, &matchPos, &matchLen, &direction)) {
11826 XBell(TheDisplay, 0);
11830 /* temporarily shut off autoShowInsertPos before setting the cursor
11831 position so MakeSelectionVisible gets a chance to place the cursor
11832 string at a pleasing position on the screen (otherwise, the cursor would
11833 be automatically scrolled on screen and MakeSelectionVisible would do
11835 XtVaSetValues(window->lastFocus, textNautoShowInsertPos, False, NULL);
11836 - TextSetCursorPos(window->lastFocus, matchPos+1);
11837 + TextSetCursorPos(window->lastFocus, matchPos);
11838 MakeSelectionVisible(window, window->lastFocus);
11839 XtVaSetValues(window->lastFocus, textNautoShowInsertPos, True, NULL);
11842 -static int findMatchingChar(WindowInfo *window, char toMatch,
11843 - void* styleToMatch, int charPos, int startLimit, int endLimit,
11846 - int nestDepth, matchIndex, direction, beginPos, pos;
11847 - char matchChar, c;
11848 - void *style = NULL;
11849 - textBuffer *buf = window->buffer;
11850 - int matchSyntaxBased = window->matchSyntaxBased;
11852 - /* If we don't match syntax based, fake a matching style. */
11853 - if (!matchSyntaxBased) style = styleToMatch;
11855 - /* Look up the matching character and match direction */
11856 - for (matchIndex = 0; matchIndex<N_MATCH_CHARS; matchIndex++) {
11857 - if (MatchingChars[matchIndex].c == toMatch)
11860 - if (matchIndex == N_MATCH_CHARS)
11862 - matchChar = MatchingChars[matchIndex].match;
11863 - direction = MatchingChars[matchIndex].direction;
11865 - /* find it in the buffer */
11866 - beginPos = (direction==SEARCH_FORWARD) ? charPos+1 : charPos-1;
11868 - if (direction == SEARCH_FORWARD) {
11869 - for (pos=beginPos; pos<endLimit; pos++) {
11870 - c=BufGetCharacter(buf, pos);
11871 - if (c == matchChar) {
11872 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11873 - if (style == styleToMatch) {
11875 - if (nestDepth == 0) {
11880 - } else if (c == toMatch) {
11881 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11882 - if (style == styleToMatch)
11886 - } else { /* SEARCH_BACKWARD */
11887 - for (pos=beginPos; pos>=startLimit; pos--) {
11888 - c=BufGetCharacter(buf, pos);
11889 - if (c == matchChar) {
11890 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11891 - if (style == styleToMatch) {
11893 - if (nestDepth == 0) {
11898 - } else if (c == toMatch) {
11899 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11900 - if (style == styleToMatch)
11909 ** Xt timer procedure for erasing the matching parenthesis marker.
11911 static void flashTimeoutProc(XtPointer clientData, XtIntervalId *id)
11913 diff --quilt old/source/smartIndent.c new/source/smartIndent.c
11914 --- old/source/smartIndent.c
11915 +++ new/source/smartIndent.c
11916 @@ -978,13 +978,13 @@ void EditSmartIndentMacros(WindowInfo *w
11917 XmNleftPosition, 1,
11918 XmNtopAttachment, XmATTACH_POSITION,
11920 XmNrightAttachment, XmATTACH_POSITION,
11921 XmNrightPosition, 99, NULL);
11923 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
11924 SmartIndentDialog.lmPulldown = CreateLanguageModeMenu(lmForm, langModeCB,
11928 XtSetArg(args[n], XmNspacing, 0); n++;
11929 XtSetArg(args[n], XmNmarginWidth, 0); n++;
11930 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
11931 XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
11932 @@ -2150,12 +2150,13 @@ void UpdateLangModeMenuSmartIndent(void)
11934 if (SmartIndentDialog.shell == NULL)
11937 oldMenu = SmartIndentDialog.lmPulldown;
11938 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
11939 SmartIndentDialog.lmPulldown = CreateLanguageModeMenu(
11940 - XtParent(XtParent(oldMenu)), langModeCB, NULL);
11941 + XtParent(XtParent(oldMenu)), langModeCB, NULL, FALSE);
11942 XtVaSetValues(XmOptionButtonGadget(SmartIndentDialog.lmOptMenu),
11943 XmNsubMenuId, SmartIndentDialog.lmPulldown, NULL);
11944 SetLangModeMenu(SmartIndentDialog.lmOptMenu, SmartIndentDialog.langModeName);
11946 XtDestroyWidget(oldMenu);
11947 diff --quilt old/source/window.c new/source/window.c
11948 --- old/source/window.c
11949 +++ new/source/window.c
11950 @@ -53,10 +53,11 @@ static const char CVSID[] = "$Id: window
11951 #include "nedit.bm"
11953 #include "windowTitle.h"
11954 #include "interpret.h"
11955 #include "rangeset.h"
11956 +#include "patternMatchData.h"
11957 #include "../util/clearcase.h"
11958 #include "../util/misc.h"
11959 #include "../util/fileUtils.h"
11960 #include "../util/utils.h"
11961 #include "../util/fileUtils.h"
11962 @@ -272,11 +273,10 @@ WindowInfo *CreateWindow(const char *nam
11963 window->saveOldVersion = GetPrefSaveOldVersion();
11964 window->wrapMode = GetPrefWrap(PLAIN_LANGUAGE_MODE);
11965 window->showWrapMargin = GetPrefShowWrapMargin();
11966 window->overstrike = False;
11967 window->showMatchingStyle = GetPrefShowMatching();
11968 - window->matchSyntaxBased = GetPrefMatchSyntaxBased();
11969 window->showStats = GetPrefStatsLine();
11970 window->showISearchLine = GetPrefISearchLine();
11971 window->showLineNumbers = GetPrefLineNums();
11972 window->highlightSyntax = GetPrefHighlightSyntax();
11973 window->backlightCharTypes = NULL;
11974 @@ -311,10 +311,14 @@ WindowInfo *CreateWindow(const char *nam
11975 window->highlightData = NULL;
11976 window->shellCmdData = NULL;
11977 window->macroCmdData = NULL;
11978 window->smartIndentData = NULL;
11979 window->languageMode = PLAIN_LANGUAGE_MODE;
11981 + /* Pattern Match Feature: assign "PLAIN" string match table*/
11982 + window->stringMatchTable = FindStringMatchTable(NULL);
11984 window->iSearchHistIndex = 0;
11985 window->iSearchStartPos = -1;
11986 window->replaceLastRegexCase = TRUE;
11987 window->replaceLastLiteralCase = FALSE;
11988 window->iSearchLastRegexCase = TRUE;
11989 @@ -3430,11 +3434,10 @@ WindowInfo* CreateDocument(WindowInfo* s
11990 window->saveOldVersion = GetPrefSaveOldVersion();
11991 window->wrapMode = GetPrefWrap(PLAIN_LANGUAGE_MODE);
11992 window->showWrapMargin = GetPrefShowWrapMargin();
11993 window->overstrike = False;
11994 window->showMatchingStyle = GetPrefShowMatching();
11995 - window->matchSyntaxBased = GetPrefMatchSyntaxBased();
11996 window->highlightSyntax = GetPrefHighlightSyntax();
11997 window->backlightCharTypes = NULL;
11998 window->backlightChars = GetPrefBacklightChars();
11999 if (window->backlightChars) {
12000 char *cTypes = GetPrefBacklightCharTypes();
12001 @@ -3465,10 +3468,16 @@ WindowInfo* CreateDocument(WindowInfo* s
12002 window->highlightData = NULL;
12003 window->shellCmdData = NULL;
12004 window->macroCmdData = NULL;
12005 window->smartIndentData = NULL;
12006 window->languageMode = PLAIN_LANGUAGE_MODE;
12009 + * Pattern Match Feature:
12011 + window->stringMatchTable = FindStringMatchTable(NULL);
12013 window->iSearchHistIndex = 0;
12014 window->iSearchStartPos = -1;
12015 window->replaceLastRegexCase = TRUE;
12016 window->replaceLastLiteralCase = FALSE;
12017 window->iSearchLastRegexCase = TRUE;
12018 @@ -3862,11 +3871,10 @@ void RefreshMenuToggleStates(WindowInfo
12020 XmToggleButtonSetState(window->saveLastItem, window->saveOldVersion, False);
12022 XmToggleButtonSetState(window->autoSaveItem, window->autoSave, False);
12023 XmToggleButtonSetState(window->overtypeModeItem, window->overstrike, False);
12024 - XmToggleButtonSetState(window->matchSyntaxBasedItem, window->matchSyntaxBased, False);
12025 XmToggleButtonSetState(window->readOnlyItem, IS_USER_LOCKED(window->lockReasons), False);
12026 XmToggleButtonSetState(window->transientItem, window->transient, False);
12028 XtSetSensitive(window->smartIndentItem,
12029 SmartIndentMacrosAvailable(LanguageModeName(window->languageMode)));
12030 @@ -4426,10 +4434,13 @@ static void cloneDocument(WindowInfo *wi
12031 window->languageMode = orgWin->languageMode;
12032 window->highlightSyntax = orgWin->highlightSyntax;
12033 if (window->highlightSyntax)
12034 StartHighlighting(window, False);
12036 + /* recycle the pattern match data */
12037 + window->stringMatchTable = orgWin->stringMatchTable;
12039 /* copy states of original document */
12040 window->filenameSet = orgWin->filenameSet;
12041 window->fileFormat = orgWin->fileFormat;
12042 window->lastModTime = orgWin->lastModTime;
12043 window->fileChanged = orgWin->fileChanged;
12044 @@ -4444,11 +4455,10 @@ static void cloneDocument(WindowInfo *wi
12045 window->autoSave = orgWin->autoSave;
12046 window->saveOldVersion = orgWin->saveOldVersion;
12047 window->wrapMode = orgWin->wrapMode;
12048 SetOverstrike(window, orgWin->overstrike);
12049 window->showMatchingStyle = orgWin->showMatchingStyle;
12050 - window->matchSyntaxBased = orgWin->matchSyntaxBased;
12052 window->showStats = orgWin->showStats;
12053 window->showISearchLine = orgWin->showISearchLine;
12054 window->showLineNumbers = orgWin->showLineNumbers;
12055 window->modeMessageDisplayed = orgWin->modeMessageDisplayed;