Professional Documents
Culture Documents
CPROJECTS
CPROJECTS
CPROJECTS
Helpmate
Menu Organisation
What is the similarity between a hotel and a computer? Both
survive on menus. We choose dishes from a menu in a hotel;
similarly, we can pick items from the menu displayed on the
screen. But the similarity ends there because, being an unusual
gourmet, the computer finds `Open file' or `Save file' menu
items more relishing than `Spring Rolls' or `Hakka Noodles'.
Most software packages today eloquently boast of `menu
driven' capability, meaning thereby that they offer the user a list
of options which allow him to move through the entire system
The exact position of the help box in relation with the main
menu is shown in the following figure.
Issuing Interrupts
For various utilities dealing with operations on files and
directories, we need to access the services of the operating
system. This is done by calling ROM BIOS/DOS routines.
These routines are called by issuing an interrupt. The
micoprocessor is usually busy when these routines get called.
Since it is caable of performing only one task at a time, the
microprocessor's current activity must be interrupted before the
control can be passed to the ROM BIOS/DOS routine. The
process of temporarily stopping the microprocessor's current
activity is called `Issuing of Interrupt'. When the interrupt is
issued, the microprocessor stops whatever it had been doing,
passes control to the appropriate ROM BIOS/DOS routine, and
once this routine has been executed, resumes its original
interrupted activity.
File Attributes
In the directory entry of any file, 32 bytes are used for storing
information about it, like its name, extension, date, time, etc. Of
these, one byte stores the attribute of the file. Bit numbers
0through 5 of the attribute byte are used to indicate the status of
this file, while the 6th and 7th bits are unused. Figure 1.5 shows
the 8 bits of this attribute byte and what each bit signifies. The
function setfileattb( ) in Helpmate allows you to alter any of
these bits, so that the attribute of any file can be changed. For
instance, if the zeroth bit is made 1, the file would become a
read only file.This means this file cannot be modified unless it
is made a read/write file, by setting its zeroth bit to zero.
File Encryption
Another utility on the File Services menu is that of encrypting a
file. For this, the function encryptfile( ) is used. This function
makes use of an offset cipher for coding the file into an
unrecognisable form. While encrypting, 127 is added to the
ascii value of each character read from the source file, and then
the character corresponding to this new value is stored in the
File Compression
An effective way of reducing the size of any file is by
eliminating the blank spaces that occur in it. White spaces, as
they are called, are present in every file, and more often than
not, are in abundance in a C program, courtesy provision made
in C for ignoring them totally. In the File menu, file
compression is done by substituting a single graphic character
for a set of consecutive spaces. Thus, if four saces are
encountered in a row, we replace them in the target file by a
graphic character corresponding to ascii (127 + 4), i.e. 131.
During decompression, if a graphic character is encountered, it
signifies that the original file had as many spaces as is the result
of sbtracting 127 from the ascii value of the graphic character.
Note that thisutility works only for text files.
Directory Tree
This utility displays all the directories and sub-directories
present in the default drive. For this purpose, the function tree( )
has been written, which calls two standard library functions,
findfirst( ) and findnext( ). These functions find the first and
consecutive occurrences respectively of directory entries which
match the skeleton "*.*". Once a matching entry is found, we
check whether it is a sub-directory or not. All sub-directories
are displayed in a tree form so that the parent-child relationship
between various sub-directories becomes immediately evident.
Miscellaneous services
This menu supplies commonly needed information like the ascii
table, the equipment list, etc. And just to let yourself unwind, a
video game - Shuffle has been thrown in too. Let's begin with
the calendar.
Calendar
This utility displays the calendar for the month and year
specified by the user. Due consideration has been given to the
leap years and the calendar is framed accordingly. Try out this
utility for September 1752 and I am sure you would be taken
aback. No, there is nothing wrong with the program. It just so
happened that the King of ngland decreed that 11 days (3rd to
13th) be knocked off from this month. This he did to adjust the
number of days while switching over from Julian to Gregorian
calendar. As a result, many people missed their Birthday
celebrations and many more got paid for the days they didn't
work on. This was a boon for the salaried class, since it was in
this month that the concept of `paid leave' was born!
System Information
On booting a computer, the ROM startup routines check and
initialise the standard equipment, i.e. VDU, Floppy Disk Drive,
Keyboard etc., and store this equipment list at a fixed location
(hex 410) in memory. This information can be retrieved by
issuing interrupt numberhex 11. On doing so this information
gets stored in the 2-byte AX register. The bit settings for AX are
Figure 1.6
Shuffle
Another item in the Miscellaneous Services menu is the game
called Shuffle. The player is presented with a grid (as shown in
Figure 1.7) having numbers 1 to 15 arranged in a random
manner, and a blank space in the lower right corner. The
numbers can be moved about in the grid using the arrow keys.
The objective is to arrange the numbers in increasing order from
1 to 15, with the blank space back in the lower right corner. The
only valid keys are the arrow keys, and the moves are
monitored in the function shuffle( ). The blank space in the grid
corresponds with the position of 0 in the two-dimensional array
num[ ][ ]. The scan code of the key hit is used to determine the
new position of the blank space, and it swaps positions with the
appropriate number in the grid. The functions shufflebox( )and
display( ) together create the display screen, and check( ) is
called after every move to compare the current order of the
numbers in the grid with the aimed one.
Figure 1.7
Expanding Helpmate
Program
# 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"
{
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 ( mode )
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 ;
int r, c, attb ;
char *s ;
{
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 ( menu, count, sr, sc, hotkeys, helpnumber )
int count, sr, sc, helpnumber ;
char **menu, *hotkeys ;
{
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] ) ;
}
{
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 ( sr, sc, er, ec, buffer )
int sr, sc, er, 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++ ;
}
}
}
}
}
/* draws double-lined box */
drawbox ( sr, sc, er, ec, attr )
int sr, sc, er, ec, 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 ( menu, hotkeys, sr, sc, count, helpnumber
)
char **menu, *hotkeys ;
int sr, sc, count, helpnumber ;
{
int choice = 1, len, hotkeychoice ;
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 ;
",
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 ) ;
"
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 ) ;
",
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 ( a, col )
int a, 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 ) ;
",
getch( ) ;
writestring ( messages[1], 22, 14, 112 ) ;
restorevideo ( 5, 5, 20, 70, p ) ;
free ( p ) ;
}
encryptfile( )
{
char sfile[20], tfile[20], *p, ch ;
FILE *fps , *fpt ;
int areareqd, 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 coding service
22, 14, 112 ) ;
writestring ( "Enter source file name:", 7, 8, 112 ) ;
size ( 6, 7 ) ;
gotoxy ( 33, 8 ) ;
fflush ( stdin ) ;
gets ( sfile ) ;
size ( 32, 0 ) ;
/* open source file */
",
if ( ch == '\n' )
flag = putc ( '\n', fpt ) ;
else
flag = putc ( ( ch + 127 ), fpt ) ;
/* if error in writing */
if ( flag == EOF )
break ;
}
if ( flag == EOF )
writestring ( "Unable to encrypt file!", 11, 8, 112 );
else
writestring ( "File is successfully encrypted!", 11,
8, 112 ) ;
writestring ( messages[28], 22, 14, 112 ) ;
getch( ) ;
fclose ( fps ) ;
fclose ( fpt ) ;
writestring ( messages[1], 22, 14, 112 ) ;
restorevideo ( 5, 5, 20, 70, p ) ;
free ( p ) ;
}
decryptfile( )
{
char sfile[20], tfile[20], *p, ch ;
FILE *fps, *fpt ;
int areareqd, flag ;
areareqd = ( 20 - 5 + 1 ) * ( 70 - 5 + 1 ) * 2 ;
p = malloc ( areareqd ) ;
if ( p == NULL )
{
writestring ( messages[29], 22, 14, 112 ) ;
getch( ) ;
",
",
if ( p == NULL )
{
writestring ( messages[29], 22, 14, 112 ) ;
getch( ) ;
writestring ( messages[1], 22, 14, 112 ) ;
return ;
}
savevideo ( 5, 5, 12, 60, p ) ;
menubox ( 5, 5, 12, 60, 112, 66 ) ;
writestring ( "
size ( 32, 0 ) ;
/* open target file */
fpt = fopen ( tfile, "w" ) ;
if ( fpt == NULL )
{
writestring ( "Unable to open target file!", 10, 8, 112);
writestring ( messages[28], 22, 14, 112 ) ;
getch( ) ;
fclose ( fps ) ;
writestring ( messages[1], 22, 14, 112 ) ;
restorevideo ( 5, 5, 12, 60, p ) ;
free ( p ) ;
return ;
}
/* read each character till end of file is reached */
while ( ( ch = getc ( fps ) ) != EOF )
{
/* if ascii value of character read exceeds 127 */
if ( ch > 127 )
{
ch = ch - 127 ;
/* write back original spaces */
for ( count = 1 ; count <= ch ; count++ )
flag = putc ( ' ', fpt ) ;
}
else
flag = putc ( ch, fpt ) ;
/* if error in writing */
if ( flag == EOF )
break ;
}
if ( flag == EOF )
", 22,
writestring ( "
Press any key to return...
22, 14, 112 ) ;
getch( ) ;
",
fclose ( fp ) ;
writestring ( messages[1], 22, 14, 112 ) ;
restorevideo ( 0, 0, 24, 79, p ) ;
free ( p ) ;
}
makedir( )
{
union REGS ii, oo ;
int areareqd ;
char dirname[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 ( "
",
getch( ) ;
writestring ( messages[1], 22, 14, 112 ) ;
return ;
}
savevideo ( 5, 5, 20, 70, p ) ;
menubox ( 6, 5, 11, 60, 112, 66 ) ;
writestring ( "
Change directory service
", 22, 14, 112 ) ;
writestring ( "Enter name of directory:", 7, 8, 112 ) ;
size ( 6, 7 ) ;
gotoxy ( 34, 8 ) ;
gets ( dirname ) ;
size ( 32, 0 ) ;
/* issue interrupt for changing directory */
ii.h.ah = 59 ;
ii.x.dx = ( unsigned int ) dirname ;
intdos ( &ii, &oo ) ;
/* check if successful in changing directory */
if ( oo.x.cflag == 0 )
writestring ( "Directory is successfully changed!", 9,
8, 112 ) ;
else
{
if ( oo.x.ax == 3 )
writestring ( "Invalid path!", 9, 8, 112 ) ;
if ( oo.x.ax == 5 )
writestring ( "Improper access!", 9, 8, 112 ) ;
}
writestring ( messages[28], 22, 14, 112 ) ;
getch( ) ;
",
listdir( )
{
int areareqd ;
char *p, filetosearch[20] ;
char sz[10], dd[10], mm[10], yy[10], hr[10], m[10], temp[3] = "0" ;
struct ffblk file ;
unsigned int done, row, col, a, year, month, day, hour,
min ;
areareqd = ( 20 - 3 + 1 ) * ( 70 - 3 + 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 ( "
List directory service
22, 15, 112 ) ;
",
strcpy ( temp, hr ) ;
writestring ( temp, row, col + 45, 112 ) ;
writechar ( row, col + 47, ':', 112 ) ;
strcpy ( temp, "0" ) ;
itoa ( min, m, 10 ) ;
if ( strlen ( m ) == 1 )
strcat ( temp, m ) ;
else
strcpy ( temp, m ) ;
writestring ( temp, row, col + 48, 112 ) ;
strcpy ( temp, "0" ) ;
}
else
writestring ( "<DIR>", row, col + 15, 112 ) ;
/* find the next file matching the skeleton */
done = findnext ( &file ) ;
/* if screen is full */
if ( row == 18 )
{
row = 8 ;
writestring ( messages[28], 22, 14, 112 ) ;
getch( ) ;
menubox ( 5, 5, 20, 70, 112, 66 ) ;
writestring ( "Directory listing", 6, 28, 112 ) ;
writestring ( "-----------------", 7, 28, 112 ) ;
}
}
}
else
writestring ( "File not found!", 9, 8, 112 ) ;
}
/* display ROOT vertically in the appropriate
attribute*/
writestring ( "R", 3, 2, attb ) ;
writestring ( "O", 4, 2, attb ) ;
writestring ( "O", 5, 2, attb ) ;
writestring ( "T", 6, 2, attb ) ;
tree ( "*.*" ) ;
chdir ( current_dir ) ; /* restore current working
directory */
writestring ( "
",
getch( ) ;
restorevideo ( 0, 0, 24, 79, p ) ;
free ( p ) ;
}
tree ( ptr )
char *ptr ;
{
struct ffblk file ;
int flag, i, len ;
static char path[40] = "" ;
char str1[9] = "
", str2[9] = "
", str3[9] = "
char str4[9] = "
", str5[4] = " " ;
/* set up strings with appropriate characters */
strnset ( str1, 196, 8 ) ;
strnset ( str1, 195, 1 ) ;
strnset ( str2, 32, 8 ) ;
strnset ( str2, 179, 1 ) ;
strnset ( str3, 196, 8 ) ;
";
}
else
{
strcat ( dirname, file.ff_name ) ;
writestring ( dirname, dirtree_row, 5, 112 ) ;
}
if ( dirtree_row == 3 )
writestring ( str5, 3, 3, 112 ) ;
dirtree_row++ ;
/* go inside the directory found */
chdir ( file.ff_name ) ;
file.ff_name[0] = '\0' ;
/* search directory entries in this directory */
tree ( ptr ) ;
}
/* find the next entry matching the specification *.* */
flag = findnext ( &file ) ;
}
/* if inside a sub-directory, change over to its parent
directory */
if ( in-- > 0 )
{
chdir ( ".." ) ;
/* update the variable path appropriately */
len = strlen ( path ) ;
if ( in >= 1 )
{
while ( path[len - 1] != '\\' )
len-- ;
path[len - 1] = '\0' ;
}
}
}
calendar( )
{
char *months[ ] = {
"January", "Feburary", "March",
"April",
"May",
"June",
"July",
"August", "September",
"October", "November",
December" } ;
int days[ ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
30, 31 } ;
int m, y, leapyears, row, col, x, i, areareqd, firstday,
thisyrdays ;
long int totaldays ;
char *p, str1[5], str2[3] ;
areareqd = ( 20 - 3 + 1 ) * ( 70 - 3 + 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, 50, 112, 66 ) ;
writestring ( "
}
else
m=m-1;
break ;
case 1 : /* Esc key */
writestring ( messages[1], 22, 14, 112 ) ;
restorevideo ( 5, 5, 20, 70, p ) ;
free ( p ) ;
return ;
}
}
}
asciitable( )
{
char *p, str[4] ;
int areareqd, j, row, col ;
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 ( 5, 5, 20, 70, 112, 66 ) ;
writestring ( "
Display ascii table service
", 22, 14, 112 ) ;
row = 8 ;
col = 10 ;
writestring ( "Value", row - 2, col - 2, 112 ) ;
writestring ( "Character", row - 2, col + 5,112) ;
/* display ascii table */
for ( j = 0 ; j <= 255 ; j++ )
{
writechar ( row, ( col + 9 ), j, 112 ) ; /* display
character */
itoa ( j, str, 10 ) ;
writestring ( str, row, col, 112 ) ; /* display value */
row++ ;
/* if screen is full */
if ( row >= 18 )
{
row = 8 ;
col += 19 ;
if ( col > 48 )
{
writestring ( messages[28], 22, 14, 112 ) ;
getch( ) ;
row = 8 ;
col = 10 ;
menubox ( 5, 5, 20, 70, 112 ) ;
}
writestring ( "Value", row - 2, col - 2, 112 ) ;
writestring ( "Character", row - 2, col + 5,112 ) ;
}
}
writestring ( messages[28], 22, 14, 112 ) ;
getch( ) ;
writestring ( messages[1], 22, 14, 112 ) ;
restorevideo ( 5, 5, 20, 70, p ) ;
free ( p ) ;
}
systeminfo( )
{
union REGS ii, oo ;
int areareqd, a, n ;
char *p, str[3] ;
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 ( 5, 5, 18, 65, 112, 66 ) ;
writestring ( "
Display equipment list service
", 22, 14, 112 ) ;
writestring ( "Equipment list", 6, 16, 112 ) ;
writestring ( "--------------", 7, 16, 112 ) ;
/* call ROM BIOS equipment list routine */
int86 ( 17, &ii, &oo ) ;
a = oo.x.ax ;
/* segregate information stored in bits and display it */
if ( ( a & 1 ) == 0 )
writestring ( "Disk drive: Absent", 9, 8, 112 ) ;
else
writestring ( "Disk drive: Present", 9, 8, 112 ) ;
if ( ( a & 2 ) == 0 )
writestring ( "Math co-processor: Absent", 10, 8, 112 ) ;
else
writestring ( "Math co-processor: Present", 10, 8, 112 ) ;
writestring ( "Initial video mode:", 11, 8, 112 ) ;
n = ( a & 48 ) ;
switch ( n )
{
case 48 :
writestring ( "80 x 25 BW with mono card", 11, 28,
112 ) ;
break ;
case 32 :
writestring ( "80 x 25 BW with color card", 11, 28,
112 ) ;
break ;
case 16 :
writestring ( "40 x 25 BW with color card", 11, 28,
112 ) ;
}
if ( ( a & 1 ) == 1 ) /* if disk drive is present */
{
n = ( a & 0x00C0 ) >> 6 ;
writestring ( "No. of disk drives:", 12, 8, 112 ) ;
writestring ( itoa ( n + 1, str, 10 ), 12, 28, 112 ) ;
}
n = ( a & 0x100 ) ;
if ( n == 0x100 )
writestring ( "DMA: Absent", 16, 8, 112 ) ;
else
writestring ( "DMA: Present", 16, 8, 112 ) ;
n = ( a << 4 ) >> 13 ;
writestring ( "No. of serial ports present:", 13, 8, 112 ) ;
writestring ( itoa ( n, str, 10 ), 13, 37, 112 ) ;
if ( ( a & 0x1000 ) == 0 )
writestring ( "Game adapter: Absent", 14, 8, 112 ) ;
else
writestring ( "Game adapter: Present", 14, 8, 112 ) ;
n = a >> 14 ;
writestring ( "No. of parallel ports present:", 15, 8, 112 ) ;
writestring ( itoa ( n, str, 10 ), 15, 39, 112 ) ;
writestring ( messages[28], 22, 14, 112 ) ;
getch( ) ;
restorevideo ( 5, 5, 20, 70, p ) ;
free ( p ) ;
}
/* 2-D array for setting up the grid in Shuffle */
int num [4][4] = {
2, 11, 15, 1,
6, 4, 3, 14,
8, 7, 9, 10,
5, 12, 13, 0
};
shuffle( )
{
int r = 3, c = 3, t, flag, areareqd ;
/* draw 16 squares */
shufflebox( ) ;
writestring ( "Hit arrow keys to shift numbers", 16, 23,
112) ;
writestring ( "Press Esc to abort", 17, 23, 112 ) ;
while ( 1 )
{
/* display numbers in the grid */
display( ) ;
/* get user's response */
getkey( ) ;
switch ( scan )
{
case 80 : /* down arrow key */
/* if space is not present in top row */
if ( r != 0 )
{
t = num [r][c] ;
num[r][c] = num[r-1][c] ;
num[r-1][c] = t ;
r-- ;
/* increment the number of moves
made */
no_moves++ ;
}
break ;
case 72 : /* up arrow key */
/* if space is not present in bottom row */
if ( r != 3 )
{
t = num[r][c] ;
num[r][c] = num[r+1][c] ;
num[r+1][c] = t ;
r++ ;
/* increment the number of moves
made */
no_moves++ ;
}
break ;
case 75 : /* left arrow key */
Goodbye!
{
int i, j, row = 7, col = 33 ;
char str[5] ;
for ( i = 0 ; i <= 3 ; i++ )
{
for ( j = 0 ; j <= 3 ; j++ )
{
/* if the array element is 0, write spaces */
if ( num[i][j] == 0 )
writestring ( " ", row, col, 112 ) ;
else
{
itoa ( num[i][j], str, 10 ) ;
writestring ( str, row, col, 112 ) ;
}
col += 3 ;
if ( col > 42 )
{
col = 33 ;
row += 2 ;
}
}
}
}
check( )
{
int row, col ;
int result[4][4] = {
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 0
};
writestring ( " ** ** ** ** ** ** ** * * ** ** ** **
** ", 5, 5, 77 ) ;
writestring ( " ** ** ** ** ** ** ** *** ** ** ** **
** ", 6, 5, 77 ) ;
writestring ( " ******* ***** ** ****** ** * ** *******
** ***** ", 7, 5, 77 ) ;
writestring ( " ** ** ** ** ** ** * ** ** ** **
** ", 8, 5, 77 ) ;
writestring ( " ** ** ** ** ** ** ** ** ** **
** ", 9, 5, 77 ) ;
writestring ( " ** ** ****** ****** ** ** ** ** **
** ****** ,10, 5, 77 ) ;
writestring ( "
",
11, 5, 77 ) ;
getch( ) ;
}
calendar( )
changedir( )
check( )
copyfile( )
decompress( )
decryptfile( )
deletefile( )
dirtree( )
display( )
the numbers.
displayfile( )
displaymenu( )
drawbox( )
dserver( )
encryptfile( )
fserver( )
getfileattb( )
getkey( )
listdir( )
logo( )
mainscreen( )
makedir( )
memsize( )
menubox( )
mserver( )
Pops
up
the
DIR/p
Miscellaneous
displayed.
Calls
function
getresponse( ) to get the user's
choice from the menu items
displayed.
removedir( )
restorevideo( )
savevideo( )
setfileattb( )
setmode( )
shuffle( )
Calls
shufflebox(
)
and
display( ) to construct the grid
and to display the numbers in it.
size( )
systeminfo( )
tree( )
writeattr( )
writechar( )
writestring( )