]> git.zerfleddert.de Git - proxmark3-svn/blob - client/ui.c
updated code to follow same blinking patterns with leds during flashing/holding button
[proxmark3-svn] / client / ui.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2009 Michael Gernoth <michael at gernoth.net>
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
12 #include <stdarg.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <time.h>
16 #include <readline/readline.h>
17
18 #include "ui.h"
19
20 double CursorScaleFactor;
21 int PlotGridX, PlotGridY, PlotGridXdefault= 64, PlotGridYdefault= 64;
22 int offline;
23
24 static char *logfilename = "proxmark3.log";
25
26 void PrintAndLog(char *fmt, ...)
27 {
28 char *saved_line;
29 int saved_point;
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 }
41
42 int need_hack = (rl_readline_state & RL_STATE_READCMD) > 0;
43
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
52 va_start(argptr, fmt);
53 va_copy(argptr2, argptr);
54 vprintf(fmt, argptr);
55 printf(" "); // cleaning prompt
56 va_end(argptr);
57 printf("\n");
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
67 if (logging && logfile) {
68 vfprintf(logfile, fmt, argptr2);
69 fprintf(logfile,"\n");
70 fflush(logfile);
71 }
72 va_end(argptr2);
73 }
74
75 void SetLogFilename(char *fn)
76 {
77 logfilename = fn;
78 }
Impressum, Datenschutz