ffmpeg upgrade from 4.3 to 4.4 / Andrew fixed patches except patch2/B by Freelancer
[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"           => "Rendered Audio Effects",
37   "Normalize"           => "Rendered Audio Effects",
38   "Resample"            => "Rendered Audio Effects",
39   "Time stretch"        => "Rendered Audio Effects",
40
41   "720 to 480"          => "Rendered Video Effects",
42   "Reframe"             => "Rendered Video Effects",
43
44   # Audio transitions are segmented in the Index
45 #  "Crossfade"           => "Audio Transitions",
46
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",
57
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 &amp; Position",
63   "FindObj"             => "Find Object",
64   "RGB - 601"           => "RGB-601",
65   "ShiftInterlace"      => "Shift Interlace",
66   "Cinelerra: Scopes"   => "Videoscope"
67   );
68
69 # Cinelerra installation path
70 $cin_dat = $ENV{'CIN_DAT'};
71 $cin_dat = '.' if $cin_dat eq '';
72
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";
78
79 # 1st argument is the requested key
80 $help_key = $ARGV[0];
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')
86 {
87   system "$cin_browser \"file://$contents\" &";
88   exit 0;
89 }
90 # Show index on this special request
91 if ($help_key eq 'IDX')
92 {
93   system "$cin_browser \"file://$index\" &";
94   exit 0;
95 }
96 # Show the named file on this special request
97 if ($help_key =~ /^FILE:/)
98 {
99   $help_key =~ s/^FILE://;
100   $help_key = $cin_man.'/'.$help_key;
101   system "$cin_browser \"file://$help_key\" &";
102   exit 0;
103 }
104
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')
110 {
111   system "$cin_browser \"file://$contents\" &";
112   exit 0;
113 }
114 # Show index on this special request
115 if ($help_key eq 'IDX')
116 {
117   system "$cin_browser \"file://$index\" &";
118   exit 0;
119 }
120 # Show the named file on this special request
121 if ($help_key =~ /^FILE:/)
122 {
123   $help_key =~ s/^FILE://;
124   $help_key = $cin_man.'/'.$help_key;
125   system "$cin_browser \"file://$help_key\" &";
126   exit 0;
127 }
128
129 # Now try searching...
130 open CONTENTS, $contents or die "Cannot open $contents: $!";
131 $node = '';
132 # First search contents for the exact key
133 while (<CONTENTS>)
134 {
135   chomp;
136   last if ($node) = /^\s*HREF=\"(.+?\.html)\">\s*$help_key\s*<\/A>$/;
137 }
138 # If not found, search contents for an approximate key
139 if ($node eq '')
140 {
141   seek CONTENTS, 0, 0;
142   while (<CONTENTS>)
143   {
144     chomp;
145     last if ($node) = /^\s*HREF=\"(.+?\.html)\">.*?$help_key.*?<\/A>$/i;
146   }
147 }
148
149 # If not found, search index for the exact key
150 if ($node eq '')
151 {
152   open INDEX, $index or die "Cannot open $index: $!";
153   while (<INDEX>)
154   {
155     chomp;
156     # Cut off anchor: xdg-open does not like it
157     last if ($node) = /<A\s+HREF=\"(.+?\.html)(?:#\d+)?\">\s*$help_key\s*<\/A>$/;
158     # Retain anchor
159 #    last if ($node) = /<A\s+HREF=\"(.+?\.html(?:#\d+)?)\">\s*$help_key\s*<\/A>$/;
160   }
161   close INDEX;
162 }
163 # If not found, search index for an approximate key
164 if ($node eq '')
165 {
166   open INDEX, $index or die "Cannot open $index: $!";
167   while (<INDEX>)
168   {
169     chomp;
170     # Cut off anchor: xdg-open does not like it
171     last if ($node) = /<A\s+HREF=\"(.+?\.html)(?:#\d+)?\">.*?$help_key.*?<\/A>$/i;
172     # Retain anchor
173 #    last if ($node) = /<A\s+HREF=\"(.+?\.html(?:#\d+)?)\">.*?$help_key.*?<\/A>$/i;
174   }
175   close INDEX;
176 }
177
178 # If not found, grep manual for exact key instance
179 if ($node eq '')
180 {
181   $_ = `grep -l \"$help_key\" $cin_dat/doc/CinelerraGG_Manual/*.html`;
182   ($node) = split;
183 }
184 # If not found, grep manual for case insensitive key instance
185 if ($node eq '')
186 {
187   $_ = `grep -il \"$help_key\" $cin_dat/doc/CinelerraGG_Manual/*.html`;
188   ($node) = split;
189 }
190
191 if ($node eq '')
192 {
193   if ($help_key =~ /^F_/)
194   { # If not found, search contents for FFmpeg plugins
195     $help_key = 'FFmpeg Audio and Video Plugins';
196     seek CONTENTS, 0, 0;
197     while (<CONTENTS>)
198     {
199       chomp;
200       last if ($node) = /^\s*HREF=\"(.+?\.html)\">\s*$help_key\s*<\/A>$/;
201     }
202   }
203   elsif ($help_key =~ /^L_/)
204   { # If not found, search contents for LADSPA plugins
205     $help_key = 'Audio Ladspa Effects';
206     seek CONTENTS, 0, 0;
207     while (<CONTENTS>)
208     {
209       chomp;
210       last if ($node) = /^\s*HREF=\"(.+?\.html)\">\s*$help_key\s*<\/A>$/;
211     }
212   }
213 }
214
215 close CONTENTS;
216
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";
221
222 # Call browser to show the proposed HTML file
223 system "$cin_browser \"file://$node\" &";
224
225 # And immediately return to the caller
226 exit 0;