fix syntax error
[nedit-bw.git] / matching_patterns.patch
blob330765b5c8d7432c98b4aaa0f3483cd1bb76cdd2
1 ---
4 ---
6 doc/help.etx | 258 +
7 source/Makefile.common | 6
8 source/Makefile.dependencies | 11
9 source/highlightData.c | 13
10 source/macro.c | 107
11 source/menu.c | 63
12 source/nedit.h | 6
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
21 source/window.c | 18
22 16 files changed, 10773 insertions(+), 297 deletions(-)
24 diff --quilt old/doc/help.etx new/doc/help.etx
25 --- old/doc/help.etx
26 +++ 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
37 + discussed below:
39 3>Language Modes
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,
67 - for instance.
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 ----------------------------------------------------------------------
80 +Matching Parentheses
81 +--------------------
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
91 + '\</.*\>').
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,
106 + for instance.
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
120 **$show_matching**
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.
127 **$statistics_line**
128 Has a value of 1 if the statistics line is shown, otherwise 0.
130 **$sub_sep**
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
149 window.
151 **get_selection()**
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.
176 **Overtype**
177 In overtype mode, new characters entered replace the characters in front of
178 the insertion cursor, rather than being inserted before them.
180 **Read Only**
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 ----------------------------------------------------------------------
187 +Matching Patterns
188 +-----------------
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
217 + Pattern Name".
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
227 + entry:
229 +* "Individual" or
230 +* "Sub-pattern" or
231 +* "Context group"
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
242 + search.
244 + In fact, "Individual" matching pattern search is faster than "Context group" /
245 + "Sub-pattern" search. "Context group" / "Sub-pattern" search results in fewer
246 + false matches.
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"
257 +* "Syntax based"
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
268 + applicable ...
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
273 + false matches.
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
285 + pattern.
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:
310 +! +-----<-----+
311 +! +--> start -+-> middle -+-> end --+
312 +! +-----------<---------------------+
314 +4>String pattern
316 + A string pattern holds three attributes:
318 +* "String Pattern Type"
319 +* "Word Boundary"
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":
332 +* "Case Sensitive"
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.
366 NEdit Command Line
367 ------------------
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
398 @@ -5,11 +5,12 @@
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
411 .c.o:
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)
424 clean:
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 \
434 ../util/clearcase.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
463 XmNtopPosition, 1,
464 XmNrightAttachment, XmATTACH_POSITION,
465 XmNrightPosition, 99,
466 NULL);
468 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
469 HighlightDialog.lmPulldown = CreateLanguageModeMenu(lmForm, langModeCB,
470 - NULL);
471 + NULL, FALSE);
472 n = 0;
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)
480 return;
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);
494 if (resp == 3)
496 SetLangModeMenu(HighlightDialog.lmOptMenu,
497 HighlightDialog.langModeName);
499 + freePatternSet(newPatSet);
501 return;
503 if (resp == 1)
505 updatePatternSet();
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);
514 return;
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"
531 #include <stdio.h>
532 #include <stdlib.h>
533 #include <string.h>
534 #include <ctype.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 },
568 { "call", callMS },
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);
590 return True;
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;
598 - return True;
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.
618 +** Syntax:
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)
632 + int startPos;
633 + int matchPos, matchLen;
634 + int direction;
635 + textBuffer *buf = window->buffer;
636 + DataValue dv;
638 + /*
639 + * Perform syntax & semantic check
640 + */
641 + if (nArgs != 1 )
642 + return wrongNArgsErr(errMsg);
644 + if (!readIntArg(argList[0], &startPos, errMsg))
645 + return False;
647 + startPos ++;
649 + /*
650 + * do the search; provide default values, if search fails
651 + */
652 + if (!FindMatchingString(window, MT_MACRO, &startPos, 0, buf->length,
653 + &matchPos, &matchLen, &direction))
655 + matchPos = -1;
656 + matchLen = 0;
657 + direction = -1;
660 + /*
661 + * initialize array holding info about matching string
662 + */
663 + result->tag = ARRAY_TAG;
664 + result->val.arrayPtr = ArrayNew();
666 + /*
667 + * the following array entries will be integers
668 + */
669 + dv.tag = INT_TAG;
671 + /*
672 + * insert match position
673 + */
674 + dv.val.n = matchPos;
675 + if (!ArrayInsert(result, PERM_ALLOC_STR("pos"), &dv))
677 + M_ARRAY_INSERT_FAILURE();
680 + /*
681 + * insert length of matching pattern
682 + */
683 + dv.val.n = matchLen;
684 + if (!ArrayInsert(result, PERM_ALLOC_STR("len"), &dv))
686 + M_ARRAY_INSERT_FAILURE();
689 + /*
690 + * insert direction where the matching pattern was found
691 + */
692 + dv.val.n = direction;
693 + if (!ArrayInsert(result, PERM_ALLOC_STR("direction"), &dv))
695 + M_ARRAY_INSERT_FAILURE();
698 + return True;
701 static int wrongNArgsErr(char **errMsg)
703 *errMsg = "Wrong number of arguments to function %s";
704 return False;
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"
711 #include "shell.h"
712 #include "macro.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
749 Cardinal *nArgs);
750 static void setIncrementalBackupAP(Widget w, XEvent *event, String *args,
751 Cardinal *nArgs);
752 static void setShowMatchingAP(Widget w, XEvent *event, String *args,
753 Cardinal *nArgs);
754 -static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
755 - Cardinal *nArgs);
756 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
757 Cardinal *nArgs);
758 static void setLockedAP(Widget w, XEvent *event, String *args,
759 Cardinal *nArgs);
760 static void setTransientAP(Widget text, XEvent *event, String *args,
761 @@ -582,11 +580,10 @@ static XtActionsRec Actions[] = {
762 #ifndef VMS
763 {"set_make_backup_copy", setMakeBackupCopyAP},
764 #endif
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);
800 #ifndef SGI_CUSTOM
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);
816 -#ifdef SGI_CUSTOM
817 - if (shortPrefAskDefault(window->shell, w, "Match Syntax Based")) {
818 - matchSyntaxBasedDefCB(w, window, callData);
819 - SaveNEditPrefs(window->shell, GetPrefShortMenus());
821 -#endif
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)
842 - WindowInfo *win;
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)
861 WindowInfo *win;
862 @@ -4286,23 +4256,10 @@ static void setShowMatchingAP(Widget w,
863 else {
864 fprintf(stderr, "nedit: set_show_matching requires argument\n");
868 -static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
869 - Cardinal *nArgs)
871 - WindowInfo *window = WidgetToWindow(w);
872 - Boolean newState;
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,
882 Cardinal *nArgs)
884 WindowInfo *window = WidgetToWindow(w);
885 Boolean newState;
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;
891 Widget lineNumsItem;
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
918 FLASH_RANGE */
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 */
934 #ifdef REPLACE_SCOPE
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
940 --- /dev/null
941 +++ new/source/patternMatch.c
942 @@ -0,0 +1,2202 @@
943 +static const char CVSID[] = "$Id: patternMatch.c,v 1.4 2003/10/27 21:59:14 uleh Exp $";
944 +/*******************************************************************************
945 +* *
946 +* patternMatch.c -- Nirvana Editor pattern matching functions *
947 +* *
948 +* Copyright (C) 2003-2004, Uwe Lehnert *
949 +* *
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. *
955 +* *
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. *
960 +* *
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 *
964 +* *
965 +* Nirvana Text Editor *
966 +* October 27, 2004 *
967 +* *
968 +* Written by Uwe Lehnert *
969 +* *
970 +*******************************************************************************/
972 +#ifdef HAVE_CONFIG_H
973 +#include "../config.h"
974 +#endif
976 +#include <stdlib.h>
977 +#include <stdio.h>
978 +#include <limits.h>
979 +#include <string.h>
980 +#include <ctype.h>
982 +#ifdef VMS
983 +#include "../util/VMSparam.h"
984 +#else
985 +#ifndef __MVS__
986 +#include <sys/param.h>
987 +#endif
988 +#endif /*VMS*/
990 +#include "regularExp.h"
991 +#include "textBuf.h"
992 +#include "search.h"
993 +#include "window.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"
1002 +#endif
1004 +#define MAX_NESTED_PATTERNS 100
1006 +#define IGNORE_HIGHLIGHT_CODE -1
1008 +typedef struct _SearchRegionInfo {
1009 + WindowInfo *sriWindow;
1010 + char *sriText;
1011 + char sriPrevChar;
1012 + char sriSuccChar;
1013 + int sriStartOfTextPos;
1014 +} SearchRegionInfo;
1016 +typedef struct _FoundStringInfo {
1017 + char *fsiStartPtr;
1018 + char *fsiEndPtr;
1019 + int fsiLength;
1020 + char fsiPrevChar;
1021 + char fsiSuccChar;
1022 + const char *fsiDelimiters;
1023 +} FoundStringInfo;
1025 +typedef struct _BackRefInfo {
1026 + int briAvailable;
1027 + int briCaseInsensitive;
1028 + char *briStartPtr[MAX_GLOBAL_BACK_REF_ID];
1029 + char *briEndPtr[MAX_GLOBAL_BACK_REF_ID];
1030 +} BackRefInfo;
1032 +typedef struct _MatchingElementInfo {
1033 + MatchPatternTableElement *meiElement;
1034 + PatternReference meiPatRef;
1035 + int meiDirection;
1036 + int meiHighLightCode;
1037 + int meiAbsStartPos;
1038 + int meiLength;
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
1050 + */
1051 +void adaptPatternPositions(
1052 + MatchingType matchingType,
1053 + int direction,
1054 + int *charPos,
1055 + int startPatternLength,
1056 + int *matchPos,
1057 + int matchedPatternLength);
1059 +static int findMatchingStringElement(
1060 + StringMatchTable *smTable,
1061 + SearchRegionInfo *searchRegion,
1062 + MatchingElementInfo *matchInfo,
1063 + int *charPos,
1064 + const char *delimiters);
1066 +static PatternElementMonoInfo determineMonoPatInfo(
1067 + WindowInfo *window,
1068 + int patHighLightCode,
1069 + int leftPos,
1070 + int rightPos,
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(
1080 + char *startPtr1,
1081 + char *endPtr1,
1082 + char *startPtr2,
1083 + char *endPtr2,
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,
1117 + int groupIdx);
1119 +static int searchPatternForward(
1120 + MatchPatternTable *table,
1121 + regexp *compiledRE,
1122 + SearchRegionInfo *searchRegion,
1123 + const char *delimiters,
1124 + int beginPos,
1125 + int *matchEndPos,
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,
1134 + int beginPos,
1135 + PatternReference *patRef,
1136 + int *highLightCode,
1137 + int *matchedPatternLength,
1138 + BackRefInfo *backRefInfo);
1140 +static int parseStringElementForward(
1141 + MatchingElementInfo *matchInfo,
1142 + SearchRegionInfo *searchRegion,
1143 + int relCharPos,
1144 + int *matchPos,
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,
1154 + int beginPos,
1155 + int *matchEndPos);
1157 +static int parseStringElementBackward(
1158 + MatchingElementInfo *matchInfo,
1159 + SearchRegionInfo *searchRegion,
1160 + int relCharPos,
1161 + int *matchPos,
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,
1171 + int beginPos,
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,
1182 + int *relBeginPos,
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);
1195 +#ifdef DEBUG_FIND
1196 +static char *getPatternForDebug(
1197 + MatchPatternTable *table,
1198 + PatternReference patRef );
1199 +static char *patElemKindToString(
1200 + PatternElementKind patElemKind);
1201 +static void printFoundStringForDebug(
1202 + WindowInfo *window,
1203 + int absStartPos,
1204 + int length);
1205 +#endif
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,
1217 + int *charPos,
1218 + int startLimit,
1219 + int endLimit,
1220 + int *matchPos,
1221 + int *matchedPatternLength,
1222 + int *direction)
1224 + StringMatchTable *smTable = (StringMatchTable *)window->stringMatchTable;
1225 + const char *delimiters;
1226 + SearchRegionInfo searchRegion;
1227 + MatchingElementInfo matchInfo;
1228 + int matchingPatternFound = FALSE;
1229 + int relCharPos;
1231 + if (smTable == NULL || smTable->smtAllPatRE == NULL)
1233 + /*
1234 + * No match pattern table available:
1235 + */
1236 + return FALSE;
1239 + /*
1240 + * Get delimiters related to window
1241 + */
1242 + delimiters = GetWindowDelimiters(window);
1243 + if (delimiters == NULL)
1244 + delimiters = GetPrefDelimiters();
1246 + /*
1247 + * Select the start pattern reg. exp. to use
1248 + */
1249 + if (matchingType == MT_FLASH_RANGE ||
1250 + matchingType == MT_FLASH_DELIMIT)
1252 + smTable->smtUsedPatRE = smTable->smtFlashPatRE;
1254 + else
1256 + smTable->smtUsedPatRE = smTable->smtAllPatRE;
1259 + /*
1260 + * Get a copy of the text buffer area to parse
1261 + */
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;
1270 + /*
1271 + * Try to find a matching pattern string using string match table
1272 + * of window
1273 + */
1274 + if (findMatchingStringElement(
1275 + smTable,
1276 + &searchRegion,
1277 + &matchInfo,
1278 + &relCharPos,
1279 + delimiters ))
1281 +#ifdef DEBUG_FIND
1282 + printf("--- Start at : ");
1283 + printFoundStringForDebug(
1284 + window,
1285 + matchInfo.meiAbsStartPos,
1286 + matchInfo.meiLength);
1287 + printf(" ---\n");
1288 +#endif
1289 + if (matchInfo.meiDirection == SEARCH_FORWARD)
1291 + matchingPatternFound =
1292 + parseStringElementForward(
1293 + &matchInfo,
1294 + &searchRegion,
1295 + relCharPos,
1296 + matchPos,
1297 + matchedPatternLength,
1298 + delimiters );
1300 + else
1302 + matchingPatternFound =
1303 + parseStringElementBackward(
1304 + &matchInfo,
1305 + &searchRegion,
1306 + relCharPos,
1307 + matchPos,
1308 + matchedPatternLength,
1309 + delimiters );
1312 + if (matchingPatternFound)
1314 + /*
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.
1318 + */
1319 + *charPos = relCharPos + startLimit;
1320 + *direction = matchInfo.meiDirection;
1322 + adaptPatternPositions(
1323 + matchingType,
1324 + matchInfo.meiDirection,
1325 + charPos,
1326 + matchInfo.meiLength,
1327 + matchPos,
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,
1343 + int direction,
1344 + int *charPos,
1345 + int startPatternLength,
1346 + int *matchPos,
1347 + int matchedPatternLength)
1349 + switch (matchingType)
1351 + case MT_FLASH_DELIMIT:
1352 + case MT_MACRO:
1353 + if (direction == SEARCH_FORWARD)
1355 + (*matchPos) -= matchedPatternLength - 1;
1357 + break;
1359 + case MT_FLASH_RANGE:
1360 + case MT_SELECT:
1361 + if (direction == SEARCH_FORWARD)
1363 + (*charPos) -= startPatternLength;
1365 + else
1367 + (*charPos) --;
1369 + break;
1371 + case MT_GOTO:
1372 + if (direction == SEARCH_FORWARD)
1374 + (*matchPos) ++;
1376 + else
1378 + (*matchPos) += matchedPatternLength;
1380 + break;
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,
1396 + int *charPos,
1397 + const char *delimiters)
1399 + if (getPatternLocatedAtPos(
1400 + smTable->smtUsedPatRE,
1401 + smTable->smtAllPatterns,
1402 + searchRegion,
1403 + charPos,
1404 + matchInfo,
1405 + delimiters))
1407 + /*
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
1412 + * direction
1413 + */
1414 + if (matchInfo->meiPatRef.prKind == PEK_END)
1415 + matchInfo->meiDirection = SEARCH_BACKWARD;
1416 + else
1417 + matchInfo->meiDirection = SEARCH_FORWARD;
1419 + return TRUE;
1422 + return FALSE;
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,
1433 + int leftPos,
1434 + int rightPos,
1435 + PatternElementKind *patElementKind)
1437 + int leftSideHasSameHC;
1438 + int rightSideHasSameHC;
1440 + /*
1441 + * Determine, if left side holds same highlight code than
1442 + * found string pattern
1443 + */
1444 + if (leftPos >= 0)
1445 + leftSideHasSameHC =
1446 + (HighlightCodeOfPos(window, leftPos) == patHighLightCode);
1447 + else
1448 + leftSideHasSameHC = FALSE;
1450 + /*
1451 + * Determine, if right side holds same highlight code than
1452 + * found string pattern
1453 + */
1454 + if (rightPos < window->buffer->length)
1455 + rightSideHasSameHC =
1456 + (HighlightCodeOfPos(window, rightPos) == patHighLightCode);
1457 + else
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;
1470 + else
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)
1485 + int i;
1486 + int localId;
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];
1503 + else
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)
1519 + int i;
1521 + /*
1522 + * if min. one string pattern doesn't hold backref info, then nothing
1523 + * could be compared -> both string pattern are matching.
1524 + */
1525 + if (!backRefInfo1->briAvailable || !backRefInfo2->briAvailable)
1526 + return TRUE;
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))
1537 + return FALSE;
1541 + return TRUE;
1545 +** Compares two backref content.
1546 +** Returns true, if backref contents match.
1548 +static int compareBackRef(
1549 + char *startPtr1,
1550 + char *endPtr1,
1551 + char *startPtr2,
1552 + char *endPtr2,
1553 + int caseInsensitive)
1555 + char *s1;
1556 + char *s2;
1558 + if (startPtr1 == NULL && startPtr2 == NULL)
1559 + return TRUE;
1561 + if (startPtr1 == NULL || startPtr2 == NULL)
1562 + return FALSE;
1564 + if ((endPtr1 - startPtr1) != (endPtr2 - startPtr2))
1565 + return FALSE;
1567 + s1 = startPtr1;
1568 + s2 = startPtr2;
1570 + if (caseInsensitive)
1572 + while (s1 != endPtr1)
1574 + if (tolower((unsigned char)*s1++) != tolower((unsigned char)*s2++))
1575 + return FALSE;
1578 + else
1580 + while (s1 != endPtr1)
1582 + if (*s1++ != *s2++)
1583 + return FALSE;
1586 + return TRUE;
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)
1600 + char *s;
1601 + char *p;
1602 + StringPattern *strPat;
1603 + int elementMatch;
1605 + switch (patElement->peType)
1607 + case PET_SINGLE:
1608 + strPat = &patElement->peVal.peuSingle;
1609 + break;
1610 + case PET_MULTIPLE:
1611 + strPat = &patElement->peVal.peuMulti.mpStringPattern;
1612 + break;
1613 + default:
1614 + return FALSE;
1617 + if (strPat->spRegularExpression)
1619 + /*
1620 + * check reg. expression:
1621 + */
1622 + elementMatch =
1623 + ExecRE(
1624 + strPat->spTextRE,
1625 + foundStringInfo->fsiStartPtr,
1626 + foundStringInfo->fsiEndPtr,
1627 + FALSE,
1628 + foundStringInfo->fsiPrevChar,
1629 + foundStringInfo->fsiSuccChar,
1630 + foundStringInfo->fsiDelimiters,
1631 + NULL,
1632 + NULL);
1634 + if (elementMatch)
1635 + assignBackRefInfo(strPat, backRefInfo);
1637 + return elementMatch;
1639 + else
1641 + backRefInfo->briAvailable = FALSE;
1643 + /*
1644 + * check literal string:
1645 + */
1646 + p = strPat->spText;
1648 + /*
1649 + * if length of found string is different from length of
1650 + * given string pattern, then there is no match.
1651 + */
1652 + if (strPat->spLength != foundStringInfo->fsiLength)
1653 + return FALSE;
1655 + s = foundStringInfo->fsiStartPtr;
1657 + if (strPat->spCaseInsensitive)
1659 + while (s != foundStringInfo->fsiEndPtr)
1661 + if (tolower((unsigned char)*s++) != *p++)
1662 + return FALSE;
1665 + else
1667 + while (s != foundStringInfo->fsiEndPtr)
1669 + if (*s++ != *p++)
1670 + return FALSE;
1675 + return TRUE;
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)
1690 + int i;
1692 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
1694 + if (doesPatternElementMatch(
1695 + element->mpteAll.pesPattern[i],
1696 + foundStringInfo,
1697 + backRefInfo))
1699 + *patternElementKind = element->mpteAll.pesPattern[i]->peKind;
1700 + *patternElementIdx = i;
1702 + return TRUE;
1706 + return FALSE;
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)
1721 + int i;
1723 + for (i=0; i<table->mptNumberOfElements; i++)
1725 + if (doesMPTableElementMatch(
1726 + table->mptElements[i],
1727 + foundStringInfo,
1728 + &patRef->prKind,
1729 + &patRef->prPatternIdx,
1730 + backRefInfo))
1732 + patRef->prElementIdx = i;
1734 + return TRUE;
1738 + /*
1739 + * Should never been reached !
1740 + */
1741 + patRef->prElementIdx = NO_ELEMENT_IDX;
1742 + patRef->prKind = PEK_UNKNOWN;
1743 + patRef->prPatternIdx = NO_PATTERN_IDX;
1745 + return FALSE;
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)
1763 + return TRUE;
1765 + if (patElementKind == PEK_START)
1767 + if (isPartOfPatternElementSet(&parent->mpteStart, childElementIdx))
1768 + return TRUE;
1770 + return( isPartOfPatternElementSet(&child->mpteStart, parentElementIdx) );
1772 + else if (patElementKind == PEK_END)
1774 + if (isPartOfPatternElementSet(&parent->mpteEnd, childElementIdx))
1775 + return TRUE;
1777 + return( isPartOfPatternElementSet(&child->mpteEnd, parentElementIdx) );
1779 + else
1781 + /*
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
1784 + */
1785 + if (isPartOfMiddlePatternElementSet(&parent->mpteMiddle, childElementIdx))
1786 + return TRUE;
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;
1801 + int i;
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)
1811 + return TRUE;
1816 + return FALSE;
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.
1824 + */
1825 +static int isPartOfMiddlePatternElementSet(
1826 + PatternElementSet *patElementSet,
1827 + int patternElementIdx)
1829 + PatternElement *patElement;
1830 + int i;
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)
1841 + return TRUE;
1846 + return FALSE;
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,
1857 + int groupIdx)
1859 + MatchPatternTableElement *tabElement;
1860 + PatternElement *startPat;
1861 + MultiPattern *multiStartPat;
1862 + PatternReference patRef;
1863 + int i;
1865 + /*
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).
1869 + */
1870 + if (startPatRef->prElementIdx == nxtPatRef.prElementIdx)
1871 + return;
1873 + /*
1874 + * Verify, if start pattern belongs to multiple pattern elements
1875 + * (like "ELSE .. FI" & "ELSE .. ESAC").
1876 + */
1877 + startPat = getPatternOfReference( table, *startPatRef );
1879 + if (startPat->peType == PET_MULTIPLE)
1881 + /*
1882 + * Check, if next pattern fits to one of the references of
1883 + * the start multi pattern. If so: adapt start pattern reference.
1884 + */
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;
1896 + return;
1903 +** Search for a string pattern in forward direction, starting at
1904 +** given beginPos. Determine related pattern reference of a found
1905 +** string pattern.
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,
1913 + int beginPos,
1914 + int *matchEndPos,
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;
1932 + if (ExecRE(
1933 + compiledRE,
1934 + searchRegion->sriText + beginPos,
1935 + NULL,
1936 + FALSE,
1937 + beginPos==0 ? searchRegion->sriPrevChar : searchRegion->sriText[beginPos-1],
1938 + searchRegion->sriSuccChar,
1939 + delimiters,
1940 + searchRegion->sriText,
1941 + NULL))
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(
1959 + table,
1960 + &foundStringInfo,
1961 + patRef,
1962 + backRefInfo))
1964 + /*
1965 + * Next string pattern was found in forward direction and
1966 + * a pattern reference could be assigned to: calculate
1967 + * relative & absolute match positions.
1968 + */
1969 + matchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
1970 + *matchEndPos = foundStringInfo.fsiEndPtr - searchRegion->sriText;
1972 + absMatchStartPos = matchStartPos + searchRegion->sriStartOfTextPos;
1974 + matchedElement = table->mptElements[patRef->prElementIdx];
1976 + /*
1977 + * get highlight code of found string pattern, if applicable
1978 + */
1979 + if (!matchedElement->mpteIgnoreHighLightInfo)
1981 + *highLightCode =
1982 + HighlightCodeOfPos(searchRegion->sriWindow, absMatchStartPos);
1985 + /*
1986 + * setup mono pattern info of found string pattern
1987 + */
1988 + if (matchedElement->mpteIsMonoPattern)
1990 + if (matchedElement->mpteIgnoreHighLightInfo)
1992 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
1994 + else
1996 + /*
1997 + * determine mono pattern info depending on highLightCodes
1998 + * before / after found string pattern.
1999 + */
2000 + patRef->prMonoInfo =
2001 + determineMonoPatInfo(
2002 + searchRegion->sriWindow,
2003 + *highLightCode,
2004 + absMatchStartPos - 1,
2005 + *matchEndPos + searchRegion->sriStartOfTextPos,
2006 + &patRef->prKind);
2009 + else
2011 + patRef->prMonoInfo = PEMI_NOT_MONO;
2014 + return matchStartPos;
2016 + else
2018 + /*
2019 + * Found string can't be assigned to a pattern element
2020 + * (should never occur).
2021 + */
2022 + return -1;
2025 + else
2027 + /*
2028 + * No next string pattern is found in forward direction.
2029 + */
2030 + return -1;
2035 +** Search for a string pattern in backward direction, starting at
2036 +** given beginPos. Determine related pattern reference of a found
2037 +** string pattern.
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,
2045 + int beginPos,
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;
2062 + if (ExecRE(
2063 + compiledRE,
2064 + searchRegion->sriText,
2065 + searchRegion->sriText + beginPos,
2066 + TRUE,
2067 + searchRegion->sriPrevChar,
2068 + searchRegion->sriText[beginPos] == '\0' ?
2069 + searchRegion->sriSuccChar : searchRegion->sriText[beginPos + 1],
2070 + delimiters,
2071 + searchRegion->sriText,
2072 + NULL))
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(
2090 + table,
2091 + &foundStringInfo,
2092 + patRef,
2093 + backRefInfo))
2095 + /*
2096 + * Next string pattern was found in backward direction and
2097 + * a pattern reference could be assigned to: calculate
2098 + * relative & absolute match positions.
2099 + */
2100 + matchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
2101 + *matchedPatternLength = foundStringInfo.fsiLength;
2103 + absMatchStartPos = matchStartPos + searchRegion->sriStartOfTextPos;
2105 + matchedElement = table->mptElements[patRef->prElementIdx];
2107 + /*
2108 + * get highlight code of found string pattern, if applicable
2109 + */
2110 + if (!matchedElement->mpteIgnoreHighLightInfo)
2112 + *highLightCode =
2113 + HighlightCodeOfPos(searchRegion->sriWindow, absMatchStartPos);
2116 + /*
2117 + * setup mono pattern info of found string pattern
2118 + */
2119 + if (matchedElement->mpteIsMonoPattern)
2121 + if (matchedElement->mpteIgnoreHighLightInfo)
2123 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
2125 + else
2127 + /*
2128 + * determine mono pattern info depending on highLightCodes
2129 + * before / after found string pattern.
2130 + */
2131 + patRef->prMonoInfo =
2132 + determineMonoPatInfo(
2133 + searchRegion->sriWindow,
2134 + *highLightCode,
2135 + absMatchStartPos - 1,
2136 + absMatchStartPos + *matchedPatternLength,
2137 + &patRef->prKind);
2140 + else
2142 + patRef->prMonoInfo = PEMI_NOT_MONO;
2145 + return matchStartPos;
2147 + else
2149 + /*
2150 + * Found string can't be assigned to a pattern element
2151 + * (should never occur).
2152 + */
2153 + return -1;
2156 + else
2158 + /*
2159 + * No next string pattern is found in backward direction.
2160 + */
2161 + return -1;
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,
2179 + int relCharPos,
2180 + int *matchPos,
2181 + int *matchedPatternLength,
2182 + const char *delimiters)
2184 + StringMatchTable *smTable =
2185 + (StringMatchTable *)searchRegion->sriWindow->stringMatchTable;
2186 + MatchPatternTableElement *matchElement = matchInfo->meiElement;
2187 + int beginPos = relCharPos;
2188 + int endStartPos;
2189 + int startStartPos;
2190 + int endEndPos;
2191 + int matchingPatternFound = FALSE;
2193 + /*
2194 + * Find matching pattern within text buffer area to parse in
2195 + * forward direction.
2196 + */
2197 + endStartPos =
2198 + findRelatedForwardPattern(
2199 + smTable,
2200 + searchRegion,
2201 + delimiters,
2202 + matchInfo->meiPatRef,
2203 + matchInfo->meiHighLightCode,
2204 + &matchInfo->meiBackRefInfo,
2205 + beginPos,
2206 + &endEndPos);
2208 + if (endEndPos != -1)
2210 + *matchPos = endEndPos - 1 + searchRegion->sriStartOfTextPos;
2211 + *matchedPatternLength = endEndPos - endStartPos;
2213 + matchingPatternFound = TRUE;
2215 + else if (matchElement->mpteIsMonoPattern)
2217 + /*
2218 + * mono pattern: forward find fails -> try backward direction.
2219 + * Calc. relative position of 1st char. before found string pattern.
2220 + */
2221 + beginPos = beginPos - matchInfo->meiLength - 1;
2223 + if (beginPos > 0)
2225 + startStartPos =
2226 + findRelatedStartPattern(
2227 + smTable,
2228 + searchRegion,
2229 + delimiters,
2230 + matchInfo->meiPatRef,
2231 + matchInfo->meiHighLightCode,
2232 + &matchInfo->meiBackRefInfo,
2233 + beginPos,
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,
2265 + int beginPos,
2266 + int *matchEndPos)
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];
2276 + int stackIdx = 0;
2277 + PatternReference startPatRef;
2278 + MatchPatternTableElement *currentElement;
2279 + int groupIdx;
2280 + regexp *groupPatRE;
2281 + regexp *currentPatRE;
2282 + int skipToEnd = FALSE;
2283 + int beginPatternIsMono;
2285 +#ifdef DEBUG_FIND
2286 + printf("Forward Start Pos: %d K: %s EI: %d PI: %d HC: %d <%s>\n",
2287 + startPos,
2288 + patElemKindToString(beginPatRef.prKind),
2289 + beginPatRef.prElementIdx,
2290 + beginPatRef.prPatternIdx,
2291 + beginPatHighLightCode,
2292 + getPatternForDebug(patTable, beginPatRef) );
2293 +#endif
2295 + /*
2296 + * put begin pattern info on stack
2297 + */
2298 + stack[stackIdx].psePatRef = beginPatRef;
2299 + stack[stackIdx].pseHighLightCode = beginPatHighLightCode;
2300 + stack[stackIdx].pseBackRefInfo = *beginPatBackRefInfo;
2301 + stackIdx ++;
2303 + currentElement = patTable->mptElements[beginPatRef.prElementIdx];
2305 + beginPatternIsMono = currentElement->mpteIsMonoPattern;
2307 + groupIdx = currentElement->mpteGroup;
2309 + /*
2310 + * no next pattern can be found, if there is no group assigned
2311 + * to begin pattern (should never occur)
2312 + */
2313 + if (groupIdx == NO_GROUP_IDX)
2315 + *matchEndPos = -1;
2317 + return -1;
2320 + /*
2321 + * Remember pattern (= keywords) regular expression of context
2322 + * group related to begin pattern. Use it for forward search.
2323 + */
2324 + groupPatRE = table->smtGroups[groupIdx]->mpgeKeywordRE;
2325 + currentPatRE = groupPatRE;
2327 + /*
2328 + * Use start / end pattern regular expression if skip to end is
2329 + * set for begin pattern.
2330 + */
2331 + if (currentElement->mpteSkipBtwnStartEnd)
2333 + currentPatRE = currentElement->mpteStartEndRE;
2334 + skipToEnd = TRUE;
2337 + while (stackIdx > 0 && nxtPatStartPos != -1)
2339 + /*
2340 + * Search for next string pattern in forward direction.
2341 + */
2342 + nxtPatStartPos =
2343 + searchPatternForward(
2344 + patTable,
2345 + currentPatRE,
2346 + searchRegion,
2347 + delimiters,
2348 + startPos,
2349 + &nxtPatEndPos,
2350 + &nxtPatRef,
2351 + &nxtPatHighLightCode,
2352 + &nxtPatBackRefInfo );
2354 + startPatRef = stack[stackIdx-1].psePatRef;
2356 + if (nxtPatStartPos == -1)
2358 + /*
2359 + * no next pattern found -> leave loop
2360 + */
2361 +#ifdef DEBUG_FIND
2362 + printf(" SI: %d [start K: %s EI: %d PI %d] Pos: %d --> no next pat. found\n",
2363 + stackIdx,
2364 + patElemKindToString(startPatRef.prKind),
2365 + startPatRef.prElementIdx,
2366 + startPatRef.prPatternIdx,
2367 + startPos);
2368 +#endif
2369 + break;
2372 + /*
2373 + * Update start pattern reference depending on next pattern
2374 + * located after start pattern.
2375 + */
2376 + considerNextPatternReference(
2377 + patTable,
2378 + &startPatRef,
2379 + nxtPatRef,
2380 + groupIdx );
2382 + /*
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.
2386 + */
2387 + if (skipToEnd &&
2388 + (nxtPatRef.prMonoInfo == PEMI_MONO_AMBIGUOUS_SYNTAX ||
2389 + nxtPatRef.prMonoInfo == PEMI_MONO_NOT_SYNTAX_BASED))
2391 + nxtPatRef.prKind = PEK_END;
2394 +#ifdef DEBUG_FIND
2395 + printf(" SI: %d [start K: %s EI: %d PI %d] Pos: %d-%d K: %s EI: %d PI: %d HC: %d f=<%s> ",
2396 + stackIdx,
2397 + patElemKindToString(startPatRef.prKind),
2398 + startPatRef.prElementIdx,
2399 + startPatRef.prPatternIdx,
2400 + nxtPatStartPos,
2401 + nxtPatEndPos,
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);
2411 + printf("\n");
2412 +#endif
2414 + if (nxtPatRef.prKind == PEK_START)
2416 + if (stackIdx >= MAX_NESTED_PATTERNS)
2418 +#ifdef DEBUG_FIND
2419 + printf("FORWARD: MAX. NESTED PATTERN DEPTH REACHED !\n");
2420 +#endif
2421 + nxtPatStartPos = -1;
2422 + nxtPatEndPos = -1;
2424 + else if (!skipToEnd)
2426 + /*
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. \* \* ..)
2431 + */
2432 + stack[stackIdx].psePatRef = nxtPatRef;
2433 + stack[stackIdx].pseHighLightCode = nxtPatHighLightCode;
2434 + stack[stackIdx].pseBackRefInfo = nxtPatBackRefInfo;
2435 + stackIdx ++;
2437 + currentElement = patTable->mptElements[nxtPatRef.prElementIdx];
2439 + /*
2440 + * Use start / end pattern regular expression if skip to
2441 + * end is set for found start pattern.
2442 + */
2443 + if (currentElement->mpteSkipBtwnStartEnd)
2445 + currentPatRE = currentElement->mpteStartEndRE;
2446 + skipToEnd = TRUE;
2449 + else if (beginPatternIsMono)
2451 + /*
2452 + * skip to end is set and a mono pattern start is reached:
2453 + * trigger backward search by returning "not found"
2454 + */
2455 +#ifdef DEBUG_FIND
2456 + printf(" ---> mono pattern (re-)start -> trigger backward search\n");
2457 +#endif
2458 + nxtPatStartPos = -1;
2459 + nxtPatEndPos = -1;
2461 +#ifdef DEBUG_FIND
2462 + else
2464 + printf(" ---> skip to end: illegal (re-)start pattern !\n");
2466 +#endif
2468 + else if (nxtPatRef.prKind == PEK_END)
2470 + /*
2471 + * ignore current found pattern, if it doesn't fit to the prev.
2472 + * opened one.
2473 + */
2474 + if (isPartOfPattern(
2475 + patTable,
2476 + nxtPatRef.prElementIdx,
2477 + startPatRef.prElementIdx,
2478 + PEK_END) &&
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))
2486 + /*
2487 + * use context group pattern again, if end pattern to skip
2488 + * to was found.
2489 + */
2490 + if (skipToEnd)
2492 + currentPatRE = groupPatRE;
2493 + skipToEnd = FALSE;
2496 + /*
2497 + * pop. related start pattern from stack.
2498 + */
2499 + stackIdx --;
2502 + else if (!skipToEnd)
2504 + /*
2505 + * middle pattern was found: ignore it, if found middle pattern
2506 + * doesn't belong to begin pattern.
2507 + */
2508 + if (stackIdx == 1 &&
2509 + isPartOfPattern(
2510 + patTable,
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))
2522 + stackIdx --;
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
2539 +** string.
2540 +** Returns true, if a matching pattern was found.
2542 +static int parseStringElementBackward(
2543 + MatchingElementInfo *matchInfo,
2544 + SearchRegionInfo *searchRegion,
2545 + int relCharPos,
2546 + int *matchPos,
2547 + int *matchedPatternLength,
2548 + const char *delimiters)
2550 + StringMatchTable *smTable =
2551 + (StringMatchTable *)searchRegion->sriWindow->stringMatchTable;
2552 + int beginPos;
2553 + int startStartPos;
2554 + int matchingPatternFound = FALSE;
2556 + /*
2557 + * determine begin of search in string buffer (= relative position
2558 + * of 1st char. before found string pattern.)
2559 + */
2560 + beginPos = relCharPos - matchInfo->meiLength - 1;
2562 + if (beginPos < 0)
2563 + return FALSE;
2565 + /*
2566 + * Find matching pattern within text buffer area to parse in
2567 + * backward direction.
2568 + */
2569 + startStartPos =
2570 + findRelatedStartPattern(
2571 + smTable,
2572 + searchRegion,
2573 + delimiters,
2574 + matchInfo->meiPatRef,
2575 + matchInfo->meiHighLightCode,
2576 + &matchInfo->meiBackRefInfo,
2577 + beginPos,
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,
2604 + int beginPos,
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];
2614 + int stackIdx = 0;
2615 + MatchPatternTableElement *currentElement;
2616 + int groupIdx;
2617 + regexp *groupPatRE;
2618 + regexp *currentPatRE;
2619 + int skipToStart = FALSE;
2621 + /*
2622 + * put begin pattern info on stack
2623 + */
2624 + stack[stackIdx].psePatRef = beginPatRef;
2625 + stack[stackIdx].pseHighLightCode = beginPatHighLightCode;
2626 + stack[stackIdx].pseBackRefInfo = *beginPatBackRefInfo;
2627 + stackIdx ++;
2629 + currentElement = patTable->mptElements[beginPatRef.prElementIdx];
2631 +#ifdef DEBUG_FIND
2632 + printf("Backward Start Pos: %d K: %s EI: %d PI: %d HC: %d <%s>\n",
2633 + startPos,
2634 + patElemKindToString(beginPatRef.prKind),
2635 + beginPatRef.prElementIdx,
2636 + beginPatRef.prPatternIdx,
2637 + beginPatHighLightCode,
2638 + getPatternForDebug(patTable, beginPatRef) );
2639 +#endif
2641 + groupIdx = currentElement->mpteGroup;
2643 + /*
2644 + * no start pattern can be found, if there is no group assigned
2645 + * to begin pattern (should never occur)
2646 + */
2647 + if (groupIdx == NO_GROUP_IDX)
2649 + return -1;
2652 + /*
2653 + * Remember pattern (= keywords) regular expression of context
2654 + * group related to begin pattern. Use it for backward search.
2655 + */
2656 + groupPatRE = table->smtGroups[groupIdx]->mpgeKeywordRE;
2657 + currentPatRE = groupPatRE;
2659 + /*
2660 + * Use start / end pattern regular expression if skip to start is
2661 + * set for begin pattern.
2662 + */
2663 + if (currentElement->mpteSkipBtwnStartEnd)
2665 + currentPatRE = currentElement->mpteStartEndRE;
2666 + skipToStart = TRUE;
2669 + while (stackIdx > 0 && prevStartPos != -1)
2671 + /*
2672 + * Search for previous string pattern in backward direction.
2673 + */
2674 + prevStartPos =
2675 + searchPatternBackward(
2676 + patTable,
2677 + currentPatRE,
2678 + searchRegion,
2679 + delimiters,
2680 + startPos,
2681 + &prevPatRef,
2682 + &prevPatHighLightCode,
2683 + matchedPatternLength,
2684 + &prevPatBackRefInfo );
2686 + if (prevStartPos == -1)
2688 + /*
2689 + * no previous pattern found -> leave loop
2690 + */
2691 +#ifdef DEBUG_FIND
2692 + printf(" SI: %d [K: %s start EI: %d PI %d] Pos: %d --> no next pat. found\n",
2693 + stackIdx,
2694 + patElemKindToString(stack[stackIdx -1].psePatRef.prKind),
2695 + stack[stackIdx -1].psePatRef.prElementIdx,
2696 + stack[stackIdx -1].psePatRef.prPatternIdx,
2697 + startPos);
2698 +#endif
2699 + break;
2702 + /*
2703 + * Update previous pattern reference depending on last stack
2704 + * pattern, which is located in text puffer after previous
2705 + * start pattern.
2706 + */
2707 + considerNextPatternReference(
2708 + patTable,
2709 + &prevPatRef,
2710 + stack[stackIdx - 1].psePatRef,
2711 + groupIdx);
2713 + /*
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.
2717 + */
2718 + if (skipToStart &&
2719 + (prevPatRef.prMonoInfo == PEMI_MONO_AMBIGUOUS_SYNTAX ||
2720 + prevPatRef.prMonoInfo == PEMI_MONO_NOT_SYNTAX_BASED))
2722 + prevPatRef.prKind = PEK_START;
2725 +#ifdef DEBUG_FIND
2726 + printf(" SI: %d [K: %s start EI: %d PI %d] Pos: %d K: %s EI: %d PI: %d HC: %d f=<%s> ",
2727 + stackIdx,
2728 + patElemKindToString(stack[stackIdx -1].psePatRef.prKind),
2729 + stack[stackIdx -1].psePatRef.prElementIdx,
2730 + stack[stackIdx -1].psePatRef.prPatternIdx,
2731 + prevStartPos,
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);
2741 + printf("\n");
2742 +#endif
2744 + if (prevPatRef.prKind == PEK_START)
2746 + /*
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)
2750 + */
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);
2759 + /*
2760 + * Ignore current found pattern, if it doesn't fit to the prev.
2761 + * opened one.
2762 + */
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))
2771 + /*
2772 + * use context group pattern again, if start pattern
2773 + * to skip to was found.
2774 + */
2775 + if (skipToStart)
2777 + currentPatRE = groupPatRE;
2778 + skipToStart = FALSE;
2781 + /*
2782 + * pop. related end pattern from stack.
2783 + */
2784 + stackIdx --;
2787 + else if (prevPatRef.prKind == PEK_END)
2789 + if (stackIdx >= MAX_NESTED_PATTERNS)
2791 +#ifdef DEBUG_FIND
2792 + printf("BACKWARD: MAX. NESTED PATTERN DEPTH REACHED !\n");
2793 +#endif
2794 + prevStartPos = -1;
2796 + else if (!skipToStart)
2798 + /*
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. *\ *\ ..)
2803 + */
2804 + stack[stackIdx].psePatRef = prevPatRef;
2805 + stack[stackIdx].pseHighLightCode = prevPatHighLightCode;
2806 + stack[stackIdx].pseBackRefInfo = prevPatBackRefInfo;
2807 + stackIdx ++;
2809 + currentElement =
2810 + patTable->mptElements[prevPatRef.prElementIdx];
2812 + /*
2813 + * Use start / end pattern regular expression if skip to
2814 + * end is set for found end pattern.
2815 + */
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;
2840 + int i;
2842 + /*
2843 + * If found pattern index already indicates, that found pattern
2844 + * belongs to pattern set stored on stack, then no adaption is needed
2845 + */
2846 + if (*foundElementIdx == stackElementIdx)
2847 + return;
2849 + /*
2850 + * Check all elements of given pattern element set:
2851 + */
2852 + for (i=0; i < patSet->pesNumberOfPattern; i++)
2854 + patElement = patSet->pesPattern[i];
2856 + /*
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
2860 + */
2861 + if (patElement->peType == PET_REFERENCE &&
2862 + patElement->peVal.peuRef.prElementIdx == stackElementIdx)
2864 + *foundElementIdx = stackElementIdx;
2866 + return;
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,
2885 + int *relBeginPos,
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;
2903 + /*
2904 + * No backward search possible, if we are at beginning of
2905 + * search region
2906 + */
2907 + if (searchStartPos == 0)
2908 + return FALSE;
2910 + /*
2911 + * Search in backward direction for 1st occurance of a string pattern
2912 + * starting one char before "searchStartPos".
2913 + */
2914 + if (ExecRE(
2915 + usedPatRE,
2916 + searchRegion->sriText,
2917 + searchRegion->sriText + searchStartPos - 1,
2918 + TRUE,
2919 + searchRegion->sriPrevChar,
2920 + searchRegion->sriText[searchStartPos],
2921 + delimiters,
2922 + searchRegion->sriText,
2923 + NULL))
2925 + /*
2926 + * String pattern was found:
2927 + */
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;
2936 + /*
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.
2941 + */
2942 + if ((*relBeginPos == relMatchEndPos) ||
2943 + (*relBeginPos >= relMatchStartPos &&
2944 + *relBeginPos < relMatchEndPos))
2946 + *relBeginPos = relMatchEndPos;
2948 + /*
2949 + * Determine match element info related to found string.
2950 + */
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;
2966 + return(
2967 + getMatchedElementInfo(
2968 + searchRegion->sriWindow,
2969 + table,
2970 + &foundStringInfo,
2971 + matchInfo));
2975 + return FALSE;
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(
2995 + table,
2996 + foundStringInfo,
2997 + patRef,
2998 + &matchInfo->meiBackRefInfo))
3000 + /*
3001 + * A pattern reference could be assigned to found string:
3002 + */
3003 + matchedElement = table->mptElements[patRef->prElementIdx];
3005 + matchInfo->meiElement = matchedElement;
3007 + /*
3008 + * get highlight code of found string pattern, if applicable
3009 + */
3010 + if (!matchedElement->mpteIgnoreHighLightInfo)
3012 + matchInfo->meiHighLightCode =
3013 + HighlightCodeOfPos(window, absMatchStartPos);
3016 + /*
3017 + * setup mono pattern info of found string pattern
3018 + */
3019 + if (matchedElement->mpteIsMonoPattern)
3021 + if (matchedElement->mpteIgnoreHighLightInfo)
3023 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
3025 + else
3027 + /*
3028 + * determine mono pattern info depending on highLightCodes
3029 + * before / after found string pattern.
3030 + */
3031 + patRef->prMonoInfo =
3032 + determineMonoPatInfo(
3033 + window,
3034 + matchInfo->meiHighLightCode,
3035 + absMatchStartPos - 1,
3036 + absMatchStartPos + matchInfo->meiLength,
3037 + &patRef->prKind);
3040 + else
3042 + patRef->prMonoInfo = PEMI_NOT_MONO;
3045 + return TRUE;
3047 + else
3049 + /*
3050 + * Found string can't be assigned to a pattern element
3051 + * (should never occur).
3052 + */
3053 + return FALSE;
3058 +** Returns string pattern of given pattern element.
3060 +StringPattern *GetStringPattern(
3061 + MatchPatternTable *table,
3062 + PatternElement *pattern )
3064 + switch (pattern->peType)
3066 + case PET_SINGLE:
3067 + return &pattern->peVal.peuSingle;
3068 + break;
3070 + case PET_MULTIPLE:
3071 + return &pattern->peVal.peuMulti.mpStringPattern;
3072 + break;
3074 + case PET_REFERENCE:
3075 + return GetStringPattern(
3076 + table,
3077 + getPatternOfReference(table, pattern->peVal.peuRef));
3078 + break;
3081 + /*
3082 + * never reached; just to make compiler happy
3083 + */
3084 + return NULL;
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];
3099 +#ifdef DEBUG_FIND
3100 +static char *getPatternForDebug(
3101 + MatchPatternTable *table,
3102 + PatternReference patRef )
3104 + if (patRef.prElementIdx < 0)
3106 + return "---";
3109 + return
3110 + GetStringPattern(
3111 + table,
3112 + getPatternOfReference(table, patRef))->spText;
3115 +static char *patElemKindToString(
3116 + PatternElementKind patElemKind)
3118 + if (patElemKind == PEK_START)
3119 + return "START";
3120 + else if (patElemKind == PEK_MIDDLE)
3121 + return "MIDDLE";
3122 + else if (patElemKind == PEK_END)
3123 + return "END";
3124 + else
3125 + return "UNKNOWN";
3128 +static void printFoundStringForDebug(
3129 + WindowInfo *window,
3130 + int absStartPos,
3131 + int length)
3133 + char *foundStr =
3134 + BufGetRange( window->buffer, absStartPos, absStartPos + length);
3136 + printf("%d (abs.) <%s>",
3137 + absStartPos,
3138 + foundStr);
3140 + XtFree(foundStr);
3142 +#endif
3145 diff --quilt /dev/null new/source/patternMatch.h
3146 --- /dev/null
3147 +++ new/source/patternMatch.h
3148 @@ -0,0 +1,170 @@
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
3163 +typedef enum {
3164 + PEK_UNKNOWN,
3165 + PEK_START,
3166 + PEK_END,
3167 + PEK_MIDDLE
3168 +} PatternElementKind;
3170 +typedef enum {
3171 + PEMI_NOT_MONO,
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;
3180 + int prElementIdx;
3181 + int prPatternIdx;
3182 +} PatternReference;
3184 +typedef enum {
3185 + MPT_INDIVIDUAL,
3186 + MPT_SUB,
3187 + MPT_GROUP
3188 +} MatchPatternType;
3190 +typedef struct _MatchPatternSequenceElement {
3191 + char *mpseName;
3192 + MatchPatternType mpseType;
3193 + int mpseIndex;
3194 +} MatchPatternSequenceElement;
3196 +typedef struct _MatchPatternGroupElement {
3197 + char *mpgeName;
3198 + int mpgeNumberOfSubPatterns;
3199 + char **mpgeSubPatternIds;
3200 + regexp *mpgeKeywordRE;
3201 +} MatchPatternGroupElement;
3203 +typedef enum {
3204 + PWB_NONE,
3205 + PWB_LEFT,
3206 + PWB_RIGHT,
3207 + PWB_BOTH
3208 +} PatternWordBoundary;
3210 +typedef struct _StrPatBackRefElement{
3211 + int spbreLocalBackRefID;
3212 + char *spbreRegExpText;
3213 +} StrPatBackRefElement;
3215 +typedef struct _StringPattern {
3216 + char *spText;
3217 + int spLength;
3218 + PatternWordBoundary spWordBoundary;
3219 + int spCaseInsensitive;
3220 + int spRegularExpression;
3221 + regexp *spTextRE;
3222 + char *spOrigText;
3223 + int spBackRefParsed;
3224 + int spBackRefResolved;
3225 + StrPatBackRefElement spOwnGlobalBackRef[MAX_GLOBAL_BACK_REF_ID];
3226 + int spGlobalToLocalBackRef[MAX_GLOBAL_BACK_REF_ID];
3227 +} StringPattern;
3229 +typedef struct _MultiPattern {
3230 + StringPattern mpStringPattern;
3231 + int mpNumberOfReferences;
3232 + PatternReference *mpRefList;
3233 +} MultiPattern;
3235 +typedef enum {
3236 + PET_SINGLE,
3237 + PET_MULTIPLE,
3238 + PET_REFERENCE
3239 +} PatternElementType;
3241 +typedef struct _PatternElement {
3242 + int peIndex;
3243 + PatternElementKind peKind;
3244 + PatternElementType peType;
3245 + union {
3246 + StringPattern peuSingle;
3247 + MultiPattern peuMulti;
3248 + PatternReference peuRef;
3249 + } peVal;
3250 +} PatternElement;
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 {
3263 + char *mpteName;
3264 + int mpteIndex;
3265 + MatchPatternType mpteType;
3266 + int mpteGroup;
3267 + PatternElementSet mpteAll;
3268 + PatternElementSet mpteStart;
3269 + PatternElementSet mpteMiddle;
3270 + PatternElementSet mpteEnd;
3271 + int mpteFlash;
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;
3296 +typedef enum {
3297 + MT_FLASH_DELIMIT,
3298 + MT_FLASH_RANGE,
3299 + MT_SELECT,
3300 + MT_GOTO,
3301 + MT_MACRO
3302 +} MatchingType;
3304 +int FindMatchingString(
3305 + WindowInfo *window,
3306 + MatchingType matchingType,
3307 + int *charPos,
3308 + int startLimit,
3309 + int endLimit,
3310 + int *matchPos,
3311 + int *matchLength,
3312 + int *direction);
3314 +StringPattern *GetStringPattern(
3315 + MatchPatternTable *table,
3316 + PatternElement *pattern);
3318 +#endif /* NEDIT_PATTERNMATCH_H_INCLUDED */
3319 diff --quilt /dev/null new/source/patternMatchData.c
3320 --- /dev/null
3321 +++ new/source/patternMatchData.c
3322 @@ -0,0 +1,7780 @@
3323 +static const char CVSID[] = "$Id: patternMatchData.c,v 1.4 2004/10/27 21:57:12 uleh Exp $";
3324 +/*******************************************************************************
3325 +* *
3326 +* patternMatchData.c -- Maintain and allow user to edit a matching pattern list*
3327 +* used for pattern matching *
3328 +* *
3329 +* Copyright (C) 2003-2004, Uwe Lehnert *
3330 +* *
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. *
3336 +* *
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. *
3341 +* *
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 *
3345 +* *
3346 +* Nirvana Text Editor *
3347 +* October 27, 2004 *
3348 +* *
3349 +* Written by Uwe Lehnert *
3350 +* *
3351 +*******************************************************************************/
3352 +#ifdef HAVE_CONFIG_H
3353 +#include "../config.h"
3354 +#endif
3356 +#include <stdlib.h>
3357 +#include <stdio.h>
3358 +#include <limits.h>
3359 +#include <string.h>
3360 +#include <ctype.h>
3362 +#ifdef VMS
3363 +#include "../util/VMSparam.h"
3364 +#else
3365 +#ifndef __MVS__
3366 +#include <sys/param.h>
3367 +#endif
3368 +#endif /*VMS*/
3370 +#include <Xm/Xm.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"
3387 +#include "nedit.h"
3388 +#include "window.h"
3389 +#include "preferences.h"
3390 +#include "help.h"
3391 +#include "file.h"
3392 +#include "textP.h"
3394 +#include "patternMatch.h"
3395 +#include "patternMatchData.h"
3397 +#ifdef HAVE_DEBUG_H
3398 +#include "../debug.h"
3399 +#endif
3402 + * local synonyms
3403 + */
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"
3416 +#define BORDER 4
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
3430 + */
3431 +typedef struct _ErrorInfo {
3432 + char *eiDetail;
3433 + char *eiLanguageMode;
3434 + char *eiMPTabElementName;
3435 + char *eiStringPatText;
3436 + char *eiRegExpCompileMsg;
3437 + int eiBackRefNbr;
3438 +} ErrorInfo;
3440 +typedef struct _BackRefBracketInfo {
3441 + int brbiGlobalId;
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 {
3468 + char *dspeText;
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 {
3481 + char *dmpteName;
3482 + MatchPatternType dmpteType;
3483 + DialogStringPatterns dmptePatterns;
3484 + int dmpteSkipBtwnStartEnd;
3485 + int dmpteIgnoreHighLightInfo;
3486 + int dmpteFlash;
3487 +} DialogMatchPatternTableElement;
3489 +typedef struct _DialogMatchPatternGroupElement {
3490 + char *dmpgeName;
3491 + int dmpgeNumberOfSubPatterns;
3492 + char *dmpgeSubPatternIds[MAX_NBR_MATCH_PATTERNS];
3493 +} DialogMatchPatternGroupElement;
3495 +typedef struct _DialogMatchPatternSequenceElement {
3496 + char *dmpseName;
3497 + MatchPatternType dmpseType;
3498 + int dmpseValid;
3499 + void *dmpsePtr;
3500 +} DialogMatchPatternSequenceElement;
3502 +typedef struct _DialogMatchPatternInfo {
3503 + int dmpiNbrOfSeqElements;
3504 + DialogMatchPatternSequenceElement *dmpiSequence[MAX_NBR_SEQ_ELEMENTS];
3505 +} DialogMatchPatternInfo;
3507 +typedef enum {
3508 + DMPTR_OK,
3509 + DMPTR_EMPTY,
3510 + DMPTR_INCOMPLETE
3511 +} DMPTranslationResult;
3513 +typedef struct _NameList {
3514 + int nlNumber;
3515 + char *nlId[MAX_NBR_SEQ_ELEMENTS + 1];
3516 +} NameList;
3519 + * prototypes of local functions
3520 + */
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(
3551 + char *compileMsg,
3552 + int *globalToLocalBackRef);
3553 +static int localToGlobalBackRef(
3554 + int *globalToLocalBackRef,
3555 + int localId);
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(
3568 + char *result,
3569 + char *partToAdd,
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(
3588 + char *regExpText,
3589 + int *commonLocalId);
3590 +static void scanForLocalBackRefs(
3591 + char *regExpText,
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(
3618 + char *title,
3619 + ErrorInfo *errInfo);
3621 +static char *createMatchPatternsString(
3622 + StringMatchTable *table,
3623 + char *indentStr);
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(
3641 + char **inPtr,
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(
3657 + char **inPtr,
3658 + ErrorInfo *errInfo,
3659 + ReadMatchPatternInfo *info);
3660 +static void recordPatternSequence(
3661 + ReadMatchPatternInfo *info,
3662 + char *name,
3663 + MatchPatternType type,
3664 + int index);
3665 +static int assignIndividualGroup(
3666 + ReadMatchPatternInfo *info,
3667 + char **errMsg,
3668 + MatchPatternTableElement *element);
3669 +static MatchPatternTableElement *getPatternOfName(
3670 + ReadMatchPatternInfo *info,
3671 + char *subPatToSearch);
3672 +static MatchPatternGroupElement *readMatchPatternGroup(
3673 + char **inPtr,
3674 + ErrorInfo *errInfo,
3675 + char *name,
3676 + ReadMatchPatternInfo *info);
3677 +static int readPatternElement(
3678 + char **inPtr,
3679 + char **errMsg,
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,
3710 + const char *end);
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,
3721 + char *subsPtr,
3722 + int globalId,
3723 + int *localId,
3724 + GlobalBackRefElement *backRefList,
3725 + ErrorInfo *errInfo);
3726 +static char *replaceBackRefIdByRegExp(
3727 + StringPattern *strPat,
3728 + char *replaceStartPtr,
3729 + char *regExp);
3730 +static char *convertGlobalToLocalBackRef(
3731 + StringPattern *strPat,
3732 + char *convertPtr);
3734 +static MatchPatternTableElement *readMatchPatternTableElement(
3735 + char **inPtr,
3736 + char **errMsg,
3737 + char *name,
3738 + MatchPatternType type);
3739 +static int sortReadPatternElementSet(
3740 + PatternElementSet *allPat,
3741 + char **errMsg,
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(
3754 + char **inPtr,
3755 + ErrorInfo *errInfo,
3756 + char **name );
3757 +static int getMPSTypeAttribute(
3758 + char **inPtr,
3759 + ErrorInfo *errInfo,
3760 + MatchPatternType *type);
3761 +static int getMPSGlobalAttribute(
3762 + char **inPtr,
3763 + char **errMsg,
3764 + int *isMonoPattern,
3765 + int *comment,
3766 + int *flash,
3767 + int *ignoreHighLightInfo);
3768 +static int getMPSPatternAttribute(
3769 + char **inPtr,
3770 + char **errMsg,
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,
3828 + void *cbArg);
3829 +static void setStringPatternDisplayedCB(void *item, void *cbArg);
3830 +static void freeStringPatternItemCB(void *item);
3832 +static void *getMatchPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
3833 + void *cbArg);
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(
3857 + Widget parent,
3858 + char *currentSubPatName,
3859 + int allSubPatterns);
3860 +static void setupSubPatternNameList(
3861 + char *currentSubPatName,
3862 + int allSubPatterns,
3863 + NameList *nameList);
3864 +static void createSubPatNameMenuEntry(
3865 + Widget menu,
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
3953 + */
3954 +static struct {
3955 + Widget mpdShell;
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;
3966 + Widget gabFlashW;
3967 + Widget gabSyntaxBasedW;
3968 + Widget mpdStringPatternsLbl;
3969 + Widget mpdStringPatternsListW;
3970 + Widget mpdStringPatternTypeLbl;
3971 + Widget sptStartW;
3972 + Widget sptMiddleW;
3973 + Widget sptEndW;
3974 + Widget mpdWordBoundaryLbl;
3975 + Widget wbbBothW;
3976 + Widget wbbLeftW;
3977 + Widget wbbRightW;
3978 + Widget wbbNoneW;
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,
4000 + {0, {NULL}},
4001 + {0, {NULL}},
4002 + True
4003 + };
4006 + * Matching pattern sources loaded from the nedit resources file or set
4007 + * by the user
4008 + */
4009 +static int NbrMatchTables = 0;
4010 +static StringMatchTable *MatchTables[MAX_LANGUAGE_MODES];
4013 + * Syntax:
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..
4021 + * TypeAttribute:
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
4033 + * ("plain").
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
4051 + */
4053 +static char *DefaultStringMatchTable[] = {
4054 + "PLAIN{"
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}",
4059 + "C++{"
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}",
4069 + "C{"
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}",
4079 + "CSS{"
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}",
4086 + "Csh{"
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}",
4098 + "Java{"
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}",
4106 + "JavaScript{"
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}",
4114 + "Makefile{"
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}",
4120 + "NEdit Macro{"
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}",
4126 + "Pascal{"
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}",
4137 + "Perl{"
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}",
4145 + "SGML HTML{"
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}",
4153 + "Sh Ksh Bash{"
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}",
4166 + "XML{"
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}",
4176 + };
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;
4190 + int i;
4192 + if (langModeName == NULL)
4193 + nameToSearch = PLAIN_LM_STRING;
4194 + else
4195 + nameToSearch = langModeName;
4197 + for (i=0; i<NbrMatchTables; i++)
4198 + if (!strcmp(nameToSearch, MatchTables[i]->smtLanguageMode))
4199 + return (void *)MatchTables[i];
4200 + return NULL;
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)
4210 + int i;
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)
4235 + int i;
4237 + for (i=0; i<NbrMatchTables; i++)
4239 + if (!strcmp(langModeName, MatchTables[i]->smtLanguageMode))
4241 + /*
4242 + * free (delete) existing matching pattern
4243 + */
4244 + freeStringMatchTable(MatchTables[i]);
4245 + memmove(
4246 + &MatchTables[i],
4247 + &MatchTables[i+1],
4248 + (NbrMatchTables-1 - i) * sizeof(StringMatchTable *));
4249 + NbrMatchTables--;
4250 + break;
4256 +** Assign a standard string match table to a given new language mode.
4258 +void AssignStandardStringMatchTable(const char *langModeName)
4260 + char *list;
4261 + StringMatchTable *newTable;
4263 + /*
4264 + * assign standard table for new language mode
4265 + * add table to end
4266 + */
4267 + list = StandardStringMatchTable;
4268 + newTable =
4269 + readMatchPatternSetContent(&list, list, XtNewString(langModeName));
4271 + /*
4272 + * add table to end
4273 + */
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)
4286 + return True;
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;
4301 + int i;
4303 + for (;;)
4305 + /*
4306 + * read each matching pattern set
4307 + */
4308 + table = readMatchPatternSet(&inPtr);
4310 + if (table != NULL)
4312 + /*
4313 + * add/change the pattern set in the list
4314 + */
4315 + for (i=0; i<NbrMatchTables; i++)
4317 + if (!strcmp(MatchTables[i]->smtLanguageMode, table->smtLanguageMode))
4319 + freeStringMatchTable(MatchTables[i]);
4320 + MatchTables[i] = table;
4321 + break;
4324 + if (i == NbrMatchTables)
4326 + MatchTables[NbrMatchTables++] = table;
4327 + if (NbrMatchTables > MAX_LANGUAGE_MODES)
4329 + return False;
4334 + /*
4335 + * find end of this pattern. if the string ends here, we're done
4336 + */
4337 + inPtr = strstr(inPtr, "\n");
4338 + if (inPtr == NULL)
4340 + return True;
4343 + /*
4344 + * skip newline, tabs & spaces in front of next pattern.
4345 + * if the string ends here, we're done
4346 + */
4347 + inPtr += strspn(inPtr, " \t\n");
4348 + if (*inPtr == '\0')
4350 + return True;
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];
4373 + written = True;
4375 + BufInsert(outBuf, outBuf->length, table->smtLanguageMode);
4376 + BufInsert(outBuf, outBuf->length, ":");
4378 + if (isDefaultMatchPatternTable(table))
4380 + BufInsert(outBuf, outBuf->length, "Default\n\t");
4382 + else
4384 + BufInsert(outBuf, outBuf->length, "{\n");
4385 + BufInsert(outBuf, outBuf->length,
4386 + str = createMatchPatternsString(table, "\t\t"));
4387 + XtFree(str);
4388 + BufInsert(outBuf, outBuf->length, "\t}\n\t");
4392 + /*
4393 + * Get the output string, and lop off the trailing newline and tab
4394 + */
4395 + outStr = BufGetRange(outBuf, 0, outBuf->length - (written?2:0));
4396 + BufFree(outBuf);
4398 + /*
4399 + * Protect newlines and backslashes from translation by the resource
4400 + * reader
4401 + */
4402 + escapedStr = EscapeSensitiveChars(outStr);
4404 + XtFree(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;
4424 + int nbrOfRef;
4426 + /*
4427 + * No duplicate check needed, if previous pattern is a reference,
4428 + * due to the related multi pattern element is checked before.
4429 + */
4430 + if (prevPattern->peType == PET_REFERENCE)
4431 + return;
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)
4442 + /*
4443 + * Patterns are identical: Is prevPattern already a multi pattern ?
4444 + */
4445 + if (prevPattern->peType == PET_MULTIPLE)
4447 + /*
4448 + * just add ref. to "lastPattern" to the ref. list
4449 + */
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) );
4455 + memcpy(
4456 + prevPattern->peVal.peuMulti.mpRefList,
4457 + oldList,
4458 + (nbrOfRef-1) * sizeof(PatternReference) );
4459 + prevPattern->peVal.peuMulti.mpRefList[nbrOfRef-1] = lastPatRef;
4460 + XtFree( (char *)oldList );
4462 + else
4464 + /*
4465 + * convert prev. single pattern to multi pattern
4466 + */
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;
4476 + /*
4477 + * convert last single pattern to reference
4478 + */
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)
4497 + int i;
4498 + PatternReference prevPatRef;
4500 + prevPatRef.prElementIdx = prevElementIdx;
4502 + for (i=0; i<prevElement->mpteAll.pesNumberOfPattern; i++)
4504 + prevPatRef.prPatternIdx = i;
4505 + treatDuplicatedPattern(
4506 + table,
4507 + prevElement->mpteAll.pesPattern[i],
4508 + prevPatRef,
4509 + lastPattern,
4510 + lastPatRef);
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
4517 +** element.
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)
4527 + int i;
4528 + PatternReference lastPatRef;
4530 + lastPatRef.prElementIdx = lastElementIdx;
4532 + for (i=0; i<lastElement->mpteAll.pesNumberOfPattern; i++)
4534 + lastPatRef.prPatternIdx = i;
4535 + treatDuplicatedPatternElements(
4536 + table,
4537 + prevElement,
4538 + prevElementIdx,
4539 + lastElement->mpteAll.pesPattern[i],
4540 + lastPatRef);
4545 +** Convert all duplicated patterns of given match pattern table to
4546 +** references.
4548 +static void treatDuplicatedMTEntries(
4549 + MatchPatternTableElement **element,
4550 + int nbrOfElements)
4552 + int i;
4553 + MatchPatternTableElement *lastElement;
4554 + int lastElementIdx;
4555 + MatchPatternTable table;
4557 + if (nbrOfElements < 2)
4558 + return;
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)
4582 + int i;
4583 + StringPattern *strPat;
4585 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
4587 + strPat = getReadStringPattern(readPatInfo, element->mpteAll.pesPattern[i]);
4589 + /*
4590 + * if current string pattern holds a regular expression, then
4591 + * compile it
4592 + */
4593 + if (strPat->spRegularExpression)
4595 + if (createStrPatRegExp(strPat, errInfo))
4597 + /*
4598 + * compilation was not successful
4599 + */
4600 + errInfo->eiMPTabElementName = XtNewString(element->mpteName);
4601 + return True;
4606 + return False;
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;
4618 + char *compileMsg;
4620 + /*
4621 + * compose regular expression for start string pattern.
4622 + */
4623 + if( strPat->spCaseInsensitive)
4625 + /*
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.
4629 + */
4630 + regExpString = XtMalloc(strPat->spLength + 5);
4631 + strcpy(regExpString, "(?i");
4632 + strcat(regExpString, strPat->spText);
4633 + strcat(regExpString, ")");
4635 + else
4637 + regExpString = strPat->spText;
4640 + /*
4641 + * compile regular expression & free allocated string buffer,
4642 + * if applicable.
4643 + */
4644 + strPat->spTextRE =
4645 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
4647 + if (strPat->spTextRE == NULL)
4649 + /*
4650 + * compilation was not successful: adapt error reason by
4651 + * converting local backrefs to global ones.
4652 + */
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(
4670 + char *compileMsg,
4671 + int *globalToLocalBackRef)
4673 + int localId;
4674 + int globalId;
4675 + char *s = compileMsg;
4677 + while (*s != '\0')
4679 + if (*s == '\\')
4681 + if (isdigit((unsigned char)*(s+1)))
4683 + /*
4684 + * \n (n=1..9) found: substitute local by global back ref.
4685 + */
4686 + s ++;
4688 + localId =
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')
4696 + s ++;
4698 + s ++;
4703 +** translate given local backref to global backref by using
4704 +** given globalToLocalBackRef list.
4706 +static int localToGlobalBackRef(
4707 + int *globalToLocalBackRef,
4708 + int localId)
4710 + int i;
4712 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
4714 + if (globalToLocalBackRef[i] == localId)
4715 + return i+1;
4718 + return 0;
4722 +** Create a regular expression holding keywords of given start & end
4723 +** pattern set.
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;
4732 + char *compileMsg;
4734 + /*
4735 + * compose regular expression for start / end pattern.
4736 + */
4737 + composeStartEndRegExpString(
4738 + readMatchPatternInfo,
4739 + element,
4740 + &regExpString);
4742 + /*
4743 + * compile regular expression & free allocated string buffer.
4744 + */
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)
4768 + int i;
4769 + MatchPatternTableElement *element;
4770 + RegExpStringInfo regExpStringInfo;
4771 + char *regExpString;
4772 + regexp *keywordRE;
4773 + char *compileMsg;
4775 + /*
4776 + * Allocate buffers for keyword regular expression of this group.
4777 + */
4778 + setupRegExpStringBuffers(
4779 + readPatInfo,
4780 + &regExpStringInfo);
4782 + for (i=0; i<group->mpgeNumberOfSubPatterns; i++)
4784 + element = getPatternOfName(readPatInfo, group->mpgeSubPatternIds[i]);
4785 + /*
4786 + * Add the keywords of the sub pattern to the keyword regular
4787 + * expression string buffer of new group.
4788 + */
4789 + addElementToRegExpString(
4790 + element,
4791 + readPatInfo,
4792 + &regExpStringInfo);
4795 + /*
4796 + * Assemble and compile the resulting keyword regular expression string.
4797 + */
4798 + catSMTRegExpStrings(
4799 + &regExpStringInfo,
4800 + &regExpString);
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)
4826 + int totalLen;
4827 + int nbrOfMultiPatterns;
4828 + int sizeOfPatRefs;
4830 + /*
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.
4834 + */
4835 + totalLen =
4836 + totalKeywordOfTableLen( readMatchPatternInfo, &nbrOfMultiPatterns );
4838 + /*
4839 + * allocate memory to store added multi pattern references (to avoid
4840 + * duplicated keywords strings later on).
4841 + */
4842 + sizeOfPatRefs = sizeof(PatternReference *) * nbrOfMultiPatterns;
4844 + regExpStringInfo->resiAddedMultiPat =
4845 + (PatternReference **)XtMalloc( sizeOfPatRefs );
4847 + regExpStringInfo->resiNbrOfAddedMultiPat = 0;
4849 + /*
4850 + * init. ID of capturing local backrefs
4851 + */
4852 + regExpStringInfo->resiLocalBackRefID = 1;
4854 + /*
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.
4859 + */
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(
4876 + char *result,
4877 + char *partToAdd,
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,
4899 + char *indentStr)
4901 + char *outStr, *str;
4902 + textBuffer *outBuf;
4903 + int i, j;
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, ":");
4930 + else
4932 + if (seq->mpseType == MPT_SUB)
4934 + BufInsert(outBuf, outBuf->length, "s");
4936 + BufInsert(outBuf, outBuf->length, ":");
4938 + element = table->smtAllPatterns->mptElements[seq->mpseIndex];
4940 + /*
4941 + * write global attributes
4942 + */
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, ":");
4953 + /*
4954 + * write string patterns
4955 + */
4956 + for (j=0; j < element->mpteAll.pesNumberOfPattern; j ++)
4958 + BufInsert(
4959 + outBuf,
4960 + outBuf->length,
4961 + str =
4962 + createPatternElementString(
4963 + table->smtAllPatterns,
4964 + element->mpteAll.pesPattern[j]));
4965 + XtFree(str);
4969 + BufInsert(outBuf, outBuf->length, "\n");
4972 + outStr = BufGetAll(outBuf);
4973 + BufFree(outBuf);
4975 + return outStr;
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);
4993 + /*
4994 + * write string pattern kind
4995 + */
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");
5003 + /*
5004 + * write word boundary
5005 + */
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");
5013 + /*
5014 + * write case insensitive flag
5015 + */
5016 + if (strPat->spCaseInsensitive)
5017 + BufInsert(outBuf, outBuf->length, "i");
5019 + /*
5020 + * write regular expression flag
5021 + */
5022 + if (strPat->spRegularExpression)
5023 + BufInsert(outBuf, outBuf->length, "x");
5025 + BufInsert(outBuf, outBuf->length, ":");
5027 + /*
5028 + * write pattern string
5029 + */
5030 + if( strPat->spOrigText != NULL)
5031 + BufInsert(
5032 + outBuf,
5033 + outBuf->length,
5034 + str = MakeQuotedString(strPat->spOrigText));
5035 + else
5036 + BufInsert(
5037 + outBuf,
5038 + outBuf->length,
5039 + str = MakeQuotedString(strPat->spText));
5040 + XtFree(str);
5042 + BufInsert(outBuf, outBuf->length, ":");
5044 + outStr = BufGetAll(outBuf);
5045 + BufFree(outBuf);
5047 + return outStr;
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;
5059 + char *list;
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
5079 +** pattern tables.
5081 +static int isDefaultMatchPatternTable(StringMatchTable *table)
5083 + StringMatchTable *defaultTable;
5084 + int retVal;
5086 + defaultTable = readDefaultStringMatchTable(table->smtLanguageMode);
5088 + if (defaultTable == NULL)
5089 + return False;
5091 + retVal = !stringMatchTableDiffer(table, defaultTable);
5093 + freeStringMatchTable(defaultTable);
5095 + return retVal;
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);
5112 + /*
5113 + * remove leading whitespace
5114 + */
5115 + *inPtr += strspn(*inPtr, " \t\n");
5117 + /*
5118 + * read language mode field
5119 + */
5120 + languageMode = ReadSymbolicField(inPtr);
5122 + /*
5123 + * look for initial brace
5124 + */
5125 + if (**inPtr == ':')
5127 + (*inPtr) ++;
5128 + /*
5129 + * look for "Default" keyword, and if it's there, return the default
5130 + * pattern set
5131 + */
5132 + if (!strncmp(*inPtr, "Default", 7))
5134 + *inPtr += 7;
5135 + table = readDefaultStringMatchTable(languageMode);
5136 + XtFree(languageMode);
5138 + return table;
5142 + table = readMatchPatternSetContent(inPtr, stringStart, languageMode);
5144 + if (table == NULL)
5145 + XtFree(languageMode);
5147 + return table;
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(
5156 + char **inPtr,
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);
5168 + /*
5169 + * look for initial brace
5170 + */
5171 + if (**inPtr != '{')
5173 + errInfo.eiLanguageMode = XtNewString(languageMode);
5174 + errInfo.eiDetail = "pattern list must begin with \"{\"";
5175 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo );
5177 + return NULL;
5180 + (*inPtr)++;
5182 + readPatInfo.rmpiNbrOfElements = 0;
5183 + readPatInfo.rmpiNbrOfGroups = 0;
5184 + readPatInfo.rmpiNbrOfSeqElements = 0;
5185 + readPatInfo.rmpiAllPatRE = NULL;
5186 + readPatInfo.rmpiFlashPatRE = NULL;
5188 + /*
5189 + * parse each pattern in the list
5190 + */
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 == '}')
5203 + (*inPtr)++;
5204 + endOfPatternSet = True;
5206 + else
5208 + if (!readMatchPatternEntry(inPtr, &errInfo, &readPatInfo))
5210 + errInfo.eiLanguageMode = XtNewString(languageMode);
5211 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5212 + successful = False;
5217 + if (successful)
5219 + /*
5220 + * compile regular expressions of read patterns
5221 + */
5222 + if (createRegExpOfPatterns(&readPatInfo, &errInfo))
5224 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5225 + successful = False;
5229 + if (successful)
5231 + return createStringMatchTable(&readPatInfo, languageMode);
5233 + else
5235 + /*
5236 + * free memory of already read patterns
5237 + */
5238 + freeReadMatchPatternInfo(&readPatInfo);
5240 + return NULL;
5243 + return table;
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))
5255 + return True;
5257 + if (createRegExpOfAllPatterns(readPatInfo, errInfo))
5258 + return True;
5260 + return False;
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)
5272 + int i;
5273 + RegExpStringInfo allPatRegExpSI;
5274 + RegExpStringInfo flashPatRegExpSI;
5275 + MatchPatternTableElement *element;
5276 + char *regExpString;
5277 + char *compileMsg;
5279 + /*
5280 + * Allocate buffers for keyword regular expressions.
5281 + */
5282 + setupRegExpStringBuffers(readPatInfo, &allPatRegExpSI);
5283 + setupRegExpStringBuffers(readPatInfo, &flashPatRegExpSI);
5285 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5287 + element = readPatInfo->rmpiElement[i];
5289 + /*
5290 + * Add the keywords of the matching pattern to the keyword
5291 + * regular expression string buffer of all patterns.
5292 + */
5293 + addElementToRegExpString(
5294 + element,
5295 + readPatInfo,
5296 + &allPatRegExpSI);
5298 + /*
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.
5302 + */
5303 + if (element->mpteFlash)
5305 + addElementToRegExpString(
5306 + element,
5307 + readPatInfo,
5308 + &flashPatRegExpSI);
5312 + /*
5313 + * Assemble and compile the resulting all keywords reg. exp. string.
5314 + */
5315 + catSMTRegExpStrings(
5316 + &allPatRegExpSI,
5317 + &regExpString);
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";
5328 + return True;
5331 + /*
5332 + * Assemble and compile the resulting flash keywords reg. exp. string.
5333 + */
5334 + catSMTRegExpStrings(
5335 + &flashPatRegExpSI,
5336 + &regExpString);
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";
5347 + return True;
5350 + /*
5351 + * Pattern reg. exp. successful created:
5352 + */
5353 + return False;
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)
5365 + int i;
5366 + MatchPatternTableElement *element;
5367 + MatchPatternGroupElement *group;
5369 + /*
5370 + * create global backref list of all elements of read info
5371 + */
5372 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5374 + element = readPatInfo->rmpiElement[i];
5376 + if (!createGlobalBackRefList(readPatInfo, element, errInfo))
5377 + return True;
5380 + /*
5381 + * resolve global backrefs of all elements of read info
5382 + */
5383 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5385 + element = readPatInfo->rmpiElement[i];
5387 + if (!resolveGlobalBackRefs(readPatInfo, element, errInfo))
5388 + return True;
5391 + /*
5392 + * compile reg. exp. of all elements of read info
5393 + */
5394 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5396 + element = readPatInfo->rmpiElement[i];
5398 + if (createStrPatRegExpOfElement(readPatInfo, element, errInfo))
5399 + return True;
5401 + /*
5402 + * create start / end reg. exp. if applicable.
5403 + */
5404 + if (element->mpteSkipBtwnStartEnd)
5406 + if (createStartEndRegExp(readPatInfo, element, errInfo))
5407 + return True;
5411 + /*
5412 + * compile reg. exp. of all groups of read info
5413 + */
5414 + for (i=0; i < readPatInfo->rmpiNbrOfGroups; i ++)
5416 + group = readPatInfo->rmpiGroup[i];
5418 + if (createGroupRegExp(readPatInfo, group, errInfo))
5420 + return True;
5424 + return False;
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;
5441 + /*
5442 + * allocate a more appropriately sized list to return matching patterns
5443 + */
5444 + patTable = (MatchPatternTable *)XtMalloc(sizeof(MatchPatternTable));
5445 + patTable->mptNumberOfElements = readPatInfo->rmpiNbrOfElements;
5447 + if (readPatInfo->rmpiNbrOfElements > 0)
5449 + sizeOfElements =
5450 + sizeof(MatchPatternTableElement *) * readPatInfo->rmpiNbrOfElements;
5451 + patTable->mptElements =
5452 + (MatchPatternTableElement **)XtMalloc(sizeOfElements);
5453 + memcpy(patTable->mptElements, readPatInfo->rmpiElement, sizeOfElements);
5455 + else
5457 + patTable->mptElements = NULL;
5460 + table->smtAllPatterns = patTable;
5462 + table->smtAllPatRE = readPatInfo->rmpiAllPatRE;
5463 + table->smtFlashPatRE = readPatInfo->rmpiFlashPatRE;
5464 + table->smtUsedPatRE = NULL;
5466 + /*
5467 + * allocate a more appropriately sized list to return matching pattern groups
5468 + */
5469 + table->smtNumberOfGroups = readPatInfo->rmpiNbrOfGroups;
5470 + if (readPatInfo->rmpiNbrOfGroups > 0)
5472 + sizeOfElements =
5473 + sizeof(MatchPatternGroupElement *) * readPatInfo->rmpiNbrOfGroups;
5474 + table->smtGroups =
5475 + (MatchPatternGroupElement **)XtMalloc(sizeOfElements);
5476 + memcpy(table->smtGroups, readPatInfo->rmpiGroup, sizeOfElements);
5478 + else
5480 + table->smtGroups = NULL;
5482 + /*
5483 + * allocate a more appropriately sized list to return matching pattern sequence
5484 + */
5485 + table->smtNumberOfSeqElements = readPatInfo->rmpiNbrOfSeqElements;
5486 + if (readPatInfo->rmpiNbrOfSeqElements > 0)
5488 + sizeOfElements =
5489 + sizeof(MatchPatternSequenceElement *) * readPatInfo->rmpiNbrOfSeqElements;
5490 + table->smtSequence =
5491 + (MatchPatternSequenceElement **)XtMalloc(sizeOfElements);
5492 + memcpy(table->smtSequence, readPatInfo->rmpiSequence, sizeOfElements);
5494 + else
5496 + table->smtSequence = NULL;
5499 + return table;
5503 +** Read one match pattern entry of a match pattern string.
5504 +** Returns true, if read was successful.
5506 +static int readMatchPatternEntry(
5507 + char **inPtr,
5508 + ErrorInfo *errInfo,
5509 + ReadMatchPatternInfo *info)
5511 + char *name;
5512 + MatchPatternType type;
5513 + MatchPatternGroupElement *readGroup;
5514 + MatchPatternTableElement *readElement;
5516 + if (!getMPSName( inPtr, errInfo, &name ))
5518 + return False;
5521 + if (!getMPSTypeAttribute( inPtr, errInfo, &type ))
5523 + errInfo->eiMPTabElementName = XtNewString(name);
5524 + return False;
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";
5533 + return False;
5536 + readGroup = readMatchPatternGroup( inPtr, errInfo, name, info );
5538 + if (readGroup == NULL)
5540 + errInfo->eiMPTabElementName = XtNewString(name);
5541 + XtFree( name );
5543 + else
5545 + info->rmpiGroup[info->rmpiNbrOfGroups ++] = readGroup;
5547 + recordPatternSequence( info, name, type, info->rmpiNbrOfGroups-1 );
5550 + return (readGroup != NULL);
5552 + else
5554 + if (info->rmpiNbrOfElements >= MAX_NBR_MATCH_PATTERNS)
5556 + errInfo->eiMPTabElementName = XtNewString(name);
5557 + errInfo->eiDetail = "max number of match patterns exceeded";
5558 + XtFree( name );
5559 + return False;
5562 + readElement =
5563 + readMatchPatternTableElement( inPtr, &errInfo->eiDetail, name, type );
5565 + if (readElement == NULL)
5567 + errInfo->eiMPTabElementName = XtNewString(name);
5568 + XtFree( name );
5570 + else
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);
5581 + return False;
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,
5600 + char *name,
5601 + MatchPatternType type,
5602 + int index)
5604 + MatchPatternSequenceElement *sequence;
5606 + 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,
5622 + char **errMsg,
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";
5630 + return False;
5633 + /*
5634 + * Assign the index of new group to the individual matching pattern
5635 + */
5636 + element->mpteGroup = info->rmpiNbrOfGroups;
5638 + /*
5639 + * Allocate memory for the matching pattern group and copy the
5640 + * info into this group element.
5641 + */
5642 + group =
5643 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
5645 + group->mpgeName = NULL;
5646 + group->mpgeKeywordRE = NULL;
5648 + /*
5649 + * remember name of match pattern table element, which is
5650 + * represented by this group.
5651 + */
5652 + group->mpgeNumberOfSubPatterns = 1;
5653 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeof(char *) );
5654 + group->mpgeSubPatternIds[0] = XtNewString(element->mpteName);
5656 + info->rmpiGroup[info->rmpiNbrOfGroups ++] = group;
5658 + return True;
5662 +** Get the match pattern table element of given 'patToSearch'
5663 +** name.
5664 +** Returns NULL, if no element was found.
5666 +static MatchPatternTableElement *getPatternOfName(
5667 + ReadMatchPatternInfo *info,
5668 + char *patToSearch)
5670 + int i;
5671 + MatchPatternTableElement *element;
5673 + for (i=0; i<info->rmpiNbrOfElements; i ++)
5675 + element = info->rmpiElement[i];
5677 + if (strcmp( element->mpteName, patToSearch ) == 0)
5679 + /*
5680 + * Related sub-pattern found:
5681 + */
5682 + return element;
5686 + /*
5687 + * No sub-pattern found:
5688 + */
5689 + return NULL;
5693 +** Read match pattern group of given match pattern string.
5694 +** Returns NULL, if read fails.
5696 +static MatchPatternGroupElement *readMatchPatternGroup(
5697 + char **inPtr,
5698 + ErrorInfo *errInfo,
5699 + char *name,
5700 + ReadMatchPatternInfo *info)
5702 + int i;
5703 + int error = False;
5704 + char *patNameInPtr;
5705 + char *subPatName;
5706 + MatchPatternTableElement *subPatElement;
5707 + int numberOfRelatedSubPattern = 0;
5708 + char *relatedSubPatternId[MAX_NBR_MATCH_PATTERNS];
5709 + int sizeOfIds;
5710 + MatchPatternGroupElement *group = NULL;
5712 + /*
5713 + * Read sub-matching patterns of this group.
5714 + */
5715 + while (**inPtr != '\n' && !error)
5717 + /*
5718 + * Read next pattern name from inPtr.
5719 + */
5720 + patNameInPtr = *inPtr;
5721 + subPatName = ReadSymbolicField(inPtr);
5723 + if (subPatName == NULL)
5725 + errInfo->eiDetail = "Sub-Matching Pattern Name expected";
5726 + error = True;
5728 + else
5730 + /*
5731 + * Get matching pattern related to sub-matching pattern name.
5732 + */
5733 + subPatElement =
5734 + getPatternOfName( info, subPatName );
5736 + if (subPatElement == NULL)
5738 + errInfo->eiStringPatText = XtNewString(subPatName);
5739 + errInfo->eiDetail = "Sub-Matching Pattern not defined before";
5740 + error = True;
5742 + else if (numberOfRelatedSubPattern >= MAX_NBR_MATCH_PATTERNS)
5744 + errInfo->eiDetail = "Group holds too many Sub-Matching Patterns";
5745 + error = True;
5747 + else if (subPatElement->mpteType != MPT_SUB)
5749 + errInfo->eiStringPatText = XtNewString(subPatName);
5750 + errInfo->eiDetail = "Not a Sub-Matching Pattern";
5751 + error = True;
5753 + else
5755 + /*
5756 + * Remember sub-matching pattern ID
5757 + */
5758 + relatedSubPatternId[numberOfRelatedSubPattern ++] = subPatName;
5760 + /*
5761 + * Assign the index of this group to the sub-matching pattern
5762 + * if no group index was assigned before.
5763 + */
5764 + if (subPatElement->mpteGroup == NO_GROUP_IDX)
5766 + subPatElement->mpteGroup = info->rmpiNbrOfGroups;
5770 + /*
5771 + * Skip to the start of the next matching pattern name.
5772 + */
5773 + if (!error && !SkipDelimiter(inPtr, &errInfo->eiDetail))
5775 + error = True;
5780 + if (error)
5782 + for (i=0; i < numberOfRelatedSubPattern; i++)
5784 + XtFree( relatedSubPatternId[i] );
5787 + return NULL;
5789 + else
5791 + /*
5792 + * Allocate memory for the matching pattern group and copy the
5793 + * info into this group element.
5794 + */
5795 + group =
5796 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
5798 + group->mpgeName = name;
5799 + group->mpgeKeywordRE = NULL;
5801 + /*
5802 + * Allocate memory for the sub-matching pattern IDs & copy
5803 + * related sub-matching pattern into the group element.
5804 + */
5805 + sizeOfIds = sizeof(char *) * numberOfRelatedSubPattern;
5806 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeOfIds );
5808 + memcpy(group->mpgeSubPatternIds, relatedSubPatternId, sizeOfIds);
5810 + group->mpgeNumberOfSubPatterns = numberOfRelatedSubPattern;
5812 + return group;
5817 +** Read one match pattern element from given match pattern string.
5818 +** Returns true, if read was successful.
5820 +static int readPatternElement(
5821 + char **inPtr,
5822 + char **errMsg,
5823 + PatternElement **pattern)
5825 + PatternElementKind patternKind;
5826 + PatternWordBoundary wordBoundary;
5827 + int caseInsensitive;
5828 + int regularExpression;
5829 + char *string;
5831 + if (!getMPSPatternAttribute(
5832 + inPtr,
5833 + errMsg,
5834 + &patternKind,
5835 + &wordBoundary,
5836 + &caseInsensitive,
5837 + &regularExpression ))
5839 + return False;
5842 + if (!ReadQuotedString(inPtr, errMsg, &string))
5844 + return False;
5847 + if (!SkipDelimiter(inPtr, errMsg))
5849 + XtFree( string );
5850 + return False;
5853 + *pattern =
5854 + createPatternElement(
5855 + string,
5856 + patternKind,
5857 + wordBoundary,
5858 + caseInsensitive,
5859 + regularExpression);
5861 + return True;
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;
5875 + char *s;
5877 + /*
5878 + * Convert pattern text to lower case, if case insensitive
5879 + * attribute is set.
5880 + */
5881 + if (caseInsensitive)
5883 + for (s = patternText; *s != '\0'; s ++)
5885 + *s = tolower(*s);
5889 + /*
5890 + * Allocate memory for the new pattern element and init. / copy
5891 + * related info into this pattern element.
5892 + */
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;
5909 + /*
5910 + * Store original string of regular expression patterns due to
5911 + * it may be later adapted (e.g. due to global backrefs etc.).
5912 + */
5913 + if (regularExpression)
5915 + pattern->peVal.peuSingle.spOrigText = patternText;
5916 + pattern->peVal.peuSingle.spText = NULL;
5917 + pattern->peVal.peuSingle.spWordBoundary = PWB_NONE;
5919 + else
5921 + pattern->peVal.peuSingle.spOrigText = NULL;
5922 + pattern->peVal.peuSingle.spText = patternText;
5923 + pattern->peVal.peuSingle.spWordBoundary = wordBoundary;
5926 + return pattern;
5930 +** Create a list holding all global backref definitions of given
5931 +** match pattern table element. The list is stored in this given
5932 +** element.
5933 +** Returns true, if list was successfully created.
5935 +static int createGlobalBackRefList(
5936 + ReadMatchPatternInfo *readPatInfo,
5937 + MatchPatternTableElement *element,
5938 + ErrorInfo *errInfo)
5940 + int i;
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)
5951 + /*
5952 + * Global backrefs or this string pattern already parsed:
5953 + * just merge string pattern list with elements one.
5954 + */
5955 + if (!updateGlobalBackRefs(
5956 + strPat,
5957 + element->mpteGlobalBackRef,
5958 + errInfo))
5960 + return False;
5963 + else
5965 + /*
5966 + * parse string pattern for global backrefs and
5967 + * merge string pattern list with elements one.
5968 + */
5969 + if (!parseGlobalBackRefs(
5970 + strPat,
5971 + element->mpteGlobalBackRef,
5972 + errInfo))
5974 + return False;
5980 + return True;
5984 +** Returns read string pattern of given pattern element.
5986 +StringPattern *getReadStringPattern(
5987 + ReadMatchPatternInfo *readPatInfo,
5988 + PatternElement *pattern )
5990 + switch (pattern->peType)
5992 + case PET_SINGLE:
5993 + return &pattern->peVal.peuSingle;
5994 + break;
5996 + case PET_MULTIPLE:
5997 + return &pattern->peVal.peuMulti.mpStringPattern;
5998 + break;
6000 + case PET_REFERENCE:
6001 + return getReadStringPattern(
6002 + readPatInfo,
6003 + getReadPatternOfReference(readPatInfo, &pattern->peVal.peuRef));
6004 + break;
6007 + /*
6008 + * never reached; just to make compiler happy
6009 + */
6010 + return NULL;
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;
6034 + const char *s;
6035 + char *d;
6036 + int nbrOfOpenBraces = 0;
6038 + s = source;
6040 + /*
6041 + * count number of open braces
6042 + */
6043 + while (*s != '\0')
6045 + if (*s++ == '(')
6046 + nbrOfOpenBraces ++;
6049 + /*
6050 + * allocate memory for substitued reg. exp. text
6051 + */
6052 + destination = XtMalloc(strlen(source) + 2*nbrOfOpenBraces);
6054 + /*
6055 + * substitute each capturing open brace by a non-capturing one
6056 + */
6057 + s = source;
6058 + d = destination;
6060 + while (*s != '\0')
6062 + if (*s == '\\')
6064 + *d++ = *s++;
6066 + if (*s != '\0')
6067 + *d++ = *s++;
6069 + else if (*s == '(')
6071 + *d++ = *s++;
6073 + if (*s != '?' && *s != '*')
6075 + *d++ = '?';
6076 + *d++ = ':';
6079 + else
6081 + *d++ = *s++;
6085 + *d = '\0';
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)
6101 + char *s;
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')
6116 + if (*s == '\\')
6118 + /*
6119 + * Ignore escaped characters
6120 + */
6121 + if (*(s+1) != '\0')
6122 + s ++;
6124 + else if (*s == '(')
6126 + if (*(s+1) == '*')
6128 + if (isdigit((unsigned char)*(s+2)))
6130 + /*
6131 + * Global backref. definition start found:
6132 + */
6133 + stackIdx ++;
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";
6142 + return False;
6145 + backRefInfo[stackIdx].brbiContentStart = s+3;
6146 + backRefInfo[stackIdx].brbiNestingLevel = nestingLevel;
6147 + s ++;
6149 + s ++;
6151 + nestingLevel ++;
6153 + else if (*s == ')')
6155 + nestingLevel --;
6156 + if (stackIdx != -1 &&
6157 + backRefInfo[stackIdx].brbiNestingLevel == nestingLevel)
6159 + /*
6160 + * Global backref. definition end found: add it to
6161 + * backref. list of string pattern.
6162 + */
6163 + curStrPatBRE =
6164 + &strPat->spOwnGlobalBackRef[backRefInfo[stackIdx].brbiGlobalId];
6166 + backRefContent =
6167 + createBackRefRegExpText(
6168 + backRefInfo[stackIdx].brbiContentStart,
6169 + s);
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);
6177 + return False;
6179 + else
6181 + curStrPatBRE->spbreRegExpText = backRefContent;
6184 + stackIdx --;
6187 + s ++;
6190 + /*
6191 + * Merge global backref. list of string pattern with given backRefList.
6192 + */
6193 + return updateGlobalBackRefs(
6194 + strPat,
6195 + backRefList,
6196 + errInfo);
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)
6208 + int i;
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";
6228 + return False;
6231 + else
6233 + curGlobalBRE->gbreDefByStrPat = strPat;
6234 + curGlobalBRE->gbreRegExpText = curStrPatBRE->spbreRegExpText;
6239 + return True;
6243 +** Allocate and return a new string holding content of
6244 +** global backref. definition.
6246 +static char *createBackRefRegExpText(
6247 + const char *start,
6248 + const char *end)
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)
6269 + int i;
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))
6279 + return False;
6281 + strPat->spBackRefResolved = True;
6285 + return 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)
6297 + char *s;
6298 + int globalId;
6299 + int localId = 1;
6301 + s = strPat->spText;
6303 + while (*s != '\0')
6305 + if (*s == '\\')
6307 + if (isdigit((unsigned char)*(s+1)))
6309 + /*
6310 + * \n (n=1..9) found: substitute global backref.
6311 + */
6312 + globalId =
6313 + (int)((unsigned char)*(s+1) - (unsigned char)'0') - 1;
6315 + if(globalId < 0)
6317 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6318 + errInfo->eiDetail = "backref '\\0' not allowed";
6319 + return False;
6322 + s = substituteGlobalBackRef(strPat, s, globalId, &localId, backRefList, errInfo);
6324 + if (s == NULL)
6325 + return False;
6327 + else if (*(s+1) != '\0')
6328 + s ++;
6330 + else if (*s == '(')
6332 + if (*(s+1) == '*')
6334 + if (isdigit((unsigned char)*(s+2)))
6336 + /*
6337 + * "(*n" (n=1..9) found: substitute global backref. definition.
6338 + */
6339 + globalId =
6340 + (int)((unsigned char)*(s+2) - (unsigned char)'0') - 1;
6342 + strPat->spOwnGlobalBackRef[globalId].spbreLocalBackRefID = localId;
6343 + strPat->spGlobalToLocalBackRef[globalId] = localId;
6345 + localId ++;
6347 + s = convertGlobalToLocalBackRef(strPat, s);
6349 + else
6351 + s ++;
6355 + s ++;
6358 + return True;
6362 +** Substitute global backref (\n, n=1..9) located at given "subsPtr"
6363 +** by its definition or by a local backref.
6364 +** Returns
6365 +** - NULL, if substitute fails or
6366 +** - substituted string pointer, where scan shall continue with.
6368 +static char *substituteGlobalBackRef(
6369 + StringPattern *strPat,
6370 + char *subsPtr,
6371 + int globalId,
6372 + int *localId,
6373 + GlobalBackRefElement *backRefList,
6374 + ErrorInfo *errInfo)
6376 + StrPatBackRefElement *strPatBackRef = &strPat->spOwnGlobalBackRef[globalId];
6377 + char *s;
6379 + if (strPatBackRef->spbreRegExpText == NULL)
6381 + /*
6382 + * given global backref definition is not located in given
6383 + * string pattern -> replace backref ID by backref reg. exp.
6384 + */
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";
6390 + return NULL;
6393 + if (strPat->spGlobalToLocalBackRef[globalId] == NO_LOCAL_BACK_REF_ID)
6395 + /*
6396 + * 1st occurence of global backref ID in this pattern ->
6397 + * replace global backref ID by backref reg. exp.
6398 + */
6399 + s = replaceBackRefIdByRegExp(strPat, subsPtr, backRefList[globalId].gbreRegExpText);
6401 + strPat->spGlobalToLocalBackRef[globalId] = *localId;
6402 + (*localId) ++;
6404 + else
6406 + /*
6407 + * next occurence of global backref ID in this pattern ->
6408 + * replace global backref ID by local one
6409 + */
6410 + s = subsPtr + 1;
6411 + *s = (char)((int)('0') + strPat->spGlobalToLocalBackRef[globalId]);
6414 + else
6416 + /*
6417 + * given global backref definition is located in given string pattern
6418 + */
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";
6424 + return NULL;
6427 + /*
6428 + * replace global backref ID by local one
6429 + */
6430 + s = subsPtr + 1;
6431 + *s = (char)((int)('0') + strPatBackRef->spbreLocalBackRefID);
6434 + return s;
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,
6445 + char *regExp)
6447 + char *oldText = strPat->spText;
6448 + char *newText;
6449 + char *n;
6450 + char *continueScanPtr;
6451 + int oldLen = strlen(oldText);
6452 + int regExpLen = strlen(regExp);
6453 + int replacePos = replaceStartPtr - oldText;
6454 + int remainingLen = oldLen-replacePos-2;
6456 + /*
6457 + * replace "\n" - located at replaceStartPtr - by "(regExp)"
6458 + */
6459 + newText = XtMalloc(oldLen + regExpLen + 3);
6461 + memcpy(newText, oldText, replacePos);
6462 + n = newText + replacePos;
6463 + *n = '(';
6464 + continueScanPtr = n;
6465 + n ++;
6466 + memcpy(n, regExp, regExpLen);
6467 + n += regExpLen;
6468 + *n = ')';
6469 + n ++;
6470 + memcpy(n, replaceStartPtr+2, remainingLen);
6471 + *(n + remainingLen) = '\0';
6473 + XtFree(oldText);
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,
6488 + char *convertPtr)
6490 + char *oldText = strPat->spText;
6491 + char *newText;
6492 + int oldLen = strlen(oldText);
6493 + int convertPos = convertPtr - oldText;
6495 + /*
6496 + * replace "(*n" - located at convertPtr - by "("
6497 + */
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';
6505 + XtFree(oldText);
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(
6518 + char **inPtr,
6519 + char **errMsg,
6520 + char *name,
6521 + MatchPatternType type)
6523 + int error = False;
6524 + PatternElement *pattern;
6525 + PatternElement *allPat[MAX_STRING_PATTERNS];
6526 + int nbrOfPat = 0;
6527 + int sizeOfPat;
6528 + MatchPatternTableElement *result;
6529 + int isMonoPattern;
6530 + int skipBtwStartEnd;
6531 + int flash;
6532 + int ignoreHighLightInfo;
6533 + int i;
6535 + if (!getMPSGlobalAttribute(
6536 + inPtr,
6537 + errMsg,
6538 + &isMonoPattern,
6539 + &skipBtwStartEnd,
6540 + &flash,
6541 + &ignoreHighLightInfo ))
6543 + return NULL;
6546 + /*
6547 + * read all patterns
6548 + */
6549 + while (**inPtr != '\n' && !error)
6551 + if (!readPatternElement( inPtr, errMsg, &pattern ))
6553 + error = True;
6555 + else if (nbrOfPat >= MAX_STRING_PATTERNS)
6557 + *errMsg = "max. number of string patterns exceeded";
6558 + error = True;
6560 + else
6562 + pattern->peIndex = nbrOfPat;
6564 + allPat[nbrOfPat ++] = pattern;
6568 + if (error)
6570 + for (i=0; i < nbrOfPat; i ++)
6571 + freePatternElement( allPat[i] );
6573 + return NULL;
6576 + if (nbrOfPat == 0)
6578 + *errMsg = "min. one string pattern needed";
6579 + return NULL;
6582 + /*
6583 + * allocate & init. MatchPatternTableElement
6584 + */
6585 + result =
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 );
6609 + /*
6610 + * sort start / end / middle pattern
6611 + */
6612 + error = !sortReadPatternElementSet( &result->mpteAll, errMsg, result );
6614 + if (error)
6616 + freeMatchPatternTableElement( result );
6617 + return NULL;
6619 + else
6621 + return result;
6626 + * Sort read pattern element set into start, middle & end arrays.
6627 + * Validate "monopattern" attribute.
6628 + * Returns true, if validation was successful.
6629 + */
6630 +static int sortReadPatternElementSet(
6631 + PatternElementSet *allPat,
6632 + char **errMsg,
6633 + MatchPatternTableElement *result)
6635 + int sizeOfPat;
6636 + int isMonoPattern = result->mpteIsMonoPattern;
6638 + /*
6639 + * count number of start, middle & end pattern elements.
6640 + */
6641 + countPatternElementKind( allPat, result );
6643 + /*
6644 + * validate and allocate pattern elements.
6645 + */
6646 + if (result->mpteStart.pesNumberOfPattern != 0)
6648 + sizeOfPat = sizeof(PatternElement *) * result->mpteStart.pesNumberOfPattern;
6649 + result->mpteStart.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6651 + else
6653 + *errMsg = "min. one start pattern needed";
6654 + return False;
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]";
6662 + return False;
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 );
6676 + else
6678 + if (!isMonoPattern)
6680 + *errMsg = "min. one end pattern needed";
6681 + return False;
6685 + /*
6686 + * sort pattern elements into start, middle & end arrays.
6687 + */
6688 + sortPatternElementSet( allPat, result );
6690 + if (isMonoPattern)
6692 + copyPatternSet( &result->mpteStart, &result->mpteEnd );
6695 + return True;
6699 + * Count number of start, middle & end patterns stored in "allPat".
6700 + */
6701 +static void countPatternElementKind(
6702 + PatternElementSet *allPat,
6703 + MatchPatternTableElement *result)
6705 + int i;
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)
6719 + case PEK_START:
6720 + result->mpteStart.pesNumberOfPattern ++;
6721 + break;
6722 + case PEK_MIDDLE:
6723 + result->mpteMiddle.pesNumberOfPattern ++;
6724 + break;
6725 + case PEK_END:
6726 + result->mpteEnd.pesNumberOfPattern ++;
6727 + break;
6728 + default:;
6734 + * Sort start, middle & end pattern elements into related arrays.
6735 + */
6736 +static void sortPatternElementSet(
6737 + PatternElementSet *allPat,
6738 + MatchPatternTableElement *result)
6740 + int i;
6741 + int s,m,e;
6743 + for (i=0, s=0, m=0, e=0; i < allPat->pesNumberOfPattern; i ++)
6745 + switch (allPat->pesPattern[i]->peKind)
6747 + case PEK_START:
6748 + result->mpteStart.pesPattern[s ++] = allPat->pesPattern[i];
6749 + break;
6750 + case PEK_MIDDLE:
6751 + result->mpteMiddle.pesPattern[m ++] = allPat->pesPattern[i];
6752 + break;
6753 + case PEK_END:
6754 + result->mpteEnd.pesPattern[e ++] = allPat->pesPattern[i];
6755 + break;
6756 + default:;
6761 +static void copyPatternSet(
6762 + PatternElementSet *sourcePS,
6763 + PatternElementSet *destPS)
6765 + int sizeOfPat;
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 )
6780 + int i;
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;
6802 + int i;
6804 + if (table == NULL)
6805 + return;
6807 + XtFree(table->smtLanguageMode);
6809 + /*
6810 + * Free all matching patterns
6811 + */
6812 + patTable = table->smtAllPatterns;
6814 + for (i=0; i<patTable->mptNumberOfElements; i++)
6815 + freeMatchPatternTableElement(patTable->mptElements[i]);
6817 + XtFree((char *)patTable);
6819 + /*
6820 + * Free matching pattern group elements
6821 + */
6822 + for (i=0; i<table->smtNumberOfGroups; i++)
6823 + freeMatchPatternGroupElement(table->smtGroups[i]);
6825 + /*
6826 + * Free matching pattern sequence elements
6827 + */
6828 + for (i=0; i<table->smtNumberOfSeqElements; i++)
6829 + freeMatchPatternSequenceElement(table->smtSequence[i]);
6831 + /*
6832 + * Free keyword reg. expressions
6833 + */
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 )
6846 + int i;
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 )
6887 + int i;
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 )
6903 + int i;
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 = "";
6941 + int msgLen;
6942 + char *errorInForm = "matching pattern of \"%s\"";
6943 + char *errorIn;
6945 + if (errInfo->eiLanguageMode == NULL)
6947 + errorIn = "matching pattern";
6949 + else
6951 + errorIn = XtMalloc(strlen(errorInForm) + strlen(errInfo->eiLanguageMode)+1);
6952 + sprintf(errorIn, "matching pattern of \"%s\"", errInfo->eiLanguageMode);
6955 + if (errInfo->eiRegExpCompileMsg != NULL)
6957 + /*
6958 + * Error message of form:
6959 + * "MP \"eiMPTabElementName\", SP \"eiStringPatText\": eiRegExpCompileMsg" or
6960 + * "MP \"eiMPTabElementName\" - eiDetail: eiRegExpCompileMsg"
6961 + */
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);
6972 + else
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);
6990 + else
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)
7005 + /*
7006 + * Error message of form:
7007 + * "MP \"eiMPTabElementName\", SP \"eiStringPatText\": Backref %d eiDetail
7008 + */
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)
7016 + msgLen += 15;
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)
7040 + XtFree(message);
7043 + if (errInfo->eiLanguageMode != NULL)
7045 + XtFree(errorIn);
7048 + freeErrorInfo(errInfo);
7049 + initErrorInfo(errInfo);
7053 + * Pop-up a warning dialog showing a matching pattern set error.
7054 + */
7055 +static void dialogMatchingPatternSetError(
7056 + char *title,
7057 + ErrorInfo *errInfo)
7059 + char *message;
7060 + int msgLen = 1;
7062 + /*
7063 + * Error message of form:
7064 + * "Name : \"eiMPTabElementName\"\n
7065 + * "String: \"eiStringPatText\"\n
7066 + * eiDetail\n
7067 + * eiRegExpCompileMsg\n"
7068 + */
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)
7077 + msgLen += 15;
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);
7096 + DialogF(
7097 + DF_WARN, MatchPatternDialog.mpdShell, 1,
7098 + title,
7099 + "%s(language mode '%s')",
7100 + "OK",
7101 + message,
7102 + errInfo->eiLanguageMode);
7104 + XtFree(message);
7106 + freeErrorInfo(errInfo);
7107 + initErrorInfo(errInfo);
7111 +** Get matching pattern set name.
7112 +** Syntax:
7113 +** patternName ::= "name:"
7114 +** Returns true, if get was successful.
7116 +static int getMPSName(
7117 + char **inPtr,
7118 + ErrorInfo *errInfo,
7119 + char **name )
7121 + char *dummy;
7122 + char *field = ReadSymbolicField(inPtr);
7124 + if (field == NULL)
7126 + errInfo->eiDetail = "matching pattern name missing";
7127 + return False;
7130 + if (!SkipDelimiter(inPtr, &dummy))
7132 + errInfo->eiMPTabElementName = XtNewString(field);
7133 + errInfo->eiDetail = "':' missing after matching pattern name";
7134 + XtFree( field );
7135 + return False;
7138 + *name = field;
7140 + return True;
7144 +** Get matching pattern set type attribute.
7145 +** TypeAttribute ::=
7146 +** [s|g]:
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(
7155 + char **inPtr,
7156 + ErrorInfo *errInfo,
7157 + MatchPatternType *type)
7159 + char *field = ReadSymbolicField(inPtr);
7160 + int successful = True;
7162 + *type = MPT_INDIVIDUAL;
7164 + if (field != NULL)
7166 + switch (*field)
7168 + case 'g':
7169 + *type = MPT_GROUP;
7170 + break;
7171 + case 's':
7172 + *type = MPT_SUB;
7173 + break;
7174 + default:
7175 + errInfo->eiDetail = "unknown matching pattern type attribute";
7176 + successful = False;
7180 + if (successful)
7182 + if (!SkipDelimiter(inPtr, &errInfo->eiDetail))
7184 + successful = False;
7188 + freeXtPtr((void **)&field);
7190 + return successful;
7194 +** Syntax:
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
7206 +** ("plain").
7208 +** Returns TRUE, if global attribute was successful read.
7210 +static int getMPSGlobalAttribute(
7211 + char **inPtr,
7212 + char **errMsg,
7213 + int *isMonoPattern,
7214 + int *comment,
7215 + int *flash,
7216 + int *ignoreHighLightInfo)
7218 + char *field = ReadSymbolicField(inPtr);
7219 + char *attribute;
7220 + int successful = True;
7222 + *isMonoPattern = False;
7223 + *comment = False;
7224 + *flash = False;
7225 + *ignoreHighLightInfo = False;
7227 + if (field != NULL)
7229 + attribute = field;
7230 + while (*attribute != '\0' && successful)
7232 + switch (*attribute)
7234 + case 'c':
7235 + *comment = True;
7236 + break;
7237 + case 'f':
7238 + *flash = True;
7239 + break;
7240 + case 'm':
7241 + *isMonoPattern = True;
7242 + break;
7243 + case 'p':
7244 + *ignoreHighLightInfo = True;
7245 + break;
7246 + default:
7247 + *errMsg = "unknown global attribute";
7248 + successful = False;
7250 + attribute ++;
7254 + if (successful)
7256 + if (!SkipDelimiter(inPtr, errMsg))
7258 + successful = False;
7262 + freeXtPtr((void **)&field);
7264 + return successful;
7268 +** Get matching pattern set attribute.
7270 +** Syntax:
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(
7294 + char **inPtr,
7295 + char **errMsg,
7296 + PatternElementKind *patternKind,
7297 + PatternWordBoundary *wordBoundary,
7298 + int *caseInsensitive,
7299 + int *regularExpression)
7301 + char *field = ReadSymbolicField(inPtr);
7302 + char *attribute;
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)
7317 + case 'e':
7318 + *patternKind = PEK_END;
7319 + break;
7320 + case 'i':
7321 + *caseInsensitive = True;
7322 + break;
7323 + case 'l':
7324 + *wordBoundary = PWB_LEFT;
7325 + break;
7326 + case 'm':
7327 + *patternKind = PEK_MIDDLE;
7328 + break;
7329 + case 'r':
7330 + *wordBoundary = PWB_RIGHT;
7331 + break;
7332 + case 's':
7333 + *patternKind = PEK_START;
7334 + break;
7335 + case 'w':
7336 + *wordBoundary = PWB_BOTH;
7337 + break;
7338 + case 'x':
7339 + *regularExpression = True;
7340 + break;
7341 + default:
7342 + *errMsg = "unknown string pattern attribute";
7343 + successful = False;
7345 + attribute ++;
7349 + if (successful)
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)
7377 + case PET_SINGLE:
7378 + strPat = &patElement->peVal.peuSingle;
7379 + break;
7381 + case PET_MULTIPLE:
7382 + strPat = &patElement->peVal.peuMulti.mpStringPattern;
7384 + (*nbrOfMultiPatterns) ++;
7386 + break;
7388 + case PET_REFERENCE:
7389 + referredElement =
7390 + info->rmpiElement[patElement->peVal.peuRef.prElementIdx]->
7391 + mpteAll.pesPattern[patElement->peVal.peuRef.prPatternIdx];
7393 + strPat = &referredElement->peVal.peuMulti.mpStringPattern;
7394 + break;
7397 + /*
7398 + * reserve additional 4 characters ("(?i)") for case insensitive search
7399 + */
7400 + if (strPat->spCaseInsensitive)
7401 + patElementLen = strPat->spLength + 4;
7402 + else
7403 + patElementLen = strPat->spLength;
7405 + /*
7406 + * reserve additional 4 characters ("(?:)") for regular expression
7407 + */
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)
7423 + int i;
7424 + int totalLen = 0;
7426 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
7428 + totalLen +=
7429 + patternElementLen(
7430 + info,
7431 + element->mpteAll.pesPattern[i],
7432 + nbrOfMultiPatterns );
7435 + return totalLen;
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)
7446 + int i;
7447 + int totalLen = 0;
7449 + *nbrOfMultiPatterns = 0;
7451 + for (i=0; i<info->rmpiNbrOfElements; i ++)
7453 + totalLen +=
7454 + totalMatchPatternTableElementLen(
7455 + info,
7456 + info->rmpiElement[i],
7457 + nbrOfMultiPatterns);
7460 + return totalLen;
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;
7472 + int prevLen = 0;
7474 + /*
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.
7478 + */
7479 + switch (pattern->spWordBoundary)
7481 + case PWB_NONE:
7482 + prevLen = strlen( regExpStringInfo->resiNoneWBRegExpString );
7484 + r = regExpStringInfo->resiNoneWBRegExpString + strlen( regExpStringInfo->resiNoneWBRegExpString );
7485 + break;
7486 + case PWB_LEFT:
7487 + prevLen = strlen( regExpStringInfo->resiLeftWBRegExpString );
7488 + if (prevLen == 0)
7490 + strcpy( regExpStringInfo->resiLeftWBRegExpString, "<(?:" );
7492 + r = regExpStringInfo->resiLeftWBRegExpString + strlen( regExpStringInfo->resiLeftWBRegExpString );
7493 + break;
7494 + case PWB_RIGHT:
7495 + prevLen = strlen( regExpStringInfo->resiRightWBRegExpString );
7496 + if (prevLen == 0)
7498 + strcpy( regExpStringInfo->resiRightWBRegExpString, "(?:" );
7500 + r = regExpStringInfo->resiRightWBRegExpString + strlen( regExpStringInfo->resiRightWBRegExpString );
7501 + break;
7502 + case PWB_BOTH:
7503 + prevLen = strlen( regExpStringInfo->resiBothWBRegExpString );
7504 + if (prevLen == 0)
7506 + strcpy( regExpStringInfo->resiBothWBRegExpString, "<(?:" );
7508 + r = regExpStringInfo->resiBothWBRegExpString + strlen( regExpStringInfo->resiBothWBRegExpString );
7509 + break;
7512 + /*
7513 + * add an "or" if there is already a pattern in the buffer
7514 + */
7515 + if (prevLen != 0)
7517 + *r++ = '|';
7520 + /*
7521 + * add "(?i" to order case insensitive search
7522 + */
7523 + if (pattern->spCaseInsensitive)
7525 + *r++ = '(';
7526 + *r++ = '?';
7527 + *r++ = 'i';
7530 + /*
7531 + * add "(?:" to group this regular expression
7532 + */
7533 + if (pattern->spRegularExpression)
7535 + *r++ = '(';
7536 + *r++ = '?';
7537 + *r++ = ':';
7539 + adaptedRegExpText =
7540 + adaptLocalBackRefs(
7541 + pattern->spText,
7542 + &regExpStringInfo->resiLocalBackRefID);
7544 + s = adaptedRegExpText;
7546 + else
7548 + s = pattern->spText;
7551 + /*
7552 + * add the pattern characters - evtl. escaped, if special
7553 + * regular expression symbols & pattern is no reg. exp. -
7554 + * to the buffer:
7555 + */
7557 + while (*s != '\0')
7559 + if (!pattern->spRegularExpression)
7561 + switch (*s)
7563 + case '(':
7564 + case ')':
7565 + case '-':
7566 + case '[':
7567 + case ']':
7568 + case '<':
7569 + case '>':
7570 + case '{':
7571 + case '}':
7572 + case '.':
7573 + case '\\':
7574 + case '|':
7575 + case '^':
7576 + case '$':
7577 + case '*':
7578 + case '+':
7579 + case '?':
7580 + case '&':
7581 + *r++ = '\\';
7582 + break;
7583 + };
7586 + *r++ = *s++;
7589 + /*
7590 + * close "reg. exp. group" bracket
7591 + */
7592 + if (pattern->spRegularExpression)
7594 + *r++ = ')';
7596 + XtFree(adaptedRegExpText);
7599 + /*
7600 + * close case insensitive search bracket
7601 + */
7602 + if (pattern->spCaseInsensitive)
7604 + *r++ = ')';
7607 + /*
7608 + * terminate added string
7609 + */
7610 + *r = '\0';
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(
7618 + char *regExpText,
7619 + int *commonLocalId)
7621 + int id;
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];
7628 + /*
7629 + * put all local backrefs into "localBackRefList".
7630 + */
7631 + scanForLocalBackRefs(regExpText, localBackRefList);
7633 + while (*s != '\0')
7635 + *n++ = *s;
7637 + if (*s == '\\')
7639 + s++;
7641 + if (isdigit((unsigned char)*s))
7643 + /*
7644 + * \n (n=1..9) found: replace local backref.
7645 + * by "common local ID"
7646 + */
7647 + 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]);
7655 + else
7657 + *n++ = '0';
7660 + s ++;
7662 + else if (*s != '\0')
7664 + /*
7665 + * copy escaped character
7666 + */
7667 + *n++ = *s++;
7670 + else if (*s == '(')
7672 + s ++;
7674 + if (*s == '?')
7676 + /*
7677 + * non capturing parentheses found -> just copy it
7678 + */
7679 + *n++ = *s++;
7681 + else
7683 + /*
7684 + * capturing parentheses found:
7685 + */
7686 + if (localBackRefList[ownLocalId] == LOCAL_BACK_REF_ID_USED)
7688 + /*
7689 + * backref used within given reg. exp. text:
7690 + * remember common local id for replacement later on
7691 + */
7692 + localBackRefList[ownLocalId] = *commonLocalId;
7693 + (*commonLocalId) ++;
7694 + ownLocalId ++;
7696 + else
7698 + /*
7699 + * backref not used within given reg. exp. text:
7700 + * replace capturing parentheses by non capturing one
7701 + */
7702 + *n++ = '?';
7703 + *n++ = ':';
7707 + else
7709 + s ++;
7713 + /*
7714 + * terminate adapted string
7715 + */
7716 + *n = '\0';
7718 + return newRegExpText;
7722 +** Get all local backrefs of given regExpText and put them into
7723 +** given localBackRefList.
7725 +static void scanForLocalBackRefs(
7726 + char *regExpText,
7727 + int *localBackRefList)
7729 + int i;
7730 + int localId;
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')
7740 + if (*s == '\\')
7742 + if (isdigit((unsigned char)*(s+1)))
7744 + /*
7745 + * \n (n=1..9) found: flag usage in local backref list
7746 + */
7747 + localId =
7748 + (int)((unsigned char)*(s+1) - (unsigned char)'0') - 1;
7750 + localBackRefList[localId] = LOCAL_BACK_REF_ID_USED;
7752 + s ++;
7754 + else if (*(s+1) != '\0')
7755 + s ++;
7757 + s ++;
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)
7769 + int i;
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)
7780 + return False;
7784 + newPR = (PatternReference *)XtMalloc(sizeof(PatternReference));
7786 + *newPR = *toBeAddedPR;
7788 + regExpStringInfo->resiAddedMultiPat[regExpStringInfo->resiNbrOfAddedMultiPat ++] = newPR;
7790 + return True;
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)
7807 + case PET_SINGLE:
7808 + addPatternToRegExpString(
7809 + &(patElement->peVal.peuSingle),
7810 + regExpStringInfo);
7811 + break;
7813 + case PET_MULTIPLE:
7814 + /*
7815 + * add element to reg. exp. string only, if it was
7816 + * not added before.
7817 + */
7818 + if (isMultiPatternNotAdded(regExpStringInfo, patElementReference))
7820 + addPatternToRegExpString(
7821 + &(patElement->peVal.peuMulti.mpStringPattern),
7822 + regExpStringInfo);
7824 + break;
7826 + case PET_REFERENCE:
7827 + /*
7828 + * add referred element to reg. exp. string only, if related
7829 + * multi pattern was not added before.
7830 + */
7831 + referredPatReference = patElement->peVal.peuRef;
7833 + referredElement =
7834 + readMatchPatternInfo->rmpiElement[referredPatReference.prElementIdx]->
7835 + mpteAll.pesPattern[referredPatReference.prPatternIdx];
7837 + if (isMultiPatternNotAdded(regExpStringInfo, &referredPatReference))
7839 + addPatternToRegExpString(
7840 + &(referredElement->peVal.peuMulti.mpStringPattern),
7841 + regExpStringInfo);
7843 + break;
7848 +** add given MatchPatternTableElement to given reg. ex. strings
7850 +static void addElementToRegExpString(
7851 + MatchPatternTableElement *element,
7852 + ReadMatchPatternInfo *readMatchPatternInfo,
7853 + RegExpStringInfo *regExpStringInfo)
7855 + int i;
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],
7866 + &elementRef,
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)
7881 + int resultingLen;
7883 + /*
7884 + * allocate & init. a buffer for the resulting regular expression
7885 + */
7886 + resultingLen =
7887 + strlen( regExpStringInfo->resiNoneWBRegExpString ) +
7888 + strlen( regExpStringInfo->resiLeftWBRegExpString ) +
7889 + strlen( regExpStringInfo->resiRightWBRegExpString ) +
7890 + strlen( regExpStringInfo->resiBothWBRegExpString ) + 5;
7892 + *regExpString = XtMalloc( resultingLen );
7894 + strcpy( *regExpString, "" );
7896 + /*
7897 + * add the single parts to the resulting regular expression
7898 + * (= cat of parts separated by an "or")
7899 + */
7900 + addSMTRegExpString( *regExpString, regExpStringInfo->resiNoneWBRegExpString, "" );
7901 + addSMTRegExpString( *regExpString, regExpStringInfo->resiLeftWBRegExpString, ")" );
7902 + addSMTRegExpString( *regExpString, regExpStringInfo->resiRightWBRegExpString, ")>" );
7903 + addSMTRegExpString( *regExpString, regExpStringInfo->resiBothWBRegExpString, ")>" );
7905 + /*
7906 + * free buffers
7907 + */
7908 + freeRegExpStringInfo( regExpStringInfo );
7912 +** Free the allocated memory contained in a RegExpStringInfo data structure
7914 +static void freeRegExpStringInfo(
7915 + RegExpStringInfo *regExpStringInfo)
7917 + int i;
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)
7938 + int i;
7939 + RegExpStringInfo regExpStringInfo;
7940 + PatternReference elementRef;
7941 + PatternElementSet startPat = element->mpteStart;
7942 + PatternElementSet endPat = element->mpteEnd;
7944 + /*
7945 + * Allocate buffers for keyword regular expression.
7946 + */
7947 + setupRegExpStringBuffers(
7948 + readMatchPatternInfo,
7949 + &regExpStringInfo);
7951 + /*
7952 + * Treat start / end element of MatchPatternTableElement
7953 + */
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],
7963 + &elementRef,
7964 + readMatchPatternInfo,
7965 + &regExpStringInfo);
7968 + for (i=0; i < endPat.pesNumberOfPattern; i ++)
7970 + elementRef.prPatternIdx = endPat.pesPattern[i]->peIndex;
7972 + addUniquePatternToRegExpString(
7973 + endPat.pesPattern[i],
7974 + &elementRef,
7975 + readMatchPatternInfo,
7976 + &regExpStringInfo);
7979 + /*
7980 + * Assemble the resulting regular expression
7981 + */
7982 + catSMTRegExpStrings(
7983 + &regExpStringInfo,
7984 + regExpString);
7987 +static void copyStringMatchTableForDialog(
7988 + StringMatchTable *sourceTable,
7989 + DialogMatchPatternInfo *dialogTable )
7991 + int i;
7993 + /*
7994 + * if no source table exist (yet), then set nbr. of elements / groups to 0
7995 + */
7996 + if (sourceTable == NULL)
7998 + dialogTable->dmpiNbrOfSeqElements = 0;
8000 + return;
8003 + /*
8004 + * copy matching pattern sequence
8005 + */
8006 + dialogTable->dmpiNbrOfSeqElements = sourceTable->smtNumberOfSeqElements;
8008 + for (i=0; i < sourceTable->smtNumberOfSeqElements; i ++)
8010 + copySequenceElementForDialog(
8011 + sourceTable,
8012 + sourceTable->smtSequence[i],
8013 + &dialogTable->dmpiSequence[i] );
8017 +static void *copyMatchPatternElementForDialog(
8018 + MatchPatternTable *table,
8019 + int sourceElementIdx)
8021 + int i;
8022 + int patIdx = 0;
8023 + MatchPatternTableElement *sourceElement;
8024 + DialogMatchPatternTableElement *destination;
8026 + sourceElement = table->mptElements[sourceElementIdx];
8028 + destination =
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(
8040 + table,
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);
8063 + else
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)
8075 + int i;
8076 + DialogMatchPatternGroupElement *destination;
8078 + 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;
8100 + 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]);
8115 + else
8117 + destSeqElement->dmpsePtr =
8118 + copyMatchPatternElementForDialog(
8119 + sourceTable->smtAllPatterns,
8120 + sourceSeqElement->mpseIndex);
8124 +static DialogMatchPatternSequenceElement *copyDialogSequenceElement(
8125 + DialogMatchPatternSequenceElement *sourceSeq)
8127 + DialogMatchPatternSequenceElement *destSeq;
8129 + 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;
8138 + return destSeq;
8141 +static void freeDialogMatchPatternElement(
8142 + DialogMatchPatternTableElement *dialogElement )
8144 + int i;
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 )
8168 + int i;
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 );
8190 + else
8192 + freeDialogMatchPatternElement(
8193 + (DialogMatchPatternTableElement *)dialogSeq->dmpsePtr );
8196 + freeXtPtr((void **)&dialogSeq);
8199 +static void copyDialogStringPatternsFromTable(
8200 + DialogMatchPatternTableElement *tableElement,
8201 + DialogStringPatterns *destPatterns)
8203 + int i;
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)
8220 + int i;
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)
8236 + int i;
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)
8266 + int i;
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)
8299 + int i;
8301 + destGroup->dmpgeNumberOfSubPatterns =
8302 + sourceNames->dspNumberOfPatterns;
8304 + for (i=0; i<destGroup->dmpgeNumberOfSubPatterns; i++)
8306 + destGroup->dmpgeSubPatternIds[i] =
8307 + XtNewString(
8308 + sourceNames->dspElements[i]->dspeText);
8314 +** Present a dialog for editing matching pattern information
8316 +void EditMatchPatterns(WindowInfo *window)
8318 + Widget form, lmOptMenu;
8319 + Widget lmForm;
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;
8330 + XmString s1;
8331 + int n;
8332 + Arg args[20];
8334 + /*
8335 + * if the dialog is already displayed, just pop it to the top and return
8336 + */
8337 + if (MatchPatternDialog.mpdShell != NULL)
8339 + RaiseDialogWindow(MatchPatternDialog.mpdShell);
8340 + return;
8343 + /*
8344 + * decide on an initial language mode
8345 + */
8346 + MatchPatternDialog.mpdLangModeName =
8347 + XtNewString(
8348 + window->languageMode == PLAIN_LANGUAGE_MODE ?
8349 + PLAIN_LM_STRING : LanguageModeName(window->languageMode));
8351 + /*
8352 + * find the associated matching pattern table to edit
8353 + */
8354 + table = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
8356 + /*
8357 + * copy the list of patterns to one that the user can freely edit
8358 + */
8359 + copyStringMatchTableForDialog( table, &MatchPatternDialog.mpdTable );
8361 + /*
8362 + * init. status information of dialog
8363 + */
8364 + MatchPatternDialog.currentDmptSeqElement = NULL;
8365 + MatchPatternDialog.currentDmptElement = NULL;
8366 + MatchPatternDialog.currentDmptGroup = NULL;
8368 + MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns = 0;
8369 + MatchPatternDialog.mpdStringPatternIsDisplayed = True;
8371 + /*
8372 + * Create a form widget in an application shell
8373 + */
8374 + n = 0;
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,
8388 + form,
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);
8399 + n = 0;
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:"),
8412 + XmNmnemonic, 'M',
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);
8420 + XmStringFree(s1);
8422 + lmBtn = XtVaCreateManagedWidget("lmBtn", xmPushButtonWidgetClass, lmForm,
8423 + XmNlabelString, s1=MKSTRING("Add / Modify\nLanguage Mode..."),
8424 + XmNmnemonic, 'A',
8425 + XmNrightAttachment, XmATTACH_FORM,
8426 + XmNtopAttachment, XmATTACH_FORM, NULL);
8427 + XtAddCallback(lmBtn, XmNactivateCallback, pmLanguageModeDialogCB, NULL);
8428 + XmStringFree(s1);
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);
8439 + XmStringFree(s1);
8441 + applyBtn = XtVaCreateManagedWidget("apply", xmPushButtonWidgetClass, form,
8442 + XmNlabelString, s1=XmStringCreateSimple("Apply"),
8443 + XmNmnemonic, 'y',
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);
8451 + XmStringFree(s1);
8453 + checkBtn = XtVaCreateManagedWidget("check", xmPushButtonWidgetClass, form,
8454 + XmNlabelString, s1=XmStringCreateSimple("Check"),
8455 + XmNmnemonic, 'k',
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);
8463 + XmStringFree(s1);
8465 + deleteBtn = XtVaCreateManagedWidget("delete", xmPushButtonWidgetClass, form,
8466 + XmNlabelString, s1=XmStringCreateSimple("Delete"),
8467 + XmNmnemonic, 'D',
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);
8475 + XmStringFree(s1);
8477 + restoreBtn = XtVaCreateManagedWidget("restore", xmPushButtonWidgetClass, form,
8478 + XmNlabelString, s1=XmStringCreateSimple("Restore Defaults"),
8479 + XmNmnemonic, 'f',
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);
8487 + XmStringFree(s1);
8489 + closeBtn = XtVaCreateManagedWidget("close", xmPushButtonWidgetClass,
8490 + form,
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);
8499 + XmStringFree(s1);
8501 + helpBtn = XtVaCreateManagedWidget("help", xmPushButtonWidgetClass,
8502 + form,
8503 + XmNlabelString, s1=XmStringCreateSimple("Help"),
8504 + XmNmnemonic, 'H',
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);
8512 + XmStringFree(s1);
8514 + stringPatternsFrame = XtVaCreateManagedWidget("stringPatternsFrame", xmFrameWidgetClass,
8515 + form,
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);
8530 + XmStringFree(s1);
8532 + n = 0;
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);
8558 + XmStringFree(s1);
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,
8571 + XmNset, True,
8572 + XmNmarginHeight, 0,
8573 + XmNlabelString, s1=XmStringCreateSimple(
8574 + "Start"),
8575 + NULL);
8576 + XmStringFree(s1);
8577 + MatchPatternDialog.sptMiddleW = XtVaCreateManagedWidget("sptMiddleW",
8578 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8579 + XmNmarginHeight, 0,
8580 + XmNlabelString, s1=XmStringCreateSimple(
8581 + "Middle"),
8582 + NULL);
8583 + XmStringFree(s1);
8584 + MatchPatternDialog.sptEndW = XtVaCreateManagedWidget("sptEndW",
8585 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8586 + XmNmarginHeight, 0,
8587 + XmNlabelString, s1=XmStringCreateSimple(
8588 + "End"),
8589 + NULL);
8590 + XmStringFree(s1);
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,
8601 + NULL);
8602 + XmStringFree(s1);
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,
8615 + XmNset, True,
8616 + XmNmarginHeight, 0,
8617 + XmNlabelString, s1=XmStringCreateSimple(
8618 + "Both (pattern is word)"),
8619 + NULL);
8620 + XmStringFree(s1);
8621 + MatchPatternDialog.wbbLeftW = XtVaCreateManagedWidget("wbbLeftW",
8622 + xmToggleButtonWidgetClass, wordBoundaryBox,
8623 + XmNmarginHeight, 0,
8624 + XmNlabelString, s1=XmStringCreateSimple(
8625 + "Left"),
8626 + NULL);
8627 + XmStringFree(s1);
8628 + MatchPatternDialog.wbbRightW = XtVaCreateManagedWidget("wbbRightW",
8629 + xmToggleButtonWidgetClass, wordBoundaryBox,
8630 + XmNmarginHeight, 0,
8631 + XmNlabelString, s1=XmStringCreateSimple(
8632 + "Right"),
8633 + NULL);
8634 + XmStringFree(s1);
8635 + MatchPatternDialog.wbbNoneW = XtVaCreateManagedWidget("wbbNoneW",
8636 + xmToggleButtonWidgetClass, wordBoundaryBox,
8637 + XmNmarginHeight, 0,
8638 + XmNlabelString, s1=XmStringCreateSimple(
8639 + "None"),
8640 + NULL);
8641 + XmStringFree(s1);
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);
8652 + XmStringFree(s1);
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,
8664 + XmNset, False,
8665 + XmNmarginHeight, 0,
8666 + XmNlabelString, s1=XmStringCreateSimple(
8667 + "Regular Expression"),
8668 + NULL);
8669 + XmStringFree(s1);
8670 + XtAddCallback(MatchPatternDialog.sabRegularExpressionW, XmNvalueChangedCallback,
8671 + strPatRegExpressionCB, NULL);
8672 + MatchPatternDialog.sabCaseSensitiveW = XtVaCreateManagedWidget("sabCaseSensitiveW",
8673 + xmToggleButtonWidgetClass, stringAttributesBox,
8674 + XmNset, True,
8675 + XmNmarginHeight, 0,
8676 + XmNlabelString, s1=XmStringCreateSimple(
8677 + "Case Sensitive"),
8678 + NULL);
8679 + XmStringFree(s1);
8681 + MatchPatternDialog.mpdStringPatternLbl = XtVaCreateManagedWidget("mpdStringPatternLbl", xmLabelGadgetClass,
8682 + stringPatternsForm,
8683 + XmNlabelString, s1=XmStringCreateSimple("String Pattern"),
8684 + XmNmnemonic, 'S',
8685 + XmNalignment, XmALIGNMENT_BEGINNING,
8686 + XmNleftAttachment, XmATTACH_POSITION,
8687 + XmNleftPosition, LIST_RIGHT,
8688 + XmNtopAttachment, XmATTACH_WIDGET,
8689 + XmNtopWidget, stringAttributesBox,
8690 + XmNtopOffset, BORDER,
8691 + NULL);
8692 + XmStringFree(s1);
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,
8702 + NULL);
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"),
8709 + XmNmnemonic, 't',
8710 + XmNalignment, XmALIGNMENT_BEGINNING,
8711 + XmNleftAttachment, XmATTACH_POSITION,
8712 + XmNleftPosition, LIST_RIGHT,
8713 + XmNtopAttachment, XmATTACH_WIDGET,
8714 + XmNtopWidget, MatchPatternDialog.mpdStringPatternW,
8715 + XmNtopOffset, BORDER,
8716 + NULL);
8717 + XmStringFree(s1);
8719 + MatchPatternDialog.mpdSubPatNamesPulldown =
8720 + createSubPatternNameMenu(stringPatternsForm, NULL, False);
8722 + n = 0;
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);
8737 + XtVaSetValues(
8738 + MatchPatternDialog.mpdSubPatNamesLbl,
8739 + XmNuserData, XtParent(MatchPatternDialog.mpdSubPatNamesOptMenu),
8740 + NULL);
8742 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesLbl, False);
8743 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesOptMenu, False);
8745 + matchPatternsFrame = XtVaCreateManagedWidget("matchPatternsFrame", xmFrameWidgetClass,
8746 + form,
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"),
8761 + XmNmnemonic, 'P',
8762 + XmNmarginHeight, 0,
8763 + XmNchildType, XmFRAME_TITLE_CHILD, NULL);
8764 + XmStringFree(s1);
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);
8774 + XmStringFree(s1);
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,
8786 + XmNset, True,
8787 + XmNmarginHeight, 0,
8788 + XmNlabelString, s1=XmStringCreateSimple(
8789 + "Individual"),
8790 + XmNmnemonic, 'I', NULL);
8791 + XmStringFree(s1);
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);
8800 + XmStringFree(s1);
8801 + XtAddCallback(MatchPatternDialog.mptbSubPatternW, XmNvalueChangedCallback,
8802 + matchPatTypeCB, NULL);
8803 + MatchPatternDialog.mptbContextGroupW = XtVaCreateManagedWidget("mptbContextGroupW",
8804 + xmToggleButtonWidgetClass, matchPatternTypeBox,
8805 + XmNmarginHeight, 0,
8806 + XmNlabelString, s1=XmStringCreateSimple(
8807 + "Context group"),
8808 + XmNmnemonic, 'g', NULL);
8809 + XmStringFree(s1);
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);
8823 + XmStringFree(s1);
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);
8838 + XmStringFree(s1);
8839 + MatchPatternDialog.gabFlashW = XtVaCreateManagedWidget("gabFlashW",
8840 + xmToggleButtonWidgetClass, globalAttributesBox,
8841 + XmNset, True,
8842 + XmNmarginHeight, 0,
8843 + XmNlabelString, s1=XmStringCreateSimple(
8844 + "Flash matching pattern"),
8845 + XmNmnemonic, 'l', NULL);
8846 + XmStringFree(s1);
8847 + MatchPatternDialog.gabSyntaxBasedW = XtVaCreateManagedWidget("gabSyntaxBasedW",
8848 + xmToggleButtonWidgetClass, globalAttributesBox,
8849 + XmNset, True,
8850 + XmNmarginHeight, 0,
8851 + XmNlabelString, s1=XmStringCreateSimple(
8852 + "Syntax based"),
8853 + XmNmnemonic, 'b', NULL);
8854 + XmStringFree(s1);
8856 + MatchPatternDialog.mpdMatchPatternNameLbl = XtVaCreateManagedWidget("mpdMatchPatternNameLbl", xmLabelGadgetClass,
8857 + matchPatternsForm,
8858 + XmNlabelString, s1=XmStringCreateSimple(MATCH_PAT_NAME_LBL_TXT),
8859 + XmNmnemonic, 'N',
8860 + XmNalignment, XmALIGNMENT_BEGINNING,
8861 + XmNleftAttachment, XmATTACH_POSITION,
8862 + XmNleftPosition, LIST_RIGHT,
8863 + XmNtopAttachment, XmATTACH_WIDGET,
8864 + XmNtopWidget, globalAttributesBox,
8865 + XmNtopOffset, BORDER, NULL);
8866 + XmStringFree(s1);
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,
8878 + NULL);
8879 + RemapDeleteKey(MatchPatternDialog.mpdMatchPatternNameW);
8880 + XtVaSetValues(MatchPatternDialog.mpdMatchPatternNameLbl, XmNuserData, MatchPatternDialog.mpdMatchPatternNameW, NULL);
8882 + n = 0;
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",
8894 + args, n,
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);
8904 + /*
8905 + * set initial default button
8906 + */
8907 + XtVaSetValues(form, XmNdefaultButton, okBtn, NULL);
8908 + XtVaSetValues(form, XmNcancelButton, closeBtn, NULL);
8910 + /*
8911 + * handle mnemonic selection of buttons and focus to dialog
8912 + */
8913 + AddDialogMnemonicHandler(form, False);
8915 + /*
8916 + * fill in the dialog information for the selected language mode
8917 + */
8918 + SetLangModeMenu(MatchPatternDialog.mpdLmOptMenu, MatchPatternDialog.mpdLangModeName);
8920 + /*
8921 + * realize all of the widgets in the new dialog
8922 + */
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;
8934 + XmString s1;
8935 + int regularExpression =
8936 + XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
8938 + /*
8939 + * check, if dialog mode needs to be switched
8940 + */
8941 + if (MatchPatternDialog.mpdStringPatternIsDisplayed == dialogShowsStringPattern)
8943 + return;
8946 + if (dialogShowsStringPattern)
8948 + matchPatternNameText = MATCH_PAT_NAME_LBL_TXT;
8949 + strPatCxtGrpListText = STRING_PATTERNS_LBL_TXT;
8951 + else
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);
8979 + XtVaSetValues(
8980 + MatchPatternDialog.mpdMatchPatternNameLbl,
8981 + XmNlabelString, s1=XmStringCreateSimple(matchPatternNameText),
8982 + NULL);
8983 + XmStringFree(s1);
8985 + XtVaSetValues(
8986 + MatchPatternDialog.mpdStringPatternsLbl,
8987 + XmNlabelString, s1=XmStringCreateSimple(strPatCxtGrpListText),
8988 + NULL);
8989 + XmStringFree(s1);
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)
9005 + char *modeName;
9006 + StringMatchTable *oldTable, *newTable;
9007 + StringMatchTable emptyTable = {"", NULL, NULL, NULL, NULL, 0, NULL, 0, NULL};
9008 + StringMatchTable *table;
9009 + DMPTranslationResult translResult;
9010 + int resp;
9012 + /*
9013 + * Get the newly selected mode name. If it's the same, do nothing
9014 + */
9015 + XtVaGetValues(w, XmNuserData, &modeName, NULL);
9016 + if (!strcmp(modeName, MatchPatternDialog.mpdLangModeName))
9017 + return;
9019 + /*
9020 + * Look up the original version of the patterns being edited
9021 + */
9022 + oldTable = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
9023 + if (oldTable == NULL)
9024 + oldTable = &emptyTable;
9026 + /*
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.
9030 + */
9031 + newTable = getDialogStringMatchTable(&translResult);
9033 + if (translResult == DMPTR_EMPTY)
9035 + newTable = &emptyTable;
9038 + if (newTable == NULL)
9040 + if (DialogF(
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)
9047 + SetLangModeMenu(
9048 + MatchPatternDialog.mpdLmOptMenu,
9049 + MatchPatternDialog.mpdLangModeName);
9051 + return;
9054 + else if (stringMatchTableDiffer(oldTable, newTable))
9056 + if (newTable == &emptyTable)
9057 + newTable = NULL;
9059 + resp =
9060 + DialogF(
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);
9067 + if (resp == 3)
9069 + SetLangModeMenu(
9070 + MatchPatternDialog.mpdLmOptMenu,
9071 + MatchPatternDialog.mpdLangModeName);
9073 + freeStringMatchTable( newTable );
9075 + return;
9077 + else if (resp == 1)
9079 + updateStringMatchTable( newTable );
9081 + /*
9082 + * Don't free the new table due to it's stored in MatchTables now
9083 + */
9084 + newTable = NULL;
9088 + if (newTable != NULL && newTable != &emptyTable)
9089 + freeStringMatchTable(newTable);
9091 + /*
9092 + * Free the old dialog information
9093 + */
9094 + freeVariableDialogData(DISCARD_LANGUAGE_MODE);
9096 + /*
9097 + * Fill the dialog with the new language mode information
9098 + */
9099 + MatchPatternDialog.mpdLangModeName = XtNewString(modeName);
9101 + /*
9102 + * Find the associated matching pattern table to edit
9103 + */
9104 + table = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
9106 + /*
9107 + * Copy the list of patterns to one that the user can freely edit
9108 + */
9109 + copyStringMatchTableForDialog( table, &MatchPatternDialog.mpdTable );
9111 + /*
9112 + * Update dialog fields
9113 + */
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)
9129 + Widget oldMenu;
9131 + if (MatchPatternDialog.mpdShell == NULL)
9132 + return;
9134 + oldMenu = MatchPatternDialog.mpdLmPulldown;
9135 + /*
9136 + * don't include "PLAIN" (4th parameter) in LM menu
9137 + */
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,
9148 + void *cbArg)
9150 + DialogMatchPatternSequenceElement *newSeq;
9152 + /*
9153 + * If the dialog is currently displaying the "new" entry and the
9154 + * fields are empty, that's just fine
9155 + */
9156 + if (oldItem == NULL && matchPatternDialogEmpty())
9157 + return NULL;
9159 + /*
9160 + * Read string patterns / sub-pattern names area first
9161 + */
9162 + UpdateManagedList(MatchPatternDialog.mpdStringPatternsListW, True);
9164 + /*
9165 + * If there are no problems reading the data, just return it
9166 + */
9167 + newSeq = readMatchPatternFields(True);
9168 + if (newSeq != NULL)
9169 + return (void *)newSeq;
9171 + /*
9172 + * If there are problems, and the user didn't ask for the fields to be
9173 + * read, give more warning
9174 + */
9175 + if (!explicitRequest)
9177 + if (DialogF(
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
9184 + ? NULL
9185 + : (void *)copyDialogSequenceElement(
9186 + (DialogMatchPatternSequenceElement *)oldItem);
9190 + /*
9191 + * read data again without "silent" mode to display warning
9192 + */
9193 + newSeq = readMatchPatternFields(False);
9194 + *abort = True;
9196 + return NULL;
9199 +static void setMatchPatternDisplayedCB(void *item, void *cbArg)
9201 + DialogMatchPatternSequenceElement *seqElement;
9202 + DialogMatchPatternTableElement *element;
9203 + DialogMatchPatternGroupElement *group;
9204 + int isGroup;
9206 + seqElement = (DialogMatchPatternSequenceElement *)item;
9208 + MatchPatternDialog.currentDmptSeqElement = seqElement;
9210 + if (item == NULL)
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 );
9228 + else
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);
9238 + else
9239 + RadioButtonChangeState(MatchPatternDialog.mptbContextGroupW, True, True);
9241 + freeDialogStringPatterns(
9242 + &MatchPatternDialog.currentStringPatterns);
9244 + if (isGroup)
9246 + group = (DialogMatchPatternGroupElement *)seqElement->dmpsePtr;
9247 + MatchPatternDialog.currentDmptElement = NULL;
9248 + MatchPatternDialog.currentDmptGroup = group;
9250 + copyDialogPatternNamesFromGroup(
9251 + group,
9252 + &MatchPatternDialog.currentStringPatterns);
9254 + else
9256 + element = (DialogMatchPatternTableElement *)seqElement->dmpsePtr;
9257 + MatchPatternDialog.currentDmptElement = element;
9258 + MatchPatternDialog.currentDmptGroup = NULL;
9260 + RadioButtonChangeState(
9261 + MatchPatternDialog.gabSkipBtwStartEndW,
9262 + element->dmpteSkipBtwnStartEnd,
9263 + False);
9264 + RadioButtonChangeState(
9265 + MatchPatternDialog.gabFlashW,
9266 + element->dmpteFlash,
9267 + False);
9268 + RadioButtonChangeState(
9269 + MatchPatternDialog.gabSyntaxBasedW,
9270 + !element->dmpteIgnoreHighLightInfo,
9271 + False);
9273 + copyDialogStringPatternsFromTable(
9274 + element,
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 );
9305 + return True;
9308 +static void *getStringPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
9309 + void *cbArg)
9311 + DialogStringPatternElement *newPat;
9312 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9314 + /*
9315 + * If the string pattern frame is currently displaying the "new" entry and the
9316 + * fields are empty, that's just fine
9317 + */
9318 + if (oldItem == NULL && stringPatternFieldsEmpty(isRelatedToGroup))
9319 + return NULL;
9321 + /*
9322 + * If there are no problems reading the data, just return it
9323 + */
9324 + newPat = readStringPatternFrameFields(True);
9325 + if (newPat != NULL)
9326 + return (void *)newPat;
9328 + /*
9329 + * If there are problems, and the user didn't ask for the fields to be
9330 + * read, give more warning
9331 + */
9333 + if (!explicitRequest)
9335 + if (DialogF(
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
9342 + ? NULL
9343 + : (void *)copyDialogStringPatternElement(
9344 + (DialogStringPatternElement *)oldItem);
9348 + /*
9349 + * read data again without "silent" mode to display warning
9350 + */
9351 + newPat = readStringPatternFrameFields(False);
9352 + *abort = True;
9354 + return NULL;
9357 +static void setStringPatternDisplayedCB(void *item, void *cbArg)
9359 + DialogStringPatternElement *element = (DialogStringPatternElement *)item;
9360 + PatternElementKind peKind;
9361 + PatternWordBoundary wordBoundary;
9362 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9364 + if (item == NULL)
9366 + if (isRelatedToGroup)
9368 + updateSubPatternNameMenu(NULL, False);
9370 + else
9372 + XmTextSetString(MatchPatternDialog.mpdStringPatternW, "");
9374 + setSensitiveWordBoundaryBox( True );
9376 + RadioButtonChangeState(MatchPatternDialog.wbbBothW, True, True);
9378 + /*
9379 + * type of "new" string pattern:
9380 + * preset "start", if no string pattern exists at all;
9381 + * else select "end"
9382 + */
9383 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
9384 + RadioButtonChangeState(MatchPatternDialog.sptStartW, True, True);
9385 + else
9386 + RadioButtonChangeState(MatchPatternDialog.sptEndW, True, True);
9388 + RadioButtonChangeState(MatchPatternDialog.sabCaseSensitiveW, True, False);
9389 + RadioButtonChangeState(MatchPatternDialog.sabRegularExpressionW, False, False);
9392 + else
9394 + if (isRelatedToGroup)
9396 + updateSubPatternNameMenu(element->dspeText, False);
9398 + else
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);
9409 + else
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);
9418 + else
9419 + RadioButtonChangeState(MatchPatternDialog.wbbNoneW, True, True);
9421 + RadioButtonChangeState(
9422 + MatchPatternDialog.sabCaseSensitiveW,
9423 + !element->dspeCaseInsensitive,
9424 + False);
9426 + RadioButtonChangeState(
9427 + MatchPatternDialog.sabRegularExpressionW,
9428 + element->dspeRegularExpression,
9429 + False);
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)
9454 + /*
9455 + * change the matching pattern
9456 + */
9457 + if (!getAndUpdateStringMatchTable())
9458 + return;
9460 + /*
9461 + * pop down and destroy the dialog
9462 + */
9463 + XtDestroyWidget(MatchPatternDialog.mpdShell);
9466 +static void applyCB(Widget w, XtPointer clientData, XtPointer callData)
9468 + /*
9469 + * change the matching pattern
9470 + */
9471 + getAndUpdateStringMatchTable();
9474 +static void checkCB(Widget w, XtPointer clientData, XtPointer callData)
9476 + StringMatchTable *newTable;
9477 + DMPTranslationResult translResult;
9479 + /*
9480 + * Get the current information displayed by the dialog.
9481 + * If a new table is available, then the test is passed successfully.
9482 + */
9483 + newTable = getDialogStringMatchTable(&translResult);
9485 + if (newTable != NULL)
9487 + DialogF(
9488 + DF_INF, MatchPatternDialog.mpdShell, 1,
9489 + "Matching Patterns Checked",
9490 + "Matching Patterns checked without error",
9491 + "OK");
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)
9505 + DialogF(
9506 + DF_WARN, MatchPatternDialog.mpdShell, 1,
9507 + "No Default Matching Pattern",
9508 + "There is no default matching pattern set\nfor language mode %s",
9509 + "OK",
9510 + MatchPatternDialog.mpdLangModeName);
9512 + return;
9515 + if (DialogF(
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);
9526 + return;
9529 + /*
9530 + * if a stored version of the matching pattern set exists, replace it.
9531 + * if it doesn't, add a new one.
9532 + */
9533 + updateStringMatchTable( defaultTable );
9535 + /*
9536 + * free the old dialog information
9537 + */
9538 + freeVariableDialogData(KEEP_LANGUAGE_MODE);
9540 + /*
9541 + * update the dialog
9542 + */
9543 + copyStringMatchTableForDialog( defaultTable, &MatchPatternDialog.mpdTable );
9545 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9546 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9549 +static void deleteCB(Widget w, XtPointer clientData, XtPointer callData)
9551 + if (DialogF(
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)
9560 + return;
9563 + /*
9564 + * if a stored version of the matching pattern exists, delete it from the list
9565 + */
9566 + DeleteStringMatchTable(MatchPatternDialog.mpdLangModeName);
9568 + /*
9569 + * free the old dialog information
9570 + */
9571 + freeVariableDialogData(KEEP_LANGUAGE_MODE);
9573 + /*
9574 + * clear out the dialog
9575 + */
9576 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9577 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9580 +static void closeCB(Widget w, XtPointer clientData, XtPointer callData)
9582 + /*
9583 + * pop down and destroy the dialog
9584 + */
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");
9643 + /*
9644 + * if context group button is (still) selected, then update labels etc.
9645 + */
9646 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW))
9648 + setDialogType(CONTEXT_GROUP_DIALOG);
9650 + else
9652 + setDialogType(STRING_PATTERN_DIALOG);
9655 + /*
9656 + * if a "new" entry is selected in matching patterns names list, then provide a
9657 + * list of all sub-pattern names
9658 + */
9659 + if (MatchPatternDialog.currentDmptSeqElement == NULL)
9661 + updateSubPatternNameMenu(NULL, True);
9665 +static void changeExistingSubPattern(
9666 + char *warnTitle)
9668 + DialogMatchPatternGroupElement *group;
9669 + int resp;
9671 + group =
9672 + getDialogGroupUsingMatchPattern(
9673 + MatchPatternDialog.currentDmptElement->dmpteName );
9675 + while ( group != NULL )
9677 + resp =
9678 + DialogF(
9679 + DF_WARN, MatchPatternDialog.mpdShell, 3,
9680 + warnTitle,
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);
9688 + if (resp == 1)
9690 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9692 + return;
9694 + else if (resp == 2)
9696 + removeMatchPatternFromGroup(
9697 + MatchPatternDialog.currentDmptElement->dmpteName,
9698 + group);
9700 + /*
9701 + * look for evtl. next context group holding this matching pattern
9702 + */
9703 + group =
9704 + getDialogGroupUsingMatchPattern(
9705 + MatchPatternDialog.currentDmptElement->dmpteName );
9707 + else
9709 + /*
9710 + * remove this matching pattern form all context groups
9711 + */
9712 + removeMatchPatternFromAllGroups(
9713 + MatchPatternDialog.currentDmptElement->dmpteName);
9715 + return;
9720 +static void changeStringPatternToGroup(void)
9722 + int resp;
9723 + int isSubPattern;
9725 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns != 0)
9727 + resp =
9728 + DialogF(
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);
9737 + if (resp == 1)
9739 + isSubPattern = (MatchPatternDialog.currentDmptElement->dmpteType == MPT_SUB);
9741 + if (isSubPattern)
9742 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9743 + else
9744 + RadioButtonChangeState(MatchPatternDialog.mptbIndividualW, True, True);
9746 + return;
9749 + /*
9750 + * remove string patterns & update dialog fields
9751 + */
9752 + freeDialogStringPatterns(&MatchPatternDialog.currentStringPatterns);
9754 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9757 + /*
9758 + * invalidate this sub-/individual pattern
9759 + */
9760 + MatchPatternDialog.currentDmptSeqElement->dmpseValid = False;
9762 + /*
9763 + * update sub-pattern menu due to change to context group
9764 + */
9765 + updateSubPatternNameMenu(NULL, True);
9768 +static void changeGroupToStringPattern(
9769 + char *warnTitle)
9771 + int resp;
9773 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
9774 + return;
9776 + resp =
9777 + DialogF(
9778 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9779 + warnTitle,
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);
9786 + if (resp == 1)
9788 + RadioButtonChangeState(MatchPatternDialog.mptbContextGroupW, True, True);
9790 + else
9792 + /*
9793 + * remove string patterns & update dialog fields
9794 + */
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(
9806 + Widget parent,
9807 + char *currentSubPatName,
9808 + int allSubPatterns)
9810 + NameList nameList;
9811 + Widget menu;
9812 + int i;
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]);
9823 + return menu;
9826 +static void setupSubPatternNameList(
9827 + char *currentSubPatName,
9828 + int allSubPatterns,
9829 + NameList *nameList)
9831 + int n = 0;
9832 + int i;
9833 + DialogMatchPatternSequenceElement *seq;
9834 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9836 + if (isRelatedToGroup || allSubPatterns)
9838 + /*
9839 + * add "none selected" (default) item
9840 + */
9841 + nameList->nlId[n ++] = SPNM_NONE_SELECTED;
9843 + /*
9844 + * add one item for each (not assigned) sub-pattern name
9845 + */
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;
9861 + else
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(
9874 + Widget menu,
9875 + char *subPatName)
9877 + Widget btn;
9878 + XmString s1;
9880 + btn = XtVaCreateManagedWidget("subPattern", xmPushButtonGadgetClass,
9881 + menu,
9882 + XmNlabelString, s1=XmStringCreateSimple(subPatName),
9883 + XmNmarginHeight, 0,
9884 + XmNuserData, (void *)subPatName, NULL);
9885 + XmStringFree(s1);
9889 +** Set the sub-patterns menu to show a particular sub-pattern name
9891 +static void setSubPatternNameMenu(
9892 + const char *subPatName)
9894 + int i;
9895 + Cardinal nItems;
9896 + WidgetList items;
9897 + Widget pulldown, selectedItem;
9898 + char *itemName;
9900 + XtVaGetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNsubMenuId, &pulldown, NULL);
9901 + XtVaGetValues(pulldown, XmNchildren, &items, XmNnumChildren, &nItems, NULL);
9903 + if (nItems == 0)
9904 + return;
9906 + selectedItem = items[0];
9908 + /*
9909 + * if no subPatName is given, then select first item of option menu
9910 + */
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];
9921 + break;
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;
9938 + WidgetList items;
9939 + Cardinal nItems;
9940 + int n;
9941 + XmString st1;
9943 + setupSubPatternNameList(currentSubPatName, allSubPatterns, &nameList);
9945 + /*
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.
9949 + */
9950 + XtVaGetValues(
9951 + MatchPatternDialog.mpdSubPatNamesPulldown,
9952 + XmNchildren, &items,
9953 + XmNnumChildren, &nItems,
9954 + NULL);
9956 + for (n=0; n<(int)nItems; n++)
9958 + if (n >= nameList.nlNumber)
9960 + /*
9961 + * unmanaging before destroying stops parent from displaying
9962 + */
9963 + XtUnmanageChild(items[n]);
9964 + XtDestroyWidget(items[n]);
9966 + else
9968 + if (items[n] == NULL || items[n]->core.being_destroyed)
9970 + /*
9971 + * create a new entry (widget) if this one is not existing or
9972 + * if it is marked as to be destroyed
9973 + */
9974 + createSubPatNameMenuEntry(
9975 + MatchPatternDialog.mpdSubPatNamesPulldown, nameList.nlId[n]);
9977 + else
9979 + XtVaSetValues(
9980 + items[n],
9981 + XmNlabelString, st1=XmStringCreateSimple(nameList.nlId[n]),
9982 + XmNuserData, (void *)nameList.nlId[n],
9983 + NULL);
9985 + XmStringFree(st1);
9990 + /*
9991 + * add new items for remaining sub-patterns names
9992 + */
9993 + for (n=(int)nItems; n<nameList.nlNumber; n++)
9995 + createSubPatNameMenuEntry(
9996 + MatchPatternDialog.mpdSubPatNamesPulldown, nameList.nlId[n]);
9999 + /*
10000 + * select entry shown in sub-pattern name option menu
10001 + */
10002 + setSubPatternNameMenu(currentSubPatName);
10005 +static char *getSelectedSubPatternName(void)
10007 + Widget selectedItem;
10008 + char *itemName;
10010 + XtVaGetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNmenuHistory, &selectedItem, NULL);
10011 + XtVaGetValues(selectedItem, XmNuserData, &itemName, NULL);
10013 + return itemName;
10016 +static int isSubPatternNameInCurStrPat(
10017 + char *subPatName)
10019 + int i;
10020 + DialogStringPatterns *curPatNames = &MatchPatternDialog.currentStringPatterns;
10022 + for (i=0; i<curPatNames->dspNumberOfPatterns; i++)
10024 + if (strcmp(curPatNames->dspElements[i]->dspeText, subPatName) == 0)
10025 + return True;
10028 + return False;
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)
10040 + int isGroup;
10041 + char *name;
10042 + char *nameLabel;
10043 + char *nameTitle;
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";
10056 + isGroup = True;
10058 + else
10060 + nameLabel = "matching pattern name";
10061 + nameTitle = "Matching Pattern Name";
10062 + contentTitle = "Matching Pattern Content";
10063 + contentWarningText = "Please specify min. 1\nstring pattern";
10064 + isGroup = False;
10067 + name =
10068 + ReadSymbolicFieldTextWidget(
10069 + MatchPatternDialog.mpdMatchPatternNameW,
10070 + nameLabel,
10071 + silent);
10073 + if (name == NULL)
10075 + return NULL;
10077 + else if (*name == '\0')
10079 + if (!silent)
10081 + DialogF(
10082 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10083 + nameTitle,
10084 + "Please specify a valid name",
10085 + "OK");
10086 + XmProcessTraversal(MatchPatternDialog.mpdMatchPatternNameW, XmTRAVERSE_CURRENT);
10088 + XtFree(name);
10089 + return NULL;
10092 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
10094 + if (!silent)
10096 + DialogF(
10097 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10098 + contentTitle,
10099 + contentWarningText,
10100 + "OK");
10102 + XtFree(name);
10103 + return NULL;
10105 + else
10107 + if (!isGroup &&
10108 + !isStartPatternElementAvailable(&MatchPatternDialog.currentStringPatterns))
10110 + if (!silent)
10112 + DialogF(
10113 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10114 + contentTitle,
10115 + "Please specify min. 1 string pattern\nof type 'start'",
10116 + "OK");
10118 + XtFree(name);
10119 + return NULL;
10123 + if (MatchPatternDialog.currentDmptElement != NULL &&
10124 + MatchPatternDialog.currentDmptElement->dmpteType == MPT_SUB &&
10125 + strcmp(MatchPatternDialog.currentDmptElement->dmpteName, name) != 0)
10127 + renameMatchPatternInAllGroups(
10128 + MatchPatternDialog.currentDmptElement->dmpteName,
10129 + name);
10132 + newSeq =
10133 + (DialogMatchPatternSequenceElement *)XtMalloc(sizeof(DialogMatchPatternSequenceElement));
10135 + newSeq->dmpseName = name;
10136 + newSeq->dmpseValid = True;
10138 + if (isGroup)
10140 + newSeq->dmpseType = MPT_GROUP;
10142 + newGroup =
10143 + (DialogMatchPatternGroupElement *)XtMalloc(sizeof(DialogMatchPatternGroupElement));
10145 + newGroup->dmpgeName = XtNewString(name);
10147 + copyDialogPatternNamesToGroup(
10148 + &MatchPatternDialog.currentStringPatterns,
10149 + newGroup);
10151 + newSeq->dmpsePtr = (void *)newGroup;
10153 + else
10155 + if (XmToggleButtonGetState(MatchPatternDialog.mptbIndividualW))
10156 + newSeq->dmpseType = MPT_INDIVIDUAL;
10157 + else
10158 + newSeq->dmpseType = MPT_SUB;
10160 + newElement =
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;
10182 + return newSeq;
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)
10194 + int i;
10196 + for (i=0; i < dialogPatterns->dspNumberOfPatterns; i++)
10198 + if (dialogPatterns->dspElements[i]->dspeKind == PEK_START)
10199 + return True;
10202 + return False;
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)
10223 + return NULL;
10226 + stringPatText = XtNewString(stringPatText);
10228 + else
10230 + stringPatText =
10231 + XmTextGetString(MatchPatternDialog.mpdStringPatternW);
10233 + if (stringPatText == NULL)
10235 + return NULL;
10237 + else if (*stringPatText == '\0')
10239 + if (!silent)
10241 + DialogF(
10242 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10243 + "String Pattern",
10244 + "Please specify string\npattern content",
10245 + "OK");
10246 + XmProcessTraversal(MatchPatternDialog.mpdStringPatternW, XmTRAVERSE_CURRENT);
10248 + XtFree(stringPatText);
10249 + return NULL;
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;
10264 + else
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;
10273 + else
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;
10284 + else
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)
10300 + return
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)
10314 + return
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)
10328 + return(
10329 + strcmp( getSelectedSubPatternName(), SPNM_NONE_SELECTED ) == 0);
10331 + else
10333 + return
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;
10352 + /*
10353 + * Get the current information displayed by the dialog. If it's bad,
10354 + * report it to the user & return.
10355 + */
10356 + newTable = getDialogStringMatchTable(&translResult);
10358 + if (newTable == NULL && translResult != DMPTR_EMPTY)
10360 + DialogF(
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",
10365 + "OK",
10366 + MatchPatternDialog.mpdLangModeName);
10368 + return False;
10371 + /*
10372 + * change the matching pattern
10373 + */
10374 + updateStringMatchTable( newTable );
10376 + return True;
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;
10388 + int i;
10390 + /*
10391 + * Find the matching pattern being modified
10392 + */
10393 + for (i=0; i<NbrMatchTables; i++)
10395 + if (!strcmp(MatchPatternDialog.mpdLangModeName, MatchTables[i]->smtLanguageMode))
10397 + /*
10398 + * replace existing matching pattern
10399 + */
10400 + freeStringMatchTable(MatchTables[i]);
10401 + MatchTables[i] = newTable;
10402 + break;
10406 + if (i == NbrMatchTables)
10408 + /*
10409 + * new match table for language mode -> add it to end
10410 + */
10411 + MatchTables[NbrMatchTables++] = newTable;
10414 + /*
10415 + * Find windows that are currently using this matching pattern set and
10416 + * update this windows
10417 + */
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;
10429 + /*
10430 + * Note that preferences have been changed
10431 + */
10432 + MarkPrefsChanged();
10435 +static StringMatchTable *getDialogStringMatchTable(
10436 + DMPTranslationResult *result)
10438 + int matchPatListIdx =
10439 + ManagedListSelectedIndex(MatchPatternDialog.mpdMatchPatternNamesListW);
10440 + int stringPatListIdx =
10441 + ManagedListSelectedIndex(MatchPatternDialog.mpdStringPatternsListW);
10443 + /*
10444 + * Get the current content of the matching pattern dialog fields
10445 + */
10446 + if (!UpdateManagedList(MatchPatternDialog.mpdStringPatternsListW, True))
10448 + *result = DMPTR_INCOMPLETE;
10450 + return NULL;
10453 + if (!UpdateManagedList(MatchPatternDialog.mpdMatchPatternNamesListW, True))
10455 + *result = DMPTR_INCOMPLETE;
10457 + return NULL;
10460 + SelectManagedListItem(MatchPatternDialog.mpdMatchPatternNamesListW, matchPatListIdx);
10461 + SelectManagedListItem(MatchPatternDialog.mpdStringPatternsListW, stringPatListIdx);
10463 + /*
10464 + * Translate dialog match table to string match table
10465 + */
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;
10477 + char *errMsg;
10478 + ErrorInfo errInfo;
10479 + int i;
10481 + initErrorInfo(&errInfo);
10483 + readPatInfo.rmpiNbrOfElements = 0;
10484 + readPatInfo.rmpiNbrOfGroups = 0;
10485 + readPatInfo.rmpiNbrOfSeqElements = 0;
10486 + readPatInfo.rmpiAllPatRE = NULL;
10487 + readPatInfo.rmpiFlashPatRE = NULL;
10489 + /*
10490 + * if no dialog patterns are defined, return "empty" table
10491 + */
10492 + if (dialogTable->dmpiNbrOfSeqElements == 0)
10494 + *result = DMPTR_EMPTY;
10496 + return createStringMatchTable(
10497 + &readPatInfo,
10498 + XtNewString(MatchPatternDialog.mpdLangModeName));
10501 + /*
10502 + * translate dialog matching pattern elements
10503 + */
10504 + for (i=0; i < dialogTable->dmpiNbrOfSeqElements; i++)
10506 + seq = dialogTable->dmpiSequence[i];
10508 + if (seq->dmpseType == MPT_GROUP)
10510 + newGroupElement =
10511 + translateDialogMatchPatternGroupElement(
10512 + &readPatInfo,
10513 + (DialogMatchPatternGroupElement *)seq->dmpsePtr);
10515 + if (newGroupElement == NULL)
10517 + freeReadMatchPatternInfo(&readPatInfo);
10519 + *result = DMPTR_INCOMPLETE;
10521 + return NULL;
10524 + readPatInfo.rmpiGroup[readPatInfo.rmpiNbrOfGroups ++] =
10525 + newGroupElement;
10527 + recordPatternSequence(
10528 + &readPatInfo,
10529 + seq->dmpseName,
10530 + seq->dmpseType,
10531 + readPatInfo.rmpiNbrOfGroups-1 );
10533 + else
10535 + newPatElement =
10536 + translateDialogMatchPatternTableElement(
10537 + (DialogMatchPatternTableElement *)seq->dmpsePtr);
10539 + newPatElement->mpteIndex = readPatInfo.rmpiNbrOfElements;
10541 + readPatInfo.rmpiElement[readPatInfo.rmpiNbrOfElements ++] =
10542 + newPatElement;
10544 + if (newPatElement->mpteType == MPT_INDIVIDUAL)
10546 + if (!assignIndividualGroup(&readPatInfo, &errMsg, newPatElement))
10548 + DialogF(
10549 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10550 + "Assign reg. exp.",
10551 + "%s\n(Pattern: '%s')",
10552 + "OK",
10553 + errMsg,
10554 + newPatElement->mpteName);
10556 + freeReadMatchPatternInfo(&readPatInfo);
10558 + *result = DMPTR_INCOMPLETE;
10560 + return NULL;
10564 + treatDuplicatedMTEntries(readPatInfo.rmpiElement, readPatInfo.rmpiNbrOfElements);
10566 + recordPatternSequence(
10567 + &readPatInfo,
10568 + seq->dmpseName,
10569 + seq->dmpseType,
10570 + newPatElement->mpteIndex );
10574 + /*
10575 + * compile reg. expressions of "read" patterns
10576 + */
10577 + if (createRegExpOfPatterns( &readPatInfo, &errInfo ))
10579 + errInfo.eiLanguageMode = XtNewString(MatchPatternDialog.mpdLangModeName);
10580 + dialogMatchingPatternSetError(
10581 + "Assign all patterns reg. exp.",
10582 + &errInfo);
10584 + freeReadMatchPatternInfo(&readPatInfo);
10586 + *result = DMPTR_INCOMPLETE;
10588 + return NULL;
10591 + *result = DMPTR_OK;
10593 + return createStringMatchTable(
10594 + &readPatInfo,
10595 + XtNewString(MatchPatternDialog.mpdLangModeName));
10598 +static MatchPatternTableElement *translateDialogMatchPatternTableElement(
10599 + DialogMatchPatternTableElement *dialogElement)
10601 + MatchPatternTableElement *newElement;
10603 + 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)
10627 + int sizeOfPat;
10628 + int i;
10630 + /*
10631 + * allocate memory for patterns
10632 + */
10633 + newElement->mpteAll.pesNumberOfPattern = dialogPatterns->dspNumberOfPatterns;
10635 + sizeOfPat =
10636 + sizeof(PatternElement *) * dialogPatterns->dspNumberOfPatterns;
10638 + newElement->mpteAll.pesPattern = (PatternElement **)XtMalloc(sizeOfPat);
10640 + /*
10641 + * assign dialog patterns to patterns of MatchPatternTableElement
10642 + */
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;
10656 + /*
10657 + * sort pattern elements into start, middle & end arrays
10658 + */
10659 + sortDialogPatternElementSet( &newElement->mpteAll, newElement );
10661 + /*
10662 + * determine mono pattern
10663 + */
10664 + if (newElement->mpteEnd.pesNumberOfPattern == 0)
10666 + newElement->mpteIsMonoPattern = True;
10668 + copyPatternSet( &newElement->mpteStart, &newElement->mpteEnd );
10670 + else
10672 + newElement->mpteIsMonoPattern = False;
10677 + * Sort dialog pattern element set into start, middle & end arrays.
10678 + */
10679 +static void sortDialogPatternElementSet(
10680 + PatternElementSet *allPat,
10681 + MatchPatternTableElement *result)
10683 + int sizeOfPat;
10685 + /*
10686 + * count number of start, middle & end pattern elements
10687 + */
10688 + countPatternElementKind( allPat, result );
10690 + /*
10691 + * allocate pattern elements
10692 + */
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 );
10708 + /*
10709 + * sort pattern elements into start, middle & end arrays
10710 + */
10711 + sortPatternElementSet( allPat, result );
10714 +static MatchPatternGroupElement *translateDialogMatchPatternGroupElement(
10715 + ReadMatchPatternInfo *info,
10716 + DialogMatchPatternGroupElement *dialogGroup)
10718 + int i;
10719 + int error = False;
10720 + MatchPatternTableElement *subPatElement;
10721 + int sizeOfIds;
10722 + MatchPatternGroupElement *group;
10724 + /*
10725 + * Allocate memory for the matching pattern group. Copy name & number of
10726 + * sub patterns.
10727 + */
10728 + group =
10729 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
10731 + group->mpgeName = XtNewString(dialogGroup->dmpgeName);
10732 + group->mpgeNumberOfSubPatterns = dialogGroup->dmpgeNumberOfSubPatterns;
10733 + group->mpgeKeywordRE = NULL;
10735 + /*
10736 + * Allocate memory for the sub-matching pattern IDs
10737 + */
10738 + sizeOfIds = sizeof(char *) * group->mpgeNumberOfSubPatterns;
10739 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeOfIds );
10741 + for (i=0; i < group->mpgeNumberOfSubPatterns; i ++)
10743 + /*
10744 + * Remember sub-matching pattern ID
10745 + */
10746 + group->mpgeSubPatternIds[i] = XtNewString(dialogGroup->dmpgeSubPatternIds[i]);
10748 + /*
10749 + * Assign the index of this group to the sub-matching pattern
10750 + * if no group index was assigned before.
10751 + */
10752 + subPatElement =
10753 + getPatternOfName( info, dialogGroup->dmpgeSubPatternIds[i]);
10755 + if (subPatElement == NULL)
10757 + DialogF(
10758 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10759 + "Group Compilation",
10760 + "Group '%s':\nsub-matching pattern '%s' not defined before",
10761 + "OK",
10762 + group->mpgeName,
10763 + dialogGroup->dmpgeSubPatternIds[i]);
10765 + error = True;
10767 + else
10769 + if (subPatElement->mpteGroup == NO_GROUP_IDX)
10771 + subPatElement->mpteGroup = info->rmpiNbrOfGroups;
10776 + if (error)
10778 + freeMatchPatternGroupElement(group);
10780 + return NULL;
10783 + return group;
10786 +static int stringMatchTableDiffer(
10787 + StringMatchTable *oldTable,
10788 + StringMatchTable *newTable)
10790 + int i, j;
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)
10801 + return True;
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))
10809 + return True;
10810 + if (oldSeq->mpseType != newSeq->mpseType)
10811 + return True;
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))
10819 + return True;
10821 + if (oldGroup->mpgeNumberOfSubPatterns != newGroup->mpgeNumberOfSubPatterns)
10822 + return True;
10824 + for (j=0; j < oldGroup->mpgeNumberOfSubPatterns; j++)
10826 + if (AllocatedStringsDiffer(
10827 + oldGroup->mpgeSubPatternIds[j],
10828 + newGroup->mpgeSubPatternIds[j]))
10829 + return True;
10832 + else
10834 + oldPat = oldPatTab->mptElements[oldSeq->mpseIndex];
10835 + newPat = newPatTab->mptElements[newSeq->mpseIndex];
10837 + if (AllocatedStringsDiffer(oldPat->mpteName, newPat->mpteName))
10838 + return True;
10840 + if (oldPat->mpteType != newPat->mpteType)
10841 + return True;
10843 + if (oldPat->mpteGroup != newPat->mpteGroup)
10844 + return True;
10846 + if (oldPat->mpteAll.pesNumberOfPattern != newPat->mpteAll.pesNumberOfPattern)
10847 + return True;
10849 + for (j=0; j < oldPat->mpteAll.pesNumberOfPattern; j ++)
10851 + if (patternElementDiffer(
10852 + oldPat->mpteAll.pesPattern[j], oldPatTab,
10853 + newPat->mpteAll.pesPattern[j], newPatTab ) )
10854 + return True;
10857 + if (oldPat->mpteIsMonoPattern != newPat->mpteIsMonoPattern)
10858 + return True;
10860 + if (oldPat->mpteSkipBtwnStartEnd != newPat->mpteSkipBtwnStartEnd)
10861 + return True;
10863 + if (oldPat->mpteIgnoreHighLightInfo != newPat->mpteIgnoreHighLightInfo)
10864 + return True;
10866 + if (oldPat->mpteFlash != newPat->mpteFlash)
10867 + return True;
10871 + return False;
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))
10887 + return True;
10888 + if (AllocatedStringsDiffer(oldSP->spOrigText, newSP->spOrigText))
10889 + return True;
10890 + if (oldPE->peKind != newPE->peKind)
10891 + return True;
10892 + if (oldSP->spWordBoundary != newSP->spWordBoundary)
10893 + return True;
10894 + if (oldSP->spCaseInsensitive != newSP->spCaseInsensitive)
10895 + return True;
10896 + if (oldSP->spRegularExpression != newSP->spRegularExpression)
10897 + return True;
10899 + return False;
10902 +static DialogMatchPatternGroupElement *getDialogGroupUsingMatchPattern(
10903 + char *matchPatternName)
10905 + DialogMatchPatternSequenceElement *seq;
10906 + DialogMatchPatternGroupElement *group;
10907 + int i, j;
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)
10920 + return group;
10925 + return NULL;
10928 +static void removeMatchPatternFromGroup(
10929 + char *matchPatternName,
10930 + DialogMatchPatternGroupElement *group)
10932 + int i;
10934 + for (i=0; i < group->dmpgeNumberOfSubPatterns; i ++)
10936 + if (strcmp(group->dmpgeSubPatternIds[i], matchPatternName) == 0)
10938 + /*
10939 + * remove existing matching pattern name from sub-pattern list
10940 + */
10941 + freeXtPtr((void **)&group->dmpgeSubPatternIds[i]);
10942 + memmove(
10943 + &group->dmpgeSubPatternIds[i],
10944 + &group->dmpgeSubPatternIds[i+1],
10945 + (group->dmpgeNumberOfSubPatterns-1 - i) * sizeof(char *));
10946 + group->dmpgeNumberOfSubPatterns --;
10948 + return;
10953 +static void removeMatchPatternFromAllGroups(
10954 + char *matchPatternName)
10956 + DialogMatchPatternSequenceElement *seq;
10957 + DialogMatchPatternGroupElement *group;
10958 + int i;
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)
10978 + int i;
10980 + for (i=0; i < group->dmpgeNumberOfSubPatterns; i ++)
10982 + if (strcmp(group->dmpgeSubPatternIds[i], oldMatchPatternName) == 0)
10984 + /*
10985 + * rename existing matching pattern name in sub-pattern list
10986 + */
10987 + freeXtPtr((void **)&group->dmpgeSubPatternIds[i]);
10989 + group->dmpgeSubPatternIds[i] =
10990 + XtNewString(newMatchPatternName);
10992 + return;
10997 +static void renameMatchPatternInAllGroups(
10998 + char *oldMatchPatternName,
10999 + char *newMatchPatternName)
11001 + DialogMatchPatternSequenceElement *seq;
11002 + DialogMatchPatternGroupElement *group;
11003 + int i;
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,
11016 + group);
11021 +static void freeVariableDialogData(
11022 + int keepLanguageModeName)
11024 + int i;
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)
11044 + int i;
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)
11056 + int i;
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);
11091 + *ptr = NULL;
11095 +static void freePtr(void **ptr)
11097 + if (*ptr != NULL)
11099 + free((char *)*ptr);
11100 + *ptr = NULL;
11103 diff --quilt /dev/null new/source/patternMatchData.h
11104 --- /dev/null
11105 +++ new/source/patternMatchData.h
11106 @@ -0,0 +1,24 @@
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"
11139 #include "tags.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 {
11162 char *language;
11163 char *styles;
11164 char *smartIndent;
11165 char *smartIndentCommon;
11166 char *shell;
11167 + char *matchPattern;
11168 } TempStringPrefs;
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[] = {
11174 C++:Default\n\
11175 Python:Default\n\
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 */
11180 +#ifdef VMS
11181 +/* The VAX compiler can't compile Java-Script's definition in highlightData.c */
11182 + {"matchPatterns", "MatchPatterns", PREF_ALLOC_STRING,
11183 + "PLAIN:Default\n\
11184 + Ada:Default\n\
11185 + Awk:Default\n\
11186 + C++:Default\n\
11187 + C:Default\n\
11188 + CSS:Default\n\
11189 + Csh:Default\n\
11190 + Fortran:Default\n\
11191 + Java:Default\n\
11192 + LaTeX:Default\n\
11193 + Lex:Default\n\
11194 + Makefile:Default\n\
11195 + Matlab:Default\n\
11196 + NEdit Macro:Default\n\
11197 + Pascal:Default\n\
11198 + Perl:Default\n\
11199 + PostScript:Default\n\
11200 + Python:Default\n\
11201 + Regex:Default\n\
11202 + SGML HTML:Default\n\
11203 + SQL:Default\n\
11204 + Sh Ksh Bash:Default\n\
11205 + Tcl:Default\n\
11206 + VHDL:Default\n\
11207 + Verilog:Default\n\
11208 + XML:Default\n\
11209 + X Resources:Default\n\
11210 + Yacc:Default\n",
11211 + &TempStringPrefs.matchPattern, NULL, True},
11212 +#else
11213 + {"matchPatterns", "MatchPatterns", PREF_ALLOC_STRING,
11214 + "PLAIN:Default\n\
11215 + Ada:Default\n\
11216 + Awk:Default\n\
11217 + C++:Default\n\
11218 + C:Default\n\
11219 + CSS:Default\n\
11220 + Csh:Default\n\
11221 + Fortran:Default\n\
11222 + Java:Default\n\
11223 + JavaScript:Default\n\
11224 + LaTeX:Default\n\
11225 + Lex:Default\n\
11226 + Makefile:Default\n\
11227 + Matlab:Default\n\
11228 + NEdit Macro:Default\n\
11229 + Pascal:Default\n\
11230 + Perl:Default\n\
11231 + PostScript:Default\n\
11232 + Python:Default\n\
11233 + Regex:Default\n\
11234 + SGML HTML:Default\n\
11235 + SQL:Default\n\
11236 + Sh Ksh Bash:Default\n\
11237 + Tcl:Default\n\
11238 + VHDL:Default\n\
11239 + Verilog:Default\n\
11240 + XML:Default\n\
11241 + X Resources:Default\n\
11242 + Yacc:Default\n",
11243 + &TempStringPrefs.matchPattern, NULL, True},
11244 +#endif
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,
11272 void *cbArg);
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");
11339 return False;
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");
11351 + return False;
11354 + /* delete "empty" string match table related to language mode to be deleted */
11355 + DeleteStringMatchTable(LMDialog.languageModeList[itemIndex]->name);
11357 return True;
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))
11365 return False;
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
11400 user menu items */
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();
11435 return True;
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) {
11448 + *c = '\0';
11449 + isOldMode = !strcmp(lmDialogName, oldModeName);
11450 + *c = ':';
11453 + return isOldMode;
11456 static void *lmGetDisplayedCB(void *oldItem, int explicitRequest, int *abort,
11457 void *cbArg)
11459 languageModeRec *lm, *oldLM = (languageModeRec *)oldItem;
11460 char *tempName;
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();
11474 else
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
11483 +** holds "PLAIN".
11485 -Widget CreateLanguageModeMenu(Widget parent, XtCallbackProc cbProc, void *cbArg)
11486 +Widget CreateLanguageModeMenu(
11487 + Widget parent,
11488 + XtCallbackProc cbProc,
11489 + void *cbArg,
11490 + int includePlain)
11492 Widget menu, btn;
11493 int i;
11494 XmString s1;
11496 menu = CreatePulldownMenu(parent, "languageModes", NULL, 0);
11498 + if (includePlain) {
11499 + btn = XtVaCreateManagedWidget("languageMode", xmPushButtonGadgetClass,
11500 + menu,
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,
11510 menu,
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,
11535 - void *cbArg);
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"
11549 #endif
11551 +#include "patternMatch.h"
11553 int NHist = 0;
11555 typedef struct _SelectionInfo {
11556 int done;
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,
11577 - int *matchPos);
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 {
11584 char c;
11585 char match;
11586 char direction;
11587 } 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
11621 -** highlights)
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)
11629 - char c;
11630 - void *style;
11631 - int pos, matchIndex;
11632 - int startPos, endPos, searchPos, matchPos;
11633 + int pos;
11634 + int direction;
11635 + int startPos, endPos, matchPos, matchLen;
11636 int constrain;
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)
11647 return;
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);
11653 if (pos < 0)
11654 return;
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)
11661 - break;
11663 - if (matchIndex == N_FLASH_CHARS)
11664 - return;
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;
11673 - endPos = pos;
11674 - searchPos = endPos;
11675 - } else {
11676 - startPos = pos;
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)
11683 + return;
11685 + /* Pattern Match Feature: determine matching type
11686 + (here: flash delimiter or range) */
11687 + if (window->showMatchingStyle == FLASH_DELIMIT) {
11688 + matchingType = MT_FLASH_DELIMIT;
11689 + } else {
11690 + matchingType = MT_FLASH_RANGE;
11693 - /* do the search */
11694 - if (!findMatchingChar(window, c, style, searchPos, startPos, endPos,
11695 - &matchPos))
11696 + /* Pattern Match Feature: do the search */
11697 + if (!FindMatchingString(window, matchingType, &pos, startPos, endPos,
11698 + &matchPos, &matchLen, &direction))
11699 return;
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);
11706 } else {
11707 /* ... or the whole range. */
11708 - if (MatchingChars[matchIndex].direction == SEARCH_BACKWARD) {
11709 + if (direction == SEARCH_BACKWARD) {
11710 BufHighlight(window->buffer, matchPos, pos+1);
11711 } else {
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)
11730 + int pos;
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)
11741 - selEnd += 1;
11742 - selStart = selEnd - 1;
11743 - if (selStart < 0) {
11744 - XBell(TheDisplay, 0);
11745 - return;
11747 + if (GetSimpleSelection(buf, &selStart, &selEnd)) {
11748 + pos = selEnd;
11750 - if ((selEnd - selStart) != 1) {
11751 - XBell(TheDisplay, 0);
11752 - return;
11753 + else {
11754 + pos = TextGetCursorPos(window->lastFocus);
11758 + return pos;
11761 +void SelectToMatchingCharacter(WindowInfo *window)
11763 + int pos;
11764 + int startPos, endPos, matchPos, matchLen;
11765 + int direction;
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);
11777 return;
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;
11794 - int matchPos;
11795 + int pos;
11796 + int matchPos, matchLen;
11797 + int direction;
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)
11806 - selEnd += 1;
11807 - selStart = selEnd - 1;
11808 - if (selStart < 0) {
11809 - XBell(TheDisplay, 0);
11810 - return;
11813 - if ((selEnd - selStart) != 1) {
11814 - XBell(TheDisplay, 0);
11815 - return;
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);
11827 return;
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
11834 nothing) */
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,
11844 - int *matchPos)
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)
11858 - break;
11860 - if (matchIndex == N_MATCH_CHARS)
11861 - return FALSE;
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;
11867 - nestDepth = 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) {
11874 - nestDepth--;
11875 - if (nestDepth == 0) {
11876 - *matchPos = pos;
11877 - return TRUE;
11880 - } else if (c == toMatch) {
11881 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11882 - if (style == styleToMatch)
11883 - nestDepth++;
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) {
11892 - nestDepth--;
11893 - if (nestDepth == 0) {
11894 - *matchPos = pos;
11895 - return TRUE;
11898 - } else if (c == toMatch) {
11899 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11900 - if (style == styleToMatch)
11901 - nestDepth++;
11905 - return FALSE;
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,
11919 XmNtopPosition, 1,
11920 XmNrightAttachment, XmATTACH_POSITION,
11921 XmNrightPosition, 99, NULL);
11923 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
11924 SmartIndentDialog.lmPulldown = CreateLanguageModeMenu(lmForm, langModeCB,
11925 - NULL);
11926 + NULL, FALSE);
11927 n = 0;
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)
11935 return;
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"
11952 #include "n.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;
12008 + /*
12009 + * Pattern Match Feature:
12010 + */
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
12019 #ifndef VMS
12020 XmToggleButtonSetState(window->saveLastItem, window->saveOldVersion, False);
12021 #endif
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;
12051 #if 0
12052 window->showStats = orgWin->showStats;
12053 window->showISearchLine = orgWin->showISearchLine;
12054 window->showLineNumbers = orgWin->showLineNumbers;
12055 window->modeMessageDisplayed = orgWin->modeMessageDisplayed;