aboutsummaryrefslogtreecommitdiffstats
path: root/ui.c
blob: fd12a0bc27bcc225a695e28a073fb7ae72eba4f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <ncurses.h>
#include "machine_type.h"
#include "output.h"
#include "input.h"
#include "menu.h"
#include "search.h"
#include "correlation.h"

void searchmask(tOutput* output,tSearch* search,tBuffer* buf,tUInt64* cursorpos)
{
	tInt8	itemnums[10];
	tMenu	Menu1;
	tInt8	selected;
	tInt16	offsx;
	tInt16	offsy;
	int i;

	offsx=COLS/2-30;
	offsy=LINES/2-7;

	drawcenterframe(output,14,60,"Search...");
	clearMenu(&Menu1);

	newMenuItem(&Menu1,"Searchstring: (hex)",1,1,'S',0,&itemnums[0]);
	newMenuItem(&Menu1,"Searchstring: (asc)",3,1,0,0,&itemnums[1]);
	newMenuItem(&Menu1,"Forward",4,1,'F',0,&itemnums[2]);
	newMenuItem(&Menu1,"Backward",4,17,'B',0,&itemnums[3]);
	newMenuItem(&Menu1,"Write to searchlog",6,1,'W',0,&itemnums[4]);
	newMenuItem(&Menu1,"File:",7,1,0,0,&itemnums[5]);
	newMenuItem(&Menu1,"Read from searchlog",9,1,'R',0,&itemnums[6]);
	newMenuItem(&Menu1,"File:",10,1,0,0,&itemnums[7]);
	newMenuItem(&Menu1,"Go",13,1,'G',0,&itemnums[8]);
	newMenuItem(&Menu1,"Cancel",13,51,'C',1,&itemnums[9]);
	selected=-1;
	setcolor(output,COLOR_BRACKETS);
	mvwprintw(output->win,offsy+2,offsx+1,"[                                                        ]");
	mvwprintw(output->win,offsy+3,offsx+38,"[                   ]");
	setcolor(output,COLOR_BRACKETS);
	mvwprintw(output->win,offsy+4,offsx+11,"( )");
	mvwprintw(output->win,offsy+4,offsx+28,"( )");
	mvwprintw(output->win,offsy+6,offsx+22,"[ ]");
	mvwprintw(output->win,offsy+9,offsx+23,"[ ]");
	mvwprintw(output->win,offsy+7 ,offsx+7,"[                                                  ]");
	mvwprintw(output->win,offsy+10,offsx+7,"[                                                  ]");
	while (selected!=itemnums[8] && selected!=itemnums[9])
	{
		setcolor(output,COLOR_TEXT);
		mvwprintw(output->win,offsy+4,offsx+12,"%c",search->forwardnotbackward?'o':' ');
		mvwprintw(output->win,offsy+4,offsx+29,"%c",search->forwardnotbackward?' ':'o');
		mvwprintw(output->win,offsy+6,offsx+23,"%c",search->writesearchlog?'X':' ');
		mvwprintw(output->win,offsy+9,offsx+24,"%c",search->readsearchlog?'X':' ');
		setcolor(output,COLOR_TEXT);
		for (i=0;i<19;i++)
		{
			if (i<search->searchlen)	mvwprintw(output->win,offsy+2,offsx+2+i*3,"%02x",(tUInt32)(search->searchstring[i]&0xff));
			else				mvwprintw(output->win,offsy+2,offsx+2+i*3,"  ");

			if (i<search->searchlen)	mvwprintw(output->win,offsy+3,offsx+39+i,"%c",(search->searchstring[i]>=32 && search->searchstring[i]<127)?search->searchstring[i]:'.');
			else 				mvwprintw(output->win,offsy+3,offsx+39+i," ");
		}

		selected=MenuInteract(output,&Menu1,offsy,offsx);
			
		if (selected==itemnums[0]) 
		{
			hexinput2(output,offsy+2,offsx+1,search->searchstring,&search->searchlen,19);
		}
		if (selected==itemnums[1])
		{
			char	tmp[32];
			memset(tmp,0,32);
			for (i=0;i<search->searchlen && i<19;i++) tmp[i]=(search->searchstring[i]>=32 && search->searchstring[i]<127)?search->searchstring[i]:'.';
			
			if (stringinput(output,offsy+3,offsx+38,tmp,19)==KEYENTER)
			{
				search->searchlen=strlen(tmp);
				memcpy(search->searchstring,tmp,19);	
			}
		}
		if (selected==itemnums[2]) search->forwardnotbackward=1;
		if (selected==itemnums[3]) search->forwardnotbackward=0;
		if (selected==itemnums[4]) search->writesearchlog=!search->writesearchlog;
		if (selected==itemnums[5]) 
		{
			stringinput(output,offsy+7,offsx+7,search->writelogfilename,50);
		}
		if (selected==itemnums[6]) search->readsearchlog=!search->readsearchlog;
		if (selected==itemnums[7]) 
		{
			stringinput(output,offsy+10,offsx+7,search->readlogfilename,50);
		}
		if (selected==itemnums[8])
		{
			searchfor(search,buf,cursorpos,1);
			if (search->writesearchlog)
			{
				drawcenterframe(output,14,60,"Found");
				setcolor(output,COLOR_TEXT);
				mvwprintw(output->win,offsy+13,offsx+1,"%lld occurances found",search->occurancesfound);
				getkey((tKeyTab*)output->pKeyTab,1);
			}
		}

	}	
}
tInt8 savedialog(tOutput* output,tBuffer* hBuf)
{
	tInt16	offsx;
	tInt16	offsy;
	tMenu	Menu1;
	tInt8	itemnums[3];
	tInt8	selected;

	offsx=COLS/2-13;
	offsy=LINES/2-2;

	drawcenterframe(output,3,26,"Save changes?");
	setcolor(output,COLOR_TEXT);
	mvwprintw(output->win,offsy+2,offsx+1,"Save %12i byte%s",hBuf->changesnum,(hBuf->changesnum==1)?"?":"s?");
	clearMenu(&Menu1);
	newMenuItem(&Menu1,"Yes",3,1,'Y',0,&itemnums[0]);		
	newMenuItem(&Menu1,"No",3,9,'N',0,&itemnums[1]);
	newMenuItem(&Menu1,"Cancel",3,19,'C',1,&itemnums[2]);
	selected=MenuInteract(output,&Menu1,offsy,offsx);
	if (selected==itemnums[2]) return RETNOK;
	if (selected==itemnums[0])
	{
		if (savechanges(hBuf)!=RETOK)
		{
			drawcenterframe(output,3,22,"ERROR");
			setcolor(output,COLOR_TEXT);
			mvwprintw(output->win,offsy+1,offsx+1,"Could not save\n");
			return	RETNOK;
		}
	}	
	return RETOK;
}
tInt8 correlationmask(tOutput* output,tCorrelation* correlation)
{
	tInt16	offsx;
	tInt16	offsy;
	tMenu	Menu1;
	tInt8	itemnums[10];
	tInt8	selected;
	tInt8	retval=RETOK;
	tBool	done=0;

	offsx=COLS/2-21;
	offsy=LINES/2-3;
	drawcenterframe(output,6,42,"Correlation");
	clearMenu(&Menu1);
	newMenuItem(&Menu1,"best match",1,5,'B',0,&itemnums[0]);
	newMenuItem(&Menu1,"longest match",2,5,'L',0,&itemnums[1]);
	newMenuItem(&Menu1,"minimum difference",3,5,'D',0,&itemnums[2]);
	newMenuItem(&Menu1,"upper diff limit",4,1,'S',0,&itemnums[3]);
	newMenuItem(&Menu1,"Go",5,1,'G',0,&itemnums[4]);
	newMenuItem(&Menu1,"Cancel",5,35,'C',1,&itemnums[5]);
	selected=itemnums[0];
	while (!done)
	{
		setcolor(output,COLOR_BRACKETS);
		mvwprintw(output->win,offsy+1,offsx+1,"( )");
		mvwprintw(output->win,offsy+2,offsx+1,"( )");
		mvwprintw(output->win,offsy+3,offsx+1,"( )");
		mvwprintw(output->win,offsy+4,offsx+22,"[                 ]");
		setcolor(output,COLOR_TEXT);
		switch(correlation->algorithm)
		{
			case CORR_BEST_MATCH:		mvwprintw(output->win,offsy+1,offsx+2,"o");break;
			case CORR_LONGEST_MATCH:	mvwprintw(output->win,offsy+2,offsx+2,"o");break;
			case CORR_MIN_DIFF:		mvwprintw(output->win,offsy+3,offsx+2,"o");break;
		}
		mvwprintw(output->win,offsy+4,offsx+23,"%17lli",correlation->start_mindiff);
		wrefresh(output->win);
		selected=MenuInteract(output,&Menu1,offsy,offsx);
		if (selected==itemnums[0])
		{
			correlation->algorithm=CORR_BEST_MATCH;
		} 
		if (selected==itemnums[1]) 
		{
			correlation->algorithm=CORR_LONGEST_MATCH;
		}
		if (selected==itemnums[2]) 
		{
			correlation->algorithm=CORR_MIN_DIFF;
		} 
		if (selected==itemnums[3]) 
		{
			decinput(output,offsy+4,offsx+22,&correlation->start_mindiff,18);
		}
		if (selected==itemnums[4]) 
		{
			done=1;
			retval=RETOK;
		}
		if (selected==itemnums[5]) {
			done=1;
			retval=RETNOK;
		}
	}
	return retval;
}