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 //-----------------------------------------------------------------------------
16 #include <readline/readline.h>
21 double CursorScaleFactor
= 1;
22 int PlotGridX
=0, PlotGridY
=0, PlotGridXdefault
= 64, PlotGridYdefault
= 64, CursorCPos
= 0, CursorDPos
= 0;
24 bool flushAfterWrite
= false; //buzzy
26 bool GridLocked
= false;
27 bool showDemod
= true;
29 extern pthread_mutex_t print_lock
;
31 static char *logfilename
= "proxmark3.log";
33 void PrintAndLog(char *fmt
, ...)
37 va_list argptr
, argptr2
;
38 static FILE *logfile
= NULL
;
41 // lock this section to avoid interlacing prints from different threads
42 pthread_mutex_lock(&print_lock
);
44 if (logging
&& !logfile
) {
45 logfile
=fopen(logfilename
, "a");
47 fprintf(stderr
, "Can't open logfile, logging disabled!\n");
52 #ifdef RL_STATE_READCMD
53 // We are using GNU readline.
54 int need_hack
= (rl_readline_state
& RL_STATE_READCMD
) > 0;
57 saved_point
= rl_point
;
58 saved_line
= rl_copy_text(0, rl_end
);
60 rl_replace_line("", 0);
64 // We are using libedit (OSX), which doesn't support this flag.
67 va_start(argptr
, fmt
);
68 va_copy(argptr2
, argptr
);
70 printf(" "); // cleaning prompt
74 // This needs to be wrapped in ifdefs, as this if optimisation is disabled,
75 // this block won't be removed, and it'll fail at the linker.
76 #ifdef RL_STATE_READCMD
79 rl_replace_line(saved_line
, 0);
80 rl_point
= saved_point
;
86 if (logging
&& logfile
) {
87 vfprintf(logfile
, fmt
, argptr2
);
88 fprintf(logfile
,"\n");
93 if (flushAfterWrite
== 1) //buzzy
98 pthread_mutex_unlock(&print_lock
);
102 void SetLogFilename(char *fn
)
107 void SetFlushAfterWrite(bool flush_after_write
) {
108 flushAfterWrite
= flush_after_write
;