home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
ibmtool.zip
/
screen.c
< prev
next >
Wrap
Text File
|
1997-11-07
|
8KB
|
216 lines
/******************************************************************************/
/* */
/* FILE: SCREEN.C */
/* */
/* PURPOSE: This file contains the General Request processing. */
/* */
/* FUNCTIONS: InitMenu */
/* InitScreen */
/* aprintf */
/* Box */
/* ClearWindow */
/* SelectMenuOpt */
/* */
/* GLOBAL DATA ACCESSED */
/* BOOLEAN Debug */
/* BOOLEAN ScriptMode */
/* */
/******************************************************************************/
#define INCL_SUB
#define INCL_BASE
#define INCL_DOS
#include <os2.h>
#include <stdio.h>
#include <stdarg.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "ndis.h"
#include "ibmtool.h"
#include "intrface.h"
int ScanTable[] = { 0x001E, // 'A'
0x0030, // 'B'
0x002E, // 'C'
0x0020, // 'D'
0x0012, // 'E'
0x0021, // 'F'
0x0022, // 'G'
0x0023, // 'H'
0x0017, // 'I'
0x0024, // 'J'
0x0025, // 'K'
0x0026, // 'L'
0x0032, // 'M'
0x0031, // 'N'
0x0018, // 'O'
0x0019, // 'P'
0x0010, // 'Q'
0x0013, // 'R'
0x001F, // 'S'
0x0014, // 'T'
0x0016, // 'U'
0x002F, // 'V'
0x0011, // 'W'
0x002D, // 'X'
0x0015, // 'Y'
0x002C }; // 'Z'
WINDOW Menu = { 0, 0, 0, MAXCOL, 0, 0x70, 0x21, 0x71 },
Info = { 1, 0, 12, MAXCOL, 0, 0x1F, 0x1E, 0x1E },
CmdLine = { 13, 0, 13, MAXCOL, 0, 0x30, 0x30, 0x30 },
Msg = { 14, 0, 24, MAXCOL, 0, 0x70, 0x70, 0x70 };
MENU MenuBar[] = { {" C&ommon Char " , 0, 0, 0, 0, CommonChar },
{" Serv &Char " , 0, 0, 0, 0, ServiceChar },
{" Serv &Stat " , 0, 0, 0, 0, ServiceStatus },
{" &MCast " , 0, 0, 0, 0, MulticastList },
{" &Flags " , 0, 0, 0, 0, Services },
{" Me&dia " , 0, 0, 0, 0, Media },
{" CC&B " , 0, 0, 0, 0, CCBDisp },
{" &Help " , 64, 0, 0, 0, Help },
{"" , 0, 0, 0, 0, NULL } };
int CurrMenuOpt = -1;
int PrevMenuOpt;
int LastMenuOpt;
void InitMenu ()
{
char msg[10];
char Selector[2], *p;
int i, col = 0;
ClearWindow (Menu);
Selector[1] = Menu.SelAttr;
VioSetCurPos (Menu.Top, Menu.Left, 0);
for (i=0; *MenuBar[i].Option; ++i)
{
if (!MenuBar[i].Col)
MenuBar[i].Col = col;
else
col = MenuBar[i].Col;
p = MenuBar[i].Option;
while (*p)
{
if (*p == '&')
{
strcpy (p, p+1);
MenuBar[i].SelCol = col;
MenuBar[i].Option[strlen (MenuBar[i].Option)] = '\0';
MenuBar[i].SelKey = ScanTable[(int) (toupper (*p) - 'A')];
MenuBar[i].SelChar = *p;
Selector[0] = *p;
VioWrtNCell (Selector, 1, Menu.Top, col++, 0);
++p;
}
else
{
VioWrtNChar (p++, 1, Menu.Top, col++, 0);
} /* endif */
} /* endwhile */
} /* endfor */
LastMenuOpt = i - 2;
}
void InitScreen ()
{
ClearWindow (Info);
Info.Lines = Info.Bottom - Info.Top + 1;
ClearWindow (CmdLine);
aprintf (CmdLine.Top, CmdLine.Left, CmdLine.Attr, ">");
ClearWindow (Msg);
Msg.Lines = Msg.Bottom - Msg.Top + 1;
SelectMenuOpt (MCC);
}
int aprintf (USHORT row, USHORT col, BYTE attr, char *fmt, ...)
{
char str[MAXSTRING]; /* Buffer to build sting into */
int cnt; /* Result of SPRINTF for return */
va_list argptr; /* Argument list pointer */
if (ScriptMode) return 0;
va_start (argptr, fmt); /* Initialize va_ functions */
cnt = vsprintf (str, fmt, argptr); /* prints string to buffer */
VioWrtCharStrAtt (str, cnt, row, col, &attr, 0);
va_end (argptr); /* Close va_ functions */
return cnt; /* Return the conversion count */
}
void Box (USHORT top, USHORT left, USHORT bottom, USHORT right, char attr)
{
BYTE battr[2] = " ";
USHORT i;
battr[1] = attr;
VioScrollUp (top, left, bottom, right, -1, battr, 0);
/* corners */
battr[0] = 0xDA;
VioWrtNCell (battr, 1, top, left, 0);
battr[0] = 0xBF;
VioWrtNCell (battr, 1, top, right, 0);
battr[0] = 0xC0;
VioWrtNCell (battr, 1, bottom, left, 0);
battr[0] = 0xD9;
VioWrtNCell (battr, 1, bottom, right, 0);
/* top and bottom */
battr[0] = 0xC4;
VioWrtNCell (battr, right - left - 1, top, left + 1, 0);
VioWrtNCell (battr, right - left - 1, bottom, left + 1, 0);
/* sides */
battr[0] = 0xB3;
for (i=top+1; i<bottom; ++i)
VioWrtNCell (battr, 1, i, left, 0);
for (i=top+1; i<bottom; ++i)
VioWrtNCell (battr, 1, i, right, 0);
}
void ClearWindow (WINDOW Window)
{
char WAttr[2] = " ";
WAttr[1] = Window.Attr;
VioScrollUp (Window.Top, Window.Left,
Window.Bottom, Window.Right,
-1, WAttr, 0);
}
void SelectMenuOpt (int MenuOpt)
{
char Selector[2];
if (CurrMenuOpt == MenuOpt) return;
if (CurrMenuOpt == -1) CurrMenuOpt = MenuOpt;
VioWrtCharStrAtt (MenuBar[CurrMenuOpt].Option,
strlen (MenuBar[CurrMenuOpt].Option),
Menu.Top, MenuBar[CurrMenuOpt].Col, &Menu.Attr, 0);
Selector[0] = MenuBar[CurrMenuOpt].SelChar;
Selector[1] = Menu.SelAttr;
VioWrtNCell (Selector, 1, Menu.Top, MenuBar[CurrMenuOpt].SelCol, 0);
CurrMenuOpt = MenuOpt;
VioWrtCharStrAtt (MenuBar[CurrMenuOpt].Option,
strlen (MenuBar[CurrMenuOpt].Option),
Menu.Top, MenuBar[CurrMenuOpt].Col, &Menu.HighAttr, 0);
MenuBar[CurrMenuOpt].Func ();
PrevMenuOpt = MenuOpt;
}