Browse Source

Apply function docstring style

Alois Mahdal 3 years ago
parent
commit
70e119aa08
1 changed files with 47 additions and 13 deletions
  1. 47
    13
      99bottles.sh

+ 47
- 13
99bottles.sh View File

22
  && echo $wastefulBreakLine \
22
  && echo $wastefulBreakLine \
23
  || echo $standardBreakLine)
23
  || echo $standardBreakLine)
24
 
24
 
25
-pred() {  #get predecessor to a number
25
+pred() {
26
+    #
27
+    # Get predecessor to a number $1
28
+    #
26
     case $1 in
29
     case $1 in
27
         *nine)      echo ${1%nine}eight;;
30
         *nine)      echo ${1%nine}eight;;
28
         *eight)     echo ${1%eight}seven;;
31
         *eight)     echo ${1%eight}seven;;
44
     esac
47
     esac
45
 }
48
 }
46
 
49
 
47
-teenpred() { #predecessor of a teen
50
+teenpred() {
51
+    #
52
+    # Get predecessor of a teen $1
53
+    #
48
     case $1 in
54
     case $1 in
49
         thirteen)   echo twelve;;
55
         thirteen)   echo twelve;;
50
         *)          echo $(crunchprefix $(pred $(uncrunchprefix ${1%teen})))teen;;
56
         *)          echo $(crunchprefix $(pred $(uncrunchprefix ${1%teen})))teen;;
51
     esac
57
     esac
52
 }
58
 }
53
 
59
 
54
-tenspred() { #predecessor of a multiple of ten
60
+tenspred() {
61
+    #
62
+    # Get predecessor of a multiple of ten $1
63
+    #
55
     case $1 in
64
     case $1 in
56
         twenty)     echo nineteen;;
65
         twenty)     echo nineteen;;
57
         *) echo $(crunchprefix --tens $(pred $(uncrunchprefix ${1%ty})))ty-nine;;
66
         *) echo $(crunchprefix --tens $(pred $(uncrunchprefix ${1%ty})))ty-nine;;
59
 }
68
 }
60
 
69
 
61
 crunchprefix() {
70
 crunchprefix() {
62
-    #crunch number prefix to its conventional form
63
-    # such as three --> thir
64
-    # option --tens     multiples of ten are a bit different
71
+    #
72
+    # Crunch number prefix $1 to its conventional form
73
+    #
74
+    # ...such as `three` --> `thir`
75
+    #
76
+    # option `--tens` - multiples of ten are a bit different
77
+    #
65
     [ $1 = --tens ] && { tensop=true; shift; }
78
     [ $1 = --tens ] && { tensop=true; shift; }
66
     case $1 in
79
     case $1 in
67
         two)    [ -n "$tensop" ] && echo twen || echo $1;;
80
         two)    [ -n "$tensop" ] && echo twen || echo $1;;
73
     esac
86
     esac
74
 }
87
 }
75
 
88
 
76
-uncrunchprefix() { #reverse crunchprefix
89
+uncrunchprefix() {
90
+    #
91
+    # Reverse crunchprefix $1
92
+    #
77
     case $1 in
93
     case $1 in
78
         twen)   echo two;;
94
         twen)   echo two;;
79
         thir)   echo three;;
95
         thir)   echo three;;
84
     esac
100
     esac
85
 }
101
 }
86
 
102
 
87
-grammar() { #peculiarities of English grammar
103
+grammar() {
104
+    #
105
+    # Apply peculiarities of English grammar to text on stdin
106
+    #
88
     local oneBottle=false  #can effect the following line
107
     local oneBottle=false  #can effect the following line
89
     while read line; do
108
     while read line; do
90
         line="${line/one more bottles/one more bottle}"
109
         line="${line/one more bottles/one more bottle}"
106
     done
125
     done
107
 }
126
 }
108
 
127
 
109
-capitalize() {  #fix beginning of each line
128
+capitalize() {
129
+    #
130
+    # Fix capitalization of each line on stdin
131
+    #
110
     while read line; do
132
     while read line; do
111
         echo -n ${line:0:1} | tr '[:lower:]' '[:upper:]'
133
         echo -n ${line:0:1} | tr '[:lower:]' '[:upper:]'
112
         echo ${line#?}
134
         echo ${line#?}
113
     done
135
     done
114
 }
136
 }
115
 
137
 
116
-punctuate() {  #add punct to each line
138
+punctuate() {
139
+    #
140
+    # Add punctuation to each line on stdin
141
+    #
117
     while read line; do
142
     while read line; do
118
         case "${line}" in
143
         case "${line}" in
119
             [Ii]f*)     echo ${line},;;
144
             [Ii]f*)     echo ${line},;;
123
     done
148
     done
124
 }
149
 }
125
 
150
 
126
-verse () { #write one verse
151
+verse () {
152
+    #
153
+    # Write one verse with number $1
154
+    #
127
     local nb=$1
155
     local nb=$1
128
     echo $nb bottles of beer on the wall
156
     echo $nb bottles of beer on the wall
129
     echo $nb bottles of beer
157
     echo $nb bottles of beer
137
     echo $nb bottles of beer on the wall
165
     echo $nb bottles of beer on the wall
138
 }
166
 }
139
 
167
 
140
-poeticize() { #make it nice
168
+poeticize() {
169
+    #
170
+    # Make text on stdin nice
171
+    #
141
     while read first rest; do
172
     while read first rest; do
142
         case "$rest" in
173
         case "$rest" in
143
             *beer*)
174
             *beer*)
153
     done
184
     done
154
 }
185
 }
155
 
186
 
156
-syllables() { #estimate number of syls in word
187
+syllables() {
188
+    #
189
+    # Estimate number of syllables in word $1
190
+    #
157
     local n=1
191
     local n=1
158
     case $1 in
192
     case $1 in
159
         eleven)     n=2;; #sounds better if not considered 3
193
         eleven)     n=2;; #sounds better if not considered 3