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 is an audio effect but erroneously placed
37 # under Rendered Video Effects in the manual
38 "CD Ripper" => "Rendered Audio Effects",
39 "Normalize" => "Rendered Audio Effects",
40 "Resample" => "Rendered Audio Effects",
41 "Time stretch" => "Rendered Audio Effects",
43 "720 to 480" => "Rendered Video Effects",
44 "Reframe" => "Rendered Video Effects",
46 # Audio transitions are segmented in the Index
47 # "Crossfade" => "Audio Transitions",
49 # Video transitions are segmented in the Index
50 # "BandSlide" => "Video Transitions",
51 # "BandWipe" => "Video Transitions",
52 # "Dissolve" => "Video Transitions",
53 # "Flash" => "Video Transitions",
54 # "IrisSquare" => "Video Transitions",
55 # "Shape Wipe" => "Video Transitions",
56 # "Slide" => "Video Transitions",
57 # "Wipe" => "Video Transitions",
58 # "Zoom" => "Video Transitions",
60 # Several not properly matched names
61 "AgingTV" => "Aging TV",
62 "Brightness/Contrast" => "Brightness\\/Contrast",
63 "Chroma key (HSV)" => "Chroma Key \\(HSV\\)",
64 "Crop & Position" => "Crop & Position",
65 "FindObj" => "Find Object",
66 "RGB - 601" => "RGB-601",
67 "ShiftInterlace" => "Shift Interlace",
68 "Cinelerra: Scopes" => "Videoscope"
71 # Cinelerra installation path
72 $cin_dat = $ENV{'CIN_DAT'};
73 $cin_dat = '.' if $cin_dat eq '';
75 # Cinelerra HTML manual must reside here
76 $cin_man = "$cin_dat/doc/CinelerraGG_Manual";
77 $contents = $cin_man.'/'.$contents_node;
78 $index = $cin_man.'/'.$index_node;
79 #print "ContextManual: using contents $contents\n";
81 # 1st argument is the requested key
83 #print "ContextManual: request=$help_key\n";
84 # Do nothing if no key requested
85 exit 0 if $help_key eq '';
86 # Show contents on this special request
87 if ($help_key eq 'TOC')
89 system "$cin_browser \"file://$contents\" &";
92 # Show index on this special request
93 if ($help_key eq 'IDX')
95 system "$cin_browser \"file://$index\" &";
98 # Show the named file on this special request
99 if ($help_key =~ /^FILE:/)
101 $help_key =~ s/^FILE://;
102 $help_key = $cin_man.'/'.$help_key;
103 system "$cin_browser \"file://$help_key\" &";
107 $help_key = $rewrite{$help_key} if exists $rewrite{$help_key};
108 # Do nothing if no key requested
109 exit 0 if $help_key eq '';
110 # Show contents on this special request
111 if ($help_key eq 'TOC')
113 system "$cin_browser \"file://$contents\" &";
116 # Show index on this special request
117 if ($help_key eq 'IDX')
119 system "$cin_browser \"file://$index\" &";
122 # Show the named file on this special request
123 if ($help_key =~ /^FILE:/)
125 $help_key =~ s/^FILE://;
126 $help_key = $cin_man.'/'.$help_key;
127 system "$cin_browser \"file://$help_key\" &";
131 # Now try searching...
132 open CONTENTS, $contents or die "Cannot open $contents: $!";
134 # First search contents for the exact key
138 last if ($node) = /^\s*HREF=\"(.+?\.html)\">\s*$help_key\s*<\/A>$/;
140 # If not found, search contents for an approximate key
147 last if ($node) = /^\s*HREF=\"(.+?\.html)\">.*?$help_key.*?<\/A>$/i;
151 # If not found, search index for the exact key
154 open INDEX, $index or die "Cannot open $index: $!";
158 # Cut off anchor: xdg-open does not like it
159 last if ($node) = /<A\s+HREF=\"(.+?\.html)(?:#\d+)?\">\s*$help_key\s*<\/A>$/;
161 # last if ($node) = /<A\s+HREF=\"(.+?\.html(?:#\d+)?)\">\s*$help_key\s*<\/A>$/;
165 # If not found, search index for an approximate key
168 open INDEX, $index or die "Cannot open $index: $!";
172 # Cut off anchor: xdg-open does not like it
173 last if ($node) = /<A\s+HREF=\"(.+?\.html)(?:#\d+)?\">.*?$help_key.*?<\/A>$/i;
175 # last if ($node) = /<A\s+HREF=\"(.+?\.html(?:#\d+)?)\">.*?$help_key.*?<\/A>$/i;
180 # If not found, grep manual for exact key instance
183 $_ = `grep -l \"$help_key\" $cin_dat/doc/CinelerraGG_Manual/*.html`;
186 # If not found, grep manual for case insensitive key instance
189 $_ = `grep -il \"$help_key\" $cin_dat/doc/CinelerraGG_Manual/*.html`;
195 if ($help_key =~ /^F_/)
196 { # If not found, search contents for FFmpeg plugins
197 $help_key = 'FFmpeg Audio and Video Plugins';
202 last if ($node) = /^\s*HREF=\"(.+?\.html)\">\s*$help_key\s*<\/A>$/;
205 elsif ($help_key =~ /^L_/)
206 { # If not found, search contents for LADSPA plugins
207 $help_key = 'Audio Ladspa Effects';
212 last if ($node) = /^\s*HREF=\"(.+?\.html)\">\s*$help_key\s*<\/A>$/;
219 # If still nothing found, show contents
220 $node = $contents_node if $node eq '';
221 $node = $cin_man.'/'.$node unless $node =~ /\//;
222 #print "ContextManual: found $node\n";
224 # Call browser to show the proposed HTML file
225 system "$cin_browser \"file://$node\" &";
227 # And immediately return to the caller