]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/ui.c
revert removal of quarter frequency support for hi_read_rx_xcorr.v
[proxmark3-svn] / client / ui.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
3 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
4 //
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
7 // the license.
8 //-----------------------------------------------------------------------------
9 // UI utilities
10 //-----------------------------------------------------------------------------
11
12 #include <stdarg.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <stdbool.h>
16 #include <readline/readline.h>
17 #include <pthread.h>
18
19 #include "ui.h"
20
21 double CursorScaleFactor = 1;
22 int PlotGridX=0, PlotGridY=0, PlotGridXdefault= 64, PlotGridYdefault= 64, CursorCPos= 0, CursorDPos= 0;
23 int offline;
24 int flushAfterWrite = 0; //buzzy
25 int GridOffset = 0;
26 bool GridLocked = false;
27 bool showDemod = true;
28
29 extern pthread_mutex_t print_lock;
30
31 static char *logfilename = "proxmark3.log";
32
33 void PrintAndLog(char *fmt, ...)
34 {
35 char *saved_line;
36 int saved_point;
37 va_list argptr, argptr2;
38 static FILE *logfile = NULL;
39 static int logging=1;
40
41 // lock this section to avoid interlacing prints from different threads
42 pthread_mutex_lock(&print_lock);
43
44 if (logging && !logfile) {
45 logfile=fopen(logfilename, "a");
46 if (!logfile) {
47 fprintf(stderr, "Can't open logfile, logging disabled!\n");
48 logging=0;
49 }
50 }
51
52 #ifdef RL_STATE_READCMD
53 // We are using GNU readline.
54 int need_hack = (rl_readline_state & RL_STATE_READCMD) > 0;
55
56 if (need_hack) {
57 saved_point = rl_point;
58 saved_line = rl_copy_text(0, rl_end);
59 rl_save_prompt();
60 rl_replace_line("", 0);
61 rl_redisplay();
62 }
63 #else
64 // We are using libedit (OSX), which doesn't support this flag.
65 int need_hack = 0;
66 #endif
67
68 va_start(argptr, fmt);
69 va_copy(argptr2, argptr);
70 vprintf(fmt, argptr);
71 printf(" "); // cleaning prompt
72 va_end(argptr);
73 printf("\n");
74
75 if (need_hack) {
76 rl_restore_prompt();
77 rl_replace_line(saved_line, 0);
78 rl_point = saved_point;
79 rl_redisplay();
80 free(saved_line);
81 }
82
83 if (logging && logfile) {
84 vfprintf(logfile, fmt, argptr2);
85 fprintf(logfile,"\n");
86 fflush(logfile);
87 }
88 va_end(argptr2);
89
90 if (flushAfterWrite == 1) //buzzy
91 {
92 fflush(NULL);
93 }
94 //release lock
95 pthread_mutex_unlock(&print_lock);
96 }
97
98
99 void SetLogFilename(char *fn)
100 {
101 logfilename = fn;
102 }
Impressum, Datenschutz