소스 검색

Add function docstrings

Alois Mahdal 7 년 전
부모
커밋
32ffb47657
1개의 변경된 파일30개의 추가작업 그리고 0개의 파일을 삭제
  1. 30
    0
      bin/notifirc

+ 30
- 0
bin/notifirc 파일 보기

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