summaryrefslogtreecommitdiffstats
path: root/scanners/which-asm.sh
blob: b4ff973cc8fe4f2ec0fa161f2592dd737fd1f2b9 (plain)
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
#!/bin/bash
#
#   Copyright (c) 2012, Al Stone <ahs3@ahs3.net>
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of version 2 (only) of the GNU General
#   Public License as published by the Free Software Foundation.
#

scanner="Which-Asm"

workdir="$1"
src="$2"

WHICHASM=whichasm

declare -i count
count=0
if [ -d "$src" ]
then
        find "$src" \( -name '*\.[cCsShH]' \
             -o -name '*\.cc' \
             -o -name '*\.cxx' \
             -o -name '*\.cpp' \
             \) -print > /tmp/$$
        if [ -s /tmp/$$ ]
        then
                count=$(cat /tmp/$$ | (
                        count=0
                        read line
                        while [ ! -z $line ]
                        do
                                res=$(${WHICHASM} $line)
                                if [ "$(echo $res | grep ^error:)" ] || \
                                   [ "$(echo $res | grep '.*: unknown')" ]
                                then
                                        true
                                else
                                        count+=1
                                fi
                                read line
                        done
                        echo $count
                ))
        fi
        rm -f /tmp/$$
else
        count="-1"
fi
echo "${scanner}: $count"