home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
CALLDOS.ZIP
/
CALLDOS.C
next >
Wrap
Text File
|
1990-09-11
|
5KB
|
162 lines
/* Rev 0.1 - document "...\" case */
/* Compiles with IBM C/2 1.1 and its MAKE/2 2.0 using: */
/*
###############################################################
# Make file for CALLDOS.C #
# #
# use MAKE CALLDOS.C #
# #
###############################################################
model=S # use large model when debugging -- bugs JUMP out at you
mode=p
linklibs=$(model)libce$(mode).lib os2.lib
CFLAGS=-A$(model) -Lp -Oxrn -Zpel -W3 -G2 -Gw -J -nologo
LINK=D:\C\Bin\Link
calldos.exe : calldos.obj
$(LINK) calldos.obj,calldos.exe/A:16/FAR/NOD/PACKD/ST:3000,NUL.MAP,$(linklibs);
calldos.obj : calldos.c
!CL $(CFLAGS) -c $?
*/
/* Merge of Peter Fitzsimmons' CALLBOX.C and 2DOS.C programs */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INCL_DOS
#define INCL_DOSERRORS
#define INCL_WINSWITCHLIST
#include <os2.h>
void jump2dos(void)
{
USHORT num, i;
void *buf = malloc(32000);
SWENTRY *swe;
HSWITCH fgHandle;
SEL selGlobalSeg, selLocalSeg;
GINFOSEG FAR * volatile pgis;
UCHAR sgDos;
/* find out who is in the foregound, so we know who to switch
* back to after the dos box is done. This method only works
* if the foreground session is NOT a pm program. If it is a
* pm program, the "Task List" will be the active app after
* the task switch
*/
DosGetInfoSeg(&selGlobalSeg, &selLocalSeg);
pgis = MAKEPGINFOSEG(selGlobalSeg);
fgHandle = WinQuerySwitchHandle(0L, pgis->pidForeground);
/* Find the switch list handle of the DOS box: */
num = WinQuerySwitchList(0L, buf, 32000);
swe = (SWENTRY *)((USHORT *)buf + 1);
for(i=0; i<num; i++){
if(!strcmp("DOS", swe[i].swctl.szSwtitle)){
WinSwitchToProgram(swe[i].hswitch);
break;
}
}
free(buf);
if(i==num){
printf("This system is configured without a dos box!\n");
return;
}
if(fgHandle){
DosSleep(500L); /* give a moment for the task switch */
sgDos = pgis->sgCurrent;
/*
* Wait (poll) current screen group -- waiting for the DOS
* program to end. I don't like polling, but this is the only
* solution I can come up with. If you don't mind the "Task
* List" always being brought the the fore after the dos progam
* ends, you can forget about all of this and exit() after the
* WinSwitchToProgram(), above.
*/
while( sgDos == pgis->sgCurrent )
DosSleep(500L);
WinSwitchToProgram(fgHandle); /* back to where we started */
}
}
#if 0
Comments
--------
The only reason this program works is becuase WinSwitchToProgram()
allows you to:
1) Switch a session to the foreground which is not one of your own
child sessions.
2) Switch a session to the foreground when you are not running
in the foreground yourself.
Acording to the documentation (IBM, v1.20), you are not supposed to
be able to do either of these things. However, the "File Manager",
from what I can figure out, uses this method to switch to the DOS
box too, so I am confident that this program will continue to work
under OS/2 1.2x.
Peter Fitzsimmons, A:WARE Inc. Thu 09-06-1990 22:15:11
#endif
void main(int argc, char **argv)
{
HFILE hf;
USHORT rc, dummy;
static char cmd[256];
int i;
if( argc < 2 ){
printf("\nUsage: CALLDOS <command>\n\n");
printf(" Each <command> with blanks should be enclosed by quotes.\n");
printf(" Any quoted <command> ending with a '\\' must use '\\ '.\n\n");
printf("For example:\n\n");
printf("CALLDOS C: \"CD \\OS2\" \"DIR > \\DIR.LST\" \"CD \\ \"\n\n");
printf("will make C:\\OS2 current, list the files to C:\\DIR.LST,\n");
printf("and switch back to C:\\.\n\n");
printf("If invoked while a PM session is current, the focus returns\n");
printf("to the Task List, else returns to the current session.\n\n");
exit (255);
}
cmd[0] = '\0';
for(i=1; i<argc; i++){
strcat(cmd, "\x80 ");
strcat(cmd, argv[i]);
strcat(cmd, "\r");
if( i != (argc-1) )
strcat(cmd, " ");
}
rc = DosOpen("DOS$", &hf, &dummy, 0L, FILE_NORMAL, FILE_OPEN,
OPEN_ACCESS_WRITEONLY | OPEN_SHARE_DENYNONE |
OPEN_FLAGS_FAIL_ON_ERROR, 0L);
if(!rc){
rc = DosWrite(hf, cmd, strlen(cmd)+1, &dummy);
DosClose(hf);
if(!rc)
jump2dos();
else if(rc == ERROR_NOT_READY) {
printf("A program is already running in the DOS box\n");
exit (1);
}
else {
printf("Unexpected OS/2 error SYS%04u\n", rc);
exit (2);
}
}
else {
printf("DOS.SYS not installed (sys%04u)\n", rc);
exit (3);
}
DosBeep(1000, 100);
}