Make error messages at start-up more consistent.  Every line of such
messages now begin with "valgrind: ", and they're more often printed before
the preamble.  This required introducing a new message kind, Vg_FailMsg, and
functions VG_(fmsg) and VG_(fmsg_bad_option), and removing
VG_(err_bad_option).

Where we used to have horrible output like this:

    [ocean:~/grind/ws2] vg5 --tool=massif --threshold=101 date
    ==31877== Massif, a heap profiler
    ==31877== Copyright (C) 2003-2010, and GNU GPL'd, by Nicholas Nethercote
    ==31877== Using Valgrind-3.6.0.SVN and LibVEX; rerun with -h for copyright info
    ==31877== Command: date
    ==31877== 
    ==31877== --threshold must be between 0.0 and 100.0
    valgrind: Bad option '--threshold'; aborting.
    valgrind: Use --help for more information.

We now have nice output like this:

    [ocean:~/grind/ws2] vg2 --tool=massif --threshold=101 date
    valgrind: Bad option: --threshold=101
    valgrind: --threshold must be between 0.0 and 100.0
    valgrind: Use --help for more information or consult the user manual.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11209 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_libcprint.c b/coregrind/m_libcprint.c
index 3a54504..4117126 100644
--- a/coregrind/m_libcprint.c
+++ b/coregrind/m_libcprint.c
@@ -400,14 +400,6 @@
       HChar ch;
       Int   i, depth;
 
-      switch (b->kind) {
-         case Vg_UserMsg:       ch = '='; break;
-         case Vg_DebugMsg:      ch = '-'; break;
-         case Vg_DebugExtraMsg: ch = '+'; break;
-         case Vg_ClientMsg:     ch = '*'; break;
-         default:               ch = '?'; break;
-      }
-
       // Print one '>' in front of the messages for each level of
       // self-hosting being performed.
       depth = RUNNING_ON_VALGRIND;
@@ -417,26 +409,48 @@
          b->buf[b->buf_used++] = '>';
       }
 
-      b->buf[b->buf_used++] = ch;
-      b->buf[b->buf_used++] = ch;
+      if (Vg_FailMsg == b->kind) {
+         // "valgrind: " prefix.
+         b->buf[b->buf_used++] = 'v';
+         b->buf[b->buf_used++] = 'a';
+         b->buf[b->buf_used++] = 'l';
+         b->buf[b->buf_used++] = 'g';
+         b->buf[b->buf_used++] = 'r';
+         b->buf[b->buf_used++] = 'i';
+         b->buf[b->buf_used++] = 'n';
+         b->buf[b->buf_used++] = 'd';
+         b->buf[b->buf_used++] = ':';
+         b->buf[b->buf_used++] = ' ';
+      } else {
+         switch (b->kind) {
+            case Vg_UserMsg:       ch = '='; break;
+            case Vg_DebugMsg:      ch = '-'; break;
+            case Vg_DebugExtraMsg: ch = '+'; break;
+            case Vg_ClientMsg:     ch = '*'; break;
+            default:               ch = '?'; break;
+         }
 
-      if (VG_(clo_time_stamp)) {
-         VG_(memset)(tmp, 0, sizeof(tmp));
-         VG_(elapsed_wallclock_time)(tmp);
+         b->buf[b->buf_used++] = ch;
+         b->buf[b->buf_used++] = ch;
+
+         if (VG_(clo_time_stamp)) {
+            VG_(memset)(tmp, 0, sizeof(tmp));
+            VG_(elapsed_wallclock_time)(tmp);
+            tmp[sizeof(tmp)-1] = 0;
+            for (i = 0; tmp[i]; i++)
+               b->buf[b->buf_used++] = tmp[i];
+         }
+
+         VG_(sprintf)(tmp, "%d", VG_(getpid)());
          tmp[sizeof(tmp)-1] = 0;
          for (i = 0; tmp[i]; i++)
             b->buf[b->buf_used++] = tmp[i];
+
+         b->buf[b->buf_used++] = ch;
+         b->buf[b->buf_used++] = ch;
+         b->buf[b->buf_used++] = ' ';
       }
 
-      VG_(sprintf)(tmp, "%d", VG_(getpid)());
-      tmp[sizeof(tmp)-1] = 0;
-      for (i = 0; tmp[i]; i++)
-         b->buf[b->buf_used++] = tmp[i];
-
-      b->buf[b->buf_used++] = ch;
-      b->buf[b->buf_used++] = ch;
-      b->buf[b->buf_used++] = ' ';
-
       /* We can't possibly have stuffed 96 chars in merely as a result
          of making the preamble (can we?) */
       vg_assert(b->buf_used < sizeof(b->buf)-32);
@@ -503,7 +517,36 @@
    return count;
 }
 
+static void revert_to_stderr ( void )
+{
+   VG_(log_output_sink).fd = 2; /* stderr */
+   VG_(log_output_sink).is_socket = False;
+}
+
 /* VG_(message) variants with hardwired first argument. */
+
+UInt VG_(fmsg) ( const HChar* format, ... )
+{
+   UInt count;
+   va_list vargs;
+   va_start(vargs,format);
+   count = VG_(vmessage) ( Vg_FailMsg, format, vargs );
+   va_end(vargs);
+   return count;
+}
+
+void VG_(fmsg_bad_option) ( HChar* opt, const HChar* format, ... )
+{
+   va_list vargs;
+   va_start(vargs,format);
+   revert_to_stderr();
+   VG_(message) (Vg_FailMsg, "Bad option: %s\n", opt);
+   VG_(vmessage)(Vg_FailMsg, format, vargs );
+   VG_(message) (Vg_FailMsg, "Use --help for more information or consult the user manual.\n");
+   VG_(exit)(1);
+   va_end(vargs);
+}
+
 UInt VG_(umsg) ( const HChar* format, ... )
 {
    UInt count;
@@ -543,6 +586,24 @@
    b->buf_used = 0;
 }
 
+__attribute__((noreturn))
+void VG_(err_missing_prog) ( void  )
+{
+   revert_to_stderr();
+   VG_(fmsg)("no program specified\n");
+   VG_(fmsg)("Use --help for more information.\n");
+   VG_(exit)(1);
+}
+
+__attribute__((noreturn))
+void VG_(err_config_error) ( Char* msg )
+{
+   revert_to_stderr();
+   VG_(fmsg)("Startup or configuration error:\n   %s\n", msg);
+   VG_(fmsg)("Unable to start up properly.  Giving up.\n");
+   VG_(exit)(1);
+}
+
 
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/