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