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