xref: /Universal-ctags/Tmain/epoch-field.d/run.sh (revision ce1f2415d4945f4d9210cc129ddaff4c590cac41)
1# Copyright: 2020 Masatake YAMATO
2# License: GPL-2
3
4CTAGS=$1
5
6O0=/tmp/ctags-tstamp-$$.c
7O1=/tmp/ctags-tstamp-$$.h
8O2=/tmp/ctags-tstamp-$$.m
9
10cat > $O0 <<EOF
11int main (void)
12{
13	return 0;
14}
15EOF
16
17cat > $O1 <<EOF
18extern void foo (void);
19EOF
20
21cat > $O2 <<EOF
22#import <class.h>
23EOF
24
25is_json_avaiable()
26{
27	$1 --quiet --options=NONE --with-list-header=no --list-features | grep -q "json"
28}
29
30run()
31{
32	local o=$1
33	local t=$2
34	shift 2
35	local s
36
37	echo $t
38	TZ=UTC+00:00 touch -t '200402291621.42' $o &&
39		$CTAGS "$@" --kinds-C= --extras=f --fields=T -o - $o \
40			| sed -e 's/.*\(epoch:.*\)/tags:\1/' &&
41		$CTAGS "$@" --kinds-C= --extras=f --fields=T -o - -x --_xformat="xref:epoch:%T" $o &&
42		{
43			if is_json_avaiable $CTAGS; then
44				$CTAGS "$@" --kinds-C= --extras=f --fields=T -o - --output-format=json $o \
45					| sed -e 's/.*"epoch": \([0-9]*\).*/json:epoch:\1/'
46			else
47				echo "json:epoch:1078071702"
48			fi
49		}
50	s=$?
51	rm $o
52	return $s
53}
54
55run $O0 ".c file" && run $O1 ".h file" && run $O2 ".m file" -G
56exit $?
57