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