OSDN Git Service

* gccbug.in: Add web category, gcc specific classes.
[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 gc host java libf2c libgcc libobjc libstdc++ middle-end objc optimization other profiling 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 list of categories above (one line)>'
209 CLASS_C='<[ 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)>'
210 RELEASE_C='<release number or tag (one line)>'
211 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
212 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
213 HOW_TO_REPEAT_C='<When reporting a compiler error, preprocessor output must be included>'
214 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
215
216 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
217 xs=0
218 trap 'rm -f $REF $TEMP; exit $xs' 0
219 trap 'echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP; xs=1; exit' 1 3 13 15
220
221 # If they told us to use a specific file, then do so.
222 if [ -n "$IN_FILE" ]; then
223   if [ "$IN_FILE" = "-" ]; then
224     # The PR is coming from the standard input.
225     if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
226       sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
227     else
228       cat > $TEMP
229     fi
230   else
231     # Use the file they named.
232     if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
233       sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
234     else
235       cat $IN_FILE > $TEMP
236     fi
237   fi
238 else
239
240   if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
241     # If their PR_FORM points to a bogus entry, then bail.
242     if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
243       echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
244       sleep 1
245       PRINT_INTERN=bad_prform
246     fi
247   fi
248
249   if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
250     cp $PR_FORM $TEMP || 
251       ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
252   else
253     for file in $TEMP $REF ; do
254       cat  > $file << '__EOF__'
255 SEND-PR: -*- send-pr -*-
256 SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
257 SEND-PR: will all comments (text enclosed in `<' and `>').
258 SEND-PR: 
259 SEND-PR: Please consult the send-pr man page `send-pr(1)' or the Texinfo
260 SEND-PR: manual if you are not sure how to fill out a problem report.
261 SEND-PR: Note that the Synopsis field is mandatory.  The Subject (for
262 SEND-PR: the mail) will be made the same as Synopsis unless explicitly
263 SEND-PR: changed.
264 SEND-PR:
265 SEND-PR: Choose from the following categories:
266 SEND-PR:
267 __EOF__
268
269       # Format the categories so they fit onto lines.
270         l=`echo "$CATEGORIES" | \
271         awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
272              END {print max + 1;}'`
273         c=`expr 61 / $l`
274         if [ $c -eq 0 ]; then c=1; fi
275         echo "$CATEGORIES" | \
276         awk 'BEGIN {printf "SEND-PR: "; i = 0 }
277           { printf ("%-'$l'.'$l's", $0);
278             if ((++i % '$c') == 0) { printf "\nSEND-PR: " } }
279             END { printf "\nSEND-PR:\n"; }' >> $file
280
281       cat >> $file << __EOF__
282 To: $GNATS_ADDR
283 Subject: 
284 From: $FROM
285 Reply-To: $REPLYTO
286 Cc: $CC
287 X-send-pr-version: $VERSION
288 X-GNATS-Notify: 
289
290
291 >Submitter-Id:  $SUBMITTER
292 >Originator:    $ORIGINATOR
293 >Organization:  ${ORGANIZATION-$ORGANIZATION_C}
294 >Confidential:  $CONFIDENTIAL_C
295 >Synopsis:      $SYNOPSIS_C
296 >Severity:      $SEVERITY_C
297 >Priority:      $PRIORITY_C
298 >Category:      $CATEGORY_C
299 >Class:         $CLASS_C
300 >Release:       ${DEFAULT_RELEASE-$RELEASE_C}
301 >Environment:
302 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
303 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
304 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
305         $ENVIRONMENT_C
306 host: @host@
307 build: @build@
308 target: @target@
309 >Description:
310         $DESCRIPTION_C
311 >How-To-Repeat:
312         $HOW_TO_REPEAT_C
313 >Fix:
314         $FIX_C
315 __EOF__
316     done
317   fi
318
319   if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
320     cat $TEMP
321     xs=0; exit
322   fi
323
324   chmod u+w $TEMP
325   if [ -z "$REQUEST_ID" ]; then
326     eval $EDIT $TEMP
327   else
328     ed -s $TEMP << '__EOF__'
329 /^Subject/s/^Subject:.*/Subject: request for a customer id/
330 /^>Category/s/^>Category:.*/>Category: send-pr/
331 w
332 q
333 __EOF__
334   fi
335
336   if cmp -s $REF $TEMP ; then
337     echo "$COMMAND: problem report not filled out, therefore not sent"
338     xs=1; exit
339   fi
340 fi
341
342 #\f
343 #       Check the enumeration fields
344
345 # This is a "sed-subroutine" with one keyword parameter 
346 # (with workaround for Sun sed bug)
347 #
348 SED_CMD='
349 /$PATTERN/{
350 s|||
351 s|<.*>||
352 s|^[    ]*||
353 s|[     ]*$||
354 p
355 q
356 }'
357
358
359 while [ -z "$REQUEST_ID" ]; do
360   CNT=0
361
362   # 1) Confidential
363   #
364   PATTERN=">Confidential:"
365   CONFIDENTIAL=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
366   case "$CONFIDENTIAL" in
367     ""|yes|no) CNT=`expr $CNT + 1` ;;
368     *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
369   esac
370   #
371   # 2) Severity
372   #
373   PATTERN=">Severity:"
374   SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
375   case "$SEVERITY" in
376     ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
377     *)  echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
378   esac
379   #
380   # 3) Priority
381   #
382   PATTERN=">Priority:"
383   PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
384   case "$PRIORITY" in
385     ""|low|medium|high) CNT=`expr $CNT + 1` ;;
386     *)  echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
387   esac
388   #
389   # 4) Category
390   #
391   PATTERN=">Category:"
392   CATEGORY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
393   FOUND=
394   for C in $CATEGORIES
395   do
396     if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
397   done
398   if [ -n "$FOUND" ]; then
399     CNT=`expr $CNT + 1` 
400   else
401     if [ -z "$CATEGORY" ]; then
402       echo "$COMMAND: you must include a Category: field in your report."
403     else
404       echo "$COMMAND: \`$CATEGORY' is not a known category."
405     fi
406   fi
407   #
408   # 5) Class
409   #
410   PATTERN=">Class:"
411   CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
412   case "$CLASS" in
413     ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
414     *)  echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
415   esac
416   #
417   # 6) Check that synopsis is not empty
418   #
419   if grep "^>Synopsis:[         ]*${SYNOPSIS_C}\$" $TEMP > /dev/null
420   then
421     echo "$COMMAND: Synopsis must not be empty."
422   else
423     CNT=`expr $CNT + 1`
424   fi
425
426   [ $CNT -lt 6 -a -z "$BATCH" ] && 
427     echo "Errors were found with the problem report."
428
429   while true; do
430     if [ -z "$BATCH" ]; then
431       $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
432       read input
433     else
434       if [ $CNT -eq 6 ]; then
435         input=s
436       else
437         input=a
438       fi
439     fi
440     case "$input" in
441       a*)
442         if [ -z "$BATCH" ]; then
443           echo "$COMMAND: the problem report remains in $BAD and is not sent."
444           mv $TEMP $BAD
445         else
446           echo "$COMMAND: the problem report is not sent."
447         fi
448         xs=1; exit
449         ;;
450       e*)
451         eval $EDIT $TEMP
452         continue 2
453         ;;
454       s*)
455         break 2
456         ;;
457     esac
458   done
459 done
460
461 #
462 # Make sure the mail has got a Subject.  If not, use the same as
463 # in Synopsis.
464 #
465
466 if grep '^Subject:[     ]*$' $TEMP > /dev/null
467 then
468   SYNOPSIS=`grep '^>Synopsis:' $TEMP | sed -e 's/^>Synopsis:[   ]*//'`
469   ed -s $TEMP << __EOF__
470 /^Subject:/s/:.*\$/: $SYNOPSIS/
471 w
472 q
473 __EOF__
474 fi
475
476 #
477 #       Remove comments and send the problem report
478 #       (we have to use patterns, where the comment contains regex chars)
479 #
480 # /^>Originator:/s;$ORIGINATOR;;
481 sed  -e "
482 /^SEND-PR:/d
483 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
484 /^>Confidential:/s;<.*>;;
485 /^>Synopsis:/s;$SYNOPSIS_C;;
486 /^>Severity:/s;<.*>;;
487 /^>Priority:/s;<.*>;;
488 /^>Category:/s;$CATEGORY_C;;
489 /^>Class:/s;<.*>;;
490 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
491 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
492 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
493 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
494 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
495 " $TEMP > $REF
496
497 if $MAIL_AGENT < $REF; then
498   echo "$COMMAND: problem report sent"
499   xs=0; exit
500 else
501   echo "$COMMAND: mysterious mail failure."
502   if [ -z "$BATCH" ]; then
503     echo "$COMMAND: the problem report remains in $BAD and is not sent."
504     mv $REF $BAD
505   else
506     echo "$COMMAND: the problem report is not sent."
507   fi
508   xs=1; exit
509 fi