uclient: update to Git HEAD (2024-04-19)
[openwrt/openwrt.git] / tools / missing-macros / src / bin / makeinfo
1 #!/usr/bin/env perl
2
3 use strict;
4 use Getopt::Long;
5
6 my $output;
7 my $version;
8 my $docbook;
9 my $html;
10 my $xml;
11 my $plaintext;
12 my $no_split;
13 my $no_headers;
14
15 Getopt::Long::Configure('pass_through');
16 Getopt::Long::GetOptions(
17 'output=s' => \$output,
18 'version' => \$version,
19 'no-split' => \$no_split,
20 'no-headers' => \$no_headers,
21 'docbook' => \$docbook,
22 'html' => \$html,
23 'xml' => \$xml,
24 'plaintext' => \$plaintext
25 );
26
27 if ($version)
28 {
29 print "makeinfo (OpenWrt stub) 9.99\n";
30 exit 0;
31 }
32
33
34 sub output_filename
35 {
36 my $path = shift || return;
37 my $name = $path;
38 my $setfile;
39
40 if (open F, "< $path")
41 {
42 while (defined(my $line = readline F))
43 {
44 if ($line =~ /\@setfilename\s+(\S+)/)
45 {
46 $setfile = $1;
47 $setfile =~ s!^.+/!!;
48 last;
49 }
50 }
51
52 close F;
53 }
54
55 $name =~ s!^.+/!!;
56 $name =~ s!\.[^.]+$!!;
57
58 if ($html)
59 {
60 $setfile =~ s!\.[^.]+$!! if $setfile;
61
62 if ($no_split)
63 {
64 return $setfile ? "$setfile.html" : "$name.html" unless $output;
65 return $output;
66 }
67
68 return $setfile ? "$setfile/index.html" : "$name/index.html" unless $output;
69 return "$output/index.html";
70 }
71 elsif ($xml || $docbook)
72 {
73 $setfile =~ s!\.[^.]+$!! if $setfile;
74
75 return $setfile ? "$setfile.xml" : "$name.info" unless $output;
76 return $output;
77 }
78 elsif ($plaintext)
79 {
80 return ($output || "-");
81 }
82
83 return ($output || $setfile || "$name.info");
84 }
85
86 foreach my $arg (@ARGV)
87 {
88 next unless -f $arg;
89
90 my $out = output_filename($arg);
91 if ($out =~ m!^(.+/)[^/]+$!)
92 {
93 system("mkdir", "-p", $1);
94 }
95
96 my $fd = \*STDOUT;
97 if ($out ne "-" && !$no_headers)
98 {
99 open $fd, "> $out" || die "Can't open $out: $!\n";
100 }
101
102 if ($html || $xml || $docbook)
103 {
104 print $fd "<!-- Dummy output for $arg -->\n";
105 }
106 else
107 {
108 print $fd "Dummy output for $arg\n";
109 }
110
111 close $fd;
112 }