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 #ifdef RL_STATE_READCMD
57 // We are using GNU readline.
58 int need_hack
= (rl_readline_state
& RL_STATE_READCMD
) > 0;
61 saved_point
= rl_point
;
62 saved_line
= rl_copy_text(0, rl_end
);
64 rl_replace_line("", 0);
68 // We are using libedit (OSX), which doesn't support this flag.
72 va_start(argptr
, fmt
);
73 va_copy(argptr2
, argptr
);
75 printf(" "); // cleaning prompt
81 rl_replace_line(saved_line
, 0);
82 rl_point
= saved_point
;
87 if (logging
&& logfile
) {
88 vfprintf(logfile
, fmt
, argptr2
);
89 fprintf(logfile
,"\n");
94 if (flushAfterWrite
== 1) //buzzy
99 pthread_mutex_unlock(&print_lock
);
103 void SetLogFilename(char *fn
)