-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPUMS.C
executable file
·2041 lines (1717 loc) · 62.2 KB
/
PUMS.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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* pums.c by I. Baumel 11/09/89
calling sequence:
pums
Pums is the main menu and control program for the Prodigy Upload
Management Station. It will enable access to the major system
functions and introduce some consistency and qc checks. The final
outcome should be an easily controled PUMS and error free object
sets for the TPF.
- added OPTION TO NOT ZIP PRODUCT 7/23 NEWMAN
- added WARNING AND EXIT FOR INVALID NO ZIP OPTION 7/25 NEWMAN
- changed isin = atoi(sing) to isin = snn to fix lost sing data 7/30 newman
- added logic to intercept choosing sinn = 0 on replace option 7/30
- ADDED CONTRACT LOGIC TO CONTROL.TXT 7/30
- added option to not virus scan 7/31
- added option to accept input from hard drive 7/31
- added option to set default input drive and output path 9/4
- added option to show default input/output drive on header 9/5
- fixed subdirectory problem - set max_adir to 30 9/6
- added logic if output directory alredy exists 9/18
- added auto calculation of object size 9/19
- changed menu layout (removed virus scan and show directory) 9/24
- modified messages for insert floppy in case of hard drive 9/24
LAST UPDATED: 9/24/91 VER 2.3.3
*/
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <io.h>
#include <stdlib.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <ctype.h>
#include <dos.h>
#include <setjmp.h>
#include <time.h>
#include <bios.h>
#include <errno.h>
/* general defaults */
#define VIRUS_SCAN_SW FALSE /* change to TRUE for production*/
#define DEFAULT_DRIVE "A" /* default diskette drive */
#define DEFAULT_PATH "A:\\UPDATE" /*default output path */
#define DEFAULT_AUDIT_SW 'N'
#define MAX_ID 4 /* max chars in CSCS id */
#define MAX_DIR 4 /* max chars in CSCS dirname */
#define MAX_SINN 4 /* max chars in SINn */
#define MAX_ADIR 30 /* max chars in path name */
#define MAX_APP_NAME 25 /* max chars in application name*/
#define MAX_FILEN 50 /* max length of file name */
#define MAX_SYS_BUFF 100 /* buffer to create system calls*/
#define MAX_AUDIT 20000 /* audit trail file big size */
#define CHOP_MAX 32000 /* maximum allowable chop size */
#define ITEM_SIZE 109 /* entry length in FF menu file */
#define REP_LINES 20 /* report lines per page */
#define MAX_LINES 9 /* directory lines per screen */
#define MAX_BUFF 500
#define MAX_PASSWD 33 /* any large number */
#define TRUE 1
#define FALSE 0
#define YES 'Y'
#define NO 'N'
/* CONTROL.TXT file related definitions */
#define KW_SEP ':' /* key word seperator in CONTROL.TXT */
#define MAX_TITLE 20 /* max length of title pieces */
#define MAX_VDATE 8 /* max length of version date */
#define MAX_VERSN 8 /* max length of version */
#define MAX_ZIPFN 12 /* max length of zip file name */
#define MAX_FILE 12 /* max length of filename */
/* special characters definitions */
#define BELL '\a' /* bell character */
#define BS '\b' /* backspace character */
#define CR '\r' /* carriage return character */
#define ESC '\x1B' /* escape character */
/* values for load_sw */
#define NEW TRUE
#define OLD FALSE
/* values for load_show_sw */
#define LOAD 1
#define LOCK 2
#define SHOW 3
/* defaults for PUMS parameters */
#define CHOP_SIZE 876 /* block size for zipfile chops */
#define LINES_SCREEN 9 /* description lines per screen */
#define CHARS_LINE 37 /* description chars per line */
#define ENTRIES_SCREEN 4 /* selection menu entries per screen*/
char upload_txt[]="UPLOAD.LST", upload_old[]="UPLOAD.OLD";
char config_txt[]="PUMSETUP.CFG", passwd_txt[]="terces";
char locked_txt[]="LOCKOUT.TXT",audit_txt[]="PUMSAUDT.TXT";
char control_txt[]="CONTROL.TXT", describe_txt[]="DESCRIBE.TXT";
char applctrl_txt[]="APPLCTRL.TXT", prodlzip_txt[]="PRODLZIP.LST";
char backup_txt[]="call pumsbup"; /* make sure that pumsbup.bat is OK*/
char buffer[MAX_BUFF], buff[ITEM_SIZE+1], dirname[MAX_FILEN];
char control[MAX_FILEN], describe[MAX_FILEN], locked[MAX_FILEN];
char title1[MAX_TITLE+1], title2[MAX_TITLE+1], vdate[MAX_VDATE+1];
char version[MAX_VERSN+1], zipfile[MAX_ZIPFN+1], data_size[7];
char zipind[2], zipfile_hold[12];
char CATEGORY[14]; /* category is contract(9) space(1) item(4) */
char save_ctrl[MAX_FILEN], drv[]=DEFAULT_DRIVE, ndrv[2], sel;
char out_path[24]=DEFAULT_PATH, nout_path[24];
char app_name[MAX_APP_NAME+1], app_code[MAX_ID*2+1];
char ch, id[MAX_ID+1], applctrl[MAX_FILEN], dir[MAX_DIR+1], adir[MAX_ADIR+1];
char ddir[MAX_ADIR+1], filename[MAX_FILEN], oldfname[MAX_FILEN];
char sys_buf[MAX_SYS_BUFF];
char sin_control[MAX_FILEN], sinn[MAX_SINN+1], ssin[MAX_SINN+1];
char menu[MAX_FILEN], sin_dir[MAX_FILEN], file_name[MAX_FILEN];
char app_change_sw=FALSE, show_titles=FALSE;
char sss[MAX_SINN+1], sing[6], fora[MAX_FILEN], dort[MAX_FILEN];
char lsw, operator[12];
char audit_trail_sw=DEFAULT_AUDIT_SW;
unsigned chop_size=CHOP_SIZE;
int lines_screen=LINES_SCREEN, chars_line=CHARS_LINE, entries_screen=ENTRIES_SCREEN;
int title1_l, title2_l, zipfile_l, price_l, category_l, catnum_l;
int des, zip, snn, show_lines;
int entries, isin, sini=0, bad_ctrl, load_sw, load_show_sw, echo_sw, full_sw, num_sw, inp_sw_ok;
int title1_sw, vdate_sw, version_sw, zipfile_sw, file_sw;
int zipind_sw, zip_file_cnt, category_sw;
int dctr, i, j, k, r;
time_t ibtm;
long ll, fl, offset;
FILE *logf, *mnu, *prt, *ctrl, *sctrl, *desc, *zlst, *adt, *cfg, *f, *t;
struct diskinfo_t disk_info;
struct stat stat_buf;
struct find_t buf_dir; /* scan directory buf */
jmp_buf env_buf; /* buffer for ESC processing */
main(argc, argv)
char *argv[];
int argc;
{
setjmp(env_buf); /* save point to be ESCaped to */
echo_sw=TRUE;
open_config(); /* open control parameter file */
system("cls"); /* start with clean screen */
no_applic(); /* no application selected */
open_audit(); /* open audit file, check size */
sel='0'; /* signal PUMS entry */
audit(0); /* report audit */
while(TRUE)
{
setjmp(env_buf); /* save point to be ESCaped to */
full_sw=num_sw=FALSE; /* turn off special requests */
echo_sw=TRUE;
show_menu(); /* show main menu */
sel=ch; /* save user selection */
switch(sel) /* switch based on selection */
{
case '1':
select_id();
break;
case '2':
add_new();
break;
case '3':
upd_old();
break;
case '4':
mnu_maker();
break;
case '5':
obj_to_tpf();
break;
case 'D':
select_drive();
break;
case 'S':
list_info();
break;
case 'M':
print_info();
break;
case 'B':
backup();
break;
case 'L':
lock_unlock();
break;
case 'T':
print_audit();
break;
case 'P':
psetup();
break;
case 'X':
leave_now(); /* finish off */
exit(0);
default:
bell();
break;
}
}
return(0); /* exit now */
}
show_menu()
{
screen_head(); /* show screen header */
printf("\t\t1. SELECT client\n");
printf("\t\t2. ADD NEW Download Package \n");
printf("\t\t3. UPDATE EXISTING download Package\n");
printf("\t\t4. CREATE menus \n");
printf("\t\t5. COPY objects for Delivery to TPF\n");
printf("\n");
printf(" D. Select input/output Drive\tL. Lock / Unlock Existing Package\n");
printf(" S. Show package info by SINN\tT. Print / Delete Audit Trail\n");
printf(" M. Print Selection Menu Report\tP. PUMS Control Setup\n");
printf(" B. Backup PUMS Data Base\t\tX. Exit this program\n");
printf("\n");
printf("\t\tEnter Selection: ");
full_sw=TRUE; /* insist on non empty response */
read_kb(&ch, 1); /* get user selection */
ch=toupper(ch); /* make upper case */
return(0);
}
select_id() /* select application ID */
{
if(app_change_sw) /* check current app open/upd */
{
bell(); /* yes */
err_msg("Current Application Changed. Please Recreate Selection Menus.");
return(0);
}
if(show_cs_dirs()) return(-1); /* show existing app id */
if(strlen(buffer) == 0) /* no selection yet */
{
ask_select_app(0); /* ask select last page */
if(strlen(buffer) == 0) return(0);
}
strcpy(id, buffer); /* copy new id */
strupr(id); /* make upper case */
strcpy(dir, id); /* make CSCS dirname */
applctrl_name(); /* make applctrl name */
i=stat(dir, &stat_buf); /* check dir exists */
if (i == 0) open_id(); /* directory exists */
else make_id(); /* does not */
return(0);
}
open_id() /* open existing application */
{
open_log("r+"); /* open applctrl rd/wr */
fscanf(logf, "%d %25c %s", &sini, app_name, app_code); /* get sini, app_name, app_code */
app_name[MAX_APP_NAME]=0; /* terminate name string*/
audit(1); /* audit report */
return(0);
}
applctrl_name() /* create applctrl.txt name */
{
strcpy(applctrl, dir); /* make CSCS */
strcat(applctrl, "\\"); /* make CSCS\ */
strcat(applctrl, applctrl_txt); /* make CSCS\APPLCTRL.TXT*/
return(0);
}
control_name() /* create control.txt name */
{
sprintf(sss, "%04.4d", snn);
strcpy(control, dir); /* make CSCS */
strcat(control, "\\"); /* make CSCS\ */
strcat(control, dir); /* make CSCS\CSCS */
strcat(control, sss); /* make CSCS\CSCSSINn */
strcat(control, "\\"); /* make CSCS\CSCSSINn\ */
strcpy(locked, control); /* copy to locked */
strcat(control, control_txt); /* add CONTROL.TXT */
strcat(locked, locked_txt); /* add locked.TXT */
return(0);
}
make_id() /* create new application dir */
{
screen_head();
printf("\n\tApplication %s does not exist. Create it? (Y/N): ", id);
read_kb(&ch, 1);
if(toupper(ch) != 'Y')
{
no_applic(); /* deselct application */
return(0);
}
printf("\n\n\tEnter Application Name: ");
read_kb(app_name, MAX_APP_NAME); /* read name for applic */
inp_sw_ok=FALSE; /* force first time */
while(!inp_sw_ok)
{
inp_sw_ok=TRUE; /* assume input OK */
printf("\n\tEnter CSCS as 4 chars, 8 HEX digits or <ENTER> to use %s: ", id);
read_kb(buffer, 2*MAX_ID); /* read code for applic */
if(strlen(buffer) == 0) strcpy(app_code, id);
else
if(strlen(buffer) == MAX_ID)
{
strcpy(app_code, buffer);
strupr(app_code);
}
else
if(strlen(buffer) == 2*MAX_ID)
{
for(i=0; i<2*MAX_ID; i++)
{
if(isxdigit(buffer[i]))
{
app_code[i]=toupper(buffer[i]); /* copy char */
continue;
}
else
{
bell();
err_msg("HEX digits are 0-9 and A-F only.");
inp_sw_ok=FALSE; /* set sw NOK */
break; /* stop loop */
}
}
app_code[i]='\0'; /* terminate */
}
else
inp_sw_ok=FALSE; /* must be 0, 4 or 8 */
}
printf("\n\n\tCreate NEW Application with:\n");
printf("\n\t\tApplication ID : %s", id);
printf("\n\t\tApplication Name: %s", app_name);
printf("\n\t\tApplication CSCS: %s\n", app_code);
msg_get("Confirm (Y/N): ");
if(ch != 'Y')
{
no_applic(0); /* deselct application */
return(0);
}
if(-1 == (i=mkdir(dir))) /* try make directory */
{
perror(""); /* show system error msg*/
err_msg("Unable to create Application Directory.");
exit(-1);
}
open_log("w+"); /* open applctrl wr/rd */
sini=0; /* initialize sini ctr */
update_log(); /* update applctrl */
audit(2); /* audit report */
return(0);
}
no_applic() /* deselect application id */
{
strcpy(id, ""); /* no applic selected */
sini=0; /* no packages */
app_change_sw=FALSE; /* no changes were made */
strcpy(app_name, "No Application Selected");
return(0);
}
leave_now() /* finish PUMS process */
{
if(app_change_sw) /* check app open/upd */
{
bell(); /* yes */
printf("\n\tCURRENT APPLICATION CHANGED BUT NEW MENU WAS NOT CREATED");
printf("\n\tARE YOU SURE YOU WANT TO LEAVE. ENTER (Y/N): ");
read_kb(&ch, 1);
if(toupper(ch) != 'Y') longjmp(env_buf, 1); /* RETURN TO MENU */
}
system("cls"); /* clear screen */
audit(0); /* audit report */
fclose(adt);
return(0);
}
read_kb(buf, n) /* get string from KB length n */
char *buf;
int n;
{
int i=0;
char c;
if(echo_sw)
{
for(i=0; i<n; i++) putchar('_');/* draw undelines */
for(i=0; i<n; i++) putchar(BS); /* reposition to start */
}
for(i=0; i<=n; ) /* loop length and CR */
{
get_one_key(&c); /* get next key */
if (c == BS && i>0) /* is it a Back Space */
{
if(echo_sw)
{
putchar(BS); /* backspace on screen */
putchar('_'); /* prompt char */
putchar(BS); /* reposition */
}
i--; /* remove last char */
continue;
}
if(i == n && c != CR) /* should CR at length */
{
putchar(BELL); /* insist on CR at end */
continue;
}
if(c == CR && (i == n || (!full_sw))) /* ENTER key */
{
buf[i]=0; /* terminate string */
break;
}
if( (num_sw && isdigit(c)) || (!num_sw && isprint(c)) ) /* OK char */
{
if(echo_sw) putchar(c); /* echo back char */
buf[i++]=c; /* store char in buffer */
continue; /* next char */
}
putchar(BELL); /* tell him bad */
}
full_sw=num_sw=FALSE; /* turn off special req */
return(0);
}
get_one_key(c) /* get one key press from KB */
char *c;
{
*c=getch(); /* get next char from KB*/
if(*c == ESC) longjmp(env_buf, 1); /* forget all, goto menu*/
return(0);
}
add_new() /* add new down load package */
{
load_sw=NEW; /* set sw for NEW */
if(!check_applic_ok(0)) return(0); /* check applic selected*/
if(!load_package()) audit(0); /* load now and report */
return(0);
}
upd_old() /* update existing package */
{
load_sw=OLD; /* set sw for OLD */
if(!check_applic_ok(1)) return(0); /* check applic selected*/
if(!load_package()) audit(0); /* load now and report */
return(0);
}
load_package() /* load package into directory */
{
if (drv[0] == 'A' || drv[0] == 'B')
printf("\n\tPlace Package Diskette in Drive %s.", drv);
else
printf("\n\t PACKAGE WILL BE LOADED FROM DRIVE %s.", drv);
wait_kb();
/* cancelled out. using diskette ready creates diskette processing problems */
/* diskette_ready(); */ /* make sure ready */
if(VIRUS_SCAN_SW) scan_now(drv[0]); /* IF SWITCH TRUE - MUST SCAN */
else
{
printf("\n\tDO YOU WANT TO VIRUS SCAN THIS DISK BEFORE CONTINUING? ENTER (Y/N):");
read_kb(&ch, 1);
if(toupper(ch) == 'Y') scan_now(drv[0]);
}
strcpy(ddir, "nodir"); /* assume single package*/
strcpy(control, drv); /* copy current drive */
strcat(control, ":\\"); /* add :\ after drive: */
strcpy(describe, control); /* copy same */
strcpy(adir, control); /* copy same */
strcat(control, control_txt); /* make A:\CONTROL.TXT */
if(NULL == (ctrl=fopen(control, "r"))) /* check CONTROL.TXT */
{
if(show_a_dirs()) return(-1); /* show subdirectories */
if(strlen(buffer) == 0) /* no selection yet */
{
ask_select_pkg(0); /* ask select last page */
if (strlen(buffer) == 0) return(-1); /* CR to end */
}
strcpy(ddir, buffer); /* copy selection 2 ddir*/
strcpy(control, drv); /* copy current drive */
strcat(control, ":\\"); /* add :\ after drive: */
strcat(control, ddir); /* make A:\dirname */
strcat(control, "\\"); /* make A:\dirname\ */
strcpy(adir, control); /* copy A:\dirname\ */
strcpy(describe, control); /* copy A:\dirname\ */
strcat(control, control_txt); /* add CONTROL.TXT */
strupr(control); /* upper case name */
if(NULL == (ctrl=fopen(control, "r"))) /* file exists */
{
bell(); /* no */
printf("\n\t\Cannot open %s on diskette.", control);
wait_kb();
return(-1);
}
fclose(ctrl); /* exists, so close it */
}
strcat(describe, describe_txt); /* add DESCRIBE.TXT */
strupr(describe); /* upper case name */
if(NULL == (desc=fopen(describe, "r"))) /* check file exists */
{
bell(); /* no */
printf("\n\tCannot open %s on diskette.", describe);
wait_kb();
return(-1);
}
fclose(desc); /* close file DESCRIBE */
if(load_sw == NEW) /* is it a NEW load */
{
isin=sini+1; /* yes */
if(check_sin_exist()) /* dl package dir exist */
{
bell();
err_msg("Directory EXISTS. Cannot Load NEW Package into it.");
return(-1);
}
}
if(load_sw == OLD) /* is it an OLD load */
{
screen_head(); /* display screen header*/
strcpy(save_ctrl, control); /* save diskette control*/
strcpy(operator, "Load Into");
load_show_sw=SHOW; /* show control only */
display_sinn();
isin=snn; /* convert to binary */
msg_get("Confirm Loading OVER this Package. (Y/N): ");
if(ch != 'Y') return(-1); /* dont load here */
strcpy(control, save_ctrl); /* restore diskette ctrl*/
check_sin_exist(); /* need some of code */
}
load_show_sw=LOAD; /* this is a load req. */
if(get_control_info()) return(-1); /* bad ctrl file or pckg*/
if (strcmp(ddir,"nodir") == 0) {
printf("\n\n\tWill load package with SIN ID=%s. Confirm (Y/N): ", ssin);
} else {
printf("\n\n\tWill load \"%s\" package with SIN ID=%s. Confirm (Y/N): ",
ddir, ssin);
}
read_kb(&ch, 1);
if (toupper(ch) != 'Y') return(-1); /* dont do it */
if(mkdir(sin_dir)) /* make CSCS\CSCSSINn */
{
if(load_sw == NEW) /* is it a NEW load */
{
bell();
err_msg("Cannot create the Application directory.");
return(-1);
}
}
/* delete all files in the sinn directory */
sprintf(buffer, "%s\\*.*", sin_dir); /* make CSCS\CSCSSINn\*.* */
if(0 == (_dos_findfirst(buffer, _A_NORMAL, &buf_dir))) /* any file */
{
sprintf(buffer, "%s\\%s", sin_dir, buf_dir.name);
unlink(buffer);
while(0 == (_dos_findnext(&buf_dir))) /* check following */
{
sprintf(buffer, "%s\\%s", sin_dir, buf_dir.name);
unlink(buffer);
}
}
/* copy files to CSCS\CSCSSINn directory */
screen_head();
if (zipind_sw == TRUE && zipind[0] == 'N' && zip_file_cnt != 1)
/*if more than 1 file being packaged*/
{
printf("WARNING-NO ZIP OPTION CANNOT BE USED WITH MULTIPLE FILES\n");
printf("TO CONTINUE ENTER Y - TO STOP ENTER N \n");
read_kb(&ch, 1);
if (toupper(ch) != 'Y') return(-1); /* dont do it */
zipind[0] = 'Y'; /* reset zip switch to zip on */
}
printf("\nCopying files to Package Directory. Please wait...\n");
fcopy(prodlzip_txt, sin_dir); /* copy PRODLZIP.LST */
fcopy(control, sin_dir); /* copy CONTROL.TXT */
fcopy(describe, sin_dir); /* copy DESCRIBE.TXT */
copyf_to_disk(); /* copy files to disk */
if (zipind_sw == TRUE && zipind[0] == 'N')
sprintf(sys_buf, "call nzipchop %s %s %-04.4d %d %d %d %s",
id, app_code, isin, chop_size, lines_screen, chars_line, zipfile_hold);
else
sprintf(sys_buf, "call zipchop %s %s %-04.4d %d %d %d", /* zipchop */
id, app_code, isin, chop_size, lines_screen, chars_line);
system(sys_buf);
if(load_sw == NEW)
{
sini=isin; /* update sini */
strcpy(sinn, ssin); /* update sinn */
}
app_change_sw=TRUE; /* set app change sw */
update_log(); /* update log */
delete_files(); /* delete original files*/
unlink(prodlzip_txt); /* list file, end usage */
/* load report deactivated currently */
/* load_report(); */ /* print load report */
/* load report deactivated currently */
if (0 != (f = fopen(locked, "r"))) /* try to open lock file*/
{
printf("\n\tThis Package Locked Out. To make it accessible, it must be Unlocked.");
fclose(f); /* close lock file */
}
err_msg("Reminder: ReCreate Selection Menus to activate ADDs or UPDATEs.");
return(0);
}
copyf_to_disk() /* copy files: diskette to disk */
{
zlst=fopen(prodlzip_txt, "r"); /* re-open PRODLZIP.LST */
strcpy(filename, adir); /* prepare active drive */
while(EOF != (fscanf(zlst, "%s\n", &filename[strlen(adir)])))
{
fcopy(filename, sin_dir); /* copy current DL file */
}
fclose(zlst);
return(0);
}
delete_files() /* delete files after zipchoped */
{
zlst=fopen(prodlzip_txt, "r"); /* re-open PRODLZIP.LST */
strcpy(filename, sin_dir); /* prepare active drive */
while(EOF != (fscanf(zlst, "%s\n", buffer)))
{
strcpy(filename, sin_dir); /* prepare dir name */
strcat(filename, "\\"); /* add \ after dirname */
strcat(filename, buffer); /* add filename after \ */
unlink(filename); /* delete file now */
}
fclose(zlst);
return(0);
}
load_report() /* produce report for this load */
{
msg_get("Confirm Printer ready for Load Report. (Y/N): ");
if(ch != 'Y') return(0);
if (0 == (prt = fopen("PRN", "a"))) /* open printer file */
{
perror("");
printf("\n\tCannot open Printer file: %s\n", "PRN");
return(0);
}
time(&ibtm); /* get time */
fprintf(prt, "Download Application: %s %s\t%s\n", id, app_name, ctime(&ibtm));
if(load_sw == NEW) fprintf(prt, "Add NEW ");
else fprintf(prt, "Update ");
fprintf(prt, "Package. Load Report for Package ID: %d\n", isin);
fprintf(prt, "\nCONTROL.TXT file follows:\n\n");
fflush(prt); /* write out */
sprintf(sys_buf, "copy %s\\%s PRN: > NUL:", sin_dir, control_txt);
system(sys_buf);
fprintf(prt, "\n\n\nDESCRIBE.TXT file follows:\n\n");
fflush(prt); /* write out */
sprintf(sys_buf, "copy %s\\%s PRN: > NUL:", sin_dir, describe_txt);
system(sys_buf);
fprintf(prt, "\014"); /* form feed */
fclose(prt);
return(0);
}
fcopy(from, to) /* copy file from from to to */
char *from, *to;
{
sprintf(sys_buf, "copy %s %s > NUL:", from, to);
system(sys_buf); /* copy file now */
return(0);
}
get_control_info() /* parse CONTROL.TXT */
{
if(load_show_sw == LOAD) /* is it a LOAD req. */
{
if(NULL == (zlst=fopen(prodlzip_txt, "w"))) /* open PRODLZIP.LST*/
{
bell();
err_msg("Cannot open PRODLZIP.LST file.");
return(r=-1);
}
}
screen_head(); /* show screen header */
if(NULL == (ctrl=fopen(control, "r")))
{
bell();
printf("\n\t\Cannot open %s file.", control);
wait_kb();
return(-1);
}
parse_ctrl(); /* parse CONTROL.TXT file*/
fclose(ctrl); /* close CONTROL.TXT */
if (load_show_sw == LOAD) fclose(zlst); /* close PRODLZIP.LST */
if (bad_ctrl) /* bad lines found */
{
err_msg("Check CONTROL.TXT file.");
return(-1); /* dont load package */
}
/* or missing mandatory lines */
if(!(title1_sw & vdate_sw & version_sw & zipfile_sw & file_sw))
{
err_msg("Missing Mandatory Lines in CONTROL.TXT file.");
return(-1); /* dont load package */
}
return(0);
}
parse_ctrl() /* parse CONTROL.TXT file */
{
printf("\n");
title1_sw=vdate_sw=version_sw=zipfile_sw=file_sw=FALSE;
zipind_sw = FALSE; /* IS ZIP OPTION INDICATOR PRESENT */
category_sw = FALSE; /* IS CONTRACT NUMBER PRESENT */
bad_ctrl=FALSE;
zip_file_cnt = 0;
zipind[0] = 'Y'; /* ASSUME ZIP UNLESS TOLD DIFFERENT */
printf("CONTROL.TXT file contents follows:\n");
printf("==================================\n");
while(NULL != (fgets(buffer, MAX_BUFF, ctrl))) /* read file */
{
if (strlen(buffer) == 0 || buffer[0] == '\n')
continue; /* skip blank lines */
printf("%s", buffer); /* show line on screen */
if (buffer[0] == 0x1A) break; /* EOF, finish */
parse_line(buffer);
if(r == -1) bad_ctrl=TRUE;
}
return(r=0); /* return, no error */
}
parse_line(buf) /* parse individual line */
char *buf;
{
char *p;
r=0;
if (NULL == (p = strchr(buf, ':'))) /* look for : */
{
printf("\t\aNo \":\" to seperate Keyword.\n");
return (r=-1);
}
*p=0; /* terminate keyword with NULL */
p++; /* point to variable */
/* remove spaces at beginning of keyword */
while(isspace(*buf)) buf++;
/* remove spaces at end of keyword */
while(isspace(buf[strlen(buf)-1])) buf[strlen(buf)-1]='\0';
/* remove nl at end of variable */
while(p[strlen(p)-1] == '\n') p[strlen(p)-1]='\0'; /* remove nl */
while(isspace(*p)) p++; /* skip lead blanks on variable */
if (0 == (strcmpi(buf, "title1")))
{
if(strlen(p) == 0 || strlen(p) > MAX_TITLE)
{
r=-1;
printf("\t\aBad Title1.\n");
}
else
{
strcpy(title1, p);
title1_sw=TRUE;
}
}
else
if (0 == (strcmpi(buf, "title2")))
{
if(strlen(p) == 0 || strlen(p) > MAX_TITLE)
{
r=-1;
printf("\t\aBad Title2.\n");
}
else
{
strcpy(title2, p);
}
}
else
if (0 == (strcmpi(buf, "date")))
{
if(strlen(p) == 0 || strlen(p) > MAX_VDATE)
{
r=-1;
printf("\t\aBad Date.\n");
}
else
{
strcpy(vdate, p);
vdate_sw=TRUE;
}
}
else
if (0 == (strcmpi(buf, "version")))
{
if(strlen(p) == 0 || strlen(p) > MAX_VERSN)
{
r=-1;
printf("\t\aBad Version.\n");
}
else
{
strcpy(version, p);
version_sw=TRUE;
}
}
else
if (0 == (strcmpi(buf, "zipfile")))
{
if(strlen(p) == 0 || strlen(p) > MAX_ZIPFN)
{
r=-1;
printf("\t\aBad Zipfile Name.\n");
}
else
{
strcpy(zipfile, p);
zipfile_sw=TRUE;
}
}
else
if (0 == (strcmpi(buf, "zipind")))
{
if(strlen(p) == 0 || strlen(p) != 1)
{
r=-1;
printf("\t\aBad Zipfile INDICATOR.\n");
}
else
{
strcpy(zipind, p);
zipind_sw=TRUE;
}
}
else
if (0 == (strcmpi(buf, "CATEGORY")))
{
if(strlen(p) == 0 || strlen(p) > 15)
{
r=-1;
printf("\t\A BAD CATEGORY FIELD.\n");
}
else
{
strcpy(CATEGORY, p);
category_sw=TRUE;
}
}
else
if (0 == (strcmpi(buf, "file")))
{
if(load_show_sw == LOAD) chkfile(p); /* check file exist, length */
}
else
{
printf("\t\aUnknown Keyword in Line.\n");
return(r=-1);
}
return(r);
}
chkfile(buf) /* parse file line and check file size */
char *buf;
{
char *p;
if(NULL == (p=strchr(buf, ','))) /* no , in line */
{
printf("\t\aMissing \",\" before Length.\n");
return(r=-1);
}
if(0L == (ll=atol(p+1))) /* bad length field */
{
printf("\t\aBad Length.\n");
return(r=-1);
}
*p=0; /* terminate file name */
p=buf; /* point to file name */
while(isspace(*p)) p++; /* skip leading blanks */
if(strlen(p) == 0 || strlen(p) > MAX_FILE)
{
printf("\t\aBad File Name.\n");
return(r=-1);
}
strcpy(filename, adir); /* copy a:\dirname\ */
strcat(filename, p); /* add filename to it */