first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / scripts / files / filedump.pl
1 #!/usr/bin/perl
2
3 ###############################################################################
4 #                                                                             #
5 #  Name   : filedump                                                          #
6 #  Author : Chris Koeritz                                                     #
7 #  Rights : Copyright (C) 1996-$now by Author                                 #
8 #                                                                             #
9 #  Purpose:                                                                   #
10 #                                                                             #
11 #    Smashes multiple text files together into one large text file.           #
12 #                                                                             #
13 ###############################################################################
14 #  This program is free software; you can redistribute it and/or modify it    #
15 #  under the terms of the GNU General Public License as published by the Free #
16 #  Software Foundation; either version 2 of the License or (at your option)   #
17 #  any later version.  See: "http://www.gruntose.com/Info/GNU/GPL.html" for a #
18 #  version of the License.  Please send any updates to "fred@gruntose.com".   #
19 ###############################################################################
20
21 require "filename_helper.pl";
22
23 if ($#ARGV < 0) {
24   &instructions;
25   exit 0;
26 }
27
28 # iterate over the list of files and dump them to standard output.
29
30 foreach $filename (&glob_list(@ARGV)) {
31   &do_dump($filename);
32 }
33
34 exit 0;
35
36 ############################################################################
37
38 sub instructions {
39   print "
40
41 filedump: this program needs a set of filenames to print out.  they will
42           be dumped to the standard output.
43
44 ";
45 }
46
47 ############################################################################
48
49 # do_dump: prints the contents of the first parameter's file out to stdout.
50
51 sub do_dump {
52
53   ($to_dump) = @_;
54
55 #  print "dumpfile=$to_dump\n";
56
57   $header = "
58
59 %2
60 %1
61 %2
62
63 ";
64
65   $header_copy = $header;
66   $shorter_name = $to_dump;
67   $shorter_name =~ s/^\.\///;
68   $shorter_name =~ s/\.txt$//;
69   $shorter_name =~ s/_/ /g;
70
71   $dashed_line = $shorter_name;
72   $dashed_line =~ s/./-/g;
73
74   $header_copy =~ s/%1/$shorter_name/;
75   $header_copy =~ s/%2/$dashed_line/g;
76
77 ##print $header_copy;
78 ##print $to_dump;
79
80   open(TO_DUMP, "<$to_dump");
81
82   print $header_copy;
83
84   local($just_started) = 1;  # check for and remove blank lines at top of file.
85
86   while (<TO_DUMP>) {
87     local($line) = $_;
88 #local($i);
89 #for ($i = 0; $i < length($line); $i++) {
90 #$curr_char = substr($line, $i, 1);
91 #print "[$curr_char]";
92 #}
93 #print "\n";
94     local($curr_char) = 0;
95 #print "start len=" . length($line) . "\n";
96     do {
97 #print "chopping\n";
98       chop $line;  # remove end of line char(s).
99       $curr_char = substr($line, length($line) - 1, 1);
100         # get new last char in string.
101     } while ( ($curr_char eq "\r") || ($curr_char eq "\n") );
102     local($do_print) = 1;
103     if ($just_started) {
104       if (length($line) == 0) {
105         #continue;  # skip the first blank lines.
106         $do_print = 0;  #no continue statement??
107       } else {
108         $just_started = 0;
109           # a non-blank line has been seen.  now we reset our flag so we stop
110           # checking for blank lines.
111       }
112 #print "do print = $do_print\n";
113     }
114     if ($do_print) { print $line . "\n"; }
115   }
116 }
117