-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpmate.c
2712 lines (2186 loc) · 58.6 KB
/
helpmate.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
/*
* Helpmate DOS Manager Version: 1.0
* DOS file manager for all your file managing needs
*
*
*
* helpmate.c
*
* Created on: Mar 22, 1998
* Author: undextrois
*/
# include "stdio.h"
# include "process.h"
# include "string.h"
# include "stdlib.h"
# include "ctype.h"
# include "conio.h"
# include "fcntl.h"
# include "types.h"
# include "stat.h"
# include "dir.h"
# include "dos.h"
/* various menu definitions */
/* character following ^ symbol is the hot key */
char *menu[] = {
"^File services",
"^Directory services",
"^Misc. services",
"e^Xit"
} ;
char *fileservices[] = {
"c^Opy file",
"^Delete file",
"^Get file attributes",
"^Set file attributes",
"^Encrypt file",
"decr^Ypt file",
"^Compress file",
"deco^Mpress file",
"ty^Pe file",
"re^Turn to main menu",
} ;
char *directoryservices[] = {
"^Make directory",
"^Change directory",
"^Remove directory",
"^List directory",
"^Display directory tree",
"re^Turn to main menu"
} ;
char *miscservices[] = {
"^Calendar",
"^Ascii table",
"^System information",
"s^Huffle",
"^Memory size" ,
"re^Turn to main menu"
} ;
/* help messages for different menu items and other frequently required messages */
char *messages[] = {
" Helpmate ",
" Select using Enter or Hot key ",
"Performs various file services",
"Performs various directory services",
"Performs various miscellaneous services",
"Return to DOS",
"Copy source file to target file",
"Delete a file",
"Display current file attributes",
"Change existing file attributes",
"Code a file using offset cypher",
"Decode a coded file",
"Compress text file",
"Decompress a compressed file",
"Display contents of file",
"Return to main menu",
"Create a new directory ",
"Change default directory",
"Remove an existing directory",
"List existing directory contents",
"Display directory tree",
"Return to main menu",
"Display calendar of any month & year",
"Display Ascii values & characters",
"Display equipment list",
"A video game",
"Display base memory size",
"Return to main menu ",
" Press any key to continue... ",
" Insufficient space! Press any key... "
} ;
char far *vid_mem ;
int ascii, scan ;
main()
{
int mm_choice ;
/* store base address of VDU memory and set appropriate video mode */
#ifdef MA
/* store base address for MA */
vid_mem = ( char far * ) 0xb0000000L ;
setmode ( 7 ) ;
#else
/* store base address for other display adapters */
vid_mem = ( char far * ) 0xb8000000L ;
setmode ( 3 ) ;
#endif
size ( 32, 0 ) ; /* hide cursor */
/* create opening screen display */
menubox ( 0, 0, 24, 79, 7, 7 ) ;
drawbox ( 1, 0, 21, 79, 7 ) ;
drawbox ( 1, 0, 23, 79, 7 ) ;
logo() ;
/* create screen on which menus are to be popped up */
mainscreen() ;
while ( 1 )
{
/* pop up main menu and collect choice */
mm_choice = popupmenu ( menu, 4, 5, 5, "FDMX", 2 ) ;
/* test choice received */
switch ( mm_choice )
{
case 1 :
fserver() ;
break ;
case 2 :
dserver() ;
break ;
case 3 :
mserver() ;
break ;
case 4 :
case 27 :
size ( 6, 7 ) ;
clrscr() ;
exit ( 1 ) ;
}
}
}
/* sets video mode */
setmode ( int mode )
{
union REGS i, o ;
i.h.ah = 0 ; /* service no. */
i.h.al = mode ; /* video mode */
int86 ( 16, &i, &o ) ; /* issue interrupt */
}
/* prepares the screen for popping up a menu */
mainscreen()
{
int i, j ;
drawbox ( 1, 0, 23, 79, 7 ) ;
drawbox ( 3, 0, 21, 79, 7 ) ;
writechar ( 3, 0, 204, 7 ) ;
writechar ( 3, 79, 185, 7 ) ;
writechar ( 21, 0, 204, 7 ) ;
writechar ( 21, 79, 185, 7 ) ;
for ( i = 4 ; i <= 20 ; i++ )
{
for ( j = 1 ; j <= 78 ; j += 2 )
{
writechar ( i, j, 177, 7 ) ;
writechar ( i, j + 1, 177, 7 ) ;
}
}
writestring ( messages[0], 2, 32, 112 ) ;
writestring ( messages[1], 22, 14, 112 ) ;
}
/* writes a character and its attribute in VDU memory */
writechar ( int r, int c, char ch, int attb )
{
char far *v ;
v = vid_mem + r * 160 + c * 2 ; /* calculate address in VDU memory corresponding to row r and column c */
*v = ch ; /* store ascii value of character */
v++ ;
*v = attb ; /* store attribute of character */
}
/* writes a string into VDU memory in the desired attribute */
writestring ( char *s, int r, int c, int attb )
{
while ( *s != '\0' )
{
/* if next character is hot key, write it in different attribute, otherwise in normal attribute */
if ( *s == '^' )
{
s++ ;
writechar ( r, c, *s, 126 ) ;
}
else
writechar ( r, c, *s, attb ) ;
s++ ;
c++ ;
}
}
/* pops up a menu on the existing screen contents */
popupmenu ( char **menu, int count, int sr, int sc, char *hotkeys, int helpnumber )
{
int er, ec, i, l = 0, areareqd, areaforhelp, choice ;
char *p, *h ;
/* calculate ending row for menu */
er = sr + count + 2 ;
/* find longest menu item */
for ( i = 0 ; i < count ; i++ )
{
if ( strlen ( menu[i] ) > l )
l = strlen ( menu[i] ) ;
}
/* calculate ending column for menu */
ec = sc + l + 3 ;
/* calculate area required to save screen contents where menu is to be popped up */
areareqd = ( er - sr + 1 ) * ( ec - sc + 1 ) * 2 ;
p = malloc ( areareqd ) ; /* allocate memory */
/* check if allocation is successful */
if ( p == NULL )
{
writestring ( messages[29], 22, 14, 112 ) ;
getch() ;
exit ( 2 ) ;
}
/* save screen contents into allocated memory */
savevideo ( sr, sc, er, ec, p ) ;
/* draw filled box with shadow */
menubox ( sr, sc, er, ec, 112, 66 ) ;
/* display the menu in the filled box */
displaymenu ( menu, count, sr + 1, sc + 1 ) ;
/* calculate area required for help box */
areaforhelp = ( 9 - 6 + 1 ) * ( 78 - 35 + 1 ) * 2 ;
h = malloc ( areaforhelp ) ;
if ( h == NULL )
{
writestring ( messages[29], 22, 14, 112 ) ;
getch() ;
exit ( 3 ) ;
}
savevideo ( 6, 35, 9, 78, h ) ;
menubox ( 6, 35, 9, 78, 112, 66 ) ;
/* display help message */
writestring ( messages[helpnumber], 7, 36, 112 ) ;
/* receive user's choice */
choice = getresponse ( menu, hotkeys, sr, sc, count, helpnumber ) ;
/* restore original screen contents */
restorevideo ( sr, sc, er, ec, p ) ;
restorevideo ( 6, 35, 9, 78, h ) ;
/* free allocated memory */
free ( p ) ;
free ( h ) ;
return ( choice ) ;
}
/* displays or hides the cursor */
size ( int ssl, int esl )
{
union REGS i, o ;
i.h.ah = 1 ; /* service number */
i.h.ch = ssl ; /* starting scan line */
i.h.cl = esl ; /* ending scan line */
i.h.bh = 0 ; /* video page number */
/* issue interrupt for changing the size of the cursor */
int86 ( 16, &i, &o ) ;
}
/* gets the ascii and scan codes of the key pressed */
getkey()
{
union REGS ii, oo ;
/* wait till a key is hit */
while ( ! kbhit() )
;
ii.h.ah = 0 ; /* service number */
/* issue interrupt */
int86 ( 22, &ii, &oo ) ;
scan = oo.h.ah ;
ascii = oo.h.al ;
}
/* saves screen contents into allocated memory in RAM */
savevideo ( int sr, int sc, int er, int ec, char *buffer )
{
char far *v ;
int i, j ;
for ( i = sr ; i <= er ; i++ )
{
for ( j = sc ; j <= ec ; j++ )
{
v = vid_mem + i * 160 + j * 2 ; /* calculate address */
*buffer = *v ; /* store character */
v++ ;
buffer++ ;
*buffer = *v ; /* store attribute */
buffer++ ;
}
}
}
/* restores screen contents from allocated memory in RAM */
restorevideo ( int sr, int sc, int er, int ec, char *buffer )
{
char far *v ;
int i, j ;
for ( i = sr ; i <= er ; i++ )
{
for ( j = sc ; j <= ec ; j++ )
{
v = vid_mem + i * 160 + j * 2 ; /* calculate address */
*v = *buffer ; /* restore character */
v++ ;
buffer++ ;
*v = *buffer ; /* restore attribute */
buffer++ ;
}
}
}
/* draws filled box with or without shadow */
menubox ( int sr, int sc, int er, int ec, char fil, char shad )
{
int i, j ;
/* draw filled box */
for ( i = sr ; i < er ; i++ )
{
for ( j = sc ; j < ( ec - 1 ) ; j++ )
writechar ( i, j, ' ', fil ) ;
}
/* if no shadow is required for the filled box */
if ( shad == 0 )
{
for ( i = sr ; i <= er ; i++ )
{
writechar ( i, ec, ' ', fil ) ;
writechar ( i, ( ec - 1 ), ' ', fil ) ;
}
for ( j = sc ; j <= ec ; j++ )
writechar ( er, j, ' ', fil ) ;
}
else
{
/* draw vertical and horizontal shadow */
for ( i = sr + 1 ; i <= er ; i++ )
{
writechar ( i, ec, ' ', shad ) ;
writechar ( i, ( ec - 1 ), ' ', shad ) ;
}
for ( j = sc + 2 ; j <= ec ; j++ )
writechar ( er, j, ' ', shad ) ;
}
}
/* displays the menu in box drawn by menubox() */
displaymenu ( char **menu, int count, int sr, int sc )
{
int i ;
for ( i = 0 ; i < count ; i++ )
{
/* write menu item in VDU memory */
writestring ( menu[i], sr, sc, 112 ) ;
sr++ ;
}
}
/* draws double-lined box */
drawbox ( int sr, int sc, int er, int ec, int attr )
{
int i ;
/* draw horizontal lines */
for ( i = sc + 1 ; i < ec ; i++ )
{
writechar ( sr, i, 205, attr ) ;
writechar ( er, i, 205, attr ) ;
}
/* draw vertical lines */
for ( i = sr + 1 ; i < er ; i++ )
{
writechar ( i, sc, 186, attr ) ;
writechar ( i, ec, 186, attr ) ;
}
/* draw four corners */
writechar ( sr, sc, 201, attr ) ;
writechar ( sr, ec, 187, attr ) ;
writechar ( er, sc, 200, attr ) ;
writechar ( er, ec, 188, attr ) ;
}
/* receives user's response for the menu displayed */
getresponse ( char **menu, char *hotkeys, int sr, int sc, int count, int helpnumber )
{
int choice = 1, len, hotkeychoice ;
/* calculate number of hot keys for the menu */
len = strlen ( hotkeys ) ;
/* highlight first menu item */
writestring ( menu[choice - 1], sr + choice, sc + 1, 111 ) ;
while ( 1 )
{
getkey() ; /* receive key */
/* if special key is hit */
if ( ascii == 0 )
{
switch ( scan )
{
case 80 : /* down arrow key */
/* make highlighted item normal */
writestring ( menu[choice - 1], sr + choice, sc + 1, 112 ) ;
choice++ ;
helpnumber++ ;
break ;
case 72 : /* up arrow key */
/* make highlighted item normal */
writestring ( menu[choice - 1], sr + choice, sc + 1, 112 ) ;
choice-- ;
helpnumber-- ;
break ;
}
/* if highlighted bar is on first item and up arrow key is hit */
if ( choice == 0 )
{
choice = count ;
helpnumber = helpnumber + count ;
}
/* if highlighted bar is on last item and down arrow key is hit */
if ( choice > count )
{
choice = 1 ;
helpnumber = helpnumber - count ;
}
/* highlight the appropriate menu item */
writestring ( menu[choice - 1], sr + choice, sc + 1, 111 ) ;
menubox ( 6, 35, 9, 78, 112, 66 ) ;
/* write the corresponding help message */
writestring ( messages[helpnumber], 7, 36, 112 ) ;
}
else
{
if ( ascii == 13 ) /* Enter key */
return ( choice ) ;
if ( ascii == 27 ) /* Esc key */
return ( 27 ) ;
ascii = toupper ( ascii ) ;
hotkeychoice = 1 ;
/* check whether hot key has been pressed */
while ( *hotkeys != '\0' )
{
if ( *hotkeys == ascii )
return ( hotkeychoice ) ;
else
{
hotkeys++ ;
hotkeychoice++ ;
}
}
/* reset hotkeys to point to the first character in the string */
hotkeys = hotkeys - len ;
}
}
}
/* pops up File Services menu, receives choice and branches to appropriate function */
fserver()
{
int fs_choice ;
while ( 2 )
{
fs_choice = popupmenu ( fileservices, 10, 5, 5, "ODGSEYCMPT", 6 ) ;
switch ( fs_choice )
{
case 1 :
copyfile() ;
break ;
case 2:
deletefile() ;
break ;
case 3:
getfileattb() ;
break ;
case 4:
setfileattb() ;
break ;
case 5 :
encryptfile() ;
break ;
case 6:
decryptfile() ;
break ;
case 7 :
compressfile() ;
break ;
case 8 :
decompressfile() ;
break ;
case 9 :
displayfile() ;
break ;
case 10 :
return ;
}
}
}
/* pops up Directory Services menu, receives choice and branches to appropriate function */
dserver()
{
int ds_choice ;
while ( 2 )
{
ds_choice = popupmenu ( directoryservices, 6, 5, 5, "MCRLDT", 16 ) ;
switch ( ds_choice )
{
case 1 :
makedir() ;
break ;
case 2 :
changedir() ;
break ;
case 3 :
removedir() ;
break ;
case 4 :
listdir() ;
break ;
case 5 :
dirtree() ;
break ;
case 6 :
return ;
}
}
}
/* pops up Miscellaneous Services menu, receives choice and branches to appropriate function */
mserver()
{
int ms_choice ;
while ( 2 )
{
ms_choice = popupmenu ( miscservices, 6, 5, 5, "CASHMT", 22 ) ;
switch ( ms_choice )
{
case 1 :
calendar() ;
break ;
case 2 :
asciitable() ;
break ;
case 3 :
systeminfo() ;
break ;
case 4 :
shuffle() ;
break ;
case 5 :
memsize() ;
break ;
case 6 :
return ;
}
}
}
copyfile()
{
char sfile[20], tfile[20], buffer[512], *p ;
int areareqd, inhandle, outhandle, bytes, flag ;
areareqd = ( 20 - 5 + 1 ) * ( 70 - 5 + 1 ) * 2 ;
p = malloc ( areareqd ) ;
if ( p == NULL )
{
writestring ( messages[29], 22, 14, 112 ) ;
getch() ;
writestring ( messages[1], 22, 14, 112 ) ;
return ;
}
savevideo ( 5, 5, 20, 70, p ) ;
menubox ( 6, 5, 13, 60, 112, 66 ) ;
writestring ( " File copy service ", 22, 14, 112 ) ;
writestring ( "Enter source file name:", 7, 8, 112 ) ;
size ( 6, 7 ) ; /* display cursor */
gotoxy ( 33, 8 ) ;
gets ( sfile ) ;
size ( 32, 0 ) ; /* hide cursor */
/* open source file in low level binary mode for reading */
inhandle = open ( sfile, O_RDONLY | O_BINARY ) ;
/* if unable to open file */
if ( inhandle < 0 )
{
writestring ( "Unable to open source file!", 9, 8, 112 ) ;
writestring ( messages[28], 22, 14, 112 ) ;
getch() ;
writestring ( messages[1], 22, 14, 112 ) ;
restorevideo ( 5, 5, 20, 70, p ) ;
free ( p ) ;
return ;
}
writestring ( "Enter target file name:", 9, 8, 112 ) ;
size ( 6, 7 ) ;
gotoxy ( 33, 10 ) ;
gets ( tfile ) ;
size ( 32, 0 ) ;
/* open target file in low level binary mode for writing */
outhandle = open ( tfile, O_CREAT | O_WRONLY | O_BINARY, S_IWRITE ) ;
/* if unable to open file */
if ( outhandle < 0 )
{
writestring ( "Unable to open target file!", 11, 8, 112 ) ;
writestring ( messages[28], 22, 14, 112 ) ;
getch() ;
close ( inhandle ) ;
writestring ( messages[1], 22, 14, 112 ) ;
restorevideo ( 5, 5, 20, 70, p ) ;
free ( p ) ;
return ;
}
/* read chunks of 512 bytes from source file and write to target file till there are bytes to read */
while ( ( bytes = read ( inhandle, buffer, 512 ) ) > 0 )
{
flag = write ( outhandle, buffer, bytes ) ;
if ( flag == -1 )
break ;
}
if ( flag == -1 )
writestring ( "Unable to copy file!", 11, 8, 112 ) ;
else
writestring ( "File has been successfully copied!", 11, 8, 112 ) ;
writestring ( messages[28], 22, 14, 112 ) ;
getch() ;
/* close files and restore original screen contents */
close ( inhandle ) ;
close ( outhandle ) ;
writestring ( messages[1], 22, 14, 112 ) ;
restorevideo ( 5, 5, 20, 70, p ) ;
free ( p ) ;
}
deletefile()
{
union REGS ii, oo ;
int areareqd ;
char filename[20], *p ;
areareqd = ( 20 - 5 + 1 ) * ( 70 - 5 + 1 ) * 2 ;
p = malloc ( areareqd ) ;
if ( p == NULL )
{
writestring ( messages[29], 22, 14, 112 ) ;
getch() ;
writestring ( messages[1], 22, 14, 112 ) ;
return ;
}
savevideo ( 5, 5, 20, 70, p ) ;
menubox ( 6, 5, 11, 60, 112, 66 ) ;
writestring ( " File delete service " , 22, 14, 112 ) ;
writestring ( "Enter name of file to be deleted:", 7, 8, 112 ) ;
size ( 6, 7 ) ;
gotoxy ( 43, 8 ) ;
gets ( filename ) ;
size ( 32, 0 ) ;
/* issue interrupt for deleting file */
ii.h.ah = 65 ; /* dos service number */
ii.x.dx = ( unsigned int ) filename ; /* store base address */
intdos ( &ii, &oo ) ;
/* check if successful in deleting file */
if ( oo.x.cflag == 0 )
writestring ( "File was successfully deleted!", 9, 8, 112 ) ;
else
{
switch ( oo.x.ax )
{
case 2 :
writestring ( "File not found!", 9, 8, 112 ) ;
break ;
case 3 :
writestring ( "Invalid path!", 9, 8, 112 ) ;
break ;
case 5 :
writestring ( "Access denied!", 9, 8, 112 ) ;
break ;
case 0x11 :
writestring ( "Invalid drive name!", 9, 8, 112 ) ;
break ;
default :
writestring ( "Improper request!", 9, 8, 112 ) ;
}
}
writestring ( messages[28], 22, 14, 112 ) ;
getch() ;
writestring ( messages[1], 22, 14, 112 ) ;
restorevideo ( 5, 5, 20, 70, p ) ;
free ( p ) ;
}
/* displays the current attributes of a file */
getfileattb()
{
union REGS ii, oo ;
int a, areareqd ;
char filename[20], *p ;
areareqd = ( 20 - 5 + 1 ) * ( 70 - 5 + 1 ) * 2 ;
p = malloc ( areareqd ) ;
if ( p == NULL )
{
writestring ( messages[29], 22, 14, 112 ) ;
getch() ;
writestring ( messages[1], 22, 14, 112 ) ;
return ;
}
savevideo ( 5, 5, 20, 70, p ) ;
menubox ( 6, 5, 16, 60, 112, 66 ) ;
writestring ( " Get file attribute service ", 22, 14, 112 ) ;
writestring ( "Enter name of file:", 7, 8, 112 ) ;
size ( 6, 7 ) ;
gotoxy ( 29, 8 ) ;
gets ( filename ) ;
size ( 32, 0 ) ;
ii.h.ah = 67 ; /* dos service number */
ii.h.al = 0 ; /* 0 - get attributes, 1 - set attributes */
ii.x.dx = ( unsigned int ) filename ; /* store base address */
intdos ( &ii, &oo ) ; /* issue interrupt */
/* if successful display attributes, else display error message */
if ( oo.x.cflag == 0 )
{
writestring ( "ATTRIBUTES", 9, 27, 112 ) ;
writestring ( "ÄÄÄÄÄÄÄÄÄÄ", 10, 27, 112 ) ;
a = oo.x.cx ;
writeattr ( a, 24 ) ;
}
else
{
switch ( oo.x.ax )
{
case 2 :
writestring ( "File not found!", 9, 8, 112 ) ;
break ;
case 3 :
writestring ( "Invalid path!", 9, 8, 112 ) ;
break ;
case 5 :
writestring ( "Access denied!", 9, 8, 112 ) ;
break ;
case 0x11 :
writestring ( "Invalid drive name!", 15, 8, 112 ) ;
break ;
default :
writestring ( "Improper request!", 9, 8, 112 ) ;
}
}
writestring ( messages[28], 22, 14, 112 ) ;
getch() ;
writestring ( messages[1], 22, 14, 112 ) ;
restorevideo ( 5, 5, 20, 70, p ) ;
free ( p ) ;
}
/* displays attributes passed to variable a */
writeattr ( int a, int col )
{
writestring ( "Read only :", 11, col, 112 ) ;
if ( ( a & 1 ) == 0 )
writestring ( "OFF", 11, ( col + 12 ), 112 ) ;
else
writestring ( "ON", 11, ( col + 12 ), 112 ) ;
writestring ( "Hidden :", 12, col, 112 ) ;
if ( ( a & 2 ) == 0 )
writestring ( "OFF", 12, ( col + 12 ), 112 ) ;
else
writestring ( "ON", 12, ( col + 12 ), 112 ) ;
writestring ( "System :", 13, col, 112 ) ;
if ( ( a & 4 ) == 0 )
writestring ( "OFF", 13, ( col + 12 ), 112 ) ;
else
writestring ( "ON", 13, ( col + 12 ), 112 ) ;
writestring ( "Archive :", 14, col, 112 ) ;
if ( ( a & 32 ) == 0 )
writestring ( "OFF", 14, ( col + 12 ), 112 ) ;
else
writestring ( "ON", 14, ( col + 12 ), 112 ) ;
}
/* sets new attributes for a file */
setfileattb()
{
union REGS ii, oo ;
int old, new, areareqd ;
char filename[20], *p, ch ;
areareqd = ( 20 - 5 + 1 ) * ( 70 - 5 + 1 ) * 2 ;
p = malloc ( areareqd ) ;
if ( p == NULL )
{
writestring ( messages[29], 22, 14, 112 ) ;
getch() ;
writestring ( messages[1], 22, 14, 112 ) ;
return ;
}
savevideo ( 5, 5, 20, 70, p ) ;
menubox ( 6, 5, 17, 60, 112, 66 ) ;
writestring ( " Set file attribute service ", 22, 14, 112 ) ;
writestring ( "Enter name of file:", 7, 8, 112 ) ;
size ( 6, 7 ) ;
gotoxy ( 29, 8 ) ;
gets ( filename ) ;
size ( 32, 0 ) ;
ii.h.ah = 67 ; /* dos service number */
ii.h.al = 0 ; /* 0 - get attributes, 1 - set attributes */
ii.x.dx = ( unsigned int ) filename ; /* base address of filename */
intdos ( &ii, &oo ) ; /* issue interrupt */
/* if successful display attributes, else display error message */
if ( oo.x.cflag == 0 )
{
old = new = oo.x.cx ;
writestring ( "Existing Attributes", 9, 8, 112 ) ;
writestring ( "-------------------", 10, 8, 112 ) ;
writeattr ( old, 8 ) ; /* display existing attributes */
}
else
{
switch ( oo.x.ax )
{
case 2 :
writestring ( "File not found!", 9, 8, 112 ) ;
break ;
case 3 :
writestring ( "Invalid path!", 9, 8, 112 ) ;
break ;
case 5 :
writestring ( "Access denied!", 9, 8, 112 ) ;
break ;
case 0x11 :
writestring ( "Invalid drive name!", 9, 8, 112 ) ;
break ;
default :
writestring ( "Improper request!", 9, 8, 112 ) ;
}
writestring ( messages[28], 22, 14, 112 ) ;
getch() ;
restorevideo ( 5, 5, 20, 70, p ) ;
free ( p ) ;
return ;
}