home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ibmtool.zip / screen.c < prev    next >
Text File  |  1997-11-07  |  8KB  |  216 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*      FILE: SCREEN.C                                                        */
  4. /*                                                                            */
  5. /*   PURPOSE: This file contains the General Request processing.              */
  6. /*                                                                            */
  7. /* FUNCTIONS: InitMenu                                                        */
  8. /*            InitScreen                                                      */
  9. /*            aprintf                                                         */
  10. /*            Box                                                             */
  11. /*            ClearWindow                                                     */
  12. /*            SelectMenuOpt                                                   */
  13. /*                                                                            */
  14. /* GLOBAL DATA ACCESSED                                                       */
  15. /*      BOOLEAN Debug                                                         */
  16. /*      BOOLEAN ScriptMode                                                    */
  17. /*                                                                            */
  18. /******************************************************************************/
  19.  
  20. #define INCL_SUB
  21. #define INCL_BASE
  22. #define INCL_DOS
  23. #include <os2.h>
  24. #include <stdio.h>
  25. #include <stdarg.h>
  26. #include <malloc.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <ctype.h>
  30. #include "ndis.h"
  31. #include "ibmtool.h"
  32. #include "intrface.h"
  33.  
  34. int ScanTable[] = { 0x001E,     //  'A'
  35.                     0x0030,     //  'B'
  36.                     0x002E,     //  'C'
  37.                     0x0020,     //  'D'
  38.                     0x0012,     //  'E'
  39.                     0x0021,     //  'F'
  40.                     0x0022,     //  'G'
  41.                     0x0023,     //  'H'
  42.                     0x0017,     //  'I'
  43.                     0x0024,     //  'J'
  44.                     0x0025,     //  'K'
  45.                     0x0026,     //  'L'
  46.                     0x0032,     //  'M'
  47.                     0x0031,     //  'N'
  48.                     0x0018,     //  'O'
  49.                     0x0019,     //  'P'
  50.                     0x0010,     //  'Q'
  51.                     0x0013,     //  'R'
  52.                     0x001F,     //  'S'
  53.                     0x0014,     //  'T'
  54.                     0x0016,     //  'U'
  55.                     0x002F,     //  'V'
  56.                     0x0011,     //  'W'
  57.                     0x002D,     //  'X'
  58.                     0x0015,     //  'Y'
  59.                     0x002C };   //  'Z'
  60.  
  61. WINDOW Menu    = {  0,  0,  0, MAXCOL, 0, 0x70, 0x21, 0x71 },
  62.        Info    = {  1,  0, 12, MAXCOL, 0, 0x1F, 0x1E, 0x1E },
  63.        CmdLine = { 13,  0, 13, MAXCOL, 0, 0x30, 0x30, 0x30 },
  64.        Msg     = { 14,  0, 24, MAXCOL, 0, 0x70, 0x70, 0x70 };
  65.  
  66. MENU MenuBar[] = { {" C&ommon Char "        ,  0, 0, 0, 0, CommonChar    },
  67.                    {" Serv &Char "          ,  0, 0, 0, 0, ServiceChar   },
  68.                    {" Serv &Stat "          ,  0, 0, 0, 0, ServiceStatus },
  69.                    {" &MCast "              ,  0, 0, 0, 0, MulticastList },
  70.                    {" &Flags "              ,  0, 0, 0, 0, Services      },
  71.                    {" Me&dia "              ,  0, 0, 0, 0, Media         },
  72.                    {" CC&B "                ,  0, 0, 0, 0, CCBDisp       },
  73.                    {" &Help "               , 64, 0, 0, 0, Help          },
  74.                    {""                      ,  0, 0, 0, 0, NULL          } };
  75.  
  76. int     CurrMenuOpt = -1;
  77. int     PrevMenuOpt;
  78. int     LastMenuOpt;
  79.  
  80. void InitMenu ()
  81. {
  82.   char msg[10];
  83.   char Selector[2], *p;
  84.   int i, col = 0;
  85.  
  86.   ClearWindow (Menu);
  87.   Selector[1] = Menu.SelAttr;
  88.   VioSetCurPos (Menu.Top, Menu.Left, 0);
  89.   for (i=0; *MenuBar[i].Option; ++i)
  90.     {
  91.      if (!MenuBar[i].Col)
  92.         MenuBar[i].Col = col;
  93.      else
  94.         col = MenuBar[i].Col;
  95.      p = MenuBar[i].Option;
  96.      while (*p)
  97.        {
  98.         if (*p == '&')
  99.           {
  100.            strcpy (p, p+1);
  101.            MenuBar[i].SelCol = col;
  102.            MenuBar[i].Option[strlen (MenuBar[i].Option)] = '\0';
  103.            MenuBar[i].SelKey = ScanTable[(int) (toupper (*p) - 'A')];
  104.            MenuBar[i].SelChar = *p;
  105.            Selector[0] = *p;
  106.            VioWrtNCell (Selector, 1, Menu.Top, col++, 0);
  107.            ++p;
  108.           }
  109.         else
  110.           {
  111.            VioWrtNChar (p++, 1, Menu.Top, col++, 0);
  112.           } /* endif */
  113.        } /* endwhile */
  114.     } /* endfor */
  115.  
  116.   LastMenuOpt = i - 2;
  117. }
  118.  
  119. void InitScreen ()
  120. {
  121.   ClearWindow (Info);
  122.   Info.Lines = Info.Bottom - Info.Top + 1;
  123.  
  124.   ClearWindow (CmdLine);
  125.   aprintf (CmdLine.Top, CmdLine.Left, CmdLine.Attr, ">");
  126.  
  127.   ClearWindow (Msg);
  128.   Msg.Lines = Msg.Bottom - Msg.Top + 1;
  129.  
  130.   SelectMenuOpt (MCC);
  131. }
  132.  
  133. int aprintf (USHORT row, USHORT col, BYTE attr, char *fmt, ...)
  134. {
  135.   char     str[MAXSTRING];              /* Buffer to build sting into   */
  136.   int      cnt;                         /* Result of SPRINTF for return */
  137.   va_list  argptr;                      /* Argument list pointer        */
  138.  
  139.   if (ScriptMode) return 0;
  140.  
  141.   va_start (argptr, fmt);               /* Initialize va_ functions     */
  142.  
  143.   cnt = vsprintf (str, fmt, argptr);    /* prints string to buffer      */
  144.  
  145.   VioWrtCharStrAtt (str, cnt, row, col, &attr, 0);
  146.  
  147.   va_end (argptr);                      /* Close va_ functions          */
  148.  
  149.   return cnt;                           /* Return the conversion count  */
  150. }
  151.  
  152. void Box (USHORT top, USHORT left, USHORT bottom, USHORT right, char attr)
  153. {
  154.   BYTE   battr[2] = " ";
  155.   USHORT i;
  156.  
  157.   battr[1] = attr;
  158.   VioScrollUp (top, left, bottom, right, -1, battr, 0);
  159.  
  160.   /* corners */
  161.   battr[0] = 0xDA;
  162.   VioWrtNCell (battr, 1, top, left, 0);
  163.   battr[0] = 0xBF;
  164.   VioWrtNCell (battr, 1, top, right, 0);
  165.   battr[0] = 0xC0;
  166.   VioWrtNCell (battr, 1, bottom, left, 0);
  167.   battr[0] = 0xD9;
  168.   VioWrtNCell (battr, 1, bottom, right, 0);
  169.  
  170.   /* top and bottom */
  171.   battr[0] = 0xC4;
  172.   VioWrtNCell (battr, right - left - 1, top, left + 1, 0);
  173.   VioWrtNCell (battr, right - left - 1, bottom, left + 1, 0);
  174.  
  175.   /* sides */
  176.   battr[0] = 0xB3;
  177.   for (i=top+1; i<bottom; ++i)
  178.      VioWrtNCell (battr, 1, i, left, 0);
  179.   for (i=top+1; i<bottom; ++i)
  180.      VioWrtNCell (battr, 1, i, right, 0);
  181. }
  182.  
  183. void ClearWindow (WINDOW Window)
  184. {
  185.   char WAttr[2] = " ";
  186.  
  187.   WAttr[1] = Window.Attr;
  188.   VioScrollUp (Window.Top, Window.Left,
  189.                Window.Bottom, Window.Right,
  190.                -1, WAttr, 0);
  191. }
  192.  
  193. void SelectMenuOpt (int MenuOpt)
  194. {
  195.   char Selector[2];
  196.  
  197.   if (CurrMenuOpt == MenuOpt) return;
  198.   if (CurrMenuOpt == -1) CurrMenuOpt = MenuOpt;
  199.  
  200.   VioWrtCharStrAtt (MenuBar[CurrMenuOpt].Option,
  201.                     strlen (MenuBar[CurrMenuOpt].Option),
  202.                     Menu.Top, MenuBar[CurrMenuOpt].Col, &Menu.Attr, 0);
  203.   Selector[0] = MenuBar[CurrMenuOpt].SelChar;
  204.   Selector[1] = Menu.SelAttr;
  205.   VioWrtNCell (Selector, 1, Menu.Top, MenuBar[CurrMenuOpt].SelCol, 0);
  206.  
  207.   CurrMenuOpt = MenuOpt;
  208.   VioWrtCharStrAtt (MenuBar[CurrMenuOpt].Option,
  209.                     strlen (MenuBar[CurrMenuOpt].Option),
  210.                     Menu.Top, MenuBar[CurrMenuOpt].Col, &Menu.HighAttr, 0);
  211.  
  212.   MenuBar[CurrMenuOpt].Func ();
  213.   PrevMenuOpt = MenuOpt;
  214. }
  215.  
  216.