home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / lsmt213c.zip / ansi_say.cmd < prev    next >
OS/2 REXX Batch file  |  1996-10-09  |  21KB  |  437 lines

  1. /* Ansi_Say.CMD */
  2.  
  3.         /****************************************************************************************/
  4.         /* Version 1.     29 dec 95      General mainstream.                                    */
  5.         /*                               Define lay-out of .RSC file.                           */
  6.         /*--------------------------------------------------------------------------------------*/
  7.         /* Version 2.     30 dec 95      Read .RSC completely into memory.                      */
  8.         /*                               This allows the Ansi Topics to be in any order.        */
  9.         /*--------------------------------------------------------------------------------------*/
  10.         /* Version 3.      2 jan 96      Remember the last Ansi Color sequence.                 */
  11.         /*                               This allows control over the Variable's color          */
  12.         /*                               to be stored inside the .RSC file.                     */
  13.         /****************************************************************************************/
  14.  
  15.  
  16.         /****************************************************************************************/
  17.         /* Needs :      parameter 1 = name of .RSC file, containing the Ansi Message Topics.    */
  18.         /*--------------------------------------------------------------------------------------*/
  19.         /* Needs :      parameter 2+= name(s) of the Topic(s) to be displayed from .RSC file.   */
  20.         /*--------------------------------------------------------------------------------------*/
  21.         /* Optional :   parameter 2+= debug-switch : /Debug     Full trace for supervisor       */
  22.         /* Optional :   parameter 2+= debug-switch : /Verbatim  Partial trace for administrator */
  23.         /****************************************************************************************/
  24.  
  25.         /****************************************************************************************/
  26.         /* Needs External Rexx : RgUtil.CMD, available via PATH= (to register the RexxUtil.DLL) */
  27.         /****************************************************************************************/
  28.  
  29.  
  30.         /**************************************/
  31.         /* Start recording the elapsed time : */
  32.         /**************************************/
  33.         Call Time('R');
  34.  
  35.         /*************************************/
  36.         /* Register the RexxUtil Functions : */
  37.         /*************************************/
  38.         Call RgUtil '/M';
  39.  
  40.         /****************/
  41.         /* ? who am I ? */
  42.         /****************/
  43.         Parse SOURCE . . Who_Am_I .;
  44.         Who_Am_I_Drive=FileSpec('Drive',Who_Am_I);
  45.         Who_Am_I_Path=FileSpec('Path',Who_Am_I);
  46.         Who_Am_I_Name=Reverse(SubStr(Reverse(FileSpec('Name',Who_Am_I)),5));
  47.  
  48.         /****************/
  49.         /* Initialize : */
  50.         /****************/
  51.         Parse VALUE SysTextScreenSize() WITH On_The_Screen_ROW On_The_Screen_COL;
  52.         On_The_Screen_Max=Min(40,On_The_Screen_ROW) - 3;
  53.         On_The_Screen_N=0;
  54.         N_Errors=0;
  55.         Variable_Indicator='~';
  56.  
  57.         /************************************************/
  58.         /* Accept the name of the ANSI Resources File : */
  59.         /************************************************/
  60.         Parse ARG Name_Of_Resource_File The_Rest;
  61.  
  62.         /***************************/
  63.         /* Hey dude, do it right ! */
  64.         /***************************/
  65.         If Strip(Name_Of_Resource_File) = ''
  66.         Then Do;
  67.              Call Something_Was_Wrong;
  68.              Call Say_This ' The name of the "RSC" file was not specified.';
  69.              Call Say_This ' Check the call syntax and try again.';
  70.              Call Say_This Center('ABORT',79,'*');
  71.              Call Clean_Up_And_Go_Home;
  72.              Return '';
  73.              End;
  74.  
  75.         /*******************************************************/
  76.         /* Accept the other parameters from the command line : */
  77.         /*******************************************************/
  78.         i=0;
  79.         Do Forever;
  80.            If The_Rest = ""
  81.            Then Do;
  82.                 Arg_Topic.0=i;
  83.                 Leave;
  84.                 End;
  85.            Else Do;
  86.                 i=i+1;
  87.                 Parse VAR The_Rest Arg_Topic.i The_Rest;
  88.                 /*******************************************/
  89.                 /* Isolate the command line DEBUG switch : */
  90.                 /*******************************************/
  91.                 If Left(Arg_Topic.i,1) = '/'
  92.                 Then Do;
  93.                      RENTOKIL=Arg_Topic.i;
  94.                      i=i-1;
  95.                      End;
  96.                 Else Do;
  97.                      Arg_Topic.i=Translate(Arg_Topic.i);
  98.                      End;
  99.                 End;
  100.            End;
  101.  
  102.         /********************************************************/
  103.         /* Accept the /DEBUG or /VERBATIM command line switch : */
  104.         /********************************************************/
  105.         RENTOKIL=Left(Translate(RENTOKIL||'x'),2);
  106.  
  107.         /**************************************/
  108.         /* Analyse the name of the RSC File : */
  109.         /**************************************/
  110.         RSC_File_Drive=FileSpec('Drive',Name_Of_Resource_File);
  111.         RSC_File_Path=FileSpec('Path',Name_Of_Resource_File);
  112.         RSC_File_Name=FileSpec('Name',Name_Of_Resource_File);
  113.         RSC_File_Ext=Pos('.',RSC_File_Name);
  114.         If RSC_File_Ext = 0
  115.         Then Do;
  116.              Qualified_Name=RSC_File_Drive || RSC_File_Path || RSC_File_Name || '.RSC';
  117.              End;
  118.         Else Do;
  119.              Qualified_Name=RSC_File_Drive || RSC_File_Path || RSC_File_Name;
  120.              End;
  121.  
  122.         /*************************************************************************************/
  123.         /* Verify existence of the RSC File : (F) Files only, (O) only names, all attributes */
  124.         /*************************************************************************************/
  125.         Sys_RC=SysFileTree(Qualified_Name,'Sys_File_Tree','FO','*****','*****');
  126.         If Sys_RC \= 0
  127.         Then Do;
  128.              Call Something_Was_Wrong;
  129.              Call Say_This ' Invalid returncode "' || Sys_RC || '" from SysFileTree.';
  130.              Call Say_This ' The "RSC" file "' || Qualified_Name || '" can not be found.';
  131.              Call Say_This ' Check the file name and try again.';
  132.              Call Say_This Center('ABORT',79,'*');
  133.              Call Clean_Up_And_Go_Home;
  134.              Return '';
  135.              End;
  136.         If Sys_File_Tree.0 = 0
  137.         Then Do;
  138.              Call Something_Was_Wrong;
  139.              Call Say_This ' The "RSC" file "' || Qualified_Name || '" can not be found.';
  140.              Call Say_This ' Check the file name and try again.';
  141.              Call Say_This Center('ABORT',79,'*');
  142.              Call Clean_Up_And_Go_Home;
  143.              Return '';
  144.              End;
  145.  
  146.         /*****************************************/
  147.         /* When the RSC is empty... what to do ? */
  148.         /*****************************************/
  149.         If \Lines(Qualified_Name)
  150.         Then Do;
  151.              Call Something_Was_Wrong;
  152.              Call Say_This ' The "RSC" file "' || Qualified_Name || '" is empty.';
  153.              Call Say_This ' Check the file and try again.';
  154.              Call Say_This Center('ABORT',79,'*');
  155.              Call Clean_Up_And_Go_Home;
  156.              Return '';
  157.              End;
  158.  
  159.         /*****************************/
  160.         /* Analyse the topics list : */
  161.         /*****************************/
  162.         If Arg_Topic.0=0
  163.         Then Do;
  164.              Call Something_Was_Wrong;
  165.              Call Say_This ' No topic names were specified.';
  166.              Call Say_This ' Check the call syntax and try again.';
  167.              Call Say_This Center('ABORT',79,'*');
  168.              Call Clean_Up_And_Go_Home;
  169.              Return '';
  170.              End;
  171.  
  172.         /***********************************/
  173.         /* Read all lines in the .RSC file */
  174.         /***********************************/
  175.         i=0;
  176.         j=0;
  177.         Do While Lines(Qualified_Name);
  178.            RSC_Line=LineIn(Qualified_Name);
  179.            /**********************/
  180.            /* Pick up position 1 */
  181.            /**********************/
  182.            Parse VAR RSC_Line Delim +1 RSC_Rest;
  183.            /******************************************/
  184.            /* When it is a comment line, forget it : */
  185.            /******************************************/
  186.            If Delim = '*'
  187.            Then Do;
  188.                 Iterate;
  189.                 End;
  190.            /********************************************************/
  191.            /* When it is a Topic Identification Line, analyze it : */
  192.            /********************************************************/
  193.            If Delim = '['
  194.            Then Do;
  195.                 Parse VAR RSC_Rest Topic ']' .;
  196.                 i=i+1;
  197.                 RSC_Topic.i=Translate(Topic);
  198.                 RSC_Topic_First.i=0;
  199.                 RSC_Topic_Last.i=0;
  200.                 Iterate;
  201.                 End;
  202.            /**********************************************************/
  203.            /* Otherwise, it is an Ansi Message Line for this topic : */
  204.            /**********************************************************/
  205.            j=j+1;
  206.            RSC_Line.j=RSC_Line;
  207.            If RSC_Topic_First.i=0
  208.            Then Do;
  209.                 RSC_Topic_First.i=j;
  210.                 End;
  211.            RSC_Topic_Last.i=j;
  212.  
  213.            End;                                         /* do while lines()*/
  214.  
  215.         RSC_Topic.0=i;
  216.         RSC_Line.0=j;
  217.  
  218.         /***********************/
  219.         /* Close the .RSC file */
  220.         /***********************/
  221.         CL_RC=Stream(Qualified_Name,'Command','CLOSE');
  222.         If CL_RC \='READY:'
  223.         Then Do;
  224.              Call Something_Was_Wrong;
  225.              Call Say_This ' *** Fatal Error "' || CL_RC || '"';
  226.              Call Say_This ' *** during Close of "' || Qualified_Name || '"';
  227.              Call Say_This Center('ABORT',79,'*');
  228.              Call Clean_Up_And_Go_Home;
  229.              Return '';
  230.              End;
  231.  
  232.  
  233.         /**************************************************/
  234.         /* The Ansi Message to be shown to the end user : */
  235.         /**************************************************/
  236.         Ansi_Message='';
  237.         /********************************************************/
  238.         /* Remember the relative row of the Ansi Message Line : */
  239.         /********************************************************/
  240.         Parse VALUE SysCurPos() WITH Variable_Row Variable_Column;
  241.         /***************************************************/
  242.         /* The Result to be returned to the calling Rexx : */
  243.         /***************************************************/
  244.         To_Be_Returned='';
  245.  
  246.         /*******************************/
  247.         /* Scan all Requested Topics : */
  248.         /*******************************/
  249.         Do a=1 To Arg_Topic.0;
  250.            /******************************************/
  251.            /* Search this Topic in the .RSC Topics : */
  252.            /******************************************/
  253.            Do b=1 To RSC_Topic.0;
  254.               If RSC_Topic.b=Arg_Topic.a
  255.               Then Do;
  256.                    Vars_Found=0;
  257.                    /*******************************/
  258.                    /* Fetch the Requested Lines : */
  259.                    /*******************************/
  260.                    Do c=RSC_Topic_First.b To RSC_Topic_Last.b;
  261.                       /********************************/
  262.                       /* Construct the Ansi Message : */
  263.                       /********************************/
  264.                       Ansi_Message=Ansi_Message || '0A0D'x || RSC_Line.c;
  265.                       /********************************************************/
  266.                       /* Remember the relative row of the Ansi Message Line : */
  267.                       /********************************************************/
  268.                       Variable_Row=Variable_Row+1;
  269.                       If Pos('1B'x || '[2J',RSC_Line.c) > 0
  270.                       Then Do;
  271.                            Variable_Row=0;
  272.                            End;
  273.                       /*******************************************************/
  274.                       /* Check for the presence of a Variable in this line : */
  275.                       /*******************************************************/
  276.                       Somewhere=Pos(Variable_Indicator,RSC_Line.c);
  277.                       If Somewhere=0
  278.                       Then Do;
  279.                            Iterate;
  280.                            End;
  281.                       /*******************************************************/
  282.                       /* Search for the place of the Variable in this line : */
  283.                       /*******************************************************/
  284.                       Variable_Color='';
  285.                       Variable_Column=0;
  286.                       Line_Length=Length(RSC_Line.c);
  287.                       Do d=1 To Line_Length;
  288.                          /****************************************************************/
  289.                          /* Forget the Ansi Escape Sequence while counting the Columns : */
  290.                          /****************************************************************/
  291.                          If Substr(RSC_Line.c,d,1)='1B'x
  292.                          Then Do;
  293.                               Do e=d+1 To Line_Length;
  294.                                  If Translate(Substr(RSC_Line.c,e,1))>'Z'
  295.                                  Then Do;
  296.                                       Iterate;
  297.                                       End;
  298.                                  If Translate(Substr(RSC_Line.c,e,1))<'A'
  299.                                  Then Do;
  300.                                       Iterate;
  301.                                       End;
  302.                                  Leave;
  303.                                  End;
  304.                               /**********************************************************************/
  305.                               /* Remember the last Ansi Color Escape sequence before the variable : */
  306.                               /**********************************************************************/
  307.                               If Substr(RSC_Line.c,e,1)='m'
  308.                               Then Do;
  309.                                    /**********************************************************/
  310.                                    /* Return the Ansi Color Escape sequence in HexaDecimal : */
  311.                                    /**********************************************************/
  312.                                    Variable_Color=c2x(Substr(RSC_Line.c,d,e-d)||'m');
  313.                                    End;
  314.                               d=e;
  315.                               End;
  316.                          Else Do;
  317.                               If Substr(RSC_Line.c,d,1)=Variable_Indicator
  318.                               Then Do;
  319.                                    /***************************************************/
  320.                                    /* The Result to be returned to the calling Rexx : */
  321.                                    /***************************************************/
  322.                                    Vars_Found=Vars_Found+1;
  323.                                    To_Be_Returned=To_Be_Returned || Arg_Topic.a || ';' || Vars_Found || ';' || Variable_Row ||  ';' || Variable_Column || ';' || Variable_Color || ';';
  324.                                    End;
  325.                               Variable_Column=Variable_Column+1;
  326.                               End;
  327.                          End;                                          /* d*/
  328.                       End;                                             /* c*/
  329.                    /*************************************************************************/
  330.                    /* When this Topic found was in the .RSC Topics, leave the Search loop : */
  331.                    /*************************************************************************/
  332.                    Leave;
  333.                    End;
  334.               End;                                                     /* b*/
  335.            End;                                                        /* a*/
  336.  
  337.         /***************************************************/
  338.         /* The Result to be returned to the calling Rexx : */
  339.         /***************************************************/
  340.         If RENTOKIL = '/D'
  341.         Then Do;
  342.              Call Say_This('****************** result returning to caller :');
  343.              Call Say_This(To_Be_Returned);
  344.              End;
  345.  
  346.         /**********/
  347.         /* Bye... */
  348.         /**********/
  349.         Call Clean_Up_And_Go_Home;
  350.  
  351.         /***********************************************************/
  352.         /* Put the Ansi Message in one quick flash on the screen : */
  353.         /***********************************************************/
  354.         Say Ansi_Message;
  355.  
  356.         /*****************************************************************/
  357.         /* Give the Variable(s)'s Coordinates back to the Calling Rexx : */
  358.         /*****************************************************************/
  359.         Return To_Be_Returned;
  360.  
  361. /*************************************************************************************************/
  362.  
  363.    Clean_Up_And_Go_Home:
  364.  
  365.         /**************************************/
  366.         /* Compute the overall elapsed time : */
  367.         /**************************************/
  368.         If (RENTOKIL = '/V' | RENTOKIL = '/D')
  369.         Then Do;
  370.              Call Say_This Center('Total Time : ' || Time('E'),79,'═');
  371.              Call SysSleep 5;
  372.              If N_Errors > 0
  373.              Then Do;
  374.                   Call SysSleep 5;
  375.                   End;
  376.              End;
  377.  
  378.         Return 0;
  379.  
  380. /*************************************************************************************************/
  381.  
  382.  
  383.    Something_Was_Wrong:
  384.  
  385.         If N_Errors = 0
  386.         Then Do;
  387.              Call Say_This Right(' Error Message from "' || Who_Am_I_Name || '" ═══',79,'═');
  388.              End;
  389.         N_Errors=N_Errors+1;
  390.  
  391.         Return 0;
  392.  
  393. /*************************************************************************************************/
  394.  
  395.    Say_This:
  396.  
  397.         Parse ARG What_Is_There_To_Say;
  398.  
  399.         If On_The_Screen_N > On_The_Screen_Max
  400.         Then Do;
  401.              '@Pause';
  402.              Say '1B'x || '[A' || '1B'x || '[K' || '1B'x || '[A';
  403.              On_The_Screen_N=0;
  404.              End;
  405.  
  406.         Say What_Is_There_To_Say;
  407.         On_The_Screen_N=On_The_Screen_N+1;
  408.  
  409.         If Length(What_Is_There_To_Say) > 79
  410.         Then On_The_Screen_N=On_The_Screen_N+1;
  411.         If Length(What_Is_There_To_Say) > 79+80
  412.         Then On_The_Screen_N=On_The_Screen_N+1;
  413.         If Length(What_Is_There_To_Say) > 79+80+80
  414.         Then On_The_Screen_N=On_The_Screen_N+1;
  415.         If Length(What_Is_There_To_Say) > 79+80+80+80
  416.         Then On_The_Screen_N=On_The_Screen_N+1;
  417.         If Length(What_Is_There_To_Say) > 79+80+80+80+80
  418.         Then On_The_Screen_N=On_The_Screen_N+1;
  419.         If Length(What_Is_There_To_Say) > 79+80+80+80+80+80
  420.         Then On_The_Screen_N=On_The_Screen_N+1;
  421.         If Length(What_Is_There_To_Say) > 79+80+80+80+80+80+80
  422.         Then On_The_Screen_N=On_The_Screen_N+1;
  423.         If Length(What_Is_There_To_Say) > 79+80+80+80+80+80+80+80
  424.         Then On_The_Screen_N=On_The_Screen_N+1;
  425.         If Length(What_Is_There_To_Say) > 79+80+80+80+80+80+80+80+80
  426.         Then On_The_Screen_N=On_The_Screen_N+1;
  427.  
  428.         Return 0;
  429.  
  430. /*************************************************************************************************/
  431.  
  432. /************************************************************************************************/
  433. /* This code is freeware.                                                                       */
  434. /*                              Intellectual Copyright : Marcel Hendrickx  BEEBEL06@IBMMAIL.COM */
  435. /************************************************************************************************/
  436.  
  437.