Updated TODO.
[grutatxt.git] / grutatxt
blobe52f2121df41d79e563cadcf84e59dcae2437f2d
1 #!/usr/bin/perl
3 use lib '.';
6 # grutatxt - Text to HTML (and other formats) converter
7 # http://www.triptico.com/software/grutatxt.html
9 # Copyright (C) 2000/2004 Angel Ortega <angel@triptico.com>
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 # http://www.triptico.com
28 use Getopt::Long;
29 use locale;
30 use Grutatxt;
32 $VERSION = $Grutatxt::VERSION . ":1";
34 # input file
35 $input_file = "-";
37 # output file
38 $output_file = ">-";
40 # CSS information
41 $css = "";
42 $embed_css = 0;
44 # page title
45 $title = "";
47 # offset for the h? headers
48 $header_offset = 0;
50 # default mode
51 $mode = "HTML";
53 # use real dl
54 $dl_as_dl = 0;
56 # troff table type
57 $table_type = "allbox";
59 # abstract line number
60 $abstract = 0;
62 # man page section
63 $man_section = 1;
65 #####################################################################
67 # parse options
68 if(!GetOptions( "i|input=s" => \$input_file,
69 "o|output=s" => \$output_file,
70 "c|css=s" => \$css,
71 "e|embed-css" => \$embed_css,
72 "t|title=s" => \$title,
73 "f|header-offset=s" => \$header_offset,
74 "b|table-headers" => \$table_headers,
75 "ct|center-tables" => \$center_tables,
76 "xt|expand-tables" => \$expand_tables,
77 "sp|strip-parens" => \$strip_parens,
78 "nb|no-body" => \$no_body,
79 "v|version" => \$version,
80 "h|help" => \$usage,
81 "m|mode=s" => \$mode,
82 "s|man-section=s" => \$man_section,
83 "dl" => \$dl_as_dl)
84 or $usage)
86 usage();
89 if($version)
91 print "$VERSION\n"; exit(0);
94 open I, $input_file or die "Can't open $input_file: $!";
95 open O, ">$output_file" or die "Can't create $output_file: $!";
97 $content = join("",<I>);
98 close I;
100 $content_title = "";
102 $grutatxt = new Grutatxt(
103 "mode" => $mode,
104 "header-offset" => $header_offset,
105 "table-headers" => $table_headers,
106 "center-tables" => $center_tables,
107 "expand-tables" => $expand_tables,
108 "strip-parens" => $strip_parens,
109 "strip-dollars" => $strip_dollars,
110 "dl-as-dl" => $dl_as_dl,
111 "table-type" => $table_type,
112 "title" => \$content_title,
113 "abstract" => \$abstract,
114 "page-name" => $title,
115 "section" => $man_section
118 @result = $grutatxt->process($content);
120 $title = $content_title unless $title;
121 $no_body = 1 unless $mode =~ /^html$/i;
123 unless($no_body)
125 print O "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n";
126 print O " \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n";
127 print O "<html><head>\n";
128 print O "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>\n";
129 print O "<title>$title</title>\n";
131 printf O "<!-- converted from text by grutatxt $VERSION on %s -->\n", scalar(localtime);
133 if($css)
135 if($embed_css)
137 if(open C, $css)
139 my ($c) = join('', <C>);
140 close C;
142 print O "<style type='text/css'>\n";
143 print O $c . "\n";
144 print O "</style>\n";
146 else
148 die "Can't open '$css' CSS file.";
151 else
153 print O "<link rel=StyleSheet href='$css' type='text/css'>";
157 print O "</head><body>\n";
160 foreach my $l (@result)
162 print O "$l\n";
165 print O "</body></html>\n" unless $no_body;
167 close O;
169 exit(0);
172 sub usage
174 print "grutatxt $VERSION - Grutatxt format processor\n";
175 print "Copyright (C) 2000/2004 Angel Ortega <angel\@triptico.com>\n";
176 print "This software is covered by the GPL license. NO WARRANTY.\n\n";
178 print "Usage:\n";
179 print "\n";
180 print "grutatxt [options] < input_text_file > output_html_file\n";
181 print "\n";
182 print "Global options:\n\n";
183 print " -i|--input=FILE Input file (STDIN)\n";
184 print " -o|--output=FILE Output file (STDOUT)\n";
185 print " -t|--title=TITLE Document title (if unset,\n";
186 print " level 1 heading is used)\n";
187 print " -sp|--strip-parens Strip parentheses in function\n";
188 print " names (shown monospaced anyway)\n";
189 print " -sd|--strip-dollars Strip leading \$ in variable\n";
190 print " names (shown monospaced anyway)\n";
191 print " -m|--mode=[HTML|troff|man] Selects output mode, HTML, troff or man\n";
192 print " (default: HTML)\n";
193 print "HTML options:\n\n";
194 print " -c|--css=CSS_URL_OR_FILE CSS URL (or file if using --embed-css)\n";
195 print " -e|--embed-css Embed CSS instead of linking to it\n";
196 print " -f|--header-offset=NUMBER Offset to add to <h1>,\n";
197 print " <h2>... headers (default 0)\n";
198 print " -b|--table-headers Use <th> instead of <td> in\n";
199 print " the first row of each table\n";
200 print " -ct|--center-tables Centers the tables\n";
201 print " -xt|--expand-tables Expands the tables (width=100\%)\n";
202 print " -nb|-no-body Don't generate <html><body>...\n";
203 print " </body></html> enclosing.\n";
204 print " -dl Use real <dl>, <dd> and <dt>\n";
205 print " instead of tables in definition lists.\n";
206 print "troff options:\n\n";
207 print " --table-type=TYPE Table type. Possible values:\n";
208 print " box, allbox, doublebox (default allbox)\n";
209 print "man options:\n\n";
210 print " -s|--man-section=section Man page section (default: 1)\n";
212 exit(0);