File: promote

package info (click to toggle)
pcp 6.3.8-1
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 235,180 kB
  • sloc: ansic: 1,253,622; sh: 173,998; xml: 160,490; cpp: 83,331; python: 20,482; perl: 18,302; yacc: 6,886; makefile: 2,955; lex: 2,862; fortran: 60; java: 52
file content (379 lines) | stat: -rwxr-xr-x 8,256 bytes parent folder | download | duplicates (4)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#!/bin/sh
#
# Promote __pmFoo to pmFoo
# Demote pmFoo to __pmFoo
# ... or in general rename foo to blah
#

_usage()
{
    echo >&2 "Usage: promote [options]  __pmFoo [[pmFoo] file ...]"
    echo >&2 "       demote [options]  pmFoo [[__pmFoo] file ...]"
    echo >&2 "options:"
    echo >&2 " -d	struct name, or typedef, or #define"
    echo >&2 "		(not function name which is the default)"
    echo >&2 " -n	show me, change nothing"
    echo >&2 " -s	suggest what should be done"
    echo >&2
    echo >&2 "Default files are from recursive descent below src man qa books debian"
    exit 1
}

promote=true
case "$0"
in
    */demote)
	promote=false
	;;
esac

function=true
showme=false
suggest=false
while getopts "dns?" c
do
    case $c
    in
	d)	# not a function
		function=false
		;;
	n)	# show me
		showme=true
		;;
	s)	# suggest
		suggest=true
		;;
	?)
		_usage
		# NOTREACHED
		;;
    esac
done
shift `expr $OPTIND - 1`

if [ -z "$1" ]
then
    _usage
    # NOTREACHED
fi
from="$1"
from_pat="(^|[^a-zA-Z0-9_])$from(\$|[^a-zA-Z0-9_])"
shift
if [ $# -ge 1 ]
then
    to="$1"
    shift
else
    if $promote
    then
	to=`echo "$from" | sed -n -e 's/^__pm/pm/p'`
	if [ -z "$to" ]
	then
	    echo >&2 "Error: from=$from does not start with \"__pm\""
	    exit 1
	fi
    else
	to=`echo "$from" | sed -n -e 's/^pm/__pm/p'`
	if [ -z "$to" ]
	then
	    echo >&2 "Error: from=$from does not start with \"pm\""
	    exit 1
	fi
    fi
fi

$showme && echo >&2 "Info: promote \"$from\" -> \"$to\""

tmp=/var/tmp/$$
trap "rm -f $tmp.*; exit 0" 0 1 2 3 15
rm -f $tmp.*

if [ $# -eq 0 ]
then
    if [ ! -d .git ]
    then
	echo >&2 "Error: need to be at the base of the git tree, bozo"
	exit 1
    fi
    topdir=''
    $showme && echo >&2 "Info: topdir=$topdir"
    find src man qa books debian -type f
else
    here=`pwd`
    rm -f $tmp.tmp
    while true
    do
	if [ -d .git ]
	then
	    topdir=`pwd`/
	    break
	fi
	if [ `pwd` = "/" ]
	then
	    echo >&2 "Error: no .git between / and $here, do you know what you're doing?"
	    exit 1
	fi
	cd ..
    done
    cd $here
    $showme && echo >&2 "Info: topdir=$topdir"

    for arg
    do
	echo $arg
    done
fi >$tmp.list

cat $tmp.list \
| while read file
do
    case $file
    in
	# these ones are binary, or expected to hold the old symbol name
	# or artifacts created in the build or QA detritis
	#
	*.so.*|*/deprecated.[ch]|*/exports|${topdir}qa/src/qa_libpcp_compat.c|${topdir}qa/1166|${topdir}qa/1166.out|${topdir}src/libpcp/src/derive_parser.y|${topdir}qa/*.bad|${topdir}src/pmie/src/fun.c)
	    ;;

	*.c|*.h|*.cpp|*.cxx|*.in|*.y|*.l|*.xs|*.[1-8]|*.xml|${topdir}qa/[0-9]*|*.install)
	    if grep -E "$from_pat" $file >/dev/null
	    then
		echo >&2 "$file:"
		# TODO
		sed <$file >$tmp.tmp \
		    -e "s/\\([^a-zA-Z0-9_]\\)$from\\([^a-zA-Z0-9_]\\)/\\1$to\\2/g" \
		    -e "s/^$from\\([^a-zA-Z0-9_]\\)/$to\\1/" \
		    -e "s/\\([^a-zA-Z0-9_]\\)$from\$/\\1$to/" \
		    -e "s/^$from\$/$to/" \
		# end
		if $showme
		then
		    diff >&2 -u $file $tmp.tmp
		else
		    cp $tmp.tmp $file
		fi
	    fi
	    ;;
    esac
done

# expect #define or prototype or typdef or extern in deprecated.h
#
if [ -f ${topdir}src/include/pcp/deprecated.h ]
then
    sed -e 's/^/ /' -e 's/$/ /' -e '/^#/d' <${topdir}src/include/pcp/deprecated.h >$tmp.tmp
    if grep "[^a-zA-Z0-9_]$from[^a-zA-Z0-9_]" <$tmp.tmp >$tmp.out
    then
	:
    else
	echo "Warning: no reference to \"$from\" in deprecated.h"
	if $suggest
	then
	    echo "? * $from()		$to()"
	    echo "? #define $from $to"
	fi
    fi
    if grep "[^a-zA-Z0-9_]$to[^a-zA-Z0-9_]" <$tmp.tmp >$tmp.out
    then
	:
    else
	echo "Warning: no reference to \"$to\" in deprecated.h"
    fi
    if $showme
    then
	grep -E "[^a-zA-Z0-9_]($from|$to)[^a-zA-Z0-9_]" <$tmp.tmp >$tmp.out
	if [ -s $tmp.out ]
	then
	    echo >&2 "details from deprecated.h:"
	    cat >&2 $tmp.out
	fi
    fi
else
    echo >&2 "Warning: cannot find ${topdir}src/include/pcp/deprecated.h"
fi

# expect $to in pmapi.h
#
if [ -f ${topdir}src/include/pcp/pmapi.h ]
then
    sed -e 's/^/ /' -e 's/$/ /' -e '/^#/d' <${topdir}src/include/pcp/pmapi.h >$tmp.tmp
    if grep "[^a-zA-Z0-9_]$to[^a-zA-Z0-9_]" <$tmp.tmp >$tmp.out
    then
	:
    else
	echo "Warning: no reference to \"$to\" in pmapi.h"
    fi
else
    echo >&2 "Warning: cannot find ${topdir}src/include/pcp/pmapi.h"
fi

# promote
#	do not expect $to or $from in impl.h nor libpcp.h
# demote
#	do not expect $to or $from in pmapi.h nor impl.h nor libpcp.h
#
for inc in pmapi.h impl.h libpcp.h
do
    [ "$inc" = pmapi.h ] && $promote && continue
    if [ -f ${topdir}src/include/pcp/$inc ]
    then
	sed -e 's/^/ /' -e 's/$/ /' -e '/^#/d' <${topdir}src/include/pcp/$inc >$tmp.tmp
	if grep "[^a-zA-Z0-9_]$from[^a-zA-Z0-9_]" <$tmp.tmp >$tmp.out
	then
	    echo "Warning: reference to \"$from\" in $inc"
	fi
	if grep "[^a-zA-Z0-9_]$to[^a-zA-Z0-9_]" <$tmp.tmp >$tmp.out
	then
	    echo "Warning: reference to \"$from\" in $inc"
	fi
	if $showme
	then
	    grep -E "[^a-zA-Z0-9_]($from|$to)[^a-zA-Z0-9_]" <$tmp.tmp >$tmp.out
	    if [ -s $tmp.out ]
	    then
		echo >&2 "details from $inc:"
		cat >&2 $tmp.out
	    fi
	fi
    else
	echo >&2 "Warning: cannot find ${topdir}src/include/pcp/$inc.h"
    fi
done

if $function
then
    # expect $from function deprecated.c
    #
    if [ -f ${topdir}src/libpcp/src/deprecated.c ]
    then
	if grep "^$from *(" ${topdir}src/libpcp/src/deprecated.c >$tmp.out
	then
	    :
	else
	    echo "Warning: no reference to \"$from\" in deprecated.c"
	    if $suggest
	    then
		cat <<End-of-File
? #undef $from
? [type]
? $from([args])
? {
?     return $to([args]);
? }
End-of-File
	    fi
	fi
	if $showme
	then
	    if [ -s $tmp.out ]
	    then
		echo >&2 "declaration from deprecated.c:"
		cat >&2 $tmp.out
	    fi
	fi
    else
	echo >&2 "Warning: cannot find ${topdir}src/libpcp/src/deprecated.c"
    fi

    # expect $from and $to symbols in exports
    #
    if [ -f ${topdir}src/libpcp/src/exports ]
    then
	for func in $from $to
	do
	    if grep "^[ 	]*$func;" ${topdir}src/libpcp/src/exports >$tmp.out
	    then
		:
	    else
		echo "Warning: no reference to \"$func\" in libpcp exports"
		$suggest && echo "?    $func;"
	    fi
	done
    else
	echo >&2 "Warning: cannot find ${topdir}src/libpcp/src/exports"
    fi

    # expect man page entry for $to, none for $old
    #
    if [ -d ${topdir}man/man3 ]
    then
	rm -f $tmp.ok
	find ${topdir}man/man3* -type f \
	| while read file
	do
	    if grep "\\\\f3$to\\\\f1" <$file >/dev/null
	    then
		$showme && echo >&2 "$file: contains man entry for $to"
		echo $file >>$tmp.ok
	    fi
	    if grep "\\\\f3$from\\\\f1" <$file >/dev/null
	    then
		echo "Warning: $file: contains man entry for $from"
	    fi
	done
	if [ ! -f $tmp.ok ]
	then
	    echo "Warning: no man entry for $to"
	fi
    else
	echo >&2 "Warning: cannot find ${topdir}man/man3"
    fi

    # expect entries for $to [$tmp.ok] in debian inventories
    #
    if [ -d ${topdir}debian ]
    then
	rm -f $tmp.routine.ok $tmp.file.ok
	for file in ${topdir}debian/*.install
	do
	    if grep "/$to.3.gz" <$file >$tmp.out
	    then
		$showme && echo >&2 "$file: inventory contains $to man page"
		touch $tmp.routine.ok
		if [ -s $tmp.ok ]
		then
		    for man in `cat $tmp.ok`
		    do
			if grep "/$man.gz" <$file >$tmp.out
			then
			    $showme && echo >&2 "$file: inventory contains `echo $man | sed -e 's@.*/@@'` man file"
			    touch $tmp.file.ok
			    break
			fi
		    done
		fi
		break
	    fi
	done
	if [ ! -f $tmp.routine.ok ]
	then
	    echo "Warning: no Debian inventory entry for $to man page"
	    $suggest && echo "? usr/share/man/man3/$to.3.gz"
	fi
	if [ -s $tmp.ok ]
	then
	    if [ ! -f $tmp.file.ok ]
	    then
		echo "Warning: no Debian inventory entry for `cat $tmp.ok` man file"
		$suggest && echo "? usr/share/`cat $tmp.ok | tr '[A-Z]' '[a-z]'`.gz"
	    fi
	fi
    else
	echo >&2 "Warning: cannot find ${topdir}debian"
    fi
fi

# expect $from reference in qa_libpcp_compat.c
#
if [ -f ${topdir}qa/src/qa_libpcp_compat.c ]
then
    if grep " $from *(" ${topdir}qa/src/qa_libpcp_compat.c >$tmp.out
    then
	:
    else
	echo "Warning: no reference to \"$from\" in qa_libpcp_compat.c"
    fi
else
    echo >&2 "Warning: cannot find ${topdir}qa/src/qa_libpcp_compat.c"
fi