streamlet-examples/lines_count
branchv_0
changeset 45 f466b4c7d9b1
parent 44 dc5c210295d0
child 49 ab48ad4ecb91
equal deleted inserted replaced
44:dc5c210295d0 45:f466b4c7d9b1
       
     1 #!/bin/bash
       
     2 
       
     3 # Relational pipes
       
     4 # Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
       
     5 #
       
     6 # This program is free software: you can redistribute it and/or modify
       
     7 # it under the terms of the GNU General Public License as published by
       
     8 # the Free Software Foundation, version 3 of the License.
       
     9 #
       
    10 # This program is distributed in the hope that it will be useful,
       
    11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    13 # GNU General Public License for more details.
       
    14 #
       
    15 # You should have received a copy of the GNU General Public License
       
    16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    17 
       
    18 
       
    19 # This streamlet provides a single attribute: number of lines of given file
       
    20 # Standard wc -l is used to count the lines.
       
    21 # Directories are reported a 0 lines and with a null flag (will be supported in further Relational pipes versions).
       
    22 
       
    23 
       
    24 . "$(dirname $0)/streamlet-common.sh"
       
    25 
       
    26 processMessage_WAITING_FOR_OUTPUT_ATTRIBUTES_METADATA() {
       
    27 	send OUTPUT_ATTRIBUTE_METADATA "${outputAttributeAliases[0]-lines_count}"    "integer"
       
    28 	send WAITING_FOR_INPUT_ATTRIBUTES
       
    29 }
       
    30 
       
    31 processMessage_WAITING_FOR_OUTPUT_ATTRIBUTES() {
       
    32 	if [[ -d "$currentFile" ]]; then
       
    33 		value="0";
       
    34 		isNull="true";
       
    35 	else
       
    36 		value=$(wc -l "$currentFile" | cut -d" " -f1);
       
    37 		isNull="false";
       
    38 	fi
       
    39 	
       
    40 	send OUTPUT_ATTRIBUTE "$value"    "$isNull";
       
    41 	send WAITING_FOR_INPUT_ATTRIBUTES;
       
    42 }
       
    43 
       
    44 initialize
       
    45 processMessages