Browse Source

Fix general whitespace issues

 *  alignment to 4 spaces,
 *  drop trailing whitespace,
 *  drop unnecessary alignment.
Alois Mahdal 3 years ago
parent
commit
9a37b004c4
1 changed files with 133 additions and 130 deletions
  1. 133
    130
      99bottles.sh

+ 133
- 130
99bottles.sh View File

@@ -5,157 +5,160 @@
5 5
 
6 6
 standardBreakLine="Take one down and pass it around"
7 7
 wastefulBreakLine="If one of those bottles should happen to fall"
8
-breakLine=$([ "$1" = --careless ] && echo $wastefulBreakLine ||
9
-                                     echo $standardBreakLine)
8
+breakLine=$([ "$1" = --careless ] \
9
+ && echo $wastefulBreakLine \
10
+ || echo $standardBreakLine)
10 11
 
11 12
 pred() {  #get predecessor to a number
12
-  case $1 in
13
-    *nine)  echo ${1%nine}eight;;
14
-    *eight) echo ${1%eight}seven;;
15
-    *seven) echo ${1%seven}six;;
16
-    *six)   echo ${1%six}five;;
17
-    *five)  echo ${1%five}four;;
18
-    *four)  echo ${1%four}three;;
19
-    *three) echo ${1%three}two;;
20
-    *two)   echo ${1%two}one;;
21
-    one)    echo zero;;
22
-    *-one)  echo ${1%-one};;
23
-    *one)   echo ${1%one};;
24
-    ten)    echo nine;;
25
-    eleven) echo ten;;
26
-    twelve) echo eleven;;
27
-    *teen)  teenpred $1;;
28
-    *ty)    tenspred $1;;
29
-    zero)   echo "";  #to terminate
30
-  esac
31
-  }
32
-  
13
+    case $1 in
14
+        *nine)      echo ${1%nine}eight;;
15
+        *eight)     echo ${1%eight}seven;;
16
+        *seven)     echo ${1%seven}six;;
17
+        *six)       echo ${1%six}five;;
18
+        *five)      echo ${1%five}four;;
19
+        *four)      echo ${1%four}three;;
20
+        *three)     echo ${1%three}two;;
21
+        *two)       echo ${1%two}one;;
22
+        one)        echo zero;;
23
+        *-one)      echo ${1%-one};;
24
+        *one)       echo ${1%one};;
25
+        ten)        echo nine;;
26
+        eleven)     echo ten;;
27
+        twelve)     echo eleven;;
28
+        *teen)      teenpred $1;;
29
+        *ty)        tenspred $1;;
30
+        zero)       echo "";  #to terminate
31
+    esac
32
+}
33
+
33 34
 teenpred() { #predecessor of a teen
34
-  case $1 in
35
-     thirteen)   echo twelve;;
36
-     *)     echo $(crunchprefix $(pred $(uncrunchprefix ${1%teen})))teen;;
37
-     esac  
38
-  }
39
-  
35
+    case $1 in
36
+        thirteen)   echo twelve;;
37
+        *)          echo $(crunchprefix $(pred $(uncrunchprefix ${1%teen})))teen;;
38
+    esac
39
+}
40
+
40 41
 tenspred() { #predecessor of a multiple of ten
41
-  case $1 in
42
-     twenty)     echo nineteen;;
43
-     *) echo $(crunchprefix --tens $(pred $(uncrunchprefix ${1%ty})))ty-nine;;
44
-     esac  
45
-  }
46
-  
42
+    case $1 in
43
+        twenty)     echo nineteen;;
44
+        *) echo $(crunchprefix --tens $(pred $(uncrunchprefix ${1%ty})))ty-nine;;
45
+    esac
46
+}
47
+
47 48
 crunchprefix() {
48
-  #crunch number prefix to its conventional form
49
-  # such as three --> thir
50
-  # option --tens     multiples of ten are a bit different
51
-  [ $1 = --tens ] && { tensop=true; shift; }
52
-  case $1 in 
53
-    two)   [ -n "$tensop" ] && echo twen || echo $1;;
54
-    three) echo thir;;
55
-    four)  [ -n "$tensop" ] && echo 'for' || echo $1;;
56
-    five)  echo fif;;
57
-    eight) [ -n "$tensop" ] && echo eigh || echo $1;;
58
-    *)     echo $1;;
59
-  esac
60
-  }
49
+    #crunch number prefix to its conventional form
50
+    # such as three --> thir
51
+    # option --tens     multiples of ten are a bit different
52
+    [ $1 = --tens ] && { tensop=true; shift; }
53
+    case $1 in
54
+        two)    [ -n "$tensop" ] && echo twen || echo $1;;
55
+        three)  echo thir;;
56
+        four)   [ -n "$tensop" ] && echo 'for' || echo $1;;
57
+        five)   echo fif;;
58
+        eight)  [ -n "$tensop" ] && echo eigh || echo $1;;
59
+        *)      echo $1;;
60
+    esac
61
+}
61 62
 
62 63
 uncrunchprefix() { #reverse crunchprefix
63
-  case $1 in
64
-    twen)  echo two;;
65
-    thir)  echo three;;
66
-    'for') echo four;;
67
-    fif)   echo five;;
68
-    eigh)  echo eight;;
69
-    *)     echo $1;;
70
-  esac
71
-  }
72
-    
64
+    case $1 in
65
+        twen)   echo two;;
66
+        thir)   echo three;;
67
+        'for')  echo four;;
68
+        fif)    echo five;;
69
+        eigh)   echo eight;;
70
+        *)      echo $1;;
71
+    esac
72
+}
73
+
73 74
 grammar() { #peculiarities of English grammar
74
-  local oneBottle=false  #can effect the following line
75
-  while read line; do
76
-    line="${line/one more bottles/one more bottle}"
77
-    case "$line" in
78
-       *"one of those bottles"*) line="$([ $oneBottle = true ] && 
79
-                         echo ${line/one of those bottles/that lone bottle} ||
80
-                         echo $line )"
81
-                         ;;
82
-       *"one down"*) line="$([ $oneBottle = true ] && 
83
-                         echo ${line/one down/it down} ||
84
-                         echo $line )"
85
-                         ;;
86
-       *bottles*)   oneBottle=false;;
87
-       *bottle*)    oneBottle=true;;
88
-       esac
89
-      #Some say the twenties should have no hyphen
90
-    line="${line/twenty-/twenty }"
91
-    echo $line
75
+    local oneBottle=false  #can effect the following line
76
+    while read line; do
77
+        line="${line/one more bottles/one more bottle}"
78
+        case "$line" in
79
+            *"one of those bottles"*)   line="$([ $oneBottle = true ] &&
80
+                                        echo ${line/one of those bottles/that lone bottle} ||
81
+                                        echo $line )"
82
+                                        ;;
83
+            *"one down"*)               line="$([ $oneBottle = true ] &&
84
+                                        echo ${line/one down/it down} ||
85
+                                        echo $line )"
86
+                                        ;;
87
+            *bottles*)                  oneBottle=false;;
88
+            *bottle*)                   oneBottle=true;;
89
+        esac
90
+        #Some say the twenties should have no hyphen
91
+        line="${line/twenty-/twenty }"
92
+        echo $line
92 93
     done
93
-  }
94
-  
94
+}
95
+
95 96
 capitalize() {  #fix beginning of each line
96
-  while read line; do
97
-    echo -n ${line:0:1} | tr '[:lower:]' '[:upper:]'
98
-    echo ${line#?}
97
+    while read line; do
98
+        echo -n ${line:0:1} | tr '[:lower:]' '[:upper:]'
99
+        echo ${line#?}
99 100
     done
100
-  }
101
+}
102
+
101 103
 punctuate() {  #add punct to each line
102
-  while read line; do 
103
-    case "${line}" in
104
-      [Ii]f*)   echo ${line},;;
105
-      '')       echo;;
106
-      *)        echo ${line}.;;
107
-      esac
104
+    while read line; do
105
+        case "${line}" in
106
+            [Ii]f*)     echo ${line},;;
107
+            '')         echo;;
108
+            *)          echo ${line}.;;
109
+        esac
108 110
     done
109
-  }
111
+}
110 112
 
111 113
 verse () { #write one verse
112
-  local nb=$1
113
-  echo $nb bottles of beer on the wall
114
-  echo $nb bottles of beer
115
-  if [ $nb = zero ]; then
116
-    echo Go to the store and buy some more
117
-    nb=ninety-nine
118
-  else
119
-    echo $breakLine
120
-    nb=$(pred $nb)
121
-  fi
122
-  echo $nb bottles of beer on the wall
123
-  }
124
-  
114
+    local nb=$1
115
+    echo $nb bottles of beer on the wall
116
+    echo $nb bottles of beer
117
+    if [ $nb = zero ]; then
118
+        echo Go to the store and buy some more
119
+        nb=ninety-nine
120
+    else
121
+        echo $breakLine
122
+        nb=$(pred $nb)
123
+    fi
124
+    echo $nb bottles of beer on the wall
125
+}
126
+
125 127
 poeticize() { #make it nice
126
-  while read first rest; do
127
-    case "$rest" in
128
-      *beer*)
129
-        first=${first/zero/no}
130
-        local syl=$(syllables ${first% *})
131
-        case $syl in  #improve meter
132
-          1|2)   echo $first 'more' $rest;;
133
-          *)     echo $first $rest;;
134
-          esac;;
135
-      *)         echo $first $rest
136
-      esac
128
+    while read first rest; do
129
+        case "$rest" in
130
+            *beer*)
131
+                first=${first/zero/no}
132
+                local syl=$(syllables ${first% *})
133
+                case $syl in  #improve meter
134
+                    1|2)    echo $first 'more' $rest;;
135
+                    *)      echo $first $rest;;
136
+                esac
137
+                ;;
138
+            *)  echo $first $rest
139
+        esac
137 140
     done
138
-  }
139
-  
141
+}
142
+
140 143
 syllables() { #estimate number of syls in word
141
-  local n=1
142
-  case $1 in
143
-    eleven)       n=2;; #sounds better if not considered 3
144
-    *teen)        n=2;;
145
-    *ty)          n=2;;
146
-    *-*)          n=3;; #don't care about more than 3
144
+    local n=1
145
+    case $1 in
146
+        eleven)     n=2;; #sounds better if not considered 3
147
+        *teen)      n=2;;
148
+        *ty)        n=2;;
149
+        *-*)        n=3;; #don't care about more than 3
147 150
     esac
148
-  case $1 in
149
-    *seven*)      let $((n = n+1));;
151
+    case $1 in
152
+        *seven*)    let $((n = n+1));;
150 153
     esac
151
-  echo $n
152
-  }
153
-    
154
+    echo $n
155
+}
156
+
154 157
 
155 158
 nb=ninety-nine
156 159
 
157 160
 while [ -n "$nb" ]; do
158
-  verse $nb
159
-  echo
160
-  nb=$(pred $nb)
161
-  done | poeticize | grammar | punctuate | capitalize
161
+    verse $nb
162
+    echo
163
+    nb=$(pred $nb)
164
+done | poeticize | grammar | punctuate | capitalize