Browse Source

Add function docstrings

Alois Mahdal 6 years ago
parent
commit
32ffb47657
1 changed files with 30 additions and 0 deletions
  1. 30
    0
      bin/notifirc

+ 30
- 0
bin/notifirc View File

2
 
2
 
3
 
3
 
4
 usage() {
4
 usage() {
5
+    #
6
+    # Print usage message and exit with status 2
7
+    #
5
     local self      # our name
8
     local self      # our name
6
     self=$(basename "$0")
9
     self=$(basename "$0")
7
     echo "usage: $self [options] message" >&2
10
     echo "usage: $self [options] message" >&2
11
 }
14
 }
12
 
15
 
13
 mkcommands() {
16
 mkcommands() {
17
+    #
18
+    # Print all IRC commands
19
+    #
14
     local user="$1"     # target user
20
     local user="$1"     # target user
15
     local nick="$2"     # our nickname
21
     local nick="$2"     # our nickname
16
     local message
22
     local message
24
 }
30
 }
25
 
31
 
26
 mknick() {
32
 mknick() {
33
+    #
34
+    # Compose bot's nickname
35
+    #
27
     case "$context" in
36
     case "$context" in
28
         "") echo "$nick" ;;
37
         "") echo "$nick" ;;
29
         *)  echo "$nick|$context" ;;
38
         *)  echo "$nick|$context" ;;
31
 }
40
 }
32
 
41
 
33
 die() {
42
 die() {
43
+    #
44
+    # End script with fatal error $1
45
+    #
34
     local msg="fatal: $1"       # message
46
     local msg="fatal: $1"       # message
35
     log "$msg"
47
     log "$msg"
36
     log "-----END *-----"
48
     log "-----END *-----"
39
 }
51
 }
40
 
52
 
41
 warn() {
53
 warn() {
54
+    #
55
+    # Issue message $1 as warning to logfile and stderr
56
+    #
42
     local msg="warning: $1"     # full message
57
     local msg="warning: $1"     # full message
43
     echo "$msg" >&2
58
     echo "$msg" >&2
44
     log "$msg"
59
     log "$msg"
45
 }
60
 }
46
 
61
 
47
 log_pipe() {
62
 log_pipe() {
63
+    #
64
+    # Log contents of standard input
65
+    #
48
     local line      # each line of input
66
     local line      # each line of input
49
     while IFS= read -r line;
67
     while IFS= read -r line;
50
     do
68
     do
53
 }
71
 }
54
 
72
 
55
 log() {
73
 log() {
74
+    #
75
+    # Log message $1 to $logfile
76
+    #
56
     echo "$1" >>"$logfile"
77
     echo "$1" >>"$logfile"
57
 }
78
 }
58
 
79
 
59
 load_defaults() {
80
 load_defaults() {
81
+    #
82
+    # Load defaults from RC file $1
83
+    #
60
     local rcfile=$1     # RC file to load
84
     local rcfile=$1     # RC file to load
61
     test -e "$rcfile" || return 0
85
     test -e "$rcfile" || return 0
62
     test -f "$rcfile" || {
86
     test -f "$rcfile" || {
78
 }
102
 }
79
 
103
 
80
 trim() {
104
 trim() {
105
+    #
106
+    # Trim to maximum $1 lines and $2 characters per line
107
+    #
81
     local limit_l=$1        # max. lines per message
108
     local limit_l=$1        # max. lines per message
82
     local limit_c=$2        # max. chars per line
109
     local limit_c=$2        # max. chars per line
83
     local lines_read=0      # how many lines we read
110
     local lines_read=0      # how many lines we read
94
 }
121
 }
95
 
122
 
96
 choose_logfile() {
123
 choose_logfile() {
124
+    #
125
+    # Decide which log file to use (/var, /home or /tmp)
126
+    #
97
     local path      # path to log file
127
     local path      # path to log file
98
     {
128
     {
99
         echo /var/log/notifirc.log
129
         echo /var/log/notifirc.log