Repository navigation
Expand file tree
/
Copy pathprint_options.c
More file actions
203 lines (171 loc) · 5.97 KB
/
Copy pathprint_options.c
File metadata and controls
203 lines (171 loc) · 5.97 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
/******************************************************************************
* Filename: print_options.c
* Author : Peter van der Woude
* Program : CatView
* Purpose : print/save option routines
******************************************************************************/
#include "catview.h"
#include "colortbl.h"
#include "config_w.h"
#include "tyac.h"
#include <conio.h>
#include <dir.h> /* dircwd() and MAXPATH */
#include <dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern struct color_table ct;
extern struct User keyword[];
void AppendMenu_Main(const char *, char *);
void Get_PrintOption(Catalog *catalog) {
char *buffer = NULL, ChangesMessage[255];
char menu_ExitKeys[] = {ENTER_KEY, ESC_KEY};
char *print_options[] = {" Print to PRINTER ", "pP",
" Save to FILE ", "sS",
" Append to FILE ", "aA",
" Manipulate Prices ", "mM",
" E(x)it ", "xX"};
int action, MenuSelection, PricesChanged;
ct.abar_fcol = LIGHTBLUE;
ct.abar_bcol = CYAN;
ct.menu_high_fcol = WHITE;
ct.menu_high_bcol = MAGENTA;
ct.menu_fcol = WHITE;
ct.menu_bcol = CYAN;
StatusBar(" ", LIGHTGRAY, GREEN);
/* clear bottom (row status bar) */
buffer = save_screen_area(9, 16, 26, 51);
action = display_menu(10, 30, DOUBLE_BOX, print_options, 4 * 2,
menu_ExitKeys, &MenuSelection, NO_LR_ARROW, SHADOW);
if (action == ESC_KEY)
MenuSelection = QUIT;
switch (MenuSelection) {
case P_OPT_PRINTER:
if (Printer_Ready())
Results_to_Printer();
else {
StatusBar("Printer (LPT1) out of paper or not turned on", YELLOW, LIGHTRED);
getkbhit();
}
break;
case P_OPT_FILE:
Results_to_File(catalog, P_OPT_FILE);
break;
case P_OPT_FILE_APPEND:
Results_to_File(catalog, P_OPT_FILE_APPEND);
break;
case P_OPT_MANIPULATE_PRICES:
PricesChanged = Manipulate_Prices();
if (PricesChanged >= MP_CHANGE_DONE) {
sprintf(ChangesMessage, " %d price code%s detected.", PricesChanged,
(PricesChanged > 1) ? "s" : "");
StatusBar(ChangesMessage, WHITE, LIGHTMAGENTA);
getkbhit();
} else if (PricesChanged == 0) {
StatusBar("NO PRICES DETECTED", YELLOW, LIGHTRED);
getkbhit();
}
/* else do nothing (MP_CHANGE_QUIT) Price change aborted */
break;
case QUIT:
default:
break;
}
restore_screen_area(buffer);
// refresh the current page information incase prices changes have been made
Display_Page(1, catalog);
}
void Results_to_File(Catalog *catalog, int MethodToFile) {
char szFilename[13], ModeSaved[80];
char ExitKey = 0;
int InvalidFilename = FALSE, x;
struct time t;
struct date d;
FILE *ResultsStream;
Record *record;
char szSavePath[CONFIG_MAX_LEN], szUserName[CONFIG_MAX_LEN];
gettime(&t);
getdate(&d);
config_getUserName(szUserName);
config_getSaveDir(szSavePath);
mkdir(szSavePath);
do {
if (ExitKey == ESC_KEY) {
return;
}
if (MethodToFile == P_OPT_FILE_APPEND) {
write_string("Directory: ", BLACK, GREEN, 24, 0);
write_string(szSavePath, BLACK, GREEN, 24, 11);
box(9, 14, 28, 50, BLANK_BOX, FILL_BOX, GREEN, GREEN);
AppendMenu_Main(szSavePath, szFilename);
if (stricmp(szFilename, "Empty") == 0) {
StatusBar("No text files to append to in [SAVE_DIR] directory - press any key",
YELLOW, LIGHTRED);
getkbhit();
return;
}
strcat(szSavePath, "\\");
strcat(szSavePath, szFilename);
if ((ResultsStream = fopen(szSavePath, "a")) == NULL) {
InvalidFilename = TRUE;
ExitKey = ESC_KEY;
} else {
strcpy(ModeSaved, "Results appended");
InvalidFilename = FALSE;
}
}
// write to file - delete if exists
else {
Display_toFileScreen(szSavePath, InvalidFilename);
memset(szFilename, NULL, 13);
_setcursortype(_SOLIDCURSOR);
ExitKey = getline(GET_ALPHA, 0, 11, 35, 0, 8, szFilename);
_setcursortype(_NOCURSOR);
if (szFilename[0] == NULL) {
StatusBar("No filename entered... try again or press 'Esc' to quit", YELLOW, LIGHTRED);
InvalidFilename = TRUE;
continue;
} else { /* concatenate extension */
strcat(szFilename, ".txt");
InvalidFilename = FALSE;
}
strcat(szSavePath, "\\");
strcat(szSavePath, szFilename);
if ((ResultsStream = fopen(szSavePath, "w")) == NULL) {
StatusBar("Invalid filename or (DOS) path. Try again or press 'Esc' to quit", YELLOW, LIGHTRED);
InvalidFilename = TRUE;
} else {
strcpy(ModeSaved, "Results saved");
InvalidFilename = FALSE;
fprintf(ResultsStream, "%s - Selective Listing", szUserName);
/* write time statistics to file */
fprintf(ResultsStream, " %02d/%02d/%02d", d.da_day, d.da_mon, d.da_year);
fprintf(ResultsStream, " - %02d:%02d:%02d", t.ti_hour, t.ti_min, t.ti_sec);
} /* print licensed user only if new file is being created */
}
} while (InvalidFilename);
fprintf(ResultsStream, "\n\nCatalogue: %s", catalog->szNameOnly);
fprintf(ResultsStream, "\nKeyword/s: ");
for (x = 1; x <= 3; x++)
fprintf(ResultsStream, "%s ", keyword[x].text);
fprintf(ResultsStream, "\n\n");
/* write records to file */
for (record = Find_Record(1); record != NULL; record = record->next)
fprintf(ResultsStream, "%s", record->szRecord);
fclose(ResultsStream);
StatusBar(ModeSaved, WHITE, LIGHTMAGENTA);
getkbhit();
}
void Display_toFileScreen(char *quoteDir, BOOL DisplayDir) {
/* erase print options */
box(10, 13, 30, 49, BLANK_BOX, FILL_BOX, LIGHTBLUE, CYAN);
write_string("Save file as...", LIGHTBLUE, CYAN, 9, 32);
write_string("do not type extension", BLUE, CYAN, 12, 29);
write_string("(\".txt\" appended)", BLUE, CYAN, 13, 30);
/* if no error messages need to be kept */
if (!DisplayDir) {
write_string("Directory: ", BLACK, GREEN, 24, 0);
/* display current dir info */
write_string(quoteDir, BLACK, GREEN, 24, 11);
}
}