Detection of loaded ANSI.SYS (two programs with different strategies). ---------------------------------------------------------------------- CHKANSI detects the presence of ANSI.SYS. Version 1.0, 30/04-94, Jim Groeneveld. ANSICHK detects the presence of ANSI.SYS. Version 1.0, 30/04-94, Jim Groeneveld. ANSI-COM demonstrates incompatibility of ANSICOM vs. 1.3 with standard ANSI.SYS. Distribution, application and copyright --------------------------------------- Distribution status: cardware, as a whole package (see contents). Copyright: Jim Groeneveld, Schoolweg 14, 8071 BC Nunspeet, Netherlands. These programs may freely be copied and used by anyone, whether commercial or not, provided a postcard is sent to the author's address indicating CHKANSI. If someone wants to change the program/routines those changes should be proposed to the author in order to maintain the program centrally. Redistribution of an incomplete or changed package is not allowed. However, it is allowed to use the unchanged C functions ChkAnsiCPR and ChkAnsiKKR, doing the actual job, the source code in CHK-ANSI.C and ANSI-CHK.C (and CHK-ANSI.H and ANSI-CHK.H), within any other program (whether commercial or not) as long as the original copyright notice and the author's name are included. The other function sources may be applied freely within any other program. Disclaimer ---------- The author is not liable for any negative consequences of the use or misuse of these routines. The package ----------- Contents of package: ANSI-CHK C 14092 04-30-94 1:00a Function ChkAnsiKKR detects ANSI.SYS ANSI-CHK H 1879 04-30-94 1:00a Header file for ANSI-CHK.C ANSI-COM C 3920 04-30-94 1:00a Demo of ANSI.COM incompatibility ANSI-COM EXE 11393 04-30-94 1:00a Executable of ANSI-COM.C ANSICHK C 2899 04-30-94 1:00a ANSICHK program source, result report ANSICHK EXE 12097 04-30-94 1:00a Executable ANSICHK detects ANSI.SYS ANSICHK MK 475 04-30-94 1:00a Make file for ANSICHK ANSIPRMT BAT 3805 04-30-94 1:00a Example batch file for demonstration CHK-ANSI C 24282 04-30-94 1:00a Function ChkAnsiCPR detects ANSI.SYS CHK-ANSI H 2475 04-30-94 1:00a Header file for CHK-ANSI.C CHKANSI C 2921 04-30-94 1:00a CHKANSI program source, result report CHKANSI DOC 10742 04-30-94 1:00a This documentation text file CHKANSI EXE 12959 04-30-94 1:00a Executable CHKANSI detects ANSI.SYS CHKANSI MK 475 04-30-94 1:00a Make file for CHKANSI FILE_ID DIZ 160 04-30-94 1:00a Short program, package description OPENREAD C 1289 04-30-94 1:00a File open and read auxiliary functions OPENREAD H 233 04-30-94 1:00a Header file for OPENREAD.C TOKEYBUF C 5069 04-30-94 1:00a Function ToKeyBuf feeds keyboard buffer TOKEYBUF H 450 04-30-94 1:00a Header file for TOKEYBUF.C Usage of CHKANSI and ANSICHK ---------------------------- Syntax (from the DOS prompt): CHKANSI [>nul] or ANSICHK [>nul] Example: see ANSIPRMT.BAT Exit values: 0 = ANSI.SYS not detected 1 = ANSI.SYS detected ( 2 = unknown, unable to open SCREEN for write ) ( 3 = unknown, unable to open KEYBOARD for read ) ( 4 = unknown, unable to read KEYBOARD ) ANSICHK only: 5 = unknown, unable to detect ANSI.SYS (out of test keys) Check these with ERRORLEVEL from DOS (see a DOS manual or book and the example). Side effect: clearing of keyboard buffer (necessary, see comments in sources), unless KEYBOARD definition in CHK-ANSI.H is 1 (see below) or unless the function ChkAnsiCPR is called with 1 as its first argument value (see below). Strategy of CHKANSI ------------------- ANSI detection is based upon sending a DSR escape sequence to the screen (stdout) and receiving a CPR escape sequence via stdin (see your ANSI.SYS documentation). This works as long as both stdin and stdout are not being redirected. It has appeared however that ANSI.SYS (of at least official DOS versions) does not explicitely use those devices, but CON instead. This made it possible to send DSR to CON and receive CPR from CON too, even while stdin and stdout may be redirected. A PD ANSI.COM, vs. 1.3 appears not to send its CPR via CON but probably only via (non-redirected) stdin, though it may receive DSR via CON. The current program (EXE) has been compiled using both CON devices for DSR output and CPR input and if CPR input via CON does not (yet) yield the CPR it is attempted to obtain it via not-redirected stdin (most optimal settings in CHK-ANSI.H: SCREEN=3 and KEYBOARD=4). The called function ChkAnsiCPR may be called from any application with either 0 or 1 as the first argument (there are more arguments, see CHK-ANSI.C). The argument value 0 indicates to search for the presence of ANSI.SYS and as a side effect to return the current cursor position via argument pointers. The argument value 1 indicates that ANSI.SYS (or any compatible ANSI driver) is surely known to be present (maybe checked firstly with value 0) and that only the current cursor position is desired from the function. This case has the advantage that it does not use the keyboard buffer at all and thus does not clear it either as a(n undesired) side effect. Strategy of ANSICHK ------------------- ChkAnsiKKR detects the presence of ANSI.SYS by redefining a key to another one (one is sufficient) using an ANSI escape sequence for KKR (Keyboard Key Reassignment), entering the original key into the keyboard buffer and check whether the redefinition or the original one is returned from CON. This only works all right if there still is space in the keyboard reassignment buffer in memory. This should always work with reading CON (KKR_KEYBOARD set to 3 in ANSI-CHK.H). However, that does not appear to work with ANSI.COM vs. 1.3 (C) 1988, Ziff Communications Co. PC Magazine by Michael J. Mefford, which reads the original key instead of the definition. If the read is done from stdin ANSI.COM vs. 1.3 indeed works OK, reading the definition (KKR_KEYBOARD set to 2 in ANSI-CHK.H). Problems with CHKANSI --------------------- If the EXE file appears to work incorrectly with your version of ANSI.SYS this may be due to a different device the ANSI.SYS expects its DSR from or it sends its CPR to. To solve that problem you may experiment with the SCREEN and KEYBOARD settings in CHK-ANSI.H and recompile CHKANSI.C. In any case it is expected that using both stdin and stdout as input and output devices should work always if neither of them is being redirected. Besides, it is expected that sending DSR to CON would work in all instances, while receiving CPR from CON may not always work, like with ANSI.COM vs. 1.3 (C) 1988 Ziff Communications Co. PC Magazine by Michael J. Mefford. If KEYBOARD is set to 4 (with which the current program has been compiled, the safest setting) any value of the first argument of the function ChkAnsiCPR does not have any effect. In that instance it is being set to 0 causing a regular check on ANSI.SYS's presence using the keyboard buffer. That has been induced because only requesting for CPR while ANSI.SYS is known to be present and not using the keyboard buffer for scratch would not allow ChkAnsiCPR to apply the second algorithm if the first one failed to detect ANSI.SYS (which happens if ANSI.COM 1.3 is the installed ANSI driver; see source CHK-ANSI.C); it would cause an unexpected and unwanted wait for user keyboard input. So if one applies the function ChkAnsiCPR with the value of 1 for the first argument one should select one of the explicit KEYBOARD values 0 to 3 in CHK-ANSI.H, not value 4, and make sure the compiled program runs correctly with it. Using ANSI.COM 1.3 would not allow to select KEYBOARD value 3. Problems with ANSICHK --------------------- If the EXE file appears to work incorrectly with your version of ANSI.SYS this may be due to a different device the ANSI driver expects its KKR from or it intercepts and sends its redefined input to. To solve that problem you may experiment with the KKR_SCREEN and KKR_KEYBOARD settings in ANSI-CHK.H and recompile ANSICHK.C. In any case it is expected that using both stdin and stdout as input and output devices should work always if neither of them is being redirected. Besides, it is expected that sending KKR to CON would work in all instances, while receiving the redefinition from CON may not always work, like with ANSI.COM vs. 1.3 (C) 1988 Ziff Communications Co. PC Magazine by Michael J. Mefford. Help ---- If you can not solve the problem(s) you may notify me of that and send me a copy of your ANSI.SYS version (on disk or by Email: ZIPped and UUEncoded) and possibly a copy of your two DOS's system files and COMMAND.COM, because some ANSI.SYS programs check for a correct, matching DOS version. isatty() -------- For some purposes it might be desired to know whether stdout is redirected. In specific instances one might decide not to apply ANSI escape codes, even though ANSI.SYS might be detected using one of the functions ChkAnsiCPR or ChkAnsiKKR, if these are being written to a redirected stdout. That is up to the programmer applying my routines. The application of Zortech's function isatty() to check for redirected input and/or output is not exclusive because it does not discriminate between redirection to CON (same as no redirection), AUX, PRN, NUL, LPT1 and so on. Who knows a solid way to discriminate between not redirected stdin (