home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Current Shareware 1994 January
/
SHAR194.ISO
/
desqview
/
dvquit.zip
/
DVQUIT.CPP
next >
Wrap
C/C++ Source or Header
|
1993-08-16
|
11KB
|
381 lines
/**************************************************************************/
/* */
/* Program Name: DVQUIT */
/* System: General Purpose. */
/* Date: 08/02/93 */
/* Revision Date: - */
/* Created By: John Byrne */
/* Program Language: C++ Compiler */
/* Modules Called: - */
/* Calling Modules: - */
/* Parameters: /F: copy from file */
/* /T: copy to file */
/* /Q: Quit Desqview option <QUIT> NOQUIT */
/* /A: File Action <FLUSH> CLOSE */
/* /W: File containing open windows names */
/* */
/* Files Used: - */
/* Description: Program to quit Desqview gracefully. */
/* The program flushes or optionally closes all files opened by DOS. */
/* This is done by using the /A: action parameter. FLUSH will commit any */
/* file output that is buffered to disk, updates the file's directory */
/* entry, and leaves the file opened. The CLOSE option does the same */
/* except it closes the file. The /Q: option permits quitting Desqview */
/* or performing any other options before exiting, leaving Desqview */
/* active. QUIT is the default, NOQUIT does not quit Desqview. NOQUIT */
/* is useful in tandem with the /A: option if a global update of all */
/* output files without quitting Desqview is desired. You may have a */
/* checkpoint in a batch file where you want to insure that all buffers */
/* have been committed to disk. To accomplish this use: */
/* DVQUIT /Q:NOQUIT /A:FLUSH */
/* The /F: and /T: options allow the user to copy a file to another prior */
/* to exiting. This allows a user selected batch file to execute within */
/* the batch file that started Desqview. */
/* The /W: option is used to specify the name of a file that contains the */
/* name of open windows to check. If any of these windows are open, the */
/* program displays an error message and exits without performing any */
/* functions. */
/**************************************************************************/
#include <stdlib.h>
#include <dos.h>
#include <IO.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <fstream.h>
#include <ctype.h>
extern "C"
{
#include "dvapi.h"
}
#define required (0x0200 + 26)
#define MAX_WIN_OPEN 16
struct DCB_REC
{
unsigned int dcb_nusers;
unsigned int dcb_mode;
unsigned char dcb_datrb;
unsigned char dcb_dvatr;
unsigned char dcb_atrb2;
void far *dcb_pdrvr;
unsigned int dcb_frstc;
unsigned int dcb_modtm;
unsigned int dcb_moddt;
long dcb_totsiz;
long dcb_curpos;
unsigned int dcb_clsctr;
unsigned int dcb_curcls;
unsigned int dcb_dirsec;
unsigned char dcb_dirndx;
char dcb_fname[8];
char dcb_fext[3];
unsigned int dcb_fill1;
unsigned int dcb_fill2;
unsigned int dcb_fill3;
void near *dcb_owner;
unsigned int dcb_fill4;
unsigned int dcb_fill5;
unsigned int dcb_fill6;
unsigned int dcb_fill7;
} far *dcb_ptr;
union REGS regs;
struct SREGS sregs;
struct CVT_REC
{
void far *cvt_dpb;
void far *cvt_dcb_blk;
void far *cvt_clk;
void far *cvt_con;
unsigned int cvt_mbs;
void far *cvt_elr;
void far *cvt_ldt;
void far *cvt_fcb;
unsigned int cvt_fks;
unsigned char cvt_bld;
unsigned char cvt_lgd;
} far *cvt_ptr;
struct DCBLNK_REC
{
void far *dcblnk_next_blk;
unsigned int dcblnk_blks;
} far *dcblnk_ptr;
struct PSP_REC
{
unsigned int psp_num_handles;
char far *psp_handle_table;
} far *handle_table;
unsigned long mywin;
char check_for_open_windows(char, char *);
main(int argc, char *argv[])
{
int j;
int TEMP_F;
int version;
unsigned int action_intr;
void far *f_p;
unsigned char save_handle;
char command_switch;
char in_file_name[50];
char out_file_name[50];
char check_file_name[50];
char in_char;
fstream *in_file, *out_file;
char ffile_parm, tfile_parm, quit_parm, chkwin_parm;
version = api_init();
if(version < required)
{
cout <<"\nThis program requires DesqView version "
<<required/256 <<"."
<<setw(2) <<setfill('0') <<required%256
<<" or later.\n";
exit(1);
}
api_level(required);
mywin = win_me();
if((_osmajor > 5) || (_osmajor < 4))
{
cout <<"Requires MSDOS Version 4.00 or 5.00\n";
exit(1);
}
if((argc == 2) && (strcmp(argv[1],"?") == 0))
{
cout <<"\n" <<argv[0] <<"\n"
<< " /F:file - File to copy from\n"
<< " /T:file - File to copy to\n"
<< " /A:<FLUSH>/CLOSE - Function to perform on open files\n"
<< " /Q:<QUIT>/NOQUIT - Quit/No quit DesqView\n"
<< " /W:file - File for open window names to check\n";
exit(0);
}
action_intr = 0x6800; /* Flush files is default */
quit_parm = 1; /* Quit DesqView is default */
ffile_parm = NULL;
tfile_parm = NULL;
chkwin_parm = NULL;
for(j=1;j < argc;++j)
{
if(strlen(argv[j]) > 3)
{
++argv[j]; /* hop over the parameter prefix slash */
command_switch = toupper(argv[j][0]);
argv[j] += 2; /* hop over rest of parameter prefix */
}
else
{
continue;
}
switch(command_switch)
{
case 'F': ffile_parm = 1;
strcpy(in_file_name,argv[j]);
break;
case 'T': tfile_parm =1;
strcpy(out_file_name,argv[j]);
break;
case 'W': chkwin_parm = 1;
strcpy(check_file_name,argv[j]);
break;
case 'A': if(stricmp(argv[j],"FLUSH") == 0)
{
action_intr = 0x6800;
/* Flush output buffers, don't close */
}
else if(stricmp(argv[j],"CLOSE") == 0)
{
action_intr = 0x3E00;
/* Close any file opened for output */
}
else
{
cout <<"\nInvalid Action Code - "
<< "Must be FLUSH or CLOSE\n";
exit(1);
}
break;
case 'Q': if(stricmp(argv[j],"QUIT") == 0)
{
quit_parm = 1;
}
else if(stricmp(argv[j],"NOQUIT") == 0)
{
quit_parm = 2;
}
else
{
cout <<"\nInvalid Quit Code - "
<<"Must be QUIT or NOQUIT\n";
exit(1);
}
break;
default: argv[j] -= 3; /* Add back parm prefix */
cout << "\nInvalid parameter - "
<< argv[j] << "\n";
exit(1);
}
}
if((ffile_parm + tfile_parm) == 1)
{
if(ffile_parm == 1)
{
cout << "\nTo file parameter is missing\n";
exit(1);
}
if(tfile_parm == 1)
{
cout << "\nFrom file parameter is missing\n";
exit(1);
}
}
if((ffile_parm + tfile_parm) == 2)
{
fstream in_file(in_file_name,
ios::in);
if(in_file.bad())
{
cout << "\nUnable to open From File\n";
exit(1);
}
fstream out_file(out_file_name,ios::out);
if(out_file.bad())
{
cout << "\nUnable to open To File\n";
exit(1);
}
in_file.get(in_char);
while(!in_file.eof())
{
out_file.put(in_char);
in_file.get(in_char);
}
in_file.close();
out_file.close();
}
if(chkwin_parm == 1)
{
if(check_for_open_windows(chkwin_parm, check_file_name) == 2)
{
exit(1);
}
}
api_beginc();
handle_table = (PSP_REC far *)MK_FP(_psp, 0x32);
regs.x.ax = 0x5200;
segread(&sregs);
intdosx(®s, ®s, &sregs);
cvt_ptr = (CVT_REC far *) MK_FP(sregs.es, regs.x.bx);
dcblnk_ptr = (DCBLNK_REC far *) cvt_ptr->cvt_dcb_blk;
do
{
f_p = (char far *)dcblnk_ptr + 6;
dcb_ptr = (DCB_REC far *) f_p;
for(j=0;j<dcblnk_ptr->dcblnk_blks;++j)
{
if((dcb_ptr->dcb_nusers > 0) &&
(dcb_ptr->dcb_mode & (O_WRONLY | O_RDWR)))
{
TEMP_F = open("AUX", O_APPEND | O_BINARY,
S_IREAD | S_IWRITE);
save_handle = handle_table->psp_handle_table[TEMP_F];
handle_table->psp_handle_table[TEMP_F] = j;
regs.x.ax = action_intr;
regs.x.bx = TEMP_F;
intdos(®s, ®s);
handle_table->psp_handle_table[TEMP_F] = save_handle;
close(TEMP_F);
}
++dcb_ptr;
}
dcblnk_ptr = (DCBLNK_REC far *)dcblnk_ptr->dcblnk_next_blk;
}
while((unsigned int) dcblnk_ptr != 0xFFFF); // only look at last word of
if(quit_parm == 1)
{
win_allow(mywin,ALW_CLOSE);
win_allow(mywin,ALW_QUIT);
api_pushkey('Y');
api_pushkey('Q');
api_pushkey(0xFC00);
}
api_endc();
return(0);
}
char check_for_open_windows(char chkwin_parm, char *check_file_name)
{
int j;
int k;
int open_windows = 0;
int chk_rcds;
char *dont_close[MAX_WIN_OPEN];
fstream *check_file;
char chkwin_msg[] = " Close the following window(s)\n"
" and try this command again!\n"
"────────────────────────────────\n";
char msg_esc[] = "\n << Press Esc to Exit >>";
char *msg_string;
check_file = new fstream(check_file_name,ios::in);
if(check_file->bad())
{
delete(check_file);
cout << "\nUnable to open Check Window File\n";
exit(1);
}
for(chk_rcds=0;chk_rcds<MAX_WIN_OPEN && !check_file->eof();
++chk_rcds)
{
*check_file >> (dont_close[chk_rcds] = new char[40]);
}
check_file->close();
delete(check_file);
msg_string = (char *) malloc(strlen(chkwin_msg) + 1);
strcpy(msg_string, chkwin_msg);
for(j=0;j<chk_rcds;++j)
{
if(mal_find(dont_close[j], strlen(dont_close[j])))
{
chkwin_parm = 2;
++open_windows;
msg_string = (char *) realloc(msg_string,
strlen(msg_string) + strlen(dont_close[j]) + 5);
strcat(msg_string, " ");
strcat(msg_string, strupr(dont_close[j]));
strcat(msg_string, "\n");
}
}
if(chkwin_parm == 2)
{
msg_string = (char *) realloc(msg_string,
strlen(msg_string) + strlen(msg_esc) + 1);
strcat(msg_string, msg_esc);
win_disperor(mywin, msg_string, strlen(msg_string),
open_windows + 5, 32, 1, 2);
}
free(msg_string);
for(j=0;j<chk_rcds;++j)
{
delete dont_close[j];
}
return(chkwin_parm);
}