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
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
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
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.
56 source/Makefile.common | 6
57 source/Makefile.dependencies | 11
58 source/highlightData.c | 13
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
71 16 files changed, 10773 insertions(+), 297 deletions(-)
73 diff --quilt old/doc/help.etx 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
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,
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
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,
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
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.
177 Has a value of 1 if the statistics line is shown, otherwise 0.
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
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.
226 In overtype mode, new characters entered replace the characters in front of
227 the insertion cursor, rather than being inserted before them.
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 ----------------------------------------------------------------------
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
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
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
293 + In fact, "Individual" matching pattern search is faster than "Context group" /
294 + "Sub-pattern" search. "Context group" / "Sub-pattern" search results in fewer
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"
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
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
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
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:
360 +! +--> start -+-> middle -+-> end --+
361 +! +-----------<---------------------+
365 + A string pattern holds three attributes:
367 +* "String Pattern Type"
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":
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.
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
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
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)
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 \
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
513 XmNrightAttachment, XmATTACH_POSITION,
514 XmNrightPosition, 99,
517 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
518 HighlightDialog.lmPulldown = CreateLanguageModeMenu(lmForm, langModeCB,
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)
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);
545 SetLangModeMenu(HighlightDialog.lmOptMenu,
546 HighlightDialog.langModeName);
548 + freePatternSet(newPatSet);
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);
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"
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 },
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);
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;
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.
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)
682 + int matchPos, matchLen;
684 + textBuffer *buf = window->buffer;
688 + * Perform syntax & semantic check
691 + return wrongNArgsErr(errMsg);
693 + if (!readIntArg(argList[0], &startPos, errMsg))
699 + * do the search; provide default values, if search fails
701 + if (!FindMatchingString(window, MT_MACRO, &startPos, 0, buf->length,
702 + &matchPos, &matchLen, &direction))
710 + * initialize array holding info about matching string
712 + result->tag = ARRAY_TAG;
713 + result->val.arrayPtr = ArrayNew();
716 + * the following array entries will be integers
721 + * insert match position
723 + dv.val.n = matchPos;
724 + if (!ArrayInsert(result, PERM_ALLOC_STR("pos"), &dv))
726 + M_ARRAY_INSERT_FAILURE();
730 + * insert length of matching pattern
732 + dv.val.n = matchLen;
733 + if (!ArrayInsert(result, PERM_ALLOC_STR("len"), &dv))
735 + M_ARRAY_INSERT_FAILURE();
739 + * insert direction where the matching pattern was found
741 + dv.val.n = direction;
742 + if (!ArrayInsert(result, PERM_ALLOC_STR("direction"), &dv))
744 + M_ARRAY_INSERT_FAILURE();
750 static int wrongNArgsErr(char **errMsg)
752 *errMsg = "Wrong number of arguments to function %s";
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"
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
799 static void setIncrementalBackupAP(Widget w, XEvent *event, String *args,
801 static void setShowMatchingAP(Widget w, XEvent *event, String *args,
803 -static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
805 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
807 static void setLockedAP(Widget w, XEvent *event, String *args,
809 static void setTransientAP(Widget text, XEvent *event, String *args,
810 @@ -582,11 +580,10 @@ static XtActionsRec Actions[] = {
812 {"set_make_backup_copy", setMakeBackupCopyAP},
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);
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);
866 - if (shortPrefAskDefault(window->shell, w, "Match Syntax Based")) {
867 - matchSyntaxBasedDefCB(w, window, callData);
868 - SaveNEditPrefs(window->shell, GetPrefShortMenus());
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)
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)
911 @@ -4286,23 +4256,10 @@ static void setShowMatchingAP(Widget w,
913 fprintf(stderr, "nedit: set_show_matching requires argument\n");
917 -static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
920 - WindowInfo *window = WidgetToWindow(w);
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,
933 WindowInfo *window = WidgetToWindow(w);
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;
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
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 */
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
990 +++ new/source/patternMatch.c
992 +static const char CVSID[] = "$Id: patternMatch.c,v 1.4 2003/10/27 21:59:14 uleh Exp $";
993 +/*******************************************************************************
995 +* patternMatch.c -- Nirvana Editor pattern matching functions *
997 +* Copyright (C) 2003-2004, Uwe Lehnert *
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. *
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. *
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 *
1014 +* Nirvana Text Editor *
1015 +* October 27, 2004 *
1017 +* Written by Uwe Lehnert *
1019 +*******************************************************************************/
1021 +#ifdef HAVE_CONFIG_H
1022 +#include "../config.h"
1025 +#include <stdlib.h>
1027 +#include <limits.h>
1028 +#include <string.h>
1032 +#include "../util/VMSparam.h"
1035 +#include <sys/param.h>
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"
1053 +#define MAX_NESTED_PATTERNS 100
1055 +#define IGNORE_HIGHLIGHT_CODE -1
1057 +typedef struct _SearchRegionInfo {
1058 + WindowInfo *sriWindow;
1062 + int sriStartOfTextPos;
1063 +} SearchRegionInfo;
1065 +typedef struct _FoundStringInfo {
1066 + char *fsiStartPtr;
1071 + const char *fsiDelimiters;
1074 +typedef struct _BackRefInfo {
1076 + int briCaseInsensitive;
1077 + char *briStartPtr[MAX_GLOBAL_BACK_REF_ID];
1078 + char *briEndPtr[MAX_GLOBAL_BACK_REF_ID];
1081 +typedef struct _MatchingElementInfo {
1082 + MatchPatternTableElement *meiElement;
1083 + PatternReference meiPatRef;
1085 + int meiHighLightCode;
1086 + int meiAbsStartPos;
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
1100 +void adaptPatternPositions(
1101 + MatchingType matchingType,
1104 + int startPatternLength,
1106 + int matchedPatternLength);
1108 +static int findMatchingStringElement(
1109 + StringMatchTable *smTable,
1110 + SearchRegionInfo *searchRegion,
1111 + MatchingElementInfo *matchInfo,
1113 + const char *delimiters);
1115 +static PatternElementMonoInfo determineMonoPatInfo(
1116 + WindowInfo *window,
1117 + int patHighLightCode,
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(
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,
1168 +static int searchPatternForward(
1169 + MatchPatternTable *table,
1170 + regexp *compiledRE,
1171 + SearchRegionInfo *searchRegion,
1172 + const char *delimiters,
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,
1184 + PatternReference *patRef,
1185 + int *highLightCode,
1186 + int *matchedPatternLength,
1187 + BackRefInfo *backRefInfo);
1189 +static int parseStringElementForward(
1190 + MatchingElementInfo *matchInfo,
1191 + SearchRegionInfo *searchRegion,
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,
1204 + int *matchEndPos);
1206 +static int parseStringElementBackward(
1207 + MatchingElementInfo *matchInfo,
1208 + SearchRegionInfo *searchRegion,
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,
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,
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);
1245 +static char *getPatternForDebug(
1246 + MatchPatternTable *table,
1247 + PatternReference patRef );
1248 +static char *patElemKindToString(
1249 + PatternElementKind patElemKind);
1250 +static void printFoundStringForDebug(
1251 + WindowInfo *window,
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,
1270 + int *matchedPatternLength,
1273 + StringMatchTable *smTable = (StringMatchTable *)window->stringMatchTable;
1274 + const char *delimiters;
1275 + SearchRegionInfo searchRegion;
1276 + MatchingElementInfo matchInfo;
1277 + int matchingPatternFound = FALSE;
1280 + if (smTable == NULL || smTable->smtAllPatRE == NULL)
1283 + * No match pattern table available:
1289 + * Get delimiters related to window
1291 + delimiters = GetWindowDelimiters(window);
1292 + if (delimiters == NULL)
1293 + delimiters = GetPrefDelimiters();
1296 + * Select the start pattern reg. exp. to use
1298 + if (matchingType == MT_FLASH_RANGE ||
1299 + matchingType == MT_FLASH_DELIMIT)
1301 + smTable->smtUsedPatRE = smTable->smtFlashPatRE;
1305 + smTable->smtUsedPatRE = smTable->smtAllPatRE;
1309 + * Get a copy of the text buffer area to parse
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;
1320 + * Try to find a matching pattern string using string match table
1323 + if (findMatchingStringElement(
1331 + printf("--- Start at : ");
1332 + printFoundStringForDebug(
1334 + matchInfo.meiAbsStartPos,
1335 + matchInfo.meiLength);
1338 + if (matchInfo.meiDirection == SEARCH_FORWARD)
1340 + matchingPatternFound =
1341 + parseStringElementForward(
1346 + matchedPatternLength,
1351 + matchingPatternFound =
1352 + parseStringElementBackward(
1357 + matchedPatternLength,
1361 + if (matchingPatternFound)
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.
1368 + *charPos = relCharPos + startLimit;
1369 + *direction = matchInfo.meiDirection;
1371 + adaptPatternPositions(
1373 + matchInfo.meiDirection,
1375 + matchInfo.meiLength,
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,
1394 + int startPatternLength,
1396 + int matchedPatternLength)
1398 + switch (matchingType)
1400 + case MT_FLASH_DELIMIT:
1402 + if (direction == SEARCH_FORWARD)
1404 + (*matchPos) -= matchedPatternLength - 1;
1408 + case MT_FLASH_RANGE:
1410 + if (direction == SEARCH_FORWARD)
1412 + (*charPos) -= startPatternLength;
1421 + if (direction == SEARCH_FORWARD)
1427 + (*matchPos) += matchedPatternLength;
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,
1446 + const char *delimiters)
1448 + if (getPatternLocatedAtPos(
1449 + smTable->smtUsedPatRE,
1450 + smTable->smtAllPatterns,
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
1463 + if (matchInfo->meiPatRef.prKind == PEK_END)
1464 + matchInfo->meiDirection = SEARCH_BACKWARD;
1466 + matchInfo->meiDirection = SEARCH_FORWARD;
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,
1484 + PatternElementKind *patElementKind)
1486 + int leftSideHasSameHC;
1487 + int rightSideHasSameHC;
1490 + * Determine, if left side holds same highlight code than
1491 + * found string pattern
1494 + leftSideHasSameHC =
1495 + (HighlightCodeOfPos(window, leftPos) == patHighLightCode);
1497 + leftSideHasSameHC = FALSE;
1500 + * Determine, if right side holds same highlight code than
1501 + * found string pattern
1503 + if (rightPos < window->buffer->length)
1504 + rightSideHasSameHC =
1505 + (HighlightCodeOfPos(window, rightPos) == patHighLightCode);
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;
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)
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];
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)
1571 + * if min. one string pattern doesn't hold backref info, then nothing
1572 + * could be compared -> both string pattern are matching.
1574 + if (!backRefInfo1->briAvailable || !backRefInfo2->briAvailable)
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))
1594 +** Compares two backref content.
1595 +** Returns true, if backref contents match.
1597 +static int compareBackRef(
1602 + int caseInsensitive)
1607 + if (startPtr1 == NULL && startPtr2 == NULL)
1610 + if (startPtr1 == NULL || startPtr2 == NULL)
1613 + if ((endPtr1 - startPtr1) != (endPtr2 - startPtr2))
1619 + if (caseInsensitive)
1621 + while (s1 != endPtr1)
1623 + if (tolower((unsigned char)*s1++) != tolower((unsigned char)*s2++))
1629 + while (s1 != endPtr1)
1631 + if (*s1++ != *s2++)
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)
1651 + StringPattern *strPat;
1654 + switch (patElement->peType)
1657 + strPat = &patElement->peVal.peuSingle;
1659 + case PET_MULTIPLE:
1660 + strPat = &patElement->peVal.peuMulti.mpStringPattern;
1666 + if (strPat->spRegularExpression)
1669 + * check reg. expression:
1674 + foundStringInfo->fsiStartPtr,
1675 + foundStringInfo->fsiEndPtr,
1677 + foundStringInfo->fsiPrevChar,
1678 + foundStringInfo->fsiSuccChar,
1679 + foundStringInfo->fsiDelimiters,
1684 + assignBackRefInfo(strPat, backRefInfo);
1686 + return elementMatch;
1690 + backRefInfo->briAvailable = FALSE;
1693 + * check literal string:
1695 + p = strPat->spText;
1698 + * if length of found string is different from length of
1699 + * given string pattern, then there is no match.
1701 + if (strPat->spLength != foundStringInfo->fsiLength)
1704 + s = foundStringInfo->fsiStartPtr;
1706 + if (strPat->spCaseInsensitive)
1708 + while (s != foundStringInfo->fsiEndPtr)
1710 + if (tolower((unsigned char)*s++) != *p++)
1716 + while (s != foundStringInfo->fsiEndPtr)
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)
1741 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
1743 + if (doesPatternElementMatch(
1744 + element->mpteAll.pesPattern[i],
1748 + *patternElementKind = element->mpteAll.pesPattern[i]->peKind;
1749 + *patternElementIdx = i;
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)
1772 + for (i=0; i<table->mptNumberOfElements; i++)
1774 + if (doesMPTableElementMatch(
1775 + table->mptElements[i],
1778 + &patRef->prPatternIdx,
1781 + patRef->prElementIdx = i;
1788 + * Should never been reached !
1790 + patRef->prElementIdx = NO_ELEMENT_IDX;
1791 + patRef->prKind = PEK_UNKNOWN;
1792 + patRef->prPatternIdx = NO_PATTERN_IDX;
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)
1814 + if (patElementKind == PEK_START)
1816 + if (isPartOfPatternElementSet(&parent->mpteStart, childElementIdx))
1819 + return( isPartOfPatternElementSet(&child->mpteStart, parentElementIdx) );
1821 + else if (patElementKind == PEK_END)
1823 + if (isPartOfPatternElementSet(&parent->mpteEnd, childElementIdx))
1826 + return( isPartOfPatternElementSet(&child->mpteEnd, parentElementIdx) );
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
1834 + if (isPartOfMiddlePatternElementSet(&parent->mpteMiddle, childElementIdx))
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;
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)
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.
1874 +static int isPartOfMiddlePatternElementSet(
1875 + PatternElementSet *patElementSet,
1876 + int patternElementIdx)
1878 + PatternElement *patElement;
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)
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,
1908 + MatchPatternTableElement *tabElement;
1909 + PatternElement *startPat;
1910 + MultiPattern *multiStartPat;
1911 + PatternReference patRef;
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).
1919 + if (startPatRef->prElementIdx == nxtPatRef.prElementIdx)
1923 + * Verify, if start pattern belongs to multiple pattern elements
1924 + * (like "ELSE .. FI" & "ELSE .. ESAC").
1926 + startPat = getPatternOfReference( table, *startPatRef );
1928 + if (startPat->peType == PET_MULTIPLE)
1931 + * Check, if next pattern fits to one of the references of
1932 + * the start multi pattern. If so: adapt start pattern reference.
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;
1952 +** Search for a string pattern in forward direction, starting at
1953 +** given beginPos. Determine related pattern reference of a found
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,
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;
1983 + searchRegion->sriText + beginPos,
1986 + beginPos==0 ? searchRegion->sriPrevChar : searchRegion->sriText[beginPos-1],
1987 + searchRegion->sriSuccChar,
1989 + searchRegion->sriText,
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(
2014 + * Next string pattern was found in forward direction and
2015 + * a pattern reference could be assigned to: calculate
2016 + * relative & absolute match positions.
2018 + matchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
2019 + *matchEndPos = foundStringInfo.fsiEndPtr - searchRegion->sriText;
2021 + absMatchStartPos = matchStartPos + searchRegion->sriStartOfTextPos;
2023 + matchedElement = table->mptElements[patRef->prElementIdx];
2026 + * get highlight code of found string pattern, if applicable
2028 + if (!matchedElement->mpteIgnoreHighLightInfo)
2031 + HighlightCodeOfPos(searchRegion->sriWindow, absMatchStartPos);
2035 + * setup mono pattern info of found string pattern
2037 + if (matchedElement->mpteIsMonoPattern)
2039 + if (matchedElement->mpteIgnoreHighLightInfo)
2041 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
2046 + * determine mono pattern info depending on highLightCodes
2047 + * before / after found string pattern.
2049 + patRef->prMonoInfo =
2050 + determineMonoPatInfo(
2051 + searchRegion->sriWindow,
2053 + absMatchStartPos - 1,
2054 + *matchEndPos + searchRegion->sriStartOfTextPos,
2060 + patRef->prMonoInfo = PEMI_NOT_MONO;
2063 + return matchStartPos;
2068 + * Found string can't be assigned to a pattern element
2069 + * (should never occur).
2077 + * No next string pattern is found in forward direction.
2084 +** Search for a string pattern in backward direction, starting at
2085 +** given beginPos. Determine related pattern reference of a found
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,
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;
2113 + searchRegion->sriText,
2114 + searchRegion->sriText + beginPos,
2116 + searchRegion->sriPrevChar,
2117 + searchRegion->sriText[beginPos] == '\0' ?
2118 + searchRegion->sriSuccChar : searchRegion->sriText[beginPos + 1],
2120 + searchRegion->sriText,
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(
2145 + * Next string pattern was found in backward direction and
2146 + * a pattern reference could be assigned to: calculate
2147 + * relative & absolute match positions.
2149 + matchStartPos = foundStringInfo.fsiStartPtr - searchRegion->sriText;
2150 + *matchedPatternLength = foundStringInfo.fsiLength;
2152 + absMatchStartPos = matchStartPos + searchRegion->sriStartOfTextPos;
2154 + matchedElement = table->mptElements[patRef->prElementIdx];
2157 + * get highlight code of found string pattern, if applicable
2159 + if (!matchedElement->mpteIgnoreHighLightInfo)
2162 + HighlightCodeOfPos(searchRegion->sriWindow, absMatchStartPos);
2166 + * setup mono pattern info of found string pattern
2168 + if (matchedElement->mpteIsMonoPattern)
2170 + if (matchedElement->mpteIgnoreHighLightInfo)
2172 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
2177 + * determine mono pattern info depending on highLightCodes
2178 + * before / after found string pattern.
2180 + patRef->prMonoInfo =
2181 + determineMonoPatInfo(
2182 + searchRegion->sriWindow,
2184 + absMatchStartPos - 1,
2185 + absMatchStartPos + *matchedPatternLength,
2191 + patRef->prMonoInfo = PEMI_NOT_MONO;
2194 + return matchStartPos;
2199 + * Found string can't be assigned to a pattern element
2200 + * (should never occur).
2208 + * No next string pattern is found in backward direction.
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,
2230 + int *matchedPatternLength,
2231 + const char *delimiters)
2233 + StringMatchTable *smTable =
2234 + (StringMatchTable *)searchRegion->sriWindow->stringMatchTable;
2235 + MatchPatternTableElement *matchElement = matchInfo->meiElement;
2236 + int beginPos = relCharPos;
2238 + int startStartPos;
2240 + int matchingPatternFound = FALSE;
2243 + * Find matching pattern within text buffer area to parse in
2244 + * forward direction.
2247 + findRelatedForwardPattern(
2251 + matchInfo->meiPatRef,
2252 + matchInfo->meiHighLightCode,
2253 + &matchInfo->meiBackRefInfo,
2257 + if (endEndPos != -1)
2259 + *matchPos = endEndPos - 1 + searchRegion->sriStartOfTextPos;
2260 + *matchedPatternLength = endEndPos - endStartPos;
2262 + matchingPatternFound = TRUE;
2264 + else if (matchElement->mpteIsMonoPattern)
2267 + * mono pattern: forward find fails -> try backward direction.
2268 + * Calc. relative position of 1st char. before found string pattern.
2270 + beginPos = beginPos - matchInfo->meiLength - 1;
2275 + findRelatedStartPattern(
2279 + matchInfo->meiPatRef,
2280 + matchInfo->meiHighLightCode,
2281 + &matchInfo->meiBackRefInfo,
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,
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];
2326 + PatternReference startPatRef;
2327 + MatchPatternTableElement *currentElement;
2329 + regexp *groupPatRE;
2330 + regexp *currentPatRE;
2331 + int skipToEnd = FALSE;
2332 + int beginPatternIsMono;
2335 + printf("Forward Start Pos: %d K: %s EI: %d PI: %d HC: %d <%s>\n",
2337 + patElemKindToString(beginPatRef.prKind),
2338 + beginPatRef.prElementIdx,
2339 + beginPatRef.prPatternIdx,
2340 + beginPatHighLightCode,
2341 + getPatternForDebug(patTable, beginPatRef) );
2345 + * put begin pattern info on stack
2347 + stack[stackIdx].psePatRef = beginPatRef;
2348 + stack[stackIdx].pseHighLightCode = beginPatHighLightCode;
2349 + stack[stackIdx].pseBackRefInfo = *beginPatBackRefInfo;
2352 + currentElement = patTable->mptElements[beginPatRef.prElementIdx];
2354 + beginPatternIsMono = currentElement->mpteIsMonoPattern;
2356 + groupIdx = currentElement->mpteGroup;
2359 + * no next pattern can be found, if there is no group assigned
2360 + * to begin pattern (should never occur)
2362 + if (groupIdx == NO_GROUP_IDX)
2364 + *matchEndPos = -1;
2370 + * Remember pattern (= keywords) regular expression of context
2371 + * group related to begin pattern. Use it for forward search.
2373 + groupPatRE = table->smtGroups[groupIdx]->mpgeKeywordRE;
2374 + currentPatRE = groupPatRE;
2377 + * Use start / end pattern regular expression if skip to end is
2378 + * set for begin pattern.
2380 + if (currentElement->mpteSkipBtwnStartEnd)
2382 + currentPatRE = currentElement->mpteStartEndRE;
2386 + while (stackIdx > 0 && nxtPatStartPos != -1)
2389 + * Search for next string pattern in forward direction.
2392 + searchPatternForward(
2400 + &nxtPatHighLightCode,
2401 + &nxtPatBackRefInfo );
2403 + startPatRef = stack[stackIdx-1].psePatRef;
2405 + if (nxtPatStartPos == -1)
2408 + * no next pattern found -> leave loop
2411 + printf(" SI: %d [start K: %s EI: %d PI %d] Pos: %d --> no next pat. found\n",
2413 + patElemKindToString(startPatRef.prKind),
2414 + startPatRef.prElementIdx,
2415 + startPatRef.prPatternIdx,
2422 + * Update start pattern reference depending on next pattern
2423 + * located after start pattern.
2425 + considerNextPatternReference(
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.
2437 + (nxtPatRef.prMonoInfo == PEMI_MONO_AMBIGUOUS_SYNTAX ||
2438 + nxtPatRef.prMonoInfo == PEMI_MONO_NOT_SYNTAX_BASED))
2440 + nxtPatRef.prKind = PEK_END;
2444 + printf(" SI: %d [start K: %s EI: %d PI %d] Pos: %d-%d K: %s EI: %d PI: %d HC: %d f=<%s> ",
2446 + patElemKindToString(startPatRef.prKind),
2447 + startPatRef.prElementIdx,
2448 + startPatRef.prPatternIdx,
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);
2463 + if (nxtPatRef.prKind == PEK_START)
2465 + if (stackIdx >= MAX_NESTED_PATTERNS)
2468 + printf("FORWARD: MAX. NESTED PATTERN DEPTH REACHED !\n");
2470 + nxtPatStartPos = -1;
2471 + nxtPatEndPos = -1;
2473 + else if (!skipToEnd)
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. \* \* ..)
2481 + stack[stackIdx].psePatRef = nxtPatRef;
2482 + stack[stackIdx].pseHighLightCode = nxtPatHighLightCode;
2483 + stack[stackIdx].pseBackRefInfo = nxtPatBackRefInfo;
2486 + currentElement = patTable->mptElements[nxtPatRef.prElementIdx];
2489 + * Use start / end pattern regular expression if skip to
2490 + * end is set for found start pattern.
2492 + if (currentElement->mpteSkipBtwnStartEnd)
2494 + currentPatRE = currentElement->mpteStartEndRE;
2498 + else if (beginPatternIsMono)
2501 + * skip to end is set and a mono pattern start is reached:
2502 + * trigger backward search by returning "not found"
2505 + printf(" ---> mono pattern (re-)start -> trigger backward search\n");
2507 + nxtPatStartPos = -1;
2508 + nxtPatEndPos = -1;
2513 + printf(" ---> skip to end: illegal (re-)start pattern !\n");
2517 + else if (nxtPatRef.prKind == PEK_END)
2520 + * ignore current found pattern, if it doesn't fit to the prev.
2523 + if (isPartOfPattern(
2525 + nxtPatRef.prElementIdx,
2526 + startPatRef.prElementIdx,
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))
2536 + * use context group pattern again, if end pattern to skip
2541 + currentPatRE = groupPatRE;
2542 + skipToEnd = FALSE;
2546 + * pop. related start pattern from stack.
2551 + else if (!skipToEnd)
2554 + * middle pattern was found: ignore it, if found middle pattern
2555 + * doesn't belong to begin pattern.
2557 + if (stackIdx == 1 &&
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))
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
2589 +** Returns true, if a matching pattern was found.
2591 +static int parseStringElementBackward(
2592 + MatchingElementInfo *matchInfo,
2593 + SearchRegionInfo *searchRegion,
2596 + int *matchedPatternLength,
2597 + const char *delimiters)
2599 + StringMatchTable *smTable =
2600 + (StringMatchTable *)searchRegion->sriWindow->stringMatchTable;
2602 + int startStartPos;
2603 + int matchingPatternFound = FALSE;
2606 + * determine begin of search in string buffer (= relative position
2607 + * of 1st char. before found string pattern.)
2609 + beginPos = relCharPos - matchInfo->meiLength - 1;
2615 + * Find matching pattern within text buffer area to parse in
2616 + * backward direction.
2619 + findRelatedStartPattern(
2623 + matchInfo->meiPatRef,
2624 + matchInfo->meiHighLightCode,
2625 + &matchInfo->meiBackRefInfo,
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,
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];
2664 + MatchPatternTableElement *currentElement;
2666 + regexp *groupPatRE;
2667 + regexp *currentPatRE;
2668 + int skipToStart = FALSE;
2671 + * put begin pattern info on stack
2673 + stack[stackIdx].psePatRef = beginPatRef;
2674 + stack[stackIdx].pseHighLightCode = beginPatHighLightCode;
2675 + stack[stackIdx].pseBackRefInfo = *beginPatBackRefInfo;
2678 + currentElement = patTable->mptElements[beginPatRef.prElementIdx];
2681 + printf("Backward Start Pos: %d K: %s EI: %d PI: %d HC: %d <%s>\n",
2683 + patElemKindToString(beginPatRef.prKind),
2684 + beginPatRef.prElementIdx,
2685 + beginPatRef.prPatternIdx,
2686 + beginPatHighLightCode,
2687 + getPatternForDebug(patTable, beginPatRef) );
2690 + groupIdx = currentElement->mpteGroup;
2693 + * no start pattern can be found, if there is no group assigned
2694 + * to begin pattern (should never occur)
2696 + if (groupIdx == NO_GROUP_IDX)
2702 + * Remember pattern (= keywords) regular expression of context
2703 + * group related to begin pattern. Use it for backward search.
2705 + groupPatRE = table->smtGroups[groupIdx]->mpgeKeywordRE;
2706 + currentPatRE = groupPatRE;
2709 + * Use start / end pattern regular expression if skip to start is
2710 + * set for begin pattern.
2712 + if (currentElement->mpteSkipBtwnStartEnd)
2714 + currentPatRE = currentElement->mpteStartEndRE;
2715 + skipToStart = TRUE;
2718 + while (stackIdx > 0 && prevStartPos != -1)
2721 + * Search for previous string pattern in backward direction.
2724 + searchPatternBackward(
2731 + &prevPatHighLightCode,
2732 + matchedPatternLength,
2733 + &prevPatBackRefInfo );
2735 + if (prevStartPos == -1)
2738 + * no previous pattern found -> leave loop
2741 + printf(" SI: %d [K: %s start EI: %d PI %d] Pos: %d --> no next pat. found\n",
2743 + patElemKindToString(stack[stackIdx -1].psePatRef.prKind),
2744 + stack[stackIdx -1].psePatRef.prElementIdx,
2745 + stack[stackIdx -1].psePatRef.prPatternIdx,
2752 + * Update previous pattern reference depending on last stack
2753 + * pattern, which is located in text puffer after previous
2756 + considerNextPatternReference(
2759 + stack[stackIdx - 1].psePatRef,
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.
2767 + if (skipToStart &&
2768 + (prevPatRef.prMonoInfo == PEMI_MONO_AMBIGUOUS_SYNTAX ||
2769 + prevPatRef.prMonoInfo == PEMI_MONO_NOT_SYNTAX_BASED))
2771 + prevPatRef.prKind = PEK_START;
2775 + printf(" SI: %d [K: %s start EI: %d PI %d] Pos: %d K: %s EI: %d PI: %d HC: %d f=<%s> ",
2777 + patElemKindToString(stack[stackIdx -1].psePatRef.prKind),
2778 + stack[stackIdx -1].psePatRef.prElementIdx,
2779 + stack[stackIdx -1].psePatRef.prPatternIdx,
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);
2793 + if (prevPatRef.prKind == PEK_START)
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)
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);
2809 + * Ignore current found pattern, if it doesn't fit to the prev.
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))
2821 + * use context group pattern again, if start pattern
2822 + * to skip to was found.
2826 + currentPatRE = groupPatRE;
2827 + skipToStart = FALSE;
2831 + * pop. related end pattern from stack.
2836 + else if (prevPatRef.prKind == PEK_END)
2838 + if (stackIdx >= MAX_NESTED_PATTERNS)
2841 + printf("BACKWARD: MAX. NESTED PATTERN DEPTH REACHED !\n");
2843 + prevStartPos = -1;
2845 + else if (!skipToStart)
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. *\ *\ ..)
2853 + stack[stackIdx].psePatRef = prevPatRef;
2854 + stack[stackIdx].pseHighLightCode = prevPatHighLightCode;
2855 + stack[stackIdx].pseBackRefInfo = prevPatBackRefInfo;
2859 + patTable->mptElements[prevPatRef.prElementIdx];
2862 + * Use start / end pattern regular expression if skip to
2863 + * end is set for found end pattern.
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;
2892 + * If found pattern index already indicates, that found pattern
2893 + * belongs to pattern set stored on stack, then no adaption is needed
2895 + if (*foundElementIdx == stackElementIdx)
2899 + * Check all elements of given pattern element set:
2901 + for (i=0; i < patSet->pesNumberOfPattern; i++)
2903 + patElement = patSet->pesPattern[i];
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
2910 + if (patElement->peType == PET_REFERENCE &&
2911 + patElement->peVal.peuRef.prElementIdx == stackElementIdx)
2913 + *foundElementIdx = stackElementIdx;
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,
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;
2953 + * No backward search possible, if we are at beginning of
2956 + if (searchStartPos == 0)
2960 + * Search in backward direction for 1st occurance of a string pattern
2961 + * starting one char before "searchStartPos".
2965 + searchRegion->sriText,
2966 + searchRegion->sriText + searchStartPos - 1,
2968 + searchRegion->sriPrevChar,
2969 + searchRegion->sriText[searchStartPos],
2971 + searchRegion->sriText,
2975 + * String pattern was found:
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;
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.
2991 + if ((*relBeginPos == relMatchEndPos) ||
2992 + (*relBeginPos >= relMatchStartPos &&
2993 + *relBeginPos < relMatchEndPos))
2995 + *relBeginPos = relMatchEndPos;
2998 + * Determine match element info related to found string.
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;
3016 + getMatchedElementInfo(
3017 + searchRegion->sriWindow,
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(
3047 + &matchInfo->meiBackRefInfo))
3050 + * A pattern reference could be assigned to found string:
3052 + matchedElement = table->mptElements[patRef->prElementIdx];
3054 + matchInfo->meiElement = matchedElement;
3057 + * get highlight code of found string pattern, if applicable
3059 + if (!matchedElement->mpteIgnoreHighLightInfo)
3061 + matchInfo->meiHighLightCode =
3062 + HighlightCodeOfPos(window, absMatchStartPos);
3066 + * setup mono pattern info of found string pattern
3068 + if (matchedElement->mpteIsMonoPattern)
3070 + if (matchedElement->mpteIgnoreHighLightInfo)
3072 + patRef->prMonoInfo = PEMI_MONO_NOT_SYNTAX_BASED;
3077 + * determine mono pattern info depending on highLightCodes
3078 + * before / after found string pattern.
3080 + patRef->prMonoInfo =
3081 + determineMonoPatInfo(
3083 + matchInfo->meiHighLightCode,
3084 + absMatchStartPos - 1,
3085 + absMatchStartPos + matchInfo->meiLength,
3091 + patRef->prMonoInfo = PEMI_NOT_MONO;
3099 + * Found string can't be assigned to a pattern element
3100 + * (should never occur).
3107 +** Returns string pattern of given pattern element.
3109 +StringPattern *GetStringPattern(
3110 + MatchPatternTable *table,
3111 + PatternElement *pattern )
3113 + switch (pattern->peType)
3116 + return &pattern->peVal.peuSingle;
3119 + case PET_MULTIPLE:
3120 + return &pattern->peVal.peuMulti.mpStringPattern;
3123 + case PET_REFERENCE:
3124 + return GetStringPattern(
3126 + getPatternOfReference(table, pattern->peVal.peuRef));
3131 + * never reached; just to make compiler happy
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];
3149 +static char *getPatternForDebug(
3150 + MatchPatternTable *table,
3151 + PatternReference patRef )
3153 + if (patRef.prElementIdx < 0)
3161 + getPatternOfReference(table, patRef))->spText;
3164 +static char *patElemKindToString(
3165 + PatternElementKind patElemKind)
3167 + if (patElemKind == PEK_START)
3169 + else if (patElemKind == PEK_MIDDLE)
3171 + else if (patElemKind == PEK_END)
3177 +static void printFoundStringForDebug(
3178 + WindowInfo *window,
3183 + BufGetRange( window->buffer, absStartPos, absStartPos + length);
3185 + printf("%d (abs.) <%s>",
3194 diff --quilt /dev/null new/source/patternMatch.h
3196 +++ new/source/patternMatch.h
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
3217 +} PatternElementKind;
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;
3231 +} PatternReference;
3237 +} MatchPatternType;
3239 +typedef struct _MatchPatternSequenceElement {
3241 + MatchPatternType mpseType;
3243 +} MatchPatternSequenceElement;
3245 +typedef struct _MatchPatternGroupElement {
3247 + int mpgeNumberOfSubPatterns;
3248 + char **mpgeSubPatternIds;
3249 + regexp *mpgeKeywordRE;
3250 +} MatchPatternGroupElement;
3257 +} PatternWordBoundary;
3259 +typedef struct _StrPatBackRefElement{
3260 + int spbreLocalBackRefID;
3261 + char *spbreRegExpText;
3262 +} StrPatBackRefElement;
3264 +typedef struct _StringPattern {
3267 + PatternWordBoundary spWordBoundary;
3268 + int spCaseInsensitive;
3269 + int spRegularExpression;
3272 + int spBackRefParsed;
3273 + int spBackRefResolved;
3274 + StrPatBackRefElement spOwnGlobalBackRef[MAX_GLOBAL_BACK_REF_ID];
3275 + int spGlobalToLocalBackRef[MAX_GLOBAL_BACK_REF_ID];
3278 +typedef struct _MultiPattern {
3279 + StringPattern mpStringPattern;
3280 + int mpNumberOfReferences;
3281 + PatternReference *mpRefList;
3288 +} PatternElementType;
3290 +typedef struct _PatternElement {
3292 + PatternElementKind peKind;
3293 + PatternElementType peType;
3295 + StringPattern peuSingle;
3296 + MultiPattern peuMulti;
3297 + PatternReference peuRef;
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 {
3314 + MatchPatternType mpteType;
3316 + PatternElementSet mpteAll;
3317 + PatternElementSet mpteStart;
3318 + PatternElementSet mpteMiddle;
3319 + PatternElementSet mpteEnd;
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;
3353 +int FindMatchingString(
3354 + WindowInfo *window,
3355 + MatchingType matchingType,
3363 +StringPattern *GetStringPattern(
3364 + MatchPatternTable *table,
3365 + PatternElement *pattern);
3367 +#endif /* NEDIT_PATTERNMATCH_H_INCLUDED */
3368 diff --quilt /dev/null new/source/patternMatchData.c
3370 +++ new/source/patternMatchData.c
3372 +static const char CVSID[] = "$Id: patternMatchData.c,v 1.4 2004/10/27 21:57:12 uleh Exp $";
3373 +/*******************************************************************************
3375 +* patternMatchData.c -- Maintain and allow user to edit a matching pattern list*
3376 +* used for pattern matching *
3378 +* Copyright (C) 2003-2004, Uwe Lehnert *
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. *
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. *
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 *
3395 +* Nirvana Text Editor *
3396 +* October 27, 2004 *
3398 +* Written by Uwe Lehnert *
3400 +*******************************************************************************/
3401 +#ifdef HAVE_CONFIG_H
3402 +#include "../config.h"
3405 +#include <stdlib.h>
3407 +#include <limits.h>
3408 +#include <string.h>
3412 +#include "../util/VMSparam.h"
3415 +#include <sys/param.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"
3437 +#include "window.h"
3438 +#include "preferences.h"
3443 +#include "patternMatch.h"
3444 +#include "patternMatchData.h"
3446 +#ifdef HAVE_DEBUG_H
3447 +#include "../debug.h"
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"
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
3480 +typedef struct _ErrorInfo {
3482 + char *eiLanguageMode;
3483 + char *eiMPTabElementName;
3484 + char *eiStringPatText;
3485 + char *eiRegExpCompileMsg;
3489 +typedef struct _BackRefBracketInfo {
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 {
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 {
3531 + MatchPatternType dmpteType;
3532 + DialogStringPatterns dmptePatterns;
3533 + int dmpteSkipBtwnStartEnd;
3534 + int dmpteIgnoreHighLightInfo;
3536 +} DialogMatchPatternTableElement;
3538 +typedef struct _DialogMatchPatternGroupElement {
3540 + int dmpgeNumberOfSubPatterns;
3541 + char *dmpgeSubPatternIds[MAX_NBR_MATCH_PATTERNS];
3542 +} DialogMatchPatternGroupElement;
3544 +typedef struct _DialogMatchPatternSequenceElement {
3546 + MatchPatternType dmpseType;
3549 +} DialogMatchPatternSequenceElement;
3551 +typedef struct _DialogMatchPatternInfo {
3552 + int dmpiNbrOfSeqElements;
3553 + DialogMatchPatternSequenceElement *dmpiSequence[MAX_NBR_SEQ_ELEMENTS];
3554 +} DialogMatchPatternInfo;
3560 +} DMPTranslationResult;
3562 +typedef struct _NameList {
3564 + char *nlId[MAX_NBR_SEQ_ELEMENTS + 1];
3568 + * prototypes of local functions
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(
3601 + int *globalToLocalBackRef);
3602 +static int localToGlobalBackRef(
3603 + int *globalToLocalBackRef,
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(
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(
3638 + int *commonLocalId);
3639 +static void scanForLocalBackRefs(
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(
3668 + ErrorInfo *errInfo);
3670 +static char *createMatchPatternsString(
3671 + StringMatchTable *table,
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(
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(
3707 + ErrorInfo *errInfo,
3708 + ReadMatchPatternInfo *info);
3709 +static void recordPatternSequence(
3710 + ReadMatchPatternInfo *info,
3712 + MatchPatternType type,
3714 +static int assignIndividualGroup(
3715 + ReadMatchPatternInfo *info,
3717 + MatchPatternTableElement *element);
3718 +static MatchPatternTableElement *getPatternOfName(
3719 + ReadMatchPatternInfo *info,
3720 + char *subPatToSearch);
3721 +static MatchPatternGroupElement *readMatchPatternGroup(
3723 + ErrorInfo *errInfo,
3725 + ReadMatchPatternInfo *info);
3726 +static int readPatternElement(
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,
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,
3773 + GlobalBackRefElement *backRefList,
3774 + ErrorInfo *errInfo);
3775 +static char *replaceBackRefIdByRegExp(
3776 + StringPattern *strPat,
3777 + char *replaceStartPtr,
3779 +static char *convertGlobalToLocalBackRef(
3780 + StringPattern *strPat,
3781 + char *convertPtr);
3783 +static MatchPatternTableElement *readMatchPatternTableElement(
3787 + MatchPatternType type);
3788 +static int sortReadPatternElementSet(
3789 + PatternElementSet *allPat,
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(
3804 + ErrorInfo *errInfo,
3806 +static int getMPSTypeAttribute(
3808 + ErrorInfo *errInfo,
3809 + MatchPatternType *type);
3810 +static int getMPSGlobalAttribute(
3813 + int *isMonoPattern,
3816 + int *ignoreHighLightInfo);
3817 +static int getMPSPatternAttribute(
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,
3878 +static void setStringPatternDisplayedCB(void *item, void *cbArg);
3879 +static void freeStringPatternItemCB(void *item);
3881 +static void *getMatchPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
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(
3907 + char *currentSubPatName,
3908 + int allSubPatterns);
3909 +static void setupSubPatternNameList(
3910 + char *currentSubPatName,
3911 + int allSubPatterns,
3912 + NameList *nameList);
3913 +static void createSubPatNameMenuEntry(
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
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;
4016 + Widget gabSyntaxBasedW;
4017 + Widget mpdStringPatternsLbl;
4018 + Widget mpdStringPatternsListW;
4019 + Widget mpdStringPatternTypeLbl;
4021 + Widget sptMiddleW;
4023 + Widget mpdWordBoundaryLbl;
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,
4055 + * Matching pattern sources loaded from the nedit resources file or set
4058 +static int NbrMatchTables = 0;
4059 +static StringMatchTable *MatchTables[MAX_LANGUAGE_MODES];
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..
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
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
4102 +static char *DefaultStringMatchTable[] = {
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}",
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}",
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}",
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}",
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}",
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}",
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}",
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}",
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}",
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}",
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}",
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}",
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}",
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}",
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;
4241 + if (langModeName == NULL)
4242 + nameToSearch = PLAIN_LM_STRING;
4244 + nameToSearch = langModeName;
4246 + for (i=0; i<NbrMatchTables; i++)
4247 + if (!strcmp(nameToSearch, MatchTables[i]->smtLanguageMode))
4248 + return (void *)MatchTables[i];
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)
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)
4286 + for (i=0; i<NbrMatchTables; i++)
4288 + if (!strcmp(langModeName, MatchTables[i]->smtLanguageMode))
4291 + * free (delete) existing matching pattern
4293 + freeStringMatchTable(MatchTables[i]);
4296 + &MatchTables[i+1],
4297 + (NbrMatchTables-1 - i) * sizeof(StringMatchTable *));
4305 +** Assign a standard string match table to a given new language mode.
4307 +void AssignStandardStringMatchTable(const char *langModeName)
4310 + StringMatchTable *newTable;
4313 + * assign standard table for new language mode
4314 + * add table to end
4316 + list = StandardStringMatchTable;
4318 + readMatchPatternSetContent(&list, list, XtNewString(langModeName));
4321 + * add table to end
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)
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;
4355 + * read each matching pattern set
4357 + table = readMatchPatternSet(&inPtr);
4359 + if (table != NULL)
4362 + * add/change the pattern set in the list
4364 + for (i=0; i<NbrMatchTables; i++)
4366 + if (!strcmp(MatchTables[i]->smtLanguageMode, table->smtLanguageMode))
4368 + freeStringMatchTable(MatchTables[i]);
4369 + MatchTables[i] = table;
4373 + if (i == NbrMatchTables)
4375 + MatchTables[NbrMatchTables++] = table;
4376 + if (NbrMatchTables > MAX_LANGUAGE_MODES)
4384 + * find end of this pattern. if the string ends here, we're done
4386 + inPtr = strstr(inPtr, "\n");
4387 + if (inPtr == NULL)
4393 + * skip newline, tabs & spaces in front of next pattern.
4394 + * if the string ends here, we're done
4396 + inPtr += strspn(inPtr, " \t\n");
4397 + if (*inPtr == '\0')
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];
4424 + BufInsert(outBuf, outBuf->length, table->smtLanguageMode);
4425 + BufInsert(outBuf, outBuf->length, ":");
4427 + if (isDefaultMatchPatternTable(table))
4429 + BufInsert(outBuf, outBuf->length, "Default\n\t");
4433 + BufInsert(outBuf, outBuf->length, "{\n");
4434 + BufInsert(outBuf, outBuf->length,
4435 + str = createMatchPatternsString(table, "\t\t"));
4437 + BufInsert(outBuf, outBuf->length, "\t}\n\t");
4442 + * Get the output string, and lop off the trailing newline and tab
4444 + outStr = BufGetRange(outBuf, 0, outBuf->length - (written?2:0));
4448 + * Protect newlines and backslashes from translation by the resource
4451 + escapedStr = EscapeSensitiveChars(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;
4476 + * No duplicate check needed, if previous pattern is a reference,
4477 + * due to the related multi pattern element is checked before.
4479 + if (prevPattern->peType == PET_REFERENCE)
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)
4492 + * Patterns are identical: Is prevPattern already a multi pattern ?
4494 + if (prevPattern->peType == PET_MULTIPLE)
4497 + * just add ref. to "lastPattern" to the ref. list
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) );
4505 + prevPattern->peVal.peuMulti.mpRefList,
4507 + (nbrOfRef-1) * sizeof(PatternReference) );
4508 + prevPattern->peVal.peuMulti.mpRefList[nbrOfRef-1] = lastPatRef;
4509 + XtFree( (char *)oldList );
4514 + * convert prev. single pattern to multi pattern
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;
4526 + * convert last single pattern to reference
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)
4547 + PatternReference prevPatRef;
4549 + prevPatRef.prElementIdx = prevElementIdx;
4551 + for (i=0; i<prevElement->mpteAll.pesNumberOfPattern; i++)
4553 + prevPatRef.prPatternIdx = i;
4554 + treatDuplicatedPattern(
4556 + prevElement->mpteAll.pesPattern[i],
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
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)
4577 + PatternReference lastPatRef;
4579 + lastPatRef.prElementIdx = lastElementIdx;
4581 + for (i=0; i<lastElement->mpteAll.pesNumberOfPattern; i++)
4583 + lastPatRef.prPatternIdx = i;
4584 + treatDuplicatedPatternElements(
4588 + lastElement->mpteAll.pesPattern[i],
4594 +** Convert all duplicated patterns of given match pattern table to
4597 +static void treatDuplicatedMTEntries(
4598 + MatchPatternTableElement **element,
4599 + int nbrOfElements)
4602 + MatchPatternTableElement *lastElement;
4603 + int lastElementIdx;
4604 + MatchPatternTable table;
4606 + if (nbrOfElements < 2)
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)
4632 + StringPattern *strPat;
4634 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i++)
4636 + strPat = getReadStringPattern(readPatInfo, element->mpteAll.pesPattern[i]);
4639 + * if current string pattern holds a regular expression, then
4642 + if (strPat->spRegularExpression)
4644 + if (createStrPatRegExp(strPat, errInfo))
4647 + * compilation was not successful
4649 + errInfo->eiMPTabElementName = XtNewString(element->mpteName);
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;
4670 + * compose regular expression for start string pattern.
4672 + if( strPat->spCaseInsensitive)
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.
4679 + regExpString = XtMalloc(strPat->spLength + 5);
4680 + strcpy(regExpString, "(?i");
4681 + strcat(regExpString, strPat->spText);
4682 + strcat(regExpString, ")");
4686 + regExpString = strPat->spText;
4690 + * compile regular expression & free allocated string buffer,
4693 + strPat->spTextRE =
4694 + CompileRE(regExpString, &compileMsg, REDFLT_STANDARD);
4696 + if (strPat->spTextRE == NULL)
4699 + * compilation was not successful: adapt error reason by
4700 + * converting local backrefs to global ones.
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(
4720 + int *globalToLocalBackRef)
4724 + char *s = compileMsg;
4726 + while (*s != '\0')
4730 + if (isdigit((unsigned char)*(s+1)))
4733 + * \n (n=1..9) found: substitute local by global back ref.
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')
4752 +** translate given local backref to global backref by using
4753 +** given globalToLocalBackRef list.
4755 +static int localToGlobalBackRef(
4756 + int *globalToLocalBackRef,
4761 + for (i=0; i < MAX_GLOBAL_BACK_REF_ID; i++)
4763 + if (globalToLocalBackRef[i] == localId)
4771 +** Create a regular expression holding keywords of given start & end
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;
4784 + * compose regular expression for start / end pattern.
4786 + composeStartEndRegExpString(
4787 + readMatchPatternInfo,
4792 + * compile regular expression & free allocated string buffer.
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)
4818 + MatchPatternTableElement *element;
4819 + RegExpStringInfo regExpStringInfo;
4820 + char *regExpString;
4821 + regexp *keywordRE;
4825 + * Allocate buffers for keyword regular expression of this group.
4827 + setupRegExpStringBuffers(
4829 + ®ExpStringInfo);
4831 + for (i=0; i<group->mpgeNumberOfSubPatterns; i++)
4833 + element = getPatternOfName(readPatInfo, group->mpgeSubPatternIds[i]);
4835 + * Add the keywords of the sub pattern to the keyword regular
4836 + * expression string buffer of new group.
4838 + addElementToRegExpString(
4841 + ®ExpStringInfo);
4845 + * Assemble and compile the resulting keyword regular expression string.
4847 + catSMTRegExpStrings(
4848 + ®ExpStringInfo,
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)
4876 + int nbrOfMultiPatterns;
4877 + int sizeOfPatRefs;
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.
4885 + totalKeywordOfTableLen( readMatchPatternInfo, &nbrOfMultiPatterns );
4888 + * allocate memory to store added multi pattern references (to avoid
4889 + * duplicated keywords strings later on).
4891 + sizeOfPatRefs = sizeof(PatternReference *) * nbrOfMultiPatterns;
4893 + regExpStringInfo->resiAddedMultiPat =
4894 + (PatternReference **)XtMalloc( sizeOfPatRefs );
4896 + regExpStringInfo->resiNbrOfAddedMultiPat = 0;
4899 + * init. ID of capturing local backrefs
4901 + regExpStringInfo->resiLocalBackRefID = 1;
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.
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(
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,
4950 + char *outStr, *str;
4951 + textBuffer *outBuf;
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, ":");
4981 + if (seq->mpseType == MPT_SUB)
4983 + BufInsert(outBuf, outBuf->length, "s");
4985 + BufInsert(outBuf, outBuf->length, ":");
4987 + element = table->smtAllPatterns->mptElements[seq->mpseIndex];
4990 + * write global attributes
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, ":");
5003 + * write string patterns
5005 + for (j=0; j < element->mpteAll.pesNumberOfPattern; j ++)
5011 + createPatternElementString(
5012 + table->smtAllPatterns,
5013 + element->mpteAll.pesPattern[j]));
5018 + BufInsert(outBuf, outBuf->length, "\n");
5021 + outStr = BufGetAll(outBuf);
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);
5043 + * write string pattern kind
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");
5053 + * write word boundary
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");
5063 + * write case insensitive flag
5065 + if (strPat->spCaseInsensitive)
5066 + BufInsert(outBuf, outBuf->length, "i");
5069 + * write regular expression flag
5071 + if (strPat->spRegularExpression)
5072 + BufInsert(outBuf, outBuf->length, "x");
5074 + BufInsert(outBuf, outBuf->length, ":");
5077 + * write pattern string
5079 + if( strPat->spOrigText != NULL)
5083 + str = MakeQuotedString(strPat->spOrigText));
5088 + str = MakeQuotedString(strPat->spText));
5091 + BufInsert(outBuf, outBuf->length, ":");
5093 + outStr = BufGetAll(outBuf);
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;
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
5130 +static int isDefaultMatchPatternTable(StringMatchTable *table)
5132 + StringMatchTable *defaultTable;
5135 + defaultTable = readDefaultStringMatchTable(table->smtLanguageMode);
5137 + if (defaultTable == NULL)
5140 + retVal = !stringMatchTableDiffer(table, defaultTable);
5142 + freeStringMatchTable(defaultTable);
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);
5162 + * remove leading whitespace
5164 + *inPtr += strspn(*inPtr, " \t\n");
5167 + * read language mode field
5169 + languageMode = ReadSymbolicField(inPtr);
5172 + * look for initial brace
5174 + if (**inPtr == ':')
5178 + * look for "Default" keyword, and if it's there, return the default
5181 + if (!strncmp(*inPtr, "Default", 7))
5184 + table = readDefaultStringMatchTable(languageMode);
5185 + XtFree(languageMode);
5191 + table = readMatchPatternSetContent(inPtr, stringStart, languageMode);
5193 + if (table == NULL)
5194 + XtFree(languageMode);
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(
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);
5218 + * look for initial brace
5220 + if (**inPtr != '{')
5222 + errInfo.eiLanguageMode = XtNewString(languageMode);
5223 + errInfo.eiDetail = "pattern list must begin with \"{\"";
5224 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo );
5231 + readPatInfo.rmpiNbrOfElements = 0;
5232 + readPatInfo.rmpiNbrOfGroups = 0;
5233 + readPatInfo.rmpiNbrOfSeqElements = 0;
5234 + readPatInfo.rmpiAllPatRE = NULL;
5235 + readPatInfo.rmpiFlashPatRE = NULL;
5238 + * parse each pattern in the list
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 == '}')
5253 + endOfPatternSet = True;
5257 + if (!readMatchPatternEntry(inPtr, &errInfo, &readPatInfo))
5259 + errInfo.eiLanguageMode = XtNewString(languageMode);
5260 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5261 + successful = False;
5269 + * compile regular expressions of read patterns
5271 + if (createRegExpOfPatterns(&readPatInfo, &errInfo))
5273 + parseMatchingPatternSetError(stringStart, *inPtr, &errInfo);
5274 + successful = False;
5280 + return createStringMatchTable(&readPatInfo, languageMode);
5285 + * free memory of already read patterns
5287 + freeReadMatchPatternInfo(&readPatInfo);
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))
5306 + if (createRegExpOfAllPatterns(readPatInfo, errInfo))
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)
5322 + RegExpStringInfo allPatRegExpSI;
5323 + RegExpStringInfo flashPatRegExpSI;
5324 + MatchPatternTableElement *element;
5325 + char *regExpString;
5329 + * Allocate buffers for keyword regular expressions.
5331 + setupRegExpStringBuffers(readPatInfo, &allPatRegExpSI);
5332 + setupRegExpStringBuffers(readPatInfo, &flashPatRegExpSI);
5334 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5336 + element = readPatInfo->rmpiElement[i];
5339 + * Add the keywords of the matching pattern to the keyword
5340 + * regular expression string buffer of all patterns.
5342 + addElementToRegExpString(
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.
5352 + if (element->mpteFlash)
5354 + addElementToRegExpString(
5357 + &flashPatRegExpSI);
5362 + * Assemble and compile the resulting all keywords reg. exp. string.
5364 + catSMTRegExpStrings(
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";
5381 + * Assemble and compile the resulting flash keywords reg. exp. string.
5383 + catSMTRegExpStrings(
5384 + &flashPatRegExpSI,
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";
5400 + * Pattern reg. exp. successful created:
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)
5415 + MatchPatternTableElement *element;
5416 + MatchPatternGroupElement *group;
5419 + * create global backref list of all elements of read info
5421 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5423 + element = readPatInfo->rmpiElement[i];
5425 + if (!createGlobalBackRefList(readPatInfo, element, errInfo))
5430 + * resolve global backrefs of all elements of read info
5432 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5434 + element = readPatInfo->rmpiElement[i];
5436 + if (!resolveGlobalBackRefs(readPatInfo, element, errInfo))
5441 + * compile reg. exp. of all elements of read info
5443 + for (i=0; i < readPatInfo->rmpiNbrOfElements; i ++)
5445 + element = readPatInfo->rmpiElement[i];
5447 + if (createStrPatRegExpOfElement(readPatInfo, element, errInfo))
5451 + * create start / end reg. exp. if applicable.
5453 + if (element->mpteSkipBtwnStartEnd)
5455 + if (createStartEndRegExp(readPatInfo, element, errInfo))
5461 + * compile reg. exp. of all groups of read info
5463 + for (i=0; i < readPatInfo->rmpiNbrOfGroups; i ++)
5465 + group = readPatInfo->rmpiGroup[i];
5467 + if (createGroupRegExp(readPatInfo, group, errInfo))
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;
5491 + * allocate a more appropriately sized list to return matching patterns
5493 + patTable = (MatchPatternTable *)XtMalloc(sizeof(MatchPatternTable));
5494 + patTable->mptNumberOfElements = readPatInfo->rmpiNbrOfElements;
5496 + if (readPatInfo->rmpiNbrOfElements > 0)
5499 + sizeof(MatchPatternTableElement *) * readPatInfo->rmpiNbrOfElements;
5500 + patTable->mptElements =
5501 + (MatchPatternTableElement **)XtMalloc(sizeOfElements);
5502 + memcpy(patTable->mptElements, readPatInfo->rmpiElement, sizeOfElements);
5506 + patTable->mptElements = NULL;
5509 + table->smtAllPatterns = patTable;
5511 + table->smtAllPatRE = readPatInfo->rmpiAllPatRE;
5512 + table->smtFlashPatRE = readPatInfo->rmpiFlashPatRE;
5513 + table->smtUsedPatRE = NULL;
5516 + * allocate a more appropriately sized list to return matching pattern groups
5518 + table->smtNumberOfGroups = readPatInfo->rmpiNbrOfGroups;
5519 + if (readPatInfo->rmpiNbrOfGroups > 0)
5522 + sizeof(MatchPatternGroupElement *) * readPatInfo->rmpiNbrOfGroups;
5523 + table->smtGroups =
5524 + (MatchPatternGroupElement **)XtMalloc(sizeOfElements);
5525 + memcpy(table->smtGroups, readPatInfo->rmpiGroup, sizeOfElements);
5529 + table->smtGroups = NULL;
5532 + * allocate a more appropriately sized list to return matching pattern sequence
5534 + table->smtNumberOfSeqElements = readPatInfo->rmpiNbrOfSeqElements;
5535 + if (readPatInfo->rmpiNbrOfSeqElements > 0)
5538 + sizeof(MatchPatternSequenceElement *) * readPatInfo->rmpiNbrOfSeqElements;
5539 + table->smtSequence =
5540 + (MatchPatternSequenceElement **)XtMalloc(sizeOfElements);
5541 + memcpy(table->smtSequence, readPatInfo->rmpiSequence, sizeOfElements);
5545 + table->smtSequence = NULL;
5552 +** Read one match pattern entry of a match pattern string.
5553 +** Returns true, if read was successful.
5555 +static int readMatchPatternEntry(
5557 + ErrorInfo *errInfo,
5558 + ReadMatchPatternInfo *info)
5561 + MatchPatternType type;
5562 + MatchPatternGroupElement *readGroup;
5563 + MatchPatternTableElement *readElement;
5565 + if (!getMPSName( inPtr, errInfo, &name ))
5570 + if (!getMPSTypeAttribute( inPtr, errInfo, &type ))
5572 + errInfo->eiMPTabElementName = XtNewString(name);
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";
5585 + readGroup = readMatchPatternGroup( inPtr, errInfo, name, info );
5587 + if (readGroup == NULL)
5589 + errInfo->eiMPTabElementName = XtNewString(name);
5594 + info->rmpiGroup[info->rmpiNbrOfGroups ++] = readGroup;
5596 + recordPatternSequence( info, name, type, info->rmpiNbrOfGroups-1 );
5599 + return (readGroup != NULL);
5603 + if (info->rmpiNbrOfElements >= MAX_NBR_MATCH_PATTERNS)
5605 + errInfo->eiMPTabElementName = XtNewString(name);
5606 + errInfo->eiDetail = "max number of match patterns exceeded";
5612 + readMatchPatternTableElement( inPtr, &errInfo->eiDetail, name, type );
5614 + if (readElement == NULL)
5616 + errInfo->eiMPTabElementName = XtNewString(name);
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);
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,
5650 + MatchPatternType type,
5653 + MatchPatternSequenceElement *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,
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";
5683 + * Assign the index of new group to the individual matching pattern
5685 + element->mpteGroup = info->rmpiNbrOfGroups;
5688 + * Allocate memory for the matching pattern group and copy the
5689 + * info into this group element.
5692 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
5694 + group->mpgeName = NULL;
5695 + group->mpgeKeywordRE = NULL;
5698 + * remember name of match pattern table element, which is
5699 + * represented by this group.
5701 + group->mpgeNumberOfSubPatterns = 1;
5702 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeof(char *) );
5703 + group->mpgeSubPatternIds[0] = XtNewString(element->mpteName);
5705 + info->rmpiGroup[info->rmpiNbrOfGroups ++] = group;
5711 +** Get the match pattern table element of given 'patToSearch'
5713 +** Returns NULL, if no element was found.
5715 +static MatchPatternTableElement *getPatternOfName(
5716 + ReadMatchPatternInfo *info,
5717 + char *patToSearch)
5720 + MatchPatternTableElement *element;
5722 + for (i=0; i<info->rmpiNbrOfElements; i ++)
5724 + element = info->rmpiElement[i];
5726 + if (strcmp( element->mpteName, patToSearch ) == 0)
5729 + * Related sub-pattern found:
5736 + * No sub-pattern found:
5742 +** Read match pattern group of given match pattern string.
5743 +** Returns NULL, if read fails.
5745 +static MatchPatternGroupElement *readMatchPatternGroup(
5747 + ErrorInfo *errInfo,
5749 + ReadMatchPatternInfo *info)
5752 + int error = False;
5753 + char *patNameInPtr;
5755 + MatchPatternTableElement *subPatElement;
5756 + int numberOfRelatedSubPattern = 0;
5757 + char *relatedSubPatternId[MAX_NBR_MATCH_PATTERNS];
5759 + MatchPatternGroupElement *group = NULL;
5762 + * Read sub-matching patterns of this group.
5764 + while (**inPtr != '\n' && !error)
5767 + * Read next pattern name from inPtr.
5769 + patNameInPtr = *inPtr;
5770 + subPatName = ReadSymbolicField(inPtr);
5772 + if (subPatName == NULL)
5774 + errInfo->eiDetail = "Sub-Matching Pattern Name expected";
5780 + * Get matching pattern related to sub-matching pattern name.
5783 + getPatternOfName( info, subPatName );
5785 + if (subPatElement == NULL)
5787 + errInfo->eiStringPatText = XtNewString(subPatName);
5788 + errInfo->eiDetail = "Sub-Matching Pattern not defined before";
5791 + else if (numberOfRelatedSubPattern >= MAX_NBR_MATCH_PATTERNS)
5793 + errInfo->eiDetail = "Group holds too many Sub-Matching Patterns";
5796 + else if (subPatElement->mpteType != MPT_SUB)
5798 + errInfo->eiStringPatText = XtNewString(subPatName);
5799 + errInfo->eiDetail = "Not a Sub-Matching Pattern";
5805 + * Remember sub-matching pattern ID
5807 + relatedSubPatternId[numberOfRelatedSubPattern ++] = subPatName;
5810 + * Assign the index of this group to the sub-matching pattern
5811 + * if no group index was assigned before.
5813 + if (subPatElement->mpteGroup == NO_GROUP_IDX)
5815 + subPatElement->mpteGroup = info->rmpiNbrOfGroups;
5820 + * Skip to the start of the next matching pattern name.
5822 + if (!error && !SkipDelimiter(inPtr, &errInfo->eiDetail))
5831 + for (i=0; i < numberOfRelatedSubPattern; i++)
5833 + XtFree( relatedSubPatternId[i] );
5841 + * Allocate memory for the matching pattern group and copy the
5842 + * info into this group element.
5845 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
5847 + group->mpgeName = name;
5848 + group->mpgeKeywordRE = NULL;
5851 + * Allocate memory for the sub-matching pattern IDs & copy
5852 + * related sub-matching pattern into the group element.
5854 + sizeOfIds = sizeof(char *) * numberOfRelatedSubPattern;
5855 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeOfIds );
5857 + memcpy(group->mpgeSubPatternIds, relatedSubPatternId, sizeOfIds);
5859 + group->mpgeNumberOfSubPatterns = numberOfRelatedSubPattern;
5866 +** Read one match pattern element from given match pattern string.
5867 +** Returns true, if read was successful.
5869 +static int readPatternElement(
5872 + PatternElement **pattern)
5874 + PatternElementKind patternKind;
5875 + PatternWordBoundary wordBoundary;
5876 + int caseInsensitive;
5877 + int regularExpression;
5880 + if (!getMPSPatternAttribute(
5886 + ®ularExpression ))
5891 + if (!ReadQuotedString(inPtr, errMsg, &string))
5896 + if (!SkipDelimiter(inPtr, errMsg))
5903 + createPatternElement(
5908 + regularExpression);
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;
5927 + * Convert pattern text to lower case, if case insensitive
5928 + * attribute is set.
5930 + if (caseInsensitive)
5932 + for (s = patternText; *s != '\0'; s ++)
5939 + * Allocate memory for the new pattern element and init. / copy
5940 + * related info into this pattern element.
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;
5959 + * Store original string of regular expression patterns due to
5960 + * it may be later adapted (e.g. due to global backrefs etc.).
5962 + if (regularExpression)
5964 + pattern->peVal.peuSingle.spOrigText = patternText;
5965 + pattern->peVal.peuSingle.spText = NULL;
5966 + pattern->peVal.peuSingle.spWordBoundary = PWB_NONE;
5970 + pattern->peVal.peuSingle.spOrigText = NULL;
5971 + pattern->peVal.peuSingle.spText = patternText;
5972 + pattern->peVal.peuSingle.spWordBoundary = wordBoundary;
5979 +** Create a list holding all global backref definitions of given
5980 +** match pattern table element. The list is stored in this given
5982 +** Returns true, if list was successfully created.
5984 +static int createGlobalBackRefList(
5985 + ReadMatchPatternInfo *readPatInfo,
5986 + MatchPatternTableElement *element,
5987 + ErrorInfo *errInfo)
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)
6001 + * Global backrefs or this string pattern already parsed:
6002 + * just merge string pattern list with elements one.
6004 + if (!updateGlobalBackRefs(
6006 + element->mpteGlobalBackRef,
6015 + * parse string pattern for global backrefs and
6016 + * merge string pattern list with elements one.
6018 + if (!parseGlobalBackRefs(
6020 + element->mpteGlobalBackRef,
6033 +** Returns read string pattern of given pattern element.
6035 +StringPattern *getReadStringPattern(
6036 + ReadMatchPatternInfo *readPatInfo,
6037 + PatternElement *pattern )
6039 + switch (pattern->peType)
6042 + return &pattern->peVal.peuSingle;
6045 + case PET_MULTIPLE:
6046 + return &pattern->peVal.peuMulti.mpStringPattern;
6049 + case PET_REFERENCE:
6050 + return getReadStringPattern(
6052 + getReadPatternOfReference(readPatInfo, &pattern->peVal.peuRef));
6057 + * never reached; just to make compiler happy
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;
6085 + int nbrOfOpenBraces = 0;
6090 + * count number of open braces
6092 + while (*s != '\0')
6095 + nbrOfOpenBraces ++;
6099 + * allocate memory for substitued reg. exp. text
6101 + destination = XtMalloc(strlen(source) + 2*nbrOfOpenBraces);
6104 + * substitute each capturing open brace by a non-capturing one
6109 + while (*s != '\0')
6118 + else if (*s == '(')
6122 + if (*s != '?' && *s != '*')
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)
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')
6168 + * Ignore escaped characters
6170 + if (*(s+1) != '\0')
6173 + else if (*s == '(')
6175 + if (*(s+1) == '*')
6177 + if (isdigit((unsigned char)*(s+2)))
6180 + * Global backref. definition start found:
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";
6194 + backRefInfo[stackIdx].brbiContentStart = s+3;
6195 + backRefInfo[stackIdx].brbiNestingLevel = nestingLevel;
6202 + else if (*s == ')')
6205 + if (stackIdx != -1 &&
6206 + backRefInfo[stackIdx].brbiNestingLevel == nestingLevel)
6209 + * Global backref. definition end found: add it to
6210 + * backref. list of string pattern.
6213 + &strPat->spOwnGlobalBackRef[backRefInfo[stackIdx].brbiGlobalId];
6216 + createBackRefRegExpText(
6217 + backRefInfo[stackIdx].brbiContentStart,
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);
6230 + curStrPatBRE->spbreRegExpText = backRefContent;
6240 + * Merge global backref. list of string pattern with given backRefList.
6242 + return updateGlobalBackRefs(
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)
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";
6282 + curGlobalBRE->gbreDefByStrPat = strPat;
6283 + curGlobalBRE->gbreRegExpText = curStrPatBRE->spbreRegExpText;
6292 +** Allocate and return a new string holding content of
6293 +** global backref. definition.
6295 +static char *createBackRefRegExpText(
6296 + const char *start,
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)
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))
6330 + strPat->spBackRefResolved = 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)
6350 + s = strPat->spText;
6352 + while (*s != '\0')
6356 + if (isdigit((unsigned char)*(s+1)))
6359 + * \n (n=1..9) found: substitute global backref.
6362 + (int)((unsigned char)*(s+1) - (unsigned char)'0') - 1;
6366 + errInfo->eiStringPatText = XtNewString(strPat->spOrigText);
6367 + errInfo->eiDetail = "backref '\\0' not allowed";
6371 + s = substituteGlobalBackRef(strPat, s, globalId, &localId, backRefList, errInfo);
6376 + else if (*(s+1) != '\0')
6379 + else if (*s == '(')
6381 + if (*(s+1) == '*')
6383 + if (isdigit((unsigned char)*(s+2)))
6386 + * "(*n" (n=1..9) found: substitute global backref. definition.
6389 + (int)((unsigned char)*(s+2) - (unsigned char)'0') - 1;
6391 + strPat->spOwnGlobalBackRef[globalId].spbreLocalBackRefID = localId;
6392 + strPat->spGlobalToLocalBackRef[globalId] = localId;
6396 + s = convertGlobalToLocalBackRef(strPat, s);
6411 +** Substitute global backref (\n, n=1..9) located at given "subsPtr"
6412 +** by its definition or by a local backref.
6414 +** - NULL, if substitute fails or
6415 +** - substituted string pointer, where scan shall continue with.
6417 +static char *substituteGlobalBackRef(
6418 + StringPattern *strPat,
6422 + GlobalBackRefElement *backRefList,
6423 + ErrorInfo *errInfo)
6425 + StrPatBackRefElement *strPatBackRef = &strPat->spOwnGlobalBackRef[globalId];
6428 + if (strPatBackRef->spbreRegExpText == NULL)
6431 + * given global backref definition is not located in given
6432 + * string pattern -> replace backref ID by backref reg. exp.
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";
6442 + if (strPat->spGlobalToLocalBackRef[globalId] == NO_LOCAL_BACK_REF_ID)
6445 + * 1st occurence of global backref ID in this pattern ->
6446 + * replace global backref ID by backref reg. exp.
6448 + s = replaceBackRefIdByRegExp(strPat, subsPtr, backRefList[globalId].gbreRegExpText);
6450 + strPat->spGlobalToLocalBackRef[globalId] = *localId;
6456 + * next occurence of global backref ID in this pattern ->
6457 + * replace global backref ID by local one
6460 + *s = (char)((int)('0') + strPat->spGlobalToLocalBackRef[globalId]);
6466 + * given global backref definition is located in given string pattern
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";
6477 + * replace global backref ID by local one
6480 + *s = (char)((int)('0') + strPatBackRef->spbreLocalBackRefID);
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,
6496 + char *oldText = strPat->spText;
6499 + char *continueScanPtr;
6500 + int oldLen = strlen(oldText);
6501 + int regExpLen = strlen(regExp);
6502 + int replacePos = replaceStartPtr - oldText;
6503 + int remainingLen = oldLen-replacePos-2;
6506 + * replace "\n" - located at replaceStartPtr - by "(regExp)"
6508 + newText = XtMalloc(oldLen + regExpLen + 3);
6510 + memcpy(newText, oldText, replacePos);
6511 + n = newText + replacePos;
6513 + continueScanPtr = n;
6515 + memcpy(n, regExp, regExpLen);
6519 + memcpy(n, replaceStartPtr+2, remainingLen);
6520 + *(n + remainingLen) = '\0';
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,
6539 + char *oldText = strPat->spText;
6541 + int oldLen = strlen(oldText);
6542 + int convertPos = convertPtr - oldText;
6545 + * replace "(*n" - located at convertPtr - by "("
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';
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(
6570 + MatchPatternType type)
6572 + int error = False;
6573 + PatternElement *pattern;
6574 + PatternElement *allPat[MAX_STRING_PATTERNS];
6577 + MatchPatternTableElement *result;
6578 + int isMonoPattern;
6579 + int skipBtwStartEnd;
6581 + int ignoreHighLightInfo;
6584 + if (!getMPSGlobalAttribute(
6590 + &ignoreHighLightInfo ))
6596 + * read all patterns
6598 + while (**inPtr != '\n' && !error)
6600 + if (!readPatternElement( inPtr, errMsg, &pattern ))
6604 + else if (nbrOfPat >= MAX_STRING_PATTERNS)
6606 + *errMsg = "max. number of string patterns exceeded";
6611 + pattern->peIndex = nbrOfPat;
6613 + allPat[nbrOfPat ++] = pattern;
6619 + for (i=0; i < nbrOfPat; i ++)
6620 + freePatternElement( allPat[i] );
6625 + if (nbrOfPat == 0)
6627 + *errMsg = "min. one string pattern needed";
6632 + * allocate & init. MatchPatternTableElement
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 );
6659 + * sort start / end / middle pattern
6661 + error = !sortReadPatternElementSet( &result->mpteAll, errMsg, result );
6665 + freeMatchPatternTableElement( result );
6675 + * Sort read pattern element set into start, middle & end arrays.
6676 + * Validate "monopattern" attribute.
6677 + * Returns true, if validation was successful.
6679 +static int sortReadPatternElementSet(
6680 + PatternElementSet *allPat,
6682 + MatchPatternTableElement *result)
6685 + int isMonoPattern = result->mpteIsMonoPattern;
6688 + * count number of start, middle & end pattern elements.
6690 + countPatternElementKind( allPat, result );
6693 + * validate and allocate pattern elements.
6695 + if (result->mpteStart.pesNumberOfPattern != 0)
6697 + sizeOfPat = sizeof(PatternElement *) * result->mpteStart.pesNumberOfPattern;
6698 + result->mpteStart.pesPattern = (PatternElement **)XtMalloc( sizeOfPat );
6702 + *errMsg = "min. one start pattern needed";
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]";
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 );
6727 + if (!isMonoPattern)
6729 + *errMsg = "min. one end pattern needed";
6735 + * sort pattern elements into start, middle & end arrays.
6737 + sortPatternElementSet( allPat, result );
6739 + if (isMonoPattern)
6741 + copyPatternSet( &result->mpteStart, &result->mpteEnd );
6748 + * Count number of start, middle & end patterns stored in "allPat".
6750 +static void countPatternElementKind(
6751 + PatternElementSet *allPat,
6752 + MatchPatternTableElement *result)
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)
6769 + result->mpteStart.pesNumberOfPattern ++;
6772 + result->mpteMiddle.pesNumberOfPattern ++;
6775 + result->mpteEnd.pesNumberOfPattern ++;
6783 + * Sort start, middle & end pattern elements into related arrays.
6785 +static void sortPatternElementSet(
6786 + PatternElementSet *allPat,
6787 + MatchPatternTableElement *result)
6792 + for (i=0, s=0, m=0, e=0; i < allPat->pesNumberOfPattern; i ++)
6794 + switch (allPat->pesPattern[i]->peKind)
6797 + result->mpteStart.pesPattern[s ++] = allPat->pesPattern[i];
6800 + result->mpteMiddle.pesPattern[m ++] = allPat->pesPattern[i];
6803 + result->mpteEnd.pesPattern[e ++] = allPat->pesPattern[i];
6810 +static void copyPatternSet(
6811 + PatternElementSet *sourcePS,
6812 + PatternElementSet *destPS)
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 )
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;
6853 + if (table == NULL)
6856 + XtFree(table->smtLanguageMode);
6859 + * Free all matching patterns
6861 + patTable = table->smtAllPatterns;
6863 + for (i=0; i<patTable->mptNumberOfElements; i++)
6864 + freeMatchPatternTableElement(patTable->mptElements[i]);
6866 + XtFree((char *)patTable);
6869 + * Free matching pattern group elements
6871 + for (i=0; i<table->smtNumberOfGroups; i++)
6872 + freeMatchPatternGroupElement(table->smtGroups[i]);
6875 + * Free matching pattern sequence elements
6877 + for (i=0; i<table->smtNumberOfSeqElements; i++)
6878 + freeMatchPatternSequenceElement(table->smtSequence[i]);
6881 + * Free keyword reg. expressions
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 )
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 )
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 )
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 = "";
6991 + char *errorInForm = "matching pattern of \"%s\"";
6994 + if (errInfo->eiLanguageMode == NULL)
6996 + errorIn = "matching pattern";
7000 + errorIn = XtMalloc(strlen(errorInForm) + strlen(errInfo->eiLanguageMode)+1);
7001 + sprintf(errorIn, "matching pattern of \"%s\"", errInfo->eiLanguageMode);
7004 + if (errInfo->eiRegExpCompileMsg != NULL)
7007 + * Error message of form:
7008 + * "MP \"eiMPTabElementName\", SP \"eiStringPatText\": eiRegExpCompileMsg" or
7009 + * "MP \"eiMPTabElementName\" - eiDetail: eiRegExpCompileMsg"
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);
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);
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)
7055 + * Error message of form:
7056 + * "MP \"eiMPTabElementName\", SP \"eiStringPatText\": Backref %d eiDetail
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)
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)
7092 + if (errInfo->eiLanguageMode != NULL)
7097 + freeErrorInfo(errInfo);
7098 + initErrorInfo(errInfo);
7102 + * Pop-up a warning dialog showing a matching pattern set error.
7104 +static void dialogMatchingPatternSetError(
7106 + ErrorInfo *errInfo)
7112 + * Error message of form:
7113 + * "Name : \"eiMPTabElementName\"\n
7114 + * "String: \"eiStringPatText\"\n
7116 + * eiRegExpCompileMsg\n"
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)
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);
7146 + DF_WARN, MatchPatternDialog.mpdShell, 1,
7148 + "%s(language mode '%s')",
7151 + errInfo->eiLanguageMode);
7155 + freeErrorInfo(errInfo);
7156 + initErrorInfo(errInfo);
7160 +** Get matching pattern set name.
7162 +** patternName ::= "name:"
7163 +** Returns true, if get was successful.
7165 +static int getMPSName(
7167 + ErrorInfo *errInfo,
7171 + char *field = ReadSymbolicField(inPtr);
7173 + if (field == NULL)
7175 + errInfo->eiDetail = "matching pattern name missing";
7179 + if (!SkipDelimiter(inPtr, &dummy))
7181 + errInfo->eiMPTabElementName = XtNewString(field);
7182 + errInfo->eiDetail = "':' missing after matching pattern name";
7193 +** Get matching pattern set type attribute.
7194 +** TypeAttribute ::=
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(
7205 + ErrorInfo *errInfo,
7206 + MatchPatternType *type)
7208 + char *field = ReadSymbolicField(inPtr);
7209 + int successful = True;
7211 + *type = MPT_INDIVIDUAL;
7213 + if (field != NULL)
7218 + *type = MPT_GROUP;
7224 + errInfo->eiDetail = "unknown matching pattern type attribute";
7225 + successful = False;
7231 + if (!SkipDelimiter(inPtr, &errInfo->eiDetail))
7233 + successful = False;
7237 + freeXtPtr((void **)&field);
7239 + return successful;
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
7257 +** Returns TRUE, if global attribute was successful read.
7259 +static int getMPSGlobalAttribute(
7262 + int *isMonoPattern,
7265 + int *ignoreHighLightInfo)
7267 + char *field = ReadSymbolicField(inPtr);
7269 + int successful = True;
7271 + *isMonoPattern = False;
7274 + *ignoreHighLightInfo = False;
7276 + if (field != NULL)
7278 + attribute = field;
7279 + while (*attribute != '\0' && successful)
7281 + switch (*attribute)
7290 + *isMonoPattern = True;
7293 + *ignoreHighLightInfo = True;
7296 + *errMsg = "unknown global attribute";
7297 + successful = False;
7305 + if (!SkipDelimiter(inPtr, errMsg))
7307 + successful = False;
7311 + freeXtPtr((void **)&field);
7313 + return successful;
7317 +** Get matching pattern set attribute.
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(
7345 + PatternElementKind *patternKind,
7346 + PatternWordBoundary *wordBoundary,
7347 + int *caseInsensitive,
7348 + int *regularExpression)
7350 + char *field = ReadSymbolicField(inPtr);
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)
7367 + *patternKind = PEK_END;
7370 + *caseInsensitive = True;
7373 + *wordBoundary = PWB_LEFT;
7376 + *patternKind = PEK_MIDDLE;
7379 + *wordBoundary = PWB_RIGHT;
7382 + *patternKind = PEK_START;
7385 + *wordBoundary = PWB_BOTH;
7388 + *regularExpression = True;
7391 + *errMsg = "unknown string pattern attribute";
7392 + successful = False;
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)
7427 + strPat = &patElement->peVal.peuSingle;
7430 + case PET_MULTIPLE:
7431 + strPat = &patElement->peVal.peuMulti.mpStringPattern;
7433 + (*nbrOfMultiPatterns) ++;
7437 + case PET_REFERENCE:
7439 + info->rmpiElement[patElement->peVal.peuRef.prElementIdx]->
7440 + mpteAll.pesPattern[patElement->peVal.peuRef.prPatternIdx];
7442 + strPat = &referredElement->peVal.peuMulti.mpStringPattern;
7447 + * reserve additional 4 characters ("(?i)") for case insensitive search
7449 + if (strPat->spCaseInsensitive)
7450 + patElementLen = strPat->spLength + 4;
7452 + patElementLen = strPat->spLength;
7455 + * reserve additional 4 characters ("(?:)") for regular expression
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)
7475 + for (i=0; i<element->mpteAll.pesNumberOfPattern; i ++)
7478 + patternElementLen(
7480 + element->mpteAll.pesPattern[i],
7481 + nbrOfMultiPatterns );
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)
7498 + *nbrOfMultiPatterns = 0;
7500 + for (i=0; i<info->rmpiNbrOfElements; i ++)
7503 + totalMatchPatternTableElementLen(
7505 + info->rmpiElement[i],
7506 + nbrOfMultiPatterns);
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;
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.
7528 + switch (pattern->spWordBoundary)
7531 + prevLen = strlen( regExpStringInfo->resiNoneWBRegExpString );
7533 + r = regExpStringInfo->resiNoneWBRegExpString + strlen( regExpStringInfo->resiNoneWBRegExpString );
7536 + prevLen = strlen( regExpStringInfo->resiLeftWBRegExpString );
7539 + strcpy( regExpStringInfo->resiLeftWBRegExpString, "<(?:" );
7541 + r = regExpStringInfo->resiLeftWBRegExpString + strlen( regExpStringInfo->resiLeftWBRegExpString );
7544 + prevLen = strlen( regExpStringInfo->resiRightWBRegExpString );
7547 + strcpy( regExpStringInfo->resiRightWBRegExpString, "(?:" );
7549 + r = regExpStringInfo->resiRightWBRegExpString + strlen( regExpStringInfo->resiRightWBRegExpString );
7552 + prevLen = strlen( regExpStringInfo->resiBothWBRegExpString );
7555 + strcpy( regExpStringInfo->resiBothWBRegExpString, "<(?:" );
7557 + r = regExpStringInfo->resiBothWBRegExpString + strlen( regExpStringInfo->resiBothWBRegExpString );
7562 + * add an "or" if there is already a pattern in the buffer
7570 + * add "(?i" to order case insensitive search
7572 + if (pattern->spCaseInsensitive)
7580 + * add "(?:" to group this regular expression
7582 + if (pattern->spRegularExpression)
7588 + adaptedRegExpText =
7589 + adaptLocalBackRefs(
7591 + ®ExpStringInfo->resiLocalBackRefID);
7593 + s = adaptedRegExpText;
7597 + s = pattern->spText;
7601 + * add the pattern characters - evtl. escaped, if special
7602 + * regular expression symbols & pattern is no reg. exp. -
7606 + while (*s != '\0')
7608 + if (!pattern->spRegularExpression)
7639 + * close "reg. exp. group" bracket
7641 + if (pattern->spRegularExpression)
7645 + XtFree(adaptedRegExpText);
7649 + * close case insensitive search bracket
7651 + if (pattern->spCaseInsensitive)
7657 + * terminate added string
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(
7668 + int *commonLocalId)
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];
7678 + * put all local backrefs into "localBackRefList".
7680 + scanForLocalBackRefs(regExpText, localBackRefList);
7682 + while (*s != '\0')
7690 + if (isdigit((unsigned char)*s))
7693 + * \n (n=1..9) found: replace local backref.
7694 + * by "common local 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]);
7711 + else if (*s != '\0')
7714 + * copy escaped character
7719 + else if (*s == '(')
7726 + * non capturing parentheses found -> just copy it
7733 + * capturing parentheses found:
7735 + if (localBackRefList[ownLocalId] == LOCAL_BACK_REF_ID_USED)
7738 + * backref used within given reg. exp. text:
7739 + * remember common local id for replacement later on
7741 + localBackRefList[ownLocalId] = *commonLocalId;
7742 + (*commonLocalId) ++;
7748 + * backref not used within given reg. exp. text:
7749 + * replace capturing parentheses by non capturing one
7763 + * terminate adapted string
7767 + return newRegExpText;
7771 +** Get all local backrefs of given regExpText and put them into
7772 +** given localBackRefList.
7774 +static void scanForLocalBackRefs(
7776 + int *localBackRefList)
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')
7791 + if (isdigit((unsigned char)*(s+1)))
7794 + * \n (n=1..9) found: flag usage in local backref list
7797 + (int)((unsigned char)*(s+1) - (unsigned char)'0') - 1;
7799 + localBackRefList[localId] = LOCAL_BACK_REF_ID_USED;
7803 + else if (*(s+1) != '\0')
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)
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)
7833 + newPR = (PatternReference *)XtMalloc(sizeof(PatternReference));
7835 + *newPR = *toBeAddedPR;
7837 + regExpStringInfo->resiAddedMultiPat[regExpStringInfo->resiNbrOfAddedMultiPat ++] = newPR;
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)
7857 + addPatternToRegExpString(
7858 + &(patElement->peVal.peuSingle),
7859 + regExpStringInfo);
7862 + case PET_MULTIPLE:
7864 + * add element to reg. exp. string only, if it was
7865 + * not added before.
7867 + if (isMultiPatternNotAdded(regExpStringInfo, patElementReference))
7869 + addPatternToRegExpString(
7870 + &(patElement->peVal.peuMulti.mpStringPattern),
7871 + regExpStringInfo);
7875 + case PET_REFERENCE:
7877 + * add referred element to reg. exp. string only, if related
7878 + * multi pattern was not added before.
7880 + referredPatReference = patElement->peVal.peuRef;
7883 + readMatchPatternInfo->rmpiElement[referredPatReference.prElementIdx]->
7884 + mpteAll.pesPattern[referredPatReference.prPatternIdx];
7886 + if (isMultiPatternNotAdded(regExpStringInfo, &referredPatReference))
7888 + addPatternToRegExpString(
7889 + &(referredElement->peVal.peuMulti.mpStringPattern),
7890 + regExpStringInfo);
7897 +** add given MatchPatternTableElement to given reg. ex. strings
7899 +static void addElementToRegExpString(
7900 + MatchPatternTableElement *element,
7901 + ReadMatchPatternInfo *readMatchPatternInfo,
7902 + RegExpStringInfo *regExpStringInfo)
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],
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)
7933 + * allocate & init. a buffer for the resulting regular expression
7936 + strlen( regExpStringInfo->resiNoneWBRegExpString ) +
7937 + strlen( regExpStringInfo->resiLeftWBRegExpString ) +
7938 + strlen( regExpStringInfo->resiRightWBRegExpString ) +
7939 + strlen( regExpStringInfo->resiBothWBRegExpString ) + 5;
7941 + *regExpString = XtMalloc( resultingLen );
7943 + strcpy( *regExpString, "" );
7946 + * add the single parts to the resulting regular expression
7947 + * (= cat of parts separated by an "or")
7949 + addSMTRegExpString( *regExpString, regExpStringInfo->resiNoneWBRegExpString, "" );
7950 + addSMTRegExpString( *regExpString, regExpStringInfo->resiLeftWBRegExpString, ")" );
7951 + addSMTRegExpString( *regExpString, regExpStringInfo->resiRightWBRegExpString, ")>" );
7952 + addSMTRegExpString( *regExpString, regExpStringInfo->resiBothWBRegExpString, ")>" );
7957 + freeRegExpStringInfo( regExpStringInfo );
7961 +** Free the allocated memory contained in a RegExpStringInfo data structure
7963 +static void freeRegExpStringInfo(
7964 + RegExpStringInfo *regExpStringInfo)
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)
7988 + RegExpStringInfo regExpStringInfo;
7989 + PatternReference elementRef;
7990 + PatternElementSet startPat = element->mpteStart;
7991 + PatternElementSet endPat = element->mpteEnd;
7994 + * Allocate buffers for keyword regular expression.
7996 + setupRegExpStringBuffers(
7997 + readMatchPatternInfo,
7998 + ®ExpStringInfo);
8001 + * Treat start / end element of MatchPatternTableElement
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],
8013 + readMatchPatternInfo,
8014 + ®ExpStringInfo);
8017 + for (i=0; i < endPat.pesNumberOfPattern; i ++)
8019 + elementRef.prPatternIdx = endPat.pesPattern[i]->peIndex;
8021 + addUniquePatternToRegExpString(
8022 + endPat.pesPattern[i],
8024 + readMatchPatternInfo,
8025 + ®ExpStringInfo);
8029 + * Assemble the resulting regular expression
8031 + catSMTRegExpStrings(
8032 + ®ExpStringInfo,
8036 +static void copyStringMatchTableForDialog(
8037 + StringMatchTable *sourceTable,
8038 + DialogMatchPatternInfo *dialogTable )
8043 + * if no source table exist (yet), then set nbr. of elements / groups to 0
8045 + if (sourceTable == NULL)
8047 + dialogTable->dmpiNbrOfSeqElements = 0;
8053 + * copy matching pattern sequence
8055 + dialogTable->dmpiNbrOfSeqElements = sourceTable->smtNumberOfSeqElements;
8057 + for (i=0; i < sourceTable->smtNumberOfSeqElements; i ++)
8059 + copySequenceElementForDialog(
8061 + sourceTable->smtSequence[i],
8062 + &dialogTable->dmpiSequence[i] );
8066 +static void *copyMatchPatternElementForDialog(
8067 + MatchPatternTable *table,
8068 + int sourceElementIdx)
8072 + MatchPatternTableElement *sourceElement;
8073 + DialogMatchPatternTableElement *destination;
8075 + sourceElement = table->mptElements[sourceElementIdx];
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(
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);
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)
8125 + DialogMatchPatternGroupElement *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;
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]);
8166 + destSeqElement->dmpsePtr =
8167 + copyMatchPatternElementForDialog(
8168 + sourceTable->smtAllPatterns,
8169 + sourceSeqElement->mpseIndex);
8173 +static DialogMatchPatternSequenceElement *copyDialogSequenceElement(
8174 + DialogMatchPatternSequenceElement *sourceSeq)
8176 + DialogMatchPatternSequenceElement *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;
8190 +static void freeDialogMatchPatternElement(
8191 + DialogMatchPatternTableElement *dialogElement )
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 )
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 );
8241 + freeDialogMatchPatternElement(
8242 + (DialogMatchPatternTableElement *)dialogSeq->dmpsePtr );
8245 + freeXtPtr((void **)&dialogSeq);
8248 +static void copyDialogStringPatternsFromTable(
8249 + DialogMatchPatternTableElement *tableElement,
8250 + DialogStringPatterns *destPatterns)
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)
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)
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)
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)
8350 + destGroup->dmpgeNumberOfSubPatterns =
8351 + sourceNames->dspNumberOfPatterns;
8353 + for (i=0; i<destGroup->dmpgeNumberOfSubPatterns; i++)
8355 + destGroup->dmpgeSubPatternIds[i] =
8357 + sourceNames->dspElements[i]->dspeText);
8363 +** Present a dialog for editing matching pattern information
8365 +void EditMatchPatterns(WindowInfo *window)
8367 + Widget form, lmOptMenu;
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;
8384 + * if the dialog is already displayed, just pop it to the top and return
8386 + if (MatchPatternDialog.mpdShell != NULL)
8388 + RaiseDialogWindow(MatchPatternDialog.mpdShell);
8393 + * decide on an initial language mode
8395 + MatchPatternDialog.mpdLangModeName =
8397 + window->languageMode == PLAIN_LANGUAGE_MODE ?
8398 + PLAIN_LM_STRING : LanguageModeName(window->languageMode));
8401 + * find the associated matching pattern table to edit
8403 + table = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
8406 + * copy the list of patterns to one that the user can freely edit
8408 + copyStringMatchTableForDialog( table, &MatchPatternDialog.mpdTable );
8411 + * init. status information of dialog
8413 + MatchPatternDialog.currentDmptSeqElement = NULL;
8414 + MatchPatternDialog.currentDmptElement = NULL;
8415 + MatchPatternDialog.currentDmptGroup = NULL;
8417 + MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns = 0;
8418 + MatchPatternDialog.mpdStringPatternIsDisplayed = True;
8421 + * Create a form widget in an application shell
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,
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);
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:"),
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);
8471 + lmBtn = XtVaCreateManagedWidget("lmBtn", xmPushButtonWidgetClass, lmForm,
8472 + XmNlabelString, s1=MKSTRING("Add / Modify\nLanguage Mode..."),
8474 + XmNrightAttachment, XmATTACH_FORM,
8475 + XmNtopAttachment, XmATTACH_FORM, NULL);
8476 + XtAddCallback(lmBtn, XmNactivateCallback, pmLanguageModeDialogCB, NULL);
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);
8490 + applyBtn = XtVaCreateManagedWidget("apply", xmPushButtonWidgetClass, form,
8491 + XmNlabelString, s1=XmStringCreateSimple("Apply"),
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);
8502 + checkBtn = XtVaCreateManagedWidget("check", xmPushButtonWidgetClass, form,
8503 + XmNlabelString, s1=XmStringCreateSimple("Check"),
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);
8514 + deleteBtn = XtVaCreateManagedWidget("delete", xmPushButtonWidgetClass, form,
8515 + XmNlabelString, s1=XmStringCreateSimple("Delete"),
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);
8526 + restoreBtn = XtVaCreateManagedWidget("restore", xmPushButtonWidgetClass, form,
8527 + XmNlabelString, s1=XmStringCreateSimple("Restore Defaults"),
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);
8538 + closeBtn = XtVaCreateManagedWidget("close", xmPushButtonWidgetClass,
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);
8550 + helpBtn = XtVaCreateManagedWidget("help", xmPushButtonWidgetClass,
8552 + XmNlabelString, s1=XmStringCreateSimple("Help"),
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);
8563 + stringPatternsFrame = XtVaCreateManagedWidget("stringPatternsFrame", xmFrameWidgetClass,
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);
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);
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,
8621 + XmNmarginHeight, 0,
8622 + XmNlabelString, s1=XmStringCreateSimple(
8626 + MatchPatternDialog.sptMiddleW = XtVaCreateManagedWidget("sptMiddleW",
8627 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8628 + XmNmarginHeight, 0,
8629 + XmNlabelString, s1=XmStringCreateSimple(
8633 + MatchPatternDialog.sptEndW = XtVaCreateManagedWidget("sptEndW",
8634 + xmToggleButtonWidgetClass, stringPatternTypeBox,
8635 + XmNmarginHeight, 0,
8636 + XmNlabelString, s1=XmStringCreateSimple(
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,
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,
8665 + XmNmarginHeight, 0,
8666 + XmNlabelString, s1=XmStringCreateSimple(
8667 + "Both (pattern is word)"),
8670 + MatchPatternDialog.wbbLeftW = XtVaCreateManagedWidget("wbbLeftW",
8671 + xmToggleButtonWidgetClass, wordBoundaryBox,
8672 + XmNmarginHeight, 0,
8673 + XmNlabelString, s1=XmStringCreateSimple(
8677 + MatchPatternDialog.wbbRightW = XtVaCreateManagedWidget("wbbRightW",
8678 + xmToggleButtonWidgetClass, wordBoundaryBox,
8679 + XmNmarginHeight, 0,
8680 + XmNlabelString, s1=XmStringCreateSimple(
8684 + MatchPatternDialog.wbbNoneW = XtVaCreateManagedWidget("wbbNoneW",
8685 + xmToggleButtonWidgetClass, wordBoundaryBox,
8686 + XmNmarginHeight, 0,
8687 + XmNlabelString, s1=XmStringCreateSimple(
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);
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,
8714 + XmNmarginHeight, 0,
8715 + XmNlabelString, s1=XmStringCreateSimple(
8716 + "Regular Expression"),
8719 + XtAddCallback(MatchPatternDialog.sabRegularExpressionW, XmNvalueChangedCallback,
8720 + strPatRegExpressionCB, NULL);
8721 + MatchPatternDialog.sabCaseSensitiveW = XtVaCreateManagedWidget("sabCaseSensitiveW",
8722 + xmToggleButtonWidgetClass, stringAttributesBox,
8724 + XmNmarginHeight, 0,
8725 + XmNlabelString, s1=XmStringCreateSimple(
8726 + "Case Sensitive"),
8730 + MatchPatternDialog.mpdStringPatternLbl = XtVaCreateManagedWidget("mpdStringPatternLbl", xmLabelGadgetClass,
8731 + stringPatternsForm,
8732 + XmNlabelString, s1=XmStringCreateSimple("String Pattern"),
8734 + XmNalignment, XmALIGNMENT_BEGINNING,
8735 + XmNleftAttachment, XmATTACH_POSITION,
8736 + XmNleftPosition, LIST_RIGHT,
8737 + XmNtopAttachment, XmATTACH_WIDGET,
8738 + XmNtopWidget, stringAttributesBox,
8739 + XmNtopOffset, BORDER,
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,
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"),
8759 + XmNalignment, XmALIGNMENT_BEGINNING,
8760 + XmNleftAttachment, XmATTACH_POSITION,
8761 + XmNleftPosition, LIST_RIGHT,
8762 + XmNtopAttachment, XmATTACH_WIDGET,
8763 + XmNtopWidget, MatchPatternDialog.mpdStringPatternW,
8764 + XmNtopOffset, BORDER,
8768 + MatchPatternDialog.mpdSubPatNamesPulldown =
8769 + createSubPatternNameMenu(stringPatternsForm, NULL, False);
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);
8787 + MatchPatternDialog.mpdSubPatNamesLbl,
8788 + XmNuserData, XtParent(MatchPatternDialog.mpdSubPatNamesOptMenu),
8791 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesLbl, False);
8792 + XtSetSensitive(MatchPatternDialog.mpdSubPatNamesOptMenu, False);
8794 + matchPatternsFrame = XtVaCreateManagedWidget("matchPatternsFrame", xmFrameWidgetClass,
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"),
8811 + XmNmarginHeight, 0,
8812 + XmNchildType, XmFRAME_TITLE_CHILD, NULL);
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);
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,
8836 + XmNmarginHeight, 0,
8837 + XmNlabelString, s1=XmStringCreateSimple(
8839 + XmNmnemonic, 'I', NULL);
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);
8850 + XtAddCallback(MatchPatternDialog.mptbSubPatternW, XmNvalueChangedCallback,
8851 + matchPatTypeCB, NULL);
8852 + MatchPatternDialog.mptbContextGroupW = XtVaCreateManagedWidget("mptbContextGroupW",
8853 + xmToggleButtonWidgetClass, matchPatternTypeBox,
8854 + XmNmarginHeight, 0,
8855 + XmNlabelString, s1=XmStringCreateSimple(
8857 + XmNmnemonic, 'g', NULL);
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);
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);
8888 + MatchPatternDialog.gabFlashW = XtVaCreateManagedWidget("gabFlashW",
8889 + xmToggleButtonWidgetClass, globalAttributesBox,
8891 + XmNmarginHeight, 0,
8892 + XmNlabelString, s1=XmStringCreateSimple(
8893 + "Flash matching pattern"),
8894 + XmNmnemonic, 'l', NULL);
8896 + MatchPatternDialog.gabSyntaxBasedW = XtVaCreateManagedWidget("gabSyntaxBasedW",
8897 + xmToggleButtonWidgetClass, globalAttributesBox,
8899 + XmNmarginHeight, 0,
8900 + XmNlabelString, s1=XmStringCreateSimple(
8902 + XmNmnemonic, 'b', NULL);
8905 + MatchPatternDialog.mpdMatchPatternNameLbl = XtVaCreateManagedWidget("mpdMatchPatternNameLbl", xmLabelGadgetClass,
8906 + matchPatternsForm,
8907 + XmNlabelString, s1=XmStringCreateSimple(MATCH_PAT_NAME_LBL_TXT),
8909 + XmNalignment, XmALIGNMENT_BEGINNING,
8910 + XmNleftAttachment, XmATTACH_POSITION,
8911 + XmNleftPosition, LIST_RIGHT,
8912 + XmNtopAttachment, XmATTACH_WIDGET,
8913 + XmNtopWidget, globalAttributesBox,
8914 + XmNtopOffset, BORDER, NULL);
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,
8928 + RemapDeleteKey(MatchPatternDialog.mpdMatchPatternNameW);
8929 + XtVaSetValues(MatchPatternDialog.mpdMatchPatternNameLbl, XmNuserData, MatchPatternDialog.mpdMatchPatternNameW, NULL);
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",
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);
8954 + * set initial default button
8956 + XtVaSetValues(form, XmNdefaultButton, okBtn, NULL);
8957 + XtVaSetValues(form, XmNcancelButton, closeBtn, NULL);
8960 + * handle mnemonic selection of buttons and focus to dialog
8962 + AddDialogMnemonicHandler(form, False);
8965 + * fill in the dialog information for the selected language mode
8967 + SetLangModeMenu(MatchPatternDialog.mpdLmOptMenu, MatchPatternDialog.mpdLangModeName);
8970 + * realize all of the widgets in the new dialog
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;
8984 + int regularExpression =
8985 + XmToggleButtonGetState(MatchPatternDialog.sabRegularExpressionW);
8988 + * check, if dialog mode needs to be switched
8990 + if (MatchPatternDialog.mpdStringPatternIsDisplayed == dialogShowsStringPattern)
8995 + if (dialogShowsStringPattern)
8997 + matchPatternNameText = MATCH_PAT_NAME_LBL_TXT;
8998 + strPatCxtGrpListText = STRING_PATTERNS_LBL_TXT;
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);
9029 + MatchPatternDialog.mpdMatchPatternNameLbl,
9030 + XmNlabelString, s1=XmStringCreateSimple(matchPatternNameText),
9035 + MatchPatternDialog.mpdStringPatternsLbl,
9036 + XmNlabelString, s1=XmStringCreateSimple(strPatCxtGrpListText),
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)
9055 + StringMatchTable *oldTable, *newTable;
9056 + StringMatchTable emptyTable = {"", NULL, NULL, NULL, NULL, 0, NULL, 0, NULL};
9057 + StringMatchTable *table;
9058 + DMPTranslationResult translResult;
9062 + * Get the newly selected mode name. If it's the same, do nothing
9064 + XtVaGetValues(w, XmNuserData, &modeName, NULL);
9065 + if (!strcmp(modeName, MatchPatternDialog.mpdLangModeName))
9069 + * Look up the original version of the patterns being edited
9071 + oldTable = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
9072 + if (oldTable == NULL)
9073 + oldTable = &emptyTable;
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.
9080 + newTable = getDialogStringMatchTable(&translResult);
9082 + if (translResult == DMPTR_EMPTY)
9084 + newTable = &emptyTable;
9087 + if (newTable == NULL)
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)
9097 + MatchPatternDialog.mpdLmOptMenu,
9098 + MatchPatternDialog.mpdLangModeName);
9103 + else if (stringMatchTableDiffer(oldTable, newTable))
9105 + if (newTable == &emptyTable)
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);
9119 + MatchPatternDialog.mpdLmOptMenu,
9120 + MatchPatternDialog.mpdLangModeName);
9122 + freeStringMatchTable( newTable );
9126 + else if (resp == 1)
9128 + updateStringMatchTable( newTable );
9131 + * Don't free the new table due to it's stored in MatchTables now
9137 + if (newTable != NULL && newTable != &emptyTable)
9138 + freeStringMatchTable(newTable);
9141 + * Free the old dialog information
9143 + freeVariableDialogData(DISCARD_LANGUAGE_MODE);
9146 + * Fill the dialog with the new language mode information
9148 + MatchPatternDialog.mpdLangModeName = XtNewString(modeName);
9151 + * Find the associated matching pattern table to edit
9153 + table = (StringMatchTable *)FindStringMatchTable(MatchPatternDialog.mpdLangModeName);
9156 + * Copy the list of patterns to one that the user can freely edit
9158 + copyStringMatchTableForDialog( table, &MatchPatternDialog.mpdTable );
9161 + * Update dialog fields
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)
9180 + if (MatchPatternDialog.mpdShell == NULL)
9183 + oldMenu = MatchPatternDialog.mpdLmPulldown;
9185 + * don't include "PLAIN" (4th parameter) in LM menu
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,
9199 + DialogMatchPatternSequenceElement *newSeq;
9202 + * If the dialog is currently displaying the "new" entry and the
9203 + * fields are empty, that's just fine
9205 + if (oldItem == NULL && matchPatternDialogEmpty())
9209 + * Read string patterns / sub-pattern names area first
9211 + UpdateManagedList(MatchPatternDialog.mpdStringPatternsListW, True);
9214 + * If there are no problems reading the data, just return it
9216 + newSeq = readMatchPatternFields(True);
9217 + if (newSeq != NULL)
9218 + return (void *)newSeq;
9221 + * If there are problems, and the user didn't ask for the fields to be
9222 + * read, give more warning
9224 + if (!explicitRequest)
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
9234 + : (void *)copyDialogSequenceElement(
9235 + (DialogMatchPatternSequenceElement *)oldItem);
9240 + * read data again without "silent" mode to display warning
9242 + newSeq = readMatchPatternFields(False);
9248 +static void setMatchPatternDisplayedCB(void *item, void *cbArg)
9250 + DialogMatchPatternSequenceElement *seqElement;
9251 + DialogMatchPatternTableElement *element;
9252 + DialogMatchPatternGroupElement *group;
9255 + seqElement = (DialogMatchPatternSequenceElement *)item;
9257 + MatchPatternDialog.currentDmptSeqElement = seqElement;
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 );
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);
9288 + RadioButtonChangeState(MatchPatternDialog.mptbContextGroupW, True, True);
9290 + freeDialogStringPatterns(
9291 + &MatchPatternDialog.currentStringPatterns);
9295 + group = (DialogMatchPatternGroupElement *)seqElement->dmpsePtr;
9296 + MatchPatternDialog.currentDmptElement = NULL;
9297 + MatchPatternDialog.currentDmptGroup = group;
9299 + copyDialogPatternNamesFromGroup(
9301 + &MatchPatternDialog.currentStringPatterns);
9305 + element = (DialogMatchPatternTableElement *)seqElement->dmpsePtr;
9306 + MatchPatternDialog.currentDmptElement = element;
9307 + MatchPatternDialog.currentDmptGroup = NULL;
9309 + RadioButtonChangeState(
9310 + MatchPatternDialog.gabSkipBtwStartEndW,
9311 + element->dmpteSkipBtwnStartEnd,
9313 + RadioButtonChangeState(
9314 + MatchPatternDialog.gabFlashW,
9315 + element->dmpteFlash,
9317 + RadioButtonChangeState(
9318 + MatchPatternDialog.gabSyntaxBasedW,
9319 + !element->dmpteIgnoreHighLightInfo,
9322 + copyDialogStringPatternsFromTable(
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 );
9357 +static void *getStringPatternDisplayedCB(void *oldItem, int explicitRequest, int *abort,
9360 + DialogStringPatternElement *newPat;
9361 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9364 + * If the string pattern frame is currently displaying the "new" entry and the
9365 + * fields are empty, that's just fine
9367 + if (oldItem == NULL && stringPatternFieldsEmpty(isRelatedToGroup))
9371 + * If there are no problems reading the data, just return it
9373 + newPat = readStringPatternFrameFields(True);
9374 + if (newPat != NULL)
9375 + return (void *)newPat;
9378 + * If there are problems, and the user didn't ask for the fields to be
9379 + * read, give more warning
9382 + if (!explicitRequest)
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
9392 + : (void *)copyDialogStringPatternElement(
9393 + (DialogStringPatternElement *)oldItem);
9398 + * read data again without "silent" mode to display warning
9400 + newPat = readStringPatternFrameFields(False);
9406 +static void setStringPatternDisplayedCB(void *item, void *cbArg)
9408 + DialogStringPatternElement *element = (DialogStringPatternElement *)item;
9409 + PatternElementKind peKind;
9410 + PatternWordBoundary wordBoundary;
9411 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9415 + if (isRelatedToGroup)
9417 + updateSubPatternNameMenu(NULL, False);
9421 + XmTextSetString(MatchPatternDialog.mpdStringPatternW, "");
9423 + setSensitiveWordBoundaryBox( True );
9425 + RadioButtonChangeState(MatchPatternDialog.wbbBothW, True, True);
9428 + * type of "new" string pattern:
9429 + * preset "start", if no string pattern exists at all;
9430 + * else select "end"
9432 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
9433 + RadioButtonChangeState(MatchPatternDialog.sptStartW, True, True);
9435 + RadioButtonChangeState(MatchPatternDialog.sptEndW, True, True);
9437 + RadioButtonChangeState(MatchPatternDialog.sabCaseSensitiveW, True, False);
9438 + RadioButtonChangeState(MatchPatternDialog.sabRegularExpressionW, False, False);
9443 + if (isRelatedToGroup)
9445 + updateSubPatternNameMenu(element->dspeText, False);
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);
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);
9468 + RadioButtonChangeState(MatchPatternDialog.wbbNoneW, True, True);
9470 + RadioButtonChangeState(
9471 + MatchPatternDialog.sabCaseSensitiveW,
9472 + !element->dspeCaseInsensitive,
9475 + RadioButtonChangeState(
9476 + MatchPatternDialog.sabRegularExpressionW,
9477 + element->dspeRegularExpression,
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)
9504 + * change the matching pattern
9506 + if (!getAndUpdateStringMatchTable())
9510 + * pop down and destroy the dialog
9512 + XtDestroyWidget(MatchPatternDialog.mpdShell);
9515 +static void applyCB(Widget w, XtPointer clientData, XtPointer callData)
9518 + * change the matching pattern
9520 + getAndUpdateStringMatchTable();
9523 +static void checkCB(Widget w, XtPointer clientData, XtPointer callData)
9525 + StringMatchTable *newTable;
9526 + DMPTranslationResult translResult;
9529 + * Get the current information displayed by the dialog.
9530 + * If a new table is available, then the test is passed successfully.
9532 + newTable = getDialogStringMatchTable(&translResult);
9534 + if (newTable != NULL)
9537 + DF_INF, MatchPatternDialog.mpdShell, 1,
9538 + "Matching Patterns Checked",
9539 + "Matching Patterns checked without error",
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)
9555 + DF_WARN, MatchPatternDialog.mpdShell, 1,
9556 + "No Default Matching Pattern",
9557 + "There is no default matching pattern set\nfor language mode %s",
9559 + MatchPatternDialog.mpdLangModeName);
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);
9579 + * if a stored version of the matching pattern set exists, replace it.
9580 + * if it doesn't, add a new one.
9582 + updateStringMatchTable( defaultTable );
9585 + * free the old dialog information
9587 + freeVariableDialogData(KEEP_LANGUAGE_MODE);
9590 + * update the dialog
9592 + copyStringMatchTableForDialog( defaultTable, &MatchPatternDialog.mpdTable );
9594 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9595 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9598 +static void deleteCB(Widget w, XtPointer clientData, XtPointer callData)
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)
9613 + * if a stored version of the matching pattern exists, delete it from the list
9615 + DeleteStringMatchTable(MatchPatternDialog.mpdLangModeName);
9618 + * free the old dialog information
9620 + freeVariableDialogData(KEEP_LANGUAGE_MODE);
9623 + * clear out the dialog
9625 + ChangeManagedListData(MatchPatternDialog.mpdMatchPatternNamesListW);
9626 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9629 +static void closeCB(Widget w, XtPointer clientData, XtPointer callData)
9632 + * pop down and destroy the dialog
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");
9693 + * if context group button is (still) selected, then update labels etc.
9695 + if (XmToggleButtonGetState(MatchPatternDialog.mptbContextGroupW))
9697 + setDialogType(CONTEXT_GROUP_DIALOG);
9701 + setDialogType(STRING_PATTERN_DIALOG);
9705 + * if a "new" entry is selected in matching patterns names list, then provide a
9706 + * list of all sub-pattern names
9708 + if (MatchPatternDialog.currentDmptSeqElement == NULL)
9710 + updateSubPatternNameMenu(NULL, True);
9714 +static void changeExistingSubPattern(
9717 + DialogMatchPatternGroupElement *group;
9721 + getDialogGroupUsingMatchPattern(
9722 + MatchPatternDialog.currentDmptElement->dmpteName );
9724 + while ( group != NULL )
9728 + DF_WARN, MatchPatternDialog.mpdShell, 3,
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);
9739 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9743 + else if (resp == 2)
9745 + removeMatchPatternFromGroup(
9746 + MatchPatternDialog.currentDmptElement->dmpteName,
9750 + * look for evtl. next context group holding this matching pattern
9753 + getDialogGroupUsingMatchPattern(
9754 + MatchPatternDialog.currentDmptElement->dmpteName );
9759 + * remove this matching pattern form all context groups
9761 + removeMatchPatternFromAllGroups(
9762 + MatchPatternDialog.currentDmptElement->dmpteName);
9769 +static void changeStringPatternToGroup(void)
9774 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns != 0)
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);
9788 + isSubPattern = (MatchPatternDialog.currentDmptElement->dmpteType == MPT_SUB);
9791 + RadioButtonChangeState(MatchPatternDialog.mptbSubPatternW, True, True);
9793 + RadioButtonChangeState(MatchPatternDialog.mptbIndividualW, True, True);
9799 + * remove string patterns & update dialog fields
9801 + freeDialogStringPatterns(&MatchPatternDialog.currentStringPatterns);
9803 + ChangeManagedListData(MatchPatternDialog.mpdStringPatternsListW);
9807 + * invalidate this sub-/individual pattern
9809 + MatchPatternDialog.currentDmptSeqElement->dmpseValid = False;
9812 + * update sub-pattern menu due to change to context group
9814 + updateSubPatternNameMenu(NULL, True);
9817 +static void changeGroupToStringPattern(
9822 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
9827 + DF_WARN, MatchPatternDialog.mpdShell, 2,
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);
9837 + RadioButtonChangeState(MatchPatternDialog.mptbContextGroupW, True, True);
9842 + * remove string patterns & update dialog fields
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(
9856 + char *currentSubPatName,
9857 + int allSubPatterns)
9859 + NameList nameList;
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]);
9875 +static void setupSubPatternNameList(
9876 + char *currentSubPatName,
9877 + int allSubPatterns,
9878 + NameList *nameList)
9882 + DialogMatchPatternSequenceElement *seq;
9883 + int isRelatedToGroup = !MatchPatternDialog.mpdStringPatternIsDisplayed;
9885 + if (isRelatedToGroup || allSubPatterns)
9888 + * add "none selected" (default) item
9890 + nameList->nlId[n ++] = SPNM_NONE_SELECTED;
9893 + * add one item for each (not assigned) sub-pattern name
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;
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(
9929 + btn = XtVaCreateManagedWidget("subPattern", xmPushButtonGadgetClass,
9931 + XmNlabelString, s1=XmStringCreateSimple(subPatName),
9932 + XmNmarginHeight, 0,
9933 + XmNuserData, (void *)subPatName, NULL);
9938 +** Set the sub-patterns menu to show a particular sub-pattern name
9940 +static void setSubPatternNameMenu(
9941 + const char *subPatName)
9946 + Widget pulldown, selectedItem;
9949 + XtVaGetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNsubMenuId, &pulldown, NULL);
9950 + XtVaGetValues(pulldown, XmNchildren, &items, XmNnumChildren, &nItems, NULL);
9955 + selectedItem = items[0];
9958 + * if no subPatName is given, then select first item of option menu
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];
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;
9992 + setupSubPatternNameList(currentSubPatName, allSubPatterns, &nameList);
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.
10000 + MatchPatternDialog.mpdSubPatNamesPulldown,
10001 + XmNchildren, &items,
10002 + XmNnumChildren, &nItems,
10005 + for (n=0; n<(int)nItems; n++)
10007 + if (n >= nameList.nlNumber)
10010 + * unmanaging before destroying stops parent from displaying
10012 + XtUnmanageChild(items[n]);
10013 + XtDestroyWidget(items[n]);
10017 + if (items[n] == NULL || items[n]->core.being_destroyed)
10020 + * create a new entry (widget) if this one is not existing or
10021 + * if it is marked as to be destroyed
10023 + createSubPatNameMenuEntry(
10024 + MatchPatternDialog.mpdSubPatNamesPulldown, nameList.nlId[n]);
10030 + XmNlabelString, st1=XmStringCreateSimple(nameList.nlId[n]),
10031 + XmNuserData, (void *)nameList.nlId[n],
10034 + XmStringFree(st1);
10040 + * add new items for remaining sub-patterns names
10042 + for (n=(int)nItems; n<nameList.nlNumber; n++)
10044 + createSubPatNameMenuEntry(
10045 + MatchPatternDialog.mpdSubPatNamesPulldown, nameList.nlId[n]);
10049 + * select entry shown in sub-pattern name option menu
10051 + setSubPatternNameMenu(currentSubPatName);
10054 +static char *getSelectedSubPatternName(void)
10056 + Widget selectedItem;
10059 + XtVaGetValues(MatchPatternDialog.mpdSubPatNamesOptMenu, XmNmenuHistory, &selectedItem, NULL);
10060 + XtVaGetValues(selectedItem, XmNuserData, &itemName, NULL);
10065 +static int isSubPatternNameInCurStrPat(
10066 + char *subPatName)
10069 + DialogStringPatterns *curPatNames = &MatchPatternDialog.currentStringPatterns;
10071 + for (i=0; i<curPatNames->dspNumberOfPatterns; i++)
10073 + if (strcmp(curPatNames->dspElements[i]->dspeText, subPatName) == 0)
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)
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";
10109 + nameLabel = "matching pattern name";
10110 + nameTitle = "Matching Pattern Name";
10111 + contentTitle = "Matching Pattern Content";
10112 + contentWarningText = "Please specify min. 1\nstring pattern";
10117 + ReadSymbolicFieldTextWidget(
10118 + MatchPatternDialog.mpdMatchPatternNameW,
10122 + if (name == NULL)
10126 + else if (*name == '\0')
10131 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10133 + "Please specify a valid name",
10135 + XmProcessTraversal(MatchPatternDialog.mpdMatchPatternNameW, XmTRAVERSE_CURRENT);
10141 + if (MatchPatternDialog.currentStringPatterns.dspNumberOfPatterns == 0)
10146 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10148 + contentWarningText,
10157 + !isStartPatternElementAvailable(&MatchPatternDialog.currentStringPatterns))
10162 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10164 + "Please specify min. 1 string pattern\nof type 'start'",
10172 + if (MatchPatternDialog.currentDmptElement != NULL &&
10173 + MatchPatternDialog.currentDmptElement->dmpteType == MPT_SUB &&
10174 + strcmp(MatchPatternDialog.currentDmptElement->dmpteName, name) != 0)
10176 + renameMatchPatternInAllGroups(
10177 + MatchPatternDialog.currentDmptElement->dmpteName,
10182 + (DialogMatchPatternSequenceElement *)XtMalloc(sizeof(DialogMatchPatternSequenceElement));
10184 + newSeq->dmpseName = name;
10185 + newSeq->dmpseValid = True;
10189 + newSeq->dmpseType = MPT_GROUP;
10192 + (DialogMatchPatternGroupElement *)XtMalloc(sizeof(DialogMatchPatternGroupElement));
10194 + newGroup->dmpgeName = XtNewString(name);
10196 + copyDialogPatternNamesToGroup(
10197 + &MatchPatternDialog.currentStringPatterns,
10200 + newSeq->dmpsePtr = (void *)newGroup;
10204 + if (XmToggleButtonGetState(MatchPatternDialog.mptbIndividualW))
10205 + newSeq->dmpseType = MPT_INDIVIDUAL;
10207 + newSeq->dmpseType = MPT_SUB;
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;
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)
10245 + for (i=0; i < dialogPatterns->dspNumberOfPatterns; i++)
10247 + if (dialogPatterns->dspElements[i]->dspeKind == PEK_START)
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)
10275 + stringPatText = XtNewString(stringPatText);
10280 + XmTextGetString(MatchPatternDialog.mpdStringPatternW);
10282 + if (stringPatText == NULL)
10286 + else if (*stringPatText == '\0')
10291 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10292 + "String Pattern",
10293 + "Please specify string\npattern content",
10295 + XmProcessTraversal(MatchPatternDialog.mpdStringPatternW, XmTRAVERSE_CURRENT);
10297 + XtFree(stringPatText);
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;
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;
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;
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)
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)
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)
10378 + strcmp( getSelectedSubPatternName(), SPNM_NONE_SELECTED ) == 0);
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;
10402 + * Get the current information displayed by the dialog. If it's bad,
10403 + * report it to the user & return.
10405 + newTable = getDialogStringMatchTable(&translResult);
10407 + if (newTable == NULL && translResult != DMPTR_EMPTY)
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",
10415 + MatchPatternDialog.mpdLangModeName);
10421 + * change the matching pattern
10423 + updateStringMatchTable( newTable );
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;
10440 + * Find the matching pattern being modified
10442 + for (i=0; i<NbrMatchTables; i++)
10444 + if (!strcmp(MatchPatternDialog.mpdLangModeName, MatchTables[i]->smtLanguageMode))
10447 + * replace existing matching pattern
10449 + freeStringMatchTable(MatchTables[i]);
10450 + MatchTables[i] = newTable;
10455 + if (i == NbrMatchTables)
10458 + * new match table for language mode -> add it to end
10460 + MatchTables[NbrMatchTables++] = newTable;
10464 + * Find windows that are currently using this matching pattern set and
10465 + * update this windows
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;
10479 + * Note that preferences have been changed
10481 + MarkPrefsChanged();
10484 +static StringMatchTable *getDialogStringMatchTable(
10485 + DMPTranslationResult *result)
10487 + int matchPatListIdx =
10488 + ManagedListSelectedIndex(MatchPatternDialog.mpdMatchPatternNamesListW);
10489 + int stringPatListIdx =
10490 + ManagedListSelectedIndex(MatchPatternDialog.mpdStringPatternsListW);
10493 + * Get the current content of the matching pattern dialog fields
10495 + if (!UpdateManagedList(MatchPatternDialog.mpdStringPatternsListW, True))
10497 + *result = DMPTR_INCOMPLETE;
10502 + if (!UpdateManagedList(MatchPatternDialog.mpdMatchPatternNamesListW, True))
10504 + *result = DMPTR_INCOMPLETE;
10509 + SelectManagedListItem(MatchPatternDialog.mpdMatchPatternNamesListW, matchPatListIdx);
10510 + SelectManagedListItem(MatchPatternDialog.mpdStringPatternsListW, stringPatListIdx);
10513 + * Translate dialog match table to string match table
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;
10527 + ErrorInfo errInfo;
10530 + initErrorInfo(&errInfo);
10532 + readPatInfo.rmpiNbrOfElements = 0;
10533 + readPatInfo.rmpiNbrOfGroups = 0;
10534 + readPatInfo.rmpiNbrOfSeqElements = 0;
10535 + readPatInfo.rmpiAllPatRE = NULL;
10536 + readPatInfo.rmpiFlashPatRE = NULL;
10539 + * if no dialog patterns are defined, return "empty" table
10541 + if (dialogTable->dmpiNbrOfSeqElements == 0)
10543 + *result = DMPTR_EMPTY;
10545 + return createStringMatchTable(
10547 + XtNewString(MatchPatternDialog.mpdLangModeName));
10551 + * translate dialog matching pattern elements
10553 + for (i=0; i < dialogTable->dmpiNbrOfSeqElements; i++)
10555 + seq = dialogTable->dmpiSequence[i];
10557 + if (seq->dmpseType == MPT_GROUP)
10559 + newGroupElement =
10560 + translateDialogMatchPatternGroupElement(
10562 + (DialogMatchPatternGroupElement *)seq->dmpsePtr);
10564 + if (newGroupElement == NULL)
10566 + freeReadMatchPatternInfo(&readPatInfo);
10568 + *result = DMPTR_INCOMPLETE;
10573 + readPatInfo.rmpiGroup[readPatInfo.rmpiNbrOfGroups ++] =
10576 + recordPatternSequence(
10580 + readPatInfo.rmpiNbrOfGroups-1 );
10585 + translateDialogMatchPatternTableElement(
10586 + (DialogMatchPatternTableElement *)seq->dmpsePtr);
10588 + newPatElement->mpteIndex = readPatInfo.rmpiNbrOfElements;
10590 + readPatInfo.rmpiElement[readPatInfo.rmpiNbrOfElements ++] =
10593 + if (newPatElement->mpteType == MPT_INDIVIDUAL)
10595 + if (!assignIndividualGroup(&readPatInfo, &errMsg, newPatElement))
10598 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10599 + "Assign reg. exp.",
10600 + "%s\n(Pattern: '%s')",
10603 + newPatElement->mpteName);
10605 + freeReadMatchPatternInfo(&readPatInfo);
10607 + *result = DMPTR_INCOMPLETE;
10613 + treatDuplicatedMTEntries(readPatInfo.rmpiElement, readPatInfo.rmpiNbrOfElements);
10615 + recordPatternSequence(
10619 + newPatElement->mpteIndex );
10624 + * compile reg. expressions of "read" patterns
10626 + if (createRegExpOfPatterns( &readPatInfo, &errInfo ))
10628 + errInfo.eiLanguageMode = XtNewString(MatchPatternDialog.mpdLangModeName);
10629 + dialogMatchingPatternSetError(
10630 + "Assign all patterns reg. exp.",
10633 + freeReadMatchPatternInfo(&readPatInfo);
10635 + *result = DMPTR_INCOMPLETE;
10640 + *result = DMPTR_OK;
10642 + return createStringMatchTable(
10644 + XtNewString(MatchPatternDialog.mpdLangModeName));
10647 +static MatchPatternTableElement *translateDialogMatchPatternTableElement(
10648 + DialogMatchPatternTableElement *dialogElement)
10650 + MatchPatternTableElement *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)
10680 + * allocate memory for patterns
10682 + newElement->mpteAll.pesNumberOfPattern = dialogPatterns->dspNumberOfPatterns;
10685 + sizeof(PatternElement *) * dialogPatterns->dspNumberOfPatterns;
10687 + newElement->mpteAll.pesPattern = (PatternElement **)XtMalloc(sizeOfPat);
10690 + * assign dialog patterns to patterns of MatchPatternTableElement
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;
10706 + * sort pattern elements into start, middle & end arrays
10708 + sortDialogPatternElementSet( &newElement->mpteAll, newElement );
10711 + * determine mono pattern
10713 + if (newElement->mpteEnd.pesNumberOfPattern == 0)
10715 + newElement->mpteIsMonoPattern = True;
10717 + copyPatternSet( &newElement->mpteStart, &newElement->mpteEnd );
10721 + newElement->mpteIsMonoPattern = False;
10726 + * Sort dialog pattern element set into start, middle & end arrays.
10728 +static void sortDialogPatternElementSet(
10729 + PatternElementSet *allPat,
10730 + MatchPatternTableElement *result)
10735 + * count number of start, middle & end pattern elements
10737 + countPatternElementKind( allPat, result );
10740 + * allocate pattern elements
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 );
10758 + * sort pattern elements into start, middle & end arrays
10760 + sortPatternElementSet( allPat, result );
10763 +static MatchPatternGroupElement *translateDialogMatchPatternGroupElement(
10764 + ReadMatchPatternInfo *info,
10765 + DialogMatchPatternGroupElement *dialogGroup)
10768 + int error = False;
10769 + MatchPatternTableElement *subPatElement;
10771 + MatchPatternGroupElement *group;
10774 + * Allocate memory for the matching pattern group. Copy name & number of
10778 + (MatchPatternGroupElement *)XtMalloc( sizeof(MatchPatternGroupElement) );
10780 + group->mpgeName = XtNewString(dialogGroup->dmpgeName);
10781 + group->mpgeNumberOfSubPatterns = dialogGroup->dmpgeNumberOfSubPatterns;
10782 + group->mpgeKeywordRE = NULL;
10785 + * Allocate memory for the sub-matching pattern IDs
10787 + sizeOfIds = sizeof(char *) * group->mpgeNumberOfSubPatterns;
10788 + group->mpgeSubPatternIds = (char **)XtMalloc( sizeOfIds );
10790 + for (i=0; i < group->mpgeNumberOfSubPatterns; i ++)
10793 + * Remember sub-matching pattern ID
10795 + group->mpgeSubPatternIds[i] = XtNewString(dialogGroup->dmpgeSubPatternIds[i]);
10798 + * Assign the index of this group to the sub-matching pattern
10799 + * if no group index was assigned before.
10802 + getPatternOfName( info, dialogGroup->dmpgeSubPatternIds[i]);
10804 + if (subPatElement == NULL)
10807 + DF_WARN, MatchPatternDialog.mpdShell, 1,
10808 + "Group Compilation",
10809 + "Group '%s':\nsub-matching pattern '%s' not defined before",
10812 + dialogGroup->dmpgeSubPatternIds[i]);
10818 + if (subPatElement->mpteGroup == NO_GROUP_IDX)
10820 + subPatElement->mpteGroup = info->rmpiNbrOfGroups;
10827 + freeMatchPatternGroupElement(group);
10835 +static int stringMatchTableDiffer(
10836 + StringMatchTable *oldTable,
10837 + StringMatchTable *newTable)
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)
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))
10859 + if (oldSeq->mpseType != newSeq->mpseType)
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))
10870 + if (oldGroup->mpgeNumberOfSubPatterns != newGroup->mpgeNumberOfSubPatterns)
10873 + for (j=0; j < oldGroup->mpgeNumberOfSubPatterns; j++)
10875 + if (AllocatedStringsDiffer(
10876 + oldGroup->mpgeSubPatternIds[j],
10877 + newGroup->mpgeSubPatternIds[j]))
10883 + oldPat = oldPatTab->mptElements[oldSeq->mpseIndex];
10884 + newPat = newPatTab->mptElements[newSeq->mpseIndex];
10886 + if (AllocatedStringsDiffer(oldPat->mpteName, newPat->mpteName))
10889 + if (oldPat->mpteType != newPat->mpteType)
10892 + if (oldPat->mpteGroup != newPat->mpteGroup)
10895 + if (oldPat->mpteAll.pesNumberOfPattern != newPat->mpteAll.pesNumberOfPattern)
10898 + for (j=0; j < oldPat->mpteAll.pesNumberOfPattern; j ++)
10900 + if (patternElementDiffer(
10901 + oldPat->mpteAll.pesPattern[j], oldPatTab,
10902 + newPat->mpteAll.pesPattern[j], newPatTab ) )
10906 + if (oldPat->mpteIsMonoPattern != newPat->mpteIsMonoPattern)
10909 + if (oldPat->mpteSkipBtwnStartEnd != newPat->mpteSkipBtwnStartEnd)
10912 + if (oldPat->mpteIgnoreHighLightInfo != newPat->mpteIgnoreHighLightInfo)
10915 + if (oldPat->mpteFlash != newPat->mpteFlash)
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))
10937 + if (AllocatedStringsDiffer(oldSP->spOrigText, newSP->spOrigText))
10939 + if (oldPE->peKind != newPE->peKind)
10941 + if (oldSP->spWordBoundary != newSP->spWordBoundary)
10943 + if (oldSP->spCaseInsensitive != newSP->spCaseInsensitive)
10945 + if (oldSP->spRegularExpression != newSP->spRegularExpression)
10951 +static DialogMatchPatternGroupElement *getDialogGroupUsingMatchPattern(
10952 + char *matchPatternName)
10954 + DialogMatchPatternSequenceElement *seq;
10955 + DialogMatchPatternGroupElement *group;
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)
10977 +static void removeMatchPatternFromGroup(
10978 + char *matchPatternName,
10979 + DialogMatchPatternGroupElement *group)
10983 + for (i=0; i < group->dmpgeNumberOfSubPatterns; i ++)
10985 + if (strcmp(group->dmpgeSubPatternIds[i], matchPatternName) == 0)
10988 + * remove existing matching pattern name from sub-pattern list
10990 + freeXtPtr((void **)&group->dmpgeSubPatternIds[i]);
10992 + &group->dmpgeSubPatternIds[i],
10993 + &group->dmpgeSubPatternIds[i+1],
10994 + (group->dmpgeNumberOfSubPatterns-1 - i) * sizeof(char *));
10995 + group->dmpgeNumberOfSubPatterns --;
11002 +static void removeMatchPatternFromAllGroups(
11003 + char *matchPatternName)
11005 + DialogMatchPatternSequenceElement *seq;
11006 + DialogMatchPatternGroupElement *group;
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)
11029 + for (i=0; i < group->dmpgeNumberOfSubPatterns; i ++)
11031 + if (strcmp(group->dmpgeSubPatternIds[i], oldMatchPatternName) == 0)
11034 + * rename existing matching pattern name in sub-pattern list
11036 + freeXtPtr((void **)&group->dmpgeSubPatternIds[i]);
11038 + group->dmpgeSubPatternIds[i] =
11039 + XtNewString(newMatchPatternName);
11046 +static void renameMatchPatternInAllGroups(
11047 + char *oldMatchPatternName,
11048 + char *newMatchPatternName)
11050 + DialogMatchPatternSequenceElement *seq;
11051 + DialogMatchPatternGroupElement *group;
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,
11070 +static void freeVariableDialogData(
11071 + int keepLanguageModeName)
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)
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)
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);
11144 +static void freePtr(void **ptr)
11146 + if (*ptr != NULL)
11148 + free((char *)*ptr);
11152 diff --quilt /dev/null new/source/patternMatchData.h
11154 +++ new/source/patternMatchData.h
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"
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 {
11214 char *smartIndentCommon;
11216 + char *matchPattern;
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[] = {
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 */
11230 +/* The VAX compiler can't compile Java-Script's definition in highlightData.c */
11231 + {"matchPatterns", "MatchPatterns", PREF_ALLOC_STRING,
11232 + "PLAIN:Default\n\
11239 + Fortran:Default\n\
11243 + Makefile:Default\n\
11244 + Matlab:Default\n\
11245 + NEdit Macro:Default\n\
11246 + Pascal:Default\n\
11248 + PostScript:Default\n\
11249 + Python:Default\n\
11251 + SGML HTML:Default\n\
11253 + Sh Ksh Bash:Default\n\
11256 + Verilog:Default\n\
11258 + X Resources:Default\n\
11260 + &TempStringPrefs.matchPattern, NULL, True},
11262 + {"matchPatterns", "MatchPatterns", PREF_ALLOC_STRING,
11263 + "PLAIN:Default\n\
11270 + Fortran:Default\n\
11272 + JavaScript:Default\n\
11275 + Makefile:Default\n\
11276 + Matlab:Default\n\
11277 + NEdit Macro:Default\n\
11278 + Pascal:Default\n\
11280 + PostScript:Default\n\
11281 + Python:Default\n\
11283 + SGML HTML:Default\n\
11285 + Sh Ksh Bash:Default\n\
11288 + Verilog:Default\n\
11290 + X Resources:Default\n\
11292 + &TempStringPrefs.matchPattern, NULL, True},
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,
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");
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");
11403 + /* delete "empty" string match table related to language mode to be deleted */
11404 + DeleteStringMatchTable(LMDialog.languageModeList[itemIndex]->name);
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))
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
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();
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) {
11498 + isOldMode = !strcmp(lmDialogName, oldModeName);
11502 + return isOldMode;
11505 static void *lmGetDisplayedCB(void *oldItem, int explicitRequest, int *abort,
11508 languageModeRec *lm, *oldLM = (languageModeRec *)oldItem;
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();
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
11534 -Widget CreateLanguageModeMenu(Widget parent, XtCallbackProc cbProc, void *cbArg)
11535 +Widget CreateLanguageModeMenu(
11537 + XtCallbackProc cbProc,
11539 + int includePlain)
11545 menu = CreatePulldownMenu(parent, "languageModes", NULL, 0);
11547 + if (includePlain) {
11548 + btn = XtVaCreateManagedWidget("languageMode", xmPushButtonGadgetClass,
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,
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,
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"
11600 +#include "patternMatch.h"
11604 typedef struct _SelectionInfo {
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,
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 {
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
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)
11680 - int pos, matchIndex;
11681 - int startPos, endPos, searchPos, matchPos;
11684 + int startPos, endPos, matchPos, matchLen;
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)
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);
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)
11712 - if (matchIndex == N_FLASH_CHARS)
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;
11723 - searchPos = endPos;
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)
11734 + /* Pattern Match Feature: determine matching type
11735 + (here: flash delimiter or range) */
11736 + if (window->showMatchingStyle == FLASH_DELIMIT) {
11737 + matchingType = MT_FLASH_DELIMIT;
11739 + matchingType = MT_FLASH_RANGE;
11742 - /* do the search */
11743 - if (!findMatchingChar(window, c, style, searchPos, startPos, endPos,
11745 + /* Pattern Match Feature: do the search */
11746 + if (!FindMatchingString(window, matchingType, &pos, startPos, endPos,
11747 + &matchPos, &matchLen, &direction))
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);
11756 /* ... or the whole range. */
11757 - if (MatchingChars[matchIndex].direction == SEARCH_BACKWARD) {
11758 + if (direction == SEARCH_BACKWARD) {
11759 BufHighlight(window->buffer, matchPos, pos+1);
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)
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)
11791 - selStart = selEnd - 1;
11792 - if (selStart < 0) {
11793 - XBell(TheDisplay, 0);
11796 + if (GetSimpleSelection(buf, &selStart, &selEnd)) {
11799 - if ((selEnd - selStart) != 1) {
11800 - XBell(TheDisplay, 0);
11803 + pos = TextGetCursorPos(window->lastFocus);
11810 +void SelectToMatchingCharacter(WindowInfo *window)
11813 + int startPos, endPos, matchPos, matchLen;
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);
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;
11846 + int matchPos, matchLen;
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)
11857 - selStart = selEnd - 1;
11858 - if (selStart < 0) {
11859 - XBell(TheDisplay, 0);
11863 - if ((selEnd - selStart) != 1) {
11864 - XBell(TheDisplay, 0);
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);
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
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,
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)
11910 - if (matchIndex == N_MATCH_CHARS)
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;
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) {
11925 - if (nestDepth == 0) {
11930 - } else if (c == toMatch) {
11931 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11932 - if (style == styleToMatch)
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) {
11943 - if (nestDepth == 0) {
11948 - } else if (c == toMatch) {
11949 - if (matchSyntaxBased) style = GetHighlightInfo(window, pos);
11950 - if (style == styleToMatch)
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,
11970 XmNrightAttachment, XmATTACH_POSITION,
11971 XmNrightPosition, 99, NULL);
11973 + /* Pattern Match Feature: don't include "PLAIN" (4th parameter) */
11974 SmartIndentDialog.lmPulldown = CreateLanguageModeMenu(lmForm, langModeCB,
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)
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"
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;
12059 + * Pattern Match Feature:
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
12070 XmToggleButtonSetState(window->saveLastItem, window->saveOldVersion, False);
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;
12102 window->showStats = orgWin->showStats;
12103 window->showISearchLine = orgWin->showISearchLine;
12104 window->showLineNumbers = orgWin->showLineNumbers;
12105 window->modeMessageDisplayed = orgWin->modeMessageDisplayed;