Repository navigation
Expand file tree
/
Copy pathcatview.c
More file actions
223 lines (186 loc) · 6.27 KB
/
Copy pathcatview.c
File metadata and controls
223 lines (186 loc) · 6.27 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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include "tyac.h"
#include "catview.h"
#include "colortbl.h"
#include "config_w.h"
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <dos.h>
#include <io.h>
char *CatalogMenu_1[20 * 2]; /* catalog menus - 20 catalogs max in each */
char *CatalogMenu_2[20 * 2];
struct User keyword[3 + 2]; /* array element 0 not used (element 4 used as end-of-array indicator)*/
int BARS_DONE; /* progress bar */
int CATS_TO_SEARCH; /* number of cats to search (excludes underscored) */
int TOTAL_CATALOGS; /* total catalogs (includes underscored) */
struct color_table ct; /* used by DisplayMenuEx function */
extern BOOL Out_Of_Memory;
//*******************************************************************
// The main loop below revolves around the state of the main screen -
// - being ready to type in keywords and pressing enter to search.
// USER_SELECT_CATALOG option shows the catalog selection screen to enable
// the user to re-choose a catalog to search.
// The boolean bNewCatalog is tested each time to check whether the user
// has indicated that a new catalog is to be chosen. On startup, this
// is set to true. Thus the initial screen is catalog selection.
// ******************************************************************
int main() {
int x, bQuit = NO, bNewCatalog = YES;
int nCatChoice = 0;
Catalog *catalog[CAT_MAX];
initialise(catalog);
while (bQuit == NO) {
if (bNewCatalog == YES) {
if ((nCatChoice = Choose_Catalog()) == USER_EXIT) {
bQuit = YES;
break;
} else if (nCatChoice == USER_SELECT_CATALOG)
continue;
else
bNewCatalog = NO;
}
if (catalog[nCatChoice]->bIncompatible) {
Catalog_Incompatible(catalog[nCatChoice]->szName);
bNewCatalog = YES;
continue;
}
Draw_Screen(catalog[nCatChoice]);
switch (Get_Keywords()) {
case USER_DO_SEARCH:
if (keyword[1].length == 0 || keyword[3].length > 1 && keyword[2].length == 0) {
InputError();
} else if (Search_Catalog(catalog, nCatChoice) == 0)
bQuit = YES;
break;
case USER_CLEAR_KEYWORDS:
for (x = 1; x < 4; x++) {
keyword[x].length = 0;
strcpy(keyword[x].text, NULL);
}
break;
case USER_NEW_CAT:
bNewCatalog = YES;
break;
case USER_EXIT:
bQuit = YES;
break;
default:
bQuit = YES;
}
}
CleanUp(catalog);
return (0);
}
void initialise(Catalog **catalog) {
int x;
char exit_keys[] = {ENTER_KEY, ESC_KEY, F1, F3, PAGE_DN, TAB, SHIFT_TAB, UP_ARROW, DN_ARROW};
_setcursortype(_SOLIDCURSOR);
/* initalise User structure */
for (x = 0; x < 5; x++) {
strcpy(keyword[x].text, NULL);
keyword[x].length = 0;
}
/* set keyword-input preferences */
getline(SET_NORMAL, 0, WHITE, BLACK, WHITE, BLACK, 0);
getline(SET_UNDERLINE, 0, WHITE, BLACK, 0, 0, 0);
getline(SET_INS, 0, YELLOW, CYAN, 24, 77, 0);
getline(SET_EXIT_KEYS, 0, 10, 0, 0, 0, exit_keys);
/* call Initialisation functions */
config_Init();
Rename_csvFiles();
Detect_CatalogFiles(catalog);
Get_FileInfo(catalog); /* fill file part of catalog struct (time,date etc.) */
Sort_Catalogs(catalog, TOTAL_CATALOGS);
Prepare_Menu_1(catalog);
Prepare_Menu_2(catalog); /* nothing performed here if 20 or less catalogs */
}
void Draw_Screen(Catalog *catalog) {
int x;
char szUserName[CONFIG_MAX_LEN];
for (x = 0; x < 5; x++) {
memset(keyword[x].text, NULL, 23);
}
clear_screen(BLACK, BLUE);
gotoxy(1, 1);
repeat_char(SPACE, 80, LIGHTGRAY, CYAN);
gotoxy(34, 1);
textcolor(LIGHTCYAN);
textbackground(CYAN);
cprintf("CatView %.*f", VERSION_PRECISION, VERSION);
gotoxy(1, 2);
textcolor(LIGHTGRAY);
textbackground(BLUE);
if (catalog->bSuperSearch == FALSE) /* print catalogue date & size if not super */
{
cprintf("Last Modified: %02u/%02u/%4u", catalog->Date.ft_day,
catalog->Date.ft_month,
catalog->Date.ft_year + 1980);
cprintf("\r\nFile Size : %ld Kb\r\n", catalog->lSize / 1000);
}
if (catalog->lRecords > 0 && !Out_Of_Memory) /* print total records if last search successful */
cprintf("Total Records: %ld", catalog->lRecords);
gotoxy(1, 1);
textcolor(BLACK);
textbackground(CYAN);
cprintf("Catalogue: %s", catalog->szNameOnly);
grid(8, 19, 3, 69, BLACK, BLUE, 2);
box(6, 18, 6, 73, DOUBLE_BOX, FILL_BOX, LIGHTGREEN, GREEN); /* MAIN BOX */
write_string("Keyword 1:", CYAN, BLUE, 10, 10);
write_string("Keyword 2:", CYAN, BLUE, 12, 10);
write_string("Keyword 3:", CYAN, BLUE, 14, 10);
for (x = 0; x < 3; x += 2) /* clear keyword-entry boxes */
{
gotoxy(29, 13 + x);
repeat_char(SPACE, 21, BLACK, BLACK);
}
gotoxy(1, 25);
repeat_char(SPACE, 80, CYAN, CYAN);
write_string("<F1 = ABOUT/CALENDAR> <F3 = QUIT> <Esc = EXIT/NEW CATALOGUE> <PgDn = SEARCH>",
BLUE, CYAN, 24, 0);
write_string("C a t V i e w", LIGHTGREEN, GREEN, 17, 59);
write_string("S y s t e m s", LIGHTGREEN, GREEN, 18, 59);
config_getUserName(szUserName);
write_string(szUserName, LIGHTBLUE, BLUE, 4, 40 - (strlen(szUserName) / 2));
_setcursortype(_SOLIDCURSOR);
}
int Get_Keywords() {
int position = 1;
while (1) {
switch (Process_Input(position)) {
case DN_ARROW :
case TAB_KEY :
case ENTER_KEY:
if (position < 3)
position++;
else
return (USER_DO_SEARCH);
break;
case UP_ARROW:
case SHIFT_TAB:
if (position > 1)
position--;
break;
case F3:
return (QUIT);
case ESC_KEY :
if (!keyword[1].length && !keyword[2].length && !keyword[3].length)
return (USER_NEW_CAT);
else
return (USER_CLEAR_KEYWORDS);
case PAGE_DN :
return (USER_DO_SEARCH);
case F1 :
display_message("about", 0);
return (USER_CLEAR_KEYWORDS);
default :
return (USER_CLEAR_KEYWORDS);
} /* end of switch */
} /* end of while loop */
} /* end of function */
char Process_Input(int pos) {
char exitc;
exitc = getline(GET_ALPHA, 0, 10 + pos + (pos - 2), 28, 0, 21, keyword[pos].text);
keyword[pos].length = strlen(keyword[pos].text);
return (exitc);
}