]> git.zerfleddert.de Git - proxmark3-svn/blame - client/ui.c
Fix for swapped parity when using lf_bulk_program.lua (#591)
[proxmark3-svn] / client / ui.c
CommitLineData
a553f267 1//-----------------------------------------------------------------------------
212ef3a0 2// Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
a553f267 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
3775e9e8
MF
12#include <stdbool.h>
13#ifndef EXTERNAL_PRINTANDLOG
51969283 14#include <stdlib.h>
7fe9b0b7 15#include <stdio.h>
3775e9e8 16#include <stdarg.h>
51969283 17#include <readline/readline.h>
9492e0b0 18#include <pthread.h>
3775e9e8 19#endif
7fe9b0b7 20
21#include "ui.h"
22
3fe71039 23double CursorScaleFactor = 1;
b8fdac9e 24int PlotGridX=0, PlotGridY=0, PlotGridXdefault= 64, PlotGridYdefault= 64, CursorCPos= 0, CursorDPos= 0;
7fe9b0b7 25int offline;
3851172d 26int flushAfterWrite = 0; //buzzy
0f321d63 27int GridOffset = 0;
3fe71039 28bool GridLocked = false;
b8fdac9e 29bool showDemod = true;
0f321d63 30
7fe9b0b7 31static char *logfilename = "proxmark3.log";
32
3775e9e8 33#ifndef EXTERNAL_PRINTANDLOG
f5ecd97b 34static pthread_mutex_t print_lock = PTHREAD_MUTEX_INITIALIZER;
3775e9e8 35
7fe9b0b7 36void PrintAndLog(char *fmt, ...)
37{
51969283
M
38 char *saved_line;
39 int saved_point;
9492e0b0 40 va_list argptr, argptr2;
41 static FILE *logfile = NULL;
42 static int logging=1;
7fe9b0b7 43
acf0582d 44 // lock this section to avoid interlacing prints from different threads
9492e0b0 45 pthread_mutex_lock(&print_lock);
46
47 if (logging && !logfile) {
48 logfile=fopen(logfilename, "a");
49 if (!logfile) {
50 fprintf(stderr, "Can't open logfile, logging disabled!\n");
51 logging=0;
52 }
53 }
ed50f7f3 54
a5a83016
MF
55 // If there is an incoming message from the hardware (eg: lf hid read) in
56 // the background (while the prompt is displayed and accepting user input),
57 // stash the prompt and bring it back later.
ed50f7f3 58#ifdef RL_STATE_READCMD
a5a83016 59 // We are using GNU readline. libedit (OSX) doesn't support this flag.
51969283 60 int need_hack = (rl_readline_state & RL_STATE_READCMD) > 0;
7fe9b0b7 61
51969283
M
62 if (need_hack) {
63 saved_point = rl_point;
64 saved_line = rl_copy_text(0, rl_end);
65 rl_save_prompt();
66 rl_replace_line("", 0);
67 rl_redisplay();
68 }
ed50f7f3 69#endif
51969283 70
9492e0b0 71 va_start(argptr, fmt);
72 va_copy(argptr2, argptr);
73 vprintf(fmt, argptr);
74 printf(" "); // cleaning prompt
75 va_end(argptr);
76 printf("\n");
51969283 77
a5a83016
MF
78#ifdef RL_STATE_READCMD
79 // We are using GNU readline. libedit (OSX) doesn't support this flag.
51969283
M
80 if (need_hack) {
81 rl_restore_prompt();
82 rl_replace_line(saved_line, 0);
83 rl_point = saved_point;
84 rl_redisplay();
85 free(saved_line);
86 }
a5a83016 87#endif
51969283 88
9492e0b0 89 if (logging && logfile) {
90 vfprintf(logfile, fmt, argptr2);
91 fprintf(logfile,"\n");
92 fflush(logfile);
93 }
94 va_end(argptr2);
95
ed77aabe 96 if (flushAfterWrite == 1) //buzzy
97 {
98 fflush(NULL);
99 }
9492e0b0 100 //release lock
101 pthread_mutex_unlock(&print_lock);
7fe9b0b7 102}
3775e9e8 103#endif
9492e0b0 104
7fe9b0b7 105void SetLogFilename(char *fn)
106{
107 logfilename = fn;
108}
Impressum, Datenschutz