home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Boston 2
/
boston-2.iso
/
DOS
/
PROGRAM
/
C
/
MENUCOPY
/
MENUCOPY.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-01
|
17KB
|
696 lines
═════════════════════════════════════════════════════════════════════════════
This program was written in Turbo C++ from March 19th to April 25th, 1991.
It consists of 630 lines and has been reduced to the smallest possible
program I could cram it on. It's Shareware to anyone who wants to compile
it themself and utilize it.
If however, you would like to borrow some of the code for your own
programs, feel free to do so. I would like a copy of any program you
create though (because I LOVE to check out good "C" coding !!).
For information concerning variables, etc., you can write me on
COMPUSERVE:
Dave Smith
71441,2723
I log on daily, so your questions, comments will be answered promptly.
Or write me: Dave Smith
I.D.F. Company
1104 Mason Dr.
Hurst TX 76053
I will also correspond to anyone by mail.
thanks,
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒ ▒▒
▒ ▒▒▒
▒ David Smith ▒▒▒┐
▒ ▒▒▒│┐
▒ Compuserve 71441,2723 ▒▒▒││
▒ ▒▒▒││
▒ ▒▒▒││
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒││
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒││
└─────────────────────────┘│
└─────────────────────────┘
══════════════════════════════════════════════════════════════════════════════
#include <stdio.h>
#include <time.h>
#include <sys\stat.h> // set up for the program
#include <stdlib.h>
#include <dir.h>
#include <string.h>
#include <dos.h>
#include <conio.h>
#include <io.h>
void findfile(void);
void finddirs(void); // a rather long list of function calls
char *getdirectory(char *path);
void menu(void);
void display(void);
void filemenu(void);
void show(void);
void getfiles(void);
void options(void);
void moremenu(void);
void help(void);
int sort_fun(const void *g, const void *h);
void sounds(void);
void end(void);
int count=1,num,x,col,temp,junk,music[12],del,moveon,cnn,ba;
int b=1,c,up=2,down,bum=1,maxcount=0,choice;
char ldir[70][70], sdir[70][70],buffer[100],a[200][200],file[40],direc[40],one[100],two[100];
char what[60];
struct date d; // an even longer list of arrays
struct time ta;
void main(void)
{
getdate(&d);
_setcursortype(_NOCURSOR); // the cursor gets in the way, so we lose it
finddirs();
menu();
end();
}
void finddirs(void) //finds all the directories on the current drive
{
int y;
char origdir[MAXPATH], rootdir[MAXPATH],tempdir[MAXPATH];
system("prompt $e[0;30;47m"); //colors the screen black-on-white
clrscr();
textcolor(1);
gotoxy(20,7);
cprintf("Dave's MENUCOPY"); //listing of directories we find
textcolor(CYAN);
gotoxy(15,9);
cprintf("╔");
gotoxy(15,11); //a monotonous way to make a box!!
cprintf("╚"); // but I had no choice if I wanted to
for(y=16;y<=45;y++){ // use double lines for borders.
gotoxy(y,9);
cprintf("═");
gotoxy(y,11);
cprintf("═");
}
gotoxy(15,10);
cprintf("║");
getdirectory(origdir);
getdirectory(tempdir);
chdir("\\");
findfile();
chdir(tempdir);
chdir(origdir);
textcolor(YELLOW+BLINK);
gotoxy(24,20);
cprintf("Press any key to start");
getch();
clrscr();
count=1; // Goto function "MENU" to display directories
menu(); // then reset the array to the first directory
}
void findfile(void)
{
char curdir[MAXPATH], temp[3];
int done, attrib,y; // my variables
struct ffblk dta;
getdirectory(curdir);
attrib=FA_DIREC+FA_SYSTEM+FA_HIDDEN; //find all directories, even if hidden
done=findfirst("*.*",&dta,attrib);
while(!done)
{
strncpy(temp,dta.ff_name,2);
if(((dta.ff_attrib & FA_DIREC) == FA_DIREC) && (temp[0] !='.'))
{ // exclude dots and filenames
if(strlen(curdir) !=3)
strcat(curdir,"\\");
textcolor(MAGENTA);
strcpy(sdir[count],dta.ff_name); // list the dir's while we find them
strcat(curdir,dta.ff_name);
strcpy(ldir[count],curdir);
count++; // count=array integer
maxcount++; // maxcount=total directories
gotoxy(16,10);
clreol();
textcolor(YELLOW);
gotoxy(16,10);
cprintf("Searching: %s",curdir);
chdir(curdir); // change into directory then recursively call "FINDFILE"
// until all dir's are exhausted
findfile();
chdir("..");
getdirectory(curdir);
}
done=findnext(&dta);
}
}
char *getdirectory(char *path) //specifies pathname based upon what drive
{ //we're currently in.
strcpy(path,"X:\\");
path[0]='A' + getdisk();
getcurdir(0,path+3);
return(path);
}
void menu(void)
{
int choice,mom,momm;
union REGS r;
r.h.ch=0;
r.h.cl=0;
r.h.dh=24; //set up for BIOS function call
r.h.dl=79;
r.h.bh=115;
r.h.al=0;
r.h.ah=6;
printf("\x1B[0;%d;%dm",30,47); //change screen color again
do{
display(); //call "DISPLAY" to show directories based upon screen
//position.
if(moveon){ //if we're called by "OPTIONS MENU" then re-display screen
//instead of starting over.
moveon=0;
getfiles();
}
choice=getch();
switch(choice)
{
case 72: //keypresses perform the menu operations
if(count>1) count--; break;
case 80:
if(count<maxcount) count++; break;
case '\r':
strcpy(direc,ldir[count]);
strcpy(buffer,direc);
buffer[0]='c'; //set up array to change directories
buffer[1]='d';
system(buffer);
b=1;
for(mom=0;mom<=200;mom++) //clear out array before re-filling it
for(momm=0;momm<=200;momm++)
a[mom][mom]=0; // the "MOMMA" names keep me from getting
int86(0x10,&r,&r); // bored while programming
num=1;
getfiles(); // calls the "GETFILES" function, which does just
// what it says.
case 27: end();
case 92:
sound(300); /*
delay(70); * Make a cute noise when the file and directory
nosound(); * menus are toggled.
sound(500); *
delay(70); * I couldn't call the "SOUNDS" function because the
nosound(); * delay is different between notes.
sound(540); *
delay(43);
nosound();
sound(700); /*
delay(32); *
nosound(); *
sound(1300); */
delay(32);
nosound();
sound(1800);
delay(32);
nosound();
filemenu(); //calls the file menus
case 59: help();
}
}while(bum>0); //BUM is the guy who keeps us running.
}
void display()
{
union REGS r;
r.h.ch=0;
r.h.cl=0; //again, set up for function calls
r.h.dh=24;
r.h.dl=12;
r.h.bh=115;
r.h.al=1;
for(c=1;c<=24;c++)
{
textcolor(0); //print borders for directory and file menus
gotoxy(12,c);
cprintf("▌");
}
for(c=1;c<=24;c++)
{
textcolor(RED); //This is the method by which
if(count==c+up-1)textcolor(YELLOW); //we scroll our directories up
down=up+23; //and down the screen.
gotoxy(1,c);
cprintf(sdir[up+c-1]);
}
if(count > down){ r.h.ah=6; //scroll when user goes over screen
int86(0x10,&r,&r); //limit.
gotoxy(1,24);
cprintf("%s",sdir[count]);
up++;
}
if(count < up) { r.h.ah=7;
int86(0x10,&r,&r);
gotoxy(1,1);
cprintf("%s",sdir[count]);
up--;
}
}
void getfiles(void)
{
int done; //get files in current directory and load them
struct ffblk dta; //into "A" array.
done=findfirst("*.*",&dta,47);
while(!done)
{
strcpy(a[b],dta.ff_name);
b++;
num++;
done=findnext(&dta);
}
qsort((void *)a, num, sizeof(a[0]), sort_fun); //sort files by first letter
//using Turbo C++'s qsort
//function.
b=1;
filemenu();
}
void filemenu(void)
{
int choose,y,yy;
FILE *opey; //remember Opey, on the Andy Griffith show??
struct stat statbuf;
union REGS r;
r.h.ch=0;
r.h.cl=0;
r.h.dh=24;
r.h.dl=11;
r.h.bh=115;
r.h.al=0;
r.h.ah=6;
int86(0x10,&r,&r);
do{
if(b<=114) show(); //If you got a lotta files, display them differently.
if(b>114) moremenu();
for(y=26;y<78;y +=13)
for(yy=1;yy<=23;yy++)
{ textbackground(7); //print border for files.
textcolor(0);
gotoxy(y,yy);
cprintf("▒");
}
textcolor(0);
opey=fopen(a[b],"r"); //Show time, day, date, file size, directory, etc....
stat(a[b],&statbuf);
while(!kbhit()) { gotoxy(1,24);
gettime(&ta);
printf("\x1B[1;%d;%dm",33,44);
printf(" *MENUCOPY* ║%s-->%ld bytes║ %d/%d/%d Time-%2d:%02d:%02d ",direc,statbuf.st_size,d.da_mon,d.da_day,d.da_year,ta.ti_hour,ta.ti_min,ta.ti_sec);
}
fclose(opey);
choose=getch();
switch(choose)
{
case 72:
if(b>1) b--; break;
case 80:
if(b<num-1) b++; break;
case 73: //keypresses rush to first and last file, go
sound(300); //up, down, etc..
delay(130);
nosound();
b=1; break;
case 81:
sound(300);
delay(130);
nosound();
b=num-1; break;
case '\r': //If you choose the file, put it into "FILE"
strcpy(file,a[b]);
options();
case 27: end();
case 75:
if(b>=23) b -=23; break; //go sideways through your files.
case 77:
if(b<num-23) b +=23; break;
case 92:
menu();
sound(300); //Again, here are those sounds !
delay(70);
nosound();
sound(500);
delay(70);
nosound();
sound(540);
delay(43);
nosound();
sound(700);
delay(32);
nosound();
sound(1300);
delay(32);
nosound();
sound(1800);
delay(32);
nosound();
case 59: help(); //F1 shows the "HELP" screen
}
}while(bum>0);
}
void show() //A "file" version of the "display" function above.
{
int cc,col,x,attrib;
if(num>114) clrscr(); //Here's the flicker that occurs when you have more
//than 114 files in a directory !!
if(num<115) attrib=num;
if(num>114) attrib=114;
textcolor(0);
for(cc=1;cc<attrib;cc++)
{
textbackground(7);
if(cc==b) { textcolor(YELLOW); //if file is currently selected,
textbackground(3); //highlight it.
}
x=14; //start files at row 14.
col=cc;
if(cc>23){
col=cc-23; //separate the rows according to how many you have.
x=27;
}
if(cc>46){
col=cc-46;
x=40;
}
if(cc>69){
col=cc-69;
x=53;
}
if(cc>92){
col=cc-92;
x=66;
}
gotoxy(x,col);
cprintf(a[cc]);
textcolor(0);
}
}
void options(void) //the File Options Menu !!
{
int y,junk1;
union REGS r;
r.h.ch=5;
r.h.cl=23;
r.h.dh=19;
r.h.dl=62;
r.h.bh=115;
r.h.al=0;
r.h.ah=6;
music[0]=7; //set up for a call to SOUNDS(); with our melody.
music[1]=9;
music[2]=11;
music[3]=13;
music[4]=15;
music[5]=17;
ba=5; //ba=how many numbers in the array
del=5;
sounds();
textbackground(1);
for(y=6;y<=18;y++){
gotoxy(24,y);
cprintf(" ");
}
textcolor(WHITE); //the above statement clears out the blue portion for
gotoxy(24,6); //our file options menu. Otherwise you'd have a rather
cprintf("╔"); //confusing background with letters, files, etc.
gotoxy(24,18); //and couldn't read anything from our menu !
cprintf("╚");
for(y=25;y<=60;y++){ gotoxy(y,6);
cprintf("═ ");
gotoxy(y,18);
cprintf("═");
}
for(y=7;y<=17;y++) { gotoxy(24,y); // Another rather long way to display
cprintf("║"); // a border. I would use a "LINE"
gotoxy(61,y); // Dos function call, but I wouldn't
cprintf("║"); // get the same pretty double
} // lines surrounding my menu.
gotoxy(61,6);
cprintf("╗");
gotoxy(61,18);
cprintf("╝");
gotoxy(35,8);
textcolor(LIGHTMAGENTA);
cprintf("FILE OPTIONS");
gotoxy(32,10);
strcpy(one,direc); //Print out my information.
strcat(one,"\\");
strcat(one,file);
cprintf("%s",one);
gotoxy(33,12);
textcolor(YELLOW);
cprintf("1. Copy");
gotoxy(33,13);
cprintf("2. Move");
gotoxy(33,14);
cprintf("3. Delete");
gotoxy(33,15);
cprintf("4. Quit Program");
junk=getch();
switch(junk){
case 49: gotoxy(26,17);
cprintf("Copy to: "); //Copy all the information into a
scanf("%s",&two); // string called "BUFFER", then do
strcpy(buffer,"copy "); // my copying from there.
strcat(buffer,one); //
strcat(buffer," "); // I use the ">null" so you don't see
strcat(buffer,two); // DOS' "1 file copied" message.
strcat(buffer," >null");// It wouldn't look stylish in the
system(buffer); // middle of a menued screen !!
int86(0x10,&r,&r);
textbackground(7);
textcolor(0);
music[0]=19;
music[1]=20;
music[2]=21;
music[3]=17;
ba=3;
del=200;
sounds();
filemenu();
case 50: gotoxy(26,17);
cprintf("Move to: "); // Same as "COPY" above, but I delete the
scanf("%s",&two); // file also.
strcpy(buffer,"copy ");
strcat(buffer,one);
strcat(buffer," ");
strcat(buffer,two);
strcat(buffer," >null");
system(buffer);
unlink(one);
textbackground(7);
clrscr();
moveon=1;
music[0]=19;
music[1]=20;
music[2]=21;
music[3]=21;
music[4]=17;
music[5]=16;
del=140;
ba=5;
sounds();
menu();
case 51: gotoxy(26,17);
gotoxy(26,17);
cprintf("Erase file %s (y/N)?",one);
junk1=getch();
if(junk1==121) unlink(one);
if(junk1==89) unlink(one);
textbackground(7);
clrscr();
moveon=1; //Deletes the file and makes more music.
music[0]=12;
music[1]=7;
music[2]=10;
del=300;
ba=2;
sounds();
menu();
case 52: end(); //exits the program
case 27: int86(0x10,&r,&r);
music[0]=7;
music[1]=9; //creates the "popping" sound when opening or
music[2]=11; //closing the menu.
music[3]=13;
music[4]=15;
music[5]=17;
ba=5;
del=5;
sounds();
filemenu();
}
end();
}
void moremenu(void) //Used to display more than 114 files.
{
int cc,col,x,y,yy;
clrscr();
for(y=13;y<78;y +=13)
for(yy=1;yy<=23;yy++)
{ textbackground(7);
textcolor(0);
gotoxy(y,yy);
cprintf("▒");
}
textcolor(0);
for(cc=115;cc<num;cc++)
{
textbackground(7);
if(cc==b) { textcolor(YELLOW);
textbackground(3);
}
x=1;
col=cc-115;
if(cc>137){
col=cc-137;
x=14;
}
if(cc>160){
col=cc-160;
x=26;
}
if(cc>183){
col=cc-183;
x=38;
}
if(cc>206){
col=cc-206;
x=50;
}
if(cc>231){
col=cc-231;
x=62;
}
gotoxy(x,col);
cprintf(a[cc]);
textcolor(0);
}
}
void help(void) //My help screen.
{
system("prompt $e[0;30;47m");
clrscr();
printf("\n\n\n");
printf("\n ╔════════════════════════════════╗ ");
printf("\n ╔║ DAVE'S MENUCOPY Menuing System ║ ");
printf("\n ║╚═══════════════════════════════╦╝ ");
printf("\n ╚════════════════════════════════╝ ");
printf("\n");
printf("\n F1 Help screen ");
printf("\n Arrows move between files and directories ");
printf("\n Page-up goes to first file in list ");
printf("\n Page-Down moves to last file ");
printf("\n Escape exits on any screen ");
printf("\n Pressing Enter pulls up file menu ");
printf("\n \"\\\" toggles between directory and file menus");
printf("\n ┌─────────────────────────────────┐ ");
printf("\n -▒│ CREATED BY DAVE SMITH │▒- ");
printf("\n -▒│ I.D.F. COMPANY FORT WORTH TEXAS │▒- ");
printf("\n └─────────────────────────────────┘ ");
printf("\n\n\n");
getch();
clrscr();
}
void end(void) //Closes up the program and exits
{
system("prompt $e[0;37;40m");
clrscr();
textcolor(YELLOW);
gotoxy(28,5);
cprintf("To REGISTER this product");
textcolor(RED);
gotoxy(25,7);
cprintf("for more utilities, write me on");
gotoxy(29,9);
textcolor(CYAN);
cprintf("Compuserve 71441,2723");
printf("\n\n\n");
_setcursortype(_NORMALCURSOR);
exit(0);
}
int sort_fun(const void *g, const void *h) //Used with the QSORT function
{ //to alphabetize the files.
return( strcmp(g,h) );
}
void sounds(void) //Plays the music and sound effects using
{ //Turbo C++ "sound" function.
int chit;
for(chit=0;chit<=ba;chit++)
{
music[chit]=music[chit] * 100;
sound(music[chit]);
delay(del);
nosound();
}
ba=0; //sets our array integer to zero.
}
/************************************************/
/* */
/* You are welcome to any part of this program */
/* for use with your own customized utilities. */
/* */
/* You cannot however, use these for profit */
/* or personal gain on your part unless you've */
/* received written permission from me, the */
/* author. */
/* */
/* DAVE SMITH */
/* */
/************************************************/