]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/ui.c
compiling on windows again
[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>
7fe9b0b7 17
18#include "ui.h"
19
20double CursorScaleFactor;
7ddb9900 21int PlotGridX, PlotGridY, PlotGridXdefault= 64, PlotGridYdefault= 64;
7fe9b0b7 22int offline;
23
24static char *logfilename = "proxmark3.log";
25
26void PrintAndLog(char *fmt, ...)
27{
51969283
M
28 char *saved_line;
29 int saved_point;
7fe9b0b7 30 va_list argptr, argptr2;
31 static FILE *logfile = NULL;
32 static int logging=1;
33
34 if (logging && !logfile) {
35 logfile=fopen(logfilename, "a");
36 if (!logfile) {
37 fprintf(stderr, "Can't open logfile, logging disabled!\n");
38 logging=0;
39 }
40 }
51969283
M
41
42 int need_hack = (rl_readline_state & RL_STATE_READCMD) > 0;
7fe9b0b7 43
51969283
M
44 if (need_hack) {
45 saved_point = rl_point;
46 saved_line = rl_copy_text(0, rl_end);
47 rl_save_prompt();
48 rl_replace_line("", 0);
49 rl_redisplay();
50 }
51
7fe9b0b7 52 va_start(argptr, fmt);
53 va_copy(argptr2, argptr);
54 vprintf(fmt, argptr);
e6b8c965 55 printf(" "); // cleaning prompt
7fe9b0b7 56 va_end(argptr);
57 printf("\n");
51969283
M
58
59 if (need_hack) {
60 rl_restore_prompt();
61 rl_replace_line(saved_line, 0);
62 rl_point = saved_point;
63 rl_redisplay();
64 free(saved_line);
65 }
66
7fe9b0b7 67 if (logging && logfile) {
7fe9b0b7 68 vfprintf(logfile, fmt, argptr2);
69 fprintf(logfile,"\n");
70 fflush(logfile);
71 }
72 va_end(argptr2);
73}
74
75void SetLogFilename(char *fn)
76{
77 logfilename = fn;
78}
Impressum, Datenschutz