finally, add at least a subject for each patch
[nedit-bw.git] / matching_patterns.patch
blob5318d3b63ed190c25922d46120e978049c3e9cb5
1 From: Uwe Lehnert
2 Subject: Matching patterns (keyword matching)
4 Short feature description:
5 --------------------------
7 'Matching patterns' - in context of the patch - are defined as groups of single
8 characters (like '(', ')'), literal strings (like '#ifdef', '#endif') or even a
9 regular expression (like '\</.*\>', which match to each other.
11 A matching pattern set is a collection of such matching patterns.
13 'Opposite pattern highlighting' (aka 'flashing') or 'Goto Matching' feature are
14 adapted by above patch to use user defineable matching pattern sets i.s.o. a
15 constant table.
17 Alternative start / end patterns as well as 'middle' patterns are allowed
18 (Example 'C preprocessor conditional statement': Start = '#if' or '#ifndef' or
19 '#ifdef'; middle = '#elif' or '#else'; end = '#endif').
21 More info about the 'matching pattern' feature can be found
23 a.) 'FEATURE.txt' document (included in patch tar ball)
24 b.) by selecting menu item
26 'Help' -> 'Features for Programming' -> 'Matching Parentheses'
30 'Help' -> 'Customizing' -> 'Matching Patterns'
32 after patch was applied and NEdit was compiled of course :-)
34 File 'mp041114-V3-0.tar.gz' holds version 3.0 of the matching patterns (keyword
35 matching) patch.
37 Version 3.0 of the patch is based on nedit-5.5 (available at
38 ftp://ftp.nedit.org/pub/NEdit/v5_5/). README.txt (included in patch tar ball)
39 holds hints about how to apply the patch.
41 Changes since Version 2.1:
42 * Adaption of this patch to 'Tabbed Editing Interface'.
43 * New built-in macro subroutine 'get_matching' added.
44 * Bug fixes: NULL pointer exception corrected, if pull-down menu child widgets
45 were already destroyed.
46 * C / C++ pattern: #ifdef statement adapted - whitespaces after '#' are now
47 recognized.
48 * CSS pattern introduced.
49 * Sh Ksh Bash pattern: back quotes added.
50 * XML pattern completely revised.
51 * NEdit Macro pattern: single quotes & '/* .. */' comment removed.
53 ---
55 doc/help.etx | 258 +
56 source/Makefile.common | 6
57 source/Makefile.dependencies | 11
58 source/highlightData.c | 13
59 source/macro.c | 107
60 source/menu.c | 63
61 source/nedit.h | 6
62 source/patternMatch.c | 2202 ++++++++++++
63 source/patternMatch.h | 170
64 source/patternMatchData.c | 7780 +++++++++++++++++++++++++++++++++++++++++++
65 source/patternMatchData.h | 24
66 source/preferences.c | 170
67 source/preferences.h | 4
68 source/search.c | 231 -
69 source/smartIndent.c | 7
70 source/window.c | 18
71 16 files changed, 10773 insertions(+), 297 deletions(-)
73 diff --quilt old/doc/help.etx new/doc/help.etx
74 --- old/doc/help.etx
75 +++ new/doc/help.etx
76 @@ -864,12 +864,13 @@ Programming with NEdit
77 ----------------------
79 Though general in appearance, NEdit has many features intended specifically
80 for programmers. Major programming-related topics are listed in separate
81 sections under the heading: "Features for Programming": Syntax_Highlighting_,
82 - Tabs/Emulated_Tabs_, Finding_Declarations_(ctags)_, Calltips_, and
83 - Auto/Smart_Indent_. Minor topics related to programming are discussed below:
84 + Tabs/Emulated_Tabs_, Matching_Parentheses_, Finding_Declarations_(ctags)_,
85 + Calltips_, and Auto/Smart_Indent_. Minor topics related to programming are
86 + discussed below:
88 3>Language Modes
90 When NEdit initially reads a file, it attempts to determine whether the file
91 is in one of the computer languages that it knows about. Knowing what language
92 @@ -923,30 +924,10 @@ Programming with NEdit
93 Search menu and enter a line number and a column number separated by a
94 comma. (e.g. Enter "100,12" for line 100 column 12.) If you want to go to
95 a column on the current line just leave out the line number. (e.g. Enter
96 ",45" to go the column 45 on the current line.)
98 -3>Matching Parentheses
100 - To help you inspect nested parentheses, brackets, braces, quotes, and other
101 - characters, NEdit has both an automatic parenthesis matching mode, and a Goto
102 - Matching command. Automatic parenthesis matching is activated when you type,
103 - or move the insertion cursor after a parenthesis, bracket, or brace. It
104 - momentarily highlights either the opposite character ('Delimiter') or the
105 - entire expression ('Range') when the opposite character is visible in the
106 - window. To find a matching character anywhere in the file, select it or
107 - position the cursor after it, and choose Goto Matching from the Search menu.
108 - If the character matches itself, such as a quote or slash, select the first
109 - character of the pair. NEdit will match {, (, [, <, ", ', `, /, and \.
110 - Holding the Shift key while typing the accelerator key (Shift+Ctrl+M, by
111 - default), will select all of the text between the matching characters.
113 - When syntax highlighting is enabled, the matching routines can optionally
114 - make use of the syntax information for improved accuracy. In that case,
115 - a brace inside a highlighted string will not match a brace inside a comment,
116 - for instance.
118 3>Opening Included Files
120 The Open Selected command in the File menu understands the C preprocessor's
121 #include syntax, so selecting an #include line and invoking Open Selected will
122 generally find the file referred to, unless doing so depends on the settings of
123 @@ -1220,10 +1201,43 @@ Syntax Highlighting
124 is scrolled in to view. Depending on your system, and the highlight patterns
125 you are using, this may or may not be noticeable. A typing delay is also
126 possible, but unlikely if you are only using the built-in patterns.
127 ----------------------------------------------------------------------
129 +Matching Parentheses
130 +--------------------
132 +3>Matching Parentheses (Patterns)
134 + To help you inspect nested parentheses (e.g. brackets, braces, quotes
135 + etc.) or nested constructs (e.g. "begin" .. "end"), NEdit has both an
136 + automatic parenthesis matching mode, and a Goto Matching command.
138 + A matching pattern can be a single character (like '(', ')'), a literal
139 + string (like '#ifdef', '#endif') or a regular expression (like
140 + '\</.*\>').
142 + Automatic parenthesis matching is activated when you type, or move the
143 + insertion cursor after a parenthesis, bracket, or brace. It momentarily
144 + highlights either the opposite pattern ('Delimiter') or the entire expression
145 + ('Range') when the opposite pattern is visible in the window. To find a
146 + matching pattern anywhere in the file, select it or position the cursor after
147 + it, and choose Goto Matching from the Search menu. If the pattern matches
148 + itself, such as a quote or slash, select the first pattern of the pair.
149 + Holding the Shift key while typing the accelerator key (Shift+Ctrl+M, by
150 + default), will select all of the text between the matching patterns.
152 + When syntax highlighting is enabled, the matching routines can optionally
153 + make use of the syntax information for improved accuracy. In that case,
154 + a brace inside a highlighted string will not match a brace inside a comment,
155 + for instance.
157 + Matching patterns are language dependent. Matching patterns can be
158 + configured by the user. If no matching patterns are available for the
159 + language that you want to use, you can create new patterns relatively quickly.
160 + The Help section "Matching_Patterns_" under "Customizing", has details.
162 Finding Declarations (ctags)
163 ----------------------------
165 NEdit can process tags files generated using the Unix _ctags command or the
166 Exuberant Ctags program. Ctags creates index files correlating names of
167 @@ -2578,13 +2592,10 @@ Macro Subroutines
169 **$show_matching**
170 Contains the current preference for showing matching pairs,
171 such as "[]" and "{}" pairs. Can be "off", "delimiter", or "range".
173 -**$match_syntax_based**
174 - Whether pair matching should use syntax information, if available.
176 **$statistics_line**
177 Has a value of 1 if the statistics line is shown, otherwise 0.
179 **$sub_sep**
180 Contains the value of the array sub-script separation string.
181 @@ -2695,10 +2706,19 @@ Macro Subroutines
183 **get_character( position )**
184 Returns the single character at the position
185 indicated by the first argument to the routine from the current window.
187 +**get_matching( position )**
188 + Find a matching pattern string related to the given position.
189 + Returns info about matching pattern within an array. The array has
190 + the following keys: **pos** (position of the first character of the
191 + matching pattern), **len** (length of the matching pattern), **direction**
192 + (direction where the matching pattern was found: ~0~ = forward;
193 + ~1~ = backward). If no matching pattern was found, then array element
194 + of **pos** holds ~-1~, **len** holds ~0~ and **direction** holds ~-1~.
196 **get_range( start, end )**
197 Returns the text between a starting and ending position from the current
198 window.
200 **get_selection()**
201 @@ -3404,13 +3424,10 @@ Action Routines
202 If no parameters are supplied the option is toggled.
204 **set_show_matching( "off" | "delimiter" | "range" )**
205 Set show matching (...) mode for the current window.
207 -**set_match_syntax_based( [0 | 1] )**
208 - Set whether matching should be syntax based for the current window.
210 **set_statistics_line( [0 | 1] )**
211 Show or hide the statistics line for the current window.
212 A value of 0 turns it off and a value of 1 turns it on.
213 If no parameters are supplied the option is toggled.
215 @@ -3938,14 +3955,10 @@ Preferences
216 range between them, when one of these characters is typed, or when the
217 insertion cursor is positioned after it. Delimiter only highlights the
218 matching delimiter, while Range highlights the whole range of text between
219 the matching delimiters.
221 - Optionally, the matching can make use of syntax information if syntax
222 - highlighting is enabled. Alternatively, the matching is purely character
223 - based. In general, syntax based matching results in fewer false matches.
225 **Overtype**
226 In overtype mode, new characters entered replace the characters in front of
227 the insertion cursor, rather than being inserted before them.
229 **Read Only**
230 @@ -5047,10 +5060,189 @@ Smart Indent Macros
231 before the character is inserted into the buffer. You can do just about
232 anything here, but keep in mind that this macro is executed for every
233 keystroke typed, so if you try to get too fancy, you may degrade performance.
234 ----------------------------------------------------------------------
236 +Matching Patterns
237 +-----------------
239 +3>Writing Matching Pattern Sets
241 + Matching Patterns Sets are groups of single characters (like '(', ')'),
242 + literal strings (like '#ifdef', '#endif') or a regular expressions (like
243 + '\</.*\>'), which match to each other.
245 + Examples: An open bracket '(' belongs a closing one ')'.
246 + Or: '#ifdef'(start), '#ifndef'(alternative start), '#ifndef' (another
247 + alternative start),'#elif' (optional), '#else' (optional), '#endif' (end)
248 + define a "#ifdef statement matching pattern".
250 + "Opposite pattern highlighting" or "Goto Matching" features are implemented
251 + in NEdit using this matching pattern sets (see Matching_Parentheses_ under
252 + the heading of Features for Programming).
254 + During definition of a new language mode a standard matching pattern set
255 + is assigned to this new language mode.
257 + To modify a matching pattern set, select "Matching Patterns ..." from
258 + "Show Matching (..)" sub-section of the "Default Settings" sub-menu
259 + of the "Preferences" menu.
261 + A matching pattern set is a collection of matching patterns.
263 + A matching pattern usually consists out of string patterns.
265 + The name of a matching pattern set needs to be defined within field "Matching
266 + Pattern Name".
268 +4>Attributes of matching pattern
270 + A matching pattern holds two types of attributes:
272 +* "Matching Pattern Type" and
273 +* "Global Attributes"
275 + The matching pattern type specifies the kind of the matching pattern
276 + entry:
278 +* "Individual" or
279 +* "Sub-pattern" or
280 +* "Context group"
282 + Each matching pattern can be defined as "Individual" or as "Sub-pattern".
283 + A "Sub-pattern" belongs to a context group. A context group is simply a
284 + collection of sub-patterns.
286 + During search for a corresponding pattern, an "Individual" matching pattern
287 + does not care about nesting of other matching patterns.
289 + If a matching pattern out of a "Context group" is searched, then all
290 + sub-pattern sets defined in this group are taken into account during the
291 + search.
293 + In fact, "Individual" matching pattern search is faster than "Context group" /
294 + "Sub-pattern" search. "Context group" / "Sub-pattern" search results in fewer
295 + false matches.
297 + To define a context group, set "Matching Pattern Type" to "Context group".
298 + Select out of "Sub-Pattern Name" pop-up field all sub-patterns, which
299 + should be placed into this group. **Note**: all "Sub-pattern" used by a context
300 + group must be defined **before** the context group itself.
302 + "Global Attributes" of a matching pattern are
304 +* "Skip content between start / end pattern"
305 +* "Flash matching pattern"
306 +* "Syntax based"
308 + If "Skip content between start / end pattern" is checked, then all text
309 + between the first / last string pattern of the related matching pattern is
310 + not scanned for other string patterns. This is useful for specifying comments.
312 + "Flash matching pattern" indicates, if the string patterns are flashed during
313 + typing. If not checked, then only the "Goto Matching" feature works for the
314 + related matching pattern. Note: if lots of "Flash matching pattern" are
315 + specified, then this may slow down the performance of NEdit: after each
316 + character typed all "Flash matching pattern" are scanned for being
317 + applicable ...
319 + "Syntax based" defines, if the matching pattern can make use of syntax
320 + information if syntax highlighting is enabled. Alternatively, the matching is
321 + purely character based. In general, syntax based matching results in fewer
322 + false matches.
324 +4>Content of matching pattern
326 + An "Individual" pattern or a "Sub-pattern" may consist out of only one string
327 + pattern (e.g. double quotes '"'). Such a pattern is called "mono pattern".
328 + You can imagine, that a match for a mono pattern is hard to find. A matching
329 + mono pattern search is always started in forward direction. If no match is
330 + found in forward direction, a backward search is started. If the "Global
331 + Attribute" "Syntax based" is selected for a mono pattern, then the character
332 + before / after the match is checked to have the same highlighting style than
333 + the pattern itself. This may help to determine the correct match for a mono
334 + pattern.
336 + Usually a matching pattern holds two string patterns (e.g. 'begin' and
337 + 'end'). One ('begin') is the start pattern. The other one ('end') is the
338 + end pattern. If the cursor is located behind the start pattern, then a
339 + corresponding end pattern is searched (in forward direction). If the
340 + cursor is located behind the end pattern, then a start pattern is search
341 + (in backward direction):
343 +! +--> start ---> end --+
344 +! +-----------<---------+
346 + Alternative start / end patterns can be defined. In this case one of the
347 + start / end patterns must be in front of the cursor to detect one of the
348 + related end / start patterns:
350 +! +-> start1 -+ +-> end1 -+
351 +! +-+-> start2 -+---+ +--+
352 +! + +-> start3 -+ +-> end2 -+ |
353 +! +---------------<-------------+
355 + At least also "middle" patterns can be defined (e.g. middle patterns
356 + 'elif' or 'else'). If the cursor is located behind a middle pattern then a
357 + next middle pattern or the end pattern is searched in forward direction:
359 +! +-----<-----+
360 +! +--> start -+-> middle -+-> end --+
361 +! +-----------<---------------------+
363 +4>String pattern
365 + A string pattern holds three attributes:
367 +* "String Pattern Type"
368 +* "Word Boundary"
369 +* "String Attributes"
371 + String Pattern Type specifies if the related string pattern is
372 + a "start", middle, or "end" pattern (see above).
374 + Word boundary defines, if before / after a string pattern a delimiter must be
375 + located ("Both" = pattern is framed by delimiters. "Left" = before pattern
376 + must be a delimiter. "Right" = after pattern must be a delimiter. "None" =
377 + there must be no delimiter before or after pattern).
379 + There are two "String Attributes":
381 +* "Case Sensitive"
382 +* "Regular Expression"
384 + If "Case Sensitive" is checked (= default), then the matching pattern search
385 + concerning this string pattern differs between upper / lower case of the
386 + characters. If "Case Sensitive" is not set, then the case of the checked
387 + characters is not considered.
389 + "Regular Expression" indicates, that string pattern is treated as
390 + regular expression (if "Regular Expression" is checked) or as literal
391 + string (if "Regular Expression" is not checked).
393 +4>Regular Expression String Pattern
395 + Syntax of regular expression is described by NEdit Help menu item
396 + Regular_Expressions_. Following deviations from this syntax are
397 + existing concerning string patterns:
399 +5>Capturing Parentheses
401 + Capturing Parentheses inside string patterns are of the form `(*n<regex>)',
402 + where n = 1 .. 9. Standard "capturing parentheses" of form `(<regex>)' are
403 + treated as "non-capturing parentheses" by the matching pattern feature.
404 + "n" defines the **global** backreference number, which can be used inside any string
405 + pattern of the same matching pattern (= set of string patterns). So
406 + matching patterns like "\<(*1[^/>])\>" (start string pattern) and "\</\1\>"
407 + (end string pattern) are possible. This matching pattern will match e.g.
408 + <body> .. </body> but will not match <body> .. </head>.
410 +5>Non-Capturing Parentheses
412 + As described above: parentheses constructs like (<regex>) are treated
413 + as `(?:<regex>)' (non-capturing parentheses) by the matching pattern feature.
415 NEdit Command Line
416 ------------------
418 .. ? help !!#ifndef VMS
419 **nedit** [-**read**] [-**create**] [-**line** n | +n] [-**server**]
420 @@ -6077,10 +6269,11 @@ Problems/Defects
421 .. Menu: Features for Programming # features
422 .. Menu: Programming with NEdit # programmer
423 .. Menu: Tabs/Emulated Tabs # tabs
424 .. Menu: Auto/Smart Indent # indent
425 .. Menu: Syntax Highlighting # syntax
426 +.. Menu: Matching Parentheses # pattern_matching
427 .. Menu: Finding Declarations (ctags) # tags
428 .. Menu: Calltips # calltips
430 .. Menu: Regular Expressions # regex
431 .. Menu: Basic Regular Expression Syntax # basicSyntax
432 @@ -6104,10 +6297,11 @@ Problems/Defects
433 .. Menu: Preferences # preferences
434 .. Menu: X Resources # resources
435 .. Menu: Key Binding # binding
436 .. Menu: Highlighting Patterns # patterns
437 .. Menu: Smart Indent Macros # smart_indent
438 +.. Menu: Matching Patterns # matching_patterns
440 .. Menu: NEdit Command Line # command_line
441 .. Menu: Client/Server Mode # server
442 .. Menu: Cr_a_sh Recovery # recovery
443 .. Menu: ---------------------------------- # separator1
444 diff --quilt old/source/Makefile.common new/source/Makefile.common
445 --- old/source/Makefile.common
446 +++ new/source/Makefile.common
447 @@ -5,11 +5,12 @@
449 OBJS = nedit.o file.o menu.o window.o selection.o search.o undo.o shift.o \
450 help.o preferences.o tags.o userCmds.o shell.o regularExp.o macro.o \
451 text.o textSel.o textDisp.o textBuf.o textDrag.o server.o highlight.o \
452 highlightData.o interpret.o parse.o smartIndent.o regexConvert.o \
453 - rbTree.o windowTitle.o calltips.o server_common.o rangeset.o
454 + rbTree.o windowTitle.o calltips.o server_common.o rangeset.o \
455 + patternMatch.o patternMatchData.o
457 XLTLIB = ../Xlt/libXlt.a
458 XMLLIB = ../Microline/XmL/libXmL.a
460 .c.o:
461 @@ -35,10 +36,13 @@ smartIndent.o: smartIndent.c
462 $(CC) $(CFLAGS) $(BIGGER_STRINGS) -c smartIndent.c -o $@
464 highlightData.o: highlightData.c
465 $(CC) $(CFLAGS) $(BIGGER_STRINGS) -c highlightData.c -o $@
467 +patternMatchData.o: patternMatchData.c
468 + $(CC) $(CFLAGS) $(BIGGER_STRINGS) -c patternMatchData.c -o $@
470 help_topic.h help_data.h: ../doc/help.etx
471 (cd ..; $(MAKE) docs)
473 clean:
474 rm -f $(OBJS) nedit nc nc.o parse.c linkdate.o
475 diff --quilt old/source/Makefile.dependencies new/source/Makefile.dependencies
476 --- old/source/Makefile.dependencies
477 +++ new/source/Makefile.dependencies
478 @@ -85,5 +85,16 @@ window.o: window.c window.h nedit.h text
479 windowTitle.o: windowTitle.c windowTitle.h nedit.h textBuf.h \
480 preferences.h help.h help_topic.h ../util/prefFile.h ../util/misc.h \
481 ../util/DialogF.h ../util/utils.h ../util/fileUtils.h \
482 ../util/clearcase.h
483 parse.c: parse.h textBuf.h nedit.h rbTree.h interpret.h ops.h
484 +patternMatch.o: patternMatch.c regularExp.h \
485 + textBuf.h search.h window.h preferences.h highlight.h\
486 + patternMatch.h patternMatchData.h
487 +patternMatchData.o: patternMatchData.c ../util/DialogF.h ../util/misc.h \
488 + ../util/managedList.h regularExp.h textBuf.h nedit.h window.h \
489 + preferences.h help.h file.h textP.h patternMatch.h patternMatchData.h
490 +macro.o: patternMatch.h regularExp.h
491 +menu.o: patternMatchData.h
492 +preferences.o: patternMatchData.h
493 +search.o: patternMatch.h
494 +window.o: patternMatchData.h
495 diff --quilt old/source/highlightData.c new/source/highlightData.c
496 --- old/source/highlightData.c
497 +++ new/source/highlightData.c
498 @@ -549,11 +549,11 @@ static char *DefaultPatternSets[] = {
499 README:\"NEdit Macro syntax highlighting patterns, version 2.6, maintainer Thorsten Haude, nedit at thorstenhau.de\":::Flag::D\n\
500 Comment:\"#\":\"$\"::Comment::\n\
501 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\
502 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\
503 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\
504 - 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\
505 + 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\
506 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\
507 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\
508 Macro Hooks:\"<(?:(?:pre|post)_(?:open|save)|cursor_moved|modified|(?:losing_)?focus)_hook(?=\\s*\\()\":::Subroutine1::\n\
509 Keyword:\"<(?:break|continue|define|delete|else|for|if|in|return|while)>\":::Keyword::\n\
510 Braces:\"[{}\\[\\]]\":::Keyword::\n\
511 @@ -2344,12 +2344,13 @@ void EditHighlightPatterns(WindowInfo *w
512 XmNtopPosition, 1,
513 XmNrightAttachment, XmATTACH_POSITION,
514 XmNrightPosition, 99,
515 NULL);
517 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
518 HighlightDialog.lmPulldown = CreateLanguageModeMenu(lmForm, langModeCB,
519 - NULL);
520 + NULL, FALSE);
521 n = 0;
522 XtSetArg(args[n], XmNspacing, 0); n++;
523 XtSetArg(args[n], XmNmarginWidth, 0); n++;
524 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
525 XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
526 @@ -2879,12 +2880,13 @@ void UpdateLanguageModeMenu(void)
528 if (HighlightDialog.shell == NULL)
529 return;
531 oldMenu = HighlightDialog.lmPulldown;
532 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
533 HighlightDialog.lmPulldown = CreateLanguageModeMenu(
534 - XtParent(XtParent(oldMenu)), langModeCB, NULL);
535 + XtParent(XtParent(oldMenu)), langModeCB, NULL, FALSE);
536 XtVaSetValues(XmOptionButtonGadget(HighlightDialog.lmOptMenu),
537 XmNsubMenuId, HighlightDialog.lmPulldown, NULL);
538 SetLangModeMenu(HighlightDialog.lmOptMenu, HighlightDialog.langModeName);
540 XtDestroyWidget(oldMenu);
541 @@ -2939,10 +2941,13 @@ static void langModeCB(Widget w, XtPoint
542 "Discard Changes", "Cancel", HighlightDialog.langModeName);
543 if (resp == 3)
545 SetLangModeMenu(HighlightDialog.lmOptMenu,
546 HighlightDialog.langModeName);
548 + freePatternSet(newPatSet);
550 return;
552 if (resp == 1)
554 updatePatternSet();
555 @@ -3038,10 +3043,12 @@ static void restoreCB(Widget w, XtPointe
556 "Are you sure you want to discard\n"
557 "all changes to syntax highlighting\n"
558 "patterns for language mode %s?", "Discard", "Cancel",
559 HighlightDialog.langModeName) == 2)
561 + freePatternSet(defaultPatSet);
563 return;
566 /* if a stored version of the pattern set exists, replace it, if it
567 doesn't, add a new one */
568 diff --quilt old/source/macro.c new/source/macro.c
569 --- old/source/macro.c
570 +++ new/source/macro.c
571 @@ -55,10 +55,12 @@ static const char CVSID[] = "$Id: macro.
572 #include "../util/utils.h"
573 #include "../util/getfiles.h"
574 #include "highlight.h"
575 #include "highlightData.h"
576 #include "rangeset.h"
577 +#include "patternMatch.h"
578 +#include "regularExp.h"
580 #include <stdio.h>
581 #include <stdlib.h>
582 #include <string.h>
583 #include <ctype.h>
584 @@ -306,12 +308,10 @@ static int makeBackupCopyMV(WindowInfo *
585 DataValue *result, char **errMsg);
586 static int incBackupMV(WindowInfo *window, DataValue *argList, int nArgs,
587 DataValue *result, char **errMsg);
588 static int showMatchingMV(WindowInfo *window, DataValue *argList, int nArgs,
589 DataValue *result, char **errMsg);
590 -static int matchSyntaxBasedMV(WindowInfo *window, DataValue *argList, int nArgs,
591 - DataValue *result, char **errMsg);
592 static int overTypeModeMV(WindowInfo *window, DataValue *argList, int nArgs,
593 DataValue *result, char **errMsg);
594 static int readOnlyMV(WindowInfo *window, DataValue *argList, int nArgs,
595 DataValue *result, char **errMsg);
596 static int lockedMV(WindowInfo *window, DataValue *argList, int nArgs,
597 @@ -423,10 +423,14 @@ static int getStyleAtPosMS(WindowInfo *w
598 static int filenameDialogMS(WindowInfo* window, DataValue* argList, int nArgs,
599 DataValue* result, char** errMsg);
600 static int callMS(WindowInfo *window, DataValue *argList,
601 int nArgs, DataValue *result, char **errMsg);
603 +/* Pattern Match Feature */
604 +static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs,
605 + DataValue *result, char **errMsg);
607 /* Built-in subroutines and variables for the macro language */
608 static const BuiltInSubrName MacroSubrs[] = {
609 { "length", lengthMS },
610 { "get_range", getRangeMS },
611 { "t_print", tPrintMS },
612 @@ -483,10 +487,11 @@ static const BuiltInSubrName MacroSubrs[
613 { "get_pattern_at_pos", getPatternAtPosMS },
614 { "get_style_by_name", getStyleByNameMS },
615 { "get_style_at_pos", getStyleAtPosMS },
616 { "filename_dialog", filenameDialogMS },
617 { "call", callMS },
618 + { "get_matching", getMatchingMS },
619 { NULL, NULL } /* sentinel */
622 static const BuiltInSubrName SpecialVars[] = {
623 { "$cursor", cursorMV },
624 @@ -512,11 +517,10 @@ static const BuiltInSubrName SpecialVars
625 { "$wrap_text", wrapTextMV },
626 { "$highlight_syntax", highlightSyntaxMV },
627 { "$make_backup_copy", makeBackupCopyMV },
628 { "$incremental_backup", incBackupMV },
629 { "$show_matching", showMatchingMV },
630 - { "$match_syntax_based", matchSyntaxBasedMV },
631 { "$overtype_mode", overTypeModeMV },
632 { "$read_only", readOnlyMV },
633 { "$locked", lockedMV },
634 { "$file_format", fileFormatMV },
635 { "$font_name", fontNameMV },
636 @@ -4455,20 +4459,10 @@ static int showMatchingMV(WindowInfo *wi
637 result->val.str.rep = res;
638 result->val.str.len = strlen(res);
639 return True;
642 -static int matchSyntaxBasedMV(WindowInfo *window, DataValue *argList, int nArgs,
643 - DataValue *result, char **errMsg)
645 - result->tag = INT_TAG;
646 - result->val.n = window->matchSyntaxBased ? 1 : 0;
647 - return True;
652 static int overTypeModeMV(WindowInfo *window, DataValue *argList, int nArgs,
653 DataValue *result, char **errMsg)
655 result->tag = INT_TAG;
656 result->val.n = window->overstrike ? 1 : 0;
657 @@ -5872,10 +5866,97 @@ static int getPatternAtPosMS(WindowInfo
658 return fillPatternResult(result, errMsg, window,
659 HighlightNameOfCode(window, patCode), False, True,
660 HighlightStyleOfCode(window, patCode), bufferPos);
664 +** Pattern Match Feature:
665 +** Find a matching pattern string related to the given position.
667 +** Syntax:
668 +** get_matching(position)
670 +** Returns info about matching pattern within an array. The array has
671 +** the following keys: "pos" (position of the first character of the
672 +** matching pattern), "len" (length of the matching pattern), "direction"
673 +** (direction where the matching pattern was found: "0" = forward;
674 +** "1" = backward). If no matching pattern was found, then array element
675 +** of "pos" holds "-1", "len" holds "0" and "direction" holds "-1".
678 +static int getMatchingMS(WindowInfo *window, DataValue *argList, int nArgs,
679 + DataValue *result, char **errMsg)
681 + int startPos;
682 + int matchPos, matchLen;
683 + int direction;
684 + textBuffer *buf = window->buffer;
685 + DataValue dv;
687 + /*
688 + * Perform syntax & semantic check
689 + */
690 + if (nArgs != 1 )
691 + return wrongNArgsErr(errMsg);
693 + if (!readIntArg(argList[0], &startPos, errMsg))
694 + return False;
696 + startPos ++;
698 + /*
699 + * do the search; provide default values, if search fails
700 + */
701 + if (!FindMatchingString(window, MT_MACRO, &startPos, 0, buf->length,
702 + &matchPos, &matchLen, &direction))
704 + matchPos = -1;
705 + matchLen = 0;
706 + direction = -1;
709 + /*
710 + * initialize array holding info about matching string
711 + */
712 + result->tag = ARRAY_TAG;
713 + result->val.arrayPtr = ArrayNew();
715 + /*
716 + * the following array entries will be integers
717 + */
718 + dv.tag = INT_TAG;
720 + /*
721 + * insert match position
722 + */
723 + dv.val.n = matchPos;
724 + if (!ArrayInsert(result, PERM_ALLOC_STR("pos"), &dv))
726 + M_ARRAY_INSERT_FAILURE();
729 + /*
730 + * insert length of matching pattern
731 + */
732 + dv.val.n = matchLen;
733 + if (!ArrayInsert(result, PERM_ALLOC_STR("len"), &dv))
735 + M_ARRAY_INSERT_FAILURE();
738 + /*
739 + * insert direction where the matching pattern was found
740 + */
741 + dv.val.n = direction;
742 + if (!ArrayInsert(result, PERM_ALLOC_STR("direction"), &dv))
744 + M_ARRAY_INSERT_FAILURE();
747 + return True;
750 static int wrongNArgsErr(char **errMsg)
752 *errMsg = "Wrong number of arguments to function %s";
753 return False;
755 diff --quilt old/source/menu.c new/source/menu.c
756 --- old/source/menu.c
757 +++ new/source/menu.c
758 @@ -47,10 +47,11 @@ static const char CVSID[] = "$Id: menu.c
759 #include "userCmds.h"
760 #include "shell.h"
761 #include "macro.h"
762 #include "highlight.h"
763 #include "highlightData.h"
764 +#include "patternMatchData.h"
765 #include "interpret.h"
766 #include "smartIndent.h"
767 #include "windowTitle.h"
768 #include "regularExp.h"
769 #include "../util/getfiles.h"
770 @@ -131,11 +132,10 @@ static void fontCB(Widget w, WindowInfo
771 static void tabsCB(Widget w, WindowInfo *window, caddr_t callData);
772 static void backlightCharsCB(Widget w, WindowInfo *window, caddr_t callData);
773 static void showMatchingOffCB(Widget w, WindowInfo *window, caddr_t callData);
774 static void showMatchingDelimitCB(Widget w, WindowInfo *window, caddr_t callData);
775 static void showMatchingRangeCB(Widget w, WindowInfo *window, caddr_t callData);
776 -static void matchSyntaxBasedCB(Widget w, WindowInfo *window, caddr_t callData);
777 static void statsCB(Widget w, WindowInfo *window, caddr_t callData);
778 static void autoIndentOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
779 static void autoIndentDefCB(Widget w, WindowInfo *window, caddr_t callData);
780 static void smartIndentDefCB(Widget w, WindowInfo *window, caddr_t callData);
781 static void autoSaveDefCB(Widget w, WindowInfo *window, caddr_t callData);
782 @@ -158,13 +158,13 @@ static void pathInWindowsMenuDefCB(Widge
783 static void customizeTitleDefCB(Widget w, WindowInfo *window, caddr_t callData);
784 static void tabsDefCB(Widget w, WindowInfo *window, caddr_t callData);
785 static void showMatchingOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
786 static void showMatchingDelimitDefCB(Widget w, WindowInfo *window, caddr_t callData);
787 static void showMatchingRangeDefCB(Widget w, WindowInfo *window, caddr_t callData);
788 -static void matchSyntaxBasedDefCB(Widget w, WindowInfo *window, caddr_t callData);
789 static void highlightOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
790 static void highlightDefCB(Widget w, WindowInfo *window, caddr_t callData);
791 +static void matchPatternsDefCB(Widget w, WindowInfo *window, caddr_t callData);
792 static void backlightCharsDefCB(Widget w, WindowInfo *window, caddr_t callData);
793 static void fontDefCB(Widget w, WindowInfo *window, caddr_t callData);
794 static void colorDefCB(Widget w, WindowInfo *window, caddr_t callData);
795 static void smartTagsDefCB(Widget parent, XtPointer client_data, XtPointer call_data);
796 static void showAllTagsDefCB(Widget parent, XtPointer client_data, XtPointer call_data);
797 @@ -407,12 +407,10 @@ static void setMakeBackupCopyAP(Widget w
798 Cardinal *nArgs);
799 static void setIncrementalBackupAP(Widget w, XEvent *event, String *args,
800 Cardinal *nArgs);
801 static void setShowMatchingAP(Widget w, XEvent *event, String *args,
802 Cardinal *nArgs);
803 -static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
804 - Cardinal *nArgs);
805 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
806 Cardinal *nArgs);
807 static void setLockedAP(Widget w, XEvent *event, String *args,
808 Cardinal *nArgs);
809 static void setTransientAP(Widget text, XEvent *event, String *args,
810 @@ -582,11 +580,10 @@ static XtActionsRec Actions[] = {
811 #ifndef VMS
812 {"set_make_backup_copy", setMakeBackupCopyAP},
813 #endif
814 {"set_incremental_backup", setIncrementalBackupAP},
815 {"set_show_matching", setShowMatchingAP},
816 - {"set_match_syntax_based", setMatchSyntaxBasedAP},
817 {"set_overtype_mode", setOvertypeModeAP},
818 {"set_locked", setLockedAP},
819 {"set_transient", setTransientAP},
820 {"set_tab_dist", setTabDistAP},
821 {"set_em_tab_dist", setEmTabDistAP},
822 @@ -1028,13 +1025,12 @@ Widget CreateMenuBar(Widget parent, Wind
823 GetPrefShowMatching() == FLASH_DELIMIT, SHORT);
824 window->showMatchingRangeDefItem = createMenuRadioToggle(subSubPane,
825 "range", "Range", 'R', showMatchingRangeDefCB, window,
826 GetPrefShowMatching() == FLASH_RANGE, SHORT);
827 createMenuSeparator(subSubPane, "sep", SHORT);
828 - window->matchSyntaxBasedDefItem = createMenuToggle(subSubPane,
829 - "matchSyntax", "Syntax Based", 'S', matchSyntaxBasedDefCB, window,
830 - GetPrefMatchSyntaxBased(), SHORT);
831 + createMenuItem(subSubPane, "matchPatterns", "Matching Patterns...",
832 + 'M', matchPatternsDefCB, window, FULL);
834 /* Show Cursorline */
835 window->showCursorlineItem = createMenuToggle(subPane,
836 "showCursorlineItem", "Show Cursorline", 'x', showCursorlineCB,
837 NULL, GetPrefShowCursorline(), FULL);
838 @@ -1152,14 +1148,10 @@ Widget CreateMenuBar(Widget parent, Wind
839 "delimiter", "Delimiter", 'D', showMatchingDelimitCB, window,
840 window->showMatchingStyle == FLASH_DELIMIT, SHORT);
841 window->showMatchingRangeItem = createMenuRadioToggle(subPane, "range",
842 "Range", 'R', showMatchingRangeCB, window,
843 window->showMatchingStyle == FLASH_RANGE, SHORT);
844 - createMenuSeparator(subPane, "sep", SHORT);
845 - window->matchSyntaxBasedItem = createMenuToggle(subPane, "matchSyntax",
846 - "Syntax Based", 'S', matchSyntaxBasedCB, window,
847 - window->matchSyntaxBased, SHORT);
849 #ifndef SGI_CUSTOM
850 createMenuSeparator(menuPane, "sep2", SHORT);
851 window->overtypeModeItem = createMenuToggle(menuPane, "overtype", "Overtype", 'O',
852 doActionCB, "set_overtype_mode", False, SHORT);
853 @@ -1687,28 +1679,10 @@ static void showMatchingRangeCB(Widget w
854 ((XmAnyCallbackStruct *)callData)->event);
855 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_show_matching",
856 ((XmAnyCallbackStruct *)callData)->event, params, 1);
859 -static void matchSyntaxBasedCB(Widget w, WindowInfo *window, caddr_t callData)
861 - Widget menu = MENU_WIDGET(w);
863 - window = WidgetToWindow(menu);
865 -#ifdef SGI_CUSTOM
866 - if (shortPrefAskDefault(window->shell, w, "Match Syntax Based")) {
867 - matchSyntaxBasedDefCB(w, window, callData);
868 - SaveNEditPrefs(window->shell, GetPrefShortMenus());
870 -#endif
871 - HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
872 - ((XmAnyCallbackStruct *)callData)->event);
873 - XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_match_syntax_based",
874 - ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
877 static void fontCB(Widget w, WindowInfo *window, caddr_t callData)
879 ChooseFonts(WidgetToWindow(MENU_WIDGET(w)), True);
882 @@ -2032,22 +2006,18 @@ static void showMatchingRangeDefCB(Widge
883 XmToggleButtonSetState(win->showMatchingDelimitDefItem, False, False);
884 XmToggleButtonSetState(win->showMatchingRangeDefItem, True, False);
888 -static void matchSyntaxBasedDefCB(Widget w, WindowInfo *window, caddr_t callData)
889 +static void matchPatternsDefCB(Widget w, WindowInfo *window, caddr_t callData)
891 - WindowInfo *win;
893 - int state = XmToggleButtonGetState(w);
894 + Widget menu = MENU_WIDGET(w);
895 + WindowInfo *activeWindow = WidgetToWindow(menu);
897 - /* Set the preference and make the other windows' menus agree */
898 - SetPrefMatchSyntaxBased(state);
899 - for (win=WindowList; win!=NULL; win=win->next) {
900 - if (IsTopDocument(win))
901 - XmToggleButtonSetState(win->matchSyntaxBasedDefItem, state, False);
903 + HidePointerOnKeyedEvent(activeWindow->lastFocus,
904 + ((XmAnyCallbackStruct *)callData)->event);
905 + EditMatchPatterns(activeWindow);
908 static void backlightCharsDefCB(Widget w, WindowInfo *window, caddr_t callData)
910 WindowInfo *win;
911 @@ -4286,23 +4256,10 @@ static void setShowMatchingAP(Widget w,
912 else {
913 fprintf(stderr, "nedit: set_show_matching requires argument\n");
917 -static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
918 - Cardinal *nArgs)
920 - WindowInfo *window = WidgetToWindow(w);
921 - Boolean newState;
923 - ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->matchSyntaxBased, "set_match_syntax_based");
925 - if (IsTopDocument(window))
926 - XmToggleButtonSetState(window->matchSyntaxBasedItem, newState, False);
927 - window->matchSyntaxBased = newState;
930 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
931 Cardinal *nArgs)
933 WindowInfo *window = WidgetToWindow(w);
934 Boolean newState;
935 diff --quilt old/source/nedit.h new/source/nedit.h
936 --- old/source/nedit.h
937 +++ new/source/nedit.h
938 @@ -364,11 +364,10 @@ typedef struct _WindowInfo {
939 Widget iSearchLineItem;
940 Widget lineNumsItem;
941 Widget showMatchingOffItem;
942 Widget showMatchingDelimitItem;
943 Widget showMatchingRangeItem;
944 - Widget matchSyntaxBasedItem;
945 Widget overtypeModeItem;
946 Widget highlightItem;
947 Widget windowMenuPane;
948 Widget shellMenuPane;
949 Widget macroMenuPane;
950 @@ -390,11 +389,10 @@ typedef struct _WindowInfo {
951 Widget newlineWrapDefItem;
952 Widget contWrapDefItem;
953 Widget showMatchingOffDefItem;
954 Widget showMatchingDelimitDefItem;
955 Widget showMatchingRangeDefItem;
956 - Widget matchSyntaxBasedDefItem;
957 Widget highlightOffDefItem;
958 Widget highlightDefItem;
959 Widget backlightCharsItem;
960 Widget backlightCharsDefItem;
961 Widget searchDlogsDefItem;
962 @@ -510,11 +508,10 @@ typedef struct _WindowInfo {
963 ALWAYS, ON-WRAP as enums */
964 Boolean overstrike; /* is overstrike mode turned on ? */
965 char showMatchingStyle; /* How to show matching parens:
966 NO_FLASH, FLASH_DELIMIT, or
967 FLASH_RANGE */
968 - char matchSyntaxBased; /* Use syntax info to show matching */
969 Boolean showStats; /* is stats line supposed to be shown */
970 Boolean showISearchLine; /* is incr. search line to be shown */
971 Boolean showLineNumbers; /* is the line number display shown */
972 Boolean highlightSyntax; /* is syntax highlighting turned on? */
973 Boolean backlightChars; /* is char backlighting turned on? */
974 @@ -556,10 +553,13 @@ typedef struct _WindowInfo {
975 incremental search bar */
976 Bool iSearchLastLiteralCase; /* idem, for literal mode */
977 Bool findLastRegexCase; /* idem, for regex mode in find dialog */
978 Bool findLastLiteralCase; /* idem, for literal mode */
980 + /* Pattern Match Feature */
981 + void *stringMatchTable; /* match pattern info related to this window */
983 #ifdef REPLACE_SCOPE
984 int replaceScope; /* Current scope for replace dialog */
985 Widget replaceScopeWinToggle; /* Scope for replace = window */
986 Widget replaceScopeSelToggle; /* Scope for replace = selection */
987 Widget replaceScopeMultiToggle;/* Scope for replace = multiple files */
988 diff --quilt /dev/null new/source/patternMatch.c
989 --- /dev/null
990 +++ new/source/patternMatch.c
991 @@ -0,0 +1,2202 @@
992 +static const char CVSID[] = "$Id: patternMatch.c,v 1.4 2003/10/27 21:59:14 uleh Exp $";
993 +/*******************************************************************************
994 +* *
995 +* patternMatch.c -- Nirvana Editor pattern matching functions *
996 +* *
997 +* Copyright (C) 2003-2004, Uwe Lehnert *
998 +* *
999 +* This is free software; you can redistribute it and/or modify it under the *
1000 +* terms of the GNU General Public License as published by the Free Software *
1001 +* Foundation; either version 2 of the License, or (at your option) any later *
1002 +* version. In addition, you may distribute versions of this program linked to *
1003 +* Motif or Open Motif. See README for details. *
1004 +* *
1005 +* This software is distributed in the hope that it will be useful, but WITHOUT *
1006 +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
1007 +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
1008 +* for more details. *
1009 +* *
1010 +* You should have received a copy of the GNU General Public License along with *
1011 +* software; if not, write to the Free Software Foundation, Inc., 59 Temple *
1012 +* Place, Suite 330, Boston, MA 02111-1307 USA *
1013 +* *
1014 +* Nirvana Text Editor *
1015 +* October 27, 2004 *
1016 +* *
1017 +* Written by Uwe Lehnert *
1018 +* *
1019 +*******************************************************************************/
1021 +#ifdef HAVE_CONFIG_H
1022 +#include "../config.h"
1023 +#endif
1025 +#include <stdlib.h>
1026 +#include <stdio.h>
1027 +#include <limits.h>
1028 +#include <string.h>
1029 +#include <ctype.h>
1031 +#ifdef VMS
1032 +#include "../util/VMSparam.h"
1033 +#else
1034 +#ifndef __MVS__
1035 +#include <sys/param.h>
1036 +#endif
1037 +#endif /*VMS*/
1039 +#include "regularExp.h"
1040 +#include "textBuf.h"
1041 +#include "search.h"
1042 +#include "window.h"
1043 +#include "preferences.h"
1044 +#include "highlight.h"
1046 +#include "patternMatch.h"
1047 +#include "patternMatchData.h"
1049 +#ifdef HAVE_DEBUG_H
1050 +#include "../debug.h"
1051 +#endif
1053 +#define MAX_NESTED_PATTERNS 100
1055 +#define IGNORE_HIGHLIGHT_CODE -1
1057 +typedef struct _SearchRegionInfo {
1058 + WindowInfo *sriWindow;
1059 + char *sriText;
1060 + char sriPrevChar;
1061 + char sriSuccChar;
1062 + int sriStartOfTextPos;
1063 +} SearchRegionInfo;
1065 +typedef struct _FoundStringInfo {
1066 + char *fsiStartPtr;
1067 + char *fsiEndPtr;
1068 + int fsiLength;
1069 + char fsiPrevChar;
1070 + char fsiSuccChar;
1071 + const char *fsiDelimiters;
1072 +} FoundStringInfo;
1074 +typedef struct _BackRefInfo {
1075 + int briAvailable;
1076 + int briCaseInsensitive;
1077 + char *briStartPtr[MAX_GLOBAL_BACK_REF_ID];
1078 + char *briEndPtr[MAX_GLOBAL_BACK_REF_ID];
1079 +} BackRefInfo;
1081 +typedef struct _MatchingElementInfo {
1082 + MatchPatternTableElement *meiElement;
1083 + PatternReference meiPatRef;
1084 + int meiDirection;
1085 + int meiHighLightCode;
1086 + int meiAbsStartPos;
1087 + int meiLength;
1088 + BackRefInfo meiBackRefInfo;
1089 +} MatchingElementInfo;
1091 +typedef struct _PatternStackElement {
1092 + PatternReference psePatRef;
1093 + int pseHighLightCode;
1094 + BackRefInfo pseBackRefInfo;
1095 +} PatternStackElement;
1098 + * Prototypes of local functions
1099 + */
1100 +void adaptPatternPositions(
1101 + MatchingType matchingType,
1102 + int direction,
1103 + int *charPos,
1104 + int startPatternLength,
1105 + int *matchPos,
1106 + int matchedPatternLength);
1108 +static int findMatchingStringElement(
1109 + StringMatchTable *smTable,
1110 + SearchRegionInfo *searchRegion,
1111 + MatchingElementInfo *matchInfo,
1112 + int *charPos,
1113 + const char *delimiters);
1115 +static PatternElementMonoInfo determineMonoPatInfo(
1116 + WindowInfo *window,
1117 + int patHighLightCode,
1118 + int leftPos,
1119 + int rightPos,
1120 + PatternElementKind *patElementKind);
1122 +static void assignBackRefInfo(
1123 + StringPattern *strPat,
1124 + BackRefInfo *backRefInfo);
1125 +static int doesBackRefInfoMatch(
1126 + BackRefInfo *backRefInfo1,
1127 + BackRefInfo *backRefInfo2);
1128 +static int compareBackRef(
1129 + char *startPtr1,
1130 + char *endPtr1,
1131 + char *startPtr2,
1132 + char *endPtr2,
1133 + int caseInsensitive);
1135 +static int doesPatternElementMatch(
1136 + PatternElement *patElement,
1137 + FoundStringInfo *foundStringInfo,
1138 + BackRefInfo *backRefInfo);
1139 +static int doesMPTableElementMatch(
1140 + MatchPatternTableElement *element,
1141 + FoundStringInfo *foundStringInfo,
1142 + PatternElementKind *patternElementKind,
1143 + int *patternElementIdx,
1144 + BackRefInfo *backRefInfo);
1145 +static int getPatternInfo(
1146 + MatchPatternTable *table,
1147 + FoundStringInfo *foundStringInfo,
1148 + PatternReference *patRef,
1149 + BackRefInfo *backRefInfo);
1151 +static int isPartOfPattern(
1152 + MatchPatternTable *table,
1153 + int parentElementIdx,
1154 + int childElementIdx,
1155 + PatternElementKind patElementKind);
1156 +static int isPartOfPatternElementSet(
1157 + PatternElementSet *patElementSet,
1158 + int patternElementIdx);
1159 +static int isPartOfMiddlePatternElementSet(
1160 + PatternElementSet *patElementSet,
1161 + int patternElementIdx);
1162 +static void considerNextPatternReference(
1163 + MatchPatternTable *table,
1164 + PatternReference *startPatRef,
1165 + PatternReference nxtPatRef,
1166 + int groupIdx);
1168 +static int searchPatternForward(
1169 + MatchPatternTable *table,
1170 + regexp *compiledRE,
1171 + SearchRegionInfo *searchRegion,
1172 + const char *delimiters,
1173 + int beginPos,
1174 + int *matchEndPos,
1175 + PatternReference *patRef,
1176 + int *highLightCode,
1177 + BackRefInfo *backRefInfo);
1178 +static int searchPatternBackward(
1179 + MatchPatternTable *table,
1180 + regexp *compiledRE,
1181 + SearchRegionInfo *searchRegion,
1182 + const char *delimiters,
1183 + int beginPos,
1184 + PatternReference *patRef,
1185 + int *highLightCode,
1186 + int *matchedPatternLength,
1187 + BackRefInfo *backRefInfo);
1189 +static int parseStringElementForward(
1190 + MatchingElementInfo *matchInfo,
1191 + SearchRegionInfo *searchRegion,
1192 + int relCharPos,
1193 + int *matchPos,
1194 + int *matchedPatternLength,
1195 + const char *delimiters);
1196 +static int findRelatedForwardPattern(
1197 + StringMatchTable *table,
1198 + SearchRegionInfo *searchRegion,
1199 + const char *delimiters,
1200 + PatternReference beginPatRef,
1201 + int beginPatHighLightCode,
1202 + BackRefInfo *beginPatBackRefInfo,
1203 + int beginPos,
1204 + int *matchEndPos);
1206 +static int parseStringElementBackward(
1207 + MatchingElementInfo *matchInfo,
1208 + SearchRegionInfo *searchRegion,
1209 + int relCharPos,
1210 + int *matchPos,
1211 + int *matchedPatternLength,
1212 + const char *delimiters);
1213 +static int findRelatedStartPattern(
1214 + StringMatchTable *table,
1215 + SearchRegionInfo *searchRegion,
1216 + const char *delimiters,
1217 + PatternReference beginPatRef,
1218 + int beginPatHighLightCode,
1219 + BackRefInfo *beginPatBackRefInfo,
1220 + int beginPos,
1221 + int *matchedPatternLength);
1222 +static void considerStackPatReference(
1223 + PatternElementSet *patSet,
1224 + int stackElementIdx,
1225 + int *foundElementIdx);
1227 +static int getPatternLocatedAtPos(
1228 + regexp *usedPatRE,
1229 + MatchPatternTable *table,
1230 + SearchRegionInfo *searchRegion,
1231 + int *relBeginPos,
1232 + MatchingElementInfo *matchInfo,
1233 + const char *delimiters);
1234 +static int getMatchedElementInfo(
1235 + WindowInfo *window,
1236 + MatchPatternTable *table,
1237 + FoundStringInfo *foundStringInfo,
1238 + MatchingElementInfo *matchInfo);
1240 +static PatternElement *getPatternOfReference(
1241 + MatchPatternTable *table,
1242 + PatternReference patRef);
1244 +#ifdef DEBUG_FIND
1245 +static char *getPatternForDebug(
1246 + MatchPatternTable *table,
1247 + PatternReference patRef );
1248 +static char *patElemKindToString(
1249 + PatternElementKind patElemKind);
1250 +static void printFoundStringForDebug(
1251 + WindowInfo *window,
1252 + int absStartPos,
1253 + int length);
1254 +#endif
1257 +** Try to find a matching pattern string related to the given "charPos"
1258 +** inside the given range (defined by startLimit & endLimit).
1259 +** Determine the matching position & the match pattern length (depending
1260 +** on given matchingType), if a matching pattern was found.
1261 +** Returns true, if a matching pattern string was found.
1263 +int FindMatchingString(
1264 + WindowInfo *window,
1265 + MatchingType matchingType,
1266 + int *charPos,
1267 + int startLimit,
1268 + int endLimit,
1269 + int *matchPos,
1270 + int *matchedPatternLength,
1271 + int *direction)
1273 + StringMatchTable *smTable = (StringMatchTable *)window->stringMatchTable;
1274 + const char *delimiters;
1275 + SearchRegionInfo searchRegion;
1276 + MatchingElementInfo matchInfo;
1277 + int matchingPatternFound = FALSE;
1278 + int relCharPos;
1280 + if (smTable == NULL || smTable->smtAllPatRE == NULL)
1282 + /*
1283 + * No match pattern table available:
1284 + */
1285 + return FALSE;
1288 + /*
1289 + * Get delimiters related to window
1290 + */
1291 + delimiters = GetWindowDelimiters(window);
1292 + if (delimiters == NULL)
1293 + delimiters = GetPrefDelimiters();
1295 + /*
1296 + * Select the start pattern reg. exp. to use
1297 + */
1298 + if (matchingType == MT_FLASH_RANGE ||
1299 + matchingType == MT_FLASH_DELIMIT)
1301 + smTable->smtUsedPatRE = smTable->smtFlashPatRE;
1303 + else
1305 + smTable->smtUsedPatRE = smTable->smtAllPatRE;
1308 + /*
1309 + * Get a copy of the text buffer area to parse
1310 + */
1311 + searchRegion.sriWindow = window;
1312 + searchRegion.sriText = BufGetRange(window->buffer, startLimit, endLimit);
1313 + searchRegion.sriPrevChar = BufGetCharacter(window->buffer, startLimit - 1);
1314 + searchRegion.sriSuccChar = BufGetCharacter(window->buffer, endLimit);
1315 + searchRegion.sriStartOfTextPos = startLimit;
1317 + relCharPos = *charPos - startLimit;
1319 + /*
1320 + * Try to find a matching pattern string using string match table
1321 + * of window
1322 + */
1323 + if (findMatchingStringElement(
1324 + smTable,
1325 + &searchRegion,
1326 + &matchInfo,
1327 + &relCharPos,
1328 + delimiters ))
1330 +#ifdef DEBUG_FIND
1331 + printf("--- Start at : ");
1332 + printFoundStringForDebug(
1333 + window,
1334 + matchInfo.meiAbsStartPos,
1335 + matchInfo.meiLength);
1336 + printf(" ---\n");
1337 +#endif
1338 + if (matchInfo.meiDirection == SEARCH_FORWARD)
1340 + matchingPatternFound =
1341 + parseStringElementForward(
1342 + &matchInfo,
1343 + &searchRegion,
1344 + relCharPos,
1345 + matchPos,
1346 + matchedPatternLength,
1347 + delimiters );
1349 + else
1351 + matchingPatternFound =
1352 + parseStringElementBackward(
1353 + &matchInfo,
1354 + &searchRegion,
1355 + relCharPos,
1356 + matchPos,
1357 + matchedPatternLength,
1358 + delimiters );
1361 + if (matchingPatternFound)
1363 + /*
1364 + * Calc. abs. start char pos. (may have been changed if
1365 + * cursor was located inside a string pattern). Adapt
1366 + * pattern positions depending on matchingType.
1367 + */
1368 + *charPos = relCharPos + startLimit;
1369 + *direction = matchInfo.meiDirection;
1371 + adaptPatternPositions(
1372 + matchingType,
1373 + matchInfo.meiDirection,
1374 + charPos,
1375 + matchInfo.meiLength,
1376 + matchPos,
1377 + *matchedPatternLength);
1381 + XtFree(searchRegion.sriText);
1383 + return matchingPatternFound;
1387 +** Adapt match pattern position / start position depending on the
1388 +** given matching type.
1390 +void adaptPatternPositions(
1391 + MatchingType matchingType,
1392 + int direction,
1393 + int *charPos,
1394 + int startPatternLength,
1395 + int *matchPos,
1396 + int matchedPatternLength)
1398 + switch (matchingType)
1400 + case MT_FLASH_DELIMIT:
1401 + case MT_MACRO:
1402 + if (direction == SEARCH_FORWARD)
1404 + (*matchPos) -= matchedPatternLength - 1;
1406 + break;
1408 + case MT_FLASH_RANGE:
1409 + case MT_SELECT:
1410 + if (direction == SEARCH_FORWARD)
1412 + (*charPos) -= startPatternLength;
1414 + else
1416 + (*charPos) --;
1418 + break;
1420 + case MT_GOTO:
1421 + if (direction == SEARCH_FORWARD)
1423 + (*matchPos) ++;
1425 + else
1427 + (*matchPos) += matchedPatternLength;
1429 + break;
1434 +** Try to find a string pattern at given buffer position 'charPos'.
1435 +** A string pattern is found, if pattern is located before 'charPos' or
1436 +** 'charPos' is located within a pattern.
1437 +** If a string pattern is found, then search direction and string pattern
1438 +** reference / properties are determined.
1439 +** Returns true, if a string pattern was found.
1441 +static int findMatchingStringElement(
1442 + StringMatchTable *smTable,
1443 + SearchRegionInfo *searchRegion,
1444 + MatchingElementInfo *matchInfo,
1445 + int *charPos,
1446 + const char *delimiters)
1448 + if (getPatternLocatedAtPos(
1449 + smTable->smtUsedPatRE,
1450 + smTable->smtAllPatterns,
1451 + searchRegion,
1452 + charPos,
1453 + matchInfo,
1454 + delimiters))
1456 + /*
1457 + * Pattern found -> define search direction:
1458 + * - START & MIDDLE pattern: matching pattern is searched in
1459 + * forward direction
1460 + * - END pattern: matching pattern is searched in backward
1461 + * direction
1462 + */
1463 + if (matchInfo->meiPatRef.prKind == PEK_END)
1464 + matchInfo->meiDirection = SEARCH_BACKWARD;
1465 + else
1466 + matchInfo->meiDirection = SEARCH_FORWARD;
1468 + return TRUE;
1471 + return FALSE;
1475 +** Return mono pattern info depending on highlight codes
1476 +** of left / right side of string pattern. Update pattern
1477 +** kind if applicable.
1479 +static PatternElementMonoInfo determineMonoPatInfo(
1480 + WindowInfo *window,
1481 + int patHighLightCode,
1482 + int leftPos,
1483 + int rightPos,
1484 + PatternElementKind *patElementKind)
1486 + int leftSideHasSameHC;
1487 + int rightSideHasSameHC;
1489 + /*
1490 + * Determine, if left side holds same highlight code than
1491 + * found string pattern
1492 + */
1493 + if (leftPos >= 0)
1494 + leftSideHasSameHC =
1495 + (HighlightCodeOfPos(window, leftPos) == patHighLightCode);
1496 + else
1497 + leftSideHasSameHC = FALSE;
1499 + /*
1500 + * Determine, if right side holds same highlight code than
1501 + * found string pattern
1502 + */
1503 + if (rightPos < window->buffer->length)
1504 + rightSideHasSameHC =
1505 + (HighlightCodeOfPos(window, rightPos) == patHighLightCode);
1506 + else
1507 + rightSideHasSameHC = FALSE;
1509 + if ((rightSideHasSameHC && leftSideHasSameHC) ||
1510 + (!rightSideHasSameHC && !leftSideHasSameHC))
1512 + return PEMI_MONO_AMBIGUOUS_SYNTAX;
1514 + else if (leftSideHasSameHC)
1516 + *patElementKind = PEK_END;
1517 + return PEMI_MONO_DEFINITE_SYNTAX;
1519 + else
1521 + *patElementKind = PEK_START;
1522 + return PEMI_MONO_DEFINITE_SYNTAX;
1527 +** Get backref info out of found string pattern and
1528 +** put it into given backRefInfo.
1530 +static void assignBackRefInfo(
1531 + StringPattern *strPat,
1532 + BackRefInfo *backRefInfo)
1534 + int i;
1535 + int localId;
1536 + regexp *patRE = strPat->spTextRE;
1538 + backRefInfo->briAvailable = FALSE;
1539 + backRefInfo->briCaseInsensitive = strPat->spCaseInsensitive;
1541 + for (i=0; i<MAX_GLOBAL_BACK_REF_ID; i++)
1543 + localId = strPat->spGlobalToLocalBackRef[i];
1545 + if (localId != NO_LOCAL_BACK_REF_ID)
1547 + backRefInfo->briAvailable = TRUE;
1549 + backRefInfo->briStartPtr[i] = patRE->startp[localId];
1550 + backRefInfo->briEndPtr[i] = patRE->endp[localId];
1552 + else
1554 + backRefInfo->briStartPtr[i] = NULL;
1555 + backRefInfo->briEndPtr[i] = NULL;
1561 +** Check, if given backref infos match.
1562 +** Returns true, if backref infos match.
1564 +static int doesBackRefInfoMatch(
1565 + BackRefInfo *backRefInfo1,
1566 + BackRefInfo *backRefInfo2)
1568 + int i;
1570 + /*
1571 + * if min. one string pattern doesn't hold backref info, then nothing
1572 + * could be compared -> both string pattern are matching.
1573 + */
1574 + if (!backRefInfo1->briAvailable || !backRefInfo2->briAvailable)
1575 + return TRUE;
1577 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
1579 + if (!compareBackRef(
1580 + backRefInfo1->briStartPtr[i],
1581 + backRefInfo1->briEndPtr[i],
1582 + backRefInfo2->briStartPtr[i],
1583 + backRefInfo2->briEndPtr[i],
1584 + backRefInfo1->briCaseInsensitive || backRefInfo2->briCaseInsensitive))
1586 + return FALSE;
1590 + return TRUE;
1594 +** Compares two backref content.
1595 +** Returns true, if backref contents match.
1597 +static int compareBackRef(
1598 + char *startPtr1,
1599 + char *endPtr1,
1600 + char *startPtr2,
1601 + char *endPtr2,
1602 + int caseInsensitive)
1604 + char *s1;
1605 + char *s2;
1607 + if (startPtr1 == NULL && startPtr2 == NULL)
1608 + return TRUE;
1610 + if (startPtr1 == NULL || startPtr2 == NULL)
1611 + return FALSE;
1613 + if ((endPtr1 - startPtr1) != (endPtr2 - startPtr2))
1614 + return FALSE;
1616 + s1 = startPtr1;
1617 + s2 = startPtr2;
1619 + if (caseInsensitive)
1621 + while (s1 != endPtr1)
1623 + if (tolower((unsigned char)*s1++) != tolower((unsigned char)*s2++))
1624 + return FALSE;
1627 + else
1629 + while (s1 != endPtr1)
1631 + if (*s1++ != *s2++)
1632 + return FALSE;
1635 + return TRUE;
1639 +** Verify if given pattern element is located between given
1640 +** start / end pointer of "foundStringInfo". Assign backreference
1641 +** information, if pattern element matches.
1642 +** Returns true, if given pattern element matches.
1644 +static int doesPatternElementMatch(
1645 + PatternElement *patElement,
1646 + FoundStringInfo *foundStringInfo,
1647 + BackRefInfo *backRefInfo)
1649 + char *s;
1650 + char *p;
1651 + StringPattern *strPat;
1652 + int elementMatch;
1654 + switch (patElement->peType)
1656 + case PET_SINGLE:
1657 + strPat = &patElement->peVal.peuSingle;
1658 + break;
1659 + case PET_MULTIPLE:
1660 + strPat = &patElement->peVal.peuMulti.mpStringPattern;
1661 + break;
1662 + default:
1663 + return FALSE;
1666 + if (strPat->spRegularExpression)
1668 + /*
1669 + * check reg. expression:
1670 + */
1671 + elementMatch =
1672 + ExecRE(
1673 + strPat->spTextRE,
1674 + foundStringInfo->fsiStartPtr,
1675 + foundStringInfo->fsiEndPtr,
1676 + FALSE,
1677 + foundStringInfo->fsiPrevChar,
1678 + foundStringInfo->fsiSuccChar,
1679 + foundStringInfo->fsiDelimiters,
1680 + NULL,
1681 + NULL);
1683 + if (elementMatch)
1684 + assignBackRefInfo(strPat, backRefInfo);
1686 + return elementMatch;
1688 + else
1690 + backRefInfo->briAvailable = FALSE;
1692 + /*
1693 + * check literal string:
1694 + */
1695 + p = strPat->spText;
1697 + /*
1698 + * if length of found string is different from length of
1699 + * given string pattern, then there is no match.
1700 + */
1701 + if (strPat->spLength != foundStringInfo->fsiLength)
1702 + return FALSE;
1704 + s = foundStringInfo->fsiStartPtr;
1706 + if (strPat->spCaseInsensitive)
1708 + while (s != foundStringInfo->fsiEndPtr)
1710 + if (tolower((unsigned char)*s++) != *p++)
1711 + return FALSE;
1714 + else
1716 + while (s != foundStringInfo->fsiEndPtr)
1718 + if (*s++ != *p++)
1719 + return FALSE;
1724 + return TRUE;
1728 +** Verify if a pattern element of given MatchPatternTableElement is
1729 +** located between given start / end pointer of "foundStringInfo".
1730 +** Returns true, if so.
1732 +static int doesMPTableElementMatch(
1733 + MatchPatternTableElement *element,
1734 + FoundStringInfo *foundStringInfo,
1735 + PatternElementKind *patternElementKind,
1736 + int *patternElementIdx,
1737 + BackRefInfo *backRefInfo)
1739 + int i;
1741 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
1743 + if (doesPatternElementMatch(
1744 + element->mpteAll.pesPattern[i],
1745 + foundStringInfo,
1746 + backRefInfo))
1748 + *patternElementKind = element->mpteAll.pesPattern[i]->peKind;
1749 + *patternElementIdx = i;
1751 + return TRUE;
1755 + return FALSE;
1759 +** Determine the pattern element of given MatchPatternTable, which is
1760 +** located between given start / end pointer of "foundStringInfo".
1761 +** Setup related pattern element reference.
1762 +** Returns true, if a pattern element was found.
1764 +static int getPatternInfo(
1765 + MatchPatternTable *table,
1766 + FoundStringInfo *foundStringInfo,
1767 + PatternReference *patRef,
1768 + BackRefInfo *backRefInfo)
1770 + int i;
1772 + for (i=0; i<table->mptNumberOfElements; i++)
1774 + if (doesMPTableElementMatch(
1775 + table->mptElements[i],
1776 + foundStringInfo,
1777 + &patRef->prKind,
1778 + &patRef->prPatternIdx,
1779 + backRefInfo))
1781 + patRef->prElementIdx = i;
1783 + return TRUE;
1787 + /*
1788 + * Should never been reached !
1789 + */
1790 + patRef->prElementIdx = NO_ELEMENT_IDX;
1791 + patRef->prKind = PEK_UNKNOWN;
1792 + patRef->prPatternIdx = NO_PATTERN_IDX;
1794 + return FALSE;
1798 +** Check, if given child pattern element is part of given
1799 +** parent pattern element.
1800 +** Returns true, if child is part of parent.
1802 +static int isPartOfPattern(
1803 + MatchPatternTable *table,
1804 + int parentElementIdx,
1805 + int childElementIdx,
1806 + PatternElementKind patElementKind)
1808 + MatchPatternTableElement *parent = table->mptElements[parentElementIdx];
1809 + MatchPatternTableElement *child = table->mptElements[childElementIdx];
1811 + if (childElementIdx == parentElementIdx)
1812 + return TRUE;
1814 + if (patElementKind == PEK_START)
1816 + if (isPartOfPatternElementSet(&parent->mpteStart, childElementIdx))
1817 + return TRUE;
1819 + return( isPartOfPatternElementSet(&child->mpteStart, parentElementIdx) );
1821 + else if (patElementKind == PEK_END)
1823 + if (isPartOfPatternElementSet(&parent->mpteEnd, childElementIdx))
1824 + return TRUE;
1826 + return( isPartOfPatternElementSet(&child->mpteEnd, parentElementIdx) );
1828 + else
1830 + /*
1831 + * Given child pattern element is middle pattern: the given pattern element
1832 + * is part of parent pattern, if it's a reference of a middle pattern
1833 + */
1834 + if (isPartOfMiddlePatternElementSet(&parent->mpteMiddle, childElementIdx))
1835 + return TRUE;
1837 + return( isPartOfMiddlePatternElementSet(&child->mpteMiddle, parentElementIdx) );
1842 +** Check, if given pattern element is part of given pattern element set.
1843 +** Returns true, if so.
1845 +static int isPartOfPatternElementSet(
1846 + PatternElementSet *patElementSet,
1847 + int patternElementIdx)
1849 + PatternElement *patElement;
1850 + int i;
1852 + for (i=0; i<patElementSet->pesNumberOfPattern; i++)
1854 + if (patElementSet->pesPattern[i]->peType == PET_REFERENCE)
1856 + patElement = patElementSet->pesPattern[i];
1858 + if (patElement->peVal.peuRef.prElementIdx == patternElementIdx)
1860 + return TRUE;
1865 + return FALSE;
1869 +** Verify, if given pattern element is part of middle pattern set.
1870 +** That's the case, if an element of the pattern set is reference
1871 +** of a middle pattern, which fits to given pattern element.
1872 +** Returns true, if pattern element is part of middle pattern set.
1873 + */
1874 +static int isPartOfMiddlePatternElementSet(
1875 + PatternElementSet *patElementSet,
1876 + int patternElementIdx)
1878 + PatternElement *patElement;
1879 + int i;
1881 + for (i=0; i<patElementSet->pesNumberOfPattern; i++)
1883 + if (patElementSet->pesPattern[i]->peType == PET_REFERENCE)
1885 + patElement = patElementSet->pesPattern[i];
1887 + if (patElement->peVal.peuRef.prElementIdx == patternElementIdx &&
1888 + patElement->peKind == PEK_MIDDLE)
1890 + return TRUE;
1895 + return FALSE;
1899 +** Update start pattern reference depending on next pattern located
1900 +** after start pattern.
1902 +static void considerNextPatternReference(
1903 + MatchPatternTable *table,
1904 + PatternReference *startPatRef,
1905 + PatternReference nxtPatRef,
1906 + int groupIdx)
1908 + MatchPatternTableElement *tabElement;
1909 + PatternElement *startPat;
1910 + MultiPattern *multiStartPat;
1911 + PatternReference patRef;
1912 + int i;
1914 + /*
1915 + * startPatRef needs no adaption, if element index of start pattern
1916 + * and next pattern are equal (i.e. start and next pattern belong
1917 + * to same pattern element).
1918 + */
1919 + if (startPatRef->prElementIdx == nxtPatRef.prElementIdx)
1920 + return;
1922 + /*
1923 + * Verify, if start pattern belongs to multiple pattern elements
1924 + * (like "ELSE .. FI" & "ELSE .. ESAC").
1925 + */
1926 + startPat = getPatternOfReference( table, *startPatRef );
1928 + if (startPat->peType == PET_MULTIPLE)
1930 + /*
1931 + * Check, if next pattern fits to one of the references of
1932 + * the start multi pattern. If so: adapt start pattern reference.
1933 + */
1934 + multiStartPat = &startPat->peVal.peuMulti;
1936 + for (i=0; i<multiStartPat->mpNumberOfReferences; i ++)
1938 + patRef = multiStartPat->mpRefList[i];
1939 + tabElement = table->mptElements[patRef.prElementIdx];
1941 + if (nxtPatRef.prElementIdx == patRef.prElementIdx &&
1942 + tabElement->mpteGroup == groupIdx)
1944 + *startPatRef = patRef;
1945 + return;
1952 +** Search for a string pattern in forward direction, starting at
1953 +** given beginPos. Determine related pattern reference of a found
1954 +** string pattern.
1955 +** Returns true, if a next string pattern was found.
1957 +static int searchPatternForward(
1958 + MatchPatternTable *table,
1959 + regexp *compiledRE,
1960 + SearchRegionInfo *searchRegion,
1961 + const char *delimiters,
1962 + int beginPos,
1963 + int *matchEndPos,
1964 + PatternReference *patRef,
1965 + int *highLightCode,
1966 + BackRefInfo *backRefInfo)
1968 + FoundStringInfo foundStringInfo;
1969 + int matchStartPos;
1970 + int absMatchStartPos;
1971 + MatchPatternTableElement *matchedElement;
1973 + *matchEndPos = -1;
1975 + patRef->prElementIdx = NO_ELEMENT_IDX;
1976 + patRef->prKind = PEK_UNKNOWN;
1977 + patRef->prPatternIdx = NO_PATTERN_IDX;
1979 + *highLightCode = IGNORE_HIGHLIGHT_CODE;
1981 + if (ExecRE(
1982 + compiledRE,
1983 + searchRegion->sriText + beginPos,
1984 + NULL,
1985 + FALSE,
1986 + beginPos==0 ? searchRegion->sriPrevChar : searchRegion->sriText[beginPos-1],
1987 + searchRegion->sriSuccChar,
1988 + delimiters,
1989 + searchRegion->sriText,
1990 + NULL))
1992 + foundStringInfo.fsiStartPtr = compiledRE->startp[0];
1993 + foundStringInfo.fsiEndPtr = compiledRE->endp[0];
1994 + foundStringInfo.fsiLength =
1995 + foundStringInfo.fsiEndPtr - foundStringInfo.fsiStartPtr;
1997 + foundStringInfo.fsiPrevChar =
1998 + foundStringInfo.fsiStartPtr == searchRegion->sriText ?
1999 + searchRegion->sriPrevChar : *(foundStringInfo.fsiStartPtr - 1);
2001 + foundStringInfo.fsiSuccChar =
2002 + *(foundStringInfo.fsiEndPtr) == '\0' ?
2003 + searchRegion->sriSuccChar : *(foundStringInfo.fsiEndPtr);
2005 + foundStringInfo.fsiDelimiters = delimiters;
2007 + if (getPatternInfo(
2008 + table,
2009 + &foundStringInfo,
2010 + patRef,
2011 + backRefInfo))
2013 + /*
2014 + * Next string pattern was found in forward direction and
2015 + * a pattern reference could be assigned to: calculate
2016 + * relative & absolute match positions.
2017 + */
2018 + matchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
2019 + *matchEndPos = foundStringInfo.fsiEndPtr - searchRegion->sriText;
2021 + absMatchStartPos = matchStartPos + searchRegion->sriStartOfTextPos;
2023 + matchedElement = table->mptElements[patRef->prElementIdx];
2025 + /*
2026 + * get highlight code of found string pattern, if applicable
2027 + */
2028 + if (!matchedElement->mpteIgnoreHighLightInfo)
2030 + *highLightCode =
2031 + HighlightCodeOfPos(searchRegion->sriWindow, absMatchStartPos);
2034 + /*
2035 + * setup mono pattern info of found string pattern
2036 + */
2037 + if (matchedElement->mpteIsMonoPattern)
2039 + if (matchedElement->mpteIgnoreHighLightInfo)
2041 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
2043 + else
2045 + /*
2046 + * determine mono pattern info depending on highLightCodes
2047 + * before / after found string pattern.
2048 + */
2049 + patRef->prMonoInfo =
2050 + determineMonoPatInfo(
2051 + searchRegion->sriWindow,
2052 + *highLightCode,
2053 + absMatchStartPos - 1,
2054 + *matchEndPos + searchRegion->sriStartOfTextPos,
2055 + &patRef->prKind);
2058 + else
2060 + patRef->prMonoInfo = PEMI_NOT_MONO;
2063 + return matchStartPos;
2065 + else
2067 + /*
2068 + * Found string can't be assigned to a pattern element
2069 + * (should never occur).
2070 + */
2071 + return -1;
2074 + else
2076 + /*
2077 + * No next string pattern is found in forward direction.
2078 + */
2079 + return -1;
2084 +** Search for a string pattern in backward direction, starting at
2085 +** given beginPos. Determine related pattern reference of a found
2086 +** string pattern.
2087 +** Returns true, if a next string pattern was found.
2089 +static int searchPatternBackward(
2090 + MatchPatternTable *table,
2091 + regexp *compiledRE,
2092 + SearchRegionInfo *searchRegion,
2093 + const char *delimiters,
2094 + int beginPos,
2095 + PatternReference *patRef,
2096 + int *highLightCode,
2097 + int *matchedPatternLength,
2098 + BackRefInfo *backRefInfo)
2100 + FoundStringInfo foundStringInfo;
2101 + int matchStartPos;
2102 + int absMatchStartPos;
2103 + MatchPatternTableElement *matchedElement;
2105 + patRef->prElementIdx = NO_ELEMENT_IDX;
2106 + patRef->prKind = PEK_UNKNOWN;
2107 + patRef->prPatternIdx = NO_PATTERN_IDX;
2109 + *highLightCode = IGNORE_HIGHLIGHT_CODE;
2111 + if (ExecRE(
2112 + compiledRE,
2113 + searchRegion->sriText,
2114 + searchRegion->sriText + beginPos,
2115 + TRUE,
2116 + searchRegion->sriPrevChar,
2117 + searchRegion->sriText[beginPos] == '\0' ?
2118 + searchRegion->sriSuccChar : searchRegion->sriText[beginPos + 1],
2119 + delimiters,
2120 + searchRegion->sriText,
2121 + NULL))
2123 + foundStringInfo.fsiStartPtr = compiledRE->startp[0];
2124 + foundStringInfo.fsiEndPtr = compiledRE->endp[0];
2125 + foundStringInfo.fsiLength =
2126 + foundStringInfo.fsiEndPtr - foundStringInfo.fsiStartPtr;
2128 + foundStringInfo.fsiPrevChar =
2129 + foundStringInfo.fsiStartPtr == searchRegion->sriText ?
2130 + searchRegion->sriPrevChar : *(foundStringInfo.fsiStartPtr - 1);
2132 + foundStringInfo.fsiSuccChar =
2133 + *(foundStringInfo.fsiEndPtr) == '\0' ?
2134 + searchRegion->sriSuccChar : *(foundStringInfo.fsiEndPtr);
2136 + foundStringInfo.fsiDelimiters = delimiters;
2138 + if (getPatternInfo(
2139 + table,
2140 + &foundStringInfo,
2141 + patRef,
2142 + backRefInfo))
2144 + /*
2145 + * Next string pattern was found in backward direction and
2146 + * a pattern reference could be assigned to: calculate
2147 + * relative & absolute match positions.
2148 + */
2149 + matchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
2150 + *matchedPatternLength = foundStringInfo.fsiLength;
2152 + absMatchStartPos = matchStartPos + searchRegion->sriStartOfTextPos;
2154 + matchedElement = table->mptElements[patRef->prElementIdx];
2156 + /*
2157 + * get highlight code of found string pattern, if applicable
2158 + */
2159 + if (!matchedElement->mpteIgnoreHighLightInfo)
2161 + *highLightCode =
2162 + HighlightCodeOfPos(searchRegion->sriWindow, absMatchStartPos);
2165 + /*
2166 + * setup mono pattern info of found string pattern
2167 + */
2168 + if (matchedElement->mpteIsMonoPattern)
2170 + if (matchedElement->mpteIgnoreHighLightInfo)
2172 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
2174 + else
2176 + /*
2177 + * determine mono pattern info depending on highLightCodes
2178 + * before / after found string pattern.
2179 + */
2180 + patRef->prMonoInfo =
2181 + determineMonoPatInfo(
2182 + searchRegion->sriWindow,
2183 + *highLightCode,
2184 + absMatchStartPos - 1,
2185 + absMatchStartPos + *matchedPatternLength,
2186 + &patRef->prKind);
2189 + else
2191 + patRef->prMonoInfo = PEMI_NOT_MONO;
2194 + return matchStartPos;
2196 + else
2198 + /*
2199 + * Found string can't be assigned to a pattern element
2200 + * (should never occur).
2201 + */
2202 + return -1;
2205 + else
2207 + /*
2208 + * No next string pattern is found in backward direction.
2209 + */
2210 + return -1;
2215 +** Find matching pattern related to given pattern (stored in
2216 +** 'matchInfo') in forward direction by considering the rules stored in
2217 +** string match table of given window. Determine match position (= abs.
2218 +** pos. of last character of matching string) and length of matching
2219 +** string. If a mono matching pattern couldn't be found in forward
2220 +** direction, then try finding it in backward direction (if found in
2221 +** backward direction, then match position indicates the 1st char. of
2222 +** matching string).
2223 +** Returns true, if a matching pattern was found.
2225 +static int parseStringElementForward(
2226 + MatchingElementInfo *matchInfo,
2227 + SearchRegionInfo *searchRegion,
2228 + int relCharPos,
2229 + int *matchPos,
2230 + int *matchedPatternLength,
2231 + const char *delimiters)
2233 + StringMatchTable *smTable =
2234 + (StringMatchTable *)searchRegion->sriWindow->stringMatchTable;
2235 + MatchPatternTableElement *matchElement = matchInfo->meiElement;
2236 + int beginPos = relCharPos;
2237 + int endStartPos;
2238 + int startStartPos;
2239 + int endEndPos;
2240 + int matchingPatternFound = FALSE;
2242 + /*
2243 + * Find matching pattern within text buffer area to parse in
2244 + * forward direction.
2245 + */
2246 + endStartPos =
2247 + findRelatedForwardPattern(
2248 + smTable,
2249 + searchRegion,
2250 + delimiters,
2251 + matchInfo->meiPatRef,
2252 + matchInfo->meiHighLightCode,
2253 + &matchInfo->meiBackRefInfo,
2254 + beginPos,
2255 + &endEndPos);
2257 + if (endEndPos != -1)
2259 + *matchPos = endEndPos - 1 + searchRegion->sriStartOfTextPos;
2260 + *matchedPatternLength = endEndPos - endStartPos;
2262 + matchingPatternFound = TRUE;
2264 + else if (matchElement->mpteIsMonoPattern)
2266 + /*
2267 + * mono pattern: forward find fails -> try backward direction.
2268 + * Calc. relative position of 1st char. before found string pattern.
2269 + */
2270 + beginPos = beginPos - matchInfo->meiLength - 1;
2272 + if (beginPos > 0)
2274 + startStartPos =
2275 + findRelatedStartPattern(
2276 + smTable,
2277 + searchRegion,
2278 + delimiters,
2279 + matchInfo->meiPatRef,
2280 + matchInfo->meiHighLightCode,
2281 + &matchInfo->meiBackRefInfo,
2282 + beginPos,
2283 + matchedPatternLength);
2285 + if (startStartPos != -1)
2287 + matchInfo->meiDirection = SEARCH_BACKWARD;
2289 + *matchPos = startStartPos + searchRegion->sriStartOfTextPos;
2291 + matchingPatternFound = TRUE;
2296 + return matchingPatternFound;
2300 +** Find matching pattern related to given begin pattern reference
2301 +** in forward direction by considering the rules stored in given
2302 +** string match table. Determine match position (= relative
2303 +** pos. of last character of matching string).
2304 +** Returns -1, if no matching pattern was found. Else the relative
2305 +** position of 1st char. of matching string is returned.
2307 +static int findRelatedForwardPattern(
2308 + StringMatchTable *table,
2309 + SearchRegionInfo *searchRegion,
2310 + const char *delimiters,
2311 + PatternReference beginPatRef,
2312 + int beginPatHighLightCode,
2313 + BackRefInfo *beginPatBackRefInfo,
2314 + int beginPos,
2315 + int *matchEndPos)
2317 + MatchPatternTable *patTable = table->smtAllPatterns;
2318 + int startPos = beginPos;
2319 + int nxtPatStartPos = 0;
2320 + int nxtPatEndPos = 0;
2321 + PatternReference nxtPatRef;
2322 + int nxtPatHighLightCode;
2323 + BackRefInfo nxtPatBackRefInfo;
2324 + PatternStackElement stack[MAX_NESTED_PATTERNS];
2325 + int stackIdx = 0;
2326 + PatternReference startPatRef;
2327 + MatchPatternTableElement *currentElement;
2328 + int groupIdx;
2329 + regexp *groupPatRE;
2330 + regexp *currentPatRE;
2331 + int skipToEnd = FALSE;
2332 + int beginPatternIsMono;
2334 +#ifdef DEBUG_FIND
2335 + printf("Forward Start Pos: %d K: %s EI: %d PI: %d HC: %d <%s>\n",
2336 + startPos,
2337 + patElemKindToString(beginPatRef.prKind),
2338 + beginPatRef.prElementIdx,
2339 + beginPatRef.prPatternIdx,
2340 + beginPatHighLightCode,
2341 + getPatternForDebug(patTable, beginPatRef) );
2342 +#endif
2344 + /*
2345 + * put begin pattern info on stack
2346 + */
2347 + stack[stackIdx].psePatRef = beginPatRef;
2348 + stack[stackIdx].pseHighLightCode = beginPatHighLightCode;
2349 + stack[stackIdx].pseBackRefInfo = *beginPatBackRefInfo;
2350 + stackIdx ++;
2352 + currentElement = patTable->mptElements[beginPatRef.prElementIdx];
2354 + beginPatternIsMono = currentElement->mpteIsMonoPattern;
2356 + groupIdx = currentElement->mpteGroup;
2358 + /*
2359 + * no next pattern can be found, if there is no group assigned
2360 + * to begin pattern (should never occur)
2361 + */
2362 + if (groupIdx == NO_GROUP_IDX)
2364 + *matchEndPos = -1;
2366 + return -1;
2369 + /*
2370 + * Remember pattern (= keywords) regular expression of context
2371 + * group related to begin pattern. Use it for forward search.
2372 + */
2373 + groupPatRE = table->smtGroups[groupIdx]->mpgeKeywordRE;
2374 + currentPatRE = groupPatRE;
2376 + /*
2377 + * Use start / end pattern regular expression if skip to end is
2378 + * set for begin pattern.
2379 + */
2380 + if (currentElement->mpteSkipBtwnStartEnd)
2382 + currentPatRE = currentElement->mpteStartEndRE;
2383 + skipToEnd = TRUE;
2386 + while (stackIdx > 0 && nxtPatStartPos != -1)
2388 + /*
2389 + * Search for next string pattern in forward direction.
2390 + */
2391 + nxtPatStartPos =
2392 + searchPatternForward(
2393 + patTable,
2394 + currentPatRE,
2395 + searchRegion,
2396 + delimiters,
2397 + startPos,
2398 + &nxtPatEndPos,
2399 + &nxtPatRef,
2400 + &nxtPatHighLightCode,
2401 + &nxtPatBackRefInfo );
2403 + startPatRef = stack[stackIdx-1].psePatRef;
2405 + if (nxtPatStartPos == -1)
2407 + /*
2408 + * no next pattern found -> leave loop
2409 + */
2410 +#ifdef DEBUG_FIND
2411 + printf(" SI: %d [start K: %s EI: %d PI %d] Pos: %d --> no next pat. found\n",
2412 + stackIdx,
2413 + patElemKindToString(startPatRef.prKind),
2414 + startPatRef.prElementIdx,
2415 + startPatRef.prPatternIdx,
2416 + startPos);
2417 +#endif
2418 + break;
2421 + /*
2422 + * Update start pattern reference depending on next pattern
2423 + * located after start pattern.
2424 + */
2425 + considerNextPatternReference(
2426 + patTable,
2427 + &startPatRef,
2428 + nxtPatRef,
2429 + groupIdx );
2431 + /*
2432 + * If current found match pattern table element is a mono pattern and
2433 + * skip to start pattern is active, then the found pattern string is
2434 + * a END one in case of ambiguous or no syntax was detected.
2435 + */
2436 + if (skipToEnd &&
2437 + (nxtPatRef.prMonoInfo == PEMI_MONO_AMBIGUOUS_SYNTAX ||
2438 + nxtPatRef.prMonoInfo == PEMI_MONO_NOT_SYNTAX_BASED))
2440 + nxtPatRef.prKind = PEK_END;
2443 +#ifdef DEBUG_FIND
2444 + printf(" SI: %d [start K: %s EI: %d PI %d] Pos: %d-%d K: %s EI: %d PI: %d HC: %d f=<%s> ",
2445 + stackIdx,
2446 + patElemKindToString(startPatRef.prKind),
2447 + startPatRef.prElementIdx,
2448 + startPatRef.prPatternIdx,
2449 + nxtPatStartPos,
2450 + nxtPatEndPos,
2451 + patElemKindToString(nxtPatRef.prKind),
2452 + nxtPatRef.prElementIdx,
2453 + nxtPatRef.prPatternIdx,
2454 + nxtPatHighLightCode,
2455 + getPatternForDebug(patTable, nxtPatRef) );
2456 + printFoundStringForDebug(
2457 + searchRegion->sriWindow,
2458 + nxtPatStartPos + searchRegion->sriStartOfTextPos,
2459 + nxtPatEndPos - nxtPatStartPos);
2460 + printf("\n");
2461 +#endif
2463 + if (nxtPatRef.prKind == PEK_START)
2465 + if (stackIdx >= MAX_NESTED_PATTERNS)
2467 +#ifdef DEBUG_FIND
2468 + printf("FORWARD: MAX. NESTED PATTERN DEPTH REACHED !\n");
2469 +#endif
2470 + nxtPatStartPos = -1;
2471 + nxtPatEndPos = -1;
2473 + else if (!skipToEnd)
2475 + /*
2476 + * Put next pattern on stack, if contents between start /
2477 + * end shouldn't be skipped (if "skipToEnd" is set,
2478 + * a (usually illegal) start pattern to skip inside the
2479 + * skipped one is found (e.g. \* \* ..)
2480 + */
2481 + stack[stackIdx].psePatRef = nxtPatRef;
2482 + stack[stackIdx].pseHighLightCode = nxtPatHighLightCode;
2483 + stack[stackIdx].pseBackRefInfo = nxtPatBackRefInfo;
2484 + stackIdx ++;
2486 + currentElement = patTable->mptElements[nxtPatRef.prElementIdx];
2488 + /*
2489 + * Use start / end pattern regular expression if skip to
2490 + * end is set for found start pattern.
2491 + */
2492 + if (currentElement->mpteSkipBtwnStartEnd)
2494 + currentPatRE = currentElement->mpteStartEndRE;
2495 + skipToEnd = TRUE;
2498 + else if (beginPatternIsMono)
2500 + /*
2501 + * skip to end is set and a mono pattern start is reached:
2502 + * trigger backward search by returning "not found"
2503 + */
2504 +#ifdef DEBUG_FIND
2505 + printf(" ---> mono pattern (re-)start -> trigger backward search\n");
2506 +#endif
2507 + nxtPatStartPos = -1;
2508 + nxtPatEndPos = -1;
2510 +#ifdef DEBUG_FIND
2511 + else
2513 + printf(" ---> skip to end: illegal (re-)start pattern !\n");
2515 +#endif
2517 + else if (nxtPatRef.prKind == PEK_END)
2519 + /*
2520 + * ignore current found pattern, if it doesn't fit to the prev.
2521 + * opened one.
2522 + */
2523 + if (isPartOfPattern(
2524 + patTable,
2525 + nxtPatRef.prElementIdx,
2526 + startPatRef.prElementIdx,
2527 + PEK_END) &&
2528 + (stack[stackIdx - 1].pseHighLightCode == nxtPatHighLightCode ||
2529 + stack[stackIdx - 1].pseHighLightCode == IGNORE_HIGHLIGHT_CODE ||
2530 + nxtPatHighLightCode == IGNORE_HIGHLIGHT_CODE) &&
2531 + doesBackRefInfoMatch(
2532 + &stack[stackIdx - 1].pseBackRefInfo,
2533 + &nxtPatBackRefInfo))
2535 + /*
2536 + * use context group pattern again, if end pattern to skip
2537 + * to was found.
2538 + */
2539 + if (skipToEnd)
2541 + currentPatRE = groupPatRE;
2542 + skipToEnd = FALSE;
2545 + /*
2546 + * pop. related start pattern from stack.
2547 + */
2548 + stackIdx --;
2551 + else if (!skipToEnd)
2553 + /*
2554 + * middle pattern was found: ignore it, if found middle pattern
2555 + * doesn't belong to begin pattern.
2556 + */
2557 + if (stackIdx == 1 &&
2558 + isPartOfPattern(
2559 + patTable,
2560 + startPatRef.prElementIdx,
2561 + nxtPatRef.prElementIdx,
2562 + nxtPatRef.prKind) &&
2563 + (beginPatHighLightCode == nxtPatHighLightCode ||
2564 + beginPatHighLightCode == IGNORE_HIGHLIGHT_CODE ||
2565 + nxtPatHighLightCode == IGNORE_HIGHLIGHT_CODE) &&
2566 + doesBackRefInfoMatch(
2567 + beginPatBackRefInfo,
2568 + &nxtPatBackRefInfo))
2571 + stackIdx --;
2575 + startPos = nxtPatEndPos;
2578 + *matchEndPos = nxtPatEndPos;
2580 + return nxtPatStartPos;
2584 +** Find matching pattern related to given pattern (stored in
2585 +** 'matchInfo') in backward direction by considering the rules stored in
2586 +** string match table of given window. Determine match position (= abs.
2587 +** pos. of 1st character of matching string) and length of matching
2588 +** string.
2589 +** Returns true, if a matching pattern was found.
2591 +static int parseStringElementBackward(
2592 + MatchingElementInfo *matchInfo,
2593 + SearchRegionInfo *searchRegion,
2594 + int relCharPos,
2595 + int *matchPos,
2596 + int *matchedPatternLength,
2597 + const char *delimiters)
2599 + StringMatchTable *smTable =
2600 + (StringMatchTable *)searchRegion->sriWindow->stringMatchTable;
2601 + int beginPos;
2602 + int startStartPos;
2603 + int matchingPatternFound = FALSE;
2605 + /*
2606 + * determine begin of search in string buffer (= relative position
2607 + * of 1st char. before found string pattern.)
2608 + */
2609 + beginPos = relCharPos - matchInfo->meiLength - 1;
2611 + if (beginPos < 0)
2612 + return FALSE;
2614 + /*
2615 + * Find matching pattern within text buffer area to parse in
2616 + * backward direction.
2617 + */
2618 + startStartPos =
2619 + findRelatedStartPattern(
2620 + smTable,
2621 + searchRegion,
2622 + delimiters,
2623 + matchInfo->meiPatRef,
2624 + matchInfo->meiHighLightCode,
2625 + &matchInfo->meiBackRefInfo,
2626 + beginPos,
2627 + matchedPatternLength);
2629 + if (startStartPos != -1)
2631 + *matchPos = startStartPos + searchRegion->sriStartOfTextPos;
2632 + matchingPatternFound = TRUE;
2635 + return matchingPatternFound;
2639 +** Find matching pattern related to given begin pattern reference
2640 +** in backward direction by considering the rules stored in given
2641 +** string match table. Determine match position (= relative
2642 +** pos. of 1st character of matching string).
2643 +** Returns -1, if no matching pattern was found. Else the relative
2644 +** position of 1st char. of matching string is returned.
2646 +static int findRelatedStartPattern(
2647 + StringMatchTable *table,
2648 + SearchRegionInfo *searchRegion,
2649 + const char *delimiters,
2650 + PatternReference beginPatRef,
2651 + int beginPatHighLightCode,
2652 + BackRefInfo *beginPatBackRefInfo,
2653 + int beginPos,
2654 + int *matchedPatternLength)
2656 + MatchPatternTable *patTable = table->smtAllPatterns;
2657 + int startPos = beginPos;
2658 + int prevStartPos = 0;
2659 + PatternReference prevPatRef;
2660 + int prevPatHighLightCode;
2661 + BackRefInfo prevPatBackRefInfo;
2662 + PatternStackElement stack[MAX_NESTED_PATTERNS];
2663 + int stackIdx = 0;
2664 + MatchPatternTableElement *currentElement;
2665 + int groupIdx;
2666 + regexp *groupPatRE;
2667 + regexp *currentPatRE;
2668 + int skipToStart = FALSE;
2670 + /*
2671 + * put begin pattern info on stack
2672 + */
2673 + stack[stackIdx].psePatRef = beginPatRef;
2674 + stack[stackIdx].pseHighLightCode = beginPatHighLightCode;
2675 + stack[stackIdx].pseBackRefInfo = *beginPatBackRefInfo;
2676 + stackIdx ++;
2678 + currentElement = patTable->mptElements[beginPatRef.prElementIdx];
2680 +#ifdef DEBUG_FIND
2681 + printf("Backward Start Pos: %d K: %s EI: %d PI: %d HC: %d <%s>\n",
2682 + startPos,
2683 + patElemKindToString(beginPatRef.prKind),
2684 + beginPatRef.prElementIdx,
2685 + beginPatRef.prPatternIdx,
2686 + beginPatHighLightCode,
2687 + getPatternForDebug(patTable, beginPatRef) );
2688 +#endif
2690 + groupIdx = currentElement->mpteGroup;
2692 + /*
2693 + * no start pattern can be found, if there is no group assigned
2694 + * to begin pattern (should never occur)
2695 + */
2696 + if (groupIdx == NO_GROUP_IDX)
2698 + return -1;
2701 + /*
2702 + * Remember pattern (= keywords) regular expression of context
2703 + * group related to begin pattern. Use it for backward search.
2704 + */
2705 + groupPatRE = table->smtGroups[groupIdx]->mpgeKeywordRE;
2706 + currentPatRE = groupPatRE;
2708 + /*
2709 + * Use start / end pattern regular expression if skip to start is
2710 + * set for begin pattern.
2711 + */
2712 + if (currentElement->mpteSkipBtwnStartEnd)
2714 + currentPatRE = currentElement->mpteStartEndRE;
2715 + skipToStart = TRUE;
2718 + while (stackIdx > 0 && prevStartPos != -1)
2720 + /*
2721 + * Search for previous string pattern in backward direction.
2722 + */
2723 + prevStartPos =
2724 + searchPatternBackward(
2725 + patTable,
2726 + currentPatRE,
2727 + searchRegion,
2728 + delimiters,
2729 + startPos,
2730 + &prevPatRef,
2731 + &prevPatHighLightCode,
2732 + matchedPatternLength,
2733 + &prevPatBackRefInfo );
2735 + if (prevStartPos == -1)
2737 + /*
2738 + * no previous pattern found -> leave loop
2739 + */
2740 +#ifdef DEBUG_FIND
2741 + printf(" SI: %d [K: %s start EI: %d PI %d] Pos: %d --> no next pat. found\n",
2742 + stackIdx,
2743 + patElemKindToString(stack[stackIdx -1].psePatRef.prKind),
2744 + stack[stackIdx -1].psePatRef.prElementIdx,
2745 + stack[stackIdx -1].psePatRef.prPatternIdx,
2746 + startPos);
2747 +#endif
2748 + break;
2751 + /*
2752 + * Update previous pattern reference depending on last stack
2753 + * pattern, which is located in text puffer after previous
2754 + * start pattern.
2755 + */
2756 + considerNextPatternReference(
2757 + patTable,
2758 + &prevPatRef,
2759 + stack[stackIdx - 1].psePatRef,
2760 + groupIdx);
2762 + /*
2763 + * If current found match pattern table element is a mono pattern and
2764 + * skip to start pattern is active, then the found pattern string is
2765 + * a START one in case of ambiguous or no syntax was detected.
2766 + */
2767 + if (skipToStart &&
2768 + (prevPatRef.prMonoInfo == PEMI_MONO_AMBIGUOUS_SYNTAX ||
2769 + prevPatRef.prMonoInfo == PEMI_MONO_NOT_SYNTAX_BASED))
2771 + prevPatRef.prKind = PEK_START;
2774 +#ifdef DEBUG_FIND
2775 + printf(" SI: %d [K: %s start EI: %d PI %d] Pos: %d K: %s EI: %d PI: %d HC: %d f=<%s> ",
2776 + stackIdx,
2777 + patElemKindToString(stack[stackIdx -1].psePatRef.prKind),
2778 + stack[stackIdx -1].psePatRef.prElementIdx,
2779 + stack[stackIdx -1].psePatRef.prPatternIdx,
2780 + prevStartPos,
2781 + patElemKindToString(prevPatRef.prKind),
2782 + prevPatRef.prElementIdx,
2783 + prevPatRef.prPatternIdx,
2784 + prevPatHighLightCode,
2785 + getPatternForDebug(patTable, prevPatRef) );
2786 + printFoundStringForDebug(
2787 + searchRegion->sriWindow,
2788 + prevStartPos + searchRegion->sriStartOfTextPos,
2789 + *matchedPatternLength);
2790 + printf("\n");
2791 +#endif
2793 + if (prevPatRef.prKind == PEK_START)
2795 + /*
2796 + * If the end pattern of the previous pattern set is a reference,
2797 + * then the prev. element index is the one of the ref. (due to this
2798 + * string was found before and was stored on stack)
2799 + */
2800 + if (patTable->mptElements[prevPatRef.prElementIdx]->mpteGroup == groupIdx)
2802 + considerStackPatReference(
2803 + &patTable->mptElements[prevPatRef.prElementIdx]->mpteEnd,
2804 + stack[stackIdx - 1].psePatRef.prElementIdx,
2805 + &prevPatRef.prElementIdx);
2808 + /*
2809 + * Ignore current found pattern, if it doesn't fit to the prev.
2810 + * opened one.
2811 + */
2812 + if (stack[stackIdx - 1].psePatRef.prElementIdx == prevPatRef.prElementIdx &&
2813 + (stack[stackIdx - 1].pseHighLightCode == prevPatHighLightCode ||
2814 + stack[stackIdx - 1].pseHighLightCode == IGNORE_HIGHLIGHT_CODE ||
2815 + prevPatHighLightCode == IGNORE_HIGHLIGHT_CODE) &&
2816 + doesBackRefInfoMatch(
2817 + &stack[stackIdx - 1].pseBackRefInfo,
2818 + &prevPatBackRefInfo))
2820 + /*
2821 + * use context group pattern again, if start pattern
2822 + * to skip to was found.
2823 + */
2824 + if (skipToStart)
2826 + currentPatRE = groupPatRE;
2827 + skipToStart = FALSE;
2830 + /*
2831 + * pop. related end pattern from stack.
2832 + */
2833 + stackIdx --;
2836 + else if (prevPatRef.prKind == PEK_END)
2838 + if (stackIdx >= MAX_NESTED_PATTERNS)
2840 +#ifdef DEBUG_FIND
2841 + printf("BACKWARD: MAX. NESTED PATTERN DEPTH REACHED !\n");
2842 +#endif
2843 + prevStartPos = -1;
2845 + else if (!skipToStart)
2847 + /*
2848 + * Put prev. pattern on stack, if contents between start /
2849 + * end shouldn't be skipped (if "skipToStart" is set,
2850 + * a (usually illegal) end pattern to skip inside the
2851 + * skipped one is found (e.g. *\ *\ ..)
2852 + */
2853 + stack[stackIdx].psePatRef = prevPatRef;
2854 + stack[stackIdx].pseHighLightCode = prevPatHighLightCode;
2855 + stack[stackIdx].pseBackRefInfo = prevPatBackRefInfo;
2856 + stackIdx ++;
2858 + currentElement =
2859 + patTable->mptElements[prevPatRef.prElementIdx];
2861 + /*
2862 + * Use start / end pattern regular expression if skip to
2863 + * end is set for found end pattern.
2864 + */
2865 + if (currentElement->mpteSkipBtwnStartEnd)
2867 + currentPatRE = currentElement->mpteStartEndRE;
2868 + skipToStart = TRUE;
2872 + startPos = prevStartPos - 1;
2875 + return prevStartPos;
2879 +** Adapt found pattern element index depending on
2880 +** the info stored on (last) stack element and
2881 +** a given pattern set (belonging to the found pattern).
2883 +static void considerStackPatReference(
2884 + PatternElementSet *patSet,
2885 + int stackElementIdx,
2886 + int *foundElementIdx)
2888 + PatternElement *patElement;
2889 + int i;
2891 + /*
2892 + * If found pattern index already indicates, that found pattern
2893 + * belongs to pattern set stored on stack, then no adaption is needed
2894 + */
2895 + if (*foundElementIdx == stackElementIdx)
2896 + return;
2898 + /*
2899 + * Check all elements of given pattern element set:
2900 + */
2901 + for (i=0; i < patSet->pesNumberOfPattern; i++)
2903 + patElement = patSet->pesPattern[i];
2905 + /*
2906 + * If this set element is a reference and this reference fits
2907 + * to the element stored on stack, then adapt found element index:
2908 + * indicate, that found pattern belongs to pattern set stored on stack
2909 + */
2910 + if (patElement->peType == PET_REFERENCE &&
2911 + patElement->peVal.peuRef.prElementIdx == stackElementIdx)
2913 + *foundElementIdx = stackElementIdx;
2915 + return;
2921 +** Determines, if a string pattern is located at the given position
2922 +** "relBeginPos" in the given "searchRegion". A string pattern is
2923 +** found, if the pattern is located just before given position
2924 +** "relBeginPos" OR if "relBeginPos" is located within a string pattern.
2926 +** Returns true, if the given "pattern" is located at
2927 +** "relBeginPos". "matchInfo" holds all info needed about matched
2928 +** "start" string pattern.
2930 +static int getPatternLocatedAtPos(
2931 + regexp *usedPatRE,
2932 + MatchPatternTable *table,
2933 + SearchRegionInfo *searchRegion,
2934 + int *relBeginPos,
2935 + MatchingElementInfo *matchInfo,
2936 + const char *delimiters)
2938 + int searchStartPos = *relBeginPos;
2939 + PatternReference *patRef = &matchInfo->meiPatRef;
2940 + FoundStringInfo foundStringInfo;
2941 + int relMatchStartPos;
2942 + int relMatchEndPos;
2944 + patRef->prElementIdx = NO_ELEMENT_IDX;
2945 + patRef->prKind = PEK_UNKNOWN;
2946 + patRef->prPatternIdx = NO_PATTERN_IDX;
2948 + matchInfo->meiHighLightCode = IGNORE_HIGHLIGHT_CODE;
2949 + matchInfo->meiAbsStartPos = -1;
2950 + matchInfo->meiLength = 0;
2952 + /*
2953 + * No backward search possible, if we are at beginning of
2954 + * search region
2955 + */
2956 + if (searchStartPos == 0)
2957 + return FALSE;
2959 + /*
2960 + * Search in backward direction for 1st occurance of a string pattern
2961 + * starting one char before "searchStartPos".
2962 + */
2963 + if (ExecRE(
2964 + usedPatRE,
2965 + searchRegion->sriText,
2966 + searchRegion->sriText + searchStartPos - 1,
2967 + TRUE,
2968 + searchRegion->sriPrevChar,
2969 + searchRegion->sriText[searchStartPos],
2970 + delimiters,
2971 + searchRegion->sriText,
2972 + NULL))
2974 + /*
2975 + * String pattern was found:
2976 + */
2977 + foundStringInfo.fsiStartPtr = usedPatRE->startp[0];
2978 + foundStringInfo.fsiEndPtr = usedPatRE->endp[0];
2979 + foundStringInfo.fsiLength =
2980 + foundStringInfo.fsiEndPtr - foundStringInfo.fsiStartPtr;
2982 + relMatchEndPos = foundStringInfo.fsiEndPtr - searchRegion->sriText;
2983 + relMatchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
2985 + /*
2986 + * Is found pattern located exactly one char before "relBeginPos" OR
2987 + * is "relBeginPos" located within found string pattern ?
2988 + * Note: "relMatchEndPos" indicates 1st pos. in "sriText"
2989 + * which does *not* belong to found string anymore.
2990 + */
2991 + if ((*relBeginPos == relMatchEndPos) ||
2992 + (*relBeginPos >= relMatchStartPos &&
2993 + *relBeginPos < relMatchEndPos))
2995 + *relBeginPos = relMatchEndPos;
2997 + /*
2998 + * Determine match element info related to found string.
2999 + */
3000 + matchInfo->meiAbsStartPos =
3001 + foundStringInfo.fsiStartPtr - searchRegion->sriText +
3002 + searchRegion->sriStartOfTextPos;
3003 + matchInfo->meiLength = foundStringInfo.fsiLength;
3005 + foundStringInfo.fsiPrevChar =
3006 + foundStringInfo.fsiStartPtr == searchRegion->sriText ?
3007 + searchRegion->sriPrevChar : *(foundStringInfo.fsiStartPtr - 1);
3009 + foundStringInfo.fsiSuccChar =
3010 + *(foundStringInfo.fsiEndPtr) == '\0' ?
3011 + searchRegion->sriSuccChar : *(foundStringInfo.fsiEndPtr);
3013 + foundStringInfo.fsiDelimiters = delimiters;
3015 + return(
3016 + getMatchedElementInfo(
3017 + searchRegion->sriWindow,
3018 + table,
3019 + &foundStringInfo,
3020 + matchInfo));
3024 + return FALSE;
3028 +** Get all needed info related to matched "start" string pattern
3029 +** (given by parameter "foundStringInfo").
3031 +** Returns true, if info was determined successfully.
3033 +static int getMatchedElementInfo(
3034 + WindowInfo *window,
3035 + MatchPatternTable *table,
3036 + FoundStringInfo *foundStringInfo,
3037 + MatchingElementInfo *matchInfo)
3039 + PatternReference *patRef = &matchInfo->meiPatRef;
3040 + int absMatchStartPos = matchInfo->meiAbsStartPos;
3041 + MatchPatternTableElement *matchedElement;
3043 + if (getPatternInfo(
3044 + table,
3045 + foundStringInfo,
3046 + patRef,
3047 + &matchInfo->meiBackRefInfo))
3049 + /*
3050 + * A pattern reference could be assigned to found string:
3051 + */
3052 + matchedElement = table->mptElements[patRef->prElementIdx];
3054 + matchInfo->meiElement = matchedElement;
3056 + /*
3057 + * get highlight code of found string pattern, if applicable
3058 + */
3059 + if (!matchedElement->mpteIgnoreHighLightInfo)
3061 + matchInfo->meiHighLightCode =
3062 + HighlightCodeOfPos(window, absMatchStartPos);
3065 + /*
3066 + * setup mono pattern info of found string pattern
3067 + */
3068 + if (matchedElement->mpteIsMonoPattern)
3070 + if (matchedElement->mpteIgnoreHighLightInfo)
3072 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
3074 + else
3076 + /*
3077 + * determine mono pattern info depending on highLightCodes
3078 + * before / after found string pattern.
3079 + */
3080 + patRef->prMonoInfo =
3081 + determineMonoPatInfo(
3082 + window,
3083 + matchInfo->meiHighLightCode,
3084 + absMatchStartPos - 1,
3085 + absMatchStartPos + matchInfo->meiLength,
3086 + &patRef->prKind);
3089 + else
3091 + patRef->prMonoInfo = PEMI_NOT_MONO;
3094 + return TRUE;
3096 + else
3098 + /*
3099 + * Found string can't be assigned to a pattern element
3100 + * (should never occur).
3101 + */
3102 + return FALSE;
3107 +** Returns string pattern of given pattern element.
3109 +StringPattern *GetStringPattern(
3110 + MatchPatternTable *table,
3111 + PatternElement *pattern )
3113 + switch (pattern->peType)
3115 + case PET_SINGLE:
3116 + return &pattern->peVal.peuSingle;
3117 + break;
3119 + case PET_MULTIPLE:
3120 + return &pattern->peVal.peuMulti.mpStringPattern;
3121 + break;
3123 + case PET_REFERENCE:
3124 + return GetStringPattern(
3125 + table,
3126 + getPatternOfReference(table, pattern->peVal.peuRef));
3127 + break;
3130 + /*
3131 + * never reached; just to make compiler happy
3132 + */
3133 + return NULL;
3137 +** Returns pattern element of given pattern reference.
3139 +static PatternElement *getPatternOfReference(
3140 + MatchPatternTable *table,
3141 + PatternReference patRef)
3143 + MatchPatternTableElement **element = table->mptElements;
3145 + return element[ patRef.prElementIdx ]->mpteAll.pesPattern[patRef.prPatternIdx];
3148 +#ifdef DEBUG_FIND
3149 +static char *getPatternForDebug(
3150 + MatchPatternTable *table,
3151 + PatternReference patRef )
3153 + if (patRef.prElementIdx < 0)
3155 + return "---";
3158 + return
3159 + GetStringPattern(
3160 + table,
3161 + getPatternOfReference(table, patRef))->spText;
3164 +static char *patElemKindToString(
3165 + PatternElementKind patElemKind)
3167 + if (patElemKind == PEK_START)
3168 + return "START";
3169 + else if (patElemKind == PEK_MIDDLE)
3170 + return "MIDDLE";
3171 + else if (patElemKind == PEK_END)
3172 + return "END";
3173 + else
3174 + return "UNKNOWN";
3177 +static void printFoundStringForDebug(
3178 + WindowInfo *window,
3179 + int absStartPos,
3180 + int length)
3182 + char *foundStr =
3183 + BufGetRange( window->buffer, absStartPos, absStartPos + length);
3185 + printf("%d (abs.) <%s>",
3186 + absStartPos,
3187 + foundStr);
3189 + XtFree(foundStr);
3191 +#endif
3194 diff --quilt /dev/null new/source/patternMatch.h
3195 --- /dev/null
3196 +++ new/source/patternMatch.h
3197 @@ -0,0 +1,170 @@
3198 +/* $Id: patternMatch.h,v 1.2 2003/10/11 16:45:25 uleh Exp $ */
3200 +#ifndef NEDIT_PATTERNMATCH_H_INCLUDED
3201 +#define NEDIT_PATTERNMATCH_H_INCLUDED
3203 +#include "regularExp.h"
3205 +#define NO_GROUP_IDX -1
3206 +#define NO_ELEMENT_IDX -1
3207 +#define NO_PATTERN_IDX -1
3209 +#define MAX_GLOBAL_BACK_REF_ID 9
3210 +#define NO_LOCAL_BACK_REF_ID -1
3212 +typedef enum {
3213 + PEK_UNKNOWN,
3214 + PEK_START,
3215 + PEK_END,
3216 + PEK_MIDDLE
3217 +} PatternElementKind;
3219 +typedef enum {
3220 + PEMI_NOT_MONO,
3221 + PEMI_MONO_NOT_SYNTAX_BASED,
3222 + PEMI_MONO_AMBIGUOUS_SYNTAX,
3223 + PEMI_MONO_DEFINITE_SYNTAX
3224 +} PatternElementMonoInfo;
3226 +typedef struct _PatternReference {
3227 + PatternElementKind prKind;
3228 + PatternElementMonoInfo prMonoInfo;
3229 + int prElementIdx;
3230 + int prPatternIdx;
3231 +} PatternReference;
3233 +typedef enum {
3234 + MPT_INDIVIDUAL,
3235 + MPT_SUB,
3236 + MPT_GROUP
3237 +} MatchPatternType;
3239 +typedef struct _MatchPatternSequenceElement {
3240 + char *mpseName;
3241 + MatchPatternType mpseType;
3242 + int mpseIndex;
3243 +} MatchPatternSequenceElement;
3245 +typedef struct _MatchPatternGroupElement {
3246 + char *mpgeName;
3247 + int mpgeNumberOfSubPatterns;
3248 + char **mpgeSubPatternIds;
3249 + regexp *mpgeKeywordRE;
3250 +} MatchPatternGroupElement;
3252 +typedef enum {
3253 + PWB_NONE,
3254 + PWB_LEFT,
3255 + PWB_RIGHT,
3256 + PWB_BOTH
3257 +} PatternWordBoundary;
3259 +typedef struct _StrPatBackRefElement{
3260 + int spbreLocalBackRefID;
3261 + char *spbreRegExpText;
3262 +} StrPatBackRefElement;
3264 +typedef struct _StringPattern {
3265 + char *spText;
3266 + int spLength;
3267 + PatternWordBoundary spWordBoundary;
3268 + int spCaseInsensitive;
3269 + int spRegularExpression;
3270 + regexp *spTextRE;
3271 + char *spOrigText;
3272 + int spBackRefParsed;
3273 + int spBackRefResolved;
3274 + StrPatBackRefElement spOwnGlobalBackRef[MAX_GLOBAL_BACK_REF_ID];
3275 + int spGlobalToLocalBackRef[MAX_GLOBAL_BACK_REF_ID];
3276 +} StringPattern;
3278 +typedef struct _MultiPattern {
3279 + StringPattern mpStringPattern;
3280 + int mpNumberOfReferences;
3281 + PatternReference *mpRefList;
3282 +} MultiPattern;
3284 +typedef enum {
3285 + PET_SINGLE,
3286 + PET_MULTIPLE,
3287 + PET_REFERENCE
3288 +} PatternElementType;
3290 +typedef struct _PatternElement {
3291 + int peIndex;
3292 + PatternElementKind peKind;
3293 + PatternElementType peType;
3294 + union {
3295 + StringPattern peuSingle;
3296 + MultiPattern peuMulti;
3297 + PatternReference peuRef;
3298 + } peVal;
3299 +} PatternElement;
3301 +typedef struct _PatternElementSet {
3302 + int pesNumberOfPattern;
3303 + PatternElement **pesPattern;
3304 +} PatternElementSet;
3306 +typedef struct _GlobalBackRefElement{
3307 + StringPattern *gbreDefByStrPat;
3308 + char *gbreRegExpText;
3309 +} GlobalBackRefElement;
3311 +typedef struct _MatchPatternTableElement {
3312 + char *mpteName;
3313 + int mpteIndex;
3314 + MatchPatternType mpteType;
3315 + int mpteGroup;
3316 + PatternElementSet mpteAll;
3317 + PatternElementSet mpteStart;
3318 + PatternElementSet mpteMiddle;
3319 + PatternElementSet mpteEnd;
3320 + int mpteFlash;
3321 + int mpteIsMonoPattern;
3322 + int mpteSkipBtwnStartEnd;
3323 + int mpteIgnoreHighLightInfo;
3324 + regexp *mpteStartEndRE;
3325 + GlobalBackRefElement mpteGlobalBackRef[MAX_GLOBAL_BACK_REF_ID];
3326 +} MatchPatternTableElement;
3328 +typedef struct _MatchPatternTable {
3329 + int mptNumberOfElements;
3330 + MatchPatternTableElement **mptElements;
3331 +} MatchPatternTable;
3333 +typedef struct _StringMatchTable {
3334 + char *smtLanguageMode;
3335 + MatchPatternTable *smtAllPatterns;
3336 + regexp *smtAllPatRE;
3337 + regexp *smtFlashPatRE;
3338 + regexp *smtUsedPatRE;
3339 + int smtNumberOfGroups;
3340 + MatchPatternGroupElement **smtGroups;
3341 + int smtNumberOfSeqElements;
3342 + MatchPatternSequenceElement **smtSequence;
3343 +} StringMatchTable;
3345 +typedef enum {
3346 + MT_FLASH_DELIMIT,
3347 + MT_FLASH_RANGE,
3348 + MT_SELECT,
3349 + MT_GOTO,
3350 + MT_MACRO
3351 +} MatchingType;
3353 +int FindMatchingString(
3354 + WindowInfo *window,
3355 + MatchingType matchingType,
3356 + int *charPos,
3357 + int startLimit,
3358 + int endLimit,
3359 + int *matchPos,
3360 + int *matchLength,
3361 + int *direction);
3363 +StringPattern *GetStringPattern(
3364 + MatchPatternTable *table,
3365 + PatternElement *pattern);
3367 +#endif /* NEDIT_PATTERNMATCH_H_INCLUDED */
3368 diff --quilt /dev/null new/source/patternMatchData.c
3369 --- /dev/null
3370 +++ new/source/patternMatchData.c
3371 @@ -0,0 +1,7780 @@
3372 +static const char CVSID[] = "$Id: patternMatchData.c,v 1.4 2004/10/27 21:57:12 uleh Exp $";
3373 +/*******************************************************************************
3374 +* *
3375 +* patternMatchData.c -- Maintain and allow user to edit a matching pattern list*
3376 +* used for pattern matching *
3377 +* *
3378 +* Copyright (C) 2003-2004, Uwe Lehnert *
3379 +* *
3380 +* This is free software; you can redistribute it and/or modify it under the *
3381 +* terms of the GNU General Public License as published by the Free Software *
3382 +* Foundation; either version 2 of the License, or (at your option) any later *
3383 +* version. In addition, you may distribute versions of this program linked to *
3384 +* Motif or Open Motif. See README for details. *
3385 +* *
3386 +* This software is distributed in the hope that it will be useful, but WITHOUT *
3387 +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
3388 +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
3389 +* for more details. *
3390 +* *
3391 +* You should have received a copy of the GNU General Public License along with *
3392 +* software; if not, write to the Free Software Foundation, Inc., 59 Temple *
3393 +* Place, Suite 330, Boston, MA 02111-1307 USA *
3394 +* *
3395 +* Nirvana Text Editor *
3396 +* October 27, 2004 *
3397 +* *
3398 +* Written by Uwe Lehnert *
3399 +* *
3400 +*******************************************************************************/
3401 +#ifdef HAVE_CONFIG_H
3402 +#include "../config.h"
3403 +#endif
3405 +#include <stdlib.h>
3406 +#include <stdio.h>
3407 +#include <limits.h>
3408 +#include <string.h>
3409 +#include <ctype.h>
3411 +#ifdef VMS
3412 +#include "../util/VMSparam.h"
3413 +#else
3414 +#ifndef __MVS__
3415 +#include <sys/param.h>
3416 +#endif
3417 +#endif /*VMS*/
3419 +#include <Xm/Xm.h>
3420 +#include <Xm/Form.h>
3421 +#include <Xm/Frame.h>
3422 +#include <Xm/Text.h>
3423 +#include <Xm/LabelG.h>
3424 +#include <Xm/PushB.h>
3425 +#include <Xm/PushBG.h>
3426 +#include <Xm/ToggleB.h>
3427 +#include <Xm/RowColumn.h>
3428 +#include <Xm/SeparatoG.h>
3430 +#include "../util/misc.h"
3431 +#include "../util/DialogF.h"
3432 +#include "../util/managedList.h"
3434 +#include "regularExp.h"
3435 +#include "textBuf.h"
3436 +#include "nedit.h"
3437 +#include "window.h"
3438 +#include "preferences.h"
3439 +#include "help.h"
3440 +#include "file.h"
3441 +#include "textP.h"
3443 +#include "patternMatch.h"
3444 +#include "patternMatchData.h"
3446 +#ifdef HAVE_DEBUG_H
3447 +#include "../debug.h"
3448 +#endif
3451 + * local synonyms
3452 + */
3453 +#define MAX_LOCAL_BACK_REF_ID 9
3454 +#define LOCAL_BACK_REF_ID_USED -2
3456 +#define MAX_NUMBER_MIDDLE_PATTERN 10
3457 +#define MAX_STRING_PATTERNS 30
3458 +#define MAX_NBR_MATCH_PATTERNS 50
3459 +#define MAX_NBR_MATCH_PATTERN_GROUPS 50
3460 +#define MAX_NBR_SEQ_ELEMENTS MAX_NBR_MATCH_PATTERNS + MAX_NBR_MATCH_PATTERN_GROUPS
3462 +#define MATCH_PAT_NAME_LBL_TXT "Matching Pattern Name"
3463 +#define STRING_PATTERNS_LBL_TXT "String Patterns"
3465 +#define BORDER 4
3466 +#define LIST_RIGHT 41
3467 +#define PLAIN_LM_STRING "PLAIN"
3469 +#define SPNM_NONE_SELECTED "none selected"
3471 +#define KEEP_LANGUAGE_MODE True
3472 +#define DISCARD_LANGUAGE_MODE False
3474 +#define STRING_PATTERN_DIALOG True
3475 +#define CONTEXT_GROUP_DIALOG False
3478 + * local data definitions
3479 + */
3480 +typedef struct _ErrorInfo {
3481 + char *eiDetail;
3482 + char *eiLanguageMode;
3483 + char *eiMPTabElementName;
3484 + char *eiStringPatText;
3485 + char *eiRegExpCompileMsg;
3486 + int eiBackRefNbr;
3487 +} ErrorInfo;
3489 +typedef struct _BackRefBracketInfo {
3490 + int brbiGlobalId;
3491 + char *brbiContentStart;
3492 + int brbiNestingLevel;
3493 +} BackRefBracketInfo;
3495 +typedef struct _RegExpStringInfo {
3496 + int resiNbrOfAddedMultiPat;
3497 + PatternReference **resiAddedMultiPat;
3498 + char *resiNoneWBRegExpString;
3499 + char *resiLeftWBRegExpString;
3500 + char *resiRightWBRegExpString;
3501 + char *resiBothWBRegExpString;
3502 + int resiLocalBackRefID;
3503 +} RegExpStringInfo;
3505 +typedef struct _ReadMatchPatternInfo {
3506 + int rmpiNbrOfElements;
3507 + MatchPatternTableElement *rmpiElement[MAX_NBR_MATCH_PATTERNS];
3508 + int rmpiNbrOfGroups;
3509 + MatchPatternGroupElement *rmpiGroup[MAX_NBR_MATCH_PATTERN_GROUPS];
3510 + int rmpiNbrOfSeqElements;
3511 + MatchPatternSequenceElement *rmpiSequence[MAX_NBR_SEQ_ELEMENTS];
3512 + regexp *rmpiAllPatRE;
3513 + regexp *rmpiFlashPatRE;
3514 +} ReadMatchPatternInfo;
3516 +typedef struct _DialogStringPatternElement {
3517 + char *dspeText;
3518 + PatternElementKind dspeKind;
3519 + PatternWordBoundary dspeWordBoundary;
3520 + int dspeCaseInsensitive;
3521 + int dspeRegularExpression;
3522 +} DialogStringPatternElement;
3524 +typedef struct _DialogStringPatterns {
3525 + int dspNumberOfPatterns;
3526 + DialogStringPatternElement *dspElements[MAX_STRING_PATTERNS];
3527 +} DialogStringPatterns;
3529 +typedef struct _DialogMatchPatternTableElement {
3530 + char *dmpteName;
3531 + MatchPatternType dmpteType;
3532 + DialogStringPatterns dmptePatterns;
3533 + int dmpteSkipBtwnStartEnd;
3534 + int dmpteIgnoreHighLightInfo;
3535 + int dmpteFlash;
3536 +} DialogMatchPatternTableElement;
3538 +typedef struct _DialogMatchPatternGroupElement {
3539 + char *dmpgeName;
3540 + int dmpgeNumberOfSubPatterns;
3541 + char *dmpgeSubPatternIds[MAX_NBR_MATCH_PATTERNS];
3542 +} DialogMatchPatternGroupElement;
3544 +typedef struct _DialogMatchPatternSequenceElement {
3545 + char *dmpseName;
3546 + MatchPatternType dmpseType;
3547 + int dmpseValid;
3548 + void *dmpsePtr;
3549 +} DialogMatchPatternSequenceElement;
3551 +typedef struct _DialogMatchPatternInfo {
3552 + int dmpiNbrOfSeqElements;
3553 + DialogMatchPatternSequenceElement *dmpiSequence[MAX_NBR_SEQ_ELEMENTS];
3554 +} DialogMatchPatternInfo;
3556 +typedef enum {
3557 + DMPTR_OK,
3558 + DMPTR_EMPTY,
3559 + DMPTR_INCOMPLETE
3560 +} DMPTranslationResult;
3562 +typedef struct _NameList {
3563 + int nlNumber;
3564 + char *nlId[MAX_NBR_SEQ_ELEMENTS + 1];
3565 +} NameList;
3568 + * prototypes of local functions
3569 + */
3570 +static void treatDuplicatedPattern(
3571 + MatchPatternTable *table,
3572 + PatternElement *prevPattern,
3573 + PatternReference prevPatRef,
3574 + PatternElement *lastPattern,
3575 + PatternReference lastPatRef);
3576 +static void treatDuplicatedPatternElements(
3577 + MatchPatternTable *table,
3578 + MatchPatternTableElement *prevElement,
3579 + int prevElementIdx,
3580 + PatternElement *lastPattern,
3581 + PatternReference lastPatRef);
3582 +static void treatDuplicatedMTElements(
3583 + MatchPatternTable *table,
3584 + MatchPatternTableElement *prevElement,
3585 + int prevElementIdx,
3586 + MatchPatternTableElement *lastElement,
3587 + int lastElementIdx);
3588 +static void treatDuplicatedMTEntries(
3589 + MatchPatternTableElement **element,
3590 + int nbrOfElements);
3592 +static int createStrPatRegExpOfElement(
3593 + ReadMatchPatternInfo *readPatInfo,
3594 + MatchPatternTableElement *element,
3595 + ErrorInfo *errInfo);
3596 +static int createStrPatRegExp(
3597 + StringPattern *strPat,
3598 + ErrorInfo *errInfo);
3599 +static void adaptCompileMsg(
3600 + char *compileMsg,
3601 + int *globalToLocalBackRef);
3602 +static int localToGlobalBackRef(
3603 + int *globalToLocalBackRef,
3604 + int localId);
3605 +static int createStartEndRegExp(
3606 + ReadMatchPatternInfo *readMatchPatternInfo,
3607 + MatchPatternTableElement *element,
3608 + ErrorInfo *errInfo);
3609 +static int createGroupRegExp(
3610 + ReadMatchPatternInfo *readPatInfo,
3611 + MatchPatternGroupElement *group,
3612 + ErrorInfo *errInfo);
3613 +static void setupRegExpStringBuffers(
3614 + ReadMatchPatternInfo *readMatchPatternInfo,
3615 + RegExpStringInfo *regExpStringInfo);
3616 +static void addSMTRegExpString(
3617 + char *result,
3618 + char *partToAdd,
3619 + const char *postfix);
3620 +static void composeStartEndRegExpString(
3621 + ReadMatchPatternInfo *readMatchPatternInfo,
3622 + MatchPatternTableElement *element,
3623 + char **regExpString);
3624 +static void addElementToRegExpString(
3625 + MatchPatternTableElement *element,
3626 + ReadMatchPatternInfo *readMatchPatternInfo,
3627 + RegExpStringInfo *regExpStringInfo);
3628 +static void addUniquePatternToRegExpString(
3629 + PatternElement *patElement,
3630 + PatternReference *patElementReference,
3631 + ReadMatchPatternInfo *readMatchPatternInfo,
3632 + RegExpStringInfo *regExpStringInfo);
3633 +static void addPatternToRegExpString(
3634 + StringPattern *pattern,
3635 + RegExpStringInfo *regExpStringInfo);
3636 +static char *adaptLocalBackRefs(
3637 + char *regExpText,
3638 + int *commonLocalId);
3639 +static void scanForLocalBackRefs(
3640 + char *regExpText,
3641 + int *localBackRefList);
3642 +static int isMultiPatternNotAdded(
3643 + RegExpStringInfo *regExpStringInfo,
3644 + PatternReference *toBeAddedPR);
3645 +static void catSMTRegExpStrings(
3646 + RegExpStringInfo *regExpStringInfo,
3647 + char **regExpString);
3648 +static void freeRegExpStringInfo(
3649 + RegExpStringInfo *regExpStringInfo);
3650 +static int totalKeywordOfTableLen(
3651 + ReadMatchPatternInfo *info,
3652 + int *nbrOfMultiPatterns);
3653 +static int totalMatchPatternTableElementLen(
3654 + ReadMatchPatternInfo *info,
3655 + MatchPatternTableElement *element,
3656 + int *nbrOfMultiPatterns);
3657 +static int patternElementLen(
3658 + ReadMatchPatternInfo *info,
3659 + PatternElement *patElement,
3660 + int *nbrOfMultiPatterns);
3662 +static void parseMatchingPatternSetError(
3663 + const char *stringStart,
3664 + const char *stoppedAt,
3665 + ErrorInfo *errInfo);
3666 +static void dialogMatchingPatternSetError(
3667 + char *title,
3668 + ErrorInfo *errInfo);
3670 +static char *createMatchPatternsString(
3671 + StringMatchTable *table,
3672 + char *indentStr);
3673 +static char *createPatternElementString(
3674 + MatchPatternTable *table,
3675 + PatternElement *pat);
3677 +static StringMatchTable *readDefaultStringMatchTable(const char *langModeName);
3678 +static int isDefaultMatchPatternTable(StringMatchTable *table);
3680 +static void freeReadMatchPatternInfo( ReadMatchPatternInfo *readPatInfo );
3681 +static void freeStringMatchTable( StringMatchTable *table );
3682 +static void freeMatchPatternTableElement( MatchPatternTableElement *element );
3683 +static void freePatternElement( PatternElement *element );
3684 +static void freeStringPattern( StringPattern *strPat );
3685 +static void freeMatchPatternGroupElement( MatchPatternGroupElement *group );
3686 +static void freeMatchPatternSequenceElement( MatchPatternSequenceElement *sequence );
3688 +static StringMatchTable *readMatchPatternSet(char **inPtr);
3689 +static StringMatchTable *readMatchPatternSetContent(
3690 + char **inPtr,
3691 + char *stringStart,
3692 + char *languageMode);
3693 +static int createRegExpOfPatterns(
3694 + ReadMatchPatternInfo *readPatInfo,
3695 + ErrorInfo *errInfo);
3696 +static int createRegExpOfAllPatterns(
3697 + ReadMatchPatternInfo *readPatInfo,
3698 + ErrorInfo *errInfo);
3699 +static int createRegExpOfStrPatterns(
3700 + ReadMatchPatternInfo *readPatInfo,
3701 + ErrorInfo *errInfo);
3702 +static StringMatchTable *createStringMatchTable(
3703 + ReadMatchPatternInfo *readPatInfo,
3704 + char *languageMode);
3705 +static int readMatchPatternEntry(
3706 + char **inPtr,
3707 + ErrorInfo *errInfo,
3708 + ReadMatchPatternInfo *info);
3709 +static void recordPatternSequence(
3710 + ReadMatchPatternInfo *info,
3711 + char *name,
3712 + MatchPatternType type,
3713 + int index);
3714 +static int assignIndividualGroup(
3715 + ReadMatchPatternInfo *info,
3716 + char **errMsg,
3717 + MatchPatternTableElement *element);
3718 +static MatchPatternTableElement *getPatternOfName(
3719 + ReadMatchPatternInfo *info,
3720 + char *subPatToSearch);
3721 +static MatchPatternGroupElement *readMatchPatternGroup(
3722 + char **inPtr,
3723 + ErrorInfo *errInfo,
3724 + char *name,
3725 + ReadMatchPatternInfo *info);
3726 +static int readPatternElement(
3727 + char **inPtr,
3728 + char **errMsg,
3729 + PatternElement **pattern);
3730 +static PatternElement *createPatternElement(
3731 + char *patternText,
3732 + PatternElementKind patternKind,
3733 + PatternWordBoundary wordBoundary,
3734 + int caseInsensitive,
3735 + int regularExpression);
3737 +static int createGlobalBackRefList(
3738 + ReadMatchPatternInfo *readPatInfo,
3739 + MatchPatternTableElement *element,
3740 + ErrorInfo *errInfo);
3741 +StringPattern *getReadStringPattern(
3742 + ReadMatchPatternInfo *readPatInfo,
3743 + PatternElement *pattern );
3744 +static PatternElement *getReadPatternOfReference(
3745 + ReadMatchPatternInfo *readPatInfo,
3746 + PatternReference *patRef);
3747 +static char *replaceCapturingParentheses(
3748 + const char *source);
3749 +static int parseGlobalBackRefs(
3750 + StringPattern *strPat,
3751 + GlobalBackRefElement *backRefList,
3752 + ErrorInfo *errInfo);
3753 +static int updateGlobalBackRefs(
3754 + StringPattern *strPat,
3755 + GlobalBackRefElement *backRefList,
3756 + ErrorInfo *errInfo);
3757 +static char *createBackRefRegExpText(
3758 + const char *start,
3759 + const char *end);
3760 +static int resolveGlobalBackRefs(
3761 + ReadMatchPatternInfo *readPatInfo,
3762 + MatchPatternTableElement *element,
3763 + ErrorInfo *errInfo);
3764 +static int resolveGlobalBackRefsOfStrPat(
3765 + StringPattern *strPat,
3766 + GlobalBackRefElement *backRefList,
3767 + ErrorInfo *errInfo);
3768 +static char *substituteGlobalBackRef(
3769 + StringPattern *strPat,
3770 + char *subsPtr,
3771 + int globalId,
3772 + int *localId,
3773 + GlobalBackRefElement *backRefList,
3774 + ErrorInfo *errInfo);
3775 +static char *replaceBackRefIdByRegExp(
3776 + StringPattern *strPat,
3777 + char *replaceStartPtr,
3778 + char *regExp);
3779 +static char *convertGlobalToLocalBackRef(
3780 + StringPattern *strPat,
3781 + char *convertPtr);
3783 +static MatchPatternTableElement *readMatchPatternTableElement(
3784 + char **inPtr,
3785 + char **errMsg,
3786 + char *name,
3787 + MatchPatternType type);
3788 +static int sortReadPatternElementSet(
3789 + PatternElementSet *allPat,
3790 + char **errMsg,
3791 + MatchPatternTableElement *result);
3792 +static void countPatternElementKind(
3793 + PatternElementSet *allPat,
3794 + MatchPatternTableElement *result);
3795 +static void sortPatternElementSet(
3796 + PatternElementSet *allPat,
3797 + MatchPatternTableElement *result);
3798 +static void copyPatternSet(
3799 + PatternElementSet *sourcePS,
3800 + PatternElementSet *destPS);
3802 +static int getMPSName(
3803 + char **inPtr,
3804 + ErrorInfo *errInfo,
3805 + char **name );
3806 +static int getMPSTypeAttribute(
3807 + char **inPtr,
3808 + ErrorInfo *errInfo,
3809 + MatchPatternType *type);
3810 +static int getMPSGlobalAttribute(
3811 + char **inPtr,
3812 + char **errMsg,
3813 + int *isMonoPattern,
3814 + int *comment,
3815 + int *flash,
3816 + int *ignoreHighLightInfo);
3817 +static int getMPSPatternAttribute(
3818 + char **inPtr,
3819 + char **errMsg,
3820 + PatternElementKind *patternKind,
3821 + PatternWordBoundary *wordBoundary,
3822 + int *caseInsensitive,
3823 + int *regularExpression);
3825 +static void copyStringMatchTableForDialog(
3826 + StringMatchTable *sourceTable,
3827 + DialogMatchPatternInfo *dialogTable );
3828 +static void *copyMatchPatternElementForDialog(
3829 + MatchPatternTable *table,
3830 + int sourceElementIdx);
3831 +static void copyPatternForDialog(
3832 + MatchPatternTable *table,
3833 + PatternElement *sourcePattern,
3834 + DialogStringPatternElement **dialogPattern );
3835 +static void *copyGroupElementForDialog(
3836 + MatchPatternGroupElement *sourceGroup);
3837 +static void copySequenceElementForDialog(
3838 + StringMatchTable *sourceTable,
3839 + MatchPatternSequenceElement *sourceSeqElement,
3840 + DialogMatchPatternSequenceElement **dialogSeqElement );
3841 +static DialogMatchPatternSequenceElement *copyDialogSequenceElement(
3842 + DialogMatchPatternSequenceElement *sourceSeq);
3843 +static void freeDialogMatchPatternElement(
3844 + DialogMatchPatternTableElement *dialogElement );
3845 +static void freeDialogStringPatternElement(
3846 + DialogStringPatternElement *element);
3847 +static void freeDialogGroupElement(
3848 + DialogMatchPatternGroupElement *dialogGroup );
3849 +static void freeDialogSequenceElement(
3850 + DialogMatchPatternSequenceElement *dialogSeq );
3852 +static void copyDialogStringPatternsFromTable(
3853 + DialogMatchPatternTableElement *tableElement,
3854 + DialogStringPatterns *destPatterns);
3855 +static void copyDialogStringPatterns(
3856 + DialogStringPatterns *sourcePatterns,
3857 + DialogStringPatterns *destPatterns);
3858 +static void freeDialogStringPatterns(
3859 + DialogStringPatterns *patterns);
3861 +static DialogStringPatternElement *copyDialogStringPatternElement(
3862 + DialogStringPatternElement *sourceElement);
3864 +static void copyDialogPatternNamesFromGroup(
3865 + DialogMatchPatternGroupElement *group,
3866 + DialogStringPatterns *destPatterns);
3867 +static DialogStringPatternElement *copyDialogPatternName(
3868 + char *sourcePatternId);
3869 +static void copyDialogPatternNamesToGroup(
3870 + DialogStringPatterns *sourceNames,
3871 + DialogMatchPatternGroupElement *destGroup);
3873 +static void setDialogType(int dialogShowsStringPattern);
3874 +static void setSensitiveWordBoundaryBox(int enable);
3876 +static void *getStringPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
3877 + void *cbArg);
3878 +static void setStringPatternDisplayedCB(void *item, void *cbArg);
3879 +static void freeStringPatternItemCB(void *item);
3881 +static void *getMatchPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
3882 + void *cbArg);
3883 +static void setMatchPatternDisplayedCB(void *item, void *cbArg);
3884 +static void freeMatchPatternItemCB(void *item);
3885 +static int deleteMatchPatternItemCB(int itemIndex, void *cbArg);
3887 +static void matchPatternLangModeCB(Widget w, XtPointer clientData, XtPointer callData);
3888 +static void pmLanguageModeDialogCB(Widget w, XtPointer clientData, XtPointer callData);
3890 +static void destroyCB(Widget w, XtPointer clientData, XtPointer callData);
3891 +static void okCB(Widget w, XtPointer clientData, XtPointer callData);
3892 +static void applyCB(Widget w, XtPointer clientData, XtPointer callData);
3893 +static void checkCB(Widget w, XtPointer clientData, XtPointer callData);
3894 +static void restoreCB(Widget w, XtPointer clientData, XtPointer callData);
3895 +static void deleteCB(Widget w, XtPointer clientData, XtPointer callData);
3896 +static void closeCB(Widget w, XtPointer clientData, XtPointer callData);
3897 +static void helpCB(Widget w, XtPointer clientData, XtPointer callData);
3899 +static void matchPatTypeCB(Widget w, XtPointer clientData, XtPointer callData);
3900 +static void strPatRegExpressionCB(Widget w, XtPointer clientData, XtPointer callData);
3901 +static void changeExistingSubPattern(char *warnTitle);
3902 +static void changeStringPatternToGroup(void);
3903 +static void changeGroupToStringPattern(char *warnTitle);
3905 +static Widget createSubPatternNameMenu(
3906 + Widget parent,
3907 + char *currentSubPatName,
3908 + int allSubPatterns);
3909 +static void setupSubPatternNameList(
3910 + char *currentSubPatName,
3911 + int allSubPatterns,
3912 + NameList *nameList);
3913 +static void createSubPatNameMenuEntry(
3914 + Widget menu,
3915 + char *subPatName);
3916 +static void setSubPatternNameMenu(
3917 + const char *subPatName);
3918 +static void updateSubPatternNameMenu(
3919 + char *currentSubPatName,
3920 + int allSubPatterns);
3921 +static char *getSelectedSubPatternName(void);
3922 +static int isSubPatternNameInCurStrPat(
3923 + char *subPatName);
3925 +static DialogMatchPatternSequenceElement *readMatchPatternFields(int silent);
3926 +static int isStartPatternElementAvailable(
3927 + DialogStringPatterns *dialogPatterns);
3928 +static DialogStringPatternElement *readStringPatternFrameFields(int silent);
3930 +static int matchPatternDialogEmpty(void);
3931 +static int stringPatternFrameEmpty(void);
3932 +static int stringPatternFieldsEmpty(
3933 + int strPatIsRelatedToGroup);
3935 +static int getAndUpdateStringMatchTable(void);
3936 +static void updateStringMatchTable(
3937 + StringMatchTable *newTable);
3939 +static StringMatchTable *getDialogStringMatchTable(
3940 + DMPTranslationResult *result);
3941 +static StringMatchTable *translateDialogStringMatchTable(
3942 + DialogMatchPatternInfo *dialogTable,
3943 + DMPTranslationResult *result);
3944 +static MatchPatternTableElement *translateDialogMatchPatternTableElement(
3945 + DialogMatchPatternTableElement *dialogElement);
3946 +static void translateDialogPatterns(
3947 + DialogStringPatterns *dialogPatterns,
3948 + MatchPatternTableElement *newElement);
3949 +static MatchPatternGroupElement *translateDialogMatchPatternGroupElement(
3950 + ReadMatchPatternInfo *info,
3951 + DialogMatchPatternGroupElement *dialogGroup);
3952 +static void sortDialogPatternElementSet(
3953 + PatternElementSet *allPat,
3954 + MatchPatternTableElement *result);
3956 +static int stringMatchTableDiffer(
3957 + StringMatchTable *oldTable,
3958 + StringMatchTable *newTable);
3960 +static int patternElementDiffer(
3961 + PatternElement *oldPE,
3962 + MatchPatternTable *oldTab,
3963 + PatternElement *newPE,
3964 + MatchPatternTable *newTab);
3966 +static DialogMatchPatternGroupElement *getDialogGroupUsingMatchPattern(
3967 + char *matchPatternName);
3968 +static void removeMatchPatternFromGroup(
3969 + char *matchPatternName,
3970 + DialogMatchPatternGroupElement *group);
3971 +static void removeMatchPatternFromAllGroups(
3972 + char *matchPatternName);
3973 +static void renameMatchPatternInGroup(
3974 + char *oldMatchPatternName,
3975 + char *newMatchPatternName,
3976 + DialogMatchPatternGroupElement *group);
3977 +static void renameMatchPatternInAllGroups(
3978 + char *oldMatchPatternName,
3979 + char *newMatchPatternName);
3981 +static void freeVariableDialogData(
3982 + int keepLanguageModeName);
3984 +static void initGlobalBackRefList(
3985 + GlobalBackRefElement *list);
3986 +static void initStrPatBackRefList(
3987 + StringPattern *strPat);
3989 +StringPattern *getUniqueStringPattern(
3990 + PatternElement *pattern );
3992 +static void initErrorInfo(
3993 + ErrorInfo *errInfo);
3994 +static void freeErrorInfo(
3995 + ErrorInfo *errInfo);
3997 +static void freeXtPtr(void **ptr);
3998 +static void freePtr(void **ptr);
4001 + * matching pattern dialog information
4002 + */
4003 +static struct {
4004 + Widget mpdShell;
4005 + Widget mpdLmOptMenu;
4006 + Widget mpdLmPulldown;
4007 + Widget mpdMatchPatternNamesListW;
4008 + Widget mpdMatchPatternNameLbl;
4009 + Widget mpdMatchPatternNameW;
4010 + Widget mptbIndividualW;
4011 + Widget mptbSubPatternW;
4012 + Widget mptbContextGroupW;
4013 + Widget mpdGlobalAttributesLbl;
4014 + Widget gabSkipBtwStartEndW;
4015 + Widget gabFlashW;
4016 + Widget gabSyntaxBasedW;
4017 + Widget mpdStringPatternsLbl;
4018 + Widget mpdStringPatternsListW;
4019 + Widget mpdStringPatternTypeLbl;
4020 + Widget sptStartW;
4021 + Widget sptMiddleW;
4022 + Widget sptEndW;
4023 + Widget mpdWordBoundaryLbl;
4024 + Widget wbbBothW;
4025 + Widget wbbLeftW;
4026 + Widget wbbRightW;
4027 + Widget wbbNoneW;
4028 + Widget mpdStringAttributesLbl;
4029 + Widget sabCaseSensitiveW;
4030 + Widget sabRegularExpressionW;
4031 + Widget mpdStringPatternLbl;
4032 + Widget mpdStringPatternW;
4033 + Widget mpdSubPatNamesLbl;
4034 + Widget mpdSubPatNamesOptMenu;
4035 + Widget mpdSubPatNamesPulldown;
4036 + char *mpdLangModeName;
4037 + DialogMatchPatternSequenceElement *currentDmptSeqElement;
4038 + DialogMatchPatternTableElement *currentDmptElement;
4039 + DialogMatchPatternGroupElement *currentDmptGroup;
4040 + DialogStringPatterns currentStringPatterns;
4041 + DialogMatchPatternInfo mpdTable;
4042 + int mpdStringPatternIsDisplayed;
4043 +} MatchPatternDialog =
4044 + {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
4045 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
4046 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
4047 + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
4048 + NULL, NULL, NULL, NULL,
4049 + {0, {NULL}},
4050 + {0, {NULL}},
4051 + True
4052 + };
4055 + * Matching pattern sources loaded from the nedit resources file or set
4056 + * by the user
4057 + */
4058 +static int NbrMatchTables = 0;
4059 +static StringMatchTable *MatchTables[MAX_LANGUAGE_MODES];
4062 + * Syntax:
4063 + * LanguagePatternSet ::=
4064 + * LanguageName{PatternStatement..}
4066 + * PatternStatement ::=
4067 + * name:[s]:[c][f][m][p][u]:([s|m|e][w|l|r][i]:"pattern":)..)\n)|
4068 + * name:g:"sub-pattern name":..\n..
4070 + * TypeAttribute:
4071 + * s : sub-pattern (pattern is only matched, if part of a pattern group).
4072 + * g : pattern (context) group (i.e. a sequence of sub-patterns).
4073 + * default: individual pattern (pattern is matched individually).
4074 + * GlobalAttribute:
4075 + * c : the content between start and end pattern is skipped
4076 + * during parsing (e.g. pattern encloses a comment).
4077 + * f : flash matching pattern (if not set, then only jump
4078 + * to matching pattern is supported).
4079 + * m : mono pattern - set exist out of only one single pattern
4080 + * (start pattern = end pattern; e.g. quotes like ")
4081 + * p : ignore highlight info code of single patterns of this set
4082 + * ("plain").
4083 + * StringPatternKind:
4084 + * s : start string pattern.
4085 + * m : middle string pattern.
4086 + * e : end string pattern.
4087 + * WordBoundaryAttribute:
4088 + * w : pattern is word (i.e. before and after pattern
4089 + * there must be a delimiter).
4090 + * l : before pattern must be a delimiter (left side).
4091 + * r : after pattern must be a delimiter (right side).
4092 + * default: neither before nor after pattern must be a delimiter.
4093 + * StringAttribute:
4094 + * i : pattern is case insensitive (if not set: pattern is
4095 + * case sensitive).
4096 + * x : pattern is regular expression (if not set: pattern is
4097 + * literal string).
4099 + * \n : end of pattern
4100 + */
4102 +static char *DefaultStringMatchTable[] = {
4103 + "PLAIN{"
4104 + "Round braces::fp:s:\"(\":e:\")\":\n"
4105 + "Curly braces::fp:s:\"{\":e:\"}\":\n"
4106 + "Squared braces::fp:s:\"[\":e:\"]\":\n"
4107 + "Sharp braces::fp:s:\"<\":e:\">\":\n}",
4108 + "C++{"
4109 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4110 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4111 + "Single Quotes:s:cmf:s:\"'\":\n"
4112 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4113 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4114 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4115 + "#ifdef statement:s:f:sx:\"#\\s*ifdef\":sx:\"#\\s*ifndef\":sx:\"#\\s*if\":mx:\"#\\s*elif\":mx:\"#\\s*else\":ex:\"#\\s*endif\":\n"
4116 + "#if group:g:Comment:Double Quotes:Single Quotes:#ifdef statement:\n"
4117 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4118 + "C{"
4119 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4120 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4121 + "Single 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 + "#ifdef statement:s:f:sx:\"#\\s*ifdef\":sx:\"#\\s*ifndef\":sx:\"#\\s*if\":mx:\"#\\s*elif\":mx:\"#\\s*else\":ex:\"#\\s*endif\":\n"
4126 + "#if group:g:Comment:Double Quotes:Single Quotes:#ifdef statement:\n"
4127 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4128 + "CSS{"
4129 + "comment:s:cf:s:\"/*\":e:\"*/\":\n"
4130 + "curly braces:s:f:s:\"{\":e:\"}\":\n"
4131 + "round braces:s:f:s:\"(\":e:\")\":\n"
4132 + "double quotes:s:cfm:s:\"\"\"\":\n"
4133 + "single quotes:s:cfm:s:\"'\":\n"
4134 + "braces:g:comment:single quotes:double quotes:curly braces:round braces:\n}",
4135 + "Csh{"
4136 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4137 + "Single Quotes:s:cmf:s:\"'\":\n"
4138 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4139 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4140 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4141 + "if statement:s:f:sw:\"if\":mw:\"else\":ew:\"endif\":\n"
4142 + "switch statement:s:f:sw:\"switch\":mw:\"case\":mw:\"default\":ew:\"endsw\":\n"
4143 + "foreach statement:s:f:sw:\"for\":ew:\"end\":\n"
4144 + "while statement:s:f:sw:\"while\":ew:\"end\":\n"
4145 + "statement group:g:Double Quotes:Single Quotes:if statement:switch statement:foreach statement:while statement:\n"
4146 + "Braces:g:Double Quotes:Single Quotes:Squared braces:Round braces:Curly braces:\n}",
4147 + "Java{"
4148 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4149 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4150 + "Single Quotes:s:cmf:s:\"'\":\n"
4151 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4152 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4153 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4154 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4155 + "JavaScript{"
4156 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4157 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4158 + "Single Quotes:s:cmf:s:\"'\":\n"
4159 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4160 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4161 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4162 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4163 + "Makefile{"
4164 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4165 + "Single Quotes:s:cmf:s:\"'\":\n"
4166 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4167 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4168 + "Braces:g:Double Quotes:Single Quotes:Curly braces:Round braces:\n}",
4169 + "NEdit Macro{"
4170 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4171 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4172 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4173 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4174 + "Braces:g:Double Quotes:Curly braces:Round braces:Squared braces:\n}",
4175 + "Pascal{"
4176 + "Single Quotes:s:cmf:s:\"'\":\n"
4177 + "Comment1:s:cf:s:\"(*\":e:\"*)\":\n"
4178 + "Comment2:s:cf:s:\"{\":e:\"}\":\n"
4179 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4180 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4181 + "Block:s:f:swi:\"begin\":ewi:\"end\":\n"
4182 + "Case:s:fp:swi:\"case\":ewi:\"end\":\n"
4183 + "Record:s:f:swi:\"record\":ewi:\"end\":\n"
4184 + "Statement:g:Comment1:Comment2:Single Quotes:Block:Case:Record:\n"
4185 + "Braces:g:Comment1:Comment2:Single Quotes:Round braces:Squared braces:\n}",
4186 + "Perl{"
4187 + "Comment:s:cf:s:\"/*\":e:\"*/\":\n"
4188 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4189 + "Single Quotes:s:cmf:s:\"'\":\n"
4190 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4191 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4192 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4193 + "Braces:g:Comment:Double Quotes:Single Quotes:Curly braces:Round braces:Squared braces:\n}",
4194 + "SGML HTML{"
4195 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4196 + "Single Quotes:s:cmf:s:\"'\":\n"
4197 + "Sharp braces:s:f:s:\"<\":e:\">\":\n"
4198 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4199 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4200 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4201 + "Braces:g:Double Quotes:Single Quotes:Sharp braces:Curly braces:Round braces:Squared braces:\n}",
4202 + "Sh Ksh Bash{"
4203 + "Double Quotes:s:cmf:s:\"\"\"\":\n"
4204 + "Single Quotes:s:cmf:s:\"'\":\n"
4205 + "Back Quotes:s:cfm:s:\"`\":\n"
4206 + "Round braces:s:f:s:\"(\":e:\")\":\n"
4207 + "Curly braces:s:f:s:\"{\":e:\"}\":\n"
4208 + "Squared braces:s:f:s:\"[\":e:\"]\":\n"
4209 + "if statement:s:f:sw:\"if\":mw:\"elif\":mw:\"else\":ew:\"fi\":\n"
4210 + "case statement:s:f:sw:\"case\":ew:\"esac\":\n"
4211 + "for statement:s:f:sw:\"for\":mw:\"do\":ew:\"done\":\n"
4212 + "while statement:s:f:sw:\"while\":mw:\"do\":ew:\"done\":\n"
4213 + "statement group:g:Double Quotes:Single Quotes:if statement:case statement:for statement:while statement:\n"
4214 + "Braces:g:Double Quotes:Single Quotes:Back Quotes:Squared braces:Round braces:Curly braces:\n}",
4215 + "XML{"
4216 + "round braces:s:f:s:\"(\":e:\")\":\n"
4217 + "comment:s:cf:s:\"<!--\":e:\"-->\":\n"
4218 + "cdata + ignore:s:cf:sx:\"\\<!\\[((?icdata)|(\\s*IGNORE\\s*))\\[\":ex:\"\\]\\]\\>\":\n"
4219 + "short element:s:cf:sx:\"(?n\\<[\\l_][^@$%/\"\"';!>\\s]*(?=[^>]*/\\>))\":ex:\"/\\>\":\n"
4220 + "element pair:s:f:sx:\"(?n\\<(*1[\\l|_][^@$%/\"\"';!>\\s]*)\\>)\":sx:\"(?n\\<(*1[\\l|_][^@$%/\"\"';!>\\s]*)(?=[^>]*[^/]\\>))\":eix:\"\\</\\1\\>\":\n"
4221 + "processing instruction:s:f:sx:\"\\<\\?\\S+\":ex:\"\\?\\>\":\n"
4222 + "double quotes:s:cmf:s:\"\"\"\":\n"
4223 + "single quotes:s:cmf:s:\"'\":\n"
4224 + "tags:g:comment:double quotes:single quotes:round braces:cdata + ignore:element pair:short element:processing instruction:\n}",
4225 + };
4227 +static char *StandardStringMatchTable =
4228 + "{Round braces::fp:s:\"(\":e:\")\":\n"
4229 + "Curly braces::fp:s:\"{\":e:\"}\":\n"
4230 + "Squared braces::fp:s:\"[\":e:\"]\":\n}";
4233 +** Return string match table related to given language mode name.
4234 +** Return NULL, if no table is found.
4236 +void *FindStringMatchTable(const char *langModeName)
4238 + const char *nameToSearch;
4239 + int i;
4241 + if (langModeName == NULL)
4242 + nameToSearch = PLAIN_LM_STRING;
4243 + else
4244 + nameToSearch = langModeName;
4246 + for (i=0; i<NbrMatchTables; i++)
4247 + if (!strcmp(nameToSearch, MatchTables[i]->smtLanguageMode))
4248 + return (void *)MatchTables[i];
4249 + return NULL;
4253 +** Change the language mode name of string match tables for language
4254 +** "oldName" to "newName" in both the stored tables, and the table
4255 +** currently being edited in the dialog.
4257 +void RenameStringMatchTable(const char *oldName, const char *newName)
4259 + int i;
4261 + for (i=0; i<NbrMatchTables; i++)
4263 + if (!strcmp(oldName, MatchTables[i]->smtLanguageMode))
4265 + XtFree(MatchTables[i]->smtLanguageMode);
4266 + MatchTables[i]->smtLanguageMode = XtNewString(newName);
4269 + if (MatchPatternDialog.mpdShell != NULL)
4271 + if (!strcmp(MatchPatternDialog.mpdLangModeName, oldName))
4273 + XtFree(MatchPatternDialog.mpdLangModeName);
4274 + MatchPatternDialog.mpdLangModeName = XtNewString(newName);
4280 +** Delete string match table related to given language mode name.
4282 +void DeleteStringMatchTable(const char *langModeName)
4284 + int i;
4286 + for (i=0; i<NbrMatchTables; i++)
4288 + if (!strcmp(langModeName, MatchTables[i]->smtLanguageMode))
4290 + /*
4291 + * free (delete) existing matching pattern
4292 + */
4293 + freeStringMatchTable(MatchTables[i]);
4294 + memmove(
4295 + &MatchTables[i],
4296 + &MatchTables[i+1],
4297 + (NbrMatchTables-1 - i) * sizeof(StringMatchTable *));
4298 + NbrMatchTables--;
4299 + break;
4305 +** Assign a standard string match table to a given new language mode.
4307 +void AssignStandardStringMatchTable(const char *langModeName)
4309 + char *list;
4310 + StringMatchTable *newTable;
4312 + /*
4313 + * assign standard table for new language mode
4314 + * add table to end
4315 + */
4316 + list = StandardStringMatchTable;
4317 + newTable =
4318 + readMatchPatternSetContent(&list, list, XtNewString(langModeName));
4320 + /*
4321 + * add table to end
4322 + */
4323 + MatchTables[NbrMatchTables++] = newTable;
4327 +** Returns True if there is a string match table, or potential table
4328 +** not yet committed in the match pattern dialog for a language mode,
4330 +int LMHasStringMatchTable(const char *languageMode)
4332 + StringMatchTable *table = FindStringMatchTable(languageMode);
4334 + if (table != NULL && table->smtNumberOfSeqElements != 0)
4335 + return True;
4336 + return MatchPatternDialog.mpdShell != NULL &&
4337 + !strcmp(MatchPatternDialog.mpdLangModeName, languageMode) &&
4338 + MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements != 0;
4342 +** Read a string representing string matching pattern sets and add them
4343 +** to the StringMatchTable list of loaded string match patterns.
4344 +** Returns true, if read of string was successful.
4346 +int LoadMatchPatternString(char *inString)
4348 + char *inPtr = inString;
4349 + StringMatchTable *table;
4350 + int i;
4352 + for (;;)
4354 + /*
4355 + * read each matching pattern set
4356 + */
4357 + table = readMatchPatternSet(&inPtr);
4359 + if (table != NULL)
4361 + /*
4362 + * add/change the pattern set in the list
4363 + */
4364 + for (i=0; i<NbrMatchTables; i++)
4366 + if (!strcmp(MatchTables[i]->smtLanguageMode, table->smtLanguageMode))
4368 + freeStringMatchTable(MatchTables[i]);
4369 + MatchTables[i] = table;
4370 + break;
4373 + if (i == NbrMatchTables)
4375 + MatchTables[NbrMatchTables++] = table;
4376 + if (NbrMatchTables > MAX_LANGUAGE_MODES)
4378 + return False;
4383 + /*
4384 + * find end of this pattern. if the string ends here, we're done
4385 + */
4386 + inPtr = strstr(inPtr, "\n");
4387 + if (inPtr == NULL)
4389 + return True;
4392 + /*
4393 + * skip newline, tabs & spaces in front of next pattern.
4394 + * if the string ends here, we're done
4395 + */
4396 + inPtr += strspn(inPtr, " \t\n");
4397 + if (*inPtr == '\0')
4399 + return True;
4405 +** Create a string in the correct format for the matchPatterns resource,
4406 +** containing all of the matching pattern information from the stored
4407 +** matching pattern sets for this NEdit session.
4409 +char *WriteMatchPatternString(void)
4411 + char *outStr, *str, *escapedStr;
4412 + textBuffer *outBuf;
4413 + int i, written = False;
4414 + StringMatchTable *table;
4416 + outBuf = BufCreate();
4418 + for (i=0; i<NbrMatchTables; i++)
4420 + table = MatchTables[i];
4422 + written = True;
4424 + BufInsert(outBuf, outBuf->length, table->smtLanguageMode);
4425 + BufInsert(outBuf, outBuf->length, ":");
4427 + if (isDefaultMatchPatternTable(table))
4429 + BufInsert(outBuf, outBuf->length, "Default\n\t");
4431 + else
4433 + BufInsert(outBuf, outBuf->length, "{\n");
4434 + BufInsert(outBuf, outBuf->length,
4435 + str = createMatchPatternsString(table, "\t\t"));
4436 + XtFree(str);
4437 + BufInsert(outBuf, outBuf->length, "\t}\n\t");
4441 + /*
4442 + * Get the output string, and lop off the trailing newline and tab
4443 + */
4444 + outStr = BufGetRange(outBuf, 0, outBuf->length - (written?2:0));
4445 + BufFree(outBuf);
4447 + /*
4448 + * Protect newlines and backslashes from translation by the resource
4449 + * reader
4450 + */
4451 + escapedStr = EscapeSensitiveChars(outStr);
4453 + XtFree(outStr);
4455 + return escapedStr;
4459 +** Check, if last pattern is a duplicate of a previous pattern.
4460 +** Convert last pattern to a reference, if so.
4462 +static void treatDuplicatedPattern(
4463 + MatchPatternTable *table,
4464 + PatternElement *prevPattern,
4465 + PatternReference prevPatRef,
4466 + PatternElement *lastPattern,
4467 + PatternReference lastPatRef)
4469 + StringPattern *prevStringPat;
4470 + StringPattern *lastStringPat;
4471 + StringPattern *stringPat;
4472 + PatternReference *oldList;
4473 + int nbrOfRef;
4475 + /*
4476 + * No duplicate check needed, if previous pattern is a reference,
4477 + * due to the related multi pattern element is checked before.
4478 + */
4479 + if (prevPattern->peType == PET_REFERENCE)
4480 + return;
4482 + prevStringPat = GetStringPattern(table, prevPattern);
4483 + lastStringPat = GetStringPattern(table, lastPattern);
4485 + if (!AllocatedStringsDiffer(prevStringPat->spText, lastStringPat->spText) &&
4486 + !AllocatedStringsDiffer(prevStringPat->spOrigText, lastStringPat->spOrigText) &&
4487 + prevStringPat->spWordBoundary == lastStringPat->spWordBoundary &&
4488 + prevStringPat->spCaseInsensitive == lastStringPat->spCaseInsensitive &&
4489 + prevStringPat->spRegularExpression == lastStringPat->spRegularExpression)
4491 + /*
4492 + * Patterns are identical: Is prevPattern already a multi pattern ?
4493 + */
4494 + if (prevPattern->peType == PET_MULTIPLE)
4496 + /*
4497 + * just add ref. to "lastPattern" to the ref. list
4498 + */
4499 + (prevPattern->peVal.peuMulti.mpNumberOfReferences) ++;
4500 + nbrOfRef = prevPattern->peVal.peuMulti.mpNumberOfReferences;
4501 + oldList = prevPattern->peVal.peuMulti.mpRefList;
4502 + prevPattern->peVal.peuMulti.mpRefList =
4503 + (PatternReference *)XtMalloc( nbrOfRef * sizeof(PatternReference) );
4504 + memcpy(
4505 + prevPattern->peVal.peuMulti.mpRefList,
4506 + oldList,
4507 + (nbrOfRef-1) * sizeof(PatternReference) );
4508 + prevPattern->peVal.peuMulti.mpRefList[nbrOfRef-1] = lastPatRef;
4509 + XtFree( (char *)oldList );
4511 + else
4513 + /*
4514 + * convert prev. single pattern to multi pattern
4515 + */
4516 + stringPat = &prevPattern->peVal.peuSingle;
4517 + prevPattern->peType = PET_MULTIPLE;
4518 + prevPattern->peVal.peuMulti.mpStringPattern = *stringPat;
4519 + prevPattern->peVal.peuMulti.mpNumberOfReferences = 1;
4520 + prevPattern->peVal.peuMulti.mpRefList =
4521 + (PatternReference *)XtMalloc( sizeof(PatternReference) );
4522 + prevPattern->peVal.peuMulti.mpRefList[0] = lastPatRef;
4525 + /*
4526 + * convert last single pattern to reference
4527 + */
4528 + freeStringPattern( &(lastPattern->peVal.peuSingle) );
4529 + lastPattern->peType = PET_REFERENCE;
4530 + lastPattern->peVal.peuRef = prevPatRef;
4535 +** Check, if last pattern is a duplicate of a pattern stored within a
4536 +** previous match pattern table element.
4537 +** Convert last pattern to a reference, if so.
4539 +static void treatDuplicatedPatternElements(
4540 + MatchPatternTable *table,
4541 + MatchPatternTableElement *prevElement,
4542 + int prevElementIdx,
4543 + PatternElement *lastPattern,
4544 + PatternReference lastPatRef)
4546 + int i;
4547 + PatternReference prevPatRef;
4549 + prevPatRef.prElementIdx = prevElementIdx;
4551 + for (i=0; i<prevElement->mpteAll.pesNumberOfPattern; i++)
4553 + prevPatRef.prPatternIdx = i;
4554 + treatDuplicatedPattern(
4555 + table,
4556 + prevElement->mpteAll.pesPattern[i],
4557 + prevPatRef,
4558 + lastPattern,
4559 + lastPatRef);
4564 +** Check, if a pattern of last match pattern table element is a
4565 +** duplicate of a pattern stored within a previous match pattern table
4566 +** element.
4567 +** Convert duplicated last patterns to references, if so.
4569 +static void treatDuplicatedMTElements(
4570 + MatchPatternTable *table,
4571 + MatchPatternTableElement *prevElement,
4572 + int prevElementIdx,
4573 + MatchPatternTableElement *lastElement,
4574 + int lastElementIdx)
4576 + int i;
4577 + PatternReference lastPatRef;
4579 + lastPatRef.prElementIdx = lastElementIdx;
4581 + for (i=0; i<lastElement->mpteAll.pesNumberOfPattern; i++)
4583 + lastPatRef.prPatternIdx = i;
4584 + treatDuplicatedPatternElements(
4585 + table,
4586 + prevElement,
4587 + prevElementIdx,
4588 + lastElement->mpteAll.pesPattern[i],
4589 + lastPatRef);
4594 +** Convert all duplicated patterns of given match pattern table to
4595 +** references.
4597 +static void treatDuplicatedMTEntries(
4598 + MatchPatternTableElement **element,
4599 + int nbrOfElements)
4601 + int i;
4602 + MatchPatternTableElement *lastElement;
4603 + int lastElementIdx;
4604 + MatchPatternTable table;
4606 + if (nbrOfElements < 2)
4607 + return;
4609 + lastElementIdx = nbrOfElements - 1;
4610 + lastElement = element[lastElementIdx];
4612 + table.mptElements = element;
4613 + table.mptNumberOfElements = nbrOfElements;
4615 + for (i=0; i<nbrOfElements-1; i ++)
4617 + treatDuplicatedMTElements( &table, element[i], i, lastElement, lastElementIdx );
4622 +** Compile regular expressions of all string patterns of given
4623 +** match pattern table element.
4624 +** Returns true, if compilation fails.
4626 +static int createStrPatRegExpOfElement(
4627 + ReadMatchPatternInfo *readPatInfo,
4628 + MatchPatternTableElement *element,
4629 + ErrorInfo *errInfo)
4631 + int i;
4632 + StringPattern *strPat;
4634 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
4636 + strPat = getReadStringPattern(readPatInfo, element->mpteAll.pesPattern[i]);
4638 + /*
4639 + * if current string pattern holds a regular expression, then
4640 + * compile it
4641 + */
4642 + if (strPat->spRegularExpression)
4644 + if (createStrPatRegExp(strPat, errInfo))
4646 + /*
4647 + * compilation was not successful
4648 + */
4649 + errInfo->eiMPTabElementName = XtNewString(element->mpteName);
4650 + return True;
4655 + return False;
4659 +** Compile regular expressions of given string pattern.
4660 +** Returns true, if compilation fails.
4662 +static int createStrPatRegExp(
4663 + StringPattern *strPat,
4664 + ErrorInfo *errInfo)
4666 + char *regExpString;
4667 + char *compileMsg;
4669 + /*
4670 + * compose regular expression for start string pattern.
4671 + */
4672 + if( strPat->spCaseInsensitive)
4674 + /*
4675 + * Add '(?i .. )' to given text for case insensitive search.
4676 + * Allocate buffer to hold 5 more char than text length
4677 + * (4 char '(?i)' + \0 char.
4678 + */
4679 + regExpString = XtMalloc(strPat->spLength + 5);
4680 + strcpy(regExpString, "(?i");
4681 + strcat(regExpString, strPat->spText);
4682 + strcat(regExpString, ")");
4684 + else
4686 + regExpString = strPat->spText;
4689 + /*
4690 + * compile regular expression & free allocated string buffer,
4691 + * if applicable.
4692 + */
4693 + strPat->spTextRE =
4694 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
4696 + if (strPat->spTextRE == NULL)
4698 + /*
4699 + * compilation was not successful: adapt error reason by
4700 + * converting local backrefs to global ones.
4701 + */
4702 + adaptCompileMsg(compileMsg, strPat->spGlobalToLocalBackRef);
4704 + errInfo->eiRegExpCompileMsg = compileMsg;
4705 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
4708 + if (strPat->spCaseInsensitive)
4709 + XtFree( regExpString );
4711 + return (strPat->spTextRE == NULL);
4715 +** adapt regular expression compilation message by converting local
4716 +** backrefs to global ones.
4718 +static void adaptCompileMsg(
4719 + char *compileMsg,
4720 + int *globalToLocalBackRef)
4722 + int localId;
4723 + int globalId;
4724 + char *s = compileMsg;
4726 + while (*s != '\0')
4728 + if (*s == '\\')
4730 + if (isdigit((unsigned char)*(s+1)))
4732 + /*
4733 + * \n (n=1..9) found: substitute local by global back ref.
4734 + */
4735 + s ++;
4737 + localId =
4738 + (int)((unsigned char)*s - (unsigned char)'0');
4740 + globalId = localToGlobalBackRef(globalToLocalBackRef, localId);
4742 + *s = (char)((int)('0') + globalId);
4744 + else if (*(s+1) != '\0')
4745 + s ++;
4747 + s ++;
4752 +** translate given local backref to global backref by using
4753 +** given globalToLocalBackRef list.
4755 +static int localToGlobalBackRef(
4756 + int *globalToLocalBackRef,
4757 + int localId)
4759 + int i;
4761 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
4763 + if (globalToLocalBackRef[i] == localId)
4764 + return i+1;
4767 + return 0;
4771 +** Create a regular expression holding keywords of given start & end
4772 +** pattern set.
4773 +** Returns true, if creation of regular expression has failed.
4775 +static int createStartEndRegExp(
4776 + ReadMatchPatternInfo *readMatchPatternInfo,
4777 + MatchPatternTableElement *element,
4778 + ErrorInfo *errInfo)
4780 + char *regExpString;
4781 + char *compileMsg;
4783 + /*
4784 + * compose regular expression for start / end pattern.
4785 + */
4786 + composeStartEndRegExpString(
4787 + readMatchPatternInfo,
4788 + element,
4789 + &regExpString);
4791 + /*
4792 + * compile regular expression & free allocated string buffer.
4793 + */
4794 + element->mpteStartEndRE =
4795 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
4797 + XtFree( regExpString );
4799 + if( element->mpteStartEndRE == NULL)
4801 + errInfo->eiRegExpCompileMsg = compileMsg;
4802 + errInfo->eiDetail = "Error compiling start / end reg. exp.";
4805 + return (element->mpteStartEndRE == NULL);
4809 +** Create a regular expression holding keywords of given group element.
4810 +** Returns true, if creation of regular expression has failed.
4812 +static int createGroupRegExp(
4813 + ReadMatchPatternInfo *readPatInfo,
4814 + MatchPatternGroupElement *group,
4815 + ErrorInfo *errInfo)
4817 + int i;
4818 + MatchPatternTableElement *element;
4819 + RegExpStringInfo regExpStringInfo;
4820 + char *regExpString;
4821 + regexp *keywordRE;
4822 + char *compileMsg;
4824 + /*
4825 + * Allocate buffers for keyword regular expression of this group.
4826 + */
4827 + setupRegExpStringBuffers(
4828 + readPatInfo,
4829 + &regExpStringInfo);
4831 + for (i=0; i<group->mpgeNumberOfSubPatterns; i++)
4833 + element = getPatternOfName(readPatInfo, group->mpgeSubPatternIds[i]);
4834 + /*
4835 + * Add the keywords of the sub pattern to the keyword regular
4836 + * expression string buffer of new group.
4837 + */
4838 + addElementToRegExpString(
4839 + element,
4840 + readPatInfo,
4841 + &regExpStringInfo);
4844 + /*
4845 + * Assemble and compile the resulting keyword regular expression string.
4846 + */
4847 + catSMTRegExpStrings(
4848 + &regExpStringInfo,
4849 + &regExpString);
4851 + keywordRE = CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
4853 + XtFree( regExpString );
4855 + if (keywordRE == NULL)
4857 + errInfo->eiMPTabElementName = XtNewString(group->mpgeName);
4858 + errInfo->eiRegExpCompileMsg = compileMsg;
4859 + errInfo->eiDetail = "Group: Compile reg. exp. error";
4862 + group->mpgeKeywordRE = keywordRE;
4864 + return (keywordRE == NULL);
4868 +** Allocate memory for regular expression strings to be
4869 +** created out of read match pattern info.
4871 +static void setupRegExpStringBuffers(
4872 + ReadMatchPatternInfo *readMatchPatternInfo,
4873 + RegExpStringInfo *regExpStringInfo)
4875 + int totalLen;
4876 + int nbrOfMultiPatterns;
4877 + int sizeOfPatRefs;
4879 + /*
4880 + * determine total length of pattern characters to determine
4881 + * the size of a string buffer for the regular expression to
4882 + * compose. Count number of total multi patterns, too.
4883 + */
4884 + totalLen =
4885 + totalKeywordOfTableLen( readMatchPatternInfo, &nbrOfMultiPatterns );
4887 + /*
4888 + * allocate memory to store added multi pattern references (to avoid
4889 + * duplicated keywords strings later on).
4890 + */
4891 + sizeOfPatRefs = sizeof(PatternReference *) * nbrOfMultiPatterns;
4893 + regExpStringInfo->resiAddedMultiPat =
4894 + (PatternReference **)XtMalloc( sizeOfPatRefs );
4896 + regExpStringInfo->resiNbrOfAddedMultiPat = 0;
4898 + /*
4899 + * init. ID of capturing local backrefs
4900 + */
4901 + regExpStringInfo->resiLocalBackRefID = 1;
4903 + /*
4904 + * allocate & init. string buffers for regular expression:
4905 + * 3 times the size + x of all pattern characters (due to
4906 + * a.) each char may need to be escaped
4907 + * b.) '<(?:', ')>', ')' and '|' need to be added.
4908 + */
4909 + regExpStringInfo->resiNoneWBRegExpString = XtMalloc( 3 * totalLen );
4910 + regExpStringInfo->resiLeftWBRegExpString = XtMalloc( 3 * totalLen + 5 );
4911 + regExpStringInfo->resiRightWBRegExpString = XtMalloc( 3 * totalLen + 5 );
4912 + regExpStringInfo->resiBothWBRegExpString = XtMalloc( 3 * totalLen + 6 );
4914 + strcpy( regExpStringInfo->resiNoneWBRegExpString, "" );
4915 + strcpy( regExpStringInfo->resiLeftWBRegExpString, "" );
4916 + strcpy( regExpStringInfo->resiRightWBRegExpString, "" );
4917 + strcpy( regExpStringInfo->resiBothWBRegExpString, "" );
4921 +** Concatenate given 'partToAdd' string to result string, separated
4922 +** by an OR ('|'). Add 'postfix' at end of result string.
4924 +static void addSMTRegExpString(
4925 + char *result,
4926 + char *partToAdd,
4927 + const char *postfix)
4929 + if (strlen(partToAdd) != 0)
4931 + if (strlen(result) != 0)
4933 + strcat( result, "|" );
4936 + strcat( result, partToAdd );
4938 + strcat( result, postfix );
4944 +** Return a string representing given string match table.
4946 +static char *createMatchPatternsString(
4947 + StringMatchTable *table,
4948 + char *indentStr)
4950 + char *outStr, *str;
4951 + textBuffer *outBuf;
4952 + int i, j;
4953 + MatchPatternSequenceElement *seq;
4954 + MatchPatternTableElement *element;
4955 + MatchPatternGroupElement *group;
4957 + outBuf = BufCreate();
4959 + for (i=0; i<table->smtNumberOfSeqElements; i++)
4961 + seq = table->smtSequence[i];
4963 + BufInsert(outBuf, outBuf->length, indentStr);
4964 + BufInsert(outBuf, outBuf->length, seq->mpseName);
4965 + BufInsert(outBuf, outBuf->length, ":");
4967 + if (seq->mpseType == MPT_GROUP)
4969 + BufInsert(outBuf, outBuf->length, "g:");
4971 + group = table->smtGroups[seq->mpseIndex];
4973 + for (j=0; j < group->mpgeNumberOfSubPatterns; j ++)
4975 + BufInsert(outBuf, outBuf->length, group->mpgeSubPatternIds[j]);
4976 + BufInsert(outBuf, outBuf->length, ":");
4979 + else
4981 + if (seq->mpseType == MPT_SUB)
4983 + BufInsert(outBuf, outBuf->length, "s");
4985 + BufInsert(outBuf, outBuf->length, ":");
4987 + element = table->smtAllPatterns->mptElements[seq->mpseIndex];
4989 + /*
4990 + * write global attributes
4991 + */
4992 + if (element->mpteSkipBtwnStartEnd)
4993 + BufInsert(outBuf, outBuf->length, "c");
4994 + if (element->mpteFlash)
4995 + BufInsert(outBuf, outBuf->length, "f");
4996 + if (element->mpteIsMonoPattern)
4997 + BufInsert(outBuf, outBuf->length, "m");
4998 + if (element->mpteIgnoreHighLightInfo)
4999 + BufInsert(outBuf, outBuf->length, "p");
5000 + BufInsert(outBuf, outBuf->length, ":");
5002 + /*
5003 + * write string patterns
5004 + */
5005 + for (j=0; j < element->mpteAll.pesNumberOfPattern; j ++)
5007 + BufInsert(
5008 + outBuf,
5009 + outBuf->length,
5010 + str =
5011 + createPatternElementString(
5012 + table->smtAllPatterns,
5013 + element->mpteAll.pesPattern[j]));
5014 + XtFree(str);
5018 + BufInsert(outBuf, outBuf->length, "\n");
5021 + outStr = BufGetAll(outBuf);
5022 + BufFree(outBuf);
5024 + return outStr;
5028 +** Return a string representing given pattern element.
5030 +static char *createPatternElementString(
5031 + MatchPatternTable *table,
5032 + PatternElement *pat)
5034 + char *outStr, *str;
5035 + textBuffer *outBuf;
5036 + StringPattern *strPat;
5038 + outBuf = BufCreate();
5040 + strPat = GetStringPattern(table, pat);
5042 + /*
5043 + * write string pattern kind
5044 + */
5045 + if (pat->peKind == PEK_START)
5046 + BufInsert(outBuf, outBuf->length, "s");
5047 + else if (pat->peKind == PEK_MIDDLE)
5048 + BufInsert(outBuf, outBuf->length, "m");
5049 + else if (pat->peKind == PEK_END)
5050 + BufInsert(outBuf, outBuf->length, "e");
5052 + /*
5053 + * write word boundary
5054 + */
5055 + if (strPat->spWordBoundary == PWB_BOTH)
5056 + BufInsert(outBuf, outBuf->length, "w");
5057 + else if (strPat->spWordBoundary == PWB_LEFT)
5058 + BufInsert(outBuf, outBuf->length, "l");
5059 + else if (strPat->spWordBoundary == PWB_RIGHT)
5060 + BufInsert(outBuf, outBuf->length, "r");
5062 + /*
5063 + * write case insensitive flag
5064 + */
5065 + if (strPat->spCaseInsensitive)
5066 + BufInsert(outBuf, outBuf->length, "i");
5068 + /*
5069 + * write regular expression flag
5070 + */
5071 + if (strPat->spRegularExpression)
5072 + BufInsert(outBuf, outBuf->length, "x");
5074 + BufInsert(outBuf, outBuf->length, ":");
5076 + /*
5077 + * write pattern string
5078 + */
5079 + if( strPat->spOrigText != NULL)
5080 + BufInsert(
5081 + outBuf,
5082 + outBuf->length,
5083 + str = MakeQuotedString(strPat->spOrigText));
5084 + else
5085 + BufInsert(
5086 + outBuf,
5087 + outBuf->length,
5088 + str = MakeQuotedString(strPat->spText));
5089 + XtFree(str);
5091 + BufInsert(outBuf, outBuf->length, ":");
5093 + outStr = BufGetAll(outBuf);
5094 + BufFree(outBuf);
5096 + return outStr;
5100 +** Given a language mode name, determine if there is a default (built-in)
5101 +** string match table available for that language mode, and if so, read it and
5102 +** return a new allocated copy of it. The returned pattern set should be
5103 +** freed by the caller with freeStringMatchTable().
5105 +static StringMatchTable *readDefaultStringMatchTable(const char *langModeName)
5107 + int i, modeNameLen;
5108 + char *list;
5110 + modeNameLen = strlen(langModeName);
5112 + for (i=0; i<(int)XtNumber(DefaultStringMatchTable); i++)
5114 + if (!strncmp(langModeName, DefaultStringMatchTable[i], modeNameLen) &&
5115 + DefaultStringMatchTable[i][modeNameLen] == '{')
5117 + list = DefaultStringMatchTable[i];
5118 + return readMatchPatternSet(&list);
5122 + list = StandardStringMatchTable;
5123 + return readMatchPatternSetContent(&list, list, XtNewString(langModeName));
5127 +** Return true, if table exactly matches one of the default matching
5128 +** pattern tables.
5130 +static int isDefaultMatchPatternTable(StringMatchTable *table)
5132 + StringMatchTable *defaultTable;
5133 + int retVal;
5135 + defaultTable = readDefaultStringMatchTable(table->smtLanguageMode);
5137 + if (defaultTable == NULL)
5138 + return False;
5140 + retVal = !stringMatchTableDiffer(table, defaultTable);
5142 + freeStringMatchTable(defaultTable);
5144 + return retVal;
5148 +** Read in a string match pattern table character string,
5149 +** and advance *inPtr beyond it.
5150 +** Returns NULL and outputs an error to stderr on failure.
5152 +static StringMatchTable *readMatchPatternSet(char **inPtr)
5154 + char *languageMode;
5155 + StringMatchTable *table = NULL;
5156 + char *stringStart = *inPtr;
5157 + ErrorInfo errInfo;
5159 + initErrorInfo(&errInfo);
5161 + /*
5162 + * remove leading whitespace
5163 + */
5164 + *inPtr += strspn(*inPtr, " \t\n");
5166 + /*
5167 + * read language mode field
5168 + */
5169 + languageMode = ReadSymbolicField(inPtr);
5171 + /*
5172 + * look for initial brace
5173 + */
5174 + if (**inPtr == ':')
5176 + (*inPtr) ++;
5177 + /*
5178 + * look for "Default" keyword, and if it's there, return the default
5179 + * pattern set
5180 + */
5181 + if (!strncmp(*inPtr, "Default", 7))
5183 + *inPtr += 7;
5184 + table = readDefaultStringMatchTable(languageMode);
5185 + XtFree(languageMode);
5187 + return table;
5191 + table = readMatchPatternSetContent(inPtr, stringStart, languageMode);
5193 + if (table == NULL)
5194 + XtFree(languageMode);
5196 + return table;
5200 +** Read in a content string ("{..}") of match pattern table,
5201 +** and advance *inPtr beyond it.
5202 +** Returns NULL and outputs an error to stderr on failure.
5204 +static StringMatchTable *readMatchPatternSetContent(
5205 + char **inPtr,
5206 + char *stringStart,
5207 + char *languageMode)
5209 + ReadMatchPatternInfo readPatInfo;
5210 + StringMatchTable *table = NULL;
5211 + ErrorInfo errInfo;
5212 + int successful = True;
5213 + int endOfPatternSet = False;
5215 + initErrorInfo(&errInfo);
5217 + /*
5218 + * look for initial brace
5219 + */
5220 + if (**inPtr != '{')
5222 + errInfo.eiLanguageMode = XtNewString(languageMode);
5223 + errInfo.eiDetail = "pattern list must begin with \"{\"";
5224 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo );
5226 + return NULL;
5229 + (*inPtr)++;
5231 + readPatInfo.rmpiNbrOfElements = 0;
5232 + readPatInfo.rmpiNbrOfGroups = 0;
5233 + readPatInfo.rmpiNbrOfSeqElements = 0;
5234 + readPatInfo.rmpiAllPatRE = NULL;
5235 + readPatInfo.rmpiFlashPatRE = NULL;
5237 + /*
5238 + * parse each pattern in the list
5239 + */
5240 + while (successful && !endOfPatternSet)
5242 + *inPtr += strspn(*inPtr, " \t\n");
5243 + if (**inPtr == '\0')
5245 + errInfo.eiLanguageMode = XtNewString(languageMode);
5246 + errInfo.eiDetail = "end of pattern list not found";
5247 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5248 + successful = False;
5250 + else if (**inPtr == '}')
5252 + (*inPtr)++;
5253 + endOfPatternSet = True;
5255 + else
5257 + if (!readMatchPatternEntry(inPtr, &errInfo, &readPatInfo))
5259 + errInfo.eiLanguageMode = XtNewString(languageMode);
5260 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5261 + successful = False;
5266 + if (successful)
5268 + /*
5269 + * compile regular expressions of read patterns
5270 + */
5271 + if (createRegExpOfPatterns(&readPatInfo, &errInfo))
5273 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5274 + successful = False;
5278 + if (successful)
5280 + return createStringMatchTable(&readPatInfo, languageMode);
5282 + else
5284 + /*
5285 + * free memory of already read patterns
5286 + */
5287 + freeReadMatchPatternInfo(&readPatInfo);
5289 + return NULL;
5292 + return table;
5296 +** Create a reg. exp. of all patterns contained
5297 +** in given read match pattern info.
5299 +static int createRegExpOfPatterns(
5300 + ReadMatchPatternInfo *readPatInfo,
5301 + ErrorInfo *errInfo)
5303 + if (createRegExpOfStrPatterns(readPatInfo, errInfo))
5304 + return True;
5306 + if (createRegExpOfAllPatterns(readPatInfo, errInfo))
5307 + return True;
5309 + return False;
5313 +** Create a "total pattern reg. exp." of all patterns / flash patterns
5314 +** contained in given read match pattern info.
5315 +** Returns true, if create of reg. exp. has failed.
5317 +static int createRegExpOfAllPatterns(
5318 + ReadMatchPatternInfo *readPatInfo,
5319 + ErrorInfo *errInfo)
5321 + int i;
5322 + RegExpStringInfo allPatRegExpSI;
5323 + RegExpStringInfo flashPatRegExpSI;
5324 + MatchPatternTableElement *element;
5325 + char *regExpString;
5326 + char *compileMsg;
5328 + /*
5329 + * Allocate buffers for keyword regular expressions.
5330 + */
5331 + setupRegExpStringBuffers(readPatInfo, &allPatRegExpSI);
5332 + setupRegExpStringBuffers(readPatInfo, &flashPatRegExpSI);
5334 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5336 + element = readPatInfo->rmpiElement[i];
5338 + /*
5339 + * Add the keywords of the matching pattern to the keyword
5340 + * regular expression string buffer of all patterns.
5341 + */
5342 + addElementToRegExpString(
5343 + element,
5344 + readPatInfo,
5345 + &allPatRegExpSI);
5347 + /*
5348 + * If flash attribute is set, then add the keywords of the
5349 + * matching pattern also to the keyword regular expression
5350 + * string buffer of flash patterns.
5351 + */
5352 + if (element->mpteFlash)
5354 + addElementToRegExpString(
5355 + element,
5356 + readPatInfo,
5357 + &flashPatRegExpSI);
5361 + /*
5362 + * Assemble and compile the resulting all keywords reg. exp. string.
5363 + */
5364 + catSMTRegExpStrings(
5365 + &allPatRegExpSI,
5366 + &regExpString);
5368 + readPatInfo->rmpiAllPatRE =
5369 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
5371 + XtFree( regExpString );
5373 + if (readPatInfo->rmpiAllPatRE == NULL)
5375 + errInfo->eiRegExpCompileMsg = compileMsg;
5376 + errInfo->eiDetail = "All patterns: compile reg. exp. error";
5377 + return True;
5380 + /*
5381 + * Assemble and compile the resulting flash keywords reg. exp. string.
5382 + */
5383 + catSMTRegExpStrings(
5384 + &flashPatRegExpSI,
5385 + &regExpString);
5387 + readPatInfo->rmpiFlashPatRE =
5388 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
5390 + XtFree( regExpString );
5392 + if (readPatInfo->rmpiFlashPatRE == NULL)
5394 + errInfo->eiRegExpCompileMsg = compileMsg;
5395 + errInfo->eiDetail = "Flash patterns: compile reg. exp. error";
5396 + return True;
5399 + /*
5400 + * Pattern reg. exp. successful created:
5401 + */
5402 + return False;
5406 +** Create reg. exp. of single patterns contained in given
5407 +** read match pattern info.
5408 +** Returns true, if create of reg. exp. has failed.
5410 +static int createRegExpOfStrPatterns(
5411 + ReadMatchPatternInfo *readPatInfo,
5412 + ErrorInfo *errInfo)
5414 + int i;
5415 + MatchPatternTableElement *element;
5416 + MatchPatternGroupElement *group;
5418 + /*
5419 + * create global backref list of all elements of read info
5420 + */
5421 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5423 + element = readPatInfo->rmpiElement[i];
5425 + if (!createGlobalBackRefList(readPatInfo, element, errInfo))
5426 + return True;
5429 + /*
5430 + * resolve global backrefs of all elements of read info
5431 + */
5432 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5434 + element = readPatInfo->rmpiElement[i];
5436 + if (!resolveGlobalBackRefs(readPatInfo, element, errInfo))
5437 + return True;
5440 + /*
5441 + * compile reg. exp. of all elements of read info
5442 + */
5443 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5445 + element = readPatInfo->rmpiElement[i];
5447 + if (createStrPatRegExpOfElement(readPatInfo, element, errInfo))
5448 + return True;
5450 + /*
5451 + * create start / end reg. exp. if applicable.
5452 + */
5453 + if (element->mpteSkipBtwnStartEnd)
5455 + if (createStartEndRegExp(readPatInfo, element, errInfo))
5456 + return True;
5460 + /*
5461 + * compile reg. exp. of all groups of read info
5462 + */
5463 + for (i=0; i < readPatInfo->rmpiNbrOfGroups; i ++)
5465 + group = readPatInfo->rmpiGroup[i];
5467 + if (createGroupRegExp(readPatInfo, group, errInfo))
5469 + return True;
5473 + return False;
5477 +** Create a string match table out of read match pattern info.
5479 +static StringMatchTable *createStringMatchTable(
5480 + ReadMatchPatternInfo *readPatInfo,
5481 + char *languageMode)
5483 + StringMatchTable *table;
5484 + MatchPatternTable *patTable;
5485 + int sizeOfElements;
5487 + table = (StringMatchTable *)XtMalloc(sizeof(StringMatchTable));
5488 + table->smtLanguageMode = languageMode;
5490 + /*
5491 + * allocate a more appropriately sized list to return matching patterns
5492 + */
5493 + patTable = (MatchPatternTable *)XtMalloc(sizeof(MatchPatternTable));
5494 + patTable->mptNumberOfElements = readPatInfo->rmpiNbrOfElements;
5496 + if (readPatInfo->rmpiNbrOfElements > 0)
5498 + sizeOfElements =
5499 + sizeof(MatchPatternTableElement *) * readPatInfo->rmpiNbrOfElements;
5500 + patTable->mptElements =
5501 + (MatchPatternTableElement **)XtMalloc(sizeOfElements);
5502 + memcpy(patTable->mptElements, readPatInfo->rmpiElement, sizeOfElements);
5504 + else
5506 + patTable->mptElements = NULL;
5509 + table->smtAllPatterns = patTable;
5511 + table->smtAllPatRE = readPatInfo->rmpiAllPatRE;
5512 + table->smtFlashPatRE = readPatInfo->rmpiFlashPatRE;
5513 + table->smtUsedPatRE = NULL;
5515 + /*
5516 + * allocate a more appropriately sized list to return matching pattern groups
5517 + */
5518 + table->smtNumberOfGroups = readPatInfo->rmpiNbrOfGroups;
5519 + if (readPatInfo->rmpiNbrOfGroups > 0)
5521 + sizeOfElements =
5522 + sizeof(MatchPatternGroupElement *) * readPatInfo->rmpiNbrOfGroups;
5523 + table->smtGroups =
5524 + (MatchPatternGroupElement **)XtMalloc(sizeOfElements);
5525 + memcpy(table->smtGroups, readPatInfo->rmpiGroup, sizeOfElements);
5527 + else
5529 + table->smtGroups = NULL;
5531 + /*
5532 + * allocate a more appropriately sized list to return matching pattern sequence
5533 + */
5534 + table->smtNumberOfSeqElements = readPatInfo->rmpiNbrOfSeqElements;
5535 + if (readPatInfo->rmpiNbrOfSeqElements > 0)
5537 + sizeOfElements =
5538 + sizeof(MatchPatternSequenceElement *) * readPatInfo->rmpiNbrOfSeqElements;
5539 + table->smtSequence =
5540 + (MatchPatternSequenceElement **)XtMalloc(sizeOfElements);
5541 + memcpy(table->smtSequence, readPatInfo->rmpiSequence, sizeOfElements);
5543 + else
5545 + table->smtSequence = NULL;
5548 + return table;
5552 +** Read one match pattern entry of a match pattern string.
5553 +** Returns true, if read was successful.
5555 +static int readMatchPatternEntry(
5556 + char **inPtr,
5557 + ErrorInfo *errInfo,
5558 + ReadMatchPatternInfo *info)
5560 + char *name;
5561 + MatchPatternType type;
5562 + MatchPatternGroupElement *readGroup;
5563 + MatchPatternTableElement *readElement;
5565 + if (!getMPSName( inPtr, errInfo, &name ))
5567 + return False;
5570 + if (!getMPSTypeAttribute( inPtr, errInfo, &type ))
5572 + errInfo->eiMPTabElementName = XtNewString(name);
5573 + return False;
5576 + if (type == MPT_GROUP)
5578 + if (info->rmpiNbrOfGroups >= MAX_NBR_MATCH_PATTERN_GROUPS)
5580 + errInfo->eiMPTabElementName = XtNewString(name);
5581 + errInfo->eiDetail = "max number of match pattern groups exceeded";
5582 + return False;
5585 + readGroup = readMatchPatternGroup( inPtr, errInfo, name, info );
5587 + if (readGroup == NULL)
5589 + errInfo->eiMPTabElementName = XtNewString(name);
5590 + XtFree( name );
5592 + else
5594 + info->rmpiGroup[info->rmpiNbrOfGroups ++] = readGroup;
5596 + recordPatternSequence( info, name, type, info->rmpiNbrOfGroups-1 );
5599 + return (readGroup != NULL);
5601 + else
5603 + if (info->rmpiNbrOfElements >= MAX_NBR_MATCH_PATTERNS)
5605 + errInfo->eiMPTabElementName = XtNewString(name);
5606 + errInfo->eiDetail = "max number of match patterns exceeded";
5607 + XtFree( name );
5608 + return False;
5611 + readElement =
5612 + readMatchPatternTableElement( inPtr, &errInfo->eiDetail, name, type );
5614 + if (readElement == NULL)
5616 + errInfo->eiMPTabElementName = XtNewString(name);
5617 + XtFree( name );
5619 + else
5621 + readElement->mpteIndex = info->rmpiNbrOfElements;
5623 + info->rmpiElement[info->rmpiNbrOfElements ++] = readElement;
5625 + if (type == MPT_INDIVIDUAL)
5627 + if (!assignIndividualGroup( info, &errInfo->eiDetail, readElement ))
5629 + errInfo->eiMPTabElementName = XtNewString(name);
5630 + return False;
5634 + treatDuplicatedMTEntries(
5635 + info->rmpiElement, info->rmpiNbrOfElements );
5637 + recordPatternSequence( info, name, type, info->rmpiNbrOfElements-1 );
5640 + return (readElement != NULL);
5645 +** Record match pattern sequence for display of match pattern dialog.
5647 +static void recordPatternSequence(
5648 + ReadMatchPatternInfo *info,
5649 + char *name,
5650 + MatchPatternType type,
5651 + int index)
5653 + MatchPatternSequenceElement *sequence;
5655 + sequence =
5656 + (MatchPatternSequenceElement *)XtMalloc( sizeof(MatchPatternSequenceElement) );
5658 + sequence->mpseName = XtNewString(name);
5659 + sequence->mpseType = type;
5660 + sequence->mpseIndex = index;
5662 + info->rmpiSequence[info->rmpiNbrOfSeqElements ++] = sequence;
5666 +** Assign a new group to an individual match pattern.
5667 +** Returns true, if assignment was successful.
5669 +static int assignIndividualGroup(
5670 + ReadMatchPatternInfo *info,
5671 + char **errMsg,
5672 + MatchPatternTableElement *element)
5674 + MatchPatternGroupElement *group = NULL;
5676 + if (info->rmpiNbrOfGroups >= MAX_NBR_MATCH_PATTERN_GROUPS)
5678 + *errMsg = "max. number of matching pattern groups exceeded\n";
5679 + return False;
5682 + /*
5683 + * Assign the index of new group to the individual matching pattern
5684 + */
5685 + element->mpteGroup = info->rmpiNbrOfGroups;
5687 + /*
5688 + * Allocate memory for the matching pattern group and copy the
5689 + * info into this group element.
5690 + */
5691 + group =
5692 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
5694 + group->mpgeName = NULL;
5695 + group->mpgeKeywordRE = NULL;
5697 + /*
5698 + * remember name of match pattern table element, which is
5699 + * represented by this group.
5700 + */
5701 + group->mpgeNumberOfSubPatterns = 1;
5702 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeof(char *) );
5703 + group->mpgeSubPatternIds[0] = XtNewString(element->mpteName);
5705 + info->rmpiGroup[info->rmpiNbrOfGroups ++] = group;
5707 + return True;
5711 +** Get the match pattern table element of given 'patToSearch'
5712 +** name.
5713 +** Returns NULL, if no element was found.
5715 +static MatchPatternTableElement *getPatternOfName(
5716 + ReadMatchPatternInfo *info,
5717 + char *patToSearch)
5719 + int i;
5720 + MatchPatternTableElement *element;
5722 + for (i=0; i<info->rmpiNbrOfElements; i ++)
5724 + element = info->rmpiElement[i];
5726 + if (strcmp( element->mpteName, patToSearch ) == 0)
5728 + /*
5729 + * Related sub-pattern found:
5730 + */
5731 + return element;
5735 + /*
5736 + * No sub-pattern found:
5737 + */
5738 + return NULL;
5742 +** Read match pattern group of given match pattern string.
5743 +** Returns NULL, if read fails.
5745 +static MatchPatternGroupElement *readMatchPatternGroup(
5746 + char **inPtr,
5747 + ErrorInfo *errInfo,
5748 + char *name,
5749 + ReadMatchPatternInfo *info)
5751 + int i;
5752 + int error = False;
5753 + char *patNameInPtr;
5754 + char *subPatName;
5755 + MatchPatternTableElement *subPatElement;
5756 + int numberOfRelatedSubPattern = 0;
5757 + char *relatedSubPatternId[MAX_NBR_MATCH_PATTERNS];
5758 + int sizeOfIds;
5759 + MatchPatternGroupElement *group = NULL;
5761 + /*
5762 + * Read sub-matching patterns of this group.
5763 + */
5764 + while (**inPtr != '\n' && !error)
5766 + /*
5767 + * Read next pattern name from inPtr.
5768 + */
5769 + patNameInPtr = *inPtr;
5770 + subPatName = ReadSymbolicField(inPtr);
5772 + if (subPatName == NULL)
5774 + errInfo->eiDetail = "Sub-Matching Pattern Name expected";
5775 + error = True;
5777 + else
5779 + /*
5780 + * Get matching pattern related to sub-matching pattern name.
5781 + */
5782 + subPatElement =
5783 + getPatternOfName( info, subPatName );
5785 + if (subPatElement == NULL)
5787 + errInfo->eiStringPatText = XtNewString(subPatName);
5788 + errInfo->eiDetail = "Sub-Matching Pattern not defined before";
5789 + error = True;
5791 + else if (numberOfRelatedSubPattern >= MAX_NBR_MATCH_PATTERNS)
5793 + errInfo->eiDetail = "Group holds too many Sub-Matching Patterns";
5794 + error = True;
5796 + else if (subPatElement->mpteType != MPT_SUB)
5798 + errInfo->eiStringPatText = XtNewString(subPatName);
5799 + errInfo->eiDetail = "Not a Sub-Matching Pattern";
5800 + error = True;
5802 + else
5804 + /*
5805 + * Remember sub-matching pattern ID
5806 + */
5807 + relatedSubPatternId[numberOfRelatedSubPattern ++] = subPatName;
5809 + /*
5810 + * Assign the index of this group to the sub-matching pattern
5811 + * if no group index was assigned before.
5812 + */
5813 + if (subPatElement->mpteGroup == NO_GROUP_IDX)
5815 + subPatElement->mpteGroup = info->rmpiNbrOfGroups;
5819 + /*
5820 + * Skip to the start of the next matching pattern name.
5821 + */
5822 + if (!error && !SkipDelimiter(inPtr, &errInfo->eiDetail))
5824 + error = True;
5829 + if (error)
5831 + for (i=0; i < numberOfRelatedSubPattern; i++)
5833 + XtFree( relatedSubPatternId[i] );
5836 + return NULL;
5838 + else
5840 + /*
5841 + * Allocate memory for the matching pattern group and copy the
5842 + * info into this group element.
5843 + */
5844 + group =
5845 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
5847 + group->mpgeName = name;
5848 + group->mpgeKeywordRE = NULL;
5850 + /*
5851 + * Allocate memory for the sub-matching pattern IDs & copy
5852 + * related sub-matching pattern into the group element.
5853 + */
5854 + sizeOfIds = sizeof(char *) * numberOfRelatedSubPattern;
5855 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeOfIds );
5857 + memcpy(group->mpgeSubPatternIds, relatedSubPatternId, sizeOfIds);
5859 + group->mpgeNumberOfSubPatterns = numberOfRelatedSubPattern;
5861 + return group;
5866 +** Read one match pattern element from given match pattern string.
5867 +** Returns true, if read was successful.
5869 +static int readPatternElement(
5870 + char **inPtr,
5871 + char **errMsg,
5872 + PatternElement **pattern)
5874 + PatternElementKind patternKind;
5875 + PatternWordBoundary wordBoundary;
5876 + int caseInsensitive;
5877 + int regularExpression;
5878 + char *string;
5880 + if (!getMPSPatternAttribute(
5881 + inPtr,
5882 + errMsg,
5883 + &patternKind,
5884 + &wordBoundary,
5885 + &caseInsensitive,
5886 + &regularExpression ))
5888 + return False;
5891 + if (!ReadQuotedString(inPtr, errMsg, &string))
5893 + return False;
5896 + if (!SkipDelimiter(inPtr, errMsg))
5898 + XtFree( string );
5899 + return False;
5902 + *pattern =
5903 + createPatternElement(
5904 + string,
5905 + patternKind,
5906 + wordBoundary,
5907 + caseInsensitive,
5908 + regularExpression);
5910 + return True;
5914 +** Create a pattern element.
5916 +static PatternElement *createPatternElement(
5917 + char *patternText,
5918 + PatternElementKind patternKind,
5919 + PatternWordBoundary wordBoundary,
5920 + int caseInsensitive,
5921 + int regularExpression)
5923 + PatternElement *pattern;
5924 + char *s;
5926 + /*
5927 + * Convert pattern text to lower case, if case insensitive
5928 + * attribute is set.
5929 + */
5930 + if (caseInsensitive)
5932 + for (s = patternText; *s != '\0'; s ++)
5934 + *s = tolower(*s);
5938 + /*
5939 + * Allocate memory for the new pattern element and init. / copy
5940 + * related info into this pattern element.
5941 + */
5942 + pattern = (PatternElement *)XtMalloc( sizeof(PatternElement) );
5944 + initStrPatBackRefList(&pattern->peVal.peuSingle);
5946 + pattern->peKind = patternKind;
5947 + pattern->peIndex = NO_PATTERN_IDX;
5948 + pattern->peType = PET_SINGLE;
5950 + pattern->peVal.peuSingle.spLength = strlen(patternText);
5951 + pattern->peVal.peuSingle.spBackRefParsed = False;
5952 + pattern->peVal.peuSingle.spBackRefResolved = False;
5954 + pattern->peVal.peuSingle.spCaseInsensitive = caseInsensitive;
5955 + pattern->peVal.peuSingle.spRegularExpression = regularExpression;
5956 + pattern->peVal.peuSingle.spTextRE = NULL;
5958 + /*
5959 + * Store original string of regular expression patterns due to
5960 + * it may be later adapted (e.g. due to global backrefs etc.).
5961 + */
5962 + if (regularExpression)
5964 + pattern->peVal.peuSingle.spOrigText = patternText;
5965 + pattern->peVal.peuSingle.spText = NULL;
5966 + pattern->peVal.peuSingle.spWordBoundary = PWB_NONE;
5968 + else
5970 + pattern->peVal.peuSingle.spOrigText = NULL;
5971 + pattern->peVal.peuSingle.spText = patternText;
5972 + pattern->peVal.peuSingle.spWordBoundary = wordBoundary;
5975 + return pattern;
5979 +** Create a list holding all global backref definitions of given
5980 +** match pattern table element. The list is stored in this given
5981 +** element.
5982 +** Returns true, if list was successfully created.
5984 +static int createGlobalBackRefList(
5985 + ReadMatchPatternInfo *readPatInfo,
5986 + MatchPatternTableElement *element,
5987 + ErrorInfo *errInfo)
5989 + int i;
5990 + StringPattern *strPat;
5992 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
5994 + strPat = getReadStringPattern(readPatInfo, element->mpteAll.pesPattern[i]);
5996 + if (strPat->spRegularExpression)
5998 + if (strPat->spBackRefParsed)
6000 + /*
6001 + * Global backrefs or this string pattern already parsed:
6002 + * just merge string pattern list with elements one.
6003 + */
6004 + if (!updateGlobalBackRefs(
6005 + strPat,
6006 + element->mpteGlobalBackRef,
6007 + errInfo))
6009 + return False;
6012 + else
6014 + /*
6015 + * parse string pattern for global backrefs and
6016 + * merge string pattern list with elements one.
6017 + */
6018 + if (!parseGlobalBackRefs(
6019 + strPat,
6020 + element->mpteGlobalBackRef,
6021 + errInfo))
6023 + return False;
6029 + return True;
6033 +** Returns read string pattern of given pattern element.
6035 +StringPattern *getReadStringPattern(
6036 + ReadMatchPatternInfo *readPatInfo,
6037 + PatternElement *pattern )
6039 + switch (pattern->peType)
6041 + case PET_SINGLE:
6042 + return &pattern->peVal.peuSingle;
6043 + break;
6045 + case PET_MULTIPLE:
6046 + return &pattern->peVal.peuMulti.mpStringPattern;
6047 + break;
6049 + case PET_REFERENCE:
6050 + return getReadStringPattern(
6051 + readPatInfo,
6052 + getReadPatternOfReference(readPatInfo, &pattern->peVal.peuRef));
6053 + break;
6056 + /*
6057 + * never reached; just to make compiler happy
6058 + */
6059 + return NULL;
6063 +** Returns read pattern element of given pattern reference.
6065 +static PatternElement *getReadPatternOfReference(
6066 + ReadMatchPatternInfo *readPatInfo,
6067 + PatternReference *patRef)
6069 + MatchPatternTableElement **element = readPatInfo->rmpiElement;
6071 + return element[ patRef->prElementIdx ]->mpteAll.pesPattern[patRef->prPatternIdx];
6075 +** Allocate a new copy of given string and substitute each capturing
6076 +** parentheses inside given string by a non-capturing one.
6077 +** Returns resulting string.
6079 +static char *replaceCapturingParentheses(
6080 + const char *source)
6082 + char *destination;
6083 + const char *s;
6084 + char *d;
6085 + int nbrOfOpenBraces = 0;
6087 + s = source;
6089 + /*
6090 + * count number of open braces
6091 + */
6092 + while (*s != '\0')
6094 + if (*s++ == '(')
6095 + nbrOfOpenBraces ++;
6098 + /*
6099 + * allocate memory for substitued reg. exp. text
6100 + */
6101 + destination = XtMalloc(strlen(source) + 2*nbrOfOpenBraces);
6103 + /*
6104 + * substitute each capturing open brace by a non-capturing one
6105 + */
6106 + s = source;
6107 + d = destination;
6109 + while (*s != '\0')
6111 + if (*s == '\\')
6113 + *d++ = *s++;
6115 + if (*s != '\0')
6116 + *d++ = *s++;
6118 + else if (*s == '(')
6120 + *d++ = *s++;
6122 + if (*s != '?' && *s != '*')
6124 + *d++ = '?';
6125 + *d++ = ':';
6128 + else
6130 + *d++ = *s++;
6134 + *d = '\0';
6136 + return destination;
6140 +** Parse given string pattern for global backrefs definitions
6141 +** (syntax: "(*n", where n=1..9). Add found global backrefs to
6142 +** given backRefList.
6143 +** Returns false, if parse fails.
6145 +static int parseGlobalBackRefs(
6146 + StringPattern *strPat,
6147 + GlobalBackRefElement *backRefList,
6148 + ErrorInfo *errInfo)
6150 + char *s;
6151 + char *backRefContent;
6152 + int nestingLevel = 0;
6153 + int stackIdx = -1;
6154 + BackRefBracketInfo backRefInfo[MAX_GLOBAL_BACK_REF_ID+1];
6155 + StrPatBackRefElement *curStrPatBRE;
6157 + strPat->spText = replaceCapturingParentheses(strPat->spOrigText);
6158 + strPat->spLength = strlen(strPat->spText);
6159 + strPat->spBackRefParsed = True;
6161 + s = strPat->spText;
6163 + while (*s != '\0')
6165 + if (*s == '\\')
6167 + /*
6168 + * Ignore escaped characters
6169 + */
6170 + if (*(s+1) != '\0')
6171 + s ++;
6173 + else if (*s == '(')
6175 + if (*(s+1) == '*')
6177 + if (isdigit((unsigned char)*(s+2)))
6179 + /*
6180 + * Global backref. definition start found:
6181 + */
6182 + stackIdx ++;
6184 + backRefInfo[stackIdx].brbiGlobalId =
6185 + (int)((unsigned char)*(s+2) - (unsigned char)'0') - 1;
6187 + if(backRefInfo[stackIdx].brbiGlobalId < 0)
6189 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6190 + errInfo->eiDetail = "Backref '0' not allowed";
6191 + return False;
6194 + backRefInfo[stackIdx].brbiContentStart = s+3;
6195 + backRefInfo[stackIdx].brbiNestingLevel = nestingLevel;
6196 + s ++;
6198 + s ++;
6200 + nestingLevel ++;
6202 + else if (*s == ')')
6204 + nestingLevel --;
6205 + if (stackIdx != -1 &&
6206 + backRefInfo[stackIdx].brbiNestingLevel == nestingLevel)
6208 + /*
6209 + * Global backref. definition end found: add it to
6210 + * backref. list of string pattern.
6211 + */
6212 + curStrPatBRE =
6213 + &strPat->spOwnGlobalBackRef[backRefInfo[stackIdx].brbiGlobalId];
6215 + backRefContent =
6216 + createBackRefRegExpText(
6217 + backRefInfo[stackIdx].brbiContentStart,
6218 + s);
6220 + if (curStrPatBRE->spbreRegExpText != NULL)
6222 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6223 + errInfo->eiBackRefNbr = backRefInfo[stackIdx].brbiGlobalId + 1;
6224 + errInfo->eiDetail = "already defined before";
6225 + XtFree(backRefContent);
6226 + return False;
6228 + else
6230 + curStrPatBRE->spbreRegExpText = backRefContent;
6233 + stackIdx --;
6236 + s ++;
6239 + /*
6240 + * Merge global backref. list of string pattern with given backRefList.
6241 + */
6242 + return updateGlobalBackRefs(
6243 + strPat,
6244 + backRefList,
6245 + errInfo);
6249 +** Merge global backref. list of given string pattern with given backRefList.
6250 +** Returns false, if merge fails.
6252 +static int updateGlobalBackRefs(
6253 + StringPattern *strPat,
6254 + GlobalBackRefElement *backRefList,
6255 + ErrorInfo *errInfo)
6257 + int i;
6258 + StrPatBackRefElement *curStrPatBRE;
6259 + GlobalBackRefElement *curGlobalBRE;
6261 + for (i=0;i < MAX_GLOBAL_BACK_REF_ID; i ++)
6263 + curStrPatBRE = &strPat->spOwnGlobalBackRef[i];
6265 + if (curStrPatBRE->spbreRegExpText != NULL)
6267 + curGlobalBRE = &backRefList[i];
6269 + if (curGlobalBRE->gbreDefByStrPat != NULL)
6271 + if (strcmp(curGlobalBRE->gbreRegExpText, curStrPatBRE->spbreRegExpText) != 0)
6273 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6274 + errInfo->eiBackRefNbr = i+1;
6275 + errInfo->eiDetail = "already defined before";
6277 + return False;
6280 + else
6282 + curGlobalBRE->gbreDefByStrPat = strPat;
6283 + curGlobalBRE->gbreRegExpText = curStrPatBRE->spbreRegExpText;
6288 + return True;
6292 +** Allocate and return a new string holding content of
6293 +** global backref. definition.
6295 +static char *createBackRefRegExpText(
6296 + const char *start,
6297 + const char *end)
6299 + int len = end - start;
6300 + char *regExpText = XtMalloc( len+1 );
6302 + memcpy( regExpText, start, len );
6304 + regExpText[len] = '\0';
6306 + return regExpText;
6310 +** Resolve all global backrefs of given match pattern table element.
6311 +** Returns false, if resolve fails.
6313 +static int resolveGlobalBackRefs(
6314 + ReadMatchPatternInfo *readPatInfo,
6315 + MatchPatternTableElement *element,
6316 + ErrorInfo *errInfo)
6318 + int i;
6319 + StringPattern *strPat;
6321 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
6323 + strPat = getReadStringPattern(readPatInfo, element->mpteAll.pesPattern[i]);
6325 + if (strPat->spRegularExpression && !strPat->spBackRefResolved)
6327 + if (!resolveGlobalBackRefsOfStrPat(strPat, element->mpteGlobalBackRef, errInfo))
6328 + return False;
6330 + strPat->spBackRefResolved = True;
6334 + return True;
6338 +** Resolve global backrefs of given string pattern.
6339 +** Returns false, if resolve fails.
6341 +static int resolveGlobalBackRefsOfStrPat(
6342 + StringPattern *strPat,
6343 + GlobalBackRefElement *backRefList,
6344 + ErrorInfo *errInfo)
6346 + char *s;
6347 + int globalId;
6348 + int localId = 1;
6350 + s = strPat->spText;
6352 + while (*s != '\0')
6354 + if (*s == '\\')
6356 + if (isdigit((unsigned char)*(s+1)))
6358 + /*
6359 + * \n (n=1..9) found: substitute global backref.
6360 + */
6361 + globalId =
6362 + (int)((unsigned char)*(s+1) - (unsigned char)'0') - 1;
6364 + if(globalId < 0)
6366 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6367 + errInfo->eiDetail = "backref '\\0' not allowed";
6368 + return False;
6371 + s = substituteGlobalBackRef(strPat, s, globalId, &localId, backRefList, errInfo);
6373 + if (s == NULL)
6374 + return False;
6376 + else if (*(s+1) != '\0')
6377 + s ++;
6379 + else if (*s == '(')
6381 + if (*(s+1) == '*')
6383 + if (isdigit((unsigned char)*(s+2)))
6385 + /*
6386 + * "(*n" (n=1..9) found: substitute global backref. definition.
6387 + */
6388 + globalId =
6389 + (int)((unsigned char)*(s+2) - (unsigned char)'0') - 1;
6391 + strPat->spOwnGlobalBackRef[globalId].spbreLocalBackRefID = localId;
6392 + strPat->spGlobalToLocalBackRef[globalId] = localId;
6394 + localId ++;
6396 + s = convertGlobalToLocalBackRef(strPat, s);
6398 + else
6400 + s ++;
6404 + s ++;
6407 + return True;
6411 +** Substitute global backref (\n, n=1..9) located at given "subsPtr"
6412 +** by its definition or by a local backref.
6413 +** Returns
6414 +** - NULL, if substitute fails or
6415 +** - substituted string pointer, where scan shall continue with.
6417 +static char *substituteGlobalBackRef(
6418 + StringPattern *strPat,
6419 + char *subsPtr,
6420 + int globalId,
6421 + int *localId,
6422 + GlobalBackRefElement *backRefList,
6423 + ErrorInfo *errInfo)
6425 + StrPatBackRefElement *strPatBackRef = &strPat->spOwnGlobalBackRef[globalId];
6426 + char *s;
6428 + if (strPatBackRef->spbreRegExpText == NULL)
6430 + /*
6431 + * given global backref definition is not located in given
6432 + * string pattern -> replace backref ID by backref reg. exp.
6433 + */
6434 + if (backRefList[globalId].gbreRegExpText == NULL)
6436 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6437 + errInfo->eiBackRefNbr = globalId + 1;
6438 + errInfo->eiDetail = "not defined within any string pattern";
6439 + return NULL;
6442 + if (strPat->spGlobalToLocalBackRef[globalId] == NO_LOCAL_BACK_REF_ID)
6444 + /*
6445 + * 1st occurence of global backref ID in this pattern ->
6446 + * replace global backref ID by backref reg. exp.
6447 + */
6448 + s = replaceBackRefIdByRegExp(strPat, subsPtr, backRefList[globalId].gbreRegExpText);
6450 + strPat->spGlobalToLocalBackRef[globalId] = *localId;
6451 + (*localId) ++;
6453 + else
6455 + /*
6456 + * next occurence of global backref ID in this pattern ->
6457 + * replace global backref ID by local one
6458 + */
6459 + s = subsPtr + 1;
6460 + *s = (char)((int)('0') + strPat->spGlobalToLocalBackRef[globalId]);
6463 + else
6465 + /*
6466 + * given global backref definition is located in given string pattern
6467 + */
6468 + if (strPatBackRef->spbreLocalBackRefID == NO_LOCAL_BACK_REF_ID)
6470 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6471 + errInfo->eiBackRefNbr = globalId + 1;
6472 + errInfo->eiDetail = "not defined before";
6473 + return NULL;
6476 + /*
6477 + * replace global backref ID by local one
6478 + */
6479 + s = subsPtr + 1;
6480 + *s = (char)((int)('0') + strPatBackRef->spbreLocalBackRefID);
6483 + return s;
6487 +** Replace global backref ID ("\n", n=1..9), located at given
6488 +** replaceStartPtr, by its definition (given by regExp parameter).
6489 +** Returns string pointer, where scan shall continue with
6491 +static char *replaceBackRefIdByRegExp(
6492 + StringPattern *strPat,
6493 + char *replaceStartPtr,
6494 + char *regExp)
6496 + char *oldText = strPat->spText;
6497 + char *newText;
6498 + char *n;
6499 + char *continueScanPtr;
6500 + int oldLen = strlen(oldText);
6501 + int regExpLen = strlen(regExp);
6502 + int replacePos = replaceStartPtr - oldText;
6503 + int remainingLen = oldLen-replacePos-2;
6505 + /*
6506 + * replace "\n" - located at replaceStartPtr - by "(regExp)"
6507 + */
6508 + newText = XtMalloc(oldLen + regExpLen + 3);
6510 + memcpy(newText, oldText, replacePos);
6511 + n = newText + replacePos;
6512 + *n = '(';
6513 + continueScanPtr = n;
6514 + n ++;
6515 + memcpy(n, regExp, regExpLen);
6516 + n += regExpLen;
6517 + *n = ')';
6518 + n ++;
6519 + memcpy(n, replaceStartPtr+2, remainingLen);
6520 + *(n + remainingLen) = '\0';
6522 + XtFree(oldText);
6524 + strPat->spText = newText;
6525 + strPat->spLength = strlen(newText);
6527 + return continueScanPtr;
6531 +** Convert global backref definition ("(*n", n=1..9), located at given
6532 +** convertPtr, by capturing parentheses "(".
6533 +** Returns string pointer, where scan shall continue with
6535 +static char *convertGlobalToLocalBackRef(
6536 + StringPattern *strPat,
6537 + char *convertPtr)
6539 + char *oldText = strPat->spText;
6540 + char *newText;
6541 + int oldLen = strlen(oldText);
6542 + int convertPos = convertPtr - oldText;
6544 + /*
6545 + * replace "(*n" - located at convertPtr - by "("
6546 + */
6547 + newText = XtMalloc(oldLen - 1);
6549 + memcpy(newText, oldText, convertPos+1);
6550 + memcpy(newText+convertPos+1, convertPtr+3, oldLen-convertPos-3);
6552 + *(newText + oldLen - 2) = '\0';
6554 + XtFree(oldText);
6556 + strPat->spText = newText;
6557 + strPat->spLength = strlen(newText);
6559 + return newText + convertPos;
6563 +** Read a match pattern table element from given input string.
6564 +** Return NULL, if read fails.
6566 +static MatchPatternTableElement *readMatchPatternTableElement(
6567 + char **inPtr,
6568 + char **errMsg,
6569 + char *name,
6570 + MatchPatternType type)
6572 + int error = False;
6573 + PatternElement *pattern;
6574 + PatternElement *allPat[MAX_STRING_PATTERNS];
6575 + int nbrOfPat = 0;
6576 + int sizeOfPat;
6577 + MatchPatternTableElement *result;
6578 + int isMonoPattern;
6579 + int skipBtwStartEnd;
6580 + int flash;
6581 + int ignoreHighLightInfo;
6582 + int i;
6584 + if (!getMPSGlobalAttribute(
6585 + inPtr,
6586 + errMsg,
6587 + &isMonoPattern,
6588 + &skipBtwStartEnd,
6589 + &flash,
6590 + &ignoreHighLightInfo ))
6592 + return NULL;
6595 + /*
6596 + * read all patterns
6597 + */
6598 + while (**inPtr != '\n' && !error)
6600 + if (!readPatternElement( inPtr, errMsg, &pattern ))
6602 + error = True;
6604 + else if (nbrOfPat >= MAX_STRING_PATTERNS)
6606 + *errMsg = "max. number of string patterns exceeded";
6607 + error = True;
6609 + else
6611 + pattern->peIndex = nbrOfPat;
6613 + allPat[nbrOfPat ++] = pattern;
6617 + if (error)
6619 + for (i=0; i < nbrOfPat; i ++)
6620 + freePatternElement( allPat[i] );
6622 + return NULL;
6625 + if (nbrOfPat == 0)
6627 + *errMsg = "min. one string pattern needed";
6628 + return NULL;
6631 + /*
6632 + * allocate & init. MatchPatternTableElement
6633 + */
6634 + result =
6635 + (MatchPatternTableElement *)XtMalloc(sizeof(MatchPatternTableElement));
6637 + result->mpteName = name;
6638 + result->mpteIndex = NO_ELEMENT_IDX;
6639 + result->mpteType = type;
6640 + result->mpteGroup = NO_GROUP_IDX;
6642 + sizeOfPat = sizeof(PatternElement *) * nbrOfPat;
6643 + result->mpteAll.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6645 + memcpy(result->mpteAll.pesPattern, allPat, sizeOfPat);
6647 + result->mpteAll.pesNumberOfPattern = nbrOfPat;
6649 + result->mpteIsMonoPattern = isMonoPattern;
6650 + result->mpteSkipBtwnStartEnd = skipBtwStartEnd;
6651 + result->mpteFlash = flash;
6652 + result->mpteIgnoreHighLightInfo = ignoreHighLightInfo;
6654 + result->mpteStartEndRE = NULL;
6656 + initGlobalBackRefList( result->mpteGlobalBackRef );
6658 + /*
6659 + * sort start / end / middle pattern
6660 + */
6661 + error = !sortReadPatternElementSet( &result->mpteAll, errMsg, result );
6663 + if (error)
6665 + freeMatchPatternTableElement( result );
6666 + return NULL;
6668 + else
6670 + return result;
6675 + * Sort read pattern element set into start, middle & end arrays.
6676 + * Validate "monopattern" attribute.
6677 + * Returns true, if validation was successful.
6678 + */
6679 +static int sortReadPatternElementSet(
6680 + PatternElementSet *allPat,
6681 + char **errMsg,
6682 + MatchPatternTableElement *result)
6684 + int sizeOfPat;
6685 + int isMonoPattern = result->mpteIsMonoPattern;
6687 + /*
6688 + * count number of start, middle & end pattern elements.
6689 + */
6690 + countPatternElementKind( allPat, result );
6692 + /*
6693 + * validate and allocate pattern elements.
6694 + */
6695 + if (result->mpteStart.pesNumberOfPattern != 0)
6697 + sizeOfPat = sizeof(PatternElement *) * result->mpteStart.pesNumberOfPattern;
6698 + result->mpteStart.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6700 + else
6702 + *errMsg = "min. one start pattern needed";
6703 + return False;
6706 + if (isMonoPattern &&
6707 + (result->mpteMiddle.pesNumberOfPattern != 0 ||
6708 + result->mpteEnd.pesNumberOfPattern !=0))
6710 + *errMsg = "mono pattern: only start pattern(s) allowed due to attribute [m]";
6711 + return False;
6714 + if (result->mpteMiddle.pesNumberOfPattern != 0)
6716 + sizeOfPat = sizeof(PatternElement *) * result->mpteMiddle.pesNumberOfPattern;
6717 + result->mpteMiddle.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6720 + if (result->mpteEnd.pesNumberOfPattern != 0)
6722 + sizeOfPat = sizeof(PatternElement *) * result->mpteEnd.pesNumberOfPattern;
6723 + result->mpteEnd.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6725 + else
6727 + if (!isMonoPattern)
6729 + *errMsg = "min. one end pattern needed";
6730 + return False;
6734 + /*
6735 + * sort pattern elements into start, middle & end arrays.
6736 + */
6737 + sortPatternElementSet( allPat, result );
6739 + if (isMonoPattern)
6741 + copyPatternSet( &result->mpteStart, &result->mpteEnd );
6744 + return True;
6748 + * Count number of start, middle & end patterns stored in "allPat".
6749 + */
6750 +static void countPatternElementKind(
6751 + PatternElementSet *allPat,
6752 + MatchPatternTableElement *result)
6754 + int i;
6756 + result->mpteStart.pesNumberOfPattern = 0;
6757 + result->mpteEnd.pesNumberOfPattern = 0;
6758 + result->mpteMiddle.pesNumberOfPattern = 0;
6760 + result->mpteStart.pesPattern = NULL;
6761 + result->mpteEnd.pesPattern = NULL;
6762 + result->mpteMiddle.pesPattern = NULL;
6764 + for (i=0; i < allPat->pesNumberOfPattern; i ++)
6766 + switch (allPat->pesPattern[i]->peKind)
6768 + case PEK_START:
6769 + result->mpteStart.pesNumberOfPattern ++;
6770 + break;
6771 + case PEK_MIDDLE:
6772 + result->mpteMiddle.pesNumberOfPattern ++;
6773 + break;
6774 + case PEK_END:
6775 + result->mpteEnd.pesNumberOfPattern ++;
6776 + break;
6777 + default:;
6783 + * Sort start, middle & end pattern elements into related arrays.
6784 + */
6785 +static void sortPatternElementSet(
6786 + PatternElementSet *allPat,
6787 + MatchPatternTableElement *result)
6789 + int i;
6790 + int s,m,e;
6792 + for (i=0, s=0, m=0, e=0; i < allPat->pesNumberOfPattern; i ++)
6794 + switch (allPat->pesPattern[i]->peKind)
6796 + case PEK_START:
6797 + result->mpteStart.pesPattern[s ++] = allPat->pesPattern[i];
6798 + break;
6799 + case PEK_MIDDLE:
6800 + result->mpteMiddle.pesPattern[m ++] = allPat->pesPattern[i];
6801 + break;
6802 + case PEK_END:
6803 + result->mpteEnd.pesPattern[e ++] = allPat->pesPattern[i];
6804 + break;
6805 + default:;
6810 +static void copyPatternSet(
6811 + PatternElementSet *sourcePS,
6812 + PatternElementSet *destPS)
6814 + int sizeOfPat;
6816 + destPS->pesNumberOfPattern = sourcePS->pesNumberOfPattern;
6818 + sizeOfPat = sizeof(PatternElement *) * destPS->pesNumberOfPattern;
6819 + destPS->pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6821 + memcpy(destPS->pesPattern, sourcePS->pesPattern, sizeOfPat);
6825 +** Free the allocated memory contained in a ReadMatchPatternInfo data structure
6827 +static void freeReadMatchPatternInfo( ReadMatchPatternInfo *readPatInfo )
6829 + int i;
6831 + for (i=0; i<readPatInfo->rmpiNbrOfElements; i++)
6832 + freeMatchPatternTableElement(readPatInfo->rmpiElement[i]);
6834 + for (i=0; i<readPatInfo->rmpiNbrOfGroups; i++)
6835 + freeMatchPatternGroupElement(readPatInfo->rmpiGroup[i]);
6837 + for (i=0; i<readPatInfo->rmpiNbrOfSeqElements; i++)
6838 + freeMatchPatternSequenceElement(readPatInfo->rmpiSequence[i]);
6840 + freePtr((void **)&readPatInfo->rmpiAllPatRE);
6842 + freePtr((void **)&readPatInfo->rmpiFlashPatRE);
6846 +** Free the allocated memory contained in a StringMatchTable data structure
6848 +static void freeStringMatchTable( StringMatchTable *table )
6850 + MatchPatternTable *patTable;
6851 + int i;
6853 + if (table == NULL)
6854 + return;
6856 + XtFree(table->smtLanguageMode);
6858 + /*
6859 + * Free all matching patterns
6860 + */
6861 + patTable = table->smtAllPatterns;
6863 + for (i=0; i<patTable->mptNumberOfElements; i++)
6864 + freeMatchPatternTableElement(patTable->mptElements[i]);
6866 + XtFree((char *)patTable);
6868 + /*
6869 + * Free matching pattern group elements
6870 + */
6871 + for (i=0; i<table->smtNumberOfGroups; i++)
6872 + freeMatchPatternGroupElement(table->smtGroups[i]);
6874 + /*
6875 + * Free matching pattern sequence elements
6876 + */
6877 + for (i=0; i<table->smtNumberOfSeqElements; i++)
6878 + freeMatchPatternSequenceElement(table->smtSequence[i]);
6880 + /*
6881 + * Free keyword reg. expressions
6882 + */
6883 + freePtr((void **)&table->smtAllPatRE);
6885 + freePtr((void **)&table->smtFlashPatRE);
6887 + XtFree((char *)table);
6891 +** Free the allocated memory contained in a MatchPatternTableElement data structure
6893 +static void freeMatchPatternTableElement( MatchPatternTableElement *element )
6895 + int i;
6897 + XtFree(element->mpteName);
6899 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
6901 + freePatternElement(element->mpteAll.pesPattern[i]);
6904 + freePtr((void **)&element->mpteStartEndRE);
6906 + freeXtPtr((void **)&element->mpteStart.pesPattern);
6908 + freeXtPtr((void **)&element->mpteMiddle.pesPattern);
6910 + freeXtPtr((void **)&element->mpteEnd.pesPattern);
6912 + XtFree((char *)element);
6916 +** Free the allocated memory contained in a PatternElement data structure
6918 +static void freePatternElement( PatternElement *element )
6920 + if (element->peType == PET_SINGLE)
6921 + freeStringPattern( &(element->peVal.peuSingle) );
6922 + else if (element->peType == PET_MULTIPLE)
6924 + freeStringPattern( &(element->peVal.peuMulti.mpStringPattern) );
6925 + XtFree( (char *)element->peVal.peuMulti.mpRefList );
6928 + XtFree( (char *)element );
6932 +** Free the allocated memory contained in a StringPattern data structure
6934 +static void freeStringPattern( StringPattern *strPat )
6936 + int i;
6938 + freeXtPtr((void **)&strPat->spText);
6939 + freeXtPtr((void **)&strPat->spOrigText);
6941 + freePtr((void **)&strPat->spTextRE);
6943 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
6944 + freeXtPtr((void **)&strPat->spOwnGlobalBackRef[i].spbreRegExpText);
6948 +** Free the allocated memory contained in a MatchPatternGroupElement data structure
6950 +static void freeMatchPatternGroupElement( MatchPatternGroupElement *group )
6952 + int i;
6954 + freeXtPtr((void **)&group->mpgeName);
6956 + freePtr((void **)&group->mpgeKeywordRE);
6958 + if (group->mpgeSubPatternIds != NULL)
6960 + for (i=0; i < group->mpgeNumberOfSubPatterns; i++)
6962 + XtFree(group->mpgeSubPatternIds[i]);
6964 + XtFree((char *)group->mpgeSubPatternIds);
6967 + XtFree((char *)group);
6971 +** Free the allocated memory contained in a MatchPatternSequenceElement data structure
6973 +static void freeMatchPatternSequenceElement( MatchPatternSequenceElement *sequence )
6975 + XtFree( sequence->mpseName );
6977 + XtFree( (char *)sequence );
6982 +** Format a matching pattern set parse error.
6984 +static void parseMatchingPatternSetError(
6985 + const char *stringStart,
6986 + const char *stoppedAt,
6987 + ErrorInfo *errInfo)
6989 + char *message = "";
6990 + int msgLen;
6991 + char *errorInForm = "matching pattern of \"%s\"";
6992 + char *errorIn;
6994 + if (errInfo->eiLanguageMode == NULL)
6996 + errorIn = "matching pattern";
6998 + else
7000 + errorIn = XtMalloc(strlen(errorInForm) + strlen(errInfo->eiLanguageMode)+1);
7001 + sprintf(errorIn, "matching pattern of \"%s\"", errInfo->eiLanguageMode);
7004 + if (errInfo->eiRegExpCompileMsg != NULL)
7006 + /*
7007 + * Error message of form:
7008 + * "MP \"eiMPTabElementName\", SP \"eiStringPatText\": eiRegExpCompileMsg" or
7009 + * "MP \"eiMPTabElementName\" - eiDetail: eiRegExpCompileMsg"
7010 + */
7012 + msgLen = strlen(errInfo->eiRegExpCompileMsg) + 1;
7014 + if (errInfo->eiMPTabElementName != NULL)
7015 + msgLen += strlen(errInfo->eiMPTabElementName) + 10;
7017 + if (errInfo->eiDetail != NULL)
7019 + msgLen += strlen(errInfo->eiDetail + 2);
7021 + else
7023 + if (errInfo->eiStringPatText != NULL)
7024 + msgLen += strlen(errInfo->eiStringPatText) + 9;
7027 + message = XtMalloc(msgLen);
7029 + strcpy(message, "");
7031 + if (errInfo->eiMPTabElementName != NULL)
7032 + sprintf( message, "MP \"%s\"", errInfo->eiMPTabElementName);
7034 + if (errInfo->eiDetail == NULL)
7036 + if (errInfo->eiStringPatText != NULL)
7037 + sprintf( message, "%s, SP \"%s\"", message, errInfo->eiStringPatText);
7039 + else
7041 + if (strlen(message) != 0)
7042 + strcat(message, " - ");
7044 + strcat(message, errInfo->eiDetail);
7047 + if (strlen(message) != 0)
7048 + strcat(message, ": ");
7050 + strcat(message, errInfo->eiRegExpCompileMsg);
7052 + else if (errInfo->eiDetail != NULL)
7054 + /*
7055 + * Error message of form:
7056 + * "MP \"eiMPTabElementName\", SP \"eiStringPatText\": Backref %d eiDetail
7057 + */
7058 + msgLen = strlen(errInfo->eiDetail) + 1;
7060 + if (errInfo->eiMPTabElementName != NULL)
7061 + msgLen += strlen(errInfo->eiMPTabElementName) + 7;
7062 + if (errInfo->eiStringPatText != NULL)
7063 + msgLen += strlen(errInfo->eiStringPatText) + 9;
7064 + if (errInfo->eiBackRefNbr != 0)
7065 + msgLen += 15;
7067 + message = XtMalloc(msgLen);
7069 + strcpy(message, "");
7071 + if (errInfo->eiMPTabElementName != NULL)
7072 + sprintf( message, "MP \"%s\"", errInfo->eiMPTabElementName);
7073 + if (errInfo->eiStringPatText != NULL)
7074 + sprintf( message, "%s, SP \"%s\"", message, errInfo->eiStringPatText);
7076 + if (strlen(message) != 0)
7077 + strcat(message, ": ");
7079 + if (errInfo->eiBackRefNbr != 0)
7080 + sprintf( message, "%s Backref %d ", message, errInfo->eiBackRefNbr);
7082 + strcat(message, errInfo->eiDetail);
7085 + ParseError(NULL, stringStart, stoppedAt, errorIn, message);
7087 + if (errInfo->eiRegExpCompileMsg != NULL || errInfo->eiDetail != NULL)
7089 + XtFree(message);
7092 + if (errInfo->eiLanguageMode != NULL)
7094 + XtFree(errorIn);
7097 + freeErrorInfo(errInfo);
7098 + initErrorInfo(errInfo);
7102 + * Pop-up a warning dialog showing a matching pattern set error.
7103 + */
7104 +static void dialogMatchingPatternSetError(
7105 + char *title,
7106 + ErrorInfo *errInfo)
7108 + char *message;
7109 + int msgLen = 1;
7111 + /*
7112 + * Error message of form:
7113 + * "Name : \"eiMPTabElementName\"\n
7114 + * "String: \"eiStringPatText\"\n
7115 + * eiDetail\n
7116 + * eiRegExpCompileMsg\n"
7117 + */
7119 + if (errInfo->eiMPTabElementName != NULL)
7120 + msgLen += strlen(errInfo->eiMPTabElementName) + 15;
7121 + if (errInfo->eiStringPatText != NULL)
7122 + msgLen += strlen(errInfo->eiStringPatText) + 15;
7123 + if (errInfo->eiDetail != NULL)
7124 + msgLen += strlen(errInfo->eiDetail) + 15;
7125 + if (errInfo->eiBackRefNbr != 0)
7126 + msgLen += 15;
7127 + if (errInfo->eiRegExpCompileMsg != NULL)
7128 + msgLen += strlen(errInfo->eiRegExpCompileMsg) + 15;
7130 + message = XtMalloc(msgLen);
7132 + strcpy(message, "");
7134 + if (errInfo->eiMPTabElementName != NULL)
7135 + sprintf( message, "%sName : \"%s\"\n", message, errInfo->eiMPTabElementName);
7136 + if (errInfo->eiStringPatText != NULL)
7137 + sprintf( message, "%sPattern: \"%s\"\n", message, errInfo->eiStringPatText);
7138 + if (errInfo->eiBackRefNbr != 0)
7139 + sprintf( message, "%sBackref %d ", message, errInfo->eiBackRefNbr);
7140 + if (errInfo->eiDetail != NULL)
7141 + sprintf( message, "%s%s\n", message, errInfo->eiDetail);
7142 + if (errInfo->eiRegExpCompileMsg != NULL)
7143 + sprintf( message, "%s%s\n", message, errInfo->eiRegExpCompileMsg);
7145 + DialogF(
7146 + DF_WARN, MatchPatternDialog.mpdShell, 1,
7147 + title,
7148 + "%s(language mode '%s')",
7149 + "OK",
7150 + message,
7151 + errInfo->eiLanguageMode);
7153 + XtFree(message);
7155 + freeErrorInfo(errInfo);
7156 + initErrorInfo(errInfo);
7160 +** Get matching pattern set name.
7161 +** Syntax:
7162 +** patternName ::= "name:"
7163 +** Returns true, if get was successful.
7165 +static int getMPSName(
7166 + char **inPtr,
7167 + ErrorInfo *errInfo,
7168 + char **name )
7170 + char *dummy;
7171 + char *field = ReadSymbolicField(inPtr);
7173 + if (field == NULL)
7175 + errInfo->eiDetail = "matching pattern name missing";
7176 + return False;
7179 + if (!SkipDelimiter(inPtr, &dummy))
7181 + errInfo->eiMPTabElementName = XtNewString(field);
7182 + errInfo->eiDetail = "':' missing after matching pattern name";
7183 + XtFree( field );
7184 + return False;
7187 + *name = field;
7189 + return True;
7193 +** Get matching pattern set type attribute.
7194 +** TypeAttribute ::=
7195 +** [s|g]:
7197 +** s : sub-pattern (pattern is only matched, if part of a pattern group).
7198 +** g : pattern (context) group (i.e. a sequence of sub-patterns).
7199 +** default: individual pattern (pattern is not part of a group and is
7200 +** matched individually.
7201 +** Returns true, if get was successful.
7203 +static int getMPSTypeAttribute(
7204 + char **inPtr,
7205 + ErrorInfo *errInfo,
7206 + MatchPatternType *type)
7208 + char *field = ReadSymbolicField(inPtr);
7209 + int successful = True;
7211 + *type = MPT_INDIVIDUAL;
7213 + if (field != NULL)
7215 + switch (*field)
7217 + case 'g':
7218 + *type = MPT_GROUP;
7219 + break;
7220 + case 's':
7221 + *type = MPT_SUB;
7222 + break;
7223 + default:
7224 + errInfo->eiDetail = "unknown matching pattern type attribute";
7225 + successful = False;
7229 + if (successful)
7231 + if (!SkipDelimiter(inPtr, &errInfo->eiDetail))
7233 + successful = False;
7237 + freeXtPtr((void **)&field);
7239 + return successful;
7243 +** Syntax:
7245 +** GlobalAttribute ::=
7246 +** [c][f][m][p][u]:
7248 +** c : the content between start and end pattern is skipped
7249 +** during parsing (e.g. pattern encloses a comment).
7250 +** f : flash matching pattern (if not set, then only jump
7251 +** to matching pattern is supported).
7252 +** m : mono pattern - set exist out of only one single pattern
7253 +** (start pattern = end pattern; e.g. quotes like ")
7254 +** p : ignore highlight info code of single patterns of this set
7255 +** ("plain").
7257 +** Returns TRUE, if global attribute was successful read.
7259 +static int getMPSGlobalAttribute(
7260 + char **inPtr,
7261 + char **errMsg,
7262 + int *isMonoPattern,
7263 + int *comment,
7264 + int *flash,
7265 + int *ignoreHighLightInfo)
7267 + char *field = ReadSymbolicField(inPtr);
7268 + char *attribute;
7269 + int successful = True;
7271 + *isMonoPattern = False;
7272 + *comment = False;
7273 + *flash = False;
7274 + *ignoreHighLightInfo = False;
7276 + if (field != NULL)
7278 + attribute = field;
7279 + while (*attribute != '\0' && successful)
7281 + switch (*attribute)
7283 + case 'c':
7284 + *comment = True;
7285 + break;
7286 + case 'f':
7287 + *flash = True;
7288 + break;
7289 + case 'm':
7290 + *isMonoPattern = True;
7291 + break;
7292 + case 'p':
7293 + *ignoreHighLightInfo = True;
7294 + break;
7295 + default:
7296 + *errMsg = "unknown global attribute";
7297 + successful = False;
7299 + attribute ++;
7303 + if (successful)
7305 + if (!SkipDelimiter(inPtr, errMsg))
7307 + successful = False;
7311 + freeXtPtr((void **)&field);
7313 + return successful;
7317 +** Get matching pattern set attribute.
7319 +** Syntax:
7321 +** patternAttribute ::=
7322 +** [s|m|e][w|l|r][i]:
7324 +** StringPatternKind:
7325 +** s : start string pattern.
7326 +** m : middle string pattern.
7327 +** e : end string pattern.
7328 +** WordBoundaryAttribute:
7329 +** w : pattern is word (i.e. before and after pattern
7330 +** there must be a delimiter).
7331 +** l : before pattern must be a delimiter (left side).
7332 +** r : after pattern must be a delimiter (right side).
7333 +** default: neither before nor after pattern must be a delimiter.
7334 +** StringAttribute:
7335 +** i : pattern is case insensitive (if not set: pattern is
7336 +** case sensitive).
7337 +** x : pattern is regular expression (if not set: pattern is
7338 +** literal string).
7340 +** Returns TRUE, if pattern attribute was successful read.
7342 +static int getMPSPatternAttribute(
7343 + char **inPtr,
7344 + char **errMsg,
7345 + PatternElementKind *patternKind,
7346 + PatternWordBoundary *wordBoundary,
7347 + int *caseInsensitive,
7348 + int *regularExpression)
7350 + char *field = ReadSymbolicField(inPtr);
7351 + char *attribute;
7352 + int successful = True;
7354 + *patternKind = PEK_UNKNOWN;
7355 + *wordBoundary = PWB_NONE;
7356 + *caseInsensitive = False;
7357 + *regularExpression = False;
7359 + if (field != NULL)
7361 + attribute = field;
7362 + while (*attribute != '\0' && successful)
7364 + switch (*attribute)
7366 + case 'e':
7367 + *patternKind = PEK_END;
7368 + break;
7369 + case 'i':
7370 + *caseInsensitive = True;
7371 + break;
7372 + case 'l':
7373 + *wordBoundary = PWB_LEFT;
7374 + break;
7375 + case 'm':
7376 + *patternKind = PEK_MIDDLE;
7377 + break;
7378 + case 'r':
7379 + *wordBoundary = PWB_RIGHT;
7380 + break;
7381 + case 's':
7382 + *patternKind = PEK_START;
7383 + break;
7384 + case 'w':
7385 + *wordBoundary = PWB_BOTH;
7386 + break;
7387 + case 'x':
7388 + *regularExpression = True;
7389 + break;
7390 + default:
7391 + *errMsg = "unknown string pattern attribute";
7392 + successful = False;
7394 + attribute ++;
7398 + if (successful)
7400 + if (!SkipDelimiter(inPtr, errMsg))
7402 + successful = False;
7406 + freeXtPtr((void **)&field);
7408 + return successful;
7412 +** Returns the (to be reserved) reg. ex. length of an pattern element.
7413 +** Update total number of multi patterns, too.
7415 +static int patternElementLen(
7416 + ReadMatchPatternInfo *info,
7417 + PatternElement *patElement,
7418 + int *nbrOfMultiPatterns)
7420 + PatternElement *referredElement;
7421 + StringPattern *strPat = NULL;
7422 + int patElementLen;
7424 + switch (patElement->peType)
7426 + case PET_SINGLE:
7427 + strPat = &patElement->peVal.peuSingle;
7428 + break;
7430 + case PET_MULTIPLE:
7431 + strPat = &patElement->peVal.peuMulti.mpStringPattern;
7433 + (*nbrOfMultiPatterns) ++;
7435 + break;
7437 + case PET_REFERENCE:
7438 + referredElement =
7439 + info->rmpiElement[patElement->peVal.peuRef.prElementIdx]->
7440 + mpteAll.pesPattern[patElement->peVal.peuRef.prPatternIdx];
7442 + strPat = &referredElement->peVal.peuMulti.mpStringPattern;
7443 + break;
7446 + /*
7447 + * reserve additional 4 characters ("(?i)") for case insensitive search
7448 + */
7449 + if (strPat->spCaseInsensitive)
7450 + patElementLen = strPat->spLength + 4;
7451 + else
7452 + patElementLen = strPat->spLength;
7454 + /*
7455 + * reserve additional 4 characters ("(?:)") for regular expression
7456 + */
7457 + if (strPat->spRegularExpression)
7458 + patElementLen += 4;
7460 + return patElementLen;
7464 +** Returns the (to be reserved) total reg. ex. length of given
7465 +** MatchPatternTableElement. Update total number of multi patterns, too.
7467 +static int totalMatchPatternTableElementLen(
7468 + ReadMatchPatternInfo *info,
7469 + MatchPatternTableElement *element,
7470 + int *nbrOfMultiPatterns)
7472 + int i;
7473 + int totalLen = 0;
7475 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
7477 + totalLen +=
7478 + patternElementLen(
7479 + info,
7480 + element->mpteAll.pesPattern[i],
7481 + nbrOfMultiPatterns );
7484 + return totalLen;
7488 +** Returns the (to be reserved) total reg. ex. length of given
7489 +** read match pattern info. Counts total number of multi patterns, too.
7491 +static int totalKeywordOfTableLen(
7492 + ReadMatchPatternInfo *info,
7493 + int *nbrOfMultiPatterns)
7495 + int i;
7496 + int totalLen = 0;
7498 + *nbrOfMultiPatterns = 0;
7500 + for (i=0; i<info->rmpiNbrOfElements; i ++)
7502 + totalLen +=
7503 + totalMatchPatternTableElementLen(
7504 + info,
7505 + info->rmpiElement[i],
7506 + nbrOfMultiPatterns);
7509 + return totalLen;
7513 +** Add given StringPattern to given reg. ex. strings
7515 +static void addPatternToRegExpString(
7516 + StringPattern *pattern,
7517 + RegExpStringInfo *regExpStringInfo)
7519 + char *r = NULL, *s;
7520 + char *adaptedRegExpText = NULL;
7521 + int prevLen = 0;
7523 + /*
7524 + * Select the buffer, where the pattern needs to be added
7525 + * to (depending on its word boundary). Prepare the buffer
7526 + * by evtl. adding a prefix, if related buffer is empty.
7527 + */
7528 + switch (pattern->spWordBoundary)
7530 + case PWB_NONE:
7531 + prevLen = strlen( regExpStringInfo->resiNoneWBRegExpString );
7533 + r = regExpStringInfo->resiNoneWBRegExpString + strlen( regExpStringInfo->resiNoneWBRegExpString );
7534 + break;
7535 + case PWB_LEFT:
7536 + prevLen = strlen( regExpStringInfo->resiLeftWBRegExpString );
7537 + if (prevLen == 0)
7539 + strcpy( regExpStringInfo->resiLeftWBRegExpString, "<(?:" );
7541 + r = regExpStringInfo->resiLeftWBRegExpString + strlen( regExpStringInfo->resiLeftWBRegExpString );
7542 + break;
7543 + case PWB_RIGHT:
7544 + prevLen = strlen( regExpStringInfo->resiRightWBRegExpString );
7545 + if (prevLen == 0)
7547 + strcpy( regExpStringInfo->resiRightWBRegExpString, "(?:" );
7549 + r = regExpStringInfo->resiRightWBRegExpString + strlen( regExpStringInfo->resiRightWBRegExpString );
7550 + break;
7551 + case PWB_BOTH:
7552 + prevLen = strlen( regExpStringInfo->resiBothWBRegExpString );
7553 + if (prevLen == 0)
7555 + strcpy( regExpStringInfo->resiBothWBRegExpString, "<(?:" );
7557 + r = regExpStringInfo->resiBothWBRegExpString + strlen( regExpStringInfo->resiBothWBRegExpString );
7558 + break;
7561 + /*
7562 + * add an "or" if there is already a pattern in the buffer
7563 + */
7564 + if (prevLen != 0)
7566 + *r++ = '|';
7569 + /*
7570 + * add "(?i" to order case insensitive search
7571 + */
7572 + if (pattern->spCaseInsensitive)
7574 + *r++ = '(';
7575 + *r++ = '?';
7576 + *r++ = 'i';
7579 + /*
7580 + * add "(?:" to group this regular expression
7581 + */
7582 + if (pattern->spRegularExpression)
7584 + *r++ = '(';
7585 + *r++ = '?';
7586 + *r++ = ':';
7588 + adaptedRegExpText =
7589 + adaptLocalBackRefs(
7590 + pattern->spText,
7591 + &regExpStringInfo->resiLocalBackRefID);
7593 + s = adaptedRegExpText;
7595 + else
7597 + s = pattern->spText;
7600 + /*
7601 + * add the pattern characters - evtl. escaped, if special
7602 + * regular expression symbols & pattern is no reg. exp. -
7603 + * to the buffer:
7604 + */
7606 + while (*s != '\0')
7608 + if (!pattern->spRegularExpression)
7610 + switch (*s)
7612 + case '(':
7613 + case ')':
7614 + case '-':
7615 + case '[':
7616 + case ']':
7617 + case '<':
7618 + case '>':
7619 + case '{':
7620 + case '}':
7621 + case '.':
7622 + case '\\':
7623 + case '|':
7624 + case '^':
7625 + case '$':
7626 + case '*':
7627 + case '+':
7628 + case '?':
7629 + case '&':
7630 + *r++ = '\\';
7631 + break;
7632 + };
7635 + *r++ = *s++;
7638 + /*
7639 + * close "reg. exp. group" bracket
7640 + */
7641 + if (pattern->spRegularExpression)
7643 + *r++ = ')';
7645 + XtFree(adaptedRegExpText);
7648 + /*
7649 + * close case insensitive search bracket
7650 + */
7651 + if (pattern->spCaseInsensitive)
7653 + *r++ = ')';
7656 + /*
7657 + * terminate added string
7658 + */
7659 + *r = '\0';
7663 +** Adapt local backrefs inside given regExpText by common local IDs.
7664 +** Returns new allocated reg. exp. string holding common local backrefs.
7666 +static char *adaptLocalBackRefs(
7667 + char *regExpText,
7668 + int *commonLocalId)
7670 + int id;
7671 + int ownLocalId = 0;
7672 + char *s = regExpText;
7673 + char *newRegExpText = XtMalloc(strlen(regExpText)*3);
7674 + char *n = newRegExpText;
7675 + int localBackRefList[MAX_LOCAL_BACK_REF_ID];
7677 + /*
7678 + * put all local backrefs into "localBackRefList".
7679 + */
7680 + scanForLocalBackRefs(regExpText, localBackRefList);
7682 + while (*s != '\0')
7684 + *n++ = *s;
7686 + if (*s == '\\')
7688 + s++;
7690 + if (isdigit((unsigned char)*s))
7692 + /*
7693 + * \n (n=1..9) found: replace local backref.
7694 + * by "common local ID"
7695 + */
7696 + id =
7697 + (int)((unsigned char)*s - (unsigned char)'0') - 1;
7699 + if (localBackRefList[id] != NO_LOCAL_BACK_REF_ID &&
7700 + localBackRefList[id] != LOCAL_BACK_REF_ID_USED)
7702 + *n++ = (char)((int)('0') + localBackRefList[id]);
7704 + else
7706 + *n++ = '0';
7709 + s ++;
7711 + else if (*s != '\0')
7713 + /*
7714 + * copy escaped character
7715 + */
7716 + *n++ = *s++;
7719 + else if (*s == '(')
7721 + s ++;
7723 + if (*s == '?')
7725 + /*
7726 + * non capturing parentheses found -> just copy it
7727 + */
7728 + *n++ = *s++;
7730 + else
7732 + /*
7733 + * capturing parentheses found:
7734 + */
7735 + if (localBackRefList[ownLocalId] == LOCAL_BACK_REF_ID_USED)
7737 + /*
7738 + * backref used within given reg. exp. text:
7739 + * remember common local id for replacement later on
7740 + */
7741 + localBackRefList[ownLocalId] = *commonLocalId;
7742 + (*commonLocalId) ++;
7743 + ownLocalId ++;
7745 + else
7747 + /*
7748 + * backref not used within given reg. exp. text:
7749 + * replace capturing parentheses by non capturing one
7750 + */
7751 + *n++ = '?';
7752 + *n++ = ':';
7756 + else
7758 + s ++;
7762 + /*
7763 + * terminate adapted string
7764 + */
7765 + *n = '\0';
7767 + return newRegExpText;
7771 +** Get all local backrefs of given regExpText and put them into
7772 +** given localBackRefList.
7774 +static void scanForLocalBackRefs(
7775 + char *regExpText,
7776 + int *localBackRefList)
7778 + int i;
7779 + int localId;
7780 + char *s = regExpText;
7782 + for (i=0; i<MAX_LOCAL_BACK_REF_ID; i++)
7784 + localBackRefList[i] = NO_LOCAL_BACK_REF_ID;
7787 + while (*s != '\0')
7789 + if (*s == '\\')
7791 + if (isdigit((unsigned char)*(s+1)))
7793 + /*
7794 + * \n (n=1..9) found: flag usage in local backref list
7795 + */
7796 + localId =
7797 + (int)((unsigned char)*(s+1) - (unsigned char)'0') - 1;
7799 + localBackRefList[localId] = LOCAL_BACK_REF_ID_USED;
7801 + s ++;
7803 + else if (*(s+1) != '\0')
7804 + s ++;
7806 + s ++;
7811 +** Returns true, if string of given multi pattern reference was
7812 +** not added to regExpStringInfo.
7814 +static int isMultiPatternNotAdded(
7815 + RegExpStringInfo *regExpStringInfo,
7816 + PatternReference *toBeAddedPR)
7818 + int i;
7819 + PatternReference *addedPR;
7820 + PatternReference *newPR;
7822 + for (i=0; i < regExpStringInfo->resiNbrOfAddedMultiPat; i++)
7824 + addedPR = regExpStringInfo->resiAddedMultiPat[i];
7826 + if (addedPR->prElementIdx == toBeAddedPR->prElementIdx &&
7827 + addedPR->prPatternIdx == toBeAddedPR->prPatternIdx)
7829 + return False;
7833 + newPR = (PatternReference *)XtMalloc(sizeof(PatternReference));
7835 + *newPR = *toBeAddedPR;
7837 + regExpStringInfo->resiAddedMultiPat[regExpStringInfo->resiNbrOfAddedMultiPat ++] = newPR;
7839 + return True;
7843 +** add given PatternElement to given reg. exp. strings
7845 +static void addUniquePatternToRegExpString(
7846 + PatternElement *patElement,
7847 + PatternReference *patElementReference,
7848 + ReadMatchPatternInfo *readMatchPatternInfo,
7849 + RegExpStringInfo *regExpStringInfo)
7851 + PatternElement *referredElement;
7852 + PatternReference referredPatReference;
7854 + switch (patElement->peType)
7856 + case PET_SINGLE:
7857 + addPatternToRegExpString(
7858 + &(patElement->peVal.peuSingle),
7859 + regExpStringInfo);
7860 + break;
7862 + case PET_MULTIPLE:
7863 + /*
7864 + * add element to reg. exp. string only, if it was
7865 + * not added before.
7866 + */
7867 + if (isMultiPatternNotAdded(regExpStringInfo, patElementReference))
7869 + addPatternToRegExpString(
7870 + &(patElement->peVal.peuMulti.mpStringPattern),
7871 + regExpStringInfo);
7873 + break;
7875 + case PET_REFERENCE:
7876 + /*
7877 + * add referred element to reg. exp. string only, if related
7878 + * multi pattern was not added before.
7879 + */
7880 + referredPatReference = patElement->peVal.peuRef;
7882 + referredElement =
7883 + readMatchPatternInfo->rmpiElement[referredPatReference.prElementIdx]->
7884 + mpteAll.pesPattern[referredPatReference.prPatternIdx];
7886 + if (isMultiPatternNotAdded(regExpStringInfo, &referredPatReference))
7888 + addPatternToRegExpString(
7889 + &(referredElement->peVal.peuMulti.mpStringPattern),
7890 + regExpStringInfo);
7892 + break;
7897 +** add given MatchPatternTableElement to given reg. ex. strings
7899 +static void addElementToRegExpString(
7900 + MatchPatternTableElement *element,
7901 + ReadMatchPatternInfo *readMatchPatternInfo,
7902 + RegExpStringInfo *regExpStringInfo)
7904 + int i;
7905 + PatternReference elementRef;
7907 + elementRef.prElementIdx = element->mpteIndex;
7909 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
7911 + elementRef.prPatternIdx = i;
7913 + addUniquePatternToRegExpString(
7914 + element->mpteAll.pesPattern[i],
7915 + &elementRef,
7916 + readMatchPatternInfo,
7917 + regExpStringInfo);
7922 +** Concatenate strings stored by regExpStringInfo.
7923 +** Free given regExpStringInfo afterwards.
7924 +** Returns resulting string.
7926 +static void catSMTRegExpStrings(
7927 + RegExpStringInfo *regExpStringInfo,
7928 + char **regExpString)
7930 + int resultingLen;
7932 + /*
7933 + * allocate & init. a buffer for the resulting regular expression
7934 + */
7935 + resultingLen =
7936 + strlen( regExpStringInfo->resiNoneWBRegExpString ) +
7937 + strlen( regExpStringInfo->resiLeftWBRegExpString ) +
7938 + strlen( regExpStringInfo->resiRightWBRegExpString ) +
7939 + strlen( regExpStringInfo->resiBothWBRegExpString ) + 5;
7941 + *regExpString = XtMalloc( resultingLen );
7943 + strcpy( *regExpString, "" );
7945 + /*
7946 + * add the single parts to the resulting regular expression
7947 + * (= cat of parts separated by an "or")
7948 + */
7949 + addSMTRegExpString( *regExpString, regExpStringInfo->resiNoneWBRegExpString, "" );
7950 + addSMTRegExpString( *regExpString, regExpStringInfo->resiLeftWBRegExpString, ")" );
7951 + addSMTRegExpString( *regExpString, regExpStringInfo->resiRightWBRegExpString, ")>" );
7952 + addSMTRegExpString( *regExpString, regExpStringInfo->resiBothWBRegExpString, ")>" );
7954 + /*
7955 + * free buffers
7956 + */
7957 + freeRegExpStringInfo( regExpStringInfo );
7961 +** Free the allocated memory contained in a RegExpStringInfo data structure
7963 +static void freeRegExpStringInfo(
7964 + RegExpStringInfo *regExpStringInfo)
7966 + int i;
7968 + XtFree( regExpStringInfo->resiNoneWBRegExpString );
7969 + XtFree( regExpStringInfo->resiLeftWBRegExpString );
7970 + XtFree( regExpStringInfo->resiRightWBRegExpString );
7971 + XtFree( regExpStringInfo->resiBothWBRegExpString );
7973 + for (i=0; i < regExpStringInfo->resiNbrOfAddedMultiPat; i ++)
7974 + XtFree( (char *)regExpStringInfo->resiAddedMultiPat[i] );
7976 + XtFree( (char *)regExpStringInfo->resiAddedMultiPat);
7980 +** Compose regular expression for start / end pattern.
7982 +static void composeStartEndRegExpString(
7983 + ReadMatchPatternInfo *readMatchPatternInfo,
7984 + MatchPatternTableElement *element,
7985 + char **regExpString)
7987 + int i;
7988 + RegExpStringInfo regExpStringInfo;
7989 + PatternReference elementRef;
7990 + PatternElementSet startPat = element->mpteStart;
7991 + PatternElementSet endPat = element->mpteEnd;
7993 + /*
7994 + * Allocate buffers for keyword regular expression.
7995 + */
7996 + setupRegExpStringBuffers(
7997 + readMatchPatternInfo,
7998 + &regExpStringInfo);
8000 + /*
8001 + * Treat start / end element of MatchPatternTableElement
8002 + */
8004 + elementRef.prElementIdx = element->mpteIndex;
8006 + for (i=0; i < startPat.pesNumberOfPattern; i ++)
8008 + elementRef.prPatternIdx = startPat.pesPattern[i]->peIndex;
8010 + addUniquePatternToRegExpString(
8011 + startPat.pesPattern[i],
8012 + &elementRef,
8013 + readMatchPatternInfo,
8014 + &regExpStringInfo);
8017 + for (i=0; i < endPat.pesNumberOfPattern; i ++)
8019 + elementRef.prPatternIdx = endPat.pesPattern[i]->peIndex;
8021 + addUniquePatternToRegExpString(
8022 + endPat.pesPattern[i],
8023 + &elementRef,
8024 + readMatchPatternInfo,
8025 + &regExpStringInfo);
8028 + /*
8029 + * Assemble the resulting regular expression
8030 + */
8031 + catSMTRegExpStrings(
8032 + &regExpStringInfo,
8033 + regExpString);
8036 +static void copyStringMatchTableForDialog(
8037 + StringMatchTable *sourceTable,
8038 + DialogMatchPatternInfo *dialogTable )
8040 + int i;
8042 + /*
8043 + * if no source table exist (yet), then set nbr. of elements / groups to 0
8044 + */
8045 + if (sourceTable == NULL)
8047 + dialogTable->dmpiNbrOfSeqElements = 0;
8049 + return;
8052 + /*
8053 + * copy matching pattern sequence
8054 + */
8055 + dialogTable->dmpiNbrOfSeqElements = sourceTable->smtNumberOfSeqElements;
8057 + for (i=0; i < sourceTable->smtNumberOfSeqElements; i ++)
8059 + copySequenceElementForDialog(
8060 + sourceTable,
8061 + sourceTable->smtSequence[i],
8062 + &dialogTable->dmpiSequence[i] );
8066 +static void *copyMatchPatternElementForDialog(
8067 + MatchPatternTable *table,
8068 + int sourceElementIdx)
8070 + int i;
8071 + int patIdx = 0;
8072 + MatchPatternTableElement *sourceElement;
8073 + DialogMatchPatternTableElement *destination;
8075 + sourceElement = table->mptElements[sourceElementIdx];
8077 + destination =
8078 + (DialogMatchPatternTableElement *)XtMalloc( sizeof(DialogMatchPatternTableElement) );
8080 + destination->dmpteName = XtNewString(sourceElement->mpteName);
8081 + destination->dmpteType = sourceElement->mpteType;
8082 + destination->dmpteSkipBtwnStartEnd = sourceElement->mpteSkipBtwnStartEnd;
8083 + destination->dmpteIgnoreHighLightInfo = sourceElement->mpteIgnoreHighLightInfo;
8084 + destination->dmpteFlash = sourceElement->mpteFlash;
8086 + for (i=0; i<sourceElement->mpteAll.pesNumberOfPattern; i++)
8088 + copyPatternForDialog(
8089 + table,
8090 + sourceElement->mpteAll.pesPattern[i],
8091 + &destination->dmptePatterns.dspElements[patIdx ++]);
8094 + destination->dmptePatterns.dspNumberOfPatterns = patIdx;
8096 + return (void *)destination;
8099 +static void copyPatternForDialog(
8100 + MatchPatternTable *table,
8101 + PatternElement *sourcePattern,
8102 + DialogStringPatternElement **dialogPattern )
8104 + DialogStringPatternElement *newPat;
8105 + StringPattern *strSourcePat = GetStringPattern( table, sourcePattern );
8107 + newPat = (DialogStringPatternElement *)XtMalloc(sizeof(DialogStringPatternElement));
8108 + *dialogPattern = newPat;
8110 + if( strSourcePat->spOrigText != NULL)
8111 + newPat->dspeText = XtNewString(strSourcePat->spOrigText);
8112 + else
8113 + newPat->dspeText = XtNewString(strSourcePat->spText);
8115 + newPat->dspeKind = sourcePattern->peKind;
8116 + newPat->dspeWordBoundary = strSourcePat->spWordBoundary;
8117 + newPat->dspeCaseInsensitive = strSourcePat->spCaseInsensitive;
8118 + newPat->dspeRegularExpression = strSourcePat->spRegularExpression;
8121 +static void *copyGroupElementForDialog(
8122 + MatchPatternGroupElement *sourceGroup)
8124 + int i;
8125 + DialogMatchPatternGroupElement *destination;
8127 + destination =
8128 + (DialogMatchPatternGroupElement *)XtMalloc( sizeof(DialogMatchPatternGroupElement) );
8130 + destination->dmpgeName = XtNewString(sourceGroup->mpgeName);
8131 + destination->dmpgeNumberOfSubPatterns = sourceGroup->mpgeNumberOfSubPatterns;
8133 + for ( i=0; i<destination->dmpgeNumberOfSubPatterns; i ++)
8135 + destination->dmpgeSubPatternIds[i] =
8136 + XtNewString(sourceGroup->mpgeSubPatternIds[i]);
8139 + return destination;
8142 +static void copySequenceElementForDialog(
8143 + StringMatchTable *sourceTable,
8144 + MatchPatternSequenceElement *sourceSeqElement,
8145 + DialogMatchPatternSequenceElement **dialogSeqElement )
8147 + DialogMatchPatternSequenceElement *destSeqElement;
8149 + destSeqElement =
8150 + (DialogMatchPatternSequenceElement *)XtMalloc( sizeof(DialogMatchPatternSequenceElement) );
8152 + *dialogSeqElement = destSeqElement;
8154 + destSeqElement->dmpseName = XtNewString(sourceSeqElement->mpseName);
8155 + destSeqElement->dmpseType = sourceSeqElement->mpseType;
8156 + destSeqElement->dmpseValid = True;
8158 + if (destSeqElement->dmpseType == MPT_GROUP)
8160 + destSeqElement->dmpsePtr =
8161 + copyGroupElementForDialog(
8162 + sourceTable->smtGroups[sourceSeqElement->mpseIndex]);
8164 + else
8166 + destSeqElement->dmpsePtr =
8167 + copyMatchPatternElementForDialog(
8168 + sourceTable->smtAllPatterns,
8169 + sourceSeqElement->mpseIndex);
8173 +static DialogMatchPatternSequenceElement *copyDialogSequenceElement(
8174 + DialogMatchPatternSequenceElement *sourceSeq)
8176 + DialogMatchPatternSequenceElement *destSeq;
8178 + destSeq =
8179 + (DialogMatchPatternSequenceElement *)XtMalloc(sizeof(DialogMatchPatternSequenceElement));
8181 + destSeq->dmpseName = XtNewString(sourceSeq->dmpseName);
8182 + destSeq->dmpseType = sourceSeq->dmpseType;
8183 + destSeq->dmpseValid = True;
8185 + destSeq->dmpsePtr = sourceSeq->dmpsePtr;
8187 + return destSeq;
8190 +static void freeDialogMatchPatternElement(
8191 + DialogMatchPatternTableElement *dialogElement )
8193 + int i;
8195 + for (i=0; i<dialogElement->dmptePatterns.dspNumberOfPatterns; i ++)
8197 + freeDialogStringPatternElement(
8198 + dialogElement->dmptePatterns.dspElements[i]);
8201 + freeXtPtr((void **)&dialogElement->dmpteName);
8203 + freeXtPtr((void **)&dialogElement);
8206 +static void freeDialogStringPatternElement(
8207 + DialogStringPatternElement *element)
8209 + freeXtPtr((void **)&element->dspeText);
8211 + freeXtPtr((void **)&element);
8214 +static void freeDialogGroupElement(
8215 + DialogMatchPatternGroupElement *dialogGroup )
8217 + int i;
8219 + for (i=0; i<dialogGroup->dmpgeNumberOfSubPatterns; i ++)
8221 + freeXtPtr((void **)&dialogGroup->dmpgeSubPatternIds[i]);
8224 + freeXtPtr((void **)&dialogGroup->dmpgeName);
8226 + freeXtPtr((void **)&dialogGroup);
8229 +static void freeDialogSequenceElement(
8230 + DialogMatchPatternSequenceElement *dialogSeq )
8232 + freeXtPtr((void **)&dialogSeq->dmpseName);
8234 + if (dialogSeq->dmpseType == MPT_GROUP)
8236 + freeDialogGroupElement(
8237 + (DialogMatchPatternGroupElement *)dialogSeq->dmpsePtr );
8239 + else
8241 + freeDialogMatchPatternElement(
8242 + (DialogMatchPatternTableElement *)dialogSeq->dmpsePtr );
8245 + freeXtPtr((void **)&dialogSeq);
8248 +static void copyDialogStringPatternsFromTable(
8249 + DialogMatchPatternTableElement *tableElement,
8250 + DialogStringPatterns *destPatterns)
8252 + int i;
8254 + destPatterns->dspNumberOfPatterns =
8255 + tableElement->dmptePatterns.dspNumberOfPatterns;
8257 + for (i=0; i<destPatterns->dspNumberOfPatterns; i++)
8259 + destPatterns->dspElements[i] =
8260 + copyDialogStringPatternElement(
8261 + tableElement->dmptePatterns.dspElements[i] );
8265 +static void copyDialogStringPatterns(
8266 + DialogStringPatterns *sourcePatterns,
8267 + DialogStringPatterns *destPatterns)
8269 + int i;
8271 + destPatterns->dspNumberOfPatterns =
8272 + sourcePatterns->dspNumberOfPatterns;
8274 + for (i=0; i<destPatterns->dspNumberOfPatterns; i++)
8276 + destPatterns->dspElements[i] =
8277 + copyDialogStringPatternElement(
8278 + sourcePatterns->dspElements[i] );
8282 +static void freeDialogStringPatterns(
8283 + DialogStringPatterns *patterns)
8285 + int i;
8287 + for (i=0; i<patterns->dspNumberOfPatterns; i++)
8289 + freeDialogStringPatternElement(patterns->dspElements[i]);
8292 + patterns->dspNumberOfPatterns = 0;
8295 +static DialogStringPatternElement *copyDialogStringPatternElement(
8296 + DialogStringPatternElement *sourceElement)
8298 + DialogStringPatternElement *newPatElement;
8300 + newPatElement = (DialogStringPatternElement *)XtMalloc(sizeof(DialogStringPatternElement));
8302 + newPatElement->dspeText = XtNewString(sourceElement->dspeText);
8303 + newPatElement->dspeKind = sourceElement->dspeKind;
8304 + newPatElement->dspeWordBoundary = sourceElement->dspeWordBoundary;
8305 + newPatElement->dspeCaseInsensitive = sourceElement->dspeCaseInsensitive;
8306 + newPatElement->dspeRegularExpression = sourceElement->dspeRegularExpression;
8308 + return newPatElement;
8311 +static void copyDialogPatternNamesFromGroup(
8312 + DialogMatchPatternGroupElement *group,
8313 + DialogStringPatterns *destPatterns)
8315 + int i;
8317 + destPatterns->dspNumberOfPatterns =
8318 + group->dmpgeNumberOfSubPatterns;
8320 + for (i=0; i<destPatterns->dspNumberOfPatterns; i++)
8322 + destPatterns->dspElements[i] =
8323 + copyDialogPatternName(
8324 + group->dmpgeSubPatternIds[i] );
8328 +static DialogStringPatternElement *copyDialogPatternName(
8329 + char *sourcePatternId)
8331 + DialogStringPatternElement *newPatElement;
8333 + newPatElement = (DialogStringPatternElement *)XtMalloc(sizeof(DialogStringPatternElement));
8335 + newPatElement->dspeText = XtNewString(sourcePatternId);
8336 + newPatElement->dspeKind = PEK_START;
8337 + newPatElement->dspeWordBoundary = PWB_NONE;
8338 + newPatElement->dspeCaseInsensitive = False;
8339 + newPatElement->dspeRegularExpression = False;
8341 + return newPatElement;
8344 +static void copyDialogPatternNamesToGroup(
8345 + DialogStringPatterns *sourceNames,
8346 + DialogMatchPatternGroupElement *destGroup)
8348 + int i;
8350 + destGroup->dmpgeNumberOfSubPatterns =
8351 + sourceNames->dspNumberOfPatterns;
8353 + for (i=0; i<destGroup->dmpgeNumberOfSubPatterns; i++)
8355 + destGroup->dmpgeSubPatternIds[i] =
8356 + XtNewString(
8357 + sourceNames->dspElements[i]->dspeText);
8363 +** Present a dialog for editing matching pattern information
8365 +void EditMatchPatterns(WindowInfo *window)
8367 + Widget form, lmOptMenu;
8368 + Widget lmForm;
8369 + Widget okBtn, applyBtn, checkBtn, deleteBtn, closeBtn, helpBtn;
8370 + Widget restoreBtn, lmBtn;
8371 + Widget matchPatternsForm, matchPatternsFrame, matchPatternsLbl;
8372 + Widget matchPatternTypeBox, matchPatternTypeLbl;
8373 + Widget globalAttributesBox;
8374 + Widget stringPatternsFrame, stringPatternsForm;
8375 + Widget stringPatternTypeBox;
8376 + Widget wordBoundaryBox;
8377 + Widget stringAttributesBox;
8378 + StringMatchTable *table;
8379 + XmString s1;
8380 + int n;
8381 + Arg args[20];
8383 + /*
8384 + * if the dialog is already displayed, just pop it to the top and return
8385 + */
8386 + if (MatchPatternDialog.mpdShell != NULL)
8388 + RaiseDialogWindow(MatchPatternDialog.mpdShell);
8389 + return;
8392 + /*
8393 + * decide on an initial language mode
8394 + */
8395 + MatchPatternDialog.mpdLangModeName =
8396 + XtNewString(
8397 + window->languageMode == PLAIN_LANGUAGE_MODE ?
8398 + PLAIN_LM_STRING : LanguageModeName(window->languageMode));
8400 + /*
8401 + * find the associated matching pattern table to edit
8402 + */
8403 + table = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
8405 + /*
8406 + * copy the list of patterns to one that the user can freely edit
8407 + */
8408 + copyStringMatchTableForDialog( table, &MatchPatternDialog.mpdTable );
8410 + /*
8411 + * init. status information of dialog
8412 + */
8413 + MatchPatternDialog.currentDmptSeqElement = NULL;
8414 + MatchPatternDialog.currentDmptElement = NULL;
8415 + MatchPatternDialog.currentDmptGroup = NULL;
8417 + MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns = 0;
8418 + MatchPatternDialog.mpdStringPatternIsDisplayed = True;
8420 + /*
8421 + * Create a form widget in an application shell
8422 + */
8423 + n = 0;
8424 + XtSetArg(args[n], XmNdeleteResponse, XmDO_NOTHING); n++;
8425 + XtSetArg(args[n], XmNiconName, "Matching Patterns"); n++;
8426 + XtSetArg(args[n], XmNtitle, "Matching (Parenthesis) Patterns"); n++;
8427 + MatchPatternDialog.mpdShell = CreateShellWithBestVis(APP_NAME, APP_CLASS,
8428 + applicationShellWidgetClass, TheDisplay, args, n);
8429 + AddSmallIcon(MatchPatternDialog.mpdShell);
8430 + form = XtVaCreateManagedWidget("editMatchPatterns", xmFormWidgetClass,
8431 + MatchPatternDialog.mpdShell, XmNautoUnmanage, False,
8432 + XmNresizePolicy, XmRESIZE_NONE, NULL);
8433 + XtAddCallback(form, XmNdestroyCallback, destroyCB, NULL);
8434 + AddMotifCloseCallback(MatchPatternDialog.mpdShell, closeCB, NULL);
8436 + lmForm = XtVaCreateManagedWidget("lmForm", xmFormWidgetClass,
8437 + form,
8438 + XmNleftAttachment, XmATTACH_POSITION,
8439 + XmNleftPosition, 1,
8440 + XmNtopAttachment, XmATTACH_POSITION,
8441 + XmNtopPosition, 1,
8442 + XmNrightAttachment, XmATTACH_POSITION,
8443 + XmNrightPosition, 99, NULL);
8445 + MatchPatternDialog.mpdLmPulldown =
8446 + CreateLanguageModeMenu(lmForm, matchPatternLangModeCB, NULL, True);
8448 + n = 0;
8449 + XtSetArg(args[n], XmNspacing, 0); n++;
8450 + XtSetArg(args[n], XmNmarginWidth, 0); n++;
8451 + XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
8452 + XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
8453 + XtSetArg(args[n], XmNleftPosition, 50); n++;
8454 + XtSetArg(args[n], XmNsubMenuId, MatchPatternDialog.mpdLmPulldown); n++;
8455 + lmOptMenu = XmCreateOptionMenu(lmForm, "langModeOptMenu", args, n);
8456 + XtManageChild(lmOptMenu);
8457 + MatchPatternDialog.mpdLmOptMenu = lmOptMenu;
8459 + XtVaCreateManagedWidget("lmLbl", xmLabelGadgetClass, lmForm,
8460 + XmNlabelString, s1=XmStringCreateSimple("Language Mode:"),
8461 + XmNmnemonic, 'M',
8462 + XmNuserData, XtParent(MatchPatternDialog.mpdLmOptMenu),
8463 + XmNalignment, XmALIGNMENT_END,
8464 + XmNrightAttachment, XmATTACH_POSITION,
8465 + XmNrightPosition, 50,
8466 + XmNtopAttachment, XmATTACH_FORM,
8467 + XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
8468 + XmNbottomWidget, lmOptMenu, NULL);
8469 + XmStringFree(s1);
8471 + lmBtn = XtVaCreateManagedWidget("lmBtn", xmPushButtonWidgetClass, lmForm,
8472 + XmNlabelString, s1=MKSTRING("Add / Modify\nLanguage Mode..."),
8473 + XmNmnemonic, 'A',
8474 + XmNrightAttachment, XmATTACH_FORM,
8475 + XmNtopAttachment, XmATTACH_FORM, NULL);
8476 + XtAddCallback(lmBtn, XmNactivateCallback, pmLanguageModeDialogCB, NULL);
8477 + XmStringFree(s1);
8479 + okBtn = XtVaCreateManagedWidget("ok", xmPushButtonWidgetClass, form,
8480 + XmNlabelString, s1=XmStringCreateSimple("OK"),
8481 + XmNleftAttachment, XmATTACH_POSITION,
8482 + XmNleftPosition, 1,
8483 + XmNrightAttachment, XmATTACH_POSITION,
8484 + XmNrightPosition, 13,
8485 + XmNbottomAttachment, XmATTACH_FORM,
8486 + XmNbottomOffset, BORDER, NULL);
8487 + XtAddCallback(okBtn, XmNactivateCallback, okCB, NULL);
8488 + XmStringFree(s1);
8490 + applyBtn = XtVaCreateManagedWidget("apply", xmPushButtonWidgetClass, form,
8491 + XmNlabelString, s1=XmStringCreateSimple("Apply"),
8492 + XmNmnemonic, 'y',
8493 + XmNleftAttachment, XmATTACH_POSITION,
8494 + XmNleftPosition, 13,
8495 + XmNrightAttachment, XmATTACH_POSITION,
8496 + XmNrightPosition, 26,
8497 + XmNbottomAttachment, XmATTACH_FORM,
8498 + XmNbottomOffset, BORDER, NULL);
8499 + XtAddCallback(applyBtn, XmNactivateCallback, applyCB, NULL);
8500 + XmStringFree(s1);
8502 + checkBtn = XtVaCreateManagedWidget("check", xmPushButtonWidgetClass, form,
8503 + XmNlabelString, s1=XmStringCreateSimple("Check"),
8504 + XmNmnemonic, 'k',
8505 + XmNleftAttachment, XmATTACH_POSITION,
8506 + XmNleftPosition, 26,
8507 + XmNrightAttachment, XmATTACH_POSITION,
8508 + XmNrightPosition, 39,
8509 + XmNbottomAttachment, XmATTACH_FORM,
8510 + XmNbottomOffset, BORDER, NULL);
8511 + XtAddCallback(checkBtn, XmNactivateCallback, checkCB, NULL);
8512 + XmStringFree(s1);
8514 + deleteBtn = XtVaCreateManagedWidget("delete", xmPushButtonWidgetClass, form,
8515 + XmNlabelString, s1=XmStringCreateSimple("Delete"),
8516 + XmNmnemonic, 'D',
8517 + XmNleftAttachment, XmATTACH_POSITION,
8518 + XmNleftPosition, 39,
8519 + XmNrightAttachment, XmATTACH_POSITION,
8520 + XmNrightPosition, 52,
8521 + XmNbottomAttachment, XmATTACH_FORM,
8522 + XmNbottomOffset, BORDER, NULL);
8523 + XtAddCallback(deleteBtn, XmNactivateCallback, deleteCB, NULL);
8524 + XmStringFree(s1);
8526 + restoreBtn = XtVaCreateManagedWidget("restore", xmPushButtonWidgetClass, form,
8527 + XmNlabelString, s1=XmStringCreateSimple("Restore Defaults"),
8528 + XmNmnemonic, 'f',
8529 + XmNleftAttachment, XmATTACH_POSITION,
8530 + XmNleftPosition, 52,
8531 + XmNrightAttachment, XmATTACH_POSITION,
8532 + XmNrightPosition, 73,
8533 + XmNbottomAttachment, XmATTACH_FORM,
8534 + XmNbottomOffset, BORDER, NULL);
8535 + XtAddCallback(restoreBtn, XmNactivateCallback, restoreCB, NULL);
8536 + XmStringFree(s1);
8538 + closeBtn = XtVaCreateManagedWidget("close", xmPushButtonWidgetClass,
8539 + form,
8540 + XmNlabelString, s1=XmStringCreateSimple("Close"),
8541 + XmNleftAttachment, XmATTACH_POSITION,
8542 + XmNleftPosition, 73,
8543 + XmNrightAttachment, XmATTACH_POSITION,
8544 + XmNrightPosition, 86,
8545 + XmNbottomAttachment, XmATTACH_FORM,
8546 + XmNbottomOffset, BORDER, NULL);
8547 + XtAddCallback(closeBtn, XmNactivateCallback, closeCB, NULL);
8548 + XmStringFree(s1);
8550 + helpBtn = XtVaCreateManagedWidget("help", xmPushButtonWidgetClass,
8551 + form,
8552 + XmNlabelString, s1=XmStringCreateSimple("Help"),
8553 + XmNmnemonic, 'H',
8554 + XmNleftAttachment, XmATTACH_POSITION,
8555 + XmNleftPosition, 86,
8556 + XmNrightAttachment, XmATTACH_POSITION,
8557 + XmNrightPosition, 99,
8558 + XmNbottomAttachment, XmATTACH_FORM,
8559 + XmNbottomOffset, BORDER, NULL);
8560 + XtAddCallback(helpBtn, XmNactivateCallback, helpCB, NULL);
8561 + XmStringFree(s1);
8563 + stringPatternsFrame = XtVaCreateManagedWidget("stringPatternsFrame", xmFrameWidgetClass,
8564 + form,
8565 + XmNleftAttachment, XmATTACH_POSITION,
8566 + XmNleftPosition, 1,
8567 + XmNrightAttachment, XmATTACH_POSITION,
8568 + XmNrightPosition, 99,
8569 + XmNbottomAttachment, XmATTACH_WIDGET,
8570 + XmNbottomWidget, okBtn,
8571 + XmNbottomOffset, BORDER, NULL);
8572 + stringPatternsForm = XtVaCreateManagedWidget("stringPatternsForm", xmFormWidgetClass,
8573 + stringPatternsFrame, NULL);
8574 + MatchPatternDialog.mpdStringPatternsLbl = XtVaCreateManagedWidget("mpdStringPatternsLbl", xmLabelGadgetClass,
8575 + stringPatternsFrame,
8576 + XmNlabelString, s1=XmStringCreateSimple(STRING_PATTERNS_LBL_TXT),
8577 + XmNmarginHeight, 0,
8578 + XmNchildType, XmFRAME_TITLE_CHILD, NULL);
8579 + XmStringFree(s1);
8581 + n = 0;
8582 + XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
8583 + XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
8584 + XtSetArg(args[n], XmNleftPosition, 1); n++;
8585 + XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
8586 + XtSetArg(args[n], XmNrightPosition, LIST_RIGHT-1); n++;
8587 + XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
8588 + XtSetArg(args[n], XmNbottomOffset, BORDER); n++;
8589 + MatchPatternDialog.mpdStringPatternsListW =
8590 + CreateManagedList(stringPatternsForm, "stringPatternsList", args,
8591 + n, (void **)MatchPatternDialog.currentStringPatterns.dspElements,
8592 + &MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns,
8593 + MAX_STRING_PATTERNS, 18,
8594 + getStringPatternDisplayedCB, NULL,
8595 + setStringPatternDisplayedCB, NULL,
8596 + freeStringPatternItemCB);
8597 + XtVaSetValues(MatchPatternDialog.mpdStringPatternsLbl, XmNuserData, MatchPatternDialog.mpdStringPatternsListW, NULL);
8599 + MatchPatternDialog.mpdStringPatternTypeLbl = XtVaCreateManagedWidget("mpdStringPatternTypeLbl", xmLabelGadgetClass,
8600 + stringPatternsForm,
8601 + XmNlabelString, s1=XmStringCreateSimple("String Pattern Type:"),
8602 + XmNmarginHeight, 0,
8603 + XmNalignment, XmALIGNMENT_BEGINNING,
8604 + XmNleftAttachment, XmATTACH_POSITION,
8605 + XmNleftPosition, LIST_RIGHT,
8606 + XmNtopAttachment, XmATTACH_FORM, NULL);
8607 + XmStringFree(s1);
8609 + stringPatternTypeBox = XtVaCreateManagedWidget("stringPatternTypeBox", xmRowColumnWidgetClass,
8610 + stringPatternsForm,
8611 + XmNorientation, XmHORIZONTAL,
8612 + XmNpacking, XmPACK_TIGHT,
8613 + XmNradioBehavior, True,
8614 + XmNleftAttachment, XmATTACH_POSITION,
8615 + XmNleftPosition, LIST_RIGHT,
8616 + XmNtopAttachment, XmATTACH_WIDGET,
8617 + XmNtopWidget, MatchPatternDialog.mpdStringPatternTypeLbl, NULL);
8618 + MatchPatternDialog.sptStartW = XtVaCreateManagedWidget("sptStartW",
8619 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8620 + XmNset, True,
8621 + XmNmarginHeight, 0,
8622 + XmNlabelString, s1=XmStringCreateSimple(
8623 + "Start"),
8624 + NULL);
8625 + XmStringFree(s1);
8626 + MatchPatternDialog.sptMiddleW = XtVaCreateManagedWidget("sptMiddleW",
8627 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8628 + XmNmarginHeight, 0,
8629 + XmNlabelString, s1=XmStringCreateSimple(
8630 + "Middle"),
8631 + NULL);
8632 + XmStringFree(s1);
8633 + MatchPatternDialog.sptEndW = XtVaCreateManagedWidget("sptEndW",
8634 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8635 + XmNmarginHeight, 0,
8636 + XmNlabelString, s1=XmStringCreateSimple(
8637 + "End"),
8638 + NULL);
8639 + XmStringFree(s1);
8641 + MatchPatternDialog.mpdWordBoundaryLbl = XtVaCreateManagedWidget("mpdWordBoundaryLbl", xmLabelGadgetClass,
8642 + stringPatternsForm,
8643 + XmNlabelString, s1=XmStringCreateSimple("Word boundary:"),
8644 + XmNmarginHeight, 0,
8645 + XmNalignment, XmALIGNMENT_BEGINNING,
8646 + XmNleftAttachment, XmATTACH_POSITION,
8647 + XmNleftPosition, LIST_RIGHT,
8648 + XmNtopAttachment, XmATTACH_WIDGET,
8649 + XmNtopWidget, stringPatternTypeBox,
8650 + NULL);
8651 + XmStringFree(s1);
8653 + wordBoundaryBox = XtVaCreateManagedWidget("wordBoundaryBox", xmRowColumnWidgetClass,
8654 + stringPatternsForm,
8655 + XmNorientation, XmHORIZONTAL,
8656 + XmNpacking, XmPACK_TIGHT,
8657 + XmNradioBehavior, True,
8658 + XmNleftAttachment, XmATTACH_POSITION,
8659 + XmNleftPosition, LIST_RIGHT,
8660 + XmNtopAttachment, XmATTACH_WIDGET,
8661 + XmNtopWidget, MatchPatternDialog.mpdWordBoundaryLbl, NULL);
8662 + MatchPatternDialog.wbbBothW = XtVaCreateManagedWidget("wbbBothW",
8663 + xmToggleButtonWidgetClass, wordBoundaryBox,
8664 + XmNset, True,
8665 + XmNmarginHeight, 0,
8666 + XmNlabelString, s1=XmStringCreateSimple(
8667 + "Both (pattern is word)"),
8668 + NULL);
8669 + XmStringFree(s1);
8670 + MatchPatternDialog.wbbLeftW = XtVaCreateManagedWidget("wbbLeftW",
8671 + xmToggleButtonWidgetClass, wordBoundaryBox,
8672 + XmNmarginHeight, 0,
8673 + XmNlabelString, s1=XmStringCreateSimple(
8674 + "Left"),
8675 + NULL);
8676 + XmStringFree(s1);
8677 + MatchPatternDialog.wbbRightW = XtVaCreateManagedWidget("wbbRightW",
8678 + xmToggleButtonWidgetClass, wordBoundaryBox,
8679 + XmNmarginHeight, 0,
8680 + XmNlabelString, s1=XmStringCreateSimple(
8681 + "Right"),
8682 + NULL);
8683 + XmStringFree(s1);
8684 + MatchPatternDialog.wbbNoneW = XtVaCreateManagedWidget("wbbNoneW",
8685 + xmToggleButtonWidgetClass, wordBoundaryBox,
8686 + XmNmarginHeight, 0,
8687 + XmNlabelString, s1=XmStringCreateSimple(
8688 + "None"),
8689 + NULL);
8690 + XmStringFree(s1);
8692 + MatchPatternDialog.mpdStringAttributesLbl = XtVaCreateManagedWidget("mpdStringAttributesLbl", xmLabelGadgetClass,
8693 + stringPatternsForm,
8694 + XmNlabelString, s1=XmStringCreateSimple("String Attributes:"),
8695 + XmNmarginHeight, 0,
8696 + XmNalignment, XmALIGNMENT_BEGINNING,
8697 + XmNleftAttachment, XmATTACH_POSITION,
8698 + XmNleftPosition, LIST_RIGHT,
8699 + XmNtopAttachment, XmATTACH_WIDGET,
8700 + XmNtopWidget, wordBoundaryBox, NULL);
8701 + XmStringFree(s1);
8703 + stringAttributesBox = XtVaCreateManagedWidget("stringAttributesBox", xmRowColumnWidgetClass,
8704 + stringPatternsForm,
8705 + XmNorientation, XmHORIZONTAL,
8706 + XmNpacking, XmPACK_TIGHT,
8707 + XmNleftAttachment, XmATTACH_POSITION,
8708 + XmNleftPosition, LIST_RIGHT,
8709 + XmNtopAttachment, XmATTACH_WIDGET,
8710 + XmNtopWidget, MatchPatternDialog.mpdStringAttributesLbl, NULL);
8711 + MatchPatternDialog.sabRegularExpressionW = XtVaCreateManagedWidget("sabRegularExpressionW",
8712 + xmToggleButtonWidgetClass, stringAttributesBox,
8713 + XmNset, False,
8714 + XmNmarginHeight, 0,
8715 + XmNlabelString, s1=XmStringCreateSimple(
8716 + "Regular Expression"),
8717 + NULL);
8718 + XmStringFree(s1);
8719 + XtAddCallback(MatchPatternDialog.sabRegularExpressionW, XmNvalueChangedCallback,
8720 + strPatRegExpressionCB, NULL);
8721 + MatchPatternDialog.sabCaseSensitiveW = XtVaCreateManagedWidget("sabCaseSensitiveW",
8722 + xmToggleButtonWidgetClass, stringAttributesBox,
8723 + XmNset, True,
8724 + XmNmarginHeight, 0,
8725 + XmNlabelString, s1=XmStringCreateSimple(
8726 + "Case Sensitive"),
8727 + NULL);
8728 + XmStringFree(s1);
8730 + MatchPatternDialog.mpdStringPatternLbl = XtVaCreateManagedWidget("mpdStringPatternLbl", xmLabelGadgetClass,
8731 + stringPatternsForm,
8732 + XmNlabelString, s1=XmStringCreateSimple("String Pattern"),
8733 + XmNmnemonic, 'S',
8734 + XmNalignment, XmALIGNMENT_BEGINNING,
8735 + XmNleftAttachment, XmATTACH_POSITION,
8736 + XmNleftPosition, LIST_RIGHT,
8737 + XmNtopAttachment, XmATTACH_WIDGET,
8738 + XmNtopWidget, stringAttributesBox,
8739 + XmNtopOffset, BORDER,
8740 + NULL);
8741 + XmStringFree(s1);
8743 + MatchPatternDialog.mpdStringPatternW = XtVaCreateManagedWidget("mpdStringPatternW", xmTextWidgetClass,
8744 + stringPatternsForm,
8745 + XmNleftAttachment, XmATTACH_POSITION,
8746 + XmNleftPosition, LIST_RIGHT,
8747 + XmNtopAttachment, XmATTACH_WIDGET,
8748 + XmNtopWidget, MatchPatternDialog.mpdStringPatternLbl,
8749 + XmNrightAttachment, XmATTACH_FORM,
8750 + XmNrightOffset, BORDER,
8751 + NULL);
8752 + RemapDeleteKey(MatchPatternDialog.mpdStringPatternW);
8753 + XtVaSetValues(MatchPatternDialog.mpdStringPatternLbl, XmNuserData, MatchPatternDialog.mpdStringPatternW, NULL);
8755 + MatchPatternDialog.mpdSubPatNamesLbl = XtVaCreateManagedWidget("mpdSubPatNamesLbl", xmLabelGadgetClass,
8756 + stringPatternsForm,
8757 + XmNlabelString, s1=XmStringCreateSimple("Sub-Pattern Name"),
8758 + XmNmnemonic, 't',
8759 + XmNalignment, XmALIGNMENT_BEGINNING,
8760 + XmNleftAttachment, XmATTACH_POSITION,
8761 + XmNleftPosition, LIST_RIGHT,
8762 + XmNtopAttachment, XmATTACH_WIDGET,
8763 + XmNtopWidget, MatchPatternDialog.mpdStringPatternW,
8764 + XmNtopOffset, BORDER,
8765 + NULL);
8766 + XmStringFree(s1);
8768 + MatchPatternDialog.mpdSubPatNamesPulldown =
8769 + createSubPatternNameMenu(stringPatternsForm, NULL, False);
8771 + n = 0;
8772 + XtSetArg(args[n], XmNspacing, 0); n++;
8773 + XtSetArg(args[n], XmNmarginWidth, 0); n++;
8774 + XtSetArg(args[n], XmNresizeWidth, True); n++;
8775 + XtSetArg(args[n], XmNresizeHeight, True); n++;
8776 + XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;
8777 + XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
8778 + XtSetArg(args[n], XmNtopWidget, MatchPatternDialog.mpdSubPatNamesLbl); n++;
8779 + XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
8780 + XtSetArg(args[n], XmNleftPosition, LIST_RIGHT); n++;
8781 + XtSetArg(args[n], XmNsubMenuId, MatchPatternDialog.mpdSubPatNamesPulldown); n++;
8782 + MatchPatternDialog.mpdSubPatNamesOptMenu =
8783 + XmCreateOptionMenu(stringPatternsForm, "subPatNamesOptMenu", args, n);
8784 + XtManageChild(MatchPatternDialog.mpdSubPatNamesOptMenu);
8786 + XtVaSetValues(
8787 + MatchPatternDialog.mpdSubPatNamesLbl,
8788 + XmNuserData, XtParent(MatchPatternDialog.mpdSubPatNamesOptMenu),
8789 + NULL);
8791 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesLbl, False);
8792 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesOptMenu, False);
8794 + matchPatternsFrame = XtVaCreateManagedWidget("matchPatternsFrame", xmFrameWidgetClass,
8795 + form,
8796 + XmNleftAttachment, XmATTACH_POSITION,
8797 + XmNleftPosition, 1,
8798 + XmNtopAttachment, XmATTACH_WIDGET,
8799 + XmNtopWidget, lmForm,
8800 + XmNrightAttachment, XmATTACH_POSITION,
8801 + XmNrightPosition, 99,
8802 + XmNbottomAttachment, XmATTACH_WIDGET,
8803 + XmNbottomWidget, stringPatternsFrame,
8804 + XmNbottomOffset, BORDER, NULL);
8805 + matchPatternsForm = XtVaCreateManagedWidget("matchPatternsForm", xmFormWidgetClass,
8806 + matchPatternsFrame, NULL);
8807 + matchPatternsLbl = XtVaCreateManagedWidget("matchPatternsLbl", xmLabelGadgetClass,
8808 + matchPatternsFrame,
8809 + XmNlabelString, s1=XmStringCreateSimple("Matching Patterns"),
8810 + XmNmnemonic, 'P',
8811 + XmNmarginHeight, 0,
8812 + XmNchildType, XmFRAME_TITLE_CHILD, NULL);
8813 + XmStringFree(s1);
8815 + matchPatternTypeLbl = XtVaCreateManagedWidget("matchPatternTypeLbl", xmLabelGadgetClass,
8816 + matchPatternsForm,
8817 + XmNlabelString, s1=XmStringCreateSimple("Matching Pattern Type:"),
8818 + XmNmarginHeight, 0,
8819 + XmNalignment, XmALIGNMENT_BEGINNING,
8820 + XmNleftAttachment, XmATTACH_POSITION,
8821 + XmNleftPosition, LIST_RIGHT,
8822 + XmNtopAttachment, XmATTACH_FORM, NULL);
8823 + XmStringFree(s1);
8825 + matchPatternTypeBox = XtVaCreateManagedWidget("matchPatternTypeBox", xmRowColumnWidgetClass,
8826 + matchPatternsForm,
8827 + XmNpacking, XmPACK_COLUMN,
8828 + XmNradioBehavior, True,
8829 + XmNleftAttachment, XmATTACH_POSITION,
8830 + XmNleftPosition, LIST_RIGHT,
8831 + XmNtopAttachment, XmATTACH_WIDGET,
8832 + XmNtopWidget, matchPatternTypeLbl, NULL);
8833 + MatchPatternDialog.mptbIndividualW = XtVaCreateManagedWidget("mptbIndividualW",
8834 + xmToggleButtonWidgetClass, matchPatternTypeBox,
8835 + XmNset, True,
8836 + XmNmarginHeight, 0,
8837 + XmNlabelString, s1=XmStringCreateSimple(
8838 + "Individual"),
8839 + XmNmnemonic, 'I', NULL);
8840 + XmStringFree(s1);
8841 + XtAddCallback(MatchPatternDialog.mptbIndividualW, XmNvalueChangedCallback,
8842 + matchPatTypeCB, NULL);
8843 + MatchPatternDialog.mptbSubPatternW = XtVaCreateManagedWidget("mptbSubPatternW",
8844 + xmToggleButtonWidgetClass, matchPatternTypeBox,
8845 + XmNmarginHeight, 0,
8846 + XmNlabelString, s1=XmStringCreateSimple(
8847 + "Sub-pattern (belongs to context group)"),
8848 + XmNmnemonic, 'u', NULL);
8849 + XmStringFree(s1);
8850 + XtAddCallback(MatchPatternDialog.mptbSubPatternW, XmNvalueChangedCallback,
8851 + matchPatTypeCB, NULL);
8852 + MatchPatternDialog.mptbContextGroupW = XtVaCreateManagedWidget("mptbContextGroupW",
8853 + xmToggleButtonWidgetClass, matchPatternTypeBox,
8854 + XmNmarginHeight, 0,
8855 + XmNlabelString, s1=XmStringCreateSimple(
8856 + "Context group"),
8857 + XmNmnemonic, 'g', NULL);
8858 + XmStringFree(s1);
8859 + XtAddCallback(MatchPatternDialog.mptbContextGroupW, XmNvalueChangedCallback,
8860 + matchPatTypeCB, NULL);
8862 + MatchPatternDialog.mpdGlobalAttributesLbl = XtVaCreateManagedWidget("mpdGlobalAttributesLbl",
8863 + xmLabelGadgetClass, matchPatternsForm,
8864 + XmNlabelString, s1=XmStringCreateSimple("Global Attributes:"),
8865 + XmNmarginHeight, 0,
8866 + XmNalignment, XmALIGNMENT_BEGINNING,
8867 + XmNleftAttachment, XmATTACH_POSITION,
8868 + XmNleftPosition, LIST_RIGHT,
8869 + XmNtopAttachment, XmATTACH_WIDGET,
8870 + XmNtopOffset, BORDER,
8871 + XmNtopWidget, matchPatternTypeBox, NULL);
8872 + XmStringFree(s1);
8874 + globalAttributesBox = XtVaCreateManagedWidget("globalAttributesBox", xmRowColumnWidgetClass,
8875 + matchPatternsForm,
8876 + XmNpacking, XmPACK_COLUMN,
8877 + XmNleftAttachment, XmATTACH_POSITION,
8878 + XmNleftPosition, LIST_RIGHT,
8879 + XmNtopAttachment, XmATTACH_WIDGET,
8880 + XmNtopWidget, MatchPatternDialog.mpdGlobalAttributesLbl, NULL);
8881 + MatchPatternDialog.gabSkipBtwStartEndW = XtVaCreateManagedWidget("gabSkipBtwStartEndW",
8882 + xmToggleButtonWidgetClass, globalAttributesBox,
8883 + XmNmarginHeight, 0,
8884 + XmNlabelString, s1=XmStringCreateSimple(
8885 + "Skip content between start / end pattern"),
8886 + XmNmnemonic, 'c', NULL);
8887 + XmStringFree(s1);
8888 + MatchPatternDialog.gabFlashW = XtVaCreateManagedWidget("gabFlashW",
8889 + xmToggleButtonWidgetClass, globalAttributesBox,
8890 + XmNset, True,
8891 + XmNmarginHeight, 0,
8892 + XmNlabelString, s1=XmStringCreateSimple(
8893 + "Flash matching pattern"),
8894 + XmNmnemonic, 'l', NULL);
8895 + XmStringFree(s1);
8896 + MatchPatternDialog.gabSyntaxBasedW = XtVaCreateManagedWidget("gabSyntaxBasedW",
8897 + xmToggleButtonWidgetClass, globalAttributesBox,
8898 + XmNset, True,
8899 + XmNmarginHeight, 0,
8900 + XmNlabelString, s1=XmStringCreateSimple(
8901 + "Syntax based"),
8902 + XmNmnemonic, 'b', NULL);
8903 + XmStringFree(s1);
8905 + MatchPatternDialog.mpdMatchPatternNameLbl = XtVaCreateManagedWidget("mpdMatchPatternNameLbl", xmLabelGadgetClass,
8906 + matchPatternsForm,
8907 + XmNlabelString, s1=XmStringCreateSimple(MATCH_PAT_NAME_LBL_TXT),
8908 + XmNmnemonic, 'N',
8909 + XmNalignment, XmALIGNMENT_BEGINNING,
8910 + XmNleftAttachment, XmATTACH_POSITION,
8911 + XmNleftPosition, LIST_RIGHT,
8912 + XmNtopAttachment, XmATTACH_WIDGET,
8913 + XmNtopWidget, globalAttributesBox,
8914 + XmNtopOffset, BORDER, NULL);
8915 + XmStringFree(s1);
8917 + MatchPatternDialog.mpdMatchPatternNameW = XtVaCreateManagedWidget("mpdMatchPatternNameW", xmTextWidgetClass,
8918 + matchPatternsForm,
8919 + XmNleftAttachment, XmATTACH_POSITION,
8920 + XmNleftPosition, LIST_RIGHT,
8921 + XmNtopAttachment, XmATTACH_WIDGET,
8922 + XmNtopWidget, MatchPatternDialog.mpdMatchPatternNameLbl,
8923 + XmNrightAttachment, XmATTACH_FORM,
8924 + XmNrightOffset, BORDER,
8925 + XmNbottomAttachment, XmATTACH_FORM,
8926 + XmNbottomOffset, BORDER,
8927 + NULL);
8928 + RemapDeleteKey(MatchPatternDialog.mpdMatchPatternNameW);
8929 + XtVaSetValues(MatchPatternDialog.mpdMatchPatternNameLbl, XmNuserData, MatchPatternDialog.mpdMatchPatternNameW, NULL);
8931 + n = 0;
8932 + XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
8933 + XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
8934 + XtSetArg(args[n], XmNleftPosition, 1); n++;
8935 + XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
8936 + XtSetArg(args[n], XmNrightPosition, LIST_RIGHT-1); n++;
8937 + XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
8939 + XtSetArg(args[n], XmNbottomOffset, BORDER); n++;
8940 + MatchPatternDialog.mpdMatchPatternNamesListW =
8941 + CreateManagedList(
8942 + matchPatternsForm, "mpdMatchPatternNamesListW",
8943 + args, n,
8944 + (void **)MatchPatternDialog.mpdTable.dmpiSequence, &MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements,
8945 + MAX_NBR_MATCH_PATTERNS, 18,
8946 + getMatchPatternDisplayedCB, NULL,
8947 + setMatchPatternDisplayedCB, NULL,
8948 + freeMatchPatternItemCB);
8949 + AddDeleteConfirmCB(MatchPatternDialog.mpdMatchPatternNamesListW, deleteMatchPatternItemCB, NULL);
8951 + XtVaSetValues(matchPatternsLbl, XmNuserData, MatchPatternDialog.mpdMatchPatternNamesListW, NULL);
8953 + /*
8954 + * set initial default button
8955 + */
8956 + XtVaSetValues(form, XmNdefaultButton, okBtn, NULL);
8957 + XtVaSetValues(form, XmNcancelButton, closeBtn, NULL);
8959 + /*
8960 + * handle mnemonic selection of buttons and focus to dialog
8961 + */
8962 + AddDialogMnemonicHandler(form, False);
8964 + /*
8965 + * fill in the dialog information for the selected language mode
8966 + */
8967 + SetLangModeMenu(MatchPatternDialog.mpdLmOptMenu, MatchPatternDialog.mpdLangModeName);
8969 + /*
8970 + * realize all of the widgets in the new dialog
8971 + */
8972 + RealizeWithoutForcingPosition(MatchPatternDialog.mpdShell);
8976 +** Modify match pattern dialog depending on showing a string pattern
8977 +** or a context group.
8979 +static void setDialogType(int dialogShowsStringPattern)
8981 + char *matchPatternNameText;
8982 + char *strPatCxtGrpListText;
8983 + XmString s1;
8984 + int regularExpression =
8985 + XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
8987 + /*
8988 + * check, if dialog mode needs to be switched
8989 + */
8990 + if (MatchPatternDialog.mpdStringPatternIsDisplayed == dialogShowsStringPattern)
8992 + return;
8995 + if (dialogShowsStringPattern)
8997 + matchPatternNameText = MATCH_PAT_NAME_LBL_TXT;
8998 + strPatCxtGrpListText = STRING_PATTERNS_LBL_TXT;
9000 + else
9002 + matchPatternNameText = "Context Group Name";
9003 + strPatCxtGrpListText = "Related Sub-Patterns";
9006 + XtSetSensitive(MatchPatternDialog.mpdGlobalAttributesLbl, dialogShowsStringPattern);
9007 + XtSetSensitive(MatchPatternDialog.gabSkipBtwStartEndW, dialogShowsStringPattern);
9008 + XtSetSensitive(MatchPatternDialog.gabFlashW, dialogShowsStringPattern);
9009 + XtSetSensitive(MatchPatternDialog.gabSyntaxBasedW, dialogShowsStringPattern);
9011 + XtSetSensitive(MatchPatternDialog.mpdStringPatternTypeLbl, dialogShowsStringPattern);
9012 + XtSetSensitive(MatchPatternDialog.sptStartW, dialogShowsStringPattern);
9013 + XtSetSensitive(MatchPatternDialog.sptMiddleW, dialogShowsStringPattern);
9014 + XtSetSensitive(MatchPatternDialog.sptEndW, dialogShowsStringPattern);
9016 + setSensitiveWordBoundaryBox( dialogShowsStringPattern && !regularExpression );
9018 + XtSetSensitive(MatchPatternDialog.mpdStringAttributesLbl, dialogShowsStringPattern);
9019 + XtSetSensitive(MatchPatternDialog.sabCaseSensitiveW, dialogShowsStringPattern);
9020 + XtSetSensitive(MatchPatternDialog.sabRegularExpressionW, dialogShowsStringPattern);
9022 + XtSetSensitive(MatchPatternDialog.mpdStringPatternLbl, dialogShowsStringPattern);
9023 + XtSetSensitive(MatchPatternDialog.mpdStringPatternW, dialogShowsStringPattern);
9025 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesLbl, !dialogShowsStringPattern);
9026 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesOptMenu, !dialogShowsStringPattern);
9028 + XtVaSetValues(
9029 + MatchPatternDialog.mpdMatchPatternNameLbl,
9030 + XmNlabelString, s1=XmStringCreateSimple(matchPatternNameText),
9031 + NULL);
9032 + XmStringFree(s1);
9034 + XtVaSetValues(
9035 + MatchPatternDialog.mpdStringPatternsLbl,
9036 + XmNlabelString, s1=XmStringCreateSimple(strPatCxtGrpListText),
9037 + NULL);
9038 + XmStringFree(s1);
9040 + MatchPatternDialog.mpdStringPatternIsDisplayed = dialogShowsStringPattern;
9043 +static void setSensitiveWordBoundaryBox(int enable)
9045 + XtSetSensitive(MatchPatternDialog.mpdWordBoundaryLbl, enable);
9046 + XtSetSensitive(MatchPatternDialog.wbbBothW , enable);
9047 + XtSetSensitive(MatchPatternDialog.wbbLeftW , enable);
9048 + XtSetSensitive(MatchPatternDialog.wbbRightW, enable);
9049 + XtSetSensitive(MatchPatternDialog.wbbNoneW , enable);
9052 +static void matchPatternLangModeCB(Widget w, XtPointer clientData, XtPointer callData)
9054 + char *modeName;
9055 + StringMatchTable *oldTable, *newTable;
9056 + StringMatchTable emptyTable = {"", NULL, NULL, NULL, NULL, 0, NULL, 0, NULL};
9057 + StringMatchTable *table;
9058 + DMPTranslationResult translResult;
9059 + int resp;
9061 + /*
9062 + * Get the newly selected mode name. If it's the same, do nothing
9063 + */
9064 + XtVaGetValues(w, XmNuserData, &modeName, NULL);
9065 + if (!strcmp(modeName, MatchPatternDialog.mpdLangModeName))
9066 + return;
9068 + /*
9069 + * Look up the original version of the patterns being edited
9070 + */
9071 + oldTable = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
9072 + if (oldTable == NULL)
9073 + oldTable = &emptyTable;
9075 + /*
9076 + * Get the current information displayed by the dialog. If it's bad,
9077 + * give the user the chance to throw it out or go back and fix it. If
9078 + * it has changed, give the user the chance to apply discard or cancel.
9079 + */
9080 + newTable = getDialogStringMatchTable(&translResult);
9082 + if (translResult == DMPTR_EMPTY)
9084 + newTable = &emptyTable;
9087 + if (newTable == NULL)
9089 + if (DialogF(
9090 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9091 + "Incomplete Matching Patterns for Language Mode",
9092 + "Discard incomplete entry for language mode '%s'?",
9093 + "Keep", "Discard",
9094 + MatchPatternDialog.mpdLangModeName) == 1)
9096 + SetLangModeMenu(
9097 + MatchPatternDialog.mpdLmOptMenu,
9098 + MatchPatternDialog.mpdLangModeName);
9100 + return;
9103 + else if (stringMatchTableDiffer(oldTable, newTable))
9105 + if (newTable == &emptyTable)
9106 + newTable = NULL;
9108 + resp =
9109 + DialogF(
9110 + DF_WARN, MatchPatternDialog.mpdShell, 3,
9111 + "Change Language Mode",
9112 + "Apply changes for language mode '%s'?",
9113 + "Apply Changes", "Discard Changes", "Cancel",
9114 + MatchPatternDialog.mpdLangModeName);
9116 + if (resp == 3)
9118 + SetLangModeMenu(
9119 + MatchPatternDialog.mpdLmOptMenu,
9120 + MatchPatternDialog.mpdLangModeName);
9122 + freeStringMatchTable( newTable );
9124 + return;
9126 + else if (resp == 1)
9128 + updateStringMatchTable( newTable );
9130 + /*
9131 + * Don't free the new table due to it's stored in MatchTables now
9132 + */
9133 + newTable = NULL;
9137 + if (newTable != NULL && newTable != &emptyTable)
9138 + freeStringMatchTable(newTable);
9140 + /*
9141 + * Free the old dialog information
9142 + */
9143 + freeVariableDialogData(DISCARD_LANGUAGE_MODE);
9145 + /*
9146 + * Fill the dialog with the new language mode information
9147 + */
9148 + MatchPatternDialog.mpdLangModeName = XtNewString(modeName);
9150 + /*
9151 + * Find the associated matching pattern table to edit
9152 + */
9153 + table = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
9155 + /*
9156 + * Copy the list of patterns to one that the user can freely edit
9157 + */
9158 + copyStringMatchTableForDialog( table, &MatchPatternDialog.mpdTable );
9160 + /*
9161 + * Update dialog fields
9162 + */
9163 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9164 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9167 +static void pmLanguageModeDialogCB(Widget w, XtPointer clientData, XtPointer callData)
9169 + EditLanguageModes();
9173 +** If a matching pattern dialog is up, ask to have the option menu for
9174 +** chosing language mode updated (via a call to CreateLanguageModeMenu)
9176 +void UpdateLanguageModeMenuMatchPattern(void)
9178 + Widget oldMenu;
9180 + if (MatchPatternDialog.mpdShell == NULL)
9181 + return;
9183 + oldMenu = MatchPatternDialog.mpdLmPulldown;
9184 + /*
9185 + * don't include "PLAIN" (4th parameter) in LM menu
9186 + */
9187 + MatchPatternDialog.mpdLmPulldown = CreateLanguageModeMenu(
9188 + XtParent(XtParent(oldMenu)), matchPatternLangModeCB, NULL, False);
9189 + XtVaSetValues(XmOptionButtonGadget(MatchPatternDialog.mpdLmOptMenu),
9190 + XmNsubMenuId, MatchPatternDialog.mpdLmPulldown, NULL);
9191 + SetLangModeMenu(MatchPatternDialog.mpdLmOptMenu, MatchPatternDialog.mpdLangModeName);
9193 + XtDestroyWidget(oldMenu);
9196 +static void *getMatchPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
9197 + void *cbArg)
9199 + DialogMatchPatternSequenceElement *newSeq;
9201 + /*
9202 + * If the dialog is currently displaying the "new" entry and the
9203 + * fields are empty, that's just fine
9204 + */
9205 + if (oldItem == NULL && matchPatternDialogEmpty())
9206 + return NULL;
9208 + /*
9209 + * Read string patterns / sub-pattern names area first
9210 + */
9211 + UpdateManagedList(MatchPatternDialog.mpdStringPatternsListW, True);
9213 + /*
9214 + * If there are no problems reading the data, just return it
9215 + */
9216 + newSeq = readMatchPatternFields(True);
9217 + if (newSeq != NULL)
9218 + return (void *)newSeq;
9220 + /*
9221 + * If there are problems, and the user didn't ask for the fields to be
9222 + * read, give more warning
9223 + */
9224 + if (!explicitRequest)
9226 + if (DialogF(
9227 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9228 + "Discard Matching Pattern Entry",
9229 + "Discard incomplete entry\nfor current matching pattern?",
9230 + "Keep", "Discard") == 2)
9232 + return oldItem == NULL
9233 + ? NULL
9234 + : (void *)copyDialogSequenceElement(
9235 + (DialogMatchPatternSequenceElement *)oldItem);
9239 + /*
9240 + * read data again without "silent" mode to display warning
9241 + */
9242 + newSeq = readMatchPatternFields(False);
9243 + *abort = True;
9245 + return NULL;
9248 +static void setMatchPatternDisplayedCB(void *item, void *cbArg)
9250 + DialogMatchPatternSequenceElement *seqElement;
9251 + DialogMatchPatternTableElement *element;
9252 + DialogMatchPatternGroupElement *group;
9253 + int isGroup;
9255 + seqElement = (DialogMatchPatternSequenceElement *)item;
9257 + MatchPatternDialog.currentDmptSeqElement = seqElement;
9259 + if (item == NULL)
9261 + MatchPatternDialog.currentDmptElement = NULL;
9262 + MatchPatternDialog.currentDmptGroup = NULL;
9264 + XmTextSetString(MatchPatternDialog.mpdMatchPatternNameW, "");
9265 + RadioButtonChangeState(MatchPatternDialog.mptbIndividualW, True, True);
9266 + RadioButtonChangeState(MatchPatternDialog.gabSkipBtwStartEndW, False, False);
9267 + RadioButtonChangeState(MatchPatternDialog.gabFlashW, True, False);
9268 + RadioButtonChangeState(MatchPatternDialog.gabSyntaxBasedW, True, False);
9270 + freeDialogStringPatterns(
9271 + &MatchPatternDialog.currentStringPatterns);
9273 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9275 + setDialogType( STRING_PATTERN_DIALOG );
9277 + else
9279 + isGroup = (seqElement->dmpseType == MPT_GROUP);
9281 + XmTextSetString(MatchPatternDialog.mpdMatchPatternNameW, seqElement->dmpseName);
9283 + if (seqElement->dmpseType == MPT_INDIVIDUAL)
9284 + RadioButtonChangeState(MatchPatternDialog.mptbIndividualW, True, True);
9285 + else if (seqElement->dmpseType == MPT_SUB)
9286 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9287 + else
9288 + RadioButtonChangeState(MatchPatternDialog.mptbContextGroupW, True, True);
9290 + freeDialogStringPatterns(
9291 + &MatchPatternDialog.currentStringPatterns);
9293 + if (isGroup)
9295 + group = (DialogMatchPatternGroupElement *)seqElement->dmpsePtr;
9296 + MatchPatternDialog.currentDmptElement = NULL;
9297 + MatchPatternDialog.currentDmptGroup = group;
9299 + copyDialogPatternNamesFromGroup(
9300 + group,
9301 + &MatchPatternDialog.currentStringPatterns);
9303 + else
9305 + element = (DialogMatchPatternTableElement *)seqElement->dmpsePtr;
9306 + MatchPatternDialog.currentDmptElement = element;
9307 + MatchPatternDialog.currentDmptGroup = NULL;
9309 + RadioButtonChangeState(
9310 + MatchPatternDialog.gabSkipBtwStartEndW,
9311 + element->dmpteSkipBtwnStartEnd,
9312 + False);
9313 + RadioButtonChangeState(
9314 + MatchPatternDialog.gabFlashW,
9315 + element->dmpteFlash,
9316 + False);
9317 + RadioButtonChangeState(
9318 + MatchPatternDialog.gabSyntaxBasedW,
9319 + !element->dmpteIgnoreHighLightInfo,
9320 + False);
9322 + copyDialogStringPatternsFromTable(
9323 + element,
9324 + &MatchPatternDialog.currentStringPatterns);
9327 + setDialogType( !isGroup );
9329 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9333 +static void freeMatchPatternItemCB(void *item)
9335 + freeDialogSequenceElement((DialogMatchPatternSequenceElement *)item);
9339 +** Use "delete confirm" to delete matching pattern name from
9340 +** any group of this matching pattern set, in case of sub-pattern.
9341 +** Always confirm the delete.
9343 +static int deleteMatchPatternItemCB(int itemIndex, void *cbArg)
9345 + DialogMatchPatternSequenceElement *seqElement;
9347 + seqElement = MatchPatternDialog.mpdTable.dmpiSequence[itemIndex];
9349 + if (seqElement->dmpseType == MPT_SUB)
9351 + removeMatchPatternFromAllGroups( seqElement->dmpseName );
9354 + return True;
9357 +static void *getStringPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
9358 + void *cbArg)
9360 + DialogStringPatternElement *newPat;
9361 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9363 + /*
9364 + * If the string pattern frame is currently displaying the "new" entry and the
9365 + * fields are empty, that's just fine
9366 + */
9367 + if (oldItem == NULL && stringPatternFieldsEmpty(isRelatedToGroup))
9368 + return NULL;
9370 + /*
9371 + * If there are no problems reading the data, just return it
9372 + */
9373 + newPat = readStringPatternFrameFields(True);
9374 + if (newPat != NULL)
9375 + return (void *)newPat;
9377 + /*
9378 + * If there are problems, and the user didn't ask for the fields to be
9379 + * read, give more warning
9380 + */
9382 + if (!explicitRequest)
9384 + if (DialogF(
9385 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9386 + "Discard String Pattern Entry",
9387 + "Discard incomplete entry\nfor current string pattern?",
9388 + "Keep", "Discard") == 2)
9390 + return oldItem == NULL
9391 + ? NULL
9392 + : (void *)copyDialogStringPatternElement(
9393 + (DialogStringPatternElement *)oldItem);
9397 + /*
9398 + * read data again without "silent" mode to display warning
9399 + */
9400 + newPat = readStringPatternFrameFields(False);
9401 + *abort = True;
9403 + return NULL;
9406 +static void setStringPatternDisplayedCB(void *item, void *cbArg)
9408 + DialogStringPatternElement *element = (DialogStringPatternElement *)item;
9409 + PatternElementKind peKind;
9410 + PatternWordBoundary wordBoundary;
9411 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9413 + if (item == NULL)
9415 + if (isRelatedToGroup)
9417 + updateSubPatternNameMenu(NULL, False);
9419 + else
9421 + XmTextSetString(MatchPatternDialog.mpdStringPatternW, "");
9423 + setSensitiveWordBoundaryBox( True );
9425 + RadioButtonChangeState(MatchPatternDialog.wbbBothW, True, True);
9427 + /*
9428 + * type of "new" string pattern:
9429 + * preset "start", if no string pattern exists at all;
9430 + * else select "end"
9431 + */
9432 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
9433 + RadioButtonChangeState(MatchPatternDialog.sptStartW, True, True);
9434 + else
9435 + RadioButtonChangeState(MatchPatternDialog.sptEndW, True, True);
9437 + RadioButtonChangeState(MatchPatternDialog.sabCaseSensitiveW, True, False);
9438 + RadioButtonChangeState(MatchPatternDialog.sabRegularExpressionW, False, False);
9441 + else
9443 + if (isRelatedToGroup)
9445 + updateSubPatternNameMenu(element->dspeText, False);
9447 + else
9449 + XmTextSetString(MatchPatternDialog.mpdStringPatternW, element->dspeText);
9451 + peKind = element->dspeKind;
9452 + wordBoundary = element->dspeWordBoundary;
9454 + if (peKind == PEK_START)
9455 + RadioButtonChangeState(MatchPatternDialog.sptStartW, True, True);
9456 + else if (peKind == PEK_MIDDLE)
9457 + RadioButtonChangeState(MatchPatternDialog.sptMiddleW, True, True);
9458 + else
9459 + RadioButtonChangeState(MatchPatternDialog.sptEndW, True, True);
9461 + if (wordBoundary == PWB_BOTH)
9462 + RadioButtonChangeState(MatchPatternDialog.wbbBothW, True, True);
9463 + else if (wordBoundary == PWB_LEFT)
9464 + RadioButtonChangeState(MatchPatternDialog.wbbLeftW, True, True);
9465 + else if (wordBoundary == PWB_RIGHT)
9466 + RadioButtonChangeState(MatchPatternDialog.wbbRightW, True, True);
9467 + else
9468 + RadioButtonChangeState(MatchPatternDialog.wbbNoneW, True, True);
9470 + RadioButtonChangeState(
9471 + MatchPatternDialog.sabCaseSensitiveW,
9472 + !element->dspeCaseInsensitive,
9473 + False);
9475 + RadioButtonChangeState(
9476 + MatchPatternDialog.sabRegularExpressionW,
9477 + element->dspeRegularExpression,
9478 + False);
9480 + setSensitiveWordBoundaryBox( !element->dspeRegularExpression );
9485 +static void freeStringPatternItemCB(void *item)
9487 + DialogStringPatternElement *patElement;
9489 + patElement = (DialogStringPatternElement *)item;
9491 + freeDialogStringPatternElement(patElement);
9494 +static void destroyCB(Widget w, XtPointer clientData, XtPointer callData)
9496 + freeVariableDialogData(DISCARD_LANGUAGE_MODE);
9498 + MatchPatternDialog.mpdShell = NULL;
9501 +static void okCB(Widget w, XtPointer clientData, XtPointer callData)
9503 + /*
9504 + * change the matching pattern
9505 + */
9506 + if (!getAndUpdateStringMatchTable())
9507 + return;
9509 + /*
9510 + * pop down and destroy the dialog
9511 + */
9512 + XtDestroyWidget(MatchPatternDialog.mpdShell);
9515 +static void applyCB(Widget w, XtPointer clientData, XtPointer callData)
9517 + /*
9518 + * change the matching pattern
9519 + */
9520 + getAndUpdateStringMatchTable();
9523 +static void checkCB(Widget w, XtPointer clientData, XtPointer callData)
9525 + StringMatchTable *newTable;
9526 + DMPTranslationResult translResult;
9528 + /*
9529 + * Get the current information displayed by the dialog.
9530 + * If a new table is available, then the test is passed successfully.
9531 + */
9532 + newTable = getDialogStringMatchTable(&translResult);
9534 + if (newTable != NULL)
9536 + DialogF(
9537 + DF_INF, MatchPatternDialog.mpdShell, 1,
9538 + "Matching Patterns Checked",
9539 + "Matching Patterns checked without error",
9540 + "OK");
9542 + freeStringMatchTable(newTable);
9546 +static void restoreCB(Widget w, XtPointer clientData, XtPointer callData)
9548 + StringMatchTable *defaultTable;
9550 + defaultTable = readDefaultStringMatchTable(MatchPatternDialog.mpdLangModeName);
9552 + if (defaultTable == NULL)
9554 + DialogF(
9555 + DF_WARN, MatchPatternDialog.mpdShell, 1,
9556 + "No Default Matching Pattern",
9557 + "There is no default matching pattern set\nfor language mode %s",
9558 + "OK",
9559 + MatchPatternDialog.mpdLangModeName);
9561 + return;
9564 + if (DialogF(
9565 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9566 + "Discard Changes",
9567 + "Are you sure you want to discard\n"
9568 + "all changes to matching patterns\n"
9569 + "for language mode %s?",
9570 + "Discard", "Cancel",
9571 + MatchPatternDialog.mpdLangModeName) == 2)
9573 + freeStringMatchTable(defaultTable);
9575 + return;
9578 + /*
9579 + * if a stored version of the matching pattern set exists, replace it.
9580 + * if it doesn't, add a new one.
9581 + */
9582 + updateStringMatchTable( defaultTable );
9584 + /*
9585 + * free the old dialog information
9586 + */
9587 + freeVariableDialogData(KEEP_LANGUAGE_MODE);
9589 + /*
9590 + * update the dialog
9591 + */
9592 + copyStringMatchTableForDialog( defaultTable, &MatchPatternDialog.mpdTable );
9594 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9595 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9598 +static void deleteCB(Widget w, XtPointer clientData, XtPointer callData)
9600 + if (DialogF(
9601 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9602 + "Delete Matching Patterns",
9603 + "Are you sure you want to delete\n"
9604 + "all matching patterns for\n"
9605 + "language mode %s?",
9606 + "Yes, Delete", "Cancel",
9607 + MatchPatternDialog.mpdLangModeName) == 2)
9609 + return;
9612 + /*
9613 + * if a stored version of the matching pattern exists, delete it from the list
9614 + */
9615 + DeleteStringMatchTable(MatchPatternDialog.mpdLangModeName);
9617 + /*
9618 + * free the old dialog information
9619 + */
9620 + freeVariableDialogData(KEEP_LANGUAGE_MODE);
9622 + /*
9623 + * clear out the dialog
9624 + */
9625 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9626 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9629 +static void closeCB(Widget w, XtPointer clientData, XtPointer callData)
9631 + /*
9632 + * pop down and destroy the dialog
9633 + */
9634 + XtDestroyWidget(MatchPatternDialog.mpdShell);
9637 +static void helpCB(Widget w, XtPointer clientData, XtPointer callData)
9640 + Help(HELP_MATCHING_PATTERNS);
9644 +static void strPatRegExpressionCB(Widget w, XtPointer clientData, XtPointer callData)
9646 + int regularExpression =
9647 + XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
9649 + setSensitiveWordBoundaryBox( !regularExpression );
9651 + if (regularExpression)
9652 + RadioButtonChangeState(MatchPatternDialog.sabCaseSensitiveW, True, False);
9655 +static void matchPatTypeCB(Widget w, XtPointer clientData, XtPointer callData)
9657 + if (MatchPatternDialog.currentDmptSeqElement != NULL)
9659 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW))
9661 + if (MatchPatternDialog.currentDmptSeqElement->dmpseType == MPT_SUB)
9663 + changeExistingSubPattern("Change to Context Group");
9666 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW) &&
9667 + MatchPatternDialog.currentDmptSeqElement->dmpseType != MPT_GROUP)
9669 + changeStringPatternToGroup();
9672 + else if (XmToggleButtonGetState(MatchPatternDialog.mptbIndividualW))
9674 + if (MatchPatternDialog.currentDmptSeqElement->dmpseType == MPT_SUB)
9676 + changeExistingSubPattern("Change to Individual Matching Pattern");
9678 + else if (MatchPatternDialog.currentDmptSeqElement->dmpseType == MPT_GROUP)
9680 + changeGroupToStringPattern("Change to Individual Matching Pattern");
9683 + else if (XmToggleButtonGetState(MatchPatternDialog.mptbSubPatternW))
9685 + if (MatchPatternDialog.currentDmptSeqElement->dmpseType == MPT_GROUP)
9687 + changeGroupToStringPattern("Change to Sub-Matching Pattern");
9692 + /*
9693 + * if context group button is (still) selected, then update labels etc.
9694 + */
9695 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW))
9697 + setDialogType(CONTEXT_GROUP_DIALOG);
9699 + else
9701 + setDialogType(STRING_PATTERN_DIALOG);
9704 + /*
9705 + * if a "new" entry is selected in matching patterns names list, then provide a
9706 + * list of all sub-pattern names
9707 + */
9708 + if (MatchPatternDialog.currentDmptSeqElement == NULL)
9710 + updateSubPatternNameMenu(NULL, True);
9714 +static void changeExistingSubPattern(
9715 + char *warnTitle)
9717 + DialogMatchPatternGroupElement *group;
9718 + int resp;
9720 + group =
9721 + getDialogGroupUsingMatchPattern(
9722 + MatchPatternDialog.currentDmptElement->dmpteName );
9724 + while ( group != NULL )
9726 + resp =
9727 + DialogF(
9728 + DF_WARN, MatchPatternDialog.mpdShell, 3,
9729 + warnTitle,
9730 + "Sub-pattern '%s' is used at least\n"
9731 + "by context group '%s'.\n\n"
9732 + "Remove this sub-pattern from this resp. all context group(s) ?",
9733 + "No, Keep", "Yes, Remove", "Yes, Remove All",
9734 + MatchPatternDialog.currentDmptElement->dmpteName,
9735 + group->dmpgeName);
9737 + if (resp == 1)
9739 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9741 + return;
9743 + else if (resp == 2)
9745 + removeMatchPatternFromGroup(
9746 + MatchPatternDialog.currentDmptElement->dmpteName,
9747 + group);
9749 + /*
9750 + * look for evtl. next context group holding this matching pattern
9751 + */
9752 + group =
9753 + getDialogGroupUsingMatchPattern(
9754 + MatchPatternDialog.currentDmptElement->dmpteName );
9756 + else
9758 + /*
9759 + * remove this matching pattern form all context groups
9760 + */
9761 + removeMatchPatternFromAllGroups(
9762 + MatchPatternDialog.currentDmptElement->dmpteName);
9764 + return;
9769 +static void changeStringPatternToGroup(void)
9771 + int resp;
9772 + int isSubPattern;
9774 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns != 0)
9776 + resp =
9777 + DialogF(
9778 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9779 + "Change to Context Group",
9780 + "All string patterns of '%s'\n"
9781 + "need to be discarded.\n\n"
9782 + "Discard related string patterns ?",
9783 + "No, Keep", "Yes, Discard",
9784 + MatchPatternDialog.currentDmptElement->dmpteName);
9786 + if (resp == 1)
9788 + isSubPattern = (MatchPatternDialog.currentDmptElement->dmpteType == MPT_SUB);
9790 + if (isSubPattern)
9791 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9792 + else
9793 + RadioButtonChangeState(MatchPatternDialog.mptbIndividualW, True, True);
9795 + return;
9798 + /*
9799 + * remove string patterns & update dialog fields
9800 + */
9801 + freeDialogStringPatterns(&MatchPatternDialog.currentStringPatterns);
9803 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9806 + /*
9807 + * invalidate this sub-/individual pattern
9808 + */
9809 + MatchPatternDialog.currentDmptSeqElement->dmpseValid = False;
9811 + /*
9812 + * update sub-pattern menu due to change to context group
9813 + */
9814 + updateSubPatternNameMenu(NULL, True);
9817 +static void changeGroupToStringPattern(
9818 + char *warnTitle)
9820 + int resp;
9822 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
9823 + return;
9825 + resp =
9826 + DialogF(
9827 + DF_WARN, MatchPatternDialog.mpdShell, 2,
9828 + warnTitle,
9829 + "Content of context group '%s'\n"
9830 + "needs to be discarded.\n\n"
9831 + "Discard content ?",
9832 + "No, Keep", "Yes, Discard",
9833 + MatchPatternDialog.currentDmptGroup->dmpgeName);
9835 + if (resp == 1)
9837 + RadioButtonChangeState(MatchPatternDialog.mptbContextGroupW, True, True);
9839 + else
9841 + /*
9842 + * remove string patterns & update dialog fields
9843 + */
9844 + freeDialogStringPatterns(&MatchPatternDialog.currentStringPatterns);
9846 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9851 +** Create a pulldown menu pane with the names of the sub-patterns of
9852 +** the current matching pattern set.
9854 +static Widget createSubPatternNameMenu(
9855 + Widget parent,
9856 + char *currentSubPatName,
9857 + int allSubPatterns)
9859 + NameList nameList;
9860 + Widget menu;
9861 + int i;
9863 + setupSubPatternNameList(currentSubPatName, allSubPatterns, &nameList);
9865 + menu = CreatePulldownMenu(parent, "subPatternNames", NULL, 0);
9867 + for (i=0; i<nameList.nlNumber; i++)
9869 + createSubPatNameMenuEntry(menu, nameList.nlId[i]);
9872 + return menu;
9875 +static void setupSubPatternNameList(
9876 + char *currentSubPatName,
9877 + int allSubPatterns,
9878 + NameList *nameList)
9880 + int n = 0;
9881 + int i;
9882 + DialogMatchPatternSequenceElement *seq;
9883 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9885 + if (isRelatedToGroup || allSubPatterns)
9887 + /*
9888 + * add "none selected" (default) item
9889 + */
9890 + nameList->nlId[n ++] = SPNM_NONE_SELECTED;
9892 + /*
9893 + * add one item for each (not assigned) sub-pattern name
9894 + */
9895 + for (i=0; i<MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i++)
9897 + seq = MatchPatternDialog.mpdTable.dmpiSequence[i];
9899 + if (seq->dmpseType == MPT_SUB &&
9900 + seq->dmpseValid &&
9901 + (allSubPatterns ||
9902 + (!isSubPatternNameInCurStrPat(seq->dmpseName) ||
9903 + (currentSubPatName != NULL &&
9904 + (strcmp(seq->dmpseName, currentSubPatName) == 0))) ))
9906 + nameList->nlId[n ++] = seq->dmpseName;
9910 + else
9912 + nameList->nlId[n ++] = "none available ";
9915 + nameList->nlNumber = n;
9919 +** Create a menu entry with the names of one sub-pattern.
9920 +** XmNuserData of this item contains the sub-pattern name.
9922 +static void createSubPatNameMenuEntry(
9923 + Widget menu,
9924 + char *subPatName)
9926 + Widget btn;
9927 + XmString s1;
9929 + btn = XtVaCreateManagedWidget("subPattern", xmPushButtonGadgetClass,
9930 + menu,
9931 + XmNlabelString, s1=XmStringCreateSimple(subPatName),
9932 + XmNmarginHeight, 0,
9933 + XmNuserData, (void *)subPatName, NULL);
9934 + XmStringFree(s1);
9938 +** Set the sub-patterns menu to show a particular sub-pattern name
9940 +static void setSubPatternNameMenu(
9941 + const char *subPatName)
9943 + int i;
9944 + Cardinal nItems;
9945 + WidgetList items;
9946 + Widget pulldown, selectedItem;
9947 + char *itemName;
9949 + XtVaGetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNsubMenuId, &pulldown, NULL);
9950 + XtVaGetValues(pulldown, XmNchildren, &items, XmNnumChildren, &nItems, NULL);
9952 + if (nItems == 0)
9953 + return;
9955 + selectedItem = items[0];
9957 + /*
9958 + * if no subPatName is given, then select first item of option menu
9959 + */
9960 + if (subPatName != NULL)
9962 + for (i=0; i<(int)nItems; i++)
9964 + if (items[i] != NULL && !items[i]->core.being_destroyed)
9966 + XtVaGetValues(items[i], XmNuserData, &itemName, NULL);
9967 + if (!strcmp(itemName, subPatName))
9969 + selectedItem = items[i];
9970 + break;
9976 + XtVaSetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNmenuHistory, selectedItem, NULL);
9980 +** Update sub-pattern names menu, e.g. when a new sub-pattern is defined
9982 +static void updateSubPatternNameMenu(
9983 + char *currentSubPatName,
9984 + int allSubPatterns)
9986 + NameList nameList;
9987 + WidgetList items;
9988 + Cardinal nItems;
9989 + int n;
9990 + XmString st1;
9992 + setupSubPatternNameList(currentSubPatName, allSubPatterns, &nameList);
9994 + /*
9995 + * Go thru all of the items in the sub-pattern names menu
9996 + * and rename them to match the current sub-patterns.
9997 + * Delete any extras.
9998 + */
9999 + XtVaGetValues(
10000 + MatchPatternDialog.mpdSubPatNamesPulldown,
10001 + XmNchildren, &items,
10002 + XmNnumChildren, &nItems,
10003 + NULL);
10005 + for (n=0; n<(int)nItems; n++)
10007 + if (n >= nameList.nlNumber)
10009 + /*
10010 + * unmanaging before destroying stops parent from displaying
10011 + */
10012 + XtUnmanageChild(items[n]);
10013 + XtDestroyWidget(items[n]);
10015 + else
10017 + if (items[n] == NULL || items[n]->core.being_destroyed)
10019 + /*
10020 + * create a new entry (widget) if this one is not existing or
10021 + * if it is marked as to be destroyed
10022 + */
10023 + createSubPatNameMenuEntry(
10024 + MatchPatternDialog.mpdSubPatNamesPulldown, nameList.nlId[n]);
10026 + else
10028 + XtVaSetValues(
10029 + items[n],
10030 + XmNlabelString, st1=XmStringCreateSimple(nameList.nlId[n]),
10031 + XmNuserData, (void *)nameList.nlId[n],
10032 + NULL);
10034 + XmStringFree(st1);
10039 + /*
10040 + * add new items for remaining sub-patterns names
10041 + */
10042 + for (n=(int)nItems; n<nameList.nlNumber; n++)
10044 + createSubPatNameMenuEntry(
10045 + MatchPatternDialog.mpdSubPatNamesPulldown, nameList.nlId[n]);
10048 + /*
10049 + * select entry shown in sub-pattern name option menu
10050 + */
10051 + setSubPatternNameMenu(currentSubPatName);
10054 +static char *getSelectedSubPatternName(void)
10056 + Widget selectedItem;
10057 + char *itemName;
10059 + XtVaGetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNmenuHistory, &selectedItem, NULL);
10060 + XtVaGetValues(selectedItem, XmNuserData, &itemName, NULL);
10062 + return itemName;
10065 +static int isSubPatternNameInCurStrPat(
10066 + char *subPatName)
10068 + int i;
10069 + DialogStringPatterns *curPatNames = &MatchPatternDialog.currentStringPatterns;
10071 + for (i=0; i<curPatNames->dspNumberOfPatterns; i++)
10073 + if (strcmp(curPatNames->dspElements[i]->dspeText, subPatName) == 0)
10074 + return True;
10077 + return False;
10081 +** Read the matching pattern fields of the matching pattern dialog and produce an
10082 +** allocated DialogMatchPatternSequenceElement structure reflecting the contents.
10083 +** Pop up dialogs telling the user what's wrong (Passing "silent" as True,
10084 +** suppresses these dialogs).
10085 +** Returns NULL on error.
10087 +static DialogMatchPatternSequenceElement *readMatchPatternFields(int silent)
10089 + int isGroup;
10090 + char *name;
10091 + char *nameLabel;
10092 + char *nameTitle;
10093 + char *contentTitle;
10094 + char *contentWarningText;
10095 + DialogMatchPatternSequenceElement *newSeq;
10096 + DialogMatchPatternTableElement *newElement;
10097 + DialogMatchPatternGroupElement *newGroup;
10099 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW))
10101 + nameLabel = "context group name";
10102 + nameTitle = "Context Group Name";
10103 + contentTitle = "Context Group Content";
10104 + contentWarningText = "Please assign min. 1\nsub-pattern";
10105 + isGroup = True;
10107 + else
10109 + nameLabel = "matching pattern name";
10110 + nameTitle = "Matching Pattern Name";
10111 + contentTitle = "Matching Pattern Content";
10112 + contentWarningText = "Please specify min. 1\nstring pattern";
10113 + isGroup = False;
10116 + name =
10117 + ReadSymbolicFieldTextWidget(
10118 + MatchPatternDialog.mpdMatchPatternNameW,
10119 + nameLabel,
10120 + silent);
10122 + if (name == NULL)
10124 + return NULL;
10126 + else if (*name == '\0')
10128 + if (!silent)
10130 + DialogF(
10131 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10132 + nameTitle,
10133 + "Please specify a valid name",
10134 + "OK");
10135 + XmProcessTraversal(MatchPatternDialog.mpdMatchPatternNameW, XmTRAVERSE_CURRENT);
10137 + XtFree(name);
10138 + return NULL;
10141 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
10143 + if (!silent)
10145 + DialogF(
10146 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10147 + contentTitle,
10148 + contentWarningText,
10149 + "OK");
10151 + XtFree(name);
10152 + return NULL;
10154 + else
10156 + if (!isGroup &&
10157 + !isStartPatternElementAvailable(&MatchPatternDialog.currentStringPatterns))
10159 + if (!silent)
10161 + DialogF(
10162 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10163 + contentTitle,
10164 + "Please specify min. 1 string pattern\nof type 'start'",
10165 + "OK");
10167 + XtFree(name);
10168 + return NULL;
10172 + if (MatchPatternDialog.currentDmptElement != NULL &&
10173 + MatchPatternDialog.currentDmptElement->dmpteType == MPT_SUB &&
10174 + strcmp(MatchPatternDialog.currentDmptElement->dmpteName, name) != 0)
10176 + renameMatchPatternInAllGroups(
10177 + MatchPatternDialog.currentDmptElement->dmpteName,
10178 + name);
10181 + newSeq =
10182 + (DialogMatchPatternSequenceElement *)XtMalloc(sizeof(DialogMatchPatternSequenceElement));
10184 + newSeq->dmpseName = name;
10185 + newSeq->dmpseValid = True;
10187 + if (isGroup)
10189 + newSeq->dmpseType = MPT_GROUP;
10191 + newGroup =
10192 + (DialogMatchPatternGroupElement *)XtMalloc(sizeof(DialogMatchPatternGroupElement));
10194 + newGroup->dmpgeName = XtNewString(name);
10196 + copyDialogPatternNamesToGroup(
10197 + &MatchPatternDialog.currentStringPatterns,
10198 + newGroup);
10200 + newSeq->dmpsePtr = (void *)newGroup;
10202 + else
10204 + if (XmToggleButtonGetState(MatchPatternDialog.mptbIndividualW))
10205 + newSeq->dmpseType = MPT_INDIVIDUAL;
10206 + else
10207 + newSeq->dmpseType = MPT_SUB;
10209 + newElement =
10210 + (DialogMatchPatternTableElement *)XtMalloc(sizeof(DialogMatchPatternTableElement));
10212 + newElement->dmpteName = XtNewString(name);
10213 + newElement->dmpteType = newSeq->dmpseType;
10215 + newElement->dmpteSkipBtwnStartEnd =
10216 + XmToggleButtonGetState(MatchPatternDialog.gabSkipBtwStartEndW);
10218 + newElement->dmpteFlash =
10219 + XmToggleButtonGetState(MatchPatternDialog.gabFlashW);
10221 + newElement->dmpteIgnoreHighLightInfo =
10222 + !XmToggleButtonGetState(MatchPatternDialog.gabSyntaxBasedW);
10224 + copyDialogStringPatterns(
10225 + &MatchPatternDialog.currentStringPatterns,
10226 + &newElement->dmptePatterns);
10228 + newSeq->dmpsePtr = (void *)newElement;
10231 + return newSeq;
10235 +** Check, if min. 1 string pattern of type 'start' is
10236 +** available within dialog.
10237 +** Returns True, if min. 1 start string pattern is
10238 +** populated in dialog.
10240 +static int isStartPatternElementAvailable(
10241 + DialogStringPatterns *dialogPatterns)
10243 + int i;
10245 + for (i=0; i < dialogPatterns->dspNumberOfPatterns; i++)
10247 + if (dialogPatterns->dspElements[i]->dspeKind == PEK_START)
10248 + return True;
10251 + return False;
10255 +** Read the string pattern fields of the string pattern frame and produce an
10256 +** allocated DialogStringPatternElement structure reflecting the contents.
10257 +** Pop up dialogs telling the user what's wrong (Passing "silent" as True,
10258 +** suppresses these dialogs).
10259 +** Returns NULL on error.
10261 +static DialogStringPatternElement *readStringPatternFrameFields(int silent)
10263 + char *stringPatText;
10264 + DialogStringPatternElement *newPatElement;
10265 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
10267 + if (isRelatedToGroup)
10269 + stringPatText = getSelectedSubPatternName();
10270 + if (strcmp(stringPatText, SPNM_NONE_SELECTED) == 0)
10272 + return NULL;
10275 + stringPatText = XtNewString(stringPatText);
10277 + else
10279 + stringPatText =
10280 + XmTextGetString(MatchPatternDialog.mpdStringPatternW);
10282 + if (stringPatText == NULL)
10284 + return NULL;
10286 + else if (*stringPatText == '\0')
10288 + if (!silent)
10290 + DialogF(
10291 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10292 + "String Pattern",
10293 + "Please specify string\npattern content",
10294 + "OK");
10295 + XmProcessTraversal(MatchPatternDialog.mpdStringPatternW, XmTRAVERSE_CURRENT);
10297 + XtFree(stringPatText);
10298 + return NULL;
10302 + newPatElement = (DialogStringPatternElement *)XtMalloc(sizeof(DialogStringPatternElement));
10304 + newPatElement->dspeText = stringPatText;
10306 + if (isRelatedToGroup)
10308 + newPatElement->dspeKind = PEK_START;
10309 + newPatElement->dspeWordBoundary = PWB_NONE;
10310 + newPatElement->dspeCaseInsensitive = False;
10311 + newPatElement->dspeRegularExpression = False;
10313 + else
10315 + newPatElement->dspeRegularExpression =
10316 + XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
10318 + if (XmToggleButtonGetState(MatchPatternDialog.sptStartW))
10319 + newPatElement->dspeKind = PEK_START;
10320 + else if (XmToggleButtonGetState(MatchPatternDialog.sptMiddleW))
10321 + newPatElement->dspeKind = PEK_MIDDLE;
10322 + else
10323 + newPatElement->dspeKind = PEK_END;
10325 + if (newPatElement->dspeRegularExpression)
10326 + newPatElement->dspeWordBoundary = PWB_NONE;
10327 + else if (XmToggleButtonGetState(MatchPatternDialog.wbbBothW))
10328 + newPatElement->dspeWordBoundary = PWB_BOTH;
10329 + else if (XmToggleButtonGetState(MatchPatternDialog.wbbLeftW))
10330 + newPatElement->dspeWordBoundary = PWB_LEFT;
10331 + else if (XmToggleButtonGetState(MatchPatternDialog.wbbRightW))
10332 + newPatElement->dspeWordBoundary = PWB_RIGHT;
10333 + else
10334 + newPatElement->dspeWordBoundary = PWB_NONE;
10336 + newPatElement->dspeCaseInsensitive =
10337 + !XmToggleButtonGetState(MatchPatternDialog.sabCaseSensitiveW);
10340 + return newPatElement;
10344 +** Returns true if the pattern fields of the matching pattern dialog are set to
10345 +** the default ("New" pattern) state.
10347 +static int matchPatternDialogEmpty(void)
10349 + return
10350 + TextWidgetIsBlank(MatchPatternDialog.mpdMatchPatternNameW) &&
10351 + XmToggleButtonGetState(MatchPatternDialog.mptbIndividualW) &&
10352 + XmToggleButtonGetState(MatchPatternDialog.gabFlashW) &&
10353 + XmToggleButtonGetState(MatchPatternDialog.gabSyntaxBasedW) &&
10354 + stringPatternFrameEmpty();
10358 +** Returns true if the string pattern frame of the matching pattern dialog is set to
10359 +** the default state.
10361 +static int stringPatternFrameEmpty(void)
10363 + return
10364 + stringPatternFieldsEmpty(False) &&
10365 + MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0;
10369 +** Returns true if the string pattern fields of the string pattern frame are set to
10370 +** the default state.
10372 +static int stringPatternFieldsEmpty(
10373 + int strPatIsRelatedToGroup)
10375 + if (strPatIsRelatedToGroup)
10377 + return(
10378 + strcmp( getSelectedSubPatternName(), SPNM_NONE_SELECTED ) == 0);
10380 + else
10382 + return
10383 + TextWidgetIsBlank(MatchPatternDialog.mpdStringPatternW) &&
10384 + XmToggleButtonGetState(MatchPatternDialog.wbbBothW) &&
10385 + XmToggleButtonGetState(MatchPatternDialog.sabCaseSensitiveW) &&
10386 + !XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
10391 +** Get the current content of the matching pattern dialog.
10392 +** If the matching pattern is o.k., then update & apply it
10393 +** to any window which is currently using the matching pattern.
10394 +** If it's bad, then only report it.
10396 +static int getAndUpdateStringMatchTable(void)
10398 + StringMatchTable *newTable;
10399 + DMPTranslationResult translResult;
10401 + /*
10402 + * Get the current information displayed by the dialog. If it's bad,
10403 + * report it to the user & return.
10404 + */
10405 + newTable = getDialogStringMatchTable(&translResult);
10407 + if (newTable == NULL && translResult != DMPTR_EMPTY)
10409 + DialogF(
10410 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10411 + "Incomplete Matching Patterns for Language Mode",
10412 + "Incomplete matching patterns for language mode '%s'.\n"
10413 + "Please complete them first",
10414 + "OK",
10415 + MatchPatternDialog.mpdLangModeName);
10417 + return False;
10420 + /*
10421 + * change the matching pattern
10422 + */
10423 + updateStringMatchTable( newTable );
10425 + return True;
10429 +** Update the matching pattern set being edited in the matching pattern dialog
10430 +** with the information that the dialog is currently displaying, and
10431 +** apply changes to any window which is currently using the matching pattern.
10433 +static void updateStringMatchTable(
10434 + StringMatchTable *newTable)
10436 + WindowInfo *window;
10437 + int i;
10439 + /*
10440 + * Find the matching pattern being modified
10441 + */
10442 + for (i=0; i<NbrMatchTables; i++)
10444 + if (!strcmp(MatchPatternDialog.mpdLangModeName, MatchTables[i]->smtLanguageMode))
10446 + /*
10447 + * replace existing matching pattern
10448 + */
10449 + freeStringMatchTable(MatchTables[i]);
10450 + MatchTables[i] = newTable;
10451 + break;
10455 + if (i == NbrMatchTables)
10457 + /*
10458 + * new match table for language mode -> add it to end
10459 + */
10460 + MatchTables[NbrMatchTables++] = newTable;
10463 + /*
10464 + * Find windows that are currently using this matching pattern set and
10465 + * update this windows
10466 + */
10467 + for (window=WindowList; window!=NULL; window=window->next)
10469 + if ((window->languageMode == PLAIN_LANGUAGE_MODE &&
10470 + !strcmp(PLAIN_LM_STRING, newTable->smtLanguageMode)) ||
10471 + (window->languageMode != PLAIN_LANGUAGE_MODE &&
10472 + !strcmp(LanguageModeName(window->languageMode), newTable->smtLanguageMode)))
10474 + window->stringMatchTable = newTable;
10478 + /*
10479 + * Note that preferences have been changed
10480 + */
10481 + MarkPrefsChanged();
10484 +static StringMatchTable *getDialogStringMatchTable(
10485 + DMPTranslationResult *result)
10487 + int matchPatListIdx =
10488 + ManagedListSelectedIndex(MatchPatternDialog.mpdMatchPatternNamesListW);
10489 + int stringPatListIdx =
10490 + ManagedListSelectedIndex(MatchPatternDialog.mpdStringPatternsListW);
10492 + /*
10493 + * Get the current content of the matching pattern dialog fields
10494 + */
10495 + if (!UpdateManagedList(MatchPatternDialog.mpdStringPatternsListW, True))
10497 + *result = DMPTR_INCOMPLETE;
10499 + return NULL;
10502 + if (!UpdateManagedList(MatchPatternDialog.mpdMatchPatternNamesListW, True))
10504 + *result = DMPTR_INCOMPLETE;
10506 + return NULL;
10509 + SelectManagedListItem(MatchPatternDialog.mpdMatchPatternNamesListW, matchPatListIdx);
10510 + SelectManagedListItem(MatchPatternDialog.mpdStringPatternsListW, stringPatListIdx);
10512 + /*
10513 + * Translate dialog match table to string match table
10514 + */
10515 + return translateDialogStringMatchTable(&MatchPatternDialog.mpdTable, result);
10518 +static StringMatchTable *translateDialogStringMatchTable(
10519 + DialogMatchPatternInfo *dialogTable,
10520 + DMPTranslationResult *result)
10522 + ReadMatchPatternInfo readPatInfo;
10523 + DialogMatchPatternSequenceElement *seq;
10524 + MatchPatternTableElement *newPatElement;
10525 + MatchPatternGroupElement *newGroupElement;
10526 + char *errMsg;
10527 + ErrorInfo errInfo;
10528 + int i;
10530 + initErrorInfo(&errInfo);
10532 + readPatInfo.rmpiNbrOfElements = 0;
10533 + readPatInfo.rmpiNbrOfGroups = 0;
10534 + readPatInfo.rmpiNbrOfSeqElements = 0;
10535 + readPatInfo.rmpiAllPatRE = NULL;
10536 + readPatInfo.rmpiFlashPatRE = NULL;
10538 + /*
10539 + * if no dialog patterns are defined, return "empty" table
10540 + */
10541 + if (dialogTable->dmpiNbrOfSeqElements == 0)
10543 + *result = DMPTR_EMPTY;
10545 + return createStringMatchTable(
10546 + &readPatInfo,
10547 + XtNewString(MatchPatternDialog.mpdLangModeName));
10550 + /*
10551 + * translate dialog matching pattern elements
10552 + */
10553 + for (i=0; i < dialogTable->dmpiNbrOfSeqElements; i++)
10555 + seq = dialogTable->dmpiSequence[i];
10557 + if (seq->dmpseType == MPT_GROUP)
10559 + newGroupElement =
10560 + translateDialogMatchPatternGroupElement(
10561 + &readPatInfo,
10562 + (DialogMatchPatternGroupElement *)seq->dmpsePtr);
10564 + if (newGroupElement == NULL)
10566 + freeReadMatchPatternInfo(&readPatInfo);
10568 + *result = DMPTR_INCOMPLETE;
10570 + return NULL;
10573 + readPatInfo.rmpiGroup[readPatInfo.rmpiNbrOfGroups ++] =
10574 + newGroupElement;
10576 + recordPatternSequence(
10577 + &readPatInfo,
10578 + seq->dmpseName,
10579 + seq->dmpseType,
10580 + readPatInfo.rmpiNbrOfGroups-1 );
10582 + else
10584 + newPatElement =
10585 + translateDialogMatchPatternTableElement(
10586 + (DialogMatchPatternTableElement *)seq->dmpsePtr);
10588 + newPatElement->mpteIndex = readPatInfo.rmpiNbrOfElements;
10590 + readPatInfo.rmpiElement[readPatInfo.rmpiNbrOfElements ++] =
10591 + newPatElement;
10593 + if (newPatElement->mpteType == MPT_INDIVIDUAL)
10595 + if (!assignIndividualGroup(&readPatInfo, &errMsg, newPatElement))
10597 + DialogF(
10598 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10599 + "Assign reg. exp.",
10600 + "%s\n(Pattern: '%s')",
10601 + "OK",
10602 + errMsg,
10603 + newPatElement->mpteName);
10605 + freeReadMatchPatternInfo(&readPatInfo);
10607 + *result = DMPTR_INCOMPLETE;
10609 + return NULL;
10613 + treatDuplicatedMTEntries(readPatInfo.rmpiElement, readPatInfo.rmpiNbrOfElements);
10615 + recordPatternSequence(
10616 + &readPatInfo,
10617 + seq->dmpseName,
10618 + seq->dmpseType,
10619 + newPatElement->mpteIndex );
10623 + /*
10624 + * compile reg. expressions of "read" patterns
10625 + */
10626 + if (createRegExpOfPatterns( &readPatInfo, &errInfo ))
10628 + errInfo.eiLanguageMode = XtNewString(MatchPatternDialog.mpdLangModeName);
10629 + dialogMatchingPatternSetError(
10630 + "Assign all patterns reg. exp.",
10631 + &errInfo);
10633 + freeReadMatchPatternInfo(&readPatInfo);
10635 + *result = DMPTR_INCOMPLETE;
10637 + return NULL;
10640 + *result = DMPTR_OK;
10642 + return createStringMatchTable(
10643 + &readPatInfo,
10644 + XtNewString(MatchPatternDialog.mpdLangModeName));
10647 +static MatchPatternTableElement *translateDialogMatchPatternTableElement(
10648 + DialogMatchPatternTableElement *dialogElement)
10650 + MatchPatternTableElement *newElement;
10652 + newElement =
10653 + (MatchPatternTableElement *)XtMalloc(sizeof(MatchPatternTableElement));
10655 + newElement->mpteName = XtNewString(dialogElement->dmpteName);
10656 + newElement->mpteIndex = NO_ELEMENT_IDX;
10657 + newElement->mpteType = dialogElement->dmpteType;
10658 + newElement->mpteGroup = NO_GROUP_IDX;
10660 + translateDialogPatterns(&dialogElement->dmptePatterns, newElement);
10662 + newElement->mpteSkipBtwnStartEnd = dialogElement->dmpteSkipBtwnStartEnd;
10663 + newElement->mpteFlash = dialogElement->dmpteFlash;
10664 + newElement->mpteIgnoreHighLightInfo = dialogElement->dmpteIgnoreHighLightInfo;
10665 + newElement->mpteStartEndRE = NULL;
10667 + initGlobalBackRefList( newElement->mpteGlobalBackRef );
10669 + return newElement;
10672 +static void translateDialogPatterns(
10673 + DialogStringPatterns *dialogPatterns,
10674 + MatchPatternTableElement *newElement)
10676 + int sizeOfPat;
10677 + int i;
10679 + /*
10680 + * allocate memory for patterns
10681 + */
10682 + newElement->mpteAll.pesNumberOfPattern = dialogPatterns->dspNumberOfPatterns;
10684 + sizeOfPat =
10685 + sizeof(PatternElement *) * dialogPatterns->dspNumberOfPatterns;
10687 + newElement->mpteAll.pesPattern = (PatternElement **)XtMalloc(sizeOfPat);
10689 + /*
10690 + * assign dialog patterns to patterns of MatchPatternTableElement
10691 + */
10692 + for (i=0; i < dialogPatterns->dspNumberOfPatterns; i++)
10694 + newElement->mpteAll.pesPattern[i] =
10695 + createPatternElement(
10696 + XtNewString(dialogPatterns->dspElements[i]->dspeText),
10697 + dialogPatterns->dspElements[i]->dspeKind,
10698 + dialogPatterns->dspElements[i]->dspeWordBoundary,
10699 + dialogPatterns->dspElements[i]->dspeCaseInsensitive,
10700 + dialogPatterns->dspElements[i]->dspeRegularExpression);
10702 + newElement->mpteAll.pesPattern[i]->peIndex = i;
10705 + /*
10706 + * sort pattern elements into start, middle & end arrays
10707 + */
10708 + sortDialogPatternElementSet( &newElement->mpteAll, newElement );
10710 + /*
10711 + * determine mono pattern
10712 + */
10713 + if (newElement->mpteEnd.pesNumberOfPattern == 0)
10715 + newElement->mpteIsMonoPattern = True;
10717 + copyPatternSet( &newElement->mpteStart, &newElement->mpteEnd );
10719 + else
10721 + newElement->mpteIsMonoPattern = False;
10726 + * Sort dialog pattern element set into start, middle & end arrays.
10727 + */
10728 +static void sortDialogPatternElementSet(
10729 + PatternElementSet *allPat,
10730 + MatchPatternTableElement *result)
10732 + int sizeOfPat;
10734 + /*
10735 + * count number of start, middle & end pattern elements
10736 + */
10737 + countPatternElementKind( allPat, result );
10739 + /*
10740 + * allocate pattern elements
10741 + */
10742 + sizeOfPat = sizeof(PatternElement *) * result->mpteStart.pesNumberOfPattern;
10743 + result->mpteStart.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
10745 + if (result->mpteMiddle.pesNumberOfPattern != 0)
10747 + sizeOfPat = sizeof(PatternElement *) * result->mpteMiddle.pesNumberOfPattern;
10748 + result->mpteMiddle.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
10751 + if (result->mpteEnd.pesNumberOfPattern != 0)
10753 + sizeOfPat = sizeof(PatternElement *) * result->mpteEnd.pesNumberOfPattern;
10754 + result->mpteEnd.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
10757 + /*
10758 + * sort pattern elements into start, middle & end arrays
10759 + */
10760 + sortPatternElementSet( allPat, result );
10763 +static MatchPatternGroupElement *translateDialogMatchPatternGroupElement(
10764 + ReadMatchPatternInfo *info,
10765 + DialogMatchPatternGroupElement *dialogGroup)
10767 + int i;
10768 + int error = False;
10769 + MatchPatternTableElement *subPatElement;
10770 + int sizeOfIds;
10771 + MatchPatternGroupElement *group;
10773 + /*
10774 + * Allocate memory for the matching pattern group. Copy name & number of
10775 + * sub patterns.
10776 + */
10777 + group =
10778 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
10780 + group->mpgeName = XtNewString(dialogGroup->dmpgeName);
10781 + group->mpgeNumberOfSubPatterns = dialogGroup->dmpgeNumberOfSubPatterns;
10782 + group->mpgeKeywordRE = NULL;
10784 + /*
10785 + * Allocate memory for the sub-matching pattern IDs
10786 + */
10787 + sizeOfIds = sizeof(char *) * group->mpgeNumberOfSubPatterns;
10788 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeOfIds );
10790 + for (i=0; i < group->mpgeNumberOfSubPatterns; i ++)
10792 + /*
10793 + * Remember sub-matching pattern ID
10794 + */
10795 + group->mpgeSubPatternIds[i] = XtNewString(dialogGroup->dmpgeSubPatternIds[i]);
10797 + /*
10798 + * Assign the index of this group to the sub-matching pattern
10799 + * if no group index was assigned before.
10800 + */
10801 + subPatElement =
10802 + getPatternOfName( info, dialogGroup->dmpgeSubPatternIds[i]);
10804 + if (subPatElement == NULL)
10806 + DialogF(
10807 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10808 + "Group Compilation",
10809 + "Group '%s':\nsub-matching pattern '%s' not defined before",
10810 + "OK",
10811 + group->mpgeName,
10812 + dialogGroup->dmpgeSubPatternIds[i]);
10814 + error = True;
10816 + else
10818 + if (subPatElement->mpteGroup == NO_GROUP_IDX)
10820 + subPatElement->mpteGroup = info->rmpiNbrOfGroups;
10825 + if (error)
10827 + freeMatchPatternGroupElement(group);
10829 + return NULL;
10832 + return group;
10835 +static int stringMatchTableDiffer(
10836 + StringMatchTable *oldTable,
10837 + StringMatchTable *newTable)
10839 + int i, j;
10840 + MatchPatternTable *oldPatTab = oldTable->smtAllPatterns;
10841 + MatchPatternTable *newPatTab = newTable->smtAllPatterns;
10842 + MatchPatternTableElement *oldPat;
10843 + MatchPatternTableElement *newPat;
10844 + MatchPatternGroupElement *oldGroup;
10845 + MatchPatternGroupElement *newGroup;
10846 + MatchPatternSequenceElement *oldSeq;
10847 + MatchPatternSequenceElement *newSeq;
10849 + if (oldTable->smtNumberOfSeqElements != newTable->smtNumberOfSeqElements)
10850 + return True;
10852 + for (i=0; i < oldTable->smtNumberOfSeqElements; i++)
10854 + oldSeq = oldTable->smtSequence[i];
10855 + newSeq = newTable->smtSequence[i];
10857 + if (AllocatedStringsDiffer(oldSeq->mpseName, newSeq->mpseName))
10858 + return True;
10859 + if (oldSeq->mpseType != newSeq->mpseType)
10860 + return True;
10862 + if (oldSeq->mpseType == MPT_GROUP)
10864 + oldGroup = oldTable->smtGroups[oldSeq->mpseIndex];
10865 + newGroup = newTable->smtGroups[newSeq->mpseIndex];
10867 + if (AllocatedStringsDiffer(oldGroup->mpgeName, newGroup->mpgeName))
10868 + return True;
10870 + if (oldGroup->mpgeNumberOfSubPatterns != newGroup->mpgeNumberOfSubPatterns)
10871 + return True;
10873 + for (j=0; j < oldGroup->mpgeNumberOfSubPatterns; j++)
10875 + if (AllocatedStringsDiffer(
10876 + oldGroup->mpgeSubPatternIds[j],
10877 + newGroup->mpgeSubPatternIds[j]))
10878 + return True;
10881 + else
10883 + oldPat = oldPatTab->mptElements[oldSeq->mpseIndex];
10884 + newPat = newPatTab->mptElements[newSeq->mpseIndex];
10886 + if (AllocatedStringsDiffer(oldPat->mpteName, newPat->mpteName))
10887 + return True;
10889 + if (oldPat->mpteType != newPat->mpteType)
10890 + return True;
10892 + if (oldPat->mpteGroup != newPat->mpteGroup)
10893 + return True;
10895 + if (oldPat->mpteAll.pesNumberOfPattern != newPat->mpteAll.pesNumberOfPattern)
10896 + return True;
10898 + for (j=0; j < oldPat->mpteAll.pesNumberOfPattern; j ++)
10900 + if (patternElementDiffer(
10901 + oldPat->mpteAll.pesPattern[j], oldPatTab,
10902 + newPat->mpteAll.pesPattern[j], newPatTab ) )
10903 + return True;
10906 + if (oldPat->mpteIsMonoPattern != newPat->mpteIsMonoPattern)
10907 + return True;
10909 + if (oldPat->mpteSkipBtwnStartEnd != newPat->mpteSkipBtwnStartEnd)
10910 + return True;
10912 + if (oldPat->mpteIgnoreHighLightInfo != newPat->mpteIgnoreHighLightInfo)
10913 + return True;
10915 + if (oldPat->mpteFlash != newPat->mpteFlash)
10916 + return True;
10920 + return False;
10923 +static int patternElementDiffer(
10924 + PatternElement *oldPE,
10925 + MatchPatternTable *oldTab,
10926 + PatternElement *newPE,
10927 + MatchPatternTable *newTab)
10929 + StringPattern *oldSP;
10930 + StringPattern *newSP;
10932 + oldSP = GetStringPattern(oldTab, oldPE);
10933 + newSP = GetStringPattern(newTab, newPE);
10935 + if (AllocatedStringsDiffer(oldSP->spText, newSP->spText))
10936 + return True;
10937 + if (AllocatedStringsDiffer(oldSP->spOrigText, newSP->spOrigText))
10938 + return True;
10939 + if (oldPE->peKind != newPE->peKind)
10940 + return True;
10941 + if (oldSP->spWordBoundary != newSP->spWordBoundary)
10942 + return True;
10943 + if (oldSP->spCaseInsensitive != newSP->spCaseInsensitive)
10944 + return True;
10945 + if (oldSP->spRegularExpression != newSP->spRegularExpression)
10946 + return True;
10948 + return False;
10951 +static DialogMatchPatternGroupElement *getDialogGroupUsingMatchPattern(
10952 + char *matchPatternName)
10954 + DialogMatchPatternSequenceElement *seq;
10955 + DialogMatchPatternGroupElement *group;
10956 + int i, j;
10958 + for (i=0; i < MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i ++)
10960 + seq = MatchPatternDialog.mpdTable.dmpiSequence[i];
10962 + if (seq->dmpseType == MPT_GROUP)
10964 + group = (DialogMatchPatternGroupElement *)seq->dmpsePtr;
10966 + for (j=0; j < group->dmpgeNumberOfSubPatterns; j ++)
10968 + if (strcmp(group->dmpgeSubPatternIds[j], matchPatternName) == 0)
10969 + return group;
10974 + return NULL;
10977 +static void removeMatchPatternFromGroup(
10978 + char *matchPatternName,
10979 + DialogMatchPatternGroupElement *group)
10981 + int i;
10983 + for (i=0; i < group->dmpgeNumberOfSubPatterns; i ++)
10985 + if (strcmp(group->dmpgeSubPatternIds[i], matchPatternName) == 0)
10987 + /*
10988 + * remove existing matching pattern name from sub-pattern list
10989 + */
10990 + freeXtPtr((void **)&group->dmpgeSubPatternIds[i]);
10991 + memmove(
10992 + &group->dmpgeSubPatternIds[i],
10993 + &group->dmpgeSubPatternIds[i+1],
10994 + (group->dmpgeNumberOfSubPatterns-1 - i) * sizeof(char *));
10995 + group->dmpgeNumberOfSubPatterns --;
10997 + return;
11002 +static void removeMatchPatternFromAllGroups(
11003 + char *matchPatternName)
11005 + DialogMatchPatternSequenceElement *seq;
11006 + DialogMatchPatternGroupElement *group;
11007 + int i;
11009 + for (i=0; i < MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i ++)
11011 + seq = MatchPatternDialog.mpdTable.dmpiSequence[i];
11013 + if (seq->dmpseType == MPT_GROUP)
11015 + group = (DialogMatchPatternGroupElement *)seq->dmpsePtr;
11017 + removeMatchPatternFromGroup(matchPatternName, group);
11022 +static void renameMatchPatternInGroup(
11023 + char *oldMatchPatternName,
11024 + char *newMatchPatternName,
11025 + DialogMatchPatternGroupElement *group)
11027 + int i;
11029 + for (i=0; i < group->dmpgeNumberOfSubPatterns; i ++)
11031 + if (strcmp(group->dmpgeSubPatternIds[i], oldMatchPatternName) == 0)
11033 + /*
11034 + * rename existing matching pattern name in sub-pattern list
11035 + */
11036 + freeXtPtr((void **)&group->dmpgeSubPatternIds[i]);
11038 + group->dmpgeSubPatternIds[i] =
11039 + XtNewString(newMatchPatternName);
11041 + return;
11046 +static void renameMatchPatternInAllGroups(
11047 + char *oldMatchPatternName,
11048 + char *newMatchPatternName)
11050 + DialogMatchPatternSequenceElement *seq;
11051 + DialogMatchPatternGroupElement *group;
11052 + int i;
11054 + for (i=0; i < MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i ++)
11056 + seq = MatchPatternDialog.mpdTable.dmpiSequence[i];
11058 + if (seq->dmpseType == MPT_GROUP)
11060 + group = (DialogMatchPatternGroupElement *)seq->dmpsePtr;
11062 + renameMatchPatternInGroup(
11063 + oldMatchPatternName,
11064 + newMatchPatternName,
11065 + group);
11070 +static void freeVariableDialogData(
11071 + int keepLanguageModeName)
11073 + int i;
11075 + if (!keepLanguageModeName)
11076 + freeXtPtr((void **)&MatchPatternDialog.mpdLangModeName);
11078 + for (i=0; i < MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements; i ++)
11080 + freeDialogSequenceElement(
11081 + MatchPatternDialog.mpdTable.dmpiSequence[i] );
11084 + MatchPatternDialog.mpdTable.dmpiNbrOfSeqElements = 0;
11086 + freeDialogStringPatterns(
11087 + &MatchPatternDialog.currentStringPatterns);
11090 +static void initGlobalBackRefList(
11091 + GlobalBackRefElement *list)
11093 + int i;
11095 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
11097 + list[i].gbreDefByStrPat = NULL;
11098 + list[i].gbreRegExpText = NULL;
11102 +static void initStrPatBackRefList(
11103 + StringPattern *strPat)
11105 + int i;
11107 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
11109 + strPat->spOwnGlobalBackRef[i].spbreRegExpText = NULL;
11110 + strPat->spOwnGlobalBackRef[i].spbreLocalBackRefID = NO_LOCAL_BACK_REF_ID;
11112 + strPat->spGlobalToLocalBackRef[i] = NO_LOCAL_BACK_REF_ID;
11116 +static void initErrorInfo(
11117 + ErrorInfo *errInfo)
11119 + errInfo->eiDetail = NULL;
11120 + errInfo->eiLanguageMode = NULL;
11121 + errInfo->eiMPTabElementName = NULL;
11122 + errInfo->eiStringPatText = NULL;
11123 + errInfo->eiRegExpCompileMsg = NULL;
11124 + errInfo->eiBackRefNbr = 0;
11127 +static void freeErrorInfo(
11128 + ErrorInfo *errInfo)
11130 + freeXtPtr((void **)&errInfo->eiLanguageMode);
11131 + freeXtPtr((void **)&errInfo->eiMPTabElementName);
11132 + freeXtPtr((void **)&errInfo->eiStringPatText);
11135 +static void freeXtPtr(void **ptr)
11137 + if (*ptr != NULL)
11139 + XtFree((char *)*ptr);
11140 + *ptr = NULL;
11144 +static void freePtr(void **ptr)
11146 + if (*ptr != NULL)
11148 + free((char *)*ptr);
11149 + *ptr = NULL;
11152 diff --quilt /dev/null new/source/patternMatchData.h
11153 --- /dev/null
11154 +++ new/source/patternMatchData.h
11155 @@ -0,0 +1,24 @@
11156 +/* $Id: patternMatchData.h,v 1.3 2003/12/12 16:45:25 uleh Exp $ */
11158 +#ifndef NEDIT_PATTERNMATCHDATA_H_INCLUDED
11159 +#define NEDIT_PATTERNMATCHDATA_H_INCLUDED
11161 +void *FindStringMatchTable(const char *langModeName);
11163 +void RenameStringMatchTable(const char *oldName, const char *newName);
11165 +void DeleteStringMatchTable(const char *langModeName);
11167 +void AssignStandardStringMatchTable(const char *langModeName);
11169 +int LMHasStringMatchTable(const char *languageMode);
11171 +int LoadMatchPatternString(char *inString);
11173 +char *WriteMatchPatternString(void);
11175 +void EditMatchPatterns(WindowInfo *window);
11177 +void UpdateLanguageModeMenuMatchPattern(void);
11179 +#endif /* NEDIT_PATTERNMATCHDATA_H_INCLUDED */
11180 diff --quilt old/source/preferences.c new/source/preferences.c
11181 --- old/source/preferences.c
11182 +++ new/source/preferences.c
11183 @@ -45,10 +45,14 @@ static const char CVSID[] = "$Id: prefer
11184 #include "regularExp.h"
11185 #include "smartIndent.h"
11186 #include "windowTitle.h"
11187 #include "server.h"
11188 #include "tags.h"
11190 +/* Pattern Match Feature */
11191 +#include "patternMatchData.h"
11193 #include "../util/prefFile.h"
11194 #include "../util/misc.h"
11195 #include "../util/DialogF.h"
11196 #include "../util/managedList.h"
11197 #include "../util/fontsel.h"
11198 @@ -278,11 +282,10 @@ static struct prefData {
11199 int textCols; /* initial window width in characters */
11200 int tabDist; /* number of characters between tab stops */
11201 int emTabDist; /* non-zero tab dist. if emulated tabs are on */
11202 int insertTabs; /* whether to use tabs for padding */
11203 int showMatchingStyle; /* how to flash matching parenthesis */
11204 - int matchSyntaxBased; /* use syntax info to match parenthesis */
11205 int highlightSyntax; /* whether to highlight syntax by default */
11206 int smartTags; /* look for tag in current window first */
11207 int alwaysCheckRelativeTagsSpecs; /* for every new opened file of session */
11208 int stickyCaseSenseBtn; /* whether Case Word Btn is sticky to Regex Btn */
11209 int prefFileRead; /* detects whether a .nedit existed */
11210 @@ -348,10 +351,11 @@ static struct {
11211 char *language;
11212 char *styles;
11213 char *smartIndent;
11214 char *smartIndentCommon;
11215 char *shell;
11216 + char *matchPattern;
11217 } TempStringPrefs;
11219 /* preference descriptions for SavePreferences and RestorePreferences. */
11220 static PrefDescripRec PrefDescrip[] = {
11221 {"fileVersion", "FileVersion" , PREF_STRING, "", PrefData.fileVersion,
11222 @@ -853,10 +857,76 @@ static PrefDescripRec PrefDescrip[] = {
11223 C++:Default\n\
11224 Python:Default\n\
11225 Matlab:Default", &TempStringPrefs.smartIndent, NULL, True},
11226 {"smartIndentInitCommon", "SmartIndentInitCommon", PREF_ALLOC_STRING,
11227 "Default", &TempStringPrefs.smartIndentCommon, NULL, True},
11228 +/* Pattern Match Feature: matchPatterns resource added */
11229 +#ifdef VMS
11230 +/* The VAX compiler can't compile Java-Script's definition in highlightData.c */
11231 + {"matchPatterns", "MatchPatterns", PREF_ALLOC_STRING,
11232 + "PLAIN:Default\n\
11233 + Ada:Default\n\
11234 + Awk:Default\n\
11235 + C++:Default\n\
11236 + C:Default\n\
11237 + CSS:Default\n\
11238 + Csh:Default\n\
11239 + Fortran:Default\n\
11240 + Java:Default\n\
11241 + LaTeX:Default\n\
11242 + Lex:Default\n\
11243 + Makefile:Default\n\
11244 + Matlab:Default\n\
11245 + NEdit Macro:Default\n\
11246 + Pascal:Default\n\
11247 + Perl:Default\n\
11248 + PostScript:Default\n\
11249 + Python:Default\n\
11250 + Regex:Default\n\
11251 + SGML HTML:Default\n\
11252 + SQL:Default\n\
11253 + Sh Ksh Bash:Default\n\
11254 + Tcl:Default\n\
11255 + VHDL:Default\n\
11256 + Verilog:Default\n\
11257 + XML:Default\n\
11258 + X Resources:Default\n\
11259 + Yacc:Default\n",
11260 + &TempStringPrefs.matchPattern, NULL, True},
11261 +#else
11262 + {"matchPatterns", "MatchPatterns", PREF_ALLOC_STRING,
11263 + "PLAIN:Default\n\
11264 + Ada:Default\n\
11265 + Awk:Default\n\
11266 + C++:Default\n\
11267 + C:Default\n\
11268 + CSS:Default\n\
11269 + Csh:Default\n\
11270 + Fortran:Default\n\
11271 + Java:Default\n\
11272 + JavaScript:Default\n\
11273 + LaTeX:Default\n\
11274 + Lex:Default\n\
11275 + Makefile:Default\n\
11276 + Matlab:Default\n\
11277 + NEdit Macro:Default\n\
11278 + Pascal:Default\n\
11279 + Perl:Default\n\
11280 + PostScript:Default\n\
11281 + Python:Default\n\
11282 + Regex:Default\n\
11283 + SGML HTML:Default\n\
11284 + SQL:Default\n\
11285 + Sh Ksh Bash:Default\n\
11286 + Tcl:Default\n\
11287 + VHDL:Default\n\
11288 + Verilog:Default\n\
11289 + XML:Default\n\
11290 + X Resources:Default\n\
11291 + Yacc:Default\n",
11292 + &TempStringPrefs.matchPattern, NULL, True},
11293 +#endif
11294 {"autoWrap", "AutoWrap", PREF_ENUM, "Continuous",
11295 &PrefData.wrapStyle, AutoWrapTypes, True},
11296 {"wrapMargin", "WrapMargin", PREF_INT, "0",
11297 &PrefData.wrapMargin, NULL, True},
11298 {"showWrapMargin", "ShowWrapMargin", PREF_ENUM, "Never",
11299 @@ -869,12 +939,10 @@ static PrefDescripRec PrefDescrip[] = {
11300 &PrefData.openInTab, NULL, True},
11301 {"saveOldVersion", "SaveOldVersion", PREF_BOOLEAN, "False",
11302 &PrefData.saveOldVersion, NULL, True},
11303 {"showMatching", "ShowMatching", PREF_ENUM, "Delimiter",
11304 &PrefData.showMatchingStyle, ShowMatchingTypes, True},
11305 - {"matchSyntaxBased", "MatchSyntaxBased", PREF_BOOLEAN, "True",
11306 - &PrefData.matchSyntaxBased, NULL, True},
11307 {"highlightSyntax", "HighlightSyntax", PREF_BOOLEAN, "True",
11308 &PrefData.highlightSyntax, NULL, True},
11309 {"backlightChars", "BacklightChars", PREF_BOOLEAN, "False",
11310 &PrefData.backlightChars, NULL, True},
11311 {"backlightCharTypes", "BacklightCharTypes", PREF_ALLOC_STRING,
11312 @@ -1243,10 +1311,11 @@ static void lmDestroyCB(Widget w, XtPoin
11313 static void lmOkCB(Widget w, XtPointer clientData, XtPointer callData);
11314 static void lmApplyCB(Widget w, XtPointer clientData, XtPointer callData);
11315 static void lmCloseCB(Widget w, XtPointer clientData, XtPointer callData);
11316 static int lmDeleteConfirmCB(int itemIndex, void *cbArg);
11317 static int updateLMList(void);
11318 +static int isOldLanguageMode(const char *lmDialogName, const char *oldModeName);
11319 static languageModeRec *copyLanguageModeRec(languageModeRec *lm);
11320 static void *lmGetDisplayedCB(void *oldItem, int explicitRequest, int *abort,
11321 void *cbArg);
11322 static void lmSetDisplayedCB(void *item, void *cbArg);
11323 static languageModeRec *readLMDialogFields(int silent);
11324 @@ -1425,10 +1494,15 @@ static void translatePrefFormats(int con
11325 if (TempStringPrefs.smartIndentCommon != NULL) {
11326 LoadSmartIndentCommonString(TempStringPrefs.smartIndentCommon);
11327 XtFree(TempStringPrefs.smartIndentCommon);
11328 TempStringPrefs.smartIndentCommon = NULL;
11330 + if (TempStringPrefs.matchPattern != NULL) {
11331 + LoadMatchPatternString(TempStringPrefs.matchPattern);
11332 + XtFree(TempStringPrefs.matchPattern);
11333 + TempStringPrefs.matchPattern = NULL;
11336 /* translate the font names into fontLists suitable for the text widget */
11337 font = XLoadQueryFont(TheDisplay, PrefData.fontString);
11338 PrefData.fontList = font==NULL ? NULL :
11339 XmFontListCreate(font, XmSTRING_DEFAULT_CHARSET);
11340 @@ -1504,10 +1578,11 @@ void SaveNEditPrefs(Widget parent, int q
11341 TempStringPrefs.highlight = WriteHighlightString();
11342 TempStringPrefs.language = writeLanguageModesString();
11343 TempStringPrefs.styles = WriteStylesString();
11344 TempStringPrefs.smartIndent = WriteSmartIndentString();
11345 TempStringPrefs.smartIndentCommon = WriteSmartIndentCommonString();
11346 + TempStringPrefs.matchPattern = WriteMatchPatternString();
11347 strcpy(PrefData.fileVersion, PREF_FILE_VERSION);
11349 if (!SavePreferences(XtDisplay(parent), prefFileName, HeaderText,
11350 PrefDescrip, XtNumber(PrefDescrip)))
11352 @@ -1523,10 +1598,11 @@ void SaveNEditPrefs(Widget parent, int q
11353 XtFree(TempStringPrefs.highlight);
11354 XtFree(TempStringPrefs.language);
11355 XtFree(TempStringPrefs.styles);
11356 XtFree(TempStringPrefs.smartIndent);
11357 XtFree(TempStringPrefs.smartIndentCommon);
11358 + XtFree(TempStringPrefs.matchPattern);
11360 PrefsHaveChanged = False;
11364 @@ -1919,20 +1995,10 @@ int GetPrefShowMatching(void)
11365 if (PrefData.showMatchingStyle >= N_SHOW_MATCHING_STYLES)
11366 PrefData.showMatchingStyle -= N_SHOW_MATCHING_STYLES;
11367 return PrefData.showMatchingStyle;
11370 -void SetPrefMatchSyntaxBased(int state)
11372 - setIntPref(&PrefData.matchSyntaxBased, state);
11375 -int GetPrefMatchSyntaxBased(void)
11377 - return PrefData.matchSyntaxBased;
11380 void SetPrefHighlightSyntax(Boolean state)
11382 setIntPref(&PrefData.highlightSyntax, state);
11385 @@ -3478,10 +3544,25 @@ static int lmDeleteConfirmCB(int itemInd
11386 "Auto Indent -> Program Smart Indent,\n"
11387 "before proceeding here.", "OK");
11388 return False;
11391 + /* Pattern Match Feature: don't allow deletion if data will be lost */
11392 + if (LMHasStringMatchTable(LMDialog.languageModeList[itemIndex]->name))
11394 + DialogF(DF_WARN, LMDialog.shell, 1, "Matching Patterns exist",
11395 + "This language mode has matching patterns\n"
11396 + "defined. Please delete the patterns first,\n"
11397 + "in Preferences -> Default Settings ->\n"
11398 + "Show Matching (..) -> Matching Patterns ..,\n"
11399 + "before proceeding here.", "Dismiss");
11400 + return False;
11403 + /* delete "empty" string match table related to language mode to be deleted */
11404 + DeleteStringMatchTable(LMDialog.languageModeList[itemIndex]->name);
11406 return True;
11410 ** Apply the changes that the user has made in the language modes dialog to the
11411 @@ -3498,19 +3579,19 @@ static int updateLMList(void)
11412 /* Get the current contents of the dialog fields */
11413 if (!UpdateManagedList(LMDialog.managedListW, True))
11414 return False;
11416 /* Fix up language mode indices in all open windows (which may change
11417 - if the currently selected mode is deleted or has changed position),
11418 - and update word delimiters */
11419 + if the currently selected mode is renamed, deleted or has changed
11420 + position), and update word delimiters */
11421 for (window=WindowList; window!=NULL; window=window->next) {
11422 if (window->languageMode != PLAIN_LANGUAGE_MODE) {
11423 oldLanguageMode = window->languageMode;
11424 oldModeName = LanguageModes[window->languageMode]->name;
11425 window->languageMode = PLAIN_LANGUAGE_MODE;
11426 for (i=0; i<LMDialog.nLanguageModes; i++) {
11427 - if (!strcmp(oldModeName, LMDialog.languageModeList[i]->name)) {
11428 + if (isOldLanguageMode(LMDialog.languageModeList[i]->name, oldModeName)) {
11429 newDelimiters = LMDialog.languageModeList[i]->delimiters;
11430 if (newDelimiters == NULL)
11431 newDelimiters = GetPrefDelimiters();
11432 XtVaSetValues(window->textArea, textNwordDelimiters,
11433 newDelimiters, NULL);
11434 @@ -3536,10 +3617,11 @@ static int updateLMList(void)
11435 if (strchr(LMDialog.languageModeList[i]->name, ':') != NULL) {
11436 char *newName = strrchr(LMDialog.languageModeList[i]->name, ':')+1;
11437 *strchr(LMDialog.languageModeList[i]->name, ':') = '\0';
11438 RenameHighlightPattern(LMDialog.languageModeList[i]->name, newName);
11439 RenameSmartIndentMacros(LMDialog.languageModeList[i]->name, newName);
11440 + RenameStringMatchTable(LMDialog.languageModeList[i]->name, newName);
11441 memmove(LMDialog.languageModeList[i]->name, newName,
11442 strlen(newName) + 1);
11443 ChangeManagedListData(LMDialog.managedListW);
11446 @@ -3553,31 +3635,62 @@ static int updateLMList(void)
11448 /* Update user menu info to update language mode dependencies of
11449 user menu items */
11450 UpdateUserMenuInfo();
11452 + /* Pattern Match Feature: assign standard string match table to new
11453 + language modes */
11454 + for (i=0; i<NLanguageModes; i++) {
11455 + if (FindStringMatchTable(LanguageModeName(i)) == NULL)
11456 + AssignStandardStringMatchTable(LanguageModeName(i));
11459 /* Update the menus in the window menu bars and load any needed
11460 - calltips files */
11461 + calltips files and reassign string match tables */
11462 for (window=WindowList; window!=NULL; window=window->next) {
11463 updateLanguageModeSubmenu(window);
11464 if (window->languageMode != PLAIN_LANGUAGE_MODE &&
11465 LanguageModes[window->languageMode]->defTipsFile != NULL)
11466 AddTagsFile(LanguageModes[window->languageMode]->defTipsFile, TIP);
11468 + window->stringMatchTable =
11469 + FindStringMatchTable(LanguageModeName(window->languageMode));
11471 /* cache user menus: Rebuild all user menus of this window */
11472 RebuildAllMenus(window);
11475 /* If a syntax highlighting dialog is up, update its menu */
11476 UpdateLanguageModeMenu();
11477 /* The same for the smart indent macro dialog */
11478 UpdateLangModeMenuSmartIndent();
11479 + /* The same for the match pattern dialog */
11480 + UpdateLanguageModeMenuMatchPattern();
11481 /* Note that preferences have been changed */
11482 MarkPrefsChanged();
11484 return True;
11488 +** Returns true, if the given old language mode name matches the
11489 +** given (new) language mode dialog name.
11491 +static int isOldLanguageMode(const char *lmDialogName, const char *oldModeName)
11493 + char *c = strchr(lmDialogName, ':');
11494 + int isOldMode = !strcmp(oldModeName, lmDialogName);
11496 + if (!isOldMode && c != NULL) {
11497 + *c = '\0';
11498 + isOldMode = !strcmp(lmDialogName, oldModeName);
11499 + *c = ':';
11502 + return isOldMode;
11505 static void *lmGetDisplayedCB(void *oldItem, int explicitRequest, int *abort,
11506 void *cbArg)
11508 languageModeRec *lm, *oldLM = (languageModeRec *)oldItem;
11509 char *tempName;
11510 @@ -4567,10 +4680,14 @@ static void reapplyLanguageMode(WindowIn
11511 /* Decref oldMode's default calltips file if needed */
11512 if (oldMode != PLAIN_LANGUAGE_MODE && LanguageModes[oldMode]->defTipsFile) {
11513 DeleteTagsFile( LanguageModes[oldMode]->defTipsFile, TIP, False );
11516 + /* Pattern Match Feature: Assign the match pattern related to
11517 + the language mode */
11518 + window->stringMatchTable = FindStringMatchTable(LanguageModeName(mode));
11520 /* Set delimiters for all text widgets */
11521 if (mode == PLAIN_LANGUAGE_MODE || LanguageModes[mode]->delimiters == NULL)
11522 delimiters = GetPrefDelimiters();
11523 else
11524 delimiters = LanguageModes[mode]->delimiters;
11525 @@ -5184,18 +5301,35 @@ char *ReadSymbolicFieldTextWidget(Widget
11529 ** Create a pulldown menu pane with the names of the current language modes.
11530 ** XmNuserData for each item contains the language mode name.
11531 +** Pattern Match Feature: if "includePlain" is set, then 1st menu entry
11532 +** holds "PLAIN".
11534 -Widget CreateLanguageModeMenu(Widget parent, XtCallbackProc cbProc, void *cbArg)
11535 +Widget CreateLanguageModeMenu(
11536 + Widget parent,
11537 + XtCallbackProc cbProc,
11538 + void *cbArg,
11539 + int includePlain)
11541 Widget menu, btn;
11542 int i;
11543 XmString s1;
11545 menu = CreatePulldownMenu(parent, "languageModes", NULL, 0);
11547 + if (includePlain) {
11548 + btn = XtVaCreateManagedWidget("languageMode", xmPushButtonGadgetClass,
11549 + menu,
11550 + XmNlabelString, s1=XmStringCreateSimple("PLAIN"),
11551 + XmNmarginHeight, 0,
11552 + XmNuserData, (void *)"PLAIN", NULL);
11553 + XmStringFree(s1);
11554 + XtAddCallback(btn, XmNactivateCallback, cbProc, cbArg);
11557 for (i=0; i<NLanguageModes; i++) {
11558 btn = XtVaCreateManagedWidget("languageMode", xmPushButtonGadgetClass,
11559 menu,
11560 XmNlabelString, s1=XmStringCreateSimple(LanguageModes[i]->name),
11561 XmNmarginHeight, 0,
11562 diff --quilt old/source/preferences.h new/source/preferences.h
11563 --- old/source/preferences.h
11564 +++ new/source/preferences.h
11565 @@ -109,12 +109,10 @@ void SetPrefEmTabDist(int tabDist);
11566 int GetPrefEmTabDist(int langMode);
11567 void SetPrefInsertTabs(int state);
11568 int GetPrefInsertTabs(void);
11569 void SetPrefShowMatching(int state);
11570 int GetPrefShowMatching(void);
11571 -void SetPrefMatchSyntaxBased(int state);
11572 -int GetPrefMatchSyntaxBased(void);
11573 void SetPrefHighlightSyntax(Boolean state);
11574 Boolean GetPrefHighlightSyntax(void);
11575 void SetPrefBacklightChars(int state);
11576 int GetPrefBacklightChars(void);
11577 void SetPrefBacklightCharTypes(char *types);
11578 @@ -190,11 +188,11 @@ int AllocatedStringsDiffer(const char *s
11579 void SetLanguageMode(WindowInfo *window, int mode, int forceNewDefaults);
11580 int FindLanguageMode(const char *languageName);
11581 void UnloadLanguageModeTipsFile(WindowInfo *window);
11582 void DetermineLanguageMode(WindowInfo *window, int forceNewDefaults);
11583 Widget CreateLanguageModeMenu(Widget parent, XtCallbackProc cbProc,
11584 - void *cbArg);
11585 + void *cbArg, int includePlain);
11586 void SetLangModeMenu(Widget optMenu, const char *modeName);
11587 void CreateLanguageModeSubMenu(WindowInfo* window, const Widget parent,
11588 const char* name, const char* label, const char mnemonic);
11589 void SetPrefFindReplaceUsesSelection(int state);
11590 int GetPrefFindReplaceUsesSelection(void);
11591 diff --quilt old/source/search.c new/source/search.c
11592 --- old/source/search.c
11593 +++ new/source/search.c
11594 @@ -83,10 +83,11 @@ static const char CVSID[] = "$Id: search
11596 #ifdef HAVE_DEBUG_H
11597 #include "../debug.h"
11598 #endif
11600 +#include "patternMatch.h"
11602 int NHist = 0;
11604 typedef struct _SelectionInfo {
11605 int done;
11606 @@ -171,10 +172,11 @@ static void freeWritableWindowsCB(Widget
11607 XmAnyCallbackStruct *callData);
11608 static void checkMultiReplaceListForDoomedW(WindowInfo* window,
11609 WindowInfo* doomedWindow);
11610 static void removeDoomedWindowFromList(WindowInfo* window, int index);
11611 static void unmanageReplaceDialogs(const WindowInfo *window);
11612 +static int getPosForMatchingCharacter(WindowInfo *window);
11613 static void flashTimeoutProc(XtPointer clientData, XtIntervalId *id);
11614 static void eraseFlash(WindowInfo *window);
11615 static int getReplaceDlogInfo(WindowInfo *window, int *direction,
11616 char *searchString, char *replaceString, int *searchType);
11617 static int getFindDlogInfo(WindowInfo *window, int *direction,
11618 @@ -211,13 +213,10 @@ static void downCaseString(char *outStri
11619 static void resetFindTabGroup(WindowInfo *window);
11620 static void resetReplaceTabGroup(WindowInfo *window);
11621 static int searchMatchesSelection(WindowInfo *window, const char *searchString,
11622 int searchType, int *left, int *right, int *searchExtentBW,
11623 int *searchExtentFW);
11624 -static int findMatchingChar(WindowInfo *window, char toMatch,
11625 - void *toMatchStyle, int charPos, int startLimit, int endLimit,
11626 - int *matchPos);
11627 static Boolean replaceUsingRE(const char* searchStr, const char* replaceStr,
11628 const char* sourceStr, int beginPos, char* destStr, int maxDestLen,
11629 int prevChar, const char* delimiters, int defaultFlags);
11630 static void saveSearchHistory(const char *searchString,
11631 const char *replaceString, int searchType, int isIncremental);
11632 @@ -251,28 +250,10 @@ typedef struct _charMatchTable {
11633 char c;
11634 char match;
11635 char direction;
11636 } charMatchTable;
11638 -#define N_MATCH_CHARS 13
11639 -#define N_FLASH_CHARS 6
11640 -static charMatchTable MatchingChars[N_MATCH_CHARS] = {
11641 - {'{', '}', SEARCH_FORWARD},
11642 - {'}', '{', SEARCH_BACKWARD},
11643 - {'(', ')', SEARCH_FORWARD},
11644 - {')', '(', SEARCH_BACKWARD},
11645 - {'[', ']', SEARCH_FORWARD},
11646 - {']', '[', SEARCH_BACKWARD},
11647 - {'<', '>', SEARCH_FORWARD},
11648 - {'>', '<', SEARCH_BACKWARD},
11649 - {'/', '/', SEARCH_FORWARD},
11650 - {'"', '"', SEARCH_FORWARD},
11651 - {'\'', '\'', SEARCH_FORWARD},
11652 - {'`', '`', SEARCH_FORWARD},
11653 - {'\\', '\\', SEARCH_FORWARD},
11657 ** Definitions for the search method strings, used as arguments for
11658 ** macro search subroutines and search action routines
11660 static char *searchTypeStrings[] = {
11661 @@ -3336,22 +3317,22 @@ static void iSearchTextKeyEH(Widget w, W
11662 XmTextSetInsertionPosition(window->iSearchText,
11663 XmTextGetLastPosition(window->iSearchText));
11667 -** Check the character before the insertion cursor of textW and flash
11668 -** matching parenthesis, brackets, or braces, by temporarily highlighting
11669 -** the matching character (a timer procedure is scheduled for removing the
11670 -** highlights)
11671 +** Check the characters before the insertion cursor of textW and flash
11672 +** matching patterns (parenthesis e.g. brackets, braces ..) by temporarily
11673 +** highlighting matching characters (a timer procedure is scheduled for
11674 +** removing the highlights)
11676 void FlashMatching(WindowInfo *window, Widget textW)
11678 - char c;
11679 - void *style;
11680 - int pos, matchIndex;
11681 - int startPos, endPos, searchPos, matchPos;
11682 + int pos;
11683 + int direction;
11684 + int startPos, endPos, matchPos, matchLen;
11685 int constrain;
11686 + MatchingType matchingType;
11688 /* if a marker is already drawn, erase it and cancel the timeout */
11689 if (window->flashTimeoutID != 0) {
11690 eraseFlash(window);
11691 XtRemoveTimeOut(window->flashTimeoutID);
11692 @@ -3365,52 +3346,47 @@ void FlashMatching(WindowInfo *window, W
11694 /* don't flash matching characters if there's a selection */
11695 if (window->buffer->primary.selected)
11696 return;
11698 - /* get the character to match and the position to start from */
11699 - pos = TextGetCursorPos(textW) - 1;
11700 + /* get the position to start from */
11701 + pos = TextGetCursorPos(textW);
11702 if (pos < 0)
11703 return;
11704 - c = BufGetCharacter(window->buffer, pos);
11705 - style = GetHighlightInfo(window, pos);
11707 - /* is the character one we want to flash? */
11708 - for (matchIndex = 0; matchIndex<N_FLASH_CHARS; matchIndex++) {
11709 - if (MatchingChars[matchIndex].c == c)
11710 - break;
11712 - if (matchIndex == N_FLASH_CHARS)
11713 - return;
11715 /* constrain the search to visible text only when in single-pane mode
11716 AND using delimiter flashing (otherwise search the whole buffer) */
11717 constrain = ((window->nPanes == 0) &&
11718 (window->showMatchingStyle == FLASH_DELIMIT));
11720 - if (MatchingChars[matchIndex].direction == SEARCH_BACKWARD) {
11721 startPos = constrain ? TextFirstVisiblePos(textW) : 0;
11722 - endPos = pos;
11723 - searchPos = endPos;
11724 - } else {
11725 - startPos = pos;
11726 endPos = constrain ? TextLastVisiblePos(textW) :
11727 window->buffer->length;
11728 - searchPos = startPos;
11730 + /* cursor pos. must be between start / end pos. */
11731 + if (pos < startPos || pos > endPos)
11732 + return;
11734 + /* Pattern Match Feature: determine matching type
11735 + (here: flash delimiter or range) */
11736 + if (window->showMatchingStyle == FLASH_DELIMIT) {
11737 + matchingType = MT_FLASH_DELIMIT;
11738 + } else {
11739 + matchingType = MT_FLASH_RANGE;
11742 - /* do the search */
11743 - if (!findMatchingChar(window, c, style, searchPos, startPos, endPos,
11744 - &matchPos))
11745 + /* Pattern Match Feature: do the search */
11746 + if (!FindMatchingString(window, matchingType, &pos, startPos, endPos,
11747 + &matchPos, &matchLen, &direction))
11748 return;
11750 if (window->showMatchingStyle == FLASH_DELIMIT) {
11751 - /* Highlight either the matching character ... */
11752 - BufHighlight(window->buffer, matchPos, matchPos+1);
11753 + /* Highlight either the matching characters ... */
11754 + BufHighlight(window->buffer, matchPos, matchPos + matchLen);
11755 } else {
11756 /* ... or the whole range. */
11757 - if (MatchingChars[matchIndex].direction == SEARCH_BACKWARD) {
11758 + if (direction == SEARCH_BACKWARD) {
11759 BufHighlight(window->buffer, matchPos, pos+1);
11760 } else {
11761 BufHighlight(window->buffer, matchPos+1, pos);
11764 @@ -3420,42 +3396,50 @@ void FlashMatching(WindowInfo *window, W
11765 XtWidgetToApplicationContext(window->shell), 1500,
11766 flashTimeoutProc, window);
11767 window->flashPos = matchPos;
11770 -void SelectToMatchingCharacter(WindowInfo *window)
11772 +** Pattern Match Feature:
11773 +** get position of the character to match from the selection, or
11774 +** the character before the insert point if nothing is selected.
11777 +static int getPosForMatchingCharacter(WindowInfo *window)
11779 + int pos;
11780 int selStart, selEnd;
11781 - int startPos, endPos, matchPos;
11782 textBuffer *buf = window->buffer;
11784 - /* get the character to match and its position from the selection, or
11785 - the character before the insert point if nothing is selected.
11786 - Give up if too many characters are selected */
11787 - if (!GetSimpleSelection(buf, &selStart, &selEnd)) {
11788 - selEnd = TextGetCursorPos(window->lastFocus);
11789 - if (window->overstrike)
11790 - selEnd += 1;
11791 - selStart = selEnd - 1;
11792 - if (selStart < 0) {
11793 - XBell(TheDisplay, 0);
11794 - return;
11796 + if (GetSimpleSelection(buf, &selStart, &selEnd)) {
11797 + pos = selEnd;
11799 - if ((selEnd - selStart) != 1) {
11800 - XBell(TheDisplay, 0);
11801 - return;
11802 + else {
11803 + pos = TextGetCursorPos(window->lastFocus);
11807 + return pos;
11810 +void SelectToMatchingCharacter(WindowInfo *window)
11812 + int pos;
11813 + int startPos, endPos, matchPos, matchLen;
11814 + int direction;
11815 + textBuffer *buf = window->buffer;
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, buf->length, &matchPos)) {
11823 + if (!FindMatchingString(window, MT_SELECT, &pos, 0,
11824 + buf->length, &matchPos, &matchLen, &direction)) {
11825 XBell(TheDisplay, 0);
11826 return;
11828 - startPos = (matchPos > selStart) ? selStart : matchPos;
11829 - endPos = (matchPos > selStart) ? matchPos : selStart;
11830 + startPos = (matchPos > pos) ? pos : matchPos;
11831 + endPos = (matchPos > pos) ? matchPos : pos;
11833 /* temporarily shut off autoShowInsertPos before setting the cursor
11834 position so MakeSelectionVisible gets a chance to place the cursor
11835 string at a pleasing position on the screen (otherwise, the cursor would
11836 be automatically scrolled on screen and MakeSelectionVisible would do
11837 @@ -3467,117 +3451,36 @@ void SelectToMatchingCharacter(WindowInf
11838 XtVaSetValues(window->lastFocus, textNautoShowInsertPos, True, NULL);
11841 void GotoMatchingCharacter(WindowInfo *window)
11843 - int selStart, selEnd;
11844 - int matchPos;
11845 + int pos;
11846 + int matchPos, matchLen;
11847 + int direction;
11848 textBuffer *buf = window->buffer;
11850 - /* get the character to match and its position from the selection, or
11851 - the character before the insert point if nothing is selected.
11852 - Give up if too many characters are selected */
11853 - if (!GetSimpleSelection(buf, &selStart, &selEnd)) {
11854 - selEnd = TextGetCursorPos(window->lastFocus);
11855 - if (window->overstrike)
11856 - selEnd += 1;
11857 - selStart = selEnd - 1;
11858 - if (selStart < 0) {
11859 - XBell(TheDisplay, 0);
11860 - return;
11863 - if ((selEnd - selStart) != 1) {
11864 - XBell(TheDisplay, 0);
11865 - return;
11867 + /* Pattern Match Feature: get position of the character to match */
11868 + pos = getPosForMatchingCharacter(window);
11870 /* Search for it in the buffer */
11871 - if (!findMatchingChar(window, BufGetCharacter(buf, selStart),
11872 - GetHighlightInfo(window, selStart), selStart, 0,
11873 - buf->length, &matchPos)) {
11874 + if (!FindMatchingString(window, MT_GOTO, &pos, 0,
11875 + buf->length, &matchPos, &matchLen, &direction)) {
11876 XBell(TheDisplay, 0);
11877 return;
11880 /* temporarily shut off autoShowInsertPos before setting the cursor
11881 position so MakeSelectionVisible gets a chance to place the cursor
11882 string at a pleasing position on the screen (otherwise, the cursor would
11883 be automatically scrolled on screen and MakeSelectionVisible would do
11884 nothing) */
11885 XtVaSetValues(window->lastFocus, textNautoShowInsertPos, False, NULL);
11886 - TextSetCursorPos(window->lastFocus, matchPos+1);
11887 + TextSetCursorPos(window->lastFocus, matchPos);
11888 MakeSelectionVisible(window, window->lastFocus);
11889 XtVaSetValues(window->lastFocus, textNautoShowInsertPos, True, NULL);
11892 -static int findMatchingChar(WindowInfo *window, char toMatch,
11893 - void* styleToMatch, int charPos, int startLimit, int endLimit,
11894 - int *matchPos)
11896 - int nestDepth, matchIndex, direction, beginPos, pos;
11897 - char matchChar, c;
11898 - void *style = NULL;
11899 - textBuffer *buf = window->buffer;
11900 - int matchSyntaxBased = window->matchSyntaxBased;
11902 - /* If we don't match syntax based, fake a matching style. */
11903 - if (!matchSyntaxBased) style = styleToMatch;
11905 - /* Look up the matching character and match direction */
11906 - for (matchIndex = 0; matchIndex<N_MATCH_CHARS; matchIndex++) {
11907 - if (MatchingChars[matchIndex].c == toMatch)
11908 - break;
11910 - if (matchIndex == N_MATCH_CHARS)
11911 - return FALSE;
11912 - matchChar = MatchingChars[matchIndex].match;
11913 - direction = MatchingChars[matchIndex].direction;
11915 - /* find it in the buffer */
11916 - beginPos = (direction==SEARCH_FORWARD) ? charPos+1 : charPos-1;
11917 - nestDepth = 1;
11918 - if (direction == SEARCH_FORWARD) {
11919 - for (pos=beginPos; pos<endLimit; pos++) {
11920 - c=BufGetCharacter(buf, pos);
11921 - if (c == matchChar) {
11922 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11923 - if (style == styleToMatch) {
11924 - nestDepth--;
11925 - if (nestDepth == 0) {
11926 - *matchPos = pos;
11927 - return TRUE;
11930 - } else if (c == toMatch) {
11931 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11932 - if (style == styleToMatch)
11933 - nestDepth++;
11936 - } else { /* SEARCH_BACKWARD */
11937 - for (pos=beginPos; pos>=startLimit; pos--) {
11938 - c=BufGetCharacter(buf, pos);
11939 - if (c == matchChar) {
11940 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11941 - if (style == styleToMatch) {
11942 - nestDepth--;
11943 - if (nestDepth == 0) {
11944 - *matchPos = pos;
11945 - return TRUE;
11948 - } else if (c == toMatch) {
11949 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11950 - if (style == styleToMatch)
11951 - nestDepth++;
11955 - return FALSE;
11959 ** Xt timer procedure for erasing the matching parenthesis marker.
11961 static void flashTimeoutProc(XtPointer clientData, XtIntervalId *id)
11963 diff --quilt old/source/smartIndent.c new/source/smartIndent.c
11964 --- old/source/smartIndent.c
11965 +++ new/source/smartIndent.c
11966 @@ -978,13 +978,13 @@ void EditSmartIndentMacros(WindowInfo *w
11967 XmNleftPosition, 1,
11968 XmNtopAttachment, XmATTACH_POSITION,
11969 XmNtopPosition, 1,
11970 XmNrightAttachment, XmATTACH_POSITION,
11971 XmNrightPosition, 99, NULL);
11973 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
11974 SmartIndentDialog.lmPulldown = CreateLanguageModeMenu(lmForm, langModeCB,
11975 - NULL);
11976 + NULL, FALSE);
11977 n = 0;
11978 XtSetArg(args[n], XmNspacing, 0); n++;
11979 XtSetArg(args[n], XmNmarginWidth, 0); n++;
11980 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
11981 XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
11982 @@ -2150,12 +2150,13 @@ void UpdateLangModeMenuSmartIndent(void)
11984 if (SmartIndentDialog.shell == NULL)
11985 return;
11987 oldMenu = SmartIndentDialog.lmPulldown;
11988 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
11989 SmartIndentDialog.lmPulldown = CreateLanguageModeMenu(
11990 - XtParent(XtParent(oldMenu)), langModeCB, NULL);
11991 + XtParent(XtParent(oldMenu)), langModeCB, NULL, FALSE);
11992 XtVaSetValues(XmOptionButtonGadget(SmartIndentDialog.lmOptMenu),
11993 XmNsubMenuId, SmartIndentDialog.lmPulldown, NULL);
11994 SetLangModeMenu(SmartIndentDialog.lmOptMenu, SmartIndentDialog.langModeName);
11996 XtDestroyWidget(oldMenu);
11997 diff --quilt old/source/window.c new/source/window.c
11998 --- old/source/window.c
11999 +++ new/source/window.c
12000 @@ -53,10 +53,11 @@ static const char CVSID[] = "$Id: window
12001 #include "nedit.bm"
12002 #include "n.bm"
12003 #include "windowTitle.h"
12004 #include "interpret.h"
12005 #include "rangeset.h"
12006 +#include "patternMatchData.h"
12007 #include "../util/clearcase.h"
12008 #include "../util/misc.h"
12009 #include "../util/fileUtils.h"
12010 #include "../util/utils.h"
12011 #include "../util/fileUtils.h"
12012 @@ -275,11 +276,10 @@ WindowInfo *CreateWindow(const char *nam
12013 window->saveOldVersion = GetPrefSaveOldVersion();
12014 window->wrapMode = GetPrefWrap(PLAIN_LANGUAGE_MODE);
12015 window->showWrapMargin = GetPrefShowWrapMargin();
12016 window->overstrike = False;
12017 window->showMatchingStyle = GetPrefShowMatching();
12018 - window->matchSyntaxBased = GetPrefMatchSyntaxBased();
12019 window->showStats = GetPrefStatsLine();
12020 window->showISearchLine = GetPrefISearchLine();
12021 window->showLineNumbers = GetPrefLineNums();
12022 window->highlightSyntax = GetPrefHighlightSyntax();
12023 window->backlightCharTypes = NULL;
12024 @@ -314,10 +314,14 @@ WindowInfo *CreateWindow(const char *nam
12025 window->highlightData = NULL;
12026 window->shellCmdData = NULL;
12027 window->macroCmdData = NULL;
12028 window->smartIndentData = NULL;
12029 window->languageMode = PLAIN_LANGUAGE_MODE;
12031 + /* Pattern Match Feature: assign "PLAIN" string match table*/
12032 + window->stringMatchTable = FindStringMatchTable(NULL);
12034 window->iSearchHistIndex = 0;
12035 window->iSearchStartPos = -1;
12036 window->replaceLastRegexCase = TRUE;
12037 window->replaceLastLiteralCase = FALSE;
12038 window->iSearchLastRegexCase = TRUE;
12039 @@ -3451,11 +3455,10 @@ WindowInfo* CreateDocument(WindowInfo* s
12040 window->saveOldVersion = GetPrefSaveOldVersion();
12041 window->wrapMode = GetPrefWrap(PLAIN_LANGUAGE_MODE);
12042 window->showWrapMargin = GetPrefShowWrapMargin();
12043 window->overstrike = False;
12044 window->showMatchingStyle = GetPrefShowMatching();
12045 - window->matchSyntaxBased = GetPrefMatchSyntaxBased();
12046 window->highlightSyntax = GetPrefHighlightSyntax();
12047 window->backlightCharTypes = NULL;
12048 window->backlightChars = GetPrefBacklightChars();
12049 if (window->backlightChars) {
12050 char *cTypes = GetPrefBacklightCharTypes();
12051 @@ -3486,10 +3489,16 @@ WindowInfo* CreateDocument(WindowInfo* s
12052 window->highlightData = NULL;
12053 window->shellCmdData = NULL;
12054 window->macroCmdData = NULL;
12055 window->smartIndentData = NULL;
12056 window->languageMode = PLAIN_LANGUAGE_MODE;
12058 + /*
12059 + * Pattern Match Feature:
12060 + */
12061 + window->stringMatchTable = FindStringMatchTable(NULL);
12063 window->iSearchHistIndex = 0;
12064 window->iSearchStartPos = -1;
12065 window->replaceLastRegexCase = TRUE;
12066 window->replaceLastLiteralCase = FALSE;
12067 window->iSearchLastRegexCase = TRUE;
12068 @@ -3883,11 +3892,10 @@ void RefreshMenuToggleStates(WindowInfo
12069 #ifndef VMS
12070 XmToggleButtonSetState(window->saveLastItem, window->saveOldVersion, False);
12071 #endif
12072 XmToggleButtonSetState(window->autoSaveItem, window->autoSave, False);
12073 XmToggleButtonSetState(window->overtypeModeItem, window->overstrike, False);
12074 - XmToggleButtonSetState(window->matchSyntaxBasedItem, window->matchSyntaxBased, False);
12075 XmToggleButtonSetState(window->readOnlyItem, IS_USER_LOCKED(window->lockReasons), False);
12076 XmToggleButtonSetState(window->transientItem, window->transient, False);
12078 XtSetSensitive(window->smartIndentItem,
12079 SmartIndentMacrosAvailable(LanguageModeName(window->languageMode)));
12080 @@ -4447,10 +4455,13 @@ static void cloneDocument(WindowInfo *wi
12081 window->languageMode = orgWin->languageMode;
12082 window->highlightSyntax = orgWin->highlightSyntax;
12083 if (window->highlightSyntax)
12084 StartHighlighting(window, False);
12086 + /* recycle the pattern match data */
12087 + window->stringMatchTable = orgWin->stringMatchTable;
12089 /* copy states of original document */
12090 window->filenameSet = orgWin->filenameSet;
12091 window->fileFormat = orgWin->fileFormat;
12092 window->lastModTime = orgWin->lastModTime;
12093 window->fileChanged = orgWin->fileChanged;
12094 @@ -4465,11 +4476,10 @@ static void cloneDocument(WindowInfo *wi
12095 window->autoSave = orgWin->autoSave;
12096 window->saveOldVersion = orgWin->saveOldVersion;
12097 window->wrapMode = orgWin->wrapMode;
12098 SetOverstrike(window, orgWin->overstrike);
12099 window->showMatchingStyle = orgWin->showMatchingStyle;
12100 - window->matchSyntaxBased = orgWin->matchSyntaxBased;
12101 #if 0
12102 window->showStats = orgWin->showStats;
12103 window->showISearchLine = orgWin->showISearchLine;
12104 window->showLineNumbers = orgWin->showLineNumbers;
12105 window->modeMessageDisplayed = orgWin->modeMessageDisplayed;