Two-years-after revision. New `vertical' version.
[p_s.git] / v.pl
blob412efeb803813eb2538d7057ad12e4e4daaaff5a
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
5 # code as grid. only the grid saves!
6 # there may already be a little groff markup in this file
7 my $textFile = "sections_7,_9" unless $ARGV[0];
8 $textFile = $ARGV[0] unless not $ARGV[0];
10 # this returns the text as an array of arrays, alllinesAllleters ;)
11 my @textAoA = &parseText($textFile);
12 &verticalMotionMarkUp(\@textAoA, 10);
14 # takes as an argument the file to be parsed, so &parseText("file")
15 sub parseText {
16 my @alllinesAllletters;
17 my @currentLineLetters;
18 open(TEXT, "<", $_[0]) || die "can't open $_[0] : $!";
20 while (<TEXT>) {
21 chomp;
22 @currentLineLetters = split //, $_;
23 push @alllinesAllletters, [@currentLineLetters];
25 @alllinesAllletters;
28 sub verticalMotionMarkUp {
29 my @textLetters = @{$_[0]};
30 my $localMotionRange = $_[1];
31 my $aLetter;
32 my $aLineRef;
33 my $anAmount;
34 my $markedUpLetter;
36 # this is the file that we will build
37 my $newFile = $textFile . "Typeset";
38 open(TYPESET, ">", $newFile) || die "can't open $newFile : $!";
40 # for evry letter...
41 foreach $aLineRef (@textLetters) {
42 if (@$aLineRef == 0) {}
43 # the script recognizes lines that begin with a `.' or a `\'
44 elsif (@$aLineRef[0] eq "." || @$aLineRef[0] eq "\\") {
45 foreach $aLetter (@{$aLineRef}) {
46 print TYPESET $aLetter;
48 } else {
49 foreach $aLetter (@{$aLineRef}) {
50 $anAmount = int(rand($localMotionRange));
51 $markedUpLetter = "\\v'" . $anAmount . "M'$aLetter\\v'-" . $anAmount . "M'";
52 print TYPESET $markedUpLetter;
55 print TYPESET "\n";