File: roundtrip

package info (click to toggle)
universal-ctags 0%2Bgit20200824-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,092 kB
  • sloc: ansic: 103,112; lisp: 7,241; sh: 6,962; vhdl: 5,924; perl: 2,014; cpp: 1,928; python: 1,828; javascript: 1,529; cs: 1,193; sql: 587; php: 544; f90: 534; makefile: 500; ruby: 498; yacc: 459; asm: 358; fortran: 341; xml: 308; objc: 289; ada: 273; tcl: 205; java: 157; cobol: 122; erlang: 61; ml: 49; awk: 43
file content (143 lines) | stat: -rw-r--r-- 4,512 bytes parent folder | download | duplicates (2)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/sh
#
#   Copyright (C) 2014 Masatake YAMATO
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.

set -e

# Avoid trouble with weird bytes on non-C locales
export LC_ALL=C

READTAGS=${1:-./readtags}
UNITS=${2:-./Units}
s=0

if ! [ -f "${READTAGS}" ]; then
    echo "No such file: ${READTAGS}" 1>&2
    exit 1
fi

if ! [ -x "${READTAGS}" ]; then
    echo "Not an executable: ${READTAGS}" 1>&2
    exit 1
fi

if ! [ -x "${UNITS}" ]; then
    echo "Not such directory: ${UNITS}" 1>&2
    exit 1
fi


# Expand CTags escape sequences (and keep the original, too)
# See docs/format.rst
expandEscapeSequences()
{
    sed -e '
# early out if there is no escape sequence (common case)
/\\/!b

# loop until we handled all occurrences of \.
# as it is not possible to do all replacements at once and we need not to
# ever use the result of an replacement to perform another one, use two
# reserved placeholders.
:again
    s/\\/__BACKSLASH__/
    s/__BACKSLASH__\\/__LITBACKSLASH__/;	t again
    s/__BACKSLASH__t/	/;			t again
    s/__BACKSLASH__r/'"$(printf '\r')"'/;	t again
    s/__BACKSLASH__n/\
/;						t again
    s/__BACKSLASH__a//;			t again
    s/__BACKSLASH__b/'"$(printf '\b')"'/;	t again
    s/__BACKSLASH__v//;			t again
    s/__BACKSLASH__f//;			t again
    s/__BACKSLASH__x01//;			t again
    s/__BACKSLASH__x02//;			t again
    s/__BACKSLASH__x03//;			t again
    s/__BACKSLASH__x04//;			t again
    s/__BACKSLASH__x05//;			t again
    s/__BACKSLASH__x06//;			t again
    s/__BACKSLASH__x07//;			t again
    s/__BACKSLASH__x08//;			t again
    s/__BACKSLASH__x09/	/;			t again
    s/__BACKSLASH__x0[aA]/\
/;						t again
    s/__BACKSLASH__x0[bB]//;			t again
    s/__BACKSLASH__x0[cC]//;			t again
    s/__BACKSLASH__x0[dD]/'"$(printf '\r')"'/;	t again
    s/__BACKSLASH__x0[eE]//;			t again
    s/__BACKSLASH__x0[fF]//;			t again
    s/__BACKSLASH__x10//;			t again
    s/__BACKSLASH__x11//;			t again
    s/__BACKSLASH__x12//;			t again
    s/__BACKSLASH__x13//;			t again
    s/__BACKSLASH__x14//;			t again
    s/__BACKSLASH__x15//;			t again
    s/__BACKSLASH__x16//;			t again
    s/__BACKSLASH__x17//;			t again
    s/__BACKSLASH__x18//;			t again
    s/__BACKSLASH__x19//;			t again
    s/__BACKSLASH__x1[aA]//;			t again
    s/__BACKSLASH__x1[bB]//;			t again
    s/__BACKSLASH__x1[cC]//;			t again
    s/__BACKSLASH__x1[dD]//;			t again
    s/__BACKSLASH__x1[eE]//;			t again
    s/__BACKSLASH__x1[fF]//;			t again
    s/__BACKSLASH__x21/!/;			t again
    s/__BACKSLASH__x20/ /;			t again
    s/__BACKSLASH__x7[fF]//;			t again
    /\\/b again

:out
    # replace lonely "\"es
    s/__BACKSLASH__/\\/g
    # replace literal "\"es ("\\" from the input)
    s/__LITBACKSLASH__/\\/g
'
}

# disable path expansion, because we don't need it and it's applied on the
# result of the commands used to loop on, and we don't want that.
set -f
# remove space from IFS as it's valid in tag names
OLD_IFS="$IFS"
IFS='
'

tagfiles=$(find "$UNITS" -name expected.tags)
for tags in $tagfiles; do
    tagnames=$(sed -e 's/^\([^	]*\)	.*/\1/' "$tags")
    for name in $tagnames; do
	# Yes, there is a reason for this craziness.  We need to properly
	# handle embedded newlines (expanded from "\n"), including trailing
	# ones the shell would strip automatically.  To work around this, we
	# add a dummy character at the end to inhibit stripping, and then
	# remove it, plus the extra newline, using variable substitutions.
	# Note: we use "printf '%s\n'" instead of "echo" because Dash's "echo"
	# unconditionally expands some sequences, like "\t" and alike.
	t="$(printf '%s\n' "$name" | expandEscapeSequences; printf _)"
	t="${t%
_}"
	if [ 1 -gt $("${READTAGS}" -t "$tags" - "$t" | wc -l) ]; then
	    printf 'FAILED: "%s" -t "%s" - "%s"\n' "${READTAGS}" "$tags" "$t"
	    printf '	The raw tag name was "%s"\n' "$name"
	    s=1
	fi
    done
done

IFS="$OLD_IFS"

exit $s