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