REXX Tips & Tricks, Version 2.80


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


Check if ANSI is active - 2 -





 
/* sample routine to check if ANSI is activated (using REXXUTIL)      */
/* based on a idea and code of Erik Schneller                         */
/* (see EMail Addresses)                                              */
/*                                                                    */
/* see also Check if ANSI is active - 1 -                             */
/*                                                                    */
  i = CheckAnsi()
  if i = 1 then
    say "ANSI is activated"
  else
    if i = 0 then
      say "ANSI is not activated."
    else
      say "Error detecting ANSI."

exit 0

/* ------------------------------------------------------------------ */
/* function: Check if ANSI is activated                               */
/*                                                                    */
/* call:     CheckAnsi                                                */
/*                                                                    */
/* where:    -                                                        */
/*                                                                    */
/* returns:  1 - ANSI support detected                                */
/*           0 - no ANSI support available                            */
/*          -1 - error detecting ansi                                 */
/*                                                                    */
/* note:     Tested with the German and the US version of OS/2 3.0    */
/*           based on a idea and code of Erik Schneller               */
/*           (see EMail Addresses)                                    */
/*                                                                    */
/*                                                                    */
CheckAnsi: PROCEDURE
  thisRC = -1

                        /* install a local error handler              */
  SIGNAL ON ERROR Name InitAnsiEnd

                    /* register the function SysCurPos from REXXUTIL  */
  call rxFuncAdd "SysCurPos", "REXXUTIL", "SysCurPos"

                    /* get and save the current cursor position       */
  curPos = SysCurPos()

                    /* write a CR/LF and the ANSI code for CursorUp   */
  call charOut , D2C(13) || "1B"x || "[1A"

                    /* now get the current cursor position            */
  NewPos=SysCurPos()

                    /* compare the new position to the old position   */
  if LEFT( NewPos,2 ) == LEFT( curPos,2 ) THEN
  do
                    /* ANSI support is OFF                            */
     thisRC = 0

                /* goto the begin of the line and delete the garbage  */
     call CharOut, D2C(13) || copies( " ",4 ) || D2C(13)
  end /* if left( ... */
  else
  do
                    /* ANSI support is ON                             */

                    /* restore the old cursor position                */
    call CharOut , "1B"x || "[B"
    thisRC = 1
  end /* else */

InitAnsiEnd:
RETURN thisRC


  

Inf-HTML End Run - Successful