3 # Helper script for context help in Cinelerra
4 # Calling: ContextManual.pl "<help keyphrase>"
5 # Searches the requested key in the following order:
8 # 3) all manual pages via grep
9 # 4) FFmpeg or Ladspa plugins
10 # The first item found is shown via the default web browser
11 # If nothing found, the Contents itself is shown
12 # On empty keyphrase do nothing
13 # The special keyphrase "TOC" shows Contents, "IDX" shows Index
14 # The keyphrase starting with "FILE:" shows the file named after colon
16 # Several important definitions
18 # Web browser executable
19 $cin_browser = $ENV{'CIN_BROWSER'};
20 # a likely default browser
21 $cin_browser = 'firefox' if $cin_browser eq '';
22 # another possible browser
23 #$cin_browser = 'xdg-open' if $cin_browser eq '';
24 # a fake browser for debugging
25 #$cin_browser = 'echo';
27 # The node with the manual contents
28 $contents_node = 'Contents.html';
30 # The node with the manual index
31 $index_node = 'Index.html';
33 # Several special plugin names necessary to rewrite
35 # Rendered effects and transitions are not segmented in the Contents
36 "CD Ripper" => "Rendered Audio Effects",
37 "Normalize" => "Rendered Audio Effects",
38 "Resample" => "Rendered Audio Effects",
39 "Time stretch" => "Rendered Audio Effects",
41 "720 to 480" => "Rendered Video Effects",
42 "Reframe" => "Rendered Video Effects",
44 # Audio transitions are segmented in the Index
45 # "Crossfade" => "Audio Transitions",
47 # Video transitions are segmented in the Index
48 # "BandSlide" => "Video Transitions",
49 # "BandWipe" => "Video Transitions",
50 # "Dissolve" => "Video Transitions",
51 # "Flash" => "Video Transitions",
52 # "IrisSquare" => "Video Transitions",
53 # "Shape Wipe" => "Video Transitions",
54 # "Slide" => "Video Transitions",
55 # "Wipe" => "Video Transitions",
56 # "Zoom" => "Video Transitions",
58 # Several not properly matched names
59 "AgingTV" => "Aging TV",
60 "Brightness/Contrast" => "Brightness\\/Contrast",
61 "Chroma key (HSV)" => "Chroma Key \\(HSV\\)",
62 "Crop & Position" => "Crop & Position",
63 "FindObj" => "Find Object",
64 "RGB - 601" => "RGB-601",
65 "ShiftInterlace" => "Shift Interlace",
66 "Cinelerra: Scopes" => "Videoscope"
69 # Cinelerra installation path
70 $cin_dat = $ENV{'CIN_DAT'};
71 $cin_dat = '.' if $cin_dat eq '';
73 # Cinelerra HTML manual must reside here
74 $cin_man = "$cin_dat/doc/CinelerraGG_Manual";
75 $contents = $cin_man.'/'.$contents_node;
76 $index = $cin_man.'/'.$index_node;
77 #print "ContextManual: using contents $contents\n";
79 # 1st argument is the requested key
81 #print "ContextManual: request=$help_key\n";
82 # Do nothing if no key requested
83 exit 0 if $help_key eq '';
84 # Show contents on this special request
85 if ($help_key eq 'TOC')
87 system "$cin_browser \"file://$contents\" &";
90 # Show index on this special request
91 if ($help_key eq 'IDX')
93 system "$cin_browser \"file://$index\" &";
96 # Show the named file on this special request
97 if ($help_key =~ /^FILE:/)
99 $help_key =~ s/^FILE://;
100 $help_key = $cin_man.'/'.$help_key;
101 system "$cin_browser \"file://$help_key\" &";
105 $help_key = $rewrite{$help_key} if exists $rewrite{$help_key};
106 # Do nothing if no key requested
107 exit 0 if $help_key eq '';
108 # Show contents on this special request
109 if ($help_key eq 'TOC')
111 system "$cin_browser \"file://$contents\" &";
114 # Show index on this special request
115 if ($help_key eq 'IDX')
117 system "$cin_browser \"file://$index\" &";
120 # Show the named file on this special request
121 if ($help_key =~ /^FILE:/)
123 $help_key =~ s/^FILE://;
124 $help_key = $cin_man.'/'.$help_key;
125 system "$cin_browser \"file://$help_key\" &";
129 # Now try searching...
130 open CONTENTS, $contents or die "Cannot open $contents: $!";
132 # First search contents for the exact key
136 last if ($node) = /^\s*HREF=\"(.+?\.html)\">\s*$help_key\s*<\/A>$/;
138 # If not found, search contents for an approximate key
145 last if ($node) = /^\s*HREF=\"(.+?\.html)\">.*?$help_key.*?<\/A>$/i;
149 # If not found, search index for the exact key
152 open INDEX, $index or die "Cannot open $index: $!";
156 # Cut off anchor: xdg-open does not like it
157 last if ($node) = /<A\s+HREF=\"(.+?\.html)(?:#\d+)?\">\s*$help_key\s*<\/A>$/;
159 # last if ($node) = /<A\s+HREF=\"(.+?\.html(?:#\d+)?)\">\s*$help_key\s*<\/A>$/;
163 # If not found, search index for an approximate key
166 open INDEX, $index or die "Cannot open $index: $!";
170 # Cut off anchor: xdg-open does not like it
171 last if ($node) = /<A\s+HREF=\"(.+?\.html)(?:#\d+)?\">.*?$help_key.*?<\/A>$/i;
173 # last if ($node) = /<A\s+HREF=\"(.+?\.html(?:#\d+)?)\">.*?$help_key.*?<\/A>$/i;
178 # If not found, grep manual for exact key instance
181 $_ = `grep -l \"$help_key\" $cin_dat/doc/CinelerraGG_Manual/*.html`;
184 # If not found, grep manual for case insensitive key instance
187 $_ = `grep -il \"$help_key\" $cin_dat/doc/CinelerraGG_Manual/*.html`;
193 if ($help_key =~ /^F_/)
194 { # If not found, search contents for FFmpeg plugins
195 $help_key = 'FFmpeg Audio and Video Plugins';
200 last if ($node) = /^\s*HREF=\"(.+?\.html)\">\s*$help_key\s*<\/A>$/;
203 elsif ($help_key =~ /^L_/)
204 { # If not found, search contents for LADSPA plugins
205 $help_key = 'Audio Ladspa Effects';
210 last if ($node) = /^\s*HREF=\"(.+?\.html)\">\s*$help_key\s*<\/A>$/;
217 # If still nothing found, show contents
218 $node = $contents_node if $node eq '';
219 $node = $cin_man.'/'.$node unless $node =~ /\//;
220 #print "ContextManual: found $node\n";
222 # Call browser to show the proposed HTML file
223 system "$cin_browser \"file://$node\" &";
225 # And immediately return to the caller