xref: /Universal-ctags/Tmain/tag-relative-option.d/run.sh (revision b9ac95a841953b996129c3e555768e2b397270ad)
1# Copyright: 2016 Masatake YAMATO
2# License: GPL-2
3
4CTAGS=$1
5O="--quiet --options=NONE -o - -x "
6P=$(pwd)
7
8. ../utils.sh
9
10if ! ${CTAGS} $O --help | grep -e --tag-relative | grep --quiet -e always; then
11	echo "--tag-relative=always|never is not available on this platform"
12	exit ${__SKIP__}
13fi
14
15{
16    F=./input.c
17    ${CTAGS} $O --_xformat="default: $F -> %F"                        $F
18    ${CTAGS} $O --_xformat="never:   $F -> %F"  --tag-relative=never  $F
19    ${CTAGS} $O --_xformat="no:      $F -> %F"  --tag-relative=no     $F
20    ${CTAGS} $O --_xformat="yes:     $F -> %F"  --tag-relative=yes    $F
21    ${CTAGS} $O --_xformat="always:  $F -> %F"  --tag-relative=always $F
22
23    F=input.c
24    ${CTAGS} $O --_xformat="default: $F -> %F"                        $F
25    ${CTAGS} $O --_xformat="never:   $F -> %F"  --tag-relative=never  $F
26    ${CTAGS} $O --_xformat="no:      $F -> %F"  --tag-relative=no     $F
27    ${CTAGS} $O --_xformat="yes:     $F -> %F"  --tag-relative=yes    $F
28    ${CTAGS} $O --_xformat="always:  $F -> %F"  --tag-relative=always $F
29
30    F=${P}/input.c
31    ${CTAGS} $O --_xformat="default: $F -> %F"                        $F
32    ${CTAGS} $O --_xformat="never:   $F -> %F"  --tag-relative=never  $F
33    ${CTAGS} $O --_xformat="no:      $F -> %F"  --tag-relative=no     $F
34    ${CTAGS} $O --_xformat="yes:     $F -> %F"  --tag-relative=yes    $F
35    ${CTAGS} $O --_xformat="always:  $F -> %F"  --tag-relative=always $F
36} | {
37    # Normalize Windows driver letter
38    #
39    # comment time:   Sat Feb  6 13:11:44 UTC 2021
40    # comment author: leleliu008@gmail.com
41    #
42    # as far as I know, the most widely used unix-like POSIX-compatible environments on Windows are Cygwin and MSYS2. Actually, MSYS2 is a modified fork of Cygwin. They both provide a command-line tool called cygpath which can be used to convert Windows PATH to UNIX path. There exists other unix-like POSIX-compatible environments on Windows, git-for-windows as an example, but they all based on Cygwin or MSYS2.
43    if command -v cygpath > /dev/null && command -v awk > /dev/null ; then
44        awk '{if ($NF ~ /^[A-Z]:/) { "cygpath "$NF | getline newpath; sub($NF,newpath) } print}'
45    else
46        # \l is a GNU extension. But only Windows's path match [A-Z]: pattern, Cygwin and MSYS2 use GNU sed.
47        sed 's|\([A-Z]\):|/\l\1|'
48    fi
49} | {
50	# Unescape
51	sed -e 's|\\\\|\\|g'
52} | {
53	# Convert to /
54    sed -e 's|\\|/|g'
55} | {
56	# Convert pwd test environment neutral
57    sed -e "s|${P}|/abs|g"
58}
59