-
Notifications
You must be signed in to change notification settings - Fork 0
/
kit.c
executable file
·402 lines (311 loc) · 9.16 KB
/
kit.c
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include smgdef
#include smg$routines
#include ints
#include ctype
#include rms
#include starlet
#include "extools.h"
#include "screen.h"
#include "filebrowse.h"
#include "warns.h"
#include "swfile.h"
#include "colours.h"
#define HEADING " Code Kit Description "
#define VHEADING "Code |Description |Units|Number |Extended Description "
void strupr (char *);
extern int TermWidth;
extern int win_depth;
extern int BottomLine;
void *lmalloc (size_t);
#define KITBUFFSIZE 10000
static int new = FALSE;
void print_kit_A ();
void print_kit_B ();
static struct cmndline_params edit_cmndline[] = {
3, NULL, NULL, 0, NULL,
F1, "Edit Recd.", NULL, 0, Edit_Record,
/* F5,"Print Kit",NULL,0,print_kit_B,*/
F9, "Previous", NULL, 0, NULL,
F10, "Next", NULL, 0, NULL
};
void kit_search ();
void
kitsrch (msg, filedef)
struct linedt_msg_rec *msg;
struct filestruct *filedef;
{
kit_search (msg, filedef, 0);
}
static struct cmndline_params index_cmndline[] = {
1, NULL, NULL, 0, NULL,
F1, "Search", NULL, 0, kitsrch
/* F5,"Print Kit",NULL,0,print_kit_A */
};
extern int check_code (char *);
/*
static int check_code(char *test)
{
unsigned int lnth,status;
struct kit_rec kit_buff;
struct kit_key0_rec kit_key;
struct kit_rec *dtr = (struct kit_rec *)kit_file.fileio;
strupr(test);
strcpy (kit_key.kit_code,test);
pad(kit_key.kit_code,PARTKEYLEN);
kit_file.rab.rab$b_krf = 0;
kit_file.rab.rab$l_kbf = (char *)&kit_key;
kit_file.rab.rab$b_ksz = sizeof(kit_key);
kit_file.rab.rab$l_ubf = (char *)kit_file.fileio;
kit_file.rab.rab$w_usz = kit_file.fileiosz;
kit_file.rab.rab$b_rac = RAB$C_KEY;
kit_file.rab.rab$l_rop = RAB$M_NLK|RAB$V_CDK;
rms_status = sys$get(&kit_file.rab);
if (!rmstest(rms_status,3,RMS$_NORMAL,RMS$_RNF,RMS$_OK_ALK)){
warn_user("$GET kit file %s %s %u",rmslookup(rms_status),filterfn(__FILE__),__LINE__);
return(TRUE);
}
if (rmstest(rms_status,2,RMS$_NORMAL,RMS$_OK_ALK)) {
warn_user("That Code is already assigned %s %u",filterfn(__FILE__),__LINE__);
return(FALSE);
}
return(TRUE);
}
*/
int kitsed ();
/* *INDENT-OFF* */
#define KITSCRNLEN 4
#define KITTEXTLN 2 /* Change in report17.c as well as here */
struct scr_params kit_entry_screen[] = {
1,0,"Kit Code :",PROMPTCOL,UNFMT_STRING,kit_buff.kit_code,FIELDCOL,10,check_code,NULL,
2,0,"Description :",PROMPTCOL,UNFMT_STRING|CAPITALIZE,kit_buff.description,FIELDCOL,28,NULL,NULL,
/* 3,0,"Per Foot Price : %7.2f",PROMPTCOL,NUMERIC,&kit_buff.per_foot,FIELDCOL,7,NULL,NULL,*/
6,18,VHEADING,HEADCOL,FREE_TEXT,NULL,FIELDCOL,100,kitsed,NULL,
0,0,"Kit Definition Record",HEADCOL,0,NULL,0,0,NULL,NULL
};
/* *INDENT-ON* */
void
kit_trans (crnt, filedef)
struct List_Element *crnt;
struct filestruct *filedef;
{
struct kit_rec *dtr = (struct kit_rec *) filedef->fileio;
sprintf (crnt->Prompt, " %.*s %-30s ",
PARTKEYLEN, dtr->kit_code, dtr->description);
}
void
kit_search (msg, filedef, frstchr)
struct linedt_msg_rec *msg;
struct filestruct *filedef;
char frstchr;
{
struct kit_key0_rec srch_key;
char srchln[15];
int wch, lnpos;
unsigned int cont = 0, status;
struct rfabuff rfa;
open_window (8, 24, 32, 3, WHITE, border);
exscrprn ("Partial Code", 0, 9, WHITE);
strncpy (srchln, &frstchr, 1);
lnpos = 1;
wch = linedt (srchln, 1, 0, 10, WHITE, &lnpos, &cont, NULL);
close_window ();
strupr (srchln);
exloccur (24, 0);
if (wch != SMG$K_TRM_CTRLZ)
{
strcpy (srch_key.kit_code, srchln);
strupr (srch_key.kit_code);
pad (srch_key.kit_code, PARTKEYLEN);
kit_file.rab.rab$b_krf = 0;
kit_file.rab.rab$l_kbf = (char *) &srch_key;
kit_file.rab.rab$b_ksz = sizeof (srch_key);
kit_file.rab.rab$b_rac = RAB$C_KEY;
kit_file.rab.rab$l_rop = RAB$M_NLK | RAB$M_EQNXT;
rms_status = sys$find (&kit_file.rab);
if (!rmstest (rms_status, 3, RMS$_NORMAL, RMS$_RNF, RMS$_OK_RLK))
{
warn_user ("$GET kit file %s %s %u", rmslookup (rms_status),
filterfn (__FILE__), __LINE__);
return;
}
if (rms_status == RMS$_RNF)
warn_user ("$FIND RMS$_RNF Record Not Found %s %u",
filterfn (__FILE__), __LINE__);
else
{
rfa_copy (&rfa, (struct rfabuff *) &filedef->rab.rab$w_rfa);
ReadMiddleOut (&rfa, filedef);
}
}
}
void
kit_defaults ()
{
memset (&kit_buff, 0, sizeof (kit_buff));
new = TRUE;
}
void
Set_Kit_List_Key (void)
{
struct kit_rec *dtr = (struct kit_rec *) kit_file.fileio;
memcpy (kit_listkey.kit_code, dtr->kit_code, PARTKEYLEN);
}
void
kit_pad_record (void)
{
struct kit_rec *dtr = (struct kit_rec *) kit_file.fileio;
pad (dtr->kit_code, PARTKEYLEN);
}
void
kit_unpad_record (void)
{
struct kit_rec *dtr = (struct kit_rec *) kit_file.fileio;
unpad (dtr->kit_code, PARTKEYLEN);
}
int
count_lines (text_start)
struct line_rec **text_start;
{
struct line_rec *temp;
int count = 0;
if ((*text_start) != NULL)
{
while ((*text_start)->last != NULL)
(*text_start) = (*text_start)->last;
for (temp = (*text_start); temp != NULL; count++)
temp = temp->next;
}
return (count);
}
void
disassemble (block, scrl_consts, v_lnth, v_ptr, reclen)
char *block;
struct filestruct *scrl_consts;
int v_lnth;
struct line_rec **v_ptr;
uint16 reclen;
{
struct line_rec *crnt_list = NULL, *temp_list = NULL, *first_line = NULL;
unsigned int main_lnth, status;
main_lnth = scrl_consts->recsize;
if (block != NULL)
{
memcpy (scrl_consts->recbuff, block, scrl_consts->recsize);
while (main_lnth < reclen)
{
if ((crnt_list = lmalloc (v_lnth)) != NULL)
{
memcpy (crnt_list->storage, block + main_lnth, v_lnth);
main_lnth += v_lnth;
if ((*v_ptr) == NULL)
{
first_line = (*v_ptr) = crnt_list;
}
else
{
(*v_ptr)->next = crnt_list;
crnt_list->last = (*v_ptr);
(*v_ptr) = crnt_list;
}
}
else
{
printf ("memory allocaton error %s %u\n", filterfn (__FILE__),
__LINE__);
exit;
}
}
(*v_ptr) = first_line;
}
}
int
assemble (block, scrl_consts, v_lnth, v_ptr)
char **block;
struct filestruct *scrl_consts;
int v_lnth;
struct line_rec **v_ptr;
{
struct line_rec *crnt_line;
unsigned int mainsz, textsz, offset = 0, counter = 0;
mainsz = scrl_consts->recsize;
textsz = count_lines (v_ptr);
crnt_line = (*v_ptr);
textsz *= v_lnth;
memcpy ((*block), scrl_consts->fileio, mainsz);
while (crnt_line != NULL)
{
memcpy (((*block) + mainsz + offset), crnt_line->storage, v_lnth);
offset += v_lnth;
crnt_line = crnt_line->next;
counter++;
}
return (counter);
}
/* Copy line editor buffer into Variable section of record after editing */
int
kit_unload_editor_buffer (curs, filedef)
struct line_rec *curs;
struct filestruct *filedef;
{
int lines = 0;
struct kit_rec *dtr = (struct kit_rec *) filedef->fileio;
while (curs != NULL && curs->last != NULL)
curs = curs->last;
lines =
assemble (&filedef->fileio, filedef, sizeof (struct kit_part_rec), &curs);
dtr->reclen = sizeof (kit_buff) + (lines * sizeof (struct kit_part_rec));
return (dtr->reclen);
}
void
kit_load_editor_buffer (ptr, filedef)
struct line_rec **ptr;
struct filestruct *filedef;
{
struct kit_rec *dtr = (struct kit_rec *) filedef->fileio;
disassemble (filedef->fileio, filedef, sizeof (struct kit_part_rec), ptr,
dtr->reclen);
while ((*ptr) != NULL && (*ptr)->last != NULL)
(*ptr) = (*ptr)->last;
}
void
kit_filedef_init (void)
{
if ((kit_diskio_buff = malloc (KITBUFFSIZE)) == NULL)
{
printf (" Could Not Allocate disk buffer memory\n");
exit;
}
kit_file.fileio = (char *) kit_diskio_buff;
kit_file.fileiosz = KITBUFFSIZE;
kit_file.recbuff = (char *) &kit_buff;
kit_file.recsize = sizeof kit_buff;
kit_file.setprompt = kit_trans;
kit_file.entry_screen = kit_entry_screen;
kit_file.entry_length = KITSCRNLEN;
kit_file.entry_comment = KITTEXTLN;
kit_file.mainsrch = kit_search;
kit_file.read_cmndline = edit_cmndline;
kit_file.list_cmndline = index_cmndline;
kit_file.listkey = (char *) &kit_listkey;
kit_file.listkeysz = sizeof kit_listkey;
kit_file.fwrdkeyid = 0;
kit_file.revrkeyid = 1;
kit_file.setlistkey = Set_Kit_List_Key;
kit_file.padrecord = kit_pad_record;
kit_file.unpadrecord = kit_unpad_record;
kit_file.loadvarbuff = kit_load_editor_buffer;
kit_file.dumpvarbuff = kit_unload_editor_buffer;
}
void
fork_kit_file (struct scrllst_msg_rec *msg)
{
spawn_scroll_window (&kit_file, 10, 54);
HeadLine ("%s (%s)", left, HEADING, filterfn (kit_file.filename));
File_Browse (&kit_file, normal);
close_window ();
win_depth--;
}