forked from baranovskiykonstantin/bviplus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
162 lines (141 loc) · 4.65 KB
/
main.c
File metadata and controls
162 lines (141 loc) · 4.65 KB
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
/*************************************************************
*
* File: main.c
* Author: David Kelley
* Description: Program entry point. Contains initialization,
* main program loop, and termination code.
*
* Copyright (C) 2009 David Kelley
*
* This file is part of bviplus.
*
* Bviplus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Bviplus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with bviplus. If not, see <http://www.gnu.org/licenses/>.
*
*************************************************************/
#include <stdio.h>
#include <ncurses.h>
#include <panel.h>
#include <unistd.h> /* usleep */
#include <stdlib.h> /* calloc */
#include <ctype.h> /* isprint */
#include <string.h> /* memset */
#include "virt_file.h"
#include "key_handler.h"
#include "display.h"
#include "app_state.h"
#include "actions.h"
#include "creadline.h"
#include "user_prefs.h"
#define MILISECONDS(x) ((x) * 1000)
#define SECONDS(x) (MILISECONDS(x) * 1000)
int main(int argc, char **argv)
{
int i, c;
file_manager_t *tmp_head;
/* Create a file ring to contain any open file references for this process */
file_ring = vf_create_fm_ring();
/* Fill the file ring with the files the user has listed on the command line */
for (i=1; i<argc; i++)
{
printf("argv[%d] = %s\n", i, argv[i]);
current_file = vf_add_fm_to_ring(file_ring);
if (vf_init(current_file, argv[i]) == FALSE)
{
fprintf(stderr, "Could not open %s\n", argv[i]);
vf_remove_fm_from_ring(file_ring, current_file);
}
}
/* Make sure we have at least one valid open file, otherwise init an empty file */
current_file = vf_get_current_fm_from_ring(file_ring);
if (current_file == NULL) /* no file specified in open */
{
current_file = vf_add_fm_to_ring(file_ring);
if (vf_init(current_file, NULL) == FALSE)
fprintf(stderr, "Empty file failed?\n");
}
/* Initialize macros, yank, search, and comand line history support */
memset(macro_record, 0, sizeof(macro_record_t) * 26);
action_init_yank();
search_init();
ascii_search_hist = new_history();
hex_search_hist = new_history();
cmd_hist = new_history();
file_hist = new_history();
/* Get our ncurses screen ready */
initscr();
keypad(stdscr, TRUE);
scrollok(stdscr, TRUE);
nonl();
//cbreak();
raw(); /* use raw instead of cbreak for alt+<key> support */
noecho();
attrset(A_NORMAL);
start_color(); /* Start color */
use_default_colors();
init_pair(1, COLOR_YELLOW, -1); /* for blob_grouping */
/* Read user rc file and set preferences */
read_rc_file();
reset_display_info();
app_state.quit = FALSE;
/* print any debug here before we make our windows */
//#define SHOW_DEBUG_SCREEN
#ifdef SHOW_DEBUG_SCREEN
printw("COLS = %d\n", COLS);
printw("PRESS q to continue\n");
while ((c = getch()) != 'q')
{
printw("PRESSED KEY = %x\n", c);
refresh();
}
#endif
/* Create the program windows, set up the pannels, and we're off */
create_screen();
/* Print our first screen with hex data */
print_screen(display_info.page_start);
/* Main program loop. We loop here until we are told to quit. */
while (app_state.quit == FALSE)
{
/* Update the status window each keypress so we can always see our current cursor address */
update_status_window();
update_panels();
doupdate();
/* Replace the cursor after updating the screen */
place_cursor(display_info.cursor_addr, CALIGN_NONE, CURSOR_REAL);
/* Get and handle the users next key press */
c = mwgetch(window_list[display_info.cursor_window]);
update_status(NULL);
handle_key(c);
}
/* We're done, start breaking things down */
destroy_screen();
endwin();
free_history(ascii_search_hist);
free_history(hex_search_hist);
free_history(cmd_hist);
free_history(file_hist);
search_cleanup();
action_clean_yank();
tmp_head = vf_get_head_fm_from_ring(file_ring);
current_file = vf_get_head_fm_from_ring(file_ring);
do
{
if (current_file == NULL)
break;
if (current_file->private_data != NULL)
free(current_file->private_data);
current_file = vf_get_next_fm_from_ring(file_ring);
} while(current_file != tmp_head);
vf_destroy_fm_ring(file_ring);
return 0;
}