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,7 +22,10 @@ breakLine=$([ "$1" = --careless ] \
22 22
  && echo $wastefulBreakLine \
23 23
  || echo $standardBreakLine)
24 24
 
25
-pred() {  #get predecessor to a number
25
+pred() {
26
+    #
27
+    # Get predecessor to a number $1
28
+    #
26 29
     case $1 in
27 30
         *nine)      echo ${1%nine}eight;;
28 31
         *eight)     echo ${1%eight}seven;;
@@ -44,14 +47,20 @@ pred() {  #get predecessor to a number
44 47
     esac
45 48
 }
46 49
 
47
-teenpred() { #predecessor of a teen
50
+teenpred() {
51
+    #
52
+    # Get predecessor of a teen $1
53
+    #
48 54
     case $1 in
49 55
         thirteen)   echo twelve;;
50 56
         *)          echo $(crunchprefix $(pred $(uncrunchprefix ${1%teen})))teen;;
51 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 64
     case $1 in
56 65
         twenty)     echo nineteen;;
57 66
         *) echo $(crunchprefix --tens $(pred $(uncrunchprefix ${1%ty})))ty-nine;;
@@ -59,9 +68,13 @@ tenspred() { #predecessor of a multiple of ten
59 68
 }
60 69
 
61 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 78
     [ $1 = --tens ] && { tensop=true; shift; }
66 79
     case $1 in
67 80
         two)    [ -n "$tensop" ] && echo twen || echo $1;;
@@ -73,7 +86,10 @@ crunchprefix() {
73 86
     esac
74 87
 }
75 88
 
76
-uncrunchprefix() { #reverse crunchprefix
89
+uncrunchprefix() {
90
+    #
91
+    # Reverse crunchprefix $1
92
+    #
77 93
     case $1 in
78 94
         twen)   echo two;;
79 95
         thir)   echo three;;
@@ -84,7 +100,10 @@ uncrunchprefix() { #reverse crunchprefix
84 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 107
     local oneBottle=false  #can effect the following line
89 108
     while read line; do
90 109
         line="${line/one more bottles/one more bottle}"
@@ -106,14 +125,20 @@ grammar() { #peculiarities of English grammar
106 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 132
     while read line; do
111 133
         echo -n ${line:0:1} | tr '[:lower:]' '[:upper:]'
112 134
         echo ${line#?}
113 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 142
     while read line; do
118 143
         case "${line}" in
119 144
             [Ii]f*)     echo ${line},;;
@@ -123,7 +148,10 @@ punctuate() {  #add punct to each line
123 148
     done
124 149
 }
125 150
 
126
-verse () { #write one verse
151
+verse () {
152
+    #
153
+    # Write one verse with number $1
154
+    #
127 155
     local nb=$1
128 156
     echo $nb bottles of beer on the wall
129 157
     echo $nb bottles of beer
@@ -137,7 +165,10 @@ verse () { #write one verse
137 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 172
     while read first rest; do
142 173
         case "$rest" in
143 174
             *beer*)
@@ -153,7 +184,10 @@ poeticize() { #make it nice
153 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 191
     local n=1
158 192
     case $1 in
159 193
         eleven)     n=2;; #sounds better if not considered 3