OSDN Git Service

2000-07-21 Alexandre Petit-Bianco <apbianco@cygnus.com>
[pf3gnuchains/gcc-fork.git] / gcc / gccbug.in
1 #!/bin/sh
2 # Submit a problem report to a GNATS site.
3 # Copyright (C) 1993, 2000 Free Software Foundation, Inc.
4 # Contributed by Brendan Kehoe (brendan@cygnus.com), based on a
5 # version written by Heinz G. Seidl (hgs@cygnus.com).
6 #
7 # This file is part of GNU GNATS.
8 #
9 # GNU GNATS is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
12 # any later version.
13 #
14 # GNU GNATS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with GNU GNATS; see the file COPYING.  If not, write to
21 # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 # The version of this send-pr.
24 VERSION=3.113
25
26 # The submitter-id for your site.
27 SUBMITTER=net
28
29 # The default mail address for PR submissions. 
30 GNATS_ADDR=gcc-gnats@gcc.gnu.org
31
32 # The default release for this host.
33 DEFAULT_RELEASE="@gcc_version@"
34
35 # The default organization.
36 DEFAULT_ORGANIZATION=
37
38 # What mailer to use.  This must come after the config file, since it is
39 # host-dependent.
40 # Copied from cvsbug
41 if [ -f /usr/sbin/sendmail ]; then  
42     MAIL_AGENT="/usr/sbin/sendmail -oi -t"
43 else  
44     MAIL_AGENT="/usr/lib/sendmail -oi -t"
45 fi
46 MAILER=`echo $MAIL_AGENT | sed -e 's, .*,,'`
47 if [ ! -f "$MAILER" ] ; then
48     echo "$COMMAND: Cannot file mail program \"$MAILER\"."
49     echo "$COMMAND: Please fix the MAIL_AGENT entry in the $COMMAND file."
50     exit 1
51 fi
52
53
54 # How to read the passwd database.
55 PASSWD="cat /etc/passwd"
56
57 ECHON=bsd
58
59 if [ $ECHON = bsd ] ; then
60   ECHON1="echo -n"
61   ECHON2=
62 elif [ $ECHON = sysv ] ; then
63   ECHON1=echo
64   ECHON2='\c'
65 else
66   ECHON1=echo
67   ECHON2=
68 fi
69
70 #\f
71
72 if [ -z "$TMPDIR" ]; then
73   TMPDIR=/tmp
74 else
75   if [ "`echo $TMPDIR | grep '/$'`" != "" ]; then
76     TMPDIR="`echo $TMPDIR | sed -e 's,/$,,'`"
77   fi
78 fi
79
80 TEMP=$TMPDIR/p$$
81 BAD=$TMPDIR/pbad$$
82 REF=$TMPDIR/pf$$
83
84 # find a user name
85 if [ "$LOGNAME" = "" ]; then
86         if [ "$USER" != "" ]; then
87                 LOGNAME="$USER"
88         else
89                 LOGNAME="UNKNOWN"
90         fi
91 fi
92
93 FROM="$LOGNAME"
94 REPLY_TO="${REPLY_TO:-${REPLYTO:-$LOGNAME}}"
95
96 # Find out the name of the originator of this PR.
97 if [ -n "$NAME" ]; then
98   ORIGINATOR="$NAME"
99 elif [ -f $HOME/.fullname ]; then
100   ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
101 else
102   # Must use temp file due to incompatibilities in quoting behavior
103   # and to protect shell metacharacters in the expansion of $LOGNAME
104   $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
105   ORIGINATOR="`cat $TEMP`"
106   rm -f $TEMP
107 fi
108
109 if [ -n "$ORGANIZATION" ]; then
110   if [ -f "$ORGANIZATION" ]; then
111     ORGANIZATION="`cat $ORGANIZATION`"
112   fi
113 else
114   if [ -n "$DEFAULT_ORGANIZATION" ]; then
115     ORGANIZATION="$DEFAULT_ORGANIZATION"
116   elif [ -f $HOME/.organization ]; then
117     ORGANIZATION="`cat $HOME/.organization`"
118   fi
119 fi
120
121 # If they don't have a preferred editor set, then use
122 if [ -z "$VISUAL" ]; then
123   if [ -z "$EDITOR" ]; then
124     EDIT=vi
125   else
126     EDIT="$EDITOR"
127   fi
128 else
129   EDIT="$VISUAL"
130 fi
131
132 # Find out some information.
133 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
134         ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
135 ARCH=`[ -f /bin/arch ] && /bin/arch`
136 MACHINE=`[ -f /bin/machine ] && /bin/machine`
137
138 COMMAND=`echo $0 | sed -e 's,.*/,,'`
139 USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [-s severity]
140        [-c address] [--request-id] [--version]"
141 REMOVE=
142 BATCH=
143 CC=
144 SEVERITY_C=
145
146 while [ $# -gt 0 ]; do
147   case "$1" in
148     -r) ;;              # Ignore for backward compat.
149     -t | --to) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
150         shift ; GNATS_ADDR="$1"
151         EXPLICIT_GNATS_ADDR=true
152         ;;
153     -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
154         shift ; IN_FILE="$1"
155         if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
156           echo "$COMMAND: cannot read $IN_FILE"
157           exit 1
158         fi
159         ;;
160     -b | --batch) BATCH=true ;;
161     -c | --cc) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
162         shift ; CC="$1"
163         ;;
164     -s | --severity) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
165         shift ; SEVERITY_C="$1"
166         ;;
167     -p | -P | --print) PRINT=true ;;
168     -L | --list) FORMAT=norm ;;
169     -l | -CL | --lisp) FORMAT=lisp ;;
170     --request-id) REQUEST_ID=true ;;
171     -h | --help) echo "$USAGE"; exit 0 ;;
172     -V | --version) echo "$VERSION"; exit 0 ;;
173     -*) echo "$USAGE" ; exit 1 ;;
174     *) echo "$USAGE" ; exit 1
175  esac
176  shift
177 done
178
179 # spam does not need to be listed here
180 CATEGORIES="c++ c debug fortran java libf2c libobjc libstdc++ middle-end objc optimization other target web"
181
182 case "$FORMAT" in
183   lisp) echo "$CATEGORIES" | \
184         awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
185         exit 0
186         ;;
187   norm) l=`echo "$CATEGORIES" | \
188         awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
189              END {print max + 1;}'`
190         c=`expr 70 / $l`
191         if [ $c -eq 0 ]; then c=1; fi
192         echo "$CATEGORIES" | \
193         awk 'BEGIN {print "Known categories:"; i = 0 }
194           { printf ("%-'$l'.'$l's", $0); if ((++i % '$c') == 0) { print "" } }
195             END { print ""; }'
196         exit 0
197         ;;
198 esac
199
200 ORIGINATOR_C='<name of the PR author (one line)>'
201 ORGANIZATION_C='<organization of PR author (multiple lines)>'
202 CONFIDENTIAL_C='<[ yes | no ] (one line)>'
203 SYNOPSIS_C='<synopsis of the problem (one line)>'
204 if [ -z "$SEVERITY_C" ]; then
205   SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
206 fi
207 PRIORITY_C='<[ low | medium | high ] (one line)>'
208 CATEGORY_C='<choose from the top of this file (one line)>'
209 RELEASE_C='<release number or tag (one line)>'
210 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
211 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
212 HOW_TO_REPEAT_C='<When reporting a compiler error, preprocessor output must be included>'
213 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
214
215 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
216 xs=0
217 trap 'rm -f $REF $TEMP; exit $xs' 0
218 trap 'echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP; xs=1; exit' 1 3 13 15
219
220 # If they told us to use a specific file, then do so.
221 if [ -n "$IN_FILE" ]; then
222   if [ "$IN_FILE" = "-" ]; then
223     # The PR is coming from the standard input.
224     if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
225       sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
226     else
227       cat > $TEMP
228     fi
229   else
230     # Use the file they named.
231     if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
232       sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
233     else
234       cat $IN_FILE > $TEMP
235     fi
236   fi
237 else
238
239   if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
240     # If their PR_FORM points to a bogus entry, then bail.
241     if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
242       echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
243       sleep 1
244       PRINT_INTERN=bad_prform
245     fi
246   fi
247
248   if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
249     cp $PR_FORM $TEMP || 
250       ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
251   else
252     for file in $TEMP $REF ; do
253       cat  > $file << '__EOF__'
254 SEND-PR: -*- send-pr -*-
255 SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
256 SEND-PR: will all comments (text enclosed in `<' and `>').
257 SEND-PR: 
258 SEND-PR: Please consult the GCC manual manual if you are not sure how to
259 SEND-PR: fill out a problem report.
260 SEND-PR: Note that the Synopsis field is mandatory.  The Subject (for
261 SEND-PR: the mail) will be made the same as Synopsis unless explicitly
262 SEND-PR: changed.
263 SEND-PR:
264 SEND-PR: Choose from the following categories:
265 SEND-PR:
266 __EOF__
267
268       # Format the categories so they fit onto lines.
269         l=`echo "$CATEGORIES" | \
270         awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
271              END {print max + 1;}'`
272         c=`expr 61 / $l`
273         if [ $c -eq 0 ]; then c=1; fi
274         echo "$CATEGORIES" | \
275         awk 'BEGIN {printf "SEND-PR: "; i = 0 }
276           { printf ("%-'$l'.'$l's", $0);
277             if ((++i % '$c') == 0) { printf "\nSEND-PR: " } }
278             END { printf "\nSEND-PR:\n"; }' >> $file
279
280       cat >> $file << __EOF__
281 To: $GNATS_ADDR
282 Subject: 
283 From: $FROM
284 Reply-To: $REPLYTO
285 Cc: $CC
286 X-send-pr-version: $VERSION
287 X-GNATS-Notify: 
288
289
290 >Submitter-Id:  $SUBMITTER
291 >Originator:    $ORIGINATOR
292 >Organization:  ${ORGANIZATION-$ORGANIZATION_C}
293 >Confidential:  $CONFIDENTIAL_C
294 >Synopsis:      $SYNOPSIS_C
295 >Severity:      $SEVERITY_C
296 SEND-PR: critical     GCC is completely not operational; no work-around known.
297 SEND-PR: serious      GCC is not working properly; a work-around is possible.
298 SEND-PR: non-critical Report indicates minor problem.
299 >Priority:      $PRIORITY_C
300 SEND-PR: high         A solution is necessary as soon as possible.
301 SEND-PR: medium       The problem should be solved in the next release.
302 SEND-PR: low          The problem should be solve in a future release.
303 >Category:      $CATEGORY_C
304 >Class:         <[ doc-bug | accepts-illegal | rejects-legal | wrong-code | ice-on-legal-code| ice-on-illegal-code | pessimizes-code | sw-bug | change-request | support ] (one line)>
305 SEND-PR: doc-bug          The doumentation is incorrect.
306 SEND-PR: accepts-illegal  GCC fails to reject erroneous code.
307 SEND-PR: rejects-legal    GCC gives an error message for correct code.
308 SEND-PR: wrong-code       The machine code generated by gcc is incorrect.
309 SEND-PR: ice-on-legal-code   GCC gives an Internal Compiler Error (ICE)
310 SEND-PR:                     for correct code
311 SEND-PR: ice-on-illegal-code GCC gives an ICE instead of reporting an error
312 SEND-PR: pessimizes-code     GCC misses an important optimization opportunity
313 SEND-PR: sw-bug              Software bug of some other class than above
314 SEND-PR: change-request      A feature in GCC is missing.
315 SEND-PR: support             I need help with gcc.
316 >Release:       ${DEFAULT_RELEASE-$RELEASE_C}
317 >Environment:
318 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
319 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
320 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
321         $ENVIRONMENT_C
322 host: @host@
323 build: @build@
324 target: @target@
325 >Description:
326         $DESCRIPTION_C
327 >How-To-Repeat:
328         $HOW_TO_REPEAT_C
329 >Fix:
330         $FIX_C
331 __EOF__
332     done
333   fi
334
335   if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
336     cat $TEMP
337     xs=0; exit
338   fi
339
340   chmod u+w $TEMP
341   if [ -z "$REQUEST_ID" ]; then
342     eval $EDIT $TEMP
343   else
344     ed -s $TEMP << '__EOF__'
345 /^Subject/s/^Subject:.*/Subject: request for a customer id/
346 /^>Category/s/^>Category:.*/>Category: send-pr/
347 w
348 q
349 __EOF__
350   fi
351
352   if cmp -s $REF $TEMP ; then
353     echo "$COMMAND: problem report not filled out, therefore not sent"
354     xs=1; exit
355   fi
356 fi
357
358 #\f
359 #       Check the enumeration fields
360
361 # This is a "sed-subroutine" with one keyword parameter 
362 # (with workaround for Sun sed bug)
363 #
364 SED_CMD='
365 /$PATTERN/{
366 s|||
367 s|<.*>||
368 s|^[    ]*||
369 s|[     ]*$||
370 p
371 q
372 }'
373
374
375 while [ -z "$REQUEST_ID" ]; do
376   CNT=0
377
378   # 1) Confidential
379   #
380   PATTERN=">Confidential:"
381   CONFIDENTIAL=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
382   case "$CONFIDENTIAL" in
383     ""|yes|no) CNT=`expr $CNT + 1` ;;
384     *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
385   esac
386   #
387   # 2) Severity
388   #
389   PATTERN=">Severity:"
390   SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
391   case "$SEVERITY" in
392     ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
393     *)  echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
394   esac
395   #
396   # 3) Priority
397   #
398   PATTERN=">Priority:"
399   PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
400   case "$PRIORITY" in
401     ""|low|medium|high) CNT=`expr $CNT + 1` ;;
402     *)  echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
403   esac
404   #
405   # 4) Category
406   #
407   PATTERN=">Category:"
408   CATEGORY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
409   FOUND=
410   for C in $CATEGORIES
411   do
412     if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
413   done
414   if [ -n "$FOUND" ]; then
415     CNT=`expr $CNT + 1` 
416   else
417     if [ -z "$CATEGORY" ]; then
418       echo "$COMMAND: you must include a Category: field in your report."
419     else
420       echo "$COMMAND: \`$CATEGORY' is not a known category."
421     fi
422   fi
423   #
424   # 5) Class
425   #
426   PATTERN=">Class:"
427   CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
428   case "$CLASS" in
429     ""|doc-bug|accepts-illegal|rejects-legal|wrong-code|ice-on-legal-code|ice-on-illegal-code|pessimizes-code|sw-bug|change-request|support) CNT=`expr $CNT + 1` ;;
430     *)  echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
431   esac
432   #
433   # 6) Check that synopsis is not empty
434   #
435   if grep "^>Synopsis:[         ]*${SYNOPSIS_C}\$" $TEMP > /dev/null
436   then
437     echo "$COMMAND: Synopsis must not be empty."
438   else
439     CNT=`expr $CNT + 1`
440   fi
441
442   [ $CNT -lt 6 -a -z "$BATCH" ] && 
443     echo "Errors were found with the problem report."
444
445   while true; do
446     if [ -z "$BATCH" ]; then
447       $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
448       read input
449     else
450       if [ $CNT -eq 6 ]; then
451         input=s
452       else
453         input=a
454       fi
455     fi
456     case "$input" in
457       a*)
458         if [ -z "$BATCH" ]; then
459           echo "$COMMAND: the problem report remains in $BAD and is not sent."
460           mv $TEMP $BAD
461         else
462           echo "$COMMAND: the problem report is not sent."
463         fi
464         xs=1; exit
465         ;;
466       e*)
467         eval $EDIT $TEMP
468         continue 2
469         ;;
470       s*)
471         break 2
472         ;;
473     esac
474   done
475 done
476
477 #
478 # Make sure the mail has got a Subject.  If not, use the same as
479 # in Synopsis.
480 #
481
482 if grep '^Subject:[     ]*$' $TEMP > /dev/null
483 then
484   SYNOPSIS=`grep '^>Synopsis:' $TEMP | sed -e 's/^>Synopsis:[   ]*//'`
485   ed -s $TEMP << __EOF__
486 /^Subject:/s/:.*\$/: $SYNOPSIS/
487 w
488 q
489 __EOF__
490 fi
491
492 #
493 #       Remove comments and send the problem report
494 #       (we have to use patterns, where the comment contains regex chars)
495 #
496 # /^>Originator:/s;$ORIGINATOR;;
497 sed  -e "
498 /^SEND-PR:/d
499 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
500 /^>Confidential:/s;<.*>;;
501 /^>Synopsis:/s;$SYNOPSIS_C;;
502 /^>Severity:/s;<.*>;;
503 /^>Priority:/s;<.*>;;
504 /^>Category:/s;$CATEGORY_C;;
505 /^>Class:/s;<.*>;;
506 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
507 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
508 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
509 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
510 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
511 " $TEMP > $REF
512
513 if $MAIL_AGENT < $REF; then
514   echo "$COMMAND: problem report sent"
515   xs=0; exit
516 else
517   echo "$COMMAND: mysterious mail failure."
518   if [ -z "$BATCH" ]; then
519     echo "$COMMAND: the problem report remains in $BAD and is not sent."
520     mv $REF $BAD
521   else
522     echo "$COMMAND: the problem report is not sent."
523   fi
524   xs=1; exit
525 fi