fixed warning
[fw/openocd] / src / helper / log.c
index f210b6d017cc8c8fa33cddbc620d4074896c9674..efe5d5bb949ff2bafc816d82fef3f90e4be03cb9 100644 (file)
@@ -2,6 +2,9 @@
  *   Copyright (C) 2005 by Dominic Rath                                    *
  *   Dominic.Rath@gmx.de                                                   *
  *                                                                         *
+ *   Copyright (C) 2007,2008 Ã˜yvind Harboe                                      *
+ *   oyvind.harboe@zylin.com                                               *
+ *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
  *   the Free Software Foundation; either version 2 of the License, or     *
@@ -24,6 +27,7 @@
 #include "log.h"
 #include "configuration.h"
 #include "time_support.h"
+#include "command.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -103,8 +107,12 @@ static void log_puts(enum log_levels level, const char *file, int line, const ch
                }
                else
                {
-                       /* do not print count and time */
-                       fprintf(log_output, "%s %s:%d %s(): %s", log_strings[level+1], file, line, function, string);
+                       if (strcmp(string, "\n")!=0)
+                       {
+                               /* print human readable output - but skip empty lines */
+                               fprintf(log_output, "%s%s",
+                                               (level > LOG_LVL_USER)?log_strings[level+1]:"", string);
+                       }
                }
        } else
        {
@@ -364,6 +372,11 @@ void keep_alive()
                LOG_USER_N("%s", "");
                last_time=current_time;
        }
+
+       /* also process TCL events (we have to do this from 'log.c' since its
+        * keep_alive() is the only routine guaranteed to be called at least
+        * once per second :( */
+       process_jim_events ();
 }
 
 /* reset keep alive timer without sending message */
@@ -372,3 +385,20 @@ void kept_alive()
        current_time=timeval_ms();
        last_time=current_time;
 }
+
+/* if we sleep for extended periods of time, we must invoke keep_alive() intermittantly */
+void alive_sleep(int ms)
+{
+       int i;
+       for (i=0; i<ms; i+=500)
+       {
+               int sleep_a_bit=ms-i;
+               if (sleep_a_bit>500)
+               {
+                       sleep_a_bit=500;
+               }
+               keep_alive();
+               usleep(sleep_a_bit*1000);
+               keep_alive();
+       }
+}