Просмотр исходного кода

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 лет назад
Родитель
Сommit
436009dc71
1 измененных файлов: 11 добавлений и 14 удалений
  1. 11
    14
      bin/notifirc

+ 11
- 14
bin/notifirc Просмотреть файл

@@ -76,23 +76,20 @@ load_defaults() {
76 76
     }
77 77
 }
78 78
 
79
-read_file() {
80
-    local fpath=$1
79
+trim() {
81 80
     local limit_l=3
82 81
     local limit_c=80
83 82
     local lines_read=0
84 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 95
 choose_logfile() {
@@ -155,7 +152,7 @@ main() {
155 152
     log "message='$message'"
156 153
     {
157 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 157
       | mkcommands "$user" "$(mknick)" \
161 158
       | nc "$host" "$port" 2>&1 \