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