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 static pthread_mutex_t print_lock
= PTHREAD_MUTEX_INITIALIZER
;
36 void PrintAndLog(char *fmt
, ...)
40 va_list argptr
, argptr2
;
41 static FILE *logfile
= NULL
;
44 // lock this section to avoid interlacing prints from different threads
45 pthread_mutex_lock(&print_lock
);
47 if (logging
&& !logfile
) {
48 logfile
=fopen(logfilename
, "a");
50 fprintf(stderr
, "Can't open logfile, logging disabled!\n");
55 // If there is an incoming message from the hardware (eg: lf hid read) in
56 // the background (while the prompt is displayed and accepting user input),
57 // stash the prompt and bring it back later.
58 #ifdef RL_STATE_READCMD
59 // We are using GNU readline. libedit (OSX) doesn't support this flag.
60 int need_hack
= (rl_readline_state
& RL_STATE_READCMD
) > 0;
63 saved_point
= rl_point
;
64 saved_line
= rl_copy_text(0, rl_end
);
66 rl_replace_line("", 0);
71 va_start(argptr
, fmt
);
72 va_copy(argptr2
, argptr
);
74 printf(" "); // cleaning prompt
78 #ifdef RL_STATE_READCMD
79 // We are using GNU readline. libedit (OSX) doesn't support this flag.
82 rl_replace_line(saved_line
, 0);
83 rl_point
= saved_point
;
89 if (logging
&& logfile
) {
90 vfprintf(logfile
, fmt
, argptr2
);
91 fprintf(logfile
,"\n");
96 if (flushAfterWrite
== 1) //buzzy
101 pthread_mutex_unlock(&print_lock
);
105 void SetLogFilename(char *fn
)