$NetBSD: patch-bq,v 1.2 2002/03/28 10:11:54 jmc Exp $

--- ../gcc-2.95.3/gcc/cccp.c.orig 2001/04/23 11:58:03 1.1.1.2
+++ ../gcc-2.95.3/gcc/cccp.c 2001/08/14 01:13:34 1.2
@@ -2779,7 +2779,8 @@
 	    RECACHE;
 	    continue;
 	  }
-	  if (!traditional) {
+	  if (!(traditional || put_out_comments))
+	  {
 	    error_with_line (line_for_error (start_line),
 			     "unterminated string or character constant");
 	    if (multiline_string_line) {
@@ -2797,7 +2798,8 @@
 	  ++op->lineno;
 	  /* Traditionally, end of line ends a string constant with no error.
 	     So exit the loop and record the new line.  */
-	  if (traditional) {
+	  if (traditional || put_out_comments)
+	  {
 	    beg_of_line = ibp;
 	    goto while2end;
 	  }
@@ -2868,7 +2870,7 @@
       break;
 
     case '/':
-      if (ip->macro != 0)
+      if (ip->macro != 0 && put_out_comments == 0)
 	goto randomchar;
       if (*ibp == '\\' && ibp[1] == '\n')
 	newline_fix (ibp);
@@ -3777,7 +3779,8 @@
       limit = ip->buf + ip->length;
       unterminated = 0;
       already_output = 0;
-      keep_comments = traditional && kt->type == T_DEFINE;
+      keep_comments = kt->type == T_DEFINE && (traditional ||
+	put_out_comments);
       /* #import is defined only in Objective C, or when on the NeXT.  */
       if (kt->type == T_IMPORT
 	  && !(objc || lookup ((U_CHAR *) "__NeXT__", -1, -1)))
@@ -4025,7 +4028,7 @@
 		while (xp != ip->bufp)
 		  *cp++ = *xp++;
 	      /* Delete or replace the slash.  */
-	      else if (traditional)
+	      else if (traditional || put_out_comments)
 		cp--;
 	      else
 		cp[-1] = ' ';
@@ -6208,6 +6211,20 @@
 	    stringify = p;
 	}
 	break;
+      case '/':
+	if (expected_delimiter != '\0') /* No comments inside strings.  */
+	  break;
+	if (*p == '*') {
+	  while (p < limit) {
+	    *exp_p++ = *p++;
+	    if (p[0] == '*' && p[1] == '/') {
+	      *exp_p++ = *p++;
+	      *exp_p++ = *p++;
+	      break;
+	    }
+	  }
+	}
+        break;
       }
     } else {
       /* In -traditional mode, recognize arguments inside strings and
@@ -6240,11 +6257,22 @@
 	  /* If we find a comment that wasn't removed by handle_directive,
 	     this must be -traditional.  So replace the comment with
 	     nothing at all.  */
-	  exp_p--;
-	  while (++p < limit) {
-	    if (p[0] == '*' && p[1] == '/') {
-	      p += 2;
-	      break;
+	  if (!put_out_comments) {
+	    exp_p--;
+	    while (++p < limit) {
+	      if (p[0] == '*' && p[1] == '/') {
+		p += 2;
+		break;
+	      }
+	    }
+	  } else {
+	    while (p < limit) {
+	      *exp_p++ = *p++;
+	      if (p[0] == '*' && p[1] == '/') {
+		  *exp_p++ = *p++;
+		  *exp_p++ = *p++;
+		  break;
+	      }
 	    }
 	  }
 #if 0
@@ -7243,6 +7271,24 @@
   pcp_inside_if = 0;
   delete_macro (save_defined);	/* clean up special symbol */
 
+  if (put_out_comments) {
+    char *ptr, *eptr = temp_obuf.buf + temp_obuf.length;
+
+    for (ptr = temp_obuf.buf; ptr < eptr; ptr++) {
+      if (*ptr == '/' && ptr + 1 < eptr && ptr[1] == '*') {
+	*ptr++ = ' ';
+	*ptr++ = ' ';
+	while (ptr < eptr) {
+	  if (*ptr == '*' && ptr + 1 < eptr && ptr[1] == '/') {
+	    *ptr++ = ' ';
+	    *ptr++ = ' ';
+	    break;
+	  } else
+	    *ptr++ = ' ';
+	}
+      }
+    }
+  }
   temp_obuf.buf[temp_obuf.length] = '\n';
   value = parse_c_expression ((char *) temp_obuf.buf,
 			      warn_undef && !instack[indepth].system_header_p);