[comp.sys.ibm.pc] Bat file using ESC seq needs to find if DEVICE=ANSI.SYS was set

msicv01@ms3.UUCP (Jay G. Heiser) (04/06/88)

I've recently written an intall batch file that any of the users supported
by my info center can use to install MSKERM.EXE & the appropriate init file
in a KERMIT directory and install a batch file to run it.

Getting ambitious. I took advantage of the colors, modes, & cursor posi-
tioning made possible with the ANSI.SYS device driver.  Unfortunately,
many of the PCs not under my control do not have their CONFIG.SYS files
properly set up to use ANSI.  Since I've tried to make install.bat as
bullet proof as possible, I need a way to test before using any ESC seq-
uences whether or not the driver has been set.  How can I do that?

	1) Best would be a utility that checks to see if the driver has
been invoked & returns the appropriate error code.  I can get this written
in ASM if someone can tell me how to find the existence of the driver in
memory (this isn't an unusual request, such a util must exist already.)
	2) I could test for the existence of the string 'ANSI.SYS' in
CONFIG.SYS.  In most cases, this would be adequite.  Unfortunately, FIND
doesn't return an errorlevel.  Turbo-C GREP doesn't either.  Anyone know of
a way to test for the existence of a string in a file?
	3)BTW DEVICE isn't an environmental variable, so echo %device% won't
work.  Also, the ANSI driver can be started ONLY through CONFIG.SYS, so I
can't carry it around on the disk containing install.bat unless I use that
as the boot disk.

Any Suggestions?    Thank you,

-- 
Jay Heiser                   UUCP: ..!umd5!vrdxhq!ms3!msicv01
                             ARPA: msicv01@hios-pent.arpa

jcmorris@mitre-bedford.ARPA (Joseph C. Morris) (04/07/88)

In article <767@ms3.UUCP> msicv01@ms3.UUCP (Jay G. Heiser) writes:
>                       ...I need a way to test before using any ESC seq-
>uences whether or not the [ANSI.SYS] driver has been set.  How can I do that?

Try this from a program:

    Flush any waiting keyboard input
    characters.

    Write to screen:  <ESC>[6n           (Request cursor position report)

    Test to see if any characters 
    are waiting in the keyboard buffer

    If not, then ANSI.SYS (or an equivalent
    driver) is NOT present.

    Eat any waiting characters.

Good luck.

davidsen@steinmetz.ge.com (William E. Davidsen Jr) (04/08/88)

From the DOS3.00 tech ref manual, pg 2-10:

  If you send the console device a "Device Ststus Report" escape
sequence, which is ESC[6n it will return a "Cursor Position Report"
which is ESC[#;#R. The first # is line, the second column. Don't know if
they're 0 or 1 based.

   Just remember to do a non-blocking read (raw read) when checking for
the return value, as you'll hang waiting for keyboard input otherwise.
-- 
	bill davidsen		(wedu@ge-crd.arpa)
  {uunet | philabs | seismo}!steinmetz!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me

slaghtrl@lafcol.UUCP (Slaght Ralph L) (04/12/88)

In article <28501@linus.UUCP>, jcmorris@mitre-bedford.ARPA (Joseph C. Morris) writes:
> In article <767@ms3.UUCP> msicv01@ms3.UUCP (Jay G. Heiser) writes:
> >                       ...I need a way to test before using any ESC seq-
> >uences whether or not the [ANSI.SYS] driver has been set.  How can I do that?
> 
Here's a fragment of C code which works for me.  It compiles under
MS C 5.0:

union REGS inregs,outregs;

printf("\n\033[2J"); /* prints a newline and then tries to clear the screen */
inregs.h.ah = 3;
inregs.h.bh = 0;
int86(0x10,&inregs,&outregs);
if (outregs.h.dh != 0) /* if cursor is not at top of screen then...*/
	{
	printf("ANSI.SYS is not loaded on this system.  In order for the\n");
   printf("program to work properly you must have ANSI.SYS on the system, and\n");
   printf("you must have a line in your CONFIG.SYS file which reads:\n");
   printf("      device=ansi.sys                                   \n");
   printf("\nAfter inserting such a line into your CONFIG.SYS file, please\n");
   printf("reset your system and rerun  .......\n");
   printf("\n***********Hit any key to exit******************");
   ch = getch();
	exit(1);
   }

mds7958@ritcv.UUCP (Mark Sicignano) (04/14/88)

> In article <28501@linus.UUCP>, jcmorris@mitre-bedford.ARPA (Joseph C. Morris) writes:
> > In article <767@ms3.UUCP> msicv01@ms3.UUCP (Jay G. Heiser) writes:
> > >...I need a way to test before using any ESC sequences 
> > >whether or not the [ANSI.SYS] driver has been set.  How can I do that?
> > 
> Here's a fragment of C code which works for me.  It compiles under
> MS C 5.0:
> 
> union REGS inregs,outregs;
> 
> printf("\n\033[2J"); /* prints a newline and then tries to clear the screen */

I don't think this will work?  At least not on my version of MS-DOS (3.1)
Even without ansi.sys installed, the \003[2J sequence still clears my screen
and puts the cursor at HOME position.

However the escape sequence \003[H is only recognized when ansi.sys is used,
so this will work.

-mark