cbb143416adfd34762ceb844ed12c725f987e18d
[goodguy/cinelerra.git] / cinelerra-5.1 / doc / ContextManual.pl
1 #!/usr/bin/perl
2
3 # Helper script for context help in Cinelerra
4 # Calling: ContextManual.pl "<help keyphrase>"
5 # Searches the requested key in the following order:
6 # 1) manual Contents
7 # 2) manual Index
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
15
16 # Several important definitions
17
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';
26
27 # The node with the manual contents
28 $contents_node = 'Contents.html';
29
30 # The node with the manual index
31 $index_node = 'Index.html';
32
33 # Several special plugin names necessary to rewrite
34 %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",
42
43   "720 to 480"          => "Rendered Video Effects",
44   "Reframe"             => "Rendered Video Effects",
45
46   # Audio transitions are segmented in the Index
47 #  "Crossfade"           => "Audio Transitions",
48
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",
59
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 &amp; Position",
65   "FindObj"             => "Find Object",
66   "RGB - 601"           => "RGB-601",
67   "ShiftInterlace"      => "Shift Interlace",
68   "Cinelerra: Scopes"   => "Videoscope"
69   );
70
71 # Cinelerra installation path
72 $cin_dat = $ENV{'CIN_DAT'};
73 $cin_dat = '.' if $cin_dat eq '';
74
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";
80
81 # 1st argument is the requested key
82 $help_key = $ARGV[0];
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')
88 {
89   system "$cin_browser \"file://$contents\" &";
90   exit 0;
91 }
92 # Show index on this special request
93 if ($help_key eq 'IDX')
94 {
95   system "$cin_browser \"file://$index\" &";
96   exit 0;
97 }
98 # Show the named file on this special request
99 if ($help_key =~ /^FILE:/)
100 {
101   $help_key =~ s/^FILE://;
102   $help_key = $cin_man.'/'.$help_key;
103   system "$cin_browser \"file://$help_key\" &";
104   exit 0;
105 }
106
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')
112 {
113   system "$cin_browser \"file://$contents\" &";
114   exit 0;
115 }
116 # Show index on this special request
117 if ($help_key eq 'IDX')
118 {
119   system "$cin_browser \"file://$index\" &";
120   exit 0;
121 }
122 # Show the named file on this special request
123 if ($help_key =~ /^FILE:/)
124 {
125   $help_key =~ s/^FILE://;
126   $help_key = $cin_man.'/'.$help_key;
127   system "$cin_browser \"file://$help_key\" &";
128   exit 0;
129 }
130
131 # Now try searching...
132 open CONTENTS, $contents or die "Cannot open $contents: $!";
133 $node = '';
134 # First search contents for the exact key
135 while (<CONTENTS>)
136 {
137   chomp;
138   last if ($node) = /^\s*HREF=\"(.+?\.html)\">\s*$help_key\s*<\/A>$/;
139 }
140 # If not found, search contents for an approximate key
141 if ($node eq '')
142 {
143   seek CONTENTS, 0, 0;
144   while (<CONTENTS>)
145   {
146     chomp;
147     last if ($node) = /^\s*HREF=\"(.+?\.html)\">.*?$help_key.*?<\/A>$/i;
148   }
149 }
150
151 # If not found, search index for the exact key
152 if ($node eq '')
153 {
154   open INDEX, $index or die "Cannot open $index: $!";
155   while (<INDEX>)
156   {
157     chomp;
158     # Cut off anchor: xdg-open does not like it
159     last if ($node) = /<A\s+HREF=\"(.+?\.html)(?:#\d+)?\">\s*$help_key\s*<\/A>$/;
160     # Retain anchor
161 #    last if ($node) = /<A\s+HREF=\"(.+?\.html(?:#\d+)?)\">\s*$help_key\s*<\/A>$/;
162   }
163   close INDEX;
164 }
165 # If not found, search index for an approximate key
166 if ($node eq '')
167 {
168   open INDEX, $index or die "Cannot open $index: $!";
169   while (<INDEX>)
170   {
171     chomp;
172     # Cut off anchor: xdg-open does not like it
173     last if ($node) = /<A\s+HREF=\"(.+?\.html)(?:#\d+)?\">.*?$help_key.*?<\/A>$/i;
174     # Retain anchor
175 #    last if ($node) = /<A\s+HREF=\"(.+?\.html(?:#\d+)?)\">.*?$help_key.*?<\/A>$/i;
176   }
177   close INDEX;
178 }
179
180 # If not found, grep manual for exact key instance
181 if ($node eq '')
182 {
183   $_ = `grep -l \"$help_key\" $cin_dat/doc/CinelerraGG_Manual/*.html`;
184   ($node) = split;
185 }
186 # If not found, grep manual for case insensitive key instance
187 if ($node eq '')
188 {
189   $_ = `grep -il \"$help_key\" $cin_dat/doc/CinelerraGG_Manual/*.html`;
190   ($node) = split;
191 }
192
193 if ($node eq '')
194 {
195   if ($help_key =~ /^F_/)
196   { # If not found, search contents for FFmpeg plugins
197     $help_key = 'FFmpeg Audio and Video Plugins';
198     seek CONTENTS, 0, 0;
199     while (<CONTENTS>)
200     {
201       chomp;
202       last if ($node) = /^\s*HREF=\"(.+?\.html)\">\s*$help_key\s*<\/A>$/;
203     }
204   }
205   elsif ($help_key =~ /^L_/)
206   { # If not found, search contents for LADSPA plugins
207     $help_key = 'Audio Ladspa Effects';
208     seek CONTENTS, 0, 0;
209     while (<CONTENTS>)
210     {
211       chomp;
212       last if ($node) = /^\s*HREF=\"(.+?\.html)\">\s*$help_key\s*<\/A>$/;
213     }
214   }
215 }
216
217 close CONTENTS;
218
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";
223
224 # Call browser to show the proposed HTML file
225 system "$cin_browser \"file://$node\" &";
226
227 # And immediately return to the caller
228 exit 0;