]> git.zerfleddert.de Git - proxmark3-svn/blame - client/ui.c
fix clang compiler warnings
[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
MF
33#ifndef EXTERNAL_PRINTANDLOG
34// Declared in proxmark3.c
35extern pthread_mutex_t print_lock;
36
7fe9b0b7 37void PrintAndLog(char *fmt, ...)
38{
51969283
M
39 char *saved_line;
40 int saved_point;
9492e0b0 41 va_list argptr, argptr2;
42 static FILE *logfile = NULL;
43 static int logging=1;
7fe9b0b7 44
acf0582d 45 // lock this section to avoid interlacing prints from different threads
9492e0b0 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 }
ed50f7f3
MF
55
56#ifdef RL_STATE_READCMD
57 // We are using GNU readline.
51969283 58 int need_hack = (rl_readline_state & RL_STATE_READCMD) > 0;
7fe9b0b7 59
51969283
M
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 }
ed50f7f3
MF
67#else
68 // We are using libedit (OSX), which doesn't support this flag.
3851172d 69 int need_hack = 0;
ed50f7f3 70#endif
51969283 71
9492e0b0 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");
51969283
M
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
9492e0b0 87 if (logging && logfile) {
88 vfprintf(logfile, fmt, argptr2);
89 fprintf(logfile,"\n");
90 fflush(logfile);
91 }
92 va_end(argptr2);
93
ed77aabe 94 if (flushAfterWrite == 1) //buzzy
95 {
96 fflush(NULL);
97 }
9492e0b0 98 //release lock
99 pthread_mutex_unlock(&print_lock);
7fe9b0b7 100}
3775e9e8 101#endif
9492e0b0 102
7fe9b0b7 103void SetLogFilename(char *fn)
104{
105 logfilename = fn;
106}
Impressum, Datenschutz