-
Notifications
You must be signed in to change notification settings - Fork 1
/
gnldiff.sh
executable file
·91 lines (78 loc) · 1.89 KB
/
gnldiff.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# @file gnldiff.sh
# @author cvidon@42
# @date 220816
#
# Make sure to use a BUFFER_SIZE of 1 if your <file> parameter contains special
# characters like those from binary file or /dev/urandom.
#
# @brief Check get_next_line output accuracy.
#
# @param[in] A file to read.
# @return OK if there are no difference otherwise KO + create diff.log
#
# TODO replace 'cat' with 'getline'
#
# # Check the number of arguments
# ###############################
#
# if [ ! "$#" -eq 2 ]
# then
# echo "Usage: bash gnldiff.sh <file_path> [ <buffer_size> ]"
# exit 1
# fi
#
# # Check arguments validity
# ##########################
#
# size=$2
# if [ $size -lt 0 ] || [ $size -ge 2147483647 ]
# then
# echo "Buffer size has to be between zero and one billion"
# exit 1
# fi
## Check if get_next_line exist
###############################
if [ ! -f get_next_line ]
then
make
fi
## Check the number of arguments
################################
if [ ! "$#" -eq 1 ]
then
echo "Usage: bash gnldiff.sh <file_path>"
exit 1
fi
## Check arguments validity
###########################
file=$1
if [ ! -f "$file" ] || [ ! -r "$file" ]
then
echo "File error"
exit 1
fi
## Operate a diff
#################
result=$(diff <(tr -d '\0' < "$file") <(./get_next_line "$file" 2>/dev/null) | wc -l)
# tr -d '\0' <
# -------- _
# | +-- built-in replacement for cat
# +--------- removes NULL BYTE characters
## Feedback
###########
if [ $result -eq 0 ]
then
tput setaf 2
echo "OK"
tput sgr0
else
tput setaf 1
echo "KO"
tput sgr0
echo -n "Press ENTER to generate log..."
read -p ""
diff <(tr -d '\0' < "$file") <(./get_next_line "$file" 2>/dev/null) > diff.log
ls -l diff.log
fi
exit 0