mktar: Use `wc` instead of `du` in summary message
[sunny256-utils.git] / commout
bloba76fe20b9e9b4eedc8ad02f40cd648fa31fb8b51
1 #!/usr/bin/env perl
3 #=======================================================================
4 # commout
5 # File ID: 998d8948-5d37-11df-86c9-90e6ba3022ac
6 # Kommenterer ut stdin.
7 #=======================================================================
9 use strict;
10 use warnings;
12 my $comm_pattern = "";
13 my $is_c = 0;
14 my $is_dbk = 0;
15 my $is_l = 0;
16 my $is_html = 0;
17 my $is_pre = 0;
18 my $is_re = 0;
19 my $prog_name = "commout";
20 my $spc_str = "";
21 my $Kommentar = "";
23 if ($#ARGV > -1) {
24 $_ = $ARGV[0];
25 /^--h/ && &print_help(0) ||
26 /^dbk$/i && ($is_dbk = 1) ||
27 /^html$/i && ($is_html = 1) ||
28 /^pre$/i && ($is_pre = 1) ||
29 /^re$/i && ($is_re = 1, $is_pre = 1) ||
30 /^c$/i && ($is_c = 1) ||
31 /^l$/i && ($is_l = 1) ||
32 ($comm_pattern = $ARGV[0]);
33 } else {
34 $comm_pattern = '#';
37 if ($is_l) {
38 my $Element = defined($ARGV[1]) ? $ARGV[1] : "l";
39 while (<STDIN>) {
40 chomp;
41 print("<$Element>$_</$Element>\n");
43 exit 0;
46 defined($ARGV[1]) && ($spc_str = " ", $Kommentar = $ARGV[1]);
48 $is_dbk && print("<!--$spc_str" . $Kommentar . " !-!\n") ||
49 $is_html && print("<!--$spc_str" . $Kommentar . " \x7B\x7B\x7B\n") ||
50 $is_pre && printf("%s<pre>\n", $is_re ? "" : "<p>") ||
51 $is_c && printf("/*$spc_str" . $Kommentar . "\n");
53 my $Bck = "";
54 while (<STDIN>) {
55 ($is_dbk || $is_html || $is_pre || $is_c) || s/^([\t ]*)/$1$comm_pattern /;
56 print;
57 $Bck = $_;
60 if ($is_html || $is_c) {
61 # Hvis stdin ikke slutta med newline, skrives en space.
62 $Bck =~ /\n$/ || print(" ");
65 $is_dbk && print("-->\n") ||
66 $is_html && print("\x7D\x7D\x7D -->\n") ||
67 $is_pre && print("</pre>\n") ||
68 $is_c && print(" */\n");
70 sub print_help {
71 my $Retval = shift;
73 print <<END;
74 Syntax:
76 $prog_name
77 For bruk i bl.a. perl og sh. Setter '#' foran hver linje.
79 $prog_name dbk ["Overskrift"]
80 dbk-filer.
82 $prog_name html ["Overskrift"]
83 HTML-source.
85 $prog_name pre
86 Også til html, men <p><pre> brukes istedenfor.
88 $prog_name re
89 Som "pre", men uten <p> i begynnelsen.
91 $prog_name c
92 C-kode. Setter inn /* */ .
94 $prog_name l [tag]
95 XML-elementer. Setter inn <l> hvis ingenting skrives som parametere.
97 $prog_name [andre_ting]
98 Setter [andre_ting] foran hver linje.
101 exit($Retval);
102 } # print_help()
104 # vim: set ts=4 sw=4 sts=4 et fenc=utf8 fo+=w2 :