1 //----------------------------------------------------------------------------- 
   2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net> 
   3 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com> 
   5 // This code is licensed to you under the terms of the GNU GPL, version 2 or, 
   6 // at your option, any later version. See the LICENSE.txt file for the text of 
   8 //----------------------------------------------------------------------------- 
  10 //----------------------------------------------------------------------------- 
  13 #ifndef EXTERNAL_PRINTANDLOG 
  17 #include <readline/readline.h> 
  23 double CursorScaleFactor 
= 1; 
  24 int PlotGridX
=0, PlotGridY
=0, PlotGridXdefault
= 64, PlotGridYdefault
= 64, CursorCPos
= 0, CursorDPos
= 0; 
  26 int flushAfterWrite 
= 0;  //buzzy 
  28 bool GridLocked 
= false; 
  29 bool showDemod 
= true; 
  31 static char *logfilename 
= "proxmark3.log"; 
  33 #ifndef EXTERNAL_PRINTANDLOG 
  34 // Declared in proxmark3.c 
  35 extern pthread_mutex_t print_lock
; 
  37 void PrintAndLog(char *fmt
, ...) 
  41         va_list argptr
, argptr2
; 
  42         static FILE *logfile 
= NULL
; 
  45         // lock this section to avoid interlacing prints from different threads 
  46         pthread_mutex_lock(&print_lock
); 
  48         if (logging 
&& !logfile
) { 
  49                 logfile
=fopen(logfilename
, "a"); 
  51                         fprintf(stderr
, "Can't open logfile, logging disabled!\n"); 
  56         // If there is an incoming message from the hardware (eg: lf hid read) in 
  57         // the background (while the prompt is displayed and accepting user input), 
  58         // stash the prompt and bring it back later. 
  59 #ifdef RL_STATE_READCMD 
  60         // We are using GNU readline. libedit (OSX) doesn't support this flag. 
  61         int need_hack 
= (rl_readline_state 
& RL_STATE_READCMD
) > 0; 
  64                 saved_point 
= rl_point
; 
  65                 saved_line 
= rl_copy_text(0, rl_end
); 
  67                 rl_replace_line("", 0); 
  72         va_start(argptr
, fmt
); 
  73         va_copy(argptr2
, argptr
); 
  75         printf("          "); // cleaning prompt 
  79 #ifdef RL_STATE_READCMD 
  80         // We are using GNU readline. libedit (OSX) doesn't support this flag. 
  83                 rl_replace_line(saved_line
, 0); 
  84                 rl_point 
= saved_point
; 
  90         if (logging 
&& logfile
) { 
  91                 vfprintf(logfile
, fmt
, argptr2
); 
  92                 fprintf(logfile
,"\n"); 
  97         if (flushAfterWrite 
== 1)  //buzzy 
 102         pthread_mutex_unlock(&print_lock
);   
 106 void SetLogFilename(char *fn
)