Repository navigation
Expand file tree
/
Copy pathresults.c
More file actions
212 lines (182 loc) · 6.6 KB
/
Copy pathresults.c
File metadata and controls
212 lines (182 loc) · 6.6 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
#include "catview.h"
#include "tyac.h"
#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern int CATS_TO_SEARCH;
extern BOOL Out_Of_Memory;
int Browse_Results(Catalog *catalog) {
char key_press = PAGE_DN;
int page = 1, RecsPerPage = 22 / catalog->nLines;
int message_bkg = LIGHTGREEN;
if (Out_Of_Memory) {
StatusBar("DOS memory limit exceeded - search discontinued", YELLOW + BLINK, RED);
getkbhit();
}
if (catalog->lMatches == 0) {
Print_NoMatches(catalog);
getkbhit();
} else
do {
message_bkg = Print_StatusMessage(page, catalog);
Print_ScreenInfo(catalog, page, message_bkg);
/* check key_press here to cater for initial printing of results without refreshing */
if (key_press != PAGE_DN && key_press != PAGE_UP && key_press != SPACE)
return (P_NO_PRINT_RESULTS);
/* get input and decide which way to turn page */
if (!(key_press = getch()))
key_press = getch();
/* space was used in version 2.3 and below */
if (key_press == PAGE_DN || key_press == SPACE) {
/* clear most of screen*/
box(2, 23, 0, 79, BLANK_BOX, FILL_BOX, BLUE, BLUE);
if (message_bkg == LIGHTGREEN) /* ie if search is not complete (isn't flashing)*/
page++;
else
page = 1;
Display_Page(page, catalog);
} else if (key_press == PAGE_UP) {
/* clear most of screen*/
box(2, 23, 0, 79, BLANK_BOX, FILL_BOX, BLUE, BLUE);
if (page > 1) /* ie if search is not complete (isn't flashing */
page--;
else {
page = ((int)catalog->lMatches / RecsPerPage);
if (catalog->lMatches % RecsPerPage)
page++;
} /* calculate last page */
Display_Page(page, catalog);
}
} while (key_press == PAGE_DN || key_press == PAGE_UP || key_press == SPACE);
textcolor(BLACK);
return (toupper(key_press) == 'P' || toupper(key_press) == 'S') ? P_PRINT_RESULTS : P_NO_PRINT_RESULTS;
}
/******************************* USE_RECORD_ARRAY *****************************/
void Display_Page(int page, Catalog *catalog) {
int x, y, row;
int RecsPerPage = 22 / catalog->nLines;
Record *record;
if (page)
page--; /* adjust page for starting at '1' based linked list */
record = Find_Record((page * RecsPerPage) + 1);
for (x = (page * RecsPerPage) + 1, row = 3, y = 0; y < RecsPerPage && x <= catalog->lMatches;
x++, y++, row += catalog->nLines) {
gotoxy(1, row);
if (catalog->bSuperSearch) {
write_string(record->szOwner, LIGHTGRAY, BLUE, row - 1, 0);
gotoxy(strlen(record->szOwner) - 3, row);
repeat_char(176, 80 - (strlen(record->szOwner) - 4), LIGHTGRAY, BLUE);
} else
repeat_char(176, 80, LIGHTGRAY, BLUE);
textcolor(CYAN);
textbackground(BLUE);
gotoxy(38, row);
/* print record number */
cprintf("%ld", record->lNumber);
Write_Record(record->szRecord, row);
record = record->next;
if (!record)
return;
}
gotoxy(1, row);
repeat_char(176, 80, LIGHTGRAY, BLUE);
}
void Draw_ResultsScreen(int catCount, int SuperSearch) {
box(0, 23, 0, 79, BLANK_BOX, FILL_BOX, BLUE, BLUE);
gotoxy(1, 1);
repeat_char(32, 80, LIGHTGRAY, LIGHTGRAY);
write_string("S E A R C H R E S U L T S", BLACK, LIGHTGRAY, 0, 28);
write_string("Catalogue# Item Description ",
WHITE, GREEN, 1, 0);
write_string("Press 'P' for print/save options", LIGHTGREEN, GREEN, 1, 48);
if (SuperSearch) {
gotoxy(1, 1);
/* reprint section just rubbed out */
textcolor(BLACK);
textbackground(LIGHTGRAY);
cprintf("Searching %d of %d", catCount, CATS_TO_SEARCH);
/* reset colours for bar draw */
textcolor(WHITE);
textbackground(BLACK);
}
}
/* currentcat is only different to chosencat in the event of a super search */
void PrePrint_Record(Catalog *currentcat, Catalog *chosencat, int catcount) {
static int CurrentRow = 3;
Record *record = Find_Record(chosencat->lMatches);
if (chosencat->lMatches == 1) {
Draw_ResultsScreen(catcount, chosencat->bSuperSearch);
CurrentRow = 3;
}
gotoxy(1, CurrentRow);
if (chosencat->bSuperSearch) {
write_string(currentcat->szName, LIGHTGRAY, BLUE, CurrentRow - 1, 0);
gotoxy(strlen(currentcat->szName) - 3, CurrentRow);
repeat_char(176, 80 - (strlen(currentcat->szName) - 4), LIGHTGRAY, BLUE);
} else
repeat_char(176, 80, LIGHTGRAY, BLUE);
textcolor(CYAN);
textbackground(BLUE);
gotoxy(38, CurrentRow); /* print record number */
cprintf("%ld", chosencat->lMatches);
Write_Record(record->szRecord, CurrentRow);
CurrentRow += (chosencat->bSuperSearch) ? SUPER_LINES : chosencat->nLines;
textcolor(WHITE);
textbackground(BLACK); /* must reset colours for first 'prograss-bar' draw */
}
void Print_NoMatches(Catalog *catalog) {
textcolor(BLACK);
textbackground(RED);
/* clear "searching..." box */
box(7, 9, 28, 48, BLANK_BOX, FILL_BOX, GREEN, GREEN);
box(10, 14, 10, 27, BLANK_BOX, FILL_BOX, GREEN, GREEN);
box(10, 14, 28, 48, BLANK_BOX, FILL_BOX, RED, RED);
write_string("NO MATCHES FOUND", WHITE + BLINK, RED, 12, 30);
gotoxy(1, 25);
repeat_char(SPACE, 80, RED, RED);
gotoxy(1, 25);
cprintf("Items Searched=%ld", catalog->lRecords);
if (catalog->bSuperSearch)
write_string("All catalogs searched", BLACK, LIGHTGRAY, 0, 0);
}
int Print_StatusMessage(int page_num, Catalog *catalog) {
/* decide message to print according to number of matches/pages remaining */
char message[81] = "\0";
int Message_bg = 0;
int RecsPerPage = 22 / catalog->nLines;
if (page_num * RecsPerPage < catalog->lMatches) {
strcpy(message, "Hit <Page Down> for more matches");
Message_bg = LIGHTGREEN;
} else if (page_num * RecsPerPage >= catalog->lMatches) {
if (Out_Of_Memory) {
strcpy(message, "SEARCH DISCONTINUED");
Message_bg = LIGHTRED;
} else {
strcpy(message, "search complete");
Message_bg = GREEN;
}
}
StatusBar(message, BLACK, Message_bg); /* print message at bottom of screen */
return (Message_bg);
}
void Print_ScreenInfo(Catalog *catalog, int PageNum, int Message_bg) {
/* print screen information */
gotoxy(1, 1);
textcolor(BLACK);
textbackground(CYAN);
write_string(" ", WHITE, LIGHTGRAY, 0, 0); /* clear space */
if (catalog->bSuperSearch)
cprintf("%s", "ALL catalogs");
else
cprintf("%s", catalog->szNameOnly);
textbackground(LIGHTGRAY);
gotoxy(71, 1);
cprintf("Page %-4d ", PageNum); /* print page number top-right */
textbackground(Message_bg);
gotoxy(66, 25);
cprintf("Matches=%ld", catalog->lMatches);
gotoxy(1, 25);
cprintf("Items Searched=%ld", catalog->lRecords);
}