fix smoketest linkage
[LibreOffice.git] / bin / generate-bash-completion
blob0a7b233e9d55665c3c10b2438ee741ae6a783f30
1 #!/usr/bin/env perl
2 # script to generate LibreOffice bash_completion file for the main applications
3 # written by Rene Engelhard <rene@debian.org>, Public Domain
4 # updated for libreoffice-build by Petr Mladek <pmladek@suse.cz>, Public Domain
5 # yes, this script probably is not real good code :) but still easier
6 # to maintain than adding those entries statically many times in
7 # a file...
9 use strict;
11 my @DRAWDOCS=("sxd", "std", "dxf", "emf", "eps", "met", "pct", "sgf", "sgv", "sda",
12 "sdd", "vor", "svm", "wmf", "bmp", "gif", "jpg", "jpeg", "jfif", "fif",
13 "jpe", "pcd", "pcx", "pgm", "png", "ppm", "psd", "ras", "tga", "tif",
14 "tiff", "xbm", "xpm", "odg", "otg", "fodg", "odc", "odi", "sds",
15 "wpg", "svg");
17 my @IMPRESSDOCS=("sxi", "sti", "ppt", "pps", "pot", "sxd", "sda", "sdd", "sdp",
18 "vor", "cgm", "odp", "otp", "fodp", "ppsm", "ppsx", "pptm", "pptx",
19 "potm", "potx");
21 my @TEMPLATES=("stw", "dot", "vor", "stc", "xlt", "sti", "pot", "std", "stw",
22 "dotm", "dotx", "potm", "potx", "xltm", "xltx");
24 my @MATHDOCS=("sxm", "smf", "mml", "odf");
26 my @MASTERDOCS=("sxg", "odm", "sgl");
28 my @WRITERDOCS=("doc", "dot", "rtf", "sxw", "stw", "sdw", "vor", "txt", "htm?",
29 "xml", "wp", "wpd", "wps", "odt", "ott", "fodt", "docm", "docx",
30 "dotm", "dotx");
32 my @WEBDOCS=("htm", "html", "stw", "txt", "vor", "oth");
34 my @BASEDOCS=("odb");
36 my @CALCDOCS=("sxc", "stc", "dif", "dbf", "xls", "xlw", "xlt", "rtf", "sdc", "vor",
37 "slk", "txt", "htm", "html", "wk1", "wks", "123", "xml", "ods", "ots",
38 "fods", "csv", "xlsb", "xlsm", "xlsx", "xltm", "xltx");
40 my @EXTENSIONS=("oxt");
42 # default names of lowrappers
43 # use "" if you want to disable any wrapper
44 my %APPS = (
45 office => "libreoffice",
46 office_short => "loffice",
47 master => "",
48 base => "lobase",
49 calc => "localc",
50 draw => "lodraw",
51 impress => "loimpress",
52 math => "lomath",
53 template => "lofromtemplate",
54 unopkg => "unopkg",
55 web => "loweb",
56 writer => "lowriter",
59 my $office_shell_function = "_loexp_";
61 sub usage()
63 print "Script to Generate bash completion for LO wrappers\n\n";
65 print "Usage: $0 --help\n";
66 print " $0 [--binsuffix=suffix]\n";
67 print "\t\t[--compat-oowrappers]\n";
68 print "\t\t[--office=wrapper_name]\n";
69 print "\t\t[--office-short=wrapper_name]\n";
70 print "\t\t[--master=wrapper_name]\n";
71 print "\t\t[--base=wrapper_name]\n";
72 print "\t\t[--calc=wrapper_name]\n";
73 print "\t\t[--draw=wrapper_name]\n";
74 print "\t\t[--impress=wrapper_name]\n";
75 print "\t\t[--math=wrapper_name]\n";
76 print "\t\t[--template=wrapper_name]\n";
77 print "\t\t[--unopkg=wrapper_name]\n";
78 print "\t\t[--web=wrapper_name]\n";
79 print "\t\t[--writer=wrapper_name]\n";
80 print "\t\tinput_file\n";
81 print "\t\toutput_file\n\n";
83 print "Options:\n";
84 print "\t--help\t\tprint this help\n";
85 print "\t--binsuffix\tdefines a suffix that is added after each wrapper\n";
86 print "\t--compat-oowrappers\tset wrapper names to the old default oo* wrapper names\n";
88 print "The other options allows to redefine the wrapper names.\n";
89 print "The value \"\" can be used to disable any wrapper.\n\n";
92 my $infilename;
93 my $outfilename;
94 my $binsuffix = '';
96 my $opt;
97 foreach my $arg (@ARGV) {
98 if ( $arg =~ /--help/ ) {
99 usage();
100 exit 0;
101 } elsif ( $arg =~ /--compat-oowrappers/ ) {
102 $APPS{'office'} = "openoffice";
103 $APPS{'office_short'} = "ooffice";
104 $APPS{'master'} = "";
105 $APPS{'base'} = "oobase";
106 $APPS{'calc'} = "oocalc";
107 $APPS{'draw'} = "oodraw";
108 $APPS{'impress'} = "ooimpress";
109 $APPS{'math'} = "oomath";
110 $APPS{'template'} = "oofromtemplate";
111 $APPS{'unopkg'} = "unopkg";
112 $APPS{'web'} = "ooweb";
113 $APPS{'writer'} = "oowriter";
114 $office_shell_function = "_ooexp_";
115 } elsif ( $arg =~ /--binsuffix=(.*)/ ) {
116 $binsuffix = "$1";
117 } elsif ( $arg =~ /--office=(.*)/ ) {
118 $APPS{'office'} = "$1";
119 } elsif ( $arg =~ /--office-short=(.*)/ ) {
120 $APPS{'office_short'} = "$1";
121 } elsif ( $arg =~ /--master=(.*)/ ) {
122 $APPS{'master'} = "$1";
123 } elsif ( $arg =~ /--base=(.*)/ ) {
124 $APPS{'base'} = "$1";
125 } elsif ( $arg =~ /--calc=(.*)/ ) {
126 $APPS{'calc'} = "$1";
127 } elsif ( $arg =~ /--draw=(.*)/ ) {
128 $APPS{'draw'} = "$1";
129 } elsif ( $arg =~ /--impress=(.*)/ ) {
130 $APPS{'impress'} = "$1"
131 } elsif ( $arg =~ /--math=(.*)/ ) {
132 $APPS{'math'} = "$1";
133 } elsif ( $arg =~ /--template=(.*)/ ) {
134 $APPS{'template'} = "$1";
135 } elsif ( $arg =~ /--unopkg=(.*)/ ) {
136 $APPS{'unopkg'} = "$1";
137 } elsif ( $arg =~ /--web=(.*)/ ) {
138 $APPS{'web'} = "$1";
139 } elsif ( $arg =~ /--writer=(.*)/ ) {
140 $APPS{'writer'} = "$1"
141 } elsif ( $arg =~ /^-.*/ ) {
142 printf STDERR "Error: invalid option \"$arg\", try --help\n";
143 exit 1;
144 } elsif ( $outfilename ) {
145 printf STDERR "Error: too much arguments, try --help\n";
146 exit 1;
147 } else {
148 if ($infilename) {
149 $outfilename = "$arg";
150 } else {
151 $infilename = "$arg";
156 unless ( $infilename ) {
157 printf STDERR "Error: undefined input file, try --help\n";
158 exit 1;
161 unless ( $outfilename ) {
162 printf STDERR "Error: undefined output file, try --help\n";
163 exit 1;
166 #add binsuffix
167 foreach my $app (keys %APPS) {
168 $APPS{$app} .= "$binsuffix" unless ( "$APPS{$app}" eq "" );
171 sub print_suffixes_check {
172 my $app = shift(@_);
173 my $first_suffix = shift(@_);
175 ($first_suffix) || die "Error: No suffix defined for $app\n";
177 print BCOUTFILE " $app)\t\te=\'!*.+(" . $first_suffix . "|" . uc($first_suffix);
178 foreach my $suffix (@_) {
179 print BCOUTFILE "|" . $suffix;
180 print BCOUTFILE "|" . uc($suffix);
182 print BCOUTFILE ")\' ;;\n";
185 sub print_suffixes_checks {
186 foreach my $app (keys %APPS) {
187 # skip the disabled wrapper
188 next if ( $APPS{$app} eq "" );
190 if ($app eq "draw" ) { print_suffixes_check ($APPS{$app}, @DRAWDOCS); }
191 if ($app eq "writer") { print_suffixes_check ($APPS{$app}, @WRITERDOCS, @MASTERDOCS); }
192 if ($app eq "web") { print_suffixes_check ($APPS{$app}, @WEBDOCS); }
193 if ($app eq "math") { print_suffixes_check ($APPS{$app}, @MATHDOCS); }
194 if ($app eq "impress") { print_suffixes_check ($APPS{$app}, @IMPRESSDOCS); }
195 if ($app eq "base") { print_suffixes_check ($APPS{$app}, @BASEDOCS); }
196 if ($app eq "calc") { print_suffixes_check ($APPS{$app}, @CALCDOCS); }
197 if ($app eq "master") { print_suffixes_check ($APPS{$app}, @MASTERDOCS); }
198 if ($app eq "template") { print_suffixes_check ($APPS{$app}, @TEMPLATES); }
199 # libreoffice should contain all...
200 if (($app eq "office") || ($app eq "office_short"))
201 { print_suffixes_check ($APPS{$app}, @DRAWDOCS, @WRITERDOCS, @MATHDOCS, @IMPRESSDOCS, @BASEDOCS, @CALCDOCS, @MASTERDOCS, @TEMPLATES, @WEBDOCS); }
202 # unopkg is a standalone tool
203 if ($app eq "unopkg") { print_suffixes_check ($APPS{$app}, @EXTENSIONS); }
207 sub print_apps {
208 my $app_to_print;
209 foreach my $app (keys %APPS) {
210 # skip the disabled wrapper
211 next if ( $APPS{$app} eq "" );
213 print BCOUTFILE "\t\t\t\t\t$app_to_print \\\n" if ($app_to_print);
214 $app_to_print = $APPS{$app};
216 # the last app will be printed without the final backslash
217 ($app_to_print) || die "Error: No LO wrapper was selected\n";
218 print BCOUTFILE "\t\t\t\t\t$app_to_print\n";
222 open (BCINFILE, "$infilename") || die "Error: can't open $infilename for reading: $!\n";
223 open (BCOUTFILE, "> $outfilename") || die "Error: can't open $outfilename for writing: $!\n";
225 while (my $line = <BCINFILE>) {
226 chomp $line;
228 $line =~ s/\@OFFICE_SHELL_FUNCTION\@/$office_shell_function/;
230 if ($line =~ m/\@BASH_COMPLETION_SUFFIXES_CHECKS\@/) {
231 print_suffixes_checks();
232 } elsif ($line =~ m/\@BASH_COMPLETION_OOO_APPS\@/) {
233 print_apps();
234 } else {
235 print BCOUTFILE "$line\n";
239 close (BCINFILE);
240 close (BCOUTFILE);