Browse Source

Move file reading outside limit function

Makes it easier to see explicitly how date is obtained.

As a bous, it will be also easier to parametrize limits.
Alois Mahdal 9 years ago
parent
commit
436009dc71
1 changed files with 11 additions and 14 deletions
  1. 11
    14
      bin/notifirc

+ 11
- 14
bin/notifirc View File

76
     }
76
     }
77
 }
77
 }
78
 
78
 
79
-read_file() {
80
-    local fpath=$1
79
+trim() {
81
     local limit_l=3
80
     local limit_l=3
82
     local limit_c=80
81
     local limit_c=80
83
     local lines_read=0
82
     local lines_read=0
84
     local suff=""
83
     local suff=""
85
-    grep . "$fpath" \
86
-      | while true;
87
-        do
88
-            test $lines_read -ge $limit_l && break
89
-            IFS= read line || break
90
-            (( lines_read++ ))
91
-            test ${#line} -gt $limit_c && suff=…
92
-            line=${line:0:$limit_c}$suff
93
-            log "read from $fpath: $line"
94
-            echo "$line"
95
-        done
84
+    while true;
85
+    do
86
+        test $lines_read -ge $limit_l && break
87
+        IFS= read line || break
88
+        (( lines_read++ ))
89
+        test ${#line} -gt $limit_c && suff=…
90
+        line=${line:0:$limit_c}$suff
91
+        echo "$line"
92
+    done
96
 }
93
 }
97
 
94
 
98
 choose_logfile() {
95
 choose_logfile() {
155
     log "message='$message'"
152
     log "message='$message'"
156
     {
153
     {
157
         test -n "$message" && printf '%s\n' "$message"
154
         test -n "$message" && printf '%s\n' "$message"
158
-        test -n "$msgfile" && read_file "$msgfile"
155
+        test -n "$msgfile" && grep . "$msgfile" | trim
159
     } \
156
     } \
160
       | mkcommands "$user" "$(mknick)" \
157
       | mkcommands "$user" "$(mknick)" \
161
       | nc "$host" "$port" 2>&1 \
158
       | nc "$host" "$port" 2>&1 \