1 |
#!/bin/sh |
#!/bin/sh |
2 |
# Copyright (C) 2004 Free Software Foundation, Inc. |
# Copyright (C) 2004, 2005 Free Software Foundation, Inc. |
3 |
# Written by Mike Bianchi <MBianchi@Foveal.com <mailto:MBianchi@Foveal.com>> |
# Written by Mike Bianchi <MBianchi@Foveal.com <mailto:MBianchi@Foveal.com>> |
4 |
|
|
5 |
# This file is part of the gdiffmk utility, which is part of groff. |
# This file is part of the gdiffmk utility, which is part of groff. |
36 |
groff \`.mc' requests added to indicate how it is different from FILE1. |
groff \`.mc' requests added to indicate how it is different from FILE1. |
37 |
|
|
38 |
FILE1 Previous version of the groff file. \`-' means standard input. |
FILE1 Previous version of the groff file. \`-' means standard input. |
39 |
FILE2 Current version of the groff file. \`-' means standard input. |
FILE2 Current version of the groff file. \`-' means standard input. |
40 |
Either FILE1 or FILE2 can be standard input, but not both. |
Either FILE1 or FILE2 can be standard input, but not both. |
41 |
OUTPUT Copy of FILE2 with \`.mc' commands added. |
OUTPUT Copy of FILE2 with \`.mc' commands added. |
42 |
\`-' means standard output (the default). |
\`-' means standard output (the default). |
43 |
|
|
44 |
OPTIONS: |
OPTIONS: |
45 |
-a addmark Mark for added groff source lines. Default: +. |
-a ADDMARK Mark for added groff source lines. Default: \`+'. |
46 |
-c changemark Mark for changed groff source lines. Default: |. |
-c CHANGEMARK Mark for changed groff source lines. Default: \`|'. |
47 |
-d deletemark Mark for deleted groff source lines. Default: *. |
-d DELETEMARK Mark for deleted groff source lines. Default: \`*'. |
48 |
-x diffcmd Use a different diff(1) command; |
|
49 |
one that accepts the \`-Dname' option, such as GNU diff. |
-D Show the deleted portions from changed and deleted text. |
50 |
|
Default delimiting marks: \`[[' .... \`]]'. |
51 |
|
-B By default, the deleted texts marked by the \`-D' option end |
52 |
|
with an added troff \`.br\' command. This option prevents |
53 |
|
the added \`.br\'. |
54 |
|
-M MARK1 MARK2 Change the delimiting marks for the \`-D' option. |
55 |
|
|
56 |
|
-x DIFFCMD Use a different diff(1) command; |
57 |
|
one that accepts the \`-Dname' option, such as GNU diff. |
58 |
--version Print version information on the standard output and exit. |
--version Print version information on the standard output and exit. |
59 |
--help Print this message on the standard error. |
--help Print this message on the standard error. |
60 |
" |
" |
132 |
fi |
fi |
133 |
} |
} |
134 |
|
|
135 |
addmark='+' |
ADDMARK='+' |
136 |
changemark='|' |
CHANGEMARK='|' |
137 |
deletemark='*' |
DELETEMARK='*' |
138 |
|
MARK1='[[' |
139 |
|
MARK2=']]' |
140 |
|
|
141 |
function RequiresArgument { |
function RequiresArgument { |
142 |
# Process flags that take either concatenated or |
# Process flags that take either concatenated or |
158 |
} |
} |
159 |
|
|
160 |
badoption= |
badoption= |
161 |
diffcmd=diff |
DIFFCMD=diff |
162 |
|
D_option= |
163 |
|
br=.br |
164 |
for OPTION |
for OPTION |
165 |
do |
do |
166 |
case "${OPTION}" in |
case "${OPTION}" in |
167 |
-a*) |
-a*) |
168 |
addmark=$( RequiresArgument "${OPTION}" $2 ) && |
ADDMARK=$( RequiresArgument "${OPTION}" $2 ) && |
169 |
shift |
shift |
170 |
;; |
;; |
171 |
-c*) |
-c*) |
172 |
changemark=$( RequiresArgument "${OPTION}" $2 ) && |
CHANGEMARK=$( RequiresArgument "${OPTION}" $2 ) && |
173 |
shift |
shift |
174 |
;; |
;; |
175 |
-d*) |
-d*) |
176 |
deletemark=$( RequiresArgument "${OPTION}" $2 ) && |
DELETEMARK=$( RequiresArgument "${OPTION}" $2 ) && |
177 |
shift |
shift |
178 |
;; |
;; |
179 |
|
-D ) |
180 |
|
D_option=D_option |
181 |
|
;; |
182 |
|
-M ) |
183 |
|
shift |
184 |
|
MARK1=$1 |
185 |
|
shift |
186 |
|
MARK2=$1 |
187 |
|
;; |
188 |
|
-B ) |
189 |
|
br=. |
190 |
|
;; |
191 |
-x* ) |
-x* ) |
192 |
diffcmd=$( RequiresArgument "${OPTION}" $2 ) && |
DIFFCMD=$( RequiresArgument "${OPTION}" $2 ) && |
193 |
shift |
shift |
194 |
;; |
;; |
195 |
--version) |
--version) |
217 |
shift |
shift |
218 |
done |
done |
219 |
|
|
220 |
${diffcmd} -Dx /dev/null /dev/null >/dev/null 2>&1 || |
${DIFFCMD} -Dx /dev/null /dev/null >/dev/null 2>&1 || |
221 |
Usage "The \`${diffcmd}' program does not accept" \ |
Usage "The \`${DIFFCMD}' program does not accept" \ |
222 |
"the required \`-Dname' option. |
"the required \`-Dname' option. |
223 |
Use GNU diff instead. See the \`-x diffcmd' option." |
Use GNU diff instead. See the \`-x DIFFCMD' option." |
224 |
|
|
225 |
if test -n "${badoption}" |
if test -n "${badoption}" |
226 |
then |
then |
263 |
# To make a very unlikely label even more unlikely ... |
# To make a very unlikely label even more unlikely ... |
264 |
label=__diffmk_$$__ |
label=__diffmk_$$__ |
265 |
|
|
266 |
diff -D"${label}" -- ${FILE1} ${FILE2} | |
sed_script=' |
|
sed -n ' |
|
267 |
/^#ifdef '"${label}"'/,/^#endif \/\* '"${label}"'/ { |
/^#ifdef '"${label}"'/,/^#endif \/\* '"${label}"'/ { |
268 |
/^#ifdef '"${label}"'/ s/.*/.mc '"${addmark}"'/ |
/^#ifdef '"${label}"'/ s/.*/.mc '"${ADDMARK}"'/ |
269 |
/^#endif \/\* '"${label}"'/ s/.*/.mc/ |
/^#endif \/\* '"${label}"'/ s/.*/.mc/ |
270 |
p |
p |
271 |
d |
d |
272 |
} |
} |
273 |
/^#ifndef '"${label}"'/,/^#endif \/\* [!not ]*'"${label}"'/ { |
/^#ifndef '"${label}"'/,/^#endif \/\* [!not ]*'"${label}"'/ { |
274 |
/^#else \/\* '"${label}"'/,/^#endif \/\* '"${label}"'/ { |
/^#else \/\* '"${label}"'/,/^#endif \/\* '"${label}"'/ { |
275 |
/^#else \/\* '"${label}"'/ s/.*/.mc '"${changemark}"'/ |
/^#else \/\* '"${label}"'/ s/.*/.mc '"${CHANGEMARK}"'/ |
276 |
/^#endif \/\* '"${label}"'/ s/.*/.mc/ |
/^#endif \/\* '"${label}"'/ s/.*/.mc/ |
277 |
p |
p |
278 |
d |
d |
279 |
} |
} |
280 |
/^#endif \/\* \(not\|!\) '"${label}"'/ { |
/^#endif \/\* \(not\|!\) '"${label}"'/ { |
281 |
s/.*/.mc '"${deletemark}"'/p |
s/.*/.mc '"${DELETEMARK}"'/p |
282 |
a\ |
a\ |
283 |
.mc |
.mc |
284 |
} |
} |
287 |
p |
p |
288 |
' |
' |
289 |
|
|
290 |
|
if [ ${D_option} ] |
291 |
|
then |
292 |
|
sed_script=' |
293 |
|
/^#ifdef '"${label}"'/,/^#endif \/\* '"${label}"'/ { |
294 |
|
/^#ifdef '"${label}"'/ s/.*/.mc '"${ADDMARK}"'/ |
295 |
|
/^#endif \/\* '"${label}"'/ s/.*/.mc/ |
296 |
|
p |
297 |
|
d |
298 |
|
} |
299 |
|
/^#ifndef '"${label}"'/,/^#endif \/\* [!not ]*'"${label}"'/ { |
300 |
|
/^#ifndef '"${label}"'/ { |
301 |
|
i\ |
302 |
|
'"${MARK1}"' |
303 |
|
d |
304 |
|
} |
305 |
|
/^#else \/\* '"${label}"'/ ! { |
306 |
|
/^#endif \/\* [!not ]*'"${label}"'/ ! { |
307 |
|
p |
308 |
|
d |
309 |
|
} |
310 |
|
} |
311 |
|
/^#else \/\* '"${label}"'/,/^#endif \/\* '"${label}"'/ { |
312 |
|
/^#else \/\* '"${label}"'/ { |
313 |
|
i\ |
314 |
|
'"${MARK2}"'\ |
315 |
|
'"${br}"' |
316 |
|
s/.*/.mc '"${CHANGEMARK}"'/ |
317 |
|
a\ |
318 |
|
.mc '"${CHANGEMARK}"' |
319 |
|
d |
320 |
|
} |
321 |
|
/^#endif \/\* '"${label}"'/ s/.*/.mc/ |
322 |
|
p |
323 |
|
d |
324 |
|
} |
325 |
|
/^#endif \/\* \(not\|!\) '"${label}"'/ { |
326 |
|
i\ |
327 |
|
'"${MARK2}"'\ |
328 |
|
'"${br}"' |
329 |
|
s/.*/.mc '"${DELETEMARK}"'/p |
330 |
|
a\ |
331 |
|
.mc |
332 |
|
} |
333 |
|
d |
334 |
|
} |
335 |
|
p |
336 |
|
' |
337 |
|
fi |
338 |
|
|
339 |
|
diff -D"${label}" -- ${FILE1} ${FILE2} | |
340 |
|
sed -n "${sed_script}" |
341 |
|
|
342 |
# EOF |
# EOF |