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;
25 bool flushAfterWrite
= false; //buzzy
27 bool GridLocked
= false;
28 bool showDemod
= true;
30 static char *logfilename
= "proxmark3.log";
32 #ifndef EXTERNAL_PRINTANDLOG
33 static pthread_mutex_t print_lock
= PTHREAD_MUTEX_INITIALIZER
;
35 void PrintAndLog(char *fmt
, ...)
39 va_list argptr
, argptr2
;
40 static FILE *logfile
= NULL
;
43 // lock this section to avoid interlacing prints from different threads
44 pthread_mutex_lock(&print_lock
);
46 if (logging
&& !logfile
) {
47 logfile
=fopen(logfilename
, "a");
49 fprintf(stderr
, "Can't open logfile, logging disabled!\n");
54 // If there is an incoming message from the hardware (eg: lf hid read) in
55 // the background (while the prompt is displayed and accepting user input),
56 // stash the prompt and bring it back later.
57 #ifdef RL_STATE_READCMD
58 // We are using GNU readline. libedit (OSX) doesn't support this flag.
59 int need_hack
= (rl_readline_state
& RL_STATE_READCMD
) > 0;
62 saved_point
= rl_point
;
63 saved_line
= rl_copy_text(0, rl_end
);
65 rl_replace_line("", 0);
70 va_start(argptr
, fmt
);
71 va_copy(argptr2
, argptr
);
73 printf(" "); // cleaning prompt
77 #ifdef RL_STATE_READCMD
78 // We are using GNU readline. libedit (OSX) doesn't support this flag.
81 rl_replace_line(saved_line
, 0);
82 rl_point
= saved_point
;
88 if (logging
&& logfile
) {
89 vfprintf(logfile
, fmt
, argptr2
);
90 fprintf(logfile
,"\n");
95 if (flushAfterWrite
) //buzzy
100 pthread_mutex_unlock(&print_lock
);
104 void SetLogFilename(char *fn
)
109 void SetFlushAfterWrite(bool flush_after_write
) {
110 flushAfterWrite
= flush_after_write
;